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

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

Removed functions for returning size of report for usage path

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