Changes in uspace/drv/bus/usb/usbhub/utils.c [5203e256:5fd0dc23] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/bus/usb/usbhub/utils.c
r5203e256 r5fd0dc23 110 110 } 111 111 112 /*----------------------------------------------------------------------------*/ 112 113 /** 113 * create deserialized desriptor structure out of serialized descriptor114 * Deserialize descriptor into given pointer 114 115 * 115 * The serialized descriptor must be proper usb hub descriptor,116 * otherwise an eerror might occur.117 *118 * @param sdescriptor serialized descriptor119 * @return newly created deserialized descriptor pointer120 */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 pointer139 *140 116 * @param serialized_descriptor 141 117 * @param descriptor 142 118 * @return 143 119 */ 144 void usb_deserialize_hub_desriptor( 145 void * serialized_descriptor, usb_hub_descriptor_t *descriptor) { 120 int usb_deserialize_hub_desriptor( 121 void *serialized_descriptor, size_t size, usb_hub_descriptor_t *descriptor) 122 { 146 123 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 147 135 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]; 150 137 descriptor->pwr_on_2_good_time = sdescriptor[5]; 151 138 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; 153 140 //descriptor->devices_removable = (uint8_t*) malloc(var_size); 154 141 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) { 157 148 descriptor->devices_removable[i] = sdescriptor[7 + i]; 158 149 } 150 return EOK; 159 151 } 160 152 /*----------------------------------------------------------------------------*/ 161 153 /** 162 154 * @}
Note:
See TracChangeset
for help on using the changeset viewer.