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

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since dde8ca4 was d70e0a3c, checked in by Vojtech Horky <vojtechhorky@…>, 14 years ago

Allocating "get full config desc" put into action

Yes, all that removed code is now replaced with a single function.
And yes, it was the same in all drivers.

  • Property mode set to 100644
File size: 20.1 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
55static ddf_dev_ops_t hub_device_ops = {
56 .interfaces[USB_DEV_IFACE] = &usb_iface_hub_impl
57};
58
59/** Hub status-change endpoint description
60 *
61 * For more see usb hub specification in 11.15.1 of
62 */
63static 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 = 0
70};
71
72int usb_hub_control_loop(void * hub_info_param){
73 usb_hub_info_t * hub_info = (usb_hub_info_t*)hub_info_param;
74 while(true){
75 usb_hub_check_hub_changes(hub_info);
76 async_usleep(1000 * 1000 );/// \TODO proper number once
77 }
78 return 0;
79}
80
81
82//*********************************************
83//
84// hub driver code, initialization
85//
86//*********************************************
87
88/**
89 * Initialize connnections to host controller, device, and device
90 * control endpoint
91 * @param hub
92 * @param device
93 * @return
94 */
95static 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 */
129static int usb_hub_process_configuration_descriptors(
130 usb_hub_info_t * hub){
131 if(hub==NULL) {
132 return EINVAL;
133 }
134 int opResult;
135
136 //device descriptor
137 usb_standard_device_descriptor_t std_descriptor;
138 opResult = usb_request_get_device_descriptor(&hub->endpoints.control,
139 &std_descriptor);
140 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",
145 std_descriptor.configuration_count);
146 if(std_descriptor.configuration_count<1){
147 dprintf(USB_LOG_LEVEL_ERROR, "THERE ARE NO CONFIGURATIONS AVAILABLE");
148 //shouldn`t I return?
149 }
150
151 /* Retrieve full configuration descriptor. */
152 uint8_t *descriptors = NULL;
153 size_t descriptors_size = 0;
154 opResult = usb_request_get_full_configuration_descriptor_alloc(
155 &hub->endpoints.control, 0,
156 (void **) &descriptors, &descriptors_size);
157 if (opResult != EOK) {
158 usb_log_error("Could not get configuration descriptor: %s.\n",
159 str_error(opResult));
160 return opResult;
161 }
162 usb_standard_configuration_descriptor_t *config_descriptor
163 = (usb_standard_configuration_descriptor_t *) descriptors;
164
165 /* Set configuration. */
166 opResult = usb_request_set_configuration(&hub->endpoints.control,
167 config_descriptor->configuration_number);
168
169 if (opResult != EOK) {
170 usb_log_error("Failed to set hub configuration: %s.\n",
171 str_error(opResult));
172 return opResult;
173 }
174 dprintf(USB_LOG_LEVEL_DEBUG, "\tused configuration %d",
175 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 free(descriptors);
202 return EOK;
203
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 */
212usb_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_get_descriptor(&result->endpoints.control,
236 USB_REQUEST_TYPE_CLASS, USB_REQUEST_RECIPIENT_DEVICE,
237 USB_DESCTYPE_HUB,
238 0, 0, serialized_descriptor,
239 USB_HUB_MAX_DESCRIPTOR_SIZE, &received_size);
240 usb_endpoint_pipe_end_session(&result->endpoints.control);
241
242 if (opResult != EOK) {
243 dprintf(USB_LOG_LEVEL_ERROR, "failed when receiving hub descriptor, badcode = %d",opResult);
244 free(serialized_descriptor);
245 return result;
246 }
247 dprintf(USB_LOG_LEVEL_DEBUG2, "deserializing descriptor");
248 descriptor = usb_deserialize_hub_desriptor(serialized_descriptor);
249 if(descriptor==NULL){
250 dprintf(USB_LOG_LEVEL_WARNING, "could not deserialize descriptor ");
251 result->port_count = 1;///\TODO this code is only for debug!!!
252 return result;
253 }
254
255 dprintf(USB_LOG_LEVEL_INFO, "setting port count to %d",descriptor->ports_count);
256 result->port_count = descriptor->ports_count;
257 result->attached_devs = (usb_hc_attached_device_t*)
258 malloc((result->port_count+1) * sizeof(usb_hc_attached_device_t));
259 int i;
260 for(i=0;i<result->port_count+1;++i){
261 result->attached_devs[i].handle=0;
262 result->attached_devs[i].address=0;
263 }
264 dprintf(USB_LOG_LEVEL_DEBUG2, "freeing data");
265 free(serialized_descriptor);
266 free(descriptor->devices_removable);
267 free(descriptor);
268
269 //finish
270
271 dprintf(USB_LOG_LEVEL_INFO, "hub info created");
272
273 return result;
274}
275
276/**
277 * Create hub representation and add it into hub list
278 * @param dev
279 * @return
280 */
281int usb_add_hub_device(ddf_dev_t *dev) {
282 dprintf(USB_LOG_LEVEL_INFO, "add_hub_device(handle=%d)", (int) dev->handle);
283
284 //dev->ops = &hub_device_ops;
285 (void) hub_device_ops;
286
287 usb_hub_info_t * hub_info = usb_create_hub_info(dev);
288
289 int opResult;
290
291 //perform final configurations
292 usb_endpoint_pipe_start_session(&hub_info->endpoints.control);
293 // process descriptors
294 opResult = usb_hub_process_configuration_descriptors(hub_info);
295 if(opResult != EOK){
296 dprintf(USB_LOG_LEVEL_ERROR,"could not get condiguration descriptors, %d",
297 opResult);
298 return opResult;
299 }
300 //power ports
301 usb_device_request_setup_packet_t request;
302 int port;
303 for (port = 1; port < hub_info->port_count+1; ++port) {
304 usb_hub_set_power_port_request(&request, port);
305 opResult = usb_endpoint_pipe_control_write(&hub_info->endpoints.control,
306 &request,sizeof(usb_device_request_setup_packet_t), NULL, 0);
307 dprintf(USB_LOG_LEVEL_INFO, "powering port %d",port);
308 if (opResult != EOK) {
309 dprintf(USB_LOG_LEVEL_WARNING, "something went wrong when setting hub`s %dth port", port);
310 }
311 }
312 //ports powered, hub seems to be enabled
313 usb_endpoint_pipe_end_session(&hub_info->endpoints.control);
314
315 //add the hub to list
316 //is this needed now?
317 fibril_mutex_lock(&usb_hub_list_lock);
318 usb_lst_append(&usb_hub_list, hub_info);
319 fibril_mutex_unlock(&usb_hub_list_lock);
320 dprintf(USB_LOG_LEVEL_DEBUG, "hub info added to list");
321
322 dprintf(USB_LOG_LEVEL_DEBUG, "adding to ddf");
323 ddf_fun_t *hub_fun = ddf_fun_create(dev, fun_exposed, "hub");
324 assert(hub_fun != NULL);
325 hub_fun->ops = NULL;
326
327 int rc = ddf_fun_bind(hub_fun);
328 assert(rc == EOK);
329 rc = ddf_fun_add_to_class(hub_fun, "hub");
330 assert(rc == EOK);
331
332 fid_t fid = fibril_create(usb_hub_control_loop, hub_info);
333 if (fid == 0) {
334 dprintf(USB_LOG_LEVEL_ERROR,
335 ": failed to start monitoring fibril for new hub");
336 return ENOMEM;
337 }
338 fibril_add_ready(fid);
339
340 dprintf(USB_LOG_LEVEL_DEBUG, "hub fibril created");
341 //(void)hub_info;
342 //usb_hub_check_hub_changes();
343
344 dprintf(USB_LOG_LEVEL_INFO, "hub dev added");
345 //address is lost...
346 dprintf(USB_LOG_LEVEL_DEBUG, "\taddress %d, has %d ports ",
347 //hub_info->endpoints.control.,
348 hub_info->port_count);
349
350 return EOK;
351 //return ENOTSUP;
352}
353
354
355//*********************************************
356//
357// hub driver code, main loop
358//
359//*********************************************
360
361/**
362 * Reset the port with new device and reserve the default address.
363 * @param hc
364 * @param port
365 * @param target
366 */
367static void usb_hub_init_add_device(usb_hub_info_t * hub, uint16_t port) {
368 usb_device_request_setup_packet_t request;
369 int opResult;
370 dprintf(USB_LOG_LEVEL_INFO, "some connection changed");
371 assert(hub->endpoints.control.hc_phone);
372 //get default address
373 //opResult = usb_drv_reserve_default_address(hc);
374 opResult = usb_hc_reserve_default_address(&hub->connection, USB_SPEED_LOW);
375
376 if (opResult != EOK) {
377 dprintf(USB_LOG_LEVEL_WARNING,
378 "cannot assign default address, it is probably used %d",opResult);
379 return;
380 }
381 //reset port
382 usb_hub_set_reset_port_request(&request, port);
383 opResult = usb_endpoint_pipe_control_write(
384 &hub->endpoints.control,
385 &request,sizeof(usb_device_request_setup_packet_t),
386 NULL, 0
387 );
388 if (opResult != EOK) {
389 dprintf(USB_LOG_LEVEL_ERROR,
390 "something went wrong when reseting a port %d",opResult);
391 //usb_hub_release_default_address(hc);
392 usb_hc_release_default_address(&hub->connection);
393 }
394}
395
396/**
397 * Finalize adding new device after port reset
398 * @param hc
399 * @param port
400 * @param target
401 */
402static void usb_hub_finalize_add_device( usb_hub_info_t * hub,
403 uint16_t port, bool isLowSpeed) {
404
405 int opResult;
406 dprintf(USB_LOG_LEVEL_INFO, "finalizing add device");
407 opResult = usb_hub_clear_port_feature(&hub->endpoints.control,
408 port, USB_HUB_FEATURE_C_PORT_RESET);
409
410 if (opResult != EOK) {
411 dprintf(USB_LOG_LEVEL_ERROR, "failed to clear port reset feature");
412 usb_hc_release_default_address(&hub->connection);
413 return;
414 }
415 //create connection to device
416 usb_endpoint_pipe_t new_device_pipe;
417 usb_device_connection_t new_device_connection;
418 usb_device_connection_initialize_on_default_address(
419 &new_device_connection,
420 &hub->connection
421 );
422 usb_endpoint_pipe_initialize_default_control(
423 &new_device_pipe,
424 &new_device_connection);
425 /// \TODO get highspeed info
426 usb_speed_t speed = isLowSpeed?USB_SPEED_LOW:USB_SPEED_FULL;
427
428
429 /* Request address from host controller. */
430 usb_address_t new_device_address = usb_hc_request_address(
431 &hub->connection,
432 speed/// \TODO fullspeed??
433 );
434 if (new_device_address < 0) {
435 dprintf(USB_LOG_LEVEL_ERROR, "failed to get free USB address");
436 opResult = new_device_address;
437 usb_hc_release_default_address(&hub->connection);
438 return;
439 }
440 dprintf(USB_LOG_LEVEL_INFO, "setting new address %d",new_device_address);
441 //opResult = usb_drv_req_set_address(hc, USB_ADDRESS_DEFAULT,
442 // new_device_address);
443 usb_endpoint_pipe_start_session(&new_device_pipe);
444 opResult = usb_request_set_address(&new_device_pipe,new_device_address);
445 usb_endpoint_pipe_end_session(&new_device_pipe);
446 if (opResult != EOK) {
447 dprintf(USB_LOG_LEVEL_ERROR,
448 "could not set address for new device %d",opResult);
449 usb_hc_release_default_address(&hub->connection);
450 return;
451 }
452
453
454 //opResult = usb_hub_release_default_address(hc);
455 opResult = usb_hc_release_default_address(&hub->connection);
456 if(opResult!=EOK){
457 return;
458 }
459
460 devman_handle_t child_handle;
461 //??
462 opResult = usb_device_register_child_in_devman(new_device_address,
463 hub->connection.hc_handle, hub->device, &child_handle,
464 NULL, NULL, NULL);
465
466 if (opResult != EOK) {
467 dprintf(USB_LOG_LEVEL_ERROR,
468 "could not start driver for new device %d",opResult);
469 return;
470 }
471 hub->attached_devs[port].handle = child_handle;
472 hub->attached_devs[port].address = new_device_address;
473
474 //opResult = usb_drv_bind_address(hc, new_device_address, child_handle);
475 opResult = usb_hc_register_device(
476 &hub->connection,
477 &hub->attached_devs[port]);
478 if (opResult != EOK) {
479 dprintf(USB_LOG_LEVEL_ERROR,
480 "could not assign address of device in hcd %d",opResult);
481 return;
482 }
483 dprintf(USB_LOG_LEVEL_INFO, "new device address %d, handle %zu",
484 new_device_address, child_handle);
485
486}
487
488/**
489 * Unregister device address in hc
490 * @param hc
491 * @param port
492 * @param target
493 */
494static void usb_hub_removed_device(
495 usb_hub_info_t * hub,uint16_t port) {
496 //usb_device_request_setup_packet_t request;
497 int opResult;
498
499 /** \TODO remove device from device manager - not yet implemented in
500 * devide manager
501 */
502
503 //close address
504 if(hub->attached_devs[port].address!=0){
505 //opResult = usb_drv_release_address(hc,hub->attached_devs[port].address);
506 opResult = usb_hc_unregister_device(
507 &hub->connection, hub->attached_devs[port].address);
508 if(opResult != EOK) {
509 dprintf(USB_LOG_LEVEL_WARNING, "could not release address of " \
510 "removed device: %d", opResult);
511 }
512 hub->attached_devs[port].address = 0;
513 hub->attached_devs[port].handle = 0;
514 }else{
515 dprintf(USB_LOG_LEVEL_WARNING, "this is strange, disconnected device had no address");
516 //device was disconnected before it`s port was reset - return default address
517 //usb_drv_release_default_address(hc);
518 usb_hc_release_default_address(&hub->connection);
519 }
520}
521
522
523/**
524 *Process over current condition on port.
525 *
526 * Turn off the power on the port.
527 *
528 * @param hub
529 * @param port
530 */
531static void usb_hub_over_current( usb_hub_info_t * hub,
532 uint16_t port){
533 int opResult;
534 opResult = usb_hub_clear_port_feature(&hub->endpoints.control,
535 port, USB_HUB_FEATURE_PORT_POWER);
536 if(opResult!=EOK){
537 dprintf(USB_LOG_LEVEL_ERROR, "cannot power off port %d; %d",
538 port, opResult);
539 }
540}
541
542/**
543 * Process interrupts on given hub port
544 * @param hc
545 * @param port
546 * @param target
547 */
548static void usb_hub_process_interrupt(usb_hub_info_t * hub,
549 uint16_t port) {
550 dprintf(USB_LOG_LEVEL_DEBUG, "interrupt at port %d", port);
551 //determine type of change
552 usb_endpoint_pipe_t *pipe = &hub->endpoints.control;
553
554 int opResult;
555
556 usb_port_status_t status;
557 size_t rcvd_size;
558 usb_device_request_setup_packet_t request;
559 //int opResult;
560 usb_hub_set_port_status_request(&request, port);
561 //endpoint 0
562
563 opResult = usb_endpoint_pipe_control_read(
564 pipe,
565 &request, sizeof(usb_device_request_setup_packet_t),
566 &status, 4, &rcvd_size
567 );
568 if (opResult != EOK) {
569 dprintf(USB_LOG_LEVEL_ERROR, "could not get port status");
570 return;
571 }
572 if (rcvd_size != sizeof (usb_port_status_t)) {
573 dprintf(USB_LOG_LEVEL_ERROR, "received status has incorrect size");
574 return;
575 }
576 //something connected/disconnected
577 if (usb_port_connect_change(&status)) {
578 opResult = usb_hub_clear_port_feature(pipe,
579 port, USB_HUB_FEATURE_C_PORT_CONNECTION);
580 // TODO: check opResult
581 if (usb_port_dev_connected(&status)) {
582 dprintf(USB_LOG_LEVEL_INFO, "some connection changed");
583 usb_hub_init_add_device(hub, port);
584 } else {
585 usb_hub_removed_device(hub, port);
586 }
587 }
588 //over current
589 if (usb_port_overcurrent_change(&status)) {
590 //check if it was not auto-resolved
591 if(usb_port_over_current(&status)){
592 usb_hub_over_current(hub,port);
593 }else{
594 dprintf(USB_LOG_LEVEL_INFO,
595 "over current condition was auto-resolved on port %d",port);
596 }
597 }
598 //port reset
599 if (usb_port_reset_completed(&status)) {
600 dprintf(USB_LOG_LEVEL_INFO, "port reset complete");
601 if (usb_port_enabled(&status)) {
602 usb_hub_finalize_add_device(hub, port, usb_port_low_speed(&status));
603 } else {
604 dprintf(USB_LOG_LEVEL_WARNING, "port reset, but port still not enabled");
605 }
606 }
607
608 usb_port_set_connect_change(&status, false);
609 usb_port_set_reset(&status, false);
610 usb_port_set_reset_completed(&status, false);
611 usb_port_set_dev_connected(&status, false);
612 if (status>>16) {
613 dprintf(USB_LOG_LEVEL_INFO, "there was some unsupported change on port %d: %X",port,status);
614
615 }
616 /// \TODO handle other changes
617}
618
619/**
620 * Check changes on particular hub
621 * @param hub_info_param
622 */
623void usb_hub_check_hub_changes(usb_hub_info_t * hub_info){
624 int opResult;
625 opResult = usb_endpoint_pipe_start_session(&hub_info->endpoints.status_change);
626 if(opResult != EOK){
627 dprintf(USB_LOG_LEVEL_ERROR,
628 "could not initialize communication for hub; %d", opResult);
629 return;
630 }
631
632 size_t port_count = hub_info->port_count;
633
634 /// FIXME: count properly
635 size_t byte_length = ((port_count+1) / 8) + 1;
636 void *change_bitmap = malloc(byte_length);
637 size_t actual_size;
638
639 /*
640 * Send the request.
641 */
642 opResult = usb_endpoint_pipe_read(
643 &hub_info->endpoints.status_change,
644 change_bitmap, byte_length, &actual_size
645 );
646
647 if (opResult != EOK) {
648 free(change_bitmap);
649 dprintf(USB_LOG_LEVEL_WARNING, "something went wrong while getting status of hub");
650 usb_endpoint_pipe_end_session(&hub_info->endpoints.status_change);
651 return;
652 }
653 unsigned int port;
654 opResult = usb_endpoint_pipe_start_session(&hub_info->endpoints.control);
655 if(opResult!=EOK){
656 dprintf(USB_LOG_LEVEL_ERROR, "could not start control pipe session %d",
657 opResult);
658 usb_endpoint_pipe_end_session(&hub_info->endpoints.status_change);
659 return;
660 }
661 opResult = usb_hc_connection_open(&hub_info->connection);
662 if(opResult!=EOK){
663 dprintf(USB_LOG_LEVEL_ERROR, "could not start host controller session %d",
664 opResult);
665 usb_endpoint_pipe_end_session(&hub_info->endpoints.control);
666 usb_endpoint_pipe_end_session(&hub_info->endpoints.status_change);
667 return;
668 }
669
670 ///todo, opresult check, pre obe konekce
671 for (port = 1; port < port_count+1; ++port) {
672 bool interrupt =
673 (((uint8_t*) change_bitmap)[port / 8] >> (port % 8)) % 2;
674 if (interrupt) {
675 usb_hub_process_interrupt(
676 hub_info, port);
677 }
678 }
679 usb_hc_connection_close(&hub_info->connection);
680 usb_endpoint_pipe_end_session(&hub_info->endpoints.control);
681 usb_endpoint_pipe_end_session(&hub_info->endpoints.status_change);
682 free(change_bitmap);
683}
684
685
686
687/**
688 * @}
689 */
Note: See TracBrowser for help on using the repository browser.