Changes in uspace/lib/usbdev/src/pipesinit.c [1a2227d:b7fd2a0] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/usbdev/src/pipesinit.c
r1a2227d rb7fd2a0 38 38 #include <usb/dev/request.h> 39 39 #include <usb/usb.h> 40 #include <usb/debug.h>41 40 #include <usb/descriptor.h> 42 41 … … 60 59 NESTING(INTERFACE, HID), 61 60 NESTING(HID, HID_REPORT), 62 NESTING(ENDPOINT, SSPEED_EP_COMPANION),63 61 LAST_NESTING 64 62 }; … … 72 70 { 73 71 return descriptor[1] == USB_DESCTYPE_ENDPOINT; 74 }75 76 /** Tells whether given descriptor is of superspeed companion type.77 *78 * @param descriptor Descriptor in question.79 * @return Whether the given descriptor is superspeed companion descriptor.80 */81 static inline bool is_superspeed_companion_descriptor(const uint8_t *descriptor)82 {83 return descriptor[1] == USB_DESCTYPE_SSPEED_EP_COMPANION;84 72 } 85 73 … … 146 134 if (interface_number_fits 147 135 && interface_setting_fits 148 && endpoint_descriptions_fits 149 && !mapping->present) { 136 && endpoint_descriptions_fits) { 150 137 return mapping; 151 138 } … … 154 141 mapping_count--; 155 142 } 156 157 143 return NULL; 158 144 } … … 164 150 * @param interface Interface descriptor under which belongs the @p endpoint. 165 151 * @param endpoint Endpoint descriptor. 166 * @param companion Superspeed companion descriptor.167 152 * @return Error code. 168 153 */ 169 static int process_endpoint(154 static errno_t process_endpoint( 170 155 usb_endpoint_mapping_t *mapping, size_t mapping_count, 171 156 usb_standard_interface_descriptor_t *interface, 172 157 usb_standard_endpoint_descriptor_t *endpoint_desc, 173 usb_superspeed_endpoint_companion_descriptor_t *companion_desc,174 158 usb_dev_session_t *bus_session) 175 159 { … … 178 162 * Get endpoint characteristics. 179 163 */ 164 165 /* Actual endpoint number is in bits 0..3 */ 166 const usb_endpoint_t ep_no = endpoint_desc->endpoint_address & 0x0F; 167 180 168 const usb_endpoint_description_t description = { 181 .transfer_type = USB_ED_GET_TRANSFER_TYPE(*endpoint_desc), 182 .direction = USB_ED_GET_DIR(*endpoint_desc), 169 /* Endpoint direction is set by bit 7 */ 170 .direction = (endpoint_desc->endpoint_address & 128) 171 ? USB_DIRECTION_IN : USB_DIRECTION_OUT, 172 /* Transfer type is in bits 0..2 and 173 * the enum values corresponds 1:1 */ 174 .transfer_type = endpoint_desc->attributes & 3, 183 175 184 176 /* Get interface characteristics. */ … … 202 194 } 203 195 204 int err = usb_pipe_initialize(&ep_mapping->pipe, bus_session); 205 if (err) 206 return err; 196 errno_t rc = usb_pipe_initialize(&ep_mapping->pipe, 197 ep_no, description.transfer_type, 198 ED_MPS_PACKET_SIZE_GET( 199 uint16_usb2host(endpoint_desc->max_packet_size)), 200 description.direction, 201 ED_MPS_TRANS_OPPORTUNITIES_GET( 202 uint16_usb2host(endpoint_desc->max_packet_size)), bus_session); 203 if (rc != EOK) { 204 return rc; 205 } 207 206 208 207 ep_mapping->present = true; 209 208 ep_mapping->descriptor = endpoint_desc; 210 ep_mapping->companion_descriptor = companion_desc;211 209 ep_mapping->interface = interface; 212 210 … … 223 221 * @return Error code. 224 222 */ 225 static int process_interface(223 static errno_t process_interface( 226 224 usb_endpoint_mapping_t *mapping, size_t mapping_count, 227 225 const usb_dp_parser_t *parser, const usb_dp_parser_data_t *parser_data, … … 237 235 do { 238 236 if (is_endpoint_descriptor(descriptor)) { 239 /* Check if companion descriptor is present too, it should immediatelly follow. */240 const uint8_t *companion_desc = usb_dp_get_nested_descriptor(parser,241 parser_data, descriptor);242 if (companion_desc && !is_superspeed_companion_descriptor(companion_desc)) {243 /* Not what we wanted, don't pass it further. */244 companion_desc = NULL;245 }246 247 237 (void) process_endpoint(mapping, mapping_count, 248 238 (usb_standard_interface_descriptor_t *) … … 250 240 (usb_standard_endpoint_descriptor_t *) 251 241 descriptor, 252 (usb_superspeed_endpoint_companion_descriptor_t *)253 companion_desc,254 242 bus_session); 255 243 } … … 293 281 * @return Error code. 294 282 */ 295 int usb_pipe_initialize_from_configuration(283 errno_t usb_pipe_initialize_from_configuration( 296 284 usb_endpoint_mapping_t *mapping, size_t mapping_count, 297 285 const uint8_t *config_descriptor, size_t config_descriptor_size, … … 300 288 if (config_descriptor == NULL) 301 289 return EBADMEM; 302 290 303 291 if (config_descriptor_size < 304 292 sizeof(usb_standard_configuration_descriptor_t)) { … … 340 328 } 341 329 330 /** Probe default control pipe for max packet size. 331 * 332 * The function tries to get the correct value of max packet size several 333 * time before giving up. 334 * 335 * The session on the pipe shall not be started. 336 * 337 * @param pipe Default control pipe. 338 * @return Error code. 339 */ 340 errno_t usb_pipe_probe_default_control(usb_pipe_t *pipe) 341 { 342 assert(pipe); 343 static_assert(DEV_DESCR_MAX_PACKET_SIZE_OFFSET < CTRL_PIPE_MIN_PACKET_SIZE); 344 345 if ((pipe->direction != USB_DIRECTION_BOTH) || 346 (pipe->transfer_type != USB_TRANSFER_CONTROL) || 347 (pipe->endpoint_no != 0)) { 348 return EINVAL; 349 } 350 351 uint8_t dev_descr_start[CTRL_PIPE_MIN_PACKET_SIZE]; 352 size_t transferred_size; 353 errno_t rc; 354 for (size_t attempt_var = 0; attempt_var < 3; ++attempt_var) { 355 rc = usb_request_get_descriptor(pipe, USB_REQUEST_TYPE_STANDARD, 356 USB_REQUEST_RECIPIENT_DEVICE, USB_DESCTYPE_DEVICE, 357 0, 0, dev_descr_start, CTRL_PIPE_MIN_PACKET_SIZE, 358 &transferred_size); 359 if (rc == EOK) { 360 if (transferred_size != CTRL_PIPE_MIN_PACKET_SIZE) { 361 rc = ELIMIT; 362 continue; 363 } 364 break; 365 } 366 } 367 if (rc != EOK) { 368 return rc; 369 } 370 371 pipe->max_packet_size 372 = dev_descr_start[DEV_DESCR_MAX_PACKET_SIZE_OFFSET]; 373 374 return EOK; 375 } 376 342 377 /** 343 378 * @}
Note:
See TracChangeset
for help on using the changeset viewer.