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

Changeset 6c69d19 in mainline for uspace/drv/bus/usb/usbhub/utils.c


Ignore:
Timestamp:
2011-07-25T20:34:17Z (10 years ago)
Author:
Jiří Zárevúcky <zarevucky.jiri@…>
Branches:
lfn, master
Children:
00c2de63, c936c7f
Parents:
5889fc74 (diff), d542aad (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:

Merge libposix.

File:
1 edited

Legend:

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

    r5889fc74 r6c69d19  
    110110}
    111111
     112/*----------------------------------------------------------------------------*/
    112113/**
    113  * create deserialized desriptor structure out of serialized descriptor
     114 * Deserialize descriptor into given pointer
    114115 *
    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  */
    121 usb_hub_descriptor_t * usb_create_deserialized_hub_desriptor(
    122     void *serialized_descriptor) {
    123         uint8_t * sdescriptor = serialized_descriptor;
    124 
    125         if (sdescriptor[1] != USB_DESCTYPE_HUB) {
    126                 usb_log_warning("trying to deserialize wrong descriptor %x\n",
    127                     sdescriptor[1]);
    128                 return NULL;
    129         }
    130 
    131         usb_hub_descriptor_t * result = malloc(sizeof (usb_hub_descriptor_t));
    132         if (result)
    133                 usb_deserialize_hub_desriptor(serialized_descriptor, result);
    134         return result;
    135 }
    136 
    137 /**
    138  * deserialize descriptor into given pointer
    139  *
    140116 * @param serialized_descriptor
    141117 * @param descriptor
    142118 * @return
    143119 */
    144 void usb_deserialize_hub_desriptor(
    145     void * serialized_descriptor, usb_hub_descriptor_t *descriptor) {
     120int usb_deserialize_hub_desriptor(
     121    void *serialized_descriptor, size_t size, usb_hub_descriptor_t *descriptor)
     122{
    146123        uint8_t * sdescriptor = serialized_descriptor;
     124
     125        if (sdescriptor[1] != USB_DESCTYPE_HUB) {
     126                usb_log_error("Trying to deserialize wrong descriptor %x\n",
     127                    sdescriptor[1]);
     128                return EINVAL;
     129        }
     130        if (size < 7) {
     131                usb_log_error("Serialized descriptor too small.\n");
     132                return EOVERFLOW;
     133        }
     134
    147135        descriptor->ports_count = sdescriptor[2];
    148         /// @fixme handling of endianness??
    149         descriptor->hub_characteristics = sdescriptor[4] + 256 * sdescriptor[3];
     136        descriptor->hub_characteristics = sdescriptor[3] + 256 * sdescriptor[4];
    150137        descriptor->pwr_on_2_good_time = sdescriptor[5];
    151138        descriptor->current_requirement = sdescriptor[6];
    152         size_t var_size = (descriptor->ports_count + 7) / 8;
     139        const size_t var_size = (descriptor->ports_count + 7) / 8;
    153140        //descriptor->devices_removable = (uint8_t*) malloc(var_size);
    154141
    155         size_t i;
    156         for (i = 0; i < var_size; ++i) {
     142        if (size < (7 + var_size)) {
     143                usb_log_error("Serialized descriptor too small.\n");
     144                return EOVERFLOW;
     145        }
     146        size_t i = 0;
     147        for (; i < var_size; ++i) {
    157148                descriptor->devices_removable[i] = sdescriptor[7 + i];
    158149        }
     150        return EOK;
    159151}
    160 
     152/*----------------------------------------------------------------------------*/
    161153/**
    162154 * @}
Note: See TracChangeset for help on using the changeset viewer.