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