From owner-freebsd-usb@FreeBSD.ORG Thu May 8 11:38:51 2008 Return-Path: Delivered-To: freebsd-usb@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 60153106564A for ; Thu, 8 May 2008 11:38:51 +0000 (UTC) (envelope-from me@NOSPAMkurganme.cjb.net) Received: from smtp4.aruba.it (smtpd3.aruba.it [62.149.128.208]) by mx1.freebsd.org (Postfix) with SMTP id 6D9518FC1B for ; Thu, 8 May 2008 11:38:50 +0000 (UTC) (envelope-from me@NOSPAMkurganme.cjb.net) Received: (qmail 4803 invoked by uid 89); 8 May 2008 11:12:06 -0000 Received: by simscan 1.1.0 ppid: 4771, pid: 4792, t: 0.3823s scanners: clamav: 0.88.4/m:40/d:1722 Received: from unknown (HELO ?192.168.0.40?) (vpa@bit4id.com@82.51.237.40) by smtp4.aruba.it with SMTP; 8 May 2008 11:12:05 -0000 Message-ID: <4822E006.9080902@NOSPAMkurganme.cjb.net> Date: Thu, 08 May 2008 13:12:06 +0200 From: kurganme User-Agent: Thunderbird 2.0.0.14 (Windows/20080421) MIME-Version: 1.0 To: freebsd-usb@freebsd.org Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Rating: smtp4.aruba.it 1.6.2 0/1000/N Subject: freebsd 6.3 smart card reader usb hang? X-BeenThere: freebsd-usb@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: FreeBSD support for USB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 08 May 2008 11:38:51 -0000 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 #include #include #include 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, "\x01\x01\x00\x00", 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... 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 198003ff,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 19880003,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 root@amd.dummy.loc:/usr/obj/usr/src/sys/GENERIC_USB_DEBUG i386 > dmesg | grep -iE '^.hci[0-9]|usb[0-9]' uhci0: port 0xe000-0xe01f irq 5 at device 29.0 on pci0 uhci0: [GIANT-LOCKED] uhci0: LegSup = 0x2f00 usb0: on uhci0 usb0: USB revision 1.0 ehci0: 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: 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