Changes in uspace/lib/usbdev/src/dp.c [160b75e:8a121b1] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/usbdev/src/dp.c
r160b75e r8a121b1 75 75 * @return Whether @p ptr points inside <code>data->data</code> field. 76 76 */ 77 static bool is_valid_descriptor_pointer( usb_dp_parser_data_t *data,78 uint8_t *ptr)77 static bool is_valid_descriptor_pointer(const usb_dp_parser_data_t *data, 78 const uint8_t *ptr) 79 79 { 80 80 if (ptr == NULL) { … … 100 100 * @retval NULL Invalid input or no next descriptor. 101 101 */ 102 static uint8_t *get_next_descriptor(usb_dp_parser_data_t *data,103 uint8_t *current)102 static const uint8_t *get_next_descriptor(const usb_dp_parser_data_t *data, 103 const uint8_t *current) 104 104 { 105 105 assert(is_valid_descriptor_pointer(data, current)); 106 106 107 uint8_t current_length = *current;108 uint8_t *next = current + current_length;107 const uint8_t current_length = *current; 108 const uint8_t *next = current + current_length; 109 109 110 110 if (!is_valid_descriptor_pointer(data, next)) { … … 124 124 * @retval -1 Invalid input. 125 125 */ 126 static int get_descriptor_type( usb_dp_parser_data_t *data,uint8_t *start)126 static int get_descriptor_type(const usb_dp_parser_data_t *data, const uint8_t *start) 127 127 { 128 128 if (start == NULL) { … … 145 145 * @return Whether @p child could be child of @p parent. 146 146 */ 147 static bool is_nested_descriptor_type( usb_dp_parser_t *parser,147 static bool is_nested_descriptor_type(const usb_dp_parser_t *parser, 148 148 int child, int parent) 149 149 { 150 usb_dp_descriptor_nesting_t *nesting = parser->nesting;150 const usb_dp_descriptor_nesting_t *nesting = parser->nesting; 151 151 while ((nesting->child > 0) && (nesting->parent > 0)) { 152 152 if ((nesting->child == child) && (nesting->parent == parent)) { … … 166 166 * @return Whether @p child could be child of @p parent. 167 167 */ 168 static bool is_nested_descriptor( usb_dp_parser_t *parser,169 usb_dp_parser_data_t *data, uint8_t *child,uint8_t *parent)168 static bool is_nested_descriptor(const usb_dp_parser_t *parser, 169 const usb_dp_parser_data_t *data, const uint8_t *child, const uint8_t *parent) 170 170 { 171 171 return is_nested_descriptor_type(parser, … … 183 183 * @retval NULL Invalid input. 184 184 */ 185 uint8_t *usb_dp_get_nested_descriptor(usb_dp_parser_t *parser,186 usb_dp_parser_data_t *data,uint8_t *parent)185 const uint8_t *usb_dp_get_nested_descriptor(const usb_dp_parser_t *parser, 186 const usb_dp_parser_data_t *data, const uint8_t *parent) 187 187 { 188 188 if (!is_valid_descriptor_pointer(data, parent)) { … … 190 190 } 191 191 192 uint8_t *next = get_next_descriptor(data, parent);192 const uint8_t *next = get_next_descriptor(data, parent); 193 193 if (next == NULL) { 194 194 return NULL; … … 211 211 * @retval NULL Invalid input. 212 212 */ 213 static uint8_t *skip_nested_descriptors(usb_dp_parser_t *parser, 214 usb_dp_parser_data_t *data, uint8_t *parent) 215 { 216 uint8_t *child = usb_dp_get_nested_descriptor(parser, data, parent); 213 static const uint8_t *skip_nested_descriptors(const usb_dp_parser_t *parser, 214 const usb_dp_parser_data_t *data, const uint8_t *parent) 215 { 216 const uint8_t *child = 217 usb_dp_get_nested_descriptor(parser, data, parent); 217 218 if (child == NULL) { 218 219 return get_next_descriptor(data, parent); 219 220 } 220 uint8_t *next_child = skip_nested_descriptors(parser, data, child); 221 const uint8_t *next_child = 222 skip_nested_descriptors(parser, data, child); 221 223 while (is_nested_descriptor(parser, data, next_child, parent)) { 222 224 next_child = skip_nested_descriptors(parser, data, next_child); … … 236 238 * @retval NULL Invalid input. 237 239 */ 238 uint8_t *usb_dp_get_sibling_descriptor(usb_dp_parser_t *parser, 239 usb_dp_parser_data_t *data, uint8_t *parent, uint8_t *sibling) 240 const uint8_t *usb_dp_get_sibling_descriptor( 241 const usb_dp_parser_t *parser, const usb_dp_parser_data_t *data, 242 const uint8_t *parent, const uint8_t *sibling) 240 243 { 241 244 if (!is_valid_descriptor_pointer(data, parent) … … 244 247 } 245 248 246 uint8_t *possible_sibling = skip_nested_descriptors(parser, data, sibling); 249 const uint8_t *possible_sibling = 250 skip_nested_descriptors(parser, data, sibling); 247 251 if (possible_sibling == NULL) { 248 252 return NULL; … … 269 273 * @param arg Custom (user) argument. 270 274 */ 271 static void usb_dp_browse_simple_internal( usb_dp_parser_t *parser,272 usb_dp_parser_data_t *data,uint8_t *root, size_t depth,273 void (*callback)( uint8_t *, size_t, void *), void *arg)275 static void usb_dp_browse_simple_internal(const usb_dp_parser_t *parser, 276 const usb_dp_parser_data_t *data, const uint8_t *root, size_t depth, 277 void (*callback)(const uint8_t *, size_t, void *), void *arg) 274 278 { 275 279 if (root == NULL) { … … 277 281 } 278 282 callback(root, depth, arg); 279 uint8_t *child = usb_dp_get_nested_descriptor(parser, data, root);283 const uint8_t *child = usb_dp_get_nested_descriptor(parser, data, root); 280 284 do { 281 285 usb_dp_browse_simple_internal(parser, data, child, depth + 1, … … 301 305 */ 302 306 void usb_dp_walk_simple(uint8_t *descriptors, size_t descriptors_size, 303 usb_dp_descriptor_nesting_t *descriptor_nesting,304 void (*callback)(uint8_t *, size_t, void *), void *arg)307 const usb_dp_descriptor_nesting_t *descriptor_nesting, 308 walk_callback_t callback, void *arg) 305 309 { 306 310 if ((descriptors == NULL) || (descriptors_size == 0) … … 309 313 } 310 314 311 usb_dp_parser_data_t data = {315 const usb_dp_parser_data_t data = { 312 316 .data = descriptors, 313 317 .size = descriptors_size, … … 315 319 }; 316 320 317 usb_dp_parser_t parser = {321 const usb_dp_parser_t parser = { 318 322 .nesting = descriptor_nesting 319 323 };
Note:
See TracChangeset
for help on using the changeset viewer.