Subject: Re: Manual pages for usb
To: None <tech-kern@NetBSD.org>
From: Ian Zagorskih <ianzag@megasignal.com>
List: tech-kern
Date: 02/06/2004 20:39:31
On Thursday 05 February 2004 21:48, Ian Zagorskih wrote:
> Not sure if I should post this message to tech-kern or tech-docs.. Well,
> let it be tech-kern :)
>
> From "man usb" at http://netbsd.gw.com/cgi-bin/man-cgi?usb++NetBSD-current
>
> ---cut---
> USB EVENT INTERFACE
>      All USB events are reported via the /dev/usb device.  This devices can
> be opened for reading and each read(2) will yield an event record (if some-
> thing has happened).  The poll(2) system call can be used to determine if
> an event record is available for reading.
> ---cut---
>
> When i read this i got confused that i can open for events not only
> /dev/usb device but also /dev/usb0, usb1 and so on i.e. all /dev/usbX.
> Though as practice shows (at least on NetBSD-1.6.1/i386) only /dev/usb
> device actually returns event on read() call and all another /dev/usbX
> devices just immediatly return ENXIO "Device not configured".
>
> Maybe, it would be better to re-phrase a bit this paragraph like
> "s/devices/device" in "This devices can be" ?
>
> // wbr

And one more thing..

man usb(4) requires to access 16bit fields in structures through 
UGETW()/USETW() macros i.e. to swap bytes in proper way.

---cut man usb(4)---
     The include file <dev/usb/usb.h> contains definitions for the types used
     by the various ioctl(2) calls.  The naming convention of the fields for
     the various USB descriptors exactly follows the naming in the USB speci-
     fication.  Byte sized fields can be accessed directly, but word (16 bit)
     sized fields must be access by the UGETW(field) and USETW(field, value)
     macros to handle byte order and alignment properly.
---cut---

But when i receive usb device attach/detach event whrough reading /dev/usb 
device (USB_EVENT_DEVICE_xxx), seems like 16bit fields udi_productNo, 
udi_vendorNo and udi_releaseNo in received usb_device_info structure are 
already swapped right way, so applying UGETW() macro gives wrong result.

For tests i'v tried several USB Flash disks and one Anchor Chips's based 
custom device (OLED display with keybord).

Any comments ? Are macros UGETW() and USETW() applicible in both kernel and 
user lands ?

// wbr