Changes in / [e3f7418:3958e315] in mainline
- Location:
- uspace
- Files:
-
- 38 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/usbinfo/desctree.c
re3f7418 r3958e315 50 50 51 51 static void browse_descriptor_tree_internal(usb_dp_parser_t *parser, 52 usb_dp_parser_data_t *data, constuint8_t *root, size_t depth,52 usb_dp_parser_data_t *data, 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 constuint8_t *child = usb_dp_get_nested_descriptor(parser, data, root);59 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
re3f7418 r3958e315 110 110 } 111 111 112 static void dump_tree_descriptor( constuint8_t *descriptor, size_t depth)112 static void dump_tree_descriptor(uint8_t *descriptor, size_t depth) 113 113 { 114 114 if (descriptor == NULL) { 115 115 return; 116 116 } 117 int type = descriptor[1];117 int type = (int) *(descriptor + 1); 118 118 const char *name = "unknown"; 119 119 switch (type) { … … 136 136 } 137 137 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) 138 static void dump_tree_internal(usb_dp_parser_t *parser, usb_dp_parser_data_t *data, 139 uint8_t *root, size_t depth) 141 140 { 142 141 if (root == NULL) { … … 144 143 } 145 144 dump_tree_descriptor(root, depth); 146 constuint8_t *child = usb_dp_get_nested_descriptor(parser, data, root);145 uint8_t *child = usb_dp_get_nested_descriptor(parser, data, root); 147 146 do { 148 147 dump_tree_internal(parser, data, child, depth + 1); … … 153 152 static void dump_tree(usb_dp_parser_t *parser, usb_dp_parser_data_t *data) 154 153 { 155 constuint8_t *ptr = data->data;154 uint8_t *ptr = data->data; 156 155 printf("Descriptor tree:\n"); 157 156 dump_tree_internal(parser, data, ptr, 0); -
uspace/app/usbinfo/hid.c
re3f7418 r3958e315 55 55 } descriptor_walk_context_t; 56 56 57 static bool is_descriptor_kind( constuint8_t *d, usb_descriptor_type_t t)57 static bool is_descriptor_kind(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( constuint8_t *raw_descriptor,182 static void descriptor_walk_callback(uint8_t *raw_descriptor, 183 183 size_t depth, void *arg) 184 184 { -
uspace/app/usbinfo/info.c
re3f7418 r3958e315 51 51 } 52 52 53 static void dump_match_ids_from_interface( 54 const uint8_t *descriptor, size_t depth,void *arg)53 static void dump_match_ids_from_interface(uint8_t *descriptor, size_t depth, 54 void *arg) 55 55 { 56 56 if (depth != 1) { … … 165 165 166 166 167 static void dump_descriptor_tree_callback( 168 const uint8_t *descriptor,size_t depth, void *arg)167 static void dump_descriptor_tree_callback(uint8_t *descriptor, 168 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( 249 const uint8_t *descriptor,size_t depth, void *arg)248 static void find_string_indexes_callback(uint8_t *descriptor, 249 size_t depth, void *arg) 250 250 { 251 251 size_t descriptor_length = descriptor[0]; -
uspace/app/usbinfo/usbinfo.h
re3f7418 r3958e315 74 74 void destroy_device(usbinfo_device_t *); 75 75 76 typedef void (*dump_descriptor_in_tree_t)( constuint8_t *, size_t, void *);76 typedef void (*dump_descriptor_in_tree_t)(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
re3f7418 r3958e315 64 64 } 65 65 66 dev->driver_data = ctl_fun;67 68 66 usb_log_info("Pretending to control %s `%s'" \ 69 67 " (node `%s', handle %" PRIun ").\n", … … 74 72 } 75 73 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 }95 74 /** USB fallback driver ops. */ 96 75 static usb_driver_ops_t usbfallback_driver_ops = { 97 76 .device_add = usbfallback_device_add, 98 .device_gone = usbfallback_device_gone,99 77 }; 100 78 -
uspace/drv/bus/usb/usbhid/generic/hiddev.c
re3f7418 r3958e315 52 52 .direction = USB_DIRECTION_IN, 53 53 .interface_class = USB_CLASS_HID, 54 .interface_subclass = -1,55 .interface_protocol = -1,56 54 .flags = 0 57 55 }; … … 94 92 usb_log_debug2("Generic HID: Get event length (fun: %p, " 95 93 "fun->driver_data: %p.\n", fun, fun->driver_data); 96 94 97 95 if (fun == NULL || fun->driver_data == NULL) { 98 96 return 0; … … 100 98 101 99 usb_hid_dev_t *hid_dev = (usb_hid_dev_t *)fun->driver_data; 102 100 103 101 usb_log_debug2("hid_dev: %p, Max input report size (%zu).\n", 104 102 hid_dev, hid_dev->max_input_report_size); 105 103 106 104 return hid_dev->max_input_report_size; 107 105 } … … 113 111 { 114 112 usb_log_debug2("Generic HID: Get event.\n"); 115 113 116 114 if (fun == NULL || fun->driver_data == NULL || buffer == NULL 117 115 || act_size == NULL || event_nr == NULL) { … … 121 119 122 120 usb_hid_dev_t *hid_dev = (usb_hid_dev_t *)fun->driver_data; 123 121 124 122 if (hid_dev->input_report_size > size) { 125 123 usb_log_debug("input_report_size > size (%zu, %zu)\n", … … 127 125 return EINVAL; // TODO: other error code 128 126 } 129 127 130 128 /*! @todo This should probably be somehow atomic. */ 131 129 memcpy(buffer, hid_dev->input_report, … … 133 131 *act_size = hid_dev->input_report_size; 134 132 *event_nr = usb_hid_report_number(hid_dev); 135 133 136 134 usb_log_debug2("OK\n"); 137 135 138 136 return EOK; 139 137 } … … 144 142 { 145 143 usb_log_debug("Generic HID: Get report descriptor length.\n"); 146 144 147 145 if (fun == NULL || fun->driver_data == NULL) { 148 146 usb_log_debug("No function"); 149 147 return EINVAL; 150 148 } 151 152 usb_hid_dev_t *hid_dev = (usb_hid_dev_t *)fun->driver_data; 153 149 150 usb_hid_dev_t *hid_dev = (usb_hid_dev_t *)fun->driver_data; 151 154 152 usb_log_debug2("hid_dev->report_desc_size = %zu\n", 155 153 hid_dev->report_desc_size); 156 154 157 155 return hid_dev->report_desc_size; 158 156 } … … 164 162 { 165 163 usb_log_debug2("Generic HID: Get report descriptor.\n"); 166 164 167 165 if (fun == NULL || fun->driver_data == NULL) { 168 166 usb_log_debug("No function"); 169 167 return EINVAL; 170 168 } 171 172 usb_hid_dev_t *hid_dev = (usb_hid_dev_t *)fun->driver_data; 173 169 170 usb_hid_dev_t *hid_dev = (usb_hid_dev_t *)fun->driver_data; 171 174 172 if (hid_dev->report_desc_size > size) { 175 173 return EINVAL; 176 174 } 177 175 178 176 memcpy(desc, hid_dev->report_desc, hid_dev->report_desc_size); 179 177 *actual_size = hid_dev->report_desc_size; 180 178 181 179 return EOK; 182 180 } … … 192 190 /*----------------------------------------------------------------------------*/ 193 191 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 192 static int usb_generic_hid_create_function(usb_hid_dev_t *hid_dev) 193 { 217 194 /* Create the exposed function. */ 218 195 /** @todo Generate numbers for the devices? */ … … 224 201 return ENOMEM; 225 202 } 226 203 227 204 fun->ops = &usb_generic_hid_ops; 205 fun->driver_data = hid_dev; 228 206 229 207 int rc = ddf_fun_bind(fun); … … 234 212 return rc; 235 213 } 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 214 240 215 usb_log_debug("HID function created. Handle: %" PRIun "\n", fun->handle); 241 *data = fun; 242 243 return EOK; 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); 244 229 } 245 230 -
uspace/drv/bus/usb/usbhid/generic/hiddev.h
re3f7418 r3958e315 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 54 52 bool usb_generic_hid_polling_callback(struct usb_hid_dev *hid_dev, void *data); 55 53 -
uspace/drv/bus/usb/usbhid/kbd/conv.c
re3f7418 r3958e315 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
re3f7418 r3958e315 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_ error("No memory!\n");504 usb_log_fatal("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_kbd_t *kbd_dev) 517 { 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); 518 520 assert(kbd_dev != NULL); 519 assert(kbd_dev->hid_dev != NULL); 520 assert(kbd_dev->hid_dev->usb_dev != NULL); 521 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( kbd_dev->hid_dev->usb_dev->ddf_dev,525 fun_exposed,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); 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 */543 542 ddf_fun_destroy(fun); 544 543 return rc; 545 544 } 546 545 547 546 usb_log_debug("%s function created. Handle: %" PRIun "\n", 548 547 HID_KBD_FUN_NAME, fun->handle); 549 548 550 549 usb_log_debug("Adding DDF function to category %s...\n", 551 550 HID_KBD_CLASS_NAME); … … 555 554 "Could not add DDF function to category %s: %s.\n", 556 555 HID_KBD_CLASS_NAME, str_error(rc)); 557 fun->driver_data = NULL; /* We need this later */558 556 ddf_fun_destroy(fun); 559 557 return rc; 560 558 } 561 kbd_dev->fun = fun; 562 559 563 560 return EOK; 564 561 } … … 590 587 { 591 588 usb_log_debug("Initializing HID/KBD structure...\n"); 592 589 593 590 if (hid_dev == NULL) { 594 591 usb_log_error("Failed to init keyboard structure: no structure" … … 596 593 return EINVAL; 597 594 } 598 595 599 596 usb_kbd_t *kbd_dev = usb_kbd_new(); 600 597 if (kbd_dev == NULL) { … … 606 603 /* Store link to HID device */ 607 604 kbd_dev->hid_dev = hid_dev; 608 605 609 606 /* 610 607 * TODO: make more general … … 612 609 usb_hid_report_path_t *path = usb_hid_report_path(); 613 610 usb_hid_report_path_append_item(path, USB_HIDUT_PAGE_KEYBOARD, 0); 614 611 615 612 usb_hid_report_path_set_report_id(path, 0); 616 613 617 614 kbd_dev->key_count = usb_hid_report_size( 618 615 hid_dev->report, 0, USB_HID_REPORT_TYPE_INPUT); 619 616 usb_hid_report_path_free(path); 620 617 621 618 usb_log_debug("Size of the input report: %zu\n", kbd_dev->key_count); 622 619 623 620 kbd_dev->keys = (int32_t *)calloc(kbd_dev->key_count, sizeof(int32_t)); 624 621 625 622 if (kbd_dev->keys == NULL) { 626 usb_log_ error("No memory!\n");623 usb_log_fatal("No memory!\n"); 627 624 free(kbd_dev); 628 625 return ENOMEM; 629 626 } 630 627 631 628 kbd_dev->keys_old = 632 629 (int32_t *)calloc(kbd_dev->key_count, sizeof(int32_t)); 633 630 634 631 if (kbd_dev->keys_old == NULL) { 635 usb_log_ error("No memory!\n");632 usb_log_fatal("No memory!\n"); 636 633 free(kbd_dev->keys); 637 634 free(kbd_dev); 638 635 return ENOMEM; 639 636 } 640 637 641 638 /* 642 639 * Output report … … 650 647 return ENOMEM; 651 648 } 652 649 653 650 usb_log_debug("Output buffer size: %zu\n", kbd_dev->output_size); 654 651 655 652 kbd_dev->led_path = usb_hid_report_path(); 656 653 usb_hid_report_path_append_item( 657 654 kbd_dev->led_path, USB_HIDUT_PAGE_LED, 0); 658 655 659 656 kbd_dev->led_output_size = usb_hid_report_size(hid_dev->report, 660 657 0, USB_HID_REPORT_TYPE_OUTPUT); 661 658 662 659 usb_log_debug("Output report size (in items): %zu\n", 663 660 kbd_dev->led_output_size); 664 661 665 662 kbd_dev->led_data = (int32_t *)calloc( 666 663 kbd_dev->led_output_size, sizeof(int32_t)); 667 664 668 665 if (kbd_dev->led_data == NULL) { 669 666 usb_log_warning("Error creating buffer for LED output report." … … 674 671 return ENOMEM; 675 672 } 676 673 677 674 /* 678 675 * Modifiers and locks … … 681 678 kbd_dev->mods = DEFAULT_ACTIVE_MODS; 682 679 kbd_dev->lock_keys = 0; 683 680 684 681 /* 685 682 * Autorepeat … … 689 686 kbd_dev->repeat.delay_before = DEFAULT_DELAY_BEFORE_FIRST_REPEAT; 690 687 kbd_dev->repeat.delay_between = DEFAULT_REPEAT_DELAY; 691 692 fibril_mutex_initialize(&kbd_dev->repeat_mtx); 693 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 694 701 // save the KBD device structure into the HID device structure 695 702 *data = kbd_dev; 696 703 697 704 // set handler for incoming calls 698 705 kbd_dev->ops.default_handler = default_connection_handler; 699 706 700 707 /* 701 708 * Set LEDs according to initial setup. … … 703 710 */ 704 711 usb_kbd_set_led(hid_dev, kbd_dev); 705 712 706 713 usbhid_req_set_idle(&hid_dev->usb_dev->ctrl_pipe, 707 714 hid_dev->usb_dev->interface_no, IDLE_RATE); 708 715 709 716 /* 710 717 * Create new fibril for auto-repeat … … 716 723 } 717 724 fibril_add_ready(fid); 718 725 719 726 kbd_dev->initialized = USB_KBD_STATUS_INITIALIZED; 720 727 usb_log_debug("HID/KBD device structure initialized.\n"); 721 728 722 729 usb_log_debug("Creating KBD function...\n"); 723 int rc = usb_kbd_create_function( kbd_dev);730 int rc = usb_kbd_create_function(hid_dev, kbd_dev); 724 731 if (rc != EOK) { 725 732 usb_kbd_destroy(kbd_dev); 726 733 return rc; 727 734 } 728 735 729 736 return EOK; 730 737 } … … 738 745 return false; 739 746 } 740 747 741 748 usb_kbd_t *kbd_dev = (usb_kbd_t *)data; 742 749 assert(kbd_dev != NULL); 743 750 744 751 // TODO: add return value from this function 745 752 usb_kbd_process_data(hid_dev, kbd_dev); 746 753 747 754 return true; 748 755 } … … 773 780 return; 774 781 } 775 782 776 783 // hangup session to the console 777 784 async_hangup(kbd_dev->console_sess); 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 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 784 794 // free all buffers 785 free(kbd_dev->keys); 786 free(kbd_dev->keys_old); 787 free(kbd_dev->led_data); 788 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 } 789 804 if (kbd_dev->led_path != NULL) { 790 805 usb_hid_report_path_free(kbd_dev->led_path); … … 793 808 usb_hid_report_output_free(kbd_dev->output_buffer); 794 809 } 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 }803 810 } 804 811 … … 810 817 return; 811 818 } 812 819 813 820 if (data != NULL) { 814 usb_kbd_t *kbd_dev = data;821 usb_kbd_t *kbd_dev = (usb_kbd_t *)data; 815 822 if (usb_kbd_is_initialized(kbd_dev)) { 816 823 usb_kbd_mark_unusable(kbd_dev); 817 /* wait for autorepeat */ 818 async_usleep(CHECK_DELAY); 824 } else { 819 825 usb_kbd_destroy(kbd_dev); 820 826 } … … 829 835 USB_KBD_BOOT_REPORT_DESCRIPTOR, 830 836 USB_KBD_BOOT_REPORT_DESCRIPTOR_SIZE); 831 837 832 838 if (rc != EOK) { 833 839 usb_log_error("Failed to parse boot report descriptor: %s\n", … … 835 841 return rc; 836 842 } 837 843 838 844 rc = usbhid_req_set_protocol(&hid_dev->usb_dev->ctrl_pipe, 839 845 hid_dev->usb_dev->interface_no, USB_HID_PROTOCOL_BOOT); 840 846 841 847 if (rc != EOK) { 842 848 usb_log_warning("Failed to set boot protocol to the device: " … … 844 850 return rc; 845 851 } 846 852 847 853 return EOK; 848 854 } -
uspace/drv/bus/usb/usbhid/kbd/kbddev.h
re3f7418 r3958e315 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;116 113 } usb_kbd_t; 117 114 -
uspace/drv/bus/usb/usbhid/kbd/kbdrepeat.c
re3f7418 r3958e315 46 46 47 47 48 /** Delay between auto-repeat state checks when no key is being repeated. */ 49 static unsigned int CHECK_DELAY = 10000; 48 50 49 51 /*----------------------------------------------------------------------------*/ … … 71 73 { 72 74 unsigned int delay = 0; 73 75 74 76 usb_log_debug("Starting autorepeat loop.\n"); 75 77 … … 77 79 // check if the kbd structure is usable 78 80 if (!usb_kbd_is_initialized(kbd)) { 79 usb_log_warning("kbd not ready, exiting autorepeat.\n"); 81 if (usb_kbd_is_ready_to_destroy(kbd)) { 82 usb_kbd_destroy(kbd); 83 } 80 84 return; 81 85 } 82 86 83 fibril_mutex_lock( &kbd->repeat_mtx);87 fibril_mutex_lock(kbd->repeat_mtx); 84 88 85 89 if (kbd->repeat.key_new > 0) { … … 105 109 delay = CHECK_DELAY; 106 110 } 107 fibril_mutex_unlock( &kbd->repeat_mtx);111 fibril_mutex_unlock(kbd->repeat_mtx); 108 112 109 113 async_usleep(delay); … … 126 130 { 127 131 usb_log_debug("Autorepeat fibril spawned.\n"); 128 132 129 133 if (arg == NULL) { 130 134 usb_log_error("No device!\n"); 131 135 return EINVAL; 132 136 } 133 137 134 138 usb_kbd_t *kbd = (usb_kbd_t *)arg; 135 139 136 140 usb_kbd_repeat_loop(kbd); 137 141 138 142 return EOK; 139 143 } … … 152 156 void usb_kbd_repeat_start(usb_kbd_t *kbd, unsigned int key) 153 157 { 154 fibril_mutex_lock( &kbd->repeat_mtx);158 fibril_mutex_lock(kbd->repeat_mtx); 155 159 kbd->repeat.key_new = key; 156 fibril_mutex_unlock( &kbd->repeat_mtx);160 fibril_mutex_unlock(kbd->repeat_mtx); 157 161 } 158 162 … … 170 174 void usb_kbd_repeat_stop(usb_kbd_t *kbd, unsigned int key) 171 175 { 172 fibril_mutex_lock( &kbd->repeat_mtx);176 fibril_mutex_lock(kbd->repeat_mtx); 173 177 if (key == kbd->repeat.key_new) { 174 178 kbd->repeat.key_new = 0; 175 179 } 176 fibril_mutex_unlock( &kbd->repeat_mtx);180 fibril_mutex_unlock(kbd->repeat_mtx); 177 181 } 178 182 -
uspace/drv/bus/usb/usbhid/kbd/kbdrepeat.h
re3f7418 r3958e315 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 1000041 42 39 struct usb_kbd_t; 43 40 -
uspace/drv/bus/usb/usbhid/main.c
re3f7418 r3958e315 76 76 { 77 77 assert(dev != NULL); 78 79 /* Initialize device (get and process descriptors, get address, etc.) */ 78 79 /* 80 * Initialize device (get and process descriptors, get address, etc.) 81 */ 80 82 usb_log_debug("Initializing USB/HID device...\n"); 81 82 usb_hid_dev_t *hid_dev = 83 usb_device_data_alloc(dev, sizeof(usb_hid_dev_t)); 83 84 usb_hid_dev_t *hid_dev = usb_hid_new(); 84 85 if (hid_dev == NULL) { 85 86 usb_log_error("Error while creating USB/HID device " … … 87 88 return ENOMEM; 88 89 } 89 90 90 91 int rc = usb_hid_init(hid_dev, dev); 91 92 92 93 if (rc != EOK) { 93 94 usb_log_error("Failed to initialize USB/HID device.\n"); 94 95 usb_hid_destroy(hid_dev); 95 96 return rc; 96 } 97 97 } 98 98 99 usb_log_debug("USB/HID device structure initialized.\n"); 99 100 100 101 /* 101 102 * 1) subdriver vytvori vlastnu ddf_fun, vlastne ddf_dev_ops, ktore da … … 108 109 * pouzit usb/classes/hid/iface.h - prvy int je telefon 109 110 */ 110 111 111 112 /* Start automated polling function. 112 113 * This will create a separate fibril that will query the device … … 124 125 /* Custom argument. */ 125 126 hid_dev); 126 127 128 127 129 if (rc != EOK) { 128 130 usb_log_error("Failed to start polling fibril for `%s'.\n", 129 131 dev->ddf_dev->name); 130 usb_hid_destroy(hid_dev);131 132 return rc; 132 133 } 133 hid_dev->running = true;134 dev->driver_data = hid_dev;135 134 136 135 /* … … 154 153 { 155 154 usb_log_debug("usb_hid_device_add()\n"); 156 155 157 156 if (dev == NULL) { 158 157 usb_log_warning("Wrong parameter given for add_device().\n"); 159 158 return EINVAL; 160 159 } 161 160 162 161 if (dev->interface_no < 0) { 163 162 usb_log_warning("Device is not a supported HID device.\n"); … … 166 165 return ENOTSUP; 167 166 } 168 167 169 168 int rc = usb_hid_try_add_device(dev); 170 169 171 170 if (rc != EOK) { 172 171 usb_log_warning("Device is not a supported HID device.\n"); … … 175 174 return rc; 176 175 } 177 176 178 177 usb_log_info("HID device `%s' ready to use.\n", dev->ddf_dev->name); 179 178 … … 183 182 /*----------------------------------------------------------------------------*/ 184 183 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 */ 184 /* Currently, the framework supports only device adding. Once the framework 185 * supports unplug, more callbacks will be added. */ 212 186 static usb_driver_ops_t usb_hid_driver_ops = { 213 .device_add = usb_hid_device_add, 214 .device_gone = usb_hid_device_gone, 187 .device_add = usb_hid_device_add, 215 188 }; 216 189 217 190 218 /* *The driver itself. */191 /* The driver itself. */ 219 192 static usb_driver_t usb_hid_driver = { 220 193 .name = NAME, -
uspace/drv/bus/usb/usbhid/mouse/mousedev.c
re3f7418 r3958e315 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 }203 188 } 204 189 … … 214 199 return; 215 200 } 216 201 217 202 int count = ((wheel < 0) ? -wheel : wheel) * ARROWS_PER_SINGLE_WHEEL; 218 203 int i; 219 204 220 205 for (i = 0; i < count; i++) { 221 206 /* Send arrow press and release. */ … … 261 246 { 262 247 assert(mouse_dev != NULL); 263 248 264 249 if (mouse_dev->mouse_sess == NULL) { 265 250 usb_log_warning(NAME " No console session.\n"); … … 279 264 async_exchange_end(exch); 280 265 } 281 266 282 267 if (wheel != 0) 283 268 usb_mouse_send_wheel(mouse_dev, wheel); 284 269 285 270 /* 286 271 * Buttons … … 289 274 usb_hid_report_path_append_item(path, USB_HIDUT_PAGE_BUTTON, 0); 290 275 usb_hid_report_path_set_report_id(path, hid_dev->report_id); 291 276 292 277 usb_hid_report_field_t *field = usb_hid_report_get_sibling( 293 278 hid_dev->report, NULL, path, USB_HID_PATH_COMPARE_END … … 324 309 USB_HID_REPORT_TYPE_INPUT); 325 310 } 326 311 327 312 usb_hid_report_path_free(path); 328 313 … … 336 321 assert(hid_dev != NULL); 337 322 assert(mouse != NULL); 338 323 339 324 /* Create the exposed function. */ 340 325 usb_log_debug("Creating DDF function %s...\n", HID_MOUSE_FUN_NAME); … … 345 330 return ENOMEM; 346 331 } 347 332 348 333 fun->ops = &mouse->ops; 349 334 fun->driver_data = mouse; … … 353 338 usb_log_error("Could not bind DDF function: %s.\n", 354 339 str_error(rc)); 355 return rc; 356 } 357 340 ddf_fun_destroy(fun); 341 return rc; 342 } 343 358 344 usb_log_debug("Adding DDF function to category %s...\n", 359 345 HID_MOUSE_CATEGORY); … … 363 349 "Could not add DDF function to category %s: %s.\n", 364 350 HID_MOUSE_CATEGORY, str_error(rc)); 365 return rc;366 }367 mouse->mouse_fun = fun;368 351 ddf_fun_destroy(fun); 352 return rc; 353 } 354 369 355 /* 370 356 * Special function for acting as keyboard (wheel) … … 378 364 return ENOMEM; 379 365 } 380 366 381 367 /* 382 368 * Store the initialized HID device and HID ops … … 390 376 usb_log_error("Could not bind DDF function: %s.\n", 391 377 str_error(rc)); 392 return rc; 393 } 394 378 ddf_fun_destroy(fun); 379 return rc; 380 } 381 395 382 usb_log_debug("Adding DDF function to category %s...\n", 396 383 HID_MOUSE_WHEEL_CATEGORY); … … 400 387 "Could not add DDF function to category %s: %s.\n", 401 388 HID_MOUSE_WHEEL_CATEGORY, str_error(rc)); 402 return rc;403 }404 mouse->wheel_fun = fun;405 389 ddf_fun_destroy(fun); 390 return rc; 391 } 392 406 393 return EOK; 407 394 } … … 454 441 { 455 442 usb_log_debug("Initializing HID/Mouse structure...\n"); 456 443 457 444 if (hid_dev == NULL) { 458 445 usb_log_error("Failed to init keyboard structure: no structure" … … 460 447 return EINVAL; 461 448 } 462 449 463 450 usb_mouse_t *mouse_dev = usb_mouse_new(); 464 451 if (mouse_dev == NULL) { … … 467 454 return ENOMEM; 468 455 } 469 456 470 457 // FIXME: This may not be optimal since stupid hardware vendor may 471 458 // use buttons 1, 2, 3 and 6000 and we would allocate array of … … 477 464 hid_dev->report_id) + 1; 478 465 mouse_dev->buttons = calloc(mouse_dev->buttons_count, sizeof(int32_t)); 479 466 480 467 if (mouse_dev->buttons == NULL) { 481 468 usb_log_error(NAME ": out of memory, giving up on device!\n"); … … 487 474 // save the Mouse device structure into the HID device structure 488 475 *data = mouse_dev; 489 476 490 477 // set handler for incoming calls 491 478 mouse_dev->ops.default_handler = default_connection_handler; 492 479 493 480 // TODO: how to know if the device supports the request??? 494 481 usbhid_req_set_idle(&hid_dev->usb_dev->ctrl_pipe, 495 482 hid_dev->usb_dev->interface_no, IDLE_RATE); 496 483 497 484 int rc = usb_mouse_create_function(hid_dev, mouse_dev); 498 485 if (rc != EOK) { … … 500 487 return rc; 501 488 } 502 489 503 490 return EOK; 504 491 } … … 513 500 return false; 514 501 } 515 502 516 503 usb_mouse_t *mouse_dev = (usb_mouse_t *)data; 517 504 … … 524 511 { 525 512 if (data != NULL) { 526 usb_mouse_destroy( data);513 usb_mouse_destroy((usb_mouse_t *)data); 527 514 } 528 515 } … … 535 522 USB_MOUSE_BOOT_REPORT_DESCRIPTOR, 536 523 USB_MOUSE_BOOT_REPORT_DESCRIPTOR_SIZE); 537 524 538 525 if (rc != EOK) { 539 526 usb_log_error("Failed to parse boot report descriptor: %s\n", … … 541 528 return rc; 542 529 } 543 530 544 531 rc = usbhid_req_set_protocol(&hid_dev->usb_dev->ctrl_pipe, 545 532 hid_dev->usb_dev->interface_no, USB_HID_PROTOCOL_BOOT); 546 533 547 534 if (rc != EOK) { 548 535 usb_log_warning("Failed to set boot protocol to the device: " … … 550 537 return rc; 551 538 } 552 539 553 540 return EOK; 554 541 } -
uspace/drv/bus/usb/usbhid/mouse/mousedev.h
re3f7418 r3958e315 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;61 57 } usb_mouse_t; 62 58 -
uspace/drv/bus/usb/usbhid/multimedia/multimedia.c
re3f7418 r3958e315 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;71 69 } usb_multimedia_t; 72 70 … … 88 86 { 89 87 usb_log_debug(NAME " default_connection_handler()\n"); 90 88 91 89 usb_multimedia_t *multim_dev = (usb_multimedia_t *)fun->driver_data; 92 90 93 91 if (multim_dev == NULL) { 94 92 async_answer_0(icallid, EINVAL); 95 93 return; 96 94 } 97 95 98 96 async_sess_t *sess = 99 97 async_callback_receive_start(EXCHANGE_SERIALIZE, icall); … … 139 137 assert(hid_dev != NULL); 140 138 assert(multim_dev != NULL); 141 139 142 140 kbd_event_t ev; 143 141 144 142 ev.type = type; 145 143 ev.key = key; … … 153 151 return; 154 152 } 155 153 156 154 async_exch_t *exch = async_exchange_begin(multim_dev->console_sess); 157 155 async_msg_4(exch, KBDEV_EVENT, ev.type, ev.key, ev.mods, ev.c); … … 171 169 return ENOMEM; 172 170 } 173 171 174 172 fun->ops = &multimedia_ops; 175 173 fun->driver_data = multim_dev; // TODO: maybe change to hid_dev->data 176 174 177 175 int rc = ddf_fun_bind(fun); 178 176 if (rc != EOK) { 179 177 usb_log_error("Could not bind DDF function: %s.\n", 180 178 str_error(rc)); 179 // TODO: Can / should I destroy the DDF function? 181 180 ddf_fun_destroy(fun); 182 181 return rc; 183 182 } 184 183 185 184 usb_log_debug("%s function created (handle: %" PRIun ").\n", 186 185 NAME, fun->handle); 187 186 188 187 rc = ddf_fun_add_to_category(fun, "keyboard"); 189 188 if (rc != EOK) { … … 191 190 "Could not add DDF function to category 'keyboard': %s.\n", 192 191 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 multim_dev->fun = fun; 197 196 198 197 return EOK; 199 198 } … … 206 205 return EINVAL; /*! @todo Other return code? */ 207 206 } 208 207 209 208 usb_log_debug(NAME " Initializing HID/multimedia structure...\n"); 210 209 211 210 usb_multimedia_t *multim_dev = (usb_multimedia_t *)malloc( 212 211 sizeof(usb_multimedia_t)); … … 214 213 return ENOMEM; 215 214 } 216 215 217 216 multim_dev->console_sess = NULL; 218 217 219 218 /*! @todo Autorepeat */ 220 219 221 220 // save the KBD device structure into the HID device structure 222 221 *data = multim_dev; 223 222 224 223 usb_log_debug(NAME " HID/multimedia device structure initialized.\n"); 225 224 226 225 int rc = usb_multimedia_create_function(hid_dev, multim_dev); 227 226 if (rc != EOK) 228 227 return rc; 229 228 230 229 usb_log_debug(NAME " HID/multimedia structure initialized.\n"); 231 230 232 231 return EOK; 233 232 } … … 240 239 return; 241 240 } 242 241 243 242 if (data != NULL) { 244 243 usb_multimedia_t *multim_dev = (usb_multimedia_t *)data; 245 244 // hangup session to the console 246 245 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 }254 246 } 255 247 } … … 265 257 266 258 usb_multimedia_t *multim_dev = (usb_multimedia_t *)data; 267 259 268 260 usb_hid_report_path_t *path = usb_hid_report_path(); 269 261 usb_hid_report_path_append_item(path, USB_HIDUT_PAGE_CONSUMER, 0); … … 291 283 key); 292 284 } 293 285 294 286 field = usb_hid_report_get_sibling( 295 287 hid_dev->report, field, path, USB_HID_PATH_COMPARE_END 296 288 | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY, 297 289 USB_HID_REPORT_TYPE_INPUT); 298 } 290 } 299 291 300 292 usb_hid_report_path_free(path); 301 293 302 294 return true; 303 295 } -
uspace/drv/bus/usb/usbhid/subdrivers.h
re3f7418 r3958e315 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
re3f7418 r3958e315 54 54 55 55 /* Array of endpoints expected on the device, NULL terminated. */ 56 usb_endpoint_description_t *usb_hid_endpoints[ ] = {56 usb_endpoint_description_t *usb_hid_endpoints[USB_HID_POLL_EP_COUNT + 1] = { 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 = 158 usb_generic_hid_deinit; 159 157 hid_dev->subdrivers[hid_dev->subdriver_count].deinit = NULL; 158 160 159 // set subdriver count 161 160 ++hid_dev->subdriver_count; 162 161 163 162 return EOK; 164 163 } … … 171 170 assert(hid_dev != NULL); 172 171 assert(hid_dev->usb_dev != NULL); 173 172 174 173 return (hid_dev->usb_dev->descriptors.device.vendor_id 175 174 == mapping->vendor_id … … 185 184 assert(hid_dev != NULL); 186 185 assert(mapping != NULL); 187 186 188 187 usb_hid_report_path_t *usage_path = usb_hid_report_path(); 189 188 if (usage_path == NULL) { … … 203 202 ++i; 204 203 } 205 204 206 205 assert(hid_dev->report != NULL); 207 206 208 207 usb_log_debug("Compare flags: %d\n", mapping->compare); 209 208 210 209 bool matches = false; 211 210 uint8_t report_id = mapping->report_id; … … 235 234 USB_HID_REPORT_TYPE_INPUT); 236 235 } while (!matches && report_id != 0); 237 236 238 237 usb_hid_report_path_free(usage_path); 239 238 240 239 return matches; 241 240 } … … 247 246 { 248 247 int i; 249 248 250 249 if (count <= 0) { 251 250 hid_dev->subdriver_count = 0; … … 253 252 return EOK; 254 253 } 255 254 256 255 // add one generic HID subdriver per device 257 256 258 257 hid_dev->subdrivers = (usb_hid_subdriver_t *)malloc((count + 1) * 259 258 sizeof(usb_hid_subdriver_t)); … … 261 260 return ENOMEM; 262 261 } 263 262 264 263 for (i = 0; i < count; ++i) { 265 264 hid_dev->subdrivers[i].init = subdrivers[i]->init; … … 268 267 hid_dev->subdrivers[i].poll_end = subdrivers[i]->poll_end; 269 268 } 270 269 271 270 hid_dev->subdrivers[count].init = usb_generic_hid_init; 272 271 hid_dev->subdrivers[count].poll = usb_generic_hid_polling_callback; 273 hid_dev->subdrivers[count].deinit = usb_generic_hid_deinit;272 hid_dev->subdrivers[count].deinit = NULL; 274 273 hid_dev->subdrivers[count].poll_end = NULL; 275 274 276 275 hid_dev->subdriver_count = count + 1; 277 276 278 277 return EOK; 279 278 } … … 284 283 { 285 284 assert(hid_dev != NULL); 286 285 287 286 const usb_hid_subdriver_t *subdrivers[USB_HID_MAX_SUBDRIVERS]; 288 287 289 288 int i = 0, count = 0; 290 289 const usb_hid_subdriver_mapping_t *mapping = &usb_hid_subdrivers[i]; … … 292 291 bool ids_matched; 293 292 bool matched; 294 293 295 294 while (count < USB_HID_MAX_SUBDRIVERS && 296 295 (mapping->usage_path != NULL … … 340 339 mapping = &usb_hid_subdrivers[++i]; 341 340 } 342 341 343 342 // we have all subdrivers determined, save them into the hid device 344 343 return usb_hid_save_subdrivers(hid_dev, subdrivers, count); … … 350 349 { 351 350 assert(hid_dev != NULL && dev != NULL); 352 351 353 352 int rc = EOK; 354 353 355 354 if (dev->pipes[USB_HID_KBD_POLL_EP_NO].present) { 356 355 usb_log_debug("Found keyboard endpoint.\n"); … … 370 369 rc = ENOTSUP; 371 370 } 372 371 373 372 return rc; 374 373 } … … 379 378 { 380 379 assert(hid_dev != NULL && hid_dev->report != NULL); 381 380 382 381 uint8_t report_id = 0; 383 382 size_t size; 384 383 385 384 size_t max_size = 0; 386 385 387 386 do { 388 387 usb_log_debug("Getting size of the report.\n"); … … 395 394 report_id, USB_HID_REPORT_TYPE_INPUT); 396 395 } while (report_id != 0); 397 396 398 397 usb_log_debug("Max size of input report: %zu\n", max_size); 399 398 400 399 hid_dev->max_input_report_size = max_size; 401 400 assert(hid_dev->input_report == NULL); 402 401 403 402 hid_dev->input_report = malloc(max_size); 404 403 if (hid_dev->input_report == NULL) { … … 406 405 } 407 406 memset(hid_dev->input_report, 0, max_size); 408 407 409 408 return EOK; 410 409 } … … 412 411 /*----------------------------------------------------------------------------*/ 413 412 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 414 438 int usb_hid_init(usb_hid_dev_t *hid_dev, usb_device_t *dev) 415 439 { 416 440 int rc, i; 417 441 418 442 usb_log_debug("Initializing HID structure...\n"); 419 443 420 444 if (hid_dev == NULL) { 421 445 usb_log_error("Failed to init HID structure: no structure given" … … 423 447 return EINVAL; 424 448 } 425 449 426 450 if (dev == NULL) { 427 451 usb_log_error("Failed to init HID structure: no USB device" … … 429 453 return EINVAL; 430 454 } 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 455 440 456 /* The USB device should already be initialized, save it in structure */ 441 457 hid_dev->usb_dev = dev; 442 hid_dev->poll_pipe_index = -1; 443 458 444 459 rc = usb_hid_check_pipes(hid_dev, dev); 445 460 if (rc != EOK) { … … 450 465 rc = usb_hid_process_report_descriptor(hid_dev->usb_dev, 451 466 hid_dev->report, &hid_dev->report_desc, &hid_dev->report_desc_size); 452 467 453 468 bool fallback = false; 454 469 455 470 if (rc == EOK) { 456 471 // try to find subdrivers that may want to handle this device … … 469 484 fallback = true; 470 485 } 471 486 472 487 if (fallback) { 473 488 // fall back to boot protocol … … 495 510 } 496 511 } 497 512 498 513 if (rc != EOK) { 499 514 usb_log_error("No subdriver for handling this device could be" … … 527 542 rc = (ok) ? EOK : -1; // what error to report 528 543 } 529 530 544 545 531 546 if (rc == EOK) { 532 547 // save max input report size and allocate space for the report … … 537 552 } 538 553 } 539 540 554 555 541 556 return rc; 542 557 } … … 548 563 { 549 564 int i; 550 565 551 566 if (dev == NULL || arg == NULL || buffer == NULL) { 552 567 usb_log_error("Missing arguments to polling callback.\n"); 553 568 return false; 554 569 } 555 570 556 571 usb_hid_dev_t *hid_dev = (usb_hid_dev_t *)arg; 557 572 558 573 assert(hid_dev->input_report != NULL); 559 574 usb_log_debug("New data [%zu/%zu]: %s\n", buffer_size, … … 567 582 usb_hid_new_report(hid_dev); 568 583 } 569 584 570 585 // parse the input report 571 586 572 587 int rc = usb_hid_parse_report(hid_dev->report, buffer, buffer_size, 573 588 &hid_dev->report_id); 574 589 575 590 if (rc != EOK) { 576 591 usb_log_warning("Error in usb_hid_parse_report():" 577 592 "%s\n", str_error(rc)); 578 593 } 579 594 580 595 bool cont = false; 581 596 582 597 // continue if at least one of the subdrivers want to continue 583 598 for (i = 0; i < hid_dev->subdriver_count; ++i) { … … 588 603 } 589 604 } 590 605 591 606 return cont; 592 607 } … … 598 613 { 599 614 int i; 600 615 601 616 if (dev == NULL || arg == NULL) { 602 617 return; 603 618 } 604 619 605 620 usb_hid_dev_t *hid_dev = (usb_hid_dev_t *)arg; 606 621 607 622 for (i = 0; i < hid_dev->subdriver_count; ++i) { 608 623 if (hid_dev->subdrivers[i].poll_end != NULL) { … … 611 626 } 612 627 } 613 614 hid_dev->running = false;628 629 usb_hid_destroy(hid_dev); 615 630 } 616 631 … … 634 649 { 635 650 int i; 636 651 637 652 if (hid_dev == NULL) { 638 653 return; 639 654 } 640 655 641 656 usb_log_debug("Subdrivers: %p, subdriver count: %d\n", 642 657 hid_dev->subdrivers, hid_dev->subdriver_count); 643 658 644 659 assert(hid_dev->subdrivers != NULL 645 660 || hid_dev->subdriver_count == 0); 646 661 647 662 for (i = 0; i < hid_dev->subdriver_count; ++i) { 648 663 if (hid_dev->subdrivers[i].deinit != NULL) { … … 651 666 } 652 667 } 653 654 /* Free allocated structures */ 655 free(hid_dev->subdrivers); 656 free(hid_dev->report_desc); 657 658 /* Destroy the parser */ 668 669 // free the subdrivers info 670 if (hid_dev->subdrivers != NULL) { 671 free(hid_dev->subdrivers); 672 } 673 674 // destroy the parser 659 675 if (hid_dev->report != NULL) { 660 676 usb_hid_free_report(hid_dev->report); 661 677 } 662 678 679 if (hid_dev->report_desc != NULL) { 680 free(hid_dev->report_desc); 681 } 663 682 } 664 683 -
uspace/drv/bus/usb/usbhid/usbhid.h
re3f7418 r3958e315 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;132 131 }; 133 132 … … 141 140 }; 142 141 143 extern usb_endpoint_description_t *usb_hid_endpoints[];142 usb_endpoint_description_t *usb_hid_endpoints[USB_HID_POLL_EP_COUNT + 1]; 144 143 145 144 /*----------------------------------------------------------------------------*/ 145 146 usb_hid_dev_t *usb_hid_new(void); 146 147 147 148 int usb_hid_init(usb_hid_dev_t *hid_dev, usb_device_t *dev); -
uspace/drv/bus/usb/usbhub/port.c
re3f7418 r3958e315 288 288 port->attached_device.fun = NULL; 289 289 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 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 } 309 296 port->attached_device.address = -1; 310 297 fibril_mutex_unlock(&port->mutex); -
uspace/drv/bus/usb/usbhub/usbhub.c
re3f7418 r3958e315 117 117 ddf_fun_destroy(hub->hub_fun); 118 118 119 free(hub); 120 usb_dev->driver_data = NULL; 119 121 usb_log_info("USB hub driver, stopped and cleaned.\n"); 120 122 return EOK; … … 252 254 { 253 255 assert(usb_dev); 254 usb_hub_dev_t *hub_dev = 255 usb_device_data_alloc(usb_dev, sizeof(usb_hub_dev_t)); 256 usb_hub_dev_t *hub_dev = malloc(sizeof(usb_hub_dev_t)); 256 257 if (!hub_dev) 257 258 return NULL; 258 259 259 260 hub_dev->usb_device = usb_dev; 261 260 262 hub_dev->ports = NULL; 261 263 hub_dev->port_count = 0; … … 264 266 fibril_mutex_initialize(&hub_dev->pending_ops_mutex); 265 267 fibril_condvar_initialize(&hub_dev->pending_ops_cv); 268 usb_dev->driver_data = hub_dev; 266 269 267 270 return hub_dev; -
uspace/drv/bus/usb/usbmast/main.c
re3f7418 r3958e315 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 108 84 /** Callback when new device is attached and recognized as a mass storage. 109 85 * … … 118 94 119 95 /* Allocate softstate */ 120 mdev = usb_device_data_alloc(dev,sizeof(usbmast_dev_t));96 dev->driver_data = mdev = malloc(sizeof(usbmast_dev_t)); 121 97 if (mdev == NULL) { 122 98 usb_log_error("Failed allocating softstate.\n"); … … 136 112 137 113 usb_log_debug("Get LUN count...\n"); 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++) { 114 mdev->luns = usb_masstor_get_lun_count(mdev); 115 116 for (i = 0; i < mdev->luns; i++) { 147 117 rc = usbmast_fun_create(mdev, i); 148 118 if (rc != EOK) … … 152 122 return EOK; 153 123 error: 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); 124 /* XXX Destroy functions */ 167 125 return rc; 168 126 } … … 204 162 } 205 163 206 mfun->ddf_fun = fun;207 164 mfun->mdev = mdev; 208 165 mfun->lun = lun; … … 255 212 256 213 free(fun_name); 257 mdev->luns[lun] = fun;258 214 259 215 return EOK; … … 339 295 static usb_driver_ops_t usbmast_driver_ops = { 340 296 .device_add = usbmast_device_add, 341 .device_gone = usbmast_device_gone,342 297 }; 343 298 -
uspace/drv/bus/usb/usbmast/usbmast.h
re3f7418 r3958e315 41 41 42 42 /** Mass storage device. */ 43 typedef struct usbmast_dev{43 typedef struct { 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 lun_count; 50 /** LUN functions */ 51 ddf_fun_t **luns; 49 unsigned luns; 52 50 } usbmast_dev_t; 53 54 51 55 52 /** Mass storage function. -
uspace/drv/bus/usb/usbmid/dump.c
re3f7418 r3958e315 47 47 * @param depth Nesting depth. 48 48 */ 49 static void dump_tree_descriptor( constuint8_t *data, size_t depth)49 static void dump_tree_descriptor(uint8_t *data, size_t depth) 50 50 { 51 51 if (data == NULL) { 52 52 return; 53 53 } 54 const int type = data[1];54 int type = (int) *(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( 74 usb_dp_parser_t *parser, usb_dp_parser_data_t *data, 75 const uint8_t *root, size_t depth) 73 static void dump_tree_internal(usb_dp_parser_t *parser, usb_dp_parser_data_t *data, 74 uint8_t *root, size_t depth) 76 75 { 77 76 if (root == NULL) { … … 79 78 } 80 79 dump_tree_descriptor(root, depth); 81 constuint8_t *child = usb_dp_get_nested_descriptor(parser, data, root);80 uint8_t *child = usb_dp_get_nested_descriptor(parser, data, root); 82 81 do { 83 82 dump_tree_internal(parser, data, child, depth + 1); … … 93 92 static void dump_tree(usb_dp_parser_t *parser, usb_dp_parser_data_t *data) 94 93 { 95 constuint8_t *ptr = data->data;94 uint8_t *ptr = data->data; 96 95 dump_tree_internal(parser, data, ptr, 0); 97 96 } -
uspace/drv/bus/usb/usbmid/explore.c
re3f7418 r3958e315 73 73 * @param list List where to add the interfaces. 74 74 */ 75 static void create_interfaces( constuint8_t *config_descriptor,75 static void create_interfaces(uint8_t *config_descriptor, 76 76 size_t config_descriptor_size, list_t *list) 77 77 { 78 constusb_dp_parser_data_t data = {78 usb_dp_parser_data_t data = { 79 79 .data = config_descriptor, 80 80 .size = config_descriptor_size, … … 86 86 }; 87 87 88 const uint8_t *interface_ptr =89 usb_dp_get_nested_descriptor(&parser, &data,data.data);88 uint8_t *interface_ptr = usb_dp_get_nested_descriptor(&parser, &data, 89 data.data); 90 90 if (interface_ptr == NULL) { 91 91 return; … … 149 149 150 150 /* Short cuts to save on typing ;-). */ 151 const void*config_descriptor_raw = dev->descriptors.configuration;151 uint8_t *config_descriptor_raw = dev->descriptors.configuration; 152 152 size_t config_descriptor_size = dev->descriptors.configuration_size; 153 constusb_standard_configuration_descriptor_t *config_descriptor =154 config_descriptor_raw;153 usb_standard_configuration_descriptor_t *config_descriptor = 154 (usb_standard_configuration_descriptor_t *) 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 171 165 /* Create control function */ 172 usb_mid->ctl_fun = ddf_fun_create(dev->ddf_dev, fun_exposed, "ctl");173 if ( usb_mid->ctl_fun == NULL) {166 ddf_fun_t *ctl_fun = ddf_fun_create(dev->ddf_dev, fun_exposed, "ctl"); 167 if (ctl_fun == NULL) { 174 168 usb_log_error("Failed to create control function.\n"); 175 169 return false; 176 170 } 177 171 178 usb_mid->ctl_fun->ops = &mid_device_ops;179 180 rc = ddf_fun_bind( usb_mid->ctl_fun);172 ctl_fun->ops = &mid_device_ops; 173 174 rc = ddf_fun_bind(ctl_fun); 181 175 if (rc != EOK) { 182 176 usb_log_error("Failed to bind control function: %s.\n", 183 177 str_error(rc)); 184 ddf_fun_destroy(usb_mid->ctl_fun); 185 return false; 186 } 187 178 return false; 179 } 188 180 189 181 /* Create interface children. */ 190 list_initialize(&usb_mid->interface_list); 182 list_t interface_list; 183 list_initialize(&interface_list); 191 184 create_interfaces(config_descriptor_raw, config_descriptor_size, 192 & usb_mid->interface_list);193 194 list_foreach( usb_mid->interface_list, link) {185 &interface_list); 186 187 list_foreach(interface_list, link) { 195 188 usbmid_interface_t *iface = list_get_instance(link, 196 189 usbmid_interface_t, link); -
uspace/drv/bus/usb/usbmid/main.c
re3f7418 r3958e315 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 108 68 /** USB MID driver ops. */ 109 69 static usb_driver_ops_t mid_driver_ops = { 110 70 .device_add = usbmid_device_add, 111 .device_gone = usbmid_device_gone,112 71 }; 113 72 -
uspace/drv/bus/usb/usbmid/usbmid.c
re3f7418 r3958e315 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. */ 47 54 static int usb_iface_get_interface_impl(ddf_fun_t *fun, devman_handle_t handle, 48 55 int *iface_no) … … 63 70 static usb_iface_t child_usb_iface = { 64 71 .get_hc_handle = usb_iface_get_hc_handle_hub_child_impl, 65 .get_address = usb_iface_get_address_ hub_impl,72 .get_address = usb_iface_get_address_impl, 66 73 .get_interface = usb_iface_get_interface_impl 67 74 }; … … 72 79 }; 73 80 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 not83 * 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 to86 * mid_iface->fun->driver_data and freed in ddf_fun_destroy */87 return EOK;88 }89 81 90 82 /** Spawn new child device from one interface. … … 114 106 (int) interface_descriptor->interface_number); 115 107 if (rc < 0) { 116 return ENOMEM;108 goto error_leave; 117 109 } 118 110 119 111 /* Create the device. */ 120 112 child = ddf_fun_create(parent->ddf_dev, fun_inner, child_name); 121 free(child_name);122 113 if (child == NULL) { 123 return ENOMEM; 114 rc = ENOMEM; 115 goto error_leave; 124 116 } 125 117 … … 130 122 131 123 rc = usb_device_create_match_ids_from_interface(device_descriptor, 132 interface_descriptor, &child->match_ids); 124 interface_descriptor, 125 &child->match_ids); 133 126 if (rc != EOK) { 134 ddf_fun_destroy(child); 135 return rc; 127 goto error_leave; 136 128 } 137 129 138 130 rc = ddf_fun_bind(child); 139 131 if (rc != EOK) { 140 /* This takes care of match_id deallocation as well. */ 141 ddf_fun_destroy(child); 142 return rc; 132 goto error_leave; 143 133 } 144 134 145 135 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; 146 148 } 147 149 -
uspace/drv/bus/usb/usbmid/usbmid.h
re3f7418 r3958e315 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 66 60 bool usbmid_explore_device(usb_device_t *); 67 61 int usbmid_spawn_interface_child(usb_device_t *, usbmid_interface_t *, … … 69 63 const usb_standard_interface_descriptor_t *); 70 64 void usbmid_dump_descriptors(uint8_t *, size_t); 71 int usbmid_interface_destroy(usbmid_interface_t *mid_iface);72 65 73 66 #endif -
uspace/lib/usbdev/include/usb/dev/dp.h
re3f7418 r3958e315 59 59 typedef struct { 60 60 /** Used descriptor nesting. */ 61 constusb_dp_descriptor_nesting_t *nesting;61 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 constuint8_t *data;67 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 typedef void (*walk_callback_t)(const uint8_t *, size_t, void *); 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 *); 75 78 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 *); 79 void usb_dp_walk_simple(uint8_t *, size_t, usb_dp_descriptor_nesting_t *, 80 void (*)(uint8_t *, size_t, void *), void *); 83 81 84 82 #endif -
uspace/lib/usbdev/include/usb/dev/driver.h
re3f7418 r3958e315 43 43 usb_standard_device_descriptor_t device; 44 44 /** Full configuration descriptor of current configuration. */ 45 constuint8_t *configuration;45 uint8_t *configuration; 46 46 size_t configuration_size; 47 47 } usb_device_descriptors_t; … … 53 53 typedef struct { 54 54 /** Interface descriptor. */ 55 constusb_standard_interface_descriptor_t *interface;55 usb_standard_interface_descriptor_t *interface; 56 56 /** Pointer to start of descriptor tree bound with this interface. */ 57 constuint8_t *nested_descriptors;57 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 constusb_driver_ops_t *ops;160 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 **, constuint8_t *, size_t, int, int,170 usb_endpoint_description_t **, 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);176 175 177 size_t usb_interface_count_alternates( constuint8_t *, size_t, uint8_t);178 int usb_alternate_interfaces_create( constuint8_t *, size_t, int,176 size_t usb_interface_count_alternates(uint8_t *, size_t, uint8_t); 177 int usb_alternate_interfaces_create(uint8_t *, size_t, int, 179 178 usb_alternate_interfaces_t **); 180 179 -
uspace/lib/usbdev/include/usb/dev/pipes.h
re3f7418 r3958e315 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, constuint8_t *, size_t, usb_device_connection_t *);173 size_t, 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
re3f7418 r3958e315 48 48 * @return Number of alternate interfaces for @p interface_no interface. 49 49 */ 50 size_t usb_interface_count_alternates( constuint8_t *config_descr,50 size_t usb_interface_count_alternates(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 constusb_dp_parser_t dp_parser = {56 usb_dp_parser_t dp_parser = { 57 57 .nesting = usb_dp_standard_descriptor_nesting 58 58 }; 59 constusb_dp_parser_data_t dp_data = {59 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 constuint8_t *iface_ptr = usb_dp_get_nested_descriptor(&dp_parser,67 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( constuint8_t *config_descr,92 int usb_alternate_interfaces_create(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 constuint8_t *iface_ptr = usb_dp_get_nested_descriptor(&dp_parser,142 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 constuint8_t *next = dp_data.data + dp_data.size;162 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
re3f7418 r3958e315 54 54 }; 55 55 56 static constusb_driver_t *driver = NULL;56 static 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, &pipes, &pipes_count); 117 dev->interface_no, alternate_setting, 118 &pipes, &pipes_count); 118 119 119 120 if (rc != EOK) { … … 152 153 gen_dev->driver_data = dev; 153 154 154 rc = driver->ops->device_add(dev); 155 if (rc != EOK) 156 usb_device_destroy(dev); 157 return rc; 155 return driver->ops->device_add(dev); 158 156 } 159 157 /*----------------------------------------------------------------------------*/ … … 188 186 if (driver->ops->device_gone == NULL) 189 187 return ENOTSUP; 190 usb_device_t *usb_dev = gen_dev->driver_data; 191 const int ret = driver->ops->device_gone(usb_dev); 188 const int ret = driver->ops->device_gone(gen_dev->driver_data); 192 189 if (ret == EOK) 193 usb_device_destroy( usb_dev);190 usb_device_destroy(gen_dev->driver_data); 194 191 195 192 return ret; … … 322 319 int usb_device_create_pipes(const ddf_dev_t *dev, usb_device_connection_t *wire, 323 320 usb_endpoint_description_t **endpoints, 324 constuint8_t *config_descr, size_t config_descr_size,321 uint8_t *config_descr, size_t config_descr_size, 325 322 int interface_no, int interface_setting, 326 323 usb_endpoint_mapping_t **pipes_ptr, size_t *pipes_count_ptr) … … 336 333 int rc; 337 334 338 constsize_t pipe_count = count_other_pipes(endpoints);335 size_t pipe_count = count_other_pipes(endpoints); 339 336 if (pipe_count == 0) { 340 *pipes_count_ptr = pipe_count;341 337 *pipes_ptr = NULL; 342 338 return EOK; … … 449 445 { 450 446 assert(dev != NULL); 447 assert(((pipes != NULL) && (pipes_count > 0)) 448 || ((pipes == NULL) && (pipes_count == 0))); 451 449 452 450 if (pipes_count == 0) { 453 assert(pipes == NULL);454 451 return EOK; 455 452 } 456 assert(pipes != NULL);457 453 458 454 int rc; … … 472 468 size_t i; 473 469 for (i = 0; i < pipes_count; i++) { 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); 470 usb_pipe_unregister(pipes[i].pipe, &hc_conn); 478 471 free(pipes[i].pipe); 479 472 } … … 599 592 600 593 /* Ignore errors and hope for the best. */ 601 destroy_current_pipes(dev); 594 usb_device_destroy_pipes(dev->ddf_dev, dev->pipes, dev->pipes_count); 595 free(dev->descriptors.configuration); 602 596 603 597 if (dev->alternate_interfaces != NULL) { … … 605 599 } 606 600 free(dev->alternate_interfaces); 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 601 602 free(dev); 617 603 } 618 604 -
uspace/lib/usbdev/src/dp.c
re3f7418 r3958e315 75 75 * @return Whether @p ptr points inside <code>data->data</code> field. 76 76 */ 77 static bool is_valid_descriptor_pointer( constusb_dp_parser_data_t *data,78 constuint8_t *ptr)77 static bool is_valid_descriptor_pointer(usb_dp_parser_data_t *data, 78 uint8_t *ptr) 79 79 { 80 80 if (ptr == NULL) { … … 100 100 * @retval NULL Invalid input or no next descriptor. 101 101 */ 102 static const uint8_t *get_next_descriptor(constusb_dp_parser_data_t *data,103 constuint8_t *current)102 static uint8_t *get_next_descriptor(usb_dp_parser_data_t *data, 103 uint8_t *current) 104 104 { 105 105 assert(is_valid_descriptor_pointer(data, current)); 106 106 107 constuint8_t current_length = *current;108 constuint8_t *next = current + current_length;107 uint8_t current_length = *current; 108 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( const usb_dp_parser_data_t *data, constuint8_t *start)126 static int get_descriptor_type(usb_dp_parser_data_t *data, 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( constusb_dp_parser_t *parser,147 static bool is_nested_descriptor_type(usb_dp_parser_t *parser, 148 148 int child, int parent) 149 149 { 150 constusb_dp_descriptor_nesting_t *nesting = parser->nesting;150 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( constusb_dp_parser_t *parser,169 const usb_dp_parser_data_t *data, const uint8_t *child, constuint8_t *parent)168 static bool is_nested_descriptor(usb_dp_parser_t *parser, 169 usb_dp_parser_data_t *data, uint8_t *child, uint8_t *parent) 170 170 { 171 171 return is_nested_descriptor_type(parser, … … 183 183 * @retval NULL Invalid input. 184 184 */ 185 const uint8_t *usb_dp_get_nested_descriptor(constusb_dp_parser_t *parser,186 const usb_dp_parser_data_t *data, constuint8_t *parent)185 uint8_t *usb_dp_get_nested_descriptor(usb_dp_parser_t *parser, 186 usb_dp_parser_data_t *data, uint8_t *parent) 187 187 { 188 188 if (!is_valid_descriptor_pointer(data, parent)) { … … 190 190 } 191 191 192 constuint8_t *next = get_next_descriptor(data, parent);192 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 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); 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); 218 217 if (child == NULL) { 219 218 return get_next_descriptor(data, parent); 220 219 } 221 const uint8_t *next_child = 222 skip_nested_descriptors(parser, data, child); 220 uint8_t *next_child = skip_nested_descriptors(parser, data, child); 223 221 while (is_nested_descriptor(parser, data, next_child, parent)) { 224 222 next_child = skip_nested_descriptors(parser, data, next_child); … … 238 236 * @retval NULL Invalid input. 239 237 */ 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) 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) 243 240 { 244 241 if (!is_valid_descriptor_pointer(data, parent) … … 247 244 } 248 245 249 const uint8_t *possible_sibling = 250 skip_nested_descriptors(parser, data, sibling); 246 uint8_t *possible_sibling = skip_nested_descriptors(parser, data, sibling); 251 247 if (possible_sibling == NULL) { 252 248 return NULL; … … 273 269 * @param arg Custom (user) argument. 274 270 */ 275 static void usb_dp_browse_simple_internal( constusb_dp_parser_t *parser,276 const usb_dp_parser_data_t *data, constuint8_t *root, size_t depth,277 void (*callback)( constuint8_t *, size_t, void *), void *arg)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) 278 274 { 279 275 if (root == NULL) { … … 281 277 } 282 278 callback(root, depth, arg); 283 constuint8_t *child = usb_dp_get_nested_descriptor(parser, data, root);279 uint8_t *child = usb_dp_get_nested_descriptor(parser, data, root); 284 280 do { 285 281 usb_dp_browse_simple_internal(parser, data, child, depth + 1, … … 305 301 */ 306 302 void usb_dp_walk_simple(uint8_t *descriptors, size_t descriptors_size, 307 constusb_dp_descriptor_nesting_t *descriptor_nesting,308 walk_callback_t callback, void *arg)303 usb_dp_descriptor_nesting_t *descriptor_nesting, 304 void (*callback)(uint8_t *, size_t, void *), void *arg) 309 305 { 310 306 if ((descriptors == NULL) || (descriptors_size == 0) … … 313 309 } 314 310 315 constusb_dp_parser_data_t data = {311 usb_dp_parser_data_t data = { 316 312 .data = descriptors, 317 313 .size = descriptors_size, … … 319 315 }; 320 316 321 constusb_dp_parser_t parser = {317 usb_dp_parser_t parser = { 322 318 .nesting = descriptor_nesting 323 319 }; -
uspace/lib/usbdev/src/pipesinit.c
re3f7418 r3958e315 68 68 * @return Whether the given descriptor is endpoint descriptor. 69 69 */ 70 static inline bool is_endpoint_descriptor( constuint8_t *descriptor)70 static inline bool is_endpoint_descriptor(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 constusb_endpoint_description_t *found)82 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 constusb_endpoint_description_t *found_endpoint,122 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; 162 163 163 164 /* … … 166 167 167 168 /* Actual endpoint number is in bits 0..3 */ 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 }; 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; 183 183 184 184 /* … … 224 224 static int process_interface( 225 225 usb_endpoint_mapping_t *mapping, size_t mapping_count, 226 const usb_dp_parser_t *parser, constusb_dp_parser_data_t *parser_data,227 constuint8_t *interface_descriptor)228 { 229 constuint8_t *descriptor = usb_dp_get_nested_descriptor(parser,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, 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 const uint8_t *config_descriptor, size_t config_descriptor_size,286 uint8_t *configuration_descriptor, size_t configuration_descriptor_size, 287 287 usb_device_connection_t *connection) 288 288 { 289 289 assert(connection); 290 290 291 if (config _descriptor == NULL) {291 if (configuration_descriptor == NULL) { 292 292 return EBADMEM; 293 293 } 294 if (config _descriptor_size294 if (configuration_descriptor_size 295 295 < sizeof(usb_standard_configuration_descriptor_t)) { 296 296 return ERANGE; … … 310 310 * Prepare the descriptor parser. 311 311 */ 312 constusb_dp_parser_t dp_parser = {312 usb_dp_parser_t dp_parser = { 313 313 .nesting = descriptor_nesting 314 314 }; 315 constusb_dp_parser_data_t dp_data = {316 .data = config _descriptor,317 .size = config _descriptor_size,315 usb_dp_parser_data_t dp_data = { 316 .data = configuration_descriptor, 317 .size = configuration_descriptor_size, 318 318 .arg = connection 319 319 }; … … 322 322 * Iterate through all interfaces. 323 323 */ 324 constuint8_t *interface = usb_dp_get_nested_descriptor(&dp_parser,325 &dp_data, config _descriptor);324 uint8_t *interface = usb_dp_get_nested_descriptor(&dp_parser, 325 &dp_data, configuration_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, interface); 331 &dp_parser, &dp_data, 332 interface); 332 333 interface = usb_dp_get_sibling_descriptor(&dp_parser, &dp_data, 333 config _descriptor, interface);334 configuration_descriptor, interface); 334 335 } while (interface != NULL); 335 336 … … 513 514 { 514 515 assert(pipe); 515 assert(pipe->wire);516 516 assert(hc_connection); 517 517 -
uspace/lib/usbdev/src/request.c
re3f7418 r3958e315 425 425 426 426 /* Everything is okay, copy the descriptor. */ 427 memcpy(descriptor, &descriptor_tmp, sizeof(descriptor_tmp)); 427 memcpy(descriptor, &descriptor_tmp, 428 sizeof(descriptor_tmp)); 428 429 429 430 return EOK; … … 469 470 470 471 /* Everything is okay, copy the descriptor. */ 471 memcpy(descriptor, &descriptor_tmp, sizeof(descriptor_tmp)); 472 memcpy(descriptor, &descriptor_tmp, 473 sizeof(descriptor_tmp)); 472 474 473 475 return EOK; -
uspace/lib/usbhid/src/hidreport.c
re3f7418 r3958e315 69 69 * First nested descriptor of the configuration descriptor. 70 70 */ 71 constuint8_t *d =71 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 constuint8_t *iface_desc = d;94 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.