xref: /third_party/FreeBSD/sys/dev/usb/usb_cdc.h (revision f9f848fa)
1/*	$NetBSD: usbcdc.h,v 1.9 2004/10/23 13:24:24 augustss Exp $	*/
2
3/*-
4 * SPDX-License-Identifier: BSD-2-Clause
5 *
6 * Copyright (c) 1998 The NetBSD Foundation, Inc.
7 * All rights reserved.
8 *
9 * This code is derived from software contributed to The NetBSD Foundation
10 * by Lennart Augustsson (lennart@augustsson.net) at
11 * Carlstedt Research & Technology.
12 *
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
15 * are met:
16 * 1. Redistributions of source code must retain the above copyright
17 *    notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 *    notice, this list of conditions and the following disclaimer in the
20 *    documentation and/or other materials provided with the distribution.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
23 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
24 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
25 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
26 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 * POSSIBILITY OF SUCH DAMAGE.
33 */
34
35#ifndef _USB_CDC_H_
36#define	_USB_CDC_H_
37
38#define	UDESCSUB_CDC_HEADER	0
39#define	UDESCSUB_CDC_CM		1	/* Call Management */
40#define	UDESCSUB_CDC_ACM	2	/* Abstract Control Model */
41#define	UDESCSUB_CDC_DLM	3	/* Direct Line Management */
42#define	UDESCSUB_CDC_TRF	4	/* Telephone Ringer */
43#define	UDESCSUB_CDC_TCLSR	5	/* Telephone Call */
44#define	UDESCSUB_CDC_UNION	6
45#define	UDESCSUB_CDC_CS		7	/* Country Selection */
46#define	UDESCSUB_CDC_TOM	8	/* Telephone Operational Modes */
47#define	UDESCSUB_CDC_USBT	9	/* USB Terminal */
48#define	UDESCSUB_CDC_NCT	10
49#define	UDESCSUB_CDC_PUF	11
50#define	UDESCSUB_CDC_EUF	12
51#define	UDESCSUB_CDC_MCMF	13
52#define	UDESCSUB_CDC_CCMF	14
53#define	UDESCSUB_CDC_ENF	15
54#define	UDESCSUB_CDC_ANF	16
55
56struct usb_cdc_header_descriptor {
57	uByte	bLength;
58	uByte	bDescriptorType;
59	uByte	bDescriptorSubtype;
60	uWord	bcdCDC;
61} __packed;
62
63struct usb_cdc_cm_descriptor {
64	uByte	bLength;
65	uByte	bDescriptorType;
66	uByte	bDescriptorSubtype;
67	uByte	bmCapabilities;
68#define	USB_CDC_CM_DOES_CM		0x01
69#define	USB_CDC_CM_OVER_DATA		0x02
70	uByte	bDataInterface;
71} __packed;
72
73struct usb_cdc_acm_descriptor {
74	uByte	bLength;
75	uByte	bDescriptorType;
76	uByte	bDescriptorSubType;
77	uByte	bmCapabilities;
78#define	USB_CDC_ACM_HAS_FEATURE		0x01
79#define	USB_CDC_ACM_HAS_LINE		0x02
80#define	USB_CDC_ACM_HAS_BREAK		0x04
81#define	USB_CDC_ACM_HAS_NETWORK_CONN	0x08
82} __packed;
83
84struct usb_cdc_call_mgmt_descriptor {
85	uByte	bLength;
86	uByte	bDescriptorType;
87	uByte	bDescriptorSubType;
88	uByte	bmCapabilities;
89
90	uByte	bDataInterface;
91} __packed;
92
93struct usb_cdc_header_desc {
94	uByte	bLength;
95	uByte	bDescriptorType;
96	uByte	bDescriptorSubType;
97
98	uWord	bcdCDC;
99} __packed;
100
101struct usb_cdc_union_desc {
102	uByte	bLength;
103	uByte	bDescriptorType;
104	uByte	bDescriptorSubType;
105
106	uByte	bMasterInterface0;
107	uByte	bSlaveInterface0;
108} __packed;
109
110/* "Ethernet Networking Functional Descriptor" from CDC spec 5.2.3.16 */
111struct usb_cdc_ether_desc {
112	uByte	bLength;
113	uByte	bDescriptorType;
114	uByte	bDescriptorSubType;
115
116	uByte	iMACAddress;
117	uDWord	bmEthernetStatistics;
118	uWord	wMaxSegmentSize;
119	uWord	wNumberMCFilters;
120	uByte	bNumberPowerFilters;
121} __packed;
122
123struct usb_cdc_union_descriptor {
124	uByte	bLength;
125	uByte	bDescriptorType;
126	uByte	bDescriptorSubtype;
127	uByte	bMasterInterface;
128	uByte	bSlaveInterface[1];
129} __packed;
130
131struct usb_cdc_ethernet_descriptor {
132	uByte	bLength;
133	uByte	bDescriptorType;
134	uByte	bDescriptorSubtype;
135	uByte	iMacAddress;
136	uDWord	bmEthernetStatistics;
137	uWord	wMaxSegmentSize;
138	uWord	wNumberMCFilters;
139	uByte	bNumberPowerFilters;
140} __packed;
141
142#define	UCDC_SEND_ENCAPSULATED_COMMAND	0x00
143#define	UCDC_GET_ENCAPSULATED_RESPONSE	0x01
144#define	UCDC_SET_COMM_FEATURE		0x02
145#define	UCDC_GET_COMM_FEATURE		0x03
146#define	UCDC_ABSTRACT_STATE		0x01
147#define	UCDC_COUNTRY_SETTING		0x02
148#define	UCDC_CLEAR_COMM_FEATURE		0x04
149#define	UCDC_SET_LINE_CODING		0x20
150#define	UCDC_GET_LINE_CODING		0x21
151#define	UCDC_SET_CONTROL_LINE_STATE	0x22
152#define	UCDC_LINE_DTR			0x0001
153#define	UCDC_LINE_RTS			0x0002
154#define	UCDC_SEND_BREAK			0x23
155#define	UCDC_BREAK_ON			0xffff
156#define	UCDC_BREAK_OFF			0x0000
157
158struct usb_cdc_abstract_state {
159	uWord	wState;
160#define	UCDC_IDLE_SETTING		0x0001
161#define	UCDC_DATA_MULTIPLEXED		0x0002
162} __packed;
163
164#define	UCDC_ABSTRACT_STATE_LENGTH	2
165
166struct usb_cdc_line_state {
167	uDWord	dwDTERate;
168	uByte	bCharFormat;
169#define	UCDC_STOP_BIT_1			0
170#define	UCDC_STOP_BIT_1_5		1
171#define	UCDC_STOP_BIT_2			2
172	uByte	bParityType;
173#define	UCDC_PARITY_NONE		0
174#define	UCDC_PARITY_ODD			1
175#define	UCDC_PARITY_EVEN		2
176#define	UCDC_PARITY_MARK		3
177#define	UCDC_PARITY_SPACE		4
178	uByte	bDataBits;
179} __packed;
180
181#define	UCDC_LINE_STATE_LENGTH		7
182
183struct usb_cdc_notification {
184	uByte	bmRequestType;
185#define	UCDC_NOTIFICATION		0xa1
186	uByte	bNotification;
187#define	UCDC_N_NETWORK_CONNECTION	0x00
188#define	UCDC_N_RESPONSE_AVAILABLE	0x01
189#define	UCDC_N_AUX_JACK_HOOK_STATE	0x08
190#define	UCDC_N_RING_DETECT		0x09
191#define	UCDC_N_SERIAL_STATE		0x20
192#define	UCDC_N_CALL_STATE_CHANGED	0x28
193#define	UCDC_N_LINE_STATE_CHANGED	0x29
194#define	UCDC_N_CONNECTION_SPEED_CHANGE	0x2a
195	uWord	wValue;
196	uWord	wIndex;
197	uWord	wLength;
198	uByte	data[16];
199} __packed;
200
201#define	UCDC_NOTIFICATION_LENGTH	8
202
203/*
204 * Bits set in the SERIAL STATE notification (first byte of data)
205 */
206
207#define	UCDC_N_SERIAL_OVERRUN		0x40
208#define	UCDC_N_SERIAL_PARITY		0x20
209#define	UCDC_N_SERIAL_FRAMING		0x10
210#define	UCDC_N_SERIAL_RI		0x08
211#define	UCDC_N_SERIAL_BREAK		0x04
212#define	UCDC_N_SERIAL_DSR		0x02
213#define	UCDC_N_SERIAL_DCD		0x01
214
215/* Serial state bit masks */
216#define	UCDC_MDM_RXCARRIER		0x01
217#define	UCDC_MDM_TXCARRIER		0x02
218#define	UCDC_MDM_BREAK			0x04
219#define	UCDC_MDM_RING			0x08
220#define	UCDC_MDM_FRAMING_ERR		0x10
221#define	UCDC_MDM_PARITY_ERR		0x20
222#define	UCDC_MDM_OVERRUN_ERR		0x40
223
224/*
225 * Network Control Model, NCM16 + NCM32, protocol definitions
226 */
227struct usb_ncm16_hdr {
228	uDWord	dwSignature;
229	uWord	wHeaderLength;
230	uWord	wSequence;
231	uWord	wBlockLength;
232	uWord	wDptIndex;
233} __packed;
234
235struct usb_ncm16_dp {
236	uWord	wFrameIndex;
237	uWord	wFrameLength;
238} __packed;
239
240struct usb_ncm16_dpt {
241	uDWord	dwSignature;
242	uWord	wLength;
243	uWord	wNextNdpIndex;
244	struct usb_ncm16_dp dp[0];
245} __packed;
246
247struct usb_ncm32_hdr {
248	uDWord	dwSignature;
249	uWord	wHeaderLength;
250	uWord	wSequence;
251	uDWord	dwBlockLength;
252	uDWord	dwDptIndex;
253} __packed;
254
255struct usb_ncm32_dp {
256	uDWord	dwFrameIndex;
257	uDWord	dwFrameLength;
258} __packed;
259
260struct usb_ncm32_dpt {
261	uDWord	dwSignature;
262	uWord	wLength;
263	uWord	wReserved6;
264	uDWord	dwNextNdpIndex;
265	uDWord	dwReserved12;
266	struct usb_ncm32_dp dp[0];
267} __packed;
268
269/* Communications interface class specific descriptors */
270
271#define	UCDC_NCM_FUNC_DESC_SUBTYPE	0x1A
272
273struct usb_ncm_func_descriptor {
274	uByte	bLength;
275	uByte	bDescriptorType;
276	uByte	bDescriptorSubtype;
277	uByte	bcdNcmVersion[2];
278	uByte	bmNetworkCapabilities;
279#define	UCDC_NCM_CAP_FILTER	0x01
280#define	UCDC_NCM_CAP_MAC_ADDR	0x02
281#define	UCDC_NCM_CAP_ENCAP	0x04
282#define	UCDC_NCM_CAP_MAX_DATA	0x08
283#define	UCDC_NCM_CAP_CRCMODE	0x10
284#define	UCDC_NCM_CAP_MAX_DGRAM	0x20
285} __packed;
286
287/* Communications interface specific class request codes */
288
289#define	UCDC_NCM_SET_ETHERNET_MULTICAST_FILTERS			0x40
290#define	UCDC_NCM_SET_ETHERNET_POWER_MGMT_PATTERN_FILTER		0x41
291#define	UCDC_NCM_GET_ETHERNET_POWER_MGMT_PATTERN_FILTER		0x42
292#define	UCDC_NCM_SET_ETHERNET_PACKET_FILTER			0x43
293#define	UCDC_NCM_GET_ETHERNET_STATISTIC				0x44
294#define	UCDC_NCM_GET_NTB_PARAMETERS				0x80
295#define	UCDC_NCM_GET_NET_ADDRESS				0x81
296#define	UCDC_NCM_SET_NET_ADDRESS				0x82
297#define	UCDC_NCM_GET_NTB_FORMAT					0x83
298#define	UCDC_NCM_SET_NTB_FORMAT					0x84
299#define	UCDC_NCM_GET_NTB_INPUT_SIZE				0x85
300#define	UCDC_NCM_SET_NTB_INPUT_SIZE				0x86
301#define	UCDC_NCM_GET_MAX_DATAGRAM_SIZE				0x87
302#define	UCDC_NCM_SET_MAX_DATAGRAM_SIZE				0x88
303#define	UCDC_NCM_GET_CRC_MODE					0x89
304#define	UCDC_NCM_SET_CRC_MODE					0x8A
305
306struct usb_ncm_parameters {
307	uWord	wLength;
308	uWord	bmNtbFormatsSupported;
309#define	UCDC_NCM_FORMAT_NTB16	0x0001
310#define	UCDC_NCM_FORMAT_NTB32	0x0002
311	uDWord	dwNtbInMaxSize;
312	uWord	wNdpInDivisor;
313	uWord	wNdpInPayloadRemainder;
314	uWord	wNdpInAlignment;
315	uWord	wReserved14;
316	uDWord	dwNtbOutMaxSize;
317	uWord	wNdpOutDivisor;
318	uWord	wNdpOutPayloadRemainder;
319	uWord	wNdpOutAlignment;
320	uWord	wNtbOutMaxDatagrams;
321} __packed;
322
323/* Communications interface specific class notification codes */
324#define	UCDC_NCM_NOTIF_NETWORK_CONNECTION	0x00
325#define	UCDC_NCM_NOTIF_RESPONSE_AVAILABLE	0x01
326#define	UCDC_NCM_NOTIF_CONNECTION_SPEED_CHANGE	0x2A
327
328#endif					/* _USB_CDC_H_ */
329