bluetooth/btstack/linkmgr/physicallinks.h
changeset 0 29b1cd4cb562
child 3 4e39398d58ed
equal deleted inserted replaced
-1:000000000000 0:29b1cd4cb562
       
     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 _PHYSICALLINKS_H
       
    17 #define _PHYSICALLINKS_H
       
    18 
       
    19 #include "linkmgr.h"
       
    20 #include "RegistryHelpers.h"
       
    21 #include "MBtHostControllerEventInternalNotifier.h"
       
    22 #include "basebandsap.h"
       
    23 #include "bluetooth/physicallinksstate.h"
       
    24 #include "physicallinkmetrics.h"
       
    25 
       
    26 #include <bt_sock.h>
       
    27 #include <btmanclient.h>
       
    28 #include <bluetooth/hcicommandqueueclient.h>
       
    29 #include <bluetooth/hcicmdqcontroller.h>
       
    30 
       
    31 
       
    32 static const TBTDevRemoteHwVersion KInvalidRemoteHwVersion={0xFF};
       
    33 static const TUint64 KInvalidRemoteFeatures = KMaxTUint64; 
       
    34 
       
    35 static const TInt KBTArbitrationDelay = 1000000;	// 1s
       
    36 
       
    37 class CPhysicalLink;
       
    38 class CBTSynchronousLink;
       
    39 class CBTProxySAP;
       
    40 class MPINCodeResponseHandler;
       
    41 class MLinkKeyResponseHandler;
       
    42 class CBTRegistryHelperBase;
       
    43 class MPhysicalLinkObserver;
       
    44 class CBTPinRequester;
       
    45 class CACLLink;
       
    46 class CRoleSwitcher;
       
    47 class CBTNumericComparator;
       
    48 class CBTPasskeyEntry;
       
    49 
       
    50 enum TPhysicalLinkSimplePairingMode
       
    51 	{
       
    52 	EPhySimplePairingUndefined,
       
    53 	EPhySimplePairingDisabled,
       
    54 	EPhySimplePairingEnabled,
       
    55 	};
       
    56 
       
    57 enum TAuthStates
       
    58 	{
       
    59 	EAuthenticationRequestPending = 0x1,
       
    60 	ELinkKeyRequestPending = 0x2,
       
    61 	EPinRequestPending = 0x4,
       
    62 	ESimplePairingPending = 0x8,
       
    63 	};	
       
    64 
       
    65 NONSHARABLE_CLASS(CArbitrationDelayTimer) : public CTimer
       
    66 /**
       
    67 	This class provides a timer which is used when the physical link goes into active mode
       
    68 	to prevent an early switch back into a low power mode.
       
    69 **/
       
    70 	{
       
    71 public:
       
    72 	static CArbitrationDelayTimer* NewL(CPhysicalLink* aParent);
       
    73 	void Start();
       
    74 	
       
    75 private:
       
    76 	CArbitrationDelayTimer(CPhysicalLink* aParent);
       
    77 	void ConstructL();
       
    78 	void RunL();
       
    79 	
       
    80 public:	
       
    81 	CPhysicalLink* 	iParent;
       
    82 	};
       
    83 
       
    84 
       
    85 NONSHARABLE_STRUCT(TLogicalLinkListener)
       
    86 	{
       
    87 	MLogicalLink*		iObserver;
       
    88 	TPhysicalLinkPort	iPort;
       
    89 	};
       
    90 
       
    91 /**
       
    92 	The following class controls low power mode command requests and related events. 
       
    93 	It bypasses HCI_Facade to keep deep control of all events including errors. 
       
    94 	Its aim is also to forbid having more than one outstanding low power mode command.
       
    95 	It doesn't manage the trasmission of the "cancel" command when the other one has
       
    96 	completed; it simply doesn't send a command if another one is pending.
       
    97 	However, using the Arbitrate and SAPSetOption mechanism, if a command is first dropped
       
    98 	because another one is pending, it will be executed (if necessary) when the new
       
    99 	arbitrate method will be called.
       
   100 	The class has a flag set when a new command is delivered and reset when the modechange
       
   101 	event is received or an error occurs. When the flag is set no other commands are executed.
       
   102 **/
       
   103 NONSHARABLE_CLASS(TLowPowModeCmdController) : public MHCICommandQueueClient
       
   104 	{
       
   105 public:
       
   106 	TLowPowModeCmdController(CPhysicalLink& aLink, MHCICommandQueue& aCmdController);
       
   107 	void Abort();
       
   108 	
       
   109 	TInt ExitMode(TBTLinkMode aMode, THCIConnHandle aHandle);
       
   110 	TInt ChangeMode(TBTLinkMode aMode, THCIConnHandle aHandle);
       
   111 
       
   112 private:	// events from MHCICommandQueueClient
       
   113 	virtual void MhcqcCommandEventReceived(const THCIEventBase& aEvent, const CHCICommandBase* aRelatedCommand);
       
   114 	virtual void MhcqcCommandErrored(TInt aErrorCode, const CHCICommandBase* aCommand);
       
   115 	
       
   116 private:
       
   117 	void DoChangeModeL(TBTLinkMode aMode, THCIConnHandle aConnHandle);
       
   118 	void DoExitModeL(TBTLinkMode aMode, THCIConnHandle aConnHandle);
       
   119 	
       
   120 	void SniffL(THCIConnHandle aHandleToRemote);
       
   121 	void ExitSniffL(THCIConnHandle aHandleToRemote);
       
   122 	void HoldL(THCIConnHandle aHandle);
       
   123 	void ParkL(THCIConnHandle aHandleToRemote);
       
   124 	void ExitParkL(THCIConnHandle aHandleToRemote);
       
   125 
       
   126 private:
       
   127 	CPhysicalLink&		iParent;
       
   128 	MHCICommandQueue&	iCmdController;
       
   129 	TBool				iOutstandingCmd;
       
   130 	};
       
   131 
       
   132 /**
       
   133 	The following class controls disconnect commands and related events. 
       
   134 	It bypasses HCI_Facade to keep deep control of all events including errors. 
       
   135 **/
       
   136 NONSHARABLE_CLASS(TDisconnectCmdController) : public MHCICommandQueueClient
       
   137 	{
       
   138 public:
       
   139 	TDisconnectCmdController(CPhysicalLink& aLink, MHCICommandQueue& aCmdController);
       
   140 	void Abort();
       
   141 	
       
   142 	TInt Disconnect(THCIErrorCode aReason);
       
   143 
       
   144 private:	// events from MHCICommandQueueClient
       
   145 	virtual void MhcqcCommandEventReceived(const THCIEventBase& aEvent, const CHCICommandBase* aRelatedCommand);
       
   146 	virtual void MhcqcCommandErrored(TInt aErrorCode, const CHCICommandBase* aCommand);
       
   147 	
       
   148 private:
       
   149 	void DoDisconnectL(THCIErrorCode aReason);
       
   150 
       
   151 private:
       
   152 	CPhysicalLink&		iParent;
       
   153 	MHCICommandQueue&	iCmdController;
       
   154 	};
       
   155 
       
   156 
       
   157 /**
       
   158 	The following class controls authentication requests and related events. 
       
   159 	It bypasses HCI_Facade to keep deep control of all events including errors. 
       
   160 **/
       
   161 
       
   162 NONSHARABLE_CLASS(TAuthenticationCmdController) : public MHCICommandQueueClient
       
   163 	{
       
   164 public:
       
   165 	TAuthenticationCmdController(CPhysicalLink& aLink, MHCICommandQueue& aCmdController);
       
   166 	void Abort();
       
   167 	
       
   168 	// events from MLinkKeyResponseHandler
       
   169     TInt LinkKeyRequestReply(const TBTDevAddr& aBdaddr, const TDesC8& aLinkKey) const;
       
   170     TInt LinkKeyRequestNegativeReply(const TBTDevAddr& aBdaddr) const;
       
   171 
       
   172 private:	// events from MHCICommandQueueClient
       
   173 	virtual void MhcqcCommandEventReceived(const THCIEventBase& aEvent, const CHCICommandBase* aRelatedCommand);
       
   174 	virtual void MhcqcCommandErrored(TInt aErrorCode, const CHCICommandBase* aCommand);
       
   175 	
       
   176 private:
       
   177 	CPhysicalLink&		iParent;
       
   178 	MHCICommandQueue&	iCmdController;
       
   179 	};
       
   180 
       
   181 /**
       
   182  * CEncryptionEnforcer.
       
   183  * The following class avoid that a wanted encrypted connection becomes an unencrypted connection permanently.
       
   184  * Due to the use of a timer, it switchs the encryption on when a previous "switch off" command is not paired
       
   185  * with the corrisponding "switch on" one. 
       
   186  * i.e.: due to a switch role the remote device disables the encryption but it doesn't enables it when the
       
   187  * operation is finished. In this case, after a while, CEncryptionEnforcer enables the encryption on its own.
       
   188  * If a request to enable the encryption is refused CEncryptionEnforcer try to disconnect the physical link
       
   189  * because is not wanted that a requested encrypted connection is unencrypted.
       
   190  **/
       
   191 NONSHARABLE_CLASS(CEncryptionEnforcer) : public CActive
       
   192 	{
       
   193 private:
       
   194 	enum TState
       
   195 		{
       
   196 		EInactive,
       
   197 		ENoRoleSwitchTimerInProgress,
       
   198 		ERoleSwitchTimerInProgress,
       
   199 		EForcingInProgress,
       
   200 		};
       
   201 public:
       
   202 	~CEncryptionEnforcer();
       
   203 	static CEncryptionEnforcer* NewL(CPhysicalLink& aLink, THCIEncryptModeFlag aEncryptionMode);
       
   204 	static CEncryptionEnforcer* NewLC(CPhysicalLink& aLink, THCIEncryptModeFlag aEncryptionMode);
       
   205 	
       
   206 	void EncryptionEnabled();
       
   207 	void EncryptionDisabled(TBool aSecurityModeFour);
       
   208 	void RoleSwitchEvent();
       
   209 	
       
   210 private:
       
   211 	CEncryptionEnforcer(CPhysicalLink& aLink, THCIEncryptModeFlag aEncryptionMode);
       
   212 	void ConstructL();
       
   213 	void ChangeState(TState aState);
       
   214 	void Start(TInt delay);
       
   215 	void Stop();
       
   216 
       
   217 	// inherited from CActive
       
   218 	void RunL();
       
   219 	void DoCancel();
       
   220 	TInt RunError(TInt aError);
       
   221 
       
   222 private:
       
   223 	static const TInt	KTimeOutDelay		= 	5000000;	// 5 secs delay
       
   224 	
       
   225 	CPhysicalLink&		iLink;
       
   226 	THCIEncryptModeFlag	iEncryptionMode;
       
   227 	TState				iState;
       
   228 	RTimer				iTimer;
       
   229 	};
       
   230 
       
   231 NONSHARABLE_CLASS(XAutoKeyRefreshToken): public MBluetoothControlPlaneToken
       
   232 	{
       
   233 public:
       
   234 	TDblQueLink iQueLink;
       
   235 private:
       
   236 	virtual void Release();
       
   237 	};
       
   238 	
       
   239 /**
       
   240  	This class avoid requesting to store device info to the registry, if a pending 
       
   241  	request for the same device info already exists.
       
   242  **/
       
   243 NONSHARABLE_CLASS(TRegistryDeviceBeingModified)
       
   244 	{
       
   245 public:
       
   246 	TRegistryDeviceBeingModified();
       
   247 	TBool InUse() const;
       
   248 	TBool IsEqual(const TBTNamelessDevice& aDevice) const;
       
   249 	void Begin(const TBTNamelessDevice& aDevice);
       
   250 	void RequestCompleted();
       
   251 private:
       
   252 	TInt					iReferenceCount;	
       
   253 	TBTNamelessDevice 		iDevice;
       
   254 	};
       
   255 
       
   256 /**
       
   257 	The following class captures all the 'physical link' stuff such as
       
   258 	whether parked/sniffed, role, etc; to a *given* device - as that is 
       
   259 	what can be done: and is incorrect to talk about a parked 'ACL' transport
       
   260 	as its a physical property that impacts SCO too.
       
   261 
       
   262 	At present the stack does not keep track of which of these are in the
       
   263 	same piconet (hopping sequence): that would be a PhysicalLink class
       
   264 
       
   265 	Whether there is need for that - possibly for piconet broadcast - then
       
   266 	there might be a use for a CBTBroadcast connection - which would begin
       
   267 	to reflect a piconet
       
   268 
       
   269  **/
       
   270 NONSHARABLE_CLASS(CPhysicalLink) : public CBase,
       
   271 					  public MBTRegistryTaskNotifier,
       
   272 					  public MBtHostControllerEventInternalNotifier,
       
   273 					  public MPINCodeResponseHandler
       
   274 
       
   275 	{
       
   276 public:			
       
   277 	static CPhysicalLink* NewLC(CPhysicalLinksManager& aConnectionMan,
       
   278 								CRegistrySession& aRegSess, const TBTNamelessDevice& aDevice);
       
   279 	static CPhysicalLink* NewL(CPhysicalLinksManager& aConnectionMan,
       
   280 								CRegistrySession& aRegSess, const TBTNamelessDevice& aDevice);
       
   281 	~CPhysicalLink();
       
   282 	TInt SubscribeProxySAP(CBTProxySAP& aProxySAP);
       
   283 	void UnsubscribeProxySAP(CBTProxySAP& aProxySAP);
       
   284 
       
   285 	void SubscribeLinkObserver(MPhysicalLinkObserver& aSubscriber);
       
   286 	void UnsubscribeLinkObserver(MPhysicalLinkObserver& aSubscriber);
       
   287 
       
   288 	TInt TryToAndThenPreventHostEncryptionKeyRefresh(TAny* aOutToken);
       
   289 
       
   290 	inline const TBTDevAddr& BDAddr() const;
       
   291 	inline const TBTBasebandLinkState& LinkState() const;
       
   292 	inline TBool IsConnected() const;
       
   293 	inline TBool IsListening() const;
       
   294 	inline TBTBasebandRole Role() const;
       
   295 	void SetDeviceNamePending(TBool aBool);
       
   296 	TInt GetOption(TUint aLevel,TUint aName,TDes8& aOption) const;
       
   297 	TInt Connect(TBasebandPageTimePolicy aPolicy=EPagingNormal);
       
   298 	TInt SCOConnect();
       
   299 	TInt SCOConnect(const TUint16 aUserHVPacketTypes);
       
   300 	TInt SynchronousConnect(TUint aTransmitBandwidth, TUint aReceiveBandwidth,
       
   301 		TUint16 aMaxLatency, TUint16 aVoiceSettings,
       
   302 		TUint8 aRetransmissionEffort, const TBTSyncPacketTypes aUserPacketTypes);
       
   303 	TInt PassiveOpen();
       
   304 	TInt Arbitrate(const TBool aImmediately=EFalse, const TBool aLocalPriority=EFalse);	
       
   305 	void SetPassKey(const TDesC8& aPassKey);
       
   306 	const TBTPinCode& PassKey() const;		
       
   307 
       
   308 	void StartArbitrationTimer() const;
       
   309 	
       
   310 	// from RegistryNotifier
       
   311 	virtual void RegistryTaskComplete(CBTRegistryHelperBase* aHelper, TInt aResult);
       
   312 	virtual void RegistryTaskComplete(CBTRegistryHelperBase* aHelper, const TBTNamelessDevice& aDevice, TInt aResult);
       
   313 	virtual void RegistryTaskComplete(CBTRegistryHelperBase* aHelper, const TRegistryUpdateStatus aRegUpdateStatus, TInt aResult);
       
   314 
       
   315 	void SetModesAllowed(TUint8 aModesAllowed, TBool aRoleSwitchAllowed);
       
   316 
       
   317 	TBool IsModeSupportedRemotely(TBTLinkMode aMode) const;
       
   318 	TBool IsEncryptionPauseResumeSupported() const;
       
   319 	TBool IsRoleSwitchSupported() const;
       
   320 	TBool IsEncryptionSupported() const;
       
   321 
       
   322 	inline TBool Authenticated() const;
       
   323 	inline TBool Encrypted() const;
       
   324 	TInt ChangeEncryption(THCIEncryptModeFlag aEnable);
       
   325 	TInt Authenticate(TBool aRequireAuthenticatedLinkKey);
       
   326 	TInt ChangeLinkKey();
       
   327 
       
   328 	TInt ChangeConnectionPacketType(TUint16 aType);
       
   329 
       
   330 	TInt ExitMode(TBTLinkMode aMode);
       
   331 	TInt RequestHold();
       
   332 	TInt RequestSniff();
       
   333 	TInt RequestPark();
       
   334 	TInt RequestActive();
       
   335 	TInt RequestChangeRole(TBTBasebandRole aRole);
       
   336 
       
   337 	void ReadNewPhysicalLinkMetricValue(TUint aIoctlName, CBTProxySAP& aSAP, TInt aCurrentValue);
       
   338 
       
   339 	TInt OverridePark();
       
   340 	TInt UndoOverridePark();
       
   341 	TInt OverrideLPMWithTimeout(TUint aTimeout);
       
   342 	TInt OverrideLPM();
       
   343 	TInt UndoOverrideLPM();
       
   344 	inline TBool IsParked() const;
       
   345 	
       
   346 	TBool ACLConnectPending() const;
       
   347 	TBool SyncConnectPending() const;
       
   348 	
       
   349 	// events from MBtHostControllerEventInternalNotifier
       
   350 	virtual void ConnectionComplete(THCIErrorCode aErr, const TBTConnect& aConn);
       
   351 	virtual void SynchronousConnectionComplete(THCIErrorCode aErr, const TBTConnect& aConn, const TBTSyncConnectOpts& aSyncOpts);
       
   352 	virtual void ConnectionRequest(const TBTConnect& aConn);
       
   353 	virtual void Disconnection(THCIErrorCode aErr, THCIConnHandle aConnH, THCIErrorCode aResult);
       
   354 	virtual void CompletedPackets(THCIConnHandle aConnH, TUint16 aNumPackets);
       
   355 	virtual void AuthenticationComplete(THCIErrorCode aErr, THCIConnHandle aConnH);
       
   356 	virtual void EncryptionChange(THCIErrorCode aErr, THCIConnHandle aConnH,TBool aEncrypted);
       
   357 	virtual void ACLDataReceived(THCIConnHandle aConnH, TUint8 aFlag, const TDesC8& aData);
       
   358 	virtual void SCODataReceived(THCIConnHandle aConnH, const TDesC8& aData);
       
   359 
       
   360 	virtual void PinRequest(const TBTDevAddr& aBDAddr, MPINCodeResponseHandler& aRequester);
       
   361 	virtual void NewLinkKey(const TBTDevAddr& aBDAddr, const TBTLinkKey& aLinkKey, THCILinkKeyType aLinkKeyType);
       
   362 	virtual void LinkKeyRequest(const TBTDevAddr& aBDAddr, MLinkKeyResponseHandler& aRequester);
       
   363 	virtual void ReadRemoteSupportedFeaturesComplete(THCIErrorCode aErr, THCIConnHandle aConnH, const TBTFeatures& aBitMask);
       
   364 	virtual void ReadRemoteExtendedFeaturesComplete(THCIErrorCode aErr, THCIConnHandle aConnH, TUint64 aBitMask, TUint8 aPageNumber, TUint8 aMaximumPageNumber);
       
   365 	virtual void ReadRemoteVersionInfoComplete(THCIErrorCode aErr, THCIConnHandle aConnH, const TBTDevRemoteHwVersion& aVer);
       
   366 	virtual void PacketTypeChange(THCIErrorCode aErr, THCIConnHandle aConnH, TUint16 aNewPacket);
       
   367 	virtual void LinkSupervisionTimeoutChange(THCIErrorCode aErr, THCIConnHandle aConnH, TUint16 aNewTimeout);
       
   368 	virtual void MaxSlotsChange(THCIConnHandle aConnH, TUint8 aSlots);
       
   369 	virtual void ModeChange(THCIErrorCode aErr, THCIConnHandle aConnH, TBTLinkMode aMode, TBasebandTime aInterval);
       
   370 	virtual void WriteLinkPolicySettingsCompleteEvent(THCIErrorCode aErr, THCIConnHandle aConnH);
       
   371 	virtual void RoleChange(THCIErrorCode aErr, const TBTDevAddr& aAddr, TBTBasebandRole aRole);
       
   372 	virtual void ClockOffset(THCIErrorCode aErr, THCIConnHandle aConnH, TBasebandTime aClockOffset);
       
   373 	virtual void RemoteName(THCIErrorCode aErr, const TBTDevAddr& aAddr, const TBTDeviceName8& aName);
       
   374 
       
   375 	TBool LinkKeyRequestPending();
       
   376 	void SetAuthenticationPending(TUint8 aFlag);
       
   377 	virtual void AuthenticationComplete(TUint8 aFlag);
       
   378 
       
   379 	static TInt OverrideLPMTimeoutCallback(TAny* aCPhysicalLink);// async callback
       
   380 	static TInt TerminateCallback(TAny* aCPhysicalLink);// async callback
       
   381 	TInt Terminate(THCIErrorCode aReason);
       
   382 
       
   383 	TInt AttachLogicalLink(TLinkType aLink, CBTBasebandSAP& aSAP);
       
   384 	void DetachLogicalLink(TLinkType aLink, CBTBasebandSAP& aSAP);
       
   385 	void PhysicalLinkUserIdle();
       
   386 
       
   387 	void PinRequestSent();
       
   388 	void PinRequestComplete();
       
   389 	void ConfirmationComplete();
       
   390 	void DeleteLinkKeyL();
       
   391 
       
   392 	TBool IsConnectionRequestPending() const;
       
   393 	void PendingConnectionRequest(TInt aError);
       
   394 	inline THCIConnHandle Handle() const;
       
   395 	TBool HasHandle(THCIConnHandle aConnH) const;
       
   396 	inline const TBTNamelessDevice& RemoteDevice() const;
       
   397 
       
   398 	void GetCurrentBasebandState(TBTBasebandEventNotification & aEvent);
       
   399 	void TryToSend();
       
   400 	
       
   401 	TBool HasSyncLink() const;
       
   402 	void GetDeviceFromRegistryL();
       
   403 	TBTLinkMode LinkMode() const; 
       
   404 	
       
   405 	void AsyncDeleteRoleSwitcher();
       
   406 	
       
   407 	inline const TLinkPolicy& LinkPolicy() const;
       
   408 	inline const TBTFeatures& RemoteFeatures() const;
       
   409 	inline const TBTDeviceClass& DeviceClass() const;
       
   410 	TInt GetConnectionHandles(RHCIConnHandleArray& aConnectionHandles,
       
   411 							  TLinkType aLinkType) const;
       
   412 
       
   413 	TInt GetNumPendingHandles(TInt& aConnectionHandles,
       
   414 							  TLinkType aLinkType) const;
       
   415 	TBool IsEncryptionDisabledForRoleSwitch() const;
       
   416 
       
   417 	void IOCapabilityAskForResponse(THCIIoCapability aIOCapability, THCIOobDataPresence aOOBDataPresence, THCIAuthenticationRequirement aAuthenticationRequirement);
       
   418 
       
   419 	void SetLocalMITM(TBool aLocalMITM);
       
   420 	TBool AuthWithMITM() const;
       
   421 	TUint LSTO() const { return iLSTO; }
       
   422 	
       
   423 	TPhysicalLinkSimplePairingMode SimplePairingMode() const;
       
   424 
       
   425 	TBool HasRemoteOobData() const;
       
   426 	
       
   427 	THCIAuthenticationRequirement AuthenticationRequirement() const;
       
   428 
       
   429 	void NewNumericComparatorL(const TBTDevAddr aAddr,CBTSecMan& aSecMan,TUint32 aNumericValue, TBool aInternallyInitiated);
       
   430 
       
   431 	CBTNumericComparator* InstanceNumericComparator() const;
       
   432 	TBool IsNumericComparatorActive()const;
       
   433 	void DeleteNumericComparator();
       
   434 	void CancelNumericComparator();
       
   435 
       
   436 
       
   437 	void NewPasskeyEntryL(const TBTDevAddr aAddr,CBTSecMan& aSecMan,TUint32 aNumericValue, TBool aInternallyInitiated);
       
   438 
       
   439 	CBTPasskeyEntry* InstancePasskeyEntry() const;
       
   440 	TBool IsPasskeyEntryActive()const;
       
   441 	void DeletePasskeyEntry();
       
   442 	void CancelPasskeyEntry();
       
   443 	void PasskeyEntryKeyPressed(THCIPasskeyEntryNotificationType aKey);
       
   444 	TBasebandTime GetSniffInterval() const;
       
   445 	
       
   446 	TBool IsPairable() const;
       
   447 
       
   448 private:
       
   449 	CPhysicalLink(CPhysicalLinksManager& aParent, CRegistrySession& aRegSess, const TBTNamelessDevice& aDevice);
       
   450 	void ConstructL();
       
   451 	void GetRemoteDetailsL(const TBTConnect& aConn);
       
   452 	void DoUpdateNameL(const TBTDeviceName8& aName);
       
   453 
       
   454 	void NotifyLogicalLinkUp(const TBTConnect& aConnect);
       
   455 	void NotifyLogicalSyncLinkUp(const TBTConnect& aConnect, const TBTSyncConnectOpts& aSyncOpts);
       
   456 	void NotifyLogicalLinkDown(TPhysicalLinkPort aPort);
       
   457 	void NotifyLogicalLinkError(TPhysicalLinkPort aPort, TInt aError);
       
   458 	void RejectConnection(const TBTConnect& aConn);
       
   459 
       
   460 	void DoPinRequestL(const TBTDevAddr& aAddr, MPINCodeResponseHandler& aRequester);
       
   461 	void UpdateFromInquiryCache();
       
   462 	void StoreDeviceL(TBool aPreventDeviceAddition);
       
   463 	void SetLinkKey(const TBTLinkKey& aLinkKey, TBTLinkKeyType aLinkKeyType);
       
   464 
       
   465 	void QueueIdleTimer(TInt aTime);
       
   466 	void RemoveIdleTimer();
       
   467 
       
   468 	void QueueLPMOverrideTimer(TInt aTimeout);
       
   469 	void NotifyStateChange(TBTBasebandEventNotification & aEvent);
       
   470 
       
   471 	TBool IsPhysicalLinkIdle() const;
       
   472 	TInt RequestMode(TBTLinkMode aMode);
       
   473 	TBasebandTime CalculatePageTimeout(TBasebandPageTimePolicy aPolicy, TUint8 aRepMode, TBool aValidClockOffset);
       
   474 	TBool IsPasskeyMinLengthOK();
       
   475 	TBool PeerSupportsLinkKeyRegeneration() const;
       
   476 
       
   477 	void DeleteRoleSwitcher();
       
   478 	static TInt RoleSwitchCompleteCallBack(TAny* CPhysicalLink);
       
   479 	TInt ManageEncryptionEnforcement(THCIEncryptModeFlag aEnable);
       
   480 
       
   481 	void HandlePrefetch();
       
   482 	void PINCodeRequestReply(const TBTDevAddr& aDevAddr,const TDesC8& aPin);
       
   483 	void PINCodeRequestNegativeReply(const TBTDevAddr& aDevAddr);
       
   484 	
       
   485 	inline TBool IsAuthenticationPending() const;
       
   486 
       
   487 private: // from MPINCodeResponseHandler
       
   488 	TInt PINCodeRequestReply(const TBTDevAddr& aDevAddr,const TDesC8& aPin) const;
       
   489 	TInt PINCodeRequestNegativeReply(const TBTDevAddr& aDevAddr) const;
       
   490 
       
   491 private:
       
   492 	CPhysicalLinksManager&					iLinksMan; // The manager of remote physical link representations
       
   493 	CRegistrySession&						iRegSess; // The RegistryServer session
       
   494 
       
   495 	// the PHY's properties
       
   496 	TBTNamelessDevice						iDevice; // names not stored here by in InqMgr
       
   497 	TBTNamelessDevice						iRegistryDevice; // the view from the registry.
       
   498 	TBTBasebandLinkState					iLinkState;
       
   499 	THCIConnHandle							iHandle;
       
   500 	TBTFeatures								iRemoteFeatures;
       
   501 	TBTDevRemoteHwVersion					iRemoteVersion;
       
   502 
       
   503 	TInt									iDeviceResult; // Whether we got device from registry OK
       
   504 	// the PHY's subscribers
       
   505 	TDblQue<TPhysicalLinkObserverQLink>		iBasebandSubscribers;
       
   506 	// the PHY's outstanding registry helpers
       
   507 	TSglQue<CBTRegistryHelperBase>			iRegistryHelpers;
       
   508 	
       
   509 	// the PHY's UI handlers
       
   510 	CBTPinRequester*						iPinRequester;	// looks after PIN entry UI/state
       
   511 	CBTNumericComparator*					iNumericComparator; // looks after the numeric comparison UI/state
       
   512 	CBTPasskeyEntry*						iPasskeyEntry; // looks after the passkey entry UI/state
       
   513 	
       
   514 	CEncryptionEnforcer*					iEncryptionEnforcer;
       
   515 	
       
   516 	// the PHY's supported logical links...
       
   517 	RPointerArray<CACLLink>					iACLLogicalLinks;
       
   518 	CBTSynchronousLink*						iSyncLogicalLink; // stack only supports a signal one per PHY
       
   519 	
       
   520 
       
   521 	MPINCodeResponseHandler*	iPinHandler;
       
   522 	TBTConnect 					iLastPendingConnection;		// for if we have to wait for Registry to decide whether to rject or accept a connection
       
   523 	TBool						iPendingConnection;  // is a connection request waiting for a reply
       
   524 	TSglQue<CBTProxySAP>		iProxySAPs;			// the proxies bound to us
       
   525 	TDeltaTimerEntry			iIdleTimerEntry;
       
   526 	TBool						iIdleTimerQueued;
       
   527 	TDeltaTimerEntry			iOverrideLPMTimerEntry;
       
   528 
       
   529 	TLinkPolicy					iLinkPolicy;
       
   530 	TUint8 						iPreviousRequestedModeMask;
       
   531 	TBool						iOverrideParkRequests; //for maybe temporary unpark
       
   532 	TBool						iOverrideLPMRequests; //for maybe temporary force active
       
   533 	TBool						iLPMOverrideTimerQueued;
       
   534 	TBool						iConnectionPacketTypeChanged; //for triggering h/w 
       
   535 	
       
   536 	TBool						iPreventLinkKeyUpdateReg; //for case e.g. user has called unpair when there is a paired logical channel
       
   537 	TUint8						iAuthStateMask; // Authentication state mask to keep track of the authentication process
       
   538 	TBool						iLinkKeyPending; //PIN has been sent, awaiting a link key.
       
   539 	
       
   540 	TBool						iPeerInSecurityMode3;
       
   541 	TBasebandTime				iSniffInterval;
       
   542 	CArbitrationDelayTimer*		iArbitrationDelay; //for lower power modes
       
   543 	CRoleSwitcher*				iRoleSwitcher; //class handles role switch, prevents LPM, removes encryption		
       
   544 	CAsyncCallBack*				iRoleSwitchCompleteCallBack;// Async Callback to delete role swticher class.
       
   545 
       
   546 	TLowPowModeCmdController	iLowPowModeCtrl;
       
   547 	CPhysicalLinkMetrics*		iPhysicalLinkMetrics;
       
   548 	TDisconnectCmdController	iDisconnectCtrl;
       
   549 	TAuthenticationCmdController iAuthenticationCtrl;
       
   550 	
       
   551 	TBool						iIOCapsReceived;
       
   552 	THCIIoCapability				iIOCapability;
       
   553 	THCIOobDataPresence			iOOBDataPresence;
       
   554 	THCIAuthenticationRequirement	iAuthenticationRequirement;
       
   555 	
       
   556 	TBool						iRequireAuthenticatedLinkKey;
       
   557 	TBool						iLocalMITM; // Whether MITM protection was requested
       
   558 	TUint						iLSTO;
       
   559 	
       
   560 	
       
   561 	TPhysicalLinkSimplePairingMode		iSimplePairingMode;
       
   562 	
       
   563 	TDblQue<XAutoKeyRefreshToken>		iAutoKeyRefreshQue;
       
   564 	TRegistryDeviceBeingModified		iRegistryDevBeingMod;	// avoid duplicate equal registry device store req
       
   565 	
       
   566 	TInt						iIdleTimeout;
       
   567 
       
   568 	TBool						iNewPinCodeValid;
       
   569 	TBTPinCode					iNewPinCode;
       
   570 
       
   571 	TBool						iWaitingForLinkKeyFromRegistry;
       
   572 
       
   573 private:
       
   574 	/**
       
   575 	Enumeration to represent the current state of the physical links storage in the registry,
       
   576 	this is to cover the asynchronous properties of actions to the registry.
       
   577 	*/
       
   578 	enum TRemoteDeviceRecordedByStack
       
   579 		{
       
   580 		ENull,
       
   581 		EPending,
       
   582 		EComplete
       
   583 		};
       
   584 	TRemoteDeviceRecordedByStack	iRemoteDeviceRecordedByStack;
       
   585 	TBool						iDisconnectRequested; //
       
   586 	};
       
   587 
       
   588 // Removed - LogicalLinkTrackers - if needed to prevent Park mode for legacy apps see in Perforce
       
   589 
       
   590 
       
   591 #include "physicallinks.inl"
       
   592 #endif //_PHYSICALLINKS_H