Ignore:
File:
1 edited

Legend:

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

    raaf6155 re3b5129  
    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(
     
    164164
    165165static bool usb_hid_path_matches(usb_hid_dev_t *hid_dev,
    166     const usb_hid_subdriver_usage_t *path, int path_size, int compare)
     166    const usb_hid_subdriver_mapping_t *mapping)
    167167{
    168168        assert(hid_dev != NULL);
    169         assert(path != NULL);
     169        assert(mapping != NULL);
    170170       
    171171        usb_hid_report_path_t *usage_path = usb_hid_report_path();
     
    174174                return false;
    175175        }
    176         int i;
    177         for (i = 0; i < path_size; ++i) {
     176        int i = 0;
     177        while (mapping->usage_path[i].usage != 0
     178            || mapping->usage_path[i].usage_page != 0) {
    178179                if (usb_hid_report_path_append_item(usage_path,
    179                     path[i].usage_page, path[i].usage) != EOK) {
     180                    mapping->usage_path[i].usage_page,
     181                    mapping->usage_path[i].usage) != EOK) {
    180182                        usb_log_debug("Failed to append to usage path.\n");
    181183                        usb_hid_report_path_free(usage_path);
    182184                        return false;
    183185                }
     186                ++i;
     187        }
     188       
     189        if (mapping->report_id >= 0) {
     190                usb_hid_report_path_set_report_id(usage_path,
     191                    mapping->report_id);
    184192        }
    185193       
    186194        assert(hid_dev->parser != NULL);
    187195       
    188         usb_log_debug("Compare flags: %d\n", compare);
     196        usb_log_debug("Compare flags: %d\n", mapping->compare);
    189197        size_t size = usb_hid_report_input_length(hid_dev->parser, usage_path,
    190             compare);
     198            mapping->compare);
    191199        usb_log_debug("Size of the input report: %d\n", size);
    192200       
     
    231239static int usb_hid_find_subdrivers(usb_hid_dev_t *hid_dev)
    232240{
     241        assert(hid_dev != NULL);
     242       
    233243        const usb_hid_subdriver_t *subdrivers[USB_HID_MAX_SUBDRIVERS];
    234244       
    235245        int i = 0, count = 0;
    236246        const usb_hid_subdriver_mapping_t *mapping = &usb_hid_subdrivers[i];
     247
     248        bool ids_matched;
     249        bool matched;
    237250       
    238251        while (count < USB_HID_MAX_SUBDRIVERS &&
    239252            (mapping->usage_path != NULL
    240             || mapping->vendor_id != NULL
    241             || mapping->product_id != NULL)) {
     253            || mapping->vendor_id != 0 || mapping->product_id != 0)) {
    242254                // 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",
     255                if (mapping->vendor_id != 0 && mapping->product_id == 0) {
     256                        usb_log_warning("Missing Product ID for Vendor ID %u\n",
    245257                            mapping->vendor_id);
    246258                        return EINVAL;
    247259                }
    248                 if (mapping->product_id != NULL && mapping->vendor_id == NULL) {
    249                         usb_log_warning("Missing Vendor ID for Product ID %s\n",
     260                if (mapping->product_id != 0 && mapping->vendor_id == 0) {
     261                        usb_log_warning("Missing Vendor ID for Product ID %u\n",
    250262                            mapping->product_id);
    251263                        return EINVAL;
    252264                }
    253265               
    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,
     266                ids_matched = false;
     267                matched = false;
     268               
     269                if (mapping->vendor_id != 0) {
     270                        assert(mapping->product_id != 0);
     271                        usb_log_debug("Comparing device against vendor ID %u"
     272                            " and product ID %u.\n", mapping->vendor_id,
    258273                            mapping->product_id);
    259274                        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;
     275                                usb_log_debug("IDs matched.\n");
     276                                ids_matched = true;
    264277                        }
    265278                }
     
    267280                if (mapping->usage_path != NULL) {
    268281                        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");
     282                        if (usb_hid_path_matches(hid_dev, mapping)) {
     283                                // does not matter if IDs were matched
     284                                matched = true;
    275285                        }
    276                 }
    277         next:
     286                } else {
     287                        // matched only if IDs were matched and there is no path
     288                        matched = ids_matched;
     289                }
     290               
     291                if (matched) {
     292                        subdrivers[count++] = &mapping->subdriver;
     293                }
     294               
    278295                mapping = &usb_hid_subdrivers[++i];
    279296        }
     
    287304static int usb_hid_check_pipes(usb_hid_dev_t *hid_dev, usb_device_t *dev)
    288305{
     306        assert(hid_dev != NULL && dev != NULL);
     307       
    289308        int rc = EOK;
    290309       
     
    360379        rc = usb_hid_check_pipes(hid_dev, dev);
    361380        if (rc != EOK) {
    362                 //usb_hid_free(&hid_dev);
     381                usb_hid_free(&hid_dev);
    363382                return rc;
    364383        }
     
    368387        if (rc != EOK) {
    369388                usb_log_error("Failed to initialize report parser.\n");
    370                 //usb_hid_free(&hid_dev);
     389                usb_hid_free(&hid_dev);
    371390                return rc;
    372391        }
     
    386405                            " device.\n");
    387406                        fallback = true;
    388                         assert(hid_dev->subdrivers == NULL);
    389                         assert(hid_dev->subdriver_count == 0);
    390407                }
    391408        } else {
     
    428445                usb_log_error("No subdriver for handling this device could be"
    429446                    " initialized: %s.\n", str_error(rc));
    430                 usb_log_debug("Subdriver count: %d\n",
    431                     hid_dev->subdriver_count);
    432                 //usb_hid_free(&hid_dev);
     447                usb_hid_free(&hid_dev);
    433448        } else {
    434449                bool ok = false;
     
    554569        }
    555570       
    556         usb_log_debug("Subdrivers: %p, subdriver count: %d\n",
    557             (*hid_dev)->subdrivers, (*hid_dev)->subdriver_count);
    558        
    559571        assert((*hid_dev)->subdrivers != NULL
    560572            || (*hid_dev)->subdriver_count == 0);
Note: See TracChangeset for help on using the changeset viewer.