Ignore:
File:
1 edited

Legend:

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

    r9ca0013 r4317827  
    109109//*********************************************
    110110
     111static void set_hub_address(device_t *dev, usb_address_t address);
     112
    111113usb_hcd_hub_info_t * usb_create_hub_info(device_t * device) {
    112114        usb_hcd_hub_info_t* result = (usb_hcd_hub_info_t*) malloc(sizeof (usb_hcd_hub_info_t));
     
    122124int usb_add_hub_device(device_t *dev) {
    123125        printf(NAME ": add_hub_device(handle=%d)\n", (int) dev->handle);
     126        set_hub_address(dev, 5);
    124127
    125128        check_hub_changes();
     
    139142}
    140143
     144/** Sample usage of usb_hc_async functions.
     145 * This function sets hub address using standard SET_ADDRESS request.
     146 *
     147 * @warning This function shall be removed once you are familiar with
     148 * the usb_hc_ API.
     149 *
     150 * @param hc Host controller the hub belongs to.
     151 * @param address New hub address.
     152 */
     153static void set_hub_address(device_t *dev, usb_address_t address) {
     154        printf(NAME ": setting hub address to %d\n", address);
     155        usb_target_t target = {0, 0};
     156        usb_handle_t handle;
     157        int rc;
     158
     159        usb_device_request_setup_packet_t setup_packet = {
     160                .request_type = 0,
     161                .request = USB_DEVREQ_SET_ADDRESS,
     162                .index = 0,
     163                .length = 0,
     164        };
     165        setup_packet.value = address;
     166
     167        int hc = usb_drv_hc_connect(dev, 0);
     168
     169        rc = usb_drv_async_control_write_setup(hc, target,
     170                        &setup_packet, sizeof (setup_packet), &handle);
     171        if (rc != EOK) {
     172                return;
     173        }
     174
     175        rc = usb_drv_async_wait_for(handle);
     176        if (rc != EOK) {
     177                return;
     178        }
     179
     180        rc = usb_drv_async_control_write_status(hc, target, &handle);
     181        if (rc != EOK) {
     182                return;
     183        }
     184
     185        rc = usb_drv_async_wait_for(handle);
     186        if (rc != EOK) {
     187                return;
     188        }
     189
     190        printf(NAME ": hub address changed\n");
     191}
    141192
    142193/** Check changes on all known hubs.
     
    186237                 */
    187238
    188                 /*
    189                  * WARNING: sample code, will not work out of the box.
    190                  * And does not contain code for checking for errors.
    191                  */
    192 #if 0
    193                 /*
    194                  * Before opening the port, we must acquire the default
    195                  * address.
    196                  */
    197                 usb_drv_reserve_default_address(hc);
    198 
    199                 usb_address_t new_device_address = usb_drv_request_address(hc);
    200 
    201                 // TODO: open the port
    202 
    203                 // TODO: send request for setting address to new_device_address
    204 
    205                 /*
    206                  * Once new address is set, we can release the default
    207                  * address.
    208                  */
    209                 usb_drv_release_default_address(hc);
    210 
    211                 /*
    212                  * Obtain descriptors and create match ids for devman.
    213                  */
    214 
    215                 // TODO: get device descriptors
    216 
    217                 // TODO: create match ids
    218 
    219                 // TODO: add child device
    220 
    221                 // child_device_register sets the device handle
    222                 // TODO: store it here
    223                 devman_handle_t new_device_handle = 0;
    224 
    225                 /*
    226                  * Inform the HC that the new device has devman handle
    227                  * assigned.
    228                  */
    229                 usb_drv_bind_address(hc, new_device_address, new_device_handle);
    230 
    231                 /*
    232                  * That's all.
    233                  */
    234 #endif
    235 
    236239
    237240                /*
Note: See TracChangeset for help on using the changeset viewer.