bluetooth/btstack/eirman/eirmanserver.cpp
branchGCC_SURGE
changeset 36 230aed0f16aa
parent 32 f72906e669b4
--- a/bluetooth/btstack/eirman/eirmanserver.cpp	Thu Jun 17 22:32:21 2010 +0100
+++ b/bluetooth/btstack/eirman/eirmanserver.cpp	Thu Jul 22 16:44:39 2010 +0100
@@ -1,4 +1,4 @@
-// Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
+// Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies).
 // All rights reserved.
 // This component and the accompanying materials are made available
 // under the terms of "Eclipse Public License v1.0"
@@ -58,9 +58,11 @@
 	: CPolicyServer(CActive::EPriorityStandard, KEirManServerPolicy)
 	, iCommandQueue(aCommandQueue)
 	, iLinkMgrProtocol(aLinkMgrProtocol)
-	, iSessionCount(0)
+	, iInternalSessionCount(0)
+	, iExternalSessionCount(0)
 	, iIsFeaturesReady(EFalse)
 	, iIsEirSupported(EFalse)
+	, iSessions(_FOFF(CEirManSession, iLink))
 	{
 	LOG_FUNC
 	}
@@ -93,28 +95,63 @@
 	
 	CEirManServer* ncThis = const_cast<CEirManServer*>(this);
 	
-	CEirManSession* sess = CEirManSession::NewL(*ncThis);
+	CEirManExternalSession* sess = CEirManExternalSession::NewL(*ncThis);
 	LOG1(_L("\tsess = 0x%08x"), sess);
 	return sess;
 	}
 
-void CEirManServer::AddSession()
+CEirManInternalSession* CEirManServer::NewInternalSessionL(MEirInternalSessionNotifier& aParent)
+	{
+	LOG_FUNC
+	// Server will refuse to create any more session if we have found out eir isn't supported.
+	if(iIsFeaturesReady && !iIsEirSupported)
+		{
+		User::Leave(KErrNotSupported);
+		}
+	CEirManInternalSession* sess = CEirManInternalSession::NewL(*this, aParent);
+	return sess;
+	}
+
+void CEirManServer::AddSession(CEirManSession& aSession, TBool aInternalSession)
 	{
 	LOG_FUNC
-	if(iSessionCount++ == 0)
+	
+	iSessions.AddLast(aSession);
+	
+	if (aInternalSession)
 		{
-		// While we have clients we need to make sure that the protocol remains alive.
-		iLinkMgrProtocol.LocalOpen();
+		if(iInternalSessionCount++ == 0)
+			{
+			// While we have clients we need to make sure that the protocol remains alive.
+			iLinkMgrProtocol.LocalOpen();
+			}
+		}
+	else
+		{
+		if(iExternalSessionCount++ == 0)
+			{
+			// While we have clients we need to make sure that the protocol remains alive.
+			iLinkMgrProtocol.Open();
+			}
 		}
 	}
 
-void CEirManServer::DropSession()
+void CEirManServer::DropSession(TBool aInternalSession)
 	{
 	LOG_FUNC
-	if(--iSessionCount == 0)
+	if (aInternalSession)
 		{
-		// There are no long 
-		iLinkMgrProtocol.LocalClose();
+		if(--iInternalSessionCount == 0)
+			{
+			iLinkMgrProtocol.LocalClose();
+			}
+		}
+	else
+		{
+		if(--iExternalSessionCount == 0)
+			{
+			iLinkMgrProtocol.Close();
+			}		
 		}
 	}
 
@@ -126,8 +163,10 @@
 		TRAPD(err, iEirManager = CEirManager::NewL(iCommandQueue, iLinkMgrProtocol));
 		iIsFeaturesReady = ETrue;
 		
-		iSessionIter.SetToFirst();
-		CSession2* sessionPtr;
+		TDblQueIter<CEirManSession> sessionIter(iSessions);
+		
+		sessionIter.SetToFirst();
+		CEirManSession* sessionPtr;
 		if(iLinkMgrProtocol.IsExtendedInquiryResponseSupportedLocally() && err == KErrNone)
 			{
 			iIsEirSupported = ETrue;
@@ -137,10 +176,9 @@
 			err = ((err != KErrNone) ? KErrNoMemory : KErrNotSupported);
 			}
 		
-		while((sessionPtr = iSessionIter++) != NULL)
+		while((sessionPtr = sessionIter++) != NULL)
 			{
-			CEirManSession* eirSession = static_cast<CEirManSession*>(sessionPtr);
-			eirSession->NotifyEirFeatureState(err);
+			sessionPtr->NotifyEirFeatureState(err);
 			}
 		}
 	}
@@ -171,42 +209,46 @@
 	_LIT_SECURITY_POLICY_S0(KSDPSecurityPolicy, KSDPServerID);
 	_LIT_SECURITY_POLICY_S0(KStackSecurityPolicy, KStackID);
 	_LIT_SECURITY_POLICY_C1(KVendorSpecificDataSecurityPolicy, ECapabilityWriteDeviceData);
-	if(function == EEirManRegisterTag)
+	_LIT_SECURITY_POLICY_C1(KEirCommonSecurityPolicy, ECapabilityLocalServices);
+
+	if(KEirCommonSecurityPolicy.CheckPolicy(aMsg))
 		{
-		tag = static_cast<TEirTag>(aMsg.Int0());
-		switch(tag)
+		if(function == EEirManRegisterTag)
 			{
-			case EEirTagName:
-			case EEirTagTxPowerLevel:
-				/** These must have come from the stack **/
-				if(KStackSecurityPolicy.CheckPolicy(aMsg))
-					{
-					result = EPass;
-					}
-				break;
-			case EEirTagSdpUuid16:
-			case EEirTagSdpUuid32:
-			case EEirTagSdpUuid128:
-				/** These must have come from SDP server **/
-				if(KSDPSecurityPolicy.CheckPolicy(aMsg))
-					{
-					result = EPass;
-					}
-				break;
-			case EEirTagManufacturerSpecific:
-				/** To do this you must have write device data **/
-				if(KVendorSpecificDataSecurityPolicy.CheckPolicy(aMsg))
-					{
-					result = EPass;
-					}
-				break;
-			
-			case EEirTagFlags:
-				/** At present no implementation of Flags is supported. 
-				    So we are rejecting this until an implementation is provided. **/
-			default: //unknown or reserved tag, reject
-				//no need to do anything 
-				break;
+			tag = static_cast<TEirTag>(aMsg.Int0());
+			switch(tag)
+				{
+				case EEirTagName:
+				case EEirTagTxPowerLevel:
+					/** These must have come from the stack **/
+					if(KStackSecurityPolicy.CheckPolicy(aMsg))
+						{
+						result = EPass;
+						}
+					break;
+				case EEirTagSdpUuid16:
+				case EEirTagSdpUuid32:
+				case EEirTagSdpUuid128:
+					/** These must have come from SDP server **/
+					if(KSDPSecurityPolicy.CheckPolicy(aMsg))
+						{
+						result = EPass;
+						}
+					break;
+				case EEirTagManufacturerSpecific:
+					/** To do this you must have write device data **/
+					if(KVendorSpecificDataSecurityPolicy.CheckPolicy(aMsg))
+						{
+						result = EPass;
+						}
+					break;
+				case EEirTagFlags:
+					/** At present no implementation of Flags is supported. 
+					So we are rejecting this until an implementation is provided. **/
+				default: //unknown or reserved tag, reject
+					//no need to do anything 
+					break;
+				}
 			}
 		}
 	//Anything not covered by the above is invalid so do nothing and let it fail