Changeset e3f7418 in mainline
- Timestamp:
- 2011-10-15T13:06:28Z (13 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
- Files:
-
- 38 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/usbinfo/desctree.c
r3958e315 re3f7418 50 50 51 51 static void browse_descriptor_tree_internal(usb_dp_parser_t *parser, 52 usb_dp_parser_data_t *data, uint8_t *root, size_t depth,52 usb_dp_parser_data_t *data, const uint8_t *root, size_t depth, 53 53 dump_descriptor_in_tree_t callback, void *arg) 54 54 { … … 57 57 } 58 58 callback(root, depth, arg); 59 uint8_t *child = usb_dp_get_nested_descriptor(parser, data, root);59 const uint8_t *child = usb_dp_get_nested_descriptor(parser, data, root); 60 60 do { 61 61 browse_descriptor_tree_internal(parser, data, child, depth + 1, -
uspace/app/usbinfo/dump.c
r3958e315 re3f7418 110 110 } 111 111 112 static void dump_tree_descriptor( uint8_t *descriptor, size_t depth)112 static void dump_tree_descriptor(const uint8_t *descriptor, size_t depth) 113 113 { 114 114 if (descriptor == NULL) { 115 115 return; 116 116 } 117 int type = (int) *(descriptor + 1);117 int type = descriptor[1]; 118 118 const char *name = "unknown"; 119 119 switch (type) { … … 136 136 } 137 137 138 static void dump_tree_internal(usb_dp_parser_t *parser, usb_dp_parser_data_t *data, 139 uint8_t *root, size_t depth) 138 static void dump_tree_internal( 139 usb_dp_parser_t *parser, usb_dp_parser_data_t *data, 140 const uint8_t *root, size_t depth) 140 141 { 141 142 if (root == NULL) { … … 143 144 } 144 145 dump_tree_descriptor(root, depth); 145 uint8_t *child = usb_dp_get_nested_descriptor(parser, data, root);146 const uint8_t *child = usb_dp_get_nested_descriptor(parser, data, root); 146 147 do { 147 148 dump_tree_internal(parser, data, child, depth + 1); … … 152 153 static void dump_tree(usb_dp_parser_t *parser, usb_dp_parser_data_t *data) 153 154 { 154 uint8_t *ptr = data->data;155 const uint8_t *ptr = data->data; 155 156 printf("Descriptor tree:\n"); 156 157 dump_tree_internal(parser, data, ptr, 0); -
uspace/app/usbinfo/hid.c
r3958e315 re3f7418 55 55 } descriptor_walk_context_t; 56 56 57 static bool is_descriptor_kind( uint8_t *d, usb_descriptor_type_t t)57 static bool is_descriptor_kind(const uint8_t *d, usb_descriptor_type_t t) 58 58 { 59 59 if (d == NULL) { … … 180 180 * @param arg Custom argument, passed as descriptor_walk_context_t. 181 181 */ 182 static void descriptor_walk_callback( uint8_t *raw_descriptor,182 static void descriptor_walk_callback(const uint8_t *raw_descriptor, 183 183 size_t depth, void *arg) 184 184 { -
uspace/app/usbinfo/info.c
r3958e315 re3f7418 51 51 } 52 52 53 static void dump_match_ids_from_interface( uint8_t *descriptor, size_t depth,54 void *arg)53 static void dump_match_ids_from_interface( 54 const uint8_t *descriptor, size_t depth, void *arg) 55 55 { 56 56 if (depth != 1) { … … 165 165 166 166 167 static void dump_descriptor_tree_callback( uint8_t *descriptor,168 size_t depth, void *arg)167 static void dump_descriptor_tree_callback( 168 const uint8_t *descriptor, size_t depth, void *arg) 169 169 { 170 170 const char *indent = get_indent(depth + 1); … … 246 246 } 247 247 248 static void find_string_indexes_callback( uint8_t *descriptor,249 size_t depth, void *arg)248 static void find_string_indexes_callback( 249 const uint8_t *descriptor, size_t depth, void *arg) 250 250 { 251 251 size_t descriptor_length = descriptor[0]; -
uspace/app/usbinfo/usbinfo.h
r3958e315 re3f7418 74 74 void destroy_device(usbinfo_device_t *); 75 75 76 typedef void (*dump_descriptor_in_tree_t)( uint8_t *, size_t, void *);76 typedef void (*dump_descriptor_in_tree_t)(const uint8_t *, size_t, void *); 77 77 void browse_descriptor_tree(uint8_t *, size_t, usb_dp_descriptor_nesting_t *, 78 78 dump_descriptor_in_tree_t, size_t, void *); -
uspace/drv/bus/usb/usbflbk/main.c
r3958e315 re3f7418 64 64 } 65 65 66 dev->driver_data = ctl_fun; 67 66 68 usb_log_info("Pretending to control %s `%s'" \ 67 69 " (node `%s', handle %" PRIun ").\n", … … 72 74 } 73 75 76 /** Callback when new device is removed and recognized as gone by DDF. 77 * 78 * @param dev Representation of a generic DDF device. 79 * @return Error code. 80 */ 81 static int usbfallback_device_gone(usb_device_t *dev) 82 { 83 assert(dev); 84 ddf_fun_t *ctl_fun = dev->driver_data; 85 const int ret = ddf_fun_unbind(ctl_fun); 86 if (ret != EOK) { 87 usb_log_error("Failed to unbind %s.\n", ctl_fun->name); 88 return ret; 89 } 90 ddf_fun_destroy(ctl_fun); 91 dev->driver_data = NULL; 92 93 return EOK; 94 } 74 95 /** USB fallback driver ops. */ 75 96 static usb_driver_ops_t usbfallback_driver_ops = { 76 97 .device_add = usbfallback_device_add, 98 .device_gone = usbfallback_device_gone, 77 99 }; 78 100 -
uspace/drv/bus/usb/usbhid/generic/hiddev.c
r3958e315 re3f7418 52 52 .direction = USB_DIRECTION_IN, 53 53 .interface_class = USB_CLASS_HID, 54 .interface_subclass = -1, 55 .interface_protocol = -1, 54 56 .flags = 0 55 57 }; … … 92 94 usb_log_debug2("Generic HID: Get event length (fun: %p, " 93 95 "fun->driver_data: %p.\n", fun, fun->driver_data); 94 96 95 97 if (fun == NULL || fun->driver_data == NULL) { 96 98 return 0; … … 98 100 99 101 usb_hid_dev_t *hid_dev = (usb_hid_dev_t *)fun->driver_data; 100 102 101 103 usb_log_debug2("hid_dev: %p, Max input report size (%zu).\n", 102 104 hid_dev, hid_dev->max_input_report_size); 103 105 104 106 return hid_dev->max_input_report_size; 105 107 } … … 111 113 { 112 114 usb_log_debug2("Generic HID: Get event.\n"); 113 115 114 116 if (fun == NULL || fun->driver_data == NULL || buffer == NULL 115 117 || act_size == NULL || event_nr == NULL) { … … 119 121 120 122 usb_hid_dev_t *hid_dev = (usb_hid_dev_t *)fun->driver_data; 121 123 122 124 if (hid_dev->input_report_size > size) { 123 125 usb_log_debug("input_report_size > size (%zu, %zu)\n", … … 125 127 return EINVAL; // TODO: other error code 126 128 } 127 129 128 130 /*! @todo This should probably be somehow atomic. */ 129 131 memcpy(buffer, hid_dev->input_report, … … 131 133 *act_size = hid_dev->input_report_size; 132 134 *event_nr = usb_hid_report_number(hid_dev); 133 135 134 136 usb_log_debug2("OK\n"); 135 137 136 138 return EOK; 137 139 } … … 142 144 { 143 145 usb_log_debug("Generic HID: Get report descriptor length.\n"); 144 146 145 147 if (fun == NULL || fun->driver_data == NULL) { 146 148 usb_log_debug("No function"); 147 149 return EINVAL; 148 150 } 149 150 usb_hid_dev_t *hid_dev = (usb_hid_dev_t *)fun->driver_data; 151 151 152 usb_hid_dev_t *hid_dev = (usb_hid_dev_t *)fun->driver_data; 153 152 154 usb_log_debug2("hid_dev->report_desc_size = %zu\n", 153 155 hid_dev->report_desc_size); 154 156 155 157 return hid_dev->report_desc_size; 156 158 } … … 162 164 { 163 165 usb_log_debug2("Generic HID: Get report descriptor.\n"); 164 166 165 167 if (fun == NULL || fun->driver_data == NULL) { 166 168 usb_log_debug("No function"); 167 169 return EINVAL; 168 170 } 169 170 usb_hid_dev_t *hid_dev = (usb_hid_dev_t *)fun->driver_data; 171 171 172 usb_hid_dev_t *hid_dev = (usb_hid_dev_t *)fun->driver_data; 173 172 174 if (hid_dev->report_desc_size > size) { 173 175 return EINVAL; 174 176 } 175 177 176 178 memcpy(desc, hid_dev->report_desc, hid_dev->report_desc_size); 177 179 *actual_size = hid_dev->report_desc_size; 178 180 179 181 return EOK; 180 182 } … … 190 192 /*----------------------------------------------------------------------------*/ 191 193 192 static int usb_generic_hid_create_function(usb_hid_dev_t *hid_dev) 193 { 194 void usb_generic_hid_deinit(usb_hid_dev_t *hid_dev, void *data) 195 { 196 ddf_fun_t *fun = data; 197 const int ret = ddf_fun_unbind(fun); 198 if (ret != EOK) { 199 usb_log_error("Failed to unbind generic hid fun.\n"); 200 return; 201 } 202 usb_log_debug2("%s unbound.\n", fun->name); 203 /* We did not allocate this, so leave this alone 204 * the device would take care of it */ 205 fun->driver_data = NULL; 206 ddf_fun_destroy(fun); 207 } 208 209 /*----------------------------------------------------------------------------*/ 210 211 int usb_generic_hid_init(usb_hid_dev_t *hid_dev, void **data) 212 { 213 if (hid_dev == NULL) { 214 return EINVAL; 215 } 216 194 217 /* Create the exposed function. */ 195 218 /** @todo Generate numbers for the devices? */ … … 201 224 return ENOMEM; 202 225 } 203 226 204 227 fun->ops = &usb_generic_hid_ops; 205 fun->driver_data = hid_dev;206 228 207 229 int rc = ddf_fun_bind(fun); … … 212 234 return rc; 213 235 } 214 236 /* This is nasty both device and this function have the same 237 * driver data, thus destruction would lead to double free */ 238 fun->driver_data = hid_dev; 239 215 240 usb_log_debug("HID function created. Handle: %" PRIun "\n", fun->handle); 216 217 return EOK; 218 } 219 220 /*----------------------------------------------------------------------------*/ 221 222 int usb_generic_hid_init(usb_hid_dev_t *hid_dev, void **data) 223 { 224 if (hid_dev == NULL) { 225 return EINVAL; 226 } 227 228 return usb_generic_hid_create_function(hid_dev); 241 *data = fun; 242 243 return EOK; 229 244 } 230 245 -
uspace/drv/bus/usb/usbhid/generic/hiddev.h
r3958e315 re3f7418 50 50 int usb_generic_hid_init(struct usb_hid_dev *hid_dev, void **data); 51 51 52 void usb_generic_hid_deinit(struct usb_hid_dev *hid_dev, void *data); 53 52 54 bool usb_generic_hid_polling_callback(struct usb_hid_dev *hid_dev, void *data); 53 55 -
uspace/drv/bus/usb/usbhid/kbd/conv.c
r3958e315 re3f7418 87 87 [0x26] = KC_9, 88 88 [0x27] = KC_0, 89 89 90 90 [0x28] = KC_ENTER, 91 91 [0x29] = KC_ESCAPE, … … 109 109 110 110 [0x39] = KC_CAPS_LOCK, 111 111 112 112 [0x3a] = KC_F1, 113 113 [0x3b] = KC_F2, … … 122 122 [0x44] = KC_F11, 123 123 [0x45] = KC_F12, 124 124 125 125 [0x46] = KC_PRTSCR, 126 126 [0x47] = KC_SCROLL_LOCK, … … 136 136 [0x51] = KC_DOWN, 137 137 [0x52] = KC_UP, 138 138 139 139 //[0x64] = // some funny key 140 140 141 141 [0xe0] = KC_LCTRL, 142 142 [0xe1] = KC_LSHIFT, … … 147 147 [0xe6] = KC_RALT, 148 148 //[0xe7] = KC_R // TODO: right GUI 149 149 150 150 [0x53] = KC_NUM_LOCK, 151 151 [0x54] = KC_NSLASH, … … 165 165 [0x62] = KC_N0, 166 166 [0x63] = KC_NPERIOD 167 167 168 168 }; 169 169 … … 186 186 187 187 key = map[scancode]; 188 188 189 189 return key; 190 190 } -
uspace/drv/bus/usb/usbhid/kbd/kbddev.c
r3958e315 re3f7418 174 174 { 175 175 sysarg_t method = IPC_GET_IMETHOD(*icall); 176 176 177 177 usb_kbd_t *kbd_dev = (usb_kbd_t *) fun->driver_data; 178 178 if (kbd_dev == NULL) { … … 182 182 return; 183 183 } 184 184 185 185 async_sess_t *sess = 186 186 async_callback_receive_start(EXCHANGE_SERIALIZE, icall); … … 240 240 USB_HID_PATH_COMPARE_END | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY, 241 241 USB_HID_REPORT_TYPE_OUTPUT); 242 242 243 243 while (field != NULL) { 244 244 … … 263 263 USB_HID_REPORT_TYPE_OUTPUT); 264 264 } 265 265 266 266 // TODO: what about the Report ID? 267 267 int rc = usb_hid_report_output_translate(hid_dev->report, 0, 268 268 kbd_dev->output_buffer, kbd_dev->output_size); 269 269 270 270 if (rc != EOK) { 271 271 usb_log_warning("Error translating LED output to output report" … … 273 273 return; 274 274 } 275 275 276 276 usb_log_debug("Output report buffer: %s\n", 277 277 usb_debug_str_buffer(kbd_dev->output_buffer, kbd_dev->output_size, 278 278 0)); 279 279 280 280 usbhid_req_set_report(&hid_dev->usb_dev->ctrl_pipe, 281 281 hid_dev->usb_dev->interface_no, USB_HID_REPORT_TYPE_OUTPUT, … … 300 300 return; 301 301 } 302 302 303 303 async_exch_t *exch = async_exchange_begin(kbd_dev->console_sess); 304 304 async_msg_2(exch, KBDEV_EVENT, type, key); … … 347 347 unsigned int key; 348 348 size_t i; 349 349 350 350 /* 351 351 * First of all, check if the kbd have reported phantom state. … … 362 362 return; 363 363 } 364 364 365 365 /* 366 366 * Key releases … … 382 382 } 383 383 } 384 384 385 385 /* 386 386 * Key presses … … 402 402 } 403 403 } 404 404 405 405 memcpy(kbd_dev->keys_old, kbd_dev->keys, kbd_dev->key_count * 4); 406 406 407 407 char key_buffer[512]; 408 408 ddf_dump_buffer(key_buffer, 512, … … 435 435 assert(hid_dev != NULL); 436 436 assert(kbd_dev != NULL); 437 437 438 438 usb_hid_report_path_t *path = usb_hid_report_path(); 439 439 usb_hid_report_path_append_item(path, USB_HIDUT_PAGE_KEYBOARD, 0); 440 440 441 441 usb_hid_report_path_set_report_id (path, hid_dev->report_id); 442 442 443 443 // fill in the currently pressed keys 444 444 445 445 usb_hid_report_field_t *field = usb_hid_report_get_sibling( 446 446 hid_dev->report, NULL, path, … … 448 448 USB_HID_REPORT_TYPE_INPUT); 449 449 unsigned i = 0; 450 450 451 451 while (field != NULL) { 452 452 usb_log_debug2("FIELD (%p) - VALUE(%d) USAGE(%u)\n", … … 470 470 USB_HID_REPORT_TYPE_INPUT); 471 471 } 472 472 473 473 usb_hid_report_path_free(path); 474 474 475 475 usb_kbd_check_key_changes(hid_dev, kbd_dev); 476 476 } … … 502 502 503 503 if (kbd_dev == NULL) { 504 usb_log_ fatal("No memory!\n");504 usb_log_error("No memory!\n"); 505 505 return NULL; 506 506 } 507 507 508 508 kbd_dev->console_sess = NULL; 509 509 kbd_dev->initialized = USB_KBD_STATUS_UNINITIALIZED; 510 510 511 511 return kbd_dev; 512 512 } … … 514 514 /*----------------------------------------------------------------------------*/ 515 515 516 static int usb_kbd_create_function(usb_hid_dev_t *hid_dev, usb_kbd_t *kbd_dev) 517 { 518 assert(hid_dev != NULL); 519 assert(hid_dev->usb_dev != NULL); 516 static int usb_kbd_create_function(usb_kbd_t *kbd_dev) 517 { 520 518 assert(kbd_dev != NULL); 521 519 assert(kbd_dev->hid_dev != NULL); 520 assert(kbd_dev->hid_dev->usb_dev != NULL); 521 522 522 /* Create the exposed function. */ 523 523 usb_log_debug("Creating DDF function %s...\n", HID_KBD_FUN_NAME); 524 ddf_fun_t *fun = ddf_fun_create( hid_dev->usb_dev->ddf_dev, fun_exposed,525 HID_KBD_FUN_NAME);524 ddf_fun_t *fun = ddf_fun_create(kbd_dev->hid_dev->usb_dev->ddf_dev, 525 fun_exposed, HID_KBD_FUN_NAME); 526 526 if (fun == NULL) { 527 527 usb_log_error("Could not create DDF function node.\n"); 528 528 return ENOMEM; 529 529 } 530 530 531 531 /* 532 532 * Store the initialized HID device and HID ops … … 540 540 usb_log_error("Could not bind DDF function: %s.\n", 541 541 str_error(rc)); 542 fun->driver_data = NULL; /* We need this later */ 542 543 ddf_fun_destroy(fun); 543 544 return rc; 544 545 } 545 546 546 547 usb_log_debug("%s function created. Handle: %" PRIun "\n", 547 548 HID_KBD_FUN_NAME, fun->handle); 548 549 549 550 usb_log_debug("Adding DDF function to category %s...\n", 550 551 HID_KBD_CLASS_NAME); … … 554 555 "Could not add DDF function to category %s: %s.\n", 555 556 HID_KBD_CLASS_NAME, str_error(rc)); 557 fun->driver_data = NULL; /* We need this later */ 556 558 ddf_fun_destroy(fun); 557 559 return rc; 558 560 } 559 561 kbd_dev->fun = fun; 562 560 563 return EOK; 561 564 } … … 587 590 { 588 591 usb_log_debug("Initializing HID/KBD structure...\n"); 589 592 590 593 if (hid_dev == NULL) { 591 594 usb_log_error("Failed to init keyboard structure: no structure" … … 593 596 return EINVAL; 594 597 } 595 598 596 599 usb_kbd_t *kbd_dev = usb_kbd_new(); 597 600 if (kbd_dev == NULL) { … … 603 606 /* Store link to HID device */ 604 607 kbd_dev->hid_dev = hid_dev; 605 608 606 609 /* 607 610 * TODO: make more general … … 609 612 usb_hid_report_path_t *path = usb_hid_report_path(); 610 613 usb_hid_report_path_append_item(path, USB_HIDUT_PAGE_KEYBOARD, 0); 611 614 612 615 usb_hid_report_path_set_report_id(path, 0); 613 616 614 617 kbd_dev->key_count = usb_hid_report_size( 615 618 hid_dev->report, 0, USB_HID_REPORT_TYPE_INPUT); 616 619 usb_hid_report_path_free(path); 617 620 618 621 usb_log_debug("Size of the input report: %zu\n", kbd_dev->key_count); 619 622 620 623 kbd_dev->keys = (int32_t *)calloc(kbd_dev->key_count, sizeof(int32_t)); 621 624 622 625 if (kbd_dev->keys == NULL) { 623 usb_log_ fatal("No memory!\n");626 usb_log_error("No memory!\n"); 624 627 free(kbd_dev); 625 628 return ENOMEM; 626 629 } 627 630 628 631 kbd_dev->keys_old = 629 632 (int32_t *)calloc(kbd_dev->key_count, sizeof(int32_t)); 630 633 631 634 if (kbd_dev->keys_old == NULL) { 632 usb_log_ fatal("No memory!\n");635 usb_log_error("No memory!\n"); 633 636 free(kbd_dev->keys); 634 637 free(kbd_dev); 635 638 return ENOMEM; 636 639 } 637 640 638 641 /* 639 642 * Output report … … 647 650 return ENOMEM; 648 651 } 649 652 650 653 usb_log_debug("Output buffer size: %zu\n", kbd_dev->output_size); 651 654 652 655 kbd_dev->led_path = usb_hid_report_path(); 653 656 usb_hid_report_path_append_item( 654 657 kbd_dev->led_path, USB_HIDUT_PAGE_LED, 0); 655 658 656 659 kbd_dev->led_output_size = usb_hid_report_size(hid_dev->report, 657 660 0, USB_HID_REPORT_TYPE_OUTPUT); 658 661 659 662 usb_log_debug("Output report size (in items): %zu\n", 660 663 kbd_dev->led_output_size); 661 664 662 665 kbd_dev->led_data = (int32_t *)calloc( 663 666 kbd_dev->led_output_size, sizeof(int32_t)); 664 667 665 668 if (kbd_dev->led_data == NULL) { 666 669 usb_log_warning("Error creating buffer for LED output report." … … 671 674 return ENOMEM; 672 675 } 673 676 674 677 /* 675 678 * Modifiers and locks … … 678 681 kbd_dev->mods = DEFAULT_ACTIVE_MODS; 679 682 kbd_dev->lock_keys = 0; 680 683 681 684 /* 682 685 * Autorepeat … … 686 689 kbd_dev->repeat.delay_before = DEFAULT_DELAY_BEFORE_FIRST_REPEAT; 687 690 kbd_dev->repeat.delay_between = DEFAULT_REPEAT_DELAY; 688 689 kbd_dev->repeat_mtx = (fibril_mutex_t *)( 690 malloc(sizeof(fibril_mutex_t))); 691 if (kbd_dev->repeat_mtx == NULL) { 692 usb_log_fatal("No memory!\n"); 693 free(kbd_dev->keys); 694 usb_hid_report_output_free(kbd_dev->output_buffer); 695 free(kbd_dev); 696 return ENOMEM; 697 } 698 699 fibril_mutex_initialize(kbd_dev->repeat_mtx); 700 691 692 fibril_mutex_initialize(&kbd_dev->repeat_mtx); 693 701 694 // save the KBD device structure into the HID device structure 702 695 *data = kbd_dev; 703 696 704 697 // set handler for incoming calls 705 698 kbd_dev->ops.default_handler = default_connection_handler; 706 699 707 700 /* 708 701 * Set LEDs according to initial setup. … … 710 703 */ 711 704 usb_kbd_set_led(hid_dev, kbd_dev); 712 705 713 706 usbhid_req_set_idle(&hid_dev->usb_dev->ctrl_pipe, 714 707 hid_dev->usb_dev->interface_no, IDLE_RATE); 715 708 716 709 /* 717 710 * Create new fibril for auto-repeat … … 723 716 } 724 717 fibril_add_ready(fid); 725 718 726 719 kbd_dev->initialized = USB_KBD_STATUS_INITIALIZED; 727 720 usb_log_debug("HID/KBD device structure initialized.\n"); 728 721 729 722 usb_log_debug("Creating KBD function...\n"); 730 int rc = usb_kbd_create_function( hid_dev,kbd_dev);723 int rc = usb_kbd_create_function(kbd_dev); 731 724 if (rc != EOK) { 732 725 usb_kbd_destroy(kbd_dev); 733 726 return rc; 734 727 } 735 728 736 729 return EOK; 737 730 } … … 745 738 return false; 746 739 } 747 740 748 741 usb_kbd_t *kbd_dev = (usb_kbd_t *)data; 749 742 assert(kbd_dev != NULL); 750 743 751 744 // TODO: add return value from this function 752 745 usb_kbd_process_data(hid_dev, kbd_dev); 753 746 754 747 return true; 755 748 } … … 780 773 return; 781 774 } 782 775 783 776 // hangup session to the console 784 777 async_hangup(kbd_dev->console_sess); 785 786 if (kbd_dev->repeat_mtx != NULL) { 787 //assert(!fibril_mutex_is_locked((*kbd_dev)->repeat_mtx)); 788 // FIXME - the fibril_mutex_is_locked may not cause 789 // fibril scheduling 790 while (fibril_mutex_is_locked(kbd_dev->repeat_mtx)) {} 791 free(kbd_dev->repeat_mtx); 792 } 793 778 779 //assert(!fibril_mutex_is_locked((*kbd_dev)->repeat_mtx)); 780 // FIXME - the fibril_mutex_is_locked may not cause 781 // fibril scheduling 782 while (fibril_mutex_is_locked(&kbd_dev->repeat_mtx)) {} 783 794 784 // free all buffers 795 if (kbd_dev->keys != NULL) { 796 free(kbd_dev->keys); 797 } 798 if (kbd_dev->keys_old != NULL) { 799 free(kbd_dev->keys_old); 800 } 801 if (kbd_dev->led_data != NULL) { 802 free(kbd_dev->led_data); 803 } 785 free(kbd_dev->keys); 786 free(kbd_dev->keys_old); 787 free(kbd_dev->led_data); 788 804 789 if (kbd_dev->led_path != NULL) { 805 790 usb_hid_report_path_free(kbd_dev->led_path); … … 808 793 usb_hid_report_output_free(kbd_dev->output_buffer); 809 794 } 795 796 if (ddf_fun_unbind(kbd_dev->fun) != EOK) { 797 usb_log_warning("Failed to unbind kbd function.\n"); 798 } else { 799 usb_log_debug2("%s unbound.\n", kbd_dev->fun->name); 800 kbd_dev->fun->driver_data = NULL; 801 ddf_fun_destroy(kbd_dev->fun); 802 } 810 803 } 811 804 … … 817 810 return; 818 811 } 819 812 820 813 if (data != NULL) { 821 usb_kbd_t *kbd_dev = (usb_kbd_t *)data;814 usb_kbd_t *kbd_dev = data; 822 815 if (usb_kbd_is_initialized(kbd_dev)) { 823 816 usb_kbd_mark_unusable(kbd_dev); 824 } else { 817 /* wait for autorepeat */ 818 async_usleep(CHECK_DELAY); 825 819 usb_kbd_destroy(kbd_dev); 826 820 } … … 835 829 USB_KBD_BOOT_REPORT_DESCRIPTOR, 836 830 USB_KBD_BOOT_REPORT_DESCRIPTOR_SIZE); 837 831 838 832 if (rc != EOK) { 839 833 usb_log_error("Failed to parse boot report descriptor: %s\n", … … 841 835 return rc; 842 836 } 843 837 844 838 rc = usbhid_req_set_protocol(&hid_dev->usb_dev->ctrl_pipe, 845 839 hid_dev->usb_dev->interface_no, USB_HID_PROTOCOL_BOOT); 846 840 847 841 if (rc != EOK) { 848 842 usb_log_warning("Failed to set boot protocol to the device: " … … 850 844 return rc; 851 845 } 852 846 853 847 return EOK; 854 848 } -
uspace/drv/bus/usb/usbhid/kbd/kbddev.h
r3958e315 re3f7418 75 75 /** Currently pressed modifiers (bitmap). */ 76 76 uint8_t modifiers; 77 77 78 78 /** Currently active modifiers including locks. Sent to the console. */ 79 79 unsigned mods; 80 80 81 81 /** Currently active lock keys. */ 82 82 unsigned lock_keys; 83 83 84 84 /** IPC session to the console device (for sending key events). */ 85 85 async_sess_t *console_sess; 86 86 87 87 /** @todo What is this actually? */ 88 88 ddf_dev_ops_t ops; 89 89 90 90 /** Information for auto-repeat of keys. */ 91 91 usb_kbd_repeat_t repeat; 92 92 93 93 /** Mutex for accessing the information about auto-repeat. */ 94 fibril_mutex_t *repeat_mtx;95 94 fibril_mutex_t repeat_mtx; 95 96 96 uint8_t *output_buffer; 97 97 98 98 size_t output_size; 99 99 100 100 size_t led_output_size; 101 101 102 102 usb_hid_report_path_t *led_path; 103 103 104 104 int32_t *led_data; 105 105 106 106 /** State of the structure (for checking before use). 107 107 * … … 111 111 */ 112 112 int initialized; 113 114 /** DDF function */ 115 ddf_fun_t *fun; 113 116 } usb_kbd_t; 114 117 -
uspace/drv/bus/usb/usbhid/kbd/kbdrepeat.c
r3958e315 re3f7418 46 46 47 47 48 /** Delay between auto-repeat state checks when no key is being repeated. */49 static unsigned int CHECK_DELAY = 10000;50 48 51 49 /*----------------------------------------------------------------------------*/ … … 73 71 { 74 72 unsigned int delay = 0; 75 73 76 74 usb_log_debug("Starting autorepeat loop.\n"); 77 75 … … 79 77 // check if the kbd structure is usable 80 78 if (!usb_kbd_is_initialized(kbd)) { 81 if (usb_kbd_is_ready_to_destroy(kbd)) { 82 usb_kbd_destroy(kbd); 83 } 79 usb_log_warning("kbd not ready, exiting autorepeat.\n"); 84 80 return; 85 81 } 86 82 87 fibril_mutex_lock( kbd->repeat_mtx);83 fibril_mutex_lock(&kbd->repeat_mtx); 88 84 89 85 if (kbd->repeat.key_new > 0) { … … 109 105 delay = CHECK_DELAY; 110 106 } 111 fibril_mutex_unlock( kbd->repeat_mtx);107 fibril_mutex_unlock(&kbd->repeat_mtx); 112 108 113 109 async_usleep(delay); … … 130 126 { 131 127 usb_log_debug("Autorepeat fibril spawned.\n"); 132 128 133 129 if (arg == NULL) { 134 130 usb_log_error("No device!\n"); 135 131 return EINVAL; 136 132 } 137 133 138 134 usb_kbd_t *kbd = (usb_kbd_t *)arg; 139 135 140 136 usb_kbd_repeat_loop(kbd); 141 137 142 138 return EOK; 143 139 } … … 156 152 void usb_kbd_repeat_start(usb_kbd_t *kbd, unsigned int key) 157 153 { 158 fibril_mutex_lock( kbd->repeat_mtx);154 fibril_mutex_lock(&kbd->repeat_mtx); 159 155 kbd->repeat.key_new = key; 160 fibril_mutex_unlock( kbd->repeat_mtx);156 fibril_mutex_unlock(&kbd->repeat_mtx); 161 157 } 162 158 … … 174 170 void usb_kbd_repeat_stop(usb_kbd_t *kbd, unsigned int key) 175 171 { 176 fibril_mutex_lock( kbd->repeat_mtx);172 fibril_mutex_lock(&kbd->repeat_mtx); 177 173 if (key == kbd->repeat.key_new) { 178 174 kbd->repeat.key_new = 0; 179 175 } 180 fibril_mutex_unlock( kbd->repeat_mtx);176 fibril_mutex_unlock(&kbd->repeat_mtx); 181 177 } 182 178 -
uspace/drv/bus/usb/usbhid/kbd/kbdrepeat.h
r3958e315 re3f7418 37 37 #define USB_HID_KBDREPEAT_H_ 38 38 39 /** Delay between auto-repeat state checks when no key is being repeated. */ 40 #define CHECK_DELAY 10000 41 39 42 struct usb_kbd_t; 40 43 -
uspace/drv/bus/usb/usbhid/main.c
r3958e315 re3f7418 76 76 { 77 77 assert(dev != NULL); 78 79 /* 80 * Initialize device (get and process descriptors, get address, etc.) 81 */ 78 79 /* Initialize device (get and process descriptors, get address, etc.) */ 82 80 usb_log_debug("Initializing USB/HID device...\n"); 83 84 usb_hid_dev_t *hid_dev = usb_hid_new(); 81 82 usb_hid_dev_t *hid_dev = 83 usb_device_data_alloc(dev, sizeof(usb_hid_dev_t)); 85 84 if (hid_dev == NULL) { 86 85 usb_log_error("Error while creating USB/HID device " … … 88 87 return ENOMEM; 89 88 } 90 89 91 90 int rc = usb_hid_init(hid_dev, dev); 92 91 93 92 if (rc != EOK) { 94 93 usb_log_error("Failed to initialize USB/HID device.\n"); 95 94 usb_hid_destroy(hid_dev); 96 95 return rc; 97 } 98 96 } 97 99 98 usb_log_debug("USB/HID device structure initialized.\n"); 100 99 101 100 /* 102 101 * 1) subdriver vytvori vlastnu ddf_fun, vlastne ddf_dev_ops, ktore da … … 109 108 * pouzit usb/classes/hid/iface.h - prvy int je telefon 110 109 */ 111 110 112 111 /* Start automated polling function. 113 112 * This will create a separate fibril that will query the device … … 125 124 /* Custom argument. */ 126 125 hid_dev); 127 128 126 129 127 if (rc != EOK) { 130 128 usb_log_error("Failed to start polling fibril for `%s'.\n", 131 129 dev->ddf_dev->name); 130 usb_hid_destroy(hid_dev); 132 131 return rc; 133 132 } 133 hid_dev->running = true; 134 dev->driver_data = hid_dev; 134 135 135 136 /* … … 153 154 { 154 155 usb_log_debug("usb_hid_device_add()\n"); 155 156 156 157 if (dev == NULL) { 157 158 usb_log_warning("Wrong parameter given for add_device().\n"); 158 159 return EINVAL; 159 160 } 160 161 161 162 if (dev->interface_no < 0) { 162 163 usb_log_warning("Device is not a supported HID device.\n"); … … 165 166 return ENOTSUP; 166 167 } 167 168 168 169 int rc = usb_hid_try_add_device(dev); 169 170 170 171 if (rc != EOK) { 171 172 usb_log_warning("Device is not a supported HID device.\n"); … … 174 175 return rc; 175 176 } 176 177 177 178 usb_log_info("HID device `%s' ready to use.\n", dev->ddf_dev->name); 178 179 … … 182 183 /*----------------------------------------------------------------------------*/ 183 184 184 /* Currently, the framework supports only device adding. Once the framework 185 * supports unplug, more callbacks will be added. */ 185 /** 186 * Callback for removing a device from the driver. 187 * 188 * @param dev Structure representing the device. 189 * 190 * @retval EOK if successful. 191 * @retval EREFUSED if the device is not supported. 192 */ 193 static int usb_hid_device_gone(usb_device_t *dev) 194 { 195 usb_hid_dev_t *hid_dev = dev->driver_data; 196 unsigned tries = 10; 197 while (hid_dev->running) { 198 async_usleep(100000); 199 if (!tries--) { 200 usb_log_error("Can't remove hub, still running.\n"); 201 return EINPROGRESS; 202 } 203 } 204 205 assert(!hid_dev->running); 206 usb_hid_destroy(hid_dev); 207 usb_log_debug2("%s destruction complete.\n", dev->ddf_dev->name); 208 return EOK; 209 } 210 211 /** USB generic driver callbacks */ 186 212 static usb_driver_ops_t usb_hid_driver_ops = { 187 .device_add = usb_hid_device_add, 213 .device_add = usb_hid_device_add, 214 .device_gone = usb_hid_device_gone, 188 215 }; 189 216 190 217 191 /* The driver itself. */218 /** The driver itself. */ 192 219 static usb_driver_t usb_hid_driver = { 193 220 .name = NAME, -
uspace/drv/bus/usb/usbhid/mouse/mousedev.c
r3958e315 re3f7418 124 124 { 125 125 usb_mouse_t *mouse_dev = (usb_mouse_t *) fun->driver_data; 126 126 127 127 if (mouse_dev == NULL) { 128 128 usb_log_debug("default_connection_handler: Missing " … … 131 131 return; 132 132 } 133 133 134 134 usb_log_debug("default_connection_handler: fun->name: %s\n", 135 135 fun->name); 136 136 usb_log_debug("default_connection_handler: mouse_sess: %p, " 137 137 "wheel_sess: %p\n", mouse_dev->mouse_sess, mouse_dev->wheel_sess); 138 138 139 139 async_sess_t **sess_ptr = 140 140 (str_cmp(fun->name, HID_MOUSE_FUN_NAME) == 0) ? 141 141 &mouse_dev->mouse_sess : &mouse_dev->wheel_sess; 142 142 143 143 async_sess_t *sess = 144 144 async_callback_receive_start(EXCHANGE_SERIALIZE, icall); … … 170 170 mouse->mouse_sess = NULL; 171 171 mouse->wheel_sess = NULL; 172 172 173 173 return mouse; 174 174 } … … 179 179 { 180 180 assert(mouse_dev != NULL); 181 181 182 182 // hangup session to the console 183 183 if (mouse_dev->mouse_sess != NULL) 184 184 async_hangup(mouse_dev->mouse_sess); 185 185 186 186 if (mouse_dev->wheel_sess != NULL) 187 187 async_hangup(mouse_dev->wheel_sess); 188 int ret = ddf_fun_unbind(mouse_dev->mouse_fun); 189 if (ret != EOK) { 190 usb_log_error("Failed to unbind mouse function.\n"); 191 } else { 192 ddf_fun_destroy(mouse_dev->mouse_fun); 193 /* Prevent double free */ 194 mouse_dev->wheel_fun->driver_data = NULL; 195 } 196 197 ret = ddf_fun_unbind(mouse_dev->wheel_fun); 198 if (ret != EOK) { 199 usb_log_error("Failed to unbind wheel function.\n"); 200 } else { 201 ddf_fun_destroy(mouse_dev->wheel_fun); 202 } 188 203 } 189 204 … … 199 214 return; 200 215 } 201 216 202 217 int count = ((wheel < 0) ? -wheel : wheel) * ARROWS_PER_SINGLE_WHEEL; 203 218 int i; 204 219 205 220 for (i = 0; i < count; i++) { 206 221 /* Send arrow press and release. */ … … 246 261 { 247 262 assert(mouse_dev != NULL); 248 263 249 264 if (mouse_dev->mouse_sess == NULL) { 250 265 usb_log_warning(NAME " No console session.\n"); … … 264 279 async_exchange_end(exch); 265 280 } 266 281 267 282 if (wheel != 0) 268 283 usb_mouse_send_wheel(mouse_dev, wheel); 269 284 270 285 /* 271 286 * Buttons … … 274 289 usb_hid_report_path_append_item(path, USB_HIDUT_PAGE_BUTTON, 0); 275 290 usb_hid_report_path_set_report_id(path, hid_dev->report_id); 276 291 277 292 usb_hid_report_field_t *field = usb_hid_report_get_sibling( 278 293 hid_dev->report, NULL, path, USB_HID_PATH_COMPARE_END … … 309 324 USB_HID_REPORT_TYPE_INPUT); 310 325 } 311 326 312 327 usb_hid_report_path_free(path); 313 328 … … 321 336 assert(hid_dev != NULL); 322 337 assert(mouse != NULL); 323 338 324 339 /* Create the exposed function. */ 325 340 usb_log_debug("Creating DDF function %s...\n", HID_MOUSE_FUN_NAME); … … 330 345 return ENOMEM; 331 346 } 332 347 333 348 fun->ops = &mouse->ops; 334 349 fun->driver_data = mouse; … … 338 353 usb_log_error("Could not bind DDF function: %s.\n", 339 354 str_error(rc)); 340 ddf_fun_destroy(fun); 341 return rc; 342 } 343 355 return rc; 356 } 357 344 358 usb_log_debug("Adding DDF function to category %s...\n", 345 359 HID_MOUSE_CATEGORY); … … 349 363 "Could not add DDF function to category %s: %s.\n", 350 364 HID_MOUSE_CATEGORY, str_error(rc)); 351 ddf_fun_destroy(fun);352 return rc;353 }354 365 return rc; 366 } 367 mouse->mouse_fun = fun; 368 355 369 /* 356 370 * Special function for acting as keyboard (wheel) … … 364 378 return ENOMEM; 365 379 } 366 380 367 381 /* 368 382 * Store the initialized HID device and HID ops … … 376 390 usb_log_error("Could not bind DDF function: %s.\n", 377 391 str_error(rc)); 378 ddf_fun_destroy(fun); 379 return rc; 380 } 381 392 return rc; 393 } 394 382 395 usb_log_debug("Adding DDF function to category %s...\n", 383 396 HID_MOUSE_WHEEL_CATEGORY); … … 387 400 "Could not add DDF function to category %s: %s.\n", 388 401 HID_MOUSE_WHEEL_CATEGORY, str_error(rc)); 389 ddf_fun_destroy(fun);390 return rc;391 }392 402 return rc; 403 } 404 mouse->wheel_fun = fun; 405 393 406 return EOK; 394 407 } … … 441 454 { 442 455 usb_log_debug("Initializing HID/Mouse structure...\n"); 443 456 444 457 if (hid_dev == NULL) { 445 458 usb_log_error("Failed to init keyboard structure: no structure" … … 447 460 return EINVAL; 448 461 } 449 462 450 463 usb_mouse_t *mouse_dev = usb_mouse_new(); 451 464 if (mouse_dev == NULL) { … … 454 467 return ENOMEM; 455 468 } 456 469 457 470 // FIXME: This may not be optimal since stupid hardware vendor may 458 471 // use buttons 1, 2, 3 and 6000 and we would allocate array of … … 464 477 hid_dev->report_id) + 1; 465 478 mouse_dev->buttons = calloc(mouse_dev->buttons_count, sizeof(int32_t)); 466 479 467 480 if (mouse_dev->buttons == NULL) { 468 481 usb_log_error(NAME ": out of memory, giving up on device!\n"); … … 474 487 // save the Mouse device structure into the HID device structure 475 488 *data = mouse_dev; 476 489 477 490 // set handler for incoming calls 478 491 mouse_dev->ops.default_handler = default_connection_handler; 479 492 480 493 // TODO: how to know if the device supports the request??? 481 494 usbhid_req_set_idle(&hid_dev->usb_dev->ctrl_pipe, 482 495 hid_dev->usb_dev->interface_no, IDLE_RATE); 483 496 484 497 int rc = usb_mouse_create_function(hid_dev, mouse_dev); 485 498 if (rc != EOK) { … … 487 500 return rc; 488 501 } 489 502 490 503 return EOK; 491 504 } … … 500 513 return false; 501 514 } 502 515 503 516 usb_mouse_t *mouse_dev = (usb_mouse_t *)data; 504 517 … … 511 524 { 512 525 if (data != NULL) { 513 usb_mouse_destroy( (usb_mouse_t *)data);526 usb_mouse_destroy(data); 514 527 } 515 528 } … … 522 535 USB_MOUSE_BOOT_REPORT_DESCRIPTOR, 523 536 USB_MOUSE_BOOT_REPORT_DESCRIPTOR_SIZE); 524 537 525 538 if (rc != EOK) { 526 539 usb_log_error("Failed to parse boot report descriptor: %s\n", … … 528 541 return rc; 529 542 } 530 543 531 544 rc = usbhid_req_set_protocol(&hid_dev->usb_dev->ctrl_pipe, 532 545 hid_dev->usb_dev->interface_no, USB_HID_PROTOCOL_BOOT); 533 546 534 547 if (rc != EOK) { 535 548 usb_log_warning("Failed to set boot protocol to the device: " … … 537 550 return rc; 538 551 } 539 552 540 553 return EOK; 541 554 } -
uspace/drv/bus/usb/usbhid/mouse/mousedev.h
r3958e315 re3f7418 49 49 async_sess_t *mouse_sess; 50 50 async_sess_t *wheel_sess; 51 51 52 52 /* Mouse buttons statuses. */ 53 53 int32_t *buttons; 54 54 size_t buttons_count; 55 55 56 56 ddf_dev_ops_t ops; 57 /* DDF mouse function */ 58 ddf_fun_t *mouse_fun; 59 /* DDF mouse function */ 60 ddf_fun_t *wheel_fun; 57 61 } usb_mouse_t; 58 62 -
uspace/drv/bus/usb/usbhid/multimedia/multimedia.c
r3958e315 re3f7418 64 64 //int32_t *keys; 65 65 /** Count of stored keys (i.e. number of keys in the report). */ 66 //size_t key_count; 66 //size_t key_count; 67 67 /** IPC session to the console device (for sending key events). */ 68 68 async_sess_t *console_sess; 69 /** DDF function */ 70 ddf_fun_t *fun; 69 71 } usb_multimedia_t; 70 72 … … 86 88 { 87 89 usb_log_debug(NAME " default_connection_handler()\n"); 88 90 89 91 usb_multimedia_t *multim_dev = (usb_multimedia_t *)fun->driver_data; 90 92 91 93 if (multim_dev == NULL) { 92 94 async_answer_0(icallid, EINVAL); 93 95 return; 94 96 } 95 97 96 98 async_sess_t *sess = 97 99 async_callback_receive_start(EXCHANGE_SERIALIZE, icall); … … 137 139 assert(hid_dev != NULL); 138 140 assert(multim_dev != NULL); 139 141 140 142 kbd_event_t ev; 141 143 142 144 ev.type = type; 143 145 ev.key = key; … … 151 153 return; 152 154 } 153 155 154 156 async_exch_t *exch = async_exchange_begin(multim_dev->console_sess); 155 157 async_msg_4(exch, KBDEV_EVENT, ev.type, ev.key, ev.mods, ev.c); … … 169 171 return ENOMEM; 170 172 } 171 173 172 174 fun->ops = &multimedia_ops; 173 175 fun->driver_data = multim_dev; // TODO: maybe change to hid_dev->data 174 176 175 177 int rc = ddf_fun_bind(fun); 176 178 if (rc != EOK) { 177 179 usb_log_error("Could not bind DDF function: %s.\n", 178 180 str_error(rc)); 179 // TODO: Can / should I destroy the DDF function?180 181 ddf_fun_destroy(fun); 181 182 return rc; 182 183 } 183 184 184 185 usb_log_debug("%s function created (handle: %" PRIun ").\n", 185 186 NAME, fun->handle); 186 187 187 188 rc = ddf_fun_add_to_category(fun, "keyboard"); 188 189 if (rc != EOK) { … … 190 191 "Could not add DDF function to category 'keyboard': %s.\n", 191 192 str_error(rc)); 192 // TODO: Can / should I destroy the DDF function?193 193 ddf_fun_destroy(fun); 194 194 return rc; 195 195 } 196 196 multim_dev->fun = fun; 197 197 198 return EOK; 198 199 } … … 205 206 return EINVAL; /*! @todo Other return code? */ 206 207 } 207 208 208 209 usb_log_debug(NAME " Initializing HID/multimedia structure...\n"); 209 210 210 211 usb_multimedia_t *multim_dev = (usb_multimedia_t *)malloc( 211 212 sizeof(usb_multimedia_t)); … … 213 214 return ENOMEM; 214 215 } 215 216 216 217 multim_dev->console_sess = NULL; 217 218 218 219 /*! @todo Autorepeat */ 219 220 220 221 // save the KBD device structure into the HID device structure 221 222 *data = multim_dev; 222 223 223 224 usb_log_debug(NAME " HID/multimedia device structure initialized.\n"); 224 225 225 226 int rc = usb_multimedia_create_function(hid_dev, multim_dev); 226 227 if (rc != EOK) 227 228 return rc; 228 229 229 230 usb_log_debug(NAME " HID/multimedia structure initialized.\n"); 230 231 231 232 return EOK; 232 233 } … … 239 240 return; 240 241 } 241 242 242 243 if (data != NULL) { 243 244 usb_multimedia_t *multim_dev = (usb_multimedia_t *)data; 244 245 // hangup session to the console 245 246 async_hangup(multim_dev->console_sess); 247 const int ret = ddf_fun_unbind(multim_dev->fun); 248 if (ret != EOK) { 249 usb_log_error("Failed to unbind multim function.\n"); 250 } else { 251 usb_log_debug2("%s unbound.\n", multim_dev->fun->name); 252 ddf_fun_destroy(multim_dev->fun); 253 } 246 254 } 247 255 } … … 257 265 258 266 usb_multimedia_t *multim_dev = (usb_multimedia_t *)data; 259 267 260 268 usb_hid_report_path_t *path = usb_hid_report_path(); 261 269 usb_hid_report_path_append_item(path, USB_HIDUT_PAGE_CONSUMER, 0); … … 283 291 key); 284 292 } 285 293 286 294 field = usb_hid_report_get_sibling( 287 295 hid_dev->report, field, path, USB_HID_PATH_COMPARE_END 288 296 | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY, 289 297 USB_HID_REPORT_TYPE_INPUT); 290 } 298 } 291 299 292 300 usb_hid_report_path_free(path); 293 301 294 302 return true; 295 303 } -
uspace/drv/bus/usb/usbhid/subdrivers.h
r3958e315 re3f7418 64 64 */ 65 65 const usb_hid_subdriver_usage_t *usage_path; 66 66 67 67 /** Report ID for which the path should apply. */ 68 68 int report_id; 69 69 70 70 /** Compare type for the Usage path. */ 71 71 int compare; 72 72 73 73 /** Vendor ID (set to -1 if not specified). */ 74 74 int vendor_id; 75 75 76 76 /** Product ID (set to -1 if not specified). */ 77 77 int product_id; 78 78 79 79 /** Subdriver for controlling this device. */ 80 80 usb_hid_subdriver_t subdriver; -
uspace/drv/bus/usb/usbhid/usbhid.c
r3958e315 re3f7418 54 54 55 55 /* Array of endpoints expected on the device, NULL terminated. */ 56 usb_endpoint_description_t *usb_hid_endpoints[ USB_HID_POLL_EP_COUNT + 1] = {56 usb_endpoint_description_t *usb_hid_endpoints[] = { 57 57 &usb_hid_kbd_poll_endpoint_description, 58 58 &usb_hid_mouse_poll_endpoint_description, … … 68 68 { 69 69 assert(hid_dev != NULL && hid_dev->subdriver_count == 0); 70 70 71 71 hid_dev->subdrivers = (usb_hid_subdriver_t *)malloc( 72 72 sizeof(usb_hid_subdriver_t)); … … 74 74 return ENOMEM; 75 75 } 76 76 77 77 assert(hid_dev->subdriver_count >= 0); 78 78 79 79 // set the init callback 80 80 hid_dev->subdrivers[hid_dev->subdriver_count].init = usb_kbd_init; 81 81 82 82 // set the polling callback 83 83 hid_dev->subdrivers[hid_dev->subdriver_count].poll = 84 84 usb_kbd_polling_callback; 85 85 86 86 // set the polling ended callback 87 87 hid_dev->subdrivers[hid_dev->subdriver_count].poll_end = NULL; 88 88 89 89 // set the deinit callback 90 90 hid_dev->subdrivers[hid_dev->subdriver_count].deinit = usb_kbd_deinit; 91 91 92 92 // set subdriver count 93 93 ++hid_dev->subdriver_count; 94 94 95 95 return EOK; 96 96 } … … 101 101 { 102 102 assert(hid_dev != NULL && hid_dev->subdriver_count == 0); 103 103 104 104 hid_dev->subdrivers = (usb_hid_subdriver_t *)malloc( 105 105 sizeof(usb_hid_subdriver_t)); … … 107 107 return ENOMEM; 108 108 } 109 109 110 110 assert(hid_dev->subdriver_count >= 0); 111 111 112 112 // set the init callback 113 113 hid_dev->subdrivers[hid_dev->subdriver_count].init = usb_mouse_init; 114 114 115 115 // set the polling callback 116 116 hid_dev->subdrivers[hid_dev->subdriver_count].poll = 117 117 usb_mouse_polling_callback; 118 118 119 119 // set the polling ended callback 120 120 hid_dev->subdrivers[hid_dev->subdriver_count].poll_end = NULL; 121 121 122 122 // set the deinit callback 123 123 hid_dev->subdrivers[hid_dev->subdriver_count].deinit = usb_mouse_deinit; 124 124 125 125 // set subdriver count 126 126 ++hid_dev->subdriver_count; 127 127 128 128 return EOK; 129 129 } … … 134 134 { 135 135 assert(hid_dev != NULL && hid_dev->subdriver_count == 0); 136 136 137 137 hid_dev->subdrivers = (usb_hid_subdriver_t *)malloc( 138 138 sizeof(usb_hid_subdriver_t)); … … 140 140 return ENOMEM; 141 141 } 142 142 143 143 assert(hid_dev->subdriver_count >= 0); 144 144 145 145 // set the init callback 146 146 hid_dev->subdrivers[hid_dev->subdriver_count].init = 147 147 usb_generic_hid_init; 148 148 149 149 // set the polling callback 150 150 hid_dev->subdrivers[hid_dev->subdriver_count].poll = 151 151 usb_generic_hid_polling_callback; 152 152 153 153 // set the polling ended callback 154 154 hid_dev->subdrivers[hid_dev->subdriver_count].poll_end = NULL; 155 155 156 156 // set the deinit callback 157 hid_dev->subdrivers[hid_dev->subdriver_count].deinit = NULL; 158 157 hid_dev->subdrivers[hid_dev->subdriver_count].deinit = 158 usb_generic_hid_deinit; 159 159 160 // set subdriver count 160 161 ++hid_dev->subdriver_count; 161 162 162 163 return EOK; 163 164 } … … 170 171 assert(hid_dev != NULL); 171 172 assert(hid_dev->usb_dev != NULL); 172 173 173 174 return (hid_dev->usb_dev->descriptors.device.vendor_id 174 175 == mapping->vendor_id … … 184 185 assert(hid_dev != NULL); 185 186 assert(mapping != NULL); 186 187 187 188 usb_hid_report_path_t *usage_path = usb_hid_report_path(); 188 189 if (usage_path == NULL) { … … 202 203 ++i; 203 204 } 204 205 205 206 assert(hid_dev->report != NULL); 206 207 207 208 usb_log_debug("Compare flags: %d\n", mapping->compare); 208 209 209 210 bool matches = false; 210 211 uint8_t report_id = mapping->report_id; … … 234 235 USB_HID_REPORT_TYPE_INPUT); 235 236 } while (!matches && report_id != 0); 236 237 237 238 usb_hid_report_path_free(usage_path); 238 239 239 240 return matches; 240 241 } … … 246 247 { 247 248 int i; 248 249 249 250 if (count <= 0) { 250 251 hid_dev->subdriver_count = 0; … … 252 253 return EOK; 253 254 } 254 255 255 256 // add one generic HID subdriver per device 256 257 257 258 hid_dev->subdrivers = (usb_hid_subdriver_t *)malloc((count + 1) * 258 259 sizeof(usb_hid_subdriver_t)); … … 260 261 return ENOMEM; 261 262 } 262 263 263 264 for (i = 0; i < count; ++i) { 264 265 hid_dev->subdrivers[i].init = subdrivers[i]->init; … … 267 268 hid_dev->subdrivers[i].poll_end = subdrivers[i]->poll_end; 268 269 } 269 270 270 271 hid_dev->subdrivers[count].init = usb_generic_hid_init; 271 272 hid_dev->subdrivers[count].poll = usb_generic_hid_polling_callback; 272 hid_dev->subdrivers[count].deinit = NULL;273 hid_dev->subdrivers[count].deinit = usb_generic_hid_deinit; 273 274 hid_dev->subdrivers[count].poll_end = NULL; 274 275 275 276 hid_dev->subdriver_count = count + 1; 276 277 277 278 return EOK; 278 279 } … … 283 284 { 284 285 assert(hid_dev != NULL); 285 286 286 287 const usb_hid_subdriver_t *subdrivers[USB_HID_MAX_SUBDRIVERS]; 287 288 288 289 int i = 0, count = 0; 289 290 const usb_hid_subdriver_mapping_t *mapping = &usb_hid_subdrivers[i]; … … 291 292 bool ids_matched; 292 293 bool matched; 293 294 294 295 while (count < USB_HID_MAX_SUBDRIVERS && 295 296 (mapping->usage_path != NULL … … 339 340 mapping = &usb_hid_subdrivers[++i]; 340 341 } 341 342 342 343 // we have all subdrivers determined, save them into the hid device 343 344 return usb_hid_save_subdrivers(hid_dev, subdrivers, count); … … 349 350 { 350 351 assert(hid_dev != NULL && dev != NULL); 351 352 352 353 int rc = EOK; 353 354 354 355 if (dev->pipes[USB_HID_KBD_POLL_EP_NO].present) { 355 356 usb_log_debug("Found keyboard endpoint.\n"); … … 369 370 rc = ENOTSUP; 370 371 } 371 372 372 373 return rc; 373 374 } … … 378 379 { 379 380 assert(hid_dev != NULL && hid_dev->report != NULL); 380 381 381 382 uint8_t report_id = 0; 382 383 size_t size; 383 384 384 385 size_t max_size = 0; 385 386 386 387 do { 387 388 usb_log_debug("Getting size of the report.\n"); … … 394 395 report_id, USB_HID_REPORT_TYPE_INPUT); 395 396 } while (report_id != 0); 396 397 397 398 usb_log_debug("Max size of input report: %zu\n", max_size); 398 399 399 400 hid_dev->max_input_report_size = max_size; 400 401 assert(hid_dev->input_report == NULL); 401 402 402 403 hid_dev->input_report = malloc(max_size); 403 404 if (hid_dev->input_report == NULL) { … … 405 406 } 406 407 memset(hid_dev->input_report, 0, max_size); 407 408 408 409 return EOK; 409 410 } … … 411 412 /*----------------------------------------------------------------------------*/ 412 413 413 usb_hid_dev_t *usb_hid_new(void)414 {415 usb_hid_dev_t *hid_dev = (usb_hid_dev_t *)calloc(1,416 sizeof(usb_hid_dev_t));417 418 if (hid_dev == NULL) {419 usb_log_fatal("No memory!\n");420 return NULL;421 }422 423 hid_dev->report = (usb_hid_report_t *)(malloc(sizeof(424 usb_hid_report_t)));425 if (hid_dev->report == NULL) {426 usb_log_fatal("No memory!\n");427 free(hid_dev);428 return NULL;429 }430 431 hid_dev->poll_pipe_index = -1;432 433 return hid_dev;434 }435 436 /*----------------------------------------------------------------------------*/437 438 414 int usb_hid_init(usb_hid_dev_t *hid_dev, usb_device_t *dev) 439 415 { 440 416 int rc, i; 441 417 442 418 usb_log_debug("Initializing HID structure...\n"); 443 419 444 420 if (hid_dev == NULL) { 445 421 usb_log_error("Failed to init HID structure: no structure given" … … 447 423 return EINVAL; 448 424 } 449 425 450 426 if (dev == NULL) { 451 427 usb_log_error("Failed to init HID structure: no USB device" … … 453 429 return EINVAL; 454 430 } 455 431 432 hid_dev->report = (usb_hid_report_t *)(malloc(sizeof( 433 usb_hid_report_t))); 434 if (hid_dev->report == NULL) { 435 usb_log_error("No memory!\n"); 436 return ENOMEM; 437 } 438 usb_hid_report_init(hid_dev->report); 439 456 440 /* The USB device should already be initialized, save it in structure */ 457 441 hid_dev->usb_dev = dev; 458 442 hid_dev->poll_pipe_index = -1; 443 459 444 rc = usb_hid_check_pipes(hid_dev, dev); 460 445 if (rc != EOK) { … … 465 450 rc = usb_hid_process_report_descriptor(hid_dev->usb_dev, 466 451 hid_dev->report, &hid_dev->report_desc, &hid_dev->report_desc_size); 467 452 468 453 bool fallback = false; 469 454 470 455 if (rc == EOK) { 471 456 // try to find subdrivers that may want to handle this device … … 484 469 fallback = true; 485 470 } 486 471 487 472 if (fallback) { 488 473 // fall back to boot protocol … … 510 495 } 511 496 } 512 497 513 498 if (rc != EOK) { 514 499 usb_log_error("No subdriver for handling this device could be" … … 542 527 rc = (ok) ? EOK : -1; // what error to report 543 528 } 544 545 529 530 546 531 if (rc == EOK) { 547 532 // save max input report size and allocate space for the report … … 552 537 } 553 538 } 554 555 539 540 556 541 return rc; 557 542 } … … 563 548 { 564 549 int i; 565 550 566 551 if (dev == NULL || arg == NULL || buffer == NULL) { 567 552 usb_log_error("Missing arguments to polling callback.\n"); 568 553 return false; 569 554 } 570 555 571 556 usb_hid_dev_t *hid_dev = (usb_hid_dev_t *)arg; 572 557 573 558 assert(hid_dev->input_report != NULL); 574 559 usb_log_debug("New data [%zu/%zu]: %s\n", buffer_size, … … 582 567 usb_hid_new_report(hid_dev); 583 568 } 584 569 585 570 // parse the input report 586 571 587 572 int rc = usb_hid_parse_report(hid_dev->report, buffer, buffer_size, 588 573 &hid_dev->report_id); 589 574 590 575 if (rc != EOK) { 591 576 usb_log_warning("Error in usb_hid_parse_report():" 592 577 "%s\n", str_error(rc)); 593 578 } 594 579 595 580 bool cont = false; 596 581 597 582 // continue if at least one of the subdrivers want to continue 598 583 for (i = 0; i < hid_dev->subdriver_count; ++i) { … … 603 588 } 604 589 } 605 590 606 591 return cont; 607 592 } … … 613 598 { 614 599 int i; 615 600 616 601 if (dev == NULL || arg == NULL) { 617 602 return; 618 603 } 619 604 620 605 usb_hid_dev_t *hid_dev = (usb_hid_dev_t *)arg; 621 606 622 607 for (i = 0; i < hid_dev->subdriver_count; ++i) { 623 608 if (hid_dev->subdrivers[i].poll_end != NULL) { … … 626 611 } 627 612 } 628 629 usb_hid_destroy(hid_dev);613 614 hid_dev->running = false; 630 615 } 631 616 … … 649 634 { 650 635 int i; 651 636 652 637 if (hid_dev == NULL) { 653 638 return; 654 639 } 655 640 656 641 usb_log_debug("Subdrivers: %p, subdriver count: %d\n", 657 642 hid_dev->subdrivers, hid_dev->subdriver_count); 658 643 659 644 assert(hid_dev->subdrivers != NULL 660 645 || hid_dev->subdriver_count == 0); 661 646 662 647 for (i = 0; i < hid_dev->subdriver_count; ++i) { 663 648 if (hid_dev->subdrivers[i].deinit != NULL) { … … 666 651 } 667 652 } 668 669 // free the subdrivers info 670 if (hid_dev->subdrivers != NULL) { 671 free(hid_dev->subdrivers); 672 } 673 674 // destroy the parser 653 654 /* Free allocated structures */ 655 free(hid_dev->subdrivers); 656 free(hid_dev->report_desc); 657 658 /* Destroy the parser */ 675 659 if (hid_dev->report != NULL) { 676 660 usb_hid_free_report(hid_dev->report); 677 661 } 678 662 679 if (hid_dev->report_desc != NULL) {680 free(hid_dev->report_desc);681 }682 663 } 683 664 -
uspace/drv/bus/usb/usbhid/usbhid.h
r3958e315 re3f7418 102 102 /** Structure holding generic USB device information. */ 103 103 usb_device_t *usb_dev; 104 104 105 105 /** Index of the polling pipe in usb_hid_endpoints array. */ 106 106 int poll_pipe_index; 107 107 108 108 /** Subdrivers. */ 109 109 usb_hid_subdriver_t *subdrivers; 110 110 111 111 /** Number of subdrivers. */ 112 112 int subdriver_count; 113 113 114 114 /** Report descriptor. */ 115 115 uint8_t *report_desc; … … 117 117 /** Report descriptor size. */ 118 118 size_t report_desc_size; 119 119 120 120 /** HID Report parser. */ 121 121 usb_hid_report_t *report; 122 122 123 123 uint8_t report_id; 124 124 125 125 uint8_t *input_report; 126 126 127 127 size_t input_report_size; 128 128 size_t max_input_report_size; 129 129 130 130 int report_nr; 131 volatile bool running; 131 132 }; 132 133 … … 140 141 }; 141 142 142 usb_endpoint_description_t *usb_hid_endpoints[USB_HID_POLL_EP_COUNT + 1];143 extern usb_endpoint_description_t *usb_hid_endpoints[]; 143 144 144 145 /*----------------------------------------------------------------------------*/ 145 146 usb_hid_dev_t *usb_hid_new(void);147 146 148 147 int usb_hid_init(usb_hid_dev_t *hid_dev, usb_device_t *dev); -
uspace/drv/bus/usb/usbhub/port.c
r3958e315 re3f7418 288 288 port->attached_device.fun = NULL; 289 289 290 ret = usb_hc_unregister_device(&hub->connection, 291 port->attached_device.address); 292 if (ret != EOK) { 293 usb_log_warning("Failed to unregister address of the removed " 294 "device: %s.\n", str_error(ret)); 295 } 290 ret = usb_hc_connection_open(&hub->connection); 291 if (ret == EOK) { 292 ret = usb_hc_unregister_device(&hub->connection, 293 port->attached_device.address); 294 if (ret != EOK) { 295 usb_log_warning("Failed to unregister address of the " 296 "removed device: %s.\n", str_error(ret)); 297 } 298 ret = usb_hc_connection_close(&hub->connection); 299 if (ret != EOK) { 300 usb_log_warning("Failed to close hc connection %s.\n", 301 str_error(ret)); 302 } 303 304 } else { 305 usb_log_warning("Failed to open hc connection %s.\n", 306 str_error(ret)); 307 } 308 296 309 port->attached_device.address = -1; 297 310 fibril_mutex_unlock(&port->mutex); -
uspace/drv/bus/usb/usbhub/usbhub.c
r3958e315 re3f7418 117 117 ddf_fun_destroy(hub->hub_fun); 118 118 119 free(hub);120 usb_dev->driver_data = NULL;121 119 usb_log_info("USB hub driver, stopped and cleaned.\n"); 122 120 return EOK; … … 254 252 { 255 253 assert(usb_dev); 256 usb_hub_dev_t *hub_dev = malloc(sizeof(usb_hub_dev_t)); 254 usb_hub_dev_t *hub_dev = 255 usb_device_data_alloc(usb_dev, sizeof(usb_hub_dev_t)); 257 256 if (!hub_dev) 258 257 return NULL; 259 258 260 259 hub_dev->usb_device = usb_dev; 261 262 260 hub_dev->ports = NULL; 263 261 hub_dev->port_count = 0; … … 266 264 fibril_mutex_initialize(&hub_dev->pending_ops_mutex); 267 265 fibril_condvar_initialize(&hub_dev->pending_ops_cv); 268 usb_dev->driver_data = hub_dev;269 266 270 267 return hub_dev; -
uspace/drv/bus/usb/usbmast/main.c
r3958e315 re3f7418 82 82 void *arg); 83 83 84 /** Callback when a device is removed from the system. 85 * 86 * @param dev Representation of USB device. 87 * @return Error code. 88 */ 89 static int usbmast_device_gone(usb_device_t *dev) 90 { 91 usbmast_dev_t *mdev = dev->driver_data; 92 assert(mdev); 93 94 for (size_t i = 0; i < mdev->lun_count; ++i) { 95 const int rc = ddf_fun_unbind(mdev->luns[i]); 96 if (rc != EOK) { 97 usb_log_error("Failed to unbind LUN function %zu: " 98 "%s\n", i, str_error(rc)); 99 return rc; 100 } 101 ddf_fun_destroy(mdev->luns[i]); 102 mdev->luns[i] = NULL; 103 } 104 free(mdev->luns); 105 return EOK; 106 } 107 84 108 /** Callback when new device is attached and recognized as a mass storage. 85 109 * … … 94 118 95 119 /* Allocate softstate */ 96 dev->driver_data = mdev = malloc(sizeof(usbmast_dev_t));120 mdev = usb_device_data_alloc(dev, sizeof(usbmast_dev_t)); 97 121 if (mdev == NULL) { 98 122 usb_log_error("Failed allocating softstate.\n"); … … 112 136 113 137 usb_log_debug("Get LUN count...\n"); 114 mdev->luns = usb_masstor_get_lun_count(mdev); 115 116 for (i = 0; i < mdev->luns; i++) { 138 mdev->lun_count = usb_masstor_get_lun_count(mdev); 139 mdev->luns = calloc(mdev->lun_count, sizeof(ddf_fun_t*)); 140 if (mdev->luns == NULL) { 141 rc = ENOMEM; 142 usb_log_error("Failed allocating luns table.\n"); 143 goto error; 144 } 145 146 for (i = 0; i < mdev->lun_count; i++) { 117 147 rc = usbmast_fun_create(mdev, i); 118 148 if (rc != EOK) … … 122 152 return EOK; 123 153 error: 124 /* XXX Destroy functions */ 154 /* Destroy functions */ 155 for (size_t i = 0; i < mdev->lun_count; ++i) { 156 if (mdev->luns[i] == NULL) 157 continue; 158 const int rc = ddf_fun_unbind(mdev->luns[i]); 159 if (rc != EOK) { 160 usb_log_warning("Failed to unbind LUN function %zu: " 161 "%s.\n", i, str_error(rc)); 162 } 163 ddf_fun_destroy(mdev->luns[i]); 164 } 165 free(mdev->luns); 166 free(mdev); 125 167 return rc; 126 168 } … … 162 204 } 163 205 206 mfun->ddf_fun = fun; 164 207 mfun->mdev = mdev; 165 208 mfun->lun = lun; … … 212 255 213 256 free(fun_name); 257 mdev->luns[lun] = fun; 214 258 215 259 return EOK; … … 295 339 static usb_driver_ops_t usbmast_driver_ops = { 296 340 .device_add = usbmast_device_add, 341 .device_gone = usbmast_device_gone, 297 342 }; 298 343 -
uspace/drv/bus/usb/usbmast/usbmast.h
r3958e315 re3f7418 41 41 42 42 /** Mass storage device. */ 43 typedef struct {43 typedef struct usbmast_dev { 44 44 /** DDF device */ 45 45 ddf_dev_t *ddf_dev; … … 47 47 usb_device_t *usb_dev; 48 48 /** Number of LUNs */ 49 unsigned luns; 49 unsigned lun_count; 50 /** LUN functions */ 51 ddf_fun_t **luns; 50 52 } usbmast_dev_t; 53 51 54 52 55 /** Mass storage function. -
uspace/drv/bus/usb/usbmid/dump.c
r3958e315 re3f7418 47 47 * @param depth Nesting depth. 48 48 */ 49 static void dump_tree_descriptor( uint8_t *data, size_t depth)49 static void dump_tree_descriptor(const uint8_t *data, size_t depth) 50 50 { 51 51 if (data == NULL) { 52 52 return; 53 53 } 54 int type = (int) *(data + 1);54 const int type = data[1]; 55 55 if (type == USB_DESCTYPE_INTERFACE) { 56 56 usb_standard_interface_descriptor_t *descriptor … … 71 71 * @param depth Nesting depth. 72 72 */ 73 static void dump_tree_internal(usb_dp_parser_t *parser, usb_dp_parser_data_t *data, 74 uint8_t *root, size_t depth) 73 static void dump_tree_internal( 74 usb_dp_parser_t *parser, usb_dp_parser_data_t *data, 75 const uint8_t *root, size_t depth) 75 76 { 76 77 if (root == NULL) { … … 78 79 } 79 80 dump_tree_descriptor(root, depth); 80 uint8_t *child = usb_dp_get_nested_descriptor(parser, data, root);81 const uint8_t *child = usb_dp_get_nested_descriptor(parser, data, root); 81 82 do { 82 83 dump_tree_internal(parser, data, child, depth + 1); … … 92 93 static void dump_tree(usb_dp_parser_t *parser, usb_dp_parser_data_t *data) 93 94 { 94 uint8_t *ptr = data->data;95 const uint8_t *ptr = data->data; 95 96 dump_tree_internal(parser, data, ptr, 0); 96 97 } -
uspace/drv/bus/usb/usbmid/explore.c
r3958e315 re3f7418 73 73 * @param list List where to add the interfaces. 74 74 */ 75 static void create_interfaces( uint8_t *config_descriptor,75 static void create_interfaces(const uint8_t *config_descriptor, 76 76 size_t config_descriptor_size, list_t *list) 77 77 { 78 usb_dp_parser_data_t data = {78 const usb_dp_parser_data_t data = { 79 79 .data = config_descriptor, 80 80 .size = config_descriptor_size, … … 86 86 }; 87 87 88 uint8_t *interface_ptr = usb_dp_get_nested_descriptor(&parser, &data,89 data.data);88 const uint8_t *interface_ptr = 89 usb_dp_get_nested_descriptor(&parser, &data, data.data); 90 90 if (interface_ptr == NULL) { 91 91 return; … … 149 149 150 150 /* Short cuts to save on typing ;-). */ 151 uint8_t*config_descriptor_raw = dev->descriptors.configuration;151 const void *config_descriptor_raw = dev->descriptors.configuration; 152 152 size_t config_descriptor_size = dev->descriptors.configuration_size; 153 usb_standard_configuration_descriptor_t *config_descriptor =154 (usb_standard_configuration_descriptor_t *)config_descriptor_raw;153 const usb_standard_configuration_descriptor_t *config_descriptor = 154 config_descriptor_raw; 155 155 156 156 /* Select the first configuration */ … … 163 163 } 164 164 165 usb_mid_t *usb_mid = usb_device_data_alloc(dev, sizeof(usb_mid_t)); 166 if (!usb_mid) { 167 usb_log_error("Failed to create USB MID structure.\n"); 168 return false; 169 } 170 165 171 /* Create control function */ 166 ddf_fun_t *ctl_fun = ddf_fun_create(dev->ddf_dev, fun_exposed, "ctl");167 if ( ctl_fun == NULL) {172 usb_mid->ctl_fun = ddf_fun_create(dev->ddf_dev, fun_exposed, "ctl"); 173 if (usb_mid->ctl_fun == NULL) { 168 174 usb_log_error("Failed to create control function.\n"); 169 175 return false; 170 176 } 171 177 172 ctl_fun->ops = &mid_device_ops;173 174 rc = ddf_fun_bind( ctl_fun);178 usb_mid->ctl_fun->ops = &mid_device_ops; 179 180 rc = ddf_fun_bind(usb_mid->ctl_fun); 175 181 if (rc != EOK) { 176 182 usb_log_error("Failed to bind control function: %s.\n", 177 183 str_error(rc)); 178 return false; 179 } 184 ddf_fun_destroy(usb_mid->ctl_fun); 185 return false; 186 } 187 180 188 181 189 /* Create interface children. */ 182 list_t interface_list; 183 list_initialize(&interface_list); 190 list_initialize(&usb_mid->interface_list); 184 191 create_interfaces(config_descriptor_raw, config_descriptor_size, 185 & interface_list);186 187 list_foreach( interface_list, link) {192 &usb_mid->interface_list); 193 194 list_foreach(usb_mid->interface_list, link) { 188 195 usbmid_interface_t *iface = list_get_instance(link, 189 196 usbmid_interface_t, link); -
uspace/drv/bus/usb/usbmid/main.c
r3958e315 re3f7418 66 66 } 67 67 68 static int usbmid_device_gone(usb_device_t *dev) 69 { 70 assert(dev); 71 usb_log_info("USB MID gone: `%s'.\n", dev->ddf_dev->name); 72 73 /* Remove ctl function */ 74 usb_mid_t *usb_mid = dev->driver_data; 75 int ret = ddf_fun_unbind(usb_mid->ctl_fun); 76 if (ret != EOK) { 77 usb_log_error("Failed to unbind USB MID ctl function: %s.\n", 78 str_error(ret)); 79 return ret; 80 } 81 ddf_fun_destroy(usb_mid->ctl_fun); 82 83 /* Now remove all other functions */ 84 while (!list_empty(&usb_mid->interface_list)) { 85 link_t *item = list_first(&usb_mid->interface_list); 86 list_remove(item); 87 88 usbmid_interface_t *iface = list_get_instance(item, 89 usbmid_interface_t, link); 90 91 usb_log_info("Removing child for interface %d (%s).\n", 92 iface->interface_no, 93 usb_str_class(iface->interface->interface_class)); 94 95 const int pret = usbmid_interface_destroy(iface); 96 if (pret != EOK) { 97 usb_log_error("Failed to remove child for interface " 98 "%d (%s): %s\n", 99 iface->interface_no, 100 usb_str_class(iface->interface->interface_class), 101 str_error(pret)); 102 ret = pret; 103 } 104 } 105 return ret; 106 } 107 68 108 /** USB MID driver ops. */ 69 109 static usb_driver_ops_t mid_driver_ops = { 70 110 .device_add = usbmid_device_add, 111 .device_gone = usbmid_device_gone, 71 112 }; 72 113 -
uspace/drv/bus/usb/usbmid/usbmid.c
r3958e315 re3f7418 45 45 46 46 /** Callback for DDF USB interface. */ 47 static int usb_iface_get_address_impl(ddf_fun_t *fun, devman_handle_t handle,48 usb_address_t *address)49 {50 return usb_iface_get_address_hub_impl(fun, handle, address);51 }52 53 /** Callback for DDF USB interface. */54 47 static int usb_iface_get_interface_impl(ddf_fun_t *fun, devman_handle_t handle, 55 48 int *iface_no) … … 70 63 static usb_iface_t child_usb_iface = { 71 64 .get_hc_handle = usb_iface_get_hc_handle_hub_child_impl, 72 .get_address = usb_iface_get_address_ impl,65 .get_address = usb_iface_get_address_hub_impl, 73 66 .get_interface = usb_iface_get_interface_impl 74 67 }; … … 79 72 }; 80 73 74 int usbmid_interface_destroy(usbmid_interface_t *mid_iface) 75 { 76 assert(mid_iface); 77 assert_link_not_used(&mid_iface->link); 78 const int ret = ddf_fun_unbind(mid_iface->fun); 79 if (ret != EOK) { 80 return ret; 81 } 82 /* NOTE: usbmid->interface points somewhere, but we did not 83 * allocate that space, so don't touch */ 84 ddf_fun_destroy(mid_iface->fun); 85 /* NOTE: mid_iface is invalid at this point, it was assigned to 86 * mid_iface->fun->driver_data and freed in ddf_fun_destroy */ 87 return EOK; 88 } 81 89 82 90 /** Spawn new child device from one interface. … … 106 114 (int) interface_descriptor->interface_number); 107 115 if (rc < 0) { 108 goto error_leave;116 return ENOMEM; 109 117 } 110 118 111 119 /* Create the device. */ 112 120 child = ddf_fun_create(parent->ddf_dev, fun_inner, child_name); 121 free(child_name); 113 122 if (child == NULL) { 114 rc = ENOMEM; 115 goto error_leave; 123 return ENOMEM; 116 124 } 117 125 … … 122 130 123 131 rc = usb_device_create_match_ids_from_interface(device_descriptor, 124 interface_descriptor, 125 &child->match_ids); 132 interface_descriptor, &child->match_ids); 126 133 if (rc != EOK) { 127 goto error_leave; 134 ddf_fun_destroy(child); 135 return rc; 128 136 } 129 137 130 138 rc = ddf_fun_bind(child); 131 139 if (rc != EOK) { 132 goto error_leave; 140 /* This takes care of match_id deallocation as well. */ 141 ddf_fun_destroy(child); 142 return rc; 133 143 } 134 144 135 145 return EOK; 136 137 error_leave:138 if (child != NULL) {139 child->name = NULL;140 /* This takes care of match_id deallocation as well. */141 ddf_fun_destroy(child);142 }143 if (child_name != NULL) {144 free(child_name);145 }146 147 return rc;148 146 } 149 147 -
uspace/drv/bus/usb/usbmid/usbmid.h
r3958e315 re3f7418 58 58 } usbmid_interface_t; 59 59 60 /** Container to hold all the function pointers */ 61 typedef struct usb_mid { 62 ddf_fun_t *ctl_fun; 63 list_t interface_list; 64 } usb_mid_t; 65 60 66 bool usbmid_explore_device(usb_device_t *); 61 67 int usbmid_spawn_interface_child(usb_device_t *, usbmid_interface_t *, … … 63 69 const usb_standard_interface_descriptor_t *); 64 70 void usbmid_dump_descriptors(uint8_t *, size_t); 71 int usbmid_interface_destroy(usbmid_interface_t *mid_iface); 65 72 66 73 #endif -
uspace/lib/usbdev/include/usb/dev/dp.h
r3958e315 re3f7418 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
r3958e315 re3f7418 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; … … 158 158 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 … … 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 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 173 int usb_device_create(ddf_dev_t *, usb_endpoint_description_t **, usb_device_t **, const char **); 174 174 void usb_device_destroy(usb_device_t *); 175 void * usb_device_data_alloc(usb_device_t *, size_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 size_t usb_interface_count_alternates(const uint8_t *, size_t, uint8_t); 178 int usb_alternate_interfaces_create(const uint8_t *, size_t, int, 178 179 usb_alternate_interfaces_t **); 179 180 -
uspace/lib/usbdev/include/usb/dev/pipes.h
r3958e315 re3f7418 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
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; -
uspace/lib/usbhid/src/hidreport.c
r3958e315 re3f7418 69 69 * First nested descriptor of the configuration descriptor. 70 70 */ 71 uint8_t *d =71 const uint8_t *d = 72 72 usb_dp_get_nested_descriptor(&parser, &parser_data, 73 73 dev->descriptors.configuration); … … 92 92 * First nested descriptor of the interface descriptor. 93 93 */ 94 uint8_t *iface_desc = d;94 const uint8_t *iface_desc = d; 95 95 d = usb_dp_get_nested_descriptor(&parser, &parser_data, iface_desc); 96 96
Note:
See TracChangeset
for help on using the changeset viewer.