Changes in uspace/lib/usbdev/src/pipesinit.c [365e29e2:3ddbd38] in mainline
- File:
-
- 1 edited
-
uspace/lib/usbdev/src/pipesinit.c (modified) (17 diffs)
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/usbdev/src/pipesinit.c
r365e29e2 r3ddbd38 54 54 55 55 /** Nesting pairs of standard descriptors. */ 56 static usb_dp_descriptor_nesting_t descriptor_nesting[] = {56 static const usb_dp_descriptor_nesting_t descriptor_nesting[] = { 57 57 NESTING(CONFIGURATION, INTERFACE), 58 58 NESTING(INTERFACE, ENDPOINT), … … 68 68 * @return Whether the given descriptor is endpoint descriptor. 69 69 */ 70 static inline bool is_endpoint_descriptor( uint8_t *descriptor)70 static inline bool is_endpoint_descriptor(const uint8_t *descriptor) 71 71 { 72 72 return descriptor[1] == USB_DESCTYPE_ENDPOINT; … … 80 80 */ 81 81 static bool endpoint_fits_description(const usb_endpoint_description_t *wanted, 82 usb_endpoint_description_t *found)82 const usb_endpoint_description_t *found) 83 83 { 84 84 #define _SAME(fieldname) ((wanted->fieldname) == (found->fieldname)) … … 120 120 static usb_endpoint_mapping_t *find_endpoint_mapping( 121 121 usb_endpoint_mapping_t *mapping, size_t mapping_count, 122 usb_endpoint_description_t *found_endpoint,122 const usb_endpoint_description_t *found_endpoint, 123 123 int interface_number, int interface_setting) 124 124 { … … 160 160 usb_device_connection_t *wire) 161 161 { 162 usb_endpoint_description_t description;163 162 164 163 /* … … 167 166 168 167 /* Actual endpoint number is in bits 0..3 */ 169 usb_endpoint_t ep_no = endpoint->endpoint_address & 0x0F; 170 171 /* Endpoint direction is set by bit 7 */ 172 description.direction = (endpoint->endpoint_address & 128) 173 ? USB_DIRECTION_IN : USB_DIRECTION_OUT; 174 /* Transfer type is in bits 0..2 and the enum values corresponds 1:1 */ 175 description.transfer_type = endpoint->attributes & 3; 176 177 /* 178 * Get interface characteristics. 179 */ 180 description.interface_class = interface->interface_class; 181 description.interface_subclass = interface->interface_subclass; 182 description.interface_protocol = interface->interface_protocol; 168 const usb_endpoint_t ep_no = endpoint->endpoint_address & 0x0F; 169 170 const usb_endpoint_description_t description = { 171 /* Endpoint direction is set by bit 7 */ 172 .direction = (endpoint->endpoint_address & 128) 173 ? USB_DIRECTION_IN : USB_DIRECTION_OUT, 174 /* Transfer type is in bits 0..2 and 175 * the enum values corresponds 1:1 */ 176 .transfer_type = endpoint->attributes & 3, 177 178 /* Get interface characteristics. */ 179 .interface_class = interface->interface_class, 180 .interface_subclass = interface->interface_subclass, 181 .interface_protocol = interface->interface_protocol, 182 }; 183 183 184 184 /* … … 192 192 } 193 193 194 if (ep_mapping->pipe == NULL) {195 return EBADMEM;196 }197 194 if (ep_mapping->present) { 198 195 return EEXISTS; 199 196 } 200 197 201 int rc = usb_pipe_initialize( ep_mapping->pipe, wire,198 int rc = usb_pipe_initialize(&ep_mapping->pipe, wire, 202 199 ep_no, description.transfer_type, endpoint->max_packet_size, 203 200 description.direction); … … 224 221 static int process_interface( 225 222 usb_endpoint_mapping_t *mapping, size_t mapping_count, 226 usb_dp_parser_t *parser,usb_dp_parser_data_t *parser_data,227 uint8_t *interface_descriptor)228 { 229 uint8_t *descriptor = usb_dp_get_nested_descriptor(parser,223 const usb_dp_parser_t *parser, const usb_dp_parser_data_t *parser_data, 224 const uint8_t *interface_descriptor) 225 { 226 const uint8_t *descriptor = usb_dp_get_nested_descriptor(parser, 230 227 parser_data, interface_descriptor); 231 228 … … 254 251 * 255 252 * The mapping array is expected to conform to following rules: 256 * - @c pipe must point to already allocated structure withuninitialized pipe253 * - @c pipe must be uninitialized pipe 257 254 * - @c description must point to prepared endpoint description 258 255 * - @c descriptor does not need to be initialized (will be overwritten) … … 284 281 int usb_pipe_initialize_from_configuration( 285 282 usb_endpoint_mapping_t *mapping, size_t mapping_count, 286 uint8_t *configuration_descriptor, size_t configuration_descriptor_size,283 const uint8_t *config_descriptor, size_t config_descriptor_size, 287 284 usb_device_connection_t *connection) 288 285 { 289 286 assert(connection); 290 287 291 if (config uration_descriptor == NULL) {288 if (config_descriptor == NULL) { 292 289 return EBADMEM; 293 290 } 294 if (config uration_descriptor_size291 if (config_descriptor_size 295 292 < sizeof(usb_standard_configuration_descriptor_t)) { 296 293 return ERANGE; 297 294 } 298 295 299 /* 300 * Go through the mapping and set all endpoints to not present. 301 */ 302 size_t i; 303 for (i = 0; i < mapping_count; i++) { 296 /* Go through the mapping and set all endpoints to not present. */ 297 for (size_t i = 0; i < mapping_count; i++) { 304 298 mapping[i].present = false; 305 299 mapping[i].descriptor = NULL; … … 307 301 } 308 302 309 /* 310 * Prepare the descriptor parser. 311 */ 312 usb_dp_parser_t dp_parser = { 303 /* Prepare the descriptor parser. */ 304 const usb_dp_parser_t dp_parser = { 313 305 .nesting = descriptor_nesting 314 306 }; 315 usb_dp_parser_data_t dp_data = {316 .data = config uration_descriptor,317 .size = config uration_descriptor_size,307 const usb_dp_parser_data_t dp_data = { 308 .data = config_descriptor, 309 .size = config_descriptor_size, 318 310 .arg = connection 319 311 }; … … 322 314 * Iterate through all interfaces. 323 315 */ 324 uint8_t *interface = usb_dp_get_nested_descriptor(&dp_parser,325 &dp_data, config uration_descriptor);316 const uint8_t *interface = usb_dp_get_nested_descriptor(&dp_parser, 317 &dp_data, config_descriptor); 326 318 if (interface == NULL) { 327 319 return ENOENT; … … 329 321 do { 330 322 (void) process_interface(mapping, mapping_count, 331 &dp_parser, &dp_data, 332 interface); 323 &dp_parser, &dp_data, interface); 333 324 interface = usb_dp_get_sibling_descriptor(&dp_parser, &dp_data, 334 config uration_descriptor, interface);325 config_descriptor, interface); 335 326 } while (interface != NULL); 336 327 … … 414 405 } 415 406 416 #define TRY_LOOP(attempt_var) \417 for (attempt_var = 0; attempt_var < 3; attempt_var++)418 419 size_t failed_attempts;420 int rc;421 407 422 408 usb_pipe_start_long_transfer(pipe); … … 424 410 uint8_t dev_descr_start[CTRL_PIPE_MIN_PACKET_SIZE]; 425 411 size_t transferred_size; 426 TRY_LOOP(failed_attempts) { 412 int rc; 413 for (size_t attempt_var = 0; attempt_var < 3; ++attempt_var) { 427 414 rc = usb_request_get_descriptor(pipe, USB_REQUEST_TYPE_STANDARD, 428 415 USB_REQUEST_RECIPIENT_DEVICE, USB_DESCTYPE_DEVICE, … … 455 442 * @return Error code. 456 443 */ 457 int usb_pipe_register(usb_pipe_t *pipe, 458 unsigned int interval, 444 int usb_pipe_register(usb_pipe_t *pipe, unsigned interval, 459 445 usb_hc_connection_t *hc_connection) 460 446 { 461 return usb_pipe_register_with_speed(pipe, USB_SPEED_MAX + 1,462 interval, hc_connection);463 }464 465 /** Register endpoint with a speed at the host controller.466 *467 * You will rarely need to use this function because it is needed only468 * if the registered endpoint is of address 0 and there is no other way469 * to tell speed of the device at address 0.470 *471 * @param pipe Pipe to be registered.472 * @param speed Speed of the device473 * (invalid speed means use previously specified one).474 * @param interval Polling interval.475 * @param hc_connection Connection to the host controller (must be opened).476 * @return Error code.477 */478 int usb_pipe_register_with_speed(usb_pipe_t *pipe, usb_speed_t speed,479 unsigned int interval,480 usb_hc_connection_t *hc_connection)481 {482 447 assert(pipe); 448 assert(pipe->wire); 483 449 assert(hc_connection); 484 450 485 451 if (!usb_hc_connection_is_opened(hc_connection)) 486 452 return EBADF; 487 488 const usb_target_t target =489 {{ .address = pipe->wire->address, .endpoint = pipe->endpoint_no }};490 #define _PACK2(high, low) (((high) << 16) + (low))491 #define _PACK3(high, middle, low) (((((high) << 8) + (middle)) << 8) + (low))492 493 453 async_exch_t *exch = async_exchange_begin(hc_connection->hc_sess); 494 int rc = async_req_4_0(exch, DEV_IFACE_ID(USBHC_DEV_IFACE), 495 IPC_M_USBHC_REGISTER_ENDPOINT, target.packed, 496 _PACK3(speed, pipe->transfer_type, pipe->direction), 497 _PACK2(pipe->max_packet_size, interval)); 454 if (!exch) 455 return ENOMEM; 456 const int ret = usbhc_register_endpoint(exch, 457 pipe->wire->address, pipe->endpoint_no, pipe->transfer_type, 458 pipe->direction, pipe->max_packet_size, interval); 459 498 460 async_exchange_end(exch); 499 500 #undef _PACK2 501 #undef _PACK3 502 503 return rc; 461 return ret; 504 462 } 505 463 … … 514 472 { 515 473 assert(pipe); 474 assert(pipe->wire); 516 475 assert(hc_connection); 517 476 518 477 if (!usb_hc_connection_is_opened(hc_connection)) 519 478 return EBADF; 520 479 521 480 async_exch_t *exch = async_exchange_begin(hc_connection->hc_sess); 522 int rc = async_req_4_0(exch, DEV_IFACE_ID(USBHC_DEV_IFACE), 523 IPC_M_USBHC_UNREGISTER_ENDPOINT, 481 if (!exch) 482 return ENOMEM; 483 const int ret = usbhc_unregister_endpoint(exch, 524 484 pipe->wire->address, pipe->endpoint_no, pipe->direction); 525 485 async_exchange_end(exch); 526 527 return r c;486 487 return ret; 528 488 } 529 489
Note:
See TracChangeset
for help on using the changeset viewer.
