|
From: Jeremy B. <go...@co...> - 2007-02-22 15:20:05
|
Good morning all.
I am having a problem that is probably a stupid error on my part. I
am trying to communicate with a smart card reader (I have tested this
with two models), and after claiming the interface, whenever I use
usb_bulk_write, I get the error "error submitting URB: No such file
or directory." I have attached a crude sample application below that
demonstrates what I am doing when the problem occurs. I also
attached the output of 'lsusb -v' for one of the devices that I am
using. This is running on a Fedora FC6 system (with pcscd disabled).
I feel like what I'm doing should be straightforward and hence I am
probably doing something wrong. Any help pointing out my error would
be appreciated.
-Jeremy
-----------
#include <usb.h>
#include <stdio.h>
int main(void)
{
struct usb_bus *busses;
struct usb_bus *bus;
usb_init();
// usb_set_debug(4);
usb_find_busses();
usb_find_devices();
busses = usb_get_busses();
if (busses)
{
for (bus = busses; bus; bus = bus->next)
{
struct usb_device *dev;
for (dev = bus->devices; dev; dev = dev->next)
{
printf("Device: Vendor=%.4X Product=%.4X \n",dev-
>descriptor.idVendor,dev->descriptor.idProduct);
// if (dev->descriptor.idVendor == 0x04E6 && dev-
>descriptor.idProduct == 0x200A) // SCM v2
if (dev->descriptor.idVendor == 0x04E6 && dev-
>descriptor.idProduct == 0x5116) // SCM v3 (CCID)
{
usb_dev_handle* devHandle;
printf("\tFound SCM Reader\n");
devHandle = usb_open(dev);
if (devHandle)
{
printf("\topened device\n");
for (int c = 0; c < dev->descriptor.bNumConfigurations; c++)
{
printf("\tChecking config %d\n",c);
/* Loop through all of the interfaces */
for (int i = 0; i < dev->config[c].bNumInterfaces; i++)
{
printf("\tChecking interface %d\n",i);
/* Loop through all of the alternate settings */
for (int a = 0; a < dev->config[c].interface
[i].num_altsetting; a++)
{
int ret;
printf("\tChecking alt settings %d\n",a);
usb_interface_descriptor interface = dev->config[c].interface
[i].altsetting[a];
printf("\tInterface available: bInterfaceNumber=%d
\n",interface.bInterfaceNumber);
ret = usb_claim_interface(devHandle,
interface.bInterfaceNumber);
if (!ret)
{
// SCM V2
//char* isTokPres = "\x54\x4c\x56\x43\x01\x01\x00\x03";
//int len = 8;
// SCMv3 - CCID
char* isTokPres = "\x65\x00\x00\x00\x00\x00\x00\x00\x00\x00";
int len=10;
printf("\tClaimed interface\n");
ret = usb_bulk_write(
devHandle,
interface.bInterfaceNumber,
isTokPres,
len,
5000);
if (ret == len)
{
printf("\tWrite succeeded\n");
}
else
{
printf("\tFAILED: write not complete: ret=%d error: %s
\n",ret,usb_strerror());
}
}
else
{
printf("\tFAILED: didn't claim interface: ret=%d error: %s
\n",ret,usb_strerror());
}
}
}
}
}
}
}
}
}
}
-----------
Bus 004 Device 016: ID 04e6:5116 SCM Microsystems, Inc. SCR331-LC1
SmartCard Reader
Device Descriptor:
bLength 18
bDescriptorType 1
bcdUSB 2.00
bDeviceClass 0 (Defined at Interface level)
bDeviceSubClass 0
bDeviceProtocol 0
bMaxPacketSize0 16
idVendor 0x04e6 SCM Microsystems, Inc.
idProduct 0x5116 SCR331-LC1 SmartCard Reader
bcdDevice 5.18
iManufacturer 1
iProduct 2
iSerial 5
bNumConfigurations 1
Configuration Descriptor:
bLength 9
bDescriptorType 2
wTotalLength 93
bNumInterfaces 1
bConfigurationValue 1
iConfiguration 3
bmAttributes 0xa0
Remote Wakeup
MaxPower 100mA
Interface Descriptor:
bLength 9
bDescriptorType 4
bInterfaceNumber 0
bAlternateSetting 0
bNumEndpoints 3
bInterfaceClass 11 Chip/SmartCard
bInterfaceSubClass 0
bInterfaceProtocol 0
iInterface 4
ChipCard Interface Descriptor:
bLength 54
bDescriptorType 33
bcdCCID 1.00
nMaxSlotIndex 0
bVoltageSupport 1 5.0V
dwProtocols 3 T=0 T=1
dwDefaultClock 4000
dwMaxiumumClock 12000
bNumClockSupported 0
dwDataRate 9600 bps
dwMaxDataRate 307200 bps
bNumDataRatesSupp. 0
dwMaxIFSD 252
dwSyncProtocols 00000000
dwMechanical 00000000
dwFeatures 000100BA
Auto configuration based on ATR
Auto voltage selection
Auto clock change
Auto baud rate change
Auto PPS made by CCID
TPDU level exchange
dwMaxCCIDMsgLen 263
bClassGetResponse echo
bClassEnvelope echo
wlcdLayout none
bPINSupport 0
bMaxCCIDBusySlots 1
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x01 EP 1 OUT
bmAttributes 2
Transfer Type Bulk
Synch Type None
Usage Type Data
wMaxPacketSize 0x0040 1x 64 bytes
bInterval 0
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x82 EP 2 IN
bmAttributes 2
Transfer Type Bulk
Synch Type None
Usage Type Data
wMaxPacketSize 0x0040 1x 64 bytes
bInterval 0
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x83 EP 3 IN
bmAttributes 3
Transfer Type Interrupt
Synch Type None
Usage Type Data
wMaxPacketSize 0x0010 1x 16 bytes
bInterval 16
-----------
-----
Jeremy Beker - go...@co...
http://www.confusticate.com
Condensing fact from the vapor of nuance.
|