Revision: 201031
authorDremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
Wed, 18 Aug 2010 09:59:05 +0300
changeset 52 4545c04e61e1
parent 41 0b2439c3e397
child 58 683a4424cb9f
child 63 bcf742120177
Revision: 201031 Kit: 201033
bluetoothappprofiles/avrcp/mediabrowseapi/group/bld.inf
bluetoothappprofiles/avrcp/nowplayingapi/group/bld.inf
bluetoothappprofiles/avrcp/remconbeareravrcp/group/remconbeareravrcp.mmp
bluetoothappprofiles/avrcp/remconbeareravrcp/inc/avrcpplayerinfomanager.h
bluetoothappprofiles/avrcp/remconbeareravrcp/inc/controlbearer.h
bluetoothappprofiles/avrcp/remconbeareravrcp/src/avrcpincomingcommandhandler.cpp
bluetoothappprofiles/avrcp/remconbeareravrcp/src/avrcpplayerinfomanager.cpp
bluetoothappprofiles/avrcp/remconbeareravrcp/src/playerstatewatcher.cpp
bluetoothappprofiles/avrcp/remconbeareravrcp/src/remconbeareravrcp.cpp
bluetoothengine/btaudioman/inc/basrvacc.h
bluetoothengine/btaudioman/inc/basrvaccstate.h
bluetoothengine/btaudioman/inc/basrvaccstateattached.h
bluetoothengine/btaudioman/src/basrvacc.cpp
bluetoothengine/btaudioman/src/basrvaccman.cpp
bluetoothengine/btaudioman/src/basrvaccstate.cpp
bluetoothengine/btaudioman/src/basrvaccstateattached.cpp
bluetoothengine/bteng/bttoggle/src/bttoggle.cpp
bluetoothengine/bteng/conf/CI_bteng.confml
bluetoothengine/bteng/group/bld.inf
bluetoothengine/bteng/src/btengsrvsettingsmgr.cpp
bluetoothengine/btindicator/inc/btindicatorconstants.h
bluetoothengine/btindicator/rom/btindicator.iby
bluetoothengine/btindicator/src/btindicatorplugin.cpp
bluetoothengine/btmac/inc/btmonobearer/bmbcmdlistener.h
bluetoothengine/btmac/inc/btmonocmdhandler/HfpAtCmdHandler.h
bluetoothengine/btmac/src/BTMonoCmdHandler/HfpAtCmdhandler.cpp
bluetoothengine/btmac/src/BTMonoCmdHandler/btmccallinghandler.cpp
bluetoothengine/btmac/src/BTMonoCmdHandler/btmcprotocol.cpp
bluetoothengine/btmac/src/btmac/btmpagescanparametersmanager.cpp
bluetoothengine/btmac/src/btmonobearer/bmbcmdlistener.cpp
bluetoothengine/btnotif/btdevicedialogplugin/btdevicedialogplugin.pro
bluetoothengine/btnotif/btdevicedialogplugin/btdevicedialogplugin.qrc
bluetoothengine/btnotif/btdevicedialogplugin/docml/bt-device-search-dialog.docml
bluetoothengine/btnotif/btdevicedialogplugin/docml/bt-more-devices-dialog.docml
bluetoothengine/btnotif/btdevicedialogplugin/docml/bt-receive-done-dialog.docml
bluetoothengine/btnotif/btdevicedialogplugin/docml/bt-send-dialog.docml
bluetoothengine/btnotif/btdevicedialogplugin/inc/btdevicedialogrecvquerywidget.h
bluetoothengine/btnotif/btdevicedialogplugin/inc/btdevicedialogutils.h
bluetoothengine/btnotif/btdevicedialogplugin/inc/btdevicesearchdialogwidget.h
bluetoothengine/btnotif/btdevicedialogplugin/inc/btmoredevicesdialogwidget.h
bluetoothengine/btnotif/btdevicedialogplugin/inc/btrecvcompleteddialogwidget.h
bluetoothengine/btnotif/btdevicedialogplugin/inc/btrecvprgrsdialogwidget.h
bluetoothengine/btnotif/btdevicedialogplugin/src/btdevicedialogplugin.cpp
bluetoothengine/btnotif/btdevicedialogplugin/src/btdevicedialogquerywidget.cpp
bluetoothengine/btnotif/btdevicedialogplugin/src/btdevicesearchdialogwidget.cpp
bluetoothengine/btnotif/btdevicedialogplugin/src/btmoredevicesdialogwidget.cpp
bluetoothengine/btnotif/btdevicedialogplugin/src/btrecvcompleteddialogwidget.cpp
bluetoothengine/btnotif/btdevicedialogplugin/src/btrecvprgrsdialogwidget.cpp
bluetoothengine/btnotif/btdevicedialogplugin/src/btsenddialogwidget.cpp
bluetoothengine/btnotif/btnotifsrv/inc/btnotifdeviceselector.h
bluetoothengine/btnotif/btnotifsrv/inc/btnotifoutgoingpairinghandler.h
bluetoothengine/btnotif/btnotifsrv/src/btnotifbasepairinghandler.cpp
bluetoothengine/btnotif/btnotifsrv/src/btnotifdeviceselector.cpp
bluetoothengine/btnotif/btnotifsrv/src/btnotifoutgoingpairinghandler.cpp
bluetoothengine/btnotif/btnotifsrv/src/btnotifpairnotifier.cpp
bluetoothengine/btnotif/btnotifsrv/src/btnotifsecuritymanager.cpp
bluetoothengine/btnotif/btnotifsrv/src/btnotifserviceauthorizer.cpp
bluetoothengine/btnotif/inc/bluetoothdevicedialogs.h
bluetoothengine/btsac/btrcc/inc/btrccVolumeLevelControllerBase.h
bluetoothengine/btsac/btrcc/src/btrccAbsoluteVolumeLevelController.cpp
bluetoothengine/btsac/btrcc/src/btrccLegacyVolumeLevelController.cpp
bluetoothengine/btsac/btrcc/src/btrccLinker.cpp
bluetoothengine/btsac/btrcc/src/btrccVolumeLevelControllerBase.cpp
bluetoothengine/btsac/inc/btsaController.h
bluetoothengine/btsac/inc/btsacStateListening.h
bluetoothengine/btsac/inc/btsacdefs.h
bluetoothengine/btsac/src/btsaController.cpp
bluetoothengine/btsac/src/btsacState.cpp
bluetoothengine/btsac/src/btsacStateAborting.cpp
bluetoothengine/btsac/src/btsacStateConfigured.cpp
bluetoothengine/btsac/src/btsacStateConfiguring.cpp
bluetoothengine/btsac/src/btsacStateConnected.cpp
bluetoothengine/btsac/src/btsacStateConnecting.cpp
bluetoothengine/btsac/src/btsacStateIdle.cpp
bluetoothengine/btsac/src/btsacStateListening.cpp
bluetoothengine/btsac/src/btsacStateStreaming.cpp
bluetoothengine/btsac/src/btsacStateSuspended.cpp
bluetoothengine/btsap/src/BTSapSniffHandler.cpp
bluetoothengine/btui/btcpplugin/btcpplugin.cpp
bluetoothengine/btui/btcpplugin/btcpuidevicedetail.cpp
bluetoothengine/btui/btcpplugin/btcpuidevicedetail.h
bluetoothengine/btui/btcpplugin/btcpuidevicedetailsview.cpp
bluetoothengine/btui/btcpplugin/btcpuidevicedetailsview.h
bluetoothengine/btui/btcpplugin/btcpuideviceview.cpp
bluetoothengine/btui/btcpplugin/btcpuideviceview.h
bluetoothengine/btui/btcpplugin/btcpuimainview.cpp
bluetoothengine/btui/btcpplugin/btcpuimainview.h
bluetoothengine/btui/btcpplugin/btcpuisearchview.cpp
bluetoothengine/btui/btcpplugin/btcpuisearchview.h
bluetoothengine/btui/btcpplugin/docml/bt-device-view.docml
bluetoothengine/btui/btcpplugin/docml/bt-main-view.docml
bluetoothengine/btui/btcpplugin/docml/bt-search-view.docml
bluetoothengine/btui/btuidelegate/btdelegateInquiry.h
bluetoothengine/btui/btuidelegate/btdelegateconnect.cpp
bluetoothengine/btui/btuidelegate/btdelegateconnect.h
bluetoothengine/btui/btuidelegate/btdelegatedevsecurity.cpp
bluetoothengine/btui/btuidelegate/btdelegatedevsecurity.h
bluetoothengine/btui/btuidelegate/btdelegatepower.cpp
bluetoothengine/btui/btuidelegate/btdelegatepower.h
bluetoothengine/btui/btuidelegate/btdelegateremotedevname.cpp
bluetoothengine/btui/btuidelegate/btdelegateremotedevname.h
bluetoothengine/btui/btuimodel/btdevicemodel_p.h
bluetoothengine/btui/inc/btuiiconutil.h
btobexprofiles/inc/BTServiceParameterList.h
btobexprofiles/inc/btserviceapi.h
btobexprofiles/inc/obexutilsdialog.h
btobexprofiles/inc/obexutilspropertynotifier.h
btobexprofiles/obexreceiveservices/bip/inc/BIPController.h
btobexprofiles/obexreceiveservices/bip/src/BIPController.cpp
btobexprofiles/obexreceiveservices/btmsgviewer/btmsgviewer.pro
btobexprofiles/obexreceiveservices/btmsgviewer/inc/btmsgviewer.h
btobexprofiles/obexreceiveservices/btmsgviewer/inc/btmsgviewerutils.h
btobexprofiles/obexreceiveservices/btmsgviewer/src/btmsgviewer.cpp
btobexprofiles/obexreceiveservices/btmsgviewer/src/btmsgviewerutils.cpp
btobexprofiles/obexreceiveservices/btmsgviewer/src/main.cpp
btobexprofiles/obexreceiveservices/opp/inc/oppcontroller.h
btobexprofiles/obexreceiveservices/opp/src/oppcontroller.cpp
btobexprofiles/obexsendservices/obexservicesendutils/src/BTServiceClient.cpp
btobexprofiles/obexsendservices/obexservicesendutils/src/BTServiceStarter.cpp
btobexprofiles/obexserviceman/rom/obex.iby
btobexprofiles/obexserviceman/utils/inc/obexutilsentryhandler.h
btobexprofiles/obexserviceman/utils/src/obexutilsentryhandler.cpp
btobexprofiles/obexserviceman/utils/src/obexutilsmessagehandler.cpp
cbsatplugin/atmisccmdplugin/data/2002C3BA_TDSCDMA.rss
cbsatplugin/atmisccmdplugin/group/atmisccmdplugin.mmp
cbsatplugin/atmisccmdplugin/inc/atcommandparser.h
cbsatplugin/atmisccmdplugin/inc/atmisccmdplugin.h
cbsatplugin/atmisccmdplugin/inc/atmisccmdpluginconsts.h
cbsatplugin/atmisccmdplugin/inc/cgmicommandhandler.h
cbsatplugin/atmisccmdplugin/inc/cgmmcommandhandler.h
cbsatplugin/atmisccmdplugin/inc/cgmrcommandhandler.h
cbsatplugin/atmisccmdplugin/inc/cgsncommandhandler.h
cbsatplugin/atmisccmdplugin/inc/cmgdcommandhandler.h
cbsatplugin/atmisccmdplugin/inc/cmgwcommandhandler.h
cbsatplugin/atmisccmdplugin/inc/cmserror.h
cbsatplugin/atmisccmdplugin/inc/hvercommandhandler.h
cbsatplugin/atmisccmdplugin/inc/scpbrcommandhandler.h
cbsatplugin/atmisccmdplugin/inc/scpbwcommandhandler.h
cbsatplugin/atmisccmdplugin/inc/telephonywrapper.h
cbsatplugin/atmisccmdplugin/rom/atmisccmdplugin.iby
cbsatplugin/atmisccmdplugin/src/atcommandparser.cpp
cbsatplugin/atmisccmdplugin/src/atmisccmdplugin.cpp
cbsatplugin/atmisccmdplugin/src/cgmicommandhandler.cpp
cbsatplugin/atmisccmdplugin/src/cgmmcommandhandler.cpp
cbsatplugin/atmisccmdplugin/src/cgmrcommandhandler.cpp
cbsatplugin/atmisccmdplugin/src/cgsncommandhandler.cpp
cbsatplugin/atmisccmdplugin/src/cmgdcommandhandler.cpp
cbsatplugin/atmisccmdplugin/src/cmgwcommandhandler.cpp
cbsatplugin/atmisccmdplugin/src/cpincommandhandler.cpp
cbsatplugin/atmisccmdplugin/src/hvercommandhandler.cpp
cbsatplugin/atmisccmdplugin/src/scpbrcommandhandler.cpp
cbsatplugin/atmisccmdplugin/src/scpbwcommandhandler.cpp
cbsatplugin/atmisccmdplugin/src/telephonywrapper.cpp
package_map.xml
--- a/bluetoothappprofiles/avrcp/mediabrowseapi/group/bld.inf	Tue Jul 06 14:27:09 2010 +0300
+++ b/bluetoothappprofiles/avrcp/mediabrowseapi/group/bld.inf	Wed Aug 18 09:59:05 2010 +0300
@@ -40,5 +40,5 @@
 ../public/remconmediabrowsetypes.h SYMBIAN_MW_LAYER_PUBLIC_EXPORT_PATH(remconmediabrowsetypes.h)
 ../public/remconmediabrowsepanic.h SYMBIAN_MW_LAYER_PUBLIC_EXPORT_PATH(remconmediabrowsepanic.h)
 
-../public/remconmediabrowsetargetbase.h	SYMBIAN_MW_LAYER_PUBLIC_EXPORT_PATH(remcon/remconmediabrowsetargetbase.h)
+../public/remconmediabrowsetargetbase.h	SYMBIAN_MW_LAYER_PLATFORM_EXPORT_PATH(remcon/remconmediabrowsetargetbase.h)
 
--- a/bluetoothappprofiles/avrcp/nowplayingapi/group/bld.inf	Tue Jul 06 14:27:09 2010 +0300
+++ b/bluetoothappprofiles/avrcp/nowplayingapi/group/bld.inf	Wed Aug 18 09:59:05 2010 +0300
@@ -30,4 +30,4 @@
 ../public/remcondatabaseunawarenowplayingtarget.h SYMBIAN_MW_LAYER_PUBLIC_EXPORT_PATH(remcondatabaseunawarenowplayingtarget.h)
 ../public/remcondatabaseunawarenowplayingtargetobserver.h SYMBIAN_MW_LAYER_PUBLIC_EXPORT_PATH(remcondatabaseunawarenowplayingtargetobserver.h)
 
-../public/remconnowplayingtargetbase.h SYMBIAN_MW_LAYER_PUBLIC_EXPORT_PATH(remcon/remconnowplayingtargetbase.h)
+../public/remconnowplayingtargetbase.h SYMBIAN_MW_LAYER_PLATFORM_EXPORT_PATH(remcon/remconnowplayingtargetbase.h)
--- a/bluetoothappprofiles/avrcp/remconbeareravrcp/group/remconbeareravrcp.mmp	Tue Jul 06 14:27:09 2010 +0300
+++ b/bluetoothappprofiles/avrcp/remconbeareravrcp/group/remconbeareravrcp.mmp	Wed Aug 18 09:59:05 2010 +0300
@@ -20,8 +20,6 @@
  @file
 */
 
-#include "../../../../../../os/bt/bluetoothmgmt/btcommon/config.cfg"
-
 #include <remcon/remconservercaps.mmh>
 
 TARGET        remconbeareravrcp.dll
--- a/bluetoothappprofiles/avrcp/remconbeareravrcp/inc/avrcpplayerinfomanager.h	Tue Jul 06 14:27:09 2010 +0300
+++ b/bluetoothappprofiles/avrcp/remconbeareravrcp/inc/avrcpplayerinfomanager.h	Wed Aug 18 09:59:05 2010 +0300
@@ -1,4 +1,4 @@
-// Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
+// Copyright (c) 2008-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"
@@ -88,6 +88,7 @@
 	void ClientStatus(TBool aControllerPresent, TBool aTargetPresent);	
 	TInt SetLocalAddressedClient(const TRemConClientId& aId);
 	void ControllerFeaturesUpdatedL(RArray<TUid>& aSupportedInterfaces);
+	void TargetFeaturesUpdated(const TRemConClientId& aId, TPlayerType aPlayerType, TPlayerSubType aPlayerSubType, const TDesC8& aName);
 	MIncomingCommandHandler& InternalCommandHandler();
 
 	// Interface to command handler
@@ -106,7 +107,10 @@
 	void MpsoPlayStatusChanged(TRemConClientId aId, MPlayerEventsObserver::TPlaybackStatus aPlaybackStatus);
 	void MpsoError(TRemConClientId aId);
 
-
+	// Helper function for ClientAvailable and TargetFeaturesUpdated
+	TInt SetItemDetails(TAvrcpMediaPlayerItem& aItem, TPlayerType aPlayerType, TPlayerSubType aPlayerSubType, const TDesC8& aName);
+	void UpdateSdpRecord(const TAvrcpMediaPlayerItem& aItem);
+	
 //---------------------------------------------------------
 // Bulk thread only functions
 //---------------------------------------------------------
--- a/bluetoothappprofiles/avrcp/remconbeareravrcp/inc/controlbearer.h	Tue Jul 06 14:27:09 2010 +0300
+++ b/bluetoothappprofiles/avrcp/remconbeareravrcp/inc/controlbearer.h	Wed Aug 18 09:59:05 2010 +0300
@@ -1,4 +1,4 @@
-// Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
+// Copyright (c) 2008-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"
@@ -118,6 +118,8 @@
 	
 	virtual TInt SetLocalAddressedClient(TRemConClientId& aId);
 	
+	virtual void TargetFeaturesUpdated(const TRemConClientId& aId, TPlayerType aPlayerType, TPlayerSubType aPlayerSubType, const TDesC8& aName);
+	
 private: // from CRemConBearerPlugin
 	TAny* GetInterface(TUid aUid);
 	
--- a/bluetoothappprofiles/avrcp/remconbeareravrcp/src/avrcpincomingcommandhandler.cpp	Tue Jul 06 14:27:09 2010 +0300
+++ b/bluetoothappprofiles/avrcp/remconbeareravrcp/src/avrcpincomingcommandhandler.cpp	Wed Aug 18 09:59:05 2010 +0300
@@ -1,4 +1,4 @@
-// Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
+// Copyright (c) 2004-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"
@@ -564,13 +564,13 @@
 			
 			// Can ignore this as we know we have allocated a big enough buffer
 			TRAP_IGNORE(response.WriteL(responseBuf));
+
+			iCommandInterface.MrccciSetAddressedClient(iClientId);
 			break;
 			}
 			};
 	
 		SendInternalResponse(aId, responseBuf);
-		iCommandInterface.MrccciSetAddressedClient(iClientId);
-	
 		responseBuf.Close();
 		}
 
--- a/bluetoothappprofiles/avrcp/remconbeareravrcp/src/avrcpplayerinfomanager.cpp	Tue Jul 06 14:27:09 2010 +0300
+++ b/bluetoothappprofiles/avrcp/remconbeareravrcp/src/avrcpplayerinfomanager.cpp	Wed Aug 18 09:59:05 2010 +0300
@@ -1,4 +1,4 @@
-// Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
+// Copyright (c) 2008-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"
@@ -133,7 +133,33 @@
 	iUidWatcher = NULL;
 	}
 
-void CAvrcpPlayerInfoManager::ClientAvailable(const TRemConClientId& aId, TPlayerType aClientType, TPlayerSubType aClientSubType, const TDesC8& aName)
+// Helper function for ClientAvailable and TargetFeaturesUpdated
+TInt CAvrcpPlayerInfoManager::SetItemDetails(TAvrcpMediaPlayerItem& aItem, TPlayerType aPlayerType, TPlayerSubType aPlayerSubType, const TDesC8& aName)
+	{
+	aItem.iPlayerType = aPlayerType;
+	aItem.iPlayerSubType = aPlayerSubType;
+	aItem.iName.Set(aName);
+	aItem.iFeatureBitmask = TPlayerFeatureBitmask();
+	return SetPlayerFeatures(aItem.iId, aItem.iFeatureBitmask, aItem.iSdpFeatures, aItem.iAbsoluteVolumeSupport);
+	}
+
+// Helper function for ClientAvailable and TargetFeaturesUpdated
+void CAvrcpPlayerInfoManager::UpdateSdpRecord(const TAvrcpMediaPlayerItem& aItem)
+	{
+	// Update SDP record, if this fails we carry on, it's non-fatal
+	TInt sdpErr = KErrNone;
+	if(!iTargetRecord)
+		{
+		TRAP(sdpErr, AvrcpSdpUtils::CreateServiceRecordL(iSdpDatabase, iTargetRecord, ETrue, 
+					(aItem.iSdpFeatures & AvrcpSdp::EBrowsing) ? AvrcpSdp::KAvrcpProfileVersion14 : AvrcpSdp::KAvrcpProfileVersion13));
+		}
+	if(sdpErr == KErrNone)
+		{
+		TRAP_IGNORE(UpdateTgServiceRecordL());
+		}
+	}
+
+void CAvrcpPlayerInfoManager::ClientAvailable(const TRemConClientId& aId, TPlayerType aPlayerType, TPlayerSubType aPlayerSubType, const TDesC8& aName)
 	{
 	LOG_FUNC;
 	ASSERT_CONTROL_THREAD;
@@ -150,15 +176,11 @@
 	
 	TAvrcpMediaPlayerItem& item = iPlayers[index];
 	item.iId = aId;
-	item.iPlayerType = aClientType;
-	item.iPlayerSubType = aClientSubType;
-	item.iName.Set(aName);
 	item.iBulkClientAvailable = EFalse;
 	item.iUidCounter = 0;
 	item.iLastUpdatedUidCounter = 0;
 	item.iPlaybackStatus = MPlayerEventsObserver::EStopped;
-	item.iFeatureBitmask = TPlayerFeatureBitmask();
-	TInt err = SetPlayerFeatures(aId, item.iFeatureBitmask, item.iSdpFeatures, item.iAbsoluteVolumeSupport);
+	TInt err = SetItemDetails(item, aPlayerType, aPlayerSubType, aName);
 
 	// Release lock before calling out of player info manager in case
 	// anyone needs to call back in - we're finished updating the
@@ -168,41 +190,21 @@
 	if(!err)
 		{
 		TRAP(err, iPlayStatusWatcher->StartWatchingPlayerL(aId));
-	
 		if(!err)
 			{
-			// Update SDP record, if this fails we carry on, it's non-fatal
-			TInt sdpErr = KErrNone;
-			if(!iTargetRecord)
+			UpdateSdpRecord(item);
+		     for(TInt i = 0; i<iObservers.Count(); i++)
 				{
-				TRAP(sdpErr, AvrcpSdpUtils::CreateServiceRecordL(iSdpDatabase, 
-						iTargetRecord, 
-						ETrue, 
-						(item.iSdpFeatures & AvrcpSdp::EBrowsing) ? 
-						AvrcpSdp::KAvrcpProfileVersion14 : 
-						AvrcpSdp::KAvrcpProfileVersion13));
-				}
-			
-			if(sdpErr == KErrNone)
-				{
-				TRAP_IGNORE(UpdateTgServiceRecordL());
+				iObservers[i]->MpcoAvailablePlayersChanged();
 				}
 			}
-		}
-
-	if(!err)
-		{
-		for(TInt i = 0; i<iObservers.Count(); i++)
+		  else    
 			{
-			iObservers[i]->MpcoAvailablePlayersChanged();
+			iLock.Wait();
+			iPlayers[index].iId = KNullClientId;
+			iLock.Signal();
 			}
 		}
-	else	
-		{
-		iLock.Wait();
-		iPlayers[index].iId = KNullClientId;
-		iLock.Signal();
-		}
 	}
 
 void CAvrcpPlayerInfoManager::ClientNotAvailable(const TRemConClientId& aId)
@@ -303,6 +305,46 @@
 	AvrcpSdpUtils::UpdateSupportedFeaturesL(iSdpDatabase, iControllerRecord, AvrcpSdp::ERemoteControl, AvrcpSdp::KAvrcpBaseCtFeatures);
 	}
 
+void CAvrcpPlayerInfoManager::TargetFeaturesUpdated(const TRemConClientId& aId, TPlayerType aPlayerType, TPlayerSubType aPlayerSubType, const TDesC8& aName)
+	{
+	LOG_FUNC;
+	ASSERT_CONTROL_THREAD;
+	iLock.Wait();
+	// Find this client in our client list
+	TInt index = iPlayers.Find(aId, PlayerCompare);
+	if(index < 0)
+		{
+		// Couldn't find client in client list, maybe we removed it after an earlier failure
+		iLock.Signal();
+		return;
+		}
+
+	TAvrcpMediaPlayerItem& item = iPlayers[index];
+	TInt err = SetItemDetails(item, aPlayerType, aPlayerSubType, aName);
+
+	// Release lock before calling out of player info manager in case
+	// anyone needs to call back in - we're finished updating the
+	// info now.
+	iLock.Signal();
+
+	if(!err)
+		{
+		UpdateSdpRecord(item);
+		}
+	else    
+		{
+		// There was an error updating the features so remove this client from the client list
+		iLock.Wait();
+		iPlayers[index].iId = KNullClientId;
+		iLock.Signal();
+		}
+
+	for(TInt i = 0; i<iObservers.Count(); i++)
+		{
+		iObservers[i]->MpcoAvailablePlayersChanged();
+		}
+	}
+
 MIncomingCommandHandler& CAvrcpPlayerInfoManager::InternalCommandHandler()
 	{
 	LOG_FUNC
--- a/bluetoothappprofiles/avrcp/remconbeareravrcp/src/playerstatewatcher.cpp	Tue Jul 06 14:27:09 2010 +0300
+++ b/bluetoothappprofiles/avrcp/remconbeareravrcp/src/playerstatewatcher.cpp	Wed Aug 18 09:59:05 2010 +0300
@@ -37,14 +37,17 @@
 void CPlayerWatcherBase::StopWatchingPlayer(TRemConClientId aClientId)
 	{
 	LOG_FUNC;
-	CInternalCommand* command = *iCommands.Find(aClientId);
-	__ASSERT_DEBUG(command, AVRCP_PANIC(ENotWatchingPlayer));
-
-	TUint transId = command->RemConCommandId();
-	iCommandInterface.MrcciCommandExpired(transId);
-
-	iCommands.Remove(aClientId);
-	command->DecrementUsers();
+	CInternalCommand** cmdPtr = iCommands.Find(aClientId);
+	if (cmdPtr) // This may be NULL if we've already stopped watching the player as a result of reciving a reject
+	    {
+        CInternalCommand* cmd = *cmdPtr;
+        
+        TUint transId = cmd->RemConCommandId();
+        iCommandInterface.MrcciCommandExpired(transId);
+    
+        iCommands.Remove(aClientId);
+        cmd->DecrementUsers();
+	    }
 	}
 
 void CPlayerWatcherBase::MessageSent(CAvrcpCommand& /*aCommand*/, TInt /*aSendResult*/)
--- a/bluetoothappprofiles/avrcp/remconbeareravrcp/src/remconbeareravrcp.cpp	Tue Jul 06 14:27:09 2010 +0300
+++ b/bluetoothappprofiles/avrcp/remconbeareravrcp/src/remconbeareravrcp.cpp	Wed Aug 18 09:59:05 2010 +0300
@@ -1,4 +1,4 @@
-// Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
+// Copyright (c) 2004-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"
@@ -698,6 +698,19 @@
 	return iPlayerInfoManager->SetLocalAddressedClient(aId);
 	}
 
+void CRemConBearerAvrcp::TargetFeaturesUpdated(const TRemConClientId& aId, TPlayerType aPlayerType, TPlayerSubType aPlayerSubType, const TDesC8& aName)
+    {
+    LOG_FUNC
+    
+    if (!iConstructionComplete)
+        {
+        // Object only partially constructed, swallow the request
+        return;
+        }
+    
+    iPlayerInfoManager->TargetFeaturesUpdated(aId, aPlayerType, aPlayerSubType, aName);
+    }
+
 void CRemConBearerAvrcp::ControllerFeaturesUpdated(RArray<TUid>& aSupportedInterfaces)
 	{
 	LOG_FUNC
--- a/bluetoothengine/btaudioman/inc/basrvacc.h	Tue Jul 06 14:27:09 2010 +0300
+++ b/bluetoothengine/btaudioman/inc/basrvacc.h	Wed Aug 18 09:59:05 2010 +0300
@@ -67,6 +67,11 @@
     void OpenAudioL(TAccAudioType aType);
 
     /**
+    * Called when the audio open request is to be cancelled.
+    */
+    void CancelOpenAudio();
+    
+    /**
     * Called when an audio close request comes from Acc FW.
     */
     void CloseAudioL(TAccAudioType aType);
--- a/bluetoothengine/btaudioman/inc/basrvaccstate.h	Tue Jul 06 14:27:09 2010 +0300
+++ b/bluetoothengine/btaudioman/inc/basrvaccstate.h	Wed Aug 18 09:59:05 2010 +0300
@@ -102,7 +102,12 @@
     * Called when an audio open request comes from Acc FW.
     */
     virtual void OpenAudioL(TAccAudioType aType);
-
+    
+    /**
+    * Called when the audio open request is to be cancelled.
+    */
+    virtual void CancelOpenAudio();
+    
     /**
     * Called when an audio close request comes from Acc FW.
     */
--- a/bluetoothengine/btaudioman/inc/basrvaccstateattached.h	Tue Jul 06 14:27:09 2010 +0300
+++ b/bluetoothengine/btaudioman/inc/basrvaccstateattached.h	Wed Aug 18 09:59:05 2010 +0300
@@ -84,6 +84,12 @@
     void OpenAudioL(TAccAudioType aType);
 
     /**
+    * Called when the audio open request is to be cancelled.
+    */
+    void CancelOpenAudio();
+
+    
+    /**
     * Called when an audio close request comes from Acc FW.
     */
     void CloseAudioL(TAccAudioType aType);
--- a/bluetoothengine/btaudioman/src/basrvacc.cpp	Tue Jul 06 14:27:09 2010 +0300
+++ b/bluetoothengine/btaudioman/src/basrvacc.cpp	Wed Aug 18 09:59:05 2010 +0300
@@ -139,6 +139,12 @@
     iState->CloseAudioL(aType);
     }
 
+void CBasrvAcc::CancelOpenAudio()
+    {
+    TRACE_FUNC
+    iState->CancelOpenAudio();
+    }
+
 const TAccInfo* CBasrvAcc::AccInfo(const TBTDevAddr& aAddr)
     {
     TRACE_FUNC
--- a/bluetoothengine/btaudioman/src/basrvaccman.cpp	Tue Jul 06 14:27:09 2010 +0300
+++ b/bluetoothengine/btaudioman/src/basrvaccman.cpp	Wed Aug 18 09:59:05 2010 +0300
@@ -12,7 +12,7 @@
 * Contributors:
 *
 * Description:  Implementation of an accessory management.
-*  Version     : %version:  14.1.11 %
+*  Version     : %version:  14.1.12 %
 *
 */
 
@@ -619,27 +619,23 @@
     TInt idx = FindAcc(aAddr);
     if (idx >= 0)
         {
-        // Check if another audio link opened already
-        TInt audiolinks = AudioLinkStatus();
-        
-        if ( ( audiolinks && audiolinks != aProfile) || 
-            ( iAudioRequests.Count() && 
-              iAudioRequests[0].iOngoing && 
-              iAudioRequests[0].iAddr == aAddr) )
+        TInt audiolinks = AudioLinkStatus();        
+        if ( audiolinks && audiolinks != aProfile) 
             {
-            // another audio type is opened while we have an audio link or pending audio request.
-            if (iAudioRequests.Count())
-                {
-                TRACE_INFO((_L(" [audio link check] existing audio link %x, audio request pending ? %d. Audio should be rejected!"),
-                        audiolinks, iAudioRequests[0].iOngoing))
-                }
-            else
-                {
-                TRACE_INFO((_L(" [audio link check] existing audio link %x. Audio should be rejected!"),
+            TRACE_INFO((_L(" [global audio link check] existing audio link %x. Audio should be rejected!"),
                         audiolinks))
-                }
             RejectAudioLink(aAddr, (aProfile == EStereo) ? EAccStereoAudio : EAccMonoAudio);
             }
+        else if ( iAudioRequests.Count() && 
+                iAudioRequests[0].iReqType == EOpenReqFromAudioPolicy &&
+                iAudioRequests[0].iAudioType == ((aProfile == EStereo) ? EAccStereoAudio : EAccMonoAudio) &&
+                iAudioRequests[0].iOngoing && 
+                iAudioRequests[0].iAddr == aAddr)
+            {
+            TRACE_INFO((_L(" [device-specific audio request check] audio request pending ? %d. Audio request should be cancelled!"),
+                    iAudioRequests[0].iOngoing))
+            iAccs[idx]->CancelOpenAudio();
+            }
         else
             {
             iAccs[idx]->AccOpenedAudio(aProfile);
--- a/bluetoothengine/btaudioman/src/basrvaccstate.cpp	Tue Jul 06 14:27:09 2010 +0300
+++ b/bluetoothengine/btaudioman/src/basrvaccstate.cpp	Wed Aug 18 09:59:05 2010 +0300
@@ -86,6 +86,11 @@
     TRACE_FUNC
     }
 
+void CBasrvAccState::CancelOpenAudio()
+    {
+    TRACE_FUNC
+    }
+
 void CBasrvAccState::CloseAudioL(TAccAudioType /*aType*/)
     {
     TRACE_FUNC
@@ -128,7 +133,7 @@
     }
 
 void CBasrvAccState::NewProfileConnection(TProfiles aProfile)
-    {
+    {    
     AccInfo().iConnProfiles |= aProfile;
     AccInfo().iSuppProfiles |= aProfile;
     if (aProfile == ERemConCT && 
--- a/bluetoothengine/btaudioman/src/basrvaccstateattached.cpp	Tue Jul 06 14:27:09 2010 +0300
+++ b/bluetoothengine/btaudioman/src/basrvaccstateattached.cpp	Wed Aug 18 09:59:05 2010 +0300
@@ -12,7 +12,7 @@
 * Contributors:
 *
 * Description:  Implementation of Connected state.
-*  Version     : %version: 21 %
+*  Version     : %version: 22 %
 *
 */
 
@@ -228,6 +228,16 @@
 	User::RequestComplete( myStatus, KErrNone );
     }
 
+void CBasrvAccStateAttached::CancelOpenAudio()
+    {
+    TRACE_FUNC
+    
+    if (iAudioOpener)
+        {
+        iAudioOpener->Cancel();
+        }
+    }
+
 void CBasrvAccStateAttached::CloseAudioL(TAccAudioType aType)
     {
     TRACE_FUNC
--- a/bluetoothengine/bteng/bttoggle/src/bttoggle.cpp	Tue Jul 06 14:27:09 2010 +0300
+++ b/bluetoothengine/bteng/bttoggle/src/bttoggle.cpp	Wed Aug 18 09:59:05 2010 +0300
@@ -303,9 +303,9 @@
     iNotifier.CancelNotifier(KBTGenericQueryNotifierUid); 
     }  
   else if ( EPowerModeChangeNote == iActiveNotifier ) 
-      {
-      iNotifier.CancelNotifier(KBTGenericQueryNotifierUid); 
-      }
+    {
+    iNotifier.CancelNotifier(KBTGenericInfoNotifierUid); 
+    }
 
   // For all cancels, we must reset iActiveNotifier back to ENoneQuery
   // to permit another request to be made.
@@ -330,8 +330,8 @@
   switch (iActiveNotifier)
     {							
     case EPowerModeQuery:
-      iActiveNotifier = ENoneQuery;
-      ShowNotification(ETrue);    
+      ShowNotification(ETrue);   
+      iActiveNotifier = EPowerModeChangeNote ;
       SetActive();
       break; 			
     case ECloseConnectionQuery:							
Binary file bluetoothengine/bteng/conf/CI_bteng.confml has changed
--- a/bluetoothengine/bteng/group/bld.inf	Tue Jul 06 14:27:09 2010 +0300
+++ b/bluetoothengine/bteng/group/bld.inf	Wed Aug 18 09:59:05 2010 +0300
@@ -37,9 +37,6 @@
 ../conf/bteng_10204DAB.crml 	            MW_LAYER_CRML(bteng_10204DAB.crml)
 ../conf/bteng_10204DAC.crml 	            MW_LAYER_CRML(bteng_10204DAC.crml)
 
-/*remove the following exportation, when SCB CR is approved*/
-../conf/CI_bteng.confml                     MW_LAYER_CONFML(CI_bteng.confml)
-
 
 ../data/btrfs.txt                           z:/resource/btrfs.txt
 
--- a/bluetoothengine/bteng/src/btengsrvsettingsmgr.cpp	Tue Jul 06 14:27:09 2010 +0300
+++ b/bluetoothengine/bteng/src/btengsrvsettingsmgr.cpp	Wed Aug 18 09:59:05 2010 +0300
@@ -707,9 +707,10 @@
     TRACE_INFO( ( _L( "[CBTEngSrvSettingsMgr]\t Using HCI API v2 power manager" ) ) )
     User::LeaveIfError( iPowerMgr.Open() );
 #ifndef __WINS__
-    iPowerMgr.SetPower( EBTOff, NULL, iActive->RequestStatus() );
-    User::WaitForRequest( iActive->RequestStatus() );
-    TInt status = ( iActive->RequestStatus().Int() == KErrAlreadyExists ? KErrNone : iActive->RequestStatus().Int() ); 
+    TRequestStatus reqStatus;
+    iPowerMgr.SetPower( EBTOff, NULL, reqStatus );
+    User::WaitForRequest( reqStatus );
+    TInt status = ( reqStatus.Int() == KErrAlreadyExists ? KErrNone : reqStatus.Int() ); 
     User::LeaveIfError( status );
 #else   //__WINS__
     iPowerState = EBTOff;
--- a/bluetoothengine/btindicator/inc/btindicatorconstants.h	Tue Jul 06 14:27:09 2010 +0300
+++ b/bluetoothengine/btindicator/inc/btindicatorconstants.h	Wed Aug 18 09:59:05 2010 +0300
@@ -15,8 +15,8 @@
  *
  */
 
-#ifndef BTINDCONSTANTS_H
-#define BTINDCONSTANTS_H
+#ifndef BTINDICATORCONSTANTS_H
+#define BTINDICATORCONSTANTS_H
 
 
 
@@ -36,7 +36,7 @@
     EBTIndicatorHiddenConnected
     };
 
-#endif /* BTINDCONSTANTS_H */
+#endif /* BTINDICATORCONSTANTS_H */
 
 
 
--- a/bluetoothengine/btindicator/rom/btindicator.iby	Tue Jul 06 14:27:09 2010 +0300
+++ b/bluetoothengine/btindicator/rom/btindicator.iby	Wed Aug 18 09:59:05 2010 +0300
@@ -1,5 +1,5 @@
 /*
-* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
+* Copyright (c) 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"
--- a/bluetoothengine/btindicator/src/btindicatorplugin.cpp	Tue Jul 06 14:27:09 2010 +0300
+++ b/bluetoothengine/btindicator/src/btindicatorplugin.cpp	Wed Aug 18 09:59:05 2010 +0300
@@ -34,9 +34,9 @@
 // BTIndicatorPlugin::~BTIndicatorPlugin
 // ----------------------------------------------------------------------------
 BTIndicatorPlugin::~BTIndicatorPlugin()
-    {
+{
     delete mIndicatorTranslator;
-    }
+}
 
 // ----------------------------------------------------------------------------
 // BTIndicatorPlugin::indicatorTypes
@@ -70,10 +70,9 @@
 // ----------------------------------------------------------------------------
 HbIndicatorInterface* BTIndicatorPlugin::createIndicator(const QString &indicatorType)
 {
-    if(!mIndicatorTranslator)
-        {
+    if(!mIndicatorTranslator) {
         mIndicatorTranslator = new HbTranslator(BTINDICATOR_TRANSLATION);
-        }
+    }
     HbIndicatorInterface *indicator = new BTIndicator(indicatorType);
     return indicator;
 }
--- a/bluetoothengine/btmac/inc/btmonobearer/bmbcmdlistener.h	Tue Jul 06 14:27:09 2010 +0300
+++ b/bluetoothengine/btmac/inc/btmonobearer/bmbcmdlistener.h	Wed Aug 18 09:59:05 2010 +0300
@@ -90,7 +90,7 @@
         RProperty iATRespProperty;
 
 		// At command buffer
-		TBuf8<KDefaultCmdBufLength> iAtCmdBuf;
+        RBuf8 iAtCmdBuf;
     };
 
 #endif
--- a/bluetoothengine/btmac/inc/btmonocmdhandler/HfpAtCmdHandler.h	Tue Jul 06 14:27:09 2010 +0300
+++ b/bluetoothengine/btmac/inc/btmonocmdhandler/HfpAtCmdHandler.h	Wed Aug 18 09:59:05 2010 +0300
@@ -133,10 +133,11 @@
     MATExtObserver& iObserver;
     
     RATExt iATExtClient;
-    TBuf8<KDefaultCmdBufLength> iCmdBuffer;
-    TBuf8<KDefaultCmdBufLength> iRecvBuffer;
-    TBuf8<KDefaultCmdBufLength> iReplyBuffer;
-    TBuf8<512> iSystemReply;
+    // reserve buffers from the heap
+    RBuf8 iCmdBuffer;
+    RBuf8 iSystemReply;
+    TBuf8<KDefaultCmdBufLength> *iRecvBuffer;
+    TBuf8<KDefaultCmdBufLength> *iReplyBuffer;
     
     TInt iRemainingReplyLength;
     TPckg<TInt> iRemainingReplyLengthPckg;
--- a/bluetoothengine/btmac/src/BTMonoCmdHandler/HfpAtCmdhandler.cpp	Tue Jul 06 14:27:09 2010 +0300
+++ b/bluetoothengine/btmac/src/BTMonoCmdHandler/HfpAtCmdhandler.cpp	Wed Aug 18 09:59:05 2010 +0300
@@ -49,20 +49,24 @@
         {
         iATExtClient.Close();
         }
+   iCmdBuffer.Close();
+   iSystemReply.Close();
+   delete iRecvBuffer;
+   delete iReplyBuffer;
 }
 
 void CHFPAtCmdHandler::HandleCommand(const TDesC8& aAT, const TDesC8& aReply)
     {
     TRACE_INFO((_L8("default reply '%S'"), &aReply))
     iCmdBuffer.Copy(aAT);
-    iReplyBuffer.Zero();
+    iReplyBuffer->Zero();
     if (aReply.Length())
         {
-        iReplyBuffer.Copy(aReply);
+        iReplyBuffer->Copy(aReply);
         iSystemReply.Copy(aReply);
-        }
+        } 
     iATExtClient.HandleCommand(iCommander->iStatus, 
-            iCmdBuffer, iReplyBuffer, iRemainingReplyLengthPckg, iReplyTypePckg);
+            iCmdBuffer, *iReplyBuffer, iRemainingReplyLengthPckg, iReplyTypePckg);
     iCommander->GoActive(); 
     }
 
@@ -79,16 +83,16 @@
                 if (iRemainingReplyLengthPckg())
                     {
                     TRACE_INFO((_L8("reply '%S'"), &iReplyBuffer))
-                    iObserver.ATExtHandleReplyReceivedL(err, iReplyBuffer);
+                    iObserver.ATExtHandleReplyReceivedL(err, *iReplyBuffer);
                     do 
                         {
                         TRACE_INFO((_L8("iRemainingReplyLength '%d'"), iRemainingReplyLengthPckg()))
                         RBuf8 reply;
                         reply.CreateL(iRemainingReplyLengthPckg());
-                        err = iATExtClient.GetNextPartOfReply(iRecvBuffer, iRemainingReplyLengthPckg());
+                        err = iATExtClient.GetNextPartOfReply(*iRecvBuffer, iRemainingReplyLengthPckg());
                         if (!err)
                             {
-                            reply.Insert(0, iRecvBuffer);
+                            reply.Insert(0, *iRecvBuffer);
                             }
                         TRACE_INFO((_L8("reply '%S'"), &reply))
                         iObserver.ATExtHandleReplyReceivedL(err, reply);
@@ -98,8 +102,8 @@
                     }
                 else
                     {
-                    TRACE_INFO((_L8("reply '%S'"), &iReplyBuffer))
-                    iObserver.ATExtHandleReplyReceivedL(err, iReplyBuffer);
+                    TRACE_INFO((_L8("reply '%S'"), iReplyBuffer))
+                    iObserver.ATExtHandleReplyReceivedL(err, *iReplyBuffer);
                     }
                 }
             else
@@ -159,6 +163,10 @@
     
     StartUrc();
     iCommander = CBtmcActive::NewL(*this, CActive::EPriorityStandard, EHandleCommandRequest);
+    iCmdBuffer.CreateL(KDefaultCmdBufLength);
+    iRecvBuffer = new (ELeave) TBuf8<KDefaultCmdBufLength>();
+    iReplyBuffer = new (ELeave) TBuf8<KDefaultCmdBufLength>();
+    iSystemReply.CreateL(KDefaultUrcBufLength);
     TRACE_FUNC_EXIT
     }
     
--- a/bluetoothengine/btmac/src/BTMonoCmdHandler/btmccallinghandler.cpp	Tue Jul 06 14:27:09 2010 +0300
+++ b/bluetoothengine/btmac/src/BTMonoCmdHandler/btmccallinghandler.cpp	Wed Aug 18 09:59:05 2010 +0300
@@ -94,13 +94,15 @@
             TInt result = KErrNone;
             if (!aErr)
                 {
-                TBuf8<KDefaultCmdBufLength> buf;
+                RBuf8 buf;
+                buf.CreateL(KDefaultCmdBufLength);
                 aErr = iRespProperty.Get(buf);
                 if (!aErr && buf.Length() >= sizeof(TInt))
                     {
                     const TUint8* ptr = buf.Ptr();
                     result = *((const TInt*)ptr);
                     }
+                buf.Close();
                 }
             TRACE_INFO((_L("resp %d"), result))
             TATId atid = EATOK;
--- a/bluetoothengine/btmac/src/BTMonoCmdHandler/btmcprotocol.cpp	Tue Jul 06 14:27:09 2010 +0300
+++ b/bluetoothengine/btmac/src/BTMonoCmdHandler/btmcprotocol.cpp	Wed Aug 18 09:59:05 2010 +0300
@@ -399,21 +399,23 @@
         {
         return;
         }
-    TBuf8<KDefaultCmdBufLength> cmddes;
-    if (iInDataBuf.NextCommand(cmddes))
+    RBuf8 cmddes;
+    cmddes.CreateL(KDefaultCmdBufLength);
+    CleanupClosePushL(cmddes);
+    if (iInDataBuf.NextCommand(cmddes) || cmddes.Length() == 0)
         {
+        CleanupStack::PopAndDestroy(&cmddes);
         return;
         }
-    if (cmddes.Length() == 0)
-        {
-        return;
-        }
+    
     TRACE_INFO_SEG(
         {
-        TBuf8<KDefaultCmdBufLength> buf;
+        RBuf8 buf;
+        buf.CreateL(KDefaultCmdBufLength);
         buf = cmddes;
         buf.Trim();
         Trace(_L8("[HFP] [I] %S"), &buf);
+        buf.Close();
         })
 
     CATCommand* cmd = NULL;
@@ -423,13 +425,16 @@
       	if(iAtExt)
         	{
       		iAtExt->HandleCommand(cmddes, _L8("\n\rERROR\n\r"));
+      		CleanupStack::PopAndDestroy(&cmddes);
         	return;
         	}
         CATResult* nok = CATResult::NewLC(EATERROR);
         SendResponseL(*nok);
         CleanupStack::PopAndDestroy(nok);
+        CleanupStack::PopAndDestroy(&cmddes);
         return;
         }
+    CleanupStack::PopAndDestroy(&cmddes);
     CleanupStack::PushL(cmd);
     iHandleCmdPending = ETrue;
 	TATId id = cmd->Id();
@@ -1080,14 +1085,17 @@
     {
     TRACE_INFO((_L("credit %d"), iCredit))
     TInt count = iOutgoPacketQueue->MdcaCount();
+    RBuf8 buf;
+    buf.CreateL(KDefaultCmdBufLength);
+    CleanupClosePushL(buf);
     for (TInt i = 0; iCredit >0 && i < count; i++)
         {
         iCredit--;
-        TBuf8<KDefaultCmdBufLength> buf;
         buf.Copy(iOutgoPacketQueue->MdcaPoint(0));
         iObserver.SendProtocolDataL(buf);
         iOutgoPacketQueue->Delete(0);
         }
+    CleanupStack::PopAndDestroy(&buf);
     }
 
 void CBtmcProtocol::StartTimerL(TInt aService, TInt aTimeout)
--- a/bluetoothengine/btmac/src/btmac/btmpagescanparametersmanager.cpp	Tue Jul 06 14:27:09 2010 +0300
+++ b/bluetoothengine/btmac/src/btmac/btmpagescanparametersmanager.cpp	Wed Aug 18 09:59:05 2010 +0300
@@ -71,6 +71,7 @@
                                                    KPageScanParametersListenerService);
 
     iTimerActive = CBtmActive::NewL(*this, CActive::EPriorityStandard, KFastConnectionService);
+    LEAVE_IF_ERROR(iTimer.CreateLocal());
     TRACE_FUNC_EXIT
     }
 
@@ -89,7 +90,6 @@
     if (!iTimerActive->IsActive())
         {
         TRACE_FUNC_ENTRY
-        iTimer.CreateLocal();
         iTimer.After(iTimerActive->iStatus, aTimeout);
         iTimerActive->SetRequestId(aService);
         iTimerActive->GoActive();
@@ -107,7 +107,6 @@
         {
         TRACE_FUNC_ENTRY
         iTimerActive->Cancel();
-        iTimer.Close();
         TRACE_FUNC_EXIT
         }
     }
--- a/bluetoothengine/btmac/src/btmonobearer/bmbcmdlistener.cpp	Tue Jul 06 14:27:09 2010 +0300
+++ b/bluetoothengine/btmac/src/btmonobearer/bmbcmdlistener.cpp	Wed Aug 18 09:59:05 2010 +0300
@@ -35,6 +35,7 @@
    	Cancel();
    	iATCmdProperty.Close();
    	iATRespProperty.Close();
+   	iAtCmdBuf.Close();
     }
 
 // ---------------------------------------------------------------------------
@@ -60,6 +61,7 @@
 	TRACE_FUNC
     LEAVE_IF_ERROR(iATCmdProperty.Attach(KPSUidBluetoothEnginePrivateCategory, KBTHfpATCommand));
 	LEAVE_IF_ERROR(iATRespProperty.Attach(KPSUidBluetoothEnginePrivateCategory, KBTHfpATResponse));
+	iAtCmdBuf.CreateL(KDefaultCmdBufLength);
 	Subscribe();
     }
 
--- a/bluetoothengine/btnotif/btdevicedialogplugin/btdevicedialogplugin.pro	Tue Jul 06 14:27:09 2010 +0300
+++ b/bluetoothengine/btnotif/btdevicedialogplugin/btdevicedialogplugin.pro	Wed Aug 18 09:59:05 2010 +0300
@@ -35,7 +35,8 @@
     inc/btsenddialogwidget.h \
     inc/btdevicedialogplugintrace.h \
     inc/btdevicedialogrecvquerywidget.h \
-    inc/btrecvprgrsdialogwidget.h
+    inc/btrecvprgrsdialogwidget.h \
+    inc/btrecvcompleteddialogwidget.h
 
     
 SOURCES += src/btdevicedialogplugin.cpp \
@@ -46,7 +47,8 @@
     src/btmoredevicesdialogwidget.cpp \
     src/btsenddialogwidget.cpp \
     src/btdevicedialogrecvquerywidget.cpp \
-    src/btrecvprgrsdialogwidget.cpp
+    src/btrecvprgrsdialogwidget.cpp \
+    src/btrecvcompleteddialogwidget.cpp
 
 RESOURCES += btdevicedialogplugin.qrc
     
@@ -56,7 +58,10 @@
     TARGET.CAPABILITY = CAP_GENERAL_DLL
     TARGET.UID3 = 0x2002E6DF
     
-    LIBS += -lbtdevice
+    LIBS += -lbtdevice \
+    		-lhbcore \
+	       	-lxqservice \
+    		-lxqserviceutil \
     
     hblib.sources = Hb.dll
     hblib.path = \sys\bin
--- a/bluetoothengine/btnotif/btdevicedialogplugin/btdevicedialogplugin.qrc	Tue Jul 06 14:27:09 2010 +0300
+++ b/bluetoothengine/btnotif/btdevicedialogplugin/btdevicedialogplugin.qrc	Wed Aug 18 09:59:05 2010 +0300
@@ -7,5 +7,6 @@
         <file>icons/qtg_large_bluetooth.svg</file>
         <file>docml/bt-receive-auth-dialog.docml</file>
         <file>docml/bt-recv-progress-dialog.docml</file>
+        <file>docml/bt-receive-done-dialog.docml</file>
     </qresource>
 </RCC>
--- a/bluetoothengine/btnotif/btdevicedialogplugin/docml/bt-device-search-dialog.docml	Tue Jul 06 14:27:09 2010 +0300
+++ b/bluetoothengine/btnotif/btdevicedialogplugin/docml/bt-device-search-dialog.docml	Wed Aug 18 09:59:05 2010 +0300
@@ -1,13 +1,19 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <hbdocument version="1.1">
     <object name="viewaction" type="HbAction">
-        <string locid="txt_common_button_show" name="text"/>
+        <string locid="txt_common_button_show" name="text" value="Show"/>
     </object>
     <object name="stopretryaction" type="HbAction">
-        <string locid="txt_common_button_stop" name="text"/>
+        <string locid="txt_common_button_stop" name="text" value="Retry"/>
+    </object>
+    <object name="cancelaction" type="HbAction">
+        <string locid="txt_common_button_cancel" name="text" value="Cancel"/>
     </object>
     <widget name="searchdialog" type="HbDialog">
-        <rect height="72.07463un" name="geometry" width="49.73134un" x="1.73134un" y="11.64179un"/>
+        <rect height="96un" name="geometry" width="60.73134un" x="1.2un" y="4.1791un"/>
+        <sizehint type="PREFERRED" width="49.73134un"/>
+        <sizehint type="MAXIMUM" width="50.73134un"/>
+        <size height="91.52239un" name="size" width="50.73134un"/>
         <widget name="heading" role="HbDialog:headingWidget" type="HbLabel">
             <enums name="alignment" value="AlignVCenter|AlignHCenter"/>
             <string locid="txt_bt_subhead_bluetooth_found_devices" name="plainText"/>
@@ -40,15 +46,16 @@
             <widget name="listView" type="HbListView">
                 <widget name="listItemPrototype" role="HbAbstractView:prototype" type="HbListViewItem"/>
                 <enums name="verticalScrollBarPolicy" value="ScrollBarAsNeeded"/>
-                <sizehint height="47.7612un" type="PREFERRED" width="35.8209un"/>
+                <sizehint height="65.7612un" type="PREFERRED" width="35.8209un"/>
             </widget>
             <layout type="grid">
                 <griditem column="0" itemname="container_1" row="0"/>
                 <griditem column="0" itemname="listView" row="1"/>
             </layout>
         </widget>
+        <ref object="viewaction" role="HbWidget:addAction"/>
         <ref object="stopretryaction" role="HbWidget:addAction"/>
-        <ref object="viewaction" role="HbWidget:addAction"/>
+        <ref object="cancelaction" role="HbWidget:addAction"/>
     </widget>
     <metadata activeUIState="Common ui state" display="NHD-3.2-inch_portrait" unit="un">
         <uistate name="Common ui state" sections="#common"/>
--- a/bluetoothengine/btnotif/btdevicedialogplugin/docml/bt-more-devices-dialog.docml	Tue Jul 06 14:27:09 2010 +0300
+++ b/bluetoothengine/btnotif/btdevicedialogplugin/docml/bt-more-devices-dialog.docml	Wed Aug 18 09:59:05 2010 +0300
@@ -3,10 +3,11 @@
     <object name="moreaction" type="HbAction">
         <enums name="softKeyRole" value="NoSoftKey"/>
         <string locid="txt_bt_button_more_devices" name="text"/>
-        <string name="toolTip" value="txt_bt_button_more_devices"/>
+        <string locid="txt_bt_button_more_devices" name="toolTip"/>
     </object>
     <object name="cancelaction" type="HbAction">
         <string locid="txt_common_button_cancel" name="text"/>
+        <string locid="txt_common_button_cancel" name="toolTip"/>
     </object>
     <widget name="lastuseddialog" type="HbDialog">
         <rect height="68.20896un" name="geometry" width="49.73134un" x="1.73134un" y="11.64179un"/>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/bluetoothengine/btnotif/btdevicedialogplugin/docml/bt-receive-done-dialog.docml	Wed Aug 18 09:59:05 2010 +0300
@@ -0,0 +1,63 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<hbdocument version="1.1">
+    <object name="showaction" type="HbAction">
+        <string locid="txt_common_button_show" name="iconText"/>
+        <string locid="txt_common_button_show" name="text"/>
+        <string locid="txt_common_button_show" name="toolTip"/>
+    </object>
+    <object name="cancelaction" type="HbAction">
+        <string locid="txt_common_button_cancel" name="iconText"/>
+        <string locid="txt_common_button_cancel" name="text"/>
+        <string locid="txt_common_button_cancel" name="toolTip"/>
+    </object>
+    <widget name="recvCompleteddialog" type="HbDialog">
+        <rect height="37.46269un" name="geometry" width="49.73134un" x="1.49254un" y="36.26866un"/>
+        <widget name="heading" role="HbDialog:headingWidget" type="HbLabel">
+            <real name="z" value="1"/>
+            <string name="plainText"/>
+        </widget>
+        <widget name="container" role="HbDialog:contentWidget" type="HbWidget">
+            <widget name="filecontainer" type="HbWidget">
+                <widget name="fileiconlabel" type="HbLabel">
+                    <enums name="alignment" value="AlignVCenter|AlignHCenter"/>
+                    <icon iconName="qtg_small_smiley_very_cool" name="icon"/>
+                    <real name="z" value="1"/>
+                </widget>
+                <widget name="fileSize" type="HbLabel">
+                    <real name="z" value="3"/>
+                    <sizehint height="4.02985un" type="PREFERRED" width="24.32836un"/>
+                    <string name="plainText"/>
+                </widget>
+                <widget name="fileName" type="HbLabel">
+                    <real name="z" value="4"/>
+                    <sizehint height="4.1791un" type="PREFERRED" width="35.07463un"/>
+                    <string name="plainText"/>
+                </widget>
+                <real name="z" value="0"/>
+                <sizehint height="9.8806un" type="PREFERRED" width="23.8806un"/>
+                <layout type="anchor">
+                    <anchoritem dst="fileiconlabel" dstEdge="LEFT" spacing="1.04478un" src="" srcEdge="LEFT"/>
+                    <anchoritem dst="fileiconlabel" dstEdge="BOTTOM" spacing="-0.71767un" src="" srcEdge="BOTTOM"/>
+                    <anchoritem dst="fileSize" dstEdge="LEFT" spacing="9.30448un" src="" srcEdge="LEFT"/>
+                    <anchoritem dst="fileSize" dstEdge="BOTTOM" spacing="-0.26991un" src="" srcEdge="BOTTOM"/>
+                    <anchoritem dst="fileName" dstEdge="LEFT" spacing="9.30448un" src="" srcEdge="LEFT"/>
+                    <anchoritem dst="fileName" dstEdge="TOP" spacing="0.44776un" src="" srcEdge="TOP"/>
+                </layout>
+            </widget>
+            <widget name="fileCount_label" type="HbLabel">
+                <enums name="alignment" value="AlignVCenter|AlignHCenter"/>
+                <string name="plainText"/>
+            </widget>
+            <real name="z" value="2"/>
+            <layout orientation="Vertical" type="linear">
+                <linearitem itemname="filecontainer"/>
+                <linearitem itemname="fileCount_label"/>
+            </layout>
+        </widget>
+        <ref object="showaction" role="HbWidget:addAction"/>
+        <ref object="cancelaction" role="HbWidget:addAction"/>
+    </widget>
+    <metadata activeUIState="Common ui state" display="NHD-3.2-inch_portrait" unit="un">
+        <uistate name="Common ui state" sections="#common"/>
+    </metadata>
+</hbdocument>
--- a/bluetoothengine/btnotif/btdevicedialogplugin/docml/bt-send-dialog.docml	Tue Jul 06 14:27:09 2010 +0300
+++ b/bluetoothengine/btnotif/btdevicedialogplugin/docml/bt-send-dialog.docml	Wed Aug 18 09:59:05 2010 +0300
@@ -1,6 +1,7 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <hbdocument version="1.1">
     <object name="hideaction" type="HbAction">
+        <bool name="enabled" value="FALSE"/>
         <string locid="txt_common_button_hide" name="text"/>
     </object>
     <object name="cancelaction" type="HbAction">
@@ -12,8 +13,8 @@
             <real name="z" value="1"/>
             <string name="plainText" value="Sending File x/y to Device"/>
         </widget>
+        <ref object="hideaction" role="HbWidget:addAction"/>
         <ref object="cancelaction" role="HbWidget:addAction"/>
-        <ref object="hideaction" role="HbWidget:addAction"/>
         <widget name="container" role="HbDialog:contentWidget" type="HbWidget">
             <widget name="filecontainer" type="HbWidget">
                 <widget name="fileiconlabel" type="HbLabel">
--- a/bluetoothengine/btnotif/btdevicedialogplugin/inc/btdevicedialogrecvquerywidget.h	Tue Jul 06 14:27:09 2010 +0300
+++ b/bluetoothengine/btnotif/btdevicedialogplugin/inc/btdevicedialogrecvquerywidget.h	Wed Aug 18 09:59:05 2010 +0300
@@ -16,8 +16,8 @@
 */
 
 
-#ifndef BTDEVICEDIALOGRECVQUERYWIDGET_H_
-#define BTDEVICEDIALOGRECVQUERYWIDGET_H_
+#ifndef BTDEVICEDIALOGRECVQUERYWIDGET_H
+#define BTDEVICEDIALOGRECVQUERYWIDGET_H
 
 #include <QObject>
 #include <QVariantMap>
@@ -74,4 +74,4 @@
     Q_DISABLE_COPY(BTRecvQueryDialogWidget)
     };
 
-#endif /* BTDEVICEDIALOGRECVQUERYWIDGET_H_ */
+#endif /* BTDEVICEDIALOGRECVQUERYWIDGET_H */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/bluetoothengine/btnotif/btdevicedialogplugin/inc/btdevicedialogutils.h	Wed Aug 18 09:59:05 2010 +0300
@@ -0,0 +1,60 @@
+/*
+ * Copyright (c) 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""
+ * which accompanies this distribution, and is available
+ * at the URL "http://www.eclipse.org/legal/epl-v10.html".
+ *
+ * Initial Contributors:
+ * Nokia Corporation - initial contribution.
+ *
+ * Contributors:
+ *
+ * Description:  
+ *
+ */
+
+#ifndef BTDEVICESDIALOGUTILS_H
+#define BTDEVICESDIALOGUTILS_H
+
+#include <QMap>
+#include <QList>
+#include <QVariant>
+
+// A data item in this model DLL. For example, power state item consists 
+// of the information regarding the current Bluetooth power state.
+typedef QMap< int, QVariant > BtSendDataItem;
+
+// A category of the model data for specific group
+typedef QList< BtSendDataItem > BtSendDataSource;
+
+
+Q_DECLARE_METATYPE(BtSendDataItem)
+Q_DECLARE_METATYPE(BtSendDataSource)
+
+enum DevDataRole {
+    NameAliasRole = Qt::DisplayRole, // QVariant::String, the name showing in UI
+    ReadableBdaddrRole = Qt::UserRole, // QString, the readable format of a BD_ADDR (BT Device address)
+    MajorPropertyRole,  // QVariant::Int, bits of DevMajorProperty
+    MinorPropertyRole,  // QVariant::Int, bits of DevMinorProperty
+    CoDRole,  // QVariant::Int, the value of Class of Device
+    DeviceTypeRole //QVairant::Int, the value of Device Type
+};
+
+
+inline void setMajorProperty(
+        BtSendDataItem& qtdev, int prop, bool addto)
+{
+    if ( addto ) {
+         qtdev[MajorPropertyRole] = 
+            QVariant( qtdev[MajorPropertyRole].toInt() | prop);
+    }
+    else {
+         qtdev[MajorPropertyRole] = 
+            QVariant( qtdev[MajorPropertyRole].toInt() & ~prop);
+    }
+}
+
+
+#endif /*BTDEVICESDIALOGUTILS_H*/
--- a/bluetoothengine/btnotif/btdevicedialogplugin/inc/btdevicesearchdialogwidget.h	Tue Jul 06 14:27:09 2010 +0300
+++ b/bluetoothengine/btnotif/btdevicedialogplugin/inc/btdevicesearchdialogwidget.h	Wed Aug 18 09:59:05 2010 +0300
@@ -30,14 +30,17 @@
 #include <hblistwidget.h>
 #include <hblabel.h>
 #include <hbaction.h>
+#include <hbselectiondialog.h>
+#include "btdevicedialogutils.h"
 
 
-struct device
+
+/*struct device
     {
     QString mDeviceName;
     QString mDeviceType;
     int     mDeviceIdx;
-    };
+    };*/
 
 
 class BTDeviceSearchDialogWidget : public QObject,
@@ -67,11 +70,15 @@
     
 private:
     bool constructDialog(const QVariantMap &parameters);
-    void hideEvent(QHideEvent *event);
-    void showEvent(QShowEvent *event);
-    void appendToDeviceList(const QString deviceName);
-    bool appendToDeviceTypeList(const QString deviceType);
-    QIcon icon();
+    
+private:
+    enum devTypeSelectionList {
+        BtUiDevAudioDevice = 0,
+        BtUiDevComputer,
+        BtUiDevInputDevice,
+        BtUiDevPhone,
+        BtUiDevOtherDevice
+    };    
     
 signals:
     void deviceDialogClosed();
@@ -86,25 +93,30 @@
      */
     
     QStandardItemModel* mContentItemModel;
-    HbDialog*           mViewByDialog;
-    HbRadioButtonList*  mRbl;
-    QList<QString>      mDeviceTypeList;
-    QList<device>       mDeviceList;
+    
+    HbSelectionDialog *mQuery;
+//    QList<QString>      mDeviceTypeList;
+    QStringList mDevTypeList;
+//    QList<device>       mDeviceList;
     HbListView*         mListView;
     HbLabel*            mSearchLabel; 
     HbLabel*            mSearchIconLabel;
     HbLabel*            mSearchDoneLabel;
-    bool                mViewByChosen;
-    QList<device>       mDeviceLstOfType;
-    int                 mDeviceLstIdx;
-    int                 mSelectedType;
-    int                 mDeviceDialogData;
+//    bool                mViewByChosen;
+//    QList<device>       mDeviceLstOfType;
+//    int                 mDeviceLstIdx;
+    int                 mSelectedDeviceType;
+//    int                 mDeviceDialogData;
     HbDialog *mSearchDevicesDialog;
     HbAction *mStopRetryAction;
-    HbAction *mViewByAction;
+    HbAction *mShowAction;
+    HbAction *mCancelAction;
 
     int mStopRetryFlag;
     
+    BtSendDataSource mData;
+    BtSendDataSource mSelectedData;
+    
     Q_DISABLE_COPY(BTDeviceSearchDialogWidget)
     };
 
--- a/bluetoothengine/btnotif/btdevicedialogplugin/inc/btmoredevicesdialogwidget.h	Tue Jul 06 14:27:09 2010 +0300
+++ b/bluetoothengine/btnotif/btdevicedialogplugin/inc/btmoredevicesdialogwidget.h	Wed Aug 18 09:59:05 2010 +0300
@@ -19,6 +19,7 @@
 #ifndef BTMOREDEVICESDIALOGWIDGET_H
 #define BTMOREDEVICESDIALOGWIDGET_H
 
+#include "btdevicedialogutils.h"
 #include <QObject>
 #include <QVariantMap>
 #include <hbdialog.h>
@@ -54,6 +55,8 @@
  //   void hideEvent(QHideEvent *event);
  //   void showEvent(QShowEvent *event);
     QIcon icon(/*QString deviceType*/);
+ //   void setMajorProperty(
+//           BtSendDataItem& qtdev, int prop, bool addto);
     
 signals:
     void deviceDialogClosed();
@@ -73,6 +76,8 @@
     
     QStandardItemModel* mContentItemModel;
     
+    BtSendDataSource mData;
+    
     Q_DISABLE_COPY(BTMoreDevicesDialogWidget)
     };
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/bluetoothengine/btnotif/btdevicedialogplugin/inc/btrecvcompleteddialogwidget.h	Wed Aug 18 09:59:05 2010 +0300
@@ -0,0 +1,89 @@
+/*
+* Copyright (c) 2009 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"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description:  BtDeviceDialogWidget class declaration.
+*
+*/
+
+
+#ifndef BTRECVCOMPLETEDDIALOGWIDGET_H_
+#define BTRECVCOMPLETEDDIALOGWIDGET_H_
+
+#include <QObject>
+#include <QVariantMap>
+#include <hbdialog.h>
+#include <hbdevicedialoginterface.h>
+#include <hbpopup.h>
+#include <hbdocumentloader.h>
+#include <qstandarditemmodel.h>
+#include <hblabel.h>
+#include <hbaction.h>
+#include <QRunnable>
+
+
+class CoversationViewServiceStarter : public QRunnable
+    {
+public:
+    CoversationViewServiceStarter(qint64 conversationId);
+    ~CoversationViewServiceStarter();
+    void run();
+private:
+    qint64 mCnvId;
+    };
+
+
+class BTRecvcompletedDialogWidget : public QObject, 
+                                public HbDeviceDialogInterface
+    {
+    Q_OBJECT
+    
+public:
+    BTRecvcompletedDialogWidget(const QVariantMap &parameters);
+    ~BTRecvcompletedDialogWidget();
+    
+public: // from HbDeviceDialogInterface
+    bool setDeviceDialogParameters(const QVariantMap &parameters);
+    int deviceDialogError() const;
+    void closeDeviceDialog(bool byClient);
+    HbPopup *deviceDialogWidget() const;
+    virtual QObject *signalSender() const;
+    
+public slots:
+    void showClicked();
+    void cancelClicked();
+
+private:
+    bool constructDialog(const QVariantMap &parameters);
+    
+signals:
+    void deviceDialogClosed();
+    void deviceDialogData(QVariantMap data);
+    
+private:
+    HbDocumentLoader    *mLoader;
+    QStandardItemModel  *mContentItemModel;
+    HbLabel             *mHeading;
+    HbLabel             *mFileName;
+    HbLabel             *mFileSize;
+    HbLabel             *mFileCount;
+    HbAction            *mShow;
+    HbAction            *mCancel;
+    HbDialog            *mDialog;
+    int                 mFileSz;
+    
+    Q_DISABLE_COPY(BTRecvcompletedDialogWidget)
+    };
+
+
+
+#endif /* BTRECVCOMPLETEDDIALOGWIDGET_H_ */
--- a/bluetoothengine/btnotif/btdevicedialogplugin/inc/btrecvprgrsdialogwidget.h	Tue Jul 06 14:27:09 2010 +0300
+++ b/bluetoothengine/btnotif/btdevicedialogplugin/inc/btrecvprgrsdialogwidget.h	Wed Aug 18 09:59:05 2010 +0300
@@ -15,8 +15,8 @@
 *
 */
 
-#ifndef BTRECVPRGRSDIALOGWIDGET_H_
-#define BTRECVPRGRSDIALOGWIDGET_H_
+#ifndef BTRECVPRGRSDIALOGWIDGET_H
+#define BTRECVPRGRSDIALOGWIDGET_H
 
 #include <QObject>
 #include <QVariantMap>
@@ -73,4 +73,4 @@
     Q_DISABLE_COPY(BTRecvPrgrsDialogWidget)
     };
 
-#endif /* BTRECVPRGRSDIALOGWIDGET_H_ */
+#endif /* BTRECVPRGRSDIALOGWIDGET_H */
--- a/bluetoothengine/btnotif/btdevicedialogplugin/src/btdevicedialogplugin.cpp	Tue Jul 06 14:27:09 2010 +0300
+++ b/bluetoothengine/btnotif/btdevicedialogplugin/src/btdevicedialogplugin.cpp	Wed Aug 18 09:59:05 2010 +0300
@@ -31,6 +31,7 @@
 #include "btmoredevicesdialogwidget.h"
 #include "btsenddialogwidget.h"
 #include "btdevicedialogrecvquerywidget.h"
+#include "btrecvcompleteddialogwidget.h"
 #include <hbtranslator.h>
 
 Q_EXPORT_PLUGIN2(btdevicedialogplugin, BtDeviceDialogPlugin)
@@ -206,7 +207,7 @@
             break;
         case TBluetoothDialogParams::EQuery:
             deviceDialog =
-                new BtDeviceDialogQueryWidget(HbMessageBox::MessageTypeQuestion, parameters);
+                new BtDeviceDialogQueryWidget(HbMessageBox::MessageTypeWarning,parameters);
             break;
         case TBluetoothDialogParams::EInput:
             deviceDialog = new BtDeviceDialogInputWidget(parameters);
@@ -229,6 +230,9 @@
         case TBluetoothDialogParams::EReceiveProgress:
             deviceDialog = new BTRecvPrgrsDialogWidget(parameters);
             break;
+        case TBluetoothDialogParams::EReceiveDone:
+            deviceDialog = new BTRecvcompletedDialogWidget(parameters);
+            break;
         default:
             d->mError = UnknownDeviceDialogError;
             break;
--- a/bluetoothengine/btnotif/btdevicedialogplugin/src/btdevicedialogquerywidget.cpp	Tue Jul 06 14:27:09 2010 +0300
+++ b/bluetoothengine/btnotif/btdevicedialogplugin/src/btdevicedialogquerywidget.cpp	Wed Aug 18 09:59:05 2010 +0300
@@ -35,7 +35,6 @@
     mLastError = NoError;
     mShowEventReceived = false;
     mMessageBox = new HbMessageBox(type);
-    
     resetProperties();
     constructQueryDialog(parameters);
     TRACE_EXIT
@@ -129,7 +128,7 @@
         mLastError = UnknownDeviceDialogError;
         return;
     }
-    title = QString(hbTrId("txt_bt_title_pairing_with_1"));
+
     param = parameters.value( keyStr );
     int key = param.toInt();
     switch ( key ) {
@@ -139,7 +138,12 @@
         case EPasskeyDisplay:
             prompt = QString( hbTrId( "txt_bt_info_enter_the_following_code_to_the_1" ) );
             break;
-        // Note dialogs, but not Notification dialogs
+        case EPairingFailureRetry:
+            prompt = QString( hbTrId( "txt_bt_info_pairing_with_1_failed_either_the_pas" ) );
+            break;
+        case EPairingFailureOk:
+            prompt = QString( hbTrId( "txt_bt_info_unable_to_pair_with_1" ) );
+            break;
         // Input dialogs
         case EPinInput:
         case EObexPasskeyInput:
@@ -154,18 +158,41 @@
     if ( repls > 0 ) {
         name = parameters.value( QString::number( TBluetoothDeviceDialog::EDeviceName ) );
         prompt = prompt.arg( name.toString() );
-        addval = parameters.value( QString::number( TBluetoothDeviceDialog::EAdditionalDesc ) );
-        // todo: Formating the prompt need to be discussed with UI designer
-        // The passcode could be displayed on a separate row if it the label did support
-        // the use of newline escape character.
-        prompt.append(tr(" "));
-        prompt.append(addval.toString());
+        if(key != EPairingFailureRetry && key != EPairingFailureOk)
+            {
+            addval = parameters.value( QString::number( TBluetoothDeviceDialog::EAdditionalDesc ) );
+            // todo: Formating the prompt need to be discussed with UI designer
+            // The passcode could be displayed on a separate row if it the label did support
+            // the use of newline escape character.
+            prompt.append(tr("\n\n")); // insert 2 newlines for clarity
+            prompt.append(addval.toString());
+            if(key == EPasskeyDisplay)
+                {
+                prompt.append("\n");   
+                }
+            }
     }
-    title = title.arg(name.toString());
     // set property value to this dialog widget
-    mMessageBox->setHeadingWidget(new HbLabel(title));
+    if(key != EPairingFailureRetry && key != EPairingFailureOk)
+        {
+        title = QString(hbTrId("txt_bt_title_pairing_with_1"));
+        title = title.arg(name.toString());
+        mMessageBox->setHeadingWidget(new HbLabel(title));
+        mMessageBox->setIconVisible(false);
+        mMessageBox->setStandardButtons( HbMessageBox::Yes | HbMessageBox::No);
+        }
+    else
+        {
+        if(key == EPairingFailureRetry)
+            {
+            mMessageBox->setStandardButtons( HbMessageBox::Retry | HbMessageBox::Cancel);
+            }
+        else
+            {
+            mMessageBox->setStandardButtons( HbMessageBox::Ok);
+            }
+        }
     mMessageBox->setText( prompt );
-    mMessageBox->setIconVisible(false);
     TRACE_EXIT
 }
 
--- a/bluetoothengine/btnotif/btdevicedialogplugin/src/btdevicesearchdialogwidget.cpp	Tue Jul 06 14:27:09 2010 +0300
+++ b/bluetoothengine/btnotif/btdevicedialogplugin/src/btdevicesearchdialogwidget.cpp	Wed Aug 18 09:59:05 2010 +0300
@@ -20,13 +20,16 @@
 
 #include <hblistview.h>
 #include <hbtoolbar.h>
-#include <hbselectiondialog.h>
+
 
 #include <qstandarditemmodel.h>
 #include <hbaction.h>
 #include <xqconversions.h>
 #include <qtranslator.h>
 #include <qcoreapplication.h>
+#include <bluetoothdevicedialogs.h>
+#include <btuidevtypemap.h>
+#include <btuiiconutil.h>
 
 const char* DOCML_BTDEV_SEARCH_DIALOG = ":/docml/bt-device-search-dialog.docml";
 
@@ -39,13 +42,19 @@
 
 BTDeviceSearchDialogWidget::BTDeviceSearchDialogWidget(const QVariantMap &parameters)
     {
-    mDeviceLstIdx = 0;
-    mViewByChosen = false;
-    mSelectedType = 0;
-    mDeviceDialogData = 0;
+//    mDeviceLstIdx = 0;
+//    mViewByChosen = false;
+    mSelectedDeviceType = 0;
+ //   mDeviceDialogData = 0;
     mLoader = 0;
     mContentItemModel = 0;
     mStopRetryFlag = 0; // Stop 
+    mQuery = 0;
+    mSelectedDeviceType |= (BtuiDevProperty::AVDev | BtuiDevProperty::Computer |
+            BtuiDevProperty::Phone | BtuiDevProperty::Peripheral |
+            BtuiDevProperty::LANAccessDev | BtuiDevProperty::Toy |
+            BtuiDevProperty::WearableDev | BtuiDevProperty::ImagingDev |
+            BtuiDevProperty::HealthDev | BtuiDevProperty::UncategorizedDev);       
     constructDialog(parameters);
     }
 
@@ -53,6 +62,9 @@
     {
     delete mLoader;
     delete mContentItemModel;
+    if ( mQuery ) {
+        delete mQuery;
+    }
     
  //   delete mRbl;
  //   delete mViewByDialog;
@@ -62,6 +74,7 @@
     {
     if(parameters.keys().at(0).compare("Search Completed")==0)
         {
+        mStopRetryFlag = 1; // Retry 
         mSearchLabel->hide();
         
         mSearchIconLabel->hide();
@@ -75,43 +88,40 @@
         }
     else
         {
-        device newDevice;
+        double cod  = parameters.value(QString::number(TBluetoothDeviceDialog::EDeviceClass)).toDouble();
+        int uiMajorDevice;
+        int uiMinorDevice;
     
-       // newDevice.mDeviceName = parameters.value("deviceName").toString();
-        newDevice.mDeviceName = parameters.value(parameters.keys().at(0)).toString();
-        
-     //   newDevice.mDeviceType = parameters.value("deviceType").toString();
-        newDevice.mDeviceIdx = mDeviceLstIdx;
-        
-        mDeviceList.append(newDevice);
-        mDeviceLstIdx++;
-    
-        QStringList info;
-     //   if(!mViewByChosen)
-            {
-            info.append(newDevice.mDeviceName);
-       //     info.append(newDevice.mDeviceType);
-            QStandardItem* listitem = new QStandardItem();
-            listitem->setData(info, Qt::DisplayRole);
+        BtuiDevProperty::mapDeiveType(uiMajorDevice, uiMinorDevice, cod);
+
+        BtSendDataItem devData;
+        devData[NameAliasRole] = QVariant(parameters.value(QString::number(TBluetoothDeviceDialog::EDeviceName)).toString());
+        devData[ReadableBdaddrRole] = QVariant(parameters.value(QString::number(TBluetoothDialogParams::EAddress)).toString());
+        devData[CoDRole] = QVariant(cod);
+        devData[DeviceTypeRole] = QVariant(uiMajorDevice);
+        setMajorProperty(devData,BtuiDevProperty::Bonded,
+                parameters.value("Bonded").toBool());
+        setMajorProperty(devData,BtuiDevProperty::Blocked,
+                parameters.value("Blocked").toBool());
+        setMajorProperty(devData,BtuiDevProperty::Trusted,
+                parameters.value("Trusted").toBool());
+        setMajorProperty(devData,BtuiDevProperty::Connected,
+                parameters.value("Connected").toBool());
+        mData.append(devData);
         
-            listitem->setIcon(icon());
-        
-            mContentItemModel->appendRow(listitem);
-            }
-     /*   else
+        if(mSelectedDeviceType & devData[DeviceTypeRole].toInt())
             {
-            if(mDeviceTypeList[mSelectedType] == newDevice.mDeviceType)
-                {
-                info.append(newDevice.mDeviceName);
-                info.append(newDevice.mDeviceType);
-                QStandardItem* listitem = new QStandardItem();
-                listitem->setData(info, Qt::DisplayRole);
-    
-                listitem->setIcon(icon(newDevice.mDeviceType));
-    
-                mContentItemModel->appendRow(listitem);
-                }
-            }*/
+            QStandardItem* listitem = new QStandardItem();
+            QStringList info;
+            info.append(devData[NameAliasRole].toString());
+            listitem->setData(info, Qt::DisplayRole);
+            HbIcon icon =  getBadgedDeviceTypeIcon(devData[CoDRole].toDouble(),
+                    devData[MajorPropertyRole].toInt(),
+                    BtuiBottomLeft | BtuiBottomRight | BtuiTopLeft | BtuiTopRight);
+            listitem->setIcon(icon.qicon());
+            mContentItemModel->appendRow(listitem);    
+            mSelectedData.append(devData);
+            }
         }
                 
     return true;
@@ -168,7 +178,7 @@
         mSearchLabel->setPlainText(LOC_SEARCHING_DEVICE);
  
         mSearchIconLabel = qobject_cast<HbLabel*>(mLoader->findWidget("iconLabel"));
-        mSearchIconLabel->setIcon(icon());
+        mSearchIconLabel->setIcon(QIcon(QString(":/icons/qtg_large_bluetooth.svg")));
 
         mSearchDoneLabel = qobject_cast<HbLabel*>(mLoader->findWidget("searchDoneLabel"));
         mSearchDoneLabel->hide();
@@ -190,13 +200,16 @@
  //       connect(mStopRetryBtn, SIGNAL(clicked()), this, SLOT(stopRetryClicked()));
  //       connect(mViewByBtn, SIGNAL(clicked()), this, SLOT(viewByClicked()));
         
-        mViewByAction = static_cast<HbAction*>( mLoader->findObject( "viewaction" ) );
-        mViewByAction->disconnect(mSearchDevicesDialog);
+        mShowAction = static_cast<HbAction*>( mLoader->findObject( "viewaction" ) );
+        mShowAction->disconnect(mSearchDevicesDialog);
         
         mStopRetryAction = static_cast<HbAction*>( mLoader->findObject( "stopretryaction" ) );
         mStopRetryAction->disconnect(mSearchDevicesDialog);
         
-        connect(mViewByAction, SIGNAL(triggered()), this, SLOT(viewByClicked()));
+//        mCancelAction = static_cast<HbAction*>( mLoader->findObject( "cancelaction" ) );
+//        mCancelAction->disconnect(mSearchDevicesDialog);
+        
+        connect(mShowAction, SIGNAL(triggered()), this, SLOT(viewByClicked()));
         connect(mStopRetryAction, SIGNAL(triggered()), this, SLOT(stopRetryClicked()));
 
         connect(mSearchDevicesDialog, SIGNAL(aboutToClose()), this, SLOT(searchDialogClosed()));
@@ -205,10 +218,16 @@
         //setContentWidget(widget);
         }
     mSearchDevicesDialog->setBackgroundFaded(false);
-    mSearchDevicesDialog->setDismissPolicy(HbPopup::TapOutside);
+    mSearchDevicesDialog->setDismissPolicy(HbPopup::NoDismiss);
     mSearchDevicesDialog->setTimeout(HbPopup::NoTimeout);
     mSearchDevicesDialog->setAttribute(Qt::WA_DeleteOnClose);
     
+    mDevTypeList << hbTrId("txt_bt_list_audio_devices")
+            << hbTrId("txt_bt_list_computers") 
+            << hbTrId("txt_bt_list_input_devices") 
+            << hbTrId("txt_bt_list_phones") 
+            << hbTrId("txt_bt_list_other_devices");
+    
  /*   mViewByDialog = new HbDialog();
     mRbl = new HbRadioButtonList(mViewByDialog);
     connect(mRbl, SIGNAL(itemSelected(int)), this, SLOT(viewByItemSelected(int)));*/
@@ -216,20 +235,6 @@
     return true;
     }
 
-/*void BTDeviceSearchDialogWidget::hideEvent(QHideEvent *event)
-    {
- //   HbDialog::hideEvent(event);
-    QVariantMap val;
-    QVariant index(-1);
-    val.insert("selectedindex",index);
-    emit deviceDialogData(val);    
-    emit deviceDialogClosed();
-    }
-
-void BTDeviceSearchDialogWidget::showEvent(QShowEvent *event)
-    {
- //   HbDialog::showEvent(event);
-    }*/
 
 void BTDeviceSearchDialogWidget::stopRetryClicked()
     {
@@ -249,7 +254,7 @@
         mSearchLabel->setAlignment(Qt::AlignHCenter);
         mSearchLabel->setPlainText(LOC_SEARCHING_DEVICE);
         
-        mSearchIconLabel->setIcon(icon());     
+        mSearchIconLabel->setIcon(QIcon(QString(":/icons/qtg_large_bluetooth.svg")));     
         mSearchLabel->show();
         
         mSearchIconLabel->show();
@@ -292,58 +297,27 @@
 
 void BTDeviceSearchDialogWidget::viewByClicked()
     {
-    QStringList list;
-    list << "Select all" << "Audio devices" << "Computers" << "Input devices" << "Phones" << "Other devices";
-
-    HbSelectionDialog *query = new HbSelectionDialog;
-    query->setStringItems(list);
-    query->setSelectionMode(HbAbstractItemView::MultiSelection);
-
-    QList<QVariant> current;
-    current.append(QVariant(0));
-    query->setSelectedItems(current);
-
-    query->setAttribute(Qt::WA_DeleteOnClose);
-
-    query->open(this,SLOT(selectionDialogClosed(HbAction*)));
+    
+    if ( !mQuery ) {
+        mQuery = new HbSelectionDialog;
+        mQuery->setStringItems(mDevTypeList, 0);
+        mQuery->setSelectionMode(HbAbstractItemView::MultiSelection);
     
-    //connect(query, SIGNAL(finished(HbAction*)), this, SLOT(selectionDialogClosed(HbAction*)));
-    
-/*    mViewByDialog->setDismissPolicy(HbPopup::NoDismiss);
-    mViewByDialog->setTimeout(HbPopup::NoTimeout);
+        QList<QVariant> current;
+        current.append(QVariant(0));
+        mQuery->setSelectedItems(current);
+ 
+        //todo need to check whether the dialog is destroyed without setting this flag
+        //if not destoryed then set this flag in the destructor and then delete it
+        
+//        mQuery->setAttribute(Qt::WA_DeleteOnClose);
+        // Set the heading for the dialog.
+        HbLabel *headingLabel = new HbLabel(hbTrId("txt_bt_title_show"), mQuery);
+        mQuery->setHeadingWidget(headingLabel);
+    }
+    mQuery->open(this,SLOT(selectionDialogClosed(HbAction*)));
 
-    bool foundEntry = false;
-    QStringList st;
-    st << "All";
-    mDeviceTypeList.clear();
-    for(int i = 0; i < mDeviceList.count(); i++)
-        {
-        for(int j = 0; j < mDeviceTypeList.count(); j++)
-            {
-            if(mDeviceTypeList[j] == mDeviceList[i].mDeviceType)
-                {
-                foundEntry = true;
-                break;
-                }
-            }
-        if(!foundEntry)
-            {
-            mDeviceTypeList.append(mDeviceList[i].mDeviceType);
-            }
-        foundEntry = false;
-        }
-    
-    for(int k = 0; k < mDeviceTypeList.count(); k++)
-        {
-        st << mDeviceTypeList[k];
-        }
-    
-    mRbl->setItems(st);
-    mViewByDialog->setContentWidget(mRbl);
-    mViewByDialog->setMaximumHeight(300);
-    mViewByDialog->setMaximumWidth(500);
-
-    mViewByDialog->show();*/
+     
     }
 
 void BTDeviceSearchDialogWidget::searchDialogClosed() 
@@ -358,6 +332,49 @@
 void BTDeviceSearchDialogWidget::selectionDialogClosed(HbAction* action)
     {
     Q_UNUSED(action);
+    
+    disconnect( mQuery ); 
+    int devTypesWanted = 0;
+
+    if (action == mQuery->actions().first()) {  // user pressed "Ok"
+        // Get selected items.
+        QList<QVariant> selections;
+        selections = mQuery->selectedItems();
+        
+        for (int i=0; i < selections.count(); i++) {
+            switch (selections.at(i).toInt()) {
+            case BtUiDevAudioDevice:
+                devTypesWanted |= BtuiDevProperty::AVDev;
+                break;
+            case BtUiDevComputer:
+                devTypesWanted |= BtuiDevProperty::Computer;
+                break;
+            case BtUiDevInputDevice:
+                devTypesWanted |= BtuiDevProperty::Peripheral;
+                break;
+            case BtUiDevPhone:
+                devTypesWanted |= BtuiDevProperty::Phone;
+                break;
+            case BtUiDevOtherDevice:
+                devTypesWanted |= (BtuiDevProperty::LANAccessDev |
+                        BtuiDevProperty::Toy |
+                        BtuiDevProperty::WearableDev |
+                        BtuiDevProperty::ImagingDev |
+                        BtuiDevProperty::HealthDev |
+                        BtuiDevProperty::UncategorizedDev);
+                break;
+            default:
+                // should never get here
+                break;
+            }
+        }
+    }
+    else
+        {
+        devTypesWanted = mSelectedDeviceType;
+        }
+        
+    
 
  /*   HbSelectionDialog *dlg = (HbSelectionDialog*)(sender());
     if(dlg->actions().first() == action) {
@@ -365,6 +382,34 @@
      } 
     else if(dlg->actions().at(1) == action) {
      }*/
+    
+    if((devTypesWanted != mSelectedDeviceType) &&(devTypesWanted !=0))
+        {
+        mSelectedDeviceType = devTypesWanted;
+//        mViewByChosen = true;
+        delete mContentItemModel;
+        mContentItemModel = new QStandardItemModel(this);
+        mListView->setModel(mContentItemModel);
+        mSelectedData.clear();
+        for(int i=0;i<mData.count();i++)
+            {
+            const BtSendDataItem& qtdev = mData[i];
+            if(devTypesWanted & qtdev[DeviceTypeRole].toInt() )
+                {
+                QStandardItem* listitem = new QStandardItem();
+                QStringList info;
+                info.append(qtdev[NameAliasRole].toString());
+    
+                listitem->setData(info, Qt::DisplayRole);
+                HbIcon icon =  getBadgedDeviceTypeIcon(qtdev[CoDRole].toDouble(),
+                        qtdev[MajorPropertyRole].toInt(),
+                         BtuiBottomLeft | BtuiBottomRight | BtuiTopLeft | BtuiTopRight);
+                listitem->setIcon(icon.qicon());
+                mContentItemModel->appendRow(listitem);        
+                mSelectedData.append(qtdev);
+                }
+            }
+        }
     }
 
 void BTDeviceSearchDialogWidget::deviceSelected(const QModelIndex& modelIndex)
@@ -382,109 +427,19 @@
         }
     
     QVariantMap val;
-    QVariant index(row);
-    val.insert("selectedindex",index);
+//    QVariant index(row);
+//    val.insert("selectedindex",index);
+    
+    const BtSendDataItem& qtdev = mSelectedData.at(row);
+    val.insert("selectedindex",QVariant(row));
+    val.insert("devicename",QVariant(qtdev[NameAliasRole]));
+    val.insert("deviceaddress",QVariant(qtdev[ReadableBdaddrRole]));
+    val.insert("deviceclass",QVariant(qtdev[CoDRole]));
+
     emit deviceDialogData(val);
 //    mDeviceDialogData = 1;//flag is to say that device dialog data is emitted required when we cancel the dialog
     //emit deviceDialogClosed();
   //  this->close();
     }
 
-//void BTDeviceSearchDialogWidget::viewByItemSelected(int index)
-  //  {
-    //  (void) index;
- /*   if(index == 0)
-        {
-        //Option 'All' selected    
-        mViewByDialog->close();
-        delete mContentItemModel;
-        mContentItemModel = new QStandardItemModel(this);
-        mListView->setModel(mContentItemModel);
-        mViewByChosen = false;
 
-        for(int i = 0; i < mDeviceList.count(); i++)
-            {        
-            QStandardItem* listitem = new QStandardItem();
-                
-            QStringList info;
-            info << mDeviceList[i].mDeviceName << mDeviceList[i].mDeviceType ;
-            listitem->setData(info, Qt::DisplayRole);
-    
-            //listitem->setIcon(icon(mDeviceList[i].mDeviceType));
-    
-            mContentItemModel->appendRow(listitem);
-            }
-        }
-    else
-        {
-        index--;
-        mSelectedType = index;
-        mViewByDialog->close();
-        
-        delete mContentItemModel;
-        mContentItemModel = new QStandardItemModel(this);
-        mListView->setModel(mContentItemModel);
-    
-        mDeviceLstOfType.clear();
-        for(int i = 0; i < mDeviceList.count(); i++)
-            {
-            if(mDeviceList[i].mDeviceType == mDeviceTypeList[index])
-                {
-                mDeviceLstOfType.append(mDeviceList[i]);
-            
-                QStandardItem* listitem = new QStandardItem();
-                
-                QStringList info;
-                info << mDeviceList[i].mDeviceName << mDeviceTypeList[index];
-                listitem->setData(info, Qt::DisplayRole);
-        
-                //listitem->setIcon(icon(mDeviceTypeList[index]));
-        
-                mContentItemModel->appendRow(listitem);
-                }
-            }
-        mViewByChosen = true;
-        }*/
- //   }
-
-QIcon BTDeviceSearchDialogWidget::icon()
-    {
- /*   if(deviceType == "Audio")
-        {
-        return (QIcon(QString(":/icons/qgn_prop_bt_audio.svg")));
-        }
-    else if(deviceType == "Car-kit")
-        {
-        return (QIcon(QString(":/icons/qgn_prop_bt_car_kit.svg")));
-        }
-    else if(deviceType == "Computer")
-        {
-        return (QIcon(QString(":/icons/qgn_prop_bt_computer.svg")));
-        }
-    else if(deviceType == "Headset")
-        {
-        return (QIcon(QString(":/icons/qgn_prop_bt_headset.svg")));
-        }
-    else if(deviceType == "Keyboard")
-        {
-        return (QIcon(QString(":/icons/qgn_prop_bt_keyboard.svg")));
-        }
-    else if(deviceType == "Mouse")
-        {
-        return (QIcon(QString(":/icons/qgn_prop_bt_mouse.svg")));
-        }
-    else if(deviceType == "Phone")
-        {
-        return (QIcon(QString(":/icons/qgn_prop_bt_phone.svg")));
-        }
-    else if(deviceType == "Printer")
-        {
-        return (QIcon(QString(":/icons/qgn_prop_bt_printer.svg")));
-        }
-    else
-        {
-        return (QIcon(QString(":/icons/qgn_prop_bt_unknown.svg")));
-        }*/
-    return QIcon(QString(":/icons/qtg_large_bluetooth.svg"));
-    }
-
--- a/bluetoothengine/btnotif/btdevicedialogplugin/src/btmoredevicesdialogwidget.cpp	Tue Jul 06 14:27:09 2010 +0300
+++ b/bluetoothengine/btnotif/btdevicedialogplugin/src/btmoredevicesdialogwidget.cpp	Wed Aug 18 09:59:05 2010 +0300
@@ -15,14 +15,17 @@
  *
  */
 
-
+#include "btmoredevicesdialogwidget.h"
 #include <hblabel.h>
 #include <hblistview.h>
 #include <hbtoolbar.h>
 #include <hbpushbutton.h>
 #include <hblistwidget.h>
 #include <qstandarditemmodel.h>
-#include "btmoredevicesdialogwidget.h"
+#include <btuidevtypemap.h>
+#include <btuiiconutil.h>
+#include <bluetoothdevicedialogs.h>
+
 
 
 const char* DOCML_BT_MORE_DEV_DIALOG = ":/docml/bt-more-devices-dialog.docml";
@@ -55,21 +58,46 @@
 
 bool BTMoreDevicesDialogWidget::setDeviceDialogParameters(const QVariantMap &parameters)
     {
-    QStandardItem* listitem = new QStandardItem();
-    QStringList info;
-   // info.append(parameters.value("deviceName").toString());
-    //info.append(parameters.value("deviceType").toString());
-    info.append(parameters.value(parameters.keys().at(0)).toString());
+    double cod  = parameters.value(QString::number(TBluetoothDeviceDialog::EDeviceClass)).toDouble();
+    int uiMajorDevice;
+    int uiMinorDevice;
+
+    BtuiDevProperty::mapDeiveType(uiMajorDevice, uiMinorDevice, cod);
+    if ((uiMajorDevice & BtuiDevProperty::Phone)||(uiMajorDevice & BtuiDevProperty::Computer) )
+        {
+        BtSendDataItem devData;
+        devData[NameAliasRole] = QVariant(parameters.value(QString::number(TBluetoothDeviceDialog::EDeviceName)).toString());
+        devData[ReadableBdaddrRole] = QVariant(parameters.value(QString::number(TBluetoothDialogParams::EAddress)).toString());
+        devData[CoDRole] = QVariant(cod);
+        
+        setMajorProperty(devData,BtuiDevProperty::Bonded,
+                parameters.value("Bonded").toBool());
+        setMajorProperty(devData,BtuiDevProperty::Blocked,
+                parameters.value("Blocked").toBool());
+        setMajorProperty(devData,BtuiDevProperty::Trusted,
+                parameters.value("Trusted").toBool());
+        setMajorProperty(devData,BtuiDevProperty::Connected,
+                parameters.value("Connected").toBool());
+        mData.append(devData);
+        
+        QStandardItem* listitem = new QStandardItem();
+        QStringList info;
+        info.append(devData[NameAliasRole].toString());
+
+        listitem->setData(info, Qt::DisplayRole);
+        HbIcon icon =  getBadgedDeviceTypeIcon(devData[CoDRole].toDouble(),
+                devData[MajorPropertyRole].toInt(),
+                BtuiBottomLeft | BtuiBottomRight | BtuiTopLeft | BtuiTopRight);        
+        listitem->setIcon(icon.qicon());
+     //   listitem->setIcon(icon(parameters.value("deviceType").toString()));
+        
+        mContentItemModel->appendRow(listitem);        
+        }
+    return true;
+    }
 
 
-    listitem->setData(info, Qt::DisplayRole);
-    listitem->setIcon(icon());
- //   listitem->setIcon(icon(parameters.value("deviceType").toString()));
-    
-    mContentItemModel->appendRow(listitem);
 
-    return true;
-    }
 
 int BTMoreDevicesDialogWidget::deviceDialogError() const
     {
@@ -213,8 +241,12 @@
     {
     int row = modelIndex.row();
     QVariantMap val;
-    QVariant index(row);
-    val.insert("selectedindex",index);
+//    QVariant index(row);
+    const BtSendDataItem& qtdev = mData.at(row);
+    val.insert("selectedindex",QVariant(row));
+    val.insert("devicename",QVariant(qtdev[NameAliasRole]));
+    val.insert("deviceaddress",QVariant(qtdev[ReadableBdaddrRole]));
+    val.insert("deviceclass",QVariant(qtdev[CoDRole]));
     emit deviceDialogData(val);
   //  mDeviceDialogData = 1;//flag is to say that device dialog data is emitted required when we cancel the dialog    
    // this->close();
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/bluetoothengine/btnotif/btdevicedialogplugin/src/btrecvcompleteddialogwidget.cpp	Wed Aug 18 09:59:05 2010 +0300
@@ -0,0 +1,202 @@
+/*
+* Copyright (c) 2009 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"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description:  BTRecvcompletedDialogWidget class declaration.
+*
+*/
+
+#include <xqaiwrequest.h>
+#include <xqappmgr.h>
+#include <QThreadPool>
+#include "btrecvcompleteddialogwidget.h"
+#include "bluetoothdevicedialogs.h"
+
+const char* DOCML_BT_RECV_CMPLTD_DIALOG = ":/docml/bt-receive-done-dialog.docml";
+const qint64 KBluetoothMsgsConversationId = 0x01;
+
+
+CoversationViewServiceStarter::CoversationViewServiceStarter(qint64 conversationId)
+:mCnvId(conversationId)
+    {
+    
+    }
+
+CoversationViewServiceStarter::~CoversationViewServiceStarter()
+    {
+    
+    }
+
+void CoversationViewServiceStarter::run()
+    {
+    QList<QVariant> args;
+    QString serviceName("com.nokia.services.hbserviceprovider");
+    QString operation("open(qint64)");
+    XQAiwRequest* request;
+    XQApplicationManager appManager;
+    request = appManager.create(serviceName, "conversationview", operation, false); // not embedded
+    if ( request == NULL )
+        {
+        return;       
+        }
+    args << QVariant(mCnvId);
+    request->setArguments(args);
+    request->send();
+    delete request;
+    }
+
+
+BTRecvcompletedDialogWidget::BTRecvcompletedDialogWidget(const QVariantMap &parameters)
+{
+    mLoader = 0;
+    constructDialog(parameters);
+}
+
+BTRecvcompletedDialogWidget::~BTRecvcompletedDialogWidget()
+{
+    if(mLoader)
+    {
+        delete mLoader;
+        mLoader = NULL;
+    }
+}
+
+bool BTRecvcompletedDialogWidget::setDeviceDialogParameters(const QVariantMap &parameters)
+{
+    return true;
+}
+
+int BTRecvcompletedDialogWidget::deviceDialogError() const
+{
+    return 0;
+}
+
+void BTRecvcompletedDialogWidget::closeDeviceDialog(bool byClient)
+{
+    Q_UNUSED(byClient);
+    mDialog->close();
+}
+
+HbPopup* BTRecvcompletedDialogWidget::deviceDialogWidget() const
+{
+    return mDialog;
+}
+
+QObject* BTRecvcompletedDialogWidget::signalSender() const
+{
+    return const_cast<BTRecvcompletedDialogWidget*>(this);
+}
+
+bool BTRecvcompletedDialogWidget::constructDialog(const QVariantMap &parameters)
+{
+    mLoader = new HbDocumentLoader();
+    bool ok = false;
+    
+    mLoader->load(DOCML_BT_RECV_CMPLTD_DIALOG, &ok);
+    if(ok)
+    {
+        mDialog = qobject_cast<HbDialog*>(mLoader->findWidget("recvCompleteddialog"));
+        mHeading = qobject_cast<HbLabel*>(mLoader->findWidget("heading"));
+        
+        mFileName = qobject_cast<HbLabel*>(mLoader->findWidget("fileName"));
+        mFileSize = qobject_cast<HbLabel*>(mLoader->findWidget("fileSize"));
+        mFileCount = qobject_cast<HbLabel*>(mLoader->findWidget("fileCount_label"));
+        mFileCount->setVisible(false);
+        
+        //TODO - set icon based on the file icon.
+        
+        mShow = qobject_cast<HbAction*>(mLoader->findObject("showaction"));
+        mCancel = qobject_cast<HbAction*>(mLoader->findObject("cancelaction"));
+        
+        QString headingStr(hbTrId("txt_bt_title_received_from_1"));
+        QString senderName(parameters.value(QString::number(TBluetoothDeviceDialog::EDeviceName)).toString());
+        mHeading->setPlainText(headingStr.arg(senderName));
+        mDialog->setHeadingWidget(mHeading);
+        
+        mFileName->setPlainText(parameters.value(QString::number(TBluetoothDeviceDialog::EReceivingFileName)).toString());
+        
+        mFileSz = parameters.value(QString::number(TBluetoothDeviceDialog::EReceivingFileSize)).toInt();
+        
+        //Format the file size into a more readable format
+        if ( mFileSz >> 20 )    // size in MB
+            {       
+            float sizeInMB = 0;
+            sizeInMB = ((float)mFileSz ) / (1024*1024);
+            QString fileSzMb;
+            fileSzMb.setNum(sizeInMB);
+            //TODO - check for localization
+            fileSzMb.append(QString(" Mb"));
+            mFileSize->setPlainText(fileSzMb);
+            }
+        
+        else if( mFileSz >> 10 )        // size in KB
+            {
+            TInt64 sizeInKB = 0;
+            sizeInKB = mFileSz >> 10;
+            QString fileSzKb;
+            fileSzKb.setNum(sizeInKB);
+            //TODO - check for localization
+            fileSzKb.append(QString(" Kb"));
+            mFileSize->setPlainText(fileSzKb);
+            }
+
+        else                              // size is unknown or less than 1K
+            {
+            QString fileSzB;
+            fileSzB.setNum(mFileSz);
+            //TODO - check for localization
+            fileSzB.append(QString(" Bytes"));
+            mFileSize->setPlainText(fileSzB);
+            }
+
+        //Set the received file count
+        int fCnt = parameters.value(QString::number(TBluetoothDeviceDialog::EReceivedFileCount)).toInt();
+        if(fCnt > 1)
+            {
+            mFileCount->setVisible(true);  
+            
+            QString fCntStr(hbTrId("txt_bt_info_ln_other_files_received", (fCnt-1)));
+            mFileCount->setPlainText(fCntStr);
+            }
+    }
+
+    mDialog->setBackgroundFaded(false);
+    mDialog->setDismissPolicy(HbPopup::NoDismiss);
+    mDialog->setTimeout(HbPopup::NoTimeout);
+     
+    connect(mShow, SIGNAL(triggered()), this, SLOT(showClicked()));
+    connect(mCancel, SIGNAL(triggered()), this, SLOT(cancelClicked()));
+    
+    return true;
+}
+
+void BTRecvcompletedDialogWidget::showClicked()
+{   
+    CoversationViewServiceStarter* service = new CoversationViewServiceStarter(KBluetoothMsgsConversationId);
+    service->setAutoDelete(true);
+    
+    QThreadPool::globalInstance()->start(service);
+          
+    QVariantMap data;
+    data.insert(QString("actionResult"), QVariant(TBluetoothDialogParams::EShow));
+    emit deviceDialogData(data);
+    emit deviceDialogClosed();
+}
+
+void BTRecvcompletedDialogWidget::cancelClicked()
+{
+    QVariantMap data;
+    data.insert(QString("actionResult"), QVariant(TBluetoothDialogParams::ECancelShow));
+    emit deviceDialogData(data);
+    emit deviceDialogClosed();
+}
+
--- a/bluetoothengine/btnotif/btdevicedialogplugin/src/btrecvprgrsdialogwidget.cpp	Tue Jul 06 14:27:09 2010 +0300
+++ b/bluetoothengine/btnotif/btdevicedialogplugin/src/btrecvprgrsdialogwidget.cpp	Wed Aug 18 09:59:05 2010 +0300
@@ -118,6 +118,7 @@
             sizeInMB = ((float)mFileSz ) / (1024*1024);
             QString fileSzMb;
             fileSzMb.setNum(sizeInMB);
+            //TODO - check for localization
             fileSzMb.append(QString(" Mb"));
             mFileSize->setPlainText(fileSzMb);
             }
@@ -128,6 +129,7 @@
             sizeInKB = mFileSz >> 10;
             QString fileSzKb;
             fileSzKb.setNum(sizeInKB);
+            //TODO - check for localization
             fileSzKb.append(QString(" Kb"));
             mFileSize->setPlainText(fileSzKb);
             }
@@ -136,6 +138,7 @@
             {
             QString fileSzB;
             fileSzB.setNum(mFileSz);
+            //TODO - check for localization
             fileSzB.append(QString(" Bytes"));
             mFileSize->setPlainText(fileSzB);
             }
@@ -146,8 +149,8 @@
             {
             mFileCount->setVisible(true);  
             
-            QString fCntStr(hbTrId("txt_bt_info_ln_files_already_received"));
-            mFileCount->setPlainText(fCntStr.arg(fCnt));
+            QString fCntStr(hbTrId("txt_bt_info_ln_files_already_received", fCnt));
+            mFileCount->setPlainText(fCntStr);
             }
     }
 
@@ -164,7 +167,7 @@
 void BTRecvPrgrsDialogWidget::hideClicked()
 {
     QVariantMap data;
-    data.insert(QString("actionResult"), QVariant(true));
+    data.insert(QString("actionResult"), QVariant(TBluetoothDialogParams::EHide));
     emit deviceDialogData(data);
     emit deviceDialogClosed();
 }
@@ -172,7 +175,7 @@
 void BTRecvPrgrsDialogWidget::cancelClicked()
 {
     QVariantMap data;
-    data.insert(QString("actionResult"), QVariant(false));
+    data.insert(QString("actionResult"), QVariant(TBluetoothDialogParams::ECancelReceive));
     emit deviceDialogData(data);
     emit deviceDialogClosed();
 }
--- a/bluetoothengine/btnotif/btdevicedialogplugin/src/btsenddialogwidget.cpp	Tue Jul 06 14:27:09 2010 +0300
+++ b/bluetoothengine/btnotif/btdevicedialogplugin/src/btsenddialogwidget.cpp	Wed Aug 18 09:59:05 2010 +0300
@@ -15,14 +15,13 @@
  *
  */
 
-
+#include "btsenddialogwidget.h"
 #include <hblabel.h>
 #include <hblistview.h>
 #include <hbtoolbar.h>
 #include <hblistwidget.h>
 #include <qstandarditemmodel.h>
 #include <hbaction.h>
-#include "btsenddialogwidget.h"
 
 
 #define LOC_SENDING_FILES_TO_DEVICE hbTrId("txt_bt_title_sending_file_l1l2_to_3")
--- a/bluetoothengine/btnotif/btnotifsrv/inc/btnotifdeviceselector.h	Tue Jul 06 14:27:09 2010 +0300
+++ b/bluetoothengine/btnotif/btnotifsrv/inc/btnotifdeviceselector.h	Wed Aug 18 09:59:05 2010 +0300
@@ -30,6 +30,7 @@
 #include <btservices/devdiscoveryobserver.h>
 #include "bluetoothnotification.h"
 #include <btservices/btdevrepository.h>
+#include <hb/hbcore/hbsymbianvariant.h>
 
 class CBTNotifServer;
 class CAdvanceDevDiscoverer;
@@ -154,7 +155,18 @@
             TBluetoothDialogParams::TBTDialogType aType,
             TBTDialogResourceId aResourceId );
 			
-	void LoadUsedDevicesL();		
+	void LoadUsedDevicesL();	
+	
+	void AddDataL(CHbSymbianVariantMap* aMap, const TDesC& aKey, const TAny* aData, 
+	        CHbSymbianVariant::TType aDataType);
+	
+	void setMajorProperty(TInt aMajorProperty, TInt prop, TBool addto);
+	
+	TBool isBonded( const CBTDevice &dev );
+	
+	CBtDevExtension* GetDeviceFromRepositoryL( const TBTDevAddr& addr );
+	
+	void SendSelectedDeviceL( CHbSymbianVariantMap& aData );
     
 private: // data    
 
@@ -176,9 +188,9 @@
     CAdvanceDevDiscoverer* iDiscoverer;
     
     /**
-     * do not own the elements in the array.
+     *  own's the elements in the array.
      */
-    RPointerArray<CBtDevExtension> iDevices;
+    RDevExtensionArray iDevices;
     
     /**
      * The message for a pending device selection request from a RNotifier client.
--- a/bluetoothengine/btnotif/btnotifsrv/inc/btnotifoutgoingpairinghandler.h	Tue Jul 06 14:27:09 2010 +0300
+++ b/bluetoothengine/btnotif/btnotifsrv/inc/btnotifoutgoingpairinghandler.h	Wed Aug 18 09:59:05 2010 +0300
@@ -23,7 +23,11 @@
 #include <e32property.h>
 #include "btnotifclientserver.h"
 #include "btnotifBasePairingHandler.h"
+#include <hb/hbcore/hbsymbianvariant.h>
+#include "btnotificationresult.h"
+#include "bluetoothdevicedialogs.h"
 
+class CBluetoothNotification;
 
 enum TBTOutgoingPairMode
     {
@@ -53,7 +57,8 @@
  *
  *  @since Symbian^4
  */
-NONSHARABLE_CLASS( CBTNotifOutgoingPairingHandler ) : public CBTNotifBasePairingHandler
+NONSHARABLE_CLASS( CBTNotifOutgoingPairingHandler ) : public CBTNotifBasePairingHandler,
+                                                      public MBTNotificationResult
     {
 
 public:
@@ -70,8 +75,36 @@
      * Destructor
      */
     ~CBTNotifOutgoingPairingHandler();
+
     
-private: // From CBTEngPairBase
+    // from base class MBTNotificationResult
+
+    /**
+     * From MBTNotificationResult.
+     * Handle an intermediate result from a user query.
+     * This function is called if the user query passes information
+     * back before it has finished i.e. is dismissed. The final acceptance/
+     * denial of a query is passed back in MBRNotificationClosed.
+     *
+     * @since Symbian^4
+     * @param aData the returned data. The actual format 
+     *              is dependent on the actual notifier.
+     */
+    virtual void MBRDataReceived( CHbSymbianVariantMap& aData );
+
+    /**
+     * From MBTNotificationResult.
+     * The notification is finished. The resulting data (e.g. user input or
+     * acceptance/denial of the query) is passed back here.
+     *
+     * @since Symbian^4
+     * @param aErr KErrNone or one of the system-wide error codes.
+     * @param aData the returned data. The actual format 
+     *              is dependent on the actual notifier.
+     */
+    virtual void MBRNotificationClosed( TInt aError, const TDesC8& aData );
+    
+private:
     
     /**
      * Start observing the result of pairing which was originated from
@@ -153,6 +186,27 @@
     void HandleError( CBtSimpleActive* aActive, TInt aError );
 
 private:
+    /**
+     * Get a notification and configure it according to the current operation.
+     *
+     * @since Symbian^4
+     * @param aType The notification type.
+     * @param aResourceId Identifier for the resource to display.
+     */
+    void PrepareNotificationL( TBluetoothDialogParams::TBTDialogType aType,
+                TBTDialogResourceId aResourceId );
+
+    /**
+     * Handle the result from a notification that is finished.
+     *
+     * @since Symbian^4
+     * @param aErr KErrNone or one of the system-wide error codes.
+     * @param aData The returned data. The actual format 
+     *              is dependent on the actual notifier.
+     */
+    void NotificationClosedL( TInt aError, const TDesC8& aData );
+
+private:
 
     /**
      * C++ default constructor
@@ -169,6 +223,16 @@
      */
     void DoPairingL();
     
+    /**
+     * Ask the user to retry pairing.
+     */    
+    void ShowPairingRetryDialog();
+    
+    /**
+     * Tell the user the pairing failed.
+     */    
+    void ShowPairingFailureDialog();
+    
 private: // data
 	
     /**
@@ -200,6 +264,17 @@
      * the current pairing mode this class is in
      */
     TBTOutgoingPairMode iPairMode;
+
+    /**
+     * Pointer to an outstanding user interaction.
+     * Not own.
+     */
+    CBluetoothNotification* iNotification;
+
+    /**
+     * Number of pairing attempt
+     */
+    TInt iPairingAttempt;
     
     };
 
--- a/bluetoothengine/btnotif/btnotifsrv/src/btnotifbasepairinghandler.cpp	Tue Jul 06 14:27:09 2010 +0300
+++ b/bluetoothengine/btnotif/btnotifsrv/src/btnotifbasepairinghandler.cpp	Wed Aug 18 09:59:05 2010 +0300
@@ -138,7 +138,7 @@
     TBTDialogResourceId resourceId = EPairingSuccess;
     if(KErrNone != aResult)
         {
-        resourceId = EPairingFailure;
+        resourceId = EPairingFailureOk;
         }
     notification->SetNotificationType( TBluetoothDialogParams::ENote, resourceId );
     const CBtDevExtension* dev = iParent.BTDevRepository().Device(iAddr);
--- a/bluetoothengine/btnotif/btnotifsrv/src/btnotifdeviceselector.cpp	Tue Jul 06 14:27:09 2010 +0300
+++ b/bluetoothengine/btnotif/btnotifsrv/src/btnotifdeviceselector.cpp	Wed Aug 18 09:59:05 2010 +0300
@@ -20,7 +20,6 @@
 #include <btservices/advancedevdiscoverer.h>
 #include <btservices/btdevextension.h>
 #include <hb/hbcore/hbdevicedialogsymbian.h>
-#include <hb/hbcore/hbsymbianvariant.h>
 #include "btnotifdeviceselector.h"
 
 #include "btnotifserver.h"
@@ -174,7 +173,7 @@
 void CBTNotifDeviceSelector::MBRDataReceived( CHbSymbianVariantMap& aData )
     {
     TInt err = KErrCancel;
-    if(aData.Keys().MdcaPoint(0).Compare(_L("selectedindex"))==KErrNone)
+    if(aData.Keys().MdcaPoint(aData.Keys().MdcaCount()-1).Compare(_L("selectedindex"))==KErrNone)
         {
         TInt val = *(static_cast<TInt*>(aData.Get(_L("selectedindex"))->Data()));
         BOstrace1( TRACE_DEBUG, TNAME_DEVLIST_2, "MBRDataReceived, val %d", val );
@@ -185,10 +184,11 @@
             TBTDeviceResponseParamsPckg devParams;    
             if (  val > -1 && val < iDevices.Count() )
                 {
-                devParams().SetDeviceAddress( iDevices[val]->Addr() );
+                TRAP(err,SendSelectedDeviceL(aData));
+             /*   devParams().SetDeviceAddress( iDevices[val]->Addr() );
                 devParams().SetDeviceClass(iDevices[val]->Device().DeviceClass());
                 devParams().SetDeviceName(iDevices[val]->Alias());
-                err = iMessage.Write( EBTNotifSrvReplySlot, devParams );
+                err = iMessage.Write( EBTNotifSrvReplySlot, devParams );*/
                 iNotification->RemoveObserver();
                 iNotification->Close(); // Also dequeues the notification from the queue.
                 iNotification = NULL;                
@@ -242,22 +242,61 @@
         const TInquirySockAddr& aAddr, const TDesC& aName )
     {
     // Todo: look for this device in repository before creating it.
-    CBtDevExtension* devext = CBtDevExtension::NewLC( aAddr, aName );
+    TBuf<KBTDevAddrSize * 2> addr; 
+    
+    
+    
+    CBtDevExtension* devext = GetDeviceFromRepositoryL(aAddr.BTAddr());
+    
+    if(!devext)
+        {
+        devext = CBtDevExtension::NewLC( aAddr, aName );
+        }
+    else
+        {
+        CleanupStack::PushL(devext);
+        }
     iDevices.AppendL( devext );
-    CleanupStack::Pop( devext );
+    CleanupStack::Pop( devext );    
     
     if(iNotification)
         {// conditional check required as CAdvanceDevDiscoverer sends discovered devices at times
          // even after canceldiscovery is issued and notification is set to NULL
          // this causes EExcDataAbort
     CHbSymbianVariantMap* map = iNotification->Data();
-        TBuf<KMaxKeyDesCLength> keyStr;
+/*    TBuf<KMaxKeyDesCLength> keyStr;
     CHbSymbianVariant* devEntry;
 
     keyStr.Num( TBluetoothDialogParams::EDialogExt + iDevices.Count() - 1 );
     devEntry = CHbSymbianVariant::NewL( (TAny*) &(devext->Alias()), 
             CHbSymbianVariant::EDes );
-    map->Add( keyStr, devEntry );
+    map->Add( keyStr, devEntry );*/
+    
+    User::LeaveIfError(iNotification->SetData(TBluetoothDeviceDialog::EDeviceName,
+            devext->Alias()));
+    
+    devext->Addr().GetReadable(addr);
+    User::LeaveIfError(iNotification->SetData(TBluetoothDialogParams::EAddress,addr));
+    
+    TInt classOfDevice;
+    classOfDevice =  devext->Device().DeviceClass().DeviceClass();
+    User::LeaveIfError(iNotification->SetData(TBluetoothDeviceDialog::EDeviceClass,classOfDevice));
+
+    TBool status;
+    status = isBonded( devext->Device());
+    
+ //   setMajorProperty(majorProperty, _L("Bonded"), isBonded( devArray[i]->Device() ));
+    AddDataL(map,_L("Bonded"),&status,CHbSymbianVariant::EBool);
+    status = devext->Device().GlobalSecurity().Banned();
+    AddDataL(map,_L("Blocked"),&status,
+            CHbSymbianVariant::EBool);
+    status = devext->Device().GlobalSecurity().NoAuthorise();
+    AddDataL(map,_L("Trusted"),&status,
+            CHbSymbianVariant::EBool);
+    status = devext->ServiceConnectionStatus() == EBTEngConnected;
+    AddDataL(map,_L("Connected"),&status,
+            CHbSymbianVariant::EBool);
+ 
     iNotification->Update();
         }
     }
@@ -371,6 +410,7 @@
 void CBTNotifDeviceSelector::LoadUsedDevicesL()
     {
     const RDevExtensionArray& devArray= iServer.DevRepository().AllDevices();
+    TBuf<KBTDevAddrSize * 2> addr; 
     for(TInt i=0; i< devArray.Count(); i++ )
         {
       const TTime& usedTime = devArray[i]->Device().Used();
@@ -381,14 +421,118 @@
             {
             iDevices.AppendL( devArray[i]->CopyL() );
             CHbSymbianVariantMap* map = iNotification->Data();
-            TBuf<KMaxKeyDesCLength> keyStr;
-            CHbSymbianVariant* devEntry;
+ //           TBuf<KMaxKeyDesCLength> keyStr;
+ //           CHbSymbianVariant* devEntry;
 
-            keyStr.Num( TBluetoothDialogParams::EDialogExt + iDevices.Count() - 1 );
-            devEntry = CHbSymbianVariant::NewL( (TAny*) &(devArray[i]->Alias()), 
-                    CHbSymbianVariant::EDes );
-            map->Add( keyStr, devEntry );
+  //          keyStr.Num( TBluetoothDialogParams::EDialogExt + iDevices.Count() - 1 );
+//            devEntry = CHbSymbianVariant::NewL( (TAny*) &(devArray[i]->Alias()), 
+  //                  CHbSymbianVariant::EDes );
+  //          map->Add( keyStr, devEntry, );
+            User::LeaveIfError(iNotification->SetData(TBluetoothDeviceDialog::EDeviceName,
+                    devArray[i]->Alias()));
+//            AddDataL(map,keyStr,&(devArray[i]->Alias()),CHbSymbianVariant::EDes);
+            devArray[i]->Addr().GetReadable(addr);
+            User::LeaveIfError(iNotification->SetData(TBluetoothDialogParams::EAddress,addr));
+            addr.Zero();
+            TInt classOfDevice;
+            classOfDevice =  devArray[i]->Device().DeviceClass().DeviceClass();
+            User::LeaveIfError(iNotification->SetData(TBluetoothDeviceDialog::EDeviceClass,classOfDevice));
+            
+            TBool status;
+            status = isBonded( devArray[i]->Device());
+            
+         //   setMajorProperty(majorProperty, _L("Bonded"), isBonded( devArray[i]->Device() ));
+            AddDataL(map,_L("Bonded"),&status,CHbSymbianVariant::EBool);
+            status = devArray[i]->Device().GlobalSecurity().Banned();
+            AddDataL(map,_L("Blocked"),&status,
+                    CHbSymbianVariant::EBool);
+            status = devArray[i]->Device().GlobalSecurity().NoAuthorise();
+            AddDataL(map,_L("Trusted"),&status,
+                    CHbSymbianVariant::EBool);
+            status = devArray[i]->ServiceConnectionStatus() == EBTEngConnected;
+            AddDataL(map,_L("Connected"),&status,
+                    CHbSymbianVariant::EBool);
+             // set blocked status:
+/*             setMajorProperty(majorProperty, BtuiDevProperty::Blocked, 
+                     devArray[i]->Device().GlobalSecurity().Banned() );
+             // set trusted status:
+             setMajorProperty(majorProperty, BtuiDevProperty::Trusted, 
+                     devArray[i]->Device().GlobalSecurity().NoAuthorise() );
+             // set connected status:
+             // EBTEngConnecting is an intermediate state between connected and not-connected, 
+             // we do not treat it as connected:         
+             setMajorProperty(majorProperty, BtuiDevProperty::Connected, devArray[i]->ServiceConnectionStatus() == EBTEngConnected);
+
+  */          
+
+ //           AddDataL(map,keyStr,&(devArray[i]->Alias()),CHbSymbianVariant::EDes);
             iNotification->Update();
             }
         }
     }
+
+
+
+/*!
+  Tells if the given device is bonded.
+*/
+TBool CBTNotifDeviceSelector::isBonded( const CBTDevice &dev )
+{
+    // todo: this has not addresses Just Works pairing mode yet.
+    return dev.IsValidPaired() && dev.IsPaired() &&
+        dev.LinkKeyType() != ELinkKeyUnauthenticatedUpgradable;
+}
+
+void CBTNotifDeviceSelector::AddDataL(CHbSymbianVariantMap* aMap, const TDesC& aKey, 
+    const TAny* aData, CHbSymbianVariant::TType aDataType)
+    {
+    CHbSymbianVariant* value = CHbSymbianVariant::NewL(aData, aDataType);
+    CleanupStack::PushL( value );
+    User::LeaveIfError( aMap->Add( aKey, value ) ); // aMap takes the ownership of value
+    CleanupStack::Pop( value );
+    }
+
+// ---------------------------------------------------------------------------
+// Tells if these two instances are for the same remote device
+// ---------------------------------------------------------------------------
+//
+TBool MatchDeviceAddress(const TBTDevAddr* aAddr, const CBtDevExtension& aDev)
+    {
+    return *aAddr == aDev.Device().BDAddr();
+    }
+
+
+CBtDevExtension* CBTNotifDeviceSelector::GetDeviceFromRepositoryL( const TBTDevAddr& aAddr ) 
+{
+    const RDevExtensionArray& devArray= iServer.DevRepository().AllDevices();
+    
+    TInt pos = devArray.Find( aAddr, MatchDeviceAddress);
+    if(pos > -1)
+        {
+        return devArray[pos]->CopyL();
+        }
+    return NULL;
+/*    addrSymbianToReadbleString( addrStr, addr );
+    for (int i = 0; i < mData.count(); ++i ) {
+        if ( mData.at( i ).value( BtDeviceModel::ReadableBdaddrRole ) 
+                == addrStr ) {
+            return i;
+        }
+    }
+    return -1;*/
+}
+
+
+void CBTNotifDeviceSelector::SendSelectedDeviceL( CHbSymbianVariantMap& aData )
+    {
+    TInt err; 
+    TBTDeviceResponseParamsPckg devParams;
+    TBTDevAddr address; 
+    User::LeaveIfError(address.SetReadable(
+                                    *(static_cast<TDesC*>(aData.Get(_L("deviceaddress"))->Data()))));
+    devParams().SetDeviceAddress( address );
+    devParams().SetDeviceClass(*(static_cast<TUint32*>(aData.Get(_L("deviceclass"))->Data())));
+    devParams().SetDeviceName(*(static_cast<TDesC*>(aData.Get(_L("devicename"))->Data())));
+    User::LeaveIfError(iMessage.Write( EBTNotifSrvReplySlot, devParams ));
+    }
+
--- a/bluetoothengine/btnotif/btnotifsrv/src/btnotifoutgoingpairinghandler.cpp	Tue Jul 06 14:27:09 2010 +0300
+++ b/bluetoothengine/btnotif/btnotifsrv/src/btnotifoutgoingpairinghandler.cpp	Wed Aug 18 09:59:05 2010 +0300
@@ -20,10 +20,21 @@
 #include <btservices/btdevextension.h>
 #include "btnotifsecuritymanager.h"
 #include "bluetoothtrace.h"
+#include "bluetoothnotification.h"
+#include "btnotifserver.h"
+#include "btnotifconnectiontracker.h"
+#include "btnotificationmanager.h"
 
 /**  Length of the default PIN. */
 const TInt KDefaultHeadsetPinLength = 4;
 
+/** Maximum repeated outgoing pairing attempt.
+ *  if the pairing fails the UI specs says
+ *  we can ask twice the user if he/she want 
+ *  to retry pairing. 
+ */
+const TInt KMaxRepeatedPairingAttempt = 2;
+
 enum TPairingStageId
     {
     /**
@@ -84,6 +95,7 @@
     {
     BaseConstructL();
     User::LeaveIfError( iTimer.CreateLocal() );
+    iPairingAttempt = KMaxRepeatedPairingAttempt;
     }
 
 // ---------------------------------------------------------------------------
@@ -113,14 +125,22 @@
     iBondingSession.Close();
     iSocket.Close();
     iTimer.Close();
+    if( iNotification )
+        {
+        // Clear the notification callback, we cannot receive them anymore.
+        iNotification->RemoveObserver();
+        iNotification->Close(); // Also dequeues the notification from the queue.
+        iNotification = NULL;
+        }
     }
 
 // ---------------------------------------------------------------------------
 // Simply deny the request as this is handing outgoing pairing
 // ---------------------------------------------------------------------------
 //
-TInt CBTNotifOutgoingPairingHandler::ObserveIncomingPair( const TBTDevAddr& /*aAddr*/ )
+TInt CBTNotifOutgoingPairingHandler::ObserveIncomingPair( const TBTDevAddr& aAddr )
     {
+    (void)aAddr;
     return KErrServerBusy;
     }
 
@@ -136,7 +156,6 @@
         // we don't allow another pairing request.
         User::Leave( KErrServerBusy );
         }
-    
     iAddr = aAddr;
     iCod = TBTDeviceClass( aCod );
     UnSetPairResult();
@@ -161,6 +180,14 @@
     {
     BOstraceFunctionEntry0( DUMMY_DEVLIST );
     iParent.RenewPairingHandler( NULL );
+    if( iNotification )
+        {
+        // Cancel the user query
+        // This will also unregister us from the notification.
+        TInt err = iNotification->Close();
+        NOTIF_NOTHANDLED( !err )
+        iNotification = NULL;
+        }
     }
 
 
@@ -185,7 +212,7 @@
         const TUint8 KZeroPinValue = '0';
         for (TInt i = 0; i < KDefaultHeadsetPinLength; ++i)
             {
-            aPin().iPIN[i] = KZeroPinValue;
+                aPin().iPIN[i] = KZeroPinValue;
             }
         aPin().iLength = KDefaultHeadsetPinLength;
         }
@@ -202,6 +229,14 @@
         {
         iParent.OutgoingPairCompleted( KErrCancel );
         iParent.RenewPairingHandler( NULL );
+        if( iNotification )
+            {
+            // Cancel the user query
+            // This will also unregister us from the notification.
+            TInt err = iNotification->Close();
+            NOTIF_NOTHANDLED( !err )
+            iNotification = NULL;
+            }
         }
     }
 
@@ -296,8 +331,23 @@
             }
         if ( aStatus )
             {
-            iParent.OutgoingPairCompleted( aStatus );
-            }
+            // retry pairing
+            if(aStatus && iPairingAttempt > 0)
+                {
+                if(aActive->RequestId() == EGeneralBondingRetry && iPairMode == EBTOutgoingHeadsetManualPairing)
+                    {
+                    // Headset pairing failed, reset and try again from auto pairing
+                    iActive->SetRequestId(EGeneralBonding);
+                    }
+                iPairingAttempt --;
+                ShowPairingRetryDialog();
+                }
+            else
+                {
+                iPairingAttempt --;
+                ShowPairingFailureDialog();
+                }
+             }
         }
     }
 
@@ -344,6 +394,14 @@
     (void) aActive;
     iParent.OutgoingPairCompleted( aError );
     iParent.RenewPairingHandler( NULL );
+    if( iNotification )
+        {
+        // Cancel the user query
+        // This will also unregister us from the notification.
+        TInt err = iNotification->Close();
+        NOTIF_NOTHANDLED( !err )
+        iNotification = NULL;
+        }
     }
 
 // ---------------------------------------------------------------------------
@@ -390,3 +448,106 @@
     BOstraceFunctionExit0( DUMMY_DEVLIST );
     }
 
+// ---------------------------------------------------------------------------
+// From class MBTNotificationResult.
+// Handle a result from a user query.
+// ---------------------------------------------------------------------------
+//
+void CBTNotifOutgoingPairingHandler::MBRDataReceived( CHbSymbianVariantMap& aData )
+    {
+    BOstraceFunctionEntry0( DUMMY_DEVLIST );
+    (void) aData;
+    BOstraceFunctionExit0( DUMMY_DEVLIST );
+    }
+
+// ---------------------------------------------------------------------------
+// From class MBTNotificationResult.
+// The notification is finished.
+// ---------------------------------------------------------------------------
+//
+void CBTNotifOutgoingPairingHandler::MBRNotificationClosed( TInt aError, const TDesC8& aData )
+    {
+    BOstraceFunctionEntryExt( DUMMY_DEVLIST, this, aError );
+    // First unregister from the notification, so we can already get the next one.
+    iNotification->RemoveObserver();
+    iNotification = NULL;
+    TRAP_IGNORE( NotificationClosedL( aError, aData ) );
+    BOstraceFunctionExit1( DUMMY_DEVLIST, this );
+    }
+
+// ---------------------------------------------------------------------------
+// Get and configure a notification.
+// ---------------------------------------------------------------------------
+//
+void CBTNotifOutgoingPairingHandler::PrepareNotificationL( TBluetoothDialogParams::TBTDialogType aType,
+    TBTDialogResourceId aResourceId )
+    {
+    BOstraceFunctionEntry0( DUMMY_DEVLIST );
+    iNotification = 
+            iParent.ConnectionTracker().NotificationManager()->GetNotification();
+    User::LeaveIfNull( iNotification ); // For OOM exception, leaves with KErrNoMemory
+    iNotification->SetObserver( this );
+    iNotification->SetNotificationType( aType, aResourceId );
+    const CBtDevExtension* dev = iParent.BTDevRepository().Device(iAddr);
+    if(dev)
+        {
+        User::LeaveIfError(iNotification->SetData( TBluetoothDeviceDialog::EDeviceName, dev->Alias()));
+        }
+    else
+        {
+        TBTDeviceName name;
+        iAddr.GetReadable(name);
+        User::LeaveIfError(iNotification->SetData( TBluetoothDeviceDialog::EDeviceName, name));
+        NOTIF_NOTHANDLED( !err )            
+        }
+    iParent.ConnectionTracker().NotificationManager()->QueueNotificationL( iNotification);
+    NOTIF_NOTHANDLED( !err )
+    BOstraceFunctionExit0( DUMMY_DEVLIST );
+    }
+
+// ---------------------------------------------------------------------------
+// The notification is finished, handle the result.
+// ---------------------------------------------------------------------------
+//
+void CBTNotifOutgoingPairingHandler::NotificationClosedL( TInt aError, const TDesC8& aData )
+    {
+    BOstraceFunctionEntryExt( DUMMY_DEVLIST, this, aError );
+    // Read the result.
+    TPckgC<TBool> result( EFalse );
+    result.Set( aData.Ptr(), result.Length() ); // Read the part containing the result
+    // Set a pointer descriptor to capture the remaining data, if any.
+    TPtrC8 dataPtr( aData.Mid( result.Length() ) );
+
+    if(result() && iPairingAttempt >= 0)
+        {
+            HandleOutgoingPairL(iAddr,iCod.DeviceClass());
+        }
+    else
+        {
+            iPairingAttempt = KMaxRepeatedPairingAttempt; // reset the counter
+            iParent.OutgoingPairCompleted( KErrCancel );
+            iParent.RenewPairingHandler( NULL );
+        }
+    BOstraceFunctionExit1( DUMMY_DEVLIST, this );
+    }
+
+// ---------------------------------------------------------------------------
+// Show a dialog to ask the user to retry the pairing
+// ---------------------------------------------------------------------------
+//
+void CBTNotifOutgoingPairingHandler::ShowPairingRetryDialog()
+    {
+    PrepareNotificationL( TBluetoothDialogParams::EQuery, EPairingFailureRetry);
+    }
+
+// ---------------------------------------------------------------------------
+// Show a dialog to tell the user pairing retry attempt failed
+// ---------------------------------------------------------------------------
+//
+void CBTNotifOutgoingPairingHandler::ShowPairingFailureDialog()
+    {
+    PrepareNotificationL( TBluetoothDialogParams::EQuery, EPairingFailureOk );
+    }
+
+
+
--- a/bluetoothengine/btnotif/btnotifsrv/src/btnotifpairnotifier.cpp	Tue Jul 06 14:27:09 2010 +0300
+++ b/bluetoothengine/btnotif/btnotifsrv/src/btnotifpairnotifier.cpp	Wed Aug 18 09:59:05 2010 +0300
@@ -196,7 +196,7 @@
                 // in pairing manager for this device:
                 iParent.GetPinCode( pinCode, iRemote, iMinPinLength );
                 }
-            if ( pinCode().iLength != 0 )        
+            if ( pinCode().iLength > 0 )        
                 {
                 // a pin is ready for this pairing.
                 // write it back to client (stack)
--- a/bluetoothengine/btnotif/btnotifsrv/src/btnotifsecuritymanager.cpp	Tue Jul 06 14:27:09 2010 +0300
+++ b/bluetoothengine/btnotif/btnotifsrv/src/btnotifsecuritymanager.cpp	Wed Aug 18 09:59:05 2010 +0300
@@ -445,6 +445,7 @@
         {
         // make sure not to leave any text as PIN.
         aPin.Zero();
+        aPin().iLength = 0;
         }
     }
 
--- a/bluetoothengine/btnotif/btnotifsrv/src/btnotifserviceauthorizer.cpp	Tue Jul 06 14:27:09 2010 +0300
+++ b/bluetoothengine/btnotif/btnotifsrv/src/btnotifserviceauthorizer.cpp	Wed Aug 18 09:59:05 2010 +0300
@@ -25,7 +25,6 @@
 #include "bluetoothnotification.h"
 #include "btnotifconnectiontracker.h"
 #include "btnotificationmanager.h"
-#include "bluetoothnotification.h"
 #include "btnotifserver.h"
 #include "btnotifutil.h"
 
--- a/bluetoothengine/btnotif/inc/bluetoothdevicedialogs.h	Tue Jul 06 14:27:09 2010 +0300
+++ b/bluetoothengine/btnotif/inc/bluetoothdevicedialogs.h	Wed Aug 18 09:59:05 2010 +0300
@@ -39,7 +39,8 @@
     EBlockUnpairedDevice,
     EBlockPairedDevice,
     EPairingSuccess,
-    EPairingFailure,
+    EPairingFailureRetry,
+    EPairingFailureOk,
     EVisibilityTimeout,
     EUnpairedDevice,
     EUnusedResource	// The last ID
@@ -68,7 +69,9 @@
         ESend,
         EGlobalNotif,
         EUserAuthorization,
-        EReceiveProgress
+        EReceiveProgress,
+        ETransferFailed, 
+        EReceiveDone
         };
 
     /**  Enumeration for the notification parameters data type to be configured. */
@@ -88,7 +91,18 @@
         EReceive,
         EReceiveFromPairedDevice,
         EConnect,
-        EPairingRequest
+        EPairingRequest,
+        ERecvFailed,
+        ESendFailed,
+        EReceiveCompleted
+        };
+    
+    enum TDialogActionType
+        {
+        EHide,
+        EShow,
+        ECancelReceive,
+        ECancelShow
         };
 
     inline TBluetoothDialogParams();
--- a/bluetoothengine/btsac/btrcc/inc/btrccVolumeLevelControllerBase.h	Tue Jul 06 14:27:09 2010 +0300
+++ b/bluetoothengine/btsac/btrcc/inc/btrccVolumeLevelControllerBase.h	Wed Aug 18 09:59:05 2010 +0300
@@ -89,7 +89,7 @@
 
         void Reset(); // Reset the volume level.  
 
-        TInt GetLocalMaxVolume();  
+        TInt GetLocalMaxVolumeL();  
         
         TInt GetCurrentLocalVolume();
         
--- a/bluetoothengine/btsac/btrcc/src/btrccAbsoluteVolumeLevelController.cpp	Tue Jul 06 14:27:09 2010 +0300
+++ b/bluetoothengine/btsac/btrcc/src/btrccAbsoluteVolumeLevelController.cpp	Wed Aug 18 09:59:05 2010 +0300
@@ -67,7 +67,7 @@
 	{
    	TRACE_FUNC
    	CBTRCCVolumeLevelControllerBase::ConstructL();
-   	iLocalMaxVolume = GetLocalMaxVolume();  
+   	iLocalMaxVolume = GetLocalMaxVolumeL();  
     iInterfaceSelector = &aInterfaceSelector;
    	
     iRemConAbsoluteVolumeController = CRemConAbsoluteVolumeController::NewL(aInterfaceSelector, 
--- a/bluetoothengine/btsac/btrcc/src/btrccLegacyVolumeLevelController.cpp	Tue Jul 06 14:27:09 2010 +0300
+++ b/bluetoothengine/btsac/btrcc/src/btrccLegacyVolumeLevelController.cpp	Wed Aug 18 09:59:05 2010 +0300
@@ -80,7 +80,7 @@
     TRACE_INFO((_L("CBTRCCActive created")))
     iCtrlRTimer.CreateLocal();    
     TRACE_INFO((_L("RTimer created")))
-    iLocalMaxVolume = GetLocalMaxVolume();
+    iLocalMaxVolume = GetLocalMaxVolumeL();
 	}
 
 // -----------------------------------------------------------------------------
--- a/bluetoothengine/btsac/btrcc/src/btrccLinker.cpp	Tue Jul 06 14:27:09 2010 +0300
+++ b/bluetoothengine/btsac/btrcc/src/btrccLinker.cpp	Wed Aug 18 09:59:05 2010 +0300
@@ -86,14 +86,35 @@
     iRegisterVolumeChangeNotificationCounter = 0;
     if (iAccObserver.IsAvrcpVolCTSupported())
         {
-        iAbsoluteVolController = CBTRCCAbsoluteVolumeLevelController::NewL(*iInterfaceSelector, *this);
-        TRACE_INFO((_L("CBTRCCLinker::ConstructL, absolute volume controller created.")))
+        TInt err = KErrNone;
+        TRAP(err, iAbsoluteVolController = CBTRCCAbsoluteVolumeLevelController::NewL(*iInterfaceSelector, *this));
+        if( err )
+            {
+            // Absolute volume controller creation failed, this means that we don't have volume controller
+            // but continue construct linker.
+            iAbsoluteVolController = NULL;
+            TRACE_INFO((_L("CBTRCCLinker::ConstructL, absolute volume controller creation failed %d, continue anyway."), err))
+            }
+        else
+            {
+            TRACE_INFO((_L("CBTRCCLinker::ConstructL, absolute volume controller created.")))
+            }
 
         // If also legacy is configured into use, prepare to use it with legacy devices. 
         if(iAccObserver.IsAvrcpLegacyVolCTSupported())
             {
-            iLegacyVolController = CBTRCCLegacyVolumeLevelController::NewL(*iInterfaceSelector, *this);
-            TRACE_INFO((_L("CBTRCCLinker::ConstructL, legacy volume controller created.")))
+            TRAP(err, iLegacyVolController = CBTRCCLegacyVolumeLevelController::NewL(*iInterfaceSelector, *this));
+            if( err )
+                {
+                // Legacy volume controller creation failed, this means that we don't have volume controller
+                // but continue construct linker.
+                iLegacyVolController = NULL;
+                TRACE_INFO((_L("CBTRCCLinker::ConstructL, legacy volume controller creation failed %d, continue anyway."), err))
+                }
+            else
+                {
+                TRACE_INFO((_L("CBTRCCLinker::ConstructL, legacy volume controller created.")))
+                }
         	}
         }
     else 
@@ -108,7 +129,7 @@
 
     iRemConBatteryTgt = CRemConBatteryApiTarget::NewL(*iInterfaceSelector, *this);
 
-    if (iAccObserver.IsAvrcpVolCTSupported()) 
+    if (iAbsoluteVolController || iLegacyVolController) 
         {
         iInterfaceSelector->OpenControllerL();
         }
@@ -445,6 +466,12 @@
         // absolute controller or legacy controller.
         if(!iVolController)
             {
+            // iAbsoluteVolController may be NULL, if creation of devsound has
+            // been failed or local max volume provided by devsound is zero.
+            
+            // iLegacyVolController may be NULL, depends on the configuration and
+            // if creation of devsound has been failed or local max volume provided
+            // by devsound is zero.
             if (iAccObserver.IsAbsoluteVolumeSupported(iRemoteAddr))
                 {
                 iVolController = iAbsoluteVolController;
@@ -452,7 +479,7 @@
                 }
            	else 
                 {
-                iVolController = iLegacyVolController; // iLegacyVolController may be NULL, depends on the configuration. 
+                iVolController = iLegacyVolController; 
                 }
             }
         }
--- a/bluetoothengine/btsac/btrcc/src/btrccVolumeLevelControllerBase.cpp	Tue Jul 06 14:27:09 2010 +0300
+++ b/bluetoothengine/btsac/btrcc/src/btrccVolumeLevelControllerBase.cpp	Wed Aug 18 09:59:05 2010 +0300
@@ -122,23 +122,21 @@
     }
 
 // -----------------------------------------------------------------------------
-// CBTRCCVolumeLevelControllerBase::GetLocalMaxVolume
+// CBTRCCVolumeLevelControllerBase::GetLocalMaxVolumeL
 // -----------------------------------------------------------------------------
 //
-TInt CBTRCCVolumeLevelControllerBase::GetLocalMaxVolume() 
+TInt CBTRCCVolumeLevelControllerBase::GetLocalMaxVolumeL() 
     {
     TRACE_FUNC
-    if(iLocalMaxVolume == 0)
+    // fetch max volume from adaptation and cache it.
+    CMMFDevSound* devSound = CMMFDevSound::NewL();
+    iLocalMaxVolume = devSound->MaxVolume();
+    TRACE_INFO((_L("Maximum volume is %d"), iLocalMaxVolume))
+    delete devSound; // This is not needed for anything else.
+    if( iLocalMaxVolume <= 0 )
         {
-        // fetch max volume from adaptation and cache it.
-        CMMFDevSound* devSound = NULL;
-        TRAPD( err, devSound  = CMMFDevSound::NewL() );
-        if(!err)
-            {
-            iLocalMaxVolume = devSound->MaxVolume();
-            TRACE_INFO((_L("Maximum volume is %d"), iLocalMaxVolume))
-            delete devSound; // This is not needed for anything else.
-            }
+        TRACE_INFO((_L("Error, Maximum volume value is invalid")))
+        User::Leave(KErrNotSupported);
         }
     return iLocalMaxVolume; 
     }
--- a/bluetoothengine/btsac/inc/btsaController.h	Tue Jul 06 14:27:09 2010 +0300
+++ b/bluetoothengine/btsac/inc/btsaController.h	Wed Aug 18 09:59:05 2010 +0300
@@ -1,5 +1,5 @@
 /*
-* Copyright (c) 2005 Nokia Corporation and/or its subsidiary(-ies).
+* Copyright (c) 2005-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"
@@ -239,6 +239,7 @@
     	CBtsacActive* iGavdpErrorActive;
     	
     	TBTDevAddr iRemoteAddr;
+		TBool iNotifiedObserverOfNewAccessory;
     	TInt  iSBCSEPIndex;   // SBC SEP Index in iRemoteSEPs array
     	TBool iResetAudioInput;
     	TRequestStatus* iConnectStatus;
--- a/bluetoothengine/btsac/inc/btsacStateListening.h	Tue Jul 06 14:27:09 2010 +0300
+++ b/bluetoothengine/btsac/inc/btsacStateListening.h	Wed Aug 18 09:59:05 2010 +0300
@@ -1,5 +1,5 @@
 /*
-* Copyright (c) 2006 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"
@@ -40,7 +40,9 @@
     
 public:
 
-    static CBtsacListening* NewL(CBTSAController& aParent, TBTSACGavdpResetReason aGavdpResetReason, TInt aDisconnectReason);
+    static CBtsacListening* NewL(CBTSAController& aParent, 
+		TBTSACResetGavdp aResetGavdp = EDontResetGavdp, 
+		TInt aDisconnectReason = KErrNone);
     
     virtual ~CBtsacListening();
     
@@ -117,15 +119,14 @@
 
 private:
 	
-    CBtsacListening(CBTSAController& aParent, TBTSACGavdpResetReason aGavdpResetReason, TInt aDisconnectReason);
+    CBtsacListening(CBTSAController& aParent, TBTSACResetGavdp aResetGavdp, TInt aDisconnectReason);
     void ConstructL();
     
 private:
-	TBTSACGavdpResetReason iGavdpResetReason;
+	TBTSACResetGavdp iResetGavdp;
 	TInt iDisconnectReason;
 	TInt iPendingRequests;
 	TBTInitProcedure iInitializationProcedure;
-	TBool iUnfinishedGavdpError;
 	 
 	 /**
      * AO for self completing.
@@ -134,4 +135,4 @@
     };
 
 #endif      // C_BTSACLISTENING_H
-            
\ No newline at end of file
+            
--- a/bluetoothengine/btsac/inc/btsacdefs.h	Tue Jul 06 14:27:09 2010 +0300
+++ b/bluetoothengine/btsac/inc/btsacdefs.h	Wed Aug 18 09:59:05 2010 +0300
@@ -1,5 +1,5 @@
 /*
-* Copyright (c) 2006 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"
@@ -57,10 +57,10 @@
 	EStreamConfiguredBySink
 	};
 
-enum TBTSACGavdpResetReason
+enum TBTSACResetGavdp
     {
-    EGavdpResetReasonNone,
-    EGavdpResetReasonGeneral  
+    EDontResetGavdp,
+    EResetGavdp
     };
 
 //Panic codes
--- a/bluetoothengine/btsac/src/btsaController.cpp	Tue Jul 06 14:27:09 2010 +0300
+++ b/bluetoothengine/btsac/src/btsaController.cpp	Wed Aug 18 09:59:05 2010 +0300
@@ -1,5 +1,5 @@
 /*
-* Copyright (c) 2005 Nokia Corporation and/or its subsidiary(-ies).
+* Copyright (c) 2005-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"
@@ -448,11 +448,16 @@
 void CBTSAController::NewAccessory(const TBTDevAddr& aAddr)
 	{
  	TRACE_FUNC
- 	TInt connectedProfiles = Observer().ConnectionStatus( aAddr );
- 	if( !(connectedProfiles & EStereo) )
- 	    {
- 	    Observer().NewAccessory( aAddr, EStereo );
- 	    } 
+	TRACE_INFO((_L("\tiNotifiedObserverOfNewAccessory = %d"), iNotifiedObserverOfNewAccessory))
+	if ( !iNotifiedObserverOfNewAccessory )
+		{
+	 	TInt connectedProfiles = Observer().ConnectionStatus( aAddr );
+	 	if( !(connectedProfiles & EStereo) )
+	 	    {
+	 	    Observer().NewAccessory( aAddr, EStereo );
+	 	    iNotifiedObserverOfNewAccessory = ETrue;
+	 	    } 
+		}
 	}
 
 // -----------------------------------------------------------------------------
@@ -462,7 +467,12 @@
 void CBTSAController::DisconnectedFromRemote(const TBTDevAddr& aAddr, TInt /*aError*/)
 	{
 	TRACE_FUNC
-	Observer().AccessoryDisconnected(aAddr, EStereo );
+	TRACE_INFO((_L("\tiNotifiedObserverOfNewAccessory = %d"), iNotifiedObserverOfNewAccessory))
+	if ( iNotifiedObserverOfNewAccessory )
+		{
+		Observer().AccessoryDisconnected(aAddr, EStereo );
+		iNotifiedObserverOfNewAccessory = EFalse;
+		}
 	}
 
 // -----------------------------------------------------------------------------
@@ -533,6 +543,11 @@
 //
 void CBTSAController::SetRemoteAddr(const TBTDevAddr& aRemoteAddr)
 	{
+#ifdef PRJ_ENABLE_TRACE
+	TBuf<12> buf;
+	aRemoteAddr.GetReadable(buf);
+	TRACE_INFO((_L("CBTSAController::SetRemoteAddr aRemoteAddr = %S"), &buf))
+#endif
 	iRemoteAddr = aRemoteAddr;
 	}
 	
@@ -542,6 +557,11 @@
 //
 TBTDevAddr CBTSAController::GetRemoteAddr() const
 	{
+#ifdef PRJ_ENABLE_TRACE
+	TBuf<12> buf;
+	iRemoteAddr.GetReadable(buf);
+	TRACE_INFO((_L("CBTSAController::GetRemoteAddr iRemoteAddr = %S"), &buf))
+#endif
 	return iRemoteAddr;
 	}
 
@@ -615,7 +635,7 @@
 		}
 	else
 		{
-		TRAPD(err, ChangeStateL(CBtsacListening::NewL(*this, EGavdpResetReasonGeneral, EFalse)));
+		TRAPD(err, ChangeStateL(CBtsacListening::NewL(*this, EResetGavdp, KErrNone)));
 		if (err)
 			{
 			TRACE_INFO((_L("CBTSAController::NotifyError() Couldn't change state.")))
--- a/bluetoothengine/btsac/src/btsacState.cpp	Tue Jul 06 14:27:09 2010 +0300
+++ b/bluetoothengine/btsac/src/btsacState.cpp	Wed Aug 18 09:59:05 2010 +0300
@@ -1,5 +1,5 @@
 /*
-* Copyright (c) 2002-2005 Nokia Corporation and/or its subsidiary(-ies).
+* Copyright (c) 2002-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"
@@ -50,7 +50,7 @@
 CBtsacState* CBtsacState::ErrorOnEntryL(TInt /*aReason*/)
     {
     TRACE_FUNC
-    return CBtsacListening::NewL(iParent, EGavdpResetReasonNone, KErrNone);
+    return CBtsacListening::NewL(iParent);
     }
 
 // -----------------------------------------------------------------------------
@@ -221,7 +221,7 @@
 	{
 	TRACE_INFO((_L("CBtsacState::GAVDP_AbortStreamConfirm(), state %d"), GetStateIndex()))
 	Parent().CompletePendingRequests(KCompleteAllReqs, KErrAbort);
-	TRAPD(err, Parent().ChangeStateL(CBtsacListening::NewL(Parent(), EGavdpResetReasonGeneral, KErrDisconnected)));
+	TRAPD(err, Parent().ChangeStateL(CBtsacListening::NewL(Parent(), EResetGavdp, KErrDisconnected)));
 	if (err)
 		{
 		TRACE_INFO((_L("CBtsacState::GAVDP_AbortStreamConfirm() Couldn't change state.")))
@@ -333,7 +333,7 @@
 	TRACE_INFO((_L("CBtsacState::GAVDP_AbortIndication(), state %d, SEID:%d"), GetStateIndex(), aSEID.SEID()))
 	(void)aSEID;
 	Parent().CompletePendingRequests(KCompleteAllReqs, KErrDisconnected);
-	TRAPD(err, Parent().ChangeStateL(CBtsacListening::NewL(Parent(), EGavdpResetReasonGeneral, KErrDisconnected)))
+	TRAPD(err, Parent().ChangeStateL(CBtsacListening::NewL(Parent(), EResetGavdp, KErrDisconnected)))
 	if(err)
 		{
 		TRACE_INFO((_L("CBtsacState::GAVDP_AbortIndication(), error! Couldn't change state")))
--- a/bluetoothengine/btsac/src/btsacStateAborting.cpp	Tue Jul 06 14:27:09 2010 +0300
+++ b/bluetoothengine/btsac/src/btsacStateAborting.cpp	Wed Aug 18 09:59:05 2010 +0300
@@ -1,5 +1,5 @@
 /*
-* Copyright (c) 2002-2005 Nokia Corporation and/or its subsidiary(-ies).
+* Copyright (c) 2002-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"
@@ -76,7 +76,7 @@
 	{
 	TRACE_FUNC
 	Parent().CompletePendingRequests(KCompleteAllReqs, aError);
-	Parent().ChangeStateL(CBtsacListening::NewL(Parent(), EGavdpResetReasonGeneral, KErrDisconnected));
+	Parent().ChangeStateL(CBtsacListening::NewL(Parent(), EResetGavdp, KErrDisconnected));
 	}
 
 //  End of File  
--- a/bluetoothengine/btsac/src/btsacStateConfigured.cpp	Tue Jul 06 14:27:09 2010 +0300
+++ b/bluetoothengine/btsac/src/btsacStateConfigured.cpp	Wed Aug 18 09:59:05 2010 +0300
@@ -1,5 +1,5 @@
 /*
-* Copyright (c) 2002-2005 Nokia Corporation and/or its subsidiary(-ies).
+* Copyright (c) 2002-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"
@@ -173,7 +173,7 @@
     {
     TRACE_FUNC
 	Parent().CompletePendingRequests(KOpenAudioReq, aError);
-	Parent().ChangeStateL(CBtsacListening::NewL(Parent(), EGavdpResetReasonGeneral, aError));
+	Parent().ChangeStateL(CBtsacListening::NewL(Parent(), EResetGavdp, aError));
     }
 
 // -----------------------------------------------------------------------------
@@ -237,7 +237,7 @@
 	Parent().CompletePendingRequests(KDisconnectReq, KErrNone);
 	// Cancel all other requests
 	Parent().CompletePendingRequests(KCompleteAllReqs, KErrCancel);
-	Parent().ChangeStateL(CBtsacListening::NewL(Parent(), EGavdpResetReasonGeneral, KErrNone));
+	Parent().ChangeStateL(CBtsacListening::NewL(Parent(), EResetGavdp, KErrNone));
 	}
 
 // -----------------------------------------------------------------------------
--- a/bluetoothengine/btsac/src/btsacStateConfiguring.cpp	Tue Jul 06 14:27:09 2010 +0300
+++ b/bluetoothengine/btsac/src/btsacStateConfiguring.cpp	Wed Aug 18 09:59:05 2010 +0300
@@ -1,5 +1,5 @@
 /*
-* Copyright (c) 2002-2005 Nokia Corporation and/or its subsidiary(-ies).
+* Copyright (c) 2002-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"
@@ -110,7 +110,7 @@
     {
     TRACE_FUNC
 	Parent().CompletePendingRequests((KConnectReq | KOpenAudioReq), aError);
-    Parent().ChangeStateL(CBtsacListening::NewL(Parent(), EGavdpResetReasonGeneral, aError));
+    Parent().ChangeStateL(CBtsacListening::NewL(Parent(), EResetGavdp, aError));
     }
 
 // -----------------------------------------------------------------------------
--- a/bluetoothengine/btsac/src/btsacStateConnected.cpp	Tue Jul 06 14:27:09 2010 +0300
+++ b/bluetoothengine/btsac/src/btsacStateConnected.cpp	Wed Aug 18 09:59:05 2010 +0300
@@ -1,5 +1,5 @@
 /*
-* Copyright (c) 2002-2005 Nokia Corporation and/or its subsidiary(-ies).
+* Copyright (c) 2002-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"
@@ -184,7 +184,7 @@
     TRACE_FUNC
     StopTimer();
 	Parent().CompletePendingRequests((KConnectReq | KOpenAudioReq), aError);
-	Parent().ChangeStateL(CBtsacListening::NewL(Parent(), EGavdpResetReasonGeneral, aError));
+	Parent().ChangeStateL(CBtsacListening::NewL(Parent(), EResetGavdp, aError));
     }
 
 // -----------------------------------------------------------------------------
@@ -552,7 +552,7 @@
 		TRACE_INFO((_L("[SOCKET] created.")))
 		Parent().iStreamingSockets.Append(aNewSocket);
 		Parent().CompletePendingRequests(KCompleteAllReqs, KErrCancel);
-		TRAP_IGNORE(Parent().ChangeStateL(CBtsacListening::NewL(Parent(), EGavdpResetReasonGeneral, KErrNone)));
+		TRAP_IGNORE(Parent().ChangeStateL(CBtsacListening::NewL(Parent(), EResetGavdp, KErrNone)));
 		}
 	}
 
--- a/bluetoothengine/btsac/src/btsacStateConnecting.cpp	Tue Jul 06 14:27:09 2010 +0300
+++ b/bluetoothengine/btsac/src/btsacStateConnecting.cpp	Wed Aug 18 09:59:05 2010 +0300
@@ -1,5 +1,5 @@
 /*
-* Copyright (c) 2002-2005 Nokia Corporation and/or its subsidiary(-ies).
+* Copyright (c) 2002-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"
@@ -81,7 +81,7 @@
     {
 	TRACE_FUNC
 	Parent().CompletePendingRequests((KConnectReq | KOpenAudioReq), aError);
-    Parent().ChangeStateL(CBtsacListening::NewL(Parent(), EGavdpResetReasonGeneral, aError));
+    Parent().ChangeStateL(CBtsacListening::NewL(Parent(), EResetGavdp, aError));
     }
 
 // -----------------------------------------------------------------------------
--- a/bluetoothengine/btsac/src/btsacStateIdle.cpp	Tue Jul 06 14:27:09 2010 +0300
+++ b/bluetoothengine/btsac/src/btsacStateIdle.cpp	Wed Aug 18 09:59:05 2010 +0300
@@ -1,5 +1,5 @@
 /*
-* Copyright (c) 2002-2005 Nokia Corporation and/or its subsidiary(-ies).
+* Copyright (c) 2002-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"
@@ -102,7 +102,7 @@
 void CBtsacIdle::GAVDP_ConfigurationConfirm()
 	{
 	TRACE_INFO((_L("CBtsacIdle::GAVDP_ConfigurationConfirm() Local SEPs registered successfully.")))
-	TRAP_IGNORE(Parent().ChangeStateL(CBtsacListening::NewL(Parent(), EGavdpResetReasonNone, KErrNone)));
+	TRAP_IGNORE(Parent().ChangeStateL(CBtsacListening::NewL(Parent())));
 	}
 
 // -----------------------------------------------------------------------------
--- a/bluetoothengine/btsac/src/btsacStateListening.cpp	Tue Jul 06 14:27:09 2010 +0300
+++ b/bluetoothengine/btsac/src/btsacStateListening.cpp	Wed Aug 18 09:59:05 2010 +0300
@@ -1,5 +1,5 @@
 /*
-* Copyright (c) 2002-2005 Nokia Corporation and/or its subsidiary(-ies).
+* Copyright (c) 2002-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"
@@ -35,9 +35,10 @@
 // -----------------------------------------------------------------------------
 //
 CBtsacListening* CBtsacListening::NewL(CBTSAController& aParent,
-	TBTSACGavdpResetReason aGavdpResetReason, TInt aDisconnectReason)
+									TBTSACResetGavdp aResetGavdp, 
+									TInt aDisconnectReason)
     {
-    CBtsacListening* self = new( ELeave ) CBtsacListening(aParent, aGavdpResetReason, aDisconnectReason);
+    CBtsacListening* self = new( ELeave ) CBtsacListening(aParent, aResetGavdp, aDisconnectReason);
     CleanupStack::PushL(self);
     self->ConstructL();
     CleanupStack::Pop(self);
@@ -49,10 +50,10 @@
 // -----------------------------------------------------------------------------
 //
 CBtsacListening::CBtsacListening(CBTSAController& aParent,
-	TBTSACGavdpResetReason aGavdpResetReason, TInt aDisconnectReason)
-: 	CBtsacState(aParent, EStateListening), iGavdpResetReason(aGavdpResetReason),
+	TBTSACResetGavdp aResetGavdp, TInt aDisconnectReason)
+: 	CBtsacState(aParent, EStateListening), iResetGavdp(aResetGavdp),
 	iDisconnectReason(aDisconnectReason), iPendingRequests(KRequestNone),
-	iInitializationProcedure(EInitProcedureOngoing), iUnfinishedGavdpError(EFalse)
+	iInitializationProcedure(EInitProcedureOngoing)
     {
     }
 
@@ -262,12 +263,13 @@
 		case KRequestIdSelfComplete:
 			{
 			TBTDevAddr remoteAddr = Parent().GetRemoteAddr();
-			if(iUnfinishedGavdpError)
-				{
-				// We have unfinished gavdp error, force gavdp reset
-				iGavdpResetReason = EGavdpResetReasonGeneral;
-				}
-			if(iGavdpResetReason != EGavdpResetReasonNone)
+#ifdef PRJ_ENABLE_TRACE
+			TBuf<12> buf;
+			remoteAddr.GetReadable(buf);
+			TRACE_INFO((_L("\tremoteAddr = %S"), &buf))
+#endif
+			TRACE_INFO((_L("\tiResetGavdp = %d"), iResetGavdp))
+			if(iResetGavdp == EResetGavdp)
 				{
 				ResetGavdp();
 				}
@@ -275,11 +277,12 @@
 				{
 				GoListen();
 				}				
-			if((iDisconnectReason == KErrDisconnected || iDisconnectReason == KErrHCILinkDisconnection) &&
-			    iPendingRequests == KRequestNone)
+			TRACE_INFO((_L("\tiPendingRequests = %d"), iPendingRequests))
+			if(iPendingRequests == KRequestNone)
 				{
 				if(remoteAddr != TBTDevAddr())
 					{						
+					TRACE_INFO((_L("\tcalling DisconnectedFromRemote with iDisconnectReason = %d"), iDisconnectReason))
 					Parent().DisconnectedFromRemote(remoteAddr, iDisconnectReason);
 					}
 				Parent().SetResetAudioInput(ETrue);
@@ -397,7 +400,7 @@
     if(iInitializationProcedure != EInitProcedureDone)
 	    {
 	    TRACE_INFO((_L("CBtsacListening::HandleGavdpErrorL() error ignored, initialization procedure ongoing.")))
-	    iUnfinishedGavdpError = ETrue;	    
+	    iResetGavdp = EResetGavdp;
 	    return;
 	    }
 	switch(aError)
--- a/bluetoothengine/btsac/src/btsacStateStreaming.cpp	Tue Jul 06 14:27:09 2010 +0300
+++ b/bluetoothengine/btsac/src/btsacStateStreaming.cpp	Wed Aug 18 09:59:05 2010 +0300
@@ -1,5 +1,5 @@
 /*
-* Copyright (c) 2002-2005 Nokia Corporation and/or its subsidiary(-ies).
+* Copyright (c) 2002-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"
@@ -99,7 +99,7 @@
 		TRACE_INFO((_L("CBtsacStreaming::Cancel() iStreamer.StopStream() returned error(%d) !!!"), ret))
 		}
 	Parent().CompletePendingRequests(KCompleteAllReqs, aError);
-	Parent().ChangeStateL(CBtsacListening::NewL(Parent(), EGavdpResetReasonGeneral, aError));
+	Parent().ChangeStateL(CBtsacListening::NewL(Parent(), EResetGavdp, aError));
 	}
 
 // -----------------------------------------------------------------------------
@@ -151,7 +151,7 @@
 	TRACE_FUNC
 	// For safety sake complete all pending requests
 	Parent().CompletePendingRequests(KCompleteAllReqs, KErrNone);
-	TRAP_IGNORE(Parent().ChangeStateL(CBtsacListening::NewL(Parent(), EGavdpResetReasonGeneral, KErrDisconnected)));
+	TRAP_IGNORE(Parent().ChangeStateL(CBtsacListening::NewL(Parent(), EResetGavdp, KErrDisconnected)));
 	}
 
 
@@ -171,7 +171,7 @@
 			{
 			TRACE_INFO((_L("CBtsacStreaming::StartRecording() Couldn't abort stream.")))	
 			}
-		TRAP_IGNORE(Parent().ChangeStateL(CBtsacListening::NewL(Parent(), EGavdpResetReasonGeneral, KErrDisconnected)));
+		TRAP_IGNORE(Parent().ChangeStateL(CBtsacListening::NewL(Parent(), EResetGavdp, KErrDisconnected)));
 	 	}
 	}
 
@@ -188,7 +188,7 @@
 		TRACE_INFO((_L("CBtsacStreaming::DisconnectL() StopStream() returned error: %d"), ret))	
 		}
 	Parent().CompletePendingRequests(KDisconnectReq, ret);
-	Parent().ChangeStateL(CBtsacListening::NewL(Parent(), EGavdpResetReasonGeneral, KErrNone));
+	Parent().ChangeStateL(CBtsacListening::NewL(Parent(), EResetGavdp, KErrNone));
 	}
 
 // -----------------------------------------------------------------------------
@@ -220,7 +220,7 @@
 	
 	// It is possible the remote disconnected while we have active close audio request.
 	Parent().CompletePendingRequests(KCompleteAllReqs, KErrNone);
-    TRAP_IGNORE(Parent().ChangeStateL(CBtsacListening::NewL(Parent(), EGavdpResetReasonGeneral, KErrDisconnected)));
+    TRAP_IGNORE(Parent().ChangeStateL(CBtsacListening::NewL(Parent(), EResetGavdp, KErrDisconnected)));
 	}
 
 // -----------------------------------------------------------------------------
@@ -339,7 +339,7 @@
 			else
 				{
 				Parent().CompletePendingRequests(KCompleteAllReqs, aError);
-				Parent().ChangeStateL(CBtsacListening::NewL(Parent(), EGavdpResetReasonGeneral, KErrDisconnected));
+				Parent().ChangeStateL(CBtsacListening::NewL(Parent(), EResetGavdp, KErrDisconnected));
 				}
 			break;
 			}
@@ -347,7 +347,7 @@
 		case KErrDisconnected: // -36
 			{
 			Parent().CompletePendingRequests(KCompleteAllReqs, aError);
-			Parent().ChangeStateL(CBtsacListening::NewL(Parent(), EGavdpResetReasonGeneral, aError));
+			Parent().ChangeStateL(CBtsacListening::NewL(Parent(), EResetGavdp, aError));
 			break;
 			}
 		default:
@@ -355,7 +355,7 @@
 			// Unknown error. For safety's sake let's disconnect a2dp link and inform btaudioman
 			TRACE_INFO((_L("CBtsacStreaming::HandleGavdpErrorL() Unknown error, goes to listening")))
 			Parent().CompletePendingRequests(KCompleteAllReqs, aError);
-			Parent().ChangeStateL(CBtsacListening::NewL(Parent(), EGavdpResetReasonGeneral, KErrDisconnected));
+			Parent().ChangeStateL(CBtsacListening::NewL(Parent(), EResetGavdp, KErrDisconnected));
 			break;
 			}
 		}
--- a/bluetoothengine/btsac/src/btsacStateSuspended.cpp	Tue Jul 06 14:27:09 2010 +0300
+++ b/bluetoothengine/btsac/src/btsacStateSuspended.cpp	Wed Aug 18 09:59:05 2010 +0300
@@ -1,5 +1,5 @@
 /*
-* Copyright (c) 2002-2005 Nokia Corporation and/or its subsidiary(-ies).
+* Copyright (c) 2002-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"
@@ -87,7 +87,7 @@
 	{
 	TRACE_FUNC
 	Parent().CompletePendingRequests(KOpenAudioReq, aError);
-	Parent().ChangeStateL(CBtsacListening::NewL(Parent(), EGavdpResetReasonGeneral, aError));
+	Parent().ChangeStateL(CBtsacListening::NewL(Parent(), EResetGavdp, aError));
 	}
     
 // -----------------------------------------------------------------------------
--- a/bluetoothengine/btsap/src/BTSapSniffHandler.cpp	Tue Jul 06 14:27:09 2010 +0300
+++ b/bluetoothengine/btsap/src/BTSapSniffHandler.cpp	Wed Aug 18 09:59:05 2010 +0300
@@ -98,7 +98,7 @@
     if(iIsLinkAdapterOpen)
         {
         // Start the sniffer timer
-        BTSAP_TRACE_OPT(KBTSAP_TRACE_INFO, BTSapPrintTrace(_L("[BTSap]  CBTSapSniffHandler::Enable: Starting the sniff timer %d µsec"), KSniffInterval));
+        BTSAP_TRACE_OPT(KBTSAP_TRACE_INFO, BTSapPrintTrace(_L("[BTSap]  CBTSapSniffHandler::Enable: Starting the sniff timer %d microseconds"), KSniffInterval));
         Cancel();
         After(KSniffInterval);
 
--- a/bluetoothengine/btui/btcpplugin/btcpplugin.cpp	Tue Jul 06 14:27:09 2010 +0300
+++ b/bluetoothengine/btui/btcpplugin/btcpplugin.cpp	Wed Aug 18 09:59:05 2010 +0300
@@ -15,9 +15,8 @@
  *
  */
 
-
+#include "btcpplugin.h"
 #include <cpsettingformentryitemdataimpl.h>
-#include "btcpplugin.h"
 #include "btcpuisettingitem.h"
 
 /*!
--- a/bluetoothengine/btui/btcpplugin/btcpuidevicedetail.cpp	Tue Jul 06 14:27:09 2010 +0300
+++ b/bluetoothengine/btui/btcpplugin/btcpuidevicedetail.cpp	Wed Aug 18 09:59:05 2010 +0300
@@ -23,6 +23,7 @@
 #include <bluetoothuitrace.h>
 #include <HbInstance>
 
+
 BtCpUiDeviceDetail::BtCpUiDeviceDetail(QObject *parent) :
     QObject(parent), mDeviceDetailView(0)
 {
@@ -31,7 +32,6 @@
 
 BtCpUiDeviceDetail::~BtCpUiDeviceDetail()
 {
-    notifyViewStatusToPlugins(AboutToClose);
     clearDeviceDetailList();
     delete mDeviceDetailView;
 }
@@ -57,8 +57,9 @@
         delete interfaces.at(i);
     }
     
+    createDeviceDetailsView(deviceName);
     notifyDeviceDetailStatus();
-    createDeviceDetailsView(deviceName);
+    
 }
 
 void BtCpUiDeviceDetail::appendDeviceToList(BtAbstractDevSetting *devSetting)
@@ -84,6 +85,7 @@
 void BtCpUiDeviceDetail::handleSettingChange(BtAbstractDevSetting *setting, bool available)
 {
     QList<BtDeviceDetails>::iterator i;
+       
     for (i = mDeviceDetailList.begin(); i != mDeviceDetailList.end(); ++i) {
         if((setting == (*i).mSetting) && mDeviceDetailView) {
             (*i).mSettingAvailable = available;
@@ -99,10 +101,9 @@
             else {
                 if((*i).mSettingForm) {
                     //remove widget
-                    //todo: In case if no items are there close this view
-                    //and disable device settings button.
                     mDeviceDetailView->removeItem((*i).mSettingForm);
-                    (*i).mSettingForm = 0; 
+                    (*i).mSettingForm = 0;
+                    checkDeviceDetailSettings();
                 }
             }
             notifyDeviceDetailStatus();
@@ -111,6 +112,25 @@
 }
 
 
+void BtCpUiDeviceDetail::checkDeviceDetailSettings()
+{
+    QList<BtDeviceDetails>::const_iterator i;
+    bool devicedetail = false;
+    
+    for (i = mDeviceDetailList.constBegin(); i != mDeviceDetailList.constEnd(); ++i) {
+        if((*i).mSettingForm) {
+            devicedetail = true;
+            break;
+        }
+    }
+    //If no setting is available and current view is device detail 
+    //view move to previous view.
+    if((!devicedetail) && (mMainWindow->currentView() == mDeviceDetailView)) {
+        mMainWindow->removeView(mDeviceDetailView); 
+        mMainWindow->setCurrentView( mPreviousView );
+    }
+}
+
 void BtCpUiDeviceDetail::notifyDeviceDetailStatus()
 {
     QList<BtDeviceDetails>::const_iterator i;
@@ -156,7 +176,6 @@
             mDeviceDetailView->addItem((*i).mSettingForm);
         }
     }
-
 }
 
 void BtCpUiDeviceDetail::loadDeviceDetailsView()
@@ -203,4 +222,9 @@
 
 }
 
+void BtCpUiDeviceDetail::sendCloseEvent()
+{
+    notifyViewStatusToPlugins(AboutToClose);
+}
 
+
--- a/bluetoothengine/btui/btcpplugin/btcpuidevicedetail.h	Tue Jul 06 14:27:09 2010 +0300
+++ b/bluetoothengine/btui/btcpplugin/btcpuidevicedetail.h	Wed Aug 18 09:59:05 2010 +0300
@@ -46,7 +46,9 @@
     void loadDeviceDetailPlugins(QString deviceAddress, QString deviceName);
         
     void loadDeviceDetailsView();
-        
+    
+    void sendCloseEvent(); 
+    
 signals:
     void deviceSettingsChanged(bool settingAvailable);
     
@@ -66,6 +68,7 @@
     void notifyDeviceDetailStatus();
     void createDeviceDetailsView(QString deviceName);
     void notifyViewStatusToPlugins(BtCpUiDeviceDetail::NotifyType type);
+    void checkDeviceDetailSettings();
     
 private:
     
--- a/bluetoothengine/btui/btcpplugin/btcpuidevicedetailsview.cpp	Tue Jul 06 14:27:09 2010 +0300
+++ b/bluetoothengine/btui/btcpplugin/btcpuidevicedetailsview.cpp	Wed Aug 18 09:59:05 2010 +0300
@@ -14,6 +14,7 @@
 * Description:  BtCpUiDeviceDetailsView implementation
 *
 */
+#include "btcpuidevicedetailsview.h"
 #include <QtGlobal>
 #include <QGraphicsLinearLayout>
 #include <HbInstance>
@@ -23,7 +24,6 @@
 #include <hbcombobox.h>
 #include <hbgroupbox.h>
 #include <bluetoothuitrace.h>
-#include "btcpuidevicedetailsview.h"
 
 // docml to load
 const char* BTUI_DEVICEDETAILSVIEW_DOCML = ":/docml/bt-device-details-view.docml";
--- a/bluetoothengine/btui/btcpplugin/btcpuidevicedetailsview.h	Tue Jul 06 14:27:09 2010 +0300
+++ b/bluetoothengine/btui/btcpplugin/btcpuidevicedetailsview.h	Wed Aug 18 09:59:05 2010 +0300
@@ -14,8 +14,8 @@
 * Description:  BtCpUiDeviceDetailsView declaration
 */
 
-#ifndef BTCPUIDEVICEDETAILSVIEW_H_
-#define BTCPUIDEVICEDETAILSVIEW_H_
+#ifndef BTCPUIDEVICEDETAILSVIEW_H
+#define BTCPUIDEVICEDETAILSVIEW_H
 
 #include <hbview.h>
 #include <qglobal.h>
@@ -50,4 +50,4 @@
     Q_DISABLE_COPY(BtCpUiDeviceDetailsView)
 };
 
-#endif /* BTCPUIDEVICEDETAILSVIEW_H_ */
+#endif /* BTCPUIDEVICEDETAILSVIEW_H */
--- a/bluetoothengine/btui/btcpplugin/btcpuideviceview.cpp	Tue Jul 06 14:27:09 2010 +0300
+++ b/bluetoothengine/btui/btcpplugin/btcpuideviceview.cpp	Wed Aug 18 09:59:05 2010 +0300
@@ -52,8 +52,8 @@
         BtDeviceModel &deviceModel, 
         QGraphicsItem *parent) :
     BtCpUiBaseView(settingModel,deviceModel,parent),
-    mPairedStatus(false), mConnectedStatus(false), mTrustedStatus(false), mBlockedStatus(false), 
-    mConnectable(false), mAbstractDelegate(0), mDeviceDetail(0)   
+    mPairedStatus(false), mConnectedStatus(false),mPreviousConnectedStatus(false), mTrustedStatus(false), 
+    mBlockedStatus(false), mConnectable(false), mAbstractDelegate(0), mDeviceDetail(0)   
 {
     mDeviceIndex = QModelIndex();//is it needed to initialize mIndex???
     
@@ -187,16 +187,46 @@
 {
     BTUI_ASSERT_X(mMainView, "BtCpUiSearchView::switchToPreviousView", "invalid mMainView");
     mMainView->switchToPreviousView();
-    delete mDeviceDetail;
-    mDeviceDetail = 0;
+
+    if(mDeviceDetail) {
+        mDeviceDetail->sendCloseEvent();
+    }
+    unloadDeviceDetails();
+}
+
+void BtCpUiDeviceView::loadDeviceDetails()
+{
+    bool ret(false);
+    
+    unloadDeviceDetails();
+    
+    mDeviceDetail = new BtCpUiDeviceDetail();
+    
+    ret=connect(mDeviceDetail, SIGNAL(deviceSettingsChanged(bool)),
+           this, SLOT(handleDeviceSettingsChange(bool)));
+    BTUI_ASSERT_X( ret, "Btui, BtCpUiDeviceView::loadDeviceDetails", "deviceSettingsChanged() connect failed");
+
+    mDeviceDetail->loadDeviceDetailPlugins(mDeviceBdAddr.toString(), mDeviceName->text());
+}
+
+void BtCpUiDeviceView::unloadDeviceDetails()
+{
+    if(mDeviceDetail) {
+        disconnect(mDeviceDetail);
+        delete mDeviceDetail;
+        mDeviceDetail = 0;
+    }
 }
 
 void BtCpUiDeviceView::activateView( const QVariant& value, bool fromBackButton )
 {
+    
     Q_UNUSED( fromBackButton );  
     
+    mConnectedStatus = false;
     setSoftkeyBack();
     
+    
     QModelIndex index = value.value<QModelIndex>();
     mDeviceBdAddr = (mDeviceModel->data(index, BtDeviceModel::ReadableBdaddrRole));
     
@@ -205,31 +235,24 @@
     updateDeviceData();
     
     mDeviceSetting->setVisible(false);
-    
-    mDeviceDetail = new BtCpUiDeviceDetail();
-    
+        
     bool ret(false);
     ret=connect(mDeviceModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)),
            this, SLOT(updateDeviceData()));
     BTUI_ASSERT_X( ret, "Btui, BtCpUiDeviceView::activateView", "dataChanged() connect failed");
 
-    ret=connect(mDeviceDetail, SIGNAL(deviceSettingsChanged(bool)),
-           this, SLOT(handleDeviceSettingsChange(bool)));
-    BTUI_ASSERT_X( ret, "Btui, BtCpUiDeviceView::activateView", "deviceSettingsChanged() connect failed");
-
-    
-    mDeviceDetail->loadDeviceDetailPlugins(mDeviceBdAddr.toString(), mDeviceName->text());
-    
 }
 
 void BtCpUiDeviceView::handleDeviceSettingsChange(bool status)
 {
-    mDeviceSetting->setVisible(status);        
+    mDeviceSetting->setVisible(status);
 }
 
 void BtCpUiDeviceView::handleDeviceSetting()
 {
-    mDeviceDetail->loadDeviceDetailsView();
+    if(mDeviceDetail) {
+        mDeviceDetail->loadDeviceDetailsView();
+    }
 }
 
 void BtCpUiDeviceView::deactivateView()
@@ -257,13 +280,15 @@
     mDeviceIcon->clear();
     mDeviceCategory->clear();
     mDeviceStatus->clear();
-    
+    mConnectable = false;
+    /*
     mPairedStatus = false;
     mConnectedStatus = false;
     mTrustedStatus = false;
     mBlockedStatus = false;
     
     mConnectable = false;
+    */
 }
     
 void BtCpUiDeviceView::updateDeviceData()
@@ -355,6 +380,8 @@
  */
 void BtCpUiDeviceView::updateStatusVariables(int majorRole)
 {
+    mPreviousConnectedStatus = mConnectedStatus;
+    
     if (majorRole & BtuiDevProperty::Trusted ) {
         mTrustedStatus = true;
     } 
@@ -369,6 +396,10 @@
     }
     if (majorRole & BtuiDevProperty::Connected) {
         mConnectedStatus = true;
+        if (!mPreviousConnectedStatus){
+            //Loading device detail plugins after successfull connection.
+            loadDeviceDetails();
+        }
     }
     else {
         mConnectedStatus = false;
@@ -402,6 +433,7 @@
     
     if (mConnectable)
     {
+        mConnect_Disconnect->setVisible(true);
         mConnect_Disconnect->setStretched(true);
         if (mConnectedStatus)
         {
@@ -539,8 +571,6 @@
         delete mAbstractDelegate;
         mAbstractDelegate = 0;
     }   
-    
-    
 }
 
 void BtCpUiDeviceView::disconnectDevice()
@@ -582,9 +612,14 @@
         disconnect(mAbstractDelegate);
         delete mAbstractDelegate;
         mAbstractDelegate = 0;
-    }   
-    
-    
+    }
+}
+
+void BtCpUiDeviceView::setPrevBtDeviceName()
+{
+    QString deviceName = (mDeviceModel->data(mDeviceIndex, 
+                BtDeviceModel::NameAliasRole)).toString(); 
+   mDeviceName->setText(deviceName);
 }
 
 void BtCpUiDeviceView::changeBtDeviceName(){
@@ -609,6 +644,9 @@
         connect( mAbstractDelegate, SIGNAL(commandCompleted(int, QVariant)), this, SLOT(changeDevNameDelegateCompleted(int, QVariant)) );
         mAbstractDelegate->exec(params);
     }
+    else {
+        setPrevBtDeviceName();
+    }
     
 }
 
@@ -620,7 +658,7 @@
         mDeviceName->setText(param.toString());
     }
     else {
-        //setPrevBtLocalName();
+        setPrevBtDeviceName();
     }
     //TODO:Error handling has to be done.    
     if (mAbstractDelegate)
--- a/bluetoothengine/btui/btcpplugin/btcpuideviceview.h	Tue Jul 06 14:27:09 2010 +0300
+++ b/bluetoothengine/btui/btcpplugin/btcpuideviceview.h	Wed Aug 18 09:59:05 2010 +0300
@@ -78,7 +78,10 @@
     void setConnectionCombobox();
     void setTextAndVisibilityOfButtons();
     void updateStatusVariables(int majorRole);
-
+    void loadDeviceDetails();
+    void unloadDeviceDetails();
+    void setPrevBtDeviceName();
+    
 private:
     HbDocumentLoader *mLoader;
     //HbGroupBox *mGroupBox;
@@ -113,6 +116,7 @@
     
     //true-> device is connected; false -> device is disconnected
     bool mConnectedStatus;
+    bool mPreviousConnectedStatus;
     bool mTrustedStatus;
     bool mBlockedStatus;
 
--- a/bluetoothengine/btui/btcpplugin/btcpuimainview.cpp	Tue Jul 06 14:27:09 2010 +0300
+++ b/bluetoothengine/btui/btcpplugin/btcpuimainview.cpp	Wed Aug 18 09:59:05 2010 +0300
@@ -34,6 +34,7 @@
 #include <hbaction.h>
 #include <hbcombobox.h>
 #include <hbgroupbox.h>
+#include <hbdataform.h>
 #include "btcpuisearchview.h"
 #include "btcpuideviceview.h"
 #include <bluetoothuitrace.h>
@@ -144,24 +145,23 @@
     ret = connect(mPairAction, SIGNAL(triggered()), this, SLOT(pairActionTriggered()));
     BTUI_ASSERT_X( ret, "bt-main-view", "pair action can't connect" ); 
 
-    mGroupBox = qobject_cast<HbGroupBox *>( mLoader->findWidget( "groupBox" ) );
-    BTUI_ASSERT_X( mGroupBox != 0, "bt-main-view", "Group Box not found" ); 
+    mDataForm = qobject_cast<HbDataForm *>( mLoader->findWidget( "dataForm" ) );
+    BTUI_ASSERT_X( mDataForm != 0, "bt-main-view", "dataForm not found" ); 
     
-    //*********************Testing device view START****************************//
-    HbAction *removePairedDevices = static_cast<HbAction*>( mLoader->findObject( "removePairedDevices" ) );
-    BTUI_ASSERT_X( removePairedDevices, "bt-main-view", "remove action missing" ); 
-    //ret = connect(removePairedDevices, SIGNAL(triggered()), this, SLOT(goToDeviceView()));
-    //BTUI_ASSERT_X( ret, "bt-main-view", "orientation toggle can't connect" ); 
-        
-    
-    
-    //*********************Testing device view END****************************//
         
     // load menu
     HbMenu *optionsMenu = qobject_cast<HbMenu *>(mLoader->findWidget("viewMenu"));
     BTUI_ASSERT_X( optionsMenu != 0, "bt-main-view", "Options menu not found" );   
     this->setMenu(optionsMenu);
     
+    HbMenu *menu = this->menu();
+    mRemovePairedDevices = menu->addAction(hbTrId("txt_bt_opt_remove_paired_devices"));
+    
+    mSubMenu = new HbMenu(hbTrId("txt_bt_opt_remove"));
+    mSubMenu->addAction(hbTrId("txt_bt_opt_remove_sub_all_devices"));
+    mSubMenu->addAction(hbTrId("txt_bt_opt_remove_sub_paired_devices"));
+    mSubMenu->addAction(hbTrId("txt_bt_opt_remove_sub_blocked_devices"));
+    
     // update display when setting data changed
     ret = connect(mSettingModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), 
             this, SLOT(updateSettingItems(QModelIndex,QModelIndex)));
@@ -183,14 +183,13 @@
     mMainFilterModel = new BtuiModelSortFilter(this);
     
     mMainFilterModel->setSourceModel( mDeviceModel );
+    mDeviceList->setModel(mMainFilterModel);
     updateDeviceListFilter(BtuiPaired);
 	    // List view item
     BtCpUiMainListViewItem *prototype = new BtCpUiMainListViewItem(mDeviceList);
     prototype->setModelSortFilter(mMainFilterModel);
     mDeviceList->setItemPrototype(prototype);
 
-    mDeviceList->setModel(mMainFilterModel);
-
 }
 
 /*!
@@ -204,6 +203,7 @@
 	if (mAbstractDelegate) {
         delete mAbstractDelegate;
     }
+
 }
 
 /*! 
@@ -214,6 +214,9 @@
     Q_UNUSED(value);
     Q_UNUSED(fromBackButton);
     
+    //Reset the device list when returning to the view, as it may have been invalidated by the device view
+    mMainFilterModel->setSourceModel( mDeviceModel );
+    mDeviceList->setModel(mMainFilterModel);
 }
 
 /*! 
@@ -321,11 +324,18 @@
 
 void BtCpUiMainView::allActionTriggered()
 {
+    HbMenu *menu = this->menu();
+    menu->removeAction(mRemovePairedDevices);
+    mRemoveDevices = menu->addMenu( mSubMenu );
+
     updateDeviceListFilter(BtuiAll);
 }
 
 void BtCpUiMainView::pairActionTriggered()
 {
+    HbMenu *menu = this->menu();
+    menu->removeAction(mRemoveDevices);
+    mRemovePairedDevices = menu->addAction(hbTrId("txt_bt_opt_remove_paired_devices"));
     updateDeviceListFilter(BtuiPaired);
 }
 
@@ -335,7 +345,7 @@
     
     switch (filter) {
         case BtuiAll:
-            mGroupBox->setHeading(hbTrId("txt_bt_subhead_bluetooth_all_devices"));
+            mDataForm->setHeading(hbTrId("txt_bt_subhead_bluetooth_all_devices"));
             mPairAction->setEnabled(true);
             mAllAction->setEnabled(false);
             mMainFilterModel->addDeviceMajorFilter(
@@ -344,7 +354,7 @@
 
             break;
         case BtuiPaired:
-            mGroupBox->setHeading(hbTrId("txt_bt_subhead_bluetooth_paired_devices"));
+            mDataForm->setHeading(hbTrId("txt_bt_subhead_bluetooth_paired_devices"));
             mPairAction->setEnabled(false);
             mAllAction->setEnabled(true);
             mMainFilterModel->addDeviceMajorFilter(
--- a/bluetoothengine/btui/btcpplugin/btcpuimainview.h	Tue Jul 06 14:27:09 2010 +0300
+++ b/bluetoothengine/btui/btcpplugin/btcpuimainview.h	Wed Aug 18 09:59:05 2010 +0300
@@ -32,6 +32,7 @@
 class BtAbstractDelegate;
 class HbListView;
 class HbGroupBox;
+class HbDataForm;
 
 class BtCpUiMainView : public BtCpUiBaseView
 {
@@ -118,6 +119,9 @@
     
     HbAction *mAllAction;
     HbAction *mPairAction;
-    HbGroupBox *mGroupBox;
+    HbDataForm *mDataForm;
+    HbAction* mRemovePairedDevices;
+    HbAction* mRemoveDevices;
+    HbMenu* mSubMenu;
 };
 #endif // BTCPUIMAINVIEW_H 
--- a/bluetoothengine/btui/btcpplugin/btcpuisearchview.cpp	Tue Jul 06 14:27:09 2010 +0300
+++ b/bluetoothengine/btui/btcpplugin/btcpuisearchview.cpp	Wed Aug 18 09:59:05 2010 +0300
@@ -26,6 +26,7 @@
 #include <HbListView>
 #include <HbMenu>
 #include <HbSelectionDialog>
+#include <HbGroupBox>
 #include <QString>
 #include <QStringList>
 #include <QDebug>
@@ -49,12 +50,14 @@
     bool ret(false);
     
     mQuery = 0;
+    mLoader = 0;
+    mSoftKeyBackAction = 0;
+    
     mMainView = (BtCpUiMainView *) parent;
-    
     mMainWindow = hbInstance->allMainWindows().first();
     
     mSoftKeyBackAction = new HbAction(Hb::BackNaviAction, this);
-    BTUI_ASSERT_X(mSoftKeyBackAction, "BtCpUiBaseView::BtCpUiBaseView", "can't create back action");
+    BTUI_ASSERT_X(mSoftKeyBackAction, "BtCpUiSearchView::BtCpUiSearchView", "can't create back action");
     
     // Create view for the application.
     // Set the name for the view. The name should be same as the view's
@@ -62,6 +65,7 @@
     setObjectName("bt_search_view");
 
     mLoader = new HbDocumentLoader();
+    BTUI_ASSERT_X( mLoader != 0, "BtCpUiSearchView::BtCpUiSearchView", "can't create mLoader" );
     // Pass the view to documentloader. Document loader uses this view
     // when docml is parsed, instead of creating new view.
     QObjectList objectList;
@@ -83,21 +87,21 @@
     mDeviceIcon=0;
     // can't use qobject_cast since HbIcon is not derived from QObject!
     mDeviceIcon = qobject_cast<HbLabel *>( mLoader->findWidget( "icon" ) );  
-    BTUI_ASSERT_X( mDeviceIcon != 0, "bt-search-view", "Device Icon not found" );
+    BTUI_ASSERT_X( mDeviceIcon != 0, "BtCpUiSearchView::BtCpUiSearchView", "Device Icon not found" );
     
-    mLabelFoundDevices=0;
-    mLabelFoundDevices = qobject_cast<HbLabel *>( mLoader->findWidget( "label_found_devices" ) );
-    BTUI_ASSERT_X( mLabelFoundDevices != 0, "bt-search-view", "Found Devices not found" );
-    mLabelFoundDevices->setPlainText(hbTrId("txt_bt_subhead_bluetooth_found_devices"));
+    mDataForm=0;
+    mDataForm = qobject_cast<HbDataForm *>( mLoader->findWidget( "dataForm" ) );
+    BTUI_ASSERT_X( mDataForm != 0, "BtCpUiSearchView::BtCpUiSearchView", "dataForm not found" );
+    mDataForm->setHeading(hbTrId("txt_bt_subhead_bluetooth_found_devices"));
 
     mLabelSearching=0;
     mLabelSearching = qobject_cast<HbLabel *>( mLoader->findWidget( "label_searching" ) );
-    BTUI_ASSERT_X( mLabelSearching != 0, "bt-search-view", "Searching not found" );
+    BTUI_ASSERT_X( mLabelSearching != 0, "BtCpUiSearchView::BtCpUiSearchView", "Searching not found" );
     mLabelSearching->setPlainText(hbTrId("txt_bt_subhead_searching"));
     
     mDeviceList=0;
     mDeviceList = qobject_cast<HbListView *>( mLoader->findWidget( "deviceList" ) );
-    BTUI_ASSERT_X( mDeviceList != 0, "bt-search-view", "Device List not found" );   
+    BTUI_ASSERT_X( mDeviceList != 0, "BtCpUiSearchView::BtCpUiSearchView", "Device List not found" );   
     
     
     mDeviceList->setSelectionMode( HbAbstractItemView::SingleSelection );
@@ -107,10 +111,10 @@
     
     if (mOrientation == Qt::Horizontal) {
         mLoader->load(BTUI_SEARCHVIEW_DOCML, "landscape_ui", &ok);
-        BTUI_ASSERT_X( ok, "bt-search-view", "Invalid docml file: landscape section problem" );
+        BTUI_ASSERT_X( ok, "BtCpUiSearchView::BtCpUiSearchView", "Invalid docml file: landscape section problem" );
     } else {
         mLoader->load(BTUI_SEARCHVIEW_DOCML, "portrait_ui", &ok);
-        BTUI_ASSERT_X( ok, "bt-search-view", "Invalid docml file: portrait section problem" );        
+        BTUI_ASSERT_X( ok, "BtCpUiSearchView::BtCpUiSearchView", "Invalid docml file: portrait section problem" );        
     }
 
     // listen for orientation changes
@@ -120,38 +124,30 @@
     
     // load tool bar actions
     mViewBy = static_cast<HbAction*>( mLoader->findObject( "viewByAction" ) );
-    BTUI_ASSERT_X( mViewBy, "bt-search-view", "view by action missing" ); 
+    BTUI_ASSERT_X( mViewBy, "BtCpUiSearchView::BtCpUiSearchView", "view by action missing" ); 
     ret = connect(mViewBy, SIGNAL(triggered()), this, SLOT(viewByDeviceTypeDialog()));
-    BTUI_ASSERT_X( ret, "bt-search-view", "viewByAction can't connect" ); 
+    BTUI_ASSERT_X( ret, "BtCpUiSearchView::BtCpUiSearchView", "viewByAction can't connect" ); 
 
     mStop = static_cast<HbAction*>( mLoader->findObject( "stopAction" ) );
-    BTUI_ASSERT_X( mStop, "bt-search-view", "stopAction missing" ); 
+    BTUI_ASSERT_X( mStop, "BtCpUiSearchView::BtCpUiSearchView", "stopAction missing" ); 
     ret = connect(mStop, SIGNAL(triggered()), this, SLOT(stopSearching()));
-    BTUI_ASSERT_X( ret, "bt-search-view", "stopAction can't connect" ); 
+    BTUI_ASSERT_X( ret, "BtCpUiSearchView::BtCpUiSearchView", "stopAction can't connect" ); 
     mStop->setEnabled(true);
     
     mRetry = static_cast<HbAction*>( mLoader->findObject( "retryAction" ) );
-    BTUI_ASSERT_X( mRetry, "bt-search-view", "retryAction missing" ); 
+    BTUI_ASSERT_X( mRetry, "BtCpUiSearchView::BtCpUiSearchView", "retryAction missing" ); 
     ret = connect(mRetry, SIGNAL(triggered()), this, SLOT(retrySearch()));
-    BTUI_ASSERT_X( ret, "bt-search-view", "retryAction can't connect" ); 
+    BTUI_ASSERT_X( ret, "BtCpUiSearchView::BtCpUiSearchView", "retryAction can't connect" ); 
     // Disable for initial search
     mRetry->setEnabled(false);
     
     // load menu
     HbMenu *optionsMenu = qobject_cast<HbMenu *>(mLoader->findWidget("viewMenu"));
-    BTUI_ASSERT_X( optionsMenu != 0, "bt-search-view", "Options menu not found" );   
+    BTUI_ASSERT_X( optionsMenu != 0, "BtCpUiSearchView::BtCpUiSearchView", "Options menu not found" );   
     this->setMenu(optionsMenu);      
     
-    mExit = static_cast<HbAction*>( mLoader->findObject( "exitAction" ) );
-    BTUI_ASSERT_X( mExit, "bt-search-view", "exitAction missing" ); 
-    mExit->setText(hbTrId("txt_common_opt_exit"));
-    
-    mConnect = static_cast<HbAction*>( mLoader->findObject( "connectAction" ) );
-    BTUI_ASSERT_X( mConnect, "bt-search-view", "connectAction missing" ); 
-    mConnect->setText(hbTrId("txt_bt_menu_connect"));
-    
     ret = connect(mDeviceList, SIGNAL(activated(QModelIndex)), this, SLOT(deviceSelected(QModelIndex)));
-    BTUI_ASSERT_X( ret, "bt-search-view", "deviceSelected can't connect" ); 
+    BTUI_ASSERT_X( ret, "BtCpUiSearchView::BtCpUiSearchView", "deviceSelected can't connect" ); 
     
     // initialize device type list for "view by" option
     // Note:  this list needs to be in the same order as enum devTypeSelectionList
@@ -181,13 +177,7 @@
     // Create the inquiry delegate.
     mAbstractDelegate = BtDelegateFactory::newDelegate(BtDelegate::Inquiry, mSettingModel, mDeviceModel );
     
-    // Connect to the signal from the BtDelegateInquiry for completion of the search request
-    ret = connect(mAbstractDelegate, SIGNAL(commandCompleted(int)), this, SLOT(searchDelegateCompleted(int)));
-    BTUI_ASSERT_X( ret, "bt-search-view", "searchDelegateCompleted can't connect" );
-    
-    // Connect to the signal from the BtuiModel when the search has been completed.
-    ret = connect(mDeviceModel, SIGNAL(deviceSearchCompleted(int)), this, SLOT(deviceSearchCompleted(int)));
-    BTUI_ASSERT_X( ret, "bt-search-view", "deviceSearchCompleted can't connect" ); 
+
 }
 
 BtCpUiSearchView::~BtCpUiSearchView()
@@ -199,6 +189,7 @@
     delete mSoftKeyBackAction;
     
     if(mAbstractDelegate) {
+        disconnect(mAbstractDelegate);   
         delete mAbstractDelegate;
     }
     if(mBtuiModelSortFilter) {
@@ -218,11 +209,11 @@
     if( orientation == Qt::Vertical ) {
         // load "portrait" section
         mLoader->load( BTUI_SEARCHVIEW_DOCML, "portrait_ui", &ok );
-        BTUI_ASSERT_X( ok, "bt-search-view", "Invalid docml file: portrait section problem" );
+        BTUI_ASSERT_X( ok, "BtCpUiSearchView::changeOrientation", "Invalid docml file: portrait section problem" );
     } else {
         // load "landscape" section
         mLoader->load( BTUI_SEARCHVIEW_DOCML, "landscape_ui", &ok );
-        BTUI_ASSERT_X( ok, "bt-search-view", "Invalid docml file: landscape section problem" );
+        BTUI_ASSERT_X( ok, "BtCpUiSearchView::changeOrientation", "Invalid docml file: landscape section problem" );
     }
 }
 
@@ -293,26 +284,31 @@
             mBtuiModelSortFilter->addDeviceMajorFilter(devTypesWanted,
                     BtuiModelSortFilter::RoughMatch);             // device can be any one of selected ones
         }
-        mBtuiModelSortFilter->sort(0, Qt::AscendingOrder);
     }
 }
 
 void BtCpUiSearchView::stopSearching()
 {
     // Stop searching
-    
-    // Change label and buttons to reflect status
-    mLabelSearching->setPlainText(hbTrId("txt_bt_subhead_search_done"));
-    mRetry->setEnabled(true);
-    mStop->setEnabled(false);    
 
     // Stop search delegate
     mAbstractDelegate->cancel();
+    // reset view 
+    deviceSearchCompleted(KErrNone);      
 }
 
 void BtCpUiSearchView::startSearchDelegate ()
 {
+    bool ret = false;
     
+    // Connect to the signal from the BtDelegateInquiry for completion of the search request
+    ret = connect(mAbstractDelegate, SIGNAL(commandCompleted(int)), this, SLOT(searchDelegateCompleted(int)));
+    BTUI_ASSERT_X( ret, "BtCpUiSearchView::BtCpUiSearchView", "searchDelegateCompleted can't connect" );
+    
+    // Connect to the signal from the BtuiModel when the search has been completed.
+    ret = connect(mDeviceModel, SIGNAL(deviceSearchCompleted(int)), this, SLOT(deviceSearchCompleted(int)));
+    BTUI_ASSERT_X( ret, "BtCpUiSearchView::BtCpUiSearchView", "deviceSearchCompleted can't connect" );     
+
     mAbstractDelegate->exec(QVariant());
 }
 
@@ -354,7 +350,8 @@
     setSoftkeyBack();
             
     if ( !fromBackButton ) {
-        startSearchDelegate();
+        // Sets the label and toolbar buttons
+        retrySearch();
     }
 }
 
@@ -374,9 +371,14 @@
 {
     //TODO - handle error.
     Q_UNUSED(error);
+    
     mLabelSearching->setPlainText(hbTrId("txt_bt_subhead_search_done"));
     mRetry->setEnabled(true);
-    mStop->setEnabled(false);    
+    mStop->setEnabled(false);
+    
+    // disconnect signals
+    disconnect(mAbstractDelegate);
+    disconnect(mDeviceModel);
 }
 
 void BtCpUiSearchView::deviceSelected(const QModelIndex& modelIndex)
--- a/bluetoothengine/btui/btcpplugin/btcpuisearchview.h	Tue Jul 06 14:27:09 2010 +0300
+++ b/bluetoothengine/btui/btcpplugin/btcpuisearchview.h	Wed Aug 18 09:59:05 2010 +0300
@@ -31,6 +31,8 @@
 class HbListView;
 class BtAbstractDelegate;
 class HbSelectionDialog;
+class HbGroupBox;
+class HbDataForm;
 
 class BtCpUiSearchView : public BtCpUiBaseView
 {
@@ -72,7 +74,7 @@
 private:
     HbDocumentLoader *mLoader;
     HbLabel *mDeviceIcon;
-    HbLabel *mLabelFoundDevices;
+    HbDataForm *mDataForm;
     HbLabel *mLabelSearching;        
     HbListView *mDeviceList;
     QStringList mDevTypeList;
@@ -86,8 +88,6 @@
     HbAction*               mViewBy;
     HbAction*               mStop;
     HbAction*               mRetry;
-    HbAction*               mExit;
-    HbAction*               mConnect;
 
     //pointer to abstract delegate, and it is instantiated at runtime
     BtAbstractDelegate*     mAbstractDelegate;
--- a/bluetoothengine/btui/btcpplugin/docml/bt-device-view.docml	Tue Jul 06 14:27:09 2010 +0300
+++ b/bluetoothengine/btui/btcpplugin/docml/bt-device-view.docml	Wed Aug 18 09:59:05 2010 +0300
@@ -1,15 +1,14 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <hbdocument version="1.1">
-    <object name="Menu_item_exit" type="HbAction">
-        <string locid="txt_common_opt_exit" name="text" value="Exit"/>
+    <object name="menu_item_home" type="HbAction">
+        <string name="text" value="Add to home screen"/>
     </object>
     <widget name="bt_device_view" type="HbView">
         <widget name="content" role="HbView:widget" type="HbWidget">
-            <widget name="groupBox_deviceView" type="HbGroupBox">
+            <widget name="dataForm_deviceView" type="HbDataForm">
                 <real name="z" value="1"/>
                 <sizepolicy horizontalPolicy="Expanding" horizontalStretch="0" verticalPolicy="Preferred" verticalStretch="0"/>
-                <sizehint height="4.92537un" type="PREFERRED" width="53.73134un"/>
-                <bool name="collapsable" value="FALSE"/>
+                <sizehint height="7.8806un" type="PREFERRED" width="53.73134un"/>
                 <string locid="txt_bt_subhead_bluetooth_device" name="heading" value="Bluetooth device"/>
             </widget>
             <widget name="deviceCategory" type="HbLabel">
@@ -43,6 +42,7 @@
                 <real name="z" value="2"/>
                 <sizehint height="16.41791un" type="PREFERRED" width="53.73134un"/>
                 <string name="description"/>
+                <string name="heading"/>
             </widget>
             <widget name="pushButton_0" type="HbPushButton">
                 <icon iconName="qtg_mono_bt_unpair" name="icon"/>
@@ -66,13 +66,13 @@
                 <string name="text" value="Settings"/>
             </widget>
             <layout type="anchor">
-                <anchoritem dst="groupBox_deviceView" dstEdge="LEFT" spacing="0un" src="" srcEdge="LEFT"/>
-                <anchoritem dst="groupBox_deviceView" dstEdge="TOP" spacing="0un" src="" srcEdge="TOP"/>
-                <anchoritem dst="groupBox_deviceView" dstEdge="RIGHT" spacing="0un" src="" srcEdge="RIGHT"/>
+                <anchoritem dst="dataForm_deviceView" dstEdge="LEFT" spacing="0un" src="" srcEdge="LEFT"/>
+                <anchoritem dst="dataForm_deviceView" dstEdge="TOP" spacing="0un" src="" srcEdge="TOP"/>
+                <anchoritem dst="dataForm_deviceView" dstEdge="RIGHT" spacing="0un" src="" srcEdge="RIGHT"/>
                 <anchoritem dst="deviceIcon" dstEdge="LEFT" spacing="var(hb-param-margin-gene-left)" src="" srcEdge="LEFT"/>
-                <anchoritem dst="deviceIcon" dstEdge="TOP" spacing="var(hb-param-margin-gene-top)" src="groupBox_deviceView" srcEdge="BOTTOM"/>
+                <anchoritem dst="deviceIcon" dstEdge="TOP" spacing="var(hb-param-margin-gene-top)" src="dataForm_deviceView" srcEdge="BOTTOM"/>
                 <anchoritem dst="deviceName" dstEdge="LEFT" spacing="2un" src="deviceIcon" srcEdge="RIGHT"/>
-                <anchoritem dst="deviceName" dstEdge="TOP" spacing="var(hb-param-margin-gene-top)" src="groupBox_deviceView" srcEdge="BOTTOM"/>
+                <anchoritem dst="deviceName" dstEdge="TOP" spacing="var(hb-param-margin-gene-top)" src="dataForm_deviceView" srcEdge="BOTTOM"/>
                 <anchoritem dst="deviceName" dstEdge="RIGHT" spacing="-var(hb-param-margin-gene-right)" src="" srcEdge="RIGHT"/>
                 <anchoritem dst="deviceStatus" dstEdge="LEFT" spacing="12un" src="" srcEdge="LEFT"/>
                 <anchoritem dst="deviceStatus" dstEdge="TOP" spacing="var(hb-param-margin-gene-bottom)" src="deviceCategory" srcEdge="BOTTOM"/>
@@ -82,33 +82,33 @@
                 <anchoritem dst="deviceCategory" dstEdge="RIGHT" spacing="-var(hb-param-margin-gene-right)" src="" srcEdge="RIGHT"/>
                 <anchoritem dst="pushButton_2" dstEdge="LEFT" spacing="expr(var(hb-param-margin-gene-left) )" src="" srcEdge="LEFT"/>
                 <anchoritem dst="pushButton_2" dstEdge="TOP" spacing="expr(var(hb-param-margin-gene-bottom) )" src="pushButton_1" srcEdge="BOTTOM"/>
-                <anchoritem dst="pushButton_2" dstEdge="RIGHT" spacing="expr(-var(hb-param-margin-gene-right) )" src="" srcEdge="RIGHT"/>
+                <anchoritem dst="pushButton_2" dstEdge="RIGHT" spacing="-expr(var(hb-param-margin-gene-right) )" src="" srcEdge="RIGHT"/>
                 <anchoritem dst="connectionCombobox" dstEdge="LEFT" spacing="0un" src="" srcEdge="LEFT"/>
                 <anchoritem dst="connectionCombobox" dstEdge="TOP" spacing="expr(var(hb-param-margin-gene-top) )" src="deviceStatus" srcEdge="BOTTOM"/>
                 <anchoritem dst="connectionCombobox" dstEdge="RIGHT" spacing="0un" src="" srcEdge="RIGHT"/>
                 <anchoritem dst="pushButton_1" dstEdge="LEFT" spacing="expr(var(hb-param-margin-gene-left) )" src="" srcEdge="LEFT"/>
                 <anchoritem dst="pushButton_1" dstEdge="TOP" spacing="expr(var(hb-param-margin-gene-middle-vertical) )" src="pushButton_0" srcEdge="BOTTOM"/>
-                <anchoritem dst="pushButton_1" dstEdge="RIGHT" spacing="expr(-var(hb-param-margin-gene-right) )" src="" srcEdge="RIGHT"/>
+                <anchoritem dst="pushButton_1" dstEdge="RIGHT" spacing="-expr(var(hb-param-margin-gene-right) )" src="" srcEdge="RIGHT"/>
                 <anchoritem dst="pushButton_0" dstEdge="LEFT" spacing="expr(var(hb-param-margin-gene-left) )" src="" srcEdge="LEFT"/>
                 <anchoritem dst="pushButton_0" dstEdge="TOP" spacing="expr(var(hb-param-margin-gene-top) )" src="connectionCombobox" srcEdge="BOTTOM"/>
-                <anchoritem dst="pushButton_0" dstEdge="RIGHT" spacing="expr(-var(hb-param-margin-gene-right) )" src="" srcEdge="RIGHT"/>
+                <anchoritem dst="pushButton_0" dstEdge="RIGHT" spacing="-expr(var(hb-param-margin-gene-right) )" src="" srcEdge="RIGHT"/>
             </layout>
         </widget>
         <widget name="viewMenu" role="HbView:menu" type="HbMenu">
-            <ref object="Menu_item_exit" role="HbWidget:addAction"/>
+            <ref object="menu_item_home" role="HbWidget:addAction"/>
         </widget>
         <string locid="txt_cp_title_control_panel" name="title" value="Control Panel"/>
     </widget>
     <section name="landscape">
         <widget name="content" role="HbView:widget" type="HbWidget">
             <layout type="anchor">
-                <anchoritem dst="groupBox_deviceView" dstEdge="LEFT" spacing="0un" src="" srcEdge="LEFT"/>
-                <anchoritem dst="groupBox_deviceView" dstEdge="TOP" spacing="0un" src="" srcEdge="TOP"/>
-                <anchoritem dst="groupBox_deviceView" dstEdge="RIGHT" spacing="0un" src="" srcEdge="RIGHT"/>
+                <anchoritem dst="dataForm_deviceView" dstEdge="LEFT" spacing="0un" src="" srcEdge="LEFT"/>
+                <anchoritem dst="dataForm_deviceView" dstEdge="TOP" spacing="0un" src="" srcEdge="TOP"/>
+                <anchoritem dst="dataForm_deviceView" dstEdge="RIGHT" spacing="0un" src="" srcEdge="RIGHT"/>
                 <anchoritem dst="deviceIcon" dstEdge="LEFT" spacing="var(hb-param-margin-gene-left)" src="" srcEdge="LEFT"/>
-                <anchoritem dst="deviceIcon" dstEdge="TOP" spacing="var(hb-param-margin-gene-top)" src="groupBox_deviceView" srcEdge="BOTTOM"/>
+                <anchoritem dst="deviceIcon" dstEdge="TOP" spacing="var(hb-param-margin-gene-top)" src="dataForm_deviceView" srcEdge="BOTTOM"/>
                 <anchoritem dst="deviceName" dstEdge="LEFT" spacing="2un" src="deviceIcon" srcEdge="RIGHT"/>
-                <anchoritem dst="deviceName" dstEdge="TOP" spacing="var(hb-param-margin-gene-top)" src="groupBox_deviceView" srcEdge="BOTTOM"/>
+                <anchoritem dst="deviceName" dstEdge="TOP" spacing="var(hb-param-margin-gene-top)" src="dataForm_deviceView" srcEdge="BOTTOM"/>
                 <anchoritem dst="deviceName" dstEdge="RIGHT" spacing="-var(hb-param-margin-gene-right)" src="" srcEdge="RIGHT"/>
                 <anchoritem dst="deviceCategory" dstEdge="LEFT" spacing="2un" src="deviceIcon" srcEdge="RIGHT"/>
                 <anchoritem dst="deviceCategory" dstEdge="TOP" spacing="var(hb-param-margin-gene-middle-vertical)" src="deviceName" srcEdge="BOTTOM"/>
@@ -123,23 +123,23 @@
                 <anchoritem dst="pushButton_0" dstEdge="RIGHT" spacing="-var(hb-param-margin-gene-right)" src="" srcEdge="CENTERH"/>
                 <anchoritem dst="pushButton_1" dstEdge="LEFT" spacing="var(hb-param-margin-gene-middle-horizontal)" src="pushButton_0" srcEdge="RIGHT"/>
                 <anchoritem dst="pushButton_1" dstEdge="TOP" spacing="expr(var(hb-param-margin-gene-top) )" src="connectionCombobox" srcEdge="BOTTOM"/>
-                <anchoritem dst="pushButton_1" dstEdge="RIGHT" spacing="expr(-var(hb-param-margin-gene-right) )" src="" srcEdge="RIGHT"/>
+                <anchoritem dst="pushButton_1" dstEdge="RIGHT" spacing="-expr(var(hb-param-margin-gene-right) )" src="" srcEdge="RIGHT"/>
                 <anchoritem dst="pushButton_2" dstEdge="LEFT" spacing="expr(var(hb-param-margin-gene-left) )" src="" srcEdge="LEFT"/>
                 <anchoritem dst="pushButton_2" dstEdge="TOP" spacing="var(hb-param-margin-gene-middle-vertical)" src="pushButton_1" srcEdge="BOTTOM"/>
-                <anchoritem dst="pushButton_2" dstEdge="RIGHT" spacing="expr(-var(hb-param-margin-gene-right) )" src="" srcEdge="RIGHT"/>
+                <anchoritem dst="pushButton_2" dstEdge="RIGHT" spacing="-expr(var(hb-param-margin-gene-right) )" src="" srcEdge="RIGHT"/>
             </layout>
         </widget>
     </section>
     <section name="portrait">
-    	<widget name="content" role="HbView:widget" type="HbWidget">
-    		<layout type="anchor">
-                <anchoritem dst="groupBox_deviceView" dstEdge="LEFT" spacing="0un" src="" srcEdge="LEFT"/>
-                <anchoritem dst="groupBox_deviceView" dstEdge="TOP" spacing="0un" src="" srcEdge="TOP"/>
-                <anchoritem dst="groupBox_deviceView" dstEdge="RIGHT" spacing="0un" src="" srcEdge="RIGHT"/>
+        <widget name="content" role="HbView:widget" type="HbWidget">
+            <layout type="anchor">
+                <anchoritem dst="dataForm_deviceView" dstEdge="LEFT" spacing="0un" src="" srcEdge="LEFT"/>
+                <anchoritem dst="dataForm_deviceView" dstEdge="TOP" spacing="0un" src="" srcEdge="TOP"/>
+                <anchoritem dst="dataForm_deviceView" dstEdge="RIGHT" spacing="0un" src="" srcEdge="RIGHT"/>
                 <anchoritem dst="deviceIcon" dstEdge="LEFT" spacing="var(hb-param-margin-gene-left)" src="" srcEdge="LEFT"/>
-                <anchoritem dst="deviceIcon" dstEdge="TOP" spacing="var(hb-param-margin-gene-top)" src="groupBox_deviceView" srcEdge="BOTTOM"/>
+                <anchoritem dst="deviceIcon" dstEdge="TOP" spacing="var(hb-param-margin-gene-top)" src="dataForm_deviceView" srcEdge="BOTTOM"/>
                 <anchoritem dst="deviceName" dstEdge="LEFT" spacing="2un" src="deviceIcon" srcEdge="RIGHT"/>
-                <anchoritem dst="deviceName" dstEdge="TOP" spacing="var(hb-param-margin-gene-top)" src="groupBox_deviceView" srcEdge="BOTTOM"/>
+                <anchoritem dst="deviceName" dstEdge="TOP" spacing="var(hb-param-margin-gene-top)" src="dataForm_deviceView" srcEdge="BOTTOM"/>
                 <anchoritem dst="deviceName" dstEdge="RIGHT" spacing="-var(hb-param-margin-gene-right)" src="" srcEdge="RIGHT"/>
                 <anchoritem dst="deviceStatus" dstEdge="LEFT" spacing="12un" src="" srcEdge="LEFT"/>
                 <anchoritem dst="deviceStatus" dstEdge="TOP" spacing="var(hb-param-margin-gene-bottom)" src="deviceCategory" srcEdge="BOTTOM"/>
@@ -149,18 +149,18 @@
                 <anchoritem dst="deviceCategory" dstEdge="RIGHT" spacing="-var(hb-param-margin-gene-right)" src="" srcEdge="RIGHT"/>
                 <anchoritem dst="pushButton_2" dstEdge="LEFT" spacing="expr(var(hb-param-margin-gene-left) )" src="" srcEdge="LEFT"/>
                 <anchoritem dst="pushButton_2" dstEdge="TOP" spacing="expr(var(hb-param-margin-gene-bottom) )" src="pushButton_1" srcEdge="BOTTOM"/>
-                <anchoritem dst="pushButton_2" dstEdge="RIGHT" spacing="expr(-var(hb-param-margin-gene-right) )" src="" srcEdge="RIGHT"/>
+                <anchoritem dst="pushButton_2" dstEdge="RIGHT" spacing="-expr(var(hb-param-margin-gene-right) )" src="" srcEdge="RIGHT"/>
                 <anchoritem dst="connectionCombobox" dstEdge="LEFT" spacing="0un" src="" srcEdge="LEFT"/>
                 <anchoritem dst="connectionCombobox" dstEdge="TOP" spacing="expr(var(hb-param-margin-gene-top) )" src="deviceStatus" srcEdge="BOTTOM"/>
                 <anchoritem dst="connectionCombobox" dstEdge="RIGHT" spacing="0un" src="" srcEdge="RIGHT"/>
                 <anchoritem dst="pushButton_1" dstEdge="LEFT" spacing="expr(var(hb-param-margin-gene-left) )" src="" srcEdge="LEFT"/>
                 <anchoritem dst="pushButton_1" dstEdge="TOP" spacing="expr(var(hb-param-margin-gene-middle-vertical) )" src="pushButton_0" srcEdge="BOTTOM"/>
-                <anchoritem dst="pushButton_1" dstEdge="RIGHT" spacing="expr(-var(hb-param-margin-gene-right) )" src="" srcEdge="RIGHT"/>
+                <anchoritem dst="pushButton_1" dstEdge="RIGHT" spacing="-expr(var(hb-param-margin-gene-right) )" src="" srcEdge="RIGHT"/>
                 <anchoritem dst="pushButton_0" dstEdge="LEFT" spacing="expr(var(hb-param-margin-gene-left) )" src="" srcEdge="LEFT"/>
                 <anchoritem dst="pushButton_0" dstEdge="TOP" spacing="expr(var(hb-param-margin-gene-top) )" src="connectionCombobox" srcEdge="BOTTOM"/>
-                <anchoritem dst="pushButton_0" dstEdge="RIGHT" spacing="expr(-var(hb-param-margin-gene-right) )" src="" srcEdge="RIGHT"/>
+                <anchoritem dst="pushButton_0" dstEdge="RIGHT" spacing="-expr(var(hb-param-margin-gene-right) )" src="" srcEdge="RIGHT"/>
             </layout>
-    	</widget>
+        </widget>
     </section>
     <metadata activeUIState="Common ui state" display="NHD-3.2-inch_portrait" unit="un">
         <uistate name="Common ui state" sections="#common"/>
--- a/bluetoothengine/btui/btcpplugin/docml/bt-main-view.docml	Tue Jul 06 14:27:09 2010 +0300
+++ b/bluetoothengine/btui/btcpplugin/docml/bt-main-view.docml	Wed Aug 18 09:59:05 2010 +0300
@@ -15,26 +15,8 @@
     <object name="advanceSettings" type="HbAction">
         <string locid="txt_bt_opt_advanced_settings" name="text" value="Advanced Settings"/>
     </object>
-    <object name="audioDevices" type="HbAction">
-        <string locid="txt_bt_list_audio_device" name="text" value="Audio Devices"/>
-    </object>
-    <object name="computers" type="HbAction">
-        <string locid="txt_bt_list_computer" name="text" value="Computers"/>
-    </object>
-    <object name="inputDevices" type="HbAction">
-        <string locid="txt_bt_list_input_device" name="text" value="Input Devices"/>
-    </object>
-    <object name="otherDevices" type="HbAction">
-        <string locid="txt_bt_list_other" name="text" value="Other Devices"/>
-    </object>
-    <object name="removePairedDevices" type="HbAction">
-        <string locid="txt_bt_opt_remove_paired_devices" name="text" value="Remove Paired Devices"/>
-    </object>
-    <object name="exit" type="HbAction">
-        <string locid="txt_common_opt_exit" name="text" value="Exit"/>
-    </object>
-    <object name="phones" type="HbAction">
-        <string locid="txt_bt_list_phone" name="text" value="Phones"/>
+    <object name="showOnly" type="HbAction">
+        <string locid="txt_bt_opt_show" name="text" value="Show only"/>
     </object>
     <widget name="view" type="HbView">
         <widget name="content" role="HbView:widget" type="HbWidget">
@@ -45,8 +27,9 @@
                 <ref object="discoverAction" role="HbWidget:addAction"/>
             </widget>
             <widget name="container_1" type="HbWidget">
-                <widget name="groupBox" type="HbGroupBox">
-                    <bool name="collapsable" value="FALSE"/>
+                <widget name="dataForm" type="HbDataForm">
+                    <widget name="dataformviewItemPrototype" role="HbAbstractView:prototype" type="HbDataFormViewItem"/>
+                    <sizehint height="7.8806un" type="MINIMUM"/>
                     <string locid="txt_bt_subhead_bluetooth_paired_devices" name="heading" value="Bluetooth"/>
                 </widget>
                 <widget name="container" type="HbWidget">
@@ -101,13 +84,14 @@
                 <sizehint height="23.8806un" type="PREFERRED" width="11.9403un"/>
                 <layout orientation="Vertical" spacing="0un" type="linear">
                     <contentsmargins bottom="0un" left="0un" right="0un" top="0un"/>
-                    <linearitem itemname="groupBox"/>
+                    <linearitem itemname="dataForm"/>
                     <linearitem itemname="container"/>
                 </layout>
             </widget>
             <widget name="listView" type="HbListView">
                 <widget name="listItemPrototype" role="HbAbstractView:prototype" type="HbListViewItem"/>
                 <enums name="selectionMode" value="NoSelection"/>
+                <sizepolicy horizontalPolicy="Expanding" horizontalStretch="0" verticalPolicy="Preferred" verticalStretch="0"/>
                 <sizehint height="47.7612un" type="PREFERRED" width="35.8209un"/>
             </widget>
             <layout orientation="Vertical" spacing="var(hb-param-margin-gene-middle-vertical)" type="linear">
@@ -118,21 +102,35 @@
             </layout>
         </widget>
         <widget name="viewMenu" role="HbView:menu" type="HbMenu">
-            <widget name="subMenu" role="HbMenu:menu" type="HbMenu">
-                <ref object="audioDevices" role="HbWidget:addAction"/>
-                <ref object="computers" role="HbWidget:addAction"/>
-                <ref object="phones" role="HbWidget:addAction"/>
-                <ref object="inputDevices" role="HbWidget:addAction"/>
-                <ref object="otherDevices" role="HbWidget:addAction"/>
-                <string locid="txt_bt_opt_show" name="title" value="Show Only"/>
-            </widget>
             <ref object="advanceSettings" role="HbWidget:addAction"/>
-            <ref object="removePairedDevices" role="HbWidget:addAction"/>
-            <ref object="exit" role="HbWidget:addAction"/>
+            <ref object="showOnly" role="HbWidget:addAction"/>
         </widget>
         <string locid="txt_cp_title_control_panel" name="title" value="Control Panel"/>
     </widget>
     <section name="portrait">
+        <widget name="combobox" type="HbComboBox">
+            <sizehint height="var(hb-param-graphic-size-primary-large)" type="PREFERRED" width="31.34328un"/>
+        </widget>
+        <widget name="content" role="HbView:widget" type="HbWidget">
+            <layout orientation="Vertical" spacing="var(hb-param-margin-gene-middle-vertical)" type="linear">
+                <contentsmargins bottom="0un" left="0un" right="0un" top="0un"/>
+                <linearitem itemname="dataForm"/>
+                <linearitem itemname="container"/>
+                <linearitem itemname="listView"/>
+                <linearitem itemname="toolBar"/>
+            </layout>
+        </widget>
+        <widget name="lineEdit" type="HbLineEdit">
+            <sizehint type="PREFERRED" width="29.25373un"/>
+        </widget>
+        <widget name="pushButton" type="HbPushButton">
+            <sizehint height="var(hb-param-graphic-size-primary-large)" type="PREFERRED" width="var(hb-param-graphic-size-primary-large)"/>
+            <sizehint height="var(hb-param-graphic-size-primary-large)" type="MAXIMUM" width="var(hb-param-graphic-size-primary-large)"/>
+        </widget>
+        <widget name="icon" type="HbLabel">
+            <sizehint height="var(hb-param-graphic-size-primary-large)" type="PREFERRED" width="var(hb-param-graphic-size-primary-large)"/>
+            <sizehint height="var(hb-param-graphic-size-primary-large)" type="MAXIMUM" width="var(hb-param-graphic-size-primary-large)"/>
+        </widget>
         <widget name="container" type="HbWidget">
             <layout type="anchor">
                 <anchoritem dst="icon" dstEdge="LEFT" spacing="var(hb-param-margin-gene-left)" src="" srcEdge="LEFT"/>
@@ -149,30 +147,17 @@
                 <anchoritem dst="pushButton" dstEdge="BOTTOM" spacing="0un" src="" srcEdge="BOTTOM"/>
             </layout>
         </widget>
-        <widget name="pushButton" type="HbPushButton">
-            <sizehint height="var(hb-param-graphic-size-primary-large)" type="PREFERRED" width="var(hb-param-graphic-size-primary-large)"/>
-            <sizehint height="var(hb-param-graphic-size-primary-large)" type="MAXIMUM" width="var(hb-param-graphic-size-primary-large)"/>
+    </section>
+    <section name="landscape">
+        <widget name="combobox" type="HbComboBox">
+            <sizehint height="var(hb-param-graphic-size-primary-large)" type="PREFERRED" width="34.92537un"/>
         </widget>
-        <widget name="content" role="HbView:widget" type="HbWidget">
-            <layout orientation="Vertical" spacing="var(hb-param-margin-gene-middle-vertical)" type="linear">
-                <linearitem itemname="groupBox"/>
-                <linearitem itemname="container"/>
-                <linearitem itemname="listView"/>
-                <linearitem itemname="toolBar"/>
-            </layout>
+        <widget name="lineEdit" type="HbLineEdit">
+            <sizehint height="var(hb-param-graphic-size-primary-large)" type="PREFERRED" width="33un"/>
         </widget>
         <widget name="icon" type="HbLabel">
             <sizehint height="var(hb-param-graphic-size-primary-large)" type="PREFERRED" width="var(hb-param-graphic-size-primary-large)"/>
-            <sizehint height="var(hb-param-graphic-size-primary-large)" type="MAXIMUM" width="var(hb-param-graphic-size-primary-large)"/>
         </widget>
-        <widget name="lineEdit" type="HbLineEdit">
-            <sizehint type="PREFERRED" width="29.25373un"/>
-        </widget>
-        <widget name="combobox" type="HbComboBox">
-            <sizehint height="var(hb-param-graphic-size-primary-large)" type="PREFERRED" width="31.34328un"/>
-        </widget>
-    </section>
-    <section name="landscape">
         <widget name="container" type="HbWidget">
             <layout type="anchor">
                 <anchoritem dst="icon" dstEdge="LEFT" spacing="var(hb-param-margin-gene-left)" src="" srcEdge="LEFT"/>
@@ -186,15 +171,6 @@
                 <anchoritem dst="pushButton" dstEdge="TOP" spacing="expr(var(hb-param-margin-gene-top) )" src="" srcEdge="TOP"/>
             </layout>
         </widget>
-        <widget name="icon" type="HbLabel">
-            <sizehint height="var(hb-param-graphic-size-primary-large)" type="PREFERRED" width="var(hb-param-graphic-size-primary-large)"/>
-        </widget>
-        <widget name="lineEdit" type="HbLineEdit">
-            <sizehint height="var(hb-param-graphic-size-primary-large)" type="PREFERRED" width="33un"/>
-        </widget>
-        <widget name="combobox" type="HbComboBox">
-            <sizehint height="var(hb-param-graphic-size-primary-large)" type="PREFERRED" width="34.92537un"/>
-        </widget>
     </section>
     <metadata activeUIState="Common ui state" display="NHD-3.2-inch_portrait" unit="un">
         <uistate name="Common ui state" sections="#common"/>
--- a/bluetoothengine/btui/btcpplugin/docml/bt-search-view.docml	Tue Jul 06 14:27:09 2010 +0300
+++ b/bluetoothengine/btui/btcpplugin/docml/bt-search-view.docml	Wed Aug 18 09:59:05 2010 +0300
@@ -13,27 +13,15 @@
         <icon iconName="qtg_mono_search" name="icon"/>
         <string name="text"/>
     </object>
-    <object name="exitAction" type="HbAction">
-        <string locid="txt_common_opt_exit" name="text" value="Exit"/>
-    </object>
-    <object name="connectAction" type="HbAction">
-        <string locid="txt_bt_menu_connect" name="text" value="Connect"/>
-    </object>
     <object name="disconnectAction" type="HbAction">
         <string name="text" value="Disconnect"/>
     </object>
     <widget name="bt_search_view" type="HbView">
         <widget name="search_view_content" role="HbView:widget" type="HbWidget">
             <widget name="search_container" type="HbWidget">
-                <widget name="label_found_devices" type="HbLabel">
-                    <real name="z" value="3"/>
-                    <sizehint height="var(hb-param-graphic-size-primary-large)" type="PREFERRED" width="38.20896un"/>
-                    <bool name="visible" value="TRUE"/>
-                    <string locid="txt_bt_subhead_bluetooth_found_devices" name="plainText" value="Bluetooth - Found devices"/>
-                </widget>
                 <widget name="icon" type="HbLabel">
                     <enums name="alignment" value="AlignVCenter|AlignHCenter"/>
-                    <icon iconName="note_warning" name="icon"/>
+                    <icon iconName="qtg_anim_small_loading.axml" name="icon"/>
                     <real name="z" value="2"/>
                     <sizehint height="var(hb-param-graphic-size-primary-large)" type="PREFERRED" width="var(hb-param-graphic-size-primary-large)"/>
                     <sizehint height="var(hb-param-graphic-size-primary-large)" type="MAXIMUM" width="var(hb-param-graphic-size-primary-large)"/>
@@ -45,20 +33,29 @@
                     <bool name="visible" value="TRUE"/>
                     <string locid="txt_bt_subhead_searching" name="plainText" value="Searching..."/>
                 </widget>
+                <widget name="dataForm" type="HbDataForm">
+                    <widget name="dataformviewItemPrototype" role="HbAbstractView:prototype" type="HbDataFormViewItem"/>
+                    <real name="z" value="4"/>
+                    <sizepolicy horizontalPolicy="Expanding" horizontalStretch="0" verticalPolicy="Expanding" verticalStretch="0"/>
+                    <sizehint type="PREFERRED" width="25un"/>
+                    <string locid="txt_bt_subhead_bluetooth_found_devices" name="heading" value="Found devices"/>
+                </widget>
                 <real name="z" value="0"/>
-                <sizehint height="21un" type="PREFERRED" width="51.19403un"/>
+                <sizepolicy horizontalPolicy="Preferred" horizontalStretch="0" verticalPolicy="Expanding" verticalStretch="0"/>
+                <sizehint height="12.784un" type="PREFERRED" width="51.19403un"/>
+                <sizehint height="14.784un" type="MAXIMUM"/>
                 <bool name="visible" value="TRUE"/>
                 <layout type="anchor">
-                    <anchoritem dst="label_found_devices" dstEdge="TOP" spacing="var(hb-param-margin-gene-top)" src="" srcEdge="TOP"/>
-                    <anchoritem dst="label_found_devices" dstEdge="LEFT" spacing="var(hb-param-margin-gene-left)" src="" srcEdge="LEFT"/>
-                    <anchoritem dst="label_found_devices" dstEdge="RIGHT" spacing="-var(hb-param-margin-gene-right)" src="" srcEdge="RIGHT"/>
-                    <anchoritem dst="icon" dstEdge="TOP" spacing="var(hb-param-margin-gene-top)" src="label_found_devices" srcEdge="BOTTOM"/>
+                    <anchoritem dst="dataForm" dstEdge="LEFT" spacing="0un" src="" srcEdge="LEFT"/>
+                    <anchoritem dst="dataForm" dstEdge="TOP" spacing="0un" src="" srcEdge="TOP"/>
+                    <anchoritem dst="dataForm" dstEdge="RIGHT" spacing="0un" src="" srcEdge="RIGHT"/>
+                    <anchoritem dst="label_searching" dstEdge="LEFT" spacing="var(hb-param-margin-gene-left)" src="icon" srcEdge="RIGHT"/>
+                    <anchoritem dst="label_searching" dstEdge="TOP" spacing="expr(var(hb-param-margin-gene-middle-vertical) )" src="dataForm" srcEdge="BOTTOM"/>
+                    <anchoritem dst="label_searching" dstEdge="RIGHT" spacing="-var(hb-param-margin-gene-right)" src="" srcEdge="RIGHT"/>
+                    <anchoritem dst="label_searching" dstEdge="BOTTOM" spacing="0un" src="" srcEdge="BOTTOM"/>
                     <anchoritem dst="icon" dstEdge="LEFT" spacing="var(hb-param-margin-gene-left)" src="" srcEdge="LEFT"/>
-                    <anchoritem dst="icon" dstEdge="BOTTOM" spacing="-var(hb-param-margin-gene-bottom)" src="" srcEdge="BOTTOM"/>
-                    <anchoritem dst="label_searching" dstEdge="TOP" spacing="var(hb-param-margin-gene-top)" src="label_found_devices" srcEdge="BOTTOM"/>
-                    <anchoritem dst="label_searching" dstEdge="LEFT" spacing="var(hb-param-margin-gene-left)" src="icon" srcEdge="RIGHT"/>
-                    <anchoritem dst="label_searching" dstEdge="BOTTOM" spacing="-var(hb-param-margin-gene-bottom)" src="" srcEdge="BOTTOM"/>
-                    <anchoritem dst="label_searching" dstEdge="RIGHT" spacing="-var(hb-param-margin-gene-right)" src="" srcEdge="RIGHT"/>
+                    <anchoritem dst="icon" dstEdge="TOP" spacing="expr(var(hb-param-margin-gene-top) )" src="dataForm" srcEdge="BOTTOM"/>
+                    <anchoritem dst="icon" dstEdge="BOTTOM" spacing="0un" src="" srcEdge="BOTTOM"/>
                 </layout>
             </widget>
             <widget name="toolBar" type="HbToolBar">
@@ -72,37 +69,49 @@
                 <enums name="horizontalScrollBarPolicy" value="ScrollBarAsNeeded"/>
             </widget>
             <real name="z" value="0"/>
-            <layout orientation="Vertical" type="linear">
+            <layout orientation="Vertical" spacing="0un" type="linear">
+                <contentsmargins bottom="0un" left="0un" right="0un" top="0un"/>
                 <linearitem itemname="search_container"/>
                 <linearitem itemname="deviceList"/>
                 <linearitem itemname="toolBar"/>
             </layout>
         </widget>
-        <widget name="viewMenu" role="HbView:menu" type="HbMenu">
-            <ref object="exitAction" role="HbWidget:addAction"/>
-            <ref object="connectAction" role="HbWidget:addAction"/>
-        </widget>
+        <widget name="viewMenu" role="HbView:menu" type="HbMenu"/>
         <string locid="txt_cp_title_control_panel" name="title" value="Control Panel"/>
         <real name="z" value="1"/>
     </widget>
     <section name="landscape">
+        <widget name="icon" type="HbLabel">
+            <sizepolicy horizontalPolicy="Expanding" horizontalStretch="0" verticalPolicy="Preferred" verticalStretch="0"/>
+        </widget>
+        <widget name="dataForm" type="HbDataForm">
+            <sizepolicy horizontalPolicy="Expanding" horizontalStretch="0" verticalPolicy="Expanding" verticalStretch="0"/>
+            <sizehint type="PREFERRED" width="51.19403un"/>
+        </widget>
+        <widget name="label_searching" type="HbLabel">
+            <sizepolicy horizontalPolicy="Expanding" horizontalStretch="0" verticalPolicy="Preferred" verticalStretch="0"/>
+        </widget>
         <widget name="search_container" type="HbWidget">
-            <sizehint height="10un" type="PREFERRED" width="51.19403un"/>
+            <sizepolicy horizontalPolicy="Preferred" horizontalStretch="0" verticalPolicy="Ignored" verticalStretch="0"/>
+            <sizehint height="12un" type="PREFERRED" width="51.19403un"/>
+            <sizehint height="12.75un" type="MAXIMUM"/>
             <layout type="anchor">
-                <anchoritem dst="label_found_devices" dstEdge="TOP" spacing="var(hb-param-margin-gene-top)" src="" srcEdge="TOP"/>
-                <anchoritem dst="label_found_devices" dstEdge="LEFT" spacing="var(hb-param-margin-gene-left)" src="" srcEdge="LEFT"/>
-                <anchoritem dst="label_found_devices" dstEdge="BOTTOM" spacing="-var(hb-param-margin-gene-bottom)" src="" srcEdge="BOTTOM"/>
-                <anchoritem dst="icon" dstEdge="TOP" spacing="var(hb-param-margin-gene-top)" src="" srcEdge="TOP"/>
-                <anchoritem dst="icon" dstEdge="LEFT" spacing="var(hb-param-margin-gene-left)" src="label_found_devices" srcEdge="RIGHT"/>
-                <anchoritem dst="icon" dstEdge="BOTTOM" spacing="-var(hb-param-margin-gene-bottom)" src="" srcEdge="BOTTOM"/>
+                <anchoritem dst="icon" dstEdge="TOP" spacing="0un" src="" srcEdge="TOP"/>
+                <anchoritem dst="icon" dstEdge="BOTTOM" spacing="0un" src="" srcEdge="BOTTOM"/>
+                <anchoritem dst="label_searching" dstEdge="BOTTOM" spacing="-var(hb-param-margin-gene-bottom)" src="" srcEdge="BOTTOM"/>
+                <anchoritem dst="label_searching" dstEdge="RIGHT" spacing="-var(hb-param-margin-gene-right)" src="" srcEdge="RIGHT"/>
                 <anchoritem dst="label_searching" dstEdge="TOP" spacing="var(hb-param-margin-gene-top)" src="" srcEdge="TOP"/>
                 <anchoritem dst="label_searching" dstEdge="LEFT" spacing="var(hb-param-margin-gene-left)" src="icon" srcEdge="RIGHT"/>
-                <anchoritem dst="label_searching" dstEdge="BOTTOM" spacing="-var(hb-param-margin-gene-bottom)" src="" srcEdge="BOTTOM"/>
-                <anchoritem dst="label_searching" dstEdge="RIGHT" spacing="-var(hb-param-margin-gene-right)" src="" srcEdge="RIGHT"/>
+                <anchoritem dst="icon" dstEdge="LEFT" spacing="0un" src="dataForm" srcEdge="RIGHT"/>
+                <anchoritem dst="icon" dstEdge="RIGHT" spacing="0un" src="label_searching" srcEdge="LEFT"/>
+                <anchoritem dst="dataForm" dstEdge="RIGHT" spacing="0un" src="icon" srcEdge="LEFT"/>
+                <anchoritem dst="dataForm" dstEdge="LEFT" spacing="0un" src="" srcEdge="LEFT"/>
+                <anchoritem dst="dataForm" dstEdge="TOP" spacing="0un" src="" srcEdge="TOP"/>
+                <anchoritem dst="dataForm" dstEdge="BOTTOM" spacing="0un" src="" srcEdge="BOTTOM"/>
             </layout>
         </widget>
     </section>
-    <metadata activeUIState="portrait_ui" display="NHD-3.2-inch_portrait" unit="un">
+    <metadata activeUIState="landscape_ui" display="NHD-3.2-inch_landscape" unit="un">
         <uistate name="Common ui state" sections="#common"/>
         <uistate name="landscape_ui" sections="#common landscape"/>
         <uistate name="portrait_ui" sections="#common"/>
--- a/bluetoothengine/btui/btuidelegate/btdelegateInquiry.h	Tue Jul 06 14:27:09 2010 +0300
+++ b/bluetoothengine/btui/btuidelegate/btdelegateInquiry.h	Wed Aug 18 09:59:05 2010 +0300
@@ -16,8 +16,8 @@
 */
 
 
-#ifndef BTDELEGATEINQUIRY_H_
-#define BTDELEGATEINQUIRY_H_
+#ifndef BTDELEGATEINQUIRY_H
+#define BTDELEGATEINQUIRY_H
 
 #include <e32base.h>
 #include <btengsettings.h>
@@ -53,4 +53,4 @@
     
 };
 
-#endif /* BTDELEGATEINQUIRY_H_ */
+#endif /* BTDELEGATEINQUIRY_H */
--- a/bluetoothengine/btui/btuidelegate/btdelegateconnect.cpp	Tue Jul 06 14:27:09 2010 +0300
+++ b/bluetoothengine/btui/btuidelegate/btdelegateconnect.cpp	Wed Aug 18 09:59:05 2010 +0300
@@ -162,8 +162,8 @@
             QString questionText(hbTrId("txt_bt_info_to_connect_1_2_needs_to_be_disconnec")
                     .arg(mDeviceName).arg(conflictDevName));
             
-            HbMessageBox::question( questionText, this, SLOT(handleUserAnswer(HbAction*)), 
-                    hbTrId("txt_common_button_continue"), hbTrId("txt_common_button_cancel") );        
+            HbMessageBox::question( questionText, this, SLOT(handleUserAnswer(int)), 
+                    HbMessageBox::Continue | HbMessageBox::Cancel );       
         }
     }
     else {
@@ -175,10 +175,9 @@
 /*!
  * handle user response to query about disconnecting conflict device
  */
-void BtDelegateConnect::handleUserAnswer( HbAction* answer )
+void BtDelegateConnect::handleUserAnswer( int answer )
 {
-    HbMessageBox* dlg = static_cast<HbMessageBox*>( sender() );
-    if( dlg->actions().first() == answer ) { 
+    if( answer == HbMessageBox::Continue ) { 
         // Continue, ie. disconnect conflict device and then try reconnecting again
         if (!mAbstractDelegate) //if there is no other delegate running
         { 
--- a/bluetoothengine/btui/btuidelegate/btdelegateconnect.h	Tue Jul 06 14:27:09 2010 +0300
+++ b/bluetoothengine/btui/btuidelegate/btdelegateconnect.h	Wed Aug 18 09:59:05 2010 +0300
@@ -54,7 +54,7 @@
     virtual void DisconnectComplete( TBTDevAddr& aAddr, TInt aErr );
   
 private slots:
-    void handleUserAnswer( HbAction* answer );
+    void handleUserAnswer( int answer );
     void powerDelegateCompleted(int status);
     void disconnectDelegateCompleted(int status);
     
--- a/bluetoothengine/btui/btuidelegate/btdelegatedevsecurity.cpp	Tue Jul 06 14:27:09 2010 +0300
+++ b/bluetoothengine/btui/btuidelegate/btdelegatedevsecurity.cpp	Wed Aug 18 09:59:05 2010 +0300
@@ -14,11 +14,9 @@
 * Description: 
 *
 */
-
+#include "btdelegatedevsecurity.h"
+#include "btqtconstants.h"
 #include <QModelIndex>
-
-#include "btqtconstants.h"
-#include "btdelegatedevsecurity.h"
 #include <btsettingmodel.h>
 #include <btdevicemodel.h>
 #include <btdelegatefactory.h>
--- a/bluetoothengine/btui/btuidelegate/btdelegatedevsecurity.h	Tue Jul 06 14:27:09 2010 +0300
+++ b/bluetoothengine/btui/btuidelegate/btdelegatedevsecurity.h	Wed Aug 18 09:59:05 2010 +0300
@@ -21,7 +21,6 @@
 #include <e32base.h>
 #include <btengconnman.h>
 #include <btengdevman.h>
-#include <btengconnman.h>
 #include "btabstractdelegate.h"
 
 class BtuiModel;
--- a/bluetoothengine/btui/btuidelegate/btdelegatepower.cpp	Tue Jul 06 14:27:09 2010 +0300
+++ b/bluetoothengine/btui/btuidelegate/btdelegatepower.cpp	Wed Aug 18 09:59:05 2010 +0300
@@ -91,7 +91,7 @@
         if (btEnabledInOffline){
             // BT is allowed to be enabled in offline mode, show query.
             HbMessageBox::question( hbTrId("txt_bt_info_trun_bluetooth_on_ini_offline_mode" ),this, 
-				SLOT(btOnQuestionClose(HbAction*)));
+							SLOT(btOnQuestionClose(int)), HbMessageBox::Yes | HbMessageBox::No );
 
         }
         else{
@@ -113,11 +113,10 @@
     
 }
 
-void BtDelegatePower::btOnQuestionClose(HbAction *action)
+void BtDelegatePower::btOnQuestionClose(int action)
 {
-    HbMessageBox *dlg = static_cast<HbMessageBox*>(sender());
     int err = 0;
-    if(action == dlg->actions().at(0)) 
+    if(action == HbMessageBox::Yes) 
     {
         //user chooses "yes" for using BT in offline 
         mActiveHandling = true;
--- a/bluetoothengine/btui/btuidelegate/btdelegatepower.h	Tue Jul 06 14:27:09 2010 +0300
+++ b/bluetoothengine/btui/btuidelegate/btdelegatepower.h	Wed Aug 18 09:59:05 2010 +0300
@@ -53,7 +53,7 @@
     virtual void VisibilityModeChanged( TBTVisibilityMode aState );
     
 public slots:
-    void btOnQuestionClose(HbAction *action);
+    void btOnQuestionClose(int action);
     
     void btOnWarningClose();
     
--- a/bluetoothengine/btui/btuidelegate/btdelegateremotedevname.cpp	Tue Jul 06 14:27:09 2010 +0300
+++ b/bluetoothengine/btui/btuidelegate/btdelegateremotedevname.cpp	Wed Aug 18 09:59:05 2010 +0300
@@ -26,7 +26,7 @@
 
 BtDelegateRemoteDevName::BtDelegateRemoteDevName(BtSettingModel* settingModel, 
         BtDeviceModel* deviceModel,QObject *parent )
-    :BtAbstractDelegate( settingModel, deviceModel, parent ), mRegistryActive(0)
+    :BtAbstractDelegate( settingModel, deviceModel, parent ), mRegistryActive(0), mRegistryOpened(false)
 {
     
 }
@@ -35,7 +35,8 @@
 {
     delete mRegistryActive;
     mSymName.Close();
-    mBtRegistry.Close();
+    if (mRegistryOpened)
+        mBtRegistry.Close();//there is crash is close the btregistry without opening it first
     mBtRegServ.Close();
 }
 
@@ -70,11 +71,20 @@
     QVariant nameVariant = paramList.at(1); 
     QString btRemoteDevName = nameVariant.toString();
     
+    if (!validateName(btRemoteDevName)){
+            emit commandCompleted(KErrBadName);
+            return;
+    }
+    mNewName = btRemoteDevName;
+    /*
+    QModelIndex start = getDeviceModel()->index(0,0);
+    QModelIndexList indexList = getDeviceModel()->match(start,BtDeviceModel::NameAliasRole, mNewName);
+    if (indexList.size() > 1){
+        emit commandCompleted(KErrBadName, mNewName);
+        return;
+    }
+    */
     int error = KErrNone;
-            
-    validateName(btRemoteDevName);
-    mNewName = btRemoteDevName;
-    
     TPtrC ptrName(reinterpret_cast<const TText*>(btRemoteDevName.constData()));
   
     error = mSymName.Create(ptrName.Length());
@@ -105,6 +115,8 @@
         emit commandCompleted(error,mNewName);
         return;
     }
+    mRegistryOpened = true;
+    
     if (!mRegistryActive){
         RequestIdentifiers requestId = Unknown;
         TRAP(error, mRegistryActive = CBtSimpleActive::NewL(
--- a/bluetoothengine/btui/btuidelegate/btdelegateremotedevname.h	Tue Jul 06 14:27:09 2010 +0300
+++ b/bluetoothengine/btui/btuidelegate/btdelegateremotedevname.h	Wed Aug 18 09:59:05 2010 +0300
@@ -72,6 +72,8 @@
     
     TBTDevAddr mSymaddr;
     
+    bool mRegistryOpened;
+    
 
 private:
 
--- a/bluetoothengine/btui/btuimodel/btdevicemodel_p.h	Tue Jul 06 14:27:09 2010 +0300
+++ b/bluetoothengine/btui/btuimodel/btdevicemodel_p.h	Wed Aug 18 09:59:05 2010 +0300
@@ -15,8 +15,8 @@
 *
 */
 
-#ifndef BTDEVICEMODE_P_H
-#define BTDEVICEMODE_P_H
+#ifndef BTDEVICEMODELPRIVATE_H
+#define BTDEVICEMODELPRIVATE_H
 
 #include "btuimodeltypes.h"
 #include <btdevicemodel.h>
@@ -137,4 +137,4 @@
 
 };
 
-#endif // BTLOCALSETTING_H
+#endif // BTDEVICEMODELPRIVATE_H
--- a/bluetoothengine/btui/inc/btuiiconutil.h	Tue Jul 06 14:27:09 2010 +0300
+++ b/bluetoothengine/btui/inc/btuiiconutil.h	Wed Aug 18 09:59:05 2010 +0300
@@ -21,7 +21,7 @@
 #include <qglobal.h>
 #include <bt_sock.h>
 #include <HbIcon>
-#include "btdevicemodel.h"
+//#include "btdevicemodel.h"
 #include "btuidevtypemap.h"
 
 enum BtuiIconCorner {
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/btobexprofiles/inc/BTServiceParameterList.h	Wed Aug 18 09:59:05 2010 +0300
@@ -0,0 +1,239 @@
+/*
+* Copyright (c) 2002 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"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description:  Parameter list
+*
+*/
+
+
+#ifndef BT_SERVICE_PARAMETER_LIST_H
+#define BT_SERVICE_PARAMETER_LIST_H
+
+// INCLUDES
+#include <e32std.h>
+#include <badesca.h>    // CDesCArray
+#include <f32file.h>
+
+// CONSTANTS
+
+// DATA TYPES
+
+struct TBTSUXhtmlParam
+    {
+    TDesC* iFileName;
+    CDesCArray* iRefObjectList;
+    };
+
+struct TBTSUImageParam
+    {    
+    RFile   iFile; 
+    TDesC*  iDisplayName;
+    TDesC8* iMimeType;
+    TSize   iPixelSize;
+    TInt    iFileSize;    
+    TBool   iSend;
+    
+    };
+    
+
+// CLASS DECLARATION
+
+/**
+*  A class holding paths to different types of files. 
+*
+*  In case of an XHTML file the list collects paths 
+*  to objects referenced in the file.
+*
+*  In case of an image the list resolves the MIME types and
+*  displayable names of the images.
+*
+*  @lib BtServiceUtils.lib
+*  @since Series 60 2.6
+*/
+class CBTServiceParameterList : public CBase
+    {
+    public: // Constructors and destructor
+        
+        /**
+        * Two-phased constructor.
+        */
+        IMPORT_C static CBTServiceParameterList* NewL();
+        IMPORT_C static CBTServiceParameterList* NewLC();
+        
+        /**
+        * Destructor.
+        */
+        virtual ~CBTServiceParameterList();
+
+    public: // New functions
+
+        /**
+        * Adds an xhtml file path to the list.
+        * @since Series 60 2.6
+        * @param aFilePath A full path and file name.
+        * @return None.
+        */
+        IMPORT_C void AddXhtmlL( const TDesC& aFilePath );
+
+        /**
+        * Adds an image file path to the list.
+        * @since Series 60 2.6
+        * @param aFilePath A full path and file name.
+        * @return None.
+        */
+        IMPORT_C void AddImageL( const TDesC& aFilePath );
+        
+        /**
+        * Adds an image file path to the list.
+        * @since Series 60 2.6
+        * @param aFile file handle to be send.
+        * @return None.
+        */
+        IMPORT_C void AddImageL( RFile aFile );
+
+        /**
+        * Adds an object file path to the list.
+        * @since Series 60 2.6
+        * @param aFilePath A full path and file name.
+        * @return None.
+        */
+        IMPORT_C void AddObjectL( const TDesC& aFilePath );
+        
+        /**
+        * Adds an object file path to the list.
+        * @since Series 60 2.6
+        * @param aFile file handle to be send .
+        * @return None.
+        */
+        IMPORT_C void AddObjectL( RFile aFile );
+
+    public: // New functions (not exported)
+        
+        /**
+        * Return the number of xhtml file paths in the list.
+        * @return The count.
+        */
+        TInt XhtmlCount() const;
+
+        /**
+        * Return the number of image file paths in the list.
+        * @return The count.
+        */
+        TInt ImageCount() const;
+
+        /**
+        * Return the number of object file paths in the list.
+        * @return The count.
+        */
+        TInt ObjectCount() const;
+        
+        /**
+        * Returns a copy of an element of the list from the given index.
+        * @param aIndex The index.
+        * @return The element.
+        */
+        TBTSUXhtmlParam XhtmlAt( TInt aIndex ) const;
+
+        /**
+        * Returns a copy of an element of the list from the given index.
+        * @param aIndex The index.
+        * @return The element.
+        */
+        TBTSUImageParam ImageAtL( TInt aIndex ) const;
+
+        /**
+        * Returns a copy of an element of the list from the given index.
+        * @param aIndex The index.
+        * @return The element.
+        */
+        RFile& ObjectAtL( TInt aIndex );
+
+        /**
+        * Checks whether the list has any xhtml-files with referenced objects.
+        * @return A boolean according to result.
+        */
+        TBool HasAnyReferencedObjects() const;
+
+        /**
+        * Return the size of objects in the list.
+        * @return The count.
+        */
+        TInt ObjectListSizeL() const;
+        
+        /**
+        * Return the size of images in the list.
+        * @return The count.
+        */
+        
+        TInt ImageListSize() const;
+        
+        /**
+        * Remove image from list.
+        * @param aIndex The index.
+        * @return None.
+        */
+        void RemoveImageL(TInt aIndex);
+        
+        /**
+        * Return count of removed image        
+        * @return The count of removed images.
+        */
+        TInt RemovedImageCount();
+        
+        /**
+        * Reset image filehandle
+        * @param aIndex The index.
+        * @return None.
+        */
+        void ResetImageHandleL(TInt aIndex);
+        
+        /**
+        * Reset object filehandle
+        * @param aIndex The index.
+        * @return None.
+        */
+        void ResetObjectHandleL(TInt aIndex);  
+        
+        
+        /**
+        * Reset image filehandle
+        * @param aIndex The index.
+        * @return None.
+        */
+        void MarkAsSendL(TInt aIndex);        
+                
+
+    private:
+
+        /**
+        * C++ default constructor.
+        */
+        CBTServiceParameterList();
+
+        /**
+        * By default Symbian 2nd phase constructor is private.
+        */
+        void ConstructL();
+
+    private: // Data
+
+        RArray<TBTSUXhtmlParam> iXhtmlList;
+        RArray<TBTSUImageParam> iImageList;
+        RArray<RFile> iObjectList;
+        RFs iFileSession;        
+        TInt iRemovedImageCount;
+    };
+
+#endif      // BT_SERVICE_PARAMETER_LIST_H
+            
+// End of File
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/btobexprofiles/inc/btserviceapi.h	Wed Aug 18 09:59:05 2010 +0300
@@ -0,0 +1,105 @@
+/*
+* Copyright (c) 2002 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"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description:  API for sending services
+*
+*/
+
+
+
+#ifndef BT_SERVICE_API_H
+#define BT_SERVICE_API_H
+
+//  INCLUDES
+#include "BTServiceParameterList.h"
+
+// CONSTANTS
+
+// DATA TYPES
+
+enum TBTServiceType
+    {
+    EBTSendingService,
+    EBTPrintingService,
+    EBTObjectPushService // use this if support for only OPP is wanted
+    };
+
+// FORWARD DECLARATIONS
+class CBTServiceStarter;
+
+// CLASS DECLARATION
+
+/**
+*  An API for starting Bluetooth services.
+*
+*  @lib BtServiceUtils.lib
+*  @since Series 60 2.6
+*/
+class CBTServiceAPI : public CBase
+    {
+    public:  // Constructors and destructor
+        
+        /**
+        * Two-phased constructor.
+        */
+        IMPORT_C static CBTServiceAPI* NewL();
+        
+        /**
+        * Destructor.
+        */
+        virtual ~CBTServiceAPI();
+
+    public: // New functions
+        
+        /**
+        * Starts the given service.
+        * Returns when service is started.
+        * @since Series 60 2.6
+        * @param aService The service to be started.
+        * @param aList Parameters for the service.
+        * @return None.
+        */
+        IMPORT_C void StartServiceL( TBTServiceType aService, 
+                                     CBTServiceParameterList* aList );
+
+        /**
+        * Starts the given service.
+        * Returns when service is completed.
+        * @since Series 60 2.6
+        * @param aService The service to be started.
+        * @param aList Parameters for the service.
+        * @return None.
+        */
+        IMPORT_C void StartSynchronousServiceL( TBTServiceType aService, 
+                                     CBTServiceParameterList* aList );
+    private:
+
+        /**
+        * C++ default constructor.
+        */
+        CBTServiceAPI();
+
+        /**
+        * By default Symbian 2nd phase constructor is private.
+        */
+        void ConstructL();
+
+    private:    // Data
+
+        CBTServiceStarter*      iStarter;
+        CActiveSchedulerWait    iSyncWaiter;
+    };
+
+#endif      // BT_SERVICE_API_H
+            
+// End of File
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/btobexprofiles/inc/obexutilsdialog.h	Wed Aug 18 09:59:05 2010 +0300
@@ -0,0 +1,271 @@
+/*
+* Copyright (c) 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"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description: 
+*
+*/
+
+
+#ifndef COBEXUTILSDIALOG_H
+#define COBEXUTILSDIALOG_H
+
+#include    <e32base.h>
+
+#include <hbdeviceprogressdialogsymbian.h>
+#include <hbdevicedialogsymbian.h>
+#include <hbdevicemessageboxsymbian.h>
+#include <hbsymbianvariant.h>
+
+class CObexUtilsDialogTimer;
+
+enum TButtonId
+    {
+    ECancelButton = -1,
+    EYesButton,
+    ENoButton
+    };
+/**
+*  An observer interface for asking progress status of an operation using 
+*  a progress dialog.
+*/
+NONSHARABLE_CLASS(  MObexUtilsProgressObserver )
+    {
+    public:
+
+        /**
+        * Returns the progress status of the operation.
+        * @since 2.6
+        * @return A progress value relative to final value.
+        */
+        virtual TInt GetProgressStatus() = 0;
+    };
+
+// CLASS DECLARATION
+
+/**
+*  An observer interface for informing about dialog events.
+*/
+NONSHARABLE_CLASS(  MObexUtilsDialogObserver )
+    {
+    public:
+
+        /**
+        * Informs the observer that a dialog has been dismissed.
+        * @since 2.6
+        * todo check whether the parameter is required
+        * @param aButtonId The button that was used to dismiss the dialog.
+        */
+        virtual void DialogDismissed(TInt aButtonId) = 0; //TInt aButtonId
+    };
+
+
+// CLASS DECLARATION
+
+/**
+*  A class for launching and managing dialogs.
+*/
+NONSHARABLE_CLASS( CObexUtilsDialog ) : public CBase, 
+                                        public MHbDeviceProgressDialogObserver,
+                                        public MHbDeviceDialogObserver,
+                                        public MHbDeviceMessageBoxObserver
+    {
+    public:// Constructors and destructor
+
+        /**
+        * Two-phased constructor.
+        */
+        IMPORT_C static CObexUtilsDialog* NewL( 
+            MObexUtilsDialogObserver* aObserverPtr );        
+        
+        IMPORT_C static CObexUtilsDialog* NewLC( 
+            MObexUtilsDialogObserver* aObserverPtr );
+
+        /**
+        * Destructor.
+        */
+        virtual ~CObexUtilsDialog();
+   
+    public: // New functions
+        
+        
+        /**
+        * Launches a progress dialog.
+        * @param aObserverPtr A pointer to progress observer. A NULL pointer if 
+                              the progress dialog is updated manually.
+        * @param aFileCount Total number of files to be sent.
+        * @param aDeviceName Device Name to which files to be sent.
+        * @param aTimeoutValue A value telling how often should the dialog be
+                               updated. Relevant only if observer is given.
+        */
+        IMPORT_C void LaunchProgressDialogL( 
+            MObexUtilsProgressObserver* aObserverPtr, TInt aFileCount, 
+            const TDesC& aDeviceName, TInt aTimeoutValue );
+        
+        /**
+        * Updates the progress dialog with new file information when multiples files are sent.
+        * @param aFileSize Size of the file to be sent
+        * @param aFileIndex Index of the file to be sent
+        * @param aFileName Name of the file to be sent.
+        */
+        IMPORT_C void UpdateProgressNoteL( TInt aFileSize,TInt aFileIndex, const TDesC& aFileName );    
+        
+        /**
+        * Launches a wait dialog.
+        * @param aDisplayText Text that needs to be displayed.
+        */
+        IMPORT_C void LaunchWaitDialogL( const TDesC& aDisplayText );
+        
+        /**
+        * Cancels a wait dialog if one exists.
+        * @since 2.6        
+        * @return None.
+        */
+        IMPORT_C void CancelWaitDialog();
+        
+        /**
+        * Cancels a wait progress dialog if one exists.
+        * @since 2.6       
+        * @return None.
+        */
+        IMPORT_C void CancelProgressDialog();
+        
+        /**
+        * Updates a progress dialog with the latest progress value 
+        * @param aValue A progress value relative to final value.
+        * @return None
+        */
+        IMPORT_C void UpdateProgressDialogL( TInt aProgressValue );
+        
+        /**
+        * Show a query note
+        * @param aConfirmText text for the note.
+        * @return None		
+        */
+        IMPORT_C void LaunchQueryDialogL( const TDesC& aConfirmText );
+
+        /**
+        * Shows an error note.
+        * @param aTextId A resource id for the note.
+        * @return None.
+        */
+        IMPORT_C void ShowErrorNoteL( const TDesC& aErrorText );
+
+        /**
+        * Shows an information note.
+        * @param aTextId A resource id for the note.
+        * @return None.
+        */
+        IMPORT_C void ShowInformationNoteL( const TDesC& aInfoText );
+
+    public: // New functions (not exported)
+
+        /**
+        * Updates the progress dialog.
+        * @return None.
+        */
+        void UpdateProgressDialog();
+
+    private: // Functions from base classes
+        
+        /**
+        * From MHbDeviceProgressDialogObserver called when dialog is closed by pressing the "cancel" button
+        * @param aDialog Pointer to dialog that was cancelled.
+        * @return None.
+        */
+        void ProgressDialogCancelled(const CHbDeviceProgressDialogSymbian* aDialog);
+        
+        /**
+        * From MHbDeviceProgressDialogObserver called when a device progress dialog is has closed
+        * @param aDialog Pointer to dialog instance that has closed.
+        * @return None.
+        */
+        void ProgressDialogClosed(const CHbDeviceProgressDialogSymbian* aDialog )  ; 
+        
+        /**
+          * From MHbDeviceDialogObserver called when data is received from a device dialog
+          * @param aDialog Pointer to dialog instance that has closed.
+          * @return None.
+          */
+        void DataReceived(CHbSymbianVariantMap& aData);
+       
+        /**
+          * From MHbDeviceDialogObserver called when a device dialog is closed
+          * @param  aData contains data from the dialog plugin.
+          * @return None.
+          */
+         void DeviceDialogClosed(TInt aCompletionCode);
+        
+        /**
+        * from base class MHbDeviceMessageBoxObserver
+        * @param aMessageBox Pointer to dialog instance that has closed.
+        * @param aButton the id of the button the user pressed
+        */    
+        void  MessageBoxClosed(const CHbDeviceMessageBoxSymbian *aMessageBox, 
+                CHbDeviceMessageBoxSymbian::TButtonId aButton); 
+
+    private:
+
+        /**
+        * C++ default constructor.
+        */
+        CObexUtilsDialog( MObexUtilsDialogObserver* aObserverPtr );
+	
+        /**
+        * By default Symbian OS constructor is private.
+        */
+        void ConstructL();
+
+        /**
+         * Add a data item into the given CHbSymbianVariantMap.
+         * @param aMap the instance to which the data item will be added.
+         * @param aKey the key of the data item.
+         * @param aData the value of the data item
+         * @param aDataType the data-type of the data item
+         */
+        void AddDataL(CHbSymbianVariantMap* aMap, const TDesC& aKey, 
+                const TAny* aData, CHbSymbianVariant::TType aDataType);
+        
+        /**
+         * Creates and shows a message box.
+         * @param aType the type of the message box to create.
+         * @param aText the text to be shown in the message box
+         * @param aObserver the observer that receives the events from the 
+         *         message box
+         * @param aTimeout the timeout value of the message box 
+         */
+        CHbDeviceMessageBoxSymbian* CreateAndShowMessageBoxL(
+                CHbDeviceMessageBoxSymbian::TType aType,
+                const TDesC& aText, 
+                MHbDeviceMessageBoxObserver* aObserver,
+                TInt aTimeout );
+        
+    private: // Data
+
+        CHbDeviceDialogSymbian *iProgressDialog;
+        CHbDeviceProgressDialogSymbian* iWaitDialog;
+        CHbDeviceMessageBoxSymbian* iMessageBox;
+        
+        CObexUtilsDialogTimer*      iObexDialogTimer;
+        TInt                        iFileIndex;
+        TInt                        iFileCount;
+        RBuf                        iDeviceName;
+
+        // Not Owned
+        //
+        MObexUtilsProgressObserver* iProgressObserverPtr;
+        MObexUtilsDialogObserver*   iDialogObserverPtr;
+    };
+
+#endif      // COBEXUTILSDIALOG_H
+            
+// End of File
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/btobexprofiles/inc/obexutilspropertynotifier.h	Wed Aug 18 09:59:05 2010 +0300
@@ -0,0 +1,127 @@
+/*
+* Copyright (c) 2004 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"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description:  Declares disk status watcher class for ObexUtils.
+*
+*/
+
+
+
+#ifndef _OBEXUTILSPROPERTYNOTIFIER_H
+#define _OBEXUTILSPROPERTYNOTIFIER_H
+
+// INCLUDES
+#include <e32base.h>
+#include <e32property.h>
+#include <UikonInternalPSKeys.h>
+
+// CLASS DECLARATION
+
+	/**
+	Type of memory property check, 
+	@param  ECheckPhoneMemory, phone memory is checked, default value if not mentioned explicitly.	
+    @param  ECheckMMCMemory, MMC memory is checked.	
+	*/
+
+enum TMemoryPropertyCheckType
+	{
+	ECheckPhoneMemory,
+	ECheckMMCMemory
+	};
+
+	/**
+	A callback interface for informing content change of disk status. Client must derive 
+    from this class and implement HandleNotifyL() method. When disk space will cross warning
+    level or critical level this method will be call back.
+    */
+
+NONSHARABLE_CLASS(  MObexUtilsPropertyNotifyHandler )
+	{
+	public:
+        /**
+        * Callback method for disk status change
+        * @param aUid  UID identifying a shared data file where notify came from.
+        * @param aKey  keyword of which value was changed
+        */
+        virtual void HandleNotifyL( TMemoryPropertyCheckType aCheckType ) =0;
+	};
+
+NONSHARABLE_CLASS( CObexUtilsPropertyNotifier ) : public CActive
+	{
+public:  // NewL, Constructors and destructor
+
+    /*
+    * Two-phased constructor.
+    * @param aHandler -Pointer to the MObexUtilsPropertyNotifyHandler derived class
+    * @param aCheckType -Constant defining type of memory checking to be done (phone/MMC)
+    * @return CObexUtilsPropertyNotifier* -Initialized object.
+    */
+
+	IMPORT_C static CObexUtilsPropertyNotifier* NewL(
+	    MObexUtilsPropertyNotifyHandler* aHandler,
+	    TMemoryPropertyCheckType aCheckType=ECheckPhoneMemory );
+
+    /**
+    * Destructor.
+    */
+
+	virtual ~CObexUtilsPropertyNotifier();
+private:  // Functions from base classes
+
+    /**
+    * Constructor.
+    * @param aHandler -Pointer to the MObexUtilsPropertyNotifyHandler derived class
+    * @param aCheckType -Constant defining type of memory checking to be done (phone/MMC)
+    */
+
+	CObexUtilsPropertyNotifier(
+	    MObexUtilsPropertyNotifyHandler* aHandler,
+	    TMemoryPropertyCheckType aCheckType );
+
+	void ConstructL();
+
+	/**
+	Subscribes to a property and sets active
+	*/
+	void Subscribe();
+
+    /**
+    * From CActive Gets called when CActive::Cancel is called, 
+    *              cancels disk status watching.
+    *
+    * @param None.
+    * @return None.
+    */
+
+	void DoCancel();
+
+    /**
+    * From CActive Gets called when content of disk status is changed, 
+    *              calls MObexUtilsPropertyNotifyHandler::HandleNotify.
+    *
+    * @param None.
+    * @return None.
+    */
+
+	void RunL();
+
+private:
+	// Reference to observer
+	MObexUtilsPropertyNotifyHandler* iHandler;
+	// Type of memory check (phone/MMC)
+	TMemoryPropertyCheckType iCheckType;
+	// Database handle	
+	RProperty iProperty;
+	};
+
+#endif  // _OBEXUTILSPROPERTYNOTIFIER_H
--- a/btobexprofiles/obexreceiveservices/bip/inc/BIPController.h	Tue Jul 06 14:27:09 2010 +0300
+++ b/btobexprofiles/obexreceiveservices/bip/inc/BIPController.h	Wed Aug 18 09:59:05 2010 +0300
@@ -165,6 +165,9 @@
     CHbDeviceDialogSymbian*     iProgressDialog;
     TBool                       iDialogActive;
     TInt                        iFileCount;
+    TBool                       iReceivingFailed;
+    CHbDeviceDialogSymbian*     iRecvDoneDialog;
+    TBool                       iShowRecvCompleteDialog;
     };
     
 _LIT(KBipPanicCategory, "BIP");
--- a/btobexprofiles/obexreceiveservices/bip/src/BIPController.cpp	Tue Jul 06 14:27:09 2010 +0300
+++ b/btobexprofiles/obexreceiveservices/bip/src/BIPController.cpp	Wed Aug 18 09:59:05 2010 +0300
@@ -110,6 +110,7 @@
     iFs.Close();
     delete iDialog;
     delete iProgressDialog;
+    delete iRecvDoneDialog;
     TRACE_FUNC_EXIT    
     }
 
@@ -139,7 +140,8 @@
 void CBIPController::HandleError(TBool aAbort)
     {
     TRACE_FUNC_ENTRY
-    
+    iReceivingFailed = ETrue;
+    iShowRecvCompleteDialog = EFalse;
     if( iBTTransferState == ETransferPut || (!aAbort && iBTTransferState == ETransferPutDiskError) )
         {
         if(iBTObject)
@@ -188,6 +190,7 @@
 void CBIPController::TransportUpIndication()
     {
     TRACE_FUNC
+    iReceivingFailed = EFalse;
     if (!iFs.Handle())
         {
         TRACE_INFO( (_L( "[bipreceiveservice] TransportUpIndication iFs.Connect()" )) ); 
@@ -247,7 +250,63 @@
 //
 void CBIPController::TransportDownIndication()
     {
-    TRACE_FUNC   
+    TRACE_FUNC  
+    if(!iReceivingFailed && iShowRecvCompleteDialog)
+        {
+        //Launch recevice completed dialog.
+        iRecvDoneDialog = CHbDeviceDialogSymbian::NewL();
+        iRecvDoneDialog->SetObserver(this);
+    
+        CHbSymbianVariantMap* variantMap = CHbSymbianVariantMap::NewL();
+        CleanupStack::PushL(variantMap);
+        
+        TInt dialogIdx = TBluetoothDialogParams::EReceiveDone;
+        CHbSymbianVariant* dialogType = CHbSymbianVariant::NewL( (TAny*) &(dialogIdx), 
+                                                            CHbSymbianVariant::EInt );
+        CleanupStack::PushL(dialogType);
+        TBuf16<6> dialogTypeKey;
+        dialogTypeKey.Num(TBluetoothDialogParams::EDialogType);
+        User::LeaveIfError(variantMap->Add(dialogTypeKey, dialogType));
+        CleanupStack::Pop(dialogType);
+        
+        CHbSymbianVariant* deviceName = CHbSymbianVariant::NewL( (TAny*) (&iRemoteDeviceName), 
+                                                            CHbSymbianVariant::EDes );
+        CleanupStack::PushL(deviceName);
+        TBuf16<6> deviceNameKey;
+        deviceNameKey.Num(TBluetoothDeviceDialog::EDeviceName);
+        User::LeaveIfError(variantMap->Add(deviceNameKey, deviceName));
+        CleanupStack::Pop(deviceName);
+        
+        CHbSymbianVariant* fileName = CHbSymbianVariant::NewL( (TAny*) (&iReceivingFileName), 
+                                                            CHbSymbianVariant::EDes );
+        CleanupStack::PushL(fileName);
+        TBuf16<6> fileNameKey;
+        fileNameKey.Num(TBluetoothDeviceDialog::EReceivingFileName);
+        User::LeaveIfError(variantMap->Add(fileNameKey, fileName));
+        CleanupStack::Pop(fileName);
+        
+        CHbSymbianVariant* fileSz = CHbSymbianVariant::NewL( (TAny*) &iTotalSizeByte, 
+                                                            CHbSymbianVariant::EInt );
+        CleanupStack::PushL(fileSz);
+        TBuf16<6> fileSzKey;
+        fileSzKey.Num(TBluetoothDeviceDialog::EReceivingFileSize);
+        User::LeaveIfError(variantMap->Add(fileSzKey, fileSz));
+        CleanupStack::Pop(fileSz);
+        
+        CHbSymbianVariant* fileCnt = CHbSymbianVariant::NewL( (TAny*) &iFileCount, 
+                                                            CHbSymbianVariant::EInt );
+        CleanupStack::PushL(fileCnt);
+        TBuf16<6> fileCntKey;
+        fileCntKey.Num(TBluetoothDeviceDialog::EReceivedFileCount);
+        User::LeaveIfError(variantMap->Add(fileCntKey, fileCnt));
+        CleanupStack::Pop(fileCnt);
+        
+        iRecvDoneDialog->Show( KBTDevDialogId(), *variantMap, this );
+        CleanupStack::PopAndDestroy(variantMap);
+        
+        iShowRecvCompleteDialog = EFalse;
+        }
+    
     // Remove receiving buffer and files used during file receiving.
     //
     delete iBTObject;
@@ -381,6 +440,7 @@
         iBTTransferState = ETransferIdle;
         CloseReceivingIndicator();
         iFileCount++;
+        iShowRecvCompleteDialog = ETrue;
         }
     TRACE_FUNC_EXIT
     return retVal;
@@ -1004,15 +1064,28 @@
      if(aData.Keys().MdcaPoint(0).Compare(_L("actionResult")) == 0)
          {
          TInt val = *(static_cast<TInt*>(aData.Get(_L("actionResult"))->Data()));
-         if(!val)
+         switch(val)
              {
-             //Cancel has been clicked
-             CancelTransfer();
-             }
-         else
-             {
-             //Hide has been clicked
-             CloseReceivingIndicator(EFalse);
+             case TBluetoothDialogParams::ECancelReceive:
+                 {
+                 //User choose to cancel receiving.
+                 CancelTransfer();
+                 }break;
+                 
+             case TBluetoothDialogParams::EHide:
+                 {
+                 //Use choose to hide the progress dialog.
+                 CloseReceivingIndicator(EFalse);
+                 }break;
+                 
+             case TBluetoothDialogParams::EShow:
+             case TBluetoothDialogParams::ECancelShow:
+                 {
+                 //In case of Show, the device dialog will handle the opening of conversation view.
+                 iRecvDoneDialog->Cancel();
+                 delete iRecvDoneDialog;
+                 iRecvDoneDialog = NULL;
+                 }break;
              }
          }
      }
--- a/btobexprofiles/obexreceiveservices/btmsgviewer/btmsgviewer.pro	Tue Jul 06 14:27:09 2010 +0300
+++ b/btobexprofiles/obexreceiveservices/btmsgviewer/btmsgviewer.pro	Wed Aug 18 09:59:05 2010 +0300
@@ -30,7 +30,9 @@
     -lbluetooth \
     -lmsgs \
     -lapmime \
-    -lefsrv
+    -lefsrv \
+    -lapgrfx \
+    -lxqutils
 	
 SERVICE.FILE = service_conf.xml
 libFiles.sources = xqservice.dll
@@ -39,7 +41,7 @@
 libFiles.path = "!:\sys\bin"
 DEPLOYMENT += libFiles
 HEADERS += ./inc/btmsgviewer.h \
-		   ./inc/btmsgviewerutils.h
+		   ./inc/btmsgviewerutils.h 
 SOURCES += ./src/btmsgviewer.cpp \
     	   ./src/main.cpp \
     	   ./src/btmsgviewerutils.cpp
--- a/btobexprofiles/obexreceiveservices/btmsgviewer/inc/btmsgviewer.h	Tue Jul 06 14:27:09 2010 +0300
+++ b/btobexprofiles/obexreceiveservices/btmsgviewer/inc/btmsgviewer.h	Wed Aug 18 09:59:05 2010 +0300
@@ -22,6 +22,7 @@
 #include <xqserviceprovider.h>
 #include <hbview.h>
 #include <xqappmgr.h>
+
 #include "btmsgviewerutils.h"
 
 
@@ -30,12 +31,19 @@
     Q_OBJECT
     
 public:
-    BTMsgViewer (QObject *parent = 0 );
-    ~BTMsgViewer ();    
+    BTMsgViewer (QObject* parent=0 );
+    ~BTMsgViewer ();
+    
 public slots:
-    int displaymsg(int messageId);
+    void displaymsg(int messageId);
+
 private:
     bool isError(int aError);
+    QString copyVCardToTemp(const QString& filepath);
+    void deleteVCardFromTemp(const QString& filepath);
+    
+private:
+    int mCurrentRequestIndex;
 };
 
 #endif // BTMSGVIEWER_H
--- a/btobexprofiles/obexreceiveservices/btmsgviewer/inc/btmsgviewerutils.h	Tue Jul 06 14:27:09 2010 +0300
+++ b/btobexprofiles/obexreceiveservices/btmsgviewer/inc/btmsgviewerutils.h	Wed Aug 18 09:59:05 2010 +0300
@@ -27,12 +27,14 @@
     static CBtMsgViewerUtils* NewL();
     ~CBtMsgViewerUtils();
     HBufC* GetMessagePath(TInt aMessageId, TInt aError);
+    HBufC8* GetMimeType();
 
 private: // From MMsvSessionObserver
     void HandleSessionEventL(TMsvSessionEvent aEvent, TAny* aArg1, TAny* aArg2, TAny* aArg3);
     
 private:
     void GetMessagePathL(TPtr aMsgPath, const TInt aMessageId);
+    void StoreMessageMimeTypeL(TPtr aMsgPath);
        
 private:
     CBtMsgViewerUtils();
@@ -40,6 +42,7 @@
     
 private:
     CMsvSession* iMsvSession;
+    HBufC8*      iMimeType;
     };
 
 #endif // BTMSGVIEWERUTILS_H_
--- a/btobexprofiles/obexreceiveservices/btmsgviewer/src/btmsgviewer.cpp	Tue Jul 06 14:27:09 2010 +0300
+++ b/btobexprofiles/obexreceiveservices/btmsgviewer/src/btmsgviewer.cpp	Wed Aug 18 09:59:05 2010 +0300
@@ -19,23 +19,31 @@
 #include "btmsgviewer.h"
 #include "apmstd.h"
 #include <xqaiwrequest.h>
-#include <f32file.h>
-//#include <documenthandler.h>
+#include <xqconversions.h>
+#include <apgcli.h>
+#include <QFileInfo>
+#include <QDir>
+#include <QFile>
+#include <hbapplication.h>
+
+const QString KMimeTypeVCard("text/X-vCard");
 
 
 BTMsgViewer::BTMsgViewer(QObject* parent)
-: XQServiceProvider("com.nokia.services.btmsgdispservices.displaymsg",parent)
+: XQServiceProvider("com.nokia.services.btmsgdispservices.displaymsg", parent), mCurrentRequestIndex(0)
     {    
     publishAll();
+    connect(this, SIGNAL(returnValueDelivered()), qApp, SLOT(quit()));
     }
 
 BTMsgViewer::~BTMsgViewer ()
     {
-    
+
     }
 
-int BTMsgViewer::displaymsg( int messageId )
-    {    
+void BTMsgViewer::displaymsg( int messageId )
+    { 
+    mCurrentRequestIndex = setCurrentRequestAsync(); 
     CBtMsgViewerUtils* btViewerUtils = 0;
     
     TRAPD(error, btViewerUtils = CBtMsgViewerUtils::NewL());  
@@ -44,7 +52,9 @@
         if(btViewerUtils)
             delete btViewerUtils;
         
-        return error;   
+        QVariant retVal(error); 
+        completeRequest(mCurrentRequestIndex, retVal);
+        return;
         }
         
     HBufC* fileName = 0;
@@ -55,19 +65,65 @@
             delete fileName;
         
         delete btViewerUtils;
-        return error;
+        
+        QVariant retVal(error); 
+        completeRequest(mCurrentRequestIndex, retVal);
+        return;
         }
     
-    QString attachmentFName = QString::fromUtf16(fileName->Ptr(),fileName->Length());    
-    
+    QString attachmentFName = XQConversions::s60DescToQString(fileName->Des());
+    QString mimeType = XQConversions::s60Desc8ToQString(btViewerUtils->GetMimeType()->Des());
     delete fileName;
     delete btViewerUtils;
+    
+    if(mimeType == KMimeTypeVCard)
+        {
+        int error = KErrGeneral;
+        
+        /*todo: copyVCardToTemp() has to be removed when phonebook updates it's capabilites to
+                access messages from private folder*/
+        QString newfilepath = copyVCardToTemp(attachmentFName);
+    
+        QString service("com.nokia.services.phonebookservices");
+        QString interface("Fetch");
+        QString operation("editCreateNew(QString)");
+        XQApplicationManager appManager;
+        XQAiwRequest* request = appManager.create(service, interface, operation, true); //embedded
+        if(request)
+        {
+            QList<QVariant> args;
+            args << newfilepath;
+            request->setArguments(args);
+            QVariant retValue;
+            bool res = request->send(retValue);
+            if  (!res) 
+                {
+                error = request->lastError();
+                }
+            else
+                {
+                error = retValue.toInt();
+                }
+            
+            delete request;
+        }
 
+        /*todo: copyVCardToTemp() has to be removed when phonebook updates it's capabilites to
+                access messages from private folder*/        
+        deleteVCardFromTemp(newfilepath);
+        
+        QVariant retVal(error); 
+        completeRequest(mCurrentRequestIndex, retVal);
+        return;
+        }
+    
     XQSharableFile sf;
     XQAiwRequest* request = 0;
 
     if (!sf.open(attachmentFName)) {
-        return KErrNotFound;
+    QVariant retVal(KErrGeneral); 
+    completeRequest(mCurrentRequestIndex, retVal);
+    return;
     }
 
     // Get handlers
@@ -79,12 +135,18 @@
 
         if (!request) {
             sf.close();
-            return KErrGeneral;
+            
+            QVariant retVal(KErrGeneral); 
+            completeRequest(mCurrentRequestIndex, retVal);
+            return;
         }
     }
     else {
         sf.close();
-        return KErrGeneral;
+        
+        QVariant retVal(KErrGeneral); 
+        completeRequest(mCurrentRequestIndex, retVal);
+        return;
     }
 
     request->setEmbedded(true);
@@ -95,23 +157,39 @@
     args << qVariantFromValue(sf);
     request->setArguments(args);
 
+    int err = KErrNone;
     bool res = request->send();
     if  (!res) 
         {
-        QString errMsg = request->lastErrorMessage();
+        err = request->lastError();
         }
 
     // Cleanup
     sf.close();
     delete request;
     
-    if(!res)
-        return request->lastError();
-    else
-        return KErrNone;
+    QVariant retVal(err); 
+    completeRequest(mCurrentRequestIndex, retVal);
+    return;
     }
 
 bool BTMsgViewer::isError(int aError)
     {
     return ((aError < KErrNone)?true:false);
     }
+
+QString BTMsgViewer::copyVCardToTemp(const QString& filepath)
+{
+    QDir tempDir;
+    QString tempFilePath(QDir::toNativeSeparators(tempDir.tempPath()));
+    tempFilePath.append(QDir::separator());
+    QFileInfo fInfo(filepath);
+    tempFilePath.append(fInfo.fileName());
+    QFile::copy(filepath, tempFilePath);
+    return tempFilePath;
+}
+
+void BTMsgViewer::deleteVCardFromTemp(const QString& filepath)
+{
+    QFile::remove(filepath);
+}
--- a/btobexprofiles/obexreceiveservices/btmsgviewer/src/btmsgviewerutils.cpp	Tue Jul 06 14:27:09 2010 +0300
+++ b/btobexprofiles/obexreceiveservices/btmsgviewer/src/btmsgviewerutils.cpp	Wed Aug 18 09:59:05 2010 +0300
@@ -16,9 +16,12 @@
  */
 
 #include <mmsvattachmentmanager.h>
+#include <apgcli.h>
 #include "btmsgviewerutils.h"
 
+const TInt32 KUidMsgTypeBtTInt32 = 0x10009ED5;
 
+    
 CBtMsgViewerUtils* CBtMsgViewerUtils::NewL()
     {
     CBtMsgViewerUtils* me = new (ELeave) CBtMsgViewerUtils();
@@ -42,8 +45,9 @@
     {
     if ( iMsvSession )
         {
-		 delete iMsvSession;
+        delete iMsvSession;
         }
+    delete iMimeType;
     }
 
 HBufC* CBtMsgViewerUtils::GetMessagePath(TInt aMessageId, TInt aError)
@@ -62,28 +66,55 @@
 void CBtMsgViewerUtils::GetMessagePathL(TPtr aMsgPath, const TInt aMessageId)
     {
     CMsvEntry* messageEntry = iMsvSession->GetEntryL(aMessageId);
-    CleanupStack::PushL(messageEntry);
-    
-    CMsvEntry* attachmentEntry = iMsvSession->GetEntryL((*messageEntry)[0].Id());
-    CleanupStack::PushL(attachmentEntry);
-    
-    CMsvStore* store = attachmentEntry->EditStoreL();
-    CleanupStack::PushL(store); 
+    CleanupStack::PushL(messageEntry); //1st push
     
-    //get file handle for the attachment & the complete path of the file
-    RFile attachmentFile;
-    attachmentFile = store->AttachmentManagerL().GetAttachmentFileL(0);
-    attachmentFile.FullName(aMsgPath);
-    attachmentFile.Close();
-    
-    //mark attachment as Read
-    TMsvEntry attachEntry = attachmentEntry->Entry();
-    attachEntry.SetUnread(EFalse);
-    attachmentEntry->ChangeL(attachEntry);
-    
-    CleanupStack::PopAndDestroy(store);
-    CleanupStack::PopAndDestroy(attachmentEntry);
-    CleanupStack::PopAndDestroy(messageEntry);
+    TMsvEntry entry = messageEntry->Entry();
+    if(entry.MtmData1() == KUidMsgTypeBtTInt32)
+        {
+        CMsvStore* store = messageEntry->ReadStoreL();
+        CleanupStack::PushL(store); //2nd push
+
+        //get file handle for the attachment & the complete path of the file
+        RFile attachmentFile;
+        attachmentFile = store->AttachmentManagerL().GetAttachmentFileL(0);
+        CleanupClosePushL(attachmentFile); //3rd push
+        User::LeaveIfError(attachmentFile.FullName(aMsgPath));
+        CleanupStack::PopAndDestroy(&attachmentFile);
+        StoreMessageMimeTypeL(aMsgPath);
+        
+        //mark attachment as Read
+        TMsvEntry attachEntry = messageEntry->Entry();
+        attachEntry.SetUnread(EFalse);
+        messageEntry->ChangeL(attachEntry);
+        
+        CleanupStack::PopAndDestroy(store);
+        CleanupStack::PopAndDestroy(messageEntry);
+        }
+    else
+        {
+        CMsvEntry* attachmentEntry = iMsvSession->GetEntryL((*messageEntry)[0].Id());
+        CleanupStack::PushL(attachmentEntry); //2nd push
+            
+        CMsvStore* store = attachmentEntry->ReadStoreL();
+        CleanupStack::PushL(store);  //3rd push
+        
+        //get file handle for the attachment & the complete path of the file
+        RFile attachmentFile;
+        attachmentFile = store->AttachmentManagerL().GetAttachmentFileL(0);
+        CleanupClosePushL(attachmentFile);
+        User::LeaveIfError(attachmentFile.FullName(aMsgPath));
+        CleanupStack::PopAndDestroy(&attachmentFile);
+        StoreMessageMimeTypeL(aMsgPath);
+        
+        //mark attachment as Read
+        TMsvEntry attachEntry = attachmentEntry->Entry();
+        attachEntry.SetUnread(EFalse);
+        attachmentEntry->ChangeL(attachEntry);
+        
+        CleanupStack::PopAndDestroy(store);
+        CleanupStack::PopAndDestroy(attachmentEntry);
+        CleanupStack::PopAndDestroy(messageEntry);
+        }
     }
 
 void CBtMsgViewerUtils::HandleSessionEventL(TMsvSessionEvent aEvent, TAny* aArg1, 
@@ -95,5 +126,41 @@
     (void) aArg3;
     }
 
+void CBtMsgViewerUtils::StoreMessageMimeTypeL(TPtr aMsgPath)
+    {
+    RFs rfs;
+    RFile file;
+    
+    User::LeaveIfError(rfs.Connect());
+    
+    User::LeaveIfError(rfs.ShareProtected());
+    
+    User::LeaveIfError(file.Open(rfs, aMsgPath, EFileShareReadersOrWriters | EFileRead));
+    
+    TDataRecognitionResult dataType;
+    RApaLsSession apaSession;
+    
+    if(apaSession.Connect() == KErrNone)
+        {
+        if (apaSession.RecognizeData(file, dataType) == KErrNone)
+            {
+            if(iMimeType)
+                {
+                delete iMimeType;
+                iMimeType = NULL;
+                }
+        
+            iMimeType = dataType.iDataType.Des8().AllocL();
+            
+            rfs.Close();
+            apaSession.Close();
+            }
+        }
 
+    rfs.Close();
+    }
 
+HBufC8* CBtMsgViewerUtils::GetMimeType()
+    {
+    return iMimeType;
+    }
--- a/btobexprofiles/obexreceiveservices/btmsgviewer/src/main.cpp	Tue Jul 06 14:27:09 2010 +0300
+++ b/btobexprofiles/obexreceiveservices/btmsgviewer/src/main.cpp	Wed Aug 18 09:59:05 2010 +0300
@@ -26,6 +26,7 @@
     HbApplication a( argc, argv );
     
     BTMsgViewer* btmsgviewer = new BTMsgViewer();
+    
     int retVal = a.exec();
     delete btmsgviewer;
     return retVal;
--- a/btobexprofiles/obexreceiveservices/opp/inc/oppcontroller.h	Tue Jul 06 14:27:09 2010 +0300
+++ b/btobexprofiles/obexreceiveservices/opp/inc/oppcontroller.h	Wed Aug 18 09:59:05 2010 +0300
@@ -157,6 +157,9 @@
     CHbDeviceDialogSymbian*     iProgressDialog;
     TBool                       iDialogActive;
     TInt                        iFileCount;
+    TBool                       iReceivingFailed;
+    CHbDeviceDialogSymbian*     iRecvDoneDialog;
+    TBool                       iShowRecvCompleteDialog;
     };
 
 #endif      // OPPCONTROLLER_H
--- a/btobexprofiles/obexreceiveservices/opp/src/oppcontroller.cpp	Tue Jul 06 14:27:09 2010 +0300
+++ b/btobexprofiles/obexreceiveservices/opp/src/oppcontroller.cpp	Wed Aug 18 09:59:05 2010 +0300
@@ -93,6 +93,7 @@
     iFs.Close();
     delete iDialog;
     delete iProgressDialog;
+    delete iRecvDoneDialog;
     }
 
 // ---------------------------------------------------------
@@ -119,6 +120,8 @@
 void COPPController::HandleError(TBool aAbort)
     {
     TRACE_ERROR((_L( "[oppreceiveservice] COPPController:HandleError" )));
+    iReceivingFailed = ETrue;
+    iShowRecvCompleteDialog = EFalse;
     if( iObexTransferState == ETransferPut || iObexTransferState == ETransferPutDiskError )
         {        
         if(iObexObject)
@@ -153,6 +156,7 @@
 void COPPController::TransportUpIndication()
 	{
 	TRACE_FUNC    
+	iReceivingFailed = EFalse;
     iObexTransferState = ETransferIdle;	
  
 	if ( !iFs.Handle() )
@@ -218,6 +222,61 @@
 void COPPController::TransportDownIndication()
     {
     TRACE_FUNC
+    if(!iReceivingFailed && iShowRecvCompleteDialog)
+        {
+        //Launch recevice completed dialog.
+        iRecvDoneDialog = CHbDeviceDialogSymbian::NewL();
+        iRecvDoneDialog->SetObserver(this);
+    
+        CHbSymbianVariantMap* variantMap = CHbSymbianVariantMap::NewL();
+        CleanupStack::PushL(variantMap);
+        
+        TInt dialogIdx = TBluetoothDialogParams::EReceiveDone;
+        CHbSymbianVariant* dialogType = CHbSymbianVariant::NewL( (TAny*) &(dialogIdx), 
+                                                            CHbSymbianVariant::EInt );
+        CleanupStack::PushL(dialogType);
+        TBuf16<6> dialogTypeKey;
+        dialogTypeKey.Num(TBluetoothDialogParams::EDialogType);
+        User::LeaveIfError(variantMap->Add(dialogTypeKey, dialogType));
+        CleanupStack::Pop(dialogType);
+        
+        CHbSymbianVariant* deviceName = CHbSymbianVariant::NewL( (TAny*) (&iRemoteDeviceName), 
+                                                            CHbSymbianVariant::EDes );
+        CleanupStack::PushL(deviceName);
+        TBuf16<6> deviceNameKey;
+        deviceNameKey.Num(TBluetoothDeviceDialog::EDeviceName);
+        User::LeaveIfError(variantMap->Add(deviceNameKey, deviceName));
+        CleanupStack::Pop(deviceName);
+        
+        CHbSymbianVariant* fileName = CHbSymbianVariant::NewL( (TAny*) (&iReceivingFileName), 
+                                                            CHbSymbianVariant::EDes );
+        CleanupStack::PushL(fileName);
+        TBuf16<6> fileNameKey;
+        fileNameKey.Num(TBluetoothDeviceDialog::EReceivingFileName);
+        User::LeaveIfError(variantMap->Add(fileNameKey, fileName));
+        CleanupStack::Pop(fileName);
+        
+        CHbSymbianVariant* fileSz = CHbSymbianVariant::NewL( (TAny*) &iTotalSizeByte, 
+                                                            CHbSymbianVariant::EInt );
+        CleanupStack::PushL(fileSz);
+        TBuf16<6> fileSzKey;
+        fileSzKey.Num(TBluetoothDeviceDialog::EReceivingFileSize);
+        User::LeaveIfError(variantMap->Add(fileSzKey, fileSz));
+        CleanupStack::Pop(fileSz);
+        
+        CHbSymbianVariant* fileCnt = CHbSymbianVariant::NewL( (TAny*) &iFileCount, 
+                                                            CHbSymbianVariant::EInt );
+        CleanupStack::PushL(fileCnt);
+        TBuf16<6> fileCntKey;
+        fileCntKey.Num(TBluetoothDeviceDialog::EReceivedFileCount);
+        User::LeaveIfError(variantMap->Add(fileCntKey, fileCnt));
+        CleanupStack::Pop(fileCnt);
+        
+        iRecvDoneDialog->Show( KBTDevDialogId(), *variantMap, this );
+        CleanupStack::PopAndDestroy(variantMap);
+        iShowRecvCompleteDialog = EFalse;
+        }
+    
     // Remove receiving buffer and files used during file receiving.
     //
     delete iObexObject;
@@ -347,6 +406,7 @@
         iObexTransferState = ETransferIdle;
         CloseReceivingIndicator();
         iFileCount++;
+        iShowRecvCompleteDialog = ETrue;
         }
     TRACE_FUNC_EXIT
     return retVal;
@@ -969,15 +1029,28 @@
      if(aData.Keys().MdcaPoint(0).Compare(_L("actionResult")) == 0)
          {
          TInt val = *(static_cast<TInt*>(aData.Get(_L("actionResult"))->Data()));
-         if(!val)
+         switch(val)
              {
-             //Cancel has been clicked
-             CancelTransfer();
-             }
-         else
-             {
-             //Hide has been clicked
-             CloseReceivingIndicator(EFalse);
+             case TBluetoothDialogParams::ECancelReceive:
+                 {
+                 //User choose to cancel receiving.
+                 CancelTransfer();
+                 }break;
+                 
+             case TBluetoothDialogParams::EHide:
+                 {
+                 //Use choose to hide the progress dialog.
+                 CloseReceivingIndicator(EFalse);
+                 }break;
+                 
+             case TBluetoothDialogParams::EShow:
+             case TBluetoothDialogParams::ECancelShow:
+                 {
+                 //In case of Show, the device dialog will handle the opening of conversation view.
+                 iRecvDoneDialog->Cancel();
+                 delete iRecvDoneDialog;
+                 iRecvDoneDialog = NULL;
+                 }break;
              }
          }
      }
--- a/btobexprofiles/obexsendservices/obexservicesendutils/src/BTServiceClient.cpp	Tue Jul 06 14:27:09 2010 +0300
+++ b/btobexprofiles/obexsendservices/obexservicesendutils/src/BTServiceClient.cpp	Wed Aug 18 09:59:05 2010 +0300
@@ -1,5 +1,5 @@
 /*
-* Copyright (c) 2002-2007 Nokia Corporation and/or its subsidiary(-ies).
+* Copyright (c) 2002-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"
@@ -25,12 +25,12 @@
 #include "BTConnectionTimer.h"
 #include "BTSUDebug.h"
 
-const TUint16 KMtuSizeReceiv    = 0xFFFF;  // 64kB
-const TUint16 KMtuSizeTrans     = 0x3000;  // 12kB 
-const TInt    KBufferSize       = 0x4000;  // 16kB
+const TUint16 KMtuSizeReceiv    = 0xFFFF;	// 64kB - 1 (65535)
+const TUint16 KMtuSizeTrans     = 0x8000;	// 32kB
+const TInt    KBufferSize       = 0x8000;	// 32kB
 
-const TInt KBTConnectionTimeout = 20000000; // 20 seconds
-const TInt KBTAbortTimeout      = 2000000;  // 20 seconds
+const TInt KBTConnectionTimeout = 20 * 1000 * 1000;	// 20 seconds
+const TInt KBTAbortTimeout      = 2 * 1000 * 1000;	// 2 seconds
 
 // CONSTANTS
 
--- a/btobexprofiles/obexsendservices/obexservicesendutils/src/BTServiceStarter.cpp	Tue Jul 06 14:27:09 2010 +0300
+++ b/btobexprofiles/obexsendservices/obexservicesendutils/src/BTServiceStarter.cpp	Wed Aug 18 09:59:05 2010 +0300
@@ -743,7 +743,7 @@
     {
     FLOG(_L("[BTSU]\t CBTServiceStarter::ServiceAttributeSearchComplete()"));               
     TInt err = KErrNone;
-    if (aErr==KErrEof && aAttr.Count()>0 )
+    if ((aErr==KErrEof || aErr==KErrNone) && aAttr.Count()>0 )
         {            
         RSdpResultArray results=aAttr;    
         iBTEngDiscovery->ParseRfcommChannel(results,iClientChannel);          
@@ -812,6 +812,10 @@
         iState = EBTSStarterFindingBIP;  
         iTriedOPP = ETrue;
         }
+    else if (aErr==KErrNone && aAttr.Count()==0)
+        {
+        // This isn't KErrEof so we aren't done yet, wait for further matches
+        }
     else
         {
         // Set destroyer AO active (destroys CBTEngDiscovery/CBTEngSdpQuery classes). This is done
--- a/btobexprofiles/obexserviceman/rom/obex.iby	Tue Jul 06 14:27:09 2010 +0300
+++ b/btobexprofiles/obexserviceman/rom/obex.iby	Wed Aug 18 09:59:05 2010 +0300
@@ -19,6 +19,8 @@
 #ifndef __OBEX_IBY__
 #define __OBEX_IBY__
 
+#include <obexprotocol.iby>
+
 #ifdef SYMBIAN_EXCLUDE_OBEX
 REM Messaging OBEX MTM is not included in this ROM, because it depends on excluded OBEX
 #else
--- a/btobexprofiles/obexserviceman/utils/inc/obexutilsentryhandler.h	Tue Jul 06 14:27:09 2010 +0300
+++ b/btobexprofiles/obexserviceman/utils/inc/obexutilsentryhandler.h	Wed Aug 18 09:59:05 2010 +0300
@@ -54,19 +54,7 @@
      */
     TInt AddEntryAttachment(const TDesC &aFilePath, CMsvAttachment* anAttachInfo, CMsvStore* aStore );
     
-    /**
-     * Update an entry attachment
-     * @since S60 v5.0
-     * @param aFilePath the absolute file path of the linked attachment file.
-     * @param anAttachInfo the attachment info associated with the file.
-     * @param aStore An interface ove the message store that is associated with a message entry.
-     * @return error code
-     */
-    TInt UpdateEntryAttachment(TFileName& aFileName,
-                              CMsvAttachment* anOldAttachInfo,
-                              CMsvAttachment* aNewAttachInfo,
-                              CMsvStore* aStore );
-    
+   
     // from base class CActive
          
     /**
@@ -97,23 +85,6 @@
      */ 
     void ConstructL();
 
-    /**
-     * Add link attachment 
-     * 
-     * @since S60 v5.0
-     */
-    void DoAddEntryAttachmentL(const TDesC &aFilePath, CMsvAttachment* anAttachInfo, CMsvStore* aStore);
-    
-   
-    /**
-     * Update link attachment 
-     * 
-     * @since S60 v5.0
-     */
-    void DoUpdateEntryAttachmentL(TFileName& aFileName,
-                                 CMsvAttachment* anOldAttachInfo,
-                                 CMsvAttachment* aNewAttachInfo,
-                                 CMsvStore* aStore);
     
 private: // member data
 
--- a/btobexprofiles/obexserviceman/utils/src/obexutilsentryhandler.cpp	Tue Jul 06 14:27:09 2010 +0300
+++ b/btobexprofiles/obexserviceman/utils/src/obexutilsentryhandler.cpp	Wed Aug 18 09:59:05 2010 +0300
@@ -81,7 +81,8 @@
     
     iStatus = KRequestPending;
   
-    TRAPD(error, DoAddEntryAttachmentL(aFilePath, anAttachInfo, aStore));
+    TRAPD(error, aStore->AttachmentManagerL().AddLinkedAttachmentL(aFilePath,anAttachInfo, iStatus););
+    
     if (error != KErrNone )
         {        
         //Complete request
@@ -98,76 +99,6 @@
 
 
 // ---------------------------------------------------------------------------
-// DoAddLinkAttachmentL()
-// ---------------------------------------------------------------------------
-//
-void CObexutilsEntryhandler::DoAddEntryAttachmentL(
-    const TDesC &aFilePath, 
-    CMsvAttachment* anAttachInfo, 
-    CMsvStore* aStore)
-    {
-    FLOG(_L("[OBEXUTILS]\t CObexutilsEntryhandler::DoAddEntryAttachmentL()"));   
-        
-    aStore->AttachmentManagerL().AddLinkedAttachmentL(aFilePath,anAttachInfo, iStatus);
-    
-    //Complete request
-    TRequestStatus* status = &iStatus;
-    User::RequestComplete(status, KErrNone);
-        
-    FLOG(_L("[OBEXUTILS]\t CObexutilsEntryhandler::DoAddEntryAttachmentL() completed"));  
-    }
-
-// ---------------------------------------------------------------------------
-// UpdateLinkAttachment()
-// ---------------------------------------------------------------------------
-//
-TInt CObexutilsEntryhandler::UpdateEntryAttachment(
-    TFileName& aFileName,
-    CMsvAttachment* anOldAttachInfo,
-    CMsvAttachment* aNewAttachInfo,
-    CMsvStore* aStore)
-    {
-    FLOG(_L("[OBEXUTILS]\t CObexutilsEntryhandler::UpdateEntryAttachment()"));       
-    
-    iStatus = KRequestPending;
-  
-    TRAPD(error, DoUpdateEntryAttachmentL(aFileName,anOldAttachInfo, aNewAttachInfo, aStore));
-    if (error != KErrNone )
-        {        
-        //Complete request
-        TRequestStatus* status = &iStatus;
-        User::RequestComplete(status, error);
-        }
-       
-    SetActive();
-    iSyncWaiter.Start();
-          
-    FLOG(_L("[OBEXUTILS]\t CObexutilsEntryhandler::UpdateEntryAttachment() Done"));
-    return iStatus.Int();
-    }
-
-// ---------------------------------------------------------------------------
-// DoUpdateEntryAttachmentL()
-// ---------------------------------------------------------------------------
-//
-void CObexutilsEntryhandler::DoUpdateEntryAttachmentL(
-    TFileName& aFileName,
-    CMsvAttachment* anOldAttachInfo,
-    CMsvAttachment* aNewAttachInfo,
-    CMsvStore* aStore)
-    {
-    FLOG(_L("[OBEXUTILS]\t CObexutilsEntryhandler::DoUpdateEntryAttachmentL()"));   
-    aStore->AttachmentManagerL().RemoveAttachmentL(anOldAttachInfo->Id(), iStatus);
-    aStore->AttachmentManagerL().AddLinkedAttachmentL(aFileName,aNewAttachInfo, iStatus);
-   
-    //Complete request
-    TRequestStatus* status = &iStatus;
-    User::RequestComplete(status, KErrNone);
-        
-    FLOG(_L("[OBEXUTILS]\t CObexutilsEntryhandler::DoUpdateEntryAttachmentL() completed"));  
-    }
-
-// ---------------------------------------------------------------------------
 // From class CActive.
 // RunL()
 // ---------------------------------------------------------------------------
--- a/btobexprofiles/obexserviceman/utils/src/obexutilsmessagehandler.cpp	Tue Jul 06 14:27:09 2010 +0300
+++ b/btobexprofiles/obexserviceman/utils/src/obexutilsmessagehandler.cpp	Wed Aug 18 09:59:05 2010 +0300
@@ -54,6 +54,8 @@
 
 const TInt KObexUtilsMaxCharToFromField = 256;
 
+const TInt32 KUidMsgTypeBtTInt32 = 0x10009ED5;
+
 // ============================= LOCAL FUNCTIONS ===============================
 
 // -----------------------------------------------------------------------------
@@ -303,6 +305,7 @@
     parentTEntry.iMtm = KUidBIOMessageTypeMtm;
     parentTEntry.iServiceId = KMsvLocalServiceIndexEntryId;  
     parentTEntry.iBioType = aBioMsgId.iUid;
+    parentTEntry.iMtmData1 = KUidMsgTypeBtTInt32;
     parentTEntry.iDescription.Set(aBioDB->BifReader(index).Description());
     parentEntry->ChangeL(parentTEntry);
     
@@ -342,11 +345,13 @@
     TPtrC mimeType16(buf16->Des());
     CleanupStack::PopAndDestroy();   //   buf16
     
-    CUpdateMusicCollection* updateMusicCollection = CUpdateMusicCollection::NewL() ;
+    CUpdateMusicCollection* updateMusicCollection = CUpdateMusicCollection::NewL();
+    CleanupStack::PushL(updateMusicCollection);    
     if (updateMusicCollection->isSupported(mimeType16))
         {
         updateMusicCollection->addToCollectionL(aFileName);
         }
+    CleanupStack::PopAndDestroy();  // updateMusicCollection
     
     aAttachInfo->SetMimeTypeL( mimeType );
     
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/cbsatplugin/atmisccmdplugin/data/2002C3BA_TDSCDMA.rss	Wed Aug 18 09:59:05 2010 +0300
@@ -0,0 +1,42 @@
+// Copyright (c) 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"
+// which accompanies this distribution, and is available
+// at the URL "http://www.eclipse.org/legal/epl-v10.html".
+// Initial Contributors:
+// Nokia Corporation - initial contribution.
+// Contributors:
+//
+
+#include "../inc/atmisccmdpluginuids.hrh"
+#include <ecom/registryinfo.rh>
+#include <atext_interfaceuid.h>
+    
+RESOURCE REGISTRY_INFO theInfo
+	{
+	// UID for the DLL
+	dll_uid = 0x2002C3BA;//KUidATCFunEcomDll; 
+	// Declare array of interface info
+	interfaces =
+		{
+		INTERFACE_INFO
+			{
+			// UID of interface that is implemented
+			interface_uid = 0x2001CBEE; // ATEXT_INTERFACE_DUN_UID; 
+			implementations =
+				{
+                IMPLEMENTATION_INFO
+	                {
+	                implementation_uid = 0x2002DC6B;// KUidATMiscCmdEcomImpl;
+	                version_no = 1;
+	                display_name = "Miscellaneous AT commands Implementation";
+	                default_data = "MAT+CLCK|MAT+CPWD|MAT+CUSD|MAT+CPIN|MAT+CNUM|MAT+CFUN|MAT+CBC|OAT+CMEE|MAT^HVER|MAT+CGSN|MAT+CGMR|MAT+CGMI|MAT+CMGD|OAT+CMGF|MAT+GMI|MAT+GMR|MAT+GSN|MAT+CGMM|MAT+GMM|MATI|MATI0|MATI1|MATI2|MATI3|MATI4|MAT^SCPBR|MAT^SCPBW";
+	                opaque_data = "";
+	                }
+				};
+			}
+		};
+	}
+
+// End of file
--- a/cbsatplugin/atmisccmdplugin/group/atmisccmdplugin.mmp	Tue Jul 06 14:27:09 2010 +0300
+++ b/cbsatplugin/atmisccmdplugin/group/atmisccmdplugin.mmp	Wed Aug 18 09:59:05 2010 +0300
@@ -13,13 +13,19 @@
  *
  */
 
+FEATUREVARIANT
+
 #include <platform_paths.hrh>
 #include <data_caging_paths.hrh>
 #include "../inc/atmisccmdpluginuids.hrh"
 
 CAPABILITY 	    CAP_ECOM_PLUGIN 
 VENDORID        VID_DEFAULT
+#ifdef PROTOCOL_TDSCDMA
+TARGET          atmisccmdplugin_td.dll
+#else
 TARGET          atmisccmdplugin.dll
+#endif
 TARGETTYPE	    PLUGIN
 UID             0x10009D8D 0x2002C3BA
 
@@ -42,15 +48,33 @@
 SOURCE          ussdreadmessageimpl.cpp
 SOURCE          ussdsendmessageimpl.cpp
 
+#ifdef PROTOCOL_TDSCDMA
+SOURCE          hvercommandhandler.cpp 
+SOURCE          cgsncommandhandler.cpp 
+SOURCE          cgmrcommandhandler.cpp 
+SOURCE          cmgwcommandhandler.cpp 
+SOURCE          cgmicommandhandler.cpp
+SOURCE			cmgdcommandhandler.cpp
+SOURCE			telephonywrapper.cpp
+SOURCE			cgmmcommandhandler.cpp 
+SOURCE			scpbrcommandhandler.cpp
+SOURCE			scpbwcommandhandler.cpp
+#endif
 
 USERINCLUDE     ../inc
 
 MW_LAYER_SYSTEMINCLUDE
 
+// Resources - inclusion controlled by iby
 START RESOURCE  ../data/2002C3BA.rss
 TARGET          atmisccmdplugin.rsc
 END
 
+START RESOURCE  ../data/2002C3BA_TDSCDMA.rss
+TARGET          atmisccmdplugin_td.rsc
+END
+
+
 LIBRARY	        ecom.lib
 LIBRARY         euser.lib
 LIBRARY         atextpluginbase.lib
@@ -65,8 +89,10 @@
 LIBRARY			etel3rdparty.lib
 LIBRARY			sysutil.lib 
 
-LIBRARY		    flogger.lib
+#ifdef PROTOCOL_TDSCDMA
+LIBRARY			customapi.lib
+#endif
 
-MACRO _DEBUG
-MACRO USE_FILE_LOGGING
+DEBUGLIBRARY	flogger.lib
+
 // End of File
--- a/cbsatplugin/atmisccmdplugin/inc/atcommandparser.h	Tue Jul 06 14:27:09 2010 +0300
+++ b/cbsatplugin/atmisccmdplugin/inc/atcommandparser.h	Wed Aug 18 09:59:05 2010 +0300
@@ -53,7 +53,27 @@
         ECmdAtCpin,
         ECmdAtCusd,
         ECmdAtCnum,
-        ECmdAtCmee
+		ECmdAtCmee,
+        ECmdAtHver,
+        ECmdAtCgsn,
+        ECmdAtGsn,
+        ECmdAtCgmr,
+        ECmdAtGmr,
+        ECmdAtCgmi,
+        ECmdAtGmi,
+        ECmdAtCmgw,
+        ECmdAtCmgd,
+        ECmdAtCmgf,
+        ECmdAtCgmm,
+        ECmdAtGmm,
+        ECmdAtI,
+        ECmdAtI0,
+        ECmdAtI1,
+        ECmdAtI2,
+        ECmdAtI3,
+        ECmdAtI4,
+		ECmdAtScpbr,
+		ECmdAtScpbw
         };
 public:
     TAtCommandParser();
--- a/cbsatplugin/atmisccmdplugin/inc/atmisccmdplugin.h	Tue Jul 06 14:27:09 2010 +0300
+++ b/cbsatplugin/atmisccmdplugin/inc/atmisccmdplugin.h	Wed Aug 18 09:59:05 2010 +0300
@@ -81,6 +81,13 @@
      */
     virtual void CreateCMEReplyAndComplete(TInt aError) = 0;
 
+    /*
+     * Complete the AT command request with AT CMS error code according to given Symbian error code
+     * @param aError Symbian error code 
+     */
+    
+    virtual void CreateCMSReplyAndComplete(TInt aError) = 0;
+
     /**
      * Returns plugin's character value settings (from CATExtPluginBase)
      *
@@ -137,6 +144,10 @@
 
     virtual TInt CreateOkOrErrorReply( RBuf8& aReplyBuffer,
                                TBool aOkReply );
+
+    virtual TInt CreateEditModeBuffer( RBuf8& aReplyBuffer );
+    virtual void CreateCMSReplyAndComplete(TInt aError);
+
     virtual void CreateCMEReplyAndComplete(TInt aError);
     virtual TInt GetCharacterValue( TCharacterTypes aCharType, TChar& aChar );
     virtual TInt GetModeValue( TModeTypes aModeType, TBool& aMode );    
@@ -148,7 +159,8 @@
     
     TInt CreatePartOfReply( RBuf8& aBuffer );
     void HandleCMEECommand();
-    
+    void HandleCMGFCommand();
+
     /*
      * Utility function that connect to Etel server and establish a subsession to RMobilePhone
      * Caller must close session and subsession after use.
@@ -175,7 +187,18 @@
     CATCmdAsyncBase* iCNUMHandler;
     CATCmdAsyncBase* iCFUNHandler;
     CATCmdAsyncBase* iCBCHandler;
-    
+
+    // TDSCDMA only
+	CATCmdSyncBase* iHVERHandler;
+    CATCmdSyncBase* iCGSNHandler;
+    CATCmdSyncBase* iCGMRHandler;
+    CATCmdSyncBase* iCGMIHandler;
+    CATCmdAsyncBase* iCMGWHandler;
+    CATCmdAsyncBase* iCMGDHandler;
+    CATCmdSyncBase* iCGMMHandler;
+	CATCmdAsyncBase* iSCPBRHandler;
+    CATCmdAsyncBase* iSCPBWHandler;
+ 
     /**
      * Buffer for handle command's command
      * Not own.
--- a/cbsatplugin/atmisccmdplugin/inc/atmisccmdpluginconsts.h	Tue Jul 06 14:27:09 2010 +0300
+++ b/cbsatplugin/atmisccmdplugin/inc/atmisccmdpluginconsts.h	Wed Aug 18 09:59:05 2010 +0300
@@ -21,15 +21,20 @@
 _LIT8(KCRLF, "\r\n");
 _LIT8(KOKCRLF, "\r\n\r\nOK\r\n");
 
-_LIT8(KAtCLCK, "+CLCK: ");
+_LIT8(KAtCLCK, "\r\n+CLCK: ");
 _LIT8(KAtCFUN, "+CFUN: ");
 _LIT8(KAtCBC, "+CBC: ");
 _LIT8(KAtCUSD, "+CUSD: ");
-
-_LIT8(KCLCKSupportedCmdsList, "+CLCK: (\"PS\",\"SC\",\"AO\",\"OI\",\"OX\",\"AI\",\"IR\",\"AB\",\"AG\",\"AC\")\r\n\r\nOK\r\n");
-_LIT8(KCFUNSupportedCmdsList, "+CFUN: (0,1,4),(0,1)\r\n\r\nOK\r\n");
-_LIT8(KCBCSupportedCmdsList, "+CBC: (0,1,2,3),(1...100)\r\n\r\nOK\r\n");
+_LIT8(KAtCMGW, "+CMGW: ");
+_LIT8(KSCPBR, "\r\n^SCPBR: ");
+_LIT8(KCLCKSupportedCmdsList, "\r\n+CLCK: (\"PS\",\"SC\",\"AO\",\"OI\",\"OX\",\"AI\",\"IR\",\"AB\",\"AG\",\"AC\")\r\n\r\nOK\r\n");
+_LIT8(KCFUNSupportedCmdsList, "\r\n+CFUN: (0,1,4),(0,1)\r\n\r\nOK\r\n");
+_LIT8(KCBCSupportedCmdsList, "\r\n+CBC: (0,1,2,3),(1...100)\r\n\r\nOK\r\n");
 _LIT8(KCUSDSupportedCmdsList, "+CUSD: (0,1)\r\n\r\nOK\r\n");
+_LIT8(KCMGDSupportedCmdsList, "\r\n+CMGD: (%S), (0,1,2,3,4)\r\n");
+_LIT8(KSCPBRSupportedEntriesIndexList,"\r\n^SCPBR:(1-%d),%d,%d,%d \r\n"); 
+_LIT8(KSCPBRReplyOneEntry,"%d,\"%S\",,\"%S\",,\"%S\",,\"%S\",,\"%S\",,\"%S\"");
+_LIT8(KSCPBWSupportedCmdsList, "\r\n^SCPBW: (1-%d),%d,(),%d,%d\r\n");
 
 _LIT8(KATCLCKPS, "PS");
 _LIT8(KATCLCKSC, "SC");
@@ -42,7 +47,19 @@
 _LIT8(KATCLCKAG, "AG");
 _LIT8(KATCLCKAC, "AC");
 
+_LIT8(KHVERModelString, "RM-");
+
+_LIT8(KCMSErr, "+CMS ERROR: ");
+
 // Max buffer length for an MD5 digest - originally defined in SCPServerInterface.h
 const TInt KSCPMaxHashLength( 32 );
 
+const TInt KSCPBRDefaultSizeOfOneEntry( 320 );
+const TInt KSCPBRMaxNameLength( 64 );
+const TInt KSCPBRMaxNumberLength( 32 );
+const TInt KSCPBRMaxEmailLength( 64 );
+const TInt KSCPBRMaxNumberCount( 4 );
+const TInt KSCPBRMaxEntryCount( 1000 );
+
+const TInt KBufBlockSize (1024);
 #endif // ATMISCCMDPLUGINCONSTS_H
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/cbsatplugin/atmisccmdplugin/inc/cgmicommandhandler.h	Wed Aug 18 09:59:05 2010 +0300
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 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"
+ * which accompanies this distribution, and is available
+ * at the URL "http://www.eclipse.org/legal/epl-v10.html".
+ * Initial Contributors:
+ * Nokia Corporation - initial contribution.
+ *
+ * Contributors:
+ * 
+ * Description :
+ * 
+ * CGMICommandHandler class declaration for AT+CGMI command
+ * 
+ */
+
+#ifndef CGMICOMMANDHANDLER_H
+#define CGMICOMMANDHANDLER_H
+
+#include "atcmdsyncbase.h"
+
+#include <etel3rdparty.h>
+
+/**
+ *  AT+CGMI command handler implementation class
+ */
+NONSHARABLE_CLASS( CCGMICommandHandler ) : public CATCmdSyncBase
+    {
+public:
+    static CCGMICommandHandler* NewL(MATMiscCmdPlugin* aCallback, TAtCommandParser& aATCmdParser, RMobilePhone& aPhone);
+    ~CCGMICommandHandler();
+    
+public:
+    void SetManufacturer(const TDesC8& aManufacturer);
+    void SetTelephonyError(TInt aTelError); 
+
+private: // methods from CATCmdSyncBase    
+    virtual void HandleCommand( const TDesC8& aCmd, RBuf8& aReply, TBool aReplyNeeded );
+    
+private:
+    CCGMICommandHandler(MATMiscCmdPlugin* aCallback, TAtCommandParser& aATCmdParser, RMobilePhone& aPhone);
+    void ConstructL();
+    
+private:
+    TInt    iTelError;
+    TBuf8<CTelephony::KPhoneManufacturerIdSize> iManufacturer;
+    
+    RBuf8 iReply;
+    };
+
+#endif /* CGMICOMMANDHANDLER_H */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/cbsatplugin/atmisccmdplugin/inc/cgmmcommandhandler.h	Wed Aug 18 09:59:05 2010 +0300
@@ -0,0 +1,55 @@
+/*
+ * Copyright (c) 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"
+ * which accompanies this distribution, and is available
+ * at the URL "http://www.eclipse.org/legal/epl-v10.html".
+ * Initial Contributors:
+ * Nokia Corporation - initial contribution.
+ *
+ * Contributors:
+ * 
+ * Description :
+ * 
+ * CGMMCommandHandler class declaration for AT+CGMM command
+ * 
+ */
+
+#ifndef CGMMCOMMANDHANDLER_H
+#define CGMMCOMMANDHANDLER_H
+
+#include "atcmdsyncbase.h"
+
+#include <etel3rdparty.h>
+
+/**
+ *  AT+CGMM command handler implementation class
+ */
+NONSHARABLE_CLASS( CCGMMCommandHandler ) : public CATCmdSyncBase
+    {
+public:
+    static CCGMMCommandHandler* NewL(MATMiscCmdPlugin* aCallback, TAtCommandParser& aATCmdParser, RMobilePhone& aPhone);
+    ~CCGMMCommandHandler();
+    
+public:
+    void SetManufacturer(const TDesC8& aManufacturer);
+    void SetModelID(const TDesC8& aModelID);
+    void SetTelephonyError(TInt aTelError); 
+
+private: // methods from CATCmdSyncBase    
+    virtual void HandleCommand( const TDesC8& aCmd, RBuf8& aReply, TBool aReplyNeeded );
+    
+private:
+    CCGMMCommandHandler(MATMiscCmdPlugin* aCallback, TAtCommandParser& aATCmdParser, RMobilePhone& aPhone);
+    void ConstructL();
+    
+private:
+    TInt    iTelError;
+    TBuf8<CTelephony::KPhoneManufacturerIdSize> iManufacturer;
+    TBuf8<CTelephony::KPhoneModelIdSize> iModel;
+    
+    RBuf8 iReply;
+    };
+
+#endif /* CGMMCOMMANDHANDLER_H */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/cbsatplugin/atmisccmdplugin/inc/cgmrcommandhandler.h	Wed Aug 18 09:59:05 2010 +0300
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 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"
+ * which accompanies this distribution, and is available
+ * at the URL "http://www.eclipse.org/legal/epl-v10.html".
+ * Initial Contributors:
+ * Nokia Corporation - initial contribution.
+ *
+ * Contributors:
+ * 
+ * Description :
+ * 
+ * CGMRCommandHandler class declaration for AT+CGMR command
+ * 
+ */
+
+#ifndef CGMRCOMMANDHANDLER_H
+#define CGMRCOMMANDHANDLER_H
+
+
+#include "atcmdsyncbase.h"
+
+/**
+ *  AT+CGMR command handler implementation class
+ */
+NONSHARABLE_CLASS( CCGMRCommandHandler ) : public CATCmdSyncBase
+    {
+public:
+    static CCGMRCommandHandler* NewL(MATMiscCmdPlugin* aCallback, TAtCommandParser& aATCmdParser, RMobilePhone& aPhone);
+    ~CCGMRCommandHandler();
+    
+private: // methods from CATCmdSyncBase    
+    virtual void HandleCommand( const TDesC8& aCmd, RBuf8& aReply, TBool aReplyNeeded );
+    
+private:
+    CCGMRCommandHandler(MATMiscCmdPlugin* aCallback, TAtCommandParser& aATCmdParser, RMobilePhone& aPhone);
+    void ConstructL();
+    
+    TInt GetSoftwareVersion();
+    
+private:    
+    RBuf8 iReply;
+    };
+
+#endif /* CGMRCOMMANDHANDLER_H */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/cbsatplugin/atmisccmdplugin/inc/cgsncommandhandler.h	Wed Aug 18 09:59:05 2010 +0300
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 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"
+ * which accompanies this distribution, and is available
+ * at the URL "http://www.eclipse.org/legal/epl-v10.html".
+ * Initial Contributors:
+ * Nokia Corporation - initial contribution.
+ *
+ * Contributors:
+ * 
+ * Description :
+ * 
+ * CGSNCommandHandler class declaration for AT+CGSN command
+ * 
+ */
+
+#ifndef CGSNCOMMANDHANDLER_H
+#define CGSNCOMMANDHANDLER_H
+
+#include "atcmdsyncbase.h"
+
+#include <etel3rdparty.h>
+
+/**
+ *  AT+CGSN command handler implementation class
+ */
+NONSHARABLE_CLASS( CCGSNCommandHandler ) : public CATCmdSyncBase
+    {
+public:
+    static CCGSNCommandHandler* NewL(MATMiscCmdPlugin* aCallback, TAtCommandParser& aATCmdParser, RMobilePhone& aPhone);
+    ~CCGSNCommandHandler();
+    
+public:
+    void SetSerialNum(const TDesC8& aSerial);
+    void SetTelephonyError(TInt aTelError);  
+
+private: // methods from CATCmdSyncBase    
+    virtual void HandleCommand( const TDesC8& aCmd, RBuf8& aReply, TBool aReplyNeeded );
+    
+private:
+    CCGSNCommandHandler(MATMiscCmdPlugin* aCallback, TAtCommandParser& aATCmdParser, RMobilePhone& aPhone);
+    void ConstructL();
+    
+private:
+    TInt    iTelError;
+    TBuf8<CTelephony::KPhoneSerialNumberSize> iSN;
+    
+    RBuf8   iReply;
+    };
+
+#endif /* CGSNCOMMANDHANDLER_H */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/cbsatplugin/atmisccmdplugin/inc/cmgdcommandhandler.h	Wed Aug 18 09:59:05 2010 +0300
@@ -0,0 +1,96 @@
+/*
+ * Copyright (c) 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"
+ * which accompanies this distribution, and is available
+ * at the URL "http://www.eclipse.org/legal/epl-v10.html".
+ * Initial Contributors:
+ * Nokia Corporation - initial contribution.
+ *
+ * Contributors:
+ * 
+ * Description :
+ * 
+ * CCMGDCommandHandler class declaration for AT+CMGD command
+ * 
+ */
+
+#ifndef CMGDCOMMANDHANDLER_H
+#define CMGDCOMMANDHANDLER_H
+
+#include "atcmdasyncbase.h"
+
+#include <etelmm.h>
+
+class CMobilePhoneGsmSmsList;
+class CRetrieveMobilePhoneSmsList;
+/**
+ *  AT+CMGD command handler implementation class
+ */
+NONSHARABLE_CLASS( CCMGDCommandHandler ) : public CATCmdAsyncBase
+    {
+private:
+/**
+ * States for CMGD command handler
+ */
+enum TCMGDState
+    {
+    ECMGDStateIdle,
+    ECMGDStateRetrieveAllIndices,
+    ECMGDStateDeleteOneEntry,
+    ECMGDStateDeleteFilteredEntries,
+    ECMGDStateDeleteAllEntries,
+    ECMGDStateSimStoreNotSupported
+    };
+
+enum TCMGDFilter
+    {
+    ECMGDFilterReadMessagesOnly,
+    ECMGDFilterReadAndSentMessages,
+    ECMGDFilterReadSentAndUnsentMessages
+    };
+
+public:
+    static CCMGDCommandHandler* NewL(MATMiscCmdPlugin* aCallback, TAtCommandParser& aATCmdParser, RMobilePhone& aPhone);
+    ~CCMGDCommandHandler();
+    
+private: // methods from CActive
+    
+    virtual void RunL();
+    virtual void DoCancel();
+    virtual TInt RunError(TInt aError);
+
+private: // methods from CATCmdAsyncBase    
+    
+    virtual void HandleCommand( const TDesC8& aCmd, RBuf8& aReply, TBool aReplyNeeded );
+    
+private:
+    
+    CCMGDCommandHandler(MATMiscCmdPlugin* aCallback, TAtCommandParser& aATCmdParser, RMobilePhone& aPhone);
+    void ConstructL();
+    
+    TInt ParseParameters();
+    TInt DoHandleCommand();
+    
+    void GetMessageIndexListL();
+    void FilterMessageListL();
+    
+private:
+    
+    RMobileSmsMessaging     iMobileSmsMessaging;
+    RMobileSmsStore         iMobileSmsStore;
+    
+    CRetrieveMobilePhoneSmsList* iRetrieveSmsList;
+    CMobilePhoneGsmSmsList*      iGsmSmsList;
+    
+    TCMGDState  iHandlerState;
+    TCMGDFilter    iFilterType;
+    TInt iIndex;
+    TInt iDelFlag;
+    RArray<TInt> iDeleteList;
+    
+    RBuf8 iReply;
+    };
+
+#endif /* CMGDCommandHandler_H */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/cbsatplugin/atmisccmdplugin/inc/cmgwcommandhandler.h	Wed Aug 18 09:59:05 2010 +0300
@@ -0,0 +1,94 @@
+/*
+ * Copyright (c) 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"
+ * which accompanies this distribution, and is available
+ * at the URL "http://www.eclipse.org/legal/epl-v10.html".
+ * Initial Contributors:
+ * Nokia Corporation - initial contribution.
+ *
+ * Contributors:
+ * 
+ * Description :
+ * 
+ * CMGWCommandHandler class declaration for AT+CMGW command
+ * 
+ */
+
+#ifndef CMGWCOMMANDHANDLER_H
+#define CMGWCOMMANDHANDLER_H
+
+#include "atcmdasyncbase.h"
+
+#include <etel3rdparty.h>
+#include <etelmm.h>
+
+class CRetrieveMobilePhoneSmspList;
+class CMobilePhoneSmspList;
+
+/**
+ *  AT+CMGW command handler implementation class
+ */
+NONSHARABLE_CLASS( CCMGWCommandHandler ) : public CATCmdAsyncBase
+    {
+private:
+    enum TCMGWState
+        {
+        ECMGWStateIdle,                     // Idle
+        ECMGWStateEditMode,                 // Edit mode
+        ECMGWStateRetrieveSCA,              // Retrieve SCA
+        ECMGWStatePreparePDU,
+        ECMGWStateWritePDU,                 // Write PDU
+        ECMGWStateSimStoreNotSupported      // Sim store not supported
+        };
+    
+public:
+    static CCMGWCommandHandler* NewL(MATMiscCmdPlugin* aCallback, TAtCommandParser& aATCmdParser, RMobilePhone& aPhone);
+    ~CCMGWCommandHandler();
+    
+    void SetMessageFormat(TInt aFormat);
+    
+private: // methods from CActive
+    virtual void RunL();
+    virtual void DoCancel();
+    virtual TInt RunError (TInt aError);
+
+private: // methods from CATCmdAsyncBase    
+    virtual void HandleCommand( const TDesC8& aCmd, RBuf8& aReply, TBool aReplyNeeded );
+    
+private:
+    CCMGWCommandHandler(MATMiscCmdPlugin* aCallback, TAtCommandParser& aATCmdParser, RMobilePhone& aPhone);
+    void ConstructL();
+
+    void HandleEditModeCommand( const TDesC8& aCmd );
+    TInt ParseParameters();
+    TInt CreateSmsEntry();
+    TInt ExtractSCA();
+    
+private:
+    RMobileSmsMessaging     iMobileSmsMessaging;
+    RMobileSmsStore         iMobileSmsStore;
+    CRetrieveMobilePhoneSmspList* iRetrieveMobilePhoneSmspList;
+    CMobilePhoneSmspList*   iMobilePhoneSmspList;
+    RMobileSmsMessaging::TMobileSmspEntryV1 iMobileSmspEntry;
+    
+    RMobilePhone::TMobileAddress iServiceCentre;
+    
+    TCMGWState iState;
+    RBuf8 iTPDU;
+    
+    TInt iTPDULength;
+    TInt iTPDUStat;
+    TUint8 iSCALength;
+    RMobileSmsStore::TMobileSmsStoreStatus iMessageStatus;
+      
+    RMobileSmsStore::TMobileGsmSmsEntryV1 iEntry;
+    RMobileSmsStore::TMobileGsmSmsEntryV1Pckg iEntryPckg;
+    
+    RBuf8 iReply;
+    
+    TInt iMsgFormat;
+    };
+
+#endif /* CMGWCOMMANDHANDLER_H */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/cbsatplugin/atmisccmdplugin/inc/cmserror.h	Wed Aug 18 09:59:05 2010 +0300
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 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"
+ * which accompanies this distribution, and is available
+ * at the URL "http://www.eclipse.org/legal/epl-v10.html".
+ * Initial Contributors:
+ * Nokia Corporation - initial contribution.
+ *
+ * Contributors:
+ * Description : define all +CMS Error codes.
+ * Reference:
+ *    3GPP TS 27.007 version 6.9.0 Release 6 118 ETSI TS 127 007 V6.9.0 (2007-06)
+ *
+ */
+
+#ifndef CMSERROR_H
+#define CMSERROR_H
+
+enum TATCMSError
+    {
+    EATCmsErrGeneral = 0,
+    EATCMSErr301 = 301,
+    EATCMSErr304 = 304,
+    EATCMSErr310 = 310,
+    EATCMSErr311 = 311,
+    EATCMSErr312 = 312,
+    EATCMSErr316 = 316,
+    EATCMSErr320 = 320,
+    EATCMSErr321 = 321,
+    EATCMSErr322 = 322
+    };
+
+#endif /* CMSERROR_H */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/cbsatplugin/atmisccmdplugin/inc/hvercommandhandler.h	Wed Aug 18 09:59:05 2010 +0300
@@ -0,0 +1,57 @@
+/*
+ * Copyright (c) 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"
+ * which accompanies this distribution, and is available
+ * at the URL "http://www.eclipse.org/legal/epl-v10.html".
+ * Initial Contributors:
+ * Nokia Corporation - initial contribution.
+ *
+ * Contributors:
+ * 
+ * Description :
+ * 
+ * CHVERCommandHandler class declaration for AT^HVER command
+ * 
+ */
+
+#ifndef CHVERCOMMANDHANDLER_H
+#define CHVERCOMMANDHANDLER_H
+
+#include "atcmdsyncbase.h"
+#include "debug.h"
+
+#include <etel3rdparty.h>
+
+/**
+ *  AT^HVER command handler implementation class
+ */
+NONSHARABLE_CLASS( CHVERCommandHandler ) : public CATCmdSyncBase
+    {
+public:
+    static CHVERCommandHandler* NewL(MATMiscCmdPlugin* aCallback, TAtCommandParser& aATCmdParser, RMobilePhone& aPhone);
+    ~CHVERCommandHandler();
+    
+public:
+    void SetHWVersion(const TDesC8& aHWVersion);
+    void SetTelephonyError(TInt aTelError); 
+
+private: // methods from CATCmdSyncBase    
+    virtual void HandleCommand( const TDesC8& aCmd, RBuf8& aReply, TBool aReplyNeeded );
+    
+private:
+    CHVERCommandHandler(MATMiscCmdPlugin* aCallback, TAtCommandParser& aATCmdParser, RMobilePhone& aPhone);
+    void ConstructL();
+    
+    void ParseSWVersion(const TDesC8& aSWVersion);
+    
+private:
+    TInt    iTelError;
+    TBuf8<CTelephony::KPhoneModelIdSize> iModel;
+
+    RBuf8 iSWVersion;
+    RBuf8 iReply;
+    };
+
+#endif /* CHVERCOMMANDHANDLER_H */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/cbsatplugin/atmisccmdplugin/inc/scpbrcommandhandler.h	Wed Aug 18 09:59:05 2010 +0300
@@ -0,0 +1,176 @@
+/*
+ * Copyright (c) 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"
+ * which accompanies this distribution, and is available
+ * at the URL "http://www.eclipse.org/legal/epl-v10.html".
+ * Initial Contributors:
+ * Nokia Corporation - initial contribution.
+ *
+ * Contributors:
+ * 
+ * Description :
+ * 
+ * CSCPBRCommandHandler class declaration for AT^SCPBR command
+ * 
+ */
+
+#ifndef SCPBRCOMMANDHANDLER_H_
+#define SCPBRCOMMANDHANDLER_H_
+
+#include <e32base.h>
+#include <etelmm.h>
+#include <e32cmn.h>
+#include <rmmcustomapi.h>
+
+#include "atcmdasyncbase.h"
+#include "atmisccmdpluginconsts.h"
+
+class CPhoneBookBuffer;
+
+/**
+ *  AT^SCPBR command handler implementation class
+ */
+NONSHARABLE_CLASS( CSCPBRCommandHandler ) : public CATCmdAsyncBase
+	{
+private:
+
+	/**
+	 * SCPBR States
+	 */
+	enum TSCPBRState
+	    {
+        ESCPBRStateIdle,                  // Idle
+        ESCPBRStateRead,                  // Read
+        ESCPBRStateGetPhoneBookInfo,      // Get phone book info.
+        ESCPBRStateGet3GPBInfo,           // Get 3G phone book info.
+        ESCPBRStateNotSupported           // phone book store not supported
+	    };
+private:
+	/**
+	 *  The data structure of phone book entry.
+	 *  Inner class used by CSCPBRCommandHandler only.
+	 */
+	class TPhoneBookEntry
+	    {
+    public:
+	    TPhoneBookEntry(): iIndex(-1)
+            {
+            }
+	    
+	    void Externalize( TDes8& aDes ) const;
+
+        TInt iIndex;
+
+        TBuf8<KSCPBRMaxNumberLength> iNumber1;
+        TBuf8<KSCPBRMaxNumberLength> iNumber2;
+        TBuf8<KSCPBRMaxNumberLength> iNumber3;
+        TBuf8<KSCPBRMaxNumberLength> iNumber4;
+
+        TBuf8<KSCPBRMaxNameLength> iName;
+
+        TBuf8<KSCPBRMaxEmailLength> iEmail;
+	    };
+	
+public:
+	static CSCPBRCommandHandler* NewL(MATMiscCmdPlugin* aCallback, TAtCommandParser& aATCmdParser, RMobilePhone& aPhone );
+	
+	virtual ~CSCPBRCommandHandler();
+
+private: // from CATCmdAsyncBase
+	virtual void HandleCommand(const TDesC8& aCmd, RBuf8& aReply, TBool aReplyNeeded);
+	
+private: // from CActive
+	virtual void RunL();
+	virtual void DoCancel();
+	virtual TInt RunError(TInt aError);
+	
+private:	
+	CSCPBRCommandHandler(MATMiscCmdPlugin* aCallback, TAtCommandParser& aATCmdParser, RMobilePhone& aPhone );
+	void ConstructL();
+
+	void ExtractEntriesL();
+	void CopyToPhonebookEntryField(TDes8& aDest, const TDesC16& aSrc);
+	void FormatReplyL();
+	TInt ParseParameters();
+	void AppendEntryL(const TPhoneBookEntry& aEntry);
+	
+private:
+	/**
+	 * The first index to be read from phonebook store.
+	 */
+    TInt iIndex1;
+
+	/**
+	 * The last index to be read from phonebook store.
+	 */
+    TInt iIndex2;
+
+	/**
+	 * The reply
+	 */
+    RBuf8 iReply;
+
+	/**
+	 * The phone book store. used to get entries information and entries.
+	 */
+    RMobilePhoneBookStore iPhoneBookStore;
+    
+	/**
+	 * used to save the entries information.
+	 */
+    RArray<TPhoneBookEntry> iEntries;
+
+	/**
+	 * Used to parse the content get from PhoneBookStore.
+	 */
+    CPhoneBookBuffer* iPhoneBookBuffer;
+    
+	/**
+	 * The buffer to get phonebookstore entries content.
+	 */
+    RBuf8 iContactsBuf; 
+    
+	/**
+	 * Current state
+	 */
+    TSCPBRState iState;
+    
+	/**
+	 * The PhonebookInfo, used to get phone book entries information.
+	 */
+    RMobilePhoneBookStore::TMobilePhoneBookInfoV1 iPhoneBookInfo;
+    
+    /**
+     * Total entries supported by phonebook store.
+     */
+    TInt iTotalEntries;
+	/**
+	 * The max number length supported
+	 */
+    TInt iNLength;
+
+	/**
+	 * The max email length supported.
+	 */
+    TInt iMLength;
+
+	/**
+	 * The max text length supported.
+	 */
+    TInt iTLength;
+    
+	/**
+	 * Used to get 3GPBInfo.
+	 */ 
+    RMmCustomAPI iCustomApi;
+    
+	/**
+	 * Used to get 3GPBInfo.
+	 */
+    RMmCustomAPI::T3GPBInfo i3GPBInfo;
+
+    };
+
+#endif /* SCPBRCOMMANDHANDLER_H_ */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/cbsatplugin/atmisccmdplugin/inc/scpbwcommandhandler.h	Wed Aug 18 09:59:05 2010 +0300
@@ -0,0 +1,99 @@
+/*
+ * Copyright (c) 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"
+ * which accompanies this distribution, and is available
+ * at the URL "http://www.eclipse.org/legal/epl-v10.html".
+ * Initial Contributors:
+ * Nokia Corporation - initial contribution.
+ *
+ * Contributors:
+ * 
+ * Description :
+ * 
+ * SCPBWCommandHandler class declaration for AT^SCPBW command
+ * 
+ */
+
+#ifndef SCPBWCOMMANDHANDLER_H
+#define SCPBWCOMMANDHANDLER_H
+
+#include "atcmdasyncbase.h"
+
+#include <etelmm.h>
+#include <rmmcustomapi.h>
+
+class CPhoneBookBuffer;
+
+/**
+ *  AT^SCPBW command handler implementation class
+ */
+NONSHARABLE_CLASS( CSCPBWCommandHandler ) : public CATCmdAsyncBase
+    {
+private:
+    enum TSCPBWState
+        {
+        ESCPBWStateIdle,
+        ESCPBWStateGetPhonebookInfo,
+        ESCPBWStateGet3GPBInfo,
+        ESCPBWStateWrite,
+        ESCPBWStateDelete,
+        ESCPBWStateSimStoreNotSupported 
+        };
+    
+public:
+    static CSCPBWCommandHandler* NewL(MATMiscCmdPlugin* aCallback, TAtCommandParser& aATCmdParser, RMobilePhone& aPhone);
+    ~CSCPBWCommandHandler();
+        
+private: // methods from CActive
+    virtual void RunL();
+    virtual void DoCancel();
+
+private: // methods from CATCmdAsyncBase    
+    virtual void HandleCommand( const TDesC8& aCmd, RBuf8& aReply, TBool aReplyNeeded );
+    
+private:
+    CSCPBWCommandHandler(MATMiscCmdPlugin* aCallback, TAtCommandParser& aATCmdParser, RMobilePhone& aPhone);
+    void ConstructL();
+
+    TInt ParseParameters( TBool& aIsDeleteRequest );
+    TInt CreateContactEntry();
+    void ResetParameters();    
+    void SetBuffer(TDes& aDest, const TDesC8& aSource);
+    
+private:
+
+    RMobilePhoneBookStore   iPhoneBookStore;
+    CPhoneBookBuffer*       iPhoneBookBuffer;
+    RMobilePhoneBookStore::TMobilePhoneBookInfoV1 iPhoneBookStoreInfo;
+    RMmCustomAPI    iMmCustomAPI;
+    RMmCustomAPI::T3GPBInfo i3GPBInfo;
+    
+    TInt    iIndex;
+    RBuf    iNum1;
+    TInt    iType1;
+    RBuf    iNum2;
+    TInt    iType2;
+    RBuf    iNum3;
+    TInt    iType3;
+    RBuf    iNum4;
+    TInt    iType4;
+    RBuf    iText;
+    TInt    iCoding;
+    RBuf    iEmail;
+    
+    TInt    iNumLength;
+    TInt    iTextLength;
+    TInt    iEmailLength;
+    TInt    iMaxEntries;
+
+    RBuf8   iPbData;
+    
+    TSCPBWState iState;
+    
+    RBuf8 iReply;
+    
+    };
+
+#endif /* SCPBWCOMMANDHANDLER_H */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/cbsatplugin/atmisccmdplugin/inc/telephonywrapper.h	Wed Aug 18 09:59:05 2010 +0300
@@ -0,0 +1,60 @@
+/*
+ * Copyright (c) 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"
+ * which accompanies this distribution, and is available
+ * at the URL "http://www.eclipse.org/legal/epl-v10.html".
+ * Initial Contributors:
+ * Nokia Corporation - initial contribution.
+ *
+ * Contributors:
+ * 
+ * Description :
+ * 
+ * CTelephonyWrapper class declaration for wrapping CTelephony::GetPhoneId 
+ * 
+ */
+
+#ifndef TELEPHONYWRAPPER_H
+#define TELEPHONYWRAPPER_H
+
+#include <etel3rdparty.h>
+
+/**
+ *  Synchronous wrapper for CTelephony::GetPhoneId 
+ */
+NONSHARABLE_CLASS (CTelephonyWrapper) : public CActive   
+    {     
+public:
+    static CTelephonyWrapper* NewL();         
+    virtual ~CTelephonyWrapper();     
+
+    TInt SynchronousGetPhoneId(); 
+
+    const TDesC8& GetPhoneModel();
+    const TDesC8& GetPhoneSerialNum();
+    const TDesC8& GetPhoneManufacturer();
+
+private: // From CActive
+    virtual void RunL();
+    virtual void DoCancel();
+    
+private: // Constructors
+    CTelephonyWrapper();
+    void ConstructL();
+    
+private:                
+    CActiveSchedulerWait        iWaiter;
+    
+    CTelephony*                 iTelephony;
+    CTelephony::TPhoneIdV1      iPhoneIdV1;
+    CTelephony::TPhoneIdV1Pckg  iPhoneIdV1Pckg;    
+    
+    TBufC8<CTelephony::KPhoneModelIdSize> iModel;
+    TBufC8<CTelephony::KPhoneSerialNumberSize> iSn;
+    TBufC8<CTelephony::KPhoneManufacturerIdSize> iManufacturer;
+    
+    };
+
+#endif /* TELEPHONYWRAPPER_H */
--- a/cbsatplugin/atmisccmdplugin/rom/atmisccmdplugin.iby	Tue Jul 06 14:27:09 2010 +0300
+++ b/cbsatplugin/atmisccmdplugin/rom/atmisccmdplugin.iby	Wed Aug 18 09:59:05 2010 +0300
@@ -16,7 +16,11 @@
 #ifndef ATMISCCMDPLUGIN_IBY
 #define ATMISCCMDPLUGIN_IBY
 
+#ifdef PROTOCOL_TDSCDMA
+ECOM_PLUGIN(atmisccmdplugin_td.dll, atmisccmdplugin_td.rsc)
+#else
 ECOM_PLUGIN(atmisccmdplugin.dll, atmisccmdplugin.rsc)
+#endif
 
 #endif // ATMISCCMDPLUGIN_IBY
 
--- a/cbsatplugin/atmisccmdplugin/src/atcommandparser.cpp	Tue Jul 06 14:27:09 2010 +0300
+++ b/cbsatplugin/atmisccmdplugin/src/atcommandparser.cpp	Wed Aug 18 09:59:05 2010 +0300
@@ -58,7 +58,29 @@
     _LIT8(KAtCpin, "AT+CPIN");
     _LIT8(KAtCusd, "AT+CUSD");
     _LIT8(KAtCnum, "AT+CNUM");
-    _LIT8(KAtCmee, "AT+CMEE");
+	_LIT8(KAtCmee, "AT+CMEE");
+#ifdef PROTOCOL_TDSCDMA
+    _LIT8(KAtHver, "AT^HVER");
+    _LIT8(KAtCgsn, "AT+CGSN");
+    _LIT8(KAtCgmr, "AT+CGMR");
+    _LIT8(KAtCgmi, "AT+CGMI");
+    _LIT8(KAtCmgw, "AT+CMGW");
+	_LIT8(KAtCmgd, "AT+CMGD");
+	_LIT8(KAtCmgf, "AT+CMGF");
+	_LIT8(KAtiBase, "ATI");
+	_LIT8(KAti0, "ATI0");
+	_LIT8(KAti1, "ATI1");
+	_LIT8(KAti2, "ATI2");
+	_LIT8(KAti3, "ATI3");
+	_LIT8(KAti4, "ATI4");
+	_LIT8(KAtGmr, "AT+GMR");
+	_LIT8(KAtGmi, "AT+GMI");
+	_LIT8(KAtGsn, "AT+GSN");
+	_LIT8(KAtCgmm, "AT+CGMM");
+	_LIT8(KAtGmm, "AT+GMM");
+	_LIT8(KAtScpbr, "AT^SCPBR");
+	_LIT8(KAtScpbw, "AT^SCPBW");
+#endif
     
     Trace(KDebugPrintS, "token: ", &token);
     // Determine the AT command type
@@ -90,10 +112,92 @@
         {
         iCmdType = ECmdAtCnum;
         }
-    else if(!token.Compare(KAtCmee))
+    else if(!token.CompareF(KAtCmee))
         {
         iCmdType = ECmdAtCmee;
+		}
+#ifdef PROTOCOL_TDSCDMA
+    else if(!token.CompareF(KAtHver))
+        {
+        iCmdType = ECmdAtHver;
         }
+    else if(!token.CompareF(KAtCgsn))
+        {
+        iCmdType = ECmdAtCgsn;
+        }
+    else if(!token.CompareF(KAtGsn))
+        {
+        iCmdType = ECmdAtGsn;
+        }
+    else if(!token.CompareF(KAtCgmr))
+        {
+        iCmdType = ECmdAtCgmr;
+        }
+    else if(!token.CompareF(KAtGmr))
+        {
+        iCmdType = ECmdAtGmr;
+        }
+    else if(!token.CompareF(KAtCgmi))
+        {
+        iCmdType = ECmdAtCgmi;
+        }    
+    else if(!token.CompareF(KAtGmi))
+        {
+        iCmdType = ECmdAtGmi;
+        } 
+    else if(!token.CompareF(KAtCmgw))
+        {
+        iCmdType = ECmdAtCmgw;
+        }
+    else if(!token.CompareF(KAtCmgd))
+        {
+        iCmdType = ECmdAtCmgd;
+        }
+    else if(!token.CompareF(KAtCmgf))
+        {
+        iCmdType = ECmdAtCmgf;
+        }
+    else if(!token.CompareF(KAtCgmm))
+        {
+        iCmdType = ECmdAtCgmm;
+        }
+    else if(!token.CompareF(KAtGmm))
+        {
+        iCmdType = ECmdAtGmm;
+        }
+    else if(!token.CompareF(KAtiBase))
+        {
+        iCmdType = ECmdAtI;
+        }
+    else if(!token.CompareF(KAti0))
+        {
+        iCmdType = ECmdAtI0;
+        }
+    else if(!token.CompareF(KAti1))
+        {
+        iCmdType = ECmdAtI1;
+        }
+    else if(!token.CompareF(KAti2))
+        {
+        iCmdType = ECmdAtI2;
+        }
+    else if(!token.CompareF(KAti3))
+        {
+        iCmdType = ECmdAtI3;
+        }
+    else if(!token.CompareF(KAti4))
+        {
+        iCmdType = ECmdAtI4;
+        }
+	else if(!token.CompareF(KAtScpbr))
+        {
+        iCmdType = ECmdAtScpbr;
+        } 
+    else if(!token.CompareF(KAtScpbw))
+        {
+        iCmdType = ECmdAtScpbw;
+        }
+#endif    
     else
         {
         iCmdType = EUnknown;
@@ -164,12 +268,14 @@
     // Extract the token at this point            
     TPtrC8 retVal = iCmd.MarkedToken();
     
-    // Skip comma, space and control chars
-    while(!iCmd.Eos() && (chr == ',' || chr.IsSpace() || chr.IsControl()))
-        {
-        iCmd.Inc();
-        chr = iCmd.Peek();
-        }
+    // Skip the first delimiter and any further space and control chars
+    do
+      {
+      iCmd.Inc();
+      chr = iCmd.Peek();
+      }
+    while(!iCmd.Eos() && (chr.IsSpace() || chr.IsControl()));
+    
     TRACE_FUNC_EXIT
     return retVal;
     }
--- a/cbsatplugin/atmisccmdplugin/src/atmisccmdplugin.cpp	Tue Jul 06 14:27:09 2010 +0300
+++ b/cbsatplugin/atmisccmdplugin/src/atmisccmdplugin.cpp	Wed Aug 18 09:59:05 2010 +0300
@@ -24,20 +24,47 @@
 #include "cnumcommandhandler.h"
 #include "cfuncommandhandler.h"
 #include "cbccommandhandler.h"
+#ifdef PROTOCOL_TDSCDMA
+#include "hvercommandhandler.h"
+#include "cgsncommandhandler.h"
+#include "cgmrcommandhandler.h"
+#include "cgmicommandhandler.h"
+#include "cmgwcommandhandler.h"
+#include "cmgdcommandhandler.h"
+#include "telephonywrapper.h"
+#include "cgmmcommandhandler.h"
+#include "scpbrcommandhandler.h"
+#include "scpbwcommandhandler.h"
+#endif
+
 
 #include "atmisccmdpluginconsts.h"
+#include "cmserror.h"
 #include "debug.h"
 
-#include <EXTERROR.H>           // Additional RMobilePhone error code
+#include <exterror.h>           // Additional RMobilePhone error code
+#include <etelmmerr.h>          // ETelMM error code
+#include <gsmerror.h>           // GSM error code
 
 // +CME error code
+_LIT8(KCMEMemoryFailure, "+CME ERROR: 23\r\n"); // Memory failure.\r\n
 _LIT8(KCMEIncorrectPassword, "+CME ERROR: 16\r\n"); // Incorrect password.\r\n
 _LIT8(KCMEPUKRequired, "+CME ERROR: 12\r\n"); // PUK required.\r\n
 _LIT8(KCMENotAllowed, "+CME ERROR: 3\r\n"); // Operation not allowed.\r\n
 _LIT8(KCMEPhoneError, "+CME ERROR: 0\r\n"); // Phone failure.\r\n
 _LIT8(KCMEPhoneUnknown, "+CME ERROR: 100\r\n"); // unknown error
+_LIT8(KCMESimNotInserted, "+CME ERROR: 10\r\n"); // SIM not inserted 
+_LIT8(KCMEMemoryFull, "+CME ERROR: 20\r\n"); // Memory full
+_LIT8(KCMEInvalidIndex, "+CME ERROR: 21\r\n"); // Invalid index 
+_LIT8(KCMENotFound, "+CME ERROR: 22\r\n"); // Not found 
+_LIT8(KCMEDialStringTooLong, "+CME ERROR: 26\r\n"); // Dial string too long 
+_LIT8(KCMETextStringTooLong, "+CME ERROR: 24\r\n"); // Text string too long 
+_LIT8(KCMEInvalidCharacters, "+CME ERROR: 27\r\n"); // Invalid characters in dial string
+
+
 
 const TInt KErrorReplyLength = 9;  // CR+LF+"ERROR"+CR+LF
+const TInt KEditorReplyLength = 4;  // CR+LF+'>'+' '
 
 CATMiscCmdPlugin* CATMiscCmdPlugin::NewL()
     {
@@ -59,7 +86,18 @@
     delete iCNUMHandler;
     delete iCFUNHandler;
     delete iCBCHandler;
-    
+#ifdef PROTOCOL_TDSCDMA
+	delete iHVERHandler;
+	delete iCGSNHandler;
+    delete iCGMRHandler;
+    delete iCGMIHandler;
+    delete iCMGWHandler;
+    delete iCMGDHandler;
+    delete iCGMMHandler;
+	delete iSCPBRHandler;
+    delete iSCPBWHandler;
+#endif    
+	
     iPhone.Close();
     iTelServer.Close();
 	}
@@ -81,6 +119,41 @@
     iCNUMHandler = CCNUMCommandHandler::NewL(this, iCommandParser, iPhone, iTelServer);
     iCFUNHandler = CCFUNCommandHandler::NewL(this, iCommandParser, iPhone);
     iCBCHandler = CCBCCommandHandler::NewL(this, iCommandParser, iPhone);
+    
+#ifdef PROTOCOL_TDSCDMA
+	iHVERHandler = CHVERCommandHandler::NewL(this, iCommandParser, iPhone);
+    iCGSNHandler = CCGSNCommandHandler::NewL(this, iCommandParser, iPhone);
+    iCGMRHandler = CCGMRCommandHandler::NewL(this, iCommandParser, iPhone);
+    iCGMIHandler = CCGMICommandHandler::NewL(this, iCommandParser, iPhone);
+    iCMGWHandler = CCMGWCommandHandler::NewL(this, iCommandParser, iPhone);
+    iCMGDHandler = CCMGDCommandHandler::NewL(this, iCommandParser, iPhone); 
+    iCGMMHandler = CCGMMCommandHandler::NewL(this, iCommandParser, iPhone);
+	iSCPBRHandler = CSCPBRCommandHandler::NewL(this, iCommandParser, iPhone);
+    iSCPBWHandler = CSCPBWCommandHandler::NewL(this, iCommandParser, iPhone);
+    
+   
+    // Get telephony information - Model, IMEI, Manufacturer
+    CTelephonyWrapper* telephonyWrapper = CTelephonyWrapper::NewL();
+    TInt result = telephonyWrapper->SynchronousGetPhoneId();
+
+    if (KErrNone == result)
+        {
+        static_cast<CHVERCommandHandler*>(iHVERHandler)->SetHWVersion(telephonyWrapper->GetPhoneModel());
+        static_cast<CCGSNCommandHandler*>(iCGSNHandler)->SetSerialNum(telephonyWrapper->GetPhoneSerialNum());
+        static_cast<CCGMICommandHandler*>(iCGMIHandler)->SetManufacturer(telephonyWrapper->GetPhoneManufacturer());
+        static_cast<CCGMMCommandHandler*>(iCGMMHandler)->SetManufacturer(telephonyWrapper->GetPhoneManufacturer());
+        static_cast<CCGMMCommandHandler*>(iCGMMHandler)->SetModelID(telephonyWrapper->GetPhoneModel());
+        }
+    else // The result is used to determine whether to display CME error or not
+        {
+        static_cast<CHVERCommandHandler*>(iHVERHandler)->SetTelephonyError(result);
+        static_cast<CCGSNCommandHandler*>(iCGSNHandler)->SetTelephonyError(result);
+        static_cast<CCGMICommandHandler*>(iCGMIHandler)->SetTelephonyError(result);
+        static_cast<CCGMMCommandHandler*>(iCGMMHandler)->SetTelephonyError(result);
+        }
+    delete telephonyWrapper;
+#endif    
+    
     TRACE_FUNC_EXIT
    	}
 
@@ -150,9 +223,71 @@
             }
         case (TAtCommandParser::ECmdAtCmee):
             {
+            iCurrentHandler = NULL;	
+            break;
+			}
+#ifdef PROTOCOL_TDSCDMA
+        case (TAtCommandParser::ECmdAtHver):
+            {
+            iCurrentHandler = iHVERHandler;
+            break;
+            }
+        case (TAtCommandParser::ECmdAtCgsn): // intentional fall through
+        case (TAtCommandParser::ECmdAtGsn):
+        case (TAtCommandParser::ECmdAtI1):
+            {
+            iCurrentHandler = iCGSNHandler;
+            break;
+            }
+        case (TAtCommandParser::ECmdAtCgmr): // intentional fall through
+        case (TAtCommandParser::ECmdAtGmr):
+        case (TAtCommandParser::ECmdAtI2):
+        case (TAtCommandParser::ECmdAtI4):
+            {
+            iCurrentHandler = iCGMRHandler;
+            break;
+            }
+        case (TAtCommandParser::ECmdAtCgmi): // intentional fall through
+        case (TAtCommandParser::ECmdAtGmi):
+        case (TAtCommandParser::ECmdAtI):
+        case (TAtCommandParser::ECmdAtI0):
+            {
+            iCurrentHandler = iCGMIHandler;
+            break;
+            }
+        case (TAtCommandParser::ECmdAtCmgw):
+            {
+            iCurrentHandler = iCMGWHandler;
+            break;
+            }
+		case (TAtCommandParser::ECmdAtCmgd):
+            {
+            iCurrentHandler = iCMGDHandler;
+            break;
+            }
+		case (TAtCommandParser::ECmdAtCmgf):
+            {
             iCurrentHandler = NULL;
             break;
             }
+		case (TAtCommandParser::ECmdAtCgmm): // intentional fall through
+		case (TAtCommandParser::ECmdAtGmm):
+		case (TAtCommandParser::ECmdAtI3):
+            {
+            iCurrentHandler = iCGMMHandler;
+            break;
+            }
+		case (TAtCommandParser::ECmdAtScpbr):
+            {
+            iCurrentHandler = iSCPBRHandler;
+            break;
+            }    
+		case (TAtCommandParser::ECmdAtScpbw):
+            {
+            iCurrentHandler = iSCPBWHandler;
+            break;
+            }
+#endif
         case (TAtCommandParser::EUnknown):
         default:
             {
@@ -179,6 +314,13 @@
         HandleCMEECommand();
         HandleCommandCompleted( KErrNone, EReplyTypeOk);
 	    }
+#ifdef PROTOCOL_TDSCDMA
+	else if (iCommandParser.Command() == TAtCommandParser::ECmdAtCmgf)
+	    {
+        HandleCMGFCommand();
+        HandleCommandCompleted( KErrNone, EReplyTypeOk);
+	    }
+#endif
 	else if (iCurrentHandler != NULL)
 	    {
 	    iHcCmd = &aCmd;
@@ -278,30 +420,29 @@
     {
     TRACE_FUNC_ENTRY
     TInt ret = KErrNone;
-    TInt partLength;
     if ( iReplyBuffer.Length() <= 0 )
         {
         ret = KErrGeneral;
         }
     else
         {
-        partLength = NextReplyPartLength();
+    	TInt partLength = NextReplyPartLength();
         if ( iReplyBuffer.Length() < partLength )
             {
             ret =  KErrNotFound;
             }
-        }
-    Trace(KDebugPrintD, "ret: ", ret);
-    if (ret == KErrNone)
-        {
-        aBuffer.Create( iReplyBuffer, partLength );
-        iReplyBuffer.Delete( 0, partLength );
-        if ( iReplyBuffer.Length() == 0 )
-            {
-            iReplyBuffer.Close();
-            }
+        else if (ret == KErrNone)
+			{
+			aBuffer.Create( iReplyBuffer, partLength );
+			iReplyBuffer.Delete( 0, partLength );
+			if ( iReplyBuffer.Length() == 0 )
+				{
+				iReplyBuffer.Close();
+				}
+			}
         }
 
+    Trace(KDebugPrintD, "ret: ", ret);
     TRACE_FUNC_EXIT
     return ret;
     }
@@ -348,6 +489,11 @@
         {
         case EReplyTypeOther:
             break;
+#ifdef PROTOCOL_TDSCDMA
+        case EReplyTypeEditor:
+            CreateEditModeBuffer( iReplyBuffer );
+            break;
+#endif
         case EReplyTypeOk:
             CreateOkOrErrorReply( iReplyBuffer, ETrue );
             break;
@@ -360,9 +506,12 @@
         }
     CreatePartOfReply( *iHcReply );
     HandleCommandCompleted( KErrNone, aReplyType );
-    iHcCmd = NULL;
-    iHcReply = NULL;
-    iCurrentHandler = NULL;
+    if ( EReplyTypeEditor != aReplyType )
+        {
+        iHcCmd = NULL;
+        iHcReply = NULL;
+        iCurrentHandler = NULL;
+        }
     TRACE_FUNC_EXIT
     return KErrNone;
     }
@@ -414,6 +563,28 @@
     }
 
 /**
+ * @see MATMiscCmdPlugin::CreateEditModeBuffer
+ */
+TInt CATMiscCmdPlugin::CreateEditModeBuffer( RBuf8& aReplyBuffer )
+    {
+    TRACE_FUNC_ENTRY
+    _LIT8( KReplyPromptAndSpace, "> " );
+    TBuf8<KEditorReplyLength> replyBuffer;
+    replyBuffer.Append( iCarriageReturn );
+    replyBuffer.Append( iLineFeed );
+    replyBuffer.Append( KReplyPromptAndSpace );
+
+    TInt err = aReplyBuffer.ReAlloc( aReplyBuffer.Length() + replyBuffer.Length() );
+    if (KErrNone != err)
+        {
+        return err;
+        }
+    aReplyBuffer.Append( replyBuffer );
+    TRACE_FUNC_EXIT
+    return KErrNone;
+    }
+
+/**
  * @see MATMiscCmdPlugin::GetCharacterValue
  */
 TInt CATMiscCmdPlugin::GetCharacterValue( TCharacterTypes aCharType,
@@ -501,12 +672,64 @@
                 response.Append(KCMENotAllowed);
                 break;
                 }
+			case KErrGsmMMImeiNotAccepted:
+	            {
+	            // Memory failure
+	            response.Append(KCMEMemoryFailure);
+	            break;
+	            }
             case KErrUnknown:
+            case KErrGsmSimServAnrFull:
                 {
                 // unknown error
                 response.Append(KCMEPhoneUnknown);
                 break;
                 }
+            case KErrNotFound:
+                {
+                response.Append(KCMENotFound);
+                break;
+                }
+            case KErrInUse:
+            case KErrGsmMMServiceOptionTemporaryOutOfOrder:
+                {
+                // SIM not inserted
+                response.Append(KCMESimNotInserted);
+                break;
+                }
+            case KErrArgument:
+            case KErrGsm0707InvalidIndex:
+            case KErrGsm0707NotFound:
+                {
+                // Invalid index
+                response.Append(KCMEInvalidIndex);
+                break;
+                }
+            case KErrGsm0707TextStringTooLong:
+                {
+                // Text string too long
+                response.Append(KCMETextStringTooLong);
+                break;
+                }
+            case KErrGsm0707DialStringTooLong:
+                {
+                // Dial string too long
+                response.Append(KCMEDialStringTooLong);
+                break;
+                }
+            case KErrGsmCCUnassignedNumber:
+            case KErrGsm0707InvalidCharsInDialString:
+                {
+                // Invalid characters in dial string
+                response.Append(KCMEInvalidCharacters);
+                break;
+                }
+            case KErrMMEtelMaxReached:
+                {
+                // Memory full
+                response.Append(KCMEMemoryFull);
+                break;
+                }
             default:
                 {
                 response.Append(KCMEPhoneError);
@@ -524,6 +747,100 @@
     TRACE_FUNC_EXIT
     }
 
+void CATMiscCmdPlugin::CreateCMSReplyAndComplete(TInt aError)
+    {
+    TRACE_FUNC_ENTRY
+    
+    if(iQuietMode)
+        {
+        CreateReplyAndComplete(EReplyTypeError);
+        }
+    else 
+        {
+        // return error code to AT client
+        RBuf8 response;
+        if (KErrNone != response.Create(KDefaultCmdBufLength))
+            {
+            CreateReplyAndComplete(EReplyTypeError);
+            return;
+            }
+       
+        // return error code to AT client
+        response.Append(KCRLF);
+        response.Append(KCMSErr);
+
+        switch(aError)
+            {
+            case KErrGsmSMSReserved:
+                {
+                // Other application cause SMS interface being reserved
+                response.AppendNum(EATCMSErr301);
+                break;
+                }
+            case KErrGsmSMSInvalidPDUModeParameter:
+                {
+                // Under the mode of PDU, PDU parameter error 
+                response.AppendNum(EATCMSErr304);
+                break;
+                }
+            case KErrGsm0707SimFailure:
+            case KErrGsmMMServiceOptionTemporaryOutOfOrder:
+                {    
+                // SIM card not inserted
+                response.AppendNum(EATCMSErr310);
+                break;
+                }
+            case KErrGsmSMSSimPin1Required:
+                {
+                // PIN request by SIM card
+                response.AppendNum(EATCMSErr311);
+                break;
+                }
+            case KErrGsmSMSPhoneToSimLockRequired:
+                {
+                // PH-(U) SIM PIN request by SIM card
+                response.AppendNum(EATCMSErr312);
+                break;
+                }
+            case KErrGsmSMSSimPuk1Required:
+                {
+                // PUK request by SIM card
+                response.AppendNum(EATCMSErr316);
+                break;
+                }
+            case KErrGsmSMSMemoryFailure:
+                {
+                // Memory error
+                response.AppendNum(EATCMSErr320);
+                break;
+                }
+            case KErrPathNotFound:
+            case KErrGsmSMSInvalidMemoryIndex:
+                {
+                // Invalid Memory index number 
+                response.AppendNum(EATCMSErr321);
+                break;
+                }
+            case KErrOverflow:
+            case KErrGsmSMSMemoryFull:
+                {
+                // Memory is full
+                response.AppendNum(EATCMSErr322);
+                break;
+                }
+            default:
+				{
+				response.AppendNum(EATCmsErrGeneral);
+				break;
+				}
+            }
+        CreateReplyAndComplete( EReplyTypeError, response );
+        response.Close();
+        }
+    
+    TRACE_FUNC_EXIT
+    }
+
 TInt CATMiscCmdPlugin::HandleUnsolicitedRequest(const TDesC8& aAT )
     {
     TRACE_FUNC_ENTRY
@@ -555,6 +872,29 @@
     TRACE_FUNC_EXIT
     }
 
+
+void CATMiscCmdPlugin::HandleCMGFCommand()
+    {
+    TRACE_FUNC_ENTRY
+    
+#ifdef PROTOCOL_TDSCDMA    
+    TAtCommandParser::TCommandHandlerType cmdHandlerType = iCommandParser.CommandHandlerType();
+    
+    if (cmdHandlerType == TAtCommandParser::ECmdHandlerTypeSet)
+        {
+        TInt msgFormat = 0;
+        TInt ret = iCommandParser.NextIntParam(msgFormat);
+        if(ret == KErrNone && iCMGWHandler)
+            {
+            static_cast<CCMGWCommandHandler*> (iCMGWHandler)->SetMessageFormat(msgFormat);
+            }
+        }
+#endif  
+    
+    TRACE_FUNC_EXIT
+    }
+  
+
 void CATMiscCmdPlugin::ConnectToEtelL(RTelServer& aTelServer, RMobilePhone& aPhone)
     {
     TRACE_FUNC_ENTRY
@@ -571,6 +911,12 @@
         }
     User::LeaveIfError(aTelServer.GetPhoneInfo(0, info));
     User::LeaveIfError(aPhone.Open(aTelServer, info.iName));
+    
+    if (iTelServer.SetExtendedErrorGranularity(RTelServer::EErrorExtended)!=KErrNone)
+        {
+        User::LeaveIfError(iTelServer.SetExtendedErrorGranularity(RTelServer::EErrorBasic));
+        }
+
     TRACE_FUNC_EXIT
     }
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/cbsatplugin/atmisccmdplugin/src/cgmicommandhandler.cpp	Wed Aug 18 09:59:05 2010 +0300
@@ -0,0 +1,112 @@
+/*
+ * Copyright (c) 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"
+ * which accompanies this distribution, and is available
+ * at the URL "http://www.eclipse.org/legal/epl-v10.html".
+ * Initial Contributors:
+ * Nokia Corporation - initial contribution.
+ *
+ * Contributors:
+ * Description :
+ *
+ */
+
+#include "cgmicommandhandler.h"
+
+#include "atmisccmdpluginconsts.h"
+#include "debug.h"
+
+CCGMICommandHandler* CCGMICommandHandler::NewL(MATMiscCmdPlugin* aCallback, TAtCommandParser& aATCmdParser, RMobilePhone& aPhone)
+    {
+    TRACE_FUNC_ENTRY
+    CCGMICommandHandler* self = new (ELeave) CCGMICommandHandler(aCallback, aATCmdParser, aPhone);
+    CleanupStack::PushL(self);
+    self->ConstructL();
+    CleanupStack::Pop(self);
+    TRACE_FUNC_EXIT
+    return self;
+    }
+
+CCGMICommandHandler::CCGMICommandHandler(MATMiscCmdPlugin* aCallback, TAtCommandParser& aATCmdParser, RMobilePhone& aPhone) :
+    CATCmdSyncBase(aCallback, aATCmdParser, aPhone)
+    {
+    TRACE_FUNC_ENTRY
+    TRACE_FUNC_EXIT
+    }
+
+void CCGMICommandHandler::ConstructL()
+    {
+    TRACE_FUNC_ENTRY
+    iReply.CreateL(KDefaultCmdBufLength);
+    TRACE_FUNC_EXIT
+    }
+
+CCGMICommandHandler::~CCGMICommandHandler()
+    {
+    TRACE_FUNC_ENTRY
+    iReply.Close();
+    TRACE_FUNC_EXIT
+    }
+
+void CCGMICommandHandler::HandleCommand(const TDesC8& /*aCmd*/, RBuf8& /*aReply*/, TBool /*aReplyNeeded*/)
+    {
+    TRACE_FUNC_ENTRY
+    
+    TAtCommandParser::TCommandHandlerType cmdHandlerType = iATCmdParser.CommandHandlerType();
+    
+    switch (cmdHandlerType)
+        {
+        case (TAtCommandParser::ECmdHandlerTypeTest):
+            {
+            iCallback->CreateReplyAndComplete( EReplyTypeOk );
+            break;
+            }
+        case (TAtCommandParser::ECmdHandlerTypeBase):
+            {
+            if(iTelError == KErrNone)
+                {
+                if (iReply.Length() == 0)
+                    {
+                    iReply.Append( KCRLF );
+                    iReply.Append( iManufacturer );            
+                    iReply.Append( KCRLF );
+                    }
+              
+                iCallback->CreateReplyAndComplete( EReplyTypeOk, iReply);
+                }
+            else
+                {
+                iCallback->CreateCMEReplyAndComplete(iTelError);
+                }
+            break;
+            }
+        default:
+            {
+            iCallback->CreateReplyAndComplete(EReplyTypeError);
+            break;
+            }
+        }
+      
+    TRACE_FUNC_EXIT
+    }
+
+void CCGMICommandHandler::SetManufacturer(const TDesC8& aManufacturer)
+    {
+    TRACE_FUNC_ENTRY
+    ASSERT( aManufacturer.Length() <= CTelephony::KPhoneModelIdSize );
+    iManufacturer.Zero();
+    iManufacturer.Copy(aManufacturer);
+    TRACE_FUNC_EXIT
+    }
+
+
+void CCGMICommandHandler::SetTelephonyError(TInt aTelError)
+    {
+    TRACE_FUNC_ENTRY
+    iTelError = aTelError;
+    TRACE_FUNC_EXIT
+    }
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/cbsatplugin/atmisccmdplugin/src/cgmmcommandhandler.cpp	Wed Aug 18 09:59:05 2010 +0300
@@ -0,0 +1,137 @@
+/*
+ * Copyright (c) 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"
+ * which accompanies this distribution, and is available
+ * at the URL "http://www.eclipse.org/legal/epl-v10.html".
+ * Initial Contributors:
+ * Nokia Corporation - initial contribution.
+ *
+ * Contributors:
+ * Description :
+ *
+ */
+
+#include "cgmmcommandhandler.h"
+
+#include "atmisccmdpluginconsts.h"
+#include "debug.h"
+
+CCGMMCommandHandler* CCGMMCommandHandler::NewL(MATMiscCmdPlugin* aCallback, TAtCommandParser& aATCmdParser, RMobilePhone& aPhone)
+    {
+    TRACE_FUNC_ENTRY
+    CCGMMCommandHandler* self = new (ELeave) CCGMMCommandHandler(aCallback, aATCmdParser, aPhone);
+    CleanupStack::PushL(self);
+    self->ConstructL();
+    CleanupStack::Pop(self);
+    TRACE_FUNC_EXIT
+    return self;
+    }
+
+CCGMMCommandHandler::CCGMMCommandHandler(MATMiscCmdPlugin* aCallback, TAtCommandParser& aATCmdParser, RMobilePhone& aPhone) :
+    CATCmdSyncBase(aCallback, aATCmdParser, aPhone)
+    {
+    TRACE_FUNC_ENTRY
+    TRACE_FUNC_EXIT
+    }
+
+void CCGMMCommandHandler::ConstructL()
+    {
+    TRACE_FUNC_ENTRY
+    iReply.CreateL(KDefaultCmdBufLength);
+    TRACE_FUNC_EXIT
+    }
+
+CCGMMCommandHandler::~CCGMMCommandHandler()
+    {
+    TRACE_FUNC_ENTRY
+    iReply.Close();
+    TRACE_FUNC_EXIT
+    }
+
+void CCGMMCommandHandler::HandleCommand(const TDesC8& /*aCmd*/, RBuf8& /*aReply*/, TBool /*aReplyNeeded*/)
+    {
+    TRACE_FUNC_ENTRY
+    
+    TAtCommandParser::TCommandHandlerType cmdHandlerType = iATCmdParser.CommandHandlerType();
+    
+    switch (cmdHandlerType)
+        {
+        case (TAtCommandParser::ECmdHandlerTypeTest):
+            {
+            iCallback->CreateReplyAndComplete( EReplyTypeOk );
+            break;
+            }
+        case (TAtCommandParser::ECmdHandlerTypeBase):
+            {
+            if(iTelError == KErrNone)
+                {
+                if (iReply.Length() == 0)
+                    {
+                    _LIT8( KSpace, " " );
+                
+                    iReply.Append( KCRLF );
+                    iReply.Append( iManufacturer );
+                    iReply.Append( KSpace );
+                    iReply.Append( iModel );    
+                    iReply.Append( KCRLF );
+                    }
+              
+                iCallback->CreateReplyAndComplete( EReplyTypeOk, iReply);
+                }
+            else
+                {
+                iCallback->CreateCMEReplyAndComplete(iTelError);
+                }
+            break;
+            }
+        default:
+            {
+            iCallback->CreateReplyAndComplete(EReplyTypeError);
+            break;
+            }
+        }
+      
+    TRACE_FUNC_EXIT
+    }
+
+void CCGMMCommandHandler::SetManufacturer(const TDesC8& aManufacturer)
+    {
+    TRACE_FUNC_ENTRY
+    iManufacturer.Zero();
+    if (aManufacturer.Length() <= CTelephony::KPhoneManufacturerIdSize)
+        {
+        iManufacturer.Copy(aManufacturer);
+        }
+    else
+        {
+        iManufacturer.Copy(aManufacturer.Left(CTelephony::KPhoneManufacturerIdSize));
+        }   
+    TRACE_FUNC_EXIT
+    }
+
+void CCGMMCommandHandler::SetModelID(const TDesC8& aModelID)
+    {
+    TRACE_FUNC_ENTRY
+    iModel.Zero();
+    if (aModelID.Length() <= CTelephony::KPhoneModelIdSize)
+        {
+        iModel.Copy(aModelID);
+        }
+    else
+        {
+        iModel.Copy(aModelID.Left(CTelephony::KPhoneModelIdSize));
+        }    
+    TRACE_FUNC_EXIT
+    }
+
+
+void CCGMMCommandHandler::SetTelephonyError(TInt aTelError)
+    {
+    TRACE_FUNC_ENTRY
+    iTelError = aTelError;
+    TRACE_FUNC_EXIT
+    }
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/cbsatplugin/atmisccmdplugin/src/cgmrcommandhandler.cpp	Wed Aug 18 09:59:05 2010 +0300
@@ -0,0 +1,123 @@
+/*
+ * Copyright (c) 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"
+ * which accompanies this distribution, and is available
+ * at the URL "http://www.eclipse.org/legal/epl-v10.html".
+ * Initial Contributors:
+ * Nokia Corporation - initial contribution.
+ *
+ * Contributors:
+ * Description :
+ *
+ */
+
+#include <sysutil.h>
+
+#include "cgmrcommandhandler.h"
+
+#include "atmisccmdpluginconsts.h"
+#include "debug.h"
+
+CCGMRCommandHandler* CCGMRCommandHandler::NewL(MATMiscCmdPlugin* aCallback, TAtCommandParser& aATCmdParser, RMobilePhone& aPhone)
+    {
+    TRACE_FUNC_ENTRY
+    CCGMRCommandHandler* self = new (ELeave) CCGMRCommandHandler(aCallback, aATCmdParser, aPhone);
+    CleanupStack::PushL(self);
+    self->ConstructL();
+    CleanupStack::Pop(self);
+    TRACE_FUNC_EXIT
+    return self;
+    }
+
+CCGMRCommandHandler::CCGMRCommandHandler(MATMiscCmdPlugin* aCallback, TAtCommandParser& aATCmdParser, RMobilePhone& aPhone) :
+    CATCmdSyncBase(aCallback, aATCmdParser, aPhone)
+    {
+    TRACE_FUNC_ENTRY
+    TRACE_FUNC_EXIT
+    }
+
+void CCGMRCommandHandler::ConstructL()
+    {
+    TRACE_FUNC_ENTRY
+    iReply.CreateL(KDefaultCmdBufLength);
+    TRACE_FUNC_EXIT
+    }
+
+CCGMRCommandHandler::~CCGMRCommandHandler()
+    {
+    TRACE_FUNC_ENTRY
+    iReply.Close();
+    TRACE_FUNC_EXIT
+    }
+
+void CCGMRCommandHandler::HandleCommand(const TDesC8& /*aCmd*/, RBuf8& /*aReply*/, TBool /*aReplyNeeded*/)
+    {
+    TRACE_FUNC_ENTRY
+    
+    TAtCommandParser::TCommandHandlerType cmdHandlerType = iATCmdParser.CommandHandlerType();
+    
+    switch (cmdHandlerType)
+        {
+        case (TAtCommandParser::ECmdHandlerTypeTest):
+            {
+            iCallback->CreateReplyAndComplete( EReplyTypeOk );
+            break;
+            }
+        case (TAtCommandParser::ECmdHandlerTypeBase):
+            {
+            TInt replyType = EReplyTypeOk;
+            if (iReply.Length() == 0)
+                {
+                replyType = GetSoftwareVersion();
+                }
+            
+            if ( (EReplyTypeOk != replyType) )
+                {
+                iCallback->CreateCMEReplyAndComplete(KErrUnknown);
+                }
+            else
+                {
+                iCallback->CreateReplyAndComplete( EReplyTypeOk, iReply);
+                }
+            break;
+            }
+        default:
+            {
+            iCallback->CreateReplyAndComplete(EReplyTypeError);
+            break;
+            }
+        }
+    TRACE_FUNC_EXIT
+    }
+
+TInt CCGMRCommandHandler::GetSoftwareVersion()
+    {
+    TRACE_FUNC_ENTRY
+    iReply.Append( KCRLF );
+
+    // Get software version (e.g. 010.009)
+    TBuf<KSysUtilVersionTextLength> swVersion;   
+    TInt errorCode = SysUtil::GetSWVersion( swVersion );
+
+    if (KErrNone == errorCode)
+        {
+        TLex8 lex(swVersion.Collapse());
+        lex.SkipCharacters();
+        TPtrC8 token = lex.MarkedToken(); 
+        iReply.Append(token);
+        
+        iReply.Append( KCRLF );
+        TRACE_FUNC_EXIT
+        return EReplyTypeOk;
+        }
+    else
+        {
+        TRACE_FUNC_EXIT
+        return EReplyTypeError;
+        }
+    }
+
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/cbsatplugin/atmisccmdplugin/src/cgsncommandhandler.cpp	Wed Aug 18 09:59:05 2010 +0300
@@ -0,0 +1,112 @@
+/*
+ * Copyright (c) 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"
+ * which accompanies this distribution, and is available
+ * at the URL "http://www.eclipse.org/legal/epl-v10.html".
+ * Initial Contributors:
+ * Nokia Corporation - initial contribution.
+ *
+ * Contributors:
+ * Description :
+ *
+ */
+
+#include "cgsncommandhandler.h"
+
+#include "atmisccmdpluginconsts.h"
+#include "debug.h"
+
+CCGSNCommandHandler* CCGSNCommandHandler::NewL(MATMiscCmdPlugin* aCallback, TAtCommandParser& aATCmdParser, RMobilePhone& aPhone)
+    {
+    TRACE_FUNC_ENTRY
+    CCGSNCommandHandler* self = new (ELeave) CCGSNCommandHandler(aCallback, aATCmdParser, aPhone);
+    CleanupStack::PushL(self);
+    self->ConstructL();
+    CleanupStack::Pop(self);
+    TRACE_FUNC_EXIT
+    return self;
+    }
+
+CCGSNCommandHandler::CCGSNCommandHandler(MATMiscCmdPlugin* aCallback, TAtCommandParser& aATCmdParser, RMobilePhone& aPhone) :
+    CATCmdSyncBase(aCallback, aATCmdParser, aPhone)
+    {
+    TRACE_FUNC_ENTRY
+    TRACE_FUNC_EXIT
+    }
+
+void CCGSNCommandHandler::ConstructL()
+    {
+    TRACE_FUNC_ENTRY
+    iTelError = KErrNone;
+    iReply.CreateL(KDefaultCmdBufLength);
+    TRACE_FUNC_EXIT
+    }
+
+CCGSNCommandHandler::~CCGSNCommandHandler()
+    {
+    TRACE_FUNC_ENTRY
+    iReply.Close();
+    TRACE_FUNC_EXIT
+    }
+
+void CCGSNCommandHandler::HandleCommand(const TDesC8& /*aCmd*/, RBuf8& /*aReply*/, TBool /*aReplyNeeded*/)
+    {
+    TRACE_FUNC_ENTRY
+    
+    TAtCommandParser::TCommandHandlerType cmdHandlerType = iATCmdParser.CommandHandlerType();
+    
+    switch (cmdHandlerType)
+        {
+        case (TAtCommandParser::ECmdHandlerTypeTest):
+            {
+            iCallback->CreateReplyAndComplete( EReplyTypeOk );
+            break;
+            }
+        case (TAtCommandParser::ECmdHandlerTypeBase):
+            {
+            if(iTelError == KErrNone)
+                {
+                if (iReply.Length() == 0)
+                    {
+                    iReply.Append( KCRLF );
+                    iReply.Append( iSN );     
+                    iReply.Append( KCRLF );
+                    }
+              
+                iCallback->CreateReplyAndComplete( EReplyTypeOk, iReply);
+                }
+            else
+                {
+                iCallback->CreateCMEReplyAndComplete(iTelError);
+                }
+            break;
+            }
+        default:
+            {
+            iCallback->CreateReplyAndComplete(EReplyTypeError);
+            break;
+            }
+        }
+      
+    TRACE_FUNC_EXIT
+    }
+
+void CCGSNCommandHandler::SetSerialNum(const TDesC8& aSerial)
+    {
+    TRACE_FUNC_ENTRY
+    ASSERT( aSerial.Length() <= CTelephony::KPhoneSerialNumberSize );
+    iSN.Zero();
+    iSN.Copy(aSerial);
+    TRACE_FUNC_EXIT
+    }
+
+void CCGSNCommandHandler::SetTelephonyError(TInt aTelError)
+    {
+    TRACE_FUNC_ENTRY
+    iTelError = aTelError;
+    TRACE_FUNC_EXIT
+    }
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/cbsatplugin/atmisccmdplugin/src/cmgdcommandhandler.cpp	Wed Aug 18 09:59:05 2010 +0300
@@ -0,0 +1,462 @@
+/*
+ * Copyright (c) 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"
+ * which accompanies this distribution, and is available
+ * at the URL "http://www.eclipse.org/legal/epl-v10.html".
+ * Initial Contributors:
+ * Nokia Corporation - initial contribution.
+ *
+ * Contributors:
+ * Description :
+ *
+ */
+
+#include "cmgdcommandhandler.h"
+#include <mmtsy_names.h> 
+#include <mmretrieve.h>
+#include <exterror.h>
+
+#include "atmisccmdpluginconsts.h"
+#include "debug.h"
+
+const TInt KDefaultListLength = 256;
+
+CCMGDCommandHandler* CCMGDCommandHandler::NewL(MATMiscCmdPlugin* aCallback, TAtCommandParser& aATCmdParser, RMobilePhone& aPhone)
+    {
+    TRACE_FUNC_ENTRY
+    CCMGDCommandHandler* self = new (ELeave) CCMGDCommandHandler(aCallback, aATCmdParser, aPhone);
+    CleanupStack::PushL(self);
+    self->ConstructL();
+    CleanupStack::Pop(self);
+    TRACE_FUNC_EXIT
+    return self;
+    }
+
+CCMGDCommandHandler::CCMGDCommandHandler(MATMiscCmdPlugin* aCallback, TAtCommandParser& aATCmdParser, RMobilePhone& aPhone) :
+    CATCmdAsyncBase(aCallback, aATCmdParser, aPhone)
+    {
+    TRACE_FUNC_ENTRY
+
+    TRACE_FUNC_EXIT
+    }
+
+void CCMGDCommandHandler::ConstructL()
+    {
+    TRACE_FUNC_ENTRY
+    
+    iReply.CreateL(KDefaultCmdBufLength);
+    
+    User::LeaveIfError( iMobileSmsMessaging.Open(iPhone) );
+
+    TInt err = iMobileSmsStore.Open(iMobileSmsMessaging, KETelIccSmsStore);
+    if (err != KErrNone)
+        {
+        iHandlerState = ECMGDStateSimStoreNotSupported;
+        }
+    
+    iRetrieveSmsList = CRetrieveMobilePhoneSmsList::NewL(iMobileSmsStore, RMobileSmsStore::KETelMobileGsmSmsEntryV1);
+    
+    TRACE_FUNC_EXIT
+    }
+
+CCMGDCommandHandler::~CCMGDCommandHandler()
+    {
+    TRACE_FUNC_ENTRY
+    Cancel();
+    delete iGsmSmsList;
+    delete iRetrieveSmsList;
+    iMobileSmsStore.Close();
+    iMobileSmsMessaging.Close();
+    iReply.Close();
+    iDeleteList.Close();
+    TRACE_FUNC_EXIT
+    }
+
+void CCMGDCommandHandler::HandleCommand(const TDesC8& /*aCmd*/, RBuf8& /*aReply*/, TBool /*aReplyNeeded*/)
+    {
+    TRACE_FUNC_ENTRY
+    
+    if (iHandlerState == ECMGDStateSimStoreNotSupported)
+        {
+        // Reply "ERROR" if SIM store is not supported
+        iCallback->CreateReplyAndComplete(EReplyTypeError);
+        TRACE_FUNC_EXIT
+        return;
+        }
+    
+    TInt ret = KErrNone;
+    
+    TAtCommandParser::TCommandHandlerType cmdHandlerType = iATCmdParser.CommandHandlerType();
+    
+    switch (cmdHandlerType)
+        {
+        case (TAtCommandParser::ECmdHandlerTypeTest):
+            {
+            iRetrieveSmsList->Start(iStatus);
+            iHandlerState = ECMGDStateRetrieveAllIndices;
+            SetActive();
+            }
+            break;
+        case (TAtCommandParser::ECmdHandlerTypeSet):
+            {
+            ret = ParseParameters();
+            if (ret == KErrNone)
+                {
+                Trace(_L("index = %d"), iIndex);
+                Trace(_L("delflag = %d"), iDelFlag);
+                ret = DoHandleCommand();
+                }
+            else
+                {
+                ret = KErrArgument;
+                }
+            break;
+            }
+        default:
+            {
+            ret = KErrNotSupported;
+            break;
+            }
+        }
+    if (ret == KErrGsmSMSInvalidMemoryIndex)
+        {
+        iCallback->CreateCMSReplyAndComplete(ret);
+        }
+    else if (ret != KErrNone)
+        {
+        iCallback->CreateReplyAndComplete(EReplyTypeError);
+        }
+
+    TRACE_FUNC_EXIT
+    }
+
+void CCMGDCommandHandler::RunL()
+    {
+    TRACE_FUNC_ENTRY
+    
+    Trace(_L("Error = %d"), iStatus.Int());
+    Trace(_L("State = %d"), iHandlerState);
+    
+    iReply.Zero();
+    
+    TInt err = iStatus.Int();
+    if(err == KErrNone)
+        {
+        switch (iHandlerState)
+            {
+            case ECMGDStateRetrieveAllIndices:
+                {
+                GetMessageIndexListL();
+                iDeleteList.Reset();
+                break;
+                }
+            case ECMGDStateDeleteOneEntry:                
+            case ECMGDStateDeleteAllEntries:
+                {
+                // do nothing
+                break;
+                }
+            case ECMGDStateDeleteFilteredEntries:
+                {
+                FilterMessageListL();
+                break;
+                }
+            default:
+                {
+                iHandlerState = ECMGDStateIdle;
+                iCallback->CreateReplyAndComplete(EReplyTypeError);
+                TRACE_FUNC_EXIT
+                return;
+                }
+            }
+        
+        if (iDeleteList.Count() != 0)
+            {
+            // delete the first entry in the list
+            iMobileSmsStore.Delete(iStatus, iDeleteList[0]);
+            iDeleteList.Remove(0);
+            iHandlerState = ECMGDStateDeleteOneEntry;
+            SetActive();                    
+            }
+        else
+            {
+            // deleting finished
+            iCallback->CreateReplyAndComplete(EReplyTypeOk, iReply);
+            }
+        }
+    else if (err == KErrNotFound)
+        {
+        // no message found in SIM
+        switch (iHandlerState)
+            {
+            case ECMGDStateRetrieveAllIndices:
+                {
+                iHandlerState = ECMGDStateIdle;
+                iReply.Format(KCMGDSupportedCmdsList, &KNullDesC8);
+                iCallback->CreateReplyAndComplete(EReplyTypeOk, iReply);
+                break;
+                }
+            case ECMGDStateDeleteFilteredEntries:
+                {
+                iMobileSmsStore.DeleteAll(iStatus);
+                iHandlerState = ECMGDStateDeleteAllEntries;
+                SetActive();
+                break;
+                }
+            default:
+                iHandlerState = ECMGDStateIdle;
+                iCallback->CreateCMSReplyAndComplete(err);
+                break;
+            }
+        }
+    else 
+        {
+        iHandlerState = ECMGDStateIdle;
+        iCallback->CreateCMSReplyAndComplete(err);
+        }
+
+    TRACE_FUNC_EXIT
+    }
+
+TInt CCMGDCommandHandler::RunError(TInt aError)
+    {
+    TRACE_FUNC_ENTRY
+    
+    iCallback->CreateCMSReplyAndComplete(aError);
+    
+    TRACE_FUNC_EXIT
+    return KErrNone;
+    }
+
+void CCMGDCommandHandler::DoCancel() 
+    {
+    TRACE_FUNC_ENTRY
+    
+    switch (iHandlerState)
+        {
+        case ECMGDStateRetrieveAllIndices:
+        case ECMGDStateDeleteFilteredEntries:
+            {
+            iRetrieveSmsList->Cancel();
+            break;
+            }
+        case ECMGDStateDeleteOneEntry:
+            {
+            iMobileSmsStore.CancelAsyncRequest(EMobilePhoneStoreDelete);
+            break;
+            }
+        case ECMGDStateDeleteAllEntries:
+            {
+            iMobileSmsStore.CancelAsyncRequest(EMobilePhoneStoreDeleteAll);
+            break;
+            }
+        }
+
+    TRACE_FUNC_EXIT
+    }
+
+TInt CCMGDCommandHandler::ParseParameters()
+    {
+    TRACE_FUNC_ENTRY
+    
+    TInt ret = KErrNone;
+    TInt index = 0;
+    TInt delflag = 0; // default value
+    TInt otherParams = 0;
+    
+    // get index 
+    TInt retIndex = iATCmdParser.NextIntParam(index);
+    // get delflag
+    TInt retDelflag = iATCmdParser.NextIntParam(delflag);
+    // get other params
+    TInt retOther = iATCmdParser.NextIntParam(otherParams);
+    // Syntax error happens if
+    // a)there is no param2 or param2 error 
+    // b)there is no param1 but param2==0
+    // c)there are too many params
+    TBool noParam = (retIndex!=KErrNone && retDelflag!=KErrNone || retDelflag==KErrGeneral );
+    TBool noParam1 = (retIndex!=KErrNone && retDelflag==KErrNone && delflag==0);
+    TBool tooManyParams = (retOther!=KErrNotFound);
+    
+    if (noParam || noParam1 || tooManyParams)
+        {
+        ret = KErrArgument;
+        }
+    else
+        {
+        iIndex = index;
+        iDelFlag = delflag;
+        }
+
+    TRACE_FUNC_EXIT
+    return ret;
+    }
+
+TInt CCMGDCommandHandler::DoHandleCommand()
+    {
+    TRACE_FUNC_ENTRY
+    
+    TInt err = KErrNone;
+    
+    switch (iDelFlag)
+        {
+        case 0:
+            // deletes the designated message with <index>.
+            {
+            if (iIndex == 0)
+                {
+                // The first position in SIM store is 1,
+                // so zero is not in the supported range.
+                err = KErrGsmSMSInvalidMemoryIndex;
+                }
+            else
+                {
+                iDeleteList.Reset();
+                iMobileSmsStore.Delete(iStatus, iIndex);
+                iHandlerState = ECMGDStateDeleteOneEntry;
+                SetActive();
+                }
+            }
+            break;
+        case 1:
+            // deletes all read message in first-choice memory and reserves unread message, 
+            // sent message and unsent message.
+            {
+            iRetrieveSmsList->Start(iStatus);
+            iHandlerState = ECMGDStateDeleteFilteredEntries;
+            iFilterType = ECMGDFilterReadMessagesOnly;
+            SetActive();
+            }
+            break;
+        case 2:
+            // deletes all read message and sent message in first-choice memory 
+            // and reserves unread message and unsent message.
+            {
+            iRetrieveSmsList->Start(iStatus);
+            iHandlerState = ECMGDStateDeleteFilteredEntries;
+            iFilterType = ECMGDFilterReadAndSentMessages;
+            SetActive();            
+            }
+            break;
+        case 3:
+            // deletes all read message, sent message and unsent message in first-choice memory 
+            // and reserves unread message.
+            {
+            iRetrieveSmsList->Start(iStatus);
+            iHandlerState = ECMGDStateDeleteFilteredEntries;
+            iFilterType = ECMGDFilterReadSentAndUnsentMessages;
+            SetActive();            
+            }
+            break;
+        case 4:
+            // deletes all messages in first-choice memory, including unread message.
+            {
+            iDeleteList.Reset();
+            iMobileSmsStore.DeleteAll(iStatus);
+            iHandlerState = ECMGDStateDeleteAllEntries;
+            SetActive();
+            }
+            break;
+            
+        default:
+            err = KErrNotSupported;
+            break;
+        }
+    
+    TRACE_FUNC_EXIT
+    return err;
+    }
+
+void CCMGDCommandHandler::GetMessageIndexListL()
+    {
+    TRACE_FUNC_ENTRY
+    
+    iReply.Zero();
+    delete iGsmSmsList;
+    iGsmSmsList = NULL;
+    
+    RBuf8 list;
+    list.CreateL(KDefaultListLength);
+    CleanupClosePushL(list);
+
+    iGsmSmsList = iRetrieveSmsList->RetrieveGsmListL();
+    TInt entriesNum = iGsmSmsList->Enumerate();
+    
+    if (entriesNum > 0)
+        {
+        // Append 1st item
+        RMobileSmsStore::TMobileGsmSmsEntryV1 entry;
+        entry = iGsmSmsList->GetEntryL(0);
+        list.AppendNum(entry.iIndex);
+        
+        for (TInt i=1; i<entriesNum; ++i)
+            {
+            entry = iGsmSmsList->GetEntryL(i);
+            list.Append(',');
+            list.AppendNum(entry.iIndex);
+            }
+        }
+    iReply.Format(KCMGDSupportedCmdsList, &list);
+    
+    CleanupStack::PopAndDestroy(&list); //list
+    
+    TRACE_FUNC_EXIT
+    }
+
+/**
+ * Filter message list with iFilterType
+ * ECMGDFilterReadSentAndUnsentMessages: read, sent and unsent messages
+ * ECMGDFilterReadAndSentMessages: read and sent messages
+ * ECMGDFilterReadMessagesOnly: read messages
+ */
+void CCMGDCommandHandler::FilterMessageListL()
+    {
+    TRACE_FUNC_ENTRY
+    
+    delete iGsmSmsList;
+    iGsmSmsList = NULL;
+        
+    iDeleteList.Reset();
+    
+    iGsmSmsList = iRetrieveSmsList->RetrieveGsmListL();
+    TInt entriesNum = iGsmSmsList->Enumerate();
+    
+    for (TInt i=0; i<entriesNum; ++i)
+        {
+        RMobileSmsStore::TMobileGsmSmsEntryV1 entry = iGsmSmsList->GetEntryL(i);
+        switch (iFilterType)
+            {
+            case ECMGDFilterReadSentAndUnsentMessages:
+                {
+                // add unsent message 
+                if (entry.iMsgStatus == RMobileSmsStore::EStoredMessageUnsent)
+                    {
+                    iDeleteList.AppendL(entry.iIndex);
+                    break;
+                    }
+                }
+            case ECMGDFilterReadAndSentMessages:
+                {
+                // add sent message 
+                if (entry.iMsgStatus == RMobileSmsStore::EStoredMessageSent)
+                    {
+                    iDeleteList.AppendL(entry.iIndex);
+                    break;
+                    }
+                }
+            case ECMGDFilterReadMessagesOnly:
+                {
+                // add read message 
+                if (entry.iMsgStatus == RMobileSmsStore::EStoredMessageRead )
+                    {
+                    iDeleteList.AppendL(entry.iIndex);
+                    break;
+                    }
+                }
+            }
+        }
+    
+    TRACE_FUNC_EXIT
+    }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/cbsatplugin/atmisccmdplugin/src/cmgwcommandhandler.cpp	Wed Aug 18 09:59:05 2010 +0300
@@ -0,0 +1,552 @@
+/*
+ * Copyright (c) 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"
+ * which accompanies this distribution, and is available
+ * at the URL "http://www.eclipse.org/legal/epl-v10.html".
+ * Initial Contributors:
+ * Nokia Corporation - initial contribution.
+ *
+ * Contributors:
+ * Description :
+ *
+ */
+
+#include "cmgwcommandhandler.h"
+#include <mmretrieve.h>
+#include <mmlist.h> 
+#include <exterror.h>
+
+#include "atmisccmdpluginconsts.h"
+#include "debug.h"
+
+const TUint KEOT = 26;    // End of Transmission
+const TUint KESC = 27;   // Escape
+
+const TUint8 KSCATonBitMask = 0x70;
+const TUint8 KSCANpiBitMask = 0x0F;
+
+CCMGWCommandHandler* CCMGWCommandHandler::NewL(MATMiscCmdPlugin* aCallback, TAtCommandParser& aATCmdParser, RMobilePhone& aPhone)
+    {
+    TRACE_FUNC_ENTRY
+    CCMGWCommandHandler* self = new (ELeave) CCMGWCommandHandler(aCallback, aATCmdParser, aPhone);
+    CleanupStack::PushL(self);
+    self->ConstructL();
+    CleanupStack::Pop(self);
+    TRACE_FUNC_EXIT
+    return self;
+    }
+
+CCMGWCommandHandler::CCMGWCommandHandler(MATMiscCmdPlugin* aCallback, TAtCommandParser& aATCmdParser, RMobilePhone& aPhone) :
+    CATCmdAsyncBase(aCallback, aATCmdParser, aPhone),
+    iEntryPckg(iEntry)
+    {
+    TRACE_FUNC_ENTRY
+    TRACE_FUNC_EXIT
+    }
+
+void CCMGWCommandHandler::ConstructL()
+    {
+    TRACE_FUNC_ENTRY
+    iReply.CreateL(KDefaultCmdBufLength);
+    iTPDU.CreateL(KDefaultCmdBufLength);
+    
+    User::LeaveIfError( iMobileSmsMessaging.Open(iPhone) );
+
+    TInt err = iMobileSmsStore.Open(iMobileSmsMessaging, KETelIccSmsStore);
+    if (err != KErrNone)
+        {
+        iState = ECMGWStateSimStoreNotSupported;
+        }
+    iRetrieveMobilePhoneSmspList = CRetrieveMobilePhoneSmspList::NewL(iMobileSmsMessaging);
+
+    TRACE_FUNC_EXIT
+    }
+
+CCMGWCommandHandler::~CCMGWCommandHandler()
+    {
+    TRACE_FUNC_ENTRY
+    Cancel();
+    delete iRetrieveMobilePhoneSmspList;
+    delete iMobilePhoneSmspList;
+    iMobileSmsStore.Close();
+    iMobileSmsMessaging.Close();
+    iReply.Close();
+    iTPDU.Close();
+    TRACE_FUNC_EXIT
+    }
+
+/**
+ * Set message format
+ * 0: PDU mode
+ * 1: Text mode - not supported
+ */
+void CCMGWCommandHandler::SetMessageFormat(TInt aFormat)
+    {
+    TRACE_FUNC_ENTRY
+    if (aFormat == 0 || aFormat == 1)
+        {
+        iMsgFormat = aFormat;
+        }
+    Trace(_L("Message format: %d"), iMsgFormat);
+    TRACE_FUNC_ENTRY
+    }
+
+void CCMGWCommandHandler::HandleCommand(const TDesC8& aCmd, RBuf8& /*aReply*/, TBool /*aReplyNeeded*/)
+    {
+    TRACE_FUNC_ENTRY
+    
+    if (iMsgFormat == 1 || iState == ECMGWStateSimStoreNotSupported )
+        {
+        // Reply "ERROR" if text mode is set
+        // Reply "ERROR" if SIM store is not supported
+        iCallback->CreateReplyAndComplete( EReplyTypeError );
+        TRACE_FUNC_EXIT
+        return;
+        }
+    
+    TInt err = KErrNone;
+    
+    TAtCommandParser::TCommandHandlerType cmdHandlerType = iATCmdParser.CommandHandlerType();
+    
+    switch (cmdHandlerType)
+        {
+        case (TAtCommandParser::ECmdHandlerTypeTest):
+            {
+            iCallback->CreateReplyAndComplete( EReplyTypeOk );
+            break;
+            }
+        case (TAtCommandParser::ECmdHandlerTypeSet): 
+            {
+            switch(iState)
+                {
+                case ECMGWStateIdle:
+                    {
+                    // Parse parameters
+                    err = ParseParameters();
+                    if (err == KErrNone)
+                        {
+                        Trace(_L("Parse parameters OK."));
+                        Trace(_L("Length = %d"), iTPDULength);
+                        Trace(_L("stat = %d"), iTPDUStat);
+                        
+                        iTPDU.Zero();
+                        iState = ECMGWStateEditMode;
+                        iCallback->CreateReplyAndComplete( EReplyTypeEditor );
+                        }
+                    else
+                        {
+                        // Syntax error
+                        Trace(_L("Syntax error. err = %d"), err);
+                        iState = ECMGWStateIdle;
+                        iCallback->CreateReplyAndComplete(EReplyTypeError);
+                        }
+                    break;
+                    }
+                case ECMGWStateEditMode:   // Edit state
+                    {
+                    HandleEditModeCommand(aCmd);
+                    break;
+                    }
+                default:    // Other states
+                    {
+                    Cancel();
+                    iCallback->CreateReplyAndComplete( EReplyTypeError );
+                    }
+                }
+            break;
+            }
+        default:
+            {
+            iCallback->CreateReplyAndComplete( EReplyTypeError );
+            break;
+            }
+        }
+    
+    TRACE_FUNC_EXIT
+    }
+
+void CCMGWCommandHandler::HandleEditModeCommand( const TDesC8& aCmd )
+    {
+    TRACE_FUNC_ENTRY
+    
+    TInt err = KErrNone;
+    TUint8 cmdCharVal = 0;
+    if (aCmd.Length())
+        {
+        cmdCharVal = aCmd[0];
+        }
+
+    switch ( cmdCharVal ) 
+        {
+        case KEOT:  // End of Transmission: Now write the message
+            {
+            // Extract SCA fro PDU
+            err = ExtractSCA();
+            if (err == KErrNotFound)
+                {
+                // SCA not provided by client
+                if (iMobileSmspEntry.iServiceCentre.iTelNumber.Length() == 0)
+                    {
+                    // Retrieve SMS parameter list
+                    iRetrieveMobilePhoneSmspList->Start(iStatus);
+                    iState = ECMGWStateRetrieveSCA;
+                    SetActive();
+                    }
+                else
+                    {
+                    // Got the SCA from SIM params already - self complete
+                    iServiceCentre = iMobileSmspEntry.iServiceCentre;
+                    
+                    TRequestStatus* status = &iStatus;
+                    User::RequestComplete(status, KErrNone);
+                    iState = ECMGWStatePreparePDU;
+                    SetActive();
+                    }
+                }
+            else if( err == KErrNone )
+                {
+                // Got the SCA from client (in iService Centre) - self complete
+                TRequestStatus* status = &iStatus;
+                User::RequestComplete(status, KErrNone);
+                iState = ECMGWStatePreparePDU;
+                SetActive();            
+                }
+            else
+                {
+                // Extract SCA failed
+                iState = ECMGWStateIdle;
+                iCallback->CreateCMSReplyAndComplete(KErrGsmSMSInvalidPDUModeParameter);
+                }
+             break;
+            }
+        case KESC:  // Escape
+            {
+            iState = ECMGWStateIdle;
+            iCallback->CreateReplyAndComplete( EReplyTypeOk );
+            break;
+            }
+        default:    // Still entering PDU data
+            {
+            iTPDU.Append( aCmd );
+            iCallback->CreateReplyAndComplete( EReplyTypeEditor );
+            break;
+            }
+        }
+    
+    TRACE_FUNC_EXIT
+    }
+
+void CCMGWCommandHandler::RunL()
+    {
+    TRACE_FUNC_ENTRY
+    
+    iReply.Zero();
+    TInt err = iStatus.Int();
+    Trace(_L("State = %d, err = %d"), iState, err);
+    
+    if (err == KErrNone)
+        {
+        switch (iState)
+            {
+            case ECMGWStateRetrieveSCA:
+                {
+                // Got SCA from SIM params - update iServiceCentre
+                iMobilePhoneSmspList = iRetrieveMobilePhoneSmspList->RetrieveListL();
+                iMobileSmspEntry = iMobilePhoneSmspList->GetEntryL(0);
+                iServiceCentre = iMobileSmspEntry.iServiceCentre;
+                
+                // Complete self to send PDU in next state
+                TRequestStatus* status = &iStatus;
+                User::RequestComplete(status, KErrNone);
+                iState = ECMGWStatePreparePDU;
+                SetActive();
+                }
+                break;
+            case ECMGWStatePreparePDU:
+                {
+                // Create an SMS entry from PDU
+                iEntry.iServiceCentre = iServiceCentre;
+                
+                err = CreateSmsEntry();
+                if (err == KErrNone)
+                    {
+                    Trace(_L("Create SMS entry OK."));
+                    Trace(_L("Service center: %S"),
+                            &iEntry.iServiceCentre.iTelNumber);
+                    Trace(_L("Type of number: %d"),
+                            iEntry.iServiceCentre.iTypeOfNumber);
+                    Trace(_L("Number plan: %d"),
+                            iEntry.iServiceCentre.iNumberPlan);
+                    Trace(_L("Message status: %d"), iEntry.iMsgStatus);
+
+                    // Start to write PDU
+                    iEntry.iIndex = -1;
+                    iMobileSmsStore.Write(iStatus, iEntryPckg);
+                    iState = ECMGWStateWritePDU;
+                    SetActive();
+                    }
+                else
+                    {
+                    // Create failed
+                    iState = ECMGWStateIdle;
+                    iCallback->CreateCMSReplyAndComplete(KErrGsmSMSInvalidPDUModeParameter);
+                    }                
+                break;
+                }
+            case ECMGWStateWritePDU:
+                {
+                Trace(_L("Write successful. Index = %d"), iEntry.iIndex);
+                
+                iReply.Append(KCRLF);
+                iReply.Append(KAtCMGW);
+                iReply.AppendNum(iEntry.iIndex);
+                iState = ECMGWStateIdle;
+                iCallback->CreateReplyAndComplete(EReplyTypeOk, iReply);
+                }
+                break;
+            default:
+                iState = ECMGWStateIdle;
+                iCallback->CreateReplyAndComplete(EReplyTypeError);
+                break;
+            }
+        }
+    else
+        {
+        iState = ECMGWStateIdle;
+        iCallback->CreateCMSReplyAndComplete(err);
+        }
+    
+    TRACE_FUNC_EXIT
+    }
+
+TInt CCMGWCommandHandler::RunError(TInt aError)
+    {
+    TRACE_FUNC_ENTRY
+    
+    delete iMobilePhoneSmspList;
+    iMobilePhoneSmspList = NULL;
+    iState = ECMGWStateIdle;
+    iCallback->CreateCMSReplyAndComplete(aError);
+    
+    TRACE_FUNC_EXIT
+    return KErrNone;
+    }
+
+void CCMGWCommandHandler::DoCancel() 
+    {
+    TRACE_FUNC_ENTRY
+    
+    switch (iState)
+        {
+        case ECMGWStateRetrieveSCA:
+            {
+            iRetrieveMobilePhoneSmspList->Cancel();
+            break;
+            }
+        case ECMGWStateWritePDU:
+            {
+            iMobileSmsStore.CancelAsyncRequest(EMobilePhoneStoreWrite);
+            break;
+            }
+        }
+    iState = ECMGWStateIdle;
+    
+    TRACE_FUNC_EXIT
+    }
+/**
+ * Parse parameters of +CMGW=<length>,<stat>
+ */
+TInt CCMGWCommandHandler::ParseParameters()
+    {
+    TRACE_FUNC_ENTRY
+    
+    TInt ret = KErrNone;
+    iTPDULength = 0;
+    iTPDUStat = 0; // default value
+    TInt otherParams = 0;
+    // Get length
+    TInt retLength = iATCmdParser.NextIntParam(iTPDULength);
+    // Get status
+    TInt retStat = iATCmdParser.NextIntParam(iTPDUStat);
+    // Get other parameters
+    TInt retOther = iATCmdParser.NextIntParam(otherParams);
+    // syntax error happens if
+    // a)there is no param 1
+    // b)there are 3 params
+    // c)param 2 is not 0,1,2 or 3
+    TBool noParam1 = (retLength != KErrNone);
+    TBool badParam2 = (retStat == KErrGeneral);
+    TBool tooManyParams = (retOther != KErrNotFound);
+    
+    if (noParam1 || badParam2 || tooManyParams)
+        {
+        ret = KErrArgument;
+        }
+    else
+        {
+        switch (iTPDUStat)
+            {
+            case 0:
+                // to receive unread message
+                iMessageStatus = RMobileSmsStore::EStoredMessageUnread;
+                break;
+            case 1:
+                // to receive read message
+                iMessageStatus = RMobileSmsStore::EStoredMessageRead;
+                break;
+            case 2:
+                // Unsent is not supported in this version
+                ret = KErrNotSupported;
+                break;
+            case 3:
+                // Sent is not supported in this version
+                ret = KErrNotSupported;
+                break;
+            default:
+                ret = KErrArgument;
+                break;
+            }
+        iEntry.iMsgStatus = iMessageStatus;
+        }
+    
+    TRACE_FUNC_EXIT
+    return ret;
+    }
+
+/**
+ * Create an SMS entry from the PDU string
+ */
+TInt CCMGWCommandHandler::CreateSmsEntry()
+    {
+    TRACE_FUNC_ENTRY
+    
+    TInt err = KErrNone;
+    
+    // Check the length
+    if (iTPDU.Length() != (iSCALength+iTPDULength+1)*2)
+        {
+        TRACE_FUNC_EXIT
+        return KErrArgument;
+        }
+    
+    RBuf8 buf;
+    err = buf.Create(iTPDULength);
+    if (err != KErrNone)
+        {
+        TRACE_FUNC_EXIT
+        return err;
+        }
+    // Convert to binary format
+    for(TInt i=(iSCALength+1)*2; i< iTPDU.Length(); i+=2)
+        {
+        TLex8 lex(iTPDU.Mid(i, 2));
+        TUint8 val = 0;
+        err = lex.Val(val, EHex);
+        if (err != KErrNone)
+            {
+            buf.Close();
+            TRACE_FUNC_EXIT
+            return err;
+            }
+        buf.Append(val);
+        }
+    iEntry.iMsgData.Copy(buf);
+    
+    buf.Close();
+    TRACE_FUNC_EXIT
+    return KErrNone;
+    }
+
+/**
+ * Extract the SMS service center address from the head of PDU string
+ */
+TInt CCMGWCommandHandler::ExtractSCA()
+    {
+    TRACE_FUNC_ENTRY
+    
+    TInt err = KErrNone;
+    TLex8 lex;
+    RMobilePhone::TMobileAddress sca;
+    // SCA length
+    lex.Assign(iTPDU.Left(2));
+    err = lex.Val(iSCALength, EHex); 
+    if (err != KErrNone)
+        {
+        TRACE_FUNC_EXIT
+        return err;
+        }
+    TInt length = iTPDU.Length();
+    if (iSCALength == 0)
+        {
+        // Service center is not found in PDU
+        err = KErrNotFound;
+        }
+    else if (iSCALength > (length-2)/2)
+        {
+        // Service certer length error
+        err = KErrArgument;
+        }
+    else
+        {
+        // SCA is given
+        // Parse SCA TON and NPI
+        TUint8 val = 0;
+        lex.Assign(iTPDU.Mid(2,2));
+        err = lex.Val(val, EHex);
+        if (err != KErrNone)
+            {
+            TRACE_FUNC_EXIT
+            return err;
+            }
+        TUint8 ton = (val&KSCATonBitMask)>>4;
+        TUint8 npi = val&KSCANpiBitMask;
+        switch (ton) // TON
+            {
+            case 0: // 000
+                sca.iTypeOfNumber = RMobilePhone::EUnknownNumber;
+                break;
+            case 1: // 001
+                sca.iTypeOfNumber = RMobilePhone::EInternationalNumber;
+                sca.iTelNumber.Append('+');
+                break;
+            case 2: // 010
+                sca.iTypeOfNumber = RMobilePhone::ENationalNumber;
+                break;
+            default: 
+                // CMCC doesn't support other types
+                TRACE_FUNC_EXIT
+                return KErrArgument;
+            }
+        switch (npi) // NPI
+            {
+            case 0: // 0000
+                sca.iNumberPlan = RMobilePhone::EUnknownNumberingPlan;
+                break;
+            case 1: // 0001
+                sca.iNumberPlan = RMobilePhone::EIsdnNumberPlan;
+                break;
+            default:
+                // CMCC doesn't support other number plans
+                TRACE_FUNC_EXIT
+                return KErrArgument;
+            }
+        // Extract SCA number
+        for (TInt i=4; i<(iSCALength+1)*2; i+=2)
+            {
+            sca.iTelNumber.Append(iTPDU[i+1]);
+            sca.iTelNumber.Append(iTPDU[i]);
+            }
+        if(sca.iTelNumber[sca.iTelNumber.Length()-1] == 'F' 
+                || sca.iTelNumber[sca.iTelNumber.Length()-1] == 'f')
+            {
+            sca.iTelNumber.Delete(sca.iTelNumber.Length()-1, 1);
+            }
+        iServiceCentre = sca;
+        }
+    TRACE_FUNC_EXIT
+    return err;
+    }
+
+
--- a/cbsatplugin/atmisccmdplugin/src/cpincommandhandler.cpp	Tue Jul 06 14:27:09 2010 +0300
+++ b/cbsatplugin/atmisccmdplugin/src/cpincommandhandler.cpp	Wed Aug 18 09:59:05 2010 +0300
@@ -18,7 +18,7 @@
 #include "cpincommandhandler.h"
 
 #include <mmretrieve.h>         // define AO wrapper
-#include <EXTERROR.H>           // Additional RMobilePhone error code
+#include <exterror.h>           // Additional RMobilePhone error code
 
 #include "debug.h"
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/cbsatplugin/atmisccmdplugin/src/hvercommandhandler.cpp	Wed Aug 18 09:59:05 2010 +0300
@@ -0,0 +1,151 @@
+/*
+ * Copyright (c) 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"
+ * which accompanies this distribution, and is available
+ * at the URL "http://www.eclipse.org/legal/epl-v10.html".
+ * Initial Contributors:
+ * Nokia Corporation - initial contribution.
+ *
+ * Contributors:
+ * Description :
+ *
+ */
+
+#include "hvercommandhandler.h"
+#include <sysutil.h>
+
+#include "atmisccmdpluginconsts.h"
+#include "debug.h"
+
+const TUint KCommaValue = 44;
+const TUint KSpaceValue = 32;
+
+CHVERCommandHandler* CHVERCommandHandler::NewL(MATMiscCmdPlugin* aCallback, TAtCommandParser& aATCmdParser, RMobilePhone& aPhone)
+    {
+    TRACE_FUNC_ENTRY
+    CHVERCommandHandler* self = new (ELeave) CHVERCommandHandler(aCallback, aATCmdParser, aPhone);
+    CleanupStack::PushL(self);
+    self->ConstructL();
+    CleanupStack::Pop(self);
+    TRACE_FUNC_EXIT
+    return self;
+    }
+
+CHVERCommandHandler::CHVERCommandHandler(MATMiscCmdPlugin* aCallback, TAtCommandParser& aATCmdParser, RMobilePhone& aPhone) :
+    CATCmdSyncBase(aCallback, aATCmdParser, aPhone)
+    {
+    TRACE_FUNC_ENTRY
+    TRACE_FUNC_EXIT
+    }
+
+void CHVERCommandHandler::ConstructL()
+    {
+    TRACE_FUNC_ENTRY
+    iTelError = KErrNone;
+    iSWVersion.CreateL(KSysUtilVersionTextLength);
+    iReply.CreateL(KDefaultCmdBufLength);
+    TRACE_FUNC_EXIT
+    }
+
+CHVERCommandHandler::~CHVERCommandHandler()
+    {
+    TRACE_FUNC_ENTRY
+    iSWVersion.Close();
+    iReply.Close();
+    TRACE_FUNC_EXIT
+    }
+
+void CHVERCommandHandler::HandleCommand(const TDesC8& /*aCmd*/, RBuf8& /*aReply*/, TBool /*aReplyNeeded*/)
+    {
+    TRACE_FUNC_ENTRY
+    
+    TAtCommandParser::TCommandHandlerType cmdHandlerType = iATCmdParser.CommandHandlerType();
+    
+    if (cmdHandlerType != TAtCommandParser::ECmdHandlerTypeBase)
+        {
+        iCallback->CreateReplyAndComplete(EReplyTypeError);
+        }
+    else if(iTelError == KErrNone)
+        {
+        if (iReply.Length() == 0)
+            {
+            // Get model
+            iReply.Append( KCRLF );
+            iReply.Append( iModel );
+    
+            TChar commaValue = KCommaValue;
+            TChar spaceValue = KSpaceValue;            
+            iReply.Append( commaValue );
+            iReply.Append( spaceValue );
+            
+            // Get software version (RM-xxx)
+            TBuf<KSysUtilVersionTextLength> swVersion;
+            TInt errorCode = SysUtil::GetSWVersion( swVersion );
+    
+            if (KErrNone == errorCode)
+                {
+                ParseSWVersion(swVersion.Collapse());
+                iReply.Append(iSWVersion);
+                }
+            iReply.Append( KCRLF );
+            }
+        iCallback->CreateReplyAndComplete( EReplyTypeOk, iReply);
+        }
+    else
+        {
+        iCallback->CreateCMEReplyAndComplete(iTelError);
+        }
+   
+    TRACE_FUNC_EXIT
+    }
+
+void CHVERCommandHandler::ParseSWVersion(const TDesC8& aSWVersion)
+    {  
+    TRACE_FUNC_ENTRY
+    if (iSWVersion.Length() != 0)
+        {
+        TRACE_FUNC_EXIT
+        return;
+        }
+    
+    TInt start = aSWVersion.Find(KHVERModelString);
+    
+    if ( KErrNotFound != start )
+        {
+        TLex8 lex(aSWVersion);
+        lex.Inc(start);
+        lex.Mark(); 
+        lex.SkipCharacters();
+        TPtrC8 token = lex.MarkedToken(); 
+    
+        iSWVersion.Append(token);
+        }
+    TRACE_FUNC_EXIT
+    }
+
+void CHVERCommandHandler::SetHWVersion(const TDesC8& aHWVersion)
+    {
+    TRACE_FUNC_ENTRY
+    iModel.Zero();
+    if (aHWVersion.Length() <= CTelephony::KPhoneModelIdSize)
+        {
+        iModel.Copy(aHWVersion);
+        }
+    else
+        {
+        iModel.Copy(aHWVersion.Left(CTelephony::KPhoneModelIdSize));
+        }    
+    TRACE_FUNC_EXIT
+    }
+
+
+
+void CHVERCommandHandler::SetTelephonyError(TInt aTelError)
+    {
+    TRACE_FUNC_ENTRY
+    iTelError = aTelError;
+    TRACE_FUNC_EXIT
+    }
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/cbsatplugin/atmisccmdplugin/src/scpbrcommandhandler.cpp	Wed Aug 18 09:59:05 2010 +0300
@@ -0,0 +1,451 @@
+/*
+ * Copyright (c) 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"
+ * which accompanies this distribution, and is available
+ * at the URL "http://www.eclipse.org/legal/epl-v10.html".
+ * Initial Contributors:
+ * Nokia Corporation - initial contribution.
+ *
+ * Contributors:
+ * Description :
+ *
+ */
+
+#include "scpbrcommandhandler.h"
+
+#include <mpbutil.h>
+#include "debug.h"
+#include "atmisccmdpluginconsts.h"
+
+CSCPBRCommandHandler::CSCPBRCommandHandler( 
+		MATMiscCmdPlugin* aCallback, 
+		TAtCommandParser& aATCmdParser, 
+		RMobilePhone& aPhone) 
+		: CATCmdAsyncBase( aCallback, aATCmdParser, aPhone )
+	{
+    TRACE_FUNC_ENTRY
+    TRACE_FUNC_EXIT
+	}
+
+CSCPBRCommandHandler::~CSCPBRCommandHandler()
+	{
+    TRACE_FUNC_ENTRY
+    Cancel();
+    iPhoneBookStore.Close();
+    iCustomApi.Close();
+    iReply.Close();
+    delete iPhoneBookBuffer;
+    iEntries.Close();
+    iContactsBuf.Close();
+    TRACE_FUNC_EXIT
+	}
+
+void CSCPBRCommandHandler::ConstructL()
+	{
+    TRACE_FUNC_ENTRY
+    TInt err = iPhoneBookStore.Open( iPhone, KETelIccAdnPhoneBook);
+    if( err != KErrNone )  // if the phonebookstore can't be opened or error occurs when try to open it.
+        {
+        iState = ESCPBRStateNotSupported;
+        TRACE_FUNC_EXIT
+        return;
+        }
+    err = iCustomApi.Open( iPhone );
+    if( err != KErrNone )  // If the custom api can't be opened.
+        {
+        iPhoneBookStore.Close();
+        iState = ESCPBRStateNotSupported;
+        TRACE_FUNC_EXIT
+        return;
+        }
+    iReply.CreateL( KBufBlockSize );
+	iPhoneBookBuffer = new ( ELeave ) CPhoneBookBuffer();	
+    TRACE_FUNC_EXIT
+	}
+
+CSCPBRCommandHandler* CSCPBRCommandHandler::NewL( 
+		MATMiscCmdPlugin* aCallback, 
+		TAtCommandParser& aATCmdParser, 
+		RMobilePhone& aPhone )
+	{
+    TRACE_FUNC_ENTRY
+	CSCPBRCommandHandler * self = new ( ELeave ) CSCPBRCommandHandler( aCallback, aATCmdParser, aPhone );
+	CleanupStack::PushL( self );
+	self->ConstructL();
+	CleanupStack::Pop( self );
+    TRACE_FUNC_EXIT
+	return self;
+	}
+
+void CSCPBRCommandHandler::HandleCommand(const TDesC8& /*aCmd*/, RBuf8& /*aReply*/, TBool /*aReplyNeeded*/ )
+	{
+    TRACE_FUNC_ENTRY
+    if( iState == ESCPBRStateIdle )  // Not supported or have unfinished task.
+        {
+        iReply.Zero();  
+        TAtCommandParser::TCommandHandlerType cmdHandlerType = iATCmdParser.CommandHandlerType();
+        switch( cmdHandlerType )
+            {
+            case TAtCommandParser::ECmdHandlerTypeTest: // command: AT^SCPBR=?
+                {
+                if( iTotalEntries == 0 )
+                    {
+                    iState = ESCPBRStateGetPhoneBookInfo;
+                    RMobilePhoneBookStore::TMobilePhoneBookInfoV1Pckg pkg( iPhoneBookInfo );
+                    iPhoneBookStore.GetInfo( iStatus, pkg );
+                    SetActive();
+                    }
+                else if ( iMLength ==0 )
+                    {
+                    iState = ESCPBRStateGet3GPBInfo;
+                    iCustomApi.Get3GPBInfo( iStatus, i3GPBInfo );
+                    SetActive();
+                    }
+                else
+                    {
+                    iReply.Format( KSCPBRSupportedEntriesIndexList, 
+                            iTotalEntries, iNLength, iTLength, iMLength );
+                    iCallback->CreateReplyAndComplete( EReplyTypeOk, iReply );
+                    }
+                break;
+                }
+            case TAtCommandParser::ECmdHandlerTypeSet:  // command: AT^SCPBR=<index1>[,<index2>]
+                {
+                if( ParseParameters() == KErrNone )
+                    {
+                    iEntries.Reset();
+                    TInt amountOfEntries = iIndex2 - iIndex1 + 1;  // the amount of entries.
+                    Trace( _L8("The amount of entries: %d "), amountOfEntries );
+                    iContactsBuf.Zero();
+                    TInt bufSize;
+                    if( amountOfEntries >= KSCPBRMaxEntryCount )
+                        {
+                        bufSize= KSCPBRMaxEntryCount * KSCPBRDefaultSizeOfOneEntry;
+                        amountOfEntries = KSCPBRMaxEntryCount;
+                        }
+                    else
+                        {
+                        bufSize = amountOfEntries * KSCPBRDefaultSizeOfOneEntry;
+                        }
+                    
+                    if( bufSize >= iContactsBuf.MaxLength() )
+                        {
+                        TInt err = iContactsBuf.ReAlloc( bufSize );
+                        Trace( _L8("The error code of the realloc: %d "), err );
+                        if( err != KErrNone )
+                            {
+                            iState = ESCPBRStateIdle;
+                            iCallback->CreateReplyAndComplete( EReplyTypeError );
+                            break;
+                            }
+                        }
+                    iState = ESCPBRStateRead;
+                    iPhoneBookStore.Read( iStatus,  iIndex1, amountOfEntries, iContactsBuf );
+                    SetActive();
+                    }
+                else
+                    {
+                    iCallback->CreateReplyAndComplete( EReplyTypeError );
+                    }
+                break;
+                }
+            default:
+                {
+                iCallback->CreateReplyAndComplete( EReplyTypeError );
+                break;
+                }
+            }
+        }
+    else
+        {
+        iCallback->CreateReplyAndComplete( EReplyTypeError );
+        } 
+       TRACE_FUNC_EXIT
+	}
+
+TInt CSCPBRCommandHandler::ParseParameters()
+    {
+    TRACE_FUNC_ENTRY
+    iIndex1 = 0; 
+    iIndex2 = 0;
+    TInt index3;
+    TInt ret1 = iATCmdParser.NextIntParam( iIndex1 );
+    TInt ret2 = iATCmdParser.NextIntParam( iIndex2 );
+    TInt ret3 = iATCmdParser.NextIntParam( index3 );
+    
+    if( ret1 != KErrNone 
+            || ( ret2 != KErrNone && ret2 != KErrNotFound )
+            || ret3 != KErrNotFound )
+        {
+        TRACE_FUNC_EXIT
+        return KErrArgument;
+        }
+    if( ret2 == KErrNotFound )
+        {
+        iIndex2 = iIndex1;
+        }
+    if (iIndex2 < iIndex1)
+        {
+        TRACE_FUNC_EXIT
+        return KErrArgument;
+        }
+    TRACE_FUNC_EXIT
+    return KErrNone;
+    }
+
+void CSCPBRCommandHandler::RunL()
+	{
+    TRACE_FUNC_ENTRY
+    iReply.Zero();
+    TInt result = iStatus.Int();
+    if( result == KErrNone )
+        {
+        switch( iState )
+            {
+            case ESCPBRStateRead:
+                {
+                ExtractEntriesL();
+                FormatReplyL();
+                iState = ESCPBRStateIdle;
+                iCallback->CreateReplyAndComplete(EReplyTypeOk, iReply);
+                break;
+                }
+            case ESCPBRStateGetPhoneBookInfo:
+                {
+                iTotalEntries = iPhoneBookInfo.iTotalEntries;
+                iNLength = iPhoneBookInfo.iMaxNumLength;
+                iTLength = iPhoneBookInfo.iMaxTextLength;
+                if (iMLength == 0)
+                    {
+                    iState = ESCPBRStateGet3GPBInfo;
+                    iCustomApi.Get3GPBInfo( iStatus, i3GPBInfo );
+                    SetActive();
+                    }
+                else 
+                    {
+                    iReply.Format( KSCPBRSupportedEntriesIndexList, 
+                            iTotalEntries, iNLength, iTLength, iMLength );
+                    iState = ESCPBRStateIdle;
+                    iCallback->CreateReplyAndComplete( EReplyTypeOk, iReply );
+                    }
+                break;
+                }
+            case ESCPBRStateGet3GPBInfo:
+                {
+                iMLength = i3GPBInfo.iMaxLenEmail;
+                iReply.Format( KSCPBRSupportedEntriesIndexList, 
+                        iTotalEntries, iNLength, iTLength, iMLength );
+                iState = ESCPBRStateIdle;
+                iCallback->CreateReplyAndComplete( EReplyTypeOk, iReply );
+                break;
+                }
+            default: 
+                {
+                iState = ESCPBRStateIdle;
+                iCallback->CreateReplyAndComplete( EReplyTypeError );
+                break;
+                }
+            }
+        }
+    else
+        {
+        iState = ESCPBRStateIdle;
+        iCallback->CreateCMEReplyAndComplete( result );
+        }
+    TRACE_FUNC_EXIT
+	}
+
+TInt CSCPBRCommandHandler::RunError(TInt aError)
+    {
+    TRACE_FUNC_ENTRY
+    iState = ESCPBRStateIdle;
+    iCallback->CreateReplyAndComplete( EReplyTypeError );
+    TRACE_FUNC_EXIT
+    return KErrNone;
+    }
+
+void CSCPBRCommandHandler::ExtractEntriesL()
+    {
+    TRACE_FUNC_ENTRY
+    iPhoneBookBuffer->Set( &iContactsBuf );
+    iPhoneBookBuffer->StartRead();
+    TUint8 fieldTag;
+    CPhoneBookBuffer::TPhBkTagType dataType;
+    TInt numCount = 0;
+	// clear entry arry for use.
+    iEntries.Reset();
+    User::LeaveIfError(iPhoneBookBuffer->GetTagAndType( fieldTag, dataType ));
+    if( fieldTag != RMobilePhoneBookStore::ETagPBNewEntry )
+        {
+        // Buffer corrupt
+        User::Leave(KErrCorrupt);
+        }
+    TInt ret = KErrNone;
+    TInt index = -1; // at least one entry
+    while (ret != KErrNotFound) // if reach the buffer end.
+        {
+        switch (fieldTag)
+            {
+            case RMobilePhoneBookStore::ETagPBNewEntry:
+                {
+                TPhoneBookEntry entry;
+                iEntries.AppendL(entry);
+                ++index;
+                numCount = 0; // set the number count of new entry to 0. 
+                break;
+                }
+            case RMobilePhoneBookStore::ETagPBAdnIndex:
+                {
+                TUint16 simIndex = 0;
+                if (dataType != CPhoneBookBuffer::EPhBkTypeInt16)
+                    {
+                    User::Leave(KErrCorrupt);
+                    }
+                User::LeaveIfError( iPhoneBookBuffer->GetValue(simIndex) );
+
+                iEntries[index].iIndex = simIndex;
+                break;
+                }
+            case RMobilePhoneBookStore::ETagPBText:
+                {
+                TPtrC16 text;
+                if (dataType != CPhoneBookBuffer::EPhBkTypeDes16)
+                    {
+                    User::Leave(KErrCorrupt);
+                    }
+                User::LeaveIfError( iPhoneBookBuffer->GetValue(text) );
+                CopyToPhonebookEntryField(iEntries[index].iName, text);
+                break;
+                }
+            case RMobilePhoneBookStore::ETagPBNumber:
+                {
+                TPtrC16 number;
+                if (dataType != CPhoneBookBuffer::EPhBkTypeDes16)
+                    {
+                    User::Leave(KErrCorrupt);
+                    }
+                User::LeaveIfError( iPhoneBookBuffer->GetValue(number) );
+                ++numCount;
+                switch (numCount)
+                    {
+                    case 1: // The first number
+                        CopyToPhonebookEntryField(iEntries[index].iNumber1, number);
+                        break;
+                    case 2: // The Second number
+                        CopyToPhonebookEntryField(iEntries[index].iNumber2, number);
+                        break;
+                    case 3: // the Third number
+                        CopyToPhonebookEntryField(iEntries[index].iNumber3, number);
+                        break;
+                    case 4: // the fourth number.
+                        CopyToPhonebookEntryField(iEntries[index].iNumber4, number);
+                        break;
+                    }
+                break;
+                }
+            case RMobilePhoneBookStore::ETagPBEmailAddress:
+                {
+                TPtrC16 email;
+                if (dataType != CPhoneBookBuffer::EPhBkTypeDes16)
+                    {
+                    User::Leave(KErrCorrupt);
+                    }
+                User::LeaveIfError( iPhoneBookBuffer->GetValue(email) );
+                CopyToPhonebookEntryField(iEntries[index].iEmail, email);
+                break;
+                }
+            default:
+                {
+                iPhoneBookBuffer->SkipValue(dataType);
+                break;
+                }
+            }
+        ret = iPhoneBookBuffer->GetTagAndType(fieldTag, dataType);
+        }
+ 
+    TRACE_FUNC_EXIT
+    }
+
+void CSCPBRCommandHandler::CopyToPhonebookEntryField(TDes8& aDest, const TDesC16& aSrc)
+    {
+    TRACE_FUNC_ENTRY
+    TInt maxLength = aDest.MaxLength();
+    if ( aSrc.Length() <= maxLength )
+        {
+        aDest.Copy(aSrc);
+        }
+    else
+        {
+        aDest.Copy( aSrc.Left(maxLength) );
+        }
+    TRACE_FUNC_EXIT    
+    }
+
+void CSCPBRCommandHandler::FormatReplyL()
+    {
+    TRACE_FUNC_ENTRY
+
+    TInt count = iEntries.Count();
+    for (TInt i = 0; i < count; ++i)
+        {
+        AppendEntryL(iEntries[i]);
+        }
+
+    TRACE_FUNC_EXIT
+    }
+
+void CSCPBRCommandHandler::AppendEntryL(const TPhoneBookEntry& aEntry)
+    {
+    TRACE_FUNC_ENTRY
+    TBuf8<KSCPBRDefaultSizeOfOneEntry> entryBuffer;
+    aEntry.Externalize(entryBuffer);
+    
+    TInt length = entryBuffer.Length() + KSCPBR().Length(); 
+    if (length + iReply.Length() > iReply.MaxLength())
+        {
+        iReply.ReAllocL(iReply.MaxLength()+KBufBlockSize);
+        }
+    
+    iReply.Append(KSCPBR);
+    iReply.Append(entryBuffer);
+    TRACE_FUNC_EXIT
+    }
+
+void CSCPBRCommandHandler::DoCancel()
+	{
+    TRACE_FUNC_ENTRY
+    switch( iState )
+        {
+        case ESCPBRStateRead:
+            {
+            iPhoneBookStore.CancelAsyncRequest( EMobilePhoneStoreRead );
+            break;
+            }
+        case ESCPBRStateGetPhoneBookInfo:
+            {
+            iPhoneBookStore.CancelAsyncRequest( EMobilePhoneStoreGetInfo );
+            break;
+            }
+        case ESCPBRStateGet3GPBInfo:
+            {
+            iPhoneBookStore.CancelAsyncRequest( EGet3GPBInfoIPC );
+            break;
+            }
+        default:
+            break;
+        }
+    iState = ESCPBRStateIdle;
+    TRACE_FUNC_EXIT
+	}
+
+
+void CSCPBRCommandHandler::TPhoneBookEntry::Externalize(TDes8& aDes) const
+    {
+    TRACE_FUNC_ENTRY
+    
+    aDes.Format(KSCPBRReplyOneEntry, iIndex, &iNumber1, &iNumber2, &iNumber3, &iNumber4, &iName, &iEmail);
+    
+    TRACE_FUNC_EXIT
+    }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/cbsatplugin/atmisccmdplugin/src/scpbwcommandhandler.cpp	Wed Aug 18 09:59:05 2010 +0300
@@ -0,0 +1,616 @@
+/*
+ * Copyright (c) 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"
+ * which accompanies this distribution, and is available
+ * at the URL "http://www.eclipse.org/legal/epl-v10.html".
+ * Initial Contributors:
+ * Nokia Corporation - initial contribution.
+ *
+ * Contributors:
+ * Description :
+ *
+ */
+
+#include "scpbwcommandhandler.h"
+#include <mpbutil.h> 
+#include <exterror.h>
+#include <etelmmerr.h>
+
+#include "atmisccmdpluginconsts.h"
+#include "debug.h"
+
+const TInt KMaxContactEntrySize = 512;
+const TInt KMaxTextLength = 64;
+const TInt KMaxNumberLength = 64;
+const TInt KMaxEmailLength = 64;
+
+CSCPBWCommandHandler* CSCPBWCommandHandler::NewL(MATMiscCmdPlugin* aCallback, TAtCommandParser& aATCmdParser, RMobilePhone& aPhone)
+    {
+    TRACE_FUNC_ENTRY
+    CSCPBWCommandHandler* self = new (ELeave) CSCPBWCommandHandler(aCallback, aATCmdParser, aPhone);
+    CleanupStack::PushL(self);
+    self->ConstructL();
+    CleanupStack::Pop(self);
+    TRACE_FUNC_EXIT
+    return self;
+    }
+
+CSCPBWCommandHandler::CSCPBWCommandHandler(MATMiscCmdPlugin* aCallback, TAtCommandParser& aATCmdParser, RMobilePhone& aPhone) :
+    CATCmdAsyncBase(aCallback, aATCmdParser, aPhone)
+    {
+    TRACE_FUNC_ENTRY
+    TRACE_FUNC_EXIT
+    }
+
+void CSCPBWCommandHandler::ConstructL()
+    {
+    TRACE_FUNC_ENTRY
+    
+    TInt err = iPhoneBookStore.Open(iPhone, KETelIccAdnPhoneBook);
+    if (err != KErrNone)
+        {
+        iState = ESCPBWStateSimStoreNotSupported;
+        TRACE_FUNC_EXIT
+        return;
+        }
+    err = iMmCustomAPI.Open(iPhone);
+    if (err != KErrNone)
+        {
+        iPhoneBookStore.Close();
+        iState = ESCPBWStateSimStoreNotSupported;
+        TRACE_FUNC_EXIT
+        return;
+        }
+    iPhoneBookBuffer = new (ELeave) CPhoneBookBuffer;
+    
+    iReply.CreateL(KDefaultCmdBufLength);
+    iNum1.CreateL(KMaxNumberLength);
+    iNum2.CreateL(KMaxNumberLength);
+    iNum3.CreateL(KMaxNumberLength);
+    iNum4.CreateL(KMaxNumberLength);
+    iText.CreateL(KMaxTextLength);
+    iEmail.CreateL(KMaxEmailLength);
+    iPbData.CreateL(KMaxContactEntrySize);
+    
+    TRACE_FUNC_EXIT
+    }
+
+CSCPBWCommandHandler::~CSCPBWCommandHandler()
+    {
+    TRACE_FUNC_ENTRY
+    Cancel();
+    delete iPhoneBookBuffer;
+    iPhoneBookStore.Close();
+    iMmCustomAPI.Close();
+    iPbData.Close();
+    iReply.Close();
+    iNum1.Close();
+    iNum2.Close();
+    iNum3.Close();
+    iNum4.Close();
+    iText.Close();
+    iEmail.Close();
+    TRACE_FUNC_EXIT
+    }
+
+void CSCPBWCommandHandler::HandleCommand(const TDesC8& /*aCmd*/, RBuf8& /*aReply*/, TBool /*aReplyNeeded*/)
+    {
+    TRACE_FUNC_ENTRY
+    
+    if (iState != ESCPBWStateIdle)
+        {
+        // Reply "ERROR" if handler is not in idle
+        iCallback->CreateReplyAndComplete(EReplyTypeError);
+        TRACE_FUNC_EXIT
+        return;
+        }
+    TInt err = KErrNone;
+    
+    TAtCommandParser::TCommandHandlerType cmdHandlerType = iATCmdParser.CommandHandlerType();
+    
+    switch (cmdHandlerType)
+        {
+        case (TAtCommandParser::ECmdHandlerTypeTest):
+            {
+            if (iMaxEntries == 0)
+                {
+                RMobilePhoneBookStore::TMobilePhoneBookInfoV1Pckg pckg(iPhoneBookStoreInfo);
+                iPhoneBookStore.GetInfo(iStatus, pckg);
+                iState = ESCPBWStateGetPhonebookInfo;
+                SetActive();
+                }
+            else if (iEmailLength == 0)
+                {
+                iState = ESCPBWStateGet3GPBInfo;
+                iMmCustomAPI.Get3GPBInfo(iStatus, i3GPBInfo);
+                SetActive();
+                }
+            else
+                {
+                // Phonebook info has been obtained
+                iReply.Zero();
+                iReply.Format(KSCPBWSupportedCmdsList, iMaxEntries, iNumLength, iTextLength, iEmailLength);
+                iCallback->CreateReplyAndComplete( EReplyTypeOk, iReply );
+                }
+            }
+            break;
+        case (TAtCommandParser::ECmdHandlerTypeSet): 
+            {
+            ResetParameters();
+            TBool isDeleteRequest = EFalse;
+            err = ParseParameters(isDeleteRequest);
+            Trace(_L("Parse completed, err = %d"), err);
+            if (isDeleteRequest)
+                {
+                // Delete entry at iIndex
+                iState = ESCPBWStateDelete;
+                iPhoneBookStore.Delete(iStatus, iIndex);
+                SetActive();
+                }
+            else if (err == KErrNone)
+                {
+                // Create an entry
+                err = CreateContactEntry();
+                if (err == KErrNone)
+                    {
+                    iPhoneBookStore.Write(iStatus, iPbData, iIndex);
+                    iState = ESCPBWStateWrite;
+                    SetActive();
+                    }
+                else
+                    {
+                    iCallback->CreateReplyAndComplete( EReplyTypeError );
+                    }
+                }
+            else
+                {
+                iCallback->CreateReplyAndComplete( EReplyTypeError );
+                }
+            break;
+            }
+        default:
+            {
+            iCallback->CreateReplyAndComplete( EReplyTypeError );
+            break;
+            }
+        }
+    
+    TRACE_FUNC_EXIT
+    }
+
+void CSCPBWCommandHandler::RunL()
+    {
+    TRACE_FUNC_ENTRY
+    
+    iReply.Zero();
+    TInt err = iStatus.Int();
+    Trace(_L("State = %d, err = %d"), iState, err);
+    
+    if (err == KErrNone)
+        {
+        switch (iState)
+            {
+            case ESCPBWStateGetPhonebookInfo:
+                {
+                Trace(_L("Get info successful."));
+                iNumLength = iPhoneBookStoreInfo.iMaxNumLength;
+                iTextLength = iPhoneBookStoreInfo.iMaxTextLength;
+                iMaxEntries = iPhoneBookStoreInfo.iTotalEntries;
+                if (iEmailLength == 0)
+                    {
+                    iMmCustomAPI.Get3GPBInfo(iStatus, i3GPBInfo);
+                    iState = ESCPBWStateGet3GPBInfo;
+                    SetActive();
+                    }
+                else
+                    {
+                    iReply.Format(KSCPBWSupportedCmdsList, iMaxEntries, iNumLength, iTextLength, iEmailLength);
+                    iCallback->CreateReplyAndComplete(EReplyTypeOk, iReply);
+                    iState = ESCPBWStateIdle;
+                    }
+                }
+                break;
+            case ESCPBWStateGet3GPBInfo:
+                {
+                Trace(_L("Get 3GPB info successful."));
+                iEmailLength = i3GPBInfo.iMaxLenEmail;
+                iReply.Format(KSCPBWSupportedCmdsList, iMaxEntries, iNumLength, iTextLength, iEmailLength);
+                iCallback->CreateReplyAndComplete(EReplyTypeOk, iReply);
+                iState = ESCPBWStateIdle;
+                }
+                break;
+            case ESCPBWStateWrite:
+                {
+                Trace(_L("Write successful. Index = %d"), iIndex);
+                iCallback->CreateReplyAndComplete(EReplyTypeOk);
+                iState = ESCPBWStateIdle;
+                }
+                break;
+            case ESCPBWStateDelete:
+                {
+                Trace(_L("Delete successful."));
+                iCallback->CreateReplyAndComplete(EReplyTypeOk);
+                iState = ESCPBWStateIdle;
+                }
+                break;
+            default:
+                {
+                iState = ESCPBWStateIdle;
+                iCallback->CreateReplyAndComplete(EReplyTypeError);
+                break;
+                }
+            }
+        }
+    else
+        {
+        iState = ESCPBWStateIdle; 
+        iCallback->CreateCMEReplyAndComplete(err);
+        }
+    
+    TRACE_FUNC_EXIT
+    }
+
+void CSCPBWCommandHandler::DoCancel() 
+    {
+    TRACE_FUNC_ENTRY
+    
+    switch (iState)
+        {
+        case ESCPBWStateGetPhonebookInfo:
+            {
+            iPhoneBookStore.CancelAsyncRequest(EMobilePhoneStoreGetInfo);
+            }
+            break;
+        case ESCPBWStateGet3GPBInfo:
+            {
+            iMmCustomAPI.CancelAsyncRequest(EGet3GPBInfoIPC);
+            }
+            break;
+        case ESCPBWStateDelete:
+            {
+            iPhoneBookStore.CancelAsyncRequest(EMobilePhoneStoreDelete);
+            }
+            break;
+        case ESCPBWStateWrite:
+            {
+            iPhoneBookStore.CancelAsyncRequest(EMobilePhoneStoreWrite);
+            }
+            break;
+        }
+    iState = ESCPBWStateIdle;
+    
+    TRACE_FUNC_EXIT
+    }
+
+TInt CSCPBWCommandHandler::ParseParameters( TBool& aIsDeleteRequest )
+    {
+    TRACE_FUNC_ENTRY
+    
+    TInt ret = KErrNone;
+    // Paese index
+    ret = iATCmdParser.NextIntParam(iIndex); 
+    Trace(_L("Parse index err: %d"), ret);
+    Trace(_L("index: %d"), iIndex);
+    if (ret != KErrNone && ret != KErrNotFound)
+        {
+        // Bad index
+        TRACE_FUNC_EXIT
+        return KErrArgument;
+        }
+    
+    TPtrC8 ptrc;
+    // Parse num1
+    ptrc.Set(iATCmdParser.NextParam());
+    if (ptrc.Length() != 0)
+        {
+        Trace(_L("Parse num1 OK: %S"), &ptrc);
+        SetBuffer(iNum1, ptrc);
+        }
+    else if (ret == KErrNone )
+        {
+        // Only index given
+        Trace(_L("Only index given."));
+        aIsDeleteRequest = ETrue;
+        TRACE_FUNC_EXIT
+        return KErrNone;
+        }
+    else 
+        {
+        // no num1 found
+        TRACE_FUNC_EXIT
+        return KErrArgument;
+        }
+    ret = iATCmdParser.NextIntParam(iType1);
+    if (ret == KErrNotFound)
+        {
+        TRACE_FUNC_EXIT
+        return KErrNone;
+        }
+    else if (ret != KErrNone)
+        {
+        TRACE_FUNC_EXIT
+        return KErrArgument;
+        }
+    
+    // Parse num2
+    ptrc.Set(iATCmdParser.NextParam());
+    if (ptrc.Length() != 0)
+        {
+        Trace(_L("Parse num2 OK: %S"), &ptrc);
+        SetBuffer(iNum2, ptrc);
+        }
+    else 
+        {
+        // no num2 found
+        TRACE_FUNC_EXIT
+        return KErrNone;
+        }
+    ret = iATCmdParser.NextIntParam(iType2);
+    if (ret == KErrNotFound)
+        {
+        TRACE_FUNC_EXIT
+        return KErrNone;
+        }
+    else if (ret != KErrNone)
+        {
+        TRACE_FUNC_EXIT
+        return KErrArgument;
+        }
+    
+    // Parse num3
+    ptrc.Set(iATCmdParser.NextParam());
+    if (ptrc.Length() != 0)
+        {
+        Trace(_L("Parse num3 OK: %S"), &ptrc);
+        SetBuffer(iNum3, ptrc);
+        }
+    else
+        {
+        // no num3 found
+        TRACE_FUNC_EXIT
+        return KErrNone;
+        }
+    ret = iATCmdParser.NextIntParam(iType3);
+    if (ret == KErrNotFound)
+        {
+        TRACE_FUNC_EXIT
+        return KErrNone;
+        }
+    else if (ret != KErrNone)
+        {
+        TRACE_FUNC_EXIT
+        return KErrArgument;
+        }
+    
+    // Parse num4
+    ptrc.Set(iATCmdParser.NextParam());
+    if (ptrc.Length() != 0)
+        {
+        Trace(_L("Parse num4 OK: %S"), &ptrc);
+        SetBuffer(iNum4, ptrc);
+        }
+    else
+        {
+        // no num4 found
+        TRACE_FUNC_EXIT
+        return KErrNone;
+        }
+    ret = iATCmdParser.NextIntParam(iType4);
+    if (ret == KErrNotFound)
+        {
+        TRACE_FUNC_EXIT
+        return KErrNone;
+        }
+    else if (ret != KErrNone)
+        {
+        TRACE_FUNC_EXIT
+        return KErrArgument;
+        }
+    
+    // Parse text
+    ptrc.Set(iATCmdParser.NextParam());
+    if (ptrc.Length() != 0)
+        {
+        Trace(_L("Parse text OK: %S"), &ptrc);
+        SetBuffer(iText, ptrc);
+        }
+    else
+        {
+        // no text found
+        TRACE_FUNC_EXIT
+        return KErrNone;
+        }
+    ret = iATCmdParser.NextIntParam(iCoding);
+    if (ret == KErrNotFound)
+        {
+        TRACE_FUNC_EXIT
+        return KErrNone;
+        }
+    else if (ret != KErrNone)
+        {
+        TRACE_FUNC_EXIT
+        return KErrArgument;
+        }
+    
+    // Parse email
+    ptrc.Set(iATCmdParser.NextParam());
+    if (ptrc.Length() != 0)
+        {
+        Trace(_L("Parse email OK: %S"), &ptrc);
+        SetBuffer(iEmail, ptrc);
+        }
+    else
+        {
+        // no email found
+        TRACE_FUNC_EXIT
+        return KErrNone;
+        }
+    
+    if (iATCmdParser.NextParam().Length() != 0)
+        {
+        // too many parameters
+        Trace(_L("Too many parameters."));
+        TRACE_FUNC_EXIT
+        return KErrArgument;
+        }
+    
+    TRACE_FUNC_EXIT
+    return KErrNone;
+    }
+
+TInt CSCPBWCommandHandler::CreateContactEntry()
+    {
+    TRACE_FUNC_ENTRY
+    
+    TInt err = KErrNone;
+    iPhoneBookBuffer->Set(&iPbData);
+    // Add new entry tag
+    err = iPhoneBookBuffer->AddNewEntryTag();
+    Trace(_L("New entry tag added, err = %d"), err);
+    if (err != KErrNone)
+        {
+        TRACE_FUNC_EXIT
+        return err;
+        }
+    // Put index into the entry
+    err = iPhoneBookBuffer->PutTagAndValue(RMobilePhoneBookStore::ETagPBAdnIndex, (TUint16)iIndex);
+    Trace(_L("Index added, err = %d"), err);
+    if (err != KErrNone)
+        {
+        TRACE_FUNC_EXIT
+        return err;
+        }
+    // Put text into the entry
+    if (iText.Length() != 0)
+        {
+        err = iPhoneBookBuffer->PutTagAndValue(RMobilePhoneBookStore::ETagPBText, iText);
+        Trace(_L("Text added, err = %d"), err);
+        if (err != KErrNone)
+            {
+            TRACE_FUNC_EXIT
+            return err;
+            }
+        }
+    // Put num1 into the entry
+    if (iNum1.Length() != 0)
+        {
+        err = iPhoneBookBuffer->PutTagAndValue(RMobilePhoneBookStore::ETagPBNumber, iNum1);
+        Trace(_L("Number 1 added, err = %d"), err);
+        if (err != KErrNone)
+            {
+            TRACE_FUNC_EXIT
+            return err;
+            }
+        }
+    // Put num2 into the entry
+    if (iNum2.Length() != 0)
+        {
+        // Add anr tag 
+        err = iPhoneBookBuffer->AddNewNumberTag();
+        Trace(_L("New number tag added, err = %d"), err);
+        if (err != KErrNone)
+            {
+            TRACE_FUNC_EXIT
+            return err;
+            }
+        err = iPhoneBookBuffer->PutTagAndValue(RMobilePhoneBookStore::ETagPBNumber, iNum2);
+        Trace(_L("Number 2 added, err = %d"), err);
+        if (err != KErrNone)
+            {
+            TRACE_FUNC_EXIT
+            return err;
+            }
+        }
+    // Put num3 into the entry
+    if (iNum3.Length() != 0)
+        {
+        // Add anr tag 
+        err = iPhoneBookBuffer->AddNewNumberTag();
+        Trace(_L("New number tag added, err = %d"), err);
+        if (err != KErrNone)
+            {
+            TRACE_FUNC_EXIT
+            return err;
+            }
+        err = iPhoneBookBuffer->PutTagAndValue(RMobilePhoneBookStore::ETagPBNumber, iNum3);
+        Trace(_L("Number 3 added, err = %d"), err);
+        if (err != KErrNone)
+            {
+            TRACE_FUNC_EXIT
+            return err;
+            }
+        }
+    // Put num4 into the entry
+    if (iNum4.Length() != 0)
+        {
+        // Add anr tag 
+        err = iPhoneBookBuffer->AddNewNumberTag();
+        Trace(_L("New number tag added, err = %d"), err);
+        if (err != KErrNone)
+            {
+            TRACE_FUNC_EXIT
+            return err;
+            }
+        err = iPhoneBookBuffer->PutTagAndValue(RMobilePhoneBookStore::ETagPBNumber, iNum4);
+        Trace(_L("Number 4 added, err = %d"), err);
+        if (err != KErrNone)
+            {
+            TRACE_FUNC_EXIT
+            return err;
+            }
+        }    
+    // Put email address into the entry
+    if (iEmail.Length() != 0)
+        {
+        err = iPhoneBookBuffer->PutTagAndValue(RMobilePhoneBookStore::ETagPBEmailAddress, iEmail);
+        Trace(_L("Email added, err = %d"), err);
+        if (err != KErrNone)
+            {
+            TRACE_FUNC_EXIT
+            return err;
+            }
+        }
+    
+    TRACE_FUNC_EXIT
+    return KErrNone;
+    }
+
+void CSCPBWCommandHandler::ResetParameters()
+    {
+    TRACE_FUNC_ENTRY
+    
+    iPbData.Zero();
+    iIndex = -1;
+    iNum1.Zero();
+    iType1 = 0x91; // International & ISDN
+    iNum2.Zero();
+    iType2 = 0x91;
+    iNum3.Zero();
+    iType3 = 0x91;
+    iNum4.Zero();
+    iType4 = 0x91;
+    iText.Zero();
+    iCoding = 0; // GSM 7 bit
+    iEmail.Zero();
+    
+    TRACE_FUNC_EXIT
+    }
+
+void CSCPBWCommandHandler::SetBuffer(TDes& aDest, const TDesC8& aSource)
+    {
+    TRACE_FUNC_ENTRY
+    TInt maxLength = aDest.MaxLength();
+    if (aSource.Length() <= maxLength)
+        {
+        aDest.Copy(aSource);
+        }
+    else
+        {
+        aDest.Copy(aSource.Left(maxLength));
+        }
+    TRACE_FUNC_EXIT
+    }
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/cbsatplugin/atmisccmdplugin/src/telephonywrapper.cpp	Wed Aug 18 09:59:05 2010 +0300
@@ -0,0 +1,117 @@
+/*
+ * Copyright (c) 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"
+ * which accompanies this distribution, and is available
+ * at the URL "http://www.eclipse.org/legal/epl-v10.html".
+ * Initial Contributors:
+ * Nokia Corporation - initial contribution.
+ *
+ * Contributors:
+ * Description :
+ *
+ */
+
+#include "telephonywrapper.h"
+#include "debug.h"
+
+CTelephonyWrapper* CTelephonyWrapper::NewL()    
+    {
+    TRACE_FUNC_ENTRY
+    CTelephonyWrapper* self = new (ELeave) CTelephonyWrapper();
+    CleanupStack::PushL(self);
+    self->ConstructL();
+    CleanupStack::Pop(self);
+    TRACE_FUNC_EXIT
+    return self;
+    } 
+
+CTelephonyWrapper::CTelephonyWrapper() :
+        CActive(CActive::EPriorityStandard), 
+        iPhoneIdV1Pckg(iPhoneIdV1)
+    {
+    TRACE_FUNC_ENTRY
+    TRACE_FUNC_EXIT
+    } 
+    
+void CTelephonyWrapper::ConstructL()    
+    {
+    TRACE_FUNC_ENTRY
+    CActiveScheduler::Add(this);
+    iTelephony = CTelephony::NewL();
+    TRACE_FUNC_EXIT
+    } 
+    
+CTelephonyWrapper::~CTelephonyWrapper()    
+    {
+    TRACE_FUNC_ENTRY
+    Cancel();
+    delete iTelephony;
+    TRACE_FUNC_EXIT
+    }    
+    
+TInt CTelephonyWrapper::SynchronousGetPhoneId()    
+    {
+    TRACE_FUNC_ENTRY
+    
+    if (!IsActive())
+        {
+        iTelephony->GetPhoneId(iStatus, iPhoneIdV1Pckg);
+        SetActive();
+        iWaiter.Start();
+        
+        if (KErrNone == iStatus.Int())
+            {
+            iModel = iPhoneIdV1.iModel.Collapse();
+            iSn = iPhoneIdV1.iSerialNumber.Collapse();
+            iManufacturer = iPhoneIdV1.iManufacturer.Collapse();
+            }
+        }
+    else
+        {
+        TRACE_FUNC_EXIT
+        return KErrInUse;
+        }
+       
+    TRACE_FUNC_EXIT
+    return iStatus.Int();    
+    } 
+
+const TDesC8& CTelephonyWrapper::GetPhoneModel()
+    {
+    TRACE_FUNC_ENTRY
+    TRACE_FUNC_EXIT
+    return iModel;
+    }
+
+const TDesC8& CTelephonyWrapper::GetPhoneSerialNum()
+    {
+    TRACE_FUNC_ENTRY
+    TRACE_FUNC_EXIT
+    return iSn;
+    }
+
+const TDesC8& CTelephonyWrapper::GetPhoneManufacturer()
+    {
+    TRACE_FUNC_ENTRY
+    TRACE_FUNC_EXIT
+    return iManufacturer;
+    }
+
+void CTelephonyWrapper::RunL()    
+    {
+    TRACE_FUNC_ENTRY
+    iWaiter.AsyncStop();
+    TRACE_FUNC_EXIT
+    } 
+
+void CTelephonyWrapper::DoCancel()    
+    {
+    TRACE_FUNC_ENTRY
+    iTelephony->CancelAsync(CTelephony::EGetPhoneIdCancel);
+    iWaiter.AsyncStop();
+    TRACE_FUNC_EXIT
+    }
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/package_map.xml	Wed Aug 18 09:59:05 2010 +0300
@@ -0,0 +1,2 @@
+<?xml version="1.0"?>
+<PackageMap root="sf" layer="mw" />
\ No newline at end of file