Revision: 201011 RCL_3 PDK_3.0.i
authorDremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
Tue, 27 Apr 2010 17:48:21 +0300
branchRCL_3
changeset 14 f8503e232b0c
parent 13 16aa830c86c8
child 16 9f17f914e828
Revision: 201011 Kit: 201017
bluetooth/btstack/linkmgr/ProxySAP.cpp
bluetooth/btstack/linkmgr/linkutil.h
bluetooth/btstack/linkmgr/physicallinks.cpp
bluetooth/btstack/linkmgr/physicallinksmanager.cpp
bluetooth/btstack/linkmgr/physicallinksmanager.h
bluetooth/btstack/secman/btaccessrequester.cpp
bluetoothmgmt/bluetoothclientlib/btlib/btbaseband.cpp
bluetoothmgmt/bluetoothclientlib/btlib/btphysicallinks.cpp
bluetoothmgmt/bluetoothclientlib/btlib/btphysicallinkshelpers.h
bluetoothmgmt/bluetoothclientlib/bwins/BLUETOOTHU.DEF
bluetoothmgmt/bluetoothclientlib/eabi/bluetoothU.def
bluetoothmgmt/bluetoothclientlib/inc/bt_sock.h
bluetoothmgmt/bluetoothclientlib/inc/btbaseband.h
bluetoothmgmt/btmgr/BTManServer/btmanserverburmgr.cpp
bluetoothmgmt/btmgr/BTManServer/btmanserverburmgr.h
bthci/bthci2/CommandsEvents/generator/Commands.txt
bthci/hci2implementations/CommandsEvents/symbian/src/disconnectcommand.cpp
--- a/bluetooth/btstack/linkmgr/ProxySAP.cpp	Wed Apr 14 17:08:52 2010 +0300
+++ b/bluetooth/btstack/linkmgr/ProxySAP.cpp	Tue Apr 27 17:48:21 2010 +0300
@@ -766,12 +766,12 @@
 			return;
 			}										
 
-		if (aDisconnectOption == KDisconnectAllPhysicalLinks)
+		if (aDisconnectOption == KDisconnectAllPhysicalLinks || aDisconnectOption == KDisconnectAllPhysicalLinksForPowerOff)
 			{
 			// Disconnecting All BT Physical Links
 			// Only support link *termination*, this is done as normal cos esock weirdness
 			__ASSERT_ALWAYS(aCloseType == CServProviderBase::ENormal, Panic(EBTProxySAPInvalidTerminate));
-			rerr = iLinksMan.TerminateAllPhysicalLinks(this);
+			rerr = iLinksMan.TerminateAllPhysicalLinks(this, aDisconnectOption == KDisconnectAllPhysicalLinksForPowerOff ? ERemoteAboutToPowerOff : ERemoteUserEndedConnection);
 			LOG2(_L("Proxy SAP 0x%08x -- Terminating all PHY Links, error: %d"), this, rerr);
 			
 			// If there was an error terminating any of the physical links then we can 
--- a/bluetooth/btstack/linkmgr/linkutil.h	Wed Apr 14 17:08:52 2010 +0300
+++ b/bluetooth/btstack/linkmgr/linkutil.h	Tue Apr 27 17:48:21 2010 +0300
@@ -185,6 +185,7 @@
 	EBTSSPModeChangedDuringConnection		=209,
 	EHCICtrlrInitAddingInitialisationCommandInBadState	=210,
 	EHCICtrlrInitOnlyOneResetCmdAllowed		=211,
+	EInvalidDisconnectReason				=212,
 
 	//Please add new panic codes common to all versions of linkmgr here.
 	EVendorSAPBadVendorEvent				=250,
--- a/bluetooth/btstack/linkmgr/physicallinks.cpp	Wed Apr 14 17:08:52 2010 +0300
+++ b/bluetooth/btstack/linkmgr/physicallinks.cpp	Tue Apr 27 17:48:21 2010 +0300
@@ -1,4 +1,4 @@
-// Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
+// Copyright (c) 2006-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"
@@ -2821,11 +2821,12 @@
 		}
 
 	TBTPinCode pinCode;
-	if(iLinksMan.PrefetchMan().IsPrefetchAvailable(aAddr, pinCode))
-		{
-		aRequester.PINCodeRequestReply(aAddr, pinCode);
-		return;
-		}
+	if(iLinksMan.PrefetchMan().GetPrefetch(aAddr, pinCode))
+	    {
+        iLinksMan.PrefetchMan().RemovePrefetch(aAddr);
+        aRequester.PINCodeRequestReply(aAddr, pinCode);
+        return;
+	    }
 
 	iPinHandler = &aRequester;
 
--- a/bluetooth/btstack/linkmgr/physicallinksmanager.cpp	Wed Apr 14 17:08:52 2010 +0300
+++ b/bluetooth/btstack/linkmgr/physicallinksmanager.cpp	Tue Apr 27 17:48:21 2010 +0300
@@ -316,7 +316,7 @@
 	iTerminatingProxy=aProxySAP;
 	}
 	
-TInt CPhysicalLinksManager::TerminateAllPhysicalLinks(CBTProxySAP* aProxySAP)
+TInt CPhysicalLinksManager::TerminateAllPhysicalLinks(CBTProxySAP* aProxySAP, THCIErrorCode aErrorCode)
 	{
 	TInt count=iPhysicalLinks.Count();
 	TInt retVal = (count==0) ? KErrNotFound : KErrNone;
@@ -325,7 +325,7 @@
 		{
 		// If any one of the physical links return an error then this 
 		// function needs to return an error.
-		TInt err = iPhysicalLinks[i]->Terminate(ERemoteUserEndedConnection);
+		TInt err = iPhysicalLinks[i]->Terminate(aErrorCode);
 		if (err != KErrNone)
 			{
 			retVal=err;
@@ -1309,16 +1309,30 @@
 	return KErrNone;
 	}
 
-TBool CBluetoothPrefetchManager::IsPrefetchAvailable(const TBTDevAddr& aAddr, TBTPinCode& aPinCode)
+
+TInt CBluetoothPrefetchManager::IsPrefetchAvailable(const TBTDevAddr& aAddr) const
+    {
+    return iPrefetchedPins.Find(aAddr, CompareAddressInStore);
+    }
+
+TBool CBluetoothPrefetchManager::GetPrefetch(const TBTDevAddr& aAddr, TBTPinCode& aPinCode) const
+    {
+    TInt ix = IsPrefetchAvailable(aAddr);
+    if (ix >= 0)
+        {
+        aPinCode.Copy(iPrefetchedPins[ix].iPin);
+        return ETrue;
+        }
+    return EFalse;
+    }
+
+void CBluetoothPrefetchManager::RemovePrefetch(const TBTDevAddr& aAddr)
 	{
-	TInt ix = iPrefetchedPins.Find(aAddr, CompareAddressInStore);
-	if (ix < 0)
+	TInt ix = IsPrefetchAvailable(aAddr);
+	if (ix >= 0)
 		{
-		return EFalse;
+        iPrefetchedPins.Remove(ix);
 		}
-	aPinCode.Copy(iPrefetchedPins[ix].iPin);
-	iPrefetchedPins.Remove(ix);
-	return ETrue;
 	}
 
 TInt CBluetoothPrefetchManager::PINCodeRequestReply(const TBTDevAddr& aDevAddr, const TDesC8& aPin) const
--- a/bluetooth/btstack/linkmgr/physicallinksmanager.h	Wed Apr 14 17:08:52 2010 +0300
+++ b/bluetooth/btstack/linkmgr/physicallinksmanager.h	Tue Apr 27 17:48:21 2010 +0300
@@ -75,7 +75,8 @@
 	TInt HandleOverPinRequester(const TBTDevAddr& aAddr, CBTPinRequester* aPinRequester);
 	TInt RegisterForPrefetching(const TBTDevAddr& aAddr, MBluetoothPrefetchNotifier& aNotifier);
 
-	TBool IsPrefetchAvailable(const TBTDevAddr& aAddr, TBTPinCode& aPinCode);
+	TBool GetPrefetch(const TBTDevAddr& aAddr, TBTPinCode& aPinCode) const;
+	void RemovePrefetch(const TBTDevAddr& aAddr);
 
 private:
 	NONSHARABLE_CLASS(RPinRequest)
@@ -105,6 +106,8 @@
 
 	static TBool CompareAddressInRequest(const TBTDevAddr* aDevAddr, const RPinRequest& aRequest);
 	static TBool CompareAddressInStore(const TBTDevAddr* aDevAddr, const TPrefetchedPin& aRequest);
+	
+	TInt IsPrefetchAvailable(const TBTDevAddr& aAddr) const;
 
 private: // from MPINCodeResponseHandler
 	TInt PINCodeRequestReply(const TBTDevAddr& aDevAddr, const TDesC8& aPin) const;
@@ -144,7 +147,7 @@
 	TInt AddListener(MLogicalLink& aLogicalLink, TPhysicalLinkPort aPort);
 	void RemoveListener(MLogicalLink& aLogicalLink);
 	void ClearTerminatingProxy(CBTProxySAP* aProxySAP);
-	TInt TerminateAllPhysicalLinks(CBTProxySAP* aProxySAP);
+	TInt TerminateAllPhysicalLinks(CBTProxySAP* aProxySAP, THCIErrorCode aErrorCode);
 	TInt TerminatePhysicalLink(CPhysicalLink* aConnection, CBTProxySAP* aProxySAP);
 
 	void FatalError(TInt aErr);
--- a/bluetooth/btstack/secman/btaccessrequester.cpp	Wed Apr 14 17:08:52 2010 +0300
+++ b/bluetooth/btstack/secman/btaccessrequester.cpp	Tue Apr 27 17:48:21 2010 +0300
@@ -1,4 +1,4 @@
-// Copyright (c) 1999-2009 Nokia Corporation and/or its subsidiary(-ies).
+// Copyright (c) 1999-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"
@@ -831,6 +831,7 @@
 	else if((aEvent.EventType() == ENotifyPhysicalLinkError))
 		{
 		LOG(_L8("\tPhysical link error...Complete(ACCESS DENIED)"));
+		iSecMan.ConnectionsManager().PrefetchMan().RemovePrefetch(DeviceAddress());		
 		LinkError(aEvent.ErrorCode());
 		}
 	}
--- a/bluetoothmgmt/bluetoothclientlib/btlib/btbaseband.cpp	Wed Apr 14 17:08:52 2010 +0300
+++ b/bluetoothmgmt/bluetoothclientlib/btlib/btbaseband.cpp	Tue Apr 27 17:48:21 2010 +0300
@@ -529,14 +529,7 @@
 		}	
 	}
 
-void RBTBaseband::TerminateAllPhysicalLinks(TInt aReason)
-	{
-	TRequestStatus stat;
-	TerminateAllPhysicalLinks(aReason, stat);
-	User::WaitForRequest(stat);
-	}
-
-void RBTBaseband::TerminateAllPhysicalLinks(TInt /*aReason*/, TRequestStatus& aStatus)
+void RBTBaseband::TerminateAllPhysicalLinks(TRequestStatus& aStatus)
 	{
 	if (!SubSessionHandle())
 		{
@@ -549,6 +542,20 @@
 		}
 	}
 
+void RBTBaseband::TerminateAllPhysicalLinksForPowerOff(TRequestStatus& aStatus)
+	{
+	if (!SubSessionHandle())
+		{
+		LocalComplete(aStatus, KErrNotReady);
+		}
+	else
+		{
+		TBuf8<1> dummy;
+		iSocket.Shutdown(RSocket::ENormal, KDisconnectAllPhysicalLinksForPowerOff, dummy, aStatus); // this *means* detach now
+		}
+	}
+
+
 TInt RBTBaseband::Enumerate(RBTDevAddrArray& aBTDevAddrArray, TUint aMaxNumber)
 	{
 	if (!SubSessionHandle())
--- a/bluetoothmgmt/bluetoothclientlib/btlib/btphysicallinks.cpp	Wed Apr 14 17:08:52 2010 +0300
+++ b/bluetoothmgmt/bluetoothclientlib/btlib/btphysicallinks.cpp	Tue Apr 27 17:48:21 2010 +0300
@@ -164,7 +164,7 @@
 	}
 
 EXPORT_C TInt CBluetoothPhysicalLinks::DisconnectAll()
-/** Disconnect all members of piconet
+/** Disconnect all members of piconet with the reason code "Remote User Terminated Connection"
 @return Error code
 @capability NetworkControl
 */
@@ -176,10 +176,10 @@
 
 	//Allow ESock to do multiple disconnects	
 	BTBaseband().Close(); 
-	TInt ESockErr = BTBaseband().Open(SockServer());
-	if(ESockErr != KErrNone)
+	TInt openErr = BTBaseband().Open(SockServer());
+	if(openErr != KErrNone)
 		{
-		return ESockErr;
+		return openErr;
 		}
 		
 	TRAPD(err, iBTDisconnector = CBTDisconnector::NewL(*this));
@@ -190,6 +190,33 @@
 	return err;
 	}
 
+EXPORT_C TInt CBluetoothPhysicalLinks::DisconnectAllForPowerOff()
+/** Disconnect all members of piconet with the reason code "Remote Device Terminated Connection due to Power Off"
+@return Error code
+@capability NetworkControl
+*/
+	{
+	if(iBTDisconnector)
+		{
+		return KErrInUse;
+		}
+
+	//Allow ESock to do multiple disconnects	
+	BTBaseband().Close(); 
+	TInt openErr = BTBaseband().Open(SockServer());
+	if(openErr != KErrNone)
+		{
+		return openErr;
+		}
+		
+	TRAPD(err, iBTDisconnector = CBTDisconnector::NewL(*this));
+	if(err == KErrNone)
+		{
+		iBTDisconnector->DisconnectAllForPowerOff();
+		}
+	return err;
+	}
+
 EXPORT_C TInt CBluetoothPhysicalLinks::Broadcast(const TDesC8& aData)
 /** Write (raw) broadcast data
 
@@ -417,11 +444,22 @@
 	{
 	__ASSERT_ALWAYS(!IsActive(), Panic(EUnfinishedBusiness));
 
-	iParent.BTBaseband().TerminateAllPhysicalLinks(0, iStatus);
+	iParent.BTBaseband().TerminateAllPhysicalLinks(iStatus);
 	iCurrentRequest = EDisconnectAll;
 	SetActive();
 	}
 
+void CBTDisconnector::DisconnectAllForPowerOff()
+
+	{
+	__ASSERT_ALWAYS(!IsActive(), Panic(EUnfinishedBusiness));
+
+	iParent.BTBaseband().TerminateAllPhysicalLinksForPowerOff(iStatus);
+	iCurrentRequest = EDisconnectAll;
+	SetActive();
+	}
+
+
 void CBTDisconnector::RunL()
 //
 //When logical socket has connected (only async bit), 
--- a/bluetoothmgmt/bluetoothclientlib/btlib/btphysicallinkshelpers.h	Wed Apr 14 17:08:52 2010 +0300
+++ b/bluetoothmgmt/bluetoothclientlib/btlib/btphysicallinkshelpers.h	Tue Apr 27 17:48:21 2010 +0300
@@ -49,6 +49,7 @@
 	static CBTDisconnector* NewL(CBluetoothPhysicalLinks& aParent);
 	void Disconnect(const TBTDevAddr& aBDAddr);
 	void DisconnectAll();
+	void DisconnectAllForPowerOff();
 	~CBTDisconnector();
 
 
--- a/bluetoothmgmt/bluetoothclientlib/bwins/BLUETOOTHU.DEF	Wed Apr 14 17:08:52 2010 +0300
+++ b/bluetoothmgmt/bluetoothclientlib/bwins/BLUETOOTHU.DEF	Tue Apr 27 17:48:21 2010 +0300
@@ -354,4 +354,5 @@
 	?SetMinMRU@TL2CapConfig@@QAEHG@Z @ 353 NONAME ; int TL2CapConfig::SetMinMRU(unsigned short)
 	?RetransmissionTimer@TL2CapConfig@@QBEGAAH@Z @ 354 NONAME ; unsigned short TL2CapConfig::RetransmissionTimer(int &) const
 	?MinMRU@TL2CapConfig@@QBEGAAH@Z @ 355 NONAME ; unsigned short TL2CapConfig::MinMRU(int &) const
+	?DisconnectAllForPowerOff@CBluetoothPhysicalLinks@@QAEHXZ @ 356 NONAME ; int CBluetoothPhysicalLinks::DisconnectAllForPowerOff(void)
 
--- a/bluetoothmgmt/bluetoothclientlib/eabi/bluetoothU.def	Wed Apr 14 17:08:52 2010 +0300
+++ b/bluetoothmgmt/bluetoothclientlib/eabi/bluetoothU.def	Tue Apr 27 17:48:21 2010 +0300
@@ -408,4 +408,5 @@
 	_ZNK12TL2CapConfig21LegacyModesDisallowedEv @ 407 NONAME
 	_ZNK12TL2CapConfig6MinMRUERi @ 408 NONAME
 	_ZNK12TL2CapConfig6MinMTUERi @ 409 NONAME
+	_ZN23CBluetoothPhysicalLinks24DisconnectAllForPowerOffEv @ 410 NONAME
 
--- a/bluetoothmgmt/bluetoothclientlib/inc/bt_sock.h	Wed Apr 14 17:08:52 2010 +0300
+++ b/bluetoothmgmt/bluetoothclientlib/inc/bt_sock.h	Tue Apr 27 17:48:21 2010 +0300
@@ -191,6 +191,7 @@
 // private tokens for use by RBTBaseband facade and stack
 _LIT8(KDisconnectOnePhysicalLink, "1");		/*!< Specifes one physical link should be disconnected */
 _LIT8(KDisconnectAllPhysicalLinks, "A");	/*!< Specifes all physical links should be disconnected */
+_LIT8(KDisconnectAllPhysicalLinksForPowerOff, "P");	/*!< Specifes all physical links should be disconnected for power off*/
 
 // HCI Ioctls
 /** Add SCO connnection Ioctl
@@ -1533,6 +1534,7 @@
 	IMPORT_C void CancelCreateConnection();
 	IMPORT_C TInt Disconnect(const TBTDevAddr& aDevAddr);
 	IMPORT_C TInt DisconnectAll();
+	IMPORT_C TInt DisconnectAllForPowerOff();
 	
 	IMPORT_C TInt Broadcast(const TDesC8& aData);
 	IMPORT_C TInt ReadRaw(TDes8& aData);
--- a/bluetoothmgmt/bluetoothclientlib/inc/btbaseband.h	Wed Apr 14 17:08:52 2010 +0300
+++ b/bluetoothmgmt/bluetoothclientlib/inc/btbaseband.h	Tue Apr 27 17:48:21 2010 +0300
@@ -87,10 +87,10 @@
 	void TerminatePhysicalLink(TInt aReason, TRequestStatus& aStatus);
 	void TerminatePhysicalLink(TInt aReason, const TBTDevAddr& aDevAddr, TRequestStatus& aStatus);
 	void ShutdownPhysicalLink(TRequestStatus& aStatus);
-	void TerminateAllPhysicalLinks(TInt aReason);
-	void TerminateAllPhysicalLinks(TInt aReason, TRequestStatus& aStatus);
+	void TerminateAllPhysicalLinks(TRequestStatus& aStatus);
+	void TerminateAllPhysicalLinksForPowerOff(TRequestStatus& aStatus);
 	TInt SubSessionHandle() const;
-	
+
 private:
 	TInt RequestRole(TBTLMOptions aRole);
 	void LocalComplete(TRequestStatus& aStatus, TInt aErr);
--- a/bluetoothmgmt/btmgr/BTManServer/btmanserverburmgr.cpp	Wed Apr 14 17:08:52 2010 +0300
+++ b/bluetoothmgmt/btmgr/BTManServer/btmanserverburmgr.cpp	Tue Apr 27 17:48:21 2010 +0300
@@ -306,9 +306,9 @@
 
 /**
 Receives notification that a restore file has been provided by the Secure Backup Engine.
-Upon receiving this notification, the restore file is renamed to have the appropriate extension and 
-the local device name is updated in the registry. The restore of the remote devices table is postponed
-until the next time BTManServer starts, so any ongoing BT connections are not affected.
+Upon receiving this notification, the restore file is renamed to have the appropriate extension 
+The actual restore to the registry is postponed until the next time BTManServer starts, 
+so any ongoing BT connections are not affected.
 **/
 void CBTManServerBURMgr::RestoreFileReady()
 	{
@@ -317,8 +317,6 @@
 
 	// Rename restore file
 	RenameBackupFileForRestore();
-	// Attempt to update local device name in the registry (best efforts only)
-	TRAP_IGNORE(UpdateLocalDeviceNameL());
 	}
 
 void CBTManServerBURMgr::HandleStateNormal()
@@ -524,7 +522,7 @@
 
 	// Start restore file processing
 	iRestoreHandler = CBTRestoreHandler::NewL(*this, iBTManServer);
-	iRestoreHandler->RestoreRemoteDeviceTableL(iLocalAddr);
+	iRestoreHandler->RestoreRegistryL(iLocalAddr);
 
 	iStateMachine->TransitionState(EBTBUREventProcessRestoreFileComplete);
 	}
@@ -710,24 +708,6 @@
 		}
 	}
 
-/**
-Parses the restore file and updates the loal device name in the registry.
-This update takes place as soon as the restore file is available, regardless of whether or not the local device
-address matches that held in the registry. If the local device name has already been set to a non-default value,
-then it is not modified.
-**/
-void CBTManServerBURMgr::UpdateLocalDeviceNameL()
-	{
-	LOG_FUNC
-		
-	CBTRestoreHandler* restoreHandler = CBTRestoreHandler::NewL(*this, iBTManServer);
-	CleanupStack::PushL(restoreHandler);
-
-	restoreHandler->RestoreLocalDeviceNameL();
-
-	CleanupStack::PopAndDestroy(restoreHandler);
-	}
-
 void CBTManServerBURMgr::RunL()
 	{
 	LOG_FUNC
@@ -865,22 +845,7 @@
 	delete iRegistryData;
 	}
 
-void CBTRestoreHandler::RestoreLocalDeviceNameL()
-	{
-	LOG_FUNC
-
-	LoadRestoreDataL();
-
-	// If the local device name is still default, restore without validating the local address
-	// (otherwise we will not be able to restore this field before the next stack start, which may cause problems with some UIs)
-	CBTRegistry& registry = iManServer.Registry();
-	if (iRegistryData->WriteLocalDeviceNameToRegistryL(registry))
-		{
-		NotifyLocalTableChange();
-		}
-	}
-
-void CBTRestoreHandler::RestoreRemoteDeviceTableL(TBTDevAddr& aLocalAddr)
+void CBTRestoreHandler::RestoreRegistryL(TBTDevAddr& aLocalAddr)
 	{
 	LOG_FUNC
 	__ASSERT_DEBUG(aLocalAddr != TBTDevAddr(), PANIC(KBTBackupPanicCat, EBTBURMgrMissingLocalAddress));
@@ -890,9 +855,15 @@
 	// Compare local address held in restore file with our local address
 	if (iRegistryData->IsLocalAddressEqualL(aLocalAddr))
 		{
-    		// Proceed with restore of remote devices table
+		// Proceed with restore
 		CBTRegistry& registry = iManServer.Registry();
 
+		if (iRegistryData->WriteLocalDeviceNameToRegistryL(registry))
+			{
+			NotifyLocalTableChange();
+			NotifyLocalDeviceNameChange(iRegistryData->GetLocalDeviceNameL());
+			}
+
 		TInt noRemoteDevices = iRegistryData->CountRemoteDevicesL();
 		for (TInt i = 0; i < noRemoteDevices; i++)
 			{
@@ -939,6 +910,39 @@
 	}
 
 /**
+Sends a notification that the local device name has been changed.
+This notification is observable through the P&S key KPRopertyKeyBluetoothSetDeviceName.
+@param aLocalName The modified local device name as an 8-bit descriptor.
+**/
+void CBTRestoreHandler::NotifyLocalDeviceNameChange(const TDesC8& aLocalName)
+	{
+	LOG_FUNC
+	
+	// The P&S key requires the local device name in unicode format.
+	TBuf16<KMaxBluetoothNameLen> localNameUniCode;
+	localNameUniCode.Copy(aLocalName);
+	
+	NotifyLocalDeviceNameChange(localNameUniCode);
+	}
+
+/**
+Sends a notification that the local device name has been changed.
+This notification is observable through the P&S key KPRopertyKeyBluetoothSetDeviceName.
+@param aLocalName The modified local device name in unicode format.
+**/
+void CBTRestoreHandler::NotifyLocalDeviceNameChange(const TDesC16& aLocalName)
+	{
+	LOG_FUNC
+	
+	// The KPropertyKeyBluetoothSetDeviceName P&S key may or may not exist at this point.
+	TInt err = RProperty::Set( KPropertyUidBluetoothCategory, KPropertyKeyBluetoothSetDeviceName, aLocalName);
+	if (err != KErrNone && err != KErrNotFound)
+		{
+		LOG1(_L("CBTRegistryBURData::NotifyLocalDeviceNameChange() - RProperty::Set() failed with %d"), err);
+		}
+	}
+
+/**
 Sends a notification that a device in the remote devices table has been changed.
 The notification is observable through the P&S key KPropertyKeyBluetoothGetRegistryTableChange. 
 Interested parties can also use RBTRegistry::NotifyViewChange() to detect if the change affects their view.
@@ -1544,8 +1548,8 @@
 	}
 
 /**
-Updates the persistence table of the registry with local device name held in this instance
-if the registry currently holds a default name.
+Updates the persistence table of the registry with local device name held in this instance.
+The update is only performed if the local name held in this instance differs from that currently held in the registry.
 @param aRegistry The CBTRegistry instance to use for registry access.
 @return ETrue if an update was made to the registry.
 **/
@@ -1554,24 +1558,15 @@
 	LOG_FUNC
 
 	TBool updateDone = EFalse;
-
-	// Update device name only if the registry has a default name 
-	TBTLocalDevice defaultDevice;
-	TRAP_IGNORE(aRegistry.GetDefaultDeviceFromIniL(defaultDevice));
-
-	if (!defaultDevice.IsValidDeviceName())
-		{
-		// Could not obtain a default name - use KDefaultLocalName instead
-		defaultDevice.SetDeviceName(KDefaultLocalName);
-		}
-
+	
 	TBTLocalDevice* localDevice = aRegistry.GetLocalDeviceL();
 	CleanupStack::PushL(localDevice);
 
-	if (localDevice->DeviceName() == defaultDevice.DeviceName())
+	const TDesC8& localName = GetLocalDeviceNameL();
+
+	if (localDevice->DeviceName() != localName)
 		{
-		// Local device name is default, update with restored value.
-		localDevice->SetDeviceName(GetLocalDeviceNameL());
+		localDevice->SetDeviceName(localName);
 		aRegistry.UpdateLocalDeviceL(*localDevice);
 		updateDone = ETrue;
 		}
@@ -1600,7 +1595,7 @@
 	const CBTDevice& nextRemDevice = GetRemoteDeviceL(aDeviceIndex);
 	TSecureId nextRemDeviceSid = GetRemoteDeviceEntrySidL(aDeviceIndex);
 
-	// Try to add device to registry. If this fails with KErrAlreadExists, then update existing device.
+	// Try to add device to registry. If this fails with KErrAlreadyExists, then update existing device.
 	TRAPD(err, aRegistry.CreateDeviceL(nextRemDevice, nextRemDevice.IsValidUiCookie(), nextRemDeviceSid));
 
 	if (err == KErrNone)
--- a/bluetoothmgmt/btmgr/BTManServer/btmanserverburmgr.h	Wed Apr 14 17:08:52 2010 +0300
+++ b/bluetoothmgmt/btmgr/BTManServer/btmanserverburmgr.h	Tue Apr 27 17:48:21 2010 +0300
@@ -157,7 +157,6 @@
 	void DeleteRestoreFile();
 
 	void RenameBackupFileForRestore();
-	void UpdateLocalDeviceNameL();
 
 	// From CActive:
 	void RunL();
@@ -213,8 +212,7 @@
 	static CBTRestoreHandler* NewL(CBTManServerBURMgr& aBURMgr, CBTManServer& aManServer);
 	~CBTRestoreHandler();
 
-	void RestoreLocalDeviceNameL();
-	void RestoreRemoteDeviceTableL(TBTDevAddr& aLocalAddr);
+	void RestoreRegistryL(TBTDevAddr& aLocalAddr);
 
 private:
 	CBTRestoreHandler(CBTManServerBURMgr& aBURMgr, CBTManServer& aManServer);
@@ -223,6 +221,8 @@
 	void LoadRestoreDataL();
 
 	void NotifyLocalTableChange();
+	void NotifyLocalDeviceNameChange(const TDesC8& aLocalName);
+	void NotifyLocalDeviceNameChange(const TDesC16& aLocalName);
 	void NotifyRemoteTableChangeL(const TBTDevAddr& aAddress);
 
 private:
@@ -250,6 +250,7 @@
 	inline TBool HasRegistryData() const;
 
 	void GetRegistryVersionL(TUint32& aRegistryVersionMajor, TUint32& aRegistryVersionMinor) const;
+	const TDesC8& GetLocalDeviceNameL() const;
 	TBool IsLocalAddressNonZeroL() const;
 	TBool IsLocalAddressEqualL(TBTDevAddr& aAddr) const;
 	TInt CountRemoteDevicesL() const;
@@ -262,8 +263,6 @@
 	CBTRegistryBURData();
 	void ConstructL();
 
-	const TDesC8& GetLocalDeviceNameL() const;
-
 private:
 	TBool iHasRegistryData;
 
--- a/bthci/bthci2/CommandsEvents/generator/Commands.txt	Wed Apr 14 17:08:52 2010 +0300
+++ b/bthci/bthci2/CommandsEvents/generator/Commands.txt	Tue Apr 27 17:48:21 2010 +0300
@@ -12,6 +12,7 @@
 #
 # Description:
 #
+
 # Bluetooth HCI Commands to be generated
 # Syntax is documented below. ("[]" brackets are used for grouping with regexp wildcards, and wildcard operators will only directly follow a ']')
 #
@@ -41,7 +42,7 @@
 PeriodicInquiryMode(1,False,True): MaxPeriodLength (2), MinPeriodLength (2), LAP (3), InquiryLength (1), NumResponses (1)
 ExitPeriodicInquiryMode(1,False,True):
 CreateACLConnection(1,True,False,Match,ConnectionCompleteEvent,True,False,BDADDR): BDADDR (6), PacketType (2), PageScanRepetitionMode (1), Reserved (1), ClockOffset (2), AllowRoleSwitch (1)
-Disconnect(1,True,False,Match,DisconnectionCompleteEvent,True,False): ConnectionHandle (2), Reason (1)
+Disconnect(1,True,False,Match,DisconnectionCompleteEvent,True,False,ConnectionHandle): ConnectionHandle (2), Reason (1)
 CreateConnectionCancel(1,False,True): BDADDR (6)
 AcceptConnectionRequest(1,True,False,Match,ConnectionCompleteEvent,True,False,BDADDR): BDADDR (6), Role (1)
 RejectConnectionRequest(1,True,False,Match,ConnectionCompleteEvent,True,False,BDADDR): BDADDR (6), Reason (1)
--- a/bthci/hci2implementations/CommandsEvents/symbian/src/disconnectcommand.cpp	Wed Apr 14 17:08:52 2010 +0300
+++ b/bthci/hci2implementations/CommandsEvents/symbian/src/disconnectcommand.cpp	Tue Apr 27 17:48:21 2010 +0300
@@ -81,9 +81,13 @@
 	{
 	if (aEvent.EventCode() == EDisconnectionCompleteEvent)
 		{
-		aMatchesCmd = ETrue;
-		aConcludesCmd = ETrue;
-		aContinueMatching = EFalse;
+		TDisconnectionCompleteEvent& event = TDisconnectionCompleteEvent::Cast(aEvent);
+		if (event.ConnectionHandle() == ConnectionHandle())
+			{
+			aMatchesCmd = ETrue;
+			aConcludesCmd = ETrue;
+			aContinueMatching = EFalse;
+			}
 		}
 	// Command Status Event and default Command Complete Event matching
 	// is implemented in the base class.  If we haven't matched already