libusb10_desc.c (227404) | libusb10_desc.c (234491) |
---|---|
1/* $FreeBSD: head/lib/libusb/libusb10_desc.c 227404 2011-11-09 19:03:26Z hselasky $ */ | 1/* $FreeBSD: head/lib/libusb/libusb10_desc.c 234491 2012-04-20 14:29:45Z hselasky $ */ |
2/*- 3 * Copyright (c) 2009 Sylvestre Gallon. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. --- 375 unchanged lines hidden (view full) --- 385 free(ep_comp); 386} 387 388int 389libusb_parse_bos_descriptor(const void *buf, int len, 390 struct libusb_bos_descriptor **bos) 391{ 392 struct libusb_bos_descriptor *ptr; | 2/*- 3 * Copyright (c) 2009 Sylvestre Gallon. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. --- 375 unchanged lines hidden (view full) --- 385 free(ep_comp); 386} 387 388int 389libusb_parse_bos_descriptor(const void *buf, int len, 390 struct libusb_bos_descriptor **bos) 391{ 392 struct libusb_bos_descriptor *ptr; |
393 struct libusb_usb_2_0_device_capability_descriptor *dcap_20; 394 struct libusb_ss_usb_device_capability_descriptor *ss_cap; | 393 struct libusb_usb_2_0_device_capability_descriptor *dcap_20 = NULL; 394 struct libusb_ss_usb_device_capability_descriptor *ss_cap = NULL; |
395 396 if (buf == NULL || bos == NULL || len < 1) 397 return (LIBUSB_ERROR_INVALID_PARAM); 398 399 if (len > 65535) 400 len = 65535; 401 402 *bos = ptr = NULL; --- 30 unchanged lines hidden (view full) --- 433 dcap_20 = (void *)(ptr + 1); 434 ss_cap = (void *)(dcap_20 + 1); 435 } 436 if (dlen >= 3 && 437 ptr != NULL && 438 dtype == LIBUSB_DT_DEVICE_CAPABILITY) { 439 switch (((const uint8_t *)buf)[2]) { 440 case LIBUSB_USB_2_0_EXTENSION_DEVICE_CAPABILITY: | 395 396 if (buf == NULL || bos == NULL || len < 1) 397 return (LIBUSB_ERROR_INVALID_PARAM); 398 399 if (len > 65535) 400 len = 65535; 401 402 *bos = ptr = NULL; --- 30 unchanged lines hidden (view full) --- 433 dcap_20 = (void *)(ptr + 1); 434 ss_cap = (void *)(dcap_20 + 1); 435 } 436 if (dlen >= 3 && 437 ptr != NULL && 438 dtype == LIBUSB_DT_DEVICE_CAPABILITY) { 439 switch (((const uint8_t *)buf)[2]) { 440 case LIBUSB_USB_2_0_EXTENSION_DEVICE_CAPABILITY: |
441 if (ptr->usb_2_0_ext_cap != NULL) | 441 if (ptr->usb_2_0_ext_cap != NULL || dcap_20 == NULL) |
442 break; 443 if (dlen < LIBUSB_USB_2_0_EXTENSION_DEVICE_CAPABILITY_SIZE) 444 break; 445 446 ptr->usb_2_0_ext_cap = dcap_20; 447 448 dcap_20->bLength = LIBUSB_USB_2_0_EXTENSION_DEVICE_CAPABILITY_SIZE; 449 dcap_20->bDescriptorType = dtype; 450 dcap_20->bDevCapabilityType = ((const uint8_t *)buf)[2]; 451 dcap_20->bmAttributes = ((const uint8_t *)buf)[3] | 452 (((const uint8_t *)buf)[4] << 8) | 453 (((const uint8_t *)buf)[5] << 16) | 454 (((const uint8_t *)buf)[6] << 24); 455 break; 456 457 case LIBUSB_SS_USB_DEVICE_CAPABILITY: | 442 break; 443 if (dlen < LIBUSB_USB_2_0_EXTENSION_DEVICE_CAPABILITY_SIZE) 444 break; 445 446 ptr->usb_2_0_ext_cap = dcap_20; 447 448 dcap_20->bLength = LIBUSB_USB_2_0_EXTENSION_DEVICE_CAPABILITY_SIZE; 449 dcap_20->bDescriptorType = dtype; 450 dcap_20->bDevCapabilityType = ((const uint8_t *)buf)[2]; 451 dcap_20->bmAttributes = ((const uint8_t *)buf)[3] | 452 (((const uint8_t *)buf)[4] << 8) | 453 (((const uint8_t *)buf)[5] << 16) | 454 (((const uint8_t *)buf)[6] << 24); 455 break; 456 457 case LIBUSB_SS_USB_DEVICE_CAPABILITY: |
458 if (ptr->ss_usb_cap != NULL) | 458 if (ptr->ss_usb_cap != NULL || ss_cap == NULL) |
459 break; 460 if (dlen < LIBUSB_SS_USB_DEVICE_CAPABILITY_SIZE) 461 break; 462 463 ptr->ss_usb_cap = ss_cap; 464 465 ss_cap->bLength = LIBUSB_SS_USB_DEVICE_CAPABILITY_SIZE; 466 ss_cap->bDescriptorType = dtype; --- 32 unchanged lines hidden --- | 459 break; 460 if (dlen < LIBUSB_SS_USB_DEVICE_CAPABILITY_SIZE) 461 break; 462 463 ptr->ss_usb_cap = ss_cap; 464 465 ss_cap->bLength = LIBUSB_SS_USB_DEVICE_CAPABILITY_SIZE; 466 ss_cap->bDescriptorType = dtype; --- 32 unchanged lines hidden --- |