Changes in uspace/lib/usbdev/src/altiface.c [ab27e01:160b75e] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/usbdev/src/altiface.c
rab27e01 r160b75e 48 48 * @return Number of alternate interfaces for @p interface_no interface. 49 49 */ 50 size_t usb_interface_count_alternates( constuint8_t *config_descr,50 size_t usb_interface_count_alternates(uint8_t *config_descr, 51 51 size_t config_descr_size, uint8_t interface_no) 52 52 { … … 54 54 assert(config_descr_size > 0); 55 55 56 constusb_dp_parser_t dp_parser = {56 usb_dp_parser_t dp_parser = { 57 57 .nesting = usb_dp_standard_descriptor_nesting 58 58 }; 59 constusb_dp_parser_data_t dp_data = {59 usb_dp_parser_data_t dp_data = { 60 60 .data = config_descr, 61 61 .size = config_descr_size, … … 65 65 size_t alternate_count = 0; 66 66 67 constuint8_t *iface_ptr = usb_dp_get_nested_descriptor(&dp_parser,67 uint8_t *iface_ptr = usb_dp_get_nested_descriptor(&dp_parser, 68 68 &dp_data, config_descr); 69 69 while (iface_ptr != NULL) { … … 90 90 * @return Error code. 91 91 */ 92 int usb_alternate_interfaces_init(usb_alternate_interfaces_t *alternates, 93 const uint8_t *config_descr, size_t config_descr_size, int interface_number) 92 int usb_alternate_interfaces_create(uint8_t *config_descr, 93 size_t config_descr_size, int interface_number, 94 usb_alternate_interfaces_t **alternates_ptr) 94 95 { 95 assert(alternates != NULL);96 assert(alternates_ptr != NULL); 96 97 assert(config_descr != NULL); 97 98 assert(config_descr_size > 0); 98 99 99 alternates->alternatives = NULL; 100 alternates->alternative_count = 0; 101 alternates->current = 0; 100 if (interface_number < 0) { 101 alternates_ptr = NULL; 102 return EOK; 103 } 102 104 103 if (interface_number < 0) { 104 return EOK; 105 usb_alternate_interfaces_t *alternates 106 = malloc(sizeof(usb_alternate_interfaces_t)); 107 108 if (alternates == NULL) { 109 return ENOMEM; 105 110 } 106 111 … … 110 115 111 116 if (alternates->alternative_count == 0) { 117 free(alternates); 112 118 return ENOENT; 113 119 } 114 120 115 alternates->alternatives = calloc(alternates->alternative_count,116 sizeof(usb_alternate_interface_descriptors_t));121 alternates->alternatives = malloc(alternates->alternative_count 122 * sizeof(usb_alternate_interface_descriptors_t)); 117 123 if (alternates->alternatives == NULL) { 124 free(alternates); 118 125 return ENOMEM; 119 126 } 120 127 121 const usb_dp_parser_t dp_parser = { 128 alternates->current = 0; 129 130 usb_dp_parser_t dp_parser = { 122 131 .nesting = usb_dp_standard_descriptor_nesting 123 132 }; 124 constusb_dp_parser_data_t dp_data = {133 usb_dp_parser_data_t dp_data = { 125 134 .data = config_descr, 126 135 .size = config_descr_size, … … 131 140 = &alternates->alternatives[0]; 132 141 133 constuint8_t *iface_ptr = usb_dp_get_nested_descriptor(&dp_parser,142 uint8_t *iface_ptr = usb_dp_get_nested_descriptor(&dp_parser, 134 143 &dp_data, dp_data.data); 135 144 while (iface_ptr != NULL) { … … 139 148 || (iface->interface_number != interface_number)) { 140 149 iface_ptr = usb_dp_get_sibling_descriptor(&dp_parser, 141 &dp_data, dp_data.data, iface_ptr); 150 &dp_data, 151 dp_data.data, iface_ptr); 142 152 continue; 143 153 } … … 150 160 dp_data.data, iface_ptr); 151 161 if (iface_ptr == NULL) { 152 constuint8_t *next = dp_data.data + dp_data.size;162 uint8_t *next = dp_data.data + dp_data.size; 153 163 cur_alt_iface->nested_descriptors_size 154 164 = next - cur_alt_iface->nested_descriptors; … … 161 171 } 162 172 173 *alternates_ptr = alternates; 174 163 175 return EOK; 164 176 } 165 177 166 void usb_alternate_interfaces_deinit(usb_alternate_interfaces_t *alternate) 167 { 168 if (!alternate) 169 return; 170 free(alternate->alternatives); 171 } 178 172 179 /** 173 180 * @}
Note:
See TracChangeset
for help on using the changeset viewer.