Changeset 20a3465 in mainline for uspace/lib/usbdev
- Timestamp:
- 2011-10-30T19:50:54Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 3ce78580, 48902fa
- Parents:
- 4c3ad56 (diff), 45bf63c (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - Location:
- uspace/lib/usbdev
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/usbdev/include/usb/dev/dp.h
r4c3ad56 r20a3465 59 59 typedef struct { 60 60 /** Used descriptor nesting. */ 61 usb_dp_descriptor_nesting_t *nesting;61 const usb_dp_descriptor_nesting_t *nesting; 62 62 } usb_dp_parser_t; 63 63 … … 65 65 typedef struct { 66 66 /** Data to be parsed. */ 67 uint8_t *data;67 const uint8_t *data; 68 68 /** Size of input data in bytes. */ 69 69 size_t size; … … 72 72 } usb_dp_parser_data_t; 73 73 74 uint8_t *usb_dp_get_nested_descriptor(usb_dp_parser_t *, 75 usb_dp_parser_data_t *, uint8_t *); 76 uint8_t *usb_dp_get_sibling_descriptor(usb_dp_parser_t *, 77 usb_dp_parser_data_t *, uint8_t *, uint8_t *); 74 typedef void (*walk_callback_t)(const uint8_t *, size_t, void *); 78 75 79 void usb_dp_walk_simple(uint8_t *, size_t, usb_dp_descriptor_nesting_t *, 80 void (*)(uint8_t *, size_t, void *), void *); 76 const uint8_t *usb_dp_get_nested_descriptor(const usb_dp_parser_t *, 77 const usb_dp_parser_data_t *, const uint8_t *); 78 const uint8_t *usb_dp_get_sibling_descriptor(const usb_dp_parser_t *, 79 const usb_dp_parser_data_t *, const uint8_t *, const uint8_t *); 80 81 void usb_dp_walk_simple(uint8_t *, size_t, const usb_dp_descriptor_nesting_t *, 82 walk_callback_t, void *); 81 83 82 84 #endif -
uspace/lib/usbdev/include/usb/dev/driver.h
r4c3ad56 r20a3465 43 43 usb_standard_device_descriptor_t device; 44 44 /** Full configuration descriptor of current configuration. */ 45 uint8_t *configuration;45 const uint8_t *configuration; 46 46 size_t configuration_size; 47 47 } usb_device_descriptors_t; … … 53 53 typedef struct { 54 54 /** Interface descriptor. */ 55 usb_standard_interface_descriptor_t *interface;55 const usb_standard_interface_descriptor_t *interface; 56 56 /** Pointer to start of descriptor tree bound with this interface. */ 57 uint8_t *nested_descriptors;57 const uint8_t *nested_descriptors; 58 58 /** Size of data pointed by nested_descriptors in bytes. */ 59 59 size_t nested_descriptors_size; … … 156 156 \endcode 157 157 */ 158 usb_endpoint_description_t **endpoints;158 const usb_endpoint_description_t **endpoints; 159 159 /** Driver ops. */ 160 usb_driver_ops_t *ops;160 const usb_driver_ops_t *ops; 161 161 } usb_driver_t; 162 162 163 int usb_driver_main( usb_driver_t *);163 int usb_driver_main(const usb_driver_t *); 164 164 165 165 int usb_device_select_interface(usb_device_t *, uint8_t, 166 usb_endpoint_description_t **);166 const usb_endpoint_description_t **); 167 167 168 168 int usb_device_retrieve_descriptors(usb_pipe_t *, usb_device_descriptors_t *); 169 169 int usb_device_create_pipes(const ddf_dev_t *, usb_device_connection_t *, 170 usb_endpoint_description_t **,uint8_t *, size_t, int, int,170 const usb_endpoint_description_t **, const uint8_t *, size_t, int, int, 171 171 usb_endpoint_mapping_t **, size_t *); 172 172 int usb_device_destroy_pipes(const ddf_dev_t *, usb_endpoint_mapping_t *, size_t); 173 int usb_device_create(ddf_dev_t *, usb_endpoint_description_t **, usb_device_t **, const char **); 174 void usb_device_destroy(usb_device_t *); 173 int usb_device_init(usb_device_t *, ddf_dev_t *, 174 const usb_endpoint_description_t **, const char **); 175 void usb_device_deinit(usb_device_t *); 175 176 176 size_t usb_interface_count_alternates(uint8_t *, size_t, uint8_t); 177 int usb_alternate_interfaces_create(uint8_t *, size_t, int, 177 void * usb_device_data_alloc(usb_device_t *, size_t); 178 179 size_t usb_interface_count_alternates(const uint8_t *, size_t, uint8_t); 180 int usb_alternate_interfaces_create(const uint8_t *, size_t, int, 178 181 usb_alternate_interfaces_t **); 179 182 void usb_alternate_interfaces_destroy(usb_alternate_interfaces_t *); 180 183 #endif 181 184 /** -
uspace/lib/usbdev/include/usb/dev/pipes.h
r4c3ad56 r20a3465 171 171 int usb_pipe_probe_default_control(usb_pipe_t *); 172 172 int usb_pipe_initialize_from_configuration(usb_endpoint_mapping_t *, 173 size_t, uint8_t *, size_t, usb_device_connection_t *);173 size_t, const uint8_t *, size_t, usb_device_connection_t *); 174 174 int usb_pipe_register_with_speed(usb_pipe_t *, usb_speed_t, 175 175 unsigned int, usb_hc_connection_t *); -
uspace/lib/usbdev/src/altiface.c
r4c3ad56 r20a3465 48 48 * @return Number of alternate interfaces for @p interface_no interface. 49 49 */ 50 size_t usb_interface_count_alternates( uint8_t *config_descr,50 size_t usb_interface_count_alternates(const uint8_t *config_descr, 51 51 size_t config_descr_size, uint8_t interface_no) 52 52 { … … 54 54 assert(config_descr_size > 0); 55 55 56 usb_dp_parser_t dp_parser = {56 const usb_dp_parser_t dp_parser = { 57 57 .nesting = usb_dp_standard_descriptor_nesting 58 58 }; 59 usb_dp_parser_data_t dp_data = {59 const usb_dp_parser_data_t dp_data = { 60 60 .data = config_descr, 61 61 .size = config_descr_size, … … 65 65 size_t alternate_count = 0; 66 66 67 uint8_t *iface_ptr = usb_dp_get_nested_descriptor(&dp_parser,67 const uint8_t *iface_ptr = usb_dp_get_nested_descriptor(&dp_parser, 68 68 &dp_data, config_descr); 69 69 while (iface_ptr != NULL) { … … 90 90 * @return Error code. 91 91 */ 92 int usb_alternate_interfaces_create( uint8_t *config_descr,92 int usb_alternate_interfaces_create(const uint8_t *config_descr, 93 93 size_t config_descr_size, int interface_number, 94 94 usb_alternate_interfaces_t **alternates_ptr) … … 98 98 assert(config_descr_size > 0); 99 99 100 *alternates_ptr = NULL; 100 101 if (interface_number < 0) { 101 alternates_ptr = NULL;102 102 return EOK; 103 103 } … … 105 105 usb_alternate_interfaces_t *alternates 106 106 = malloc(sizeof(usb_alternate_interfaces_t)); 107 108 107 if (alternates == NULL) { 109 108 return ENOMEM; … … 119 118 } 120 119 121 alternates->alternatives = malloc(alternates->alternative_count122 *sizeof(usb_alternate_interface_descriptors_t));120 alternates->alternatives = calloc(alternates->alternative_count, 121 sizeof(usb_alternate_interface_descriptors_t)); 123 122 if (alternates->alternatives == NULL) { 124 123 free(alternates); … … 140 139 = &alternates->alternatives[0]; 141 140 142 uint8_t *iface_ptr = usb_dp_get_nested_descriptor(&dp_parser,141 const uint8_t *iface_ptr = usb_dp_get_nested_descriptor(&dp_parser, 143 142 &dp_data, dp_data.data); 144 143 while (iface_ptr != NULL) { … … 160 159 dp_data.data, iface_ptr); 161 160 if (iface_ptr == NULL) { 162 uint8_t *next = dp_data.data + dp_data.size;161 const uint8_t *next = dp_data.data + dp_data.size; 163 162 cur_alt_iface->nested_descriptors_size 164 163 = next - cur_alt_iface->nested_descriptors; … … 176 175 } 177 176 178 177 void usb_alternate_interfaces_destroy(usb_alternate_interfaces_t *alternate) 178 { 179 if (!alternate) 180 return; 181 free(alternate->alternatives); 182 free(alternate); 183 } 179 184 /** 180 185 * @} -
uspace/lib/usbdev/src/devdrv.c
r4c3ad56 r20a3465 54 54 }; 55 55 56 static usb_driver_t *driver = NULL;56 static const usb_driver_t *driver = NULL; 57 57 58 58 … … 64 64 * @return Task exit status. 65 65 */ 66 int usb_driver_main( usb_driver_t *drv)66 int usb_driver_main(const usb_driver_t *drv) 67 67 { 68 68 assert(drv != NULL); … … 81 81 * @return Number of pipes (excluding default control pipe). 82 82 */ 83 static size_t count_other_pipes( usb_endpoint_description_t **endpoints)83 static size_t count_other_pipes(const usb_endpoint_description_t **endpoints) 84 84 { 85 85 size_t count = 0; … … 101 101 * @return Error code. 102 102 */ 103 static int initialize_other_pipes( usb_endpoint_description_t **endpoints,103 static int initialize_other_pipes(const usb_endpoint_description_t **endpoints, 104 104 usb_device_t *dev, int alternate_setting) 105 105 { … … 115 115 int rc = usb_device_create_pipes(dev->ddf_dev, &dev->wire, endpoints, 116 116 dev->descriptors.configuration, dev->descriptors.configuration_size, 117 dev->interface_no, alternate_setting, 118 &pipes, &pipes_count); 117 dev->interface_no, alternate_setting, &pipes, &pipes_count); 119 118 120 119 if (rc != EOK) { … … 141 140 assert(driver->ops->device_add); 142 141 143 int rc; 144 145 usb_device_t *dev = NULL; 142 usb_device_t *dev = ddf_dev_data_alloc(gen_dev, sizeof(usb_device_t)); 143 if (dev == NULL) { 144 usb_log_error("USB device `%s' structure allocation failed.\n", 145 gen_dev->name); 146 return ENOMEM; 147 } 146 148 const char *err_msg = NULL; 147 rc = usb_device_create(gen_dev, driver->endpoints, &dev, &err_msg);148 if (rc != EOK) { 149 usb_log_error("USB device `%s' creationfailed (%s): %s.\n",149 int rc = usb_device_init(dev, gen_dev, driver->endpoints, &err_msg); 150 if (rc != EOK) { 151 usb_log_error("USB device `%s' init failed (%s): %s.\n", 150 152 gen_dev->name, err_msg, str_error(rc)); 151 153 return rc; 152 154 } 153 gen_dev->driver_data = dev; 154 155 return driver->ops->device_add(dev); 155 156 rc = driver->ops->device_add(dev); 157 if (rc != EOK) 158 usb_device_deinit(dev); 159 return rc; 156 160 } 157 161 /*----------------------------------------------------------------------------*/ … … 186 190 if (driver->ops->device_gone == NULL) 187 191 return ENOTSUP; 188 const int ret = driver->ops->device_gone(gen_dev->driver_data); 192 usb_device_t *usb_dev = gen_dev->driver_data; 193 const int ret = driver->ops->device_gone(usb_dev); 189 194 if (ret == EOK) 190 usb_device_de stroy(gen_dev->driver_data);195 usb_device_deinit(usb_dev); 191 196 192 197 return ret; … … 235 240 */ 236 241 int usb_device_select_interface(usb_device_t *dev, uint8_t alternate_setting, 237 usb_endpoint_description_t **endpoints)242 const usb_endpoint_description_t **endpoints) 238 243 { 239 244 if (dev->interface_no < 0) { … … 318 323 */ 319 324 int usb_device_create_pipes(const ddf_dev_t *dev, usb_device_connection_t *wire, 320 usb_endpoint_description_t **endpoints,321 uint8_t *config_descr, size_t config_descr_size,325 const usb_endpoint_description_t **endpoints, 326 const uint8_t *config_descr, size_t config_descr_size, 322 327 int interface_no, int interface_setting, 323 328 usb_endpoint_mapping_t **pipes_ptr, size_t *pipes_count_ptr) … … 333 338 int rc; 334 339 335 size_t pipe_count = count_other_pipes(endpoints);340 const size_t pipe_count = count_other_pipes(endpoints); 336 341 if (pipe_count == 0) { 342 *pipes_count_ptr = pipe_count; 337 343 *pipes_ptr = NULL; 338 344 return EOK; … … 445 451 { 446 452 assert(dev != NULL); 447 assert(((pipes != NULL) && (pipes_count > 0))448 || ((pipes == NULL) && (pipes_count == 0)));449 453 450 454 if (pipes_count == 0) { 455 assert(pipes == NULL); 451 456 return EOK; 452 457 } 458 assert(pipes != NULL); 453 459 454 460 int rc; … … 468 474 size_t i; 469 475 for (i = 0; i < pipes_count; i++) { 470 usb_pipe_unregister(pipes[i].pipe, &hc_conn); 476 usb_log_debug2("Unregistering pipe %zu (%spresent).\n", 477 i, pipes[i].present ? "" : "not "); 478 if (pipes[i].present) 479 usb_pipe_unregister(pipes[i].pipe, &hc_conn); 471 480 free(pipes[i].pipe); 472 481 } … … 509 518 510 519 511 /** Create new instance of USB device. 512 * 520 /** Initialize new instance of USB device. 521 * 522 * @param[in] usb_dev Pointer to the new device. 513 523 * @param[in] ddf_dev Generic DDF device backing the USB one. 514 524 * @param[in] endpoints NULL terminated array of endpoints (NULL for none). 515 * @param[out] dev_ptr Where to store pointer to the new device.516 525 * @param[out] errstr_ptr Where to store description of context 517 526 * (in case error occurs). 518 527 * @return Error code. 519 528 */ 520 int usb_device_create(ddf_dev_t *ddf_dev, 521 usb_endpoint_description_t **endpoints, 522 usb_device_t **dev_ptr, const char **errstr_ptr) 523 { 524 assert(dev_ptr != NULL); 529 int usb_device_init(usb_device_t *usb_dev, ddf_dev_t *ddf_dev, 530 const usb_endpoint_description_t **endpoints, const char **errstr_ptr) 531 { 532 assert(usb_dev != NULL); 525 533 assert(ddf_dev != NULL); 526 534 527 int rc; 528 529 usb_device_t *dev = malloc(sizeof(usb_device_t)); 530 if (dev == NULL) { 531 *errstr_ptr = "structure allocation"; 532 return ENOMEM; 533 } 534 535 // FIXME: proper deallocation in case of errors 536 537 dev->ddf_dev = ddf_dev; 538 dev->driver_data = NULL; 539 dev->descriptors.configuration = NULL; 540 dev->alternate_interfaces = NULL; 541 542 dev->pipes_count = 0; 543 dev->pipes = NULL; 535 usb_dev->ddf_dev = ddf_dev; 536 usb_dev->driver_data = NULL; 537 usb_dev->descriptors.configuration = NULL; 538 usb_dev->alternate_interfaces = NULL; 539 usb_dev->pipes_count = 0; 540 usb_dev->pipes = NULL; 544 541 545 542 /* Initialize backing wire and control pipe. */ 546 rc = init_wire_and_ctrl_pipe(dev, errstr_ptr);543 int rc = init_wire_and_ctrl_pipe(usb_dev, errstr_ptr); 547 544 if (rc != EOK) { 548 545 return rc; … … 550 547 551 548 /* Get our interface. */ 552 dev->interface_no = usb_device_get_assigned_interface(dev->ddf_dev);549 usb_dev->interface_no = usb_device_get_assigned_interface(ddf_dev); 553 550 554 551 /* Retrieve standard descriptors. */ 555 rc = usb_device_retrieve_descriptors(&dev->ctrl_pipe, 556 &dev->descriptors); 557 if (rc != EOK) { 552 rc = usb_device_retrieve_descriptors(&usb_dev->ctrl_pipe, 553 &usb_dev->descriptors); 554 if (rc != EOK) { 555 /* Nothing allocated, nothing to free. */ 558 556 *errstr_ptr = "descriptor retrieval"; 559 557 return rc; 560 558 } 561 559 562 /* Create alternate interfaces. */ 563 rc = usb_alternate_interfaces_create(dev->descriptors.configuration, 564 dev->descriptors.configuration_size, dev->interface_no, 565 &dev->alternate_interfaces); 566 if (rc != EOK) { 567 /* We will try to silently ignore this. */ 568 dev->alternate_interfaces = NULL; 569 } 570 571 rc = initialize_other_pipes(endpoints, dev, 0); 572 if (rc != EOK) { 560 /* Create alternate interfaces. We will silently ignore failure. */ 561 //TODO Why ignore? 562 usb_alternate_interfaces_create(usb_dev->descriptors.configuration, 563 usb_dev->descriptors.configuration_size, usb_dev->interface_no, 564 &usb_dev->alternate_interfaces); 565 566 rc = initialize_other_pipes(endpoints, usb_dev, 0); 567 if (rc != EOK) { 568 /* Full configuration descriptor is allocated. */ 569 free(usb_dev->descriptors.configuration); 570 /* Alternate interfaces may be allocated */ 571 usb_alternate_interfaces_destroy(usb_dev->alternate_interfaces); 573 572 *errstr_ptr = "pipes initialization"; 574 573 return rc; … … 576 575 577 576 *errstr_ptr = NULL; 578 *dev_ptr = dev;579 577 580 578 return EOK; 581 579 } 582 580 583 /** Destroy instance of a USB device. 584 * 585 * @param dev Device to be destroyed. 586 */ 587 void usb_device_destroy(usb_device_t *dev) 588 { 589 if (dev == NULL) { 590 return; 591 } 592 593 /* Ignore errors and hope for the best. */ 594 usb_device_destroy_pipes(dev->ddf_dev, dev->pipes, dev->pipes_count); 595 free(dev->descriptors.configuration); 596 597 if (dev->alternate_interfaces != NULL) { 598 free(dev->alternate_interfaces->alternatives); 599 } 600 free(dev->alternate_interfaces); 601 602 free(dev); 581 /** Clean instance of a USB device. 582 * 583 * @param dev Device to be de-initialized. 584 * 585 * Does not free/destroy supplied pointer. 586 */ 587 void usb_device_deinit(usb_device_t *dev) 588 { 589 if (dev) { 590 /* Ignore errors and hope for the best. */ 591 destroy_current_pipes(dev); 592 593 usb_alternate_interfaces_destroy(dev->alternate_interfaces); 594 free(dev->descriptors.configuration); 595 free(dev->driver_data); 596 } 597 } 598 599 void * usb_device_data_alloc(usb_device_t *usb_dev, size_t size) 600 { 601 assert(usb_dev); 602 assert(usb_dev->driver_data == NULL); 603 return usb_dev->driver_data = calloc(1, size); 604 603 605 } 604 606 -
uspace/lib/usbdev/src/dp.c
r4c3ad56 r20a3465 75 75 * @return Whether @p ptr points inside <code>data->data</code> field. 76 76 */ 77 static bool is_valid_descriptor_pointer( usb_dp_parser_data_t *data,78 uint8_t *ptr)77 static bool is_valid_descriptor_pointer(const usb_dp_parser_data_t *data, 78 const uint8_t *ptr) 79 79 { 80 80 if (ptr == NULL) { … … 100 100 * @retval NULL Invalid input or no next descriptor. 101 101 */ 102 static uint8_t *get_next_descriptor(usb_dp_parser_data_t *data,103 uint8_t *current)102 static const uint8_t *get_next_descriptor(const usb_dp_parser_data_t *data, 103 const uint8_t *current) 104 104 { 105 105 assert(is_valid_descriptor_pointer(data, current)); 106 106 107 uint8_t current_length = *current;108 uint8_t *next = current + current_length;107 const uint8_t current_length = *current; 108 const uint8_t *next = current + current_length; 109 109 110 110 if (!is_valid_descriptor_pointer(data, next)) { … … 124 124 * @retval -1 Invalid input. 125 125 */ 126 static int get_descriptor_type( usb_dp_parser_data_t *data,uint8_t *start)126 static int get_descriptor_type(const usb_dp_parser_data_t *data, const uint8_t *start) 127 127 { 128 128 if (start == NULL) { … … 145 145 * @return Whether @p child could be child of @p parent. 146 146 */ 147 static bool is_nested_descriptor_type( usb_dp_parser_t *parser,147 static bool is_nested_descriptor_type(const usb_dp_parser_t *parser, 148 148 int child, int parent) 149 149 { 150 usb_dp_descriptor_nesting_t *nesting = parser->nesting;150 const usb_dp_descriptor_nesting_t *nesting = parser->nesting; 151 151 while ((nesting->child > 0) && (nesting->parent > 0)) { 152 152 if ((nesting->child == child) && (nesting->parent == parent)) { … … 166 166 * @return Whether @p child could be child of @p parent. 167 167 */ 168 static bool is_nested_descriptor( usb_dp_parser_t *parser,169 usb_dp_parser_data_t *data, uint8_t *child,uint8_t *parent)168 static bool is_nested_descriptor(const usb_dp_parser_t *parser, 169 const usb_dp_parser_data_t *data, const uint8_t *child, const uint8_t *parent) 170 170 { 171 171 return is_nested_descriptor_type(parser, … … 183 183 * @retval NULL Invalid input. 184 184 */ 185 uint8_t *usb_dp_get_nested_descriptor(usb_dp_parser_t *parser,186 usb_dp_parser_data_t *data,uint8_t *parent)185 const uint8_t *usb_dp_get_nested_descriptor(const usb_dp_parser_t *parser, 186 const usb_dp_parser_data_t *data, const uint8_t *parent) 187 187 { 188 188 if (!is_valid_descriptor_pointer(data, parent)) { … … 190 190 } 191 191 192 uint8_t *next = get_next_descriptor(data, parent);192 const uint8_t *next = get_next_descriptor(data, parent); 193 193 if (next == NULL) { 194 194 return NULL; … … 211 211 * @retval NULL Invalid input. 212 212 */ 213 static uint8_t *skip_nested_descriptors(usb_dp_parser_t *parser, 214 usb_dp_parser_data_t *data, uint8_t *parent) 215 { 216 uint8_t *child = usb_dp_get_nested_descriptor(parser, data, parent); 213 static const uint8_t *skip_nested_descriptors(const usb_dp_parser_t *parser, 214 const usb_dp_parser_data_t *data, const uint8_t *parent) 215 { 216 const uint8_t *child = 217 usb_dp_get_nested_descriptor(parser, data, parent); 217 218 if (child == NULL) { 218 219 return get_next_descriptor(data, parent); 219 220 } 220 uint8_t *next_child = skip_nested_descriptors(parser, data, child); 221 const uint8_t *next_child = 222 skip_nested_descriptors(parser, data, child); 221 223 while (is_nested_descriptor(parser, data, next_child, parent)) { 222 224 next_child = skip_nested_descriptors(parser, data, next_child); … … 236 238 * @retval NULL Invalid input. 237 239 */ 238 uint8_t *usb_dp_get_sibling_descriptor(usb_dp_parser_t *parser, 239 usb_dp_parser_data_t *data, uint8_t *parent, uint8_t *sibling) 240 const uint8_t *usb_dp_get_sibling_descriptor( 241 const usb_dp_parser_t *parser, const usb_dp_parser_data_t *data, 242 const uint8_t *parent, const uint8_t *sibling) 240 243 { 241 244 if (!is_valid_descriptor_pointer(data, parent) … … 244 247 } 245 248 246 uint8_t *possible_sibling = skip_nested_descriptors(parser, data, sibling); 249 const uint8_t *possible_sibling = 250 skip_nested_descriptors(parser, data, sibling); 247 251 if (possible_sibling == NULL) { 248 252 return NULL; … … 269 273 * @param arg Custom (user) argument. 270 274 */ 271 static void usb_dp_browse_simple_internal( usb_dp_parser_t *parser,272 usb_dp_parser_data_t *data,uint8_t *root, size_t depth,273 void (*callback)( uint8_t *, size_t, void *), void *arg)275 static void usb_dp_browse_simple_internal(const usb_dp_parser_t *parser, 276 const usb_dp_parser_data_t *data, const uint8_t *root, size_t depth, 277 void (*callback)(const uint8_t *, size_t, void *), void *arg) 274 278 { 275 279 if (root == NULL) { … … 277 281 } 278 282 callback(root, depth, arg); 279 uint8_t *child = usb_dp_get_nested_descriptor(parser, data, root);283 const uint8_t *child = usb_dp_get_nested_descriptor(parser, data, root); 280 284 do { 281 285 usb_dp_browse_simple_internal(parser, data, child, depth + 1, … … 301 305 */ 302 306 void usb_dp_walk_simple(uint8_t *descriptors, size_t descriptors_size, 303 usb_dp_descriptor_nesting_t *descriptor_nesting,304 void (*callback)(uint8_t *, size_t, void *), void *arg)307 const usb_dp_descriptor_nesting_t *descriptor_nesting, 308 walk_callback_t callback, void *arg) 305 309 { 306 310 if ((descriptors == NULL) || (descriptors_size == 0) … … 309 313 } 310 314 311 usb_dp_parser_data_t data = {315 const usb_dp_parser_data_t data = { 312 316 .data = descriptors, 313 317 .size = descriptors_size, … … 315 319 }; 316 320 317 usb_dp_parser_t parser = {321 const usb_dp_parser_t parser = { 318 322 .nesting = descriptor_nesting 319 323 }; -
uspace/lib/usbdev/src/pipesinit.c
r4c3ad56 r20a3465 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 /* … … 224 224 static int process_interface( 225 225 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,226 const usb_dp_parser_t *parser, const usb_dp_parser_data_t *parser_data, 227 const uint8_t *interface_descriptor) 228 { 229 const uint8_t *descriptor = usb_dp_get_nested_descriptor(parser, 230 230 parser_data, interface_descriptor); 231 231 … … 284 284 int usb_pipe_initialize_from_configuration( 285 285 usb_endpoint_mapping_t *mapping, size_t mapping_count, 286 uint8_t *configuration_descriptor, size_t configuration_descriptor_size,286 const uint8_t *config_descriptor, size_t config_descriptor_size, 287 287 usb_device_connection_t *connection) 288 288 { 289 289 assert(connection); 290 290 291 if (config uration_descriptor == NULL) {291 if (config_descriptor == NULL) { 292 292 return EBADMEM; 293 293 } 294 if (config uration_descriptor_size294 if (config_descriptor_size 295 295 < sizeof(usb_standard_configuration_descriptor_t)) { 296 296 return ERANGE; … … 310 310 * Prepare the descriptor parser. 311 311 */ 312 usb_dp_parser_t dp_parser = {312 const usb_dp_parser_t dp_parser = { 313 313 .nesting = descriptor_nesting 314 314 }; 315 usb_dp_parser_data_t dp_data = {316 .data = config uration_descriptor,317 .size = config uration_descriptor_size,315 const usb_dp_parser_data_t dp_data = { 316 .data = config_descriptor, 317 .size = config_descriptor_size, 318 318 .arg = connection 319 319 }; … … 322 322 * Iterate through all interfaces. 323 323 */ 324 uint8_t *interface = usb_dp_get_nested_descriptor(&dp_parser,325 &dp_data, config uration_descriptor);324 const uint8_t *interface = usb_dp_get_nested_descriptor(&dp_parser, 325 &dp_data, config_descriptor); 326 326 if (interface == NULL) { 327 327 return ENOENT; … … 329 329 do { 330 330 (void) process_interface(mapping, mapping_count, 331 &dp_parser, &dp_data, 332 interface); 331 &dp_parser, &dp_data, interface); 333 332 interface = usb_dp_get_sibling_descriptor(&dp_parser, &dp_data, 334 config uration_descriptor, interface);333 config_descriptor, interface); 335 334 } while (interface != NULL); 336 335 … … 514 513 { 515 514 assert(pipe); 515 assert(pipe->wire); 516 516 assert(hc_connection); 517 517 -
uspace/lib/usbdev/src/request.c
r4c3ad56 r20a3465 425 425 426 426 /* Everything is okay, copy the descriptor. */ 427 memcpy(descriptor, &descriptor_tmp, 428 sizeof(descriptor_tmp)); 427 memcpy(descriptor, &descriptor_tmp, sizeof(descriptor_tmp)); 429 428 430 429 return EOK; … … 470 469 471 470 /* Everything is okay, copy the descriptor. */ 472 memcpy(descriptor, &descriptor_tmp, 473 sizeof(descriptor_tmp)); 471 memcpy(descriptor, &descriptor_tmp, sizeof(descriptor_tmp)); 474 472 475 473 return EOK;
Note:
See TracChangeset
for help on using the changeset viewer.