From c718fafee74450ad64458e773bdc19943885ffce Mon Sep 17 00:00:00 2001 From: Audrey Diacre Date: Wed, 23 Nov 2011 15:55:40 +0000 Subject: [PATCH] Massive code clean up: (Fixes Issue 161) - Remove typedef from internal structs - Remove _t suffix from types - Fix tests using connstrings --- examples/doc/quick_start_example1.c | 6 +- examples/nfc-anticol.c | 2 +- examples/nfc-dep-initiator.c | 4 +- examples/nfc-dep-target.c | 4 +- examples/nfc-emulate-tag.c | 50 ++++--- examples/nfc-emulate-uid.c | 6 +- examples/nfc-poll.c | 6 +- examples/nfc-relay.c | 6 +- examples/pn53x-diagnose.c | 2 +- examples/pn53x-sam.c | 8 +- examples/pn53x-tamashell.c | 2 +- include/nfc/nfc-emulation.h | 4 +- include/nfc/nfc-types.h | 90 ++++++------- include/nfc/nfc.h | 48 +++---- libnfc/buses/uart_posix.c | 34 ++--- libnfc/buses/uart_win32.c | 26 ++-- libnfc/chips/pn53x.c | 196 ++++++++++++++-------------- libnfc/chips/pn53x.h | 126 +++++++++--------- libnfc/drivers/acr122.c | 16 +-- libnfc/drivers/acr122.h | 8 +- libnfc/drivers/arygon.c | 24 ++-- libnfc/drivers/arygon.h | 8 +- libnfc/drivers/pn532_uart.c | 22 ++-- libnfc/drivers/pn532_uart.h | 8 +- libnfc/drivers/pn53x_usb.c | 22 ++-- libnfc/drivers/pn53x_usb.h | 8 +- libnfc/nfc-device.c | 8 +- libnfc/nfc-emulation.c | 2 +- libnfc/nfc-internal.c | 3 +- libnfc/nfc-internal.h | 46 +++---- libnfc/nfc.c | 120 ++++++++--------- test/test_access_storm.c | 14 +- test/test_dep.c | 20 +-- test/test_register_access.c | 8 +- test/test_register_endianness.c | 8 +- utils/mifare.c | 8 +- utils/mifare.h | 20 +-- utils/nfc-emulate-forum-tag2.c | 4 +- utils/nfc-emulate-forum-tag4.c | 4 +- utils/nfc-list.c | 6 +- utils/nfc-mfclassic.c | 6 +- utils/nfc-mfsetuid.c | 2 +- utils/nfc-mfultralight.c | 6 +- utils/nfc-read-forum-tag3.c | 10 +- utils/nfc-relay-picc.c | 10 +- utils/nfc-utils.c | 20 +-- utils/nfc-utils.h | 18 +-- 47 files changed, 546 insertions(+), 533 deletions(-) diff --git a/examples/doc/quick_start_example1.c b/examples/doc/quick_start_example1.c index 9d32642..d828bd0 100644 --- a/examples/doc/quick_start_example1.c +++ b/examples/doc/quick_start_example1.c @@ -10,8 +10,8 @@ int main (int argc, const char *argv[]) { - nfc_device_t *pnd; - nfc_target_info_t nti; + nfc_device *pnd; + nfc_target_info nti; // Display libnfc version const char *acLibnfcVersion = nfc_version (); @@ -30,7 +30,7 @@ main (int argc, const char *argv[]) printf ("Connected to NFC reader: %s\n", pnd->acName); // Poll for a ISO14443A (MIFARE) tag - const nfc_modulation_t nmMifare = { + const nfc_modulation nmMifare = { .nmt = NMT_ISO14443A, .nbr = NBR_106, }; diff --git a/examples/nfc-anticol.c b/examples/nfc-anticol.c index a1f906f..4566c98 100644 --- a/examples/nfc-anticol.c +++ b/examples/nfc-anticol.c @@ -60,7 +60,7 @@ static byte_t abtSak; static byte_t abtAts[MAX_FRAME_LEN]; static byte_t szAts = 0; static size_t szCL = 1;//Always start with Cascade Level 1 (CL1) -static nfc_device_t *pnd; +static nfc_device *pnd; bool quiet_output = false; bool force_rats = false; diff --git a/examples/nfc-dep-initiator.c b/examples/nfc-dep-initiator.c index db8ac9a..37cf78c 100644 --- a/examples/nfc-dep-initiator.c +++ b/examples/nfc-dep-initiator.c @@ -48,7 +48,7 @@ #define MAX_FRAME_LEN 264 -static nfc_device_t *pnd; +static nfc_device *pnd; void stop_dep_communication (int sig) { @@ -62,7 +62,7 @@ void stop_dep_communication (int sig) int main (int argc, const char *argv[]) { - nfc_target_t nt; + nfc_target nt; byte_t abtRx[MAX_FRAME_LEN]; size_t szRx = sizeof(abtRx); byte_t abtTx[] = "Hello World!"; diff --git a/examples/nfc-dep-target.c b/examples/nfc-dep-target.c index 031db8f..a46bf45 100644 --- a/examples/nfc-dep-target.c +++ b/examples/nfc-dep-target.c @@ -47,7 +47,7 @@ #define MAX_FRAME_LEN 264 -static nfc_device_t *pnd; +static nfc_device *pnd; void stop_dep_communication (int sig) { @@ -86,7 +86,7 @@ main (int argc, const char *argv[]) return EXIT_FAILURE; } - nfc_target_t nt = { + nfc_target nt = { .nm = { .nmt = NMT_DEP, .nbr = NBR_UNDEFINED diff --git a/examples/nfc-emulate-tag.c b/examples/nfc-emulate-tag.c index 79792c8..133701d 100644 --- a/examples/nfc-emulate-tag.c +++ b/examples/nfc-emulate-tag.c @@ -56,7 +56,7 @@ static byte_t abtRx[MAX_FRAME_LEN]; static size_t szRx = sizeof(abtRx); -static nfc_device_t *pnd; +static nfc_device *pnd; static bool quiet_output = false; static bool init_mfc_auth = false; @@ -71,7 +71,7 @@ intr_hdlr (void) } bool -target_io( nfc_target_t * pnt, const byte_t * pbtInput, const size_t szInput, byte_t * pbtOutput, size_t *pszOutput ) +target_io( nfc_target * pnt, const byte_t * pbtInput, const size_t szInput, byte_t * pbtOutput, size_t *pszOutput ) { bool loop = true; *pszOutput = 0; @@ -134,7 +134,7 @@ target_io( nfc_target_t * pnt, const byte_t * pbtInput, const size_t szInput, by } bool -nfc_target_emulate_tag(nfc_device_t* pnd, nfc_target_t * pnt) +nfc_target_emulate_tag(nfc_device* pnd, nfc_target * pnt) { size_t szTx; byte_t abtTx[MAX_FRAME_LEN]; @@ -203,7 +203,7 @@ main (int argc, char *argv[]) // Example of a Mifare Classic Mini // Note that crypto1 is not implemented in this example - nfc_target_t nt = { + nfc_target nt = { .nm = { .nmt = NMT_ISO14443A, .nbr = NBR_UNDEFINED, @@ -220,25 +220,37 @@ main (int argc, char *argv[]) }; /* // Example of a FeliCa - nfc_target_t nt = { - .nm.nmt = NMT_FELICA, - .nm.nbr = NBR_UNDEFINED, - .nti.nfi.abtId = { 0x01, 0xFE, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF }, - .nti.nfi.abtPad = { 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF }, - .nti.nfi.abtSysCode = { 0xFF, 0xFF }, + nfc_target nt = { + .nm = { + .nmt = NMT_FELICA, + .nbr = NBR_UNDEFINED, + }, + .nti = { + .nfi = { + .abtId = { 0x01, 0xFE, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF }, + .abtPad = { 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF }, + .abtSysCode = { 0xFF, 0xFF }, + }, + }, }; */ /* // Example of a ISO14443-4 (DESfire) - nfc_target_t nt = { - .nm.nmt = NMT_ISO14443A, - .nm.nbr = NBR_UNDEFINED, - .nti.nai.abtAtqa = { 0x03, 0x44 }, - .nti.nai.abtUid = { 0x08, 0xab, 0xcd, 0xef }, - .nti.nai.btSak = 0x20, - .nti.nai.szUidLen = 4, - .nti.nai.abtAts = { 0x75, 0x77, 0x81, 0x02, 0x80 }, - .nti.nai.szAtsLen = 5, + nfc_target nt = { + .nm = { + .nmt = NMT_ISO14443A, + .nbr = NBR_UNDEFINED, + }, + .nti = { + .nai = { + abtAtqa = { 0x03, 0x44 }, + abtUid = { 0x08, 0xab, 0xcd, 0xef }, + btSak = 0x20, + .szUidLen = 4, + .abtAts = { 0x75, 0x77, 0x81, 0x02, 0x80 }, + .szAtsLen = 5, + }, + }, }; */ diff --git a/examples/nfc-emulate-uid.c b/examples/nfc-emulate-uid.c index 4548dc8..a6f8387 100644 --- a/examples/nfc-emulate-uid.c +++ b/examples/nfc-emulate-uid.c @@ -58,7 +58,7 @@ static byte_t abtRecv[MAX_FRAME_LEN]; static size_t szRecvBits; -static nfc_device_t *pnd; +static nfc_device *pnd; // ISO14443A Anti-Collision response byte_t abtAtqa[2] = { 0x04, 0x00 }; @@ -139,8 +139,8 @@ main (int argc, char *argv[]) printf ("[+] To do this, please send any command after the anti-collision\n"); printf ("[+] For example, send a RATS command or use the \"nfc-anticol\" or \"nfc-list\" tool.\n"); - // Note: We have to build a "fake" nfc_target_t in order to do exactly the same that was done before the new nfc_target_init() was introduced. - nfc_target_t nt = { + // Note: We have to build a "fake" nfc_target in order to do exactly the same that was done before the new nfc_target_init() was introduced. + nfc_target nt = { .nm = { .nmt = NMT_ISO14443A, .nbr = NBR_UNDEFINED, diff --git a/examples/nfc-poll.c b/examples/nfc-poll.c index a5c27f1..c3b414c 100644 --- a/examples/nfc-poll.c +++ b/examples/nfc-poll.c @@ -51,7 +51,7 @@ #define MAX_DEVICE_COUNT 16 -static nfc_device_t *pnd = NULL; +static nfc_device *pnd = NULL; void stop_polling (int sig) { @@ -80,7 +80,7 @@ main (int argc, const char *argv[]) const uint8_t uiPollNr = 20; const uint8_t uiPeriod = 2; - const nfc_modulation_t nmModulations[5] = { + const nfc_modulation nmModulations[5] = { { .nmt = NMT_ISO14443A, .nbr = NBR_106 }, { .nmt = NMT_ISO14443B, .nbr = NBR_106 }, { .nmt = NMT_FELICA, .nbr = NBR_212 }, @@ -89,7 +89,7 @@ main (int argc, const char *argv[]) }; const size_t szModulations = 5; - nfc_target_t nt; + nfc_target nt; bool res; pnd = nfc_connect (NULL); diff --git a/examples/nfc-relay.c b/examples/nfc-relay.c index 7ec4ec5..631a63a 100644 --- a/examples/nfc-relay.c +++ b/examples/nfc-relay.c @@ -56,8 +56,8 @@ static size_t szReaderRxBits; static byte_t abtTagRx[MAX_FRAME_LEN]; static byte_t abtTagRxPar[MAX_FRAME_LEN]; static size_t szTagRxBits; -static nfc_device_t *pndReader; -static nfc_device_t *pndTag; +static nfc_device *pndReader; +static nfc_device *pndTag; static bool quitting = false; void @@ -130,7 +130,7 @@ main (int argc, char *argv[]) printf ("[+] To do this, please send any command after the anti-collision\n"); printf ("[+] For example, send a RATS command or use the \"nfc-anticol\" tool\n"); - nfc_target_t nt = { + nfc_target nt = { .nm = { .nmt = NMT_ISO14443A, .nbr = NBR_UNDEFINED, diff --git a/examples/pn53x-diagnose.c b/examples/pn53x-diagnose.c index bc28be0..0bf53c6 100644 --- a/examples/pn53x-diagnose.c +++ b/examples/pn53x-diagnose.c @@ -54,7 +54,7 @@ main (int argc, const char *argv[]) { size_t szFound; size_t i; - nfc_device_t *pnd; + nfc_device *pnd; const char *acLibnfcVersion; bool result; diff --git a/examples/pn53x-sam.c b/examples/pn53x-sam.c index ee9d664..113cac0 100644 --- a/examples/pn53x-sam.c +++ b/examples/pn53x-sam.c @@ -72,7 +72,7 @@ wait_one_minute () int main (int argc, const char *argv[]) { - nfc_device_t *pnd; + nfc_device *pnd; (void) argc; (void) argv; @@ -125,7 +125,7 @@ main (int argc, const char *argv[]) case PSM_WIRED_CARD: { - nfc_target_t nt; + nfc_target nt; // Set connected NFC device to initiator mode nfc_initiator_init (pnd); @@ -136,7 +136,7 @@ main (int argc, const char *argv[]) exit (EXIT_FAILURE); } // Read the SAM's info - const nfc_modulation_t nmSAM = { + const nfc_modulation nmSAM = { .nmt = NMT_ISO14443A, .nbr = NBR_106, }; @@ -156,7 +156,7 @@ main (int argc, const char *argv[]) byte_t abtRx[MAX_FRAME_LEN]; size_t szRx = sizeof(abtRx); - nfc_target_t nt = { + nfc_target nt = { .nm = { .nmt = NMT_ISO14443A, .nbr = NBR_UNDEFINED, diff --git a/examples/pn53x-tamashell.c b/examples/pn53x-tamashell.c index 1d3fe94..1929697 100644 --- a/examples/pn53x-tamashell.c +++ b/examples/pn53x-tamashell.c @@ -71,7 +71,7 @@ int main(int argc, const char* argv[]) { - nfc_device_t* pnd; + nfc_device* pnd; byte_t abtRx[MAX_FRAME_LEN]; byte_t abtTx[MAX_FRAME_LEN]; size_t szRx = sizeof(abtRx); diff --git a/include/nfc/nfc-emulation.h b/include/nfc/nfc-emulation.h index ab92d6c..a4b087d 100644 --- a/include/nfc/nfc-emulation.h +++ b/include/nfc/nfc-emulation.h @@ -32,7 +32,7 @@ struct nfc_emulation_state_machine; struct nfc_emulator { - nfc_target_t *target; + nfc_target *target; struct nfc_emulation_state_machine *state_machine; void *user_data; }; @@ -42,7 +42,7 @@ struct nfc_emulation_state_machine { void *data; }; -NFC_EXPORT int nfc_emulate_target (nfc_device_t* 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 15b9367..1a3b7ad 100644 --- a/include/nfc/nfc-types.h +++ b/include/nfc/nfc-types.h @@ -38,7 +38,7 @@ typedef uint8_t byte_t; # define DEVICE_PORT_LENGTH 64 /** - * @struct nfc_device_t + * @struct nfc_device * @brief NFC device information */ typedef struct { @@ -69,7 +69,7 @@ typedef struct { * +----------- Driver-level general error (common to all drivers) */ int iLastError; -} nfc_device_t; +} nfc_device; typedef char nfc_connstring[1024]; @@ -77,7 +77,7 @@ typedef char nfc_connstring[1024]; # pragma pack(1) /** - * @enum nfc_device_option_t + * @enum nfc_device_option * @brief NFC device option */ typedef enum { @@ -137,20 +137,20 @@ typedef enum { NDO_FORCE_ISO14443_B = 0x43, /** Force the chip to run at 106 kbps */ NDO_FORCE_SPEED_106 = 0x50, -} nfc_device_option_t; +} nfc_device_option; /** - * @enum nfc_dep_mode_t + * @enum nfc_dep_mode * @brief NFC D.E.P. (Data Exchange Protocol) active/passive mode */ typedef enum { NDM_UNDEFINED = 0, NDM_PASSIVE, NDM_ACTIVE, -} nfc_dep_mode_t; +} nfc_dep_mode; /** - * @struct nfc_dep_info_t + * @struct nfc_dep_info * @brief NFC target information in D.E.P. (Data Exchange Protocol) see ISO/IEC 18092 (NFCIP-1) */ typedef struct { @@ -170,11 +170,11 @@ typedef struct { byte_t abtGB[48]; size_t szGB; /** DEP mode */ - nfc_dep_mode_t ndm; -} nfc_dep_info_t; + nfc_dep_mode ndm; +} nfc_dep_info; /** - * @struct nfc_iso14443a_info_t + * @struct nfc_iso14443a_info * @brief NFC ISO14443A tag (MIFARE) information */ typedef struct { @@ -184,10 +184,10 @@ typedef struct { byte_t abtUid[10]; size_t szAtsLen; byte_t abtAts[254]; // Maximal theoretical ATS is FSD-2, FSD=256 for FSDI=8 in RATS -} nfc_iso14443a_info_t; +} nfc_iso14443a_info; /** - * @struct nfc_felica_info_t + * @struct nfc_felica_info * @brief NFC FeLiCa tag information */ typedef struct { @@ -196,10 +196,10 @@ typedef struct { byte_t abtId[8]; byte_t abtPad[8]; byte_t abtSysCode[2]; -} nfc_felica_info_t; +} nfc_felica_info; /** - * @struct nfc_iso14443b_info_t + * @struct nfc_iso14443b_info * @brief NFC ISO14443B tag information */ typedef struct { @@ -211,10 +211,10 @@ typedef struct { byte_t abtProtocolInfo[3]; /** ui8CardIdentifier store CID (Card Identifier) attributted by PCD to the PICC */ uint8_t ui8CardIdentifier; -} nfc_iso14443b_info_t; +} nfc_iso14443b_info; /** - * @struct nfc_iso14443bi_info_t + * @struct nfc_iso14443bi_info * @brief NFC ISO14443B' tag information */ typedef struct { @@ -227,52 +227,52 @@ typedef struct { /** ATR, if any */ size_t szAtrLen; byte_t abtAtr[33]; -} nfc_iso14443bi_info_t; +} nfc_iso14443bi_info; /** - * @struct nfc_iso14443b2sr_info_t + * @struct nfc_iso14443b2sr_info * @brief NFC ISO14443-2B ST SRx tag information */ typedef struct { byte_t abtUID[8]; -} nfc_iso14443b2sr_info_t; +} nfc_iso14443b2sr_info; /** - * @struct nfc_iso14443b2ct_info_t + * @struct nfc_iso14443b2ct_info * @brief NFC ISO14443-2B ASK CTx tag information */ typedef struct { byte_t abtUID[4]; byte_t btProdCode; byte_t btFabCode; -} nfc_iso14443b2ct_info_t; +} nfc_iso14443b2ct_info; /** - * @struct nfc_jewel_info_t + * @struct nfc_jewel_info * @brief NFC Jewel tag information */ typedef struct { byte_t btSensRes[2]; byte_t btId[4]; -} nfc_jewel_info_t; +} nfc_jewel_info; /** - * @union nfc_target_info_t + * @union nfc_target_info * @brief Union between all kind of tags information structures. */ typedef union { - nfc_iso14443a_info_t nai; - nfc_felica_info_t nfi; - nfc_iso14443b_info_t nbi; - nfc_iso14443bi_info_t nii; - nfc_iso14443b2sr_info_t nsi; - nfc_iso14443b2ct_info_t nci; - nfc_jewel_info_t nji; - nfc_dep_info_t ndi; -} nfc_target_info_t; + nfc_iso14443a_info nai; + nfc_felica_info nfi; + nfc_iso14443b_info nbi; + nfc_iso14443bi_info nii; + nfc_iso14443b2sr_info nsi; + nfc_iso14443b2ct_info nci; + nfc_jewel_info nji; + nfc_dep_info ndi; +} nfc_target_info; /** - * @enum nfc_baud_rate_t + * @enum nfc_baud_rate * @brief NFC baud rate enumeration */ typedef enum { @@ -281,10 +281,10 @@ typedef enum { NBR_212, NBR_424, NBR_847, -} nfc_baud_rate_t; +} nfc_baud_rate; /** - * @enum nfc_modulation_type_t + * @enum nfc_modulationype * @brief NFC modulation type enumeration */ typedef enum { @@ -296,25 +296,25 @@ typedef enum { NMT_ISO14443B2CT, // ISO14443-2B ASK CTx NMT_FELICA, NMT_DEP, -} nfc_modulation_type_t; +} nfc_modulationype; /** - * @struct nfc_modulation_t + * @struct nfc_modulation * @brief NFC modulation structure */ typedef struct { - nfc_modulation_type_t nmt; - nfc_baud_rate_t nbr; -} nfc_modulation_t; + nfc_modulationype nmt; + nfc_baud_rate nbr; +} nfc_modulation; /** - * @struct nfc_target_t + * @struct nfc_target * @brief NFC target structure */ typedef struct { - nfc_target_info_t nti; - nfc_modulation_t nm; -} nfc_target_t; + nfc_target_info nti; + nfc_modulation nm; +} nfc_target; // Reset struct alignment to default # pragma pack() diff --git a/include/nfc/nfc.h b/include/nfc/nfc.h index 011e475..c90fa17 100644 --- a/include/nfc/nfc.h +++ b/include/nfc/nfc.h @@ -64,39 +64,39 @@ extern "C" { /* NFC Device/Hardware manipulation */ NFC_EXPORT bool nfc_get_default_device (nfc_connstring *connstring); - NFC_EXPORT nfc_device_t *nfc_connect (const nfc_connstring connstring); - NFC_EXPORT void nfc_disconnect (nfc_device_t * pnd); - NFC_EXPORT bool nfc_abort_command (nfc_device_t * pnd); + NFC_EXPORT nfc_device *nfc_connect (const nfc_connstring connstring); + NFC_EXPORT void nfc_disconnect (nfc_device * pnd); + NFC_EXPORT bool nfc_abort_command (nfc_device * pnd); NFC_EXPORT void nfc_list_devices (nfc_connstring connstrings[], size_t connstrings_len, size_t * pszDeviceFound); - NFC_EXPORT bool nfc_configure (nfc_device_t * pnd, const nfc_device_option_t ndo, const bool bEnable); - NFC_EXPORT bool nfc_idle (nfc_device_t * pnd); + NFC_EXPORT bool nfc_configure (nfc_device * pnd, const nfc_device_option ndo, const bool bEnable); + NFC_EXPORT bool nfc_idle (nfc_device * pnd); /* NFC initiator: act as "reader" */ - NFC_EXPORT bool nfc_initiator_init (nfc_device_t * pnd); - NFC_EXPORT bool nfc_initiator_select_passive_target (nfc_device_t * pnd, const nfc_modulation_t nm, const byte_t * pbtInitData, const size_t szInitData, nfc_target_t * pnt); - NFC_EXPORT bool nfc_initiator_list_passive_targets (nfc_device_t * pnd, const nfc_modulation_t nm, nfc_target_t ant[], const size_t szTargets, size_t * pszTargetFound); - NFC_EXPORT bool nfc_initiator_poll_target (nfc_device_t * pnd, const nfc_modulation_t * pnmTargetTypes, const size_t szTargetTypes, const uint8_t uiPollNr, const uint8_t uiPeriod, nfc_target_t * pnt); - NFC_EXPORT bool nfc_initiator_select_dep_target (nfc_device_t * pnd, const nfc_dep_mode_t ndm, const nfc_baud_rate_t nbr, const nfc_dep_info_t * pndiInitiator, nfc_target_t * pnt); - NFC_EXPORT bool nfc_initiator_deselect_target (nfc_device_t * pnd); - NFC_EXPORT bool nfc_initiator_transceive_bytes (nfc_device_t * pnd, const byte_t * pbtTx, const size_t szTx, byte_t * pbtRx, size_t * pszRx, struct timeval *timeout); - NFC_EXPORT bool nfc_initiator_transceive_bits (nfc_device_t * pnd, const byte_t * pbtTx, const size_t szTxBits, const byte_t * pbtTxPar, byte_t * pbtRx, size_t * pszRxBits, byte_t * pbtRxPar); - NFC_EXPORT bool nfc_initiator_transceive_bytes_timed (nfc_device_t * pnd, const byte_t * pbtTx, const size_t szTx, byte_t * pbtRx, size_t * pszRx, uint32_t * cycles); - NFC_EXPORT bool nfc_initiator_transceive_bits_timed (nfc_device_t * pnd, const byte_t * pbtTx, const size_t szTxBits, const byte_t * pbtTxPar, byte_t * pbtRx, size_t * pszRxBits, byte_t * pbtRxPar, uint32_t * cycles); + NFC_EXPORT bool nfc_initiator_init (nfc_device * pnd); + NFC_EXPORT bool nfc_initiator_select_passive_target (nfc_device * pnd, const nfc_modulation nm, const byte_t * pbtInitData, const size_t szInitData, nfc_target * pnt); + NFC_EXPORT bool nfc_initiator_list_passive_targets (nfc_device * pnd, const nfc_modulation nm, nfc_target ant[], const size_t szTargets, size_t * pszTargetFound); + NFC_EXPORT bool nfc_initiator_poll_target (nfc_device * pnd, const nfc_modulation * pnmTargetTypes, const size_t szTargetTypes, const uint8_t uiPollNr, const uint8_t uiPeriod, nfc_target * pnt); + NFC_EXPORT bool nfc_initiator_select_dep_target (nfc_device * pnd, const nfc_dep_mode ndm, const nfc_baud_rate nbr, const nfc_dep_info * pndiInitiator, nfc_target * pnt); + NFC_EXPORT bool nfc_initiator_deselect_target (nfc_device * pnd); + NFC_EXPORT bool nfc_initiator_transceive_bytes (nfc_device * pnd, const byte_t * pbtTx, const size_t szTx, byte_t * pbtRx, size_t * pszRx, struct timeval *timeout); + NFC_EXPORT bool nfc_initiator_transceive_bits (nfc_device * pnd, const byte_t * pbtTx, const size_t szTxBits, const byte_t * pbtTxPar, byte_t * pbtRx, size_t * pszRxBits, byte_t * pbtRxPar); + NFC_EXPORT bool nfc_initiator_transceive_bytes_timed (nfc_device * pnd, const byte_t * pbtTx, const size_t szTx, byte_t * pbtRx, size_t * pszRx, uint32_t * cycles); + NFC_EXPORT bool nfc_initiator_transceive_bits_timed (nfc_device * pnd, const byte_t * pbtTx, const size_t szTxBits, const byte_t * pbtTxPar, byte_t * pbtRx, size_t * pszRxBits, byte_t * pbtRxPar, uint32_t * cycles); /* NFC target: act as tag (i.e. MIFARE Classic) or NFC target device. */ - NFC_EXPORT bool nfc_target_init (nfc_device_t * pnd, nfc_target_t * pnt, byte_t * pbtRx, size_t * pszRx); - NFC_EXPORT bool nfc_target_send_bytes (nfc_device_t * pnd, const byte_t * pbtTx, const size_t szTx, struct timeval *timout); - NFC_EXPORT bool nfc_target_receive_bytes (nfc_device_t * pnd, byte_t * pbtRx, size_t * pszRx, struct timeval *timout); - NFC_EXPORT bool nfc_target_send_bits (nfc_device_t * pnd, const byte_t * pbtTx, const size_t szTxBits, const byte_t * pbtTxPar); - NFC_EXPORT bool nfc_target_receive_bits (nfc_device_t * pnd, byte_t * pbtRx, size_t * pszRxBits, byte_t * pbtRxPar); + NFC_EXPORT bool nfc_target_init (nfc_device * pnd, nfc_target * pnt, byte_t * pbtRx, size_t * pszRx); + NFC_EXPORT bool nfc_target_send_bytes (nfc_device * pnd, const byte_t * pbtTx, const size_t szTx, struct timeval *timout); + NFC_EXPORT bool nfc_target_receive_bytes (nfc_device * pnd, byte_t * pbtRx, size_t * pszRx, struct timeval *timout); + NFC_EXPORT bool nfc_target_send_bits (nfc_device * pnd, const byte_t * pbtTx, const size_t szTxBits, const byte_t * pbtTxPar); + NFC_EXPORT bool nfc_target_receive_bits (nfc_device * pnd, byte_t * pbtRx, size_t * pszRxBits, byte_t * pbtRxPar); /* Error reporting */ - NFC_EXPORT const char *nfc_strerror (const nfc_device_t * pnd); - NFC_EXPORT int nfc_strerror_r (const nfc_device_t * pnd, char *pcStrErrBuf, size_t szBufLen); - NFC_EXPORT void nfc_perror (const nfc_device_t * pnd, const char *pcString); + NFC_EXPORT const char *nfc_strerror (const nfc_device * pnd); + NFC_EXPORT int nfc_strerror_r (const nfc_device * pnd, char *pcStrErrBuf, size_t szBufLen); + NFC_EXPORT void nfc_perror (const nfc_device * pnd, const char *pcString); /* Special data accessors */ - NFC_EXPORT const char *nfc_device_name (nfc_device_t * pnd); + NFC_EXPORT const char *nfc_device_name (nfc_device * pnd); /* Misc. functions */ NFC_EXPORT void iso14443a_crc (byte_t * pbtData, size_t szLen, byte_t * pbtCrc); diff --git a/libnfc/buses/uart_posix.c b/libnfc/buses/uart_posix.c index 78cf67b..2fc3b47 100644 --- a/libnfc/buses/uart_posix.c +++ b/libnfc/buses/uart_posix.c @@ -61,18 +61,20 @@ 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 -typedef struct { +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 -} serial_port_unix; +}; + +// TODO: #define UART_FD( X ) (((struct serial_port_unix *) X)->fd) void uart_close_ext (const serial_port sp, const bool restore_termios); serial_port uart_open (const char *pcPortName) { - serial_port_unix *sp = malloc (sizeof (serial_port_unix)); + struct serial_port_unix *sp = malloc (sizeof (struct serial_port_unix)); if (sp == 0) return INVALID_SERIAL_PORT; @@ -114,12 +116,12 @@ void uart_flush_input (serial_port sp) { // This line seems to produce absolutely no effect on my system (GNU/Linux 2.6.35) - tcflush (((serial_port_unix *) sp)->fd, TCIFLUSH); + tcflush (((struct serial_port_unix *) sp)->fd, TCIFLUSH); // So, I wrote this byte-eater // Retrieve the count of the incoming bytes int available_bytes_count = 0; int res; - res = ioctl (((serial_port_unix *) sp)->fd, FIONREAD, &available_bytes_count); + res = ioctl (((struct serial_port_unix *) sp)->fd, FIONREAD, &available_bytes_count); if (res != 0) { return; } @@ -128,7 +130,7 @@ uart_flush_input (serial_port sp) } char* rx = malloc (available_bytes_count); // There is something available, read the data - res = read (((serial_port_unix *) sp)->fd, rx, available_bytes_count); + res = read (((struct serial_port_unix *) sp)->fd, rx, available_bytes_count); log_put (LOG_CATEGORY, NFC_PRIORITY_TRACE, "%d bytes have eatten.", available_bytes_count); free (rx); } @@ -137,7 +139,7 @@ void 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); - serial_port_unix *spu = (serial_port_unix *) sp; + struct serial_port_unix *spu = (struct serial_port_unix *) sp; // Portability note: on some systems, B9600 != 9600 so we have to do // uint32_t <=> speed_t associations by hand. @@ -190,7 +192,7 @@ uint32_t uart_get_speed (serial_port sp) { uint32_t uiPortSpeed = 0; - const serial_port_unix *spu = (serial_port_unix *) sp; + const struct serial_port_unix *spu = (struct serial_port_unix *) sp; switch (cfgetispeed (&spu->termios_new)) { case B9600: uiPortSpeed = 9600; @@ -229,10 +231,10 @@ uart_get_speed (serial_port sp) void uart_close_ext (const serial_port sp, const bool restore_termios) { - if (((serial_port_unix *) sp)->fd >= 0) { + if (((struct serial_port_unix *) sp)->fd >= 0) { if (restore_termios) - tcsetattr (((serial_port_unix *) sp)->fd, TCSANOW, &((serial_port_unix *) sp)->termios_backup); - close (((serial_port_unix *) sp)->fd); + tcsetattr (((struct serial_port_unix *) sp)->fd, TCSANOW, &((struct serial_port_unix *) sp)->termios_backup); + close (((struct serial_port_unix *) sp)->fd); } free (sp); } @@ -261,7 +263,7 @@ uart_receive (serial_port sp, byte_t * pbtRx, const size_t szRx, void * abort_p, select: // Reset file descriptor FD_ZERO (&rfds); - FD_SET (((serial_port_unix *) sp)->fd, &rfds); + FD_SET (((struct serial_port_unix *) sp)->fd, &rfds); if (iAbortFd) { FD_SET (iAbortFd, &rfds); @@ -277,7 +279,7 @@ select: timeout = &fixed_timeout; } - res = select (MAX(((serial_port_unix *) sp)->fd, iAbortFd) + 1, &rfds, NULL, NULL, timeout); + res = select (MAX(((struct serial_port_unix *) sp)->fd, iAbortFd) + 1, &rfds, NULL, NULL, timeout); if ((res < 0) && (EINTR == errno)) { // The system call was interupted by a signal and a signal handler was @@ -304,12 +306,12 @@ select: } // Retrieve the count of the incoming bytes - res = ioctl (((serial_port_unix *) sp)->fd, FIONREAD, &available_bytes_count); + res = ioctl (((struct serial_port_unix *) sp)->fd, FIONREAD, &available_bytes_count); if (res != 0) { return ECOMIO; } // There is something available, read the data - res = read (((serial_port_unix *) sp)->fd, pbtRx + received_bytes_count, MIN(available_bytes_count, (expected_bytes_count - received_bytes_count))); + res = read (((struct serial_port_unix *) sp)->fd, pbtRx + received_bytes_count, MIN(available_bytes_count, (expected_bytes_count - received_bytes_count))); // Stop if the OS has some troubles reading the data if (res <= 0) { return ECOMIO; @@ -331,7 +333,7 @@ uart_send (serial_port sp, const byte_t * pbtTx, const size_t szTx, struct timev { (void) timeout; LOG_HEX ("TX", pbtTx, szTx); - if ((int) szTx == write (((serial_port_unix *) sp)->fd, pbtTx, szTx)) + if ((int) szTx == write (((struct serial_port_unix *) sp)->fd, pbtTx, szTx)) return 0; else return ECOMIO; diff --git a/libnfc/buses/uart_win32.c b/libnfc/buses/uart_win32.c index 29977c6..339be57 100644 --- a/libnfc/buses/uart_win32.c +++ b/libnfc/buses/uart_win32.c @@ -31,17 +31,17 @@ #include "contrib/windows.h" #define delay_ms( X ) Sleep( X ) -typedef struct { +struct serial_port_windows { HANDLE hPort; // Serial port handle DCB dcb; // Device control settings COMMTIMEOUTS ct; // Serial port time-out configuration -} serial_port_windows; +}; serial_port uart_open (const char *pcPortName) { char acPortName[255]; - serial_port_windows *sp = malloc (sizeof (serial_port_windows)); + struct serial_port_windows *sp = malloc (sizeof (struct serial_port_windows)); // Copy the input "com?" to "\\.\COM?" format sprintf (acPortName, "\\\\.\\%s", pcPortName); @@ -85,8 +85,8 @@ uart_open (const char *pcPortName) void uart_close (const serial_port sp) { - if (((serial_port_windows *) sp)->hPort != INVALID_HANDLE_VALUE) { - CloseHandle (((serial_port_windows *) sp)->hPort); + if (((struct serial_port_windows *) sp)->hPort != INVALID_HANDLE_VALUE) { + CloseHandle (((struct serial_port_windows *) sp)->hPort); } free (sp); } @@ -94,13 +94,13 @@ uart_close (const serial_port sp) void uart_flush_input (const serial_port sp) { - PurgeComm(((serial_port_windows *) sp)->hPort, PURGE_RXABORT | PURGE_RXCLEAR); + PurgeComm(((struct serial_port_windows *) sp)->hPort, PURGE_RXABORT | PURGE_RXCLEAR); } void uart_set_speed (serial_port sp, const uint32_t uiPortSpeed) { - serial_port_windows *spw; + struct serial_port_windows *spw; log_put (LOG_CATEGORY, NFC_PRIORITY_TRACE, "Serial port speed requested to be set to %d bauds.", uiPortSpeed); // Set port speed (Input and Output) @@ -117,7 +117,7 @@ uart_set_speed (serial_port sp, const uint32_t uiPortSpeed) 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 = (serial_port_windows *) sp; + spw = (struct serial_port_windows *) sp; // Set baud rate spw->dcb.BaudRate = uiPortSpeed; @@ -131,7 +131,7 @@ uart_set_speed (serial_port sp, const uint32_t uiPortSpeed) uint32_t uart_get_speed (const serial_port sp) { - const serial_port_windows *spw = (serial_port_windows *) sp; + const struct serial_port_windows *spw = (struct serial_port_windows *) sp; if (!GetCommState (spw->hPort, (serial_port) & spw->dcb)) return spw->dcb.BaudRate; @@ -155,7 +155,7 @@ uart_receive (serial_port sp, byte_t * pbtRx, const size_t szRx, void * abort_p, timeouts.WriteTotalTimeoutMultiplier = 0; timeouts.WriteTotalTimeoutConstant = timeout_ms; - if (!SetCommTimeouts (((serial_port_windows *) sp)->hPort, &timeouts)) { + if (!SetCommTimeouts (((struct serial_port_windows *) sp)->hPort, &timeouts)) { log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "Unable to apply new timeout settings."); return ECOMIO; } @@ -166,7 +166,7 @@ uart_receive (serial_port sp, byte_t * pbtRx, const size_t szRx, void * abort_p, volatile bool * abort_flag_p = (volatile bool *)abort_p; do { log_put (LOG_CATEGORY, NFC_PRIORITY_TRACE, "ReadFile"); - res = ReadFile (((serial_port_windows *) sp)->hPort, pbtRx + dwTotalBytesReceived, + res = ReadFile (((struct serial_port_windows *) sp)->hPort, pbtRx + dwTotalBytesReceived, dwBytesToGet, &dwBytesReceived, NULL); @@ -205,13 +205,13 @@ uart_send (serial_port sp, const byte_t * pbtTx, const size_t szTx, struct timev timeouts.WriteTotalTimeoutMultiplier = 0; timeouts.WriteTotalTimeoutConstant = timeout ? ((timeout->tv_sec * 1000) + (timeout->tv_usec / 1000)) : 0; - if (!SetCommTimeouts (((serial_port_windows *) sp)->hPort, &timeouts)) { + if (!SetCommTimeouts (((struct serial_port_windows *) sp)->hPort, &timeouts)) { log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "Unable to apply new timeout settings."); return ECOMIO; } LOG_HEX ("TX", pbtTx, szTx); - if (!WriteFile (((serial_port_windows *) sp)->hPort, pbtTx, szTx, &dwTxLen, NULL)) { + if (!WriteFile (((struct serial_port_windows *) sp)->hPort, pbtTx, szTx, &dwTxLen, NULL)) { return ECOMIO; } if (!dwTxLen) diff --git a/libnfc/chips/pn53x.c b/libnfc/chips/pn53x.c index 246d839..7de9520 100644 --- a/libnfc/chips/pn53x.c +++ b/libnfc/chips/pn53x.c @@ -51,15 +51,15 @@ const byte_t pn53x_nack_frame[] = { 0x00, 0x00, 0xff, 0xff, 0x00, 0x00 }; static const byte_t pn53x_error_frame[] = { 0x00, 0x00, 0xff, 0x01, 0xff, 0x7f, 0x81, 0x00 }; /* prototypes */ -bool pn53x_reset_settings (nfc_device_t * pnd); -bool pn53x_writeback_register (nfc_device_t * pnd); +bool pn53x_reset_settings (nfc_device * pnd); +bool pn53x_writeback_register (nfc_device * pnd); -nfc_modulation_t pn53x_ptt_to_nm (const pn53x_target_type_t ptt); -pn53x_modulation_t pn53x_nm_to_pm (const nfc_modulation_t nm); -pn53x_target_type_t pn53x_nm_to_ptt (const nfc_modulation_t nm); +nfc_modulation pn53x_ptt_to_nm (const pn53x_target_type ptt); +pn53x_modulation pn53x_nm_to_pm (const nfc_modulation nm); +pn53x_target_type pn53x_nm_to_ptt (const nfc_modulation nm); bool -pn53x_init(nfc_device_t * pnd) +pn53x_init(nfc_device * pnd) { // GetFirmwareVersion command is used to set PN53x chips type (PN531, PN532 or PN533) char abtFirmwareText[22]; @@ -89,7 +89,7 @@ pn53x_init(nfc_device_t * pnd) } bool -pn53x_reset_settings(nfc_device_t * pnd) +pn53x_reset_settings(nfc_device * pnd) { // Reset the ending transmission bits register, it is unknown what the last tranmission used there CHIP_DATA (pnd)->ui8TxBits = 0; @@ -100,7 +100,7 @@ pn53x_reset_settings(nfc_device_t * pnd) } bool -pn53x_transceive (nfc_device_t * pnd, const byte_t * pbtTx, const size_t szTx, byte_t * pbtRx, size_t *pszRx, struct timeval *timeout) +pn53x_transceive (nfc_device * pnd, const byte_t * pbtTx, const size_t szTx, byte_t * pbtRx, size_t *pszRx, struct timeval *timeout) { if (CHIP_DATA (pnd)->wb_trigged) { if (!pn53x_writeback_register (pnd)) { @@ -190,7 +190,7 @@ pn53x_transceive (nfc_device_t * pnd, const byte_t * pbtTx, const size_t szTx, b } bool -pn53x_set_parameters (nfc_device_t * pnd, const uint8_t ui8Parameter, const bool bEnable) +pn53x_set_parameters (nfc_device * pnd, const uint8_t ui8Parameter, const bool bEnable) { uint8_t ui8Value = (bEnable) ? (CHIP_DATA (pnd)->ui8Parameters | ui8Parameter) : (CHIP_DATA (pnd)->ui8Parameters & ~(ui8Parameter)); if (ui8Value != CHIP_DATA (pnd)->ui8Parameters) { @@ -200,7 +200,7 @@ pn53x_set_parameters (nfc_device_t * pnd, const uint8_t ui8Parameter, const bool } bool -pn53x_set_tx_bits (nfc_device_t * pnd, const uint8_t ui8Bits) +pn53x_set_tx_bits (nfc_device * pnd, const uint8_t ui8Bits) { // Test if we need to update the transmission bits register setting if (CHIP_DATA (pnd)->ui8TxBits != ui8Bits) { @@ -318,8 +318,8 @@ pn53x_unwrap_frame (const byte_t * pbtFrame, const size_t szFrameBits, byte_t * } bool -pn53x_decode_target_data (const byte_t * pbtRawData, size_t szRawData, pn53x_type type, nfc_modulation_type_t nmt, - nfc_target_info_t * pnti) +pn53x_decode_target_data (const byte_t * pbtRawData, size_t szRawData, pn53x_type type, nfc_modulationype nmt, + nfc_target_info * pnti) { uint8_t szAttribRes; @@ -462,7 +462,7 @@ pn53x_decode_target_data (const byte_t * pbtRawData, size_t szRawData, pn53x_typ } bool -pn53x_ReadRegister (nfc_device_t * pnd, uint16_t ui16RegisterAddress, uint8_t * ui8Value) +pn53x_ReadRegister (nfc_device * pnd, uint16_t ui16RegisterAddress, uint8_t * ui8Value) { byte_t abtCmd[] = { ReadRegister, ui16RegisterAddress >> 8, ui16RegisterAddress & 0xff }; byte_t abtRegValue[2]; @@ -481,13 +481,13 @@ pn53x_ReadRegister (nfc_device_t * pnd, uint16_t ui16RegisterAddress, uint8_t * return true; } -bool pn53x_read_register (nfc_device_t * pnd, uint16_t ui16RegisterAddress, uint8_t * ui8Value) +bool pn53x_read_register (nfc_device * pnd, uint16_t ui16RegisterAddress, uint8_t * ui8Value) { return pn53x_ReadRegister (pnd, ui16RegisterAddress, ui8Value); } bool -pn53x_WriteRegister (nfc_device_t * pnd, const uint16_t ui16RegisterAddress, const uint8_t ui8Value) +pn53x_WriteRegister (nfc_device * pnd, const uint16_t ui16RegisterAddress, const uint8_t ui8Value) { byte_t abtCmd[] = { WriteRegister, ui16RegisterAddress >> 8, ui16RegisterAddress & 0xff, ui8Value }; PNREG_TRACE (ui16RegisterAddress); @@ -495,7 +495,7 @@ pn53x_WriteRegister (nfc_device_t * pnd, const uint16_t ui16RegisterAddress, con } bool -pn53x_write_register (nfc_device_t * pnd, const uint16_t ui16RegisterAddress, const uint8_t ui8SymbolMask, const uint8_t ui8Value) +pn53x_write_register (nfc_device * pnd, const uint16_t ui16RegisterAddress, const uint8_t ui8SymbolMask, const uint8_t ui8Value) { if ((ui16RegisterAddress < PN53X_CACHE_REGISTER_MIN_ADDRESS) || (ui16RegisterAddress > PN53X_CACHE_REGISTER_MAX_ADDRESS)) { // Direct write @@ -521,7 +521,7 @@ pn53x_write_register (nfc_device_t * pnd, const uint16_t ui16RegisterAddress, co } bool -pn53x_writeback_register (nfc_device_t * pnd) +pn53x_writeback_register (nfc_device * pnd) { // TODO Check at each step (ReadRegister, WriteRegister) if we didn't exceed max supported frame length BUFFER_INIT (abtReadRegisterCmd, PN53x_EXTENDED_FRAME__DATA_MAX_LEN); @@ -589,7 +589,7 @@ pn53x_writeback_register (nfc_device_t * pnd) } bool -pn53x_get_firmware_version (nfc_device_t * pnd, char abtFirmwareText[22]) +pn53x_get_firmware_version (nfc_device * pnd, char abtFirmwareText[22]) { const byte_t abtCmd[] = { GetFirmwareVersion }; byte_t abtFw[4]; @@ -640,7 +640,7 @@ pn53x_get_firmware_version (nfc_device_t * pnd, char abtFirmwareText[22]) } bool -pn53x_configure (nfc_device_t * pnd, const nfc_device_option_t ndo, const bool bEnable) +pn53x_configure (nfc_device * pnd, const nfc_device_option ndo, const bool bEnable) { byte_t btValue; switch (ndo) { @@ -777,7 +777,7 @@ pn53x_configure (nfc_device_t * pnd, const nfc_device_option_t ndo, const bool b } bool -pn53x_idle (nfc_device_t *pnd) +pn53x_idle (nfc_device *pnd) { switch (CHIP_DATA (pnd)->operating_mode) { case TARGET: @@ -825,7 +825,7 @@ pn53x_idle (nfc_device_t *pnd) } bool -pn53x_check_communication (nfc_device_t *pnd) +pn53x_check_communication (nfc_device *pnd) { const byte_t abtCmd[] = { Diagnose, 0x00, 'l', 'i', 'b', 'n', 'f', 'c' }; const byte_t abtExpectedRx[] = { 0x00, 'l', 'i', 'b', 'n', 'f', 'c' }; @@ -843,7 +843,7 @@ pn53x_check_communication (nfc_device_t *pnd) } bool -pn53x_initiator_init (nfc_device_t * pnd) +pn53x_initiator_init (nfc_device * pnd) { pn53x_reset_settings(pnd); @@ -856,10 +856,10 @@ pn53x_initiator_init (nfc_device_t * pnd) } bool -pn53x_initiator_select_passive_target_ext (nfc_device_t * pnd, - const nfc_modulation_t nm, +pn53x_initiator_select_passive_target_ext (nfc_device * pnd, + const nfc_modulation nm, const byte_t * pbtInitData, const size_t szInitData, - nfc_target_t * pnt, + nfc_target * pnt, struct timeval* timeout) { byte_t abtTargetsData[PN53x_EXTENDED_FRAME__DATA_MAX_LEN]; @@ -941,7 +941,7 @@ pn53x_initiator_select_passive_target_ext (nfc_device_t * pnd, return true; } // else: - const pn53x_modulation_t pm = pn53x_nm_to_pm(nm); + const pn53x_modulation pm = pn53x_nm_to_pm(nm); if (PM_UNDEFINED == pm) { pnd->iLastError = EINVALARG; return false; @@ -966,25 +966,25 @@ pn53x_initiator_select_passive_target_ext (nfc_device_t * pnd, } bool -pn53x_initiator_select_passive_target (nfc_device_t * pnd, - const nfc_modulation_t nm, +pn53x_initiator_select_passive_target (nfc_device * pnd, + const nfc_modulation nm, const byte_t * pbtInitData, const size_t szInitData, - nfc_target_t * pnt) + nfc_target * pnt) { return pn53x_initiator_select_passive_target_ext (pnd, nm, pbtInitData, szInitData, pnt, NULL); } bool -pn53x_initiator_poll_target (nfc_device_t * pnd, - const nfc_modulation_t * pnmModulations, const size_t szModulations, +pn53x_initiator_poll_target (nfc_device * pnd, + const nfc_modulation * pnmModulations, const size_t szModulations, const uint8_t uiPollNr, const uint8_t uiPeriod, - nfc_target_t * pnt) + nfc_target * pnt) { if (CHIP_DATA(pnd)->type == PN532) { size_t szTargetTypes = 0; - pn53x_target_type_t apttTargetTypes[32]; + pn53x_target_type apttTargetTypes[32]; for (size_t n=0; niLastError = EINVALARG; return false; @@ -998,7 +998,7 @@ pn53x_initiator_poll_target (nfc_device_t * pnd, szTargetTypes++; } size_t szTargetFound = 0; - nfc_target_t ntTargets[2]; + nfc_target ntTargets[2]; if (!pn53x_InAutoPoll (pnd, apttTargetTypes, szTargetTypes, uiPollNr, uiPeriod, ntTargets, &szTargetFound)) return false; switch (szTargetFound) { @@ -1042,10 +1042,10 @@ pn53x_initiator_poll_target (nfc_device_t * pnd, } bool -pn53x_initiator_select_dep_target(nfc_device_t * pnd, - const nfc_dep_mode_t ndm, const nfc_baud_rate_t nbr, - const nfc_dep_info_t * pndiInitiator, - nfc_target_t * pnt) +pn53x_initiator_select_dep_target(nfc_device * pnd, + const nfc_dep_mode ndm, const nfc_baud_rate nbr, + const nfc_dep_info * pndiInitiator, + nfc_target * pnt) { const byte_t abtPassiveInitiatorData[] = { 0x00, 0xff, 0xff, 0x00, 0x00 }; // 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 byte_t * pbtPassiveInitiatorData = NULL; @@ -1070,7 +1070,7 @@ pn53x_initiator_select_dep_target(nfc_device_t * pnd, } bool -pn53x_initiator_transceive_bits (nfc_device_t * pnd, const byte_t * pbtTx, const size_t szTxBits, +pn53x_initiator_transceive_bits (nfc_device * pnd, const byte_t * pbtTx, const size_t szTxBits, const byte_t * pbtTxPar, byte_t * pbtRx, size_t * pszRxBits, byte_t * pbtRxPar) { size_t szFrameBits = 0; @@ -1134,7 +1134,7 @@ pn53x_initiator_transceive_bits (nfc_device_t * pnd, const byte_t * pbtTx, const } bool -pn53x_initiator_transceive_bytes (nfc_device_t * pnd, const byte_t * pbtTx, const size_t szTx, byte_t * pbtRx, +pn53x_initiator_transceive_bytes (nfc_device * pnd, const byte_t * pbtTx, const size_t szTx, byte_t * pbtRx, size_t * pszRx, struct timeval *timeout) { size_t szExtraTxLen; @@ -1180,7 +1180,7 @@ pn53x_initiator_transceive_bytes (nfc_device_t * pnd, const byte_t * pbtTx, cons return true; } -void __pn53x_init_timer(nfc_device_t * pnd, const uint32_t max_cycles) +void __pn53x_init_timer(nfc_device * pnd, const uint32_t max_cycles) { // The prescaler will dictate what will be the precision and // the largest delay to measure before saturation. Some examples: @@ -1201,7 +1201,7 @@ void __pn53x_init_timer(nfc_device_t * pnd, const uint32_t max_cycles) pn53x_write_register (pnd, PN53X_REG_CIU_TReloadVal_lo, 0xFF, reloadval & 0xFF); } -uint32_t __pn53x_get_timer(nfc_device_t * pnd, const uint8_t last_cmd_byte) +uint32_t __pn53x_get_timer(nfc_device * pnd, const uint8_t last_cmd_byte) { uint8_t parity; uint8_t counter_hi, counter_lo; @@ -1262,7 +1262,7 @@ uint32_t __pn53x_get_timer(nfc_device_t * pnd, const uint8_t last_cmd_byte) } bool -pn53x_initiator_transceive_bits_timed (nfc_device_t * pnd, const byte_t * pbtTx, const size_t szTxBits, +pn53x_initiator_transceive_bits_timed (nfc_device * pnd, const byte_t * pbtTx, const size_t szTxBits, const byte_t * pbtTxPar, byte_t * pbtRx, size_t * pszRxBits, byte_t * pbtRxPar, uint32_t * cycles) { // TODO Do something with these bytes... @@ -1364,7 +1364,7 @@ pn53x_initiator_transceive_bits_timed (nfc_device_t * pnd, const byte_t * pbtTx, } bool -pn53x_initiator_transceive_bytes_timed (nfc_device_t * pnd, const byte_t * pbtTx, const size_t szTx, byte_t * pbtRx, +pn53x_initiator_transceive_bytes_timed (nfc_device * pnd, const byte_t * pbtTx, const size_t szTx, byte_t * pbtRx, size_t * pszRx, uint32_t * cycles) { uint16_t i; @@ -1467,7 +1467,7 @@ pn53x_initiator_transceive_bytes_timed (nfc_device_t * pnd, const byte_t * pbtTx } bool -pn53x_initiator_deselect_target (nfc_device_t * pnd) +pn53x_initiator_deselect_target (nfc_device * pnd) { return (pn53x_InDeselect (pnd, 0)); // 0 mean deselect all selected targets } @@ -1475,13 +1475,13 @@ pn53x_initiator_deselect_target (nfc_device_t * pnd) #define SAK_ISO14443_4_COMPLIANT 0x20 #define SAK_ISO18092_COMPLIANT 0x40 bool -pn53x_target_init (nfc_device_t * pnd, nfc_target_t * pnt, byte_t * pbtRx, size_t * pszRx) +pn53x_target_init (nfc_device * pnd, nfc_target * pnt, byte_t * pbtRx, size_t * pszRx) { pn53x_reset_settings(pnd); CHIP_DATA (pnd)->operating_mode = TARGET; - pn53x_target_mode_t ptm = PTM_NORMAL; + pn53x_target_mode ptm = PTM_NORMAL; switch (pnt->nm.nmt) { case NMT_ISO14443A: @@ -1631,11 +1631,11 @@ pn53x_target_init (nfc_device_t * pnd, nfc_target_t * pnt, byte_t * pbtRx, size_ return false; } - nfc_modulation_t nm = { + nfc_modulation nm = { .nmt = NMT_DEP, // Silent compilation warnings .nbr = NBR_UNDEFINED }; - nfc_dep_mode_t ndm = NDM_UNDEFINED; + nfc_dep_mode ndm = NDM_UNDEFINED; // Decode activated "mode" switch(btActivatedMode & 0x70) { // Baud rate case 0x00: // 106kbps @@ -1681,8 +1681,8 @@ pn53x_target_init (nfc_device_t * pnd, nfc_target_t * pnt, byte_t * pbtRx, size_ if (CHIP_DATA (pnd)->current_target) { free (CHIP_DATA (pnd)->current_target); } - CHIP_DATA (pnd)->current_target = malloc (sizeof(nfc_target_t)); - memcpy (CHIP_DATA (pnd)->current_target, pnt, sizeof(nfc_target_t)); + CHIP_DATA (pnd)->current_target = malloc (sizeof(nfc_target)); + 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 @@ -1696,7 +1696,7 @@ pn53x_target_init (nfc_device_t * pnd, nfc_target_t * pnt, byte_t * pbtRx, size_ } bool -pn53x_target_receive_bits (nfc_device_t * pnd, byte_t * pbtRx, size_t * pszRxBits, byte_t * pbtRxPar) +pn53x_target_receive_bits (nfc_device * pnd, byte_t * pbtRx, size_t * pszRxBits, byte_t * pbtRxPar) { byte_t abtCmd[] = { TgGetInitiatorCommand }; @@ -1731,7 +1731,7 @@ pn53x_target_receive_bits (nfc_device_t * pnd, byte_t * pbtRx, size_t * pszRxBit } bool -pn53x_target_receive_bytes (nfc_device_t * pnd, byte_t * pbtRx, size_t * pszRx, struct timeval *timeout) +pn53x_target_receive_bytes (nfc_device * pnd, byte_t * pbtRx, size_t * pszRx, struct timeval *timeout) { byte_t abtCmd[1]; @@ -1780,7 +1780,7 @@ pn53x_target_receive_bytes (nfc_device_t * pnd, byte_t * pbtRx, size_t * pszRx, } bool -pn53x_target_send_bits (nfc_device_t * pnd, const byte_t * pbtTx, const size_t szTxBits, const byte_t * pbtTxPar) +pn53x_target_send_bits (nfc_device * pnd, const byte_t * pbtTx, const size_t szTxBits, const byte_t * pbtTxPar) { size_t szFrameBits = 0; size_t szFrameBytes = 0; @@ -1818,7 +1818,7 @@ pn53x_target_send_bits (nfc_device_t * pnd, const byte_t * pbtTx, const size_t s } bool -pn53x_target_send_bytes (nfc_device_t * pnd, const byte_t * pbtTx, const size_t szTx, struct timeval *timeout) +pn53x_target_send_bytes (nfc_device * pnd, const byte_t * pbtTx, const size_t szTx, struct timeval *timeout) { byte_t abtCmd[PN53x_EXTENDED_FRAME__DATA_MAX_LEN]; @@ -1917,7 +1917,7 @@ static struct sErrorMessage { }; const char * -pn53x_strerror (const nfc_device_t * pnd) +pn53x_strerror (const nfc_device * pnd) { const char *pcRes = "Unknown error"; size_t i; @@ -1933,14 +1933,14 @@ pn53x_strerror (const nfc_device_t * pnd) } bool -pn53x_RFConfiguration__RF_field (nfc_device_t * pnd, bool bEnable) +pn53x_RFConfiguration__RF_field (nfc_device * pnd, bool bEnable) { byte_t abtCmd[] = { RFConfiguration, RFCI_FIELD, (bEnable) ? 0x01 : 0x00 }; return pn53x_transceive (pnd, abtCmd, sizeof (abtCmd), NULL, NULL, NULL); } bool -pn53x_RFConfiguration__Various_timings (nfc_device_t * pnd, const uint8_t fATR_RES_Timeout, const uint8_t fRetryTimeout) +pn53x_RFConfiguration__Various_timings (nfc_device * pnd, const uint8_t fATR_RES_Timeout, const uint8_t fRetryTimeout) { byte_t abtCmd[] = { RFConfiguration, @@ -1953,7 +1953,7 @@ pn53x_RFConfiguration__Various_timings (nfc_device_t * pnd, const uint8_t fATR_R } bool -pn53x_RFConfiguration__MaxRtyCOM (nfc_device_t * pnd, const uint8_t MaxRtyCOM) +pn53x_RFConfiguration__MaxRtyCOM (nfc_device * pnd, const uint8_t MaxRtyCOM) { byte_t abtCmd[] = { RFConfiguration, @@ -1964,7 +1964,7 @@ pn53x_RFConfiguration__MaxRtyCOM (nfc_device_t * pnd, const uint8_t MaxRtyCOM) } bool -pn53x_RFConfiguration__MaxRetries (nfc_device_t * pnd, const uint8_t MxRtyATR, const uint8_t MxRtyPSL, const uint8_t MxRtyPassiveActivation) +pn53x_RFConfiguration__MaxRetries (nfc_device * pnd, const uint8_t MxRtyATR, const uint8_t MxRtyPSL, const uint8_t MxRtyPassiveActivation) { // Retry format: 0x00 means only 1 try, 0xff means infinite byte_t abtCmd[] = { @@ -1978,7 +1978,7 @@ pn53x_RFConfiguration__MaxRetries (nfc_device_t * pnd, const uint8_t MxRtyATR, c } bool -pn53x_SetParameters (nfc_device_t * pnd, const uint8_t ui8Value) +pn53x_SetParameters (nfc_device * pnd, const uint8_t ui8Value) { byte_t abtCmd[] = { SetParameters, ui8Value }; @@ -1991,7 +1991,7 @@ pn53x_SetParameters (nfc_device_t * pnd, const uint8_t ui8Value) } bool -pn53x_SAMConfiguration (nfc_device_t * pnd, const pn532_sam_mode ui8Mode, struct timeval *timeout) +pn53x_SAMConfiguration (nfc_device * pnd, const pn532_sam_mode ui8Mode, struct timeval *timeout) { byte_t abtCmd[] = { SAMConfiguration, ui8Mode, 0x00, 0x00 }; size_t szCmd = sizeof(abtCmd); @@ -2020,7 +2020,7 @@ pn53x_SAMConfiguration (nfc_device_t * pnd, const pn532_sam_mode ui8Mode, struct } bool -pn53x_PowerDown (nfc_device_t * pnd) +pn53x_PowerDown (nfc_device * pnd) { byte_t abtCmd[] = { PowerDown, 0xf0 }; return (pn53x_transceive (pnd, abtCmd, sizeof (abtCmd), NULL, NULL, NULL)); @@ -2030,7 +2030,7 @@ pn53x_PowerDown (nfc_device_t * pnd) * @brief C wrapper to InListPassiveTarget command * @return true if command is successfully sent * - * @param pnd nfc_device_t struct pointer that represent currently used device + * @param pnd nfc_device struct pointer that represent currently used device * @param pmInitModulation Desired modulation * @param pbtInitiatorData Optional initiator data used for Felica, ISO14443B, Topaz Polling or for ISO14443A selecting a specific UID * @param szInitiatorData Length of initiator data \a pbtInitiatorData @@ -2041,8 +2041,8 @@ pn53x_PowerDown (nfc_device_t * pnd) * @note To decode theses TargetData[n], there is @fn pn53x_decode_target_data */ bool -pn53x_InListPassiveTarget (nfc_device_t * pnd, - const pn53x_modulation_t pmInitModulation, const byte_t szMaxTargets, +pn53x_InListPassiveTarget (nfc_device * pnd, + const pn53x_modulation pmInitModulation, const byte_t szMaxTargets, const byte_t * pbtInitiatorData, const size_t szInitiatorData, byte_t * pbtTargetsData, size_t * pszTargetsData, struct timeval* timeout) @@ -2094,7 +2094,7 @@ pn53x_InListPassiveTarget (nfc_device_t * pnd, } bool -pn53x_InDeselect (nfc_device_t * pnd, const uint8_t ui8Target) +pn53x_InDeselect (nfc_device * pnd, const uint8_t ui8Target) { if (CHIP_DATA(pnd)->type == RCS360) { // We should do act here *only* if a target was previously selected @@ -2116,7 +2116,7 @@ pn53x_InDeselect (nfc_device_t * pnd, const uint8_t ui8Target) } bool -pn53x_InRelease (nfc_device_t * pnd, const uint8_t ui8Target) +pn53x_InRelease (nfc_device * pnd, const uint8_t ui8Target) { if (CHIP_DATA(pnd)->type == RCS360) { // We should do act here *only* if a target was previously selected @@ -2138,9 +2138,9 @@ pn53x_InRelease (nfc_device_t * pnd, const uint8_t ui8Target) } bool -pn53x_InAutoPoll (nfc_device_t * pnd, - const pn53x_target_type_t * ppttTargetTypes, const size_t szTargetTypes, - const byte_t btPollNr, const byte_t btPeriod, nfc_target_t * pntTargets, size_t * pszTargetFound) +pn53x_InAutoPoll (nfc_device * pnd, + const pn53x_target_type * ppttTargetTypes, const size_t szTargetTypes, + const byte_t btPollNr, const byte_t btPeriod, nfc_target * pntTargets, size_t * pszTargetFound) { if (CHIP_DATA(pnd)->type != PN532) { // This function is not supported by pn531 neither pn533 @@ -2168,7 +2168,7 @@ pn53x_InAutoPoll (nfc_device_t * pnd, byte_t *pbt = abtRx + 1; /* 1st target */ // Target type - pn53x_target_type_t ptt = *(pbt++); + pn53x_target_type ptt = *(pbt++); pntTargets[0].nm = pn53x_ptt_to_nm(ptt); // AutoPollTargetData length ln = *(pbt++); @@ -2197,16 +2197,16 @@ pn53x_InAutoPoll (nfc_device_t * pnd, * @param pbtNFCID3i NFCID3 of the initiator * @param pbtGBi General Bytes of the initiator * @param szGBi count of General Bytes - * @param[out] pnt \a nfc_target_t which will be filled by this function + * @param[out] pnt \a nfc_target which will be filled by this function */ bool -pn53x_InJumpForDEP (nfc_device_t * pnd, - const nfc_dep_mode_t ndm, - const nfc_baud_rate_t nbr, +pn53x_InJumpForDEP (nfc_device * pnd, + const nfc_dep_mode ndm, + const nfc_baud_rate nbr, const byte_t * pbtPassiveInitiatorData, const byte_t * pbtNFCID3i, const byte_t * pbtGBi, const size_t szGBi, - nfc_target_t * pnt) + nfc_target * pnt) { // Max frame size = 1 (Command) + 1 (ActPass) + 1 (Baud rate) + 1 (Next) + 5 (PassiveInitiatorData) + 10 (NFCID3) + 48 (General bytes) = 67 bytes byte_t abtCmd[67] = { InJumpForDEP, (ndm == NDM_ACTIVE) ? 0x01 : 0x00 }; @@ -2294,7 +2294,7 @@ pn53x_InJumpForDEP (nfc_device_t * pnd, } bool -pn53x_TgInitAsTarget (nfc_device_t * pnd, pn53x_target_mode_t ptm, +pn53x_TgInitAsTarget (nfc_device * pnd, pn53x_target_mode ptm, const byte_t * pbtMifareParams, const byte_t * pbtTkt, size_t szTkt, const byte_t * pbtFeliCaParams, @@ -2365,7 +2365,7 @@ pn53x_TgInitAsTarget (nfc_device_t * pnd, pn53x_target_mode_t ptm, } bool -pn53x_check_ack_frame (nfc_device_t * pnd, const byte_t * pbtRxFrame, const size_t szRxFrameLen) +pn53x_check_ack_frame (nfc_device * pnd, const byte_t * pbtRxFrame, const size_t szRxFrameLen) { if (szRxFrameLen >= sizeof (pn53x_ack_frame)) { if (0 == memcmp (pbtRxFrame, pn53x_ack_frame, sizeof (pn53x_ack_frame))) { @@ -2379,7 +2379,7 @@ pn53x_check_ack_frame (nfc_device_t * pnd, const byte_t * pbtRxFrame, const size } bool -pn53x_check_error_frame (nfc_device_t * pnd, const byte_t * pbtRxFrame, const size_t szRxFrameLen) +pn53x_check_error_frame (nfc_device * pnd, const byte_t * pbtRxFrame, const size_t szRxFrameLen) { if (szRxFrameLen >= sizeof (pn53x_error_frame)) { if (0 == memcmp (pbtRxFrame, pn53x_error_frame, sizeof (pn53x_error_frame))) { @@ -2453,8 +2453,8 @@ pn53x_build_frame (byte_t * pbtFrame, size_t * pszFrame, const byte_t * pbtData, } return true; } -pn53x_modulation_t -pn53x_nm_to_pm(const nfc_modulation_t nm) +pn53x_modulation +pn53x_nm_to_pm(const nfc_modulation nm) { switch(nm.nmt) { case NMT_ISO14443A: @@ -2511,8 +2511,8 @@ pn53x_nm_to_pm(const nfc_modulation_t nm) return PM_UNDEFINED; } -nfc_modulation_t -pn53x_ptt_to_nm( const pn53x_target_type_t ptt ) +nfc_modulation +pn53x_ptt_to_nm( const pn53x_target_type ptt ) { switch (ptt) { case PTT_GENERIC_PASSIVE_106: @@ -2524,44 +2524,44 @@ pn53x_ptt_to_nm( const pn53x_target_type_t ptt ) case PTT_MIFARE: case PTT_ISO14443_4A_106: - return (const nfc_modulation_t){ .nmt = NMT_ISO14443A, .nbr = NBR_106 }; + 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_t){ .nmt = NMT_ISO14443B, .nbr = NBR_106 }; + return (const nfc_modulation){ .nmt = NMT_ISO14443B, .nbr = NBR_106 }; break; case PTT_JEWEL_106: - return (const nfc_modulation_t){ .nmt = NMT_JEWEL, .nbr = NBR_106 }; + return (const nfc_modulation){ .nmt = NMT_JEWEL, .nbr = NBR_106 }; break; case PTT_FELICA_212: - return (const nfc_modulation_t){ .nmt = NMT_FELICA, .nbr = NBR_212 }; + return (const nfc_modulation){ .nmt = NMT_FELICA, .nbr = NBR_212 }; break; case PTT_FELICA_424: - return (const nfc_modulation_t){ .nmt = NMT_FELICA, .nbr = NBR_424 }; + 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_t){ .nmt = NMT_DEP, .nbr = NBR_106 }; + 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_t){ .nmt = NMT_DEP, .nbr = NBR_212 }; + 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_t){ .nmt = NMT_DEP, .nbr = NBR_424 }; + 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_t){ .nmt = NMT_ISO14443A, .nbr = NBR_106 }; + return (const nfc_modulation){ .nmt = NMT_ISO14443A, .nbr = NBR_106 }; } -pn53x_target_type_t -pn53x_nm_to_ptt(const nfc_modulation_t nm) +pn53x_target_type +pn53x_nm_to_ptt(const nfc_modulation nm) { switch(nm.nmt) { case NMT_ISO14443A: @@ -2614,7 +2614,7 @@ pn53x_nm_to_ptt(const nfc_modulation_t nm) } void -pn53x_data_new (nfc_device_t * pnd, const struct pn53x_io* io) +pn53x_data_new (nfc_device * pnd, const struct pn53x_io* io) { pnd->chip_data = malloc(sizeof(struct pn53x_data)); @@ -2640,7 +2640,7 @@ pn53x_data_new (nfc_device_t * pnd, const struct pn53x_io* io) } void -pn53x_data_free (nfc_device_t * pnd) +pn53x_data_free (nfc_device * pnd) { if (CHIP_DATA (pnd)->current_target) { free (CHIP_DATA (pnd)->current_target); diff --git a/libnfc/chips/pn53x.h b/libnfc/chips/pn53x.h index 9f32b6f..4e1a53b 100644 --- a/libnfc/chips/pn53x.h +++ b/libnfc/chips/pn53x.h @@ -127,8 +127,8 @@ typedef enum { } pn53x_operating_mode; struct pn53x_io { - bool (*send)(nfc_device_t * pnd, const byte_t * pbtData, const size_t szData, struct timeval *timeout); - int (*receive)(nfc_device_t * pnd, byte_t * pbtData, const size_t szDataLen, struct timeval *timeout); + bool (*send)(nfc_device * pnd, const byte_t * pbtData, const size_t szData, struct timeval *timeout); + int (*receive)(nfc_device * pnd, byte_t * pbtData, const size_t szDataLen, struct timeval *timeout); }; /* defines */ @@ -143,7 +143,7 @@ struct pn53x_data { /** Current operating mode */ pn53x_operating_mode operating_mode; /** Current emulated target */ - nfc_target_t* current_target; + nfc_target* current_target; /** PN53x I/O functions stored in struct */ const struct pn53x_io * io; /** 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 */ @@ -165,7 +165,7 @@ struct pn53x_data { #define CHIP_DATA(pnd) ((struct pn53x_data*)(pnd->chip_data)) /** - * @enum pn53x_modulation_t + * @enum pn53x_modulation * @brief NFC modulation */ typedef enum { @@ -187,10 +187,10 @@ typedef enum { PM_ISO14443B_424 = 0x07, /** ISO14443-B http://en.wikipedia.org/wiki/ISO/IEC_14443 (Not supported by PN531 nor PN532) */ PM_ISO14443B_847 = 0x08, -} pn53x_modulation_t; +} pn53x_modulation; /** - * @enum pn53x_target_type_t + * @enum pn53x_target_type * @brief NFC target type enumeration */ typedef enum { @@ -228,7 +228,7 @@ typedef enum { PTT_DEP_ACTIVE_212 = 0x81, /** DEP active 424 kbps */ PTT_DEP_ACTIVE_424 = 0x82, -} pn53x_target_type_t; +} pn53x_target_type; typedef enum { PSM_NORMAL = 0x01, @@ -238,7 +238,7 @@ typedef enum { } pn532_sam_mode; /** - * @enum pn53x_target_mode_t + * @enum pn53x_target_mode * @brief PN53x target mode enumeration */ typedef enum { @@ -250,86 +250,86 @@ typedef enum { PTM_DEP_ONLY = 0x02, /** Configure the PN532 to accept to be initialized only as ISO/IEC14443-4 PICC */ PTM_ISO14443_4_PICC_ONLY = 0x04 -} pn53x_target_mode_t; +} pn53x_target_mode; extern const byte_t pn53x_ack_frame[6]; extern const byte_t pn53x_nack_frame[6]; -bool pn53x_init(nfc_device_t * pnd); -bool pn53x_transceive (nfc_device_t * pnd, const byte_t * pbtTx, const size_t szTx, byte_t * pbtRx, size_t *pszRx, struct timeval *timeout); +bool pn53x_init(nfc_device * pnd); +bool pn53x_transceive (nfc_device * pnd, const byte_t * pbtTx, const size_t szTx, byte_t * pbtRx, size_t *pszRx, struct timeval *timeout); -bool pn53x_set_parameters (nfc_device_t * pnd, const uint8_t ui8Value, const bool bEnable); -bool pn53x_set_tx_bits (nfc_device_t * pnd, const uint8_t ui8Bits); +bool pn53x_set_parameters (nfc_device * pnd, const uint8_t ui8Value, const bool bEnable); +bool pn53x_set_tx_bits (nfc_device * pnd, const uint8_t ui8Bits); bool pn53x_wrap_frame (const byte_t * pbtTx, const size_t szTxBits, const byte_t * pbtTxPar, byte_t * pbtFrame, size_t * pszFrameBits); bool pn53x_unwrap_frame (const byte_t * pbtFrame, const size_t szFrameBits, byte_t * pbtRx, size_t * pszRxBits, byte_t * pbtRxPar); bool pn53x_decode_target_data (const byte_t * pbtRawData, size_t szRawData, - pn53x_type chip_type, nfc_modulation_type_t nmt, - nfc_target_info_t * pnti); -bool pn53x_read_register (nfc_device_t * pnd, uint16_t ui16Reg, uint8_t * ui8Value); -bool pn53x_write_register (nfc_device_t * pnd, uint16_t ui16Reg, uint8_t ui8SymbolMask, uint8_t ui8Value); -bool pn53x_get_firmware_version (nfc_device_t * pnd, char abtFirmwareText[22]); -bool pn53x_configure (nfc_device_t * pnd, const nfc_device_option_t ndo, const bool bEnable); -bool pn53x_check_communication (nfc_device_t *pnd); -bool pn53x_idle (nfc_device_t * pnd); + pn53x_type chip_type, nfc_modulationype nmt, + nfc_target_info * pnti); +bool pn53x_read_register (nfc_device * pnd, uint16_t ui16Reg, uint8_t * ui8Value); +bool pn53x_write_register (nfc_device * pnd, uint16_t ui16Reg, uint8_t ui8SymbolMask, uint8_t ui8Value); +bool pn53x_get_firmware_version (nfc_device * pnd, char abtFirmwareText[22]); +bool pn53x_configure (nfc_device * pnd, const nfc_device_option ndo, const bool bEnable); +bool pn53x_check_communication (nfc_device *pnd); +bool pn53x_idle (nfc_device * pnd); // NFC device as Initiator functions -bool pn53x_initiator_init (nfc_device_t * pnd); -bool pn53x_initiator_select_passive_target (nfc_device_t * pnd, - const nfc_modulation_t nm, +bool pn53x_initiator_init (nfc_device * pnd); +bool pn53x_initiator_select_passive_target (nfc_device * pnd, + const nfc_modulation nm, const byte_t * pbtInitData, const size_t szInitData, - nfc_target_t * pnt); -bool pn53x_initiator_poll_target (nfc_device_t * pnd, - const nfc_modulation_t * pnmModulations, const size_t szModulations, + nfc_target * pnt); +bool pn53x_initiator_poll_target (nfc_device * pnd, + const nfc_modulation * pnmModulations, const size_t szModulations, const uint8_t uiPollNr, const uint8_t uiPeriod, - nfc_target_t * pnt); -bool pn53x_initiator_select_dep_target (nfc_device_t * pnd, - const nfc_dep_mode_t ndm, const nfc_baud_rate_t nbr, - const nfc_dep_info_t * pndiInitiator, - nfc_target_t * pnt); -bool pn53x_initiator_transceive_bits (nfc_device_t * pnd, const byte_t * pbtTx, const size_t szTxBits, + nfc_target * pnt); +bool pn53x_initiator_select_dep_target (nfc_device * pnd, + const nfc_dep_mode ndm, const nfc_baud_rate nbr, + const nfc_dep_info * pndiInitiator, + nfc_target * pnt); +bool pn53x_initiator_transceive_bits (nfc_device * pnd, const byte_t * pbtTx, const size_t szTxBits, const byte_t * pbtTxPar, byte_t * pbtRx, size_t * pszRxBits, byte_t * pbtRxPar); -bool pn53x_initiator_transceive_bytes (nfc_device_t * pnd, const byte_t * pbtTx, const size_t szTx, +bool pn53x_initiator_transceive_bytes (nfc_device * pnd, const byte_t * pbtTx, const size_t szTx, byte_t * pbtRx, size_t * pszRx, struct timeval *timeout); -bool pn53x_initiator_transceive_bits_timed (nfc_device_t * pnd, const byte_t * pbtTx, const size_t szTxBits, +bool pn53x_initiator_transceive_bits_timed (nfc_device * pnd, const byte_t * pbtTx, const size_t szTxBits, const byte_t * pbtTxPar, byte_t * pbtRx, size_t * pszRxBits, byte_t * pbtRxPar, uint32_t * cycles); -bool pn53x_initiator_transceive_bytes_timed (nfc_device_t * pnd, const byte_t * pbtTx, const size_t szTx, +bool pn53x_initiator_transceive_bytes_timed (nfc_device * pnd, const byte_t * pbtTx, const size_t szTx, byte_t * pbtRx, size_t * pszRx, uint32_t * cycles); -bool pn53x_initiator_deselect_target (nfc_device_t * pnd); +bool pn53x_initiator_deselect_target (nfc_device * pnd); // NFC device as Target functions -bool pn53x_target_init (nfc_device_t * pnd, nfc_target_t * pnt, byte_t * pbtRx, size_t * pszRx); -bool pn53x_target_receive_bits (nfc_device_t * pnd, byte_t * pbtRx, size_t * pszRxBits, byte_t * pbtRxPar); -bool pn53x_target_receive_bytes (nfc_device_t * pnd, byte_t * pbtRx, size_t * pszRx, struct timeval *timeout); -bool pn53x_target_send_bits (nfc_device_t * pnd, const byte_t * pbtTx, const size_t szTxBits, const byte_t * pbtTxPar); -bool pn53x_target_send_bytes (nfc_device_t * pnd, const byte_t * pbtTx, const size_t szTx, struct timeval *timeout); +bool pn53x_target_init (nfc_device * pnd, nfc_target * pnt, byte_t * pbtRx, size_t * pszRx); +bool pn53x_target_receive_bits (nfc_device * pnd, byte_t * pbtRx, size_t * pszRxBits, byte_t * pbtRxPar); +bool pn53x_target_receive_bytes (nfc_device * pnd, byte_t * pbtRx, size_t * pszRx, struct timeval *timeout); +bool pn53x_target_send_bits (nfc_device * pnd, const byte_t * pbtTx, const size_t szTxBits, const byte_t * pbtTxPar); +bool pn53x_target_send_bytes (nfc_device * pnd, const byte_t * pbtTx, const size_t szTx, struct timeval *timeout); // Error handling functions -const char *pn53x_strerror (const nfc_device_t * pnd); +const char *pn53x_strerror (const nfc_device * pnd); // C wrappers for PN53x commands -bool pn53x_SetParameters (nfc_device_t * pnd, const uint8_t ui8Value); -bool pn53x_SAMConfiguration (nfc_device_t * pnd, const pn532_sam_mode mode, struct timeval *timeout); -bool pn53x_PowerDown (nfc_device_t * pnd); -bool pn53x_InListPassiveTarget (nfc_device_t * pnd, const pn53x_modulation_t pmInitModulation, +bool pn53x_SetParameters (nfc_device * pnd, const uint8_t ui8Value); +bool pn53x_SAMConfiguration (nfc_device * pnd, const pn532_sam_mode mode, struct timeval *timeout); +bool pn53x_PowerDown (nfc_device * pnd); +bool pn53x_InListPassiveTarget (nfc_device * pnd, const pn53x_modulation pmInitModulation, const byte_t szMaxTargets, const byte_t * pbtInitiatorData, const size_t szInitiatorDataLen, byte_t * pbtTargetsData, size_t * pszTargetsData, struct timeval *timeout); -bool pn53x_InDeselect (nfc_device_t * pnd, const uint8_t ui8Target); -bool pn53x_InRelease (nfc_device_t * pnd, const uint8_t ui8Target); -bool pn53x_InAutoPoll (nfc_device_t * pnd, const pn53x_target_type_t * ppttTargetTypes, const size_t szTargetTypes, - const byte_t btPollNr, const byte_t btPeriod, nfc_target_t * pntTargets, +bool pn53x_InDeselect (nfc_device * pnd, const uint8_t ui8Target); +bool pn53x_InRelease (nfc_device * pnd, const uint8_t ui8Target); +bool pn53x_InAutoPoll (nfc_device * pnd, const pn53x_target_type * ppttTargetTypes, const size_t szTargetTypes, + const byte_t btPollNr, const byte_t btPeriod, nfc_target * pntTargets, size_t * pszTargetFound); -bool pn53x_InJumpForDEP (nfc_device_t * pnd, - const nfc_dep_mode_t ndm, const nfc_baud_rate_t nbr, +bool pn53x_InJumpForDEP (nfc_device * pnd, + const nfc_dep_mode ndm, const nfc_baud_rate nbr, const byte_t * pbtPassiveInitiatorData, const byte_t * pbtNFCID3i, const byte_t * pbtGB, const size_t szGB, - nfc_target_t * pnt); -bool pn53x_TgInitAsTarget (nfc_device_t * pnd, pn53x_target_mode_t ptm, + nfc_target * pnt); +bool pn53x_TgInitAsTarget (nfc_device * pnd, pn53x_target_mode ptm, const byte_t * pbtMifareParams, const byte_t * pbtTkt, size_t szTkt, const byte_t * pbtFeliCaParams, @@ -337,17 +337,17 @@ bool pn53x_TgInitAsTarget (nfc_device_t * pnd, pn53x_target_mode_t ptm, byte_t * pbtRx, size_t * pszRx, byte_t * pbtModeByte); // RFConfiguration -bool pn53x_RFConfiguration__RF_field (nfc_device_t * pnd, bool bEnable); -bool pn53x_RFConfiguration__Various_timings (nfc_device_t * pnd, const uint8_t fATR_RES_Timeout, const uint8_t fRetryTimeout); -bool pn53x_RFConfiguration__MaxRtyCOM (nfc_device_t * pnd, const uint8_t MaxRtyCOM); -bool pn53x_RFConfiguration__MaxRetries (nfc_device_t * pnd, const uint8_t MxRtyATR, const uint8_t MxRtyPSL, const uint8_t MxRtyPassiveActivation); +bool pn53x_RFConfiguration__RF_field (nfc_device * pnd, bool bEnable); +bool pn53x_RFConfiguration__Various_timings (nfc_device * pnd, const uint8_t fATR_RES_Timeout, const uint8_t fRetryTimeout); +bool pn53x_RFConfiguration__MaxRtyCOM (nfc_device * pnd, const uint8_t MaxRtyCOM); +bool pn53x_RFConfiguration__MaxRetries (nfc_device * pnd, const uint8_t MxRtyATR, const uint8_t MxRtyPSL, const uint8_t MxRtyPassiveActivation); // Misc -bool pn53x_check_ack_frame (nfc_device_t * pnd, const byte_t * pbtRxFrame, const size_t szRxFrameLen); -bool pn53x_check_error_frame (nfc_device_t * pnd, const byte_t * pbtRxFrame, const size_t szRxFrameLen); +bool pn53x_check_ack_frame (nfc_device * pnd, const byte_t * pbtRxFrame, const size_t szRxFrameLen); +bool pn53x_check_error_frame (nfc_device * pnd, const byte_t * pbtRxFrame, const size_t szRxFrameLen); bool pn53x_build_frame (byte_t * pbtFrame, size_t * pszFrame, const byte_t * pbtData, const size_t szData); -void pn53x_data_new (nfc_device_t * pnd, const struct pn53x_io* io); -void pn53x_data_free (nfc_device_t * pnd); +void pn53x_data_new (nfc_device * pnd, const struct pn53x_io* io); +void pn53x_data_free (nfc_device * pnd); #endif // __NFC_CHIPS_PN53X_H__ diff --git a/libnfc/drivers/acr122.c b/libnfc/drivers/acr122.c index 419f7ad..3c3f349 100644 --- a/libnfc/drivers/acr122.c +++ b/libnfc/drivers/acr122.c @@ -76,7 +76,7 @@ const struct pn53x_io acr122_io; -char *acr122_firmware (nfc_device_t *pnd); +char *acr122_firmware (nfc_device *pnd); const char *supported_devices[] = { "ACS ACR122", // ACR122U & Touchatag, last version @@ -239,7 +239,7 @@ acr122_connstring_decode (const nfc_connstring connstring, struct acr122_descrip return 3; } -nfc_device_t * +nfc_device * acr122_connect (const nfc_connstring connstring) { struct acr122_descriptor ndd; @@ -251,7 +251,7 @@ acr122_connect (const nfc_connstring connstring) // FIXME: acr122_connect() does not take care about bus index char *pcFirmware; - nfc_device_t *pnd = nfc_device_new (); + nfc_device *pnd = nfc_device_new (); pnd->driver_data = malloc (sizeof (struct acr122_data)); // Alloc and init chip's data @@ -300,7 +300,7 @@ error: } void -acr122_disconnect (nfc_device_t * pnd) +acr122_disconnect (nfc_device * pnd) { SCardDisconnect (DRIVER_DATA (pnd)->hCard, SCARD_LEAVE_CARD); acr122_free_scardcontext (); @@ -310,7 +310,7 @@ acr122_disconnect (nfc_device_t * pnd) } bool -acr122_send (nfc_device_t * pnd, const byte_t * pbtData, const size_t szData, struct timeval *timeout) +acr122_send (nfc_device * pnd, const byte_t * pbtData, const size_t szData, struct timeval *timeout) { // FIXME: timeout is not handled (void) timeout; @@ -381,7 +381,7 @@ acr122_send (nfc_device_t * pnd, const byte_t * pbtData, const size_t szData, st } int -acr122_receive (nfc_device_t * pnd, byte_t * pbtData, const size_t szData, struct timeval *timeout) +acr122_receive (nfc_device * pnd, byte_t * pbtData, const size_t szData, struct timeval *timeout) { // FIXME: timeout is not handled (void) timeout; @@ -422,7 +422,7 @@ acr122_receive (nfc_device_t * pnd, byte_t * pbtData, const size_t szData, struc } char * -acr122_firmware (nfc_device_t *pnd) +acr122_firmware (nfc_device *pnd) { byte_t abtGetFw[5] = { 0xFF, 0x00, 0x48, 0x00, 0x00 }; uint32_t uiResult; @@ -445,7 +445,7 @@ acr122_firmware (nfc_device_t *pnd) #if 0 bool -acr122_led_red (nfc_device_t *pnd, bool bOn) +acr122_led_red (nfc_device *pnd, bool bOn) { byte_t abtLed[9] = { 0xFF, 0x00, 0x40, 0x05, 0x04, 0x00, 0x00, 0x00, 0x00 }; byte_t abtBuf[2]; diff --git a/libnfc/drivers/acr122.h b/libnfc/drivers/acr122.h index 0a2c087..a139cb2 100644 --- a/libnfc/drivers/acr122.h +++ b/libnfc/drivers/acr122.h @@ -29,10 +29,10 @@ bool acr122_probe (nfc_connstring connstrings[], size_t connstrings_len, size_t * pszDeviceFound); // Functions used by developer to handle connection to this device -nfc_device_t *acr122_connect (const nfc_connstring connstring); -bool acr122_send (nfc_device_t * pnd, const byte_t * pbtData, const size_t szData, struct timeval *timeout); -int acr122_receive (nfc_device_t * pnd, byte_t * pbtData, const size_t szData, struct timeval *timeout); -void acr122_disconnect (nfc_device_t * pnd); +nfc_device *acr122_connect (const nfc_connstring connstring); +bool acr122_send (nfc_device * pnd, const byte_t * pbtData, const size_t szData, struct timeval *timeout); +int acr122_receive (nfc_device * pnd, byte_t * pbtData, const size_t szData, struct timeval *timeout); +void acr122_disconnect (nfc_device * pnd); extern const struct nfc_driver_t acr122_driver; diff --git a/libnfc/drivers/arygon.c b/libnfc/drivers/arygon.c index 2ff78c6..d39cd07 100644 --- a/libnfc/drivers/arygon.c +++ b/libnfc/drivers/arygon.c @@ -88,8 +88,8 @@ static const byte_t arygon_error_none[] = "FF000000\x0d\x0a"; static const byte_t arygon_error_incomplete_command[] = "FF0C0000\x0d\x0a"; static const byte_t arygon_error_unknown_mode[] = "FF060000\x0d\x0a"; -bool arygon_reset_tama (nfc_device_t * pnd); -void arygon_firmware (nfc_device_t * pnd, char * str); +bool arygon_reset_tama (nfc_device * pnd); +void arygon_firmware (nfc_device * pnd, char * str); bool arygon_probe (nfc_connstring connstrings[], size_t connstrings_len, size_t * pszDeviceFound) @@ -120,7 +120,7 @@ arygon_probe (nfc_connstring connstrings[], size_t connstrings_len, size_t * psz uart_flush_input (sp); uart_set_speed (sp, ARYGON_DEFAULT_SPEED); - nfc_device_t *pnd = nfc_device_new (); + nfc_device *pnd = nfc_device_new (); pnd->driver = &arygon_driver; pnd->driver_data = malloc(sizeof(struct arygon_data)); DRIVER_DATA (pnd)->port = sp; @@ -215,7 +215,7 @@ arygon_connstring_decode (const nfc_connstring connstring, struct arygon_descrip return 3; } -nfc_device_t * +nfc_device * arygon_connect (const nfc_connstring connstring) { struct arygon_descriptor ndd; @@ -228,7 +228,7 @@ arygon_connect (const nfc_connstring connstring) ndd.speed = ARYGON_DEFAULT_SPEED; } serial_port sp; - nfc_device_t *pnd = NULL; + nfc_device *pnd = NULL; log_put (LOG_CATEGORY, NFC_PRIORITY_TRACE, "Attempt to connect to: %s at %d bauds.", ndd.port, ndd.speed); sp = uart_open (ndd.port); @@ -286,7 +286,7 @@ arygon_connect (const nfc_connstring connstring) } void -arygon_disconnect (nfc_device_t * pnd) +arygon_disconnect (nfc_device * pnd) { // Release UART port uart_close (DRIVER_DATA (pnd)->port); @@ -304,7 +304,7 @@ arygon_disconnect (nfc_device_t * pnd) #define ARYGON_TX_BUFFER_LEN (PN53x_NORMAL_FRAME__DATA_MAX_LEN + PN53x_NORMAL_FRAME__OVERHEAD + 1) #define ARYGON_RX_BUFFER_LEN (PN53x_EXTENDED_FRAME__DATA_MAX_LEN + PN53x_EXTENDED_FRAME__OVERHEAD) bool -arygon_tama_send (nfc_device_t * pnd, const byte_t * pbtData, const size_t szData, struct timeval *timeout) +arygon_tama_send (nfc_device * pnd, const byte_t * pbtData, const size_t szData, struct timeval *timeout) { // Before sending anything, we need to discard from any junk bytes uart_flush_input (DRIVER_DATA(pnd)->port); @@ -354,7 +354,7 @@ arygon_tama_send (nfc_device_t * pnd, const byte_t * pbtData, const size_t szDat } int -arygon_abort (nfc_device_t *pnd) +arygon_abort (nfc_device *pnd) { // Send a valid TAMA packet to wakup the PN53x (we will not have an answer, according to Arygon manual) byte_t dummy[] = { 0x32, 0x00, 0x00, 0xff, 0x09, 0xf7, 0xd4, 0x00, 0x00, 0x6c, 0x69, 0x62, 0x6e, 0x66, 0x63, 0xbe, 0x00 }; @@ -366,7 +366,7 @@ arygon_abort (nfc_device_t *pnd) } int -arygon_tama_receive (nfc_device_t * pnd, byte_t * pbtData, const size_t szDataLen, struct timeval *timeout) +arygon_tama_receive (nfc_device * pnd, byte_t * pbtData, const size_t szDataLen, struct timeval *timeout) { byte_t abtRxBuf[5]; size_t len; @@ -484,7 +484,7 @@ arygon_tama_receive (nfc_device_t * pnd, byte_t * pbtData, const size_t szDataLe } void -arygon_firmware (nfc_device_t * pnd, char * str) +arygon_firmware (nfc_device * pnd, char * str) { const byte_t arygon_firmware_version_cmd[] = { DEV_ARYGON_PROTOCOL_ARYGON_ASCII, 'a', 'v' }; byte_t abtRx[16]; @@ -512,7 +512,7 @@ arygon_firmware (nfc_device_t * pnd, char * str) } bool -arygon_reset_tama (nfc_device_t * pnd) +arygon_reset_tama (nfc_device * pnd) { const byte_t arygon_reset_tama_cmd[] = { DEV_ARYGON_PROTOCOL_ARYGON_ASCII, 'a', 'r' }; byte_t abtRx[10]; // Attempted response is 10 bytes long @@ -541,7 +541,7 @@ arygon_reset_tama (nfc_device_t * pnd) } bool -arygon_abort_command (nfc_device_t * pnd) +arygon_abort_command (nfc_device * pnd) { if (pnd) { #ifndef WIN32 diff --git a/libnfc/drivers/arygon.h b/libnfc/drivers/arygon.h index 6ef6ff3..482a97b 100644 --- a/libnfc/drivers/arygon.h +++ b/libnfc/drivers/arygon.h @@ -32,11 +32,11 @@ bool arygon_probe (nfc_connstring connstrings[], size_t connstrings_len, size_t * pszDeviceFound); -nfc_device_t *arygon_connect (const nfc_connstring connstring); -void arygon_disconnect (nfc_device_t * pnd); +nfc_device *arygon_connect (const nfc_connstring connstring); +void arygon_disconnect (nfc_device * pnd); -bool arygon_tama_send (nfc_device_t * pnd, const byte_t * pbtData, const size_t szData, struct timeval *timeout); -int arygon_tama_receive (nfc_device_t * pnd, byte_t * pbtData, const size_t szDat, struct timeval *timeouta); +bool arygon_tama_send (nfc_device * pnd, const byte_t * pbtData, const size_t szData, struct timeval *timeout); +int arygon_tama_receive (nfc_device * pnd, byte_t * pbtData, const size_t szDat, struct timeval *timeouta); extern const struct nfc_driver_t arygon_driver; diff --git a/libnfc/drivers/pn532_uart.c b/libnfc/drivers/pn532_uart.c index 688323d..45ec262 100644 --- a/libnfc/drivers/pn532_uart.c +++ b/libnfc/drivers/pn532_uart.c @@ -48,8 +48,8 @@ #define PN532_UART_DRIVER_NAME "pn532_uart" #define LOG_CATEGORY "libnfc.driver.pn532_uart" -int pn532_uart_ack (nfc_device_t * pnd); -int pn532_uart_wakeup (nfc_device_t * pnd); +int pn532_uart_ack (nfc_device * pnd); +int pn532_uart_wakeup (nfc_device * pnd); const struct pn53x_io pn532_uart_io; @@ -94,7 +94,7 @@ pn532_uart_probe (nfc_connstring connstrings[], size_t connstrings_len, size_t * // Serial port claimed but we need to check if a PN532_UART is connected. uart_set_speed (sp, PN532_UART_DEFAULT_SPEED); - nfc_device_t *pnd = nfc_device_new (); + nfc_device *pnd = nfc_device_new (); pnd->driver = &pn532_uart_driver; pnd->driver_data = malloc(sizeof(struct pn532_uart_data)); DRIVER_DATA (pnd)->port = sp; @@ -196,7 +196,7 @@ pn532_connstring_decode (const nfc_connstring connstring, struct pn532_uart_desc return 3; } -nfc_device_t * +nfc_device * pn532_uart_connect (const nfc_connstring connstring) { struct pn532_uart_descriptor ndd; @@ -209,7 +209,7 @@ pn532_uart_connect (const nfc_connstring connstring) ndd.speed = PN532_UART_DEFAULT_SPEED; } serial_port sp; - nfc_device_t *pnd = NULL; + nfc_device *pnd = NULL; log_put (LOG_CATEGORY, NFC_PRIORITY_TRACE, "Attempt to connect to: %s at %d bauds.", ndd.port, ndd.speed); sp = uart_open (ndd.port); @@ -262,7 +262,7 @@ pn532_uart_connect (const nfc_connstring connstring) } void -pn532_uart_disconnect (nfc_device_t * pnd) +pn532_uart_disconnect (nfc_device * pnd) { // Release UART port uart_close (DRIVER_DATA(pnd)->port); @@ -278,7 +278,7 @@ pn532_uart_disconnect (nfc_device_t * pnd) } int -pn532_uart_wakeup (nfc_device_t * pnd) +pn532_uart_wakeup (nfc_device * pnd) { /* High Speed Unit (HSU) wake up consist to send 0x55 and wait a "long" delay for PN532 being wakeup. */ const byte_t pn532_wakeup_preamble[] = { 0x55, 0x55, 0x00, 0x00, 0x00 }; @@ -289,7 +289,7 @@ pn532_uart_wakeup (nfc_device_t * pnd) #define PN532_BUFFER_LEN (PN53x_EXTENDED_FRAME__DATA_MAX_LEN + PN53x_EXTENDED_FRAME__OVERHEAD) bool -pn532_uart_send (nfc_device_t * pnd, const byte_t * pbtData, const size_t szData, struct timeval *timeout) +pn532_uart_send (nfc_device * pnd, const byte_t * pbtData, const size_t szData, struct timeval *timeout) { // Before sending anything, we need to discard from any junk bytes uart_flush_input (DRIVER_DATA(pnd)->port); @@ -352,7 +352,7 @@ pn532_uart_send (nfc_device_t * pnd, const byte_t * pbtData, const size_t szData } int -pn532_uart_receive (nfc_device_t * pnd, byte_t * pbtData, const size_t szDataLen, struct timeval *timeout) +pn532_uart_receive (nfc_device * pnd, byte_t * pbtData, const size_t szDataLen, struct timeval *timeout) { byte_t abtRxBuf[5]; size_t len; @@ -476,7 +476,7 @@ pn532_uart_receive (nfc_device_t * pnd, byte_t * pbtData, const size_t szDataLen } int -pn532_uart_ack (nfc_device_t * pnd) +pn532_uart_ack (nfc_device * pnd) { if (POWERDOWN == CHIP_DATA(pnd)->power_mode) { if (-1 == pn532_uart_wakeup(pnd)) { @@ -487,7 +487,7 @@ pn532_uart_ack (nfc_device_t * pnd) } bool -pn532_uart_abort_command (nfc_device_t * pnd) +pn532_uart_abort_command (nfc_device * pnd) { if (pnd) { #ifndef WIN32 diff --git a/libnfc/drivers/pn532_uart.h b/libnfc/drivers/pn532_uart.h index 5f8f344..20e0ca6 100644 --- a/libnfc/drivers/pn532_uart.h +++ b/libnfc/drivers/pn532_uart.h @@ -31,10 +31,10 @@ bool pn532_uart_probe (nfc_connstring connstrings[], size_t connstrings_len, size_t * pszDeviceFound); -nfc_device_t *pn532_uart_connect (const nfc_connstring connstring); -void pn532_uart_disconnect (nfc_device_t * pnd); -bool pn532_uart_send (nfc_device_t * pnd, const byte_t * pbtData, const size_t szData, struct timeval *timeout); -int pn532_uart_receive (nfc_device_t * pnd, byte_t * pbtData, const size_t szData, struct timeval *timeout); +nfc_device *pn532_uart_connect (const nfc_connstring connstring); +void pn532_uart_disconnect (nfc_device * pnd); +bool pn532_uart_send (nfc_device * pnd, const byte_t * pbtData, const size_t szData, struct timeval *timeout); +int pn532_uart_receive (nfc_device * pnd, byte_t * pbtData, const size_t szData, struct timeval *timeout); extern const struct nfc_driver_t pn532_uart_driver; diff --git a/libnfc/drivers/pn53x_usb.c b/libnfc/drivers/pn53x_usb.c index aae9203..41e92ca 100644 --- a/libnfc/drivers/pn53x_usb.c +++ b/libnfc/drivers/pn53x_usb.c @@ -118,7 +118,7 @@ struct pn53x_usb_data { const struct pn53x_io pn53x_usb_io; bool pn53x_usb_get_usb_device_name (struct usb_device *dev, usb_dev_handle *udev, char *buffer, size_t len); -bool pn53x_usb_init (nfc_device_t *pnd); +bool pn53x_usb_init (nfc_device *pnd); int pn53x_usb_bulk_read (struct pn53x_usb_data *data, byte_t abtRx[], const size_t szRx, struct timeval *timeout) @@ -190,7 +190,7 @@ pn53x_usb_get_device_model (uint16_t vendor_id, uint16_t product_id) return UNKNOWN; } -int pn53x_usb_ack (nfc_device_t * pnd); +int pn53x_usb_ack (nfc_device * pnd); // Find transfer endpoints for bulk transfers void @@ -378,7 +378,7 @@ pn53x_usb_get_usb_device_name (struct usb_device *dev, usb_dev_handle *udev, cha return false; } -nfc_device_t * +nfc_device * pn53x_usb_connect (const nfc_connstring connstring) { struct pn53x_usb_descriptor desc; @@ -388,7 +388,7 @@ pn53x_usb_connect (const nfc_connstring connstring) return NULL; } - nfc_device_t *pnd = NULL; + nfc_device *pnd = NULL; struct pn53x_usb_data data = { .pudh = NULL, .uiEndPointIn = 0, @@ -492,7 +492,7 @@ error: } void -pn53x_usb_disconnect (nfc_device_t * pnd) +pn53x_usb_disconnect (nfc_device * pnd) { pn53x_usb_ack (pnd); @@ -519,7 +519,7 @@ pn53x_usb_disconnect (nfc_device_t * pnd) #define PN53X_USB_BUFFER_LEN (PN53x_EXTENDED_FRAME__DATA_MAX_LEN + PN53x_EXTENDED_FRAME__OVERHEAD) bool -pn53x_usb_send (nfc_device_t * pnd, const byte_t * pbtData, const size_t szData, struct timeval *timeout) +pn53x_usb_send (nfc_device * pnd, const byte_t * pbtData, const size_t szData, struct timeval *timeout) { byte_t abtFrame[PN53X_USB_BUFFER_LEN] = { 0x00, 0x00, 0xff }; // Every packet must start with "00 00 ff" size_t szFrame = 0; @@ -565,7 +565,7 @@ pn53x_usb_send (nfc_device_t * pnd, const byte_t * pbtData, const size_t szData, } int -pn53x_usb_receive (nfc_device_t * pnd, byte_t * pbtData, const size_t szDataLen, struct timeval *timeout) +pn53x_usb_receive (nfc_device * pnd, byte_t * pbtData, const size_t szDataLen, struct timeval *timeout) { size_t len; off_t offset = 0; @@ -715,13 +715,13 @@ read: } int -pn53x_usb_ack (nfc_device_t * pnd) +pn53x_usb_ack (nfc_device * pnd) { return pn53x_usb_bulk_write (DRIVER_DATA (pnd), (byte_t *) pn53x_ack_frame, sizeof (pn53x_ack_frame), NULL); } bool -pn53x_usb_init (nfc_device_t *pnd) +pn53x_usb_init (nfc_device *pnd) { // Sometimes PN53x USB doesn't reply ACK one the first frame, so we need to send a dummy one... //pn53x_check_communication (pnd); // Sony RC-S360 doesn't support this command for now so let's use a get_firmware_version instead: @@ -778,7 +778,7 @@ On ASK LoGO hardware: } bool -pn53x_usb_configure (nfc_device_t * pnd, const nfc_device_option_t ndo, const bool bEnable) +pn53x_usb_configure (nfc_device * pnd, const nfc_device_option ndo, const bool bEnable) { if (!pn53x_configure (pnd, ndo, bEnable)) return false; @@ -806,7 +806,7 @@ pn53x_usb_configure (nfc_device_t * pnd, const nfc_device_option_t ndo, const bo } bool -pn53x_usb_abort_command (nfc_device_t * pnd) +pn53x_usb_abort_command (nfc_device * pnd) { DRIVER_DATA (pnd)->abort_flag = true; return true; diff --git a/libnfc/drivers/pn53x_usb.h b/libnfc/drivers/pn53x_usb.h index 2450ea5..9d8b637 100644 --- a/libnfc/drivers/pn53x_usb.h +++ b/libnfc/drivers/pn53x_usb.h @@ -30,10 +30,10 @@ # include bool pn53x_usb_probe (nfc_connstring connstrings[], size_t connstrings_len, size_t * pszDeviceFound); -nfc_device_t *pn53x_usb_connect (const nfc_connstring connstring); -bool pn53x_usb_send (nfc_device_t * pnd, const byte_t * pbtData, const size_t szData, struct timeval *timeout); -int pn53x_usb_receive (nfc_device_t * pnd, byte_t * pbtData, const size_t szData, struct timeval *timeout); -void pn53x_usb_disconnect (nfc_device_t * pnd); +nfc_device *pn53x_usb_connect (const nfc_connstring connstring); +bool pn53x_usb_send (nfc_device * pnd, const byte_t * pbtData, const size_t szData, struct timeval *timeout); +int pn53x_usb_receive (nfc_device * pnd, byte_t * pbtData, const size_t szData, struct timeval *timeout); +void pn53x_usb_disconnect (nfc_device * pnd); extern const struct nfc_driver_t pn53x_usb_driver; diff --git a/libnfc/nfc-device.c b/libnfc/nfc-device.c index 7cd5cb6..edf3a17 100644 --- a/libnfc/nfc-device.c +++ b/libnfc/nfc-device.c @@ -19,7 +19,7 @@ /** * @file nfc-device.c - * @brief Provide internal function to manipulate nfc_device_t type + * @brief Provide internal function to manipulate nfc_device type */ /* vim:set et sw=2 ts=2: */ @@ -32,10 +32,10 @@ #include "nfc-internal.h" -nfc_device_t * +nfc_device * nfc_device_new (void) { - nfc_device_t *res = malloc (sizeof (*res)); + nfc_device *res = malloc (sizeof (*res)); if (!res) { err (EXIT_FAILURE, "nfc_device_new: malloc"); @@ -57,7 +57,7 @@ nfc_device_new (void) } void -nfc_device_free (nfc_device_t *nfc_device) +nfc_device_free (nfc_device *nfc_device) { if (nfc_device) { free (nfc_device->driver_data); diff --git a/libnfc/nfc-emulation.c b/libnfc/nfc-emulation.c index 264f651..d9b622c 100644 --- a/libnfc/nfc-emulation.c +++ b/libnfc/nfc-emulation.c @@ -28,7 +28,7 @@ #include "iso7816.h" int -nfc_emulate_target (nfc_device_t* pnd, struct nfc_emulator *emulator) +nfc_emulate_target (nfc_device* pnd, struct nfc_emulator *emulator) { byte_t abtRx[ISO7816_SHORT_R_APDU_MAX_LEN]; size_t szRx = sizeof(abtRx); diff --git a/libnfc/nfc-internal.c b/libnfc/nfc-internal.c index 36da205..bd74b30 100644 --- a/libnfc/nfc-internal.c +++ b/libnfc/nfc-internal.c @@ -23,10 +23,9 @@ */ #include -#include void -prepare_initiator_data (const nfc_modulation_t nm, byte_t **ppbtInitiatorData, size_t * pszInitiatorData) +prepare_initiator_data (const nfc_modulation nm, byte_t **ppbtInitiatorData, size_t * pszInitiatorData) { switch (nm.nmt) { case NMT_ISO14443B: { diff --git a/libnfc/nfc-internal.h b/libnfc/nfc-internal.h index 425c341..1617286 100644 --- a/libnfc/nfc-internal.h +++ b/libnfc/nfc-internal.h @@ -127,37 +127,37 @@ struct nfc_driver_t { const char *name; bool (*probe)(nfc_connstring connstrings[], size_t connstrings_len, size_t * pszDeviceFound); - nfc_device_t * (*connect) (const nfc_connstring connstring); - void (*disconnect) (nfc_device_t * pnd); - const char *(*strerror) (const nfc_device_t * pnd); + nfc_device * (*connect) (const nfc_connstring connstring); + void (*disconnect) (nfc_device * pnd); + const char *(*strerror) (const nfc_device * pnd); - bool (*initiator_init) (nfc_device_t * pnd); - bool (*initiator_select_passive_target) (nfc_device_t * pnd, const nfc_modulation_t nm, const byte_t * pbtInitData, const size_t szInitData, nfc_target_t * pnt); - bool (*initiator_poll_target) (nfc_device_t * pnd, const nfc_modulation_t * pnmModulations, const size_t szModulations, const uint8_t uiPollNr, const uint8_t btPeriod, nfc_target_t * pnt); - bool (*initiator_select_dep_target) (nfc_device_t * pnd, const nfc_dep_mode_t ndm, const nfc_baud_rate_t nbr, const nfc_dep_info_t * pndiInitiator, nfc_target_t * pnt); - bool (*initiator_deselect_target) (nfc_device_t * pnd); - bool (*initiator_transceive_bytes) (nfc_device_t * pnd, const byte_t * pbtTx, const size_t szTx, byte_t * pbtRx, size_t * pszRx, struct timeval *timeout); - bool (*initiator_transceive_bits) (nfc_device_t * pnd, const byte_t * pbtTx, const size_t szTxBits, const byte_t * pbtTxPar, byte_t * pbtRx, size_t * pszRxBits, byte_t * pbtRxPar); - bool (*initiator_transceive_bytes_timed) (nfc_device_t * pnd, const byte_t * pbtTx, const size_t szTx, byte_t * pbtRx, size_t * pszRx, uint32_t * cycles); - bool (*initiator_transceive_bits_timed) (nfc_device_t * pnd, const byte_t * pbtTx, const size_t szTxBits, const byte_t * pbtTxPar, byte_t * pbtRx, size_t * pszRxBits, byte_t * pbtRxPar, uint32_t * cycles); + bool (*initiator_init) (nfc_device * pnd); + bool (*initiator_select_passive_target) (nfc_device * pnd, const nfc_modulation nm, const byte_t * pbtInitData, const size_t szInitData, nfc_target * pnt); + bool (*initiator_poll_target) (nfc_device * pnd, const nfc_modulation * pnmModulations, const size_t szModulations, const uint8_t uiPollNr, const uint8_t btPeriod, nfc_target * pnt); + bool (*initiator_select_dep_target) (nfc_device * pnd, const nfc_dep_mode ndm, const nfc_baud_rate nbr, const nfc_dep_info * pndiInitiator, nfc_target * pnt); + bool (*initiator_deselect_target) (nfc_device * pnd); + bool (*initiator_transceive_bytes) (nfc_device * pnd, const byte_t * pbtTx, const size_t szTx, byte_t * pbtRx, size_t * pszRx, struct timeval *timeout); + bool (*initiator_transceive_bits) (nfc_device * pnd, const byte_t * pbtTx, const size_t szTxBits, const byte_t * pbtTxPar, byte_t * pbtRx, size_t * pszRxBits, byte_t * pbtRxPar); + bool (*initiator_transceive_bytes_timed) (nfc_device * pnd, const byte_t * pbtTx, const size_t szTx, byte_t * pbtRx, size_t * pszRx, uint32_t * cycles); + bool (*initiator_transceive_bits_timed) (nfc_device * pnd, const byte_t * pbtTx, const size_t szTxBits, const byte_t * pbtTxPar, byte_t * pbtRx, size_t * pszRxBits, byte_t * pbtRxPar, uint32_t * cycles); - bool (*target_init) (nfc_device_t * pnd, nfc_target_t * pnt, byte_t * pbtRx, size_t * pszRx); - bool (*target_send_bytes) (nfc_device_t * pnd, const byte_t * pbtTx, const size_t szTx, struct timeval *timeout); - bool (*target_receive_bytes) (nfc_device_t * pnd, byte_t * pbtRx, size_t * pszRx, struct timeval *timeout); - bool (*target_send_bits) (nfc_device_t * pnd, const byte_t * pbtTx, const size_t szTxBits, const byte_t * pbtTxPar); - bool (*target_receive_bits) (nfc_device_t * pnd, byte_t * pbtRx, size_t * pszRxBits, byte_t * pbtRxPar); + bool (*target_init) (nfc_device * pnd, nfc_target * pnt, byte_t * pbtRx, size_t * pszRx); + bool (*target_send_bytes) (nfc_device * pnd, const byte_t * pbtTx, const size_t szTx, struct timeval *timeout); + bool (*target_receive_bytes) (nfc_device * pnd, byte_t * pbtRx, size_t * pszRx, struct timeval *timeout); + bool (*target_send_bits) (nfc_device * pnd, const byte_t * pbtTx, const size_t szTxBits, const byte_t * pbtTxPar); + bool (*target_receive_bits) (nfc_device * pnd, byte_t * pbtRx, size_t * pszRxBits, byte_t * pbtRxPar); - bool (*configure) (nfc_device_t * pnd, const nfc_device_option_t ndo, const bool bEnable); + bool (*configure) (nfc_device * pnd, const nfc_device_option ndo, const bool bEnable); - bool (*abort_command) (nfc_device_t * pnd); - bool (*idle) (nfc_device_t * pnd); + bool (*abort_command) (nfc_device * pnd); + bool (*idle) (nfc_device * pnd); }; -nfc_device_t *nfc_device_new (void); -void nfc_device_free (nfc_device_t *nfc_device); +nfc_device *nfc_device_new (void); +void nfc_device_free (nfc_device *nfc_device); void iso14443_cascade_uid (const byte_t abtUID[], const size_t szUID, byte_t * pbtCascadedUID, size_t * pszCascadedUID); -void prepare_initiator_data (const nfc_modulation_t nm, byte_t **ppbtInitiatorData, size_t * pszInitiatorData); +void prepare_initiator_data (const nfc_modulation nm, byte_t **ppbtInitiatorData, size_t * pszInitiatorData); #endif // __NFC_INTERNAL_H__ diff --git a/libnfc/nfc.c b/libnfc/nfc.c index 5f1810f..aeea3da 100644 --- a/libnfc/nfc.c +++ b/libnfc/nfc.c @@ -98,24 +98,24 @@ nfc_get_default_device (nfc_connstring *connstring) /** * @brief Connect to a NFC device * @param connstring The device connection string if specific device is wanted, \c NULL otherwise - * @return Returns pointer to a \a nfc_device_t struct if successfull; otherwise returns \c NULL value. + * @return Returns pointer to a \a nfc_device struct if successfull; otherwise returns \c NULL value. * * If \e connstring is \c NULL, the \a nfc_get_default_device() function is used. * * If \e connstring is set, this function will try to claim the right device using information provided by \e connstring. * * When it has successfully claimed a NFC device, memory is allocated to save the device information. - * It will return a pointer to a \a nfc_device_t struct. + * It will return a pointer to a \a nfc_device struct. * This pointer should be supplied by every next functions of libnfc that should perform an action with this device. * * @note Depending on the desired operation mode, the device needs to be configured by using nfc_initiator_init() or nfc_target_init(), * optionally followed by manual tuning of the parameters if the default parameters are not suiting your goals. */ -nfc_device_t * +nfc_device * nfc_connect (const nfc_connstring connstring) { log_init (); - nfc_device_t *pnd = NULL; + nfc_device *pnd = NULL; nfc_connstring ncs; if (connstring == NULL) { @@ -158,12 +158,12 @@ nfc_connect (const nfc_connstring connstring) /** * @brief Disconnect from a NFC device - * @param pnd \a nfc_device_t struct pointer that represent currently used device + * @param pnd \a nfc_device struct pointer that represent currently used device * - * Initiator's selected tag is disconnected and the device, including allocated \a nfc_device_t struct, is released. + * Initiator's selected tag is disconnected and the device, including allocated \a nfc_device struct, is released. */ void -nfc_disconnect (nfc_device_t * pnd) +nfc_disconnect (nfc_device * pnd) { if (pnd) { // Go in idle mode @@ -206,8 +206,8 @@ nfc_list_devices (nfc_connstring connstrings[] , size_t szDevices, size_t * pszD /** * @brief Configure advanced NFC device settings * @return Returns \c true if action was successfully performed; otherwise returns \c false. - * @param pnd \a nfc_device_t struct pointer that represent currently used device - * @param ndo \a nfc_device_option_t struct that contains option to set to device + * @param pnd \a nfc_device struct pointer that represent currently used device + * @param ndo \a nfc_device_option struct that contains option to set to device * @param bEnable boolean to activate/disactivate the option * * Configures parameters and registers that control for example timing, @@ -216,7 +216,7 @@ nfc_list_devices (nfc_connstring connstrings[] , size_t szDevices, size_t * pszD * accept). */ bool -nfc_configure (nfc_device_t * pnd, const nfc_device_option_t ndo, const bool bEnable) +nfc_configure (nfc_device * pnd, const nfc_device_option ndo, const bool bEnable) { HAL (configure, pnd, ndo, bEnable); } @@ -224,7 +224,7 @@ nfc_configure (nfc_device_t * pnd, const nfc_device_option_t ndo, const bool bEn /** * @brief Initialize NFC device as initiator (reader) * @return Returns \c true if action was successfully performed; otherwise returns \c false. - * @param pnd \a nfc_device_t struct pointer that represent currently used device + * @param pnd \a nfc_device struct pointer that represent currently used device * * The NFC device is configured to function as RFID reader. * After initialization it can be used to communicate to passive RFID tags and active NFC devices. @@ -242,7 +242,7 @@ nfc_configure (nfc_device_t * pnd, const nfc_device_option_t ndo, const bool bEn * - RF field is shortly dropped (if it was enabled) then activated again */ bool -nfc_initiator_init (nfc_device_t * pnd) +nfc_initiator_init (nfc_device * pnd) { // Drop the field for a while if (!nfc_configure (pnd, NDO_ACTIVATE_FIELD, false)) @@ -287,7 +287,7 @@ nfc_initiator_init (nfc_device_t * pnd) * @brief Select a passive or emulated tag * @return Returns \c true if action was successfully performed; otherwise returns \c false. * - * @param pnd \a nfc_device_t struct pointer that represent currently used device + * @param pnd \a nfc_device struct pointer that represent currently used device * @param nm desired modulation * @param pbtInitData optional initiator data used for Felica, ISO14443B, Topaz polling or to select a specific UID in ISO14443A. * @param szInitData length of initiator data \a pbtInitData. @@ -296,7 +296,7 @@ nfc_initiator_init (nfc_device_t * pnd) * - for an ISO/IEC 14443 type B modulation, pbbInitData contains Application Family Identifier (AFI) (see ISO/IEC 14443-3); * - for a FeliCa modulation, pbbInitData contains polling payload (see ISO/IEC 18092 11.2.2.5). * - * @param[out] pnt \a nfc_target_t struct pointer which will filled if available + * @param[out] pnt \a nfc_target struct pointer which will filled if available * * The NFC device will try to find one available passive tag or emulated tag. * @@ -304,10 +304,10 @@ nfc_initiator_init (nfc_device_t * pnd) * the initial modulation and speed (106, 212 or 424 kbps) should be supplied. */ bool -nfc_initiator_select_passive_target (nfc_device_t * pnd, - const nfc_modulation_t nm, +nfc_initiator_select_passive_target (nfc_device * pnd, + const nfc_modulation nm, const byte_t * pbtInitData, const size_t szInitData, - nfc_target_t * pnt) + nfc_target * pnt) { byte_t abtInit[MAX(12, szInitData)]; size_t szInit; @@ -330,9 +330,9 @@ nfc_initiator_select_passive_target (nfc_device_t * pnd, * @brief List passive or emulated tags * @return Returns \c true if action was successfully performed; otherwise returns \c false. * - * @param pnd \a nfc_device_t struct pointer that represent currently used device + * @param pnd \a nfc_device struct pointer that represent currently used device * @param nm desired modulation - * @param[out] ant array of \a nfc_target_t that will be filled with targets info + * @param[out] ant array of \a nfc_target that will be filled with targets info * @param szTargets size of \a ant (will be the max targets listed) * @param[out] pszTargetFound pointer where target found counter will be stored * @@ -344,11 +344,11 @@ nfc_initiator_select_passive_target (nfc_device_t * pnd, * should be supplied. */ bool -nfc_initiator_list_passive_targets (nfc_device_t * pnd, - const nfc_modulation_t nm, - nfc_target_t ant[], const size_t szTargets, size_t * pszTargetFound) +nfc_initiator_list_passive_targets (nfc_device * pnd, + const nfc_modulation nm, + nfc_target ant[], const size_t szTargets, size_t * pszTargetFound) { - nfc_target_t nt; + nfc_target nt; size_t szTargetFound = 0; byte_t *pbtInitData = NULL; size_t szInitDataLen = 0; @@ -371,14 +371,14 @@ nfc_initiator_list_passive_targets (nfc_device_t * pnd, bool seen = false; // Check if we've already seen this tag for (i = 0; i < szTargetFound; i++) { - if (memcmp(&(ant[i]), &nt, sizeof (nfc_target_t)) == 0) { + if (memcmp(&(ant[i]), &nt, sizeof (nfc_target)) == 0) { seen = true; } } if (seen) { break; } - memcpy (&(ant[szTargetFound]), &nt, sizeof (nfc_target_t)); + memcpy (&(ant[szTargetFound]), &nt, sizeof (nfc_target)); szTargetFound++; // deselect has no effect on FeliCa and Jewel cards so we'll stop after one... // ISO/IEC 14443 B' cards are polled at 100% probability so it's not possible to detect correctly two cards at the same time @@ -395,20 +395,20 @@ nfc_initiator_list_passive_targets (nfc_device_t * pnd, * @brief Polling for NFC targets * @return Returns \c true if action was successfully performed; otherwise returns \c false. * - * @param pnd \a nfc_device_t struct pointer that represent currently used device + * @param pnd \a nfc_device struct pointer that represent currently used device * @param ppttTargetTypes array of desired target types * @param szTargetTypes \e ppttTargetTypes count * @param uiPollNr specifies the number of polling (0x01 – 0xFE: 1 up to 254 polling, 0xFF: Endless polling) * @note one polling is a polling for each desired target type * @param uiPeriod indicates the polling period in units of 150 ms (0x01 – 0x0F: 150ms – 2.25s) * @note e.g. if uiPeriod=10, it will poll each desired target type during 1.5s - * @param[out] pnt pointer on \a nfc_target_t (over)writable struct + * @param[out] pnt pointer on \a nfc_target (over)writable struct */ bool -nfc_initiator_poll_target (nfc_device_t * pnd, - const nfc_modulation_t * pnmModulations, const size_t szModulations, +nfc_initiator_poll_target (nfc_device * pnd, + const nfc_modulation * pnmModulations, const size_t szModulations, const uint8_t uiPollNr, const uint8_t uiPeriod, - nfc_target_t * pnt) + nfc_target * pnt) { HAL (initiator_poll_target, pnd, pnmModulations, szModulations, uiPollNr, uiPeriod, pnt); } @@ -418,21 +418,21 @@ nfc_initiator_poll_target (nfc_device_t * pnd, * @brief Select a target and request active or passive mode for D.E.P. (Data Exchange Protocol) * @return Returns \c true if action was successfully performed; otherwise returns \c false. * - * @param pnd \a nfc_device_t struct pointer that represent currently used device + * @param pnd \a nfc_device struct pointer that represent currently used device * @param ndm desired D.E.P. mode (\a NDM_ACTIVE or \a NDM_PASSIVE for active, respectively passive mode) - * @param ndiInitiator pointer \a nfc_dep_info_t struct that contains \e NFCID3 and \e General \e Bytes to set to the initiator device (optionnal, can be \e NULL) - * @param[out] pnt is a \a nfc_target_t struct pointer where target information will be put. + * @param ndiInitiator pointer \a nfc_dep_info struct that contains \e NFCID3 and \e General \e Bytes to set to the initiator device (optionnal, can be \e NULL) + * @param[out] pnt is a \a nfc_target struct pointer where target information will be put. * * The NFC device will try to find an available D.E.P. target. The standards * (ISO18092 and ECMA-340) describe the modulation that can be used for reader * to passive communications. * - * @note \a nfc_dep_info_t will be returned when the target was acquired successfully. + * @note \a nfc_dep_info will be returned when the target was acquired successfully. */ bool -nfc_initiator_select_dep_target (nfc_device_t * pnd, - const nfc_dep_mode_t ndm, const nfc_baud_rate_t nbr, - const nfc_dep_info_t * pndiInitiator, nfc_target_t * pnt) +nfc_initiator_select_dep_target (nfc_device * pnd, + const nfc_dep_mode ndm, const nfc_baud_rate nbr, + const nfc_dep_info * pndiInitiator, nfc_target * pnt) { HAL (initiator_select_dep_target, pnd, ndm, nbr, pndiInitiator, pnt); } @@ -440,7 +440,7 @@ nfc_initiator_select_dep_target (nfc_device_t * pnd, /** * @brief Deselect a selected passive or emulated tag * @return Returns \c true if action was successfully performed; otherwise returns \c false. - * @param pnd \a nfc_device_t struct pointer that represents currently used device + * @param pnd \a nfc_device struct pointer that represents currently used device * * After selecting and communicating with a passive tag, this function could be * used to deactivate and release the tag. This is very useful when there are @@ -450,7 +450,7 @@ nfc_initiator_select_dep_target (nfc_device_t * pnd, * the next tag until the correct tag is found. */ bool -nfc_initiator_deselect_target (nfc_device_t * pnd) +nfc_initiator_deselect_target (nfc_device * pnd) { HAL (initiator_deselect_target, pnd); } @@ -479,7 +479,7 @@ nfc_initiator_deselect_target (nfc_device_t * pnd) * @warning The configuration option \a NDO_HANDLE_PARITY must be set to \c true (the default value). */ bool -nfc_initiator_transceive_bytes (nfc_device_t * pnd, const byte_t * pbtTx, const size_t szTx, byte_t * pbtRx, +nfc_initiator_transceive_bytes (nfc_device * pnd, const byte_t * pbtTx, const size_t szTx, byte_t * pbtRx, size_t * pszRx, struct timeval *timeout) { HAL (initiator_transceive_bytes, pnd, pbtTx, szTx, pbtRx, pszRx, timeout) @@ -521,7 +521,7 @@ nfc_initiator_transceive_bytes (nfc_device_t * pnd, const byte_t * pbtTx, const * CRC bytes. Using this feature you are able to simulate these frames. */ bool -nfc_initiator_transceive_bits (nfc_device_t * pnd, const byte_t * pbtTx, const size_t szTxBits, const byte_t * pbtTxPar, +nfc_initiator_transceive_bits (nfc_device * pnd, const byte_t * pbtTx, const size_t szTxBits, const byte_t * pbtTxPar, byte_t * pbtRx, size_t * pszRxBits, byte_t * pbtRxPar) { HAL (initiator_transceive_bits, pnd, pbtTx, szTxBits, pbtTxPar, pbtRx, pszRxBits, pbtRxPar); @@ -548,7 +548,7 @@ nfc_initiator_transceive_bits (nfc_device_t * pnd, const byte_t * pbtTx, const s * @warning The configuration option \a NDO_HANDLE_PARITY must be set to \c true (the default value). */ bool -nfc_initiator_transceive_bytes_timed (nfc_device_t * pnd, const byte_t * pbtTx, const size_t szTx, byte_t * pbtRx, +nfc_initiator_transceive_bytes_timed (nfc_device * pnd, const byte_t * pbtTx, const size_t szTx, byte_t * pbtRx, size_t * pszRx, uint32_t * cycles) { HAL (initiator_transceive_bytes_timed, pnd, pbtTx, szTx, pbtRx, pszRx, cycles) @@ -576,7 +576,7 @@ nfc_initiator_transceive_bytes_timed (nfc_device_t * pnd, const byte_t * pbtTx, * @warning The configuration option \a NDO_HANDLE_PARITY must be set to \c true (the default value). */ bool -nfc_initiator_transceive_bits_timed (nfc_device_t * pnd, const byte_t * pbtTx, const size_t szTxBits, const byte_t * pbtTxPar, +nfc_initiator_transceive_bits_timed (nfc_device * pnd, const byte_t * pbtTx, const size_t szTxBits, const byte_t * pbtTxPar, byte_t * pbtRx, size_t * pszRxBits, byte_t * pbtRxPar, uint32_t * cycles) { HAL (initiator_transceive_bits_timed, pnd, pbtTx, szTxBits, pbtTxPar, pbtRx, pszRxBits, pbtRxPar, cycles); @@ -586,9 +586,9 @@ nfc_initiator_transceive_bits_timed (nfc_device_t * pnd, const byte_t * pbtTx, c * @brief Initialize NFC device as an emulated tag * @return Returns \c true if action was successfully performed; otherwise returns \c false. * - * @param pnd \a nfc_device_t struct pointer that represent currently used device + * @param pnd \a nfc_device struct pointer that represent currently used device * @param ntm target mode restriction that you want to emulate (eg. NTM_PASSIVE_ONLY) - * @param pnt pointer to \a nfc_target_t struct that represents the wanted emulated target + * @param pnt pointer to \a nfc_target struct that represents the wanted emulated target * * @note \a pnt can be updated by this function: if you set NBR_UNDEFINED * and/or NDM_UNDEFINED (ie. for DEP mode), these fields will be updated. @@ -613,7 +613,7 @@ nfc_initiator_transceive_bits_timed (nfc_device_t * pnd, const byte_t * pbtTx, c * receive functions can be used. */ bool -nfc_target_init (nfc_device_t * pnd, nfc_target_t * pnt, byte_t * pbtRx, size_t * pszRx) +nfc_target_init (nfc_device * pnd, nfc_target * pnt, byte_t * pbtRx, size_t * pszRx) { // Disallow invalid frame if (!nfc_configure (pnd, NDO_ACCEPT_INVALID_FRAMES, false)) @@ -646,14 +646,14 @@ nfc_target_init (nfc_device_t * pnd, nfc_target_t * pnt, byte_t * pbtRx, size_t * @brief Turn NFC device in idle mode * @return Returns \c true if action was successfully performed; otherwise returns \c false. * - * @param pnd \a nfc_device_t struct pointer that represent currently used device + * @param pnd \a nfc_device struct pointer that represent currently used device * * This function switch the device in idle mode. * In initiator mode, the RF field is turned off and the device is set to low power mode (if avaible); * In target mode, the emulation is stoped (no target available from external initiator) and the device is set to low power mode (if avaible). */ bool -nfc_idle (nfc_device_t * pnd) +nfc_idle (nfc_device * pnd) { HAL (idle, pnd); } @@ -662,7 +662,7 @@ nfc_idle (nfc_device_t * pnd) * @brief Abort current running command * @return Returns \c true if action was successfully performed; otherwise returns \c false. * - * @param pnd \a nfc_device_t struct pointer that represent currently used device + * @param pnd \a nfc_device struct pointer that represent currently used device * * Some commands (ie. nfc_target_init()) are blocking functions and will return only in particular conditions (ie. external initiator request). * This function attempt to abort the current running command. @@ -670,7 +670,7 @@ nfc_idle (nfc_device_t * pnd) * @note The blocking function (ie. nfc_target_init()) will failed with DEABORT error. */ bool -nfc_abort_command (nfc_device_t * pnd) +nfc_abort_command (nfc_device * pnd) { HAL (abort_command, pnd); } @@ -679,7 +679,7 @@ nfc_abort_command (nfc_device_t * pnd) * @brief Send bytes and APDU frames * @return Returns \c true if action was successfully performed; otherwise returns \c false. * - * @param pnd \a nfc_device_t struct pointer that represent currently used device + * @param pnd \a nfc_device struct pointer that represent currently used device * @param pbtTx pointer to Tx buffer * @param szTx size of Tx buffer * @param timeout timeval struct pointer (NULL means infinite) @@ -691,7 +691,7 @@ nfc_abort_command (nfc_device_t * pnd) * If timeout is a null pointer, the function blocks indefinitely (until an error is raised or function is completed). */ bool -nfc_target_send_bytes (nfc_device_t * pnd, const byte_t * pbtTx, const size_t szTx, struct timeval *timeout) +nfc_target_send_bytes (nfc_device * pnd, const byte_t * pbtTx, const size_t szTx, struct timeval *timeout) { HAL (target_send_bytes, pnd, pbtTx, szTx, timeout); } @@ -700,7 +700,7 @@ nfc_target_send_bytes (nfc_device_t * pnd, const byte_t * pbtTx, const size_t sz * @brief Receive bytes and APDU frames * @return Returns \c true if action was successfully performed; otherwise returns \c false. * - * @param pnd \a nfc_device_t struct pointer that represent currently used device + * @param pnd \a nfc_device struct pointer that represent currently used device * @param[out] pbtRx pointer to Rx buffer * @param[out] pszRx received byte count * @param timeout timeval struct pointer (NULL means infinite) @@ -711,7 +711,7 @@ nfc_target_send_bytes (nfc_device_t * pnd, const byte_t * pbtTx, const size_t sz * If timeout is a null pointer, the function blocks indefinitely (until an error is raised or function is completed). */ bool -nfc_target_receive_bytes (nfc_device_t * pnd, byte_t * pbtRx, size_t * pszRx, struct timeval *timeout) +nfc_target_receive_bytes (nfc_device * pnd, byte_t * pbtRx, size_t * pszRx, struct timeval *timeout) { HAL (target_receive_bytes, pnd, pbtRx, pszRx, timeout); } @@ -724,7 +724,7 @@ nfc_target_receive_bytes (nfc_device_t * pnd, byte_t * pbtRx, size_t * pszRx, st * using the specified NFC device (configured as \e target). */ bool -nfc_target_send_bits (nfc_device_t * pnd, const byte_t * pbtTx, const size_t szTxBits, const byte_t * pbtTxPar) +nfc_target_send_bits (nfc_device * pnd, const byte_t * pbtTx, const size_t szTxBits, const byte_t * pbtTxPar) { HAL (target_send_bits, pnd, pbtTx, szTxBits, pbtTxPar); } @@ -741,7 +741,7 @@ nfc_target_send_bits (nfc_device_t * pnd, const byte_t * pbtTx, const size_t szT * frames. */ bool -nfc_target_receive_bits (nfc_device_t * pnd, byte_t * pbtRx, size_t * pszRxBits, byte_t * pbtRxPar) +nfc_target_receive_bits (nfc_device * pnd, byte_t * pbtRx, size_t * pszRxBits, byte_t * pbtRxPar) { HAL (target_receive_bits, pnd, pbtRx, pszRxBits, pbtRxPar); } @@ -751,7 +751,7 @@ nfc_target_receive_bits (nfc_device_t * pnd, byte_t * pbtRx, size_t * pszRxBits, * @return Returns a string */ const char * -nfc_strerror (const nfc_device_t * pnd) +nfc_strerror (const nfc_device * pnd) { return pnd->driver->strerror (pnd); } @@ -761,7 +761,7 @@ nfc_strerror (const nfc_device_t * pnd) * @return Returns 0 upon success */ int -nfc_strerror_r (const nfc_device_t * pnd, char *pcStrErrBuf, size_t szBufLen) +nfc_strerror_r (const nfc_device * pnd, char *pcStrErrBuf, size_t szBufLen) { return (snprintf (pcStrErrBuf, szBufLen, "%s", nfc_strerror (pnd)) < 0) ? -1 : 0; } @@ -770,7 +770,7 @@ nfc_strerror_r (const nfc_device_t * pnd, char *pcStrErrBuf, size_t szBufLen) * @brief Display the PCD error a-la perror */ void -nfc_perror (const nfc_device_t * pnd, const char *pcString) +nfc_perror (const nfc_device * pnd, const char *pcString) { fprintf (stderr, "%s: %s\n", pcString, nfc_strerror (pnd)); } @@ -782,7 +782,7 @@ nfc_perror (const nfc_device_t * pnd, const char *pcString) * @return Returns a string with the device name */ const char * -nfc_device_name (nfc_device_t * pnd) +nfc_device_name (nfc_device * pnd) { return pnd->acName; } diff --git a/test/test_access_storm.c b/test/test_access_storm.c index 7e8408b..ead2190 100644 --- a/test/test_access_storm.c +++ b/test/test_access_storm.c @@ -14,31 +14,31 @@ void test_access_storm (void) { int n = NTESTS; - nfc_device_desc_t devices[MAX_DEVICE_COUNT]; + nfc_connstring connstrings[MAX_DEVICE_COUNT]; size_t device_count, ref_device_count, target_count; bool res; - nfc_list_devices (devices, MAX_DEVICE_COUNT, &ref_device_count); + nfc_list_devices (connstrings, MAX_DEVICE_COUNT, &ref_device_count); if (!ref_device_count) cut_omit ("No NFC device found"); while (n) { size_t i; - nfc_list_devices (devices, MAX_DEVICE_COUNT, &device_count); + nfc_list_devices (connstrings, MAX_DEVICE_COUNT, &device_count); cut_assert_equal_int (ref_device_count, device_count, cut_message ("device count")); for (i = 0; i < device_count; i++) { - nfc_device_t *device; - nfc_target_t ant[MAX_TARGET_COUNT]; + nfc_device *device; + nfc_target ant[MAX_TARGET_COUNT]; - device = nfc_connect (&(devices[i])); + device = nfc_connect (&(connstrings[i])); cut_assert_not_null (device, cut_message ("nfc_connect")); res = nfc_initiator_init(device); cut_assert_true (res, cut_message ("nfc_initiator_init")); - const nfc_modulation_t nm = { + const nfc_modulation nm = { .nmt = NMT_ISO14443A, .nbr = NBR_106, }; diff --git a/test/test_dep.c b/test/test_dep.c index d7b96b3..0c84678 100644 --- a/test/test_dep.c +++ b/test/test_dep.c @@ -9,8 +9,8 @@ #define TARGET 1 pthread_t threads[2]; -nfc_device_desc_t device_descriptions[2]; -nfc_device_t *devices[2]; +nfc_connstring connstrings[2]; +nfc_device *devices[2]; intptr_t result[2]; void @@ -28,13 +28,13 @@ cut_setup (void) { size_t n; - nfc_list_devices (device_descriptions, 2, &n); + nfc_list_devices (connstrings, 2, &n); if (n < 2) { cut_omit ("At least two NFC devices must be plugged-in to run this test"); } - devices[TARGET] = nfc_connect (&device_descriptions[TARGET]); - devices[INITIATOR] = nfc_connect (&device_descriptions[INITIATOR]); + devices[TARGET] = nfc_connect (&connstrings[TARGET]); + devices[INITIATOR] = nfc_connect (&connstrings[INITIATOR]); signal (SIGINT, abort_test_by_keypress); } @@ -47,7 +47,7 @@ cut_teardown (void) } struct thread_data { - nfc_device_t *device; + nfc_device *device; void *cut_test_context; }; @@ -55,11 +55,11 @@ void * target_thread (void *arg) { intptr_t thread_res = 0; -// nfc_device_t *device = ((struct thread_data *) arg)->device; +// nfc_device *device = ((struct thread_data *) arg)->device; cut_set_current_test_context (((struct thread_data *) arg)->cut_test_context); #if 0 - nfc_target_t nt = { + nfc_target nt = { .nm = { .nmt = NMT_DEP, .nbr = NBR_UNDEFINED @@ -106,7 +106,7 @@ void * initiator_thread (void *arg) { intptr_t thread_res = 0; -// nfc_device_t *device = ((struct thread_data *) arg)->device; +// nfc_device *device = ((struct thread_data *) arg)->device; cut_set_current_test_context (((struct thread_data *) arg)->cut_test_context); cut_fail("plop"); @@ -122,7 +122,7 @@ initiator_thread (void *arg) bool res = nfc_initiator_init (device); // cut_assert_true (res, cut_message ("Can't initialize NFC device as initiator")); - nfc_target_t nt; + nfc_target nt; // Passive mode / 212Kbps res = nfc_initiator_select_dep_target (device, NDM_PASSIVE, NBR_212, NULL, &nt); diff --git a/test/test_register_access.c b/test/test_register_access.c index a713081..9363f9f 100644 --- a/test/test_register_access.c +++ b/test/test_register_access.c @@ -9,17 +9,17 @@ void test_register_endianness (void) { - nfc_device_desc_t devices[MAX_DEVICE_COUNT]; + nfc_connstring connstrings[MAX_DEVICE_COUNT]; size_t device_count; bool res; - nfc_list_devices (devices, MAX_DEVICE_COUNT, &device_count); + nfc_list_devices (connstrings, MAX_DEVICE_COUNT, &device_count); if (!device_count) cut_omit ("No NFC device found"); - nfc_device_t *device; + nfc_device *device; - device = nfc_connect (&(devices[0])); + device = nfc_connect (&(connstrings[0])); cut_assert_not_null (device, cut_message ("nfc_connect")); uint8_t value; diff --git a/test/test_register_endianness.c b/test/test_register_endianness.c index 19372a3..2f7e6e5 100644 --- a/test/test_register_endianness.c +++ b/test/test_register_endianness.c @@ -10,17 +10,17 @@ void test_register_endianness (void) { - nfc_device_desc_t devices[MAX_DEVICE_COUNT]; + nfc_connstring connstrings[MAX_DEVICE_COUNT]; size_t device_count; bool res; - nfc_list_devices (devices, MAX_DEVICE_COUNT, &device_count); + nfc_list_devices (connstrings, MAX_DEVICE_COUNT, &device_count); if (!device_count) cut_omit ("No NFC device found"); - nfc_device_t *device; + nfc_device *device; - device = nfc_connect (&(devices[0])); + device = nfc_connect (&(connstrings[0])); cut_assert_not_null (device, cut_message ("nfc_connect")); uint8_t value; diff --git a/utils/mifare.c b/utils/mifare.c index ef9d147..32679c1 100644 --- a/utils/mifare.c +++ b/utils/mifare.c @@ -48,7 +48,7 @@ * The MIFARE Classic Specification (http://www.nxp.com/acrobat/other/identification/M001053_MF1ICS50_rev5_3.pdf) explains more about this process. */ bool -nfc_initiator_mifare_cmd (nfc_device_t * pnd, const mifare_cmd mc, const uint8_t ui8Block, mifare_param * pmp) +nfc_initiator_mifare_cmd (nfc_device * pnd, const mifare_cmd mc, const uint8_t ui8Block, mifare_param * pmp) { byte_t abtRx[265]; size_t szRx = sizeof(abtRx); @@ -69,19 +69,19 @@ nfc_initiator_mifare_cmd (nfc_device_t * pnd, const mifare_cmd mc, const uint8_t // Authenticate command case MC_AUTH_A: case MC_AUTH_B: - szParamLen = sizeof (mifare_param_auth); + szParamLen = sizeof (struct mifare_param_auth); break; // Data command case MC_WRITE: - szParamLen = sizeof (mifare_param_data); + szParamLen = sizeof (struct mifare_param_data); break; // Value command case MC_DECREMENT: case MC_INCREMENT: case MC_TRANSFER: - szParamLen = sizeof (mifare_param_value); + szParamLen = sizeof (struct mifare_param_value); break; // Please fix your code, you never should reach this statement diff --git a/utils/mifare.h b/utils/mifare.h index df357df..2b44f9e 100644 --- a/utils/mifare.h +++ b/utils/mifare.h @@ -53,29 +53,29 @@ typedef enum { } mifare_cmd; // MIFARE command params -typedef struct { +struct mifare_param_auth { byte_t abtKey[6]; byte_t abtUid[4]; -} mifare_param_auth; +}; -typedef struct { +struct mifare_param_data { byte_t abtData[16]; -} mifare_param_data; +}; -typedef struct { +struct mifare_param_value { byte_t abtValue[4]; -} mifare_param_value; +}; typedef union { - mifare_param_auth mpa; - mifare_param_data mpd; - mifare_param_value mpv; + struct mifare_param_auth mpa; + struct mifare_param_data mpd; + struct mifare_param_value mpv; } mifare_param; // Reset struct alignment to default # pragma pack() -bool nfc_initiator_mifare_cmd (nfc_device_t * pnd, const mifare_cmd mc, const uint8_t ui8Block, mifare_param * pmp); +bool nfc_initiator_mifare_cmd (nfc_device * pnd, const mifare_cmd mc, const uint8_t ui8Block, mifare_param * pmp); // Compiler directive, set struct alignment to 1 byte_t for compatibility # pragma pack(1) diff --git a/utils/nfc-emulate-forum-tag2.c b/utils/nfc-emulate-forum-tag2.c index 0159bae..04e274c 100644 --- a/utils/nfc-emulate-forum-tag2.c +++ b/utils/nfc-emulate-forum-tag2.c @@ -71,7 +71,7 @@ #include "nfc-utils.h" -static nfc_device_t *pnd; +static nfc_device *pnd; void stop_emulation (int sig) @@ -155,7 +155,7 @@ main(int argc, char *argv[]) (void)argc; (void)argv; - nfc_target_t nt = { + nfc_target nt = { .nm = { .nmt = NMT_ISO14443A, .nbr = NBR_UNDEFINED, // Will be updated by nfc_target_init() diff --git a/utils/nfc-emulate-forum-tag4.c b/utils/nfc-emulate-forum-tag4.c index b942b96..51ea535 100644 --- a/utils/nfc-emulate-forum-tag4.c +++ b/utils/nfc-emulate-forum-tag4.c @@ -68,7 +68,7 @@ #include "nfc-utils.h" -static nfc_device_t *pnd; +static nfc_device *pnd; static bool quiet_output = false; #define SYMBOL_PARAM_fISO14443_4_PICC 0x20 @@ -289,7 +289,7 @@ usage (char *progname) int main (int argc, char *argv[]) { - nfc_target_t nt = { + nfc_target nt = { .nm = { .nmt = NMT_ISO14443A, .nbr = NBR_UNDEFINED, // Will be updated by nfc_target_init() diff --git a/utils/nfc-list.c b/utils/nfc-list.c index 342b5f2..9c7f62e 100644 --- a/utils/nfc-list.c +++ b/utils/nfc-list.c @@ -57,7 +57,7 @@ #define MAX_DEVICE_COUNT 16 #define MAX_TARGET_COUNT 16 -static nfc_device_t *pnd; +static nfc_device *pnd; int main (int argc, const char *argv[]) @@ -108,7 +108,7 @@ main (int argc, const char *argv[]) } for (i = 0; i < szDeviceFound; i++) { - nfc_target_t ant[MAX_TARGET_COUNT]; + nfc_target ant[MAX_TARGET_COUNT]; pnd = nfc_connect (connstrings[i]); if (pnd == NULL) { @@ -119,7 +119,7 @@ main (int argc, const char *argv[]) printf ("Connected to NFC device: %s\n", pnd->acName); - nfc_modulation_t nm; + nfc_modulation nm; nm.nmt = NMT_ISO14443A; nm.nbr = NBR_106; diff --git a/utils/nfc-mfclassic.c b/utils/nfc-mfclassic.c index c3d7d95..440e6f2 100644 --- a/utils/nfc-mfclassic.c +++ b/utils/nfc-mfclassic.c @@ -52,8 +52,8 @@ #include "mifare.h" #include "nfc-utils.h" -static nfc_device_t *pnd; -static nfc_target_t nt; +static nfc_device *pnd; +static nfc_target nt; static mifare_param mp; static mifare_classic_tag mtKeys; static mifare_classic_tag mtDump; @@ -72,7 +72,7 @@ static byte_t keys[] = { 0xab, 0xcd, 0xef, 0x12, 0x34, 0x56 }; -static const nfc_modulation_t nmMifare = { +static const nfc_modulation nmMifare = { .nmt = NMT_ISO14443A, .nbr = NBR_106, }; diff --git a/utils/nfc-mfsetuid.c b/utils/nfc-mfsetuid.c index 4134acc..79f398f 100644 --- a/utils/nfc-mfsetuid.c +++ b/utils/nfc-mfsetuid.c @@ -65,7 +65,7 @@ static byte_t abtSak; static byte_t abtAts[MAX_FRAME_LEN]; static byte_t szAts = 0; static size_t szCL = 1;//Always start with Cascade Level 1 (CL1) -static nfc_device_t *pnd; +static nfc_device *pnd; bool quiet_output = false; bool iso_ats_supported = false; diff --git a/utils/nfc-mfultralight.c b/utils/nfc-mfultralight.c index 4ae8ccf..a9396c7 100644 --- a/utils/nfc-mfultralight.c +++ b/utils/nfc-mfultralight.c @@ -51,13 +51,13 @@ #include "nfc-utils.h" #include "mifare.h" -static nfc_device_t *pnd; -static nfc_target_t nt; +static nfc_device *pnd; +static nfc_target nt; static mifare_param mp; static mifareul_tag mtDump; static uint32_t uiBlocks = 0xF; -static const nfc_modulation_t nmMifare = { +static const nfc_modulation nmMifare = { .nmt = NMT_ISO14443A, .nbr = NBR_106, }; diff --git a/utils/nfc-read-forum-tag3.c b/utils/nfc-read-forum-tag3.c index cf68e23..c634ea5 100644 --- a/utils/nfc-read-forum-tag3.c +++ b/utils/nfc-read-forum-tag3.c @@ -57,7 +57,7 @@ #include "nfc-utils.h" -static nfc_device_t *pnd; +static nfc_device *pnd; void print_usage(char *progname) @@ -77,7 +77,7 @@ void stop_select (int sig) } void -build_felica_frame(const nfc_felica_info_t nfi, const byte_t command, const byte_t* payload, const size_t payload_len, byte_t * frame, size_t * frame_len) +build_felica_frame(const nfc_felica_info nfi, const byte_t command, const byte_t* payload, const size_t payload_len, byte_t * frame, size_t * frame_len) { frame[0] = 1 + 1 + 8 + payload_len; *frame_len = frame[0]; @@ -88,7 +88,7 @@ build_felica_frame(const nfc_felica_info_t nfi, const byte_t command, const byte #define CHECK 0x06 int -nfc_forum_tag_type3_check (nfc_device_t *pnd, const nfc_target_t nt, const uint16_t block, const uint8_t block_count, byte_t * data, size_t * data_len) +nfc_forum_tag_type3_check (nfc_device *pnd, const nfc_target nt, const uint16_t block, const uint8_t block_count, byte_t * data, size_t * data_len) { byte_t payload[1024] = { 1, // Services @@ -204,14 +204,14 @@ main(int argc, char *argv[]) fprintf (message_stream, "Connected to NFC device: %s\n", pnd->acName); - nfc_modulation_t nm = { + nfc_modulation nm = { .nmt = NMT_FELICA, .nbr = NBR_212, }; signal (SIGINT, stop_select); - nfc_target_t nt; + nfc_target nt; nfc_initiator_init(pnd); fprintf (message_stream, "Place your NFC Forum Tag Type 3 in the field...\n"); diff --git a/utils/nfc-relay-picc.c b/utils/nfc-relay-picc.c index cbf27b7..82b26a0 100644 --- a/utils/nfc-relay-picc.c +++ b/utils/nfc-relay-picc.c @@ -61,8 +61,8 @@ static byte_t abtCapdu[MAX_FRAME_LEN]; static size_t szCapduLen; static byte_t abtRapdu[MAX_FRAME_LEN]; static size_t szRapduLen; -static nfc_device_t *pndInitiator; -static nfc_device_t *pndTarget; +static nfc_device *pndInitiator; +static nfc_device *pndTarget; static bool quitting = false; static bool quiet_output = false; static bool initiator_only_mode = false; @@ -151,7 +151,7 @@ main (int argc, char *argv[]) int arg; size_t szFound; const char *acLibnfcVersion = nfc_version (); - nfc_target_t ntRealTarget; + nfc_target ntRealTarget; // Get commandline options for (arg = 1; arg < argc; arg++) { @@ -236,7 +236,7 @@ main (int argc, char *argv[]) } // Try to find a ISO 14443-4A tag - nfc_modulation_t nm = { + nfc_modulation nm = { .nmt = NMT_ISO14443A, .nbr = NBR_106, }; @@ -279,7 +279,7 @@ main (int argc, char *argv[]) printf ("Hint: tag <---> initiator (relay) <---> target (relay) <---> original reader\n\n"); } if (!initiator_only_mode) { - nfc_target_t ntEmulatedTarget = { + nfc_target ntEmulatedTarget = { .nm = { .nmt = NMT_ISO14443A, .nbr = NBR_106, diff --git a/utils/nfc-utils.c b/utils/nfc-utils.c index 4321169..9b87844 100644 --- a/utils/nfc-utils.c +++ b/utils/nfc-utils.c @@ -133,7 +133,7 @@ print_hex_par (const byte_t * pbtData, const size_t szBits, const byte_t * pbtDa #define SAK_ISO18092_COMPLIANT 0x40 void -print_nfc_iso14443a_info (const nfc_iso14443a_info_t nai, bool verbose) +print_nfc_iso14443a_info (const nfc_iso14443a_info nai, bool verbose) { printf (" ATQA (SENS_RES): "); print_hex (nai.abtAtqa, 2); @@ -530,7 +530,7 @@ print_nfc_iso14443a_info (const nfc_iso14443a_info_t nai, bool verbose) } void -print_nfc_felica_info (const nfc_felica_info_t nfi, bool verbose) +print_nfc_felica_info (const nfc_felica_info nfi, bool verbose) { (void) verbose; printf (" ID (NFCID2): "); @@ -542,7 +542,7 @@ print_nfc_felica_info (const nfc_felica_info_t nfi, bool verbose) } void -print_nfc_jewel_info (const nfc_jewel_info_t nji, bool verbose) +print_nfc_jewel_info (const nfc_jewel_info nji, bool verbose) { (void) verbose; printf (" ATQA (SENS_RES): "); @@ -555,7 +555,7 @@ print_nfc_jewel_info (const nfc_jewel_info_t nji, bool verbose) #define PI_NAD_SUPPORTED 0x01 #define PI_CID_SUPPORTED 0x02 void -print_nfc_iso14443b_info (const nfc_iso14443b_info_t nbi, bool verbose) +print_nfc_iso14443b_info (const nfc_iso14443b_info nbi, bool verbose) { const int iMaxFrameSizes[] = { 16, 24, 32, 40, 48, 64, 96, 128, 256 }; printf (" PUPI: "); @@ -610,7 +610,7 @@ print_nfc_iso14443b_info (const nfc_iso14443b_info_t nbi, bool verbose) } void -print_nfc_iso14443bi_info (const nfc_iso14443bi_info_t nii, bool verbose) +print_nfc_iso14443bi_info (const nfc_iso14443bi_info nii, bool verbose) { printf (" DIV: "); print_hex (nii.abtDIV, 4); @@ -634,7 +634,7 @@ print_nfc_iso14443bi_info (const nfc_iso14443bi_info_t nii, bool verbose) } void -print_nfc_iso14443b2sr_info (const nfc_iso14443b2sr_info_t nsi, bool verbose) +print_nfc_iso14443b2sr_info (const nfc_iso14443b2sr_info nsi, bool verbose) { (void) verbose; printf (" UID: "); @@ -642,7 +642,7 @@ print_nfc_iso14443b2sr_info (const nfc_iso14443b2sr_info_t nsi, bool verbose) } void -print_nfc_iso14443b2ct_info (const nfc_iso14443b2ct_info_t nci, bool verbose) +print_nfc_iso14443b2ct_info (const nfc_iso14443b2ct_info nci, bool verbose) { (void) verbose; uint32_t uid; @@ -655,7 +655,7 @@ print_nfc_iso14443b2ct_info (const nfc_iso14443b2ct_info_t nci, bool verbose) } void -print_nfc_dep_info (const nfc_dep_info_t ndi, bool verbose) +print_nfc_dep_info (const nfc_dep_info ndi, bool verbose) { (void) verbose; printf (" NFCID3: "); @@ -671,7 +671,7 @@ print_nfc_dep_info (const nfc_dep_info_t ndi, bool verbose) } const char * -str_nfc_baud_rate (const nfc_baud_rate_t nbr) +str_nfc_baud_rate (const nfc_baud_rate nbr) { switch(nbr) { case NBR_UNDEFINED: @@ -694,7 +694,7 @@ str_nfc_baud_rate (const nfc_baud_rate_t nbr) } void -print_nfc_target (const nfc_target_t nt, bool verbose) +print_nfc_target (const nfc_target nt, bool verbose) { switch(nt.nm.nmt) { case NMT_ISO14443A: diff --git a/utils/nfc-utils.h b/utils/nfc-utils.h index ace6473..f0ae97f 100644 --- a/utils/nfc-utils.h +++ b/utils/nfc-utils.h @@ -86,15 +86,15 @@ void print_hex (const byte_t * pbtData, const size_t szLen); void print_hex_bits (const byte_t * pbtData, const size_t szBits); void print_hex_par (const byte_t * pbtData, const size_t szBits, const byte_t * pbtDataPar); -void print_nfc_iso14443a_info (const nfc_iso14443a_info_t nai, bool verbose); -void print_nfc_iso14443b_info (const nfc_iso14443b_info_t nbi, bool verbose); -void print_nfc_iso14443bi_info (const nfc_iso14443bi_info_t nii, bool verbose); -void print_nfc_iso14443b2sr_info (const nfc_iso14443b2sr_info_t nsi, bool verbose); -void print_nfc_iso14443b2ct_info (const nfc_iso14443b2ct_info_t nci, bool verbose); -void print_nfc_felica_info (const nfc_felica_info_t nfi, bool verbose); -void print_nfc_jewel_info (const nfc_jewel_info_t nji, bool verbose); -void print_nfc_dep_info (const nfc_dep_info_t ndi, bool verbose); +void print_nfc_iso14443a_info (const nfc_iso14443a_info nai, bool verbose); +void print_nfc_iso14443b_info (const nfc_iso14443b_info nbi, bool verbose); +void print_nfc_iso14443bi_info (const nfc_iso14443bi_info nii, bool verbose); +void print_nfc_iso14443b2sr_info (const nfc_iso14443b2sr_info nsi, bool verbose); +void print_nfc_iso14443b2ct_info (const nfc_iso14443b2ct_info nci, bool verbose); +void print_nfc_felica_info (const nfc_felica_info nfi, bool verbose); +void print_nfc_jewel_info (const nfc_jewel_info nji, bool verbose); +void print_nfc_dep_info (const nfc_dep_info ndi, bool verbose); -void print_nfc_target (const nfc_target_t nt, bool verbose); +void print_nfc_target (const nfc_target nt, bool verbose); #endif