bluetooth/btstack/secman/pairingserver.cpp
branchRCL_3
changeset 24 e9b924a62a66
parent 23 5b153be919d4
equal deleted inserted replaced
23:5b153be919d4 24:e9b924a62a66
   637 		{
   637 		{
   638 		OobDataManager().CancelReadLocalOobData(*this);
   638 		OobDataManager().CancelReadLocalOobData(*this);
   639 		}
   639 		}
   640 	}
   640 	}
   641 
   641 
   642 
       
   643 void COobDataSession::XoldoLocalOobDataRetrieved(TInt aResult, const TBluetoothSimplePairingHash& aHash, const TBluetoothSimplePairingRandomizer& aRandomizer)
   642 void COobDataSession::XoldoLocalOobDataRetrieved(TInt aResult, const TBluetoothSimplePairingHash& aHash, const TBluetoothSimplePairingRandomizer& aRandomizer)
   644 	{
   643 	{
   645 	LOG_FUNC
   644 	LOG_FUNC
   646 	__ASSERT_DEBUG(iReadLocalOobDataMsg.Handle(),
   645 	__ASSERT_DEBUG(iReadLocalOobDataMsg.Handle(),
   647 			PANIC(KPairingServerFaultCat, EPairingServerNoMessageForObserverCompletion));
   646 			PANIC(KPairingServerFaultCat, EPairingServerNoMessageForObserverCompletion));
   700 
   699 
   701 CDedicatedBondingSession::~CDedicatedBondingSession()
   700 CDedicatedBondingSession::~CDedicatedBondingSession()
   702 	{
   701 	{
   703 	LOG_FUNC
   702 	LOG_FUNC
   704 	iPhysicalLinksManager.SecMan().CancelRequest(*this);
   703 	iPhysicalLinksManager.SecMan().CancelRequest(*this);
   705 	delete iProxySap;
   704 	delete iProxySap; // cannot do an immediate shutdown as the semantics for that kill the phy
   706 	if(iStartBondingMsg.Handle())
   705 	if(!iStartBondingMsg.IsNull())
   707 		{
   706 		{
   708 		iStartBondingMsg.Complete(KErrCancel);
   707 		iStartBondingMsg.Complete(KErrCancel);
   709 		}
   708 		}
   710 	delete iAsyncShutdown;
   709 	delete iAsyncShutdown;
   711 	}
   710 	}
   716 	switch(aMessage.Function())
   715 	switch(aMessage.Function())
   717 		{
   716 		{
   718 	case EPairingServerStartDedicatedBond:
   717 	case EPairingServerStartDedicatedBond:
   719 		StartBondingL(aMessage);
   718 		StartBondingL(aMessage);
   720 		break;
   719 		break;
       
   720 		
   721 	default:
   721 	default:
   722 		CPairingSubSession::DispatchSubSessMessageL(aMessage);
   722 		CPairingSubSession::DispatchSubSessMessageL(aMessage);
   723 		break;
   723 		break;
   724 		}
   724 		}
   725 	}
   725 	}
   726 
   726 
   727 void CDedicatedBondingSession::Complete(TInt aError)
   727 void CDedicatedBondingSession::Complete(TInt aError)
   728 	{
   728 	{
   729 	LOG_FUNC
   729 	LOG_FUNC
   730 	iState = EShutdown;
   730 	if(!iStartBondingMsg.IsNull())
   731 	iAsyncShutdown->CallBack();
   731 		{
   732 	iStartBondingMsg.Complete(aError);
   732 		__ASSERT_DEBUG(!ShuttingDown(), PANIC(KPairingServerFaultCat, EPairingServerBadShutdownState));
       
   733 		iState = EShutdownRequested;
       
   734 		iAsyncShutdown->CallBack();
       
   735 		iPhysicalLinksManager.SecMan().CancelRequest(*this); // we don't want the result anymore (if it's still pending).
       
   736 		iStartBondingMsg.Complete(aError); 
       
   737 		}
       
   738 	else
       
   739 		{
       
   740 		__ASSERT_DEBUG(ShuttingDown(), PANIC(KPairingServerFaultCat, EPairingServerBadShutdownState));
       
   741 		}
   733 	}
   742 	}
   734 
   743 
   735 TInt CDedicatedBondingSession::StaticShutdown(TAny* aDedBond)
   744 TInt CDedicatedBondingSession::StaticShutdown(TAny* aDedBond)
   736 	{
   745 	{
   737 	LOG_STATIC_FUNC
   746 	LOG_STATIC_FUNC
   740 	}
   749 	}
   741 
   750 
   742 void CDedicatedBondingSession::Shutdown()
   751 void CDedicatedBondingSession::Shutdown()
   743 	{
   752 	{
   744 	LOG_FUNC
   753 	LOG_FUNC
   745 	__ASSERT_DEBUG(iState == EShutdown, PANIC(KPairingServerFaultCat, EPairingServerBadShutdownState));
   754 	__ASSERT_DEBUG(iState == EShutdownRequested, PANIC(KPairingServerFaultCat, EPairingServerBadShutdownState));
   746 	iState = EInvalid;
   755 	__ASSERT_DEBUG(iStartBondingMsg.IsNull(), PANIC(KPairingServerFaultCat, EPairingServerMessageShouldBeNull));
       
   756 	iState = EShutdownPending;
   747 	iProxySap->Shutdown(CServProviderBase::ENormal);
   757 	iProxySap->Shutdown(CServProviderBase::ENormal);
   748 	}
   758 	}
       
   759 	
       
   760 TBool CDedicatedBondingSession::ShuttingDown() const
       
   761 	{
       
   762 	return iState == EShutdownRequested || iState == EShutdownPending;
       
   763 	}
   749 
   764 
   750 void CDedicatedBondingSession::StartBondingL(const RMessage2& aMessage)
   765 void CDedicatedBondingSession::StartBondingL(const RMessage2& aMessage)
   751 	{
   766 	{
   752 	LOG_FUNC
   767 	LOG_FUNC
   753 
   768 
   754 	if(!iStartBondingMsg.IsNull() || iState != EInvalid)
   769 	if(iState != EMintCondition)
   755 		{
   770 		{
   756 		aMessage.Panic(KPairingServerPanicCat, EPairingServerDedicatedBondAlreadyInProgress);
   771 		aMessage.Panic(KPairingServerPanicCat, EPairingServerDedicatedBondAlreadyInProgress);
   757 		return;
   772 		return;
   758 		}
   773 		}
   759 
   774 	__ASSERT_DEBUG(iStartBondingMsg.IsNull(), PANIC(KPairingServerFaultCat, EPairingServerMessageShouldBeNull));
       
   775 	
       
   776 	// Now we've been initiated, no turning back for this object.
       
   777 	iState = EInitiated;
       
   778 	
   760 	TPckgBuf<TBTDevAddr> addrBuf;
   779 	TPckgBuf<TBTDevAddr> addrBuf;
   761 	TInt addrLen = aMessage.GetDesLengthL(0);
   780 	TInt addrLen = aMessage.GetDesLengthL(0);
   762 	if(addrLen != sizeof(TBTDevAddr))
   781 	if(addrLen != sizeof(TBTDevAddr))
   763 		{
   782 		{
   764 		// If the length is correct then the address has been packaged incorrect for the
   783 		// If the length is incorrect then the address has been packaged incorrectly for the
   765 		// IPC operation.
   784 		// IPC operation.
   766 		LEAVEL(KErrBadDescriptor);
   785 		LEAVEL(KErrBadDescriptor);
   767 		}
   786 		}
   768 	aMessage.ReadL(0, addrBuf);
   787 	aMessage.ReadL(0, addrBuf);
   769 
       
   770 	iStartBondingMsg = aMessage;
       
   771 	CleanupStack::PushL(TCleanupItem(CleanupStartMessage, this));
       
   772 
   788 
   773 	TBTSockAddr addr;
   789 	TBTSockAddr addr;
   774 	addr.SetBTAddr(addrBuf());
   790 	addr.SetBTAddr(addrBuf());
   775 	iProxySap = CBTProxySAP::NewL(iPhysicalLinksManager, NULL);
   791 	iProxySap = CBTProxySAP::NewL(iPhysicalLinksManager, NULL);
   776 
       
   777 	CleanupStack::Pop(this); // the start message cleaner
       
   778 	
   792 	
       
   793 	iStartBondingMsg = aMessage;
   779 	// Now we've entered the realm of not leaving with an error, since the connection
   794 	// Now we've entered the realm of not leaving with an error, since the connection
   780 	// process has started.  Errors from now on must be via the Error() function call.
   795 	// process has started.  Errors from now on must be via the Error() function call.
       
   796 	
   781 	iState = EInitialConnectionPending;
   797 	iState = EInitialConnectionPending;
   782 	iProxySap->SetNotify(this);
   798 	iProxySap->SetNotify(this);
   783 	iProxySap->SetRemName(addr);
   799 	iProxySap->SetRemName(addr);
   784 	iProxySap->ActiveOpen();
   800 	iProxySap->ActiveOpen();
   785 	TRAPD(err, DoAccessRequestL());
   801 	TRAPD(err, DoAccessRequestL());
   786 	if(err != KErrNone)
   802 	if(err != KErrNone)
   787 		{
   803 		{
   788 		Error(err);
   804 		Error(err);
   789 		}
   805 		}
   790 	}
       
   791 
       
   792 void CDedicatedBondingSession::CleanupStartMessage(TAny* aPtr)
       
   793 	{
       
   794 	LOG_STATIC_FUNC
       
   795 	CDedicatedBondingSession* session = reinterpret_cast<CDedicatedBondingSession*>(aPtr);
       
   796 	session->iStartBondingMsg = RMessage2(); // blat the old one
       
   797 	}
   806 	}
   798 
   807 
   799 void CDedicatedBondingSession::DoAccessRequestL()
   808 void CDedicatedBondingSession::DoAccessRequestL()
   800 	{
   809 	{
   801 	LOG_FUNC
   810 	LOG_FUNC
   831 			}
   840 			}
   832 		// else not deferred so complete now....
   841 		// else not deferred so complete now....
   833 		// fall-through...
   842 		// fall-through...
   834 	case EInitialConnection:
   843 	case EInitialConnection:
   835 		ASSERT_DEBUG(aResult != EBTSecManAccessDeferred); // Should have been disconnected if we receive
   844 		ASSERT_DEBUG(aResult != EBTSecManAccessDeferred); // Should have been disconnected if we receive
   836 													// this - I don't expect this to happen.
   845 														  // this - I don't expect this to happen.
   837 		// fall-through...
   846 		// fall-through...
   838 	case EFinalConnection:
   847 	case EFinalConnection:
   839 		completed = ETrue; // in the final connection any complete is errored.
   848 		completed = ETrue; // in the final connection any complete is errored.
   840 		if(aResult == EBTSecManAccessDenied)
   849 		if(aResult == EBTSecManAccessDenied)
   841 			{
   850 			{
   842 			err = KErrAccessDenied;
   851 			err = KErrAccessDenied;
   843 			}
   852 			}
   844 		break;
   853 		break;
       
   854 		
   845 	case EInitialConnectionPending:
   855 	case EInitialConnectionPending:
       
   856 		// fall-through deliberate
   846 	case EFinalConnectionPending:
   857 	case EFinalConnectionPending:
   847 		// Access request shouldn't successfully complete if the connection is still pending
   858 		// Access request shouldn't successfully complete if the connection is still pending
   848 		__ASSERT_DEBUG(aResult != EBTSecManAccessGranted,  PANIC(KPairingServerFaultCat, EPairingServerUnexpectedAccessCallback));
   859 		__ASSERT_DEBUG(aResult != EBTSecManAccessGranted,  PANIC(KPairingServerFaultCat, EPairingServerUnexpectedAccessCallback));
   849 		// We should get the MSocketNotify::Error callback, so don't do anything else
   860 		// We should get the MSocketNotify::Error callback, so don't do anything else
   850 		break;
   861 		break;
       
   862 		
   851 	default:
   863 	default:
   852 		LOG1(_L("Unexpected Access Request Complete in state %d"), iState);
   864 		LOG1(_L("Unexpected Access Request Complete in state %d"), iState);
   853 		__ASSERT_DEBUG(EFalse, PANIC(KPairingServerFaultCat, EPairingServerUnexpectedAccessCallback));
   865 		__ASSERT_DEBUG(EFalse, PANIC(KPairingServerFaultCat, EPairingServerUnexpectedAccessCallback));
   854 		break;
   866 		break;
   855 		}
   867 		}
   883 		iState = EInitialConnection;
   895 		iState = EInitialConnection;
   884 		break;
   896 		break;
   885 	case EFinalConnectionPending:
   897 	case EFinalConnectionPending:
   886 		iState = EFinalConnection;
   898 		iState = EFinalConnection;
   887 		break;
   899 		break;
       
   900 		
   888 	case EInitialConnection:
   901 	case EInitialConnection:
       
   902 		// fall-through deliberate
   889 	case EFinalConnection:
   903 	case EFinalConnection:
   890 		// Apparently multiple connect completes are allowed by CSocket
   904 		// Apparently multiple connect completes are allowed by CSocket
   891 		break;
   905 		break;
   892 	case EShutdown:
   906 		
       
   907 	case EShutdownRequested:
       
   908 		// fall-through deliberate
       
   909 	case EShutdownPending:
   893 		// If an error occurred just after the connection request then we
   910 		// If an error occurred just after the connection request then we
   894 		// might receive a connection complete before the async shutdown request
   911 		// might receive a connection complete before the async shutdown request
   895 		// has been executed.
   912 		// has been executed or completed.
   896 		break;
   913 		break;
       
   914 		
   897 	default:
   915 	default:
   898 		LOG1(_L("Unexpected Connect Complete in state %d"), iState);
   916 		LOG1(_L("Unexpected Connect Complete in state %d"), iState);
   899 		__ASSERT_DEBUG(EFalse, PANIC(KPairingServerFaultCat, EPairingServerUnexpectedSocketCallback));
   917 		__ASSERT_DEBUG(EFalse, PANIC(KPairingServerFaultCat, EPairingServerUnexpectedSocketCallback));
   900 		break;
   918 		break;
   901 		}
   919 		}
   922 	}
   940 	}
   923 
   941 
   924 void CDedicatedBondingSession::CanClose(TDelete aDelete)
   942 void CDedicatedBondingSession::CanClose(TDelete aDelete)
   925 	{
   943 	{
   926 	LOG_FUNC
   944 	LOG_FUNC
       
   945 	__ASSERT_DEBUG(iState == EShutdownPending, PANIC(KPairingServerFaultCat, EPairingServerUnexpectedSocketCallback));
       
   946 	__ASSERT_DEBUG(iStartBondingMsg.IsNull(), PANIC(KPairingServerFaultCat, EPairingServerMessageShouldBeNull));
       
   947 	iState = EShutdown;
   927 	if (aDelete == EDelete)
   948 	if (aDelete == EDelete)
   928 		{
   949 		{
   929 		delete iProxySap; iProxySap = NULL;
   950 		delete iProxySap; iProxySap = NULL;
   930 		}
   951 		}
   931 	}
   952 	}
   949 		{
   970 		{
   950 	case EInitialConnection:
   971 	case EInitialConnection:
   951 		// enter the zombie state and wait for the access requester to complete.
   972 		// enter the zombie state and wait for the access requester to complete.
   952 		iState = EZombie;
   973 		iState = EZombie;
   953 		break;
   974 		break;
       
   975 		
   954 	case EFinalConnection:
   976 	case EFinalConnection:
   955 		Error(KErrDisconnected);
   977 		Error(KErrDisconnected);
   956 		break;
   978 		break;
   957 	case EShutdown:
   979 		
       
   980 	case EShutdownRequested:
       
   981 		// fall-through deliberate
       
   982 	case EShutdownPending:
   958 		// Already closing down.
   983 		// Already closing down.
   959 		break;
   984 		break;
       
   985 		
   960 	default:
   986 	default:
   961 		LOG1(_L("Unexpected Disconnect in state %d"), iState);
   987 		LOG1(_L("Unexpected Disconnect in state %d"), iState);
   962 		__ASSERT_DEBUG(EFalse, PANIC(KPairingServerFaultCat, EPairingServerUnexpectedSocketCallback));
   988 		__ASSERT_DEBUG(EFalse, PANIC(KPairingServerFaultCat, EPairingServerUnexpectedSocketCallback));
   963 		break;
   989 		break;
   964 		}
   990 		}