From b8a9a7d743308f03ea5e4a2ebb47351fa2d46eda Mon Sep 17 00:00:00 2001 From: Adam Laurie Date: Wed, 2 Dec 2009 11:45:38 +0000 Subject: [PATCH] more debuggers and fix auto-connecting to libusb devices (still no way to list them though) --- src/examples/nfc-list.c | 3 ++- src/lib/drivers/pn531_usb.c | 14 ++++++++++++-- src/lib/nfc.c | 15 +++++++++++---- 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/src/examples/nfc-list.c b/src/examples/nfc-list.c index c26a8a9..7f90027 100644 --- a/src/examples/nfc-list.c +++ b/src/examples/nfc-list.c @@ -49,7 +49,8 @@ int main(int argc, const char* argv[]) printf("%s use libnfc %s\n", argv[0], acLibnfcVersion); // Lazy way to open an NFC device - /* + + /* pnd = nfc_connect(NULL); */ diff --git a/src/lib/drivers/pn531_usb.c b/src/lib/drivers/pn531_usb.c index 8c77db5..82635a7 100644 --- a/src/lib/drivers/pn531_usb.c +++ b/src/lib/drivers/pn531_usb.c @@ -95,6 +95,7 @@ nfc_device_t* pn531_usb_connect(const nfc_device_desc_t* pndd) usb_spec_t* pus; usb_spec_t us; uint32_t uiDevIndex; + int devs; us.uiEndPointIn = 0; us.uiEndPointOut = 0; @@ -102,8 +103,17 @@ nfc_device_t* pn531_usb_connect(const nfc_device_desc_t* pndd) DBG("%s", "Looking for PN531 device"); usb_init(); - if (usb_find_busses() < 0) return NULL; - if (usb_find_devices() < 0) return NULL; + if (usb_find_busses() < 0) + { + DBG("%s","No USB bus found"); + return NULL; + } + if ((devs= usb_find_devices()) < 0) + { + DBG("%s","No USB devices found"); + return NULL; + } + DBG("%i USB candidates found",devs); // Initialize the device index we are seaching for if( pndd == NULL ) { diff --git a/src/lib/nfc.c b/src/lib/nfc.c index 30a9d9d..b37f108 100644 --- a/src/lib/nfc.c +++ b/src/lib/nfc.c @@ -94,7 +94,7 @@ nfc_list_devices(nfc_device_desc_t pnddDevices[], size_t szDevices, size_t *pszD { if (drivers_callbacks_list[uiDriver].list_devices != NULL) { - DBG("Checking driver: %s",drivers_callbacks_list[uiDriver]); + DBG("Checking driver: %s",drivers_callbacks_list[uiDriver].acDriver); size_t szN = 0; if (drivers_callbacks_list[uiDriver].list_devices (pnddDevices + (*pszDeviceFound), szDevices - (*pszDeviceFound), &szN)) { @@ -103,7 +103,7 @@ nfc_list_devices(nfc_device_desc_t pnddDevices[], size_t szDevices, size_t *pszD } #ifdef DEBUG else - DBG("Not checking driver: %s",drivers_callbacks_list[uiDriver]); + DBG("Not checking driver: %s",drivers_callbacks_list[uiDriver].acDriver); #endif } } @@ -120,9 +120,16 @@ nfc_device_t* nfc_connect(nfc_device_desc_t* pndd) { if (pndd == NULL) { // No device description specified: try to automatically claim a device - DBG("%s","Autodetecting available devices..."); - pndd = drivers_callbacks_list[uiDriver].pick_device (); + DBG("Autodetecting available devices: %s", drivers_callbacks_list[uiDriver].acDriver); + if(drivers_callbacks_list[uiDriver].pick_device != NULL) + pndd = drivers_callbacks_list[uiDriver].pick_device (); + DBG("Auto-connecting %s device",drivers_callbacks_list[uiDriver].acDriver); pnd = drivers_callbacks_list[uiDriver].connect(pndd); + if(pnd == NULL) + { + DBG("%s Not found",drivers_callbacks_list[uiDriver].acDriver); + pndd = NULL; + } } else { // Specific device is requested: using device description pndd if( 0 != strcmp(drivers_callbacks_list[uiDriver].acDriver, pndd->pcDriver ) )