Add "usb" keyword support to connstring to specify all usb drivers at once

This commit is contained in:
Philippe Teuwen 2012-06-06 01:10:05 +00:00
parent b4ef1a3a5d
commit 4b5b45f14a
3 changed files with 12 additions and 4 deletions

View file

@ -275,7 +275,7 @@ acr122_usb_connstring_decode(const nfc_connstring connstring, struct acr122_usb_
int res = sscanf(connstring, "%[^:]:%[^:]:%[^:]", driver_name, dirname, filename); int res = sscanf(connstring, "%[^:]:%[^:]:%[^:]", driver_name, dirname, filename);
if (!res || (0 != strcmp(driver_name, ACR122_USB_DRIVER_NAME))) { if (!res || ((0 != strcmp(driver_name, ACR122_USB_DRIVER_NAME)) && (0 != strcmp(driver_name, "usb")))) {
// Driver name does not match. // Driver name does not match.
res = 0; res = 0;
} else { } else {

View file

@ -266,7 +266,7 @@ pn53x_usb_connstring_decode(const nfc_connstring connstring, struct pn53x_usb_de
int res = sscanf(connstring, "%[^:]:%[^:]:%[^:]", driver_name, dirname, filename); int res = sscanf(connstring, "%[^:]:%[^:]:%[^:]", driver_name, dirname, filename);
if (!res || (0 != strcmp(driver_name, PN53X_USB_DRIVER_NAME))) { if (!res || ((0 != strcmp(driver_name, PN53X_USB_DRIVER_NAME)) && (0 != strcmp(driver_name, "usb")))) {
// Driver name does not match. // Driver name does not match.
res = 0; res = 0;
} else { } else {

View file

@ -198,13 +198,21 @@ nfc_open(nfc_context *context, const nfc_connstring connstring)
while ((ndr = *pndr)) { while ((ndr = *pndr)) {
// Specific device is requested: using device description // Specific device is requested: using device description
if (0 != strncmp(ndr->name, ncs, strlen(ndr->name))) { if (0 != strncmp(ndr->name, ncs, strlen(ndr->name))) {
// Check if connstring driver is usb -> accept any driver *_usb
if ((0 != strncmp("usb", ncs, strlen("usb"))) || 0 != strncmp ("_usb", ndr->name + (strlen(ndr->name) - 4), 4)) {
pndr++; pndr++;
continue; continue;
} }
}
pnd = ndr->open(ncs); pnd = ndr->open(ncs);
// Test if the opening was successful // Test if the opening was successful
if (pnd == NULL) { if (pnd == NULL) {
if (0 == strncmp("usb", ncs, strlen("usb"))) {
// We've to test the other usb drivers before giving up
pndr++;
continue;
}
log_put(LOG_CATEGORY, NFC_PRIORITY_TRACE, "Unable to open \"%s\".", ncs); log_put(LOG_CATEGORY, NFC_PRIORITY_TRACE, "Unable to open \"%s\".", ncs);
log_fini(); log_fini();
return pnd; return pnd;