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 __APPLEUSBCDCACMControl__
26#define __APPLEUSBCDCACMControl__
27
28#include "AppleUSBCDCCommon.h"
29#include "AppleUSBCDCACMData.h"
30
31    // Miscellaneous
32
33#define COMM_BUFF_SIZE	16
34
35#define kDeviceSelfPowered	1
36
37enum
38{
39    kCDCPowerOffState	= 0,
40    kCDCPowerOnState	= 1,
41    kNumCDCStates	= 2
42};
43
44class AppleUSBCDCACMData;
45
46	/* AppleUSBCDCACMControl.h - This file contains the class definition for the		*/
47	/* USB Communication Device Class (CDC) ACM Control driver. 				*/
48
49class AppleUSBCDCACMControl : public IOService
50{
51    OSDeclareDefaultStructors(AppleUSBCDCACMControl);			// Constructor & Destructor stuff
52
53private:
54	AppleUSBCDC				*fCDCDriver;		// The CDC driver
55    AppleUSBCDCACMData		*fDataDriver;       // Our Data Driver
56    bool			fdataAcquired;				// Has the data port been acquired
57    UInt8			fSessions;				// Active sessions (across all ports)
58    bool			fTerminate;				// Are we being terminated (ie the device was unplugged)
59    bool			fStopping;				// Are we being "stopped"
60    UInt8			fPowerState;				// Ordinal for power management
61    UInt8			fConfig;				// Configuration number
62	bool			fReadDead;				// Is the Comm pipe read dead
63    IOUSBPipe			*fCommPipe;				// The interrupt pipe
64    IOBufferMemoryDescriptor	*fCommPipeMDP;				// Interrupt pipe memory descriptor
65    UInt8			*fCommPipeBuffer;			// Interrupt pipe buffer
66    IOUSBCompletion		fCommCompletionInfo;			// Interrupt completion routine
67    IOUSBCompletion		fMERCompletionInfo;			// MER Completion routine
68    UInt8			fCommInterfaceNumber;			// My interface number
69    UInt8			fCMCapabilities;			// Call Management Capabilities
70    UInt8			fACMCapabilities;			// Abstract Control Management
71
72    static void			commReadComplete( void *obj, void *param, IOReturn ior, UInt32 remaining);
73    static void			merWriteComplete(void *obj, void *param, IOReturn ior, UInt32 remaining);
74
75public:
76
77    IOUSBInterface		*fControlInterface;
78    UInt8			fDataInterfaceNumber;			// Matching Data interface number
79
80        // IOKit methods:
81
82	virtual IOService   *probe(IOService *provider, SInt32 *score);
83    virtual bool		start(IOService *provider);
84    virtual void		stop(IOService *provider);
85    virtual IOReturn 		message(UInt32 type, IOService *provider, void *argument = 0);
86
87        // CDC ACM Control Driver Methods
88
89    bool			configureACM(void);
90    bool			getFunctionalDescriptors(void);
91    virtual bool		dataAcquired(void);
92    virtual void		dataReleased(void);
93    virtual void 		USBSendSetLineCoding(UInt32 BaudRate, UInt8 StopBits, UInt8 TX_Parity, UInt8 CharLength);
94    virtual void 		USBSendSetControlLineState(bool RTS, bool DTR);
95    virtual void 		USBSendBreak(bool sBreak);
96    IOReturn			checkPipe(IOUSBPipe *thePipe, bool devReq);
97    bool 			allocateResources(void);
98    void			releaseResources(void);
99    bool			WakeonRing(void);
100    void                        resetDevice(void);
101    virtual bool		checkInterfaceNumber(AppleUSBCDCACMData *dataDriver);
102
103        // Power Manager Methods
104
105    bool			initForPM(IOService *provider);
106    unsigned long		initialPowerStateForDomainState(IOPMPowerFlags flags);
107    IOReturn			setPowerState(unsigned long powerStateOrdinal, IOService *whatDevice);
108
109}; /* end class AppleUSBCDCACMControl */
110#endif