|
1 // Copyright (c) 2006-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 PHYSICALLINKSMANAGER_H_ |
|
17 #define PHYSICALLINKSMANAGER_H_ |
|
18 |
|
19 #include "MBtHostControllerEventInternalNotifier.h" |
|
20 #include "linkmuxer.h" |
|
21 #include "linkmgr.h" |
|
22 #include "bluetooth/physicallinksstate.h" |
|
23 #include "RegistryHelpers.h" |
|
24 #include "pairingscache.h" |
|
25 |
|
26 #include <bt_sock.h> |
|
27 |
|
28 static const TInt KBTBasebandConnectionArrayGranularity = 4; |
|
29 static const TInt KBTStateChangeSubscriberArrayGranularity = 2; |
|
30 |
|
31 class CBTBasebandModel; |
|
32 class CHCIFacade; |
|
33 class CBTSecMan; |
|
34 class RBTRegServ; |
|
35 class CPhysicalLink; |
|
36 class CBTProxySAP; |
|
37 class MPINCodeResponseHandler; |
|
38 class MLinkKeyResponseHandler; |
|
39 class MLogicalLink; |
|
40 |
|
41 struct TLogicalLinkListener; |
|
42 class CRoleSwitcher; |
|
43 class CRoleSwitcherStateFactory; |
|
44 |
|
45 NONSHARABLE_CLASS(TPageTimeoutController) : public MHCICommandQueueClient |
|
46 { |
|
47 public: |
|
48 TPageTimeoutController(MHCICommandQueue& aCommandQueue); |
|
49 void Abort(); |
|
50 |
|
51 void WritePageTimeout(TBasebandTime aPageTimeout); |
|
52 |
|
53 private: // events from MHCICommandQueueClient |
|
54 virtual void MhcqcCommandEventReceived(const THCIEventBase& aEvent, const CHCICommandBase* aRelatedCommand); |
|
55 virtual void MhcqcCommandErrored(TInt aErrorCode, const CHCICommandBase* aCommand); |
|
56 |
|
57 private: |
|
58 void WritePageTimeoutL(TBasebandTime aPageTimeout); |
|
59 |
|
60 private: |
|
61 MHCICommandQueue& iCommandQueue; |
|
62 TInt iOutstandingCommands; |
|
63 TInt iLastCommandId; |
|
64 }; |
|
65 |
|
66 |
|
67 NONSHARABLE_CLASS(CBluetoothPrefetchManager) |
|
68 : public CBase |
|
69 , public MPINCodeResponseHandler |
|
70 { |
|
71 public: |
|
72 static CBluetoothPrefetchManager* NewL(); |
|
73 ~CBluetoothPrefetchManager(); |
|
74 |
|
75 TInt HandleOverPinRequester(const TBTDevAddr& aAddr, CBTPinRequester* aPinRequester); |
|
76 TInt RegisterForPrefetching(const TBTDevAddr& aAddr, MBluetoothPrefetchNotifier& aNotifier); |
|
77 |
|
78 TBool IsPrefetchAvailable(const TBTDevAddr& aAddr, TBTPinCode& aPinCode); |
|
79 |
|
80 private: |
|
81 NONSHARABLE_CLASS(RPinRequest) |
|
82 { |
|
83 friend class CBluetoothPrefetchManager; |
|
84 public: |
|
85 RPinRequest(); |
|
86 TInt Create(const TBTDevAddr& aAddr, CBTPinRequester* aPinRequester); |
|
87 void AddNotifier(MBluetoothPrefetchNotifier& aNotifier); |
|
88 TBool NotifiersWaiting() const; |
|
89 void CompleteRequest(TInt aResult); |
|
90 |
|
91 private: |
|
92 TBTDevAddr iAddr; |
|
93 CBTPinRequester* iPinRequester; |
|
94 TDblQue<TPrefetchNotifierQLink>* iNotifiers; |
|
95 }; |
|
96 |
|
97 NONSHARABLE_STRUCT(TPrefetchedPin) |
|
98 { |
|
99 TBTDevAddr iAddr; |
|
100 TBTPinCode iPin; |
|
101 }; |
|
102 |
|
103 private: |
|
104 CBluetoothPrefetchManager(); |
|
105 |
|
106 static TBool CompareAddressInRequest(const TBTDevAddr* aDevAddr, const RPinRequest& aRequest); |
|
107 static TBool CompareAddressInStore(const TBTDevAddr* aDevAddr, const TPrefetchedPin& aRequest); |
|
108 |
|
109 private: // from MPINCodeResponseHandler |
|
110 TInt PINCodeRequestReply(const TBTDevAddr& aDevAddr, const TDesC8& aPin) const; |
|
111 TInt PINCodeRequestNegativeReply(const TBTDevAddr& aDevAddr) const; |
|
112 |
|
113 private: |
|
114 mutable RArray<RPinRequest> iPinRequesters; |
|
115 mutable RArray<TPrefetchedPin> iPrefetchedPins; |
|
116 }; |
|
117 |
|
118 |
|
119 NONSHARABLE_CLASS(CPhysicalLinksManager) : public CBase, |
|
120 public MBtHostControllerEventInternalNotifier, |
|
121 public MBTPairingsCacheObserver |
|
122 /** |
|
123 Manages CPhysicalLink objects. |
|
124 One connections manager exists to take care of all CPhysicalLink objects. |
|
125 */ |
|
126 { |
|
127 public: |
|
128 |
|
129 static CPhysicalLinksManager* NewL(CLinkMgrProtocol& aLinkMgrProtocol, |
|
130 CHCIFacade& aHCIFacade, |
|
131 CRegistrySession& aRegSess, |
|
132 CBTSecMan& aSecMan, |
|
133 CBTCodServiceMan& aCodMan); |
|
134 ~CPhysicalLinksManager(); |
|
135 inline CBTSecMan& SecMan() const; |
|
136 inline CBTCodServiceMan& CodMan() const; |
|
137 inline CBTBasebandModel& Baseband() const; |
|
138 CPhysicalLink& NewPhysicalLinkL(const TBTDevAddr& aDevice); // factory function |
|
139 CPhysicalLink& NewPhysicalLinkL(const TBTNamelessDevice& aDevice); // factory function |
|
140 void AuthenticateL(const TBTDevAddr& aBDAddr); |
|
141 void EncryptL(const TBTDevAddr& aBDAddr); |
|
142 |
|
143 void RemovePhysicalLink(const CPhysicalLink& aConnection); |
|
144 TInt AddListener(MLogicalLink& aLogicalLink, TPhysicalLinkPort aPort); |
|
145 void RemoveListener(MLogicalLink& aLogicalLink); |
|
146 void ClearTerminatingProxy(CBTProxySAP* aProxySAP); |
|
147 TInt TerminateAllPhysicalLinks(CBTProxySAP* aProxySAP); |
|
148 TInt TerminatePhysicalLink(CPhysicalLink* aConnection, CBTProxySAP* aProxySAP); |
|
149 |
|
150 void FatalError(TInt aErr); |
|
151 void UpdateRemoteDevicesDetails(); |
|
152 TInt RefreshPairedBDAddrs(); |
|
153 |
|
154 void SetAcceptPairedOnlyMode(TBool aOn); |
|
155 void SetSimplePairingDebugMode(TBool aOn); |
|
156 |
|
157 void SimplePairingDebugModeChanged(TBool aOn); |
|
158 |
|
159 inline TInt NumberOfPhysicalLinks() const; |
|
160 void EnumeratePhysicalLinks(TDes8& aPackagedArray); |
|
161 void DumpPhysicalLinks(); |
|
162 TBool IsAcceptPairedOnlyMode(); |
|
163 |
|
164 void RequireSlotSpace(); // for HostResolver (or others) who need to reduce connection commitments |
|
165 TBasebandTime TryToChangePageTimeout(TBasebandTime aPageTimeout); |
|
166 |
|
167 // role change methods to control locally initiated requests |
|
168 void AddRoleSwitcher(CRoleSwitcher& aRoleSwitcher); |
|
169 // This method must be called only from the D'tor of CRoleSwitcher |
|
170 void RemoveRoleSwitcher(CRoleSwitcher& aRoleSwitcher); |
|
171 // to enable to generate BTBaseband event, RoleChange error in case of RoleChange |
|
172 // command was 'not allowed' by HW |
|
173 void RoleChangeRejectedByHW(THCIErrorCode aErr); |
|
174 CRoleSwitcherStateFactory& RoleSwitcherStateFactory() const; |
|
175 |
|
176 public: |
|
177 |
|
178 |
|
179 // events from MBtHostControllerEventInternalNotifier |
|
180 virtual void ConnectionComplete(THCIErrorCode aErr, const TBTConnect& aConn); |
|
181 virtual void ConnectionRequest(const TBTConnect& aConn); |
|
182 virtual void Disconnection(THCIErrorCode aErr, THCIConnHandle aConnH, THCIErrorCode aResult); |
|
183 virtual void CompletedPackets(THCIConnHandle aConnH, TUint16 aNumPackets); |
|
184 virtual void AuthenticationComplete(THCIErrorCode aErr, THCIConnHandle aConnH); |
|
185 virtual void EncryptionChange(THCIErrorCode aErr, THCIConnHandle aConnH,TBool aEncrypted); |
|
186 virtual void ACLDataReceived(THCIConnHandle aConnH, TUint8 aFlag, const TDesC8& aData); |
|
187 virtual void SCODataReceived(THCIConnHandle aConnH, const TDesC8& aData); |
|
188 virtual void SynchronousConnectionComplete(THCIErrorCode aErr, const TBTConnect& aConn, const TBTSyncConnectOpts& aSyncOpts); |
|
189 virtual void PinRequest(const TBTDevAddr& aBDAddr, MPINCodeResponseHandler& aRequester); |
|
190 virtual void NewLinkKey(const TBTDevAddr& aBDAddr, const TBTLinkKey& aLinkKey, THCILinkKeyType aLinkKeyType); |
|
191 virtual void LinkKeyRequest(const TBTDevAddr& aBDAddr, MLinkKeyResponseHandler& aRequester); |
|
192 virtual void ReadRemoteSupportedFeaturesComplete(THCIErrorCode aErr, THCIConnHandle aConnH, const TBTFeatures& aBitMask); |
|
193 virtual void ReadRemoteExtendedFeaturesComplete(THCIErrorCode aErr, THCIConnHandle aConnH, TUint64 aBitMask, TUint8 aPageNumber, TUint8 aMaximimPageNumber); |
|
194 virtual void ReadRemoteVersionInfoComplete(THCIErrorCode aErr, THCIConnHandle aConnH, const TBTDevRemoteHwVersion& aVer); |
|
195 virtual void PacketTypeChange(THCIErrorCode aErr, THCIConnHandle aConnH, TUint16 aNewPacket); |
|
196 virtual void LinkSupervisionTimeoutChange(THCIErrorCode aErr, THCIConnHandle aConnH, TUint16 aNewTimeout); |
|
197 virtual void MaxSlotsChange(THCIConnHandle aConnH, TUint8 aSlots); |
|
198 virtual void ModeChange(THCIErrorCode aErr, THCIConnHandle aConnH, TBTLinkMode aMode, TBasebandTime aInterval); |
|
199 virtual void WriteLinkPolicySettingsCompleteEvent(THCIErrorCode aErr, THCIConnHandle aConnH); |
|
200 virtual void RoleChange(THCIErrorCode aErr, const TBTDevAddr& aAddr, TBTBasebandRole aRole); |
|
201 virtual void ClockOffset(THCIErrorCode aErr, THCIConnHandle aConnH, TBasebandTime aClockOffset); |
|
202 virtual void RemoteName(THCIErrorCode aErr, const TBTDevAddr& aAddr, const TBTDeviceName8& aName); |
|
203 virtual void SimplePairingComplete(const TBTDevAddr& aBDAddr, THCIErrorCode aErr); |
|
204 |
|
205 // events from MBTPairingsCacheObserver |
|
206 virtual void MbpcoDeferredDecisionResolved(TInt aError); |
|
207 |
|
208 // Getters |
|
209 inline CHCIFacade& HCIFacade() const; |
|
210 inline CLinkMgrProtocol& LinkManagerProtocol() const; |
|
211 inline CBTPairingsCache& PairingsCache() const; |
|
212 inline CBluetoothPrefetchManager& PrefetchMan() const; |
|
213 |
|
214 CPhysicalLink* FindPhysicalLink() const; // mainly for finding random coonected PHY for proxy SAP |
|
215 CPhysicalLink* FindPhysicalLink(THCIConnHandle aConnH) const; // mainly for LinkMgrProtocol |
|
216 CPhysicalLink* FindPhysicalLink(const TBTDevAddr& aBDAddr) const; |
|
217 TLogicalLinkListener* FindListener(TPhysicalLinkPort aPort); |
|
218 |
|
219 TInt ChangeMode(TBTLinkMode aMode, THCIConnHandle aConnHandle); |
|
220 TInt ExitMode(TBTLinkMode aMode, THCIConnHandle aConnHandle); |
|
221 TInt ChangeRole(TBTBasebandRole aRole, CPhysicalLink& aPhysicalLink); |
|
222 TInt Encrypt(TBool aEnable, CPhysicalLink& aPhysicalLink); |
|
223 |
|
224 TBool ActiveConnectRoleSwitchAllowed() const; |
|
225 TBool PassiveConnectBecomeMaster() const; |
|
226 TBool RoleSwitchAllowed() const; |
|
227 |
|
228 void ArbitrateAllPhysicalLinks(); |
|
229 |
|
230 TInt GetConnectionHandles(RHCIConnHandleArray& aConnectionHandles, TLinkType aLinkType) const; |
|
231 TInt GetNumPendingHandles(TInt& aConnectionHandles, TLinkType aLinkType) const; |
|
232 TInt GetConnectionHandles(RHCIConnHandleArray& aConnectionHandles, TLinkType aLinkType, const TBTDevAddr& aBDAddr) const; |
|
233 TInt GetNumPendingHandles(TInt& aConnectionHandles, TLinkType aLinkType, const TBTDevAddr& aBDAddr) const; |
|
234 TInt GetRemoteAddress(TBTDevAddr& aBDAddr, THCIConnHandle aConnectionHandle) const; |
|
235 TInt GetRemoteDeviceClass(TBTDeviceClass& aDeviceClass, const TBTDevAddr& aBDAddr) const; |
|
236 TInt GetRemoteSupportedFeatures(TBTFeatures& aRemoteSupportedFeatures, const TBTDevAddr& aBDAddr) const; |
|
237 TInt GetLinkPolicySettings(TLinkPolicy& aLinkPolicySettings, const TBTDevAddr& aBDAddr) const; |
|
238 TInt GetBasebandLinkState(TBTBasebandLinkState& aBasebandLinkState, const TBTDevAddr& aBDAddr) const; |
|
239 |
|
240 private: |
|
241 |
|
242 CPhysicalLinksManager(CLinkMgrProtocol& aLinkMgrProtocol, |
|
243 CHCIFacade& aHCIFacade, |
|
244 CRegistrySession& aRegSess, CBTSecMan& aSecMan, CBTCodServiceMan& aCodMan); |
|
245 void ConstructL(); |
|
246 void CancelPendingConnections(THCIErrorCode aErr, const TBTConnect& aConn); |
|
247 void DoConnectionRequestL(const TBTConnect& aConn); |
|
248 static TBool ListenerMatch(const TLogicalLinkListener& aA, const TLogicalLinkListener& aB); |
|
249 void UpdateTerminatingProxy(CBTProxySAP* aProxySAP); |
|
250 |
|
251 TBasebandTime CheckPageTimeoutAgainstLSTO(TBasebandTime aPageTimeout); |
|
252 |
|
253 private: |
|
254 RPointerArray<CPhysicalLink> iPhysicalLinks; |
|
255 |
|
256 CHCIFacade& iHCIRequestHandler; |
|
257 CRegistrySession& iRegSess; // we don't "own" an "access". |
|
258 CBTSecMan& iSecMan; |
|
259 CBTCodServiceMan& iCodMan; |
|
260 CLinkMgrProtocol& iLinkManagerProtocol; |
|
261 |
|
262 CBTProxySAP* iTerminatingProxy; // unowned |
|
263 CPhysicalLink* iTerminatingConnection; // unowned |
|
264 |
|
265 CBTBasebandModel* iBaseband; |
|
266 RArray<TLogicalLinkListener> iListeners; |
|
267 |
|
268 // role change control variables |
|
269 TSglQue<CRoleSwitcher> iRoleSwitchersQ; |
|
270 CRoleSwitcherStateFactory* iRoleSwitcherStateFactory; |
|
271 |
|
272 TBool iAcceptPairedOnlyMode; |
|
273 CBTPairingsCache* iPairingsCache; |
|
274 |
|
275 TPageTimeoutController iPageTimeoutController; |
|
276 CBluetoothPrefetchManager* iPrefetchMan; |
|
277 }; |
|
278 |
|
279 inline CLinkMgrProtocol& CPhysicalLinksManager::LinkManagerProtocol() const |
|
280 { |
|
281 return iLinkManagerProtocol; |
|
282 } |
|
283 |
|
284 inline CHCIFacade& CPhysicalLinksManager::HCIFacade() const |
|
285 { |
|
286 return iHCIRequestHandler; |
|
287 } |
|
288 |
|
289 inline CBTSecMan& CPhysicalLinksManager::SecMan() const |
|
290 { |
|
291 return iSecMan; |
|
292 } |
|
293 |
|
294 inline CBTBasebandModel& CPhysicalLinksManager::Baseband() const |
|
295 { |
|
296 return *iBaseband; |
|
297 } |
|
298 |
|
299 inline TInt CPhysicalLinksManager::NumberOfPhysicalLinks() const |
|
300 { |
|
301 return iPhysicalLinks.Count(); |
|
302 } |
|
303 |
|
304 inline CBTCodServiceMan& CPhysicalLinksManager::CodMan() const |
|
305 { |
|
306 return iCodMan; |
|
307 } |
|
308 |
|
309 inline CBTPairingsCache& CPhysicalLinksManager::PairingsCache() const |
|
310 { |
|
311 return *iPairingsCache; |
|
312 } |
|
313 |
|
314 inline CRoleSwitcherStateFactory& CPhysicalLinksManager::RoleSwitcherStateFactory() const |
|
315 { |
|
316 return *iRoleSwitcherStateFactory; |
|
317 } |
|
318 |
|
319 inline CBluetoothPrefetchManager& CPhysicalLinksManager::PrefetchMan() const |
|
320 { |
|
321 return *iPrefetchMan; |
|
322 } |
|
323 |
|
324 #endif //PHYSICALLINKSMANAGER |