/* set host_endian if the w values are already in host endian format,
* as opposed to bus endian. */
-int usbi_parse_descriptor(const unsigned char *source, const char *descriptor,
+static void parse_descriptor(const unsigned char *source, const char *descriptor,
void *dest, int host_endian)
{
const unsigned char *sp = source;
break;
}
}
-
- return (int) (sp - source);
}
static void clear_endpoint(struct libusb_endpoint_descriptor *endpoint)
return parsed;
}
if (header->bLength >= ENDPOINT_AUDIO_DESC_LENGTH)
- usbi_parse_descriptor(buffer, "bbbbwbbb", endpoint, host_endian);
+ parse_descriptor(buffer, "bbbbwbbb", endpoint, host_endian);
else if (header->bLength >= ENDPOINT_DESC_LENGTH)
- usbi_parse_descriptor(buffer, "bbbbwb", endpoint, host_endian);
+ parse_descriptor(buffer, "bbbbwb", endpoint, host_endian);
else {
usbi_err(ctx, "invalid endpoint bLength (%d)", header->bLength);
return LIBUSB_ERROR_IO;
usb_interface->altsetting = altsetting;
ifp = altsetting + usb_interface->num_altsetting;
- usbi_parse_descriptor(buffer, "bbbbbbbbb", ifp, 0);
+ parse_descriptor(buffer, "bbbbbbbbb", ifp, 0);
if (ifp->bDescriptorType != LIBUSB_DT_INTERFACE) {
usbi_err(ctx, "unexpected descriptor %x (expected %x)",
ifp->bDescriptorType, LIBUSB_DT_INTERFACE);
return LIBUSB_ERROR_IO;
}
- usbi_parse_descriptor(buffer, "bbwbbbbb", config, host_endian);
+ parse_descriptor(buffer, "bbwbbbbb", config, host_endian);
if (config->bDescriptorType != LIBUSB_DT_CONFIG) {
usbi_err(ctx, "unexpected descriptor %x (expected %x)",
config->bDescriptorType, LIBUSB_DT_CONFIG);
return LIBUSB_ERROR_IO;
}
- usbi_parse_descriptor(tmp, "bbw", &_config, host_endian);
+ parse_descriptor(tmp, "bbw", &_config, host_endian);
buf = malloc(_config.wTotalLength);
if (!buf)
return LIBUSB_ERROR_NO_MEM;
return LIBUSB_ERROR_IO;
}
- usbi_parse_descriptor(tmp, "bbw", &_config, host_endian);
+ parse_descriptor(tmp, "bbw", &_config, host_endian);
buf = malloc(_config.wTotalLength);
if (!buf)
return LIBUSB_ERROR_NO_MEM;
*ep_comp = malloc(sizeof(**ep_comp));
if (*ep_comp == NULL)
return LIBUSB_ERROR_NO_MEM;
- usbi_parse_descriptor(buffer, "bbbbw", *ep_comp, 0);
+ parse_descriptor(buffer, "bbbbw", *ep_comp, 0);
return LIBUSB_SUCCESS;
}
return LIBUSB_ERROR_NOT_FOUND;
return LIBUSB_ERROR_IO;
}
- usbi_parse_descriptor(buffer, "bbwb", &bos_header, host_endian);
+ parse_descriptor(buffer, "bbwb", &bos_header, host_endian);
if (bos_header.bDescriptorType != LIBUSB_DT_BOS) {
usbi_err(ctx, "unexpected descriptor %x (expected %x)",
bos_header.bDescriptorType, LIBUSB_DT_BOS);
if (!_bos)
return LIBUSB_ERROR_NO_MEM;
- usbi_parse_descriptor(buffer, "bbwb", _bos, host_endian);
+ parse_descriptor(buffer, "bbwb", _bos, host_endian);
buffer += bos_header.bLength;
size -= bos_header.bLength;
size, LIBUSB_DT_DEVICE_CAPABILITY_SIZE);
break;
}
- usbi_parse_descriptor(buffer, "bbb", &dev_cap, host_endian);
+ parse_descriptor(buffer, "bbb", &dev_cap, host_endian);
if (dev_cap.bDescriptorType != LIBUSB_DT_DEVICE_CAPABILITY) {
usbi_warn(ctx, "unexpected descriptor %x (expected %x)",
dev_cap.bDescriptorType, LIBUSB_DT_DEVICE_CAPABILITY);
return LIBUSB_ERROR_IO;
}
- usbi_parse_descriptor(bos_header, "bbwb", &_bos, host_endian);
+ parse_descriptor(bos_header, "bbwb", &_bos, host_endian);
usbi_dbg("found BOS descriptor: size %d bytes, %d capabilities",
_bos.wTotalLength, _bos.bNumDeviceCaps);
bos_data = calloc(_bos.wTotalLength, 1);
if (!_usb_2_0_extension)
return LIBUSB_ERROR_NO_MEM;
- usbi_parse_descriptor((unsigned char *)dev_cap, "bbbd",
- _usb_2_0_extension, host_endian);
+ parse_descriptor((unsigned char *)dev_cap, "bbbd",
+ _usb_2_0_extension, host_endian);
*usb_2_0_extension = _usb_2_0_extension;
return LIBUSB_SUCCESS;
if (!_ss_usb_device_cap)
return LIBUSB_ERROR_NO_MEM;
- usbi_parse_descriptor((unsigned char *)dev_cap, "bbbbwbbw",
- _ss_usb_device_cap, host_endian);
+ parse_descriptor((unsigned char *)dev_cap, "bbbbwbbw",
+ _ss_usb_device_cap, host_endian);
*ss_usb_device_cap = _ss_usb_device_cap;
return LIBUSB_SUCCESS;
if (!_container_id)
return LIBUSB_ERROR_NO_MEM;
- usbi_parse_descriptor((unsigned char *)dev_cap, "bbbbu",
- _container_id, host_endian);
+ parse_descriptor((unsigned char *)dev_cap, "bbbbu",
+ _container_id, host_endian);
*container_id = _container_id;
return LIBUSB_SUCCESS;
static int seek_to_next_descriptor(struct libusb_context *ctx,
uint8_t descriptor_type, unsigned char *buffer, int size)
{
- struct usbi_descriptor_header header;
+ struct usbi_descriptor_header *header;
int i;
- for (i = 0; size >= 0; i += header.bLength, size -= header.bLength) {
+ for (i = 0; size >= 0; i += header->bLength, size -= header->bLength) {
if (size == 0)
return LIBUSB_ERROR_NOT_FOUND;
usbi_err(ctx, "short descriptor read %d/2", size);
return LIBUSB_ERROR_IO;
}
- usbi_parse_descriptor(buffer + i, "bb", &header, 0);
- if (i && header.bDescriptorType == descriptor_type)
+ header = (struct usbi_descriptor_header *)(buffer + i);
+ if (i && header->bDescriptorType == descriptor_type)
return i;
}
usbi_err(ctx, "bLength overflow by %d bytes", -size);
{
struct libusb_context *ctx = DEVICE_CTX(dev);
struct linux_device_priv *priv = usbi_get_device_priv(dev);
- struct libusb_config_descriptor config;
+ struct usbi_configuration_descriptor *config;
+ uint16_t config_len;
if (size == 0)
return LIBUSB_ERROR_NOT_FOUND;
return LIBUSB_ERROR_IO;
}
- usbi_parse_descriptor(buffer, "bbwbbbbb", &config, 0);
- if (config.bDescriptorType != LIBUSB_DT_CONFIG) {
+ config = (struct usbi_configuration_descriptor *)buffer;
+ if (config->bDescriptorType != LIBUSB_DT_CONFIG) {
usbi_err(ctx, "descriptor is not a config desc (type 0x%02x)",
- config.bDescriptorType);
+ config->bDescriptorType);
return LIBUSB_ERROR_IO;
}
+ config_len = libusb_le16_to_cpu(config->wTotalLength);
/*
- * In usbfs the config descriptors are config.wTotalLength bytes apart,
+ * In usbfs the config descriptors are wTotalLength bytes apart,
* with any short reads from the device appearing as holes in the file.
*
* In sysfs wTotalLength is ignored, instead the kernel returns a
if (next < 0)
return next;
- if (next != config.wTotalLength)
+ if (next != config_len)
usbi_warn(ctx, "config length mismatch wTotalLength %u real %d",
- config.wTotalLength, next);
+ config_len, next);
return next;
} else {
- if (config.wTotalLength < LIBUSB_DT_CONFIG_SIZE) {
- usbi_err(ctx, "invalid wTotalLength %u", config.wTotalLength);
+ if (config_len < LIBUSB_DT_CONFIG_SIZE) {
+ usbi_err(ctx, "invalid wTotalLength %u", config_len);
return LIBUSB_ERROR_IO;
- } else if (config.wTotalLength > size) {
+ } else if (config_len > size) {
usbi_warn(ctx, "short descriptor read %d/%u",
- size, config.wTotalLength);
+ size, config_len);
return size;
} else {
- return config.wTotalLength;
+ return config_len;
}
}
}
struct linux_device_priv *priv = usbi_get_device_priv(dev);
unsigned char *descriptors = priv->descriptors;
int size = priv->descriptors_len;
- struct libusb_config_descriptor *config;
+ struct usbi_configuration_descriptor *config;
*buffer = NULL;
/* Unlike the device desc. config descs. are always in raw format */
if (next < 0)
return next;
- config = (struct libusb_config_descriptor *)descriptors;
+ config = (struct usbi_configuration_descriptor *)descriptors;
if (config->bConfigurationValue == value) {
*buffer = descriptors;
return next;
usbi_warn(ctx, "Missing rw usbfs access; cannot determine "
"active configuration descriptor");
if (priv->descriptors_len >= (DEVICE_DESC_LENGTH + LIBUSB_DT_CONFIG_SIZE)) {
- struct libusb_config_descriptor config;
+ struct usbi_configuration_descriptor *config;
- usbi_parse_descriptor(priv->descriptors + DEVICE_DESC_LENGTH,
- "bbwbbbbb", &config, 0);
- priv->active_config = config.bConfigurationValue;
+ config = (struct usbi_configuration_descriptor *)(priv->descriptors + DEVICE_DESC_LENGTH);
+ priv->active_config = config->bConfigurationValue;
} else {
priv->active_config = -1; /* No config dt */
}