Changes in uspace/drv/bus/usb/usbhub/utils.c [5fd0dc23:5203e256] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/bus/usb/usbhub/utils.c
r5fd0dc23 r5203e256 110 110 } 111 111 112 /*----------------------------------------------------------------------------*/113 112 /** 114 * Deserialize descriptor into given pointer113 * create deserialized desriptor structure out of serialized descriptor 115 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 */ 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 * 116 140 * @param serialized_descriptor 117 141 * @param descriptor 118 142 * @return 119 143 */ 120 int usb_deserialize_hub_desriptor( 121 void *serialized_descriptor, size_t size, usb_hub_descriptor_t *descriptor) 122 { 144 void usb_deserialize_hub_desriptor( 145 void * serialized_descriptor, usb_hub_descriptor_t *descriptor) { 123 146 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 135 147 descriptor->ports_count = sdescriptor[2]; 136 descriptor->hub_characteristics = sdescriptor[3] + 256 * sdescriptor[4]; 148 /// @fixme handling of endianness?? 149 descriptor->hub_characteristics = sdescriptor[4] + 256 * sdescriptor[3]; 137 150 descriptor->pwr_on_2_good_time = sdescriptor[5]; 138 151 descriptor->current_requirement = sdescriptor[6]; 139 constsize_t var_size = (descriptor->ports_count + 7) / 8;152 size_t var_size = (descriptor->ports_count + 7) / 8; 140 153 //descriptor->devices_removable = (uint8_t*) malloc(var_size); 141 154 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) { 155 size_t i; 156 for (i = 0; i < var_size; ++i) { 148 157 descriptor->devices_removable[i] = sdescriptor[7 + i]; 149 158 } 150 return EOK;151 159 } 152 /*----------------------------------------------------------------------------*/ 160 153 161 /** 154 162 * @}
Note:
See TracChangeset
for help on using the changeset viewer.