1/* 2 * 3 * @APPLE_LICENSE_HEADER_START@ 4 * 5 * Copyright (c) 1998-2003 Apple Computer, Inc. All Rights Reserved. 6 * 7 * This file contains Original Code and/or Modifications of Original Code 8 * as defined in and that are subject to the Apple Public Source License 9 * Version 2.0 (the 'License'). You may not use this file except in 10 * compliance with the License. Please obtain a copy of the License at 11 * http://www.opensource.apple.com/apsl/ and read it before using this 12 * file. 13 * 14 * The Original Code and all software distributed under the License are 15 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 16 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 17 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 18 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 19 * Please see the License for the specific language governing rights and 20 * limitations under the License. 21 * 22 * @APPLE_LICENSE_HEADER_END@ 23 */ 24 25#ifndef __APPLEUSBCDCCOMMON__ 26#define __APPLEUSBCDCCOMMON__ 27 28#define VersionNumber "4.2.1b5" 29 30 // USB CDC Common Defintions 31 32#define kUSBAbstractControlModel 2 33#define kUSBEthernetControlModel 6 34#define kUSBWirelessHandsetControlModel 8 35#define kUSBDeviceManagementModel 9 36#define kUSBMobileDirectLineModel 10 37#define kUSBOBEXModel 11 38#define kUSBEthernetEmulationModel 12 39#define kUSBNetworkControlModel 13 40#define kUSBMobileBroadbandInterfaceModel 14 41 42#define kUSBv25 1 43#define kUSBv25PCCA 2 44#define kUSBv25PCCAO 3 45#define kUSBv25GSM 4 46#define kUSBv253GPPP 5 47#define kUSBv25CS 6 48 49#define kNetworkTransferBlock 1 50 51enum 52{ 53 kUSBSEND_ENCAPSULATED_COMMAND = 0, // Requests 54 kUSBGET_ENCAPSULATED_RESPONSE = 1, 55 kUSBSET_COMM_FEATURE = 2, 56 kUSBGET_COMM_FEATURE = 3, 57 kUSBCLEAR_COMM_FEATURE = 4, 58 kUSBRESET_FUNCTION = 5, 59 kUSBSET_LINE_CODING = 0x20, 60 kUSBGET_LINE_CODING = 0x21, 61 kUSBSET_CONTROL_LINE_STATE = 0x22, 62 kUSBSEND_BREAK = 0x23 63}; 64 65enum 66{ 67 kSet_Ethernet_Multicast_Filter = 0x40, 68 kSet_Ethernet_PM_Packet_Filter = 0x41, 69 kGet_Ethernet_PM_Packet_Filter = 0x42, 70 kSet_Ethernet_Packet_Filter = 0x43, 71 kGet_Ethernet_Statistics = 0x44, 72 kGet_AUX_Inputs = 4, 73 kSet_AUX_Outputs = 5, 74 kSet_Temp_MAC = 6, 75 kGet_Temp_MAC = 7, 76 kSet_URB_Size = 8, 77 kSet_SOFS_To_Wait = 9, 78 kSet_Even_Packets = 10, 79 kScan = 0xFF 80}; 81 82enum 83{ 84 kUSBNETWORK_CONNECTION = 0, // Notifications 85 kUSBRESPONSE_AVAILABLE = 1, 86 kUSBSERIAL_STATE = 0x20, 87 kUSBCONNECTION_SPEED_CHANGE = 0x2A 88}; 89 90typedef struct 91{ 92 UInt8 bmRequestType; 93 UInt8 bNotification; 94 UInt16 wValue; 95 UInt16 wIndex; 96 UInt16 wLength; 97} __attribute__((packed)) Notification; 98 99typedef struct 100{ 101 Notification header; 102 UInt16 UART_State_Bit_Map; 103} __attribute__((packed)) SerialState; 104 105typedef struct 106{ 107 Notification header; 108 UInt32 USBitRate; 109 UInt32 DSBitRate; 110} __attribute__((packed)) ConnectionSpeedChange; 111 112enum 113{ 114 kGet_NTB_Parameters = 0x80, 115 kGet_NET_Address = 0x81, 116 kSet_NET_Address = 0x82, 117 kGet_NTB_Format = 0x83, 118 kSet_NTB_Format = 0x84, 119 kGet_NTB_Input_Size = 0x85, 120 kSet_NTB_Input_Size = 0x86, 121 kGet_MAX_Datagram_Size = 0x87, 122 kSet_MAX_Datagram_Size = 0x88, 123 kGet_CRC_Mode = 0x89, 124 kSet_CRC_Mode = 0x8A 125}; 126 127enum 128{ 129 CS_INTERFACE = 0x24, 130 131 Header_FunctionalDescriptor = 0x00, 132 CM_FunctionalDescriptor = 0x01, 133 ACM_FunctionalDescriptor = 0x02, 134 Union_FunctionalDescriptor = 0x06, 135 CS_FunctionalDescriptor = 0x07, 136 ECM_Functional_Descriptor = 0x0f, 137 WCM_FunctionalDescriptor = 0x11, 138 DMM_FunctionalDescriptor = 0x14, 139 OBEX_FunctionalDescriptor = 0x15, 140 EEM_Functional_Descriptor = 0xff, 141 NCM_Functional_Descriptor = 0x1A, 142 MBIM_Functional_Descriptor = 0x1B, 143 144 CM_ManagementData = 0x01, 145 CM_ManagementOnData = 0x02, 146 147 ACM_DeviceSuppCommFeature = 0x01, 148 ACM_DeviceSuppControl = 0x02, 149 ACM_DeviceSuppBreak = 0x04, 150 ACM_DeviceSuppNetConnect = 0x08 151}; 152 153 // Ethernet Stats of interest in bmEthernetStatistics (bit definitions) 154 155enum 156{ 157 kXMIT_OK = 0x01, // Byte 1 158 kRCV_OK = 0x02, 159 kXMIT_ERROR = 0x04, 160 kRCV_ERROR = 0x08, 161 162 kRCV_CRC_ERROR = 0x02, // Byte 3 163 kRCV_ERROR_ALIGNMENT = 0x08, 164 kXMIT_ONE_COLLISION = 0x10, 165 kXMIT_MORE_COLLISIONS = 0x20, 166 kXMIT_DEFERRED = 0x40, 167 kXMIT_MAX_COLLISION = 0x80, 168 169 kRCV_OVERRUN = 0x01, // Byte 4 170 kXMIT_TIMES_CARRIER_LOST = 0x08, 171 kXMIT_LATE_COLLISIONS = 0x10 172}; 173 174 // Ethernet Stats request definitions 175 176enum 177{ 178 kXMIT_OK_REQ = 0x0001, 179 kRCV_OK_REQ = 0x0002, 180 kXMIT_ERROR_REQ = 0x0003, 181 kRCV_ERROR_REQ = 0x0004, 182 183 kRCV_CRC_ERROR_REQ = 0x0012, 184 kRCV_ERROR_ALIGNMENT_REQ = 0x0014, 185 kXMIT_ONE_COLLISION_REQ = 0x0015, 186 kXMIT_MORE_COLLISIONS_REQ = 0x0016, 187 kXMIT_DEFERRED_REQ = 0x0017, 188 kXMIT_MAX_COLLISION_REQ = 0x0018, 189 190 kRCV_OVERRUN_REQ = 0x0019, 191 kXMIT_TIMES_CARRIER_LOST_REQ = 0x001c, 192 kXMIT_LATE_COLLISIONS_REQ = 0x001d 193}; 194 195 // Ethernet Packet Filter definitions 196 197enum 198{ 199 kPACKET_TYPE_PROMISCUOUS = 0x0001, 200 kPACKET_TYPE_ALL_MULTICAST = 0x0002, 201 kPACKET_TYPE_DIRECTED = 0x0004, 202 kPACKET_TYPE_BROADCAST = 0x0008, 203 kPACKET_TYPE_MULTICAST = 0x0010 204}; 205 206 // EEM packet definitions 207 208typedef struct 209{ 210 UInt16 bmHeader; 211 212} EEMPacketHeader; 213 214 // Functional Descriptors 215 216typedef struct 217{ 218 UInt8 bFunctionLength; 219 UInt8 bDescriptorType; 220 UInt8 bDescriptorSubtype; 221} FunctionalDescriptorHeader; 222 223typedef struct 224{ 225 UInt8 bFunctionLength; 226 UInt8 bDescriptorType; 227 UInt8 bDescriptorSubtype; 228 UInt8 bcdCDC1; 229 UInt8 bcdCDC2; 230} HDRFunctionalDescriptor; 231 232typedef struct 233{ 234 UInt8 bFunctionLength; 235 UInt8 bDescriptorType; 236 UInt8 bDescriptorSubtype; 237 UInt8 bmCapabilities; 238 UInt8 bDataInterface; 239} CMFunctionalDescriptor; 240 241typedef struct 242{ 243 UInt8 bFunctionLength; 244 UInt8 bDescriptorType; 245 UInt8 bDescriptorSubtype; 246 UInt8 bmCapabilities; 247} ACMFunctionalDescriptor; 248 249typedef struct 250{ 251 UInt8 bFunctionLength; 252 UInt8 bDescriptorType; 253 UInt8 bDescriptorSubtype; 254 UInt8 iMACAddress; 255 UInt8 bmEthernetStatistics[4]; 256 UInt16 wMaxSegmentSize; 257 UInt16 wNumberMCFilters; 258 UInt8 bNumberPowerFilters; 259} ECMFunctionalDescriptor; 260 261typedef struct 262{ 263 UInt8 bFunctionLength; 264 UInt8 bDescriptorType; 265 UInt8 bDescriptorSubtype; 266 UInt8 iMACAddress; 267 UInt8 bmEthernetStatistics[4]; 268 UInt16 wMaxSegmentSize; 269 UInt16 wNumberMCFilters; 270 UInt8 bNumberPowerFilters; 271} EEMFunctionalDescriptor; 272 273typedef struct 274{ 275 UInt8 bFunctionLength; 276 UInt8 bDescriptorType; 277 UInt8 bDescriptorSubtype; 278 UInt8 bcdCDC1; 279 UInt8 bcdCDC2; 280} WHCMFunctionalDescriptor; 281 282typedef struct 283{ 284 UInt8 bFunctionLength; 285 UInt8 bDescriptorType; 286 UInt8 bDescriptorSubtype; 287 UInt8 bcdCDC1; 288 UInt8 bcdCDC2; 289 UInt16 wMaxCommand; 290} DMMFunctionalDescriptor; 291 292typedef struct 293{ 294 UInt8 bFunctionLength; 295 UInt8 bDescriptorType; 296 UInt8 bDescriptorSubtype; 297 UInt8 bMasterInterface; 298 UInt8 bSlaveInterface[]; 299} UnionFunctionalDescriptor; 300 301typedef struct 302{ 303 UInt8 bLength; 304 UInt8 bDescriptorType; 305 UInt8 bFirstInterface; 306 UInt8 bInterfaceCount; 307 UInt8 bFunctionClass; 308 UInt8 bFunctionSubClass; 309 UInt8 bFunctionProtocol; 310 UInt8 iFunction; 311} IADDescriptor; 312 313typedef struct 314{ 315 UInt8 bFunctionLength; 316 UInt8 bDescriptorType; 317 UInt8 bDescriptorSubtype; 318 UInt16 bcdNcmVersion; 319 UInt8 bmNetworkingCapabilities; 320} __attribute__((packed)) NCMFunctionalDescriptor; 321 322typedef struct 323{ 324 UInt8 bFunctionLength; 325 UInt8 bDescriptorType; 326 UInt8 bDescriptorSubtype; 327 UInt16 bcdMBIMVersion; 328 UInt16 wMaxControlMessage; 329 UInt8 bNumberFilters; 330 UInt8 bMaxFilterSize; 331 UInt16 wMaxSegmentSize; 332 UInt8 bmNetworkingCapabilities; 333} __attribute__((packed)) MBIMFunctionalDescriptor; 334 335 // NCM/MBIM definitions 336 337typedef struct 338{ 339 UInt16 wLength; 340 UInt16 bmNtbFormatsSupported; 341 UInt32 dwNtbInMaxSize; 342 UInt16 wNdpInDivisor; 343 UInt16 wNdpInPayloadRemainder; 344 UInt16 wNdpInAlignment; 345 UInt16 wReserved; 346 UInt32 dwNtbOutMaxSize; 347 UInt16 wNdpOutDivisor; 348 UInt16 wNdpOutPayloadRemainder; 349 UInt16 wNdpOutAlignment; 350 UInt16 wNtbOutMaxDatagrams; 351} __attribute__((packed)) NTBParameters; 352 353typedef struct 354{ 355 UInt32 dwNtbInMaxSize; 356 UInt16 wNtbInMaxDatagrams; 357 UInt16 wReserved; 358} __attribute__((packed)) NTBInSize; 359 360#define NCM_Support_Packet_Filter 0x01 361#define NCM_Support_Net_Address 0x02 362#define NCM_Support_Encapsulated 0x04 363#define NCM_Support_Max_Datagram_Size 0x08 364#define NCM_Support_CRC_Mode 0x10 365#define NCM_Support_NTB_Size_8_Byte 0x20 366 367#define NCM_Format_Support_NTB16 0x01 368#define NCM_Format_Support_NTB32 0x02 369 370#define NCM_Format_Selection_NTB16 0x00 371#define NCM_Format_Selection_NTB32 0x01 372 373#define NCM_CRC_Mode_NotAppend 0x00 374#define NCM_CRC_Mode_Append 0x01 375 376#define NCM_NO_CRC32 0x30 377#define NCM_WITH_CRC32 0x31 378 379#define NCM_MAX_OUT 16 // Arbitrary for unlimited datagrams 380 381#define NTH16_Signature 0x484D434E // NCMH 382#define NTH32_Signature 0x686D636E // ncmh 383 384#define NCM16_Signature_NoCRC 0x304D434E // NCM0 385#define NCM16_Signature_CRC 0x314D434E // NCM1 386#define NCM32_Signature_NoCRC 0x306D636E // ncm0 387#define NCM32_Signature_CRC 0x316D636E // ncm1 388 389#define MBIM_IPS_16 0x00535049 //�IPS�<SessionId> Raw IPv4 or IPv6 payload IPS0 for now 390#define MBIM_IPS_32 0x00737069 //�ips�<SessionId> Raw IPv4 or IPv6 payload ips0 for now 391#define MBIM_DSS_16 0x00535344 //�DSS�<SessionId> Device Service Stream payload 392#define MBIM_DSS_32 0x00737364 //�DSS�<SessionId> Device Service Stream payload 393 394typedef struct 395{ 396 UInt32 dwSignature; 397 UInt16 wHeaderLength; 398 UInt16 wSequence; 399 UInt16 wBlockLength; 400 UInt16 wNdpIndex; 401} __attribute__((packed)) NTH16; 402 403typedef struct 404{ 405 UInt32 dwSignature; 406 UInt16 wHeaderLength; 407 UInt16 wSequence; 408 UInt32 wBlockLength; 409 UInt32 wNdpIndex; 410} __attribute__((packed)) NTH32; 411 412typedef struct 413{ 414 UInt32 dwSignature; 415 UInt16 wLength; 416 UInt16 wNextNdpIndex; //Reserved for use as a link to the next NDP16 in the NTB set to 0x0000 417} __attribute__((packed)) NDP16; 418 419typedef struct 420{ 421 UInt16 wDatagramIndex; 422 UInt16 wDatagramLength; 423 UInt16 wDatagramIndex_Next; 424} __attribute__((packed)) DPIndex16; 425 426typedef struct 427{ 428 NDP16 ndp16; 429 DPIndex16 dp16; 430 DPIndex16 dp16_Next; 431} __attribute__((packed)) FullNDP16; 432 433typedef struct 434{ 435 UInt32 dwSignature; 436 UInt16 wLength; 437 UInt16 wReserved6; 438 UInt32 dwNextNdpIndex; 439 UInt32 dwReserved12; 440} __attribute__((packed)) NDP32; 441 442typedef struct 443{ 444 UInt32 wDatagramIndex; 445 UInt32 wDatagramLength; 446 UInt32 wDatagramIndex_Next; 447} __attribute__((packed)) DPIndex32; 448 449typedef struct 450{ 451 NDP32 ndp32; 452 DPIndex32 dp32; 453 DPIndex32 dp32_Next; 454} __attribute__((packed)) FullNDP32; 455 456 // Inline conversions 457 458static inline unsigned long tval2long(mach_timespec val) 459{ 460 return (val.tv_sec * NSEC_PER_SEC) + val.tv_nsec; 461} 462 463static inline mach_timespec long2tval(unsigned long val) 464{ 465 mach_timespec tval; 466 467 tval.tv_sec = val / NSEC_PER_SEC; 468 tval.tv_nsec = val % NSEC_PER_SEC; 469 return tval; 470} 471 472static inline UInt8 Asciify(UInt8 i) 473{ 474 475 i &= 0xF; 476 if (i < 10) 477 return('0' + i); 478 else return(55 + i); 479 480} 481 482/* Message Tracing Defines */ 483#define CDC_ASL_MAX_FMT_LEN 1024 484#define CDC_ASL_MSG_LEN " 0" 485#define CDC_ASL_LEVEL_NOTICE 5 486#define CDC_ASL_KEY_DOMAIN "com.apple.message.domain" 487#define CDC_ASL_KEY_SIG "com.apple.message.signature" 488#define CDC_ASL_KEY_SIG2 "com.apple.message.signature2" 489#define CDC_ASL_KEY_SIG3 "com.apple.message.signature3" 490#define CDC_ASL_KEY_SUCCESS "com.apple.message.success" 491#define CDC_ASL_SUCCESS_VALUE 1 492#define CDC_ASL_KEY_VALUE "com.apple.message.value" 493#define CDC_ASL_KEY_MSG "Message" 494 495#define CDC_ASL_DOMAIN "com.apple.commssw.cdc.device" 496 497extern "C" 498{ 499#include <sys/kernel.h> 500#include <IOKit/IOLib.h> 501#include <sys/systm.h> 502#include <sys/malloc.h> 503#include <sys/syslog.h> 504#include <sys/fslog.h> 505#include <IOKit/IOLib.h> 506 extern void cdc_LogToMessageTracer(const char *domain, const char *signature, const char *signature2, const char *signature3, u_int64_t optValue, int optSucceeded); 507 508} 509 510#endif