Changes in / [deece2f:fb78ae72] in mainline
- Files:
-
- 5 added
- 9 deleted
- 43 edited
Legend:
- Unmodified
- Added
- Removed
-
.bzrignore
rdeece2f rfb78ae72 88 88 ./uspace/drv/usbhub/usbhub 89 89 ./uspace/drv/usbhid/usbhid 90 ./uspace/drv/usbmid/usbmid91 90 ./uspace/drv/vhc/vhc 92 91 ./uspace/srv/bd/ata_bd/ata_bd -
boot/arch/amd64/Makefile.inc
rdeece2f rfb78ae72 47 47 usbhub \ 48 48 usbhid \ 49 usbmid \50 49 vhc 51 50 -
uspace/Makefile
rdeece2f rfb78ae72 121 121 drv/usbhid \ 122 122 drv/usbhub \ 123 drv/usbmid \124 123 drv/vhc 125 124 endif … … 137 136 drv/usbhid \ 138 137 drv/usbhub \ 139 drv/usbmid \140 138 drv/vhc 141 139 endif -
uspace/app/usbinfo/info.c
rdeece2f rfb78ae72 37 37 #include <str_error.h> 38 38 #include <errno.h> 39 #include <usb/usbdrv.h> 39 40 #include <usb/pipes.h> 40 41 #include <usb/recognise.h> -
uspace/app/usbinfo/main.c
rdeece2f rfb78ae72 43 43 #include <devman.h> 44 44 #include <devmap.h> 45 #include <usb/usbdrv.h> 45 46 #include "usbinfo.h" 46 47 -
uspace/doc/doxygroups.h
rdeece2f rfb78ae72 220 220 221 221 /** 222 * @defgroup drvusbmid USB multi interface device driver223 * @ingroup usb224 * @brief USB multi interface device driver225 * @details226 * This driver serves as a mini hub (or bus) driver for devices227 * that have the class defined at interface level (those devices228 * usually have several interfaces).229 *230 * The term multi interface device driver (MID) was borrowed231 * Solaris operating system.232 */233 234 /**235 222 * @defgroup drvusbhub USB hub driver 236 223 * @ingroup usb -
uspace/drv/uhci-hcd/iface.c
rdeece2f rfb78ae72 42 42 #include "uhci.h" 43 43 44 static int get_address(device_t *dev, devman_handle_t handle, 45 usb_address_t *address) 46 { 47 assert(dev); 48 uhci_t *hc = dev_to_uhci(dev); 49 assert(hc); 50 *address = usb_address_keeping_find(&hc->address_manager, handle); 51 if (*address <= 0) 52 return *address; 53 return EOK; 54 } 44 55 /*----------------------------------------------------------------------------*/ 45 56 static int reserve_default_address(device_t *dev, usb_speed_t speed) … … 157 168 /*----------------------------------------------------------------------------*/ 158 169 usbhc_iface_t uhci_iface = { 170 .tell_address = get_address, 171 159 172 .reserve_default_address = reserve_default_address, 160 173 .release_default_address = release_default_address, -
uspace/drv/uhci-hcd/main.c
rdeece2f rfb78ae72 34 34 #include <driver.h> 35 35 #include <usb_iface.h> 36 #include <usb/ddfiface.h>37 36 #include <device/hw_res.h> 38 37 … … 49 48 50 49 static int uhci_add_device(device_t *device); 50 static int usb_iface_get_hc_handle(device_t *dev, devman_handle_t *handle); 51 /*----------------------------------------------------------------------------*/ 52 static int usb_iface_get_hc_handle(device_t *dev, devman_handle_t *handle) 53 { 54 /* This shall be called only for the UHCI itself. */ 55 assert(dev->parent == NULL); 51 56 52 static int usb_iface_get_address(device_t *dev, devman_handle_t handle, 53 usb_address_t *address) 54 { 55 assert(dev); 56 uhci_t *hc = dev_to_uhci(dev); 57 assert(hc); 58 59 usb_address_t addr = usb_address_keeping_find(&hc->address_manager, 60 handle); 61 if (addr < 0) { 62 return addr; 63 } 64 65 if (address != NULL) { 66 *address = addr; 67 } 68 57 *handle = dev->handle; 69 58 return EOK; 70 59 } 71 72 60 /*----------------------------------------------------------------------------*/ 73 61 static usb_iface_t hc_usb_iface = { 74 .get_hc_handle = usb_iface_get_hc_handle_hc_impl, 75 .get_address = usb_iface_get_address 62 .get_hc_handle = usb_iface_get_hc_handle 76 63 }; 77 64 /*----------------------------------------------------------------------------*/ -
uspace/drv/uhci-rhd/main.c
rdeece2f rfb78ae72 34 34 #include <driver.h> 35 35 #include <usb_iface.h> 36 #include <usb/ddfiface.h>37 36 38 37 #include <errno.h> … … 57 56 58 57 static usb_iface_t uhci_rh_usb_iface = { 59 .get_hc_handle = usb_iface_get_hc_handle, 60 .get_address = usb_iface_get_address_hub_impl 58 .get_hc_handle = usb_iface_get_hc_handle 61 59 }; 62 60 -
uspace/drv/uhci-rhd/root_hub.c
rdeece2f rfb78ae72 35 35 #include <stdint.h> 36 36 37 #include <usb/usbdrv.h> 37 38 #include <usb/debug.h> 38 39 -
uspace/drv/usbhid/main.c
rdeece2f rfb78ae72 36 36 */ 37 37 38 #include <usb/usbdrv.h> 38 39 #include <driver.h> 39 40 #include <ipc/driver.h> … … 264 265 for (i = 0; i < count; ++i) { 265 266 printf("%d ", key_codes[i]); 266 }267 printf("\n");268 269 for (i = 0; i < count; ++i) {270 267 // TODO: Key press / release 271 268 272 269 // TODO: NOT WORKING 273 270 unsigned int key = usbkbd_parse_scancode(key_codes[i]); 274 275 if (key == 0) {276 continue;277 }278 271 kbd_push_ev(KEY_PRESS, key); 279 272 } … … 355 348 { 356 349 .pipe = &kbd_dev->poll_pipe, 357 .description = &poll_endpoint_description, 358 .interface_no = 359 usb_device_get_assigned_interface(kbd_dev->device) 350 .description = &poll_endpoint_description 360 351 } 361 352 }; -
uspace/drv/usbhub/main.c
rdeece2f rfb78ae72 34 34 #include <errno.h> 35 35 #include <async.h> 36 37 #include <usb/usbdrv.h> 38 36 39 37 40 #include "usbhub.h" -
uspace/drv/usbhub/port_status.h
rdeece2f rfb78ae72 35 35 #include <bool.h> 36 36 #include <sys/types.h> 37 #include <usb/ request.h>37 #include <usb/devreq.h> 38 38 #include "usbhub_private.h" 39 39 -
uspace/drv/usbhub/usbhub.c
rdeece2f rfb78ae72 39 39 40 40 #include <usb_iface.h> 41 #include <usb/ ddfiface.h>41 #include <usb/usbdrv.h> 42 42 #include <usb/descriptor.h> 43 43 #include <usb/recognise.h> 44 #include <usb/ request.h>44 #include <usb/devreq.h> 45 45 #include <usb/classes/hub.h> 46 46 … … 49 49 #include "port_status.h" 50 50 #include "usb/usb.h" 51 #include "usb/pipes.h" 52 #include "usb/classes/classes.h" 51 52 static int iface_get_hc_handle(device_t *device, devman_handle_t *handle) 53 { 54 return usb_hc_find(device->handle, handle); 55 } 56 57 static usb_iface_t hub_usb_iface = { 58 .get_hc_handle = iface_get_hc_handle 59 }; 53 60 54 61 static device_ops_t hub_device_ops = { 55 .interfaces[USB_DEV_IFACE] = & usb_iface_hub_impl62 .interfaces[USB_DEV_IFACE] = &hub_usb_iface 56 63 }; 57 58 /** Hub status-change endpoint description */59 static usb_endpoint_description_t status_change_endpoint_description = {60 .transfer_type = USB_TRANSFER_INTERRUPT,61 .direction = USB_DIRECTION_IN,62 .interface_class = USB_CLASS_HUB,63 .flags = 064 };65 66 64 67 65 //********************************************* … … 71 69 //********************************************* 72 70 73 /** 74 * Initialize connnections to host controller, device, and device 75 * control endpoint 76 * @param hub 77 * @param device 78 * @return 79 */ 80 static int usb_hub_init_communication(usb_hub_info_t * hub){ 81 int opResult; 82 opResult = usb_device_connection_initialize_from_device( 83 &hub->device_connection, 84 hub->device); 85 if(opResult != EOK){ 86 dprintf(USB_LOG_LEVEL_ERROR, 87 "could not initialize connection to hc, errno %d",opResult); 88 return opResult; 89 } 90 opResult = usb_hc_connection_initialize_from_device(&hub->connection, 91 hub->device); 92 if(opResult != EOK){ 93 dprintf(USB_LOG_LEVEL_ERROR, 94 "could not initialize connection to device, errno %d",opResult); 95 return opResult; 96 } 97 opResult = usb_endpoint_pipe_initialize_default_control(&hub->endpoints.control, 98 &hub->device_connection); 99 if(opResult != EOK){ 100 dprintf(USB_LOG_LEVEL_ERROR, 101 "could not initialize connection to device endpoint, errno %d",opResult); 102 } 103 return opResult; 104 } 105 106 /** 107 * When entering this function, hub->endpoints.control should be active. 108 * @param hub 109 * @return 110 */ 111 static int usb_hub_process_configuration_descriptors( 112 usb_hub_info_t * hub){ 113 if(hub==NULL) { 114 return EINVAL; 115 } 116 int opResult; 117 118 //device descriptor 119 usb_standard_device_descriptor_t std_descriptor; 120 opResult = usb_request_get_device_descriptor(&hub->endpoints.control, 121 &std_descriptor); 122 if(opResult!=EOK){ 123 dprintf(USB_LOG_LEVEL_ERROR, "could not get device descriptor, %d",opResult); 124 return opResult; 125 } 126 dprintf(USB_LOG_LEVEL_INFO, "hub has %d configurations", 127 std_descriptor.configuration_count); 128 if(std_descriptor.configuration_count<1){ 129 dprintf(USB_LOG_LEVEL_ERROR, "THERE ARE NO CONFIGURATIONS AVAILABLE"); 130 //shouldn`t I return? 131 } 132 133 //configuration descriptor 134 /// \TODO check other configurations 135 usb_standard_configuration_descriptor_t config_descriptor; 136 opResult = usb_request_get_bare_configuration_descriptor( 137 &hub->endpoints.control, 0, 138 &config_descriptor); 139 if(opResult!=EOK){ 140 dprintf(USB_LOG_LEVEL_ERROR, "could not get configuration descriptor, %d",opResult); 141 return opResult; 142 } 143 //set configuration 144 opResult = usb_request_set_configuration(&hub->endpoints.control, 145 config_descriptor.configuration_number); 146 147 if (opResult != EOK) { 148 dprintf(USB_LOG_LEVEL_ERROR, 149 "something went wrong when setting hub`s configuration, %d", 150 opResult); 151 return opResult; 152 } 153 dprintf(USB_LOG_LEVEL_DEBUG, "\tused configuration %d", 154 config_descriptor.configuration_number); 155 156 //full configuration descriptor 157 size_t transferred = 0; 158 uint8_t * descriptors = (uint8_t *)malloc(config_descriptor.total_length); 159 if (descriptors == NULL) { 160 dprintf(USB_LOG_LEVEL_ERROR, "insufficient memory"); 161 return ENOMEM; 162 } 163 opResult = usb_request_get_full_configuration_descriptor(&hub->endpoints.control, 164 0, descriptors, 165 config_descriptor.total_length, &transferred); 166 if(opResult!=EOK){ 167 free(descriptors); 168 dprintf(USB_LOG_LEVEL_ERROR, 169 "could not get full configuration descriptor, %d",opResult); 170 return opResult; 171 } 172 if (transferred != config_descriptor.total_length) { 173 dprintf(USB_LOG_LEVEL_ERROR, 174 "received incorrect full configuration descriptor"); 175 return ELIMIT; 176 } 177 178 /** 179 * Initialize the interrupt in endpoint. 180 * \TODO this code should be checked... 181 */ 182 usb_endpoint_mapping_t endpoint_mapping[1] = { 183 { 184 .pipe = &hub->endpoints.status_change, 185 .description = &status_change_endpoint_description, 186 .interface_no = 187 usb_device_get_assigned_interface(hub->device) 188 } 189 }; 190 opResult = usb_endpoint_pipe_initialize_from_configuration( 191 endpoint_mapping, 1, 192 descriptors, config_descriptor.total_length, 193 &hub->device_connection); 194 if (opResult != EOK) { 195 dprintf(USB_LOG_LEVEL_ERROR, 196 "Failed to initialize status change pipe: %s", 197 str_error(opResult)); 198 return opResult; 199 } 200 if (!endpoint_mapping[0].present) { 201 dprintf(USB_LOG_LEVEL_ERROR,"Not accepting device, " \ 202 "cannot understand what is happenning"); 203 return EREFUSED; 204 } 205 206 free(descriptors); 207 return EOK; 208 209 210 // Initialize the interrupt(=status change) endpoint. 211 /*usb_endpoint_pipe_initialize( 212 &result->endpoints->status_change, 213 &result->device_connection, );USB_TRANSFER_INTERRUPT 214 USB_DIRECTION_IN*/ 215 216 } 217 218 219 /** 220 * Create hub representation from device information. 221 * @param device 222 * @return pointer to created structure or NULL in case of error 223 */ 224 usb_hub_info_t * usb_create_hub_info(device_t * device) { 71 usb_hub_info_t * usb_create_hub_info(device_t * device, int hc) { 225 72 usb_hub_info_t* result = usb_new(usb_hub_info_t); 226 result->device = device;227 int opResult;228 opResult = usb_hub_init_communication(result);229 if(opResult != EOK){230 free(result);231 return NULL;232 }233 234 73 //result->device = device; 235 74 result->port_count = -1; 75 /// \TODO is this correct? is the device stored? 236 76 result->device = device; 237 77 238 //result->usb_device = usb_new(usb_hcd_attached_device_info_t); 239 size_t received_size; 78 79 dprintf(USB_LOG_LEVEL_DEBUG, "phone to hc = %d", hc); 80 if (hc < 0) { 81 return result; 82 } 83 //get some hub info 84 usb_address_t addr = usb_drv_get_my_address(hc, device); 85 dprintf(USB_LOG_LEVEL_DEBUG, "address of newly created hub = %d", addr); 86 /*if(addr<0){ 87 //return result; 88 89 }*/ 90 91 result->address = addr; 240 92 241 93 // get hub descriptor 94 242 95 dprintf(USB_LOG_LEVEL_DEBUG, "creating serialized descripton"); 243 96 void * serialized_descriptor = malloc(USB_HUB_MAX_DESCRIPTOR_SIZE); 244 97 usb_hub_descriptor_t * descriptor; 98 size_t received_size; 99 int opResult; 245 100 dprintf(USB_LOG_LEVEL_DEBUG, "starting control transaction"); 246 usb_endpoint_pipe_start_session(&result->endpoints.control);247 opResult = usb_ request_get_descriptor(&result->endpoints.control,101 102 opResult = usb_drv_req_get_descriptor(hc, addr, 248 103 USB_REQUEST_TYPE_CLASS, 249 104 USB_DESCTYPE_HUB, 0, 0, serialized_descriptor, 250 105 USB_HUB_MAX_DESCRIPTOR_SIZE, &received_size); 251 usb_endpoint_pipe_end_session(&result->endpoints.control);252 106 253 107 if (opResult != EOK) { … … 263 117 return result; 264 118 } 265 266 267 119 dprintf(USB_LOG_LEVEL_INFO, "setting port count to %d",descriptor->ports_count); 268 120 result->port_count = descriptor->ports_count; 269 result->attached_devs = (usb_h c_attached_device_t*)270 malloc((result->port_count+1) * sizeof(usb_h c_attached_device_t));121 result->attached_devs = (usb_hub_attached_device_t*) 122 malloc((result->port_count+1) * sizeof(usb_hub_attached_device_t)); 271 123 int i; 272 124 for(i=0;i<result->port_count+1;++i){ 273 result->attached_devs[i]. handle=0;125 result->attached_devs[i].devman_handle=0; 274 126 result->attached_devs[i].address=0; 275 127 } … … 286 138 } 287 139 288 /**289 * Create hub representation and add it into hub list290 * @param dev291 * @return292 */293 140 int usb_add_hub_device(device_t *dev) { 294 141 dprintf(USB_LOG_LEVEL_INFO, "add_hub_device(handle=%d)", (int) dev->handle); 295 142 143 /* 144 * We are some (probably deeply nested) hub. 145 * Thus, assign our own operations and explore already 146 * connected devices. 147 */ 296 148 dev->ops = &hub_device_ops; 297 149 298 usb_hub_info_t * hub_info = usb_create_hub_info(dev); 299 300 int opResult; 301 302 //perform final configurations 303 usb_endpoint_pipe_start_session(&hub_info->endpoints.control); 304 // process descriptors 305 opResult = usb_hub_process_configuration_descriptors(hub_info); 306 if(opResult != EOK){ 307 dprintf(USB_LOG_LEVEL_ERROR,"could not get condiguration descriptors, %d", 308 opResult); 150 //create the hub structure 151 //get hc connection 152 int hc = usb_drv_hc_connect_auto(dev, 0); 153 if (hc < 0) { 154 return hc; 155 } 156 157 usb_hub_info_t * hub_info = usb_create_hub_info(dev, hc); 158 int port; 159 int opResult; 160 usb_target_t target; 161 target.address = hub_info->address; 162 target.endpoint = 0; 163 164 //get configuration descriptor 165 // this is not fully correct - there are more configurations 166 // and all should be checked 167 usb_standard_device_descriptor_t std_descriptor; 168 opResult = usb_drv_req_get_device_descriptor(hc, target.address, 169 &std_descriptor); 170 if(opResult!=EOK){ 171 dprintf(USB_LOG_LEVEL_ERROR, "could not get device descriptor, %d",opResult); 309 172 return opResult; 310 173 } 311 //power ports 174 dprintf(USB_LOG_LEVEL_INFO, "hub has %d configurations",std_descriptor.configuration_count); 175 if(std_descriptor.configuration_count<1){ 176 dprintf(USB_LOG_LEVEL_ERROR, "THERE ARE NO CONFIGURATIONS AVAILABLE"); 177 //shouldn`t I return? 178 } 179 /// \TODO check other configurations 180 usb_standard_configuration_descriptor_t config_descriptor; 181 opResult = usb_drv_req_get_bare_configuration_descriptor(hc, 182 target.address, 0, 183 &config_descriptor); 184 if(opResult!=EOK){ 185 dprintf(USB_LOG_LEVEL_ERROR, "could not get configuration descriptor, %d",opResult); 186 return opResult; 187 } 188 //set configuration 189 opResult = usb_drv_req_set_configuration(hc, target.address, 190 config_descriptor.configuration_number); 191 192 if (opResult != EOK) { 193 dprintf(USB_LOG_LEVEL_ERROR, "something went wrong when setting hub`s configuration, %d", opResult); 194 } 195 312 196 usb_device_request_setup_packet_t request; 313 int port;314 197 for (port = 1; port < hub_info->port_count+1; ++port) { 315 198 usb_hub_set_power_port_request(&request, port); 316 opResult = usb_endpoint_pipe_control_write(&hub_info->endpoints.control, 317 &request,sizeof(usb_device_request_setup_packet_t), NULL, 0); 199 opResult = usb_drv_sync_control_write(hc, target, &request, NULL, 0); 318 200 dprintf(USB_LOG_LEVEL_INFO, "powering port %d",port); 319 201 if (opResult != EOK) { … … 322 204 } 323 205 //ports powered, hub seems to be enabled 324 usb_endpoint_pipe_end_session(&hub_info->endpoints.control); 206 207 async_hangup(hc); 325 208 326 209 //add the hub to list … … 332 215 //(void)hub_info; 333 216 usb_hub_check_hub_changes(); 217 334 218 219 335 220 dprintf(USB_LOG_LEVEL_INFO, "hub dev added"); 336 //address is lost...337 221 dprintf(USB_LOG_LEVEL_DEBUG, "\taddress %d, has %d ports ", 338 //hub_info->endpoints.control.,222 hub_info->address, 339 223 hub_info->port_count); 224 dprintf(USB_LOG_LEVEL_DEBUG, "\tused configuration %d",config_descriptor.configuration_number); 340 225 341 226 return EOK; … … 351 236 352 237 /** 238 * Convenience function for releasing default address and writing debug info 239 * (these few lines are used too often to be written again and again). 240 * @param hc 241 * @return 242 */ 243 inline static int usb_hub_release_default_address(int hc){ 244 int opResult; 245 dprintf(USB_LOG_LEVEL_INFO, "releasing default address"); 246 opResult = usb_drv_release_default_address(hc); 247 if (opResult != EOK) { 248 dprintf(USB_LOG_LEVEL_WARNING, "failed to release default address"); 249 } 250 return opResult; 251 } 252 253 /** 353 254 * Reset the port with new device and reserve the default address. 354 255 * @param hc … … 356 257 * @param target 357 258 */ 358 static void usb_hub_init_add_device( usb_hub_info_t * hub, uint16_t port) {259 static void usb_hub_init_add_device(int hc, uint16_t port, usb_target_t target) { 359 260 usb_device_request_setup_packet_t request; 360 261 int opResult; 361 262 dprintf(USB_LOG_LEVEL_INFO, "some connection changed"); 362 assert(hub->endpoints.control.hc_phone);363 263 //get default address 364 //opResult = usb_drv_reserve_default_address(hc); 365 opResult = usb_hc_reserve_default_address(&hub->connection, USB_SPEED_LOW); 366 264 opResult = usb_drv_reserve_default_address(hc); 367 265 if (opResult != EOK) { 368 266 dprintf(USB_LOG_LEVEL_WARNING, "cannot assign default address, it is probably used"); … … 371 269 //reset port 372 270 usb_hub_set_reset_port_request(&request, port); 373 opResult = usb_ endpoint_pipe_control_write(374 &hub->endpoints.control,375 &request, sizeof(usb_device_request_setup_packet_t),271 opResult = usb_drv_sync_control_write( 272 hc, target, 273 &request, 376 274 NULL, 0 377 275 ); 378 276 if (opResult != EOK) { 379 277 dprintf(USB_LOG_LEVEL_ERROR, "something went wrong when reseting a port"); 380 //usb_hub_release_default_address(hc); 381 usb_hc_release_default_address(&hub->connection); 278 usb_hub_release_default_address(hc); 382 279 } 383 280 } … … 390 287 */ 391 288 static void usb_hub_finalize_add_device( usb_hub_info_t * hub, 392 uint16_t port) {289 int hc, uint16_t port, usb_target_t target) { 393 290 394 291 int opResult; 395 292 dprintf(USB_LOG_LEVEL_INFO, "finalizing add device"); 396 opResult = usb_hub_clear_port_feature( &hub->endpoints.control,293 opResult = usb_hub_clear_port_feature(hc, target.address, 397 294 port, USB_HUB_FEATURE_C_PORT_RESET); 398 399 295 if (opResult != EOK) { 400 296 dprintf(USB_LOG_LEVEL_ERROR, "failed to clear port reset feature"); 401 usb_hc_release_default_address(&hub->connection); 402 return; 403 } 404 //create connection to device 405 usb_endpoint_pipe_t new_device_pipe; 406 usb_device_connection_t new_device_connection; 407 usb_device_connection_initialize_on_default_address( 408 &new_device_connection, 409 &hub->connection 410 ); 411 usb_endpoint_pipe_initialize_default_control( 412 &new_device_pipe, 413 &new_device_connection); 414 /// \TODO get highspeed info 415 416 417 418 419 420 /* Request address from host controller. */ 421 usb_address_t new_device_address = usb_hc_request_address( 422 &hub->connection, 423 USB_SPEED_LOW/// \TODO fullspeed?? 424 ); 297 usb_hub_release_default_address(hc); 298 return; 299 } 300 301 /* Request address at from host controller. */ 302 usb_address_t new_device_address = usb_drv_request_address(hc); 425 303 if (new_device_address < 0) { 426 304 dprintf(USB_LOG_LEVEL_ERROR, "failed to get free USB address"); 427 305 opResult = new_device_address; 428 usb_h c_release_default_address(&hub->connection);306 usb_hub_release_default_address(hc); 429 307 return; 430 308 } 431 309 dprintf(USB_LOG_LEVEL_INFO, "setting new address %d",new_device_address); 432 //opResult = usb_drv_req_set_address(hc, USB_ADDRESS_DEFAULT, 433 // new_device_address); 434 opResult = usb_request_set_address(&new_device_pipe,new_device_address); 310 opResult = usb_drv_req_set_address(hc, USB_ADDRESS_DEFAULT, 311 new_device_address); 435 312 436 313 if (opResult != EOK) { 437 314 dprintf(USB_LOG_LEVEL_ERROR, "could not set address for new device"); 438 usb_hc_release_default_address(&hub->connection); 439 return; 440 } 441 442 443 //opResult = usb_hub_release_default_address(hc); 444 opResult = usb_hc_release_default_address(&hub->connection); 315 usb_hub_release_default_address(hc); 316 return; 317 } 318 319 320 opResult = usb_hub_release_default_address(hc); 445 321 if(opResult!=EOK){ 446 322 return; 447 323 } 448 324 325 devman_handle_t hc_handle; 326 opResult = usb_drv_find_hc(hub->device, &hc_handle); 327 if (opResult != EOK) { 328 usb_log_error("Failed to get handle of host controller: %s.\n", 329 str_error(opResult)); 330 return; 331 } 332 449 333 devman_handle_t child_handle; 450 //?? 451 opResult = usb_device_register_child_in_devman(new_device_address, 452 hub->connection.hc_handle, hub->device, &child_handle); 453 334 opResult = usb_device_register_child_in_devman(new_device_address, 335 hc_handle, hub->device, &child_handle); 454 336 if (opResult != EOK) { 455 337 dprintf(USB_LOG_LEVEL_ERROR, "could not start driver for new device"); 456 338 return; 457 339 } 458 hub->attached_devs[port]. handle = child_handle;340 hub->attached_devs[port].devman_handle = child_handle; 459 341 hub->attached_devs[port].address = new_device_address; 460 342 461 //opResult = usb_drv_bind_address(hc, new_device_address, child_handle); 462 opResult = usb_hc_register_device( 463 &hub->connection, 464 &hub->attached_devs[port]); 343 opResult = usb_drv_bind_address(hc, new_device_address, child_handle); 465 344 if (opResult != EOK) { 466 345 dprintf(USB_LOG_LEVEL_ERROR, "could not assign address of device in hcd"); … … 479 358 */ 480 359 static void usb_hub_removed_device( 481 usb_hub_info_t * hub, uint16_t port) {360 usb_hub_info_t * hub, int hc, uint16_t port, usb_target_t target) { 482 361 //usb_device_request_setup_packet_t request; 483 362 int opResult; … … 486 365 * devide manager 487 366 */ 488 367 368 hub->attached_devs[port].devman_handle=0; 489 369 //close address 490 370 if(hub->attached_devs[port].address!=0){ 491 //opResult = usb_drv_release_address(hc,hub->attached_devs[port].address); 492 opResult = usb_hc_unregister_device( 493 &hub->connection, hub->attached_devs[port].address); 371 opResult = usb_drv_release_address(hc,hub->attached_devs[port].address); 494 372 if(opResult != EOK) { 495 373 dprintf(USB_LOG_LEVEL_WARNING, "could not release address of " \ … … 497 375 } 498 376 hub->attached_devs[port].address = 0; 499 hub->attached_devs[port].handle = 0;500 377 }else{ 501 378 dprintf(USB_LOG_LEVEL_WARNING, "this is strange, disconnected device had no address"); 502 379 //device was disconnected before it`s port was reset - return default address 503 //usb_drv_release_default_address(hc); 504 usb_hc_release_default_address(&hub->connection); 380 usb_drv_release_default_address(hc); 505 381 } 506 382 } … … 512 388 * @param target 513 389 */ 514 static void usb_hub_process_interrupt(usb_hub_info_t * hub, 515 uint16_t port ) {390 static void usb_hub_process_interrupt(usb_hub_info_t * hub, int hc, 391 uint16_t port, usb_address_t address) { 516 392 dprintf(USB_LOG_LEVEL_DEBUG, "interrupt at port %d", port); 517 393 //determine type of change 518 usb_endpoint_pipe_t *pipe = &hub->endpoints.control;519 int opResult = usb_endpoint_pipe_start_session(pipe);520 521 if(opResult != EOK){522 dprintf(USB_LOG_LEVEL_ERROR, "cannot open pipe %d", opResult);523 }524 525 /*526 394 usb_target_t target; 527 395 target.address=address; 528 396 target.endpoint=0; 529 */530 531 397 usb_port_status_t status; 532 398 size_t rcvd_size; 533 399 usb_device_request_setup_packet_t request; 534 //int opResult;400 int opResult; 535 401 usb_hub_set_port_status_request(&request, port); 536 402 //endpoint 0 537 403 538 opResult = usb_ endpoint_pipe_control_read(539 pipe,540 &request, sizeof(usb_device_request_setup_packet_t),404 opResult = usb_drv_sync_control_read( 405 hc, target, 406 &request, 541 407 &status, 4, &rcvd_size 542 408 ); … … 551 417 //something connected/disconnected 552 418 if (usb_port_connect_change(&status)) { 553 opResult = usb_hub_clear_port_feature( pipe,419 opResult = usb_hub_clear_port_feature(hc, target.address, 554 420 port, USB_HUB_FEATURE_C_PORT_CONNECTION); 555 421 // TODO: check opResult 556 422 if (usb_port_dev_connected(&status)) { 557 423 dprintf(USB_LOG_LEVEL_INFO, "some connection changed"); 558 usb_hub_init_add_device(h ub, port);424 usb_hub_init_add_device(hc, port, target); 559 425 } else { 560 usb_hub_removed_device(hub, port);426 usb_hub_removed_device(hub, hc, port, target); 561 427 } 562 428 } … … 565 431 dprintf(USB_LOG_LEVEL_INFO, "port reset complete"); 566 432 if (usb_port_enabled(&status)) { 567 usb_hub_finalize_add_device(hub, port);433 usb_hub_finalize_add_device(hub, hc, port, target); 568 434 } else { 569 435 dprintf(USB_LOG_LEVEL_WARNING, "ERROR: port reset, but port still not enabled"); … … 581 447 /// \TODO handle other changes 582 448 /// \TODO debug log for various situations 583 usb_endpoint_pipe_end_session(pipe);584 585 449 586 450 } … … 600 464 fibril_mutex_unlock(&usb_hub_list_lock); 601 465 usb_hub_info_t * hub_info = ((usb_hub_info_t*)lst_item->data); 602 int opResult;603 604 opResult = usb_endpoint_pipe_start_session(&hub_info->endpoints.status_change);605 if(opResult != EOK){606 continue;607 }608 466 /* 609 467 * Check status change pipe of this hub. 610 468 */ 611 /* 469 612 470 usb_target_t target; 613 471 target.address = hub_info->address; … … 615 473 dprintf(USB_LOG_LEVEL_INFO, "checking changes for hub at addr %d", 616 474 target.address); 617 */ 475 618 476 size_t port_count = hub_info->port_count; 619 477 620 478 /* 621 479 * Connect to respective HC. 622 * 480 */ 623 481 int hc = usb_drv_hc_connect_auto(hub_info->device, 0); 624 482 if (hc < 0) { 625 483 continue; 626 } */484 } 627 485 628 486 /// FIXME: count properly … … 631 489 void *change_bitmap = malloc(byte_length); 632 490 size_t actual_size; 633 //usb_handle_t handle;491 usb_handle_t handle; 634 492 635 493 /* 636 494 * Send the request. 637 495 */ 638 opResult = usb_endpoint_pipe_read( 639 &hub_info->endpoints.status_change, 640 change_bitmap, byte_length, &actual_size 641 ); 642 643 //usb_drv_async_wait_for(handle); 496 int opResult = usb_drv_async_interrupt_in(hc, target, 497 change_bitmap, byte_length, &actual_size, 498 &handle); 499 500 usb_drv_async_wait_for(handle); 644 501 645 502 if (opResult != EOK) { … … 654 511 if (interrupt) { 655 512 usb_hub_process_interrupt( 656 hub_info, port);513 hub_info, hc, port, hub_info->address); 657 514 } 658 515 } 659 usb_endpoint_pipe_end_session(&hub_info->endpoints.status_change);660 516 free(change_bitmap); 661 662 663 //async_hangup(hc); 517 518 async_hangup(hc); 664 519 fibril_mutex_lock(&usb_hub_list_lock); 665 520 } -
uspace/drv/usbhub/usbhub.h
rdeece2f rfb78ae72 42 42 #define NAME "usbhub" 43 43 44 #include <usb/hub.h> 45 46 #include <usb/pipes.h> 47 48 /* Hub endpoints. */ 49 typedef struct { 50 usb_endpoint_pipe_t control; 51 usb_endpoint_pipe_t status_change; 52 } usb_hub_endpoints_t; 53 54 44 /** basic information about device attached to hub */ 45 typedef struct{ 46 usb_address_t address; 47 devman_handle_t devman_handle; 48 }usb_hub_attached_device_t; 55 49 56 50 /** Information about attached hub. */ … … 58 52 /** Number of ports. */ 59 53 int port_count; 60 /** attached device handles , for each port one*/61 usb_h c_attached_device_t * attached_devs;62 /** General usb device info. */63 //usb_hcd_attached_device_info_t * usb_device;54 /** attached device handles */ 55 usb_hub_attached_device_t * attached_devs; 56 /** USB address of the hub. */ 57 usb_address_t address; 64 58 /** General device info*/ 65 59 device_t * device; 66 /** connection to hcd */67 //usb_device_connection_t connection;68 usb_hc_connection_t connection;69 /** */70 usb_device_connection_t device_connection;71 /** hub endpoints */72 usb_hub_endpoints_t endpoints;73 60 } usb_hub_info_t; 74 61 -
uspace/drv/usbhub/usbhub_private.h
rdeece2f rfb78ae72 45 45 #include <fibril_synch.h> 46 46 47 #include <usb/usb.h> 48 #include <usb/usbdrv.h> 47 49 #include <usb/classes/hub.h> 48 #include <usb/ usb.h>50 #include <usb/devreq.h> 49 51 #include <usb/debug.h> 50 #include <usb/request.h>51 52 52 53 //************ … … 76 77 * @return 77 78 */ 78 usb_hub_info_t * usb_create_hub_info(device_t * device );79 usb_hub_info_t * usb_create_hub_info(device_t * device, int hc); 79 80 80 81 /** List of hubs maanged by this driver */ … … 97 98 * @return error code 98 99 */ 99 /*100 100 int usb_drv_sync_control_read( 101 usb_endpoint_pipe_t *pipe,101 int phone, usb_target_t target, 102 102 usb_device_request_setup_packet_t * request, 103 103 void * rcvd_buffer, size_t rcvd_size, size_t * actual_size 104 ); */104 ); 105 105 106 106 /** … … 115 115 * @return error code 116 116 */ 117 /*int usb_drv_sync_control_write(118 usb_endpoint_pipe_t *pipe,117 int usb_drv_sync_control_write( 118 int phone, usb_target_t target, 119 119 usb_device_request_setup_packet_t * request, 120 120 void * sent_buffer, size_t sent_size 121 ); */121 ); 122 122 123 123 /** … … 147 147 * @return Operation result 148 148 */ 149 static inline int usb_hub_clear_port_feature( usb_endpoint_pipe_t *pipe,149 static inline int usb_hub_clear_port_feature(int hc, usb_address_t address, 150 150 int port_index, 151 151 usb_hub_class_feature_t feature) { 152 152 usb_target_t target = { 153 .address = address, 154 .endpoint = 0 155 }; 153 156 usb_device_request_setup_packet_t clear_request = { 154 157 .request_type = USB_HUB_REQ_TYPE_CLEAR_PORT_FEATURE, … … 158 161 }; 159 162 clear_request.value = feature; 160 return usb_ endpoint_pipe_control_write(pipe, &clear_request,163 return usb_drv_psync_control_write(hc, target, &clear_request, 161 164 sizeof(clear_request), NULL, 0); 162 165 } -
uspace/drv/usbhub/utils.c
rdeece2f rfb78ae72 38 38 39 39 #include <usbhc_iface.h> 40 #include <usb/usbdrv.h> 40 41 #include <usb/descriptor.h> 42 #include <usb/devreq.h> 41 43 #include <usb/classes/hub.h> 42 44 … … 112 114 113 115 //control transactions 114 /* 116 115 117 int usb_drv_sync_control_read( 116 118 int phone, usb_target_t target, … … 197 199 } 198 200 199 */ 201 200 202 201 203 -
uspace/drv/vhc/conn.h
rdeece2f rfb78ae72 38 38 #include <usb/usb.h> 39 39 #include <usbhc_iface.h> 40 #include <usb_iface.h>41 40 #include "vhcd.h" 42 41 #include "devices.h" … … 44 43 void connection_handler_host(sysarg_t); 45 44 46 extern usbhc_iface_t vhc_iface; 47 extern usb_iface_t vhc_usb_iface; 45 usbhc_iface_t vhc_iface; 48 46 49 47 void address_init(void); -
uspace/drv/vhc/connhost.c
rdeece2f rfb78ae72 37 37 #include <usb/usb.h> 38 38 #include <usb/addrkeep.h> 39 #include <usb/ddfiface.h>40 39 41 40 #include "vhcd.h" … … 314 313 static usb_address_keeping_t addresses; 315 314 315 316 static int reserve_default_address(device_t *dev, usb_speed_t ignored) 317 { 318 usb_address_keeping_reserve_default(&addresses); 319 return EOK; 320 } 321 322 static int release_default_address(device_t *dev) 323 { 324 usb_address_keeping_release_default(&addresses); 325 return EOK; 326 } 327 328 static int request_address(device_t *dev, usb_speed_t ignored, 329 usb_address_t *address) 330 { 331 usb_address_t addr = usb_address_keeping_request(&addresses); 332 if (addr < 0) { 333 return (int)addr; 334 } 335 336 *address = addr; 337 return EOK; 338 } 339 340 static int release_address(device_t *dev, usb_address_t address) 341 { 342 return usb_address_keeping_release(&addresses, address); 343 } 344 345 static int bind_address(device_t *dev, usb_address_t address, 346 devman_handle_t handle) 347 { 348 usb_address_keeping_devman_bind(&addresses, address, handle); 349 return EOK; 350 } 351 316 352 static int tell_address(device_t *dev, devman_handle_t handle, 317 353 usb_address_t *address) … … 326 362 } 327 363 328 static int reserve_default_address(device_t *dev, usb_speed_t ignored)329 {330 usb_address_keeping_reserve_default(&addresses);331 return EOK;332 }333 334 static int release_default_address(device_t *dev)335 {336 usb_address_keeping_release_default(&addresses);337 return EOK;338 }339 340 static int request_address(device_t *dev, usb_speed_t ignored,341 usb_address_t *address)342 {343 usb_address_t addr = usb_address_keeping_request(&addresses);344 if (addr < 0) {345 return (int)addr;346 }347 348 *address = addr;349 return EOK;350 }351 352 static int release_address(device_t *dev, usb_address_t address)353 {354 return usb_address_keeping_release(&addresses, address);355 }356 357 static int bind_address(device_t *dev, usb_address_t address,358 devman_handle_t handle)359 {360 usb_address_keeping_devman_bind(&addresses, address, handle);361 return EOK;362 }363 364 364 void address_init(void) 365 365 { … … 368 368 369 369 usbhc_iface_t vhc_iface = { 370 .tell_address = tell_address, 371 370 372 .reserve_default_address = reserve_default_address, 371 373 .release_default_address = release_default_address, … … 381 383 }; 382 384 383 usb_iface_t vhc_usb_iface = {384 .get_hc_handle = usb_iface_get_hc_handle_hc_impl,385 .get_address = tell_address386 };387 388 389 385 /** 390 386 * @} -
uspace/drv/vhc/hcd.c
rdeece2f rfb78ae72 45 45 46 46 #include <usb/usb.h> 47 #include <usb/ddfiface.h>48 47 #include <usb_iface.h> 49 48 #include "vhcd.h" … … 53 52 #include "conn.h" 54 53 54 static int usb_iface_get_hc_handle(device_t *dev, devman_handle_t *handle) 55 { 56 /* This shall be called only for VHC device. */ 57 assert(dev->parent == NULL); 58 59 *handle = dev->handle; 60 return EOK; 61 } 62 63 static usb_iface_t hc_usb_iface = { 64 .get_hc_handle = usb_iface_get_hc_handle 65 }; 66 55 67 static device_ops_t vhc_ops = { 56 68 .interfaces[USBHC_DEV_IFACE] = &vhc_iface, 57 .interfaces[USB_DEV_IFACE] = & vhc_usb_iface,69 .interfaces[USB_DEV_IFACE] = &hc_usb_iface, 58 70 .close = on_client_close, 59 71 .default_handler = default_connection_handler -
uspace/drv/vhc/hub.c
rdeece2f rfb78ae72 40 40 #include <stdlib.h> 41 41 #include <driver.h> 42 #include <usb/ hub.h>42 #include <usb/usbdrv.h> 43 43 #include <usb/recognise.h> 44 44 … … 71 71 } 72 72 73 static int pretend_port_rest(int unused, void *unused2)74 {75 return EOK;76 }77 78 73 /** Register root hub in devman. 79 74 * … … 85 80 device_t *hc_dev = (device_t *) arg; 86 81 87 /* 88 * Wait until parent device is properly initialized. 89 */ 90 int phone; 82 int hc; 91 83 do { 92 phone = devman_device_connect(hc_dev->handle, 0);93 } while (phone < 0);94 async_hangup(phone);84 hc = usb_drv_hc_connect(hc_dev, hc_dev->handle, 85 IPC_FLAG_BLOCKING); 86 } while (hc < 0); 95 87 96 usb_hc_connection_t hc_conn; 97 usb_hc_connection_initialize(&hc_conn, hc_dev->handle); 88 usb_drv_reserve_default_address(hc); 98 89 99 usb_hc_connection_open(&hc_conn); 90 usb_address_t hub_address = usb_drv_request_address(hc); 91 usb_drv_req_set_address(hc, USB_ADDRESS_DEFAULT, hub_address); 100 92 101 int rc = usb_hc_new_device_wrapper(hc_dev, &hc_conn, USB_SPEED_FULL, 102 pretend_port_rest, 0, NULL, 103 NULL, NULL); 104 if (rc != EOK) { 105 usb_log_fatal("Failed to create root hub: %s.\n", 106 str_error(rc)); 107 } 93 usb_drv_release_default_address(hc); 108 94 109 usb_hc_connection_close(&hc_conn); 95 devman_handle_t hub_handle; 96 usb_device_register_child_in_devman(hub_address, hc_dev->handle, 97 hc_dev, &hub_handle); 98 //usb_drv_register_child_in_devman(hc, hc_dev, hub_address, &hub_handle); 99 usb_drv_bind_address(hc, hub_address, hub_handle); 110 100 111 return 0;101 return EOK; 112 102 } 113 103 -
uspace/drv/vhc/hub/hub.c
rdeece2f rfb78ae72 40 40 #include <stdlib.h> 41 41 #include <driver.h> 42 #include <usb/usbdrv.h> 42 43 43 44 #include "hub.h" -
uspace/drv/vhc/hub/virthub.c
rdeece2f rfb78ae72 41 41 #include <stdlib.h> 42 42 #include <driver.h> 43 #include <usb/usbdrv.h> 43 44 44 45 #include "virthub.h" -
uspace/lib/drv/generic/remote_usb.c
rdeece2f rfb78ae72 40 40 41 41 42 static void remote_usb_get_address(device_t *, void *, ipc_callid_t, ipc_call_t *);43 static void remote_usb_get_interface(device_t *, void *, ipc_callid_t, ipc_call_t *);44 42 static void remote_usb_get_hc_handle(device_t *, void *, ipc_callid_t, ipc_call_t *); 45 43 //static void remote_usb(device_t *, void *, ipc_callid_t, ipc_call_t *); … … 47 45 /** Remote USB interface operations. */ 48 46 static remote_iface_func_ptr_t remote_usb_iface_ops [] = { 49 remote_usb_get_address,50 remote_usb_get_interface,51 47 remote_usb_get_hc_handle 52 48 }; … … 60 56 }; 61 57 62 63 void remote_usb_get_address(device_t *device, void *iface,64 ipc_callid_t callid, ipc_call_t *call)65 {66 usb_iface_t *usb_iface = (usb_iface_t *) iface;67 68 if (usb_iface->get_address == NULL) {69 async_answer_0(callid, ENOTSUP);70 return;71 }72 73 devman_handle_t handle = DEV_IPC_GET_ARG1(*call);74 75 usb_address_t address;76 int rc = usb_iface->get_address(device, handle, &address);77 if (rc != EOK) {78 async_answer_0(callid, rc);79 } else {80 async_answer_1(callid, EOK, address);81 }82 }83 84 void remote_usb_get_interface(device_t *device, void *iface,85 ipc_callid_t callid, ipc_call_t *call)86 {87 usb_iface_t *usb_iface = (usb_iface_t *) iface;88 89 if (usb_iface->get_interface == NULL) {90 async_answer_0(callid, ENOTSUP);91 return;92 }93 94 devman_handle_t handle = DEV_IPC_GET_ARG1(*call);95 96 int iface_no;97 int rc = usb_iface->get_interface(device, handle, &iface_no);98 if (rc != EOK) {99 async_answer_0(callid, rc);100 } else {101 async_answer_1(callid, EOK, iface_no);102 }103 }104 58 105 59 void remote_usb_get_hc_handle(device_t *device, void *iface, -
uspace/lib/drv/generic/remote_usbhc.c
rdeece2f rfb78ae72 43 43 #define HACK_MAX_PACKET_SIZE_INTERRUPT_IN 4 44 44 45 static void remote_usbhc_get_address(device_t *, void *, ipc_callid_t, ipc_call_t *); 45 46 static void remote_usbhc_interrupt_out(device_t *, void *, ipc_callid_t, ipc_call_t *); 46 47 static void remote_usbhc_interrupt_in(device_t *, void *, ipc_callid_t, ipc_call_t *); 47 static void remote_usbhc_bulk_out(device_t *, void *, ipc_callid_t, ipc_call_t *);48 static void remote_usbhc_bulk_in(device_t *, void *, ipc_callid_t, ipc_call_t *);49 48 static void remote_usbhc_control_write(device_t *, void *, ipc_callid_t, ipc_call_t *); 50 49 static void remote_usbhc_control_read(device_t *, void *, ipc_callid_t, ipc_call_t *); … … 58 57 /** Remote USB host controller interface operations. */ 59 58 static remote_iface_func_ptr_t remote_usbhc_iface_ops [] = { 59 remote_usbhc_get_address, 60 60 61 remote_usbhc_reserve_default_address, 61 62 remote_usbhc_release_default_address, … … 67 68 remote_usbhc_interrupt_out, 68 69 remote_usbhc_interrupt_in, 69 70 remote_usbhc_bulk_out,71 remote_usbhc_bulk_in,72 70 73 71 remote_usbhc_control_write, … … 123 121 } 124 122 123 void remote_usbhc_get_address(device_t *device, void *iface, 124 ipc_callid_t callid, ipc_call_t *call) 125 { 126 usbhc_iface_t *usb_iface = (usbhc_iface_t *) iface; 127 128 if (!usb_iface->tell_address) { 129 async_answer_0(callid, ENOTSUP); 130 return; 131 } 132 133 devman_handle_t handle = DEV_IPC_GET_ARG1(*call); 134 135 usb_address_t address; 136 int rc = usb_iface->tell_address(device, handle, &address); 137 if (rc != EOK) { 138 async_answer_0(callid, rc); 139 } else { 140 async_answer_1(callid, EOK, address); 141 } 142 } 143 125 144 void remote_usbhc_reserve_default_address(device_t *device, void *iface, 126 145 ipc_callid_t callid, ipc_call_t *call) … … 370 389 return remote_usbhc_in_transfer(device, callid, call, 371 390 usb_iface->interrupt_in); 372 }373 374 void remote_usbhc_bulk_out(device_t *device, void *iface,375 ipc_callid_t callid, ipc_call_t *call)376 {377 usbhc_iface_t *usb_iface = (usbhc_iface_t *) iface;378 assert(usb_iface != NULL);379 380 return remote_usbhc_out_transfer(device, callid, call,381 usb_iface->bulk_out);382 }383 384 void remote_usbhc_bulk_in(device_t *device, void *iface,385 ipc_callid_t callid, ipc_call_t *call)386 {387 usbhc_iface_t *usb_iface = (usbhc_iface_t *) iface;388 assert(usb_iface != NULL);389 390 return remote_usbhc_in_transfer(device, callid, call,391 usb_iface->bulk_in);392 391 } 393 392 -
uspace/lib/drv/include/usb_iface.h
rdeece2f rfb78ae72 41 41 #include <usb/usb.h> 42 42 typedef enum { 43 /** Tell USB address assigned to device.44 * Parameters:45 * - devman handle id46 * Answer:47 * - EINVAL - unknown handle or handle not managed by this driver48 * - ENOTSUP - operation not supported (shall not happen)49 * - arbitrary error code if returned by remote implementation50 * - EOK - handle found, first parameter contains the USB address51 */52 IPC_M_USB_GET_ADDRESS,53 54 /** Tell interface number given device can use.55 * Parameters56 * - devman handle id of the device57 * Answer:58 * - ENOTSUP - operation not supported (can also mean any interface)59 * - EOK - operation okay, first parameter contains interface number60 */61 IPC_M_USB_GET_INTERFACE,62 63 43 /** Tell devman handle of device host controller. 64 44 * Parameters: … … 75 55 /** USB device communication interface. */ 76 56 typedef struct { 77 int (*get_address)(device_t *, devman_handle_t, usb_address_t *);78 int (*get_interface)(device_t *, devman_handle_t, int *);79 57 int (*get_hc_handle)(device_t *, devman_handle_t *); 80 58 } usb_iface_t; -
uspace/lib/drv/include/usbhc_iface.h
rdeece2f rfb78ae72 85 85 */ 86 86 typedef enum { 87 /** Tell USB address assigned to device. 88 * Parameters: 89 * - devman handle id 90 * Answer: 91 * - EINVAL - unknown handle or handle not managed by this driver 92 * - ENOTSUP - operation not supported by HC (shall not happen) 93 * - arbitrary error code if returned by remote implementation 94 * - EOK - handle found, first parameter contains the USB address 95 */ 96 IPC_M_USBHC_GET_ADDRESS, 97 98 87 99 /** Reserve usage of default address. 88 100 * This call informs the host controller that the caller will be … … 141 153 IPC_M_USBHC_INTERRUPT_IN, 142 154 143 /** Send bulk data to device.144 * See explanation at usb_iface_funcs_t (OUT transaction).145 */146 IPC_M_USBHC_BULK_OUT,147 148 /** Get bulk data from device.149 * See explanation at usb_iface_funcs_t (IN transaction).150 */151 IPC_M_USBHC_BULK_IN,152 153 155 /** Issue control WRITE transfer. 154 156 * See explanation at usb_iface_funcs_t (OUT transaction) for … … 194 196 /** USB host controller communication interface. */ 195 197 typedef struct { 198 int (*tell_address)(device_t *, devman_handle_t, usb_address_t *); 199 196 200 int (*reserve_default_address)(device_t *, usb_speed_t); 197 201 int (*release_default_address)(device_t *); … … 203 207 usbhc_iface_transfer_in_t interrupt_in; 204 208 205 usbhc_iface_transfer_out_t bulk_out;206 usbhc_iface_transfer_in_t bulk_in;207 208 209 int (*control_write)(device_t *, usb_target_t, 209 210 size_t, -
uspace/lib/usb/Makefile
rdeece2f rfb78ae72 35 35 src/addrkeep.c \ 36 36 src/class.c \ 37 src/ddfiface.c \38 37 src/debug.c \ 39 38 src/dp.c \ 39 src/drvpsync.c \ 40 40 src/dump.c \ 41 41 src/hidparser.c \ … … 48 48 src/usb.c \ 49 49 src/usbdevice.c \ 50 src/usbdrvreq.c \ 51 src/usbdrv.c \ 50 52 src/usbmem.c 51 53 -
uspace/lib/usb/include/usb/classes/hub.h
rdeece2f rfb78ae72 1 1 /* 2 * Copyright (c) 2010 Matus Dekanek2 * Copyright (c) 2010 Vojtech Horky 3 3 * All rights reserved. 4 4 * … … 33 33 * @brief USB hub related structures. 34 34 */ 35 #ifndef LIBUSB_ CLASS_HUB_H_36 #define LIBUSB_ CLASS_HUB_H_35 #ifndef LIBUSB_HUB_H_ 36 #define LIBUSB_HUB_H_ 37 37 38 38 #include <sys/types.h> -
uspace/lib/usb/include/usb/dp.h
rdeece2f rfb78ae72 45 45 } usb_dp_descriptor_nesting_t; 46 46 47 extern usb_dp_descriptor_nesting_t usb_dp_standard_descriptor_nesting[];48 49 47 typedef struct { 50 48 usb_dp_descriptor_nesting_t *nesting; -
uspace/lib/usb/include/usb/pipes.h
rdeece2f rfb78ae72 107 107 /** Endpoint description. */ 108 108 const usb_endpoint_description_t *description; 109 /** Interface number the endpoint must belong to (-1 for any). */110 const int interface_no;111 109 /** Found descriptor fitting the description. */ 112 110 usb_standard_endpoint_descriptor_t *descriptor; … … 123 121 int usb_device_connection_initialize(usb_device_connection_t *, 124 122 devman_handle_t, usb_address_t); 125 126 int usb_device_get_assigned_interface(device_t *);127 123 128 124 int usb_endpoint_pipe_initialize(usb_endpoint_pipe_t *, -
uspace/lib/usb/include/usb/recognise.h
rdeece2f rfb78ae72 41 41 #include <ipc/devman.h> 42 42 43 int usb_device_create_match_ids_from_device_descriptor(44 const usb_standard_device_descriptor_t *, match_id_list_t *);45 46 int usb_device_create_match_ids_from_interface(47 const usb_standard_device_descriptor_t *,48 const usb_standard_interface_descriptor_t *, match_id_list_t *);49 50 43 int usb_device_create_match_ids(usb_endpoint_pipe_t *, match_id_list_t *); 51 44 -
uspace/lib/usb/include/usb/request.h
rdeece2f rfb78ae72 41 41 #include <usb/descriptor.h> 42 42 43 /** Standard device request. */44 typedef enum {45 USB_DEVREQ_GET_STATUS = 0,46 USB_DEVREQ_CLEAR_FEATURE = 1,47 USB_DEVREQ_SET_FEATURE = 3,48 USB_DEVREQ_SET_ADDRESS = 5,49 USB_DEVREQ_GET_DESCRIPTOR = 6,50 USB_DEVREQ_SET_DESCRIPTOR = 7,51 USB_DEVREQ_GET_CONFIGURATION = 8,52 USB_DEVREQ_SET_CONFIGURATION = 9,53 USB_DEVREQ_GET_INTERFACE = 10,54 USB_DEVREQ_SET_INTERFACE = 11,55 USB_DEVREQ_SYNCH_FRAME = 12,56 USB_DEVREQ_LAST_STD57 } usb_stddevreq_t;58 59 /** Device request setup packet.60 * The setup packet describes the request.61 */62 typedef struct {63 /** Request type.64 * The type combines transfer direction, request type and65 * intended recipient.66 */67 uint8_t request_type;68 /** Request identification. */69 uint8_t request;70 /** Main parameter to the request. */71 union {72 uint16_t value;73 /* FIXME: add #ifdefs according to host endianess */74 struct {75 uint8_t value_low;76 uint8_t value_high;77 };78 };79 /** Auxiliary parameter to the request.80 * Typically, it is offset to something.81 */82 uint16_t index;83 /** Length of extra data. */84 uint16_t length;85 } __attribute__ ((packed)) usb_device_request_setup_packet_t;86 87 43 int usb_control_request_set(usb_endpoint_pipe_t *, 88 44 usb_request_type_t, usb_request_recipient_t, uint8_t, -
uspace/lib/usb/src/dp.c
rdeece2f rfb78ae72 37 37 #include <str_error.h> 38 38 #include <errno.h> 39 #include < assert.h>39 #include <usb/usbdrv.h> 40 40 #include <bool.h> 41 41 #include <usb/dp.h> 42 #include <usb/descriptor.h>43 44 #define NESTING(parentname, childname) \45 { \46 .child = USB_DESCTYPE_##childname, \47 .parent = USB_DESCTYPE_##parentname, \48 }49 #define LAST_NESTING { -1, -1 }50 51 /** Nesting of standard USB descriptors. */52 usb_dp_descriptor_nesting_t usb_dp_standard_descriptor_nesting[] = {53 NESTING(CONFIGURATION, INTERFACE),54 NESTING(INTERFACE, ENDPOINT),55 NESTING(INTERFACE, HUB),56 NESTING(INTERFACE, HID),57 NESTING(HID, HID_REPORT),58 LAST_NESTING59 };60 61 #undef NESTING62 #undef LAST_NESTING63 42 64 43 /** Tells whether pointer points inside descriptor data. -
uspace/lib/usb/src/hub.c
rdeece2f rfb78ae72 301 301 } 302 302 303 303 304 /** 304 305 * @} -
uspace/lib/usb/src/pipes.c
rdeece2f rfb78ae72 36 36 #include <usb/pipes.h> 37 37 #include <usbhc_iface.h> 38 #include <usb_iface.h>39 38 #include <errno.h> 40 39 #include <assert.h> … … 42 41 /** Tell USB address assigned to given device. 43 42 * 44 * @param phone Phone to parent device.43 * @param phone Phone to my HC. 45 44 * @param dev Device in question. 46 45 * @return USB address or error code. … … 49 48 { 50 49 sysarg_t address; 51 int rc = async_req_2_1(phone, DEV_IFACE_ID(USB _DEV_IFACE),52 IPC_M_USB _GET_ADDRESS,50 int rc = async_req_2_1(phone, DEV_IFACE_ID(USBHC_DEV_IFACE), 51 IPC_M_USBHC_GET_ADDRESS, 53 52 dev->handle, &address); 54 53 … … 58 57 59 58 return (usb_address_t) address; 60 }61 62 /** Tell USB interface assigned to given device.63 *64 * @param device Device in question.65 * @return Interface number (negative code means any).66 */67 int usb_device_get_assigned_interface(device_t *device)68 {69 int parent_phone = devman_parent_device_connect(device->handle,70 IPC_FLAG_BLOCKING);71 if (parent_phone < 0) {72 return -1;73 }74 75 sysarg_t iface_no;76 int rc = async_req_2_1(parent_phone, DEV_IFACE_ID(USB_DEV_IFACE),77 IPC_M_USB_GET_INTERFACE,78 device->handle, &iface_no);79 80 async_hangup(parent_phone);81 82 if (rc != EOK) {83 return -1;84 }85 86 return (int) iface_no;87 59 } 88 60 … … 108 80 } 109 81 110 int parent_phone = devman_parent_device_connect(device->handle, 111 IPC_FLAG_BLOCKING); 112 if (parent_phone < 0) { 113 return parent_phone; 114 } 115 116 my_address = get_my_address(parent_phone, device); 82 int hc_phone = devman_device_connect(hc_handle, 0); 83 if (hc_phone < 0) { 84 return hc_phone; 85 } 86 87 my_address = get_my_address(hc_phone, device); 117 88 if (my_address < 0) { 118 89 rc = my_address; … … 124 95 125 96 leave: 126 async_hangup( parent_phone);97 async_hangup(hc_phone); 127 98 return rc; 128 99 } -
uspace/lib/usb/src/pipesinit.c
rdeece2f rfb78ae72 109 109 * @param mapping_count Number of endpoint mappings in @p mapping. 110 110 * @param found_endpoint Description of found endpoint. 111 * @param interface_number Number of currently processed interface.112 111 * @return Endpoint mapping corresponding to @p found_endpoint. 113 112 * @retval NULL No corresponding endpoint found. … … 115 114 static usb_endpoint_mapping_t *find_endpoint_mapping( 116 115 usb_endpoint_mapping_t *mapping, size_t mapping_count, 117 usb_endpoint_description_t *found_endpoint, 118 int interface_number) 116 usb_endpoint_description_t *found_endpoint) 119 117 { 120 118 while (mapping_count > 0) { 121 bool interface_number_fits = (mapping->interface_no < 0) 122 || (mapping->interface_no == interface_number); 123 124 bool endpoint_descriptions_fits = endpoint_fits_description( 125 mapping->description, found_endpoint); 126 127 if (interface_number_fits && endpoint_descriptions_fits) { 119 if (endpoint_fits_description(mapping->description, 120 found_endpoint)) { 128 121 return mapping; 129 122 } … … 176 169 */ 177 170 usb_endpoint_mapping_t *ep_mapping = find_endpoint_mapping(mapping, 178 mapping_count, &description , interface->interface_number);171 mapping_count, &description); 179 172 if (ep_mapping == NULL) { 180 173 return ENOENT; -
uspace/lib/usb/src/pipesio.c
rdeece2f rfb78ae72 71 71 ipc_method = IPC_M_USBHC_INTERRUPT_IN; 72 72 break; 73 case USB_TRANSFER_BULK:74 ipc_method = IPC_M_USBHC_BULK_IN;75 break;76 73 default: 77 74 return ENOTSUP; … … 197 194 case USB_TRANSFER_INTERRUPT: 198 195 ipc_method = IPC_M_USBHC_INTERRUPT_OUT; 199 break;200 case USB_TRANSFER_BULK:201 ipc_method = IPC_M_USBHC_BULK_OUT;202 196 break; 203 197 default: -
uspace/lib/usb/src/recognise.c
rdeece2f rfb78ae72 34 34 */ 35 35 #include <sys/types.h> 36 #include <usb_iface.h> 37 #include <usb/usbdrv.h> 36 38 #include <usb/pipes.h> 37 39 #include <usb/recognise.h> 38 #include <usb/ddfiface.h>39 40 #include <usb/request.h> 40 41 #include <usb/classes/classes.h> … … 45 46 static FIBRIL_MUTEX_INITIALIZE(device_name_index_mutex); 46 47 48 /** Callback for getting host controller handle. 49 * 50 * @param dev Device in question. 51 * @param[out] handle Devman handle of the host controller. 52 * @return Error code. 53 */ 54 static int usb_iface_get_hc_handle(device_t *dev, devman_handle_t *handle) 55 { 56 assert(dev); 57 assert(dev->parent != NULL); 58 59 device_t *parent = dev->parent; 60 61 if (parent->ops && parent->ops->interfaces[USB_DEV_IFACE]) { 62 usb_iface_t *usb_iface 63 = (usb_iface_t *) parent->ops->interfaces[USB_DEV_IFACE]; 64 assert(usb_iface != NULL); 65 if (usb_iface->get_hc_handle) { 66 int rc = usb_iface->get_hc_handle(parent, handle); 67 return rc; 68 } 69 } 70 71 return ENOTSUP; 72 } 73 74 static usb_iface_t usb_iface = { 75 .get_hc_handle = usb_iface_get_hc_handle 76 }; 77 47 78 device_ops_t child_ops = { 48 .interfaces[USB_DEV_IFACE] = &usb_iface _hub_child_impl79 .interfaces[USB_DEV_IFACE] = &usb_iface 49 80 }; 50 81 … … 111 142 } 112 143 113 #define ADD_MATCHID_OR_RETURN(match_ids, score, format, ...) \114 do { \115 int __rc = usb_add_match_id((match_ids), (score), \116 format, ##__VA_ARGS__); \117 if (__rc != EOK) { \118 return __rc; \119 } \120 } while (0)121 122 /** Create device match ids based on its interface.123 *124 * @param[in] descriptor Interface descriptor.125 * @param[out] matches Initialized list of match ids.126 * @return Error code (the two mentioned are not the only ones).127 * @retval EINVAL Invalid input parameters (expects non NULL pointers).128 * @retval ENOENT Interface does not specify class.129 */130 int usb_device_create_match_ids_from_interface(131 const usb_standard_device_descriptor_t *desc_device,132 const usb_standard_interface_descriptor_t *desc_interface,133 match_id_list_t *matches)134 {135 if (desc_interface == NULL) {136 return EINVAL;137 }138 if (matches == NULL) {139 return EINVAL;140 }141 142 if (desc_interface->interface_class == USB_CLASS_USE_INTERFACE) {143 return ENOENT;144 }145 146 const char *classname = usb_str_class(desc_interface->interface_class);147 assert(classname != NULL);148 149 #define IFACE_PROTOCOL_FMT "interface&class=%s&subclass=0x%02x&protocol=0x%02x"150 #define IFACE_PROTOCOL_ARGS classname, desc_interface->interface_subclass, \151 desc_interface->interface_protocol152 153 #define IFACE_SUBCLASS_FMT "interface&class=%s&subclass=0x%02x"154 #define IFACE_SUBCLASS_ARGS classname, desc_interface->interface_subclass155 156 #define IFACE_CLASS_FMT "interface&class=%s"157 #define IFACE_CLASS_ARGS classname158 159 #define VENDOR_RELEASE_FMT "vendor=0x%04x&product=0x%04x&release=" BCD_FMT160 #define VENDOR_RELEASE_ARGS desc_device->vendor_id, desc_device->product_id, \161 BCD_ARGS(desc_device->device_version)162 163 #define VENDOR_PRODUCT_FMT "vendor=0x%04x&product=0x%04x"164 #define VENDOR_PRODUCT_ARGS desc_device->vendor_id, desc_device->product_id165 166 #define VENDOR_ONLY_FMT "vendor=0x%04x"167 #define VENDOR_ONLY_ARGS desc_device->vendor_id168 169 /*170 * If the vendor is specified, create match ids with vendor with171 * higher score.172 * Then the same ones without the vendor part.173 */174 if ((desc_device != NULL) && (desc_device->vendor_id != 0)) {175 /* First, interface matches with device release number. */176 ADD_MATCHID_OR_RETURN(matches, 250,177 "usb&" VENDOR_RELEASE_FMT "&" IFACE_PROTOCOL_FMT,178 VENDOR_RELEASE_ARGS, IFACE_PROTOCOL_ARGS);179 ADD_MATCHID_OR_RETURN(matches, 240,180 "usb&" VENDOR_RELEASE_FMT "&" IFACE_SUBCLASS_FMT,181 VENDOR_RELEASE_ARGS, IFACE_SUBCLASS_ARGS);182 ADD_MATCHID_OR_RETURN(matches, 230,183 "usb&" VENDOR_RELEASE_FMT "&" IFACE_CLASS_FMT,184 VENDOR_RELEASE_ARGS, IFACE_CLASS_ARGS);185 186 /* Next, interface matches without release number. */187 ADD_MATCHID_OR_RETURN(matches, 220,188 "usb&" VENDOR_PRODUCT_FMT "&" IFACE_PROTOCOL_FMT,189 VENDOR_PRODUCT_ARGS, IFACE_PROTOCOL_ARGS);190 ADD_MATCHID_OR_RETURN(matches, 210,191 "usb&" VENDOR_PRODUCT_FMT "&" IFACE_SUBCLASS_FMT,192 VENDOR_PRODUCT_ARGS, IFACE_SUBCLASS_ARGS);193 ADD_MATCHID_OR_RETURN(matches, 200,194 "usb&" VENDOR_PRODUCT_FMT "&" IFACE_CLASS_FMT,195 VENDOR_PRODUCT_ARGS, IFACE_CLASS_ARGS);196 197 /* Finally, interface matches with only vendor. */198 ADD_MATCHID_OR_RETURN(matches, 190,199 "usb&" VENDOR_ONLY_FMT "&" IFACE_PROTOCOL_FMT,200 VENDOR_ONLY_ARGS, IFACE_PROTOCOL_ARGS);201 ADD_MATCHID_OR_RETURN(matches, 180,202 "usb&" VENDOR_ONLY_FMT "&" IFACE_SUBCLASS_FMT,203 VENDOR_ONLY_ARGS, IFACE_SUBCLASS_ARGS);204 ADD_MATCHID_OR_RETURN(matches, 170,205 "usb&" VENDOR_ONLY_FMT "&" IFACE_CLASS_FMT,206 VENDOR_ONLY_ARGS, IFACE_CLASS_ARGS);207 }208 209 /* Now, the same but without any vendor specification. */210 ADD_MATCHID_OR_RETURN(matches, 160,211 "usb&" IFACE_PROTOCOL_FMT,212 IFACE_PROTOCOL_ARGS);213 ADD_MATCHID_OR_RETURN(matches, 150,214 "usb&" IFACE_SUBCLASS_FMT,215 IFACE_SUBCLASS_ARGS);216 ADD_MATCHID_OR_RETURN(matches, 140,217 "usb&" IFACE_CLASS_FMT,218 IFACE_CLASS_ARGS);219 220 #undef IFACE_PROTOCOL_FMT221 #undef IFACE_PROTOCOL_ARGS222 #undef IFACE_SUBCLASS_FMT223 #undef IFACE_SUBCLASS_ARGS224 #undef IFACE_CLASS_FMT225 #undef IFACE_CLASS_ARGS226 #undef VENDOR_RELEASE_FMT227 #undef VENDOR_RELEASE_ARGS228 #undef VENDOR_PRODUCT_FMT229 #undef VENDOR_PRODUCT_ARGS230 #undef VENDOR_ONLY_FMT231 #undef VENDOR_ONLY_ARGS232 233 return EOK;234 }235 236 144 /** Create DDF match ids from USB device descriptor. 237 145 * … … 240 148 * @return Error code. 241 149 */ 242 int usb_device_create_match_ids_from_device_descriptor( 243 const usb_standard_device_descriptor_t *device_descriptor, 244 match_id_list_t *matches) 245 { 150 int usb_drv_create_match_ids_from_device_descriptor( 151 match_id_list_t *matches, 152 const usb_standard_device_descriptor_t *device_descriptor) 153 { 154 int rc; 155 246 156 /* 247 157 * Unless the vendor id is 0, the pair idVendor-idProduct … … 250 160 if (device_descriptor->vendor_id != 0) { 251 161 /* First, with release number. */ 252 ADD_MATCHID_OR_RETURN(matches, 100,162 rc = usb_add_match_id(matches, 100, 253 163 "usb&vendor=0x%04x&product=0x%04x&release=" BCD_FMT, 254 164 (int) device_descriptor->vendor_id, 255 165 (int) device_descriptor->product_id, 256 166 BCD_ARGS(device_descriptor->device_version)); 167 if (rc != EOK) { 168 return rc; 169 } 257 170 258 171 /* Next, without release number. */ 259 ADD_MATCHID_OR_RETURN(matches, 90,172 rc = usb_add_match_id(matches, 90, 260 173 "usb&vendor=0x%04x&product=0x%04x", 261 174 (int) device_descriptor->vendor_id, 262 175 (int) device_descriptor->product_id); 176 if (rc != EOK) { 177 return rc; 178 } 263 179 } 264 180 265 181 /* 266 182 * If the device class points to interface we skip adding 267 * class directly but we add a multi interface device.183 * class directly. 268 184 */ 269 185 if (device_descriptor->device_class != USB_CLASS_USE_INTERFACE) { 270 ADD_MATCHID_OR_RETURN(matches, 50, "usb&class=%s",186 rc = usb_add_match_id(matches, 50, "usb&class=%s", 271 187 usb_str_class(device_descriptor->device_class)); 272 } else { 273 ADD_MATCHID_OR_RETURN(matches, 50, "usb&mid"); 188 if (rc != EOK) { 189 return rc; 190 } 274 191 } 275 192 … … 277 194 } 278 195 196 /** Create DDF match ids from USB configuration descriptor. 197 * The configuration descriptor is expected to be in the complete form, 198 * i.e. including interface, endpoint etc. descriptors. 199 * 200 * @param matches List of match ids to extend. 201 * @param config_descriptor Configuration descriptor returned by given device. 202 * @param total_size Size of the @p config_descriptor. 203 * @return Error code. 204 */ 205 int usb_drv_create_match_ids_from_configuration_descriptor( 206 match_id_list_t *matches, 207 const void *config_descriptor, size_t total_size) 208 { 209 /* 210 * Iterate through config descriptor to find the interface 211 * descriptors. 212 */ 213 size_t position = sizeof(usb_standard_configuration_descriptor_t); 214 while (position + 1 < total_size) { 215 uint8_t *current_descriptor 216 = ((uint8_t *) config_descriptor) + position; 217 uint8_t cur_descr_len = current_descriptor[0]; 218 uint8_t cur_descr_type = current_descriptor[1]; 219 220 if (cur_descr_len == 0) { 221 return ENOENT; 222 } 223 224 position += cur_descr_len; 225 226 if (cur_descr_type != USB_DESCTYPE_INTERFACE) { 227 continue; 228 } 229 230 /* 231 * Finally, we found an interface descriptor. 232 */ 233 usb_standard_interface_descriptor_t *interface 234 = (usb_standard_interface_descriptor_t *) 235 current_descriptor; 236 237 int rc = usb_add_match_id(matches, 50, 238 "usb&interface&class=%s", 239 usb_str_class(interface->interface_class)); 240 if (rc != EOK) { 241 return rc; 242 } 243 } 244 245 return EOK; 246 } 247 248 /** Add match ids based on configuration descriptor. 249 * 250 * @param pipe Control pipe to the device. 251 * @param matches Match ids list to add matches to. 252 * @param config_count Number of configurations the device has. 253 * @return Error code. 254 */ 255 static int usb_add_config_descriptor_match_ids(usb_endpoint_pipe_t *pipe, 256 match_id_list_t *matches, int config_count) 257 { 258 int final_rc = EOK; 259 260 int config_index; 261 for (config_index = 0; config_index < config_count; config_index++) { 262 int rc; 263 usb_standard_configuration_descriptor_t config_descriptor; 264 rc = usb_request_get_bare_configuration_descriptor(pipe, 265 config_index, &config_descriptor); 266 if (rc != EOK) { 267 final_rc = rc; 268 continue; 269 } 270 271 size_t full_config_descriptor_size; 272 void *full_config_descriptor 273 = malloc(config_descriptor.total_length); 274 rc = usb_request_get_full_configuration_descriptor(pipe, 275 config_index, 276 full_config_descriptor, config_descriptor.total_length, 277 &full_config_descriptor_size); 278 if (rc != EOK) { 279 final_rc = rc; 280 continue; 281 } 282 if (full_config_descriptor_size 283 != config_descriptor.total_length) { 284 final_rc = ERANGE; 285 continue; 286 } 287 288 rc = usb_drv_create_match_ids_from_configuration_descriptor( 289 matches, 290 full_config_descriptor, full_config_descriptor_size); 291 if (rc != EOK) { 292 final_rc = rc; 293 continue; 294 } 295 296 } 297 298 return final_rc; 299 } 279 300 280 301 /** Create match ids describing attached device. … … 302 323 } 303 324 304 rc = usb_d evice_create_match_ids_from_device_descriptor(305 &device_descriptor , matches);325 rc = usb_drv_create_match_ids_from_device_descriptor(matches, 326 &device_descriptor); 306 327 if (rc != EOK) { 307 328 return rc; … … 309 330 310 331 /* 332 * Go through all configurations and add matches 333 * based on interface class. 334 */ 335 rc = usb_add_config_descriptor_match_ids(ctrl_pipe, matches, 336 device_descriptor.configuration_count); 337 if (rc != EOK) { 338 return rc; 339 } 340 341 /* 311 342 * As a fallback, provide the simplest match id possible. 312 343 */ 313 ADD_MATCHID_OR_RETURN(matches, 1, "usb&fallback"); 344 rc = usb_add_match_id(matches, 1, "usb&fallback"); 345 if (rc != EOK) { 346 return rc; 347 } 314 348 315 349 return EOK; -
uspace/lib/usb/src/request.c
rdeece2f rfb78ae72 34 34 */ 35 35 #include <usb/request.h> 36 #include <usb/devreq.h> 36 37 #include <errno.h> 37 38 -
uspace/lib/usbvirt/Makefile
rdeece2f rfb78ae72 30 30 LIBRARY = libusbvirt 31 31 32 EXTRA_CFLAGS = -I$(LIBUSB_PREFIX)/include -I $(LIBDRV_PREFIX)/include -Iinclude32 EXTRA_CFLAGS = -I$(LIBUSB_PREFIX)/include -Iinclude 33 33 34 34 SOURCES = \ -
uspace/lib/usbvirt/include/usbvirt/device.h
rdeece2f rfb78ae72 37 37 38 38 #include <usb/usb.h> 39 #include <usb/request.h>40 39 #include <usb/descriptor.h> 40 #include <usb/devreq.h> 41 41 42 42 /** Request type of a control transfer. */ -
uspace/lib/usbvirt/src/stdreq.c
rdeece2f rfb78ae72 36 36 #include <stdlib.h> 37 37 #include <mem.h> 38 #include <usb/ request.h>38 #include <usb/devreq.h> 39 39 40 40 #include "private.h"
Note:
See TracChangeset
for help on using the changeset viewer.