|
1 // Copyright (c) 2008-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 /** |
|
17 @file |
|
18 @internalComponent |
|
19 */ |
|
20 |
|
21 #ifndef PAIRINGSERVER_H |
|
22 #define PAIRINGSERVER_H |
|
23 |
|
24 #include <e32base.h> |
|
25 #include <es_prot.h> |
|
26 #include "oobdata.h" |
|
27 #include "simplepairingresult.h" |
|
28 #include "SecManNotifiers.h" |
|
29 |
|
30 class CPhysicalLinksManager; |
|
31 class CBTProxySAP; |
|
32 |
|
33 class CPairingSession; |
|
34 class CPairingSubSession; |
|
35 class COobDataSession; |
|
36 class CLinkMgrProtocol; |
|
37 |
|
38 const TUint KOOBBtAddrOffset = 2; |
|
39 const TUint KOOBOptionalDataOffset = 8; |
|
40 |
|
41 /** |
|
42 This class is the server which provides the services associated with |
|
43 Bluetooth pairing. |
|
44 */ |
|
45 NONSHARABLE_CLASS(CPairingServer) |
|
46 : public CPolicyServer |
|
47 { |
|
48 friend class CPairingSession; |
|
49 public: |
|
50 static CPairingServer* NewL(COobDataManager& aOobDataManager, CSimplePairingResultList& aSimplePairingResultList, CAuthenticationResultList& aAuthenticationResultList); |
|
51 ~CPairingServer(); |
|
52 |
|
53 void SetPhysicalLinksManager(CPhysicalLinksManager& aLinksMan); |
|
54 void ClearPhysicalLinkMgr(); |
|
55 void SetLinksMgrProtocol(CLinkMgrProtocol& aLinkMgrProtocol); |
|
56 void ClearLinksMgrProtocol(); |
|
57 |
|
58 private: // used by sessions. |
|
59 CObjectCon* NewContainerL(); |
|
60 void DeleteContainer(CObjectCon* aContainer); |
|
61 |
|
62 CPhysicalLinksManager& LinksManL() const; |
|
63 COobDataManager& OobDataManager() const; |
|
64 CSimplePairingResultList& SimplePairingResultList() const; |
|
65 CAuthenticationResultList& AuthenticationResultList() const; |
|
66 |
|
67 private: |
|
68 CPairingServer(COobDataManager& aOobDataManager, CSimplePairingResultList& aSimplePairingResultList, CAuthenticationResultList& aAuthenticationResultList); |
|
69 void ConstructL(); |
|
70 void AddSession(); |
|
71 void DropSession(); |
|
72 |
|
73 private: // from CPolicyServer |
|
74 CSession2* NewSessionL(const TVersion &aVersion, const RMessage2& aMessage) const; |
|
75 |
|
76 private: // unowned |
|
77 COobDataManager& iOobDataManager; |
|
78 CSimplePairingResultList& iSimplePairingResultList; |
|
79 CAuthenticationResultList& iAuthenticationResultList; |
|
80 CPhysicalLinksManager* iLinksMan; |
|
81 CLinkMgrProtocol* iLinkMgrProtocol; |
|
82 |
|
83 private: // owned |
|
84 CObjectConIx* iContainerIndex; |
|
85 TInt iSessionCount; |
|
86 }; |
|
87 |
|
88 |
|
89 /** |
|
90 This class provides the session representation for the Pairing server. |
|
91 The class mostly manages and dispatches requests to subsessions. |
|
92 */ |
|
93 NONSHARABLE_CLASS(CPairingSession) |
|
94 : public CSession2 |
|
95 { |
|
96 public: |
|
97 static CPairingSession* NewL(CPairingServer& aPairingServer); |
|
98 ~CPairingSession(); |
|
99 |
|
100 private: |
|
101 CPairingSession(CPairingServer& aPairingServer); |
|
102 void CreateL(); |
|
103 |
|
104 CPairingServer& Server() const; |
|
105 |
|
106 TBool DispatchSessMessageL(const RMessage2& aMessage); |
|
107 void DispatchSubSessMessageL(const RMessage2& aMessage); |
|
108 |
|
109 CPairingSubSession* SubSessionFromHandle(TInt aHandle); |
|
110 |
|
111 void NewOobDataSubSessionL(const RMessage2& aMessage); |
|
112 void NewDedicatedBondingSubSessionL(const RMessage2& aMessage); |
|
113 void NewSimplePairingResultSubSessionL(const RMessage2& aMessage); |
|
114 void NewAuthenticationResultSubSessionL(const RMessage2& aMessage); |
|
115 void SubSessionConstructL(const RMessage2& aMessage, CPairingSubSession* aSubSession); |
|
116 void DeleteSubSession(const RMessage2& aMessage); |
|
117 |
|
118 #ifdef _DEBUG |
|
119 // We don't use __DECLARE_TEST because we don't want to export this function. |
|
120 void __DbgTestInvariant() const; |
|
121 #endif // _DEBUG |
|
122 |
|
123 private: // from CSession2 |
|
124 void ServiceL(const RMessage2& aMessage); |
|
125 void ServiceError(const RMessage2& aMessage, TInt aError); |
|
126 |
|
127 private: |
|
128 CObjectCon* iContainer; |
|
129 CObjectIx* iSubSessions; |
|
130 |
|
131 // Unowned |
|
132 CPairingServer& iPairingServer; |
|
133 }; |
|
134 |
|
135 |
|
136 /** |
|
137 This abstract class provides the base class representation for all subsessions on the |
|
138 pairing server. |
|
139 */ |
|
140 NONSHARABLE_CLASS(CPairingSubSession) |
|
141 : public CObject |
|
142 { |
|
143 public: |
|
144 ~CPairingSubSession(); |
|
145 virtual void DispatchSubSessMessageL(const RMessage2& aMessage) = 0; |
|
146 |
|
147 protected: |
|
148 CPairingSubSession(CPairingSession& aSession); |
|
149 void ConstructL(); |
|
150 |
|
151 CPairingSession& Session() const; |
|
152 |
|
153 private: |
|
154 CPairingSession& iSession; |
|
155 }; |
|
156 |
|
157 |
|
158 /** |
|
159 This is the pairing server sub-session for handling OOB data requests. |
|
160 This covers both inbound OOB data provision, and outbound OOB data retrieval. |
|
161 */ |
|
162 NONSHARABLE_CLASS(COobDataSession) |
|
163 : public CPairingSubSession |
|
164 , private XOobLocalDataObserver |
|
165 { |
|
166 public: |
|
167 static COobDataSession* NewLC(CPairingSession& aSession, COobDataManager& aOobDataManager); |
|
168 ~COobDataSession(); |
|
169 |
|
170 private: |
|
171 COobDataSession(CPairingSession& aSession, COobDataManager& aOobDataManager); |
|
172 |
|
173 void ProvideParsedRemoteOobDataL(const RMessage2& aMessage); |
|
174 void ProvideRawRemoteOobDataL(const RMessage2& aMessage); |
|
175 void ClearRemoteOobDataL(const RMessage2& aMessage); |
|
176 void ReadLocalOobDataL(const RMessage2& aMessage); |
|
177 void CancelReadLocalOobData(const RMessage2& aMessage); |
|
178 |
|
179 void LocalOobDataRetrievedL(const TBluetoothSimplePairingHash& aHash, const TBluetoothSimplePairingRandomizer& aRandomizer); |
|
180 |
|
181 void TryCancelReadLocalOobData(); |
|
182 |
|
183 COobDataManager& OobDataManager() const; |
|
184 |
|
185 private: // from CPairingSubSession |
|
186 void DispatchSubSessMessageL(const RMessage2& aMessage); |
|
187 |
|
188 private: // from XOobLocalDataObserver |
|
189 void XoldoLocalOobDataRetrieved(TInt aResult, const TBluetoothSimplePairingHash& aHash, const TBluetoothSimplePairingRandomizer& aRandomizer); |
|
190 |
|
191 private: // unowned |
|
192 COobDataManager& iOobDataManager; |
|
193 |
|
194 private: // owned |
|
195 RMessage2 iReadLocalOobDataMsg; |
|
196 }; |
|
197 |
|
198 /** |
|
199 This is the pairing server sub-session for handling dedicated bonding requests. |
|
200 To the client side this represents a single dedicated bond attempt... |
|
201 */ |
|
202 NONSHARABLE_CLASS(CDedicatedBondingSession) |
|
203 : public CPairingSubSession |
|
204 , public MAccessRequestResponseHandler |
|
205 , public MSocketNotify |
|
206 { |
|
207 public: |
|
208 static CDedicatedBondingSession* NewLC(CPairingSession& aSession, CPhysicalLinksManager& aPhysicalLinksManager); |
|
209 ~CDedicatedBondingSession(); |
|
210 |
|
211 private: |
|
212 CDedicatedBondingSession(CPairingSession& aSession, CPhysicalLinksManager& aPhysicalLinksManager); |
|
213 void ConstructL(); |
|
214 |
|
215 void StartBondingL(const RMessage2& aMessage); |
|
216 void DoAccessRequestL(); |
|
217 void ConnectCompleteL(); |
|
218 void Shutdown(); |
|
219 |
|
220 void Complete(TInt aError); |
|
221 |
|
222 static void CleanupStartMessage(TAny* aPtr); |
|
223 static TInt StaticShutdown(TAny* aPtr); |
|
224 |
|
225 private: // from CPairingSubSession |
|
226 void DispatchSubSessMessageL(const RMessage2& aMessage); |
|
227 |
|
228 private: // from MAccessRequestResponseHandler |
|
229 void AccessRequestComplete(TInt aResult); |
|
230 |
|
231 private: // from MSocketNotify |
|
232 void NewData(TUint aCount); |
|
233 void CanSend(); |
|
234 void ConnectComplete(); |
|
235 void ConnectComplete(const TDesC8& aConnectData); |
|
236 void ConnectComplete(CServProviderBase& aSSP); |
|
237 void ConnectComplete(CServProviderBase& aSSP, const TDesC8& aConnectData); |
|
238 void CanClose(TDelete aDelete=EDelete); |
|
239 void CanClose(const TDesC8& aDisconnectData, TDelete aDelete=EDelete); |
|
240 void Error(TInt aError, TUint anOperationMask=EErrorAllOperations); |
|
241 void Disconnect(void); |
|
242 void Disconnect(TDesC8& aDisconnectData); |
|
243 void IoctlComplete(TDesC8* aBuf); |
|
244 void NoBearer(const TDesC8& aConnectionParams); |
|
245 void Bearer(const TDesC8& aConnectionInfo); |
|
246 |
|
247 private: |
|
248 enum TState |
|
249 { |
|
250 EInvalid, |
|
251 EInitialConnectionPending, |
|
252 EInitialConnection, |
|
253 EZombie, |
|
254 EFinalConnectionPending, |
|
255 EFinalConnection, |
|
256 EShutdown, |
|
257 }; |
|
258 |
|
259 private: |
|
260 TState iState; |
|
261 |
|
262 private: // unowned |
|
263 CPhysicalLinksManager& iPhysicalLinksManager; |
|
264 |
|
265 private: // owned |
|
266 RMessage2 iStartBondingMsg; |
|
267 CBTProxySAP* iProxySap; |
|
268 CAsyncCallBack* iAsyncShutdown; |
|
269 }; |
|
270 |
|
271 |
|
272 NONSHARABLE_CLASS(CSimplePairingResultSession) |
|
273 : public CPairingSubSession |
|
274 , public MBluetoothSecurityResultObserver |
|
275 { |
|
276 public: |
|
277 static CSimplePairingResultSession* NewLC(CPairingSession& aSession, CSimplePairingResultList& aResultList); |
|
278 ~CSimplePairingResultSession(); |
|
279 |
|
280 private: |
|
281 CSimplePairingResultSession(CPairingSession& aSession, CSimplePairingResultList& aResultList); |
|
282 void ConstructL(); |
|
283 |
|
284 void SimplePairingResultL(const RMessage2& aMessage); |
|
285 void CancelSimplePairingResult(const RMessage2& aMessage); |
|
286 |
|
287 void ReturnResultL(const TBTDevAddr& aDevAddr); |
|
288 |
|
289 private: // from CPairingSubSession |
|
290 void DispatchSubSessMessageL(const RMessage2& aMessage); |
|
291 |
|
292 private: // from MBluetoothSecurityResultObserver |
|
293 TInt MbsroResult(const TBTDevAddr& aDevAddr, TInt aResult); |
|
294 |
|
295 private: // unowned |
|
296 CSimplePairingResultList& iResultList; |
|
297 |
|
298 private: // owned |
|
299 RMessage2 iResultMsg; |
|
300 }; |
|
301 |
|
302 |
|
303 |
|
304 NONSHARABLE_CLASS(CAuthenticationResultSession) |
|
305 : public CPairingSubSession |
|
306 , public MBluetoothSecurityResultObserver |
|
307 { |
|
308 public: |
|
309 static CAuthenticationResultSession* NewLC(CPairingSession& aSession, CAuthenticationResultList& aResultList); |
|
310 ~CAuthenticationResultSession(); |
|
311 |
|
312 private: |
|
313 CAuthenticationResultSession(CPairingSession& aSession, CAuthenticationResultList& aResultList); |
|
314 void ConstructL(); |
|
315 |
|
316 void AuthenticationResultL(const RMessage2& aMessage); |
|
317 void CancelAuthenticationResult(const RMessage2& aMessage); |
|
318 |
|
319 void ReturnResultL(const TBTDevAddr& aDevAddr); |
|
320 |
|
321 private: // from CPairingSubSession |
|
322 void DispatchSubSessMessageL(const RMessage2& aMessage); |
|
323 |
|
324 private: // from MBluetoothSecurityResultObserver |
|
325 TInt MbsroResult(const TBTDevAddr& aDevAddr, TInt aResult); |
|
326 |
|
327 private: // unowned |
|
328 CAuthenticationResultList& iResultList; |
|
329 |
|
330 private: // owned |
|
331 RMessage2 iResultMsg; |
|
332 }; |
|
333 |
|
334 |
|
335 #endif // PAIRINGSERVER_H |
|
336 |