bluetooth/btstack/linkmgr/physicallinks.cpp
changeset 17 907b2fb7aa8e
parent 16 0089b2f7ebd8
child 19 4b81101308c6
equal deleted inserted replaced
16:0089b2f7ebd8 17:907b2fb7aa8e
   382 	iDevice = device;
   382 	iDevice = device;
   383 
   383 
   384 	// Store the result of the retrieval for usage later.
   384 	// Store the result of the retrieval for usage later.
   385 	iDeviceResult = aResult;
   385 	iDeviceResult = aResult;
   386 
   386 
   387 	// the HW asked earlier for a link key - we can respond now
   387 	if (iLinkKeyRequestOutstanding)
   388 	__ASSERT_DEBUG(iDevice.IsValidAddress(), Panic(EBTPhysicalLinksInvalidAddress));
   388 		{
   389 	if(iWaitingForLinkKeyFromRegistry)
   389 		// the HW asked earlier for a link key - we can respond now
   390 		{
   390 		__ASSERT_DEBUG(iDevice.IsValidAddress(), Panic(EBTPhysicalLinksInvalidAddress));
   391 		if (aResult == KErrNone && iDevice.IsValidLinkKey())
   391 		LinkKeyRequestResponseAttempt(ETrue);
   392 			{
   392 		}
   393 			if ( iDevice.LinkKeyType() != ELinkKeyCombination)
       
   394 				{
       
   395 				if (iLinksMan.SecMan().DebugMode() && iDevice.LinkKeyType() != ELinkKeyDebug)
       
   396 					{
       
   397 					LOG(_L("CPhysicalLink: Debug mode - Link to debug link key"))
       
   398 					iAuthenticationCtrl.LinkKeyRequestNegativeReply(iDevice.Address());
       
   399 					}
       
   400 				else
       
   401 				if (iRequireAuthenticatedLinkKey && iDevice.LinkKeyType() == ELinkKeyUnauthenticatedUpgradable && IsPairable())
       
   402 					{
       
   403 					LOG(_L("CPhysicalLink: Requiring Authenticated link key but currently only have unauthenticated"))
       
   404 					iAuthenticationCtrl.LinkKeyRequestNegativeReply(iDevice.Address());
       
   405 					}
       
   406 				else
       
   407 					{
       
   408 					LOG(_L("CPhysicalLink: Issuing link key to HC now"))
       
   409 					iAuthenticationCtrl.LinkKeyRequestReply(iDevice.Address(), iDevice.LinkKey());
       
   410 					}
       
   411 				}
       
   412 			else if(IsPasskeyMinLengthOK() && SimplePairingMode() != EPhySimplePairingEnabled)
       
   413 				{
       
   414 				LOG(_L("CPhysicalLink: Issuing link key to HC now"))
       
   415 				iAuthenticationCtrl.LinkKeyRequestReply(iDevice.Address(), iDevice.LinkKey());
       
   416 				}
       
   417 			else
       
   418 				{
       
   419 				LOG(_L("CPhysicalLink: Current PIN code too short!"))
       
   420 				iAuthenticationCtrl.LinkKeyRequestNegativeReply(iDevice.Address());
       
   421 				}
       
   422 			}
       
   423 		else
       
   424 			{
       
   425 			iAuthenticationCtrl.LinkKeyRequestNegativeReply(iDevice.Address());
       
   426 			}	
       
   427 		}
       
   428 	iRequireAuthenticatedLinkKey = EFalse;
       
   429 	iWaitingForLinkKeyFromRegistry = EFalse;
       
   430 
   393 
   431 	RegistryTaskComplete(aHelper, aResult);	 // cleans up our helper
   394 	RegistryTaskComplete(aHelper, aResult);	 // cleans up our helper
   432 	}
   395 	}
   433 
   396 
   434 void CPhysicalLink::RegistryTaskComplete(CBTRegistryHelperBase* aHelper, TRegistryUpdateStatus aRegUpdateStatus, TInt aResult)
   397 void CPhysicalLink::RegistryTaskComplete(CBTRegistryHelperBase* aHelper, TRegistryUpdateStatus aRegUpdateStatus, TInt aResult)
   544 		// Only bind a PIN code to the device if we receive a link key based on it.
   507 		// Only bind a PIN code to the device if we receive a link key based on it.
   545 		iNewPinCodeValid = EFalse;
   508 		iNewPinCodeValid = EFalse;
   546 		iDevice.SetPassKey(iNewPinCode);
   509 		iDevice.SetPassKey(iNewPinCode);
   547 		}
   510 		}
   548 
   511 
       
   512 	if (iLinksMan.SecMan().IsDedicatedBondingAttempted(iDevice.Address()))
       
   513 		{
       
   514 		iLinkKeyObtainedThroughDedicatedBonding = ETrue;
       
   515 		}
   549 
   516 
   550 	SetLinkKey(aLinkKey, linkKeyType);	// keeps a copy in our 'cache', updates paired list in PHYs mananger
   517 	SetLinkKey(aLinkKey, linkKeyType);	// keeps a copy in our 'cache', updates paired list in PHYs mananger
   551 
   518 
   552 	TRAP_IGNORE(StoreDeviceL(EFalse)); //EFalse: new meaning - do not prevent addition
   519 	TRAP_IGNORE(StoreDeviceL(EFalse)); //EFalse: new meaning - do not prevent addition
   553 	// if that errored we just have to keep it here - but it won't be in registry
   520 	// if that errored we just have to keep it here - but it won't be in registry
   607 		{
   574 		{
   608 		device.SetDeviceClass(iDevice.DeviceClass());
   575 		device.SetDeviceClass(iDevice.DeviceClass());
   609 		}
   576 		}
   610 	if(iDevice.IsValidLinkKey() && !iPreventLinkKeyUpdateReg)
   577 	if(iDevice.IsValidLinkKey() && !iPreventLinkKeyUpdateReg)
   611 		{
   578 		{
   612 		if(!(iIOCapsReceived && (iAuthenticationRequirement == EMitmNotReqNoBonding || iAuthenticationRequirement == EMitmReqNoBonding)))
   579 		// We store the link key if it was obtained through dedicated bonding, even if the remote device indicated "no bonding"
       
   580 		// This fixes issues with a lot of remote stacks, and we'll let the UI delete the link key if they want to.
       
   581 		if(iLinkKeyObtainedThroughDedicatedBonding ||
       
   582 			!(iIOCapsReceived && (iAuthenticationRequirement == EMitmNotReqNoBonding || iAuthenticationRequirement == EMitmReqNoBonding)))
   613 			{
   583 			{
   614 			LOG(_L("!!! Storing Link Key in Registry"));
   584 			LOG(_L("!!! Storing Link Key in Registry"));
   615 			device.SetLinkKey(iDevice.LinkKey(), iDevice.LinkKeyType());
   585 			device.SetLinkKey(iDevice.LinkKey(), iDevice.LinkKeyType());
   616 			}
   586 			}
   617 		}
   587 		}
   706 			{
   676 			{
   707 			TRAP_IGNORE(iLinksMan.HCIFacade().ReadRemoteExtendedFeaturesL(iHandle, KRemoteExtendedFeaturesPage1));
   677 			TRAP_IGNORE(iLinksMan.HCIFacade().ReadRemoteExtendedFeaturesL(iHandle, KRemoteExtendedFeaturesPage1));
   708 			}
   678 			}
   709 		else
   679 		else
   710 			{
   680 			{
   711 			// If the remote doesn't support extended features, then neither they support SSP
   681 			// If the remote doesn't support extended features, then they cannot support SSP
   712 			// (no way to indicate the host supported bit).  So set it as disabled.
   682 			// (no way to indicate the host supported bit).  So set feature as disabled.
   713 			TPhysicalLinkSimplePairingMode previousSetting = SimplePairingMode();
   683 			RemoteSimplePairingModeDetermined(EPhySimplePairingDisabled);
   714 			__ASSERT_DEBUG(((SimplePairingMode() == EPhySimplePairingDisabled) || (SimplePairingMode() == EPhySimplePairingUndefined)),Panic(EBTSSPModeChangedDuringConnection));
       
   715 			iSimplePairingMode = EPhySimplePairingDisabled;
       
   716 			if(SimplePairingMode() != previousSetting)
       
   717 				{
       
   718 				iLinksMan.SecMan().SimplePairingSupportDetermined(BDAddr());
       
   719 				}
       
   720 			}
   684 			}
   721 		}
   685 		}
   722 	else
   686 	else
   723 		{
   687 		{
   724 		iRemoteFeatures = TBTFeatures(KInvalidRemoteFeatures);
   688 		iRemoteFeatures = TBTFeatures(KInvalidRemoteFeatures);
   738 			{
   702 			{
   739 			TPhysicalLinkSimplePairingMode currentSetting = SimplePairingMode();
   703 			TPhysicalLinkSimplePairingMode currentSetting = SimplePairingMode();
   740 
   704 
   741 			if (aErr == EOK && aBitMask & (1 << ESecureSimplePairingHostSupportBit) && iLinksMan.SecMan().LocalSimplePairingMode())
   705 			if (aErr == EOK && aBitMask & (1 << ESecureSimplePairingHostSupportBit) && iLinksMan.SecMan().LocalSimplePairingMode())
   742 				{
   706 				{
   743 				__ASSERT_DEBUG(((SimplePairingMode() == EPhySimplePairingEnabled) || (SimplePairingMode() == EPhySimplePairingUndefined)),Panic(EBTSSPModeChangedDuringConnection));
   707 				RemoteSimplePairingModeDetermined(EPhySimplePairingEnabled);
   744 				iSimplePairingMode = EPhySimplePairingEnabled;
       
   745 				}
   708 				}
   746 			else
   709 			else
   747 				{
   710 				{
   748 				__ASSERT_DEBUG(((SimplePairingMode() == EPhySimplePairingDisabled) || (SimplePairingMode() == EPhySimplePairingUndefined)),Panic(EBTSSPModeChangedDuringConnection));
   711 				RemoteSimplePairingModeDetermined(EPhySimplePairingDisabled);
   749 				iSimplePairingMode = EPhySimplePairingDisabled;
   712 				}
   750 				}
       
   751 			if(SimplePairingMode()!=currentSetting)
       
   752 				{
       
   753 				iLinksMan.SecMan().SimplePairingSupportDetermined(BDAddr());
       
   754 				}			
       
   755 			break;
   713 			break;
   756 			}
   714 			}
   757 		default:
   715 		default:
   758 			{
   716 			{
   759 			// Ignore
   717 			// Ignore
   906 		{
   864 		{
   907 		iRequireAuthenticatedLinkKey = aRequireAuthenticatedLinkKey;
   865 		iRequireAuthenticatedLinkKey = aRequireAuthenticatedLinkKey;
   908 		TRAP(err, iLinksMan.HCIFacade().AuthenticateL(Handle()));
   866 		TRAP(err, iLinksMan.HCIFacade().AuthenticateL(Handle()));
   909 		if(err == KErrNone)
   867 		if(err == KErrNone)
   910 			{
   868 			{
       
   869 			iLinkKeyReturnedInThisAuthentication = EFalse;
   911 			SetAuthenticationPending(EAuthenticationRequestPending);
   870 			SetAuthenticationPending(EAuthenticationRequestPending);
   912 			}
   871 			}
   913 		}
   872 		}
   914 	return err;
   873 	return err;
   915 	}
   874 	}
  2833 	// However, in UDEB we panic to raise awareness that the hardware is behaving incorrectly.
  2792 	// However, in UDEB we panic to raise awareness that the hardware is behaving incorrectly.
  2834 	__ASSERT_DEBUG(!iPinRequester, Panic(EBTConnectionPINRequestedTwice));
  2793 	__ASSERT_DEBUG(!iPinRequester, Panic(EBTConnectionPINRequestedTwice));
  2835 
  2794 
  2836 	SetAuthenticationPending(EPinRequestPending); // if not already set (because the remote initiated authentication).
  2795 	SetAuthenticationPending(EPinRequestPending); // if not already set (because the remote initiated authentication).
  2837 
  2796 
  2838 	__ASSERT_DEBUG(iSimplePairingMode != EPhySimplePairingEnabled, Panic(EBTSSPModeChangedDuringConnection));
       
  2839 	if (iSimplePairingMode == EPhySimplePairingUndefined)
       
  2840 		{
       
  2841 		iSimplePairingMode = EPhySimplePairingDisabled;
       
  2842 		}
       
  2843 	
       
  2844 	if (!IsConnected())
  2797 	if (!IsConnected())
  2845 		{
  2798 		{
  2846 		iPeerInSecurityMode3 = ETrue;
  2799 		// If the ACL to the peer device is not yet connected, and the peer has initiated
  2847 		}
  2800 		// authentication then it must be in security mode 3.  This information is stored and
  2848 
  2801 		// if the connection completes the link will be set as authenticated.
  2849 	
  2802 		SetPeerInSecurityMode3();
       
  2803 		}
       
  2804 
       
  2805 	// We can receive "fast" PIN requests if the remote device initiates pairing and indicates
       
  2806 	// it doesn't have a link key.  If we see this then we know that we are not engaging in 
       
  2807 	// simple pairing on this particular link.
       
  2808 	RemoteSimplePairingModeDetermined(EPhySimplePairingDisabled);
       
  2809 
  2850 	if (iPinRequester)
  2810 	if (iPinRequester)
  2851 		{
  2811 		{
  2852 		return;
  2812 		return;
  2853 		}
  2813 		}
  2854 
  2814 
  2987 		|| iLinkState.Authenticated() 
  2947 		|| iLinkState.Authenticated() 
  2988 		|| locallyInitiatedLogicalLink
  2948 		|| locallyInitiatedLogicalLink
  2989 		|| iLinksMan.SecMan().IsDedicatedBondingAttempted(iDevice.Address());
  2949 		|| iLinksMan.SecMan().IsDedicatedBondingAttempted(iDevice.Address());
  2990 	}
  2950 	}
  2991 
  2951 
       
  2952 TBool CPhysicalLink::IsPairingExpected() const
       
  2953 	{
       
  2954 	LOG_FUNC
       
  2955 	return !(IsAuthenticationPending() && iLinkKeyReturnedInThisAuthentication);
       
  2956 	}
       
  2957 
  2992 void CPhysicalLink::DeleteLinkKeyL()
  2958 void CPhysicalLink::DeleteLinkKeyL()
  2993 /**
  2959 /**
  2994 ensure that the LinkKey is removed from the device in the registry
  2960 ensure that the LinkKey is removed from the device in the registry
  2995 **/
  2961 **/
  2996 	{
  2962 	{
  3054 		}
  3020 		}
  3055 
  3021 
  3056 	return isPasskeyMinLengthOK;
  3022 	return isPasskeyMinLengthOK;
  3057 	}
  3023 	}
  3058 
  3024 
  3059 void CPhysicalLink::LinkKeyRequest(const TBTDevAddr& aAddr, MLinkKeyResponseHandler& /*aRequester*/)
  3025 void CPhysicalLink::LinkKeyRequest(const TBTDevAddr& __DEBUG_ONLY(aAddr), MLinkKeyResponseHandler& /*aRequester*/)
  3060 	{
  3026 	{
  3061 	LOG_FUNC
  3027 	LOG_FUNC
       
  3028 	__ASSERT_DEBUG(aAddr == BDAddr(), Panic(EBTConnectionBadDeviceAddress));
       
  3029 	ASSERT_DEBUG(!iLinkKeyRequestOutstanding);
       
  3030 
       
  3031 	iLinkKeyRequestOutstanding = ETrue;
       
  3032 
  3062 	// we don't keep a copy of the device record - we just leave the one copy with
  3033 	// we don't keep a copy of the device record - we just leave the one copy with
  3063 	// the baseband - it can tell us if there's a link key
  3034 	// the baseband - it can tell us if there's a link key
  3064 	// we can tell if the baseband has the device record or not
  3035 	// we can tell if the baseband has the device record or not
  3065 
  3036 
  3066 	SetAuthenticationPending(ELinkKeyRequestPending); //authentication process started by remote
  3037 	SetAuthenticationPending(ELinkKeyRequestPending); //authentication process started by remote
  3068 	// If the ACL to the peer device is not yet connected, and the peer has initiated
  3039 	// If the ACL to the peer device is not yet connected, and the peer has initiated
  3069 	// authentication then it must be in security mode 3.  This information is stored and
  3040 	// authentication then it must be in security mode 3.  This information is stored and
  3070 	// if the connection completes the link will be set as authenticated.
  3041 	// if the connection completes the link will be set as authenticated.
  3071 	if (!IsConnected())
  3042 	if (!IsConnected())
  3072 		{
  3043 		{
  3073 		iPeerInSecurityMode3 = ETrue;
  3044 		SetPeerInSecurityMode3();
  3074 		}
  3045 		}
  3075 
  3046 
  3076 	if(!iPeerInSecurityMode3 && iLinksMan.SecMan().IsDedicatedBondingAttempted(iDevice.Address()))
  3047 	if (iLinkKeyRequestOutstanding)
  3077 		{
  3048 		{ // might have already been called via SetPeerInSecurityMode3()
  3078 		// If we are doing DedicatedBonding then we should ignore the existing linkkey
  3049 		LinkKeyRequestResponseAttempt();
  3079 		// in an attempt to generate a stronger one if possible.
  3050 		}
  3080 		// Security mode 3 is a odd case - because we get what looks like double pairing (the remote
       
  3081 		// initiated pairing on connection, then the dedicated bonding pairing).  So we have removed
       
  3082 		// this feature for security mode 3 devices...they will have to suffer for their transgressions
       
  3083 		LOG(_L("CPhysicalLink: Dedicated bonding attempt - Sending link key request negative reply"));
       
  3084 		iAuthenticationCtrl.LinkKeyRequestNegativeReply(aAddr);
       
  3085 		iRequireAuthenticatedLinkKey = EFalse;
       
  3086 		}
       
  3087 	else if (iDeviceResult==KErrNone && iDevice.IsValidLinkKey())
       
  3088 		{
       
  3089 		if (iLinksMan.SecMan().DebugMode() && iDevice.LinkKeyType() != ELinkKeyDebug)
       
  3090 			{
       
  3091 			LOG(_L("CPhysicalLink: Debug mode - Link to debug link key"))
       
  3092 			iAuthenticationCtrl.LinkKeyRequestNegativeReply(aAddr);
       
  3093 			}
       
  3094 		else
       
  3095 			{
       
  3096 			if (iDevice.LinkKeyType() != ELinkKeyCombination)
       
  3097 				{
       
  3098 				if (iRequireAuthenticatedLinkKey && iDevice.LinkKeyType() == ELinkKeyUnauthenticatedUpgradable && IsPairable())
       
  3099 					{
       
  3100 					LOG(_L("CPhysicalLink: Requiring Authenticated link key but currently only have unauthenticated"))
       
  3101 					iAuthenticationCtrl.LinkKeyRequestNegativeReply(aAddr);
       
  3102 					}
       
  3103 				else
       
  3104 					{
       
  3105 					LOG(_L("CPhysicalLink: Issuing link key to HC now"))
       
  3106 					iAuthenticationCtrl.LinkKeyRequestReply(aAddr, iDevice.LinkKey());
       
  3107 					}
       
  3108 				}
       
  3109 			else if(IsPasskeyMinLengthOK() && SimplePairingMode() != EPhySimplePairingEnabled)
       
  3110 				{
       
  3111 				LOG(_L("CPhysicalLink: Issuing link key to HC now"))
       
  3112 				iAuthenticationCtrl.LinkKeyRequestReply(aAddr, iDevice.LinkKey());
       
  3113 				}
       
  3114 			else
       
  3115 				{
       
  3116 				LOG(_L("CPhysicalLink: Current PIN code too short!"))
       
  3117 				iAuthenticationCtrl.LinkKeyRequestNegativeReply(aAddr);
       
  3118 				}
       
  3119 			}
       
  3120 		iRequireAuthenticatedLinkKey = EFalse;
       
  3121 		}
       
  3122 	else if (iDeviceResult==KErrNone && !iDevice.IsValidLinkKey() || iDeviceResult==KErrNotFound)
       
  3123 		{
       
  3124 		LOG(_L("CPhysicalLink: No Link key available for the device"));
       
  3125 		iAuthenticationCtrl.LinkKeyRequestNegativeReply(aAddr);
       
  3126 		iRequireAuthenticatedLinkKey = EFalse;
       
  3127 		}
       
  3128 	else
       
  3129 		{
       
  3130 		LOG(_L("CPhysicalLink: Waiting for link key from Registry!"))
       
  3131 		// we're still waiting for the device....we'll respond when it turns up
       
  3132 		iWaitingForLinkKeyFromRegistry = ETrue;
       
  3133 		}
       
  3134 
       
  3135 	}
  3051 	}
  3136 
  3052 
  3137 TInt CPhysicalLink::PINCodeRequestReply(const TBTDevAddr& aDevAddr, const TDesC8& aPin) const
  3053 TInt CPhysicalLink::PINCodeRequestReply(const TBTDevAddr& aDevAddr, const TDesC8& aPin) const
  3138 	{
  3054 	{
  3139 	ASSERT_DEBUG(aDevAddr == this->BDAddr());
  3055 	ASSERT_DEBUG(aDevAddr == this->BDAddr());
  3611 	iIOCapsReceived = ETrue;
  3527 	iIOCapsReceived = ETrue;
  3612 	iIOCapability = aIOCapability;
  3528 	iIOCapability = aIOCapability;
  3613 	iOOBDataPresence = aOOBDataPresence;
  3529 	iOOBDataPresence = aOOBDataPresence;
  3614 	iAuthenticationRequirement = aAuthenticationRequirement;
  3530 	iAuthenticationRequirement = aAuthenticationRequirement;
  3615 	
  3531 	
  3616 	//If we haven't determined the SSP pairing mode till now then enable it and notify the state m/c.
  3532 	// If we haven't determined the SSP pairing mode the link is operating in yet then enable it,
  3617 	//This condition is to cater the fast remote device which responds very quickly,  
  3533 	// since we have received a I/O cap response the simple pairing must be enabled.
  3618 	//even before we determine whether it supports simple pairing!*/ 
  3534 	// This condition is to cater the fast remote device which responds very quickly,
  3619 	__ASSERT_DEBUG(((SimplePairingMode() == EPhySimplePairingEnabled) || (SimplePairingMode() == EPhySimplePairingUndefined)),Panic(EBTSSPModeChangedDuringConnection));
  3535 	// even before we determine whether it supports simple pairing!
  3620 	if(SimplePairingMode() == EPhySimplePairingUndefined)
  3536 	RemoteSimplePairingModeDetermined(EPhySimplePairingEnabled);
  3621 		{
       
  3622 		//Since we have received a I/O cap response the simple pairing must be enabled
       
  3623 		iSimplePairingMode = EPhySimplePairingEnabled;
       
  3624 		iLinksMan.SecMan().SimplePairingSupportDetermined(BDAddr());
       
  3625 		}
       
  3626 	}
  3537 	}
  3627 
  3538 
  3628 
  3539 
  3629 TBool CPhysicalLink::AuthWithMITM() const
  3540 TBool CPhysicalLink::AuthWithMITM() const
  3630 	{
  3541 	{
  3749 	{
  3660 	{
  3750 	LOG_FUNC
  3661 	LOG_FUNC
  3751 	iPasskeyEntry->KeyPressed(aKey);
  3662 	iPasskeyEntry->KeyPressed(aKey);
  3752 	}
  3663 	}
  3753 
  3664 
       
  3665 void CPhysicalLink::NewUserConfirmerL(const TBTDevAddr aAddr,
       
  3666  										  CBTSecMan& aSecMan,
       
  3667  										  TBool	aInternallyInitiated)
       
  3668    	{
       
  3669 	LOG_FUNC
       
  3670  	__ASSERT_DEBUG(aAddr == BDAddr(), Panic(EBTConnectionBadDeviceAddress));
       
  3671   	iUserConfirmer = CBTUserConfirmer::NewL(aAddr, aSecMan, aInternallyInitiated);
       
  3672    	}
       
  3673 
       
  3674 CBTUserConfirmer* CPhysicalLink::InstanceUserConfirmer() const
       
  3675 	{
       
  3676 	LOG_FUNC
       
  3677 	return iUserConfirmer;
       
  3678 	}
       
  3679 
       
  3680 TBool CPhysicalLink::IsUserConfirmerActive()const
       
  3681 	{
       
  3682 	LOG_FUNC
       
  3683 	return iUserConfirmer->IsActive();
       
  3684 	}
       
  3685 
       
  3686 void CPhysicalLink::DeleteUserConfirmer()
       
  3687 	{
       
  3688 	LOG_FUNC
       
  3689 	delete iUserConfirmer;
       
  3690 	iUserConfirmer = NULL;
       
  3691 	}
       
  3692 
       
  3693 void CPhysicalLink::CancelUserConfirmer()
       
  3694 	{
       
  3695 	LOG_FUNC
       
  3696 	iUserConfirmer->Cancel();
       
  3697 	}
       
  3698 
  3754 
  3699 
  3755 TBasebandTime CPhysicalLink::GetSniffInterval() const
  3700 TBasebandTime CPhysicalLink::GetSniffInterval() const
  3756 	{
  3701 	{
  3757 	return iSniffInterval;
  3702 	return iSniffInterval;
       
  3703 	}
       
  3704 
       
  3705 void CPhysicalLink::LinkKeyRequestResponseAttempt(TBool aForceResponse)
       
  3706 	{
       
  3707 	ASSERT_DEBUG(iLinkKeyRequestOutstanding);
       
  3708 
       
  3709 	if(!iPeerInSecurityMode3 && iLinksMan.SecMan().IsDedicatedBondingAttempted(iDevice.Address()))
       
  3710 		{
       
  3711 		// If we are doing DedicatedBonding then we should ignore the existing linkkey
       
  3712 		// in an attempt to generate a stronger one if possible.
       
  3713 		// Security mode 3 is a odd case - because we get what looks like double pairing (the remote
       
  3714 		// initiated pairing on connection, then the dedicated bonding pairing).  So we have removed
       
  3715 		// this feature for security mode 3 devices...they will have to suffer for their transgressions
       
  3716 		LOG(_L("CPhysicalLink: Dedicated bonding attempt - Sending link key request negative reply"));
       
  3717 		DoLinkKeyResponse(EFalse);
       
  3718 		iRequireAuthenticatedLinkKey = EFalse;
       
  3719 		}
       
  3720 	else if (iDeviceResult==KErrNone && iDevice.IsValidLinkKey())
       
  3721 		{
       
  3722 		if (iLinksMan.SecMan().DebugMode() && iDevice.LinkKeyType() != ELinkKeyDebug)
       
  3723 			{
       
  3724 			LOG(_L("CPhysicalLink: Debug mode - Link to debug link key"))
       
  3725 			DoLinkKeyResponse(EFalse);
       
  3726 			}
       
  3727 		else if (iDevice.LinkKeyType() != ELinkKeyCombination)
       
  3728 			{
       
  3729 			if (iRequireAuthenticatedLinkKey && iDevice.LinkKeyType() == ELinkKeyUnauthenticatedUpgradable && IsPairable())
       
  3730 				{
       
  3731 				LOG(_L("CPhysicalLink: Requiring Authenticated link key but currently only have unauthenticated"))
       
  3732 				DoLinkKeyResponse(EFalse);
       
  3733 				}
       
  3734 			else
       
  3735 				{
       
  3736 				LOG(_L("CPhysicalLink: non - combination key, auth OK"))
       
  3737 				DoLinkKeyResponse(ETrue);
       
  3738 				}
       
  3739 			}
       
  3740 		else // Standard (legacy) Combination Key
       
  3741 			{
       
  3742 			if (SimplePairingMode() == EPhySimplePairingUndefined)
       
  3743 				{
       
  3744 				LOG(_L("CPhysicalLink: Waiting for Secure Simple Pairing mode to be determined"));
       
  3745 				// wait for ssp mode to be determined...then try again
       
  3746 				}
       
  3747 			else if (IsPasskeyMinLengthOK() && SimplePairingMode() == EPhySimplePairingDisabled)
       
  3748 				{
       
  3749 				LOG(_L("CPhysicalLink: Combination key, Passkey len OK, no SSP"));
       
  3750 				DoLinkKeyResponse(ETrue);
       
  3751 				}
       
  3752 			else
       
  3753 				{
       
  3754 				LOG(_L("CPhysicalLink: Current link key is not sufficient!"))
       
  3755 				DoLinkKeyResponse(EFalse);
       
  3756 				}
       
  3757 			}
       
  3758 		iRequireAuthenticatedLinkKey = EFalse;
       
  3759 		}
       
  3760 	else if (iDeviceResult==KErrNone && !iDevice.IsValidLinkKey() || iDeviceResult==KErrNotFound)
       
  3761 		{
       
  3762 		LOG(_L("CPhysicalLink: No Link key available for the device"));
       
  3763 		DoLinkKeyResponse(EFalse);
       
  3764 		iRequireAuthenticatedLinkKey = EFalse;
       
  3765 		}
       
  3766 	else if (aForceResponse)
       
  3767 		{
       
  3768 		LOG(_L("CPhysicalLink: Forcing a link key response (-ve as we don't have a link key yet)"));
       
  3769 		DoLinkKeyResponse(EFalse);
       
  3770 		}
       
  3771 	else
       
  3772 		{
       
  3773 		LOG(_L("CPhysicalLink: Waiting for link key from Registry!"))
       
  3774 		// we're still waiting for the device....we'll respond when it turns up
       
  3775 		}
       
  3776 	}
       
  3777 
       
  3778 /**
       
  3779 Send a link key response for an outstanding request, assumes that all details
       
  3780 have be validated.
       
  3781 */
       
  3782 void CPhysicalLink::DoLinkKeyResponse(TBool aPositive)
       
  3783 	{
       
  3784 	LOG_FUNC
       
  3785 	ASSERT_DEBUG(iLinkKeyRequestOutstanding);
       
  3786 
       
  3787 	if(aPositive)
       
  3788 		{
       
  3789 		LOG(_L("CPhysicalLink: Providing link key to HC..."))
       
  3790 		ASSERT_DEBUG(iDevice.IsValidLinkKey());
       
  3791 		if (IsAuthenticationPending())
       
  3792 			{
       
  3793 			iLinkKeyReturnedInThisAuthentication = ETrue;
       
  3794 			}
       
  3795 		iAuthenticationCtrl.LinkKeyRequestReply(iDevice.Address(), iDevice.LinkKey());
       
  3796 		}
       
  3797 	else
       
  3798 		{
       
  3799 		LOG(_L("CPhysicalLink: Indicating no link key to HC..."));
       
  3800 		iAuthenticationCtrl.LinkKeyRequestNegativeReply(iDevice.Address());
       
  3801 		}
       
  3802 	iLinkKeyRequestOutstanding = EFalse;
       
  3803 	}
       
  3804 
       
  3805 void CPhysicalLink::RemoteSimplePairingModeDetermined(TPhysicalLinkSimplePairingMode aSimplePairingMode)
       
  3806 	{
       
  3807 	LOG2(_L8("Current SimplePairingMode = %d, aSimplePairingMode = %d"), SimplePairingMode(), aSimplePairingMode);
       
  3808 	ASSERT_DEBUG(aSimplePairingMode != EPhySimplePairingUndefined); // must be a definite value
       
  3809 	__ASSERT_DEBUG(SimplePairingMode() == aSimplePairingMode || SimplePairingMode() == EPhySimplePairingUndefined, Panic(EBTSSPModeChangedDuringConnection));
       
  3810 
       
  3811 	const TPhysicalLinkSimplePairingMode previousSetting = iSimplePairingMode;
       
  3812 	iSimplePairingMode = aSimplePairingMode;
       
  3813 	if (previousSetting != iSimplePairingMode)
       
  3814 		{
       
  3815 		iLinksMan.SecMan().SimplePairingSupportDetermined(BDAddr());
       
  3816 
       
  3817 		// Also we may be waiting to respond to a link key request.
       
  3818 		if (iLinkKeyRequestOutstanding)
       
  3819 			{
       
  3820 			LinkKeyRequestResponseAttempt();
       
  3821 			}
       
  3822 		}
       
  3823 	}
       
  3824 
       
  3825 void CPhysicalLink::SetPeerInSecurityMode3()
       
  3826 	{
       
  3827 	iPeerInSecurityMode3 = ETrue;
       
  3828 
       
  3829 	// We also now know that the remote cannot possibly do SSP, *and* the LMP will
       
  3830 	// likely lock our finding if the remote does SSP anyway while we do SM3.
       
  3831 	RemoteSimplePairingModeDetermined(EPhySimplePairingDisabled);
  3758 	}
  3832 	}
  3759 
  3833 
  3760 //
  3834 //
  3761 // TLowPowModeCmdController
  3835 // TLowPowModeCmdController
  3762 //
  3836 //