From owner-freebsd-usb@FreeBSD.ORG Wed Feb 10 07:08:38 2010 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 8E6EE106566B for ; Wed, 10 Feb 2010 07:08:38 +0000 (UTC) (envelope-from doconnor@gsoft.com.au) Received: from cain.gsoft.com.au (cain.gsoft.com.au [203.31.81.10]) by mx1.freebsd.org (Postfix) with ESMTP id F1FEE8FC12 for ; Wed, 10 Feb 2010 07:08:37 +0000 (UTC) Received: from inchoate.gsoft.com.au ([203.31.81.30]) (authenticated bits=0) by cain.gsoft.com.au (8.13.8/8.13.8) with ESMTP id o1A78XfW016594 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NO); Wed, 10 Feb 2010 17:38:33 +1030 (CST) (envelope-from doconnor@gsoft.com.au) From: "Daniel O'Connor" To: freebsd-usb@freebsd.org Date: Wed, 10 Feb 2010 17:38:08 +1030 User-Agent: KMail/1.9.10 MIME-Version: 1.0 Content-Type: multipart/signed; boundary="nextPart3290127.aTiBjmm4lI"; protocol="application/pgp-signature"; micalg=pgp-sha1 Content-Transfer-Encoding: 7bit Message-Id: <201002101738.30753.doconnor@gsoft.com.au> X-Spam-Score: -3.638 () ALL_TRUSTED,AWL,BAYES_00 X-Scanned-By: MIMEDefang 2.63 on 203.31.81.10 Subject: usb_interrupt_read blocks "forever" sometimes 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: Wed, 10 Feb 2010 07:08:38 -0000 --nextPart3290127.aTiBjmm4lI Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline I am trying to talk to my WH1080 weather station and I find that=20 sometimes when I start the program it will stall forever in=20 usb_interrupt_read even though the timeout specified is 50 milliseconds. I also tried using alarm() but that doesn't cause the transfer to abort=20 (it appears the libusb code loops and doesn't check for EINTR). The code in question is.. signal(SIGALRM, alarmhandler); alarm(1); do { if ((bytes_read =3D usb_interrupt_read (station, USB_ENDPOINT_IN | USB_RECIP_INTER= =46ACE, buf, 8, 100 )) =3D=3D 8 ){ if (i > 0) fprintf(stderr, "Read OK after %d tries\n", i + 1); return bytes_read; } if (errno =3D=3D EINTR) fprintf(stderr, "Alarmed\n"); =20 fprintf(stderr, "Retrying..\n"); if (errno =3D=3D EAGAIN) usleep (10000); i++; } while (errno !=3D EINTR && i < MAXTRIES); =2E.. (Then stuff printing out if we get EINTR etc) The general procedure is to issue a request on the control endpoint and then read the result via the interrupt end point in 8 byte pieces. The retry stuff is there because I was having issues with reliable reads. The alarm handler doesn't seem to get called sometimes, maybe one in 10 starts causes usb_interrupt_read to hang in.. (gdb) bt #0 0x0000000800a8086c in poll () from /lib/libc.so.7 #1 0x000000080077531d in libusb20_dev_wait_process (pdev=3D0x7fffffffe870,= timeout=3D1)=20 at /usr/src/lib/libusb/libusb20.c:979 #2 0x000000080076f78c in usb_std_io (dev=3D0x801044d00, ep=3DVariable "ep"= is not available. ) at /usr/src/lib/libusb/libusb20_compat01.c:598 #3 0x000000000040180d in read_station (buf=3D0x5048d0 "=C3=BF=C3=BF=C3=BF= =C3=BF=C3=BF=C3=BF=C3=BF=C3=BF\036 \0040\021") at wh1080.c:249 Other starts I find it fails 10 times, retries the control message and works fine - I figure the micro has issues missing requests. The missing SIGALRM seems much worse though - how can it be masked? Of course if usb_interrupt_read honored its timeout that wouldn't matter :) The device reports as.. ugen0.5: at usbus0, cfg=3D0 md=3DHOST spd=3D= LOW (1.5Mbps) pwr=3DON Configuration index 0 bLength =3D 0x0009 bDescriptorType =3D 0x0002 wTotalLength =3D 0x0022 bNumInterfaces =3D 0x0001 bConfigurationValue =3D 0x0001 iConfiguration =3D 0x0000 bmAttributes =3D 0x0080 bMaxPower =3D 0x0032 Interface 0 bLength =3D 0x0009 bDescriptorType =3D 0x0004 bInterfaceNumber =3D 0x0000 bAlternateSetting =3D 0x0000 bNumEndpoints =3D 0x0001 bInterfaceClass =3D 0x0003 bInterfaceSubClass =3D 0x0000 bInterfaceProtocol =3D 0x0000 iInterface =3D 0x0000 Additional Descriptor bLength =3D 0x09 bDescriptorType =3D 0x21 bDescriptorSubType =3D 0x00 RAW dump: 0x00 | 0x09, 0x21, 0x00, 0x01, 0x00, 0x01, 0x22, 0x34, 0x08 | 0x00 Endpoint 0 bLength =3D 0x0007 bDescriptorType =3D 0x0005 bEndpointAddress =3D 0x0081 bmAttributes =3D 0x0003 wMaxPacketSize =3D 0x0008 bInterval =3D 0x000a bRefresh =3D 0x0000 bSynchAddress =3D 0x0000 Any help appreciated, thanks! PS please CC me. =2D-=20 Daniel O'Connor software and network engineer for Genesis Software - http://www.gsoft.com.au "The nice thing about standards is that there are so many of them to choose from." -- Andrew Tanenbaum GPG Fingerprint - 5596 B766 97C0 0E94 4347 295E E593 DC20 7B3F CE8C --nextPart3290127.aTiBjmm4lI Content-Type: application/pgp-signature; name=signature.asc Content-Description: This is a digitally signed message part. -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.12 (FreeBSD) iD8DBQBLcltu5ZPcIHs/zowRArvvAJ9od5hnf94qPGFkPz7nSLjw/vtMxwCgln6G ZvkQnEFw9bzem+h/hiRIgcs= =BaVK -----END PGP SIGNATURE----- --nextPart3290127.aTiBjmm4lI--