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