bluetooth/btstack/secman/secman.cpp
branchRCL_3
changeset 11 20fda83a6398
parent 8 2b6718f05bdb
child 12 9b6d3ca0c601
equal deleted inserted replaced
10:8a27654f7b62 11:20fda83a6398
   553 		}
   553 		}
   554 
   554 
   555 	CPhysicalLink* link = iPhysicalLinksManager->FindPhysicalLink(aAddr);
   555 	CPhysicalLink* link = iPhysicalLinksManager->FindPhysicalLink(aAddr);
   556 	__ASSERT_ALWAYS(link, PANIC(KBTSecPanic, EBTSecPhysicalLinkMissing));
   556 	__ASSERT_ALWAYS(link, PANIC(KBTSecPanic, EBTSecPhysicalLinkMissing));
   557 	__ASSERT_DEBUG(!link->InstanceNumericComparator(), PANIC(KBTSecPanic, EBTSecConnectionNumericComparisonTwice));
   557 	__ASSERT_DEBUG(!link->InstanceNumericComparator(), PANIC(KBTSecPanic, EBTSecConnectionNumericComparisonTwice));
       
   558 	__ASSERT_DEBUG(!link->InstanceUserConfirmer(), PANIC(KBTSecPanic, EBTSecConnectionUserConfirmationTwice));
   558 	if(link->InstanceNumericComparator())
   559 	if(link->InstanceNumericComparator())
   559 		{
   560 		{
   560 		return;
   561 		return;
   561 		}
   562 		}
   562 
   563 
   579 				TRAP_IGNORE(iCommandController->UserConfirmationRequestNegativeReplyL(aAddr));
   580 				TRAP_IGNORE(iCommandController->UserConfirmationRequestNegativeReplyL(aAddr));
   580 				return;// No passkey or comparison dialogs; disconnect instead
   581 				return;// No passkey or comparison dialogs; disconnect instead
   581 				}
   582 				}
   582 			}
   583 			}
   583 		}
   584 		}
       
   585 	else if (!link->IsPairingExpected())
       
   586 		{
       
   587 		TRAPD(err,link->NewUserConfirmerL(aAddr, *this, ETrue));
       
   588 		if(err)
       
   589 			{
       
   590 			if(requester)
       
   591 				{
       
   592 				requester->CompleteRequest(EBTSecManAccessDenied);
       
   593 				}
       
   594 			else
       
   595 				{
       
   596 				TRAP_IGNORE(iCommandController->UserConfirmationRequestNegativeReplyL(aAddr));
       
   597 				return;// No passkey or comparison dialogs; disconnect instead
       
   598 				}
       
   599 			}
       
   600 		}
   584 	else
   601 	else
   585 		{
   602 		{
   586 		// Just Work...
   603 		// Just Work...
   587 		if(requester)
   604 		if(requester)
   588 			{
   605 			{
   594 		// note: -- check errors here
   611 		// note: -- check errors here
   595 		TRAP_IGNORE(iCommandController->UserConfirmationRequestReplyL(aAddr));
   612 		TRAP_IGNORE(iCommandController->UserConfirmationRequestReplyL(aAddr));
   596 		}
   613 		}
   597 	}
   614 	}
   598 
   615 
   599 void CBTSecMan::UserConfirmationComplete(const TBTDevAddr& aAddr, TBool aResult, TInt aError)
   616 void CBTSecMan::NumericComparisonComplete(const TBTDevAddr& aAddr, TBool aResult, TInt aError)
   600 	{
   617 	{
   601 	LOG_FUNC
   618 	LOG_FUNC
   602 	CBTAccessRequester* requester = FindActiveAccessRequester(aAddr);
   619 	CBTAccessRequester* requester = FindActiveAccessRequester(aAddr);
   603 	if (requester)
   620 	if (requester)
   604 		{
   621 		{
   638 			// note: -- check errors here
   655 			// note: -- check errors here
   639 			TRAP_IGNORE(iCommandController->UserConfirmationRequestNegativeReplyL(aAddr));
   656 			TRAP_IGNORE(iCommandController->UserConfirmationRequestNegativeReplyL(aAddr));
   640 			}
   657 			}
   641 		}
   658 		}
   642 	link->DeleteNumericComparator();
   659 	link->DeleteNumericComparator();
       
   660 	}
       
   661 
       
   662 void CBTSecMan::UserConfirmationComplete(const TBTDevAddr& aAddr, TBool aResult, TInt aError)
       
   663 	{
       
   664 	LOG_FUNC
       
   665 	CBTAccessRequester* requester = FindActiveAccessRequester(aAddr);
       
   666 	if (requester)
       
   667 		{
       
   668 		LOG(_L8("\tCBTAccessRequester FOUND!\n"));
       
   669 		if (aError == KErrNone)
       
   670 			{
       
   671 			TBTSecEventUserConfirmationComplete event(aResult);
       
   672 			requester->SendEvent(event);
       
   673 			}
       
   674 		else if (aError == KErrNotFound) // KErrNotFound -> Notifier isn't present, so allow anyway
       
   675 			{
       
   676 			TBTSecEventUserConfirmationComplete event(ETrue);
       
   677 			requester->SendEvent(event);
       
   678 			}
       
   679 		else
       
   680 			{
       
   681 			TBTSecEventUserConfirmationComplete event(EFalse);  // Failed, so send EFalse
       
   682 			requester->SendEvent(event);
       
   683 			}
       
   684 		}
       
   685 
       
   686 	CPhysicalLink* link = iPhysicalLinksManager->FindPhysicalLink(aAddr);
       
   687 	__ASSERT_ALWAYS(link, PANIC(KBTSecPanic, EBTSecPhysicalLinkMissing));
       
   688 
       
   689 	if (aError==KErrNotFound) // KErrNotFound -> Notifier isn't present, so allow anyway
       
   690 		{
       
   691 		link->PinRequestSent();
       
   692 		// note: -- check errors here
       
   693 		TRAP_IGNORE(iCommandController->UserConfirmationRequestReplyL(aAddr));
       
   694 		}
       
   695 	else if (aError!=KErrNone)
       
   696 		{
       
   697 		// there was an error somewhere a long the way so respond negatively
       
   698 		// note: -- check errors here
       
   699 		TRAP_IGNORE(iCommandController->UserConfirmationRequestNegativeReplyL(aAddr));
       
   700 		}
       
   701 	else
       
   702 		{
       
   703 		// got a result
       
   704 		if(aResult)
       
   705 			{
       
   706 			link->PinRequestSent();
       
   707 			// note: -- check errors here
       
   708 			TRAP_IGNORE(iCommandController->UserConfirmationRequestReplyL(aAddr));
       
   709 			}
       
   710 		else
       
   711 			{
       
   712 			// note: -- check errors here
       
   713 			TRAP_IGNORE(iCommandController->UserConfirmationRequestNegativeReplyL(aAddr));
       
   714 			}
       
   715 		}
       
   716 	link->DeleteUserConfirmer();
   643 	}
   717 	}
   644 
   718 
   645 void CBTSecMan::PasskeyNotification(const TBTDevAddr& aAddr, TUint32 aPasskey)
   719 void CBTSecMan::PasskeyNotification(const TBTDevAddr& aAddr, TUint32 aPasskey)
   646 	{
   720 	{
   647 	LOG_FUNC
   721 	LOG_FUNC
   804 		PasskeyNotificationComplete(aAddr, err);
   878 		PasskeyNotificationComplete(aAddr, err);
   805 		}
   879 		}
   806 	if (link->InstanceNumericComparator() && link->IsNumericComparatorActive())
   880 	if (link->InstanceNumericComparator() && link->IsNumericComparatorActive())
   807 		{
   881 		{
   808 		link->CancelNumericComparator();
   882 		link->CancelNumericComparator();
       
   883 		NumericComparisonComplete(aAddr, EFalse, err);
       
   884 		}
       
   885 	if (link->InstanceUserConfirmer() && link->IsUserConfirmerActive())
       
   886 		{
       
   887 		link->CancelUserConfirmer();
   809 		UserConfirmationComplete(aAddr, EFalse, err);
   888 		UserConfirmationComplete(aAddr, EFalse, err);
   810 		}
   889 		}
   811 
       
   812 	iPhysicalLinksManager->SimplePairingComplete(aAddr, aError);
   890 	iPhysicalLinksManager->SimplePairingComplete(aAddr, aError);
   813 
   891 
   814  	// Add result to list (always with HCI error code).
   892  	// Add result to list (always with HCI error code).
   815  	// Pairing results will be added only if pairing that involved numeric Comparison or passkey entry.
   893  	// Pairing results will be added only if pairing that involved numeric Comparison or passkey entry.
   816  	// It should not be added if the pairing completed using Just Works
   894  	// It should not be added if the pairing completed using Just Works
  1751 	RemoveMyselfFromQue();
  1829 	RemoveMyselfFromQue();
  1752 	iIsAddedToNotifierQue = EFalse;
  1830 	iIsAddedToNotifierQue = EFalse;
  1753 
  1831 
  1754 	__ASSERT_DEBUG(iNumericComparisonParamsPckg().DeviceAddress() == iDevAddr, PANIC(KBTSecPanic, EBTSecBadDeviceAddress));
  1832 	__ASSERT_DEBUG(iNumericComparisonParamsPckg().DeviceAddress() == iDevAddr, PANIC(KBTSecPanic, EBTSecBadDeviceAddress));
  1755 
  1833 
  1756 	iSecMan.UserConfirmationComplete(iDevAddr, iResultPckg(), iStatus.Int());
  1834 	iSecMan.NumericComparisonComplete(iDevAddr, iResultPckg(), iStatus.Int());
  1757 	}
  1835 	}
  1758 
  1836 
  1759 TInt CBTNumericComparator::RunError(TInt aError)
  1837 TInt CBTNumericComparator::RunError(TInt aError)
  1760 	{
  1838 	{
  1761 	LOG_FUNC
  1839 	LOG_FUNC
  1915 	//will never get called as our RunL doesn't leave.
  1993 	//will never get called as our RunL doesn't leave.
  1916 	LOG1(_L8("\tCBTPasskeyEntry::RunError(%d)\n"), aError);
  1994 	LOG1(_L8("\tCBTPasskeyEntry::RunError(%d)\n"), aError);
  1917 	return aError;
  1995 	return aError;
  1918 	}
  1996 	}
  1919 
  1997 
       
  1998 //------------------------------------------------------------------------//
       
  1999 //class CBTNumericComparator
       
  2000 //------------------------------------------------------------------------//
       
  2001 CBTUserConfirmer* CBTUserConfirmer::NewL(const TBTDevAddr aAddr,
       
  2002 												 CBTSecMan& aSecMan,
       
  2003 												 TBool aInternallyInitiated)
       
  2004 	{
       
  2005 	LOG_STATIC_FUNC
       
  2006 	CBTUserConfirmer* s = CBTUserConfirmer::NewLC(aAddr, aSecMan, aInternallyInitiated);
       
  2007 	CleanupStack::Pop(s);
       
  2008 	return s;
       
  2009 	}
       
  2010 
       
  2011 CBTUserConfirmer* CBTUserConfirmer::NewLC(const TBTDevAddr aAddr,
       
  2012 												  CBTSecMan& aSecMan,
       
  2013 												  TBool aInternallyInitiated)
       
  2014 	{
       
  2015 	LOG_STATIC_FUNC
       
  2016 	CBTUserConfirmer* s = new(ELeave) CBTUserConfirmer(aSecMan, aInternallyInitiated);
       
  2017 	CleanupStack::PushL(s);
       
  2018 	s->ConstructL(aAddr);
       
  2019 	return s;
       
  2020 	}
       
  2021 
       
  2022 CBTUserConfirmer::CBTUserConfirmer(CBTSecMan& aSecMan, TBool aInternallyInitiated)
       
  2023 	: CSecNotifierRequester(aSecMan)
       
  2024 	, iSecMan(aSecMan)
       
  2025 	, iInternallyInitiated(aInternallyInitiated)
       
  2026 	{
       
  2027 	LOG_FUNC
       
  2028 	CActiveScheduler::Add(this);
       
  2029 	}
       
  2030 
       
  2031 CBTUserConfirmer::~CBTUserConfirmer()
       
  2032 	{
       
  2033 	LOG_FUNC
       
  2034 	Cancel();
       
  2035 	delete iNameUpdater;
       
  2036 	}
       
  2037 
       
  2038 
       
  2039 void CBTUserConfirmer::DoUpdateNotifier()
       
  2040 	{
       
  2041 	LOG_FUNC
       
  2042 	if(IsActive())
       
  2043 		{
       
  2044 		if(!iNameUpdater)
       
  2045 			{
       
  2046 			//Create a new CSecNotifierUpdateAO object
       
  2047 			TRAP_IGNORE(iNameUpdater = CSecNotifierUpdateAO<TBTDeviceNameUpdateParamsPckg>::NewL(iNotifier, KBTUserConfirmationNotifierUid));
       
  2048 			}
       
  2049 		if(iNameUpdater)
       
  2050 			{
       
  2051 			TBTDeviceName deviceName(KNullDesC);
       
  2052 			TInt err = KErrNotFound;
       
  2053 			if(iDeviceName)
       
  2054 				{
       
  2055 				TRAP(err, deviceName = BTDeviceNameConverter::ToUnicodeL(*iDeviceName)); // Best effort attempt.
       
  2056 				}
       
  2057 
       
  2058 			TBTDeviceNameUpdateParamsPckg pckg = TBTDeviceNameUpdateParams(deviceName, err);
       
  2059 			iNameUpdater->DoUpdate(pckg);
       
  2060 			}
       
  2061 		}
       
  2062 	}
       
  2063 
       
  2064 void CBTUserConfirmer::DoRequest()
       
  2065 /**
       
  2066 Start the RNotifier plugin that deals with authorisation.
       
  2067 **/
       
  2068 	{
       
  2069 	LOG_FUNC
       
  2070 	TInt err(KErrNone);
       
  2071 
       
  2072 	TBTDeviceName deviceName;
       
  2073 
       
  2074 	if (iDeviceName)
       
  2075 		{
       
  2076 		TRAP(err, deviceName = BTDeviceNameConverter::ToUnicodeL(*iDeviceName));
       
  2077 		if (err!=KErrNone)
       
  2078 			{
       
  2079 			deviceName = KNullDesC;
       
  2080 			}
       
  2081 		}
       
  2082 	else
       
  2083 		{
       
  2084 		deviceName = KNullDesC;
       
  2085 		}
       
  2086 	iUserConfirmationParamsPckg = TBTUserConfirmationParams(iDevAddr, deviceName, iInternallyInitiated);
       
  2087 
       
  2088 	iNotifier.StartNotifierAndGetResponse(iStatus, KBTUserConfirmationNotifierUid, iUserConfirmationParamsPckg, iResultPckg);
       
  2089 	SetActive();
       
  2090 	}
       
  2091 
       
  2092 
       
  2093 void CBTUserConfirmer::DoCancel()
       
  2094 	{
       
  2095 	LOG_FUNC
       
  2096 	iNotifier.CancelNotifier(KBTUserConfirmationNotifierUid);
       
  2097 	if(iNameUpdater)
       
  2098 		{
       
  2099 		iNameUpdater->Cancel();
       
  2100 		}
       
  2101 	}
       
  2102 
       
  2103 void CBTUserConfirmer::RunL()
       
  2104 	{
       
  2105 	LOG_FUNC
       
  2106 	// got an answer so unload the notifier
       
  2107 	iNotifier.CancelNotifier(KBTUserConfirmationNotifierUid);
       
  2108 
       
  2109 	//remove ourself from the notifier que, allowing the next notifier to be activated
       
  2110 	RemoveMyselfFromQue();
       
  2111 	iIsAddedToNotifierQue = EFalse;
       
  2112 
       
  2113 	__ASSERT_DEBUG(iUserConfirmationParamsPckg().DeviceAddress() == iDevAddr, PANIC(KBTSecPanic, EBTSecBadDeviceAddress));
       
  2114 
       
  2115 	iSecMan.UserConfirmationComplete(iDevAddr, iResultPckg(), iStatus.Int());
       
  2116 	}
       
  2117 
       
  2118 TInt CBTUserConfirmer::RunError(TInt aError)
       
  2119 	{
       
  2120 	LOG_FUNC
       
  2121 	//will never get called as our RunL doesn't leave.
       
  2122 	LOG1(_L8("\tCBTUserConfirmation::RunError(%d)\n"), aError);
       
  2123 	return aError;
       
  2124 	}
       
  2125 
       
  2126 
       
  2127