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) |
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 |
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 // |