Ignore:
File:
1 edited

Legend:

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

    raaf6155 r36f737a  
    6767static int usb_hid_set_boot_kbd_subdriver(usb_hid_dev_t *hid_dev)
    6868{
    69         assert(hid_dev->subdriver_count == 0);
     69        assert(hid_dev != NULL && hid_dev->subdriver_count == 0);
    7070       
    7171        hid_dev->subdrivers = (usb_hid_subdriver_t *)malloc(
     
    9797static int usb_hid_set_boot_mouse_subdriver(usb_hid_dev_t *hid_dev)
    9898{
    99         assert(hid_dev->subdriver_count == 0);
     99        assert(hid_dev != NULL && hid_dev->subdriver_count == 0);
    100100       
    101101        hid_dev->subdrivers = (usb_hid_subdriver_t *)malloc(
     
    127127static int usb_hid_set_generic_hid_subdriver(usb_hid_dev_t *hid_dev)
    128128{
    129         assert(hid_dev->subdriver_count == 0);
     129        assert(hid_dev != NULL && hid_dev->subdriver_count == 0);
    130130       
    131131        hid_dev->subdrivers = (usb_hid_subdriver_t *)malloc(
     
    158158    const usb_hid_subdriver_mapping_t *mapping)
    159159{
    160         return false;
     160        assert(hid_dev != NULL);
     161        assert(hid_dev->usb_dev != NULL);
     162       
     163        return (hid_dev->usb_dev->descriptors.device.vendor_id
     164            == mapping->vendor_id
     165            && hid_dev->usb_dev->descriptors.device.product_id
     166            == mapping->product_id);
    161167}
    162168
     
    164170
    165171static bool usb_hid_path_matches(usb_hid_dev_t *hid_dev,
    166     const usb_hid_subdriver_usage_t *path, int path_size, int compare)
     172    const usb_hid_subdriver_mapping_t *mapping)
    167173{
    168174        assert(hid_dev != NULL);
    169         assert(path != NULL);
     175        assert(mapping != NULL);
    170176       
    171177        usb_hid_report_path_t *usage_path = usb_hid_report_path();
     
    174180                return false;
    175181        }
    176         int i;
    177         for (i = 0; i < path_size; ++i) {
     182        int i = 0;
     183        while (mapping->usage_path[i].usage != 0
     184            || mapping->usage_path[i].usage_page != 0) {
    178185                if (usb_hid_report_path_append_item(usage_path,
    179                     path[i].usage_page, path[i].usage) != EOK) {
     186                    mapping->usage_path[i].usage_page,
     187                    mapping->usage_path[i].usage) != EOK) {
    180188                        usb_log_debug("Failed to append to usage path.\n");
    181189                        usb_hid_report_path_free(usage_path);
    182190                        return false;
    183191                }
    184         }
    185        
    186         assert(hid_dev->parser != NULL);
    187        
    188         usb_log_debug("Compare flags: %d\n", compare);
    189         size_t size = usb_hid_report_input_length(hid_dev->parser, usage_path,
    190             compare);
    191         usb_log_debug("Size of the input report: %d\n", size);
     192                ++i;
     193        }
     194       
     195        if (mapping->report_id >= 0) {
     196                usb_hid_report_path_set_report_id(usage_path,
     197                    mapping->report_id);
     198        }
     199       
     200        assert(hid_dev->report != NULL);
     201       
     202        usb_log_debug("Compare flags: %d\n", mapping->compare);
     203        size_t size = usb_hid_report_input_length(hid_dev->report, usage_path,
     204            mapping->compare);
     205        usb_log_debug("Size of the input report: %zuB\n", size);
    192206       
    193207        usb_hid_report_path_free(usage_path);
     
    231245static int usb_hid_find_subdrivers(usb_hid_dev_t *hid_dev)
    232246{
     247        assert(hid_dev != NULL);
     248       
    233249        const usb_hid_subdriver_t *subdrivers[USB_HID_MAX_SUBDRIVERS];
    234250       
    235251        int i = 0, count = 0;
    236252        const usb_hid_subdriver_mapping_t *mapping = &usb_hid_subdrivers[i];
     253
     254        bool ids_matched;
     255        bool matched;
    237256       
    238257        while (count < USB_HID_MAX_SUBDRIVERS &&
    239258            (mapping->usage_path != NULL
    240             || mapping->vendor_id != NULL
    241             || mapping->product_id != NULL)) {
     259            || mapping->vendor_id >= 0 || mapping->product_id >= 0)) {
    242260                // check the vendor & product ID
    243                 if (mapping->vendor_id != NULL && mapping->product_id == NULL) {
    244                         usb_log_warning("Missing Product ID for Vendor ID %s\n",
     261                if (mapping->vendor_id >= 0 && mapping->product_id < 0) {
     262                        usb_log_warning("Missing Product ID for Vendor ID %d\n",
    245263                            mapping->vendor_id);
    246264                        return EINVAL;
    247265                }
    248                 if (mapping->product_id != NULL && mapping->vendor_id == NULL) {
    249                         usb_log_warning("Missing Vendor ID for Product ID %s\n",
     266                if (mapping->product_id >= 0 && mapping->vendor_id < 0) {
     267                        usb_log_warning("Missing Vendor ID for Product ID %d\n",
    250268                            mapping->product_id);
    251269                        return EINVAL;
    252270                }
    253271               
    254                 if (mapping->vendor_id != NULL) {
    255                         assert(mapping->product_id != NULL);
    256                         usb_log_debug("Comparing device against vendor ID %s"
    257                             " and product ID %s.\n", mapping->vendor_id,
     272                ids_matched = false;
     273                matched = false;
     274               
     275                if (mapping->vendor_id >= 0) {
     276                        assert(mapping->product_id >= 0);
     277                        usb_log_debug("Comparing device against vendor ID %u"
     278                            " and product ID %u.\n", mapping->vendor_id,
    258279                            mapping->product_id);
    259280                        if (usb_hid_ids_match(hid_dev, mapping)) {
    260                                 usb_log_debug("Matched.\n");
    261                                 subdrivers[count++] = &mapping->subdriver;
    262                                 // skip the checking of usage path
    263                                 goto next;
     281                                usb_log_debug("IDs matched.\n");
     282                                ids_matched = true;
    264283                        }
    265284                }
     
    267286                if (mapping->usage_path != NULL) {
    268287                        usb_log_debug("Comparing device against usage path.\n");
    269                         if (usb_hid_path_matches(hid_dev,
    270                             mapping->usage_path, mapping->path_size,
    271                             mapping->compare)) {
    272                                 subdrivers[count++] = &mapping->subdriver;
    273                         } else {
    274                                 usb_log_debug("Not matched.\n");
     288                        if (usb_hid_path_matches(hid_dev, mapping)) {
     289                                // does not matter if IDs were matched
     290                                matched = true;
    275291                        }
    276                 }
    277         next:
     292                } else {
     293                        // matched only if IDs were matched and there is no path
     294                        matched = ids_matched;
     295                }
     296               
     297                if (matched) {
     298                        subdrivers[count++] = &mapping->subdriver;
     299                }
     300               
    278301                mapping = &usb_hid_subdrivers[++i];
    279302        }
     
    287310static int usb_hid_check_pipes(usb_hid_dev_t *hid_dev, usb_device_t *dev)
    288311{
     312        assert(hid_dev != NULL && dev != NULL);
     313       
    289314        int rc = EOK;
    290315       
     
    322347        }
    323348       
    324         hid_dev->parser = (usb_hid_report_parser_t *)(malloc(sizeof(
    325             usb_hid_report_parser_t)));
    326         if (hid_dev->parser == NULL) {
     349        hid_dev->report = (usb_hid_report_t *)(malloc(sizeof(
     350            usb_hid_report_t)));
     351        if (hid_dev->report == NULL) {
    327352                usb_log_fatal("No memory!\n");
    328353                free(hid_dev);
     
    363388                return rc;
    364389        }
    365        
    366         /* Initialize the report parser. */
    367         rc = usb_hid_parser_init(hid_dev->parser);
    368         if (rc != EOK) {
    369                 usb_log_error("Failed to initialize report parser.\n");
    370                 //usb_hid_free(&hid_dev);
    371                 return rc;
    372         }
    373        
     390               
    374391        /* Get the report descriptor and parse it. */
    375392        rc = usb_hid_process_report_descriptor(hid_dev->usb_dev,
    376             hid_dev->parser);
     393            hid_dev->report);
    377394       
    378395        bool fallback = false;
     
    572589
    573590        // destroy the parser
    574         if ((*hid_dev)->parser != NULL) {
    575                 usb_hid_free_report_parser((*hid_dev)->parser);
     591        if ((*hid_dev)->report != NULL) {
     592                usb_hid_free_report((*hid_dev)->report);
    576593        }
    577594
Note: See TracChangeset for help on using the changeset viewer.