diff --git a/src/examples/mifaretag.h b/src/examples/mifaretag.h index 3715fa3..741d89f 100644 --- a/src/examples/mifaretag.h +++ b/src/examples/mifaretag.h @@ -24,7 +24,7 @@ #ifndef _LIBNFC_MIFARE_TAG_H_ #define _LIBNFC_MIFARE_TAG_H_ -#include "defines.h" +#include "nfc-defines.h" typedef struct { byte_t abtUID[4]; diff --git a/src/examples/mifareultag.h b/src/examples/mifareultag.h index 454aa7d..0e953e8 100644 --- a/src/examples/mifareultag.h +++ b/src/examples/mifareultag.h @@ -24,7 +24,7 @@ #ifndef _LIBNFC_MIFARE_UL_TAG_H_ #define _LIBNFC_MIFARE_UL_TAG_H_ -#include "defines.h" +#include "nfc-defines.h" typedef struct { byte_t sn0[3]; diff --git a/src/examples/nfc-anticol.c b/src/examples/nfc-anticol.c index 048858a..a4e312c 100644 --- a/src/examples/nfc-anticol.c +++ b/src/examples/nfc-anticol.c @@ -30,7 +30,7 @@ #include -#include "messages.h" +#include "nfc-messages.h" #include "bitutils.h" #define SAK_FLAG_ATS_SUPPORTED 0x20 @@ -40,7 +40,7 @@ static size_t szRxBits; static size_t szRxLen; static byte_t abtUid[10]; static size_t szUidLen = 4; -static dev_info* pdi; +static nfc_device_t* pnd; bool quiet_output = false; @@ -61,7 +61,7 @@ bool transmit_bits(const byte_t* pbtTx, const size_t szTxBits) } // Transmit the bit frame command, we don't use the arbitrary parity feature - if (!nfc_initiator_transceive_bits(pdi,pbtTx,szTxBits,NULL,abtRx,&szRxBits,NULL)) return false; + if (!nfc_initiator_transceive_bits(pnd,pbtTx,szTxBits,NULL,abtRx,&szRxBits,NULL)) return false; // Show received answer if(!quiet_output) @@ -85,7 +85,7 @@ bool transmit_bytes(const byte_t* pbtTx, const size_t szTxLen) } // Transmit the command bytes - if (!nfc_initiator_transceive_bytes(pdi,pbtTx,szTxLen,abtRx,&szRxLen)) return false; + if (!nfc_initiator_transceive_bytes(pnd,pbtTx,szTxLen,abtRx,&szRxLen)) return false; // Show received answer if(!quiet_output) @@ -126,32 +126,32 @@ int main(int argc,char* argv[]) } // Try to open the NFC reader - pdi = nfc_connect(NULL); + pnd = nfc_connect(NULL); - if (!pdi) + if (!pnd) { printf("Error connecting NFC reader\n"); return 1; } - nfc_initiator_init(pdi); + nfc_initiator_init(pnd); // Drop the field for a while - nfc_configure(pdi,DCO_ACTIVATE_FIELD,false); + nfc_configure(pnd,DCO_ACTIVATE_FIELD,false); // Configure the CRC and Parity settings - nfc_configure(pdi,DCO_HANDLE_CRC,false); - nfc_configure(pdi,DCO_HANDLE_PARITY,true); + nfc_configure(pnd,DCO_HANDLE_CRC,false); + nfc_configure(pnd,DCO_HANDLE_PARITY,true); // Enable field so more power consuming cards can power themselves up - nfc_configure(pdi,DCO_ACTIVATE_FIELD,true); + nfc_configure(pnd,DCO_ACTIVATE_FIELD,true); - printf("\nConnected to NFC reader: %s\n\n",pdi->acName); + printf("\nConnected to NFC reader: %s\n\n",pnd->acName); // Send the 7 bits request command specified in ISO 14443A (0x26) if (!transmit_bits(abtReqa,7)) { printf("Error: No tag available\n"); - nfc_disconnect(pdi); + nfc_disconnect(pnd); return 1; } @@ -198,6 +198,6 @@ int main(int argc,char* argv[]) printf("%014llx\n",swap_endian64(abtUid)&0x00ffffffffffffffull); } - nfc_disconnect(pdi); + nfc_disconnect(pnd); return 0; } diff --git a/src/examples/nfc-emulate.c b/src/examples/nfc-emulate.c index 73d81d7..8198c31 100644 --- a/src/examples/nfc-emulate.c +++ b/src/examples/nfc-emulate.c @@ -29,12 +29,12 @@ #include -#include "messages.h" +#include "nfc-messages.h" #include "bitutils.h" static byte_t abtRecv[MAX_FRAME_LEN]; static size_t szRecvBits; -static dev_info* pdi; +static nfc_device_t* pnd; // ISO14443A Anti-Collision response byte_t abtAtqa [2] = { 0x04,0x00 }; @@ -85,20 +85,20 @@ int main(int argc, char *argv[]) } // Try to open the NFC reader - pdi = nfc_connect(NULL); + pnd = nfc_connect(NULL); - if (pdi == INVALID_DEVICE_INFO) + if (pnd == INVALID_DEVICE_INFO) { printf("Error connecting NFC reader\n"); return 1; } printf("\n"); - printf("[+] Connected to NFC reader: %s\n",pdi->acName); + printf("[+] Connected to NFC reader: %s\n",pnd->acName); printf("[+] Try to break out the auto-emulation, this requires a second reader!\n"); 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"); - if (!nfc_target_init(pdi,abtRecv,&szRecvBits)) + if (!nfc_target_init(pnd,abtRecv,&szRecvBits)) { printf("Error: Could not come out of auto-emulation, no command was received\n"); return 1; @@ -106,14 +106,14 @@ int main(int argc, char *argv[]) printf("[+] Received initiator command: "); print_hex_bits(abtRecv,szRecvBits); printf("[+] Configuring communication\n"); - nfc_configure(pdi,DCO_HANDLE_CRC,false); - nfc_configure(pdi,DCO_HANDLE_PARITY,true); + nfc_configure(pnd,DCO_HANDLE_CRC,false); + nfc_configure(pnd,DCO_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) { // Test if we received a frame - if (nfc_target_receive_bits(pdi,abtRecv,&szRecvBits,NULL)) + if (nfc_target_receive_bits(pnd,abtRecv,&szRecvBits,NULL)) { // Prepare the command to send back for the anti-collision request switch(szRecvBits) @@ -150,7 +150,7 @@ int main(int argc, char *argv[]) if(szTxBits) { // Send and print the command to the screen - nfc_target_send_bits(pdi,pbtTx,szTxBits,NULL); + nfc_target_send_bits(pnd,pbtTx,szTxBits,NULL); if(!quiet_output) { printf("T: "); @@ -160,6 +160,6 @@ int main(int argc, char *argv[]) } } - nfc_disconnect(pdi); + nfc_disconnect(pnd); } diff --git a/src/examples/nfc-list.c b/src/examples/nfc-list.c index 9e81d91..023ea58 100644 --- a/src/examples/nfc-list.c +++ b/src/examples/nfc-list.c @@ -29,10 +29,10 @@ #include -#include "messages.h" +#include "nfc-messages.h" #include "bitutils.h" -static dev_info* pdi; +static nfc_device_t* pnd; static byte_t abtFelica[5] = { 0x00, 0xff, 0xff, 0x00, 0x00 }; int main(int argc, const char* argv[]) @@ -40,7 +40,7 @@ int main(int argc, const char* argv[]) tag_info ti; // Try to open the NFC device - pdi = nfc_connect(NULL); + pnd = nfc_connect(NULL); // If specific device is wanted, i.e. an ARYGON device on /dev/ttyUSB0 /* @@ -49,33 +49,33 @@ int main(int argc, const char* argv[]) ndd.pcPort = "/dev/ttyUSB0"; ndd.uiSpeed = 115200; - pdi = nfc_connect(&ndd); + pnd = nfc_connect(&ndd); */ - if (pdi == INVALID_DEVICE_INFO) + if (pnd == INVALID_DEVICE_INFO) { ERR("Unable to connect to NFC device."); return 1; } - nfc_initiator_init(pdi); + nfc_initiator_init(pnd); // Drop the field for a while - nfc_configure(pdi,DCO_ACTIVATE_FIELD,false); + nfc_configure(pnd,DCO_ACTIVATE_FIELD,false); // Let the reader only try once to find a tag - nfc_configure(pdi,DCO_INFINITE_SELECT,false); + nfc_configure(pnd,DCO_INFINITE_SELECT,false); // Configure the CRC and Parity settings - nfc_configure(pdi,DCO_HANDLE_CRC,true); - nfc_configure(pdi,DCO_HANDLE_PARITY,true); + nfc_configure(pnd,DCO_HANDLE_CRC,true); + nfc_configure(pnd,DCO_HANDLE_PARITY,true); // Enable field so more power consuming cards can power themselves up - nfc_configure(pdi,DCO_ACTIVATE_FIELD,true); + nfc_configure(pnd,DCO_ACTIVATE_FIELD,true); - printf("Connected to NFC reader: %s\n\n",pdi->acName); + printf("Connected to NFC reader: %s\n\n",pnd->acName); // Poll for a ISO14443A (MIFARE) tag - if (nfc_initiator_select_tag(pdi,IM_ISO14443A_106,NULL,0,&ti)) + if (nfc_initiator_select_tag(pnd,IM_ISO14443A_106,NULL,0,&ti)) { printf("The following (NFC) ISO14443A tag was found:\n\n"); printf(" ATQA (SENS_RES): "); print_hex(ti.tia.abtAtqa,2); @@ -89,7 +89,7 @@ int main(int argc, const char* argv[]) } // Poll for a Felica tag - if (nfc_initiator_select_tag(pdi,IM_FELICA_212,abtFelica,5,&ti) || nfc_initiator_select_tag(pdi,IM_FELICA_424,abtFelica,5,&ti)) + if (nfc_initiator_select_tag(pnd,IM_FELICA_212,abtFelica,5,&ti) || nfc_initiator_select_tag(pnd,IM_FELICA_424,abtFelica,5,&ti)) { printf("The following (NFC) Felica tag was found:\n\n"); printf("%18s","ID (NFCID2): "); print_hex(ti.tif.abtId,8); @@ -97,7 +97,7 @@ int main(int argc, const char* argv[]) } // Poll for a ISO14443B tag - if (nfc_initiator_select_tag(pdi,IM_ISO14443B_106,(byte_t*)"\x00",1,&ti)) + if (nfc_initiator_select_tag(pnd,IM_ISO14443B_106,(byte_t*)"\x00",1,&ti)) { printf("The following (NFC) ISO14443-B tag was found:\n\n"); printf(" ATQB: "); print_hex(ti.tib.abtAtqb,12); @@ -111,12 +111,12 @@ int main(int argc, const char* argv[]) } // Poll for a Jewel tag - if (nfc_initiator_select_tag(pdi,IM_JEWEL_106,NULL,0,&ti)) + if (nfc_initiator_select_tag(pnd,IM_JEWEL_106,NULL,0,&ti)) { // No test results yet printf("jewel\n"); } - nfc_disconnect(pdi); + nfc_disconnect(pnd); return 1; } diff --git a/src/examples/nfc-mfclassic.c b/src/examples/nfc-mfclassic.c index 91910a2..a7d543a 100644 --- a/src/examples/nfc-mfclassic.c +++ b/src/examples/nfc-mfclassic.c @@ -35,7 +35,7 @@ #include "mifaretag.h" #include "bitutils.h" -static dev_info* pdi; +static nfc_device_t* pnd; static tag_info ti; static mifare_param mp; static mifare_tag mtKeys; @@ -99,7 +99,7 @@ bool authenticate(uint32_t uiBlock) } // Try to authenticate for the current sector - if (nfc_initiator_mifare_cmd(pdi,mc,uiBlock,&mp)) + if (nfc_initiator_mifare_cmd(pnd,mc,uiBlock,&mp)) return true; } @@ -115,7 +115,7 @@ bool authenticate(uint32_t uiBlock) for (key_index = 0; key_index < num_keys; key_index++) { memcpy(mp.mpa.abtKey, keys + (key_index*6), 6); - if (nfc_initiator_mifare_cmd(pdi, mc, uiBlock, &mp)) + if (nfc_initiator_mifare_cmd(pnd, mc, uiBlock, &mp)) { /** * @note: what about the other key? @@ -128,7 +128,7 @@ bool authenticate(uint32_t uiBlock) return true; } - nfc_initiator_select_tag(pdi, IM_ISO14443A_106, mp.mpa.abtUid, 4, NULL); + nfc_initiator_select_tag(pnd, IM_ISO14443A_106, mp.mpa.abtUid, 4, NULL); } } @@ -153,7 +153,7 @@ bool read_card() { printf("x"); // When a failure occured we need to redo the anti-collision - if (!nfc_initiator_select_tag(pdi,IM_ISO14443A_106,NULL,0,&ti)) + if (!nfc_initiator_select_tag(pnd,IM_ISO14443A_106,NULL,0,&ti)) { printf("!\nError: tag was removed\n"); return 1; @@ -176,7 +176,7 @@ bool read_card() } // Try to read out the trailer - if (nfc_initiator_mifare_cmd(pdi,MC_READ,iBlock,&mp)) + if (nfc_initiator_mifare_cmd(pnd,MC_READ,iBlock,&mp)) { // Copy the keys over from our key dump and store the retrieved access bits memcpy(mtDump.amb[iBlock].mbt.abtKeyA,mtKeys.amb[iBlock].mbt.abtKeyA,6); @@ -188,7 +188,7 @@ bool read_card() if (!bFailure) { // Try to read out the data block - if (nfc_initiator_mifare_cmd(pdi,MC_READ,iBlock,&mp)) + if (nfc_initiator_mifare_cmd(pnd,MC_READ,iBlock,&mp)) { memcpy(mtDump.amb[iBlock].mbd.abtData,mp.mpd.abtData,16); } else { @@ -221,7 +221,7 @@ bool write_card() { printf("x"); // When a failure occured we need to redo the anti-collision - if (!nfc_initiator_select_tag(pdi,IM_ISO14443A_106,NULL,0,&ti)) + if (!nfc_initiator_select_tag(pnd,IM_ISO14443A_106,NULL,0,&ti)) { printf("!\nError: tag was removed\n"); return false; @@ -252,7 +252,7 @@ bool write_card() memcpy(mp.mpd.abtData+10,mtDump.amb[uiBlock].mbt.abtKeyB,6); // Try to write the trailer - nfc_initiator_mifare_cmd(pdi,MC_WRITE,uiBlock,&mp); + nfc_initiator_mifare_cmd(pnd,MC_WRITE,uiBlock,&mp); } else { @@ -264,7 +264,7 @@ bool write_card() { // Try to write the data block memcpy(mp.mpd.abtData,mtDump.amb[uiBlock].mbd.abtData,16); - if (!nfc_initiator_mifare_cmd(pdi,MC_WRITE,uiBlock,&mp)) bFailure = true; + if (!nfc_initiator_mifare_cmd(pnd,MC_WRITE,uiBlock,&mp)) bFailure = true; } } } @@ -396,33 +396,33 @@ int main(int argc, const char* argv[]) // printf("Successfully opened required files\n"); // Try to open the NFC reader - pdi = nfc_connect(NULL); - if (pdi == INVALID_DEVICE_INFO) + pnd = nfc_connect(NULL); + if (pnd == INVALID_DEVICE_INFO) { printf("Error connecting NFC reader\n"); return 1; } - nfc_initiator_init(pdi); + nfc_initiator_init(pnd); // Drop the field for a while - nfc_configure(pdi,DCO_ACTIVATE_FIELD,false); + nfc_configure(pnd,DCO_ACTIVATE_FIELD,false); // Let the reader only try once to find a tag - nfc_configure(pdi,DCO_INFINITE_SELECT,false); - nfc_configure(pdi,DCO_HANDLE_CRC,true); - nfc_configure(pdi,DCO_HANDLE_PARITY,true); + nfc_configure(pnd,DCO_INFINITE_SELECT,false); + nfc_configure(pnd,DCO_HANDLE_CRC,true); + nfc_configure(pnd,DCO_HANDLE_PARITY,true); // Enable field so more power consuming cards can power themselves up - nfc_configure(pdi,DCO_ACTIVATE_FIELD,true); + nfc_configure(pnd,DCO_ACTIVATE_FIELD,true); - printf("Connected to NFC reader: %s\n",pdi->acName); + printf("Connected to NFC reader: %s\n",pnd->acName); // Try to find a MIFARE Classic tag - if (!nfc_initiator_select_tag(pdi,IM_ISO14443A_106,NULL,0,&ti)) + if (!nfc_initiator_select_tag(pnd,IM_ISO14443A_106,NULL,0,&ti)) { printf("Error: no tag was found\n"); - nfc_disconnect(pdi); + nfc_disconnect(pnd); return 1; } @@ -430,7 +430,7 @@ int main(int argc, const char* argv[]) if ((ti.tia.btSak & 0x08) == 0) { printf("Error: tag is not a MIFARE Classic card\n"); - nfc_disconnect(pdi); + nfc_disconnect(pnd); return 1; } @@ -476,7 +476,7 @@ int main(int argc, const char* argv[]) } } - nfc_disconnect(pdi); + nfc_disconnect(pnd); break; case ACTION_EXTRACT: { diff --git a/src/examples/nfc-mfultralight.c b/src/examples/nfc-mfultralight.c index 4940688..660fc28 100644 --- a/src/examples/nfc-mfultralight.c +++ b/src/examples/nfc-mfultralight.c @@ -35,7 +35,7 @@ #include "mifareultag.h" #include "bitutils.h" -static dev_info* pdi; +static nfc_device_t* pnd; static tag_info ti; static mifare_param mp; static mifareul_tag mtDump; @@ -48,7 +48,7 @@ bool read_card() // these are pages of 4 bytes each; we can read 4 pages at once. for (page = 0; page <= 0xF; page += 4){ // Try to read out the data block - if (nfc_initiator_mifare_cmd(pdi,MC_READ,page,&mp)) + if (nfc_initiator_mifare_cmd(pnd,MC_READ,page,&mp)) { memcpy(mtDump.amb[page / 4].mbd.abtData, mp.mpd.abtData, 16); } else { @@ -71,7 +71,7 @@ bool write_card() { printf("x"); // When a failure occured we need to redo the anti-collision - if (!nfc_initiator_select_tag(pdi,IM_ISO14443A_106,NULL,0,&ti)) + if (!nfc_initiator_select_tag(pnd,IM_ISO14443A_106,NULL,0,&ti)) { printf("!\nError: tag was removed\n"); return false; @@ -95,7 +95,7 @@ bool write_card() // writes one page at a time. uiBlock = page / 4; memcpy(mp.mpd.abtData, mtDump.amb[uiBlock].mbd.abtData + ((page % 4) * 4), 16); - if (!nfc_initiator_mifare_cmd(pdi, MC_WRITE, page, &mp)) bFailure = true; + if (!nfc_initiator_mifare_cmd(pnd, MC_WRITE, page, &mp)) bFailure = true; } } printf("%c|\n",(bFailure)?'x':'.'); @@ -148,33 +148,33 @@ int main(int argc, const char* argv[]) printf("Succesful opened the dump file\n"); // Try to open the NFC reader - pdi = nfc_connect(NULL); - if (pdi == INVALID_DEVICE_INFO) + pnd = nfc_connect(NULL); + if (pnd == INVALID_DEVICE_INFO) { printf("Error connecting NFC reader\n"); return 1; } - nfc_initiator_init(pdi); + nfc_initiator_init(pnd); // Drop the field for a while - nfc_configure(pdi,DCO_ACTIVATE_FIELD,false); + nfc_configure(pnd,DCO_ACTIVATE_FIELD,false); // Let the reader only try once to find a tag - nfc_configure(pdi,DCO_INFINITE_SELECT,false); - nfc_configure(pdi,DCO_HANDLE_CRC,true); - nfc_configure(pdi,DCO_HANDLE_PARITY,true); + nfc_configure(pnd,DCO_INFINITE_SELECT,false); + nfc_configure(pnd,DCO_HANDLE_CRC,true); + nfc_configure(pnd,DCO_HANDLE_PARITY,true); // Enable field so more power consuming cards can power themselves up - nfc_configure(pdi,DCO_ACTIVATE_FIELD,true); + nfc_configure(pnd,DCO_ACTIVATE_FIELD,true); - printf("Connected to NFC reader: %s\n",pdi->acName); + printf("Connected to NFC reader: %s\n",pnd->acName); // Try to find a MIFARE Ultralight tag - if (!nfc_initiator_select_tag(pdi,IM_ISO14443A_106,NULL,0,&ti)) + if (!nfc_initiator_select_tag(pnd,IM_ISO14443A_106,NULL,0,&ti)) { printf("Error: no tag was found\n"); - nfc_disconnect(pdi); + nfc_disconnect(pnd); return 1; } @@ -182,7 +182,7 @@ int main(int argc, const char* argv[]) if (ti.tia.abtAtqa[1] != 0x44){ printf("Error: tag is not a MIFARE Ultralight card\n"); - nfc_disconnect(pdi); + nfc_disconnect(pnd); return 1; } @@ -218,7 +218,7 @@ int main(int argc, const char* argv[]) } } - nfc_disconnect(pdi); + nfc_disconnect(pnd); return 0; } diff --git a/src/examples/nfc-relay.c b/src/examples/nfc-relay.c index 1a986f0..fba1eb0 100644 --- a/src/examples/nfc-relay.c +++ b/src/examples/nfc-relay.c @@ -28,7 +28,7 @@ #include -#include "messages.h" +#include "nfc-messages.h" #include "bitutils.h" static byte_t abtReaderRx[MAX_FRAME_LEN]; @@ -37,8 +37,8 @@ static size_t szReaderRxBits; static byte_t abtTagRx[MAX_FRAME_LEN]; static byte_t abtTagRxPar[MAX_FRAME_LEN]; static size_t szTagRxBits; -static dev_info* pdiReader; -static dev_info* pdiTag; +static nfc_device_t* pndReader; +static nfc_device_t* pndTag; void print_usage(char* argv[]) { @@ -69,8 +69,8 @@ int main(int argc,char* argv[]) } // Try to open the NFC emulator device - pdiTag = nfc_connect(NULL); - if (pdiTag == INVALID_DEVICE_INFO) + pndTag = nfc_connect(NULL); + if (pndTag == INVALID_DEVICE_INFO) { printf("Error connecting NFC emulator device\n"); return 1; @@ -81,35 +81,35 @@ int main(int argc,char* argv[]) printf("[+] Try to break out the auto-emulation, this requires a second reader!\n"); 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_init(pdiTag,abtReaderRx,&szReaderRxBits); + nfc_target_init(pndTag,abtReaderRx,&szReaderRxBits); printf("[+] Configuring emulator settings\n"); - nfc_configure(pdiTag,DCO_HANDLE_CRC,false); - nfc_configure(pdiTag,DCO_HANDLE_PARITY,false); - nfc_configure(pdiTag,DCO_ACCEPT_INVALID_FRAMES,true); + nfc_configure(pndTag,DCO_HANDLE_CRC,false); + nfc_configure(pndTag,DCO_HANDLE_PARITY,false); + nfc_configure(pndTag,DCO_ACCEPT_INVALID_FRAMES,true); printf("[+] Thank you, the emulated tag is initialized\n"); // Try to open the NFC reader - pdiReader = INVALID_DEVICE_INFO; - while (pdiReader == INVALID_DEVICE_INFO) pdiReader = nfc_connect(NULL); + pndReader = INVALID_DEVICE_INFO; + while (pndReader == INVALID_DEVICE_INFO) pndReader = nfc_connect(NULL); printf("[+] Configuring NFC reader settings\n"); - nfc_configure(pdiReader,DCO_HANDLE_CRC,false); - nfc_configure(pdiReader,DCO_HANDLE_PARITY,false); - nfc_configure(pdiReader,DCO_ACCEPT_INVALID_FRAMES,true); + nfc_configure(pndReader,DCO_HANDLE_CRC,false); + nfc_configure(pndReader,DCO_HANDLE_PARITY,false); + nfc_configure(pndReader,DCO_ACCEPT_INVALID_FRAMES,true); printf("[+] Done, relaying frames now!\n\n"); while(true) { // Test if we received a frame from the reader - if (nfc_target_receive_bits(pdiTag,abtReaderRx,&szReaderRxBits,abtReaderRxPar)) + if (nfc_target_receive_bits(pndTag,abtReaderRx,&szReaderRxBits,abtReaderRxPar)) { // Drop down the field before sending a REQA command and start a new session if (szReaderRxBits == 7 && abtReaderRx[0] == 0x26) { // Drop down field for a very short time (original tag will reboot) - nfc_configure(pdiReader,DCO_ACTIVATE_FIELD,false); + nfc_configure(pndReader,DCO_ACTIVATE_FIELD,false); if(!quiet_output) printf("\n"); - nfc_configure(pdiReader,DCO_ACTIVATE_FIELD,true); + nfc_configure(pndReader,DCO_ACTIVATE_FIELD,true); } // Print the reader frame to the screen @@ -119,10 +119,10 @@ int main(int argc,char* argv[]) print_hex_par(abtReaderRx,szReaderRxBits,abtReaderRxPar); } // Forward the frame to the original tag - if (nfc_initiator_transceive_bits(pdiReader,abtReaderRx,szReaderRxBits,abtReaderRxPar,abtTagRx,&szTagRxBits,abtTagRxPar)) + if (nfc_initiator_transceive_bits(pndReader,abtReaderRx,szReaderRxBits,abtReaderRxPar,abtTagRx,&szTagRxBits,abtTagRxPar)) { // Redirect the answer back to the reader - nfc_target_send_bits(pdiTag,abtTagRx,szTagRxBits,abtTagRxPar); + nfc_target_send_bits(pndTag,abtTagRx,szTagRxBits,abtTagRxPar); // Print the tag frame to the screen if(!quiet_output) @@ -134,6 +134,6 @@ int main(int argc,char* argv[]) } } - nfc_disconnect(pdiTag); - nfc_disconnect(pdiReader); + nfc_disconnect(pndTag); + nfc_disconnect(pndReader); } diff --git a/src/examples/nfcip-initiator.c b/src/examples/nfcip-initiator.c index 1721b8b..a1c0cb9 100644 --- a/src/examples/nfcip-initiator.c +++ b/src/examples/nfcip-initiator.c @@ -27,15 +27,15 @@ int main(int argc, const char *argv[]) { - dev_info *pdi; + nfc_device_t *pnd; tag_info ti; byte_t abtRecv[MAX_FRAME_LEN]; size_t szRecvBits; byte_t send[] = "Hello World!"; - pdi = nfc_connect(NULL); - if (!pdi || !nfc_initiator_init(pdi) - || !nfc_initiator_select_dep_target(pdi, IM_PASSIVE_DEP, NULL, 0, + pnd = nfc_connect(NULL); + if (!pnd || !nfc_initiator_init(pnd) + || !nfc_initiator_select_dep_target(pnd, IM_PASSIVE_DEP, NULL, 0, NULL, 0, NULL, 0, &ti)) { printf ("unable to connect, initialize, or select the target\n"); @@ -43,7 +43,7 @@ int main(int argc, const char *argv[]) } printf("Sending : %s\n", send); - if (!nfc_initiator_transceive_dep_bytes(pdi, + if (!nfc_initiator_transceive_dep_bytes(pnd, send, strlen((char*)send), abtRecv, &szRecvBits)) { @@ -54,7 +54,7 @@ int main(int argc, const char *argv[]) abtRecv[szRecvBits] = 0; printf("Received: %s\n", abtRecv); - nfc_initiator_deselect_tag(pdi); - nfc_disconnect(pdi); + nfc_initiator_deselect_tag(pnd); + nfc_disconnect(pnd); return 0; } diff --git a/src/examples/nfcip-target.c b/src/examples/nfcip-target.c index 86adf15..0c0bb3a 100644 --- a/src/examples/nfcip-target.c +++ b/src/examples/nfcip-target.c @@ -29,14 +29,14 @@ int main(int argc, const char *argv[]) byte_t abtRecv[MAX_FRAME_LEN]; size_t szRecvBits; byte_t send[] = "Hello Mars!"; - dev_info *pdi = nfc_connect(NULL); + nfc_device_t *pnd = nfc_connect(NULL); - if (!pdi || !nfc_target_init(pdi, abtRecv, &szRecvBits)) { + if (!pnd || !nfc_target_init(pnd, abtRecv, &szRecvBits)) { printf("unable to connect or initialize\n"); return 1; } - if (!nfc_target_receive_dep_bytes(pdi, abtRecv, &szRecvBits)) { + if (!nfc_target_receive_dep_bytes(pnd, abtRecv, &szRecvBits)) { printf("unable to receive data\n"); return 1; } @@ -44,11 +44,11 @@ int main(int argc, const char *argv[]) printf("Received: %s\n", abtRecv); printf("Sending : %s\n", send); - if (!nfc_target_send_dep_bytes(pdi, send, 11)) { + if (!nfc_target_send_dep_bytes(pnd, send, 11)) { printf("unable to send data\n"); return 1; } - nfc_disconnect(pdi); + nfc_disconnect(pnd); return 0; } diff --git a/src/lib/Makefile.am b/src/lib/Makefile.am index 3f2a750..a53eccf 100644 --- a/src/lib/Makefile.am +++ b/src/lib/Makefile.am @@ -3,7 +3,7 @@ SUBDIRS = buses drivers . # set the include path found by configure INCLUDES= $(all_includes) -nfcinclude_HEADERS = nfc.h defines.h types.h buses.h drivers.h messages.h bitutils.h +nfcinclude_HEADERS = nfc.h nfc-defines.h nfc-types.h buses.h drivers.h nfc-messages.h bitutils.h nfcincludedir = $(includedir)/nfc lib_LTLIBRARIES = libnfc.la diff --git a/src/lib/bitutils.h b/src/lib/bitutils.h index 98213f1..a34941e 100644 --- a/src/lib/bitutils.h +++ b/src/lib/bitutils.h @@ -26,7 +26,7 @@ #include -#include "types.h" +#include "nfc-types.h" byte_t oddparity(const byte_t bt); void oddparity_byte_ts(const byte_t* pbtData, const size_t szLen, byte_t* pbtPar); diff --git a/src/lib/buses.h b/src/lib/buses.h index 478d2e2..a5c7295 100644 --- a/src/lib/buses.h +++ b/src/lib/buses.h @@ -21,3 +21,5 @@ * @brief */ +#include "nfc-types.h" + diff --git a/src/lib/buses/uart.c b/src/lib/buses/uart.c index 66f7cdd..e862ccb 100644 --- a/src/lib/buses/uart.c +++ b/src/lib/buses/uart.c @@ -22,14 +22,13 @@ */ /* -Based on uart-code written by Teunis van Beelen available: +Based on RS232 code written by Teunis van Beelen available: http://www.teuniz.net/RS-232/index.html */ - #include "uart.h" -#include "messages.h" +#include "nfc-messages.h" // Test if we are dealing with unix operating systems #ifndef _WIN32 @@ -325,6 +324,13 @@ uint32_t uart_get_speed(const serial_port sp) return 0; } +bool uart_cts(const serial_port sp) +{ + char status; + if (ioctl(((serial_port_unix*)sp)->fd,TIOCMGET,&status) < 0) return false; + return (status & TIOCM_CTS); +} + bool uart_receive(const serial_port sp, byte_t* pbtRx, size_t* pszRxLen) { ReadFile(((serial_port_windows*)sp)->hPort,pbtRx,*pszRxLen,(LPDWORD)pszRxLen,NULL); @@ -338,4 +344,4 @@ bool uart_send(const serial_port sp, const byte_t* pbtTx, const size_t szTxLen) return (dwTxLen != 0); } -#endif +#endif /* _WIN32 */ diff --git a/src/lib/buses/uart.h b/src/lib/buses/uart.h index 373b659..f42b75c 100644 --- a/src/lib/buses/uart.h +++ b/src/lib/buses/uart.h @@ -21,14 +21,15 @@ * @brief */ -#ifndef _LIBNFC_RS232_H_ -#define _LIBNFC_RS232_H_ +#ifndef __NFC_BUS_UART_H__ +#define __NFC_BUS_UART_H__ #include #include #include -#include "defines.h" -#include "types.h" + +#include "nfc-defines.h" +#include "nfc-types.h" // Handle platform specific includes #ifndef _WIN32 @@ -58,6 +59,6 @@ uint32_t uart_get_speed(const serial_port sp); bool uart_receive(const serial_port sp, byte_t* pbtRx, size_t* pszRxLen); bool uart_send(const serial_port sp, const byte_t* pbtTx, const size_t szTxLen); -#endif // _LIBNFC_RS232_H_ +#endif // __NFC_BUS_UART_H__ diff --git a/src/lib/drivers.h b/src/lib/drivers.h index 8061f59..1b78aa0 100644 --- a/src/lib/drivers.h +++ b/src/lib/drivers.h @@ -24,8 +24,8 @@ #ifndef _LIBNFC_DEVICES_H_ #define _LIBNFC_DEVICES_H_ -#include "defines.h" -#include "types.h" +#include "nfc-defines.h" +#include "nfc-types.h" #ifdef HAVE_PCSC_LITE #include "drivers/acr122.h" #endif /* HAVE_PCSC_LITE */ diff --git a/src/lib/drivers/acr122.c b/src/lib/drivers/acr122.c index de1e720..145da14 100644 --- a/src/lib/drivers/acr122.c +++ b/src/lib/drivers/acr122.c @@ -33,8 +33,8 @@ #include #endif -#include "defines.h" -#include "messages.h" +#include "nfc-defines.h" +#include "nfc-messages.h" // WINDOWS: #define IOCTL_CCID_ESCAPE_SCARD_CTL_CODE SCARD_CTL_CODE(3500) #define IOCTL_CCID_ESCAPE_SCARD_CTL_CODE (((0x31) << 16) | ((3500) << 2)) @@ -57,7 +57,7 @@ typedef struct { SCARD_IO_REQUEST ioCard; } dev_spec_acr122; -dev_info* acr122_connect(const nfc_device_desc_t* pndd) +nfc_device_t* acr122_connect(const nfc_device_desc_t* pndd) { char* pacReaders[MAX_DEVICES]; char acList[256+64*MAX_DEVICES]; @@ -66,7 +66,7 @@ dev_info* acr122_connect(const nfc_device_desc_t* pndd) uint32_t uiReaderCount; uint32_t uiReader; uint32_t uiDevIndex; - dev_info* pdi; + nfc_device_t* pnd; dev_spec_acr122* pdsa; dev_spec_acr122 dsa; char* pcFirmware; @@ -130,7 +130,7 @@ dev_info* acr122_connect(const nfc_device_desc_t* pndd) dsa.ioCard.cbPciLength = sizeof(SCARD_IO_REQUEST); // Retrieve the current firmware version - pcFirmware = acr122_firmware((dev_info*)&dsa); + pcFirmware = acr122_firmware((nfc_device_t*)&dsa); if (strstr(pcFirmware,FIRMWARE_TEXT) != NULL) { // We found a occurence, test if it has the right index @@ -146,15 +146,15 @@ dev_info* acr122_connect(const nfc_device_desc_t* pndd) *pdsa = dsa; // Done, we found the reader we are looking for - pdi = malloc(sizeof(dev_info)); - strcpy(pdi->acName,pcFirmware); - pdi->ct = CT_PN532; - pdi->ds = (dev_spec)pdsa; - pdi->bActive = true; - pdi->bCrc = true; - pdi->bPar = true; - pdi->ui8TxBits = 0; - return pdi; + pnd = malloc(sizeof(nfc_device_t)); + strcpy(pnd->acName,pcFirmware); + pnd->ct = CT_PN532; + pnd->ds = (dev_spec)pdsa; + pnd->bActive = true; + pnd->bCrc = true; + pnd->bPar = true; + pnd->ui8TxBits = 0; + return pnd; } } @@ -162,13 +162,13 @@ dev_info* acr122_connect(const nfc_device_desc_t* pndd) return INVALID_DEVICE_INFO; } -void acr122_disconnect(dev_info* pdi) +void acr122_disconnect(nfc_device_t* pnd) { - dev_spec_acr122* pdsa = (dev_spec_acr122*)pdi->ds; + dev_spec_acr122* pdsa = (dev_spec_acr122*)pnd->ds; SCardDisconnect(pdsa->hCard,SCARD_LEAVE_CARD); SCardReleaseContext(pdsa->hCtx); free(pdsa); - free(pdi); + free(pnd); } bool acr122_transceive(const dev_spec ds, const byte_t* pbtTx, const size_t szTxLen, byte_t* pbtRx, size_t* pszRxLen) diff --git a/src/lib/drivers/acr122.h b/src/lib/drivers/acr122.h index 5c0826d..bdca283 100644 --- a/src/lib/drivers/acr122.h +++ b/src/lib/drivers/acr122.h @@ -27,12 +27,12 @@ #include #include -#include "defines.h" -#include "types.h" +#include "nfc-defines.h" +#include "nfc-types.h" // Functions used by developer to handle connection to this device -dev_info* acr122_connect(const nfc_device_desc_t* pndd); -void acr122_disconnect(dev_info* pdi); +nfc_device_t* acr122_connect(const nfc_device_desc_t* pndd); +void acr122_disconnect(nfc_device_t* pnd); // Callback function used by libnfc to transmit commands to the PN53X chip bool acr122_transceive(const dev_spec ds, const byte_t* pbtTx, const size_t szTxLen, byte_t* pbtRx, size_t* pszRxLen); diff --git a/src/lib/drivers/arygon.c b/src/lib/drivers/arygon.c index a9e4969..c25f4b7 100644 --- a/src/lib/drivers/arygon.c +++ b/src/lib/drivers/arygon.c @@ -24,7 +24,7 @@ #include "arygon.h" #include "uart.h" -#include "messages.h" +#include "nfc-messages.h" #ifdef _WIN32 #define SERIAL_STRING "COM" @@ -72,12 +72,12 @@ * @note ARYGON-APDB2UA33 (PN532 + ARYGON µC): 9600,n,8,1 */ -dev_info* arygon_connect(const nfc_device_desc_t* pndd) +nfc_device_t* arygon_connect(const nfc_device_desc_t* pndd) { uint32_t uiDevNr; serial_port sp; char acConnect[BUFFER_LENGTH]; - dev_info* pdi = INVALID_DEVICE_INFO; + nfc_device_t* pnd = INVALID_DEVICE_INFO; if( pndd == NULL ) { #ifdef DISABLE_SERIAL_AUTOPROBE @@ -122,21 +122,21 @@ dev_info* arygon_connect(const nfc_device_desc_t* pndd) DBG("Successfully connected to: %s",acConnect); // We have a connection - pdi = malloc(sizeof(dev_info)); - strcpy(pdi->acName,"ARYGON"); - pdi->ct = CT_PN532; - pdi->ds = (dev_spec)sp; - pdi->bActive = true; - pdi->bCrc = true; - pdi->bPar = true; - pdi->ui8TxBits = 0; - return pdi; + pnd = malloc(sizeof(nfc_device_t)); + strcpy(pnd->acName,"ARYGON"); + pnd->ct = CT_PN532; + pnd->ds = (dev_spec)sp; + pnd->bActive = true; + pnd->bCrc = true; + pnd->bPar = true; + pnd->ui8TxBits = 0; + return pnd; } -void arygon_disconnect(dev_info* pdi) +void arygon_disconnect(nfc_device_t* pnd) { - uart_close((serial_port)pdi->ds); - free(pdi); + uart_close((serial_port)pnd->ds); + free(pnd); } bool arygon_transceive(const dev_spec ds, const byte_t* pbtTx, const size_t szTxLen, byte_t* pbtRx, size_t* pszRxLen) diff --git a/src/lib/drivers/arygon.h b/src/lib/drivers/arygon.h index a489f38..e662a81 100644 --- a/src/lib/drivers/arygon.h +++ b/src/lib/drivers/arygon.h @@ -24,12 +24,12 @@ #ifndef _LIBNFC_DEV_ARYGON_H_ #define _LIBNFC_DEV_ARYGON_H_ -#include "defines.h" -#include "types.h" +#include "nfc-defines.h" +#include "nfc-types.h" // Functions used by developer to handle connection to this device -dev_info* arygon_connect(const nfc_device_desc_t* pndd); -void arygon_disconnect(dev_info* pdi); +nfc_device_t* arygon_connect(const nfc_device_desc_t* pndd); +void arygon_disconnect(nfc_device_t* pnd); // Callback function used by libnfc to transmit commands to the PN53X chip bool arygon_transceive(const dev_spec ds, const byte_t* pbtTx, const size_t szTxLen, byte_t* pbtRx, size_t* pszRxLen); diff --git a/src/lib/drivers/pn531.c b/src/lib/drivers/pn531_usb.c similarity index 91% rename from src/lib/drivers/pn531.c rename to src/lib/drivers/pn531_usb.c index 1bde5b0..833e48b 100644 --- a/src/lib/drivers/pn531.c +++ b/src/lib/drivers/pn531_usb.c @@ -31,9 +31,9 @@ Thanks to d18c7db and Okko for example code #include #include -#include "defines.h" +#include "nfc-defines.h" #include "pn531.h" -#include "messages.h" +#include "nfc-messages.h" #define BUFFER_LENGTH 256 #define USB_TIMEOUT 30000 @@ -80,7 +80,7 @@ static void get_end_points(struct usb_device *dev, dev_spec_pn531* pdsp) } } -dev_info* pn531_connect(const nfc_device_desc_t* pndd) +nfc_device_t* pn531_connect(const nfc_device_desc_t* pndd) { int idvendor = 0x04CC; int idproduct = 0x0531; @@ -88,7 +88,7 @@ dev_info* pn531_connect(const nfc_device_desc_t* pndd) int idproduct_alt = 0x0193; struct usb_bus *bus; struct usb_device *dev; - dev_info* pdi = INVALID_DEVICE_INFO; + nfc_device_t* pnd = INVALID_DEVICE_INFO; dev_spec_pn531* pdsp; dev_spec_pn531 dsp; uint32_t uiDevIndex; @@ -116,7 +116,7 @@ dev_info* pn531_connect(const nfc_device_desc_t* pndd) (idvendor_alt==dev->descriptor.idVendor && idproduct_alt==dev->descriptor.idProduct)) { // Make sure there are 2 endpoints available - if (dev->config->interface->altsetting->bNumEndpoints < 2) return pdi; + if (dev->config->interface->altsetting->bNumEndpoints < 2) return pnd; // Test if we are looking for this device according to the current index if (uiDevIndex != 0) @@ -147,28 +147,28 @@ dev_info* pn531_connect(const nfc_device_desc_t* pndd) // Allocate memory for the device info and specification, fill it and return the info pdsp = malloc(sizeof(dev_spec_pn531)); *pdsp = dsp; - pdi = malloc(sizeof(dev_info)); - strcpy(pdi->acName,"PN531USB"); - pdi->ct = CT_PN531; - pdi->ds = (dev_spec)pdsp; - pdi->bActive = true; - pdi->bCrc = true; - pdi->bPar = true; - pdi->ui8TxBits = 0; - return pdi; + pnd = malloc(sizeof(nfc_device_t)); + strcpy(pnd->acName,"PN531USB"); + pnd->ct = CT_PN531; + pnd->ds = (dev_spec)pdsp; + pnd->bActive = true; + pnd->bCrc = true; + pnd->bPar = true; + pnd->ui8TxBits = 0; + return pnd; } } } - return pdi; + return pnd; } -void pn531_disconnect(dev_info* pdi) +void pn531_disconnect(nfc_device_t* pnd) { - dev_spec_pn531* pdsp = (dev_spec_pn531*)pdi->ds; + dev_spec_pn531* pdsp = (dev_spec_pn531*)pnd->ds; usb_release_interface(pdsp->pudh,0); usb_close(pdsp->pudh); - free(pdi->ds); - free(pdi); + free(pnd->ds); + free(pnd); } bool pn531_transceive(const dev_spec ds, const byte_t* pbtTx, const size_t szTxLen, byte_t* pbtRx, size_t* pszRxLen) diff --git a/src/lib/drivers/pn531.h b/src/lib/drivers/pn531_usb.h similarity index 89% rename from src/lib/drivers/pn531.h rename to src/lib/drivers/pn531_usb.h index 9ad2490..34dbe36 100644 --- a/src/lib/drivers/pn531.h +++ b/src/lib/drivers/pn531_usb.h @@ -27,12 +27,12 @@ #include #include -#include "defines.h" -#include "types.h" +#include "nfc-defines.h" +#include "nfc-types.h" // Functions used by developer to handle connection to this device -dev_info* pn531_connect(const nfc_device_desc_t* pndd); -void pn531_disconnect(dev_info* pdi); +nfc_device_t* pn531_connect(const nfc_device_desc_t* pndd); +void pn531_disconnect(nfc_device_t* pnd); // Callback function used by libnfc to transmit commands to the PN53X chip bool pn531_transceive(const dev_spec ds, const byte_t* pbtTx, const size_t szTxLen, byte_t* pbtRx, size_t* pszRxLen); diff --git a/src/lib/drivers/pn532_uart.c b/src/lib/drivers/pn532_uart.c index 9f2db3f..e0f1876 100644 --- a/src/lib/drivers/pn532_uart.c +++ b/src/lib/drivers/pn532_uart.c @@ -24,7 +24,7 @@ #include "pn532_uart.h" #include "uart.h" -#include "messages.h" +#include "nfc-messages.h" #ifdef _WIN32 #define SERIAL_STRING "COM" @@ -47,12 +47,12 @@ #define SERIAL_DEFAULT_PORT_SPEED 115200 -dev_info* pn532_uart_connect(const nfc_device_desc_t* pndd) +nfc_device_t* pn532_uart_connect(const nfc_device_desc_t* pndd) { uint32_t uiDevNr; serial_port sp; char acConnect[BUFFER_LENGTH]; - dev_info* pdi = INVALID_DEVICE_INFO; + nfc_device_t* pnd = INVALID_DEVICE_INFO; if( pndd == NULL ) { #ifdef DISABLE_SERIAL_AUTOPROBE @@ -114,21 +114,21 @@ dev_info* pn532_uart_connect(const nfc_device_desc_t* pndd) DBG("Successfully connected to: %s",acConnect); // We have a connection - pdi = malloc(sizeof(dev_info)); - strcpy(pdi->acName,"PN532_UART"); - pdi->ct = CT_PN532; - pdi->ds = (dev_spec)sp; - pdi->bActive = true; - pdi->bCrc = true; - pdi->bPar = true; - pdi->ui8TxBits = 0; - return pdi; + pnd = malloc(sizeof(nfc_device_t)); + strcpy(pnd->acName,"PN532_UART"); + pnd->ct = CT_PN532; + pnd->ds = (dev_spec)sp; + pnd->bActive = true; + pnd->bCrc = true; + pnd->bPar = true; + pnd->ui8TxBits = 0; + return pnd; } -void pn532_uart_disconnect(dev_info* pdi) +void pn532_uart_disconnect(nfc_device_t* pnd) { - uart_close((serial_port)pdi->ds); - free(pdi); + uart_close((serial_port)pnd->ds); + free(pnd); } bool pn532_uart_transceive(const dev_spec ds, const byte_t* pbtTx, const size_t szTxLen, byte_t* pbtRx, size_t* pszRxLen) diff --git a/src/lib/drivers/pn532_uart.h b/src/lib/drivers/pn532_uart.h index d10e7c2..a8e4069 100644 --- a/src/lib/drivers/pn532_uart.h +++ b/src/lib/drivers/pn532_uart.h @@ -24,12 +24,12 @@ #ifndef _LIBNFC_DEV_PN532_UART_H_ #define _LIBNFC_DEV_PN532_UART_H_ -#include "defines.h" -#include "types.h" +#include "nfc-defines.h" +#include "nfc-types.h" // Functions used by developer to handle connection to this device -dev_info* pn532_uart_connect(const nfc_device_desc_t* pndd); -void pn532_uart_disconnect(dev_info* pdi); +nfc_device_t* pn532_uart_connect(const nfc_device_desc_t* pndd); +void pn532_uart_disconnect(nfc_device_t* pnd); // Callback function used by libnfc to transmit commands to the PN53X chip bool pn532_uart_transceive(const dev_spec ds, const byte_t* pbtTx, const size_t szTxLen, byte_t* pbtRx, size_t* pszRxLen); diff --git a/src/lib/drivers/pn533.c b/src/lib/drivers/pn533_usb.c similarity index 91% rename from src/lib/drivers/pn533.c rename to src/lib/drivers/pn533_usb.c index faf50d0..5cf599b 100644 --- a/src/lib/drivers/pn533.c +++ b/src/lib/drivers/pn533_usb.c @@ -30,8 +30,8 @@ Thanks to d18c7db and Okko for example code #include #include -#include "defines.h" -#include "messages.h" +#include "nfc-defines.h" +#include "nfc-messages.h" #define BUFFER_LENGTH 256 #define USB_TIMEOUT 30000 @@ -78,13 +78,13 @@ static void get_end_points(struct usb_device *dev, dev_spec_pn533* pdsp) } } -dev_info* pn533_connect(const nfc_device_desc_t* pndd) +nfc_device_t* pn533_connect(const nfc_device_desc_t* pndd) { int idvendor = 0x04e6; int idproduct = 0x5591; struct usb_bus *bus; struct usb_device *dev; - dev_info* pdi = INVALID_DEVICE_INFO; + nfc_device_t* pnd = INVALID_DEVICE_INFO; dev_spec_pn533* pdsp; dev_spec_pn533 dsp; uint32_t uiDevIndex; @@ -111,7 +111,7 @@ dev_info* pn533_connect(const nfc_device_desc_t* pndd) if (idvendor==dev->descriptor.idVendor && idproduct==dev->descriptor.idProduct) { // Make sure there are 2 endpoints available - if (dev->config->interface->altsetting->bNumEndpoints < 2) return pdi; + if (dev->config->interface->altsetting->bNumEndpoints < 2) return pnd; // Test if we are looking for this device according to the current index if (uiDevIndex != 0) @@ -142,28 +142,28 @@ dev_info* pn533_connect(const nfc_device_desc_t* pndd) // Allocate memory for the device info and specification, fill it and return the info pdsp = malloc(sizeof(dev_spec_pn533)); *pdsp = dsp; - pdi = malloc(sizeof(dev_info)); - strcpy(pdi->acName,"PN533USB"); - pdi->ct = CT_PN533; - pdi->ds = (dev_spec)pdsp; - pdi->bActive = true; - pdi->bCrc = true; - pdi->bPar = true; - pdi->ui8TxBits = 0; - return pdi; + pnd = malloc(sizeof(nfc_device_t)); + strcpy(pnd->acName,"PN533USB"); + pnd->ct = CT_PN533; + pnd->ds = (dev_spec)pdsp; + pnd->bActive = true; + pnd->bCrc = true; + pnd->bPar = true; + pnd->ui8TxBits = 0; + return pnd; } } } - return pdi; + return pnd; } -void pn533_disconnect(dev_info* pdi) +void pn533_disconnect(nfc_device_t* pnd) { - dev_spec_pn533* pdsp = (dev_spec_pn533*)pdi->ds; + dev_spec_pn533* pdsp = (dev_spec_pn533*)pnd->ds; usb_release_interface(pdsp->pudh,0); usb_close(pdsp->pudh); - free(pdi->ds); - free(pdi); + free(pnd->ds); + free(pnd); } bool pn533_transceive(const dev_spec ds, const byte_t* pbtTx, const size_t szTxLen, byte_t* pbtRx, size_t* pszRxLen) diff --git a/src/lib/drivers/pn533.h b/src/lib/drivers/pn533_usb.h similarity index 88% rename from src/lib/drivers/pn533.h rename to src/lib/drivers/pn533_usb.h index 0c18e36..860768f 100644 --- a/src/lib/drivers/pn533.h +++ b/src/lib/drivers/pn533_usb.h @@ -24,12 +24,12 @@ #ifndef _LIBNFC_DEV_PN533_H_ #define _LIBNFC_DEV_PN533_H_ -#include "defines.h" -#include "types.h" +#include "nfc-defines.h" +#include "nfc-types.h" // Functions used by developer to handle connection to this device -dev_info* pn533_connect(const nfc_device_desc_t* pndd); -void pn533_disconnect(dev_info* pdi); +nfc_device_t* pn533_connect(const nfc_device_desc_t* pndd); +void pn533_disconnect(nfc_device_t* pnd); // Callback function used by libnfc to transmit commands to the PN53X chip bool pn533_transceive(const dev_spec ds, const byte_t* pbtTx, const size_t szTxLen, byte_t* pbtRx, size_t* pszRxLen); diff --git a/src/lib/defines.h b/src/lib/nfc-defines.h similarity index 50% rename from src/lib/defines.h rename to src/lib/nfc-defines.h index b6f535b..9c6eafd 100644 --- a/src/lib/defines.h +++ b/src/lib/nfc-defines.h @@ -17,43 +17,18 @@ * along with this program. If not, see * * - * @file defines.h + * @file nfc-defines.h * @brief */ -#ifndef _LIBNFC_DEFINES_H_ -#define _LIBNFC_DEFINES_H_ +#ifndef __NFC_DEFINES_H__ +#define __NFC_DEFINES_H__ -//#define DEBUG /* DEBUG flag can also be enabled using ./configure --enable-debug */ +/* DEBUG flag can also be enabled using ./configure --enable-debug */ +/* #define DEBUG */ -typedef void* dev_spec; // Device connection specification #define INVALID_DEVICE_INFO 0 #define MAX_FRAME_LEN 264 -#define DEVICE_NAME_LENGTH 256 #define MAX_DEVICES 16 -#if defined __cplusplus - #define LIBNFC_EXTERN_C extern "C" -#else - #define LIBNFC_EXTERN_C -#endif - -#ifdef _WIN32 - #ifdef nfc_EXPORTS - #define LIBNFC_DECLSPEC __declspec( dllexport ) - #else - #define LIBNFC_DECLSPEC __declspec( dllimport ) - #endif -#else - #define LIBNFC_DECLSPEC -#endif - -#define LIBNFC_EXPORT LIBNFC_EXTERN_C LIBNFC_DECLSPEC - -//#define MIN(a,b) (((a) < (b)) ? (a) : (b)) -//#define MAX(a,b) (((a) > (b)) ? (a) : (b)) -#define INNER_XOR8(n) {n ^= (n >> 4); n ^= (n >> 2); n ^= (n >> 1); n &= 0x01; } -#define INNER_XOR32(n) {n ^= (n >> 16); n ^= (n >> 8); INNER_XOR8(n); } -#define INNER_XOR64(n) {n ^= (n >> 32); INNER_XOR32(n); } - #endif // _LIBNFC_DEFINES_H_ diff --git a/src/lib/messages.h b/src/lib/nfc-messages.h similarity index 100% rename from src/lib/messages.h rename to src/lib/nfc-messages.h diff --git a/src/lib/types.h b/src/lib/nfc-types.h similarity index 94% rename from src/lib/types.h rename to src/lib/nfc-types.h index 979f1bb..c56bf4a 100644 --- a/src/lib/types.h +++ b/src/lib/nfc-types.h @@ -17,12 +17,12 @@ * along with this program. If not, see * * - * @file types.h - * @brief + * @file nfc-types.h + * @brief Define NFC types */ -#ifndef _LIBNFC_TYPES_H_ -#define _LIBNFC_TYPES_H_ +#ifndef __NFC_TYPES_H__ +#define __NFC_TYPES_H__ /** * @file types.h @@ -34,8 +34,6 @@ #include #include -#include "defines.h" - typedef uint8_t byte_t; typedef enum { @@ -46,8 +44,11 @@ typedef enum { struct driver_callbacks; // Prototype the callback struct +typedef void* dev_spec; // Device connection specification + +#define DEVICE_NAME_LENGTH 256 /** - * @struct dev_info + * @struct nfc_device_t * @brief NFC device information */ typedef struct { @@ -67,7 +68,8 @@ typedef struct { bool bPar; /** The last tx bits setting, we need to reset this if it does not apply anymore */ uint8_t ui8TxBits; -} dev_info; +} nfc_device_t; + /** * @struct nfc_device_desc_t @@ -76,11 +78,11 @@ typedef struct { * This struct is used to try to connect to a specified nfc device when nfc_connect(...) */ typedef struct { - /** Driver name */ + /** Driver name (ie. PN532)*/ char* pcDriver; - /** Port (i.e. /dev/ttyUSB2) */ + /** Port (ie. /dev/ttyUSB0) */ char* pcPort; - /** Port speed (i.e. 115200) */ + /** Port speed (ie. 115200) */ uint32_t uiSpeed; /** Device index for backward compatibility (used to choose one specific device in USB or PSCS devices list) */ uint32_t uiIndex; @@ -88,17 +90,17 @@ typedef struct { /** * @struct driver_callbacks - * @brief NFC defice callbacks + * @brief Generic structure to handle NFC device functions. */ struct driver_callbacks { /** Driver name */ const char* acDriver; /** Connect callback */ - dev_info* (*connect)(const nfc_device_desc_t* pndd); + nfc_device_t* (*connect)(const nfc_device_desc_t* pndd); /** Transceive callback */ bool (*transceive)(const dev_spec ds, const byte_t* pbtTx, const size_t szTxLen, byte_t* pbtRx, size_t* pszRxLen); /** Disconnect callback */ - void (*disconnect)(dev_info* pdi); + void (*disconnect)(nfc_device_t* pnd); }; // Compiler directive, set struct alignment to 1 byte_t for compatibility diff --git a/src/lib/nfc.c b/src/lib/nfc.c index 9116b47..407cd13 100644 --- a/src/lib/nfc.c +++ b/src/lib/nfc.c @@ -29,7 +29,7 @@ #include "drivers.h" -#include "messages.h" +#include "nfc-messages.h" #include "../../config.h" @@ -101,7 +101,7 @@ const byte_t pncmd_target_receive [ 2] = { 0xD4,0x88 }; const byte_t pncmd_target_send [264] = { 0xD4,0x90 }; const byte_t pncmd_target_get_status [ 2] = { 0xD4,0x8A }; -bool pn53x_transceive(const dev_info* pdi, const byte_t* pbtTx, const size_t szTxLen, byte_t* pbtRx, size_t* pszRxLen) +bool pn53x_transceive(const nfc_device_t* pnd, const byte_t* pbtTx, const size_t szTxLen, byte_t* pbtRx, size_t* pszRxLen) { byte_t abtRx[MAX_FRAME_LEN]; size_t szRxLen; @@ -115,7 +115,7 @@ bool pn53x_transceive(const dev_info* pdi, const byte_t* pbtTx, const size_t szT *pszRxLen = MAX_FRAME_LEN; // Call the tranceive callback function of the current device - if (!pdi->pdc->transceive(pdi->ds,pbtTx,szTxLen,pbtRx,pszRxLen)) return false; + if (!pnd->pdc->transceive(pnd->ds,pbtTx,szTxLen,pbtRx,pszRxLen)) return false; // Make sure there was no failure reported by the PN53X chip (0x00 == OK) if (pbtRx[0] != 0) return false; @@ -124,7 +124,7 @@ bool pn53x_transceive(const dev_info* pdi, const byte_t* pbtTx, const size_t szT return true; } -byte_t pn53x_get_reg(const dev_info* pdi, uint16_t ui16Reg) +byte_t pn53x_get_reg(const nfc_device_t* pnd, uint16_t ui16Reg) { uint8_t ui8Value; size_t szValueLen = 1; @@ -134,42 +134,42 @@ byte_t pn53x_get_reg(const dev_info* pdi, uint16_t ui16Reg) abtCmd[2] = ui16Reg >> 8; abtCmd[3] = ui16Reg & 0xff; // We can not use pn53x_transceive() because abtRx[0] gives no status info - pdi->pdc->transceive(pdi->ds,abtCmd,4,&ui8Value,&szValueLen); + pnd->pdc->transceive(pnd->ds,abtCmd,4,&ui8Value,&szValueLen); return ui8Value; } -bool pn53x_set_reg(const dev_info* pdi, uint16_t ui16Reg, uint8_t ui8SybmolMask, uint8_t ui8Value) +bool pn53x_set_reg(const nfc_device_t* pnd, uint16_t ui16Reg, uint8_t ui8SybmolMask, uint8_t ui8Value) { byte_t abtCmd[sizeof(pncmd_set_register)]; memcpy(abtCmd,pncmd_set_register,sizeof(pncmd_set_register)); abtCmd[2] = ui16Reg >> 8; abtCmd[3] = ui16Reg & 0xff; - abtCmd[4] = ui8Value | (pn53x_get_reg(pdi,ui16Reg) & (~ui8SybmolMask)); + abtCmd[4] = ui8Value | (pn53x_get_reg(pnd,ui16Reg) & (~ui8SybmolMask)); // We can not use pn53x_transceive() because abtRx[0] gives no status info - return pdi->pdc->transceive(pdi->ds,abtCmd,5,NULL,NULL); + return pnd->pdc->transceive(pnd->ds,abtCmd,5,NULL,NULL); } -bool pn53x_set_parameters(const dev_info* pdi, uint8_t ui8Value) +bool pn53x_set_parameters(const nfc_device_t* pnd, uint8_t ui8Value) { byte_t abtCmd[sizeof(pncmd_set_parameters)]; memcpy(abtCmd,pncmd_set_parameters,sizeof(pncmd_set_parameters)); abtCmd[2] = ui8Value; // We can not use pn53x_transceive() because abtRx[0] gives no status info - return pdi->pdc->transceive(pdi->ds,abtCmd,3,NULL,NULL); + return pnd->pdc->transceive(pnd->ds,abtCmd,3,NULL,NULL); } -bool pn53x_set_tx_bits(const dev_info* pdi, uint8_t ui8Bits) +bool pn53x_set_tx_bits(const nfc_device_t* pnd, uint8_t ui8Bits) { // Test if we need to update the transmission bits register setting - if (pdi->ui8TxBits != ui8Bits) + if (pnd->ui8TxBits != ui8Bits) { // Set the amount of transmission bits in the PN53X chip register - if (!pn53x_set_reg(pdi,REG_CIU_BIT_FRAMING,SYMBOL_TX_LAST_BITS,ui8Bits)) return false; + if (!pn53x_set_reg(pnd,REG_CIU_BIT_FRAMING,SYMBOL_TX_LAST_BITS,ui8Bits)) return false; // Store the new setting - ((dev_info*)pdi)->ui8TxBits = ui8Bits; + ((nfc_device_t*)pnd)->ui8TxBits = ui8Bits; } return true; } @@ -276,9 +276,9 @@ bool pn53x_unwrap_frame(const byte_t* pbtFrame, const size_t szFrameBits, byte_t } } -dev_info* nfc_connect(nfc_device_desc_t* pndd) +nfc_device_t* nfc_connect(nfc_device_desc_t* pndd) { - dev_info* pdi; + nfc_device_t* pnd; uint32_t uiDev; byte_t abtFw[4]; size_t szFwLen = sizeof(abtFw); @@ -288,7 +288,7 @@ dev_info* nfc_connect(nfc_device_desc_t* pndd) { if (pndd == NULL) { // No device description specified: try to automatically claim a device - pdi = drivers_callbacks_list[uiDev].connect(pndd); + pnd = drivers_callbacks_list[uiDev].connect(pndd); } else { // Specific device is requested: using device description pndd if( 0 != strcmp(drivers_callbacks_list[uiDev].acDriver, pndd->pcDriver ) ) @@ -297,46 +297,46 @@ dev_info* nfc_connect(nfc_device_desc_t* pndd) continue; } else { DBG("Looking for %s, found %s... Use it.", pndd->pcDriver, drivers_callbacks_list[uiDev].acDriver); - pdi = drivers_callbacks_list[uiDev].connect(pndd); + pnd = drivers_callbacks_list[uiDev].connect(pndd); } } // Test if the connection was successful - if (pdi != INVALID_DEVICE_INFO) + if (pnd != INVALID_DEVICE_INFO) { - DBG("[%s] has been claimed.", pdi->acName); + DBG("[%s] has been claimed.", pnd->acName); // Great we have claimed a device - pdi->pdc = &(drivers_callbacks_list[uiDev]); + pnd->pdc = &(drivers_callbacks_list[uiDev]); // Try to retrieve PN53x chip revision // We can not use pn53x_transceive() because abtRx[0] gives no status info - if (!pdi->pdc->transceive(pdi->ds,pncmd_get_firmware_version,2,abtFw,&szFwLen)) + if (!pnd->pdc->transceive(pnd->ds,pncmd_get_firmware_version,2,abtFw,&szFwLen)) { // Failed to get firmware revision??, whatever...let's disconnect and clean up and return err - ERR("Failed to get firmware revision for: %s", pdi->acName); - pdi->pdc->disconnect(pdi); + ERR("Failed to get firmware revision for: %s", pnd->acName); + pnd->pdc->disconnect(pnd); return INVALID_DEVICE_INFO; } // Add the firmware revision to the device name, PN531 gives 2 bytes info, but PN532 gives 4 - switch(pdi->ct) + switch(pnd->ct) { - case CT_PN531: sprintf(pdi->acName,"%s - PN531 v%d.%d",pdi->acName,abtFw[0],abtFw[1]); break; - case CT_PN532: sprintf(pdi->acName,"%s - PN532 v%d.%d (0x%02x)",pdi->acName,abtFw[1],abtFw[2],abtFw[3]); break; - case CT_PN533: sprintf(pdi->acName,"%s - PN533 v%d.%d (0x%02x)",pdi->acName,abtFw[1],abtFw[2],abtFw[3]); break; + case CT_PN531: sprintf(pnd->acName,"%s - PN531 v%d.%d",pnd->acName,abtFw[0],abtFw[1]); break; + case CT_PN532: sprintf(pnd->acName,"%s - PN532 v%d.%d (0x%02x)",pnd->acName,abtFw[1],abtFw[2],abtFw[3]); break; + case CT_PN533: sprintf(pnd->acName,"%s - PN533 v%d.%d (0x%02x)",pnd->acName,abtFw[1],abtFw[2],abtFw[3]); break; } // Reset the ending transmission bits register, it is unknown what the last tranmission used there - if (!pn53x_set_reg(pdi,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 INVALID_DEVICE_INFO; // Make sure we reset the CRC and parity to chip handling. - if (!nfc_configure(pdi,DCO_HANDLE_CRC,true)) return INVALID_DEVICE_INFO; - if (!nfc_configure(pdi,DCO_HANDLE_PARITY,true)) return INVALID_DEVICE_INFO; + if (!nfc_configure(pnd,DCO_HANDLE_CRC,true)) return INVALID_DEVICE_INFO; + if (!nfc_configure(pnd,DCO_HANDLE_PARITY,true)) return INVALID_DEVICE_INFO; // Deactivate the CRYPTO1 chiper, it may could cause problems when still active - if (!nfc_configure(pdi,DCO_ACTIVATE_CRYPTO1,false)) return INVALID_DEVICE_INFO; + if (!nfc_configure(pnd,DCO_ACTIVATE_CRYPTO1,false)) return INVALID_DEVICE_INFO; - return pdi; + return pnd; } else { DBG("No device found using driver: %s", drivers_callbacks_list[uiDev].acDriver); } @@ -345,22 +345,22 @@ dev_info* nfc_connect(nfc_device_desc_t* pndd) return INVALID_DEVICE_INFO; } -void nfc_disconnect(dev_info* pdi) +void nfc_disconnect(nfc_device_t* pnd) { // Release and deselect all active communications - nfc_initiator_deselect_tag(pdi); + nfc_initiator_deselect_tag(pnd); // Disconnect, clean up and release the device - pdi->pdc->disconnect(pdi); + pnd->pdc->disconnect(pnd); } -bool nfc_configure(dev_info* pdi, const dev_config_option dco, const bool bEnable) +bool nfc_configure(nfc_device_t* pnd, const dev_config_option dco, const bool bEnable) { byte_t btValue; byte_t abtCmd[sizeof(pncmd_rf_configure)]; memcpy(abtCmd,pncmd_rf_configure,sizeof(pncmd_rf_configure)); // Make sure we are dealing with a active device - if (!pdi->bActive) return false; + if (!pnd->bActive) return false; switch(dco) { @@ -368,28 +368,28 @@ bool nfc_configure(dev_info* pdi, const dev_config_option dco, const bool bEnabl // Enable or disable automatic receiving/sending of CRC bytes // TX and RX are both represented by the symbol 0x80 btValue = (bEnable) ? 0x80 : 0x00; - if (!pn53x_set_reg(pdi,REG_CIU_TX_MODE,SYMBOL_TX_CRC_ENABLE,btValue)) return false; - if (!pn53x_set_reg(pdi,REG_CIU_RX_MODE,SYMBOL_RX_CRC_ENABLE,btValue)) return false; - pdi->bCrc = bEnable; + if (!pn53x_set_reg(pnd,REG_CIU_TX_MODE,SYMBOL_TX_CRC_ENABLE,btValue)) return false; + if (!pn53x_set_reg(pnd,REG_CIU_RX_MODE,SYMBOL_RX_CRC_ENABLE,btValue)) return false; + pnd->bCrc = bEnable; break; case DCO_HANDLE_PARITY: // Handle parity bit by PN53X chip or parse it as data bit btValue = (bEnable) ? 0x00 : SYMBOL_PARITY_DISABLE; - if (!pn53x_set_reg(pdi,REG_CIU_MANUAL_RCV,SYMBOL_PARITY_DISABLE,btValue)) return false; - pdi->bPar = bEnable; + if (!pn53x_set_reg(pnd,REG_CIU_MANUAL_RCV,SYMBOL_PARITY_DISABLE,btValue)) return false; + pnd->bPar = bEnable; break; case DCO_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 (!pdi->pdc->transceive(pdi->ds,abtCmd,4,NULL,NULL)) return false; + if (!pnd->pdc->transceive(pnd->ds,abtCmd,4,NULL,NULL)) return false; break; case DCO_ACTIVATE_CRYPTO1: btValue = (bEnable) ? SYMBOL_MF_CRYPTO1_ON : 0x00; - if (!pn53x_set_reg(pdi,REG_CIU_STATUS2,SYMBOL_MF_CRYPTO1_ON,btValue)) return false; + if (!pn53x_set_reg(pnd,REG_CIU_STATUS2,SYMBOL_MF_CRYPTO1_ON,btValue)) return false; break; case DCO_INFINITE_SELECT: @@ -399,17 +399,17 @@ bool nfc_configure(dev_info* pdi, const dev_config_option dco, const bool bEnabl abtCmd[4] = (bEnable) ? 0xff : 0x00; // MxRtyPSL, default: 0x01 abtCmd[5] = (bEnable) ? 0xff : 0x00; // MxRtyPassiveActivation, default: 0xff // We can not use pn53x_transceive() because abtRx[0] gives no status info - if (!pdi->pdc->transceive(pdi->ds,abtCmd,6,NULL,NULL)) return false; + if (!pnd->pdc->transceive(pnd->ds,abtCmd,6,NULL,NULL)) return false; break; case DCO_ACCEPT_INVALID_FRAMES: btValue = (bEnable) ? SYMBOL_RX_NO_ERROR : 0x00; - if (!pn53x_set_reg(pdi,REG_CIU_RX_MODE,SYMBOL_RX_NO_ERROR,btValue)) return false; + if (!pn53x_set_reg(pnd,REG_CIU_RX_MODE,SYMBOL_RX_NO_ERROR,btValue)) return false; break; case DCO_ACCEPT_MULTIPLE_FRAMES: btValue = (bEnable) ? SYMBOL_RX_MULTIPLE : 0x00; - if (!pn53x_set_reg(pdi,REG_CIU_RX_MODE,SYMBOL_RX_MULTIPLE,btValue)) return false; + if (!pn53x_set_reg(pnd,REG_CIU_RX_MODE,SYMBOL_RX_MULTIPLE,btValue)) return false; return true; break; @@ -419,21 +419,21 @@ bool nfc_configure(dev_info* pdi, const dev_config_option dco, const bool bEnabl return true; } -bool nfc_initiator_init(const dev_info* pdi) +bool nfc_initiator_init(const nfc_device_t* pnd) { // Make sure we are dealing with a active device - if (!pdi->bActive) return false; + if (!pnd->bActive) return false; // Set the PN53X to force 100% ASK Modified miller decoding (default for 14443A cards) - if (!pn53x_set_reg(pdi,REG_CIU_TX_AUTO,SYMBOL_FORCE_100_ASK,0x40)) return false; + if (!pn53x_set_reg(pnd,REG_CIU_TX_AUTO,SYMBOL_FORCE_100_ASK,0x40)) return false; // Configure the PN53X to be an Initiator or Reader/Writer - if (!pn53x_set_reg(pdi,REG_CIU_CONTROL,SYMBOL_INITIATOR,0x10)) return false; + if (!pn53x_set_reg(pnd,REG_CIU_CONTROL,SYMBOL_INITIATOR,0x10)) return false; return true; } -bool nfc_initiator_select_dep_target(const dev_info* pdi, const init_modulation im, const byte_t* pbtPidData, const size_t szPidDataLen, const byte_t* pbtNFCID3i, const size_t szNFCID3iDataLen, const byte_t *pbtGbData, const size_t szGbDataLen, tag_info* pti) +bool nfc_initiator_select_dep_target(const nfc_device_t* pnd, const init_modulation im, const byte_t* pbtPidData, const size_t szPidDataLen, const byte_t* pbtNFCID3i, const size_t szNFCID3iDataLen, const byte_t *pbtGbData, const size_t szGbDataLen, tag_info* pti) { byte_t abtRx[MAX_FRAME_LEN]; size_t szRxLen; @@ -466,7 +466,7 @@ bool nfc_initiator_select_dep_target(const dev_info* pdi, const init_modulation } // Try to find a target, call the transceive callback function of the current device - if (!pn53x_transceive(pdi,abtCmd,5+szPidDataLen+szNFCID3iDataLen+szGbDataLen,abtRx,&szRxLen)) return false; + if (!pn53x_transceive(pnd,abtCmd,5+szPidDataLen+szNFCID3iDataLen+szGbDataLen,abtRx,&szRxLen)) return false; // Make sure one target has been found, the PN53X returns 0x00 if none was available if (abtRx[1] != 1) return false; @@ -482,7 +482,7 @@ bool nfc_initiator_select_dep_target(const dev_info* pdi, const init_modulation return true; } -bool nfc_initiator_select_tag(const dev_info* pdi, const init_modulation im, const byte_t* pbtInitData, const size_t szInitDataLen, tag_info* pti) +bool nfc_initiator_select_tag(const nfc_device_t* pnd, const init_modulation im, const byte_t* pbtInitData, const size_t szInitDataLen, tag_info* pti) { byte_t abtInit[MAX_FRAME_LEN]; size_t szInitLen; @@ -492,7 +492,7 @@ bool nfc_initiator_select_tag(const dev_info* pdi, const init_modulation im, con memcpy(abtCmd,pncmd_initiator_list_passive,sizeof(pncmd_initiator_list_passive)); // Make sure we are dealing with a active device - if (!pdi->bActive) return false; + if (!pnd->bActive) return false; abtCmd[2] = 1; // MaxTg, we only want to select 1 tag at the time abtCmd[3] = im; // BrTy, the type of init modulation used for polling a passive tag @@ -536,7 +536,7 @@ bool nfc_initiator_select_tag(const dev_info* pdi, const init_modulation im, con // Try to find a tag, call the tranceive callback function of the current device szRxLen = MAX_FRAME_LEN; // We can not use pn53x_transceive() because abtRx[0] gives no status info - if (!pdi->pdc->transceive(pdi->ds,abtCmd,4+szInitLen,abtRx,&szRxLen)) return false; + if (!pnd->pdc->transceive(pnd->ds,abtCmd,4+szInitLen,abtRx,&szRxLen)) return false; // Make sure one tag has been found, the PN53X returns 0x00 if none was available if (abtRx[0] != 1) return false; @@ -549,7 +549,7 @@ bool nfc_initiator_select_tag(const dev_info* pdi, const init_modulation im, con { case IM_ISO14443A_106: // Somehow they switched the lower and upper ATQA bytes around for the PN531 chipset - if (pdi->ct == CT_PN531) + if (pnd->ct == CT_PN531) { pti->tia.abtAtqa[0] = abtRx[3]; pti->tia.abtAtqa[1] = abtRx[2]; @@ -619,12 +619,12 @@ bool nfc_initiator_select_tag(const dev_info* pdi, const init_modulation im, con return true; } -bool nfc_initiator_deselect_tag(const dev_info* pdi) +bool nfc_initiator_deselect_tag(const nfc_device_t* pnd) { - return (pn53x_transceive(pdi,pncmd_initiator_deselect,3,NULL,NULL)); + return (pn53x_transceive(pnd,pncmd_initiator_deselect,3,NULL,NULL)); } -bool nfc_initiator_transceive_bits(const dev_info* pdi, const byte_t* pbtTx, const size_t szTxBits, const byte_t* pbtTxPar, byte_t* pbtRx, size_t* pszRxBits, byte_t* pbtRxPar) +bool nfc_initiator_transceive_bits(const 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) { byte_t abtRx[MAX_FRAME_LEN]; size_t szRxLen; @@ -635,7 +635,7 @@ bool nfc_initiator_transceive_bits(const dev_info* pdi, const byte_t* pbtTx, con memcpy(abtCmd,pncmd_initiator_exchange_raw_data,sizeof(pncmd_initiator_exchange_raw_data)); // Check if we should prepare the parity bits ourself - if (!pdi->bPar) + if (!pnd->bPar) { // Convert data with parity to a frame pn53x_wrap_frame(pbtTx,szTxBits,pbtTxPar,abtCmd+2,&szFrameBits); @@ -650,24 +650,24 @@ bool nfc_initiator_transceive_bits(const dev_info* pdi, const byte_t* pbtTx, con szFrameBytes = (szFrameBits/8)+((ui8Bits==0)?0:1); // When the parity is handled before us, we just copy the data - if (pdi->bPar) memcpy(abtCmd+2,pbtTx,szFrameBytes); + if (pnd->bPar) memcpy(abtCmd+2,pbtTx,szFrameBytes); // Set the amount of transmission bits in the PN53X chip register - if (!pn53x_set_tx_bits(pdi,ui8Bits)) return false; + if (!pn53x_set_tx_bits(pnd,ui8Bits)) return false; // Send the frame to the PN53X chip and get the answer // We have to give the amount of bytes + (the two command bytes 0xD4, 0x42) - if (!pn53x_transceive(pdi,abtCmd,szFrameBytes+2,abtRx,&szRxLen)) return false; + if (!pn53x_transceive(pnd,abtCmd,szFrameBytes+2,abtRx,&szRxLen)) return false; // Get the last bit-count that is stored in the received byte - ui8Bits = pn53x_get_reg(pdi,REG_CIU_CONTROL) & SYMBOL_RX_LAST_BITS; + ui8Bits = pn53x_get_reg(pnd,REG_CIU_CONTROL) & SYMBOL_RX_LAST_BITS; // Recover the real frame length in bits szFrameBits = ((szRxLen-1-((ui8Bits==0)?0:1))*8)+ui8Bits; // Ignore the status byte from the PN53X here, it was checked earlier in pn53x_transceive() // Check if we should recover the parity bits ourself - if (!pdi->bPar) + if (!pnd->bPar) { // Unwrap the response frame pn53x_unwrap_frame(abtRx+1,szFrameBits,pbtRx,pszRxBits,pbtRxPar); @@ -682,7 +682,7 @@ bool nfc_initiator_transceive_bits(const dev_info* pdi, const byte_t* pbtTx, con return true; } -bool nfc_initiator_transceive_dep_bytes(const dev_info* pdi, const byte_t* pbtTx, const size_t szTxLen, byte_t* pbtRx, size_t* pszRxLen) +bool nfc_initiator_transceive_dep_bytes(const nfc_device_t* pnd, const byte_t* pbtTx, const size_t szTxLen, byte_t* pbtRx, size_t* pszRxLen) { byte_t abtRx[MAX_FRAME_LEN]; size_t szRxLen; @@ -690,18 +690,18 @@ bool nfc_initiator_transceive_dep_bytes(const dev_info* pdi, const byte_t* pbtTx memcpy(abtCmd,pncmd_initiator_exchange_data,sizeof(pncmd_initiator_exchange_data)); // We can not just send bytes without parity if while the PN53X expects we handled them - if (!pdi->bPar) return false; + if (!pnd->bPar) return false; // Copy the data into the command frame abtCmd[2] = 1; /* target number */ memcpy(abtCmd+3,pbtTx,szTxLen); // To transfer command frames bytes we can not have any leading bits, reset this to zero - if (!pn53x_set_tx_bits(pdi,0)) return false; + if (!pn53x_set_tx_bits(pnd,0)) return false; // Send the frame to the PN53X chip and get the answer // We have to give the amount of bytes + (the two command bytes 0xD4, 0x42) - if (!pn53x_transceive(pdi,abtCmd,szTxLen+3,abtRx,&szRxLen)) return false; + if (!pn53x_transceive(pnd,abtCmd,szTxLen+3,abtRx,&szRxLen)) return false; // Save the received byte count *pszRxLen = szRxLen-1; @@ -713,7 +713,7 @@ bool nfc_initiator_transceive_dep_bytes(const dev_info* pdi, const byte_t* pbtTx return true; } -bool nfc_initiator_transceive_bytes(const dev_info* pdi, const byte_t* pbtTx, const size_t szTxLen, byte_t* pbtRx, size_t* pszRxLen) +bool nfc_initiator_transceive_bytes(const nfc_device_t* pnd, const byte_t* pbtTx, const size_t szTxLen, byte_t* pbtRx, size_t* pszRxLen) { byte_t abtRx[MAX_FRAME_LEN]; size_t szRxLen; @@ -721,17 +721,17 @@ bool nfc_initiator_transceive_bytes(const dev_info* pdi, const byte_t* pbtTx, co memcpy(abtCmd,pncmd_initiator_exchange_raw_data,sizeof(pncmd_initiator_exchange_raw_data)); // We can not just send bytes without parity if while the PN53X expects we handled them - if (!pdi->bPar) return false; + if (!pnd->bPar) return false; // Copy the data into the command frame memcpy(abtCmd+2,pbtTx,szTxLen); // To transfer command frames bytes we can not have any leading bits, reset this to zero - if (!pn53x_set_tx_bits(pdi,0)) return false; + if (!pn53x_set_tx_bits(pnd,0)) return false; // Send the frame to the PN53X chip and get the answer // We have to give the amount of bytes + (the two command bytes 0xD4, 0x42) - if (!pn53x_transceive(pdi,abtCmd,szTxLen+2,abtRx,&szRxLen)) return false; + if (!pn53x_transceive(pnd,abtCmd,szTxLen+2,abtRx,&szRxLen)) return false; // Save the received byte count *pszRxLen = szRxLen-1; @@ -743,7 +743,7 @@ bool nfc_initiator_transceive_bytes(const dev_info* pdi, const byte_t* pbtTx, co return true; } -bool nfc_initiator_mifare_cmd(const dev_info* pdi, const mifare_cmd mc, const uint8_t ui8Block, mifare_param* pmp) +bool nfc_initiator_mifare_cmd(const nfc_device_t* pnd, const mifare_cmd mc, const uint8_t ui8Block, mifare_param* pmp) { byte_t abtRx[MAX_FRAME_LEN]; size_t szRxLen; @@ -752,7 +752,7 @@ bool nfc_initiator_mifare_cmd(const dev_info* pdi, const mifare_cmd mc, const ui memcpy(abtCmd,pncmd_initiator_exchange_data,sizeof(pncmd_initiator_exchange_data)); // Make sure we are dealing with a active device - if (!pdi->bActive) return false; + if (!pnd->bActive) return false; abtCmd[2] = 0x01; // Use first target/card abtCmd[3] = mc; // The MIFARE Classic command @@ -794,7 +794,7 @@ bool nfc_initiator_mifare_cmd(const dev_info* pdi, const mifare_cmd mc, const ui if (szParamLen) memcpy(abtCmd+5,(byte_t*)pmp,szParamLen); // Fire the mifare command - if (!pn53x_transceive(pdi,abtCmd,5+szParamLen,abtRx,&szRxLen)) return false; + if (!pn53x_transceive(pnd,abtCmd,5+szParamLen,abtRx,&szRxLen)) return false; // When we have executed a read command, copy the received bytes into the param if (mc == MC_READ && szRxLen == 17) memcpy(pmp->mpd.abtData,abtRx+1,16); @@ -803,14 +803,14 @@ bool nfc_initiator_mifare_cmd(const dev_info* pdi, const mifare_cmd mc, const ui return true; } -bool nfc_target_init(const dev_info* pdi, byte_t* pbtRx, size_t* pszRxBits) +bool nfc_target_init(const nfc_device_t* pnd, byte_t* pbtRx, size_t* pszRxBits) { byte_t abtRx[MAX_FRAME_LEN]; size_t szRxLen; uint8_t ui8Bits; // Save the current configuration settings - bool bCrc = pdi->bCrc; - bool bPar = pdi->bPar; + bool bCrc = pnd->bCrc; + bool bPar = pnd->bPar; byte_t abtCmd[sizeof(pncmd_target_init)]; memcpy(abtCmd,pncmd_target_init,sizeof(pncmd_target_init)); @@ -830,19 +830,19 @@ bool nfc_target_init(const dev_info* pdi, 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((dev_info*)pdi,DCO_HANDLE_CRC,true); - if (!bPar) nfc_configure((dev_info*)pdi,DCO_HANDLE_PARITY,true); + if (!bCrc) nfc_configure((nfc_device_t*)pnd,DCO_HANDLE_CRC,true); + if (!bPar) nfc_configure((nfc_device_t*)pnd,DCO_HANDLE_PARITY,true); // Let the PN53X be activated by the RF level detector from power down mode - if (!pn53x_set_reg(pdi,REG_CIU_TX_AUTO, SYMBOL_INITIAL_RF_ON,0x04)) return false; + if (!pn53x_set_reg(pnd,REG_CIU_TX_AUTO, SYMBOL_INITIAL_RF_ON,0x04)) return false; // Request the initialization as a target, we can not use pn53x_transceive() because // abtRx[0] contains the emulation mode (baudrate, 14443-4?, DEP and framing type) szRxLen = MAX_FRAME_LEN; - if (!pdi->pdc->transceive(pdi->ds,abtCmd,39,abtRx,&szRxLen)) return false; + if (!pnd->pdc->transceive(pnd->ds,abtCmd,39,abtRx,&szRxLen)) return false; // Get the last bit-count that is stored in the received byte - ui8Bits = pn53x_get_reg(pdi,REG_CIU_CONTROL) & SYMBOL_RX_LAST_BITS; + ui8Bits = pn53x_get_reg(pnd,REG_CIU_CONTROL) & SYMBOL_RX_LAST_BITS; // We are sure the parity is handled by the PN53X chip, so we handle it this way *pszRxBits = ((szRxLen-1-((ui8Bits==0)?0:1))*8)+ui8Bits; @@ -850,13 +850,13 @@ bool nfc_target_init(const dev_info* pdi, 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((dev_info*)pdi,DCO_HANDLE_CRC,false); - if (!bPar) nfc_configure((dev_info*)pdi,DCO_HANDLE_PARITY,false); + if (!bCrc) nfc_configure((nfc_device_t*)pnd,DCO_HANDLE_CRC,false); + if (!bPar) nfc_configure((nfc_device_t*)pnd,DCO_HANDLE_PARITY,false); return true; } -bool nfc_target_receive_bits(const dev_info* pdi, byte_t* pbtRx, size_t* pszRxBits, byte_t* pbtRxPar) +bool nfc_target_receive_bits(const nfc_device_t* pnd, byte_t* pbtRx, size_t* pszRxBits, byte_t* pbtRxPar) { byte_t abtRx[MAX_FRAME_LEN]; size_t szRxLen; @@ -864,17 +864,17 @@ bool nfc_target_receive_bits(const dev_info* pdi, byte_t* pbtRx, size_t* pszRxBi uint8_t ui8Bits; // Try to gather a received frame from the reader - if (!pn53x_transceive(pdi,pncmd_target_receive,2,abtRx,&szRxLen)) return false; + if (!pn53x_transceive(pnd,pncmd_target_receive,2,abtRx,&szRxLen)) return false; // Get the last bit-count that is stored in the received byte - ui8Bits = pn53x_get_reg(pdi,REG_CIU_CONTROL) & SYMBOL_RX_LAST_BITS; + ui8Bits = pn53x_get_reg(pnd,REG_CIU_CONTROL) & SYMBOL_RX_LAST_BITS; // Recover the real frame length in bits szFrameBits = ((szRxLen-1-((ui8Bits==0)?0:1))*8)+ui8Bits; // Ignore the status byte from the PN53X here, it was checked earlier in pn53x_transceive() // Check if we should recover the parity bits ourself - if (!pdi->bPar) + if (!pnd->bPar) { // Unwrap the response frame pn53x_unwrap_frame(abtRx+1,szFrameBits,pbtRx,pszRxBits,pbtRxPar); @@ -888,13 +888,13 @@ bool nfc_target_receive_bits(const dev_info* pdi, byte_t* pbtRx, size_t* pszRxBi return true; } -bool nfc_target_receive_dep_bytes(const dev_info* pdi, byte_t* pbtRx, size_t* pszRxLen) +bool nfc_target_receive_dep_bytes(const nfc_device_t* pnd, byte_t* pbtRx, size_t* pszRxLen) { byte_t abtRx[MAX_FRAME_LEN]; size_t szRxLen; // Try to gather a received frame from the reader - if (!pn53x_transceive(pdi,pncmd_target_get_data,2,abtRx,&szRxLen)) return false; + if (!pn53x_transceive(pnd,pncmd_target_get_data,2,abtRx,&szRxLen)) return false; // Save the received byte count *pszRxLen = szRxLen-1; @@ -906,13 +906,13 @@ bool nfc_target_receive_dep_bytes(const dev_info* pdi, byte_t* pbtRx, size_t* ps return true; } -bool nfc_target_receive_bytes(const dev_info* pdi, byte_t* pbtRx, size_t* pszRxLen) +bool nfc_target_receive_bytes(const nfc_device_t* pnd, byte_t* pbtRx, size_t* pszRxLen) { byte_t abtRx[MAX_FRAME_LEN]; size_t szRxLen; // Try to gather a received frame from the reader - if (!pn53x_transceive(pdi,pncmd_target_receive,2,abtRx,&szRxLen)) return false; + if (!pn53x_transceive(pnd,pncmd_target_receive,2,abtRx,&szRxLen)) return false; // Save the received byte count *pszRxLen = szRxLen-1; @@ -924,7 +924,7 @@ bool nfc_target_receive_bytes(const dev_info* pdi, byte_t* pbtRx, size_t* pszRxL return true; } -bool nfc_target_send_bits(const dev_info* pdi, const byte_t* pbtTx, const size_t szTxBits, const byte_t* pbtTxPar) +bool nfc_target_send_bits(const nfc_device_t* pnd, const byte_t* pbtTx, const size_t szTxBits, const byte_t* pbtTxPar) { size_t szFrameBits = 0; size_t szFrameBytes = 0; @@ -933,7 +933,7 @@ bool nfc_target_send_bits(const dev_info* pdi, const byte_t* pbtTx, const size_t memcpy(abtCmd,pncmd_target_send,sizeof(pncmd_target_send)); // Check if we should prepare the parity bits ourself - if (!pdi->bPar) + if (!pnd->bPar) { // Convert data with parity to a frame pn53x_wrap_frame(pbtTx,szTxBits,pbtTxPar,abtCmd+2,&szFrameBits); @@ -948,50 +948,50 @@ bool nfc_target_send_bits(const dev_info* pdi, const byte_t* pbtTx, const size_t szFrameBytes = (szFrameBits/8)+((ui8Bits==0)?0:1); // When the parity is handled before us, we just copy the data - if (pdi->bPar) memcpy(abtCmd+2,pbtTx,szFrameBytes); + if (pnd->bPar) memcpy(abtCmd+2,pbtTx,szFrameBytes); // Set the amount of transmission bits in the PN53X chip register - if (!pn53x_set_tx_bits(pdi,ui8Bits)) return false; + if (!pn53x_set_tx_bits(pnd,ui8Bits)) return false; // Try to send the bits to the reader - if (!pn53x_transceive(pdi,abtCmd,szFrameBytes+2,NULL,NULL)) return false; + if (!pn53x_transceive(pnd,abtCmd,szFrameBytes+2,NULL,NULL)) return false; // Everyting seems ok, return true return true; } -bool nfc_target_send_bytes(const dev_info* pdi, const byte_t* pbtTx, const size_t szTxLen) +bool nfc_target_send_bytes(const nfc_device_t* pnd, const byte_t* pbtTx, const size_t szTxLen) { byte_t abtCmd[sizeof(pncmd_target_send)]; memcpy(abtCmd,pncmd_target_send,sizeof(pncmd_target_send)); // We can not just send bytes without parity if while the PN53X expects we handled them - if (!pdi->bPar) return false; + if (!pnd->bPar) return false; // Copy the data into the command frame memcpy(abtCmd+2,pbtTx,szTxLen); // Try to send the bits to the reader - if (!pn53x_transceive(pdi,abtCmd,szTxLen+2,NULL,NULL)) return false; + if (!pn53x_transceive(pnd,abtCmd,szTxLen+2,NULL,NULL)) return false; // Everyting seems ok, return true return true; } -bool nfc_target_send_dep_bytes(const dev_info* pdi, const byte_t* pbtTx, const size_t szTxLen) +bool nfc_target_send_dep_bytes(const nfc_device_t* pnd, const byte_t* pbtTx, const size_t szTxLen) { byte_t abtCmd[sizeof(pncmd_target_set_data)]; memcpy(abtCmd,pncmd_target_set_data,sizeof(pncmd_target_set_data)); // We can not just send bytes without parity if while the PN53X expects we handled them - if (!pdi->bPar) return false; + if (!pnd->bPar) return false; // Copy the data into the command frame memcpy(abtCmd+2,pbtTx,szTxLen); // Try to send the bits to the reader - if (!pn53x_transceive(pdi,abtCmd,szTxLen+2,NULL,NULL)) return false; + if (!pn53x_transceive(pnd,abtCmd,szTxLen+2,NULL,NULL)) return false; // Everyting seems ok, return true return true; diff --git a/src/lib/nfc.h b/src/lib/nfc.h index df73afe..7c8bb3d 100644 --- a/src/lib/nfc.h +++ b/src/lib/nfc.h @@ -29,43 +29,43 @@ #include #include -#include "defines.h" -#include "types.h" +#include "nfc-defines.h" +#include "nfc-types.h" #ifdef __cplusplus #define NFCAPI extern "C" { #endif // __cplusplus /** - * @fn dev_info* nfc_connect(nfc_device_desc_t* pndd) + * @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 dev_info struct if successfull; otherwise returns INVALID_DEVICE_INFO value. + * @return Returns pointer to a nfc_device_t struct if successfull; otherwise returns INVALID_DEVICE_INFO 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. * * If \a pndd is passed then libnfc will try to claim the right device using information provided by this struct. * - * When it has successfully claimed a NFC device, memory is allocated to save the device information. It will return a pointer to a dev_info struct. + * When it has successfully claimed a NFC device, memory is allocated to save the device information. It will return a pointer to a nfc_device_t struct. * This pointer should be supplied by every next function of libnfc that should perform an action with this device. */ -dev_info* nfc_connect(nfc_device_desc_t* pndd); +nfc_device_t* nfc_connect(nfc_device_desc_t* pndd); /** - * @fn void nfc_disconnect(dev_info* pdi) + * @fn void nfc_disconnect(nfc_device_t* pnd) * @brief Disconnect from a NFC device - * @param pdi dev_info struct pointer that represent currently used device + * @param pnd nfc_device_t struct pointer that represent currently used device * - * Initiator is disconnected and the device, including allocated dev_info struct, is released. + * Initiator is disconnected and the device, including allocated nfc_device_t struct, is released. */ -void nfc_disconnect(dev_info* pdi); +void nfc_disconnect(nfc_device_t* pnd); /** - * @fn nfc_configure(dev_info* pdi, const dev_config_option dco, const bool bEnable) + * @fn nfc_configure(nfc_device_t* pnd, const dev_config_option dco, const bool bEnable) * @brief Configure advanced NFC device settings * @return Returns true if action was successfully performed; otherwise returns false. - * @param pdi dev_info struct pointer that represent currently used device + * @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 bEnable boolean * @@ -73,23 +73,23 @@ void nfc_disconnect(dev_info* pdi); * 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(dev_info* pdi, const dev_config_option dco, const bool bEnable); +bool nfc_configure(nfc_device_t* pnd, const dev_config_option dco, const bool bEnable); /** - * @fn nfc_initiator_init(const dev_info* pdi) + * @fn nfc_initiator_init(const nfc_device_t* pnd) * @brief Initialize NFC device as initiator (reader) * @return Returns true if action was successfully performed; otherwise returns false. - * @param pdi dev_info struct pointer that represent currently used device + * @param pnd nfc_device_t 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. The reader will act as initiator to communicate peer 2 peer (NFCIP) to other active NFC devices. */ -bool nfc_initiator_init(const dev_info* pdi); +bool nfc_initiator_init(const nfc_device_t* pnd); /** - * @fn nfc_initiator_select_tag(const dev_info* pdi, const init_modulation im, const byte_t* pbtInitData, const size_t szInitDataLen, tag_info* pti) + * @fn nfc_initiator_select_tag(const nfc_device_t* pnd, const init_modulation im, const byte_t* pbtInitData, const size_t szInitDataLen, tag_info* pti) * @brief Select a passive or emulated tag * @return Returns true if action was successfully performed; otherwise returns false. - * @param pdi dev_info struct pointer that represent currently used device + * @param pnd nfc_device_t struct pointer that represent currently used device * @param im Desired modulation * @param pbtInitData Optional initiator data used for Felica, ISO14443B, Topaz Polling or for ISO14443A selecting a specific UID. * @param szInitDataLen Length of initiator data \a pbtInitData. @@ -97,13 +97,13 @@ bool nfc_initiator_init(const dev_info* pdi); * The NFC device will try to find the available passive tags. Some NFC devices are capable to emulate passive tags. The standards (ISO18092 and ECMA-340) describe the modulation that can be used for reader to passive communications. The chip needs to know with what kind of tag it is dealing with, therefore the initial modulation and speed (106, 212 or 424 kbps) should be supplied. * @note For every initial modulation type there is a different collection of information returned (in tag_info pointer pti) They all fit in the data-type which is called tag_info. This is a union which contains the tag information that belongs to the according initial modulation type. */ -bool nfc_initiator_select_tag(const dev_info* pdi, const init_modulation im, const byte_t* pbtInitData, const size_t szInitDataLen, tag_info* pti); +bool nfc_initiator_select_tag(const nfc_device_t* pnd, const init_modulation im, const byte_t* pbtInitData, const size_t szInitDataLen, tag_info* pti); /** - * @fn nfc_initiator_select_dep_target(const dev_info *pdi, const init_modulation im, const byte_t *pbtPidData, const size_t szPidDataLen, const byte_t *pbtNFCID3i, const size_t szNFCID3iDataLen, const byte_t *pbtGbData, const size_t szGbDataLen, tag_info * pti); + * @fn nfc_initiator_select_dep_target(const nfc_device_t *pnd, const init_modulation im, const byte_t *pbtPidData, const size_t szPidDataLen, const byte_t *pbtNFCID3i, const size_t szNFCID3iDataLen, const byte_t *pbtGbData, const size_t szGbDataLen, tag_info * pti); * @brief Select a target and request active or passive mode for DEP (Data Exchange Protocol) * @return Returns true if action was successfully performed; otherwise returns false. - * @param pdi dev_info struct pointer that represent currently used device + * @param pnd nfc_device_t struct pointer that represent currently used device * @param im Desired modulation (IM_ACTIVE_DEP or IM_PASSIVE_DEP for active, respectively passive mode) * @param pbtPidData passive initiator data, 4 or 5 bytes long, (optional, only for IM_PASSIVE_DEP, can be NULL) * @param pbtNFCID3i the NFCID3, 10 bytes long, of the initiator (optional, can be NULL) @@ -112,19 +112,19 @@ bool nfc_initiator_select_tag(const dev_info* pdi, const init_modulation im, con * The NFC device will try to find the available target. The standards (ISO18092 and ECMA-340) describe the modulation that can be used for reader to passive communications. * @note tag_info_dep will be returned when the target was acquired successfully. */ -bool nfc_initiator_select_dep_target(const dev_info* pdi, const init_modulation im, const byte_t* pbtPidData, const size_t szPidDataLen, const byte_t* pbtNFCID3i, const size_t szNFCID3iDataLen, const byte_t *pbtGbData, const size_t szGbDataLen, tag_info* pti); +bool nfc_initiator_select_dep_target(const nfc_device_t* pnd, const init_modulation im, const byte_t* pbtPidData, const size_t szPidDataLen, const byte_t* pbtNFCID3i, const size_t szNFCID3iDataLen, const byte_t *pbtGbData, const size_t szGbDataLen, tag_info* pti); /** - * @fn nfc_initiator_deselect_tag(const dev_info* pdi); + * @fn nfc_initiator_deselect_tag(const nfc_device_t* pnd); * @brief Deselect a selected passive or emulated tag * @return Returns true if action was successfully performed; otherwise returns false. - * @param pdi dev_info struct pointer that represent currently used device + * @param pnd nfc_device_t struct pointer that represent 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 multiple tags available in the field. It is possible to use the nfc_initiator_select_tag() function to select the first available tag, test it for the available features and support, deselect it and skip to the next tag until the correct tag is found. */ -bool nfc_initiator_deselect_tag(const dev_info* pdi); +bool nfc_initiator_deselect_tag(const nfc_device_t* pnd); /** - * @fn nfc_initiator_transceive_bits(const dev_info* pdi, const byte_t* pbtTx, const size_t szTxBits, const byte_t* pbtTxPar, byte_t* pbtRx, size_t* pszRxBits, byte_t* pbtRxPar) + * @fn nfc_initiator_transceive_bits(const 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) * @brief Transceive raw bit-frames * @return Returns true if action was successfully performed; otherwise returns false. * @param pbtTx contains a byte array of the frame that needs to be transmitted. @@ -136,29 +136,29 @@ bool nfc_initiator_deselect_tag(const dev_info* pdi); * * The NFC reader will transmit low-level messages where only the modulation is handled by the PN53X chip. Construction of the frame (data, CRC and parity) is completely done by libnfc. This can be very useful for testing purposes. Some protocols (e.g. MIFARE Classic) require to violate the ISO14443-A standard by sending incorrect parity and CRC bytes. Using this feature you are able to simulate these frames. */ -bool nfc_initiator_transceive_bits(const dev_info* pdi, const byte_t* pbtTx, const size_t szTxBits, const byte_t* pbtTxPar, byte_t* pbtRx, size_t* pszRxBits, byte_t* pbtRxPar); +bool nfc_initiator_transceive_bits(const 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); /** - * @fn nfc_initiator_transceive_bytes(const dev_info* pdi, const byte_t* pbtTx, const size_t szTxLen, byte_t* pbtRx, size_t* pszRxLen) + * @fn nfc_initiator_transceive_bytes(const nfc_device_t* pnd, const byte_t* pbtTx, const size_t szTxLen, byte_t* pbtRx, size_t* pszRxLen) * @brief Transceive byte and APDU frames * @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). */ -bool nfc_initiator_transceive_bytes(const dev_info* pdi, const byte_t* pbtTx, const size_t szTxLen, byte_t* pbtRx, size_t* pszRxLen); +bool nfc_initiator_transceive_bytes(const nfc_device_t* pnd, const byte_t* pbtTx, const size_t szTxLen, byte_t* pbtRx, size_t* pszRxLen); /** - * @fn nfc_initiator_transceive_dep_bytes(const dev_info* pdi, const byte_t* pbtTx, const size_t szTxLen, byte_t* pbtRx, size_t* pszRxLen) + * @fn nfc_initiator_transceive_dep_bytes(const nfc_device_t* pnd, const byte_t* pbtTx, const size_t szTxLen, byte_t* pbtRx, size_t* pszRxLen) * @brief Transceive data * @return Returns true if action was successfully performed; otherwise returns false. * * The reader will transmit the supplied (data) bytes in pbtTx to the target (tag). It waits for the response and stores the received bytes in the pbtRx byte array. The difference between this function and nfc_initiator_transceive_bytes is that here pbtTx and pbtRx contain *only* the data sent and received and not any additional commands, that is all handled internally by the PN53X. */ -bool nfc_initiator_transceive_dep_bytes(const dev_info* pdi, const byte_t* pbtTx, const size_t szTxLen, byte_t* pbtRx, size_t* pszRxLen); +bool nfc_initiator_transceive_dep_bytes(const nfc_device_t* pnd, const byte_t* pbtTx, const size_t szTxLen, byte_t* pbtRx, size_t* pszRxLen); /** - * @fn nfc_initiator_mifare_cmd(const dev_info* pdi, const mifare_cmd mc, const uint8_t ui8Block, mifare_param* pmp) + * @fn nfc_initiator_mifare_cmd(const nfc_device_t* pnd, const mifare_cmd mc, const uint8_t ui8Block, mifare_param* pmp) * @brief Execute a MIFARE Classic Command * @return Returns true if action was successfully performed; otherwise returns false. * @param pmp Some commands need additional information. This information should be supplied in the mifare_param union. @@ -168,10 +168,10 @@ bool nfc_initiator_transceive_dep_bytes(const dev_info* pdi, const byte_t* pbtTx * * First an authentication must take place using Key A or B. It requires a 48 bit Key (6 bytes) and the UID. They are both used to initialize the internal cipher-state of the PN53X chip (http://libnfc.org/hardware/pn53x-chip). After a successful authentication it will be possible to execute other commands (e.g. Read/Write). 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(const dev_info* pdi, const mifare_cmd mc, const uint8_t ui8Block, mifare_param* pmp); +bool nfc_initiator_mifare_cmd(const nfc_device_t* pnd, const mifare_cmd mc, const uint8_t ui8Block, mifare_param* pmp); /** - * @fn nfc_target_init(const dev_info* pdi, byte_t* pbtRx, size_t* pszRxBits) + * @fn nfc_target_init(const nfc_device_t* pnd, byte_t* pbtRx, size_t* pszRxBits) * @brief Initialize NFC device as an emulated tag * @return Returns true if action was successfully performed; otherwise returns false. * @@ -179,61 +179,61 @@ bool nfc_initiator_mifare_cmd(const dev_info* pdi, const mifare_cmd mc, const ui * * @warning Be aware that this function will wait (hang) until a command is received that is not part of the anti-collision. The RATS command for example would wake up the emulator. After this is received, the send and receive functions can be used. */ -bool nfc_target_init(const dev_info* pdi, byte_t* pbtRx, size_t* pszRxBits); +bool nfc_target_init(const nfc_device_t* pnd, byte_t* pbtRx, size_t* pszRxBits); /** - * @fn nfc_target_receive_bits(const dev_info* pdi, byte_t* pbtRx, size_t* pszRxBits, byte_t* pbtRxPar) + * @fn nfc_target_receive_bits(const nfc_device_t* pnd, byte_t* pbtRx, size_t* pszRxBits, byte_t* pbtRxPar) * @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. */ -bool nfc_target_receive_bits(const dev_info* pdi, byte_t* pbtRx, size_t* pszRxBits, byte_t* pbtRxPar); +bool nfc_target_receive_bits(const nfc_device_t* pnd, byte_t* pbtRx, size_t* pszRxBits, byte_t* pbtRxPar); /** - * @fn nfc_target_receive_bytes(const dev_info* pdi, byte_t* pbtRx, size_t* pszRxLen) + * @fn nfc_target_receive_bytes(const nfc_device_t* pnd, byte_t* pbtRx, size_t* pszRxLen) * @brief Receive bytes and APDU frames * @return Returns true if action was successfully performed; otherwise returns false. * * The main receive function that returns the received frames from a nearby reader. */ -bool nfc_target_receive_bytes(const dev_info* pdi, byte_t* pbtRx, size_t* pszRxLen); +bool nfc_target_receive_bytes(const nfc_device_t* pnd, byte_t* pbtRx, size_t* pszRxLen); /** - * @fn nfc_target_receive_dep_bytes(const dev_info* pdi, byte_t* pbtRx, size_t* pszRxLen) + * @fn nfc_target_receive_dep_bytes(const nfc_device_t* pnd, byte_t* pbtRx, size_t* pszRxLen) * @brief Receive data * @return Returns true if action was successfully performed; otherwise returns false. * * The main receive function that returns the received data from a nearby reader. The difference between this function and nfc_target_receive_bytes is that here pbtRx contains *only* the data received and not any additional commands, that is all handled internally by the PN53X. */ -bool nfc_target_receive_dep_bytes(const dev_info* pdi, byte_t* pbtRx, size_t* pszRxLen); +bool nfc_target_receive_dep_bytes(const nfc_device_t* pnd, byte_t* pbtRx, size_t* pszRxLen); /** - * @fn nfc_target_send_bits(const dev_info* pdi, const byte_t* pbtTx, const size_t szTxBits, const byte_t* pbtTxPar) + * @fn nfc_target_send_bits(const nfc_device_t* pnd, const byte_t* pbtTx, const size_t szTxBits, const byte_t* pbtTxPar) * @brief Send raw bit-frames * @return Returns true if action was successfully performed; otherwise returns false. * * This function can be used to transmit (raw) bit-frames to the reader. */ -bool nfc_target_send_bits(const dev_info* pdi, const byte_t* pbtTx, const size_t szTxBits, const byte_t* pbtTxPar); +bool nfc_target_send_bits(const nfc_device_t* pnd, const byte_t* pbtTx, const size_t szTxBits, const byte_t* pbtTxPar); /** - * @fn nfc_target_send_bytes(const dev_info* pdi, const byte_t* pbtTx, const size_t szTxLen) + * @fn nfc_target_send_bytes(const nfc_device_t* pnd, const byte_t* pbtTx, const size_t szTxLen) * @brief Send bytes and APDU frames * @return Returns true if action was successfully performed; otherwise returns false. * * To communicate byte frames and APDU responses to the reader, this function could be used. */ -bool nfc_target_send_bytes(const dev_info* pdi, const byte_t* pbtTx, const size_t szTxLen); +bool nfc_target_send_bytes(const nfc_device_t* pnd, const byte_t* pbtTx, const size_t szTxLen); /** - * @fn nfc_target_send_dep_bytes(const dev_info* pdi, const byte_t* pbtTx, const size_t szTxLen) + * @fn nfc_target_send_dep_bytes(const nfc_device_t* pnd, const byte_t* pbtTx, const size_t szTxLen) * @brief Send data * @return Returns true if action was successfully performed; otherwise returns false. * * To communicate data to the reader, this function could be used. The difference between this function and nfc_target_send_bytes is that here pbtTx contains *only* the data sent and not any additional commands, that is all handled internally by the PN53X. */ -bool nfc_target_send_dep_bytes(const dev_info* pdi, const byte_t* pbtTx, const size_t szTxLen); +bool nfc_target_send_dep_bytes(const nfc_device_t* pnd, const byte_t* pbtTx, const size_t szTxLen); /** * @fn const char* nfc_version(void)