pn53x_target_init() now takes care of Historical Bytes

This commit is contained in:
Romuald Conty 2010-10-14 17:38:54 +00:00
parent 4a50be27de
commit 41758ab63f
4 changed files with 29 additions and 12 deletions

View file

@ -107,6 +107,7 @@ extern "C" {
/* Misc. functions */ /* Misc. functions */
NFC_EXPORT void iso14443a_crc (byte_t * pbtData, size_t szLen, byte_t * pbtCrc); NFC_EXPORT void iso14443a_crc (byte_t * pbtData, size_t szLen, byte_t * pbtCrc);
NFC_EXPORT void append_iso14443a_crc (byte_t * pbtData, size_t szLen); NFC_EXPORT void append_iso14443a_crc (byte_t * pbtData, size_t szLen);
NFC_EXPORT byte_t * iso14443a_extract_historical_bytes (byte_t * pbtAts, size_t szAts, size_t * pszHB);
NFC_EXPORT const char *nfc_version (void); NFC_EXPORT const char *nfc_version (void);
/* Common device-level errors */ /* Common device-level errors */

View file

@ -1157,8 +1157,11 @@ pn53x_target_init (nfc_device_t * pnd, const nfc_target_mode_t ntm, nfc_target_t
return false; return false;
byte_t abtMifareParams[6]; byte_t abtMifareParams[6];
byte_t abtFeliCaParams[18];
byte_t * pbtMifareParams = NULL; byte_t * pbtMifareParams = NULL;
byte_t * pbtHBt = NULL;
size_t szHBt = 0;
byte_t abtFeliCaParams[18];
byte_t * pbtFeliCaParams = NULL; byte_t * pbtFeliCaParams = NULL;
const byte_t * pbtNFCID3t = NULL; const byte_t * pbtNFCID3t = NULL;
@ -1179,6 +1182,9 @@ pn53x_target_init (nfc_device_t * pnd, const nfc_target_mode_t ntm, nfc_target_t
abtMifareParams[5] = pnt->nti.nai.btSak; abtMifareParams[5] = pnt->nti.nai.btSak;
pbtMifareParams = abtMifareParams; pbtMifareParams = abtMifareParams;
// Historical Bytes
pbtHBt = iso14443a_extract_historical_bytes (pnt->nti.nai.abtAts, pnt->nti.nai.szAtsLen, &szHBt);
} }
break; break;
@ -1208,7 +1214,7 @@ pn53x_target_init (nfc_device_t * pnd, const nfc_target_mode_t ntm, nfc_target_t
byte_t btActivatedMode; byte_t btActivatedMode;
target_activation: target_activation:
if(!pn53x_TgInitAsTarget(pnd, ntm, pbtMifareParams, pbtFeliCaParams, pbtNFCID3t, pbtGBt, szGBt, pbtRx, pszRx, &btActivatedMode)) { if(!pn53x_TgInitAsTarget(pnd, ntm, pbtMifareParams, pbtHBt, szHBt, pbtFeliCaParams, pbtNFCID3t, pbtGBt, szGBt, pbtRx, pszRx, &btActivatedMode)) {
return false; return false;
} }
@ -1258,8 +1264,9 @@ target_activation:
bool bool
pn53x_TgInitAsTarget (nfc_device_t * pnd, nfc_target_mode_t ntm, pn53x_TgInitAsTarget (nfc_device_t * pnd, nfc_target_mode_t ntm,
const byte_t * pbtMifareParams, const byte_t * pbtMifareParams,
const byte_t * pbtHBt, size_t szHBt,
const byte_t * pbtFeliCaParams, const byte_t * pbtFeliCaParams,
const byte_t * pbtNFCID3t, const byte_t * pbtGB, const size_t szGB, const byte_t * pbtNFCID3t, const byte_t * pbtGBt, const size_t szGBt,
byte_t * pbtRx, size_t * pszRx, byte_t * pbtModeByte) byte_t * pbtRx, size_t * pszRx, byte_t * pbtModeByte)
{ {
byte_t abtRx[MAX_FRAME_LEN]; byte_t abtRx[MAX_FRAME_LEN];
@ -1287,17 +1294,25 @@ pn53x_TgInitAsTarget (nfc_device_t * pnd, nfc_target_mode_t ntm,
if (pbtNFCID3t) { if (pbtNFCID3t) {
memcpy(abtCmd+27, pbtNFCID3t, 10); memcpy(abtCmd+27, pbtNFCID3t, 10);
} }
if (szGB) { // General Bytes (ISO/IEC 18092)
if (szGBt) {
if (pnd->nc == NC_PN531) { if (pnd->nc == NC_PN531) {
memcpy (abtCmd+37, pbtGB, szGB); memcpy (abtCmd+37, pbtGBt, szGBt);
szOptionalBytes = szGB; szOptionalBytes = szGBt;
} else { } else {
abtCmd[37] = (byte_t)(szGB); abtCmd[37] = (byte_t)(szGBt);
memcpy (abtCmd+38, pbtGB, szGB); memcpy (abtCmd+38, pbtGBt, szGBt);
szOptionalBytes = szGB + 1; szOptionalBytes = szGBt + 1;
}
}
// Historical bytes (ISO/IEC 14443-4)
if (pnd->nc != NC_PN531) { // PN531 does not handle Historical Bytes
if (szHBt) {
abtCmd[37+szOptionalBytes] = (byte_t)(szHBt);
memcpy (abtCmd+38+szOptionalBytes, pbtHBt, szHBt);
szOptionalBytes += szHBt + 1;
} }
} }
// TODO Handle Tk (Historical bytes) length (only available on PN532, PN533)
// Request the initialization as a target // Request the initialization as a target
szRx = MAX_FRAME_LEN; szRx = MAX_FRAME_LEN;

View file

@ -223,6 +223,7 @@ bool pn53x_InJumpForDEP (nfc_device_t * pnd,
nfc_target_t * pnt); nfc_target_t * pnt);
bool pn53x_TgInitAsTarget (nfc_device_t * pnd, nfc_target_mode_t ntm, bool pn53x_TgInitAsTarget (nfc_device_t * pnd, nfc_target_mode_t ntm,
const byte_t * pbtMifareParams, const byte_t * pbtMifareParams,
const byte_t * pbtHBt, size_t szHBt,
const byte_t * pbtFeliCaParams, const byte_t * pbtFeliCaParams,
const byte_t * pbtNFCID3t, const byte_t * pbtGB, const size_t szGB, const byte_t * pbtNFCID3t, const byte_t * pbtGB, const size_t szGB,
byte_t * pbtRx, size_t * pszRx, byte_t * pbtModeByte); byte_t * pbtRx, size_t * pszRx, byte_t * pbtModeByte);

View file

@ -54,7 +54,7 @@ append_iso14443a_crc (byte_t * pbtData, size_t szLen)
} }
byte_t * byte_t *
extract_historical_bytes(byte_t * pbtAts, size_t szAts, size_t * pszHB) iso14443a_extract_historical_bytes(byte_t * pbtAts, size_t szAts, size_t * pszHB)
{ {
if (szAts) { if (szAts) {
size_t offset = 1; size_t offset = 1;