Changeset 6986418 in mainline


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
Location:
uspace
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/usbhub/usbhub.c

    r2b0db98 r6986418  
    468468                target.address = hub_info->usb_device->address;
    469469                target.endpoint = 1;/// \TODO get from endpoint descriptor
    470                 dprintf(1,"[usb_hub] checking changes for hub at addr %d",
    471                     target.address);
     470                /*dprintf(1,"[usb_hub] checking changes for hub at addr %d",
     471                    target.address);*/
    472472
    473473                size_t port_count = hub_info->port_count;
  • uspace/drv/usbkbd/Makefile

    r2b0db98 r6986418  
    3434SOURCES = \
    3535        main.c \
    36         descparser.c
     36        descparser.c \
     37        descdump.c
    3738
    3839include $(USPACE_PREFIX)/Makefile.common
  • 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
  • uspace/drv/usbkbd/descparser.h

    r2b0db98 r6986418  
    2626 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2727 */
     28#ifndef USBHID_DESCPARSER_H_
     29#define USBHID_DESCPARSER_H_
     30
    2831#include <usb/classes/hid.h>
    2932
     
    3235
    3336void usbkbd_print_config(const usb_hid_configuration_t *config);
     37
     38#endif
  • uspace/drv/usbkbd/main.c

    r2b0db98 r6986418  
    107107 * Kbd functions
    108108 */
     109static int usbkbd_get_report_descriptor(usb_hid_dev_kbd_t *kbd_dev)
     110{
     111        // iterate over all configurations and interfaces
     112        // TODO: more configurations!!
     113        unsigned i;
     114        for (i = 0; i < kbd_dev->conf->config_descriptor.interface_count; ++i) {
     115                uint8_t type =
     116                    kbd_dev->conf->interfaces[i].hid_desc.report_desc_info.type;
     117                // TODO: endianness
     118                uint16_t length =
     119                    kbd_dev->conf->interfaces[i].hid_desc.report_desc_info.length;
     120
     121                // allocate space for the report descriptor
     122                kbd_dev->conf->interfaces[i].report_desc = (uint8_t *)malloc(length);
     123                // get the descriptor from the device
     124               
     125        }
     126}
     127
    109128static int usbkbd_process_descriptors(usb_hid_dev_kbd_t *kbd_dev)
    110129{
     
    147166        rc = usbkbd_parse_descriptors(descriptors, transferred, kbd_dev->conf);
    148167        free(descriptors);
    149        
    150         //usbkbd_print_config(kbd_dev->conf);
     168
     169        // get and report descriptors
     170        rc = usbkbd_get_report_descriptor(kbd_dev);
     171       
     172        usbkbd_print_config(kbd_dev->conf);
    151173       
    152174        return rc;
     
    223245static void usbkbd_poll_keyboard(usb_hid_dev_kbd_t *kbd_dev)
    224246{
     247        return;
     248       
    225249        int rc;
    226250        usb_handle_t handle;
  • uspace/lib/usb/include/usb/classes/hid.h

    r2b0db98 r6986418  
    9393        /** Total number of class-specific (i.e. Report and Physical)
    9494         * descriptors.
     95         *
     96         * @note There is always only one Report descriptor.
    9597         */
    9698        uint8_t class_desc_count;
    97 //      /** First mandatory class descriptor info. */
    98 //      usb_standard_hid_descriptor_class_item_t class_descriptor;
     99        /** First mandatory class descriptor (Report) info. */
     100        usb_standard_hid_descriptor_class_item_t report_desc_info;
    99101} __attribute__ ((packed)) usb_standard_hid_descriptor_t;
    100102
     
    106108        usb_standard_endpoint_descriptor_t *endpoints;
    107109        usb_standard_hid_descriptor_t hid_desc;
    108         usb_standard_hid_class_descriptor_info_t *class_desc_info;
    109         uint8_t **class_descs;
     110        uint8_t *report_desc;
     111        //usb_standard_hid_class_descriptor_info_t *class_desc_info;
     112        //uint8_t **class_descs;
    110113} usb_hid_iface_t;
    111114
     
    131134} usb_hid_dev_kbd_t;
    132135
     136// TODO: more configurations!
     137
    133138#endif
    134139/**
Note: See TracChangeset for help on using the changeset viewer.