Rename tag_info to nfc_target_info_t.

Rename init_modulation to nfc_modulation_t.
This commit is contained in:
Romuald Conty 2009-11-18 11:52:18 +00:00
parent 2feedddbfe
commit 483c69dd03
7 changed files with 117 additions and 117 deletions

View file

@ -37,7 +37,7 @@ static byte_t abtFelica[5] = { 0x00, 0xff, 0xff, 0x00, 0x00 };
int main(int argc, const char* argv[]) int main(int argc, const char* argv[])
{ {
tag_info ti; nfc_target_info_t nti;
// Try to open the NFC device // Try to open the NFC device
pnd = nfc_connect(NULL); pnd = nfc_connect(NULL);
@ -75,43 +75,43 @@ int main(int argc, const char* argv[])
printf("Connected to NFC reader: %s\n\n",pnd->acName); printf("Connected to NFC reader: %s\n\n",pnd->acName);
// Poll for a ISO14443A (MIFARE) tag // Poll for a ISO14443A (MIFARE) tag
if (nfc_initiator_select_tag(pnd,IM_ISO14443A_106,NULL,0,&ti)) if (nfc_initiator_select_tag(pnd,NM_ISO14443A_106,NULL,0,&nti))
{ {
printf("The following (NFC) ISO14443A tag was found:\n\n"); printf("The following (NFC) ISO14443A tag was found:\n\n");
printf(" ATQA (SENS_RES): "); print_hex(ti.tia.abtAtqa,2); printf(" ATQA (SENS_RES): "); print_hex(nti.nai.abtAtqa,2);
printf(" UID (NFCID%c): ",(ti.tia.abtUid[0]==0x08?'3':'1')); print_hex(ti.tia.abtUid,ti.tia.szUidLen); printf(" UID (NFCID%c): ",(nti.nai.abtUid[0]==0x08?'3':'1')); print_hex(nti.nai.abtUid,nti.nai.szUidLen);
printf(" SAK (SEL_RES): "); print_hex(&ti.tia.btSak,1); printf(" SAK (SEL_RES): "); print_hex(&nti.nai.btSak,1);
if (ti.tia.szAtsLen) if (nti.nai.szAtsLen)
{ {
printf(" ATS (ATR): "); printf(" ATS (ATR): ");
print_hex(ti.tia.abtAts,ti.tia.szAtsLen); print_hex(nti.nai.abtAts,nti.nai.szAtsLen);
} }
} }
// Poll for a Felica tag // Poll for a Felica tag
if (nfc_initiator_select_tag(pnd,IM_FELICA_212,abtFelica,5,&ti) || nfc_initiator_select_tag(pnd,IM_FELICA_424,abtFelica,5,&ti)) if (nfc_initiator_select_tag(pnd,NM_FELICA_212,abtFelica,5,&nti) || nfc_initiator_select_tag(pnd,NM_FELICA_424,abtFelica,5,&nti))
{ {
printf("The following (NFC) Felica tag was found:\n\n"); printf("The following (NFC) Felica tag was found:\n\n");
printf("%18s","ID (NFCID2): "); print_hex(ti.tif.abtId,8); printf("%18s","ID (NFCID2): "); print_hex(nti.nfi.abtId,8);
printf("%18s","Parameter (PAD): "); print_hex(ti.tif.abtPad,8); printf("%18s","Parameter (PAD): "); print_hex(nti.nfi.abtPad,8);
} }
// Poll for a ISO14443B tag // Poll for a ISO14443B tag
if (nfc_initiator_select_tag(pnd,IM_ISO14443B_106,(byte_t*)"\x00",1,&ti)) if (nfc_initiator_select_tag(pnd,NM_ISO14443B_106,(byte_t*)"\x00",1,&nti))
{ {
printf("The following (NFC) ISO14443-B tag was found:\n\n"); printf("The following (NFC) ISO14443-B tag was found:\n\n");
printf(" ATQB: "); print_hex(ti.tib.abtAtqb,12); printf(" ATQB: "); print_hex(nti.nbi.abtAtqb,12);
printf(" ID: "); print_hex(ti.tib.abtId,4); printf(" ID: "); print_hex(nti.nbi.abtId,4);
printf(" CID: %02x\n",ti.tib.btCid); printf(" CID: %02x\n",nti.nbi.btCid);
if (ti.tib.szInfLen>0) if (nti.nbi.szInfLen>0)
{ {
printf(" INF: "); print_hex(ti.tib.abtInf,ti.tib.szInfLen); printf(" INF: "); print_hex(nti.nbi.abtInf,nti.nbi.szInfLen);
} }
printf("PARAMS: %02x %02x %02x %02x\n",ti.tib.btParam1,ti.tib.btParam2,ti.tib.btParam3,ti.tib.btParam4); printf("PARAMS: %02x %02x %02x %02x\n",nti.nbi.btParam1,nti.nbi.btParam2,nti.nbi.btParam3,nti.nbi.btParam4);
} }
// Poll for a Jewel tag // Poll for a Jewel tag
if (nfc_initiator_select_tag(pnd,IM_JEWEL_106,NULL,0,&ti)) if (nfc_initiator_select_tag(pnd,NM_JEWEL_106,NULL,0,&nti))
{ {
// No test results yet // No test results yet
printf("jewel\n"); printf("jewel\n");

View file

@ -36,7 +36,7 @@
#include "bitutils.h" #include "bitutils.h"
static nfc_device_t* pnd; static nfc_device_t* pnd;
static tag_info ti; static nfc_target_info_t nti;
static mifare_param mp; static mifare_param mp;
static mifare_tag mtKeys; static mifare_tag mtKeys;
static mifare_tag mtDump; static mifare_tag mtDump;
@ -89,7 +89,7 @@ bool authenticate(uint32_t uiBlock)
if (bUseKeyFile) if (bUseKeyFile)
{ {
// Set the authentication information (uid) // Set the authentication information (uid)
memcpy(mp.mpa.abtUid,ti.tia.abtUid,4); memcpy(mp.mpa.abtUid,nti.nai.abtUid,4);
// Locate the trailer (with the keys) used for this sector // Locate the trailer (with the keys) used for this sector
uiTrailerBlock = get_trailer_block(uiBlock); uiTrailerBlock = get_trailer_block(uiBlock);
@ -116,7 +116,7 @@ bool authenticate(uint32_t uiBlock)
mc = (bUseKeyA) ? MC_AUTH_A : MC_AUTH_B; mc = (bUseKeyA) ? MC_AUTH_A : MC_AUTH_B;
// Set the authentication information (uid) // Set the authentication information (uid)
memcpy(mp.mpa.abtUid,ti.tia.abtUid,4); memcpy(mp.mpa.abtUid,nti.nai.abtUid,4);
for (key_index = 0; key_index < num_keys; key_index++) for (key_index = 0; key_index < num_keys; key_index++)
{ {
@ -134,7 +134,7 @@ bool authenticate(uint32_t uiBlock)
return true; return true;
} }
nfc_initiator_select_tag(pnd, IM_ISO14443A_106, mp.mpa.abtUid, 4, NULL); nfc_initiator_select_tag(pnd, NM_ISO14443A_106, mp.mpa.abtUid, 4, NULL);
} }
} }
@ -159,7 +159,7 @@ bool read_card()
{ {
printf("x"); printf("x");
// When a failure occured we need to redo the anti-collision // When a failure occured we need to redo the anti-collision
if (!nfc_initiator_select_tag(pnd,IM_ISO14443A_106,NULL,0,&ti)) if (!nfc_initiator_select_tag(pnd,NM_ISO14443A_106,NULL,0,&nti))
{ {
printf("!\nError: tag was removed\n"); printf("!\nError: tag was removed\n");
return 1; return 1;
@ -227,7 +227,7 @@ bool write_card()
{ {
printf("x"); printf("x");
// When a failure occured we need to redo the anti-collision // When a failure occured we need to redo the anti-collision
if (!nfc_initiator_select_tag(pnd,IM_ISO14443A_106,NULL,0,&ti)) if (!nfc_initiator_select_tag(pnd,NM_ISO14443A_106,NULL,0,&nti))
{ {
printf("!\nError: tag was removed\n"); printf("!\nError: tag was removed\n");
return false; return false;
@ -427,7 +427,7 @@ int main(int argc, const char* argv[])
printf("Connected to NFC reader: %s\n",pnd->acName); printf("Connected to NFC reader: %s\n",pnd->acName);
// Try to find a MIFARE Classic tag // Try to find a MIFARE Classic tag
if (!nfc_initiator_select_tag(pnd,IM_ISO14443A_106,NULL,0,&ti)) if (!nfc_initiator_select_tag(pnd,NM_ISO14443A_106,NULL,0,&nti))
{ {
printf("Error: no tag was found\n"); printf("Error: no tag was found\n");
nfc_disconnect(pnd); nfc_disconnect(pnd);
@ -435,7 +435,7 @@ int main(int argc, const char* argv[])
} }
// Test if we are dealing with a MIFARE compatible tag // Test if we are dealing with a MIFARE compatible tag
if ((ti.tia.btSak & 0x08) == 0) if ((nti.nai.btSak & 0x08) == 0)
{ {
printf("Error: tag is not a MIFARE Classic card\n"); printf("Error: tag is not a MIFARE Classic card\n");
nfc_disconnect(pnd); nfc_disconnect(pnd);
@ -449,15 +449,15 @@ int main(int argc, const char* argv[])
pbtUID = mtKeys.amb[0].mbm.abtUID; pbtUID = mtKeys.amb[0].mbm.abtUID;
// Compare if key dump UID is the same as the current tag UID // Compare if key dump UID is the same as the current tag UID
if (memcmp(ti.tia.abtUid,pbtUID,4) != 0) if (memcmp(nti.nai.abtUid,pbtUID,4) != 0)
{ {
printf("Expected MIFARE Classic %cK card with UID: %08x\n",b4K?'4':'1',swap_endian32(pbtUID)); printf("Expected MIFARE Classic %cK card with UID: %08x\n",b4K?'4':'1',swap_endian32(pbtUID));
} }
} }
// Get the info from the current tag // Get the info from the current tag
pbtUID = ti.tia.abtUid; pbtUID = nti.nai.abtUid;
b4K = (ti.tia.abtAtqa[1] == 0x02); b4K = (nti.nai.abtAtqa[1] == 0x02);
printf("Found MIFARE Classic %cK card with UID: %08x\n",b4K?'4':'1',swap_endian32(pbtUID)); printf("Found MIFARE Classic %cK card with UID: %08x\n",b4K?'4':'1',swap_endian32(pbtUID));
uiBlocks = (b4K)?0xff:0x3f; uiBlocks = (b4K)?0xff:0x3f;

View file

@ -36,7 +36,7 @@
#include "bitutils.h" #include "bitutils.h"
static nfc_device_t* pnd; static nfc_device_t* pnd;
static tag_info ti; static nfc_target_info_t nti;
static mifare_param mp; static mifare_param mp;
static mifareul_tag mtDump; static mifareul_tag mtDump;
@ -71,7 +71,7 @@ bool write_card()
{ {
printf("x"); printf("x");
// When a failure occured we need to redo the anti-collision // When a failure occured we need to redo the anti-collision
if (!nfc_initiator_select_tag(pnd,IM_ISO14443A_106,NULL,0,&ti)) if (!nfc_initiator_select_tag(pnd,NM_ISO14443A_106,NULL,0,&nti))
{ {
printf("!\nError: tag was removed\n"); printf("!\nError: tag was removed\n");
return false; return false;
@ -171,7 +171,7 @@ int main(int argc, const char* argv[])
printf("Connected to NFC reader: %s\n",pnd->acName); printf("Connected to NFC reader: %s\n",pnd->acName);
// Try to find a MIFARE Ultralight tag // Try to find a MIFARE Ultralight tag
if (!nfc_initiator_select_tag(pnd,IM_ISO14443A_106,NULL,0,&ti)) if (!nfc_initiator_select_tag(pnd,NM_ISO14443A_106,NULL,0,&nti))
{ {
printf("Error: no tag was found\n"); printf("Error: no tag was found\n");
nfc_disconnect(pnd); nfc_disconnect(pnd);
@ -180,7 +180,7 @@ int main(int argc, const char* argv[])
// Test if we are dealing with a MIFARE compatible tag // Test if we are dealing with a MIFARE compatible tag
if (ti.tia.abtAtqa[1] != 0x44){ if (nti.nai.abtAtqa[1] != 0x44){
printf("Error: tag is not a MIFARE Ultralight card\n"); printf("Error: tag is not a MIFARE Ultralight card\n");
nfc_disconnect(pnd); nfc_disconnect(pnd);
return 1; return 1;
@ -188,7 +188,7 @@ int main(int argc, const char* argv[])
// Get the info from the current tag // Get the info from the current tag
pbtUID = ti.tia.abtUid; pbtUID = nti.nai.abtUid;
printf("Found MIFARE Ultralight card with uid: %08x\n", swap_endian32(pbtUID)); printf("Found MIFARE Ultralight card with uid: %08x\n", swap_endian32(pbtUID));
if (bReadAction) if (bReadAction)

View file

@ -30,14 +30,14 @@
int main(int argc, const char *argv[]) int main(int argc, const char *argv[])
{ {
nfc_device_t *pnd; nfc_device_t *pnd;
tag_info ti; nfc_target_info_t ti;
byte_t abtRecv[MAX_FRAME_LEN]; byte_t abtRecv[MAX_FRAME_LEN];
size_t szRecvBits; size_t szRecvBits;
byte_t send[] = "Hello World!"; byte_t send[] = "Hello World!";
pnd = nfc_connect(NULL); pnd = nfc_connect(NULL);
if (!pnd || !nfc_initiator_init(pnd) if (!pnd || !nfc_initiator_init(pnd)
|| !nfc_initiator_select_dep_target(pnd, IM_PASSIVE_DEP, NULL, 0, || !nfc_initiator_select_dep_target(pnd, NM_PASSIVE_DEP, NULL, 0,
NULL, 0, NULL, 0, &ti)) { NULL, 0, NULL, 0, &ti)) {
printf printf
("unable to connect, initialize, or select the target\n"); ("unable to connect, initialize, or select the target\n");

View file

@ -131,28 +131,28 @@ typedef enum {
// nfc_reader_list_passive - using InListPassiveTarget // nfc_reader_list_passive - using InListPassiveTarget
/** /**
* @enum init_modulation * @enum nfc_modulation_t
* @brief NFC modulation * @brief NFC modulation
*/ */
typedef enum { typedef enum {
/** ISO14443-A (NXP MIFARE) http://en.wikipedia.org/wiki/MIFARE */ /** ISO14443-A (NXP MIFARE) http://en.wikipedia.org/wiki/MIFARE */
IM_ISO14443A_106 = 0x00, NM_ISO14443A_106 = 0x00,
/** JIS X 6319-4 (Sony Felica) http://en.wikipedia.org/wiki/FeliCa */ /** JIS X 6319-4 (Sony Felica) http://en.wikipedia.org/wiki/FeliCa */
IM_FELICA_212 = 0x01, NM_FELICA_212 = 0x01,
/** JIS X 6319-4 (Sony Felica) http://en.wikipedia.org/wiki/FeliCa */ /** JIS X 6319-4 (Sony Felica) http://en.wikipedia.org/wiki/FeliCa */
IM_FELICA_424 = 0x02, NM_FELICA_424 = 0x02,
/** ISO14443-B http://en.wikipedia.org/wiki/ISO/IEC_14443 */ /** ISO14443-B http://en.wikipedia.org/wiki/ISO/IEC_14443 */
IM_ISO14443B_106 = 0x03, NM_ISO14443B_106 = 0x03,
/** Jewel Topaz (Innovision Research & Development) */ /** Jewel Topaz (Innovision Research & Development) */
IM_JEWEL_106 = 0x04, NM_JEWEL_106 = 0x04,
/** Active DEP */ /** Active DEP */
IM_ACTIVE_DEP = 0x05, NM_ACTIVE_DEP = 0x05,
/** Passive DEP */ /** Passive DEP */
IM_PASSIVE_DEP = 0x06, NM_PASSIVE_DEP = 0x06,
}init_modulation; } nfc_modulation_t;
/** /**
* @struct tag_info_dep * @struct nfc_target_info_t_dep
* @brief NFC tag information in Data Exchange Protocol * @brief NFC tag information in Data Exchange Protocol
*/ */
typedef struct { typedef struct {
@ -160,10 +160,10 @@ typedef struct {
byte_t btDID; byte_t btDID;
byte_t btBSt; byte_t btBSt;
byte_t btBRt; byte_t btBRt;
}tag_info_dep; } nfc_dep_info_t;
/** /**
* @struct tag_info_iso14443a * @struct nfc_target_info_t_iso14443a
* @brief NFC ISO14443A tag (MIFARE) information * @brief NFC ISO14443A tag (MIFARE) information
*/ */
typedef struct { typedef struct {
@ -173,10 +173,10 @@ typedef struct {
byte_t abtUid[10]; byte_t abtUid[10];
size_t szAtsLen; size_t szAtsLen;
byte_t abtAts[36]; byte_t abtAts[36];
}tag_info_iso14443a; } nfc_iso14443a_info_t;
/** /**
* @struct tag_info_felica * @struct nfc_target_info_t_felica
* @brief NFC FeLiCa tag information * @brief NFC FeLiCa tag information
*/ */
typedef struct { typedef struct {
@ -185,10 +185,10 @@ typedef struct {
byte_t abtId[8]; byte_t abtId[8];
byte_t abtPad[8]; byte_t abtPad[8];
byte_t abtSysCode[2]; byte_t abtSysCode[2];
}tag_info_felica; } nfc_felica_info_t;
/** /**
* @struct tag_info_iso14443b * @struct nfc_target_info_t_iso14443b
* @brief NFC ISO14443B tag information * @brief NFC ISO14443B tag information
*/ */
typedef struct { typedef struct {
@ -201,28 +201,28 @@ typedef struct {
byte_t btCid; byte_t btCid;
size_t szInfLen; size_t szInfLen;
byte_t abtInf[64]; byte_t abtInf[64];
}tag_info_iso14443b; } nfc_iso14443b_info_t;
/** /**
* @struct tag_info_jewel * @struct nfc_target_info_t_jewel
* @brief NFC Jewel tag information * @brief NFC Jewel tag information
*/ */
typedef struct { typedef struct {
byte_t btSensRes[2]; byte_t btSensRes[2];
byte_t btId[4]; byte_t btId[4];
}tag_info_jewel; } nfc_jewel_info_t;
/** /**
* @union tag_info * @union nfc_target_info_t
* @brief Union between all kind of tags information structures. * @brief Union between all kind of tags information structures.
*/ */
typedef union { typedef union {
tag_info_iso14443a tia; nfc_iso14443a_info_t nai;
tag_info_felica tif; nfc_felica_info_t nfi;
tag_info_iso14443b tib; nfc_iso14443b_info_t nbi;
tag_info_jewel tij; nfc_jewel_info_t nji;
tag_info_dep tid; nfc_dep_info_t ndi;
}tag_info; } nfc_target_info_t;
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// InDataExchange, MIFARE Classic card // InDataExchange, MIFARE Classic card

View file

@ -18,7 +18,7 @@
* *
* *
* @file nfc.c * @file nfc.c
* @brief * @brief NFC library implementation
*/ */
#include "nfc.h" #include "nfc.h"
@ -433,7 +433,7 @@ bool nfc_initiator_init(const nfc_device_t* pnd)
return true; return true;
} }
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) bool nfc_initiator_select_dep_target(const nfc_device_t* pnd, const nfc_modulation_t nmInitModulation, const byte_t* pbtPidData, const size_t szPidDataLen, const byte_t* pbtNFCID3i, const size_t szNFCID3iDataLen, const byte_t *pbtGbData, const size_t szGbDataLen, nfc_target_info_t* pnti)
{ {
byte_t abtRx[MAX_FRAME_LEN]; byte_t abtRx[MAX_FRAME_LEN];
size_t szRxLen; size_t szRxLen;
@ -441,13 +441,13 @@ bool nfc_initiator_select_dep_target(const nfc_device_t* pnd, const init_modulat
byte_t abtCmd[sizeof(pncmd_initiator_jump_for_dep)]; byte_t abtCmd[sizeof(pncmd_initiator_jump_for_dep)];
memcpy(abtCmd,pncmd_initiator_jump_for_dep,sizeof(pncmd_initiator_jump_for_dep)); memcpy(abtCmd,pncmd_initiator_jump_for_dep,sizeof(pncmd_initiator_jump_for_dep));
if(im == IM_ACTIVE_DEP) { if(nmInitModulation == NM_ACTIVE_DEP) {
abtCmd[2] = 0x01; /* active DEP */ abtCmd[2] = 0x01; /* active DEP */
} }
abtCmd[3] = 0x00; /* baud rate = 106kbps */ abtCmd[3] = 0x00; /* baud rate = 106kbps */
offset = 5; offset = 5;
if(pbtPidData && im != IM_ACTIVE_DEP) { /* can't have passive initiator data when using active mode */ if(pbtPidData && nmInitModulation != NM_ACTIVE_DEP) { /* can't have passive initiator data when using active mode */
abtCmd[4] |= 0x01; abtCmd[4] |= 0x01;
memcpy(abtCmd+offset,pbtPidData,szPidDataLen); memcpy(abtCmd+offset,pbtPidData,szPidDataLen);
offset+= szPidDataLen; offset+= szPidDataLen;
@ -472,17 +472,17 @@ bool nfc_initiator_select_dep_target(const nfc_device_t* pnd, const init_modulat
if (abtRx[1] != 1) return false; if (abtRx[1] != 1) return false;
// Is a target info struct available // Is a target info struct available
if (pti) if (pnti)
{ {
memcpy(pti->tid.NFCID3i,abtRx+2,10); memcpy(pnti->ndi.NFCID3i,abtRx+2,10);
pti->tid.btDID = abtRx[12]; pnti->ndi.btDID = abtRx[12];
pti->tid.btBSt = abtRx[13]; pnti->ndi.btBSt = abtRx[13];
pti->tid.btBRt = abtRx[14]; pnti->ndi.btBRt = abtRx[14];
} }
return true; return true;
} }
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) bool nfc_initiator_select_tag(const nfc_device_t* pnd, const nfc_modulation_t nmInitModulation, const byte_t* pbtInitData, const size_t szInitDataLen, nfc_target_info_t* pnti)
{ {
byte_t abtInit[MAX_FRAME_LEN]; byte_t abtInit[MAX_FRAME_LEN];
size_t szInitLen; size_t szInitLen;
@ -495,11 +495,11 @@ bool nfc_initiator_select_tag(const nfc_device_t* pnd, const init_modulation im,
if (!pnd->bActive) return false; if (!pnd->bActive) return false;
abtCmd[2] = 1; // MaxTg, we only want to select 1 tag at the time 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 abtCmd[3] = nmInitModulation; // BrTy, the type of init modulation used for polling a passive tag
switch(im) switch(nmInitModulation)
{ {
case IM_ISO14443A_106: case NM_ISO14443A_106:
switch (szInitDataLen) switch (szInitDataLen)
{ {
case 7: case 7:
@ -542,73 +542,73 @@ bool nfc_initiator_select_tag(const nfc_device_t* pnd, const init_modulation im,
if (abtRx[0] != 1) return false; if (abtRx[0] != 1) return false;
// Is a tag info struct available // Is a tag info struct available
if (pti) if (pnti)
{ {
// Fill the tag info struct with the values corresponding to this init modulation // Fill the tag info struct with the values corresponding to this init modulation
switch(im) switch(nmInitModulation)
{ {
case IM_ISO14443A_106: case NM_ISO14443A_106:
// Somehow they switched the lower and upper ATQA bytes around for the PN531 chipset // Somehow they switched the lower and upper ATQA bytes around for the PN531 chipset
if (pnd->nc == NC_PN531) if (pnd->nc == NC_PN531)
{ {
pti->tia.abtAtqa[0] = abtRx[3]; pnti->nai.abtAtqa[0] = abtRx[3];
pti->tia.abtAtqa[1] = abtRx[2]; pnti->nai.abtAtqa[1] = abtRx[2];
} else { } else {
memcpy(pti->tia.abtAtqa,abtRx+2,2); memcpy(pnti->nai.abtAtqa,abtRx+2,2);
} }
pti->tia.btSak = abtRx[4]; pnti->nai.btSak = abtRx[4];
// Copy the NFCID1 // Copy the NFCID1
pti->tia.szUidLen = abtRx[5]; pnti->nai.szUidLen = abtRx[5];
memcpy(pti->tia.abtUid,abtRx+6,pti->tia.szUidLen); memcpy(pnti->nai.abtUid,abtRx+6,pnti->nai.szUidLen);
// Did we received an optional ATS (Smardcard ATR) // Did we received an optional ATS (Smardcard ATR)
if (szRxLen > pti->tia.szUidLen+6) if (szRxLen > pnti->nai.szUidLen+6)
{ {
pti->tia.szAtsLen = abtRx[pti->tia.szUidLen+6]; pnti->nai.szAtsLen = abtRx[pnti->nai.szUidLen+6];
memcpy(pti->tia.abtAts,abtRx+pti->tia.szUidLen+6,pti->tia.szAtsLen); memcpy(pnti->nai.abtAts,abtRx+pnti->nai.szUidLen+6,pnti->nai.szAtsLen);
} else { } else {
pti->tia.szAtsLen = 0; pnti->nai.szAtsLen = 0;
} }
break; break;
case IM_FELICA_212: case NM_FELICA_212:
case IM_FELICA_424: case NM_FELICA_424:
// Store the mandatory info // Store the mandatory info
pti->tif.szLen = abtRx[2]; pnti->nfi.szLen = abtRx[2];
pti->tif.btResCode = abtRx[3]; pnti->nfi.btResCode = abtRx[3];
// Copy the NFCID2t // Copy the NFCID2t
memcpy(pti->tif.abtId,abtRx+4,8); memcpy(pnti->nfi.abtId,abtRx+4,8);
// Copy the felica padding // Copy the felica padding
memcpy(pti->tif.abtPad,abtRx+12,8); memcpy(pnti->nfi.abtPad,abtRx+12,8);
// Test if the System code (SYST_CODE) is available // Test if the System code (SYST_CODE) is available
if (szRxLen > 20) if (szRxLen > 20)
{ {
memcpy(pti->tif.abtSysCode,abtRx+20,2); memcpy(pnti->nfi.abtSysCode,abtRx+20,2);
} }
break; break;
case IM_ISO14443B_106: case NM_ISO14443B_106:
// Store the mandatory info // Store the mandatory info
memcpy(pti->tib.abtAtqb,abtRx+2,12); memcpy(pnti->nbi.abtAtqb,abtRx+2,12);
// Ignore the 0x1D byte, and just store the 4 byte id // Ignore the 0x1D byte, and just store the 4 byte id
memcpy(pti->tib.abtId,abtRx+15,4); memcpy(pnti->nbi.abtId,abtRx+15,4);
pti->tib.btParam1 = abtRx[19]; pnti->nbi.btParam1 = abtRx[19];
pti->tib.btParam2 = abtRx[20]; pnti->nbi.btParam2 = abtRx[20];
pti->tib.btParam3 = abtRx[21]; pnti->nbi.btParam3 = abtRx[21];
pti->tib.btParam4 = abtRx[22]; pnti->nbi.btParam4 = abtRx[22];
// Test if the Higher layer (INF) is available // Test if the Higher layer (INF) is available
if (szRxLen > 22) if (szRxLen > 22)
{ {
pti->tib.szInfLen = abtRx[23]; pnti->nbi.szInfLen = abtRx[23];
memcpy(pti->tib.abtInf,abtRx+24,pti->tib.szInfLen); memcpy(pnti->nbi.abtInf,abtRx+24,pnti->nbi.szInfLen);
} else { } else {
pti->tib.szInfLen = 0; pnti->nbi.szInfLen = 0;
} }
break; break;
case IM_JEWEL_106: case NM_JEWEL_106:
// Store the mandatory info // Store the mandatory info
memcpy(pti->tij.btSensRes,abtRx+2,2); memcpy(pnti->nji.btSensRes,abtRx+2,2);
memcpy(pti->tij.btId,abtRx+4,4); memcpy(pnti->nji.btId,abtRx+4,4);
break; break;
default: default:

View file

@ -86,7 +86,7 @@ bool nfc_configure(nfc_device_t* pnd, const nfc_device_option_t ndo, const bool
bool nfc_initiator_init(const nfc_device_t* pnd); bool nfc_initiator_init(const nfc_device_t* pnd);
/** /**
* @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) * @fn nfc_initiator_select_tag(const nfc_device_t* pnd, const nfc_modulation_t nmInitModulation, const byte_t* pbtInitData, const size_t szInitDataLen, nfc_target_info_t* pti)
* @brief Select a passive or emulated tag * @brief Select a passive or emulated tag
* @return Returns true if action was successfully performed; otherwise returns false. * @return Returns true if action was successfully performed; otherwise returns false.
* @param pnd nfc_device_t struct pointer that represent currently used device * @param pnd nfc_device_t struct pointer that represent currently used device
@ -95,24 +95,24 @@ bool nfc_initiator_init(const nfc_device_t* pnd);
* @param szInitDataLen Length of initiator data \a pbtInitData. * @param szInitDataLen Length of initiator data \a pbtInitData.
* *
* 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. * 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. * @note For every initial modulation type there is a different collection of information returned (in nfc_target_info_t pointer pti) They all fit in the data-type which is called nfc_target_info_t. This is a union which contains the tag information that belongs to the according initial modulation type.
*/ */
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); bool nfc_initiator_select_tag(const nfc_device_t* pnd, const nfc_modulation_t nmInitModulation, const byte_t* pbtInitData, const size_t szInitDataLen, nfc_target_info_t* 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); * @fn nfc_initiator_select_dep_target(const nfc_device_t *pnd, const nfc_modulation_t nmInitModulation, const byte_t *pbtPidData, const size_t szPidDataLen, const byte_t *pbtNFCID3i, const size_t szNFCID3iDataLen, const byte_t *pbtGbData, const size_t szGbDataLen, nfc_target_info_t * pti);
* @brief Select a target and request active or passive mode for DEP (Data Exchange Protocol) * @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. * @return Returns true if action was successfully performed; otherwise returns false.
* @param pnd nfc_device_t 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 im Desired modulation (NM_ACTIVE_DEP or NM_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 pbtPidData passive initiator data, 4 or 5 bytes long, (optional, only for NM_PASSIVE_DEP, can be NULL)
* @param pbtNFCID3i the NFCID3, 10 bytes long, of the initiator (optional, can be NULL) * @param pbtNFCID3i the NFCID3, 10 bytes long, of the initiator (optional, can be NULL)
* @param pbtGbData generic data of the initiator, max 48 bytes long, (optional, can be NULL) * @param pbtGbData generic data of the initiator, max 48 bytes long, (optional, can be NULL)
* *
* 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. * 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. * @note nfc_target_info_t_dep will be returned when the target was acquired successfully.
*/ */
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); bool nfc_initiator_select_dep_target(const nfc_device_t* pnd, const nfc_modulation_t nmInitModulation, const byte_t* pbtPidData, const size_t szPidDataLen, const byte_t* pbtNFCID3i, const size_t szNFCID3iDataLen, const byte_t *pbtGbData, const size_t szGbDataLen, nfc_target_info_t* pti);
/** /**
* @fn nfc_initiator_deselect_tag(const nfc_device_t* pnd); * @fn nfc_initiator_deselect_tag(const nfc_device_t* pnd);
* @brief Deselect a selected passive or emulated tag * @brief Deselect a selected passive or emulated tag