diff --git a/fido2/main.c b/fido2/main.c index 35c4c6f..3849633 100644 --- a/fido2/main.c +++ b/fido2/main.c @@ -65,8 +65,6 @@ int main(int argc, char * argv[]) usbhid_init(); printf1(TAG_GEN,"init usb\n"); - nfc_init(); - ctaphid_init(); printf1(TAG_GEN,"init ctaphid\n"); diff --git a/fido2/u2f.c b/fido2/u2f.c index eb24ae5..6d5e6eb 100644 --- a/fido2/u2f.c +++ b/fido2/u2f.c @@ -135,7 +135,7 @@ void u2f_request(struct u2f_request_apdu* req, CTAP_RESPONSE * resp) { uint32_t len = ((req->LC3) | ((uint32_t)req->LC2 << 8) | ((uint32_t)req->LC1 << 16)); - u2f_request_ex((APDU_HEADER *)req, &req[7], len, resp, false); + u2f_request_ex((APDU_HEADER *)req, req->payload, len, resp, false); } int8_t u2f_response_writeback(const uint8_t * buf, uint16_t len) diff --git a/targets/stm32l432/src/ams.c b/targets/stm32l432/src/ams.c index 1b2c87a..a342513 100644 --- a/targets/stm32l432/src/ams.c +++ b/targets/stm32l432/src/ams.c @@ -28,7 +28,7 @@ static void wait_for_rx() } -static void ams_print_device(AMS_DEVICE * dev) +void ams_print_device(AMS_DEVICE * dev) { printf1(TAG_NFC, "AMS_DEVICE:\r\n"); printf1(TAG_NFC, " io_conf: %02x\r\n",dev->regs.io_conf); @@ -252,7 +252,7 @@ void ams_print_int1(uint8_t int0) printf1(tag,"\r\n"); } -void ams_init() +bool ams_init() { uint8_t block[4]; @@ -273,13 +273,19 @@ void ams_init() ams_write_command(AMS_CMD_DEFAULT); ams_write_command(AMS_CMD_CLEAR_BUFFER); + // check connection + uint8_t productType = ams_read_reg(AMS_REG_PRODUCT_TYPE); + if (!productType) + { + printf1(TAG_NFC,"Have no product type. Connection error."); + return false; + } + printf1(TAG_NFC,"Product type 0x%02x.", productType); + // enable tunneling mode and RF configuration ams_write_reg(AMS_REG_IC_CONF2, AMS_RFCFG_EN | AMS_TUN_MOD); - ams_read_eeprom_block(0, block); - printf1(TAG_NFC,"UID: "); dump_hex1(TAG_NFC,block,4); - - ams_read_eeprom_block(0, block); + ams_read_eeprom_block(AMS_CONFIG_UID_ADDR, block); printf1(TAG_NFC,"UID: "); dump_hex1(TAG_NFC,block,4); ams_read_eeprom_block(AMS_CONFIG_BLOCK0_ADDR, block); @@ -336,5 +342,6 @@ void ams_init() ams_read_eeprom_block(0x7F, block); printf1(TAG_NFC,"conf1: "); dump_hex1(TAG_NFC,block,4); } - + + return true; } diff --git a/targets/stm32l432/src/ams.h b/targets/stm32l432/src/ams.h index 361cb0d..ad3b94f 100644 --- a/targets/stm32l432/src/ams.h +++ b/targets/stm32l432/src/ams.h @@ -1,8 +1,12 @@ +// AS3956 interface +// https://ams.com/as3956 +// https://ams.com/documents/20143/36005/AS3956_DS000546_7-00.pdf + #ifndef _AMS_H_ #define _AMS_H_ #include -#include +#include #include "stm32l4xx_ll_gpio.h" @@ -35,7 +39,7 @@ typedef union #define SELECT() LL_GPIO_ResetOutputPin(SOLO_AMS_CS_PORT,SOLO_AMS_CS_PIN) #define UNSELECT() LL_GPIO_SetOutputPin(SOLO_AMS_CS_PORT,SOLO_AMS_CS_PIN) -void ams_init(); +bool ams_init(); void ams_read_buffer(uint8_t * data, int len); void ams_write_buffer(uint8_t * data, int len); @@ -92,7 +96,14 @@ void ams_write_reg(uint8_t addr, uint8_t tx); #define AMS_REG_BUF2 0x0c #define AMS_BUF_LEN_MASK 0x1f #define AMS_BUF_INVALID 0x80 +#define AMS_REG_BUF1 0x0d +// ... // +#define AMS_REG_PRODUCT_TYPE 0x1c +#define AMS_REG_PRODUCT_SUBTYPE 0x1d +#define AMS_REG_VERSION_MAJOR 0x1e +#define AMS_REG_VERSION_MINOR 0x1f +#define AMS_CONFIG_UID_ADDR 0x00 #define AMS_CONFIG_BLOCK0_ADDR 0x7e #define AMS_CONFIG_BLOCK1_ADDR 0x7f diff --git a/targets/stm32l432/src/device.c b/targets/stm32l432/src/device.c index 33d9113..b3fd58f 100644 --- a/targets/stm32l432/src/device.c +++ b/targets/stm32l432/src/device.c @@ -48,6 +48,7 @@ uint32_t __90_ms = 0; uint32_t __device_status = 0; uint32_t __last_update = 0; extern PCD_HandleTypeDef hpcd; +bool haveNFC = false; #define IS_BUTTON_PRESSED() (0 == (LL_GPIO_ReadInputPort(SOLO_BUTTON_PORT) & SOLO_BUTTON_PIN)) @@ -118,6 +119,12 @@ void device_init() #else flash_option_bytes_init(0); #endif + printf1(TAG_GEN,"init nfc\n"); + haveNFC = nfc_init(); + if (haveNFC) + printf1(TAG_GEN,"NFC OK.\n"); + else + printf1(TAG_GEN,"NFC not found.\n"); #endif printf1(TAG_GEN,"hello solo\r\n"); @@ -397,7 +404,8 @@ void device_manage() } #endif #ifndef IS_BOOTLOADER - nfc_loop(); + if(haveNFC) + nfc_loop(); #endif } diff --git a/targets/stm32l432/src/nfc.c b/targets/stm32l432/src/nfc.c index 1e2bfbf..75ba0bf 100644 --- a/targets/stm32l432/src/nfc.c +++ b/targets/stm32l432/src/nfc.c @@ -43,11 +43,12 @@ void nfc_state_init() NFC_STATE.block_num = 1; } -void nfc_init() +bool nfc_init() { nfc_state_init(); - ams_init(); + return ams_init(); } + void process_int0(uint8_t int0) { diff --git a/targets/stm32l432/src/nfc.h b/targets/stm32l432/src/nfc.h index 0079ea4..b425b28 100644 --- a/targets/stm32l432/src/nfc.h +++ b/targets/stm32l432/src/nfc.h @@ -2,10 +2,11 @@ #define _NFC_H_ #include +#include #include "apdu.h" void nfc_loop(); -void nfc_init(); +bool nfc_init(); typedef struct {