| 96 |
* OpenUSB |
* OpenUSB |
| 97 |
* |
* |
| 98 |
****************************************************************************/ |
****************************************************************************/ |
| 99 |
status_t OpenUSB(unsigned int lun, /*@unused@*/ int Channel) |
status_t OpenUSB(unsigned int reader_index, /*@unused@*/ int Channel) |
| 100 |
{ |
{ |
| 101 |
return OpenUSBByName(lun, NULL); |
return OpenUSBByName(reader_index, NULL); |
| 102 |
} /* OpenUSB */ |
} /* OpenUSB */ |
| 103 |
|
|
| 104 |
|
|
| 107 |
* OpenUSBByName |
* OpenUSBByName |
| 108 |
* |
* |
| 109 |
****************************************************************************/ |
****************************************************************************/ |
| 110 |
status_t OpenUSBByName(unsigned int lun, /*@null@*/ char *device) |
status_t OpenUSBByName(unsigned int reader_index, /*@null@*/ char *device) |
| 111 |
{ |
{ |
| 112 |
static struct usb_bus *busses = NULL; |
static struct usb_bus *busses = NULL; |
|
unsigned int reader = LunToReaderIndex(lun); |
|
| 113 |
int alias = 0; |
int alias = 0; |
| 114 |
struct usb_bus *bus; |
struct usb_bus *bus; |
| 115 |
struct usb_dev_handle *dev_handle; |
struct usb_dev_handle *dev_handle; |
| 119 |
unsigned int device_vendor, device_product; |
unsigned int device_vendor, device_product; |
| 120 |
char *dirname = NULL, *filename = NULL; |
char *dirname = NULL, *filename = NULL; |
| 121 |
|
|
| 122 |
DEBUG_COMM3("Lun: %X, Device: %s", lun, device); |
DEBUG_COMM3("Reader index: %X, Device: %s", reader_index, device); |
| 123 |
|
|
| 124 |
/* device name specified */ |
/* device name specified */ |
| 125 |
if (device) |
if (device) |
| 180 |
return STATUS_UNSUCCESSFUL; |
return STATUS_UNSUCCESSFUL; |
| 181 |
} |
} |
| 182 |
|
|
| 183 |
/* is the lun already used? */ |
/* is the reader_index already used? */ |
| 184 |
if (usbDevice[reader].handle != NULL) |
if (usbDevice[reader_index].handle != NULL) |
| 185 |
{ |
{ |
| 186 |
DEBUG_CRITICAL2("USB driver with lun %X already in use", lun); |
DEBUG_CRITICAL2("USB driver with index %X already in use", |
| 187 |
|
reader_index); |
| 188 |
return STATUS_UNSUCCESSFUL; |
return STATUS_UNSUCCESSFUL; |
| 189 |
} |
} |
| 190 |
|
|
| 333 |
bus->dirname, dev->filename); |
bus->dirname, dev->filename); |
| 334 |
|
|
| 335 |
/* Get Endpoints values*/ |
/* Get Endpoints values*/ |
| 336 |
get_end_points(dev, &usbDevice[reader]); |
get_end_points(dev, &usbDevice[reader_index]); |
| 337 |
|
|
| 338 |
/* store device information */ |
/* store device information */ |
| 339 |
usbDevice[reader].handle = dev_handle; |
usbDevice[reader_index].handle = dev_handle; |
| 340 |
usbDevice[reader].dev = dev; |
usbDevice[reader_index].dev = dev; |
| 341 |
|
|
| 342 |
/* CCID common informations */ |
/* CCID common informations */ |
| 343 |
usbDevice[reader].ccid.bSeq = 0; |
usbDevice[reader_index].ccid.bSeq = 0; |
| 344 |
usbDevice[reader].ccid.readerID = |
usbDevice[reader_index].ccid.readerID = |
| 345 |
(dev->descriptor.idVendor << 16) + |
(dev->descriptor.idVendor << 16) + |
| 346 |
dev->descriptor.idProduct; |
dev->descriptor.idProduct; |
| 347 |
usbDevice[reader].ccid.dwFeatures = dw2i(usb_interface->altsetting->extra, 40); |
usbDevice[reader_index].ccid.dwFeatures = dw2i(usb_interface->altsetting->extra, 40); |
| 348 |
usbDevice[reader].ccid.bPINSupport = usb_interface->altsetting->extra[52]; |
usbDevice[reader_index].ccid.bPINSupport = usb_interface->altsetting->extra[52]; |
| 349 |
usbDevice[reader].ccid.dwMaxCCIDMessageLength = dw2i(usb_interface->altsetting->extra, 44); |
usbDevice[reader_index].ccid.dwMaxCCIDMessageLength = dw2i(usb_interface->altsetting->extra, 44); |
| 350 |
usbDevice[reader].ccid.dwMaxIFSD = dw2i(usb_interface->altsetting->extra, 28); |
usbDevice[reader_index].ccid.dwMaxIFSD = dw2i(usb_interface->altsetting->extra, 28); |
| 351 |
usbDevice[reader].ccid.dwDefaultClock = dw2i(usb_interface->altsetting->extra, 10); |
usbDevice[reader_index].ccid.dwDefaultClock = dw2i(usb_interface->altsetting->extra, 10); |
| 352 |
usbDevice[reader].ccid.dwMaxDataRate = dw2i(usb_interface->altsetting->extra, 23); |
usbDevice[reader_index].ccid.dwMaxDataRate = dw2i(usb_interface->altsetting->extra, 23); |
| 353 |
usbDevice[reader].ccid.bMaxSlotIndex = usb_interface->altsetting->extra[4]; |
usbDevice[reader_index].ccid.bMaxSlotIndex = usb_interface->altsetting->extra[4]; |
| 354 |
usbDevice[reader].ccid.bCurrentSlotIndex = 0; |
usbDevice[reader_index].ccid.bCurrentSlotIndex = 0; |
| 355 |
usbDevice[reader].ccid.defaultFeatures = usbDevice[reader].ccid.dwFeatures; |
usbDevice[reader_index].ccid.defaultFeatures = usbDevice[reader_index].ccid.dwFeatures; |
| 356 |
goto end; |
goto end; |
| 357 |
} |
} |
| 358 |
} |
} |
| 359 |
} |
} |
| 360 |
} |
} |
| 361 |
end: |
end: |
| 362 |
if (usbDevice[reader].handle == NULL) |
if (usbDevice[reader_index].handle == NULL) |
| 363 |
return STATUS_UNSUCCESSFUL; |
return STATUS_UNSUCCESSFUL; |
| 364 |
|
|
| 365 |
return STATUS_SUCCESS; |
return STATUS_SUCCESS; |
| 371 |
* WriteUSB |
* WriteUSB |
| 372 |
* |
* |
| 373 |
****************************************************************************/ |
****************************************************************************/ |
| 374 |
status_t WriteUSB(unsigned int lun, unsigned int length, unsigned char *buffer) |
status_t WriteUSB(unsigned int reader_index, unsigned int length, |
| 375 |
|
unsigned char *buffer) |
| 376 |
{ |
{ |
| 377 |
int rv; |
int rv; |
|
unsigned int reader = LunToReaderIndex(lun); |
|
| 378 |
#ifdef DEBUG_LEVEL_COMM |
#ifdef DEBUG_LEVEL_COMM |
| 379 |
char debug_header[] = "-> 121234 "; |
char debug_header[] = "-> 121234 "; |
| 380 |
|
|
| 381 |
sprintf(debug_header, "-> %06X ", (int)lun); |
sprintf(debug_header, "-> %06X ", (int)reader_index); |
| 382 |
#endif |
#endif |
| 383 |
|
|
| 384 |
#ifdef DEBUG_LEVEL_COMM |
#ifdef DEBUG_LEVEL_COMM |
| 385 |
DEBUG_XXD(debug_header, buffer, length); |
DEBUG_XXD(debug_header, buffer, length); |
| 386 |
#endif |
#endif |
| 387 |
|
|
| 388 |
rv = usb_bulk_write(usbDevice[reader].handle, usbDevice[reader].bulk_out, |
rv = usb_bulk_write(usbDevice[reader_index].handle, |
| 389 |
(char *)buffer, length, USB_WRITE_TIMEOUT); |
usbDevice[reader_index].bulk_out, (char *)buffer, length, |
| 390 |
|
USB_WRITE_TIMEOUT); |
| 391 |
|
|
| 392 |
if (rv < 0) |
if (rv < 0) |
| 393 |
{ |
{ |
| 394 |
DEBUG_CRITICAL4("usb_bulk_write(%s/%s): %s", |
DEBUG_CRITICAL4("usb_bulk_write(%s/%s): %s", |
| 395 |
usbDevice[reader].dev->bus->dirname, |
usbDevice[reader_index].dev->bus->dirname, |
| 396 |
usbDevice[reader].dev->filename, strerror(errno)); |
usbDevice[reader_index].dev->filename, strerror(errno)); |
| 397 |
return STATUS_UNSUCCESSFUL; |
return STATUS_UNSUCCESSFUL; |
| 398 |
} |
} |
| 399 |
|
|
| 406 |
* ReadUSB |
* ReadUSB |
| 407 |
* |
* |
| 408 |
****************************************************************************/ |
****************************************************************************/ |
| 409 |
status_t ReadUSB(unsigned int lun, unsigned int * length, unsigned char *buffer) |
status_t ReadUSB(unsigned int reader_index, unsigned int * length, |
| 410 |
|
unsigned char *buffer) |
| 411 |
{ |
{ |
| 412 |
int rv; |
int rv; |
|
unsigned int reader = LunToReaderIndex(lun); |
|
| 413 |
#ifdef DEBUG_LEVEL_COMM |
#ifdef DEBUG_LEVEL_COMM |
| 414 |
char debug_header[] = "<- 121234 "; |
char debug_header[] = "<- 121234 "; |
| 415 |
|
|
| 416 |
sprintf(debug_header, "<- %06X ", (int)lun); |
sprintf(debug_header, "<- %06X ", (int)reader_index); |
| 417 |
#endif |
#endif |
| 418 |
|
|
| 419 |
rv = usb_bulk_read(usbDevice[reader].handle, usbDevice[reader].bulk_in, |
rv = usb_bulk_read(usbDevice[reader_index].handle, |
| 420 |
(char *)buffer, *length, USB_READ_TIMEOUT); |
usbDevice[reader_index].bulk_in, (char *)buffer, *length, |
| 421 |
|
USB_READ_TIMEOUT); |
| 422 |
|
|
| 423 |
if (rv < 0) |
if (rv < 0) |
| 424 |
{ |
{ |
| 425 |
*length = 0; |
*length = 0; |
| 426 |
DEBUG_CRITICAL4("usb_bulk_read(%s/%s): %s", |
DEBUG_CRITICAL4("usb_bulk_read(%s/%s): %s", |
| 427 |
usbDevice[reader].dev->bus->dirname, |
usbDevice[reader_index].dev->bus->dirname, |
| 428 |
usbDevice[reader].dev->filename, strerror(errno)); |
usbDevice[reader_index].dev->filename, strerror(errno)); |
| 429 |
return STATUS_UNSUCCESSFUL; |
return STATUS_UNSUCCESSFUL; |
| 430 |
} |
} |
| 431 |
|
|
| 444 |
* CloseUSB |
* CloseUSB |
| 445 |
* |
* |
| 446 |
****************************************************************************/ |
****************************************************************************/ |
| 447 |
status_t CloseUSB(unsigned int lun) |
status_t CloseUSB(unsigned int reader_index) |
| 448 |
{ |
{ |
| 449 |
struct usb_interface *usb_interface; |
struct usb_interface *usb_interface; |
| 450 |
int interface; |
int interface; |
|
unsigned int reader = LunToReaderIndex(lun); |
|
| 451 |
|
|
| 452 |
/* device not opened */ |
/* device not opened */ |
| 453 |
if (usbDevice[reader].dev == NULL) |
if (usbDevice[reader_index].dev == NULL) |
| 454 |
return STATUS_UNSUCCESSFUL; |
return STATUS_UNSUCCESSFUL; |
| 455 |
|
|
| 456 |
DEBUG_COMM3("Closing USB device: %s/%s", |
DEBUG_COMM3("Closing USB device: %s/%s", |
| 457 |
usbDevice[reader].dev->bus->dirname, usbDevice[reader].dev->filename); |
usbDevice[reader_index].dev->bus->dirname, |
| 458 |
|
usbDevice[reader_index].dev->filename); |
| 459 |
|
|
| 460 |
usb_interface = get_ccid_usb_interface(usbDevice[reader].dev); |
usb_interface = get_ccid_usb_interface(usbDevice[reader_index].dev); |
| 461 |
interface = usb_interface ? |
interface = usb_interface ? |
| 462 |
usb_interface->altsetting->bInterfaceNumber : |
usb_interface->altsetting->bInterfaceNumber : |
| 463 |
usbDevice[reader].dev->config->interface->altsetting->bInterfaceNumber; |
usbDevice[reader_index].dev->config->interface->altsetting->bInterfaceNumber; |
| 464 |
|
|
| 465 |
/* reset so that bSeq starts at 0 again */ |
/* reset so that bSeq starts at 0 again */ |
| 466 |
usb_reset(usbDevice[reader].handle); |
usb_reset(usbDevice[reader_index].handle); |
| 467 |
|
|
| 468 |
usb_release_interface(usbDevice[reader].handle, interface); |
usb_release_interface(usbDevice[reader_index].handle, interface); |
| 469 |
usb_close(usbDevice[reader].handle); |
usb_close(usbDevice[reader_index].handle); |
| 470 |
|
|
| 471 |
/* mark the resource unused */ |
/* mark the resource unused */ |
| 472 |
usbDevice[reader].handle = NULL; |
usbDevice[reader_index].handle = NULL; |
| 473 |
usbDevice[reader].dev = NULL; |
usbDevice[reader_index].dev = NULL; |
| 474 |
|
|
| 475 |
return STATUS_SUCCESS; |
return STATUS_SUCCESS; |
| 476 |
} /* CloseUSB */ |
} /* CloseUSB */ |
| 481 |
* get_ccid_descriptor |
* get_ccid_descriptor |
| 482 |
* |
* |
| 483 |
****************************************************************************/ |
****************************************************************************/ |
| 484 |
_ccid_descriptor *get_ccid_descriptor(unsigned int lun) |
_ccid_descriptor *get_ccid_descriptor(unsigned int reader_index) |
| 485 |
{ |
{ |
| 486 |
return &usbDevice[LunToReaderIndex(lun)].ccid; |
return &usbDevice[reader_index].ccid; |
| 487 |
} /* get_ccid_descriptor */ |
} /* get_ccid_descriptor */ |
| 488 |
|
|
| 489 |
|
|