diff --git a/contrib/win32/err.h b/contrib/win32/err.h index 20c9a57..fab9ec7 100644 --- a/contrib/win32/err.h +++ b/contrib/win32/err.h @@ -4,15 +4,15 @@ #include #define warnx(...) do { \ - fprintf (stderr, __VA_ARGS__); \ - fprintf (stderr, "\n"); \ -} while (0) + fprintf (stderr, __VA_ARGS__); \ + fprintf (stderr, "\n"); \ + } while (0) #define errx(code, ...) do { \ - fprintf (stderr, __VA_ARGS__); \ - fprintf (stderr, "\n"); \ - exit (code); \ -} while (0) + fprintf (stderr, __VA_ARGS__); \ + fprintf (stderr, "\n"); \ + exit (code); \ + } while (0) #define err errx diff --git a/examples/nfc-anticol.c b/examples/nfc-anticol.c index e299121..27837df 100644 --- a/examples/nfc-anticol.c +++ b/examples/nfc-anticol.c @@ -277,13 +277,13 @@ main (int argc, char *argv[]) // Request ATS, this only applies to tags that support ISO 14443A-4 if (abtRx[0] & SAK_FLAG_ATS_SUPPORTED) { - iso_ats_supported = true; + iso_ats_supported = true; } if ((abtRx[0] & SAK_FLAG_ATS_SUPPORTED) || force_rats) { iso14443a_crc_append(abtRats, 2); if (transmit_bytes (abtRats, 4)) { - memcpy (abtAts, abtRx, szRx); - szAts = szRx; + memcpy (abtAts, abtRx, szRx); + szAts = szRx; } } @@ -295,25 +295,25 @@ main (int argc, char *argv[]) switch (szCL) { case 1: printf ("%02x%02x%02x%02x", abtRawUid[0], abtRawUid[1], abtRawUid[2], abtRawUid[3]); - break; + break; case 2: printf ("%02x%02x%02x", abtRawUid[1], abtRawUid[2], abtRawUid[3]); printf ("%02x%02x%02x%02x", abtRawUid[4], abtRawUid[5], abtRawUid[6], abtRawUid[7]); - break; + break; case 3: printf ("%02x%02x%02x", abtRawUid[1], abtRawUid[2], abtRawUid[3]); printf ("%02x%02x%02x", abtRawUid[5], abtRawUid[6], abtRawUid[7]); printf ("%02x%02x%02x%02x", abtRawUid[8], abtRawUid[9], abtRawUid[10], abtRawUid[11]); - break; + break; } printf("\n"); printf("ATQA: %02x%02x\n SAK: %02x\n", abtAtqa[1], abtAtqa[0], abtSak); if (szAts > 1) { // if = 1, it's not actual ATS but error code - if (force_rats && ! iso_ats_supported) { - printf(" RATS forced\n"); - } - printf(" ATS: "); - print_hex (abtAts, szAts); + if (force_rats && ! iso_ats_supported) { + printf(" RATS forced\n"); + } + printf(" ATS: "); + print_hex (abtAts, szAts); } nfc_close (pnd); diff --git a/examples/nfc-dep-target.c b/examples/nfc-dep-target.c index ecbbd3c..8202657 100644 --- a/examples/nfc-dep-target.c +++ b/examples/nfc-dep-target.c @@ -64,7 +64,7 @@ main (int argc, const char *argv[]) uint8_t abtRx[MAX_FRAME_LEN]; int szRx; uint8_t abtTx[] = "Hello Mars!"; - #define MAX_DEVICE_COUNT 2 +#define MAX_DEVICE_COUNT 2 nfc_connstring connstrings[MAX_DEVICE_COUNT]; size_t szDeviceFound = nfc_list_devices (NULL, connstrings, MAX_DEVICE_COUNT); // Little hack to allow using nfc-dep-initiator & nfc-dep-target from @@ -96,7 +96,7 @@ main (int argc, const char *argv[]) .abtNFCID3 = { 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xff, 0x00, 0x00 }, .szGB = 4, .abtGB = { 0x12, 0x34, 0x56, 0x78 }, - .ndm = NDM_UNDEFINED, + .ndm = NDM_UNDEFINED, /* These bytes are not used by nfc_target_init: the chip will provide them automatically to the initiator */ .btDID = 0x00, .btBS = 0x00, diff --git a/examples/nfc-emulate-forum-tag2.c b/examples/nfc-emulate-forum-tag2.c index 621833c..adc989d 100644 --- a/examples/nfc-emulate-forum-tag2.c +++ b/examples/nfc-emulate-forum-tag2.c @@ -78,7 +78,7 @@ stop_emulation (int sig) { (void)sig; if (pnd) { - nfc_abort_command(pnd); + nfc_abort_command(pnd); } else { exit (EXIT_FAILURE); } diff --git a/examples/nfc-emulate-uid.c b/examples/nfc-emulate-uid.c index 93ee0f5..f847e05 100644 --- a/examples/nfc-emulate-uid.c +++ b/examples/nfc-emulate-uid.c @@ -178,27 +178,27 @@ main (int argc, char *argv[]) if ((szRecvBits = nfc_target_receive_bits (pnd, abtRecv, sizeof (abtRecv), 0)) > 0) { // Prepare the command to send back for the anti-collision request switch (szRecvBits) { - case 7: // Request or Wakeup - pbtTx = abtAtqa; - szTxBits = 16; - // New anti-collsion session started - if (!quiet_output) - printf ("\n"); - break; + case 7: // Request or Wakeup + pbtTx = abtAtqa; + szTxBits = 16; + // New anti-collsion session started + if (!quiet_output) + printf ("\n"); + break; - case 16: // Select All - pbtTx = abtUidBcc; - szTxBits = 40; - break; + case 16: // Select All + pbtTx = abtUidBcc; + szTxBits = 40; + break; - case 72: // Select Tag - pbtTx = abtSak; - szTxBits = 24; - break; + case 72: // Select Tag + pbtTx = abtSak; + szTxBits = 24; + break; - default: // unknown length? - szTxBits = 0; - break; + default: // unknown length? + szTxBits = 0; + break; } if (!quiet_output) { diff --git a/examples/nfc-mfsetuid.c b/examples/nfc-mfsetuid.c index 0fa64f7..eade4b8 100644 --- a/examples/nfc-mfsetuid.c +++ b/examples/nfc-mfsetuid.c @@ -163,13 +163,13 @@ main (int argc, char *argv[]) } else if (0 == strcmp (argv[arg], "-q")) { quiet_output = true; } else if (strlen(argv[arg]) == 8) { - for(i= 0 ; i < 4 ; ++i) { - memcpy(tmp, argv[arg]+i*2, 2); - sscanf(tmp, "%02x", &c); - abtData[i]= (char) c; - } - abtData[4]= abtData[0] ^ abtData[1] ^ abtData[2] ^ abtData[3]; - iso14443a_crc_append (abtData, 16); + for(i= 0 ; i < 4 ; ++i) { + memcpy(tmp, argv[arg]+i*2, 2); + sscanf(tmp, "%02x", &c); + abtData[i]= (char) c; + } + abtData[4]= abtData[0] ^ abtData[1] ^ abtData[2] ^ abtData[3]; + iso14443a_crc_append (abtData, 16); } else { ERR ("%s is not supported option.", argv[arg]); print_usage (argv); @@ -305,29 +305,29 @@ main (int argc, char *argv[]) // Request ATS, this only applies to tags that support ISO 14443A-4 if (abtRx[0] & SAK_FLAG_ATS_SUPPORTED) { - iso_ats_supported = true; + iso_ats_supported = true; } printf ("\nFound tag with\n UID: "); switch (szCL) { case 1: printf ("%02x%02x%02x%02x", abtRawUid[0], abtRawUid[1], abtRawUid[2], abtRawUid[3]); - break; + break; case 2: printf ("%02x%02x%02x", abtRawUid[1], abtRawUid[2], abtRawUid[3]); printf ("%02x%02x%02x%02x", abtRawUid[4], abtRawUid[5], abtRawUid[6], abtRawUid[7]); - break; + break; case 3: printf ("%02x%02x%02x", abtRawUid[1], abtRawUid[2], abtRawUid[3]); printf ("%02x%02x%02x", abtRawUid[5], abtRawUid[6], abtRawUid[7]); printf ("%02x%02x%02x%02x", abtRawUid[8], abtRawUid[9], abtRawUid[10], abtRawUid[11]); - break; + break; } printf("\n"); printf("ATQA: %02x%02x\n SAK: %02x\n", abtAtqa[1], abtAtqa[0], abtSak); if (szAts > 1) { // if = 1, it's not actual ATS but error code - printf(" ATS: "); - print_hex (abtAts, szAts); + printf(" ATS: "); + print_hex (abtAts, szAts); } printf("\n"); diff --git a/examples/nfc-relay.c b/examples/nfc-relay.c index 77ee043..97b97fc 100644 --- a/examples/nfc-relay.c +++ b/examples/nfc-relay.c @@ -205,7 +205,7 @@ main (int argc, char *argv[]) } // Forward the frame to the original tag if ((szTagRxBits = nfc_initiator_transceive_bits - (pndReader, abtReaderRx, (size_t) szReaderRxBits, abtReaderRxPar, abtTagRx, abtTagRxPar)) > 0) { + (pndReader, abtReaderRx, (size_t) szReaderRxBits, abtReaderRxPar, abtTagRx, abtTagRxPar)) > 0) { // Redirect the answer back to the reader if (nfc_target_send_bits (pndTag, abtTagRx, szTagRxBits, abtTagRxPar) < 0) { nfc_perror (pndTag, "nfc_target_send_bits"); diff --git a/examples/pn53x-sam.c b/examples/pn53x-sam.c index 4a8e24d..67c551e 100644 --- a/examples/pn53x-sam.c +++ b/examples/pn53x-sam.c @@ -125,14 +125,14 @@ main (int argc, const char *argv[]) } switch (mode) { - case PSM_VIRTUAL_CARD: + case PSM_VIRTUAL_CARD: { printf ("Now the SAM is readable for 1 minute from an external reader.\n"); wait_one_minute (); } break; - case PSM_WIRED_CARD: + case PSM_WIRED_CARD: { nfc_target nt; @@ -169,7 +169,7 @@ main (int argc, const char *argv[]) } break; - case PSM_DUAL_CARD: + case PSM_DUAL_CARD: { uint8_t abtRx[MAX_FRAME_LEN]; @@ -197,8 +197,8 @@ main (int argc, const char *argv[]) // wait_one_minute (); } break; - case PSM_NORMAL: - break; + case PSM_NORMAL: + break; } ret = EXIT_SUCCESS; diff --git a/examples/pn53x-tamashell.c b/examples/pn53x-tamashell.c index 8e8e496..7af4d74 100644 --- a/examples/pn53x-tamashell.c +++ b/examples/pn53x-tamashell.c @@ -148,7 +148,7 @@ int main(int argc, const char* argv[]) sscanf(cmd + offset, "%d", &s); printf("Pause for %i msecs\n", s); if (s>0) { - sleep(s * SUSP_TIME); + sleep(s * SUSP_TIME); } free(cmd); continue; diff --git a/include/nfc/nfc-emulation.h b/include/nfc/nfc-emulation.h index ed67dd4..523eb78 100644 --- a/include/nfc/nfc-emulation.h +++ b/include/nfc/nfc-emulation.h @@ -32,29 +32,29 @@ extern "C" { #endif /* __cplusplus */ -struct nfc_emulator; -struct nfc_emulation_state_machine; + struct nfc_emulator; + struct nfc_emulation_state_machine; -/** - * @struct nfc_emulator - * @brief NFC emulator structure - */ -struct nfc_emulator { - nfc_target *target; - struct nfc_emulation_state_machine *state_machine; - void *user_data; -}; + /** + * @struct nfc_emulator + * @brief NFC emulator structure + */ + struct nfc_emulator { + nfc_target *target; + struct nfc_emulation_state_machine *state_machine; + void *user_data; + }; -/** - * @struct nfc_emulation_state_machine - * @brief NFC emulation state machine structure - */ -struct nfc_emulation_state_machine { - int (*io)(struct nfc_emulator *emulator, const uint8_t *data_in, const size_t data_in_len, uint8_t *data_out, const size_t data_out_len); - void *data; -}; + /** + * @struct nfc_emulation_state_machine + * @brief NFC emulation state machine structure + */ + struct nfc_emulation_state_machine { + int (*io)(struct nfc_emulator *emulator, const uint8_t *data_in, const size_t data_in_len, uint8_t *data_out, const size_t data_out_len); + void *data; + }; -NFC_EXPORT int nfc_emulate_target (nfc_device* pnd, struct nfc_emulator *emulator); + NFC_EXPORT int nfc_emulate_target (nfc_device* pnd, struct nfc_emulator *emulator); #ifdef __cplusplus } diff --git a/include/nfc/nfc-types.h b/include/nfc/nfc-types.h index 6e41698..0799c0f 100644 --- a/include/nfc/nfc-types.h +++ b/include/nfc/nfc-types.h @@ -48,79 +48,79 @@ typedef char nfc_connstring[1024]; * Properties */ typedef enum { -/** - * Default command processing timeout - * Property value's (duration) unit is ms and 0 means no timeout (infinite). - * Default value is set by driver layer - */ + /** + * Default command processing timeout + * Property value's (duration) unit is ms and 0 means no timeout (infinite). + * Default value is set by driver layer + */ NP_TIMEOUT_COMMAND, -/** - * Timeout between ATR_REQ and ATR_RES - * When the device is in initiator mode, a target is considered as mute if no - * valid ATR_RES is received within this timeout value. - * Default value for this property is 103 ms on PN53x based devices. - */ + /** + * Timeout between ATR_REQ and ATR_RES + * When the device is in initiator mode, a target is considered as mute if no + * valid ATR_RES is received within this timeout value. + * Default value for this property is 103 ms on PN53x based devices. + */ NP_TIMEOUT_ATR, -/** - * Timeout value to give up reception from the target in case of no answer. - * Default value for this property is 52 ms). - */ + /** + * Timeout value to give up reception from the target in case of no answer. + * Default value for this property is 52 ms). + */ NP_TIMEOUT_COM, /** Let the PN53X chip handle the CRC bytes. This means that the chip appends - * the CRC bytes to the frames that are transmitted. It will parse the last - * bytes from received frames as incoming CRC bytes. They will be verified - * against the used modulation and protocol. If an frame is expected with - * incorrect CRC bytes this option should be disabled. Example frames where - * this is useful are the ATQA and UID+BCC that are transmitted without CRC - * bytes during the anti-collision phase of the ISO14443-A protocol. */ + * the CRC bytes to the frames that are transmitted. It will parse the last + * bytes from received frames as incoming CRC bytes. They will be verified + * against the used modulation and protocol. If an frame is expected with + * incorrect CRC bytes this option should be disabled. Example frames where + * this is useful are the ATQA and UID+BCC that are transmitted without CRC + * bytes during the anti-collision phase of the ISO14443-A protocol. */ NP_HANDLE_CRC, -/** Parity bits in the network layer of ISO14443-A are by default generated and - * validated in the PN53X chip. This is a very convenient feature. On certain - * times though it is useful to get full control of the transmitted data. The - * proprietary MIFARE Classic protocol uses for example custom (encrypted) - * parity bits. For interoperability it is required to be completely - * compatible, including the arbitrary parity bits. When this option is - * disabled, the functions to communicating bits should be used. */ + /** Parity bits in the network layer of ISO14443-A are by default generated and + * validated in the PN53X chip. This is a very convenient feature. On certain + * times though it is useful to get full control of the transmitted data. The + * proprietary MIFARE Classic protocol uses for example custom (encrypted) + * parity bits. For interoperability it is required to be completely + * compatible, including the arbitrary parity bits. When this option is + * disabled, the functions to communicating bits should be used. */ NP_HANDLE_PARITY, -/** This option can be used to enable or disable the electronic field of the - * NFC device. */ + /** This option can be used to enable or disable the electronic field of the + * NFC device. */ NP_ACTIVATE_FIELD, -/** The internal CRYPTO1 co-processor can be used to transmit messages - * encrypted. This option is automatically activated after a successful MIFARE - * Classic authentication. */ + /** The internal CRYPTO1 co-processor can be used to transmit messages + * encrypted. This option is automatically activated after a successful MIFARE + * Classic authentication. */ NP_ACTIVATE_CRYPTO1, -/** The default configuration defines that the PN53X chip will try indefinitely - * to invite a tag in the field to respond. This could be desired when it is - * certain a tag will enter the field. On the other hand, when this is - * uncertain, it will block the application. This option could best be compared - * to the (NON)BLOCKING option used by (socket)network programming. */ + /** The default configuration defines that the PN53X chip will try indefinitely + * to invite a tag in the field to respond. This could be desired when it is + * certain a tag will enter the field. On the other hand, when this is + * uncertain, it will block the application. This option could best be compared + * to the (NON)BLOCKING option used by (socket)network programming. */ NP_INFINITE_SELECT, -/** If this option is enabled, frames that carry less than 4 bits are allowed. - * According to the standards these frames should normally be handles as - * invalid frames. */ + /** If this option is enabled, frames that carry less than 4 bits are allowed. + * According to the standards these frames should normally be handles as + * invalid frames. */ NP_ACCEPT_INVALID_FRAMES, -/** If the NFC device should only listen to frames, it could be useful to let - * it gather multiple frames in a sequence. They will be stored in the internal - * FIFO of the PN53X chip. This could be retrieved by using the receive data - * functions. Note that if the chip runs out of bytes (FIFO = 64 bytes long), - * it will overwrite the first received frames, so quick retrieving of the - * received data is desirable. */ + /** If the NFC device should only listen to frames, it could be useful to let + * it gather multiple frames in a sequence. They will be stored in the internal + * FIFO of the PN53X chip. This could be retrieved by using the receive data + * functions. Note that if the chip runs out of bytes (FIFO = 64 bytes long), + * it will overwrite the first received frames, so quick retrieving of the + * received data is desirable. */ NP_ACCEPT_MULTIPLE_FRAMES, -/** This option can be used to enable or disable the auto-switching mode to - * ISO14443-4 is device is compliant. - * In initiator mode, it means that NFC chip will send RATS automatically when - * select and it will automatically poll for ISO14443-4 card when ISO14443A is - * requested. - * In target mode, with a NFC chip compliant (ie. PN532), the chip will - * emulate a 14443-4 PICC using hardware capability */ + /** This option can be used to enable or disable the auto-switching mode to + * ISO14443-4 is device is compliant. + * In initiator mode, it means that NFC chip will send RATS automatically when + * select and it will automatically poll for ISO14443-4 card when ISO14443A is + * requested. + * In target mode, with a NFC chip compliant (ie. PN532), the chip will + * emulate a 14443-4 PICC using hardware capability */ NP_AUTO_ISO14443_4, -/** Use automatic frames encapsulation and chaining. */ + /** Use automatic frames encapsulation and chaining. */ NP_EASY_FRAMING, -/** Force the chip to switch in ISO14443-A */ + /** Force the chip to switch in ISO14443-A */ NP_FORCE_ISO14443_A, -/** Force the chip to switch in ISO14443-B */ + /** Force the chip to switch in ISO14443-B */ NP_FORCE_ISO14443_B, -/** Force the chip to run at 106 kbps */ + /** Force the chip to run at 106 kbps */ NP_FORCE_SPEED_106, } nfc_property; @@ -142,22 +142,22 @@ typedef enum { * @brief NFC target information in D.E.P. (Data Exchange Protocol) see ISO/IEC 18092 (NFCIP-1) */ typedef struct { -/** NFCID3 */ + /** NFCID3 */ uint8_t abtNFCID3[10]; -/** DID */ + /** DID */ uint8_t btDID; -/** Supported send-bit rate */ + /** Supported send-bit rate */ uint8_t btBS; -/** Supported receive-bit rate */ + /** Supported receive-bit rate */ uint8_t btBR; -/** Timeout value */ + /** Timeout value */ uint8_t btTO; -/** PP Parameters */ + /** PP Parameters */ uint8_t btPP; -/** General Bytes */ + /** General Bytes */ uint8_t abtGB[48]; size_t szGB; -/** DEP mode */ + /** DEP mode */ nfc_dep_mode ndm; } nfc_dep_info; @@ -191,13 +191,13 @@ typedef struct { * @brief NFC ISO14443B tag information */ typedef struct { -/** abtPupi store PUPI contained in ATQB (Answer To reQuest of type B) (see ISO14443-3) */ + /** abtPupi store PUPI contained in ATQB (Answer To reQuest of type B) (see ISO14443-3) */ uint8_t abtPupi[4]; -/** abtApplicationData store Application Data contained in ATQB (see ISO14443-3) */ + /** abtApplicationData store Application Data contained in ATQB (see ISO14443-3) */ uint8_t abtApplicationData[4]; -/** abtProtocolInfo store Protocol Info contained in ATQB (see ISO14443-3) */ + /** abtProtocolInfo store Protocol Info contained in ATQB (see ISO14443-3) */ uint8_t abtProtocolInfo[3]; -/** ui8CardIdentifier store CID (Card Identifier) attributted by PCD to the PICC */ + /** ui8CardIdentifier store CID (Card Identifier) attributted by PCD to the PICC */ uint8_t ui8CardIdentifier; } nfc_iso14443b_info; @@ -206,13 +206,13 @@ typedef struct { * @brief NFC ISO14443B' tag information */ typedef struct { -/** DIV: 4 LSBytes of tag serial number */ + /** DIV: 4 LSBytes of tag serial number */ uint8_t abtDIV[4]; -/** Software version & type of REPGEN */ + /** Software version & type of REPGEN */ uint8_t btVerLog; -/** Config Byte, present if long REPGEN */ + /** Config Byte, present if long REPGEN */ uint8_t btConfig; -/** ATR, if any */ + /** ATR, if any */ size_t szAtrLen; uint8_t abtAtr[33]; } nfc_iso14443bi_info; diff --git a/include/nfc/nfc.h b/include/nfc/nfc.h index eb2456d..1009aed 100644 --- a/include/nfc/nfc.h +++ b/include/nfc/nfc.h @@ -34,27 +34,27 @@ # include # ifdef _WIN32 - /* Windows platform */ +/* Windows platform */ # ifndef _WINDLL - /* CMake compilation */ +/* CMake compilation */ # ifdef nfc_EXPORTS # define NFC_EXPORT __declspec(dllexport) # else - /* nfc_EXPORTS */ +/* nfc_EXPORTS */ # define NFC_EXPORT __declspec(dllimport) # endif - /* nfc_EXPORTS */ +/* nfc_EXPORTS */ # else - /* _WINDLL */ - /* Manual makefile */ +/* _WINDLL */ +/* Manual makefile */ # define NFC_EXPORT # endif - /* _WINDLL */ +/* _WINDLL */ # else - /* _WIN32 */ +/* _WIN32 */ # define NFC_EXPORT # endif - /* _WIN32 */ +/* _WIN32 */ # include @@ -62,11 +62,11 @@ extern "C" { # endif // __cplusplus -/* Library initialization/deinitialization */ + /* Library initialization/deinitialization */ NFC_EXPORT void nfc_init(nfc_context *context); NFC_EXPORT void nfc_exit(nfc_context *context); -/* NFC Device/Hardware manipulation */ + /* NFC Device/Hardware manipulation */ NFC_EXPORT bool nfc_get_default_device (nfc_connstring *connstring); NFC_EXPORT nfc_device *nfc_open (nfc_context *context, const nfc_connstring connstring); NFC_EXPORT void nfc_close (nfc_device *pnd); @@ -74,7 +74,7 @@ extern "C" { NFC_EXPORT size_t nfc_list_devices (nfc_context *context, nfc_connstring connstrings[], size_t connstrings_len); NFC_EXPORT int nfc_idle (nfc_device *pnd); -/* NFC initiator: act as "reader" */ + /* NFC initiator: act as "reader" */ NFC_EXPORT int nfc_initiator_init (nfc_device *pnd); NFC_EXPORT int nfc_initiator_select_passive_target (nfc_device *pnd, const nfc_modulation nm, const uint8_t *pbtInitData, const size_t szInitData, nfc_target *pnt); NFC_EXPORT int nfc_initiator_list_passive_targets (nfc_device *pnd, const nfc_modulation nm, nfc_target ant[], const size_t szTargets); @@ -88,30 +88,30 @@ extern "C" { NFC_EXPORT int nfc_initiator_transceive_bits_timed (nfc_device *pnd, const uint8_t *pbtTx, const size_t szTxBits, const uint8_t *pbtTxPar, uint8_t *pbtRx, uint8_t *pbtRxPar, uint32_t *cycles); NFC_EXPORT int nfc_initiator_target_is_present (nfc_device *pnd, const nfc_target nt); -/* NFC target: act as tag (i.e. MIFARE Classic) or NFC target device. */ + /* NFC target: act as tag (i.e. MIFARE Classic) or NFC target device. */ NFC_EXPORT int nfc_target_init (nfc_device *pnd, nfc_target *pnt, uint8_t *pbtRx, const size_t szRx, int timeout); NFC_EXPORT int nfc_target_send_bytes (nfc_device *pnd, const uint8_t *pbtTx, const size_t szTx, int timeout); NFC_EXPORT int nfc_target_receive_bytes (nfc_device *pnd, uint8_t *pbtRx, const size_t szRx, int timeout); NFC_EXPORT int nfc_target_send_bits (nfc_device *pnd, const uint8_t *pbtTx, const size_t szTxBits, const uint8_t *pbtTxPar); NFC_EXPORT int nfc_target_receive_bits (nfc_device *pnd, uint8_t *pbtRx, const size_t szRx, uint8_t *pbtRxPar); -/* Error reporting */ + /* Error reporting */ NFC_EXPORT const char *nfc_strerror (const nfc_device *pnd); NFC_EXPORT int nfc_strerror_r (const nfc_device *pnd, char *buf, size_t buflen); NFC_EXPORT void nfc_perror (const nfc_device *pnd, const char *s); NFC_EXPORT int nfc_device_get_last_error (const nfc_device *pnd); -/* Special data accessors */ + /* Special data accessors */ NFC_EXPORT const char *nfc_device_get_name (nfc_device *pnd); NFC_EXPORT const char *nfc_device_get_connstring (nfc_device *pnd); NFC_EXPORT int nfc_device_get_supported_modulation (nfc_device *pnd, const nfc_mode mode, const nfc_modulation_type **const supported_mt); NFC_EXPORT int nfc_device_get_supported_baud_rate (nfc_device *pnd, const nfc_modulation_type nmt, const nfc_baud_rate **const supported_br); -/* Properties accessors */ + /* Properties accessors */ NFC_EXPORT int nfc_device_set_property_int (nfc_device *pnd, const nfc_property property, const int value); NFC_EXPORT int nfc_device_set_property_bool (nfc_device *pnd, const nfc_property property, const bool bEnable); -/* Misc. functions */ + /* Misc. functions */ NFC_EXPORT void iso14443a_crc (uint8_t *pbtData, size_t szLen, uint8_t *pbtCrc); NFC_EXPORT void iso14443a_crc_append (uint8_t *pbtData, size_t szLen); NFC_EXPORT uint8_t *iso14443a_locate_historical_bytes (uint8_t *pbtAts, size_t szAts, size_t *pszTk); @@ -119,76 +119,76 @@ extern "C" { NFC_EXPORT const char *nfc_version (void); NFC_EXPORT int nfc_device_get_information_about (nfc_device *pnd, char *buf, size_t buflen); -/* String converter functions */ + /* String converter functions */ NFC_EXPORT const char * str_nfc_modulation_type (const nfc_modulation_type nmt); NFC_EXPORT const char * str_nfc_baud_rate (const nfc_baud_rate nbr); -/* Error codes */ -/** @ingroup error - * @hideinitializer - * Success (no error) - */ + /* Error codes */ + /** @ingroup error + * @hideinitializer + * Success (no error) + */ #define NFC_SUCCESS 0 -/** @ingroup error - * @hideinitializer - * Input / output error, device may not be usable anymore without re-open it - */ + /** @ingroup error + * @hideinitializer + * Input / output error, device may not be usable anymore without re-open it + */ #define NFC_EIO -1 -/** @ingroup error - * @hideinitializer - * Invalid argument(s) - */ + /** @ingroup error + * @hideinitializer + * Invalid argument(s) + */ #define NFC_EINVARG -2 -/** @ingroup error - * @hideinitializer - * Operation not supported by device - */ + /** @ingroup error + * @hideinitializer + * Operation not supported by device + */ #define NFC_EDEVNOTSUPP -3 -/** @ingroup error - * @hideinitializer - * No such device - */ + /** @ingroup error + * @hideinitializer + * No such device + */ #define NFC_ENOTSUCHDEV -4 -/** @ingroup error - * @hideinitializer - * Buffer overflow - */ + /** @ingroup error + * @hideinitializer + * Buffer overflow + */ #define NFC_EOVFLOW -5 -/** @ingroup error - * @hideinitializer - * Operation timed out - */ + /** @ingroup error + * @hideinitializer + * Operation timed out + */ #define NFC_ETIMEOUT -6 -/** @ingroup error - * @hideinitializer - * Operation aborted (by user) - */ + /** @ingroup error + * @hideinitializer + * Operation aborted (by user) + */ #define NFC_EOPABORTED -7 -/** @ingroup error - * @hideinitializer - * Not (yet) implemented - */ + /** @ingroup error + * @hideinitializer + * Not (yet) implemented + */ #define NFC_ENOTIMPL -8 -/** @ingroup error - * @hideinitializer - * Target released - */ + /** @ingroup error + * @hideinitializer + * Target released + */ #define NFC_ETGRELEASED -10 -/** @ingroup error - * @hideinitializer - * Error while RF transmission - */ + /** @ingroup error + * @hideinitializer + * Error while RF transmission + */ #define NFC_ERFTRANS -20 -/** @ingroup error - * @hideinitializer - * Software error (allocation, file/pipe creation, etc.) - */ + /** @ingroup error + * @hideinitializer + * Software error (allocation, file/pipe creation, etc.) + */ #define NFC_ESOFT -80 -/** @ingroup error - * @hideinitializer - * Device's internal chip error - */ + /** @ingroup error + * @hideinitializer + * Device's internal chip error + */ #define NFC_ECHIP -90 diff --git a/libnfc/buses/uart_posix.c b/libnfc/buses/uart_posix.c index d14fdea..9ddebf2 100644 --- a/libnfc/buses/uart_posix.c +++ b/libnfc/buses/uart_posix.c @@ -47,7 +47,7 @@ #define LOG_CATEGORY "libnfc.bus.uart" # if defined(__APPLE__) - // FIXME: find UART connection string for PN53X device on Mac OS X when multiples devices are used +// FIXME: find UART connection string for PN53X device on Mac OS X when multiples devices are used const char *serial_ports_device_radix[] = { "tty.SLAB_USBtoUART", NULL }; # elif defined (__FreeBSD__) || defined (__OpenBSD__) const char *serial_ports_device_radix[] = { "cuaU", "cuau", NULL }; @@ -60,7 +60,7 @@ const char *serial_ports_device_radix[] = { "ttyUSB", "ttyS", NULL }; // Work-around to claim uart interface using the c_iflag (software input processing) from the termios struct # define CCLAIMED 0x80000000 -struct serial_port_unix{ +struct serial_port_unix { int fd; // Serial port file descriptor struct termios termios_backup; // Terminal info before using the port struct termios termios_new; // Terminal info during the transaction @@ -143,39 +143,39 @@ uart_set_speed (serial_port sp, const uint32_t uiPortSpeed) // uint32_t <=> speed_t associations by hand. speed_t stPortSpeed = B9600; switch (uiPortSpeed) { - case 9600: - stPortSpeed = B9600; - break; - case 19200: - stPortSpeed = B19200; - break; - case 38400: - stPortSpeed = B38400; - break; + case 9600: + stPortSpeed = B9600; + break; + case 19200: + stPortSpeed = B19200; + break; + case 38400: + stPortSpeed = B38400; + break; # ifdef B57600 - case 57600: - stPortSpeed = B57600; - break; + case 57600: + stPortSpeed = B57600; + break; # endif # ifdef B115200 - case 115200: - stPortSpeed = B115200; - break; + case 115200: + stPortSpeed = B115200; + break; # endif # ifdef B230400 - case 230400: - stPortSpeed = B230400; - break; + case 230400: + stPortSpeed = B230400; + break; # endif # ifdef B460800 - case 460800: - stPortSpeed = B460800; - break; + case 460800: + stPortSpeed = B460800; + break; # endif - default: - log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "Unable to set serial port speed to %d bauds. Speed value must be one of those defined in termios(3).", - uiPortSpeed); - return; + default: + log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "Unable to set serial port speed to %d bauds. Speed value must be one of those defined in termios(3).", + uiPortSpeed); + return; }; // Set port speed (Input and Output) @@ -191,34 +191,34 @@ uart_get_speed (serial_port sp) { uint32_t uiPortSpeed = 0; switch (cfgetispeed (&UART_DATA(sp)->termios_new)) { - case B9600: - uiPortSpeed = 9600; - break; - case B19200: - uiPortSpeed = 19200; - break; - case B38400: - uiPortSpeed = 38400; - break; + case B9600: + uiPortSpeed = 9600; + break; + case B19200: + uiPortSpeed = 19200; + break; + case B38400: + uiPortSpeed = 38400; + break; # ifdef B57600 - case B57600: - uiPortSpeed = 57600; - break; + case B57600: + uiPortSpeed = 57600; + break; # endif # ifdef B115200 - case B115200: - uiPortSpeed = 115200; - break; + case B115200: + uiPortSpeed = 115200; + break; # endif # ifdef B230400 - case B230400: - uiPortSpeed = 230400; - break; + case B230400: + uiPortSpeed = 230400; + break; # endif # ifdef B460800 - case B460800: - uiPortSpeed = 460800; - break; + case B460800: + uiPortSpeed = 460800; + break; # endif } @@ -335,38 +335,38 @@ uart_send (serial_port sp, const uint8_t *pbtTx, const size_t szTx, int timeout) char ** uart_list_ports (void) { - char **res = malloc (sizeof (char *)); - size_t szRes = 1; + char **res = malloc (sizeof (char *)); + size_t szRes = 1; - res[0] = NULL; + res[0] = NULL; - DIR *pdDir = opendir("/dev"); - struct dirent *pdDirEnt; - while ((pdDirEnt = readdir(pdDir)) != NULL) { - if (!isdigit (pdDirEnt->d_name[strlen (pdDirEnt->d_name) - 1])) - continue; + DIR *pdDir = opendir("/dev"); + struct dirent *pdDirEnt; + while ((pdDirEnt = readdir(pdDir)) != NULL) { + if (!isdigit (pdDirEnt->d_name[strlen (pdDirEnt->d_name) - 1])) + continue; - const char **p = serial_ports_device_radix; - while (*p) { - if (!strncmp(pdDirEnt->d_name, *p, strlen (*p))) { - char **res2 = realloc (res, (szRes+1) * sizeof (char *)); - if (!res2) - goto oom; + const char **p = serial_ports_device_radix; + while (*p) { + if (!strncmp(pdDirEnt->d_name, *p, strlen (*p))) { + char **res2 = realloc (res, (szRes+1) * sizeof (char *)); + if (!res2) + goto oom; - res = res2; - if (!(res[szRes-1] = malloc (6 + strlen (pdDirEnt->d_name)))) - goto oom; + res = res2; + if (!(res[szRes-1] = malloc (6 + strlen (pdDirEnt->d_name)))) + goto oom; - sprintf (res[szRes-1], "/dev/%s", pdDirEnt->d_name); + sprintf (res[szRes-1], "/dev/%s", pdDirEnt->d_name); - szRes++; - res[szRes-1] = NULL; - } - p++; - } + szRes++; + res[szRes-1] = NULL; + } + p++; } + } oom: - closedir (pdDir); + closedir (pdDir); - return res; + return res; } diff --git a/libnfc/buses/uart_win32.c b/libnfc/buses/uart_win32.c index 5e3bafa..07461cb 100644 --- a/libnfc/buses/uart_win32.c +++ b/libnfc/buses/uart_win32.c @@ -105,17 +105,17 @@ uart_set_speed (serial_port sp, const uint32_t uiPortSpeed) log_put (LOG_CATEGORY, NFC_PRIORITY_TRACE, "Serial port speed requested to be set to %d bauds.", uiPortSpeed); // Set port speed (Input and Output) switch (uiPortSpeed) { - case 9600: - case 19200: - case 38400: - case 57600: - case 115200: - case 230400: - case 460800: - break; - default: - log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "Unable to set serial port speed to %d bauds. Speed value must be one of these constants: 9600 (default), 19200, 38400, 57600, 115200, 230400 or 460800.", uiPortSpeed); - return; + case 9600: + case 19200: + case 38400: + case 57600: + case 115200: + case 230400: + case 460800: + break; + default: + log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "Unable to set serial port speed to %d bauds. Speed value must be one of these constants: 9600 (default), 19200, 38400, 57600, 115200, 230400 or 460800.", uiPortSpeed); + return; }; spw = (struct serial_port_windows *) sp; @@ -167,8 +167,8 @@ uart_receive (serial_port sp, uint8_t * pbtRx, const size_t szRx, void * abort_p do { log_put (LOG_CATEGORY, NFC_PRIORITY_TRACE, "ReadFile"); res = ReadFile (((struct serial_port_windows *) sp)->hPort, pbtRx + dwTotalBytesReceived, - dwBytesToGet, - &dwBytesReceived, NULL); + dwBytesToGet, + &dwBytesReceived, NULL); dwTotalBytesReceived += dwBytesReceived; @@ -177,8 +177,8 @@ uart_receive (serial_port sp, uint8_t * pbtRx, const size_t szRx, void * abort_p log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "ReadFile error: %u", err); return NFC_EIO; } else if (dwBytesReceived == 0) { - return NFC_ETIMEOUT; - } + return NFC_ETIMEOUT; + } if (((DWORD)szRx) > dwTotalBytesReceived) { dwBytesToGet -= dwBytesReceived; diff --git a/libnfc/chips/pn53x-internal.h b/libnfc/chips/pn53x-internal.h index 56c6d9b..e49a160 100644 --- a/libnfc/chips/pn53x-internal.h +++ b/libnfc/chips/pn53x-internal.h @@ -133,13 +133,13 @@ typedef enum { #else # define PNCMD( X, Y ) { X , Y, #X } # define PNCMD_TRACE( X ) do { \ - for (size_t i=0; i<(sizeof(pn53x_commands)/sizeof(pn53x_command)); i++) { \ - if ( X == pn53x_commands[i].ui8Code ) { \ - log_put( LOG_CATEGORY, NFC_PRIORITY_TRACE, "%s", pn53x_commands[i].abtCommandText ); \ - break; \ - } \ - } \ - } while(0) + for (size_t i=0; i<(sizeof(pn53x_commands)/sizeof(pn53x_command)); i++) { \ + if ( X == pn53x_commands[i].ui8Code ) { \ + log_put( LOG_CATEGORY, NFC_PRIORITY_TRACE, "%s", pn53x_commands[i].abtCommandText ); \ + break; \ + } \ + } \ + } while(0) #endif static const pn53x_command pn53x_commands[] = { @@ -214,16 +214,16 @@ typedef struct { #ifndef LOGGING # define PNREG_TRACE( X ) do { \ - } while(0) + } while(0) #else # define PNREG_TRACE( X ) do { \ - for (size_t i=0; i<(sizeof(pn53x_registers)/sizeof(pn53x_register)); i++) { \ - if ( X == pn53x_registers[i].ui16Address ) { \ - log_put( LOG_CATEGORY, NFC_PRIORITY_TRACE, "%s (%s)", pn53x_registers[i].abtRegisterText, pn53x_registers[i].abtRegisterDescription ); \ - break; \ - } \ - } \ - } while(0) + for (size_t i=0; i<(sizeof(pn53x_registers)/sizeof(pn53x_register)); i++) { \ + if ( X == pn53x_registers[i].ui16Address ) { \ + log_put( LOG_CATEGORY, NFC_PRIORITY_TRACE, "%s (%s)", pn53x_registers[i].abtRegisterText, pn53x_registers[i].abtRegisterDescription ); \ + break; \ + } \ + } \ + } while(0) #endif // Register addresses diff --git a/libnfc/chips/pn53x.c b/libnfc/chips/pn53x.c index 0e9e593..1f7691f 100644 --- a/libnfc/chips/pn53x.c +++ b/libnfc/chips/pn53x.c @@ -271,9 +271,9 @@ pn53x_transceive (struct nfc_device *pnd, const uint8_t *pbtTx, const size_t szT res = NFC_ECHIP; break; }; -/* - { EMFAUTH, "Mifare Authentication Error" }, -*/ + /* + { EMFAUTH, "Mifare Authentication Error" }, + */ if (res < 0) { pnd->last_error = res; @@ -551,7 +551,7 @@ pn53x_decode_target_data (const uint8_t *pbtRawData, size_t szRawData, pn53x_typ pbtRawData += 2; memcpy (pnti->nji.btId, pbtRawData, 4); break; - // Should not happend... + // Should not happend... case NMT_DEP: return NFC_ECHIP; break; @@ -763,16 +763,16 @@ pn53x_set_property_int (struct nfc_device *pnd, const nfc_property property, con switch (property) { case NP_TIMEOUT_COMMAND: CHIP_DATA (pnd)->timeout_command = value; - break; + break; case NP_TIMEOUT_ATR: CHIP_DATA (pnd)->timeout_atr = value; return pn53x_RFConfiguration__Various_timings (pnd, pn53x_int_to_timeout(CHIP_DATA (pnd)->timeout_atr), pn53x_int_to_timeout(CHIP_DATA (pnd)->timeout_communication)); - break; + break; case NP_TIMEOUT_COM: CHIP_DATA (pnd)->timeout_communication = value; return pn53x_RFConfiguration__Various_timings (pnd, pn53x_int_to_timeout(CHIP_DATA (pnd)->timeout_atr), pn53x_int_to_timeout(CHIP_DATA (pnd)->timeout_communication)); break; - // Following properties are invalid (not integer) + // Following properties are invalid (not integer) case NP_HANDLE_CRC: case NP_HANDLE_PARITY: case NP_ACTIVATE_FIELD: @@ -847,10 +847,10 @@ pn53x_set_property_bool (struct nfc_device *pnd, const nfc_property property, co // timings could be tweak better than this, and maybe we can tweak timings // to "gain" a sort-of hardware polling (ie. like PN532 does) if (pn53x_RFConfiguration__MaxRetries (pnd, - (bEnable) ? 0xff : 0x00, // MxRtyATR, default: active = 0xff, passive = 0x02 - (bEnable) ? 0xff : 0x01, // MxRtyPSL, default: 0x01 - (bEnable) ? 0xff : 0x02 // MxRtyPassiveActivation, default: 0xff (0x00 leads to problems with PN531) - ) == 0) + (bEnable) ? 0xff : 0x00, // MxRtyATR, default: active = 0xff, passive = 0x02 + (bEnable) ? 0xff : 0x01, // MxRtyPSL, default: 0x01 + (bEnable) ? 0xff : 0x02 // MxRtyPassiveActivation, default: 0xff (0x00 leads to problems with PN531) + ) == 0) return NFC_SUCCESS; } break; @@ -913,7 +913,7 @@ pn53x_set_property_bool (struct nfc_device *pnd, const nfc_property property, co } return pn53x_write_register (pnd, PN53X_REG_CIU_RxMode, SYMBOL_RX_SPEED, 0x00); break; - // Following properties are invalid (not boolean) + // Following properties are invalid (not boolean) case NP_TIMEOUT_COMMAND: case NP_TIMEOUT_ATR: case NP_TIMEOUT_COM: @@ -941,7 +941,7 @@ pn53x_idle (struct nfc_device *pnd) return res; } } - break; + break; case INITIATOR: // Deselect all active communications if ((res = pn53x_InDeselect (pnd, 0)) < 0) { @@ -962,9 +962,9 @@ pn53x_idle (struct nfc_device *pnd) return res; } } - break; + break; case IDLE: // Nothing to do. - break; + break; }; CHIP_DATA (pnd)->operating_mode = IDLE; return NFC_SUCCESS; @@ -1004,10 +1004,10 @@ pn53x_initiator_init (struct nfc_device *pnd) static int pn53x_initiator_select_passive_target_ext (struct nfc_device *pnd, - const nfc_modulation nm, - const uint8_t *pbtInitData, const size_t szInitData, - nfc_target *pnt, - int timeout) + const nfc_modulation nm, + const uint8_t *pbtInitData, const size_t szInitData, + nfc_target *pnt, + int timeout) { uint8_t abtTargetsData[PN53x_EXTENDED_FRAME__DATA_MAX_LEN]; size_t szTargetsData = sizeof (abtTargetsData); @@ -1118,9 +1118,9 @@ pn53x_initiator_select_passive_target (struct nfc_device *pnd, int pn53x_initiator_poll_target (struct nfc_device *pnd, - const nfc_modulation *pnmModulations, const size_t szModulations, - const uint8_t uiPollNr, const uint8_t uiPeriod, - nfc_target *pnt) + const nfc_modulation *pnmModulations, const size_t szModulations, + const uint8_t uiPollNr, const uint8_t uiPeriod, + nfc_target *pnt) { int res = 0; @@ -1155,7 +1155,7 @@ pn53x_initiator_poll_target (struct nfc_device *pnd, break; default: return NFC_ECHIP; - break; + break; } } else { pn53x_set_property_bool (pnd, NP_INFINITE_SELECT, true); @@ -1186,10 +1186,10 @@ pn53x_initiator_poll_target (struct nfc_device *pnd, int pn53x_initiator_select_dep_target (struct nfc_device *pnd, - const nfc_dep_mode ndm, const nfc_baud_rate nbr, - const nfc_dep_info *pndiInitiator, - nfc_target *pnt, - const int timeout) + const nfc_dep_mode ndm, const nfc_baud_rate nbr, + const nfc_dep_info *pndiInitiator, + nfc_target *pnt, + const int timeout) { const uint8_t abtPassiveInitiatorData[] = { 0x00, 0xff, 0xff, 0x00, 0x0f }; // Only for 212/424 kpbs: First 4 bytes shall be set like this according to NFCIP-1, last byte is TSN (Time Slot Number) const uint8_t * pbtPassiveInitiatorData = NULL; @@ -1323,8 +1323,8 @@ pn53x_initiator_transceive_bytes (struct nfc_device *pnd, const uint8_t *pbtTx, // We have to give the amount of bytes + (the two command bytes 0xD4, 0x42) uint8_t abtRx[PN53x_EXTENDED_FRAME__DATA_MAX_LEN]; if ((res = pn53x_transceive (pnd, abtCmd, szTx + szExtraTxLen, abtRx, sizeof(abtRx), timeout)) < 0) { - pnd->last_error = res; - return pnd->last_error; + pnd->last_error = res; + return pnd->last_error; } const size_t szRxLen = (size_t)res - 1; if (pbtRx != NULL) { @@ -1347,9 +1347,9 @@ static void __pn53x_init_timer(struct nfc_device *pnd, const uint32_t max_cycles // prescaler = 2 => precision: ~369ns timer saturates at ~25ms // prescaler = 10 => precision: ~1.5us timer saturates at ~100ms if (max_cycles > 0xFFFF) { - CHIP_DATA (pnd)->timer_prescaler = ((max_cycles/0xFFFF)-1)/2; + CHIP_DATA (pnd)->timer_prescaler = ((max_cycles/0xFFFF)-1)/2; } else { - CHIP_DATA (pnd)->timer_prescaler = 0; + CHIP_DATA (pnd)->timer_prescaler = 0; } uint16_t reloadval = 0xFFFF; // Initialize timer @@ -1404,9 +1404,9 @@ static uint32_t __pn53x_get_timer(struct nfc_device *pnd, const uint8_t last_cmd } // Correction depending on last parity bit sent parity = (last_cmd_byte >> 7) ^ ((last_cmd_byte >> 6) & 1) ^ - ((last_cmd_byte >> 5) & 1) ^ ((last_cmd_byte >> 4) & 1) ^ - ((last_cmd_byte >> 3) & 1) ^ ((last_cmd_byte >> 2) & 1) ^ - ((last_cmd_byte >> 1) & 1) ^ (last_cmd_byte & 1); + ((last_cmd_byte >> 5) & 1) ^ ((last_cmd_byte >> 4) & 1) ^ + ((last_cmd_byte >> 3) & 1) ^ ((last_cmd_byte >> 2) & 1) ^ + ((last_cmd_byte >> 1) & 1) ^ (last_cmd_byte & 1); parity = parity ? 0:1; // When sent ...YY (cmd ends with logical 1, so when last parity bit is 1): if (parity) { @@ -1676,17 +1676,17 @@ pn53x_target_init (struct nfc_device *pnd, nfc_target *pnt, uint8_t *pbtRx, cons pn53x_set_parameters (pnd, PARAM_14443_4_PICC, false); } } - break; + break; case NMT_FELICA: ptm = PTM_PASSIVE_ONLY; - break; + break; case NMT_DEP: pn53x_set_parameters (pnd, PARAM_AUTO_ATR_RES, true); ptm = PTM_DEP_ONLY; if (pnt->nti.ndi.ndm == NDM_PASSIVE) { ptm |= PTM_PASSIVE_ONLY; // We add passive mode restriction } - break; + break; case NMT_ISO14443B: case NMT_ISO14443BI: case NMT_ISO14443B2SR: @@ -1694,7 +1694,7 @@ pn53x_target_init (struct nfc_device *pnd, nfc_target *pnt, uint8_t *pbtRx, cons case NMT_JEWEL: pnd->last_error = NFC_EDEVNOTSUPP; return pnd->last_error; - break; + break; } // Let the PN53X be activated by the RF level detector from power down mode @@ -1741,7 +1741,7 @@ pn53x_target_init (struct nfc_device *pnd, nfc_target *pnt, uint8_t *pbtRx, cons // Set SystemCode memcpy(abtFeliCaParams+16, pnt->nti.nfi.abtSysCode, 2); pbtFeliCaParams = abtFeliCaParams; - break; + break; case NMT_DEP: // Set NFCID3 @@ -1788,7 +1788,7 @@ pn53x_target_init (struct nfc_device *pnd, nfc_target *pnt, uint8_t *pbtRx, cons abtFeliCaParams[17] = 0xab; pbtFeliCaParams = abtFeliCaParams; - break; + break; case NMT_ISO14443B: case NMT_ISO14443BI: case NMT_ISO14443B2SR: @@ -1796,7 +1796,7 @@ pn53x_target_init (struct nfc_device *pnd, nfc_target *pnt, uint8_t *pbtRx, cons case NMT_JEWEL: pnd->last_error = NFC_EDEVNOTSUPP; return pnd->last_error; - break; + break; } bool targetActivated = false; @@ -1820,13 +1820,13 @@ pn53x_target_init (struct nfc_device *pnd, nfc_target *pnt, uint8_t *pbtRx, cons switch(btActivatedMode & 0x70) { // Baud rate case 0x00: // 106kbps nm.nbr = NBR_106; - break; + break; case 0x10: // 212kbps nm.nbr = NBR_212; - break; + break; case 0x20: // 424kbps nm.nbr = NBR_424; - break; + break; }; if (btActivatedMode & 0x04) { // D.E.P. @@ -1865,8 +1865,8 @@ pn53x_target_init (struct nfc_device *pnd, nfc_target *pnt, uint8_t *pbtRx, cons memcpy (CHIP_DATA (pnd)->current_target, pnt, sizeof(nfc_target)); if (ptm & PTM_ISO14443_4_PICC_ONLY) { - // When PN532 is in PICC target mode, it automatically reply to RATS so - // we don't need to forward this command + // When PN532 is in PICC target mode, it automatically reply to RATS so + // we don't need to forward this command szRx = 0; } } @@ -1943,7 +1943,7 @@ pn53x_target_receive_bytes (struct nfc_device *pnd, uint8_t *pbtRx, const size_t return pnd->last_error; } } - // NO BREAK + // NO BREAK case NMT_JEWEL: case NMT_ISO14443B: case NMT_ISO14443BI: @@ -2048,7 +2048,7 @@ pn53x_target_send_bytes (struct nfc_device *pnd, const uint8_t *pbtTx, const siz return pnd->last_error; } } - // NO BREAK + // NO BREAK case NMT_JEWEL: case NMT_ISO14443B: case NMT_ISO14443BI: @@ -2367,7 +2367,7 @@ pn53x_InAutoPoll (struct nfc_device *pnd, uint8_t abtRx[PN53x_EXTENDED_FRAME__DATA_MAX_LEN]; size_t szRx = sizeof(abtRx); int res = pn53x_transceive (pnd, abtCmd, szTxInAutoPoll, abtRx, szRx, timeout); -szRx = (size_t) res; + szRx = (size_t) res; if (res < 0) { return res; } else if (szRx > 0) { @@ -2428,18 +2428,18 @@ pn53x_InJumpForDEP (struct nfc_device *pnd, switch (nbr) { case NBR_106: abtCmd[2] = 0x00; // baud rate is 106 kbps - break; + break; case NBR_212: abtCmd[2] = 0x01; // baud rate is 212 kbps - break; + break; case NBR_424: abtCmd[2] = 0x02; // baud rate is 424 kbps - break; + break; case NBR_847: case NBR_UNDEFINED: pnd->last_error = NFC_EINVARG; return pnd->last_error; - break; + break; } if (pbtPassiveInitiatorData && (ndm == NDM_PASSIVE)) { /* can't have passive initiator data when using active mode */ @@ -2448,18 +2448,18 @@ pn53x_InJumpForDEP (struct nfc_device *pnd, abtCmd[3] |= 0x01; memcpy (abtCmd + offset, pbtPassiveInitiatorData, 4); offset += 4; - break; + break; case NBR_212: case NBR_424: abtCmd[3] |= 0x01; memcpy (abtCmd + offset, pbtPassiveInitiatorData, 5); offset += 5; - break; + break; case NBR_847: case NBR_UNDEFINED: pnd->last_error = NFC_EINVARG; return pnd->last_error; - break; + break; } } @@ -2677,54 +2677,54 @@ pn53x_nm_to_pm(const nfc_modulation nm) switch(nm.nmt) { case NMT_ISO14443A: return PM_ISO14443A_106; - break; + break; case NMT_ISO14443B: switch(nm.nbr) { case NBR_106: return PM_ISO14443B_106; - break; + break; case NBR_212: return PM_ISO14443B_212; - break; + break; case NBR_424: return PM_ISO14443B_424; - break; + break; case NBR_847: return PM_ISO14443B_847; - break; + break; case NBR_UNDEFINED: // Nothing to do... - break; + break; } - break; + break; case NMT_JEWEL: return PM_JEWEL_106; - break; + break; case NMT_FELICA: switch(nm.nbr) { case NBR_212: return PM_FELICA_212; - break; + break; case NBR_424: return PM_FELICA_424; - break; + break; case NBR_106: case NBR_847: case NBR_UNDEFINED: // Nothing to do... - break; + break; } - break; + break; case NMT_ISO14443BI: case NMT_ISO14443B2SR: case NMT_ISO14443B2CT: case NMT_DEP: // Nothing to do... - break; + break; } return PM_UNDEFINED; } @@ -2738,44 +2738,44 @@ pn53x_ptt_to_nm( const pn53x_target_type ptt ) case PTT_GENERIC_PASSIVE_424: case PTT_UNDEFINED: // XXX This should not happend, how handle it cleanly ? - break; + break; case PTT_MIFARE: case PTT_ISO14443_4A_106: - return (const nfc_modulation){ .nmt = NMT_ISO14443A, .nbr = NBR_106 }; - break; + return (const nfc_modulation) { .nmt = NMT_ISO14443A, .nbr = NBR_106 }; + break; case PTT_ISO14443_4B_106: case PTT_ISO14443_4B_TCL_106: - return (const nfc_modulation){ .nmt = NMT_ISO14443B, .nbr = NBR_106 }; - break; + return (const nfc_modulation) { .nmt = NMT_ISO14443B, .nbr = NBR_106 }; + break; case PTT_JEWEL_106: - return (const nfc_modulation){ .nmt = NMT_JEWEL, .nbr = NBR_106 }; - break; + return (const nfc_modulation) { .nmt = NMT_JEWEL, .nbr = NBR_106 }; + break; case PTT_FELICA_212: - return (const nfc_modulation){ .nmt = NMT_FELICA, .nbr = NBR_212 }; - break; + return (const nfc_modulation) { .nmt = NMT_FELICA, .nbr = NBR_212 }; + break; case PTT_FELICA_424: - return (const nfc_modulation){ .nmt = NMT_FELICA, .nbr = NBR_424 }; - break; + return (const nfc_modulation) { .nmt = NMT_FELICA, .nbr = NBR_424 }; + break; case PTT_DEP_PASSIVE_106: case PTT_DEP_ACTIVE_106: - return (const nfc_modulation){ .nmt = NMT_DEP, .nbr = NBR_106 }; - break; + return (const nfc_modulation) { .nmt = NMT_DEP, .nbr = NBR_106 }; + break; case PTT_DEP_PASSIVE_212: case PTT_DEP_ACTIVE_212: - return (const nfc_modulation){ .nmt = NMT_DEP, .nbr = NBR_212 }; - break; + return (const nfc_modulation) { .nmt = NMT_DEP, .nbr = NBR_212 }; + break; case PTT_DEP_PASSIVE_424: case PTT_DEP_ACTIVE_424: - return (const nfc_modulation){ .nmt = NMT_DEP, .nbr = NBR_424 }; - break; + return (const nfc_modulation) { .nmt = NMT_DEP, .nbr = NBR_424 }; + break; } // We should never be here, this line silent compilation warning - return (const nfc_modulation){ .nmt = NMT_ISO14443A, .nbr = NBR_106 }; + return (const nfc_modulation) { .nmt = NMT_ISO14443A, .nbr = NBR_106 }; } pn53x_target_type @@ -2785,48 +2785,48 @@ pn53x_nm_to_ptt(const nfc_modulation nm) case NMT_ISO14443A: return PTT_MIFARE; // return PTT_ISO14443_4A_106; - break; + break; case NMT_ISO14443B: switch(nm.nbr) { case NBR_106: return PTT_ISO14443_4B_106; - break; + break; case NBR_UNDEFINED: case NBR_212: case NBR_424: case NBR_847: // Nothing to do... - break; + break; } - break; + break; case NMT_JEWEL: return PTT_JEWEL_106; - break; + break; case NMT_FELICA: switch(nm.nbr) { case NBR_212: return PTT_FELICA_212; - break; + break; case NBR_424: return PTT_FELICA_424; - break; + break; case NBR_UNDEFINED: case NBR_106: case NBR_847: // Nothing to do... - break; + break; } - break; + break; case NMT_ISO14443BI: case NMT_ISO14443B2SR: case NMT_ISO14443B2CT: case NMT_DEP: // Nothing to do... - break; + break; } return PTT_UNDEFINED; } @@ -2837,10 +2837,10 @@ pn53x_get_supported_modulation(nfc_device *pnd, const nfc_mode mode, const nfc_m switch (mode) { case N_TARGET: *supported_mt = CHIP_DATA(pnd)->supported_modulation_as_target; - break; + break; case N_INITIATOR: *supported_mt = CHIP_DATA(pnd)->supported_modulation_as_initiator; - break; + break; default: return NFC_EINVARG; } @@ -2853,10 +2853,10 @@ pn53x_get_supported_baud_rate (nfc_device *pnd, const nfc_modulation_type nmt, c switch (nmt) { case NMT_FELICA: *supported_br = (nfc_baud_rate*)pn53x_felica_supported_baud_rates; - break; + break; case NMT_ISO14443A: *supported_br = (nfc_baud_rate*)pn53x_iso14443a_supported_baud_rates; - break; + break; case NMT_ISO14443B: case NMT_ISO14443BI: case NMT_ISO14443B2SR: @@ -2871,10 +2871,10 @@ pn53x_get_supported_baud_rate (nfc_device *pnd, const nfc_modulation_type nmt, c break; case NMT_JEWEL: *supported_br = (nfc_baud_rate*)pn53x_jewel_supported_baud_rates; - break; + break; case NMT_DEP: *supported_br = (nfc_baud_rate*)pn53x_dep_supported_baud_rates; - break; + break; default: return NFC_EINVARG; } diff --git a/libnfc/chips/pn53x.h b/libnfc/chips/pn53x.h index 9827860..1c1f0f9 100644 --- a/libnfc/chips/pn53x.h +++ b/libnfc/chips/pn53x.h @@ -155,41 +155,41 @@ struct pn53x_io { * @brief PN53x data structure */ struct pn53x_data { -/** Chip type (PN531, PN532 or PN533) */ + /** Chip type (PN531, PN532 or PN533) */ pn53x_type type; -/** Chip firmware text */ + /** Chip firmware text */ char firmware_text[22]; -/** Current power mode */ + /** Current power mode */ pn53x_power_mode power_mode; -/** Current operating mode */ + /** Current operating mode */ pn53x_operating_mode operating_mode; -/** Current emulated target */ + /** Current emulated target */ nfc_target *current_target; -/** PN53x I/O functions stored in struct */ + /** PN53x I/O functions stored in struct */ const struct pn53x_io *io; -/** Last status byte returned by PN53x */ + /** Last status byte returned by PN53x */ uint8_t last_status_byte; -/** Register cache for REG_CIU_BIT_FRAMING, SYMBOL_TX_LAST_BITS: The last TX bits setting, we need to reset this if it does not apply anymore */ + /** Register cache for REG_CIU_BIT_FRAMING, SYMBOL_TX_LAST_BITS: The last TX bits setting, we need to reset this if it does not apply anymore */ uint8_t ui8TxBits; -/** Register cache for SetParameters function. */ + /** Register cache for SetParameters function. */ uint8_t ui8Parameters; -/** Last sent command */ + /** Last sent command */ uint8_t last_command; -/** Interframe timer correction */ + /** Interframe timer correction */ int16_t timer_correction; -/** Timer prescaler */ + /** Timer prescaler */ uint16_t timer_prescaler; -/** WriteBack cache */ + /** WriteBack cache */ uint8_t wb_data[PN53X_CACHE_REGISTER_SIZE]; uint8_t wb_mask[PN53X_CACHE_REGISTER_SIZE]; bool wb_trigged; -/** Command timeout */ + /** Command timeout */ int timeout_command; -/** ATR timeout */ + /** ATR timeout */ int timeout_atr; -/** Communication timeout */ + /** Communication timeout */ int timeout_communication; -/** Supported modulation type */ + /** Supported modulation type */ nfc_modulation_type *supported_modulation_as_initiator; nfc_modulation_type *supported_modulation_as_target; }; @@ -203,21 +203,21 @@ struct pn53x_data { typedef enum { /** Undefined modulation */ PM_UNDEFINED = -1, -/** ISO14443-A (NXP MIFARE) http://en.wikipedia.org/wiki/MIFARE */ + /** ISO14443-A (NXP MIFARE) http://en.wikipedia.org/wiki/MIFARE */ PM_ISO14443A_106 = 0x00, -/** JIS X 6319-4 (Sony Felica) http://en.wikipedia.org/wiki/FeliCa */ + /** JIS X 6319-4 (Sony Felica) http://en.wikipedia.org/wiki/FeliCa */ PM_FELICA_212 = 0x01, -/** JIS X 6319-4 (Sony Felica) http://en.wikipedia.org/wiki/FeliCa */ + /** JIS X 6319-4 (Sony Felica) http://en.wikipedia.org/wiki/FeliCa */ PM_FELICA_424 = 0x02, -/** ISO14443-B http://en.wikipedia.org/wiki/ISO/IEC_14443 (Not supported by PN531) */ + /** ISO14443-B http://en.wikipedia.org/wiki/ISO/IEC_14443 (Not supported by PN531) */ PM_ISO14443B_106 = 0x03, -/** Jewel Topaz (Innovision Research & Development) (Not supported by PN531) */ + /** Jewel Topaz (Innovision Research & Development) (Not supported by PN531) */ PM_JEWEL_106 = 0x04, -/** ISO14443-B http://en.wikipedia.org/wiki/ISO/IEC_14443 (Not supported by PN531 nor PN532) */ + /** ISO14443-B http://en.wikipedia.org/wiki/ISO/IEC_14443 (Not supported by PN531 nor PN532) */ PM_ISO14443B_212 = 0x06, -/** ISO14443-B http://en.wikipedia.org/wiki/ISO/IEC_14443 (Not supported by PN531 nor PN532) */ + /** ISO14443-B http://en.wikipedia.org/wiki/ISO/IEC_14443 (Not supported by PN531 nor PN532) */ PM_ISO14443B_424 = 0x07, -/** ISO14443-B http://en.wikipedia.org/wiki/ISO/IEC_14443 (Not supported by PN531 nor PN532) */ + /** ISO14443-B http://en.wikipedia.org/wiki/ISO/IEC_14443 (Not supported by PN531 nor PN532) */ PM_ISO14443B_847 = 0x08, } pn53x_modulation; @@ -299,8 +299,8 @@ int pn53x_set_tx_bits (struct nfc_device *pnd, const uint8_t ui8Bits); int pn53x_wrap_frame (const uint8_t *pbtTx, const size_t szTxBits, const uint8_t *pbtTxPar, uint8_t *pbtFrame); int pn53x_unwrap_frame (const uint8_t *pbtFrame, const size_t szFrameBits, uint8_t *pbtRx, uint8_t *pbtRxPar); int pn53x_decode_target_data (const uint8_t *pbtRawData, size_t szRawData, - pn53x_type chip_type, nfc_modulation_type nmt, - nfc_target_info *pnti); + pn53x_type chip_type, nfc_modulation_type nmt, + nfc_target_info *pnti); int pn53x_read_register (struct nfc_device *pnd, uint16_t ui16Reg, uint8_t *ui8Value); int pn53x_write_register (struct nfc_device *pnd, uint16_t ui16Reg, uint8_t ui8SymbolMask, uint8_t ui8Value); int pn53x_decode_firmware_version (struct nfc_device *pnd); @@ -313,26 +313,26 @@ int pn53x_idle (struct nfc_device *pnd); // NFC device as Initiator functions int pn53x_initiator_init (struct nfc_device *pnd); int pn53x_initiator_select_passive_target (struct nfc_device *pnd, - const nfc_modulation nm, - const uint8_t *pbtInitData, const size_t szInitData, - nfc_target *pnt); + const nfc_modulation nm, + const uint8_t *pbtInitData, const size_t szInitData, + nfc_target *pnt); int pn53x_initiator_poll_target (struct nfc_device *pnd, - const nfc_modulation *pnmModulations, const size_t szModulations, - const uint8_t uiPollNr, const uint8_t uiPeriod, - nfc_target *pnt); + const nfc_modulation *pnmModulations, const size_t szModulations, + const uint8_t uiPollNr, const uint8_t uiPeriod, + nfc_target *pnt); int pn53x_initiator_select_dep_target (struct nfc_device *pnd, - const nfc_dep_mode ndm, const nfc_baud_rate nbr, - const nfc_dep_info *pndiInitiator, - nfc_target *pnt, - const int timeout); + const nfc_dep_mode ndm, const nfc_baud_rate nbr, + const nfc_dep_info *pndiInitiator, + nfc_target *pnt, + const int timeout); int pn53x_initiator_transceive_bits (struct nfc_device *pnd, const uint8_t *pbtTx, const size_t szTxBits, - const uint8_t *pbtTxPar, uint8_t *pbtRx, uint8_t *pbtRxPar); + const uint8_t *pbtTxPar, uint8_t *pbtRx, uint8_t *pbtRxPar); int pn53x_initiator_transceive_bytes (struct nfc_device *pnd, const uint8_t *pbtTx, const size_t szTx, - uint8_t *pbtRx, const size_t szRx, int timeout); + uint8_t *pbtRx, const size_t szRx, int timeout); int pn53x_initiator_transceive_bits_timed (struct nfc_device *pnd, const uint8_t *pbtTx, const size_t szTxBits, - const uint8_t *pbtTxPar, uint8_t *pbtRx, uint8_t *pbtRxPar, uint32_t *cycles); + const uint8_t *pbtTxPar, uint8_t *pbtRx, uint8_t *pbtRxPar, uint32_t *cycles); int pn53x_initiator_transceive_bytes_timed (struct nfc_device *pnd, const uint8_t *pbtTx, const size_t szTx, - uint8_t *pbtRx, uint32_t *cycles); + uint8_t *pbtRx, uint32_t *cycles); int pn53x_initiator_deselect_target (struct nfc_device *pnd); int pn53x_initiator_target_is_present (struct nfc_device *pnd, const nfc_target nt); @@ -351,27 +351,27 @@ int pn53x_SetParameters (struct nfc_device *pnd, const uint8_t ui8Value); int pn53x_SAMConfiguration (struct nfc_device *pnd, const pn532_sam_mode mode, int timeout); int pn53x_PowerDown (struct nfc_device *pnd); int pn53x_InListPassiveTarget (struct nfc_device *pnd, const pn53x_modulation pmInitModulation, - const uint8_t szMaxTargets, const uint8_t *pbtInitiatorData, - const size_t szInitiatorDataLen, uint8_t *pbtTargetsData, size_t *pszTargetsData, - int timeout); + const uint8_t szMaxTargets, const uint8_t *pbtInitiatorData, + const size_t szInitiatorDataLen, uint8_t *pbtTargetsData, size_t *pszTargetsData, + int timeout); int pn53x_InDeselect (struct nfc_device *pnd, const uint8_t ui8Target); int pn53x_InRelease (struct nfc_device *pnd, const uint8_t ui8Target); int pn53x_InAutoPoll (struct nfc_device *pnd, const pn53x_target_type *ppttTargetTypes, const size_t szTargetTypes, - const uint8_t btPollNr, const uint8_t btPeriod, nfc_target *pntTargets, - const int timeout); + const uint8_t btPollNr, const uint8_t btPeriod, nfc_target *pntTargets, + const int timeout); int pn53x_InJumpForDEP (struct nfc_device *pnd, - const nfc_dep_mode ndm, const nfc_baud_rate nbr, - const uint8_t *pbtPassiveInitiatorData, - const uint8_t *pbtNFCID3i, - const uint8_t *pbtGB, const size_t szGB, - nfc_target *pnt, - const int timeout); + const nfc_dep_mode ndm, const nfc_baud_rate nbr, + const uint8_t *pbtPassiveInitiatorData, + const uint8_t *pbtNFCID3i, + const uint8_t *pbtGB, const size_t szGB, + nfc_target *pnt, + const int timeout); int pn53x_TgInitAsTarget (struct nfc_device *pnd, pn53x_target_mode ptm, - const uint8_t *pbtMifareParams, - const uint8_t *pbtTkt, size_t szTkt, - const uint8_t *pbtFeliCaParams, - const uint8_t *pbtNFCID3t, const uint8_t *pbtGB, const size_t szGB, - uint8_t *pbtRx, const size_t szRxLen, uint8_t *pbtModeByte, int timeout); + const uint8_t *pbtMifareParams, + const uint8_t *pbtTkt, size_t szTkt, + const uint8_t *pbtFeliCaParams, + const uint8_t *pbtNFCID3t, const uint8_t *pbtGB, const size_t szGB, + uint8_t *pbtRx, const size_t szRxLen, uint8_t *pbtModeByte, int timeout); // RFConfiguration int pn53x_RFConfiguration__RF_field (struct nfc_device *pnd, bool bEnable); diff --git a/libnfc/drivers/acr122_pcsc.c b/libnfc/drivers/acr122_pcsc.c index adb1c88..d1bee2a 100644 --- a/libnfc/drivers/acr122_pcsc.c +++ b/libnfc/drivers/acr122_pcsc.c @@ -383,9 +383,9 @@ acr122_pcsc_send (nfc_device *pnd, const uint8_t *pbtData, const size_t szData, } if (DRIVER_DATA (pnd)->ioCard.dwProtocol == SCARD_PROTOCOL_T0) { - /* - * Check the MCU response - */ + /* + * Check the MCU response + */ // Make sure we received the byte-count we expected if (dwRxLen != 2) { diff --git a/libnfc/drivers/acr122_usb.c b/libnfc/drivers/acr122_usb.c index d81e551..544d9b9 100644 --- a/libnfc/drivers/acr122_usb.c +++ b/libnfc/drivers/acr122_usb.c @@ -56,15 +56,15 @@ Thanks to d18c7db and Okko for example code #include #ifndef _WIN32 - // Under POSIX system, we use libusb (>= 0.1.12) - #include - #define USB_TIMEDOUT ETIMEDOUT - #define _usb_strerror( X ) strerror(-X) +// Under POSIX system, we use libusb (>= 0.1.12) +#include +#define USB_TIMEDOUT ETIMEDOUT +#define _usb_strerror( X ) strerror(-X) #else - // Under Windows we use libusb-win32 (>= 1.2.5) - #include - #define USB_TIMEDOUT 116 - #define _usb_strerror( X ) usb_strerror() +// Under Windows we use libusb-win32 (>= 1.2.5) +#include +#define USB_TIMEDOUT 116 +#define _usb_strerror( X ) usb_strerror() #endif #include @@ -158,7 +158,7 @@ acr122_usb_get_device_model (uint16_t vendor_id, uint16_t product_id) { for (size_t n = 0; n < sizeof (acr122_usb_supported_devices) / sizeof (struct acr122_usb_supported_device); n++) { if ((vendor_id == acr122_usb_supported_devices[n].vendor_id) && - (product_id == acr122_usb_supported_devices[n].product_id)) + (product_id == acr122_usb_supported_devices[n].product_id)) return acr122_usb_supported_devices[n].model; } @@ -363,7 +363,7 @@ acr122_usb_open (const nfc_connstring connstring) for (dev = bus->devices; dev; dev = dev->next) { if (connstring_decode_level > 2) { // A specific dev have been specified - if (0 != strcmp (dev->filename, desc.filename)) + if (0 != strcmp (dev->filename, desc.filename)) continue; } // Open the USB device @@ -401,7 +401,7 @@ acr122_usb_open (const nfc_connstring connstring) pn53x_data_new (pnd, &acr122_usb_io); switch (DRIVER_DATA (pnd)->model) { - // empirical tuning + // empirical tuning case ACR122: CHIP_DATA (pnd)->timer_correction = 46; break; diff --git a/libnfc/drivers/acr122s.c b/libnfc/drivers/acr122s.c index d7ce693..68b25e9 100644 --- a/libnfc/drivers/acr122s.c +++ b/libnfc/drivers/acr122s.c @@ -223,10 +223,10 @@ acr122s_send_frame(nfc_device *pnd, uint8_t *frame, int timeout) if ((ret = uart_receive(port, ack, 4, abort_p, timeout)) < 0) return ret; - if (memcmp(ack, positive_ack, 4) != 0){ - pnd->last_error = NFC_EIO; - return pnd->last_error; - } + if (memcmp(ack, positive_ack, 4) != 0) { + pnd->last_error = NFC_EIO; + return pnd->last_error; + } struct xfr_block_req *req = (struct xfr_block_req *) &frame[1]; DRIVER_DATA(pnd)->seq = req->seq + 1; @@ -250,9 +250,9 @@ static int acr122s_recv_frame(nfc_device *pnd, uint8_t *frame, size_t frame_size, void *abort_p, int timeout) { if (frame_size < 13) - { pnd->last_error = NFC_EINVARG; + { pnd->last_error = NFC_EINVARG; return pnd->last_error; - } + } int ret; serial_port port = DRIVER_DATA(pnd)->port; @@ -260,7 +260,7 @@ acr122s_recv_frame(nfc_device *pnd, uint8_t *frame, size_t frame_size, void *abo return ret; // Is buffer sufficient to store response? - if (frame_size < FRAME_SIZE(frame)){ + if (frame_size < FRAME_SIZE(frame)) { pnd->last_error = NFC_EIO; return pnd->last_error; } @@ -286,13 +286,13 @@ acr122s_recv_frame(nfc_device *pnd, uint8_t *frame, size_t frame_size, void *abo */ static uint32_t le32(uint32_t val) { - uint32_t res; - uint8_t *p = (uint8_t *) &res; - p[0] = val; - p[1] = val >> 8; - p[2] = val >> 16; - p[3] = val >> 24; - return res; + uint32_t res; + uint8_t *p = (uint8_t *) &res; + p[0] = val; + p[1] = val >> 8; + p[2] = val >> 16; + p[3] = val >> 24; + return res; } /** @@ -311,8 +311,8 @@ le32(uint32_t val) { */ static bool acr122s_build_frame(nfc_device *pnd, - uint8_t *frame, size_t frame_size, uint8_t p1, uint8_t p2, - const uint8_t *data, size_t data_size, int should_prefix) + uint8_t *frame, size_t frame_size, uint8_t p1, uint8_t p2, + const uint8_t *data, size_t data_size, int should_prefix) { if (frame_size < data_size + APDU_OVERHEAD + should_prefix) return false; @@ -333,7 +333,7 @@ acr122s_build_frame(nfc_device *pnd, header->ins = 0; header->p1 = p1; header->p2 = p2; - header->length = data_size + should_prefix; + header->length = data_size + should_prefix; uint8_t *buf = (uint8_t *) &frame[16]; if (should_prefix) @@ -480,7 +480,7 @@ acr122s_probe(nfc_connstring connstrings[], size_t connstrings_len, size_t *pszD #else /* SERIAL_AUTOPROBE_ENABLED */ *pszDeviceFound = 0; - serial_port sp; + serial_port sp; char **acPorts = uart_list_ports (); const char *acPort; int iDevice = 0; @@ -560,17 +560,17 @@ acr122s_open(const nfc_connstring connstring) } log_put(LOG_CATEGORY, NFC_PRIORITY_TRACE, - "Attempt to connect to: %s at %d bauds.", ndd.port, ndd.speed); + "Attempt to connect to: %s at %d bauds.", ndd.port, ndd.speed); sp = uart_open(ndd.port); if (sp == INVALID_SERIAL_PORT) { log_put(LOG_CATEGORY, NFC_PRIORITY_ERROR, - "Invalid serial port: %s", ndd.port); + "Invalid serial port: %s", ndd.port); return NULL; } if (sp == CLAIMED_SERIAL_PORT) { log_put(LOG_CATEGORY, NFC_PRIORITY_ERROR, - "Serial port already claimed: %s", ndd.port); + "Serial port already claimed: %s", ndd.port); return NULL; } @@ -607,7 +607,7 @@ acr122s_open(const nfc_connstring connstring) if (strncmp(version, "ACR122S", 7) != 0) { log_put(LOG_CATEGORY, NFC_PRIORITY_ERROR, "Invalid firmware version: %s", - version); + version); acr122s_close(pnd); return NULL; } diff --git a/libnfc/drivers/pn532_uart.c b/libnfc/drivers/pn532_uart.c index 4bff08a..733383a 100644 --- a/libnfc/drivers/pn532_uart.c +++ b/libnfc/drivers/pn532_uart.c @@ -314,7 +314,7 @@ pn532_uart_send (nfc_device *pnd, const uint8_t *pbtData, const size_t szData, i break; case NORMAL: // Nothing to do :) - break; + break; }; uint8_t abtFrame[PN532_BUFFER_LEN] = { 0x00, 0x00, 0xff }; // Every packet must start with "00 00 ff" diff --git a/libnfc/drivers/pn53x_usb.c b/libnfc/drivers/pn53x_usb.c index b366a6f..5f5a435 100644 --- a/libnfc/drivers/pn53x_usb.c +++ b/libnfc/drivers/pn53x_usb.c @@ -39,15 +39,15 @@ Thanks to d18c7db and Okko for example code #include #ifndef _WIN32 - // Under POSIX system, we use libusb (>= 0.1.12) - #include - #define USB_TIMEDOUT ETIMEDOUT - #define _usb_strerror( X ) strerror(-X) +// Under POSIX system, we use libusb (>= 0.1.12) +#include +#define USB_TIMEDOUT ETIMEDOUT +#define _usb_strerror( X ) strerror(-X) #else - // Under Windows we use libusb-win32 (>= 1.2.5) - #include - #define USB_TIMEDOUT 116 - #define _usb_strerror( X ) usb_strerror() +// Under Windows we use libusb-win32 (>= 1.2.5) +#include +#define USB_TIMEDOUT 116 +#define _usb_strerror( X ) usb_strerror() #endif #include @@ -139,7 +139,7 @@ pn53x_usb_get_device_model (uint16_t vendor_id, uint16_t product_id) { for (size_t n = 0; n < sizeof (pn53x_usb_supported_devices) / sizeof (struct pn53x_usb_supported_device); n++) { if ((vendor_id == pn53x_usb_supported_devices[n].vendor_id) && - (product_id == pn53x_usb_supported_devices[n].product_id)) + (product_id == pn53x_usb_supported_devices[n].product_id)) return pn53x_usb_supported_devices[n].model; } @@ -354,7 +354,7 @@ pn53x_usb_open (const nfc_connstring connstring) for (dev = bus->devices; dev; dev = dev->next) { if (connstring_decode_level > 2) { // A specific dev have been specified - if (0 != strcmp (dev->filename, desc.filename)) + if (0 != strcmp (dev->filename, desc.filename)) continue; } // Open the USB device @@ -392,7 +392,7 @@ pn53x_usb_open (const nfc_connstring connstring) pn53x_data_new (pnd, &pn53x_usb_io); switch (DRIVER_DATA (pnd)->model) { - // empirical tuning + // empirical tuning case ASK_LOGO: CHIP_DATA (pnd)->timer_correction = 50; break; @@ -684,23 +684,23 @@ pn53x_usb_init (nfc_device *pnd) /* Setup push-pulls for pins from P30 to P35 */ pn53x_write_register (pnd, PN53X_SFR_P3CFGB, 0xFF, 0x37); -/* -On ASK LoGO hardware: - LEDs port bits definition: - * LED 1: bit 2 (P32) - * LED 2: bit 1 (P31) - * LED 3: bit 0 or 3 (depending of hardware revision) (P30 or P33) - * LED 4: bit 5 (P35) - Notes: - * Set logical 0 to switch LED on; logical 1 to switch LED off. - * Bit 4 should be maintained at 1 to keep RF field on. + /* + On ASK LoGO hardware: + LEDs port bits definition: + * LED 1: bit 2 (P32) + * LED 2: bit 1 (P31) + * LED 3: bit 0 or 3 (depending of hardware revision) (P30 or P33) + * LED 4: bit 5 (P35) + Notes: + * Set logical 0 to switch LED on; logical 1 to switch LED off. + * Bit 4 should be maintained at 1 to keep RF field on. - Progressive field activation: - The ASK LoGO hardware can progressively power-up the antenna. - To use this feature we have to switch on the field by switching on - the field on PN533 (RFConfiguration) then set P34 to '1', and cut-off the - field by switching off the field on PN533 then set P34 to '0'. -*/ + Progressive field activation: + The ASK LoGO hardware can progressively power-up the antenna. + To use this feature we have to switch on the field by switching on + the field on PN533 (RFConfiguration) then set P34 to '1', and cut-off the + field by switching off the field on PN533 then set P34 to '0'. + */ /* Set P30, P31, P33, P35 to logic 1 and P32, P34 to 0 logic */ /* ie. Switch LED1 on and turn off progressive field */ diff --git a/libnfc/iso14443-subr.c b/libnfc/iso14443-subr.c index 86acf4c..3efe89b 100644 --- a/libnfc/iso14443-subr.c +++ b/libnfc/iso14443-subr.c @@ -17,10 +17,10 @@ * along with this program. If not, see */ - /** - * @file iso14443-subr.c - * @brief Defines some function extracted for ISO/IEC 14443 - */ +/** +* @file iso14443-subr.c +* @brief Defines some function extracted for ISO/IEC 14443 +*/ #ifdef HAVE_CONFIG_H # include "config.h" diff --git a/libnfc/iso7816.h b/libnfc/iso7816.h index 60b8898..6250515 100644 --- a/libnfc/iso7816.h +++ b/libnfc/iso7816.h @@ -17,10 +17,10 @@ * along with this program. If not, see */ - /** - * @file iso7816.h - * @brief Defines some macros extracted for ISO/IEC 7816-4 - */ +/** +* @file iso7816.h +* @brief Defines some macros extracted for ISO/IEC 7816-4 +*/ #ifndef __LIBNFC_ISO7816_H__ #define __LIBNFC_ISO7816_H__ diff --git a/libnfc/log.h b/libnfc/log.h index f72fe15..361c3fd 100644 --- a/libnfc/log.h +++ b/libnfc/log.h @@ -32,43 +32,43 @@ # define __has_attribute_format 1 # endif - // User want debug features - #define LOGGING 1 - int log_init (void); - int log_fini (void); - void log_put (const char *category, const char *priority, const char *format, ...) +// User want debug features +#define LOGGING 1 +int log_init (void); +int log_fini (void); +void log_put (const char *category, const char *priority, const char *format, ...) # if __has_attribute_format - __attribute__((format(printf, 3, 4))) +__attribute__((format(printf, 3, 4))) # endif - ; +; - #define NFC_PRIORITY_FATAL "fatal" - #define NFC_PRIORITY_ALERT "alert" - #define NFC_PRIORITY_CRIT "critical" - #define NFC_PRIORITY_ERROR "error" - #define NFC_PRIORITY_WARN "warning" - #define NFC_PRIORITY_NOTICE "notice" - #define NFC_PRIORITY_INFO "info" - #define NFC_PRIORITY_DEBUG "debug" - #define NFC_PRIORITY_TRACE "trace" +#define NFC_PRIORITY_FATAL "fatal" +#define NFC_PRIORITY_ALERT "alert" +#define NFC_PRIORITY_CRIT "critical" +#define NFC_PRIORITY_ERROR "error" +#define NFC_PRIORITY_WARN "warning" +#define NFC_PRIORITY_NOTICE "notice" +#define NFC_PRIORITY_INFO "info" +#define NFC_PRIORITY_DEBUG "debug" +#define NFC_PRIORITY_TRACE "trace" #else - // No logging - #define log_init() ((void) 0) - #define log_fini() ((void) 0) - #define log_msg(category, priority, message) do {} while (0) - #define log_set_appender(category, appender) do {} while (0) - #define log_put(category, priority, format, ...) do {} while (0) +// No logging +#define log_init() ((void) 0) +#define log_fini() ((void) 0) +#define log_msg(category, priority, message) do {} while (0) +#define log_set_appender(category, appender) do {} while (0) +#define log_put(category, priority, format, ...) do {} while (0) - #define NFC_PRIORITY_FATAL 8 - #define NFC_PRIORITY_ALERT 7 - #define NFC_PRIORITY_CRIT 6 - #define NFC_PRIORITY_ERROR 5 - #define NFC_PRIORITY_WARN 4 - #define NFC_PRIORITY_NOTICE 3 - #define NFC_PRIORITY_INFO 2 - #define NFC_PRIORITY_DEBUG 1 - #define NFC_PRIORITY_TRACE 0 +#define NFC_PRIORITY_FATAL 8 +#define NFC_PRIORITY_ALERT 7 +#define NFC_PRIORITY_CRIT 6 +#define NFC_PRIORITY_ERROR 5 +#define NFC_PRIORITY_WARN 4 +#define NFC_PRIORITY_NOTICE 3 +#define NFC_PRIORITY_INFO 2 +#define NFC_PRIORITY_DEBUG 1 +#define NFC_PRIORITY_TRACE 0 #endif /* HAS_LOG4C, DEBUG */ /** diff --git a/libnfc/mirror-subr.c b/libnfc/mirror-subr.c index 1746e49..fdf4ad5 100644 --- a/libnfc/mirror-subr.c +++ b/libnfc/mirror-subr.c @@ -17,10 +17,10 @@ * along with this program. If not, see */ - /** - * @file mirror-subr.c - * @brief Mirror bytes - */ +/** +* @file mirror-subr.c +* @brief Mirror bytes +*/ #ifdef HAVE_CONFIG_H # include "config.h" diff --git a/libnfc/nfc-device.c b/libnfc/nfc-device.c index 4e296f5..ef19fe9 100644 --- a/libnfc/nfc-device.c +++ b/libnfc/nfc-device.c @@ -17,10 +17,10 @@ * along with this program. If not, see */ - /** - * @file nfc-device.c - * @brief Provide internal function to manipulate nfc_device type - */ +/** +* @file nfc-device.c +* @brief Provide internal function to manipulate nfc_device type +*/ /* vim:set et sw=2 ts=2: */ diff --git a/libnfc/nfc-emulation.c b/libnfc/nfc-emulation.c index b8445c1..3b34731 100644 --- a/libnfc/nfc-emulation.c +++ b/libnfc/nfc-emulation.c @@ -17,10 +17,10 @@ * along with this program. If not, see */ - /** - * @file nfc-emulation.c - * @brief Provide a small API to ease emulation in libnfc - */ +/** +* @file nfc-emulation.c +* @brief Provide a small API to ease emulation in libnfc +*/ #include #include diff --git a/libnfc/nfc-internal.c b/libnfc/nfc-internal.c index c6862c9..564a37a 100644 --- a/libnfc/nfc-internal.c +++ b/libnfc/nfc-internal.c @@ -17,10 +17,10 @@ * along with this program. If not, see */ - /** - * @file nfc-internal.c - * @brief Provide some useful internal functions - */ +/** +* @file nfc-internal.c +* @brief Provide some useful internal functions +*/ #include #include "nfc-internal.h" @@ -64,6 +64,6 @@ prepare_initiator_data (const nfc_modulation nm, uint8_t **ppbtInitiatorData, si case NMT_DEP: *ppbtInitiatorData = NULL; *pszInitiatorData = 0; - break; + break; } } diff --git a/libnfc/nfc-internal.h b/libnfc/nfc-internal.h index b1dee6c..f0ebe42 100644 --- a/libnfc/nfc-internal.h +++ b/libnfc/nfc-internal.h @@ -73,16 +73,16 @@ * Initialise a buffer named buffer_name of size bytes. */ #define BUFFER_INIT(buffer_name, size) \ - uint8_t buffer_name[size]; \ - size_t __##buffer_name##_n = 0 + uint8_t buffer_name[size]; \ + size_t __##buffer_name##_n = 0 /* * Create a wrapper for an existing buffer. * BEWARE! It eats children! */ #define BUFFER_ALIAS(buffer_name, origin) \ - uint8_t *buffer_name = (void *)origin; \ - size_t __##buffer_name##_n = 0; + uint8_t *buffer_name = (void *)origin; \ + size_t __##buffer_name##_n = 0; #define BUFFER_SIZE(buffer_name) (__##buffer_name##_n) @@ -91,20 +91,20 @@ * Append one byte of data to the buffer buffer_name. */ #define BUFFER_APPEND(buffer_name, data) \ - do { \ - buffer_name[__##buffer_name##_n++] = data; \ - } while (0) + do { \ + buffer_name[__##buffer_name##_n++] = data; \ + } while (0) /* * Append size bytes of data to the buffer buffer_name. */ #define BUFFER_APPEND_BYTES(buffer_name, data, size) \ - do { \ - size_t __n = 0; \ - while (__n < size) { \ - buffer_name[__##buffer_name##_n++] = ((uint8_t *)data)[__n++]; \ - } \ - } while (0) + do { \ + size_t __n = 0; \ + while (__n < size) { \ + buffer_name[__##buffer_name##_n++] = ((uint8_t *)data)[__n++]; \ + } \ + } while (0) /* * Append data_size bytes of data at the end of the buffer. Since data is @@ -117,19 +117,19 @@ #if defined(_BYTE_ORDER) && (_BYTE_ORDER != _LITTLE_ENDIAN) #define BUFFER_APPEND_LE(buffer, data, data_size, field_size) \ - do { \ - size_t __data_size = data_size; \ - size_t __field_size = field_size; \ - while (__field_size--, __data_size--) { \ - buffer[__##buffer##_n++] = ((uint8_t *)&data)[__field_size]; \ - } \ - } while (0) + do { \ + size_t __data_size = data_size; \ + size_t __field_size = field_size; \ + while (__field_size--, __data_size--) { \ + buffer[__##buffer##_n++] = ((uint8_t *)&data)[__field_size]; \ + } \ + } while (0) #else #define BUFFER_APPEND_LE(buffer, data, data_size, field_size) \ - do { \ - memcpy (buffer + __##buffer##_n, &data, data_size); \ - __##buffer##_n += data_size; \ - } while (0) + do { \ + memcpy (buffer + __##buffer##_n, &data, data_size); \ + __##buffer##_n += data_size; \ + } while (0) #endif @@ -179,22 +179,22 @@ struct nfc_device { void *driver_data; void *chip_data; -/** Device name string, including device wrapper firmware */ + /** Device name string, including device wrapper firmware */ char name[DEVICE_NAME_LENGTH]; -/** Device connection string */ + /** Device connection string */ nfc_connstring connstring; -/** Is the CRC automaticly added, checked and removed from the frames */ + /** Is the CRC automaticly added, checked and removed from the frames */ bool bCrc; -/** Does the chip handle parity bits, all parities are handled as data */ + /** Does the chip handle parity bits, all parities are handled as data */ bool bPar; -/** Should the chip handle frames encapsulation and chaining */ + /** Should the chip handle frames encapsulation and chaining */ bool bEasyFraming; -/** Should the chip switch automatically activate ISO14443-4 when - selecting tags supporting it? */ + /** Should the chip switch automatically activate ISO14443-4 when + selecting tags supporting it? */ bool bAutoIso14443_4; -/** Supported modulation encoded in a byte */ + /** Supported modulation encoded in a byte */ uint8_t btSupportByte; -/** Last reported error */ + /** Last reported error */ int last_error; }; diff --git a/libnfc/nfc.c b/libnfc/nfc.c index a049c86..864add1 100644 --- a/libnfc/nfc.c +++ b/libnfc/nfc.c @@ -263,7 +263,7 @@ nfc_list_devices (nfc_context *context, nfc_connstring connstrings[] , size_t sz szDeviceFound += szN; log_put (LOG_CATEGORY, NFC_PRIORITY_TRACE, "%ld device(s) found using %s driver", (unsigned long) szN, ndr->name); if (szDeviceFound == szDevices) - break; + break; } pndr++; } @@ -400,20 +400,20 @@ nfc_initiator_select_passive_target (nfc_device *pnd, size_t szInit; switch (nm.nmt) { - case NMT_ISO14443A: - iso14443_cascade_uid (pbtInitData, szInitData, abtInit, &szInit); - break; + case NMT_ISO14443A: + iso14443_cascade_uid (pbtInitData, szInitData, abtInit, &szInit); + break; - case NMT_JEWEL: - case NMT_ISO14443B: - case NMT_ISO14443BI: - case NMT_ISO14443B2SR: - case NMT_ISO14443B2CT: - case NMT_FELICA: - case NMT_DEP: - memcpy (abtInit, pbtInitData, szInitData); - szInit = szInitData; - break; + case NMT_JEWEL: + case NMT_ISO14443B: + case NMT_ISO14443BI: + case NMT_ISO14443B2SR: + case NMT_ISO14443B2CT: + case NMT_FELICA: + case NMT_DEP: + memcpy (abtInit, pbtInitData, szInitData); + szInit = szInitData; + break; } HAL (initiator_select_passive_target, pnd, nm, abtInit, szInit, pnt); @@ -549,10 +549,10 @@ nfc_initiator_select_dep_target (nfc_device *pnd, */ int nfc_initiator_poll_dep_target (struct nfc_device *pnd, - const nfc_dep_mode ndm, const nfc_baud_rate nbr, - const nfc_dep_info *pndiInitiator, - nfc_target *pnt, - const int timeout) + const nfc_dep_mode ndm, const nfc_baud_rate nbr, + const nfc_dep_info *pndiInitiator, + nfc_target *pnt, + const int timeout) { const int period = 300; int remaining_time = timeout; @@ -727,7 +727,7 @@ nfc_initiator_target_is_present (nfc_device *pnd, const nfc_target nt) */ int nfc_initiator_transceive_bits_timed (nfc_device *pnd, const uint8_t *pbtTx, const size_t szTxBits, const uint8_t *pbtTxPar, - uint8_t *pbtRx, uint8_t *pbtRxPar, uint32_t *cycles) + uint8_t *pbtRx, uint8_t *pbtRxPar, uint32_t *cycles) { HAL (initiator_transceive_bits_timed, pnd, pbtTx, szTxBits, pbtTxPar, pbtRx, pbtRxPar, cycles); } @@ -1080,19 +1080,19 @@ str_nfc_baud_rate (const nfc_baud_rate nbr) switch(nbr) { case NBR_UNDEFINED: return "undefined baud rate"; - break; + break; case NBR_106: return "106 kbps"; - break; + break; case NBR_212: return "212 kbps"; - break; + break; case NBR_424: return "424 kbps"; - break; + break; case NBR_847: return "847 kbps"; - break; + break; } // Should never go there.. return ""; @@ -1109,28 +1109,28 @@ str_nfc_modulation_type (const nfc_modulation_type nmt) switch(nmt) { case NMT_ISO14443A: return "ISO/IEC 14443A"; - break; + break; case NMT_ISO14443B: return "ISO/IEC 14443-4B"; - break; + break; case NMT_ISO14443BI: return "ISO/IEC 14443-4B'"; - break; + break; case NMT_ISO14443B2CT: return "ISO/IEC 14443-2B ASK CTx"; - break; + break; case NMT_ISO14443B2SR: return "ISO/IEC 14443-2B ST SRx"; - break; + break; case NMT_FELICA: return "FeliCa"; - break; + break; case NMT_JEWEL: return "Innovision Jewel"; - break; + break; case NMT_DEP: return "D.E.P."; - break; + break; } // Should never go there.. return ""; diff --git a/test/test_access_storm.c b/test/test_access_storm.c index d293374..3dec9d4 100644 --- a/test/test_access_storm.c +++ b/test/test_access_storm.c @@ -13,43 +13,43 @@ void test_access_storm (void) { - int n = NTESTS; - nfc_connstring connstrings[MAX_DEVICE_COUNT]; - int res = 0; + int n = NTESTS; + nfc_connstring connstrings[MAX_DEVICE_COUNT]; + int res = 0; - nfc_init (NULL); + nfc_init (NULL); - size_t ref_device_count = nfc_list_devices (NULL, connstrings, MAX_DEVICE_COUNT); - if (!ref_device_count) - cut_omit ("No NFC device found"); + size_t ref_device_count = nfc_list_devices (NULL, connstrings, MAX_DEVICE_COUNT); + if (!ref_device_count) + cut_omit ("No NFC device found"); - while (n) { - size_t i; + while (n) { + size_t i; - size_t device_count = nfc_list_devices (NULL, connstrings, MAX_DEVICE_COUNT); - cut_assert_equal_int (ref_device_count, device_count, cut_message ("device count")); + size_t device_count = nfc_list_devices (NULL, connstrings, MAX_DEVICE_COUNT); + cut_assert_equal_int (ref_device_count, device_count, cut_message ("device count")); - for (i = 0; i < device_count; i++) { - nfc_device *device; - nfc_target ant[MAX_TARGET_COUNT]; + for (i = 0; i < device_count; i++) { + nfc_device *device; + nfc_target ant[MAX_TARGET_COUNT]; - device = nfc_open (NULL, connstrings[i]); - cut_assert_not_null (device, cut_message ("nfc_open")); + device = nfc_open (NULL, connstrings[i]); + cut_assert_not_null (device, cut_message ("nfc_open")); - res = nfc_initiator_init(device); - cut_assert_equal_int (0, res, cut_message ("nfc_initiator_init")); + res = nfc_initiator_init(device); + cut_assert_equal_int (0, res, cut_message ("nfc_initiator_init")); - const nfc_modulation nm = { - .nmt = NMT_ISO14443A, - .nbr = NBR_106, - }; - res = nfc_initiator_list_passive_targets(device, nm, ant, MAX_TARGET_COUNT); - cut_assert_operator_int (res, >=, 0, cut_message ("nfc_initiator_list_passive_targets")); + const nfc_modulation nm = { + .nmt = NMT_ISO14443A, + .nbr = NBR_106, + }; + res = nfc_initiator_list_passive_targets(device, nm, ant, MAX_TARGET_COUNT); + cut_assert_operator_int (res, >=, 0, cut_message ("nfc_initiator_list_passive_targets")); - nfc_close (device); - } - - n--; + nfc_close (device); } - nfc_exit (NULL); + + n--; + } + nfc_exit (NULL); } diff --git a/test/test_dep_passive.c b/test/test_dep_passive.c index 36e40bb..f054845 100644 --- a/test/test_dep_passive.c +++ b/test/test_dep_passive.c @@ -227,7 +227,7 @@ initiator_thread (void *arg) cut_assert_operator_int (res, >=, 0, cut_message ("Can't deselect target: %s", nfc_strerror (device))); if (res < 0) { thread_res = -1; return (void*) thread_res; } - // Passive mode / 424Kbps + // Passive mode / 424Kbps printf ("=========== INITIATOR %s (Passive mode / 424Kbps) =========\n", nfc_device_get_name (device)); res = nfc_initiator_select_dep_target (device, NDM_PASSIVE, NBR_424, NULL, &nt, 1000); cut_assert_operator_int (res, >, 0, cut_message ("Can't select any DEP target: %s", nfc_strerror (device))); diff --git a/test/test_device_modes_as_dep.c b/test/test_device_modes_as_dep.c index 95c6099..5018f7b 100644 --- a/test/test_device_modes_as_dep.c +++ b/test/test_device_modes_as_dep.c @@ -185,7 +185,7 @@ test_dep_states (void) .cut_test_context = test_context, }; - struct thread_data initiator_data = { + struct thread_data initiator_data = { .device = second_device, .cut_test_context = test_context, }; diff --git a/test/test_register_access.c b/test/test_register_access.c index e196416..c0d2e5a 100644 --- a/test/test_register_access.c +++ b/test/test_register_access.c @@ -9,40 +9,40 @@ void test_register_endianness (void) { - nfc_connstring connstrings[MAX_DEVICE_COUNT]; - int res = 0; + nfc_connstring connstrings[MAX_DEVICE_COUNT]; + int res = 0; - nfc_init (NULL); + nfc_init (NULL); - size_t device_count = nfc_list_devices (NULL, connstrings, MAX_DEVICE_COUNT); - if (!device_count) - cut_omit ("No NFC device found"); + size_t device_count = nfc_list_devices (NULL, connstrings, MAX_DEVICE_COUNT); + if (!device_count) + cut_omit ("No NFC device found"); - nfc_device *device; + nfc_device *device; - device = nfc_open (NULL, connstrings[0]); - cut_assert_not_null (device, cut_message ("nfc_open")); + device = nfc_open (NULL, connstrings[0]); + cut_assert_not_null (device, cut_message ("nfc_open")); - uint8_t value; + uint8_t value; - /* Set a 0xAA test value in writable register memory to test register access */ - res = pn53x_write_register (device, PN53X_REG_CIU_TxMode, 0xFF, 0xAA); - cut_assert_equal_int (0, res, cut_message ("write register value to 0xAA")); + /* Set a 0xAA test value in writable register memory to test register access */ + res = pn53x_write_register (device, PN53X_REG_CIU_TxMode, 0xFF, 0xAA); + cut_assert_equal_int (0, res, cut_message ("write register value to 0xAA")); - /* Get test value from register memory */ - res = pn53x_read_register (device, PN53X_REG_CIU_TxMode, &value); - cut_assert_equal_int (0, res, cut_message ("read register value")); - cut_assert_equal_uint (0xAA, value, cut_message ("check register value")); + /* Get test value from register memory */ + res = pn53x_read_register (device, PN53X_REG_CIU_TxMode, &value); + cut_assert_equal_int (0, res, cut_message ("read register value")); + cut_assert_equal_uint (0xAA, value, cut_message ("check register value")); - /* Set a 0x55 test value in writable register memory to test register access */ - res = pn53x_write_register (device, PN53X_REG_CIU_TxMode, 0xFF, 0x55); - cut_assert_equal_int (0, res, cut_message ("write register value to 0x55")); + /* Set a 0x55 test value in writable register memory to test register access */ + res = pn53x_write_register (device, PN53X_REG_CIU_TxMode, 0xFF, 0x55); + cut_assert_equal_int (0, res, cut_message ("write register value to 0x55")); - /* Get test value from register memory */ - res = pn53x_read_register (device, PN53X_REG_CIU_TxMode, &value); - cut_assert_equal_int (0, res, cut_message ("read register value")); - cut_assert_equal_uint (0x55, value, cut_message ("check register value")); + /* Get test value from register memory */ + res = pn53x_read_register (device, PN53X_REG_CIU_TxMode, &value); + cut_assert_equal_int (0, res, cut_message ("read register value")); + cut_assert_equal_uint (0x55, value, cut_message ("check register value")); - nfc_close (device); - nfc_exit (NULL); + nfc_close (device); + nfc_exit (NULL); } diff --git a/test/test_register_endianness.c b/test/test_register_endianness.c index 3310b79..f234cbe 100644 --- a/test/test_register_endianness.c +++ b/test/test_register_endianness.c @@ -10,30 +10,30 @@ void test_register_endianness (void) { - nfc_connstring connstrings[MAX_DEVICE_COUNT]; - int res = 0; + nfc_connstring connstrings[MAX_DEVICE_COUNT]; + int res = 0; - nfc_init (NULL); + nfc_init (NULL); - size_t device_count = nfc_list_devices (NULL, connstrings, MAX_DEVICE_COUNT); - if (!device_count) - cut_omit ("No NFC device found"); + size_t device_count = nfc_list_devices (NULL, connstrings, MAX_DEVICE_COUNT); + if (!device_count) + cut_omit ("No NFC device found"); - nfc_device *device; + nfc_device *device; - device = nfc_open (NULL, connstrings[0]); - cut_assert_not_null (device, cut_message ("nfc_open")); + device = nfc_open (NULL, connstrings[0]); + cut_assert_not_null (device, cut_message ("nfc_open")); - uint8_t value; + uint8_t value; - /* Read valid XRAM memory */ - res = pn53x_read_register (device, 0xF0FF, &value); - cut_assert_equal_int (0, res, cut_message ("read register 0xF0FF")); + /* Read valid XRAM memory */ + res = pn53x_read_register (device, 0xF0FF, &value); + cut_assert_equal_int (0, res, cut_message ("read register 0xF0FF")); - /* Read invalid SFR register */ - res = pn53x_read_register (device, 0xFFF0, &value); - cut_assert_equal_int (0, res, cut_message ("read register 0xFFF0")); + /* Read invalid SFR register */ + res = pn53x_read_register (device, 0xFFF0, &value); + cut_assert_equal_int (0, res, cut_message ("read register 0xFFF0")); - nfc_close (device); - nfc_exit (NULL); + nfc_close (device); + nfc_exit (NULL); } diff --git a/utils/mifare.c b/utils/mifare.c index 46ffe85..a0c57d9 100644 --- a/utils/mifare.c +++ b/utils/mifare.c @@ -62,34 +62,34 @@ nfc_initiator_mifare_cmd (nfc_device *pnd, const mifare_cmd mc, const uint8_t ui abtCmd[1] = ui8Block; // The block address (1K=0x00..0x39, 4K=0x00..0xff) switch (mc) { - // Read and store command have no parameter - case MC_READ: - case MC_STORE: - szParamLen = 0; - break; + // Read and store command have no parameter + case MC_READ: + case MC_STORE: + szParamLen = 0; + break; - // Authenticate command - case MC_AUTH_A: - case MC_AUTH_B: - szParamLen = sizeof (struct mifare_param_auth); - break; + // Authenticate command + case MC_AUTH_A: + case MC_AUTH_B: + szParamLen = sizeof (struct mifare_param_auth); + break; - // Data command - case MC_WRITE: - szParamLen = sizeof (struct mifare_param_data); - break; + // Data command + case MC_WRITE: + szParamLen = sizeof (struct mifare_param_data); + break; - // Value command - case MC_DECREMENT: - case MC_INCREMENT: - case MC_TRANSFER: - szParamLen = sizeof (struct mifare_param_value); - break; + // Value command + case MC_DECREMENT: + case MC_INCREMENT: + case MC_TRANSFER: + szParamLen = sizeof (struct mifare_param_value); + break; - // Please fix your code, you never should reach this statement - default: - return false; - break; + // Please fix your code, you never should reach this statement + default: + return false; + break; } // When available, copy the parameter bytes diff --git a/utils/nfc-emulate-forum-tag4.c b/utils/nfc-emulate-forum-tag4.c index c1b4a19..2ca414a 100644 --- a/utils/nfc-emulate-forum-tag4.c +++ b/utils/nfc-emulate-forum-tag4.c @@ -98,7 +98,7 @@ uint8_t nfcforum_capability_container[] = { 0x00, 0xFF, /* MLc Maximum C-ADPU data size */ 0x04, /* T field of the NDEF File-Control TLV */ 0x06, /* L field of the NDEF File-Control TLV */ - /* V field of the NDEF File-Control TLV */ + /* V field of the NDEF File-Control TLV */ 0xE1, 0x04, /* File identifier */ 0xFF, 0xFE, /* Maximum NDEF Size */ 0x00, /* NDEF file read access condition */ @@ -143,79 +143,79 @@ nfcforum_tag4_io (struct nfc_emulator *emulator, const uint8_t *data_in, const s #define ISO7816_UPDATE_BINARY 0xD6 switch(data_in[INS]) { - case ISO7816_SELECT: + case ISO7816_SELECT: - switch (data_in[P1]) { - case 0x00: /* Select by ID */ - if ((data_in[P2] | 0x0C) != 0x0C) - return -ENOTSUP; + switch (data_in[P1]) { + case 0x00: /* Select by ID */ + if ((data_in[P2] | 0x0C) != 0x0C) + return -ENOTSUP; - const uint8_t ndef_capability_container[] = { 0xE1, 0x03 }; - const uint8_t ndef_file[] = { 0xE1, 0x04 }; - if ((data_in[LC] == sizeof (ndef_capability_container)) && (0 == memcmp (ndef_capability_container, data_in + DATA, data_in[LC]))) { - memcpy (data_out, "\x90\x00", res = 2); - state_machine_data->current_file = CC_FILE; - } else if ((data_in[LC] == sizeof (ndef_file)) && (0 == memcmp (ndef_file, data_in + DATA, data_in[LC]))) { - memcpy (data_out, "\x90\x00", res = 2); - state_machine_data->current_file = NDEF_FILE; - } else { - memcpy (data_out, "\x6a\x00", res = 2); - state_machine_data->current_file = NONE; + const uint8_t ndef_capability_container[] = { 0xE1, 0x03 }; + const uint8_t ndef_file[] = { 0xE1, 0x04 }; + if ((data_in[LC] == sizeof (ndef_capability_container)) && (0 == memcmp (ndef_capability_container, data_in + DATA, data_in[LC]))) { + memcpy (data_out, "\x90\x00", res = 2); + state_machine_data->current_file = CC_FILE; + } else if ((data_in[LC] == sizeof (ndef_file)) && (0 == memcmp (ndef_file, data_in + DATA, data_in[LC]))) { + memcpy (data_out, "\x90\x00", res = 2); + state_machine_data->current_file = NDEF_FILE; + } else { + memcpy (data_out, "\x6a\x00", res = 2); + state_machine_data->current_file = NONE; + } + + break; + case 0x04: /* Select by name */ + if (data_in[P2] != 0x00) + return -ENOTSUP; + + const uint8_t ndef_tag_application_name_v1[] = { 0xD2, 0x76, 0x00, 0x00, 0x85, 0x01, 0x00 }; + const uint8_t ndef_tag_application_name_v2[] = { 0xD2, 0x76, 0x00, 0x00, 0x85, 0x01, 0x01 }; + if ((type4v == 1) && (data_in[LC] == sizeof (ndef_tag_application_name_v1)) && (0 == memcmp (ndef_tag_application_name_v1, data_in + DATA, data_in[LC]))) + memcpy (data_out, "\x90\x00", res = 2); + else if ((type4v == 2) && (data_in[LC] == sizeof (ndef_tag_application_name_v2)) && (0 == memcmp (ndef_tag_application_name_v2, data_in + DATA, data_in[LC]))) + memcpy (data_out, "\x90\x00", res = 2); + else + memcpy (data_out, "\x6a\x82", res = 2); + + break; + default: + return -ENOTSUP; } break; - case 0x04: /* Select by name */ - if (data_in[P2] != 0x00) - return -ENOTSUP; - - const uint8_t ndef_tag_application_name_v1[] = { 0xD2, 0x76, 0x00, 0x00, 0x85, 0x01, 0x00 }; - const uint8_t ndef_tag_application_name_v2[] = { 0xD2, 0x76, 0x00, 0x00, 0x85, 0x01, 0x01 }; - if ((type4v == 1) && (data_in[LC] == sizeof (ndef_tag_application_name_v1)) && (0 == memcmp (ndef_tag_application_name_v1, data_in + DATA, data_in[LC]))) - memcpy (data_out, "\x90\x00", res = 2); - else if ((type4v == 2) && (data_in[LC] == sizeof (ndef_tag_application_name_v2)) && (0 == memcmp (ndef_tag_application_name_v2, data_in + DATA, data_in[LC]))) - memcpy (data_out, "\x90\x00", res = 2); - else - memcpy (data_out, "\x6a\x82", res = 2); - + case ISO7816_READ_BINARY: + if ((size_t)(data_in[LC] + 2) > data_out_len) { + return -ENOSPC; + } + switch (state_machine_data->current_file) { + case NONE: + memcpy (data_out, "\x6a\x82", res = 2); + break; + case CC_FILE: + memcpy (data_out, nfcforum_capability_container + (data_in[P1] << 8) + data_in[P2], data_in[LC]); + memcpy (data_out + data_in[LC], "\x90\x00", 2); + res = data_in[LC] + 2; + break; + case NDEF_FILE: + memcpy (data_out, ndef_data->ndef_file + (data_in[P1] << 8) + data_in[P2], data_in[LC]); + memcpy (data_out + data_in[LC], "\x90\x00", 2); + res = data_in[LC] + 2; + break; + } break; - default: - return -ENOTSUP; - } - break; - case ISO7816_READ_BINARY: - if ((size_t)(data_in[LC] + 2) > data_out_len) { - return -ENOSPC; - } - switch (state_machine_data->current_file) { - case NONE: - memcpy (data_out, "\x6a\x82", res = 2); + case ISO7816_UPDATE_BINARY: + memcpy (ndef_data->ndef_file + (data_in[P1] << 8) + data_in[P2], data_in + DATA, data_in[LC]); + if ((data_in[P1] << 8) + data_in[P2] == 0) { + ndef_data->ndef_file_len = (ndef_data->ndef_file[0] << 8) + ndef_data->ndef_file[1] + 2; + } + memcpy (data_out, "\x90\x00", res = 2); break; - case CC_FILE: - memcpy (data_out, nfcforum_capability_container + (data_in[P1] << 8) + data_in[P2], data_in[LC]); - memcpy (data_out + data_in[LC], "\x90\x00", 2); - res = data_in[LC] + 2; - break; - case NDEF_FILE: - memcpy (data_out, ndef_data->ndef_file + (data_in[P1] << 8) + data_in[P2], data_in[LC]); - memcpy (data_out + data_in[LC], "\x90\x00", 2); - res = data_in[LC] + 2; - break; - } - break; - - case ISO7816_UPDATE_BINARY: - memcpy (ndef_data->ndef_file + (data_in[P1] << 8) + data_in[P2], data_in + DATA, data_in[LC]); - if ((data_in[P1] << 8) + data_in[P2] == 0) { - ndef_data->ndef_file_len = (ndef_data->ndef_file[0] << 8) + ndef_data->ndef_file[1] + 2; - } - memcpy (data_out, "\x90\x00", res = 2); - break; - default: // Unknown - if (!quiet_output) { - printf("Unknown frame, emulated target abort.\n"); - } - res = -ENOTSUP; + default: // Unknown + if (!quiet_output) { + printf("Unknown frame, emulated target abort.\n"); + } + res = -ENOTSUP; } } else { res = -ENOTSUP; diff --git a/utils/nfc-list.c b/utils/nfc-list.c index 8bd4cad..91e754f 100644 --- a/utils/nfc-list.c +++ b/utils/nfc-list.c @@ -130,10 +130,10 @@ main (int argc, const char *argv[]) ERR ("Unable to open NFC device: %s", connstrings[i]); continue; } - if (nfc_initiator_init (pnd) < 0) { - nfc_perror (pnd, "nfc_initiator_init"); - exit (EXIT_FAILURE); - } + if (nfc_initiator_init (pnd) < 0) { + nfc_perror (pnd, "nfc_initiator_init"); + exit (EXIT_FAILURE); + } printf ("NFC device: %s opened\n", nfc_device_get_name (pnd)); diff --git a/utils/nfc-mfclassic.c b/utils/nfc-mfclassic.c index 76c34e4..e600797 100644 --- a/utils/nfc-mfclassic.c +++ b/utils/nfc-mfclassic.c @@ -468,131 +468,131 @@ main (int argc, const char *argv[]) } switch (atAction) { - case ACTION_USAGE: - print_usage (argv[0]); - exit (EXIT_FAILURE); - break; - case ACTION_READ: - case ACTION_WRITE: - if (bUseKeyFile) { - pfKeys = fopen (argv[4], "rb"); - if (pfKeys == NULL) { - printf ("Could not open keys file: %s\n", argv[4]); - exit (EXIT_FAILURE); - } - if (fread (&mtKeys, 1, sizeof (mtKeys), pfKeys) != sizeof (mtKeys)) { - printf ("Could not read keys file: %s\n", argv[4]); - fclose (pfKeys); - exit (EXIT_FAILURE); - } - fclose (pfKeys); - } - - if (atAction == ACTION_READ) { - memset (&mtDump, 0x00, sizeof (mtDump)); - } else { - pfDump = fopen (argv[3], "rb"); - - if (pfDump == NULL) { - printf ("Could not open dump file: %s\n", argv[3]); - exit (EXIT_FAILURE); - } - - if (fread (&mtDump, 1, sizeof (mtDump), pfDump) != sizeof (mtDump)) { - printf ("Could not read dump file: %s\n", argv[3]); - fclose (pfDump); - exit (EXIT_FAILURE); - } - fclose (pfDump); - } - // printf("Successfully opened required files\n"); - - nfc_init (NULL); - - // Try to open the NFC reader - pnd = nfc_open (NULL, NULL); - if (pnd == NULL) { - printf ("Error opening NFC reader\n"); + case ACTION_USAGE: + print_usage (argv[0]); exit (EXIT_FAILURE); - } - - if (nfc_initiator_init (pnd) < 0) { - nfc_perror (pnd, "nfc_initiator_init"); - exit (EXIT_FAILURE); - }; - - // Let the reader only try once to find a tag - if (nfc_device_set_property_bool (pnd, NP_INFINITE_SELECT, false) < 0) { - nfc_perror (pnd, "nfc_device_set_property_bool"); - exit (EXIT_FAILURE); - } - // Disable ISO14443-4 switching in order to read devices that emulate Mifare Classic with ISO14443-4 compliance. - nfc_device_set_property_bool (pnd, NP_AUTO_ISO14443_4, false); - - printf ("NFC reader: %s opened\n", nfc_device_get_name (pnd)); - - // Try to find a MIFARE Classic tag - if (nfc_initiator_select_passive_target (pnd, nmMifare, NULL, 0, &nt) < 0) { - printf ("Error: no tag was found\n"); - nfc_close (pnd); - nfc_exit (NULL); - exit (EXIT_FAILURE); - } - // Test if we are dealing with a MIFARE compatible tag - if ((nt.nti.nai.btSak & 0x08) == 0) { - printf ("Warning: tag is probably not a MFC!\n"); - } - - // Get the info from the current tag - pbtUID = nt.nti.nai.abtUid; - - if (bUseKeyFile) { - uint8_t fileUid[4]; - memcpy (fileUid, mtKeys.amb[0].mbm.abtUID, 4); - // Compare if key dump UID is the same as the current tag UID, at least for the first 4 bytes - if (memcmp (pbtUID, fileUid, 4) != 0) { - printf ("Expected MIFARE Classic card with UID starting as: %02x%02x%02x%02x\n", - fileUid[0], fileUid[1], fileUid[2], fileUid[3]); - } - } - printf ("Found MIFARE Classic card:\n"); - print_nfc_iso14443a_info (nt.nti.nai, false); - - // Guessing size - if ((nt.nti.nai.abtAtqa[1] & 0x02) == 0x02) - // 4K - uiBlocks = 0xff; - else if ((nt.nti.nai.btSak & 0x01) == 0x01) - // 320b - uiBlocks = 0x13; - else - // 1K - // TODO: for MFP it is 0x7f (2K) but how to be sure it's a MFP? Try to get RATS? - uiBlocks = 0x3f; - printf ("Guessing size: seems to be a %i-byte card\n", (uiBlocks + 1) * 16); - - if (atAction == ACTION_READ) { - if (read_card (unlock)) { - printf ("Writing data to file: %s ...", argv[3]); - fflush (stdout); - pfDump = fopen (argv[3], "wb"); - if (pfDump == NULL) { - printf ("Could not open dump file: %s\n", argv[3]); - exit (EXIT_FAILURE); - } - if (fwrite (&mtDump, 1, sizeof (mtDump), pfDump) != sizeof (mtDump)) { - printf ("\nCould not write to file: %s\n", argv[3]); + break; + case ACTION_READ: + case ACTION_WRITE: + if (bUseKeyFile) { + pfKeys = fopen (argv[4], "rb"); + if (pfKeys == NULL) { + printf ("Could not open keys file: %s\n", argv[4]); + exit (EXIT_FAILURE); + } + if (fread (&mtKeys, 1, sizeof (mtKeys), pfKeys) != sizeof (mtKeys)) { + printf ("Could not read keys file: %s\n", argv[4]); + fclose (pfKeys); + exit (EXIT_FAILURE); + } + fclose (pfKeys); + } + + if (atAction == ACTION_READ) { + memset (&mtDump, 0x00, sizeof (mtDump)); + } else { + pfDump = fopen (argv[3], "rb"); + + if (pfDump == NULL) { + printf ("Could not open dump file: %s\n", argv[3]); + exit (EXIT_FAILURE); + } + + if (fread (&mtDump, 1, sizeof (mtDump), pfDump) != sizeof (mtDump)) { + printf ("Could not read dump file: %s\n", argv[3]); + fclose (pfDump); exit (EXIT_FAILURE); } - printf ("Done.\n"); fclose (pfDump); } - } else if (atAction == ACTION_WRITE) { - write_card (unlock); - } + // printf("Successfully opened required files\n"); - nfc_close (pnd); - break; + nfc_init (NULL); + + // Try to open the NFC reader + pnd = nfc_open (NULL, NULL); + if (pnd == NULL) { + printf ("Error opening NFC reader\n"); + exit (EXIT_FAILURE); + } + + if (nfc_initiator_init (pnd) < 0) { + nfc_perror (pnd, "nfc_initiator_init"); + exit (EXIT_FAILURE); + }; + + // Let the reader only try once to find a tag + if (nfc_device_set_property_bool (pnd, NP_INFINITE_SELECT, false) < 0) { + nfc_perror (pnd, "nfc_device_set_property_bool"); + exit (EXIT_FAILURE); + } + // Disable ISO14443-4 switching in order to read devices that emulate Mifare Classic with ISO14443-4 compliance. + nfc_device_set_property_bool (pnd, NP_AUTO_ISO14443_4, false); + + printf ("NFC reader: %s opened\n", nfc_device_get_name (pnd)); + + // Try to find a MIFARE Classic tag + if (nfc_initiator_select_passive_target (pnd, nmMifare, NULL, 0, &nt) < 0) { + printf ("Error: no tag was found\n"); + nfc_close (pnd); + nfc_exit (NULL); + exit (EXIT_FAILURE); + } + // Test if we are dealing with a MIFARE compatible tag + if ((nt.nti.nai.btSak & 0x08) == 0) { + printf ("Warning: tag is probably not a MFC!\n"); + } + + // Get the info from the current tag + pbtUID = nt.nti.nai.abtUid; + + if (bUseKeyFile) { + uint8_t fileUid[4]; + memcpy (fileUid, mtKeys.amb[0].mbm.abtUID, 4); + // Compare if key dump UID is the same as the current tag UID, at least for the first 4 bytes + if (memcmp (pbtUID, fileUid, 4) != 0) { + printf ("Expected MIFARE Classic card with UID starting as: %02x%02x%02x%02x\n", + fileUid[0], fileUid[1], fileUid[2], fileUid[3]); + } + } + printf ("Found MIFARE Classic card:\n"); + print_nfc_iso14443a_info (nt.nti.nai, false); + + // Guessing size + if ((nt.nti.nai.abtAtqa[1] & 0x02) == 0x02) + // 4K + uiBlocks = 0xff; + else if ((nt.nti.nai.btSak & 0x01) == 0x01) + // 320b + uiBlocks = 0x13; + else + // 1K + // TODO: for MFP it is 0x7f (2K) but how to be sure it's a MFP? Try to get RATS? + uiBlocks = 0x3f; + printf ("Guessing size: seems to be a %i-byte card\n", (uiBlocks + 1) * 16); + + if (atAction == ACTION_READ) { + if (read_card (unlock)) { + printf ("Writing data to file: %s ...", argv[3]); + fflush (stdout); + pfDump = fopen (argv[3], "wb"); + if (pfDump == NULL) { + printf ("Could not open dump file: %s\n", argv[3]); + exit (EXIT_FAILURE); + } + if (fwrite (&mtDump, 1, sizeof (mtDump), pfDump) != sizeof (mtDump)) { + printf ("\nCould not write to file: %s\n", argv[3]); + exit (EXIT_FAILURE); + } + printf ("Done.\n"); + fclose (pfDump); + } + } else if (atAction == ACTION_WRITE) { + write_card (unlock); + } + + nfc_close (pnd); + break; }; nfc_exit (NULL); diff --git a/utils/nfc-probe.c b/utils/nfc-probe.c index b35c73f..25d3061 100644 --- a/utils/nfc-probe.c +++ b/utils/nfc-probe.c @@ -116,8 +116,8 @@ main (int argc, const char *argv[]) } nfc_close (pnd); } else { - printf("nfc_open failed for %s\n", connstrings[i]); - } + printf("nfc_open failed for %s\n", connstrings[i]); + } } res = EXIT_SUCCESS; diff --git a/utils/nfc-read-forum-tag3.c b/utils/nfc-read-forum-tag3.c index 9e046cc..4013e1a 100644 --- a/utils/nfc-read-forum-tag3.c +++ b/utils/nfc-read-forum-tag3.c @@ -60,9 +60,9 @@ static nfc_device *pnd; static void print_usage(char *progname) { - fprintf (stderr, "usage: %s -o FILE\n", progname); - fprintf (stderr, "\nOptions:\n"); - fprintf (stderr, " -o Extract NDEF message if available in FILE\n"); + fprintf (stderr, "usage: %s -o FILE\n", progname); + fprintf (stderr, "\nOptions:\n"); + fprintf (stderr, " -o Extract NDEF message if available in FILE\n"); } static void stop_select (int sig) @@ -89,11 +89,11 @@ static int nfc_forum_tag_type3_check (nfc_device *dev, const nfc_target nt, const uint16_t block, const uint8_t block_count, uint8_t *data, size_t *data_len) { uint8_t payload[1024] = { - 1, // Services - 0x0B, 0x00, // NFC Forum Tag Type 3's Service code - block_count, - 0x80, block, // block 0 - }; + 1, // Services + 0x0B, 0x00, // NFC Forum Tag Type 3's Service code + block_count, + 0x80, block, // block 0 + }; size_t payload_len = 1 + 2 + 1; for (uint8_t b = 0; b < block_count; b++) { @@ -157,19 +157,19 @@ main(int argc, char *argv[]) char *ndef_output = NULL; while ((ch = getopt (argc, argv, "ho:")) != -1) { switch (ch) { - case 'h': - print_usage(argv[0]); - exit (EXIT_SUCCESS); - break; - case 'o': - ndef_output = optarg; - break; - case '?': - if (optopt == 'o') - fprintf (stderr, "Option -%c requires an argument.\n", optopt); - default: - print_usage (argv[0]); - exit (EXIT_FAILURE); + case 'h': + print_usage(argv[0]); + exit (EXIT_SUCCESS); + break; + case 'o': + ndef_output = optarg; + break; + case '?': + if (optopt == 'o') + fprintf (stderr, "Option -%c requires an argument.\n", optopt); + default: + print_usage (argv[0]); + exit (EXIT_FAILURE); } } diff --git a/utils/nfc-relay-picc.c b/utils/nfc-relay-picc.c index 2235bae..d086ffb 100644 --- a/utils/nfc-relay-picc.c +++ b/utils/nfc-relay-picc.c @@ -395,7 +395,7 @@ main (int argc, char *argv[]) szCapduLen = (size_t) res; if (target_only_mode) { if (print_hex_fd4(abtCapdu, szCapduLen, "C-APDU") != EXIT_SUCCESS) { - fprintf (stderr, "Error while printing C-APDU to FD4\n"); + fprintf (stderr, "Error while printing C-APDU to FD4\n"); nfc_close (pndTarget); nfc_exit (NULL); exit(EXIT_FAILURE); @@ -461,7 +461,7 @@ main (int argc, char *argv[]) } } else { if (print_hex_fd4(abtRapdu, szRapduLen, "R-APDU") != EXIT_SUCCESS) { - fprintf (stderr, "Error while printing R-APDU to FD4\n"); + fprintf (stderr, "Error while printing R-APDU to FD4\n"); nfc_close (pndInitiator); nfc_exit (NULL); exit(EXIT_FAILURE); diff --git a/utils/nfc-utils.c b/utils/nfc-utils.c index 0c9cdd5..fc5b1a9 100644 --- a/utils/nfc-utils.c +++ b/utils/nfc-utils.c @@ -38,65 +38,79 @@ struct card_atqa { - uint16_t atqa; - uint16_t mask; - char type[128]; - // list of up to 8 SAK values compatible with this ATQA - int saklist[8]; + uint16_t atqa; + uint16_t mask; + char type[128]; + // list of up to 8 SAK values compatible with this ATQA + int saklist[8]; }; struct card_sak { - uint8_t sak; - uint8_t mask; - char type[128]; + uint8_t sak; + uint8_t mask; + char type[128]; }; struct card_atqa const_ca[] = { - {0x0044, 0xffff, "MIFARE Ultralight", - {0, -1} }, - {0x0044, 0xffff, "MIFARE Ultralight C", - {0, -1} }, - {0x0004, 0xff0f, "MIFARE Mini 0.3K", - {1, -1} }, - {0x0004, 0xff0f, "MIFARE Classic 1K", - {2, -1} }, - {0x0002, 0xff0f, "MIFARE Classic 4K", - {3, -1} }, - {0x0004, 0xffff, "MIFARE Plus (4 Byte UID or 4 Byte RID)", - {4, 5, 6, 7, 8, 9, -1} }, - {0x0002, 0xffff, "MIFARE Plus (4 Byte UID or 4 Byte RID)", - {4, 5, 6, 7, 8, 9, -1} }, - {0x0044, 0xffff, "MIFARE Plus (7 Byte UID)", - {4, 5, 6, 7, 8, 9, -1} }, - {0x0042, 0xffff, "MIFARE Plus (7 Byte UID)", - {4, 5, 6, 7, 8, 9, -1} }, - {0x0344, 0xffff, "MIFARE DESFire", - {10, 11, -1} }, - {0x0044, 0xffff, "P3SR008", - {-1} }, // TODO we need SAK info - {0x0004, 0xf0ff, "SmartMX with MIFARE 1K emulation", - {12, -1} }, - {0x0002, 0xf0ff, "SmartMX with MIFARE 4K emulation", - {12, -1} }, - {0x0048, 0xf0ff, "SmartMX with 7 Byte UID", - {12, -1} } + { 0x0044, 0xffff, "MIFARE Ultralight", + {0, -1} + }, + { 0x0044, 0xffff, "MIFARE Ultralight C", + {0, -1} + }, + { 0x0004, 0xff0f, "MIFARE Mini 0.3K", + {1, -1} + }, + { 0x0004, 0xff0f, "MIFARE Classic 1K", + {2, -1} + }, + { 0x0002, 0xff0f, "MIFARE Classic 4K", + {3, -1} + }, + { 0x0004, 0xffff, "MIFARE Plus (4 Byte UID or 4 Byte RID)", + {4, 5, 6, 7, 8, 9, -1} + }, + { 0x0002, 0xffff, "MIFARE Plus (4 Byte UID or 4 Byte RID)", + {4, 5, 6, 7, 8, 9, -1} + }, + { 0x0044, 0xffff, "MIFARE Plus (7 Byte UID)", + {4, 5, 6, 7, 8, 9, -1} + }, + { 0x0042, 0xffff, "MIFARE Plus (7 Byte UID)", + {4, 5, 6, 7, 8, 9, -1} + }, + { 0x0344, 0xffff, "MIFARE DESFire", + {10, 11, -1} + }, + { 0x0044, 0xffff, "P3SR008", + {-1} + }, // TODO we need SAK info + { 0x0004, 0xf0ff, "SmartMX with MIFARE 1K emulation", + {12, -1} + }, + { 0x0002, 0xf0ff, "SmartMX with MIFARE 4K emulation", + {12, -1} + }, + { 0x0048, 0xf0ff, "SmartMX with 7 Byte UID", + {12, -1} + } }; struct card_sak const_cs[] = { - {0x00, 0xff, "" }, // 00 MIFARE Ultralight / Ultralight C - {0x09, 0xff, "" }, // 01 MIFARE Mini 0.3K - {0x08, 0xff, "" }, // 02 MIFARE Classic 1K - {0x18, 0xff, "" }, // 03 MIFARE Classik 4K - {0x08, 0xff, " 2K, Security level 1" }, // 04 MIFARE Plus - {0x18, 0xff, " 4K, Security level 1" }, // 05 MIFARE Plus - {0x10, 0xff, " 2K, Security level 2" }, // 06 MIFARE Plus - {0x11, 0xff, " 4K, Security level 2" }, // 07 MIFARE Plus - {0x20, 0xff, " 2K, Security level 3" }, // 08 MIFARE Plus - {0x20, 0xff, " 4K, Security level 3" }, // 09 MIFARE Plus - {0x20, 0xff, " 4K" }, // 10 MIFARE DESFire - {0x20, 0xff, " EV1 2K/4K/8K" }, // 11 MIFARE DESFire - {0x00, 0x00, "" }, // 12 SmartMX + {0x00, 0xff, "" }, // 00 MIFARE Ultralight / Ultralight C + {0x09, 0xff, "" }, // 01 MIFARE Mini 0.3K + {0x08, 0xff, "" }, // 02 MIFARE Classic 1K + {0x18, 0xff, "" }, // 03 MIFARE Classik 4K + {0x08, 0xff, " 2K, Security level 1" }, // 04 MIFARE Plus + {0x18, 0xff, " 4K, Security level 1" }, // 05 MIFARE Plus + {0x10, 0xff, " 2K, Security level 2" }, // 06 MIFARE Plus + {0x11, 0xff, " 4K, Security level 2" }, // 07 MIFARE Plus + {0x20, 0xff, " 2K, Security level 3" }, // 08 MIFARE Plus + {0x20, 0xff, " 4K, Security level 3" }, // 09 MIFARE Plus + {0x20, 0xff, " 4K" }, // 10 MIFARE DESFire + {0x20, 0xff, " EV1 2K/4K/8K" }, // 11 MIFARE DESFire + {0x00, 0x00, "" }, // 12 SmartMX }; uint8_t @@ -190,16 +204,16 @@ print_nfc_iso14443a_info (const nfc_iso14443a_info nai, bool verbose) switch ((nai.abtAtqa[1] & 0xc0)>>6) { case 0: printf("single\n"); - break; + break; case 1: printf("double\n"); - break; + break; case 2: printf("triple\n"); - break; + break; case 3: printf("RFU\n"); - break; + break; } printf("* bit frame anticollision "); switch (nai.abtAtqa[1] & 0x1f) { @@ -209,10 +223,10 @@ print_nfc_iso14443a_info (const nfc_iso14443a_info nai, bool verbose) case 0x08: case 0x10: printf("supported\n"); - break; + break; default: printf("not supported\n"); - break; + break; } } printf (" UID (NFCID%c): ", (nai.abtUid[0] == 0x08 ? '3' : '1')); @@ -327,40 +341,40 @@ print_nfc_iso14443a_info (const nfc_iso14443a_info nai, bool verbose) switch (CTC & 0xf0) { case 0x00: printf("(Multiple) Virtual Cards\n"); - break; + break; case 0x10: printf("Mifare DESFire\n"); - break; + break; case 0x20: printf("Mifare Plus\n"); - break; + break; default: printf("RFU\n"); - break; + break; } printf(" * Memory size: "); switch (CTC & 0x0f) { case 0x00: printf("<1 kbyte\n"); - break; + break; case 0x01: printf("1 kbyte\n"); - break; + break; case 0x02: printf("2 kbyte\n"); - break; + break; case 0x03: printf("4 kbyte\n"); - break; + break; case 0x04: printf("8 kbyte\n"); - break; + break; case 0x0f: printf("Unspecified\n"); - break; + break; default: printf("RFU\n"); - break; + break; } } if ((nai.szAtsLen - offset) > 0) { // Omit 2 CRC bytes @@ -370,31 +384,31 @@ print_nfc_iso14443a_info (const nfc_iso14443a_info nai, bool verbose) switch (CVC & 0xf0) { case 0x00: printf("Engineering sample\n"); - break; + break; case 0x20: printf("Released\n"); - break; + break; default: printf("RFU\n"); - break; + break; } printf(" * Chip Generation: "); switch (CVC & 0x0f) { case 0x00: printf("Generation 1\n"); - break; + break; case 0x01: printf("Generation 2\n"); - break; + break; case 0x02: printf("Generation 3\n"); - break; + break; case 0x0f: printf("Unspecified\n"); - break; + break; default: printf("RFU\n"); - break; + break; } } if ((nai.szAtsLen - offset) > 0) { // Omit 2 CRC bytes @@ -474,40 +488,40 @@ print_nfc_iso14443a_info (const nfc_iso14443a_info nai, bool verbose) case 0x000488: printf("* Mifare Classic 1K Infineon\n"); found_possible_match = true; - break; + break; case 0x000298: printf("* Gemplus MPCOS\n"); found_possible_match = true; - break; + break; case 0x030428: printf("* JCOP31\n"); found_possible_match = true; - break; + break; case 0x004820: printf("* JCOP31 v2.4.1\n"); printf("* JCOP31 v2.2\n"); found_possible_match = true; - break; + break; case 0x000428: printf("* JCOP31 v2.3.1\n"); found_possible_match = true; - break; + break; case 0x000453: printf("* Fudan FM1208SH01\n"); found_possible_match = true; - break; + break; case 0x000820: printf("* Fudan FM1208\n"); found_possible_match = true; - break; + break; case 0x000238: printf("* MFC 4K emulated by Nokia 6212 Classic\n"); found_possible_match = true; - break; + break; case 0x000838: printf("* MFC 4K emulated by Nokia 6131 NFC\n"); found_possible_match = true; - break; + break; } if (! found_possible_match) { printf("* Unknown card, sorry\n"); @@ -609,7 +623,7 @@ print_nfc_iso14443bi_info (const nfc_iso14443bi_info nii, bool verbose) printf ("%i\n", version); } - if ((nii.btVerLog & 0x80) && (nii.btConfig & 0x80)){ + if ((nii.btVerLog & 0x80) && (nii.btConfig & 0x80)) { printf (" Wait Enable: yes"); } } @@ -663,28 +677,28 @@ print_nfc_target (const nfc_target nt, bool verbose) switch(nt.nm.nmt) { case NMT_ISO14443A: print_nfc_iso14443a_info (nt.nti.nai, verbose); - break; + break; case NMT_JEWEL: print_nfc_jewel_info (nt.nti.nji, verbose); - break; + break; case NMT_FELICA: print_nfc_felica_info (nt.nti.nfi, verbose); - break; + break; case NMT_ISO14443B: print_nfc_iso14443b_info (nt.nti.nbi, verbose); - break; + break; case NMT_ISO14443BI: print_nfc_iso14443bi_info (nt.nti.nii, verbose); - break; + break; case NMT_ISO14443B2SR: print_nfc_iso14443b2sr_info (nt.nti.nsi, verbose); - break; + break; case NMT_ISO14443B2CT: print_nfc_iso14443b2ct_info (nt.nti.nci, verbose); - break; + break; case NMT_DEP: print_nfc_dep_info (nt.nti.ndi, verbose); - break; + break; } } diff --git a/windows/usb/include/usb.h b/windows/usb/include/usb.h index f93c6b2..663749e 100644 --- a/windows/usb/include/usb.h +++ b/windows/usb/include/usb.h @@ -361,27 +361,27 @@ extern "C" { /* Windows specific functions */ - #define LIBUSB_HAS_INSTALL_SERVICE_NP 1 +#define LIBUSB_HAS_INSTALL_SERVICE_NP 1 int usb_install_service_np(void); void CALLBACK usb_install_service_np_rundll(HWND wnd, HINSTANCE instance, LPSTR cmd_line, int cmd_show); - #define LIBUSB_HAS_UNINSTALL_SERVICE_NP 1 +#define LIBUSB_HAS_UNINSTALL_SERVICE_NP 1 int usb_uninstall_service_np(void); void CALLBACK usb_uninstall_service_np_rundll(HWND wnd, HINSTANCE instance, LPSTR cmd_line, int cmd_show); - #define LIBUSB_HAS_INSTALL_DRIVER_NP 1 +#define LIBUSB_HAS_INSTALL_DRIVER_NP 1 int usb_install_driver_np(const char *inf_file); void CALLBACK usb_install_driver_np_rundll(HWND wnd, HINSTANCE instance, LPSTR cmd_line, int cmd_show); - #define LIBUSB_HAS_TOUCH_INF_FILE_NP 1 +#define LIBUSB_HAS_TOUCH_INF_FILE_NP 1 int usb_touch_inf_file_np(const char *inf_file); void CALLBACK usb_touch_inf_file_np_rundll(HWND wnd, HINSTANCE instance, LPSTR cmd_line, int cmd_show); - #define LIBUSB_HAS_INSTALL_NEEDS_RESTART_NP 1 +#define LIBUSB_HAS_INSTALL_NEEDS_RESTART_NP 1 int usb_install_needs_restart_np(void); const struct usb_version *usb_get_version(void);