Commit graph

25 commits

Author SHA1 Message Date
cinap_lenrek bea20cd152 nusb/lib: provide a setalt() function to set the interface to its altsetting 2022-02-23 18:00:34 +00:00
cinap_lenrek 065d601916 nusb: Fix handling of interface altsetting.
The altsetting was handled only for a single endpoint
(per interface number), but has to be handled for each
endpoint (per interface *AND* altsetting number).

A multi function device (like a disk) can have
multiple interfaces, all with the same interface number
but varying altsetting numbers and each of these
interfaces would list distict endpoint configurations.

Multiple interfaces can even share some endpoints (they
use the same endpoint addresses), but
we still have to duplicate them for each
interface+altsetting number (as they'r part of
actually distict interfaces with distict endpoint
configurations).

It is also important to *NOT* make endpoints bi-directional
(dir == Eboth) when only one direction is used in a
interface/altsetting and the other direction in another.
This was the case for nusb/disk with some seagate drive
where endpoints where shared between the UAS and
usb storage class interface (but with distict altsettings).

The duplicate endpoints (as in using the same endpoint address)
are chained together by a next pointer and the head
is stored in Usbdev.ep[addr], where addr is the endpoint
address. These Ep structures will have distinct endpoint
numbers Ep.id (when they have conflicting types), but all
will share the endpoint address (lower 4 bits of the
endpoint number).

The consequence is that all of the endpoints configuration
(attributes, interval) is now stored in the Ep struct and
no more Altc struct is present.

A pointer to the Ep struct has to be passed to openep()
for it to configure the endpoint.

For the Iface struct, we will now create multiple of them:
one for each interface *AND* altsetting nunber,
chained together on a next pointer and the head being
stored in conf->iface[ifaceid].

--
cinap
2022-02-21 19:50:16 +00:00
cinap_lenrek 2f28aaac65 nusb: don't create rw iso endpoints (by Michael Forney)
There may be two iso endpoints with the same ID if it is asynchronous
or adaptive (one for data, one for feedback), and rw iso endpoints are
unusable (error out with "iso i/o is half-duplex").
2021-02-10 20:08:13 +01:00
cinap_lenrek d7ade692c8 nusb: don't create rw iso endpoints (by Michael Forney)
There may be two iso endpoints with the same ID if it is asynchronous
or adaptive (one for data, one for feedback), and rw iso endpoints are
unusable (error out with "iso i/o is half-duplex").
2021-02-10 19:52:00 +01:00
Sigrid 0505f8fb3a nusb/lib: use fmtprint for the entire dump to be printed out 2020-08-23 12:14:32 +02:00
cinap_lenrek 3a4a3faf29 nusb/usbd: work around devices that ignore the high byte of wLength in control transfer reads
there appear to be devices out there such as Realtek RTL2838UHIDIR
SDR that do not process control transfers correctly, ignoring the
high byte of the wLength field. to work around this, we specify an
odd number of bytes for read sizes >= 256 which keeps the low byte
0xFF.
2019-05-07 09:19:53 +02:00
aiju a2d8dcfd82 usb lib: add maxpkt and ntds to Altc struct 2018-03-07 10:04:27 +00:00
cinap_lenrek 56ac6ea29e nusb/*: cleanup 2017-07-31 15:29:08 +02:00
cinap_lenrek 215b67ff3d nusb/usbd: create endpoint files for conf #1, usb3 preparation 2017-07-31 03:19:24 +02:00
cinap_lenrek a397bfd48c usb: fix wrong pollival calculation in setmaxpkt() 2017-07-24 23:47:55 +02:00
cinap_lenrek e0087b2a78 nusb/lib: make usbcmd() return value symmetic; returning size of data phase (if any) (thanks aiju)
usbcmd() with Rh2d used to return the command size (8+ndata) wile returning
only ndata for Rd2h. this changes it to always return ndata for Rh2d. it
mostly doesnt matter as Rh2d callers only check r < 0 for error, but this
makes the interface symmetic.
2017-04-01 22:19:58 +02:00
cinap_lenrek 9cb3e5900e nusb/lib: fix wrong endpoint id when openep() finds already existing endpoint file 2016-09-28 19:15:10 +02:00
cinap_lenrek 4ad63a4c56 nusb: fix spelling, sorry 2014-06-28 19:55:14 +02:00
cinap_lenrek 4275c49e72 nusb: implement aijus stable uniqueue device names
instead of naming devices by ther dynamically assigned device address,
we hash device uniqueue fields from the device descriptor and produce
a 5 digit hex string that will identify the device across machines.

when there is a collision (less than 1% chance with 100 devices),
usbd will append the device address to the name to make it uniqueue
for this machine.

the hname is passed to drivers in the devid argument, which now has
the form addr:hname, where the colon and hname can be omited (for backwards
compatibility).

when the new behaviour isnt desired, nousbhname= environment variable
can be defined giving the old behaviour.
2014-06-28 18:09:43 +02:00
cinap_lenrek 0753d7852d revert previous change, i was confused. 2014-04-24 22:02:47 +02:00
cinap_lenrek 634b40fe27 nusb: use ep->addr instead of ep->id in unstall() library function
this is not a bug, but using ep->addr makes the intend more clear.
2014-04-24 22:00:31 +02:00
cinap_lenrek 41908149de nusb: resolve endpoint id conflict with different input and output types
ftrvxmtrx repots devices that use the endpoint number for
input and output of different types like:

 nusb/ether:             parsedesc endpoint 5[7]  07 05 81 03 08 00 09	# ep1 in intr
 nusb/ether:             parsedesc endpoint 5[7]  07 05 82 02 00 02 00
 nusb/ether:             parsedesc endpoint 5[7]  07 05 01 02 00 02 00	# ep1 out bulk

the previous change tried to work arround this but had the
concequence that only the lastly defined endpoint was
usable.

this change addresses the issue by allowing up to 32 endpoints
per device (16 output + 16 input endpoints) in devusb. the
hci driver will ignore the 4th bit and will only use the
lower 4 bits as endpoint address when talking to the usb
device.

when we encounter a conflict, we map the input endpoint
to the upper id range 16..31 and the output endpoint
to id 0..15 so two distinct endpoints are created.
2014-04-23 20:03:01 +02:00
ftrvxmtrx 2ef8c9ed41 nusb: workaround for endpoints with same index but different types
nusb code assumes endpoint numbers are unique.  It's true in general
case, but it becomes false once the direction bit is ignored.  The
commit adds a check so that two endpoints of different types are not
merged into one with Eboth direction.  It does overwrite endpoint
though, so it shouldn't be considered as a full fix.
2014-04-23 23:45:00 +02:00
cinap_lenrek b94c766fef nusb: dont include <bio.h>, we'r not using it (thanks erik) 2014-04-19 16:18:39 +02:00
cinap_lenrek f88d0c372d nusb: fix loaddevstr() (thanks erik quanstro and richard miller)
loaddevstr() should request 256 bytes, as per standard and
respect the length embedded in the string.
2014-03-06 22:53:20 +01:00
ppatience0 473d12c94f nusb: only read 18 bytes for device descriptor 2013-07-05 18:42:15 -04:00
cinap_lenrek 3971337d13 nusb: provide language id when reading string descriptors (thanks ftrvxmtrx)
there are devices which do not return a string if used
with invalid language id, so at least try to use the first
one and choose english if failed.

this fixes CDC ethernet for N900
2012-12-10 10:36:53 +01:00
cinap_lenrek a064a48e6d nusb: handle 0 csp value on iface, remove unneeded configdev() calls after getdev() 2012-09-06 05:25:23 +02:00
cinap_lenrek 1404cc5077 nusb: fix documentation, cleanup, remove /sys/src/cmd/usb 2011-08-26 05:24:55 +02:00
aiju 05d09f086f nusb: improved 2011-07-27 20:07:30 +02:00