From 58ad2a5760edcd3b39c825f63af51b4757e4688c Mon Sep 17 00:00:00 2001 From: Romuald Conty Date: Tue, 1 Feb 2011 21:20:48 +0000 Subject: [PATCH] Add new supported device: ASK / LoGO. (Thanks to ASK for sending one sample of this device) --- include/nfc/nfc-types.h | 2 ++ libnfc/drivers.h | 10 +++++----- libnfc/drivers/pn533_usb.c | 21 +++++++++++++++++++-- libnfc/drivers/pn533_usb.h | 1 + libnfc/drivers/pn53x_usb.c | 7 +++++-- libnfc/drivers/pn53x_usb.h | 20 +++++++++++--------- libnfc/nfc.c | 5 +++++ pn53x.rules | 1 + 8 files changed, 49 insertions(+), 18 deletions(-) diff --git a/include/nfc/nfc-types.h b/include/nfc/nfc-types.h index a8e9ad0..1d9e50c 100644 --- a/include/nfc/nfc-types.h +++ b/include/nfc/nfc-types.h @@ -133,6 +133,8 @@ struct driver_callbacks { bool (*list_devices) (nfc_device_desc_t pnddDevices[], size_t szDevices, size_t * pszDeviceFound); /** Connect callback */ nfc_device_t *(*connect) (const nfc_device_desc_t * pndd); + /** Init callback */ + void (*init) (nfc_device_t * pnd); /** Transceive callback */ bool (*transceive) (nfc_device_t * pnd, const byte_t * pbtTx, const size_t szTx, byte_t * pbtRx, size_t * pszRx); /** Disconnect callback */ diff --git a/libnfc/drivers.h b/libnfc/drivers.h index 238c409..14c5891 100644 --- a/libnfc/drivers.h +++ b/libnfc/drivers.h @@ -60,23 +60,23 @@ static const struct driver_callbacks drivers_callbacks_list[] = { // Driver Name Chip callbacks Pick Device List Devices Connect Transceive Disconnect # if defined (DRIVER_PN531_USB_ENABLED) {PN531_USB_DRIVER_NAME, &pn53x_callbacks_list, pn531_usb_pick_device, pn531_usb_list_devices, pn531_usb_connect, - pn53x_usb_transceive, pn53x_usb_disconnect}, + NULL, pn53x_usb_transceive, pn53x_usb_disconnect}, # endif /* DRIVER_PN531_USB_ENABLED */ # if defined (DRIVER_PN533_USB_ENABLED) {PN533_USB_DRIVER_NAME, &pn53x_callbacks_list, pn533_usb_pick_device, pn533_usb_list_devices, pn533_usb_connect, - pn53x_usb_transceive, pn53x_usb_disconnect}, + pn533_usb_init, pn53x_usb_transceive, pn53x_usb_disconnect}, # endif /* DRIVER_PN533_USB_ENABLED */ # if defined (DRIVER_ACR122_ENABLED) {ACR122_DRIVER_NAME, &pn53x_callbacks_list, acr122_pick_device, acr122_list_devices, acr122_connect, - acr122_transceive, acr122_disconnect}, + NULL, acr122_transceive, acr122_disconnect}, # endif /* DRIVER_ACR122_ENABLED */ # if defined (DRIVER_ARYGON_ENABLED) {ARYGON_DRIVER_NAME, &pn53x_callbacks_list, arygon_pick_device, arygon_list_devices, arygon_connect, - arygon_transceive, arygon_disconnect}, + NULL, arygon_transceive, arygon_disconnect}, # endif /* DRIVER_ARYGON_ENABLED */ # if defined (DRIVER_PN532_UART_ENABLED) {PN532_UART_DRIVER_NAME, &pn53x_callbacks_list, pn532_uart_pick_device, pn532_uart_list_devices, pn532_uart_connect, - pn532_uart_transceive, pn532_uart_disconnect}, + NULL, pn532_uart_transceive, pn532_uart_disconnect}, # endif /* DRIVER_PN532_UART_ENABLED */ }; diff --git a/libnfc/drivers/pn533_usb.c b/libnfc/drivers/pn533_usb.c index fd9764e..22e079e 100644 --- a/libnfc/drivers/pn533_usb.c +++ b/libnfc/drivers/pn533_usb.c @@ -63,8 +63,10 @@ bool pn533_usb_list_devices (nfc_device_desc_t pnddDevices[], size_t szDevices, size_t * pszDeviceFound) { // array of {vendor,product} pairs for USB devices - usb_candidate_t candidates[] = { {0x04CC, 0x2533} - , {0x04E6, 0x5591} + usb_candidate_t candidates[] = { + { 0x04CC, 0x2533 }, // NXP - PN533 + { 0x04E6, 0x5591 }, // SCM Micro - SCL3711-NFC&RW + { 0x1FD3, 0x0608 } // ASK - LoGO }; return pn53x_usb_list_devices (&pnddDevices[0], szDevices, pszDeviceFound, &candidates[0], @@ -76,3 +78,18 @@ pn533_usb_connect (const nfc_device_desc_t * pndd) { return pn53x_usb_connect (pndd, pndd->acDevice, NC_PN533); } + +void +pn533_usb_init (nfc_device_t * pnd) +{ + usb_spec_t* pus = (usb_spec_t*) pnd->nds; + DBG ("pus->uc.idVendor == 0x%04x, pus->uc.idProduct == 0x%04x", pus->uc.idVendor, pus->uc.idProduct); + if ((pus->uc.idVendor == 0x1FD3) && (pus->uc.idProduct == 0x0608)) { // ASK - LoGO + DBG ("ASK LoGO initialization."); + pn53x_set_reg (pnd, 0x6106, 0xFF, 0x1B); + pn53x_set_reg (pnd, 0x6306, 0xFF, 0x14); + pn53x_set_reg (pnd, 0xFFFD, 0xFF, 0x37); + pn53x_set_reg (pnd, 0xFFB0, 0xFF, 0x3B); + } +} + diff --git a/libnfc/drivers/pn533_usb.h b/libnfc/drivers/pn533_usb.h index 18a89f3..0252e55 100644 --- a/libnfc/drivers/pn533_usb.h +++ b/libnfc/drivers/pn533_usb.h @@ -28,6 +28,7 @@ // Functions used by developer to handle connection to this device nfc_device_t *pn533_usb_connect (const nfc_device_desc_t * pndd); +void pn533_usb_init (nfc_device_t * pnd); bool pn533_usb_list_devices (nfc_device_desc_t pnddDevices[], size_t szDevices, size_t * pszDeviceFound); nfc_device_desc_t *pn533_usb_pick_device (void); diff --git a/libnfc/drivers/pn53x_usb.c b/libnfc/drivers/pn53x_usb.c index 3a7c8b8..532ade4 100644 --- a/libnfc/drivers/pn53x_usb.c +++ b/libnfc/drivers/pn53x_usb.c @@ -172,14 +172,14 @@ pn53x_usb_connect (const nfc_device_desc_t * pndd, const char *target_name, int for (bus = usb_get_busses (); bus; bus = bus->next) { for (dev = bus->devices; dev; dev = dev->next, uiBusIndex--) { - // DBG("Checking device %04x:%04x",dev->descriptor.idVendor,dev->descriptor.idProduct); + DBG ("Checking device %04x:%04x", dev->descriptor.idVendor, dev->descriptor.idProduct); if (uiBusIndex == 0) { // Open the USB device us.pudh = usb_open (dev); get_end_points (dev, &us); if (usb_set_configuration (us.pudh, 1) < 0) { - DBG ("%s", "Setting config failed"); + ERR ("Unable to set USB configuration, please check USB permissions for device %04x:%04x", dev->descriptor.idVendor, dev->descriptor.idProduct); usb_close (us.pudh); // we failed to use the specified device return NULL; @@ -191,6 +191,9 @@ pn53x_usb_connect (const nfc_device_desc_t * pndd, const char *target_name, int // we failed to use the specified device return NULL; } + // Copy VendorId and ProductId + us.uc.idVendor = dev->descriptor.idVendor; + us.uc.idProduct = dev->descriptor.idProduct; // Allocate memory for the device info and specification, fill it and return the info pus = malloc (sizeof (usb_spec_t)); *pus = us; diff --git a/libnfc/drivers/pn53x_usb.h b/libnfc/drivers/pn53x_usb.h index 151d844..1f62610 100644 --- a/libnfc/drivers/pn53x_usb.h +++ b/libnfc/drivers/pn53x_usb.h @@ -23,22 +23,24 @@ #include +typedef struct { + uint16_t idVendor; + uint16_t idProduct; +} usb_candidate_t; + typedef struct { usb_dev_handle *pudh; + usb_candidate_t uc; uint32_t uiEndPointIn; uint32_t uiEndPointOut; uint32_t wMaxPacketSize; } usb_spec_t; -typedef struct { - uint16_t idVendor; - uint16_t idProduct; -} usb_candidate_t; - -nfc_device_t *pn53x_usb_connect (const nfc_device_desc_t * pndd, const char *target_name, int target_chip); void get_end_points (struct usb_device *dev, usb_spec_t * pus); -void pn53x_usb_disconnect (nfc_device_t * pnd); -bool pn53x_usb_transceive (nfc_device_t * pnd, const byte_t * pbtTx, const size_t szTx, byte_t * pbtRx, - size_t * pszRx); + bool pn53x_usb_list_devices (nfc_device_desc_t pnddDevices[], size_t szDevices, size_t * pszDeviceFound, usb_candidate_t candidates[], int num_candidates, char *target_name); +nfc_device_t *pn53x_usb_connect (const nfc_device_desc_t * pndd, const char *target_name, int target_chip); +bool pn53x_usb_transceive (nfc_device_t * pnd, const byte_t * pbtTx, const size_t szTx, byte_t * pbtRx, + size_t * pszRx); +void pn53x_usb_disconnect (nfc_device_t * pnd); diff --git a/libnfc/nfc.c b/libnfc/nfc.c index f7d1063..0cc85a2 100644 --- a/libnfc/nfc.c +++ b/libnfc/nfc.c @@ -107,9 +107,14 @@ nfc_connect (nfc_device_desc_t * pndd) // Great we have claimed a device pnd->pdc = &(drivers_callbacks_list[uiDriver]); + // TODO: Put this pn53x related in driver_init() if (!pn53x_init (pnd)) return NULL; + if (pnd->pdc->init) { + pnd->pdc->init (pnd); + } + // Set default configuration options // Make sure we reset the CRC and parity to chip handling. if (!nfc_configure (pnd, NDO_HANDLE_CRC, true)) diff --git a/pn53x.rules b/pn53x.rules index b7219cb..594da3b 100644 --- a/pn53x.rules +++ b/pn53x.rules @@ -11,5 +11,6 @@ ATTRS{idVendor}=="054c", ATTRS{idProduct}=="0193", MODE="0664", GROUP="plugdev" # PN533 ATTRS{idVendor}=="04cc", ATTRS{idProduct}=="2533", MODE="0664", GROUP="plugdev" ATTRS{idVendor}=="04e6", ATTRS{idProduct}=="5591", MODE="0664", GROUP="plugdev" +ATTRS{idVendor}=="1fd3", ATTRS{idProduct}=="0608", MODE="0664", GROUP="plugdev" LABEL="pn53x_rules_end"