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

Changeset cd5b878 in mainline


Ignore:
Timestamp:
2011-04-15T11:49:36Z (11 years ago)
Author:
Matus Dekanek <smekideki@…>
Branches:
lfn, master
Children:
c1693dae
Parents:
3a85a2b
Message:

removed pipe start/end functions; small changes in usb_hub_descriptor_type (less malloc)

Location:
uspace
Files:
4 edited

Legend:

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

    r3a85a2b rcd5b878  
    105105        }
    106106
    107         usb_pipe_start_session(hub_info->control_pipe);
     107        //usb_pipe_start_session(hub_info->control_pipe);
    108108        //set hub configuration
    109109        opResult = usb_hub_set_configuration(hub_info);
     
    122122                return opResult;
    123123        }
    124         usb_pipe_end_session(hub_info->control_pipe);
     124        //usb_pipe_end_session(hub_info->control_pipe);
    125125
    126126        /// \TODO what is this?
     
    235235        }
    236236        usb_log_debug2("deserializing descriptor\n");
    237         descriptor = usb_deserialize_hub_desriptor(serialized_descriptor);
     237        descriptor = usb_create_deserialized_hub_desriptor(
     238            serialized_descriptor);
    238239        if (descriptor == NULL) {
    239240                usb_log_warning("could not deserialize descriptor \n");
     
    259260        usb_log_debug2("freeing data\n");
    260261        free(serialized_descriptor);
    261         free(descriptor->devices_removable);
     262        //free(descriptor->devices_removable);
    262263        free(descriptor);
    263264        return EOK;
     
    321322         * auto destruction, this could work better.
    322323         */
    323         int rc = usb_pipe_start_session(hub_info->control_pipe);
     324        int rc = usb_hc_connection_open(&hub_info->connection);
    324325        if (rc != EOK) {
    325                 usb_log_error("Failed to start session on control pipe: %s.\n",
    326                     str_error(rc));
    327                 return rc;
    328         }
    329         rc = usb_hc_connection_open(&hub_info->connection);
    330         if (rc != EOK) {
    331                 usb_pipe_end_session(hub_info->control_pipe);
     326                //usb_pipe_end_session(hub_info->control_pipe);
    332327                usb_log_error("Failed to open connection to HC: %s.\n",
    333328                    str_error(rc));
  • uspace/drv/usbhub/usbhub_private.h

    r3a85a2b rcd5b878  
    166166}
    167167
    168 /**
    169  * create uint8_t array with serialized descriptor
    170  *
    171  * @param descriptor
    172  * @return newly created serializd descriptor pointer
    173  */
    174 void * usb_serialize_hub_descriptor(usb_hub_descriptor_t * descriptor);
    175168
    176 /**
    177  * create deserialized desriptor structure out of serialized descriptor
    178  *
    179  * The serialized descriptor must be proper usb hub descriptor,
    180  * otherwise an eerror might occur.
    181  *
    182  * @param sdescriptor serialized descriptor
    183  * @return newly created deserialized descriptor pointer
    184  */
    185 usb_hub_descriptor_t * usb_deserialize_hub_desriptor(void * sdescriptor);
     169void * usb_create_serialized_hub_descriptor(usb_hub_descriptor_t * descriptor);
     170
     171void usb_serialize_hub_descriptor(usb_hub_descriptor_t * descriptor,
     172    void * serialized_descriptor);
     173
     174usb_hub_descriptor_t * usb_create_deserialized_hub_desriptor(
     175    void * serialized_descriptor);
     176
     177void usb_deserialize_hub_desriptor(void * serialized_descriptor,
     178    usb_hub_descriptor_t * descriptor);
    186179
    187180
  • uspace/drv/usbhub/utils.c

    r3a85a2b rcd5b878  
    5656//hub descriptor utils
    5757
    58 void * usb_serialize_hub_descriptor(usb_hub_descriptor_t * descriptor) {
     58/**
     59 * create uint8_t array with serialized descriptor
     60 *
     61 * @param descriptor
     62 * @return newly created serializd descriptor pointer
     63 */
     64void * usb_create_serialized_hub_descriptor(usb_hub_descriptor_t * descriptor) {
    5965        //base size
    6066        size_t size = 7;
     
    6470        uint8_t * result = malloc(size);
    6571        //size
    66         result[0] = size;
     72        usb_serialize_hub_descriptor(descriptor,result);
     73        return result;
     74}
     75
     76/**
     77 * serialize descriptor into given buffer
     78 *
     79 * The buffer size is not checked.
     80 * @param descriptor
     81 * @param serialized_descriptor
     82 */
     83void usb_serialize_hub_descriptor(usb_hub_descriptor_t * descriptor,
     84    void * serialized_descriptor) {
     85        //base size
     86        uint8_t * sdescriptor = serialized_descriptor;
     87        size_t size = 7;
     88        //variable size according to port count
     89        size_t var_size = (descriptor->ports_count+7)/8;
     90        size += 2 * var_size;
     91        //size
     92        sdescriptor[0] = size;
    6793        //descriptor type
    68         result[1] = USB_DESCTYPE_HUB;
    69         result[2] = descriptor->ports_count;
     94        sdescriptor[1] = USB_DESCTYPE_HUB;
     95        sdescriptor[2] = descriptor->ports_count;
    7096        /// @fixme handling of endianness??
    71         result[3] = descriptor->hub_characteristics / 256;
    72         result[4] = descriptor->hub_characteristics % 256;
    73         result[5] = descriptor->pwr_on_2_good_time;
    74         result[6] = descriptor->current_requirement;
     97        sdescriptor[3] = descriptor->hub_characteristics / 256;
     98        sdescriptor[4] = descriptor->hub_characteristics % 256;
     99        sdescriptor[5] = descriptor->pwr_on_2_good_time;
     100        sdescriptor[6] = descriptor->current_requirement;
    75101
    76102        size_t i;
    77103        for (i = 0; i < var_size; ++i) {
    78                 result[7 + i] = descriptor->devices_removable[i];
     104                sdescriptor[7 + i] = descriptor->devices_removable[i];
    79105        }
    80106        for (i = 0; i < var_size; ++i) {
    81                 result[7 + var_size + i] = 255;
     107                sdescriptor[7 + var_size + i] = 255;
    82108        }
    83         return result;
    84109}
    85110
    86 usb_hub_descriptor_t * usb_deserialize_hub_desriptor(
     111
     112/**
     113 * create deserialized desriptor structure out of serialized descriptor
     114 *
     115 * The serialized descriptor must be proper usb hub descriptor,
     116 * otherwise an eerror might occur.
     117 *
     118 * @param sdescriptor serialized descriptor
     119 * @return newly created deserialized descriptor pointer
     120 */
     121usb_hub_descriptor_t * usb_create_deserialized_hub_desriptor(
    87122void * serialized_descriptor) {
    88123        uint8_t * sdescriptor = serialized_descriptor;
     
    95130
    96131        usb_hub_descriptor_t * result = malloc(sizeof(usb_hub_descriptor_t));
    97        
     132        if(result)
     133                usb_deserialize_hub_desriptor(serialized_descriptor,result);
     134        return result;
     135}
    98136
    99         result->ports_count = sdescriptor[2];
     137/**
     138 * deserialize descriptor into given pointer
     139 *
     140 * @param serialized_descriptor
     141 * @param descriptor
     142 * @return
     143 */
     144void usb_deserialize_hub_desriptor(
     145void * serialized_descriptor, usb_hub_descriptor_t * descriptor) {
     146        uint8_t * sdescriptor = serialized_descriptor;
     147        descriptor->ports_count = sdescriptor[2];
    100148        /// @fixme handling of endianness??
    101         result->hub_characteristics = sdescriptor[4] + 256 * sdescriptor[3];
    102         result->pwr_on_2_good_time = sdescriptor[5];
    103         result->current_requirement = sdescriptor[6];
    104         size_t var_size = (result->ports_count+7) / 8;
    105         result->devices_removable = (uint8_t*) malloc(var_size);
     149        descriptor->hub_characteristics = sdescriptor[4] + 256 * sdescriptor[3];
     150        descriptor->pwr_on_2_good_time = sdescriptor[5];
     151        descriptor->current_requirement = sdescriptor[6];
     152        size_t var_size = (descriptor->ports_count+7) / 8;
     153        //descriptor->devices_removable = (uint8_t*) malloc(var_size);
    106154
    107155        size_t i;
    108156        for (i = 0; i < var_size; ++i) {
    109                 result->devices_removable[i] = sdescriptor[7 + i];
     157                descriptor->devices_removable[i] = sdescriptor[7 + i];
    110158        }
    111         return result;
    112159}
    113 
    114 
    115160
    116161/**
  • uspace/lib/usb/include/usb/classes/hub.h

    r3a85a2b rcd5b878  
    152152            maximum of 255 ports).
    153153     */
    154     uint8_t * devices_removable;
     154    uint8_t devices_removable[32];
    155155
    156156    /**
Note: See TracChangeset for help on using the changeset viewer.