|
1 // Copyright (c) 1999-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // Define the L2CAP Service Access Point (SAP) class |
|
15 // |
|
16 // |
|
17 |
|
18 #ifndef L2SAP_H |
|
19 #define L2SAP_H |
|
20 |
|
21 #include <bt_sock.h> |
|
22 #include "BtSap.h" |
|
23 |
|
24 class CL2CAPProtocol; |
|
25 class TL2CAPSAPState; |
|
26 |
|
27 class CL2CapSDUQueue; |
|
28 class CL2CapSAPSignalHandler; |
|
29 class CL2CapChannelConfig; |
|
30 class CL2CAPMux; |
|
31 //class CBTCodServiceMan; |
|
32 |
|
33 NONSHARABLE_CLASS(CL2CAPConnectionSAP) : public CBluetoothSAP |
|
34 { |
|
35 public: |
|
36 friend class TL2CAPSAPStateClosed; |
|
37 friend class TL2CAPSAPStateBound; |
|
38 friend class TL2CAPSAPStateAwaitingInitialData; |
|
39 friend class TL2CAPSAPStateOpen; |
|
40 friend class TL2CAPSAPStateAccepting; |
|
41 friend class TL2CAPSAPStateDisconnecting; |
|
42 |
|
43 enum TShutdownType |
|
44 { |
|
45 ESAPShutdownNone, |
|
46 ESAPShutdownImmediate, |
|
47 ESAPShutdownNormal, |
|
48 }; |
|
49 |
|
50 static CL2CAPConnectionSAP* NewL(CL2CAPProtocol&); |
|
51 ~CL2CAPConnectionSAP(); |
|
52 |
|
53 // 'Un-hide' the other overloads |
|
54 #ifndef __WINS__ |
|
55 #ifndef __GCC32__ |
|
56 using CServProviderBase::Write; |
|
57 using CServProviderBase::GetData; |
|
58 #endif |
|
59 #endif |
|
60 |
|
61 // Virtual Methods from CServProviderBase / CBluetoothSAP |
|
62 void LocalName(TSockAddr& anAddr) const; |
|
63 TInt SetLocalName(TSockAddr& anAddr); |
|
64 void RemName(TSockAddr& anAddr) const; |
|
65 TInt SetRemName(TSockAddr& anAddr); |
|
66 const TBTDevAddr& RemoteDev() const; |
|
67 void SetRemoteDev(const TBTDevAddr& aAddr); |
|
68 |
|
69 TInt SAPSetOption(TUint aLevel,TUint aName,const TDesC8 &aOption); |
|
70 TInt GetOption(TUint aLevel,TUint aName,TDes8& aOption)const; |
|
71 |
|
72 void Ioctl(TUint aLevel,TUint aName,TDes8* aOption); |
|
73 void CancelIoctl(TUint aLevel,TUint aName); |
|
74 void IoctlComplete(TInt aErr, TUint aLevel,TUint aName,TDesC8* aBuf); // From CBluetoothSAP |
|
75 |
|
76 void Start(); |
|
77 |
|
78 void ActiveOpen(); |
|
79 void ActiveOpen(const TDesC8& aConnectionData); |
|
80 TInt PassiveOpen(TUint aQueSize); |
|
81 TInt PassiveOpen(TUint aQueSize,const TDesC8& aConnectionData); |
|
82 void Shutdown(TCloseType aOption); |
|
83 void Shutdown(TCloseType option,const TDesC8& aDisconnectionData); |
|
84 void AutoBind(); |
|
85 |
|
86 TInt Write(RMBufChain& aData, TUint aOptions, TSockAddr* anAddr = NULL); |
|
87 TInt GetData(RMBufChain& aData, TUint aLength, TUint aOptions, TSockAddr* anAddr = NULL); |
|
88 |
|
89 // Des. versions. These should be removed when they become |
|
90 // redundant. |
|
91 TUint Write(const TDesC8& aDesc, TUint aOptions, TSockAddr* anAddr = NULL); |
|
92 void GetData(TDes8& aDesc, TUint aOptions, TSockAddr* anAddr = NULL); |
|
93 |
|
94 |
|
95 // Methods from SAP Signal Handler |
|
96 void LinkUp(); |
|
97 void ChannelOpened(); |
|
98 void ChannelConfigured(CL2CapChannelConfig& aConfig, |
|
99 CL2CAPMux& aMuxer, |
|
100 TL2CAPPort aLocalPort, |
|
101 TL2CAPPort aRemotePort); |
|
102 |
|
103 TInt UpdateChannelConfig(const TL2CapConfig& aAPIConfig); |
|
104 void ReconfiguringChannel(); |
|
105 |
|
106 void ChannelClosed(); |
|
107 |
|
108 void AccessRequestComplete(TInt aResult); |
|
109 |
|
110 void SignalHandlerError(TInt aErrorCode, MSocketNotify::TOperationBitmasks aErrorAction); |
|
111 void DataPlaneError(TInt aErrorCode, MSocketNotify::TOperationBitmasks aErrorAction); |
|
112 |
|
113 |
|
114 // Methods from Data Controller |
|
115 void NewData(); |
|
116 void CanSend(); |
|
117 void CloseOutgoingSDUQueue(); |
|
118 void SDUQueueClosed(); |
|
119 |
|
120 // State Pattern Utility Methods. |
|
121 void SetState(TL2CAPSAPState& aNewState); |
|
122 |
|
123 TInt CreateDataPlane(CL2CapChannelConfig& aConfig, |
|
124 CL2CAPMux& aMuxer, |
|
125 TL2CAPPort aLocalPort, |
|
126 TL2CAPPort aRemotePort); |
|
127 |
|
128 void PauseDataPlane(); |
|
129 void TryToCompleteConfigurationIoctl(TInt aError); |
|
130 |
|
131 static TInt NewDataAsyncCallBack(TAny* aSAP); |
|
132 inline void StartNewDataAsyncCallBack(); |
|
133 |
|
134 // Cloning Related Methods. |
|
135 TUint8 TotalOutstandingCloneCount() const; |
|
136 TBool CanAcceptConnection() const; |
|
137 CL2CAPConnectionSAP* CloneListeningSAP(const TBTDevAddr& aAddr); |
|
138 TBool DequeClone(CL2CAPConnectionSAP* aSAP); |
|
139 |
|
140 void DeleteAllClones(); |
|
141 |
|
142 // This method is used by the SAP states if they need to delete the SAP. |
|
143 void DeleteSAP(); |
|
144 |
|
145 void SocketConnectComplete(); |
|
146 |
|
147 void EchoResponseReceived(const TDesC8* aData); |
|
148 void DetachFromListeningSAP(); |
|
149 inline void SetListeningSAP(CL2CAPConnectionSAP& aSAP); |
|
150 inline void ClearListeningSAP(); |
|
151 inline CL2CAPConnectionSAP* ListeningSAP() const; |
|
152 |
|
153 inline CL2CapSAPSignalHandler& SignalHandler() const; |
|
154 inline CL2CapSDUQueue& DataQueue() const; |
|
155 inline MSocketNotify* Socket() const; |
|
156 inline CL2CAPProtocol& Protocol() const; |
|
157 |
|
158 inline TBool IsSDUQueueClosed() const; |
|
159 inline TShutdownType ShutdownReceived() const; |
|
160 inline TUint8 ChannelPriority() const; |
|
161 |
|
162 inline TInt SocketErrorCode() const; |
|
163 inline TUint SocketErrorAction() const; |
|
164 inline void SetSocketErrorCode(TInt aError); |
|
165 inline void SetSocketErrorAction(MSocketNotify::TOperationBitmasks aAction); |
|
166 inline TBool IsAcceptPending() const; |
|
167 private: |
|
168 CL2CAPConnectionSAP(CL2CAPProtocol&); |
|
169 void ConstructL(); |
|
170 |
|
171 TBool EnqueClone(CL2CAPConnectionSAP* aSAP); |
|
172 |
|
173 TUint GetOptimalMTUSize(TUint aMTU, TUint aPduSize, TBool aBasicMode) const; |
|
174 |
|
175 private: |
|
176 TL2CAPSAPState* iState; |
|
177 CL2CAPProtocol& iProtocol; |
|
178 |
|
179 CL2CapSDUQueue* iL2CapDataQueue; |
|
180 CL2CapSAPSignalHandler* iL2CapSAPSignalHandler; |
|
181 |
|
182 // Async Callback to notify New Data. |
|
183 CAsyncCallBack* iNewDataAsyncCallBack; |
|
184 TUint16 iNewDataToNotify; |
|
185 |
|
186 TUint8 iMaxAcceptingQCount; |
|
187 |
|
188 RPointerArray<CL2CAPConnectionSAP> iClones; |
|
189 CL2CAPConnectionSAP* iListeningSAP; |
|
190 |
|
191 TShutdownType iShutdownReceived; |
|
192 TUint iOutstandingIoctlName; |
|
193 |
|
194 TUint8 iChannelPriority; |
|
195 |
|
196 TInt iSocketErrorCode; |
|
197 MSocketNotify::TOperationBitmasks iSocketErrorAction; |
|
198 //flag for dealing with the situation that we disconnect after connection |
|
199 //complete and before accept. |
|
200 TBool iAcceptPending; |
|
201 }; |
|
202 |
|
203 |
|
204 #include "l2sap.inl" |
|
205 |
|
206 |
|
207 #endif |
|
208 |