bluetooth/btstack/eirman/eirmanserver.cpp
changeset 32 f72906e669b4
parent 0 29b1cd4cb562
equal deleted inserted replaced
31:b9d1744dc449 32:f72906e669b4
     1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
     1 // Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     3 // This component and the accompanying materials are made available
     4 // under the terms of "Eclipse Public License v1.0"
     4 // under the terms of "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
    56 
    56 
    57 CEirManServer::CEirManServer(MHCICommandQueue& aCommandQueue, CLinkMgrProtocol& aLinkMgrProtocol)
    57 CEirManServer::CEirManServer(MHCICommandQueue& aCommandQueue, CLinkMgrProtocol& aLinkMgrProtocol)
    58 	: CPolicyServer(CActive::EPriorityStandard, KEirManServerPolicy)
    58 	: CPolicyServer(CActive::EPriorityStandard, KEirManServerPolicy)
    59 	, iCommandQueue(aCommandQueue)
    59 	, iCommandQueue(aCommandQueue)
    60 	, iLinkMgrProtocol(aLinkMgrProtocol)
    60 	, iLinkMgrProtocol(aLinkMgrProtocol)
    61 	, iSessionCount(0)
    61 	, iInternalSessionCount(0)
       
    62 	, iExternalSessionCount(0)
    62 	, iIsFeaturesReady(EFalse)
    63 	, iIsFeaturesReady(EFalse)
    63 	, iIsEirSupported(EFalse)
    64 	, iIsEirSupported(EFalse)
       
    65 	, iSessions(_FOFF(CEirManSession, iLink))
    64 	{
    66 	{
    65 	LOG_FUNC
    67 	LOG_FUNC
    66 	}
    68 	}
    67 
    69 
    68 void CEirManServer::ConstructL()
    70 void CEirManServer::ConstructL()
    91 		LEAVEIFERRORL(KErrNotSupported);
    93 		LEAVEIFERRORL(KErrNotSupported);
    92 		}
    94 		}
    93 	
    95 	
    94 	CEirManServer* ncThis = const_cast<CEirManServer*>(this);
    96 	CEirManServer* ncThis = const_cast<CEirManServer*>(this);
    95 	
    97 	
    96 	CEirManSession* sess = CEirManSession::NewL(*ncThis);
    98 	CEirManExternalSession* sess = CEirManExternalSession::NewL(*ncThis);
    97 	LOG1(_L("\tsess = 0x%08x"), sess);
    99 	LOG1(_L("\tsess = 0x%08x"), sess);
    98 	return sess;
   100 	return sess;
    99 	}
   101 	}
   100 
   102 
   101 void CEirManServer::AddSession()
   103 CEirManInternalSession* CEirManServer::NewInternalSessionL(MEirInternalSessionNotifier& aParent)
   102 	{
   104 	{
   103 	LOG_FUNC
   105 	LOG_FUNC
   104 	if(iSessionCount++ == 0)
   106 	// Server will refuse to create any more session if we have found out eir isn't supported.
   105 		{
   107 	if(iIsFeaturesReady && !iIsEirSupported)
   106 		// While we have clients we need to make sure that the protocol remains alive.
   108 		{
   107 		iLinkMgrProtocol.LocalOpen();
   109 		User::Leave(KErrNotSupported);
   108 		}
   110 		}
   109 	}
   111 	CEirManInternalSession* sess = CEirManInternalSession::NewL(*this, aParent);
   110 
   112 	return sess;
   111 void CEirManServer::DropSession()
   113 	}
   112 	{
   114 
   113 	LOG_FUNC
   115 void CEirManServer::AddSession(CEirManSession& aSession, TBool aInternalSession)
   114 	if(--iSessionCount == 0)
   116 	{
   115 		{
   117 	LOG_FUNC
   116 		// There are no long 
   118 	
   117 		iLinkMgrProtocol.LocalClose();
   119 	iSessions.AddLast(aSession);
       
   120 	
       
   121 	if (aInternalSession)
       
   122 		{
       
   123 		if(iInternalSessionCount++ == 0)
       
   124 			{
       
   125 			// While we have clients we need to make sure that the protocol remains alive.
       
   126 			iLinkMgrProtocol.LocalOpen();
       
   127 			}
       
   128 		}
       
   129 	else
       
   130 		{
       
   131 		if(iExternalSessionCount++ == 0)
       
   132 			{
       
   133 			// While we have clients we need to make sure that the protocol remains alive.
       
   134 			iLinkMgrProtocol.Open();
       
   135 			}
       
   136 		}
       
   137 	}
       
   138 
       
   139 void CEirManServer::DropSession(TBool aInternalSession)
       
   140 	{
       
   141 	LOG_FUNC
       
   142 	if (aInternalSession)
       
   143 		{
       
   144 		if(--iInternalSessionCount == 0)
       
   145 			{
       
   146 			iLinkMgrProtocol.LocalClose();
       
   147 			}
       
   148 		}
       
   149 	else
       
   150 		{
       
   151 		if(--iExternalSessionCount == 0)
       
   152 			{
       
   153 			iLinkMgrProtocol.Close();
       
   154 			}		
   118 		}
   155 		}
   119 	}
   156 	}
   120 
   157 
   121 void CEirManServer::NotifyFeaturesReady()
   158 void CEirManServer::NotifyFeaturesReady()
   122 	{
   159 	{
   124 		{
   161 		{
   125 		__ASSERT_DEBUG(!iEirManager, EIR_SERVER_PANIC(EEirServerEirMangerAlreadyExists));
   162 		__ASSERT_DEBUG(!iEirManager, EIR_SERVER_PANIC(EEirServerEirMangerAlreadyExists));
   126 		TRAPD(err, iEirManager = CEirManager::NewL(iCommandQueue, iLinkMgrProtocol));
   163 		TRAPD(err, iEirManager = CEirManager::NewL(iCommandQueue, iLinkMgrProtocol));
   127 		iIsFeaturesReady = ETrue;
   164 		iIsFeaturesReady = ETrue;
   128 		
   165 		
   129 		iSessionIter.SetToFirst();
   166 		TDblQueIter<CEirManSession> sessionIter(iSessions);
   130 		CSession2* sessionPtr;
   167 		
       
   168 		sessionIter.SetToFirst();
       
   169 		CEirManSession* sessionPtr;
   131 		if(iLinkMgrProtocol.IsExtendedInquiryResponseSupportedLocally() && err == KErrNone)
   170 		if(iLinkMgrProtocol.IsExtendedInquiryResponseSupportedLocally() && err == KErrNone)
   132 			{
   171 			{
   133 			iIsEirSupported = ETrue;
   172 			iIsEirSupported = ETrue;
   134 			}
   173 			}
   135 		else
   174 		else
   136 			{
   175 			{
   137 			err = ((err != KErrNone) ? KErrNoMemory : KErrNotSupported);
   176 			err = ((err != KErrNone) ? KErrNoMemory : KErrNotSupported);
   138 			}
   177 			}
   139 		
   178 		
   140 		while((sessionPtr = iSessionIter++) != NULL)
   179 		while((sessionPtr = sessionIter++) != NULL)
   141 			{
   180 			{
   142 			CEirManSession* eirSession = static_cast<CEirManSession*>(sessionPtr);
   181 			sessionPtr->NotifyEirFeatureState(err);
   143 			eirSession->NotifyEirFeatureState(err);
       
   144 			}
   182 			}
   145 		}
   183 		}
   146 	}
   184 	}
   147 
   185 
   148 TEirFeatureState CEirManServer::EirFeatureState()
   186 TEirFeatureState CEirManServer::EirFeatureState()
   169 	TEirTag tag;
   207 	TEirTag tag;
   170 	TCustomResult result = EFail; //Fail everything by default
   208 	TCustomResult result = EFail; //Fail everything by default
   171 	_LIT_SECURITY_POLICY_S0(KSDPSecurityPolicy, KSDPServerID);
   209 	_LIT_SECURITY_POLICY_S0(KSDPSecurityPolicy, KSDPServerID);
   172 	_LIT_SECURITY_POLICY_S0(KStackSecurityPolicy, KStackID);
   210 	_LIT_SECURITY_POLICY_S0(KStackSecurityPolicy, KStackID);
   173 	_LIT_SECURITY_POLICY_C1(KVendorSpecificDataSecurityPolicy, ECapabilityWriteDeviceData);
   211 	_LIT_SECURITY_POLICY_C1(KVendorSpecificDataSecurityPolicy, ECapabilityWriteDeviceData);
   174 	if(function == EEirManRegisterTag)
   212 	_LIT_SECURITY_POLICY_C1(KEirCommonSecurityPolicy, ECapabilityLocalServices);
   175 		{
   213 
   176 		tag = static_cast<TEirTag>(aMsg.Int0());
   214 	if(KEirCommonSecurityPolicy.CheckPolicy(aMsg))
   177 		switch(tag)
   215 		{
   178 			{
   216 		if(function == EEirManRegisterTag)
   179 			case EEirTagName:
   217 			{
   180 			case EEirTagTxPowerLevel:
   218 			tag = static_cast<TEirTag>(aMsg.Int0());
   181 				/** These must have come from the stack **/
   219 			switch(tag)
   182 				if(KStackSecurityPolicy.CheckPolicy(aMsg))
   220 				{
   183 					{
   221 				case EEirTagName:
   184 					result = EPass;
   222 				case EEirTagTxPowerLevel:
   185 					}
   223 					/** These must have come from the stack **/
   186 				break;
   224 					if(KStackSecurityPolicy.CheckPolicy(aMsg))
   187 			case EEirTagSdpUuid16:
   225 						{
   188 			case EEirTagSdpUuid32:
   226 						result = EPass;
   189 			case EEirTagSdpUuid128:
   227 						}
   190 				/** These must have come from SDP server **/
   228 					break;
   191 				if(KSDPSecurityPolicy.CheckPolicy(aMsg))
   229 				case EEirTagSdpUuid16:
   192 					{
   230 				case EEirTagSdpUuid32:
   193 					result = EPass;
   231 				case EEirTagSdpUuid128:
   194 					}
   232 					/** These must have come from SDP server **/
   195 				break;
   233 					if(KSDPSecurityPolicy.CheckPolicy(aMsg))
   196 			case EEirTagManufacturerSpecific:
   234 						{
   197 				/** To do this you must have write device data **/
   235 						result = EPass;
   198 				if(KVendorSpecificDataSecurityPolicy.CheckPolicy(aMsg))
   236 						}
   199 					{
   237 					break;
   200 					result = EPass;
   238 				case EEirTagManufacturerSpecific:
   201 					}
   239 					/** To do this you must have write device data **/
   202 				break;
   240 					if(KVendorSpecificDataSecurityPolicy.CheckPolicy(aMsg))
   203 			
   241 						{
   204 			case EEirTagFlags:
   242 						result = EPass;
   205 				/** At present no implementation of Flags is supported. 
   243 						}
   206 				    So we are rejecting this until an implementation is provided. **/
   244 					break;
   207 			default: //unknown or reserved tag, reject
   245 				case EEirTagFlags:
   208 				//no need to do anything 
   246 					/** At present no implementation of Flags is supported. 
   209 				break;
   247 					So we are rejecting this until an implementation is provided. **/
       
   248 				default: //unknown or reserved tag, reject
       
   249 					//no need to do anything 
       
   250 					break;
       
   251 				}
   210 			}
   252 			}
   211 		}
   253 		}
   212 	//Anything not covered by the above is invalid so do nothing and let it fail
   254 	//Anything not covered by the above is invalid so do nothing and let it fail
   213 	if(result == EFail)
   255 	if(result == EFail)
   214 		{
   256 		{