Changeset 6986418 in mainline for uspace/drv/usbkbd/descparser.c
- Timestamp:
- 2011-01-14T12:20:54Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- b2a6fcfe
- Parents:
- 2b0db98
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/usbkbd/descparser.c
r2b0db98 r6986418 32 32 #include <usb/descriptor.h> 33 33 #include "descparser.h" 34 #include "descdump.h" 34 35 35 36 static void usbkbd_config_free(usb_hid_configuration_t *config) … … 94 95 sizeof(usb_standard_configuration_descriptor_t)); 95 96 pos += sizeof(usb_standard_configuration_descriptor_t); 97 98 printf("Parsed configuration descriptor: \n"); 99 dump_standard_configuration_descriptor(0, &config->config_descriptor); 96 100 97 101 int ret = EOK; … … 102 106 *(pos + 1)); 103 107 return EINVAL; 104 } 108 } 105 109 106 110 // prepare place for interface descriptors … … 112 116 // the respective structures 113 117 int ep_i = -1; 114 int hid_i = -1;118 //int hid_i = -1; 115 119 116 120 usb_hid_iface_t *actual_iface = NULL; … … 134 138 memcpy(&actual_iface->iface_desc, pos, desc_size); 135 139 pos += desc_size; 140 141 printf("Parsed interface descriptor: \n"); 142 dump_standard_interface_descriptor(&actual_iface->iface_desc); 136 143 137 144 // allocate space for endpoint descriptors … … 170 177 memcpy(&actual_iface->endpoints[ep_i], pos, desc_size); 171 178 pos += desc_size; 179 180 printf("Parsed endpoint descriptor: \n"); 181 dump_standard_endpoint_descriptor(&actual_iface->endpoints[ep_i]); 172 182 ++ep_i; 173 183 … … 194 204 goto end; 195 205 } 206 207 printf("Parsed HID descriptor header: \n"); 208 dump_standard_hid_descriptor_header(&actual_iface->hid_desc); 196 209 197 210 // allocate space for all class-specific descriptor info … … 206 219 207 220 // allocate space for all class-specific descriptors 208 actual_iface->class_descs = (uint8_t **)calloc(221 /*actual_iface->class_descs = (uint8_t **)calloc( 209 222 actual_iface->hid_desc.class_desc_count, 210 223 sizeof(uint8_t *)); … … 212 225 ret = ENOMEM; 213 226 goto end; 214 } 227 }*/ 215 228 216 229 // copy all class-specific descriptor info 217 230 // TODO: endianness 231 /* 218 232 memcpy(actual_iface->class_desc_info, pos, 219 233 actual_iface->hid_desc.class_desc_count … … 221 235 pos += actual_iface->hid_desc.class_desc_count 222 236 * sizeof(usb_standard_hid_class_descriptor_info_t); 223 224 size_t tmp = (size_t)(pos - data); 237 238 printf("Parsed HID descriptor info:\n"); 239 dump_standard_hid_class_descriptor_info( 240 actual_iface->class_desc_info); 241 */ 242 243 /*size_t tmp = (size_t)(pos - data); 225 244 printf("Parser position: %d, remaining: %d\n", 226 pos - data, size - tmp); 227 228 /* 229 * TODO: this is not good, only 7 bytes remaining, 230 * something is wrong! 231 */ 232 233 hid_i = 0; 245 pos - data, size - tmp);*/ 246 247 //hid_i = 0; 234 248 235 249 break; 236 case USB_DESCTYPE_HID_REPORT:250 /* case USB_DESCTYPE_HID_REPORT: 237 251 case USB_DESCTYPE_HID_PHYSICAL: { 238 252 // check if the type matches … … 262 276 memcpy(actual_iface->class_descs[hid_i], pos, length); 263 277 pos += length; 278 279 printf("Parsed class-specific descriptor:\n"); 280 dump_hid_class_descriptor(hid_i, desc_type, 281 actual_iface->class_descs[hid_i], length); 282 264 283 ++hid_i; 265 284 266 break; } 285 break; }*/ 267 286 default: 268 287 fprintf(stderr, "Got descriptor of unknown type: %u.\n", … … 280 299 281 300 return ret; 282 }283 284 /*----------------------------------------------------------------------------*/285 286 #define BYTES_PER_LINE 12287 288 static void dump_buffer(const char *msg, const uint8_t *buffer, size_t length)289 {290 printf("%s\n", msg);291 292 size_t i;293 for (i = 0; i < length; i++) {294 printf(" 0x%02X", buffer[i]);295 if (((i > 0) && (((i+1) % BYTES_PER_LINE) == 0))296 || (i + 1 == length)) {297 printf("\n");298 }299 }300 }301 302 /*----------------------------------------------------------------------------*/303 304 #define INDENT " "305 306 static void dump_standard_configuration_descriptor(307 int index, const usb_standard_configuration_descriptor_t *d)308 {309 bool self_powered = d->attributes & 64;310 bool remote_wakeup = d->attributes & 32;311 312 printf("Standard configuration descriptor #%d\n", index);313 printf(INDENT "bLength = %d\n", d->length);314 printf(INDENT "bDescriptorType = 0x%02x\n", d->descriptor_type);315 printf(INDENT "wTotalLength = %d\n", d->total_length);316 printf(INDENT "bNumInterfaces = %d\n", d->interface_count);317 printf(INDENT "bConfigurationValue = %d\n", d->configuration_number);318 printf(INDENT "iConfiguration = %d\n", d->str_configuration);319 printf(INDENT "bmAttributes = %d [%s%s%s]\n", d->attributes,320 self_powered ? "self-powered" : "",321 (self_powered & remote_wakeup) ? ", " : "",322 remote_wakeup ? "remote-wakeup" : "");323 printf(INDENT "MaxPower = %d (%dmA)\n", d->max_power,324 2 * d->max_power);325 // printf(INDENT " = %d\n", d->);326 }327 328 static void dump_standard_interface_descriptor(329 const usb_standard_interface_descriptor_t *d)330 {331 printf("Standard interface descriptor\n");332 printf(INDENT "bLength = %d\n", d->length);333 printf(INDENT "bDescriptorType = 0x%02x\n", d->descriptor_type);334 printf(INDENT "bInterfaceNumber = %d\n", d->interface_number);335 printf(INDENT "bAlternateSetting = %d\n", d->alternate_setting);336 printf(INDENT "bNumEndpoints = %d\n", d->endpoint_count);337 printf(INDENT "bInterfaceClass = %d\n", d->interface_class);338 printf(INDENT "bInterfaceSubClass = %d\n", d->interface_subclass);339 printf(INDENT "bInterfaceProtocol = %d\n", d->interface_protocol);340 printf(INDENT "iInterface = %d", d->str_interface);341 }342 343 static void dump_standard_endpoint_descriptor(344 const usb_standard_endpoint_descriptor_t *d)345 {346 const char *transfer_type;347 switch (d->attributes & 3) {348 case USB_TRANSFER_CONTROL:349 transfer_type = "control";350 break;351 case USB_TRANSFER_ISOCHRONOUS:352 transfer_type = "isochronous";353 break;354 case USB_TRANSFER_BULK:355 transfer_type = "bulk";356 break;357 case USB_TRANSFER_INTERRUPT:358 transfer_type = "interrupt";359 break;360 }361 362 printf("Standard endpoint descriptor\n");363 printf(INDENT "bLength = %d\n", d->length);364 printf(INDENT "bDescriptorType = 0x%02x\n", d->descriptor_type);365 printf(INDENT "bmAttributes = %d [%s]\n", d->attributes, transfer_type);366 printf(INDENT "wMaxPacketSize = %d\n", d->max_packet_size);367 printf(INDENT "bInterval = %d\n", d->poll_interval);368 }369 370 static void dump_standard_hid_descriptor_header(371 const usb_standard_hid_descriptor_t *d)372 {373 printf("Standard HID descriptor\n");374 printf(INDENT "bLength = %d\n", d->length);375 printf(INDENT "bDescriptorType = 0x%02x\n", d->descriptor_type);376 printf(INDENT "bcdHID = %d\n", d->spec_release);377 printf(INDENT "bCountryCode = %d\n", d->country_code);378 printf(INDENT "bNumDescriptors = %d\n", d->class_desc_count);379 }380 381 static void dump_standard_hid_class_descriptor_info(382 const usb_standard_hid_class_descriptor_info_t *d)383 {384 printf(INDENT "bDescriptorType = %d\n", d->type);385 printf(INDENT "wDescriptorLength = %d\n", d->length);386 }387 388 static void dump_hid_class_descriptor(int index, uint8_t type,389 const uint8_t *d, size_t size )390 {391 printf("Class-specific descriptor #%d (type: %u)\n", index, type);392 assert(d != NULL);393 dump_buffer("", d, size);394 301 } 395 302
Note:
See TracChangeset
for help on using the changeset viewer.