|
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 // Defines the LinkMgr protocol class |
|
15 // |
|
16 // |
|
17 |
|
18 #ifndef LINKMGR_H |
|
19 #define LINKMGR_H |
|
20 |
|
21 #include <e32property.h> |
|
22 #include <es_prot.h> |
|
23 #include <bt_sock.h> |
|
24 #include "notification.h" |
|
25 #include <btextnotifiers.h> |
|
26 #include <bluetooth/hci/hcishared.h> |
|
27 #include <bluetooth/hci/hcitypes.h> |
|
28 #include "btfeatures.h" |
|
29 #include "secman.h" |
|
30 #include "linkmuxer.h" |
|
31 #include "bt.h" |
|
32 #include "btconsts.h" |
|
33 #include "internaltypes.h" |
|
34 #include <bluetooth/lmoptions.h> |
|
35 #include <es_prot_internal.h> |
|
36 #include <bt_subscribe_partner.h> |
|
37 |
|
38 |
|
39 class CBTProtocolFamily; |
|
40 class CLinkMgrProtocol; |
|
41 class CBTInquiryMgr; |
|
42 class CHCIFacade; |
|
43 class CLinkMuxer; |
|
44 class CACLDataQController; |
|
45 class CBTSecMan; |
|
46 class CPhysicalLinksManager; |
|
47 class CACLLinkStateFactory; |
|
48 class CSyncLinkStateFactory; |
|
49 class CSubscriber; |
|
50 class CVendorSAP; |
|
51 class CHCIDirectAccessSAPsManager; |
|
52 class CEirManServer; |
|
53 class CEirPublisherTxPowerLevel; |
|
54 class CEirPublisherLocalName; |
|
55 |
|
56 NONSHARABLE_CLASS(CRegistrySession) |
|
57 : public CBase |
|
58 { |
|
59 friend class CLinkMgrProtocol; |
|
60 public: |
|
61 void Open(); |
|
62 void Close(); |
|
63 |
|
64 RBTRegServ& RegServ(); |
|
65 |
|
66 private: // for use by CLinkMgrProtocol |
|
67 static CRegistrySession* NewL(CLinkMgrProtocol& aLinkMgrProtocol); |
|
68 ~CRegistrySession(); |
|
69 |
|
70 CRegistrySession(CLinkMgrProtocol& aLinkMgrProtocol); |
|
71 void ConstructL(); |
|
72 |
|
73 private: |
|
74 TInt iAccessCount; |
|
75 RBTRegServ iRegServ; |
|
76 CLinkMgrProtocol& iLinkMgrProtocol; |
|
77 }; |
|
78 |
|
79 NONSHARABLE_CLASS(TBTTrackedLocalDevice) : public TBTLocalDevice |
|
80 { |
|
81 public: |
|
82 void SetAddress(const TBTDevAddr& aAddr); |
|
83 void SetDeviceClass(TUint32 aCod); |
|
84 void SetDeviceName(const TDesC8& aName); |
|
85 void SetScanEnable(THCIScanEnable aEnable); |
|
86 void SetLimitedDiscoverable(TBool aOn); |
|
87 void SetPowerSetting(TUint8 aPowerSetting); |
|
88 void SetAFHChannelAssessmentMode(TBool aOn); |
|
89 void SetAcceptPairedOnlyMode(TBool aOn); |
|
90 |
|
91 void Modify(TBTLocalDevice& aLocalDeviceSettings); |
|
92 void ResetChangesMask(); |
|
93 |
|
94 private: |
|
95 void StoreChange(TUint8 aChange); |
|
96 |
|
97 private: |
|
98 TUint8 iChangedSettings; |
|
99 }; |
|
100 |
|
101 NONSHARABLE_CLASS(CRegistryUpdater) : public CActive |
|
102 { |
|
103 public: |
|
104 ~CRegistryUpdater(); |
|
105 CRegistryUpdater(RBTLocalDevice& aLocalDevice, TBTTrackedLocalDevice& aSettings); |
|
106 void Update(); |
|
107 private: |
|
108 void RunL(); |
|
109 void DoCancel(); |
|
110 private: |
|
111 RBTLocalDevice& iLocalDevice; |
|
112 TBTTrackedLocalDevice& iStackSettings; |
|
113 TBTLocalDevice iRegistrySettings; |
|
114 TBool iRepeatUpdate; |
|
115 }; |
|
116 |
|
117 |
|
118 NONSHARABLE_CLASS(CLinkMgrProtocol) : public CBluetoothProtocolBase |
|
119 { |
|
120 public: |
|
121 // Create ourselves |
|
122 static CLinkMgrProtocol* NewL(CBTSecMan& aSecMan, RBTControlPlane& aControlPlane, CBTCodServiceMan& aCodMan); |
|
123 static void ProtocolIdentity(TServerProtocolDesc* aDesc); |
|
124 |
|
125 void LocalOpen(); |
|
126 void LocalClose(); |
|
127 |
|
128 void Error(TInt anError,CProtocolBase* aSourceProtocol=NULL); |
|
129 |
|
130 private: // From CProtocolBase |
|
131 // Factories |
|
132 CHostResolvProvdBase* NewHostResolverL(); |
|
133 CServProviderBase* NewSAPL(TUint aSockType); |
|
134 |
|
135 // Ref Counting |
|
136 void Close(); |
|
137 void Open(); |
|
138 void CloseNow(); |
|
139 |
|
140 // Others |
|
141 void InitL(TDesC &aTag); // From ProtocolManager before all binding. |
|
142 void StartL(); // From Protocol Manager - after all binding |
|
143 void BindL(CProtocolBase* protocol, TUint id); |
|
144 void Identify(TServerProtocolDesc* aDesc)const; // Query function |
|
145 |
|
146 private: // from CBluetoothProtocolBase |
|
147 TInt BearerConnectComplete(const TBTDevAddr& /*aAddr*/, CServProviderBase* /*aSAP*/) {return KErrNotSupported;}; |
|
148 TInt ControlPlaneMessage(TBTControlPlaneMessage aMessage, TAny* aParam); |
|
149 |
|
150 public: |
|
151 |
|
152 void SetInquiryAndPageScanningL(); |
|
153 void SetAcceptPairedOnlyMode(TBool aOn); |
|
154 void SetSimplePairingDebugMode(TBool aOn); |
|
155 |
|
156 // LinkMgr specific functions |
|
157 inline const TBTDevAddr& LocalBTAddress() const; // Get our local address |
|
158 void SetLocalBTAddress(const TBTDevAddr& aAddr); |
|
159 |
|
160 void SetUIDiscovering(TInt aDiscoveringState); |
|
161 |
|
162 inline CPhysicalLinksManager& PhysicalLinksMgr() const; |
|
163 inline CACLLinkStateFactory& ACLStateFactory() const; |
|
164 inline CSyncLinkStateFactory& SyncStateFactory() const; |
|
165 |
|
166 // later - change local device management/notification to be nicer... |
|
167 inline const TBTLocalDevice& LocalDevice() const; |
|
168 void UpdateLocalDeviceName(const TDesC8& aName); |
|
169 void UpdateLocalDeviceName(TBool aSucceeded); |
|
170 void UpdateLocalDevicePower(TBTPowerState aState); |
|
171 void UpdateLocalDeviceScanEnable(TBool aSucceeded); |
|
172 void UpdateDeviceClass(TBool aSucceeded); |
|
173 void UpdateAFHChannelAssessmentMode(TBool aSucceeded); |
|
174 void UpdateLimitedDiscoverable(TBool aSucceeded); |
|
175 |
|
176 TBTDevHCIVersion GetHWHCIVersion() const; |
|
177 |
|
178 void SetLimitedDiscoverableIfChangedL(TBool aOn); |
|
179 void SetLocalVersion(THCIErrorCode aErr, TBTDevHCIVersion aHCIVersion, TBTDevLMPVersion aLMPVersion); |
|
180 void SetOverrideLPMTimeout(TUint aOverrideLPMTimeout); |
|
181 void SetLocalFeatures(THCIErrorCode aErr, const TBTFeatures& aMask); |
|
182 void SetLocalCommands(THCIErrorCode aErr, const TBluetoothHciCommands& aMask); |
|
183 void SetDeviceClassL(TUint32 aCod); |
|
184 TInt SetLocalDeviceName(const TDesC8& aName); |
|
185 void SetAFHChannelAssessmentModeL(TBool aMode); |
|
186 void SetAFHHostChannelClassificationL(const TBTAFHHostChannelClassification& aChannelClassification); |
|
187 void SetUIConnecting(TBool aConnecting); |
|
188 void SetUINumPhysicalLinks(TUint aNum); |
|
189 void SetUINumSynchronousLinks(TUint aNum); |
|
190 |
|
191 inline CHCIFacade& HCIFacade() const; |
|
192 inline CBTInquiryMgr& InquiryMgr() const; |
|
193 inline CLinkMuxer& LinkMuxer() const; |
|
194 inline CACLDataQController& ACLController() const; |
|
195 TInt ACLPacketMTU() const; |
|
196 |
|
197 inline CVendorSAP* VendorSpecificSAP() const; |
|
198 void UpdateDeviceClass(TBool aSucceeded, TUint aCoD); |
|
199 void WriteClassOfDeviceL(TUint32 aCod); |
|
200 void ClearPendingLocalDeviceSettingsCod(); |
|
201 |
|
202 void UpdateInquiryResponseTxPowerLevel(TInt8 aTxPowerLevel); |
|
203 |
|
204 inline const TBTFeatures& PacketsSupportedLocally() const; |
|
205 inline TUint8 ModesSupportedLocally() const; |
|
206 |
|
207 void LocalSupportedFeaturesAvailable(); |
|
208 |
|
209 inline TBool IsEncryptionSupportedLocally() const; |
|
210 inline TBool IsRoleSwitchSupportedLocally() const; |
|
211 inline TBool IsSecureSimplePairingSupportedLocally() const; |
|
212 inline TBool IsModeSupportedLocally(TBTLinkMode aMode) const; |
|
213 inline TBool IsEncryptionPauseResumeSupportedLocally() const; |
|
214 inline TBool IsExtendedInquiryResponseSupportedLocally() const; |
|
215 inline TBool IsRssiWithInquiryResultsSupportedLocally() const; |
|
216 |
|
217 inline TBool IsCommandSupportedLocally(TBluetoothSupportedCommandsBits aCommand) const; |
|
218 |
|
219 private: |
|
220 CLinkMgrProtocol(CBTSecMan& aSecMan, RBTControlPlane& aControlPlane, CBTCodServiceMan& aCodMan); |
|
221 ~CLinkMgrProtocol(); |
|
222 void DoSetLimitedDiscoverableL(TBool aOn); |
|
223 void QueIdleTimerEntry(); |
|
224 void RemoveIdleTimerEntry(); |
|
225 static TInt TryToClose(TAny* aProtocol); |
|
226 void UpdateSettings(); |
|
227 virtual TInt StartProtocolListening(); |
|
228 virtual void StopProtocolListening(); |
|
229 TInt KickDiscoverabilitySubscriber(); |
|
230 void DefinePublications(THCIScanEnable aHCIScanEnable); |
|
231 void DeletePublications(); |
|
232 |
|
233 void ExternalOpenInit(); |
|
234 void ExternalCloseCleanup(); |
|
235 |
|
236 private: |
|
237 friend class CVendorSAP; |
|
238 friend class CBTCodServiceMan; |
|
239 TInt iExternalRef; |
|
240 |
|
241 // Singleton objects owned |
|
242 CPhysicalLinksManager* iPhysicalLinksMgr; |
|
243 |
|
244 CRegistrySession* iRegSess; // owns an RBTRegServ for sharing. |
|
245 RBTLocalDevice iLocalDevice; //subsession |
|
246 TBTTrackedLocalDevice iLocalDeviceSettings; |
|
247 TBTLocalDevice iPendingLocalDeviceSettings; |
|
248 |
|
249 RProperty iProperty; |
|
250 |
|
251 CBTInquiryMgr* iInquiryMgr; |
|
252 CHCIFacade* iHCIFacade; |
|
253 CLinkMuxer* iLinkMuxer; |
|
254 CEirManServer* iEirManServer; |
|
255 |
|
256 CACLLinkStateFactory* iACLStateFactory; |
|
257 CSyncLinkStateFactory* iSCOStateFactory; |
|
258 |
|
259 RPointerArray<CSubscriber> iSubscribers; |
|
260 |
|
261 TUint iOverrideLPMTimeout; |
|
262 |
|
263 // protocol state objects |
|
264 TBool iClosePending; // the protocol is closing |
|
265 TDeltaTimerEntry iIdleTimerEntry; |
|
266 TBool iIdleEntryQueued; |
|
267 |
|
268 // features of the local hardware that dont need persisting |
|
269 TBTDevAddr iLocalDeviceAddress; |
|
270 TBTDevHCIVersion iHWHCIVersion; |
|
271 TBTDevLMPVersion iHWLMPVersion; |
|
272 TBTFeatures iHWFeatures; |
|
273 TBluetoothHciCommands iHWCommands; |
|
274 |
|
275 CRegistryUpdater* iRegistryUpdater; |
|
276 |
|
277 // non-owned |
|
278 CProtocolBase* iUpperProtocol; // L2CAP |
|
279 CVendorSAP* iVendorSpecificSAP; |
|
280 |
|
281 |
|
282 // Inquiry Response Transmit Power Level value |
|
283 TInt8 iTxPowerLevel; |
|
284 CEirPublisherLocalName* iLocalNamePublisher; |
|
285 CEirPublisherTxPowerLevel* iTxPowerLevelPublisher; |
|
286 |
|
287 TInt iDebugModeDefinitionResult; |
|
288 }; |
|
289 |
|
290 inline const TBTDevAddr& CLinkMgrProtocol::LocalBTAddress() const |
|
291 /** |
|
292 Return the local BT address. |
|
293 This actually might not be set on initial startup, as it |
|
294 takes a finite time to get the local address out of the |
|
295 hardware. But it should not matter, as this local address |
|
296 is not actually used for much (get local address ioctl |
|
297 actually re-reads it from the hardware.) |
|
298 **/ |
|
299 { |
|
300 return iLocalDeviceAddress; |
|
301 } |
|
302 |
|
303 inline CPhysicalLinksManager& CLinkMgrProtocol::PhysicalLinksMgr() const |
|
304 { |
|
305 __ASSERT_DEBUG(iPhysicalLinksMgr, User::Panic(_L("linkmgr.h"), __LINE__)); |
|
306 return *iPhysicalLinksMgr; |
|
307 } |
|
308 |
|
309 inline const TBTLocalDevice& CLinkMgrProtocol::LocalDevice() const |
|
310 { |
|
311 return iLocalDeviceSettings; |
|
312 } |
|
313 |
|
314 inline CBTInquiryMgr& CLinkMgrProtocol::InquiryMgr() const |
|
315 { |
|
316 return *iInquiryMgr; |
|
317 } |
|
318 |
|
319 inline CHCIFacade& CLinkMgrProtocol::HCIFacade() const |
|
320 { |
|
321 return *iHCIFacade; |
|
322 } |
|
323 |
|
324 inline CLinkMuxer& CLinkMgrProtocol::LinkMuxer() const |
|
325 { |
|
326 return *iLinkMuxer; |
|
327 } |
|
328 |
|
329 inline CACLDataQController& CLinkMgrProtocol::ACLController() const |
|
330 { |
|
331 return LinkMuxer().DataQController(); |
|
332 } |
|
333 |
|
334 inline CACLLinkStateFactory& CLinkMgrProtocol::ACLStateFactory() const |
|
335 { |
|
336 return *iACLStateFactory; |
|
337 } |
|
338 |
|
339 inline CSyncLinkStateFactory& CLinkMgrProtocol::SyncStateFactory() const |
|
340 { |
|
341 return *iSCOStateFactory; |
|
342 } |
|
343 |
|
344 inline CVendorSAP* CLinkMgrProtocol::VendorSpecificSAP() const |
|
345 { |
|
346 return iVendorSpecificSAP; |
|
347 } |
|
348 |
|
349 inline TUint8 CLinkMgrProtocol::ModesSupportedLocally() const |
|
350 { |
|
351 // baseband spec: |
|
352 // mode support is --------|-------x|xx------ |
|
353 // **this method returns it in lowest bits of a uint8** |
|
354 return TUint8(iHWFeatures.LinkModes()); |
|
355 } |
|
356 |
|
357 inline const TBTFeatures& CLinkMgrProtocol::PacketsSupportedLocally() const |
|
358 { |
|
359 // not masking for now - disparate bits and in future have EV packets |
|
360 return iHWFeatures; |
|
361 } |
|
362 |
|
363 inline TBool CLinkMgrProtocol::IsModeSupportedLocally(TBTLinkMode aMode) const |
|
364 { |
|
365 // bits 6 to 8 show us modes supported |
|
366 return iHWFeatures.IsModeSupported(aMode); |
|
367 } |
|
368 |
|
369 inline TBool CLinkMgrProtocol::IsRoleSwitchSupportedLocally() const |
|
370 { |
|
371 return iHWFeatures.IsRoleSwitchSupported(); |
|
372 } |
|
373 |
|
374 inline TBool CLinkMgrProtocol::IsEncryptionSupportedLocally() const |
|
375 { |
|
376 return iHWFeatures.IsEncryptionSupported(); |
|
377 } |
|
378 |
|
379 inline TBool CLinkMgrProtocol::IsExtendedInquiryResponseSupportedLocally() const |
|
380 { |
|
381 return iHWFeatures.IsExtendedInquiryResponseSupported(); |
|
382 } |
|
383 |
|
384 inline TBool CLinkMgrProtocol::IsRssiWithInquiryResultsSupportedLocally() const |
|
385 { |
|
386 return iHWFeatures.IsRssiWithInquiryResultsSupported(); |
|
387 } |
|
388 |
|
389 inline TBool CLinkMgrProtocol::IsSecureSimplePairingSupportedLocally() const |
|
390 { |
|
391 return iHWFeatures.IsSecureSimplePairingSupported(); |
|
392 } |
|
393 |
|
394 inline TBool CLinkMgrProtocol::IsEncryptionPauseResumeSupportedLocally() const |
|
395 { |
|
396 return iHWFeatures.IsEncryptionPauseResumeSupported(); |
|
397 } |
|
398 |
|
399 inline TBool CLinkMgrProtocol::IsCommandSupportedLocally(TBluetoothSupportedCommandsBits aCommand) const |
|
400 { |
|
401 return iHWCommands[aCommand]; |
|
402 } |
|
403 |
|
404 #endif |