Rename chip_type to nfc_chip_t.

Rename dev_spec to nfc_device_spec_t.
Update configure.ac and autotools related files.
This commit is contained in:
Romuald Conty
2009-11-18 10:52:13 +00:00
parent 8a579c3aab
commit 2a0ff6c5d0
15 changed files with 713 additions and 441 deletions

View File

@@ -59,7 +59,7 @@ typedef struct {
SCARDCONTEXT hCtx;
SCARDHANDLE hCard;
SCARD_IO_REQUEST ioCard;
} dev_spec_acr122;
} acr122_spec_t;
nfc_device_t* acr122_connect(const nfc_device_desc_t* pndd)
{
@@ -71,18 +71,18 @@ nfc_device_t* acr122_connect(const nfc_device_desc_t* pndd)
uint32_t uiReader;
uint32_t uiDevIndex;
nfc_device_t* pnd;
dev_spec_acr122* pdsa;
dev_spec_acr122 dsa;
acr122_spec_t* pas;
acr122_spec_t as;
char* pcFirmware;
// Clear the reader list
memset(acList,0x00,szListLen);
// Test if context succeeded
if (SCardEstablishContext(SCARD_SCOPE_USER,NULL,NULL,&(dsa.hCtx)) != SCARD_S_SUCCESS) return INVALID_DEVICE_INFO;
if (SCardEstablishContext(SCARD_SCOPE_USER,NULL,NULL,&(as.hCtx)) != SCARD_S_SUCCESS) return INVALID_DEVICE_INFO;
// Retrieve the string array of all available pcsc readers
if (SCardListReaders(dsa.hCtx,NULL,acList,(void*)&szListLen) != SCARD_S_SUCCESS) return INVALID_DEVICE_INFO;
if (SCardListReaders(as.hCtx,NULL,acList,(void*)&szListLen) != SCARD_S_SUCCESS) return INVALID_DEVICE_INFO;
DBG("PCSC reports following device(s):");
DBG("- %s",acList);
@@ -121,20 +121,20 @@ nfc_device_t* acr122_connect(const nfc_device_desc_t* pndd)
for (uiReader=0; uiReader<uiReaderCount; uiReader++)
{
// Test if we were able to connect to the "emulator" card
if (SCardConnect(dsa.hCtx,pacReaders[uiReader],SCARD_SHARE_EXCLUSIVE,SCARD_PROTOCOL_T0 | SCARD_PROTOCOL_T1,&(dsa.hCard),(void*)&(dsa.ioCard.dwProtocol)) != SCARD_S_SUCCESS)
if (SCardConnect(as.hCtx,pacReaders[uiReader],SCARD_SHARE_EXCLUSIVE,SCARD_PROTOCOL_T0 | SCARD_PROTOCOL_T1,&(as.hCard),(void*)&(as.ioCard.dwProtocol)) != SCARD_S_SUCCESS)
{
// Connect to ACR122 firmware version >2.0
if (SCardConnect(dsa.hCtx,pacReaders[uiReader],SCARD_SHARE_DIRECT,0,&(dsa.hCard),(void*)&(dsa.ioCard.dwProtocol)) != SCARD_S_SUCCESS)
if (SCardConnect(as.hCtx,pacReaders[uiReader],SCARD_SHARE_DIRECT,0,&(as.hCard),(void*)&(as.ioCard.dwProtocol)) != SCARD_S_SUCCESS)
{
// We can not connect to this device, we will just ignore it
continue;
}
}
// Configure I/O settings for card communication
dsa.ioCard.cbPciLength = sizeof(SCARD_IO_REQUEST);
as.ioCard.cbPciLength = sizeof(SCARD_IO_REQUEST);
// Retrieve the current firmware version
pcFirmware = acr122_firmware((nfc_device_t*)&dsa);
pcFirmware = acr122_firmware((nfc_device_t*)&as);
if (strstr(pcFirmware,FIRMWARE_TEXT) != NULL)
{
// We found a occurence, test if it has the right index
@@ -146,14 +146,14 @@ nfc_device_t* acr122_connect(const nfc_device_desc_t* pndd)
}
// Allocate memory and store the device specification
pdsa = malloc(sizeof(dev_spec_acr122));
*pdsa = dsa;
pas = malloc(sizeof(acr122_spec_t));
*pas = as;
// Done, we found the reader we are looking for
pnd = malloc(sizeof(nfc_device_t));
strcpy(pnd->acName,pcFirmware);
pnd->ct = CT_PN532;
pnd->ds = (dev_spec)pdsa;
pnd->nc = NC_PN532;
pnd->nds = (nfc_device_spec_t)pas;
pnd->bActive = true;
pnd->bCrc = true;
pnd->bPar = true;
@@ -168,21 +168,21 @@ nfc_device_t* acr122_connect(const nfc_device_desc_t* pndd)
void acr122_disconnect(nfc_device_t* pnd)
{
dev_spec_acr122* pdsa = (dev_spec_acr122*)pnd->ds;
SCardDisconnect(pdsa->hCard,SCARD_LEAVE_CARD);
SCardReleaseContext(pdsa->hCtx);
free(pdsa);
acr122_spec_t* pas = (acr122_spec_t*)pnd->nds;
SCardDisconnect(pas->hCard,SCARD_LEAVE_CARD);
SCardReleaseContext(pas->hCtx);
free(pas);
free(pnd);
}
bool acr122_transceive(const dev_spec ds, const byte_t* pbtTx, const size_t szTxLen, byte_t* pbtRx, size_t* pszRxLen)
bool acr122_transceive(const nfc_device_spec_t nds, const byte_t* pbtTx, const size_t szTxLen, byte_t* pbtRx, size_t* pszRxLen)
{
byte_t abtRxCmd[5] = { 0xFF,0xC0,0x00,0x00 };
size_t szRxCmdLen = sizeof(abtRxCmd);
byte_t abtRxBuf[ACR122_RESPONSE_LEN];
size_t szRxBufLen;
byte_t abtTxBuf[ACR122_WRAP_LEN+ACR122_COMMAND_LEN] = { 0xFF, 0x00, 0x00, 0x00 };
dev_spec_acr122* pdsa = (dev_spec_acr122*)ds;
acr122_spec_t* pas = (acr122_spec_t*)nds;
// Make sure the command does not overflow the send buffer
if (szTxLen > ACR122_COMMAND_LEN) return false;
@@ -198,14 +198,14 @@ bool acr122_transceive(const dev_spec ds, const byte_t* pbtTx, const size_t szTx
print_hex(abtTxBuf,szTxLen+5);
#endif
if (pdsa->ioCard.dwProtocol == SCARD_PROTOCOL_UNDEFINED)
if (pas->ioCard.dwProtocol == SCARD_PROTOCOL_UNDEFINED)
{
if (SCardControl(pdsa->hCard,IOCTL_CCID_ESCAPE_SCARD_CTL_CODE,abtTxBuf,szTxLen+5,abtRxBuf,szRxBufLen,(void*)&szRxBufLen) != SCARD_S_SUCCESS) return false;
if (SCardControl(pas->hCard,IOCTL_CCID_ESCAPE_SCARD_CTL_CODE,abtTxBuf,szTxLen+5,abtRxBuf,szRxBufLen,(void*)&szRxBufLen) != SCARD_S_SUCCESS) return false;
} else {
if (SCardTransmit(pdsa->hCard,&(pdsa->ioCard),abtTxBuf,szTxLen+5,NULL,abtRxBuf,(void*)&szRxBufLen) != SCARD_S_SUCCESS) return false;
if (SCardTransmit(pas->hCard,&(pas->ioCard),abtTxBuf,szTxLen+5,NULL,abtRxBuf,(void*)&szRxBufLen) != SCARD_S_SUCCESS) return false;
}
if (pdsa->ioCard.dwProtocol == SCARD_PROTOCOL_T0)
if (pas->ioCard.dwProtocol == SCARD_PROTOCOL_T0)
{
// Make sure we received the byte-count we expected
if (szRxBufLen != 2) return false;
@@ -216,7 +216,7 @@ bool acr122_transceive(const dev_spec ds, const byte_t* pbtTx, const size_t szTx
// Retrieve the response bytes
abtRxCmd[4] = abtRxBuf[1];
szRxBufLen = sizeof(abtRxBuf);
if (SCardTransmit(pdsa->hCard,&(pdsa->ioCard),abtRxCmd,szRxCmdLen,NULL,abtRxBuf,(void*)&szRxBufLen) != SCARD_S_SUCCESS) return false;
if (SCardTransmit(pas->hCard,&(pas->ioCard),abtRxCmd,szRxCmdLen,NULL,abtRxBuf,(void*)&szRxBufLen) != SCARD_S_SUCCESS) return false;
}
#ifdef DEBUG
@@ -237,20 +237,20 @@ bool acr122_transceive(const dev_spec ds, const byte_t* pbtTx, const size_t szTx
return true;
}
char* acr122_firmware(const dev_spec ds)
char* acr122_firmware(const nfc_device_spec_t nds)
{
byte_t abtGetFw[5] = { 0xFF,0x00,0x48,0x00,0x00 };
uint32_t uiResult;
dev_spec_acr122* pdsa = (dev_spec_acr122*)ds;
acr122_spec_t* pas = (acr122_spec_t*)nds;
static char abtFw[11];
size_t szFwLen = sizeof(abtFw);
memset(abtFw,0x00,szFwLen);
if (pdsa->ioCard.dwProtocol == SCARD_PROTOCOL_UNDEFINED)
if (pas->ioCard.dwProtocol == SCARD_PROTOCOL_UNDEFINED)
{
uiResult = SCardControl(pdsa->hCard,IOCTL_CCID_ESCAPE_SCARD_CTL_CODE,abtGetFw,sizeof(abtGetFw),abtFw,szFwLen,(void*)&szFwLen);
uiResult = SCardControl(pas->hCard,IOCTL_CCID_ESCAPE_SCARD_CTL_CODE,abtGetFw,sizeof(abtGetFw),abtFw,szFwLen,(void*)&szFwLen);
} else {
uiResult = SCardTransmit(pdsa->hCard,&(pdsa->ioCard),abtGetFw,sizeof(abtGetFw),NULL,(byte_t*)abtFw,(void*)&szFwLen);
uiResult = SCardTransmit(pas->hCard,&(pas->ioCard),abtGetFw,sizeof(abtGetFw),NULL,(byte_t*)abtFw,(void*)&szFwLen);
}
#ifdef DEBUG
@@ -263,17 +263,17 @@ char* acr122_firmware(const dev_spec ds)
return abtFw;
}
bool acr122_led_red(const dev_spec ds, bool bOn)
bool acr122_led_red(const nfc_device_spec_t nds, bool bOn)
{
byte_t abtLed[9] = { 0xFF,0x00,0x40,0x05,0x04,0x00,0x00,0x00,0x00 };
dev_spec_acr122* pdsa = (dev_spec_acr122*)ds;
acr122_spec_t* pas = (acr122_spec_t*)nds;
byte_t abtBuf[2];
size_t szBufLen = sizeof(abtBuf);
if (pdsa->ioCard.dwProtocol == SCARD_PROTOCOL_UNDEFINED)
if (pas->ioCard.dwProtocol == SCARD_PROTOCOL_UNDEFINED)
{
return (SCardControl(pdsa->hCard,IOCTL_CCID_ESCAPE_SCARD_CTL_CODE,abtLed,sizeof(abtLed),abtBuf,szBufLen,(void*)&szBufLen) == SCARD_S_SUCCESS);
return (SCardControl(pas->hCard,IOCTL_CCID_ESCAPE_SCARD_CTL_CODE,abtLed,sizeof(abtLed),abtBuf,szBufLen,(void*)&szBufLen) == SCARD_S_SUCCESS);
} else {
return (SCardTransmit(pdsa->hCard,&(pdsa->ioCard),abtLed,sizeof(abtLed),NULL,(byte_t*)abtBuf,(void*)&szBufLen) == SCARD_S_SUCCESS);
return (SCardTransmit(pas->hCard,&(pas->ioCard),abtLed,sizeof(abtLed),NULL,(byte_t*)abtBuf,(void*)&szBufLen) == SCARD_S_SUCCESS);
}
}

View File

@@ -35,11 +35,11 @@ nfc_device_t* acr122_connect(const nfc_device_desc_t* pndd);
void acr122_disconnect(nfc_device_t* pnd);
// Callback function used by libnfc to transmit commands to the PN53X chip
bool acr122_transceive(const dev_spec ds, const byte_t* pbtTx, const size_t szTxLen, byte_t* pbtRx, size_t* pszRxLen);
bool acr122_transceive(const nfc_device_spec_t nds, const byte_t* pbtTx, const size_t szTxLen, byte_t* pbtRx, size_t* pszRxLen);
// Various additional features this device supports
char* acr122_firmware(const dev_spec ds);
bool acr122_led_red(const dev_spec ds, bool bOn);
char* acr122_firmware(const nfc_device_spec_t nds);
bool acr122_led_red(const nfc_device_spec_t nds, bool bOn);
#endif // _LIBNFC_DEV_ACR122_H_

View File

@@ -127,8 +127,8 @@ nfc_device_t* arygon_connect(const nfc_device_desc_t* pndd)
// We have a connection
pnd = malloc(sizeof(nfc_device_t));
strcpy(pnd->acName,"ARYGON");
pnd->ct = CT_PN532;
pnd->ds = (dev_spec)sp;
pnd->nc = NC_PN532;
pnd->nds = (nfc_device_spec_t)sp;
pnd->bActive = true;
pnd->bCrc = true;
pnd->bPar = true;
@@ -138,11 +138,11 @@ nfc_device_t* arygon_connect(const nfc_device_desc_t* pndd)
void arygon_disconnect(nfc_device_t* pnd)
{
uart_close((serial_port)pnd->ds);
uart_close((serial_port)pnd->nds);
free(pnd);
}
bool arygon_transceive(const dev_spec ds, const byte_t* pbtTx, const size_t szTxLen, byte_t* pbtRx, size_t* pszRxLen)
bool arygon_transceive(const nfc_device_spec_t nds, const byte_t* pbtTx, const size_t szTxLen, byte_t* pbtRx, size_t* pszRxLen)
{
byte_t abtTxBuf[BUFFER_LENGTH] = { DEV_ARYGON_PROTOCOL_TAMA, 0x00, 0x00, 0xff }; // Every packet must start with "00 00 ff"
byte_t abtRxBuf[BUFFER_LENGTH];
@@ -170,7 +170,7 @@ bool arygon_transceive(const dev_spec ds, const byte_t* pbtTx, const size_t szTx
printf(" TX: ");
print_hex(abtTxBuf,szTxLen+8);
#endif
if (!uart_send((serial_port)ds,abtTxBuf,szTxLen+8)) {
if (!uart_send((serial_port)nds,abtTxBuf,szTxLen+8)) {
ERR("Unable to transmit data. (TX)");
return false;
}
@@ -190,7 +190,7 @@ bool arygon_transceive(const dev_spec ds, const byte_t* pbtTx, const size_t szTx
* For more information, see Issue 23 on development site : http://code.google.com/p/libnfc/issues/detail?id=23
*/
if (!uart_receive((serial_port)ds,abtRxBuf,&szRxBufLen)) {
if (!uart_receive((serial_port)nds,abtRxBuf,&szRxBufLen)) {
ERR("Unable to receive data. (RX)");
return false;
}

View File

@@ -32,7 +32,7 @@ nfc_device_t* arygon_connect(const nfc_device_desc_t* pndd);
void arygon_disconnect(nfc_device_t* pnd);
// Callback function used by libnfc to transmit commands to the PN53X chip
bool arygon_transceive(const dev_spec ds, const byte_t* pbtTx, const size_t szTxLen, byte_t* pbtRx, size_t* pszRxLen);
bool arygon_transceive(const nfc_device_spec_t nds, const byte_t* pbtTx, const size_t szTxLen, byte_t* pbtRx, size_t* pszRxLen);
#endif // _LIBNFC_DEV_ARYGON_H_

View File

@@ -44,10 +44,10 @@ typedef struct {
usb_dev_handle* pudh;
uint32_t uiEndPointIn;
uint32_t uiEndPointOut;
} dev_spec_pn531_usb;
} usb_spec_t;
// Find transfer endpoints for bulk transfers
static void get_end_points(struct usb_device *dev, dev_spec_pn531_usb* pdsp)
static void get_end_points(struct usb_device *dev, usb_spec_t* pus)
{
uint32_t uiIndex;
uint32_t uiEndPoint;
@@ -68,7 +68,7 @@ static void get_end_points(struct usb_device *dev, dev_spec_pn531_usb* pdsp)
#ifdef DEBUG
printf("Bulk endpoint in : 0x%02X\n", uiEndPoint);
#endif
pdsp->uiEndPointIn = uiEndPoint;
pus->uiEndPointIn = uiEndPoint;
}
// Test if we dealing with a bulk OUT endpoint
@@ -77,7 +77,7 @@ static void get_end_points(struct usb_device *dev, dev_spec_pn531_usb* pdsp)
#ifdef DEBUG
printf("Bulk endpoint in : 0x%02X\n", uiEndPoint);
#endif
pdsp->uiEndPointOut = uiEndPoint;
pus->uiEndPointOut = uiEndPoint;
}
}
}
@@ -91,13 +91,13 @@ nfc_device_t* pn531_usb_connect(const nfc_device_desc_t* pndd)
struct usb_bus *bus;
struct usb_device *dev;
nfc_device_t* pnd = INVALID_DEVICE_INFO;
dev_spec_pn531_usb* pdsp;
dev_spec_pn531_usb dsp;
usb_spec_t* pus;
usb_spec_t us;
uint32_t uiDevIndex;
dsp.uiEndPointIn = 0;
dsp.uiEndPointOut = 0;
dsp.pudh = NULL;
us.uiEndPointIn = 0;
us.uiEndPointOut = 0;
us.pudh = NULL;
usb_init();
if (usb_find_busses() < 0) return INVALID_DEVICE_INFO;
@@ -130,29 +130,29 @@ nfc_device_t* pn531_usb_connect(const nfc_device_desc_t* pndd)
DBG("Found PN531 device");
// Open the PN531 USB device
dsp.pudh = usb_open(dev);
us.pudh = usb_open(dev);
get_end_points(dev,&dsp);
if(usb_set_configuration(dsp.pudh,1) < 0)
get_end_points(dev,&us);
if(usb_set_configuration(us.pudh,1) < 0)
{
DBG("Set config failed");
usb_close(dsp.pudh);
usb_close(us.pudh);
return INVALID_DEVICE_INFO;
}
if(usb_claim_interface(dsp.pudh,0) < 0)
if(usb_claim_interface(us.pudh,0) < 0)
{
DBG("Can't claim interface");
usb_close(dsp.pudh);
usb_close(us.pudh);
return INVALID_DEVICE_INFO;
}
// Allocate memory for the device info and specification, fill it and return the info
pdsp = malloc(sizeof(dev_spec_pn531_usb));
*pdsp = dsp;
pus = malloc(sizeof(usb_spec_t));
*pus = us;
pnd = malloc(sizeof(nfc_device_t));
strcpy(pnd->acName,"PN531USB");
pnd->ct = CT_PN531;
pnd->ds = (dev_spec)pdsp;
pnd->nc = NC_PN531;
pnd->nds = (nfc_device_spec_t)pus;
pnd->bActive = true;
pnd->bCrc = true;
pnd->bPar = true;
@@ -166,20 +166,20 @@ nfc_device_t* pn531_usb_connect(const nfc_device_desc_t* pndd)
void pn531_usb_disconnect(nfc_device_t* pnd)
{
dev_spec_pn531_usb* pdsp = (dev_spec_pn531_usb*)pnd->ds;
usb_release_interface(pdsp->pudh,0);
usb_close(pdsp->pudh);
free(pnd->ds);
usb_spec_t* pus = (usb_spec_t*)pnd->nds;
usb_release_interface(pus->pudh,0);
usb_close(pus->pudh);
free(pnd->nds);
free(pnd);
}
bool pn531_usb_transceive(const dev_spec ds, const byte_t* pbtTx, const size_t szTxLen, byte_t* pbtRx, size_t* pszRxLen)
bool pn531_usb_transceive(const nfc_device_spec_t nds, const byte_t* pbtTx, const size_t szTxLen, byte_t* pbtRx, size_t* pszRxLen)
{
size_t uiPos = 0;
int ret = 0;
byte_t abtTx[BUFFER_LENGTH] = { 0x00, 0x00, 0xff }; // Every packet must start with "00 00 ff"
byte_t abtRx[BUFFER_LENGTH];
dev_spec_pn531_usb* pdsp = (dev_spec_pn531_usb*)ds;
usb_spec_t* pus = (usb_spec_t*)nds;
// Packet length = data length (len) + checksum (1) + end of stream marker (1)
abtTx[3] = szTxLen;
@@ -203,7 +203,7 @@ bool pn531_usb_transceive(const dev_spec ds, const byte_t* pbtTx, const size_t s
print_hex(abtTx,szTxLen+7);
#endif
ret = usb_bulk_write(pdsp->pudh, pdsp->uiEndPointOut, (char*)abtTx, szTxLen+7, USB_TIMEOUT);
ret = usb_bulk_write(pus->pudh, pus->uiEndPointOut, (char*)abtTx, szTxLen+7, USB_TIMEOUT);
if( ret < 0 )
{
#ifdef DEBUG
@@ -212,7 +212,7 @@ bool pn531_usb_transceive(const dev_spec ds, const byte_t* pbtTx, const size_t s
return false;
}
ret = usb_bulk_read(pdsp->pudh, pdsp->uiEndPointIn, (char*)abtRx, BUFFER_LENGTH, USB_TIMEOUT);
ret = usb_bulk_read(pus->pudh, pus->uiEndPointIn, (char*)abtRx, BUFFER_LENGTH, USB_TIMEOUT);
if( ret < 0 )
{
#ifdef DEBUG
@@ -228,7 +228,7 @@ bool pn531_usb_transceive(const dev_spec ds, const byte_t* pbtTx, const size_t s
if( ret == 6 )
{
ret = usb_bulk_read(pdsp->pudh, pdsp->uiEndPointIn, (char*)abtRx, BUFFER_LENGTH, USB_TIMEOUT);
ret = usb_bulk_read(pus->pudh, pus->uiEndPointIn, (char*)abtRx, BUFFER_LENGTH, USB_TIMEOUT);
if( ret < 0 )
{
#ifdef DEBUG

View File

@@ -35,7 +35,7 @@ nfc_device_t* pn531_usb_connect(const nfc_device_desc_t* pndd);
void pn531_usb_disconnect(nfc_device_t* pnd);
// Callback function used by libnfc to transmit commands to the PN53X chip
bool pn531_usb_transceive(const dev_spec ds, const byte_t* pbtTx, const size_t szTxLen, byte_t* pbtRx, size_t* pszRxLen);
bool pn531_usb_transceive(const nfc_device_spec_t nds, const byte_t* pbtTx, const size_t szTxLen, byte_t* pbtRx, size_t* pszRxLen);
#endif // _LIBNFC_DEV_PN531_H_

View File

@@ -120,8 +120,8 @@ nfc_device_t* pn532_uart_connect(const nfc_device_desc_t* pndd)
// We have a connection
pnd = malloc(sizeof(nfc_device_t));
strcpy(pnd->acName,"PN532_UART");
pnd->ct = CT_PN532;
pnd->ds = (dev_spec)sp;
pnd->nc = NC_PN532;
pnd->nds = (nfc_device_spec_t)sp;
pnd->bActive = true;
pnd->bCrc = true;
pnd->bPar = true;
@@ -131,11 +131,11 @@ nfc_device_t* pn532_uart_connect(const nfc_device_desc_t* pndd)
void pn532_uart_disconnect(nfc_device_t* pnd)
{
uart_close((serial_port)pnd->ds);
uart_close((serial_port)pnd->nds);
free(pnd);
}
bool pn532_uart_transceive(const dev_spec ds, const byte_t* pbtTx, const size_t szTxLen, byte_t* pbtRx, size_t* pszRxLen)
bool pn532_uart_transceive(const nfc_device_spec_t nds, const byte_t* pbtTx, const size_t szTxLen, byte_t* pbtRx, size_t* pszRxLen)
{
byte_t abtTxBuf[BUFFER_LENGTH] = { 0x00, 0x00, 0xff }; // Every packet must start with "00 00 ff"
byte_t abtRxBuf[BUFFER_LENGTH];
@@ -163,7 +163,7 @@ bool pn532_uart_transceive(const dev_spec ds, const byte_t* pbtTx, const size_t
printf(" TX: ");
print_hex(abtTxBuf,szTxLen+7);
#endif
if (!uart_send((serial_port)ds,abtTxBuf,szTxLen+7)) {
if (!uart_send((serial_port)nds,abtTxBuf,szTxLen+7)) {
ERR("Unable to transmit data. (TX)");
return false;
}
@@ -178,7 +178,7 @@ bool pn532_uart_transceive(const dev_spec ds, const byte_t* pbtTx, const size_t
*/
delay_ms(30);
if (!uart_receive((serial_port)ds,abtRxBuf,&szRxBufLen)) {
if (!uart_receive((serial_port)nds,abtRxBuf,&szRxBufLen)) {
ERR("Unable to receive data. (RX)");
return false;
}

View File

@@ -32,7 +32,7 @@ nfc_device_t* pn532_uart_connect(const nfc_device_desc_t* pndd);
void pn532_uart_disconnect(nfc_device_t* pnd);
// Callback function used by libnfc to transmit commands to the PN53X chip
bool pn532_uart_transceive(const dev_spec ds, const byte_t* pbtTx, const size_t szTxLen, byte_t* pbtRx, size_t* pszRxLen);
bool pn532_uart_transceive(const nfc_device_spec_t nds, const byte_t* pbtTx, const size_t szTxLen, byte_t* pbtRx, size_t* pszRxLen);
#endif // _LIBNFC_DEV_PN532_UART_H_

View File

@@ -43,10 +43,10 @@ typedef struct {
usb_dev_handle* pudh;
uint32_t uiEndPointIn;
uint32_t uiEndPointOut;
} dev_spec_pn533_usb;
} usb_spec_t;
// Find transfer endpoints for bulk transfers
static void get_end_points(struct usb_device *dev, dev_spec_pn533_usb* pdsp)
static void get_end_points(struct usb_device *dev, usb_spec_t* pus)
{
uint32_t uiIndex;
uint32_t uiEndPoint;
@@ -67,7 +67,7 @@ static void get_end_points(struct usb_device *dev, dev_spec_pn533_usb* pdsp)
#ifdef DEBUG
printf("Bulk endpoint in : 0x%02X\n", uiEndPoint);
#endif
pdsp->uiEndPointIn = uiEndPoint;
pus->uiEndPointIn = uiEndPoint;
}
// Test if we dealing with a bulk OUT endpoint
@@ -76,7 +76,7 @@ static void get_end_points(struct usb_device *dev, dev_spec_pn533_usb* pdsp)
#ifdef DEBUG
printf("Bulk endpoint in : 0x%02X\n", uiEndPoint);
#endif
pdsp->uiEndPointOut = uiEndPoint;
pus->uiEndPointOut = uiEndPoint;
}
}
}
@@ -88,13 +88,13 @@ nfc_device_t* pn533_usb_connect(const nfc_device_desc_t* pndd)
struct usb_bus *bus;
struct usb_device *dev;
nfc_device_t* pnd = INVALID_DEVICE_INFO;
dev_spec_pn533_usb* pdsp;
dev_spec_pn533_usb dsp;
usb_spec_t* pus;
usb_spec_t us;
uint32_t uiDevIndex;
dsp.uiEndPointIn = 0;
dsp.uiEndPointOut = 0;
dsp.pudh = NULL;
us.uiEndPointIn = 0;
us.uiEndPointOut = 0;
us.pudh = NULL;
usb_init();
if (usb_find_busses() < 0) return INVALID_DEVICE_INFO;
@@ -126,29 +126,29 @@ nfc_device_t* pn533_usb_connect(const nfc_device_desc_t* pndd)
DBG("Found PN533 device");
// Open the PN533 USB device
dsp.pudh = usb_open(dev);
us.pudh = usb_open(dev);
get_end_points(dev,&dsp);
if(usb_set_configuration(dsp.pudh,1) < 0)
get_end_points(dev,&us);
if(usb_set_configuration(us.pudh,1) < 0)
{
DBG("Setting config failed");
usb_close(dsp.pudh);
usb_close(us.pudh);
return INVALID_DEVICE_INFO;
}
if(usb_claim_interface(dsp.pudh,0) < 0)
if(usb_claim_interface(us.pudh,0) < 0)
{
DBG("Can't claim interface");
usb_close(dsp.pudh);
usb_close(us.pudh);
return INVALID_DEVICE_INFO;
}
// Allocate memory for the device info and specification, fill it and return the info
pdsp = malloc(sizeof(dev_spec_pn533_usb));
*pdsp = dsp;
pus = malloc(sizeof(usb_spec_t));
*pus = us;
pnd = malloc(sizeof(nfc_device_t));
strcpy(pnd->acName,"PN533USB");
pnd->ct = CT_PN533;
pnd->ds = (dev_spec)pdsp;
pnd->nc = NC_PN533;
pnd->nds = (nfc_device_spec_t)pus;
pnd->bActive = true;
pnd->bCrc = true;
pnd->bPar = true;
@@ -162,20 +162,20 @@ nfc_device_t* pn533_usb_connect(const nfc_device_desc_t* pndd)
void pn533_usb_disconnect(nfc_device_t* pnd)
{
dev_spec_pn533_usb* pdsp = (dev_spec_pn533_usb*)pnd->ds;
usb_release_interface(pdsp->pudh,0);
usb_close(pdsp->pudh);
free(pnd->ds);
usb_spec_t* pus = (usb_spec_t*)pnd->nds;
usb_release_interface(pus->pudh,0);
usb_close(pus->pudh);
free(pnd->nds);
free(pnd);
}
bool pn533_usb_transceive(const dev_spec ds, const byte_t* pbtTx, const size_t szTxLen, byte_t* pbtRx, size_t* pszRxLen)
bool pn533_usb_transceive(const nfc_device_spec_t nds, const byte_t* pbtTx, const size_t szTxLen, byte_t* pbtRx, size_t* pszRxLen)
{
size_t uiPos = 0;
int ret = 0;
byte_t abtTx[BUFFER_LENGTH] = { 0x00, 0x00, 0xff }; // Every packet must start with "00 00 ff"
byte_t abtRx[BUFFER_LENGTH];
dev_spec_pn533_usb* pdsp = (dev_spec_pn533_usb*)ds;
usb_spec_t* pus = (usb_spec_t*)nds;
// Packet length = data length (len) + checksum (1) + end of stream marker (1)
abtTx[3] = szTxLen;
@@ -199,7 +199,7 @@ bool pn533_usb_transceive(const dev_spec ds, const byte_t* pbtTx, const size_t s
print_hex(abtTx,szTxLen+7);
#endif
ret = usb_bulk_write(pdsp->pudh, pdsp->uiEndPointOut, (char*)abtTx, szTxLen+7, USB_TIMEOUT);
ret = usb_bulk_write(pus->pudh, pus->uiEndPointOut, (char*)abtTx, szTxLen+7, USB_TIMEOUT);
if( ret < 0 )
{
#ifdef DEBUG
@@ -208,7 +208,7 @@ bool pn533_usb_transceive(const dev_spec ds, const byte_t* pbtTx, const size_t s
return false;
}
ret = usb_bulk_read(pdsp->pudh, pdsp->uiEndPointIn, (char*)abtRx, BUFFER_LENGTH, USB_TIMEOUT);
ret = usb_bulk_read(pus->pudh, pus->uiEndPointIn, (char*)abtRx, BUFFER_LENGTH, USB_TIMEOUT);
if( ret < 0 )
{
#ifdef DEBUG
@@ -224,7 +224,7 @@ bool pn533_usb_transceive(const dev_spec ds, const byte_t* pbtTx, const size_t s
if( ret == 6 )
{
ret = usb_bulk_read(pdsp->pudh, pdsp->uiEndPointIn, (char*)abtRx, BUFFER_LENGTH, USB_TIMEOUT);
ret = usb_bulk_read(pus->pudh, pus->uiEndPointIn, (char*)abtRx, BUFFER_LENGTH, USB_TIMEOUT);
if( ret < 0 )
{
#ifdef DEBUG

View File

@@ -32,7 +32,7 @@ nfc_device_t* pn533_usb_connect(const nfc_device_desc_t* pndd);
void pn533_usb_disconnect(nfc_device_t* pnd);
// Callback function used by libnfc to transmit commands to the PN53X chip
bool pn533_usb_transceive(const dev_spec ds, const byte_t* pbtTx, const size_t szTxLen, byte_t* pbtRx, size_t* pszRxLen);
bool pn533_usb_transceive(const nfc_device_spec_t nds, const byte_t* pbtTx, const size_t szTxLen, byte_t* pbtRx, size_t* pszRxLen);
#endif // _LIBNFC_DEV_PN533_H_