bluetooth/btstack/secman/pairingserver.cpp
changeset 16 0089b2f7ebd8
parent 0 29b1cd4cb562
child 47 a1b8f5cc021e
child 48 22de2e391156
--- a/bluetooth/btstack/secman/pairingserver.cpp	Tue Feb 02 01:12:20 2010 +0200
+++ b/bluetooth/btstack/secman/pairingserver.cpp	Fri Mar 19 09:53:48 2010 +0200
@@ -775,11 +775,18 @@
 	iProxySap = CBTProxySAP::NewL(iPhysicalLinksManager, NULL);
 
 	CleanupStack::Pop(this); // the start message cleaner
-
+	
+	// Now we've entered the realm of not leaving with an error, since the connection
+	// process has started.  Errors from now on must be via the Error() function call.
 	iState = EInitialConnectionPending;
 	iProxySap->SetNotify(this);
 	iProxySap->SetRemName(addr);
 	iProxySap->ActiveOpen();
+	TRAPD(err, DoAccessRequestL());
+	if(err != KErrNone)
+		{
+		Error(err);
+		}
 	}
 
 void CDedicatedBondingSession::CleanupStartMessage(TAny* aPtr)
@@ -815,6 +822,11 @@
 			addr.SetBTAddr(iProxySap->RemoteAddress());
 			iProxySap->SetRemName(addr); // triggers finding a link again.
 			iProxySap->ActiveOpen();
+			TRAPD(err, DoAccessRequestL());
+			if(err != KErrNone)
+				{
+				Error(err);
+				}
 			break;
 			}
 		// else not deferred so complete now....
@@ -830,6 +842,12 @@
 			err = KErrAccessDenied;
 			}
 		break;
+	case EInitialConnectionPending:
+	case EFinalConnectionPending:
+		// Access request shouldn't successfully complete if the connection is still pending
+		__ASSERT_DEBUG(aResult != EBTSecManAccessGranted,  PANIC(KPairingServerFaultCat, EPairingServerUnexpectedAccessCallback));
+		// We should get the MSocketNotify::Error callback, so don't do anything else
+		break;
 	default:
 		LOG1(_L("Unexpected Access Request Complete in state %d"), iState);
 		__ASSERT_DEBUG(EFalse, PANIC(KPairingServerFaultCat, EPairingServerUnexpectedAccessCallback));
@@ -856,23 +874,26 @@
 	__ASSERT_DEBUG(EFalse, PANIC(KPairingServerFaultCat, EPairingServerUnexpectedSocketCallback));
 	}
 
-void CDedicatedBondingSession::ConnectCompleteL()
+void CDedicatedBondingSession::ConnectComplete()
 	{
 	LOG_FUNC
 	switch(iState)
 		{
 	case EInitialConnectionPending:
 		iState = EInitialConnection;
-		DoAccessRequestL();
 		break;
 	case EFinalConnectionPending:
 		iState = EFinalConnection;
-		DoAccessRequestL();
 		break;
 	case EInitialConnection:
 	case EFinalConnection:
 		// Apparently multiple connect completes are allowed by CSocket
 		break;
+	case EShutdown:
+		// If an error occurred just after the connection request then we
+		// might receive a connection complete before the async shutdown request
+		// has been executed.
+		break;
 	default:
 		LOG1(_L("Unexpected Connect Complete in state %d"), iState);
 		__ASSERT_DEBUG(EFalse, PANIC(KPairingServerFaultCat, EPairingServerUnexpectedSocketCallback));
@@ -880,16 +901,6 @@
 		}
 	}
 
-void CDedicatedBondingSession::ConnectComplete()
-	{
-	LOG_FUNC
-	TRAPD(err, ConnectCompleteL());
-	if(err != KErrNone)
-		{
-		Error(err);
-		}
-	}
-
 void CDedicatedBondingSession::ConnectComplete(const TDesC8& /*aConnectData*/)
 	{
 	LOG_FUNC