source: mainline/uspace/drv/usbhub/usbhub.c@ a9c7c6f

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since a9c7c6f was a9c7c6f, checked in by Matus Dekanek <smekideki@…>, 15 years ago

hub - non removable devices: more debug logging

  • Property mode set to 100644
File size: 22.0 KB
Line 
1/*
2 * Copyright (c) 2010 Matus Dekanek
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28/** @addtogroup drvusbhub
29 * @{
30 */
31/** @file
32 * @brief usb hub main functionality
33 */
34
35#include <ddf/driver.h>
36#include <bool.h>
37#include <errno.h>
38#include <str_error.h>
39
40#include <usb_iface.h>
41#include <usb/ddfiface.h>
42#include <usb/descriptor.h>
43#include <usb/recognise.h>
44#include <usb/request.h>
45#include <usb/classes/hub.h>
46#include <stdio.h>
47
48#include "usbhub.h"
49#include "usbhub_private.h"
50#include "port_status.h"
51#include "usb/usb.h"
52#include "usb/pipes.h"
53#include "usb/classes/classes.h"
54
55
56static void usb_hub_init_add_device(usb_hub_info_t * hub, uint16_t port,
57 usb_speed_t speed);
58
59static int usb_hub_trigger_connecting_non_removable_devices(
60 usb_hub_info_t * hub, usb_hub_descriptor_t * descriptor);
61
62/**
63 * control loop running in hub`s fibril
64 *
65 * Hub`s fibril periodically asks for changes on hub and if needded calls
66 * change handling routine.
67 * @warning currently hub driver asks for changes once a second
68 * @param hub_info_param hub representation pointer
69 * @return zero
70 */
71int usb_hub_control_loop(void * hub_info_param){
72 usb_hub_info_t * hub_info = (usb_hub_info_t*)hub_info_param;
73 int errorCode = EOK;
74
75 while(errorCode == EOK){
76 async_usleep(1000 * 1000 * 10 );/// \TODO proper number once
77 errorCode = usb_hub_check_hub_changes(hub_info);
78 }
79 usb_log_error("something in ctrl loop went wrong, errno %d\n",errorCode);
80
81 return 0;
82}
83
84
85//*********************************************
86//
87// hub driver code, initialization
88//
89//*********************************************
90
91/**
92 * create usb_hub_info_t structure
93 *
94 * Does only basic copying of known information into new structure.
95 * @param usb_dev usb device structure
96 * @return basic usb_hub_info_t structure
97 */
98static usb_hub_info_t * usb_hub_info_create(usb_device_t * usb_dev) {
99 usb_hub_info_t * result = usb_new(usb_hub_info_t);
100 if(!result) return NULL;
101 result->usb_device = usb_dev;
102 result->status_change_pipe = usb_dev->pipes[0].pipe;
103 result->control_pipe = &usb_dev->ctrl_pipe;
104 result->is_default_address_used = false;
105 return result;
106}
107
108/**
109 * Load hub-specific information into hub_info structure and process if needed
110 *
111 * Particularly read port count and initialize structure holding port
112 * information. If there are non-removable devices, start initializing them.
113 * This function is hub-specific and should be run only after the hub is
114 * configured using usb_hub_set_configuration function.
115 * @param hub_info hub representation
116 * @return error code
117 */
118static int usb_hub_process_hub_specific_info(usb_hub_info_t * hub_info){
119 // get hub descriptor
120 usb_log_debug("creating serialized descriptor\n");
121 void * serialized_descriptor = malloc(USB_HUB_MAX_DESCRIPTOR_SIZE);
122 usb_hub_descriptor_t * descriptor;
123
124 /* this was one fix of some bug, should not be needed anymore
125 * these lines allow to reset hub once more, it can be used as
126 * brute-force initialization for non-removable devices
127 int opResult = usb_request_set_configuration(&result->endpoints.control, 1);
128 if(opResult!=EOK){
129 usb_log_error("could not set default configuration, errno %d",opResult);
130 return opResult;
131 }
132 */
133 size_t received_size;
134 int opResult = usb_request_get_descriptor(&hub_info->usb_device->ctrl_pipe,
135 USB_REQUEST_TYPE_CLASS, USB_REQUEST_RECIPIENT_DEVICE,
136 USB_DESCTYPE_HUB,
137 0, 0, serialized_descriptor,
138 USB_HUB_MAX_DESCRIPTOR_SIZE, &received_size);
139
140 if (opResult != EOK) {
141 usb_log_error("failed when receiving hub descriptor, badcode = %d\n",
142 opResult);
143 free(serialized_descriptor);
144 return opResult;
145 }
146 usb_log_debug2("deserializing descriptor\n");
147 descriptor = usb_deserialize_hub_desriptor(serialized_descriptor);
148 if(descriptor==NULL){
149 usb_log_warning("could not deserialize descriptor \n");
150 return opResult;
151 }
152 usb_log_debug("setting port count to %d\n",descriptor->ports_count);
153 hub_info->port_count = descriptor->ports_count;
154 hub_info->attached_devs = (usb_hc_attached_device_t*)
155 malloc((hub_info->port_count+1) * sizeof(usb_hc_attached_device_t));
156 int i;
157 for(i=0;i<hub_info->port_count+1;++i){
158 hub_info->attached_devs[i].handle=0;
159 hub_info->attached_devs[i].address=0;
160 }
161 //handle non-removable devices
162 usb_hub_trigger_connecting_non_removable_devices(hub_info, descriptor);
163 usb_log_debug2("freeing data\n");
164 free(serialized_descriptor);
165 free(descriptor->devices_removable);
166 free(descriptor);
167 return EOK;
168}
169/**
170 * Set configuration of hub
171 *
172 * Check whether there is at least one configuration and sets the first one.
173 * This function should be run prior to running any hub-specific action.
174 * @param hub_info hub representation
175 * @return error code
176 */
177static int usb_hub_set_configuration(usb_hub_info_t * hub_info){
178 //device descriptor
179 usb_standard_device_descriptor_t *std_descriptor
180 = &hub_info->usb_device->descriptors.device;
181 usb_log_debug("hub has %d configurations\n",
182 std_descriptor->configuration_count);
183 if(std_descriptor->configuration_count<1){
184 usb_log_error("there are no configurations available\n");
185 return EINVAL;
186 }
187
188 usb_standard_configuration_descriptor_t *config_descriptor
189 = (usb_standard_configuration_descriptor_t *)
190 hub_info->usb_device->descriptors.configuration;
191
192 /* Set configuration. */
193 int opResult = usb_request_set_configuration(
194 &hub_info->usb_device->ctrl_pipe,
195 config_descriptor->configuration_number);
196
197 if (opResult != EOK) {
198 usb_log_error("Failed to set hub configuration: %s.\n",
199 str_error(opResult));
200 return opResult;
201 }
202 usb_log_debug("\tused configuration %d\n",
203 config_descriptor->configuration_number);
204
205 return EOK;
206}
207
208/**
209 * Initialize hub device driver fibril
210 *
211 * Creates hub representation and fibril that periodically checks hub`s status.
212 * Hub representation is passed to the fibril.
213 * @param usb_dev generic usb device information
214 * @return error code
215 */
216int usb_hub_add_device(usb_device_t * usb_dev){
217 if(!usb_dev) return EINVAL;
218 usb_hub_info_t * hub_info = usb_hub_info_create(usb_dev);
219 //create hc connection
220 usb_log_debug("Initializing USB wire abstraction.\n");
221 int opResult = usb_hc_connection_initialize_from_device(
222 &hub_info->connection,
223 hub_info->usb_device->ddf_dev);
224 if(opResult != EOK){
225 usb_log_error("could not initialize connection to device, errno %d\n",
226 opResult);
227 free(hub_info);
228 return opResult;
229 }
230
231 usb_pipe_start_session(hub_info->control_pipe);
232 //set hub configuration
233 opResult = usb_hub_set_configuration(hub_info);
234 if(opResult!=EOK){
235 usb_log_error("could not set hub configuration, errno %d\n",opResult);
236 free(hub_info);
237 return opResult;
238 }
239 //get port count and create attached_devs
240 opResult = usb_hub_process_hub_specific_info(hub_info);
241 if(opResult!=EOK){
242 usb_log_error("could not set hub configuration, errno %d\n",opResult);
243 free(hub_info);
244 return opResult;
245 }
246 usb_pipe_end_session(hub_info->control_pipe);
247
248
249 /// \TODO what is this?
250 usb_log_debug("Creating `hub' function.\n");
251 ddf_fun_t *hub_fun = ddf_fun_create(hub_info->usb_device->ddf_dev,
252 fun_exposed, "hub");
253 assert(hub_fun != NULL);
254 hub_fun->ops = NULL;
255
256 int rc = ddf_fun_bind(hub_fun);
257 assert(rc == EOK);
258 rc = ddf_fun_add_to_class(hub_fun, "hub");
259 assert(rc == EOK);
260
261 //create fibril for the hub control loop
262 fid_t fid = fibril_create(usb_hub_control_loop, hub_info);
263 if (fid == 0) {
264 usb_log_error("failed to start monitoring fibril for new hub.\n");
265 return ENOMEM;
266 }
267 fibril_add_ready(fid);
268 usb_log_debug("Hub fibril created.\n");
269
270 usb_log_info("Controlling hub `%s' (%d ports).\n",
271 hub_info->usb_device->ddf_dev->name, hub_info->port_count);
272 return EOK;
273}
274
275
276//*********************************************
277//
278// hub driver code, main loop and port handling
279//
280//*********************************************
281
282/**
283 * triggers actions to connect non0removable devices
284 *
285 * This will trigger operations leading to activated non-removable device.
286 * Control pipe of the hub must be open fo communication.
287 * @param hub hub representation
288 * @param descriptor usb hub descriptor
289 * @return error code
290 */
291static int usb_hub_trigger_connecting_non_removable_devices(usb_hub_info_t * hub,
292 usb_hub_descriptor_t * descriptor)
293{
294 usb_log_info("attaching non-removable devices(if any)\n");
295 usb_device_request_setup_packet_t request;
296 int opResult;
297 size_t rcvd_size;
298 usb_port_status_t status;
299 uint8_t * non_removable_dev_bitmap = descriptor->devices_removable;
300 int port;
301 for(port=1;port<=descriptor->ports_count;++port){
302 bool is_non_removable =
303 ((non_removable_dev_bitmap[port/8]) >> (port%8)) %2;
304 if(is_non_removable){
305 usb_log_debug("non-removable device on port %d\n",port);
306 usb_hub_set_port_status_request(&request, port);
307 opResult = usb_pipe_control_read(
308 hub->control_pipe,
309 &request, sizeof(usb_device_request_setup_packet_t),
310 &status, 4, &rcvd_size
311 );
312 if (opResult != EOK) {
313 usb_log_error("could not get port status of port %d errno:%d\n",
314 port, opResult);
315 return opResult;
316 }
317 //set the status change bit, so it will be noticed in driver loop
318 if(usb_port_dev_connected(&status)){
319 usb_hub_set_enable_port_feature_request(&request, port,
320 USB_HUB_FEATURE_C_PORT_CONNECTION);
321 opResult = usb_pipe_control_read(
322 hub->control_pipe,
323 &request, sizeof(usb_device_request_setup_packet_t),
324 &status, 4, &rcvd_size
325 );
326 if (opResult != EOK) {
327 usb_log_warning(
328 "could not set port change on port %d errno:%d\n",
329 port, opResult);
330 }
331 }
332 }
333 }
334 /// \TODO this is just a debug code
335 for(port=1;port<=descriptor->ports_count;++port){
336 bool is_non_removable =
337 ((non_removable_dev_bitmap[port/8]) >> (port%8)) %2;
338 if(is_non_removable){
339 usb_log_debug("port %d is non-removable\n",port);
340 usb_port_status_t status;
341 size_t rcvd_size;
342 usb_device_request_setup_packet_t request;
343 //int opResult;
344 usb_hub_set_port_status_request(&request, port);
345 //endpoint 0
346 opResult = usb_pipe_control_read(
347 hub->control_pipe,
348 &request, sizeof(usb_device_request_setup_packet_t),
349 &status, 4, &rcvd_size
350 );
351 if (opResult != EOK) {
352 usb_log_error("could not get port status %d\n",opResult);
353 }
354 if (rcvd_size != sizeof (usb_port_status_t)) {
355 usb_log_error("received status has incorrect size\n");
356 }
357 //something connected/disconnected
358 if (usb_port_connect_change(&status)) {
359 usb_log_debug("some connection changed\n");
360 }
361 usb_log_debug("status: %s\n",usb_debug_str_buffer(
362 (uint8_t *)&status,4,4));
363 }
364 }
365 return EOK;
366}
367
368
369/**
370 * release default address used by given hub
371 *
372 * Also unsets hub->is_default_address_used. Convenience wrapper function.
373 * @note hub->connection MUST be open for communication
374 * @param hub hub representation
375 * @return error code
376 */
377static int usb_hub_release_default_address(usb_hub_info_t * hub){
378 int opResult = usb_hc_release_default_address(&hub->connection);
379 if(opResult!=EOK){
380 usb_log_error("could not release default address, errno %d\n",opResult);
381 return opResult;
382 }
383 hub->is_default_address_used = false;
384 return EOK;
385}
386
387/**
388 * Reset the port with new device and reserve the default address.
389 * @param hub hub representation
390 * @param port port number, starting from 1
391 * @param speed transfer speed of attached device, one of low, full or high
392 */
393static void usb_hub_init_add_device(usb_hub_info_t * hub, uint16_t port,
394 usb_speed_t speed) {
395 //if this hub already uses default address, it cannot request it once more
396 if(hub->is_default_address_used) return;
397 usb_log_debug("some connection changed\n");
398 assert(hub->control_pipe->hc_phone);
399 int opResult = usb_hub_clear_port_feature(hub->control_pipe,
400 port, USB_HUB_FEATURE_C_PORT_CONNECTION);
401 if(opResult != EOK){
402 usb_log_warning("could not clear port-change-connection flag\n");
403 }
404 usb_device_request_setup_packet_t request;
405
406 //get default address
407 opResult = usb_hc_reserve_default_address(&hub->connection, speed);
408
409 if (opResult != EOK) {
410 usb_log_warning("cannot assign default address, it is probably used %d\n",
411 opResult);
412 return;
413 }
414 hub->is_default_address_used = true;
415 //reset port
416 usb_hub_set_reset_port_request(&request, port);
417 opResult = usb_pipe_control_write(
418 hub->control_pipe,
419 &request,sizeof(usb_device_request_setup_packet_t),
420 NULL, 0
421 );
422 if (opResult != EOK) {
423 usb_log_error("something went wrong when reseting a port %d\n",opResult);
424 usb_hub_release_default_address(hub);
425 }
426 return;
427}
428
429/**
430 * Finalize adding new device after port reset
431 *
432 * Set device`s address and start it`s driver.
433 * @param hub hub representation
434 * @param port port number, starting from 1
435 * @param speed transfer speed of attached device, one of low, full or high
436 */
437static void usb_hub_finalize_add_device( usb_hub_info_t * hub,
438 uint16_t port, usb_speed_t speed) {
439
440 int opResult;
441 usb_log_debug("finalizing add device\n");
442 opResult = usb_hub_clear_port_feature(hub->control_pipe,
443 port, USB_HUB_FEATURE_C_PORT_RESET);
444
445 if (opResult != EOK) {
446 usb_log_error("failed to clear port reset feature\n");
447 usb_hub_release_default_address(hub);
448 return;
449 }
450 //create connection to device
451 usb_pipe_t new_device_pipe;
452 usb_device_connection_t new_device_connection;
453 usb_device_connection_initialize_on_default_address(
454 &new_device_connection,
455 &hub->connection
456 );
457 usb_pipe_initialize_default_control(
458 &new_device_pipe,
459 &new_device_connection);
460 usb_pipe_probe_default_control(&new_device_pipe);
461
462 /* Request address from host controller. */
463 usb_address_t new_device_address = usb_hc_request_address(
464 &hub->connection,
465 speed
466 );
467 if (new_device_address < 0) {
468 usb_log_error("failed to get free USB address\n");
469 opResult = new_device_address;
470 usb_hub_release_default_address(hub);
471 return;
472 }
473 usb_log_debug("setting new address %d\n",new_device_address);
474 //opResult = usb_drv_req_set_address(hc, USB_ADDRESS_DEFAULT,
475 // new_device_address);
476 usb_pipe_start_session(&new_device_pipe);
477 opResult = usb_request_set_address(&new_device_pipe,new_device_address);
478 usb_pipe_end_session(&new_device_pipe);
479 if (opResult != EOK) {
480 usb_log_error("could not set address for new device %d\n",opResult);
481 usb_hub_release_default_address(hub);
482 return;
483 }
484
485 //opResult = usb_hub_release_default_address(hc);
486 opResult = usb_hub_release_default_address(hub);
487 if(opResult!=EOK){
488 return;
489 }
490
491 devman_handle_t child_handle;
492 //??
493 opResult = usb_device_register_child_in_devman(new_device_address,
494 hub->connection.hc_handle, hub->usb_device->ddf_dev, &child_handle,
495 NULL, NULL, NULL);
496
497 if (opResult != EOK) {
498 usb_log_error("could not start driver for new device %d\n",opResult);
499 return;
500 }
501 hub->attached_devs[port].handle = child_handle;
502 hub->attached_devs[port].address = new_device_address;
503
504 //opResult = usb_drv_bind_address(hc, new_device_address, child_handle);
505 opResult = usb_hc_register_device(
506 &hub->connection,
507 &hub->attached_devs[port]);
508 if (opResult != EOK) {
509 usb_log_error("could not assign address of device in hcd %d\n",opResult);
510 return;
511 }
512 usb_log_info("Detected new device on `%s' (port %d), " \
513 "address %d (handle %llu).\n",
514 hub->usb_device->ddf_dev->name, (int) port,
515 new_device_address, child_handle);
516}
517
518/**
519 * routine called when a device on port has been removed
520 *
521 * If the device on port had default address, it releases default address.
522 * Otherwise does not do anything, because DDF does not allow to remove device
523 * from it`s device tree.
524 * @param hub hub representation
525 * @param port port number, starting from 1
526 */
527static void usb_hub_removed_device(
528 usb_hub_info_t * hub,uint16_t port) {
529
530 int opResult = usb_hub_clear_port_feature(hub->control_pipe,
531 port, USB_HUB_FEATURE_C_PORT_CONNECTION);
532 if(opResult != EOK){
533 usb_log_warning("could not clear port-change-connection flag\n");
534 }
535 /** \TODO remove device from device manager - not yet implemented in
536 * devide manager
537 */
538
539 //close address
540 if(hub->attached_devs[port].address!=0){
541 /*uncomment this code to use it when DDF allows device removal
542 opResult = usb_hc_unregister_device(
543 &hub->connection, hub->attached_devs[port].address);
544 if(opResult != EOK) {
545 dprintf(USB_LOG_LEVEL_WARNING, "could not release address of " \
546 "removed device: %d", opResult);
547 }
548 hub->attached_devs[port].address = 0;
549 hub->attached_devs[port].handle = 0;
550 */
551 }else{
552 usb_log_warning("this is strange, disconnected device had no address\n");
553 //device was disconnected before it`s port was reset - return default address
554 usb_hub_release_default_address(hub);
555 }
556}
557
558
559/**
560 * Process over current condition on port.
561 *
562 * Turn off the power on the port.
563 *
564 * @param hub hub representation
565 * @param port port number, starting from 1
566 */
567static void usb_hub_over_current( usb_hub_info_t * hub,
568 uint16_t port){
569 int opResult;
570 opResult = usb_hub_clear_port_feature(hub->control_pipe,
571 port, USB_HUB_FEATURE_PORT_POWER);
572 if(opResult!=EOK){
573 usb_log_error("cannot power off port %d; %d\n",
574 port, opResult);
575 }
576}
577
578/**
579 * Process interrupts on given hub port
580 *
581 * Accepts connection, over current and port reset change.
582 * @param hub hub representation
583 * @param port port number, starting from 1
584 */
585static void usb_hub_process_interrupt(usb_hub_info_t * hub,
586 uint16_t port) {
587 usb_log_debug("interrupt at port %d\n", port);
588 //determine type of change
589 usb_pipe_t *pipe = hub->control_pipe;
590
591 int opResult;
592
593 usb_port_status_t status;
594 size_t rcvd_size;
595 usb_device_request_setup_packet_t request;
596 //int opResult;
597 usb_hub_set_port_status_request(&request, port);
598 //endpoint 0
599
600 opResult = usb_pipe_control_read(
601 pipe,
602 &request, sizeof(usb_device_request_setup_packet_t),
603 &status, 4, &rcvd_size
604 );
605 if (opResult != EOK) {
606 usb_log_error("could not get port status\n");
607 return;
608 }
609 if (rcvd_size != sizeof (usb_port_status_t)) {
610 usb_log_error("received status has incorrect size\n");
611 return;
612 }
613 //something connected/disconnected
614 if (usb_port_connect_change(&status)) {
615 if (usb_port_dev_connected(&status)) {
616 usb_log_debug("some connection changed\n");
617 usb_hub_init_add_device(hub, port, usb_port_speed(&status));
618 } else {
619 usb_hub_removed_device(hub, port);
620 }
621 }
622 //over current
623 if (usb_port_overcurrent_change(&status)) {
624 //check if it was not auto-resolved
625 if(usb_port_over_current(&status)){
626 usb_hub_over_current(hub,port);
627 }else{
628 usb_log_debug("over current condition was auto-resolved on port %d\n",
629 port);
630 }
631 }
632 //port reset
633 if (usb_port_reset_completed(&status)) {
634 usb_log_debug("port reset complete\n");
635 if (usb_port_enabled(&status)) {
636 usb_hub_finalize_add_device(hub, port, usb_port_speed(&status));
637 } else {
638 usb_log_warning("port reset, but port still not enabled\n");
639 }
640 }
641
642 usb_port_set_connect_change(&status, false);
643 usb_port_set_reset(&status, false);
644 usb_port_set_reset_completed(&status, false);
645 usb_port_set_dev_connected(&status, false);
646 if (status>>16) {
647 usb_log_info("there was some unsupported change on port %d: %X\n",
648 port,status);
649
650 }
651}
652
653/**
654 * check changes on hub
655 *
656 * Handles changes on each port with a status change.
657 * @param hub_info hub representation
658 * @return error code
659 */
660int usb_hub_check_hub_changes(usb_hub_info_t * hub_info){
661 int opResult;
662 opResult = usb_pipe_start_session(
663 hub_info->status_change_pipe);
664 if(opResult != EOK){
665 usb_log_error("could not initialize communication for hub; %d\n",
666 opResult);
667 return opResult;
668 }
669
670 size_t port_count = hub_info->port_count;
671
672 /// FIXME: count properly
673 size_t byte_length = ((port_count+1) / 8) + 1;
674 void *change_bitmap = malloc(byte_length);
675 size_t actual_size;
676
677 /*
678 * Send the request.
679 */
680 opResult = usb_pipe_read(
681 hub_info->status_change_pipe,
682 change_bitmap, byte_length, &actual_size
683 );
684
685 if (opResult != EOK) {
686 free(change_bitmap);
687 usb_log_warning("something went wrong while getting status of hub\n");
688 usb_pipe_end_session(hub_info->status_change_pipe);
689 return opResult;
690 }
691 unsigned int port;
692 opResult = usb_pipe_start_session(hub_info->control_pipe);
693 if(opResult!=EOK){
694 usb_log_error("could not start control pipe session %d\n", opResult);
695 usb_pipe_end_session(hub_info->status_change_pipe);
696 return opResult;
697 }
698 opResult = usb_hc_connection_open(&hub_info->connection);
699 if(opResult!=EOK){
700 usb_log_error("could not start host controller session %d\n",
701 opResult);
702 usb_pipe_end_session(hub_info->control_pipe);
703 usb_pipe_end_session(hub_info->status_change_pipe);
704 return opResult;
705 }
706
707 ///todo, opresult check, pre obe konekce
708 for (port = 1; port < port_count+1; ++port) {
709 bool interrupt =
710 (((uint8_t*) change_bitmap)[port / 8] >> (port % 8)) % 2;
711 if (interrupt) {
712 usb_hub_process_interrupt(
713 hub_info, port);
714 }
715 }
716 usb_hc_connection_close(&hub_info->connection);
717 usb_pipe_end_session(hub_info->control_pipe);
718 usb_pipe_end_session(hub_info->status_change_pipe);
719 free(change_bitmap);
720 return EOK;
721}
722
723
724
725/**
726 * @}
727 */
Note: See TracBrowser for help on using the repository browser.