Changeset deece2f in mainline


Ignore:
Timestamp:
2011-02-21T22:25:58Z (13 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
233e68d
Parents:
fb78ae72 (diff), dbe25f1 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Development branch merge

Files:
9 added
5 deleted
43 edited

Legend:

Unmodified
Added
Removed
  • .bzrignore

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

    rfb78ae72 rdeece2f  
    4747        usbhub \
    4848        usbhid \
     49        usbmid \
    4950        vhc
    5051
  • uspace/Makefile

    rfb78ae72 rdeece2f  
    121121                drv/usbhid \
    122122                drv/usbhub \
     123                drv/usbmid \
    123124                drv/vhc
    124125endif
     
    136137                drv/usbhid \
    137138                drv/usbhub \
     139                drv/usbmid \
    138140                drv/vhc
    139141endif
  • uspace/app/usbinfo/info.c

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

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

    rfb78ae72 rdeece2f  
    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        /**
    222235         * @defgroup drvusbhub USB hub driver
    223236         * @ingroup usb
  • uspace/drv/uhci-hcd/iface.c

    rfb78ae72 rdeece2f  
    4242#include "uhci.h"
    4343
    44 static 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 }
    5544/*----------------------------------------------------------------------------*/
    5645static int reserve_default_address(device_t *dev, usb_speed_t speed)
     
    168157/*----------------------------------------------------------------------------*/
    169158usbhc_iface_t uhci_iface = {
    170         .tell_address = get_address,
    171 
    172159        .reserve_default_address = reserve_default_address,
    173160        .release_default_address = release_default_address,
  • uspace/drv/uhci-hcd/main.c

    rfb78ae72 rdeece2f  
    3434#include <driver.h>
    3535#include <usb_iface.h>
     36#include <usb/ddfiface.h>
    3637#include <device/hw_res.h>
    3738
     
    4849
    4950static int uhci_add_device(device_t *device);
    50 static int usb_iface_get_hc_handle(device_t *dev, devman_handle_t *handle);
    51 /*----------------------------------------------------------------------------*/
    52 static int usb_iface_get_hc_handle(device_t *dev, devman_handle_t *handle)
     51
     52static int usb_iface_get_address(device_t *dev, devman_handle_t handle,
     53    usb_address_t *address)
    5354{
    54         /* This shall be called only for the UHCI itself. */
    55         assert(dev->parent == NULL);
     55        assert(dev);
     56        uhci_t *hc = dev_to_uhci(dev);
     57        assert(hc);
    5658
    57         *handle = dev->handle;
     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
    5869        return EOK;
    5970}
    60 /*----------------------------------------------------------------------------*/
     71
     72
    6173static usb_iface_t hc_usb_iface = {
    62         .get_hc_handle = usb_iface_get_hc_handle
     74        .get_hc_handle = usb_iface_get_hc_handle_hc_impl,
     75        .get_address = usb_iface_get_address
    6376};
    6477/*----------------------------------------------------------------------------*/
  • uspace/drv/uhci-rhd/main.c

    rfb78ae72 rdeece2f  
    3434#include <driver.h>
    3535#include <usb_iface.h>
     36#include <usb/ddfiface.h>
    3637
    3738#include <errno.h>
     
    5657
    5758static usb_iface_t uhci_rh_usb_iface = {
    58         .get_hc_handle = usb_iface_get_hc_handle
     59        .get_hc_handle = usb_iface_get_hc_handle,
     60        .get_address = usb_iface_get_address_hub_impl
    5961};
    6062
  • uspace/drv/uhci-rhd/root_hub.c

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

    rfb78ae72 rdeece2f  
    3636 */
    3737
    38 #include <usb/usbdrv.h>
    3938#include <driver.h>
    4039#include <ipc/driver.h>
     
    265264        for (i = 0; i < count; ++i) {
    266265                printf("%d ", key_codes[i]);
     266        }
     267        printf("\n");
     268
     269        for (i = 0; i < count; ++i) {
    267270                // TODO: Key press / release
    268271
    269272                // TODO: NOT WORKING
    270273                unsigned int key = usbkbd_parse_scancode(key_codes[i]);
     274
     275                if (key == 0) {
     276                        continue;
     277                }
    271278                kbd_push_ev(KEY_PRESS, key);
    272279        }
     
    348355                {
    349356                        .pipe = &kbd_dev->poll_pipe,
    350                         .description = &poll_endpoint_description
     357                        .description = &poll_endpoint_description,
     358                        .interface_no =
     359                            usb_device_get_assigned_interface(kbd_dev->device)
    351360                }
    352361        };
  • uspace/drv/usbhub/main.c

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

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

    rfb78ae72 rdeece2f  
    3939
    4040#include <usb_iface.h>
    41 #include <usb/usbdrv.h>
     41#include <usb/ddfiface.h>
    4242#include <usb/descriptor.h>
    4343#include <usb/recognise.h>
    44 #include <usb/devreq.h>
     44#include <usb/request.h>
    4545#include <usb/classes/hub.h>
    4646
     
    4949#include "port_status.h"
    5050#include "usb/usb.h"
    51 
    52 static int iface_get_hc_handle(device_t *device, devman_handle_t *handle)
    53 {
    54         return usb_hc_find(device->handle, handle);
    55 }
    56 
    57 static usb_iface_t hub_usb_iface = {
    58         .get_hc_handle = iface_get_hc_handle
     51#include "usb/pipes.h"
     52#include "usb/classes/classes.h"
     53
     54static device_ops_t hub_device_ops = {
     55        .interfaces[USB_DEV_IFACE] = &usb_iface_hub_impl
    5956};
    6057
    61 static device_ops_t hub_device_ops = {
    62         .interfaces[USB_DEV_IFACE] = &hub_usb_iface
     58/** Hub status-change endpoint description */
     59static 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
    6364};
     65
    6466
    6567//*********************************************
     
    6971//*********************************************
    7072
    71 usb_hub_info_t * usb_create_hub_info(device_t * device, int hc) {
     73/**
     74 * Initialize connnections to host controller, device, and device
     75 * control endpoint
     76 * @param hub
     77 * @param device
     78 * @return
     79 */
     80static 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 */
     111static 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 */
     224usb_hub_info_t * usb_create_hub_info(device_t * device) {
    72225        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
    73234        //result->device = device;
    74235        result->port_count = -1;
    75         /// \TODO is this correct? is the device stored?
    76236        result->device = device;
    77237
    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;
     238        //result->usb_device = usb_new(usb_hcd_attached_device_info_t);
     239        size_t received_size;
    92240
    93241        // get hub descriptor
    94 
    95242        dprintf(USB_LOG_LEVEL_DEBUG, "creating serialized descripton");
    96243        void * serialized_descriptor = malloc(USB_HUB_MAX_DESCRIPTOR_SIZE);
    97244        usb_hub_descriptor_t * descriptor;
    98         size_t received_size;
    99         int opResult;
    100245        dprintf(USB_LOG_LEVEL_DEBUG, "starting control transaction");
    101        
    102         opResult = usb_drv_req_get_descriptor(hc, addr,
     246        usb_endpoint_pipe_start_session(&result->endpoints.control);
     247        opResult = usb_request_get_descriptor(&result->endpoints.control,
    103248                        USB_REQUEST_TYPE_CLASS,
    104249                        USB_DESCTYPE_HUB, 0, 0, serialized_descriptor,
    105250                        USB_HUB_MAX_DESCRIPTOR_SIZE, &received_size);
     251        usb_endpoint_pipe_end_session(&result->endpoints.control);
    106252
    107253        if (opResult != EOK) {
     
    117263                return result;
    118264        }
     265
     266       
    119267        dprintf(USB_LOG_LEVEL_INFO, "setting port count to %d",descriptor->ports_count);
    120268        result->port_count = descriptor->ports_count;
    121         result->attached_devs = (usb_hub_attached_device_t*)
    122             malloc((result->port_count+1) * sizeof(usb_hub_attached_device_t));
     269        result->attached_devs = (usb_hc_attached_device_t*)
     270            malloc((result->port_count+1) * sizeof(usb_hc_attached_device_t));
    123271        int i;
    124272        for(i=0;i<result->port_count+1;++i){
    125                 result->attached_devs[i].devman_handle=0;
     273                result->attached_devs[i].handle=0;
    126274                result->attached_devs[i].address=0;
    127275        }
     
    138286}
    139287
     288/**
     289 * Create hub representation and add it into hub list
     290 * @param dev
     291 * @return
     292 */
    140293int usb_add_hub_device(device_t *dev) {
    141294        dprintf(USB_LOG_LEVEL_INFO, "add_hub_device(handle=%d)", (int) dev->handle);
    142295
    143         /*
    144          * We are some (probably deeply nested) hub.
    145          * Thus, assign our own operations and explore already
    146          * connected devices.
    147          */
    148296        dev->ops = &hub_device_ops;
    149297
    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);
     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);
     309                return opResult;
     310        }
     311        //power ports
     312        usb_device_request_setup_packet_t request;
    158313        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);
    172                 return opResult;
    173         }
    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 
    196         usb_device_request_setup_packet_t request;
    197314        for (port = 1; port < hub_info->port_count+1; ++port) {
    198315                usb_hub_set_power_port_request(&request, port);
    199                 opResult = usb_drv_sync_control_write(hc, target, &request, NULL, 0);
     316                opResult = usb_endpoint_pipe_control_write(&hub_info->endpoints.control,
     317                                &request,sizeof(usb_device_request_setup_packet_t), NULL, 0);
    200318                dprintf(USB_LOG_LEVEL_INFO, "powering port %d",port);
    201319                if (opResult != EOK) {
     
    204322        }
    205323        //ports powered, hub seems to be enabled
    206 
    207         async_hangup(hc);
     324        usb_endpoint_pipe_end_session(&hub_info->endpoints.control);
    208325
    209326        //add the hub to list
     
    215332        //(void)hub_info;
    216333        usb_hub_check_hub_changes();
    217 
    218334       
    219 
    220335        dprintf(USB_LOG_LEVEL_INFO, "hub dev added");
     336        //address is lost...
    221337        dprintf(USB_LOG_LEVEL_DEBUG, "\taddress %d, has %d ports ",
    222                         hub_info->address,
     338                        //hub_info->endpoints.control.,
    223339                        hub_info->port_count);
    224         dprintf(USB_LOG_LEVEL_DEBUG, "\tused configuration %d",config_descriptor.configuration_number);
    225340
    226341        return EOK;
     
    236351
    237352/**
    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  */
    243 inline 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 /**
    254353 * Reset the port with new device and reserve the default address.
    255354 * @param hc
     
    257356 * @param target
    258357 */
    259 static void usb_hub_init_add_device(int hc, uint16_t port, usb_target_t target) {
     358static void usb_hub_init_add_device(usb_hub_info_t * hub, uint16_t port) {
    260359        usb_device_request_setup_packet_t request;
    261360        int opResult;
    262361        dprintf(USB_LOG_LEVEL_INFO, "some connection changed");
     362        assert(hub->endpoints.control.hc_phone);
    263363        //get default address
    264         opResult = usb_drv_reserve_default_address(hc);
     364        //opResult = usb_drv_reserve_default_address(hc);
     365        opResult = usb_hc_reserve_default_address(&hub->connection, USB_SPEED_LOW);
     366
    265367        if (opResult != EOK) {
    266368                dprintf(USB_LOG_LEVEL_WARNING, "cannot assign default address, it is probably used");
     
    269371        //reset port
    270372        usb_hub_set_reset_port_request(&request, port);
    271         opResult = usb_drv_sync_control_write(
    272                         hc, target,
    273                         &request,
     373        opResult = usb_endpoint_pipe_control_write(
     374                        &hub->endpoints.control,
     375                        &request,sizeof(usb_device_request_setup_packet_t),
    274376                        NULL, 0
    275377                        );
    276378        if (opResult != EOK) {
    277379                dprintf(USB_LOG_LEVEL_ERROR, "something went wrong when reseting a port");
    278                 usb_hub_release_default_address(hc);
     380                //usb_hub_release_default_address(hc);
     381                usb_hc_release_default_address(&hub->connection);
    279382        }
    280383}
     
    287390 */
    288391static void usb_hub_finalize_add_device( usb_hub_info_t * hub,
    289                 int hc, uint16_t port, usb_target_t target) {
     392                uint16_t port) {
    290393
    291394        int opResult;
    292395        dprintf(USB_LOG_LEVEL_INFO, "finalizing add device");
    293         opResult = usb_hub_clear_port_feature(hc, target.address,
     396        opResult = usb_hub_clear_port_feature(&hub->endpoints.control,
    294397            port, USB_HUB_FEATURE_C_PORT_RESET);
     398
    295399        if (opResult != EOK) {
    296400                dprintf(USB_LOG_LEVEL_ERROR, "failed to clear port reset feature");
    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);
     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                        );
    303425        if (new_device_address < 0) {
    304426                dprintf(USB_LOG_LEVEL_ERROR, "failed to get free USB address");
    305427                opResult = new_device_address;
    306                 usb_hub_release_default_address(hc);
     428                usb_hc_release_default_address(&hub->connection);
    307429                return;
    308430        }
    309431        dprintf(USB_LOG_LEVEL_INFO, "setting new address %d",new_device_address);
    310         opResult = usb_drv_req_set_address(hc, USB_ADDRESS_DEFAULT,
    311             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);
    312435
    313436        if (opResult != EOK) {
    314437                dprintf(USB_LOG_LEVEL_ERROR, "could not set address for new device");
    315                 usb_hub_release_default_address(hc);
    316                 return;
    317         }
    318 
    319 
    320         opResult = usb_hub_release_default_address(hc);
     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);
    321445        if(opResult!=EOK){
    322446                return;
    323447        }
    324448
    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 
    333449        devman_handle_t child_handle;
    334         opResult = usb_device_register_child_in_devman(new_device_address,
    335             hc_handle, hub->device, &child_handle);
     450        //??
     451    opResult = usb_device_register_child_in_devman(new_device_address,
     452            hub->connection.hc_handle, hub->device, &child_handle);
     453
    336454        if (opResult != EOK) {
    337455                dprintf(USB_LOG_LEVEL_ERROR, "could not start driver for new device");
    338456                return;
    339457        }
    340         hub->attached_devs[port].devman_handle = child_handle;
     458        hub->attached_devs[port].handle = child_handle;
    341459        hub->attached_devs[port].address = new_device_address;
    342460
    343         opResult = usb_drv_bind_address(hc, new_device_address, child_handle);
     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]);
    344465        if (opResult != EOK) {
    345466                dprintf(USB_LOG_LEVEL_ERROR, "could not assign address of device in hcd");
     
    358479 */
    359480static void usb_hub_removed_device(
    360     usb_hub_info_t * hub, int hc, uint16_t port, usb_target_t target) {
     481    usb_hub_info_t * hub,uint16_t port) {
    361482        //usb_device_request_setup_packet_t request;
    362483        int opResult;
     
    365486         * devide manager
    366487         */
    367 
    368         hub->attached_devs[port].devman_handle=0;
     488       
    369489        //close address
    370490        if(hub->attached_devs[port].address!=0){
    371                 opResult = usb_drv_release_address(hc,hub->attached_devs[port].address);
     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);
    372494                if(opResult != EOK) {
    373495                        dprintf(USB_LOG_LEVEL_WARNING, "could not release address of " \
     
    375497                }
    376498                hub->attached_devs[port].address = 0;
     499                hub->attached_devs[port].handle = 0;
    377500        }else{
    378501                dprintf(USB_LOG_LEVEL_WARNING, "this is strange, disconnected device had no address");
    379502                //device was disconnected before it`s port was reset - return default address
    380                 usb_drv_release_default_address(hc);
     503                //usb_drv_release_default_address(hc);
     504                usb_hc_release_default_address(&hub->connection);
    381505        }
    382506}
     
    388512 * @param target
    389513 */
    390 static void usb_hub_process_interrupt(usb_hub_info_t * hub, int hc,
    391         uint16_t port, usb_address_t address) {
     514static void usb_hub_process_interrupt(usb_hub_info_t * hub,
     515        uint16_t port) {
    392516        dprintf(USB_LOG_LEVEL_DEBUG, "interrupt at port %d", port);
    393517        //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        /*
    394526        usb_target_t target;
    395527        target.address=address;
    396528        target.endpoint=0;
     529        */
     530
    397531        usb_port_status_t status;
    398532        size_t rcvd_size;
    399533        usb_device_request_setup_packet_t request;
    400         int opResult;
     534        //int opResult;
    401535        usb_hub_set_port_status_request(&request, port);
    402536        //endpoint 0
    403537
    404         opResult = usb_drv_sync_control_read(
    405                         hc, target,
    406                         &request,
     538        opResult = usb_endpoint_pipe_control_read(
     539                        pipe,
     540                        &request, sizeof(usb_device_request_setup_packet_t),
    407541                        &status, 4, &rcvd_size
    408542                        );
     
    417551        //something connected/disconnected
    418552        if (usb_port_connect_change(&status)) {
    419                 opResult = usb_hub_clear_port_feature(hc, target.address,
     553                opResult = usb_hub_clear_port_feature(pipe,
    420554                    port, USB_HUB_FEATURE_C_PORT_CONNECTION);
    421555                // TODO: check opResult
    422556                if (usb_port_dev_connected(&status)) {
    423557                        dprintf(USB_LOG_LEVEL_INFO, "some connection changed");
    424                         usb_hub_init_add_device(hc, port, target);
     558                        usb_hub_init_add_device(hub, port);
    425559                } else {
    426                         usb_hub_removed_device(hub, hc, port, target);
     560                        usb_hub_removed_device(hub, port);
    427561                }
    428562        }
     
    431565                dprintf(USB_LOG_LEVEL_INFO, "port reset complete");
    432566                if (usb_port_enabled(&status)) {
    433                         usb_hub_finalize_add_device(hub, hc, port, target);
     567                        usb_hub_finalize_add_device(hub, port);
    434568                } else {
    435569                        dprintf(USB_LOG_LEVEL_WARNING, "ERROR: port reset, but port still not enabled");
     
    447581        /// \TODO handle other changes
    448582        /// \TODO debug log for various situations
     583        usb_endpoint_pipe_end_session(pipe);
     584
    449585
    450586}
     
    464600                fibril_mutex_unlock(&usb_hub_list_lock);
    465601                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                }
    466608                /*
    467609                 * Check status change pipe of this hub.
    468610                 */
    469 
     611                /*
    470612                usb_target_t target;
    471613                target.address = hub_info->address;
     
    473615                dprintf(USB_LOG_LEVEL_INFO, "checking changes for hub at addr %d",
    474616                    target.address);
    475 
     617                */
    476618                size_t port_count = hub_info->port_count;
    477619
    478620                /*
    479621                 * Connect to respective HC.
    480                  */
     622                 *
    481623                int hc = usb_drv_hc_connect_auto(hub_info->device, 0);
    482624                if (hc < 0) {
    483625                        continue;
    484                 }
     626                }*/
    485627
    486628                /// FIXME: count properly
     
    489631                void *change_bitmap = malloc(byte_length);
    490632                size_t actual_size;
    491                 usb_handle_t handle;
     633                //usb_handle_t handle;
    492634
    493635                /*
    494636                 * Send the request.
    495637                 */
    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);
     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);
    501644
    502645                if (opResult != EOK) {
     
    511654                        if (interrupt) {
    512655                                usb_hub_process_interrupt(
    513                                         hub_info, hc, port, hub_info->address);
     656                                        hub_info, port);
    514657                        }
    515658                }
     659                usb_endpoint_pipe_end_session(&hub_info->endpoints.status_change);
    516660                free(change_bitmap);
    517 
    518                 async_hangup(hc);
     661               
     662
     663                //async_hangup(hc);
    519664                fibril_mutex_lock(&usb_hub_list_lock);
    520665        }
  • uspace/drv/usbhub/usbhub.h

    rfb78ae72 rdeece2f  
    4242#define NAME "usbhub"
    4343
    44 /** basic information about device attached to hub */
    45 typedef struct{
    46         usb_address_t address;
    47         devman_handle_t devman_handle;
    48 }usb_hub_attached_device_t;
     44#include <usb/hub.h>
     45
     46#include <usb/pipes.h>
     47
     48/* Hub endpoints. */
     49typedef struct {
     50        usb_endpoint_pipe_t control;
     51        usb_endpoint_pipe_t status_change;
     52} usb_hub_endpoints_t;
     53
     54
    4955
    5056/** Information about attached hub. */
     
    5258        /** Number of ports. */
    5359        int port_count;
    54         /** attached device handles */
    55         usb_hub_attached_device_t * attached_devs;
    56         /** USB address of the hub. */
    57         usb_address_t address;
     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;
    5864        /** General device info*/
    5965        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;
    6073} usb_hub_info_t;
    6174
  • uspace/drv/usbhub/usbhub_private.h

    rfb78ae72 rdeece2f  
    4545#include <fibril_synch.h>
    4646
     47#include <usb/classes/hub.h>
    4748#include <usb/usb.h>
    48 #include <usb/usbdrv.h>
    49 #include <usb/classes/hub.h>
    50 #include <usb/devreq.h>
    5149#include <usb/debug.h>
     50#include <usb/request.h>
    5251
    5352//************
     
    7776 * @return
    7877 */
    79 usb_hub_info_t * usb_create_hub_info(device_t * device, int hc);
     78usb_hub_info_t * usb_create_hub_info(device_t * device);
    8079
    8180/** List of hubs maanged by this driver */
     
    9897 * @return error code
    9998 */
     99/*
    100100int usb_drv_sync_control_read(
    101     int phone, usb_target_t target,
     101    usb_endpoint_pipe_t *pipe,
    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     int phone, usb_target_t target,
     117/*int usb_drv_sync_control_write(
     118    usb_endpoint_pipe_t *pipe,
    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(int hc, usb_address_t address,
     149static inline int usb_hub_clear_port_feature(usb_endpoint_pipe_t *pipe,
    150150    int port_index,
    151151    usb_hub_class_feature_t feature) {
    152         usb_target_t target = {
    153                 .address = address,
    154                 .endpoint = 0
    155         };
     152       
    156153        usb_device_request_setup_packet_t clear_request = {
    157154                .request_type = USB_HUB_REQ_TYPE_CLEAR_PORT_FEATURE,
     
    161158        };
    162159        clear_request.value = feature;
    163         return usb_drv_psync_control_write(hc, target, &clear_request,
     160        return usb_endpoint_pipe_control_write(pipe, &clear_request,
    164161            sizeof(clear_request), NULL, 0);
    165162}
  • uspace/drv/usbhub/utils.c

    rfb78ae72 rdeece2f  
    3838
    3939#include <usbhc_iface.h>
    40 #include <usb/usbdrv.h>
    4140#include <usb/descriptor.h>
    42 #include <usb/devreq.h>
    4341#include <usb/classes/hub.h>
    4442
     
    114112
    115113//control transactions
    116 
     114/*
    117115int usb_drv_sync_control_read(
    118116    int phone, usb_target_t target,
     
    199197}
    200198
    201 
     199*/
    202200
    203201
  • uspace/drv/vhc/conn.h

    rfb78ae72 rdeece2f  
    3838#include <usb/usb.h>
    3939#include <usbhc_iface.h>
     40#include <usb_iface.h>
    4041#include "vhcd.h"
    4142#include "devices.h"
     
    4344void connection_handler_host(sysarg_t);
    4445
    45 usbhc_iface_t vhc_iface;
     46extern usbhc_iface_t vhc_iface;
     47extern usb_iface_t vhc_usb_iface;
    4648
    4749void address_init(void);
  • uspace/drv/vhc/connhost.c

    rfb78ae72 rdeece2f  
    3737#include <usb/usb.h>
    3838#include <usb/addrkeep.h>
     39#include <usb/ddfiface.h>
    3940
    4041#include "vhcd.h"
     
    313314static usb_address_keeping_t addresses;
    314315
     316static int tell_address(device_t *dev, devman_handle_t handle,
     317    usb_address_t *address)
     318{
     319        usb_address_t addr = usb_address_keeping_find(&addresses, handle);
     320        if (addr < 0) {
     321                return addr;
     322        }
     323
     324        *address = addr;
     325        return EOK;
     326}
    315327
    316328static int reserve_default_address(device_t *dev, usb_speed_t ignored)
     
    350362}
    351363
    352 static int tell_address(device_t *dev, devman_handle_t handle,
    353     usb_address_t *address)
    354 {
    355         usb_address_t addr = usb_address_keeping_find(&addresses, handle);
    356         if (addr < 0) {
    357                 return addr;
    358         }
    359 
    360         *address = addr;
    361         return EOK;
    362 }
    363 
    364364void address_init(void)
    365365{
     
    368368
    369369usbhc_iface_t vhc_iface = {
    370         .tell_address = tell_address,
    371 
    372370        .reserve_default_address = reserve_default_address,
    373371        .release_default_address = release_default_address,
     
    383381};
    384382
     383usb_iface_t vhc_usb_iface = {
     384        .get_hc_handle = usb_iface_get_hc_handle_hc_impl,
     385        .get_address = tell_address
     386};
     387
     388
    385389/**
    386390 * @}
  • uspace/drv/vhc/hcd.c

    rfb78ae72 rdeece2f  
    4545
    4646#include <usb/usb.h>
     47#include <usb/ddfiface.h>
    4748#include <usb_iface.h>
    4849#include "vhcd.h"
     
    5253#include "conn.h"
    5354
    54 static 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 
    63 static usb_iface_t hc_usb_iface = {
    64         .get_hc_handle = usb_iface_get_hc_handle
    65 };
    66 
    6755static device_ops_t vhc_ops = {
    6856        .interfaces[USBHC_DEV_IFACE] = &vhc_iface,
    69         .interfaces[USB_DEV_IFACE] = &hc_usb_iface,
     57        .interfaces[USB_DEV_IFACE] = &vhc_usb_iface,
    7058        .close = on_client_close,
    7159        .default_handler = default_connection_handler
  • uspace/drv/vhc/hub.c

    rfb78ae72 rdeece2f  
    4040#include <stdlib.h>
    4141#include <driver.h>
    42 #include <usb/usbdrv.h>
     42#include <usb/hub.h>
    4343#include <usb/recognise.h>
    4444
     
    7171}
    7272
     73static int pretend_port_rest(int unused, void *unused2)
     74{
     75        return EOK;
     76}
     77
    7378/** Register root hub in devman.
    7479 *
     
    8085        device_t *hc_dev = (device_t *) arg;
    8186
    82         int hc;
     87        /*
     88         * Wait until parent device is properly initialized.
     89         */
     90        int phone;
    8391        do {
    84                 hc = usb_drv_hc_connect(hc_dev, hc_dev->handle,
    85                     IPC_FLAG_BLOCKING);
    86         } while (hc < 0);
     92                phone = devman_device_connect(hc_dev->handle, 0);
     93        } while (phone < 0);
     94        async_hangup(phone);
    8795
    88         usb_drv_reserve_default_address(hc);
     96        usb_hc_connection_t hc_conn;
     97        usb_hc_connection_initialize(&hc_conn, hc_dev->handle);
    8998
    90         usb_address_t hub_address = usb_drv_request_address(hc);
    91         usb_drv_req_set_address(hc, USB_ADDRESS_DEFAULT, hub_address);
     99        usb_hc_connection_open(&hc_conn);
    92100
    93         usb_drv_release_default_address(hc);
     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        }
    94108
    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);
     109        usb_hc_connection_close(&hc_conn);
    100110
    101         return EOK;
     111        return 0;
    102112}
    103113       
  • uspace/drv/vhc/hub/hub.c

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

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

    rfb78ae72 rdeece2f  
    4040
    4141
     42static void remote_usb_get_address(device_t *, void *, ipc_callid_t, ipc_call_t *);
     43static void remote_usb_get_interface(device_t *, void *, ipc_callid_t, ipc_call_t *);
    4244static void remote_usb_get_hc_handle(device_t *, void *, ipc_callid_t, ipc_call_t *);
    4345//static void remote_usb(device_t *, void *, ipc_callid_t, ipc_call_t *);
     
    4547/** Remote USB interface operations. */
    4648static remote_iface_func_ptr_t remote_usb_iface_ops [] = {
     49        remote_usb_get_address,
     50        remote_usb_get_interface,
    4751        remote_usb_get_hc_handle
    4852};
     
    5660};
    5761
     62
     63void 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
     84void 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}
    58104
    59105void remote_usb_get_hc_handle(device_t *device, void *iface,
  • uspace/lib/drv/generic/remote_usbhc.c

    rfb78ae72 rdeece2f  
    4343#define HACK_MAX_PACKET_SIZE_INTERRUPT_IN 4
    4444
    45 static void remote_usbhc_get_address(device_t *, void *, ipc_callid_t, ipc_call_t *);
    4645static void remote_usbhc_interrupt_out(device_t *, void *, ipc_callid_t, ipc_call_t *);
    4746static void remote_usbhc_interrupt_in(device_t *, void *, ipc_callid_t, ipc_call_t *);
     47static void remote_usbhc_bulk_out(device_t *, void *, ipc_callid_t, ipc_call_t *);
     48static void remote_usbhc_bulk_in(device_t *, void *, ipc_callid_t, ipc_call_t *);
    4849static void remote_usbhc_control_write(device_t *, void *, ipc_callid_t, ipc_call_t *);
    4950static void remote_usbhc_control_read(device_t *, void *, ipc_callid_t, ipc_call_t *);
     
    5758/** Remote USB host controller interface operations. */
    5859static remote_iface_func_ptr_t remote_usbhc_iface_ops [] = {
    59         remote_usbhc_get_address,
    60 
    6160        remote_usbhc_reserve_default_address,
    6261        remote_usbhc_release_default_address,
     
    6867        remote_usbhc_interrupt_out,
    6968        remote_usbhc_interrupt_in,
     69
     70        remote_usbhc_bulk_out,
     71        remote_usbhc_bulk_in,
    7072
    7173        remote_usbhc_control_write,
     
    121123}
    122124
    123 void 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 
    144125void remote_usbhc_reserve_default_address(device_t *device, void *iface,
    145126    ipc_callid_t callid, ipc_call_t *call)
     
    389370        return remote_usbhc_in_transfer(device, callid, call,
    390371            usb_iface->interrupt_in);
     372}
     373
     374void 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
     384void 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);
    391392}
    392393
  • uspace/lib/drv/include/usb_iface.h

    rfb78ae72 rdeece2f  
    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
    4363        /** Tell devman handle of device host controller.
    4464         * Parameters:
     
    5575/** USB device communication interface. */
    5676typedef struct {
     77        int (*get_address)(device_t *, devman_handle_t, usb_address_t *);
     78        int (*get_interface)(device_t *, devman_handle_t, int *);
    5779        int (*get_hc_handle)(device_t *, devman_handle_t *);
    5880} usb_iface_t;
  • uspace/lib/drv/include/usbhc_iface.h

    rfb78ae72 rdeece2f  
    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 
    9987        /** Reserve usage of default address.
    10088         * This call informs the host controller that the caller will be
     
    153141        IPC_M_USBHC_INTERRUPT_IN,
    154142
     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
    155153        /** Issue control WRITE transfer.
    156154         * See explanation at usb_iface_funcs_t (OUT transaction) for
     
    196194/** USB host controller communication interface. */
    197195typedef struct {
    198         int (*tell_address)(device_t *, devman_handle_t, usb_address_t *);
    199 
    200196        int (*reserve_default_address)(device_t *, usb_speed_t);
    201197        int (*release_default_address)(device_t *);
     
    207203        usbhc_iface_transfer_in_t interrupt_in;
    208204
     205        usbhc_iface_transfer_out_t bulk_out;
     206        usbhc_iface_transfer_in_t bulk_in;
     207
    209208        int (*control_write)(device_t *, usb_target_t,
    210209            size_t,
  • uspace/lib/usb/Makefile

    rfb78ae72 rdeece2f  
    3535        src/addrkeep.c \
    3636        src/class.c \
     37        src/ddfiface.c \
    3738        src/debug.c \
    3839        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 \
    5250        src/usbmem.c
    5351
  • uspace/lib/usb/include/usb/classes/hub.h

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

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

    rfb78ae72 rdeece2f  
    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;
    109111        /** Found descriptor fitting the description. */
    110112        usb_standard_endpoint_descriptor_t *descriptor;
     
    121123int usb_device_connection_initialize(usb_device_connection_t *,
    122124    devman_handle_t, usb_address_t);
     125
     126int usb_device_get_assigned_interface(device_t *);
    123127
    124128int usb_endpoint_pipe_initialize(usb_endpoint_pipe_t *,
  • uspace/lib/usb/include/usb/recognise.h

    rfb78ae72 rdeece2f  
    4141#include <ipc/devman.h>
    4242
     43int usb_device_create_match_ids_from_device_descriptor(
     44    const usb_standard_device_descriptor_t *, match_id_list_t *);
     45
     46int 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
    4350int usb_device_create_match_ids(usb_endpoint_pipe_t *, match_id_list_t *);
    4451
  • uspace/lib/usb/include/usb/request.h

    rfb78ae72 rdeece2f  
    4141#include <usb/descriptor.h>
    4242
     43/** Standard device request. */
     44typedef 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 */
     62typedef 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
    4387int usb_control_request_set(usb_endpoint_pipe_t *,
    4488    usb_request_type_t, usb_request_recipient_t, uint8_t,
  • uspace/lib/usb/src/dp.c

    rfb78ae72 rdeece2f  
    3737#include <str_error.h>
    3838#include <errno.h>
    39 #include <usb/usbdrv.h>
     39#include <assert.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. */
     52usb_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
    4263
    4364/** Tells whether pointer points inside descriptor data.
  • uspace/lib/usb/src/hub.c

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

    rfb78ae72 rdeece2f  
    3636#include <usb/pipes.h>
    3737#include <usbhc_iface.h>
     38#include <usb_iface.h>
    3839#include <errno.h>
    3940#include <assert.h>
     
    4142/** Tell USB address assigned to given device.
    4243 *
    43  * @param phone Phone to my HC.
     44 * @param phone Phone to parent device.
    4445 * @param dev Device in question.
    4546 * @return USB address or error code.
     
    4849{
    4950        sysarg_t address;
    50         int rc = async_req_2_1(phone, DEV_IFACE_ID(USBHC_DEV_IFACE),
    51             IPC_M_USBHC_GET_ADDRESS,
     51        int rc = async_req_2_1(phone, DEV_IFACE_ID(USB_DEV_IFACE),
     52            IPC_M_USB_GET_ADDRESS,
    5253            dev->handle, &address);
    5354
     
    5758
    5859        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 */
     67int 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;
    5987}
    6088
     
    80108        }
    81109
    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);
     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);
    88117        if (my_address < 0) {
    89118                rc = my_address;
     
    95124
    96125leave:
    97         async_hangup(hc_phone);
     126        async_hangup(parent_phone);
    98127        return rc;
    99128}
  • uspace/lib/usb/src/pipesinit.c

    rfb78ae72 rdeece2f  
    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.
    111112 * @return Endpoint mapping corresponding to @p found_endpoint.
    112113 * @retval NULL No corresponding endpoint found.
     
    114115static usb_endpoint_mapping_t *find_endpoint_mapping(
    115116    usb_endpoint_mapping_t *mapping, size_t mapping_count,
    116     usb_endpoint_description_t *found_endpoint)
     117    usb_endpoint_description_t *found_endpoint,
     118    int interface_number)
    117119{
    118120        while (mapping_count > 0) {
    119                 if (endpoint_fits_description(mapping->description,
    120                     found_endpoint)) {
     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) {
    121128                        return mapping;
    122129                }
     
    169176         */
    170177        usb_endpoint_mapping_t *ep_mapping = find_endpoint_mapping(mapping,
    171             mapping_count, &description);
     178            mapping_count, &description, interface->interface_number);
    172179        if (ep_mapping == NULL) {
    173180                return ENOENT;
  • uspace/lib/usb/src/pipesio.c

    rfb78ae72 rdeece2f  
    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;
    7376                default:
    7477                        return ENOTSUP;
     
    194197                case USB_TRANSFER_INTERRUPT:
    195198                        ipc_method = IPC_M_USBHC_INTERRUPT_OUT;
     199                        break;
     200                case USB_TRANSFER_BULK:
     201                        ipc_method = IPC_M_USBHC_BULK_OUT;
    196202                        break;
    197203                default:
  • uspace/lib/usb/src/recognise.c

    rfb78ae72 rdeece2f  
    3434 */
    3535#include <sys/types.h>
    36 #include <usb_iface.h>
    37 #include <usb/usbdrv.h>
    3836#include <usb/pipes.h>
    3937#include <usb/recognise.h>
     38#include <usb/ddfiface.h>
    4039#include <usb/request.h>
    4140#include <usb/classes/classes.h>
     
    4645static FIBRIL_MUTEX_INITIALIZE(device_name_index_mutex);
    4746
    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  */
    54 static 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 
    74 static usb_iface_t usb_iface = {
    75         .get_hc_handle = usb_iface_get_hc_handle
    76 };
    77 
    7847device_ops_t child_ops = {
    79         .interfaces[USB_DEV_IFACE] = &usb_iface
     48        .interfaces[USB_DEV_IFACE] = &usb_iface_hub_child_impl
    8049};
    8150
     
    142111}
    143112
     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 */
     130int 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
    144236/** Create DDF match ids from USB device descriptor.
    145237 *
     
    148240 * @return Error code.
    149241 */
    150 int usb_drv_create_match_ids_from_device_descriptor(
    151     match_id_list_t *matches,
    152     const usb_standard_device_descriptor_t *device_descriptor)
     242int usb_device_create_match_ids_from_device_descriptor(
     243    const usb_standard_device_descriptor_t *device_descriptor,
     244    match_id_list_t *matches)
    153245{
    154         int rc;
    155        
    156246        /*
    157247         * Unless the vendor id is 0, the pair idVendor-idProduct
     
    160250        if (device_descriptor->vendor_id != 0) {
    161251                /* First, with release number. */
    162                 rc = usb_add_match_id(matches, 100,
     252                ADD_MATCHID_OR_RETURN(matches, 100,
    163253                    "usb&vendor=0x%04x&product=0x%04x&release=" BCD_FMT,
    164254                    (int) device_descriptor->vendor_id,
    165255                    (int) device_descriptor->product_id,
    166256                    BCD_ARGS(device_descriptor->device_version));
    167                 if (rc != EOK) {
    168                         return rc;
    169                 }
    170257               
    171258                /* Next, without release number. */
    172                 rc = usb_add_match_id(matches, 90,
     259                ADD_MATCHID_OR_RETURN(matches, 90,
    173260                    "usb&vendor=0x%04x&product=0x%04x",
    174261                    (int) device_descriptor->vendor_id,
    175262                    (int) device_descriptor->product_id);
    176                 if (rc != EOK) {
    177                         return rc;
    178                 }
    179263        }       
    180264
    181265        /*
    182266         * If the device class points to interface we skip adding
    183          * class directly.
     267         * class directly but we add a multi interface device.
    184268         */
    185269        if (device_descriptor->device_class != USB_CLASS_USE_INTERFACE) {
    186                 rc = usb_add_match_id(matches, 50, "usb&class=%s",
     270                ADD_MATCHID_OR_RETURN(matches, 50, "usb&class=%s",
    187271                    usb_str_class(device_descriptor->device_class));
    188                 if (rc != EOK) {
    189                         return rc;
    190                 }
     272        } else {
     273                ADD_MATCHID_OR_RETURN(matches, 50, "usb&mid");
    191274        }
    192275       
     
    194277}
    195278
    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  */
    205 int 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  */
    255 static 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 }
    300279
    301280/** Create match ids describing attached device.
     
    323302        }
    324303
    325         rc = usb_drv_create_match_ids_from_device_descriptor(matches,
    326             &device_descriptor);
     304        rc = usb_device_create_match_ids_from_device_descriptor(
     305            &device_descriptor, matches);
    327306        if (rc != EOK) {
    328307                return rc;
     
    330309
    331310        /*
    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         /*
    342311         * As a fallback, provide the simplest match id possible.
    343312         */
    344         rc = usb_add_match_id(matches, 1, "usb&fallback");
    345         if (rc != EOK) {
    346                 return rc;
    347         }
     313        ADD_MATCHID_OR_RETURN(matches, 1, "usb&fallback");
    348314
    349315        return EOK;
  • uspace/lib/usb/src/request.c

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

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

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

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