astyle --formatted --mode=c --indent=spaces=2 --indent-switches --indent-preprocessor --keep-one-line-blocks --max-instatement-indent=60 --brackets=linux --pad-oper --unpad-paren --pad-header --align-pointer=name
This commit is contained in:
parent
01303fab0d
commit
568317929d
21 changed files with 94 additions and 94 deletions
|
@ -88,7 +88,7 @@ target_io(nfc_target *pnt, const uint8_t *pbtInput, const size_t szInput, uint8_
|
||||||
case 0x30: // Mifare read
|
case 0x30: // Mifare read
|
||||||
// block address is in pbtInput[1]
|
// block address is in pbtInput[1]
|
||||||
*pszOutput = 15;
|
*pszOutput = 15;
|
||||||
strcpy((char*)pbtOutput, "You read block ");
|
strcpy((char *)pbtOutput, "You read block ");
|
||||||
pbtOutput[15] = pbtInput[1];
|
pbtOutput[15] = pbtInput[1];
|
||||||
break;
|
break;
|
||||||
case 0x50: // HLTA (ISO14443-3)
|
case 0x50: // HLTA (ISO14443-3)
|
||||||
|
|
|
@ -63,7 +63,7 @@ static void stop_polling(int sig)
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
print_usage(const char* progname)
|
print_usage(const char *progname)
|
||||||
{
|
{
|
||||||
printf("usage: %s [-v]\n", progname);
|
printf("usage: %s [-v]\n", progname);
|
||||||
printf(" -v\t verbose display\n");
|
printf(" -v\t verbose display\n");
|
||||||
|
|
|
@ -67,14 +67,14 @@
|
||||||
|
|
||||||
#define MAX_FRAME_LEN 264
|
#define MAX_FRAME_LEN 264
|
||||||
|
|
||||||
int main(int argc, const char* argv[])
|
int main(int argc, const char *argv[])
|
||||||
{
|
{
|
||||||
nfc_device *pnd;
|
nfc_device *pnd;
|
||||||
uint8_t abtRx[MAX_FRAME_LEN];
|
uint8_t abtRx[MAX_FRAME_LEN];
|
||||||
uint8_t abtTx[MAX_FRAME_LEN];
|
uint8_t abtTx[MAX_FRAME_LEN];
|
||||||
size_t szRx = sizeof(abtRx);
|
size_t szRx = sizeof(abtRx);
|
||||||
size_t szTx;
|
size_t szTx;
|
||||||
FILE* input = NULL;
|
FILE *input = NULL;
|
||||||
|
|
||||||
if (argc >= 2) {
|
if (argc >= 2) {
|
||||||
if ((input = fopen(argv[1], "r")) == NULL) {
|
if ((input = fopen(argv[1], "r")) == NULL) {
|
||||||
|
|
|
@ -54,7 +54,7 @@ extern "C" {
|
||||||
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
|
||||||
}
|
}
|
||||||
|
|
|
@ -120,8 +120,8 @@ extern "C" {
|
||||||
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 */
|
||||||
|
|
|
@ -127,7 +127,7 @@ uart_flush_input(serial_port sp)
|
||||||
if (available_bytes_count == 0) {
|
if (available_bytes_count == 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
char* rx = malloc(available_bytes_count);
|
char *rx = malloc(available_bytes_count);
|
||||||
// There is something available, read the data
|
// There is something available, read the data
|
||||||
res = read(UART_DATA(sp)->fd, rx, available_bytes_count);
|
res = read(UART_DATA(sp)->fd, rx, available_bytes_count);
|
||||||
log_put(LOG_CATEGORY, NFC_PRIORITY_TRACE, "%d bytes have eatten.", available_bytes_count);
|
log_put(LOG_CATEGORY, NFC_PRIORITY_TRACE, "%d bytes have eatten.", available_bytes_count);
|
||||||
|
@ -250,7 +250,7 @@ uart_close(const serial_port sp)
|
||||||
int
|
int
|
||||||
uart_receive(serial_port sp, uint8_t *pbtRx, const size_t szRx, void *abort_p, int timeout)
|
uart_receive(serial_port sp, uint8_t *pbtRx, const size_t szRx, void *abort_p, int timeout)
|
||||||
{
|
{
|
||||||
int iAbortFd = abort_p ? *((int*)abort_p) : 0;
|
int iAbortFd = abort_p ? *((int *)abort_p) : 0;
|
||||||
int received_bytes_count = 0;
|
int received_bytes_count = 0;
|
||||||
int available_bytes_count = 0;
|
int available_bytes_count = 0;
|
||||||
const int expected_bytes_count = (int)szRx;
|
const int expected_bytes_count = (int)szRx;
|
||||||
|
|
|
@ -139,7 +139,7 @@ uart_get_speed(const serial_port sp)
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
uart_receive(serial_port sp, uint8_t * pbtRx, const size_t szRx, void * abort_p, int timeout)
|
uart_receive(serial_port sp, uint8_t *pbtRx, const size_t szRx, void *abort_p, int timeout)
|
||||||
{
|
{
|
||||||
DWORD dwBytesToGet = (DWORD)szRx;
|
DWORD dwBytesToGet = (DWORD)szRx;
|
||||||
DWORD dwBytesReceived = 0;
|
DWORD dwBytesReceived = 0;
|
||||||
|
@ -163,7 +163,7 @@ uart_receive(serial_port sp, uint8_t * pbtRx, const size_t szRx, void * abort_p,
|
||||||
|
|
||||||
// TODO Enhance the reception method
|
// TODO Enhance the reception method
|
||||||
// - According to MSDN, it could be better to implement nfc_abort_command() mecanism using Cancello()
|
// - According to MSDN, it could be better to implement nfc_abort_command() mecanism using Cancello()
|
||||||
volatile bool * abort_flag_p = (volatile bool *)abort_p;
|
volatile bool *abort_flag_p = (volatile bool *)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,
|
||||||
|
@ -194,7 +194,7 @@ uart_receive(serial_port sp, uint8_t * pbtRx, const size_t szRx, void * abort_p,
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
uart_send(serial_port sp, const uint8_t * pbtTx, const size_t szTx, int timeout)
|
uart_send(serial_port sp, const uint8_t *pbtTx, const size_t szTx, int timeout)
|
||||||
{
|
{
|
||||||
DWORD dwTxLen = 0;
|
DWORD dwTxLen = 0;
|
||||||
|
|
||||||
|
@ -238,12 +238,12 @@ BOOL is_port_available(int nPort)
|
||||||
char **
|
char **
|
||||||
uart_list_ports(void)
|
uart_list_ports(void)
|
||||||
{
|
{
|
||||||
char **availablePorts = malloc((1 + MAX_SERIAL_PORT_WIN) * sizeof(char*));
|
char **availablePorts = malloc((1 + MAX_SERIAL_PORT_WIN) * sizeof(char *));
|
||||||
int curIndex = 0;
|
int curIndex = 0;
|
||||||
int i;
|
int i;
|
||||||
for (i = 1; i <= MAX_SERIAL_PORT_WIN; i++) {
|
for (i = 1; i <= MAX_SERIAL_PORT_WIN; i++) {
|
||||||
if (is_port_available(i)) {
|
if (is_port_available(i)) {
|
||||||
availablePorts[curIndex] = (char*)malloc(10);
|
availablePorts[curIndex] = (char *)malloc(10);
|
||||||
sprintf(availablePorts[curIndex], "COM%d", i);
|
sprintf(availablePorts[curIndex], "COM%d", i);
|
||||||
// printf("found candidate port: %s\n", availablePorts[curIndex]);
|
// printf("found candidate port: %s\n", availablePorts[curIndex]);
|
||||||
curIndex++;
|
curIndex++;
|
||||||
|
|
|
@ -95,7 +95,7 @@ pn53x_init(struct nfc_device *pnd)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!CHIP_DATA(pnd)->supported_modulation_as_target) {
|
if (!CHIP_DATA(pnd)->supported_modulation_as_target) {
|
||||||
CHIP_DATA(pnd)->supported_modulation_as_target = (nfc_modulation_type*) pn53x_supported_modulation_as_target;
|
CHIP_DATA(pnd)->supported_modulation_as_target = (nfc_modulation_type *) pn53x_supported_modulation_as_target;
|
||||||
}
|
}
|
||||||
|
|
||||||
// CRC handling should be enabled by default as declared in nfc_device_new
|
// CRC handling should be enabled by default as declared in nfc_device_new
|
||||||
|
@ -1189,7 +1189,7 @@ pn53x_initiator_select_dep_target(struct nfc_device *pnd,
|
||||||
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;
|
||||||
|
|
||||||
switch (nbr) {
|
switch (nbr) {
|
||||||
case NBR_212:
|
case NBR_212:
|
||||||
|
@ -2345,7 +2345,7 @@ pn53x_InRelease(struct nfc_device *pnd, const uint8_t ui8Target)
|
||||||
int
|
int
|
||||||
pn53x_InAutoPoll(struct nfc_device *pnd,
|
pn53x_InAutoPoll(struct nfc_device *pnd,
|
||||||
const pn53x_target_type *ppttTargetTypes, const size_t szTargetTypes,
|
const pn53x_target_type *ppttTargetTypes, const size_t szTargetTypes,
|
||||||
const uint8_t btPollNr, const uint8_t btPeriod, nfc_target * pntTargets, const int timeout)
|
const uint8_t btPollNr, const uint8_t btPeriod, nfc_target *pntTargets, const int timeout)
|
||||||
{
|
{
|
||||||
size_t szTargetFound = 0;
|
size_t szTargetFound = 0;
|
||||||
if (CHIP_DATA(pnd)->type != PN532) {
|
if (CHIP_DATA(pnd)->type != PN532) {
|
||||||
|
@ -2849,27 +2849,27 @@ pn53x_get_supported_baud_rate(nfc_device *pnd, const nfc_modulation_type nmt, co
|
||||||
{
|
{
|
||||||
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:
|
||||||
case NMT_ISO14443B2CT: {
|
case NMT_ISO14443B2CT: {
|
||||||
if ((CHIP_DATA(pnd)->type != PN533)) {
|
if ((CHIP_DATA(pnd)->type != PN533)) {
|
||||||
*supported_br = (nfc_baud_rate*)pn532_iso14443b_supported_baud_rates;
|
*supported_br = (nfc_baud_rate *)pn532_iso14443b_supported_baud_rates;
|
||||||
} else {
|
} else {
|
||||||
*supported_br = (nfc_baud_rate*)pn533_iso14443b_supported_baud_rates;
|
*supported_br = (nfc_baud_rate *)pn533_iso14443b_supported_baud_rates;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
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;
|
||||||
|
|
|
@ -538,7 +538,7 @@ acr122s_probe(nfc_connstring connstrings[], size_t connstrings_len, size_t *pszD
|
||||||
}
|
}
|
||||||
iDevice = 0;
|
iDevice = 0;
|
||||||
while ((acPort = acPorts[iDevice++])) {
|
while ((acPort = acPorts[iDevice++])) {
|
||||||
free((void*)acPort);
|
free((void *)acPort);
|
||||||
}
|
}
|
||||||
free(acPorts);
|
free(acPorts);
|
||||||
#endif /* SERIAL_AUTOPROBE_ENABLED */
|
#endif /* SERIAL_AUTOPROBE_ENABLED */
|
||||||
|
|
|
@ -156,7 +156,7 @@ arygon_probe(nfc_connstring connstrings[], size_t connstrings_len, size_t *pszDe
|
||||||
}
|
}
|
||||||
iDevice = 0;
|
iDevice = 0;
|
||||||
while ((acPort = acPorts[iDevice++])) {
|
while ((acPort = acPorts[iDevice++])) {
|
||||||
free((void*)acPort);
|
free((void *)acPort);
|
||||||
}
|
}
|
||||||
free(acPorts);
|
free(acPorts);
|
||||||
#endif /* SERIAL_AUTOPROBE_ENABLED */
|
#endif /* SERIAL_AUTOPROBE_ENABLED */
|
||||||
|
@ -378,7 +378,7 @@ arygon_tama_receive(nfc_device *pnd, uint8_t *pbtData, const size_t szDataLen, i
|
||||||
#ifndef WIN32
|
#ifndef WIN32
|
||||||
abort_p = &(DRIVER_DATA(pnd)->iAbortFds[1]);
|
abort_p = &(DRIVER_DATA(pnd)->iAbortFds[1]);
|
||||||
#else
|
#else
|
||||||
abort_p = (void*) & (DRIVER_DATA(pnd)->abort_flag);
|
abort_p = (void *) & (DRIVER_DATA(pnd)->abort_flag);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
pnd->last_error = uart_receive(DRIVER_DATA(pnd)->port, abtRxBuf, 5, abort_p, timeout);
|
pnd->last_error = uart_receive(DRIVER_DATA(pnd)->port, abtRxBuf, 5, abort_p, timeout);
|
||||||
|
@ -508,7 +508,7 @@ arygon_firmware(nfc_device *pnd, char *str)
|
||||||
if (0 == memcmp(abtRx, arygon_error_none, 6)) {
|
if (0 == memcmp(abtRx, arygon_error_none, 6)) {
|
||||||
uint8_t *p = abtRx + 6;
|
uint8_t *p = abtRx + 6;
|
||||||
unsigned int szData;
|
unsigned int szData;
|
||||||
sscanf((const char*)p, "%02x%s", &szData, p);
|
sscanf((const char *)p, "%02x%s", &szData, p);
|
||||||
memcpy(str, p, szData);
|
memcpy(str, p, szData);
|
||||||
*(str + szData) = '\0';
|
*(str + szData) = '\0';
|
||||||
}
|
}
|
||||||
|
|
|
@ -134,7 +134,7 @@ pn532_uart_probe(nfc_connstring connstrings[], size_t connstrings_len, size_t *p
|
||||||
}
|
}
|
||||||
iDevice = 0;
|
iDevice = 0;
|
||||||
while ((acPort = acPorts[iDevice++])) {
|
while ((acPort = acPorts[iDevice++])) {
|
||||||
free((void*)acPort);
|
free((void *)acPort);
|
||||||
}
|
}
|
||||||
free(acPorts);
|
free(acPorts);
|
||||||
#endif /* SERIAL_AUTOPROBE_ENABLED */
|
#endif /* SERIAL_AUTOPROBE_ENABLED */
|
||||||
|
@ -358,7 +358,7 @@ pn532_uart_receive(nfc_device *pnd, uint8_t *pbtData, const size_t szDataLen, in
|
||||||
#ifndef WIN32
|
#ifndef WIN32
|
||||||
abort_p = &(DRIVER_DATA(pnd)->iAbortFds[1]);
|
abort_p = &(DRIVER_DATA(pnd)->iAbortFds[1]);
|
||||||
#else
|
#else
|
||||||
abort_p = (void*) & (DRIVER_DATA(pnd)->abort_flag);
|
abort_p = (void *) & (DRIVER_DATA(pnd)->abort_flag);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
pnd->last_error = uart_receive(DRIVER_DATA(pnd)->port, abtRxBuf, 5, abort_p, timeout);
|
pnd->last_error = uart_receive(DRIVER_DATA(pnd)->port, abtRxBuf, 5, abort_p, timeout);
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
#include "nfc-internal.h"
|
#include "nfc-internal.h"
|
||||||
|
|
||||||
void
|
void
|
||||||
prepare_initiator_data(const nfc_modulation nm, uint8_t **ppbtInitiatorData, size_t * pszInitiatorData)
|
prepare_initiator_data(const nfc_modulation nm, uint8_t **ppbtInitiatorData, size_t *pszInitiatorData)
|
||||||
{
|
{
|
||||||
switch (nm.nmt) {
|
switch (nm.nmt) {
|
||||||
case NMT_ISO14443B: {
|
case NMT_ISO14443B: {
|
||||||
|
|
|
@ -135,27 +135,27 @@
|
||||||
|
|
||||||
struct nfc_driver {
|
struct nfc_driver {
|
||||||
const char *name;
|
const char *name;
|
||||||
bool (*probe)(nfc_connstring connstrings[], size_t connstrings_len, size_t * pszDeviceFound);
|
bool (*probe)(nfc_connstring connstrings[], size_t connstrings_len, size_t *pszDeviceFound);
|
||||||
struct nfc_device *(*open)(const nfc_connstring connstring);
|
struct nfc_device *(*open)(const nfc_connstring connstring);
|
||||||
void (*close)(struct nfc_device *pnd);
|
void (*close)(struct nfc_device *pnd);
|
||||||
const char *(*strerror)(const struct nfc_device *pnd);
|
const char *(*strerror)(const struct nfc_device *pnd);
|
||||||
|
|
||||||
int (*initiator_init)(struct nfc_device *pnd);
|
int (*initiator_init)(struct nfc_device *pnd);
|
||||||
int (*initiator_select_passive_target)(struct nfc_device *pnd, const nfc_modulation nm, const uint8_t * pbtInitData, const size_t szInitData, nfc_target * pnt);
|
int (*initiator_select_passive_target)(struct nfc_device *pnd, const nfc_modulation nm, const uint8_t *pbtInitData, const size_t szInitData, nfc_target *pnt);
|
||||||
int (*initiator_poll_target)(struct nfc_device *pnd, const nfc_modulation * pnmModulations, const size_t szModulations, const uint8_t uiPollNr, const uint8_t btPeriod, nfc_target * pnt);
|
int (*initiator_poll_target)(struct nfc_device *pnd, const nfc_modulation *pnmModulations, const size_t szModulations, const uint8_t uiPollNr, const uint8_t btPeriod, nfc_target *pnt);
|
||||||
int (*initiator_select_dep_target)(struct nfc_device *pnd, const nfc_dep_mode ndm, const nfc_baud_rate nbr, const nfc_dep_info * pndiInitiator, nfc_target * pnt, const int timeout);
|
int (*initiator_select_dep_target)(struct nfc_device *pnd, const nfc_dep_mode ndm, const nfc_baud_rate nbr, const nfc_dep_info *pndiInitiator, nfc_target *pnt, const int timeout);
|
||||||
int (*initiator_deselect_target)(struct nfc_device *pnd);
|
int (*initiator_deselect_target)(struct nfc_device *pnd);
|
||||||
int (*initiator_transceive_bytes)(struct nfc_device *pnd, const uint8_t * pbtTx, const size_t szTx, uint8_t * pbtRx, const size_t szRx, int timeout);
|
int (*initiator_transceive_bytes)(struct nfc_device *pnd, const uint8_t *pbtTx, const size_t szTx, uint8_t *pbtRx, const size_t szRx, int timeout);
|
||||||
int (*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);
|
int (*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);
|
||||||
int (*initiator_transceive_bytes_timed)(struct nfc_device *pnd, const uint8_t * pbtTx, const size_t szTx, uint8_t * pbtRx, uint32_t * cycles);
|
int (*initiator_transceive_bytes_timed)(struct nfc_device *pnd, const uint8_t *pbtTx, const size_t szTx, uint8_t *pbtRx, uint32_t *cycles);
|
||||||
int (*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);
|
int (*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);
|
||||||
int (*initiator_target_is_present)(struct nfc_device *pnd, const nfc_target nt);
|
int (*initiator_target_is_present)(struct nfc_device *pnd, const nfc_target nt);
|
||||||
|
|
||||||
int (*target_init)(struct nfc_device *pnd, nfc_target * pnt, uint8_t * pbtRx, const size_t szRx, int timeout);
|
int (*target_init)(struct nfc_device *pnd, nfc_target *pnt, uint8_t *pbtRx, const size_t szRx, int timeout);
|
||||||
int (*target_send_bytes)(struct nfc_device *pnd, const uint8_t * pbtTx, const size_t szTx, int timeout);
|
int (*target_send_bytes)(struct nfc_device *pnd, const uint8_t *pbtTx, const size_t szTx, int timeout);
|
||||||
int (*target_receive_bytes)(struct nfc_device *pnd, uint8_t * pbtRx, const size_t szRxLen, int timeout);
|
int (*target_receive_bytes)(struct nfc_device *pnd, uint8_t *pbtRx, const size_t szRxLen, int timeout);
|
||||||
int (*target_send_bits)(struct nfc_device *pnd, const uint8_t * pbtTx, const size_t szTxBits, const uint8_t * pbtTxPar);
|
int (*target_send_bits)(struct nfc_device *pnd, const uint8_t *pbtTx, const size_t szTxBits, const uint8_t *pbtTxPar);
|
||||||
int (*target_receive_bits)(struct nfc_device *pnd, uint8_t * pbtRx, const size_t szRxLen, uint8_t * pbtRxPar);
|
int (*target_receive_bits)(struct nfc_device *pnd, uint8_t *pbtRx, const size_t szRxLen, uint8_t *pbtRxPar);
|
||||||
|
|
||||||
int (*device_set_property_bool)(struct nfc_device *pnd, const nfc_property property, const bool bEnable);
|
int (*device_set_property_bool)(struct nfc_device *pnd, const nfc_property property, const bool bEnable);
|
||||||
int (*device_set_property_int)(struct nfc_device *pnd, const nfc_property property, const int value);
|
int (*device_set_property_int)(struct nfc_device *pnd, const nfc_property property, const int value);
|
||||||
|
@ -201,8 +201,8 @@ struct nfc_device {
|
||||||
nfc_device *nfc_device_new(const nfc_connstring connstring);
|
nfc_device *nfc_device_new(const nfc_connstring connstring);
|
||||||
void nfc_device_free(nfc_device *dev);
|
void nfc_device_free(nfc_device *dev);
|
||||||
|
|
||||||
void iso14443_cascade_uid(const uint8_t abtUID[], const size_t szUID, uint8_t * pbtCascadedUID, size_t * pszCascadedUID);
|
void iso14443_cascade_uid(const uint8_t abtUID[], const size_t szUID, uint8_t *pbtCascadedUID, size_t *pszCascadedUID);
|
||||||
|
|
||||||
void prepare_initiator_data(const nfc_modulation nm, uint8_t **ppbtInitiatorData, size_t * pszInitiatorData);
|
void prepare_initiator_data(const nfc_modulation nm, uint8_t **ppbtInitiatorData, size_t *pszInitiatorData);
|
||||||
|
|
||||||
#endif // __NFC_INTERNAL_H__
|
#endif // __NFC_INTERNAL_H__
|
||||||
|
|
|
@ -85,19 +85,19 @@ target_thread(void *arg)
|
||||||
size_t szRx = sizeof(abtRx);
|
size_t szRx = sizeof(abtRx);
|
||||||
int res = nfc_target_init(device, &nt, abtRx, sizeof(abtRx), 0);
|
int res = nfc_target_init(device, &nt, abtRx, sizeof(abtRx), 0);
|
||||||
cut_assert_operator_int(res, > , 0, cut_message("Can't initialize NFC device as target: %s", nfc_strerror(device)));
|
cut_assert_operator_int(res, > , 0, cut_message("Can't initialize NFC device as 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; }
|
||||||
|
|
||||||
res = nfc_target_receive_bytes(device, abtRx, sizeof(abtRx), 500);
|
res = nfc_target_receive_bytes(device, abtRx, sizeof(abtRx), 500);
|
||||||
cut_assert_operator_int(res, > , 0, cut_message("Can't receive bytes from initiator: %s", nfc_strerror(device)));
|
cut_assert_operator_int(res, > , 0, cut_message("Can't receive bytes from initiator: %s", nfc_strerror(device)));
|
||||||
szRx = (size_t) res;
|
szRx = (size_t) res;
|
||||||
const uint8_t abtAttRx[] = "Hello DEP target!";
|
const uint8_t abtAttRx[] = "Hello DEP target!";
|
||||||
cut_assert_equal_memory(abtAttRx, sizeof(abtAttRx), abtRx, szRx, cut_message("Invalid received data"));
|
cut_assert_equal_memory(abtAttRx, sizeof(abtAttRx), abtRx, szRx, cut_message("Invalid received data"));
|
||||||
if (res <= 0) { thread_res = -1; return (void*) thread_res; }
|
if (res <= 0) { thread_res = -1; return (void *) thread_res; }
|
||||||
|
|
||||||
const uint8_t abtTx[] = "Hello DEP initiator!";
|
const uint8_t abtTx[] = "Hello DEP initiator!";
|
||||||
res = nfc_target_send_bytes(device, abtTx, sizeof(abtTx), 500);
|
res = nfc_target_send_bytes(device, abtTx, sizeof(abtTx), 500);
|
||||||
cut_assert_operator_int(res, > , 0, cut_message("Can't send bytes to initiator: %s", nfc_strerror(device)));
|
cut_assert_operator_int(res, > , 0, cut_message("Can't send bytes to initiator: %s", nfc_strerror(device)));
|
||||||
if (res <= 0) { thread_res = -1; return (void*) thread_res; }
|
if (res <= 0) { thread_res = -1; return (void *) thread_res; }
|
||||||
|
|
||||||
return (void *) thread_res;
|
return (void *) thread_res;
|
||||||
}
|
}
|
||||||
|
@ -117,7 +117,7 @@ initiator_thread(void *arg)
|
||||||
printf("=========== INITIATOR %s =========\n", nfc_device_get_name(device));
|
printf("=========== INITIATOR %s =========\n", nfc_device_get_name(device));
|
||||||
int res = nfc_initiator_init(device);
|
int res = nfc_initiator_init(device);
|
||||||
cut_assert_equal_int(0, res, cut_message("Can't initialize NFC device as initiator: %s", nfc_strerror(device)));
|
cut_assert_equal_int(0, res, cut_message("Can't initialize NFC device as initiator: %s", nfc_strerror(device)));
|
||||||
if (res < 0) { thread_res = -1; return (void*) thread_res; }
|
if (res < 0) { thread_res = -1; return (void *) thread_res; }
|
||||||
|
|
||||||
nfc_target nt;
|
nfc_target nt;
|
||||||
|
|
||||||
|
@ -130,7 +130,7 @@ initiator_thread(void *arg)
|
||||||
cut_assert_equal_memory("\x11\x22\x33\x44\x55\x66\x77\x88\x99\xAA", 10, nt.nti.ndi.abtNFCID3, 10, cut_message("Invalid target NFCID3"));
|
cut_assert_equal_memory("\x11\x22\x33\x44\x55\x66\x77\x88\x99\xAA", 10, nt.nti.ndi.abtNFCID3, 10, cut_message("Invalid target NFCID3"));
|
||||||
cut_assert_equal_int(NDM_ACTIVE, nt.nti.ndi.ndm, cut_message("Invalid target DEP mode"));
|
cut_assert_equal_int(NDM_ACTIVE, nt.nti.ndi.ndm, cut_message("Invalid target DEP mode"));
|
||||||
cut_assert_equal_memory("\x12\x34\x56\x78", 4, nt.nti.ndi.abtGB, nt.nti.ndi.szGB, cut_message("Invalid target general bytes"));
|
cut_assert_equal_memory("\x12\x34\x56\x78", 4, nt.nti.ndi.abtGB, nt.nti.ndi.szGB, cut_message("Invalid target general bytes"));
|
||||||
if (res <= 0) { thread_res = -1; return (void*) thread_res; }
|
if (res <= 0) { thread_res = -1; return (void *) thread_res; }
|
||||||
|
|
||||||
const uint8_t abtTx[] = "Hello DEP target!";
|
const uint8_t abtTx[] = "Hello DEP target!";
|
||||||
uint8_t abtRx[1024];
|
uint8_t abtRx[1024];
|
||||||
|
@ -140,10 +140,10 @@ initiator_thread(void *arg)
|
||||||
|
|
||||||
const uint8_t abtAttRx[] = "Hello DEP initiator!";
|
const uint8_t abtAttRx[] = "Hello DEP initiator!";
|
||||||
cut_assert_equal_memory(abtAttRx, sizeof(abtAttRx), abtRx, szRx, cut_message("Invalid received data"));
|
cut_assert_equal_memory(abtAttRx, sizeof(abtAttRx), abtRx, szRx, cut_message("Invalid received data"));
|
||||||
if (res < 0) { thread_res = -1; return (void*) thread_res; }
|
if (res < 0) { thread_res = -1; return (void *) thread_res; }
|
||||||
res = nfc_initiator_deselect_target(device);
|
res = nfc_initiator_deselect_target(device);
|
||||||
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; }
|
||||||
|
|
||||||
return (void *) thread_res;
|
return (void *) thread_res;
|
||||||
}
|
}
|
||||||
|
|
|
@ -84,7 +84,7 @@ target_thread(void *arg)
|
||||||
size_t szRx = sizeof(abtRx);
|
size_t szRx = sizeof(abtRx);
|
||||||
int res = nfc_target_init(device, &nt, abtRx, szRx, 0);
|
int res = nfc_target_init(device, &nt, abtRx, szRx, 0);
|
||||||
cut_assert_operator_int(res, > , 0, cut_message("Can't initialize NFC device as target: %s", nfc_strerror(device)));
|
cut_assert_operator_int(res, > , 0, cut_message("Can't initialize NFC device as 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; }
|
||||||
|
|
||||||
// First pass
|
// First pass
|
||||||
res = nfc_target_receive_bytes(device, abtRx, sizeof(abtRx), 500);
|
res = nfc_target_receive_bytes(device, abtRx, sizeof(abtRx), 500);
|
||||||
|
@ -93,12 +93,12 @@ target_thread(void *arg)
|
||||||
|
|
||||||
const uint8_t abtAttRx[] = "Hello DEP target!";
|
const uint8_t abtAttRx[] = "Hello DEP target!";
|
||||||
cut_assert_equal_memory(abtAttRx, sizeof(abtAttRx), abtRx, szRx, cut_message("Invalid received data"));
|
cut_assert_equal_memory(abtAttRx, sizeof(abtAttRx), abtRx, szRx, cut_message("Invalid received data"));
|
||||||
if (res <= 0) { thread_res = -1; return (void*) thread_res; }
|
if (res <= 0) { thread_res = -1; return (void *) thread_res; }
|
||||||
|
|
||||||
const uint8_t abtTx[] = "Hello DEP initiator!";
|
const uint8_t abtTx[] = "Hello DEP initiator!";
|
||||||
res = nfc_target_send_bytes(device, abtTx, sizeof(abtTx), 500);
|
res = nfc_target_send_bytes(device, abtTx, sizeof(abtTx), 500);
|
||||||
cut_assert_operator_int(res, > , 0, cut_message("Can't send bytes to initiator: %s", nfc_strerror(device)));
|
cut_assert_operator_int(res, > , 0, cut_message("Can't send bytes to initiator: %s", nfc_strerror(device)));
|
||||||
if (res <= 0) { thread_res = -1; return (void*) thread_res; }
|
if (res <= 0) { thread_res = -1; return (void *) thread_res; }
|
||||||
|
|
||||||
// Second pass
|
// Second pass
|
||||||
res = nfc_target_receive_bytes(device, abtRx, sizeof(abtRx), 500);
|
res = nfc_target_receive_bytes(device, abtRx, sizeof(abtRx), 500);
|
||||||
|
@ -106,11 +106,11 @@ target_thread(void *arg)
|
||||||
szRx = (size_t) res;
|
szRx = (size_t) res;
|
||||||
|
|
||||||
cut_assert_equal_memory(abtAttRx, sizeof(abtAttRx), abtRx, szRx, cut_message("Invalid received data"));
|
cut_assert_equal_memory(abtAttRx, sizeof(abtAttRx), abtRx, szRx, cut_message("Invalid received data"));
|
||||||
if (res <= 0) { thread_res = -1; return (void*) thread_res; }
|
if (res <= 0) { thread_res = -1; return (void *) thread_res; }
|
||||||
|
|
||||||
res = nfc_target_send_bytes(device, abtTx, sizeof(abtTx), 500);
|
res = nfc_target_send_bytes(device, abtTx, sizeof(abtTx), 500);
|
||||||
cut_assert_operator_int(res, > , 0, cut_message("Can't send bytes to initiator: %s", nfc_strerror(device)));
|
cut_assert_operator_int(res, > , 0, cut_message("Can't send bytes to initiator: %s", nfc_strerror(device)));
|
||||||
if (res <= 0) { thread_res = -1; return (void*) thread_res; }
|
if (res <= 0) { thread_res = -1; return (void *) thread_res; }
|
||||||
|
|
||||||
// Third pass
|
// Third pass
|
||||||
res = nfc_target_receive_bytes(device, abtRx, sizeof(abtRx), 500);
|
res = nfc_target_receive_bytes(device, abtRx, sizeof(abtRx), 500);
|
||||||
|
@ -118,11 +118,11 @@ target_thread(void *arg)
|
||||||
szRx = (size_t) res;
|
szRx = (size_t) res;
|
||||||
|
|
||||||
cut_assert_equal_memory(abtAttRx, sizeof(abtAttRx), abtRx, szRx, cut_message("Invalid received data"));
|
cut_assert_equal_memory(abtAttRx, sizeof(abtAttRx), abtRx, szRx, cut_message("Invalid received data"));
|
||||||
if (res <= 0) { thread_res = -1; return (void*) thread_res; }
|
if (res <= 0) { thread_res = -1; return (void *) thread_res; }
|
||||||
|
|
||||||
res = nfc_target_send_bytes(device, abtTx, sizeof(abtTx), 500);
|
res = nfc_target_send_bytes(device, abtTx, sizeof(abtTx), 500);
|
||||||
cut_assert_operator_int(res, > , 0, cut_message("Can't send bytes to initiator: %s", nfc_strerror(device)));
|
cut_assert_operator_int(res, > , 0, cut_message("Can't send bytes to initiator: %s", nfc_strerror(device)));
|
||||||
if (res <= 0) { thread_res = -1; return (void*) thread_res; }
|
if (res <= 0) { thread_res = -1; return (void *) thread_res; }
|
||||||
|
|
||||||
// Fourth pass
|
// Fourth pass
|
||||||
res = nfc_target_receive_bytes(device, abtRx, sizeof(abtRx), 500);
|
res = nfc_target_receive_bytes(device, abtRx, sizeof(abtRx), 500);
|
||||||
|
@ -130,11 +130,11 @@ target_thread(void *arg)
|
||||||
szRx = (size_t) res;
|
szRx = (size_t) res;
|
||||||
|
|
||||||
cut_assert_equal_memory(abtAttRx, sizeof(abtAttRx), abtRx, szRx, cut_message("Invalid received data"));
|
cut_assert_equal_memory(abtAttRx, sizeof(abtAttRx), abtRx, szRx, cut_message("Invalid received data"));
|
||||||
if (res <= 0) { thread_res = -1; return (void*) thread_res; }
|
if (res <= 0) { thread_res = -1; return (void *) thread_res; }
|
||||||
|
|
||||||
res = nfc_target_send_bytes(device, abtTx, sizeof(abtTx), 500);
|
res = nfc_target_send_bytes(device, abtTx, sizeof(abtTx), 500);
|
||||||
cut_assert_operator_int(res, > , 0, cut_message("Can't send bytes to initiator: %s", nfc_strerror(device)));
|
cut_assert_operator_int(res, > , 0, cut_message("Can't send bytes to initiator: %s", nfc_strerror(device)));
|
||||||
if (res <= 0) { thread_res = -1; return (void*) thread_res; }
|
if (res <= 0) { thread_res = -1; return (void *) thread_res; }
|
||||||
|
|
||||||
return (void *) thread_res;
|
return (void *) thread_res;
|
||||||
}
|
}
|
||||||
|
@ -154,7 +154,7 @@ initiator_thread(void *arg)
|
||||||
|
|
||||||
int res = nfc_initiator_init(device);
|
int res = nfc_initiator_init(device);
|
||||||
cut_assert_equal_int(0, res, cut_message("Can't initialize NFC device as initiator: %s", nfc_strerror(device)));
|
cut_assert_equal_int(0, res, cut_message("Can't initialize NFC device as initiator: %s", nfc_strerror(device)));
|
||||||
if (res < 0) { thread_res = -1; return (void*) thread_res; }
|
if (res < 0) { thread_res = -1; return (void *) thread_res; }
|
||||||
|
|
||||||
nfc_target nt;
|
nfc_target nt;
|
||||||
|
|
||||||
|
@ -167,7 +167,7 @@ initiator_thread(void *arg)
|
||||||
cut_assert_equal_memory("\x11\x22\x33\x44\x55\x66\x77\x88\x99\xAA", 10, nt.nti.ndi.abtNFCID3, 10, cut_message("Invalid target NFCID3"));
|
cut_assert_equal_memory("\x11\x22\x33\x44\x55\x66\x77\x88\x99\xAA", 10, nt.nti.ndi.abtNFCID3, 10, cut_message("Invalid target NFCID3"));
|
||||||
cut_assert_equal_int(NDM_PASSIVE, nt.nti.ndi.ndm, cut_message("Invalid target DEP mode"));
|
cut_assert_equal_int(NDM_PASSIVE, nt.nti.ndi.ndm, cut_message("Invalid target DEP mode"));
|
||||||
cut_assert_equal_memory("\x12\x34\x56\x78", 4, nt.nti.ndi.abtGB, nt.nti.ndi.szGB, cut_message("Invalid target general bytes"));
|
cut_assert_equal_memory("\x12\x34\x56\x78", 4, nt.nti.ndi.abtGB, nt.nti.ndi.szGB, cut_message("Invalid target general bytes"));
|
||||||
if (res <= 0) { thread_res = -1; return (void*) thread_res; }
|
if (res <= 0) { thread_res = -1; return (void *) thread_res; }
|
||||||
|
|
||||||
const uint8_t abtTx[] = "Hello DEP target!";
|
const uint8_t abtTx[] = "Hello DEP target!";
|
||||||
uint8_t abtRx[1024];
|
uint8_t abtRx[1024];
|
||||||
|
@ -177,11 +177,11 @@ initiator_thread(void *arg)
|
||||||
|
|
||||||
const uint8_t abtAttRx[] = "Hello DEP initiator!";
|
const uint8_t abtAttRx[] = "Hello DEP initiator!";
|
||||||
cut_assert_equal_memory(abtAttRx, sizeof(abtAttRx), abtRx, szRx, cut_message("Invalid received data"));
|
cut_assert_equal_memory(abtAttRx, sizeof(abtAttRx), abtRx, szRx, cut_message("Invalid received data"));
|
||||||
if (res < 0) { thread_res = -1; return (void*) thread_res; }
|
if (res < 0) { thread_res = -1; return (void *) thread_res; }
|
||||||
|
|
||||||
res = nfc_initiator_deselect_target(device);
|
res = nfc_initiator_deselect_target(device);
|
||||||
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 / 212Kbps (second pass)
|
// Passive mode / 212Kbps (second pass)
|
||||||
printf("=========== INITIATOR %s (Passive mode / 212Kbps) =========\n", nfc_device_get_name(device));
|
printf("=========== INITIATOR %s (Passive mode / 212Kbps) =========\n", nfc_device_get_name(device));
|
||||||
|
@ -192,18 +192,18 @@ initiator_thread(void *arg)
|
||||||
cut_assert_equal_memory("\x11\x22\x33\x44\x55\x66\x77\x88\x99\xAA", 10, nt.nti.ndi.abtNFCID3, 10, cut_message("Invalid target NFCID3"));
|
cut_assert_equal_memory("\x11\x22\x33\x44\x55\x66\x77\x88\x99\xAA", 10, nt.nti.ndi.abtNFCID3, 10, cut_message("Invalid target NFCID3"));
|
||||||
cut_assert_equal_int(NDM_PASSIVE, nt.nti.ndi.ndm, cut_message("Invalid target DEP mode"));
|
cut_assert_equal_int(NDM_PASSIVE, nt.nti.ndi.ndm, cut_message("Invalid target DEP mode"));
|
||||||
cut_assert_equal_memory("\x12\x34\x56\x78", 4, nt.nti.ndi.abtGB, nt.nti.ndi.szGB, cut_message("Invalid target general bytes"));
|
cut_assert_equal_memory("\x12\x34\x56\x78", 4, nt.nti.ndi.abtGB, nt.nti.ndi.szGB, cut_message("Invalid target general bytes"));
|
||||||
if (res <= 0) { thread_res = -1; return (void*) thread_res; }
|
if (res <= 0) { thread_res = -1; return (void *) thread_res; }
|
||||||
|
|
||||||
szRx = sizeof(abtRx);
|
szRx = sizeof(abtRx);
|
||||||
res = nfc_initiator_transceive_bytes(device, abtTx, sizeof(abtTx), abtRx, &szRx, 1000);
|
res = nfc_initiator_transceive_bytes(device, abtTx, sizeof(abtTx), abtRx, &szRx, 1000);
|
||||||
cut_assert_operator_int(res, >= , 0, cut_message("Can't transceive bytes to target: %s", nfc_strerror(device)));
|
cut_assert_operator_int(res, >= , 0, cut_message("Can't transceive bytes to target: %s", nfc_strerror(device)));
|
||||||
|
|
||||||
cut_assert_equal_memory(abtAttRx, sizeof(abtAttRx), abtRx, szRx, cut_message("Invalid received data"));
|
cut_assert_equal_memory(abtAttRx, sizeof(abtAttRx), abtRx, szRx, cut_message("Invalid received data"));
|
||||||
if (res < 0) { thread_res = -1; return (void*) thread_res; }
|
if (res < 0) { thread_res = -1; return (void *) thread_res; }
|
||||||
|
|
||||||
res = nfc_initiator_deselect_target(device);
|
res = nfc_initiator_deselect_target(device);
|
||||||
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 / 212Kbps
|
// Passive mode / 212Kbps
|
||||||
printf("=========== INITIATOR %s (Passive mode / 212Kbps, second pass) =========\n", nfc_device_get_name(device));
|
printf("=========== INITIATOR %s (Passive mode / 212Kbps, second pass) =========\n", nfc_device_get_name(device));
|
||||||
|
@ -214,18 +214,18 @@ initiator_thread(void *arg)
|
||||||
cut_assert_equal_memory("\x11\x22\x33\x44\x55\x66\x77\x88\x99\xAA", 10, nt.nti.ndi.abtNFCID3, 10, cut_message("Invalid target NFCID3"));
|
cut_assert_equal_memory("\x11\x22\x33\x44\x55\x66\x77\x88\x99\xAA", 10, nt.nti.ndi.abtNFCID3, 10, cut_message("Invalid target NFCID3"));
|
||||||
cut_assert_equal_int(NDM_PASSIVE, nt.nti.ndi.ndm, cut_message("Invalid target DEP mode"));
|
cut_assert_equal_int(NDM_PASSIVE, nt.nti.ndi.ndm, cut_message("Invalid target DEP mode"));
|
||||||
cut_assert_equal_memory("\x12\x34\x56\x78", 4, nt.nti.ndi.abtGB, nt.nti.ndi.szGB, cut_message("Invalid target general bytes"));
|
cut_assert_equal_memory("\x12\x34\x56\x78", 4, nt.nti.ndi.abtGB, nt.nti.ndi.szGB, cut_message("Invalid target general bytes"));
|
||||||
if (res <= 0) { thread_res = -1; return (void*) thread_res; }
|
if (res <= 0) { thread_res = -1; return (void *) thread_res; }
|
||||||
|
|
||||||
szRx = sizeof(abtRx);
|
szRx = sizeof(abtRx);
|
||||||
res = nfc_initiator_transceive_bytes(device, abtTx, sizeof(abtTx), abtRx, &szRx, 5000);
|
res = nfc_initiator_transceive_bytes(device, abtTx, sizeof(abtTx), abtRx, &szRx, 5000);
|
||||||
cut_assert_operator_int(res, >= , 0, cut_message("Can't transceive bytes to target: %s", nfc_strerror(device)));
|
cut_assert_operator_int(res, >= , 0, cut_message("Can't transceive bytes to target: %s", nfc_strerror(device)));
|
||||||
|
|
||||||
cut_assert_equal_memory(abtAttRx, sizeof(abtAttRx), abtRx, szRx, cut_message("Invalid received data"));
|
cut_assert_equal_memory(abtAttRx, sizeof(abtAttRx), abtRx, szRx, cut_message("Invalid received data"));
|
||||||
if (res < 0) { thread_res = -1; return (void*) thread_res; }
|
if (res < 0) { thread_res = -1; return (void *) thread_res; }
|
||||||
|
|
||||||
res = nfc_initiator_deselect_target(device);
|
res = nfc_initiator_deselect_target(device);
|
||||||
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));
|
||||||
|
@ -236,18 +236,18 @@ initiator_thread(void *arg)
|
||||||
cut_assert_equal_memory("\x11\x22\x33\x44\x55\x66\x77\x88\x99\xAA", 10, nt.nti.ndi.abtNFCID3, 10, cut_message("Invalid target NFCID3"));
|
cut_assert_equal_memory("\x11\x22\x33\x44\x55\x66\x77\x88\x99\xAA", 10, nt.nti.ndi.abtNFCID3, 10, cut_message("Invalid target NFCID3"));
|
||||||
cut_assert_equal_int(NDM_PASSIVE, nt.nti.ndi.ndm, cut_message("Invalid target DEP mode"));
|
cut_assert_equal_int(NDM_PASSIVE, nt.nti.ndi.ndm, cut_message("Invalid target DEP mode"));
|
||||||
cut_assert_equal_memory("\x12\x34\x56\x78", 4, nt.nti.ndi.abtGB, nt.nti.ndi.szGB, cut_message("Invalid target general bytes"));
|
cut_assert_equal_memory("\x12\x34\x56\x78", 4, nt.nti.ndi.abtGB, nt.nti.ndi.szGB, cut_message("Invalid target general bytes"));
|
||||||
if (res <= 0) { thread_res = -1; return (void*) thread_res; }
|
if (res <= 0) { thread_res = -1; return (void *) thread_res; }
|
||||||
|
|
||||||
szRx = sizeof(abtRx);
|
szRx = sizeof(abtRx);
|
||||||
res = nfc_initiator_transceive_bytes(device, abtTx, sizeof(abtTx), abtRx, &szRx, 5000);
|
res = nfc_initiator_transceive_bytes(device, abtTx, sizeof(abtTx), abtRx, &szRx, 5000);
|
||||||
cut_assert_operator_int(res, >= , 0, cut_message("Can't transceive bytes to target: %s", nfc_strerror(device)));
|
cut_assert_operator_int(res, >= , 0, cut_message("Can't transceive bytes to target: %s", nfc_strerror(device)));
|
||||||
|
|
||||||
cut_assert_equal_memory(abtAttRx, sizeof(abtAttRx), abtRx, szRx, cut_message("Invalid received data"));
|
cut_assert_equal_memory(abtAttRx, sizeof(abtAttRx), abtRx, szRx, cut_message("Invalid received data"));
|
||||||
if (res < 0) { thread_res = -1; return (void*) thread_res; }
|
if (res < 0) { thread_res = -1; return (void *) thread_res; }
|
||||||
|
|
||||||
res = nfc_initiator_deselect_target(device);
|
res = nfc_initiator_deselect_target(device);
|
||||||
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; }
|
||||||
|
|
||||||
return (void *) thread_res;
|
return (void *) thread_res;
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,7 +65,7 @@ target_thread(void *arg)
|
||||||
// 1) nfc_target_init should take target in idle mode
|
// 1) nfc_target_init should take target in idle mode
|
||||||
int res = nfc_target_init(device, &nt, abtRx, szRx, 500);
|
int res = nfc_target_init(device, &nt, abtRx, szRx, 500);
|
||||||
cut_assert_operator_int(res, >= , 0, cut_message("Can't initialize NFC device as target: %s", nfc_strerror(device)));
|
cut_assert_operator_int(res, >= , 0, cut_message("Can't initialize NFC device as 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; }
|
||||||
|
|
||||||
// 2) act as target
|
// 2) act as target
|
||||||
nfc_target nt1 = {
|
nfc_target nt1 = {
|
||||||
|
@ -91,7 +91,7 @@ target_thread(void *arg)
|
||||||
sleep(6);
|
sleep(6);
|
||||||
res = nfc_target_init(device, &nt1, abtRx, szRx, 0);
|
res = nfc_target_init(device, &nt1, abtRx, szRx, 0);
|
||||||
cut_assert_operator_int(res, > , 0, cut_message("Can't initialize NFC device as target: %s", nfc_strerror(device)));
|
cut_assert_operator_int(res, > , 0, cut_message("Can't initialize NFC device as 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; }
|
||||||
|
|
||||||
res = nfc_target_receive_bytes(device, abtRx, sizeof(abtRx), 500);
|
res = nfc_target_receive_bytes(device, abtRx, sizeof(abtRx), 500);
|
||||||
cut_assert_operator_int(res, > , 0, cut_message("Can't receive bytes from initiator: %s", nfc_strerror(device)));
|
cut_assert_operator_int(res, > , 0, cut_message("Can't receive bytes from initiator: %s", nfc_strerror(device)));
|
||||||
|
@ -99,12 +99,12 @@ target_thread(void *arg)
|
||||||
|
|
||||||
const uint8_t abtAttRx[] = "Hello DEP target!";
|
const uint8_t abtAttRx[] = "Hello DEP target!";
|
||||||
cut_assert_equal_memory(abtAttRx, sizeof(abtAttRx), abtRx, szRx, cut_message("Invalid received data"));
|
cut_assert_equal_memory(abtAttRx, sizeof(abtAttRx), abtRx, szRx, cut_message("Invalid received data"));
|
||||||
if (res <= 0) { thread_res = -1; return (void*) thread_res; }
|
if (res <= 0) { thread_res = -1; return (void *) thread_res; }
|
||||||
|
|
||||||
const uint8_t abtTx[] = "Hello DEP initiator!";
|
const uint8_t abtTx[] = "Hello DEP initiator!";
|
||||||
res = nfc_target_send_bytes(device, abtTx, sizeof(abtTx), 500);
|
res = nfc_target_send_bytes(device, abtTx, sizeof(abtTx), 500);
|
||||||
cut_assert_operator_int(res, > , 0, cut_message("Can't send bytes to initiator: %s", nfc_strerror(device)));
|
cut_assert_operator_int(res, > , 0, cut_message("Can't send bytes to initiator: %s", nfc_strerror(device)));
|
||||||
if (res <= 0) { thread_res = -1; return (void*) thread_res; }
|
if (res <= 0) { thread_res = -1; return (void *) thread_res; }
|
||||||
|
|
||||||
// 3) idle mode
|
// 3) idle mode
|
||||||
sleep(1);
|
sleep(1);
|
||||||
|
@ -128,13 +128,13 @@ initiator_thread(void *arg)
|
||||||
|
|
||||||
int res = nfc_initiator_init(device);
|
int res = nfc_initiator_init(device);
|
||||||
cut_assert_equal_int(0, res, cut_message("Can't initialize NFC device as initiator: %s", nfc_strerror(device)));
|
cut_assert_equal_int(0, res, cut_message("Can't initialize NFC device as initiator: %s", nfc_strerror(device)));
|
||||||
if (res < 0) { thread_res = -1; return (void*) thread_res; }
|
if (res < 0) { thread_res = -1; return (void *) thread_res; }
|
||||||
|
|
||||||
// 1) As other device should be in idle mode, nfc_initiator_poll_dep_target should return 0
|
// 1) As other device should be in idle mode, nfc_initiator_poll_dep_target should return 0
|
||||||
nfc_target nt;
|
nfc_target nt;
|
||||||
res = nfc_initiator_poll_dep_target(device, NDM_PASSIVE, NBR_106, NULL, &nt, 1000);
|
res = nfc_initiator_poll_dep_target(device, NDM_PASSIVE, NBR_106, NULL, &nt, 1000);
|
||||||
cut_assert_equal_int(0, res, cut_message("Problem with nfc_idle"));
|
cut_assert_equal_int(0, res, cut_message("Problem with nfc_idle"));
|
||||||
if (res != 0) { thread_res = -1; return (void*) thread_res; }
|
if (res != 0) { thread_res = -1; return (void *) thread_res; }
|
||||||
|
|
||||||
|
|
||||||
// 2 As other device should be in target mode, nfc_initiator_poll_dep_target should be positive.
|
// 2 As other device should be in target mode, nfc_initiator_poll_dep_target should be positive.
|
||||||
|
@ -149,7 +149,7 @@ initiator_thread(void *arg)
|
||||||
cut_assert_equal_memory("\x11\x22\x33\x44\x55\x66\x77\x88\x99\xAA", 10, nt1.nti.ndi.abtNFCID3, 10, cut_message("Invalid target NFCID3"));
|
cut_assert_equal_memory("\x11\x22\x33\x44\x55\x66\x77\x88\x99\xAA", 10, nt1.nti.ndi.abtNFCID3, 10, cut_message("Invalid target NFCID3"));
|
||||||
cut_assert_equal_int(NDM_PASSIVE, nt1.nti.ndi.ndm, cut_message("Invalid target DEP mode"));
|
cut_assert_equal_int(NDM_PASSIVE, nt1.nti.ndi.ndm, cut_message("Invalid target DEP mode"));
|
||||||
cut_assert_equal_memory("\x12\x34\x56\x78", 4, nt1.nti.ndi.abtGB, nt1.nti.ndi.szGB, cut_message("Invalid target general bytes"));
|
cut_assert_equal_memory("\x12\x34\x56\x78", 4, nt1.nti.ndi.abtGB, nt1.nti.ndi.szGB, cut_message("Invalid target general bytes"));
|
||||||
if (res <= 0) { thread_res = -1; return (void*) thread_res; }
|
if (res <= 0) { thread_res = -1; return (void *) thread_res; }
|
||||||
|
|
||||||
const uint8_t abtTx[] = "Hello DEP target!";
|
const uint8_t abtTx[] = "Hello DEP target!";
|
||||||
uint8_t abtRx[1024];
|
uint8_t abtRx[1024];
|
||||||
|
@ -159,17 +159,17 @@ initiator_thread(void *arg)
|
||||||
|
|
||||||
const uint8_t abtAttRx[] = "Hello DEP initiator!";
|
const uint8_t abtAttRx[] = "Hello DEP initiator!";
|
||||||
cut_assert_equal_memory(abtAttRx, sizeof(abtAttRx), abtRx, szRx, cut_message("Invalid received data"));
|
cut_assert_equal_memory(abtAttRx, sizeof(abtAttRx), abtRx, szRx, cut_message("Invalid received data"));
|
||||||
if (res < 0) { thread_res = -1; return (void*) thread_res; }
|
if (res < 0) { thread_res = -1; return (void *) thread_res; }
|
||||||
|
|
||||||
res = nfc_initiator_deselect_target(device);
|
res = nfc_initiator_deselect_target(device);
|
||||||
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; }
|
||||||
|
|
||||||
// 3) As other device should be in idle mode, nfc_initiator_poll_dep_target should return 0
|
// 3) As other device should be in idle mode, nfc_initiator_poll_dep_target should return 0
|
||||||
nfc_target nt2;
|
nfc_target nt2;
|
||||||
res = nfc_initiator_poll_dep_target(device, NDM_PASSIVE, NBR_106, NULL, &nt2, 1000);
|
res = nfc_initiator_poll_dep_target(device, NDM_PASSIVE, NBR_106, NULL, &nt2, 1000);
|
||||||
cut_assert_equal_int(0, res, cut_message("Problem with nfc_idle"));
|
cut_assert_equal_int(0, res, cut_message("Problem with nfc_idle"));
|
||||||
if (res != 0) { thread_res = -1; return (void*) thread_res; }
|
if (res != 0) { thread_res = -1; return (void *) thread_res; }
|
||||||
|
|
||||||
return (void *) thread_res;
|
return (void *) thread_res;
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,7 +59,7 @@
|
||||||
static nfc_device *pnd;
|
static nfc_device *pnd;
|
||||||
|
|
||||||
static void
|
static void
|
||||||
print_usage(const char* progname)
|
print_usage(const char *progname)
|
||||||
{
|
{
|
||||||
printf("usage: %s [-v]\n", progname);
|
printf("usage: %s [-v]\n", progname);
|
||||||
printf(" -v\t verbose display\n");
|
printf(" -v\t verbose display\n");
|
||||||
|
|
|
@ -63,7 +63,7 @@ static const nfc_modulation nmMifare = {
|
||||||
};
|
};
|
||||||
|
|
||||||
static void
|
static void
|
||||||
print_success_or_failure(bool bFailure, uint32_t * uiCounter)
|
print_success_or_failure(bool bFailure, uint32_t *uiCounter)
|
||||||
{
|
{
|
||||||
printf("%c", (bFailure) ? 'x' : '.');
|
printf("%c", (bFailure) ? 'x' : '.');
|
||||||
if (uiCounter)
|
if (uiCounter)
|
||||||
|
|
|
@ -60,7 +60,7 @@
|
||||||
static nfc_device *pnd;
|
static nfc_device *pnd;
|
||||||
|
|
||||||
static void
|
static void
|
||||||
print_usage(const char* progname)
|
print_usage(const char *progname)
|
||||||
{
|
{
|
||||||
printf("usage: %s [-v]\n", progname);
|
printf("usage: %s [-v]\n", progname);
|
||||||
printf(" -v\t verbose display\n");
|
printf(" -v\t verbose display\n");
|
||||||
|
|
|
@ -177,8 +177,8 @@ main(int argc, char *argv[])
|
||||||
print_usage(argv[0]);
|
print_usage(argv[0]);
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
FILE* message_stream = NULL;
|
FILE *message_stream = NULL;
|
||||||
FILE* ndef_stream = NULL;
|
FILE *ndef_stream = NULL;
|
||||||
|
|
||||||
if ((strlen(ndef_output) == 1) && (ndef_output[0] == '-')) {
|
if ((strlen(ndef_output) == 1) && (ndef_output[0] == '-')) {
|
||||||
message_stream = stderr;
|
message_stream = stderr;
|
||||||
|
@ -220,7 +220,7 @@ main(int argc, char *argv[])
|
||||||
|
|
||||||
int error = EXIT_SUCCESS;
|
int error = EXIT_SUCCESS;
|
||||||
// Polling payload (SENSF_REQ) must be present (see NFC Digital Protol)
|
// Polling payload (SENSF_REQ) must be present (see NFC Digital Protol)
|
||||||
const uint8_t *pbtSensfReq = (uint8_t*)"\x00\xff\xff\x01\x00";
|
const uint8_t *pbtSensfReq = (uint8_t *)"\x00\xff\xff\x01\x00";
|
||||||
if (nfc_initiator_select_passive_target(pnd, nm, pbtSensfReq, 5, &nt) < 0) {
|
if (nfc_initiator_select_passive_target(pnd, nm, pbtSensfReq, 5, &nt) < 0) {
|
||||||
nfc_perror(pnd, "nfc_initiator_select_passive_target");
|
nfc_perror(pnd, "nfc_initiator_select_passive_target");
|
||||||
error = EXIT_FAILURE;
|
error = EXIT_FAILURE;
|
||||||
|
@ -231,7 +231,7 @@ main(int argc, char *argv[])
|
||||||
const uint8_t abtNfcForumSysCode[] = { 0x12, 0xfc };
|
const uint8_t abtNfcForumSysCode[] = { 0x12, 0xfc };
|
||||||
if (0 != memcmp(nt.nti.nfi.abtSysCode, abtNfcForumSysCode, 2)) {
|
if (0 != memcmp(nt.nti.nfi.abtSysCode, abtNfcForumSysCode, 2)) {
|
||||||
// Retry with special polling
|
// Retry with special polling
|
||||||
const uint8_t *pbtSensfReqNfcForum = (uint8_t*)"\x00\x12\xfc\x01\x00";
|
const uint8_t *pbtSensfReqNfcForum = (uint8_t *)"\x00\x12\xfc\x01\x00";
|
||||||
if (nfc_initiator_select_passive_target(pnd, nm, pbtSensfReqNfcForum, 5, &nt) < 0) {
|
if (nfc_initiator_select_passive_target(pnd, nm, pbtSensfReqNfcForum, 5, &nt) < 0) {
|
||||||
nfc_perror(pnd, "nfc_initiator_select_passive_target");
|
nfc_perror(pnd, "nfc_initiator_select_passive_target");
|
||||||
error = EXIT_FAILURE;
|
error = EXIT_FAILURE;
|
||||||
|
|
|
@ -68,8 +68,8 @@ static bool quiet_output = false;
|
||||||
static bool initiator_only_mode = false;
|
static bool initiator_only_mode = false;
|
||||||
static bool target_only_mode = false;
|
static bool target_only_mode = false;
|
||||||
static int waiting_time = 0;
|
static int waiting_time = 0;
|
||||||
FILE * fd3;
|
FILE *fd3;
|
||||||
FILE * fd4;
|
FILE *fd4;
|
||||||
|
|
||||||
static void
|
static void
|
||||||
intr_hdlr(int sig)
|
intr_hdlr(int sig)
|
||||||
|
@ -336,7 +336,7 @@ main(int argc, char *argv[])
|
||||||
// PC/SC pseudo-ATR = 3B 80 80 01 01 if there is no historical bytes
|
// PC/SC pseudo-ATR = 3B 80 80 01 01 if there is no historical bytes
|
||||||
|
|
||||||
// Creates ATS and copy max 48 bytes of Tk:
|
// Creates ATS and copy max 48 bytes of Tk:
|
||||||
uint8_t * pbtTk;
|
uint8_t *pbtTk;
|
||||||
size_t szTk;
|
size_t szTk;
|
||||||
pbtTk = iso14443a_locate_historical_bytes(ntEmulatedTarget.nti.nai.abtAts, ntEmulatedTarget.nti.nai.szAtsLen, &szTk);
|
pbtTk = iso14443a_locate_historical_bytes(ntEmulatedTarget.nti.nai.abtAts, ntEmulatedTarget.nti.nai.szAtsLen, &szTk);
|
||||||
szTk = (szTk > 48) ? 48 : szTk;
|
szTk = (szTk > 48) ? 48 : szTk;
|
||||||
|
|
Loading…
Reference in a new issue