List Info

Thread: freebsd 6.3 smart card reader usb hang?




freebsd 6.3 smart card reader usb hang?
country flaguser name
Italy
2008-05-08 06:12:06
Hi everybody,
I have a device, an usb smart card reader (I use it
succesfully under
Windows Linux and MacOS-X), to which I'd like to send some
messages.
I wrote a simple code in C to send a "request
status" message, but it
not works.
The process hangs writing to the endpoint.
I'm sure that the message I send is correct (I take it from
the API
documentation of the device).
I have tried to run the code on different PCs with different
usb
controllers (Intel, VIA, nVidia)

The code is:

> cat >test_device.c
#include <stdio.h>
#include <fcntl.h>
#include <errno.h>
#include <dev/usb/usb.h>

int main() {
     int d, i;
     struct usb_ctl_request req;
     unsigned char buffer[256];
     d = open("/dev/ugen0.2", O_RDWR);
     printf("opening...n");
     if(d<0) {
         fprintf(stderr, "open error (%d).n",
errno);
         exit(1);
     }
     printf("writing...n");
     if(write(d, "x01x01x00x00", 4)<0) {
         fprintf(stderr, "write error (%d).n",
errno);
         close(d);
         exit(1);
     }
     printf("reading...n");
     if(read(d, buffer, 20)<0) {
         fprintf(stderr, "read error (%d).n",
errno);
         close(d);
         exit(1);
     }
     for(i=0; i<20; i++) printf("%02x",
buffer[i]);
     printf("n");
     printf("closing...n");
     close(d);
     return 0;
}

> gcc test_device.c

I have activeted the debug option this way:

> sudo sysctl hw.usb.debug=15
> sudo sysctl hw.usb.uhci.debug=15
> sudo sysctl hw.usb.ugen.debug=15

When I execute the code, it hangs on writing:

> sudo ./a.out
opening...
writing...<hang>

This is the Log I obtained:

---- BEGIN KERNEL LOG ----
ugenopen: flag=3, mode=8192, unit=0 endpt=2
ugenopen: sc=0xc4f66000, endpt=2, dir=0, sce=0xc4f6639c
usbd_open_pipe: iface=0xc4f5f1e0 address=0x2 flags=0x0
usbd_setup_pipe: dev=0xc4f4fc80 iface=0xc4f5f1e0
ep=0xc4f4d2cc
pipe=0xed0bf964
uhci_open: pipe=0xc52e7400, addr=2, endpt=2 (1)
ugenopen: sc=0xc4f66000, endpt=2, dir=1, sce=0xc4f6647c
usbd_open_pipe: iface=0xc4f5f1e0 address=0x82 flags=0x0
usbd_setup_pipe: dev=0xc4f4fc80 iface=0xc4f5f1e0
ep=0xc4f4d2d8
pipe=0xed0bf964
uhci_open: pipe=0xc53f7100, addr=2, endpt=130 (1)
ugen0: ugenwrite: 2
usbd_alloc_xfer() = 0xc4eede00
ugenwrite: transfer 4 bytes
usbd_bulk_transfer: start transfer 4 bytes
usbd_transfer: xfer=0xc4eede00, flags=0, pipe=0xc52e7400,
running=0
usbd_dump_queue: pipe=0xc52e7400
usb_allocmem: use frag=0xc4f21f00 size=4
usb_insert_transfer: pipe=0xc52e7400 running=0 timeout=0
uhci_device_bulk_start: xfer=0xc4eede00 len=4 flags=0
ii=0xc4eede74
uhci_alloc_std_chain: addr=2 endpt=2 len=4 speed=2
flags=0x0
uhci_alloc_std_chain: maxp=64 ntd=1
uhci_alloc_std_chain: nexttog=1
uhci_device_bulk_transfer: data(1)
TD(0xc4ee9f80) at 0025df80 = link=0x00000005
status=0x198003ff
token=0x006102e1 buffer=0x3ca35f00
5<T,VF> 198003ff<ACTIVE,IOC>,errcnt=3,actlen=0
pid=e1,addr=2,endpt=2,D=0,maxlen=4
uhci_add_bulk: sqh=0xc4ee8f40
uhci_start_loop: add
uhci_device_bulk_transfer: data(2)
TD(0xc4ee9f80) at 0025df80 = link=0x00000005
status=0x19880003
token=0x006102e1 buffer=0x3ca35f00
5<T,VF>
19880003<NAK,ACTIVE,IOC>,errcnt=3,actlen=4
pid=e1,addr=2,endpt=2,D=0,maxlen=4
---- END KERNEL LOG ----

I add also some informations about Kernel and usb device:

> ident /boot/kernel/kernel | grep /dev/usb/
      $FreeBSD: src/sys/dev/usb/ehci.c,v 1.36.2.4 2007/08/20
13:04:04
truckman Exp $
      $FreeBSD: src/sys/dev/usb/ehci_pci.c,v 1.18.2.2
2007/09/26
17:33:18 jhb Exp $
      $FreeBSD: src/sys/dev/usb/hid.c,v 1.25.2.1 2006/03/25
04:46:52
iedowse Exp $
      $FreeBSD: src/sys/dev/usb/if_aue.c,v 1.90.2.7
2007/02/10 15:17:34
mlaier Exp $
      $FreeBSD: src/sys/dev/usb/if_axe.c,v 1.30.2.6
2007/05/21 18:13:11
brueffer Exp $
      $FreeBSD: src/sys/dev/usb/if_cdce.c,v 1.7.2.7
2006/11/14 12:54:38
flz Exp $
      $FreeBSD: src/sys/dev/usb/if_cue.c,v 1.57.2.4
2007/05/21 18:10:48
brueffer Exp $
      $FreeBSD: src/sys/dev/usb/if_kue.c,v 1.64.2.6
2007/05/21 18:14:12
brueffer Exp $
      $FreeBSD: src/sys/dev/usb/if_ural.c,v 1.10.2.11
2007/03/31
22:00:44 sam Exp $
      $FreeBSD: src/sys/dev/usb/if_rue.c,v 1.21.2.5
2007/05/21 18:10:48
brueffer Exp $
      $FreeBSD: src/sys/dev/usb/ohci.c,v 1.154.2.4
2006/06/26 00:31:25
iedowse Exp $
      $FreeBSD: src/sys/dev/usb/ohci_pci.c,v 1.44.2.1
2006/01/29
01:26:46 iedowse Exp $
      $FreeBSD: src/sys/dev/usb/ugen.c,v 1.103.2.1
2006/09/24 14:55:48
iedowse Exp $
      $FreeBSD: src/sys/dev/usb/uhci.c,v 1.162.2.1
2006/03/01 01:59:04
iedowse Exp $
      $FreeBSD: src/sys/dev/usb/uhci_pci.c,v 1.57 2005/03/01
07:50:11
imp Exp $
      $FreeBSD: src/sys/dev/usb/uhid.c,v 1.77.2.5 2007/06/17
09:38:26
brueffer Exp $
      $FreeBSD: src/sys/dev/usb/uhub.c,v 1.69.2.1 2005/12/18
15:51:31
iedowse Exp $
      $FreeBSD: src/sys/dev/usb/ukbd.c,v 1.52.2.8 2007/10/25
16:56:15
jhb Exp $
      $FreeBSD: src/sys/dev/usb/ulpt.c,v 1.66.2.2 2007/06/17
09:38:26
brueffer Exp $
      $FreeBSD: src/sys/dev/usb/ums.c,v 1.77.2.5 2007/06/17
09:38:26
brueffer Exp $
      $FreeBSD: src/sys/dev/usb/urio.c,v 1.35.2.1 2007/06/17
09:38:27
brueffer Exp $
      $FreeBSD: src/sys/dev/usb/usb.c,v 1.106.2.2 2007/06/17
09:38:27
brueffer Exp $
      $FreeBSD: src/sys/dev/usb/usb_ethersubr.c,v 1.20
2005/03/25
12:42:30 sobomax Exp $
      $FreeBSD: src/sys/dev/usb/usb_mem.c,v 1.7.2.1
2007/05/21 18:10:48
brueffer Exp $
      $FreeBSD: src/sys/dev/usb/usb_quirks.c,v 1.41.2.8
2007/04/28
20:31:30 maxim Exp $
      $FreeBSD: src/sys/dev/usb/usb_subr.c,v 1.76.2.3
2006/03/01
01:59:05 iedowse Exp $
      $FreeBSD: src/sys/dev/usb/usbdi.c,v 1.91.2.1
2005/12/15 00:36:00
iedowse Exp $
      $FreeBSD: src/sys/dev/usb/usbdi_util.c,v 1.34
2005/03/01 08:01:22
sobomax Exp $
      $FreeBSD: src/sys/dev/usb/uscanner.c,v 1.63.2.7
2007/11/04
03:28:31 luigi Exp $

> uname -a
FreeBSD sspia.dummy.loc 6.3-RELEASE-p2 FreeBSD
6.3-RELEASE-p2 #0: Thu
May  8 11:51:43 CEST 2008
rootamd.dummy.loc:/usr/obj/usr/src/sys/GENERIC_USB_DEBUG 
i386

> dmesg | grep -iE '^.hci[0-9]|usb[0-9]'
uhci0: <Intel 82801DB (ICH4) USB controller USB-A>
port 0xe000-0xe01f
irq 5 at device 29.0 on pci0
uhci0: [GIANT-LOCKED]
uhci0: LegSup = 0x2f00
usb0: <Intel 82801DB (ICH4) USB controller USB-A> on
uhci0
usb0: USB revision 1.0
ehci0: <Intel 82801DB/L/M (ICH4) USB 2.0 controller>
mem
0xe8300000-0xe83003ff irq 3 at device 29.7 on pci0
ehci0: [GIANT-LOCKED]
usb1: EHCI version 1.0
usb1: companion controller, 2 ports each: usb0
usb1: <Intel 82801DB/L/M (ICH4) USB 2.0 controller> on
ehci0
usb1: USB revision 2.0
usb1: handing over full speed device on port 2 to usb0

> sudo usbdevs -v
Controller /dev/usb0:
addr 1: full speed, self powered, config 1, UHCI root
hub(0x0000),
Intel(0x0000), rev 1.00
  port 1 powered
  port 2 addr 2: full speed, power 100 mA, config 1, ACR38
USB
Reader(0x9000), ACS(0x072f), rev 1.00
Controller /dev/usb1:
addr 1: high speed, self powered, config 1, EHCI root
hub(0x0000),
Intel(0x0000), rev 1.00
  port 1 powered
  port 2 powered

> sudo lsusb -v
Bus /dev/usb0 Device /dev/ugen0: ID 072f:9000 Advanced Card
Systems, Ltd
ACR38 AC1038-based Smart Card Reader
Device Descriptor:
   bLength                18
   bDescriptorType         1
   bcdUSB               1.10
   bDeviceClass            0 (Defined at Interface level)
   bDeviceSubClass         0
   bDeviceProtocol         0
   bMaxPacketSize0         8
   idVendor           0x072f Advanced Card Systems, Ltd
   idProduct          0x9000 ACR38 AC1038-based Smart Card
Reader
   bcdDevice            1.00
   iManufacturer           1 ACS
   iProduct                2 ACR38 USB Reader
   iSerial                 0
   bNumConfigurations      1
   Configuration Descriptor:
     bLength                 9
     bDescriptorType         2
     wTotalLength           39
     bNumInterfaces          1
     bConfigurationValue     1
     iConfiguration          0
     bmAttributes         0x80
       (Bus Powered)
     MaxPower              100mA
     Interface Descriptor:
       bLength                 9
       bDescriptorType         4
       bInterfaceNumber        0
       bAlternateSetting       0
       bNumEndpoints           3
       bInterfaceClass         0 (Defined at Interface
level)
       bInterfaceSubClass      0
       bInterfaceProtocol      0
       iInterface              0
       Endpoint Descriptor:
         bLength                 7
         bDescriptorType         5
         bEndpointAddress     0x81  EP 1 IN
         bmAttributes            3
           Transfer Type            Interrupt
           Synch Type               None
           Usage Type               Data
         wMaxPacketSize     0x0008  1x 8 bytes
         bInterval               2
       Endpoint Descriptor:
         bLength                 7
         bDescriptorType         5
         bEndpointAddress     0x02  EP 2 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
Device Status:     0x0000
   (Bus Powered)

I hope that someone can help me.

Regars
Kurganme

_______________________________________________
freebsd-usbfreebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-usb
To unsubscribe, send any mail to
"freebsd-usb-unsubscribefreebsd.org"

Re: freebsd 6.3 smart card reader usb hang?
country flaguser name
Italy
2008-05-08 06:23:45
Btw I've tested the code on a Virtual Machine, with the same
kernel, 
same test code (I have copied the binaries) and, as you can
see below, 
it WORKS!
I obtain response from the usb reader, and it is correct!
This is the log for the execution on the Virtual Machine.

The VM is created with VMWare Server on a Windows XP host.

 > sudo ./a.out
opening...
writing...
reading...
0100001041435233382d31313030ffff00060c00
closing...

---- BEGIN KERNEL LOG ----
ugenopen: flag=3, mode=8192, unit=0 endpt=2
ugenopen: sc=0xc2697000, endpt=2, dir=0, sce=0xc269739c
usbd_open_pipe: iface=0xc2641440 address=0x2 flags=0x0
usbd_setup_pipe: dev=0xc268c080 iface=0xc2641440
ep=0xc267a5cc 
pipe=0xd153d964
uhci_open: pipe=0xc273cc80, addr=2, endpt=2 (1)
ugenopen: sc=0xc2697000, endpt=2, dir=1, sce=0xc269747c
usbd_open_pipe: iface=0xc2641440 address=0x82 flags=0x0
usbd_setup_pipe: dev=0xc268c080 iface=0xc2641440
ep=0xc267a5d8 
pipe=0xd153d964
uhci_open: pipe=0xc27afa00, addr=2, endpt=130 (1)
ugen0: ugenwrite: 2
usbd_alloc_xfer() = 0xc2645000
ugenwrite: transfer 4 bytes
usbd_bulk_transfer: start transfer 4 bytes
usbd_transfer: xfer=0xc2645000, flags=0, pipe=0xc273cc80,
running=0
usbd_dump_queue: pipe=0xc273cc80
usb_allocmem: use frag=0xc2650f40 size=4
usb_insert_transfer: pipe=0xc273cc80 running=0 timeout=0
uhci_device_bulk_start: xfer=0xc2645000 len=4 flags=0
ii=0xc2645074
uhci_alloc_std_chain: addr=2 endpt=2 len=4 speed=2
flags=0x0
uhci_alloc_std_chain: maxp=64 ntd=1
uhci_alloc_std_chain: nexttog=0
uhci_device_bulk_transfer: data(1)
TD(0xc264af80) at 0f39ef80 = link=0x00000005
status=0x198003ff 
token=0x006902e1 buffer=0x0f8e4f40
5<T,VF> 198003ff<ACTIVE,IOC>,errcnt=3,actlen=0 
pid=e1,addr=2,endpt=2,D=1,maxlen=4
uhci_add_bulk: sqh=0xc264bf20
uhci_start_loop: add
uhci_device_bulk_transfer: data(2)
TD(0xc264af80) at 0f39ef80 = link=0x00000005
status=0x198003ff 
token=0x006902e1 buffer=0x0f8e4f40
5<T,VF> 198003ff<ACTIVE,IOC>,errcnt=3,actlen=0 
pid=e1,addr=2,endpt=2,D=1,maxlen=4
usb_schedsoftintr: polling=0
usb0: uhci_softintr (0)
uhci_check_intr: ii=0xc2645074 done
uhci_idone: ii=0xc2645074
uhci_idone: ii=0xc2645074, xfer=0xc2645000, pipe=0xc273cc80
ready
TD(0xc264af80) at 0f39ef80 = link=0x00000005
status=0x19000003 
token=0x006902e1 buffer=0x0f8e4f40
5<T,VF> 19000003<IOC>,errcnt=3,actlen=4
pid=e1,addr=2,endpt=2,D=1,maxlen=4
uhci_idone: actlen=4, status=0x0
usb_transfer_complete: pipe=0xc273cc80 xfer=0xc2645000
status=0 actlen=4
usb_freemem: frag=0xc2650f40
usb_transfer_complete: repeat=0 new head=0
uhci_device_bulk_done: xfer=0xc2645000 ii=0xc2645074
sc=0xc264f000 
upipe=0xc273cc80
uhci_remove_bulk: sqh=0xc264bf20
uhci_end_loop: remove
uhci_device_bulk_done: length=4
usbd_start_next: pipe=0xc273cc80, xfer=0
uhci_idone: ii=0xc2645074 done
usbd_bulk_transfer: transferred 4
usbd_free_xfer: 0xc2645000
ugen0: ugenread: 2
usbd_alloc_xfer() = 0xc2645000
ugenread: start transfer 20 bytes
usbd_bulk_transfer: start transfer 20 bytes
usbd_transfer: xfer=0xc2645000, flags=0, pipe=0xc27afa00,
running=0
usbd_dump_queue: pipe=0xc27afa00
usb_allocmem: use frag=0xc2650f40 size=20
usb_insert_transfer: pipe=0xc27afa00 running=0 timeout=0
uhci_device_bulk_start: xfer=0xc2645000 len=20 flags=0
ii=0xc2645074
uhci_alloc_std_chain: addr=2 endpt=2 len=20 speed=2
flags=0x0
uhci_alloc_std_chain: maxp=64 ntd=1
uhci_alloc_std_chain: nexttog=0
uhci_device_bulk_transfer: data(1)
TD(0xc264af80) at 0f39ef80 = link=0x00000005
status=0x198003ff 
token=0x02690269 buffer=0x0f8e4f40
5<T,VF> 198003ff<ACTIVE,IOC>,errcnt=3,actlen=0 
pid=69,addr=2,endpt=2,D=1,maxlen=20
uhci_add_bulk: sqh=0xc264bf40
uhci_start_loop: add
uhci_device_bulk_transfer: data(2)
TD(0xc264af80) at 0f39ef80 = link=0x00000005
status=0x198003ff 
token=0x02690269 buffer=0x0f8e4f40
5<T,VF> 198003ff<ACTIVE,IOC>,errcnt=3,actlen=0 
pid=69,addr=2,endpt=2,D=1,maxlen=20
usb_schedsoftintr: polling=0
usb0: uhci_softintr (0)
uhci_check_intr: ii=0xc2645074 done
uhci_idone: ii=0xc2645074
uhci_idone: ii=0xc2645074, xfer=0xc2645000, pipe=0xc27afa00
ready
TD(0xc264af80) at 0f39ef80 = link=0x00000005
status=0x19000013 
token=0x02690269 buffer=0x0f8e4f40
5<T,VF> 19000013<IOC>,errcnt=3,actlen=20
pid=69,addr=2,endpt=2,D=1,maxlen=20
uhci_idone: actlen=20, status=0x0
usb_transfer_complete: pipe=0xc27afa00 xfer=0xc2645000
status=0 actlen=20
usb_freemem: frag=0xc2650f40
usb_transfer_complete: repeat=0 new head=0
uhci_device_bulk_done: xfer=0xc2645000 ii=0xc2645074
sc=0xc264f000 
upipe=0xc27afa00
uhci_remove_bulk: sqh=0xc264bf40
uhci_end_loop: remove
uhci_device_bulk_done: length=20
usbd_start_next: pipe=0xc27afa00, xfer=0
uhci_idone: ii=0xc2645074 done
usbd_bulk_transfer: transferred 20
ugenread: got 20 bytes
usbd_free_xfer: 0xc2645000
ugenclose: flag=3, mode=8192, unit=0, endpt=2
ugenclose: endpt=2 dir=0 sce=0xc269739c
usbd_ar_pipe: pipe=0xc273cc80
usbd_dump_queue: pipe=0xc273cc80
ugenclose: endpt=2 dir=1 sce=0xc269747c
usbd_ar_pipe: pipe=0xc27afa00
usbd_dump_queue: pipe=0xc27afa00
---- END KERNEL LOG ----

 > dmesg | grep -iE '^.hci[0-9]|usb[0-9]'
uhci0: <Intel 82371AB/EB (PIIX4) USB controller> port
0x1060-0x107f irq 
19 at device 7.2 on pci0
uhci0: [GIANT-LOCKED]
uhci0: LegSup = 0x003b
usb0: <Intel 82371AB/EB (PIIX4) USB controller> on
uhci0
usb0: USB revision 1.0
_______________________________________________
freebsd-usbfreebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-usb
To unsubscribe, send any mail to
"freebsd-usb-unsubscribefreebsd.org"

Re: freebsd 6.3 smart card reader usb hang?
user name
2008-05-08 06:54:23
kurganme wrote:
> Hi everybody,
> I have a device, an usb smart card reader (I use it
succesfully under
> Windows Linux and MacOS-X), to which I'd like to send
some messages.
> I wrote a simple code in C to send a "request
status" message, but it
> not works.
> The process hangs writing to the endpoint.
> I'm sure that the message I send is correct (I take it
from the API
> documentation of the device).
> I have tried to run the code on different PCs with
different usb
> controllers (Intel, VIA, nVidia)

Are you using OpenCT/OpenSC/PCSC under Linux for this
reader? What kind 
of openct driver are you using?

Maybe one needs to send some initialization sequence to the
card reader 
after open (this is the case of Reiner SCT for example).

--Marcin


Re: freebsd 6.3 smart card reader usb hang?
country flaguser name
Italy
2008-05-08 09:13:00
Marcin Cieslak wrote:
> Are you using OpenCT/OpenSC/PCSC under Linux for this
reader? What kind 
> of openct driver are you using?
> Maybe one needs to send some initialization sequence to
the card reader 
> after open (this is the case of Reiner SCT for
example).

I use the reader on Linux with a similar test code and it
works. It 
doesn't need any initialization sequence for working, infact
that device 
works under a virtualized FreeBSD (vmware with Windows XP
host) with no 
problem, with the same kernel and test code (see a previous
messase in 
this thread). How is it possible?

Regards,
Kurganme

_______________________________________________
freebsd-usbfreebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-usb
To unsubscribe, send any mail to
"freebsd-usb-unsubscribefreebsd.org"

[1-4]

about | contact  Other archives ( Real Estate discussion Medical topics )