astyle --formatted --mode=c --indent=spaces=2 --indent-switches --indent-preprocessor --keep-one-line-blocks --max-instatement-indent=60

This commit is contained in:
Philippe Teuwen 2012-05-29 15:52:51 +00:00
parent 26569c2202
commit a2cd236441
45 changed files with 1096 additions and 1082 deletions

View file

@ -47,7 +47,7 @@
#define LOG_CATEGORY "libnfc.bus.uart"
# 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 };
# elif defined (__FreeBSD__) || defined (__OpenBSD__)
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
# define CCLAIMED 0x80000000
struct serial_port_unix{
struct serial_port_unix {
int fd; // Serial port file descriptor
struct termios termios_backup; // Terminal info before using the port
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.
speed_t stPortSpeed = B9600;
switch (uiPortSpeed) {
case 9600:
stPortSpeed = B9600;
break;
case 19200:
stPortSpeed = B19200;
break;
case 38400:
stPortSpeed = B38400;
break;
case 9600:
stPortSpeed = B9600;
break;
case 19200:
stPortSpeed = B19200;
break;
case 38400:
stPortSpeed = B38400;
break;
# ifdef B57600
case 57600:
stPortSpeed = B57600;
break;
case 57600:
stPortSpeed = B57600;
break;
# endif
# ifdef B115200
case 115200:
stPortSpeed = B115200;
break;
case 115200:
stPortSpeed = B115200;
break;
# endif
# ifdef B230400
case 230400:
stPortSpeed = B230400;
break;
case 230400:
stPortSpeed = B230400;
break;
# endif
# ifdef B460800
case 460800:
stPortSpeed = B460800;
break;
case 460800:
stPortSpeed = B460800;
break;
# endif
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).",
uiPortSpeed);
return;
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).",
uiPortSpeed);
return;
};
// Set port speed (Input and Output)
@ -191,34 +191,34 @@ uart_get_speed (serial_port sp)
{
uint32_t uiPortSpeed = 0;
switch (cfgetispeed (&UART_DATA(sp)->termios_new)) {
case B9600:
uiPortSpeed = 9600;
break;
case B19200:
uiPortSpeed = 19200;
break;
case B38400:
uiPortSpeed = 38400;
break;
case B9600:
uiPortSpeed = 9600;
break;
case B19200:
uiPortSpeed = 19200;
break;
case B38400:
uiPortSpeed = 38400;
break;
# ifdef B57600
case B57600:
uiPortSpeed = 57600;
break;
case B57600:
uiPortSpeed = 57600;
break;
# endif
# ifdef B115200
case B115200:
uiPortSpeed = 115200;
break;
case B115200:
uiPortSpeed = 115200;
break;
# endif
# ifdef B230400
case B230400:
uiPortSpeed = 230400;
break;
case B230400:
uiPortSpeed = 230400;
break;
# endif
# ifdef B460800
case B460800:
uiPortSpeed = 460800;
break;
case B460800:
uiPortSpeed = 460800;
break;
# endif
}
@ -335,38 +335,38 @@ uart_send (serial_port sp, const uint8_t *pbtTx, const size_t szTx, int timeout)
char **
uart_list_ports (void)
{
char **res = malloc (sizeof (char *));
size_t szRes = 1;
char **res = malloc (sizeof (char *));
size_t szRes = 1;
res[0] = NULL;
res[0] = NULL;
DIR *pdDir = opendir("/dev");
struct dirent *pdDirEnt;
while ((pdDirEnt = readdir(pdDir)) != NULL) {
if (!isdigit (pdDirEnt->d_name[strlen (pdDirEnt->d_name) - 1]))
continue;
DIR *pdDir = opendir("/dev");
struct dirent *pdDirEnt;
while ((pdDirEnt = readdir(pdDir)) != NULL) {
if (!isdigit (pdDirEnt->d_name[strlen (pdDirEnt->d_name) - 1]))
continue;
const char **p = serial_ports_device_radix;
while (*p) {
if (!strncmp(pdDirEnt->d_name, *p, strlen (*p))) {
char **res2 = realloc (res, (szRes+1) * sizeof (char *));
if (!res2)
goto oom;
const char **p = serial_ports_device_radix;
while (*p) {
if (!strncmp(pdDirEnt->d_name, *p, strlen (*p))) {
char **res2 = realloc (res, (szRes+1) * sizeof (char *));
if (!res2)
goto oom;
res = res2;
if (!(res[szRes-1] = malloc (6 + strlen (pdDirEnt->d_name))))
goto oom;
res = res2;
if (!(res[szRes-1] = malloc (6 + strlen (pdDirEnt->d_name))))
goto oom;
sprintf (res[szRes-1], "/dev/%s", pdDirEnt->d_name);
sprintf (res[szRes-1], "/dev/%s", pdDirEnt->d_name);
szRes++;
res[szRes-1] = NULL;
}
p++;
}
szRes++;
res[szRes-1] = NULL;
}
p++;
}
}
oom:
closedir (pdDir);
closedir (pdDir);
return res;
return res;
}

View file

@ -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);
// Set port speed (Input and Output)
switch (uiPortSpeed) {
case 9600:
case 19200:
case 38400:
case 57600:
case 115200:
case 230400:
case 460800:
break;
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);
return;
case 9600:
case 19200:
case 38400:
case 57600:
case 115200:
case 230400:
case 460800:
break;
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);
return;
};
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 {
log_put (LOG_CATEGORY, NFC_PRIORITY_TRACE, "ReadFile");
res = ReadFile (((struct serial_port_windows *) sp)->hPort, pbtRx + dwTotalBytesReceived,
dwBytesToGet,
&dwBytesReceived, NULL);
dwBytesToGet,
&dwBytesReceived, NULL);
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);
return NFC_EIO;
} else if (dwBytesReceived == 0) {
return NFC_ETIMEOUT;
}
return NFC_ETIMEOUT;
}
if (((DWORD)szRx) > dwTotalBytesReceived) {
dwBytesToGet -= dwBytesReceived;

View file

@ -133,13 +133,13 @@ typedef enum {
#else
# define PNCMD( X, Y ) { X , Y, #X }
# define PNCMD_TRACE( X ) do { \
for (size_t i=0; i<(sizeof(pn53x_commands)/sizeof(pn53x_command)); i++) { \
if ( X == pn53x_commands[i].ui8Code ) { \
log_put( LOG_CATEGORY, NFC_PRIORITY_TRACE, "%s", pn53x_commands[i].abtCommandText ); \
break; \
} \
} \
} while(0)
for (size_t i=0; i<(sizeof(pn53x_commands)/sizeof(pn53x_command)); i++) { \
if ( X == pn53x_commands[i].ui8Code ) { \
log_put( LOG_CATEGORY, NFC_PRIORITY_TRACE, "%s", pn53x_commands[i].abtCommandText ); \
break; \
} \
} \
} while(0)
#endif
static const pn53x_command pn53x_commands[] = {
@ -214,16 +214,16 @@ typedef struct {
#ifndef LOGGING
# define PNREG_TRACE( X ) do { \
} while(0)
} while(0)
#else
# define PNREG_TRACE( X ) do { \
for (size_t i=0; i<(sizeof(pn53x_registers)/sizeof(pn53x_register)); i++) { \
if ( X == pn53x_registers[i].ui16Address ) { \
log_put( LOG_CATEGORY, NFC_PRIORITY_TRACE, "%s (%s)", pn53x_registers[i].abtRegisterText, pn53x_registers[i].abtRegisterDescription ); \
break; \
} \
} \
} while(0)
for (size_t i=0; i<(sizeof(pn53x_registers)/sizeof(pn53x_register)); i++) { \
if ( X == pn53x_registers[i].ui16Address ) { \
log_put( LOG_CATEGORY, NFC_PRIORITY_TRACE, "%s (%s)", pn53x_registers[i].abtRegisterText, pn53x_registers[i].abtRegisterDescription ); \
break; \
} \
} \
} while(0)
#endif
// Register addresses

View file

@ -271,9 +271,9 @@ pn53x_transceive (struct nfc_device *pnd, const uint8_t *pbtTx, const size_t szT
res = NFC_ECHIP;
break;
};
/*
{ EMFAUTH, "Mifare Authentication Error" },
*/
/*
{ EMFAUTH, "Mifare Authentication Error" },
*/
if (res < 0) {
pnd->last_error = res;
@ -551,7 +551,7 @@ pn53x_decode_target_data (const uint8_t *pbtRawData, size_t szRawData, pn53x_typ
pbtRawData += 2;
memcpy (pnti->nji.btId, pbtRawData, 4);
break;
// Should not happend...
// Should not happend...
case NMT_DEP:
return NFC_ECHIP;
break;
@ -763,16 +763,16 @@ pn53x_set_property_int (struct nfc_device *pnd, const nfc_property property, con
switch (property) {
case NP_TIMEOUT_COMMAND:
CHIP_DATA (pnd)->timeout_command = value;
break;
break;
case NP_TIMEOUT_ATR:
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));
break;
break;
case NP_TIMEOUT_COM:
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));
break;
// Following properties are invalid (not integer)
// Following properties are invalid (not integer)
case NP_HANDLE_CRC:
case NP_HANDLE_PARITY:
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
// to "gain" a sort-of hardware polling (ie. like PN532 does)
if (pn53x_RFConfiguration__MaxRetries (pnd,
(bEnable) ? 0xff : 0x00, // MxRtyATR, default: active = 0xff, passive = 0x02
(bEnable) ? 0xff : 0x01, // MxRtyPSL, default: 0x01
(bEnable) ? 0xff : 0x02 // MxRtyPassiveActivation, default: 0xff (0x00 leads to problems with PN531)
) == 0)
(bEnable) ? 0xff : 0x00, // MxRtyATR, default: active = 0xff, passive = 0x02
(bEnable) ? 0xff : 0x01, // MxRtyPSL, default: 0x01
(bEnable) ? 0xff : 0x02 // MxRtyPassiveActivation, default: 0xff (0x00 leads to problems with PN531)
) == 0)
return NFC_SUCCESS;
}
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);
break;
// Following properties are invalid (not boolean)
// Following properties are invalid (not boolean)
case NP_TIMEOUT_COMMAND:
case NP_TIMEOUT_ATR:
case NP_TIMEOUT_COM:
@ -941,7 +941,7 @@ pn53x_idle (struct nfc_device *pnd)
return res;
}
}
break;
break;
case INITIATOR:
// Deselect all active communications
if ((res = pn53x_InDeselect (pnd, 0)) < 0) {
@ -962,9 +962,9 @@ pn53x_idle (struct nfc_device *pnd)
return res;
}
}
break;
break;
case IDLE: // Nothing to do.
break;
break;
};
CHIP_DATA (pnd)->operating_mode = IDLE;
return NFC_SUCCESS;
@ -1004,10 +1004,10 @@ pn53x_initiator_init (struct nfc_device *pnd)
static int
pn53x_initiator_select_passive_target_ext (struct nfc_device *pnd,
const nfc_modulation nm,
const uint8_t *pbtInitData, const size_t szInitData,
nfc_target *pnt,
int timeout)
const nfc_modulation nm,
const uint8_t *pbtInitData, const size_t szInitData,
nfc_target *pnt,
int timeout)
{
uint8_t abtTargetsData[PN53x_EXTENDED_FRAME__DATA_MAX_LEN];
size_t szTargetsData = sizeof (abtTargetsData);
@ -1118,9 +1118,9 @@ pn53x_initiator_select_passive_target (struct nfc_device *pnd,
int
pn53x_initiator_poll_target (struct nfc_device *pnd,
const nfc_modulation *pnmModulations, const size_t szModulations,
const uint8_t uiPollNr, const uint8_t uiPeriod,
nfc_target *pnt)
const nfc_modulation *pnmModulations, const size_t szModulations,
const uint8_t uiPollNr, const uint8_t uiPeriod,
nfc_target *pnt)
{
int res = 0;
@ -1155,7 +1155,7 @@ pn53x_initiator_poll_target (struct nfc_device *pnd,
break;
default:
return NFC_ECHIP;
break;
break;
}
} else {
pn53x_set_property_bool (pnd, NP_INFINITE_SELECT, true);
@ -1186,10 +1186,10 @@ pn53x_initiator_poll_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_info *pndiInitiator,
nfc_target *pnt,
const int timeout)
const nfc_dep_mode ndm, const nfc_baud_rate nbr,
const nfc_dep_info *pndiInitiator,
nfc_target *pnt,
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 * 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)
uint8_t abtRx[PN53x_EXTENDED_FRAME__DATA_MAX_LEN];
if ((res = pn53x_transceive (pnd, abtCmd, szTx + szExtraTxLen, abtRx, sizeof(abtRx), timeout)) < 0) {
pnd->last_error = res;
return pnd->last_error;
pnd->last_error = res;
return pnd->last_error;
}
const size_t szRxLen = (size_t)res - 1;
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 = 10 => precision: ~1.5us timer saturates at ~100ms
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 {
CHIP_DATA (pnd)->timer_prescaler = 0;
CHIP_DATA (pnd)->timer_prescaler = 0;
}
uint16_t reloadval = 0xFFFF;
// 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
parity = (last_cmd_byte >> 7) ^ ((last_cmd_byte >> 6) & 1) ^
((last_cmd_byte >> 5) & 1) ^ ((last_cmd_byte >> 4) & 1) ^
((last_cmd_byte >> 3) & 1) ^ ((last_cmd_byte >> 2) & 1) ^
((last_cmd_byte >> 1) & 1) ^ (last_cmd_byte & 1);
((last_cmd_byte >> 5) & 1) ^ ((last_cmd_byte >> 4) & 1) ^
((last_cmd_byte >> 3) & 1) ^ ((last_cmd_byte >> 2) & 1) ^
((last_cmd_byte >> 1) & 1) ^ (last_cmd_byte & 1);
parity = parity ? 0:1;
// When sent ...YY (cmd ends with logical 1, so when last parity bit is 1):
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);
}
}
break;
break;
case NMT_FELICA:
ptm = PTM_PASSIVE_ONLY;
break;
break;
case NMT_DEP:
pn53x_set_parameters (pnd, PARAM_AUTO_ATR_RES, true);
ptm = PTM_DEP_ONLY;
if (pnt->nti.ndi.ndm == NDM_PASSIVE) {
ptm |= PTM_PASSIVE_ONLY; // We add passive mode restriction
}
break;
break;
case NMT_ISO14443B:
case NMT_ISO14443BI:
case NMT_ISO14443B2SR:
@ -1694,7 +1694,7 @@ pn53x_target_init (struct nfc_device *pnd, nfc_target *pnt, uint8_t *pbtRx, cons
case NMT_JEWEL:
pnd->last_error = NFC_EDEVNOTSUPP;
return pnd->last_error;
break;
break;
}
// 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
memcpy(abtFeliCaParams+16, pnt->nti.nfi.abtSysCode, 2);
pbtFeliCaParams = abtFeliCaParams;
break;
break;
case NMT_DEP:
// Set NFCID3
@ -1788,7 +1788,7 @@ pn53x_target_init (struct nfc_device *pnd, nfc_target *pnt, uint8_t *pbtRx, cons
abtFeliCaParams[17] = 0xab;
pbtFeliCaParams = abtFeliCaParams;
break;
break;
case NMT_ISO14443B:
case NMT_ISO14443BI:
case NMT_ISO14443B2SR:
@ -1796,7 +1796,7 @@ pn53x_target_init (struct nfc_device *pnd, nfc_target *pnt, uint8_t *pbtRx, cons
case NMT_JEWEL:
pnd->last_error = NFC_EDEVNOTSUPP;
return pnd->last_error;
break;
break;
}
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
case 0x00: // 106kbps
nm.nbr = NBR_106;
break;
break;
case 0x10: // 212kbps
nm.nbr = NBR_212;
break;
break;
case 0x20: // 424kbps
nm.nbr = NBR_424;
break;
break;
};
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));
if (ptm & PTM_ISO14443_4_PICC_ONLY) {
// When PN532 is in PICC target mode, it automatically reply to RATS so
// we don't need to forward this command
// When PN532 is in PICC target mode, it automatically reply to RATS so
// we don't need to forward this command
szRx = 0;
}
}
@ -1943,7 +1943,7 @@ pn53x_target_receive_bytes (struct nfc_device *pnd, uint8_t *pbtRx, const size_t
return pnd->last_error;
}
}
// NO BREAK
// NO BREAK
case NMT_JEWEL:
case NMT_ISO14443B:
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;
}
}
// NO BREAK
// NO BREAK
case NMT_JEWEL:
case NMT_ISO14443B:
case NMT_ISO14443BI:
@ -2367,7 +2367,7 @@ pn53x_InAutoPoll (struct nfc_device *pnd,
uint8_t abtRx[PN53x_EXTENDED_FRAME__DATA_MAX_LEN];
size_t szRx = sizeof(abtRx);
int res = pn53x_transceive (pnd, abtCmd, szTxInAutoPoll, abtRx, szRx, timeout);
szRx = (size_t) res;
szRx = (size_t) res;
if (res < 0) {
return res;
} else if (szRx > 0) {
@ -2428,18 +2428,18 @@ pn53x_InJumpForDEP (struct nfc_device *pnd,
switch (nbr) {
case NBR_106:
abtCmd[2] = 0x00; // baud rate is 106 kbps
break;
break;
case NBR_212:
abtCmd[2] = 0x01; // baud rate is 212 kbps
break;
break;
case NBR_424:
abtCmd[2] = 0x02; // baud rate is 424 kbps
break;
break;
case NBR_847:
case NBR_UNDEFINED:
pnd->last_error = NFC_EINVARG;
return pnd->last_error;
break;
break;
}
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;
memcpy (abtCmd + offset, pbtPassiveInitiatorData, 4);
offset += 4;
break;
break;
case NBR_212:
case NBR_424:
abtCmd[3] |= 0x01;
memcpy (abtCmd + offset, pbtPassiveInitiatorData, 5);
offset += 5;
break;
break;
case NBR_847:
case NBR_UNDEFINED:
pnd->last_error = NFC_EINVARG;
return pnd->last_error;
break;
break;
}
}
@ -2677,54 +2677,54 @@ pn53x_nm_to_pm(const nfc_modulation nm)
switch(nm.nmt) {
case NMT_ISO14443A:
return PM_ISO14443A_106;
break;
break;
case NMT_ISO14443B:
switch(nm.nbr) {
case NBR_106:
return PM_ISO14443B_106;
break;
break;
case NBR_212:
return PM_ISO14443B_212;
break;
break;
case NBR_424:
return PM_ISO14443B_424;
break;
break;
case NBR_847:
return PM_ISO14443B_847;
break;
break;
case NBR_UNDEFINED:
// Nothing to do...
break;
break;
}
break;
break;
case NMT_JEWEL:
return PM_JEWEL_106;
break;
break;
case NMT_FELICA:
switch(nm.nbr) {
case NBR_212:
return PM_FELICA_212;
break;
break;
case NBR_424:
return PM_FELICA_424;
break;
break;
case NBR_106:
case NBR_847:
case NBR_UNDEFINED:
// Nothing to do...
break;
break;
}
break;
break;
case NMT_ISO14443BI:
case NMT_ISO14443B2SR:
case NMT_ISO14443B2CT:
case NMT_DEP:
// Nothing to do...
break;
break;
}
return PM_UNDEFINED;
}
@ -2738,44 +2738,44 @@ pn53x_ptt_to_nm( const pn53x_target_type ptt )
case PTT_GENERIC_PASSIVE_424:
case PTT_UNDEFINED:
// XXX This should not happend, how handle it cleanly ?
break;
break;
case PTT_MIFARE:
case PTT_ISO14443_4A_106:
return (const nfc_modulation){ .nmt = NMT_ISO14443A, .nbr = NBR_106 };
break;
return (const nfc_modulation) { .nmt = NMT_ISO14443A, .nbr = NBR_106 };
break;
case PTT_ISO14443_4B_106:
case PTT_ISO14443_4B_TCL_106:
return (const nfc_modulation){ .nmt = NMT_ISO14443B, .nbr = NBR_106 };
break;
return (const nfc_modulation) { .nmt = NMT_ISO14443B, .nbr = NBR_106 };
break;
case PTT_JEWEL_106:
return (const nfc_modulation){ .nmt = NMT_JEWEL, .nbr = NBR_106 };
break;
return (const nfc_modulation) { .nmt = NMT_JEWEL, .nbr = NBR_106 };
break;
case PTT_FELICA_212:
return (const nfc_modulation){ .nmt = NMT_FELICA, .nbr = NBR_212 };
break;
return (const nfc_modulation) { .nmt = NMT_FELICA, .nbr = NBR_212 };
break;
case PTT_FELICA_424:
return (const nfc_modulation){ .nmt = NMT_FELICA, .nbr = NBR_424 };
break;
return (const nfc_modulation) { .nmt = NMT_FELICA, .nbr = NBR_424 };
break;
case PTT_DEP_PASSIVE_106:
case PTT_DEP_ACTIVE_106:
return (const nfc_modulation){ .nmt = NMT_DEP, .nbr = NBR_106 };
break;
return (const nfc_modulation) { .nmt = NMT_DEP, .nbr = NBR_106 };
break;
case PTT_DEP_PASSIVE_212:
case PTT_DEP_ACTIVE_212:
return (const nfc_modulation){ .nmt = NMT_DEP, .nbr = NBR_212 };
break;
return (const nfc_modulation) { .nmt = NMT_DEP, .nbr = NBR_212 };
break;
case PTT_DEP_PASSIVE_424:
case PTT_DEP_ACTIVE_424:
return (const nfc_modulation){ .nmt = NMT_DEP, .nbr = NBR_424 };
break;
return (const nfc_modulation) { .nmt = NMT_DEP, .nbr = NBR_424 };
break;
}
// 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
@ -2785,48 +2785,48 @@ pn53x_nm_to_ptt(const nfc_modulation nm)
case NMT_ISO14443A:
return PTT_MIFARE;
// return PTT_ISO14443_4A_106;
break;
break;
case NMT_ISO14443B:
switch(nm.nbr) {
case NBR_106:
return PTT_ISO14443_4B_106;
break;
break;
case NBR_UNDEFINED:
case NBR_212:
case NBR_424:
case NBR_847:
// Nothing to do...
break;
break;
}
break;
break;
case NMT_JEWEL:
return PTT_JEWEL_106;
break;
break;
case NMT_FELICA:
switch(nm.nbr) {
case NBR_212:
return PTT_FELICA_212;
break;
break;
case NBR_424:
return PTT_FELICA_424;
break;
break;
case NBR_UNDEFINED:
case NBR_106:
case NBR_847:
// Nothing to do...
break;
break;
}
break;
break;
case NMT_ISO14443BI:
case NMT_ISO14443B2SR:
case NMT_ISO14443B2CT:
case NMT_DEP:
// Nothing to do...
break;
break;
}
return PTT_UNDEFINED;
}
@ -2837,10 +2837,10 @@ pn53x_get_supported_modulation(nfc_device *pnd, const nfc_mode mode, const nfc_m
switch (mode) {
case N_TARGET:
*supported_mt = CHIP_DATA(pnd)->supported_modulation_as_target;
break;
break;
case N_INITIATOR:
*supported_mt = CHIP_DATA(pnd)->supported_modulation_as_initiator;
break;
break;
default:
return NFC_EINVARG;
}
@ -2853,10 +2853,10 @@ pn53x_get_supported_baud_rate (nfc_device *pnd, const nfc_modulation_type nmt, c
switch (nmt) {
case NMT_FELICA:
*supported_br = (nfc_baud_rate*)pn53x_felica_supported_baud_rates;
break;
break;
case NMT_ISO14443A:
*supported_br = (nfc_baud_rate*)pn53x_iso14443a_supported_baud_rates;
break;
break;
case NMT_ISO14443B:
case NMT_ISO14443BI:
case NMT_ISO14443B2SR:
@ -2871,10 +2871,10 @@ pn53x_get_supported_baud_rate (nfc_device *pnd, const nfc_modulation_type nmt, c
break;
case NMT_JEWEL:
*supported_br = (nfc_baud_rate*)pn53x_jewel_supported_baud_rates;
break;
break;
case NMT_DEP:
*supported_br = (nfc_baud_rate*)pn53x_dep_supported_baud_rates;
break;
break;
default:
return NFC_EINVARG;
}

View file

@ -155,41 +155,41 @@ struct pn53x_io {
* @brief PN53x data structure
*/
struct pn53x_data {
/** Chip type (PN531, PN532 or PN533) */
/** Chip type (PN531, PN532 or PN533) */
pn53x_type type;
/** Chip firmware text */
/** Chip firmware text */
char firmware_text[22];
/** Current power mode */
/** Current power mode */
pn53x_power_mode power_mode;
/** Current operating mode */
/** Current operating mode */
pn53x_operating_mode operating_mode;
/** Current emulated target */
/** Current emulated target */
nfc_target *current_target;
/** PN53x I/O functions stored in struct */
/** PN53x I/O functions stored in struct */
const struct pn53x_io *io;
/** Last status byte returned by PN53x */
/** Last status byte returned by PN53x */
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;
/** Register cache for SetParameters function. */
/** Register cache for SetParameters function. */
uint8_t ui8Parameters;
/** Last sent command */
/** Last sent command */
uint8_t last_command;
/** Interframe timer correction */
/** Interframe timer correction */
int16_t timer_correction;
/** Timer prescaler */
/** Timer prescaler */
uint16_t timer_prescaler;
/** WriteBack cache */
/** WriteBack cache */
uint8_t wb_data[PN53X_CACHE_REGISTER_SIZE];
uint8_t wb_mask[PN53X_CACHE_REGISTER_SIZE];
bool wb_trigged;
/** Command timeout */
/** Command timeout */
int timeout_command;
/** ATR timeout */
/** ATR timeout */
int timeout_atr;
/** Communication timeout */
/** Communication timeout */
int timeout_communication;
/** Supported modulation type */
/** Supported modulation type */
nfc_modulation_type *supported_modulation_as_initiator;
nfc_modulation_type *supported_modulation_as_target;
};
@ -203,21 +203,21 @@ struct pn53x_data {
typedef enum {
/** Undefined modulation */
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,
/** 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,
/** 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,
/** 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,
/** Jewel Topaz (Innovision Research & Development) (Not supported by PN531) */
/** Jewel Topaz (Innovision Research & Development) (Not supported by PN531) */
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,
/** 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,
/** 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,
} 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_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,
pn53x_type chip_type, nfc_modulation_type nmt,
nfc_target_info *pnti);
pn53x_type chip_type, nfc_modulation_type nmt,
nfc_target_info *pnti);
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_decode_firmware_version (struct nfc_device *pnd);
@ -313,26 +313,26 @@ int pn53x_idle (struct nfc_device *pnd);
// NFC device as Initiator functions
int pn53x_initiator_init (struct nfc_device *pnd);
int pn53x_initiator_select_passive_target (struct nfc_device *pnd,
const nfc_modulation nm,
const uint8_t *pbtInitData, const size_t szInitData,
nfc_target *pnt);
const nfc_modulation nm,
const uint8_t *pbtInitData, const size_t szInitData,
nfc_target *pnt);
int pn53x_initiator_poll_target (struct nfc_device *pnd,
const nfc_modulation *pnmModulations, const size_t szModulations,
const uint8_t uiPollNr, const uint8_t uiPeriod,
nfc_target *pnt);
const nfc_modulation *pnmModulations, const size_t szModulations,
const uint8_t uiPollNr, const uint8_t uiPeriod,
nfc_target *pnt);
int pn53x_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);
const nfc_dep_mode ndm, const nfc_baud_rate nbr,
const nfc_dep_info *pndiInitiator,
nfc_target *pnt,
const int timeout);
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,
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,
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,
uint8_t *pbtRx, uint32_t *cycles);
uint8_t *pbtRx, uint32_t *cycles);
int pn53x_initiator_deselect_target (struct nfc_device *pnd);
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_PowerDown (struct nfc_device *pnd);
int pn53x_InListPassiveTarget (struct nfc_device *pnd, const pn53x_modulation pmInitModulation,
const uint8_t szMaxTargets, const uint8_t *pbtInitiatorData,
const size_t szInitiatorDataLen, uint8_t *pbtTargetsData, size_t *pszTargetsData,
int timeout);
const uint8_t szMaxTargets, const uint8_t *pbtInitiatorData,
const size_t szInitiatorDataLen, uint8_t *pbtTargetsData, size_t *pszTargetsData,
int timeout);
int pn53x_InDeselect (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,
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);
int pn53x_InJumpForDEP (struct nfc_device *pnd,
const nfc_dep_mode ndm, const nfc_baud_rate nbr,
const uint8_t *pbtPassiveInitiatorData,
const uint8_t *pbtNFCID3i,
const uint8_t *pbtGB, const size_t szGB,
nfc_target *pnt,
const int timeout);
const nfc_dep_mode ndm, const nfc_baud_rate nbr,
const uint8_t *pbtPassiveInitiatorData,
const uint8_t *pbtNFCID3i,
const uint8_t *pbtGB, const size_t szGB,
nfc_target *pnt,
const int timeout);
int pn53x_TgInitAsTarget (struct nfc_device *pnd, pn53x_target_mode ptm,
const uint8_t *pbtMifareParams,
const uint8_t *pbtTkt, size_t szTkt,
const uint8_t *pbtFeliCaParams,
const uint8_t *pbtNFCID3t, const uint8_t *pbtGB, const size_t szGB,
uint8_t *pbtRx, const size_t szRxLen, uint8_t *pbtModeByte, int timeout);
const uint8_t *pbtMifareParams,
const uint8_t *pbtTkt, size_t szTkt,
const uint8_t *pbtFeliCaParams,
const uint8_t *pbtNFCID3t, const uint8_t *pbtGB, const size_t szGB,
uint8_t *pbtRx, const size_t szRxLen, uint8_t *pbtModeByte, int timeout);
// RFConfiguration
int pn53x_RFConfiguration__RF_field (struct nfc_device *pnd, bool bEnable);

View file

@ -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) {
/*
* Check the MCU response
*/
/*
* Check the MCU response
*/
// Make sure we received the byte-count we expected
if (dwRxLen != 2) {

View file

@ -56,15 +56,15 @@ Thanks to d18c7db and Okko for example code
#include <errno.h>
#ifndef _WIN32
// Under POSIX system, we use libusb (>= 0.1.12)
#include <usb.h>
#define USB_TIMEDOUT ETIMEDOUT
#define _usb_strerror( X ) strerror(-X)
// Under POSIX system, we use libusb (>= 0.1.12)
#include <usb.h>
#define USB_TIMEDOUT ETIMEDOUT
#define _usb_strerror( X ) strerror(-X)
#else
// Under Windows we use libusb-win32 (>= 1.2.5)
#include <lusb0_usb.h>
#define USB_TIMEDOUT 116
#define _usb_strerror( X ) usb_strerror()
// Under Windows we use libusb-win32 (>= 1.2.5)
#include <lusb0_usb.h>
#define USB_TIMEDOUT 116
#define _usb_strerror( X ) usb_strerror()
#endif
#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++) {
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;
}
@ -363,7 +363,7 @@ acr122_usb_open (const nfc_connstring connstring)
for (dev = bus->devices; dev; dev = dev->next) {
if (connstring_decode_level > 2) {
// A specific dev have been specified
if (0 != strcmp (dev->filename, desc.filename))
if (0 != strcmp (dev->filename, desc.filename))
continue;
}
// Open the USB device
@ -401,7 +401,7 @@ acr122_usb_open (const nfc_connstring connstring)
pn53x_data_new (pnd, &acr122_usb_io);
switch (DRIVER_DATA (pnd)->model) {
// empirical tuning
// empirical tuning
case ACR122:
CHIP_DATA (pnd)->timer_correction = 46;
break;

View file

@ -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)
return ret;
if (memcmp(ack, positive_ack, 4) != 0){
pnd->last_error = NFC_EIO;
return pnd->last_error;
}
if (memcmp(ack, positive_ack, 4) != 0) {
pnd->last_error = NFC_EIO;
return pnd->last_error;
}
struct xfr_block_req *req = (struct xfr_block_req *) &frame[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)
{
if (frame_size < 13)
{ pnd->last_error = NFC_EINVARG;
{ pnd->last_error = NFC_EINVARG;
return pnd->last_error;
}
}
int ret;
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;
// Is buffer sufficient to store response?
if (frame_size < FRAME_SIZE(frame)){
if (frame_size < FRAME_SIZE(frame)) {
pnd->last_error = NFC_EIO;
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
le32(uint32_t val) {
uint32_t res;
uint8_t *p = (uint8_t *) &res;
p[0] = val;
p[1] = val >> 8;
p[2] = val >> 16;
p[3] = val >> 24;
return res;
uint32_t res;
uint8_t *p = (uint8_t *) &res;
p[0] = val;
p[1] = val >> 8;
p[2] = val >> 16;
p[3] = val >> 24;
return res;
}
/**
@ -311,8 +311,8 @@ le32(uint32_t val) {
*/
static bool
acr122s_build_frame(nfc_device *pnd,
uint8_t *frame, size_t frame_size, uint8_t p1, uint8_t p2,
const uint8_t *data, size_t data_size, int should_prefix)
uint8_t *frame, size_t frame_size, uint8_t p1, uint8_t p2,
const uint8_t *data, size_t data_size, int should_prefix)
{
if (frame_size < data_size + APDU_OVERHEAD + should_prefix)
return false;
@ -333,7 +333,7 @@ acr122s_build_frame(nfc_device *pnd,
header->ins = 0;
header->p1 = p1;
header->p2 = p2;
header->length = data_size + should_prefix;
header->length = data_size + should_prefix;
uint8_t *buf = (uint8_t *) &frame[16];
if (should_prefix)
@ -480,7 +480,7 @@ acr122s_probe(nfc_connstring connstrings[], size_t connstrings_len, size_t *pszD
#else /* SERIAL_AUTOPROBE_ENABLED */
*pszDeviceFound = 0;
serial_port sp;
serial_port sp;
char **acPorts = uart_list_ports ();
const char *acPort;
int iDevice = 0;
@ -560,17 +560,17 @@ acr122s_open(const nfc_connstring connstring)
}
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);
if (sp == INVALID_SERIAL_PORT) {
log_put(LOG_CATEGORY, NFC_PRIORITY_ERROR,
"Invalid serial port: %s", ndd.port);
"Invalid serial port: %s", ndd.port);
return NULL;
}
if (sp == CLAIMED_SERIAL_PORT) {
log_put(LOG_CATEGORY, NFC_PRIORITY_ERROR,
"Serial port already claimed: %s", ndd.port);
"Serial port already claimed: %s", ndd.port);
return NULL;
}
@ -607,7 +607,7 @@ acr122s_open(const nfc_connstring connstring)
if (strncmp(version, "ACR122S", 7) != 0) {
log_put(LOG_CATEGORY, NFC_PRIORITY_ERROR, "Invalid firmware version: %s",
version);
version);
acr122s_close(pnd);
return NULL;
}

View file

@ -314,7 +314,7 @@ pn532_uart_send (nfc_device *pnd, const uint8_t *pbtData, const size_t szData, i
break;
case NORMAL:
// Nothing to do :)
break;
break;
};
uint8_t abtFrame[PN532_BUFFER_LEN] = { 0x00, 0x00, 0xff }; // Every packet must start with "00 00 ff"

View file

@ -39,15 +39,15 @@ Thanks to d18c7db and Okko for example code
#include <errno.h>
#ifndef _WIN32
// Under POSIX system, we use libusb (>= 0.1.12)
#include <usb.h>
#define USB_TIMEDOUT ETIMEDOUT
#define _usb_strerror( X ) strerror(-X)
// Under POSIX system, we use libusb (>= 0.1.12)
#include <usb.h>
#define USB_TIMEDOUT ETIMEDOUT
#define _usb_strerror( X ) strerror(-X)
#else
// Under Windows we use libusb-win32 (>= 1.2.5)
#include <lusb0_usb.h>
#define USB_TIMEDOUT 116
#define _usb_strerror( X ) usb_strerror()
// Under Windows we use libusb-win32 (>= 1.2.5)
#include <lusb0_usb.h>
#define USB_TIMEDOUT 116
#define _usb_strerror( X ) usb_strerror()
#endif
#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++) {
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;
}
@ -354,7 +354,7 @@ pn53x_usb_open (const nfc_connstring connstring)
for (dev = bus->devices; dev; dev = dev->next) {
if (connstring_decode_level > 2) {
// A specific dev have been specified
if (0 != strcmp (dev->filename, desc.filename))
if (0 != strcmp (dev->filename, desc.filename))
continue;
}
// Open the USB device
@ -392,7 +392,7 @@ pn53x_usb_open (const nfc_connstring connstring)
pn53x_data_new (pnd, &pn53x_usb_io);
switch (DRIVER_DATA (pnd)->model) {
// empirical tuning
// empirical tuning
case ASK_LOGO:
CHIP_DATA (pnd)->timer_correction = 50;
break;
@ -684,23 +684,23 @@ pn53x_usb_init (nfc_device *pnd)
/* Setup push-pulls for pins from P30 to P35 */
pn53x_write_register (pnd, PN53X_SFR_P3CFGB, 0xFF, 0x37);
/*
On ASK LoGO hardware:
LEDs port bits definition:
* LED 1: bit 2 (P32)
* LED 2: bit 1 (P31)
* LED 3: bit 0 or 3 (depending of hardware revision) (P30 or P33)
* LED 4: bit 5 (P35)
Notes:
* 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.
/*
On ASK LoGO hardware:
LEDs port bits definition:
* LED 1: bit 2 (P32)
* LED 2: bit 1 (P31)
* LED 3: bit 0 or 3 (depending of hardware revision) (P30 or P33)
* LED 4: bit 5 (P35)
Notes:
* 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.
Progressive field activation:
The ASK LoGO hardware can progressively power-up the antenna.
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
field by switching off the field on PN533 then set P34 to '0'.
*/
Progressive field activation:
The ASK LoGO hardware can progressively power-up the antenna.
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
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 */
/* ie. Switch LED1 on and turn off progressive field */

View file

@ -17,10 +17,10 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
/**
* @file iso14443-subr.c
* @brief Defines some function extracted for ISO/IEC 14443
*/
/**
* @file iso14443-subr.c
* @brief Defines some function extracted for ISO/IEC 14443
*/
#ifdef HAVE_CONFIG_H
# include "config.h"

View file

@ -17,10 +17,10 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
/**
* @file iso7816.h
* @brief Defines some macros extracted for ISO/IEC 7816-4
*/
/**
* @file iso7816.h
* @brief Defines some macros extracted for ISO/IEC 7816-4
*/
#ifndef __LIBNFC_ISO7816_H__
#define __LIBNFC_ISO7816_H__

View file

@ -32,43 +32,43 @@
# define __has_attribute_format 1
# endif
// User want debug features
#define LOGGING 1
int log_init (void);
int log_fini (void);
void log_put (const char *category, const char *priority, const char *format, ...)
// User want debug features
#define LOGGING 1
int log_init (void);
int log_fini (void);
void log_put (const char *category, const char *priority, const char *format, ...)
# if __has_attribute_format
__attribute__((format(printf, 3, 4)))
__attribute__((format(printf, 3, 4)))
# endif
;
;
#define NFC_PRIORITY_FATAL "fatal"
#define NFC_PRIORITY_ALERT "alert"
#define NFC_PRIORITY_CRIT "critical"
#define NFC_PRIORITY_ERROR "error"
#define NFC_PRIORITY_WARN "warning"
#define NFC_PRIORITY_NOTICE "notice"
#define NFC_PRIORITY_INFO "info"
#define NFC_PRIORITY_DEBUG "debug"
#define NFC_PRIORITY_TRACE "trace"
#define NFC_PRIORITY_FATAL "fatal"
#define NFC_PRIORITY_ALERT "alert"
#define NFC_PRIORITY_CRIT "critical"
#define NFC_PRIORITY_ERROR "error"
#define NFC_PRIORITY_WARN "warning"
#define NFC_PRIORITY_NOTICE "notice"
#define NFC_PRIORITY_INFO "info"
#define NFC_PRIORITY_DEBUG "debug"
#define NFC_PRIORITY_TRACE "trace"
#else
// No logging
#define log_init() ((void) 0)
#define log_fini() ((void) 0)
#define log_msg(category, priority, message) do {} while (0)
#define log_set_appender(category, appender) do {} while (0)
#define log_put(category, priority, format, ...) do {} while (0)
// No logging
#define log_init() ((void) 0)
#define log_fini() ((void) 0)
#define log_msg(category, priority, message) do {} while (0)
#define log_set_appender(category, appender) do {} while (0)
#define log_put(category, priority, format, ...) do {} while (0)
#define NFC_PRIORITY_FATAL 8
#define NFC_PRIORITY_ALERT 7
#define NFC_PRIORITY_CRIT 6
#define NFC_PRIORITY_ERROR 5
#define NFC_PRIORITY_WARN 4
#define NFC_PRIORITY_NOTICE 3
#define NFC_PRIORITY_INFO 2
#define NFC_PRIORITY_DEBUG 1
#define NFC_PRIORITY_TRACE 0
#define NFC_PRIORITY_FATAL 8
#define NFC_PRIORITY_ALERT 7
#define NFC_PRIORITY_CRIT 6
#define NFC_PRIORITY_ERROR 5
#define NFC_PRIORITY_WARN 4
#define NFC_PRIORITY_NOTICE 3
#define NFC_PRIORITY_INFO 2
#define NFC_PRIORITY_DEBUG 1
#define NFC_PRIORITY_TRACE 0
#endif /* HAS_LOG4C, DEBUG */
/**

View file

@ -17,10 +17,10 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
/**
* @file mirror-subr.c
* @brief Mirror bytes
*/
/**
* @file mirror-subr.c
* @brief Mirror bytes
*/
#ifdef HAVE_CONFIG_H
# include "config.h"

View file

@ -17,10 +17,10 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
/**
* @file nfc-device.c
* @brief Provide internal function to manipulate nfc_device type
*/
/**
* @file nfc-device.c
* @brief Provide internal function to manipulate nfc_device type
*/
/* vim:set et sw=2 ts=2: */

View file

@ -17,10 +17,10 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
/**
* @file nfc-emulation.c
* @brief Provide a small API to ease emulation in libnfc
*/
/**
* @file nfc-emulation.c
* @brief Provide a small API to ease emulation in libnfc
*/
#include <nfc/nfc.h>
#include <nfc/nfc-emulation.h>

View file

@ -17,10 +17,10 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
/**
* @file nfc-internal.c
* @brief Provide some useful internal functions
*/
/**
* @file nfc-internal.c
* @brief Provide some useful internal functions
*/
#include <nfc/nfc.h>
#include "nfc-internal.h"
@ -64,6 +64,6 @@ prepare_initiator_data (const nfc_modulation nm, uint8_t **ppbtInitiatorData, si
case NMT_DEP:
*ppbtInitiatorData = NULL;
*pszInitiatorData = 0;
break;
break;
}
}

View file

@ -73,16 +73,16 @@
* Initialise a buffer named buffer_name of size bytes.
*/
#define BUFFER_INIT(buffer_name, size) \
uint8_t buffer_name[size]; \
size_t __##buffer_name##_n = 0
uint8_t buffer_name[size]; \
size_t __##buffer_name##_n = 0
/*
* Create a wrapper for an existing buffer.
* BEWARE! It eats children!
*/
#define BUFFER_ALIAS(buffer_name, origin) \
uint8_t *buffer_name = (void *)origin; \
size_t __##buffer_name##_n = 0;
uint8_t *buffer_name = (void *)origin; \
size_t __##buffer_name##_n = 0;
#define BUFFER_SIZE(buffer_name) (__##buffer_name##_n)
@ -91,20 +91,20 @@
* Append one byte of data to the buffer buffer_name.
*/
#define BUFFER_APPEND(buffer_name, data) \
do { \
buffer_name[__##buffer_name##_n++] = data; \
} while (0)
do { \
buffer_name[__##buffer_name##_n++] = data; \
} while (0)
/*
* Append size bytes of data to the buffer buffer_name.
*/
#define BUFFER_APPEND_BYTES(buffer_name, data, size) \
do { \
size_t __n = 0; \
while (__n < size) { \
buffer_name[__##buffer_name##_n++] = ((uint8_t *)data)[__n++]; \
} \
} while (0)
do { \
size_t __n = 0; \
while (__n < size) { \
buffer_name[__##buffer_name##_n++] = ((uint8_t *)data)[__n++]; \
} \
} while (0)
/*
* 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)
#define BUFFER_APPEND_LE(buffer, data, data_size, field_size) \
do { \
size_t __data_size = data_size; \
size_t __field_size = field_size; \
while (__field_size--, __data_size--) { \
buffer[__##buffer##_n++] = ((uint8_t *)&data)[__field_size]; \
} \
} while (0)
do { \
size_t __data_size = data_size; \
size_t __field_size = field_size; \
while (__field_size--, __data_size--) { \
buffer[__##buffer##_n++] = ((uint8_t *)&data)[__field_size]; \
} \
} while (0)
#else
#define BUFFER_APPEND_LE(buffer, data, data_size, field_size) \
do { \
memcpy (buffer + __##buffer##_n, &data, data_size); \
__##buffer##_n += data_size; \
} while (0)
do { \
memcpy (buffer + __##buffer##_n, &data, data_size); \
__##buffer##_n += data_size; \
} while (0)
#endif
@ -179,22 +179,22 @@ struct nfc_device {
void *driver_data;
void *chip_data;
/** Device name string, including device wrapper firmware */
/** Device name string, including device wrapper firmware */
char name[DEVICE_NAME_LENGTH];
/** Device connection string */
/** Device connection string */
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;
/** 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;
/** Should the chip handle frames encapsulation and chaining */
/** Should the chip handle frames encapsulation and chaining */
bool bEasyFraming;
/** Should the chip switch automatically activate ISO14443-4 when
selecting tags supporting it? */
/** Should the chip switch automatically activate ISO14443-4 when
selecting tags supporting it? */
bool bAutoIso14443_4;
/** Supported modulation encoded in a byte */
/** Supported modulation encoded in a byte */
uint8_t btSupportByte;
/** Last reported error */
/** Last reported error */
int last_error;
};

View file

@ -263,7 +263,7 @@ nfc_list_devices (nfc_context *context, nfc_connstring connstrings[] , size_t sz
szDeviceFound += szN;
log_put (LOG_CATEGORY, NFC_PRIORITY_TRACE, "%ld device(s) found using %s driver", (unsigned long) szN, ndr->name);
if (szDeviceFound == szDevices)
break;
break;
}
pndr++;
}
@ -400,20 +400,20 @@ nfc_initiator_select_passive_target (nfc_device *pnd,
size_t szInit;
switch (nm.nmt) {
case NMT_ISO14443A:
iso14443_cascade_uid (pbtInitData, szInitData, abtInit, &szInit);
break;
case NMT_ISO14443A:
iso14443_cascade_uid (pbtInitData, szInitData, abtInit, &szInit);
break;
case NMT_JEWEL:
case NMT_ISO14443B:
case NMT_ISO14443BI:
case NMT_ISO14443B2SR:
case NMT_ISO14443B2CT:
case NMT_FELICA:
case NMT_DEP:
memcpy (abtInit, pbtInitData, szInitData);
szInit = szInitData;
break;
case NMT_JEWEL:
case NMT_ISO14443B:
case NMT_ISO14443BI:
case NMT_ISO14443B2SR:
case NMT_ISO14443B2CT:
case NMT_FELICA:
case NMT_DEP:
memcpy (abtInit, pbtInitData, szInitData);
szInit = szInitData;
break;
}
HAL (initiator_select_passive_target, pnd, nm, abtInit, szInit, pnt);
@ -549,10 +549,10 @@ nfc_initiator_select_dep_target (nfc_device *pnd,
*/
int
nfc_initiator_poll_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)
const nfc_dep_mode ndm, const nfc_baud_rate nbr,
const nfc_dep_info *pndiInitiator,
nfc_target *pnt,
const int timeout)
{
const int period = 300;
int remaining_time = timeout;
@ -727,7 +727,7 @@ nfc_initiator_target_is_present (nfc_device *pnd, const nfc_target nt)
*/
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)
uint8_t *pbtRx, uint8_t *pbtRxPar, uint32_t *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) {
case NBR_UNDEFINED:
return "undefined baud rate";
break;
break;
case NBR_106:
return "106 kbps";
break;
break;
case NBR_212:
return "212 kbps";
break;
break;
case NBR_424:
return "424 kbps";
break;
break;
case NBR_847:
return "847 kbps";
break;
break;
}
// Should never go there..
return "";
@ -1109,28 +1109,28 @@ str_nfc_modulation_type (const nfc_modulation_type nmt)
switch(nmt) {
case NMT_ISO14443A:
return "ISO/IEC 14443A";
break;
break;
case NMT_ISO14443B:
return "ISO/IEC 14443-4B";
break;
break;
case NMT_ISO14443BI:
return "ISO/IEC 14443-4B'";
break;
break;
case NMT_ISO14443B2CT:
return "ISO/IEC 14443-2B ASK CTx";
break;
break;
case NMT_ISO14443B2SR:
return "ISO/IEC 14443-2B ST SRx";
break;
break;
case NMT_FELICA:
return "FeliCa";
break;
break;
case NMT_JEWEL:
return "Innovision Jewel";
break;
break;
case NMT_DEP:
return "D.E.P.";
break;
break;
}
// Should never go there..
return "";