summaryrefslogtreecommitdiff
path: root/usr/src/man/man9f/usb_parse_data.9f
blob: f3ac26e71040767ff287dce0fead9df25a314c64 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
'\" te
.\" 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]
.TH USB_PARSE_DATA 9F "April 4, 2019"
.SH NAME
usb_parse_data \- Tokenize and align the bytes of raw variable-format data
.SH SYNOPSIS
.nf
#include <sys/usb/usba.h>



\fBsize_t\fR \fBusb_parse_data\fR(\fBchar *\fR\fIformat\fR, \fBconst uchar_t *\fR\fIdata\fR,
     \fBsize_t\fR \fIdatalen\fR, \fBvoid *\fR\fIstructure\fR, \fBsize_t\fR \fIstructlen\fR);
.fi

.SH INTERFACE LEVEL
Solaris DDI specific (Solaris DDI)
.SH PARAMETERS
.ne 2
.na
\fB\fIformat\fR\fR
.ad
.RS 13n
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."
.RE

.sp
.ne 2
.na
\fB\fIdata\fR\fR
.ad
.RS 13n
Raw descriptor data to parse.
.RE

.sp
.ne 2
.na
\fB\fIdatalen\fR\fR
.ad
.RS 13n
Length, in bytes, of the raw descriptor data buffer.
.RE

.sp
.ne 2
.na
\fB\fIstructure\fR\fR
.ad
.RS 13n
Destination data buffer where parsed data is returned.
.RE

.sp
.ne 2
.na
\fB\fIstructlen\fR\fR
.ad
.RS 13n
Length, in bytes, of the destination data buffer. Parsed result length will not
exceed this value.
.RE

.SH DESCRIPTION
The \fBusb_parse_data\fR function parses data such as a variable-format class-
or vendor-specific descriptor. The function also tokenizes and aligns the bytes
of raw descriptor data into fields of a variable-format descriptor.
.sp
.LP
While the USBA framework can parse the endpoint, interface, configuration, and
string descriptors defined by the \fIUSB 3.0\fR specification, the format of
class- or vendor-specific descriptors cannot be explicitly defined by the
specification and will be unique for each. The \fIformat\fR argument defines
how to parse such a descriptor.
.sp
.LP
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.
.sp
.LP
The \fIstructlen\fR parameter defines the size of the destination data buffer.
Data is truncated to this size if the destination data buffer is too small.
.SH RETURN VALUES
On success: Returns the size (in bytes) of the parsed data result.
.sp
.LP
On failure: Returns 0. (Same as USB_PARSE_ERROR).
.SH CONTEXT
May be called from user, kernel or interrupt context.
.SH EXAMPLES
.in +2
.nf
  /*
   * 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. */
  }
.fi
.in -2

.SH ATTRIBUTES
See \fBattributes\fR(5) for descriptions of the following attributes:
.sp

.sp
.TS
box;
c | c
l | l .
ATTRIBUTE TYPE	ATTRIBUTE VALUE
_
Architecture	PCI-based systems
_
Interface stability	Committed
.TE

.SH SEE ALSO
\fBattributes\fR(5), \fBusb_get_dev_data\fR(9F),
\fBusb_get_string_descr\fR(9F), \fBusb_get_cfg\fR(9F)