Move ISO14443-3 UID cascading in a dedicated function.
This commit is contained in:
parent
0b42cbfb8f
commit
699e9008d1
3 changed files with 34 additions and 23 deletions
|
@ -27,6 +27,7 @@
|
||||||
#endif // HAVE_CONFIG_H
|
#endif // HAVE_CONFIG_H
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
#include <nfc/nfc.h>
|
#include <nfc/nfc.h>
|
||||||
|
|
||||||
|
@ -54,7 +55,7 @@ iso14443a_crc_append (byte_t * pbtData, size_t szLen)
|
||||||
}
|
}
|
||||||
|
|
||||||
byte_t *
|
byte_t *
|
||||||
iso14443a_locate_historical_bytes(byte_t * pbtAts, size_t szAts, size_t * pszTk)
|
iso14443a_locate_historical_bytes (byte_t * pbtAts, size_t szAts, size_t * pszTk)
|
||||||
{
|
{
|
||||||
if (szAts) {
|
if (szAts) {
|
||||||
size_t offset = 1;
|
size_t offset = 1;
|
||||||
|
@ -75,3 +76,33 @@ iso14443a_locate_historical_bytes(byte_t * pbtAts, size_t szAts, size_t * pszTk)
|
||||||
*pszTk = 0;
|
*pszTk = 0;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Add cascade tags (0x88) in UID
|
||||||
|
* @see ISO/IEC 14443-3 (6.4.4 UID contents and cascade levels)
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
iso14443_cascade_uid (const byte_t abtUID[], const size_t szUID, byte_t * pbtCascadedUID, size_t * pszCascadedUID)
|
||||||
|
{
|
||||||
|
switch (szUID) {
|
||||||
|
case 7:
|
||||||
|
pbtCascadedUID[0] = 0x88;
|
||||||
|
memcpy (pbtCascadedUID + 1, abtUID, 7);
|
||||||
|
*pszCascadedUID = 8;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 10:
|
||||||
|
pbtCascadedUID[0] = 0x88;
|
||||||
|
memcpy (pbtCascadedUID + 1, abtUID, 3);
|
||||||
|
pbtCascadedUID[4] = 0x88;
|
||||||
|
memcpy (pbtCascadedUID + 5, abtUID + 3, 7);
|
||||||
|
*pszCascadedUID = 12;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 4:
|
||||||
|
default:
|
||||||
|
memcpy (pbtCascadedUID, abtUID, szUID);
|
||||||
|
*pszCascadedUID = szUID;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -213,5 +213,6 @@ struct nfc_driver_t {
|
||||||
nfc_device_t *nfc_device_new (void);
|
nfc_device_t *nfc_device_new (void);
|
||||||
void nfc_device_free (nfc_device_t *nfc_device);
|
void nfc_device_free (nfc_device_t *nfc_device);
|
||||||
|
|
||||||
|
void iso14443_cascade_uid (const byte_t abtUID[], const size_t szUID, byte_t * pbtCascadedUID, size_t * pszCascadedUID);
|
||||||
|
|
||||||
#endif // __NFC_INTERNAL_H__
|
#endif // __NFC_INTERNAL_H__
|
||||||
|
|
23
libnfc/nfc.c
23
libnfc/nfc.c
|
@ -299,30 +299,9 @@ nfc_initiator_select_passive_target (nfc_device_t * pnd,
|
||||||
byte_t abtInit[MAX(12, szInitData)];
|
byte_t abtInit[MAX(12, szInitData)];
|
||||||
size_t szInit;
|
size_t szInit;
|
||||||
|
|
||||||
// TODO Put this in a function: this part is defined by ISO14443-3 (UID and Cascade levels)
|
|
||||||
switch (nm.nmt) {
|
switch (nm.nmt) {
|
||||||
case NMT_ISO14443A:
|
case NMT_ISO14443A:
|
||||||
switch (szInitData) {
|
iso14443_cascade_uid (pbtInitData, szInitData, abtInit, &szInit);
|
||||||
case 7:
|
|
||||||
abtInit[0] = 0x88;
|
|
||||||
memcpy (abtInit + 1, pbtInitData, 7);
|
|
||||||
szInit = 8;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 10:
|
|
||||||
abtInit[0] = 0x88;
|
|
||||||
memcpy (abtInit + 1, pbtInitData, 3);
|
|
||||||
abtInit[4] = 0x88;
|
|
||||||
memcpy (abtInit + 5, pbtInitData + 3, 7);
|
|
||||||
szInit = 12;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 4:
|
|
||||||
default:
|
|
||||||
memcpy (abtInit, pbtInitData, szInitData);
|
|
||||||
szInit = szInitData;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|
Loading…
Reference in a new issue