fixed windows compiling issues
This commit is contained in:
parent
f8b3ba9ab6
commit
15981b743e
7 changed files with 35 additions and 22 deletions
|
@ -45,7 +45,7 @@ static byte_t abtFelica[5] = { 0x00, 0xff, 0xff, 0x00, 0x00 };
|
||||||
int main(int argc, const char* argv[])
|
int main(int argc, const char* argv[])
|
||||||
{
|
{
|
||||||
size_t szFound;
|
size_t szFound;
|
||||||
int i;
|
size_t i;
|
||||||
nfc_target_info_t nti;
|
nfc_target_info_t nti;
|
||||||
nfc_device_desc_t *pnddDevices;
|
nfc_device_desc_t *pnddDevices;
|
||||||
|
|
||||||
|
|
|
@ -338,6 +338,7 @@ int main(int argc, const char* argv[])
|
||||||
byte_t* pbtUID;
|
byte_t* pbtUID;
|
||||||
FILE* pfKeys = NULL;
|
FILE* pfKeys = NULL;
|
||||||
FILE* pfDump = NULL;
|
FILE* pfDump = NULL;
|
||||||
|
const char* command = argv[1];
|
||||||
|
|
||||||
if(argc < 2)
|
if(argc < 2)
|
||||||
{
|
{
|
||||||
|
@ -345,7 +346,6 @@ int main(int argc, const char* argv[])
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* command = argv[1];
|
|
||||||
if(strcmp(command, "r") == 0)
|
if(strcmp(command, "r") == 0)
|
||||||
{
|
{
|
||||||
atAction = ACTION_READ;
|
atAction = ACTION_READ;
|
||||||
|
|
|
@ -152,6 +152,7 @@ void print_hex(const byte_t* pbtData, const size_t szBytes)
|
||||||
|
|
||||||
void print_hex_bits(const byte_t* pbtData, const size_t szBits)
|
void print_hex_bits(const byte_t* pbtData, const size_t szBits)
|
||||||
{
|
{
|
||||||
|
uint8_t uRemainder;
|
||||||
size_t szPos;
|
size_t szPos;
|
||||||
size_t szBytes = szBits/8;
|
size_t szBytes = szBits/8;
|
||||||
|
|
||||||
|
@ -160,7 +161,7 @@ void print_hex_bits(const byte_t* pbtData, const size_t szBits)
|
||||||
printf("%02x ",pbtData[szPos]);
|
printf("%02x ",pbtData[szPos]);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t uRemainder = szBits % 8;
|
uRemainder = szBits % 8;
|
||||||
// Print the rest bits
|
// Print the rest bits
|
||||||
if (uRemainder != 0)
|
if (uRemainder != 0)
|
||||||
{
|
{
|
||||||
|
@ -174,6 +175,7 @@ void print_hex_bits(const byte_t* pbtData, const size_t szBits)
|
||||||
|
|
||||||
void print_hex_par(const byte_t* pbtData, const size_t szBits, const byte_t* pbtDataPar)
|
void print_hex_par(const byte_t* pbtData, const size_t szBits, const byte_t* pbtDataPar)
|
||||||
{
|
{
|
||||||
|
uint8_t uRemainder;
|
||||||
size_t szPos;
|
size_t szPos;
|
||||||
size_t szBytes = szBits/8;
|
size_t szBytes = szBits/8;
|
||||||
|
|
||||||
|
@ -188,7 +190,7 @@ void print_hex_par(const byte_t* pbtData, const size_t szBits, const byte_t* pbt
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t uRemainder = szBits % 8;
|
uRemainder = szBits % 8;
|
||||||
// Print the rest bits, these cannot have parity bit
|
// Print the rest bits, these cannot have parity bit
|
||||||
if (uRemainder != 0)
|
if (uRemainder != 0)
|
||||||
{
|
{
|
||||||
|
|
|
@ -369,9 +369,10 @@ uint32_t uart_get_speed(const serial_port sp)
|
||||||
|
|
||||||
bool uart_cts(const serial_port sp)
|
bool uart_cts(const serial_port sp)
|
||||||
{
|
{
|
||||||
char status;
|
DWORD ModemStat;
|
||||||
if (ioctl(((serial_port_unix*)sp)->fd,TIOCMGET,&status) < 0) return false;
|
const serial_port_windows* spw = (serial_port_windows*)sp;
|
||||||
return (status & TIOCM_CTS);
|
if (!GetCommModemStatus(spw->hPort,&ModemStat)) return false;
|
||||||
|
return (ModemStat & MS_CTS_ON);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool uart_receive(const serial_port sp, byte_t* pbtRx, size_t* pszRxLen)
|
bool uart_receive(const serial_port sp, byte_t* pbtRx, size_t* pszRxLen)
|
||||||
|
|
|
@ -56,8 +56,9 @@
|
||||||
#define ACR122_RESPONSE_LEN 268
|
#define ACR122_RESPONSE_LEN 268
|
||||||
|
|
||||||
const char *supported_devices[] = {
|
const char *supported_devices[] = {
|
||||||
"ACS ACR122U",
|
"ACS ACR122",
|
||||||
"ACS ACR 38U-CCID",
|
"ACS ACR 38U-CCID",
|
||||||
|
" CCID USB",
|
||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -135,6 +136,8 @@ acr122_list_devices(nfc_device_desc_t pnddDevices[], size_t szDevices, size_t *p
|
||||||
size_t szDeviceNamesLen = sizeof(acDeviceNames);
|
size_t szDeviceNamesLen = sizeof(acDeviceNames);
|
||||||
uint32_t uiBusIndex = 0;
|
uint32_t uiBusIndex = 0;
|
||||||
SCARDCONTEXT *pscc;
|
SCARDCONTEXT *pscc;
|
||||||
|
bool bSupported;
|
||||||
|
int i;
|
||||||
|
|
||||||
// Clear the reader list
|
// Clear the reader list
|
||||||
memset(acDeviceNames, '\0', szDeviceNamesLen);
|
memset(acDeviceNames, '\0', szDeviceNamesLen);
|
||||||
|
@ -158,8 +161,8 @@ acr122_list_devices(nfc_device_desc_t pnddDevices[], size_t szDevices, size_t *p
|
||||||
|
|
||||||
DBG("- %s (pos=%d)", acDeviceNames + szPos, szPos);
|
DBG("- %s (pos=%d)", acDeviceNames + szPos, szPos);
|
||||||
|
|
||||||
bool bSupported = false;
|
bSupported = false;
|
||||||
for (int i = 0; supported_devices[i] && !bSupported; i++) {
|
for (i = 0; supported_devices[i] && !bSupported; i++) {
|
||||||
int l = strlen(supported_devices[i]);
|
int l = strlen(supported_devices[i]);
|
||||||
bSupported = 0 == strncmp(supported_devices[i], acDeviceNames + szPos, l);
|
bSupported = 0 == strncmp(supported_devices[i], acDeviceNames + szPos, l);
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,6 +37,8 @@
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#define SERIAL_STRING "COM"
|
#define SERIAL_STRING "COM"
|
||||||
|
#define snprintf _snprintf
|
||||||
|
#define strdup _strdup
|
||||||
#else
|
#else
|
||||||
// unistd.h is needed for usleep() fct.
|
// unistd.h is needed for usleep() fct.
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
@ -80,6 +82,10 @@ pn532_uart_pick_device (void)
|
||||||
bool
|
bool
|
||||||
pn532_uart_list_devices(nfc_device_desc_t pnddDevices[], size_t szDevices, size_t *pszDeviceFound)
|
pn532_uart_list_devices(nfc_device_desc_t pnddDevices[], size_t szDevices, size_t *pszDeviceFound)
|
||||||
{
|
{
|
||||||
|
serial_port sp;
|
||||||
|
char acConnect[BUFFER_LENGTH];
|
||||||
|
int iDevice;
|
||||||
|
|
||||||
/* @note: Due to UART bus we can't know if its really a pn532 without
|
/* @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
|
* sending some PN53x commands. But using this way to probe devices, we can
|
||||||
* have serious problem with other device on this bus */
|
* have serious problem with other device on this bus */
|
||||||
|
@ -89,12 +95,9 @@ pn532_uart_list_devices(nfc_device_desc_t pnddDevices[], size_t szDevices, size_
|
||||||
INFO("Sorry, serial auto-probing have been disabled at compile time.");
|
INFO("Sorry, serial auto-probing have been disabled at compile time.");
|
||||||
return false;
|
return false;
|
||||||
#else /* DISABLE_SERIAL_AUTOPROBE */
|
#else /* DISABLE_SERIAL_AUTOPROBE */
|
||||||
char acConnect[BUFFER_LENGTH];
|
|
||||||
serial_port sp;
|
|
||||||
|
|
||||||
|
|
||||||
// I have no idea how MAC OS X deals with multiple devices, so a quick workaround
|
// I have no idea how MAC OS X deals with multiple devices, so a quick workaround
|
||||||
for (int iDevice=0; iDevice<DRIVERS_MAX_DEVICES; iDevice++)
|
for (iDevice=0; iDevice<DRIVERS_MAX_DEVICES; iDevice++)
|
||||||
{
|
{
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
strcpy(acConnect,SERIAL_STRING);
|
strcpy(acConnect,SERIAL_STRING);
|
||||||
|
@ -132,6 +135,12 @@ pn532_uart_list_devices(nfc_device_desc_t pnddDevices[], size_t szDevices, size_
|
||||||
|
|
||||||
nfc_device_t* pn532_uart_connect(const nfc_device_desc_t* pndd)
|
nfc_device_t* pn532_uart_connect(const nfc_device_desc_t* pndd)
|
||||||
{
|
{
|
||||||
|
/** @info PN532C106 wakeup. */
|
||||||
|
/** @todo Put this command in pn53x init process */
|
||||||
|
byte_t abtRxBuf[BUFFER_LENGTH];
|
||||||
|
size_t szRxBufLen;
|
||||||
|
const byte_t pncmd_pn532c106_wakeup[] = { 0x55,0x55,0x00,0x00,0x00,0x00,0x00,0xFF,0x03,0xFD,0xD4,0x14,0x01,0x17,0x00 };
|
||||||
|
|
||||||
serial_port sp;
|
serial_port sp;
|
||||||
nfc_device_t* pnd = NULL;
|
nfc_device_t* pnd = NULL;
|
||||||
|
|
||||||
|
@ -149,12 +158,6 @@ nfc_device_t* pn532_uart_connect(const nfc_device_desc_t* pndd)
|
||||||
uart_set_speed(sp, pndd->uiSpeed);
|
uart_set_speed(sp, pndd->uiSpeed);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @info PN532C106 wakeup. */
|
|
||||||
/** @todo Put this command in pn53x init process */
|
|
||||||
byte_t abtRxBuf[BUFFER_LENGTH];
|
|
||||||
size_t szRxBufLen;
|
|
||||||
const byte_t pncmd_pn532c106_wakeup[] = { 0x55,0x55,0x00,0x00,0x00,0x00,0x00,0xFF,0x03,0xFD,0xD4,0x14,0x01,0x17,0x00 };
|
|
||||||
|
|
||||||
uart_send(sp, pncmd_pn532c106_wakeup, sizeof(pncmd_pn532c106_wakeup));
|
uart_send(sp, pncmd_pn532c106_wakeup, sizeof(pncmd_pn532c106_wakeup));
|
||||||
|
|
||||||
if (!uart_receive(sp,abtRxBuf,&szRxBufLen)) {
|
if (!uart_receive(sp,abtRxBuf,&szRxBufLen)) {
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
@ -34,7 +35,9 @@
|
||||||
|
|
||||||
#include <nfc/nfc-messages.h>
|
#include <nfc/nfc-messages.h>
|
||||||
|
|
||||||
#include "../../config.h"
|
#ifndef _WIN32
|
||||||
|
#include "../../config.h"
|
||||||
|
#endif // _WIN32
|
||||||
|
|
||||||
nfc_device_desc_t * nfc_pick_device (void);
|
nfc_device_desc_t * nfc_pick_device (void);
|
||||||
|
|
||||||
|
@ -94,6 +97,7 @@ void
|
||||||
nfc_list_devices(nfc_device_desc_t pnddDevices[], size_t szDevices, size_t *pszDeviceFound)
|
nfc_list_devices(nfc_device_desc_t pnddDevices[], size_t szDevices, size_t *pszDeviceFound)
|
||||||
{
|
{
|
||||||
uint32_t uiDriver;
|
uint32_t uiDriver;
|
||||||
|
size_t szN;
|
||||||
|
|
||||||
*pszDeviceFound = 0;
|
*pszDeviceFound = 0;
|
||||||
|
|
||||||
|
@ -102,7 +106,7 @@ nfc_list_devices(nfc_device_desc_t pnddDevices[], size_t szDevices, size_t *pszD
|
||||||
if (drivers_callbacks_list[uiDriver].list_devices != NULL)
|
if (drivers_callbacks_list[uiDriver].list_devices != NULL)
|
||||||
{
|
{
|
||||||
DBG("List avaible device using %s driver",drivers_callbacks_list[uiDriver].acDriver);
|
DBG("List avaible device using %s driver",drivers_callbacks_list[uiDriver].acDriver);
|
||||||
size_t szN = 0;
|
szN = 0;
|
||||||
if (drivers_callbacks_list[uiDriver].list_devices (pnddDevices + (*pszDeviceFound), szDevices - (*pszDeviceFound), &szN))
|
if (drivers_callbacks_list[uiDriver].list_devices (pnddDevices + (*pszDeviceFound), szDevices - (*pszDeviceFound), &szN))
|
||||||
{
|
{
|
||||||
*pszDeviceFound += szN;
|
*pszDeviceFound += szN;
|
||||||
|
|
Loading…
Add table
Reference in a new issue