|
1 // Copyright (c) 2004-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 // |
|
15 |
|
16 #ifndef L2CAPSAPSIGNALHANDLER_H |
|
17 #define L2CAPSAPSIGNALHANDLER_H |
|
18 |
|
19 #include <e32std.h> |
|
20 #include <e32base.h> |
|
21 |
|
22 #include "L2CapChannelConfig.h" |
|
23 #include "l2capSigStates.h" |
|
24 #include "bttypes.h" |
|
25 #include "l2capSignalHandler.h" |
|
26 #include "l2capSigPacketEcho.h" |
|
27 #include "l2sap.h" |
|
28 |
|
29 class HConnectionResponse; |
|
30 class HConnectionRequest; |
|
31 class HConfigureRequest; |
|
32 class HConfigureResponse; |
|
33 class HDisconnectRequest; |
|
34 class HDisconnectResponse; |
|
35 class HCommandReject; |
|
36 |
|
37 class TL2CAPEntityConfig; |
|
38 |
|
39 class CL2CAPConnectionSAP; |
|
40 class CL2CAPSignalStateFactory; |
|
41 |
|
42 NONSHARABLE_CLASS(CL2CapSAPSignalHandler) : public CL2CapSignalHandler, |
|
43 public MEchoResponseHandler |
|
44 { |
|
45 public: |
|
46 static CL2CapSAPSignalHandler* NewL(CL2CAPConnectionSAP& aSAP); |
|
47 |
|
48 virtual ~CL2CapSAPSignalHandler(); |
|
49 |
|
50 // Prepare outgoing commands |
|
51 TInt UpdateChannelConfig(const TL2CapConfig& aAPIConfig); |
|
52 void CloneChannelConfig(CL2CapChannelConfig& aL2CAPChannelConfig); |
|
53 |
|
54 TInt ConstructConnectionResponse(TUint8 aId, TConnectResponseResult aResult, TConnectResponseStatus aStatus = EConnectPendNoFurtherInfo); |
|
55 TInt ConstructConnectionRequest(); |
|
56 TInt ConstructConfigRequest(); |
|
57 TInt ConstructConfigResponse(TUint8 aId, TConfigFlags aFlags, TConfigResponseResult aResult, RMBufChain& aUnknownParameters); |
|
58 TInt ConstructConfigResponse(TUint8 aId, TConfigFlags aFlags, TConfigResponseResult aResult); |
|
59 TInt ConstructDisconnectRequest(); |
|
60 TInt ConstructDisconnectResponse(TUint8 aId); |
|
61 |
|
62 void L2CapEntityConfigUpdated(); |
|
63 inline TBool IsPeerInfoDefined(); |
|
64 void ConfigRequestDelayTimerExpiry(); |
|
65 TBool DelayConfigRequest(); |
|
66 |
|
67 TBool HandleConnectionResponse(HConnectionResponse* aConnectionResponse); |
|
68 TBool HandleConfigureRequest(HConfigureRequest* aConfigRequest); |
|
69 TBool HandleConfigureResponse(HConfigureResponse* aConfigResponse); |
|
70 TBool HandleDisconnectRequest(HDisconnectRequest* aDisconnectRequest); |
|
71 TBool HandleDisconnectResponse(HDisconnectResponse* aDisconnectResponse); |
|
72 TBool HandleCommandReject(HCommandReject* aCommandReject); |
|
73 |
|
74 void CommandResponseFailure(HL2CapCommand* aCommand); |
|
75 |
|
76 TInt PassiveConnectionRequest(const TBTDevAddr& aAddr, HConnectionRequest* aConnectionRequest); |
|
77 void ActiveConnectionRequest(); |
|
78 |
|
79 void ConnectRequestReceived(); |
|
80 void OpenChannelRequest(); |
|
81 void ConfigureChannelRequest(); |
|
82 void CloseChannelRequest(); |
|
83 |
|
84 void SAPSignalHandlerRegistered(CL2CAPMux& aMuxer, TL2CAPEntityConfig& aEntityConfig); |
|
85 void ReconfiguringChannel(); |
|
86 |
|
87 void SignalHandlerDisconnectedCanClose(); |
|
88 void SignalHandlerErrorD(TInt aErrorCode, MSocketNotify::TOperationBitmasks aErrorAction); |
|
89 |
|
90 void Error(TInt aErrorCode, MSocketNotify::TOperationBitmasks aErrorAction); |
|
91 |
|
92 void LinkUp(); |
|
93 |
|
94 inline TBool IsChannelClosed() const; |
|
95 inline TBool IsChannelOpen() const; |
|
96 inline TInt GetNegotiatedChannelMode(TL2CapChannelMode& aMode) const; |
|
97 |
|
98 void SetLocalParameters(TL2CAPSockAddr& aAddr); |
|
99 void GetLocalParameters(TL2CAPSockAddr& aAddr) const; |
|
100 void SetRemName(TL2CAPSockAddr& aAddr); |
|
101 void GetRemName(TL2CAPSockAddr& aAddr) const; |
|
102 |
|
103 inline TUint8 RTXTimerDuration() const; |
|
104 inline TUint16 ERTXTimerDuration() const; |
|
105 TInt SetRTXTimerDuration(TUint8 aDuration); |
|
106 TInt SetERTXTimerDuration(TUint16 aDuration); |
|
107 |
|
108 void SetState(TL2CAPSigState& aState); |
|
109 |
|
110 TInt SetOption(TUint aLevel,TUint aName,const TDesC8 &aOption); |
|
111 TInt GetOption(TUint aLevel,TUint aName,TDes8& aOption)const; |
|
112 |
|
113 inline CL2CAPConnectionSAP* SAP(); |
|
114 inline const TBTDevAddr& RemoteBTAddress() const; |
|
115 |
|
116 void SetLocalPort(TL2CAPPort aPort); |
|
117 inline TL2CAPPort LocalPort() const; |
|
118 void SetRemotePort(TL2CAPPort aPort); |
|
119 inline TL2CAPPort RemotePort() const; |
|
120 |
|
121 inline CL2CapChannelConfig& ChannelConfig(); |
|
122 inline const CL2CapChannelConfig& ChannelConfig() const; |
|
123 |
|
124 TUint8 GetOutstandingRequestID(); |
|
125 void SetOutstandingRequestID(TUint8 aOutstandingRequestID); |
|
126 |
|
127 // SAP signal handler timer methods. |
|
128 static TInt TimerExpired(TAny* aSAPSignalHandler); |
|
129 |
|
130 void StartConfigurationTimer(); |
|
131 void CancelTimer(); |
|
132 |
|
133 void DetachFromMux(); |
|
134 void SAPClosed(); |
|
135 |
|
136 TInt SendEchoRequest(const TDes8* aData); |
|
137 void EchoResponseReceived(const TDesC8* aData); |
|
138 |
|
139 void OverrideParkMode(); |
|
140 void UndoOverrideParkMode(); |
|
141 void OverrideLPMWithTimeout(); |
|
142 inline TInt SignalHandlerErrorCode() const; |
|
143 inline MSocketNotify::TOperationBitmasks SignalHandlerErrorAction() const; |
|
144 inline void SetSignalHandlerErrorCode(TInt aError); |
|
145 inline void SetSignalHandlerErrorAction(MSocketNotify::TOperationBitmasks aAction); |
|
146 |
|
147 private: |
|
148 CL2CapSAPSignalHandler(CL2CAPConnectionSAP& aSAP); |
|
149 void ConstructL(); |
|
150 |
|
151 void PendingCommandsDrained(); |
|
152 void HandleTimerExpired(); |
|
153 |
|
154 public: |
|
155 TDblQueLink iLink; |
|
156 private: |
|
157 enum TSAPSignalHandlerTimerState |
|
158 { |
|
159 ETimerIdle, |
|
160 EConfigRequestDelayTimer, |
|
161 EConfigurationTimer, |
|
162 }; |
|
163 |
|
164 CL2CAPConnectionSAP* iSAP; |
|
165 |
|
166 TBTDevAddr iLocalBTAddress; |
|
167 TL2CAPPort iLocalPort; |
|
168 |
|
169 TL2CAPPort iRemotePort; |
|
170 |
|
171 TUint8 iDefaultRTXTimerDuration; |
|
172 TUint16 iERTXTimerDuration; |
|
173 |
|
174 CL2CapChannelConfig* iChannelConfig; |
|
175 TL2CAPSigState* iSigState; // Our signalling base state object |
|
176 |
|
177 TUint8 iOutstandingRequestID; |
|
178 |
|
179 TSAPSignalHandlerTimerState iSAPSignalHandlerTimerState; |
|
180 TDeltaTimerEntry iSAPSignalHandlerTimerEntry; |
|
181 |
|
182 TInt iSignalHandlerErrorCode; |
|
183 MSocketNotify::TOperationBitmasks iSignalHandlerErrorAction; |
|
184 |
|
185 // We need the peer supported features to be able to handle a Config Request coming |
|
186 // through (to be able to negotiate channel mode properly), which may be any time after |
|
187 // OpenChannelRequest, so OpenChannelRequest is delayed until Information Response comes |
|
188 // through. |
|
189 TBool iOpenChannelRequestAwaitingPeerEntityConfig; |
|
190 // The SAP is ready to send a config request |
|
191 // Flag to indicate that we are delaying sending this config request |
|
192 TBool iAwaitingConfigRequestDelayTimer; |
|
193 }; |
|
194 |
|
195 inline TUint8 CL2CapSAPSignalHandler::GetOutstandingRequestID() |
|
196 { |
|
197 return iOutstandingRequestID; |
|
198 } |
|
199 |
|
200 inline void CL2CapSAPSignalHandler::SetOutstandingRequestID(TUint8 aOutstandingRequestID) |
|
201 { |
|
202 iOutstandingRequestID = aOutstandingRequestID; |
|
203 } |
|
204 |
|
205 inline CL2CapChannelConfig& CL2CapSAPSignalHandler::ChannelConfig() |
|
206 { |
|
207 return *iChannelConfig; |
|
208 } |
|
209 |
|
210 inline const CL2CapChannelConfig& CL2CapSAPSignalHandler::ChannelConfig() const |
|
211 { |
|
212 return *iChannelConfig; |
|
213 } |
|
214 |
|
215 inline TInt CL2CapSAPSignalHandler::GetNegotiatedChannelMode(TL2CapChannelMode& aMode) const |
|
216 { |
|
217 return iSigState->GetNegotiatedChannelMode(*this, aMode); |
|
218 } |
|
219 |
|
220 inline CL2CAPConnectionSAP* CL2CapSAPSignalHandler::SAP() |
|
221 { |
|
222 return iSAP; |
|
223 } |
|
224 |
|
225 inline TL2CAPPort CL2CapSAPSignalHandler::LocalPort() const |
|
226 { |
|
227 return iLocalPort; |
|
228 } |
|
229 inline TL2CAPPort CL2CapSAPSignalHandler::RemotePort() const |
|
230 { |
|
231 return iRemotePort; |
|
232 } |
|
233 |
|
234 inline const TBTDevAddr& CL2CapSAPSignalHandler::RemoteBTAddress() const |
|
235 { |
|
236 return iSAP->RemoteDev(); |
|
237 } |
|
238 |
|
239 inline TBool CL2CapSAPSignalHandler::IsChannelClosed() const |
|
240 { |
|
241 return iSigState->IsChannelClosed(); |
|
242 } |
|
243 |
|
244 inline TBool CL2CapSAPSignalHandler::IsChannelOpen() const |
|
245 { |
|
246 return iSigState->IsChannelOpen(); |
|
247 } |
|
248 |
|
249 inline TUint8 CL2CapSAPSignalHandler::RTXTimerDuration() const |
|
250 { |
|
251 return iDefaultRTXTimerDuration; |
|
252 } |
|
253 |
|
254 inline TUint16 CL2CapSAPSignalHandler::ERTXTimerDuration() const |
|
255 { |
|
256 return iERTXTimerDuration; |
|
257 } |
|
258 |
|
259 inline TInt CL2CapSAPSignalHandler::SignalHandlerErrorCode() const |
|
260 { |
|
261 return iSignalHandlerErrorCode; |
|
262 } |
|
263 |
|
264 inline MSocketNotify::TOperationBitmasks CL2CapSAPSignalHandler::SignalHandlerErrorAction() const |
|
265 { |
|
266 return iSignalHandlerErrorAction; |
|
267 } |
|
268 |
|
269 inline void CL2CapSAPSignalHandler::SetSignalHandlerErrorCode(TInt aError) |
|
270 { |
|
271 iSignalHandlerErrorCode = aError; |
|
272 } |
|
273 |
|
274 inline TBool CL2CapSAPSignalHandler::IsPeerInfoDefined() |
|
275 { |
|
276 return iChannelConfig->IsPeerInfoDefined(); |
|
277 } |
|
278 |
|
279 inline void CL2CapSAPSignalHandler::SetSignalHandlerErrorAction(MSocketNotify::TOperationBitmasks aAction) |
|
280 { |
|
281 iSignalHandlerErrorAction = aAction; |
|
282 } |
|
283 |
|
284 #endif |