Ignore:
File:
1 edited

Legend:

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

    r28cb8bf7 rd81ef61c  
    3636#include <bool.h>
    3737#include <errno.h>
    38 #include <str_error.h>
    3938
    4039#include <usb_iface.h>
    4140#include <usb/usbdrv.h>
    4241#include <usb/descriptor.h>
    43 #include <usb/recognise.h>
    4442#include <usb/devreq.h>
     43#include <usb/request.h>
    4544#include <usb/classes/hub.h>
    4645
     
    4948#include "port_status.h"
    5049#include "usb/usb.h"
     50#include "usb/pipes.h"
    5151
    5252static usb_iface_t hub_usb_iface = {
     
    6464//*********************************************
    6565
    66 usb_hub_info_t * usb_create_hub_info(device_t * device, int hc) {
     66usb_hub_info_t * usb_create_hub_info(device_t * device) {
    6767        usb_hub_info_t* result = usb_new(usb_hub_info_t);
     68        usb_device_connection_initialize_from_device(&result->connection, device);
     69        usb_endpoint_pipe_initialize_default_control(&result->endpoints.control,
     70            &result->connection);
     71       
     72
    6873        //result->device = device;
    6974        result->port_count = -1;
     
    7176        result->device = device;
    7277
    73 
    74         dprintf(USB_LOG_LEVEL_DEBUG, "phone to hc = %d", hc);
    75         if (hc < 0) {
    76                 return result;
    77         }
    78         //get some hub info
    79         usb_address_t addr = usb_drv_get_my_address(hc, device);
    80         dprintf(USB_LOG_LEVEL_DEBUG, "address of newly created hub = %d", addr);
    81         /*if(addr<0){
    82                 //return result;
    83 
    84         }*/
    85 
    86         result->address = addr;
    87 
     78        result->usb_device = usb_new(usb_hcd_attached_device_info_t);
     79       
    8880        // get hub descriptor
    8981
     
    9486        int opResult;
    9587        dprintf(USB_LOG_LEVEL_DEBUG, "starting control transaction");
    96        
    97         opResult = usb_drv_req_get_descriptor(hc, addr,
     88        usb_endpoint_pipe_start_session(&result->endpoints.control);
     89        opResult = usb_request_get_descriptor(&result->endpoints.control,
    9890                        USB_REQUEST_TYPE_CLASS,
    9991                        USB_DESCTYPE_HUB, 0, 0, serialized_descriptor,
    10092                        USB_HUB_MAX_DESCRIPTOR_SIZE, &received_size);
     93        usb_endpoint_pipe_end_session(&result->endpoints.control);
     94
     95        /* Initialize the interrupt endpoint.
     96        usb_endpoint_pipe_initalize(
     97                &hub_data->endpoints->status_change,
     98                &endpiont_descriptor, &hub_data->connection);
     99
     100         */ /// \TODO add this call
    101101
    102102        if (opResult != EOK) {
     
    143143        dev->ops = &hub_device_ops;
    144144
    145         //create the hub structure
    146         //get hc connection
    147         int hc = usb_drv_hc_connect_auto(dev, 0);
    148         if (hc < 0) {
    149                 return hc;
    150         }
    151 
    152         usb_hub_info_t * hub_info = usb_create_hub_info(dev, hc);
     145
     146        usb_hub_info_t * hub_info = usb_create_hub_info(dev);
     147        usb_endpoint_pipe_start_session(&hub_info->endpoints.control);
    153148        int port;
    154149        int opResult;
    155         usb_target_t target;
    156         target.address = hub_info->address;
    157         target.endpoint = 0;
     150        //usb_target_t target;
     151        //target.address = hub_info->usb_device->address;
     152        //target.endpoint = 0;
    158153
    159154        //get configuration descriptor
     
    161156        // and all should be checked
    162157        usb_standard_device_descriptor_t std_descriptor;
    163         opResult = usb_drv_req_get_device_descriptor(hc, target.address,
     158        opResult = usb_request_get_device_descriptor(&hub_info->endpoints.control,
    164159            &std_descriptor);
    165160        if(opResult!=EOK){
     
    174169        /// \TODO check other configurations
    175170        usb_standard_configuration_descriptor_t config_descriptor;
    176         opResult = usb_drv_req_get_bare_configuration_descriptor(hc,
    177         target.address, 0,
     171        opResult = usb_request_get_bare_configuration_descriptor(
     172            &hub_info->endpoints.control, 0,
    178173        &config_descriptor);
    179174        if(opResult!=EOK){
     
    182177        }
    183178        //set configuration
    184         opResult = usb_drv_req_set_configuration(hc, target.address,
     179        opResult = usb_request_set_configuration(&hub_info->endpoints.control,
    185180    config_descriptor.configuration_number);
    186181
     
    192187        for (port = 1; port < hub_info->port_count+1; ++port) {
    193188                usb_hub_set_power_port_request(&request, port);
    194                 opResult = usb_drv_sync_control_write(hc, target, &request, NULL, 0);
     189                opResult = usb_endpoint_pipe_control_write(&hub_info->endpoints.control,
     190                                &request,sizeof(usb_device_request_setup_packet_t), NULL, 0);
    195191                dprintf(USB_LOG_LEVEL_INFO, "powering port %d",port);
    196192                if (opResult != EOK) {
     
    200196        //ports powered, hub seems to be enabled
    201197
    202         async_hangup(hc);
     198        usb_endpoint_pipe_end_session(&hub_info->endpoints.control);
     199        //async_hangup(hc);
    203200
    204201        //add the hub to list
     
    215212        dprintf(USB_LOG_LEVEL_INFO, "hub dev added");
    216213        dprintf(USB_LOG_LEVEL_DEBUG, "\taddress %d, has %d ports ",
    217                         hub_info->address,
     214                        hub_info->usb_device->address,
    218215                        hub_info->port_count);
    219216        dprintf(USB_LOG_LEVEL_DEBUG, "\tused configuration %d",config_descriptor.configuration_number);
     
    252249 * @param target
    253250 */
    254 static void usb_hub_init_add_device(int hc, uint16_t port, usb_target_t target) {
     251static void usb_hub_init_add_device(usb_hub_info_t * hub, uint16_t port) {
    255252        usb_device_request_setup_packet_t request;
    256253        int opResult;
    257254        dprintf(USB_LOG_LEVEL_INFO, "some connection changed");
    258255        //get default address
     256        ///////////////here ended pipe api upgrading
     257        gfdl;gfdgldglglkfgklfjfkld;sjgk;fgklsjgld
    259258        opResult = usb_drv_reserve_default_address(hc);
    260259        if (opResult != EOK) {
     
    318317        }
    319318
    320         devman_handle_t hc_handle;
    321         opResult = usb_drv_find_hc(hub->device, &hc_handle);
    322         if (opResult != EOK) {
    323                 usb_log_error("Failed to get handle of host controller: %s.\n",
    324                     str_error(opResult));
    325                 return;
    326         }
    327 
    328319        devman_handle_t child_handle;
    329         opResult = usb_device_register_child_in_devman(new_device_address,
    330             hc_handle, hub->device, &child_handle);
     320        opResult = usb_drv_register_child_in_devman(hc, hub->device,
     321            new_device_address, &child_handle);
    331322        if (opResult != EOK) {
    332323                dprintf(USB_LOG_LEVEL_ERROR, "could not start driver for new device");
     
    383374 * @param target
    384375 */
    385 static void usb_hub_process_interrupt(usb_hub_info_t * hub, int hc,
    386         uint16_t port, usb_address_t address) {
     376static void usb_hub_process_interrupt(usb_hub_info_t * hub,
     377        uint16_t port) {
    387378        dprintf(USB_LOG_LEVEL_DEBUG, "interrupt at port %d", port);
    388379        //determine type of change
     380        int opResult = usb_endpoint_pipe_start_session(&hub->endpoints.control);
     381        usb_endpoint_pipe_t *pipe = &hub->endpoints.control;
     382        if(opResult != EOK){
     383                continue;
     384        }
     385
     386        /*
    389387        usb_target_t target;
    390388        target.address=address;
    391389        target.endpoint=0;
     390        */
     391
    392392        usb_port_status_t status;
    393393        size_t rcvd_size;
    394394        usb_device_request_setup_packet_t request;
    395         int opResult;
     395        //int opResult;
    396396        usb_hub_set_port_status_request(&request, port);
    397397        //endpoint 0
    398398
    399         opResult = usb_drv_sync_control_read(
    400                         hc, target,
    401                         &request,
     399        opResult = usb_endpoint_pipe_control_read(
     400                        pipe,
     401                        &request, sizeof(usb_device_request_setup_packet_t),
    402402                        &status, 4, &rcvd_size
    403403                        );
     
    412412        //something connected/disconnected
    413413        if (usb_port_connect_change(&status)) {
    414                 opResult = usb_hub_clear_port_feature(hc, target.address,
     414                opResult = usb_hub_clear_port_feature(&hub->endpoints.control,
    415415                    port, USB_HUB_FEATURE_C_PORT_CONNECTION);
    416416                // TODO: check opResult
    417417                if (usb_port_dev_connected(&status)) {
    418418                        dprintf(USB_LOG_LEVEL_INFO, "some connection changed");
    419                         usb_hub_init_add_device(hc, port, target);
     419                        usb_hub_init_add_device(hub, port);
    420420                } else {
    421                         usb_hub_removed_device(hub, hc, port, target);
     421                        usb_hub_removed_device(hub, port);
    422422                }
    423423        }
     
    426426                dprintf(USB_LOG_LEVEL_INFO, "port reset complete");
    427427                if (usb_port_enabled(&status)) {
    428                         usb_hub_finalize_add_device(hub, hc, port, target);
     428                        usb_hub_finalize_add_device(hub, port);
    429429                } else {
    430430                        dprintf(USB_LOG_LEVEL_WARNING, "ERROR: port reset, but port still not enabled");
     
    442442        /// \TODO handle other changes
    443443        /// \TODO debug log for various situations
     444        usb_endpoint_pipe_end_session(&hub->endpoints.control);
     445
    444446
    445447}
     
    459461                fibril_mutex_unlock(&usb_hub_list_lock);
    460462                usb_hub_info_t * hub_info = ((usb_hub_info_t*)lst_item->data);
     463                int opResult;
     464
     465                opResult = usb_endpoint_pipe_start_session(&hub_info->endpoints.status_change);
     466                if(opResult != EOK){
     467                        continue;
     468                }
    461469                /*
    462470                 * Check status change pipe of this hub.
    463471                 */
    464 
     472                /*
    465473                usb_target_t target;
    466                 target.address = hub_info->address;
     474                target.address = hub_info->usb_device->address;
    467475                target.endpoint = 1;/// \TODO get from endpoint descriptor
    468476                dprintf(USB_LOG_LEVEL_INFO, "checking changes for hub at addr %d",
    469477                    target.address);
    470 
     478                */
    471479                size_t port_count = hub_info->port_count;
    472480
    473481                /*
    474482                 * Connect to respective HC.
    475                  */
     483                 *
    476484                int hc = usb_drv_hc_connect_auto(hub_info->device, 0);
    477485                if (hc < 0) {
    478486                        continue;
    479                 }
     487                }*/
    480488
    481489                /// FIXME: count properly
     
    489497                 * Send the request.
    490498                 */
    491                 int opResult = usb_drv_async_interrupt_in(hc, target,
     499                opResult = usb_endpoint_pipe_read(
     500                                &hub_info->endpoints.status_change,
    492501                                change_bitmap, byte_length, &actual_size,
    493                                 &handle);
     502                                );
    494503
    495504                usb_drv_async_wait_for(handle);
     
    506515                        if (interrupt) {
    507516                                usb_hub_process_interrupt(
    508                                         hub_info, hc, port, hub_info->address);
     517                                        hub_info, port);
    509518                        }
    510519                }
     520                usb_endpoint_pipe_end_session(&hub_info->endpoints.status_change);
    511521                free(change_bitmap);
    512 
    513                 async_hangup(hc);
     522               
     523
     524                //async_hangup(hc);
    514525                fibril_mutex_lock(&usb_hub_list_lock);
    515526        }
Note: See TracChangeset for help on using the changeset viewer.