source: mainline/uspace/lib/usb/src/hiddescriptor.c@ 22ded10

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

Usage path fix in HID parser

  • Property mode set to 100644
File size: 22.4 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 switch(tag)
441 {
442 case USB_HID_REPORT_TAG_INPUT:
443 case USB_HID_REPORT_TAG_OUTPUT:
444 case USB_HID_REPORT_TAG_FEATURE:
445 report_item->item_flags = *data;
446 return EOK;
447 break;
448
449 case USB_HID_REPORT_TAG_COLLECTION:
450 //TODO: usage_path->flags = *data;
451
452 usb_log_debug("APPENDED ITEM TO USAGE PATH (PAGE %d, USAGE %d\n", report_item->usage_page, report_item->usages[report_item->usages_count-1]);
453 usb_hid_print_usage_path(usage_path);
454
455 // set last item
456 usb_hid_report_set_last_item(usage_path, USB_HID_TAG_CLASS_GLOBAL, report_item->usage_page);
457 usb_hid_report_set_last_item(usage_path, USB_HID_TAG_CLASS_LOCAL, report_item->usages[report_item->usages_count-1]);
458 // append the new one which will be set by common
459 // usage/usage page
460 usb_hid_report_path_append_item(usage_path, report_item->usage_page, report_item->usages[report_item->usages_count-1]);
461 usb_hid_print_usage_path(usage_path);
462
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(tag)
554 {
555 case USB_HID_REPORT_TAG_USAGE:
556 report_item->usages[report_item->usages_count] = usb_hid_report_tag_data_uint32(data,item_size);
557 report_item->usages_count++;
558 break;
559 case USB_HID_REPORT_TAG_USAGE_MINIMUM:
560 if (item_size == 3) {
561 // usage extended usages
562 report_item->extended_usage_page = (usb_hid_report_tag_data_uint32(data,item_size) & 0xFF00) >> 16;
563 report_item->usage_minimum = usb_hid_report_tag_data_uint32(data,item_size) & 0xFF;
564 }
565 else {
566 report_item->usage_minimum = usb_hid_report_tag_data_uint32(data,item_size);
567 }
568 break;
569 case USB_HID_REPORT_TAG_USAGE_MAXIMUM:
570 if (item_size == 3) {
571 // usage extended usages
572 report_item->extended_usage_page = (usb_hid_report_tag_data_uint32(data,item_size) & 0xFF00) >> 16;
573 report_item->usage_maximum = usb_hid_report_tag_data_uint32(data,item_size) & 0xFF;
574 }
575 else {
576 report_item->usage_maximum = usb_hid_report_tag_data_uint32(data,item_size);
577 }
578 break;
579 case USB_HID_REPORT_TAG_DESIGNATOR_INDEX:
580 report_item->designator_index = usb_hid_report_tag_data_uint32(data,item_size);
581 break;
582 case USB_HID_REPORT_TAG_DESIGNATOR_MINIMUM:
583 report_item->designator_minimum = usb_hid_report_tag_data_uint32(data,item_size);
584 break;
585 case USB_HID_REPORT_TAG_DESIGNATOR_MAXIMUM:
586 report_item->designator_maximum = usb_hid_report_tag_data_uint32(data,item_size);
587 break;
588 case USB_HID_REPORT_TAG_STRING_INDEX:
589 report_item->string_index = usb_hid_report_tag_data_uint32(data,item_size);
590 break;
591 case USB_HID_REPORT_TAG_STRING_MINIMUM:
592 report_item->string_minimum = usb_hid_report_tag_data_uint32(data,item_size);
593 break;
594 case USB_HID_REPORT_TAG_STRING_MAXIMUM:
595 report_item->string_maximum = usb_hid_report_tag_data_uint32(data,item_size);
596 break;
597 case USB_HID_REPORT_TAG_DELIMITER:
598 if (report_item->in_delimiter == OUTSIDE_DELIMITER_SET) {
599 report_item->in_delimiter = START_DELIMITER_SET;
600 }
601 else {
602 report_item->in_delimiter = OUTSIDE_DELIMITER_SET;
603 }
604
605 break;
606
607 default:
608 return USB_HID_NO_ACTION;
609 }
610
611 return EOK;
612}
613
614/**
615 * Converts raw data to uint32 (thats the maximum length of short item data)
616 *
617 * @param Data buffer
618 * @param Size of buffer
619 * @return Converted int32 number
620 */
621uint32_t usb_hid_report_tag_data_uint32(const uint8_t *data, size_t size)
622{
623 unsigned int i;
624 uint32_t result;
625
626 result = 0;
627 for(i=0; i<size; i++) {
628 result = (result | (data[i]) << (i*8));
629 }
630
631 return result;
632}
633
634/**
635 * Prints content of given list of report items.
636 *
637 * @param List of report items (usb_hid_report_item_t)
638 * @return void
639 */
640void usb_hid_descriptor_print_list(link_t *head)
641{
642 usb_hid_report_field_t *report_item;
643 link_t *item;
644
645
646 if(head == NULL || list_empty(head)) {
647 usb_log_debug("\tempty\n");
648 return;
649 }
650
651 for(item = head->next; item != head; item = item->next) {
652
653 report_item = list_get_instance(item, usb_hid_report_field_t, link);
654
655 usb_log_debug("\t\tOFFSET: %X\n", report_item->offset);
656 usb_log_debug("\t\tSIZE: %X\n", report_item->size);
657 usb_log_debug("\t\tLOGMIN: %d\n", report_item->logical_minimum);
658 usb_log_debug("\t\tLOGMAX: %d\n", report_item->logical_maximum);
659 usb_log_debug("\t\tPHYMIN: %d\n", report_item->physical_minimum);
660 usb_log_debug("\t\tPHYMAX: %d\n", report_item->physical_maximum);
661 usb_log_debug("\t\ttUSAGEMIN: %X\n", report_item->usage_minimum);
662 usb_log_debug("\t\tUSAGEMAX: %X\n", report_item->usage_maximum);
663
664 usb_log_debug("\t\tVALUE: %X\n", report_item->value);
665 usb_log_debug("\t\ttUSAGE: %X\n", report_item->usage);
666 usb_log_debug("\t\tUSAGE PAGE: %X\n", report_item->usage_page);
667
668 //usb_hid_print_usage_path(report_item->collection_path);
669
670 usb_log_debug("\n");
671
672 }
673
674
675}
676/**
677 * Prints content of given report descriptor in human readable format.
678 *
679 * @param parser Parsed descriptor to print
680 * @return void
681 */
682void usb_hid_descriptor_print(usb_hid_report_t *report)
683{
684 if(report == NULL) {
685 return;
686 }
687
688 link_t *report_it = report->reports.next;
689 usb_hid_report_description_t *report_des;
690
691 while(report_it != &report->reports) {
692 report_des = list_get_instance(report_it, usb_hid_report_description_t, link);
693 usb_log_debug("Report ID: %d\n", report_des->report_id);
694 usb_log_debug("\tType: %d\n", report_des->type);
695 usb_log_debug("\tLength: %d\n", report_des->bit_length);
696 usb_log_debug("\tItems: %d\n", report_des->item_length);
697
698 usb_hid_descriptor_print_list(&report_des->report_items);
699
700
701 link_t *path_it = report->collection_paths.next;
702 while(path_it != &report->collection_paths) {
703 usb_hid_print_usage_path (list_get_instance(path_it, usb_hid_report_path_t, link));
704 path_it = path_it->next;
705 }
706
707 report_it = report_it->next;
708 }
709}
710
711/**
712 * Releases whole linked list of report items
713 *
714 * @param head Head of list of report descriptor items (usb_hid_report_item_t)
715 * @return void
716 */
717void usb_hid_free_report_list(link_t *head)
718{
719 return;
720
721 usb_hid_report_item_t *report_item;
722 link_t *next;
723
724 if(head == NULL || list_empty(head)) {
725 return;
726 }
727
728 next = head->next;
729 while(next != head) {
730
731 report_item = list_get_instance(next, usb_hid_report_item_t, link);
732
733 while(!list_empty(&report_item->usage_path->link)) {
734 usb_hid_report_remove_last_item(report_item->usage_path);
735 }
736
737
738 next = next->next;
739
740 free(report_item);
741 }
742
743 return;
744
745}
746
747/** Frees the HID report descriptor parser structure
748 *
749 * @param parser Opaque HID report parser structure
750 * @return void
751 */
752void usb_hid_free_report(usb_hid_report_t *report)
753{
754 if(report == NULL){
755 return;
756 }
757
758 // free collection paths
759 usb_hid_report_path_t *path;
760 while(!list_empty(&report->collection_paths)) {
761 path = list_get_instance(report->collection_paths.next, usb_hid_report_path_t, link);
762 usb_hid_report_path_free(path);
763 }
764
765 // free report items
766 usb_hid_report_description_t *report_des;
767 usb_hid_report_field_t *field;
768 while(!list_empty(&report->reports)) {
769 report_des = list_get_instance(report->reports.next, usb_hid_report_description_t, link);
770 list_remove(&report_des->link);
771
772 while(!list_empty(&report_des->report_items)) {
773 field = list_get_instance(report_des->report_items.next, usb_hid_report_field_t, link);
774 list_remove(&field->link);
775
776 free(field);
777 }
778
779 free(report_des);
780 }
781
782 return;
783}
784
785/**
786 * @}
787 */
Note: See TracBrowser for help on using the repository browser.