Ignore:
File:
1 edited

Legend:

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

    rfbefd0e ra7528a16  
    5353#include "usb/classes/classes.h"
    5454
     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
    5572int usb_hub_control_loop(void * hub_info_param){
    5673        usb_hub_info_t * hub_info = (usb_hub_info_t*)hub_info_param;
     
    6178                async_usleep(1000 * 1000 );/// \TODO proper number once
    6279        }
    63         usb_log_error("something in ctrl loop went wrong, errno %d\n",errorCode);
     80        usb_log_error("something in ctrl loop went wrong, errno %d",errorCode);
    6481
    6582        return 0;
     
    7491
    7592/**
    76  * create usb_hub_info_t structure
    77  *
    78  * Does only basic copying of known information into new structure.
    79  * @param usb_dev usb device structure
    80  * @return basic usb_hub_info_t structure
    81  */
    82 static usb_hub_info_t * usb_hub_info_create(usb_device_t * usb_dev) {
    83         usb_hub_info_t * result = usb_new(usb_hub_info_t);
    84         if(!result) return NULL;
    85         result->usb_device = usb_dev;
    86         result->status_change_pipe = usb_dev->pipes[0].pipe;
    87         result->control_pipe = &usb_dev->ctrl_pipe;
     93 * Initialize connnections to host controller, device, and device
     94 * control endpoint
     95 * @param hub
     96 * @param device
     97 * @return
     98 */
     99static int usb_hub_init_communication(usb_hub_info_t * hub){
     100        usb_log_debug("Initializing hub USB communication (hub->device->handle=%zu).\n", hub->device->handle);
     101        int opResult;
     102        opResult = usb_device_connection_initialize_from_device(
     103                        &hub->device_connection,
     104                        hub->device);
     105        if(opResult != EOK){
     106                usb_log_error("could not initialize connection to hc, errno %d",opResult);
     107                return opResult;
     108        }
     109        usb_log_debug("Initializing USB wire abstraction.\n");
     110        opResult = usb_hc_connection_initialize_from_device(&hub->connection,
     111                        hub->device);
     112        if(opResult != EOK){
     113                usb_log_error("could not initialize connection to device, errno %d",
     114                                opResult);
     115                return opResult;
     116        }
     117        usb_log_debug("Initializing default control pipe.\n");
     118        opResult = usb_endpoint_pipe_initialize_default_control(&hub->endpoints.control,
     119            &hub->device_connection);
     120        if(opResult != EOK){
     121                usb_log_error("could not initialize connection to device endpoint, errno %d",
     122                                opResult);
     123                return opResult;
     124        }
     125
     126        opResult = usb_endpoint_pipe_probe_default_control(&hub->endpoints.control);
     127        if (opResult != EOK) {
     128                usb_log_error("failed probing endpoint 0, %d", opResult);
     129                return opResult;
     130        }
     131
     132        return EOK;
     133}
     134
     135/**
     136 * When entering this function, hub->endpoints.control should be active.
     137 * @param hub
     138 * @return
     139 */
     140static int usb_hub_process_configuration_descriptors(
     141        usb_hub_info_t * hub){
     142        if(hub==NULL) {
     143                return EINVAL;
     144        }
     145        int opResult;
     146       
     147        //device descriptor
     148        usb_standard_device_descriptor_t std_descriptor;
     149        opResult = usb_request_get_device_descriptor(&hub->endpoints.control,
     150            &std_descriptor);
     151        if(opResult!=EOK){
     152                usb_log_error("could not get device descriptor, %d",opResult);
     153                return opResult;
     154        }
     155        usb_log_info("hub has %d configurations",
     156                        std_descriptor.configuration_count);
     157        if(std_descriptor.configuration_count<1){
     158                usb_log_error("THERE ARE NO CONFIGURATIONS AVAILABLE");
     159                //shouldn`t I return?
     160        }
     161
     162        /* Retrieve full configuration descriptor. */
     163        uint8_t *descriptors = NULL;
     164        size_t descriptors_size = 0;
     165        opResult = usb_request_get_full_configuration_descriptor_alloc(
     166            &hub->endpoints.control, 0,
     167            (void **) &descriptors, &descriptors_size);
     168        if (opResult != EOK) {
     169                usb_log_error("Could not get configuration descriptor: %s.\n",
     170                    str_error(opResult));
     171                return opResult;
     172        }
     173        usb_standard_configuration_descriptor_t *config_descriptor
     174            = (usb_standard_configuration_descriptor_t *) descriptors;
     175
     176        /* Set configuration. */
     177        opResult = usb_request_set_configuration(&hub->endpoints.control,
     178            config_descriptor->configuration_number);
     179
     180        if (opResult != EOK) {
     181                usb_log_error("Failed to set hub configuration: %s.\n",
     182                    str_error(opResult));
     183                return opResult;
     184        }
     185        usb_log_debug("\tused configuration %d",
     186                        config_descriptor->configuration_number);
     187
     188        usb_endpoint_mapping_t endpoint_mapping[1] = {
     189                {
     190                        .pipe = &hub->endpoints.status_change,
     191                        .description = &status_change_endpoint_description,
     192                        .interface_no =
     193                            usb_device_get_assigned_interface(hub->device)
     194                }
     195        };
     196        opResult = usb_endpoint_pipe_initialize_from_configuration(
     197            endpoint_mapping, 1,
     198            descriptors, descriptors_size,
     199            &hub->device_connection);
     200        if (opResult != EOK) {
     201                usb_log_error("Failed to initialize status change pipe: %s",
     202                    str_error(opResult));
     203                return opResult;
     204        }
     205        if (!endpoint_mapping[0].present) {
     206                usb_log_error("Not accepting device, " \
     207                    "cannot understand what is happenning");
     208                return EREFUSED;
     209        }
     210
     211        free(descriptors);
     212        return EOK;
     213       
     214}
     215
     216
     217/**
     218 * Create hub representation from device information.
     219 * @param device
     220 * @return pointer to created structure or NULL in case of error
     221 */
     222usb_hub_info_t * usb_create_hub_info(ddf_dev_t * device) {
     223        usb_hub_info_t* result = usb_new(usb_hub_info_t);
     224        result->device = device;
     225        int opResult;
     226        opResult = usb_hub_init_communication(result);
     227        if(opResult != EOK){
     228                free(result);
     229                return NULL;
     230        }
     231
     232        //result->device = device;
     233        result->port_count = -1;
     234        result->device = device;
    88235        result->is_default_address_used = false;
    89         return result;
    90 }
    91 
    92 /**
    93  * Load hub-specific information into hub_info structure.
    94  *
    95  * Particularly read port count and initialize structure holding port
    96  * information.
    97  * This function is hub-specific and should be run only after the hub is
    98  * configured using usb_hub_set_configuration function.
    99  * @param hub_info pointer to structure with usb hub data
    100  * @return error code
    101  */
    102 static int usb_hub_get_hub_specific_info(usb_hub_info_t * hub_info){
     236
     237        //result->usb_device = usb_new(usb_hcd_attached_device_info_t);
     238        size_t received_size;
     239
    103240        // get hub descriptor
    104         usb_log_debug("creating serialized descriptor\n");
     241        usb_log_debug("creating serialized descripton");
    105242        void * serialized_descriptor = malloc(USB_HUB_MAX_DESCRIPTOR_SIZE);
    106243        usb_hub_descriptor_t * descriptor;
    107 
    108         /* this was one fix of some bug, should not be needed anymore
    109         int opResult = usb_request_set_configuration(&result->endpoints.control, 1);
    110         if(opResult!=EOK){
    111                 usb_log_error("could not set default configuration, errno %d",opResult);
    112                 return opResult;
    113         }
    114          */
    115         size_t received_size;
    116         int opResult = usb_request_get_descriptor(&hub_info->usb_device->ctrl_pipe,
     244        usb_log_debug("starting control transaction");
     245        usb_endpoint_pipe_start_session(&result->endpoints.control);
     246        opResult = usb_request_set_configuration(&result->endpoints.control, 1);
     247        assert(opResult == EOK);
     248
     249        opResult = usb_request_get_descriptor(&result->endpoints.control,
    117250                        USB_REQUEST_TYPE_CLASS, USB_REQUEST_RECIPIENT_DEVICE,
    118251                        USB_DESCTYPE_HUB,
    119252                        0, 0, serialized_descriptor,
    120253                        USB_HUB_MAX_DESCRIPTOR_SIZE, &received_size);
    121 
    122         if (opResult != EOK) {
    123                 usb_log_error("failed when receiving hub descriptor, badcode = %d\n",
     254        usb_endpoint_pipe_end_session(&result->endpoints.control);
     255
     256        if (opResult != EOK) {
     257                usb_log_error("failed when receiving hub descriptor, badcode = %d",
    124258                                opResult);
    125259                free(serialized_descriptor);
    126                 return opResult;
    127         }
    128         usb_log_debug2("deserializing descriptor\n");
     260                free(result);
     261                return NULL;
     262        }
     263        usb_log_debug2("deserializing descriptor");
    129264        descriptor = usb_deserialize_hub_desriptor(serialized_descriptor);
    130265        if(descriptor==NULL){
    131                 usb_log_warning("could not deserialize descriptor \n");
    132                 return opResult;
    133         }
    134         usb_log_debug("setting port count to %d\n",descriptor->ports_count);
    135         hub_info->port_count = descriptor->ports_count;
    136         hub_info->attached_devs = (usb_hc_attached_device_t*)
    137             malloc((hub_info->port_count+1) * sizeof(usb_hc_attached_device_t));
     266                usb_log_warning("could not deserialize descriptor ");
     267                free(result);
     268                return NULL;
     269        }
     270
     271        usb_log_info("setting port count to %d",descriptor->ports_count);
     272        result->port_count = descriptor->ports_count;
     273        result->attached_devs = (usb_hc_attached_device_t*)
     274            malloc((result->port_count+1) * sizeof(usb_hc_attached_device_t));
    138275        int i;
    139         for(i=0;i<hub_info->port_count+1;++i){
    140                 hub_info->attached_devs[i].handle=0;
    141                 hub_info->attached_devs[i].address=0;
    142         }
    143         usb_log_debug2("freeing data\n");
     276        for(i=0;i<result->port_count+1;++i){
     277                result->attached_devs[i].handle=0;
     278                result->attached_devs[i].address=0;
     279        }
     280        usb_log_debug2("freeing data");
    144281        free(serialized_descriptor);
    145282        free(descriptor->devices_removable);
    146283        free(descriptor);
    147         return EOK;
    148 }
    149 /**
    150  * Set configuration of hub
    151  *
    152  * Check whether there is at least one configuration and sets the first one.
    153  * This function should be run prior to running any hub-specific action.
    154  * @param hub_info
     284
     285        //finish
     286
     287        usb_log_info("hub info created");
     288
     289        return result;
     290}
     291
     292/**
     293 * Create hub representation and add it into hub list
     294 * @param dev
    155295 * @return
    156296 */
    157 static int usb_hub_set_configuration(usb_hub_info_t * hub_info){
    158         //device descriptor
    159         usb_standard_device_descriptor_t *std_descriptor
    160             = &hub_info->usb_device->descriptors.device;
    161         usb_log_debug("hub has %d configurations\n",
    162             std_descriptor->configuration_count);
    163         if(std_descriptor->configuration_count<1){
    164                 usb_log_error("THERE ARE NO CONFIGURATIONS AVAILABLE\n");
    165                 //shouldn`t I return?
    166                 //definitely
    167                 return EINVAL;
    168         }
    169 
    170         usb_standard_configuration_descriptor_t *config_descriptor
    171             = (usb_standard_configuration_descriptor_t *)
    172             hub_info->usb_device->descriptors.configuration;
    173 
    174         /* Set configuration. */
    175         int opResult = usb_request_set_configuration(
    176             &hub_info->usb_device->ctrl_pipe,
    177             config_descriptor->configuration_number);
    178 
    179         if (opResult != EOK) {
    180                 usb_log_error("Failed to set hub configuration: %s.\n",
    181                     str_error(opResult));
    182                 return opResult;
    183         }
    184         usb_log_debug("\tused configuration %d\n",
    185                         config_descriptor->configuration_number);
    186 
    187         return EOK;
    188 }
    189 
    190 /**
    191  * Initialize hub device driver fibril
    192  *
    193  * Creates hub representation and fibril that periodically checks hub`s status.
    194  * Hub representation is passed to the fibril.
    195  * @param usb_dev generic usb device information
    196  * @return error code
    197  */
    198 int usb_hub_add_device(usb_device_t * usb_dev){
    199         if(!usb_dev) return EINVAL;
    200         usb_hub_info_t * hub_info = usb_hub_info_create(usb_dev);
    201         //create hc connection
    202         usb_log_debug("Initializing USB wire abstraction.\n");
    203         int opResult = usb_hc_connection_initialize_from_device(
    204                         &hub_info->connection,
    205                         hub_info->usb_device->ddf_dev);
     297int usb_add_hub_device(ddf_dev_t *dev) {
     298        usb_log_info("add_hub_device(handle=%d)", (int) dev->handle);
     299
     300        //dev->ops = &hub_device_ops;
     301        (void) hub_device_ops;
     302
     303        usb_hub_info_t * hub_info = usb_create_hub_info(dev);
     304        if(!hub_info){
     305                return EINTR;
     306        }
     307
     308        int opResult;
     309
     310        //perform final configurations
     311        usb_endpoint_pipe_start_session(&hub_info->endpoints.control);
     312        // process descriptors
     313        opResult = usb_hub_process_configuration_descriptors(hub_info);
    206314        if(opResult != EOK){
    207                 usb_log_error("could not initialize connection to device, errno %d\n",
     315                usb_log_error("could not get configuration descriptors, %d",
    208316                                opResult);
    209                 free(hub_info);
    210                 return opResult;
    211         }
    212        
    213         usb_pipe_start_session(hub_info->control_pipe);
    214         //set hub configuration
    215         opResult = usb_hub_set_configuration(hub_info);
    216         if(opResult!=EOK){
    217                 usb_log_error("could not set hub configuration, errno %d\n",opResult);
    218                 free(hub_info);
    219                 return opResult;
    220         }
    221         //get port count and create attached_devs
    222         opResult = usb_hub_get_hub_specific_info(hub_info);
    223         if(opResult!=EOK){
    224                 usb_log_error("could not set hub configuration, errno %d\n",opResult);
    225                 free(hub_info);
    226                 return opResult;
    227         }
    228         usb_pipe_end_session(hub_info->control_pipe);
    229 
    230 
    231         /// \TODO what is this?
    232         usb_log_debug("Creating `hub' function.\n");
    233         ddf_fun_t *hub_fun = ddf_fun_create(hub_info->usb_device->ddf_dev,
    234                         fun_exposed, "hub");
     317                return opResult;
     318        }
     319        //power ports
     320        usb_device_request_setup_packet_t request;
     321        int port;
     322        for (port = 1; port < hub_info->port_count+1; ++port) {
     323                usb_hub_set_power_port_request(&request, port);
     324                opResult = usb_endpoint_pipe_control_write(&hub_info->endpoints.control,
     325                                &request,sizeof(usb_device_request_setup_packet_t), NULL, 0);
     326                usb_log_info("powering port %d",port);
     327                if (opResult != EOK) {
     328                        usb_log_warning("something went wrong when setting hub`s %dth port", port);
     329                }
     330        }
     331        //ports powered, hub seems to be enabled
     332        usb_endpoint_pipe_end_session(&hub_info->endpoints.control);
     333
     334        //add the hub to list
     335        //is this needed now?
     336        fibril_mutex_lock(&usb_hub_list_lock);
     337        usb_lst_append(&usb_hub_list, hub_info);
     338        fibril_mutex_unlock(&usb_hub_list_lock);
     339        usb_log_debug("hub info added to list");
     340
     341        usb_log_debug("adding to ddf");
     342        ddf_fun_t *hub_fun = ddf_fun_create(dev, fun_exposed, "hub");
    235343        assert(hub_fun != NULL);
    236344        hub_fun->ops = NULL;
     
    241349        assert(rc == EOK);
    242350
    243         //create fibril for the hub control loop
    244351        fid_t fid = fibril_create(usb_hub_control_loop, hub_info);
    245352        if (fid == 0) {
    246                 usb_log_error("failed to start monitoring fibril for new hub.\n");
     353                usb_log_error("failed to start monitoring fibril for new hub");
    247354                return ENOMEM;
    248355        }
    249356        fibril_add_ready(fid);
    250         usb_log_debug("Hub fibril created.\n");
    251 
    252         usb_log_info("Controlling hub `%s' (%d ports).\n",
    253             hub_info->usb_device->ddf_dev->name, hub_info->port_count);
     357
     358        usb_log_debug("hub fibril created");
     359        //(void)hub_info;
     360        //usb_hub_check_hub_changes();
     361       
     362        usb_log_info("hub dev added");
     363        //address is lost...
     364        usb_log_debug("\taddress %d, has %d ports ",
     365                        //hub_info->endpoints.control.,
     366                        hub_info->port_count);
     367
    254368        return EOK;
     369        //return ENOTSUP;
    255370}
    256371
     
    273388        int opResult = usb_hc_release_default_address(&hub->connection);
    274389        if(opResult!=EOK){
    275                 usb_log_error("could not release default address, errno %d\n",opResult);
     390                usb_log_error("could not release default address, errno %d",opResult);
    276391                return opResult;
    277392        }
     
    290405        //if this hub already uses default address, it cannot request it once more
    291406        if(hub->is_default_address_used) return;
    292         usb_log_debug("some connection changed\n");
    293         assert(hub->control_pipe->hc_phone);
    294         int opResult = usb_hub_clear_port_feature(hub->control_pipe,
    295                                 port, USB_HUB_FEATURE_C_PORT_CONNECTION);
    296         if(opResult != EOK){
    297                 usb_log_warning("could not clear port-change-connection flag\n");
    298         }
     407
    299408        usb_device_request_setup_packet_t request;
    300        
     409        int opResult;
     410        usb_log_info("some connection changed");
     411        assert(hub->endpoints.control.hc_phone);
    301412        //get default address
    302413        opResult = usb_hc_reserve_default_address(&hub->connection, speed);
    303414       
    304415        if (opResult != EOK) {
    305                 usb_log_warning("cannot assign default address, it is probably used %d\n",
     416                usb_log_warning("cannot assign default address, it is probably used %d",
    306417                                opResult);
    307418                return;
     
    310421        //reset port
    311422        usb_hub_set_reset_port_request(&request, port);
    312         opResult = usb_pipe_control_write(
    313                         hub->control_pipe,
     423        opResult = usb_endpoint_pipe_control_write(
     424                        &hub->endpoints.control,
    314425                        &request,sizeof(usb_device_request_setup_packet_t),
    315426                        NULL, 0
    316427                        );
    317428        if (opResult != EOK) {
    318                 usb_log_error("something went wrong when reseting a port %d\n",opResult);
     429                usb_log_error("something went wrong when reseting a port %d",opResult);
    319430                //usb_hub_release_default_address(hc);
    320431                usb_hub_release_default_address(hub);
    321432        }
    322         return;
    323433}
    324434
     
    330440 */
    331441static void usb_hub_finalize_add_device( usb_hub_info_t * hub,
    332                 uint16_t port, usb_speed_t speed) {
    333 
    334         int opResult;
    335         usb_log_debug("finalizing add device\n");
    336         opResult = usb_hub_clear_port_feature(hub->control_pipe,
     442                uint16_t port, bool isLowSpeed) {
     443
     444        int opResult;
     445        usb_log_info("finalizing add device");
     446        opResult = usb_hub_clear_port_feature(&hub->endpoints.control,
    337447            port, USB_HUB_FEATURE_C_PORT_RESET);
    338448
    339449        if (opResult != EOK) {
    340                 usb_log_error("failed to clear port reset feature\n");
     450                usb_log_error("failed to clear port reset feature");
    341451                usb_hub_release_default_address(hub);
    342452                return;
    343453        }
    344454        //create connection to device
    345         usb_pipe_t new_device_pipe;
     455        usb_endpoint_pipe_t new_device_pipe;
    346456        usb_device_connection_t new_device_connection;
    347457        usb_device_connection_initialize_on_default_address(
     
    349459                        &hub->connection
    350460                        );
    351         usb_pipe_initialize_default_control(
     461        usb_endpoint_pipe_initialize_default_control(
    352462                        &new_device_pipe,
    353463                        &new_device_connection);
    354         usb_pipe_probe_default_control(&new_device_pipe);
     464        usb_endpoint_pipe_probe_default_control(&new_device_pipe);
     465        /// \TODO get highspeed info
     466        usb_speed_t speed = isLowSpeed?USB_SPEED_LOW:USB_SPEED_FULL;
     467
    355468
    356469        /* Request address from host controller. */
     
    360473                        );
    361474        if (new_device_address < 0) {
    362                 usb_log_error("failed to get free USB address\n");
     475                usb_log_error("failed to get free USB address");
    363476                opResult = new_device_address;
    364477                usb_hub_release_default_address(hub);
    365478                return;
    366479        }
    367         usb_log_debug("setting new address %d\n",new_device_address);
     480        usb_log_info("setting new address %d",new_device_address);
    368481        //opResult = usb_drv_req_set_address(hc, USB_ADDRESS_DEFAULT,
    369482        //    new_device_address);
    370         usb_pipe_start_session(&new_device_pipe);
     483        usb_endpoint_pipe_start_session(&new_device_pipe);
    371484        opResult = usb_request_set_address(&new_device_pipe,new_device_address);
    372         usb_pipe_end_session(&new_device_pipe);
    373         if (opResult != EOK) {
    374                 usb_log_error("could not set address for new device %d\n",opResult);
     485        usb_endpoint_pipe_end_session(&new_device_pipe);
     486        if (opResult != EOK) {
     487                usb_log_error("could not set address for new device %d",opResult);
    375488                usb_hub_release_default_address(hub);
    376489                return;
     
    387500        //??
    388501    opResult = usb_device_register_child_in_devman(new_device_address,
    389             hub->connection.hc_handle, hub->usb_device->ddf_dev, &child_handle,
     502            hub->connection.hc_handle, hub->device, &child_handle,
    390503            NULL, NULL, NULL);
    391504
    392505        if (opResult != EOK) {
    393                 usb_log_error("could not start driver for new device %d\n",opResult);
     506                usb_log_error("could not start driver for new device %d",opResult);
    394507                return;
    395508        }
     
    402515                        &hub->attached_devs[port]);
    403516        if (opResult != EOK) {
    404                 usb_log_error("could not assign address of device in hcd %d\n",opResult);
    405                 return;
    406         }
    407         usb_log_info("Detected new device on `%s' (port %d), " \
    408             "address %d (handle %llu).\n",
    409             hub->usb_device->ddf_dev->name, (int) port,
     517                usb_log_error("could not assign address of device in hcd %d",opResult);
     518                return;
     519        }
     520        usb_log_info("new device address %d, handle %zu",
    410521            new_device_address, child_handle);
     522
    411523}
    412524
     
    419531static void usb_hub_removed_device(
    420532    usb_hub_info_t * hub,uint16_t port) {
    421 
    422         int opResult = usb_hub_clear_port_feature(hub->control_pipe,
    423                                 port, USB_HUB_FEATURE_C_PORT_CONNECTION);
    424         if(opResult != EOK){
    425                 usb_log_warning("could not clear port-change-connection flag\n");
    426         }
     533               
    427534        /** \TODO remove device from device manager - not yet implemented in
    428535         * devide manager
     
    442549                 */
    443550        }else{
    444                 usb_log_warning("this is strange, disconnected device had no address\n");
     551                usb_log_warning("this is strange, disconnected device had no address");
    445552                //device was disconnected before it`s port was reset - return default address
    446553                usb_hub_release_default_address(hub);
     
    460567                uint16_t port){
    461568        int opResult;
    462         opResult = usb_hub_clear_port_feature(hub->control_pipe,
     569        opResult = usb_hub_clear_port_feature(&hub->endpoints.control,
    463570            port, USB_HUB_FEATURE_PORT_POWER);
    464571        if(opResult!=EOK){
    465                 usb_log_error("cannot power off port %d;  %d\n",
     572                usb_log_error("cannot power off port %d;  %d",
    466573                                port, opResult);
    467574        }
     
    476583static void usb_hub_process_interrupt(usb_hub_info_t * hub,
    477584        uint16_t port) {
    478         usb_log_debug("interrupt at port %d\n", port);
     585        usb_log_debug("interrupt at port %d", port);
    479586        //determine type of change
    480         usb_pipe_t *pipe = hub->control_pipe;
     587        usb_endpoint_pipe_t *pipe = &hub->endpoints.control;
    481588       
    482589        int opResult;
     
    489596        //endpoint 0
    490597
    491         opResult = usb_pipe_control_read(
     598        opResult = usb_endpoint_pipe_control_read(
    492599                        pipe,
    493600                        &request, sizeof(usb_device_request_setup_packet_t),
     
    495602                        );
    496603        if (opResult != EOK) {
    497                 usb_log_error("could not get port status\n");
     604                usb_log_error("could not get port status");
    498605                return;
    499606        }
    500607        if (rcvd_size != sizeof (usb_port_status_t)) {
    501                 usb_log_error("received status has incorrect size\n");
     608                usb_log_error("received status has incorrect size");
    502609                return;
    503610        }
    504611        //something connected/disconnected
    505612        if (usb_port_connect_change(&status)) {
     613                opResult = usb_hub_clear_port_feature(pipe,
     614                    port, USB_HUB_FEATURE_C_PORT_CONNECTION);
     615                // TODO: check opResult
    506616                if (usb_port_dev_connected(&status)) {
    507                         usb_log_debug("some connection changed\n");
     617                        usb_log_info("some connection changed");
    508618                        usb_hub_init_add_device(hub, port, usb_port_speed(&status));
    509619                } else {
     
    517627                        usb_hub_over_current(hub,port);
    518628                }else{
    519                         usb_log_debug("over current condition was auto-resolved on port %d\n",
     629                        usb_log_info("over current condition was auto-resolved on port %d",
    520630                                        port);
    521631                }
     
    523633        //port reset
    524634        if (usb_port_reset_completed(&status)) {
    525                 usb_log_debug("port reset complete\n");
     635                usb_log_info("port reset complete");
    526636                if (usb_port_enabled(&status)) {
    527                         usb_hub_finalize_add_device(hub, port, usb_port_speed(&status));
     637                        usb_hub_finalize_add_device(hub, port, usb_port_low_speed(&status));
    528638                } else {
    529                         usb_log_warning("port reset, but port still not enabled\n");
     639                        usb_log_warning("port reset, but port still not enabled");
    530640                }
    531641        }
     
    536646        usb_port_set_dev_connected(&status, false);
    537647        if (status>>16) {
    538                 usb_log_info("there was some unsupported change on port %d: %X\n",
     648                usb_log_info("there was some unsupported change on port %d: %X",
    539649                                port,status);
    540650
    541651        }
     652        /// \TODO handle other changes - is there any?
    542653}
    543654
     
    550661int usb_hub_check_hub_changes(usb_hub_info_t * hub_info){
    551662        int opResult;
    552         opResult = usb_pipe_start_session(
    553                         hub_info->status_change_pipe);
     663        opResult = usb_endpoint_pipe_start_session(&hub_info->endpoints.status_change);
    554664        if(opResult != EOK){
    555                 usb_log_error("could not initialize communication for hub; %d\n",
     665                usb_log_error("could not initialize communication for hub; %d",
    556666                                opResult);
    557667                return opResult;
     
    568678         * Send the request.
    569679         */
    570         opResult = usb_pipe_read(
    571                         hub_info->status_change_pipe,
     680        opResult = usb_endpoint_pipe_read(
     681                        &hub_info->endpoints.status_change,
    572682                        change_bitmap, byte_length, &actual_size
    573683                        );
     
    575685        if (opResult != EOK) {
    576686                free(change_bitmap);
    577                 usb_log_warning("something went wrong while getting status of hub\n");
    578                 usb_pipe_end_session(hub_info->status_change_pipe);
     687                usb_log_warning("something went wrong while getting status of hub");
     688                usb_endpoint_pipe_end_session(&hub_info->endpoints.status_change);
    579689                return opResult;
    580690        }
    581691        unsigned int port;
    582         opResult = usb_pipe_start_session(hub_info->control_pipe);
     692        opResult = usb_endpoint_pipe_start_session(&hub_info->endpoints.control);
    583693        if(opResult!=EOK){
    584                 usb_log_error("could not start control pipe session %d\n", opResult);
    585                 usb_pipe_end_session(hub_info->status_change_pipe);
     694                usb_log_error("could not start control pipe session %d", opResult);
     695                usb_endpoint_pipe_end_session(&hub_info->endpoints.status_change);
    586696                return opResult;
    587697        }
    588698        opResult = usb_hc_connection_open(&hub_info->connection);
    589699        if(opResult!=EOK){
    590                 usb_log_error("could not start host controller session %d\n",
     700                usb_log_error("could not start host controller session %d",
    591701                                opResult);
    592                 usb_pipe_end_session(hub_info->control_pipe);
    593                 usb_pipe_end_session(hub_info->status_change_pipe);
     702                usb_endpoint_pipe_end_session(&hub_info->endpoints.control);
     703                usb_endpoint_pipe_end_session(&hub_info->endpoints.status_change);
    594704                return opResult;
    595705        }
     
    605715        }
    606716        usb_hc_connection_close(&hub_info->connection);
    607         usb_pipe_end_session(hub_info->control_pipe);
    608         usb_pipe_end_session(hub_info->status_change_pipe);
     717        usb_endpoint_pipe_end_session(&hub_info->endpoints.control);
     718        usb_endpoint_pipe_end_session(&hub_info->endpoints.status_change);
    609719        free(change_bitmap);
    610720        return EOK;
Note: See TracChangeset for help on using the changeset viewer.