bluetooth/btstack/l2cap/l2capSigStates.cpp
branchRCL_3
changeset 25 99439b07e980
parent 24 e9b924a62a66
--- a/bluetooth/btstack/l2cap/l2capSigStates.cpp	Wed Sep 01 12:38:54 2010 +0100
+++ b/bluetooth/btstack/l2cap/l2capSigStates.cpp	Tue Sep 14 23:28:24 2010 +0300
@@ -286,6 +286,8 @@
 	{
 	LOG_FUNC
 	// The SAP has requested a channel be opened.
+	// Override all LPMs to try and avoid signalling timeouts
+	aSignalHandler.OverrideLPM();
 
 	TInt err = aSignalHandler.ChannelConfig().UpdateLocalConfigWithEntityCapabilities();
 	if (err == KErrNone)
@@ -298,9 +300,6 @@
 			// Update local Port.
 			aSignalHandler.SetLocalPort(port);
 	
-			// Override park to allow the connection to be made.
-			aSignalHandler.OverrideParkMode();
-	
 			// Active connection.  Send a Connect Request command.
 			err = aSignalHandler.ConstructConnectionRequest();
 			if(err == KErrNone)
@@ -330,10 +329,8 @@
 		// Update local Port.
 		aSignalHandler.SetLocalPort(port);
 
-		// Override park to allow the connection to be made.
-		aSignalHandler.OverrideParkMode();
-		// Override all LPMs (if timeout not set to zero)
-		aSignalHandler.OverrideLPMWithTimeout();
+		// Override all LPMs to try and avoid signalling timeouts
+		aSignalHandler.OverrideLPM();
 
 		// Send a response with a 'pending' result and start security procedure.
 		err = aSignalHandler.ConstructConnectionResponse(aSignalHandler.GetOutstandingRequestID(),
@@ -384,10 +381,16 @@
 
 	aSignalHandler.iOpenChannelRequestAwaitingPeerEntityConfig = EFalse;
 
-	// If Park mode has been overridden during either channel establishment or
-	// channel disconnect, remove the override.
-	// NB It is safe to call this method multiple times.
+	// Depending where we came from we may have applied either a
+	// park override or an all LPM override.  We remove both these
+	// overrides because it's safe to remove an override that 
+	// hasn't been applied.
+	// Note that although park is one of the LPMs the different
+	// levels of override are managed separately, so an
+	// UndoOverrideLPM does not remove an explicit park only 
+	// override.
 	aSignalHandler.UndoOverrideParkMode();
+	aSignalHandler.UndoOverrideLPM();
 
 	// If the signal handler has left the closed state, it will have been added
 	// to the SH list in the Muxer.  Now that the closed state is being
@@ -1091,8 +1094,16 @@
 		}
 	else
 		{
-		// Remove and park override.
+		// Depending where we came from we may have applied either a
+		// park override or an all LPM override.  We remove both these
+		// overrides because it's safe to remove an override that 
+		// hasn't been applied.
+		// Note that although park is one of the LPMs the different
+		// levels of override are managed separately, so an
+		// UndoOverrideLPM does not remove an explicit park only 
+		// override.
 		aSignalHandler.UndoOverrideParkMode();
+		aSignalHandler.UndoOverrideLPM();
 
 		// Cancel the configuration timer.
 		aSignalHandler.CancelTimer();
@@ -1149,7 +1160,23 @@
 void TL2CAPSigStateWaitDisconnect::DisconnectResponse(CL2CapSAPSignalHandler& aSignalHandler) const
 	{
 	LOG_FUNC
-	aSignalHandler.DrainPendingCommands();
+	// We've got a disconnect response, we're done.  Any remaing stuff on the queue
+	// is redundant, so ditch it and close synchronously.
+	aSignalHandler.FlushAllQueues();
+	
+	// If an error condition has been recorded forward the error 
+	// to the SAP.
+	if(aSignalHandler.SignalHandlerErrorCode() != KErrNone)
+		{
+		Error(aSignalHandler, aSignalHandler.SignalHandlerErrorCode(), aSignalHandler.SignalHandlerErrorAction());
+		}
+	else
+		{
+		// This will delete the signal handler if the SAP has detached.
+		aSignalHandler.SetState(iFactory.GetState(CL2CAPSignalStateFactory::EClosed));
+		aSignalHandler.SignalHandlerDisconnectedCanClose();
+		}
+
 	}
 
 // "Artificial" state events
@@ -1173,7 +1200,9 @@
 void TL2CAPSigStateWaitDisconnect::Enter(CL2CapSAPSignalHandler& aSignalHandler) const
 	{
 	LOG_FUNC
-	// Override park to allow the disconnect to continue.
+	// Only override park for disconnect.  We need to be able
+	// to send the signalling, but we don't care if it takes
+	// ages.  No point starting a sniff bun-fight.
 	aSignalHandler.OverrideParkMode();
 
 	// Cancel the configuration timer.