Changeset e3f7418 in mainline for uspace/lib/usbdev/src
- Timestamp:
- 2011-10-15T13:06:28Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- a044f71
- Parents:
- 3958e315 (diff), 065064e6 (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/src
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/usbdev/src/altiface.c
r3958e315 re3f7418 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) … … 140 140 = &alternates->alternatives[0]; 141 141 142 uint8_t *iface_ptr = usb_dp_get_nested_descriptor(&dp_parser,142 const uint8_t *iface_ptr = usb_dp_get_nested_descriptor(&dp_parser, 143 143 &dp_data, dp_data.data); 144 144 while (iface_ptr != NULL) { … … 160 160 dp_data.data, iface_ptr); 161 161 if (iface_ptr == NULL) { 162 uint8_t *next = dp_data.data + dp_data.size;162 const uint8_t *next = dp_data.data + dp_data.size; 163 163 cur_alt_iface->nested_descriptors_size 164 164 = next - cur_alt_iface->nested_descriptors; -
uspace/lib/usbdev/src/devdrv.c
r3958e315 re3f7418 54 54 }; 55 55 56 static usb_driver_t *driver = NULL;56 static const usb_driver_t *driver = NULL; 57 57 58 58 … … 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) { … … 153 152 gen_dev->driver_data = dev; 154 153 155 return driver->ops->device_add(dev); 154 rc = driver->ops->device_add(dev); 155 if (rc != EOK) 156 usb_device_destroy(dev); 157 return rc; 156 158 } 157 159 /*----------------------------------------------------------------------------*/ … … 186 188 if (driver->ops->device_gone == NULL) 187 189 return ENOTSUP; 188 const int ret = driver->ops->device_gone(gen_dev->driver_data); 190 usb_device_t *usb_dev = gen_dev->driver_data; 191 const int ret = driver->ops->device_gone(usb_dev); 189 192 if (ret == EOK) 190 usb_device_destroy( gen_dev->driver_data);193 usb_device_destroy(usb_dev); 191 194 192 195 return ret; … … 319 322 int usb_device_create_pipes(const ddf_dev_t *dev, usb_device_connection_t *wire, 320 323 usb_endpoint_description_t **endpoints, 321 uint8_t *config_descr, size_t config_descr_size,324 const uint8_t *config_descr, size_t config_descr_size, 322 325 int interface_no, int interface_setting, 323 326 usb_endpoint_mapping_t **pipes_ptr, size_t *pipes_count_ptr) … … 333 336 int rc; 334 337 335 size_t pipe_count = count_other_pipes(endpoints);338 const size_t pipe_count = count_other_pipes(endpoints); 336 339 if (pipe_count == 0) { 340 *pipes_count_ptr = pipe_count; 337 341 *pipes_ptr = NULL; 338 342 return EOK; … … 445 449 { 446 450 assert(dev != NULL); 447 assert(((pipes != NULL) && (pipes_count > 0))448 || ((pipes == NULL) && (pipes_count == 0)));449 451 450 452 if (pipes_count == 0) { 453 assert(pipes == NULL); 451 454 return EOK; 452 455 } 456 assert(pipes != NULL); 453 457 454 458 int rc; … … 468 472 size_t i; 469 473 for (i = 0; i < pipes_count; i++) { 470 usb_pipe_unregister(pipes[i].pipe, &hc_conn); 474 usb_log_debug2("Unregistering pipe %zu (%spresent).\n", 475 i, pipes[i].present ? "" : "not "); 476 if (pipes[i].present) 477 usb_pipe_unregister(pipes[i].pipe, &hc_conn); 471 478 free(pipes[i].pipe); 472 479 } … … 592 599 593 600 /* 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); 601 destroy_current_pipes(dev); 596 602 597 603 if (dev->alternate_interfaces != NULL) { … … 599 605 } 600 606 free(dev->alternate_interfaces); 601 602 free(dev); 607 free(dev->descriptors.configuration); 608 free(dev->driver_data); 609 } 610 611 void * usb_device_data_alloc(usb_device_t *usb_dev, size_t size) 612 { 613 assert(usb_dev); 614 assert(usb_dev->driver_data == NULL); 615 return usb_dev->driver_data = calloc(1, size); 616 603 617 } 604 618 -
uspace/lib/usbdev/src/dp.c
r3958e315 re3f7418 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
r3958e315 re3f7418 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
r3958e315 re3f7418 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.