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