@@ -112,74 +112,78 @@ uint16_t btd_open(uint8_t rhport, tusb_desc_interface_t const *itf_desc, uint16_
112112 TUD_BT_APP_SUBCLASS == itf_desc -> bInterfaceSubClass &&
113113 TUD_BT_PROTOCOL_PRIMARY_CONTROLLER == itf_desc -> bInterfaceProtocol , 0 );
114114
115- // Distinguish interface by number of endpoints, as both interface have same class, subclass and protocol
116- if (itf_desc -> bNumEndpoints == 3 && max_len >= hci_itf_size )
117- {
118- _btd_itf .itf_num = itf_desc -> bInterfaceNumber ;
115+ TU_ASSERT (itf_desc -> bNumEndpoints == 3 && max_len >= hci_itf_size );
119116
120- desc_ep = ( tusb_desc_endpoint_t const * ) tu_desc_next ( itf_desc ) ;
117+ _btd_itf . itf_num = itf_desc -> bInterfaceNumber ;
121118
122- TU_ASSERT (TUSB_DESC_ENDPOINT == desc_ep -> bDescriptorType && TUSB_XFER_INTERRUPT == desc_ep -> bmAttributes .xfer , 0 );
123- TU_ASSERT (usbd_edpt_open (rhport , desc_ep ), 0 );
124- _btd_itf .ep_ev = desc_ep -> bEndpointAddress ;
119+ desc_ep = (tusb_desc_endpoint_t const * ) tu_desc_next (itf_desc );
125120
126- // Open endpoint pair
127- TU_ASSERT (usbd_open_edpt_pair (rhport , tu_desc_next ( desc_ep ), 2 , TUSB_XFER_BULK , & _btd_itf . ep_acl_out ,
128- & _btd_itf .ep_acl_in ), 0 ) ;
121+ TU_ASSERT ( TUSB_DESC_ENDPOINT == desc_ep -> bDescriptorType && TUSB_XFER_INTERRUPT == desc_ep -> bmAttributes . xfer , 0 );
122+ TU_ASSERT (usbd_edpt_open (rhport , desc_ep ), 0 );
123+ _btd_itf .ep_ev = desc_ep -> bEndpointAddress ;
129124
130- // Prepare for incoming data from host
131- TU_ASSERT (usbd_edpt_xfer (rhport , _btd_itf .ep_acl_out , _btd_itf .epout_buf , CFG_TUD_BTH_DATA_EPSIZE ), 0 );
125+ // Open endpoint pair
126+ TU_ASSERT (usbd_open_edpt_pair (rhport , tu_desc_next (desc_ep ), 2 , TUSB_XFER_BULK , & _btd_itf .ep_acl_out ,
127+ & _btd_itf .ep_acl_in ), 0 );
132128
133- drv_len = hci_itf_size ;
134- }
135- else if (itf_desc -> bNumEndpoints == 2 && max_len >= iso_alt_itf_size )
136- {
137- uint8_t dir ;
129+ itf_desc = (tusb_desc_interface_t const * )tu_desc_next (tu_desc_next (tu_desc_next (desc_ep )));
138130
139- desc_ep = (tusb_desc_endpoint_t const * )tu_desc_next (itf_desc );
131+ // Prepare for incoming data from host
132+ TU_ASSERT (usbd_edpt_xfer (rhport , _btd_itf .ep_acl_out , _btd_itf .epout_buf , CFG_TUD_BTH_DATA_EPSIZE ), 0 );
133+
134+ drv_len = hci_itf_size ;
135+
136+ // Ensure this is still BT Primary Controller
137+ TU_ASSERT (TUSB_CLASS_WIRELESS_CONTROLLER == itf_desc -> bInterfaceClass &&
138+ TUD_BT_APP_SUBCLASS == itf_desc -> bInterfaceSubClass &&
139+ TUD_BT_PROTOCOL_PRIMARY_CONTROLLER == itf_desc -> bInterfaceProtocol , 0 );
140+ TU_ASSERT (itf_desc -> bNumEndpoints == 2 && max_len >= iso_alt_itf_size + drv_len );
141+
142+ uint8_t dir ;
143+
144+ desc_ep = (tusb_desc_endpoint_t const * )tu_desc_next (itf_desc );
145+ TU_ASSERT (itf_desc -> bAlternateSetting < CFG_TUD_BTH_ISO_ALT_COUNT , 0 );
146+ TU_ASSERT (desc_ep -> bDescriptorType == TUSB_DESC_ENDPOINT , 0 );
147+ dir = tu_edpt_dir (desc_ep -> bEndpointAddress );
148+ _btd_itf .ep_voice [dir ] = desc_ep -> bEndpointAddress ;
149+ // Store endpoint size for alternative
150+ _btd_itf .ep_voice_size [dir ][itf_desc -> bAlternateSetting ] = (uint8_t ) tu_edpt_packet_size (desc_ep );
151+
152+ desc_ep = (tusb_desc_endpoint_t const * )tu_desc_next (desc_ep );
153+ TU_ASSERT (desc_ep -> bDescriptorType == TUSB_DESC_ENDPOINT , 0 );
154+ dir = tu_edpt_dir (desc_ep -> bEndpointAddress );
155+ _btd_itf .ep_voice [dir ] = desc_ep -> bEndpointAddress ;
156+ // Store endpoint size for alternative
157+ _btd_itf .ep_voice_size [dir ][itf_desc -> bAlternateSetting ] = (uint8_t ) tu_edpt_packet_size (desc_ep );
158+ drv_len += iso_alt_itf_size ;
159+
160+ for (int i = 1 ; i < CFG_TUD_BTH_ISO_ALT_COUNT && drv_len + iso_alt_itf_size <= max_len ; ++ i ) {
161+ // Make sure rest of alternatives matches
162+ itf_desc = (tusb_desc_interface_t const * )tu_desc_next (desc_ep );
163+ if (itf_desc -> bDescriptorType != TUSB_DESC_INTERFACE ||
164+ TUSB_CLASS_WIRELESS_CONTROLLER != itf_desc -> bInterfaceClass ||
165+ TUD_BT_APP_SUBCLASS != itf_desc -> bInterfaceSubClass ||
166+ TUD_BT_PROTOCOL_PRIMARY_CONTROLLER != itf_desc -> bInterfaceProtocol )
167+ {
168+ // Not an Iso interface instance
169+ break ;
170+ }
140171 TU_ASSERT (itf_desc -> bAlternateSetting < CFG_TUD_BTH_ISO_ALT_COUNT , 0 );
141- TU_ASSERT (desc_ep -> bDescriptorType == TUSB_DESC_ENDPOINT , 0 );
172+
173+ desc_ep = (tusb_desc_endpoint_t const * )tu_desc_next (itf_desc );
142174 dir = tu_edpt_dir (desc_ep -> bEndpointAddress );
143- _btd_itf .ep_voice [dir ] = desc_ep -> bEndpointAddress ;
144- // Store endpoint size for alternative
175+ // Verify that alternative endpoint are same as first ones
176+ TU_ASSERT (desc_ep -> bDescriptorType == TUSB_DESC_ENDPOINT &&
177+ _btd_itf .ep_voice [dir ] == desc_ep -> bEndpointAddress , 0 );
145178 _btd_itf .ep_voice_size [dir ][itf_desc -> bAlternateSetting ] = (uint8_t ) tu_edpt_packet_size (desc_ep );
146179
147180 desc_ep = (tusb_desc_endpoint_t const * )tu_desc_next (desc_ep );
148- TU_ASSERT (desc_ep -> bDescriptorType == TUSB_DESC_ENDPOINT , 0 );
149181 dir = tu_edpt_dir (desc_ep -> bEndpointAddress );
150- _btd_itf .ep_voice [dir ] = desc_ep -> bEndpointAddress ;
151- // Store endpoint size for alternative
182+ // Verify that alternative endpoint are same as first ones
183+ TU_ASSERT (desc_ep -> bDescriptorType == TUSB_DESC_ENDPOINT &&
184+ _btd_itf .ep_voice [dir ] == desc_ep -> bEndpointAddress , 0 );
152185 _btd_itf .ep_voice_size [dir ][itf_desc -> bAlternateSetting ] = (uint8_t ) tu_edpt_packet_size (desc_ep );
153186 drv_len += iso_alt_itf_size ;
154-
155- for (int i = 1 ; i < CFG_TUD_BTH_ISO_ALT_COUNT && drv_len + iso_alt_itf_size <= max_len ; ++ i ) {
156- // Make sure rest of alternatives matches
157- itf_desc = (tusb_desc_interface_t const * )tu_desc_next (desc_ep );
158- if (itf_desc -> bDescriptorType != TUSB_DESC_INTERFACE ||
159- TUSB_CLASS_WIRELESS_CONTROLLER != itf_desc -> bInterfaceClass ||
160- TUD_BT_APP_SUBCLASS != itf_desc -> bInterfaceSubClass ||
161- TUD_BT_PROTOCOL_PRIMARY_CONTROLLER != itf_desc -> bInterfaceProtocol )
162- {
163- // Not an Iso interface instance
164- break ;
165- }
166- TU_ASSERT (itf_desc -> bAlternateSetting < CFG_TUD_BTH_ISO_ALT_COUNT , 0 );
167-
168- desc_ep = (tusb_desc_endpoint_t const * )tu_desc_next (itf_desc );
169- dir = tu_edpt_dir (desc_ep -> bEndpointAddress );
170- // Verify that alternative endpoint are same as first ones
171- TU_ASSERT (desc_ep -> bDescriptorType == TUSB_DESC_ENDPOINT &&
172- _btd_itf .ep_voice [dir ] == desc_ep -> bEndpointAddress , 0 );
173- _btd_itf .ep_voice_size [dir ][itf_desc -> bAlternateSetting ] = (uint8_t ) tu_edpt_packet_size (desc_ep );
174-
175- desc_ep = (tusb_desc_endpoint_t const * )tu_desc_next (desc_ep );
176- dir = tu_edpt_dir (desc_ep -> bEndpointAddress );
177- // Verify that alternative endpoint are same as first ones
178- TU_ASSERT (desc_ep -> bDescriptorType == TUSB_DESC_ENDPOINT &&
179- _btd_itf .ep_voice [dir ] == desc_ep -> bEndpointAddress , 0 );
180- _btd_itf .ep_voice_size [dir ][itf_desc -> bAlternateSetting ] = (uint8_t ) tu_edpt_packet_size (desc_ep );
181- drv_len += iso_alt_itf_size ;
182- }
183187 }
184188
185189 return drv_len ;
0 commit comments