Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/usbhub/usbhub.c

    r15b0432 r563fb40  
    3939
    4040#include <usb_iface.h>
    41 #include <usb/ddfiface.h>
     41#include <usb/usbdrv.h>
    4242#include <usb/descriptor.h>
    4343#include <usb/recognise.h>
    44 #include <usb/request.h>
     44#include <usb/devreq.h>
    4545#include <usb/classes/hub.h>
    4646
     
    4949#include "port_status.h"
    5050#include "usb/usb.h"
    51 #include "usb/pipes.h"
    52 #include "usb/classes/classes.h"
     51
     52static int iface_get_hc_handle(device_t *device, devman_handle_t *handle)
     53{
     54        return usb_hc_find(device->handle, handle);
     55}
     56
     57static usb_iface_t hub_usb_iface = {
     58        .get_hc_handle = iface_get_hc_handle
     59};
    5360
    5461static device_ops_t hub_device_ops = {
    55         .interfaces[USB_DEV_IFACE] = &usb_iface_hub_impl
     62        .interfaces[USB_DEV_IFACE] = &hub_usb_iface
    5663};
    57 
    58 /** Hub status-change endpoint description */
    59 static usb_endpoint_description_t status_change_endpoint_description = {
    60         .transfer_type = USB_TRANSFER_INTERRUPT,
    61         .direction = USB_DIRECTION_IN,
    62         .interface_class = USB_CLASS_HUB,
    63         .flags = 0
    64 };
    65 
    6664
    6765//*********************************************
     
    7169//*********************************************
    7270
    73 /**
    74  * Initialize connnections to host controller, device, and device
    75  * control endpoint
    76  * @param hub
    77  * @param device
    78  * @return
    79  */
    80 static int usb_hub_init_communication(usb_hub_info_t * hub){
    81         int opResult;
    82         opResult = usb_device_connection_initialize_from_device(
    83                         &hub->device_connection,
    84                         hub->device);
    85         if(opResult != EOK){
    86                 dprintf(USB_LOG_LEVEL_ERROR,
    87                                 "could not initialize connection to hc, errno %d",opResult);
    88                 return opResult;
    89         }
    90         opResult = usb_hc_connection_initialize_from_device(&hub->connection,
    91                         hub->device);
    92         if(opResult != EOK){
    93                 dprintf(USB_LOG_LEVEL_ERROR,
    94                                 "could not initialize connection to device, errno %d",opResult);
    95                 return opResult;
    96         }
    97         opResult = usb_endpoint_pipe_initialize_default_control(&hub->endpoints.control,
    98             &hub->device_connection);
    99         if(opResult != EOK){
    100                 dprintf(USB_LOG_LEVEL_ERROR,
    101                                 "could not initialize connection to device endpoint, errno %d",opResult);
    102         }
    103         return opResult;
    104 }
    105 
    106 /**
    107  * When entering this function, hub->endpoints.control should be active.
    108  * @param hub
    109  * @return
    110  */
    111 static int usb_hub_process_configuration_descriptors(
    112         usb_hub_info_t * hub){
    113         if(hub==NULL) {
    114                 return EINVAL;
    115         }
    116         int opResult;
    117        
    118         //device descriptor
    119         usb_standard_device_descriptor_t std_descriptor;
    120         opResult = usb_request_get_device_descriptor(&hub->endpoints.control,
    121             &std_descriptor);
    122         if(opResult!=EOK){
    123                 dprintf(USB_LOG_LEVEL_ERROR, "could not get device descriptor, %d",opResult);
    124                 return opResult;
    125         }
    126         dprintf(USB_LOG_LEVEL_INFO, "hub has %d configurations",
    127                         std_descriptor.configuration_count);
    128         if(std_descriptor.configuration_count<1){
    129                 dprintf(USB_LOG_LEVEL_ERROR, "THERE ARE NO CONFIGURATIONS AVAILABLE");
    130                 //shouldn`t I return?
    131         }
    132 
    133         //configuration descriptor
    134         /// \TODO check other configurations
    135         usb_standard_configuration_descriptor_t config_descriptor;
    136         opResult = usb_request_get_bare_configuration_descriptor(
    137             &hub->endpoints.control, 0,
    138         &config_descriptor);
    139         if(opResult!=EOK){
    140                 dprintf(USB_LOG_LEVEL_ERROR, "could not get configuration descriptor, %d",opResult);
    141                 return opResult;
    142         }
    143         //set configuration
    144         opResult = usb_request_set_configuration(&hub->endpoints.control,
    145                 config_descriptor.configuration_number);
    146 
    147         if (opResult != EOK) {
    148                 dprintf(USB_LOG_LEVEL_ERROR,
    149                                 "something went wrong when setting hub`s configuration, %d",
    150                                 opResult);
    151                 return opResult;
    152         }
    153         dprintf(USB_LOG_LEVEL_DEBUG, "\tused configuration %d",
    154                         config_descriptor.configuration_number);
    155 
    156         //full configuration descriptor
    157         size_t transferred = 0;
    158         uint8_t * descriptors = (uint8_t *)malloc(config_descriptor.total_length);
    159         if (descriptors == NULL) {
    160                 dprintf(USB_LOG_LEVEL_ERROR, "insufficient memory");
    161                 return ENOMEM;
    162         }
    163         opResult = usb_request_get_full_configuration_descriptor(&hub->endpoints.control,
    164             0, descriptors,
    165             config_descriptor.total_length, &transferred);
    166         if(opResult!=EOK){
    167                 free(descriptors);
    168                 dprintf(USB_LOG_LEVEL_ERROR,
    169                                 "could not get full configuration descriptor, %d",opResult);
    170                 return opResult;
    171         }
    172         if (transferred != config_descriptor.total_length) {
    173                 dprintf(USB_LOG_LEVEL_ERROR,
    174                                 "received incorrect full configuration descriptor");
    175                 return ELIMIT;
    176         }
    177 
    178         /**
    179          * Initialize the interrupt in endpoint.
    180          * \TODO this code should be checked...
    181          */
    182         usb_endpoint_mapping_t endpoint_mapping[1] = {
    183                 {
    184                         .pipe = &hub->endpoints.status_change,
    185                         .description = &status_change_endpoint_description,
    186                         .interface_no =
    187                             usb_device_get_assigned_interface(hub->device)
    188                 }
    189         };
    190         opResult = usb_endpoint_pipe_initialize_from_configuration(
    191             endpoint_mapping, 1,
    192             descriptors, config_descriptor.total_length,
    193             &hub->device_connection);
    194         if (opResult != EOK) {
    195                 dprintf(USB_LOG_LEVEL_ERROR,
    196                                 "Failed to initialize status change pipe: %s",
    197                     str_error(opResult));
    198                 return opResult;
    199         }
    200         if (!endpoint_mapping[0].present) {
    201                 dprintf(USB_LOG_LEVEL_ERROR,"Not accepting device, " \
    202                     "cannot understand what is happenning");
    203                 return EREFUSED;
    204         }
    205 
    206         free(descriptors);
    207         return EOK;
    208        
    209 
    210         // Initialize the interrupt(=status change) endpoint.
    211         /*usb_endpoint_pipe_initialize(
    212                 &result->endpoints->status_change,
    213                 &result->device_connection, );USB_TRANSFER_INTERRUPT
    214         USB_DIRECTION_IN*/
    215 
    216 }
    217 
    218 
    219 /**
    220  * Create hub representation from device information.
    221  * @param device
    222  * @return pointer to created structure or NULL in case of error
    223  */
    224 usb_hub_info_t * usb_create_hub_info(device_t * device) {
     71usb_hub_info_t * usb_create_hub_info(device_t * device, int hc) {
    22572        usb_hub_info_t* result = usb_new(usb_hub_info_t);
    226         result->device = device;
    227         int opResult;
    228         opResult = usb_hub_init_communication(result);
    229         if(opResult != EOK){
    230                 free(result);
    231                 return NULL;
    232         }
    233 
    23473        //result->device = device;
    23574        result->port_count = -1;
     75        /// \TODO is this correct? is the device stored?
    23676        result->device = device;
    23777
    238         //result->usb_device = usb_new(usb_hcd_attached_device_info_t);
    239         size_t received_size;
     78
     79        dprintf(USB_LOG_LEVEL_DEBUG, "phone to hc = %d", hc);
     80        if (hc < 0) {
     81                return result;
     82        }
     83        //get some hub info
     84        usb_address_t addr = usb_drv_get_my_address(hc, device);
     85        dprintf(USB_LOG_LEVEL_DEBUG, "address of newly created hub = %d", addr);
     86        /*if(addr<0){
     87                //return result;
     88
     89        }*/
     90
     91        result->address = addr;
    24092
    24193        // get hub descriptor
     94
    24295        dprintf(USB_LOG_LEVEL_DEBUG, "creating serialized descripton");
    24396        void * serialized_descriptor = malloc(USB_HUB_MAX_DESCRIPTOR_SIZE);
    24497        usb_hub_descriptor_t * descriptor;
     98        size_t received_size;
     99        int opResult;
    245100        dprintf(USB_LOG_LEVEL_DEBUG, "starting control transaction");
    246         usb_endpoint_pipe_start_session(&result->endpoints.control);
    247         opResult = usb_request_get_descriptor(&result->endpoints.control,
     101       
     102        opResult = usb_drv_req_get_descriptor(hc, addr,
    248103                        USB_REQUEST_TYPE_CLASS,
    249104                        USB_DESCTYPE_HUB, 0, 0, serialized_descriptor,
    250105                        USB_HUB_MAX_DESCRIPTOR_SIZE, &received_size);
    251         usb_endpoint_pipe_end_session(&result->endpoints.control);
    252106
    253107        if (opResult != EOK) {
     
    263117                return result;
    264118        }
    265 
    266        
    267119        dprintf(USB_LOG_LEVEL_INFO, "setting port count to %d",descriptor->ports_count);
    268120        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));
     121        result->attached_devs = (usb_hub_attached_device_t*)
     122            malloc((result->port_count+1) * sizeof(usb_hub_attached_device_t));
    271123        int i;
    272124        for(i=0;i<result->port_count+1;++i){
    273                 result->attached_devs[i].handle=0;
     125                result->attached_devs[i].devman_handle=0;
    274126                result->attached_devs[i].address=0;
    275127        }
     
    286138}
    287139
    288 /**
    289  * Create hub representation and add it into hub list
    290  * @param dev
    291  * @return
    292  */
    293140int usb_add_hub_device(device_t *dev) {
    294141        dprintf(USB_LOG_LEVEL_INFO, "add_hub_device(handle=%d)", (int) dev->handle);
    295142
     143        /*
     144         * We are some (probably deeply nested) hub.
     145         * Thus, assign our own operations and explore already
     146         * connected devices.
     147         */
    296148        dev->ops = &hub_device_ops;
    297149
    298         usb_hub_info_t * hub_info = usb_create_hub_info(dev);
    299 
    300         int opResult;
    301 
    302         //perform final configurations
    303         usb_endpoint_pipe_start_session(&hub_info->endpoints.control);
    304         // process descriptors
    305         opResult = usb_hub_process_configuration_descriptors(hub_info);
    306         if(opResult != EOK){
    307                 dprintf(USB_LOG_LEVEL_ERROR,"could not get condiguration descriptors, %d",
    308                                 opResult);
     150        //create the hub structure
     151        //get hc connection
     152        int hc = usb_drv_hc_connect_auto(dev, 0);
     153        if (hc < 0) {
     154                return hc;
     155        }
     156
     157        usb_hub_info_t * hub_info = usb_create_hub_info(dev, hc);
     158        int port;
     159        int opResult;
     160        usb_target_t target;
     161        target.address = hub_info->address;
     162        target.endpoint = 0;
     163
     164        //get configuration descriptor
     165        // this is not fully correct - there are more configurations
     166        // and all should be checked
     167        usb_standard_device_descriptor_t std_descriptor;
     168        opResult = usb_drv_req_get_device_descriptor(hc, target.address,
     169            &std_descriptor);
     170        if(opResult!=EOK){
     171                dprintf(USB_LOG_LEVEL_ERROR, "could not get device descriptor, %d",opResult);
    309172                return opResult;
    310173        }
    311         //power ports
     174        dprintf(USB_LOG_LEVEL_INFO, "hub has %d configurations",std_descriptor.configuration_count);
     175        if(std_descriptor.configuration_count<1){
     176                dprintf(USB_LOG_LEVEL_ERROR, "THERE ARE NO CONFIGURATIONS AVAILABLE");
     177                //shouldn`t I return?
     178        }
     179        /// \TODO check other configurations
     180        usb_standard_configuration_descriptor_t config_descriptor;
     181        opResult = usb_drv_req_get_bare_configuration_descriptor(hc,
     182        target.address, 0,
     183        &config_descriptor);
     184        if(opResult!=EOK){
     185                dprintf(USB_LOG_LEVEL_ERROR, "could not get configuration descriptor, %d",opResult);
     186                return opResult;
     187        }
     188        //set configuration
     189        opResult = usb_drv_req_set_configuration(hc, target.address,
     190    config_descriptor.configuration_number);
     191
     192        if (opResult != EOK) {
     193                dprintf(USB_LOG_LEVEL_ERROR, "something went wrong when setting hub`s configuration, %d", opResult);
     194        }
     195
    312196        usb_device_request_setup_packet_t request;
    313         int port;
    314197        for (port = 1; port < hub_info->port_count+1; ++port) {
    315198                usb_hub_set_power_port_request(&request, port);
    316                 opResult = usb_endpoint_pipe_control_write(&hub_info->endpoints.control,
    317                                 &request,sizeof(usb_device_request_setup_packet_t), NULL, 0);
     199                opResult = usb_drv_sync_control_write(hc, target, &request, NULL, 0);
    318200                dprintf(USB_LOG_LEVEL_INFO, "powering port %d",port);
    319201                if (opResult != EOK) {
     
    322204        }
    323205        //ports powered, hub seems to be enabled
    324         usb_endpoint_pipe_end_session(&hub_info->endpoints.control);
     206
     207        async_hangup(hc);
    325208
    326209        //add the hub to list
     
    332215        //(void)hub_info;
    333216        usb_hub_check_hub_changes();
     217
    334218       
     219
    335220        dprintf(USB_LOG_LEVEL_INFO, "hub dev added");
    336         //address is lost...
    337221        dprintf(USB_LOG_LEVEL_DEBUG, "\taddress %d, has %d ports ",
    338                         //hub_info->endpoints.control.,
     222                        hub_info->address,
    339223                        hub_info->port_count);
     224        dprintf(USB_LOG_LEVEL_DEBUG, "\tused configuration %d",config_descriptor.configuration_number);
    340225
    341226        return EOK;
     
    351236
    352237/**
     238 * Convenience function for releasing default address and writing debug info
     239 * (these few lines are used too often to be written again and again).
     240 * @param hc
     241 * @return
     242 */
     243inline static int usb_hub_release_default_address(int hc){
     244        int opResult;
     245        dprintf(USB_LOG_LEVEL_INFO, "releasing default address");
     246        opResult = usb_drv_release_default_address(hc);
     247        if (opResult != EOK) {
     248                dprintf(USB_LOG_LEVEL_WARNING, "failed to release default address");
     249        }
     250        return opResult;
     251}
     252
     253/**
    353254 * Reset the port with new device and reserve the default address.
    354255 * @param hc
     
    356257 * @param target
    357258 */
    358 static void usb_hub_init_add_device(usb_hub_info_t * hub, uint16_t port) {
     259static void usb_hub_init_add_device(int hc, uint16_t port, usb_target_t target) {
    359260        usb_device_request_setup_packet_t request;
    360261        int opResult;
    361262        dprintf(USB_LOG_LEVEL_INFO, "some connection changed");
    362         assert(hub->endpoints.control.hc_phone);
    363263        //get default address
    364         //opResult = usb_drv_reserve_default_address(hc);
    365         opResult = usb_hc_reserve_default_address(&hub->connection, USB_SPEED_LOW);
    366 
     264        opResult = usb_drv_reserve_default_address(hc);
    367265        if (opResult != EOK) {
    368266                dprintf(USB_LOG_LEVEL_WARNING, "cannot assign default address, it is probably used");
     
    371269        //reset port
    372270        usb_hub_set_reset_port_request(&request, port);
    373         opResult = usb_endpoint_pipe_control_write(
    374                         &hub->endpoints.control,
    375                         &request,sizeof(usb_device_request_setup_packet_t),
     271        opResult = usb_drv_sync_control_write(
     272                        hc, target,
     273                        &request,
    376274                        NULL, 0
    377275                        );
    378276        if (opResult != EOK) {
    379277                dprintf(USB_LOG_LEVEL_ERROR, "something went wrong when reseting a port");
    380                 //usb_hub_release_default_address(hc);
    381                 usb_hc_release_default_address(&hub->connection);
     278                usb_hub_release_default_address(hc);
    382279        }
    383280}
     
    390287 */
    391288static void usb_hub_finalize_add_device( usb_hub_info_t * hub,
    392                 uint16_t port) {
     289                int hc, uint16_t port, usb_target_t target) {
    393290
    394291        int opResult;
    395292        dprintf(USB_LOG_LEVEL_INFO, "finalizing add device");
    396         opResult = usb_hub_clear_port_feature(&hub->endpoints.control,
     293        opResult = usb_hub_clear_port_feature(hc, target.address,
    397294            port, USB_HUB_FEATURE_C_PORT_RESET);
    398 
    399295        if (opResult != EOK) {
    400296                dprintf(USB_LOG_LEVEL_ERROR, "failed to clear port reset feature");
    401                 usb_hc_release_default_address(&hub->connection);
    402                 return;
    403         }
    404         //create connection to device
    405         usb_endpoint_pipe_t new_device_pipe;
    406         usb_device_connection_t new_device_connection;
    407         usb_device_connection_initialize_on_default_address(
    408                         &new_device_connection,
    409                         &hub->connection
    410                         );
    411         usb_endpoint_pipe_initialize_default_control(
    412                         &new_device_pipe,
    413                         &new_device_connection);
    414         /// \TODO get highspeed info
    415 
    416 
    417 
    418 
    419 
    420         /* Request address from host controller. */
    421         usb_address_t new_device_address = usb_hc_request_address(
    422                         &hub->connection,
    423                         USB_SPEED_LOW/// \TODO fullspeed??
    424                         );
     297                usb_hub_release_default_address(hc);
     298                return;
     299        }
     300
     301        /* Request address at from host controller. */
     302        usb_address_t new_device_address = usb_drv_request_address(hc);
    425303        if (new_device_address < 0) {
    426304                dprintf(USB_LOG_LEVEL_ERROR, "failed to get free USB address");
    427305                opResult = new_device_address;
    428                 usb_hc_release_default_address(&hub->connection);
     306                usb_hub_release_default_address(hc);
    429307                return;
    430308        }
    431309        dprintf(USB_LOG_LEVEL_INFO, "setting new address %d",new_device_address);
    432         //opResult = usb_drv_req_set_address(hc, USB_ADDRESS_DEFAULT,
    433         //    new_device_address);
    434         opResult = usb_request_set_address(&new_device_pipe,new_device_address);
     310        opResult = usb_drv_req_set_address(hc, USB_ADDRESS_DEFAULT,
     311            new_device_address);
    435312
    436313        if (opResult != EOK) {
    437314                dprintf(USB_LOG_LEVEL_ERROR, "could not set address for new device");
    438                 usb_hc_release_default_address(&hub->connection);
    439                 return;
    440         }
    441 
    442 
    443         //opResult = usb_hub_release_default_address(hc);
    444         opResult = usb_hc_release_default_address(&hub->connection);
     315                usb_hub_release_default_address(hc);
     316                return;
     317        }
     318
     319
     320        opResult = usb_hub_release_default_address(hc);
    445321        if(opResult!=EOK){
    446322                return;
    447323        }
    448324
     325        devman_handle_t hc_handle;
     326        opResult = usb_drv_find_hc(hub->device, &hc_handle);
     327        if (opResult != EOK) {
     328                usb_log_error("Failed to get handle of host controller: %s.\n",
     329                    str_error(opResult));
     330                return;
     331        }
     332
    449333        devman_handle_t child_handle;
    450         //??
    451     opResult = usb_device_register_child_in_devman(new_device_address,
    452             hub->connection.hc_handle, hub->device, &child_handle);
    453 
     334        opResult = usb_device_register_child_in_devman(new_device_address,
     335            hc_handle, hub->device, &child_handle);
    454336        if (opResult != EOK) {
    455337                dprintf(USB_LOG_LEVEL_ERROR, "could not start driver for new device");
    456338                return;
    457339        }
    458         hub->attached_devs[port].handle = child_handle;
     340        hub->attached_devs[port].devman_handle = child_handle;
    459341        hub->attached_devs[port].address = new_device_address;
    460342
    461         //opResult = usb_drv_bind_address(hc, new_device_address, child_handle);
    462         opResult = usb_hc_register_device(
    463                         &hub->connection,
    464                         &hub->attached_devs[port]);
     343        opResult = usb_drv_bind_address(hc, new_device_address, child_handle);
    465344        if (opResult != EOK) {
    466345                dprintf(USB_LOG_LEVEL_ERROR, "could not assign address of device in hcd");
     
    479358 */
    480359static void usb_hub_removed_device(
    481     usb_hub_info_t * hub,uint16_t port) {
     360    usb_hub_info_t * hub, int hc, uint16_t port, usb_target_t target) {
    482361        //usb_device_request_setup_packet_t request;
    483362        int opResult;
     
    486365         * devide manager
    487366         */
    488        
     367
     368        hub->attached_devs[port].devman_handle=0;
    489369        //close address
    490370        if(hub->attached_devs[port].address!=0){
    491                 //opResult = usb_drv_release_address(hc,hub->attached_devs[port].address);
    492                 opResult = usb_hc_unregister_device(
    493                                 &hub->connection, hub->attached_devs[port].address);
     371                opResult = usb_drv_release_address(hc,hub->attached_devs[port].address);
    494372                if(opResult != EOK) {
    495373                        dprintf(USB_LOG_LEVEL_WARNING, "could not release address of " \
     
    497375                }
    498376                hub->attached_devs[port].address = 0;
    499                 hub->attached_devs[port].handle = 0;
    500377        }else{
    501378                dprintf(USB_LOG_LEVEL_WARNING, "this is strange, disconnected device had no address");
    502379                //device was disconnected before it`s port was reset - return default address
    503                 //usb_drv_release_default_address(hc);
    504                 usb_hc_release_default_address(&hub->connection);
     380                usb_drv_release_default_address(hc);
    505381        }
    506382}
     
    512388 * @param target
    513389 */
    514 static void usb_hub_process_interrupt(usb_hub_info_t * hub,
    515         uint16_t port) {
     390static void usb_hub_process_interrupt(usb_hub_info_t * hub, int hc,
     391        uint16_t port, usb_address_t address) {
    516392        dprintf(USB_LOG_LEVEL_DEBUG, "interrupt at port %d", port);
    517393        //determine type of change
    518         usb_endpoint_pipe_t *pipe = &hub->endpoints.control;
    519         int opResult = usb_endpoint_pipe_start_session(pipe);
    520        
    521         if(opResult != EOK){
    522                 dprintf(USB_LOG_LEVEL_ERROR, "cannot open pipe %d", opResult);
    523         }
    524 
    525         /*
    526394        usb_target_t target;
    527395        target.address=address;
    528396        target.endpoint=0;
    529         */
    530 
    531397        usb_port_status_t status;
    532398        size_t rcvd_size;
    533399        usb_device_request_setup_packet_t request;
    534         //int opResult;
     400        int opResult;
    535401        usb_hub_set_port_status_request(&request, port);
    536402        //endpoint 0
    537403
    538         opResult = usb_endpoint_pipe_control_read(
    539                         pipe,
    540                         &request, sizeof(usb_device_request_setup_packet_t),
     404        opResult = usb_drv_sync_control_read(
     405                        hc, target,
     406                        &request,
    541407                        &status, 4, &rcvd_size
    542408                        );
     
    551417        //something connected/disconnected
    552418        if (usb_port_connect_change(&status)) {
    553                 opResult = usb_hub_clear_port_feature(pipe,
     419                opResult = usb_hub_clear_port_feature(hc, target.address,
    554420                    port, USB_HUB_FEATURE_C_PORT_CONNECTION);
    555421                // TODO: check opResult
    556422                if (usb_port_dev_connected(&status)) {
    557423                        dprintf(USB_LOG_LEVEL_INFO, "some connection changed");
    558                         usb_hub_init_add_device(hub, port);
     424                        usb_hub_init_add_device(hc, port, target);
    559425                } else {
    560                         usb_hub_removed_device(hub, port);
     426                        usb_hub_removed_device(hub, hc, port, target);
    561427                }
    562428        }
     
    565431                dprintf(USB_LOG_LEVEL_INFO, "port reset complete");
    566432                if (usb_port_enabled(&status)) {
    567                         usb_hub_finalize_add_device(hub, port);
     433                        usb_hub_finalize_add_device(hub, hc, port, target);
    568434                } else {
    569435                        dprintf(USB_LOG_LEVEL_WARNING, "ERROR: port reset, but port still not enabled");
     
    581447        /// \TODO handle other changes
    582448        /// \TODO debug log for various situations
    583         usb_endpoint_pipe_end_session(pipe);
    584 
    585449
    586450}
     
    600464                fibril_mutex_unlock(&usb_hub_list_lock);
    601465                usb_hub_info_t * hub_info = ((usb_hub_info_t*)lst_item->data);
    602                 int opResult;
    603 
    604                 opResult = usb_endpoint_pipe_start_session(&hub_info->endpoints.status_change);
    605                 if(opResult != EOK){
    606                         continue;
    607                 }
    608466                /*
    609467                 * Check status change pipe of this hub.
    610468                 */
    611                 /*
     469
    612470                usb_target_t target;
    613471                target.address = hub_info->address;
     
    615473                dprintf(USB_LOG_LEVEL_INFO, "checking changes for hub at addr %d",
    616474                    target.address);
    617                 */
     475
    618476                size_t port_count = hub_info->port_count;
    619477
    620478                /*
    621479                 * Connect to respective HC.
    622                  *
     480                 */
    623481                int hc = usb_drv_hc_connect_auto(hub_info->device, 0);
    624482                if (hc < 0) {
    625483                        continue;
    626                 }*/
     484                }
    627485
    628486                /// FIXME: count properly
     
    631489                void *change_bitmap = malloc(byte_length);
    632490                size_t actual_size;
    633                 //usb_handle_t handle;
     491                usb_handle_t handle;
    634492
    635493                /*
    636494                 * Send the request.
    637495                 */
    638                 opResult = usb_endpoint_pipe_read(
    639                                 &hub_info->endpoints.status_change,
    640                                 change_bitmap, byte_length, &actual_size
    641                                 );
    642 
    643                 //usb_drv_async_wait_for(handle);
     496                int opResult = usb_drv_async_interrupt_in(hc, target,
     497                                change_bitmap, byte_length, &actual_size,
     498                                &handle);
     499
     500                usb_drv_async_wait_for(handle);
    644501
    645502                if (opResult != EOK) {
     
    654511                        if (interrupt) {
    655512                                usb_hub_process_interrupt(
    656                                         hub_info, port);
     513                                        hub_info, hc, port, hub_info->address);
    657514                        }
    658515                }
    659                 usb_endpoint_pipe_end_session(&hub_info->endpoints.status_change);
    660516                free(change_bitmap);
    661                
    662 
    663                 //async_hangup(hc);
     517
     518                async_hangup(hc);
    664519                fibril_mutex_lock(&usb_hub_list_lock);
    665520        }
Note: See TracChangeset for help on using the changeset viewer.