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.2b5"
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_DISABLED =		0x0000,
200    kPACKET_TYPE_PROMISCUOUS =		0x0001,
201    kPACKET_TYPE_ALL_MULTICAST =	0x0002,
202    kPACKET_TYPE_DIRECTED =		0x0004,
203    kPACKET_TYPE_BROADCAST =		0x0008,
204    kPACKET_TYPE_MULTICAST =		0x0010
205};
206
207	// EEM packet definitions
208
209typedef struct
210{
211	UInt16  bmHeader;
212
213} EEMPacketHeader;
214
215    // Functional Descriptors
216
217typedef struct
218{
219    UInt8	bFunctionLength;
220    UInt8 	bDescriptorType;
221    UInt8 	bDescriptorSubtype;
222} FunctionalDescriptorHeader;
223
224typedef struct
225{
226    UInt8	bFunctionLength;
227    UInt8 	bDescriptorType;
228    UInt8 	bDescriptorSubtype;
229    UInt8 	bcdCDC1;
230    UInt8 	bcdCDC2;
231} HDRFunctionalDescriptor;
232
233typedef struct
234{
235    UInt8	bFunctionLength;
236    UInt8 	bDescriptorType;
237    UInt8 	bDescriptorSubtype;
238    UInt8 	bmCapabilities;
239    UInt8 	bDataInterface;
240} CMFunctionalDescriptor;
241
242typedef struct
243{
244    UInt8	bFunctionLength;
245    UInt8 	bDescriptorType;
246    UInt8 	bDescriptorSubtype;
247    UInt8 	bmCapabilities;
248} ACMFunctionalDescriptor;
249
250typedef struct
251{
252    UInt8 	bFunctionLength;
253    UInt8 	bDescriptorType;
254    UInt8 	bDescriptorSubtype;
255    UInt8 	iMACAddress;
256    UInt8 	bmEthernetStatistics[4];
257    UInt16 	wMaxSegmentSize;
258    UInt16 	wNumberMCFilters;
259    UInt8 	bNumberPowerFilters;
260} ECMFunctionalDescriptor;
261
262typedef struct
263{
264    UInt8 	bFunctionLength;
265    UInt8 	bDescriptorType;
266    UInt8 	bDescriptorSubtype;
267	UInt8 	iMACAddress;
268    UInt8 	bmEthernetStatistics[4];
269    UInt16 	wMaxSegmentSize;
270    UInt16 	wNumberMCFilters;
271    UInt8 	bNumberPowerFilters;
272} EEMFunctionalDescriptor;
273
274typedef struct
275{
276    UInt8	bFunctionLength;
277    UInt8 	bDescriptorType;
278    UInt8 	bDescriptorSubtype;
279    UInt8 	bcdCDC1;
280    UInt8 	bcdCDC2;
281} WHCMFunctionalDescriptor;
282
283typedef struct
284{
285    UInt8	bFunctionLength;
286    UInt8 	bDescriptorType;
287    UInt8 	bDescriptorSubtype;
288    UInt8 	bcdCDC1;
289    UInt8 	bcdCDC2;
290	UInt16  wMaxCommand;
291} DMMFunctionalDescriptor;
292
293typedef struct
294{
295    UInt8	bFunctionLength;
296    UInt8 	bDescriptorType;
297    UInt8 	bDescriptorSubtype;
298    UInt8 	bMasterInterface;
299    UInt8	bSlaveInterface[];
300} UnionFunctionalDescriptor;
301
302typedef struct
303{
304    UInt8	bLength;
305    UInt8 	bDescriptorType;
306    UInt8 	bFirstInterface;
307    UInt8 	bInterfaceCount;
308    UInt8	bFunctionClass;
309	UInt8	bFunctionSubClass;
310	UInt8	bFunctionProtocol;
311	UInt8	iFunction;
312} IADDescriptor;
313
314typedef struct
315{
316    UInt8 	bFunctionLength;
317    UInt8 	bDescriptorType;
318    UInt8 	bDescriptorSubtype;
319    UInt16 	bcdNcmVersion;
320    UInt8 	bmNetworkingCapabilities;
321} __attribute__((packed)) NCMFunctionalDescriptor;
322
323typedef struct
324{
325    UInt8 	bFunctionLength;
326    UInt8 	bDescriptorType;
327    UInt8 	bDescriptorSubtype;
328    UInt16 	bcdMBIMVersion;
329	UInt16	wMaxControlMessage;
330	UInt8	bNumberFilters;
331	UInt8	bMaxFilterSize;
332	UInt16	wMaxSegmentSize;
333    UInt8 	bmNetworkingCapabilities;
334} __attribute__((packed)) MBIMFunctionalDescriptor;
335
336	// NCM/MBIM definitions
337
338typedef struct
339{
340    UInt16 	wLength;
341    UInt16 	bmNtbFormatsSupported;
342    UInt32 	dwNtbInMaxSize;
343    UInt16 	wNdpInDivisor;
344    UInt16 	wNdpInPayloadRemainder;
345	UInt16 	wNdpInAlignment;
346	UInt16	wReserved;
347	UInt32 	dwNtbOutMaxSize;
348    UInt16 	wNdpOutDivisor;
349    UInt16 	wNdpOutPayloadRemainder;
350	UInt16 	wNdpOutAlignment;
351	UInt16	wNtbOutMaxDatagrams;
352} __attribute__((packed)) NTBParameters;
353
354typedef struct
355{
356    UInt32 	dwNtbInMaxSize;
357    UInt16 	wNtbInMaxDatagrams;
358	UInt16	wReserved;
359} __attribute__((packed)) NTBInSize;
360
361#define NCM_Support_Packet_Filter		0x01
362#define NCM_Support_Net_Address			0x02
363#define NCM_Support_Encapsulated		0x04
364#define NCM_Support_Max_Datagram_Size	0x08
365#define NCM_Support_CRC_Mode			0x10
366#define NCM_Support_NTB_Size_8_Byte		0x20
367
368#define NCM_Format_Support_NTB16		0x01
369#define NCM_Format_Support_NTB32		0x02
370
371#define NCM_Format_Selection_NTB16		0x00
372#define NCM_Format_Selection_NTB32		0x01
373
374#define NCM_CRC_Mode_NotAppend			0x00
375#define NCM_CRC_Mode_Append				0x01
376
377#define NCM_NO_CRC32					0x30
378#define NCM_WITH_CRC32					0x31
379
380#define NCM_MAX_OUT						16				// Arbitrary for unlimited datagrams
381
382#define NTH16_Signature                 0x484D434E		// NCMH
383#define NTH32_Signature					0x686D636E		// ncmh
384
385#define NCM16_Signature_NoCRC           0x304D434E		// NCM0
386#define NCM16_Signature_CRC             0x314D434E		// NCM1
387#define NCM32_Signature_NoCRC           0x306D636E		// ncm0
388#define NCM32_Signature_CRC             0x316D636E		// ncm1
389
390#define MBIM_IPS_16                     0x00535049      //�IPS�<SessionId> Raw IPv4 or IPv6 payload IPS0 for now
391#define MBIM_IPS_32                     0x00737069      //�ips�<SessionId> Raw IPv4 or IPv6 payload ips0 for now
392#define MBIM_DSS_16                     0x00535344      //�DSS�<SessionId> Device Service Stream payload
393#define MBIM_DSS_32                     0x00737364      //�DSS�<SessionId> Device Service Stream payload
394
395typedef struct
396{
397    UInt32 	dwSignature;
398    UInt16 	wHeaderLength;
399	UInt16	wSequence;
400	UInt16	wBlockLength;
401	UInt16	wNdpIndex;
402} __attribute__((packed)) NTH16;
403
404typedef struct
405{
406    UInt32 	dwSignature;
407    UInt16 	wHeaderLength;
408	UInt16	wSequence;
409	UInt32	wBlockLength;
410	UInt32	wNdpIndex;
411} __attribute__((packed)) NTH32;
412
413typedef struct
414{
415    UInt32		dwSignature;
416    UInt16		wLength;
417	UInt16		wNextNdpIndex;  //Reserved for use as a link to the next NDP16 in the NTB set to 0x0000
418} __attribute__((packed)) NDP16;
419
420typedef struct
421{
422    UInt16 	wDatagramIndex;
423	UInt16	wDatagramLength;
424	UInt16	wDatagramIndex_Next;
425} __attribute__((packed)) DPIndex16;
426
427typedef struct
428{
429    NDP16		ndp16;
430	DPIndex16	dp16;
431	DPIndex16	dp16_Next;
432} __attribute__((packed)) FullNDP16;
433
434typedef struct
435{
436    UInt32		dwSignature;
437    UInt16		wLength;
438	UInt16		wReserved6;
439	UInt32		dwNextNdpIndex;
440	UInt32		dwReserved12;
441} __attribute__((packed)) NDP32;
442
443typedef struct
444{
445    UInt32 	wDatagramIndex;
446	UInt32	wDatagramLength;
447	UInt32	wDatagramIndex_Next;
448} __attribute__((packed)) DPIndex32;
449
450typedef struct
451{
452    NDP32		ndp32;
453	DPIndex32	dp32;
454	DPIndex32	dp32_Next;
455} __attribute__((packed)) FullNDP32;
456
457    // Inline conversions
458
459static inline unsigned long tval2long(mach_timespec val)
460{
461   return (val.tv_sec * NSEC_PER_SEC) + val.tv_nsec;
462}
463
464static inline mach_timespec long2tval(unsigned long val)
465{
466    mach_timespec tval;
467
468    tval.tv_sec = val / NSEC_PER_SEC;
469    tval.tv_nsec = val % NSEC_PER_SEC;
470    return tval;
471}
472
473static inline UInt8 Asciify(UInt8 i)
474{
475
476    i &= 0xF;
477    if (i < 10)
478        return('0' + i);
479    else return(55  + i);
480
481}
482
483/* Message Tracing Defines */
484#define CDC_ASL_MAX_FMT_LEN		1024
485#define CDC_ASL_MSG_LEN			"         0"
486#define CDC_ASL_LEVEL_NOTICE		5
487#define CDC_ASL_KEY_DOMAIN         "com.apple.message.domain"
488#define CDC_ASL_KEY_SIG			"com.apple.message.signature"
489#define CDC_ASL_KEY_SIG2			"com.apple.message.signature2"
490#define CDC_ASL_KEY_SIG3			"com.apple.message.signature3"
491#define CDC_ASL_KEY_SUCCESS		"com.apple.message.success"
492#define CDC_ASL_SUCCESS_VALUE		1
493#define CDC_ASL_KEY_VALUE			"com.apple.message.value"
494#define CDC_ASL_KEY_MSG			"Message"
495
496#define CDC_ASL_DOMAIN             "com.apple.commssw.cdc.device"
497
498extern "C"
499{
500#include <sys/kernel.h>
501#include <IOKit/IOLib.h>
502#include <sys/systm.h>
503#include <sys/malloc.h>
504#include <sys/syslog.h>
505#include <sys/fslog.h>
506#include <IOKit/IOLib.h>
507    extern void cdc_LogToMessageTracer(const char *domain, const char *signature, const char *signature2, const char *signature3, u_int64_t optValue, int optSucceeded);
508
509}
510
511#endif
512