Skip to content

Commit

Permalink
ethernet: add missing UNION functional descriptor
Browse files Browse the repository at this point in the history
Add the required UNION functional descriptor (see USBNCM10, 5.2,
table 5-1 and USBCDC12, 5.2.3.1).

On Linux the network interface will otherwise not be recognized.

Signed-off-by: Florian Grandel <[email protected]>
  • Loading branch information
Florian Grandel committed Nov 27, 2024
1 parent 8d26950 commit 20d3fb6
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/ethernet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,7 @@ impl<B: UsbBus> UsbClass<B> for Ethernet<'_, B> {
const CDC_PROTOCOL_NTB: u8 = 0x01;
const CDC_SUBCLASS_NCM: u8 = 0x0d;
const CDC_TYPE_ETHERNET: u8 = 0x0F;
const CDC_TYPE_UNION: u8 = 0x06;
const CDC_TYPE_HEADER: u8 = 0x00;
const CDC_TYPE_NCM: u8 = 0x1A;
const CS_INTERFACE: u8 = 0x24;
Expand Down Expand Up @@ -542,6 +543,19 @@ impl<B: UsbBus> UsbClass<B> for Ethernet<'_, B> {
}
})?;

writer.write_with(CS_INTERFACE, |buf| {
const LEN: usize = 3;
if let Some(mut buf) = buf.get_mut(..LEN) {
buf.put_u8(CDC_TYPE_UNION); // bDescriptorSubtype
buf.put_u8(u8::from(self.comm_if)); // bControlInterface
buf.put_u8(u8::from(self.data_if)); // bSubordinateInterface0
assert!(!buf.has_remaining_mut());
Ok(LEN)
} else {
Err(UsbError::BufferOverflow)
}
})?;

writer.write_with(CS_INTERFACE, |buf| {
const LEN: usize = 11;
if let Some(mut buf) = buf.get_mut(..LEN) {
Expand Down

0 comments on commit 20d3fb6

Please sign in to comment.