Changes in uspace/lib/usbdev/src/altiface.c [e978ada:69b9740] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/usbdev/src/altiface.c
re978ada r69b9740 65 65 size_t alternate_count = 0; 66 66 67 const uint8_t *iface_ptr = usb_dp_get_nested_descriptor(&dp_parser,68 &dp_data, config_descr);67 const void *iface_ptr = 68 usb_dp_get_nested_descriptor(&dp_parser, &dp_data, config_descr); 69 69 while (iface_ptr != NULL) { 70 usb_standard_interface_descriptor_t *iface 71 = (usb_standard_interface_descriptor_t *) iface_ptr; 72 if (iface->descriptor_type == USB_DESCTYPE_INTERFACE) { 73 if (iface->interface_number == interface_no) { 74 alternate_count++; 75 } 70 const usb_standard_interface_descriptor_t *iface = iface_ptr; 71 if (iface->descriptor_type == USB_DESCTYPE_INTERFACE 72 && iface->interface_number == interface_no) { 73 ++alternate_count; 76 74 } 77 75 iface_ptr = usb_dp_get_sibling_descriptor(&dp_parser, &dp_data, … … 82 80 } 83 81 84 /** Create alternate interface representation structure.82 /** Initialize alternate interface representation structure. 85 83 * 84 * @param[in] alternates Pointer to allocated structure. 86 85 * @param[in] config_descr Configuration descriptor. 87 86 * @param[in] config_descr_size Size of configuration descriptor. 88 87 * @param[in] interface_number Interface number. 89 * @param[out] alternates_ptr Where to store pointer to allocated structure.90 88 * @return Error code. 91 89 */ 92 int usb_alternate_interfaces_create(const uint8_t *config_descr, 93 size_t config_descr_size, int interface_number, 94 usb_alternate_interfaces_t **alternates_ptr) 90 int usb_alternate_interfaces_init(usb_alternate_interfaces_t *alternates, 91 const uint8_t *config_descr, size_t config_descr_size, int interface_number) 95 92 { 96 assert(alternates _ptr!= NULL);93 assert(alternates != NULL); 97 94 assert(config_descr != NULL); 98 95 assert(config_descr_size > 0); 99 96 100 *alternates_ptr = NULL; 97 alternates->alternatives = NULL; 98 alternates->alternative_count = 0; 99 alternates->current = 0; 100 101 /* No interfaces. */ 101 102 if (interface_number < 0) { 102 103 return EOK; 103 104 } 104 105 105 usb_alternate_interfaces_t *alternates106 = malloc(sizeof(usb_alternate_interfaces_t));107 if (alternates == NULL) {108 return ENOMEM;109 }110 111 106 alternates->alternative_count 112 107 = usb_interface_count_alternates(config_descr, config_descr_size, 113 interface_number);108 interface_number); 114 109 115 110 if (alternates->alternative_count == 0) { 116 free(alternates);117 111 return ENOENT; 118 112 } … … 121 115 sizeof(usb_alternate_interface_descriptors_t)); 122 116 if (alternates->alternatives == NULL) { 123 free(alternates);124 117 return ENOMEM; 125 118 } 126 119 127 alternates->current = 0; 128 129 usb_dp_parser_t dp_parser = { 120 const usb_dp_parser_t dp_parser = { 130 121 .nesting = usb_dp_standard_descriptor_nesting 131 122 }; 132 usb_dp_parser_data_t dp_data = {123 const usb_dp_parser_data_t dp_data = { 133 124 .data = config_descr, 134 125 .size = config_descr_size, … … 136 127 }; 137 128 138 usb_alternate_interface_descriptors_t * cur_alt_iface129 usb_alternate_interface_descriptors_t *iterator 139 130 = &alternates->alternatives[0]; 140 131 141 const uint8_t *iface_ptr = usb_dp_get_nested_descriptor(&dp_parser, 142 &dp_data, dp_data.data); 143 while (iface_ptr != NULL) { 144 usb_standard_interface_descriptor_t *iface 145 = (usb_standard_interface_descriptor_t *) iface_ptr; 132 const usb_alternate_interface_descriptors_t *end 133 = &alternates->alternatives[alternates->alternative_count]; 134 135 const void *iface_ptr = 136 usb_dp_get_nested_descriptor(&dp_parser, &dp_data, dp_data.data); 137 138 while (iface_ptr != NULL && iterator < end) { 139 const usb_standard_interface_descriptor_t *iface = iface_ptr; 140 146 141 if ((iface->descriptor_type != USB_DESCTYPE_INTERFACE) 147 142 || (iface->interface_number != interface_number)) { 143 /* This is not a valid alternate interface descriptor 144 * for interface with number == interface_number. */ 148 145 iface_ptr = usb_dp_get_sibling_descriptor(&dp_parser, 149 &dp_data, 150 dp_data.data, iface_ptr); 146 &dp_data, dp_data.data, iface_ptr); 151 147 continue; 152 148 } 153 149 154 cur_alt_iface->interface = iface;155 cur_alt_iface->nested_descriptors = iface_ptr + sizeof(*iface);150 iterator->interface = iface; 151 iterator->nested_descriptors = iface_ptr + sizeof(*iface); 156 152 157 153 /* Find next interface to count size of nested descriptors. */ 158 154 iface_ptr = usb_dp_get_sibling_descriptor(&dp_parser, &dp_data, 159 155 dp_data.data, iface_ptr); 160 if (iface_ptr == NULL) {161 const uint8_t *next = dp_data.data + dp_data.size;162 cur_alt_iface->nested_descriptors_size163 = next - cur_alt_iface->nested_descriptors;164 } else {165 cur_alt_iface->nested_descriptors_size166 = iface_ptr - cur_alt_iface->nested_descriptors;167 }168 156 169 cur_alt_iface++; 157 const uint8_t *next = (iface_ptr == NULL) ? 158 dp_data.data + dp_data.size : iface_ptr; 159 160 iterator->nested_descriptors_size 161 = next - iterator->nested_descriptors; 162 163 ++iterator; 170 164 } 171 172 *alternates_ptr = alternates;173 165 174 166 return EOK; 175 167 } 176 168 177 void usb_alternate_interfaces_de stroy(usb_alternate_interfaces_t *alternate)169 void usb_alternate_interfaces_deinit(usb_alternate_interfaces_t *alternate) 178 170 { 179 171 if (!alternate) 180 172 return; 181 173 free(alternate->alternatives); 182 free(alternate);183 174 } 184 175 /**
Note:
See TracChangeset
for help on using the changeset viewer.