Copyright (c) 2004, Sun Microsystems, Inc., All Rights Reserved
The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License.
You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing. See the License for the specific language governing permissions and limitations under the License.
When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
#include <sys/usb/usba.h> size_t usb_parse_data(char *format, const uchar_t *data, size_t datalen, void *structure, size_t structlen);
Null terminated string describing the format of the data structure for general-purpose byte swapping. The letters "c," "s," "l," and "L" represent 1, 2, 4 and 8 byte quantities, respectively. A descriptor that consists of a short and two bytes would be described by "scc." A number preceding a letter serves as a multiplier of that letter. A format equivalent to "scc" is "s2c."
Raw descriptor data to parse.
Length, in bytes, of the raw descriptor data buffer.
Destination data buffer where parsed data is returned.
Length, in bytes, of the destination data buffer. Parsed result length will not exceed this value.
While the USBA framework can parse the endpoint, interface, configuration, and string descriptors defined by the USB 3.0 specification, the format of class- or vendor-specific descriptors cannot be explicitly defined by the specification and will be unique for each. The format argument defines how to parse such a descriptor.
While the USB specification defines bit ordering as little-endian, this routine (like the entire API), converts the data to the endianness of the host.
The structlen parameter defines the size of the destination data buffer. Data is truncated to this size if the destination data buffer is too small.
On failure: Returns 0. (Same as USB_PARSE_ERROR).
/* * Parse raw descriptor data in buf, putting result into ret_descr. * ret_buf_len holds the size of ret_descr buf; routine returns * number of resulting bytes. * * Descriptor being parsed has 2 chars, followed by one short, * 3 chars and one more short. */ size_t size_of_returned_descr; xxx_descr_t ret_descr; size_of_returned_descr = usb_parse_data("ccscccs", buf, sizeof(buf), (void *)ret_descr, (sizeof)xxx_descr_t)); if (size_of_returned_descr < (sizeof (xxx_descr_t))) { /* Data truncated. */ } or: size_of_returned_descr = usb_parse_data("2cs3cs", buf, sizeof(buf), (void *)ret_descr, (sizeof)xxx_descr_t)); if (size_of_returned_descr < (sizeof (xxx_descr_t))) { /* Data truncated. */ }
ATTRIBUTE TYPE ATTRIBUTE VALUE |
Architecture PCI-based systems |
Interface stability Committed |