blob: 2b39f6953da8ce7b8a248679bca01be5f97af970 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * USB Communications Device Class (CDC) definitions
3 *
4 * CDC says how to talk to lots of different types of network adapters,
5 * notably ethernet adapters and various modems. It's used mostly with
6 * firmware based USB peripherals.
7 */
8
Robert P. J. Daydda43a02008-03-07 13:45:32 -05009#ifndef __LINUX_USB_CDC_H
10#define __LINUX_USB_CDC_H
11
Jaswinder Singh Rajputd8151582009-01-30 20:15:47 +053012#include <linux/types.h>
13
Linus Torvalds1da177e2005-04-16 15:20:36 -070014#define USB_CDC_SUBCLASS_ACM 0x02
15#define USB_CDC_SUBCLASS_ETHERNET 0x06
16#define USB_CDC_SUBCLASS_WHCM 0x08
17#define USB_CDC_SUBCLASS_DMM 0x09
18#define USB_CDC_SUBCLASS_MDLM 0x0a
19#define USB_CDC_SUBCLASS_OBEX 0x0b
Omar Laazimani9f722c02009-05-04 12:01:43 -070020#define USB_CDC_SUBCLASS_EEM 0x0c
Yauheni Kaliuta01154aa2010-04-16 16:13:34 +030021#define USB_CDC_SUBCLASS_NCM 0x0d
Linus Torvalds1da177e2005-04-16 15:20:36 -070022
23#define USB_CDC_PROTO_NONE 0
24
25#define USB_CDC_ACM_PROTO_AT_V25TER 1
26#define USB_CDC_ACM_PROTO_AT_PCCA101 2
27#define USB_CDC_ACM_PROTO_AT_PCCA101_WAKE 3
28#define USB_CDC_ACM_PROTO_AT_GSM 4
29#define USB_CDC_ACM_PROTO_AT_3G 5
30#define USB_CDC_ACM_PROTO_AT_CDMA 6
31#define USB_CDC_ACM_PROTO_VENDOR 0xff
32
Omar Laazimani9f722c02009-05-04 12:01:43 -070033#define USB_CDC_PROTO_EEM 7
34
Yauheni Kaliutae5dcd532010-09-20 15:40:28 +030035#define USB_CDC_NCM_PROTO_NTB 1
36
Linus Torvalds1da177e2005-04-16 15:20:36 -070037/*-------------------------------------------------------------------------*/
38
39/*
40 * Class-Specific descriptors ... there are a couple dozen of them
41 */
42
Greg Kroah-Hartman41dceed2008-01-30 15:21:33 -080043#define USB_CDC_HEADER_TYPE 0x00 /* header_desc */
44#define USB_CDC_CALL_MANAGEMENT_TYPE 0x01 /* call_mgmt_descriptor */
45#define USB_CDC_ACM_TYPE 0x02 /* acm_descriptor */
46#define USB_CDC_UNION_TYPE 0x06 /* union_desc */
Linus Torvalds1da177e2005-04-16 15:20:36 -070047#define USB_CDC_COUNTRY_TYPE 0x07
Greg Kroah-Hartman41dceed2008-01-30 15:21:33 -080048#define USB_CDC_NETWORK_TERMINAL_TYPE 0x0a /* network_terminal_desc */
49#define USB_CDC_ETHERNET_TYPE 0x0f /* ether_desc */
Linus Torvalds1da177e2005-04-16 15:20:36 -070050#define USB_CDC_WHCM_TYPE 0x11
Greg Kroah-Hartman41dceed2008-01-30 15:21:33 -080051#define USB_CDC_MDLM_TYPE 0x12 /* mdlm_desc */
52#define USB_CDC_MDLM_DETAIL_TYPE 0x13 /* mdlm_detail_desc */
Linus Torvalds1da177e2005-04-16 15:20:36 -070053#define USB_CDC_DMM_TYPE 0x14
54#define USB_CDC_OBEX_TYPE 0x15
Yauheni Kaliuta01154aa2010-04-16 16:13:34 +030055#define USB_CDC_NCM_TYPE 0x1a
Anna Perela8c991d2012-04-09 16:44:46 +030056#define USB_CDC_MBB_TYPE 0x1b /* mbb_desc */
Linus Torvalds1da177e2005-04-16 15:20:36 -070057
58/* "Header Functional Descriptor" from CDC spec 5.2.3.1 */
59struct usb_cdc_header_desc {
60 __u8 bLength;
61 __u8 bDescriptorType;
62 __u8 bDescriptorSubType;
63
64 __le16 bcdCDC;
65} __attribute__ ((packed));
66
67/* "Call Management Descriptor" from CDC spec 5.2.3.2 */
68struct usb_cdc_call_mgmt_descriptor {
69 __u8 bLength;
70 __u8 bDescriptorType;
71 __u8 bDescriptorSubType;
72
73 __u8 bmCapabilities;
74#define USB_CDC_CALL_MGMT_CAP_CALL_MGMT 0x01
75#define USB_CDC_CALL_MGMT_CAP_DATA_INTF 0x02
76
77 __u8 bDataInterface;
78} __attribute__ ((packed));
79
80/* "Abstract Control Management Descriptor" from CDC spec 5.2.3.3 */
81struct usb_cdc_acm_descriptor {
82 __u8 bLength;
83 __u8 bDescriptorType;
84 __u8 bDescriptorSubType;
85
86 __u8 bmCapabilities;
87} __attribute__ ((packed));
88
Oliver Neukumca79b7b2007-02-12 08:41:35 +010089/* capabilities from 5.2.3.3 */
90
91#define USB_CDC_COMM_FEATURE 0x01
92#define USB_CDC_CAP_LINE 0x02
Alexey Orishko3a9dda72011-02-07 09:45:09 +000093#define USB_CDC_CAP_BRK 0x04
Oliver Neukumca79b7b2007-02-12 08:41:35 +010094#define USB_CDC_CAP_NOTIFY 0x08
95
Linus Torvalds1da177e2005-04-16 15:20:36 -070096/* "Union Functional Descriptor" from CDC spec 5.2.3.8 */
97struct usb_cdc_union_desc {
98 __u8 bLength;
99 __u8 bDescriptorType;
100 __u8 bDescriptorSubType;
101
102 __u8 bMasterInterface0;
103 __u8 bSlaveInterface0;
104 /* ... and there could be other slave interfaces */
105} __attribute__ ((packed));
106
Oliver Neukumbb747822007-02-27 11:30:24 +0100107/* "Country Selection Functional Descriptor" from CDC spec 5.2.3.9 */
108struct usb_cdc_country_functional_desc {
109 __u8 bLength;
110 __u8 bDescriptorType;
111 __u8 bDescriptorSubType;
112
113 __u8 iCountryCodeRelDate;
114 __le16 wCountyCode0;
115 /* ... and there can be a lot of country codes */
116} __attribute__ ((packed));
117
david-b@pacbell.net00ab9972005-06-29 07:04:14 -0700118/* "Network Channel Terminal Functional Descriptor" from CDC spec 5.2.3.11 */
119struct usb_cdc_network_terminal_desc {
120 __u8 bLength;
121 __u8 bDescriptorType;
122 __u8 bDescriptorSubType;
123
124 __u8 bEntityId;
125 __u8 iName;
126 __u8 bChannelIndex;
127 __u8 bPhysicalInterface;
128} __attribute__ ((packed));
129
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130/* "Ethernet Networking Functional Descriptor" from CDC spec 5.2.3.16 */
131struct usb_cdc_ether_desc {
132 __u8 bLength;
133 __u8 bDescriptorType;
134 __u8 bDescriptorSubType;
135
136 __u8 iMACAddress;
137 __le32 bmEthernetStatistics;
138 __le16 wMaxSegmentSize;
139 __le16 wNumberMCFilters;
140 __u8 bNumberPowerFilters;
141} __attribute__ ((packed));
142
Oliver Neukumafba9372008-05-13 17:01:25 +0200143/* "Telephone Control Model Functional Descriptor" from CDC WMC spec 6.3..3 */
144struct usb_cdc_dmm_desc {
145 __u8 bFunctionLength;
146 __u8 bDescriptorType;
147 __u8 bDescriptorSubtype;
148 __u16 bcdVersion;
149 __le16 wMaxCommand;
150} __attribute__ ((packed));
151
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152/* "MDLM Functional Descriptor" from CDC WMC spec 6.7.2.3 */
153struct usb_cdc_mdlm_desc {
154 __u8 bLength;
155 __u8 bDescriptorType;
156 __u8 bDescriptorSubType;
157
158 __le16 bcdVersion;
159 __u8 bGUID[16];
160} __attribute__ ((packed));
161
162/* "MDLM Detail Functional Descriptor" from CDC WMC spec 6.7.2.4 */
163struct usb_cdc_mdlm_detail_desc {
164 __u8 bLength;
165 __u8 bDescriptorType;
166 __u8 bDescriptorSubType;
167
168 /* type is associated with mdlm_desc.bGUID */
169 __u8 bGuidDescriptorType;
akpm@osdl.org84d79cb2005-04-18 17:39:21 -0700170 __u8 bDetailData[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171} __attribute__ ((packed));
172
Felipe Balbi30867752008-08-18 17:39:30 -0700173/* "OBEX Control Model Functional Descriptor" */
174struct usb_cdc_obex_desc {
175 __u8 bLength;
176 __u8 bDescriptorType;
177 __u8 bDescriptorSubType;
178
179 __le16 bcdVersion;
180} __attribute__ ((packed));
181
Yauheni Kaliuta01154aa2010-04-16 16:13:34 +0300182/* "NCM Control Model Functional Descriptor" */
183struct usb_cdc_ncm_desc {
184 __u8 bLength;
185 __u8 bDescriptorType;
186 __u8 bDescriptorSubType;
187
188 __le16 bcdNcmVersion;
189 __u8 bmNetworkCapabilities;
190} __attribute__ ((packed));
Anna Perela8c991d2012-04-09 16:44:46 +0300191
192/* "MBIM Functional Descriptor" */
193struct usb_cdc_mbb_desc {
194 __u8 bLength;
195 __u8 bDescriptorType;
196 __u8 bDescriptorSubType;
197
198 __le16 bcdMbbVersion;
199 __le16 wMaxControlMessage;
200 __u8 bNumberFilters;
201 __u8 bMaxFilterSize;
202 __le16 wMaxSegmentSize;
203 __u8 bmNetworkCapabilities;
204} __packed;
205
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206/*-------------------------------------------------------------------------*/
207
208/*
209 * Class-Specific Control Requests (6.2)
210 *
211 * section 3.6.2.1 table 4 has the ACM profile, for modems.
212 * section 3.8.2 table 10 has the ethernet profile.
213 *
214 * Microsoft's RNDIS stack for Ethernet is a vendor-specific CDC ACM variant,
215 * heavily dependent on the encapsulated (proprietary) command mechanism.
216 */
217
218#define USB_CDC_SEND_ENCAPSULATED_COMMAND 0x00
219#define USB_CDC_GET_ENCAPSULATED_RESPONSE 0x01
Anna Perela8c991d2012-04-09 16:44:46 +0300220#define USB_CDC_RESET_FUNCTION 0x05
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221#define USB_CDC_REQ_SET_LINE_CODING 0x20
222#define USB_CDC_REQ_GET_LINE_CODING 0x21
223#define USB_CDC_REQ_SET_CONTROL_LINE_STATE 0x22
224#define USB_CDC_REQ_SEND_BREAK 0x23
225#define USB_CDC_SET_ETHERNET_MULTICAST_FILTERS 0x40
226#define USB_CDC_SET_ETHERNET_PM_PATTERN_FILTER 0x41
227#define USB_CDC_GET_ETHERNET_PM_PATTERN_FILTER 0x42
228#define USB_CDC_SET_ETHERNET_PACKET_FILTER 0x43
229#define USB_CDC_GET_ETHERNET_STATISTIC 0x44
Yauheni Kaliuta01154aa2010-04-16 16:13:34 +0300230#define USB_CDC_GET_NTB_PARAMETERS 0x80
231#define USB_CDC_GET_NET_ADDRESS 0x81
232#define USB_CDC_SET_NET_ADDRESS 0x82
233#define USB_CDC_GET_NTB_FORMAT 0x83
234#define USB_CDC_SET_NTB_FORMAT 0x84
235#define USB_CDC_GET_NTB_INPUT_SIZE 0x85
236#define USB_CDC_SET_NTB_INPUT_SIZE 0x86
237#define USB_CDC_GET_MAX_DATAGRAM_SIZE 0x87
238#define USB_CDC_SET_MAX_DATAGRAM_SIZE 0x88
239#define USB_CDC_GET_CRC_MODE 0x89
240#define USB_CDC_SET_CRC_MODE 0x8a
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241
242/* Line Coding Structure from CDC spec 6.2.13 */
243struct usb_cdc_line_coding {
244 __le32 dwDTERate;
245 __u8 bCharFormat;
246#define USB_CDC_1_STOP_BITS 0
247#define USB_CDC_1_5_STOP_BITS 1
248#define USB_CDC_2_STOP_BITS 2
249
250 __u8 bParityType;
251#define USB_CDC_NO_PARITY 0
252#define USB_CDC_ODD_PARITY 1
253#define USB_CDC_EVEN_PARITY 2
254#define USB_CDC_MARK_PARITY 3
255#define USB_CDC_SPACE_PARITY 4
256
257 __u8 bDataBits;
258} __attribute__ ((packed));
259
260/* table 62; bits in multicast filter */
261#define USB_CDC_PACKET_TYPE_PROMISCUOUS (1 << 0)
262#define USB_CDC_PACKET_TYPE_ALL_MULTICAST (1 << 1) /* no filter */
263#define USB_CDC_PACKET_TYPE_DIRECTED (1 << 2)
264#define USB_CDC_PACKET_TYPE_BROADCAST (1 << 3)
265#define USB_CDC_PACKET_TYPE_MULTICAST (1 << 4) /* filtered */
266
267
268/*-------------------------------------------------------------------------*/
269
270/*
271 * Class-Specific Notifications (6.3) sent by interrupt transfers
272 *
273 * section 3.8.2 table 11 of the CDC spec lists Ethernet notifications
274 * section 3.6.2.1 table 5 specifies ACM notifications, accepted by RNDIS
275 * RNDIS also defines its own bit-incompatible notifications
276 */
277
278#define USB_CDC_NOTIFY_NETWORK_CONNECTION 0x00
279#define USB_CDC_NOTIFY_RESPONSE_AVAILABLE 0x01
280#define USB_CDC_NOTIFY_SERIAL_STATE 0x20
281#define USB_CDC_NOTIFY_SPEED_CHANGE 0x2a
282
283struct usb_cdc_notification {
284 __u8 bmRequestType;
285 __u8 bNotificationType;
286 __le16 wValue;
287 __le16 wIndex;
288 __le16 wLength;
289} __attribute__ ((packed));
290
Alexey Orishko3a9dda72011-02-07 09:45:09 +0000291struct usb_cdc_speed_change {
292 __le32 DLBitRRate; /* contains the downlink bit rate (IN pipe) */
293 __le32 ULBitRate; /* contains the uplink bit rate (OUT pipe) */
294} __attribute__ ((packed));
295
Yauheni Kaliuta01154aa2010-04-16 16:13:34 +0300296/*-------------------------------------------------------------------------*/
297
298/*
299 * Class Specific structures and constants
300 *
Yauheni Kaliuta1f53c0e2010-09-20 15:40:26 +0300301 * CDC NCM NTB parameters structure, CDC NCM subclass 6.2.1
Yauheni Kaliuta01154aa2010-04-16 16:13:34 +0300302 *
303 */
304
Yauheni Kaliuta1f53c0e2010-09-20 15:40:26 +0300305struct usb_cdc_ncm_ntb_parameters {
Yauheni Kaliuta01154aa2010-04-16 16:13:34 +0300306 __le16 wLength;
Yauheni Kaliuta1f53c0e2010-09-20 15:40:26 +0300307 __le16 bmNtbFormatsSupported;
Yauheni Kaliuta01154aa2010-04-16 16:13:34 +0300308 __le32 dwNtbInMaxSize;
309 __le16 wNdpInDivisor;
310 __le16 wNdpInPayloadRemainder;
311 __le16 wNdpInAlignment;
312 __le16 wPadding1;
313 __le32 dwNtbOutMaxSize;
314 __le16 wNdpOutDivisor;
315 __le16 wNdpOutPayloadRemainder;
316 __le16 wNdpOutAlignment;
Alexey Orishko3a9dda72011-02-07 09:45:09 +0000317 __le16 wNtbOutMaxDatagrams;
Yauheni Kaliuta01154aa2010-04-16 16:13:34 +0300318} __attribute__ ((packed));
319
320/*
321 * CDC NCM transfer headers, CDC NCM subclass 3.2
322 */
323
Yauheni Kaliuta1f53c0e2010-09-20 15:40:26 +0300324#define USB_CDC_NCM_NTH16_SIGN 0x484D434E /* NCMH */
325#define USB_CDC_NCM_NTH32_SIGN 0x686D636E /* ncmh */
Yauheni Kaliuta01154aa2010-04-16 16:13:34 +0300326
327struct usb_cdc_ncm_nth16 {
328 __le32 dwSignature;
329 __le16 wHeaderLength;
330 __le16 wSequence;
331 __le16 wBlockLength;
Alexey Orishko3a9dda72011-02-07 09:45:09 +0000332 __le16 wNdpIndex;
Yauheni Kaliuta01154aa2010-04-16 16:13:34 +0300333} __attribute__ ((packed));
334
335struct usb_cdc_ncm_nth32 {
336 __le32 dwSignature;
337 __le16 wHeaderLength;
338 __le16 wSequence;
339 __le32 dwBlockLength;
Alexey Orishko3a9dda72011-02-07 09:45:09 +0000340 __le32 dwNdpIndex;
Yauheni Kaliuta01154aa2010-04-16 16:13:34 +0300341} __attribute__ ((packed));
342
343/*
344 * CDC NCM datagram pointers, CDC NCM subclass 3.3
345 */
346
Yauheni Kaliuta1f53c0e2010-09-20 15:40:26 +0300347#define USB_CDC_NCM_NDP16_CRC_SIGN 0x314D434E /* NCM1 */
348#define USB_CDC_NCM_NDP16_NOCRC_SIGN 0x304D434E /* NCM0 */
349#define USB_CDC_NCM_NDP32_CRC_SIGN 0x316D636E /* ncm1 */
350#define USB_CDC_NCM_NDP32_NOCRC_SIGN 0x306D636E /* ncm0 */
Yauheni Kaliuta01154aa2010-04-16 16:13:34 +0300351
Yauheni Kaliutae5dcd532010-09-20 15:40:28 +0300352/* 16-bit NCM Datagram Pointer Entry */
353struct usb_cdc_ncm_dpe16 {
354 __le16 wDatagramIndex;
355 __le16 wDatagramLength;
356} __attribute__((__packed__));
357
Yauheni Kaliuta1f53c0e2010-09-20 15:40:26 +0300358/* 16-bit NCM Datagram Pointer Table */
Yauheni Kaliuta01154aa2010-04-16 16:13:34 +0300359struct usb_cdc_ncm_ndp16 {
360 __le32 dwSignature;
361 __le16 wLength;
Alexey Orishko3a9dda72011-02-07 09:45:09 +0000362 __le16 wNextNdpIndex;
Yauheni Kaliutae5dcd532010-09-20 15:40:28 +0300363 struct usb_cdc_ncm_dpe16 dpe16[0];
Yauheni Kaliuta01154aa2010-04-16 16:13:34 +0300364} __attribute__ ((packed));
365
Yauheni Kaliutae5dcd532010-09-20 15:40:28 +0300366/* 32-bit NCM Datagram Pointer Entry */
367struct usb_cdc_ncm_dpe32 {
Yauheni Kaliuta6195e3c2010-09-24 09:43:27 +0300368 __le32 dwDatagramIndex;
369 __le32 dwDatagramLength;
Yauheni Kaliutae5dcd532010-09-20 15:40:28 +0300370} __attribute__((__packed__));
371
Yauheni Kaliuta1f53c0e2010-09-20 15:40:26 +0300372/* 32-bit NCM Datagram Pointer Table */
Yauheni Kaliuta01154aa2010-04-16 16:13:34 +0300373struct usb_cdc_ncm_ndp32 {
374 __le32 dwSignature;
375 __le16 wLength;
376 __le16 wReserved6;
Yauheni Kaliuta1f53c0e2010-09-20 15:40:26 +0300377 __le32 dwNextNdpIndex;
Yauheni Kaliuta01154aa2010-04-16 16:13:34 +0300378 __le32 dwReserved12;
Yauheni Kaliutae5dcd532010-09-20 15:40:28 +0300379 struct usb_cdc_ncm_dpe32 dpe32[0];
Yauheni Kaliuta01154aa2010-04-16 16:13:34 +0300380} __attribute__ ((packed));
381
Yauheni Kaliutae5dcd532010-09-20 15:40:28 +0300382/* CDC NCM subclass 3.2.1 and 3.2.2 */
383#define USB_CDC_NCM_NDP16_INDEX_MIN 0x000C
384#define USB_CDC_NCM_NDP32_INDEX_MIN 0x0010
385
386/* CDC NCM subclass 3.3.3 Datagram Formatting */
387#define USB_CDC_NCM_DATAGRAM_FORMAT_CRC 0x30
388#define USB_CDC_NCM_DATAGRAM_FORMAT_NOCRC 0X31
389
390/* CDC NCM subclass 4.2 NCM Communications Interface Protocol Code */
391#define USB_CDC_NCM_PROTO_CODE_NO_ENCAP_COMMANDS 0x00
392#define USB_CDC_NCM_PROTO_CODE_EXTERN_PROTO 0xFE
393
394/* CDC NCM subclass 5.2.1 NCM Functional Descriptor, bmNetworkCapabilities */
395#define USB_CDC_NCM_NCAP_ETH_FILTER (1 << 0)
396#define USB_CDC_NCM_NCAP_NET_ADDRESS (1 << 1)
397#define USB_CDC_NCM_NCAP_ENCAP_COMMAND (1 << 2)
398#define USB_CDC_NCM_NCAP_MAX_DATAGRAM_SIZE (1 << 3)
399#define USB_CDC_NCM_NCAP_CRC_MODE (1 << 4)
Alexey Orishko3a9dda72011-02-07 09:45:09 +0000400#define USB_CDC_NCM_NCAP_NTB_INPUT_SIZE (1 << 5)
Yauheni Kaliutae5dcd532010-09-20 15:40:28 +0300401
402/* CDC NCM subclass Table 6-3: NTB Parameter Structure */
403#define USB_CDC_NCM_NTB16_SUPPORTED (1 << 0)
404#define USB_CDC_NCM_NTB32_SUPPORTED (1 << 1)
405
406/* CDC NCM subclass Table 6-3: NTB Parameter Structure */
407#define USB_CDC_NCM_NDP_ALIGN_MIN_SIZE 0x04
408#define USB_CDC_NCM_NTB_MAX_LENGTH 0x1C
409
410/* CDC NCM subclass 6.2.5 SetNtbFormat */
411#define USB_CDC_NCM_NTB16_FORMAT 0x00
412#define USB_CDC_NCM_NTB32_FORMAT 0x01
413
414/* CDC NCM subclass 6.2.7 SetNtbInputSize */
415#define USB_CDC_NCM_NTB_MIN_IN_SIZE 2048
416#define USB_CDC_NCM_NTB_MIN_OUT_SIZE 2048
417
Alexey Orishko3a9dda72011-02-07 09:45:09 +0000418/* NTB Input Size Structure */
419struct usb_cdc_ncm_ndp_input_size {
420 __le32 dwNtbInMaxSize;
421 __le16 wNtbInMaxDatagrams;
422 __le16 wReserved;
423} __attribute__ ((packed));
424
Yauheni Kaliutae5dcd532010-09-20 15:40:28 +0300425/* CDC NCM subclass 6.2.11 SetCrcMode */
426#define USB_CDC_NCM_CRC_NOT_APPENDED 0x00
427#define USB_CDC_NCM_CRC_APPENDED 0x01
428
Robert P. J. Daydda43a02008-03-07 13:45:32 -0500429#endif /* __LINUX_USB_CDC_H */