mirror of
https://github.com/nfc-tools/libnfc.git
synced 2026-07-20 10:41:50 +00:00
Prefix defines.h, messages.h and types.h headers by "nfc-"
Rename dev_info struct to nfc_device_t Some code cleanup Rename pn531.h/c to pn531_usb.h/c Rename pn533.h/c to pn533_usb.h/c
This commit is contained in:
@@ -33,8 +33,8 @@
|
||||
#include <wintypes.h>
|
||||
#endif
|
||||
|
||||
#include "defines.h"
|
||||
#include "messages.h"
|
||||
#include "nfc-defines.h"
|
||||
#include "nfc-messages.h"
|
||||
|
||||
// WINDOWS: #define IOCTL_CCID_ESCAPE_SCARD_CTL_CODE SCARD_CTL_CODE(3500)
|
||||
#define IOCTL_CCID_ESCAPE_SCARD_CTL_CODE (((0x31) << 16) | ((3500) << 2))
|
||||
@@ -57,7 +57,7 @@ typedef struct {
|
||||
SCARD_IO_REQUEST ioCard;
|
||||
} dev_spec_acr122;
|
||||
|
||||
dev_info* acr122_connect(const nfc_device_desc_t* pndd)
|
||||
nfc_device_t* acr122_connect(const nfc_device_desc_t* pndd)
|
||||
{
|
||||
char* pacReaders[MAX_DEVICES];
|
||||
char acList[256+64*MAX_DEVICES];
|
||||
@@ -66,7 +66,7 @@ dev_info* acr122_connect(const nfc_device_desc_t* pndd)
|
||||
uint32_t uiReaderCount;
|
||||
uint32_t uiReader;
|
||||
uint32_t uiDevIndex;
|
||||
dev_info* pdi;
|
||||
nfc_device_t* pnd;
|
||||
dev_spec_acr122* pdsa;
|
||||
dev_spec_acr122 dsa;
|
||||
char* pcFirmware;
|
||||
@@ -130,7 +130,7 @@ dev_info* acr122_connect(const nfc_device_desc_t* pndd)
|
||||
dsa.ioCard.cbPciLength = sizeof(SCARD_IO_REQUEST);
|
||||
|
||||
// Retrieve the current firmware version
|
||||
pcFirmware = acr122_firmware((dev_info*)&dsa);
|
||||
pcFirmware = acr122_firmware((nfc_device_t*)&dsa);
|
||||
if (strstr(pcFirmware,FIRMWARE_TEXT) != NULL)
|
||||
{
|
||||
// We found a occurence, test if it has the right index
|
||||
@@ -146,15 +146,15 @@ dev_info* acr122_connect(const nfc_device_desc_t* pndd)
|
||||
*pdsa = dsa;
|
||||
|
||||
// Done, we found the reader we are looking for
|
||||
pdi = malloc(sizeof(dev_info));
|
||||
strcpy(pdi->acName,pcFirmware);
|
||||
pdi->ct = CT_PN532;
|
||||
pdi->ds = (dev_spec)pdsa;
|
||||
pdi->bActive = true;
|
||||
pdi->bCrc = true;
|
||||
pdi->bPar = true;
|
||||
pdi->ui8TxBits = 0;
|
||||
return pdi;
|
||||
pnd = malloc(sizeof(nfc_device_t));
|
||||
strcpy(pnd->acName,pcFirmware);
|
||||
pnd->ct = CT_PN532;
|
||||
pnd->ds = (dev_spec)pdsa;
|
||||
pnd->bActive = true;
|
||||
pnd->bCrc = true;
|
||||
pnd->bPar = true;
|
||||
pnd->ui8TxBits = 0;
|
||||
return pnd;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -162,13 +162,13 @@ dev_info* acr122_connect(const nfc_device_desc_t* pndd)
|
||||
return INVALID_DEVICE_INFO;
|
||||
}
|
||||
|
||||
void acr122_disconnect(dev_info* pdi)
|
||||
void acr122_disconnect(nfc_device_t* pnd)
|
||||
{
|
||||
dev_spec_acr122* pdsa = (dev_spec_acr122*)pdi->ds;
|
||||
dev_spec_acr122* pdsa = (dev_spec_acr122*)pnd->ds;
|
||||
SCardDisconnect(pdsa->hCard,SCARD_LEAVE_CARD);
|
||||
SCardReleaseContext(pdsa->hCtx);
|
||||
free(pdsa);
|
||||
free(pdi);
|
||||
free(pnd);
|
||||
}
|
||||
|
||||
bool acr122_transceive(const dev_spec ds, const byte_t* pbtTx, const size_t szTxLen, byte_t* pbtRx, size_t* pszRxLen)
|
||||
|
||||
@@ -27,12 +27,12 @@
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "defines.h"
|
||||
#include "types.h"
|
||||
#include "nfc-defines.h"
|
||||
#include "nfc-types.h"
|
||||
|
||||
// Functions used by developer to handle connection to this device
|
||||
dev_info* acr122_connect(const nfc_device_desc_t* pndd);
|
||||
void acr122_disconnect(dev_info* pdi);
|
||||
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);
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
#include "arygon.h"
|
||||
|
||||
#include "uart.h"
|
||||
#include "messages.h"
|
||||
#include "nfc-messages.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
#define SERIAL_STRING "COM"
|
||||
@@ -72,12 +72,12 @@
|
||||
* @note ARYGON-APDB2UA33 (PN532 + ARYGON µC): 9600,n,8,1
|
||||
*/
|
||||
|
||||
dev_info* arygon_connect(const nfc_device_desc_t* pndd)
|
||||
nfc_device_t* arygon_connect(const nfc_device_desc_t* pndd)
|
||||
{
|
||||
uint32_t uiDevNr;
|
||||
serial_port sp;
|
||||
char acConnect[BUFFER_LENGTH];
|
||||
dev_info* pdi = INVALID_DEVICE_INFO;
|
||||
nfc_device_t* pnd = INVALID_DEVICE_INFO;
|
||||
|
||||
if( pndd == NULL ) {
|
||||
#ifdef DISABLE_SERIAL_AUTOPROBE
|
||||
@@ -122,21 +122,21 @@ dev_info* arygon_connect(const nfc_device_desc_t* pndd)
|
||||
DBG("Successfully connected to: %s",acConnect);
|
||||
|
||||
// We have a connection
|
||||
pdi = malloc(sizeof(dev_info));
|
||||
strcpy(pdi->acName,"ARYGON");
|
||||
pdi->ct = CT_PN532;
|
||||
pdi->ds = (dev_spec)sp;
|
||||
pdi->bActive = true;
|
||||
pdi->bCrc = true;
|
||||
pdi->bPar = true;
|
||||
pdi->ui8TxBits = 0;
|
||||
return pdi;
|
||||
pnd = malloc(sizeof(nfc_device_t));
|
||||
strcpy(pnd->acName,"ARYGON");
|
||||
pnd->ct = CT_PN532;
|
||||
pnd->ds = (dev_spec)sp;
|
||||
pnd->bActive = true;
|
||||
pnd->bCrc = true;
|
||||
pnd->bPar = true;
|
||||
pnd->ui8TxBits = 0;
|
||||
return pnd;
|
||||
}
|
||||
|
||||
void arygon_disconnect(dev_info* pdi)
|
||||
void arygon_disconnect(nfc_device_t* pnd)
|
||||
{
|
||||
uart_close((serial_port)pdi->ds);
|
||||
free(pdi);
|
||||
uart_close((serial_port)pnd->ds);
|
||||
free(pnd);
|
||||
}
|
||||
|
||||
bool arygon_transceive(const dev_spec ds, const byte_t* pbtTx, const size_t szTxLen, byte_t* pbtRx, size_t* pszRxLen)
|
||||
|
||||
@@ -24,12 +24,12 @@
|
||||
#ifndef _LIBNFC_DEV_ARYGON_H_
|
||||
#define _LIBNFC_DEV_ARYGON_H_
|
||||
|
||||
#include "defines.h"
|
||||
#include "types.h"
|
||||
#include "nfc-defines.h"
|
||||
#include "nfc-types.h"
|
||||
|
||||
// Functions used by developer to handle connection to this device
|
||||
dev_info* arygon_connect(const nfc_device_desc_t* pndd);
|
||||
void arygon_disconnect(dev_info* pdi);
|
||||
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);
|
||||
|
||||
@@ -31,9 +31,9 @@ Thanks to d18c7db and Okko for example code
|
||||
#include <usb.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "defines.h"
|
||||
#include "nfc-defines.h"
|
||||
#include "pn531.h"
|
||||
#include "messages.h"
|
||||
#include "nfc-messages.h"
|
||||
|
||||
#define BUFFER_LENGTH 256
|
||||
#define USB_TIMEOUT 30000
|
||||
@@ -80,7 +80,7 @@ static void get_end_points(struct usb_device *dev, dev_spec_pn531* pdsp)
|
||||
}
|
||||
}
|
||||
|
||||
dev_info* pn531_connect(const nfc_device_desc_t* pndd)
|
||||
nfc_device_t* pn531_connect(const nfc_device_desc_t* pndd)
|
||||
{
|
||||
int idvendor = 0x04CC;
|
||||
int idproduct = 0x0531;
|
||||
@@ -88,7 +88,7 @@ dev_info* pn531_connect(const nfc_device_desc_t* pndd)
|
||||
int idproduct_alt = 0x0193;
|
||||
struct usb_bus *bus;
|
||||
struct usb_device *dev;
|
||||
dev_info* pdi = INVALID_DEVICE_INFO;
|
||||
nfc_device_t* pnd = INVALID_DEVICE_INFO;
|
||||
dev_spec_pn531* pdsp;
|
||||
dev_spec_pn531 dsp;
|
||||
uint32_t uiDevIndex;
|
||||
@@ -116,7 +116,7 @@ dev_info* pn531_connect(const nfc_device_desc_t* pndd)
|
||||
(idvendor_alt==dev->descriptor.idVendor && idproduct_alt==dev->descriptor.idProduct))
|
||||
{
|
||||
// Make sure there are 2 endpoints available
|
||||
if (dev->config->interface->altsetting->bNumEndpoints < 2) return pdi;
|
||||
if (dev->config->interface->altsetting->bNumEndpoints < 2) return pnd;
|
||||
|
||||
// Test if we are looking for this device according to the current index
|
||||
if (uiDevIndex != 0)
|
||||
@@ -147,28 +147,28 @@ dev_info* pn531_connect(const nfc_device_desc_t* pndd)
|
||||
// Allocate memory for the device info and specification, fill it and return the info
|
||||
pdsp = malloc(sizeof(dev_spec_pn531));
|
||||
*pdsp = dsp;
|
||||
pdi = malloc(sizeof(dev_info));
|
||||
strcpy(pdi->acName,"PN531USB");
|
||||
pdi->ct = CT_PN531;
|
||||
pdi->ds = (dev_spec)pdsp;
|
||||
pdi->bActive = true;
|
||||
pdi->bCrc = true;
|
||||
pdi->bPar = true;
|
||||
pdi->ui8TxBits = 0;
|
||||
return pdi;
|
||||
pnd = malloc(sizeof(nfc_device_t));
|
||||
strcpy(pnd->acName,"PN531USB");
|
||||
pnd->ct = CT_PN531;
|
||||
pnd->ds = (dev_spec)pdsp;
|
||||
pnd->bActive = true;
|
||||
pnd->bCrc = true;
|
||||
pnd->bPar = true;
|
||||
pnd->ui8TxBits = 0;
|
||||
return pnd;
|
||||
}
|
||||
}
|
||||
}
|
||||
return pdi;
|
||||
return pnd;
|
||||
}
|
||||
|
||||
void pn531_disconnect(dev_info* pdi)
|
||||
void pn531_disconnect(nfc_device_t* pnd)
|
||||
{
|
||||
dev_spec_pn531* pdsp = (dev_spec_pn531*)pdi->ds;
|
||||
dev_spec_pn531* pdsp = (dev_spec_pn531*)pnd->ds;
|
||||
usb_release_interface(pdsp->pudh,0);
|
||||
usb_close(pdsp->pudh);
|
||||
free(pdi->ds);
|
||||
free(pdi);
|
||||
free(pnd->ds);
|
||||
free(pnd);
|
||||
}
|
||||
|
||||
bool pn531_transceive(const dev_spec ds, const byte_t* pbtTx, const size_t szTxLen, byte_t* pbtRx, size_t* pszRxLen)
|
||||
@@ -27,12 +27,12 @@
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "defines.h"
|
||||
#include "types.h"
|
||||
#include "nfc-defines.h"
|
||||
#include "nfc-types.h"
|
||||
|
||||
// Functions used by developer to handle connection to this device
|
||||
dev_info* pn531_connect(const nfc_device_desc_t* pndd);
|
||||
void pn531_disconnect(dev_info* pdi);
|
||||
nfc_device_t* pn531_connect(const nfc_device_desc_t* pndd);
|
||||
void pn531_disconnect(nfc_device_t* pnd);
|
||||
|
||||
// Callback function used by libnfc to transmit commands to the PN53X chip
|
||||
bool pn531_transceive(const dev_spec ds, const byte_t* pbtTx, const size_t szTxLen, byte_t* pbtRx, size_t* pszRxLen);
|
||||
@@ -24,7 +24,7 @@
|
||||
#include "pn532_uart.h"
|
||||
|
||||
#include "uart.h"
|
||||
#include "messages.h"
|
||||
#include "nfc-messages.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
#define SERIAL_STRING "COM"
|
||||
@@ -47,12 +47,12 @@
|
||||
|
||||
#define SERIAL_DEFAULT_PORT_SPEED 115200
|
||||
|
||||
dev_info* pn532_uart_connect(const nfc_device_desc_t* pndd)
|
||||
nfc_device_t* pn532_uart_connect(const nfc_device_desc_t* pndd)
|
||||
{
|
||||
uint32_t uiDevNr;
|
||||
serial_port sp;
|
||||
char acConnect[BUFFER_LENGTH];
|
||||
dev_info* pdi = INVALID_DEVICE_INFO;
|
||||
nfc_device_t* pnd = INVALID_DEVICE_INFO;
|
||||
|
||||
if( pndd == NULL ) {
|
||||
#ifdef DISABLE_SERIAL_AUTOPROBE
|
||||
@@ -114,21 +114,21 @@ dev_info* pn532_uart_connect(const nfc_device_desc_t* pndd)
|
||||
DBG("Successfully connected to: %s",acConnect);
|
||||
|
||||
// We have a connection
|
||||
pdi = malloc(sizeof(dev_info));
|
||||
strcpy(pdi->acName,"PN532_UART");
|
||||
pdi->ct = CT_PN532;
|
||||
pdi->ds = (dev_spec)sp;
|
||||
pdi->bActive = true;
|
||||
pdi->bCrc = true;
|
||||
pdi->bPar = true;
|
||||
pdi->ui8TxBits = 0;
|
||||
return pdi;
|
||||
pnd = malloc(sizeof(nfc_device_t));
|
||||
strcpy(pnd->acName,"PN532_UART");
|
||||
pnd->ct = CT_PN532;
|
||||
pnd->ds = (dev_spec)sp;
|
||||
pnd->bActive = true;
|
||||
pnd->bCrc = true;
|
||||
pnd->bPar = true;
|
||||
pnd->ui8TxBits = 0;
|
||||
return pnd;
|
||||
}
|
||||
|
||||
void pn532_uart_disconnect(dev_info* pdi)
|
||||
void pn532_uart_disconnect(nfc_device_t* pnd)
|
||||
{
|
||||
uart_close((serial_port)pdi->ds);
|
||||
free(pdi);
|
||||
uart_close((serial_port)pnd->ds);
|
||||
free(pnd);
|
||||
}
|
||||
|
||||
bool pn532_uart_transceive(const dev_spec ds, const byte_t* pbtTx, const size_t szTxLen, byte_t* pbtRx, size_t* pszRxLen)
|
||||
|
||||
@@ -24,12 +24,12 @@
|
||||
#ifndef _LIBNFC_DEV_PN532_UART_H_
|
||||
#define _LIBNFC_DEV_PN532_UART_H_
|
||||
|
||||
#include "defines.h"
|
||||
#include "types.h"
|
||||
#include "nfc-defines.h"
|
||||
#include "nfc-types.h"
|
||||
|
||||
// Functions used by developer to handle connection to this device
|
||||
dev_info* pn532_uart_connect(const nfc_device_desc_t* pndd);
|
||||
void pn532_uart_disconnect(dev_info* pdi);
|
||||
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);
|
||||
|
||||
@@ -30,8 +30,8 @@ Thanks to d18c7db and Okko for example code
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "defines.h"
|
||||
#include "messages.h"
|
||||
#include "nfc-defines.h"
|
||||
#include "nfc-messages.h"
|
||||
|
||||
#define BUFFER_LENGTH 256
|
||||
#define USB_TIMEOUT 30000
|
||||
@@ -78,13 +78,13 @@ static void get_end_points(struct usb_device *dev, dev_spec_pn533* pdsp)
|
||||
}
|
||||
}
|
||||
|
||||
dev_info* pn533_connect(const nfc_device_desc_t* pndd)
|
||||
nfc_device_t* pn533_connect(const nfc_device_desc_t* pndd)
|
||||
{
|
||||
int idvendor = 0x04e6;
|
||||
int idproduct = 0x5591;
|
||||
struct usb_bus *bus;
|
||||
struct usb_device *dev;
|
||||
dev_info* pdi = INVALID_DEVICE_INFO;
|
||||
nfc_device_t* pnd = INVALID_DEVICE_INFO;
|
||||
dev_spec_pn533* pdsp;
|
||||
dev_spec_pn533 dsp;
|
||||
uint32_t uiDevIndex;
|
||||
@@ -111,7 +111,7 @@ dev_info* pn533_connect(const nfc_device_desc_t* pndd)
|
||||
if (idvendor==dev->descriptor.idVendor && idproduct==dev->descriptor.idProduct)
|
||||
{
|
||||
// Make sure there are 2 endpoints available
|
||||
if (dev->config->interface->altsetting->bNumEndpoints < 2) return pdi;
|
||||
if (dev->config->interface->altsetting->bNumEndpoints < 2) return pnd;
|
||||
|
||||
// Test if we are looking for this device according to the current index
|
||||
if (uiDevIndex != 0)
|
||||
@@ -142,28 +142,28 @@ dev_info* pn533_connect(const nfc_device_desc_t* pndd)
|
||||
// Allocate memory for the device info and specification, fill it and return the info
|
||||
pdsp = malloc(sizeof(dev_spec_pn533));
|
||||
*pdsp = dsp;
|
||||
pdi = malloc(sizeof(dev_info));
|
||||
strcpy(pdi->acName,"PN533USB");
|
||||
pdi->ct = CT_PN533;
|
||||
pdi->ds = (dev_spec)pdsp;
|
||||
pdi->bActive = true;
|
||||
pdi->bCrc = true;
|
||||
pdi->bPar = true;
|
||||
pdi->ui8TxBits = 0;
|
||||
return pdi;
|
||||
pnd = malloc(sizeof(nfc_device_t));
|
||||
strcpy(pnd->acName,"PN533USB");
|
||||
pnd->ct = CT_PN533;
|
||||
pnd->ds = (dev_spec)pdsp;
|
||||
pnd->bActive = true;
|
||||
pnd->bCrc = true;
|
||||
pnd->bPar = true;
|
||||
pnd->ui8TxBits = 0;
|
||||
return pnd;
|
||||
}
|
||||
}
|
||||
}
|
||||
return pdi;
|
||||
return pnd;
|
||||
}
|
||||
|
||||
void pn533_disconnect(dev_info* pdi)
|
||||
void pn533_disconnect(nfc_device_t* pnd)
|
||||
{
|
||||
dev_spec_pn533* pdsp = (dev_spec_pn533*)pdi->ds;
|
||||
dev_spec_pn533* pdsp = (dev_spec_pn533*)pnd->ds;
|
||||
usb_release_interface(pdsp->pudh,0);
|
||||
usb_close(pdsp->pudh);
|
||||
free(pdi->ds);
|
||||
free(pdi);
|
||||
free(pnd->ds);
|
||||
free(pnd);
|
||||
}
|
||||
|
||||
bool pn533_transceive(const dev_spec ds, const byte_t* pbtTx, const size_t szTxLen, byte_t* pbtRx, size_t* pszRxLen)
|
||||
@@ -24,12 +24,12 @@
|
||||
#ifndef _LIBNFC_DEV_PN533_H_
|
||||
#define _LIBNFC_DEV_PN533_H_
|
||||
|
||||
#include "defines.h"
|
||||
#include "types.h"
|
||||
#include "nfc-defines.h"
|
||||
#include "nfc-types.h"
|
||||
|
||||
// Functions used by developer to handle connection to this device
|
||||
dev_info* pn533_connect(const nfc_device_desc_t* pndd);
|
||||
void pn533_disconnect(dev_info* pdi);
|
||||
nfc_device_t* pn533_connect(const nfc_device_desc_t* pndd);
|
||||
void pn533_disconnect(nfc_device_t* pnd);
|
||||
|
||||
// Callback function used by libnfc to transmit commands to the PN53X chip
|
||||
bool pn533_transceive(const dev_spec ds, const byte_t* pbtTx, const size_t szTxLen, byte_t* pbtRx, size_t* pszRxLen);
|
||||
Reference in New Issue
Block a user