Changeset 6986418 in mainline for uspace/drv/usbkbd/descparser.c


Ignore:
Timestamp:
2011-01-14T12:20:54Z (13 years ago)
Author:
Lubos Slovak <lubos.slovak@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
b2a6fcfe
Parents:
2b0db98
Message:

Descriptor parsing modified (fixed)

  • change usbkbd_parse_descriptors() not to parse class-specific descriptors as these are retrieved differently
  • dump functions moved to descdump.h/c
  • getting report descriptor in usbkbd/main.c
  • changed descriptor structures (hid.h) to reflect, that there is only one report descriptor
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/usbkbd/descparser.c

    r2b0db98 r6986418  
    3232#include <usb/descriptor.h>
    3333#include "descparser.h"
     34#include "descdump.h"
    3435
    3536static void usbkbd_config_free(usb_hid_configuration_t *config)
     
    9495            sizeof(usb_standard_configuration_descriptor_t));
    9596        pos += sizeof(usb_standard_configuration_descriptor_t);
     97
     98        printf("Parsed configuration descriptor: \n");
     99        dump_standard_configuration_descriptor(0, &config->config_descriptor);
    96100       
    97101        int ret = EOK;
     
    102106                    *(pos + 1));
    103107                return EINVAL;
    104         }       
     108        }
    105109       
    106110        // prepare place for interface descriptors
     
    112116        // the respective structures
    113117        int ep_i = -1;
    114         int hid_i = -1;
     118        //int hid_i = -1;
    115119       
    116120        usb_hid_iface_t *actual_iface = NULL;
     
    134138                        memcpy(&actual_iface->iface_desc, pos, desc_size);
    135139                        pos += desc_size;
     140
     141                        printf("Parsed interface descriptor: \n");
     142                        dump_standard_interface_descriptor(&actual_iface->iface_desc);
    136143                       
    137144                        // allocate space for endpoint descriptors
     
    170177                        memcpy(&actual_iface->endpoints[ep_i], pos, desc_size);
    171178                        pos += desc_size;
     179
     180                        printf("Parsed endpoint descriptor: \n");
     181                        dump_standard_endpoint_descriptor(&actual_iface->endpoints[ep_i]);
    172182                        ++ep_i;
    173183                       
     
    194204                                goto end;
    195205                        }
     206
     207                        printf("Parsed HID descriptor header: \n");
     208                        dump_standard_hid_descriptor_header(&actual_iface->hid_desc);
    196209                       
    197210                        // allocate space for all class-specific descriptor info
     
    206219                       
    207220                        // allocate space for all class-specific descriptors
    208                         actual_iface->class_descs = (uint8_t **)calloc(
     221                        /*actual_iface->class_descs = (uint8_t **)calloc(
    209222                            actual_iface->hid_desc.class_desc_count,
    210223                            sizeof(uint8_t *));
     
    212225                                ret = ENOMEM;
    213226                                goto end;
    214                         }
     227                        }*/
    215228
    216229                        // copy all class-specific descriptor info
    217230                        // TODO: endianness
     231                        /*
    218232                        memcpy(actual_iface->class_desc_info, pos,
    219233                            actual_iface->hid_desc.class_desc_count
     
    221235                        pos += actual_iface->hid_desc.class_desc_count
    222236                            * 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);
    225244                        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;
    234248                       
    235249                        break;
    236                 case USB_DESCTYPE_HID_REPORT:
     250/*              case USB_DESCTYPE_HID_REPORT:
    237251                case USB_DESCTYPE_HID_PHYSICAL: {
    238252                        // check if the type matches
     
    262276                        memcpy(actual_iface->class_descs[hid_i], pos, length);
    263277                        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                                                 
    264283                        ++hid_i;
    265284                       
    266                         break; }
     285                        break; }*/
    267286                default:
    268287                        fprintf(stderr, "Got descriptor of unknown type: %u.\n",
     
    280299       
    281300        return ret;
    282 }
    283 
    284 /*----------------------------------------------------------------------------*/
    285 
    286 #define BYTES_PER_LINE 12
    287 
    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);
    394301}
    395302
Note: See TracChangeset for help on using the changeset viewer.