Changes in / [24aa62c:af430ce] in mainline
- Files:
-
- 6 deleted
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
.bzrignore
r24aa62c raf430ce 89 89 ./uspace/drv/usbhid/usbhid 90 90 ./uspace/drv/usbmid/usbmid 91 ./uspace/drv/usbmouse/usbmouse92 91 ./uspace/drv/vhc/vhc 93 92 ./uspace/srv/bd/ata_bd/ata_bd -
boot/arch/amd64/Makefile.inc
r24aa62c raf430ce 48 48 usbhid \ 49 49 usbmid \ 50 usbmouse \51 50 vhc 52 51 -
uspace/Makefile
r24aa62c raf430ce 122 122 drv/usbhub \ 123 123 drv/usbmid \ 124 drv/usbmouse \125 124 drv/vhc 126 125 endif … … 139 138 drv/usbhub \ 140 139 drv/usbmid \ 141 drv/usbmouse \142 140 drv/vhc 143 141 endif -
uspace/doc/doxygroups.h
r24aa62c raf430ce 245 245 246 246 /** 247 * @defgroup drvusbmouse USB mouse driver248 * @ingroup usb249 * @brief USB driver for mouse with boot protocol.250 */251 252 /**253 247 * @defgroup drvusbuhci UHCI driver 254 248 * @ingroup usb -
uspace/drv/usbhid/hiddev.c
r24aa62c raf430ce 149 149 usb_log_info("Processing descriptors...\n"); 150 150 151 // get the first configuration descriptor 152 usb_standard_configuration_descriptor_t config_desc; 153 151 154 int rc; 152 153 uint8_t *descriptors = NULL; 154 size_t descriptors_size; 155 rc = usb_request_get_full_configuration_descriptor_alloc( 156 &hid_dev->ctrl_pipe, 0, (void **) &descriptors, &descriptors_size); 157 if (rc != EOK) { 158 usb_log_error("Failed to retrieve config descriptor: %s.\n", 159 str_error(rc)); 160 return rc; 155 rc = usb_request_get_bare_configuration_descriptor(&hid_dev->ctrl_pipe, 156 0, &config_desc); 157 158 if (rc != EOK) { 159 usb_log_error("Failed to get bare config descriptor: %s.\n", 160 str_error(rc)); 161 return rc; 162 } 163 164 // prepare space for all underlying descriptors 165 uint8_t *descriptors = (uint8_t *)malloc(config_desc.total_length); 166 if (descriptors == NULL) { 167 usb_log_error("No memory!.\n"); 168 return ENOMEM; 169 } 170 171 size_t transferred = 0; 172 // get full configuration descriptor 173 rc = usb_request_get_full_configuration_descriptor(&hid_dev->ctrl_pipe, 174 0, descriptors, config_desc.total_length, &transferred); 175 176 if (rc != EOK) { 177 usb_log_error("Failed to get full config descriptor: %s.\n", 178 str_error(rc)); 179 free(descriptors); 180 return rc; 181 } 182 183 if (transferred != config_desc.total_length) { 184 usb_log_error("Configuration descriptor has wrong size (%u, " 185 "expected %u).\n", transferred, config_desc.total_length); 186 free(descriptors); 187 return ELIMIT; 161 188 } 162 189 … … 174 201 175 202 rc = usb_endpoint_pipe_initialize_from_configuration( 176 endpoint_mapping, 1, descriptors, descriptors_size,203 endpoint_mapping, 1, descriptors, config_desc.total_length, 177 204 &hid_dev->wire); 178 205 … … 206 233 assert(endpoint_mapping[0].interface != NULL); 207 234 208 rc = usbhid_dev_get_report_descriptor(hid_dev, 209 descriptors, descriptors_size, 235 rc = usbhid_dev_get_report_descriptor(hid_dev, descriptors, transferred, 210 236 (uint8_t *)endpoint_mapping[0].interface); 211 237 -
uspace/drv/usbhub/usbhub.c
r24aa62c raf430ce 149 149 } 150 150 151 / * Retrieve full configuration descriptor. */152 uint8_t *descriptors = NULL;153 size_t descriptors_size = 0;154 opResult = usb_request_get_ full_configuration_descriptor_alloc(151 //configuration descriptor 152 /// \TODO check other configurations? 153 usb_standard_configuration_descriptor_t config_descriptor; 154 opResult = usb_request_get_bare_configuration_descriptor( 155 155 &hub->endpoints.control, 0, 156 (void **) &descriptors, &descriptors_size); 157 if (opResult != EOK) { 158 usb_log_error("Could not get configuration descriptor: %s.\n", 159 str_error(opResult)); 156 &config_descriptor); 157 if(opResult!=EOK){ 158 dprintf(USB_LOG_LEVEL_ERROR, "could not get configuration descriptor, %d",opResult); 160 159 return opResult; 161 160 } 162 usb_standard_configuration_descriptor_t *config_descriptor 163 = (usb_standard_configuration_descriptor_t *) descriptors; 164 165 /* Set configuration. */ 161 //set configuration 166 162 opResult = usb_request_set_configuration(&hub->endpoints.control, 167 config_descriptor->configuration_number); 168 169 if (opResult != EOK) { 170 usb_log_error("Failed to set hub configuration: %s.\n", 171 str_error(opResult)); 163 config_descriptor.configuration_number); 164 165 if (opResult != EOK) { 166 dprintf(USB_LOG_LEVEL_ERROR, 167 "something went wrong when setting hub`s configuration, %d", 168 opResult); 172 169 return opResult; 173 170 } 174 171 dprintf(USB_LOG_LEVEL_DEBUG, "\tused configuration %d", 175 config_descriptor->configuration_number); 172 config_descriptor.configuration_number); 173 174 //full configuration descriptor 175 size_t transferred = 0; 176 uint8_t * descriptors = (uint8_t *)malloc(config_descriptor.total_length); 177 if (descriptors == NULL) { 178 dprintf(USB_LOG_LEVEL_ERROR, "insufficient memory"); 179 return ENOMEM; 180 } 181 opResult = usb_request_get_full_configuration_descriptor(&hub->endpoints.control, 182 0, descriptors, 183 config_descriptor.total_length, &transferred); 184 if(opResult!=EOK){ 185 free(descriptors); 186 dprintf(USB_LOG_LEVEL_ERROR, 187 "could not get full configuration descriptor, %d",opResult); 188 return opResult; 189 } 190 if (transferred != config_descriptor.total_length) { 191 dprintf(USB_LOG_LEVEL_ERROR, 192 "received incorrect full configuration descriptor"); 193 return ELIMIT; 194 } 176 195 177 196 usb_endpoint_mapping_t endpoint_mapping[1] = { … … 185 204 opResult = usb_endpoint_pipe_initialize_from_configuration( 186 205 endpoint_mapping, 1, 187 descriptors, descriptors_size,206 descriptors, config_descriptor.total_length, 188 207 &hub->device_connection); 189 208 if (opResult != EOK) { -
uspace/drv/usbmid/explore.c
r24aa62c raf430ce 42 42 #include "usbmid.h" 43 43 44 /** Allocate and retrieve full configuration descriptor. 45 * 46 * @param[in] dev USB device. 47 * @param[in] config_index Configuration index. 48 * @param[out] size Pointer where to store size of the allocated buffer. 49 * @return Allocated full configuration descriptor. 50 * @retval NULL Error occured. 51 */ 52 static void *get_configuration_descriptor(usbmid_device_t *dev, 53 size_t config_index, size_t *size) 54 { 55 usb_standard_configuration_descriptor_t config_descriptor; 56 int rc = usb_request_get_bare_configuration_descriptor(&dev->ctrl_pipe, 57 config_index, &config_descriptor); 58 if (rc != EOK) { 59 usb_log_error("Failed getting configuration descriptor: %s.\n", 60 str_error(rc)); 61 return NULL; 62 } 63 64 void *full_config_descriptor = malloc(config_descriptor.total_length); 65 if (full_config_descriptor == NULL) { 66 usb_log_fatal("Out of memory (wanted: %zuB).\n", 67 (size_t) config_descriptor.total_length); 68 return NULL; 69 } 70 71 size_t full_config_descriptor_size; 72 rc = usb_request_get_full_configuration_descriptor(&dev->ctrl_pipe, 73 config_index, 74 full_config_descriptor, config_descriptor.total_length, 75 &full_config_descriptor_size); 76 if (rc != EOK) { 77 usb_log_error("Failed getting configuration descriptor: %s.\n", 78 str_error(rc)); 79 free(full_config_descriptor); 80 return NULL; 81 } 82 83 if (full_config_descriptor_size != config_descriptor.total_length) { 84 usb_log_error("Failed getting full configuration descriptor.\n"); 85 free(full_config_descriptor); 86 return NULL; 87 } 88 89 if (size != NULL) { 90 *size = full_config_descriptor_size; 91 } 92 93 return full_config_descriptor; 94 } 95 44 96 /** Find starting indexes of all interface descriptors in a configuration. 45 97 * … … 126 178 127 179 size_t config_descriptor_size; 128 uint8_t *config_descriptor_raw = NULL; 129 rc = usb_request_get_full_configuration_descriptor_alloc( 130 &dev->ctrl_pipe, 0, 131 (void **) &config_descriptor_raw, &config_descriptor_size); 132 if (rc != EOK) { 133 usb_log_error("Failed getting full config descriptor: %s.\n", 134 str_error(rc)); 180 uint8_t *config_descriptor_raw = get_configuration_descriptor(dev, 0, 181 &config_descriptor_size); 182 if (config_descriptor_raw == NULL) { 135 183 return false; 136 184 } -
uspace/lib/usb/include/usb/request.h
r24aa62c raf430ce 106 106 int usb_request_get_full_configuration_descriptor(usb_endpoint_pipe_t *, int, 107 107 void *, size_t, size_t *); 108 int usb_request_get_full_configuration_descriptor_alloc(usb_endpoint_pipe_t *,109 int, void **, size_t *);110 108 int usb_request_set_configuration(usb_endpoint_pipe_t *, uint8_t); 111 109 -
uspace/lib/usb/src/request.c
r24aa62c raf430ce 412 412 } 413 413 414 /** Retrieve full configuration descriptor, allocate space for it.415 *416 * The function takes care that full configuration descriptor is returned417 * (i.e. the function will fail when less data then descriptor.totalLength418 * is returned).419 *420 * @param[in] pipe Control endpoint pipe (session must be already started).421 * @param[in] index Configuration index.422 * @param[out] descriptor_ptr Where to store pointer to allocated buffer.423 * @param[out] descriptor_size Where to store the size of the descriptor.424 * @return Error code.425 */426 int usb_request_get_full_configuration_descriptor_alloc(427 usb_endpoint_pipe_t *pipe, int index,428 void **descriptor_ptr, size_t *descriptor_size)429 {430 int rc;431 432 if (descriptor_ptr == NULL) {433 return EBADMEM;434 }435 436 usb_standard_configuration_descriptor_t bare_config;437 rc = usb_request_get_bare_configuration_descriptor(pipe, index,438 &bare_config);439 if (rc != EOK) {440 return rc;441 }442 443 if (bare_config.descriptor_type != USB_DESCTYPE_CONFIGURATION) {444 return ENOENT;445 }446 if (bare_config.total_length < sizeof(bare_config)) {447 return ELIMIT;448 }449 450 void *buffer = malloc(bare_config.total_length);451 if (buffer == NULL) {452 return ENOMEM;453 }454 455 size_t transferred = 0;456 rc = usb_request_get_full_configuration_descriptor(pipe, index,457 buffer, bare_config.total_length, &transferred);458 if (rc != EOK) {459 free(buffer);460 return rc;461 }462 463 if (transferred != bare_config.total_length) {464 free(buffer);465 return ELIMIT;466 }467 468 /* Everything looks okay, copy the pointers. */469 470 *descriptor_ptr = buffer;471 472 if (descriptor_size != NULL) {473 *descriptor_size = bare_config.total_length;474 }475 476 return EOK;477 }478 479 414 /** Set configuration of USB device. 480 415 * -
uspace/srv/hid/console/console.c
r24aa62c raf430ce 715 715 } 716 716 717 static int connect_keyboard_or_mouse(const char *devname, 718 async_client_conn_t handler, const char *path) 717 static int connect_keyboard(char *path) 719 718 { 720 719 int fd = open(path, O_RDONLY); … … 729 728 } 730 729 731 int rc = async_connect_to_me(phone, SERVICE_CONSOLE, 0, 0, handler); 730 int rc = async_connect_to_me(phone, SERVICE_CONSOLE, 0, 0, 731 keyboard_events); 732 732 if (rc != EOK) { 733 733 printf(NAME ": " \ … … 737 737 } 738 738 739 printf(NAME ": found %s \"%s\".\n", devname, path);739 printf(NAME ": found keyboard \"%s\".\n", path); 740 740 741 741 return phone; 742 742 } 743 743 744 static int connect_keyboard(const char *path)745 {746 return connect_keyboard_or_mouse("keyboard", keyboard_events, path);747 }748 749 static int connect_mouse(const char *path)750 {751 return connect_keyboard_or_mouse("mouse", mouse_events, path);752 }753 754 struct hid_class_info {755 char *classname;756 int (*connection_func)(const char *);757 };758 744 759 745 /** Periodically check for new keyboards in /dev/class/. … … 762 748 * @return This function should never exit. 763 749 */ 764 static int check_new_ device_fibril(void *arg)765 { 766 struct hid_class_info *dev_info =arg;750 static int check_new_keyboards(void *arg) 751 { 752 char *class_name = (char *) arg; 767 753 768 754 size_t index = 1; … … 772 758 char *path; 773 759 int rc = asprintf(&path, "/dev/class/%s\\%zu", 774 dev_info->classname, index);760 class_name, index); 775 761 if (rc < 0) { 776 762 continue; 777 763 } 778 764 rc = 0; 779 rc = dev_info->connection_func(path);765 rc = connect_keyboard(path); 780 766 if (rc > 0) { 781 767 /* We do not allow unplug. */ … … 792 778 /** Start a fibril monitoring hot-plugged keyboards. 793 779 */ 794 static void check_new_devices_in_background(int (*connection_func)(const char *), 795 const char *classname) 796 { 797 struct hid_class_info *dev_info = malloc(sizeof(struct hid_class_info)); 798 if (dev_info == NULL) { 799 printf(NAME ": " \ 800 "out of memory, will not start hot-plug-watch fibril.\n"); 801 return; 802 } 803 int rc; 804 805 rc = asprintf(&dev_info->classname, "%s", classname); 806 if (rc < 0) { 807 printf(NAME ": failed to format classname: %s.\n", 808 str_error(rc)); 809 return; 810 } 811 dev_info->connection_func = connection_func; 812 813 fid_t fid = fibril_create(check_new_device_fibril, (void *)dev_info); 780 static void check_new_keyboards_in_background() 781 { 782 fid_t fid = fibril_create(check_new_keyboards, (void *)"keyboard"); 814 783 if (!fid) { 815 printf(NAME 816 ": failed to create hot-plug-watch fibril for %s.\n", 817 classname); 784 printf(NAME ": failed to create hot-plug-watch fibril.\n"); 818 785 return; 819 786 } … … 829 796 } 830 797 831 mouse_phone = connect_mouse("/dev/hid_in/mouse"); 798 /* Connect to mouse device */ 799 mouse_phone = -1; 800 int mouse_fd = open("/dev/hid_in/mouse", O_RDONLY); 801 802 if (mouse_fd < 0) { 803 printf(NAME ": Notice - failed opening %s\n", "/dev/hid_in/mouse"); 804 goto skip_mouse; 805 } 806 807 mouse_phone = fd_phone(mouse_fd); 832 808 if (mouse_phone < 0) { 833 printf(NAME ": Failed to connect to mouse device: %s.\n", 834 str_error(mouse_phone)); 835 } 809 printf(NAME ": Failed to connect to mouse device\n"); 810 goto skip_mouse; 811 } 812 813 if (async_connect_to_me(mouse_phone, SERVICE_CONSOLE, 0, 0, mouse_events) 814 != 0) { 815 printf(NAME ": Failed to create callback from mouse device\n"); 816 mouse_phone = -1; 817 goto skip_mouse; 818 } 819 820 skip_mouse: 836 821 837 822 /* Connect to framebuffer driver */ … … 917 902 918 903 /* Start fibril for checking on hot-plugged keyboards. */ 919 check_new_devices_in_background(connect_keyboard, "keyboard"); 920 check_new_devices_in_background(connect_mouse, "mouse"); 904 check_new_keyboards_in_background(); 921 905 922 906 return true;
Note:
See TracChangeset
for help on using the changeset viewer.