source: mainline/uspace/drv/usbhub/usbhub.c@ 206f71a

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

Getting max_packet_size for default control pipe

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