On 04/01/16(Mon) 14:53, Devin Reade wrote: > --On Monday, January 04, 2016 08:02:34 PM +0100 Martin Pieuchot > <m...@openbsd.org> wrote: > [...] > An earlier version of the code (not submitted) matched on only vendor > and product, but I was seeing onerng_match being invoked twice; one for > the control interface and one for the data interface, so I was getting > two devices (onerng0 and onerng1). By matching on the control interface > and then using it to retrieve the data interface from the parent device > (and thus returning UMATCH_VENDOR_PRODUCT), we only get one onerng0 > device.
That's because of the "if (iface == NULL)" check in the beginning of your function. usb(4) describe how devices are matched and the code can be found in usbd_probe_and_attach(). If you inverse this check, and only attach when no iface has been configured by the stack you'll have to set the configuration yourself but only one onerng(4) will be attached per corresponding USB device. > Bus 001 Device 006: ID 1d50:6086 OpenMoko, Inc. > Device Descriptor: > bLength 18 > bDescriptorType 1 > bcdUSB 2.00 > bDeviceClass 2 Communications > bDeviceSubClass 0 > bDeviceProtocol 0 > bMaxPacketSize0 32 > idVendor 0x1d50 OpenMoko, Inc. > idProduct 0x6086 > bcdDevice 0.09 > iManufacturer 1 > iProduct 3 > iSerial 3 > bNumConfigurations 1 > Configuration Descriptor: > bLength 9 > bDescriptorType 2 > wTotalLength 67 > bNumInterfaces 2 > bConfigurationValue 1 > iConfiguration 0 > bmAttributes 0x80 > (Bus Powered) > MaxPower 200mA > Interface Descriptor: > bLength 9 > bDescriptorType 4 > bInterfaceNumber 0 > bAlternateSetting 0 > bNumEndpoints 1 > bInterfaceClass 2 Communications > bInterfaceSubClass 2 Abstract (modem) > bInterfaceProtocol 1 AT-commands (v.25ter) > iInterface 0 > CDC Header: > bcdCDC 1.10 > CDC ACM: > bmCapabilities 0x06 > sends break > line coding and serial state > CDC Union: > bMasterInterface 0 > bSlaveInterface 1 > CDC Call Management: > bmCapabilities 0x00 > bDataInterface 1 > Endpoint Descriptor: > bLength 7 > bDescriptorType 5 > bEndpointAddress 0x82 EP 2 IN > bmAttributes 3 > Transfer Type Interrupt > Synch Type None > Usage Type Data > wMaxPacketSize 0x0020 1x 32 bytes > bInterval 64 > Interface Descriptor: > bLength 9 > bDescriptorType 4 > bInterfaceNumber 1 > bAlternateSetting 0 > bNumEndpoints 2 > bInterfaceClass 10 CDC Data > bInterfaceSubClass 0 Unused > bInterfaceProtocol 0 > iInterface 4 > Endpoint Descriptor: > bLength 7 > bDescriptorType 5 > bEndpointAddress 0x85 EP 5 IN > bmAttributes 2 > Transfer Type Bulk > Synch Type None > Usage Type Data > wMaxPacketSize 0x0040 1x 64 bytes > bInterval 1 > Endpoint Descriptor: > bLength 7 > bDescriptorType 5 > bEndpointAddress 0x05 EP 5 OUT > bmAttributes 2 > Transfer Type Bulk > Synch Type None > Usage Type Data > wMaxPacketSize 0x0040 1x 64 bytes > bInterval 1