Ignore:
File:
1 edited

Legend:

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

    r36f737a raaf6155  
    6767static int usb_hid_set_boot_kbd_subdriver(usb_hid_dev_t *hid_dev)
    6868{
    69         assert(hid_dev != NULL && hid_dev->subdriver_count == 0);
     69        assert(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 != NULL && hid_dev->subdriver_count == 0);
     99        assert(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 != NULL && hid_dev->subdriver_count == 0);
     129        assert(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;
     161}
     162
     163/*----------------------------------------------------------------------------*/
     164
     165static bool usb_hid_path_matches(usb_hid_dev_t *hid_dev,
     166    const usb_hid_subdriver_usage_t *path, int path_size, int compare)
     167{
    160168        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);
    167 }
    168 
    169 /*----------------------------------------------------------------------------*/
    170 
    171 static bool usb_hid_path_matches(usb_hid_dev_t *hid_dev,
    172     const usb_hid_subdriver_mapping_t *mapping)
    173 {
    174         assert(hid_dev != NULL);
    175         assert(mapping != NULL);
     169        assert(path != NULL);
    176170       
    177171        usb_hid_report_path_t *usage_path = usb_hid_report_path();
     
    180174                return false;
    181175        }
    182         int i = 0;
    183         while (mapping->usage_path[i].usage != 0
    184             || mapping->usage_path[i].usage_page != 0) {
     176        int i;
     177        for (i = 0; i < path_size; ++i) {
    185178                if (usb_hid_report_path_append_item(usage_path,
    186                     mapping->usage_path[i].usage_page,
    187                     mapping->usage_path[i].usage) != EOK) {
     179                    path[i].usage_page, path[i].usage) != EOK) {
    188180                        usb_log_debug("Failed to append to usage path.\n");
    189181                        usb_hid_report_path_free(usage_path);
    190182                        return false;
    191183                }
    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);
     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);
    206192       
    207193        usb_hid_report_path_free(usage_path);
     
    245231static int usb_hid_find_subdrivers(usb_hid_dev_t *hid_dev)
    246232{
    247         assert(hid_dev != NULL);
    248        
    249233        const usb_hid_subdriver_t *subdrivers[USB_HID_MAX_SUBDRIVERS];
    250234       
    251235        int i = 0, count = 0;
    252236        const usb_hid_subdriver_mapping_t *mapping = &usb_hid_subdrivers[i];
    253 
    254         bool ids_matched;
    255         bool matched;
    256237       
    257238        while (count < USB_HID_MAX_SUBDRIVERS &&
    258239            (mapping->usage_path != NULL
    259             || mapping->vendor_id >= 0 || mapping->product_id >= 0)) {
     240            || mapping->vendor_id != NULL
     241            || mapping->product_id != NULL)) {
    260242                // check the vendor & product ID
    261                 if (mapping->vendor_id >= 0 && mapping->product_id < 0) {
    262                         usb_log_warning("Missing Product ID for Vendor ID %d\n",
     243                if (mapping->vendor_id != NULL && mapping->product_id == NULL) {
     244                        usb_log_warning("Missing Product ID for Vendor ID %s\n",
    263245                            mapping->vendor_id);
    264246                        return EINVAL;
    265247                }
    266                 if (mapping->product_id >= 0 && mapping->vendor_id < 0) {
    267                         usb_log_warning("Missing Vendor ID for Product ID %d\n",
     248                if (mapping->product_id != NULL && mapping->vendor_id == NULL) {
     249                        usb_log_warning("Missing Vendor ID for Product ID %s\n",
    268250                            mapping->product_id);
    269251                        return EINVAL;
    270252                }
    271253               
    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,
     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,
    279258                            mapping->product_id);
    280259                        if (usb_hid_ids_match(hid_dev, mapping)) {
    281                                 usb_log_debug("IDs matched.\n");
    282                                 ids_matched = true;
     260                                usb_log_debug("Matched.\n");
     261                                subdrivers[count++] = &mapping->subdriver;
     262                                // skip the checking of usage path
     263                                goto next;
    283264                        }
    284265                }
     
    286267                if (mapping->usage_path != NULL) {
    287268                        usb_log_debug("Comparing device against usage path.\n");
    288                         if (usb_hid_path_matches(hid_dev, mapping)) {
    289                                 // does not matter if IDs were matched
    290                                 matched = true;
     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");
    291275                        }
    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                
     276                }
     277        next:
    301278                mapping = &usb_hid_subdrivers[++i];
    302279        }
     
    310287static int usb_hid_check_pipes(usb_hid_dev_t *hid_dev, usb_device_t *dev)
    311288{
    312         assert(hid_dev != NULL && dev != NULL);
    313        
    314289        int rc = EOK;
    315290       
     
    347322        }
    348323       
    349         hid_dev->report = (usb_hid_report_t *)(malloc(sizeof(
    350             usb_hid_report_t)));
    351         if (hid_dev->report == NULL) {
     324        hid_dev->parser = (usb_hid_report_parser_t *)(malloc(sizeof(
     325            usb_hid_report_parser_t)));
     326        if (hid_dev->parser == NULL) {
    352327                usb_log_fatal("No memory!\n");
    353328                free(hid_dev);
     
    388363                return rc;
    389364        }
    390                
     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       
    391374        /* Get the report descriptor and parse it. */
    392375        rc = usb_hid_process_report_descriptor(hid_dev->usb_dev,
    393             hid_dev->report);
     376            hid_dev->parser);
    394377       
    395378        bool fallback = false;
     
    589572
    590573        // destroy the parser
    591         if ((*hid_dev)->report != NULL) {
    592                 usb_hid_free_report((*hid_dev)->report);
     574        if ((*hid_dev)->parser != NULL) {
     575                usb_hid_free_report_parser((*hid_dev)->parser);
    593576        }
    594577
Note: See TracChangeset for help on using the changeset viewer.