Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/usb/src/recognise.c

    r345ea18 r38648f0  
    3333 * @brief Functions for recognising kind of attached devices.
    3434 */
    35 #include <sys/types.h>
    3635#include <usb_iface.h>
    3736#include <usb/usbdrv.h>
    38 #include <usb/pipes.h>
    39 #include <usb/recognise.h>
    40 #include <usb/request.h>
    4137#include <usb/classes/classes.h>
    4238#include <stdio.h>
    4339#include <errno.h>
    44 
    45 static size_t device_name_index = 0;
    46 static FIBRIL_MUTEX_INITIALIZE(device_name_index_mutex);
    4740
    4841/** Callback for getting host controller handle.
     
    7669};
    7770
    78 device_ops_t child_ops = {
     71static device_ops_t child_ops = {
    7972        .interfaces[USB_DEV_IFACE] = &usb_iface
    8073};
     
    161154                /* First, with release number. */
    162155                rc = usb_add_match_id(matches, 100,
    163                     "usb&vendor=0x%04x&product=0x%04x&release=" BCD_FMT,
     156                    "usb&vendor=%d&product=%d&release=" BCD_FMT,
    164157                    (int) device_descriptor->vendor_id,
    165158                    (int) device_descriptor->product_id,
     
    170163               
    171164                /* Next, without release number. */
    172                 rc = usb_add_match_id(matches, 90,
    173                     "usb&vendor=0x%04x&product=0x%04x",
     165                rc = usb_add_match_id(matches, 90, "usb&vendor=%d&product=%d",
    174166                    (int) device_descriptor->vendor_id,
    175167                    (int) device_descriptor->product_id);
     
    248240/** Add match ids based on configuration descriptor.
    249241 *
    250  * @param pipe Control pipe to the device.
     242 * @param hc Open phone to host controller.
    251243 * @param matches Match ids list to add matches to.
     244 * @param address USB address of the attached device.
    252245 * @param config_count Number of configurations the device has.
    253246 * @return Error code.
    254247 */
    255 static int usb_add_config_descriptor_match_ids(usb_endpoint_pipe_t *pipe,
    256     match_id_list_t *matches, int config_count)
     248static int usb_add_config_descriptor_match_ids(int hc,
     249    match_id_list_t *matches, usb_address_t address,
     250    int config_count)
    257251{
    258252        int final_rc = EOK;
     
    262256                int rc;
    263257                usb_standard_configuration_descriptor_t config_descriptor;
    264                 rc = usb_request_get_bare_configuration_descriptor(pipe,
    265                     config_index, &config_descriptor);
     258                rc = usb_drv_req_get_bare_configuration_descriptor(hc,
     259                    address,  config_index, &config_descriptor);
    266260                if (rc != EOK) {
    267261                        final_rc = rc;
     
    272266                void *full_config_descriptor
    273267                    = malloc(config_descriptor.total_length);
    274                 rc = usb_request_get_full_configuration_descriptor(pipe,
    275                     config_index,
     268                rc = usb_drv_req_get_full_configuration_descriptor(hc,
     269                    address, config_index,
    276270                    full_config_descriptor, config_descriptor.total_length,
    277271                    &full_config_descriptor_size);
     
    304298 * function exits with error.
    305299 *
    306  * @param ctrl_pipe Control pipe to given device (session must be already
    307  *      started).
     300 * @param hc Open phone to host controller.
    308301 * @param matches Initialized list of match ids.
    309  * @return Error code.
    310  */
    311 int usb_device_create_match_ids(usb_endpoint_pipe_t *ctrl_pipe,
    312     match_id_list_t *matches)
     302 * @param address USB address of the attached device.
     303 * @return Error code.
     304 */
     305int usb_drv_create_device_match_ids(int hc, match_id_list_t *matches,
     306    usb_address_t address)
    313307{
    314308        int rc;
     309       
    315310        /*
    316311         * Retrieve device descriptor and add matches from it.
     
    318313        usb_standard_device_descriptor_t device_descriptor;
    319314
    320         rc = usb_request_get_device_descriptor(ctrl_pipe, &device_descriptor);
     315        rc = usb_drv_req_get_device_descriptor(hc, address,
     316            &device_descriptor);
    321317        if (rc != EOK) {
    322318                return rc;
    323319        }
    324 
     320       
    325321        rc = usb_drv_create_match_ids_from_device_descriptor(matches,
    326322            &device_descriptor);
     
    328324                return rc;
    329325        }
    330 
     326       
    331327        /*
    332328         * Go through all configurations and add matches
    333329         * based on interface class.
    334330         */
    335         rc = usb_add_config_descriptor_match_ids(ctrl_pipe, matches,
    336             device_descriptor.configuration_count);
     331        rc = usb_add_config_descriptor_match_ids(hc, matches,
     332            address, device_descriptor.configuration_count);
    337333        if (rc != EOK) {
    338334                return rc;
     
    350346}
    351347
     348
    352349/** Probe for device kind and register it in devman.
    353350 *
     351 * @param[in] hc Open phone to the host controller.
     352 * @param[in] parent Parent device.
    354353 * @param[in] address Address of the (unknown) attached device.
    355  * @param[in] hc_handle Handle of the host controller.
    356  * @param[in] parent Parent device.
    357354 * @param[out] child_handle Handle of the child device.
    358355 * @return Error code.
    359356 */
    360 int usb_device_register_child_in_devman(usb_address_t address,
    361     devman_handle_t hc_handle,
    362     device_t *parent, devman_handle_t *child_handle)
    363 {
     357int usb_drv_register_child_in_devman(int hc, device_t *parent,
     358    usb_address_t address, devman_handle_t *child_handle)
     359{
     360        static size_t device_name_index = 0;
     361        static FIBRIL_MUTEX_INITIALIZE(device_name_index_mutex);
     362
    364363        size_t this_device_name_index;
    365364
     
    369368        fibril_mutex_unlock(&device_name_index_mutex);
    370369
     370
    371371        device_t *child = NULL;
    372372        char *child_name = NULL;
    373373        int rc;
    374         usb_device_connection_t dev_connection;
    375         usb_endpoint_pipe_t ctrl_pipe;
    376 
    377         rc = usb_device_connection_initialize(&dev_connection, hc_handle, address);
    378         if (rc != EOK) {
    379                 goto failure;
    380         }
    381 
    382         rc = usb_endpoint_pipe_initialize_default_control(&ctrl_pipe,
    383             &dev_connection);
    384         if (rc != EOK) {
    385                 goto failure;
    386         }
    387374
    388375        child = create_device();
     
    403390        child->name = child_name;
    404391        child->ops = &child_ops;
    405 
    406         rc = usb_endpoint_pipe_start_session(&ctrl_pipe);
    407         if (rc != EOK) {
    408                 goto failure;
    409         }
    410 
    411         rc = usb_device_create_match_ids(&ctrl_pipe, &child->match_ids);
    412         if (rc != EOK) {
    413                 goto failure;
    414         }
    415 
    416         rc = usb_endpoint_pipe_end_session(&ctrl_pipe);
     392       
     393        rc = usb_drv_create_device_match_ids(hc, &child->match_ids, address);
    417394        if (rc != EOK) {
    418395                goto failure;
     
    427404                *child_handle = child->handle;
    428405        }
    429 
     406       
    430407        return EOK;
    431408
     
    441418
    442419        return rc;
     420
    443421}
    444422
Note: See TracChangeset for help on using the changeset viewer.