From 21df72269a8c8352fbb1b07e22e107f38870b87c Mon Sep 17 00:00:00 2001 From: Romain Tartiere Date: Tue, 24 Nov 2009 18:05:31 +0000 Subject: [PATCH] Reindent; Fix ACR122 driver [1]; make distcheck OK. Pointy hat to: me [1] --- src/examples/nfc-list.c | 118 +++++++++++++++++++-------------------- src/lib/drivers/acr122.c | 38 ++++++------- 2 files changed, 78 insertions(+), 78 deletions(-) diff --git a/src/examples/nfc-list.c b/src/examples/nfc-list.c index b6466d9..42f8ce8 100644 --- a/src/examples/nfc-list.c +++ b/src/examples/nfc-list.c @@ -80,73 +80,73 @@ int main(int argc, const char* argv[]) pnd = nfc_connect(&(pnddDevices[i])); - if (pnd == NULL) - { - ERR("%s", "Unable to connect to NFC device."); - return 1; - } - nfc_initiator_init(pnd); - - // Drop the field for a while - nfc_configure(pnd,NDO_ACTIVATE_FIELD,false); - - // Let the reader only try once to find a tag - nfc_configure(pnd,NDO_INFINITE_SELECT,false); - - // Configure the CRC and Parity settings - nfc_configure(pnd,NDO_HANDLE_CRC,true); - nfc_configure(pnd,NDO_HANDLE_PARITY,true); - - // Enable field so more power consuming cards can power themselves up - nfc_configure(pnd,NDO_ACTIVATE_FIELD,true); - - printf("Connected to NFC reader: %s\n\n",pnd->acName); - - // Poll for a ISO14443A (MIFARE) tag - if (nfc_initiator_select_tag(pnd,NM_ISO14443A_106,NULL,0,&nti)) - { - printf("The following (NFC) ISO14443A tag was found:\n\n"); - printf(" ATQA (SENS_RES): "); print_hex(nti.nai.abtAtqa,2); - printf(" UID (NFCID%c): ",(nti.nai.abtUid[0]==0x08?'3':'1')); print_hex(nti.nai.abtUid,nti.nai.szUidLen); - printf(" SAK (SEL_RES): "); print_hex(&nti.nai.btSak,1); - if (nti.nai.szAtsLen) + if (pnd == NULL) { - printf(" ATS (ATR): "); - print_hex(nti.nai.abtAts,nti.nai.szAtsLen); + ERR("%s", "Unable to connect to NFC device."); + return 1; } - } + nfc_initiator_init(pnd); - // Poll for a Felica tag - if (nfc_initiator_select_tag(pnd,NM_FELICA_212,abtFelica,5,&nti) || nfc_initiator_select_tag(pnd,NM_FELICA_424,abtFelica,5,&nti)) - { - printf("The following (NFC) Felica tag was found:\n\n"); - printf("%18s","ID (NFCID2): "); print_hex(nti.nfi.abtId,8); - printf("%18s","Parameter (PAD): "); print_hex(nti.nfi.abtPad,8); - } + // Drop the field for a while + nfc_configure(pnd,NDO_ACTIVATE_FIELD,false); - // Poll for a ISO14443B tag - if (nfc_initiator_select_tag(pnd,NM_ISO14443B_106,(byte_t*)"\x00",1,&nti)) - { - printf("The following (NFC) ISO14443-B tag was found:\n\n"); - printf(" ATQB: "); print_hex(nti.nbi.abtAtqb,12); - printf(" ID: "); print_hex(nti.nbi.abtId,4); - printf(" CID: %02x\n",nti.nbi.btCid); - if (nti.nbi.szInfLen>0) + // Let the reader only try once to find a tag + nfc_configure(pnd,NDO_INFINITE_SELECT,false); + + // Configure the CRC and Parity settings + nfc_configure(pnd,NDO_HANDLE_CRC,true); + nfc_configure(pnd,NDO_HANDLE_PARITY,true); + + // Enable field so more power consuming cards can power themselves up + nfc_configure(pnd,NDO_ACTIVATE_FIELD,true); + + printf("Connected to NFC reader: %s\n\n",pnd->acName); + + // Poll for a ISO14443A (MIFARE) tag + if (nfc_initiator_select_tag(pnd,NM_ISO14443A_106,NULL,0,&nti)) { - printf(" INF: "); print_hex(nti.nbi.abtInf,nti.nbi.szInfLen); + printf("The following (NFC) ISO14443A tag was found:\n\n"); + printf(" ATQA (SENS_RES): "); print_hex(nti.nai.abtAtqa,2); + printf(" UID (NFCID%c): ",(nti.nai.abtUid[0]==0x08?'3':'1')); print_hex(nti.nai.abtUid,nti.nai.szUidLen); + printf(" SAK (SEL_RES): "); print_hex(&nti.nai.btSak,1); + if (nti.nai.szAtsLen) + { + printf(" ATS (ATR): "); + print_hex(nti.nai.abtAts,nti.nai.szAtsLen); + } } - printf("PARAMS: %02x %02x %02x %02x\n",nti.nbi.btParam1,nti.nbi.btParam2,nti.nbi.btParam3,nti.nbi.btParam4); - } - // Poll for a Jewel tag - if (nfc_initiator_select_tag(pnd,NM_JEWEL_106,NULL,0,&nti)) - { - // No test results yet - printf("jewel\n"); - } + // Poll for a Felica tag + if (nfc_initiator_select_tag(pnd,NM_FELICA_212,abtFelica,5,&nti) || nfc_initiator_select_tag(pnd,NM_FELICA_424,abtFelica,5,&nti)) + { + printf("The following (NFC) Felica tag was found:\n\n"); + printf("%18s","ID (NFCID2): "); print_hex(nti.nfi.abtId,8); + printf("%18s","Parameter (PAD): "); print_hex(nti.nfi.abtPad,8); + } - nfc_disconnect(pnd); - } + // Poll for a ISO14443B tag + if (nfc_initiator_select_tag(pnd,NM_ISO14443B_106,(byte_t*)"\x00",1,&nti)) + { + printf("The following (NFC) ISO14443-B tag was found:\n\n"); + printf(" ATQB: "); print_hex(nti.nbi.abtAtqb,12); + printf(" ID: "); print_hex(nti.nbi.abtId,4); + printf(" CID: %02x\n",nti.nbi.btCid); + if (nti.nbi.szInfLen>0) + { + printf(" INF: "); print_hex(nti.nbi.abtInf,nti.nbi.szInfLen); + } + printf("PARAMS: %02x %02x %02x %02x\n",nti.nbi.btParam1,nti.nbi.btParam2,nti.nbi.btParam3,nti.nbi.btParam4); + } + + // Poll for a Jewel tag + if (nfc_initiator_select_tag(pnd,NM_JEWEL_106,NULL,0,&nti)) + { + // No test results yet + printf("jewel\n"); + } + + nfc_disconnect(pnd); + } free (pnddDevices); return 0; diff --git a/src/lib/drivers/acr122.c b/src/lib/drivers/acr122.c index f307138..740d0bc 100644 --- a/src/lib/drivers/acr122.c +++ b/src/lib/drivers/acr122.c @@ -156,32 +156,32 @@ acr122_list_devices(nfc_device_desc_t pnddDevices[], size_t szDevices, size_t *p if (SCardConnect(*pscc,acDeviceNames + szPos,SCARD_SHARE_EXCLUSIVE,SCARD_PROTOCOL_T0 | SCARD_PROTOCOL_T1,&(as.hCard),(void*)&(as.ioCard.dwProtocol)) != SCARD_S_SUCCESS) { // Connect to ACR122 firmware version >2.0 - if (SCardConnect(*pscc,pndd->acDevice,SCARD_SHARE_DIRECT,0,&(as.hCard),(void*)&(as.ioCard.dwProtocol)) != SCARD_S_SUCCESS) + if (SCardConnect(*pscc,acDeviceNames + szPos,SCARD_SHARE_DIRECT,0,&(as.hCard),(void*)&(as.ioCard.dwProtocol)) != SCARD_S_SUCCESS) { // We can not connect to this device. continue; } } - // Configure I/O settings for card communication - as.ioCard.cbPciLength = sizeof(SCARD_IO_REQUEST); + // Configure I/O settings for card communication + as.ioCard.cbPciLength = sizeof(SCARD_IO_REQUEST); - // Retrieve the current firmware version - pcFirmware = acr122_firmware((nfc_device_t*)&as); - if (strstr(pcFirmware,FIRMWARE_TEXT) != NULL) - { - // Supported ACR122 device found - strncpy(pnddDevices[*pszDeviceFound].acDevice, acDeviceNames + szPos, BUFSIZ - 1); - pnddDevices[*pszDeviceFound].acDevice[BUFSIZ - 1] = '\0'; - pnddDevices[*pszDeviceFound].pcDriver = ACR122_DRIVER_NAME; - pnddDevices[*pszDeviceFound].uiBusIndex = uiBusIndex; - (*pszDeviceFound)++; - } - else - { - DBG("%s", "Firmware version mismatch"); - } - SCardDisconnect(as.hCard,SCARD_LEAVE_CARD); + // Retrieve the current firmware version + pcFirmware = acr122_firmware((nfc_device_t*)&as); + if (strstr(pcFirmware,FIRMWARE_TEXT) != NULL) + { + // Supported ACR122 device found + strncpy(pnddDevices[*pszDeviceFound].acDevice, acDeviceNames + szPos, BUFSIZ - 1); + pnddDevices[*pszDeviceFound].acDevice[BUFSIZ - 1] = '\0'; + pnddDevices[*pszDeviceFound].pcDriver = ACR122_DRIVER_NAME; + pnddDevices[*pszDeviceFound].uiBusIndex = uiBusIndex; + (*pszDeviceFound)++; + } + else + { + DBG("%s", "Firmware version mismatch"); + } + SCardDisconnect(as.hCard,SCARD_LEAVE_CARD); // Find next device name position while (acDeviceNames[szPos++] != '\0');