Changes in / [deece2f:fb78ae72] in mainline


Ignore:
Files:
5 added
9 deleted
43 edited

Legend:

Unmodified
Added
Removed
  • .bzrignore

    rdeece2f rfb78ae72  
    8888./uspace/drv/usbhub/usbhub
    8989./uspace/drv/usbhid/usbhid
    90 ./uspace/drv/usbmid/usbmid
    9190./uspace/drv/vhc/vhc
    9291./uspace/srv/bd/ata_bd/ata_bd
  • boot/arch/amd64/Makefile.inc

    rdeece2f rfb78ae72  
    4747        usbhub \
    4848        usbhid \
    49         usbmid \
    5049        vhc
    5150
  • uspace/Makefile

    rdeece2f rfb78ae72  
    121121                drv/usbhid \
    122122                drv/usbhub \
    123                 drv/usbmid \
    124123                drv/vhc
    125124endif
     
    137136                drv/usbhid \
    138137                drv/usbhub \
    139                 drv/usbmid \
    140138                drv/vhc
    141139endif
  • uspace/app/usbinfo/info.c

    rdeece2f rfb78ae72  
    3737#include <str_error.h>
    3838#include <errno.h>
     39#include <usb/usbdrv.h>
    3940#include <usb/pipes.h>
    4041#include <usb/recognise.h>
  • uspace/app/usbinfo/main.c

    rdeece2f rfb78ae72  
    4343#include <devman.h>
    4444#include <devmap.h>
     45#include <usb/usbdrv.h>
    4546#include "usbinfo.h"
    4647
  • uspace/doc/doxygroups.h

    rdeece2f rfb78ae72  
    220220
    221221        /**
    222          * @defgroup drvusbmid USB multi interface device driver
    223          * @ingroup usb
    224          * @brief USB multi interface device driver
    225          * @details
    226          * This driver serves as a mini hub (or bus) driver for devices
    227          * that have the class defined at interface level (those devices
    228          * usually have several interfaces).
    229          *
    230          * The term multi interface device driver (MID) was borrowed
    231          * Solaris operating system.
    232          */
    233 
    234         /**
    235222         * @defgroup drvusbhub USB hub driver
    236223         * @ingroup usb
  • uspace/drv/uhci-hcd/iface.c

    rdeece2f rfb78ae72  
    4242#include "uhci.h"
    4343
     44static int get_address(device_t *dev, devman_handle_t handle,
     45    usb_address_t *address)
     46{
     47        assert(dev);
     48        uhci_t *hc = dev_to_uhci(dev);
     49        assert(hc);
     50        *address = usb_address_keeping_find(&hc->address_manager, handle);
     51        if (*address <= 0)
     52          return *address;
     53        return EOK;
     54}
    4455/*----------------------------------------------------------------------------*/
    4556static int reserve_default_address(device_t *dev, usb_speed_t speed)
     
    157168/*----------------------------------------------------------------------------*/
    158169usbhc_iface_t uhci_iface = {
     170        .tell_address = get_address,
     171
    159172        .reserve_default_address = reserve_default_address,
    160173        .release_default_address = release_default_address,
  • uspace/drv/uhci-hcd/main.c

    rdeece2f rfb78ae72  
    3434#include <driver.h>
    3535#include <usb_iface.h>
    36 #include <usb/ddfiface.h>
    3736#include <device/hw_res.h>
    3837
     
    4948
    5049static int uhci_add_device(device_t *device);
     50static int usb_iface_get_hc_handle(device_t *dev, devman_handle_t *handle);
     51/*----------------------------------------------------------------------------*/
     52static int usb_iface_get_hc_handle(device_t *dev, devman_handle_t *handle)
     53{
     54        /* This shall be called only for the UHCI itself. */
     55        assert(dev->parent == NULL);
    5156
    52 static int usb_iface_get_address(device_t *dev, devman_handle_t handle,
    53     usb_address_t *address)
    54 {
    55         assert(dev);
    56         uhci_t *hc = dev_to_uhci(dev);
    57         assert(hc);
    58 
    59         usb_address_t addr = usb_address_keeping_find(&hc->address_manager,
    60             handle);
    61         if (addr < 0) {
    62                 return addr;
    63         }
    64 
    65         if (address != NULL) {
    66                 *address = addr;
    67         }
    68 
     57        *handle = dev->handle;
    6958        return EOK;
    7059}
    71 
    72 
     60/*----------------------------------------------------------------------------*/
    7361static usb_iface_t hc_usb_iface = {
    74         .get_hc_handle = usb_iface_get_hc_handle_hc_impl,
    75         .get_address = usb_iface_get_address
     62        .get_hc_handle = usb_iface_get_hc_handle
    7663};
    7764/*----------------------------------------------------------------------------*/
  • uspace/drv/uhci-rhd/main.c

    rdeece2f rfb78ae72  
    3434#include <driver.h>
    3535#include <usb_iface.h>
    36 #include <usb/ddfiface.h>
    3736
    3837#include <errno.h>
     
    5756
    5857static usb_iface_t uhci_rh_usb_iface = {
    59         .get_hc_handle = usb_iface_get_hc_handle,
    60         .get_address = usb_iface_get_address_hub_impl
     58        .get_hc_handle = usb_iface_get_hc_handle
    6159};
    6260
  • uspace/drv/uhci-rhd/root_hub.c

    rdeece2f rfb78ae72  
    3535#include <stdint.h>
    3636
     37#include <usb/usbdrv.h>
    3738#include <usb/debug.h>
    3839
  • uspace/drv/usbhid/main.c

    rdeece2f rfb78ae72  
    3636 */
    3737
     38#include <usb/usbdrv.h>
    3839#include <driver.h>
    3940#include <ipc/driver.h>
     
    264265        for (i = 0; i < count; ++i) {
    265266                printf("%d ", key_codes[i]);
    266         }
    267         printf("\n");
    268 
    269         for (i = 0; i < count; ++i) {
    270267                // TODO: Key press / release
    271268
    272269                // TODO: NOT WORKING
    273270                unsigned int key = usbkbd_parse_scancode(key_codes[i]);
    274 
    275                 if (key == 0) {
    276                         continue;
    277                 }
    278271                kbd_push_ev(KEY_PRESS, key);
    279272        }
     
    355348                {
    356349                        .pipe = &kbd_dev->poll_pipe,
    357                         .description = &poll_endpoint_description,
    358                         .interface_no =
    359                             usb_device_get_assigned_interface(kbd_dev->device)
     350                        .description = &poll_endpoint_description
    360351                }
    361352        };
  • uspace/drv/usbhub/main.c

    rdeece2f rfb78ae72  
    3434#include <errno.h>
    3535#include <async.h>
     36
     37#include <usb/usbdrv.h>
     38
    3639
    3740#include "usbhub.h"
  • uspace/drv/usbhub/port_status.h

    rdeece2f rfb78ae72  
    3535#include <bool.h>
    3636#include <sys/types.h>
    37 #include <usb/request.h>
     37#include <usb/devreq.h>
    3838#include "usbhub_private.h"
    3939
  • uspace/drv/usbhub/usbhub.c

    rdeece2f rfb78ae72  
    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        }
  • uspace/drv/usbhub/usbhub.h

    rdeece2f rfb78ae72  
    4242#define NAME "usbhub"
    4343
    44 #include <usb/hub.h>
    45 
    46 #include <usb/pipes.h>
    47 
    48 /* Hub endpoints. */
    49 typedef struct {
    50         usb_endpoint_pipe_t control;
    51         usb_endpoint_pipe_t status_change;
    52 } usb_hub_endpoints_t;
    53 
    54 
     44/** basic information about device attached to hub */
     45typedef struct{
     46        usb_address_t address;
     47        devman_handle_t devman_handle;
     48}usb_hub_attached_device_t;
    5549
    5650/** Information about attached hub. */
     
    5852        /** Number of ports. */
    5953        int port_count;
    60         /** attached device handles, for each port one */
    61         usb_hc_attached_device_t * attached_devs;
    62         /** General usb device info. */
    63         //usb_hcd_attached_device_info_t * usb_device;
     54        /** attached device handles */
     55        usb_hub_attached_device_t * attached_devs;
     56        /** USB address of the hub. */
     57        usb_address_t address;
    6458        /** General device info*/
    6559        device_t * device;
    66         /** connection to hcd */
    67         //usb_device_connection_t connection;
    68         usb_hc_connection_t connection;
    69         /** */
    70         usb_device_connection_t device_connection;
    71         /** hub endpoints */
    72         usb_hub_endpoints_t endpoints;
    7360} usb_hub_info_t;
    7461
  • uspace/drv/usbhub/usbhub_private.h

    rdeece2f rfb78ae72  
    4545#include <fibril_synch.h>
    4646
     47#include <usb/usb.h>
     48#include <usb/usbdrv.h>
    4749#include <usb/classes/hub.h>
    48 #include <usb/usb.h>
     50#include <usb/devreq.h>
    4951#include <usb/debug.h>
    50 #include <usb/request.h>
    5152
    5253//************
     
    7677 * @return
    7778 */
    78 usb_hub_info_t * usb_create_hub_info(device_t * device);
     79usb_hub_info_t * usb_create_hub_info(device_t * device, int hc);
    7980
    8081/** List of hubs maanged by this driver */
     
    9798 * @return error code
    9899 */
    99 /*
    100100int usb_drv_sync_control_read(
    101     usb_endpoint_pipe_t *pipe,
     101    int phone, usb_target_t target,
    102102    usb_device_request_setup_packet_t * request,
    103103    void * rcvd_buffer, size_t rcvd_size, size_t * actual_size
    104 );*/
     104);
    105105
    106106/**
     
    115115 * @return error code
    116116 */
    117 /*int usb_drv_sync_control_write(
    118     usb_endpoint_pipe_t *pipe,
     117int usb_drv_sync_control_write(
     118    int phone, usb_target_t target,
    119119    usb_device_request_setup_packet_t * request,
    120120    void * sent_buffer, size_t sent_size
    121 );*/
     121);
    122122
    123123/**
     
    147147 * @return Operation result
    148148 */
    149 static inline int usb_hub_clear_port_feature(usb_endpoint_pipe_t *pipe,
     149static inline int usb_hub_clear_port_feature(int hc, usb_address_t address,
    150150    int port_index,
    151151    usb_hub_class_feature_t feature) {
    152        
     152        usb_target_t target = {
     153                .address = address,
     154                .endpoint = 0
     155        };
    153156        usb_device_request_setup_packet_t clear_request = {
    154157                .request_type = USB_HUB_REQ_TYPE_CLEAR_PORT_FEATURE,
     
    158161        };
    159162        clear_request.value = feature;
    160         return usb_endpoint_pipe_control_write(pipe, &clear_request,
     163        return usb_drv_psync_control_write(hc, target, &clear_request,
    161164            sizeof(clear_request), NULL, 0);
    162165}
  • uspace/drv/usbhub/utils.c

    rdeece2f rfb78ae72  
    3838
    3939#include <usbhc_iface.h>
     40#include <usb/usbdrv.h>
    4041#include <usb/descriptor.h>
     42#include <usb/devreq.h>
    4143#include <usb/classes/hub.h>
    4244
     
    112114
    113115//control transactions
    114 /*
     116
    115117int usb_drv_sync_control_read(
    116118    int phone, usb_target_t target,
     
    197199}
    198200
    199 */
     201
    200202
    201203
  • uspace/drv/vhc/conn.h

    rdeece2f rfb78ae72  
    3838#include <usb/usb.h>
    3939#include <usbhc_iface.h>
    40 #include <usb_iface.h>
    4140#include "vhcd.h"
    4241#include "devices.h"
     
    4443void connection_handler_host(sysarg_t);
    4544
    46 extern usbhc_iface_t vhc_iface;
    47 extern usb_iface_t vhc_usb_iface;
     45usbhc_iface_t vhc_iface;
    4846
    4947void address_init(void);
  • uspace/drv/vhc/connhost.c

    rdeece2f rfb78ae72  
    3737#include <usb/usb.h>
    3838#include <usb/addrkeep.h>
    39 #include <usb/ddfiface.h>
    4039
    4140#include "vhcd.h"
     
    314313static usb_address_keeping_t addresses;
    315314
     315
     316static int reserve_default_address(device_t *dev, usb_speed_t ignored)
     317{
     318        usb_address_keeping_reserve_default(&addresses);
     319        return EOK;
     320}
     321
     322static int release_default_address(device_t *dev)
     323{
     324        usb_address_keeping_release_default(&addresses);
     325        return EOK;
     326}
     327
     328static int request_address(device_t *dev, usb_speed_t ignored,
     329    usb_address_t *address)
     330{
     331        usb_address_t addr = usb_address_keeping_request(&addresses);
     332        if (addr < 0) {
     333                return (int)addr;
     334        }
     335
     336        *address = addr;
     337        return EOK;
     338}
     339
     340static int release_address(device_t *dev, usb_address_t address)
     341{
     342        return usb_address_keeping_release(&addresses, address);
     343}
     344
     345static int bind_address(device_t *dev, usb_address_t address,
     346    devman_handle_t handle)
     347{
     348        usb_address_keeping_devman_bind(&addresses, address, handle);
     349        return EOK;
     350}
     351
    316352static int tell_address(device_t *dev, devman_handle_t handle,
    317353    usb_address_t *address)
     
    326362}
    327363
    328 static int reserve_default_address(device_t *dev, usb_speed_t ignored)
    329 {
    330         usb_address_keeping_reserve_default(&addresses);
    331         return EOK;
    332 }
    333 
    334 static int release_default_address(device_t *dev)
    335 {
    336         usb_address_keeping_release_default(&addresses);
    337         return EOK;
    338 }
    339 
    340 static int request_address(device_t *dev, usb_speed_t ignored,
    341     usb_address_t *address)
    342 {
    343         usb_address_t addr = usb_address_keeping_request(&addresses);
    344         if (addr < 0) {
    345                 return (int)addr;
    346         }
    347 
    348         *address = addr;
    349         return EOK;
    350 }
    351 
    352 static int release_address(device_t *dev, usb_address_t address)
    353 {
    354         return usb_address_keeping_release(&addresses, address);
    355 }
    356 
    357 static int bind_address(device_t *dev, usb_address_t address,
    358     devman_handle_t handle)
    359 {
    360         usb_address_keeping_devman_bind(&addresses, address, handle);
    361         return EOK;
    362 }
    363 
    364364void address_init(void)
    365365{
     
    368368
    369369usbhc_iface_t vhc_iface = {
     370        .tell_address = tell_address,
     371
    370372        .reserve_default_address = reserve_default_address,
    371373        .release_default_address = release_default_address,
     
    381383};
    382384
    383 usb_iface_t vhc_usb_iface = {
    384         .get_hc_handle = usb_iface_get_hc_handle_hc_impl,
    385         .get_address = tell_address
    386 };
    387 
    388 
    389385/**
    390386 * @}
  • uspace/drv/vhc/hcd.c

    rdeece2f rfb78ae72  
    4545
    4646#include <usb/usb.h>
    47 #include <usb/ddfiface.h>
    4847#include <usb_iface.h>
    4948#include "vhcd.h"
     
    5352#include "conn.h"
    5453
     54static int usb_iface_get_hc_handle(device_t *dev, devman_handle_t *handle)
     55{
     56        /* This shall be called only for VHC device. */
     57        assert(dev->parent == NULL);
     58
     59        *handle = dev->handle;
     60        return EOK;
     61}
     62
     63static usb_iface_t hc_usb_iface = {
     64        .get_hc_handle = usb_iface_get_hc_handle
     65};
     66
    5567static device_ops_t vhc_ops = {
    5668        .interfaces[USBHC_DEV_IFACE] = &vhc_iface,
    57         .interfaces[USB_DEV_IFACE] = &vhc_usb_iface,
     69        .interfaces[USB_DEV_IFACE] = &hc_usb_iface,
    5870        .close = on_client_close,
    5971        .default_handler = default_connection_handler
  • uspace/drv/vhc/hub.c

    rdeece2f rfb78ae72  
    4040#include <stdlib.h>
    4141#include <driver.h>
    42 #include <usb/hub.h>
     42#include <usb/usbdrv.h>
    4343#include <usb/recognise.h>
    4444
     
    7171}
    7272
    73 static int pretend_port_rest(int unused, void *unused2)
    74 {
    75         return EOK;
    76 }
    77 
    7873/** Register root hub in devman.
    7974 *
     
    8580        device_t *hc_dev = (device_t *) arg;
    8681
    87         /*
    88          * Wait until parent device is properly initialized.
    89          */
    90         int phone;
     82        int hc;
    9183        do {
    92                 phone = devman_device_connect(hc_dev->handle, 0);
    93         } while (phone < 0);
    94         async_hangup(phone);
     84                hc = usb_drv_hc_connect(hc_dev, hc_dev->handle,
     85                    IPC_FLAG_BLOCKING);
     86        } while (hc < 0);
    9587
    96         usb_hc_connection_t hc_conn;
    97         usb_hc_connection_initialize(&hc_conn, hc_dev->handle);
     88        usb_drv_reserve_default_address(hc);
    9889
    99         usb_hc_connection_open(&hc_conn);
     90        usb_address_t hub_address = usb_drv_request_address(hc);
     91        usb_drv_req_set_address(hc, USB_ADDRESS_DEFAULT, hub_address);
    10092
    101         int rc = usb_hc_new_device_wrapper(hc_dev, &hc_conn, USB_SPEED_FULL,
    102             pretend_port_rest, 0, NULL,
    103             NULL, NULL);
    104         if (rc != EOK) {
    105                 usb_log_fatal("Failed to create root hub: %s.\n",
    106                     str_error(rc));
    107         }
     93        usb_drv_release_default_address(hc);
    10894
    109         usb_hc_connection_close(&hc_conn);
     95        devman_handle_t hub_handle;
     96        usb_device_register_child_in_devman(hub_address, hc_dev->handle,
     97            hc_dev, &hub_handle);
     98        //usb_drv_register_child_in_devman(hc, hc_dev, hub_address, &hub_handle);
     99        usb_drv_bind_address(hc, hub_address, hub_handle);
    110100
    111         return 0;
     101        return EOK;
    112102}
    113103       
  • uspace/drv/vhc/hub/hub.c

    rdeece2f rfb78ae72  
    4040#include <stdlib.h>
    4141#include <driver.h>
     42#include <usb/usbdrv.h>
    4243
    4344#include "hub.h"
  • uspace/drv/vhc/hub/virthub.c

    rdeece2f rfb78ae72  
    4141#include <stdlib.h>
    4242#include <driver.h>
     43#include <usb/usbdrv.h>
    4344
    4445#include "virthub.h"
  • uspace/lib/drv/generic/remote_usb.c

    rdeece2f rfb78ae72  
    4040
    4141
    42 static void remote_usb_get_address(device_t *, void *, ipc_callid_t, ipc_call_t *);
    43 static void remote_usb_get_interface(device_t *, void *, ipc_callid_t, ipc_call_t *);
    4442static void remote_usb_get_hc_handle(device_t *, void *, ipc_callid_t, ipc_call_t *);
    4543//static void remote_usb(device_t *, void *, ipc_callid_t, ipc_call_t *);
     
    4745/** Remote USB interface operations. */
    4846static remote_iface_func_ptr_t remote_usb_iface_ops [] = {
    49         remote_usb_get_address,
    50         remote_usb_get_interface,
    5147        remote_usb_get_hc_handle
    5248};
     
    6056};
    6157
    62 
    63 void remote_usb_get_address(device_t *device, void *iface,
    64     ipc_callid_t callid, ipc_call_t *call)
    65 {
    66         usb_iface_t *usb_iface = (usb_iface_t *) iface;
    67 
    68         if (usb_iface->get_address == NULL) {
    69                 async_answer_0(callid, ENOTSUP);
    70                 return;
    71         }
    72 
    73         devman_handle_t handle = DEV_IPC_GET_ARG1(*call);
    74 
    75         usb_address_t address;
    76         int rc = usb_iface->get_address(device, handle, &address);
    77         if (rc != EOK) {
    78                 async_answer_0(callid, rc);
    79         } else {
    80                 async_answer_1(callid, EOK, address);
    81         }
    82 }
    83 
    84 void remote_usb_get_interface(device_t *device, void *iface,
    85     ipc_callid_t callid, ipc_call_t *call)
    86 {
    87         usb_iface_t *usb_iface = (usb_iface_t *) iface;
    88 
    89         if (usb_iface->get_interface == NULL) {
    90                 async_answer_0(callid, ENOTSUP);
    91                 return;
    92         }
    93 
    94         devman_handle_t handle = DEV_IPC_GET_ARG1(*call);
    95 
    96         int iface_no;
    97         int rc = usb_iface->get_interface(device, handle, &iface_no);
    98         if (rc != EOK) {
    99                 async_answer_0(callid, rc);
    100         } else {
    101                 async_answer_1(callid, EOK, iface_no);
    102         }
    103 }
    10458
    10559void remote_usb_get_hc_handle(device_t *device, void *iface,
  • uspace/lib/drv/generic/remote_usbhc.c

    rdeece2f rfb78ae72  
    4343#define HACK_MAX_PACKET_SIZE_INTERRUPT_IN 4
    4444
     45static void remote_usbhc_get_address(device_t *, void *, ipc_callid_t, ipc_call_t *);
    4546static void remote_usbhc_interrupt_out(device_t *, void *, ipc_callid_t, ipc_call_t *);
    4647static void remote_usbhc_interrupt_in(device_t *, void *, ipc_callid_t, ipc_call_t *);
    47 static void remote_usbhc_bulk_out(device_t *, void *, ipc_callid_t, ipc_call_t *);
    48 static void remote_usbhc_bulk_in(device_t *, void *, ipc_callid_t, ipc_call_t *);
    4948static void remote_usbhc_control_write(device_t *, void *, ipc_callid_t, ipc_call_t *);
    5049static void remote_usbhc_control_read(device_t *, void *, ipc_callid_t, ipc_call_t *);
     
    5857/** Remote USB host controller interface operations. */
    5958static remote_iface_func_ptr_t remote_usbhc_iface_ops [] = {
     59        remote_usbhc_get_address,
     60
    6061        remote_usbhc_reserve_default_address,
    6162        remote_usbhc_release_default_address,
     
    6768        remote_usbhc_interrupt_out,
    6869        remote_usbhc_interrupt_in,
    69 
    70         remote_usbhc_bulk_out,
    71         remote_usbhc_bulk_in,
    7270
    7371        remote_usbhc_control_write,
     
    123121}
    124122
     123void remote_usbhc_get_address(device_t *device, void *iface,
     124    ipc_callid_t callid, ipc_call_t *call)
     125{
     126        usbhc_iface_t *usb_iface = (usbhc_iface_t *) iface;
     127
     128        if (!usb_iface->tell_address) {
     129                async_answer_0(callid, ENOTSUP);
     130                return;
     131        }
     132
     133        devman_handle_t handle = DEV_IPC_GET_ARG1(*call);
     134
     135        usb_address_t address;
     136        int rc = usb_iface->tell_address(device, handle, &address);
     137        if (rc != EOK) {
     138                async_answer_0(callid, rc);
     139        } else {
     140                async_answer_1(callid, EOK, address);
     141        }
     142}
     143
    125144void remote_usbhc_reserve_default_address(device_t *device, void *iface,
    126145    ipc_callid_t callid, ipc_call_t *call)
     
    370389        return remote_usbhc_in_transfer(device, callid, call,
    371390            usb_iface->interrupt_in);
    372 }
    373 
    374 void remote_usbhc_bulk_out(device_t *device, void *iface,
    375     ipc_callid_t callid, ipc_call_t *call)
    376 {
    377         usbhc_iface_t *usb_iface = (usbhc_iface_t *) iface;
    378         assert(usb_iface != NULL);
    379 
    380         return remote_usbhc_out_transfer(device, callid, call,
    381             usb_iface->bulk_out);
    382 }
    383 
    384 void remote_usbhc_bulk_in(device_t *device, void *iface,
    385     ipc_callid_t callid, ipc_call_t *call)
    386 {
    387         usbhc_iface_t *usb_iface = (usbhc_iface_t *) iface;
    388         assert(usb_iface != NULL);
    389 
    390         return remote_usbhc_in_transfer(device, callid, call,
    391             usb_iface->bulk_in);
    392391}
    393392
  • uspace/lib/drv/include/usb_iface.h

    rdeece2f rfb78ae72  
    4141#include <usb/usb.h>
    4242typedef enum {
    43         /** Tell USB address assigned to device.
    44          * Parameters:
    45          * - devman handle id
    46          * Answer:
    47          * - EINVAL - unknown handle or handle not managed by this driver
    48          * - ENOTSUP - operation not supported (shall not happen)
    49          * - arbitrary error code if returned by remote implementation
    50          * - EOK - handle found, first parameter contains the USB address
    51          */
    52         IPC_M_USB_GET_ADDRESS,
    53 
    54         /** Tell interface number given device can use.
    55          * Parameters
    56          * - devman handle id of the device
    57          * Answer:
    58          * - ENOTSUP - operation not supported (can also mean any interface)
    59          * - EOK - operation okay, first parameter contains interface number
    60          */
    61         IPC_M_USB_GET_INTERFACE,
    62 
    6343        /** Tell devman handle of device host controller.
    6444         * Parameters:
     
    7555/** USB device communication interface. */
    7656typedef struct {
    77         int (*get_address)(device_t *, devman_handle_t, usb_address_t *);
    78         int (*get_interface)(device_t *, devman_handle_t, int *);
    7957        int (*get_hc_handle)(device_t *, devman_handle_t *);
    8058} usb_iface_t;
  • uspace/lib/drv/include/usbhc_iface.h

    rdeece2f rfb78ae72  
    8585 */
    8686typedef enum {
     87        /** Tell USB address assigned to device.
     88         * Parameters:
     89         * - devman handle id
     90         * Answer:
     91         * - EINVAL - unknown handle or handle not managed by this driver
     92         * - ENOTSUP - operation not supported by HC (shall not happen)
     93         * - arbitrary error code if returned by remote implementation
     94         * - EOK - handle found, first parameter contains the USB address
     95         */
     96        IPC_M_USBHC_GET_ADDRESS,
     97
     98
    8799        /** Reserve usage of default address.
    88100         * This call informs the host controller that the caller will be
     
    141153        IPC_M_USBHC_INTERRUPT_IN,
    142154
    143         /** Send bulk data to device.
    144          * See explanation at usb_iface_funcs_t (OUT transaction).
    145          */
    146         IPC_M_USBHC_BULK_OUT,
    147 
    148         /** Get bulk data from device.
    149          * See explanation at usb_iface_funcs_t (IN transaction).
    150          */
    151         IPC_M_USBHC_BULK_IN,
    152 
    153155        /** Issue control WRITE transfer.
    154156         * See explanation at usb_iface_funcs_t (OUT transaction) for
     
    194196/** USB host controller communication interface. */
    195197typedef struct {
     198        int (*tell_address)(device_t *, devman_handle_t, usb_address_t *);
     199
    196200        int (*reserve_default_address)(device_t *, usb_speed_t);
    197201        int (*release_default_address)(device_t *);
     
    203207        usbhc_iface_transfer_in_t interrupt_in;
    204208
    205         usbhc_iface_transfer_out_t bulk_out;
    206         usbhc_iface_transfer_in_t bulk_in;
    207 
    208209        int (*control_write)(device_t *, usb_target_t,
    209210            size_t,
  • uspace/lib/usb/Makefile

    rdeece2f rfb78ae72  
    3535        src/addrkeep.c \
    3636        src/class.c \
    37         src/ddfiface.c \
    3837        src/debug.c \
    3938        src/dp.c \
     39        src/drvpsync.c \
    4040        src/dump.c \
    4141        src/hidparser.c \
     
    4848        src/usb.c \
    4949        src/usbdevice.c \
     50        src/usbdrvreq.c \
     51        src/usbdrv.c \
    5052        src/usbmem.c
    5153
  • uspace/lib/usb/include/usb/classes/hub.h

    rdeece2f rfb78ae72  
    11/*
    2  * Copyright (c) 2010 Matus Dekanek
     2 * Copyright (c) 2010 Vojtech Horky
    33 * All rights reserved.
    44 *
     
    3333 * @brief USB hub related structures.
    3434 */
    35 #ifndef LIBUSB_CLASS_HUB_H_
    36 #define LIBUSB_CLASS_HUB_H_
     35#ifndef LIBUSB_HUB_H_
     36#define LIBUSB_HUB_H_
    3737
    3838#include <sys/types.h>
  • uspace/lib/usb/include/usb/dp.h

    rdeece2f rfb78ae72  
    4545} usb_dp_descriptor_nesting_t;
    4646
    47 extern usb_dp_descriptor_nesting_t usb_dp_standard_descriptor_nesting[];
    48 
    4947typedef struct {
    5048        usb_dp_descriptor_nesting_t *nesting;
  • uspace/lib/usb/include/usb/pipes.h

    rdeece2f rfb78ae72  
    107107        /** Endpoint description. */
    108108        const usb_endpoint_description_t *description;
    109         /** Interface number the endpoint must belong to (-1 for any). */
    110         const int interface_no;
    111109        /** Found descriptor fitting the description. */
    112110        usb_standard_endpoint_descriptor_t *descriptor;
     
    123121int usb_device_connection_initialize(usb_device_connection_t *,
    124122    devman_handle_t, usb_address_t);
    125 
    126 int usb_device_get_assigned_interface(device_t *);
    127123
    128124int usb_endpoint_pipe_initialize(usb_endpoint_pipe_t *,
  • uspace/lib/usb/include/usb/recognise.h

    rdeece2f rfb78ae72  
    4141#include <ipc/devman.h>
    4242
    43 int usb_device_create_match_ids_from_device_descriptor(
    44     const usb_standard_device_descriptor_t *, match_id_list_t *);
    45 
    46 int usb_device_create_match_ids_from_interface(
    47     const usb_standard_device_descriptor_t *,
    48     const usb_standard_interface_descriptor_t *, match_id_list_t *);
    49 
    5043int usb_device_create_match_ids(usb_endpoint_pipe_t *, match_id_list_t *);
    5144
  • uspace/lib/usb/include/usb/request.h

    rdeece2f rfb78ae72  
    4141#include <usb/descriptor.h>
    4242
    43 /** Standard device request. */
    44 typedef enum {
    45         USB_DEVREQ_GET_STATUS = 0,
    46         USB_DEVREQ_CLEAR_FEATURE = 1,
    47         USB_DEVREQ_SET_FEATURE = 3,
    48         USB_DEVREQ_SET_ADDRESS = 5,
    49         USB_DEVREQ_GET_DESCRIPTOR = 6,
    50         USB_DEVREQ_SET_DESCRIPTOR = 7,
    51         USB_DEVREQ_GET_CONFIGURATION = 8,
    52         USB_DEVREQ_SET_CONFIGURATION = 9,
    53         USB_DEVREQ_GET_INTERFACE = 10,
    54         USB_DEVREQ_SET_INTERFACE = 11,
    55         USB_DEVREQ_SYNCH_FRAME = 12,
    56         USB_DEVREQ_LAST_STD
    57 } usb_stddevreq_t;
    58 
    59 /** Device request setup packet.
    60  * The setup packet describes the request.
    61  */
    62 typedef struct {
    63         /** Request type.
    64          * The type combines transfer direction, request type and
    65          * intended recipient.
    66          */
    67         uint8_t request_type;
    68         /** Request identification. */
    69         uint8_t request;
    70         /** Main parameter to the request. */
    71         union {
    72                 uint16_t value;
    73                 /* FIXME: add #ifdefs according to host endianess */
    74                 struct {
    75                         uint8_t value_low;
    76                         uint8_t value_high;
    77                 };
    78         };
    79         /** Auxiliary parameter to the request.
    80          * Typically, it is offset to something.
    81          */
    82         uint16_t index;
    83         /** Length of extra data. */
    84         uint16_t length;
    85 } __attribute__ ((packed)) usb_device_request_setup_packet_t;
    86 
    8743int usb_control_request_set(usb_endpoint_pipe_t *,
    8844    usb_request_type_t, usb_request_recipient_t, uint8_t,
  • uspace/lib/usb/src/dp.c

    rdeece2f rfb78ae72  
    3737#include <str_error.h>
    3838#include <errno.h>
    39 #include <assert.h>
     39#include <usb/usbdrv.h>
    4040#include <bool.h>
    4141#include <usb/dp.h>
    42 #include <usb/descriptor.h>
    43 
    44 #define NESTING(parentname, childname) \
    45         { \
    46                 .child = USB_DESCTYPE_##childname, \
    47                 .parent = USB_DESCTYPE_##parentname, \
    48         }
    49 #define LAST_NESTING { -1, -1 }
    50 
    51 /** Nesting of standard USB descriptors. */
    52 usb_dp_descriptor_nesting_t usb_dp_standard_descriptor_nesting[] = {
    53         NESTING(CONFIGURATION, INTERFACE),
    54         NESTING(INTERFACE, ENDPOINT),
    55         NESTING(INTERFACE, HUB),
    56         NESTING(INTERFACE, HID),
    57         NESTING(HID, HID_REPORT),
    58         LAST_NESTING
    59 };
    60 
    61 #undef NESTING
    62 #undef LAST_NESTING
    6342
    6443/** Tells whether pointer points inside descriptor data.
  • uspace/lib/usb/src/hub.c

    rdeece2f rfb78ae72  
    301301}
    302302
     303
    303304/**
    304305 * @}
  • uspace/lib/usb/src/pipes.c

    rdeece2f rfb78ae72  
    3636#include <usb/pipes.h>
    3737#include <usbhc_iface.h>
    38 #include <usb_iface.h>
    3938#include <errno.h>
    4039#include <assert.h>
     
    4241/** Tell USB address assigned to given device.
    4342 *
    44  * @param phone Phone to parent device.
     43 * @param phone Phone to my HC.
    4544 * @param dev Device in question.
    4645 * @return USB address or error code.
     
    4948{
    5049        sysarg_t address;
    51         int rc = async_req_2_1(phone, DEV_IFACE_ID(USB_DEV_IFACE),
    52             IPC_M_USB_GET_ADDRESS,
     50        int rc = async_req_2_1(phone, DEV_IFACE_ID(USBHC_DEV_IFACE),
     51            IPC_M_USBHC_GET_ADDRESS,
    5352            dev->handle, &address);
    5453
     
    5857
    5958        return (usb_address_t) address;
    60 }
    61 
    62 /** Tell USB interface assigned to given device.
    63  *
    64  * @param device Device in question.
    65  * @return Interface number (negative code means any).
    66  */
    67 int usb_device_get_assigned_interface(device_t *device)
    68 {
    69         int parent_phone = devman_parent_device_connect(device->handle,
    70             IPC_FLAG_BLOCKING);
    71         if (parent_phone < 0) {
    72                 return -1;
    73         }
    74 
    75         sysarg_t iface_no;
    76         int rc = async_req_2_1(parent_phone, DEV_IFACE_ID(USB_DEV_IFACE),
    77             IPC_M_USB_GET_INTERFACE,
    78             device->handle, &iface_no);
    79 
    80         async_hangup(parent_phone);
    81 
    82         if (rc != EOK) {
    83                 return -1;
    84         }
    85 
    86         return (int) iface_no;
    8759}
    8860
     
    10880        }
    10981
    110         int parent_phone = devman_parent_device_connect(device->handle,
    111             IPC_FLAG_BLOCKING);
    112         if (parent_phone < 0) {
    113                 return parent_phone;
    114         }
    115 
    116         my_address = get_my_address(parent_phone, device);
     82        int hc_phone = devman_device_connect(hc_handle, 0);
     83        if (hc_phone < 0) {
     84                return hc_phone;
     85        }
     86
     87        my_address = get_my_address(hc_phone, device);
    11788        if (my_address < 0) {
    11889                rc = my_address;
     
    12495
    12596leave:
    126         async_hangup(parent_phone);
     97        async_hangup(hc_phone);
    12798        return rc;
    12899}
  • uspace/lib/usb/src/pipesinit.c

    rdeece2f rfb78ae72  
    109109 * @param mapping_count Number of endpoint mappings in @p mapping.
    110110 * @param found_endpoint Description of found endpoint.
    111  * @param interface_number Number of currently processed interface.
    112111 * @return Endpoint mapping corresponding to @p found_endpoint.
    113112 * @retval NULL No corresponding endpoint found.
     
    115114static usb_endpoint_mapping_t *find_endpoint_mapping(
    116115    usb_endpoint_mapping_t *mapping, size_t mapping_count,
    117     usb_endpoint_description_t *found_endpoint,
    118     int interface_number)
     116    usb_endpoint_description_t *found_endpoint)
    119117{
    120118        while (mapping_count > 0) {
    121                 bool interface_number_fits = (mapping->interface_no < 0)
    122                     || (mapping->interface_no == interface_number);
    123 
    124                 bool endpoint_descriptions_fits = endpoint_fits_description(
    125                     mapping->description, found_endpoint);
    126 
    127                 if (interface_number_fits && endpoint_descriptions_fits) {
     119                if (endpoint_fits_description(mapping->description,
     120                    found_endpoint)) {
    128121                        return mapping;
    129122                }
     
    176169         */
    177170        usb_endpoint_mapping_t *ep_mapping = find_endpoint_mapping(mapping,
    178             mapping_count, &description, interface->interface_number);
     171            mapping_count, &description);
    179172        if (ep_mapping == NULL) {
    180173                return ENOENT;
  • uspace/lib/usb/src/pipesio.c

    rdeece2f rfb78ae72  
    7171                        ipc_method = IPC_M_USBHC_INTERRUPT_IN;
    7272                        break;
    73                 case USB_TRANSFER_BULK:
    74                         ipc_method = IPC_M_USBHC_BULK_IN;
    75                         break;
    7673                default:
    7774                        return ENOTSUP;
     
    197194                case USB_TRANSFER_INTERRUPT:
    198195                        ipc_method = IPC_M_USBHC_INTERRUPT_OUT;
    199                         break;
    200                 case USB_TRANSFER_BULK:
    201                         ipc_method = IPC_M_USBHC_BULK_OUT;
    202196                        break;
    203197                default:
  • uspace/lib/usb/src/recognise.c

    rdeece2f rfb78ae72  
    3434 */
    3535#include <sys/types.h>
     36#include <usb_iface.h>
     37#include <usb/usbdrv.h>
    3638#include <usb/pipes.h>
    3739#include <usb/recognise.h>
    38 #include <usb/ddfiface.h>
    3940#include <usb/request.h>
    4041#include <usb/classes/classes.h>
     
    4546static FIBRIL_MUTEX_INITIALIZE(device_name_index_mutex);
    4647
     48/** Callback for getting host controller handle.
     49 *
     50 * @param dev Device in question.
     51 * @param[out] handle Devman handle of the host controller.
     52 * @return Error code.
     53 */
     54static int usb_iface_get_hc_handle(device_t *dev, devman_handle_t *handle)
     55{
     56        assert(dev);
     57        assert(dev->parent != NULL);
     58
     59        device_t *parent = dev->parent;
     60
     61        if (parent->ops && parent->ops->interfaces[USB_DEV_IFACE]) {
     62                usb_iface_t *usb_iface
     63                    = (usb_iface_t *) parent->ops->interfaces[USB_DEV_IFACE];
     64                assert(usb_iface != NULL);
     65                if (usb_iface->get_hc_handle) {
     66                        int rc = usb_iface->get_hc_handle(parent, handle);
     67                        return rc;
     68                }
     69        }
     70
     71        return ENOTSUP;
     72}
     73
     74static usb_iface_t usb_iface = {
     75        .get_hc_handle = usb_iface_get_hc_handle
     76};
     77
    4778device_ops_t child_ops = {
    48         .interfaces[USB_DEV_IFACE] = &usb_iface_hub_child_impl
     79        .interfaces[USB_DEV_IFACE] = &usb_iface
    4980};
    5081
     
    111142}
    112143
    113 #define ADD_MATCHID_OR_RETURN(match_ids, score, format, ...) \
    114         do { \
    115                 int __rc = usb_add_match_id((match_ids), (score), \
    116                     format, ##__VA_ARGS__); \
    117                 if (__rc != EOK) { \
    118                         return __rc; \
    119                 } \
    120         } while (0)
    121 
    122 /** Create device match ids based on its interface.
    123  *
    124  * @param[in] descriptor Interface descriptor.
    125  * @param[out] matches Initialized list of match ids.
    126  * @return Error code (the two mentioned are not the only ones).
    127  * @retval EINVAL Invalid input parameters (expects non NULL pointers).
    128  * @retval ENOENT Interface does not specify class.
    129  */
    130 int usb_device_create_match_ids_from_interface(
    131     const usb_standard_device_descriptor_t *desc_device,
    132     const usb_standard_interface_descriptor_t *desc_interface,
    133     match_id_list_t *matches)
    134 {
    135         if (desc_interface == NULL) {
    136                 return EINVAL;
    137         }
    138         if (matches == NULL) {
    139                 return EINVAL;
    140         }
    141 
    142         if (desc_interface->interface_class == USB_CLASS_USE_INTERFACE) {
    143                 return ENOENT;
    144         }
    145 
    146         const char *classname = usb_str_class(desc_interface->interface_class);
    147         assert(classname != NULL);
    148 
    149 #define IFACE_PROTOCOL_FMT "interface&class=%s&subclass=0x%02x&protocol=0x%02x"
    150 #define IFACE_PROTOCOL_ARGS classname, desc_interface->interface_subclass, \
    151     desc_interface->interface_protocol
    152 
    153 #define IFACE_SUBCLASS_FMT "interface&class=%s&subclass=0x%02x"
    154 #define IFACE_SUBCLASS_ARGS classname, desc_interface->interface_subclass
    155 
    156 #define IFACE_CLASS_FMT "interface&class=%s"
    157 #define IFACE_CLASS_ARGS classname
    158 
    159 #define VENDOR_RELEASE_FMT "vendor=0x%04x&product=0x%04x&release=" BCD_FMT
    160 #define VENDOR_RELEASE_ARGS desc_device->vendor_id, desc_device->product_id, \
    161     BCD_ARGS(desc_device->device_version)
    162 
    163 #define VENDOR_PRODUCT_FMT "vendor=0x%04x&product=0x%04x"
    164 #define VENDOR_PRODUCT_ARGS desc_device->vendor_id, desc_device->product_id
    165 
    166 #define VENDOR_ONLY_FMT "vendor=0x%04x"
    167 #define VENDOR_ONLY_ARGS desc_device->vendor_id
    168 
    169         /*
    170          * If the vendor is specified, create match ids with vendor with
    171          * higher score.
    172          * Then the same ones without the vendor part.
    173          */
    174         if ((desc_device != NULL) && (desc_device->vendor_id != 0)) {
    175                 /* First, interface matches with device release number. */
    176                 ADD_MATCHID_OR_RETURN(matches, 250,
    177                     "usb&" VENDOR_RELEASE_FMT "&" IFACE_PROTOCOL_FMT,
    178                     VENDOR_RELEASE_ARGS, IFACE_PROTOCOL_ARGS);
    179                 ADD_MATCHID_OR_RETURN(matches, 240,
    180                     "usb&" VENDOR_RELEASE_FMT "&" IFACE_SUBCLASS_FMT,
    181                     VENDOR_RELEASE_ARGS, IFACE_SUBCLASS_ARGS);
    182                 ADD_MATCHID_OR_RETURN(matches, 230,
    183                     "usb&" VENDOR_RELEASE_FMT "&" IFACE_CLASS_FMT,
    184                     VENDOR_RELEASE_ARGS, IFACE_CLASS_ARGS);
    185 
    186                 /* Next, interface matches without release number. */
    187                 ADD_MATCHID_OR_RETURN(matches, 220,
    188                     "usb&" VENDOR_PRODUCT_FMT "&" IFACE_PROTOCOL_FMT,
    189                     VENDOR_PRODUCT_ARGS, IFACE_PROTOCOL_ARGS);
    190                 ADD_MATCHID_OR_RETURN(matches, 210,
    191                     "usb&" VENDOR_PRODUCT_FMT "&" IFACE_SUBCLASS_FMT,
    192                     VENDOR_PRODUCT_ARGS, IFACE_SUBCLASS_ARGS);
    193                 ADD_MATCHID_OR_RETURN(matches, 200,
    194                     "usb&" VENDOR_PRODUCT_FMT "&" IFACE_CLASS_FMT,
    195                     VENDOR_PRODUCT_ARGS, IFACE_CLASS_ARGS);
    196 
    197                 /* Finally, interface matches with only vendor. */
    198                 ADD_MATCHID_OR_RETURN(matches, 190,
    199                     "usb&" VENDOR_ONLY_FMT "&" IFACE_PROTOCOL_FMT,
    200                     VENDOR_ONLY_ARGS, IFACE_PROTOCOL_ARGS);
    201                 ADD_MATCHID_OR_RETURN(matches, 180,
    202                     "usb&" VENDOR_ONLY_FMT "&" IFACE_SUBCLASS_FMT,
    203                     VENDOR_ONLY_ARGS, IFACE_SUBCLASS_ARGS);
    204                 ADD_MATCHID_OR_RETURN(matches, 170,
    205                     "usb&" VENDOR_ONLY_FMT "&" IFACE_CLASS_FMT,
    206                     VENDOR_ONLY_ARGS, IFACE_CLASS_ARGS);
    207         }
    208 
    209         /* Now, the same but without any vendor specification. */
    210         ADD_MATCHID_OR_RETURN(matches, 160,
    211             "usb&" IFACE_PROTOCOL_FMT,
    212             IFACE_PROTOCOL_ARGS);
    213         ADD_MATCHID_OR_RETURN(matches, 150,
    214             "usb&" IFACE_SUBCLASS_FMT,
    215             IFACE_SUBCLASS_ARGS);
    216         ADD_MATCHID_OR_RETURN(matches, 140,
    217             "usb&" IFACE_CLASS_FMT,
    218             IFACE_CLASS_ARGS);
    219 
    220 #undef IFACE_PROTOCOL_FMT
    221 #undef IFACE_PROTOCOL_ARGS
    222 #undef IFACE_SUBCLASS_FMT
    223 #undef IFACE_SUBCLASS_ARGS
    224 #undef IFACE_CLASS_FMT
    225 #undef IFACE_CLASS_ARGS
    226 #undef VENDOR_RELEASE_FMT
    227 #undef VENDOR_RELEASE_ARGS
    228 #undef VENDOR_PRODUCT_FMT
    229 #undef VENDOR_PRODUCT_ARGS
    230 #undef VENDOR_ONLY_FMT
    231 #undef VENDOR_ONLY_ARGS
    232 
    233         return EOK;
    234 }
    235 
    236144/** Create DDF match ids from USB device descriptor.
    237145 *
     
    240148 * @return Error code.
    241149 */
    242 int usb_device_create_match_ids_from_device_descriptor(
    243     const usb_standard_device_descriptor_t *device_descriptor,
    244     match_id_list_t *matches)
    245 {
     150int usb_drv_create_match_ids_from_device_descriptor(
     151    match_id_list_t *matches,
     152    const usb_standard_device_descriptor_t *device_descriptor)
     153{
     154        int rc;
     155       
    246156        /*
    247157         * Unless the vendor id is 0, the pair idVendor-idProduct
     
    250160        if (device_descriptor->vendor_id != 0) {
    251161                /* First, with release number. */
    252                 ADD_MATCHID_OR_RETURN(matches, 100,
     162                rc = usb_add_match_id(matches, 100,
    253163                    "usb&vendor=0x%04x&product=0x%04x&release=" BCD_FMT,
    254164                    (int) device_descriptor->vendor_id,
    255165                    (int) device_descriptor->product_id,
    256166                    BCD_ARGS(device_descriptor->device_version));
     167                if (rc != EOK) {
     168                        return rc;
     169                }
    257170               
    258171                /* Next, without release number. */
    259                 ADD_MATCHID_OR_RETURN(matches, 90,
     172                rc = usb_add_match_id(matches, 90,
    260173                    "usb&vendor=0x%04x&product=0x%04x",
    261174                    (int) device_descriptor->vendor_id,
    262175                    (int) device_descriptor->product_id);
     176                if (rc != EOK) {
     177                        return rc;
     178                }
    263179        }       
    264180
    265181        /*
    266182         * If the device class points to interface we skip adding
    267          * class directly but we add a multi interface device.
     183         * class directly.
    268184         */
    269185        if (device_descriptor->device_class != USB_CLASS_USE_INTERFACE) {
    270                 ADD_MATCHID_OR_RETURN(matches, 50, "usb&class=%s",
     186                rc = usb_add_match_id(matches, 50, "usb&class=%s",
    271187                    usb_str_class(device_descriptor->device_class));
    272         } else {
    273                 ADD_MATCHID_OR_RETURN(matches, 50, "usb&mid");
     188                if (rc != EOK) {
     189                        return rc;
     190                }
    274191        }
    275192       
     
    277194}
    278195
     196/** Create DDF match ids from USB configuration descriptor.
     197 * The configuration descriptor is expected to be in the complete form,
     198 * i.e. including interface, endpoint etc. descriptors.
     199 *
     200 * @param matches List of match ids to extend.
     201 * @param config_descriptor Configuration descriptor returned by given device.
     202 * @param total_size Size of the @p config_descriptor.
     203 * @return Error code.
     204 */
     205int usb_drv_create_match_ids_from_configuration_descriptor(
     206    match_id_list_t *matches,
     207    const void *config_descriptor, size_t total_size)
     208{
     209        /*
     210         * Iterate through config descriptor to find the interface
     211         * descriptors.
     212         */
     213        size_t position = sizeof(usb_standard_configuration_descriptor_t);
     214        while (position + 1 < total_size) {
     215                uint8_t *current_descriptor
     216                    = ((uint8_t *) config_descriptor) + position;
     217                uint8_t cur_descr_len = current_descriptor[0];
     218                uint8_t cur_descr_type = current_descriptor[1];
     219
     220                if (cur_descr_len == 0) {
     221                        return ENOENT;
     222                }
     223               
     224                position += cur_descr_len;
     225               
     226                if (cur_descr_type != USB_DESCTYPE_INTERFACE) {
     227                        continue;
     228                }
     229               
     230                /*
     231                 * Finally, we found an interface descriptor.
     232                 */
     233                usb_standard_interface_descriptor_t *interface
     234                    = (usb_standard_interface_descriptor_t *)
     235                    current_descriptor;
     236               
     237                int rc = usb_add_match_id(matches, 50,
     238                    "usb&interface&class=%s",
     239                    usb_str_class(interface->interface_class));
     240                if (rc != EOK) {
     241                        return rc;
     242                }
     243        }
     244       
     245        return EOK;
     246}
     247
     248/** Add match ids based on configuration descriptor.
     249 *
     250 * @param pipe Control pipe to the device.
     251 * @param matches Match ids list to add matches to.
     252 * @param config_count Number of configurations the device has.
     253 * @return Error code.
     254 */
     255static int usb_add_config_descriptor_match_ids(usb_endpoint_pipe_t *pipe,
     256    match_id_list_t *matches, int config_count)
     257{
     258        int final_rc = EOK;
     259       
     260        int config_index;
     261        for (config_index = 0; config_index < config_count; config_index++) {
     262                int rc;
     263                usb_standard_configuration_descriptor_t config_descriptor;
     264                rc = usb_request_get_bare_configuration_descriptor(pipe,
     265                    config_index, &config_descriptor);
     266                if (rc != EOK) {
     267                        final_rc = rc;
     268                        continue;
     269                }
     270
     271                size_t full_config_descriptor_size;
     272                void *full_config_descriptor
     273                    = malloc(config_descriptor.total_length);
     274                rc = usb_request_get_full_configuration_descriptor(pipe,
     275                    config_index,
     276                    full_config_descriptor, config_descriptor.total_length,
     277                    &full_config_descriptor_size);
     278                if (rc != EOK) {
     279                        final_rc = rc;
     280                        continue;
     281                }
     282                if (full_config_descriptor_size
     283                    != config_descriptor.total_length) {
     284                        final_rc = ERANGE;
     285                        continue;
     286                }
     287               
     288                rc = usb_drv_create_match_ids_from_configuration_descriptor(
     289                    matches,
     290                    full_config_descriptor, full_config_descriptor_size);
     291                if (rc != EOK) {
     292                        final_rc = rc;
     293                        continue;
     294                }
     295               
     296        }
     297       
     298        return final_rc;
     299}
    279300
    280301/** Create match ids describing attached device.
     
    302323        }
    303324
    304         rc = usb_device_create_match_ids_from_device_descriptor(
    305             &device_descriptor, matches);
     325        rc = usb_drv_create_match_ids_from_device_descriptor(matches,
     326            &device_descriptor);
    306327        if (rc != EOK) {
    307328                return rc;
     
    309330
    310331        /*
     332         * Go through all configurations and add matches
     333         * based on interface class.
     334         */
     335        rc = usb_add_config_descriptor_match_ids(ctrl_pipe, matches,
     336            device_descriptor.configuration_count);
     337        if (rc != EOK) {
     338                return rc;
     339        }
     340
     341        /*
    311342         * As a fallback, provide the simplest match id possible.
    312343         */
    313         ADD_MATCHID_OR_RETURN(matches, 1, "usb&fallback");
     344        rc = usb_add_match_id(matches, 1, "usb&fallback");
     345        if (rc != EOK) {
     346                return rc;
     347        }
    314348
    315349        return EOK;
  • uspace/lib/usb/src/request.c

    rdeece2f rfb78ae72  
    3434 */
    3535#include <usb/request.h>
     36#include <usb/devreq.h>
    3637#include <errno.h>
    3738
  • uspace/lib/usbvirt/Makefile

    rdeece2f rfb78ae72  
    3030LIBRARY = libusbvirt
    3131
    32 EXTRA_CFLAGS = -I$(LIBUSB_PREFIX)/include -I$(LIBDRV_PREFIX)/include -Iinclude
     32EXTRA_CFLAGS = -I$(LIBUSB_PREFIX)/include -Iinclude
    3333
    3434SOURCES = \
  • uspace/lib/usbvirt/include/usbvirt/device.h

    rdeece2f rfb78ae72  
    3737
    3838#include <usb/usb.h>
    39 #include <usb/request.h>
    4039#include <usb/descriptor.h>
     40#include <usb/devreq.h>
    4141
    4242/** Request type of a control transfer. */
  • uspace/lib/usbvirt/src/stdreq.c

    rdeece2f rfb78ae72  
    3636#include <stdlib.h>
    3737#include <mem.h>
    38 #include <usb/request.h>
     38#include <usb/devreq.h>
    3939
    4040#include "private.h"
Note: See TracChangeset for help on using the changeset viewer.