Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset 10096231 in mainline


Ignore:
Timestamp:
2010-12-10T16:44:57Z (11 years ago)
Author:
Matus Dekanek <smekideki@…>
Branches:
lfn, master
Children:
fa9b606
Parents:
c01255c
Message:

hub is successfully initialized

Location:
uspace
Files:
6 edited

Legend:

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

    rc01255c r10096231  
    5050} usb_hub_info_t;
    5151
    52 
    5352int usb_add_hub_device(device_t *);
    5453
  • uspace/drv/usbhub/usbhub_private.h

    rc01255c r10096231  
    4242#include <driver.h>
    4343#include <usb/usb.h>
     44#include <usb/classes/hub.h>
    4445#include <usb/devreq.h>
    4546
     
    152153 * @param request
    153154 * @param addr
     155 * \TODO this will be obsolete see usb/dev_req.h
    154156 */
    155157static inline void usb_hub_set_set_address_request(
     
    169171 * @param addr
    170172 */
    171 static inline void usb_hub_get_descriptor_request(
     173static inline void usb_hub_set_descriptor_request(
    172174usb_device_request_setup_packet_t * request
    173175){
     
    175177        request->request_type = USB_HUB_REQ_TYPE_GET_DESCRIPTOR;
    176178        request->request = USB_HUB_REQUEST_GET_DESCRIPTOR;
    177         request->value = USB_DESCTYPE_HUB;
     179        request->value_high = USB_DESCTYPE_HUB;
     180        request->value_low = 0;
    178181        request->length = USB_HUB_MAX_DESCRIPTOR_SIZE;
    179182}
  • uspace/drv/usbhub/utils.c

    rc01255c r10096231  
    8989usb_hub_descriptor_t * usb_deserialize_hub_desriptor(void * serialized_descriptor) {
    9090        uint8_t * sdescriptor = (uint8_t*) serialized_descriptor;
    91         if (sdescriptor[1] != USB_DESCTYPE_HUB) return NULL;
     91
     92        if (sdescriptor[1] != USB_DESCTYPE_HUB) {
     93                printf("[usb_hub] wrong descriptor %x\n",sdescriptor[1]);
     94                return NULL;
     95        }
     96
    9297        usb_hub_descriptor_t * result = usb_new(usb_hub_descriptor_t);
    93         //uint8_t size = sdescriptor[0];
     98       
     99
    94100        result->ports_count = sdescriptor[2];
    95101        /// @fixme handling of endianness??
     
    99105        size_t var_size = result->ports_count / 8 + ((result->ports_count % 8 > 0) ? 1 : 0);
    100106        result->devices_removable = (uint8_t*) malloc(var_size);
    101 
     107        //printf("[usb_hub] getting removable devices data \n");
    102108        size_t i;
    103109        for (i = 0; i < var_size; ++i) {
     
    298304
    299305
    300         printf("[usb_hub] phone to hc = %d\n", hc);
     306        //printf("[usb_hub] phone to hc = %d\n", hc);
    301307        if (hc < 0) {
    302308                return result;
    303309        }
    304310        //get some hub info
    305         /// \TODO get correct params
    306311        usb_address_t addr = usb_drv_get_my_address(hc, device);
    307312        addr = 7;
     
    320325        target.endpoint = 0;
    321326        usb_device_request_setup_packet_t request;
    322         usb_hub_get_descriptor_request(&request);
     327        //printf("[usb_hub] creating descriptor request\n");
     328        usb_hub_set_descriptor_request(&request);
     329
     330        //printf("[usb_hub] creating serialized descriptor\n");
    323331        void * serialized_descriptor = malloc(USB_HUB_MAX_DESCRIPTOR_SIZE);
    324332        usb_hub_descriptor_t * descriptor;
    325333        size_t received_size;
    326334        int opResult;
    327 
     335        //printf("[usb_hub] starting control transaction\n");
    328336        opResult = usb_drv_sync_control_read(
    329337                        hc, target, &request, serialized_descriptor,
    330338                        USB_HUB_MAX_DESCRIPTOR_SIZE, &received_size);
    331339        if (opResult != EOK) {
    332                 printf("[usb_hub] failed when receiving hub descriptor \n");
    333         }
     340                printf("[usb_hub] failed when receiving hub descriptor, badcode = %d\n",opResult);
     341                ///\TODO memory leak will occur here!
     342                return result;
     343        }
     344        //printf("[usb_hub] deserializing descriptor\n");
    334345        descriptor = usb_deserialize_hub_desriptor(serialized_descriptor);
     346        if(descriptor==NULL){
     347                printf("[usb_hub] could not deserialize descriptor \n");
     348                result->port_count = 1;///\TODO this code is only for debug!!!
     349                return result;
     350        }
     351        //printf("[usb_hub] setting port count to %d\n",descriptor->ports_count);
    335352        result->port_count = descriptor->ports_count;
     353        //printf("[usb_hub] freeing data\n");
    336354        free(serialized_descriptor);
     355        free(descriptor->devices_removable);
    337356        free(descriptor);
    338357
     
    362381        //get hc connection
    363382        /// \TODO correct params
    364         int hc = usb_drv_hc_connect(NULL, 0);
     383        int hc = usb_drv_hc_connect(dev, 0);
    365384
    366385        usb_hub_info_t * hub_info = usb_create_hub_info(dev, hc);
     
    416435        int opResult;
    417436        printf("[usb_hub] some connection changed\n");
     437
    418438        opResult = usb_drv_reserve_default_address(hc);
    419439        if (opResult != EOK) {
    420440                printf("[usb_hub] cannot assign default address, it is probably used\n");
     441                return;
    421442        }
    422443        //reset port
     
    456477        if (opResult != EOK) {
    457478                printf("[usb_hub] could not set address for new device\n");
     479                //will retry later...
     480                return;
    458481        }
    459482        usb_drv_release_default_address(hc);
     
    461484
    462485        /// \TODO driver work
     486        //add_child_device.....
    463487}
    464488
  • uspace/drv/vhc/hubops.c

    rc01255c r10096231  
    195195}
    196196
    197 static int get_hub_descriptor(uint8_t descriptor_type,
    198     uint8_t descriptor_index, uint16_t length)
    199 {
     197static int get_hub_descriptor(struct usbvirt_device *dev,
     198    uint8_t descriptor_index,
     199    uint8_t descriptor_type, uint16_t length)
     200{
     201        if (descriptor_type == USB_DESCTYPE_HUB) {
     202                int rc = dev->control_transfer_reply(dev, 0,
     203                    &hub_descriptor, hub_descriptor.length);
     204
     205                return rc;
     206
     207        }
     208
    200209        return ENOTSUP;
    201210}
     
    313322                       
    314323                case USB_HUB_REQUEST_GET_DESCRIPTOR:
    315                         return get_hub_descriptor(request->value_low,
     324                        return get_hub_descriptor(dev, request->value_low,
    316325                            request->value_high, request->length);
    317326                       
  • uspace/lib/usb/include/usb/classes/hub.h

    rc01255c r10096231  
    177177
    178178/** @brief hub class request codes*/
     179/// \TODO these are duplicit to standart descriptors
    179180typedef enum {
    180181    /**  */
  • uspace/lib/usbvirt/transaction.c

    rc01255c r10096231  
    184184                                actual_size = size;
    185185                        }
     186                        device->lib_debug(device, 1, USBVIRT_DEBUGTAG_TRANSACTION,
     187                            "in transaction: will copy %zu bytes", actual_size);
    186188                        if (actual_size > 0) {
    187189                                memcpy(buffer, transfer->data, actual_size);
Note: See TracChangeset for help on using the changeset viewer.