From 20d3fb62776233cfb6e156d814308d7c80118380 Mon Sep 17 00:00:00 2001 From: Florian Grandel Date: Wed, 27 Nov 2024 19:52:27 +0100 Subject: [PATCH] ethernet: add missing UNION functional descriptor 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 --- src/ethernet.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/ethernet.rs b/src/ethernet.rs index 1034502..4d4b45e 100644 --- a/src/ethernet.rs +++ b/src/ethernet.rs @@ -504,6 +504,7 @@ impl UsbClass 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; @@ -542,6 +543,19 @@ impl UsbClass 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) {