Skip to content

Commit ff14e88

Browse files
tmon-nordicbjarki-andreasen
authored andcommitted
[nrf fromtree] usb: device_next: Update IAD first interface on init
IAD must be before the interfaces it associates and therefore there is no need for the class to be in charge of updating the bFirstInterface. Update IAD in common initialization code and remove the updates from classes. This fixes UAC2 instances where the IAD bFirstInterface is not 0, e.g. when HID was used together with UAC2. Signed-off-by: Tomasz Moń <[email protected]> (cherry picked from commit 9006780)
1 parent fead2a2 commit ff14e88

File tree

5 files changed

+10
-12
lines changed

5 files changed

+10
-12
lines changed

subsys/usb/device_next/class/bt_hci.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -459,11 +459,7 @@ static void *bt_hci_get_desc(struct usbd_class_data *const c_data,
459459

460460
static int bt_hci_init(struct usbd_class_data *const c_data)
461461
{
462-
463-
struct bt_hci_data *data = usbd_class_get_private(c_data);
464-
struct usbd_bt_hci_desc *desc = data->desc;
465-
466-
desc->iad.bFirstInterface = desc->if0.bInterfaceNumber;
462+
ARG_UNUSED(c_data);
467463

468464
return 0;
469465
}

subsys/usb/device_next/class/loopback.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,6 @@ static void *lb_get_desc(struct usbd_class_data *const c_data,
135135

136136
static int lb_init(struct usbd_class_data *c_data)
137137
{
138-
struct lb_data *data = usbd_class_get_private(c_data);
139-
struct loopback_desc *desc = data->desc;
140-
141-
desc->iad.bFirstInterface = desc->if0.bInterfaceNumber;
142-
143138
LOG_DBG("Init class instance %p", c_data);
144139

145140
return 0;

subsys/usb/device_next/class/usbd_cdc_acm.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,6 @@ static int usbd_cdc_acm_init(struct usbd_class_data *const c_data)
473473
struct cdc_acm_uart_data *data = dev->data;
474474
struct usbd_cdc_acm_desc *desc = data->desc;
475475

476-
desc->iad.bFirstInterface = desc->if0.bInterfaceNumber;
477476
desc->if0_union.bControlInterface = desc->if0.bInterfaceNumber;
478477
desc->if0_union.bSubordinateInterface0 = desc->if1.bInterfaceNumber;
479478

subsys/usb/device_next/class/usbd_cdc_ecm.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,6 @@ static int usbd_cdc_ecm_init(struct usbd_class_data *const c_data)
449449
const uint8_t if_num = desc->if0.bInterfaceNumber;
450450

451451
/* Update relevant b*Interface fields */
452-
desc->iad.bFirstInterface = if_num;
453452
desc->if0_union.bControlInterface = if_num;
454453
desc->if0_union.bSubordinateInterface0 = if_num + 1;
455454
LOG_DBG("CDC ECM class initialized");

subsys/usb/device_next/usbd_init.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ static int init_configuration_inst(struct usbd_context *const uds_ctx,
115115
uint8_t *const nif)
116116
{
117117
struct usb_desc_header **dhp;
118+
struct usb_association_descriptor *iad = NULL;
118119
struct usb_if_descriptor *ifd = NULL;
119120
struct usb_ep_descriptor *ed;
120121
uint32_t class_ep_bm = 0;
@@ -132,6 +133,14 @@ static int init_configuration_inst(struct usbd_context *const uds_ctx,
132133
c_nd->ep_active = 0U;
133134

134135
while (*dhp != NULL && (*dhp)->bLength != 0) {
136+
if ((*dhp)->bDescriptorType == USB_DESC_INTERFACE_ASSOC) {
137+
iad = (struct usb_association_descriptor *)(*dhp);
138+
139+
/* IAD must be before interfaces it associates, so the
140+
* first interface will be the next interface assigned.
141+
*/
142+
iad->bFirstInterface = tmp_nif;
143+
}
135144

136145
if ((*dhp)->bDescriptorType == USB_DESC_INTERFACE) {
137146
ifd = (struct usb_if_descriptor *)(*dhp);

0 commit comments

Comments
 (0)