Changes in uspace/drv/usbhub/usbhub.c [4e900c1:09daa8b] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/usbhub/usbhub.c
r4e900c1 r09daa8b 53 53 #include "usb/classes/classes.h" 54 54 55 static ddf_dev_ops_t hub_device_ops = {56 .interfaces[USB_DEV_IFACE] = &usb_iface_hub_impl57 };58 59 /** Hub status-change endpoint description60 *61 * For more see usb hub specification in 11.15.1 of62 */63 static usb_endpoint_description_t status_change_endpoint_description = {64 .transfer_type = USB_TRANSFER_INTERRUPT,65 .direction = USB_DIRECTION_IN,66 .interface_class = USB_CLASS_HUB,67 .interface_subclass = 0,68 .interface_protocol = 0,69 .flags = 070 };71 72 55 int usb_hub_control_loop(void * hub_info_param){ 73 56 usb_hub_info_t * hub_info = (usb_hub_info_t*)hub_info_param; 74 while(true){ 75 usb_hub_check_hub_changes(hub_info); 57 int errorCode = EOK; 58 59 while(errorCode == EOK){ 60 errorCode = usb_hub_check_hub_changes(hub_info); 76 61 async_usleep(1000 * 1000 );/// \TODO proper number once 77 62 } 63 usb_log_error("something in ctrl loop went wrong, errno %d\n",errorCode); 64 78 65 return 0; 79 66 } … … 87 74 88 75 /** 89 * Initialize connnections to host controller, device, and device 90 * control endpoint 91 * @param hub 92 * @param device 76 * create usb_hub_info_t structure 77 * 78 * Does only basic copying of known information into new structure. 79 * @param usb_dev usb device structure 80 * @return basic usb_hub_info_t structure 81 */ 82 static usb_hub_info_t * usb_hub_info_create(usb_device_t * usb_dev) { 83 usb_hub_info_t * result = usb_new(usb_hub_info_t); 84 if(!result) return NULL; 85 result->usb_device = usb_dev; 86 result->status_change_pipe = usb_dev->pipes[0].pipe; 87 result->control_pipe = &usb_dev->ctrl_pipe; 88 result->is_default_address_used = false; 89 return result; 90 } 91 92 /** 93 * Load hub-specific information into hub_info structure. 94 * 95 * Particularly read port count and initialize structure holding port 96 * information. 97 * This function is hub-specific and should be run only after the hub is 98 * configured using usb_hub_set_configuration function. 99 * @param hub_info pointer to structure with usb hub data 100 * @return error code 101 */ 102 static int usb_hub_get_hub_specific_info(usb_hub_info_t * hub_info){ 103 // get hub descriptor 104 usb_log_debug("creating serialized descriptor\n"); 105 void * serialized_descriptor = malloc(USB_HUB_MAX_DESCRIPTOR_SIZE); 106 usb_hub_descriptor_t * descriptor; 107 108 /* this was one fix of some bug, should not be needed anymore 109 int opResult = usb_request_set_configuration(&result->endpoints.control, 1); 110 if(opResult!=EOK){ 111 usb_log_error("could not set default configuration, errno %d",opResult); 112 return opResult; 113 } 114 */ 115 size_t received_size; 116 int opResult = usb_request_get_descriptor(&hub_info->usb_device->ctrl_pipe, 117 USB_REQUEST_TYPE_CLASS, USB_REQUEST_RECIPIENT_DEVICE, 118 USB_DESCTYPE_HUB, 119 0, 0, serialized_descriptor, 120 USB_HUB_MAX_DESCRIPTOR_SIZE, &received_size); 121 122 if (opResult != EOK) { 123 usb_log_error("failed when receiving hub descriptor, badcode = %d\n", 124 opResult); 125 free(serialized_descriptor); 126 return opResult; 127 } 128 usb_log_debug2("deserializing descriptor\n"); 129 descriptor = usb_deserialize_hub_desriptor(serialized_descriptor); 130 if(descriptor==NULL){ 131 usb_log_warning("could not deserialize descriptor \n"); 132 return opResult; 133 } 134 usb_log_info("setting port count to %d\n",descriptor->ports_count); 135 hub_info->port_count = descriptor->ports_count; 136 hub_info->attached_devs = (usb_hc_attached_device_t*) 137 malloc((hub_info->port_count+1) * sizeof(usb_hc_attached_device_t)); 138 int i; 139 for(i=0;i<hub_info->port_count+1;++i){ 140 hub_info->attached_devs[i].handle=0; 141 hub_info->attached_devs[i].address=0; 142 } 143 usb_log_debug2("freeing data\n"); 144 free(serialized_descriptor); 145 free(descriptor->devices_removable); 146 free(descriptor); 147 return EOK; 148 } 149 /** 150 * Set configuration of hub 151 * 152 * Check whether there is at least one configuration and sets the first one. 153 * This function should be run prior to running any hub-specific action. 154 * @param hub_info 93 155 * @return 94 156 */ 95 static int usb_hub_init_communication(usb_hub_info_t * hub){ 96 usb_log_debug("Initializing hub USB communication (hub->device->handle=%zu).\n", hub->device->handle); 97 int opResult; 98 opResult = usb_device_connection_initialize_from_device( 99 &hub->device_connection, 100 hub->device); 101 if(opResult != EOK){ 102 dprintf(USB_LOG_LEVEL_ERROR, 103 "could not initialize connection to hc, errno %d",opResult); 104 return opResult; 105 } 106 usb_log_debug("Initializing USB wire abstraction.\n"); 107 opResult = usb_hc_connection_initialize_from_device(&hub->connection, 108 hub->device); 109 if(opResult != EOK){ 110 dprintf(USB_LOG_LEVEL_ERROR, 111 "could not initialize connection to device, errno %d",opResult); 112 return opResult; 113 } 114 usb_log_debug("Initializing default control pipe.\n"); 115 opResult = usb_endpoint_pipe_initialize_default_control(&hub->endpoints.control, 116 &hub->device_connection); 117 if(opResult != EOK){ 118 dprintf(USB_LOG_LEVEL_ERROR, 119 "could not initialize connection to device endpoint, errno %d",opResult); 120 } 121 return opResult; 122 } 123 124 /** 125 * When entering this function, hub->endpoints.control should be active. 126 * @param hub 127 * @return 128 */ 129 static int usb_hub_process_configuration_descriptors( 130 usb_hub_info_t * hub){ 131 if(hub==NULL) { 132 return EINVAL; 133 } 134 int opResult; 135 157 static int usb_hub_set_configuration(usb_hub_info_t * hub_info){ 136 158 //device descriptor 137 159 usb_standard_device_descriptor_t std_descriptor; 138 opResult = usb_request_get_device_descriptor(&hub->endpoints.control, 160 int opResult = usb_request_get_device_descriptor( 161 &hub_info->usb_device->ctrl_pipe, 139 162 &std_descriptor); 140 163 if(opResult!=EOK){ 141 dprintf(USB_LOG_LEVEL_ERROR, "could not get device descriptor, %d",opResult);142 return opResult; 143 } 144 dprintf(USB_LOG_LEVEL_INFO, "hub has %d configurations",164 usb_log_error("could not get device descriptor, %d\n",opResult); 165 return opResult; 166 } 167 usb_log_info("hub has %d configurations\n", 145 168 std_descriptor.configuration_count); 146 169 if(std_descriptor.configuration_count<1){ 147 dprintf(USB_LOG_LEVEL_ERROR, "THERE ARE NO CONFIGURATIONS AVAILABLE");170 usb_log_error("THERE ARE NO CONFIGURATIONS AVAILABLE\n"); 148 171 //shouldn`t I return? 149 172 } … … 153 176 size_t descriptors_size = 0; 154 177 opResult = usb_request_get_full_configuration_descriptor_alloc( 155 &hub ->endpoints.control, 0,178 &hub_info->usb_device->ctrl_pipe, 0, 156 179 (void **) &descriptors, &descriptors_size); 157 180 if (opResult != EOK) { … … 164 187 165 188 /* Set configuration. */ 166 opResult = usb_request_set_configuration(&hub ->endpoints.control,189 opResult = usb_request_set_configuration(&hub_info->usb_device->ctrl_pipe, 167 190 config_descriptor->configuration_number); 168 191 … … 172 195 return opResult; 173 196 } 174 dprintf(USB_LOG_LEVEL_DEBUG, "\tused configuration %d",197 usb_log_debug("\tused configuration %d\n", 175 198 config_descriptor->configuration_number); 176 177 usb_endpoint_mapping_t endpoint_mapping[1] = {178 {179 .pipe = &hub->endpoints.status_change,180 .description = &status_change_endpoint_description,181 .interface_no =182 usb_device_get_assigned_interface(hub->device)183 }184 };185 opResult = usb_endpoint_pipe_initialize_from_configuration(186 endpoint_mapping, 1,187 descriptors, descriptors_size,188 &hub->device_connection);189 if (opResult != EOK) {190 dprintf(USB_LOG_LEVEL_ERROR,191 "Failed to initialize status change pipe: %s",192 str_error(opResult));193 return opResult;194 }195 if (!endpoint_mapping[0].present) {196 dprintf(USB_LOG_LEVEL_ERROR,"Not accepting device, " \197 "cannot understand what is happenning");198 return EREFUSED;199 }200 201 199 free(descriptors); 202 200 return EOK; 201 } 202 203 /** 204 * Initialize hub device driver fibril 205 * 206 * Creates hub representation and fibril that periodically checks hub`s status. 207 * Hub representation is passed to the fibril. 208 * @param usb_dev generic usb device information 209 * @return error code 210 */ 211 int usb_hub_add_device(usb_device_t * usb_dev){ 212 if(!usb_dev) return EINVAL; 213 usb_hub_info_t * hub_info = usb_hub_info_create(usb_dev); 214 //create hc connection 215 usb_log_debug("Initializing USB wire abstraction.\n"); 216 int opResult = usb_hc_connection_initialize_from_device( 217 &hub_info->connection, 218 hub_info->usb_device->ddf_dev); 219 if(opResult != EOK){ 220 usb_log_error("could not initialize connection to device, errno %d\n", 221 opResult); 222 free(hub_info); 223 return opResult; 224 } 203 225 204 } 205 206 207 /** 208 * Create hub representation from device information. 209 * @param device 210 * @return pointer to created structure or NULL in case of error 211 */ 212 usb_hub_info_t * usb_create_hub_info(ddf_dev_t * device) { 213 usb_hub_info_t* result = usb_new(usb_hub_info_t); 214 result->device = device; 215 int opResult; 216 opResult = usb_hub_init_communication(result); 217 if(opResult != EOK){ 218 free(result); 219 return NULL; 220 } 221 222 //result->device = device; 223 result->port_count = -1; 224 result->device = device; 225 226 //result->usb_device = usb_new(usb_hcd_attached_device_info_t); 227 size_t received_size; 228 229 // get hub descriptor 230 dprintf(USB_LOG_LEVEL_DEBUG, "creating serialized descripton"); 231 void * serialized_descriptor = malloc(USB_HUB_MAX_DESCRIPTOR_SIZE); 232 usb_hub_descriptor_t * descriptor; 233 dprintf(USB_LOG_LEVEL_DEBUG, "starting control transaction"); 234 usb_endpoint_pipe_start_session(&result->endpoints.control); 235 opResult = usb_request_set_configuration(&result->endpoints.control, 1); 236 assert(opResult == EOK); 237 238 opResult = usb_request_get_descriptor(&result->endpoints.control, 239 USB_REQUEST_TYPE_CLASS, USB_REQUEST_RECIPIENT_DEVICE, 240 USB_DESCTYPE_HUB, 241 0, 0, serialized_descriptor, 242 USB_HUB_MAX_DESCRIPTOR_SIZE, &received_size); 243 usb_endpoint_pipe_end_session(&result->endpoints.control); 244 245 if (opResult != EOK) { 246 dprintf(USB_LOG_LEVEL_ERROR, "failed when receiving hub descriptor, badcode = %d",opResult); 247 free(serialized_descriptor); 248 free(result); 249 return NULL; 250 } 251 dprintf(USB_LOG_LEVEL_DEBUG2, "deserializing descriptor"); 252 descriptor = usb_deserialize_hub_desriptor(serialized_descriptor); 253 if(descriptor==NULL){ 254 dprintf(USB_LOG_LEVEL_WARNING, "could not deserialize descriptor "); 255 free(result); 256 return NULL; 257 } 258 259 dprintf(USB_LOG_LEVEL_INFO, "setting port count to %d",descriptor->ports_count); 260 result->port_count = descriptor->ports_count; 261 result->attached_devs = (usb_hc_attached_device_t*) 262 malloc((result->port_count+1) * sizeof(usb_hc_attached_device_t)); 263 int i; 264 for(i=0;i<result->port_count+1;++i){ 265 result->attached_devs[i].handle=0; 266 result->attached_devs[i].address=0; 267 } 268 dprintf(USB_LOG_LEVEL_DEBUG2, "freeing data"); 269 free(serialized_descriptor); 270 free(descriptor->devices_removable); 271 free(descriptor); 272 273 //finish 274 275 dprintf(USB_LOG_LEVEL_INFO, "hub info created"); 276 277 return result; 278 } 279 280 /** 281 * Create hub representation and add it into hub list 282 * @param dev 283 * @return 284 */ 285 int usb_add_hub_device(ddf_dev_t *dev) { 286 dprintf(USB_LOG_LEVEL_INFO, "add_hub_device(handle=%d)", (int) dev->handle); 287 288 //dev->ops = &hub_device_ops; 289 (void) hub_device_ops; 290 291 usb_hub_info_t * hub_info = usb_create_hub_info(dev); 292 if(!hub_info){ 293 return EINTR; 294 } 295 296 int opResult; 297 298 //perform final configurations 299 usb_endpoint_pipe_start_session(&hub_info->endpoints.control); 300 // process descriptors 301 opResult = usb_hub_process_configuration_descriptors(hub_info); 302 if(opResult != EOK){ 303 dprintf(USB_LOG_LEVEL_ERROR,"could not get configuration descriptors, %d", 304 opResult); 305 return opResult; 306 } 307 //power ports 308 usb_device_request_setup_packet_t request; 309 int port; 310 for (port = 1; port < hub_info->port_count+1; ++port) { 311 usb_hub_set_power_port_request(&request, port); 312 opResult = usb_endpoint_pipe_control_write(&hub_info->endpoints.control, 313 &request,sizeof(usb_device_request_setup_packet_t), NULL, 0); 314 dprintf(USB_LOG_LEVEL_INFO, "powering port %d",port); 315 if (opResult != EOK) { 316 dprintf(USB_LOG_LEVEL_WARNING, "something went wrong when setting hub`s %dth port", port); 317 } 318 } 319 //ports powered, hub seems to be enabled 320 usb_endpoint_pipe_end_session(&hub_info->endpoints.control); 321 322 //add the hub to list 323 //is this needed now? 324 fibril_mutex_lock(&usb_hub_list_lock); 325 usb_lst_append(&usb_hub_list, hub_info); 326 fibril_mutex_unlock(&usb_hub_list_lock); 327 dprintf(USB_LOG_LEVEL_DEBUG, "hub info added to list"); 328 329 dprintf(USB_LOG_LEVEL_DEBUG, "adding to ddf"); 330 ddf_fun_t *hub_fun = ddf_fun_create(dev, fun_exposed, "hub"); 226 usb_endpoint_pipe_start_session(hub_info->control_pipe); 227 //set hub configuration 228 opResult = usb_hub_set_configuration(hub_info); 229 if(opResult!=EOK){ 230 usb_log_error("could not set hub configuration, errno %d\n",opResult); 231 free(hub_info); 232 return opResult; 233 } 234 //get port count and create attached_devs 235 opResult = usb_hub_get_hub_specific_info(hub_info); 236 if(opResult!=EOK){ 237 usb_log_error("could not set hub configuration, errno %d\n",opResult); 238 free(hub_info); 239 return opResult; 240 } 241 usb_endpoint_pipe_end_session(hub_info->control_pipe); 242 243 244 /// \TODO what is this? 245 usb_log_debug("adding to ddf"); 246 ddf_fun_t *hub_fun = ddf_fun_create(hub_info->usb_device->ddf_dev, 247 fun_exposed, "hub"); 331 248 assert(hub_fun != NULL); 332 249 hub_fun->ops = NULL; … … 337 254 assert(rc == EOK); 338 255 256 //create fibril for the hub control loop 339 257 fid_t fid = fibril_create(usb_hub_control_loop, hub_info); 340 258 if (fid == 0) { 341 dprintf(USB_LOG_LEVEL_ERROR, 342 ": failed to start monitoring fibril for new hub"); 259 usb_log_error("failed to start monitoring fibril for new hub"); 343 260 return ENOMEM; 344 261 } 345 262 fibril_add_ready(fid); 346 347 dprintf(USB_LOG_LEVEL_DEBUG, "hub fibril created"); 348 //(void)hub_info; 349 //usb_hub_check_hub_changes(); 350 351 dprintf(USB_LOG_LEVEL_INFO, "hub dev added"); 352 //address is lost... 353 dprintf(USB_LOG_LEVEL_DEBUG, "\taddress %d, has %d ports ", 354 //hub_info->endpoints.control., 355 hub_info->port_count); 356 263 usb_log_debug("hub fibril created"); 264 usb_log_debug("has %d ports ",hub_info->port_count); 357 265 return EOK; 358 //return ENOTSUP;359 266 } 360 267 … … 367 274 368 275 /** 276 * release default address used by given hub 277 * 278 * Also unsets hub->is_default_address_used. Convenience wrapper function. 279 * @note hub->connection MUST be open for communication 280 * @param hub hub representation 281 * @return error code 282 */ 283 static int usb_hub_release_default_address(usb_hub_info_t * hub){ 284 int opResult = usb_hc_release_default_address(&hub->connection); 285 if(opResult!=EOK){ 286 usb_log_error("could not release default address, errno %d\n",opResult); 287 return opResult; 288 } 289 hub->is_default_address_used = false; 290 return EOK; 291 } 292 293 /** 369 294 * Reset the port with new device and reserve the default address. 370 295 * @param hc … … 372 297 * @param target 373 298 */ 374 static void usb_hub_init_add_device(usb_hub_info_t * hub, uint16_t port) { 299 static void usb_hub_init_add_device(usb_hub_info_t * hub, uint16_t port, 300 usb_speed_t speed) { 301 //if this hub already uses default address, it cannot request it once more 302 if(hub->is_default_address_used) return; 303 usb_log_info("some connection changed\n"); 304 assert(hub->control_pipe->hc_phone); 305 int opResult = usb_hub_clear_port_feature(hub->control_pipe, 306 port, USB_HUB_FEATURE_C_PORT_CONNECTION); 307 if(opResult != EOK){ 308 usb_log_warning("could not clear port-change-connection flag\n"); 309 } 375 310 usb_device_request_setup_packet_t request; 376 int opResult; 377 dprintf(USB_LOG_LEVEL_INFO, "some connection changed"); 378 assert(hub->endpoints.control.hc_phone); 311 379 312 //get default address 380 //opResult = usb_drv_reserve_default_address(hc); 381 opResult = usb_hc_reserve_default_address(&hub->connection, USB_SPEED_LOW); 313 opResult = usb_hc_reserve_default_address(&hub->connection, speed); 382 314 383 315 if (opResult != EOK) { 384 dprintf(USB_LOG_LEVEL_WARNING, 385 "cannot assign default address, it is probably used %d",opResult); 386 return; 387 } 316 usb_log_warning("cannot assign default address, it is probably used %d\n", 317 opResult); 318 return; 319 } 320 hub->is_default_address_used = true; 388 321 //reset port 389 322 usb_hub_set_reset_port_request(&request, port); 390 323 opResult = usb_endpoint_pipe_control_write( 391 &hub->endpoints.control,324 hub->control_pipe, 392 325 &request,sizeof(usb_device_request_setup_packet_t), 393 326 NULL, 0 394 327 ); 395 328 if (opResult != EOK) { 396 dprintf(USB_LOG_LEVEL_ERROR, 397 "something went wrong when reseting a port %d",opResult); 329 usb_log_error("something went wrong when reseting a port %d\n",opResult); 398 330 //usb_hub_release_default_address(hc); 399 usb_hc_release_default_address(&hub->connection); 400 } 331 usb_hub_release_default_address(hub); 332 } 333 return; 401 334 } 402 335 … … 408 341 */ 409 342 static void usb_hub_finalize_add_device( usb_hub_info_t * hub, 410 uint16_t port, bool isLowSpeed) {343 uint16_t port, usb_speed_t speed) { 411 344 412 345 int opResult; 413 dprintf(USB_LOG_LEVEL_INFO, "finalizing add device");414 opResult = usb_hub_clear_port_feature( &hub->endpoints.control,346 usb_log_info("finalizing add device\n"); 347 opResult = usb_hub_clear_port_feature(hub->control_pipe, 415 348 port, USB_HUB_FEATURE_C_PORT_RESET); 416 349 417 350 if (opResult != EOK) { 418 dprintf(USB_LOG_LEVEL_ERROR, "failed to clear port reset feature");419 usb_h c_release_default_address(&hub->connection);351 usb_log_error("failed to clear port reset feature\n"); 352 usb_hub_release_default_address(hub); 420 353 return; 421 354 } … … 430 363 &new_device_pipe, 431 364 &new_device_connection); 432 /// \TODO get highspeed info 433 usb_speed_t speed = isLowSpeed?USB_SPEED_LOW:USB_SPEED_FULL; 434 365 usb_endpoint_pipe_probe_default_control(&new_device_pipe); 435 366 436 367 /* Request address from host controller. */ 437 368 usb_address_t new_device_address = usb_hc_request_address( 438 369 &hub->connection, 439 speed /// \TODO fullspeed??370 speed 440 371 ); 441 372 if (new_device_address < 0) { 442 dprintf(USB_LOG_LEVEL_ERROR, "failed to get free USB address");373 usb_log_error("failed to get free USB address\n"); 443 374 opResult = new_device_address; 444 usb_h c_release_default_address(&hub->connection);445 return; 446 } 447 dprintf(USB_LOG_LEVEL_INFO, "setting new address %d",new_device_address);375 usb_hub_release_default_address(hub); 376 return; 377 } 378 usb_log_info("setting new address %d\n",new_device_address); 448 379 //opResult = usb_drv_req_set_address(hc, USB_ADDRESS_DEFAULT, 449 380 // new_device_address); … … 452 383 usb_endpoint_pipe_end_session(&new_device_pipe); 453 384 if (opResult != EOK) { 454 dprintf(USB_LOG_LEVEL_ERROR, 455 "could not set address for new device %d",opResult); 456 usb_hc_release_default_address(&hub->connection); 385 usb_log_error("could not set address for new device %d\n",opResult); 386 usb_hub_release_default_address(hub); 457 387 return; 458 388 } … … 460 390 461 391 //opResult = usb_hub_release_default_address(hc); 462 opResult = usb_h c_release_default_address(&hub->connection);392 opResult = usb_hub_release_default_address(hub); 463 393 if(opResult!=EOK){ 464 394 return; … … 468 398 //?? 469 399 opResult = usb_device_register_child_in_devman(new_device_address, 470 hub->connection.hc_handle, hub-> device, &child_handle,400 hub->connection.hc_handle, hub->usb_device->ddf_dev, &child_handle, 471 401 NULL, NULL, NULL); 472 402 473 403 if (opResult != EOK) { 474 dprintf(USB_LOG_LEVEL_ERROR, 475 "could not start driver for new device %d",opResult); 404 usb_log_error("could not start driver for new device %d\n",opResult); 476 405 return; 477 406 } … … 484 413 &hub->attached_devs[port]); 485 414 if (opResult != EOK) { 486 dprintf(USB_LOG_LEVEL_ERROR, 487 "could not assign address of device in hcd %d",opResult); 488 return; 489 } 490 dprintf(USB_LOG_LEVEL_INFO, "new device address %d, handle %zu", 415 usb_log_error("could not assign address of device in hcd %d\n",opResult); 416 return; 417 } 418 usb_log_info("new device address %d, handle %zu\n", 491 419 new_device_address, child_handle); 492 420 … … 501 429 static void usb_hub_removed_device( 502 430 usb_hub_info_t * hub,uint16_t port) { 503 //usb_device_request_setup_packet_t request; 504 int opResult; 505 431 432 int opResult = usb_hub_clear_port_feature(hub->control_pipe, 433 port, USB_HUB_FEATURE_C_PORT_CONNECTION); 434 if(opResult != EOK){ 435 usb_log_warning("could not clear port-change-connection flag\n"); 436 } 506 437 /** \TODO remove device from device manager - not yet implemented in 507 438 * devide manager … … 510 441 //close address 511 442 if(hub->attached_devs[port].address!=0){ 512 / /opResult = usb_drv_release_address(hc,hub->attached_devs[port].address);443 /*uncomment this code to use it when DDF allows device removal 513 444 opResult = usb_hc_unregister_device( 514 445 &hub->connection, hub->attached_devs[port].address); … … 519 450 hub->attached_devs[port].address = 0; 520 451 hub->attached_devs[port].handle = 0; 452 */ 521 453 }else{ 522 dprintf(USB_LOG_LEVEL_WARNING, "this is strange, disconnected device had no address");454 usb_log_warning("this is strange, disconnected device had no address\n"); 523 455 //device was disconnected before it`s port was reset - return default address 524 //usb_drv_release_default_address(hc); 525 usb_hc_release_default_address(&hub->connection); 526 } 527 } 528 529 530 /** 531 *Process over current condition on port. 456 usb_hub_release_default_address(hub); 457 } 458 } 459 460 461 /** 462 * Process over current condition on port. 532 463 * 533 464 * Turn off the power on the port. … … 539 470 uint16_t port){ 540 471 int opResult; 541 opResult = usb_hub_clear_port_feature( &hub->endpoints.control,472 opResult = usb_hub_clear_port_feature(hub->control_pipe, 542 473 port, USB_HUB_FEATURE_PORT_POWER); 543 474 if(opResult!=EOK){ 544 dprintf(USB_LOG_LEVEL_ERROR, "cannot power off port %d; %d",475 usb_log_error("cannot power off port %d; %d\n", 545 476 port, opResult); 546 477 } … … 555 486 static void usb_hub_process_interrupt(usb_hub_info_t * hub, 556 487 uint16_t port) { 557 dprintf(USB_LOG_LEVEL_DEBUG, "interrupt at port %d", port);488 usb_log_debug("interrupt at port %d\n", port); 558 489 //determine type of change 559 usb_endpoint_pipe_t *pipe = &hub->endpoints.control;490 usb_endpoint_pipe_t *pipe = hub->control_pipe; 560 491 561 492 int opResult; … … 574 505 ); 575 506 if (opResult != EOK) { 576 dprintf(USB_LOG_LEVEL_ERROR, "could not get port status");507 usb_log_error("could not get port status\n"); 577 508 return; 578 509 } 579 510 if (rcvd_size != sizeof (usb_port_status_t)) { 580 dprintf(USB_LOG_LEVEL_ERROR, "received status has incorrect size");511 usb_log_error("received status has incorrect size\n"); 581 512 return; 582 513 } 583 514 //something connected/disconnected 584 515 if (usb_port_connect_change(&status)) { 585 opResult = usb_hub_clear_port_feature(pipe,586 port, USB_HUB_FEATURE_C_PORT_CONNECTION);587 // TODO: check opResult588 516 if (usb_port_dev_connected(&status)) { 589 dprintf(USB_LOG_LEVEL_INFO, "some connection changed");590 usb_hub_init_add_device(hub, port );517 usb_log_info("some connection changed\n"); 518 usb_hub_init_add_device(hub, port, usb_port_speed(&status)); 591 519 } else { 592 520 usb_hub_removed_device(hub, port); … … 599 527 usb_hub_over_current(hub,port); 600 528 }else{ 601 dprintf(USB_LOG_LEVEL_INFO,602 "over current condition was auto-resolved on port %d",port);529 usb_log_info("over current condition was auto-resolved on port %d\n", 530 port); 603 531 } 604 532 } 605 533 //port reset 606 534 if (usb_port_reset_completed(&status)) { 607 dprintf(USB_LOG_LEVEL_INFO,"port reset complete");535 usb_log_info("port reset complete"); 608 536 if (usb_port_enabled(&status)) { 609 usb_hub_finalize_add_device(hub, port, usb_port_ low_speed(&status));537 usb_hub_finalize_add_device(hub, port, usb_port_speed(&status)); 610 538 } else { 611 dprintf(USB_LOG_LEVEL_WARNING, "port reset, but port still not enabled");539 usb_log_warning("port reset, but port still not enabled\n"); 612 540 } 613 541 } … … 618 546 usb_port_set_dev_connected(&status, false); 619 547 if (status>>16) { 620 dprintf(USB_LOG_LEVEL_INFO, "there was some unsupported change on port %d: %X",port,status);621 622 } 623 /// \TODO handle other changes548 usb_log_info("there was some unsupported change on port %d: %X\n", 549 port,status); 550 551 } 624 552 } 625 553 626 554 /** 627 555 * Check changes on particular hub 628 * @param hub_info_param 629 */ 630 void usb_hub_check_hub_changes(usb_hub_info_t * hub_info){ 556 * @param hub_info_param pointer to usb_hub_info_t structure 557 * @return error code if there is problem when initializing communication with 558 * hub, EOK otherwise 559 */ 560 int usb_hub_check_hub_changes(usb_hub_info_t * hub_info){ 631 561 int opResult; 632 opResult = usb_endpoint_pipe_start_session(&hub_info->endpoints.status_change); 562 opResult = usb_endpoint_pipe_start_session( 563 hub_info->status_change_pipe); 633 564 if(opResult != EOK){ 634 dprintf(USB_LOG_LEVEL_ERROR,635 "could not initialize communication for hub; %d",opResult);636 return ;565 usb_log_error("could not initialize communication for hub; %d\n", 566 opResult); 567 return opResult; 637 568 } 638 569 … … 648 579 */ 649 580 opResult = usb_endpoint_pipe_read( 650 &hub_info->endpoints.status_change,581 hub_info->status_change_pipe, 651 582 change_bitmap, byte_length, &actual_size 652 583 ); … … 654 585 if (opResult != EOK) { 655 586 free(change_bitmap); 656 dprintf(USB_LOG_LEVEL_WARNING, "something went wrong while getting status of hub");657 usb_endpoint_pipe_end_session( &hub_info->endpoints.status_change);658 return ;587 usb_log_warning("something went wrong while getting status of hub\n"); 588 usb_endpoint_pipe_end_session(hub_info->status_change_pipe); 589 return opResult; 659 590 } 660 591 unsigned int port; 661 opResult = usb_endpoint_pipe_start_session(&hub_info->endpoints.control); 662 if(opResult!=EOK){ 663 dprintf(USB_LOG_LEVEL_ERROR, "could not start control pipe session %d", 592 opResult = usb_endpoint_pipe_start_session(hub_info->control_pipe); 593 if(opResult!=EOK){ 594 usb_log_error("could not start control pipe session %d\n", opResult); 595 usb_endpoint_pipe_end_session(hub_info->status_change_pipe); 596 return opResult; 597 } 598 opResult = usb_hc_connection_open(&hub_info->connection); 599 if(opResult!=EOK){ 600 usb_log_error("could not start host controller session %d\n", 664 601 opResult); 665 usb_endpoint_pipe_end_session(&hub_info->endpoints.status_change); 666 return; 667 } 668 opResult = usb_hc_connection_open(&hub_info->connection); 669 if(opResult!=EOK){ 670 dprintf(USB_LOG_LEVEL_ERROR, "could not start host controller session %d", 671 opResult); 672 usb_endpoint_pipe_end_session(&hub_info->endpoints.control); 673 usb_endpoint_pipe_end_session(&hub_info->endpoints.status_change); 674 return; 602 usb_endpoint_pipe_end_session(hub_info->control_pipe); 603 usb_endpoint_pipe_end_session(hub_info->status_change_pipe); 604 return opResult; 675 605 } 676 606 … … 685 615 } 686 616 usb_hc_connection_close(&hub_info->connection); 687 usb_endpoint_pipe_end_session( &hub_info->endpoints.control);688 usb_endpoint_pipe_end_session( &hub_info->endpoints.status_change);617 usb_endpoint_pipe_end_session(hub_info->control_pipe); 618 usb_endpoint_pipe_end_session(hub_info->status_change_pipe); 689 619 free(change_bitmap); 620 return EOK; 690 621 } 691 622
Note:
See TracChangeset
for help on using the changeset viewer.