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
This commit is contained in:
parent
562205cc14
commit
01303fab0d
59 changed files with 3178 additions and 3178 deletions
|
|
@ -42,16 +42,16 @@ typedef void *serial_port;
|
|||
# define INVALID_SERIAL_PORT (void*)(~1)
|
||||
# define CLAIMED_SERIAL_PORT (void*)(~2)
|
||||
|
||||
serial_port uart_open (const char *pcPortName);
|
||||
void uart_close (const serial_port sp);
|
||||
void uart_flush_input (const serial_port sp);
|
||||
serial_port uart_open(const char *pcPortName);
|
||||
void uart_close(const serial_port sp);
|
||||
void uart_flush_input(const serial_port sp);
|
||||
|
||||
void uart_set_speed (serial_port sp, const uint32_t uiPortSpeed);
|
||||
uint32_t uart_get_speed (const serial_port sp);
|
||||
void uart_set_speed(serial_port sp, const uint32_t uiPortSpeed);
|
||||
uint32_t uart_get_speed(const serial_port sp);
|
||||
|
||||
int uart_receive (serial_port sp, uint8_t *pbtRx, const size_t szRx, void *abort_p, int timeout);
|
||||
int uart_send (serial_port sp, const uint8_t *pbtTx, const size_t szTx, int timeout);
|
||||
int uart_receive(serial_port sp, uint8_t *pbtRx, const size_t szRx, void *abort_p, int timeout);
|
||||
int uart_send(serial_port sp, const uint8_t *pbtTx, const size_t szTx, int timeout);
|
||||
|
||||
char **uart_list_ports (void);
|
||||
char **uart_list_ports(void);
|
||||
|
||||
#endif // __NFC_BUS_UART_H__
|
||||
|
|
|
|||
|
|
@ -68,29 +68,29 @@ struct serial_port_unix {
|
|||
|
||||
#define UART_DATA( X ) ((struct serial_port_unix *) X)
|
||||
|
||||
void uart_close_ext (const serial_port sp, const bool restore_termios);
|
||||
void uart_close_ext(const serial_port sp, const bool restore_termios);
|
||||
|
||||
serial_port
|
||||
uart_open (const char *pcPortName)
|
||||
uart_open(const char *pcPortName)
|
||||
{
|
||||
struct serial_port_unix *sp = malloc (sizeof (struct serial_port_unix));
|
||||
struct serial_port_unix *sp = malloc(sizeof(struct serial_port_unix));
|
||||
|
||||
if (sp == 0)
|
||||
return INVALID_SERIAL_PORT;
|
||||
|
||||
sp->fd = open (pcPortName, O_RDWR | O_NOCTTY | O_NONBLOCK);
|
||||
sp->fd = open(pcPortName, O_RDWR | O_NOCTTY | O_NONBLOCK);
|
||||
if (sp->fd == -1) {
|
||||
uart_close_ext (sp, false);
|
||||
uart_close_ext(sp, false);
|
||||
return INVALID_SERIAL_PORT;
|
||||
}
|
||||
|
||||
if (tcgetattr (sp->fd, &sp->termios_backup) == -1) {
|
||||
uart_close_ext (sp, false);
|
||||
if (tcgetattr(sp->fd, &sp->termios_backup) == -1) {
|
||||
uart_close_ext(sp, false);
|
||||
return INVALID_SERIAL_PORT;
|
||||
}
|
||||
// Make sure the port is not claimed already
|
||||
if (sp->termios_backup.c_iflag & CCLAIMED) {
|
||||
uart_close_ext (sp, false);
|
||||
uart_close_ext(sp, false);
|
||||
return CLAIMED_SERIAL_PORT;
|
||||
}
|
||||
// Copy the old terminal info struct
|
||||
|
|
@ -104,40 +104,40 @@ uart_open (const char *pcPortName)
|
|||
sp->termios_new.c_cc[VMIN] = 0; // block until n bytes are received
|
||||
sp->termios_new.c_cc[VTIME] = 0; // block until a timer expires (n * 100 mSec.)
|
||||
|
||||
if (tcsetattr (sp->fd, TCSANOW, &sp->termios_new) == -1) {
|
||||
uart_close_ext (sp, true);
|
||||
if (tcsetattr(sp->fd, TCSANOW, &sp->termios_new) == -1) {
|
||||
uart_close_ext(sp, true);
|
||||
return INVALID_SERIAL_PORT;
|
||||
}
|
||||
return sp;
|
||||
}
|
||||
|
||||
void
|
||||
uart_flush_input (serial_port sp)
|
||||
uart_flush_input(serial_port sp)
|
||||
{
|
||||
// This line seems to produce absolutely no effect on my system (GNU/Linux 2.6.35)
|
||||
tcflush (UART_DATA(sp)->fd, TCIFLUSH);
|
||||
tcflush(UART_DATA(sp)->fd, TCIFLUSH);
|
||||
// So, I wrote this byte-eater
|
||||
// Retrieve the count of the incoming bytes
|
||||
int available_bytes_count = 0;
|
||||
int res;
|
||||
res = ioctl (UART_DATA(sp)->fd, FIONREAD, &available_bytes_count);
|
||||
res = ioctl(UART_DATA(sp)->fd, FIONREAD, &available_bytes_count);
|
||||
if (res != 0) {
|
||||
return;
|
||||
}
|
||||
if (available_bytes_count == 0) {
|
||||
return;
|
||||
}
|
||||
char* rx = malloc (available_bytes_count);
|
||||
char* rx = malloc(available_bytes_count);
|
||||
// There is something available, read the data
|
||||
res = read (UART_DATA(sp)->fd, rx, available_bytes_count);
|
||||
log_put (LOG_CATEGORY, NFC_PRIORITY_TRACE, "%d bytes have eatten.", available_bytes_count);
|
||||
free (rx);
|
||||
res = read(UART_DATA(sp)->fd, rx, available_bytes_count);
|
||||
log_put(LOG_CATEGORY, NFC_PRIORITY_TRACE, "%d bytes have eatten.", available_bytes_count);
|
||||
free(rx);
|
||||
}
|
||||
|
||||
void
|
||||
uart_set_speed (serial_port sp, const uint32_t uiPortSpeed)
|
||||
uart_set_speed(serial_port sp, const uint32_t uiPortSpeed)
|
||||
{
|
||||
log_put (LOG_CATEGORY, NFC_PRIORITY_TRACE, "Serial port speed requested to be set to %d bauds.", uiPortSpeed);
|
||||
log_put(LOG_CATEGORY, NFC_PRIORITY_TRACE, "Serial port speed requested to be set to %d bauds.", uiPortSpeed);
|
||||
|
||||
// Portability note: on some systems, B9600 != 9600 so we have to do
|
||||
// uint32_t <=> speed_t associations by hand.
|
||||
|
|
@ -173,24 +173,24 @@ uart_set_speed (serial_port sp, const uint32_t uiPortSpeed)
|
|||
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);
|
||||
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)
|
||||
cfsetispeed (&(UART_DATA(sp)->termios_new), stPortSpeed);
|
||||
cfsetospeed (&(UART_DATA(sp)->termios_new), stPortSpeed);
|
||||
if (tcsetattr (UART_DATA(sp)->fd, TCSADRAIN, &(UART_DATA(sp)->termios_new)) == -1) {
|
||||
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Unable to apply new speed settings.");
|
||||
cfsetispeed(&(UART_DATA(sp)->termios_new), stPortSpeed);
|
||||
cfsetospeed(&(UART_DATA(sp)->termios_new), stPortSpeed);
|
||||
if (tcsetattr(UART_DATA(sp)->fd, TCSADRAIN, &(UART_DATA(sp)->termios_new)) == -1) {
|
||||
log_put(LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Unable to apply new speed settings.");
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t
|
||||
uart_get_speed (serial_port sp)
|
||||
uart_get_speed(serial_port sp)
|
||||
{
|
||||
uint32_t uiPortSpeed = 0;
|
||||
switch (cfgetispeed (&UART_DATA(sp)->termios_new)) {
|
||||
switch (cfgetispeed(&UART_DATA(sp)->termios_new)) {
|
||||
case B9600:
|
||||
uiPortSpeed = 9600;
|
||||
break;
|
||||
|
|
@ -226,20 +226,20 @@ uart_get_speed (serial_port sp)
|
|||
}
|
||||
|
||||
void
|
||||
uart_close_ext (const serial_port sp, const bool restore_termios)
|
||||
uart_close_ext(const serial_port sp, const bool restore_termios)
|
||||
{
|
||||
if (UART_DATA(sp)->fd >= 0) {
|
||||
if (restore_termios)
|
||||
tcsetattr (UART_DATA(sp)->fd, TCSANOW, &UART_DATA(sp)->termios_backup);
|
||||
close (UART_DATA(sp)->fd);
|
||||
tcsetattr(UART_DATA(sp)->fd, TCSANOW, &UART_DATA(sp)->termios_backup);
|
||||
close(UART_DATA(sp)->fd);
|
||||
}
|
||||
free (sp);
|
||||
free(sp);
|
||||
}
|
||||
|
||||
void
|
||||
uart_close (const serial_port sp)
|
||||
uart_close(const serial_port sp)
|
||||
{
|
||||
uart_close_ext (sp, true);
|
||||
uart_close_ext(sp, true);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -248,7 +248,7 @@ uart_close (const serial_port sp)
|
|||
* @return 0 on success, otherwise driver error code
|
||||
*/
|
||||
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 received_bytes_count = 0;
|
||||
|
|
@ -259,11 +259,11 @@ uart_receive (serial_port sp, uint8_t *pbtRx, const size_t szRx, void *abort_p,
|
|||
do {
|
||||
select:
|
||||
// Reset file descriptor
|
||||
FD_ZERO (&rfds);
|
||||
FD_SET (UART_DATA(sp)->fd, &rfds);
|
||||
FD_ZERO(&rfds);
|
||||
FD_SET(UART_DATA(sp)->fd, &rfds);
|
||||
|
||||
if (iAbortFd) {
|
||||
FD_SET (iAbortFd, &rfds);
|
||||
FD_SET(iAbortFd, &rfds);
|
||||
}
|
||||
|
||||
struct timeval timeout_tv;
|
||||
|
|
@ -272,7 +272,7 @@ select:
|
|||
timeout_tv.tv_usec = ((timeout % 1000) * 1000);
|
||||
}
|
||||
|
||||
res = select (MAX(UART_DATA(sp)->fd, iAbortFd) + 1, &rfds, NULL, NULL, timeout ? &timeout_tv : NULL);
|
||||
res = select(MAX(UART_DATA(sp)->fd, iAbortFd) + 1, &rfds, NULL, NULL, timeout ? &timeout_tv : NULL);
|
||||
|
||||
if ((res < 0) && (EINTR == errno)) {
|
||||
// The system call was interupted by a signal and a signal handler was
|
||||
|
|
@ -282,29 +282,29 @@ select:
|
|||
|
||||
// Read error
|
||||
if (res < 0) {
|
||||
log_put (LOG_CATEGORY, NFC_PRIORITY_TRACE, "Error: %s", strerror(errno));
|
||||
log_put(LOG_CATEGORY, NFC_PRIORITY_TRACE, "Error: %s", strerror(errno));
|
||||
return NFC_EIO;
|
||||
}
|
||||
// Read time-out
|
||||
if (res == 0) {
|
||||
log_put (LOG_CATEGORY, NFC_PRIORITY_TRACE, "%s", "Timeout!");
|
||||
log_put(LOG_CATEGORY, NFC_PRIORITY_TRACE, "%s", "Timeout!");
|
||||
return NFC_ETIMEOUT;
|
||||
}
|
||||
|
||||
if (FD_ISSET (iAbortFd, &rfds)) {
|
||||
if (FD_ISSET(iAbortFd, &rfds)) {
|
||||
// Abort requested
|
||||
log_put (LOG_CATEGORY, NFC_PRIORITY_TRACE, "%s", "Abort!");
|
||||
close (iAbortFd);
|
||||
log_put(LOG_CATEGORY, NFC_PRIORITY_TRACE, "%s", "Abort!");
|
||||
close(iAbortFd);
|
||||
return NFC_EOPABORTED;
|
||||
}
|
||||
|
||||
// Retrieve the count of the incoming bytes
|
||||
res = ioctl (UART_DATA(sp)->fd, FIONREAD, &available_bytes_count);
|
||||
res = ioctl(UART_DATA(sp)->fd, FIONREAD, &available_bytes_count);
|
||||
if (res != 0) {
|
||||
return NFC_EIO;
|
||||
}
|
||||
// There is something available, read the data
|
||||
res = read (UART_DATA(sp)->fd, pbtRx + received_bytes_count, MIN(available_bytes_count, (expected_bytes_count - received_bytes_count)));
|
||||
res = read(UART_DATA(sp)->fd, pbtRx + received_bytes_count, MIN(available_bytes_count, (expected_bytes_count - received_bytes_count)));
|
||||
// Stop if the OS has some troubles reading the data
|
||||
if (res <= 0) {
|
||||
return NFC_EIO;
|
||||
|
|
@ -312,7 +312,7 @@ select:
|
|||
received_bytes_count += res;
|
||||
|
||||
} while (expected_bytes_count > received_bytes_count);
|
||||
LOG_HEX ("RX", pbtRx, szRx);
|
||||
LOG_HEX("RX", pbtRx, szRx);
|
||||
return NFC_SUCCESS;
|
||||
}
|
||||
|
||||
|
|
@ -322,20 +322,20 @@ select:
|
|||
* @return 0 on success, otherwise a driver error is returned
|
||||
*/
|
||||
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)
|
||||
{
|
||||
(void) timeout;
|
||||
LOG_HEX ("TX", pbtTx, szTx);
|
||||
if ((int) szTx == write (UART_DATA(sp)->fd, pbtTx, szTx))
|
||||
LOG_HEX("TX", pbtTx, szTx);
|
||||
if ((int) szTx == write(UART_DATA(sp)->fd, pbtTx, szTx))
|
||||
return NFC_SUCCESS;
|
||||
else
|
||||
return NFC_EIO;
|
||||
}
|
||||
|
||||
char **
|
||||
uart_list_ports (void)
|
||||
uart_list_ports(void)
|
||||
{
|
||||
char **res = malloc (sizeof (char *));
|
||||
char **res = malloc(sizeof(char *));
|
||||
size_t szRes = 1;
|
||||
|
||||
res[0] = NULL;
|
||||
|
|
@ -343,21 +343,21 @@ uart_list_ports (void)
|
|||
DIR *pdDir = opendir("/dev");
|
||||
struct dirent *pdDirEnt;
|
||||
while ((pdDirEnt = readdir(pdDir)) != NULL) {
|
||||
if (!isdigit (pdDirEnt->d_name[strlen (pdDirEnt->d_name) - 1]))
|
||||
if (!isdigit(pdDirEnt->d_name[strlen(pdDirEnt->d_name) - 1]))
|
||||
continue;
|
||||
|
||||
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 (!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))))
|
||||
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;
|
||||
|
|
@ -366,7 +366,7 @@ uart_list_ports (void)
|
|||
}
|
||||
}
|
||||
oom:
|
||||
closedir (pdDir);
|
||||
closedir(pdDir);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,31 +38,31 @@ struct serial_port_windows {
|
|||
};
|
||||
|
||||
serial_port
|
||||
uart_open (const char *pcPortName)
|
||||
uart_open(const char *pcPortName)
|
||||
{
|
||||
char acPortName[255];
|
||||
struct serial_port_windows *sp = malloc (sizeof (struct serial_port_windows));
|
||||
struct serial_port_windows *sp = malloc(sizeof(struct serial_port_windows));
|
||||
|
||||
// Copy the input "com?" to "\\.\COM?" format
|
||||
sprintf (acPortName, "\\\\.\\%s", pcPortName);
|
||||
_strupr (acPortName);
|
||||
sprintf(acPortName, "\\\\.\\%s", pcPortName);
|
||||
_strupr(acPortName);
|
||||
|
||||
// Try to open the serial port
|
||||
sp->hPort = CreateFileA (acPortName, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
|
||||
sp->hPort = CreateFileA(acPortName, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
|
||||
if (sp->hPort == INVALID_HANDLE_VALUE) {
|
||||
uart_close (sp);
|
||||
uart_close(sp);
|
||||
return INVALID_SERIAL_PORT;
|
||||
}
|
||||
// Prepare the device control
|
||||
memset (&sp->dcb, 0, sizeof (DCB));
|
||||
sp->dcb.DCBlength = sizeof (DCB);
|
||||
if (!BuildCommDCBA ("baud=9600 data=8 parity=N stop=1", &sp->dcb)) {
|
||||
uart_close (sp);
|
||||
memset(&sp->dcb, 0, sizeof(DCB));
|
||||
sp->dcb.DCBlength = sizeof(DCB);
|
||||
if (!BuildCommDCBA("baud=9600 data=8 parity=N stop=1", &sp->dcb)) {
|
||||
uart_close(sp);
|
||||
return INVALID_SERIAL_PORT;
|
||||
}
|
||||
// Update the active serial port
|
||||
if (!SetCommState (sp->hPort, &sp->dcb)) {
|
||||
uart_close (sp);
|
||||
if (!SetCommState(sp->hPort, &sp->dcb)) {
|
||||
uart_close(sp);
|
||||
return INVALID_SERIAL_PORT;
|
||||
}
|
||||
|
||||
|
|
@ -72,37 +72,37 @@ uart_open (const char *pcPortName)
|
|||
sp->ct.WriteTotalTimeoutMultiplier = 30;
|
||||
sp->ct.WriteTotalTimeoutConstant = 0;
|
||||
|
||||
if (!SetCommTimeouts (sp->hPort, &sp->ct)) {
|
||||
uart_close (sp);
|
||||
if (!SetCommTimeouts(sp->hPort, &sp->ct)) {
|
||||
uart_close(sp);
|
||||
return INVALID_SERIAL_PORT;
|
||||
}
|
||||
|
||||
PurgeComm (sp->hPort, PURGE_RXABORT | PURGE_RXCLEAR);
|
||||
PurgeComm(sp->hPort, PURGE_RXABORT | PURGE_RXCLEAR);
|
||||
|
||||
return sp;
|
||||
}
|
||||
|
||||
void
|
||||
uart_close (const serial_port sp)
|
||||
uart_close(const serial_port sp)
|
||||
{
|
||||
if (((struct serial_port_windows *) sp)->hPort != INVALID_HANDLE_VALUE) {
|
||||
CloseHandle (((struct serial_port_windows *) sp)->hPort);
|
||||
CloseHandle(((struct serial_port_windows *) sp)->hPort);
|
||||
}
|
||||
free (sp);
|
||||
free(sp);
|
||||
}
|
||||
|
||||
void
|
||||
uart_flush_input (const serial_port sp)
|
||||
uart_flush_input(const serial_port sp)
|
||||
{
|
||||
PurgeComm(((struct serial_port_windows *) sp)->hPort, PURGE_RXABORT | PURGE_RXCLEAR);
|
||||
}
|
||||
|
||||
void
|
||||
uart_set_speed (serial_port sp, const uint32_t uiPortSpeed)
|
||||
uart_set_speed(serial_port sp, const uint32_t uiPortSpeed)
|
||||
{
|
||||
struct serial_port_windows *spw;
|
||||
|
||||
log_put (LOG_CATEGORY, NFC_PRIORITY_TRACE, "Serial port speed requested to be set to %d bauds.", uiPortSpeed);
|
||||
log_put(LOG_CATEGORY, NFC_PRIORITY_TRACE, "Serial port speed requested to be set to %d bauds.", uiPortSpeed);
|
||||
// Set port speed (Input and Output)
|
||||
switch (uiPortSpeed) {
|
||||
case 9600:
|
||||
|
|
@ -114,32 +114,32 @@ uart_set_speed (serial_port sp, const uint32_t uiPortSpeed)
|
|||
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);
|
||||
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;
|
||||
|
||||
// Set baud rate
|
||||
spw->dcb.BaudRate = uiPortSpeed;
|
||||
if (!SetCommState (spw->hPort, &spw->dcb)) {
|
||||
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Unable to apply new speed settings.");
|
||||
if (!SetCommState(spw->hPort, &spw->dcb)) {
|
||||
log_put(LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Unable to apply new speed settings.");
|
||||
return;
|
||||
}
|
||||
PurgeComm (spw->hPort, PURGE_RXABORT | PURGE_RXCLEAR);
|
||||
PurgeComm(spw->hPort, PURGE_RXABORT | PURGE_RXCLEAR);
|
||||
}
|
||||
|
||||
uint32_t
|
||||
uart_get_speed (const serial_port sp)
|
||||
uart_get_speed(const serial_port sp)
|
||||
{
|
||||
const struct serial_port_windows *spw = (struct serial_port_windows *) sp;
|
||||
if (!GetCommState (spw->hPort, (serial_port) & spw->dcb))
|
||||
if (!GetCommState(spw->hPort, (serial_port) & spw->dcb))
|
||||
return spw->dcb.BaudRate;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
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 dwBytesReceived = 0;
|
||||
|
|
@ -155,26 +155,26 @@ uart_receive (serial_port sp, uint8_t * pbtRx, const size_t szRx, void * abort_p
|
|||
timeouts.WriteTotalTimeoutMultiplier = 0;
|
||||
timeouts.WriteTotalTimeoutConstant = timeout_ms;
|
||||
|
||||
if (!SetCommTimeouts (((struct serial_port_windows *) sp)->hPort, &timeouts)) {
|
||||
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "Unable to apply new timeout settings.");
|
||||
if (!SetCommTimeouts(((struct serial_port_windows *) sp)->hPort, &timeouts)) {
|
||||
log_put(LOG_CATEGORY, NFC_PRIORITY_ERROR, "Unable to apply new timeout settings.");
|
||||
return NFC_EIO;
|
||||
}
|
||||
log_put (LOG_CATEGORY, NFC_PRIORITY_TRACE, "Timeouts are set to %u ms", timeout_ms);
|
||||
log_put(LOG_CATEGORY, NFC_PRIORITY_TRACE, "Timeouts are set to %u ms", timeout_ms);
|
||||
|
||||
// TODO Enhance the reception method
|
||||
// - According to MSDN, it could be better to implement nfc_abort_command() mecanism using Cancello()
|
||||
volatile bool * abort_flag_p = (volatile bool *)abort_p;
|
||||
do {
|
||||
log_put (LOG_CATEGORY, NFC_PRIORITY_TRACE, "ReadFile");
|
||||
res = ReadFile (((struct serial_port_windows *) sp)->hPort, pbtRx + dwTotalBytesReceived,
|
||||
dwBytesToGet,
|
||||
&dwBytesReceived, NULL);
|
||||
log_put(LOG_CATEGORY, NFC_PRIORITY_TRACE, "ReadFile");
|
||||
res = ReadFile(((struct serial_port_windows *) sp)->hPort, pbtRx + dwTotalBytesReceived,
|
||||
dwBytesToGet,
|
||||
&dwBytesReceived, NULL);
|
||||
|
||||
dwTotalBytesReceived += dwBytesReceived;
|
||||
|
||||
if (!res) {
|
||||
DWORD err = GetLastError();
|
||||
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "ReadFile error: %u", err);
|
||||
log_put(LOG_CATEGORY, NFC_PRIORITY_ERROR, "ReadFile error: %u", err);
|
||||
return NFC_EIO;
|
||||
} else if (dwBytesReceived == 0) {
|
||||
return NFC_ETIMEOUT;
|
||||
|
|
@ -188,13 +188,13 @@ uart_receive (serial_port sp, uint8_t * pbtRx, const size_t szRx, void * abort_p
|
|||
return NFC_EOPABORTED;
|
||||
}
|
||||
} while (((DWORD)szRx) > dwTotalBytesReceived);
|
||||
LOG_HEX ("RX", pbtRx, szRx);
|
||||
LOG_HEX("RX", pbtRx, szRx);
|
||||
|
||||
return (dwTotalBytesReceived == (DWORD) szRx) ? 0 : NFC_EIO;
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
|
|
@ -205,13 +205,13 @@ uart_send (serial_port sp, const uint8_t * pbtTx, const size_t szTx, int timeout
|
|||
timeouts.WriteTotalTimeoutMultiplier = 0;
|
||||
timeouts.WriteTotalTimeoutConstant = timeout;
|
||||
|
||||
if (!SetCommTimeouts (((struct serial_port_windows *) sp)->hPort, &timeouts)) {
|
||||
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "Unable to apply new timeout settings.");
|
||||
if (!SetCommTimeouts(((struct serial_port_windows *) sp)->hPort, &timeouts)) {
|
||||
log_put(LOG_CATEGORY, NFC_PRIORITY_ERROR, "Unable to apply new timeout settings.");
|
||||
return NFC_EIO;
|
||||
}
|
||||
|
||||
LOG_HEX ("TX", pbtTx, szTx);
|
||||
if (!WriteFile (((struct serial_port_windows *) sp)->hPort, pbtTx, szTx, &dwTxLen, NULL)) {
|
||||
LOG_HEX("TX", pbtTx, szTx);
|
||||
if (!WriteFile(((struct serial_port_windows *) sp)->hPort, pbtTx, szTx, &dwTxLen, NULL)) {
|
||||
return NFC_EIO;
|
||||
}
|
||||
if (!dwTxLen)
|
||||
|
|
@ -236,7 +236,7 @@ BOOL is_port_available(int nPort)
|
|||
// Try to guess what we should use.
|
||||
#define MAX_SERIAL_PORT_WIN 255
|
||||
char **
|
||||
uart_list_ports (void)
|
||||
uart_list_ports(void)
|
||||
{
|
||||
char **availablePorts = malloc((1 + MAX_SERIAL_PORT_WIN) * sizeof(char*));
|
||||
int curIndex = 0;
|
||||
|
|
|
|||
|
|
@ -144,49 +144,49 @@ typedef enum {
|
|||
|
||||
static const pn53x_command pn53x_commands[] = {
|
||||
// Miscellaneous
|
||||
PNCMD( Diagnose, PN531 | PN532 | PN533 | RCS360 ),
|
||||
PNCMD( GetFirmwareVersion, PN531 | PN532 | PN533 | RCS360 ),
|
||||
PNCMD( GetGeneralStatus, PN531 | PN532 | PN533 | RCS360 ),
|
||||
PNCMD( ReadRegister, PN531 | PN532 | PN533 | RCS360 ),
|
||||
PNCMD( WriteRegister, PN531 | PN532 | PN533 | RCS360 ),
|
||||
PNCMD( ReadGPIO, PN531 | PN532 | PN533 ),
|
||||
PNCMD( WriteGPIO, PN531 | PN532 | PN533 ),
|
||||
PNCMD( SetSerialBaudRate, PN531 | PN532 | PN533 ),
|
||||
PNCMD( SetParameters, PN531 | PN532 | PN533 | RCS360 ),
|
||||
PNCMD( SAMConfiguration, PN531 | PN532 ),
|
||||
PNCMD( PowerDown, PN531 | PN532 ),
|
||||
PNCMD( AlparCommandForTDA, PN533 | RCS360 ), // Has another usage on RC-S360...
|
||||
PNCMD(Diagnose, PN531 | PN532 | PN533 | RCS360),
|
||||
PNCMD(GetFirmwareVersion, PN531 | PN532 | PN533 | RCS360),
|
||||
PNCMD(GetGeneralStatus, PN531 | PN532 | PN533 | RCS360),
|
||||
PNCMD(ReadRegister, PN531 | PN532 | PN533 | RCS360),
|
||||
PNCMD(WriteRegister, PN531 | PN532 | PN533 | RCS360),
|
||||
PNCMD(ReadGPIO, PN531 | PN532 | PN533),
|
||||
PNCMD(WriteGPIO, PN531 | PN532 | PN533),
|
||||
PNCMD(SetSerialBaudRate, PN531 | PN532 | PN533),
|
||||
PNCMD(SetParameters, PN531 | PN532 | PN533 | RCS360),
|
||||
PNCMD(SAMConfiguration, PN531 | PN532),
|
||||
PNCMD(PowerDown, PN531 | PN532),
|
||||
PNCMD(AlparCommandForTDA, PN533 | RCS360), // Has another usage on RC-S360...
|
||||
|
||||
// RF communication
|
||||
PNCMD( RFConfiguration, PN531 | PN532 | PN533 | RCS360 ),
|
||||
PNCMD( RFRegulationTest, PN531 | PN532 | PN533 ),
|
||||
PNCMD(RFConfiguration, PN531 | PN532 | PN533 | RCS360),
|
||||
PNCMD(RFRegulationTest, PN531 | PN532 | PN533),
|
||||
|
||||
// Initiator
|
||||
PNCMD( InJumpForDEP, PN531 | PN532 | PN533 | RCS360 ),
|
||||
PNCMD( InJumpForPSL, PN531 | PN532 | PN533 ),
|
||||
PNCMD( InListPassiveTarget, PN531 | PN532 | PN533 | RCS360 ),
|
||||
PNCMD( InATR, PN531 | PN532 | PN533 ),
|
||||
PNCMD( InPSL, PN531 | PN532 | PN533 ),
|
||||
PNCMD( InDataExchange, PN531 | PN532 | PN533 ),
|
||||
PNCMD( InCommunicateThru, PN531 | PN532 | PN533 | RCS360 ),
|
||||
PNCMD( InQuartetByteExchange, PN533 ),
|
||||
PNCMD( InDeselect, PN531 | PN532 | PN533 | RCS360 ),
|
||||
PNCMD( InRelease, PN531 | PN532 | PN533 | RCS360 ),
|
||||
PNCMD( InSelect, PN531 | PN532 | PN533 ),
|
||||
PNCMD( InAutoPoll, PN532 ),
|
||||
PNCMD( InActivateDeactivatePaypass, PN533 ),
|
||||
PNCMD(InJumpForDEP, PN531 | PN532 | PN533 | RCS360),
|
||||
PNCMD(InJumpForPSL, PN531 | PN532 | PN533),
|
||||
PNCMD(InListPassiveTarget, PN531 | PN532 | PN533 | RCS360),
|
||||
PNCMD(InATR, PN531 | PN532 | PN533),
|
||||
PNCMD(InPSL, PN531 | PN532 | PN533),
|
||||
PNCMD(InDataExchange, PN531 | PN532 | PN533),
|
||||
PNCMD(InCommunicateThru, PN531 | PN532 | PN533 | RCS360),
|
||||
PNCMD(InQuartetByteExchange, PN533),
|
||||
PNCMD(InDeselect, PN531 | PN532 | PN533 | RCS360),
|
||||
PNCMD(InRelease, PN531 | PN532 | PN533 | RCS360),
|
||||
PNCMD(InSelect, PN531 | PN532 | PN533),
|
||||
PNCMD(InAutoPoll, PN532),
|
||||
PNCMD(InActivateDeactivatePaypass, PN533),
|
||||
|
||||
// Target
|
||||
PNCMD( TgInitAsTarget, PN531 | PN532 | PN533 ),
|
||||
PNCMD( TgSetGeneralBytes, PN531 | PN532 | PN533 ),
|
||||
PNCMD( TgGetData, PN531 | PN532 | PN533 ),
|
||||
PNCMD( TgSetData, PN531 | PN532 | PN533 ),
|
||||
PNCMD( TgSetDataSecure, PN533 ),
|
||||
PNCMD( TgSetMetaData, PN531 | PN532 | PN533 ),
|
||||
PNCMD( TgSetMetaDataSecure, PN533 ),
|
||||
PNCMD( TgGetInitiatorCommand, PN531 | PN532 | PN533 ),
|
||||
PNCMD( TgResponseToInitiator, PN531 | PN532 | PN533 ),
|
||||
PNCMD( TgGetTargetStatus, PN531 | PN532 | PN533 ),
|
||||
PNCMD(TgInitAsTarget, PN531 | PN532 | PN533),
|
||||
PNCMD(TgSetGeneralBytes, PN531 | PN532 | PN533),
|
||||
PNCMD(TgGetData, PN531 | PN532 | PN533),
|
||||
PNCMD(TgSetData, PN531 | PN532 | PN533),
|
||||
PNCMD(TgSetDataSecure, PN533),
|
||||
PNCMD(TgSetMetaData, PN531 | PN532 | PN533),
|
||||
PNCMD(TgSetMetaDataSecure, PN533),
|
||||
PNCMD(TgGetInitiatorCommand, PN531 | PN532 | PN533),
|
||||
PNCMD(TgResponseToInitiator, PN531 | PN532 | PN533),
|
||||
PNCMD(TgGetTargetStatus, PN531 | PN532 | PN533),
|
||||
};
|
||||
|
||||
// SFR part
|
||||
|
|
@ -330,76 +330,76 @@ typedef struct {
|
|||
|
||||
#ifdef LOGGING
|
||||
static const pn53x_register pn53x_registers[] = {
|
||||
PNREG (PN53X_REG_CIU_Mode, "Defines general modes for transmitting and receiving"),
|
||||
PNREG (PN53X_REG_CIU_TxMode, "Defines the transmission data rate and framing during transmission"),
|
||||
PNREG (PN53X_REG_CIU_RxMode, "Defines the transmission data rate and framing during receiving"),
|
||||
PNREG (PN53X_REG_CIU_TxControl, "Controls the logical behaviour of the antenna driver pins TX1 and TX2"),
|
||||
PNREG (PN53X_REG_CIU_TxAuto, "Controls the settings of the antenna driver"),
|
||||
PNREG (PN53X_REG_CIU_TxSel, "Selects the internal sources for the antenna driver"),
|
||||
PNREG (PN53X_REG_CIU_RxSel, "Selects internal receiver settings"),
|
||||
PNREG (PN53X_REG_CIU_RxThreshold, "Selects thresholds for the bit decoder"),
|
||||
PNREG (PN53X_REG_CIU_Demod, "Defines demodulator settings"),
|
||||
PNREG (PN53X_REG_CIU_FelNFC1, "Defines the length of the valid range for the received frame"),
|
||||
PNREG (PN53X_REG_CIU_FelNFC2, "Defines the length of the valid range for the received frame"),
|
||||
PNREG (PN53X_REG_CIU_MifNFC, "Controls the communication in ISO/IEC 14443/MIFARE and NFC target mode at 106 kbit/s"),
|
||||
PNREG (PN53X_REG_CIU_ManualRCV, "Allows manual fine tuning of the internal receiver"),
|
||||
PNREG (PN53X_REG_CIU_TypeB, "Configure the ISO/IEC 14443 type B"),
|
||||
PNREG(PN53X_REG_CIU_Mode, "Defines general modes for transmitting and receiving"),
|
||||
PNREG(PN53X_REG_CIU_TxMode, "Defines the transmission data rate and framing during transmission"),
|
||||
PNREG(PN53X_REG_CIU_RxMode, "Defines the transmission data rate and framing during receiving"),
|
||||
PNREG(PN53X_REG_CIU_TxControl, "Controls the logical behaviour of the antenna driver pins TX1 and TX2"),
|
||||
PNREG(PN53X_REG_CIU_TxAuto, "Controls the settings of the antenna driver"),
|
||||
PNREG(PN53X_REG_CIU_TxSel, "Selects the internal sources for the antenna driver"),
|
||||
PNREG(PN53X_REG_CIU_RxSel, "Selects internal receiver settings"),
|
||||
PNREG(PN53X_REG_CIU_RxThreshold, "Selects thresholds for the bit decoder"),
|
||||
PNREG(PN53X_REG_CIU_Demod, "Defines demodulator settings"),
|
||||
PNREG(PN53X_REG_CIU_FelNFC1, "Defines the length of the valid range for the received frame"),
|
||||
PNREG(PN53X_REG_CIU_FelNFC2, "Defines the length of the valid range for the received frame"),
|
||||
PNREG(PN53X_REG_CIU_MifNFC, "Controls the communication in ISO/IEC 14443/MIFARE and NFC target mode at 106 kbit/s"),
|
||||
PNREG(PN53X_REG_CIU_ManualRCV, "Allows manual fine tuning of the internal receiver"),
|
||||
PNREG(PN53X_REG_CIU_TypeB, "Configure the ISO/IEC 14443 type B"),
|
||||
// PNREG (PN53X_REG_-, "Reserved"),
|
||||
// PNREG (PN53X_REG_-, "Reserved"),
|
||||
PNREG (PN53X_REG_CIU_CRCResultMSB, "Shows the actual MSB values of the CRC calculation"),
|
||||
PNREG (PN53X_REG_CIU_CRCResultLSB, "Shows the actual LSB values of the CRC calculation"),
|
||||
PNREG (PN53X_REG_CIU_GsNOFF, "Selects the conductance of the antenna driver pins TX1 and TX2 for load modulation when own RF field is switched OFF"),
|
||||
PNREG (PN53X_REG_CIU_ModWidth, "Controls the setting of the width of the Miller pause"),
|
||||
PNREG (PN53X_REG_CIU_TxBitPhase, "Bit synchronization at 106 kbit/s"),
|
||||
PNREG (PN53X_REG_CIU_RFCfg, "Configures the receiver gain and RF level"),
|
||||
PNREG (PN53X_REG_CIU_GsNOn, "Selects the conductance of the antenna driver pins TX1 and TX2 for modulation, when own RF field is switched ON"),
|
||||
PNREG (PN53X_REG_CIU_CWGsP, "Selects the conductance of the antenna driver pins TX1 and TX2 when not in modulation phase"),
|
||||
PNREG (PN53X_REG_CIU_ModGsP, "Selects the conductance of the antenna driver pins TX1 and TX2 when in modulation phase"),
|
||||
PNREG (PN53X_REG_CIU_TMode, "Defines settings for the internal timer"),
|
||||
PNREG (PN53X_REG_CIU_TPrescaler, "Defines settings for the internal timer"),
|
||||
PNREG (PN53X_REG_CIU_TReloadVal_hi, "Describes the 16-bit long timer reload value (Higher 8 bits)"),
|
||||
PNREG (PN53X_REG_CIU_TReloadVal_lo, "Describes the 16-bit long timer reload value (Lower 8 bits)"),
|
||||
PNREG (PN53X_REG_CIU_TCounterVal_hi, "Describes the 16-bit long timer actual value (Higher 8 bits)"),
|
||||
PNREG (PN53X_REG_CIU_TCounterVal_lo, "Describes the 16-bit long timer actual value (Lower 8 bits)"),
|
||||
PNREG(PN53X_REG_CIU_CRCResultMSB, "Shows the actual MSB values of the CRC calculation"),
|
||||
PNREG(PN53X_REG_CIU_CRCResultLSB, "Shows the actual LSB values of the CRC calculation"),
|
||||
PNREG(PN53X_REG_CIU_GsNOFF, "Selects the conductance of the antenna driver pins TX1 and TX2 for load modulation when own RF field is switched OFF"),
|
||||
PNREG(PN53X_REG_CIU_ModWidth, "Controls the setting of the width of the Miller pause"),
|
||||
PNREG(PN53X_REG_CIU_TxBitPhase, "Bit synchronization at 106 kbit/s"),
|
||||
PNREG(PN53X_REG_CIU_RFCfg, "Configures the receiver gain and RF level"),
|
||||
PNREG(PN53X_REG_CIU_GsNOn, "Selects the conductance of the antenna driver pins TX1 and TX2 for modulation, when own RF field is switched ON"),
|
||||
PNREG(PN53X_REG_CIU_CWGsP, "Selects the conductance of the antenna driver pins TX1 and TX2 when not in modulation phase"),
|
||||
PNREG(PN53X_REG_CIU_ModGsP, "Selects the conductance of the antenna driver pins TX1 and TX2 when in modulation phase"),
|
||||
PNREG(PN53X_REG_CIU_TMode, "Defines settings for the internal timer"),
|
||||
PNREG(PN53X_REG_CIU_TPrescaler, "Defines settings for the internal timer"),
|
||||
PNREG(PN53X_REG_CIU_TReloadVal_hi, "Describes the 16-bit long timer reload value (Higher 8 bits)"),
|
||||
PNREG(PN53X_REG_CIU_TReloadVal_lo, "Describes the 16-bit long timer reload value (Lower 8 bits)"),
|
||||
PNREG(PN53X_REG_CIU_TCounterVal_hi, "Describes the 16-bit long timer actual value (Higher 8 bits)"),
|
||||
PNREG(PN53X_REG_CIU_TCounterVal_lo, "Describes the 16-bit long timer actual value (Lower 8 bits)"),
|
||||
// PNREG (PN53X_REG_-, "Reserved"),
|
||||
PNREG (PN53X_REG_CIU_TestSel1, "General test signals configuration"),
|
||||
PNREG (PN53X_REG_CIU_TestSel2, "General test signals configuration and PRBS control"),
|
||||
PNREG (PN53X_REG_CIU_TestPinEn, "Enables test signals output on pins."),
|
||||
PNREG (PN53X_REG_CIU_TestPinValue, "Defines the values for the 8-bit parallel bus when it is used as I/O bus"),
|
||||
PNREG (PN53X_REG_CIU_TestBus, "Shows the status of the internal test bus"),
|
||||
PNREG (PN53X_REG_CIU_AutoTest, "Controls the digital self-test"),
|
||||
PNREG (PN53X_REG_CIU_Version, "Shows the CIU version"),
|
||||
PNREG (PN53X_REG_CIU_AnalogTest, "Controls the pins AUX1 and AUX2"),
|
||||
PNREG (PN53X_REG_CIU_TestDAC1, "Defines the test value for the TestDAC1"),
|
||||
PNREG (PN53X_REG_CIU_TestDAC2, "Defines the test value for the TestDAC2"),
|
||||
PNREG (PN53X_REG_CIU_TestADC, "Show the actual value of ADC I and Q"),
|
||||
PNREG(PN53X_REG_CIU_TestSel1, "General test signals configuration"),
|
||||
PNREG(PN53X_REG_CIU_TestSel2, "General test signals configuration and PRBS control"),
|
||||
PNREG(PN53X_REG_CIU_TestPinEn, "Enables test signals output on pins."),
|
||||
PNREG(PN53X_REG_CIU_TestPinValue, "Defines the values for the 8-bit parallel bus when it is used as I/O bus"),
|
||||
PNREG(PN53X_REG_CIU_TestBus, "Shows the status of the internal test bus"),
|
||||
PNREG(PN53X_REG_CIU_AutoTest, "Controls the digital self-test"),
|
||||
PNREG(PN53X_REG_CIU_Version, "Shows the CIU version"),
|
||||
PNREG(PN53X_REG_CIU_AnalogTest, "Controls the pins AUX1 and AUX2"),
|
||||
PNREG(PN53X_REG_CIU_TestDAC1, "Defines the test value for the TestDAC1"),
|
||||
PNREG(PN53X_REG_CIU_TestDAC2, "Defines the test value for the TestDAC2"),
|
||||
PNREG(PN53X_REG_CIU_TestADC, "Show the actual value of ADC I and Q"),
|
||||
// PNREG (PN53X_REG_-, "Reserved for tests"),
|
||||
// PNREG (PN53X_REG_-, "Reserved for tests"),
|
||||
// PNREG (PN53X_REG_-, "Reserved for tests"),
|
||||
PNREG (PN53X_REG_CIU_RFlevelDet, "Power down of the RF level detector"),
|
||||
PNREG (PN53X_REG_CIU_SIC_CLK_en, "Enables the use of secure IC clock on P34 / SIC_CLK"),
|
||||
PNREG (PN53X_REG_CIU_Command, "Starts and stops the command execution"),
|
||||
PNREG (PN53X_REG_CIU_CommIEn, "Control bits to enable and disable the passing of interrupt requests"),
|
||||
PNREG (PN53X_REG_CIU_DivIEn, "Controls bits to enable and disable the passing of interrupt requests"),
|
||||
PNREG (PN53X_REG_CIU_CommIrq, "Contains common CIU interrupt request flags"),
|
||||
PNREG (PN53X_REG_CIU_DivIrq, "Contains miscellaneous interrupt request flags"),
|
||||
PNREG (PN53X_REG_CIU_Error, "Error flags showing the error status of the last command executed"),
|
||||
PNREG (PN53X_REG_CIU_Status1, "Contains status flags of the CRC, Interrupt Request System and FIFO buffer"),
|
||||
PNREG (PN53X_REG_CIU_Status2, "Contain status flags of the receiver, transmitter and Data Mode Detector"),
|
||||
PNREG (PN53X_REG_CIU_FIFOData, "In- and output of 64 byte FIFO buffer"),
|
||||
PNREG (PN53X_REG_CIU_FIFOLevel, "Indicates the number of bytes stored in the FIFO"),
|
||||
PNREG (PN53X_REG_CIU_WaterLevel, "Defines the thresholds for FIFO under- and overflow warning"),
|
||||
PNREG (PN53X_REG_CIU_Control, "Contains miscellaneous control bits"),
|
||||
PNREG (PN53X_REG_CIU_BitFraming, "Adjustments for bit oriented frames"),
|
||||
PNREG (PN53X_REG_CIU_Coll, "Defines the first bit collision detected on the RF interface"),
|
||||
PNREG(PN53X_REG_CIU_RFlevelDet, "Power down of the RF level detector"),
|
||||
PNREG(PN53X_REG_CIU_SIC_CLK_en, "Enables the use of secure IC clock on P34 / SIC_CLK"),
|
||||
PNREG(PN53X_REG_CIU_Command, "Starts and stops the command execution"),
|
||||
PNREG(PN53X_REG_CIU_CommIEn, "Control bits to enable and disable the passing of interrupt requests"),
|
||||
PNREG(PN53X_REG_CIU_DivIEn, "Controls bits to enable and disable the passing of interrupt requests"),
|
||||
PNREG(PN53X_REG_CIU_CommIrq, "Contains common CIU interrupt request flags"),
|
||||
PNREG(PN53X_REG_CIU_DivIrq, "Contains miscellaneous interrupt request flags"),
|
||||
PNREG(PN53X_REG_CIU_Error, "Error flags showing the error status of the last command executed"),
|
||||
PNREG(PN53X_REG_CIU_Status1, "Contains status flags of the CRC, Interrupt Request System and FIFO buffer"),
|
||||
PNREG(PN53X_REG_CIU_Status2, "Contain status flags of the receiver, transmitter and Data Mode Detector"),
|
||||
PNREG(PN53X_REG_CIU_FIFOData, "In- and output of 64 byte FIFO buffer"),
|
||||
PNREG(PN53X_REG_CIU_FIFOLevel, "Indicates the number of bytes stored in the FIFO"),
|
||||
PNREG(PN53X_REG_CIU_WaterLevel, "Defines the thresholds for FIFO under- and overflow warning"),
|
||||
PNREG(PN53X_REG_CIU_Control, "Contains miscellaneous control bits"),
|
||||
PNREG(PN53X_REG_CIU_BitFraming, "Adjustments for bit oriented frames"),
|
||||
PNREG(PN53X_REG_CIU_Coll, "Defines the first bit collision detected on the RF interface"),
|
||||
|
||||
// SFR
|
||||
PNREG (PN53X_SFR_P3CFGA, "Port 3 configuration"),
|
||||
PNREG (PN53X_SFR_P3CFGB, "Port 3 configuration"),
|
||||
PNREG (PN53X_SFR_P3, "Port 3 value"),
|
||||
PNREG (PN53X_SFR_P7CFGA, "Port 7 configuration"),
|
||||
PNREG (PN53X_SFR_P7CFGB, "Port 7 configuration"),
|
||||
PNREG (PN53X_SFR_P7, "Port 7 value"),
|
||||
PNREG(PN53X_SFR_P3CFGA, "Port 3 configuration"),
|
||||
PNREG(PN53X_SFR_P3CFGB, "Port 3 configuration"),
|
||||
PNREG(PN53X_SFR_P3, "Port 3 value"),
|
||||
PNREG(PN53X_SFR_P7CFGA, "Port 7 configuration"),
|
||||
PNREG(PN53X_SFR_P7CFGB, "Port 7 configuration"),
|
||||
PNREG(PN53X_SFR_P7, "Port 7 value"),
|
||||
};
|
||||
#endif
|
||||
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -292,102 +292,102 @@ extern const uint8_t pn53x_ack_frame[6];
|
|||
extern const uint8_t pn53x_nack_frame[6];
|
||||
|
||||
int pn53x_init(struct nfc_device *pnd);
|
||||
int pn53x_transceive (struct nfc_device *pnd, const uint8_t *pbtTx, const size_t szTx, uint8_t *pbtRx, const size_t szRxLen, int timeout);
|
||||
int pn53x_transceive(struct nfc_device *pnd, const uint8_t *pbtTx, const size_t szTx, uint8_t *pbtRx, const size_t szRxLen, int timeout);
|
||||
|
||||
int pn53x_set_parameters (struct nfc_device *pnd, const uint8_t ui8Value, const bool bEnable);
|
||||
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);
|
||||
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);
|
||||
int pn53x_set_property_int (struct nfc_device *pnd, const nfc_property property, const int value);
|
||||
int pn53x_set_property_bool (struct nfc_device *pnd, const nfc_property property, const bool bEnable);
|
||||
int pn53x_set_parameters(struct nfc_device *pnd, const uint8_t ui8Value, const bool bEnable);
|
||||
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);
|
||||
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);
|
||||
int pn53x_set_property_int(struct nfc_device *pnd, const nfc_property property, const int value);
|
||||
int pn53x_set_property_bool(struct nfc_device *pnd, const nfc_property property, const bool bEnable);
|
||||
|
||||
int pn53x_check_communication (struct nfc_device *pnd);
|
||||
int pn53x_idle (struct nfc_device *pnd);
|
||||
int pn53x_check_communication(struct nfc_device *pnd);
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
int pn53x_initiator_transceive_bytes_timed (struct nfc_device *pnd, const uint8_t *pbtTx, const size_t szTx,
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
int pn53x_initiator_transceive_bytes_timed(struct nfc_device *pnd, const uint8_t *pbtTx, const size_t szTx,
|
||||
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);
|
||||
|
||||
// NFC device as Target functions
|
||||
int pn53x_target_init (struct nfc_device *pnd, nfc_target *pnt, uint8_t *pbtRx, const size_t szRxLen, int timeout);
|
||||
int pn53x_target_receive_bits (struct nfc_device *pnd, uint8_t *pbtRx, const size_t szRxLen, uint8_t *pbtRxPar);
|
||||
int pn53x_target_receive_bytes (struct nfc_device *pnd, uint8_t *pbtRx, const size_t szRxLen, int timeout);
|
||||
int pn53x_target_send_bits (struct nfc_device *pnd, const uint8_t *pbtTx, const size_t szTxBits, const uint8_t *pbtTxPar);
|
||||
int pn53x_target_send_bytes (struct nfc_device *pnd, const uint8_t *pbtTx, const size_t szTx, int timeout);
|
||||
int pn53x_target_init(struct nfc_device *pnd, nfc_target *pnt, uint8_t *pbtRx, const size_t szRxLen, int timeout);
|
||||
int pn53x_target_receive_bits(struct nfc_device *pnd, uint8_t *pbtRx, const size_t szRxLen, uint8_t *pbtRxPar);
|
||||
int pn53x_target_receive_bytes(struct nfc_device *pnd, uint8_t *pbtRx, const size_t szRxLen, int timeout);
|
||||
int pn53x_target_send_bits(struct nfc_device *pnd, const uint8_t *pbtTx, const size_t szTxBits, const uint8_t *pbtTxPar);
|
||||
int pn53x_target_send_bytes(struct nfc_device *pnd, const uint8_t *pbtTx, const size_t szTx, int timeout);
|
||||
|
||||
// Error handling functions
|
||||
const char *pn53x_strerror (const struct nfc_device *pnd);
|
||||
const char *pn53x_strerror(const struct nfc_device *pnd);
|
||||
|
||||
// C wrappers for PN53x commands
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
|
||||
// RFConfiguration
|
||||
int pn53x_RFConfiguration__RF_field (struct nfc_device *pnd, bool bEnable);
|
||||
int pn53x_RFConfiguration__Various_timings (struct nfc_device *pnd, const uint8_t fATR_RES_Timeout, const uint8_t fRetryTimeout);
|
||||
int pn53x_RFConfiguration__MaxRtyCOM (struct nfc_device *pnd, const uint8_t MaxRtyCOM);
|
||||
int pn53x_RFConfiguration__MaxRetries (struct nfc_device *pnd, const uint8_t MxRtyATR, const uint8_t MxRtyPSL, const uint8_t MxRtyPassiveActivation);
|
||||
int pn53x_RFConfiguration__RF_field(struct nfc_device *pnd, bool bEnable);
|
||||
int pn53x_RFConfiguration__Various_timings(struct nfc_device *pnd, const uint8_t fATR_RES_Timeout, const uint8_t fRetryTimeout);
|
||||
int pn53x_RFConfiguration__MaxRtyCOM(struct nfc_device *pnd, const uint8_t MaxRtyCOM);
|
||||
int pn53x_RFConfiguration__MaxRetries(struct nfc_device *pnd, const uint8_t MxRtyATR, const uint8_t MxRtyPSL, const uint8_t MxRtyPassiveActivation);
|
||||
|
||||
// Misc
|
||||
int pn53x_check_ack_frame (struct nfc_device *pnd, const uint8_t *pbtRxFrame, const size_t szRxFrameLen);
|
||||
int pn53x_check_error_frame (struct nfc_device *pnd, const uint8_t *pbtRxFrame, const size_t szRxFrameLen);
|
||||
int pn53x_build_frame (uint8_t *pbtFrame, size_t *pszFrame, const uint8_t *pbtData, const size_t szData);
|
||||
int pn53x_get_supported_modulation (nfc_device *pnd, const nfc_mode mode, const nfc_modulation_type **const supported_mt);
|
||||
int pn53x_get_supported_baud_rate (nfc_device *pnd, const nfc_modulation_type nmt, const nfc_baud_rate **const supported_br);
|
||||
int pn53x_get_information_about (nfc_device *pnd, char *buf, size_t buflen);
|
||||
int pn53x_check_ack_frame(struct nfc_device *pnd, const uint8_t *pbtRxFrame, const size_t szRxFrameLen);
|
||||
int pn53x_check_error_frame(struct nfc_device *pnd, const uint8_t *pbtRxFrame, const size_t szRxFrameLen);
|
||||
int pn53x_build_frame(uint8_t *pbtFrame, size_t *pszFrame, const uint8_t *pbtData, const size_t szData);
|
||||
int pn53x_get_supported_modulation(nfc_device *pnd, const nfc_mode mode, const nfc_modulation_type **const supported_mt);
|
||||
int pn53x_get_supported_baud_rate(nfc_device *pnd, const nfc_modulation_type nmt, const nfc_baud_rate **const supported_br);
|
||||
int pn53x_get_information_about(nfc_device *pnd, char *buf, size_t buflen);
|
||||
|
||||
void pn53x_data_new (struct nfc_device *pnd, const struct pn53x_io *io);
|
||||
void pn53x_data_free (struct nfc_device *pnd);
|
||||
void pn53x_data_new(struct nfc_device *pnd, const struct pn53x_io *io);
|
||||
void pn53x_data_free(struct nfc_device *pnd);
|
||||
|
||||
#endif // __NFC_CHIPS_PN53X_H__
|
||||
|
|
|
|||
|
|
@ -83,7 +83,7 @@
|
|||
|
||||
const struct pn53x_io acr122_pcsc_io;
|
||||
|
||||
char *acr122_pcsc_firmware (nfc_device *pnd);
|
||||
char *acr122_pcsc_firmware(nfc_device *pnd);
|
||||
|
||||
const char *supported_devices[] = {
|
||||
"ACS ACR122", // ACR122U & Touchatag, last version
|
||||
|
|
@ -106,10 +106,10 @@ static SCARDCONTEXT _SCardContext;
|
|||
static int _iSCardContextRefCount = 0;
|
||||
|
||||
static SCARDCONTEXT *
|
||||
acr122_pcsc_get_scardcontext (void)
|
||||
acr122_pcsc_get_scardcontext(void)
|
||||
{
|
||||
if (_iSCardContextRefCount == 0) {
|
||||
if (SCardEstablishContext (SCARD_SCOPE_USER, NULL, NULL, &_SCardContext) != SCARD_S_SUCCESS)
|
||||
if (SCardEstablishContext(SCARD_SCOPE_USER, NULL, NULL, &_SCardContext) != SCARD_S_SUCCESS)
|
||||
return NULL;
|
||||
}
|
||||
_iSCardContextRefCount++;
|
||||
|
|
@ -118,12 +118,12 @@ acr122_pcsc_get_scardcontext (void)
|
|||
}
|
||||
|
||||
static void
|
||||
acr122_pcsc_free_scardcontext (void)
|
||||
acr122_pcsc_free_scardcontext(void)
|
||||
{
|
||||
if (_iSCardContextRefCount) {
|
||||
_iSCardContextRefCount--;
|
||||
if (!_iSCardContextRefCount) {
|
||||
SCardReleaseContext (_SCardContext);
|
||||
SCardReleaseContext(_SCardContext);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -140,28 +140,28 @@ acr122_pcsc_free_scardcontext (void)
|
|||
* @return true if succeeded, false otherwise.
|
||||
*/
|
||||
bool
|
||||
acr122_pcsc_probe (nfc_connstring connstrings[], size_t connstrings_len, size_t *pszDeviceFound)
|
||||
acr122_pcsc_probe(nfc_connstring connstrings[], size_t connstrings_len, size_t *pszDeviceFound)
|
||||
{
|
||||
size_t szPos = 0;
|
||||
char acDeviceNames[256 + 64 * PCSC_MAX_DEVICES];
|
||||
size_t szDeviceNamesLen = sizeof (acDeviceNames);
|
||||
size_t szDeviceNamesLen = sizeof(acDeviceNames);
|
||||
SCARDCONTEXT *pscc;
|
||||
bool bSupported;
|
||||
int i;
|
||||
|
||||
// Clear the reader list
|
||||
memset (acDeviceNames, '\0', szDeviceNamesLen);
|
||||
memset(acDeviceNames, '\0', szDeviceNamesLen);
|
||||
|
||||
*pszDeviceFound = 0;
|
||||
|
||||
// Test if context succeeded
|
||||
if (!(pscc = acr122_pcsc_get_scardcontext ())) {
|
||||
log_put (LOG_CATEGORY, NFC_PRIORITY_WARN, "%s", "PCSC context not found (make sure PCSC daemon is running).");
|
||||
if (!(pscc = acr122_pcsc_get_scardcontext())) {
|
||||
log_put(LOG_CATEGORY, NFC_PRIORITY_WARN, "%s", "PCSC context not found (make sure PCSC daemon is running).");
|
||||
return false;
|
||||
}
|
||||
// Retrieve the string array of all available pcsc readers
|
||||
DWORD dwDeviceNamesLen = szDeviceNamesLen;
|
||||
if (SCardListReaders (*pscc, NULL, acDeviceNames, &dwDeviceNamesLen) != SCARD_S_SUCCESS)
|
||||
if (SCardListReaders(*pscc, NULL, acDeviceNames, &dwDeviceNamesLen) != SCARD_S_SUCCESS)
|
||||
return false;
|
||||
|
||||
while ((acDeviceNames[szPos] != '\0') && ((*pszDeviceFound) < connstrings_len)) {
|
||||
|
|
@ -170,22 +170,22 @@ acr122_pcsc_probe (nfc_connstring connstrings[], size_t connstrings_len, size_t
|
|||
|
||||
bSupported = false;
|
||||
for (i = 0; supported_devices[i] && !bSupported; i++) {
|
||||
int l = strlen (supported_devices[i]);
|
||||
bSupported = 0 == strncmp (supported_devices[i], acDeviceNames + szPos, l);
|
||||
int l = strlen(supported_devices[i]);
|
||||
bSupported = 0 == strncmp(supported_devices[i], acDeviceNames + szPos, l);
|
||||
}
|
||||
|
||||
if (bSupported) {
|
||||
// Supported ACR122 device found
|
||||
snprintf (connstrings[*pszDeviceFound], sizeof(nfc_connstring), "%s:%s", ACR122_PCSC_DRIVER_NAME, acDeviceNames + szPos);
|
||||
snprintf(connstrings[*pszDeviceFound], sizeof(nfc_connstring), "%s:%s", ACR122_PCSC_DRIVER_NAME, acDeviceNames + szPos);
|
||||
(*pszDeviceFound)++;
|
||||
} else {
|
||||
log_put (LOG_CATEGORY, NFC_PRIORITY_TRACE, "PCSC device [%s] is not NFC capable or not supported by libnfc.", acDeviceNames + szPos);
|
||||
log_put(LOG_CATEGORY, NFC_PRIORITY_TRACE, "PCSC device [%s] is not NFC capable or not supported by libnfc.", acDeviceNames + szPos);
|
||||
}
|
||||
|
||||
// Find next device name position
|
||||
while (acDeviceNames[szPos++] != '\0');
|
||||
}
|
||||
acr122_pcsc_free_scardcontext ();
|
||||
acr122_pcsc_free_scardcontext();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
@ -195,48 +195,48 @@ struct acr122_pcsc_descriptor {
|
|||
};
|
||||
|
||||
static int
|
||||
acr122_pcsc_connstring_decode (const nfc_connstring connstring, struct acr122_pcsc_descriptor *desc)
|
||||
acr122_pcsc_connstring_decode(const nfc_connstring connstring, struct acr122_pcsc_descriptor *desc)
|
||||
{
|
||||
char *cs = malloc (strlen (connstring) + 1);
|
||||
char *cs = malloc(strlen(connstring) + 1);
|
||||
if (!cs) {
|
||||
perror ("malloc");
|
||||
perror("malloc");
|
||||
return -1;
|
||||
}
|
||||
strcpy (cs, connstring);
|
||||
const char *driver_name = strtok (cs, ":");
|
||||
strcpy(cs, connstring);
|
||||
const char *driver_name = strtok(cs, ":");
|
||||
if (!driver_name) {
|
||||
// Parse error
|
||||
free (cs);
|
||||
free(cs);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (0 != strcmp (driver_name, ACR122_PCSC_DRIVER_NAME)) {
|
||||
if (0 != strcmp(driver_name, ACR122_PCSC_DRIVER_NAME)) {
|
||||
// Driver name does not match.
|
||||
free (cs);
|
||||
free(cs);
|
||||
return 0;
|
||||
}
|
||||
|
||||
const char *device_name = strtok (NULL, ":");
|
||||
const char *device_name = strtok(NULL, ":");
|
||||
if (!device_name) {
|
||||
// Only driver name was specified (or parsing error)
|
||||
free (cs);
|
||||
free(cs);
|
||||
return 1;
|
||||
}
|
||||
strncpy (desc->pcsc_device_name, device_name, sizeof(desc->pcsc_device_name) - 1);
|
||||
strncpy(desc->pcsc_device_name, device_name, sizeof(desc->pcsc_device_name) - 1);
|
||||
desc->pcsc_device_name[sizeof(desc->pcsc_device_name) - 1] = '\0';
|
||||
|
||||
free (cs);
|
||||
free(cs);
|
||||
return 2;
|
||||
|
||||
free (cs);
|
||||
free(cs);
|
||||
return 3;
|
||||
}
|
||||
|
||||
nfc_device *
|
||||
acr122_pcsc_open (const nfc_connstring connstring)
|
||||
acr122_pcsc_open(const nfc_connstring connstring)
|
||||
{
|
||||
struct acr122_pcsc_descriptor ndd;
|
||||
int connstring_decode_level = acr122_pcsc_connstring_decode (connstring, &ndd);
|
||||
int connstring_decode_level = acr122_pcsc_connstring_decode(connstring, &ndd);
|
||||
|
||||
if (connstring_decode_level < 1) {
|
||||
return NULL;
|
||||
|
|
@ -249,7 +249,7 @@ acr122_pcsc_open (const nfc_connstring connstring)
|
|||
acr122_pcsc_probe(&fullconnstring, 1, &szDeviceFound);
|
||||
if (szDeviceFound < 1)
|
||||
return NULL;
|
||||
connstring_decode_level = acr122_pcsc_connstring_decode (fullconnstring, &ndd);
|
||||
connstring_decode_level = acr122_pcsc_connstring_decode(fullconnstring, &ndd);
|
||||
if (connstring_decode_level < 2) {
|
||||
return NULL;
|
||||
}
|
||||
|
|
@ -259,82 +259,82 @@ acr122_pcsc_open (const nfc_connstring connstring)
|
|||
if (strlen(ndd.pcsc_device_name) < 5) { // We can assume it's a reader ID as pcsc_name always ends with "NN NN"
|
||||
// Device was not specified, only ID, retrieve it
|
||||
size_t index;
|
||||
if (sscanf (ndd.pcsc_device_name, "%lu", &index) != 1)
|
||||
if (sscanf(ndd.pcsc_device_name, "%lu", &index) != 1)
|
||||
return NULL;
|
||||
nfc_connstring *ncs = malloc (sizeof (nfc_connstring) * (index + 1));
|
||||
nfc_connstring *ncs = malloc(sizeof(nfc_connstring) * (index + 1));
|
||||
size_t szDeviceFound;
|
||||
acr122_pcsc_probe(ncs, index + 1, &szDeviceFound);
|
||||
if (szDeviceFound < index + 1)
|
||||
return NULL;
|
||||
strncpy(fullconnstring, ncs[index], sizeof(nfc_connstring));
|
||||
free(ncs);
|
||||
connstring_decode_level = acr122_pcsc_connstring_decode (fullconnstring, &ndd);
|
||||
connstring_decode_level = acr122_pcsc_connstring_decode(fullconnstring, &ndd);
|
||||
if (connstring_decode_level < 2) {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
char *pcFirmware;
|
||||
nfc_device *pnd = nfc_device_new (fullconnstring);
|
||||
pnd->driver_data = malloc (sizeof (struct acr122_pcsc_data));
|
||||
nfc_device *pnd = nfc_device_new(fullconnstring);
|
||||
pnd->driver_data = malloc(sizeof(struct acr122_pcsc_data));
|
||||
|
||||
// Alloc and init chip's data
|
||||
pn53x_data_new (pnd, &acr122_pcsc_io);
|
||||
pn53x_data_new(pnd, &acr122_pcsc_io);
|
||||
|
||||
SCARDCONTEXT *pscc;
|
||||
|
||||
log_put (LOG_CATEGORY, NFC_PRIORITY_TRACE, "Attempt to open %s", ndd.pcsc_device_name);
|
||||
log_put(LOG_CATEGORY, NFC_PRIORITY_TRACE, "Attempt to open %s", ndd.pcsc_device_name);
|
||||
// Test if context succeeded
|
||||
if (!(pscc = acr122_pcsc_get_scardcontext ()))
|
||||
if (!(pscc = acr122_pcsc_get_scardcontext()))
|
||||
goto error;
|
||||
// Test if we were able to connect to the "emulator" card
|
||||
if (SCardConnect (*pscc, ndd.pcsc_device_name, SCARD_SHARE_EXCLUSIVE, SCARD_PROTOCOL_T0 | SCARD_PROTOCOL_T1, &(DRIVER_DATA (pnd)->hCard), (void *) & (DRIVER_DATA (pnd)->ioCard.dwProtocol)) != SCARD_S_SUCCESS) {
|
||||
if (SCardConnect(*pscc, ndd.pcsc_device_name, SCARD_SHARE_EXCLUSIVE, SCARD_PROTOCOL_T0 | SCARD_PROTOCOL_T1, &(DRIVER_DATA(pnd)->hCard), (void *) & (DRIVER_DATA(pnd)->ioCard.dwProtocol)) != SCARD_S_SUCCESS) {
|
||||
// Connect to ACR122 firmware version >2.0
|
||||
if (SCardConnect (*pscc, ndd.pcsc_device_name, SCARD_SHARE_DIRECT, 0, &(DRIVER_DATA (pnd)->hCard), (void *) & (DRIVER_DATA (pnd)->ioCard.dwProtocol)) != SCARD_S_SUCCESS) {
|
||||
if (SCardConnect(*pscc, ndd.pcsc_device_name, SCARD_SHARE_DIRECT, 0, &(DRIVER_DATA(pnd)->hCard), (void *) & (DRIVER_DATA(pnd)->ioCard.dwProtocol)) != SCARD_S_SUCCESS) {
|
||||
// We can not connect to this device.
|
||||
log_put (LOG_CATEGORY, NFC_PRIORITY_TRACE, "%s", "PCSC connect failed");
|
||||
log_put(LOG_CATEGORY, NFC_PRIORITY_TRACE, "%s", "PCSC connect failed");
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
// Configure I/O settings for card communication
|
||||
DRIVER_DATA (pnd)->ioCard.cbPciLength = sizeof (SCARD_IO_REQUEST);
|
||||
DRIVER_DATA(pnd)->ioCard.cbPciLength = sizeof(SCARD_IO_REQUEST);
|
||||
|
||||
// Retrieve the current firmware version
|
||||
pcFirmware = acr122_pcsc_firmware (pnd);
|
||||
if (strstr (pcFirmware, FIRMWARE_TEXT) != NULL) {
|
||||
pcFirmware = acr122_pcsc_firmware(pnd);
|
||||
if (strstr(pcFirmware, FIRMWARE_TEXT) != NULL) {
|
||||
|
||||
// Done, we found the reader we are looking for
|
||||
snprintf (pnd->name, sizeof (pnd->name), "%s / %s", ndd.pcsc_device_name, pcFirmware);
|
||||
snprintf(pnd->name, sizeof(pnd->name), "%s / %s", ndd.pcsc_device_name, pcFirmware);
|
||||
|
||||
// 50: empirical tuning on Touchatag
|
||||
// 46: empirical tuning on ACR122U
|
||||
CHIP_DATA (pnd)->timer_correction = 50;
|
||||
CHIP_DATA(pnd)->timer_correction = 50;
|
||||
|
||||
pnd->driver = &acr122_pcsc_driver;
|
||||
|
||||
pn53x_init (pnd);
|
||||
pn53x_init(pnd);
|
||||
|
||||
return pnd;
|
||||
}
|
||||
|
||||
error:
|
||||
nfc_device_free (pnd);
|
||||
nfc_device_free(pnd);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void
|
||||
acr122_pcsc_close (nfc_device *pnd)
|
||||
acr122_pcsc_close(nfc_device *pnd)
|
||||
{
|
||||
SCardDisconnect (DRIVER_DATA (pnd)->hCard, SCARD_LEAVE_CARD);
|
||||
acr122_pcsc_free_scardcontext ();
|
||||
SCardDisconnect(DRIVER_DATA(pnd)->hCard, SCARD_LEAVE_CARD);
|
||||
acr122_pcsc_free_scardcontext();
|
||||
|
||||
pn53x_data_free (pnd);
|
||||
nfc_device_free (pnd);
|
||||
pn53x_data_free(pnd);
|
||||
nfc_device_free(pnd);
|
||||
}
|
||||
|
||||
int
|
||||
acr122_pcsc_send (nfc_device *pnd, const uint8_t *pbtData, const size_t szData, int timeout)
|
||||
acr122_pcsc_send(nfc_device *pnd, const uint8_t *pbtData, const size_t szData, int timeout)
|
||||
{
|
||||
// FIXME: timeout is not handled
|
||||
(void) timeout;
|
||||
|
|
@ -348,14 +348,14 @@ acr122_pcsc_send (nfc_device *pnd, const uint8_t *pbtData, const size_t szData,
|
|||
// Prepare and transmit the send buffer
|
||||
const size_t szTxBuf = szData + 6;
|
||||
uint8_t abtTxBuf[ACR122_PCSC_WRAP_LEN + ACR122_PCSC_COMMAND_LEN] = { 0xFF, 0x00, 0x00, 0x00, szData + 1, 0xD4 };
|
||||
memcpy (abtTxBuf + 6, pbtData, szData);
|
||||
LOG_HEX ("TX", abtTxBuf, szTxBuf);
|
||||
memcpy(abtTxBuf + 6, pbtData, szData);
|
||||
LOG_HEX("TX", abtTxBuf, szTxBuf);
|
||||
|
||||
DRIVER_DATA (pnd)->szRx = 0;
|
||||
DRIVER_DATA(pnd)->szRx = 0;
|
||||
|
||||
DWORD dwRxLen = sizeof (DRIVER_DATA (pnd)->abtRx);
|
||||
DWORD dwRxLen = sizeof(DRIVER_DATA(pnd)->abtRx);
|
||||
|
||||
if (DRIVER_DATA (pnd)->ioCard.dwProtocol == SCARD_PROTOCOL_UNDEFINED) {
|
||||
if (DRIVER_DATA(pnd)->ioCard.dwProtocol == SCARD_PROTOCOL_UNDEFINED) {
|
||||
/*
|
||||
* In this communication mode, we directly have the response from the
|
||||
* PN532. Save it in the driver data structure so that it can be retrieved
|
||||
|
|
@ -367,7 +367,7 @@ acr122_pcsc_send (nfc_device *pnd, const uint8_t *pbtData, const size_t szData,
|
|||
* This state is generaly reached when the ACR122 has no target in it's
|
||||
* field.
|
||||
*/
|
||||
if (SCardControl (DRIVER_DATA (pnd)->hCard, IOCTL_CCID_ESCAPE_SCARD_CTL_CODE, abtTxBuf, szTxBuf, DRIVER_DATA (pnd)->abtRx, ACR122_PCSC_RESPONSE_LEN, &dwRxLen) != SCARD_S_SUCCESS) {
|
||||
if (SCardControl(DRIVER_DATA(pnd)->hCard, IOCTL_CCID_ESCAPE_SCARD_CTL_CODE, abtTxBuf, szTxBuf, DRIVER_DATA(pnd)->abtRx, ACR122_PCSC_RESPONSE_LEN, &dwRxLen) != SCARD_S_SUCCESS) {
|
||||
pnd->last_error = NFC_EIO;
|
||||
return pnd->last_error;
|
||||
}
|
||||
|
|
@ -376,13 +376,13 @@ acr122_pcsc_send (nfc_device *pnd, const uint8_t *pbtData, const size_t szData,
|
|||
* In T=0 mode, we receive an acknoledge from the MCU, in T=1 mode, we
|
||||
* receive the response from the PN532.
|
||||
*/
|
||||
if (SCardTransmit (DRIVER_DATA (pnd)->hCard, &(DRIVER_DATA (pnd)->ioCard), abtTxBuf, szTxBuf, NULL, DRIVER_DATA (pnd)->abtRx, &dwRxLen) != SCARD_S_SUCCESS) {
|
||||
if (SCardTransmit(DRIVER_DATA(pnd)->hCard, &(DRIVER_DATA(pnd)->ioCard), abtTxBuf, szTxBuf, NULL, DRIVER_DATA(pnd)->abtRx, &dwRxLen) != SCARD_S_SUCCESS) {
|
||||
pnd->last_error = NFC_EIO;
|
||||
return pnd->last_error;
|
||||
}
|
||||
}
|
||||
|
||||
if (DRIVER_DATA (pnd)->ioCard.dwProtocol == SCARD_PROTOCOL_T0) {
|
||||
if (DRIVER_DATA(pnd)->ioCard.dwProtocol == SCARD_PROTOCOL_T0) {
|
||||
/*
|
||||
* Check the MCU response
|
||||
*/
|
||||
|
|
@ -393,19 +393,19 @@ acr122_pcsc_send (nfc_device *pnd, const uint8_t *pbtData, const size_t szData,
|
|||
return pnd->last_error;
|
||||
}
|
||||
// Check if the operation was successful, so an answer is available
|
||||
if (DRIVER_DATA (pnd)->abtRx[0] == SCARD_OPERATION_ERROR) {
|
||||
if (DRIVER_DATA(pnd)->abtRx[0] == SCARD_OPERATION_ERROR) {
|
||||
pnd->last_error = NFC_EIO;
|
||||
return pnd->last_error;
|
||||
}
|
||||
} else {
|
||||
DRIVER_DATA (pnd)->szRx = dwRxLen;
|
||||
DRIVER_DATA(pnd)->szRx = dwRxLen;
|
||||
}
|
||||
|
||||
return NFC_SUCCESS;
|
||||
}
|
||||
|
||||
int
|
||||
acr122_pcsc_receive (nfc_device *pnd, uint8_t *pbtData, const size_t szData, int timeout)
|
||||
acr122_pcsc_receive(nfc_device *pnd, uint8_t *pbtData, const size_t szData, int timeout)
|
||||
{
|
||||
// FIXME: timeout is not handled
|
||||
(void) timeout;
|
||||
|
|
@ -413,53 +413,53 @@ acr122_pcsc_receive (nfc_device *pnd, uint8_t *pbtData, const size_t szData, int
|
|||
int len;
|
||||
uint8_t abtRxCmd[5] = { 0xFF, 0xC0, 0x00, 0x00 };
|
||||
|
||||
if (DRIVER_DATA (pnd)->ioCard.dwProtocol == SCARD_PROTOCOL_T0) {
|
||||
if (DRIVER_DATA(pnd)->ioCard.dwProtocol == SCARD_PROTOCOL_T0) {
|
||||
/*
|
||||
* Retrieve the PN532 response.
|
||||
*/
|
||||
DWORD dwRxLen = sizeof (DRIVER_DATA (pnd)->abtRx);
|
||||
abtRxCmd[4] = DRIVER_DATA (pnd)->abtRx[1];
|
||||
if (SCardTransmit (DRIVER_DATA (pnd)->hCard, &(DRIVER_DATA (pnd)->ioCard), abtRxCmd, sizeof (abtRxCmd), NULL, DRIVER_DATA (pnd)->abtRx, &dwRxLen) != SCARD_S_SUCCESS) {
|
||||
DWORD dwRxLen = sizeof(DRIVER_DATA(pnd)->abtRx);
|
||||
abtRxCmd[4] = DRIVER_DATA(pnd)->abtRx[1];
|
||||
if (SCardTransmit(DRIVER_DATA(pnd)->hCard, &(DRIVER_DATA(pnd)->ioCard), abtRxCmd, sizeof(abtRxCmd), NULL, DRIVER_DATA(pnd)->abtRx, &dwRxLen) != SCARD_S_SUCCESS) {
|
||||
pnd->last_error = NFC_EIO;
|
||||
return pnd->last_error;
|
||||
}
|
||||
DRIVER_DATA (pnd)->szRx = dwRxLen;
|
||||
DRIVER_DATA(pnd)->szRx = dwRxLen;
|
||||
} else {
|
||||
/*
|
||||
* We already have the PN532 answer, it was saved by acr122_pcsc_send().
|
||||
*/
|
||||
}
|
||||
LOG_HEX ("RX", DRIVER_DATA (pnd)->abtRx, DRIVER_DATA (pnd)->szRx);
|
||||
LOG_HEX("RX", DRIVER_DATA(pnd)->abtRx, DRIVER_DATA(pnd)->szRx);
|
||||
|
||||
// Make sure we have an emulated answer that fits the return buffer
|
||||
if (DRIVER_DATA (pnd)->szRx < 4 || (DRIVER_DATA (pnd)->szRx - 4) > szData) {
|
||||
if (DRIVER_DATA(pnd)->szRx < 4 || (DRIVER_DATA(pnd)->szRx - 4) > szData) {
|
||||
pnd->last_error = NFC_EIO;
|
||||
return pnd->last_error;
|
||||
}
|
||||
// Wipe out the 4 APDU emulation bytes: D5 4B .. .. .. 90 00
|
||||
len = DRIVER_DATA (pnd)->szRx - 4;
|
||||
memcpy (pbtData, DRIVER_DATA (pnd)->abtRx + 2, len);
|
||||
len = DRIVER_DATA(pnd)->szRx - 4;
|
||||
memcpy(pbtData, DRIVER_DATA(pnd)->abtRx + 2, len);
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
char *
|
||||
acr122_pcsc_firmware (nfc_device *pnd)
|
||||
acr122_pcsc_firmware(nfc_device *pnd)
|
||||
{
|
||||
uint8_t abtGetFw[5] = { 0xFF, 0x00, 0x48, 0x00, 0x00 };
|
||||
uint32_t uiResult;
|
||||
|
||||
static char abtFw[11];
|
||||
DWORD dwFwLen = sizeof (abtFw);
|
||||
memset (abtFw, 0x00, sizeof (abtFw));
|
||||
if (DRIVER_DATA (pnd)->ioCard.dwProtocol == SCARD_PROTOCOL_UNDEFINED) {
|
||||
uiResult = SCardControl (DRIVER_DATA (pnd)->hCard, IOCTL_CCID_ESCAPE_SCARD_CTL_CODE, abtGetFw, sizeof (abtGetFw), (uint8_t *) abtFw, dwFwLen - 1, &dwFwLen);
|
||||
DWORD dwFwLen = sizeof(abtFw);
|
||||
memset(abtFw, 0x00, sizeof(abtFw));
|
||||
if (DRIVER_DATA(pnd)->ioCard.dwProtocol == SCARD_PROTOCOL_UNDEFINED) {
|
||||
uiResult = SCardControl(DRIVER_DATA(pnd)->hCard, IOCTL_CCID_ESCAPE_SCARD_CTL_CODE, abtGetFw, sizeof(abtGetFw), (uint8_t *) abtFw, dwFwLen - 1, &dwFwLen);
|
||||
} else {
|
||||
uiResult = SCardTransmit (DRIVER_DATA (pnd)->hCard, &(DRIVER_DATA (pnd)->ioCard), abtGetFw, sizeof (abtGetFw), NULL, (uint8_t *) abtFw, &dwFwLen);
|
||||
uiResult = SCardTransmit(DRIVER_DATA(pnd)->hCard, &(DRIVER_DATA(pnd)->ioCard), abtGetFw, sizeof(abtGetFw), NULL, (uint8_t *) abtFw, &dwFwLen);
|
||||
}
|
||||
|
||||
if (uiResult != SCARD_S_SUCCESS) {
|
||||
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "No ACR122 firmware received, Error: %08x", uiResult);
|
||||
log_put(LOG_CATEGORY, NFC_PRIORITY_ERROR, "No ACR122 firmware received, Error: %08x", uiResult);
|
||||
}
|
||||
|
||||
return abtFw;
|
||||
|
|
@ -467,16 +467,16 @@ acr122_pcsc_firmware (nfc_device *pnd)
|
|||
|
||||
#if 0
|
||||
bool
|
||||
acr122_pcsc_led_red (nfc_device *pnd, bool bOn)
|
||||
acr122_pcsc_led_red(nfc_device *pnd, bool bOn)
|
||||
{
|
||||
uint8_t abtLed[9] = { 0xFF, 0x00, 0x40, 0x05, 0x04, 0x00, 0x00, 0x00, 0x00 };
|
||||
uint8_t abtBuf[2];
|
||||
DWORD dwBufLen = sizeof (abtBuf);
|
||||
DWORD dwBufLen = sizeof(abtBuf);
|
||||
(void) bOn;
|
||||
if (DRIVER_DATA (pnd)->ioCard.dwProtocol == SCARD_PROTOCOL_UNDEFINED) {
|
||||
return (SCardControl (DRIVER_DATA (pnd)->hCard, IOCTL_CCID_ESCAPE_SCARD_CTL_CODE, abtLed, sizeof (abtLed), abtBuf, dwBufLen, &dwBufLen) == SCARD_S_SUCCESS);
|
||||
if (DRIVER_DATA(pnd)->ioCard.dwProtocol == SCARD_PROTOCOL_UNDEFINED) {
|
||||
return (SCardControl(DRIVER_DATA(pnd)->hCard, IOCTL_CCID_ESCAPE_SCARD_CTL_CODE, abtLed, sizeof(abtLed), abtBuf, dwBufLen, &dwBufLen) == SCARD_S_SUCCESS);
|
||||
} else {
|
||||
return (SCardTransmit (DRIVER_DATA (pnd)->hCard, &(DRIVER_DATA (pnd)->ioCard), abtLed, sizeof (abtLed), NULL, abtBuf, &dwBufLen) == SCARD_S_SUCCESS);
|
||||
return (SCardTransmit(DRIVER_DATA(pnd)->hCard, &(DRIVER_DATA(pnd)->ioCard), abtLed, sizeof(abtLed), NULL, abtBuf, &dwBufLen) == SCARD_S_SUCCESS);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -28,13 +28,13 @@
|
|||
|
||||
# include <nfc/nfc-types.h>
|
||||
|
||||
bool acr122_pcsc_probe (nfc_connstring connstrings[], size_t connstrings_len, size_t *pszDeviceFound);
|
||||
bool acr122_pcsc_probe(nfc_connstring connstrings[], size_t connstrings_len, size_t *pszDeviceFound);
|
||||
|
||||
// Functions used by developer to handle connection to this device
|
||||
nfc_device *acr122_pcsc_open (const nfc_connstring connstring);
|
||||
int acr122_pcsc_send (nfc_device *pnd, const uint8_t *pbtData, const size_t szData, int timeout);
|
||||
int acr122_pcsc_receive (nfc_device *pnd, uint8_t *pbtData, const size_t szData, int timeout);
|
||||
void acr122_pcsc_close (nfc_device *pnd);
|
||||
nfc_device *acr122_pcsc_open(const nfc_connstring connstring);
|
||||
int acr122_pcsc_send(nfc_device *pnd, const uint8_t *pbtData, const size_t szData, int timeout);
|
||||
int acr122_pcsc_receive(nfc_device *pnd, uint8_t *pbtData, const size_t szData, int timeout);
|
||||
void acr122_pcsc_close(nfc_device *pnd);
|
||||
|
||||
extern const struct nfc_driver acr122_pcsc_driver;
|
||||
|
||||
|
|
|
|||
|
|
@ -99,20 +99,20 @@ struct acr122_usb_data {
|
|||
};
|
||||
|
||||
const struct pn53x_io acr122_usb_io;
|
||||
bool acr122_usb_get_usb_device_name (struct usb_device *dev, usb_dev_handle *udev, char *buffer, size_t len);
|
||||
int acr122_usb_init (nfc_device *pnd);
|
||||
int acr122_usb_ack (nfc_device *pnd);
|
||||
bool acr122_usb_get_usb_device_name(struct usb_device *dev, usb_dev_handle *udev, char *buffer, size_t len);
|
||||
int acr122_usb_init(nfc_device *pnd);
|
||||
int acr122_usb_ack(nfc_device *pnd);
|
||||
|
||||
static int
|
||||
acr122_usb_bulk_read (struct acr122_usb_data *data, uint8_t abtRx[], const size_t szRx, const int timeout)
|
||||
acr122_usb_bulk_read(struct acr122_usb_data *data, uint8_t abtRx[], const size_t szRx, const int timeout)
|
||||
{
|
||||
int res = usb_bulk_read (data->pudh, data->uiEndPointIn, (char *) abtRx, szRx, timeout);
|
||||
int res = usb_bulk_read(data->pudh, data->uiEndPointIn, (char *) abtRx, szRx, timeout);
|
||||
if (res > 0) {
|
||||
LOG_HEX ("RX", abtRx, res);
|
||||
LOG_HEX("RX", abtRx, res);
|
||||
} else if (res < 0) {
|
||||
if (res != -USB_TIMEDOUT) {
|
||||
res = NFC_EIO;
|
||||
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "Unable to read from USB (%s)", _usb_strerror (res));
|
||||
log_put(LOG_CATEGORY, NFC_PRIORITY_ERROR, "Unable to read from USB (%s)", _usb_strerror(res));
|
||||
} else {
|
||||
res = NFC_ETIMEOUT;
|
||||
}
|
||||
|
|
@ -121,17 +121,17 @@ acr122_usb_bulk_read (struct acr122_usb_data *data, uint8_t abtRx[], const size_
|
|||
}
|
||||
|
||||
static int
|
||||
acr122_usb_bulk_write (struct acr122_usb_data *data, uint8_t abtTx[], const size_t szTx, const int timeout)
|
||||
acr122_usb_bulk_write(struct acr122_usb_data *data, uint8_t abtTx[], const size_t szTx, const int timeout)
|
||||
{
|
||||
LOG_HEX ("TX", abtTx, szTx);
|
||||
int res = usb_bulk_write (data->pudh, data->uiEndPointOut, (char *) abtTx, szTx, timeout);
|
||||
LOG_HEX("TX", abtTx, szTx);
|
||||
int res = usb_bulk_write(data->pudh, data->uiEndPointOut, (char *) abtTx, szTx, timeout);
|
||||
if (res > 0) {
|
||||
// HACK This little hack is a well know problem of USB, see http://www.libusb.org/ticket/6 for more details
|
||||
if ((res % data->uiMaxPacketSize) == 0) {
|
||||
usb_bulk_write (data->pudh, data->uiEndPointOut, "\0", 0, timeout);
|
||||
usb_bulk_write(data->pudh, data->uiEndPointOut, "\0", 0, timeout);
|
||||
}
|
||||
} else if (res < 0) {
|
||||
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "Unable to write to USB (%s)", _usb_strerror (res));
|
||||
log_put(LOG_CATEGORY, NFC_PRIORITY_ERROR, "Unable to write to USB (%s)", _usb_strerror(res));
|
||||
if (res == -USB_TIMEDOUT) {
|
||||
res = NFC_ETIMEOUT;
|
||||
} else {
|
||||
|
|
@ -154,9 +154,9 @@ const struct acr122_usb_supported_device acr122_usb_supported_devices[] = {
|
|||
};
|
||||
|
||||
static acr122_usb_model
|
||||
acr122_usb_get_device_model (uint16_t vendor_id, uint16_t product_id)
|
||||
acr122_usb_get_device_model(uint16_t vendor_id, uint16_t product_id)
|
||||
{
|
||||
for (size_t n = 0; n < sizeof (acr122_usb_supported_devices) / sizeof (struct acr122_usb_supported_device); n++) {
|
||||
for (size_t n = 0; n < sizeof(acr122_usb_supported_devices) / sizeof(struct acr122_usb_supported_device); n++) {
|
||||
if ((vendor_id == acr122_usb_supported_devices[n].vendor_id) &&
|
||||
(product_id == acr122_usb_supported_devices[n].product_id))
|
||||
return acr122_usb_supported_devices[n].model;
|
||||
|
|
@ -167,7 +167,7 @@ acr122_usb_get_device_model (uint16_t vendor_id, uint16_t product_id)
|
|||
|
||||
// Find transfer endpoints for bulk transfers
|
||||
static void
|
||||
acr122_usb_get_end_points (struct usb_device *dev, struct acr122_usb_data *data)
|
||||
acr122_usb_get_end_points(struct usb_device *dev, struct acr122_usb_data *data)
|
||||
{
|
||||
uint32_t uiIndex;
|
||||
uint32_t uiEndPoint;
|
||||
|
|
@ -196,23 +196,23 @@ acr122_usb_get_end_points (struct usb_device *dev, struct acr122_usb_data *data)
|
|||
}
|
||||
|
||||
bool
|
||||
acr122_usb_probe (nfc_connstring connstrings[], size_t connstrings_len, size_t *pszDeviceFound)
|
||||
acr122_usb_probe(nfc_connstring connstrings[], size_t connstrings_len, size_t *pszDeviceFound)
|
||||
{
|
||||
usb_init ();
|
||||
usb_init();
|
||||
|
||||
int res;
|
||||
// usb_find_busses will find all of the busses on the system. Returns the
|
||||
// number of changes since previous call to this function (total of new
|
||||
// busses and busses removed).
|
||||
if ((res = usb_find_busses () < 0)) {
|
||||
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "Unable to find USB busses (%s)", _usb_strerror (res));
|
||||
if ((res = usb_find_busses() < 0)) {
|
||||
log_put(LOG_CATEGORY, NFC_PRIORITY_ERROR, "Unable to find USB busses (%s)", _usb_strerror(res));
|
||||
return false;
|
||||
}
|
||||
// usb_find_devices will find all of the devices on each bus. This should be
|
||||
// called after usb_find_busses. Returns the number of changes since the
|
||||
// previous call to this function (total of new device and devices removed).
|
||||
if ((res = usb_find_devices () < 0)) {
|
||||
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "Unable to find USB devices (%s)", _usb_strerror (res));
|
||||
if ((res = usb_find_devices() < 0)) {
|
||||
log_put(LOG_CATEGORY, NFC_PRIORITY_ERROR, "Unable to find USB devices (%s)", _usb_strerror(res));
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -220,11 +220,11 @@ acr122_usb_probe (nfc_connstring connstrings[], size_t connstrings_len, size_t *
|
|||
|
||||
uint32_t uiBusIndex = 0;
|
||||
struct usb_bus *bus;
|
||||
for (bus = usb_get_busses (); bus; bus = bus->next) {
|
||||
for (bus = usb_get_busses(); bus; bus = bus->next) {
|
||||
struct usb_device *dev;
|
||||
|
||||
for (dev = bus->devices; dev; dev = dev->next, uiBusIndex++) {
|
||||
for (size_t n = 0; n < sizeof (acr122_usb_supported_devices) / sizeof (struct acr122_usb_supported_device); n++) {
|
||||
for (size_t n = 0; n < sizeof(acr122_usb_supported_devices) / sizeof(struct acr122_usb_supported_device); n++) {
|
||||
if ((acr122_usb_supported_devices[n].vendor_id == dev->descriptor.idVendor) &&
|
||||
(acr122_usb_supported_devices[n].product_id == dev->descriptor.idProduct)) {
|
||||
// Make sure there are 2 endpoints available
|
||||
|
|
@ -238,13 +238,13 @@ acr122_usb_probe (nfc_connstring connstrings[], size_t connstrings_len, size_t *
|
|||
continue;
|
||||
}
|
||||
|
||||
usb_dev_handle *udev = usb_open (dev);
|
||||
usb_dev_handle *udev = usb_open(dev);
|
||||
|
||||
// Set configuration
|
||||
// acr122_usb_get_usb_device_name (dev, udev, pnddDevices[*pszDeviceFound].acDevice, sizeof (pnddDevices[*pszDeviceFound].acDevice));
|
||||
log_put (LOG_CATEGORY, NFC_PRIORITY_TRACE, "device found: Bus %s Device %s", bus->dirname, dev->filename);
|
||||
usb_close (udev);
|
||||
snprintf (connstrings[*pszDeviceFound], sizeof(nfc_connstring), "%s:%s:%s", ACR122_USB_DRIVER_NAME, bus->dirname, dev->filename);
|
||||
log_put(LOG_CATEGORY, NFC_PRIORITY_TRACE, "device found: Bus %s Device %s", bus->dirname, dev->filename);
|
||||
usb_close(udev);
|
||||
snprintf(connstrings[*pszDeviceFound], sizeof(nfc_connstring), "%s:%s:%s", ACR122_USB_DRIVER_NAME, bus->dirname, dev->filename);
|
||||
(*pszDeviceFound)++;
|
||||
// Test if we reach the maximum "wanted" devices
|
||||
if ((*pszDeviceFound) == connstrings_len) {
|
||||
|
|
@ -264,51 +264,51 @@ struct acr122_usb_descriptor {
|
|||
};
|
||||
|
||||
static int
|
||||
acr122_usb_connstring_decode (const nfc_connstring connstring, struct acr122_usb_descriptor *desc)
|
||||
acr122_usb_connstring_decode(const nfc_connstring connstring, struct acr122_usb_descriptor *desc)
|
||||
{
|
||||
int n = strlen (connstring) + 1;
|
||||
char *driver_name = malloc (n);
|
||||
char *dirname = malloc (n);
|
||||
char *filename = malloc (n);
|
||||
int n = strlen(connstring) + 1;
|
||||
char *driver_name = malloc(n);
|
||||
char *dirname = malloc(n);
|
||||
char *filename = malloc(n);
|
||||
|
||||
driver_name[0] = '\0';
|
||||
|
||||
int res = sscanf (connstring, "%[^:]:%[^:]:%[^:]", driver_name, dirname, filename);
|
||||
int res = sscanf(connstring, "%[^:]:%[^:]:%[^:]", driver_name, dirname, filename);
|
||||
|
||||
if (!res || (0 != strcmp (driver_name, ACR122_USB_DRIVER_NAME))) {
|
||||
if (!res || (0 != strcmp(driver_name, ACR122_USB_DRIVER_NAME))) {
|
||||
// Driver name does not match.
|
||||
res = 0;
|
||||
} else {
|
||||
desc->dirname = strdup (dirname);
|
||||
desc->filename = strdup (filename);
|
||||
desc->dirname = strdup(dirname);
|
||||
desc->filename = strdup(filename);
|
||||
}
|
||||
|
||||
free (driver_name);
|
||||
free (dirname);
|
||||
free (filename);
|
||||
free(driver_name);
|
||||
free(dirname);
|
||||
free(filename);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
bool
|
||||
acr122_usb_get_usb_device_name (struct usb_device *dev, usb_dev_handle *udev, char *buffer, size_t len)
|
||||
acr122_usb_get_usb_device_name(struct usb_device *dev, usb_dev_handle *udev, char *buffer, size_t len)
|
||||
{
|
||||
*buffer = '\0';
|
||||
|
||||
if (dev->descriptor.iManufacturer || dev->descriptor.iProduct) {
|
||||
if (udev) {
|
||||
usb_get_string_simple (udev, dev->descriptor.iManufacturer, buffer, len);
|
||||
if (strlen (buffer) > 0)
|
||||
strcpy (buffer + strlen (buffer), " / ");
|
||||
usb_get_string_simple (udev, dev->descriptor.iProduct, buffer + strlen (buffer), len - strlen (buffer));
|
||||
usb_get_string_simple(udev, dev->descriptor.iManufacturer, buffer, len);
|
||||
if (strlen(buffer) > 0)
|
||||
strcpy(buffer + strlen(buffer), " / ");
|
||||
usb_get_string_simple(udev, dev->descriptor.iProduct, buffer + strlen(buffer), len - strlen(buffer));
|
||||
}
|
||||
}
|
||||
|
||||
if (!*buffer) {
|
||||
for (size_t n = 0; n < sizeof (acr122_usb_supported_devices) / sizeof (struct acr122_usb_supported_device); n++) {
|
||||
for (size_t n = 0; n < sizeof(acr122_usb_supported_devices) / sizeof(struct acr122_usb_supported_device); n++) {
|
||||
if ((acr122_usb_supported_devices[n].vendor_id == dev->descriptor.idVendor) &&
|
||||
(acr122_usb_supported_devices[n].product_id == dev->descriptor.idProduct)) {
|
||||
strncpy (buffer, acr122_usb_supported_devices[n].name, len);
|
||||
strncpy(buffer, acr122_usb_supported_devices[n].name, len);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -318,12 +318,12 @@ acr122_usb_get_usb_device_name (struct usb_device *dev, usb_dev_handle *udev, ch
|
|||
}
|
||||
|
||||
static nfc_device *
|
||||
acr122_usb_open (const nfc_connstring connstring)
|
||||
acr122_usb_open(const nfc_connstring connstring)
|
||||
{
|
||||
nfc_device *pnd = NULL;
|
||||
struct acr122_usb_descriptor desc = { NULL, NULL };
|
||||
int connstring_decode_level = acr122_usb_connstring_decode (connstring, &desc);
|
||||
log_put (LOG_CATEGORY, NFC_PRIORITY_TRACE, "%d element(s) have been decoded from \"%s\"", connstring_decode_level, connstring);
|
||||
int connstring_decode_level = acr122_usb_connstring_decode(connstring, &desc);
|
||||
log_put(LOG_CATEGORY, NFC_PRIORITY_TRACE, "%d element(s) have been decoded from \"%s\"", connstring_decode_level, connstring);
|
||||
if (connstring_decode_level < 1) {
|
||||
goto free_mem;
|
||||
}
|
||||
|
|
@ -336,88 +336,88 @@ acr122_usb_open (const nfc_connstring connstring)
|
|||
struct usb_bus *bus;
|
||||
struct usb_device *dev;
|
||||
|
||||
usb_init ();
|
||||
usb_init();
|
||||
|
||||
int res;
|
||||
// usb_find_busses will find all of the busses on the system. Returns the
|
||||
// number of changes since previous call to this function (total of new
|
||||
// busses and busses removed).
|
||||
if ((res = usb_find_busses () < 0)) {
|
||||
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "Unable to find USB busses (%s)", _usb_strerror (res));
|
||||
if ((res = usb_find_busses() < 0)) {
|
||||
log_put(LOG_CATEGORY, NFC_PRIORITY_ERROR, "Unable to find USB busses (%s)", _usb_strerror(res));
|
||||
goto free_mem;
|
||||
}
|
||||
// usb_find_devices will find all of the devices on each bus. This should be
|
||||
// called after usb_find_busses. Returns the number of changes since the
|
||||
// previous call to this function (total of new device and devices removed).
|
||||
if ((res = usb_find_devices () < 0)) {
|
||||
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "Unable to find USB devices (%s)", _usb_strerror (res));
|
||||
if ((res = usb_find_devices() < 0)) {
|
||||
log_put(LOG_CATEGORY, NFC_PRIORITY_ERROR, "Unable to find USB devices (%s)", _usb_strerror(res));
|
||||
goto free_mem;
|
||||
}
|
||||
|
||||
for (bus = usb_get_busses (); bus; bus = bus->next) {
|
||||
for (bus = usb_get_busses(); bus; bus = bus->next) {
|
||||
if (connstring_decode_level > 1) {
|
||||
// A specific bus have been specified
|
||||
if (0 != strcmp (bus->dirname, desc.dirname))
|
||||
if (0 != strcmp(bus->dirname, desc.dirname))
|
||||
continue;
|
||||
}
|
||||
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
|
||||
data.pudh = usb_open (dev);
|
||||
data.pudh = usb_open(dev);
|
||||
// Reset device
|
||||
usb_reset (data.pudh);
|
||||
usb_reset(data.pudh);
|
||||
// Retrieve end points
|
||||
acr122_usb_get_end_points (dev, &data);
|
||||
acr122_usb_get_end_points(dev, &data);
|
||||
// Claim interface
|
||||
res = usb_claim_interface (data.pudh, 0);
|
||||
res = usb_claim_interface(data.pudh, 0);
|
||||
if (res < 0) {
|
||||
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "Unable to claim USB interface (%s)", _usb_strerror (res));
|
||||
usb_close (data.pudh);
|
||||
log_put(LOG_CATEGORY, NFC_PRIORITY_ERROR, "Unable to claim USB interface (%s)", _usb_strerror(res));
|
||||
usb_close(data.pudh);
|
||||
// we failed to use the specified device
|
||||
goto free_mem;
|
||||
}
|
||||
|
||||
res = usb_set_altinterface (data.pudh, 0);
|
||||
res = usb_set_altinterface(data.pudh, 0);
|
||||
if (res < 0) {
|
||||
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "Unable to set alternate setting on USB interface (%s)", _usb_strerror (res));
|
||||
usb_close (data.pudh);
|
||||
log_put(LOG_CATEGORY, NFC_PRIORITY_ERROR, "Unable to set alternate setting on USB interface (%s)", _usb_strerror(res));
|
||||
usb_close(data.pudh);
|
||||
// we failed to use the specified device
|
||||
goto free_mem;
|
||||
}
|
||||
|
||||
data.model = acr122_usb_get_device_model (dev->descriptor.idVendor, dev->descriptor.idProduct);
|
||||
data.model = acr122_usb_get_device_model(dev->descriptor.idVendor, dev->descriptor.idProduct);
|
||||
// Allocate memory for the device info and specification, fill it and return the info
|
||||
pnd = nfc_device_new (connstring);
|
||||
acr122_usb_get_usb_device_name (dev, data.pudh, pnd->name, sizeof (pnd->name));
|
||||
pnd = nfc_device_new(connstring);
|
||||
acr122_usb_get_usb_device_name(dev, data.pudh, pnd->name, sizeof(pnd->name));
|
||||
|
||||
pnd->driver_data = malloc(sizeof(struct acr122_usb_data));
|
||||
*DRIVER_DATA (pnd) = data;
|
||||
*DRIVER_DATA(pnd) = data;
|
||||
|
||||
// Alloc and init chip's data
|
||||
pn53x_data_new (pnd, &acr122_usb_io);
|
||||
pn53x_data_new(pnd, &acr122_usb_io);
|
||||
|
||||
switch (DRIVER_DATA (pnd)->model) {
|
||||
switch (DRIVER_DATA(pnd)->model) {
|
||||
// empirical tuning
|
||||
case ACR122:
|
||||
CHIP_DATA (pnd)->timer_correction = 46;
|
||||
CHIP_DATA(pnd)->timer_correction = 46;
|
||||
break;
|
||||
case TOUCHATAG:
|
||||
CHIP_DATA (pnd)->timer_correction = 50;
|
||||
CHIP_DATA(pnd)->timer_correction = 50;
|
||||
break;
|
||||
case UNKNOWN:
|
||||
break;
|
||||
}
|
||||
pnd->driver = &acr122_usb_driver;
|
||||
|
||||
if (acr122_usb_init (pnd) < 0) {
|
||||
usb_close (data.pudh);
|
||||
if (acr122_usb_init(pnd) < 0) {
|
||||
usb_close(data.pudh);
|
||||
goto error;
|
||||
}
|
||||
DRIVER_DATA (pnd)->abort_flag = false;
|
||||
DRIVER_DATA(pnd)->abort_flag = false;
|
||||
goto free_mem;
|
||||
}
|
||||
}
|
||||
|
|
@ -426,31 +426,31 @@ acr122_usb_open (const nfc_connstring connstring)
|
|||
|
||||
error:
|
||||
// Free allocated structure on error.
|
||||
nfc_device_free (pnd);
|
||||
nfc_device_free(pnd);
|
||||
pnd = NULL;
|
||||
free_mem:
|
||||
free (desc.dirname);
|
||||
free (desc.filename);
|
||||
free(desc.dirname);
|
||||
free(desc.filename);
|
||||
return pnd;
|
||||
}
|
||||
|
||||
static void
|
||||
acr122_usb_close (nfc_device *pnd)
|
||||
acr122_usb_close(nfc_device *pnd)
|
||||
{
|
||||
acr122_usb_ack (pnd);
|
||||
acr122_usb_ack(pnd);
|
||||
|
||||
pn53x_idle (pnd);
|
||||
pn53x_idle(pnd);
|
||||
|
||||
int res;
|
||||
if ((res = usb_release_interface (DRIVER_DATA (pnd)->pudh, 0)) < 0) {
|
||||
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "Unable to release USB interface (%s)", _usb_strerror (res));
|
||||
if ((res = usb_release_interface(DRIVER_DATA(pnd)->pudh, 0)) < 0) {
|
||||
log_put(LOG_CATEGORY, NFC_PRIORITY_ERROR, "Unable to release USB interface (%s)", _usb_strerror(res));
|
||||
}
|
||||
|
||||
if ((res = usb_close (DRIVER_DATA (pnd)->pudh)) < 0) {
|
||||
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "Unable to close USB connection (%s)", _usb_strerror (res));
|
||||
if ((res = usb_close(DRIVER_DATA(pnd)->pudh)) < 0) {
|
||||
log_put(LOG_CATEGORY, NFC_PRIORITY_ERROR, "Unable to close USB connection (%s)", _usb_strerror(res));
|
||||
}
|
||||
pn53x_data_free (pnd);
|
||||
nfc_device_free (pnd);
|
||||
pn53x_data_free(pnd);
|
||||
nfc_device_free(pnd);
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
@ -505,7 +505,7 @@ RDR_to_PC_DataBlock SW: more data: 8 bytes
|
|||
// FIXME ACR122_USB_BUFFER_LEN don't have the correct lenght value
|
||||
#define ACR122_USB_BUFFER_LEN (PN53x_EXTENDED_FRAME__DATA_MAX_LEN + PN53x_EXTENDED_FRAME__OVERHEAD)
|
||||
static int
|
||||
acr122_build_frame_from_apdu (uint8_t **frame, const uint8_t *apdu, const size_t apdu_len)
|
||||
acr122_build_frame_from_apdu(uint8_t **frame, const uint8_t *apdu, const size_t apdu_len)
|
||||
{
|
||||
static uint8_t abtFrame[ACR122_USB_BUFFER_LEN] = {
|
||||
0x6b, // PC_to_RDR_Escape
|
||||
|
|
@ -516,13 +516,13 @@ acr122_build_frame_from_apdu (uint8_t **frame, const uint8_t *apdu, const size_t
|
|||
return NFC_EINVARG;
|
||||
|
||||
abtFrame[1] = apdu_len;
|
||||
memcpy (abtFrame + 10, apdu, apdu_len);
|
||||
memcpy(abtFrame + 10, apdu, apdu_len);
|
||||
*frame = abtFrame;
|
||||
return (apdu_len + 10);
|
||||
}
|
||||
|
||||
static int
|
||||
acr122_build_frame_from_tama (uint8_t **frame, const uint8_t *tama, const size_t tama_len)
|
||||
acr122_build_frame_from_tama(uint8_t **frame, const uint8_t *tama, const size_t tama_len)
|
||||
{
|
||||
static uint8_t abtFrame[ACR122_USB_BUFFER_LEN] = {
|
||||
0x6b, // PC_to_RDR_Escape
|
||||
|
|
@ -538,22 +538,22 @@ acr122_build_frame_from_tama (uint8_t **frame, const uint8_t *tama, const size_t
|
|||
|
||||
abtFrame[1] = tama_len + 6;
|
||||
abtFrame[14] = tama_len + 1;
|
||||
memcpy (abtFrame + 16, tama, tama_len);
|
||||
memcpy(abtFrame + 16, tama, tama_len);
|
||||
*frame = abtFrame;
|
||||
return (tama_len + 16);
|
||||
}
|
||||
|
||||
int
|
||||
acr122_usb_send (nfc_device *pnd, const uint8_t *pbtData, const size_t szData, const int timeout)
|
||||
acr122_usb_send(nfc_device *pnd, const uint8_t *pbtData, const size_t szData, const int timeout)
|
||||
{
|
||||
uint8_t *frame;
|
||||
int res;
|
||||
if ((res = acr122_build_frame_from_tama (&frame, pbtData, szData)) < 0) {
|
||||
if ((res = acr122_build_frame_from_tama(&frame, pbtData, szData)) < 0) {
|
||||
pnd->last_error = NFC_EINVARG;
|
||||
return pnd->last_error;
|
||||
}
|
||||
|
||||
if ((res = acr122_usb_bulk_write (DRIVER_DATA (pnd), frame, res, timeout)) < 0) {
|
||||
if ((res = acr122_usb_bulk_write(DRIVER_DATA(pnd), frame, res, timeout)) < 0) {
|
||||
pnd->last_error = res;
|
||||
return pnd->last_error;
|
||||
}
|
||||
|
|
@ -562,7 +562,7 @@ acr122_usb_send (nfc_device *pnd, const uint8_t *pbtData, const size_t szData, c
|
|||
|
||||
#define USB_TIMEOUT_PER_PASS 200
|
||||
int
|
||||
acr122_usb_receive (nfc_device *pnd, uint8_t *pbtData, const size_t szDataLen, const int timeout)
|
||||
acr122_usb_receive(nfc_device *pnd, uint8_t *pbtData, const size_t szDataLen, const int timeout)
|
||||
{
|
||||
off_t offset = 0;
|
||||
|
||||
|
|
@ -589,12 +589,12 @@ read:
|
|||
}
|
||||
}
|
||||
|
||||
res = acr122_usb_bulk_read (DRIVER_DATA (pnd), abtRxBuf, sizeof (abtRxBuf), usb_timeout);
|
||||
res = acr122_usb_bulk_read(DRIVER_DATA(pnd), abtRxBuf, sizeof(abtRxBuf), usb_timeout);
|
||||
|
||||
if (res == NFC_ETIMEOUT) {
|
||||
if (DRIVER_DATA (pnd)->abort_flag) {
|
||||
DRIVER_DATA (pnd)->abort_flag = false;
|
||||
acr122_usb_ack (pnd);
|
||||
if (DRIVER_DATA(pnd)->abort_flag) {
|
||||
DRIVER_DATA(pnd)->abort_flag = false;
|
||||
acr122_usb_ack(pnd);
|
||||
pnd->last_error = NFC_EOPABORTED;
|
||||
return pnd->last_error;
|
||||
} else {
|
||||
|
|
@ -610,7 +610,7 @@ read:
|
|||
}
|
||||
|
||||
if (abtRxBuf[offset] != 0x83) {
|
||||
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Frame header mismatch");
|
||||
log_put(LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Frame header mismatch");
|
||||
pnd->last_error = NFC_EIO;
|
||||
return pnd->last_error;
|
||||
}
|
||||
|
|
@ -618,21 +618,21 @@ read:
|
|||
|
||||
size_t len = abtRxBuf[offset++];
|
||||
if (len < 4) {
|
||||
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Too small reply");
|
||||
log_put(LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Too small reply");
|
||||
pnd->last_error = NFC_EIO;
|
||||
return pnd->last_error;
|
||||
}
|
||||
len -= 4;
|
||||
|
||||
if (len > szDataLen) {
|
||||
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "Unable to receive data: buffer too small. (szDataLen: %zu, len: %zu)", szDataLen, len);
|
||||
log_put(LOG_CATEGORY, NFC_PRIORITY_ERROR, "Unable to receive data: buffer too small. (szDataLen: %zu, len: %zu)", szDataLen, len);
|
||||
pnd->last_error = NFC_EIO;
|
||||
return pnd->last_error;
|
||||
}
|
||||
|
||||
const uint8_t acr122_preamble[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x81, 0x00 };
|
||||
if (0 != (memcmp (abtRxBuf + offset, acr122_preamble, sizeof(acr122_preamble)))) {
|
||||
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Frame preamble mismatch");
|
||||
if (0 != (memcmp(abtRxBuf + offset, acr122_preamble, sizeof(acr122_preamble)))) {
|
||||
log_put(LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Frame preamble mismatch");
|
||||
pnd->last_error = NFC_EIO;
|
||||
return pnd->last_error;
|
||||
}
|
||||
|
|
@ -640,44 +640,44 @@ read:
|
|||
|
||||
// TFI + PD0 (CC+1)
|
||||
if (abtRxBuf[offset] != 0xD5) {
|
||||
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "TFI Mismatch");
|
||||
log_put(LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "TFI Mismatch");
|
||||
pnd->last_error = NFC_EIO;
|
||||
return pnd->last_error;
|
||||
}
|
||||
offset += 1;
|
||||
|
||||
if (abtRxBuf[offset] != CHIP_DATA (pnd)->last_command + 1) {
|
||||
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Command Code verification failed");
|
||||
if (abtRxBuf[offset] != CHIP_DATA(pnd)->last_command + 1) {
|
||||
log_put(LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Command Code verification failed");
|
||||
pnd->last_error = NFC_EIO;
|
||||
return pnd->last_error;
|
||||
}
|
||||
offset += 1;
|
||||
|
||||
memcpy (pbtData, abtRxBuf + offset, len);
|
||||
memcpy(pbtData, abtRxBuf + offset, len);
|
||||
offset += len;
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
int
|
||||
acr122_usb_ack (nfc_device *pnd)
|
||||
acr122_usb_ack(nfc_device *pnd)
|
||||
{
|
||||
(void) pnd;
|
||||
int res = 0;
|
||||
uint8_t acr122_ack_frame[] = { GetFirmwareVersion }; // We can't send a PN532's ACK frame, so we use a normal command to cancel current command
|
||||
log_put (LOG_CATEGORY, NFC_PRIORITY_DEBUG, "%s", "ACR122 Abort");
|
||||
log_put(LOG_CATEGORY, NFC_PRIORITY_DEBUG, "%s", "ACR122 Abort");
|
||||
uint8_t *frame;
|
||||
if ((res = acr122_build_frame_from_tama (&frame, acr122_ack_frame, sizeof (acr122_ack_frame))) < 0)
|
||||
if ((res = acr122_build_frame_from_tama(&frame, acr122_ack_frame, sizeof(acr122_ack_frame))) < 0)
|
||||
return res;
|
||||
|
||||
res = acr122_usb_bulk_write (DRIVER_DATA (pnd), frame, res, 1000);
|
||||
res = acr122_usb_bulk_write(DRIVER_DATA(pnd), frame, res, 1000);
|
||||
uint8_t abtRxBuf[ACR122_USB_BUFFER_LEN];
|
||||
res = acr122_usb_bulk_read (DRIVER_DATA (pnd), abtRxBuf, sizeof (abtRxBuf), 1000);
|
||||
res = acr122_usb_bulk_read(DRIVER_DATA(pnd), abtRxBuf, sizeof(abtRxBuf), 1000);
|
||||
return res;
|
||||
}
|
||||
|
||||
int
|
||||
acr122_usb_init (nfc_device *pnd)
|
||||
acr122_usb_init(nfc_device *pnd)
|
||||
{
|
||||
int res = 0;
|
||||
uint8_t abtRxBuf[ACR122_USB_BUFFER_LEN];
|
||||
|
|
@ -705,7 +705,7 @@ acr122_usb_init (nfc_device *pnd)
|
|||
return res;
|
||||
*/
|
||||
|
||||
if ((res = pn53x_set_property_int (pnd, NP_TIMEOUT_COMMAND, 1000)) < 0)
|
||||
if ((res = pn53x_set_property_int(pnd, NP_TIMEOUT_COMMAND, 1000)) < 0)
|
||||
return res;
|
||||
|
||||
uint8_t acr122u_set_picc_operating_parameters_off_frame[] = {
|
||||
|
|
@ -717,24 +717,24 @@ acr122_usb_init (nfc_device *pnd)
|
|||
};
|
||||
uint8_t *frame;
|
||||
|
||||
log_put (LOG_CATEGORY, NFC_PRIORITY_DEBUG, "%s", "ACR122 PICC Operating Parameters");
|
||||
if ((res = acr122_build_frame_from_apdu (&frame, acr122u_set_picc_operating_parameters_off_frame, sizeof(acr122u_set_picc_operating_parameters_off_frame))) < 0)
|
||||
log_put(LOG_CATEGORY, NFC_PRIORITY_DEBUG, "%s", "ACR122 PICC Operating Parameters");
|
||||
if ((res = acr122_build_frame_from_apdu(&frame, acr122u_set_picc_operating_parameters_off_frame, sizeof(acr122u_set_picc_operating_parameters_off_frame))) < 0)
|
||||
return res;
|
||||
if ((res = acr122_usb_bulk_write (DRIVER_DATA (pnd), frame, res, 1000)) < 0)
|
||||
if ((res = acr122_usb_bulk_write(DRIVER_DATA(pnd), frame, res, 1000)) < 0)
|
||||
return res;
|
||||
if ((res = acr122_usb_bulk_read (DRIVER_DATA (pnd), abtRxBuf, sizeof (abtRxBuf), 1000)) < 0)
|
||||
if ((res = acr122_usb_bulk_read(DRIVER_DATA(pnd), abtRxBuf, sizeof(abtRxBuf), 1000)) < 0)
|
||||
return res;
|
||||
|
||||
if ((res = pn53x_init (pnd)) < 0)
|
||||
if ((res = pn53x_init(pnd)) < 0)
|
||||
return res;
|
||||
|
||||
return NFC_SUCCESS;
|
||||
}
|
||||
|
||||
static int
|
||||
acr122_usb_abort_command (nfc_device *pnd)
|
||||
acr122_usb_abort_command(nfc_device *pnd)
|
||||
{
|
||||
DRIVER_DATA (pnd)->abort_flag = true;
|
||||
DRIVER_DATA(pnd)->abort_flag = true;
|
||||
return NFC_SUCCESS;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -29,11 +29,11 @@
|
|||
|
||||
# include <nfc/nfc-types.h>
|
||||
|
||||
bool acr122_usb_probe (nfc_connstring connstrings[], size_t connstrings_len, size_t *pszDeviceFound);
|
||||
nfc_device *acr122_usb_connect (const nfc_connstring connstring);
|
||||
int acr122_usb_send (nfc_device *pnd, const uint8_t *pbtData, const size_t szData, int timeout);
|
||||
int acr122_usb_receive (nfc_device *pnd, uint8_t *pbtData, const size_t szData, int timeout);
|
||||
void acr122_usb_disconnect (nfc_device *pnd);
|
||||
bool acr122_usb_probe(nfc_connstring connstrings[], size_t connstrings_len, size_t *pszDeviceFound);
|
||||
nfc_device *acr122_usb_connect(const nfc_connstring connstring);
|
||||
int acr122_usb_send(nfc_device *pnd, const uint8_t *pbtData, const size_t szData, int timeout);
|
||||
int acr122_usb_receive(nfc_device *pnd, uint8_t *pbtData, const size_t szData, int timeout);
|
||||
void acr122_usb_disconnect(nfc_device *pnd);
|
||||
|
||||
extern const struct nfc_driver acr122_usb_driver;
|
||||
|
||||
|
|
|
|||
|
|
@ -270,7 +270,7 @@ acr122s_recv_frame(nfc_device *pnd, uint8_t *frame, size_t frame_size, void *abo
|
|||
return ret;
|
||||
|
||||
struct xfr_block_res *res = (struct xfr_block_res *) &frame[1];
|
||||
if ((uint8_t) (res->seq + 1) != DRIVER_DATA(pnd)->seq) {
|
||||
if ((uint8_t)(res->seq + 1) != DRIVER_DATA(pnd)->seq) {
|
||||
log_put(LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Invalid response sequence number.");
|
||||
pnd->last_error = NFC_EIO;
|
||||
return pnd->last_error;
|
||||
|
|
@ -418,51 +418,51 @@ struct acr122s_descriptor {
|
|||
};
|
||||
|
||||
static int
|
||||
acr122s_connstring_decode (const nfc_connstring connstring, struct acr122s_descriptor *desc)
|
||||
acr122s_connstring_decode(const nfc_connstring connstring, struct acr122s_descriptor *desc)
|
||||
{
|
||||
char *cs = malloc (strlen (connstring) + 1);
|
||||
char *cs = malloc(strlen(connstring) + 1);
|
||||
if (!cs) {
|
||||
perror ("malloc");
|
||||
perror("malloc");
|
||||
return -1;
|
||||
}
|
||||
strcpy (cs, connstring);
|
||||
const char *driver_name = strtok (cs, ":");
|
||||
strcpy(cs, connstring);
|
||||
const char *driver_name = strtok(cs, ":");
|
||||
if (!driver_name) {
|
||||
// Parse error
|
||||
free (cs);
|
||||
free(cs);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (0 != strcmp (driver_name, ACR122S_DRIVER_NAME)) {
|
||||
if (0 != strcmp(driver_name, ACR122S_DRIVER_NAME)) {
|
||||
// Driver name does not match.
|
||||
free (cs);
|
||||
free(cs);
|
||||
return 0;
|
||||
}
|
||||
|
||||
const char *port = strtok (NULL, ":");
|
||||
const char *port = strtok(NULL, ":");
|
||||
if (!port) {
|
||||
// Only driver name was specified (or parsing error)
|
||||
free (cs);
|
||||
free(cs);
|
||||
return 1;
|
||||
}
|
||||
strncpy (desc->port, port, sizeof(desc->port) - 1);
|
||||
strncpy(desc->port, port, sizeof(desc->port) - 1);
|
||||
desc->port[sizeof(desc->port) - 1] = '\0';
|
||||
|
||||
const char *speed_s = strtok (NULL, ":");
|
||||
const char *speed_s = strtok(NULL, ":");
|
||||
if (!speed_s) {
|
||||
// speed not specified (or parsing error)
|
||||
free (cs);
|
||||
free(cs);
|
||||
return 2;
|
||||
}
|
||||
unsigned long speed;
|
||||
if (sscanf (speed_s, "%lu", &speed) != 1) {
|
||||
if (sscanf(speed_s, "%lu", &speed) != 1) {
|
||||
// speed_s is not a number
|
||||
free (cs);
|
||||
free(cs);
|
||||
return 2;
|
||||
}
|
||||
desc->speed = speed;
|
||||
|
||||
free (cs);
|
||||
free(cs);
|
||||
return 3;
|
||||
}
|
||||
|
||||
|
|
@ -482,26 +482,26 @@ acr122s_probe(nfc_connstring connstrings[], size_t connstrings_len, size_t *pszD
|
|||
*pszDeviceFound = 0;
|
||||
|
||||
serial_port sp;
|
||||
char **acPorts = uart_list_ports ();
|
||||
char **acPorts = uart_list_ports();
|
||||
const char *acPort;
|
||||
int iDevice = 0;
|
||||
|
||||
while ((acPort = acPorts[iDevice++])) {
|
||||
sp = uart_open (acPort);
|
||||
log_put (LOG_CATEGORY, NFC_PRIORITY_TRACE, "Trying to find ACR122S device on serial port: %s at %d bauds.", acPort, ACR122S_DEFAULT_SPEED);
|
||||
sp = uart_open(acPort);
|
||||
log_put(LOG_CATEGORY, NFC_PRIORITY_TRACE, "Trying to find ACR122S device on serial port: %s at %d bauds.", acPort, ACR122S_DEFAULT_SPEED);
|
||||
|
||||
if ((sp != INVALID_SERIAL_PORT) && (sp != CLAIMED_SERIAL_PORT)) {
|
||||
// We need to flush input to be sure first reply does not comes from older byte transceive
|
||||
uart_flush_input (sp);
|
||||
uart_set_speed (sp, ACR122S_DEFAULT_SPEED);
|
||||
uart_flush_input(sp);
|
||||
uart_set_speed(sp, ACR122S_DEFAULT_SPEED);
|
||||
|
||||
nfc_connstring connstring;
|
||||
snprintf (connstring, sizeof(nfc_connstring), "%s:%s:%"PRIu32, ACR122S_DRIVER_NAME, acPort, ACR122S_DEFAULT_SPEED);
|
||||
nfc_device *pnd = nfc_device_new (connstring);
|
||||
snprintf(connstring, sizeof(nfc_connstring), "%s:%s:%"PRIu32, ACR122S_DRIVER_NAME, acPort, ACR122S_DEFAULT_SPEED);
|
||||
nfc_device *pnd = nfc_device_new(connstring);
|
||||
|
||||
pnd->driver = &acr122s_driver;
|
||||
pnd->driver_data = malloc(sizeof(struct acr122s_data));
|
||||
DRIVER_DATA (pnd)->port = sp;
|
||||
DRIVER_DATA(pnd)->port = sp;
|
||||
DRIVER_DATA(pnd)->seq = 0;
|
||||
|
||||
#ifndef WIN32
|
||||
|
|
@ -528,7 +528,7 @@ acr122s_probe(nfc_connstring connstrings[], size_t connstrings_len, size_t *pszD
|
|||
continue;
|
||||
|
||||
// ACR122S reader is found
|
||||
memcpy (connstrings[*pszDeviceFound], connstring, sizeof(nfc_connstring));
|
||||
memcpy(connstrings[*pszDeviceFound], connstring, sizeof(nfc_connstring));
|
||||
(*pszDeviceFound)++;
|
||||
|
||||
// Test if we reach the maximum "wanted" devices
|
||||
|
|
@ -538,9 +538,9 @@ acr122s_probe(nfc_connstring connstrings[], size_t connstrings_len, size_t *pszD
|
|||
}
|
||||
iDevice = 0;
|
||||
while ((acPort = acPorts[iDevice++])) {
|
||||
free ((void*)acPort);
|
||||
free((void*)acPort);
|
||||
}
|
||||
free (acPorts);
|
||||
free(acPorts);
|
||||
#endif /* SERIAL_AUTOPROBE_ENABLED */
|
||||
return true;
|
||||
}
|
||||
|
|
@ -551,7 +551,7 @@ acr122s_open(const nfc_connstring connstring)
|
|||
serial_port sp;
|
||||
nfc_device *pnd;
|
||||
struct acr122s_descriptor ndd;
|
||||
int connstring_decode_level = acr122s_connstring_decode (connstring, &ndd);
|
||||
int connstring_decode_level = acr122s_connstring_decode(connstring, &ndd);
|
||||
|
||||
if (connstring_decode_level < 2) {
|
||||
return NULL;
|
||||
|
|
@ -633,15 +633,15 @@ acr122s_open(const nfc_connstring connstring)
|
|||
}
|
||||
|
||||
void
|
||||
acr122s_close (nfc_device *pnd)
|
||||
acr122s_close(nfc_device *pnd)
|
||||
{
|
||||
acr122s_deactivate_sam(pnd);
|
||||
uart_close(DRIVER_DATA(pnd)->port);
|
||||
|
||||
#ifndef WIN32
|
||||
// Release file descriptors used for abort mecanism
|
||||
close (DRIVER_DATA(pnd)->abort_fds[0]);
|
||||
close (DRIVER_DATA(pnd)->abort_fds[1]);
|
||||
close(DRIVER_DATA(pnd)->abort_fds[0]);
|
||||
close(DRIVER_DATA(pnd)->abort_fds[1]);
|
||||
#endif
|
||||
|
||||
pn53x_data_free(pnd);
|
||||
|
|
@ -691,7 +691,7 @@ acr122s_receive(nfc_device *pnd, uint8_t *buf, size_t buf_len, int timeout)
|
|||
|
||||
size_t data_len = FRAME_SIZE(tmp) - 17;
|
||||
if (data_len > buf_len) {
|
||||
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "Receive buffer too small. (buf_len: %zu, data_len: %zu)", buf_len, data_len);
|
||||
log_put(LOG_CATEGORY, NFC_PRIORITY_ERROR, "Receive buffer too small. (buf_len: %zu, data_len: %zu)", buf_len, data_len);
|
||||
pnd->last_error = NFC_EIO;
|
||||
return pnd->last_error;
|
||||
}
|
||||
|
|
@ -707,7 +707,7 @@ acr122s_abort_command(nfc_device *pnd)
|
|||
#ifndef WIN32
|
||||
close(DRIVER_DATA(pnd)->abort_fds[0]);
|
||||
close(DRIVER_DATA(pnd)->abort_fds[1]);
|
||||
if (pipe(DRIVER_DATA(pnd)->abort_fds) < 0 ) {
|
||||
if (pipe(DRIVER_DATA(pnd)->abort_fds) < 0) {
|
||||
return NFC_ESOFT;
|
||||
}
|
||||
#else
|
||||
|
|
|
|||
|
|
@ -87,11 +87,11 @@ static const uint8_t arygon_error_none[] = "FF000000\x0d\x0a";
|
|||
static const uint8_t arygon_error_incomplete_command[] = "FF0C0000\x0d\x0a";
|
||||
static const uint8_t arygon_error_unknown_mode[] = "FF060000\x0d\x0a";
|
||||
|
||||
int arygon_reset_tama (nfc_device *pnd);
|
||||
void arygon_firmware (nfc_device *pnd, char *str);
|
||||
int arygon_reset_tama(nfc_device *pnd);
|
||||
void arygon_firmware(nfc_device *pnd, char *str);
|
||||
|
||||
bool
|
||||
arygon_probe (nfc_connstring connstrings[], size_t connstrings_len, size_t *pszDeviceFound)
|
||||
arygon_probe(nfc_connstring connstrings[], size_t connstrings_len, size_t *pszDeviceFound)
|
||||
{
|
||||
/** @note: Due to UART bus we can't know if its really an ARYGON without
|
||||
* sending some commands. But using this way to probe devices, we can
|
||||
|
|
@ -100,53 +100,53 @@ arygon_probe (nfc_connstring connstrings[], size_t connstrings_len, size_t *pszD
|
|||
(void) connstrings;
|
||||
(void) connstrings_len;
|
||||
*pszDeviceFound = 0;
|
||||
log_put (LOG_CATEGORY, NFC_PRIORITY_INFO, "%s", "Serial auto-probing have been disabled at compile time. Skipping autoprobe.");
|
||||
log_put(LOG_CATEGORY, NFC_PRIORITY_INFO, "%s", "Serial auto-probing have been disabled at compile time. Skipping autoprobe.");
|
||||
return false;
|
||||
#else /* SERIAL_AUTOPROBE_ENABLED */
|
||||
*pszDeviceFound = 0;
|
||||
|
||||
serial_port sp;
|
||||
char **acPorts = uart_list_ports ();
|
||||
char **acPorts = uart_list_ports();
|
||||
const char *acPort;
|
||||
int iDevice = 0;
|
||||
|
||||
while ((acPort = acPorts[iDevice++])) {
|
||||
sp = uart_open (acPort);
|
||||
log_put (LOG_CATEGORY, NFC_PRIORITY_TRACE, "Trying to find ARYGON device on serial port: %s at %d bauds.", acPort, ARYGON_DEFAULT_SPEED);
|
||||
sp = uart_open(acPort);
|
||||
log_put(LOG_CATEGORY, NFC_PRIORITY_TRACE, "Trying to find ARYGON device on serial port: %s at %d bauds.", acPort, ARYGON_DEFAULT_SPEED);
|
||||
|
||||
if ((sp != INVALID_SERIAL_PORT) && (sp != CLAIMED_SERIAL_PORT)) {
|
||||
// We need to flush input to be sure first reply does not comes from older byte transceive
|
||||
uart_flush_input (sp);
|
||||
uart_set_speed (sp, ARYGON_DEFAULT_SPEED);
|
||||
uart_flush_input(sp);
|
||||
uart_set_speed(sp, ARYGON_DEFAULT_SPEED);
|
||||
|
||||
nfc_connstring connstring;
|
||||
snprintf (connstring, sizeof(nfc_connstring), "%s:%s:%"PRIu32, ARYGON_DRIVER_NAME, acPort, ARYGON_DEFAULT_SPEED);
|
||||
nfc_device *pnd = nfc_device_new (connstring);
|
||||
snprintf(connstring, sizeof(nfc_connstring), "%s:%s:%"PRIu32, ARYGON_DRIVER_NAME, acPort, ARYGON_DEFAULT_SPEED);
|
||||
nfc_device *pnd = nfc_device_new(connstring);
|
||||
|
||||
pnd->driver = &arygon_driver;
|
||||
pnd->driver_data = malloc(sizeof(struct arygon_data));
|
||||
DRIVER_DATA (pnd)->port = sp;
|
||||
DRIVER_DATA(pnd)->port = sp;
|
||||
|
||||
// Alloc and init chip's data
|
||||
pn53x_data_new (pnd, &arygon_tama_io);
|
||||
pn53x_data_new(pnd, &arygon_tama_io);
|
||||
|
||||
#ifndef WIN32
|
||||
// pipe-based abort mecanism
|
||||
pipe (DRIVER_DATA (pnd)->iAbortFds);
|
||||
pipe(DRIVER_DATA(pnd)->iAbortFds);
|
||||
#else
|
||||
DRIVER_DATA (pnd)->abort_flag = false;
|
||||
DRIVER_DATA(pnd)->abort_flag = false;
|
||||
#endif
|
||||
|
||||
int res = arygon_reset_tama (pnd);
|
||||
pn53x_data_free (pnd);
|
||||
nfc_device_free (pnd);
|
||||
uart_close (sp);
|
||||
if(res < 0) {
|
||||
int res = arygon_reset_tama(pnd);
|
||||
pn53x_data_free(pnd);
|
||||
nfc_device_free(pnd);
|
||||
uart_close(sp);
|
||||
if (res < 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// ARYGON reader is found
|
||||
memcpy (connstrings[*pszDeviceFound], connstring, sizeof(nfc_connstring));
|
||||
memcpy(connstrings[*pszDeviceFound], connstring, sizeof(nfc_connstring));
|
||||
(*pszDeviceFound)++;
|
||||
|
||||
// Test if we reach the maximum "wanted" devices
|
||||
|
|
@ -156,9 +156,9 @@ arygon_probe (nfc_connstring connstrings[], size_t connstrings_len, size_t *pszD
|
|||
}
|
||||
iDevice = 0;
|
||||
while ((acPort = acPorts[iDevice++])) {
|
||||
free ((void*)acPort);
|
||||
free((void*)acPort);
|
||||
}
|
||||
free (acPorts);
|
||||
free(acPorts);
|
||||
#endif /* SERIAL_AUTOPROBE_ENABLED */
|
||||
return true;
|
||||
}
|
||||
|
|
@ -169,59 +169,59 @@ struct arygon_descriptor {
|
|||
};
|
||||
|
||||
static int
|
||||
arygon_connstring_decode (const nfc_connstring connstring, struct arygon_descriptor *desc)
|
||||
arygon_connstring_decode(const nfc_connstring connstring, struct arygon_descriptor *desc)
|
||||
{
|
||||
char *cs = malloc (strlen (connstring) + 1);
|
||||
char *cs = malloc(strlen(connstring) + 1);
|
||||
if (!cs) {
|
||||
perror ("malloc");
|
||||
perror("malloc");
|
||||
return -1;
|
||||
}
|
||||
strcpy (cs, connstring);
|
||||
const char *driver_name = strtok (cs, ":");
|
||||
strcpy(cs, connstring);
|
||||
const char *driver_name = strtok(cs, ":");
|
||||
if (!driver_name) {
|
||||
// Parse error
|
||||
free (cs);
|
||||
free(cs);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (0 != strcmp (driver_name, ARYGON_DRIVER_NAME)) {
|
||||
if (0 != strcmp(driver_name, ARYGON_DRIVER_NAME)) {
|
||||
// Driver name does not match.
|
||||
free (cs);
|
||||
free(cs);
|
||||
return 0;
|
||||
}
|
||||
|
||||
const char *port = strtok (NULL, ":");
|
||||
const char *port = strtok(NULL, ":");
|
||||
if (!port) {
|
||||
// Only driver name was specified (or parsing error)
|
||||
free (cs);
|
||||
free(cs);
|
||||
return 1;
|
||||
}
|
||||
strncpy (desc->port, port, sizeof(desc->port) - 1);
|
||||
strncpy(desc->port, port, sizeof(desc->port) - 1);
|
||||
desc->port[sizeof(desc->port) - 1] = '\0';
|
||||
|
||||
const char *speed_s = strtok (NULL, ":");
|
||||
const char *speed_s = strtok(NULL, ":");
|
||||
if (!speed_s) {
|
||||
// speed not specified (or parsing error)
|
||||
free (cs);
|
||||
free(cs);
|
||||
return 2;
|
||||
}
|
||||
unsigned long speed;
|
||||
if (sscanf (speed_s, "%lu", &speed) != 1) {
|
||||
if (sscanf(speed_s, "%lu", &speed) != 1) {
|
||||
// speed_s is not a number
|
||||
free (cs);
|
||||
free(cs);
|
||||
return 2;
|
||||
}
|
||||
desc->speed = speed;
|
||||
|
||||
free (cs);
|
||||
free(cs);
|
||||
return 3;
|
||||
}
|
||||
|
||||
nfc_device *
|
||||
arygon_open (const nfc_connstring connstring)
|
||||
arygon_open(const nfc_connstring connstring)
|
||||
{
|
||||
struct arygon_descriptor ndd;
|
||||
int connstring_decode_level = arygon_connstring_decode (connstring, &ndd);
|
||||
int connstring_decode_level = arygon_connstring_decode(connstring, &ndd);
|
||||
|
||||
if (connstring_decode_level < 2) {
|
||||
return NULL;
|
||||
|
|
@ -232,123 +232,123 @@ arygon_open (const nfc_connstring connstring)
|
|||
serial_port sp;
|
||||
nfc_device *pnd = NULL;
|
||||
|
||||
log_put (LOG_CATEGORY, NFC_PRIORITY_TRACE, "Attempt to open: %s at %d bauds.", ndd.port, ndd.speed);
|
||||
sp = uart_open (ndd.port);
|
||||
log_put(LOG_CATEGORY, NFC_PRIORITY_TRACE, "Attempt to open: %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);
|
||||
log_put(LOG_CATEGORY, NFC_PRIORITY_ERROR, "Invalid serial port: %s", ndd.port);
|
||||
if (sp == CLAIMED_SERIAL_PORT)
|
||||
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "Serial port already claimed: %s", ndd.port);
|
||||
log_put(LOG_CATEGORY, NFC_PRIORITY_ERROR, "Serial port already claimed: %s", ndd.port);
|
||||
if ((sp == CLAIMED_SERIAL_PORT) || (sp == INVALID_SERIAL_PORT))
|
||||
return NULL;
|
||||
|
||||
// We need to flush input to be sure first reply does not comes from older byte transceive
|
||||
uart_flush_input (sp);
|
||||
uart_set_speed (sp, ndd.speed);
|
||||
uart_flush_input(sp);
|
||||
uart_set_speed(sp, ndd.speed);
|
||||
|
||||
// We have a connection
|
||||
pnd = nfc_device_new (connstring);
|
||||
snprintf (pnd->name, sizeof (pnd->name), "%s:%s", ARYGON_DRIVER_NAME, ndd.port);
|
||||
pnd = nfc_device_new(connstring);
|
||||
snprintf(pnd->name, sizeof(pnd->name), "%s:%s", ARYGON_DRIVER_NAME, ndd.port);
|
||||
|
||||
pnd->driver_data = malloc(sizeof(struct arygon_data));
|
||||
DRIVER_DATA (pnd)->port = sp;
|
||||
DRIVER_DATA(pnd)->port = sp;
|
||||
|
||||
// Alloc and init chip's data
|
||||
pn53x_data_new (pnd, &arygon_tama_io);
|
||||
pn53x_data_new(pnd, &arygon_tama_io);
|
||||
|
||||
// The PN53x chip opened to ARYGON MCU doesn't seems to be in LowVBat mode
|
||||
CHIP_DATA (pnd)->power_mode = NORMAL;
|
||||
CHIP_DATA(pnd)->power_mode = NORMAL;
|
||||
|
||||
// empirical tuning
|
||||
CHIP_DATA (pnd)->timer_correction = 46;
|
||||
CHIP_DATA(pnd)->timer_correction = 46;
|
||||
pnd->driver = &arygon_driver;
|
||||
|
||||
#ifndef WIN32
|
||||
// pipe-based abort mecanism
|
||||
if (pipe (DRIVER_DATA (pnd)->iAbortFds) < 0) {
|
||||
if (pipe(DRIVER_DATA(pnd)->iAbortFds) < 0) {
|
||||
return NULL;
|
||||
}
|
||||
#else
|
||||
DRIVER_DATA (pnd)->abort_flag = false;
|
||||
DRIVER_DATA(pnd)->abort_flag = false;
|
||||
#endif
|
||||
|
||||
// Check communication using "Reset TAMA" command
|
||||
if (arygon_reset_tama(pnd) < 0) {
|
||||
arygon_close (pnd);
|
||||
arygon_close(pnd);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char arygon_firmware_version[10];
|
||||
arygon_firmware (pnd, arygon_firmware_version);
|
||||
arygon_firmware(pnd, arygon_firmware_version);
|
||||
char *pcName;
|
||||
pcName = strdup (pnd->name);
|
||||
snprintf (pnd->name, sizeof (pnd->name), "%s %s", pcName, arygon_firmware_version);
|
||||
free (pcName);
|
||||
pcName = strdup(pnd->name);
|
||||
snprintf(pnd->name, sizeof(pnd->name), "%s %s", pcName, arygon_firmware_version);
|
||||
free(pcName);
|
||||
|
||||
pn53x_init(pnd);
|
||||
return pnd;
|
||||
}
|
||||
|
||||
void
|
||||
arygon_close (nfc_device *pnd)
|
||||
arygon_close(nfc_device *pnd)
|
||||
{
|
||||
// Release UART port
|
||||
uart_close (DRIVER_DATA (pnd)->port);
|
||||
uart_close(DRIVER_DATA(pnd)->port);
|
||||
|
||||
#ifndef WIN32
|
||||
// Release file descriptors used for abort mecanism
|
||||
close (DRIVER_DATA (pnd)->iAbortFds[0]);
|
||||
close (DRIVER_DATA (pnd)->iAbortFds[1]);
|
||||
close(DRIVER_DATA(pnd)->iAbortFds[0]);
|
||||
close(DRIVER_DATA(pnd)->iAbortFds[1]);
|
||||
#endif
|
||||
|
||||
pn53x_data_free (pnd);
|
||||
nfc_device_free (pnd);
|
||||
pn53x_data_free(pnd);
|
||||
nfc_device_free(pnd);
|
||||
}
|
||||
|
||||
#define ARYGON_TX_BUFFER_LEN (PN53x_NORMAL_FRAME__DATA_MAX_LEN + PN53x_NORMAL_FRAME__OVERHEAD + 1)
|
||||
#define ARYGON_RX_BUFFER_LEN (PN53x_EXTENDED_FRAME__DATA_MAX_LEN + PN53x_EXTENDED_FRAME__OVERHEAD)
|
||||
int
|
||||
arygon_tama_send (nfc_device *pnd, const uint8_t *pbtData, const size_t szData, int timeout)
|
||||
arygon_tama_send(nfc_device *pnd, const uint8_t *pbtData, const size_t szData, int timeout)
|
||||
{
|
||||
int res = 0;
|
||||
// Before sending anything, we need to discard from any junk bytes
|
||||
uart_flush_input (DRIVER_DATA(pnd)->port);
|
||||
uart_flush_input(DRIVER_DATA(pnd)->port);
|
||||
|
||||
uint8_t abtFrame[ARYGON_TX_BUFFER_LEN] = { DEV_ARYGON_PROTOCOL_TAMA, 0x00, 0x00, 0xff }; // Every packet must start with "0x32 0x00 0x00 0xff"
|
||||
|
||||
size_t szFrame = 0;
|
||||
if (szData > PN53x_NORMAL_FRAME__DATA_MAX_LEN) {
|
||||
// ARYGON Reader with PN532 equipped does not support extended frame (bug in ARYGON firmware?)
|
||||
log_put (LOG_CATEGORY, NFC_PRIORITY_TRACE, "ARYGON device does not support more than %d bytes as payload (requested: %zd)", PN53x_NORMAL_FRAME__DATA_MAX_LEN, szData);
|
||||
log_put(LOG_CATEGORY, NFC_PRIORITY_TRACE, "ARYGON device does not support more than %d bytes as payload (requested: %zd)", PN53x_NORMAL_FRAME__DATA_MAX_LEN, szData);
|
||||
pnd->last_error = NFC_EDEVNOTSUPP;
|
||||
return pnd->last_error;
|
||||
}
|
||||
|
||||
if ((res = pn53x_build_frame (abtFrame + 1, &szFrame, pbtData, szData)) < 0) {
|
||||
if ((res = pn53x_build_frame(abtFrame + 1, &szFrame, pbtData, szData)) < 0) {
|
||||
pnd->last_error = res;
|
||||
return pnd->last_error;
|
||||
}
|
||||
|
||||
if ((res = uart_send (DRIVER_DATA (pnd)->port, abtFrame, szFrame + 1, timeout)) != 0) {
|
||||
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Unable to transmit data. (TX)");
|
||||
if ((res = uart_send(DRIVER_DATA(pnd)->port, abtFrame, szFrame + 1, timeout)) != 0) {
|
||||
log_put(LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Unable to transmit data. (TX)");
|
||||
pnd->last_error = res;
|
||||
return pnd->last_error;
|
||||
}
|
||||
|
||||
uint8_t abtRxBuf[6];
|
||||
if ((res = uart_receive (DRIVER_DATA (pnd)->port, abtRxBuf, sizeof (abtRxBuf), 0, timeout)) != 0) {
|
||||
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Unable to read ACK");
|
||||
if ((res = uart_receive(DRIVER_DATA(pnd)->port, abtRxBuf, sizeof(abtRxBuf), 0, timeout)) != 0) {
|
||||
log_put(LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Unable to read ACK");
|
||||
pnd->last_error = res;
|
||||
return pnd->last_error;
|
||||
}
|
||||
|
||||
if (pn53x_check_ack_frame (pnd, abtRxBuf, sizeof(abtRxBuf)) == 0) {
|
||||
if (pn53x_check_ack_frame(pnd, abtRxBuf, sizeof(abtRxBuf)) == 0) {
|
||||
// The PN53x is running the sent command
|
||||
} else if (0 == memcmp(arygon_error_unknown_mode, abtRxBuf, sizeof(abtRxBuf))) {
|
||||
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Bad frame format.");
|
||||
log_put(LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Bad frame format.");
|
||||
// We have already read 6 bytes and arygon_error_unknown_mode is 10 bytes long
|
||||
// so we have to read 4 remaining bytes to be synchronized at the next receiving pass.
|
||||
pnd->last_error = uart_receive (DRIVER_DATA (pnd)->port, abtRxBuf, 4, 0, timeout);
|
||||
pnd->last_error = uart_receive(DRIVER_DATA(pnd)->port, abtRxBuf, 4, 0, timeout);
|
||||
return pnd->last_error;
|
||||
} else {
|
||||
return pnd->last_error;
|
||||
|
|
@ -357,34 +357,34 @@ arygon_tama_send (nfc_device *pnd, const uint8_t *pbtData, const size_t szData,
|
|||
}
|
||||
|
||||
static int
|
||||
arygon_abort (nfc_device *pnd)
|
||||
arygon_abort(nfc_device *pnd)
|
||||
{
|
||||
// Send a valid TAMA packet to wakup the PN53x (we will not have an answer, according to Arygon manual)
|
||||
uint8_t dummy[] = { 0x32, 0x00, 0x00, 0xff, 0x09, 0xf7, 0xd4, 0x00, 0x00, 0x6c, 0x69, 0x62, 0x6e, 0x66, 0x63, 0xbe, 0x00 };
|
||||
|
||||
uart_send (DRIVER_DATA (pnd)->port, dummy, sizeof (dummy), 0);
|
||||
uart_send(DRIVER_DATA(pnd)->port, dummy, sizeof(dummy), 0);
|
||||
|
||||
// Using Arygon device we can't send ACK frame to abort the running command
|
||||
return pn53x_check_communication (pnd);
|
||||
return pn53x_check_communication(pnd);
|
||||
}
|
||||
|
||||
int
|
||||
arygon_tama_receive (nfc_device *pnd, uint8_t *pbtData, const size_t szDataLen, int timeout)
|
||||
arygon_tama_receive(nfc_device *pnd, uint8_t *pbtData, const size_t szDataLen, int timeout)
|
||||
{
|
||||
uint8_t abtRxBuf[5];
|
||||
size_t len;
|
||||
void *abort_p = NULL;
|
||||
|
||||
#ifndef WIN32
|
||||
abort_p = &(DRIVER_DATA (pnd)->iAbortFds[1]);
|
||||
abort_p = &(DRIVER_DATA(pnd)->iAbortFds[1]);
|
||||
#else
|
||||
abort_p = (void*) & (DRIVER_DATA (pnd)->abort_flag);
|
||||
abort_p = (void*) & (DRIVER_DATA(pnd)->abort_flag);
|
||||
#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);
|
||||
|
||||
if (abort_p && (NFC_EOPABORTED == pnd->last_error)) {
|
||||
arygon_abort (pnd);
|
||||
arygon_abort(pnd);
|
||||
|
||||
/* last_error got reset by arygon_abort() */
|
||||
pnd->last_error = NFC_EOPABORTED;
|
||||
|
|
@ -392,32 +392,32 @@ arygon_tama_receive (nfc_device *pnd, uint8_t *pbtData, const size_t szDataLen,
|
|||
}
|
||||
|
||||
if (pnd->last_error != 0) {
|
||||
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Unable to receive data. (RX)");
|
||||
log_put(LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Unable to receive data. (RX)");
|
||||
return pnd->last_error;
|
||||
}
|
||||
|
||||
const uint8_t pn53x_preamble[3] = { 0x00, 0x00, 0xff };
|
||||
if (0 != (memcmp (abtRxBuf, pn53x_preamble, 3))) {
|
||||
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Frame preamble+start code mismatch");
|
||||
if (0 != (memcmp(abtRxBuf, pn53x_preamble, 3))) {
|
||||
log_put(LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Frame preamble+start code mismatch");
|
||||
pnd->last_error = NFC_EIO;
|
||||
return pnd->last_error;
|
||||
}
|
||||
|
||||
if ((0x01 == abtRxBuf[3]) && (0xff == abtRxBuf[4])) {
|
||||
// Error frame
|
||||
uart_receive (DRIVER_DATA (pnd)->port, abtRxBuf, 3, 0, timeout);
|
||||
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Application level error detected");
|
||||
uart_receive(DRIVER_DATA(pnd)->port, abtRxBuf, 3, 0, timeout);
|
||||
log_put(LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Application level error detected");
|
||||
pnd->last_error = NFC_EIO;
|
||||
return pnd->last_error;
|
||||
} else if ((0xff == abtRxBuf[3]) && (0xff == abtRxBuf[4])) {
|
||||
// Extended frame
|
||||
// ARYGON devices does not support extended frame sending
|
||||
abort ();
|
||||
abort();
|
||||
} else {
|
||||
// Normal frame
|
||||
if (256 != (abtRxBuf[3] + abtRxBuf[4])) {
|
||||
// TODO: Retry
|
||||
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Length checksum mismatch");
|
||||
log_put(LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Length checksum mismatch");
|
||||
pnd->last_error = NFC_EIO;
|
||||
return pnd->last_error;
|
||||
}
|
||||
|
|
@ -427,58 +427,58 @@ arygon_tama_receive (nfc_device *pnd, uint8_t *pbtData, const size_t szDataLen,
|
|||
}
|
||||
|
||||
if (len > szDataLen) {
|
||||
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "Unable to receive data: buffer too small. (szDataLen: %zu, len: %zu)", szDataLen, len);
|
||||
log_put(LOG_CATEGORY, NFC_PRIORITY_ERROR, "Unable to receive data: buffer too small. (szDataLen: %zu, len: %zu)", szDataLen, len);
|
||||
pnd->last_error = NFC_EIO;
|
||||
return pnd->last_error;
|
||||
}
|
||||
|
||||
// TFI + PD0 (CC+1)
|
||||
pnd->last_error = uart_receive (DRIVER_DATA (pnd)->port, abtRxBuf, 2, 0, timeout);
|
||||
pnd->last_error = uart_receive(DRIVER_DATA(pnd)->port, abtRxBuf, 2, 0, timeout);
|
||||
if (pnd->last_error != 0) {
|
||||
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Unable to receive data. (RX)");
|
||||
log_put(LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Unable to receive data. (RX)");
|
||||
return pnd->last_error;
|
||||
}
|
||||
|
||||
if (abtRxBuf[0] != 0xD5) {
|
||||
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "TFI Mismatch");
|
||||
log_put(LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "TFI Mismatch");
|
||||
pnd->last_error = NFC_EIO;
|
||||
return pnd->last_error;
|
||||
}
|
||||
|
||||
if (abtRxBuf[1] != CHIP_DATA (pnd)->last_command + 1) {
|
||||
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Command Code verification failed");
|
||||
if (abtRxBuf[1] != CHIP_DATA(pnd)->last_command + 1) {
|
||||
log_put(LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Command Code verification failed");
|
||||
pnd->last_error = NFC_EIO;
|
||||
return pnd->last_error;
|
||||
}
|
||||
|
||||
if (len) {
|
||||
pnd->last_error = uart_receive (DRIVER_DATA (pnd)->port, pbtData, len, 0, timeout);
|
||||
pnd->last_error = uart_receive(DRIVER_DATA(pnd)->port, pbtData, len, 0, timeout);
|
||||
if (pnd->last_error != 0) {
|
||||
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Unable to receive data. (RX)");
|
||||
log_put(LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Unable to receive data. (RX)");
|
||||
return pnd->last_error;
|
||||
}
|
||||
}
|
||||
|
||||
pnd->last_error = uart_receive (DRIVER_DATA (pnd)->port, abtRxBuf, 2, 0, timeout);
|
||||
pnd->last_error = uart_receive(DRIVER_DATA(pnd)->port, abtRxBuf, 2, 0, timeout);
|
||||
if (pnd->last_error != 0) {
|
||||
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Unable to receive data. (RX)");
|
||||
log_put(LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Unable to receive data. (RX)");
|
||||
return pnd->last_error;
|
||||
}
|
||||
|
||||
uint8_t btDCS = (256 - 0xD5);
|
||||
btDCS -= CHIP_DATA (pnd)->last_command + 1;
|
||||
btDCS -= CHIP_DATA(pnd)->last_command + 1;
|
||||
for (size_t szPos = 0; szPos < len; szPos++) {
|
||||
btDCS -= pbtData[szPos];
|
||||
}
|
||||
|
||||
if (btDCS != abtRxBuf[0]) {
|
||||
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Data checksum mismatch");
|
||||
log_put(LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Data checksum mismatch");
|
||||
pnd->last_error = NFC_EIO;
|
||||
return pnd->last_error;
|
||||
}
|
||||
|
||||
if (0x00 != abtRxBuf[1]) {
|
||||
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Frame postamble mismatch");
|
||||
log_put(LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Frame postamble mismatch");
|
||||
pnd->last_error = NFC_EIO;
|
||||
return pnd->last_error;
|
||||
}
|
||||
|
|
@ -487,53 +487,53 @@ arygon_tama_receive (nfc_device *pnd, uint8_t *pbtData, const size_t szDataLen,
|
|||
}
|
||||
|
||||
void
|
||||
arygon_firmware (nfc_device *pnd, char *str)
|
||||
arygon_firmware(nfc_device *pnd, char *str)
|
||||
{
|
||||
const uint8_t arygon_firmware_version_cmd[] = { DEV_ARYGON_PROTOCOL_ARYGON_ASCII, 'a', 'v' };
|
||||
uint8_t abtRx[16];
|
||||
size_t szRx = sizeof(abtRx);
|
||||
|
||||
|
||||
int res = uart_send (DRIVER_DATA (pnd)->port, arygon_firmware_version_cmd, sizeof (arygon_firmware_version_cmd), 0);
|
||||
int res = uart_send(DRIVER_DATA(pnd)->port, arygon_firmware_version_cmd, sizeof(arygon_firmware_version_cmd), 0);
|
||||
if (res != 0) {
|
||||
log_put (LOG_CATEGORY, NFC_PRIORITY_TRACE, "%s", "Unable to send ARYGON firmware command.");
|
||||
log_put(LOG_CATEGORY, NFC_PRIORITY_TRACE, "%s", "Unable to send ARYGON firmware command.");
|
||||
return;
|
||||
}
|
||||
res = uart_receive (DRIVER_DATA (pnd)->port, abtRx, szRx, 0, 0);
|
||||
res = uart_receive(DRIVER_DATA(pnd)->port, abtRx, szRx, 0, 0);
|
||||
if (res != 0) {
|
||||
log_put (LOG_CATEGORY, NFC_PRIORITY_TRACE, "%s", "Unable to retrieve ARYGON firmware version.");
|
||||
log_put(LOG_CATEGORY, NFC_PRIORITY_TRACE, "%s", "Unable to retrieve ARYGON firmware version.");
|
||||
return;
|
||||
}
|
||||
|
||||
if ( 0 == memcmp (abtRx, arygon_error_none, 6)) {
|
||||
if (0 == memcmp(abtRx, arygon_error_none, 6)) {
|
||||
uint8_t *p = abtRx + 6;
|
||||
unsigned int szData;
|
||||
sscanf ((const char*)p, "%02x%s", &szData, p);
|
||||
memcpy (str, p, szData);
|
||||
sscanf((const char*)p, "%02x%s", &szData, p);
|
||||
memcpy(str, p, szData);
|
||||
*(str + szData) = '\0';
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
arygon_reset_tama (nfc_device *pnd)
|
||||
arygon_reset_tama(nfc_device *pnd)
|
||||
{
|
||||
const uint8_t arygon_reset_tama_cmd[] = { DEV_ARYGON_PROTOCOL_ARYGON_ASCII, 'a', 'r' };
|
||||
uint8_t abtRx[10]; // Attempted response is 10 bytes long
|
||||
size_t szRx = sizeof(abtRx);
|
||||
int res;
|
||||
|
||||
uart_send (DRIVER_DATA (pnd)->port, arygon_reset_tama_cmd, sizeof (arygon_reset_tama_cmd), 500);
|
||||
uart_send(DRIVER_DATA(pnd)->port, arygon_reset_tama_cmd, sizeof(arygon_reset_tama_cmd), 500);
|
||||
|
||||
// Two reply are possible from ARYGON device: arygon_error_none (ie. in case the byte is well-sent)
|
||||
// or arygon_error_unknown_mode (ie. in case of the first byte was bad-transmitted)
|
||||
res = uart_receive (DRIVER_DATA (pnd)->port, abtRx, szRx, 0, 1000);
|
||||
res = uart_receive(DRIVER_DATA(pnd)->port, abtRx, szRx, 0, 1000);
|
||||
if (res != 0) {
|
||||
log_put (LOG_CATEGORY, NFC_PRIORITY_TRACE, "%s", "No reply to 'reset TAMA' command.");
|
||||
log_put(LOG_CATEGORY, NFC_PRIORITY_TRACE, "%s", "No reply to 'reset TAMA' command.");
|
||||
pnd->last_error = res;
|
||||
return pnd->last_error;
|
||||
}
|
||||
|
||||
if (0 != memcmp (abtRx, arygon_error_none, sizeof (arygon_error_none) - 1)) {
|
||||
if (0 != memcmp(abtRx, arygon_error_none, sizeof(arygon_error_none) - 1)) {
|
||||
pnd->last_error = NFC_EIO;
|
||||
return pnd->last_error;
|
||||
}
|
||||
|
|
@ -542,16 +542,16 @@ arygon_reset_tama (nfc_device *pnd)
|
|||
}
|
||||
|
||||
static int
|
||||
arygon_abort_command (nfc_device *pnd)
|
||||
arygon_abort_command(nfc_device *pnd)
|
||||
{
|
||||
if (pnd) {
|
||||
#ifndef WIN32
|
||||
close (DRIVER_DATA (pnd)->iAbortFds[0]);
|
||||
if (pipe (DRIVER_DATA (pnd)->iAbortFds) < 0) {
|
||||
close(DRIVER_DATA(pnd)->iAbortFds[0]);
|
||||
if (pipe(DRIVER_DATA(pnd)->iAbortFds) < 0) {
|
||||
return NFC_ESOFT;
|
||||
}
|
||||
#else
|
||||
DRIVER_DATA (pnd)->abort_flag = true;
|
||||
DRIVER_DATA(pnd)->abort_flag = true;
|
||||
#endif
|
||||
}
|
||||
return NFC_SUCCESS;
|
||||
|
|
|
|||
|
|
@ -30,13 +30,13 @@
|
|||
|
||||
# include <nfc/nfc-types.h>
|
||||
|
||||
bool arygon_probe (nfc_connstring connstrings[], size_t connstrings_len, size_t *pszDeviceFound);
|
||||
bool arygon_probe(nfc_connstring connstrings[], size_t connstrings_len, size_t *pszDeviceFound);
|
||||
|
||||
nfc_device *arygon_open (const nfc_connstring connstring);
|
||||
void arygon_close (nfc_device *pnd);
|
||||
nfc_device *arygon_open(const nfc_connstring connstring);
|
||||
void arygon_close(nfc_device *pnd);
|
||||
|
||||
int arygon_tama_send (nfc_device *pnd, const uint8_t *pbtData, const size_t szData, int timeout);
|
||||
int arygon_tama_receive (nfc_device *pnd, uint8_t *pbtData, const size_t szDat, int timeouta);
|
||||
int arygon_tama_send(nfc_device *pnd, const uint8_t *pbtData, const size_t szData, int timeout);
|
||||
int arygon_tama_receive(nfc_device *pnd, uint8_t *pbtData, const size_t szDat, int timeouta);
|
||||
|
||||
extern const struct nfc_driver arygon_driver;
|
||||
|
||||
|
|
|
|||
|
|
@ -48,8 +48,8 @@
|
|||
#define PN532_UART_DRIVER_NAME "pn532_uart"
|
||||
#define LOG_CATEGORY "libnfc.driver.pn532_uart"
|
||||
|
||||
int pn532_uart_ack (nfc_device *pnd);
|
||||
int pn532_uart_wakeup (nfc_device *pnd);
|
||||
int pn532_uart_ack(nfc_device *pnd);
|
||||
int pn532_uart_wakeup(nfc_device *pnd);
|
||||
|
||||
const struct pn53x_io pn532_uart_io;
|
||||
|
||||
|
|
@ -65,7 +65,7 @@ struct pn532_uart_data {
|
|||
#define DRIVER_DATA(pnd) ((struct pn532_uart_data*)(pnd->driver_data))
|
||||
|
||||
bool
|
||||
pn532_uart_probe (nfc_connstring connstrings[], size_t connstrings_len, size_t *pszDeviceFound)
|
||||
pn532_uart_probe(nfc_connstring connstrings[], size_t connstrings_len, size_t *pszDeviceFound)
|
||||
{
|
||||
/** @note: Due to UART bus we can't know if its really a pn532 without
|
||||
* sending some PN53x commands. But using this way to probe devices, we can
|
||||
|
|
@ -74,57 +74,57 @@ pn532_uart_probe (nfc_connstring connstrings[], size_t connstrings_len, size_t *
|
|||
(void) connstrings;
|
||||
(void) connstrings_len;
|
||||
*pszDeviceFound = 0;
|
||||
log_put (LOG_CATEGORY, NFC_PRIORITY_INFO, "%s", "Serial auto-probing have been disabled at compile time. Skipping autoprobe.");
|
||||
log_put(LOG_CATEGORY, NFC_PRIORITY_INFO, "%s", "Serial auto-probing have been disabled at compile time. Skipping autoprobe.");
|
||||
return false;
|
||||
#else /* SERIAL_AUTOPROBE_ENABLED */
|
||||
*pszDeviceFound = 0;
|
||||
|
||||
serial_port sp;
|
||||
char **acPorts = uart_list_ports ();
|
||||
char **acPorts = uart_list_ports();
|
||||
const char *acPort;
|
||||
int iDevice = 0;
|
||||
|
||||
while ((acPort = acPorts[iDevice++])) {
|
||||
sp = uart_open (acPort);
|
||||
log_put (LOG_CATEGORY, NFC_PRIORITY_TRACE, "Trying to find PN532 device on serial port: %s at %d bauds.", acPort, PN532_UART_DEFAULT_SPEED);
|
||||
sp = uart_open(acPort);
|
||||
log_put(LOG_CATEGORY, NFC_PRIORITY_TRACE, "Trying to find PN532 device on serial port: %s at %d bauds.", acPort, PN532_UART_DEFAULT_SPEED);
|
||||
|
||||
if ((sp != INVALID_SERIAL_PORT) && (sp != CLAIMED_SERIAL_PORT)) {
|
||||
// We need to flush input to be sure first reply does not comes from older byte transceive
|
||||
uart_flush_input (sp);
|
||||
uart_flush_input(sp);
|
||||
// Serial port claimed but we need to check if a PN532_UART is opened.
|
||||
uart_set_speed (sp, PN532_UART_DEFAULT_SPEED);
|
||||
uart_set_speed(sp, PN532_UART_DEFAULT_SPEED);
|
||||
|
||||
nfc_connstring connstring;
|
||||
snprintf (connstring, sizeof(nfc_connstring), "%s:%s:%"PRIu32, PN532_UART_DRIVER_NAME, acPort, PN532_UART_DEFAULT_SPEED);
|
||||
nfc_device *pnd = nfc_device_new (connstring);
|
||||
snprintf(connstring, sizeof(nfc_connstring), "%s:%s:%"PRIu32, PN532_UART_DRIVER_NAME, acPort, PN532_UART_DEFAULT_SPEED);
|
||||
nfc_device *pnd = nfc_device_new(connstring);
|
||||
pnd->driver = &pn532_uart_driver;
|
||||
pnd->driver_data = malloc(sizeof(struct pn532_uart_data));
|
||||
DRIVER_DATA (pnd)->port = sp;
|
||||
DRIVER_DATA(pnd)->port = sp;
|
||||
|
||||
// Alloc and init chip's data
|
||||
pn53x_data_new (pnd, &pn532_uart_io);
|
||||
pn53x_data_new(pnd, &pn532_uart_io);
|
||||
// SAMConfiguration command if needed to wakeup the chip and pn53x_SAMConfiguration check if the chip is a PN532
|
||||
CHIP_DATA (pnd)->type = PN532;
|
||||
CHIP_DATA(pnd)->type = PN532;
|
||||
// This device starts in LowVBat power mode
|
||||
CHIP_DATA (pnd)->power_mode = LOWVBAT;
|
||||
CHIP_DATA(pnd)->power_mode = LOWVBAT;
|
||||
|
||||
#ifndef WIN32
|
||||
// pipe-based abort mecanism
|
||||
pipe (DRIVER_DATA (pnd)->iAbortFds);
|
||||
pipe(DRIVER_DATA(pnd)->iAbortFds);
|
||||
#else
|
||||
DRIVER_DATA (pnd)->abort_flag = false;
|
||||
DRIVER_DATA(pnd)->abort_flag = false;
|
||||
#endif
|
||||
|
||||
// Check communication using "Diagnose" command, with "Communication test" (0x00)
|
||||
int res = pn53x_check_communication (pnd);
|
||||
pn53x_data_free (pnd);
|
||||
nfc_device_free (pnd);
|
||||
uart_close (sp);
|
||||
if(res < 0) {
|
||||
int res = pn53x_check_communication(pnd);
|
||||
pn53x_data_free(pnd);
|
||||
nfc_device_free(pnd);
|
||||
uart_close(sp);
|
||||
if (res < 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
memcpy (connstrings[*pszDeviceFound], connstring, sizeof (nfc_connstring));
|
||||
memcpy(connstrings[*pszDeviceFound], connstring, sizeof(nfc_connstring));
|
||||
(*pszDeviceFound)++;
|
||||
|
||||
// Test if we reach the maximum "wanted" devices
|
||||
|
|
@ -134,9 +134,9 @@ pn532_uart_probe (nfc_connstring connstrings[], size_t connstrings_len, size_t *
|
|||
}
|
||||
iDevice = 0;
|
||||
while ((acPort = acPorts[iDevice++])) {
|
||||
free ((void*)acPort);
|
||||
free((void*)acPort);
|
||||
}
|
||||
free (acPorts);
|
||||
free(acPorts);
|
||||
#endif /* SERIAL_AUTOPROBE_ENABLED */
|
||||
return true;
|
||||
}
|
||||
|
|
@ -147,59 +147,59 @@ struct pn532_uart_descriptor {
|
|||
};
|
||||
|
||||
static int
|
||||
pn532_connstring_decode (const nfc_connstring connstring, struct pn532_uart_descriptor *desc)
|
||||
pn532_connstring_decode(const nfc_connstring connstring, struct pn532_uart_descriptor *desc)
|
||||
{
|
||||
char *cs = malloc (strlen (connstring) + 1);
|
||||
char *cs = malloc(strlen(connstring) + 1);
|
||||
if (!cs) {
|
||||
perror ("malloc");
|
||||
perror("malloc");
|
||||
return -1;
|
||||
}
|
||||
strcpy (cs, connstring);
|
||||
const char *driver_name = strtok (cs, ":");
|
||||
strcpy(cs, connstring);
|
||||
const char *driver_name = strtok(cs, ":");
|
||||
if (!driver_name) {
|
||||
// Parse error
|
||||
free (cs);
|
||||
free(cs);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (0 != strcmp (driver_name, PN532_UART_DRIVER_NAME)) {
|
||||
if (0 != strcmp(driver_name, PN532_UART_DRIVER_NAME)) {
|
||||
// Driver name does not match.
|
||||
free (cs);
|
||||
free(cs);
|
||||
return 0;
|
||||
}
|
||||
|
||||
const char *port = strtok (NULL, ":");
|
||||
const char *port = strtok(NULL, ":");
|
||||
if (!port) {
|
||||
// Only driver name was specified (or parsing error)
|
||||
free (cs);
|
||||
free(cs);
|
||||
return 1;
|
||||
}
|
||||
strncpy (desc->port, port, sizeof(desc->port) - 1);
|
||||
strncpy(desc->port, port, sizeof(desc->port) - 1);
|
||||
desc->port[sizeof(desc->port) - 1] = '\0';
|
||||
|
||||
const char *speed_s = strtok (NULL, ":");
|
||||
const char *speed_s = strtok(NULL, ":");
|
||||
if (!speed_s) {
|
||||
// speed not specified (or parsing error)
|
||||
free (cs);
|
||||
free(cs);
|
||||
return 2;
|
||||
}
|
||||
unsigned long speed;
|
||||
if (sscanf (speed_s, "%lu", &speed) != 1) {
|
||||
if (sscanf(speed_s, "%lu", &speed) != 1) {
|
||||
// speed_s is not a number
|
||||
free (cs);
|
||||
free(cs);
|
||||
return 2;
|
||||
}
|
||||
desc->speed = speed;
|
||||
|
||||
free (cs);
|
||||
free(cs);
|
||||
return 3;
|
||||
}
|
||||
|
||||
nfc_device *
|
||||
pn532_uart_open (const nfc_connstring connstring)
|
||||
pn532_uart_open(const nfc_connstring connstring)
|
||||
{
|
||||
struct pn532_uart_descriptor ndd;
|
||||
int connstring_decode_level = pn532_connstring_decode (connstring, &ndd);
|
||||
int connstring_decode_level = pn532_connstring_decode(connstring, &ndd);
|
||||
|
||||
if (connstring_decode_level < 2) {
|
||||
return NULL;
|
||||
|
|
@ -210,31 +210,31 @@ pn532_uart_open (const nfc_connstring connstring)
|
|||
serial_port sp;
|
||||
nfc_device *pnd = NULL;
|
||||
|
||||
log_put (LOG_CATEGORY, NFC_PRIORITY_TRACE, "Attempt to open: %s at %d bauds.", ndd.port, ndd.speed);
|
||||
sp = uart_open (ndd.port);
|
||||
log_put(LOG_CATEGORY, NFC_PRIORITY_TRACE, "Attempt to open: %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);
|
||||
log_put(LOG_CATEGORY, NFC_PRIORITY_ERROR, "Invalid serial port: %s", ndd.port);
|
||||
if (sp == CLAIMED_SERIAL_PORT)
|
||||
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "Serial port already claimed: %s", ndd.port);
|
||||
log_put(LOG_CATEGORY, NFC_PRIORITY_ERROR, "Serial port already claimed: %s", ndd.port);
|
||||
if ((sp == CLAIMED_SERIAL_PORT) || (sp == INVALID_SERIAL_PORT))
|
||||
return NULL;
|
||||
|
||||
// We need to flush input to be sure first reply does not comes from older byte transceive
|
||||
uart_flush_input (sp);
|
||||
uart_set_speed (sp, ndd.speed);
|
||||
uart_flush_input(sp);
|
||||
uart_set_speed(sp, ndd.speed);
|
||||
|
||||
// We have a connection
|
||||
pnd = nfc_device_new (connstring);
|
||||
snprintf (pnd->name, sizeof (pnd->name), "%s:%s", PN532_UART_DRIVER_NAME, ndd.port);
|
||||
pnd = nfc_device_new(connstring);
|
||||
snprintf(pnd->name, sizeof(pnd->name), "%s:%s", PN532_UART_DRIVER_NAME, ndd.port);
|
||||
|
||||
pnd->driver_data = malloc(sizeof(struct pn532_uart_data));
|
||||
DRIVER_DATA (pnd)->port = sp;
|
||||
DRIVER_DATA(pnd)->port = sp;
|
||||
|
||||
// Alloc and init chip's data
|
||||
pn53x_data_new (pnd, &pn532_uart_io);
|
||||
pn53x_data_new(pnd, &pn532_uart_io);
|
||||
// SAMConfiguration command if needed to wakeup the chip and pn53x_SAMConfiguration check if the chip is a PN532
|
||||
CHIP_DATA (pnd)->type = PN532;
|
||||
CHIP_DATA(pnd)->type = PN532;
|
||||
// This device starts in LowVBat mode
|
||||
CHIP_DATA(pnd)->power_mode = LOWVBAT;
|
||||
|
||||
|
|
@ -244,15 +244,15 @@ pn532_uart_open (const nfc_connstring connstring)
|
|||
|
||||
#ifndef WIN32
|
||||
// pipe-based abort mecanism
|
||||
pipe (DRIVER_DATA (pnd)->iAbortFds);
|
||||
pipe(DRIVER_DATA(pnd)->iAbortFds);
|
||||
#else
|
||||
DRIVER_DATA (pnd)->abort_flag = false;
|
||||
DRIVER_DATA(pnd)->abort_flag = false;
|
||||
#endif
|
||||
|
||||
// Check communication using "Diagnose" command, with "Communication test" (0x00)
|
||||
if (pn53x_check_communication (pnd) < 0) {
|
||||
nfc_perror (pnd, "pn53x_check_communication");
|
||||
pn532_uart_close (pnd);
|
||||
if (pn53x_check_communication(pnd) < 0) {
|
||||
nfc_perror(pnd, "pn53x_check_communication");
|
||||
pn532_uart_close(pnd);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
@ -261,38 +261,38 @@ pn532_uart_open (const nfc_connstring connstring)
|
|||
}
|
||||
|
||||
void
|
||||
pn532_uart_close (nfc_device *pnd)
|
||||
pn532_uart_close(nfc_device *pnd)
|
||||
{
|
||||
// Release UART port
|
||||
uart_close (DRIVER_DATA(pnd)->port);
|
||||
uart_close(DRIVER_DATA(pnd)->port);
|
||||
|
||||
#ifndef WIN32
|
||||
// Release file descriptors used for abort mecanism
|
||||
close (DRIVER_DATA (pnd)->iAbortFds[0]);
|
||||
close (DRIVER_DATA (pnd)->iAbortFds[1]);
|
||||
close(DRIVER_DATA(pnd)->iAbortFds[0]);
|
||||
close(DRIVER_DATA(pnd)->iAbortFds[1]);
|
||||
#endif
|
||||
|
||||
pn53x_data_free (pnd);
|
||||
nfc_device_free (pnd);
|
||||
pn53x_data_free(pnd);
|
||||
nfc_device_free(pnd);
|
||||
}
|
||||
|
||||
int
|
||||
pn532_uart_wakeup (nfc_device *pnd)
|
||||
pn532_uart_wakeup(nfc_device *pnd)
|
||||
{
|
||||
/* High Speed Unit (HSU) wake up consist to send 0x55 and wait a "long" delay for PN532 being wakeup. */
|
||||
const uint8_t pn532_wakeup_preamble[] = { 0x55, 0x55, 0x00, 0x00, 0x00 };
|
||||
int res = uart_send (DRIVER_DATA(pnd)->port, pn532_wakeup_preamble, sizeof (pn532_wakeup_preamble), 0);
|
||||
int res = uart_send(DRIVER_DATA(pnd)->port, pn532_wakeup_preamble, sizeof(pn532_wakeup_preamble), 0);
|
||||
CHIP_DATA(pnd)->power_mode = NORMAL; // PN532 should now be awake
|
||||
return res;
|
||||
}
|
||||
|
||||
#define PN532_BUFFER_LEN (PN53x_EXTENDED_FRAME__DATA_MAX_LEN + PN53x_EXTENDED_FRAME__OVERHEAD)
|
||||
int
|
||||
pn532_uart_send (nfc_device *pnd, const uint8_t *pbtData, const size_t szData, int timeout)
|
||||
pn532_uart_send(nfc_device *pnd, const uint8_t *pbtData, const size_t szData, int timeout)
|
||||
{
|
||||
int res = 0;
|
||||
// Before sending anything, we need to discard from any junk bytes
|
||||
uart_flush_input (DRIVER_DATA(pnd)->port);
|
||||
uart_flush_input(DRIVER_DATA(pnd)->port);
|
||||
|
||||
switch (CHIP_DATA(pnd)->power_mode) {
|
||||
case LOWVBAT: {
|
||||
|
|
@ -301,7 +301,7 @@ pn532_uart_send (nfc_device *pnd, const uint8_t *pbtData, const size_t szData, i
|
|||
return res;
|
||||
}
|
||||
// According to PN532 application note, C106 appendix: to go out Low Vbat mode and enter in normal mode we need to send a SAMConfiguration command
|
||||
if ((res = pn53x_SAMConfiguration (pnd, 0x01, 1000)) < 0) {
|
||||
if ((res = pn53x_SAMConfiguration(pnd, 0x01, 1000)) < 0) {
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
|
@ -320,27 +320,27 @@ pn532_uart_send (nfc_device *pnd, const uint8_t *pbtData, const size_t szData, i
|
|||
uint8_t abtFrame[PN532_BUFFER_LEN] = { 0x00, 0x00, 0xff }; // Every packet must start with "00 00 ff"
|
||||
size_t szFrame = 0;
|
||||
|
||||
if ((res = pn53x_build_frame (abtFrame, &szFrame, pbtData, szData)) < 0) {
|
||||
if ((res = pn53x_build_frame(abtFrame, &szFrame, pbtData, szData)) < 0) {
|
||||
pnd->last_error = res;
|
||||
return pnd->last_error;
|
||||
}
|
||||
|
||||
res = uart_send (DRIVER_DATA(pnd)->port, abtFrame, szFrame, timeout);
|
||||
res = uart_send(DRIVER_DATA(pnd)->port, abtFrame, szFrame, timeout);
|
||||
if (res != 0) {
|
||||
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Unable to transmit data. (TX)");
|
||||
log_put(LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Unable to transmit data. (TX)");
|
||||
pnd->last_error = res;
|
||||
return pnd->last_error;
|
||||
}
|
||||
|
||||
uint8_t abtRxBuf[6];
|
||||
res = uart_receive (DRIVER_DATA(pnd)->port, abtRxBuf, 6, 0, timeout);
|
||||
res = uart_receive(DRIVER_DATA(pnd)->port, abtRxBuf, 6, 0, timeout);
|
||||
if (res != 0) {
|
||||
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Unable to read ACK");
|
||||
log_put(LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Unable to read ACK");
|
||||
pnd->last_error = res;
|
||||
return pnd->last_error;
|
||||
}
|
||||
|
||||
if (pn53x_check_ack_frame (pnd, abtRxBuf, sizeof(abtRxBuf)) == 0) {
|
||||
if (pn53x_check_ack_frame(pnd, abtRxBuf, sizeof(abtRxBuf)) == 0) {
|
||||
// The PN53x is running the sent command
|
||||
} else {
|
||||
return pnd->last_error;
|
||||
|
|
@ -349,22 +349,22 @@ pn532_uart_send (nfc_device *pnd, const uint8_t *pbtData, const size_t szData, i
|
|||
}
|
||||
|
||||
int
|
||||
pn532_uart_receive (nfc_device *pnd, uint8_t *pbtData, const size_t szDataLen, int timeout)
|
||||
pn532_uart_receive(nfc_device *pnd, uint8_t *pbtData, const size_t szDataLen, int timeout)
|
||||
{
|
||||
uint8_t abtRxBuf[5];
|
||||
size_t len;
|
||||
void *abort_p = NULL;
|
||||
|
||||
#ifndef WIN32
|
||||
abort_p = &(DRIVER_DATA (pnd)->iAbortFds[1]);
|
||||
abort_p = &(DRIVER_DATA(pnd)->iAbortFds[1]);
|
||||
#else
|
||||
abort_p = (void*) & (DRIVER_DATA (pnd)->abort_flag);
|
||||
abort_p = (void*) & (DRIVER_DATA(pnd)->abort_flag);
|
||||
#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);
|
||||
|
||||
if (abort_p && (NFC_EOPABORTED == pnd->last_error)) {
|
||||
return pn532_uart_ack (pnd);
|
||||
return pn532_uart_ack(pnd);
|
||||
}
|
||||
|
||||
if (pnd->last_error < 0) {
|
||||
|
|
@ -372,29 +372,29 @@ pn532_uart_receive (nfc_device *pnd, uint8_t *pbtData, const size_t szDataLen, i
|
|||
}
|
||||
|
||||
const uint8_t pn53x_preamble[3] = { 0x00, 0x00, 0xff };
|
||||
if (0 != (memcmp (abtRxBuf, pn53x_preamble, 3))) {
|
||||
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Frame preamble+start code mismatch");
|
||||
if (0 != (memcmp(abtRxBuf, pn53x_preamble, 3))) {
|
||||
log_put(LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Frame preamble+start code mismatch");
|
||||
pnd->last_error = NFC_EIO;
|
||||
goto error;
|
||||
}
|
||||
|
||||
if ((0x01 == abtRxBuf[3]) && (0xff == abtRxBuf[4])) {
|
||||
// Error frame
|
||||
uart_receive (DRIVER_DATA (pnd)->port, abtRxBuf, 3, 0, timeout);
|
||||
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Application level error detected");
|
||||
uart_receive(DRIVER_DATA(pnd)->port, abtRxBuf, 3, 0, timeout);
|
||||
log_put(LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Application level error detected");
|
||||
pnd->last_error = NFC_EIO;
|
||||
goto error;
|
||||
} else if ((0xff == abtRxBuf[3]) && (0xff == abtRxBuf[4])) {
|
||||
// Extended frame
|
||||
pnd->last_error = uart_receive (DRIVER_DATA(pnd)->port, abtRxBuf, 3, 0, timeout);
|
||||
pnd->last_error = uart_receive(DRIVER_DATA(pnd)->port, abtRxBuf, 3, 0, timeout);
|
||||
if (pnd->last_error != 0) {
|
||||
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Unable to receive data. (RX)");
|
||||
log_put(LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Unable to receive data. (RX)");
|
||||
goto error;
|
||||
}
|
||||
// (abtRxBuf[0] << 8) + abtRxBuf[1] (LEN) include TFI + (CC+1)
|
||||
len = (abtRxBuf[0] << 8) + abtRxBuf[1] - 2;
|
||||
if (((abtRxBuf[0] + abtRxBuf[1] + abtRxBuf[2]) % 256) != 0) {
|
||||
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Length checksum mismatch");
|
||||
log_put(LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Length checksum mismatch");
|
||||
pnd->last_error = NFC_EIO;
|
||||
goto error;
|
||||
}
|
||||
|
|
@ -402,7 +402,7 @@ pn532_uart_receive (nfc_device *pnd, uint8_t *pbtData, const size_t szDataLen, i
|
|||
// Normal frame
|
||||
if (256 != (abtRxBuf[3] + abtRxBuf[4])) {
|
||||
// TODO: Retry
|
||||
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Length checksum mismatch");
|
||||
log_put(LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Length checksum mismatch");
|
||||
pnd->last_error = NFC_EIO;
|
||||
goto error;
|
||||
}
|
||||
|
|
@ -412,70 +412,70 @@ pn532_uart_receive (nfc_device *pnd, uint8_t *pbtData, const size_t szDataLen, i
|
|||
}
|
||||
|
||||
if (len > szDataLen) {
|
||||
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "Unable to receive data: buffer too small. (szDataLen: %zu, len: %zu)", szDataLen, len);
|
||||
log_put(LOG_CATEGORY, NFC_PRIORITY_ERROR, "Unable to receive data: buffer too small. (szDataLen: %zu, len: %zu)", szDataLen, len);
|
||||
pnd->last_error = NFC_EIO;
|
||||
goto error;
|
||||
}
|
||||
|
||||
// TFI + PD0 (CC+1)
|
||||
pnd->last_error = uart_receive (DRIVER_DATA (pnd)->port, abtRxBuf, 2, 0, timeout);
|
||||
pnd->last_error = uart_receive(DRIVER_DATA(pnd)->port, abtRxBuf, 2, 0, timeout);
|
||||
if (pnd->last_error != 0) {
|
||||
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Unable to receive data. (RX)");
|
||||
log_put(LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Unable to receive data. (RX)");
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (abtRxBuf[0] != 0xD5) {
|
||||
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "TFI Mismatch");
|
||||
log_put(LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "TFI Mismatch");
|
||||
pnd->last_error = NFC_EIO;
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (abtRxBuf[1] != CHIP_DATA (pnd)->last_command + 1) {
|
||||
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Command Code verification failed");
|
||||
if (abtRxBuf[1] != CHIP_DATA(pnd)->last_command + 1) {
|
||||
log_put(LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Command Code verification failed");
|
||||
pnd->last_error = NFC_EIO;
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (len) {
|
||||
pnd->last_error = uart_receive (DRIVER_DATA (pnd)->port, pbtData, len, 0, timeout);
|
||||
pnd->last_error = uart_receive(DRIVER_DATA(pnd)->port, pbtData, len, 0, timeout);
|
||||
if (pnd->last_error != 0) {
|
||||
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Unable to receive data. (RX)");
|
||||
log_put(LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Unable to receive data. (RX)");
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
|
||||
pnd->last_error = uart_receive (DRIVER_DATA (pnd)->port, abtRxBuf, 2, 0, timeout);
|
||||
pnd->last_error = uart_receive(DRIVER_DATA(pnd)->port, abtRxBuf, 2, 0, timeout);
|
||||
if (pnd->last_error != 0) {
|
||||
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Unable to receive data. (RX)");
|
||||
log_put(LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Unable to receive data. (RX)");
|
||||
goto error;
|
||||
}
|
||||
|
||||
uint8_t btDCS = (256 - 0xD5);
|
||||
btDCS -= CHIP_DATA (pnd)->last_command + 1;
|
||||
btDCS -= CHIP_DATA(pnd)->last_command + 1;
|
||||
for (size_t szPos = 0; szPos < len; szPos++) {
|
||||
btDCS -= pbtData[szPos];
|
||||
}
|
||||
|
||||
if (btDCS != abtRxBuf[0]) {
|
||||
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Data checksum mismatch");
|
||||
log_put(LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Data checksum mismatch");
|
||||
pnd->last_error = NFC_EIO;
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (0x00 != abtRxBuf[1]) {
|
||||
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Frame postamble mismatch");
|
||||
log_put(LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Frame postamble mismatch");
|
||||
pnd->last_error = NFC_EIO;
|
||||
goto error;
|
||||
}
|
||||
// The PN53x command is done and we successfully received the reply
|
||||
return len;
|
||||
error:
|
||||
uart_flush_input (DRIVER_DATA (pnd)->port);
|
||||
uart_flush_input(DRIVER_DATA(pnd)->port);
|
||||
return pnd->last_error;
|
||||
}
|
||||
|
||||
int
|
||||
pn532_uart_ack (nfc_device *pnd)
|
||||
pn532_uart_ack(nfc_device *pnd)
|
||||
{
|
||||
int res = 0;
|
||||
if (POWERDOWN == CHIP_DATA(pnd)->power_mode) {
|
||||
|
|
@ -483,18 +483,18 @@ pn532_uart_ack (nfc_device *pnd)
|
|||
return res;
|
||||
}
|
||||
}
|
||||
return (uart_send (DRIVER_DATA(pnd)->port, pn53x_ack_frame, sizeof (pn53x_ack_frame), 0));
|
||||
return (uart_send(DRIVER_DATA(pnd)->port, pn53x_ack_frame, sizeof(pn53x_ack_frame), 0));
|
||||
}
|
||||
|
||||
static int
|
||||
pn532_uart_abort_command (nfc_device *pnd)
|
||||
pn532_uart_abort_command(nfc_device *pnd)
|
||||
{
|
||||
if (pnd) {
|
||||
#ifndef WIN32
|
||||
close (DRIVER_DATA (pnd)->iAbortFds[0]);
|
||||
pipe (DRIVER_DATA (pnd)->iAbortFds);
|
||||
close(DRIVER_DATA(pnd)->iAbortFds[0]);
|
||||
pipe(DRIVER_DATA(pnd)->iAbortFds);
|
||||
#else
|
||||
DRIVER_DATA (pnd)->abort_flag = true;
|
||||
DRIVER_DATA(pnd)->abort_flag = true;
|
||||
#endif
|
||||
}
|
||||
return NFC_SUCCESS;
|
||||
|
|
|
|||
|
|
@ -29,12 +29,12 @@
|
|||
|
||||
# include <nfc/nfc-types.h>
|
||||
|
||||
bool pn532_uart_probe (nfc_connstring connstrings[], size_t connstrings_len, size_t *pszDeviceFound);
|
||||
bool pn532_uart_probe(nfc_connstring connstrings[], size_t connstrings_len, size_t *pszDeviceFound);
|
||||
|
||||
nfc_device *pn532_uart_open (const nfc_connstring connstring);
|
||||
void pn532_uart_close (nfc_device *pnd);
|
||||
int pn532_uart_send (nfc_device *pnd, const uint8_t *pbtData, const size_t szData, int timeout);
|
||||
int pn532_uart_receive (nfc_device *pnd, uint8_t *pbtData, const size_t szData, int timeout);
|
||||
nfc_device *pn532_uart_open(const nfc_connstring connstring);
|
||||
void pn532_uart_close(nfc_device *pnd);
|
||||
int pn532_uart_send(nfc_device *pnd, const uint8_t *pbtData, const size_t szData, int timeout);
|
||||
int pn532_uart_receive(nfc_device *pnd, uint8_t *pbtData, const size_t szData, int timeout);
|
||||
|
||||
extern const struct nfc_driver pn532_uart_driver;
|
||||
|
||||
|
|
|
|||
|
|
@ -86,34 +86,34 @@ struct pn53x_usb_data {
|
|||
};
|
||||
|
||||
const struct pn53x_io pn53x_usb_io;
|
||||
bool pn53x_usb_get_usb_device_name (struct usb_device *dev, usb_dev_handle *udev, char *buffer, size_t len);
|
||||
int pn53x_usb_init (nfc_device *pnd);
|
||||
bool pn53x_usb_get_usb_device_name(struct usb_device *dev, usb_dev_handle *udev, char *buffer, size_t len);
|
||||
int pn53x_usb_init(nfc_device *pnd);
|
||||
|
||||
static int
|
||||
pn53x_usb_bulk_read (struct pn53x_usb_data *data, uint8_t abtRx[], const size_t szRx, const int timeout)
|
||||
pn53x_usb_bulk_read(struct pn53x_usb_data *data, uint8_t abtRx[], const size_t szRx, const int timeout)
|
||||
{
|
||||
int res = usb_bulk_read (data->pudh, data->uiEndPointIn, (char *) abtRx, szRx, timeout);
|
||||
int res = usb_bulk_read(data->pudh, data->uiEndPointIn, (char *) abtRx, szRx, timeout);
|
||||
if (res > 0) {
|
||||
LOG_HEX ("RX", abtRx, res);
|
||||
LOG_HEX("RX", abtRx, res);
|
||||
} else if (res < 0) {
|
||||
if (res != -USB_TIMEDOUT)
|
||||
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "Unable to read from USB (%s)", _usb_strerror (res));
|
||||
log_put(LOG_CATEGORY, NFC_PRIORITY_ERROR, "Unable to read from USB (%s)", _usb_strerror(res));
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
static int
|
||||
pn53x_usb_bulk_write (struct pn53x_usb_data *data, uint8_t abtTx[], const size_t szTx, const int timeout)
|
||||
pn53x_usb_bulk_write(struct pn53x_usb_data *data, uint8_t abtTx[], const size_t szTx, const int timeout)
|
||||
{
|
||||
LOG_HEX ("TX", abtTx, szTx);
|
||||
int res = usb_bulk_write (data->pudh, data->uiEndPointOut, (char *) abtTx, szTx, timeout);
|
||||
LOG_HEX("TX", abtTx, szTx);
|
||||
int res = usb_bulk_write(data->pudh, data->uiEndPointOut, (char *) abtTx, szTx, timeout);
|
||||
if (res > 0) {
|
||||
// HACK This little hack is a well know problem of USB, see http://www.libusb.org/ticket/6 for more details
|
||||
if ((res % data->uiMaxPacketSize) == 0) {
|
||||
usb_bulk_write (data->pudh, data->uiEndPointOut, "\0", 0, timeout);
|
||||
usb_bulk_write(data->pudh, data->uiEndPointOut, "\0", 0, timeout);
|
||||
}
|
||||
} else {
|
||||
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "Unable to write to USB (%s)", _usb_strerror (res));
|
||||
log_put(LOG_CATEGORY, NFC_PRIORITY_ERROR, "Unable to write to USB (%s)", _usb_strerror(res));
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
|
@ -135,9 +135,9 @@ const struct pn53x_usb_supported_device pn53x_usb_supported_devices[] = {
|
|||
};
|
||||
|
||||
static pn53x_usb_model
|
||||
pn53x_usb_get_device_model (uint16_t vendor_id, uint16_t product_id)
|
||||
pn53x_usb_get_device_model(uint16_t vendor_id, uint16_t product_id)
|
||||
{
|
||||
for (size_t n = 0; n < sizeof (pn53x_usb_supported_devices) / sizeof (struct pn53x_usb_supported_device); n++) {
|
||||
for (size_t n = 0; n < sizeof(pn53x_usb_supported_devices) / sizeof(struct pn53x_usb_supported_device); n++) {
|
||||
if ((vendor_id == pn53x_usb_supported_devices[n].vendor_id) &&
|
||||
(product_id == pn53x_usb_supported_devices[n].product_id))
|
||||
return pn53x_usb_supported_devices[n].model;
|
||||
|
|
@ -146,11 +146,11 @@ pn53x_usb_get_device_model (uint16_t vendor_id, uint16_t product_id)
|
|||
return UNKNOWN;
|
||||
}
|
||||
|
||||
int pn53x_usb_ack (nfc_device *pnd);
|
||||
int pn53x_usb_ack(nfc_device *pnd);
|
||||
|
||||
// Find transfer endpoints for bulk transfers
|
||||
static void
|
||||
pn53x_usb_get_end_points (struct usb_device *dev, struct pn53x_usb_data *data)
|
||||
pn53x_usb_get_end_points(struct usb_device *dev, struct pn53x_usb_data *data)
|
||||
{
|
||||
uint32_t uiIndex;
|
||||
uint32_t uiEndPoint;
|
||||
|
|
@ -179,23 +179,23 @@ pn53x_usb_get_end_points (struct usb_device *dev, struct pn53x_usb_data *data)
|
|||
}
|
||||
|
||||
bool
|
||||
pn53x_usb_probe (nfc_connstring connstrings[], size_t connstrings_len, size_t *pszDeviceFound)
|
||||
pn53x_usb_probe(nfc_connstring connstrings[], size_t connstrings_len, size_t *pszDeviceFound)
|
||||
{
|
||||
usb_init ();
|
||||
usb_init();
|
||||
|
||||
int res;
|
||||
// usb_find_busses will find all of the busses on the system. Returns the
|
||||
// number of changes since previous call to this function (total of new
|
||||
// busses and busses removed).
|
||||
if ((res = usb_find_busses () < 0)) {
|
||||
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "Unable to find USB busses (%s)", _usb_strerror (res));
|
||||
if ((res = usb_find_busses() < 0)) {
|
||||
log_put(LOG_CATEGORY, NFC_PRIORITY_ERROR, "Unable to find USB busses (%s)", _usb_strerror(res));
|
||||
return false;
|
||||
}
|
||||
// usb_find_devices will find all of the devices on each bus. This should be
|
||||
// called after usb_find_busses. Returns the number of changes since the
|
||||
// previous call to this function (total of new device and devices removed).
|
||||
if ((res = usb_find_devices () < 0)) {
|
||||
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "Unable to find USB devices (%s)", _usb_strerror (res));
|
||||
if ((res = usb_find_devices() < 0)) {
|
||||
log_put(LOG_CATEGORY, NFC_PRIORITY_ERROR, "Unable to find USB devices (%s)", _usb_strerror(res));
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -203,11 +203,11 @@ pn53x_usb_probe (nfc_connstring connstrings[], size_t connstrings_len, size_t *p
|
|||
|
||||
uint32_t uiBusIndex = 0;
|
||||
struct usb_bus *bus;
|
||||
for (bus = usb_get_busses (); bus; bus = bus->next) {
|
||||
for (bus = usb_get_busses(); bus; bus = bus->next) {
|
||||
struct usb_device *dev;
|
||||
|
||||
for (dev = bus->devices; dev; dev = dev->next, uiBusIndex++) {
|
||||
for (size_t n = 0; n < sizeof (pn53x_usb_supported_devices) / sizeof (struct pn53x_usb_supported_device); n++) {
|
||||
for (size_t n = 0; n < sizeof(pn53x_usb_supported_devices) / sizeof(struct pn53x_usb_supported_device); n++) {
|
||||
if ((pn53x_usb_supported_devices[n].vendor_id == dev->descriptor.idVendor) &&
|
||||
(pn53x_usb_supported_devices[n].product_id == dev->descriptor.idProduct)) {
|
||||
// Make sure there are 2 endpoints available
|
||||
|
|
@ -221,21 +221,21 @@ pn53x_usb_probe (nfc_connstring connstrings[], size_t connstrings_len, size_t *p
|
|||
continue;
|
||||
}
|
||||
|
||||
usb_dev_handle *udev = usb_open (dev);
|
||||
usb_dev_handle *udev = usb_open(dev);
|
||||
|
||||
// Set configuration
|
||||
res = usb_set_configuration (udev, 1);
|
||||
res = usb_set_configuration(udev, 1);
|
||||
if (res < 0) {
|
||||
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "Unable to set USB configuration (%s)", _usb_strerror (res));
|
||||
usb_close (udev);
|
||||
log_put(LOG_CATEGORY, NFC_PRIORITY_ERROR, "Unable to set USB configuration (%s)", _usb_strerror(res));
|
||||
usb_close(udev);
|
||||
// we failed to use the device
|
||||
continue;
|
||||
}
|
||||
|
||||
// pn53x_usb_get_usb_device_name (dev, udev, pnddDevices[*pszDeviceFound].acDevice, sizeof (pnddDevices[*pszDeviceFound].acDevice));
|
||||
log_put (LOG_CATEGORY, NFC_PRIORITY_TRACE, "device found: Bus %s Device %s", bus->dirname, dev->filename);
|
||||
usb_close (udev);
|
||||
snprintf (connstrings[*pszDeviceFound], sizeof(nfc_connstring), "%s:%s:%s", PN53X_USB_DRIVER_NAME, bus->dirname, dev->filename);
|
||||
log_put(LOG_CATEGORY, NFC_PRIORITY_TRACE, "device found: Bus %s Device %s", bus->dirname, dev->filename);
|
||||
usb_close(udev);
|
||||
snprintf(connstrings[*pszDeviceFound], sizeof(nfc_connstring), "%s:%s:%s", PN53X_USB_DRIVER_NAME, bus->dirname, dev->filename);
|
||||
(*pszDeviceFound)++;
|
||||
// Test if we reach the maximum "wanted" devices
|
||||
if ((*pszDeviceFound) == connstrings_len) {
|
||||
|
|
@ -255,51 +255,51 @@ struct pn53x_usb_descriptor {
|
|||
};
|
||||
|
||||
static int
|
||||
pn53x_usb_connstring_decode (const nfc_connstring connstring, struct pn53x_usb_descriptor *desc)
|
||||
pn53x_usb_connstring_decode(const nfc_connstring connstring, struct pn53x_usb_descriptor *desc)
|
||||
{
|
||||
int n = strlen (connstring) + 1;
|
||||
char *driver_name = malloc (n);
|
||||
char *dirname = malloc (n);
|
||||
char *filename = malloc (n);
|
||||
int n = strlen(connstring) + 1;
|
||||
char *driver_name = malloc(n);
|
||||
char *dirname = malloc(n);
|
||||
char *filename = malloc(n);
|
||||
|
||||
driver_name[0] = '\0';
|
||||
|
||||
int res = sscanf (connstring, "%[^:]:%[^:]:%[^:]", driver_name, dirname, filename);
|
||||
int res = sscanf(connstring, "%[^:]:%[^:]:%[^:]", driver_name, dirname, filename);
|
||||
|
||||
if (!res || (0 != strcmp (driver_name, PN53X_USB_DRIVER_NAME))) {
|
||||
if (!res || (0 != strcmp(driver_name, PN53X_USB_DRIVER_NAME))) {
|
||||
// Driver name does not match.
|
||||
res = 0;
|
||||
} else {
|
||||
desc->dirname = strdup (dirname);
|
||||
desc->filename = strdup (filename);
|
||||
desc->dirname = strdup(dirname);
|
||||
desc->filename = strdup(filename);
|
||||
}
|
||||
|
||||
free (driver_name);
|
||||
free (dirname);
|
||||
free (filename);
|
||||
free(driver_name);
|
||||
free(dirname);
|
||||
free(filename);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
bool
|
||||
pn53x_usb_get_usb_device_name (struct usb_device *dev, usb_dev_handle *udev, char *buffer, size_t len)
|
||||
pn53x_usb_get_usb_device_name(struct usb_device *dev, usb_dev_handle *udev, char *buffer, size_t len)
|
||||
{
|
||||
*buffer = '\0';
|
||||
|
||||
if (dev->descriptor.iManufacturer || dev->descriptor.iProduct) {
|
||||
if (udev) {
|
||||
usb_get_string_simple (udev, dev->descriptor.iManufacturer, buffer, len);
|
||||
if (strlen (buffer) > 0)
|
||||
strcpy (buffer + strlen (buffer), " / ");
|
||||
usb_get_string_simple (udev, dev->descriptor.iProduct, buffer + strlen (buffer), len - strlen (buffer));
|
||||
usb_get_string_simple(udev, dev->descriptor.iManufacturer, buffer, len);
|
||||
if (strlen(buffer) > 0)
|
||||
strcpy(buffer + strlen(buffer), " / ");
|
||||
usb_get_string_simple(udev, dev->descriptor.iProduct, buffer + strlen(buffer), len - strlen(buffer));
|
||||
}
|
||||
}
|
||||
|
||||
if (!*buffer) {
|
||||
for (size_t n = 0; n < sizeof (pn53x_usb_supported_devices) / sizeof (struct pn53x_usb_supported_device); n++) {
|
||||
for (size_t n = 0; n < sizeof(pn53x_usb_supported_devices) / sizeof(struct pn53x_usb_supported_device); n++) {
|
||||
if ((pn53x_usb_supported_devices[n].vendor_id == dev->descriptor.idVendor) &&
|
||||
(pn53x_usb_supported_devices[n].product_id == dev->descriptor.idProduct)) {
|
||||
strncpy (buffer, pn53x_usb_supported_devices[n].name, len);
|
||||
strncpy(buffer, pn53x_usb_supported_devices[n].name, len);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -309,12 +309,12 @@ pn53x_usb_get_usb_device_name (struct usb_device *dev, usb_dev_handle *udev, cha
|
|||
}
|
||||
|
||||
nfc_device *
|
||||
pn53x_usb_open (const nfc_connstring connstring)
|
||||
pn53x_usb_open(const nfc_connstring connstring)
|
||||
{
|
||||
nfc_device *pnd = NULL;
|
||||
struct pn53x_usb_descriptor desc = { NULL, NULL };
|
||||
int connstring_decode_level = pn53x_usb_connstring_decode (connstring, &desc);
|
||||
log_put (LOG_CATEGORY, NFC_PRIORITY_TRACE, "%d element(s) have been decoded from \"%s\"", connstring_decode_level, connstring);
|
||||
int connstring_decode_level = pn53x_usb_connstring_decode(connstring, &desc);
|
||||
log_put(LOG_CATEGORY, NFC_PRIORITY_TRACE, "%d element(s) have been decoded from \"%s\"", connstring_decode_level, connstring);
|
||||
if (connstring_decode_level < 1) {
|
||||
goto free_mem;
|
||||
}
|
||||
|
|
@ -327,102 +327,102 @@ pn53x_usb_open (const nfc_connstring connstring)
|
|||
struct usb_bus *bus;
|
||||
struct usb_device *dev;
|
||||
|
||||
usb_init ();
|
||||
usb_init();
|
||||
|
||||
int res;
|
||||
// usb_find_busses will find all of the busses on the system. Returns the
|
||||
// number of changes since previous call to this function (total of new
|
||||
// busses and busses removed).
|
||||
if ((res = usb_find_busses () < 0)) {
|
||||
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "Unable to find USB busses (%s)", _usb_strerror (res));
|
||||
if ((res = usb_find_busses() < 0)) {
|
||||
log_put(LOG_CATEGORY, NFC_PRIORITY_ERROR, "Unable to find USB busses (%s)", _usb_strerror(res));
|
||||
goto free_mem;
|
||||
}
|
||||
// usb_find_devices will find all of the devices on each bus. This should be
|
||||
// called after usb_find_busses. Returns the number of changes since the
|
||||
// previous call to this function (total of new device and devices removed).
|
||||
if ((res = usb_find_devices () < 0)) {
|
||||
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "Unable to find USB devices (%s)", _usb_strerror (res));
|
||||
if ((res = usb_find_devices() < 0)) {
|
||||
log_put(LOG_CATEGORY, NFC_PRIORITY_ERROR, "Unable to find USB devices (%s)", _usb_strerror(res));
|
||||
goto free_mem;
|
||||
}
|
||||
|
||||
for (bus = usb_get_busses (); bus; bus = bus->next) {
|
||||
for (bus = usb_get_busses(); bus; bus = bus->next) {
|
||||
if (connstring_decode_level > 1) {
|
||||
// A specific bus have been specified
|
||||
if (0 != strcmp (bus->dirname, desc.dirname))
|
||||
if (0 != strcmp(bus->dirname, desc.dirname))
|
||||
continue;
|
||||
}
|
||||
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
|
||||
data.pudh = usb_open (dev);
|
||||
data.pudh = usb_open(dev);
|
||||
// Retrieve end points
|
||||
pn53x_usb_get_end_points (dev, &data);
|
||||
pn53x_usb_get_end_points(dev, &data);
|
||||
// Set configuration
|
||||
res = usb_set_configuration (data.pudh, 1);
|
||||
res = usb_set_configuration(data.pudh, 1);
|
||||
if (res < 0) {
|
||||
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "Unable to set USB configuration (%s)", _usb_strerror (res));
|
||||
log_put(LOG_CATEGORY, NFC_PRIORITY_ERROR, "Unable to set USB configuration (%s)", _usb_strerror(res));
|
||||
if (EPERM == -res) {
|
||||
log_put (LOG_CATEGORY, NFC_PRIORITY_WARN, "Please double check USB permissions for device %04x:%04x", dev->descriptor.idVendor, dev->descriptor.idProduct);
|
||||
log_put(LOG_CATEGORY, NFC_PRIORITY_WARN, "Please double check USB permissions for device %04x:%04x", dev->descriptor.idVendor, dev->descriptor.idProduct);
|
||||
}
|
||||
usb_close (data.pudh);
|
||||
usb_close(data.pudh);
|
||||
// we failed to use the specified device
|
||||
goto free_mem;
|
||||
}
|
||||
|
||||
res = usb_claim_interface (data.pudh, 0);
|
||||
res = usb_claim_interface(data.pudh, 0);
|
||||
if (res < 0) {
|
||||
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "Unable to claim USB interface (%s)", _usb_strerror (res));
|
||||
usb_close (data.pudh);
|
||||
log_put(LOG_CATEGORY, NFC_PRIORITY_ERROR, "Unable to claim USB interface (%s)", _usb_strerror(res));
|
||||
usb_close(data.pudh);
|
||||
// we failed to use the specified device
|
||||
goto free_mem;
|
||||
}
|
||||
data.model = pn53x_usb_get_device_model (dev->descriptor.idVendor, dev->descriptor.idProduct);
|
||||
data.model = pn53x_usb_get_device_model(dev->descriptor.idVendor, dev->descriptor.idProduct);
|
||||
// Allocate memory for the device info and specification, fill it and return the info
|
||||
pnd = nfc_device_new (connstring);
|
||||
pn53x_usb_get_usb_device_name (dev, data.pudh, pnd->name, sizeof (pnd->name));
|
||||
pnd = nfc_device_new(connstring);
|
||||
pn53x_usb_get_usb_device_name(dev, data.pudh, pnd->name, sizeof(pnd->name));
|
||||
|
||||
pnd->driver_data = malloc(sizeof(struct pn53x_usb_data));
|
||||
*DRIVER_DATA (pnd) = data;
|
||||
*DRIVER_DATA(pnd) = data;
|
||||
|
||||
// Alloc and init chip's data
|
||||
pn53x_data_new (pnd, &pn53x_usb_io);
|
||||
pn53x_data_new(pnd, &pn53x_usb_io);
|
||||
|
||||
switch (DRIVER_DATA (pnd)->model) {
|
||||
switch (DRIVER_DATA(pnd)->model) {
|
||||
// empirical tuning
|
||||
case ASK_LOGO:
|
||||
CHIP_DATA (pnd)->timer_correction = 50;
|
||||
CHIP_DATA(pnd)->timer_correction = 50;
|
||||
break;
|
||||
case SCM_SCL3711:
|
||||
case NXP_PN533:
|
||||
CHIP_DATA (pnd)->timer_correction = 46;
|
||||
CHIP_DATA(pnd)->timer_correction = 46;
|
||||
break;
|
||||
case NXP_PN531:
|
||||
CHIP_DATA (pnd)->timer_correction = 50;
|
||||
CHIP_DATA(pnd)->timer_correction = 50;
|
||||
break;
|
||||
case SONY_PN531:
|
||||
CHIP_DATA (pnd)->timer_correction = 54;
|
||||
CHIP_DATA(pnd)->timer_correction = 54;
|
||||
break;
|
||||
case SONY_RCS360:
|
||||
case UNKNOWN:
|
||||
CHIP_DATA (pnd)->timer_correction = 0; // TODO: allow user to know if timed functions are available
|
||||
CHIP_DATA(pnd)->timer_correction = 0; // TODO: allow user to know if timed functions are available
|
||||
break;
|
||||
}
|
||||
pnd->driver = &pn53x_usb_driver;
|
||||
|
||||
// HACK1: Send first an ACK as Abort command, to reset chip before talking to it:
|
||||
pn53x_usb_ack (pnd);
|
||||
pn53x_usb_ack(pnd);
|
||||
|
||||
// HACK2: Then send a GetFirmware command to resync USB toggle bit between host & device
|
||||
// in case host used set_configuration and expects the device to have reset its toggle bit, which PN53x doesn't do
|
||||
if (pn53x_usb_init (pnd) < 0) {
|
||||
usb_close (data.pudh);
|
||||
if (pn53x_usb_init(pnd) < 0) {
|
||||
usb_close(data.pudh);
|
||||
goto error;
|
||||
}
|
||||
DRIVER_DATA (pnd)->abort_flag = false;
|
||||
DRIVER_DATA(pnd)->abort_flag = false;
|
||||
goto free_mem;
|
||||
}
|
||||
}
|
||||
|
|
@ -431,64 +431,64 @@ pn53x_usb_open (const nfc_connstring connstring)
|
|||
|
||||
error:
|
||||
// Free allocated structure on error.
|
||||
nfc_device_free (pnd);
|
||||
nfc_device_free(pnd);
|
||||
pnd = NULL;
|
||||
free_mem:
|
||||
free (desc.dirname);
|
||||
free (desc.filename);
|
||||
free(desc.dirname);
|
||||
free(desc.filename);
|
||||
return pnd;
|
||||
}
|
||||
|
||||
void
|
||||
pn53x_usb_close (nfc_device *pnd)
|
||||
pn53x_usb_close(nfc_device *pnd)
|
||||
{
|
||||
pn53x_usb_ack (pnd);
|
||||
pn53x_usb_ack(pnd);
|
||||
|
||||
pn53x_idle (pnd);
|
||||
pn53x_idle(pnd);
|
||||
|
||||
if (DRIVER_DATA (pnd)->model == ASK_LOGO) {
|
||||
if (DRIVER_DATA(pnd)->model == ASK_LOGO) {
|
||||
/* Set P30, P31, P32, P33, P35 to logic 1 and P34 to 0 logic */
|
||||
/* ie. Switch all LEDs off and turn off progressive field */
|
||||
pn53x_write_register (pnd, PN53X_SFR_P3, 0xFF, _BV (P30) | _BV (P31) | _BV (P32) | _BV (P33) | _BV (P35));
|
||||
pn53x_write_register(pnd, PN53X_SFR_P3, 0xFF, _BV(P30) | _BV(P31) | _BV(P32) | _BV(P33) | _BV(P35));
|
||||
}
|
||||
|
||||
int res;
|
||||
if ((res = usb_release_interface (DRIVER_DATA (pnd)->pudh, 0)) < 0) {
|
||||
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "Unable to release USB interface (%s)", _usb_strerror (res));
|
||||
if ((res = usb_release_interface(DRIVER_DATA(pnd)->pudh, 0)) < 0) {
|
||||
log_put(LOG_CATEGORY, NFC_PRIORITY_ERROR, "Unable to release USB interface (%s)", _usb_strerror(res));
|
||||
}
|
||||
|
||||
if ((res = usb_close (DRIVER_DATA (pnd)->pudh)) < 0) {
|
||||
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "Unable to close USB connection (%s)", _usb_strerror (res));
|
||||
if ((res = usb_close(DRIVER_DATA(pnd)->pudh)) < 0) {
|
||||
log_put(LOG_CATEGORY, NFC_PRIORITY_ERROR, "Unable to close USB connection (%s)", _usb_strerror(res));
|
||||
}
|
||||
pn53x_data_free (pnd);
|
||||
nfc_device_free (pnd);
|
||||
pn53x_data_free(pnd);
|
||||
nfc_device_free(pnd);
|
||||
}
|
||||
|
||||
#define PN53X_USB_BUFFER_LEN (PN53x_EXTENDED_FRAME__DATA_MAX_LEN + PN53x_EXTENDED_FRAME__OVERHEAD)
|
||||
|
||||
int
|
||||
pn53x_usb_send (nfc_device *pnd, const uint8_t *pbtData, const size_t szData, const int timeout)
|
||||
pn53x_usb_send(nfc_device *pnd, const uint8_t *pbtData, const size_t szData, const int timeout)
|
||||
{
|
||||
uint8_t abtFrame[PN53X_USB_BUFFER_LEN] = { 0x00, 0x00, 0xff }; // Every packet must start with "00 00 ff"
|
||||
size_t szFrame = 0;
|
||||
int res = 0;
|
||||
|
||||
pn53x_build_frame (abtFrame, &szFrame, pbtData, szData);
|
||||
pn53x_build_frame(abtFrame, &szFrame, pbtData, szData);
|
||||
|
||||
if ((res = pn53x_usb_bulk_write (DRIVER_DATA (pnd), abtFrame, szFrame, timeout)) < 0) {
|
||||
if ((res = pn53x_usb_bulk_write(DRIVER_DATA(pnd), abtFrame, szFrame, timeout)) < 0) {
|
||||
pnd->last_error = res;
|
||||
return pnd->last_error;
|
||||
}
|
||||
|
||||
uint8_t abtRxBuf[PN53X_USB_BUFFER_LEN];
|
||||
if ((res = pn53x_usb_bulk_read (DRIVER_DATA (pnd), abtRxBuf, sizeof (abtRxBuf), timeout)) < 0) {
|
||||
if ((res = pn53x_usb_bulk_read(DRIVER_DATA(pnd), abtRxBuf, sizeof(abtRxBuf), timeout)) < 0) {
|
||||
// try to interrupt current device state
|
||||
pn53x_usb_ack(pnd);
|
||||
pnd->last_error = res;
|
||||
return pnd->last_error;
|
||||
}
|
||||
|
||||
if (pn53x_check_ack_frame (pnd, abtRxBuf, res) == 0) {
|
||||
if (pn53x_check_ack_frame(pnd, abtRxBuf, res) == 0) {
|
||||
// The PN53x is running the sent command
|
||||
} else {
|
||||
// For some reasons (eg. send another command while a previous one is
|
||||
|
|
@ -498,7 +498,7 @@ pn53x_usb_send (nfc_device *pnd, const uint8_t *pbtData, const size_t szData, co
|
|||
// pn53x_usb_receive()) will be able to retreive the correct response
|
||||
// packet.
|
||||
// FIXME Sony reader is also affected by this bug but NACK is not supported
|
||||
if ((res = pn53x_usb_bulk_write (DRIVER_DATA (pnd), (uint8_t *)pn53x_nack_frame, sizeof(pn53x_nack_frame), timeout)) < 0) {
|
||||
if ((res = pn53x_usb_bulk_write(DRIVER_DATA(pnd), (uint8_t *)pn53x_nack_frame, sizeof(pn53x_nack_frame), timeout)) < 0) {
|
||||
pnd->last_error = res;
|
||||
// try to interrupt current device state
|
||||
pn53x_usb_ack(pnd);
|
||||
|
|
@ -511,7 +511,7 @@ pn53x_usb_send (nfc_device *pnd, const uint8_t *pbtData, const size_t szData, co
|
|||
|
||||
#define USB_TIMEOUT_PER_PASS 200
|
||||
int
|
||||
pn53x_usb_receive (nfc_device *pnd, uint8_t *pbtData, const size_t szDataLen, const int timeout)
|
||||
pn53x_usb_receive(nfc_device *pnd, uint8_t *pbtData, const size_t szDataLen, const int timeout)
|
||||
{
|
||||
size_t len;
|
||||
off_t offset = 0;
|
||||
|
|
@ -539,12 +539,12 @@ read:
|
|||
}
|
||||
}
|
||||
|
||||
res = pn53x_usb_bulk_read (DRIVER_DATA (pnd), abtRxBuf, sizeof (abtRxBuf), usb_timeout);
|
||||
res = pn53x_usb_bulk_read(DRIVER_DATA(pnd), abtRxBuf, sizeof(abtRxBuf), usb_timeout);
|
||||
|
||||
if (res == -USB_TIMEDOUT) {
|
||||
if (DRIVER_DATA (pnd)->abort_flag) {
|
||||
DRIVER_DATA (pnd)->abort_flag = false;
|
||||
pn53x_usb_ack (pnd);
|
||||
if (DRIVER_DATA(pnd)->abort_flag) {
|
||||
DRIVER_DATA(pnd)->abort_flag = false;
|
||||
pn53x_usb_ack(pnd);
|
||||
pnd->last_error = NFC_EOPABORTED;
|
||||
return pnd->last_error;
|
||||
} else {
|
||||
|
|
@ -560,8 +560,8 @@ read:
|
|||
}
|
||||
|
||||
const uint8_t pn53x_preamble[3] = { 0x00, 0x00, 0xff };
|
||||
if (0 != (memcmp (abtRxBuf, pn53x_preamble, 3))) {
|
||||
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Frame preamble+start code mismatch");
|
||||
if (0 != (memcmp(abtRxBuf, pn53x_preamble, 3))) {
|
||||
log_put(LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Frame preamble+start code mismatch");
|
||||
pnd->last_error = NFC_EIO;
|
||||
return pnd->last_error;
|
||||
}
|
||||
|
|
@ -569,7 +569,7 @@ read:
|
|||
|
||||
if ((0x01 == abtRxBuf[offset]) && (0xff == abtRxBuf[offset + 1])) {
|
||||
// Error frame
|
||||
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Application level error detected");
|
||||
log_put(LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Application level error detected");
|
||||
pnd->last_error = NFC_EIO;
|
||||
return pnd->last_error;
|
||||
} else if ((0xff == abtRxBuf[offset]) && (0xff == abtRxBuf[offset + 1])) {
|
||||
|
|
@ -580,7 +580,7 @@ read:
|
|||
len = (abtRxBuf[offset] << 8) + abtRxBuf[offset + 1] - 2;
|
||||
if (((abtRxBuf[offset] + abtRxBuf[offset + 1] + abtRxBuf[offset + 2]) % 256) != 0) {
|
||||
// TODO: Retry
|
||||
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Length checksum mismatch");
|
||||
log_put(LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Length checksum mismatch");
|
||||
pnd->last_error = NFC_EIO;
|
||||
return pnd->last_error;
|
||||
}
|
||||
|
|
@ -589,7 +589,7 @@ read:
|
|||
// Normal frame
|
||||
if (256 != (abtRxBuf[offset] + abtRxBuf[offset + 1])) {
|
||||
// TODO: Retry
|
||||
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Length checksum mismatch");
|
||||
log_put(LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Length checksum mismatch");
|
||||
pnd->last_error = NFC_EIO;
|
||||
return pnd->last_error;
|
||||
}
|
||||
|
|
@ -600,44 +600,44 @@ read:
|
|||
}
|
||||
|
||||
if (len > szDataLen) {
|
||||
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "Unable to receive data: buffer too small. (szDataLen: %zu, len: %zu)", szDataLen, len);
|
||||
log_put(LOG_CATEGORY, NFC_PRIORITY_ERROR, "Unable to receive data: buffer too small. (szDataLen: %zu, len: %zu)", szDataLen, len);
|
||||
pnd->last_error = NFC_EIO;
|
||||
return pnd->last_error;
|
||||
}
|
||||
|
||||
// TFI + PD0 (CC+1)
|
||||
if (abtRxBuf[offset] != 0xD5) {
|
||||
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "TFI Mismatch");
|
||||
log_put(LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "TFI Mismatch");
|
||||
pnd->last_error = NFC_EIO;
|
||||
return pnd->last_error;
|
||||
}
|
||||
offset += 1;
|
||||
|
||||
if (abtRxBuf[offset] != CHIP_DATA (pnd)->last_command + 1) {
|
||||
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Command Code verification failed");
|
||||
if (abtRxBuf[offset] != CHIP_DATA(pnd)->last_command + 1) {
|
||||
log_put(LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Command Code verification failed");
|
||||
pnd->last_error = NFC_EIO;
|
||||
return pnd->last_error;
|
||||
}
|
||||
offset += 1;
|
||||
|
||||
memcpy (pbtData, abtRxBuf + offset, len);
|
||||
memcpy(pbtData, abtRxBuf + offset, len);
|
||||
offset += len;
|
||||
|
||||
uint8_t btDCS = (256 - 0xD5);
|
||||
btDCS -= CHIP_DATA (pnd)->last_command + 1;
|
||||
btDCS -= CHIP_DATA(pnd)->last_command + 1;
|
||||
for (size_t szPos = 0; szPos < len; szPos++) {
|
||||
btDCS -= pbtData[szPos];
|
||||
}
|
||||
|
||||
if (btDCS != abtRxBuf[offset]) {
|
||||
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Data checksum mismatch");
|
||||
log_put(LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Data checksum mismatch");
|
||||
pnd->last_error = NFC_EIO;
|
||||
return pnd->last_error;
|
||||
}
|
||||
offset += 1;
|
||||
|
||||
if (0x00 != abtRxBuf[offset]) {
|
||||
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Frame postamble mismatch");
|
||||
log_put(LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Frame postamble mismatch");
|
||||
pnd->last_error = NFC_EIO;
|
||||
return pnd->last_error;
|
||||
}
|
||||
|
|
@ -647,42 +647,42 @@ read:
|
|||
}
|
||||
|
||||
int
|
||||
pn53x_usb_ack (nfc_device *pnd)
|
||||
pn53x_usb_ack(nfc_device *pnd)
|
||||
{
|
||||
return pn53x_usb_bulk_write (DRIVER_DATA (pnd), (uint8_t *) pn53x_ack_frame, sizeof (pn53x_ack_frame), 0);
|
||||
return pn53x_usb_bulk_write(DRIVER_DATA(pnd), (uint8_t *) pn53x_ack_frame, sizeof(pn53x_ack_frame), 0);
|
||||
}
|
||||
|
||||
int
|
||||
pn53x_usb_init (nfc_device *pnd)
|
||||
pn53x_usb_init(nfc_device *pnd)
|
||||
{
|
||||
int res = 0;
|
||||
// Sometimes PN53x USB doesn't reply ACK one the first frame, so we need to send a dummy one...
|
||||
//pn53x_check_communication (pnd); // Sony RC-S360 doesn't support this command for now so let's use a get_firmware_version instead:
|
||||
const uint8_t abtCmd[] = { GetFirmwareVersion };
|
||||
pn53x_transceive (pnd, abtCmd, sizeof (abtCmd), NULL, 0, 0);
|
||||
pn53x_transceive(pnd, abtCmd, sizeof(abtCmd), NULL, 0, 0);
|
||||
// ...and we don't care about error
|
||||
pnd->last_error = 0;
|
||||
if (SONY_RCS360 == DRIVER_DATA (pnd)->model) {
|
||||
log_put (LOG_CATEGORY, NFC_PRIORITY_TRACE, "%s", "SONY RC-S360 initialization.");
|
||||
if (SONY_RCS360 == DRIVER_DATA(pnd)->model) {
|
||||
log_put(LOG_CATEGORY, NFC_PRIORITY_TRACE, "%s", "SONY RC-S360 initialization.");
|
||||
const uint8_t abtCmd2[] = { 0x18, 0x01 };
|
||||
pn53x_transceive (pnd, abtCmd2, sizeof (abtCmd2), NULL, 0, 0);
|
||||
pn53x_usb_ack (pnd);
|
||||
pn53x_transceive(pnd, abtCmd2, sizeof(abtCmd2), NULL, 0, 0);
|
||||
pn53x_usb_ack(pnd);
|
||||
}
|
||||
|
||||
if ((res = pn53x_init (pnd)) < 0)
|
||||
if ((res = pn53x_init(pnd)) < 0)
|
||||
return res;
|
||||
|
||||
if (ASK_LOGO == DRIVER_DATA (pnd)->model) {
|
||||
log_put (LOG_CATEGORY, NFC_PRIORITY_TRACE, "%s", "ASK LoGO initialization.");
|
||||
if (ASK_LOGO == DRIVER_DATA(pnd)->model) {
|
||||
log_put(LOG_CATEGORY, NFC_PRIORITY_TRACE, "%s", "ASK LoGO initialization.");
|
||||
/* Internal registers */
|
||||
/* Disable 100mA current limit, Power on Secure IC (SVDD) */
|
||||
pn53x_write_register (pnd, PN53X_REG_Control_switch_rng, 0xFF, SYMBOL_CURLIMOFF | SYMBOL_SIC_SWITCH_EN | SYMBOL_RANDOM_DATAREADY);
|
||||
pn53x_write_register(pnd, PN53X_REG_Control_switch_rng, 0xFF, SYMBOL_CURLIMOFF | SYMBOL_SIC_SWITCH_EN | SYMBOL_RANDOM_DATAREADY);
|
||||
/* Select the signal to be output on SIGOUT: Modulation signal (envelope) from the internal coder */
|
||||
pn53x_write_register (pnd, PN53X_REG_CIU_TxSel, 0xFF, 0x14);
|
||||
pn53x_write_register(pnd, PN53X_REG_CIU_TxSel, 0xFF, 0x14);
|
||||
|
||||
/* SFR Registers */
|
||||
/* Setup push-pulls for pins from P30 to P35 */
|
||||
pn53x_write_register (pnd, PN53X_SFR_P3CFGB, 0xFF, 0x37);
|
||||
pn53x_write_register(pnd, PN53X_SFR_P3CFGB, 0xFF, 0x37);
|
||||
|
||||
/*
|
||||
On ASK LoGO hardware:
|
||||
|
|
@ -704,32 +704,32 @@ pn53x_usb_init (nfc_device *pnd)
|
|||
|
||||
/* Set P30, P31, P33, P35 to logic 1 and P32, P34 to 0 logic */
|
||||
/* ie. Switch LED1 on and turn off progressive field */
|
||||
pn53x_write_register (pnd, PN53X_SFR_P3, 0xFF, _BV (P30) | _BV (P31) | _BV (P33) | _BV (P35));
|
||||
pn53x_write_register(pnd, PN53X_SFR_P3, 0xFF, _BV(P30) | _BV(P31) | _BV(P33) | _BV(P35));
|
||||
}
|
||||
|
||||
return NFC_SUCCESS;
|
||||
}
|
||||
|
||||
static int
|
||||
pn53x_usb_set_property_bool (nfc_device *pnd, const nfc_property property, const bool bEnable)
|
||||
pn53x_usb_set_property_bool(nfc_device *pnd, const nfc_property property, const bool bEnable)
|
||||
{
|
||||
int res = 0;
|
||||
if ((res = pn53x_set_property_bool (pnd, property, bEnable)) < 0)
|
||||
if ((res = pn53x_set_property_bool(pnd, property, bEnable)) < 0)
|
||||
return res;
|
||||
|
||||
switch (DRIVER_DATA (pnd)->model) {
|
||||
switch (DRIVER_DATA(pnd)->model) {
|
||||
case ASK_LOGO:
|
||||
if (NP_ACTIVATE_FIELD == property) {
|
||||
/* Switch on/off LED2 and Progressive Field GPIO according to ACTIVATE_FIELD option */
|
||||
log_put (LOG_CATEGORY, NFC_PRIORITY_TRACE, "Switch progressive field %s", bEnable ? "On" : "Off");
|
||||
if ((res = pn53x_write_register (pnd, PN53X_SFR_P3, _BV(P31) | _BV(P34), bEnable ? _BV (P34) : _BV (P31))) < 0)
|
||||
log_put(LOG_CATEGORY, NFC_PRIORITY_TRACE, "Switch progressive field %s", bEnable ? "On" : "Off");
|
||||
if ((res = pn53x_write_register(pnd, PN53X_SFR_P3, _BV(P31) | _BV(P34), bEnable ? _BV(P34) : _BV(P31))) < 0)
|
||||
return NFC_ECHIP;
|
||||
}
|
||||
break;
|
||||
case SCM_SCL3711:
|
||||
if (NP_ACTIVATE_FIELD == property) {
|
||||
// Switch on/off LED according to ACTIVATE_FIELD option
|
||||
if ((res = pn53x_write_register (pnd, PN53X_SFR_P3, _BV (P32), bEnable ? 0 : _BV (P32))) < 0)
|
||||
if ((res = pn53x_write_register(pnd, PN53X_SFR_P3, _BV(P32), bEnable ? 0 : _BV(P32))) < 0)
|
||||
return res;
|
||||
}
|
||||
break;
|
||||
|
|
@ -745,9 +745,9 @@ pn53x_usb_set_property_bool (nfc_device *pnd, const nfc_property property, const
|
|||
}
|
||||
|
||||
static int
|
||||
pn53x_usb_abort_command (nfc_device *pnd)
|
||||
pn53x_usb_abort_command(nfc_device *pnd)
|
||||
{
|
||||
DRIVER_DATA (pnd)->abort_flag = true;
|
||||
DRIVER_DATA(pnd)->abort_flag = true;
|
||||
return NFC_SUCCESS;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -31,11 +31,11 @@
|
|||
|
||||
#include "nfc-internal.h"
|
||||
|
||||
bool pn53x_usb_probe (nfc_connstring connstrings[], size_t connstrings_len, size_t *pszDeviceFound);
|
||||
nfc_device *pn53x_usb_open (const nfc_connstring connstring);
|
||||
int pn53x_usb_send (nfc_device *pnd, const uint8_t *pbtData, const size_t szData, int timeout);
|
||||
int pn53x_usb_receive (nfc_device *pnd, uint8_t *pbtData, const size_t szData, int timeout);
|
||||
void pn53x_usb_close (nfc_device *pnd);
|
||||
bool pn53x_usb_probe(nfc_connstring connstrings[], size_t connstrings_len, size_t *pszDeviceFound);
|
||||
nfc_device *pn53x_usb_open(const nfc_connstring connstring);
|
||||
int pn53x_usb_send(nfc_device *pnd, const uint8_t *pbtData, const size_t szData, int timeout);
|
||||
int pn53x_usb_receive(nfc_device *pnd, uint8_t *pbtData, const size_t szData, int timeout);
|
||||
void pn53x_usb_close(nfc_device *pnd);
|
||||
|
||||
extern const struct nfc_driver pn53x_usb_driver;
|
||||
|
||||
|
|
|
|||
|
|
@ -38,20 +38,20 @@
|
|||
*
|
||||
*/
|
||||
void
|
||||
iso14443a_crc (uint8_t *pbtData, size_t szLen, uint8_t *pbtCrc)
|
||||
iso14443a_crc(uint8_t *pbtData, size_t szLen, uint8_t *pbtCrc)
|
||||
{
|
||||
uint8_t bt;
|
||||
uint32_t wCrc = 0x6363;
|
||||
|
||||
do {
|
||||
bt = *pbtData++;
|
||||
bt = (bt ^ (uint8_t) (wCrc & 0x00FF));
|
||||
bt = (bt ^ (bt << 4));
|
||||
wCrc = (wCrc >> 8) ^ ((uint32_t) bt << 8) ^ ((uint32_t) bt << 3) ^ ((uint32_t) bt >> 4);
|
||||
bt = (bt ^(uint8_t)(wCrc & 0x00FF));
|
||||
bt = (bt ^(bt << 4));
|
||||
wCrc = (wCrc >> 8) ^((uint32_t) bt << 8) ^((uint32_t) bt << 3) ^((uint32_t) bt >> 4);
|
||||
} while (--szLen);
|
||||
|
||||
*pbtCrc++ = (uint8_t) (wCrc & 0xFF);
|
||||
*pbtCrc = (uint8_t) ((wCrc >> 8) & 0xFF);
|
||||
*pbtCrc++ = (uint8_t)(wCrc & 0xFF);
|
||||
*pbtCrc = (uint8_t)((wCrc >> 8) & 0xFF);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -59,9 +59,9 @@ iso14443a_crc (uint8_t *pbtData, size_t szLen, uint8_t *pbtCrc)
|
|||
*
|
||||
*/
|
||||
void
|
||||
iso14443a_crc_append (uint8_t *pbtData, size_t szLen)
|
||||
iso14443a_crc_append(uint8_t *pbtData, size_t szLen)
|
||||
{
|
||||
iso14443a_crc (pbtData, szLen, pbtData + szLen);
|
||||
iso14443a_crc(pbtData, szLen, pbtData + szLen);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -69,7 +69,7 @@ iso14443a_crc_append (uint8_t *pbtData, size_t szLen)
|
|||
* @see ISO/IEC 14443-4 (5.2.7 Historical bytes)
|
||||
*/
|
||||
uint8_t *
|
||||
iso14443a_locate_historical_bytes (uint8_t *pbtAts, size_t szAts, size_t *pszTk)
|
||||
iso14443a_locate_historical_bytes(uint8_t *pbtAts, size_t szAts, size_t *pszTk)
|
||||
{
|
||||
if (szAts) {
|
||||
size_t offset = 1;
|
||||
|
|
@ -96,26 +96,26 @@ iso14443a_locate_historical_bytes (uint8_t *pbtAts, size_t szAts, size_t *pszTk)
|
|||
* @see ISO/IEC 14443-3 (6.4.4 UID contents and cascade levels)
|
||||
*/
|
||||
void
|
||||
iso14443_cascade_uid (const uint8_t abtUID[], const size_t szUID, uint8_t *pbtCascadedUID, size_t *pszCascadedUID)
|
||||
iso14443_cascade_uid(const uint8_t abtUID[], const size_t szUID, uint8_t *pbtCascadedUID, size_t *pszCascadedUID)
|
||||
{
|
||||
switch (szUID) {
|
||||
case 7:
|
||||
pbtCascadedUID[0] = 0x88;
|
||||
memcpy (pbtCascadedUID + 1, abtUID, 7);
|
||||
memcpy(pbtCascadedUID + 1, abtUID, 7);
|
||||
*pszCascadedUID = 8;
|
||||
break;
|
||||
|
||||
case 10:
|
||||
pbtCascadedUID[0] = 0x88;
|
||||
memcpy (pbtCascadedUID + 1, abtUID, 3);
|
||||
memcpy(pbtCascadedUID + 1, abtUID, 3);
|
||||
pbtCascadedUID[4] = 0x88;
|
||||
memcpy (pbtCascadedUID + 5, abtUID + 3, 7);
|
||||
memcpy(pbtCascadedUID + 5, abtUID + 3, 7);
|
||||
*pszCascadedUID = 12;
|
||||
break;
|
||||
|
||||
case 4:
|
||||
default:
|
||||
memcpy (pbtCascadedUID, abtUID, szUID);
|
||||
memcpy(pbtCascadedUID, abtUID, szUID);
|
||||
*pszCascadedUID = szUID;
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@
|
|||
static uint8_t __log_init_counter = 0;
|
||||
|
||||
int
|
||||
log_init (void)
|
||||
log_init(void)
|
||||
{
|
||||
int res = 0;
|
||||
|
||||
|
|
@ -41,7 +41,7 @@ log_init (void)
|
|||
}
|
||||
|
||||
int
|
||||
log_fini (void)
|
||||
log_fini(void)
|
||||
{
|
||||
int res = 0;
|
||||
if (__log_init_counter >= 1) {
|
||||
|
|
@ -56,12 +56,12 @@ log_fini (void)
|
|||
}
|
||||
|
||||
void
|
||||
log_put (const char *category, const char *priority, const char *format, ...)
|
||||
log_put(const char *category, const char *priority, const char *format, ...)
|
||||
{
|
||||
va_list va;
|
||||
va_start (va, format);
|
||||
fprintf (stderr, "%s\t%s\t", priority, category);
|
||||
vfprintf (stderr, format, va);
|
||||
fprintf (stderr, "\n");
|
||||
va_end (va);
|
||||
va_start(va, format);
|
||||
fprintf(stderr, "%s\t%s\t", priority, category);
|
||||
vfprintf(stderr, format, va);
|
||||
fprintf(stderr, "\n");
|
||||
va_end(va);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,9 +34,9 @@
|
|||
|
||||
// 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, ...)
|
||||
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)))
|
||||
# endif
|
||||
|
|
|
|||
|
|
@ -54,13 +54,13 @@ static const uint8_t ByteMirror[256] = {
|
|||
};
|
||||
|
||||
uint8_t
|
||||
mirror (uint8_t bt)
|
||||
mirror(uint8_t bt)
|
||||
{
|
||||
return ByteMirror[bt];
|
||||
}
|
||||
|
||||
static void
|
||||
mirror_bytes (uint8_t *pbts, size_t szLen)
|
||||
mirror_bytes(uint8_t *pbts, size_t szLen)
|
||||
{
|
||||
size_t szByteNr;
|
||||
|
||||
|
|
@ -71,15 +71,15 @@ mirror_bytes (uint8_t *pbts, size_t szLen)
|
|||
}
|
||||
|
||||
uint32_t
|
||||
mirror32 (uint32_t ui32Bits)
|
||||
mirror32(uint32_t ui32Bits)
|
||||
{
|
||||
mirror_bytes ((uint8_t *) & ui32Bits, 4);
|
||||
mirror_bytes((uint8_t *) & ui32Bits, 4);
|
||||
return ui32Bits;
|
||||
}
|
||||
|
||||
uint64_t
|
||||
mirror64 (uint64_t ui64Bits)
|
||||
mirror64(uint64_t ui64Bits)
|
||||
{
|
||||
mirror_bytes ((uint8_t *) & ui64Bits, 8);
|
||||
mirror_bytes((uint8_t *) & ui64Bits, 8);
|
||||
return ui64Bits;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,9 +29,9 @@
|
|||
# include <nfc/nfc-types.h>
|
||||
|
||||
|
||||
uint8_t mirror (uint8_t bt);
|
||||
uint32_t mirror32 (uint32_t ui32Bits);
|
||||
uint64_t mirror64 (uint64_t ui64Bits);
|
||||
void mirror_uint8_ts (uint8_t *pbts, size_t szLen);
|
||||
uint8_t mirror(uint8_t bt);
|
||||
uint32_t mirror32(uint32_t ui32Bits);
|
||||
uint64_t mirror64(uint64_t ui64Bits);
|
||||
void mirror_uint8_ts(uint8_t *pbts, size_t szLen);
|
||||
|
||||
#endif // _LIBNFC_MIRROR_SUBR_H_
|
||||
|
|
|
|||
|
|
@ -34,12 +34,12 @@
|
|||
#include "nfc-internal.h"
|
||||
|
||||
nfc_device *
|
||||
nfc_device_new (const nfc_connstring connstring)
|
||||
nfc_device_new(const nfc_connstring connstring)
|
||||
{
|
||||
nfc_device *res = malloc (sizeof (*res));
|
||||
nfc_device *res = malloc(sizeof(*res));
|
||||
|
||||
if (!res) {
|
||||
err (EXIT_FAILURE, "nfc_device_new: malloc");
|
||||
err(EXIT_FAILURE, "nfc_device_new: malloc");
|
||||
}
|
||||
|
||||
// Variables initiatialization
|
||||
|
|
@ -51,7 +51,7 @@ nfc_device_new (const nfc_connstring connstring)
|
|||
res->bEasyFraming = false;
|
||||
res->bAutoIso14443_4 = false;
|
||||
res->last_error = 0;
|
||||
memcpy (res->connstring, connstring, sizeof (res->connstring));
|
||||
memcpy(res->connstring, connstring, sizeof(res->connstring));
|
||||
res->driver_data = NULL;
|
||||
res->chip_data = NULL;
|
||||
|
||||
|
|
@ -59,10 +59,10 @@ nfc_device_new (const nfc_connstring connstring)
|
|||
}
|
||||
|
||||
void
|
||||
nfc_device_free (nfc_device *dev)
|
||||
nfc_device_free(nfc_device *dev)
|
||||
{
|
||||
if (dev) {
|
||||
free (dev->driver_data);
|
||||
free (dev);
|
||||
free(dev->driver_data);
|
||||
free(dev);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,20 +28,20 @@
|
|||
#include "iso7816.h"
|
||||
|
||||
int
|
||||
nfc_emulate_target (nfc_device *pnd, struct nfc_emulator *emulator)
|
||||
nfc_emulate_target(nfc_device *pnd, struct nfc_emulator *emulator)
|
||||
{
|
||||
uint8_t abtRx[ISO7816_SHORT_R_APDU_MAX_LEN];
|
||||
uint8_t abtTx[ISO7816_SHORT_C_APDU_MAX_LEN];
|
||||
|
||||
int res;
|
||||
if ((res = nfc_target_init (pnd, emulator->target, abtRx, sizeof(abtRx), 0)) < 0) {
|
||||
if ((res = nfc_target_init(pnd, emulator->target, abtRx, sizeof(abtRx), 0)) < 0) {
|
||||
return res;
|
||||
}
|
||||
|
||||
size_t szRx = res;
|
||||
int io_res = res;
|
||||
while (io_res >= 0) {
|
||||
io_res = emulator->state_machine->io (emulator, abtRx, szRx, abtTx, sizeof (abtTx));
|
||||
io_res = emulator->state_machine->io(emulator, abtRx, szRx, abtTx, sizeof(abtTx));
|
||||
if (io_res > 0) {
|
||||
if ((res = nfc_target_send_bytes(pnd, abtTx, io_res, 0)) < 0) {
|
||||
return res;
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@
|
|||
#include "nfc-internal.h"
|
||||
|
||||
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) {
|
||||
case NMT_ISO14443B: {
|
||||
|
|
|
|||
|
|
@ -136,35 +136,35 @@
|
|||
struct nfc_driver {
|
||||
const char *name;
|
||||
bool (*probe)(nfc_connstring connstrings[], size_t connstrings_len, size_t * pszDeviceFound);
|
||||
struct nfc_device *(*open) (const nfc_connstring connstring);
|
||||
void (*close) (struct nfc_device *pnd);
|
||||
const char *(*strerror) (const struct nfc_device *pnd);
|
||||
struct nfc_device *(*open)(const nfc_connstring connstring);
|
||||
void (*close)(struct nfc_device *pnd);
|
||||
const char *(*strerror)(const 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_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_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_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_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_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_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_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_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_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 (*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_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_receive_bits) (struct nfc_device *pnd, uint8_t * pbtRx, const size_t szRxLen, uint8_t * pbtRxPar);
|
||||
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_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_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_int) (struct nfc_device *pnd, const nfc_property property, const int value);
|
||||
int (*get_supported_modulation) (struct nfc_device *pnd, const nfc_mode mode, const nfc_modulation_type **const supported_mt);
|
||||
int (*get_supported_baud_rate) (struct nfc_device *pnd, const nfc_modulation_type nmt, const nfc_baud_rate **const supported_br);
|
||||
int (*device_get_information_about) (struct nfc_device *pnd, char *buf, size_t buflen);
|
||||
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 (*get_supported_modulation)(struct nfc_device *pnd, const nfc_mode mode, const nfc_modulation_type **const supported_mt);
|
||||
int (*get_supported_baud_rate)(struct nfc_device *pnd, const nfc_modulation_type nmt, const nfc_baud_rate **const supported_br);
|
||||
int (*device_get_information_about)(struct nfc_device *pnd, char *buf, size_t buflen);
|
||||
|
||||
int (*abort_command) (struct nfc_device *pnd);
|
||||
int (*idle) (struct nfc_device *pnd);
|
||||
int (*abort_command)(struct nfc_device *pnd);
|
||||
int (*idle)(struct nfc_device *pnd);
|
||||
};
|
||||
|
||||
# define DEVICE_NAME_LENGTH 256
|
||||
|
|
@ -198,11 +198,11 @@ struct nfc_device {
|
|||
int last_error;
|
||||
};
|
||||
|
||||
nfc_device *nfc_device_new (const nfc_connstring connstring);
|
||||
void nfc_device_free (nfc_device *dev);
|
||||
nfc_device *nfc_device_new(const nfc_connstring connstring);
|
||||
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__
|
||||
|
|
|
|||
266
libnfc/nfc.c
266
libnfc/nfc.c
|
|
@ -111,7 +111,7 @@ void
|
|||
nfc_init(nfc_context *context)
|
||||
{
|
||||
(void) context;
|
||||
log_init ();
|
||||
log_init();
|
||||
}
|
||||
|
||||
/** @ingroup lib
|
||||
|
|
@ -123,7 +123,7 @@ void
|
|||
nfc_exit(nfc_context *context)
|
||||
{
|
||||
(void) context;
|
||||
log_fini ();
|
||||
log_fini();
|
||||
}
|
||||
|
||||
/** @ingroup dev
|
||||
|
|
@ -141,20 +141,20 @@ nfc_exit(nfc_context *context)
|
|||
* set with incorrect value.
|
||||
*/
|
||||
bool
|
||||
nfc_get_default_device (nfc_connstring *connstring)
|
||||
nfc_get_default_device(nfc_connstring *connstring)
|
||||
{
|
||||
char *env_default_connstring = getenv ("LIBNFC_DEFAULT_DEVICE");
|
||||
char *env_default_connstring = getenv("LIBNFC_DEFAULT_DEVICE");
|
||||
if (NULL == env_default_connstring) {
|
||||
// LIBNFC_DEFAULT_DEVICE is not set, we fallback on probing for the first available device
|
||||
nfc_connstring listed_cs[1];
|
||||
size_t szDeviceFound = nfc_list_devices (NULL, listed_cs, 1);
|
||||
size_t szDeviceFound = nfc_list_devices(NULL, listed_cs, 1);
|
||||
if (szDeviceFound) {
|
||||
strncpy (*connstring, listed_cs[0], sizeof(nfc_connstring));
|
||||
strncpy(*connstring, listed_cs[0], sizeof(nfc_connstring));
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
strncpy (*connstring, env_default_connstring, sizeof(nfc_connstring));
|
||||
strncpy(*connstring, env_default_connstring, sizeof(nfc_connstring));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
@ -177,19 +177,19 @@ nfc_get_default_device (nfc_connstring *connstring)
|
|||
* optionally followed by manual tuning of the parameters if the default parameters are not suiting your goals.
|
||||
*/
|
||||
nfc_device *
|
||||
nfc_open (nfc_context *context, const nfc_connstring connstring)
|
||||
nfc_open(nfc_context *context, const nfc_connstring connstring)
|
||||
{
|
||||
(void) context;
|
||||
nfc_device *pnd = NULL;
|
||||
|
||||
nfc_connstring ncs;
|
||||
if (connstring == NULL) {
|
||||
if (!nfc_get_default_device (&ncs)) {
|
||||
log_fini ();
|
||||
if (!nfc_get_default_device(&ncs)) {
|
||||
log_fini();
|
||||
return NULL;
|
||||
}
|
||||
} else {
|
||||
strncpy (ncs, connstring, sizeof (nfc_connstring));
|
||||
strncpy(ncs, connstring, sizeof(nfc_connstring));
|
||||
}
|
||||
|
||||
// Search through the device list for an available device
|
||||
|
|
@ -197,27 +197,27 @@ nfc_open (nfc_context *context, const nfc_connstring connstring)
|
|||
const struct nfc_driver **pndr = nfc_drivers;
|
||||
while ((ndr = *pndr)) {
|
||||
// Specific device is requested: using device description
|
||||
if (0 != strncmp (ndr->name, ncs, strlen(ndr->name))) {
|
||||
if (0 != strncmp(ndr->name, ncs, strlen(ndr->name))) {
|
||||
pndr++;
|
||||
continue;
|
||||
}
|
||||
|
||||
pnd = ndr->open (ncs);
|
||||
pnd = ndr->open(ncs);
|
||||
// Test if the opening was successful
|
||||
if (pnd == NULL) {
|
||||
log_put (LOG_CATEGORY, NFC_PRIORITY_TRACE, "Unable to open \"%s\".", ncs);
|
||||
log_fini ();
|
||||
log_put(LOG_CATEGORY, NFC_PRIORITY_TRACE, "Unable to open \"%s\".", ncs);
|
||||
log_fini();
|
||||
return pnd;
|
||||
}
|
||||
|
||||
log_put (LOG_CATEGORY, NFC_PRIORITY_TRACE, "\"%s\" (%s) has been claimed.", pnd->name, pnd->connstring);
|
||||
log_fini ();
|
||||
log_put(LOG_CATEGORY, NFC_PRIORITY_TRACE, "\"%s\" (%s) has been claimed.", pnd->name, pnd->connstring);
|
||||
log_fini();
|
||||
return pnd;
|
||||
}
|
||||
|
||||
// Too bad, no driver can decode connstring
|
||||
log_put (LOG_CATEGORY, NFC_PRIORITY_TRACE, "No driver available to handle \"%s\".", ncs);
|
||||
log_fini ();
|
||||
log_put(LOG_CATEGORY, NFC_PRIORITY_TRACE, "No driver available to handle \"%s\".", ncs);
|
||||
log_fini();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
@ -228,13 +228,13 @@ nfc_open (nfc_context *context, const nfc_connstring connstring)
|
|||
* Initiator's selected tag is closed and the device, including allocated \a nfc_device struct, is released.
|
||||
*/
|
||||
void
|
||||
nfc_close (nfc_device *pnd)
|
||||
nfc_close(nfc_device *pnd)
|
||||
{
|
||||
if (pnd) {
|
||||
// Go in idle mode
|
||||
nfc_idle (pnd);
|
||||
nfc_idle(pnd);
|
||||
// Close, clean up and release the device
|
||||
pnd->driver->close (pnd);
|
||||
pnd->driver->close(pnd);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -248,7 +248,7 @@ nfc_close (nfc_device *pnd)
|
|||
*
|
||||
*/
|
||||
size_t
|
||||
nfc_list_devices (nfc_context *context, nfc_connstring connstrings[] , size_t szDevices)
|
||||
nfc_list_devices(nfc_context *context, nfc_connstring connstrings[] , size_t szDevices)
|
||||
{
|
||||
size_t szN;
|
||||
size_t szDeviceFound = 0;
|
||||
|
|
@ -259,15 +259,15 @@ nfc_list_devices (nfc_context *context, nfc_connstring connstrings[] , size_t sz
|
|||
|
||||
while ((ndr = *pndr)) {
|
||||
szN = 0;
|
||||
if (ndr->probe (connstrings + (szDeviceFound), szDevices - (szDeviceFound), &szN)) {
|
||||
if (ndr->probe(connstrings + (szDeviceFound), szDevices - (szDeviceFound), &szN)) {
|
||||
szDeviceFound += szN;
|
||||
log_put (LOG_CATEGORY, NFC_PRIORITY_TRACE, "%ld device(s) found using %s driver", (unsigned long) szN, ndr->name);
|
||||
log_put(LOG_CATEGORY, NFC_PRIORITY_TRACE, "%ld device(s) found using %s driver", (unsigned long) szN, ndr->name);
|
||||
if (szDeviceFound == szDevices)
|
||||
break;
|
||||
}
|
||||
pndr++;
|
||||
}
|
||||
log_fini ();
|
||||
log_fini();
|
||||
return szDeviceFound;
|
||||
}
|
||||
|
||||
|
|
@ -283,9 +283,9 @@ nfc_list_devices (nfc_context *context, nfc_connstring connstrings[] , size_t sz
|
|||
* @see nfc_property enum values
|
||||
*/
|
||||
int
|
||||
nfc_device_set_property_int (nfc_device *pnd, const nfc_property property, const int value)
|
||||
nfc_device_set_property_int(nfc_device *pnd, const nfc_property property, const int value)
|
||||
{
|
||||
HAL (device_set_property_int, pnd, property, value);
|
||||
HAL(device_set_property_int, pnd, property, value);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -302,9 +302,9 @@ nfc_device_set_property_int (nfc_device *pnd, const nfc_property property, const
|
|||
* accept).
|
||||
*/
|
||||
int
|
||||
nfc_device_set_property_bool (nfc_device *pnd, const nfc_property property, const bool bEnable)
|
||||
nfc_device_set_property_bool(nfc_device *pnd, const nfc_property property, const bool bEnable)
|
||||
{
|
||||
HAL (device_set_property_bool, pnd, property, bEnable);
|
||||
HAL(device_set_property_bool, pnd, property, bEnable);
|
||||
}
|
||||
|
||||
/** @ingroup initiator
|
||||
|
|
@ -328,46 +328,46 @@ nfc_device_set_property_bool (nfc_device *pnd, const nfc_property property, cons
|
|||
* - RF field is shortly dropped (if it was enabled) then activated again
|
||||
*/
|
||||
int
|
||||
nfc_initiator_init (nfc_device *pnd)
|
||||
nfc_initiator_init(nfc_device *pnd)
|
||||
{
|
||||
int res = 0;
|
||||
// Drop the field for a while
|
||||
if ((res = nfc_device_set_property_bool (pnd, NP_ACTIVATE_FIELD, false)) < 0)
|
||||
if ((res = nfc_device_set_property_bool(pnd, NP_ACTIVATE_FIELD, false)) < 0)
|
||||
return res;
|
||||
// Enable field so more power consuming cards can power themselves up
|
||||
if ((res = nfc_device_set_property_bool (pnd, NP_ACTIVATE_FIELD, true)) < 0)
|
||||
if ((res = nfc_device_set_property_bool(pnd, NP_ACTIVATE_FIELD, true)) < 0)
|
||||
return res;
|
||||
// Let the device try forever to find a target/tag
|
||||
if ((res = nfc_device_set_property_bool (pnd, NP_INFINITE_SELECT, true)) < 0)
|
||||
if ((res = nfc_device_set_property_bool(pnd, NP_INFINITE_SELECT, true)) < 0)
|
||||
return res;
|
||||
// Activate auto ISO14443-4 switching by default
|
||||
if ((res = nfc_device_set_property_bool (pnd, NP_AUTO_ISO14443_4, true)) < 0)
|
||||
if ((res = nfc_device_set_property_bool(pnd, NP_AUTO_ISO14443_4, true)) < 0)
|
||||
return res;
|
||||
// Force 14443-A mode
|
||||
if ((res = nfc_device_set_property_bool (pnd, NP_FORCE_ISO14443_A, true)) < 0)
|
||||
if ((res = nfc_device_set_property_bool(pnd, NP_FORCE_ISO14443_A, true)) < 0)
|
||||
return res;
|
||||
// Force speed at 106kbps
|
||||
if ((res = nfc_device_set_property_bool (pnd, NP_FORCE_SPEED_106, true)) < 0)
|
||||
if ((res = nfc_device_set_property_bool(pnd, NP_FORCE_SPEED_106, true)) < 0)
|
||||
return res;
|
||||
// Disallow invalid frame
|
||||
if ((res = nfc_device_set_property_bool (pnd, NP_ACCEPT_INVALID_FRAMES, false)) < 0)
|
||||
if ((res = nfc_device_set_property_bool(pnd, NP_ACCEPT_INVALID_FRAMES, false)) < 0)
|
||||
return res;
|
||||
// Disallow multiple frames
|
||||
if ((res = nfc_device_set_property_bool (pnd, NP_ACCEPT_MULTIPLE_FRAMES, false)) < 0)
|
||||
if ((res = nfc_device_set_property_bool(pnd, NP_ACCEPT_MULTIPLE_FRAMES, false)) < 0)
|
||||
return res;
|
||||
// Make sure we reset the CRC and parity to chip handling.
|
||||
if ((res = nfc_device_set_property_bool (pnd, NP_HANDLE_CRC, true)) < 0)
|
||||
if ((res = nfc_device_set_property_bool(pnd, NP_HANDLE_CRC, true)) < 0)
|
||||
return res;
|
||||
if ((res = nfc_device_set_property_bool (pnd, NP_HANDLE_PARITY, true)) < 0)
|
||||
if ((res = nfc_device_set_property_bool(pnd, NP_HANDLE_PARITY, true)) < 0)
|
||||
return res;
|
||||
// Activate "easy framing" feature by default
|
||||
if ((res = nfc_device_set_property_bool (pnd, NP_EASY_FRAMING, true)) < 0)
|
||||
if ((res = nfc_device_set_property_bool(pnd, NP_EASY_FRAMING, true)) < 0)
|
||||
return res;
|
||||
// Deactivate the CRYPTO1 cipher, it may could cause problems when still active
|
||||
if ((res = nfc_device_set_property_bool (pnd, NP_ACTIVATE_CRYPTO1, false)) < 0)
|
||||
if ((res = nfc_device_set_property_bool(pnd, NP_ACTIVATE_CRYPTO1, false)) < 0)
|
||||
return res;
|
||||
|
||||
HAL (initiator_init, pnd);
|
||||
HAL(initiator_init, pnd);
|
||||
}
|
||||
|
||||
/** @ingroup initiator
|
||||
|
|
@ -391,17 +391,17 @@ nfc_initiator_init (nfc_device *pnd)
|
|||
* the initial modulation and speed (106, 212 or 424 kbps) should be supplied.
|
||||
*/
|
||||
int
|
||||
nfc_initiator_select_passive_target (nfc_device *pnd,
|
||||
const nfc_modulation nm,
|
||||
const uint8_t *pbtInitData, const size_t szInitData,
|
||||
nfc_target *pnt)
|
||||
nfc_initiator_select_passive_target(nfc_device *pnd,
|
||||
const nfc_modulation nm,
|
||||
const uint8_t *pbtInitData, const size_t szInitData,
|
||||
nfc_target *pnt)
|
||||
{
|
||||
uint8_t abtInit[MAX(12, szInitData)];
|
||||
size_t szInit;
|
||||
|
||||
switch (nm.nmt) {
|
||||
case NMT_ISO14443A:
|
||||
iso14443_cascade_uid (pbtInitData, szInitData, abtInit, &szInit);
|
||||
iso14443_cascade_uid(pbtInitData, szInitData, abtInit, &szInit);
|
||||
break;
|
||||
|
||||
case NMT_JEWEL:
|
||||
|
|
@ -411,12 +411,12 @@ nfc_initiator_select_passive_target (nfc_device *pnd,
|
|||
case NMT_ISO14443B2CT:
|
||||
case NMT_FELICA:
|
||||
case NMT_DEP:
|
||||
memcpy (abtInit, pbtInitData, szInitData);
|
||||
memcpy(abtInit, pbtInitData, szInitData);
|
||||
szInit = szInitData;
|
||||
break;
|
||||
}
|
||||
|
||||
HAL (initiator_select_passive_target, pnd, nm, abtInit, szInit, pnt);
|
||||
HAL(initiator_select_passive_target, pnd, nm, abtInit, szInit, pnt);
|
||||
}
|
||||
|
||||
/** @ingroup initiator
|
||||
|
|
@ -436,9 +436,9 @@ nfc_initiator_select_passive_target (nfc_device *pnd,
|
|||
* should be supplied.
|
||||
*/
|
||||
int
|
||||
nfc_initiator_list_passive_targets (nfc_device *pnd,
|
||||
const nfc_modulation nm,
|
||||
nfc_target ant[], const size_t szTargets)
|
||||
nfc_initiator_list_passive_targets(nfc_device *pnd,
|
||||
const nfc_modulation nm,
|
||||
nfc_target ant[], const size_t szTargets)
|
||||
{
|
||||
nfc_target nt;
|
||||
size_t szTargetFound = 0;
|
||||
|
|
@ -449,14 +449,14 @@ nfc_initiator_list_passive_targets (nfc_device *pnd,
|
|||
pnd->last_error = 0;
|
||||
|
||||
// Let the reader only try once to find a tag
|
||||
if ((res = nfc_device_set_property_bool (pnd, NP_INFINITE_SELECT, false)) < 0) {
|
||||
if ((res = nfc_device_set_property_bool(pnd, NP_INFINITE_SELECT, false)) < 0) {
|
||||
return res;
|
||||
}
|
||||
|
||||
prepare_initiator_data (nm, &pbtInitData, &szInitDataLen);
|
||||
prepare_initiator_data(nm, &pbtInitData, &szInitDataLen);
|
||||
|
||||
while (nfc_initiator_select_passive_target (pnd, nm, pbtInitData, szInitDataLen, &nt) > 0) {
|
||||
nfc_initiator_deselect_target (pnd);
|
||||
while (nfc_initiator_select_passive_target(pnd, nm, pbtInitData, szInitDataLen, &nt) > 0) {
|
||||
nfc_initiator_deselect_target(pnd);
|
||||
if (szTargets == szTargetFound) {
|
||||
break;
|
||||
}
|
||||
|
|
@ -464,14 +464,14 @@ nfc_initiator_list_passive_targets (nfc_device *pnd,
|
|||
bool seen = false;
|
||||
// Check if we've already seen this tag
|
||||
for (i = 0; i < szTargetFound; i++) {
|
||||
if (memcmp(&(ant[i]), &nt, sizeof (nfc_target)) == 0) {
|
||||
if (memcmp(&(ant[i]), &nt, sizeof(nfc_target)) == 0) {
|
||||
seen = true;
|
||||
}
|
||||
}
|
||||
if (seen) {
|
||||
break;
|
||||
}
|
||||
memcpy (&(ant[szTargetFound]), &nt, sizeof (nfc_target));
|
||||
memcpy(&(ant[szTargetFound]), &nt, sizeof(nfc_target));
|
||||
szTargetFound++;
|
||||
// deselect has no effect on FeliCa and Jewel cards so we'll stop after one...
|
||||
// ISO/IEC 14443 B' cards are polled at 100% probability so it's not possible to detect correctly two cards at the same time
|
||||
|
|
@ -496,12 +496,12 @@ nfc_initiator_list_passive_targets (nfc_device *pnd,
|
|||
* @param[out] pnt pointer on \a nfc_target (over)writable struct
|
||||
*/
|
||||
int
|
||||
nfc_initiator_poll_target (nfc_device *pnd,
|
||||
const nfc_modulation *pnmModulations, const size_t szModulations,
|
||||
const uint8_t uiPollNr, const uint8_t uiPeriod,
|
||||
nfc_target *pnt)
|
||||
nfc_initiator_poll_target(nfc_device *pnd,
|
||||
const nfc_modulation *pnmModulations, const size_t szModulations,
|
||||
const uint8_t uiPollNr, const uint8_t uiPeriod,
|
||||
nfc_target *pnt)
|
||||
{
|
||||
HAL (initiator_poll_target, pnd, pnmModulations, szModulations, uiPollNr, uiPeriod, pnt);
|
||||
HAL(initiator_poll_target, pnd, pnmModulations, szModulations, uiPollNr, uiPeriod, pnt);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -523,11 +523,11 @@ nfc_initiator_poll_target (nfc_device *pnd,
|
|||
* @note \a nfc_dep_info will be returned when the target was acquired successfully.
|
||||
*/
|
||||
int
|
||||
nfc_initiator_select_dep_target (nfc_device *pnd,
|
||||
const nfc_dep_mode ndm, const nfc_baud_rate nbr,
|
||||
const nfc_dep_info *pndiInitiator, nfc_target *pnt, const int timeout)
|
||||
nfc_initiator_select_dep_target(nfc_device *pnd,
|
||||
const nfc_dep_mode ndm, const nfc_baud_rate nbr,
|
||||
const nfc_dep_info *pndiInitiator, nfc_target *pnt, const int timeout)
|
||||
{
|
||||
HAL (initiator_select_dep_target, pnd, ndm, nbr, pndiInitiator, pnt, timeout);
|
||||
HAL(initiator_select_dep_target, pnd, ndm, nbr, pndiInitiator, pnt, timeout);
|
||||
}
|
||||
|
||||
/** @ingroup initiator
|
||||
|
|
@ -548,19 +548,19 @@ nfc_initiator_select_dep_target (nfc_device *pnd,
|
|||
* @note \a nfc_dep_info will be returned when the target was acquired successfully.
|
||||
*/
|
||||
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)
|
||||
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 int period = 300;
|
||||
int remaining_time = timeout;
|
||||
int res;
|
||||
if ((res = nfc_device_set_property_bool (pnd, NP_INFINITE_SELECT, true)) < 0)
|
||||
if ((res = nfc_device_set_property_bool(pnd, NP_INFINITE_SELECT, true)) < 0)
|
||||
return res;
|
||||
while (remaining_time > 0) {
|
||||
if ((res = nfc_initiator_select_dep_target (pnd, ndm, nbr, pndiInitiator, pnt, period)) < 0) {
|
||||
if ((res = nfc_initiator_select_dep_target(pnd, ndm, nbr, pndiInitiator, pnt, period)) < 0) {
|
||||
if (res != NFC_ETIMEOUT)
|
||||
return res;
|
||||
}
|
||||
|
|
@ -584,9 +584,9 @@ nfc_initiator_poll_dep_target (struct nfc_device *pnd,
|
|||
* the next tag until the correct tag is found.
|
||||
*/
|
||||
int
|
||||
nfc_initiator_deselect_target (nfc_device *pnd)
|
||||
nfc_initiator_deselect_target(nfc_device *pnd)
|
||||
{
|
||||
HAL (initiator_deselect_target, pnd);
|
||||
HAL(initiator_deselect_target, pnd);
|
||||
}
|
||||
|
||||
/** @ingroup initiator
|
||||
|
|
@ -616,10 +616,10 @@ nfc_initiator_deselect_target (nfc_device *pnd)
|
|||
* @warning The configuration option \a NP_HANDLE_PARITY must be set to \c true (the default value).
|
||||
*/
|
||||
int
|
||||
nfc_initiator_transceive_bytes (nfc_device *pnd, const uint8_t *pbtTx, const size_t szTx, uint8_t *pbtRx,
|
||||
const size_t szRx, int timeout)
|
||||
nfc_initiator_transceive_bytes(nfc_device *pnd, const uint8_t *pbtTx, const size_t szTx, uint8_t *pbtRx,
|
||||
const size_t szRx, int timeout)
|
||||
{
|
||||
HAL (initiator_transceive_bytes, pnd, pbtTx, szTx, pbtRx, szRx, timeout)
|
||||
HAL(initiator_transceive_bytes, pnd, pbtTx, szTx, pbtRx, szRx, timeout)
|
||||
}
|
||||
|
||||
/** @ingroup initiator
|
||||
|
|
@ -658,10 +658,10 @@ nfc_initiator_transceive_bytes (nfc_device *pnd, const uint8_t *pbtTx, const siz
|
|||
* CRC bytes. Using this feature you are able to simulate these frames.
|
||||
*/
|
||||
int
|
||||
nfc_initiator_transceive_bits (nfc_device *pnd, const uint8_t *pbtTx, const size_t szTxBits, const uint8_t *pbtTxPar,
|
||||
uint8_t *pbtRx, uint8_t *pbtRxPar)
|
||||
nfc_initiator_transceive_bits(nfc_device *pnd, const uint8_t *pbtTx, const size_t szTxBits, const uint8_t *pbtTxPar,
|
||||
uint8_t *pbtRx, uint8_t *pbtRxPar)
|
||||
{
|
||||
HAL (initiator_transceive_bits, pnd, pbtTx, szTxBits, pbtTxPar, pbtRx, pbtRxPar);
|
||||
HAL(initiator_transceive_bits, pnd, pbtTx, szTxBits, pbtTxPar, pbtRx, pbtRxPar);
|
||||
}
|
||||
|
||||
/** @ingroup initiator
|
||||
|
|
@ -685,9 +685,9 @@ nfc_initiator_transceive_bits (nfc_device *pnd, const uint8_t *pbtTx, const size
|
|||
* @warning The configuration option \a NP_HANDLE_PARITY must be set to \c true (the default value).
|
||||
*/
|
||||
int
|
||||
nfc_initiator_transceive_bytes_timed (nfc_device *pnd, const uint8_t *pbtTx, const size_t szTx, uint8_t *pbtRx, uint32_t *cycles)
|
||||
nfc_initiator_transceive_bytes_timed(nfc_device *pnd, const uint8_t *pbtTx, const size_t szTx, uint8_t *pbtRx, uint32_t *cycles)
|
||||
{
|
||||
HAL (initiator_transceive_bytes_timed, pnd, pbtTx, szTx, pbtRx, cycles);
|
||||
HAL(initiator_transceive_bytes_timed, pnd, pbtTx, szTx, pbtRx, cycles);
|
||||
}
|
||||
|
||||
/** @ingroup initiator
|
||||
|
|
@ -699,9 +699,9 @@ nfc_initiator_transceive_bytes_timed (nfc_device *pnd, const uint8_t *pbtTx, con
|
|||
* @warning To run the test, one or more commands will be sent to target
|
||||
*/
|
||||
int
|
||||
nfc_initiator_target_is_present (nfc_device *pnd, const nfc_target nt)
|
||||
nfc_initiator_target_is_present(nfc_device *pnd, const nfc_target nt)
|
||||
{
|
||||
HAL (initiator_target_is_present, pnd, nt);
|
||||
HAL(initiator_target_is_present, pnd, nt);
|
||||
}
|
||||
|
||||
/** @ingroup initiator
|
||||
|
|
@ -726,10 +726,10 @@ nfc_initiator_target_is_present (nfc_device *pnd, const nfc_target nt)
|
|||
* @warning The configuration option \a NP_HANDLE_PARITY must be set to \c true (the default value).
|
||||
*/
|
||||
int
|
||||
nfc_initiator_transceive_bits_timed (nfc_device *pnd, const uint8_t *pbtTx, const size_t szTxBits, const uint8_t *pbtTxPar,
|
||||
uint8_t *pbtRx, uint8_t *pbtRxPar, uint32_t *cycles)
|
||||
nfc_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)
|
||||
{
|
||||
HAL (initiator_transceive_bits_timed, pnd, pbtTx, szTxBits, pbtTxPar, pbtRx, pbtRxPar, cycles);
|
||||
HAL(initiator_transceive_bits_timed, pnd, pbtTx, szTxBits, pbtTxPar, pbtRx, pbtRxPar, cycles);
|
||||
}
|
||||
|
||||
/** @ingroup target
|
||||
|
|
@ -763,34 +763,34 @@ nfc_initiator_transceive_bits_timed (nfc_device *pnd, const uint8_t *pbtTx, cons
|
|||
* receive functions can be used.
|
||||
*/
|
||||
int
|
||||
nfc_target_init (nfc_device *pnd, nfc_target *pnt, uint8_t *pbtRx, const size_t szRx, int timeout)
|
||||
nfc_target_init(nfc_device *pnd, nfc_target *pnt, uint8_t *pbtRx, const size_t szRx, int timeout)
|
||||
{
|
||||
int res = 0;
|
||||
// Disallow invalid frame
|
||||
if ((res = nfc_device_set_property_bool (pnd, NP_ACCEPT_INVALID_FRAMES, false)) < 0)
|
||||
if ((res = nfc_device_set_property_bool(pnd, NP_ACCEPT_INVALID_FRAMES, false)) < 0)
|
||||
return res;
|
||||
// Disallow multiple frames
|
||||
if ((res = nfc_device_set_property_bool (pnd, NP_ACCEPT_MULTIPLE_FRAMES, false)) < 0)
|
||||
if ((res = nfc_device_set_property_bool(pnd, NP_ACCEPT_MULTIPLE_FRAMES, false)) < 0)
|
||||
return res;
|
||||
// Make sure we reset the CRC and parity to chip handling.
|
||||
if ((res = nfc_device_set_property_bool (pnd, NP_HANDLE_CRC, true)) < 0)
|
||||
if ((res = nfc_device_set_property_bool(pnd, NP_HANDLE_CRC, true)) < 0)
|
||||
return res;
|
||||
if ((res = nfc_device_set_property_bool (pnd, NP_HANDLE_PARITY, true)) < 0)
|
||||
if ((res = nfc_device_set_property_bool(pnd, NP_HANDLE_PARITY, true)) < 0)
|
||||
return res;
|
||||
// Activate auto ISO14443-4 switching by default
|
||||
if ((res = nfc_device_set_property_bool (pnd, NP_AUTO_ISO14443_4, true)) < 0)
|
||||
if ((res = nfc_device_set_property_bool(pnd, NP_AUTO_ISO14443_4, true)) < 0)
|
||||
return res;
|
||||
// Activate "easy framing" feature by default
|
||||
if ((res = nfc_device_set_property_bool (pnd, NP_EASY_FRAMING, true)) < 0)
|
||||
if ((res = nfc_device_set_property_bool(pnd, NP_EASY_FRAMING, true)) < 0)
|
||||
return res;
|
||||
// Deactivate the CRYPTO1 cipher, it may could cause problems when still active
|
||||
if ((res = nfc_device_set_property_bool (pnd, NP_ACTIVATE_CRYPTO1, false)) < 0)
|
||||
if ((res = nfc_device_set_property_bool(pnd, NP_ACTIVATE_CRYPTO1, false)) < 0)
|
||||
return res;
|
||||
// Drop explicitely the field
|
||||
if ((res = nfc_device_set_property_bool (pnd, NP_ACTIVATE_FIELD, false)) < 0)
|
||||
if ((res = nfc_device_set_property_bool(pnd, NP_ACTIVATE_FIELD, false)) < 0)
|
||||
return res;
|
||||
|
||||
HAL (target_init, pnd, pnt, pbtRx, szRx, timeout);
|
||||
HAL(target_init, pnd, pnt, pbtRx, szRx, timeout);
|
||||
}
|
||||
|
||||
/** @ingroup dev
|
||||
|
|
@ -804,9 +804,9 @@ nfc_target_init (nfc_device *pnd, nfc_target *pnt, uint8_t *pbtRx, const size_t
|
|||
* In target mode, the emulation is stoped (no target available from external initiator) and the device is set to low power mode (if avaible).
|
||||
*/
|
||||
int
|
||||
nfc_idle (nfc_device *pnd)
|
||||
nfc_idle(nfc_device *pnd)
|
||||
{
|
||||
HAL (idle, pnd);
|
||||
HAL(idle, pnd);
|
||||
}
|
||||
|
||||
/** @ingroup dev
|
||||
|
|
@ -821,9 +821,9 @@ nfc_idle (nfc_device *pnd)
|
|||
* @note The blocking function (ie. nfc_target_init()) will failed with DEABORT error.
|
||||
*/
|
||||
int
|
||||
nfc_abort_command (nfc_device *pnd)
|
||||
nfc_abort_command(nfc_device *pnd)
|
||||
{
|
||||
HAL (abort_command, pnd);
|
||||
HAL(abort_command, pnd);
|
||||
}
|
||||
|
||||
/** @ingroup target
|
||||
|
|
@ -842,9 +842,9 @@ nfc_abort_command (nfc_device *pnd)
|
|||
* If timeout is a null pointer, the function blocks indefinitely (until an error is raised or function is completed).
|
||||
*/
|
||||
int
|
||||
nfc_target_send_bytes (nfc_device *pnd, const uint8_t *pbtTx, const size_t szTx, int timeout)
|
||||
nfc_target_send_bytes(nfc_device *pnd, const uint8_t *pbtTx, const size_t szTx, int timeout)
|
||||
{
|
||||
HAL (target_send_bytes, pnd, pbtTx, szTx, timeout);
|
||||
HAL(target_send_bytes, pnd, pbtTx, szTx, timeout);
|
||||
}
|
||||
|
||||
/** @ingroup target
|
||||
|
|
@ -862,9 +862,9 @@ nfc_target_send_bytes (nfc_device *pnd, const uint8_t *pbtTx, const size_t szTx,
|
|||
* If timeout equals to -1, the default timeout will be used
|
||||
*/
|
||||
int
|
||||
nfc_target_receive_bytes (nfc_device *pnd, uint8_t *pbtRx, const size_t szRx, int timeout)
|
||||
nfc_target_receive_bytes(nfc_device *pnd, uint8_t *pbtRx, const size_t szRx, int timeout)
|
||||
{
|
||||
HAL (target_receive_bytes, pnd, pbtRx, szRx, timeout);
|
||||
HAL(target_receive_bytes, pnd, pbtRx, szRx, timeout);
|
||||
}
|
||||
|
||||
/** @ingroup target
|
||||
|
|
@ -879,9 +879,9 @@ nfc_target_receive_bytes (nfc_device *pnd, uint8_t *pbtRx, const size_t szRx, in
|
|||
* using the specified NFC device (configured as \e target).
|
||||
*/
|
||||
int
|
||||
nfc_target_send_bits (nfc_device *pnd, const uint8_t *pbtTx, const size_t szTxBits, const uint8_t *pbtTxPar)
|
||||
nfc_target_send_bits(nfc_device *pnd, const uint8_t *pbtTx, const size_t szTxBits, const uint8_t *pbtTxPar)
|
||||
{
|
||||
HAL (target_send_bits, pnd, pbtTx, szTxBits, pbtTxPar);
|
||||
HAL(target_send_bits, pnd, pbtTx, szTxBits, pbtTxPar);
|
||||
}
|
||||
|
||||
/** @ingroup target
|
||||
|
|
@ -901,9 +901,9 @@ nfc_target_send_bits (nfc_device *pnd, const uint8_t *pbtTx, const size_t szTxBi
|
|||
* frames.
|
||||
*/
|
||||
int
|
||||
nfc_target_receive_bits (nfc_device *pnd, uint8_t *pbtRx, const size_t szRx, uint8_t *pbtRxPar)
|
||||
nfc_target_receive_bits(nfc_device *pnd, uint8_t *pbtRx, const size_t szRx, uint8_t *pbtRxPar)
|
||||
{
|
||||
HAL (target_receive_bits, pnd, pbtRx, szRx, pbtRxPar);
|
||||
HAL(target_receive_bits, pnd, pbtRx, szRx, pbtRxPar);
|
||||
}
|
||||
|
||||
static struct sErrorMessage {
|
||||
|
|
@ -932,11 +932,11 @@ static struct sErrorMessage {
|
|||
* @param pnd \a nfc_device struct pointer that represent currently used device
|
||||
*/
|
||||
const char *
|
||||
nfc_strerror (const nfc_device *pnd)
|
||||
nfc_strerror(const nfc_device *pnd)
|
||||
{
|
||||
const char *pcRes = "Unknown error";
|
||||
size_t i;
|
||||
for (i = 0; i < (sizeof (sErrorMessages) / sizeof (struct sErrorMessage)); i++) {
|
||||
for (i = 0; i < (sizeof(sErrorMessages) / sizeof(struct sErrorMessage)); i++) {
|
||||
if (sErrorMessages[i].iErrorCode == pnd->last_error) {
|
||||
pcRes = sErrorMessages[i].pcErrorMsg;
|
||||
break;
|
||||
|
|
@ -955,9 +955,9 @@ nfc_strerror (const nfc_device *pnd)
|
|||
* @param szBufLen size of buffer
|
||||
*/
|
||||
int
|
||||
nfc_strerror_r (const nfc_device *pnd, char *pcStrErrBuf, size_t szBufLen)
|
||||
nfc_strerror_r(const nfc_device *pnd, char *pcStrErrBuf, size_t szBufLen)
|
||||
{
|
||||
return (snprintf (pcStrErrBuf, szBufLen, "%s", nfc_strerror (pnd)) < 0) ? -1 : 0;
|
||||
return (snprintf(pcStrErrBuf, szBufLen, "%s", nfc_strerror(pnd)) < 0) ? -1 : 0;
|
||||
}
|
||||
|
||||
/** @ingroup error
|
||||
|
|
@ -967,9 +967,9 @@ nfc_strerror_r (const nfc_device *pnd, char *pcStrErrBuf, size_t szBufLen)
|
|||
* @param pcString a string
|
||||
*/
|
||||
void
|
||||
nfc_perror (const nfc_device *pnd, const char *pcString)
|
||||
nfc_perror(const nfc_device *pnd, const char *pcString)
|
||||
{
|
||||
fprintf (stderr, "%s: %s\n", pcString, nfc_strerror (pnd));
|
||||
fprintf(stderr, "%s: %s\n", pcString, nfc_strerror(pnd));
|
||||
}
|
||||
|
||||
/** @ingroup error
|
||||
|
|
@ -979,7 +979,7 @@ nfc_perror (const nfc_device *pnd, const char *pcString)
|
|||
* @param pnd \a nfc_device struct pointer that represent currently used device
|
||||
*/
|
||||
int
|
||||
nfc_device_get_last_error (const nfc_device *pnd)
|
||||
nfc_device_get_last_error(const nfc_device *pnd)
|
||||
{
|
||||
return pnd->last_error;
|
||||
}
|
||||
|
|
@ -993,7 +993,7 @@ nfc_device_get_last_error (const nfc_device *pnd)
|
|||
* @param pnd \a nfc_device struct pointer that represent currently used device
|
||||
*/
|
||||
const char *
|
||||
nfc_device_get_name (nfc_device *pnd)
|
||||
nfc_device_get_name(nfc_device *pnd)
|
||||
{
|
||||
return pnd->name;
|
||||
}
|
||||
|
|
@ -1005,7 +1005,7 @@ nfc_device_get_name (nfc_device *pnd)
|
|||
* @param pnd \a nfc_device struct pointer that represent currently used device
|
||||
*/
|
||||
const char *
|
||||
nfc_device_get_connstring (nfc_device *pnd)
|
||||
nfc_device_get_connstring(nfc_device *pnd)
|
||||
{
|
||||
return pnd->connstring;
|
||||
}
|
||||
|
|
@ -1019,9 +1019,9 @@ nfc_device_get_connstring (nfc_device *pnd)
|
|||
*
|
||||
*/
|
||||
int
|
||||
nfc_device_get_supported_modulation (nfc_device *pnd, const nfc_mode mode, const nfc_modulation_type **const supported_mt)
|
||||
nfc_device_get_supported_modulation(nfc_device *pnd, const nfc_mode mode, const nfc_modulation_type **const supported_mt)
|
||||
{
|
||||
HAL (get_supported_modulation, pnd, mode, supported_mt);
|
||||
HAL(get_supported_modulation, pnd, mode, supported_mt);
|
||||
}
|
||||
|
||||
/** @ingroup data
|
||||
|
|
@ -1033,9 +1033,9 @@ nfc_device_get_supported_modulation (nfc_device *pnd, const nfc_mode mode, const
|
|||
*
|
||||
*/
|
||||
int
|
||||
nfc_device_get_supported_baud_rate (nfc_device *pnd, const nfc_modulation_type nmt, const nfc_baud_rate **const supported_br)
|
||||
nfc_device_get_supported_baud_rate(nfc_device *pnd, const nfc_modulation_type nmt, const nfc_baud_rate **const supported_br)
|
||||
{
|
||||
HAL (get_supported_baud_rate, pnd, nmt, supported_br);
|
||||
HAL(get_supported_baud_rate, pnd, nmt, supported_br);
|
||||
}
|
||||
|
||||
/* Misc. functions */
|
||||
|
|
@ -1047,7 +1047,7 @@ nfc_device_get_supported_baud_rate (nfc_device *pnd, const nfc_modulation_type n
|
|||
* @param pnd \a nfc_device struct pointer that represent currently used device
|
||||
*/
|
||||
const char *
|
||||
nfc_version (void)
|
||||
nfc_version(void)
|
||||
{
|
||||
#ifdef SVN_REVISION
|
||||
return PACKAGE_VERSION " (r" SVN_REVISION ")";
|
||||
|
|
@ -1064,9 +1064,9 @@ nfc_version (void)
|
|||
* @param buflen buf length
|
||||
*/
|
||||
int
|
||||
nfc_device_get_information_about (nfc_device *pnd, char *buf, size_t buflen)
|
||||
nfc_device_get_information_about(nfc_device *pnd, char *buf, size_t buflen)
|
||||
{
|
||||
HAL (device_get_information_about, pnd, buf, buflen);
|
||||
HAL(device_get_information_about, pnd, buf, buflen);
|
||||
}
|
||||
|
||||
/** @ingroup string-converter
|
||||
|
|
@ -1075,9 +1075,9 @@ nfc_device_get_information_about (nfc_device *pnd, char *buf, size_t buflen)
|
|||
* @param \a nfc_baud_rate to convert
|
||||
*/
|
||||
const char *
|
||||
str_nfc_baud_rate (const nfc_baud_rate nbr)
|
||||
str_nfc_baud_rate(const nfc_baud_rate nbr)
|
||||
{
|
||||
switch(nbr) {
|
||||
switch (nbr) {
|
||||
case NBR_UNDEFINED:
|
||||
return "undefined baud rate";
|
||||
break;
|
||||
|
|
@ -1104,9 +1104,9 @@ str_nfc_baud_rate (const nfc_baud_rate nbr)
|
|||
* @param \a nfc_modulation_type to convert
|
||||
*/
|
||||
const char *
|
||||
str_nfc_modulation_type (const nfc_modulation_type nmt)
|
||||
str_nfc_modulation_type(const nfc_modulation_type nmt)
|
||||
{
|
||||
switch(nmt) {
|
||||
switch (nmt) {
|
||||
case NMT_ISO14443A:
|
||||
return "ISO/IEC 14443A";
|
||||
break;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue