Changes in uspace/drv/usbhid/usbhid.c [36f737a:aaf6155] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/usbhid/usbhid.c
r36f737a raaf6155 67 67 static int usb_hid_set_boot_kbd_subdriver(usb_hid_dev_t *hid_dev) 68 68 { 69 assert(hid_dev != NULL && hid_dev->subdriver_count == 0);69 assert(hid_dev->subdriver_count == 0); 70 70 71 71 hid_dev->subdrivers = (usb_hid_subdriver_t *)malloc( … … 97 97 static int usb_hid_set_boot_mouse_subdriver(usb_hid_dev_t *hid_dev) 98 98 { 99 assert(hid_dev != NULL && hid_dev->subdriver_count == 0);99 assert(hid_dev->subdriver_count == 0); 100 100 101 101 hid_dev->subdrivers = (usb_hid_subdriver_t *)malloc( … … 127 127 static int usb_hid_set_generic_hid_subdriver(usb_hid_dev_t *hid_dev) 128 128 { 129 assert(hid_dev != NULL && hid_dev->subdriver_count == 0);129 assert(hid_dev->subdriver_count == 0); 130 130 131 131 hid_dev->subdrivers = (usb_hid_subdriver_t *)malloc( … … 158 158 const usb_hid_subdriver_mapping_t *mapping) 159 159 { 160 return false; 161 } 162 163 /*----------------------------------------------------------------------------*/ 164 165 static 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 { 160 168 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); 176 170 177 171 usb_hid_report_path_t *usage_path = usb_hid_report_path(); … … 180 174 return false; 181 175 } 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) { 185 178 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) { 188 180 usb_log_debug("Failed to append to usage path.\n"); 189 181 usb_hid_report_path_free(usage_path); 190 182 return false; 191 183 } 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); 206 192 207 193 usb_hid_report_path_free(usage_path); … … 245 231 static int usb_hid_find_subdrivers(usb_hid_dev_t *hid_dev) 246 232 { 247 assert(hid_dev != NULL);248 249 233 const usb_hid_subdriver_t *subdrivers[USB_HID_MAX_SUBDRIVERS]; 250 234 251 235 int i = 0, count = 0; 252 236 const usb_hid_subdriver_mapping_t *mapping = &usb_hid_subdrivers[i]; 253 254 bool ids_matched;255 bool matched;256 237 257 238 while (count < USB_HID_MAX_SUBDRIVERS && 258 239 (mapping->usage_path != NULL 259 || mapping->vendor_id >= 0 || mapping->product_id >= 0)) { 240 || mapping->vendor_id != NULL 241 || mapping->product_id != NULL)) { 260 242 // 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", 263 245 mapping->vendor_id); 264 246 return EINVAL; 265 247 } 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", 268 250 mapping->product_id); 269 251 return EINVAL; 270 252 } 271 253 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, 279 258 mapping->product_id); 280 259 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; 283 264 } 284 265 } … … 286 267 if (mapping->usage_path != NULL) { 287 268 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"); 291 275 } 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: 301 278 mapping = &usb_hid_subdrivers[++i]; 302 279 } … … 310 287 static int usb_hid_check_pipes(usb_hid_dev_t *hid_dev, usb_device_t *dev) 311 288 { 312 assert(hid_dev != NULL && dev != NULL);313 314 289 int rc = EOK; 315 290 … … 347 322 } 348 323 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) { 352 327 usb_log_fatal("No memory!\n"); 353 328 free(hid_dev); … … 388 363 return rc; 389 364 } 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 391 374 /* Get the report descriptor and parse it. */ 392 375 rc = usb_hid_process_report_descriptor(hid_dev->usb_dev, 393 hid_dev-> report);376 hid_dev->parser); 394 377 395 378 bool fallback = false; … … 589 572 590 573 // 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); 593 576 } 594 577
Note:
See TracChangeset
for help on using the changeset viewer.