From 3ffcc473748b6c7f14ec5ed55c12cc921c09703f Mon Sep 17 00:00:00 2001 From: merlokk <807634+merlokk@users.noreply.github.com> Date: Wed, 6 Feb 2019 14:11:49 +0200 Subject: [PATCH 1/9] fix logger --- targets/stm32l432/src/redirect.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/targets/stm32l432/src/redirect.c b/targets/stm32l432/src/redirect.c index d3d5e5d..ee587d0 100644 --- a/targets/stm32l432/src/redirect.c +++ b/targets/stm32l432/src/redirect.c @@ -43,11 +43,22 @@ static int NFC = 0; int _write (int fd, const void *buf, long int len) { uint8_t * data = (uint8_t *) buf; + static uint8_t logbuf[1000] = {0}; + static int logbuflen = 0; + if (logbuflen + len > 1000) { + int mlen = logbuflen + len - 1000; + memmove(logbuf, &logbuf[mlen], mlen); + logbuflen -= mlen; + } + memcpy(&logbuf[logbuflen], data, len); + logbuflen += len; if (!NFC) { // Send out USB serial - CDC_Transmit_FS(data, len); + uint8_t res = CDC_Transmit_FS(logbuf, logbuflen); + if (res == USBD_OK) + logbuflen = 0; } // Send out UART serial From e657e26886993bc7489f19d5ac6b84cb1f6eb788 Mon Sep 17 00:00:00 2001 From: merlokk <807634+merlokk@users.noreply.github.com> Date: Wed, 6 Feb 2019 15:15:37 +0200 Subject: [PATCH 2/9] check AMS product type --- targets/stm32l432/src/ams.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/targets/stm32l432/src/ams.c b/targets/stm32l432/src/ams.c index a342513..4a7a2f7 100644 --- a/targets/stm32l432/src/ams.c +++ b/targets/stm32l432/src/ams.c @@ -275,12 +275,12 @@ bool ams_init() // check connection uint8_t productType = ams_read_reg(AMS_REG_PRODUCT_TYPE); - if (!productType) + if (productType != 0x14) { - printf1(TAG_NFC,"Have no product type. Connection error."); + printf1(TAG_NFC,"Have no product type [0x%02x]. Connection error.\n", productType); return false; } - printf1(TAG_NFC,"Product type 0x%02x.", productType); + printf1(TAG_NFC,"Product type 0x%02x.\n", productType); // enable tunneling mode and RF configuration ams_write_reg(AMS_REG_IC_CONF2, AMS_RFCFG_EN | AMS_TUN_MOD); From 4611f05051dfe6a17fb85f801c7fca65635ed041 Mon Sep 17 00:00:00 2001 From: merlokk <807634+merlokk@users.noreply.github.com> Date: Wed, 6 Feb 2019 15:17:52 +0200 Subject: [PATCH 3/9] small fix in AMS3956 debug texts --- targets/stm32l432/src/ams.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/targets/stm32l432/src/ams.c b/targets/stm32l432/src/ams.c index 4a7a2f7..76a256c 100644 --- a/targets/stm32l432/src/ams.c +++ b/targets/stm32l432/src/ams.c @@ -277,10 +277,10 @@ bool ams_init() uint8_t productType = ams_read_reg(AMS_REG_PRODUCT_TYPE); if (productType != 0x14) { - printf1(TAG_NFC,"Have no product type [0x%02x]. Connection error.\n", productType); + printf1(TAG_NFC, "Have no product type [0x%02x]. AMS3956 connection error.\n", productType); return false; } - printf1(TAG_NFC,"Product type 0x%02x.\n", productType); + printf1(TAG_NFC,"AMS3956 product type 0x%02x.\n", productType); // enable tunneling mode and RF configuration ams_write_reg(AMS_REG_IC_CONF2, AMS_RFCFG_EN | AMS_TUN_MOD); From 771fffe329746be23278c674ea43cfe1759adffa Mon Sep 17 00:00:00 2001 From: merlokk <807634+merlokk@users.noreply.github.com> Date: Wed, 6 Feb 2019 17:12:22 +0200 Subject: [PATCH 4/9] WTX works. todo: clean debug unneeded messages --- targets/stm32l432/src/device.c | 6 +++++ targets/stm32l432/src/nfc.c | 41 ++++++++++++++++++++++++++-------- targets/stm32l432/src/nfc.h | 2 ++ 3 files changed, 40 insertions(+), 9 deletions(-) diff --git a/targets/stm32l432/src/device.c b/targets/stm32l432/src/device.c index b3fd58f..725727d 100644 --- a/targets/stm32l432/src/device.c +++ b/targets/stm32l432/src/device.c @@ -65,6 +65,12 @@ void TIM6_DAC_IRQHandler() ctaphid_update_status(__device_status); } } + + // NFC sending WTX if needs + if (haveNFC) + { + WTX_timer_exec(); + } } // Global USB interrupt handler diff --git a/targets/stm32l432/src/nfc.c b/targets/stm32l432/src/nfc.c index eb07440..9369487 100644 --- a/targets/stm32l432/src/nfc.c +++ b/targets/stm32l432/src/nfc.c @@ -215,41 +215,55 @@ void nfc_write_response_chaining(uint8_t req0, uint8_t * data, int len) // WTX: f2 01 91 40 === f2(S-block + WTX, frame without CID) 01(from iso - multiply WTX from ATS by 1) <2b crc16> static bool WTX_sent; static bool WTX_fail; +static uint32_t WTX_timer; + +bool WTX_process(int read_timeout); void WTX_clear() { WTX_sent = false; WTX_fail = false; + WTX_timer = 0; } bool WTX_on(int WTX_time) { WTX_clear(); - // TODO: start interrupt + WTX_timer = millis(); return true; } -bool WTX_process(int read_timeout); - bool WTX_off() { - // TODO: stop interrupt + WTX_timer = 0; // read data if we sent WTX if (WTX_sent) { - if (!WTX_process(10)) +printf1(TAG_NFC, "WTX_process from WTX_off\n"); + if (!WTX_process(100)) return false; } if (WTX_fail) return false; + WTX_clear(); return true; } +void WTX_timer_exec() +{ + // timer on and expired (300ms) + if ((WTX_timer <= 0) || WTX_timer + 300 > millis()) + return; + + WTX_process(10); + WTX_timer = millis(); +} + // executes twice a period. 1st for send WTX, 2nd for check the result // read timeout must be 0 to call from int bool WTX_process(int read_timeout) @@ -262,24 +276,28 @@ bool WTX_process(int read_timeout) { nfc_write_frame(wtx, sizeof(wtx)); WTX_sent = true; +printf1(TAG_NFC, "+ %d\n", millis()); return true; } else { uint8_t data[32]; int len; - if (ams_receive_with_timeout(read_timeout, data, sizeof(data), &len)) + if (!ams_receive_with_timeout(read_timeout, data, sizeof(data), &len)) { +printf1(TAG_NFC, "ft len=%d ms=%d\n", len, millis()); WTX_fail = true; return false; } if (len != 2 || data[0] != 0xf2 || data[1] != 0x01) { +printf1(TAG_NFC, "fl %d [%02x]\n", len, data[0]); WTX_fail = true; return false; } +printf1(TAG_NFC, "- %d\n", millis()); WTX_sent = false; return true; } @@ -398,6 +416,7 @@ void nfc_process_iblock(uint8_t * buf, int len) // block = buf[0] & 1; // block = NFC_STATE.block_num; // block = !block; + // NFC_STATE.block_num = block; // NFC_STATE.block_num = block; nfc_write_response_ex(buf[0], (uint8_t *)"U2F_V2", 6, SW_SUCCESS); printf1(TAG_NFC, "FIDO applet selected.\r\n"); @@ -444,8 +463,10 @@ void nfc_process_iblock(uint8_t * buf, int len) t1 = millis(); WTX_on(WTX_TIME_DEFAULT); u2f_request_nfc(&buf[1], len, &ctap_resp); - if (!WTX_off()) + if (!WTX_off()) { +printf1(TAG_NFC, "WRX-off err\n"); return; + } printf1(TAG_NFC, "U2F resp len: %d\r\n", ctap_resp.length); printf1(TAG_NFC,"U2F Register processing %d (took %d)\r\n", millis(), millis() - t1); @@ -493,8 +514,10 @@ void nfc_process_iblock(uint8_t * buf, int len) WTX_on(WTX_TIME_DEFAULT); ctap_response_init(&ctap_resp); status = ctap_request(payload, plen, &ctap_resp); - if (!WTX_off()) + if (!WTX_off()){ +printf1(TAG_NFC, "WTX-off err\n"); return; + } printf1(TAG_NFC, "CTAP resp: %d len: %d\r\n", status, ctap_resp.length); if (status == CTAP1_ERR_SUCCESS) @@ -643,7 +666,7 @@ void nfc_process_block(uint8_t * buf, int len) } else { - printf1(TAG_NFC, "NFC_CMD_SBLOCK, Unknown\r\n"); + printf1(TAG_NFC, "NFC_CMD_SBLOCK, Unknown. len[%d]\r\n", len); } dump_hex1(TAG_NFC, buf, len); } diff --git a/targets/stm32l432/src/nfc.h b/targets/stm32l432/src/nfc.h index 4859570..2388018 100644 --- a/targets/stm32l432/src/nfc.h +++ b/targets/stm32l432/src/nfc.h @@ -57,4 +57,6 @@ typedef enum APP_FIDO, } APPLETS; +void WTX_timer_exec(); + #endif From 375db69e3a2e6d836e4ccce118ecd95a2b70d875 Mon Sep 17 00:00:00 2001 From: merlokk <807634+merlokk@users.noreply.github.com> Date: Wed, 6 Feb 2019 19:06:49 +0200 Subject: [PATCH 5/9] fido2 works --- fido2/ctap.c | 25 +++++++++++++++---------- fido2/ctap.h | 2 +- targets/stm32l432/src/nfc.c | 4 ++-- 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/fido2/ctap.c b/fido2/ctap.c index 6b644f3..b84f9b7 100644 --- a/fido2/ctap.c +++ b/fido2/ctap.c @@ -324,7 +324,7 @@ static int is_matching_rk(CTAP_residentKey * rk, CTAP_residentKey * rk2) } -static int ctap_make_auth_data(struct rpId * rp, CborEncoder * map, uint8_t * auth_data_buf, int len, CTAP_userEntity * user, uint8_t credtype, int32_t algtype, int32_t * sz, int store) +static int ctap_make_auth_data(struct rpId * rp, CborEncoder * map, uint8_t * auth_data_buf, int len, CTAP_userEntity * user, uint8_t credtype, int32_t algtype, int32_t * sz, int store, bool fromNFC) { CborEncoder cose_key; int auth_data_sz, ret; @@ -350,8 +350,13 @@ static int ctap_make_auth_data(struct rpId * rp, CborEncoder * map, uint8_t * au count = auth_data_update_count(&authData->head); device_set_status(CTAPHID_STATUS_UPNEEDED); - int but = ctap_user_presence_test(); - + // if NFC - not need to click a button + int but = 1; + if(!fromNFC) + { + but = ctap_user_presence_test(); + } + if (!but) { return CTAP2_ERR_OPERATION_DENIED; @@ -551,7 +556,7 @@ int ctap_authenticate_credential(struct rpId * rp, CTAP_credentialDescriptor * d -uint8_t ctap_make_credential(CborEncoder * encoder, uint8_t * request, int length) +uint8_t ctap_make_credential(CborEncoder * encoder, uint8_t * request, int length, bool fromNFC) { CTAP_makeCredential MC; int ret, i; @@ -621,7 +626,7 @@ uint8_t ctap_make_credential(CborEncoder * encoder, uint8_t * request, int lengt int32_t auth_data_sz; ret = ctap_make_auth_data(&MC.rp, &map, auth_data_buf, sizeof(auth_data_buf), - &MC.user, MC.publicKeyCredentialType, MC.COSEAlgorithmIdentifier, &auth_data_sz, MC.rk); + &MC.user, MC.publicKeyCredentialType, MC.COSEAlgorithmIdentifier, &auth_data_sz, MC.rk, fromNFC); check_retr(ret); @@ -940,7 +945,7 @@ uint8_t ctap_get_next_assertion(CborEncoder * encoder) return 0; } -uint8_t ctap_get_assertion(CborEncoder * encoder, uint8_t * request, int length) +uint8_t ctap_get_assertion(CborEncoder * encoder, uint8_t * request, int length, bool fromNFC) { CTAP_getAssertion GA; uint8_t auth_data_buf[sizeof(CTAP_authDataHeader)]; @@ -992,7 +997,7 @@ uint8_t ctap_get_assertion(CborEncoder * encoder, uint8_t * request, int length) ret = cbor_encoder_create_map(encoder, &map, map_size); check_ret(ret); - ret = ctap_make_auth_data(&GA.rp, &map, auth_data_buf, sizeof(auth_data_buf), NULL, 0,0,NULL, 0); + ret = ctap_make_auth_data(&GA.rp, &map, auth_data_buf, sizeof(auth_data_buf), NULL, 0,0,NULL, 0, fromNFC); check_retr(ret); /*for (int j = 0; j < GA.credLen; j++)*/ @@ -1358,7 +1363,7 @@ void ctap_response_init(CTAP_RESPONSE * resp) } -uint8_t ctap_request(uint8_t * pkt_raw, int length, CTAP_RESPONSE * resp) +uint8_t ctap_request(uint8_t * pkt_raw, int length, CTAP_RESPONSE * resp, bool fromNFC) { CborEncoder encoder; uint8_t status = 0; @@ -1398,7 +1403,7 @@ uint8_t ctap_request(uint8_t * pkt_raw, int length, CTAP_RESPONSE * resp) device_set_status(CTAPHID_STATUS_PROCESSING); printf1(TAG_CTAP,"CTAP_MAKE_CREDENTIAL\n"); t1 = millis(); - status = ctap_make_credential(&encoder, pkt_raw, length); + status = ctap_make_credential(&encoder, pkt_raw, length, fromNFC); t2 = millis(); printf1(TAG_TIME,"make_credential time: %d ms\n", t2-t1); @@ -1410,7 +1415,7 @@ uint8_t ctap_request(uint8_t * pkt_raw, int length, CTAP_RESPONSE * resp) device_set_status(CTAPHID_STATUS_PROCESSING); printf1(TAG_CTAP,"CTAP_GET_ASSERTION\n"); t1 = millis(); - status = ctap_get_assertion(&encoder, pkt_raw, length); + status = ctap_get_assertion(&encoder, pkt_raw, length, fromNFC); t2 = millis(); printf1(TAG_TIME,"get_assertion time: %d ms\n", t2-t1); diff --git a/fido2/ctap.h b/fido2/ctap.h index 7448b44..2df795b 100644 --- a/fido2/ctap.h +++ b/fido2/ctap.h @@ -275,7 +275,7 @@ typedef struct void ctap_response_init(CTAP_RESPONSE * resp); -uint8_t ctap_request(uint8_t * pkt_raw, int length, CTAP_RESPONSE * resp); +uint8_t ctap_request(uint8_t * pkt_raw, int length, CTAP_RESPONSE * resp, bool fromNFC); // Encodes R,S signature to 2 der sequence of two integers. Sigder must be at least 72 bytes. // @return length of der signature diff --git a/targets/stm32l432/src/nfc.c b/targets/stm32l432/src/nfc.c index 9369487..892a853 100644 --- a/targets/stm32l432/src/nfc.c +++ b/targets/stm32l432/src/nfc.c @@ -513,12 +513,12 @@ printf1(TAG_NFC, "WRX-off err\n"); WTX_on(WTX_TIME_DEFAULT); ctap_response_init(&ctap_resp); - status = ctap_request(payload, plen, &ctap_resp); + status = ctap_request(payload, plen, &ctap_resp, true); if (!WTX_off()){ printf1(TAG_NFC, "WTX-off err\n"); return; } - printf1(TAG_NFC, "CTAP resp: %d len: %d\r\n", status, ctap_resp.length); + printf1(TAG_NFC, "CTAP resp: 0x%02õ len: %d\r\n", status, ctap_resp.length); if (status == CTAP1_ERR_SUCCESS) { From bc1bb3509f202e26fcaf111c2d58075bb65cdc7e Mon Sep 17 00:00:00 2001 From: merlokk <807634+merlokk@users.noreply.github.com> Date: Wed, 6 Feb 2019 19:21:06 +0200 Subject: [PATCH 6/9] move APDU dumps to separate log channel --- fido2/log.c | 1 + fido2/log.h | 45 +++++++++++++++++++------------------ fido2/main.c | 37 +++++++++++++++--------------- targets/stm32l432/src/nfc.c | 16 +++++++------ 4 files changed, 52 insertions(+), 47 deletions(-) diff --git a/fido2/log.c b/fido2/log.c index 01514db..e070a23 100644 --- a/fido2/log.c +++ b/fido2/log.c @@ -63,6 +63,7 @@ struct logtag tagtable[] = { {TAG_BOOT,"BOOT"}, {TAG_EXT,"EXT"}, {TAG_NFC,"NFC"}, + {TAG_NFC_APDU, "NAPDU"}, }; diff --git a/fido2/log.h b/fido2/log.h index a6f5097..ea056ad 100644 --- a/fido2/log.h +++ b/fido2/log.h @@ -38,29 +38,30 @@ void set_logging_tag(uint32_t tag); typedef enum { - TAG_GEN = (1 << 0), - TAG_MC = (1 << 1), - TAG_GA = (1 << 2), - TAG_CP = (1 << 3), - TAG_ERR = (1 << 4), - TAG_PARSE= (1 << 5), - TAG_CTAP = (1 << 6), - TAG_U2F = (1 << 7), - TAG_DUMP = (1 << 8), - TAG_GREEN = (1 << 9), - TAG_RED= (1 << 10), - TAG_TIME= (1 << 11), - TAG_HID = (1 << 12), - TAG_USB = (1 << 13), - TAG_WALLET = (1 << 14), - TAG_STOR = (1 << 15), - TAG_DUMP2 = (1 << 16), - TAG_BOOT = (1 << 17), - TAG_EXT = (1 << 17), - TAG_NFC = (1 << 18), + TAG_GEN = (1 << 0), + TAG_MC = (1 << 1), + TAG_GA = (1 << 2), + TAG_CP = (1 << 3), + TAG_ERR = (1 << 4), + TAG_PARSE = (1 << 5), + TAG_CTAP = (1 << 6), + TAG_U2F = (1 << 7), + TAG_DUMP = (1 << 8), + TAG_GREEN = (1 << 9), + TAG_RED = (1 << 10), + TAG_TIME = (1 << 11), + TAG_HID = (1 << 12), + TAG_USB = (1 << 13), + TAG_WALLET = (1 << 14), + TAG_STOR = (1 << 15), + TAG_DUMP2 = (1 << 16), + TAG_BOOT = (1 << 17), + TAG_EXT = (1 << 18), + TAG_NFC = (1 << 19), + TAG_NFC_APDU = (1 << 20), - TAG_NO_TAG = (1UL<<30), - TAG_FILENO = (1UL<<31) + TAG_NO_TAG = (1UL << 30), + TAG_FILENO = (1UL << 31) } LOG_TAG; #if DEBUG_LEVEL > 0 diff --git a/fido2/main.c b/fido2/main.c index 3849633..19111e6 100644 --- a/fido2/main.c +++ b/fido2/main.c @@ -40,24 +40,25 @@ int main(int argc, char * argv[]) uint32_t t1 = 0; set_logging_mask( - /*0*/ - // TAG_GEN| - // TAG_MC | - // TAG_GA | - // TAG_WALLET | - TAG_STOR | - TAG_NFC | - // TAG_CP | - // TAG_CTAP| - // TAG_HID| - //TAG_U2F| - // TAG_PARSE | - // TAG_TIME| - // TAG_DUMP| - TAG_GREEN| - TAG_RED| - TAG_ERR - ); + /*0*/ + //TAG_GEN| + //TAG_MC | + //TAG_GA | + //TAG_WALLET | + TAG_STOR | + //TAG_NFC_APDU | + TAG_NFC | + //TAG_CP | + //TAG_CTAP| + //TAG_HID| + //TAG_U2F| + //TAG_PARSE | + //TAG_TIME| + //TAG_DUMP| + TAG_GREEN| + TAG_RED| + TAG_ERR + ); device_init(); printf1(TAG_GEN,"init device\n"); diff --git a/targets/stm32l432/src/nfc.c b/targets/stm32l432/src/nfc.c index 892a853..c1d6024 100644 --- a/targets/stm32l432/src/nfc.c +++ b/targets/stm32l432/src/nfc.c @@ -91,7 +91,8 @@ bool ams_receive_with_timeout(uint32_t timeout_ms, uint8_t * data, int maxlen, i { uint8_t len = buffer_status2 & AMS_BUF_LEN_MASK; ams_read_buffer(buf, len); - printf1(TAG_NFC,">> "); dump_hex1(TAG_NFC, buf, len); + printf1(TAG_NFC_APDU, ">> "); + dump_hex1(TAG_NFC_APDU, buf, len); *dlen = MIN(32, MIN(maxlen, len)); memcpy(data, buf, *dlen); @@ -116,7 +117,8 @@ void nfc_write_frame(uint8_t * data, uint8_t len) ams_write_buffer(data,len); ams_write_command(AMS_CMD_TRANSMIT_BUFFER); - printf1(TAG_NFC,"<< "); dump_hex1(TAG_NFC, data, len); + printf1(TAG_NFC_APDU, "<< "); + dump_hex1(TAG_NFC_APDU, data, len); } bool nfc_write_response_ex(uint8_t req0, uint8_t * data, uint8_t len, uint16_t resp) @@ -600,7 +602,7 @@ void nfc_process_block(uint8_t * buf, int len) { if (buf[0] & 0x10) { - printf1(TAG_NFC, "NFC_CMD_IBLOCK chaining blen=%d len=%d\r\n", ibuflen, len); + printf1(TAG_NFC_APDU, "NFC_CMD_IBLOCK chaining blen=%d len=%d\r\n", ibuflen, len); if (ibuflen + len > sizeof(ibuf)) { printf1(TAG_NFC, "I block memory error! must have %d but have only %d\r\n", ibuflen + len, sizeof(ibuf)); @@ -608,8 +610,8 @@ void nfc_process_block(uint8_t * buf, int len) return; } - printf1(TAG_NFC,"i> "); - dump_hex1(TAG_NFC, buf, len); + printf1(TAG_NFC_APDU,"i> "); + dump_hex1(TAG_NFC_APDU, buf, len); if (len) { @@ -635,8 +637,8 @@ void nfc_process_block(uint8_t * buf, int len) printf1(TAG_NFC, "NFC_CMD_IBLOCK chaining last block. blen=%d len=%d\r\n", ibuflen, len); - printf1(TAG_NFC,"i> "); - dump_hex1(TAG_NFC, buf, len); + printf1(TAG_NFC_APDU,"i> "); + dump_hex1(TAG_NFC_APDU, buf, len); nfc_process_iblock(ibuf, ibuflen); } else { From 5328610ff14225e571ada1bd67fb2a9e9ca8175f Mon Sep 17 00:00:00 2001 From: merlokk <807634+merlokk@users.noreply.github.com> Date: Wed, 6 Feb 2019 19:51:32 +0200 Subject: [PATCH 7/9] delete debug messages --- targets/stm32l432/src/nfc.c | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/targets/stm32l432/src/nfc.c b/targets/stm32l432/src/nfc.c index c1d6024..6a9b3ad 100644 --- a/targets/stm32l432/src/nfc.c +++ b/targets/stm32l432/src/nfc.c @@ -244,13 +244,18 @@ bool WTX_off() // read data if we sent WTX if (WTX_sent) { -printf1(TAG_NFC, "WTX_process from WTX_off\n"); if (!WTX_process(100)) + { + printf1(TAG_NFC, "WTX-off get last WTX error\n"); return false; + } } if (WTX_fail) + { + printf1(TAG_NFC, "WTX-off fail\n"); return false; + } WTX_clear(); return true; @@ -258,7 +263,7 @@ printf1(TAG_NFC, "WTX_process from WTX_off\n"); void WTX_timer_exec() { - // timer on and expired (300ms) + // condition: (timer on) or (not expired[300ms]) if ((WTX_timer <= 0) || WTX_timer + 300 > millis()) return; @@ -267,7 +272,7 @@ void WTX_timer_exec() } // executes twice a period. 1st for send WTX, 2nd for check the result -// read timeout must be 0 to call from int +// read timeout must be 10 ms to call from interrupt bool WTX_process(int read_timeout) { uint8_t wtx[] = {0xf2, 0x01}; @@ -278,7 +283,6 @@ bool WTX_process(int read_timeout) { nfc_write_frame(wtx, sizeof(wtx)); WTX_sent = true; -printf1(TAG_NFC, "+ %d\n", millis()); return true; } else @@ -287,19 +291,16 @@ printf1(TAG_NFC, "+ %d\n", millis()); int len; if (!ams_receive_with_timeout(read_timeout, data, sizeof(data), &len)) { -printf1(TAG_NFC, "ft len=%d ms=%d\n", len, millis()); WTX_fail = true; return false; } if (len != 2 || data[0] != 0xf2 || data[1] != 0x01) { -printf1(TAG_NFC, "fl %d [%02x]\n", len, data[0]); WTX_fail = true; return false; } -printf1(TAG_NFC, "- %d\n", millis()); WTX_sent = false; return true; } @@ -386,7 +387,7 @@ void nfc_process_iblock(uint8_t * buf, int len) CTAP_RESPONSE ctap_resp; int status; - printf1(TAG_NFC,">> "); + printf1(TAG_NFC,"Iblock: "); dump_hex1(TAG_NFC, buf, len); // TODO this needs to be organized better @@ -465,10 +466,8 @@ void nfc_process_iblock(uint8_t * buf, int len) t1 = millis(); WTX_on(WTX_TIME_DEFAULT); u2f_request_nfc(&buf[1], len, &ctap_resp); - if (!WTX_off()) { -printf1(TAG_NFC, "WRX-off err\n"); + if (!WTX_off()) return; - } printf1(TAG_NFC, "U2F resp len: %d\r\n", ctap_resp.length); printf1(TAG_NFC,"U2F Register processing %d (took %d)\r\n", millis(), millis() - t1); @@ -516,10 +515,9 @@ printf1(TAG_NFC, "WRX-off err\n"); WTX_on(WTX_TIME_DEFAULT); ctap_response_init(&ctap_resp); status = ctap_request(payload, plen, &ctap_resp, true); - if (!WTX_off()){ -printf1(TAG_NFC, "WTX-off err\n"); + if (!WTX_off()) return; - } + printf1(TAG_NFC, "CTAP resp: 0x%02õ len: %d\r\n", status, ctap_resp.length); if (status == CTAP1_ERR_SUCCESS) @@ -635,7 +633,7 @@ void nfc_process_block(uint8_t * buf, int len) ibuf[0] = buf[0]; ibuflen++; - printf1(TAG_NFC, "NFC_CMD_IBLOCK chaining last block. blen=%d len=%d\r\n", ibuflen, len); + printf1(TAG_NFC_APDU, "NFC_CMD_IBLOCK chaining last block. blen=%d len=%d\r\n", ibuflen, len); printf1(TAG_NFC_APDU,"i> "); dump_hex1(TAG_NFC_APDU, buf, len); From ca0538551334b564d995bec42d022bdc6c4f4c08 Mon Sep 17 00:00:00 2001 From: merlokk <807634+merlokk@users.noreply.github.com> Date: Wed, 6 Feb 2019 20:06:46 +0200 Subject: [PATCH 8/9] log fixing --- targets/stm32l432/src/redirect.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/targets/stm32l432/src/redirect.c b/targets/stm32l432/src/redirect.c index ee587d0..8e55b9a 100644 --- a/targets/stm32l432/src/redirect.c +++ b/targets/stm32l432/src/redirect.c @@ -45,9 +45,9 @@ int _write (int fd, const void *buf, long int len) uint8_t * data = (uint8_t *) buf; static uint8_t logbuf[1000] = {0}; static int logbuflen = 0; - if (logbuflen + len > 1000) { - int mlen = logbuflen + len - 1000; - memmove(logbuf, &logbuf[mlen], mlen); + if (logbuflen + len > sizeof(logbuf)) { + int mlen = logbuflen + len - sizeof(logbuf); + memmove(logbuf, &logbuf[mlen], sizeof(logbuf) - mlen); logbuflen -= mlen; } memcpy(&logbuf[logbuflen], data, len); From c6d946136e31bb183425a55f7772a85cf0b2f110 Mon Sep 17 00:00:00 2001 From: merlokk <807634+merlokk@users.noreply.github.com> Date: Thu, 7 Feb 2019 16:05:08 +0200 Subject: [PATCH 9/9] small fix --- targets/stm32l432/src/ams.c | 9 +++------ targets/stm32l432/src/redirect.c | 2 +- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/targets/stm32l432/src/ams.c b/targets/stm32l432/src/ams.c index 8d43148..e218f34 100644 --- a/targets/stm32l432/src/ams.c +++ b/targets/stm32l432/src/ams.c @@ -268,7 +268,6 @@ void ams_print_int1(uint8_t int0) bool ams_init() { - uint8_t block[4]; LL_GPIO_SetPinMode(SOLO_AMS_CS_PORT,SOLO_AMS_CS_PIN,LL_GPIO_MODE_OUTPUT); @@ -290,7 +289,7 @@ bool ams_init() uint8_t productType = ams_read_reg(AMS_REG_PRODUCT_TYPE); if (productType != 0x14) { - printf1(TAG_NFC, "Have no product type [0x%02x]. AMS3956 connection error.\n", productType); + printf1(TAG_NFC, "Have wrong product type [0x%02x]. AMS3956 connection error.\n", productType); return false; } printf1(TAG_NFC,"AMS3956 product type 0x%02x.\n", productType); @@ -298,10 +297,8 @@ bool ams_init() // enable tunneling mode and RF configuration ams_write_reg(AMS_REG_IC_CONF2, AMS_RFCFG_EN | AMS_TUN_MOD); - // enable tunneling mode and RF configuration - ams_write_reg(AMS_REG_IC_CONF2, AMS_RFCFG_EN | AMS_TUN_MOD); - - + if (1) + { ams_read_eeprom_block(AMS_CONFIG_UID_ADDR, block); printf1(TAG_NFC,"UID: "); dump_hex1(TAG_NFC,block,4); diff --git a/targets/stm32l432/src/redirect.c b/targets/stm32l432/src/redirect.c index 8f40035..ff03c1e 100644 --- a/targets/stm32l432/src/redirect.c +++ b/targets/stm32l432/src/redirect.c @@ -52,7 +52,7 @@ int _write (int fd, const void *buf, long int len) memcpy(&logbuf[logbuflen], data, len); logbuflen += len; - // Send out USB serial + // Send out USB serial uint8_t res = CDC_Transmit_FS(logbuf, logbuflen); if (res == USBD_OK) logbuflen = 0;