Changeset b7d9606 in mainline for uspace/lib/usb/src/hidparser.c
- Timestamp:
- 2011-03-04T13:35:14Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- fad14d7
- Parents:
- c7a2e7e
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/usb/src/hidparser.c
rc7a2e7e rb7d9606 36 36 #include <errno.h> 37 37 #include <stdio.h> 38 #include <adt/list.h>39 38 #include <malloc.h> 40 39 #include <mem.h> 41 42 #define USB_HID_NEW_REPORT_ITEM 0 43 44 45 int usb_hid_report_parse_tag(uint8_t tag, uint8_t class, const const uint8_t *data, size_t item_size, 40 #include <assert.h> 41 #include <usb/debug.h> 42 43 #define USB_HID_NEW_REPORT_ITEM 1 44 #define USB_HID_NO_ACTION 2 45 #define USB_HID_UNKNOWN_TAG -99 46 47 48 int usb_hid_report_parse_tag(uint8_t tag, uint8_t class, const uint8_t *data, size_t item_size, 46 49 usb_hid_report_item_t *report_item); 47 50 int usb_hid_report_parse_main_tag(uint8_t tag, const uint8_t *data, size_t item_size, … … 56 59 void usb_hid_free_report_list(link_t *head); 57 60 int32_t usb_hid_report_tag_data_int32(const uint8_t *data, size_t size); 58 size_t usb_hid_count_item_offset(usb_hid_report_item_t * report_item, size_t offset);61 inline size_t usb_hid_count_item_offset(usb_hid_report_item_t * report_item, size_t offset); 59 62 /** 60 63 * … … 81 84 */ 82 85 int usb_hid_parse_report_descriptor(usb_hid_report_parser_t *parser, 83 const constuint8_t *data, size_t size)86 const uint8_t *data, size_t size) 84 87 { 85 88 size_t i=0; … … 99 102 link_initialize(&(report_item->link)); 100 103 101 while(i<size){ 102 104 while(i<size){ 103 105 if(!USB_HID_ITEM_IS_LONG(data[i])){ 106 107 if((i+1) >= size){ 108 return -1; // TODO ERROR CODE 109 } 110 104 111 tag = USB_HID_ITEM_TAG(data[i]); 105 112 item_size = USB_HID_ITEM_SIZE(data[i]); 106 113 class = USB_HID_ITEM_TAG_CLASS(data[i]); 107 108 ret = usb_hid_report_parse_tag(tag,class,(data + (i+1)), 114 115 usb_log_debug2( 116 "i(%u) data(%X) value(%X): TAG %u, class %u, size %u - ", i, 117 data[i], usb_hid_report_tag_data_int32(data+i+1,item_size), 118 tag, class, item_size); 119 120 ret = usb_hid_report_parse_tag(tag,class,data+i+1, 109 121 item_size,report_item); 122 printf("ret: %u\n", ret); 110 123 switch(ret){ 111 124 case USB_HID_NEW_REPORT_ITEM: 112 125 // store report item to report and create the new one 113 printf("\nNEW REPORT ITEM: %X",tag); 114 126 usb_log_debug("\nNEW REPORT ITEM: %X",tag); 127 128 report_item->offset = offset; 115 129 offset = usb_hid_count_item_offset(report_item, offset); 116 report_item->offset = offset;117 130 switch(tag) { 118 131 case USB_HID_REPORT_TAG_INPUT: 119 printf(" - INPUT\n");132 usb_log_debug(" - INPUT\n"); 120 133 list_append(&(report_item->link), &(parser->input)); 121 134 break; 122 135 case USB_HID_REPORT_TAG_OUTPUT: 123 printf(" - OUTPUT\n");136 usb_log_debug(" - OUTPUT\n"); 124 137 list_append(&(report_item->link), &(parser->output)); 125 138 126 139 break; 127 140 case USB_HID_REPORT_TAG_FEATURE: 128 printf(" - FEATURE\n");141 usb_log_debug(" - FEATURE\n"); 129 142 list_append(&(report_item->link), &(parser->feature)); 130 143 break; 131 144 default: 132 printf("\tjump over tag: %X\n", tag q);145 usb_log_debug("\tjump over - tag %X\n", tag); 133 146 break; 134 147 } … … 153 166 154 167 default: 155 // nothing special to do 168 // nothing special to do 156 169 break; 157 170 } … … 183 196 */ 184 197 int usb_hid_parse_report(const usb_hid_report_parser_t *parser, 185 const constuint8_t *data, size_t size,198 const uint8_t *data, size_t size, 186 199 const usb_hid_report_in_callbacks_t *callbacks, void *arg) 187 200 { … … 215 228 * @return Error code 216 229 */ 217 int usb_hid_boot_keyboard_input_report(const constuint8_t *data, size_t size,230 int usb_hid_boot_keyboard_input_report(const uint8_t *data, size_t size, 218 231 const usb_hid_report_in_callbacks_t *callbacks, void *arg) 219 232 { … … 273 286 * @return Code of action to be done next 274 287 */ 275 int usb_hid_report_parse_tag(uint8_t tag, uint8_t class, const constuint8_t *data, size_t item_size,288 int usb_hid_report_parse_tag(uint8_t tag, uint8_t class, const uint8_t *data, size_t item_size, 276 289 usb_hid_report_item_t *report_item) 277 290 { 291 int ret; 292 278 293 switch(class){ 279 294 case USB_HID_TAG_CLASS_MAIN: 280 295 281 if( usb_hid_report_parse_main_tag(tag,data,item_size,report_item) == EOK) {296 if((ret=usb_hid_report_parse_main_tag(tag,data,item_size,report_item)) == EOK) { 282 297 return USB_HID_NEW_REPORT_ITEM; 283 298 } 284 299 else { 285 300 /*TODO process the error */ 286 return -1;301 return ret; 287 302 } 288 303 break; … … 296 311 break; 297 312 default: 298 return -1; /* TODO ERROR CODE - UNKNOWN TAG CODE */313 return USB_HID_NO_ACTION; 299 314 } 300 315 } … … 318 333 case USB_HID_REPORT_TAG_OUTPUT: 319 334 case USB_HID_REPORT_TAG_FEATURE: 320 report_item->item_flags = *data; 321 return USB_HID_NEW_REPORT_ITEM;335 report_item->item_flags = *data; 336 return EOK; 322 337 break; 323 338 … … 330 345 break; 331 346 default: 332 return -1; //TODO ERROR CODE333 } 334 335 return EOK;347 return USB_HID_NO_ACTION; 348 } 349 350 return USB_HID_NO_ACTION; 336 351 } 337 352 … … 388 403 389 404 default: 390 return -1; //TODO ERROR CODE INVALID GLOBAL TAG405 return USB_HID_NO_ACTION; 391 406 } 392 407 … … 441 456 */ 442 457 default: 443 return -1; //TODO ERROR CODE INVALID LOCAL TAG NOW IS ONLY UNSUPPORTED458 return USB_HID_NO_ACTION; 444 459 } 445 460 … … 484 499 return; 485 500 } 486 487 488 printf("\tHEAD %p\n",head); 501 489 502 for(item = head->next; item != head; item = item->next) { 490 503
Note:
See TracChangeset
for help on using the changeset viewer.