Massive code clean up: (Fixes Issue 161)

- Remove typedef from internal structs
- Remove _t suffix from types
- Fix tests using connstrings
This commit is contained in:
Audrey Diacre
2011-11-23 15:55:40 +00:00
parent 55daa29a7c
commit c718fafee7
47 changed files with 546 additions and 533 deletions
+8 -8
View File
@@ -76,7 +76,7 @@
const struct pn53x_io acr122_io;
char *acr122_firmware (nfc_device_t *pnd);
char *acr122_firmware (nfc_device *pnd);
const char *supported_devices[] = {
"ACS ACR122", // ACR122U & Touchatag, last version
@@ -239,7 +239,7 @@ acr122_connstring_decode (const nfc_connstring connstring, struct acr122_descrip
return 3;
}
nfc_device_t *
nfc_device *
acr122_connect (const nfc_connstring connstring)
{
struct acr122_descriptor ndd;
@@ -251,7 +251,7 @@ acr122_connect (const nfc_connstring connstring)
// FIXME: acr122_connect() does not take care about bus index
char *pcFirmware;
nfc_device_t *pnd = nfc_device_new ();
nfc_device *pnd = nfc_device_new ();
pnd->driver_data = malloc (sizeof (struct acr122_data));
// Alloc and init chip's data
@@ -300,7 +300,7 @@ error:
}
void
acr122_disconnect (nfc_device_t * pnd)
acr122_disconnect (nfc_device * pnd)
{
SCardDisconnect (DRIVER_DATA (pnd)->hCard, SCARD_LEAVE_CARD);
acr122_free_scardcontext ();
@@ -310,7 +310,7 @@ acr122_disconnect (nfc_device_t * pnd)
}
bool
acr122_send (nfc_device_t * pnd, const byte_t * pbtData, const size_t szData, struct timeval *timeout)
acr122_send (nfc_device * pnd, const byte_t * pbtData, const size_t szData, struct timeval *timeout)
{
// FIXME: timeout is not handled
(void) timeout;
@@ -381,7 +381,7 @@ acr122_send (nfc_device_t * pnd, const byte_t * pbtData, const size_t szData, st
}
int
acr122_receive (nfc_device_t * pnd, byte_t * pbtData, const size_t szData, struct timeval *timeout)
acr122_receive (nfc_device * pnd, byte_t * pbtData, const size_t szData, struct timeval *timeout)
{
// FIXME: timeout is not handled
(void) timeout;
@@ -422,7 +422,7 @@ acr122_receive (nfc_device_t * pnd, byte_t * pbtData, const size_t szData, struc
}
char *
acr122_firmware (nfc_device_t *pnd)
acr122_firmware (nfc_device *pnd)
{
byte_t abtGetFw[5] = { 0xFF, 0x00, 0x48, 0x00, 0x00 };
uint32_t uiResult;
@@ -445,7 +445,7 @@ acr122_firmware (nfc_device_t *pnd)
#if 0
bool
acr122_led_red (nfc_device_t *pnd, bool bOn)
acr122_led_red (nfc_device *pnd, bool bOn)
{
byte_t abtLed[9] = { 0xFF, 0x00, 0x40, 0x05, 0x04, 0x00, 0x00, 0x00, 0x00 };
byte_t abtBuf[2];
+4 -4
View File
@@ -29,10 +29,10 @@
bool acr122_probe (nfc_connstring connstrings[], size_t connstrings_len, size_t * pszDeviceFound);
// Functions used by developer to handle connection to this device
nfc_device_t *acr122_connect (const nfc_connstring connstring);
bool acr122_send (nfc_device_t * pnd, const byte_t * pbtData, const size_t szData, struct timeval *timeout);
int acr122_receive (nfc_device_t * pnd, byte_t * pbtData, const size_t szData, struct timeval *timeout);
void acr122_disconnect (nfc_device_t * pnd);
nfc_device *acr122_connect (const nfc_connstring connstring);
bool acr122_send (nfc_device * pnd, const byte_t * pbtData, const size_t szData, struct timeval *timeout);
int acr122_receive (nfc_device * pnd, byte_t * pbtData, const size_t szData, struct timeval *timeout);
void acr122_disconnect (nfc_device * pnd);
extern const struct nfc_driver_t acr122_driver;
+12 -12
View File
@@ -88,8 +88,8 @@ static const byte_t arygon_error_none[] = "FF000000\x0d\x0a";
static const byte_t arygon_error_incomplete_command[] = "FF0C0000\x0d\x0a";
static const byte_t arygon_error_unknown_mode[] = "FF060000\x0d\x0a";
bool arygon_reset_tama (nfc_device_t * pnd);
void arygon_firmware (nfc_device_t * pnd, char * str);
bool 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)
@@ -120,7 +120,7 @@ arygon_probe (nfc_connstring connstrings[], size_t connstrings_len, size_t * psz
uart_flush_input (sp);
uart_set_speed (sp, ARYGON_DEFAULT_SPEED);
nfc_device_t *pnd = nfc_device_new ();
nfc_device *pnd = nfc_device_new ();
pnd->driver = &arygon_driver;
pnd->driver_data = malloc(sizeof(struct arygon_data));
DRIVER_DATA (pnd)->port = sp;
@@ -215,7 +215,7 @@ arygon_connstring_decode (const nfc_connstring connstring, struct arygon_descrip
return 3;
}
nfc_device_t *
nfc_device *
arygon_connect (const nfc_connstring connstring)
{
struct arygon_descriptor ndd;
@@ -228,7 +228,7 @@ arygon_connect (const nfc_connstring connstring)
ndd.speed = ARYGON_DEFAULT_SPEED;
}
serial_port sp;
nfc_device_t *pnd = NULL;
nfc_device *pnd = NULL;
log_put (LOG_CATEGORY, NFC_PRIORITY_TRACE, "Attempt to connect to: %s at %d bauds.", ndd.port, ndd.speed);
sp = uart_open (ndd.port);
@@ -286,7 +286,7 @@ arygon_connect (const nfc_connstring connstring)
}
void
arygon_disconnect (nfc_device_t * pnd)
arygon_disconnect (nfc_device * pnd)
{
// Release UART port
uart_close (DRIVER_DATA (pnd)->port);
@@ -304,7 +304,7 @@ arygon_disconnect (nfc_device_t * 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)
bool
arygon_tama_send (nfc_device_t * pnd, const byte_t * pbtData, const size_t szData, struct timeval *timeout)
arygon_tama_send (nfc_device * pnd, const byte_t * pbtData, const size_t szData, struct timeval *timeout)
{
// Before sending anything, we need to discard from any junk bytes
uart_flush_input (DRIVER_DATA(pnd)->port);
@@ -354,7 +354,7 @@ arygon_tama_send (nfc_device_t * pnd, const byte_t * pbtData, const size_t szDat
}
int
arygon_abort (nfc_device_t *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)
byte_t dummy[] = { 0x32, 0x00, 0x00, 0xff, 0x09, 0xf7, 0xd4, 0x00, 0x00, 0x6c, 0x69, 0x62, 0x6e, 0x66, 0x63, 0xbe, 0x00 };
@@ -366,7 +366,7 @@ arygon_abort (nfc_device_t *pnd)
}
int
arygon_tama_receive (nfc_device_t * pnd, byte_t * pbtData, const size_t szDataLen, struct timeval *timeout)
arygon_tama_receive (nfc_device * pnd, byte_t * pbtData, const size_t szDataLen, struct timeval *timeout)
{
byte_t abtRxBuf[5];
size_t len;
@@ -484,7 +484,7 @@ arygon_tama_receive (nfc_device_t * pnd, byte_t * pbtData, const size_t szDataLe
}
void
arygon_firmware (nfc_device_t * pnd, char * str)
arygon_firmware (nfc_device * pnd, char * str)
{
const byte_t arygon_firmware_version_cmd[] = { DEV_ARYGON_PROTOCOL_ARYGON_ASCII, 'a', 'v' };
byte_t abtRx[16];
@@ -512,7 +512,7 @@ arygon_firmware (nfc_device_t * pnd, char * str)
}
bool
arygon_reset_tama (nfc_device_t * pnd)
arygon_reset_tama (nfc_device * pnd)
{
const byte_t arygon_reset_tama_cmd[] = { DEV_ARYGON_PROTOCOL_ARYGON_ASCII, 'a', 'r' };
byte_t abtRx[10]; // Attempted response is 10 bytes long
@@ -541,7 +541,7 @@ arygon_reset_tama (nfc_device_t * pnd)
}
bool
arygon_abort_command (nfc_device_t * pnd)
arygon_abort_command (nfc_device * pnd)
{
if (pnd) {
#ifndef WIN32
+4 -4
View File
@@ -32,11 +32,11 @@
bool arygon_probe (nfc_connstring connstrings[], size_t connstrings_len, size_t * pszDeviceFound);
nfc_device_t *arygon_connect (const nfc_connstring connstring);
void arygon_disconnect (nfc_device_t * pnd);
nfc_device *arygon_connect (const nfc_connstring connstring);
void arygon_disconnect (nfc_device * pnd);
bool arygon_tama_send (nfc_device_t * pnd, const byte_t * pbtData, const size_t szData, struct timeval *timeout);
int arygon_tama_receive (nfc_device_t * pnd, byte_t * pbtData, const size_t szDat, struct timeval *timeouta);
bool arygon_tama_send (nfc_device * pnd, const byte_t * pbtData, const size_t szData, struct timeval *timeout);
int arygon_tama_receive (nfc_device * pnd, byte_t * pbtData, const size_t szDat, struct timeval *timeouta);
extern const struct nfc_driver_t arygon_driver;
+11 -11
View File
@@ -48,8 +48,8 @@
#define PN532_UART_DRIVER_NAME "pn532_uart"
#define LOG_CATEGORY "libnfc.driver.pn532_uart"
int pn532_uart_ack (nfc_device_t * pnd);
int pn532_uart_wakeup (nfc_device_t * pnd);
int pn532_uart_ack (nfc_device * pnd);
int pn532_uart_wakeup (nfc_device * pnd);
const struct pn53x_io pn532_uart_io;
@@ -94,7 +94,7 @@ pn532_uart_probe (nfc_connstring connstrings[], size_t connstrings_len, size_t *
// Serial port claimed but we need to check if a PN532_UART is connected.
uart_set_speed (sp, PN532_UART_DEFAULT_SPEED);
nfc_device_t *pnd = nfc_device_new ();
nfc_device *pnd = nfc_device_new ();
pnd->driver = &pn532_uart_driver;
pnd->driver_data = malloc(sizeof(struct pn532_uart_data));
DRIVER_DATA (pnd)->port = sp;
@@ -196,7 +196,7 @@ pn532_connstring_decode (const nfc_connstring connstring, struct pn532_uart_desc
return 3;
}
nfc_device_t *
nfc_device *
pn532_uart_connect (const nfc_connstring connstring)
{
struct pn532_uart_descriptor ndd;
@@ -209,7 +209,7 @@ pn532_uart_connect (const nfc_connstring connstring)
ndd.speed = PN532_UART_DEFAULT_SPEED;
}
serial_port sp;
nfc_device_t *pnd = NULL;
nfc_device *pnd = NULL;
log_put (LOG_CATEGORY, NFC_PRIORITY_TRACE, "Attempt to connect to: %s at %d bauds.", ndd.port, ndd.speed);
sp = uart_open (ndd.port);
@@ -262,7 +262,7 @@ pn532_uart_connect (const nfc_connstring connstring)
}
void
pn532_uart_disconnect (nfc_device_t * pnd)
pn532_uart_disconnect (nfc_device * pnd)
{
// Release UART port
uart_close (DRIVER_DATA(pnd)->port);
@@ -278,7 +278,7 @@ pn532_uart_disconnect (nfc_device_t * pnd)
}
int
pn532_uart_wakeup (nfc_device_t * 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 byte_t pn532_wakeup_preamble[] = { 0x55, 0x55, 0x00, 0x00, 0x00 };
@@ -289,7 +289,7 @@ pn532_uart_wakeup (nfc_device_t * pnd)
#define PN532_BUFFER_LEN (PN53x_EXTENDED_FRAME__DATA_MAX_LEN + PN53x_EXTENDED_FRAME__OVERHEAD)
bool
pn532_uart_send (nfc_device_t * pnd, const byte_t * pbtData, const size_t szData, struct timeval *timeout)
pn532_uart_send (nfc_device * pnd, const byte_t * pbtData, const size_t szData, struct timeval *timeout)
{
// Before sending anything, we need to discard from any junk bytes
uart_flush_input (DRIVER_DATA(pnd)->port);
@@ -352,7 +352,7 @@ pn532_uart_send (nfc_device_t * pnd, const byte_t * pbtData, const size_t szData
}
int
pn532_uart_receive (nfc_device_t * pnd, byte_t * pbtData, const size_t szDataLen, struct timeval *timeout)
pn532_uart_receive (nfc_device * pnd, byte_t * pbtData, const size_t szDataLen, struct timeval *timeout)
{
byte_t abtRxBuf[5];
size_t len;
@@ -476,7 +476,7 @@ pn532_uart_receive (nfc_device_t * pnd, byte_t * pbtData, const size_t szDataLen
}
int
pn532_uart_ack (nfc_device_t * pnd)
pn532_uart_ack (nfc_device * pnd)
{
if (POWERDOWN == CHIP_DATA(pnd)->power_mode) {
if (-1 == pn532_uart_wakeup(pnd)) {
@@ -487,7 +487,7 @@ pn532_uart_ack (nfc_device_t * pnd)
}
bool
pn532_uart_abort_command (nfc_device_t * pnd)
pn532_uart_abort_command (nfc_device * pnd)
{
if (pnd) {
#ifndef WIN32
+4 -4
View File
@@ -31,10 +31,10 @@
bool pn532_uart_probe (nfc_connstring connstrings[], size_t connstrings_len, size_t * pszDeviceFound);
nfc_device_t *pn532_uart_connect (const nfc_connstring connstring);
void pn532_uart_disconnect (nfc_device_t * pnd);
bool pn532_uart_send (nfc_device_t * pnd, const byte_t * pbtData, const size_t szData, struct timeval *timeout);
int pn532_uart_receive (nfc_device_t * pnd, byte_t * pbtData, const size_t szData, struct timeval *timeout);
nfc_device *pn532_uart_connect (const nfc_connstring connstring);
void pn532_uart_disconnect (nfc_device * pnd);
bool pn532_uart_send (nfc_device * pnd, const byte_t * pbtData, const size_t szData, struct timeval *timeout);
int pn532_uart_receive (nfc_device * pnd, byte_t * pbtData, const size_t szData, struct timeval *timeout);
extern const struct nfc_driver_t pn532_uart_driver;
+11 -11
View File
@@ -118,7 +118,7 @@ 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);
bool pn53x_usb_init (nfc_device_t *pnd);
bool pn53x_usb_init (nfc_device *pnd);
int
pn53x_usb_bulk_read (struct pn53x_usb_data *data, byte_t abtRx[], const size_t szRx, struct timeval *timeout)
@@ -190,7 +190,7 @@ pn53x_usb_get_device_model (uint16_t vendor_id, uint16_t product_id)
return UNKNOWN;
}
int pn53x_usb_ack (nfc_device_t * pnd);
int pn53x_usb_ack (nfc_device * pnd);
// Find transfer endpoints for bulk transfers
void
@@ -378,7 +378,7 @@ pn53x_usb_get_usb_device_name (struct usb_device *dev, usb_dev_handle *udev, cha
return false;
}
nfc_device_t *
nfc_device *
pn53x_usb_connect (const nfc_connstring connstring)
{
struct pn53x_usb_descriptor desc;
@@ -388,7 +388,7 @@ pn53x_usb_connect (const nfc_connstring connstring)
return NULL;
}
nfc_device_t *pnd = NULL;
nfc_device *pnd = NULL;
struct pn53x_usb_data data = {
.pudh = NULL,
.uiEndPointIn = 0,
@@ -492,7 +492,7 @@ error:
}
void
pn53x_usb_disconnect (nfc_device_t * pnd)
pn53x_usb_disconnect (nfc_device * pnd)
{
pn53x_usb_ack (pnd);
@@ -519,7 +519,7 @@ pn53x_usb_disconnect (nfc_device_t * pnd)
#define PN53X_USB_BUFFER_LEN (PN53x_EXTENDED_FRAME__DATA_MAX_LEN + PN53x_EXTENDED_FRAME__OVERHEAD)
bool
pn53x_usb_send (nfc_device_t * pnd, const byte_t * pbtData, const size_t szData, struct timeval *timeout)
pn53x_usb_send (nfc_device * pnd, const byte_t * pbtData, const size_t szData, struct timeval *timeout)
{
byte_t abtFrame[PN53X_USB_BUFFER_LEN] = { 0x00, 0x00, 0xff }; // Every packet must start with "00 00 ff"
size_t szFrame = 0;
@@ -565,7 +565,7 @@ pn53x_usb_send (nfc_device_t * pnd, const byte_t * pbtData, const size_t szData,
}
int
pn53x_usb_receive (nfc_device_t * pnd, byte_t * pbtData, const size_t szDataLen, struct timeval *timeout)
pn53x_usb_receive (nfc_device * pnd, byte_t * pbtData, const size_t szDataLen, struct timeval *timeout)
{
size_t len;
off_t offset = 0;
@@ -715,13 +715,13 @@ read:
}
int
pn53x_usb_ack (nfc_device_t * pnd)
pn53x_usb_ack (nfc_device * pnd)
{
return pn53x_usb_bulk_write (DRIVER_DATA (pnd), (byte_t *) pn53x_ack_frame, sizeof (pn53x_ack_frame), NULL);
}
bool
pn53x_usb_init (nfc_device_t *pnd)
pn53x_usb_init (nfc_device *pnd)
{
// 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:
@@ -778,7 +778,7 @@ On ASK LoGO hardware:
}
bool
pn53x_usb_configure (nfc_device_t * pnd, const nfc_device_option_t ndo, const bool bEnable)
pn53x_usb_configure (nfc_device * pnd, const nfc_device_option ndo, const bool bEnable)
{
if (!pn53x_configure (pnd, ndo, bEnable))
return false;
@@ -806,7 +806,7 @@ pn53x_usb_configure (nfc_device_t * pnd, const nfc_device_option_t ndo, const bo
}
bool
pn53x_usb_abort_command (nfc_device_t * pnd)
pn53x_usb_abort_command (nfc_device * pnd)
{
DRIVER_DATA (pnd)->abort_flag = true;
return true;
+4 -4
View File
@@ -30,10 +30,10 @@
# include <nfc/nfc-types.h>
bool pn53x_usb_probe (nfc_connstring connstrings[], size_t connstrings_len, size_t * pszDeviceFound);
nfc_device_t *pn53x_usb_connect (const nfc_connstring connstring);
bool pn53x_usb_send (nfc_device_t * pnd, const byte_t * pbtData, const size_t szData, struct timeval *timeout);
int pn53x_usb_receive (nfc_device_t * pnd, byte_t * pbtData, const size_t szData, struct timeval *timeout);
void pn53x_usb_disconnect (nfc_device_t * pnd);
nfc_device *pn53x_usb_connect (const nfc_connstring connstring);
bool pn53x_usb_send (nfc_device * pnd, const byte_t * pbtData, const size_t szData, struct timeval *timeout);
int pn53x_usb_receive (nfc_device * pnd, byte_t * pbtData, const size_t szData, struct timeval *timeout);
void pn53x_usb_disconnect (nfc_device * pnd);
extern const struct nfc_driver_t pn53x_usb_driver;