diff --git a/src/examples/nfc-anticol.c b/src/examples/nfc-anticol.c index 3bec5d8..f6b606b 100644 --- a/src/examples/nfc-anticol.c +++ b/src/examples/nfc-anticol.c @@ -138,14 +138,14 @@ int main(int argc,char* argv[]) nfc_initiator_init(pnd); // Drop the field for a while - nfc_configure(pnd,DCO_ACTIVATE_FIELD,false); + nfc_configure(pnd,NDO_ACTIVATE_FIELD,false); // Configure the CRC and Parity settings - nfc_configure(pnd,DCO_HANDLE_CRC,false); - nfc_configure(pnd,DCO_HANDLE_PARITY,true); + nfc_configure(pnd,NDO_HANDLE_CRC,false); + nfc_configure(pnd,NDO_HANDLE_PARITY,true); // Enable field so more power consuming cards can power themselves up - nfc_configure(pnd,DCO_ACTIVATE_FIELD,true); + nfc_configure(pnd,NDO_ACTIVATE_FIELD,true); printf("\nConnected to NFC reader: %s\n\n",pnd->acName); diff --git a/src/examples/nfc-emulate.c b/src/examples/nfc-emulate.c index 1781508..b208784 100644 --- a/src/examples/nfc-emulate.c +++ b/src/examples/nfc-emulate.c @@ -108,8 +108,8 @@ int main(int argc, char *argv[]) printf("[+] Received initiator command: "); print_hex_bits(abtRecv,szRecvBits); printf("[+] Configuring communication\n"); - nfc_configure(pnd,DCO_HANDLE_CRC,false); - nfc_configure(pnd,DCO_HANDLE_PARITY,true); + nfc_configure(pnd,NDO_HANDLE_CRC,false); + nfc_configure(pnd,NDO_HANDLE_PARITY,true); printf("[+] Done, the emulated tag is initialized with UID: %02X%02X%02X%02X\n\n",abtUidBcc[0],abtUidBcc[1],abtUidBcc[2],abtUidBcc[3]); while(true) diff --git a/src/examples/nfc-list.c b/src/examples/nfc-list.c index ec6cfec..debad29 100644 --- a/src/examples/nfc-list.c +++ b/src/examples/nfc-list.c @@ -60,17 +60,17 @@ int main(int argc, const char* argv[]) nfc_initiator_init(pnd); // Drop the field for a while - nfc_configure(pnd,DCO_ACTIVATE_FIELD,false); + nfc_configure(pnd,NDO_ACTIVATE_FIELD,false); // Let the reader only try once to find a tag - nfc_configure(pnd,DCO_INFINITE_SELECT,false); + nfc_configure(pnd,NDO_INFINITE_SELECT,false); // Configure the CRC and Parity settings - nfc_configure(pnd,DCO_HANDLE_CRC,true); - nfc_configure(pnd,DCO_HANDLE_PARITY,true); + nfc_configure(pnd,NDO_HANDLE_CRC,true); + nfc_configure(pnd,NDO_HANDLE_PARITY,true); // Enable field so more power consuming cards can power themselves up - nfc_configure(pnd,DCO_ACTIVATE_FIELD,true); + nfc_configure(pnd,NDO_ACTIVATE_FIELD,true); printf("Connected to NFC reader: %s\n\n",pnd->acName); diff --git a/src/examples/nfc-mfclassic.c b/src/examples/nfc-mfclassic.c index 3821c8e..d8eca84 100644 --- a/src/examples/nfc-mfclassic.c +++ b/src/examples/nfc-mfclassic.c @@ -414,15 +414,15 @@ int main(int argc, const char* argv[]) nfc_initiator_init(pnd); // Drop the field for a while - nfc_configure(pnd,DCO_ACTIVATE_FIELD,false); + nfc_configure(pnd,NDO_ACTIVATE_FIELD,false); // Let the reader only try once to find a tag - nfc_configure(pnd,DCO_INFINITE_SELECT,false); - nfc_configure(pnd,DCO_HANDLE_CRC,true); - nfc_configure(pnd,DCO_HANDLE_PARITY,true); + nfc_configure(pnd,NDO_INFINITE_SELECT,false); + nfc_configure(pnd,NDO_HANDLE_CRC,true); + nfc_configure(pnd,NDO_HANDLE_PARITY,true); // Enable field so more power consuming cards can power themselves up - nfc_configure(pnd,DCO_ACTIVATE_FIELD,true); + nfc_configure(pnd,NDO_ACTIVATE_FIELD,true); printf("Connected to NFC reader: %s\n",pnd->acName); diff --git a/src/examples/nfc-mfultralight.c b/src/examples/nfc-mfultralight.c index a957d35..abadab0 100644 --- a/src/examples/nfc-mfultralight.c +++ b/src/examples/nfc-mfultralight.c @@ -158,15 +158,15 @@ int main(int argc, const char* argv[]) nfc_initiator_init(pnd); // Drop the field for a while - nfc_configure(pnd,DCO_ACTIVATE_FIELD,false); + nfc_configure(pnd,NDO_ACTIVATE_FIELD,false); // Let the reader only try once to find a tag - nfc_configure(pnd,DCO_INFINITE_SELECT,false); - nfc_configure(pnd,DCO_HANDLE_CRC,true); - nfc_configure(pnd,DCO_HANDLE_PARITY,true); + nfc_configure(pnd,NDO_INFINITE_SELECT,false); + nfc_configure(pnd,NDO_HANDLE_CRC,true); + nfc_configure(pnd,NDO_HANDLE_PARITY,true); // Enable field so more power consuming cards can power themselves up - nfc_configure(pnd,DCO_ACTIVATE_FIELD,true); + nfc_configure(pnd,NDO_ACTIVATE_FIELD,true); printf("Connected to NFC reader: %s\n",pnd->acName); diff --git a/src/examples/nfc-relay.c b/src/examples/nfc-relay.c index 659e339..bb1d110 100644 --- a/src/examples/nfc-relay.c +++ b/src/examples/nfc-relay.c @@ -85,18 +85,18 @@ int main(int argc,char* argv[]) printf("[+] For example, send a RATS command or use the \"nfc-anticol\" tool\n"); nfc_target_init(pndTag,abtReaderRx,&szReaderRxBits); printf("[+] Configuring emulator settings\n"); - nfc_configure(pndTag,DCO_HANDLE_CRC,false); - nfc_configure(pndTag,DCO_HANDLE_PARITY,false); - nfc_configure(pndTag,DCO_ACCEPT_INVALID_FRAMES,true); + nfc_configure(pndTag,NDO_HANDLE_CRC,false); + nfc_configure(pndTag,NDO_HANDLE_PARITY,false); + nfc_configure(pndTag,NDO_ACCEPT_INVALID_FRAMES,true); printf("[+] Thank you, the emulated tag is initialized\n"); // Try to open the NFC reader pndReader = NULL; while (pndReader == NULL) pndReader = nfc_connect(NULL); printf("[+] Configuring NFC reader settings\n"); - nfc_configure(pndReader,DCO_HANDLE_CRC,false); - nfc_configure(pndReader,DCO_HANDLE_PARITY,false); - nfc_configure(pndReader,DCO_ACCEPT_INVALID_FRAMES,true); + nfc_configure(pndReader,NDO_HANDLE_CRC,false); + nfc_configure(pndReader,NDO_HANDLE_PARITY,false); + nfc_configure(pndReader,NDO_ACCEPT_INVALID_FRAMES,true); printf("[+] Done, relaying frames now!\n\n"); while(true) @@ -108,10 +108,10 @@ int main(int argc,char* argv[]) if (szReaderRxBits == 7 && abtReaderRx[0] == 0x26) { // Drop down field for a very short time (original tag will reboot) - nfc_configure(pndReader,DCO_ACTIVATE_FIELD,false); + nfc_configure(pndReader,NDO_ACTIVATE_FIELD,false); if(!quiet_output) printf("\n"); - nfc_configure(pndReader,DCO_ACTIVATE_FIELD,true); + nfc_configure(pndReader,NDO_ACTIVATE_FIELD,true); } // Print the reader frame to the screen diff --git a/src/lib/drivers.h b/src/lib/drivers.h index a455bba..b20778e 100644 --- a/src/lib/drivers.h +++ b/src/lib/drivers.h @@ -40,7 +40,6 @@ #include "drivers/pn532_uart.h" #define DRIVERS_MAX_DEVICES 16 -#define INVALID_DEVICE_INFO 0 #define MAX_FRAME_LEN 264 const static struct driver_callbacks drivers_callbacks_list[] = { diff --git a/src/lib/drivers/acr122.c b/src/lib/drivers/acr122.c index e2e197f..646e555 100644 --- a/src/lib/drivers/acr122.c +++ b/src/lib/drivers/acr122.c @@ -79,10 +79,10 @@ nfc_device_t* acr122_connect(const nfc_device_desc_t* pndd) memset(acList,0x00,szListLen); // Test if context succeeded - if (SCardEstablishContext(SCARD_SCOPE_USER,NULL,NULL,&(as.hCtx)) != SCARD_S_SUCCESS) return INVALID_DEVICE_INFO; + if (SCardEstablishContext(SCARD_SCOPE_USER,NULL,NULL,&(as.hCtx)) != SCARD_S_SUCCESS) return NULL; // Retrieve the string array of all available pcsc readers - if (SCardListReaders(as.hCtx,NULL,acList,(void*)&szListLen) != SCARD_S_SUCCESS) return INVALID_DEVICE_INFO; + if (SCardListReaders(as.hCtx,NULL,acList,(void*)&szListLen) != SCARD_S_SUCCESS) return NULL; DBG("PCSC reports following device(s):"); DBG("- %s",acList); @@ -163,7 +163,7 @@ nfc_device_t* acr122_connect(const nfc_device_desc_t* pndd) } // Too bad, the reader could not be located; - return INVALID_DEVICE_INFO; + return NULL; } void acr122_disconnect(nfc_device_t* pnd) diff --git a/src/lib/drivers/arygon.c b/src/lib/drivers/arygon.c index c9071ba..2b329a5 100644 --- a/src/lib/drivers/arygon.c +++ b/src/lib/drivers/arygon.c @@ -80,12 +80,12 @@ nfc_device_t* arygon_connect(const nfc_device_desc_t* pndd) uint32_t uiDevNr; serial_port sp; char acConnect[BUFFER_LENGTH]; - nfc_device_t* pnd = INVALID_DEVICE_INFO; + nfc_device_t* pnd = NULL; if( pndd == NULL ) { #ifdef DISABLE_SERIAL_AUTOPROBE INFO("Sorry, serial auto-probing have been disabled at compile time."); - return INVALID_DEVICE_INFO; + return NULL; #else DBG("Trying to find ARYGON device on serial port: %s# at %d bauds.",SERIAL_STRING, SERIAL_DEFAULT_PORT_SPEED); // I have no idea how MAC OS X deals with multiple devices, so a quick workaround @@ -110,14 +110,14 @@ nfc_device_t* arygon_connect(const nfc_device_desc_t* pndd) } #endif // Test if we have found a device - if (uiDevNr == DRIVERS_MAX_DEVICES) return INVALID_DEVICE_INFO; + if (uiDevNr == DRIVERS_MAX_DEVICES) return NULL; } else { DBG("Connecting to: %s at %d bauds.",pndd->pcPort, pndd->uiSpeed); strcpy(acConnect,pndd->pcPort); sp = uart_open(acConnect); if (sp == INVALID_SERIAL_PORT) ERR("Invalid serial port: %s",acConnect); if (sp == CLAIMED_SERIAL_PORT) ERR("Serial port already claimed: %s",acConnect); - if ((sp == CLAIMED_SERIAL_PORT) || (sp == INVALID_SERIAL_PORT)) return INVALID_DEVICE_INFO; + if ((sp == CLAIMED_SERIAL_PORT) || (sp == INVALID_SERIAL_PORT)) return NULL; uart_set_speed(sp, pndd->uiSpeed); } diff --git a/src/lib/drivers/pn531_usb.c b/src/lib/drivers/pn531_usb.c index fbc7394..69cdcec 100644 --- a/src/lib/drivers/pn531_usb.c +++ b/src/lib/drivers/pn531_usb.c @@ -90,7 +90,7 @@ nfc_device_t* pn531_usb_connect(const nfc_device_desc_t* pndd) int idproduct_alt = 0x0193; struct usb_bus *bus; struct usb_device *dev; - nfc_device_t* pnd = INVALID_DEVICE_INFO; + nfc_device_t* pnd = NULL; usb_spec_t* pus; usb_spec_t us; uint32_t uiDevIndex; @@ -100,8 +100,8 @@ nfc_device_t* pn531_usb_connect(const nfc_device_desc_t* pndd) us.pudh = NULL; usb_init(); - if (usb_find_busses() < 0) return INVALID_DEVICE_INFO; - if (usb_find_devices() < 0) return INVALID_DEVICE_INFO; + if (usb_find_busses() < 0) return NULL; + if (usb_find_devices() < 0) return NULL; // Initialize the device index we are seaching for if( pndd == NULL ) { @@ -137,14 +137,14 @@ nfc_device_t* pn531_usb_connect(const nfc_device_desc_t* pndd) { DBG("Set config failed"); usb_close(us.pudh); - return INVALID_DEVICE_INFO; + return NULL; } if(usb_claim_interface(us.pudh,0) < 0) { DBG("Can't claim interface"); usb_close(us.pudh); - return INVALID_DEVICE_INFO; + return NULL; } // Allocate memory for the device info and specification, fill it and return the info pus = malloc(sizeof(usb_spec_t)); diff --git a/src/lib/drivers/pn532_uart.c b/src/lib/drivers/pn532_uart.c index 9644df2..c49b317 100644 --- a/src/lib/drivers/pn532_uart.c +++ b/src/lib/drivers/pn532_uart.c @@ -56,12 +56,12 @@ nfc_device_t* pn532_uart_connect(const nfc_device_desc_t* pndd) uint32_t uiDevNr; serial_port sp; char acConnect[BUFFER_LENGTH]; - nfc_device_t* pnd = INVALID_DEVICE_INFO; + nfc_device_t* pnd = NULL; if( pndd == NULL ) { #ifdef DISABLE_SERIAL_AUTOPROBE INFO("Sorry, serial auto-probing have been disabled at compile time."); - return INVALID_DEVICE_INFO; + return NULL; #else DBG("Trying to find ARYGON device on serial port: %s# at %d bauds.",SERIAL_STRING, SERIAL_DEFAULT_PORT_SPEED); // I have no idea how MAC OS X deals with multiple devices, so a quick workaround @@ -86,14 +86,14 @@ nfc_device_t* pn532_uart_connect(const nfc_device_desc_t* pndd) } #endif // Test if we have found a device - if (uiDevNr == DRIVERS_MAX_DEVICES) return INVALID_DEVICE_INFO; + if (uiDevNr == DRIVERS_MAX_DEVICES) return NULL; } else { DBG("Connecting to: %s at %d bauds.",pndd->pcPort, pndd->uiSpeed); strcpy(acConnect,pndd->pcPort); sp = uart_open(acConnect); if (sp == INVALID_SERIAL_PORT) ERR("Invalid serial port: %s",acConnect); if (sp == CLAIMED_SERIAL_PORT) ERR("Serial port already claimed: %s",acConnect); - if ((sp == CLAIMED_SERIAL_PORT) || (sp == INVALID_SERIAL_PORT)) return INVALID_DEVICE_INFO; + if ((sp == CLAIMED_SERIAL_PORT) || (sp == INVALID_SERIAL_PORT)) return NULL; uart_set_speed(sp, pndd->uiSpeed); } diff --git a/src/lib/drivers/pn533_usb.c b/src/lib/drivers/pn533_usb.c index 22ac126..ae770b2 100644 --- a/src/lib/drivers/pn533_usb.c +++ b/src/lib/drivers/pn533_usb.c @@ -87,7 +87,7 @@ nfc_device_t* pn533_usb_connect(const nfc_device_desc_t* pndd) int idproduct = 0x5591; struct usb_bus *bus; struct usb_device *dev; - nfc_device_t* pnd = INVALID_DEVICE_INFO; + nfc_device_t* pnd = NULL; usb_spec_t* pus; usb_spec_t us; uint32_t uiDevIndex; @@ -97,8 +97,8 @@ nfc_device_t* pn533_usb_connect(const nfc_device_desc_t* pndd) us.pudh = NULL; usb_init(); - if (usb_find_busses() < 0) return INVALID_DEVICE_INFO; - if (usb_find_devices() < 0) return INVALID_DEVICE_INFO; + if (usb_find_busses() < 0) return NULL; + if (usb_find_devices() < 0) return NULL; // Initialize the device index we are seaching for if( pndd == NULL ) { @@ -133,14 +133,14 @@ nfc_device_t* pn533_usb_connect(const nfc_device_desc_t* pndd) { DBG("Setting config failed"); usb_close(us.pudh); - return INVALID_DEVICE_INFO; + return NULL; } if(usb_claim_interface(us.pudh,0) < 0) { DBG("Can't claim interface"); usb_close(us.pudh); - return INVALID_DEVICE_INFO; + return NULL; } // Allocate memory for the device info and specification, fill it and return the info pus = malloc(sizeof(usb_spec_t)); diff --git a/src/lib/nfc-types.h b/src/lib/nfc-types.h index 88a1174..1c937e3 100644 --- a/src/lib/nfc-types.h +++ b/src/lib/nfc-types.h @@ -107,25 +107,25 @@ struct driver_callbacks { #pragma pack(1) /** - * @enum dev_config_option + * @enum nfc_device_option_t * @brief NFC device option */ typedef enum { /** Let the PN53X chip handle the CRC bytes. This means that the chip appends the CRC bytes to the frames that are transmitted. It will parse the last bytes from received frames as incoming CRC bytes. They will be verified against the used modulation and protocol. If an frame is expected with incorrect CRC bytes this option should be disabled. Example frames where this is useful are the ATQA and UID+BCC that are transmitted without CRC bytes during the anti-collision phase of the ISO14443-A protocol. */ - DCO_HANDLE_CRC = 0x00, + NDO_HANDLE_CRC = 0x00, /** Parity bits in the network layer of ISO14443-A are by default generated and validated in the PN53X chip. This is a very convenient feature. On certain times though it is useful to get full control of the transmitted data. The proprietary MIFARE Classic protocol uses for example custom (encrypted) parity bits. For interoperability it is required to be completely compatible, including the arbitrary parity bits. When this option is disabled, the functions to communicating bits should be used. */ - DCO_HANDLE_PARITY = 0x01, + NDO_HANDLE_PARITY = 0x01, /** This option can be used to enable or disable the electronic field of the NFC device. */ - DCO_ACTIVATE_FIELD = 0x10, + NDO_ACTIVATE_FIELD = 0x10, /** The internal CRYPTO1 co-processor can be used to transmit messages encrypted. This option is automatically activated after a successful MIFARE Classic authentication. */ - DCO_ACTIVATE_CRYPTO1 = 0x11, + NDO_ACTIVATE_CRYPTO1 = 0x11, /** The default configuration defines that the PN53X chip will try indefinitely to invite a tag in the field to respond. This could be desired when it is certain a tag will enter the field. On the other hand, when this is uncertain, it will block the application. This option could best be compared to the (NON)BLOCKING option used by (socket)network programming. */ - DCO_INFINITE_SELECT = 0x20, + NDO_INFINITE_SELECT = 0x20, /** If this option is enabled, frames that carry less than 4 bits are allowed. According to the standards these frames should normally be handles as invalid frames. */ - DCO_ACCEPT_INVALID_FRAMES = 0x30, + NDO_ACCEPT_INVALID_FRAMES = 0x30, /** If the NFC device should only listen to frames, it could be useful to let it gather multiple frames in a sequence. They will be stored in the internal FIFO of the PN53X chip. This could be retrieved by using the receive data functions. Note that if the chip runs out of bytes (FIFO = 64 bytes long), it will overwrite the first received frames, so quick retrieving of the received data is desirable. */ - DCO_ACCEPT_MULTIPLE_FRAMES = 0x31 -}dev_config_option; + NDO_ACCEPT_MULTIPLE_FRAMES = 0x31 +} nfc_device_option_t; //////////////////////////////////////////////////////////////////// // nfc_reader_list_passive - using InListPassiveTarget diff --git a/src/lib/nfc.c b/src/lib/nfc.c index 6212e1e..4ed6915 100644 --- a/src/lib/nfc.c +++ b/src/lib/nfc.c @@ -302,7 +302,7 @@ nfc_device_t* nfc_connect(nfc_device_desc_t* pndd) } // Test if the connection was successful - if (pnd != INVALID_DEVICE_INFO) + if (pnd != NULL) { DBG("[%s] has been claimed.", pnd->acName); // Great we have claimed a device @@ -315,7 +315,7 @@ nfc_device_t* nfc_connect(nfc_device_desc_t* pndd) // Failed to get firmware revision??, whatever...let's disconnect and clean up and return err ERR("Failed to get firmware revision for: %s", pnd->acName); pnd->pdc->disconnect(pnd); - return INVALID_DEVICE_INFO; + return NULL; } // Add the firmware revision to the device name, PN531 gives 2 bytes info, but PN532 gives 4 @@ -327,14 +327,14 @@ nfc_device_t* nfc_connect(nfc_device_desc_t* pndd) } // Reset the ending transmission bits register, it is unknown what the last tranmission used there - if (!pn53x_set_reg(pnd,REG_CIU_BIT_FRAMING,SYMBOL_TX_LAST_BITS,0x00)) return INVALID_DEVICE_INFO; + if (!pn53x_set_reg(pnd,REG_CIU_BIT_FRAMING,SYMBOL_TX_LAST_BITS,0x00)) return NULL; // Make sure we reset the CRC and parity to chip handling. - if (!nfc_configure(pnd,DCO_HANDLE_CRC,true)) return INVALID_DEVICE_INFO; - if (!nfc_configure(pnd,DCO_HANDLE_PARITY,true)) return INVALID_DEVICE_INFO; + if (!nfc_configure(pnd,NDO_HANDLE_CRC,true)) return NULL; + if (!nfc_configure(pnd,NDO_HANDLE_PARITY,true)) return NULL; // Deactivate the CRYPTO1 chiper, it may could cause problems when still active - if (!nfc_configure(pnd,DCO_ACTIVATE_CRYPTO1,false)) return INVALID_DEVICE_INFO; + if (!nfc_configure(pnd,NDO_ACTIVATE_CRYPTO1,false)) return NULL; return pnd; } else { @@ -342,7 +342,7 @@ nfc_device_t* nfc_connect(nfc_device_desc_t* pndd) } } // To bad, no reader is ready to be claimed - return INVALID_DEVICE_INFO; + return NULL; } void nfc_disconnect(nfc_device_t* pnd) @@ -353,7 +353,7 @@ void nfc_disconnect(nfc_device_t* pnd) pnd->pdc->disconnect(pnd); } -bool nfc_configure(nfc_device_t* pnd, const dev_config_option dco, const bool bEnable) +bool nfc_configure(nfc_device_t* pnd, const nfc_device_option_t dco, const bool bEnable) { byte_t btValue; byte_t abtCmd[sizeof(pncmd_rf_configure)]; @@ -364,7 +364,7 @@ bool nfc_configure(nfc_device_t* pnd, const dev_config_option dco, const bool bE switch(dco) { - case DCO_HANDLE_CRC: + case NDO_HANDLE_CRC: // Enable or disable automatic receiving/sending of CRC bytes // TX and RX are both represented by the symbol 0x80 btValue = (bEnable) ? 0x80 : 0x00; @@ -373,26 +373,26 @@ bool nfc_configure(nfc_device_t* pnd, const dev_config_option dco, const bool bE pnd->bCrc = bEnable; break; - case DCO_HANDLE_PARITY: + case NDO_HANDLE_PARITY: // Handle parity bit by PN53X chip or parse it as data bit btValue = (bEnable) ? 0x00 : SYMBOL_PARITY_DISABLE; if (!pn53x_set_reg(pnd,REG_CIU_MANUAL_RCV,SYMBOL_PARITY_DISABLE,btValue)) return false; pnd->bPar = bEnable; break; - case DCO_ACTIVATE_FIELD: + case NDO_ACTIVATE_FIELD: abtCmd[2] = RFCI_FIELD; abtCmd[3] = (bEnable) ? 1 : 0; // We can not use pn53x_transceive() because abtRx[0] gives no status info if (!pnd->pdc->transceive(pnd->nds,abtCmd,4,NULL,NULL)) return false; break; - case DCO_ACTIVATE_CRYPTO1: + case NDO_ACTIVATE_CRYPTO1: btValue = (bEnable) ? SYMBOL_MF_CRYPTO1_ON : 0x00; if (!pn53x_set_reg(pnd,REG_CIU_STATUS2,SYMBOL_MF_CRYPTO1_ON,btValue)) return false; break; - case DCO_INFINITE_SELECT: + case NDO_INFINITE_SELECT: // Retry format: 0x00 means only 1 try, 0xff means infinite abtCmd[2] = RFCI_RETRY_SELECT; abtCmd[3] = (bEnable) ? 0xff : 0x00; // MxRtyATR, default: active = 0xff, passive = 0x02 @@ -402,12 +402,12 @@ bool nfc_configure(nfc_device_t* pnd, const dev_config_option dco, const bool bE if (!pnd->pdc->transceive(pnd->nds,abtCmd,6,NULL,NULL)) return false; break; - case DCO_ACCEPT_INVALID_FRAMES: + case NDO_ACCEPT_INVALID_FRAMES: btValue = (bEnable) ? SYMBOL_RX_NO_ERROR : 0x00; if (!pn53x_set_reg(pnd,REG_CIU_RX_MODE,SYMBOL_RX_NO_ERROR,btValue)) return false; break; - case DCO_ACCEPT_MULTIPLE_FRAMES: + case NDO_ACCEPT_MULTIPLE_FRAMES: btValue = (bEnable) ? SYMBOL_RX_MULTIPLE : 0x00; if (!pn53x_set_reg(pnd,REG_CIU_RX_MODE,SYMBOL_RX_MULTIPLE,btValue)) return false; return true; @@ -830,8 +830,8 @@ bool nfc_target_init(const nfc_device_t* pnd, byte_t* pbtRx, size_t* pszRxBits) abtCmd[7] = 0x0b; // Make sure the CRC & parity are handled by the device, this is needed for target_init to work properly - if (!bCrc) nfc_configure((nfc_device_t*)pnd,DCO_HANDLE_CRC,true); - if (!bPar) nfc_configure((nfc_device_t*)pnd,DCO_HANDLE_PARITY,true); + if (!bCrc) nfc_configure((nfc_device_t*)pnd,NDO_HANDLE_CRC,true); + if (!bPar) nfc_configure((nfc_device_t*)pnd,NDO_HANDLE_PARITY,true); // Let the PN53X be activated by the RF level detector from power down mode if (!pn53x_set_reg(pnd,REG_CIU_TX_AUTO, SYMBOL_INITIAL_RF_ON,0x04)) return false; @@ -850,8 +850,8 @@ bool nfc_target_init(const nfc_device_t* pnd, byte_t* pbtRx, size_t* pszRxBits) memcpy(pbtRx,abtRx+1,szRxLen-1); // Restore the CRC & parity setting to the original value (if needed) - if (!bCrc) nfc_configure((nfc_device_t*)pnd,DCO_HANDLE_CRC,false); - if (!bPar) nfc_configure((nfc_device_t*)pnd,DCO_HANDLE_PARITY,false); + if (!bCrc) nfc_configure((nfc_device_t*)pnd,NDO_HANDLE_CRC,false); + if (!bPar) nfc_configure((nfc_device_t*)pnd,NDO_HANDLE_PARITY,false); return true; } diff --git a/src/lib/nfc.h b/src/lib/nfc.h index 20d9000..50de6f8 100644 --- a/src/lib/nfc.h +++ b/src/lib/nfc.h @@ -40,7 +40,7 @@ * @fn nfc_device_t* nfc_connect(nfc_device_desc_t* pndd) * @brief Connect to a NFC device * @param pndd Device description if specific device is wanted, NULL otherwise - * @return Returns pointer to a nfc_device_t struct if successfull; otherwise returns INVALID_DEVICE_INFO value. + * @return Returns pointer to a nfc_device_t struct if successfull; otherwise returns NULL value. * * If \a pndd is NULL, the first available NFC device is claimed by libnfc. * It will automatically search the system using all available drivers to determine a device is free. @@ -62,18 +62,18 @@ nfc_device_t* nfc_connect(nfc_device_desc_t* pndd); void nfc_disconnect(nfc_device_t* pnd); /** - * @fn nfc_configure(nfc_device_t* pnd, const dev_config_option dco, const bool bEnable) + * @fn nfc_configure(nfc_device_t* pnd, const nfc_device_option_t ndo, const bool bEnable) * @brief Configure advanced NFC device settings * @return Returns true if action was successfully performed; otherwise returns false. * @param pnd nfc_device_t struct pointer that represent currently used device - * @param dco dev_config_option struct that contains options to set to device + * @param ndo nfc_device_option_t struct that contains options to set to device * @param bEnable boolean * * Configures parameters and registers that control for example timing, modulation, frame and error handling. * There are different categories for configuring the PN53X chip features (handle, activate, infinite and accept). * These are defined to organize future settings that will become available when they are needed. */ -bool nfc_configure(nfc_device_t* pnd, const dev_config_option dco, const bool bEnable); +bool nfc_configure(nfc_device_t* pnd, const nfc_device_option_t ndo, const bool bEnable); /** * @fn nfc_initiator_init(const nfc_device_t* pnd) @@ -144,7 +144,7 @@ bool nfc_initiator_transceive_bits(const nfc_device_t* pnd, const byte_t* pbtTx, * @return Returns true if action was successfully performed; otherwise returns false. * * The reader will transmit the supplied bytes in pbtTx to the target (tag). It waits for the response and stores the received bytes in the pbtRx byte array. The parity bits are handled by the PN53X chip. The CRC can be generated automatically or handled manually. Using this function, frames can be communicated very fast via the NFC reader to the tag. Tests show that on average this way of communicating is much faster than using the regular driver/middle-ware (often supplied by manufacturers). - * @warning The configuration option DCO_HANDLE_PARITY must be set to true (the default value). + * @warning The configuration option NDO_HANDLE_PARITY must be set to true (the default value). */ bool nfc_initiator_transceive_bytes(const nfc_device_t* pnd, const byte_t* pbtTx, const size_t szTxLen, byte_t* pbtRx, size_t* pszRxLen); @@ -186,7 +186,7 @@ bool nfc_target_init(const nfc_device_t* pnd, byte_t* pbtRx, size_t* pszRxBits); * @brief Receive bit-frames * @return Returns true if action was successfully performed; otherwise returns false. * - * This function makes it possible to receive (raw) bit-frames. It returns all the messages that are stored in the FIFO buffer of the PN53X chip. It does not require to send any frame and thereby could be used to snoop frames that are transmitted by a nearby reader. Check out the DCO_ACCEPT_MULTIPLE_FRAMES configuration option to avoid losing transmitted frames. + * This function makes it possible to receive (raw) bit-frames. It returns all the messages that are stored in the FIFO buffer of the PN53X chip. It does not require to send any frame and thereby could be used to snoop frames that are transmitted by a nearby reader. Check out the NDO_ACCEPT_MULTIPLE_FRAMES configuration option to avoid losing transmitted frames. */ bool nfc_target_receive_bits(const nfc_device_t* pnd, byte_t* pbtRx, size_t* pszRxBits, byte_t* pbtRxPar);