astyle --formatted --mode=c --indent=spaces=2 --indent-switches --indent-preprocessor --keep-one-line-blocks --max-instatement-indent=60
This commit is contained in:
parent
26569c2202
commit
a2cd236441
45 changed files with 1096 additions and 1082 deletions
|
@ -4,15 +4,15 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#define warnx(...) do { \
|
#define warnx(...) do { \
|
||||||
fprintf (stderr, __VA_ARGS__); \
|
fprintf (stderr, __VA_ARGS__); \
|
||||||
fprintf (stderr, "\n"); \
|
fprintf (stderr, "\n"); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#define errx(code, ...) do { \
|
#define errx(code, ...) do { \
|
||||||
fprintf (stderr, __VA_ARGS__); \
|
fprintf (stderr, __VA_ARGS__); \
|
||||||
fprintf (stderr, "\n"); \
|
fprintf (stderr, "\n"); \
|
||||||
exit (code); \
|
exit (code); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#define err errx
|
#define err errx
|
||||||
|
|
||||||
|
|
|
@ -277,13 +277,13 @@ main (int argc, char *argv[])
|
||||||
|
|
||||||
// Request ATS, this only applies to tags that support ISO 14443A-4
|
// Request ATS, this only applies to tags that support ISO 14443A-4
|
||||||
if (abtRx[0] & SAK_FLAG_ATS_SUPPORTED) {
|
if (abtRx[0] & SAK_FLAG_ATS_SUPPORTED) {
|
||||||
iso_ats_supported = true;
|
iso_ats_supported = true;
|
||||||
}
|
}
|
||||||
if ((abtRx[0] & SAK_FLAG_ATS_SUPPORTED) || force_rats) {
|
if ((abtRx[0] & SAK_FLAG_ATS_SUPPORTED) || force_rats) {
|
||||||
iso14443a_crc_append(abtRats, 2);
|
iso14443a_crc_append(abtRats, 2);
|
||||||
if (transmit_bytes (abtRats, 4)) {
|
if (transmit_bytes (abtRats, 4)) {
|
||||||
memcpy (abtAts, abtRx, szRx);
|
memcpy (abtAts, abtRx, szRx);
|
||||||
szAts = szRx;
|
szAts = szRx;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -295,25 +295,25 @@ main (int argc, char *argv[])
|
||||||
switch (szCL) {
|
switch (szCL) {
|
||||||
case 1:
|
case 1:
|
||||||
printf ("%02x%02x%02x%02x", abtRawUid[0], abtRawUid[1], abtRawUid[2], abtRawUid[3]);
|
printf ("%02x%02x%02x%02x", abtRawUid[0], abtRawUid[1], abtRawUid[2], abtRawUid[3]);
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
printf ("%02x%02x%02x", abtRawUid[1], abtRawUid[2], abtRawUid[3]);
|
printf ("%02x%02x%02x", abtRawUid[1], abtRawUid[2], abtRawUid[3]);
|
||||||
printf ("%02x%02x%02x%02x", abtRawUid[4], abtRawUid[5], abtRawUid[6], abtRawUid[7]);
|
printf ("%02x%02x%02x%02x", abtRawUid[4], abtRawUid[5], abtRawUid[6], abtRawUid[7]);
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
printf ("%02x%02x%02x", abtRawUid[1], abtRawUid[2], abtRawUid[3]);
|
printf ("%02x%02x%02x", abtRawUid[1], abtRawUid[2], abtRawUid[3]);
|
||||||
printf ("%02x%02x%02x", abtRawUid[5], abtRawUid[6], abtRawUid[7]);
|
printf ("%02x%02x%02x", abtRawUid[5], abtRawUid[6], abtRawUid[7]);
|
||||||
printf ("%02x%02x%02x%02x", abtRawUid[8], abtRawUid[9], abtRawUid[10], abtRawUid[11]);
|
printf ("%02x%02x%02x%02x", abtRawUid[8], abtRawUid[9], abtRawUid[10], abtRawUid[11]);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
printf("\n");
|
printf("\n");
|
||||||
printf("ATQA: %02x%02x\n SAK: %02x\n", abtAtqa[1], abtAtqa[0], abtSak);
|
printf("ATQA: %02x%02x\n SAK: %02x\n", abtAtqa[1], abtAtqa[0], abtSak);
|
||||||
if (szAts > 1) { // if = 1, it's not actual ATS but error code
|
if (szAts > 1) { // if = 1, it's not actual ATS but error code
|
||||||
if (force_rats && ! iso_ats_supported) {
|
if (force_rats && ! iso_ats_supported) {
|
||||||
printf(" RATS forced\n");
|
printf(" RATS forced\n");
|
||||||
}
|
}
|
||||||
printf(" ATS: ");
|
printf(" ATS: ");
|
||||||
print_hex (abtAts, szAts);
|
print_hex (abtAts, szAts);
|
||||||
}
|
}
|
||||||
|
|
||||||
nfc_close (pnd);
|
nfc_close (pnd);
|
||||||
|
|
|
@ -64,7 +64,7 @@ main (int argc, const char *argv[])
|
||||||
uint8_t abtRx[MAX_FRAME_LEN];
|
uint8_t abtRx[MAX_FRAME_LEN];
|
||||||
int szRx;
|
int szRx;
|
||||||
uint8_t abtTx[] = "Hello Mars!";
|
uint8_t abtTx[] = "Hello Mars!";
|
||||||
#define MAX_DEVICE_COUNT 2
|
#define MAX_DEVICE_COUNT 2
|
||||||
nfc_connstring connstrings[MAX_DEVICE_COUNT];
|
nfc_connstring connstrings[MAX_DEVICE_COUNT];
|
||||||
size_t szDeviceFound = nfc_list_devices (NULL, connstrings, MAX_DEVICE_COUNT);
|
size_t szDeviceFound = nfc_list_devices (NULL, connstrings, MAX_DEVICE_COUNT);
|
||||||
// Little hack to allow using nfc-dep-initiator & nfc-dep-target from
|
// Little hack to allow using nfc-dep-initiator & nfc-dep-target from
|
||||||
|
@ -96,7 +96,7 @@ main (int argc, const char *argv[])
|
||||||
.abtNFCID3 = { 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xff, 0x00, 0x00 },
|
.abtNFCID3 = { 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xff, 0x00, 0x00 },
|
||||||
.szGB = 4,
|
.szGB = 4,
|
||||||
.abtGB = { 0x12, 0x34, 0x56, 0x78 },
|
.abtGB = { 0x12, 0x34, 0x56, 0x78 },
|
||||||
.ndm = NDM_UNDEFINED,
|
.ndm = NDM_UNDEFINED,
|
||||||
/* These bytes are not used by nfc_target_init: the chip will provide them automatically to the initiator */
|
/* These bytes are not used by nfc_target_init: the chip will provide them automatically to the initiator */
|
||||||
.btDID = 0x00,
|
.btDID = 0x00,
|
||||||
.btBS = 0x00,
|
.btBS = 0x00,
|
||||||
|
|
|
@ -78,7 +78,7 @@ stop_emulation (int sig)
|
||||||
{
|
{
|
||||||
(void)sig;
|
(void)sig;
|
||||||
if (pnd) {
|
if (pnd) {
|
||||||
nfc_abort_command(pnd);
|
nfc_abort_command(pnd);
|
||||||
} else {
|
} else {
|
||||||
exit (EXIT_FAILURE);
|
exit (EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
|
@ -178,27 +178,27 @@ main (int argc, char *argv[])
|
||||||
if ((szRecvBits = nfc_target_receive_bits (pnd, abtRecv, sizeof (abtRecv), 0)) > 0) {
|
if ((szRecvBits = nfc_target_receive_bits (pnd, abtRecv, sizeof (abtRecv), 0)) > 0) {
|
||||||
// Prepare the command to send back for the anti-collision request
|
// Prepare the command to send back for the anti-collision request
|
||||||
switch (szRecvBits) {
|
switch (szRecvBits) {
|
||||||
case 7: // Request or Wakeup
|
case 7: // Request or Wakeup
|
||||||
pbtTx = abtAtqa;
|
pbtTx = abtAtqa;
|
||||||
szTxBits = 16;
|
szTxBits = 16;
|
||||||
// New anti-collsion session started
|
// New anti-collsion session started
|
||||||
if (!quiet_output)
|
if (!quiet_output)
|
||||||
printf ("\n");
|
printf ("\n");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 16: // Select All
|
case 16: // Select All
|
||||||
pbtTx = abtUidBcc;
|
pbtTx = abtUidBcc;
|
||||||
szTxBits = 40;
|
szTxBits = 40;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 72: // Select Tag
|
case 72: // Select Tag
|
||||||
pbtTx = abtSak;
|
pbtTx = abtSak;
|
||||||
szTxBits = 24;
|
szTxBits = 24;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default: // unknown length?
|
default: // unknown length?
|
||||||
szTxBits = 0;
|
szTxBits = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!quiet_output) {
|
if (!quiet_output) {
|
||||||
|
|
|
@ -163,13 +163,13 @@ main (int argc, char *argv[])
|
||||||
} else if (0 == strcmp (argv[arg], "-q")) {
|
} else if (0 == strcmp (argv[arg], "-q")) {
|
||||||
quiet_output = true;
|
quiet_output = true;
|
||||||
} else if (strlen(argv[arg]) == 8) {
|
} else if (strlen(argv[arg]) == 8) {
|
||||||
for(i= 0 ; i < 4 ; ++i) {
|
for(i= 0 ; i < 4 ; ++i) {
|
||||||
memcpy(tmp, argv[arg]+i*2, 2);
|
memcpy(tmp, argv[arg]+i*2, 2);
|
||||||
sscanf(tmp, "%02x", &c);
|
sscanf(tmp, "%02x", &c);
|
||||||
abtData[i]= (char) c;
|
abtData[i]= (char) c;
|
||||||
}
|
}
|
||||||
abtData[4]= abtData[0] ^ abtData[1] ^ abtData[2] ^ abtData[3];
|
abtData[4]= abtData[0] ^ abtData[1] ^ abtData[2] ^ abtData[3];
|
||||||
iso14443a_crc_append (abtData, 16);
|
iso14443a_crc_append (abtData, 16);
|
||||||
} else {
|
} else {
|
||||||
ERR ("%s is not supported option.", argv[arg]);
|
ERR ("%s is not supported option.", argv[arg]);
|
||||||
print_usage (argv);
|
print_usage (argv);
|
||||||
|
@ -305,29 +305,29 @@ main (int argc, char *argv[])
|
||||||
|
|
||||||
// Request ATS, this only applies to tags that support ISO 14443A-4
|
// Request ATS, this only applies to tags that support ISO 14443A-4
|
||||||
if (abtRx[0] & SAK_FLAG_ATS_SUPPORTED) {
|
if (abtRx[0] & SAK_FLAG_ATS_SUPPORTED) {
|
||||||
iso_ats_supported = true;
|
iso_ats_supported = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
printf ("\nFound tag with\n UID: ");
|
printf ("\nFound tag with\n UID: ");
|
||||||
switch (szCL) {
|
switch (szCL) {
|
||||||
case 1:
|
case 1:
|
||||||
printf ("%02x%02x%02x%02x", abtRawUid[0], abtRawUid[1], abtRawUid[2], abtRawUid[3]);
|
printf ("%02x%02x%02x%02x", abtRawUid[0], abtRawUid[1], abtRawUid[2], abtRawUid[3]);
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
printf ("%02x%02x%02x", abtRawUid[1], abtRawUid[2], abtRawUid[3]);
|
printf ("%02x%02x%02x", abtRawUid[1], abtRawUid[2], abtRawUid[3]);
|
||||||
printf ("%02x%02x%02x%02x", abtRawUid[4], abtRawUid[5], abtRawUid[6], abtRawUid[7]);
|
printf ("%02x%02x%02x%02x", abtRawUid[4], abtRawUid[5], abtRawUid[6], abtRawUid[7]);
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
printf ("%02x%02x%02x", abtRawUid[1], abtRawUid[2], abtRawUid[3]);
|
printf ("%02x%02x%02x", abtRawUid[1], abtRawUid[2], abtRawUid[3]);
|
||||||
printf ("%02x%02x%02x", abtRawUid[5], abtRawUid[6], abtRawUid[7]);
|
printf ("%02x%02x%02x", abtRawUid[5], abtRawUid[6], abtRawUid[7]);
|
||||||
printf ("%02x%02x%02x%02x", abtRawUid[8], abtRawUid[9], abtRawUid[10], abtRawUid[11]);
|
printf ("%02x%02x%02x%02x", abtRawUid[8], abtRawUid[9], abtRawUid[10], abtRawUid[11]);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
printf("\n");
|
printf("\n");
|
||||||
printf("ATQA: %02x%02x\n SAK: %02x\n", abtAtqa[1], abtAtqa[0], abtSak);
|
printf("ATQA: %02x%02x\n SAK: %02x\n", abtAtqa[1], abtAtqa[0], abtSak);
|
||||||
if (szAts > 1) { // if = 1, it's not actual ATS but error code
|
if (szAts > 1) { // if = 1, it's not actual ATS but error code
|
||||||
printf(" ATS: ");
|
printf(" ATS: ");
|
||||||
print_hex (abtAts, szAts);
|
print_hex (abtAts, szAts);
|
||||||
}
|
}
|
||||||
printf("\n");
|
printf("\n");
|
||||||
|
|
||||||
|
|
|
@ -205,7 +205,7 @@ main (int argc, char *argv[])
|
||||||
}
|
}
|
||||||
// Forward the frame to the original tag
|
// Forward the frame to the original tag
|
||||||
if ((szTagRxBits = nfc_initiator_transceive_bits
|
if ((szTagRxBits = nfc_initiator_transceive_bits
|
||||||
(pndReader, abtReaderRx, (size_t) szReaderRxBits, abtReaderRxPar, abtTagRx, abtTagRxPar)) > 0) {
|
(pndReader, abtReaderRx, (size_t) szReaderRxBits, abtReaderRxPar, abtTagRx, abtTagRxPar)) > 0) {
|
||||||
// Redirect the answer back to the reader
|
// Redirect the answer back to the reader
|
||||||
if (nfc_target_send_bits (pndTag, abtTagRx, szTagRxBits, abtTagRxPar) < 0) {
|
if (nfc_target_send_bits (pndTag, abtTagRx, szTagRxBits, abtTagRxPar) < 0) {
|
||||||
nfc_perror (pndTag, "nfc_target_send_bits");
|
nfc_perror (pndTag, "nfc_target_send_bits");
|
||||||
|
|
|
@ -125,14 +125,14 @@ main (int argc, const char *argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (mode) {
|
switch (mode) {
|
||||||
case PSM_VIRTUAL_CARD:
|
case PSM_VIRTUAL_CARD:
|
||||||
{
|
{
|
||||||
printf ("Now the SAM is readable for 1 minute from an external reader.\n");
|
printf ("Now the SAM is readable for 1 minute from an external reader.\n");
|
||||||
wait_one_minute ();
|
wait_one_minute ();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PSM_WIRED_CARD:
|
case PSM_WIRED_CARD:
|
||||||
{
|
{
|
||||||
nfc_target nt;
|
nfc_target nt;
|
||||||
|
|
||||||
|
@ -169,7 +169,7 @@ main (int argc, const char *argv[])
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PSM_DUAL_CARD:
|
case PSM_DUAL_CARD:
|
||||||
{
|
{
|
||||||
uint8_t abtRx[MAX_FRAME_LEN];
|
uint8_t abtRx[MAX_FRAME_LEN];
|
||||||
|
|
||||||
|
@ -197,8 +197,8 @@ main (int argc, const char *argv[])
|
||||||
// wait_one_minute ();
|
// wait_one_minute ();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case PSM_NORMAL:
|
case PSM_NORMAL:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
ret = EXIT_SUCCESS;
|
ret = EXIT_SUCCESS;
|
||||||
|
|
||||||
|
|
|
@ -148,7 +148,7 @@ int main(int argc, const char* argv[])
|
||||||
sscanf(cmd + offset, "%d", &s);
|
sscanf(cmd + offset, "%d", &s);
|
||||||
printf("Pause for %i msecs\n", s);
|
printf("Pause for %i msecs\n", s);
|
||||||
if (s>0) {
|
if (s>0) {
|
||||||
sleep(s * SUSP_TIME);
|
sleep(s * SUSP_TIME);
|
||||||
}
|
}
|
||||||
free(cmd);
|
free(cmd);
|
||||||
continue;
|
continue;
|
||||||
|
|
|
@ -32,29 +32,29 @@
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif /* __cplusplus */
|
#endif /* __cplusplus */
|
||||||
|
|
||||||
struct nfc_emulator;
|
struct nfc_emulator;
|
||||||
struct nfc_emulation_state_machine;
|
struct nfc_emulation_state_machine;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @struct nfc_emulator
|
* @struct nfc_emulator
|
||||||
* @brief NFC emulator structure
|
* @brief NFC emulator structure
|
||||||
*/
|
*/
|
||||||
struct nfc_emulator {
|
struct nfc_emulator {
|
||||||
nfc_target *target;
|
nfc_target *target;
|
||||||
struct nfc_emulation_state_machine *state_machine;
|
struct nfc_emulation_state_machine *state_machine;
|
||||||
void *user_data;
|
void *user_data;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @struct nfc_emulation_state_machine
|
* @struct nfc_emulation_state_machine
|
||||||
* @brief NFC emulation state machine structure
|
* @brief NFC emulation state machine structure
|
||||||
*/
|
*/
|
||||||
struct nfc_emulation_state_machine {
|
struct nfc_emulation_state_machine {
|
||||||
int (*io)(struct nfc_emulator *emulator, const uint8_t *data_in, const size_t data_in_len, uint8_t *data_out, const size_t data_out_len);
|
int (*io)(struct nfc_emulator *emulator, const uint8_t *data_in, const size_t data_in_len, uint8_t *data_out, const size_t data_out_len);
|
||||||
void *data;
|
void *data;
|
||||||
};
|
};
|
||||||
|
|
||||||
NFC_EXPORT int nfc_emulate_target (nfc_device* pnd, struct nfc_emulator *emulator);
|
NFC_EXPORT int nfc_emulate_target (nfc_device* pnd, struct nfc_emulator *emulator);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,79 +48,79 @@ typedef char nfc_connstring[1024];
|
||||||
* Properties
|
* Properties
|
||||||
*/
|
*/
|
||||||
typedef enum {
|
typedef enum {
|
||||||
/**
|
/**
|
||||||
* Default command processing timeout
|
* Default command processing timeout
|
||||||
* Property value's (duration) unit is ms and 0 means no timeout (infinite).
|
* Property value's (duration) unit is ms and 0 means no timeout (infinite).
|
||||||
* Default value is set by driver layer
|
* Default value is set by driver layer
|
||||||
*/
|
*/
|
||||||
NP_TIMEOUT_COMMAND,
|
NP_TIMEOUT_COMMAND,
|
||||||
/**
|
/**
|
||||||
* Timeout between ATR_REQ and ATR_RES
|
* Timeout between ATR_REQ and ATR_RES
|
||||||
* When the device is in initiator mode, a target is considered as mute if no
|
* When the device is in initiator mode, a target is considered as mute if no
|
||||||
* valid ATR_RES is received within this timeout value.
|
* valid ATR_RES is received within this timeout value.
|
||||||
* Default value for this property is 103 ms on PN53x based devices.
|
* Default value for this property is 103 ms on PN53x based devices.
|
||||||
*/
|
*/
|
||||||
NP_TIMEOUT_ATR,
|
NP_TIMEOUT_ATR,
|
||||||
/**
|
/**
|
||||||
* Timeout value to give up reception from the target in case of no answer.
|
* Timeout value to give up reception from the target in case of no answer.
|
||||||
* Default value for this property is 52 ms).
|
* Default value for this property is 52 ms).
|
||||||
*/
|
*/
|
||||||
NP_TIMEOUT_COM,
|
NP_TIMEOUT_COM,
|
||||||
/** Let the PN53X chip handle the CRC bytes. This means that the chip appends
|
/** Let the PN53X chip handle the CRC bytes. This means that the chip appends
|
||||||
* the CRC bytes to the frames that are transmitted. It will parse the last
|
* the CRC bytes to the frames that are transmitted. It will parse the last
|
||||||
* bytes from received frames as incoming CRC bytes. They will be verified
|
* bytes from received frames as incoming CRC bytes. They will be verified
|
||||||
* against the used modulation and protocol. If an frame is expected with
|
* against the used modulation and protocol. If an frame is expected with
|
||||||
* incorrect CRC bytes this option should be disabled. Example frames where
|
* incorrect CRC bytes this option should be disabled. Example frames where
|
||||||
* this is useful are the ATQA and UID+BCC that are transmitted without CRC
|
* this is useful are the ATQA and UID+BCC that are transmitted without CRC
|
||||||
* bytes during the anti-collision phase of the ISO14443-A protocol. */
|
* bytes during the anti-collision phase of the ISO14443-A protocol. */
|
||||||
NP_HANDLE_CRC,
|
NP_HANDLE_CRC,
|
||||||
/** Parity bits in the network layer of ISO14443-A are by default generated and
|
/** Parity bits in the network layer of ISO14443-A are by default generated and
|
||||||
* validated in the PN53X chip. This is a very convenient feature. On certain
|
* validated in the PN53X chip. This is a very convenient feature. On certain
|
||||||
* times though it is useful to get full control of the transmitted data. The
|
* times though it is useful to get full control of the transmitted data. The
|
||||||
* proprietary MIFARE Classic protocol uses for example custom (encrypted)
|
* proprietary MIFARE Classic protocol uses for example custom (encrypted)
|
||||||
* parity bits. For interoperability it is required to be completely
|
* parity bits. For interoperability it is required to be completely
|
||||||
* compatible, including the arbitrary parity bits. When this option is
|
* compatible, including the arbitrary parity bits. When this option is
|
||||||
* disabled, the functions to communicating bits should be used. */
|
* disabled, the functions to communicating bits should be used. */
|
||||||
NP_HANDLE_PARITY,
|
NP_HANDLE_PARITY,
|
||||||
/** This option can be used to enable or disable the electronic field of the
|
/** This option can be used to enable or disable the electronic field of the
|
||||||
* NFC device. */
|
* NFC device. */
|
||||||
NP_ACTIVATE_FIELD,
|
NP_ACTIVATE_FIELD,
|
||||||
/** The internal CRYPTO1 co-processor can be used to transmit messages
|
/** The internal CRYPTO1 co-processor can be used to transmit messages
|
||||||
* encrypted. This option is automatically activated after a successful MIFARE
|
* encrypted. This option is automatically activated after a successful MIFARE
|
||||||
* Classic authentication. */
|
* Classic authentication. */
|
||||||
NP_ACTIVATE_CRYPTO1,
|
NP_ACTIVATE_CRYPTO1,
|
||||||
/** The default configuration defines that the PN53X chip will try indefinitely
|
/** The default configuration defines that the PN53X chip will try indefinitely
|
||||||
* to invite a tag in the field to respond. This could be desired when it is
|
* to invite a tag in the field to respond. This could be desired when it is
|
||||||
* certain a tag will enter the field. On the other hand, when this is
|
* certain a tag will enter the field. On the other hand, when this is
|
||||||
* uncertain, it will block the application. This option could best be compared
|
* uncertain, it will block the application. This option could best be compared
|
||||||
* to the (NON)BLOCKING option used by (socket)network programming. */
|
* to the (NON)BLOCKING option used by (socket)network programming. */
|
||||||
NP_INFINITE_SELECT,
|
NP_INFINITE_SELECT,
|
||||||
/** If this option is enabled, frames that carry less than 4 bits are allowed.
|
/** If this option is enabled, frames that carry less than 4 bits are allowed.
|
||||||
* According to the standards these frames should normally be handles as
|
* According to the standards these frames should normally be handles as
|
||||||
* invalid frames. */
|
* invalid frames. */
|
||||||
NP_ACCEPT_INVALID_FRAMES,
|
NP_ACCEPT_INVALID_FRAMES,
|
||||||
/** If the NFC device should only listen to frames, it could be useful to let
|
/** If the NFC device should only listen to frames, it could be useful to let
|
||||||
* it gather multiple frames in a sequence. They will be stored in the internal
|
* it gather multiple frames in a sequence. They will be stored in the internal
|
||||||
* FIFO of the PN53X chip. This could be retrieved by using the receive data
|
* FIFO of the PN53X chip. This could be retrieved by using the receive data
|
||||||
* functions. Note that if the chip runs out of bytes (FIFO = 64 bytes long),
|
* functions. Note that if the chip runs out of bytes (FIFO = 64 bytes long),
|
||||||
* it will overwrite the first received frames, so quick retrieving of the
|
* it will overwrite the first received frames, so quick retrieving of the
|
||||||
* received data is desirable. */
|
* received data is desirable. */
|
||||||
NP_ACCEPT_MULTIPLE_FRAMES,
|
NP_ACCEPT_MULTIPLE_FRAMES,
|
||||||
/** This option can be used to enable or disable the auto-switching mode to
|
/** This option can be used to enable or disable the auto-switching mode to
|
||||||
* ISO14443-4 is device is compliant.
|
* ISO14443-4 is device is compliant.
|
||||||
* In initiator mode, it means that NFC chip will send RATS automatically when
|
* In initiator mode, it means that NFC chip will send RATS automatically when
|
||||||
* select and it will automatically poll for ISO14443-4 card when ISO14443A is
|
* select and it will automatically poll for ISO14443-4 card when ISO14443A is
|
||||||
* requested.
|
* requested.
|
||||||
* In target mode, with a NFC chip compliant (ie. PN532), the chip will
|
* In target mode, with a NFC chip compliant (ie. PN532), the chip will
|
||||||
* emulate a 14443-4 PICC using hardware capability */
|
* emulate a 14443-4 PICC using hardware capability */
|
||||||
NP_AUTO_ISO14443_4,
|
NP_AUTO_ISO14443_4,
|
||||||
/** Use automatic frames encapsulation and chaining. */
|
/** Use automatic frames encapsulation and chaining. */
|
||||||
NP_EASY_FRAMING,
|
NP_EASY_FRAMING,
|
||||||
/** Force the chip to switch in ISO14443-A */
|
/** Force the chip to switch in ISO14443-A */
|
||||||
NP_FORCE_ISO14443_A,
|
NP_FORCE_ISO14443_A,
|
||||||
/** Force the chip to switch in ISO14443-B */
|
/** Force the chip to switch in ISO14443-B */
|
||||||
NP_FORCE_ISO14443_B,
|
NP_FORCE_ISO14443_B,
|
||||||
/** Force the chip to run at 106 kbps */
|
/** Force the chip to run at 106 kbps */
|
||||||
NP_FORCE_SPEED_106,
|
NP_FORCE_SPEED_106,
|
||||||
} nfc_property;
|
} nfc_property;
|
||||||
|
|
||||||
|
@ -142,22 +142,22 @@ typedef enum {
|
||||||
* @brief NFC target information in D.E.P. (Data Exchange Protocol) see ISO/IEC 18092 (NFCIP-1)
|
* @brief NFC target information in D.E.P. (Data Exchange Protocol) see ISO/IEC 18092 (NFCIP-1)
|
||||||
*/
|
*/
|
||||||
typedef struct {
|
typedef struct {
|
||||||
/** NFCID3 */
|
/** NFCID3 */
|
||||||
uint8_t abtNFCID3[10];
|
uint8_t abtNFCID3[10];
|
||||||
/** DID */
|
/** DID */
|
||||||
uint8_t btDID;
|
uint8_t btDID;
|
||||||
/** Supported send-bit rate */
|
/** Supported send-bit rate */
|
||||||
uint8_t btBS;
|
uint8_t btBS;
|
||||||
/** Supported receive-bit rate */
|
/** Supported receive-bit rate */
|
||||||
uint8_t btBR;
|
uint8_t btBR;
|
||||||
/** Timeout value */
|
/** Timeout value */
|
||||||
uint8_t btTO;
|
uint8_t btTO;
|
||||||
/** PP Parameters */
|
/** PP Parameters */
|
||||||
uint8_t btPP;
|
uint8_t btPP;
|
||||||
/** General Bytes */
|
/** General Bytes */
|
||||||
uint8_t abtGB[48];
|
uint8_t abtGB[48];
|
||||||
size_t szGB;
|
size_t szGB;
|
||||||
/** DEP mode */
|
/** DEP mode */
|
||||||
nfc_dep_mode ndm;
|
nfc_dep_mode ndm;
|
||||||
} nfc_dep_info;
|
} nfc_dep_info;
|
||||||
|
|
||||||
|
@ -191,13 +191,13 @@ typedef struct {
|
||||||
* @brief NFC ISO14443B tag information
|
* @brief NFC ISO14443B tag information
|
||||||
*/
|
*/
|
||||||
typedef struct {
|
typedef struct {
|
||||||
/** abtPupi store PUPI contained in ATQB (Answer To reQuest of type B) (see ISO14443-3) */
|
/** abtPupi store PUPI contained in ATQB (Answer To reQuest of type B) (see ISO14443-3) */
|
||||||
uint8_t abtPupi[4];
|
uint8_t abtPupi[4];
|
||||||
/** abtApplicationData store Application Data contained in ATQB (see ISO14443-3) */
|
/** abtApplicationData store Application Data contained in ATQB (see ISO14443-3) */
|
||||||
uint8_t abtApplicationData[4];
|
uint8_t abtApplicationData[4];
|
||||||
/** abtProtocolInfo store Protocol Info contained in ATQB (see ISO14443-3) */
|
/** abtProtocolInfo store Protocol Info contained in ATQB (see ISO14443-3) */
|
||||||
uint8_t abtProtocolInfo[3];
|
uint8_t abtProtocolInfo[3];
|
||||||
/** ui8CardIdentifier store CID (Card Identifier) attributted by PCD to the PICC */
|
/** ui8CardIdentifier store CID (Card Identifier) attributted by PCD to the PICC */
|
||||||
uint8_t ui8CardIdentifier;
|
uint8_t ui8CardIdentifier;
|
||||||
} nfc_iso14443b_info;
|
} nfc_iso14443b_info;
|
||||||
|
|
||||||
|
@ -206,13 +206,13 @@ typedef struct {
|
||||||
* @brief NFC ISO14443B' tag information
|
* @brief NFC ISO14443B' tag information
|
||||||
*/
|
*/
|
||||||
typedef struct {
|
typedef struct {
|
||||||
/** DIV: 4 LSBytes of tag serial number */
|
/** DIV: 4 LSBytes of tag serial number */
|
||||||
uint8_t abtDIV[4];
|
uint8_t abtDIV[4];
|
||||||
/** Software version & type of REPGEN */
|
/** Software version & type of REPGEN */
|
||||||
uint8_t btVerLog;
|
uint8_t btVerLog;
|
||||||
/** Config Byte, present if long REPGEN */
|
/** Config Byte, present if long REPGEN */
|
||||||
uint8_t btConfig;
|
uint8_t btConfig;
|
||||||
/** ATR, if any */
|
/** ATR, if any */
|
||||||
size_t szAtrLen;
|
size_t szAtrLen;
|
||||||
uint8_t abtAtr[33];
|
uint8_t abtAtr[33];
|
||||||
} nfc_iso14443bi_info;
|
} nfc_iso14443bi_info;
|
||||||
|
|
|
@ -34,27 +34,27 @@
|
||||||
# include <stdbool.h>
|
# include <stdbool.h>
|
||||||
|
|
||||||
# ifdef _WIN32
|
# ifdef _WIN32
|
||||||
/* Windows platform */
|
/* Windows platform */
|
||||||
# ifndef _WINDLL
|
# ifndef _WINDLL
|
||||||
/* CMake compilation */
|
/* CMake compilation */
|
||||||
# ifdef nfc_EXPORTS
|
# ifdef nfc_EXPORTS
|
||||||
# define NFC_EXPORT __declspec(dllexport)
|
# define NFC_EXPORT __declspec(dllexport)
|
||||||
# else
|
# else
|
||||||
/* nfc_EXPORTS */
|
/* nfc_EXPORTS */
|
||||||
# define NFC_EXPORT __declspec(dllimport)
|
# define NFC_EXPORT __declspec(dllimport)
|
||||||
# endif
|
# endif
|
||||||
/* nfc_EXPORTS */
|
/* nfc_EXPORTS */
|
||||||
# else
|
# else
|
||||||
/* _WINDLL */
|
/* _WINDLL */
|
||||||
/* Manual makefile */
|
/* Manual makefile */
|
||||||
# define NFC_EXPORT
|
# define NFC_EXPORT
|
||||||
# endif
|
# endif
|
||||||
/* _WINDLL */
|
/* _WINDLL */
|
||||||
# else
|
# else
|
||||||
/* _WIN32 */
|
/* _WIN32 */
|
||||||
# define NFC_EXPORT
|
# define NFC_EXPORT
|
||||||
# endif
|
# endif
|
||||||
/* _WIN32 */
|
/* _WIN32 */
|
||||||
|
|
||||||
# include <nfc/nfc-types.h>
|
# include <nfc/nfc-types.h>
|
||||||
|
|
||||||
|
@ -62,11 +62,11 @@
|
||||||
extern "C" {
|
extern "C" {
|
||||||
# endif // __cplusplus
|
# endif // __cplusplus
|
||||||
|
|
||||||
/* Library initialization/deinitialization */
|
/* Library initialization/deinitialization */
|
||||||
NFC_EXPORT void nfc_init(nfc_context *context);
|
NFC_EXPORT void nfc_init(nfc_context *context);
|
||||||
NFC_EXPORT void nfc_exit(nfc_context *context);
|
NFC_EXPORT void nfc_exit(nfc_context *context);
|
||||||
|
|
||||||
/* NFC Device/Hardware manipulation */
|
/* NFC Device/Hardware manipulation */
|
||||||
NFC_EXPORT bool nfc_get_default_device (nfc_connstring *connstring);
|
NFC_EXPORT bool nfc_get_default_device (nfc_connstring *connstring);
|
||||||
NFC_EXPORT nfc_device *nfc_open (nfc_context *context, const nfc_connstring connstring);
|
NFC_EXPORT nfc_device *nfc_open (nfc_context *context, const nfc_connstring connstring);
|
||||||
NFC_EXPORT void nfc_close (nfc_device *pnd);
|
NFC_EXPORT void nfc_close (nfc_device *pnd);
|
||||||
|
@ -74,7 +74,7 @@ extern "C" {
|
||||||
NFC_EXPORT size_t nfc_list_devices (nfc_context *context, nfc_connstring connstrings[], size_t connstrings_len);
|
NFC_EXPORT size_t nfc_list_devices (nfc_context *context, nfc_connstring connstrings[], size_t connstrings_len);
|
||||||
NFC_EXPORT int nfc_idle (nfc_device *pnd);
|
NFC_EXPORT int nfc_idle (nfc_device *pnd);
|
||||||
|
|
||||||
/* NFC initiator: act as "reader" */
|
/* NFC initiator: act as "reader" */
|
||||||
NFC_EXPORT int nfc_initiator_init (nfc_device *pnd);
|
NFC_EXPORT int nfc_initiator_init (nfc_device *pnd);
|
||||||
NFC_EXPORT int nfc_initiator_select_passive_target (nfc_device *pnd, const nfc_modulation nm, const uint8_t *pbtInitData, const size_t szInitData, nfc_target *pnt);
|
NFC_EXPORT int nfc_initiator_select_passive_target (nfc_device *pnd, const nfc_modulation nm, const uint8_t *pbtInitData, const size_t szInitData, nfc_target *pnt);
|
||||||
NFC_EXPORT int nfc_initiator_list_passive_targets (nfc_device *pnd, const nfc_modulation nm, nfc_target ant[], const size_t szTargets);
|
NFC_EXPORT int nfc_initiator_list_passive_targets (nfc_device *pnd, const nfc_modulation nm, nfc_target ant[], const size_t szTargets);
|
||||||
|
@ -88,30 +88,30 @@ extern "C" {
|
||||||
NFC_EXPORT int nfc_initiator_transceive_bits_timed (nfc_device *pnd, const uint8_t *pbtTx, const size_t szTxBits, const uint8_t *pbtTxPar, uint8_t *pbtRx, uint8_t *pbtRxPar, uint32_t *cycles);
|
NFC_EXPORT int nfc_initiator_transceive_bits_timed (nfc_device *pnd, const uint8_t *pbtTx, const size_t szTxBits, const uint8_t *pbtTxPar, uint8_t *pbtRx, uint8_t *pbtRxPar, uint32_t *cycles);
|
||||||
NFC_EXPORT int nfc_initiator_target_is_present (nfc_device *pnd, const nfc_target nt);
|
NFC_EXPORT int nfc_initiator_target_is_present (nfc_device *pnd, const nfc_target nt);
|
||||||
|
|
||||||
/* NFC target: act as tag (i.e. MIFARE Classic) or NFC target device. */
|
/* NFC target: act as tag (i.e. MIFARE Classic) or NFC target device. */
|
||||||
NFC_EXPORT int nfc_target_init (nfc_device *pnd, nfc_target *pnt, uint8_t *pbtRx, const size_t szRx, int timeout);
|
NFC_EXPORT int nfc_target_init (nfc_device *pnd, nfc_target *pnt, uint8_t *pbtRx, const size_t szRx, int timeout);
|
||||||
NFC_EXPORT int nfc_target_send_bytes (nfc_device *pnd, const uint8_t *pbtTx, const size_t szTx, int timeout);
|
NFC_EXPORT int nfc_target_send_bytes (nfc_device *pnd, const uint8_t *pbtTx, const size_t szTx, int timeout);
|
||||||
NFC_EXPORT int nfc_target_receive_bytes (nfc_device *pnd, uint8_t *pbtRx, const size_t szRx, int timeout);
|
NFC_EXPORT int nfc_target_receive_bytes (nfc_device *pnd, uint8_t *pbtRx, const size_t szRx, int timeout);
|
||||||
NFC_EXPORT int nfc_target_send_bits (nfc_device *pnd, const uint8_t *pbtTx, const size_t szTxBits, const uint8_t *pbtTxPar);
|
NFC_EXPORT int nfc_target_send_bits (nfc_device *pnd, const uint8_t *pbtTx, const size_t szTxBits, const uint8_t *pbtTxPar);
|
||||||
NFC_EXPORT int nfc_target_receive_bits (nfc_device *pnd, uint8_t *pbtRx, const size_t szRx, uint8_t *pbtRxPar);
|
NFC_EXPORT int nfc_target_receive_bits (nfc_device *pnd, uint8_t *pbtRx, const size_t szRx, uint8_t *pbtRxPar);
|
||||||
|
|
||||||
/* Error reporting */
|
/* Error reporting */
|
||||||
NFC_EXPORT const char *nfc_strerror (const nfc_device *pnd);
|
NFC_EXPORT const char *nfc_strerror (const nfc_device *pnd);
|
||||||
NFC_EXPORT int nfc_strerror_r (const nfc_device *pnd, char *buf, size_t buflen);
|
NFC_EXPORT int nfc_strerror_r (const nfc_device *pnd, char *buf, size_t buflen);
|
||||||
NFC_EXPORT void nfc_perror (const nfc_device *pnd, const char *s);
|
NFC_EXPORT void nfc_perror (const nfc_device *pnd, const char *s);
|
||||||
NFC_EXPORT int nfc_device_get_last_error (const nfc_device *pnd);
|
NFC_EXPORT int nfc_device_get_last_error (const nfc_device *pnd);
|
||||||
|
|
||||||
/* Special data accessors */
|
/* Special data accessors */
|
||||||
NFC_EXPORT const char *nfc_device_get_name (nfc_device *pnd);
|
NFC_EXPORT const char *nfc_device_get_name (nfc_device *pnd);
|
||||||
NFC_EXPORT const char *nfc_device_get_connstring (nfc_device *pnd);
|
NFC_EXPORT const char *nfc_device_get_connstring (nfc_device *pnd);
|
||||||
NFC_EXPORT int nfc_device_get_supported_modulation (nfc_device *pnd, const nfc_mode mode, const nfc_modulation_type **const supported_mt);
|
NFC_EXPORT int nfc_device_get_supported_modulation (nfc_device *pnd, const nfc_mode mode, const nfc_modulation_type **const supported_mt);
|
||||||
NFC_EXPORT int nfc_device_get_supported_baud_rate (nfc_device *pnd, const nfc_modulation_type nmt, const nfc_baud_rate **const supported_br);
|
NFC_EXPORT int nfc_device_get_supported_baud_rate (nfc_device *pnd, const nfc_modulation_type nmt, const nfc_baud_rate **const supported_br);
|
||||||
|
|
||||||
/* Properties accessors */
|
/* Properties accessors */
|
||||||
NFC_EXPORT int nfc_device_set_property_int (nfc_device *pnd, const nfc_property property, const int value);
|
NFC_EXPORT int nfc_device_set_property_int (nfc_device *pnd, const nfc_property property, const int value);
|
||||||
NFC_EXPORT int nfc_device_set_property_bool (nfc_device *pnd, const nfc_property property, const bool bEnable);
|
NFC_EXPORT int nfc_device_set_property_bool (nfc_device *pnd, const nfc_property property, const bool bEnable);
|
||||||
|
|
||||||
/* Misc. functions */
|
/* Misc. functions */
|
||||||
NFC_EXPORT void iso14443a_crc (uint8_t *pbtData, size_t szLen, uint8_t *pbtCrc);
|
NFC_EXPORT void iso14443a_crc (uint8_t *pbtData, size_t szLen, uint8_t *pbtCrc);
|
||||||
NFC_EXPORT void iso14443a_crc_append (uint8_t *pbtData, size_t szLen);
|
NFC_EXPORT void iso14443a_crc_append (uint8_t *pbtData, size_t szLen);
|
||||||
NFC_EXPORT uint8_t *iso14443a_locate_historical_bytes (uint8_t *pbtAts, size_t szAts, size_t *pszTk);
|
NFC_EXPORT uint8_t *iso14443a_locate_historical_bytes (uint8_t *pbtAts, size_t szAts, size_t *pszTk);
|
||||||
|
@ -119,76 +119,76 @@ extern "C" {
|
||||||
NFC_EXPORT const char *nfc_version (void);
|
NFC_EXPORT const char *nfc_version (void);
|
||||||
NFC_EXPORT int nfc_device_get_information_about (nfc_device *pnd, char *buf, size_t buflen);
|
NFC_EXPORT int nfc_device_get_information_about (nfc_device *pnd, char *buf, size_t buflen);
|
||||||
|
|
||||||
/* String converter functions */
|
/* String converter functions */
|
||||||
NFC_EXPORT const char * str_nfc_modulation_type (const nfc_modulation_type nmt);
|
NFC_EXPORT const char * str_nfc_modulation_type (const nfc_modulation_type nmt);
|
||||||
NFC_EXPORT const char * str_nfc_baud_rate (const nfc_baud_rate nbr);
|
NFC_EXPORT const char * str_nfc_baud_rate (const nfc_baud_rate nbr);
|
||||||
|
|
||||||
|
|
||||||
/* Error codes */
|
/* Error codes */
|
||||||
/** @ingroup error
|
/** @ingroup error
|
||||||
* @hideinitializer
|
* @hideinitializer
|
||||||
* Success (no error)
|
* Success (no error)
|
||||||
*/
|
*/
|
||||||
#define NFC_SUCCESS 0
|
#define NFC_SUCCESS 0
|
||||||
/** @ingroup error
|
/** @ingroup error
|
||||||
* @hideinitializer
|
* @hideinitializer
|
||||||
* Input / output error, device may not be usable anymore without re-open it
|
* Input / output error, device may not be usable anymore without re-open it
|
||||||
*/
|
*/
|
||||||
#define NFC_EIO -1
|
#define NFC_EIO -1
|
||||||
/** @ingroup error
|
/** @ingroup error
|
||||||
* @hideinitializer
|
* @hideinitializer
|
||||||
* Invalid argument(s)
|
* Invalid argument(s)
|
||||||
*/
|
*/
|
||||||
#define NFC_EINVARG -2
|
#define NFC_EINVARG -2
|
||||||
/** @ingroup error
|
/** @ingroup error
|
||||||
* @hideinitializer
|
* @hideinitializer
|
||||||
* Operation not supported by device
|
* Operation not supported by device
|
||||||
*/
|
*/
|
||||||
#define NFC_EDEVNOTSUPP -3
|
#define NFC_EDEVNOTSUPP -3
|
||||||
/** @ingroup error
|
/** @ingroup error
|
||||||
* @hideinitializer
|
* @hideinitializer
|
||||||
* No such device
|
* No such device
|
||||||
*/
|
*/
|
||||||
#define NFC_ENOTSUCHDEV -4
|
#define NFC_ENOTSUCHDEV -4
|
||||||
/** @ingroup error
|
/** @ingroup error
|
||||||
* @hideinitializer
|
* @hideinitializer
|
||||||
* Buffer overflow
|
* Buffer overflow
|
||||||
*/
|
*/
|
||||||
#define NFC_EOVFLOW -5
|
#define NFC_EOVFLOW -5
|
||||||
/** @ingroup error
|
/** @ingroup error
|
||||||
* @hideinitializer
|
* @hideinitializer
|
||||||
* Operation timed out
|
* Operation timed out
|
||||||
*/
|
*/
|
||||||
#define NFC_ETIMEOUT -6
|
#define NFC_ETIMEOUT -6
|
||||||
/** @ingroup error
|
/** @ingroup error
|
||||||
* @hideinitializer
|
* @hideinitializer
|
||||||
* Operation aborted (by user)
|
* Operation aborted (by user)
|
||||||
*/
|
*/
|
||||||
#define NFC_EOPABORTED -7
|
#define NFC_EOPABORTED -7
|
||||||
/** @ingroup error
|
/** @ingroup error
|
||||||
* @hideinitializer
|
* @hideinitializer
|
||||||
* Not (yet) implemented
|
* Not (yet) implemented
|
||||||
*/
|
*/
|
||||||
#define NFC_ENOTIMPL -8
|
#define NFC_ENOTIMPL -8
|
||||||
/** @ingroup error
|
/** @ingroup error
|
||||||
* @hideinitializer
|
* @hideinitializer
|
||||||
* Target released
|
* Target released
|
||||||
*/
|
*/
|
||||||
#define NFC_ETGRELEASED -10
|
#define NFC_ETGRELEASED -10
|
||||||
/** @ingroup error
|
/** @ingroup error
|
||||||
* @hideinitializer
|
* @hideinitializer
|
||||||
* Error while RF transmission
|
* Error while RF transmission
|
||||||
*/
|
*/
|
||||||
#define NFC_ERFTRANS -20
|
#define NFC_ERFTRANS -20
|
||||||
/** @ingroup error
|
/** @ingroup error
|
||||||
* @hideinitializer
|
* @hideinitializer
|
||||||
* Software error (allocation, file/pipe creation, etc.)
|
* Software error (allocation, file/pipe creation, etc.)
|
||||||
*/
|
*/
|
||||||
#define NFC_ESOFT -80
|
#define NFC_ESOFT -80
|
||||||
/** @ingroup error
|
/** @ingroup error
|
||||||
* @hideinitializer
|
* @hideinitializer
|
||||||
* Device's internal chip error
|
* Device's internal chip error
|
||||||
*/
|
*/
|
||||||
#define NFC_ECHIP -90
|
#define NFC_ECHIP -90
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -47,7 +47,7 @@
|
||||||
#define LOG_CATEGORY "libnfc.bus.uart"
|
#define LOG_CATEGORY "libnfc.bus.uart"
|
||||||
|
|
||||||
# if defined(__APPLE__)
|
# if defined(__APPLE__)
|
||||||
// FIXME: find UART connection string for PN53X device on Mac OS X when multiples devices are used
|
// FIXME: find UART connection string for PN53X device on Mac OS X when multiples devices are used
|
||||||
const char *serial_ports_device_radix[] = { "tty.SLAB_USBtoUART", NULL };
|
const char *serial_ports_device_radix[] = { "tty.SLAB_USBtoUART", NULL };
|
||||||
# elif defined (__FreeBSD__) || defined (__OpenBSD__)
|
# elif defined (__FreeBSD__) || defined (__OpenBSD__)
|
||||||
const char *serial_ports_device_radix[] = { "cuaU", "cuau", NULL };
|
const char *serial_ports_device_radix[] = { "cuaU", "cuau", NULL };
|
||||||
|
@ -60,7 +60,7 @@ const char *serial_ports_device_radix[] = { "ttyUSB", "ttyS", NULL };
|
||||||
// Work-around to claim uart interface using the c_iflag (software input processing) from the termios struct
|
// Work-around to claim uart interface using the c_iflag (software input processing) from the termios struct
|
||||||
# define CCLAIMED 0x80000000
|
# define CCLAIMED 0x80000000
|
||||||
|
|
||||||
struct serial_port_unix{
|
struct serial_port_unix {
|
||||||
int fd; // Serial port file descriptor
|
int fd; // Serial port file descriptor
|
||||||
struct termios termios_backup; // Terminal info before using the port
|
struct termios termios_backup; // Terminal info before using the port
|
||||||
struct termios termios_new; // Terminal info during the transaction
|
struct termios termios_new; // Terminal info during the transaction
|
||||||
|
@ -143,39 +143,39 @@ uart_set_speed (serial_port sp, const uint32_t uiPortSpeed)
|
||||||
// uint32_t <=> speed_t associations by hand.
|
// uint32_t <=> speed_t associations by hand.
|
||||||
speed_t stPortSpeed = B9600;
|
speed_t stPortSpeed = B9600;
|
||||||
switch (uiPortSpeed) {
|
switch (uiPortSpeed) {
|
||||||
case 9600:
|
case 9600:
|
||||||
stPortSpeed = B9600;
|
stPortSpeed = B9600;
|
||||||
break;
|
break;
|
||||||
case 19200:
|
case 19200:
|
||||||
stPortSpeed = B19200;
|
stPortSpeed = B19200;
|
||||||
break;
|
break;
|
||||||
case 38400:
|
case 38400:
|
||||||
stPortSpeed = B38400;
|
stPortSpeed = B38400;
|
||||||
break;
|
break;
|
||||||
# ifdef B57600
|
# ifdef B57600
|
||||||
case 57600:
|
case 57600:
|
||||||
stPortSpeed = B57600;
|
stPortSpeed = B57600;
|
||||||
break;
|
break;
|
||||||
# endif
|
# endif
|
||||||
# ifdef B115200
|
# ifdef B115200
|
||||||
case 115200:
|
case 115200:
|
||||||
stPortSpeed = B115200;
|
stPortSpeed = B115200;
|
||||||
break;
|
break;
|
||||||
# endif
|
# endif
|
||||||
# ifdef B230400
|
# ifdef B230400
|
||||||
case 230400:
|
case 230400:
|
||||||
stPortSpeed = B230400;
|
stPortSpeed = B230400;
|
||||||
break;
|
break;
|
||||||
# endif
|
# endif
|
||||||
# ifdef B460800
|
# ifdef B460800
|
||||||
case 460800:
|
case 460800:
|
||||||
stPortSpeed = B460800;
|
stPortSpeed = B460800;
|
||||||
break;
|
break;
|
||||||
# endif
|
# endif
|
||||||
default:
|
default:
|
||||||
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "Unable to set serial port speed to %d bauds. Speed value must be one of those defined in termios(3).",
|
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "Unable to set serial port speed to %d bauds. Speed value must be one of those defined in termios(3).",
|
||||||
uiPortSpeed);
|
uiPortSpeed);
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Set port speed (Input and Output)
|
// Set port speed (Input and Output)
|
||||||
|
@ -191,34 +191,34 @@ uart_get_speed (serial_port sp)
|
||||||
{
|
{
|
||||||
uint32_t uiPortSpeed = 0;
|
uint32_t uiPortSpeed = 0;
|
||||||
switch (cfgetispeed (&UART_DATA(sp)->termios_new)) {
|
switch (cfgetispeed (&UART_DATA(sp)->termios_new)) {
|
||||||
case B9600:
|
case B9600:
|
||||||
uiPortSpeed = 9600;
|
uiPortSpeed = 9600;
|
||||||
break;
|
break;
|
||||||
case B19200:
|
case B19200:
|
||||||
uiPortSpeed = 19200;
|
uiPortSpeed = 19200;
|
||||||
break;
|
break;
|
||||||
case B38400:
|
case B38400:
|
||||||
uiPortSpeed = 38400;
|
uiPortSpeed = 38400;
|
||||||
break;
|
break;
|
||||||
# ifdef B57600
|
# ifdef B57600
|
||||||
case B57600:
|
case B57600:
|
||||||
uiPortSpeed = 57600;
|
uiPortSpeed = 57600;
|
||||||
break;
|
break;
|
||||||
# endif
|
# endif
|
||||||
# ifdef B115200
|
# ifdef B115200
|
||||||
case B115200:
|
case B115200:
|
||||||
uiPortSpeed = 115200;
|
uiPortSpeed = 115200;
|
||||||
break;
|
break;
|
||||||
# endif
|
# endif
|
||||||
# ifdef B230400
|
# ifdef B230400
|
||||||
case B230400:
|
case B230400:
|
||||||
uiPortSpeed = 230400;
|
uiPortSpeed = 230400;
|
||||||
break;
|
break;
|
||||||
# endif
|
# endif
|
||||||
# ifdef B460800
|
# ifdef B460800
|
||||||
case B460800:
|
case B460800:
|
||||||
uiPortSpeed = 460800;
|
uiPortSpeed = 460800;
|
||||||
break;
|
break;
|
||||||
# endif
|
# endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -335,38 +335,38 @@ uart_send (serial_port sp, const uint8_t *pbtTx, const size_t szTx, int timeout)
|
||||||
char **
|
char **
|
||||||
uart_list_ports (void)
|
uart_list_ports (void)
|
||||||
{
|
{
|
||||||
char **res = malloc (sizeof (char *));
|
char **res = malloc (sizeof (char *));
|
||||||
size_t szRes = 1;
|
size_t szRes = 1;
|
||||||
|
|
||||||
res[0] = NULL;
|
res[0] = NULL;
|
||||||
|
|
||||||
DIR *pdDir = opendir("/dev");
|
DIR *pdDir = opendir("/dev");
|
||||||
struct dirent *pdDirEnt;
|
struct dirent *pdDirEnt;
|
||||||
while ((pdDirEnt = readdir(pdDir)) != NULL) {
|
while ((pdDirEnt = readdir(pdDir)) != NULL) {
|
||||||
if (!isdigit (pdDirEnt->d_name[strlen (pdDirEnt->d_name) - 1]))
|
if (!isdigit (pdDirEnt->d_name[strlen (pdDirEnt->d_name) - 1]))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
const char **p = serial_ports_device_radix;
|
const char **p = serial_ports_device_radix;
|
||||||
while (*p) {
|
while (*p) {
|
||||||
if (!strncmp(pdDirEnt->d_name, *p, strlen (*p))) {
|
if (!strncmp(pdDirEnt->d_name, *p, strlen (*p))) {
|
||||||
char **res2 = realloc (res, (szRes+1) * sizeof (char *));
|
char **res2 = realloc (res, (szRes+1) * sizeof (char *));
|
||||||
if (!res2)
|
if (!res2)
|
||||||
goto oom;
|
goto oom;
|
||||||
|
|
||||||
res = res2;
|
res = res2;
|
||||||
if (!(res[szRes-1] = malloc (6 + strlen (pdDirEnt->d_name))))
|
if (!(res[szRes-1] = malloc (6 + strlen (pdDirEnt->d_name))))
|
||||||
goto oom;
|
goto oom;
|
||||||
|
|
||||||
sprintf (res[szRes-1], "/dev/%s", pdDirEnt->d_name);
|
sprintf (res[szRes-1], "/dev/%s", pdDirEnt->d_name);
|
||||||
|
|
||||||
szRes++;
|
szRes++;
|
||||||
res[szRes-1] = NULL;
|
res[szRes-1] = NULL;
|
||||||
}
|
}
|
||||||
p++;
|
p++;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
oom:
|
oom:
|
||||||
closedir (pdDir);
|
closedir (pdDir);
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
|
@ -105,17 +105,17 @@ uart_set_speed (serial_port sp, const uint32_t uiPortSpeed)
|
||||||
log_put (LOG_CATEGORY, NFC_PRIORITY_TRACE, "Serial port speed requested to be set to %d bauds.", uiPortSpeed);
|
log_put (LOG_CATEGORY, NFC_PRIORITY_TRACE, "Serial port speed requested to be set to %d bauds.", uiPortSpeed);
|
||||||
// Set port speed (Input and Output)
|
// Set port speed (Input and Output)
|
||||||
switch (uiPortSpeed) {
|
switch (uiPortSpeed) {
|
||||||
case 9600:
|
case 9600:
|
||||||
case 19200:
|
case 19200:
|
||||||
case 38400:
|
case 38400:
|
||||||
case 57600:
|
case 57600:
|
||||||
case 115200:
|
case 115200:
|
||||||
case 230400:
|
case 230400:
|
||||||
case 460800:
|
case 460800:
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "Unable to set serial port speed to %d bauds. Speed value must be one of these constants: 9600 (default), 19200, 38400, 57600, 115200, 230400 or 460800.", uiPortSpeed);
|
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "Unable to set serial port speed to %d bauds. Speed value must be one of these constants: 9600 (default), 19200, 38400, 57600, 115200, 230400 or 460800.", uiPortSpeed);
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
spw = (struct serial_port_windows *) sp;
|
spw = (struct serial_port_windows *) sp;
|
||||||
|
|
||||||
|
@ -167,8 +167,8 @@ uart_receive (serial_port sp, uint8_t * pbtRx, const size_t szRx, void * abort_p
|
||||||
do {
|
do {
|
||||||
log_put (LOG_CATEGORY, NFC_PRIORITY_TRACE, "ReadFile");
|
log_put (LOG_CATEGORY, NFC_PRIORITY_TRACE, "ReadFile");
|
||||||
res = ReadFile (((struct serial_port_windows *) sp)->hPort, pbtRx + dwTotalBytesReceived,
|
res = ReadFile (((struct serial_port_windows *) sp)->hPort, pbtRx + dwTotalBytesReceived,
|
||||||
dwBytesToGet,
|
dwBytesToGet,
|
||||||
&dwBytesReceived, NULL);
|
&dwBytesReceived, NULL);
|
||||||
|
|
||||||
dwTotalBytesReceived += dwBytesReceived;
|
dwTotalBytesReceived += dwBytesReceived;
|
||||||
|
|
||||||
|
@ -177,8 +177,8 @@ uart_receive (serial_port sp, uint8_t * pbtRx, const size_t szRx, void * abort_p
|
||||||
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "ReadFile error: %u", err);
|
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "ReadFile error: %u", err);
|
||||||
return NFC_EIO;
|
return NFC_EIO;
|
||||||
} else if (dwBytesReceived == 0) {
|
} else if (dwBytesReceived == 0) {
|
||||||
return NFC_ETIMEOUT;
|
return NFC_ETIMEOUT;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (((DWORD)szRx) > dwTotalBytesReceived) {
|
if (((DWORD)szRx) > dwTotalBytesReceived) {
|
||||||
dwBytesToGet -= dwBytesReceived;
|
dwBytesToGet -= dwBytesReceived;
|
||||||
|
|
|
@ -133,13 +133,13 @@ typedef enum {
|
||||||
#else
|
#else
|
||||||
# define PNCMD( X, Y ) { X , Y, #X }
|
# define PNCMD( X, Y ) { X , Y, #X }
|
||||||
# define PNCMD_TRACE( X ) do { \
|
# define PNCMD_TRACE( X ) do { \
|
||||||
for (size_t i=0; i<(sizeof(pn53x_commands)/sizeof(pn53x_command)); i++) { \
|
for (size_t i=0; i<(sizeof(pn53x_commands)/sizeof(pn53x_command)); i++) { \
|
||||||
if ( X == pn53x_commands[i].ui8Code ) { \
|
if ( X == pn53x_commands[i].ui8Code ) { \
|
||||||
log_put( LOG_CATEGORY, NFC_PRIORITY_TRACE, "%s", pn53x_commands[i].abtCommandText ); \
|
log_put( LOG_CATEGORY, NFC_PRIORITY_TRACE, "%s", pn53x_commands[i].abtCommandText ); \
|
||||||
break; \
|
break; \
|
||||||
} \
|
} \
|
||||||
} \
|
} \
|
||||||
} while(0)
|
} while(0)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static const pn53x_command pn53x_commands[] = {
|
static const pn53x_command pn53x_commands[] = {
|
||||||
|
@ -214,16 +214,16 @@ typedef struct {
|
||||||
|
|
||||||
#ifndef LOGGING
|
#ifndef LOGGING
|
||||||
# define PNREG_TRACE( X ) do { \
|
# define PNREG_TRACE( X ) do { \
|
||||||
} while(0)
|
} while(0)
|
||||||
#else
|
#else
|
||||||
# define PNREG_TRACE( X ) do { \
|
# define PNREG_TRACE( X ) do { \
|
||||||
for (size_t i=0; i<(sizeof(pn53x_registers)/sizeof(pn53x_register)); i++) { \
|
for (size_t i=0; i<(sizeof(pn53x_registers)/sizeof(pn53x_register)); i++) { \
|
||||||
if ( X == pn53x_registers[i].ui16Address ) { \
|
if ( X == pn53x_registers[i].ui16Address ) { \
|
||||||
log_put( LOG_CATEGORY, NFC_PRIORITY_TRACE, "%s (%s)", pn53x_registers[i].abtRegisterText, pn53x_registers[i].abtRegisterDescription ); \
|
log_put( LOG_CATEGORY, NFC_PRIORITY_TRACE, "%s (%s)", pn53x_registers[i].abtRegisterText, pn53x_registers[i].abtRegisterDescription ); \
|
||||||
break; \
|
break; \
|
||||||
} \
|
} \
|
||||||
} \
|
} \
|
||||||
} while(0)
|
} while(0)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Register addresses
|
// Register addresses
|
||||||
|
|
|
@ -271,9 +271,9 @@ pn53x_transceive (struct nfc_device *pnd, const uint8_t *pbtTx, const size_t szT
|
||||||
res = NFC_ECHIP;
|
res = NFC_ECHIP;
|
||||||
break;
|
break;
|
||||||
};
|
};
|
||||||
/*
|
/*
|
||||||
{ EMFAUTH, "Mifare Authentication Error" },
|
{ EMFAUTH, "Mifare Authentication Error" },
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (res < 0) {
|
if (res < 0) {
|
||||||
pnd->last_error = res;
|
pnd->last_error = res;
|
||||||
|
@ -551,7 +551,7 @@ pn53x_decode_target_data (const uint8_t *pbtRawData, size_t szRawData, pn53x_typ
|
||||||
pbtRawData += 2;
|
pbtRawData += 2;
|
||||||
memcpy (pnti->nji.btId, pbtRawData, 4);
|
memcpy (pnti->nji.btId, pbtRawData, 4);
|
||||||
break;
|
break;
|
||||||
// Should not happend...
|
// Should not happend...
|
||||||
case NMT_DEP:
|
case NMT_DEP:
|
||||||
return NFC_ECHIP;
|
return NFC_ECHIP;
|
||||||
break;
|
break;
|
||||||
|
@ -763,16 +763,16 @@ pn53x_set_property_int (struct nfc_device *pnd, const nfc_property property, con
|
||||||
switch (property) {
|
switch (property) {
|
||||||
case NP_TIMEOUT_COMMAND:
|
case NP_TIMEOUT_COMMAND:
|
||||||
CHIP_DATA (pnd)->timeout_command = value;
|
CHIP_DATA (pnd)->timeout_command = value;
|
||||||
break;
|
break;
|
||||||
case NP_TIMEOUT_ATR:
|
case NP_TIMEOUT_ATR:
|
||||||
CHIP_DATA (pnd)->timeout_atr = value;
|
CHIP_DATA (pnd)->timeout_atr = value;
|
||||||
return pn53x_RFConfiguration__Various_timings (pnd, pn53x_int_to_timeout(CHIP_DATA (pnd)->timeout_atr), pn53x_int_to_timeout(CHIP_DATA (pnd)->timeout_communication));
|
return pn53x_RFConfiguration__Various_timings (pnd, pn53x_int_to_timeout(CHIP_DATA (pnd)->timeout_atr), pn53x_int_to_timeout(CHIP_DATA (pnd)->timeout_communication));
|
||||||
break;
|
break;
|
||||||
case NP_TIMEOUT_COM:
|
case NP_TIMEOUT_COM:
|
||||||
CHIP_DATA (pnd)->timeout_communication = value;
|
CHIP_DATA (pnd)->timeout_communication = value;
|
||||||
return pn53x_RFConfiguration__Various_timings (pnd, pn53x_int_to_timeout(CHIP_DATA (pnd)->timeout_atr), pn53x_int_to_timeout(CHIP_DATA (pnd)->timeout_communication));
|
return pn53x_RFConfiguration__Various_timings (pnd, pn53x_int_to_timeout(CHIP_DATA (pnd)->timeout_atr), pn53x_int_to_timeout(CHIP_DATA (pnd)->timeout_communication));
|
||||||
break;
|
break;
|
||||||
// Following properties are invalid (not integer)
|
// Following properties are invalid (not integer)
|
||||||
case NP_HANDLE_CRC:
|
case NP_HANDLE_CRC:
|
||||||
case NP_HANDLE_PARITY:
|
case NP_HANDLE_PARITY:
|
||||||
case NP_ACTIVATE_FIELD:
|
case NP_ACTIVATE_FIELD:
|
||||||
|
@ -847,10 +847,10 @@ pn53x_set_property_bool (struct nfc_device *pnd, const nfc_property property, co
|
||||||
// timings could be tweak better than this, and maybe we can tweak timings
|
// timings could be tweak better than this, and maybe we can tweak timings
|
||||||
// to "gain" a sort-of hardware polling (ie. like PN532 does)
|
// to "gain" a sort-of hardware polling (ie. like PN532 does)
|
||||||
if (pn53x_RFConfiguration__MaxRetries (pnd,
|
if (pn53x_RFConfiguration__MaxRetries (pnd,
|
||||||
(bEnable) ? 0xff : 0x00, // MxRtyATR, default: active = 0xff, passive = 0x02
|
(bEnable) ? 0xff : 0x00, // MxRtyATR, default: active = 0xff, passive = 0x02
|
||||||
(bEnable) ? 0xff : 0x01, // MxRtyPSL, default: 0x01
|
(bEnable) ? 0xff : 0x01, // MxRtyPSL, default: 0x01
|
||||||
(bEnable) ? 0xff : 0x02 // MxRtyPassiveActivation, default: 0xff (0x00 leads to problems with PN531)
|
(bEnable) ? 0xff : 0x02 // MxRtyPassiveActivation, default: 0xff (0x00 leads to problems with PN531)
|
||||||
) == 0)
|
) == 0)
|
||||||
return NFC_SUCCESS;
|
return NFC_SUCCESS;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -913,7 +913,7 @@ pn53x_set_property_bool (struct nfc_device *pnd, const nfc_property property, co
|
||||||
}
|
}
|
||||||
return pn53x_write_register (pnd, PN53X_REG_CIU_RxMode, SYMBOL_RX_SPEED, 0x00);
|
return pn53x_write_register (pnd, PN53X_REG_CIU_RxMode, SYMBOL_RX_SPEED, 0x00);
|
||||||
break;
|
break;
|
||||||
// Following properties are invalid (not boolean)
|
// Following properties are invalid (not boolean)
|
||||||
case NP_TIMEOUT_COMMAND:
|
case NP_TIMEOUT_COMMAND:
|
||||||
case NP_TIMEOUT_ATR:
|
case NP_TIMEOUT_ATR:
|
||||||
case NP_TIMEOUT_COM:
|
case NP_TIMEOUT_COM:
|
||||||
|
@ -941,7 +941,7 @@ pn53x_idle (struct nfc_device *pnd)
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case INITIATOR:
|
case INITIATOR:
|
||||||
// Deselect all active communications
|
// Deselect all active communications
|
||||||
if ((res = pn53x_InDeselect (pnd, 0)) < 0) {
|
if ((res = pn53x_InDeselect (pnd, 0)) < 0) {
|
||||||
|
@ -962,9 +962,9 @@ pn53x_idle (struct nfc_device *pnd)
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case IDLE: // Nothing to do.
|
case IDLE: // Nothing to do.
|
||||||
break;
|
break;
|
||||||
};
|
};
|
||||||
CHIP_DATA (pnd)->operating_mode = IDLE;
|
CHIP_DATA (pnd)->operating_mode = IDLE;
|
||||||
return NFC_SUCCESS;
|
return NFC_SUCCESS;
|
||||||
|
@ -1004,10 +1004,10 @@ pn53x_initiator_init (struct nfc_device *pnd)
|
||||||
|
|
||||||
static int
|
static int
|
||||||
pn53x_initiator_select_passive_target_ext (struct nfc_device *pnd,
|
pn53x_initiator_select_passive_target_ext (struct nfc_device *pnd,
|
||||||
const nfc_modulation nm,
|
const nfc_modulation nm,
|
||||||
const uint8_t *pbtInitData, const size_t szInitData,
|
const uint8_t *pbtInitData, const size_t szInitData,
|
||||||
nfc_target *pnt,
|
nfc_target *pnt,
|
||||||
int timeout)
|
int timeout)
|
||||||
{
|
{
|
||||||
uint8_t abtTargetsData[PN53x_EXTENDED_FRAME__DATA_MAX_LEN];
|
uint8_t abtTargetsData[PN53x_EXTENDED_FRAME__DATA_MAX_LEN];
|
||||||
size_t szTargetsData = sizeof (abtTargetsData);
|
size_t szTargetsData = sizeof (abtTargetsData);
|
||||||
|
@ -1118,9 +1118,9 @@ pn53x_initiator_select_passive_target (struct nfc_device *pnd,
|
||||||
|
|
||||||
int
|
int
|
||||||
pn53x_initiator_poll_target (struct nfc_device *pnd,
|
pn53x_initiator_poll_target (struct nfc_device *pnd,
|
||||||
const nfc_modulation *pnmModulations, const size_t szModulations,
|
const nfc_modulation *pnmModulations, const size_t szModulations,
|
||||||
const uint8_t uiPollNr, const uint8_t uiPeriod,
|
const uint8_t uiPollNr, const uint8_t uiPeriod,
|
||||||
nfc_target *pnt)
|
nfc_target *pnt)
|
||||||
{
|
{
|
||||||
int res = 0;
|
int res = 0;
|
||||||
|
|
||||||
|
@ -1155,7 +1155,7 @@ pn53x_initiator_poll_target (struct nfc_device *pnd,
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return NFC_ECHIP;
|
return NFC_ECHIP;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
pn53x_set_property_bool (pnd, NP_INFINITE_SELECT, true);
|
pn53x_set_property_bool (pnd, NP_INFINITE_SELECT, true);
|
||||||
|
@ -1186,10 +1186,10 @@ pn53x_initiator_poll_target (struct nfc_device *pnd,
|
||||||
|
|
||||||
int
|
int
|
||||||
pn53x_initiator_select_dep_target (struct nfc_device *pnd,
|
pn53x_initiator_select_dep_target (struct nfc_device *pnd,
|
||||||
const nfc_dep_mode ndm, const nfc_baud_rate nbr,
|
const nfc_dep_mode ndm, const nfc_baud_rate nbr,
|
||||||
const nfc_dep_info *pndiInitiator,
|
const nfc_dep_info *pndiInitiator,
|
||||||
nfc_target *pnt,
|
nfc_target *pnt,
|
||||||
const int timeout)
|
const int timeout)
|
||||||
{
|
{
|
||||||
const uint8_t abtPassiveInitiatorData[] = { 0x00, 0xff, 0xff, 0x00, 0x0f }; // Only for 212/424 kpbs: First 4 bytes shall be set like this according to NFCIP-1, last byte is TSN (Time Slot Number)
|
const uint8_t abtPassiveInitiatorData[] = { 0x00, 0xff, 0xff, 0x00, 0x0f }; // Only for 212/424 kpbs: First 4 bytes shall be set like this according to NFCIP-1, last byte is TSN (Time Slot Number)
|
||||||
const uint8_t * pbtPassiveInitiatorData = NULL;
|
const uint8_t * pbtPassiveInitiatorData = NULL;
|
||||||
|
@ -1323,8 +1323,8 @@ pn53x_initiator_transceive_bytes (struct nfc_device *pnd, const uint8_t *pbtTx,
|
||||||
// We have to give the amount of bytes + (the two command bytes 0xD4, 0x42)
|
// We have to give the amount of bytes + (the two command bytes 0xD4, 0x42)
|
||||||
uint8_t abtRx[PN53x_EXTENDED_FRAME__DATA_MAX_LEN];
|
uint8_t abtRx[PN53x_EXTENDED_FRAME__DATA_MAX_LEN];
|
||||||
if ((res = pn53x_transceive (pnd, abtCmd, szTx + szExtraTxLen, abtRx, sizeof(abtRx), timeout)) < 0) {
|
if ((res = pn53x_transceive (pnd, abtCmd, szTx + szExtraTxLen, abtRx, sizeof(abtRx), timeout)) < 0) {
|
||||||
pnd->last_error = res;
|
pnd->last_error = res;
|
||||||
return pnd->last_error;
|
return pnd->last_error;
|
||||||
}
|
}
|
||||||
const size_t szRxLen = (size_t)res - 1;
|
const size_t szRxLen = (size_t)res - 1;
|
||||||
if (pbtRx != NULL) {
|
if (pbtRx != NULL) {
|
||||||
|
@ -1347,9 +1347,9 @@ static void __pn53x_init_timer(struct nfc_device *pnd, const uint32_t max_cycles
|
||||||
// prescaler = 2 => precision: ~369ns timer saturates at ~25ms
|
// prescaler = 2 => precision: ~369ns timer saturates at ~25ms
|
||||||
// prescaler = 10 => precision: ~1.5us timer saturates at ~100ms
|
// prescaler = 10 => precision: ~1.5us timer saturates at ~100ms
|
||||||
if (max_cycles > 0xFFFF) {
|
if (max_cycles > 0xFFFF) {
|
||||||
CHIP_DATA (pnd)->timer_prescaler = ((max_cycles/0xFFFF)-1)/2;
|
CHIP_DATA (pnd)->timer_prescaler = ((max_cycles/0xFFFF)-1)/2;
|
||||||
} else {
|
} else {
|
||||||
CHIP_DATA (pnd)->timer_prescaler = 0;
|
CHIP_DATA (pnd)->timer_prescaler = 0;
|
||||||
}
|
}
|
||||||
uint16_t reloadval = 0xFFFF;
|
uint16_t reloadval = 0xFFFF;
|
||||||
// Initialize timer
|
// Initialize timer
|
||||||
|
@ -1404,9 +1404,9 @@ static uint32_t __pn53x_get_timer(struct nfc_device *pnd, const uint8_t last_cmd
|
||||||
}
|
}
|
||||||
// Correction depending on last parity bit sent
|
// Correction depending on last parity bit sent
|
||||||
parity = (last_cmd_byte >> 7) ^ ((last_cmd_byte >> 6) & 1) ^
|
parity = (last_cmd_byte >> 7) ^ ((last_cmd_byte >> 6) & 1) ^
|
||||||
((last_cmd_byte >> 5) & 1) ^ ((last_cmd_byte >> 4) & 1) ^
|
((last_cmd_byte >> 5) & 1) ^ ((last_cmd_byte >> 4) & 1) ^
|
||||||
((last_cmd_byte >> 3) & 1) ^ ((last_cmd_byte >> 2) & 1) ^
|
((last_cmd_byte >> 3) & 1) ^ ((last_cmd_byte >> 2) & 1) ^
|
||||||
((last_cmd_byte >> 1) & 1) ^ (last_cmd_byte & 1);
|
((last_cmd_byte >> 1) & 1) ^ (last_cmd_byte & 1);
|
||||||
parity = parity ? 0:1;
|
parity = parity ? 0:1;
|
||||||
// When sent ...YY (cmd ends with logical 1, so when last parity bit is 1):
|
// When sent ...YY (cmd ends with logical 1, so when last parity bit is 1):
|
||||||
if (parity) {
|
if (parity) {
|
||||||
|
@ -1676,17 +1676,17 @@ pn53x_target_init (struct nfc_device *pnd, nfc_target *pnt, uint8_t *pbtRx, cons
|
||||||
pn53x_set_parameters (pnd, PARAM_14443_4_PICC, false);
|
pn53x_set_parameters (pnd, PARAM_14443_4_PICC, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case NMT_FELICA:
|
case NMT_FELICA:
|
||||||
ptm = PTM_PASSIVE_ONLY;
|
ptm = PTM_PASSIVE_ONLY;
|
||||||
break;
|
break;
|
||||||
case NMT_DEP:
|
case NMT_DEP:
|
||||||
pn53x_set_parameters (pnd, PARAM_AUTO_ATR_RES, true);
|
pn53x_set_parameters (pnd, PARAM_AUTO_ATR_RES, true);
|
||||||
ptm = PTM_DEP_ONLY;
|
ptm = PTM_DEP_ONLY;
|
||||||
if (pnt->nti.ndi.ndm == NDM_PASSIVE) {
|
if (pnt->nti.ndi.ndm == NDM_PASSIVE) {
|
||||||
ptm |= PTM_PASSIVE_ONLY; // We add passive mode restriction
|
ptm |= PTM_PASSIVE_ONLY; // We add passive mode restriction
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case NMT_ISO14443B:
|
case NMT_ISO14443B:
|
||||||
case NMT_ISO14443BI:
|
case NMT_ISO14443BI:
|
||||||
case NMT_ISO14443B2SR:
|
case NMT_ISO14443B2SR:
|
||||||
|
@ -1694,7 +1694,7 @@ pn53x_target_init (struct nfc_device *pnd, nfc_target *pnt, uint8_t *pbtRx, cons
|
||||||
case NMT_JEWEL:
|
case NMT_JEWEL:
|
||||||
pnd->last_error = NFC_EDEVNOTSUPP;
|
pnd->last_error = NFC_EDEVNOTSUPP;
|
||||||
return pnd->last_error;
|
return pnd->last_error;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Let the PN53X be activated by the RF level detector from power down mode
|
// Let the PN53X be activated by the RF level detector from power down mode
|
||||||
|
@ -1741,7 +1741,7 @@ pn53x_target_init (struct nfc_device *pnd, nfc_target *pnt, uint8_t *pbtRx, cons
|
||||||
// Set SystemCode
|
// Set SystemCode
|
||||||
memcpy(abtFeliCaParams+16, pnt->nti.nfi.abtSysCode, 2);
|
memcpy(abtFeliCaParams+16, pnt->nti.nfi.abtSysCode, 2);
|
||||||
pbtFeliCaParams = abtFeliCaParams;
|
pbtFeliCaParams = abtFeliCaParams;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case NMT_DEP:
|
case NMT_DEP:
|
||||||
// Set NFCID3
|
// Set NFCID3
|
||||||
|
@ -1788,7 +1788,7 @@ pn53x_target_init (struct nfc_device *pnd, nfc_target *pnt, uint8_t *pbtRx, cons
|
||||||
abtFeliCaParams[17] = 0xab;
|
abtFeliCaParams[17] = 0xab;
|
||||||
|
|
||||||
pbtFeliCaParams = abtFeliCaParams;
|
pbtFeliCaParams = abtFeliCaParams;
|
||||||
break;
|
break;
|
||||||
case NMT_ISO14443B:
|
case NMT_ISO14443B:
|
||||||
case NMT_ISO14443BI:
|
case NMT_ISO14443BI:
|
||||||
case NMT_ISO14443B2SR:
|
case NMT_ISO14443B2SR:
|
||||||
|
@ -1796,7 +1796,7 @@ pn53x_target_init (struct nfc_device *pnd, nfc_target *pnt, uint8_t *pbtRx, cons
|
||||||
case NMT_JEWEL:
|
case NMT_JEWEL:
|
||||||
pnd->last_error = NFC_EDEVNOTSUPP;
|
pnd->last_error = NFC_EDEVNOTSUPP;
|
||||||
return pnd->last_error;
|
return pnd->last_error;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool targetActivated = false;
|
bool targetActivated = false;
|
||||||
|
@ -1820,13 +1820,13 @@ pn53x_target_init (struct nfc_device *pnd, nfc_target *pnt, uint8_t *pbtRx, cons
|
||||||
switch(btActivatedMode & 0x70) { // Baud rate
|
switch(btActivatedMode & 0x70) { // Baud rate
|
||||||
case 0x00: // 106kbps
|
case 0x00: // 106kbps
|
||||||
nm.nbr = NBR_106;
|
nm.nbr = NBR_106;
|
||||||
break;
|
break;
|
||||||
case 0x10: // 212kbps
|
case 0x10: // 212kbps
|
||||||
nm.nbr = NBR_212;
|
nm.nbr = NBR_212;
|
||||||
break;
|
break;
|
||||||
case 0x20: // 424kbps
|
case 0x20: // 424kbps
|
||||||
nm.nbr = NBR_424;
|
nm.nbr = NBR_424;
|
||||||
break;
|
break;
|
||||||
};
|
};
|
||||||
|
|
||||||
if (btActivatedMode & 0x04) { // D.E.P.
|
if (btActivatedMode & 0x04) { // D.E.P.
|
||||||
|
@ -1865,8 +1865,8 @@ pn53x_target_init (struct nfc_device *pnd, nfc_target *pnt, uint8_t *pbtRx, cons
|
||||||
memcpy (CHIP_DATA (pnd)->current_target, pnt, sizeof(nfc_target));
|
memcpy (CHIP_DATA (pnd)->current_target, pnt, sizeof(nfc_target));
|
||||||
|
|
||||||
if (ptm & PTM_ISO14443_4_PICC_ONLY) {
|
if (ptm & PTM_ISO14443_4_PICC_ONLY) {
|
||||||
// When PN532 is in PICC target mode, it automatically reply to RATS so
|
// When PN532 is in PICC target mode, it automatically reply to RATS so
|
||||||
// we don't need to forward this command
|
// we don't need to forward this command
|
||||||
szRx = 0;
|
szRx = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1943,7 +1943,7 @@ pn53x_target_receive_bytes (struct nfc_device *pnd, uint8_t *pbtRx, const size_t
|
||||||
return pnd->last_error;
|
return pnd->last_error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// NO BREAK
|
// NO BREAK
|
||||||
case NMT_JEWEL:
|
case NMT_JEWEL:
|
||||||
case NMT_ISO14443B:
|
case NMT_ISO14443B:
|
||||||
case NMT_ISO14443BI:
|
case NMT_ISO14443BI:
|
||||||
|
@ -2048,7 +2048,7 @@ pn53x_target_send_bytes (struct nfc_device *pnd, const uint8_t *pbtTx, const siz
|
||||||
return pnd->last_error;
|
return pnd->last_error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// NO BREAK
|
// NO BREAK
|
||||||
case NMT_JEWEL:
|
case NMT_JEWEL:
|
||||||
case NMT_ISO14443B:
|
case NMT_ISO14443B:
|
||||||
case NMT_ISO14443BI:
|
case NMT_ISO14443BI:
|
||||||
|
@ -2367,7 +2367,7 @@ pn53x_InAutoPoll (struct nfc_device *pnd,
|
||||||
uint8_t abtRx[PN53x_EXTENDED_FRAME__DATA_MAX_LEN];
|
uint8_t abtRx[PN53x_EXTENDED_FRAME__DATA_MAX_LEN];
|
||||||
size_t szRx = sizeof(abtRx);
|
size_t szRx = sizeof(abtRx);
|
||||||
int res = pn53x_transceive (pnd, abtCmd, szTxInAutoPoll, abtRx, szRx, timeout);
|
int res = pn53x_transceive (pnd, abtCmd, szTxInAutoPoll, abtRx, szRx, timeout);
|
||||||
szRx = (size_t) res;
|
szRx = (size_t) res;
|
||||||
if (res < 0) {
|
if (res < 0) {
|
||||||
return res;
|
return res;
|
||||||
} else if (szRx > 0) {
|
} else if (szRx > 0) {
|
||||||
|
@ -2428,18 +2428,18 @@ pn53x_InJumpForDEP (struct nfc_device *pnd,
|
||||||
switch (nbr) {
|
switch (nbr) {
|
||||||
case NBR_106:
|
case NBR_106:
|
||||||
abtCmd[2] = 0x00; // baud rate is 106 kbps
|
abtCmd[2] = 0x00; // baud rate is 106 kbps
|
||||||
break;
|
break;
|
||||||
case NBR_212:
|
case NBR_212:
|
||||||
abtCmd[2] = 0x01; // baud rate is 212 kbps
|
abtCmd[2] = 0x01; // baud rate is 212 kbps
|
||||||
break;
|
break;
|
||||||
case NBR_424:
|
case NBR_424:
|
||||||
abtCmd[2] = 0x02; // baud rate is 424 kbps
|
abtCmd[2] = 0x02; // baud rate is 424 kbps
|
||||||
break;
|
break;
|
||||||
case NBR_847:
|
case NBR_847:
|
||||||
case NBR_UNDEFINED:
|
case NBR_UNDEFINED:
|
||||||
pnd->last_error = NFC_EINVARG;
|
pnd->last_error = NFC_EINVARG;
|
||||||
return pnd->last_error;
|
return pnd->last_error;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pbtPassiveInitiatorData && (ndm == NDM_PASSIVE)) { /* can't have passive initiator data when using active mode */
|
if (pbtPassiveInitiatorData && (ndm == NDM_PASSIVE)) { /* can't have passive initiator data when using active mode */
|
||||||
|
@ -2448,18 +2448,18 @@ pn53x_InJumpForDEP (struct nfc_device *pnd,
|
||||||
abtCmd[3] |= 0x01;
|
abtCmd[3] |= 0x01;
|
||||||
memcpy (abtCmd + offset, pbtPassiveInitiatorData, 4);
|
memcpy (abtCmd + offset, pbtPassiveInitiatorData, 4);
|
||||||
offset += 4;
|
offset += 4;
|
||||||
break;
|
break;
|
||||||
case NBR_212:
|
case NBR_212:
|
||||||
case NBR_424:
|
case NBR_424:
|
||||||
abtCmd[3] |= 0x01;
|
abtCmd[3] |= 0x01;
|
||||||
memcpy (abtCmd + offset, pbtPassiveInitiatorData, 5);
|
memcpy (abtCmd + offset, pbtPassiveInitiatorData, 5);
|
||||||
offset += 5;
|
offset += 5;
|
||||||
break;
|
break;
|
||||||
case NBR_847:
|
case NBR_847:
|
||||||
case NBR_UNDEFINED:
|
case NBR_UNDEFINED:
|
||||||
pnd->last_error = NFC_EINVARG;
|
pnd->last_error = NFC_EINVARG;
|
||||||
return pnd->last_error;
|
return pnd->last_error;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2677,54 +2677,54 @@ pn53x_nm_to_pm(const nfc_modulation nm)
|
||||||
switch(nm.nmt) {
|
switch(nm.nmt) {
|
||||||
case NMT_ISO14443A:
|
case NMT_ISO14443A:
|
||||||
return PM_ISO14443A_106;
|
return PM_ISO14443A_106;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case NMT_ISO14443B:
|
case NMT_ISO14443B:
|
||||||
switch(nm.nbr) {
|
switch(nm.nbr) {
|
||||||
case NBR_106:
|
case NBR_106:
|
||||||
return PM_ISO14443B_106;
|
return PM_ISO14443B_106;
|
||||||
break;
|
break;
|
||||||
case NBR_212:
|
case NBR_212:
|
||||||
return PM_ISO14443B_212;
|
return PM_ISO14443B_212;
|
||||||
break;
|
break;
|
||||||
case NBR_424:
|
case NBR_424:
|
||||||
return PM_ISO14443B_424;
|
return PM_ISO14443B_424;
|
||||||
break;
|
break;
|
||||||
case NBR_847:
|
case NBR_847:
|
||||||
return PM_ISO14443B_847;
|
return PM_ISO14443B_847;
|
||||||
break;
|
break;
|
||||||
case NBR_UNDEFINED:
|
case NBR_UNDEFINED:
|
||||||
// Nothing to do...
|
// Nothing to do...
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case NMT_JEWEL:
|
case NMT_JEWEL:
|
||||||
return PM_JEWEL_106;
|
return PM_JEWEL_106;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case NMT_FELICA:
|
case NMT_FELICA:
|
||||||
switch(nm.nbr) {
|
switch(nm.nbr) {
|
||||||
case NBR_212:
|
case NBR_212:
|
||||||
return PM_FELICA_212;
|
return PM_FELICA_212;
|
||||||
break;
|
break;
|
||||||
case NBR_424:
|
case NBR_424:
|
||||||
return PM_FELICA_424;
|
return PM_FELICA_424;
|
||||||
break;
|
break;
|
||||||
case NBR_106:
|
case NBR_106:
|
||||||
case NBR_847:
|
case NBR_847:
|
||||||
case NBR_UNDEFINED:
|
case NBR_UNDEFINED:
|
||||||
// Nothing to do...
|
// Nothing to do...
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case NMT_ISO14443BI:
|
case NMT_ISO14443BI:
|
||||||
case NMT_ISO14443B2SR:
|
case NMT_ISO14443B2SR:
|
||||||
case NMT_ISO14443B2CT:
|
case NMT_ISO14443B2CT:
|
||||||
case NMT_DEP:
|
case NMT_DEP:
|
||||||
// Nothing to do...
|
// Nothing to do...
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return PM_UNDEFINED;
|
return PM_UNDEFINED;
|
||||||
}
|
}
|
||||||
|
@ -2738,44 +2738,44 @@ pn53x_ptt_to_nm( const pn53x_target_type ptt )
|
||||||
case PTT_GENERIC_PASSIVE_424:
|
case PTT_GENERIC_PASSIVE_424:
|
||||||
case PTT_UNDEFINED:
|
case PTT_UNDEFINED:
|
||||||
// XXX This should not happend, how handle it cleanly ?
|
// XXX This should not happend, how handle it cleanly ?
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PTT_MIFARE:
|
case PTT_MIFARE:
|
||||||
case PTT_ISO14443_4A_106:
|
case PTT_ISO14443_4A_106:
|
||||||
return (const nfc_modulation){ .nmt = NMT_ISO14443A, .nbr = NBR_106 };
|
return (const nfc_modulation) { .nmt = NMT_ISO14443A, .nbr = NBR_106 };
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PTT_ISO14443_4B_106:
|
case PTT_ISO14443_4B_106:
|
||||||
case PTT_ISO14443_4B_TCL_106:
|
case PTT_ISO14443_4B_TCL_106:
|
||||||
return (const nfc_modulation){ .nmt = NMT_ISO14443B, .nbr = NBR_106 };
|
return (const nfc_modulation) { .nmt = NMT_ISO14443B, .nbr = NBR_106 };
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PTT_JEWEL_106:
|
case PTT_JEWEL_106:
|
||||||
return (const nfc_modulation){ .nmt = NMT_JEWEL, .nbr = NBR_106 };
|
return (const nfc_modulation) { .nmt = NMT_JEWEL, .nbr = NBR_106 };
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PTT_FELICA_212:
|
case PTT_FELICA_212:
|
||||||
return (const nfc_modulation){ .nmt = NMT_FELICA, .nbr = NBR_212 };
|
return (const nfc_modulation) { .nmt = NMT_FELICA, .nbr = NBR_212 };
|
||||||
break;
|
break;
|
||||||
case PTT_FELICA_424:
|
case PTT_FELICA_424:
|
||||||
return (const nfc_modulation){ .nmt = NMT_FELICA, .nbr = NBR_424 };
|
return (const nfc_modulation) { .nmt = NMT_FELICA, .nbr = NBR_424 };
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PTT_DEP_PASSIVE_106:
|
case PTT_DEP_PASSIVE_106:
|
||||||
case PTT_DEP_ACTIVE_106:
|
case PTT_DEP_ACTIVE_106:
|
||||||
return (const nfc_modulation){ .nmt = NMT_DEP, .nbr = NBR_106 };
|
return (const nfc_modulation) { .nmt = NMT_DEP, .nbr = NBR_106 };
|
||||||
break;
|
break;
|
||||||
case PTT_DEP_PASSIVE_212:
|
case PTT_DEP_PASSIVE_212:
|
||||||
case PTT_DEP_ACTIVE_212:
|
case PTT_DEP_ACTIVE_212:
|
||||||
return (const nfc_modulation){ .nmt = NMT_DEP, .nbr = NBR_212 };
|
return (const nfc_modulation) { .nmt = NMT_DEP, .nbr = NBR_212 };
|
||||||
break;
|
break;
|
||||||
case PTT_DEP_PASSIVE_424:
|
case PTT_DEP_PASSIVE_424:
|
||||||
case PTT_DEP_ACTIVE_424:
|
case PTT_DEP_ACTIVE_424:
|
||||||
return (const nfc_modulation){ .nmt = NMT_DEP, .nbr = NBR_424 };
|
return (const nfc_modulation) { .nmt = NMT_DEP, .nbr = NBR_424 };
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// We should never be here, this line silent compilation warning
|
// We should never be here, this line silent compilation warning
|
||||||
return (const nfc_modulation){ .nmt = NMT_ISO14443A, .nbr = NBR_106 };
|
return (const nfc_modulation) { .nmt = NMT_ISO14443A, .nbr = NBR_106 };
|
||||||
}
|
}
|
||||||
|
|
||||||
pn53x_target_type
|
pn53x_target_type
|
||||||
|
@ -2785,48 +2785,48 @@ pn53x_nm_to_ptt(const nfc_modulation nm)
|
||||||
case NMT_ISO14443A:
|
case NMT_ISO14443A:
|
||||||
return PTT_MIFARE;
|
return PTT_MIFARE;
|
||||||
// return PTT_ISO14443_4A_106;
|
// return PTT_ISO14443_4A_106;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case NMT_ISO14443B:
|
case NMT_ISO14443B:
|
||||||
switch(nm.nbr) {
|
switch(nm.nbr) {
|
||||||
case NBR_106:
|
case NBR_106:
|
||||||
return PTT_ISO14443_4B_106;
|
return PTT_ISO14443_4B_106;
|
||||||
break;
|
break;
|
||||||
case NBR_UNDEFINED:
|
case NBR_UNDEFINED:
|
||||||
case NBR_212:
|
case NBR_212:
|
||||||
case NBR_424:
|
case NBR_424:
|
||||||
case NBR_847:
|
case NBR_847:
|
||||||
// Nothing to do...
|
// Nothing to do...
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case NMT_JEWEL:
|
case NMT_JEWEL:
|
||||||
return PTT_JEWEL_106;
|
return PTT_JEWEL_106;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case NMT_FELICA:
|
case NMT_FELICA:
|
||||||
switch(nm.nbr) {
|
switch(nm.nbr) {
|
||||||
case NBR_212:
|
case NBR_212:
|
||||||
return PTT_FELICA_212;
|
return PTT_FELICA_212;
|
||||||
break;
|
break;
|
||||||
case NBR_424:
|
case NBR_424:
|
||||||
return PTT_FELICA_424;
|
return PTT_FELICA_424;
|
||||||
break;
|
break;
|
||||||
case NBR_UNDEFINED:
|
case NBR_UNDEFINED:
|
||||||
case NBR_106:
|
case NBR_106:
|
||||||
case NBR_847:
|
case NBR_847:
|
||||||
// Nothing to do...
|
// Nothing to do...
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case NMT_ISO14443BI:
|
case NMT_ISO14443BI:
|
||||||
case NMT_ISO14443B2SR:
|
case NMT_ISO14443B2SR:
|
||||||
case NMT_ISO14443B2CT:
|
case NMT_ISO14443B2CT:
|
||||||
case NMT_DEP:
|
case NMT_DEP:
|
||||||
// Nothing to do...
|
// Nothing to do...
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return PTT_UNDEFINED;
|
return PTT_UNDEFINED;
|
||||||
}
|
}
|
||||||
|
@ -2837,10 +2837,10 @@ pn53x_get_supported_modulation(nfc_device *pnd, const nfc_mode mode, const nfc_m
|
||||||
switch (mode) {
|
switch (mode) {
|
||||||
case N_TARGET:
|
case N_TARGET:
|
||||||
*supported_mt = CHIP_DATA(pnd)->supported_modulation_as_target;
|
*supported_mt = CHIP_DATA(pnd)->supported_modulation_as_target;
|
||||||
break;
|
break;
|
||||||
case N_INITIATOR:
|
case N_INITIATOR:
|
||||||
*supported_mt = CHIP_DATA(pnd)->supported_modulation_as_initiator;
|
*supported_mt = CHIP_DATA(pnd)->supported_modulation_as_initiator;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return NFC_EINVARG;
|
return NFC_EINVARG;
|
||||||
}
|
}
|
||||||
|
@ -2853,10 +2853,10 @@ pn53x_get_supported_baud_rate (nfc_device *pnd, const nfc_modulation_type nmt, c
|
||||||
switch (nmt) {
|
switch (nmt) {
|
||||||
case NMT_FELICA:
|
case NMT_FELICA:
|
||||||
*supported_br = (nfc_baud_rate*)pn53x_felica_supported_baud_rates;
|
*supported_br = (nfc_baud_rate*)pn53x_felica_supported_baud_rates;
|
||||||
break;
|
break;
|
||||||
case NMT_ISO14443A:
|
case NMT_ISO14443A:
|
||||||
*supported_br = (nfc_baud_rate*)pn53x_iso14443a_supported_baud_rates;
|
*supported_br = (nfc_baud_rate*)pn53x_iso14443a_supported_baud_rates;
|
||||||
break;
|
break;
|
||||||
case NMT_ISO14443B:
|
case NMT_ISO14443B:
|
||||||
case NMT_ISO14443BI:
|
case NMT_ISO14443BI:
|
||||||
case NMT_ISO14443B2SR:
|
case NMT_ISO14443B2SR:
|
||||||
|
@ -2871,10 +2871,10 @@ pn53x_get_supported_baud_rate (nfc_device *pnd, const nfc_modulation_type nmt, c
|
||||||
break;
|
break;
|
||||||
case NMT_JEWEL:
|
case NMT_JEWEL:
|
||||||
*supported_br = (nfc_baud_rate*)pn53x_jewel_supported_baud_rates;
|
*supported_br = (nfc_baud_rate*)pn53x_jewel_supported_baud_rates;
|
||||||
break;
|
break;
|
||||||
case NMT_DEP:
|
case NMT_DEP:
|
||||||
*supported_br = (nfc_baud_rate*)pn53x_dep_supported_baud_rates;
|
*supported_br = (nfc_baud_rate*)pn53x_dep_supported_baud_rates;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return NFC_EINVARG;
|
return NFC_EINVARG;
|
||||||
}
|
}
|
||||||
|
|
|
@ -155,41 +155,41 @@ struct pn53x_io {
|
||||||
* @brief PN53x data structure
|
* @brief PN53x data structure
|
||||||
*/
|
*/
|
||||||
struct pn53x_data {
|
struct pn53x_data {
|
||||||
/** Chip type (PN531, PN532 or PN533) */
|
/** Chip type (PN531, PN532 or PN533) */
|
||||||
pn53x_type type;
|
pn53x_type type;
|
||||||
/** Chip firmware text */
|
/** Chip firmware text */
|
||||||
char firmware_text[22];
|
char firmware_text[22];
|
||||||
/** Current power mode */
|
/** Current power mode */
|
||||||
pn53x_power_mode power_mode;
|
pn53x_power_mode power_mode;
|
||||||
/** Current operating mode */
|
/** Current operating mode */
|
||||||
pn53x_operating_mode operating_mode;
|
pn53x_operating_mode operating_mode;
|
||||||
/** Current emulated target */
|
/** Current emulated target */
|
||||||
nfc_target *current_target;
|
nfc_target *current_target;
|
||||||
/** PN53x I/O functions stored in struct */
|
/** PN53x I/O functions stored in struct */
|
||||||
const struct pn53x_io *io;
|
const struct pn53x_io *io;
|
||||||
/** Last status byte returned by PN53x */
|
/** Last status byte returned by PN53x */
|
||||||
uint8_t last_status_byte;
|
uint8_t last_status_byte;
|
||||||
/** Register cache for REG_CIU_BIT_FRAMING, SYMBOL_TX_LAST_BITS: The last TX bits setting, we need to reset this if it does not apply anymore */
|
/** Register cache for REG_CIU_BIT_FRAMING, SYMBOL_TX_LAST_BITS: The last TX bits setting, we need to reset this if it does not apply anymore */
|
||||||
uint8_t ui8TxBits;
|
uint8_t ui8TxBits;
|
||||||
/** Register cache for SetParameters function. */
|
/** Register cache for SetParameters function. */
|
||||||
uint8_t ui8Parameters;
|
uint8_t ui8Parameters;
|
||||||
/** Last sent command */
|
/** Last sent command */
|
||||||
uint8_t last_command;
|
uint8_t last_command;
|
||||||
/** Interframe timer correction */
|
/** Interframe timer correction */
|
||||||
int16_t timer_correction;
|
int16_t timer_correction;
|
||||||
/** Timer prescaler */
|
/** Timer prescaler */
|
||||||
uint16_t timer_prescaler;
|
uint16_t timer_prescaler;
|
||||||
/** WriteBack cache */
|
/** WriteBack cache */
|
||||||
uint8_t wb_data[PN53X_CACHE_REGISTER_SIZE];
|
uint8_t wb_data[PN53X_CACHE_REGISTER_SIZE];
|
||||||
uint8_t wb_mask[PN53X_CACHE_REGISTER_SIZE];
|
uint8_t wb_mask[PN53X_CACHE_REGISTER_SIZE];
|
||||||
bool wb_trigged;
|
bool wb_trigged;
|
||||||
/** Command timeout */
|
/** Command timeout */
|
||||||
int timeout_command;
|
int timeout_command;
|
||||||
/** ATR timeout */
|
/** ATR timeout */
|
||||||
int timeout_atr;
|
int timeout_atr;
|
||||||
/** Communication timeout */
|
/** Communication timeout */
|
||||||
int timeout_communication;
|
int timeout_communication;
|
||||||
/** Supported modulation type */
|
/** Supported modulation type */
|
||||||
nfc_modulation_type *supported_modulation_as_initiator;
|
nfc_modulation_type *supported_modulation_as_initiator;
|
||||||
nfc_modulation_type *supported_modulation_as_target;
|
nfc_modulation_type *supported_modulation_as_target;
|
||||||
};
|
};
|
||||||
|
@ -203,21 +203,21 @@ struct pn53x_data {
|
||||||
typedef enum {
|
typedef enum {
|
||||||
/** Undefined modulation */
|
/** Undefined modulation */
|
||||||
PM_UNDEFINED = -1,
|
PM_UNDEFINED = -1,
|
||||||
/** ISO14443-A (NXP MIFARE) http://en.wikipedia.org/wiki/MIFARE */
|
/** ISO14443-A (NXP MIFARE) http://en.wikipedia.org/wiki/MIFARE */
|
||||||
PM_ISO14443A_106 = 0x00,
|
PM_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 */
|
||||||
PM_FELICA_212 = 0x01,
|
PM_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 */
|
||||||
PM_FELICA_424 = 0x02,
|
PM_FELICA_424 = 0x02,
|
||||||
/** ISO14443-B http://en.wikipedia.org/wiki/ISO/IEC_14443 (Not supported by PN531) */
|
/** ISO14443-B http://en.wikipedia.org/wiki/ISO/IEC_14443 (Not supported by PN531) */
|
||||||
PM_ISO14443B_106 = 0x03,
|
PM_ISO14443B_106 = 0x03,
|
||||||
/** Jewel Topaz (Innovision Research & Development) (Not supported by PN531) */
|
/** Jewel Topaz (Innovision Research & Development) (Not supported by PN531) */
|
||||||
PM_JEWEL_106 = 0x04,
|
PM_JEWEL_106 = 0x04,
|
||||||
/** ISO14443-B http://en.wikipedia.org/wiki/ISO/IEC_14443 (Not supported by PN531 nor PN532) */
|
/** ISO14443-B http://en.wikipedia.org/wiki/ISO/IEC_14443 (Not supported by PN531 nor PN532) */
|
||||||
PM_ISO14443B_212 = 0x06,
|
PM_ISO14443B_212 = 0x06,
|
||||||
/** ISO14443-B http://en.wikipedia.org/wiki/ISO/IEC_14443 (Not supported by PN531 nor PN532) */
|
/** ISO14443-B http://en.wikipedia.org/wiki/ISO/IEC_14443 (Not supported by PN531 nor PN532) */
|
||||||
PM_ISO14443B_424 = 0x07,
|
PM_ISO14443B_424 = 0x07,
|
||||||
/** ISO14443-B http://en.wikipedia.org/wiki/ISO/IEC_14443 (Not supported by PN531 nor PN532) */
|
/** ISO14443-B http://en.wikipedia.org/wiki/ISO/IEC_14443 (Not supported by PN531 nor PN532) */
|
||||||
PM_ISO14443B_847 = 0x08,
|
PM_ISO14443B_847 = 0x08,
|
||||||
} pn53x_modulation;
|
} pn53x_modulation;
|
||||||
|
|
||||||
|
@ -299,8 +299,8 @@ int pn53x_set_tx_bits (struct nfc_device *pnd, const uint8_t ui8Bits);
|
||||||
int pn53x_wrap_frame (const uint8_t *pbtTx, const size_t szTxBits, const uint8_t *pbtTxPar, uint8_t *pbtFrame);
|
int pn53x_wrap_frame (const uint8_t *pbtTx, const size_t szTxBits, const uint8_t *pbtTxPar, uint8_t *pbtFrame);
|
||||||
int pn53x_unwrap_frame (const uint8_t *pbtFrame, const size_t szFrameBits, uint8_t *pbtRx, uint8_t *pbtRxPar);
|
int pn53x_unwrap_frame (const uint8_t *pbtFrame, const size_t szFrameBits, uint8_t *pbtRx, uint8_t *pbtRxPar);
|
||||||
int pn53x_decode_target_data (const uint8_t *pbtRawData, size_t szRawData,
|
int pn53x_decode_target_data (const uint8_t *pbtRawData, size_t szRawData,
|
||||||
pn53x_type chip_type, nfc_modulation_type nmt,
|
pn53x_type chip_type, nfc_modulation_type nmt,
|
||||||
nfc_target_info *pnti);
|
nfc_target_info *pnti);
|
||||||
int pn53x_read_register (struct nfc_device *pnd, uint16_t ui16Reg, uint8_t *ui8Value);
|
int pn53x_read_register (struct nfc_device *pnd, uint16_t ui16Reg, uint8_t *ui8Value);
|
||||||
int pn53x_write_register (struct nfc_device *pnd, uint16_t ui16Reg, uint8_t ui8SymbolMask, uint8_t ui8Value);
|
int pn53x_write_register (struct nfc_device *pnd, uint16_t ui16Reg, uint8_t ui8SymbolMask, uint8_t ui8Value);
|
||||||
int pn53x_decode_firmware_version (struct nfc_device *pnd);
|
int pn53x_decode_firmware_version (struct nfc_device *pnd);
|
||||||
|
@ -313,26 +313,26 @@ int pn53x_idle (struct nfc_device *pnd);
|
||||||
// NFC device as Initiator functions
|
// NFC device as Initiator functions
|
||||||
int pn53x_initiator_init (struct nfc_device *pnd);
|
int pn53x_initiator_init (struct nfc_device *pnd);
|
||||||
int pn53x_initiator_select_passive_target (struct nfc_device *pnd,
|
int pn53x_initiator_select_passive_target (struct nfc_device *pnd,
|
||||||
const nfc_modulation nm,
|
const nfc_modulation nm,
|
||||||
const uint8_t *pbtInitData, const size_t szInitData,
|
const uint8_t *pbtInitData, const size_t szInitData,
|
||||||
nfc_target *pnt);
|
nfc_target *pnt);
|
||||||
int pn53x_initiator_poll_target (struct nfc_device *pnd,
|
int pn53x_initiator_poll_target (struct nfc_device *pnd,
|
||||||
const nfc_modulation *pnmModulations, const size_t szModulations,
|
const nfc_modulation *pnmModulations, const size_t szModulations,
|
||||||
const uint8_t uiPollNr, const uint8_t uiPeriod,
|
const uint8_t uiPollNr, const uint8_t uiPeriod,
|
||||||
nfc_target *pnt);
|
nfc_target *pnt);
|
||||||
int pn53x_initiator_select_dep_target (struct nfc_device *pnd,
|
int pn53x_initiator_select_dep_target (struct nfc_device *pnd,
|
||||||
const nfc_dep_mode ndm, const nfc_baud_rate nbr,
|
const nfc_dep_mode ndm, const nfc_baud_rate nbr,
|
||||||
const nfc_dep_info *pndiInitiator,
|
const nfc_dep_info *pndiInitiator,
|
||||||
nfc_target *pnt,
|
nfc_target *pnt,
|
||||||
const int timeout);
|
const int timeout);
|
||||||
int pn53x_initiator_transceive_bits (struct nfc_device *pnd, const uint8_t *pbtTx, const size_t szTxBits,
|
int pn53x_initiator_transceive_bits (struct nfc_device *pnd, const uint8_t *pbtTx, const size_t szTxBits,
|
||||||
const uint8_t *pbtTxPar, uint8_t *pbtRx, uint8_t *pbtRxPar);
|
const uint8_t *pbtTxPar, uint8_t *pbtRx, uint8_t *pbtRxPar);
|
||||||
int pn53x_initiator_transceive_bytes (struct nfc_device *pnd, const uint8_t *pbtTx, const size_t szTx,
|
int pn53x_initiator_transceive_bytes (struct nfc_device *pnd, const uint8_t *pbtTx, const size_t szTx,
|
||||||
uint8_t *pbtRx, const size_t szRx, int timeout);
|
uint8_t *pbtRx, const size_t szRx, int timeout);
|
||||||
int pn53x_initiator_transceive_bits_timed (struct nfc_device *pnd, const uint8_t *pbtTx, const size_t szTxBits,
|
int pn53x_initiator_transceive_bits_timed (struct nfc_device *pnd, const uint8_t *pbtTx, const size_t szTxBits,
|
||||||
const uint8_t *pbtTxPar, uint8_t *pbtRx, uint8_t *pbtRxPar, uint32_t *cycles);
|
const uint8_t *pbtTxPar, uint8_t *pbtRx, uint8_t *pbtRxPar, uint32_t *cycles);
|
||||||
int pn53x_initiator_transceive_bytes_timed (struct nfc_device *pnd, const uint8_t *pbtTx, const size_t szTx,
|
int pn53x_initiator_transceive_bytes_timed (struct nfc_device *pnd, const uint8_t *pbtTx, const size_t szTx,
|
||||||
uint8_t *pbtRx, uint32_t *cycles);
|
uint8_t *pbtRx, uint32_t *cycles);
|
||||||
int pn53x_initiator_deselect_target (struct nfc_device *pnd);
|
int pn53x_initiator_deselect_target (struct nfc_device *pnd);
|
||||||
int pn53x_initiator_target_is_present (struct nfc_device *pnd, const nfc_target nt);
|
int pn53x_initiator_target_is_present (struct nfc_device *pnd, const nfc_target nt);
|
||||||
|
|
||||||
|
@ -351,27 +351,27 @@ int pn53x_SetParameters (struct nfc_device *pnd, const uint8_t ui8Value);
|
||||||
int pn53x_SAMConfiguration (struct nfc_device *pnd, const pn532_sam_mode mode, int timeout);
|
int pn53x_SAMConfiguration (struct nfc_device *pnd, const pn532_sam_mode mode, int timeout);
|
||||||
int pn53x_PowerDown (struct nfc_device *pnd);
|
int pn53x_PowerDown (struct nfc_device *pnd);
|
||||||
int pn53x_InListPassiveTarget (struct nfc_device *pnd, const pn53x_modulation pmInitModulation,
|
int pn53x_InListPassiveTarget (struct nfc_device *pnd, const pn53x_modulation pmInitModulation,
|
||||||
const uint8_t szMaxTargets, const uint8_t *pbtInitiatorData,
|
const uint8_t szMaxTargets, const uint8_t *pbtInitiatorData,
|
||||||
const size_t szInitiatorDataLen, uint8_t *pbtTargetsData, size_t *pszTargetsData,
|
const size_t szInitiatorDataLen, uint8_t *pbtTargetsData, size_t *pszTargetsData,
|
||||||
int timeout);
|
int timeout);
|
||||||
int pn53x_InDeselect (struct nfc_device *pnd, const uint8_t ui8Target);
|
int pn53x_InDeselect (struct nfc_device *pnd, const uint8_t ui8Target);
|
||||||
int pn53x_InRelease (struct nfc_device *pnd, const uint8_t ui8Target);
|
int pn53x_InRelease (struct nfc_device *pnd, const uint8_t ui8Target);
|
||||||
int pn53x_InAutoPoll (struct nfc_device *pnd, const pn53x_target_type *ppttTargetTypes, const size_t szTargetTypes,
|
int pn53x_InAutoPoll (struct nfc_device *pnd, const pn53x_target_type *ppttTargetTypes, const size_t szTargetTypes,
|
||||||
const uint8_t btPollNr, const uint8_t btPeriod, nfc_target *pntTargets,
|
const uint8_t btPollNr, const uint8_t btPeriod, nfc_target *pntTargets,
|
||||||
const int timeout);
|
const int timeout);
|
||||||
int pn53x_InJumpForDEP (struct nfc_device *pnd,
|
int pn53x_InJumpForDEP (struct nfc_device *pnd,
|
||||||
const nfc_dep_mode ndm, const nfc_baud_rate nbr,
|
const nfc_dep_mode ndm, const nfc_baud_rate nbr,
|
||||||
const uint8_t *pbtPassiveInitiatorData,
|
const uint8_t *pbtPassiveInitiatorData,
|
||||||
const uint8_t *pbtNFCID3i,
|
const uint8_t *pbtNFCID3i,
|
||||||
const uint8_t *pbtGB, const size_t szGB,
|
const uint8_t *pbtGB, const size_t szGB,
|
||||||
nfc_target *pnt,
|
nfc_target *pnt,
|
||||||
const int timeout);
|
const int timeout);
|
||||||
int pn53x_TgInitAsTarget (struct nfc_device *pnd, pn53x_target_mode ptm,
|
int pn53x_TgInitAsTarget (struct nfc_device *pnd, pn53x_target_mode ptm,
|
||||||
const uint8_t *pbtMifareParams,
|
const uint8_t *pbtMifareParams,
|
||||||
const uint8_t *pbtTkt, size_t szTkt,
|
const uint8_t *pbtTkt, size_t szTkt,
|
||||||
const uint8_t *pbtFeliCaParams,
|
const uint8_t *pbtFeliCaParams,
|
||||||
const uint8_t *pbtNFCID3t, const uint8_t *pbtGB, const size_t szGB,
|
const uint8_t *pbtNFCID3t, const uint8_t *pbtGB, const size_t szGB,
|
||||||
uint8_t *pbtRx, const size_t szRxLen, uint8_t *pbtModeByte, int timeout);
|
uint8_t *pbtRx, const size_t szRxLen, uint8_t *pbtModeByte, int timeout);
|
||||||
|
|
||||||
// RFConfiguration
|
// RFConfiguration
|
||||||
int pn53x_RFConfiguration__RF_field (struct nfc_device *pnd, bool bEnable);
|
int pn53x_RFConfiguration__RF_field (struct nfc_device *pnd, bool bEnable);
|
||||||
|
|
|
@ -383,9 +383,9 @@ acr122_pcsc_send (nfc_device *pnd, const uint8_t *pbtData, const size_t szData,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (DRIVER_DATA (pnd)->ioCard.dwProtocol == SCARD_PROTOCOL_T0) {
|
if (DRIVER_DATA (pnd)->ioCard.dwProtocol == SCARD_PROTOCOL_T0) {
|
||||||
/*
|
/*
|
||||||
* Check the MCU response
|
* Check the MCU response
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// Make sure we received the byte-count we expected
|
// Make sure we received the byte-count we expected
|
||||||
if (dwRxLen != 2) {
|
if (dwRxLen != 2) {
|
||||||
|
|
|
@ -56,15 +56,15 @@ Thanks to d18c7db and Okko for example code
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
// Under POSIX system, we use libusb (>= 0.1.12)
|
// Under POSIX system, we use libusb (>= 0.1.12)
|
||||||
#include <usb.h>
|
#include <usb.h>
|
||||||
#define USB_TIMEDOUT ETIMEDOUT
|
#define USB_TIMEDOUT ETIMEDOUT
|
||||||
#define _usb_strerror( X ) strerror(-X)
|
#define _usb_strerror( X ) strerror(-X)
|
||||||
#else
|
#else
|
||||||
// Under Windows we use libusb-win32 (>= 1.2.5)
|
// Under Windows we use libusb-win32 (>= 1.2.5)
|
||||||
#include <lusb0_usb.h>
|
#include <lusb0_usb.h>
|
||||||
#define USB_TIMEDOUT 116
|
#define USB_TIMEDOUT 116
|
||||||
#define _usb_strerror( X ) usb_strerror()
|
#define _usb_strerror( X ) usb_strerror()
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
@ -158,7 +158,7 @@ acr122_usb_get_device_model (uint16_t vendor_id, uint16_t product_id)
|
||||||
{
|
{
|
||||||
for (size_t n = 0; n < sizeof (acr122_usb_supported_devices) / sizeof (struct acr122_usb_supported_device); n++) {
|
for (size_t n = 0; n < sizeof (acr122_usb_supported_devices) / sizeof (struct acr122_usb_supported_device); n++) {
|
||||||
if ((vendor_id == acr122_usb_supported_devices[n].vendor_id) &&
|
if ((vendor_id == acr122_usb_supported_devices[n].vendor_id) &&
|
||||||
(product_id == acr122_usb_supported_devices[n].product_id))
|
(product_id == acr122_usb_supported_devices[n].product_id))
|
||||||
return acr122_usb_supported_devices[n].model;
|
return acr122_usb_supported_devices[n].model;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -363,7 +363,7 @@ acr122_usb_open (const nfc_connstring connstring)
|
||||||
for (dev = bus->devices; dev; dev = dev->next) {
|
for (dev = bus->devices; dev; dev = dev->next) {
|
||||||
if (connstring_decode_level > 2) {
|
if (connstring_decode_level > 2) {
|
||||||
// A specific dev have been specified
|
// A specific dev have been specified
|
||||||
if (0 != strcmp (dev->filename, desc.filename))
|
if (0 != strcmp (dev->filename, desc.filename))
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// Open the USB device
|
// Open the USB device
|
||||||
|
@ -401,7 +401,7 @@ acr122_usb_open (const nfc_connstring connstring)
|
||||||
pn53x_data_new (pnd, &acr122_usb_io);
|
pn53x_data_new (pnd, &acr122_usb_io);
|
||||||
|
|
||||||
switch (DRIVER_DATA (pnd)->model) {
|
switch (DRIVER_DATA (pnd)->model) {
|
||||||
// empirical tuning
|
// empirical tuning
|
||||||
case ACR122:
|
case ACR122:
|
||||||
CHIP_DATA (pnd)->timer_correction = 46;
|
CHIP_DATA (pnd)->timer_correction = 46;
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -223,10 +223,10 @@ acr122s_send_frame(nfc_device *pnd, uint8_t *frame, int timeout)
|
||||||
if ((ret = uart_receive(port, ack, 4, abort_p, timeout)) < 0)
|
if ((ret = uart_receive(port, ack, 4, abort_p, timeout)) < 0)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
if (memcmp(ack, positive_ack, 4) != 0){
|
if (memcmp(ack, positive_ack, 4) != 0) {
|
||||||
pnd->last_error = NFC_EIO;
|
pnd->last_error = NFC_EIO;
|
||||||
return pnd->last_error;
|
return pnd->last_error;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct xfr_block_req *req = (struct xfr_block_req *) &frame[1];
|
struct xfr_block_req *req = (struct xfr_block_req *) &frame[1];
|
||||||
DRIVER_DATA(pnd)->seq = req->seq + 1;
|
DRIVER_DATA(pnd)->seq = req->seq + 1;
|
||||||
|
@ -250,9 +250,9 @@ static int
|
||||||
acr122s_recv_frame(nfc_device *pnd, uint8_t *frame, size_t frame_size, void *abort_p, int timeout)
|
acr122s_recv_frame(nfc_device *pnd, uint8_t *frame, size_t frame_size, void *abort_p, int timeout)
|
||||||
{
|
{
|
||||||
if (frame_size < 13)
|
if (frame_size < 13)
|
||||||
{ pnd->last_error = NFC_EINVARG;
|
{ pnd->last_error = NFC_EINVARG;
|
||||||
return pnd->last_error;
|
return pnd->last_error;
|
||||||
}
|
}
|
||||||
int ret;
|
int ret;
|
||||||
serial_port port = DRIVER_DATA(pnd)->port;
|
serial_port port = DRIVER_DATA(pnd)->port;
|
||||||
|
|
||||||
|
@ -260,7 +260,7 @@ acr122s_recv_frame(nfc_device *pnd, uint8_t *frame, size_t frame_size, void *abo
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
// Is buffer sufficient to store response?
|
// Is buffer sufficient to store response?
|
||||||
if (frame_size < FRAME_SIZE(frame)){
|
if (frame_size < FRAME_SIZE(frame)) {
|
||||||
pnd->last_error = NFC_EIO;
|
pnd->last_error = NFC_EIO;
|
||||||
return pnd->last_error;
|
return pnd->last_error;
|
||||||
}
|
}
|
||||||
|
@ -286,13 +286,13 @@ acr122s_recv_frame(nfc_device *pnd, uint8_t *frame, size_t frame_size, void *abo
|
||||||
*/
|
*/
|
||||||
static uint32_t
|
static uint32_t
|
||||||
le32(uint32_t val) {
|
le32(uint32_t val) {
|
||||||
uint32_t res;
|
uint32_t res;
|
||||||
uint8_t *p = (uint8_t *) &res;
|
uint8_t *p = (uint8_t *) &res;
|
||||||
p[0] = val;
|
p[0] = val;
|
||||||
p[1] = val >> 8;
|
p[1] = val >> 8;
|
||||||
p[2] = val >> 16;
|
p[2] = val >> 16;
|
||||||
p[3] = val >> 24;
|
p[3] = val >> 24;
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -311,8 +311,8 @@ le32(uint32_t val) {
|
||||||
*/
|
*/
|
||||||
static bool
|
static bool
|
||||||
acr122s_build_frame(nfc_device *pnd,
|
acr122s_build_frame(nfc_device *pnd,
|
||||||
uint8_t *frame, size_t frame_size, uint8_t p1, uint8_t p2,
|
uint8_t *frame, size_t frame_size, uint8_t p1, uint8_t p2,
|
||||||
const uint8_t *data, size_t data_size, int should_prefix)
|
const uint8_t *data, size_t data_size, int should_prefix)
|
||||||
{
|
{
|
||||||
if (frame_size < data_size + APDU_OVERHEAD + should_prefix)
|
if (frame_size < data_size + APDU_OVERHEAD + should_prefix)
|
||||||
return false;
|
return false;
|
||||||
|
@ -333,7 +333,7 @@ acr122s_build_frame(nfc_device *pnd,
|
||||||
header->ins = 0;
|
header->ins = 0;
|
||||||
header->p1 = p1;
|
header->p1 = p1;
|
||||||
header->p2 = p2;
|
header->p2 = p2;
|
||||||
header->length = data_size + should_prefix;
|
header->length = data_size + should_prefix;
|
||||||
|
|
||||||
uint8_t *buf = (uint8_t *) &frame[16];
|
uint8_t *buf = (uint8_t *) &frame[16];
|
||||||
if (should_prefix)
|
if (should_prefix)
|
||||||
|
@ -480,7 +480,7 @@ acr122s_probe(nfc_connstring connstrings[], size_t connstrings_len, size_t *pszD
|
||||||
#else /* SERIAL_AUTOPROBE_ENABLED */
|
#else /* SERIAL_AUTOPROBE_ENABLED */
|
||||||
*pszDeviceFound = 0;
|
*pszDeviceFound = 0;
|
||||||
|
|
||||||
serial_port sp;
|
serial_port sp;
|
||||||
char **acPorts = uart_list_ports ();
|
char **acPorts = uart_list_ports ();
|
||||||
const char *acPort;
|
const char *acPort;
|
||||||
int iDevice = 0;
|
int iDevice = 0;
|
||||||
|
@ -560,17 +560,17 @@ acr122s_open(const nfc_connstring connstring)
|
||||||
}
|
}
|
||||||
|
|
||||||
log_put(LOG_CATEGORY, NFC_PRIORITY_TRACE,
|
log_put(LOG_CATEGORY, NFC_PRIORITY_TRACE,
|
||||||
"Attempt to connect to: %s at %d bauds.", ndd.port, ndd.speed);
|
"Attempt to connect to: %s at %d bauds.", ndd.port, ndd.speed);
|
||||||
|
|
||||||
sp = uart_open(ndd.port);
|
sp = uart_open(ndd.port);
|
||||||
if (sp == INVALID_SERIAL_PORT) {
|
if (sp == INVALID_SERIAL_PORT) {
|
||||||
log_put(LOG_CATEGORY, NFC_PRIORITY_ERROR,
|
log_put(LOG_CATEGORY, NFC_PRIORITY_ERROR,
|
||||||
"Invalid serial port: %s", ndd.port);
|
"Invalid serial port: %s", ndd.port);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (sp == CLAIMED_SERIAL_PORT) {
|
if (sp == CLAIMED_SERIAL_PORT) {
|
||||||
log_put(LOG_CATEGORY, NFC_PRIORITY_ERROR,
|
log_put(LOG_CATEGORY, NFC_PRIORITY_ERROR,
|
||||||
"Serial port already claimed: %s", ndd.port);
|
"Serial port already claimed: %s", ndd.port);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -607,7 +607,7 @@ acr122s_open(const nfc_connstring connstring)
|
||||||
|
|
||||||
if (strncmp(version, "ACR122S", 7) != 0) {
|
if (strncmp(version, "ACR122S", 7) != 0) {
|
||||||
log_put(LOG_CATEGORY, NFC_PRIORITY_ERROR, "Invalid firmware version: %s",
|
log_put(LOG_CATEGORY, NFC_PRIORITY_ERROR, "Invalid firmware version: %s",
|
||||||
version);
|
version);
|
||||||
acr122s_close(pnd);
|
acr122s_close(pnd);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
|
@ -314,7 +314,7 @@ pn532_uart_send (nfc_device *pnd, const uint8_t *pbtData, const size_t szData, i
|
||||||
break;
|
break;
|
||||||
case NORMAL:
|
case NORMAL:
|
||||||
// Nothing to do :)
|
// Nothing to do :)
|
||||||
break;
|
break;
|
||||||
};
|
};
|
||||||
|
|
||||||
uint8_t abtFrame[PN532_BUFFER_LEN] = { 0x00, 0x00, 0xff }; // Every packet must start with "00 00 ff"
|
uint8_t abtFrame[PN532_BUFFER_LEN] = { 0x00, 0x00, 0xff }; // Every packet must start with "00 00 ff"
|
||||||
|
|
|
@ -39,15 +39,15 @@ Thanks to d18c7db and Okko for example code
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
// Under POSIX system, we use libusb (>= 0.1.12)
|
// Under POSIX system, we use libusb (>= 0.1.12)
|
||||||
#include <usb.h>
|
#include <usb.h>
|
||||||
#define USB_TIMEDOUT ETIMEDOUT
|
#define USB_TIMEDOUT ETIMEDOUT
|
||||||
#define _usb_strerror( X ) strerror(-X)
|
#define _usb_strerror( X ) strerror(-X)
|
||||||
#else
|
#else
|
||||||
// Under Windows we use libusb-win32 (>= 1.2.5)
|
// Under Windows we use libusb-win32 (>= 1.2.5)
|
||||||
#include <lusb0_usb.h>
|
#include <lusb0_usb.h>
|
||||||
#define USB_TIMEDOUT 116
|
#define USB_TIMEDOUT 116
|
||||||
#define _usb_strerror( X ) usb_strerror()
|
#define _usb_strerror( X ) usb_strerror()
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
@ -139,7 +139,7 @@ pn53x_usb_get_device_model (uint16_t vendor_id, uint16_t product_id)
|
||||||
{
|
{
|
||||||
for (size_t n = 0; n < sizeof (pn53x_usb_supported_devices) / sizeof (struct pn53x_usb_supported_device); n++) {
|
for (size_t n = 0; n < sizeof (pn53x_usb_supported_devices) / sizeof (struct pn53x_usb_supported_device); n++) {
|
||||||
if ((vendor_id == pn53x_usb_supported_devices[n].vendor_id) &&
|
if ((vendor_id == pn53x_usb_supported_devices[n].vendor_id) &&
|
||||||
(product_id == pn53x_usb_supported_devices[n].product_id))
|
(product_id == pn53x_usb_supported_devices[n].product_id))
|
||||||
return pn53x_usb_supported_devices[n].model;
|
return pn53x_usb_supported_devices[n].model;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -354,7 +354,7 @@ pn53x_usb_open (const nfc_connstring connstring)
|
||||||
for (dev = bus->devices; dev; dev = dev->next) {
|
for (dev = bus->devices; dev; dev = dev->next) {
|
||||||
if (connstring_decode_level > 2) {
|
if (connstring_decode_level > 2) {
|
||||||
// A specific dev have been specified
|
// A specific dev have been specified
|
||||||
if (0 != strcmp (dev->filename, desc.filename))
|
if (0 != strcmp (dev->filename, desc.filename))
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// Open the USB device
|
// Open the USB device
|
||||||
|
@ -392,7 +392,7 @@ pn53x_usb_open (const nfc_connstring connstring)
|
||||||
pn53x_data_new (pnd, &pn53x_usb_io);
|
pn53x_data_new (pnd, &pn53x_usb_io);
|
||||||
|
|
||||||
switch (DRIVER_DATA (pnd)->model) {
|
switch (DRIVER_DATA (pnd)->model) {
|
||||||
// empirical tuning
|
// empirical tuning
|
||||||
case ASK_LOGO:
|
case ASK_LOGO:
|
||||||
CHIP_DATA (pnd)->timer_correction = 50;
|
CHIP_DATA (pnd)->timer_correction = 50;
|
||||||
break;
|
break;
|
||||||
|
@ -684,23 +684,23 @@ pn53x_usb_init (nfc_device *pnd)
|
||||||
/* Setup push-pulls for pins from P30 to P35 */
|
/* Setup push-pulls for pins from P30 to P35 */
|
||||||
pn53x_write_register (pnd, PN53X_SFR_P3CFGB, 0xFF, 0x37);
|
pn53x_write_register (pnd, PN53X_SFR_P3CFGB, 0xFF, 0x37);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
On ASK LoGO hardware:
|
On ASK LoGO hardware:
|
||||||
LEDs port bits definition:
|
LEDs port bits definition:
|
||||||
* LED 1: bit 2 (P32)
|
* LED 1: bit 2 (P32)
|
||||||
* LED 2: bit 1 (P31)
|
* LED 2: bit 1 (P31)
|
||||||
* LED 3: bit 0 or 3 (depending of hardware revision) (P30 or P33)
|
* LED 3: bit 0 or 3 (depending of hardware revision) (P30 or P33)
|
||||||
* LED 4: bit 5 (P35)
|
* LED 4: bit 5 (P35)
|
||||||
Notes:
|
Notes:
|
||||||
* Set logical 0 to switch LED on; logical 1 to switch LED off.
|
* Set logical 0 to switch LED on; logical 1 to switch LED off.
|
||||||
* Bit 4 should be maintained at 1 to keep RF field on.
|
* Bit 4 should be maintained at 1 to keep RF field on.
|
||||||
|
|
||||||
Progressive field activation:
|
Progressive field activation:
|
||||||
The ASK LoGO hardware can progressively power-up the antenna.
|
The ASK LoGO hardware can progressively power-up the antenna.
|
||||||
To use this feature we have to switch on the field by switching on
|
To use this feature we have to switch on the field by switching on
|
||||||
the field on PN533 (RFConfiguration) then set P34 to '1', and cut-off the
|
the field on PN533 (RFConfiguration) then set P34 to '1', and cut-off the
|
||||||
field by switching off the field on PN533 then set P34 to '0'.
|
field by switching off the field on PN533 then set P34 to '0'.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* Set P30, P31, P33, P35 to logic 1 and P32, P34 to 0 logic */
|
/* Set P30, P31, P33, P35 to logic 1 and P32, P34 to 0 logic */
|
||||||
/* ie. Switch LED1 on and turn off progressive field */
|
/* ie. Switch LED1 on and turn off progressive field */
|
||||||
|
|
|
@ -17,10 +17,10 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @file iso14443-subr.c
|
* @file iso14443-subr.c
|
||||||
* @brief Defines some function extracted for ISO/IEC 14443
|
* @brief Defines some function extracted for ISO/IEC 14443
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifdef HAVE_CONFIG_H
|
#ifdef HAVE_CONFIG_H
|
||||||
# include "config.h"
|
# include "config.h"
|
||||||
|
|
|
@ -17,10 +17,10 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @file iso7816.h
|
* @file iso7816.h
|
||||||
* @brief Defines some macros extracted for ISO/IEC 7816-4
|
* @brief Defines some macros extracted for ISO/IEC 7816-4
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef __LIBNFC_ISO7816_H__
|
#ifndef __LIBNFC_ISO7816_H__
|
||||||
#define __LIBNFC_ISO7816_H__
|
#define __LIBNFC_ISO7816_H__
|
||||||
|
|
62
libnfc/log.h
62
libnfc/log.h
|
@ -32,43 +32,43 @@
|
||||||
# define __has_attribute_format 1
|
# define __has_attribute_format 1
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
// User want debug features
|
// User want debug features
|
||||||
#define LOGGING 1
|
#define LOGGING 1
|
||||||
int log_init (void);
|
int log_init (void);
|
||||||
int log_fini (void);
|
int log_fini (void);
|
||||||
void log_put (const char *category, const char *priority, const char *format, ...)
|
void log_put (const char *category, const char *priority, const char *format, ...)
|
||||||
# if __has_attribute_format
|
# if __has_attribute_format
|
||||||
__attribute__((format(printf, 3, 4)))
|
__attribute__((format(printf, 3, 4)))
|
||||||
# endif
|
# endif
|
||||||
;
|
;
|
||||||
|
|
||||||
|
|
||||||
#define NFC_PRIORITY_FATAL "fatal"
|
#define NFC_PRIORITY_FATAL "fatal"
|
||||||
#define NFC_PRIORITY_ALERT "alert"
|
#define NFC_PRIORITY_ALERT "alert"
|
||||||
#define NFC_PRIORITY_CRIT "critical"
|
#define NFC_PRIORITY_CRIT "critical"
|
||||||
#define NFC_PRIORITY_ERROR "error"
|
#define NFC_PRIORITY_ERROR "error"
|
||||||
#define NFC_PRIORITY_WARN "warning"
|
#define NFC_PRIORITY_WARN "warning"
|
||||||
#define NFC_PRIORITY_NOTICE "notice"
|
#define NFC_PRIORITY_NOTICE "notice"
|
||||||
#define NFC_PRIORITY_INFO "info"
|
#define NFC_PRIORITY_INFO "info"
|
||||||
#define NFC_PRIORITY_DEBUG "debug"
|
#define NFC_PRIORITY_DEBUG "debug"
|
||||||
#define NFC_PRIORITY_TRACE "trace"
|
#define NFC_PRIORITY_TRACE "trace"
|
||||||
#else
|
#else
|
||||||
// No logging
|
// No logging
|
||||||
#define log_init() ((void) 0)
|
#define log_init() ((void) 0)
|
||||||
#define log_fini() ((void) 0)
|
#define log_fini() ((void) 0)
|
||||||
#define log_msg(category, priority, message) do {} while (0)
|
#define log_msg(category, priority, message) do {} while (0)
|
||||||
#define log_set_appender(category, appender) do {} while (0)
|
#define log_set_appender(category, appender) do {} while (0)
|
||||||
#define log_put(category, priority, format, ...) do {} while (0)
|
#define log_put(category, priority, format, ...) do {} while (0)
|
||||||
|
|
||||||
#define NFC_PRIORITY_FATAL 8
|
#define NFC_PRIORITY_FATAL 8
|
||||||
#define NFC_PRIORITY_ALERT 7
|
#define NFC_PRIORITY_ALERT 7
|
||||||
#define NFC_PRIORITY_CRIT 6
|
#define NFC_PRIORITY_CRIT 6
|
||||||
#define NFC_PRIORITY_ERROR 5
|
#define NFC_PRIORITY_ERROR 5
|
||||||
#define NFC_PRIORITY_WARN 4
|
#define NFC_PRIORITY_WARN 4
|
||||||
#define NFC_PRIORITY_NOTICE 3
|
#define NFC_PRIORITY_NOTICE 3
|
||||||
#define NFC_PRIORITY_INFO 2
|
#define NFC_PRIORITY_INFO 2
|
||||||
#define NFC_PRIORITY_DEBUG 1
|
#define NFC_PRIORITY_DEBUG 1
|
||||||
#define NFC_PRIORITY_TRACE 0
|
#define NFC_PRIORITY_TRACE 0
|
||||||
#endif /* HAS_LOG4C, DEBUG */
|
#endif /* HAS_LOG4C, DEBUG */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -17,10 +17,10 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @file mirror-subr.c
|
* @file mirror-subr.c
|
||||||
* @brief Mirror bytes
|
* @brief Mirror bytes
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifdef HAVE_CONFIG_H
|
#ifdef HAVE_CONFIG_H
|
||||||
# include "config.h"
|
# include "config.h"
|
||||||
|
|
|
@ -17,10 +17,10 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @file nfc-device.c
|
* @file nfc-device.c
|
||||||
* @brief Provide internal function to manipulate nfc_device type
|
* @brief Provide internal function to manipulate nfc_device type
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* vim:set et sw=2 ts=2: */
|
/* vim:set et sw=2 ts=2: */
|
||||||
|
|
||||||
|
|
|
@ -17,10 +17,10 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @file nfc-emulation.c
|
* @file nfc-emulation.c
|
||||||
* @brief Provide a small API to ease emulation in libnfc
|
* @brief Provide a small API to ease emulation in libnfc
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <nfc/nfc.h>
|
#include <nfc/nfc.h>
|
||||||
#include <nfc/nfc-emulation.h>
|
#include <nfc/nfc-emulation.h>
|
||||||
|
|
|
@ -17,10 +17,10 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @file nfc-internal.c
|
* @file nfc-internal.c
|
||||||
* @brief Provide some useful internal functions
|
* @brief Provide some useful internal functions
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <nfc/nfc.h>
|
#include <nfc/nfc.h>
|
||||||
#include "nfc-internal.h"
|
#include "nfc-internal.h"
|
||||||
|
@ -64,6 +64,6 @@ prepare_initiator_data (const nfc_modulation nm, uint8_t **ppbtInitiatorData, si
|
||||||
case NMT_DEP:
|
case NMT_DEP:
|
||||||
*ppbtInitiatorData = NULL;
|
*ppbtInitiatorData = NULL;
|
||||||
*pszInitiatorData = 0;
|
*pszInitiatorData = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -73,16 +73,16 @@
|
||||||
* Initialise a buffer named buffer_name of size bytes.
|
* Initialise a buffer named buffer_name of size bytes.
|
||||||
*/
|
*/
|
||||||
#define BUFFER_INIT(buffer_name, size) \
|
#define BUFFER_INIT(buffer_name, size) \
|
||||||
uint8_t buffer_name[size]; \
|
uint8_t buffer_name[size]; \
|
||||||
size_t __##buffer_name##_n = 0
|
size_t __##buffer_name##_n = 0
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Create a wrapper for an existing buffer.
|
* Create a wrapper for an existing buffer.
|
||||||
* BEWARE! It eats children!
|
* BEWARE! It eats children!
|
||||||
*/
|
*/
|
||||||
#define BUFFER_ALIAS(buffer_name, origin) \
|
#define BUFFER_ALIAS(buffer_name, origin) \
|
||||||
uint8_t *buffer_name = (void *)origin; \
|
uint8_t *buffer_name = (void *)origin; \
|
||||||
size_t __##buffer_name##_n = 0;
|
size_t __##buffer_name##_n = 0;
|
||||||
|
|
||||||
#define BUFFER_SIZE(buffer_name) (__##buffer_name##_n)
|
#define BUFFER_SIZE(buffer_name) (__##buffer_name##_n)
|
||||||
|
|
||||||
|
@ -91,20 +91,20 @@
|
||||||
* Append one byte of data to the buffer buffer_name.
|
* Append one byte of data to the buffer buffer_name.
|
||||||
*/
|
*/
|
||||||
#define BUFFER_APPEND(buffer_name, data) \
|
#define BUFFER_APPEND(buffer_name, data) \
|
||||||
do { \
|
do { \
|
||||||
buffer_name[__##buffer_name##_n++] = data; \
|
buffer_name[__##buffer_name##_n++] = data; \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Append size bytes of data to the buffer buffer_name.
|
* Append size bytes of data to the buffer buffer_name.
|
||||||
*/
|
*/
|
||||||
#define BUFFER_APPEND_BYTES(buffer_name, data, size) \
|
#define BUFFER_APPEND_BYTES(buffer_name, data, size) \
|
||||||
do { \
|
do { \
|
||||||
size_t __n = 0; \
|
size_t __n = 0; \
|
||||||
while (__n < size) { \
|
while (__n < size) { \
|
||||||
buffer_name[__##buffer_name##_n++] = ((uint8_t *)data)[__n++]; \
|
buffer_name[__##buffer_name##_n++] = ((uint8_t *)data)[__n++]; \
|
||||||
} \
|
} \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Append data_size bytes of data at the end of the buffer. Since data is
|
* Append data_size bytes of data at the end of the buffer. Since data is
|
||||||
|
@ -117,19 +117,19 @@
|
||||||
|
|
||||||
#if defined(_BYTE_ORDER) && (_BYTE_ORDER != _LITTLE_ENDIAN)
|
#if defined(_BYTE_ORDER) && (_BYTE_ORDER != _LITTLE_ENDIAN)
|
||||||
#define BUFFER_APPEND_LE(buffer, data, data_size, field_size) \
|
#define BUFFER_APPEND_LE(buffer, data, data_size, field_size) \
|
||||||
do { \
|
do { \
|
||||||
size_t __data_size = data_size; \
|
size_t __data_size = data_size; \
|
||||||
size_t __field_size = field_size; \
|
size_t __field_size = field_size; \
|
||||||
while (__field_size--, __data_size--) { \
|
while (__field_size--, __data_size--) { \
|
||||||
buffer[__##buffer##_n++] = ((uint8_t *)&data)[__field_size]; \
|
buffer[__##buffer##_n++] = ((uint8_t *)&data)[__field_size]; \
|
||||||
} \
|
} \
|
||||||
} while (0)
|
} while (0)
|
||||||
#else
|
#else
|
||||||
#define BUFFER_APPEND_LE(buffer, data, data_size, field_size) \
|
#define BUFFER_APPEND_LE(buffer, data, data_size, field_size) \
|
||||||
do { \
|
do { \
|
||||||
memcpy (buffer + __##buffer##_n, &data, data_size); \
|
memcpy (buffer + __##buffer##_n, &data, data_size); \
|
||||||
__##buffer##_n += data_size; \
|
__##buffer##_n += data_size; \
|
||||||
} while (0)
|
} while (0)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
@ -179,22 +179,22 @@ struct nfc_device {
|
||||||
void *driver_data;
|
void *driver_data;
|
||||||
void *chip_data;
|
void *chip_data;
|
||||||
|
|
||||||
/** Device name string, including device wrapper firmware */
|
/** Device name string, including device wrapper firmware */
|
||||||
char name[DEVICE_NAME_LENGTH];
|
char name[DEVICE_NAME_LENGTH];
|
||||||
/** Device connection string */
|
/** Device connection string */
|
||||||
nfc_connstring connstring;
|
nfc_connstring connstring;
|
||||||
/** Is the CRC automaticly added, checked and removed from the frames */
|
/** Is the CRC automaticly added, checked and removed from the frames */
|
||||||
bool bCrc;
|
bool bCrc;
|
||||||
/** Does the chip handle parity bits, all parities are handled as data */
|
/** Does the chip handle parity bits, all parities are handled as data */
|
||||||
bool bPar;
|
bool bPar;
|
||||||
/** Should the chip handle frames encapsulation and chaining */
|
/** Should the chip handle frames encapsulation and chaining */
|
||||||
bool bEasyFraming;
|
bool bEasyFraming;
|
||||||
/** Should the chip switch automatically activate ISO14443-4 when
|
/** Should the chip switch automatically activate ISO14443-4 when
|
||||||
selecting tags supporting it? */
|
selecting tags supporting it? */
|
||||||
bool bAutoIso14443_4;
|
bool bAutoIso14443_4;
|
||||||
/** Supported modulation encoded in a byte */
|
/** Supported modulation encoded in a byte */
|
||||||
uint8_t btSupportByte;
|
uint8_t btSupportByte;
|
||||||
/** Last reported error */
|
/** Last reported error */
|
||||||
int last_error;
|
int last_error;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
64
libnfc/nfc.c
64
libnfc/nfc.c
|
@ -263,7 +263,7 @@ nfc_list_devices (nfc_context *context, nfc_connstring connstrings[] , size_t sz
|
||||||
szDeviceFound += szN;
|
szDeviceFound += szN;
|
||||||
log_put (LOG_CATEGORY, NFC_PRIORITY_TRACE, "%ld device(s) found using %s driver", (unsigned long) szN, ndr->name);
|
log_put (LOG_CATEGORY, NFC_PRIORITY_TRACE, "%ld device(s) found using %s driver", (unsigned long) szN, ndr->name);
|
||||||
if (szDeviceFound == szDevices)
|
if (szDeviceFound == szDevices)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
pndr++;
|
pndr++;
|
||||||
}
|
}
|
||||||
|
@ -400,20 +400,20 @@ nfc_initiator_select_passive_target (nfc_device *pnd,
|
||||||
size_t szInit;
|
size_t szInit;
|
||||||
|
|
||||||
switch (nm.nmt) {
|
switch (nm.nmt) {
|
||||||
case NMT_ISO14443A:
|
case NMT_ISO14443A:
|
||||||
iso14443_cascade_uid (pbtInitData, szInitData, abtInit, &szInit);
|
iso14443_cascade_uid (pbtInitData, szInitData, abtInit, &szInit);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case NMT_JEWEL:
|
case NMT_JEWEL:
|
||||||
case NMT_ISO14443B:
|
case NMT_ISO14443B:
|
||||||
case NMT_ISO14443BI:
|
case NMT_ISO14443BI:
|
||||||
case NMT_ISO14443B2SR:
|
case NMT_ISO14443B2SR:
|
||||||
case NMT_ISO14443B2CT:
|
case NMT_ISO14443B2CT:
|
||||||
case NMT_FELICA:
|
case NMT_FELICA:
|
||||||
case NMT_DEP:
|
case NMT_DEP:
|
||||||
memcpy (abtInit, pbtInitData, szInitData);
|
memcpy (abtInit, pbtInitData, szInitData);
|
||||||
szInit = szInitData;
|
szInit = szInitData;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
HAL (initiator_select_passive_target, pnd, nm, abtInit, szInit, pnt);
|
HAL (initiator_select_passive_target, pnd, nm, abtInit, szInit, pnt);
|
||||||
|
@ -549,10 +549,10 @@ nfc_initiator_select_dep_target (nfc_device *pnd,
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
nfc_initiator_poll_dep_target (struct nfc_device *pnd,
|
nfc_initiator_poll_dep_target (struct nfc_device *pnd,
|
||||||
const nfc_dep_mode ndm, const nfc_baud_rate nbr,
|
const nfc_dep_mode ndm, const nfc_baud_rate nbr,
|
||||||
const nfc_dep_info *pndiInitiator,
|
const nfc_dep_info *pndiInitiator,
|
||||||
nfc_target *pnt,
|
nfc_target *pnt,
|
||||||
const int timeout)
|
const int timeout)
|
||||||
{
|
{
|
||||||
const int period = 300;
|
const int period = 300;
|
||||||
int remaining_time = timeout;
|
int remaining_time = timeout;
|
||||||
|
@ -727,7 +727,7 @@ nfc_initiator_target_is_present (nfc_device *pnd, const nfc_target nt)
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
nfc_initiator_transceive_bits_timed (nfc_device *pnd, const uint8_t *pbtTx, const size_t szTxBits, const uint8_t *pbtTxPar,
|
nfc_initiator_transceive_bits_timed (nfc_device *pnd, const uint8_t *pbtTx, const size_t szTxBits, const uint8_t *pbtTxPar,
|
||||||
uint8_t *pbtRx, uint8_t *pbtRxPar, uint32_t *cycles)
|
uint8_t *pbtRx, uint8_t *pbtRxPar, uint32_t *cycles)
|
||||||
{
|
{
|
||||||
HAL (initiator_transceive_bits_timed, pnd, pbtTx, szTxBits, pbtTxPar, pbtRx, pbtRxPar, cycles);
|
HAL (initiator_transceive_bits_timed, pnd, pbtTx, szTxBits, pbtTxPar, pbtRx, pbtRxPar, cycles);
|
||||||
}
|
}
|
||||||
|
@ -1080,19 +1080,19 @@ str_nfc_baud_rate (const nfc_baud_rate nbr)
|
||||||
switch(nbr) {
|
switch(nbr) {
|
||||||
case NBR_UNDEFINED:
|
case NBR_UNDEFINED:
|
||||||
return "undefined baud rate";
|
return "undefined baud rate";
|
||||||
break;
|
break;
|
||||||
case NBR_106:
|
case NBR_106:
|
||||||
return "106 kbps";
|
return "106 kbps";
|
||||||
break;
|
break;
|
||||||
case NBR_212:
|
case NBR_212:
|
||||||
return "212 kbps";
|
return "212 kbps";
|
||||||
break;
|
break;
|
||||||
case NBR_424:
|
case NBR_424:
|
||||||
return "424 kbps";
|
return "424 kbps";
|
||||||
break;
|
break;
|
||||||
case NBR_847:
|
case NBR_847:
|
||||||
return "847 kbps";
|
return "847 kbps";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// Should never go there..
|
// Should never go there..
|
||||||
return "";
|
return "";
|
||||||
|
@ -1109,28 +1109,28 @@ str_nfc_modulation_type (const nfc_modulation_type nmt)
|
||||||
switch(nmt) {
|
switch(nmt) {
|
||||||
case NMT_ISO14443A:
|
case NMT_ISO14443A:
|
||||||
return "ISO/IEC 14443A";
|
return "ISO/IEC 14443A";
|
||||||
break;
|
break;
|
||||||
case NMT_ISO14443B:
|
case NMT_ISO14443B:
|
||||||
return "ISO/IEC 14443-4B";
|
return "ISO/IEC 14443-4B";
|
||||||
break;
|
break;
|
||||||
case NMT_ISO14443BI:
|
case NMT_ISO14443BI:
|
||||||
return "ISO/IEC 14443-4B'";
|
return "ISO/IEC 14443-4B'";
|
||||||
break;
|
break;
|
||||||
case NMT_ISO14443B2CT:
|
case NMT_ISO14443B2CT:
|
||||||
return "ISO/IEC 14443-2B ASK CTx";
|
return "ISO/IEC 14443-2B ASK CTx";
|
||||||
break;
|
break;
|
||||||
case NMT_ISO14443B2SR:
|
case NMT_ISO14443B2SR:
|
||||||
return "ISO/IEC 14443-2B ST SRx";
|
return "ISO/IEC 14443-2B ST SRx";
|
||||||
break;
|
break;
|
||||||
case NMT_FELICA:
|
case NMT_FELICA:
|
||||||
return "FeliCa";
|
return "FeliCa";
|
||||||
break;
|
break;
|
||||||
case NMT_JEWEL:
|
case NMT_JEWEL:
|
||||||
return "Innovision Jewel";
|
return "Innovision Jewel";
|
||||||
break;
|
break;
|
||||||
case NMT_DEP:
|
case NMT_DEP:
|
||||||
return "D.E.P.";
|
return "D.E.P.";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// Should never go there..
|
// Should never go there..
|
||||||
return "";
|
return "";
|
||||||
|
|
|
@ -13,43 +13,43 @@
|
||||||
void
|
void
|
||||||
test_access_storm (void)
|
test_access_storm (void)
|
||||||
{
|
{
|
||||||
int n = NTESTS;
|
int n = NTESTS;
|
||||||
nfc_connstring connstrings[MAX_DEVICE_COUNT];
|
nfc_connstring connstrings[MAX_DEVICE_COUNT];
|
||||||
int res = 0;
|
int res = 0;
|
||||||
|
|
||||||
nfc_init (NULL);
|
nfc_init (NULL);
|
||||||
|
|
||||||
size_t ref_device_count = nfc_list_devices (NULL, connstrings, MAX_DEVICE_COUNT);
|
size_t ref_device_count = nfc_list_devices (NULL, connstrings, MAX_DEVICE_COUNT);
|
||||||
if (!ref_device_count)
|
if (!ref_device_count)
|
||||||
cut_omit ("No NFC device found");
|
cut_omit ("No NFC device found");
|
||||||
|
|
||||||
while (n) {
|
while (n) {
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
size_t device_count = nfc_list_devices (NULL, connstrings, MAX_DEVICE_COUNT);
|
size_t device_count = nfc_list_devices (NULL, connstrings, MAX_DEVICE_COUNT);
|
||||||
cut_assert_equal_int (ref_device_count, device_count, cut_message ("device count"));
|
cut_assert_equal_int (ref_device_count, device_count, cut_message ("device count"));
|
||||||
|
|
||||||
for (i = 0; i < device_count; i++) {
|
for (i = 0; i < device_count; i++) {
|
||||||
nfc_device *device;
|
nfc_device *device;
|
||||||
nfc_target ant[MAX_TARGET_COUNT];
|
nfc_target ant[MAX_TARGET_COUNT];
|
||||||
|
|
||||||
device = nfc_open (NULL, connstrings[i]);
|
device = nfc_open (NULL, connstrings[i]);
|
||||||
cut_assert_not_null (device, cut_message ("nfc_open"));
|
cut_assert_not_null (device, cut_message ("nfc_open"));
|
||||||
|
|
||||||
res = nfc_initiator_init(device);
|
res = nfc_initiator_init(device);
|
||||||
cut_assert_equal_int (0, res, cut_message ("nfc_initiator_init"));
|
cut_assert_equal_int (0, res, cut_message ("nfc_initiator_init"));
|
||||||
|
|
||||||
const nfc_modulation nm = {
|
const nfc_modulation nm = {
|
||||||
.nmt = NMT_ISO14443A,
|
.nmt = NMT_ISO14443A,
|
||||||
.nbr = NBR_106,
|
.nbr = NBR_106,
|
||||||
};
|
};
|
||||||
res = nfc_initiator_list_passive_targets(device, nm, ant, MAX_TARGET_COUNT);
|
res = nfc_initiator_list_passive_targets(device, nm, ant, MAX_TARGET_COUNT);
|
||||||
cut_assert_operator_int (res, >=, 0, cut_message ("nfc_initiator_list_passive_targets"));
|
cut_assert_operator_int (res, >=, 0, cut_message ("nfc_initiator_list_passive_targets"));
|
||||||
|
|
||||||
nfc_close (device);
|
nfc_close (device);
|
||||||
}
|
|
||||||
|
|
||||||
n--;
|
|
||||||
}
|
}
|
||||||
nfc_exit (NULL);
|
|
||||||
|
n--;
|
||||||
|
}
|
||||||
|
nfc_exit (NULL);
|
||||||
}
|
}
|
||||||
|
|
|
@ -227,7 +227,7 @@ initiator_thread (void *arg)
|
||||||
cut_assert_operator_int (res, >=, 0, cut_message ("Can't deselect target: %s", nfc_strerror (device)));
|
cut_assert_operator_int (res, >=, 0, cut_message ("Can't deselect target: %s", nfc_strerror (device)));
|
||||||
if (res < 0) { thread_res = -1; return (void*) thread_res; }
|
if (res < 0) { thread_res = -1; return (void*) thread_res; }
|
||||||
|
|
||||||
// Passive mode / 424Kbps
|
// Passive mode / 424Kbps
|
||||||
printf ("=========== INITIATOR %s (Passive mode / 424Kbps) =========\n", nfc_device_get_name (device));
|
printf ("=========== INITIATOR %s (Passive mode / 424Kbps) =========\n", nfc_device_get_name (device));
|
||||||
res = nfc_initiator_select_dep_target (device, NDM_PASSIVE, NBR_424, NULL, &nt, 1000);
|
res = nfc_initiator_select_dep_target (device, NDM_PASSIVE, NBR_424, NULL, &nt, 1000);
|
||||||
cut_assert_operator_int (res, >, 0, cut_message ("Can't select any DEP target: %s", nfc_strerror (device)));
|
cut_assert_operator_int (res, >, 0, cut_message ("Can't select any DEP target: %s", nfc_strerror (device)));
|
||||||
|
|
|
@ -185,7 +185,7 @@ test_dep_states (void)
|
||||||
.cut_test_context = test_context,
|
.cut_test_context = test_context,
|
||||||
};
|
};
|
||||||
|
|
||||||
struct thread_data initiator_data = {
|
struct thread_data initiator_data = {
|
||||||
.device = second_device,
|
.device = second_device,
|
||||||
.cut_test_context = test_context,
|
.cut_test_context = test_context,
|
||||||
};
|
};
|
||||||
|
|
|
@ -9,40 +9,40 @@
|
||||||
void
|
void
|
||||||
test_register_endianness (void)
|
test_register_endianness (void)
|
||||||
{
|
{
|
||||||
nfc_connstring connstrings[MAX_DEVICE_COUNT];
|
nfc_connstring connstrings[MAX_DEVICE_COUNT];
|
||||||
int res = 0;
|
int res = 0;
|
||||||
|
|
||||||
nfc_init (NULL);
|
nfc_init (NULL);
|
||||||
|
|
||||||
size_t device_count = nfc_list_devices (NULL, connstrings, MAX_DEVICE_COUNT);
|
size_t device_count = nfc_list_devices (NULL, connstrings, MAX_DEVICE_COUNT);
|
||||||
if (!device_count)
|
if (!device_count)
|
||||||
cut_omit ("No NFC device found");
|
cut_omit ("No NFC device found");
|
||||||
|
|
||||||
nfc_device *device;
|
nfc_device *device;
|
||||||
|
|
||||||
device = nfc_open (NULL, connstrings[0]);
|
device = nfc_open (NULL, connstrings[0]);
|
||||||
cut_assert_not_null (device, cut_message ("nfc_open"));
|
cut_assert_not_null (device, cut_message ("nfc_open"));
|
||||||
|
|
||||||
uint8_t value;
|
uint8_t value;
|
||||||
|
|
||||||
/* Set a 0xAA test value in writable register memory to test register access */
|
/* Set a 0xAA test value in writable register memory to test register access */
|
||||||
res = pn53x_write_register (device, PN53X_REG_CIU_TxMode, 0xFF, 0xAA);
|
res = pn53x_write_register (device, PN53X_REG_CIU_TxMode, 0xFF, 0xAA);
|
||||||
cut_assert_equal_int (0, res, cut_message ("write register value to 0xAA"));
|
cut_assert_equal_int (0, res, cut_message ("write register value to 0xAA"));
|
||||||
|
|
||||||
/* Get test value from register memory */
|
/* Get test value from register memory */
|
||||||
res = pn53x_read_register (device, PN53X_REG_CIU_TxMode, &value);
|
res = pn53x_read_register (device, PN53X_REG_CIU_TxMode, &value);
|
||||||
cut_assert_equal_int (0, res, cut_message ("read register value"));
|
cut_assert_equal_int (0, res, cut_message ("read register value"));
|
||||||
cut_assert_equal_uint (0xAA, value, cut_message ("check register value"));
|
cut_assert_equal_uint (0xAA, value, cut_message ("check register value"));
|
||||||
|
|
||||||
/* Set a 0x55 test value in writable register memory to test register access */
|
/* Set a 0x55 test value in writable register memory to test register access */
|
||||||
res = pn53x_write_register (device, PN53X_REG_CIU_TxMode, 0xFF, 0x55);
|
res = pn53x_write_register (device, PN53X_REG_CIU_TxMode, 0xFF, 0x55);
|
||||||
cut_assert_equal_int (0, res, cut_message ("write register value to 0x55"));
|
cut_assert_equal_int (0, res, cut_message ("write register value to 0x55"));
|
||||||
|
|
||||||
/* Get test value from register memory */
|
/* Get test value from register memory */
|
||||||
res = pn53x_read_register (device, PN53X_REG_CIU_TxMode, &value);
|
res = pn53x_read_register (device, PN53X_REG_CIU_TxMode, &value);
|
||||||
cut_assert_equal_int (0, res, cut_message ("read register value"));
|
cut_assert_equal_int (0, res, cut_message ("read register value"));
|
||||||
cut_assert_equal_uint (0x55, value, cut_message ("check register value"));
|
cut_assert_equal_uint (0x55, value, cut_message ("check register value"));
|
||||||
|
|
||||||
nfc_close (device);
|
nfc_close (device);
|
||||||
nfc_exit (NULL);
|
nfc_exit (NULL);
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,30 +10,30 @@
|
||||||
void
|
void
|
||||||
test_register_endianness (void)
|
test_register_endianness (void)
|
||||||
{
|
{
|
||||||
nfc_connstring connstrings[MAX_DEVICE_COUNT];
|
nfc_connstring connstrings[MAX_DEVICE_COUNT];
|
||||||
int res = 0;
|
int res = 0;
|
||||||
|
|
||||||
nfc_init (NULL);
|
nfc_init (NULL);
|
||||||
|
|
||||||
size_t device_count = nfc_list_devices (NULL, connstrings, MAX_DEVICE_COUNT);
|
size_t device_count = nfc_list_devices (NULL, connstrings, MAX_DEVICE_COUNT);
|
||||||
if (!device_count)
|
if (!device_count)
|
||||||
cut_omit ("No NFC device found");
|
cut_omit ("No NFC device found");
|
||||||
|
|
||||||
nfc_device *device;
|
nfc_device *device;
|
||||||
|
|
||||||
device = nfc_open (NULL, connstrings[0]);
|
device = nfc_open (NULL, connstrings[0]);
|
||||||
cut_assert_not_null (device, cut_message ("nfc_open"));
|
cut_assert_not_null (device, cut_message ("nfc_open"));
|
||||||
|
|
||||||
uint8_t value;
|
uint8_t value;
|
||||||
|
|
||||||
/* Read valid XRAM memory */
|
/* Read valid XRAM memory */
|
||||||
res = pn53x_read_register (device, 0xF0FF, &value);
|
res = pn53x_read_register (device, 0xF0FF, &value);
|
||||||
cut_assert_equal_int (0, res, cut_message ("read register 0xF0FF"));
|
cut_assert_equal_int (0, res, cut_message ("read register 0xF0FF"));
|
||||||
|
|
||||||
/* Read invalid SFR register */
|
/* Read invalid SFR register */
|
||||||
res = pn53x_read_register (device, 0xFFF0, &value);
|
res = pn53x_read_register (device, 0xFFF0, &value);
|
||||||
cut_assert_equal_int (0, res, cut_message ("read register 0xFFF0"));
|
cut_assert_equal_int (0, res, cut_message ("read register 0xFFF0"));
|
||||||
|
|
||||||
nfc_close (device);
|
nfc_close (device);
|
||||||
nfc_exit (NULL);
|
nfc_exit (NULL);
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,34 +62,34 @@ nfc_initiator_mifare_cmd (nfc_device *pnd, const mifare_cmd mc, const uint8_t ui
|
||||||
abtCmd[1] = ui8Block; // The block address (1K=0x00..0x39, 4K=0x00..0xff)
|
abtCmd[1] = ui8Block; // The block address (1K=0x00..0x39, 4K=0x00..0xff)
|
||||||
|
|
||||||
switch (mc) {
|
switch (mc) {
|
||||||
// Read and store command have no parameter
|
// Read and store command have no parameter
|
||||||
case MC_READ:
|
case MC_READ:
|
||||||
case MC_STORE:
|
case MC_STORE:
|
||||||
szParamLen = 0;
|
szParamLen = 0;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// Authenticate command
|
// Authenticate command
|
||||||
case MC_AUTH_A:
|
case MC_AUTH_A:
|
||||||
case MC_AUTH_B:
|
case MC_AUTH_B:
|
||||||
szParamLen = sizeof (struct mifare_param_auth);
|
szParamLen = sizeof (struct mifare_param_auth);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// Data command
|
// Data command
|
||||||
case MC_WRITE:
|
case MC_WRITE:
|
||||||
szParamLen = sizeof (struct mifare_param_data);
|
szParamLen = sizeof (struct mifare_param_data);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// Value command
|
// Value command
|
||||||
case MC_DECREMENT:
|
case MC_DECREMENT:
|
||||||
case MC_INCREMENT:
|
case MC_INCREMENT:
|
||||||
case MC_TRANSFER:
|
case MC_TRANSFER:
|
||||||
szParamLen = sizeof (struct mifare_param_value);
|
szParamLen = sizeof (struct mifare_param_value);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// Please fix your code, you never should reach this statement
|
// Please fix your code, you never should reach this statement
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// When available, copy the parameter bytes
|
// When available, copy the parameter bytes
|
||||||
|
|
|
@ -98,7 +98,7 @@ uint8_t nfcforum_capability_container[] = {
|
||||||
0x00, 0xFF, /* MLc Maximum C-ADPU data size */
|
0x00, 0xFF, /* MLc Maximum C-ADPU data size */
|
||||||
0x04, /* T field of the NDEF File-Control TLV */
|
0x04, /* T field of the NDEF File-Control TLV */
|
||||||
0x06, /* L field of the NDEF File-Control TLV */
|
0x06, /* L field of the NDEF File-Control TLV */
|
||||||
/* V field of the NDEF File-Control TLV */
|
/* V field of the NDEF File-Control TLV */
|
||||||
0xE1, 0x04, /* File identifier */
|
0xE1, 0x04, /* File identifier */
|
||||||
0xFF, 0xFE, /* Maximum NDEF Size */
|
0xFF, 0xFE, /* Maximum NDEF Size */
|
||||||
0x00, /* NDEF file read access condition */
|
0x00, /* NDEF file read access condition */
|
||||||
|
@ -143,79 +143,79 @@ nfcforum_tag4_io (struct nfc_emulator *emulator, const uint8_t *data_in, const s
|
||||||
#define ISO7816_UPDATE_BINARY 0xD6
|
#define ISO7816_UPDATE_BINARY 0xD6
|
||||||
|
|
||||||
switch(data_in[INS]) {
|
switch(data_in[INS]) {
|
||||||
case ISO7816_SELECT:
|
case ISO7816_SELECT:
|
||||||
|
|
||||||
switch (data_in[P1]) {
|
switch (data_in[P1]) {
|
||||||
case 0x00: /* Select by ID */
|
case 0x00: /* Select by ID */
|
||||||
if ((data_in[P2] | 0x0C) != 0x0C)
|
if ((data_in[P2] | 0x0C) != 0x0C)
|
||||||
return -ENOTSUP;
|
return -ENOTSUP;
|
||||||
|
|
||||||
const uint8_t ndef_capability_container[] = { 0xE1, 0x03 };
|
const uint8_t ndef_capability_container[] = { 0xE1, 0x03 };
|
||||||
const uint8_t ndef_file[] = { 0xE1, 0x04 };
|
const uint8_t ndef_file[] = { 0xE1, 0x04 };
|
||||||
if ((data_in[LC] == sizeof (ndef_capability_container)) && (0 == memcmp (ndef_capability_container, data_in + DATA, data_in[LC]))) {
|
if ((data_in[LC] == sizeof (ndef_capability_container)) && (0 == memcmp (ndef_capability_container, data_in + DATA, data_in[LC]))) {
|
||||||
memcpy (data_out, "\x90\x00", res = 2);
|
memcpy (data_out, "\x90\x00", res = 2);
|
||||||
state_machine_data->current_file = CC_FILE;
|
state_machine_data->current_file = CC_FILE;
|
||||||
} else if ((data_in[LC] == sizeof (ndef_file)) && (0 == memcmp (ndef_file, data_in + DATA, data_in[LC]))) {
|
} else if ((data_in[LC] == sizeof (ndef_file)) && (0 == memcmp (ndef_file, data_in + DATA, data_in[LC]))) {
|
||||||
memcpy (data_out, "\x90\x00", res = 2);
|
memcpy (data_out, "\x90\x00", res = 2);
|
||||||
state_machine_data->current_file = NDEF_FILE;
|
state_machine_data->current_file = NDEF_FILE;
|
||||||
} else {
|
} else {
|
||||||
memcpy (data_out, "\x6a\x00", res = 2);
|
memcpy (data_out, "\x6a\x00", res = 2);
|
||||||
state_machine_data->current_file = NONE;
|
state_machine_data->current_file = NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
case 0x04: /* Select by name */
|
||||||
|
if (data_in[P2] != 0x00)
|
||||||
|
return -ENOTSUP;
|
||||||
|
|
||||||
|
const uint8_t ndef_tag_application_name_v1[] = { 0xD2, 0x76, 0x00, 0x00, 0x85, 0x01, 0x00 };
|
||||||
|
const uint8_t ndef_tag_application_name_v2[] = { 0xD2, 0x76, 0x00, 0x00, 0x85, 0x01, 0x01 };
|
||||||
|
if ((type4v == 1) && (data_in[LC] == sizeof (ndef_tag_application_name_v1)) && (0 == memcmp (ndef_tag_application_name_v1, data_in + DATA, data_in[LC])))
|
||||||
|
memcpy (data_out, "\x90\x00", res = 2);
|
||||||
|
else if ((type4v == 2) && (data_in[LC] == sizeof (ndef_tag_application_name_v2)) && (0 == memcmp (ndef_tag_application_name_v2, data_in + DATA, data_in[LC])))
|
||||||
|
memcpy (data_out, "\x90\x00", res = 2);
|
||||||
|
else
|
||||||
|
memcpy (data_out, "\x6a\x82", res = 2);
|
||||||
|
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return -ENOTSUP;
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case 0x04: /* Select by name */
|
case ISO7816_READ_BINARY:
|
||||||
if (data_in[P2] != 0x00)
|
if ((size_t)(data_in[LC] + 2) > data_out_len) {
|
||||||
return -ENOTSUP;
|
return -ENOSPC;
|
||||||
|
}
|
||||||
const uint8_t ndef_tag_application_name_v1[] = { 0xD2, 0x76, 0x00, 0x00, 0x85, 0x01, 0x00 };
|
switch (state_machine_data->current_file) {
|
||||||
const uint8_t ndef_tag_application_name_v2[] = { 0xD2, 0x76, 0x00, 0x00, 0x85, 0x01, 0x01 };
|
case NONE:
|
||||||
if ((type4v == 1) && (data_in[LC] == sizeof (ndef_tag_application_name_v1)) && (0 == memcmp (ndef_tag_application_name_v1, data_in + DATA, data_in[LC])))
|
memcpy (data_out, "\x6a\x82", res = 2);
|
||||||
memcpy (data_out, "\x90\x00", res = 2);
|
break;
|
||||||
else if ((type4v == 2) && (data_in[LC] == sizeof (ndef_tag_application_name_v2)) && (0 == memcmp (ndef_tag_application_name_v2, data_in + DATA, data_in[LC])))
|
case CC_FILE:
|
||||||
memcpy (data_out, "\x90\x00", res = 2);
|
memcpy (data_out, nfcforum_capability_container + (data_in[P1] << 8) + data_in[P2], data_in[LC]);
|
||||||
else
|
memcpy (data_out + data_in[LC], "\x90\x00", 2);
|
||||||
memcpy (data_out, "\x6a\x82", res = 2);
|
res = data_in[LC] + 2;
|
||||||
|
break;
|
||||||
|
case NDEF_FILE:
|
||||||
|
memcpy (data_out, ndef_data->ndef_file + (data_in[P1] << 8) + data_in[P2], data_in[LC]);
|
||||||
|
memcpy (data_out + data_in[LC], "\x90\x00", 2);
|
||||||
|
res = data_in[LC] + 2;
|
||||||
|
break;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
|
||||||
return -ENOTSUP;
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
case ISO7816_UPDATE_BINARY:
|
||||||
case ISO7816_READ_BINARY:
|
memcpy (ndef_data->ndef_file + (data_in[P1] << 8) + data_in[P2], data_in + DATA, data_in[LC]);
|
||||||
if ((size_t)(data_in[LC] + 2) > data_out_len) {
|
if ((data_in[P1] << 8) + data_in[P2] == 0) {
|
||||||
return -ENOSPC;
|
ndef_data->ndef_file_len = (ndef_data->ndef_file[0] << 8) + ndef_data->ndef_file[1] + 2;
|
||||||
}
|
}
|
||||||
switch (state_machine_data->current_file) {
|
memcpy (data_out, "\x90\x00", res = 2);
|
||||||
case NONE:
|
|
||||||
memcpy (data_out, "\x6a\x82", res = 2);
|
|
||||||
break;
|
break;
|
||||||
case CC_FILE:
|
default: // Unknown
|
||||||
memcpy (data_out, nfcforum_capability_container + (data_in[P1] << 8) + data_in[P2], data_in[LC]);
|
if (!quiet_output) {
|
||||||
memcpy (data_out + data_in[LC], "\x90\x00", 2);
|
printf("Unknown frame, emulated target abort.\n");
|
||||||
res = data_in[LC] + 2;
|
}
|
||||||
break;
|
res = -ENOTSUP;
|
||||||
case NDEF_FILE:
|
|
||||||
memcpy (data_out, ndef_data->ndef_file + (data_in[P1] << 8) + data_in[P2], data_in[LC]);
|
|
||||||
memcpy (data_out + data_in[LC], "\x90\x00", 2);
|
|
||||||
res = data_in[LC] + 2;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case ISO7816_UPDATE_BINARY:
|
|
||||||
memcpy (ndef_data->ndef_file + (data_in[P1] << 8) + data_in[P2], data_in + DATA, data_in[LC]);
|
|
||||||
if ((data_in[P1] << 8) + data_in[P2] == 0) {
|
|
||||||
ndef_data->ndef_file_len = (ndef_data->ndef_file[0] << 8) + ndef_data->ndef_file[1] + 2;
|
|
||||||
}
|
|
||||||
memcpy (data_out, "\x90\x00", res = 2);
|
|
||||||
break;
|
|
||||||
default: // Unknown
|
|
||||||
if (!quiet_output) {
|
|
||||||
printf("Unknown frame, emulated target abort.\n");
|
|
||||||
}
|
|
||||||
res = -ENOTSUP;
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
res = -ENOTSUP;
|
res = -ENOTSUP;
|
||||||
|
|
|
@ -130,10 +130,10 @@ main (int argc, const char *argv[])
|
||||||
ERR ("Unable to open NFC device: %s", connstrings[i]);
|
ERR ("Unable to open NFC device: %s", connstrings[i]);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (nfc_initiator_init (pnd) < 0) {
|
if (nfc_initiator_init (pnd) < 0) {
|
||||||
nfc_perror (pnd, "nfc_initiator_init");
|
nfc_perror (pnd, "nfc_initiator_init");
|
||||||
exit (EXIT_FAILURE);
|
exit (EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
printf ("NFC device: %s opened\n", nfc_device_get_name (pnd));
|
printf ("NFC device: %s opened\n", nfc_device_get_name (pnd));
|
||||||
|
|
||||||
|
|
|
@ -468,131 +468,131 @@ main (int argc, const char *argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (atAction) {
|
switch (atAction) {
|
||||||
case ACTION_USAGE:
|
case ACTION_USAGE:
|
||||||
print_usage (argv[0]);
|
print_usage (argv[0]);
|
||||||
exit (EXIT_FAILURE);
|
|
||||||
break;
|
|
||||||
case ACTION_READ:
|
|
||||||
case ACTION_WRITE:
|
|
||||||
if (bUseKeyFile) {
|
|
||||||
pfKeys = fopen (argv[4], "rb");
|
|
||||||
if (pfKeys == NULL) {
|
|
||||||
printf ("Could not open keys file: %s\n", argv[4]);
|
|
||||||
exit (EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
if (fread (&mtKeys, 1, sizeof (mtKeys), pfKeys) != sizeof (mtKeys)) {
|
|
||||||
printf ("Could not read keys file: %s\n", argv[4]);
|
|
||||||
fclose (pfKeys);
|
|
||||||
exit (EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
fclose (pfKeys);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (atAction == ACTION_READ) {
|
|
||||||
memset (&mtDump, 0x00, sizeof (mtDump));
|
|
||||||
} else {
|
|
||||||
pfDump = fopen (argv[3], "rb");
|
|
||||||
|
|
||||||
if (pfDump == NULL) {
|
|
||||||
printf ("Could not open dump file: %s\n", argv[3]);
|
|
||||||
exit (EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (fread (&mtDump, 1, sizeof (mtDump), pfDump) != sizeof (mtDump)) {
|
|
||||||
printf ("Could not read dump file: %s\n", argv[3]);
|
|
||||||
fclose (pfDump);
|
|
||||||
exit (EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
fclose (pfDump);
|
|
||||||
}
|
|
||||||
// printf("Successfully opened required files\n");
|
|
||||||
|
|
||||||
nfc_init (NULL);
|
|
||||||
|
|
||||||
// Try to open the NFC reader
|
|
||||||
pnd = nfc_open (NULL, NULL);
|
|
||||||
if (pnd == NULL) {
|
|
||||||
printf ("Error opening NFC reader\n");
|
|
||||||
exit (EXIT_FAILURE);
|
exit (EXIT_FAILURE);
|
||||||
}
|
break;
|
||||||
|
case ACTION_READ:
|
||||||
if (nfc_initiator_init (pnd) < 0) {
|
case ACTION_WRITE:
|
||||||
nfc_perror (pnd, "nfc_initiator_init");
|
if (bUseKeyFile) {
|
||||||
exit (EXIT_FAILURE);
|
pfKeys = fopen (argv[4], "rb");
|
||||||
};
|
if (pfKeys == NULL) {
|
||||||
|
printf ("Could not open keys file: %s\n", argv[4]);
|
||||||
// Let the reader only try once to find a tag
|
exit (EXIT_FAILURE);
|
||||||
if (nfc_device_set_property_bool (pnd, NP_INFINITE_SELECT, false) < 0) {
|
}
|
||||||
nfc_perror (pnd, "nfc_device_set_property_bool");
|
if (fread (&mtKeys, 1, sizeof (mtKeys), pfKeys) != sizeof (mtKeys)) {
|
||||||
exit (EXIT_FAILURE);
|
printf ("Could not read keys file: %s\n", argv[4]);
|
||||||
}
|
fclose (pfKeys);
|
||||||
// Disable ISO14443-4 switching in order to read devices that emulate Mifare Classic with ISO14443-4 compliance.
|
exit (EXIT_FAILURE);
|
||||||
nfc_device_set_property_bool (pnd, NP_AUTO_ISO14443_4, false);
|
}
|
||||||
|
fclose (pfKeys);
|
||||||
printf ("NFC reader: %s opened\n", nfc_device_get_name (pnd));
|
}
|
||||||
|
|
||||||
// Try to find a MIFARE Classic tag
|
if (atAction == ACTION_READ) {
|
||||||
if (nfc_initiator_select_passive_target (pnd, nmMifare, NULL, 0, &nt) < 0) {
|
memset (&mtDump, 0x00, sizeof (mtDump));
|
||||||
printf ("Error: no tag was found\n");
|
} else {
|
||||||
nfc_close (pnd);
|
pfDump = fopen (argv[3], "rb");
|
||||||
nfc_exit (NULL);
|
|
||||||
exit (EXIT_FAILURE);
|
if (pfDump == NULL) {
|
||||||
}
|
printf ("Could not open dump file: %s\n", argv[3]);
|
||||||
// Test if we are dealing with a MIFARE compatible tag
|
exit (EXIT_FAILURE);
|
||||||
if ((nt.nti.nai.btSak & 0x08) == 0) {
|
}
|
||||||
printf ("Warning: tag is probably not a MFC!\n");
|
|
||||||
}
|
if (fread (&mtDump, 1, sizeof (mtDump), pfDump) != sizeof (mtDump)) {
|
||||||
|
printf ("Could not read dump file: %s\n", argv[3]);
|
||||||
// Get the info from the current tag
|
fclose (pfDump);
|
||||||
pbtUID = nt.nti.nai.abtUid;
|
|
||||||
|
|
||||||
if (bUseKeyFile) {
|
|
||||||
uint8_t fileUid[4];
|
|
||||||
memcpy (fileUid, mtKeys.amb[0].mbm.abtUID, 4);
|
|
||||||
// Compare if key dump UID is the same as the current tag UID, at least for the first 4 bytes
|
|
||||||
if (memcmp (pbtUID, fileUid, 4) != 0) {
|
|
||||||
printf ("Expected MIFARE Classic card with UID starting as: %02x%02x%02x%02x\n",
|
|
||||||
fileUid[0], fileUid[1], fileUid[2], fileUid[3]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
printf ("Found MIFARE Classic card:\n");
|
|
||||||
print_nfc_iso14443a_info (nt.nti.nai, false);
|
|
||||||
|
|
||||||
// Guessing size
|
|
||||||
if ((nt.nti.nai.abtAtqa[1] & 0x02) == 0x02)
|
|
||||||
// 4K
|
|
||||||
uiBlocks = 0xff;
|
|
||||||
else if ((nt.nti.nai.btSak & 0x01) == 0x01)
|
|
||||||
// 320b
|
|
||||||
uiBlocks = 0x13;
|
|
||||||
else
|
|
||||||
// 1K
|
|
||||||
// TODO: for MFP it is 0x7f (2K) but how to be sure it's a MFP? Try to get RATS?
|
|
||||||
uiBlocks = 0x3f;
|
|
||||||
printf ("Guessing size: seems to be a %i-byte card\n", (uiBlocks + 1) * 16);
|
|
||||||
|
|
||||||
if (atAction == ACTION_READ) {
|
|
||||||
if (read_card (unlock)) {
|
|
||||||
printf ("Writing data to file: %s ...", argv[3]);
|
|
||||||
fflush (stdout);
|
|
||||||
pfDump = fopen (argv[3], "wb");
|
|
||||||
if (pfDump == NULL) {
|
|
||||||
printf ("Could not open dump file: %s\n", argv[3]);
|
|
||||||
exit (EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
if (fwrite (&mtDump, 1, sizeof (mtDump), pfDump) != sizeof (mtDump)) {
|
|
||||||
printf ("\nCould not write to file: %s\n", argv[3]);
|
|
||||||
exit (EXIT_FAILURE);
|
exit (EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
printf ("Done.\n");
|
|
||||||
fclose (pfDump);
|
fclose (pfDump);
|
||||||
}
|
}
|
||||||
} else if (atAction == ACTION_WRITE) {
|
// printf("Successfully opened required files\n");
|
||||||
write_card (unlock);
|
|
||||||
}
|
|
||||||
|
|
||||||
nfc_close (pnd);
|
nfc_init (NULL);
|
||||||
break;
|
|
||||||
|
// Try to open the NFC reader
|
||||||
|
pnd = nfc_open (NULL, NULL);
|
||||||
|
if (pnd == NULL) {
|
||||||
|
printf ("Error opening NFC reader\n");
|
||||||
|
exit (EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (nfc_initiator_init (pnd) < 0) {
|
||||||
|
nfc_perror (pnd, "nfc_initiator_init");
|
||||||
|
exit (EXIT_FAILURE);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Let the reader only try once to find a tag
|
||||||
|
if (nfc_device_set_property_bool (pnd, NP_INFINITE_SELECT, false) < 0) {
|
||||||
|
nfc_perror (pnd, "nfc_device_set_property_bool");
|
||||||
|
exit (EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
// Disable ISO14443-4 switching in order to read devices that emulate Mifare Classic with ISO14443-4 compliance.
|
||||||
|
nfc_device_set_property_bool (pnd, NP_AUTO_ISO14443_4, false);
|
||||||
|
|
||||||
|
printf ("NFC reader: %s opened\n", nfc_device_get_name (pnd));
|
||||||
|
|
||||||
|
// Try to find a MIFARE Classic tag
|
||||||
|
if (nfc_initiator_select_passive_target (pnd, nmMifare, NULL, 0, &nt) < 0) {
|
||||||
|
printf ("Error: no tag was found\n");
|
||||||
|
nfc_close (pnd);
|
||||||
|
nfc_exit (NULL);
|
||||||
|
exit (EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
// Test if we are dealing with a MIFARE compatible tag
|
||||||
|
if ((nt.nti.nai.btSak & 0x08) == 0) {
|
||||||
|
printf ("Warning: tag is probably not a MFC!\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get the info from the current tag
|
||||||
|
pbtUID = nt.nti.nai.abtUid;
|
||||||
|
|
||||||
|
if (bUseKeyFile) {
|
||||||
|
uint8_t fileUid[4];
|
||||||
|
memcpy (fileUid, mtKeys.amb[0].mbm.abtUID, 4);
|
||||||
|
// Compare if key dump UID is the same as the current tag UID, at least for the first 4 bytes
|
||||||
|
if (memcmp (pbtUID, fileUid, 4) != 0) {
|
||||||
|
printf ("Expected MIFARE Classic card with UID starting as: %02x%02x%02x%02x\n",
|
||||||
|
fileUid[0], fileUid[1], fileUid[2], fileUid[3]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
printf ("Found MIFARE Classic card:\n");
|
||||||
|
print_nfc_iso14443a_info (nt.nti.nai, false);
|
||||||
|
|
||||||
|
// Guessing size
|
||||||
|
if ((nt.nti.nai.abtAtqa[1] & 0x02) == 0x02)
|
||||||
|
// 4K
|
||||||
|
uiBlocks = 0xff;
|
||||||
|
else if ((nt.nti.nai.btSak & 0x01) == 0x01)
|
||||||
|
// 320b
|
||||||
|
uiBlocks = 0x13;
|
||||||
|
else
|
||||||
|
// 1K
|
||||||
|
// TODO: for MFP it is 0x7f (2K) but how to be sure it's a MFP? Try to get RATS?
|
||||||
|
uiBlocks = 0x3f;
|
||||||
|
printf ("Guessing size: seems to be a %i-byte card\n", (uiBlocks + 1) * 16);
|
||||||
|
|
||||||
|
if (atAction == ACTION_READ) {
|
||||||
|
if (read_card (unlock)) {
|
||||||
|
printf ("Writing data to file: %s ...", argv[3]);
|
||||||
|
fflush (stdout);
|
||||||
|
pfDump = fopen (argv[3], "wb");
|
||||||
|
if (pfDump == NULL) {
|
||||||
|
printf ("Could not open dump file: %s\n", argv[3]);
|
||||||
|
exit (EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
if (fwrite (&mtDump, 1, sizeof (mtDump), pfDump) != sizeof (mtDump)) {
|
||||||
|
printf ("\nCould not write to file: %s\n", argv[3]);
|
||||||
|
exit (EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
printf ("Done.\n");
|
||||||
|
fclose (pfDump);
|
||||||
|
}
|
||||||
|
} else if (atAction == ACTION_WRITE) {
|
||||||
|
write_card (unlock);
|
||||||
|
}
|
||||||
|
|
||||||
|
nfc_close (pnd);
|
||||||
|
break;
|
||||||
};
|
};
|
||||||
|
|
||||||
nfc_exit (NULL);
|
nfc_exit (NULL);
|
||||||
|
|
|
@ -116,8 +116,8 @@ main (int argc, const char *argv[])
|
||||||
}
|
}
|
||||||
nfc_close (pnd);
|
nfc_close (pnd);
|
||||||
} else {
|
} else {
|
||||||
printf("nfc_open failed for %s\n", connstrings[i]);
|
printf("nfc_open failed for %s\n", connstrings[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
res = EXIT_SUCCESS;
|
res = EXIT_SUCCESS;
|
||||||
|
|
||||||
|
|
|
@ -60,9 +60,9 @@ static nfc_device *pnd;
|
||||||
static void
|
static void
|
||||||
print_usage(char *progname)
|
print_usage(char *progname)
|
||||||
{
|
{
|
||||||
fprintf (stderr, "usage: %s -o FILE\n", progname);
|
fprintf (stderr, "usage: %s -o FILE\n", progname);
|
||||||
fprintf (stderr, "\nOptions:\n");
|
fprintf (stderr, "\nOptions:\n");
|
||||||
fprintf (stderr, " -o Extract NDEF message if available in FILE\n");
|
fprintf (stderr, " -o Extract NDEF message if available in FILE\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void stop_select (int sig)
|
static void stop_select (int sig)
|
||||||
|
@ -89,11 +89,11 @@ static int
|
||||||
nfc_forum_tag_type3_check (nfc_device *dev, const nfc_target nt, const uint16_t block, const uint8_t block_count, uint8_t *data, size_t *data_len)
|
nfc_forum_tag_type3_check (nfc_device *dev, const nfc_target nt, const uint16_t block, const uint8_t block_count, uint8_t *data, size_t *data_len)
|
||||||
{
|
{
|
||||||
uint8_t payload[1024] = {
|
uint8_t payload[1024] = {
|
||||||
1, // Services
|
1, // Services
|
||||||
0x0B, 0x00, // NFC Forum Tag Type 3's Service code
|
0x0B, 0x00, // NFC Forum Tag Type 3's Service code
|
||||||
block_count,
|
block_count,
|
||||||
0x80, block, // block 0
|
0x80, block, // block 0
|
||||||
};
|
};
|
||||||
|
|
||||||
size_t payload_len = 1 + 2 + 1;
|
size_t payload_len = 1 + 2 + 1;
|
||||||
for (uint8_t b = 0; b < block_count; b++) {
|
for (uint8_t b = 0; b < block_count; b++) {
|
||||||
|
@ -157,19 +157,19 @@ main(int argc, char *argv[])
|
||||||
char *ndef_output = NULL;
|
char *ndef_output = NULL;
|
||||||
while ((ch = getopt (argc, argv, "ho:")) != -1) {
|
while ((ch = getopt (argc, argv, "ho:")) != -1) {
|
||||||
switch (ch) {
|
switch (ch) {
|
||||||
case 'h':
|
case 'h':
|
||||||
print_usage(argv[0]);
|
print_usage(argv[0]);
|
||||||
exit (EXIT_SUCCESS);
|
exit (EXIT_SUCCESS);
|
||||||
break;
|
break;
|
||||||
case 'o':
|
case 'o':
|
||||||
ndef_output = optarg;
|
ndef_output = optarg;
|
||||||
break;
|
break;
|
||||||
case '?':
|
case '?':
|
||||||
if (optopt == 'o')
|
if (optopt == 'o')
|
||||||
fprintf (stderr, "Option -%c requires an argument.\n", optopt);
|
fprintf (stderr, "Option -%c requires an argument.\n", optopt);
|
||||||
default:
|
default:
|
||||||
print_usage (argv[0]);
|
print_usage (argv[0]);
|
||||||
exit (EXIT_FAILURE);
|
exit (EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -395,7 +395,7 @@ main (int argc, char *argv[])
|
||||||
szCapduLen = (size_t) res;
|
szCapduLen = (size_t) res;
|
||||||
if (target_only_mode) {
|
if (target_only_mode) {
|
||||||
if (print_hex_fd4(abtCapdu, szCapduLen, "C-APDU") != EXIT_SUCCESS) {
|
if (print_hex_fd4(abtCapdu, szCapduLen, "C-APDU") != EXIT_SUCCESS) {
|
||||||
fprintf (stderr, "Error while printing C-APDU to FD4\n");
|
fprintf (stderr, "Error while printing C-APDU to FD4\n");
|
||||||
nfc_close (pndTarget);
|
nfc_close (pndTarget);
|
||||||
nfc_exit (NULL);
|
nfc_exit (NULL);
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
|
@ -461,7 +461,7 @@ main (int argc, char *argv[])
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (print_hex_fd4(abtRapdu, szRapduLen, "R-APDU") != EXIT_SUCCESS) {
|
if (print_hex_fd4(abtRapdu, szRapduLen, "R-APDU") != EXIT_SUCCESS) {
|
||||||
fprintf (stderr, "Error while printing R-APDU to FD4\n");
|
fprintf (stderr, "Error while printing R-APDU to FD4\n");
|
||||||
nfc_close (pndInitiator);
|
nfc_close (pndInitiator);
|
||||||
nfc_exit (NULL);
|
nfc_exit (NULL);
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
|
|
|
@ -38,65 +38,79 @@
|
||||||
|
|
||||||
struct card_atqa
|
struct card_atqa
|
||||||
{
|
{
|
||||||
uint16_t atqa;
|
uint16_t atqa;
|
||||||
uint16_t mask;
|
uint16_t mask;
|
||||||
char type[128];
|
char type[128];
|
||||||
// list of up to 8 SAK values compatible with this ATQA
|
// list of up to 8 SAK values compatible with this ATQA
|
||||||
int saklist[8];
|
int saklist[8];
|
||||||
};
|
};
|
||||||
|
|
||||||
struct card_sak
|
struct card_sak
|
||||||
{
|
{
|
||||||
uint8_t sak;
|
uint8_t sak;
|
||||||
uint8_t mask;
|
uint8_t mask;
|
||||||
char type[128];
|
char type[128];
|
||||||
};
|
};
|
||||||
|
|
||||||
struct card_atqa const_ca[] = {
|
struct card_atqa const_ca[] = {
|
||||||
{0x0044, 0xffff, "MIFARE Ultralight",
|
{ 0x0044, 0xffff, "MIFARE Ultralight",
|
||||||
{0, -1} },
|
{0, -1}
|
||||||
{0x0044, 0xffff, "MIFARE Ultralight C",
|
},
|
||||||
{0, -1} },
|
{ 0x0044, 0xffff, "MIFARE Ultralight C",
|
||||||
{0x0004, 0xff0f, "MIFARE Mini 0.3K",
|
{0, -1}
|
||||||
{1, -1} },
|
},
|
||||||
{0x0004, 0xff0f, "MIFARE Classic 1K",
|
{ 0x0004, 0xff0f, "MIFARE Mini 0.3K",
|
||||||
{2, -1} },
|
{1, -1}
|
||||||
{0x0002, 0xff0f, "MIFARE Classic 4K",
|
},
|
||||||
{3, -1} },
|
{ 0x0004, 0xff0f, "MIFARE Classic 1K",
|
||||||
{0x0004, 0xffff, "MIFARE Plus (4 Byte UID or 4 Byte RID)",
|
{2, -1}
|
||||||
{4, 5, 6, 7, 8, 9, -1} },
|
},
|
||||||
{0x0002, 0xffff, "MIFARE Plus (4 Byte UID or 4 Byte RID)",
|
{ 0x0002, 0xff0f, "MIFARE Classic 4K",
|
||||||
{4, 5, 6, 7, 8, 9, -1} },
|
{3, -1}
|
||||||
{0x0044, 0xffff, "MIFARE Plus (7 Byte UID)",
|
},
|
||||||
{4, 5, 6, 7, 8, 9, -1} },
|
{ 0x0004, 0xffff, "MIFARE Plus (4 Byte UID or 4 Byte RID)",
|
||||||
{0x0042, 0xffff, "MIFARE Plus (7 Byte UID)",
|
{4, 5, 6, 7, 8, 9, -1}
|
||||||
{4, 5, 6, 7, 8, 9, -1} },
|
},
|
||||||
{0x0344, 0xffff, "MIFARE DESFire",
|
{ 0x0002, 0xffff, "MIFARE Plus (4 Byte UID or 4 Byte RID)",
|
||||||
{10, 11, -1} },
|
{4, 5, 6, 7, 8, 9, -1}
|
||||||
{0x0044, 0xffff, "P3SR008",
|
},
|
||||||
{-1} }, // TODO we need SAK info
|
{ 0x0044, 0xffff, "MIFARE Plus (7 Byte UID)",
|
||||||
{0x0004, 0xf0ff, "SmartMX with MIFARE 1K emulation",
|
{4, 5, 6, 7, 8, 9, -1}
|
||||||
{12, -1} },
|
},
|
||||||
{0x0002, 0xf0ff, "SmartMX with MIFARE 4K emulation",
|
{ 0x0042, 0xffff, "MIFARE Plus (7 Byte UID)",
|
||||||
{12, -1} },
|
{4, 5, 6, 7, 8, 9, -1}
|
||||||
{0x0048, 0xf0ff, "SmartMX with 7 Byte UID",
|
},
|
||||||
{12, -1} }
|
{ 0x0344, 0xffff, "MIFARE DESFire",
|
||||||
|
{10, 11, -1}
|
||||||
|
},
|
||||||
|
{ 0x0044, 0xffff, "P3SR008",
|
||||||
|
{-1}
|
||||||
|
}, // TODO we need SAK info
|
||||||
|
{ 0x0004, 0xf0ff, "SmartMX with MIFARE 1K emulation",
|
||||||
|
{12, -1}
|
||||||
|
},
|
||||||
|
{ 0x0002, 0xf0ff, "SmartMX with MIFARE 4K emulation",
|
||||||
|
{12, -1}
|
||||||
|
},
|
||||||
|
{ 0x0048, 0xf0ff, "SmartMX with 7 Byte UID",
|
||||||
|
{12, -1}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct card_sak const_cs[] = {
|
struct card_sak const_cs[] = {
|
||||||
{0x00, 0xff, "" }, // 00 MIFARE Ultralight / Ultralight C
|
{0x00, 0xff, "" }, // 00 MIFARE Ultralight / Ultralight C
|
||||||
{0x09, 0xff, "" }, // 01 MIFARE Mini 0.3K
|
{0x09, 0xff, "" }, // 01 MIFARE Mini 0.3K
|
||||||
{0x08, 0xff, "" }, // 02 MIFARE Classic 1K
|
{0x08, 0xff, "" }, // 02 MIFARE Classic 1K
|
||||||
{0x18, 0xff, "" }, // 03 MIFARE Classik 4K
|
{0x18, 0xff, "" }, // 03 MIFARE Classik 4K
|
||||||
{0x08, 0xff, " 2K, Security level 1" }, // 04 MIFARE Plus
|
{0x08, 0xff, " 2K, Security level 1" }, // 04 MIFARE Plus
|
||||||
{0x18, 0xff, " 4K, Security level 1" }, // 05 MIFARE Plus
|
{0x18, 0xff, " 4K, Security level 1" }, // 05 MIFARE Plus
|
||||||
{0x10, 0xff, " 2K, Security level 2" }, // 06 MIFARE Plus
|
{0x10, 0xff, " 2K, Security level 2" }, // 06 MIFARE Plus
|
||||||
{0x11, 0xff, " 4K, Security level 2" }, // 07 MIFARE Plus
|
{0x11, 0xff, " 4K, Security level 2" }, // 07 MIFARE Plus
|
||||||
{0x20, 0xff, " 2K, Security level 3" }, // 08 MIFARE Plus
|
{0x20, 0xff, " 2K, Security level 3" }, // 08 MIFARE Plus
|
||||||
{0x20, 0xff, " 4K, Security level 3" }, // 09 MIFARE Plus
|
{0x20, 0xff, " 4K, Security level 3" }, // 09 MIFARE Plus
|
||||||
{0x20, 0xff, " 4K" }, // 10 MIFARE DESFire
|
{0x20, 0xff, " 4K" }, // 10 MIFARE DESFire
|
||||||
{0x20, 0xff, " EV1 2K/4K/8K" }, // 11 MIFARE DESFire
|
{0x20, 0xff, " EV1 2K/4K/8K" }, // 11 MIFARE DESFire
|
||||||
{0x00, 0x00, "" }, // 12 SmartMX
|
{0x00, 0x00, "" }, // 12 SmartMX
|
||||||
};
|
};
|
||||||
|
|
||||||
uint8_t
|
uint8_t
|
||||||
|
@ -190,16 +204,16 @@ print_nfc_iso14443a_info (const nfc_iso14443a_info nai, bool verbose)
|
||||||
switch ((nai.abtAtqa[1] & 0xc0)>>6) {
|
switch ((nai.abtAtqa[1] & 0xc0)>>6) {
|
||||||
case 0:
|
case 0:
|
||||||
printf("single\n");
|
printf("single\n");
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
printf("double\n");
|
printf("double\n");
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
printf("triple\n");
|
printf("triple\n");
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
printf("RFU\n");
|
printf("RFU\n");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
printf("* bit frame anticollision ");
|
printf("* bit frame anticollision ");
|
||||||
switch (nai.abtAtqa[1] & 0x1f) {
|
switch (nai.abtAtqa[1] & 0x1f) {
|
||||||
|
@ -209,10 +223,10 @@ print_nfc_iso14443a_info (const nfc_iso14443a_info nai, bool verbose)
|
||||||
case 0x08:
|
case 0x08:
|
||||||
case 0x10:
|
case 0x10:
|
||||||
printf("supported\n");
|
printf("supported\n");
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
printf("not supported\n");
|
printf("not supported\n");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
printf (" UID (NFCID%c): ", (nai.abtUid[0] == 0x08 ? '3' : '1'));
|
printf (" UID (NFCID%c): ", (nai.abtUid[0] == 0x08 ? '3' : '1'));
|
||||||
|
@ -327,40 +341,40 @@ print_nfc_iso14443a_info (const nfc_iso14443a_info nai, bool verbose)
|
||||||
switch (CTC & 0xf0) {
|
switch (CTC & 0xf0) {
|
||||||
case 0x00:
|
case 0x00:
|
||||||
printf("(Multiple) Virtual Cards\n");
|
printf("(Multiple) Virtual Cards\n");
|
||||||
break;
|
break;
|
||||||
case 0x10:
|
case 0x10:
|
||||||
printf("Mifare DESFire\n");
|
printf("Mifare DESFire\n");
|
||||||
break;
|
break;
|
||||||
case 0x20:
|
case 0x20:
|
||||||
printf("Mifare Plus\n");
|
printf("Mifare Plus\n");
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
printf("RFU\n");
|
printf("RFU\n");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
printf(" * Memory size: ");
|
printf(" * Memory size: ");
|
||||||
switch (CTC & 0x0f) {
|
switch (CTC & 0x0f) {
|
||||||
case 0x00:
|
case 0x00:
|
||||||
printf("<1 kbyte\n");
|
printf("<1 kbyte\n");
|
||||||
break;
|
break;
|
||||||
case 0x01:
|
case 0x01:
|
||||||
printf("1 kbyte\n");
|
printf("1 kbyte\n");
|
||||||
break;
|
break;
|
||||||
case 0x02:
|
case 0x02:
|
||||||
printf("2 kbyte\n");
|
printf("2 kbyte\n");
|
||||||
break;
|
break;
|
||||||
case 0x03:
|
case 0x03:
|
||||||
printf("4 kbyte\n");
|
printf("4 kbyte\n");
|
||||||
break;
|
break;
|
||||||
case 0x04:
|
case 0x04:
|
||||||
printf("8 kbyte\n");
|
printf("8 kbyte\n");
|
||||||
break;
|
break;
|
||||||
case 0x0f:
|
case 0x0f:
|
||||||
printf("Unspecified\n");
|
printf("Unspecified\n");
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
printf("RFU\n");
|
printf("RFU\n");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ((nai.szAtsLen - offset) > 0) { // Omit 2 CRC bytes
|
if ((nai.szAtsLen - offset) > 0) { // Omit 2 CRC bytes
|
||||||
|
@ -370,31 +384,31 @@ print_nfc_iso14443a_info (const nfc_iso14443a_info nai, bool verbose)
|
||||||
switch (CVC & 0xf0) {
|
switch (CVC & 0xf0) {
|
||||||
case 0x00:
|
case 0x00:
|
||||||
printf("Engineering sample\n");
|
printf("Engineering sample\n");
|
||||||
break;
|
break;
|
||||||
case 0x20:
|
case 0x20:
|
||||||
printf("Released\n");
|
printf("Released\n");
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
printf("RFU\n");
|
printf("RFU\n");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
printf(" * Chip Generation: ");
|
printf(" * Chip Generation: ");
|
||||||
switch (CVC & 0x0f) {
|
switch (CVC & 0x0f) {
|
||||||
case 0x00:
|
case 0x00:
|
||||||
printf("Generation 1\n");
|
printf("Generation 1\n");
|
||||||
break;
|
break;
|
||||||
case 0x01:
|
case 0x01:
|
||||||
printf("Generation 2\n");
|
printf("Generation 2\n");
|
||||||
break;
|
break;
|
||||||
case 0x02:
|
case 0x02:
|
||||||
printf("Generation 3\n");
|
printf("Generation 3\n");
|
||||||
break;
|
break;
|
||||||
case 0x0f:
|
case 0x0f:
|
||||||
printf("Unspecified\n");
|
printf("Unspecified\n");
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
printf("RFU\n");
|
printf("RFU\n");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ((nai.szAtsLen - offset) > 0) { // Omit 2 CRC bytes
|
if ((nai.szAtsLen - offset) > 0) { // Omit 2 CRC bytes
|
||||||
|
@ -474,40 +488,40 @@ print_nfc_iso14443a_info (const nfc_iso14443a_info nai, bool verbose)
|
||||||
case 0x000488:
|
case 0x000488:
|
||||||
printf("* Mifare Classic 1K Infineon\n");
|
printf("* Mifare Classic 1K Infineon\n");
|
||||||
found_possible_match = true;
|
found_possible_match = true;
|
||||||
break;
|
break;
|
||||||
case 0x000298:
|
case 0x000298:
|
||||||
printf("* Gemplus MPCOS\n");
|
printf("* Gemplus MPCOS\n");
|
||||||
found_possible_match = true;
|
found_possible_match = true;
|
||||||
break;
|
break;
|
||||||
case 0x030428:
|
case 0x030428:
|
||||||
printf("* JCOP31\n");
|
printf("* JCOP31\n");
|
||||||
found_possible_match = true;
|
found_possible_match = true;
|
||||||
break;
|
break;
|
||||||
case 0x004820:
|
case 0x004820:
|
||||||
printf("* JCOP31 v2.4.1\n");
|
printf("* JCOP31 v2.4.1\n");
|
||||||
printf("* JCOP31 v2.2\n");
|
printf("* JCOP31 v2.2\n");
|
||||||
found_possible_match = true;
|
found_possible_match = true;
|
||||||
break;
|
break;
|
||||||
case 0x000428:
|
case 0x000428:
|
||||||
printf("* JCOP31 v2.3.1\n");
|
printf("* JCOP31 v2.3.1\n");
|
||||||
found_possible_match = true;
|
found_possible_match = true;
|
||||||
break;
|
break;
|
||||||
case 0x000453:
|
case 0x000453:
|
||||||
printf("* Fudan FM1208SH01\n");
|
printf("* Fudan FM1208SH01\n");
|
||||||
found_possible_match = true;
|
found_possible_match = true;
|
||||||
break;
|
break;
|
||||||
case 0x000820:
|
case 0x000820:
|
||||||
printf("* Fudan FM1208\n");
|
printf("* Fudan FM1208\n");
|
||||||
found_possible_match = true;
|
found_possible_match = true;
|
||||||
break;
|
break;
|
||||||
case 0x000238:
|
case 0x000238:
|
||||||
printf("* MFC 4K emulated by Nokia 6212 Classic\n");
|
printf("* MFC 4K emulated by Nokia 6212 Classic\n");
|
||||||
found_possible_match = true;
|
found_possible_match = true;
|
||||||
break;
|
break;
|
||||||
case 0x000838:
|
case 0x000838:
|
||||||
printf("* MFC 4K emulated by Nokia 6131 NFC\n");
|
printf("* MFC 4K emulated by Nokia 6131 NFC\n");
|
||||||
found_possible_match = true;
|
found_possible_match = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (! found_possible_match) {
|
if (! found_possible_match) {
|
||||||
printf("* Unknown card, sorry\n");
|
printf("* Unknown card, sorry\n");
|
||||||
|
@ -609,7 +623,7 @@ print_nfc_iso14443bi_info (const nfc_iso14443bi_info nii, bool verbose)
|
||||||
printf ("%i\n", version);
|
printf ("%i\n", version);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((nii.btVerLog & 0x80) && (nii.btConfig & 0x80)){
|
if ((nii.btVerLog & 0x80) && (nii.btConfig & 0x80)) {
|
||||||
printf (" Wait Enable: yes");
|
printf (" Wait Enable: yes");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -663,28 +677,28 @@ print_nfc_target (const nfc_target nt, bool verbose)
|
||||||
switch(nt.nm.nmt) {
|
switch(nt.nm.nmt) {
|
||||||
case NMT_ISO14443A:
|
case NMT_ISO14443A:
|
||||||
print_nfc_iso14443a_info (nt.nti.nai, verbose);
|
print_nfc_iso14443a_info (nt.nti.nai, verbose);
|
||||||
break;
|
break;
|
||||||
case NMT_JEWEL:
|
case NMT_JEWEL:
|
||||||
print_nfc_jewel_info (nt.nti.nji, verbose);
|
print_nfc_jewel_info (nt.nti.nji, verbose);
|
||||||
break;
|
break;
|
||||||
case NMT_FELICA:
|
case NMT_FELICA:
|
||||||
print_nfc_felica_info (nt.nti.nfi, verbose);
|
print_nfc_felica_info (nt.nti.nfi, verbose);
|
||||||
break;
|
break;
|
||||||
case NMT_ISO14443B:
|
case NMT_ISO14443B:
|
||||||
print_nfc_iso14443b_info (nt.nti.nbi, verbose);
|
print_nfc_iso14443b_info (nt.nti.nbi, verbose);
|
||||||
break;
|
break;
|
||||||
case NMT_ISO14443BI:
|
case NMT_ISO14443BI:
|
||||||
print_nfc_iso14443bi_info (nt.nti.nii, verbose);
|
print_nfc_iso14443bi_info (nt.nti.nii, verbose);
|
||||||
break;
|
break;
|
||||||
case NMT_ISO14443B2SR:
|
case NMT_ISO14443B2SR:
|
||||||
print_nfc_iso14443b2sr_info (nt.nti.nsi, verbose);
|
print_nfc_iso14443b2sr_info (nt.nti.nsi, verbose);
|
||||||
break;
|
break;
|
||||||
case NMT_ISO14443B2CT:
|
case NMT_ISO14443B2CT:
|
||||||
print_nfc_iso14443b2ct_info (nt.nti.nci, verbose);
|
print_nfc_iso14443b2ct_info (nt.nti.nci, verbose);
|
||||||
break;
|
break;
|
||||||
case NMT_DEP:
|
case NMT_DEP:
|
||||||
print_nfc_dep_info (nt.nti.ndi, verbose);
|
print_nfc_dep_info (nt.nti.ndi, verbose);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -361,27 +361,27 @@ extern "C" {
|
||||||
|
|
||||||
/* Windows specific functions */
|
/* Windows specific functions */
|
||||||
|
|
||||||
#define LIBUSB_HAS_INSTALL_SERVICE_NP 1
|
#define LIBUSB_HAS_INSTALL_SERVICE_NP 1
|
||||||
int usb_install_service_np(void);
|
int usb_install_service_np(void);
|
||||||
void CALLBACK usb_install_service_np_rundll(HWND wnd, HINSTANCE instance,
|
void CALLBACK usb_install_service_np_rundll(HWND wnd, HINSTANCE instance,
|
||||||
LPSTR cmd_line, int cmd_show);
|
LPSTR cmd_line, int cmd_show);
|
||||||
|
|
||||||
#define LIBUSB_HAS_UNINSTALL_SERVICE_NP 1
|
#define LIBUSB_HAS_UNINSTALL_SERVICE_NP 1
|
||||||
int usb_uninstall_service_np(void);
|
int usb_uninstall_service_np(void);
|
||||||
void CALLBACK usb_uninstall_service_np_rundll(HWND wnd, HINSTANCE instance,
|
void CALLBACK usb_uninstall_service_np_rundll(HWND wnd, HINSTANCE instance,
|
||||||
LPSTR cmd_line, int cmd_show);
|
LPSTR cmd_line, int cmd_show);
|
||||||
|
|
||||||
#define LIBUSB_HAS_INSTALL_DRIVER_NP 1
|
#define LIBUSB_HAS_INSTALL_DRIVER_NP 1
|
||||||
int usb_install_driver_np(const char *inf_file);
|
int usb_install_driver_np(const char *inf_file);
|
||||||
void CALLBACK usb_install_driver_np_rundll(HWND wnd, HINSTANCE instance,
|
void CALLBACK usb_install_driver_np_rundll(HWND wnd, HINSTANCE instance,
|
||||||
LPSTR cmd_line, int cmd_show);
|
LPSTR cmd_line, int cmd_show);
|
||||||
|
|
||||||
#define LIBUSB_HAS_TOUCH_INF_FILE_NP 1
|
#define LIBUSB_HAS_TOUCH_INF_FILE_NP 1
|
||||||
int usb_touch_inf_file_np(const char *inf_file);
|
int usb_touch_inf_file_np(const char *inf_file);
|
||||||
void CALLBACK usb_touch_inf_file_np_rundll(HWND wnd, HINSTANCE instance,
|
void CALLBACK usb_touch_inf_file_np_rundll(HWND wnd, HINSTANCE instance,
|
||||||
LPSTR cmd_line, int cmd_show);
|
LPSTR cmd_line, int cmd_show);
|
||||||
|
|
||||||
#define LIBUSB_HAS_INSTALL_NEEDS_RESTART_NP 1
|
#define LIBUSB_HAS_INSTALL_NEEDS_RESTART_NP 1
|
||||||
int usb_install_needs_restart_np(void);
|
int usb_install_needs_restart_np(void);
|
||||||
|
|
||||||
const struct usb_version *usb_get_version(void);
|
const struct usb_version *usb_get_version(void);
|
||||||
|
|
Loading…
Reference in a new issue