source: mainline/uspace/lib/usb/src/hiddescriptor.c@ 674cf89

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 674cf89 was 674cf89, checked in by Matej Klonfar <maklf@…>, 14 years ago

HID Parser - basic support for delimiters

  • Property mode set to 100644
File size: 22.5 KB
Line 
1/*
2 * Copyright (c) 2011 Matej Klonfar
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/** @addtogroup libusb
30 * @{
31 */
32/** @file
33 * HID report descriptor and report data parser implementation.
34 */
35#include <usb/classes/hidparser.h>
36#include <errno.h>
37#include <stdio.h>
38#include <malloc.h>
39#include <mem.h>
40#include <usb/debug.h>
41#include <assert.h>
42
43
44#define OUTSIDE_DELIMITER_SET 0
45#define START_DELIMITER_SET 1
46#define INSIDE_DELIMITER_SET 2
47
48/** The new report item flag. Used to determine when the item is completly
49 * configured and should be added to the report structure
50 */
51#define USB_HID_NEW_REPORT_ITEM 1
52
53/** No special action after the report descriptor tag is processed should be
54 * done
55 */
56#define USB_HID_NO_ACTION 2
57
58#define USB_HID_RESET_OFFSET 3
59
60/** Unknown tag was founded in report descriptor data*/
61#define USB_HID_UNKNOWN_TAG -99
62
63usb_hid_report_path_t *usb_hid_report_path_try_insert(usb_hid_report_t *report, usb_hid_report_path_t *cmp_path)
64{
65 /* find or append current collection path to the list */
66 link_t *path_it = report->collection_paths.next;
67 usb_hid_report_path_t *path = NULL;
68 while(path_it != &report->collection_paths) {
69 path = list_get_instance(path_it, usb_hid_report_path_t, link);
70
71 if(usb_hid_report_compare_usage_path(path, cmp_path, USB_HID_PATH_COMPARE_STRICT) == EOK){
72 break;
73 }
74 path_it = path_it->next;
75 }
76 if(path_it == &report->collection_paths) {
77 path = usb_hid_report_path_clone(cmp_path);
78 list_append(&path->link, &report->collection_paths);
79 report->collection_paths_count++;
80
81 return path;
82 }
83 else {
84 return list_get_instance(path_it, usb_hid_report_path_t, link);
85 }
86}
87
88/**
89 * Initialize the report descriptor parser structure
90 *
91 * @param parser Report descriptor parser structure
92 * @return Error code
93 */
94int usb_hid_report_init(usb_hid_report_t *report)
95{
96 if(report == NULL) {
97 return EINVAL;
98 }
99
100 memset(report, 0, sizeof(usb_hid_report_t));
101 list_initialize(&report->reports);
102 list_initialize(&report->collection_paths);
103
104 report->use_report_ids = 0;
105 return EOK;
106}
107
108
109/*
110 *
111 *
112 */
113int usb_hid_report_append_fields(usb_hid_report_t *report, usb_hid_report_item_t *report_item)
114{
115 usb_hid_report_field_t *field;
116 int i;
117
118 for(i=0; i<report_item->usages_count; i++){
119 usb_log_debug("usages (%d) - %x\n", i, report_item->usages[i]);
120 }
121
122 usb_hid_report_path_t *path = report_item->usage_path;
123 for(i=0; i<report_item->count; i++){
124
125 field = malloc(sizeof(usb_hid_report_field_t));
126 memset(field, 0, sizeof(usb_hid_report_field_t));
127 list_initialize(&field->link);
128
129 /* fill the attributes */
130 field->logical_minimum = report_item->logical_minimum;
131 field->logical_maximum = report_item->logical_maximum;
132 field->physical_minimum = report_item->physical_minimum;
133 field->physical_maximum = report_item->physical_maximum;
134
135 field->usage_minimum = report_item->usage_minimum;
136 field->usage_maximum = report_item->usage_maximum;
137 if(report_item->extended_usage_page != 0){
138 field->usage_page = report_item->extended_usage_page;
139 }
140 else {
141 field->usage_page = report_item->usage_page;
142 }
143
144 if(report_item->usages_count > 0 && ((report_item->usage_minimum == 0) && (report_item->usage_maximum == 0))) {
145 uint32_t usage;
146 if(i < report_item->usages_count){
147 usage = report_item->usages[i];
148 }
149 else {
150 usage = report_item->usages[report_item->usages_count - 1];
151 }
152
153
154 if((usage & 0xFFFF0000) != 0){
155 field->usage_page = (usage >> 16);
156 field->usage = (usage & 0xFFFF);
157 }
158 else {
159 field->usage = usage;
160 }
161
162
163 }
164
165 if((USB_HID_ITEM_FLAG_VARIABLE(report_item->item_flags) != 0) && (!((report_item->usage_minimum == 0) && (report_item->usage_maximum == 0)))) {
166 field->usage = report_item->usage_minimum + i;
167 }
168
169 usb_hid_report_set_last_item(path, USB_HID_TAG_CLASS_GLOBAL, field->usage_page);
170 usb_hid_report_set_last_item(path, USB_HID_TAG_CLASS_LOCAL, field->usage);
171
172 field->collection_path = usb_hid_report_path_try_insert(report, path);
173
174 field->size = report_item->size;
175
176 size_t offset_byte = (report_item->offset + (i * report_item->size)) / 8;
177 size_t offset_bit = 8 - ((report_item->offset + (i * report_item->size)) % 8) - report_item->size;
178
179 field->offset = 8 * offset_byte + offset_bit;
180 if(report_item->id != 0) {
181 field->offset += 8;
182 report->use_report_ids = 1;
183 }
184 field->item_flags = report_item->item_flags;
185
186 /* find the right report list*/
187 usb_hid_report_description_t *report_des;
188 report_des = usb_hid_report_find_description(report, report_item->id, report_item->type);
189 if(report_des == NULL){
190 report_des = malloc(sizeof(usb_hid_report_description_t));
191 memset(report_des, 0, sizeof(usb_hid_report_description_t));
192
193 report_des->type = report_item->type;
194 report_des->report_id = report_item->id;
195 list_initialize (&report_des->link);
196 list_initialize (&report_des->report_items);
197
198 list_append(&report_des->link, &report->reports);
199 report->report_count++;
200 }
201
202 /* append this field to the end of founded report list */
203 list_append (&field->link, &report_des->report_items);
204
205 /* update the sizes */
206 report_des->bit_length += field->size;
207 report_des->item_length++;
208
209 }
210
211
212 return EOK;
213}
214
215usb_hid_report_description_t * usb_hid_report_find_description(const usb_hid_report_t *report, uint8_t report_id, usb_hid_report_type_t type)
216{
217 link_t *report_it = report->reports.next;
218 usb_hid_report_description_t *report_des = NULL;
219
220 while(report_it != &report->reports) {
221 report_des = list_get_instance(report_it, usb_hid_report_description_t, link);
222
223 if((report_des->report_id == report_id) && (report_des->type == type)){
224 return report_des;
225 }
226
227 report_it = report_it->next;
228 }
229
230 return NULL;
231}
232
233/** Parse HID report descriptor.
234 *
235 * @param parser Opaque HID report parser structure.
236 * @param data Data describing the report.
237 * @return Error code.
238 */
239int usb_hid_parse_report_descriptor(usb_hid_report_t *report,
240 const uint8_t *data, size_t size)
241{
242 size_t i=0;
243 uint8_t tag=0;
244 uint8_t item_size=0;
245 int class=0;
246 int ret;
247 usb_hid_report_item_t *report_item=0;
248 usb_hid_report_item_t *new_report_item;
249 usb_hid_report_path_t *usage_path;
250
251 size_t offset_input=0;
252 size_t offset_output=0;
253 size_t offset_feature=0;
254
255 link_t stack;
256 list_initialize(&stack);
257
258 /* parser structure initialization*/
259 if(usb_hid_report_init(report) != EOK) {
260 return EINVAL;
261 }
262
263 /*report item initialization*/
264 if(!(report_item=malloc(sizeof(usb_hid_report_item_t)))){
265 return ENOMEM;
266 }
267 memset(report_item, 0, sizeof(usb_hid_report_item_t));
268 list_initialize(&(report_item->link));
269
270 /* usage path context initialization */
271 if(!(usage_path=usb_hid_report_path())){
272 return ENOMEM;
273 }
274 usb_hid_report_path_append_item(usage_path, 0, 0);
275
276 while(i<size){
277 if(!USB_HID_ITEM_IS_LONG(data[i])){
278
279 if((i+USB_HID_ITEM_SIZE(data[i]))>= size){
280 return EINVAL;
281 }
282
283 tag = USB_HID_ITEM_TAG(data[i]);
284 item_size = USB_HID_ITEM_SIZE(data[i]);
285 class = USB_HID_ITEM_TAG_CLASS(data[i]);
286
287 ret = usb_hid_report_parse_tag(tag,class,data+i+1,
288 item_size,report_item, usage_path);
289 switch(ret){
290 case USB_HID_NEW_REPORT_ITEM:
291 // store report item to report and create the new one
292 // store current collection path
293 report_item->usage_path = usage_path;
294
295 usb_hid_report_path_set_report_id(report_item->usage_path, report_item->id);
296 if(report_item->id != 0){
297 report->use_report_ids = 1;
298 }
299
300 switch(tag) {
301 case USB_HID_REPORT_TAG_INPUT:
302 report_item->type = USB_HID_REPORT_TYPE_INPUT;
303 report_item->offset = offset_input;
304 offset_input += report_item->count * report_item->size;
305 break;
306 case USB_HID_REPORT_TAG_OUTPUT:
307 report_item->type = USB_HID_REPORT_TYPE_OUTPUT;
308 report_item->offset = offset_output;
309 offset_output += report_item->count * report_item->size;
310
311 break;
312 case USB_HID_REPORT_TAG_FEATURE:
313 report_item->type = USB_HID_REPORT_TYPE_FEATURE;
314 report_item->offset = offset_feature;
315 offset_feature += report_item->count * report_item->size;
316 break;
317 default:
318 usb_log_debug("\tjump over - tag %X\n", tag);
319 break;
320 }
321
322 /*
323 * append new fields to the report
324 * structure
325 */
326 usb_hid_report_append_fields(report, report_item);
327
328 /* reset local items */
329 usb_hid_report_reset_local_items (report_item);
330
331 break;
332
333 case USB_HID_RESET_OFFSET:
334 offset_input = 0;
335 offset_output = 0;
336 offset_feature = 0;
337 usb_hid_report_path_set_report_id (usage_path, report_item->id);
338 break;
339
340 case USB_HID_REPORT_TAG_PUSH:
341 // push current state to stack
342 new_report_item = usb_hid_report_item_clone(report_item);
343 usb_hid_report_path_t *tmp_path = usb_hid_report_path_clone(usage_path);
344 new_report_item->usage_path = tmp_path;
345
346 list_prepend (&new_report_item->link, &stack);
347 break;
348 case USB_HID_REPORT_TAG_POP:
349 // restore current state from stack
350 if(list_empty (&stack)) {
351 return EINVAL;
352 }
353 free(report_item);
354
355 report_item = list_get_instance(stack.next, usb_hid_report_item_t, link);
356
357 usb_hid_report_usage_path_t *tmp_usage_path;
358 tmp_usage_path = list_get_instance(report_item->usage_path->link.prev, usb_hid_report_usage_path_t, link);
359
360 usb_hid_report_set_last_item(usage_path, USB_HID_TAG_CLASS_GLOBAL, tmp_usage_path->usage_page);
361 usb_hid_report_set_last_item(usage_path, USB_HID_TAG_CLASS_LOCAL, tmp_usage_path->usage);
362
363 usb_hid_report_path_free(report_item->usage_path);
364 list_initialize(&report_item->usage_path->link);
365 list_remove (stack.next);
366
367 break;
368
369 default:
370 // nothing special to do
371 break;
372 }
373
374 /* jump over the processed block */
375 i += 1 + USB_HID_ITEM_SIZE(data[i]);
376 }
377 else{
378 // TBD
379 i += 3 + USB_HID_ITEM_SIZE(data[i+1]);
380 }
381
382
383 }
384
385 return EOK;
386}
387
388
389/**
390 * Parse one tag of the report descriptor
391 *
392 * @param Tag to parse
393 * @param Report descriptor buffer
394 * @param Size of data belongs to this tag
395 * @param Current report item structe
396 * @return Code of action to be done next
397 */
398int usb_hid_report_parse_tag(uint8_t tag, uint8_t class, const uint8_t *data, size_t item_size,
399 usb_hid_report_item_t *report_item, usb_hid_report_path_t *usage_path)
400{
401 int ret;
402
403 switch(class){
404 case USB_HID_TAG_CLASS_MAIN:
405
406 if((ret=usb_hid_report_parse_main_tag(tag,data,item_size,report_item, usage_path)) == EOK) {
407 return USB_HID_NEW_REPORT_ITEM;
408 }
409 else {
410 /*TODO process the error */
411 return ret;
412 }
413 break;
414
415 case USB_HID_TAG_CLASS_GLOBAL:
416 return usb_hid_report_parse_global_tag(tag,data,item_size,report_item, usage_path);
417 break;
418
419 case USB_HID_TAG_CLASS_LOCAL:
420 return usb_hid_report_parse_local_tag(tag,data,item_size,report_item, usage_path);
421 break;
422 default:
423 return USB_HID_NO_ACTION;
424 }
425}
426
427/**
428 * Parse main tags of report descriptor
429 *
430 * @param Tag identifier
431 * @param Data buffer
432 * @param Length of data buffer
433 * @param Current state table
434 * @return Error code
435 */
436
437int usb_hid_report_parse_main_tag(uint8_t tag, const uint8_t *data, size_t item_size,
438 usb_hid_report_item_t *report_item, usb_hid_report_path_t *usage_path)
439{
440 usb_hid_report_usage_path_t *path_item;
441
442 switch(tag)
443 {
444 case USB_HID_REPORT_TAG_INPUT:
445 case USB_HID_REPORT_TAG_OUTPUT:
446 case USB_HID_REPORT_TAG_FEATURE:
447 report_item->item_flags = *data;
448 return EOK;
449 break;
450
451 case USB_HID_REPORT_TAG_COLLECTION:
452 // store collection atributes
453 path_item = list_get_instance(usage_path->head.prev, usb_hid_report_usage_path_t, link);
454 path_item->flags = *data;
455
456 // set last item
457 usb_hid_report_set_last_item(usage_path, USB_HID_TAG_CLASS_GLOBAL, report_item->usage_page);
458 usb_hid_report_set_last_item(usage_path, USB_HID_TAG_CLASS_LOCAL, report_item->usages[report_item->usages_count-1]);
459
460 // append the new one which will be set by common
461 // usage/usage page
462 usb_hid_report_path_append_item(usage_path, report_item->usage_page, report_item->usages[report_item->usages_count-1]);
463 usb_hid_report_reset_local_items (report_item);
464 return USB_HID_NO_ACTION;
465 break;
466
467 case USB_HID_REPORT_TAG_END_COLLECTION:
468 usb_hid_report_remove_last_item(usage_path);
469 return USB_HID_NO_ACTION;
470 break;
471 default:
472 return USB_HID_NO_ACTION;
473 }
474
475 return EOK;
476}
477
478/**
479 * Parse global tags of report descriptor
480 *
481 * @param Tag identifier
482 * @param Data buffer
483 * @param Length of data buffer
484 * @param Current state table
485 * @return Error code
486 */
487int usb_hid_report_parse_global_tag(uint8_t tag, const uint8_t *data, size_t item_size,
488 usb_hid_report_item_t *report_item, usb_hid_report_path_t *usage_path)
489{
490 // TODO take care about the bit length of data
491 switch(tag)
492 {
493 case USB_HID_REPORT_TAG_USAGE_PAGE:
494 report_item->usage_page = usb_hid_report_tag_data_uint32(data, item_size);
495 break;
496 case USB_HID_REPORT_TAG_LOGICAL_MINIMUM:
497 report_item->logical_minimum = USB_HID_UINT32_TO_INT32(usb_hid_report_tag_data_uint32(data,item_size), item_size * 8);
498 break;
499 case USB_HID_REPORT_TAG_LOGICAL_MAXIMUM:
500 report_item->logical_maximum = USB_HID_UINT32_TO_INT32(usb_hid_report_tag_data_uint32(data,item_size), item_size * 8);
501 break;
502 case USB_HID_REPORT_TAG_PHYSICAL_MINIMUM:
503 report_item->physical_minimum = USB_HID_UINT32_TO_INT32(usb_hid_report_tag_data_uint32(data,item_size), item_size * 8);
504 break;
505 case USB_HID_REPORT_TAG_PHYSICAL_MAXIMUM:
506 report_item->physical_maximum = USB_HID_UINT32_TO_INT32(usb_hid_report_tag_data_uint32(data,item_size), item_size * 8);
507
508 break;
509 case USB_HID_REPORT_TAG_UNIT_EXPONENT:
510 report_item->unit_exponent = usb_hid_report_tag_data_uint32(data,item_size);
511 break;
512 case USB_HID_REPORT_TAG_UNIT:
513 report_item->unit = usb_hid_report_tag_data_uint32(data,item_size);
514 break;
515 case USB_HID_REPORT_TAG_REPORT_SIZE:
516 report_item->size = usb_hid_report_tag_data_uint32(data,item_size);
517 break;
518 case USB_HID_REPORT_TAG_REPORT_COUNT:
519 report_item->count = usb_hid_report_tag_data_uint32(data,item_size);
520 break;
521 case USB_HID_REPORT_TAG_REPORT_ID:
522 report_item->id = usb_hid_report_tag_data_uint32(data,item_size);
523 return USB_HID_RESET_OFFSET;
524 break;
525 case USB_HID_REPORT_TAG_PUSH:
526 case USB_HID_REPORT_TAG_POP:
527 /*
528 * stack operations are done in top level parsing
529 * function
530 */
531 return tag;
532 break;
533
534 default:
535 return USB_HID_NO_ACTION;
536 }
537
538 return EOK;
539}
540
541/**
542 * Parse local tags of report descriptor
543 *
544 * @param Tag identifier
545 * @param Data buffer
546 * @param Length of data buffer
547 * @param Current state table
548 * @return Error code
549 */
550int usb_hid_report_parse_local_tag(uint8_t tag, const uint8_t *data, size_t item_size,
551 usb_hid_report_item_t *report_item, usb_hid_report_path_t *usage_path)
552{
553 switch(report_item->in_delimiter) {
554 case INSIDE_DELIMITER_SET:
555 // nothing to do
556 break;
557 case START_DELIMITER_SET:
558 report_item->in_delimiter = INSIDE_DELIMITER_SET;
559 case OUTSIDE_DELIMITER_SET:
560
561 switch(tag) {
562 case USB_HID_REPORT_TAG_USAGE:
563 report_item->usages[report_item->usages_count] = usb_hid_report_tag_data_uint32(data,item_size);
564 report_item->usages_count++;
565 break;
566 case USB_HID_REPORT_TAG_USAGE_MINIMUM:
567 if (item_size == 3) {
568 // usage extended usages
569 report_item->extended_usage_page = (usb_hid_report_tag_data_uint32(data,item_size) & 0xFF00) >> 16;
570 report_item->usage_minimum = usb_hid_report_tag_data_uint32(data,item_size) & 0xFF;
571 }
572 else {
573 report_item->usage_minimum = usb_hid_report_tag_data_uint32(data,item_size);
574 }
575 break;
576 case USB_HID_REPORT_TAG_USAGE_MAXIMUM:
577 if (item_size == 3) {
578 // usage extended usages
579 report_item->extended_usage_page = (usb_hid_report_tag_data_uint32(data,item_size) & 0xFF00) >> 16;
580 report_item->usage_maximum = usb_hid_report_tag_data_uint32(data,item_size) & 0xFF;
581 }
582 else {
583 report_item->usage_maximum = usb_hid_report_tag_data_uint32(data,item_size);
584 }
585 break;
586 case USB_HID_REPORT_TAG_DESIGNATOR_INDEX:
587 report_item->designator_index = usb_hid_report_tag_data_uint32(data,item_size);
588 break;
589 case USB_HID_REPORT_TAG_DESIGNATOR_MINIMUM:
590 report_item->designator_minimum = usb_hid_report_tag_data_uint32(data,item_size);
591 break;
592 case USB_HID_REPORT_TAG_DESIGNATOR_MAXIMUM:
593 report_item->designator_maximum = usb_hid_report_tag_data_uint32(data,item_size);
594 break;
595 case USB_HID_REPORT_TAG_STRING_INDEX:
596 report_item->string_index = usb_hid_report_tag_data_uint32(data,item_size);
597 break;
598 case USB_HID_REPORT_TAG_STRING_MINIMUM:
599 report_item->string_minimum = usb_hid_report_tag_data_uint32(data,item_size);
600 break;
601 case USB_HID_REPORT_TAG_STRING_MAXIMUM:
602 report_item->string_maximum = usb_hid_report_tag_data_uint32(data,item_size);
603 break;
604 case USB_HID_REPORT_TAG_DELIMITER:
605 report_item->in_delimiter = usb_hid_report_tag_data_uint32(data,item_size);
606 break;
607
608 default:
609 return USB_HID_NO_ACTION;
610 }
611
612 break;
613 }
614
615 return EOK;
616}
617
618/**
619 * Converts raw data to uint32 (thats the maximum length of short item data)
620 *
621 * @param Data buffer
622 * @param Size of buffer
623 * @return Converted int32 number
624 */
625uint32_t usb_hid_report_tag_data_uint32(const uint8_t *data, size_t size)
626{
627 unsigned int i;
628 uint32_t result;
629
630 result = 0;
631 for(i=0; i<size; i++) {
632 result = (result | (data[i]) << (i*8));
633 }
634
635 return result;
636}
637
638/**
639 * Prints content of given list of report items.
640 *
641 * @param List of report items (usb_hid_report_item_t)
642 * @return void
643 */
644void usb_hid_descriptor_print_list(link_t *head)
645{
646 usb_hid_report_field_t *report_item;
647 link_t *item;
648
649
650 if(head == NULL || list_empty(head)) {
651 usb_log_debug("\tempty\n");
652 return;
653 }
654
655 for(item = head->next; item != head; item = item->next) {
656
657 report_item = list_get_instance(item, usb_hid_report_field_t, link);
658
659 usb_log_debug("\t\tOFFSET: %X\n", report_item->offset);
660 usb_log_debug("\t\tSIZE: %X\n", report_item->size);
661 usb_log_debug("\t\tLOGMIN: %d\n", report_item->logical_minimum);
662 usb_log_debug("\t\tLOGMAX: %d\n", report_item->logical_maximum);
663 usb_log_debug("\t\tPHYMIN: %d\n", report_item->physical_minimum);
664 usb_log_debug("\t\tPHYMAX: %d\n", report_item->physical_maximum);
665 usb_log_debug("\t\ttUSAGEMIN: %X\n", report_item->usage_minimum);
666 usb_log_debug("\t\tUSAGEMAX: %X\n", report_item->usage_maximum);
667
668 usb_log_debug("\t\tVALUE: %X\n", report_item->value);
669 usb_log_debug("\t\ttUSAGE: %X\n", report_item->usage);
670 usb_log_debug("\t\tUSAGE PAGE: %X\n", report_item->usage_page);
671
672 //usb_hid_print_usage_path(report_item->collection_path);
673
674 usb_log_debug("\n");
675
676 }
677
678
679}
680/**
681 * Prints content of given report descriptor in human readable format.
682 *
683 * @param parser Parsed descriptor to print
684 * @return void
685 */
686void usb_hid_descriptor_print(usb_hid_report_t *report)
687{
688 if(report == NULL) {
689 return;
690 }
691
692 link_t *report_it = report->reports.next;
693 usb_hid_report_description_t *report_des;
694
695 while(report_it != &report->reports) {
696 report_des = list_get_instance(report_it, usb_hid_report_description_t, link);
697 usb_log_debug("Report ID: %d\n", report_des->report_id);
698 usb_log_debug("\tType: %d\n", report_des->type);
699 usb_log_debug("\tLength: %d\n", report_des->bit_length);
700 usb_log_debug("\tItems: %d\n", report_des->item_length);
701
702 usb_hid_descriptor_print_list(&report_des->report_items);
703
704
705 link_t *path_it = report->collection_paths.next;
706 while(path_it != &report->collection_paths) {
707 usb_hid_print_usage_path (list_get_instance(path_it, usb_hid_report_path_t, link));
708 path_it = path_it->next;
709 }
710
711 report_it = report_it->next;
712 }
713}
714
715/**
716 * Releases whole linked list of report items
717 *
718 * @param head Head of list of report descriptor items (usb_hid_report_item_t)
719 * @return void
720 */
721void usb_hid_free_report_list(link_t *head)
722{
723 return;
724
725 usb_hid_report_item_t *report_item;
726 link_t *next;
727
728 if(head == NULL || list_empty(head)) {
729 return;
730 }
731
732 next = head->next;
733 while(next != head) {
734
735 report_item = list_get_instance(next, usb_hid_report_item_t, link);
736
737 while(!list_empty(&report_item->usage_path->link)) {
738 usb_hid_report_remove_last_item(report_item->usage_path);
739 }
740
741
742 next = next->next;
743
744 free(report_item);
745 }
746
747 return;
748
749}
750
751/** Frees the HID report descriptor parser structure
752 *
753 * @param parser Opaque HID report parser structure
754 * @return void
755 */
756void usb_hid_free_report(usb_hid_report_t *report)
757{
758 if(report == NULL){
759 return;
760 }
761
762 // free collection paths
763 usb_hid_report_path_t *path;
764 while(!list_empty(&report->collection_paths)) {
765 path = list_get_instance(report->collection_paths.next, usb_hid_report_path_t, link);
766 usb_hid_report_path_free(path);
767 }
768
769 // free report items
770 usb_hid_report_description_t *report_des;
771 usb_hid_report_field_t *field;
772 while(!list_empty(&report->reports)) {
773 report_des = list_get_instance(report->reports.next, usb_hid_report_description_t, link);
774 list_remove(&report_des->link);
775
776 while(!list_empty(&report_des->report_items)) {
777 field = list_get_instance(report_des->report_items.next, usb_hid_report_field_t, link);
778 list_remove(&field->link);
779
780 free(field);
781 }
782
783 free(report_des);
784 }
785
786 return;
787}
788
789/**
790 * @}
791 */
Note: See TracBrowser for help on using the repository browser.