xref: /freebsd/sys/dev/usb/usb_cdc.h (revision 207332450ebe1df184818ab11115dcd7b95a5bc5)
102ac6454SAndrew Thompson /*	$NetBSD: usbcdc.h,v 1.9 2004/10/23 13:24:24 augustss Exp $	*/
202ac6454SAndrew Thompson /*	$FreeBSD$	*/
302ac6454SAndrew Thompson 
402ac6454SAndrew Thompson /*-
502ac6454SAndrew Thompson  * Copyright (c) 1998 The NetBSD Foundation, Inc.
602ac6454SAndrew Thompson  * All rights reserved.
702ac6454SAndrew Thompson  *
802ac6454SAndrew Thompson  * This code is derived from software contributed to The NetBSD Foundation
902ac6454SAndrew Thompson  * by Lennart Augustsson (lennart@augustsson.net) at
1002ac6454SAndrew Thompson  * Carlstedt Research & Technology.
1102ac6454SAndrew Thompson  *
1202ac6454SAndrew Thompson  * Redistribution and use in source and binary forms, with or without
1302ac6454SAndrew Thompson  * modification, are permitted provided that the following conditions
1402ac6454SAndrew Thompson  * are met:
1502ac6454SAndrew Thompson  * 1. Redistributions of source code must retain the above copyright
1602ac6454SAndrew Thompson  *    notice, this list of conditions and the following disclaimer.
1702ac6454SAndrew Thompson  * 2. Redistributions in binary form must reproduce the above copyright
1802ac6454SAndrew Thompson  *    notice, this list of conditions and the following disclaimer in the
1902ac6454SAndrew Thompson  *    documentation and/or other materials provided with the distribution.
2002ac6454SAndrew Thompson  *
2102ac6454SAndrew Thompson  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
2202ac6454SAndrew Thompson  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
2302ac6454SAndrew Thompson  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
2402ac6454SAndrew Thompson  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
2502ac6454SAndrew Thompson  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2602ac6454SAndrew Thompson  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2702ac6454SAndrew Thompson  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2802ac6454SAndrew Thompson  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2902ac6454SAndrew Thompson  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
3002ac6454SAndrew Thompson  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
3102ac6454SAndrew Thompson  * POSSIBILITY OF SUCH DAMAGE.
3202ac6454SAndrew Thompson  */
3302ac6454SAndrew Thompson 
3402ac6454SAndrew Thompson #ifndef _USB_CDC_H_
3502ac6454SAndrew Thompson #define	_USB_CDC_H_
3602ac6454SAndrew Thompson 
3702ac6454SAndrew Thompson #define	UDESCSUB_CDC_HEADER	0
3802ac6454SAndrew Thompson #define	UDESCSUB_CDC_CM		1	/* Call Management */
3902ac6454SAndrew Thompson #define	UDESCSUB_CDC_ACM	2	/* Abstract Control Model */
4002ac6454SAndrew Thompson #define	UDESCSUB_CDC_DLM	3	/* Direct Line Management */
4102ac6454SAndrew Thompson #define	UDESCSUB_CDC_TRF	4	/* Telephone Ringer */
4202ac6454SAndrew Thompson #define	UDESCSUB_CDC_TCLSR	5	/* Telephone Call */
4302ac6454SAndrew Thompson #define	UDESCSUB_CDC_UNION	6
4402ac6454SAndrew Thompson #define	UDESCSUB_CDC_CS		7	/* Country Selection */
4502ac6454SAndrew Thompson #define	UDESCSUB_CDC_TOM	8	/* Telephone Operational Modes */
4602ac6454SAndrew Thompson #define	UDESCSUB_CDC_USBT	9	/* USB Terminal */
4702ac6454SAndrew Thompson #define	UDESCSUB_CDC_NCT	10
4802ac6454SAndrew Thompson #define	UDESCSUB_CDC_PUF	11
4902ac6454SAndrew Thompson #define	UDESCSUB_CDC_EUF	12
5002ac6454SAndrew Thompson #define	UDESCSUB_CDC_MCMF	13
5102ac6454SAndrew Thompson #define	UDESCSUB_CDC_CCMF	14
5202ac6454SAndrew Thompson #define	UDESCSUB_CDC_ENF	15
5302ac6454SAndrew Thompson #define	UDESCSUB_CDC_ANF	16
5402ac6454SAndrew Thompson 
55760bc48eSAndrew Thompson struct usb_cdc_header_descriptor {
5602ac6454SAndrew Thompson 	uByte	bLength;
5702ac6454SAndrew Thompson 	uByte	bDescriptorType;
5802ac6454SAndrew Thompson 	uByte	bDescriptorSubtype;
5902ac6454SAndrew Thompson 	uWord	bcdCDC;
6002ac6454SAndrew Thompson } __packed;
6102ac6454SAndrew Thompson 
62760bc48eSAndrew Thompson struct usb_cdc_cm_descriptor {
6302ac6454SAndrew Thompson 	uByte	bLength;
6402ac6454SAndrew Thompson 	uByte	bDescriptorType;
6502ac6454SAndrew Thompson 	uByte	bDescriptorSubtype;
6602ac6454SAndrew Thompson 	uByte	bmCapabilities;
6702ac6454SAndrew Thompson #define	USB_CDC_CM_DOES_CM		0x01
6802ac6454SAndrew Thompson #define	USB_CDC_CM_OVER_DATA		0x02
6902ac6454SAndrew Thompson 	uByte	bDataInterface;
7002ac6454SAndrew Thompson } __packed;
7102ac6454SAndrew Thompson 
72760bc48eSAndrew Thompson struct usb_cdc_acm_descriptor {
7302ac6454SAndrew Thompson 	uByte	bLength;
7402ac6454SAndrew Thompson 	uByte	bDescriptorType;
7502ac6454SAndrew Thompson 	uByte	bDescriptorSubtype;
7602ac6454SAndrew Thompson 	uByte	bmCapabilities;
7702ac6454SAndrew Thompson #define	USB_CDC_ACM_HAS_FEATURE		0x01
7802ac6454SAndrew Thompson #define	USB_CDC_ACM_HAS_LINE		0x02
7902ac6454SAndrew Thompson #define	USB_CDC_ACM_HAS_BREAK		0x04
8002ac6454SAndrew Thompson #define	USB_CDC_ACM_HAS_NETWORK_CONN	0x08
8102ac6454SAndrew Thompson } __packed;
8202ac6454SAndrew Thompson 
83760bc48eSAndrew Thompson struct usb_cdc_union_descriptor {
8402ac6454SAndrew Thompson 	uByte	bLength;
8502ac6454SAndrew Thompson 	uByte	bDescriptorType;
8602ac6454SAndrew Thompson 	uByte	bDescriptorSubtype;
8702ac6454SAndrew Thompson 	uByte	bMasterInterface;
8802ac6454SAndrew Thompson 	uByte	bSlaveInterface[1];
8902ac6454SAndrew Thompson } __packed;
9002ac6454SAndrew Thompson 
91760bc48eSAndrew Thompson struct usb_cdc_ethernet_descriptor {
9202ac6454SAndrew Thompson 	uByte	bLength;
9302ac6454SAndrew Thompson 	uByte	bDescriptorType;
9402ac6454SAndrew Thompson 	uByte	bDescriptorSubtype;
9502ac6454SAndrew Thompson 	uByte	iMacAddress;
9602ac6454SAndrew Thompson 	uDWord	bmEthernetStatistics;
9702ac6454SAndrew Thompson 	uWord	wMaxSegmentSize;
9802ac6454SAndrew Thompson 	uWord	wNumberMCFilters;
9902ac6454SAndrew Thompson 	uByte	bNumberPowerFilters;
10002ac6454SAndrew Thompson } __packed;
10102ac6454SAndrew Thompson 
10202ac6454SAndrew Thompson #define	UCDC_SEND_ENCAPSULATED_COMMAND	0x00
10302ac6454SAndrew Thompson #define	UCDC_GET_ENCAPSULATED_RESPONSE	0x01
10402ac6454SAndrew Thompson #define	UCDC_SET_COMM_FEATURE		0x02
10502ac6454SAndrew Thompson #define	UCDC_GET_COMM_FEATURE		0x03
10602ac6454SAndrew Thompson #define	UCDC_ABSTRACT_STATE		0x01
10702ac6454SAndrew Thompson #define	UCDC_COUNTRY_SETTING		0x02
10802ac6454SAndrew Thompson #define	UCDC_CLEAR_COMM_FEATURE		0x04
10902ac6454SAndrew Thompson #define	UCDC_SET_LINE_CODING		0x20
11002ac6454SAndrew Thompson #define	UCDC_GET_LINE_CODING		0x21
11102ac6454SAndrew Thompson #define	UCDC_SET_CONTROL_LINE_STATE	0x22
11202ac6454SAndrew Thompson #define	UCDC_LINE_DTR			0x0001
11302ac6454SAndrew Thompson #define	UCDC_LINE_RTS			0x0002
11402ac6454SAndrew Thompson #define	UCDC_SEND_BREAK			0x23
11502ac6454SAndrew Thompson #define	UCDC_BREAK_ON			0xffff
11602ac6454SAndrew Thompson #define	UCDC_BREAK_OFF			0x0000
11702ac6454SAndrew Thompson 
118760bc48eSAndrew Thompson struct usb_cdc_abstract_state {
11902ac6454SAndrew Thompson 	uWord	wState;
12002ac6454SAndrew Thompson #define	UCDC_IDLE_SETTING		0x0001
12102ac6454SAndrew Thompson #define	UCDC_DATA_MULTIPLEXED		0x0002
12202ac6454SAndrew Thompson } __packed;
12302ac6454SAndrew Thompson 
12402ac6454SAndrew Thompson #define	UCDC_ABSTRACT_STATE_LENGTH	2
12502ac6454SAndrew Thompson 
126760bc48eSAndrew Thompson struct usb_cdc_line_state {
12702ac6454SAndrew Thompson 	uDWord	dwDTERate;
12802ac6454SAndrew Thompson 	uByte	bCharFormat;
12902ac6454SAndrew Thompson #define	UCDC_STOP_BIT_1			0
13002ac6454SAndrew Thompson #define	UCDC_STOP_BIT_1_5		1
13102ac6454SAndrew Thompson #define	UCDC_STOP_BIT_2			2
13202ac6454SAndrew Thompson 	uByte	bParityType;
13302ac6454SAndrew Thompson #define	UCDC_PARITY_NONE		0
13402ac6454SAndrew Thompson #define	UCDC_PARITY_ODD			1
13502ac6454SAndrew Thompson #define	UCDC_PARITY_EVEN		2
13602ac6454SAndrew Thompson #define	UCDC_PARITY_MARK		3
13702ac6454SAndrew Thompson #define	UCDC_PARITY_SPACE		4
13802ac6454SAndrew Thompson 	uByte	bDataBits;
13902ac6454SAndrew Thompson } __packed;
14002ac6454SAndrew Thompson 
14102ac6454SAndrew Thompson #define	UCDC_LINE_STATE_LENGTH		7
14202ac6454SAndrew Thompson 
143760bc48eSAndrew Thompson struct usb_cdc_notification {
14402ac6454SAndrew Thompson 	uByte	bmRequestType;
14502ac6454SAndrew Thompson #define	UCDC_NOTIFICATION		0xa1
14602ac6454SAndrew Thompson 	uByte	bNotification;
14702ac6454SAndrew Thompson #define	UCDC_N_NETWORK_CONNECTION	0x00
14802ac6454SAndrew Thompson #define	UCDC_N_RESPONSE_AVAILABLE	0x01
14902ac6454SAndrew Thompson #define	UCDC_N_AUX_JACK_HOOK_STATE	0x08
15002ac6454SAndrew Thompson #define	UCDC_N_RING_DETECT		0x09
15102ac6454SAndrew Thompson #define	UCDC_N_SERIAL_STATE		0x20
15202ac6454SAndrew Thompson #define	UCDC_N_CALL_STATE_CHANGED	0x28
15302ac6454SAndrew Thompson #define	UCDC_N_LINE_STATE_CHANGED	0x29
15402ac6454SAndrew Thompson #define	UCDC_N_CONNECTION_SPEED_CHANGE	0x2a
15502ac6454SAndrew Thompson 	uWord	wValue;
15602ac6454SAndrew Thompson 	uWord	wIndex;
15702ac6454SAndrew Thompson 	uWord	wLength;
15802ac6454SAndrew Thompson 	uByte	data[16];
15902ac6454SAndrew Thompson } __packed;
16002ac6454SAndrew Thompson 
16102ac6454SAndrew Thompson #define	UCDC_NOTIFICATION_LENGTH	8
16202ac6454SAndrew Thompson 
16302ac6454SAndrew Thompson /*
164*20733245SPedro F. Giffuni  * Bits set in the SERIAL STATE notification (first byte of data)
16502ac6454SAndrew Thompson  */
16602ac6454SAndrew Thompson 
16702ac6454SAndrew Thompson #define	UCDC_N_SERIAL_OVERRUN		0x40
16802ac6454SAndrew Thompson #define	UCDC_N_SERIAL_PARITY		0x20
16902ac6454SAndrew Thompson #define	UCDC_N_SERIAL_FRAMING		0x10
17002ac6454SAndrew Thompson #define	UCDC_N_SERIAL_RI		0x08
17102ac6454SAndrew Thompson #define	UCDC_N_SERIAL_BREAK		0x04
17202ac6454SAndrew Thompson #define	UCDC_N_SERIAL_DSR		0x02
17302ac6454SAndrew Thompson #define	UCDC_N_SERIAL_DCD		0x01
17402ac6454SAndrew Thompson 
17502ac6454SAndrew Thompson /* Serial state bit masks */
17602ac6454SAndrew Thompson #define	UCDC_MDM_RXCARRIER		0x01
17702ac6454SAndrew Thompson #define	UCDC_MDM_TXCARRIER		0x02
17802ac6454SAndrew Thompson #define	UCDC_MDM_BREAK			0x04
17902ac6454SAndrew Thompson #define	UCDC_MDM_RING			0x08
18002ac6454SAndrew Thompson #define	UCDC_MDM_FRAMING_ERR		0x10
18102ac6454SAndrew Thompson #define	UCDC_MDM_PARITY_ERR		0x20
18202ac6454SAndrew Thompson #define	UCDC_MDM_OVERRUN_ERR		0x40
18302ac6454SAndrew Thompson 
1844076dd23SAndrew Thompson /*
1854076dd23SAndrew Thompson  * Network Control Model, NCM16 + NCM32, protocol definitions
1864076dd23SAndrew Thompson  */
1874076dd23SAndrew Thompson struct usb_ncm16_hdr {
1884076dd23SAndrew Thompson 	uDWord	dwSignature;
1894076dd23SAndrew Thompson 	uWord	wHeaderLength;
1904076dd23SAndrew Thompson 	uWord	wSequence;
1914076dd23SAndrew Thompson 	uWord	wBlockLength;
1924076dd23SAndrew Thompson 	uWord	wDptIndex;
1934076dd23SAndrew Thompson } __packed;
1944076dd23SAndrew Thompson 
1954076dd23SAndrew Thompson struct usb_ncm16_dp {
1964076dd23SAndrew Thompson 	uWord	wFrameIndex;
1974076dd23SAndrew Thompson 	uWord	wFrameLength;
1984076dd23SAndrew Thompson } __packed;
1994076dd23SAndrew Thompson 
2004076dd23SAndrew Thompson struct usb_ncm16_dpt {
2014076dd23SAndrew Thompson 	uDWord	dwSignature;
2024076dd23SAndrew Thompson 	uWord	wLength;
2034076dd23SAndrew Thompson 	uWord	wNextNdpIndex;
2044076dd23SAndrew Thompson 	struct usb_ncm16_dp dp[0];
2054076dd23SAndrew Thompson } __packed;
2064076dd23SAndrew Thompson 
2074076dd23SAndrew Thompson struct usb_ncm32_hdr {
2084076dd23SAndrew Thompson 	uDWord	dwSignature;
2094076dd23SAndrew Thompson 	uWord	wHeaderLength;
2104076dd23SAndrew Thompson 	uWord	wSequence;
2114076dd23SAndrew Thompson 	uDWord	dwBlockLength;
2124076dd23SAndrew Thompson 	uDWord	dwDptIndex;
2134076dd23SAndrew Thompson } __packed;
2144076dd23SAndrew Thompson 
2154076dd23SAndrew Thompson struct usb_ncm32_dp {
2164076dd23SAndrew Thompson 	uDWord	dwFrameIndex;
2174076dd23SAndrew Thompson 	uDWord	dwFrameLength;
2184076dd23SAndrew Thompson } __packed;
2194076dd23SAndrew Thompson 
2204076dd23SAndrew Thompson struct usb_ncm32_dpt {
2214076dd23SAndrew Thompson 	uDWord	dwSignature;
2224076dd23SAndrew Thompson 	uWord	wLength;
2234076dd23SAndrew Thompson 	uWord	wReserved6;
2244076dd23SAndrew Thompson 	uDWord	dwNextNdpIndex;
2254076dd23SAndrew Thompson 	uDWord	dwReserved12;
2264076dd23SAndrew Thompson 	struct usb_ncm32_dp dp[0];
2274076dd23SAndrew Thompson } __packed;
2284076dd23SAndrew Thompson 
2294076dd23SAndrew Thompson /* Communications interface class specific descriptors */
2304076dd23SAndrew Thompson 
2314076dd23SAndrew Thompson #define	UCDC_NCM_FUNC_DESC_SUBTYPE	0x1A
2324076dd23SAndrew Thompson 
2334076dd23SAndrew Thompson struct usb_ncm_func_descriptor {
2344076dd23SAndrew Thompson 	uByte	bLength;
2354076dd23SAndrew Thompson 	uByte	bDescriptorType;
2364076dd23SAndrew Thompson 	uByte	bDescriptorSubtype;
2374076dd23SAndrew Thompson 	uByte	bcdNcmVersion[2];
2384076dd23SAndrew Thompson 	uByte	bmNetworkCapabilities;
2394076dd23SAndrew Thompson #define	UCDC_NCM_CAP_FILTER	0x01
2404076dd23SAndrew Thompson #define	UCDC_NCM_CAP_MAC_ADDR	0x02
2414076dd23SAndrew Thompson #define	UCDC_NCM_CAP_ENCAP	0x04
2424076dd23SAndrew Thompson #define	UCDC_NCM_CAP_MAX_DATA	0x08
2434076dd23SAndrew Thompson #define	UCDC_NCM_CAP_CRCMODE	0x10
2447e05daaeSHans Petter Selasky #define	UCDC_NCM_CAP_MAX_DGRAM	0x20
2454076dd23SAndrew Thompson } __packed;
2464076dd23SAndrew Thompson 
2474076dd23SAndrew Thompson /* Communications interface specific class request codes */
2484076dd23SAndrew Thompson 
2494076dd23SAndrew Thompson #define	UCDC_NCM_SET_ETHERNET_MULTICAST_FILTERS			0x40
2504076dd23SAndrew Thompson #define	UCDC_NCM_SET_ETHERNET_POWER_MGMT_PATTERN_FILTER		0x41
2514076dd23SAndrew Thompson #define	UCDC_NCM_GET_ETHERNET_POWER_MGMT_PATTERN_FILTER		0x42
2524076dd23SAndrew Thompson #define	UCDC_NCM_SET_ETHERNET_PACKET_FILTER			0x43
2534076dd23SAndrew Thompson #define	UCDC_NCM_GET_ETHERNET_STATISTIC				0x44
2544076dd23SAndrew Thompson #define	UCDC_NCM_GET_NTB_PARAMETERS				0x80
2554076dd23SAndrew Thompson #define	UCDC_NCM_GET_NET_ADDRESS				0x81
2564076dd23SAndrew Thompson #define	UCDC_NCM_SET_NET_ADDRESS				0x82
2574076dd23SAndrew Thompson #define	UCDC_NCM_GET_NTB_FORMAT					0x83
2584076dd23SAndrew Thompson #define	UCDC_NCM_SET_NTB_FORMAT					0x84
2594076dd23SAndrew Thompson #define	UCDC_NCM_GET_NTB_INPUT_SIZE				0x85
2604076dd23SAndrew Thompson #define	UCDC_NCM_SET_NTB_INPUT_SIZE				0x86
2614076dd23SAndrew Thompson #define	UCDC_NCM_GET_MAX_DATAGRAM_SIZE				0x87
2624076dd23SAndrew Thompson #define	UCDC_NCM_SET_MAX_DATAGRAM_SIZE				0x88
2634076dd23SAndrew Thompson #define	UCDC_NCM_GET_CRC_MODE					0x89
2644076dd23SAndrew Thompson #define	UCDC_NCM_SET_CRC_MODE					0x8A
2654076dd23SAndrew Thompson 
2664076dd23SAndrew Thompson struct usb_ncm_parameters {
2674076dd23SAndrew Thompson 	uWord	wLength;
2684076dd23SAndrew Thompson 	uWord	bmNtbFormatsSupported;
2694076dd23SAndrew Thompson #define	UCDC_NCM_FORMAT_NTB16	0x0001
2704076dd23SAndrew Thompson #define	UCDC_NCM_FORMAT_NTB32	0x0002
2714076dd23SAndrew Thompson 	uDWord	dwNtbInMaxSize;
2724076dd23SAndrew Thompson 	uWord	wNdpInDivisor;
2734076dd23SAndrew Thompson 	uWord	wNdpInPayloadRemainder;
2744076dd23SAndrew Thompson 	uWord	wNdpInAlignment;
2754076dd23SAndrew Thompson 	uWord	wReserved14;
2764076dd23SAndrew Thompson 	uDWord	dwNtbOutMaxSize;
2774076dd23SAndrew Thompson 	uWord	wNdpOutDivisor;
2784076dd23SAndrew Thompson 	uWord	wNdpOutPayloadRemainder;
2794076dd23SAndrew Thompson 	uWord	wNdpOutAlignment;
2807e05daaeSHans Petter Selasky 	uWord	wNtbOutMaxDatagrams;
2814076dd23SAndrew Thompson } __packed;
2824076dd23SAndrew Thompson 
2834076dd23SAndrew Thompson /* Communications interface specific class notification codes */
2844076dd23SAndrew Thompson #define	UCDC_NCM_NOTIF_NETWORK_CONNECTION	0x00
2854076dd23SAndrew Thompson #define	UCDC_NCM_NOTIF_RESPONSE_AVAILABLE	0x01
2864076dd23SAndrew Thompson #define	UCDC_NCM_NOTIF_CONNECTION_SPEED_CHANGE	0x2A
2874076dd23SAndrew Thompson 
28802ac6454SAndrew Thompson #endif					/* _USB_CDC_H_ */
289