bluetooth/btstack/l2cap/l2capSigStates.cpp
branchRCL_3
changeset 25 99439b07e980
parent 24 e9b924a62a66
equal deleted inserted replaced
24:e9b924a62a66 25:99439b07e980
   284 
   284 
   285 void TL2CAPSigStateClosed::OpenChannel(CL2CapSAPSignalHandler& aSignalHandler) const
   285 void TL2CAPSigStateClosed::OpenChannel(CL2CapSAPSignalHandler& aSignalHandler) const
   286 	{
   286 	{
   287 	LOG_FUNC
   287 	LOG_FUNC
   288 	// The SAP has requested a channel be opened.
   288 	// The SAP has requested a channel be opened.
       
   289 	// Override all LPMs to try and avoid signalling timeouts
       
   290 	aSignalHandler.OverrideLPM();
   289 
   291 
   290 	TInt err = aSignalHandler.ChannelConfig().UpdateLocalConfigWithEntityCapabilities();
   292 	TInt err = aSignalHandler.ChannelConfig().UpdateLocalConfigWithEntityCapabilities();
   291 	if (err == KErrNone)
   293 	if (err == KErrNone)
   292 		{
   294 		{
   293 		// Get a free source CID for this channel to use.
   295 		// Get a free source CID for this channel to use.
   296 		if(err == KErrNone)
   298 		if(err == KErrNone)
   297 			{
   299 			{
   298 			// Update local Port.
   300 			// Update local Port.
   299 			aSignalHandler.SetLocalPort(port);
   301 			aSignalHandler.SetLocalPort(port);
   300 	
   302 	
   301 			// Override park to allow the connection to be made.
       
   302 			aSignalHandler.OverrideParkMode();
       
   303 	
       
   304 			// Active connection.  Send a Connect Request command.
   303 			// Active connection.  Send a Connect Request command.
   305 			err = aSignalHandler.ConstructConnectionRequest();
   304 			err = aSignalHandler.ConstructConnectionRequest();
   306 			if(err == KErrNone)
   305 			if(err == KErrNone)
   307 				{
   306 				{
   308 				aSignalHandler.SetState(iFactory.GetState(CL2CAPSignalStateFactory::EWaitConnectRsp));
   307 				aSignalHandler.SetState(iFactory.GetState(CL2CAPSignalStateFactory::EWaitConnectRsp));
   328 	if(err == KErrNone)
   327 	if(err == KErrNone)
   329 		{
   328 		{
   330 		// Update local Port.
   329 		// Update local Port.
   331 		aSignalHandler.SetLocalPort(port);
   330 		aSignalHandler.SetLocalPort(port);
   332 
   331 
   333 		// Override park to allow the connection to be made.
   332 		// Override all LPMs to try and avoid signalling timeouts
   334 		aSignalHandler.OverrideParkMode();
   333 		aSignalHandler.OverrideLPM();
   335 		// Override all LPMs (if timeout not set to zero)
       
   336 		aSignalHandler.OverrideLPMWithTimeout();
       
   337 
   334 
   338 		// Send a response with a 'pending' result and start security procedure.
   335 		// Send a response with a 'pending' result and start security procedure.
   339 		err = aSignalHandler.ConstructConnectionResponse(aSignalHandler.GetOutstandingRequestID(),
   336 		err = aSignalHandler.ConstructConnectionResponse(aSignalHandler.GetOutstandingRequestID(),
   340 	                                                     EConnectPending,
   337 	                                                     EConnectPending,
   341 		                                                 EConnectPendAuthorization);
   338 		                                                 EConnectPendAuthorization);
   382 	// Cancel the configuration timer.
   379 	// Cancel the configuration timer.
   383 	aSignalHandler.CancelTimer();
   380 	aSignalHandler.CancelTimer();
   384 
   381 
   385 	aSignalHandler.iOpenChannelRequestAwaitingPeerEntityConfig = EFalse;
   382 	aSignalHandler.iOpenChannelRequestAwaitingPeerEntityConfig = EFalse;
   386 
   383 
   387 	// If Park mode has been overridden during either channel establishment or
   384 	// Depending where we came from we may have applied either a
   388 	// channel disconnect, remove the override.
   385 	// park override or an all LPM override.  We remove both these
   389 	// NB It is safe to call this method multiple times.
   386 	// overrides because it's safe to remove an override that 
       
   387 	// hasn't been applied.
       
   388 	// Note that although park is one of the LPMs the different
       
   389 	// levels of override are managed separately, so an
       
   390 	// UndoOverrideLPM does not remove an explicit park only 
       
   391 	// override.
   390 	aSignalHandler.UndoOverrideParkMode();
   392 	aSignalHandler.UndoOverrideParkMode();
       
   393 	aSignalHandler.UndoOverrideLPM();
   391 
   394 
   392 	// If the signal handler has left the closed state, it will have been added
   395 	// If the signal handler has left the closed state, it will have been added
   393 	// to the SH list in the Muxer.  Now that the closed state is being
   396 	// to the SH list in the Muxer.  Now that the closed state is being
   394 	// re-entered, remove the handler from the Muxer queue.
   397 	// re-entered, remove the handler from the Muxer queue.
   395 	// NB It is safe to call this method multiple times.
   398 	// NB It is safe to call this method multiple times.
  1089 		aSignalHandler.SetState(iFactory.GetState(CL2CAPSignalStateFactory::EWaitConfig));
  1092 		aSignalHandler.SetState(iFactory.GetState(CL2CAPSignalStateFactory::EWaitConfig));
  1090 		aSignalHandler.ConfigureChannel();
  1093 		aSignalHandler.ConfigureChannel();
  1091 		}
  1094 		}
  1092 	else
  1095 	else
  1093 		{
  1096 		{
  1094 		// Remove and park override.
  1097 		// Depending where we came from we may have applied either a
       
  1098 		// park override or an all LPM override.  We remove both these
       
  1099 		// overrides because it's safe to remove an override that 
       
  1100 		// hasn't been applied.
       
  1101 		// Note that although park is one of the LPMs the different
       
  1102 		// levels of override are managed separately, so an
       
  1103 		// UndoOverrideLPM does not remove an explicit park only 
       
  1104 		// override.
  1095 		aSignalHandler.UndoOverrideParkMode();
  1105 		aSignalHandler.UndoOverrideParkMode();
       
  1106 		aSignalHandler.UndoOverrideLPM();
  1096 
  1107 
  1097 		// Cancel the configuration timer.
  1108 		// Cancel the configuration timer.
  1098 		aSignalHandler.CancelTimer();
  1109 		aSignalHandler.CancelTimer();
  1099 
  1110 
  1100 		// Inform the SAP that the channel is now configured and ready to use.
  1111 		// Inform the SAP that the channel is now configured and ready to use.
  1147 	}
  1158 	}
  1148 	
  1159 	
  1149 void TL2CAPSigStateWaitDisconnect::DisconnectResponse(CL2CapSAPSignalHandler& aSignalHandler) const
  1160 void TL2CAPSigStateWaitDisconnect::DisconnectResponse(CL2CapSAPSignalHandler& aSignalHandler) const
  1150 	{
  1161 	{
  1151 	LOG_FUNC
  1162 	LOG_FUNC
  1152 	aSignalHandler.DrainPendingCommands();
  1163 	// We've got a disconnect response, we're done.  Any remaing stuff on the queue
  1153 	}
  1164 	// is redundant, so ditch it and close synchronously.
  1154 
  1165 	aSignalHandler.FlushAllQueues();
  1155 // "Artificial" state events
  1166 	
  1156 void TL2CAPSigStateWaitDisconnect::PendingCommandsDrained(CL2CapSAPSignalHandler& aSignalHandler) const
       
  1157 	{
       
  1158 	LOG_FUNC
       
  1159 	// If an error condition has been recorded forward the error 
  1167 	// If an error condition has been recorded forward the error 
  1160 	// to the SAP.
  1168 	// to the SAP.
  1161 	if(aSignalHandler.SignalHandlerErrorCode() != KErrNone)
  1169 	if(aSignalHandler.SignalHandlerErrorCode() != KErrNone)
  1162 		{
  1170 		{
  1163 		Error(aSignalHandler, aSignalHandler.SignalHandlerErrorCode(), aSignalHandler.SignalHandlerErrorAction());
  1171 		Error(aSignalHandler, aSignalHandler.SignalHandlerErrorCode(), aSignalHandler.SignalHandlerErrorAction());
  1166 		{
  1174 		{
  1167 		// This will delete the signal handler if the SAP has detached.
  1175 		// This will delete the signal handler if the SAP has detached.
  1168 		aSignalHandler.SetState(iFactory.GetState(CL2CAPSignalStateFactory::EClosed));
  1176 		aSignalHandler.SetState(iFactory.GetState(CL2CAPSignalStateFactory::EClosed));
  1169 		aSignalHandler.SignalHandlerDisconnectedCanClose();
  1177 		aSignalHandler.SignalHandlerDisconnectedCanClose();
  1170 		}
  1178 		}
       
  1179 
       
  1180 	}
       
  1181 
       
  1182 // "Artificial" state events
       
  1183 void TL2CAPSigStateWaitDisconnect::PendingCommandsDrained(CL2CapSAPSignalHandler& aSignalHandler) const
       
  1184 	{
       
  1185 	LOG_FUNC
       
  1186 	// If an error condition has been recorded forward the error 
       
  1187 	// to the SAP.
       
  1188 	if(aSignalHandler.SignalHandlerErrorCode() != KErrNone)
       
  1189 		{
       
  1190 		Error(aSignalHandler, aSignalHandler.SignalHandlerErrorCode(), aSignalHandler.SignalHandlerErrorAction());
       
  1191 		}
       
  1192 	else
       
  1193 		{
       
  1194 		// This will delete the signal handler if the SAP has detached.
       
  1195 		aSignalHandler.SetState(iFactory.GetState(CL2CAPSignalStateFactory::EClosed));
       
  1196 		aSignalHandler.SignalHandlerDisconnectedCanClose();
       
  1197 		}
  1171 	}
  1198 	}
  1172 		
  1199 		
  1173 void TL2CAPSigStateWaitDisconnect::Enter(CL2CapSAPSignalHandler& aSignalHandler) const
  1200 void TL2CAPSigStateWaitDisconnect::Enter(CL2CapSAPSignalHandler& aSignalHandler) const
  1174 	{
  1201 	{
  1175 	LOG_FUNC
  1202 	LOG_FUNC
  1176 	// Override park to allow the disconnect to continue.
  1203 	// Only override park for disconnect.  We need to be able
       
  1204 	// to send the signalling, but we don't care if it takes
       
  1205 	// ages.  No point starting a sniff bun-fight.
  1177 	aSignalHandler.OverrideParkMode();
  1206 	aSignalHandler.OverrideParkMode();
  1178 
  1207 
  1179 	// Cancel the configuration timer.
  1208 	// Cancel the configuration timer.
  1180 	aSignalHandler.CancelTimer();
  1209 	aSignalHandler.CancelTimer();
  1181 	}
  1210 	}