Revision: 201031 RCL_3
authorDremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
Thu, 19 Aug 2010 10:05:41 +0300
branchRCL_3
changeset 21 0ba996a9b75d
parent 20 eede1356aa52
child 22 613943a21004
Revision: 201031 Kit: 201033
bluetoothengine/bteng/bttoggle/src/bttoggle.cpp
bluetoothengine/bteng/src/btengsrvsettingsmgr.cpp
bluetoothengine/bthid/keyboard/src/keyboard.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/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
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/clckcommandhandler.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
--- a/bluetoothengine/bteng/bttoggle/src/bttoggle.cpp	Thu Jul 15 18:50:18 2010 +0300
+++ b/bluetoothengine/bteng/bttoggle/src/bttoggle.cpp	Thu Aug 19 10:05:41 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:							
--- a/bluetoothengine/bteng/src/btengsrvsettingsmgr.cpp	Thu Jul 15 18:50:18 2010 +0300
+++ b/bluetoothengine/bteng/src/btengsrvsettingsmgr.cpp	Thu Aug 19 10:05:41 2010 +0300
@@ -699,9 +699,11 @@
     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/bthid/keyboard/src/keyboard.cpp	Thu Jul 15 18:50:18 2010 +0300
+++ b/bluetoothengine/bthid/keyboard/src/keyboard.cpp	Thu Aug 19 10:05:41 2010 +0300
@@ -25,6 +25,7 @@
 #include <apgtask.h>
 #include <e32keys.h>
 #include <avkondomainpskeys.h>
+#include <coreapplicationuisdomainpskeys.h>
 
 #include "hidtranslate.h"
 #include "finder.h"
@@ -1188,17 +1189,6 @@
         TRACE_INFO( (_L("[HID]\tCHidKeyboardDriver::WindowGroupForKeyEvent: type %d, kc 0x%08x, sc 0x%08x, mod 0x%06x, rep %d]"),
                         aType, aKeyEvent.iCode, aKeyEvent.iScanCode,
                         aKeyEvent.iModifiers, aKeyEvent.iRepeats));
-    _LIT(KBackDrop, "*EiksrvBackdrop*");
-
-    if (EStdKeyApplication0 == aKeyEvent.iScanCode && (EEventKeyDown == aType
-            || EEventKeyUp == aType))
-        {
-        // Application key up/down events go to the Eikon server
-        // Use this old way for application key
-        TInt result = iWsSession.FindWindowGroupIdentifier(0, KBackDrop); //This was in A2.x __EIKON_SERVER_NAME
-        DBG(if (KErrNotFound == result) RDebug::Print(_L("[HID]\tCHidKeyboardDriver::WindowGroupForKeyEvent(): BackDropWindowGroup Name not found!")));
-        return result;
-        }
 
     if (EKeyDevice2 == aKeyEvent.iCode && EEventKey == aType)
         {
@@ -1379,7 +1369,33 @@
 void CHidKeyboardDriver::LaunchApplicationL(TInt aAppUid)
     {
         TRACE_INFO( (_L("[HID]\tCHidKeyboardDriver::LaunchApplication: UID 0x%08x"), aAppUid));
-
+    
+    //KeyLock or phone auto lock is on, refuse to continue    
+    if (iKeyLock.IsKeyLockEnabled())
+        {        
+        TRACE_INFO( _L("[HID]\tCHidKeyboardDriver::LaunchApplicationL() SKIPPED BECAUSE OF KEYLOCK"));
+        return;
+        }
+    
+    TInt devLockStatus( EAutolockStatusUninitialized );
+    TInt err = RProperty::Get(  KPSUidCoreApplicationUIs, KCoreAppUIsAutolockStatus, devLockStatus );
+                    
+    if (!err)
+        {
+        if ( EAutolockOff != devLockStatus && EAutolockStatusUninitialized != devLockStatus)
+            {
+            //Auto lock is on, refuse to continue
+            TRACE_INFO( _L("[HID]\tCHidKeyboardDriver::LaunchApplicationL() SKIPPED BECAUSE OF AUTO LOCK"));
+            return;
+            }
+        }
+    else
+        {
+        //failed to get AUTO LOCK status
+        TRACE_INFO( _L("[HID]\tCHidKeyboardDriver::LaunchApplicationL() SKIPPED BECAUSE OF FAILED TO GET AUTO LOCK STATUS"));
+        return;
+        }
+    
     TApaTaskList taskList(iWsSession);
     TUid uid = TUid::Uid(aAppUid);
     TApaTask task = taskList.FindApp(uid);
@@ -1465,6 +1481,8 @@
             // fall through
         case EStdKeyF8:
             // fall through
+        case EStdKeyApplication0: 	 
+            // fall through
         case EStdKeyApplication2:
             // fall through
         case EStdKeyApplication3:
@@ -1916,16 +1934,41 @@
             else if (aIsKeyDown &&
                 iKeyLock.IsKeyLockEnabled())
                 {
-                TRACE_INFO((_L("[HID]\tESC >>> DISBALE KEY LOCK DOWN")));
+                TInt devLockStatus( EAutolockStatusUninitialized );
+                TInt err = RProperty::Get(	KPSUidCoreApplicationUIs, KCoreAppUIsAutolockStatus, devLockStatus );
                 
-                iKeyLock.DisableKeyLock();
+                if (!err)
+                    {
+                    if (EAutolockOff == devLockStatus || EAutolockStatusUninitialized == devLockStatus)
+                        {
+                        TRACE_INFO((_L("[HID]\tESC >>> AUTO LOCK IS OFF, DISBALE KEY LOCK DOWN ")));                                       
+                        iKeyLock.DisableKeyLock();
+                        ret = ETrue;
+                        iNavKeyDown = (iNavKeyDown | EEsc);
+                        }
+                    else
+                        {
+                        TRACE_INFO((_L("[HID]\tESC >>> AUTO LOCK IS ON, DISBALE KEY LOCK DOWN SKIPPED")));
+                        }
+                    }
+                else
+                    {
+                    TRACE_INFO((_L("[HID]\tESC >>> FAILED to get AUTO LOCK status, DISBALE KEY LOCK DOWN SKIPPED")));
+                    }
 
-                ret = ETrue;
-                iNavKeyDown = (iNavKeyDown | EEsc);
                 }
 
             break;
             }
+        case EStdKeyApplication0:
+			{ 	  	 
+			TRACE_INFO((_L("[HID]\tAPPLICATION KEY(Alt+Tab) >>> TSW"))); 	  	 
+					 
+			// Dedicated Application key 	  	 
+			scancode = EStdKeyApplication0; 	  	 
+			isMmKey = ETrue; 	  	 
+			break; 	  	 
+			}            
         case EStdKeyF8:
             // fall through
         case EStdKeyApplication2:
--- a/bluetoothengine/btmac/inc/btmonobearer/bmbcmdlistener.h	Thu Jul 15 18:50:18 2010 +0300
+++ b/bluetoothengine/btmac/inc/btmonobearer/bmbcmdlistener.h	Thu Aug 19 10:05:41 2010 +0300
@@ -90,7 +90,7 @@
         RProperty iATRespProperty;
 
 		// At command buffer
-		TBuf8<KDefaultCmdBufLength> iAtCmdBuf;
+        RBuf8 iAtCmdBuf;
     };
 
 #endif
--- a/bluetoothengine/btmac/inc/btmonocmdhandler/HfpAtCmdHandler.h	Thu Jul 15 18:50:18 2010 +0300
+++ b/bluetoothengine/btmac/inc/btmonocmdhandler/HfpAtCmdHandler.h	Thu Aug 19 10:05:41 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	Thu Jul 15 18:50:18 2010 +0300
+++ b/bluetoothengine/btmac/src/BTMonoCmdHandler/HfpAtCmdhandler.cpp	Thu Aug 19 10:05:41 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	Thu Jul 15 18:50:18 2010 +0300
+++ b/bluetoothengine/btmac/src/BTMonoCmdHandler/btmccallinghandler.cpp	Thu Aug 19 10:05:41 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	Thu Jul 15 18:50:18 2010 +0300
+++ b/bluetoothengine/btmac/src/BTMonoCmdHandler/btmcprotocol.cpp	Thu Aug 19 10:05:41 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	Thu Jul 15 18:50:18 2010 +0300
+++ b/bluetoothengine/btmac/src/btmac/btmpagescanparametersmanager.cpp	Thu Aug 19 10:05:41 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	Thu Jul 15 18:50:18 2010 +0300
+++ b/bluetoothengine/btmac/src/btmonobearer/bmbcmdlistener.cpp	Thu Aug 19 10:05:41 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/btsac/btrcc/inc/btrccVolumeLevelControllerBase.h	Thu Jul 15 18:50:18 2010 +0300
+++ b/bluetoothengine/btsac/btrcc/inc/btrccVolumeLevelControllerBase.h	Thu Aug 19 10:05:41 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	Thu Jul 15 18:50:18 2010 +0300
+++ b/bluetoothengine/btsac/btrcc/src/btrccAbsoluteVolumeLevelController.cpp	Thu Aug 19 10:05:41 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	Thu Jul 15 18:50:18 2010 +0300
+++ b/bluetoothengine/btsac/btrcc/src/btrccLegacyVolumeLevelController.cpp	Thu Aug 19 10:05:41 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	Thu Jul 15 18:50:18 2010 +0300
+++ b/bluetoothengine/btsac/btrcc/src/btrccLinker.cpp	Thu Aug 19 10:05:41 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	Thu Jul 15 18:50:18 2010 +0300
+++ b/bluetoothengine/btsac/btrcc/src/btrccVolumeLevelControllerBase.cpp	Thu Aug 19 10:05:41 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	Thu Jul 15 18:50:18 2010 +0300
+++ b/bluetoothengine/btsac/inc/btsaController.h	Thu Aug 19 10:05:41 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	Thu Jul 15 18:50:18 2010 +0300
+++ b/bluetoothengine/btsac/inc/btsacStateListening.h	Thu Aug 19 10:05:41 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	Thu Jul 15 18:50:18 2010 +0300
+++ b/bluetoothengine/btsac/inc/btsacdefs.h	Thu Aug 19 10:05:41 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	Thu Jul 15 18:50:18 2010 +0300
+++ b/bluetoothengine/btsac/src/btsaController.cpp	Thu Aug 19 10:05:41 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	Thu Jul 15 18:50:18 2010 +0300
+++ b/bluetoothengine/btsac/src/btsacState.cpp	Thu Aug 19 10:05:41 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	Thu Jul 15 18:50:18 2010 +0300
+++ b/bluetoothengine/btsac/src/btsacStateAborting.cpp	Thu Aug 19 10:05:41 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	Thu Jul 15 18:50:18 2010 +0300
+++ b/bluetoothengine/btsac/src/btsacStateConfigured.cpp	Thu Aug 19 10:05:41 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	Thu Jul 15 18:50:18 2010 +0300
+++ b/bluetoothengine/btsac/src/btsacStateConfiguring.cpp	Thu Aug 19 10:05:41 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	Thu Jul 15 18:50:18 2010 +0300
+++ b/bluetoothengine/btsac/src/btsacStateConnected.cpp	Thu Aug 19 10:05:41 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	Thu Jul 15 18:50:18 2010 +0300
+++ b/bluetoothengine/btsac/src/btsacStateConnecting.cpp	Thu Aug 19 10:05:41 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	Thu Jul 15 18:50:18 2010 +0300
+++ b/bluetoothengine/btsac/src/btsacStateIdle.cpp	Thu Aug 19 10:05:41 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	Thu Jul 15 18:50:18 2010 +0300
+++ b/bluetoothengine/btsac/src/btsacStateListening.cpp	Thu Aug 19 10:05:41 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	Thu Jul 15 18:50:18 2010 +0300
+++ b/bluetoothengine/btsac/src/btsacStateStreaming.cpp	Thu Aug 19 10:05:41 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	Thu Jul 15 18:50:18 2010 +0300
+++ b/bluetoothengine/btsac/src/btsacStateSuspended.cpp	Thu Aug 19 10:05:41 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));
 	}
     
 // -----------------------------------------------------------------------------
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/cbsatplugin/atmisccmdplugin/data/2002C3BA_TDSCDMA.rss	Thu Aug 19 10:05:41 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	Thu Jul 15 18:50:18 2010 +0300
+++ b/cbsatplugin/atmisccmdplugin/group/atmisccmdplugin.mmp	Thu Aug 19 10:05:41 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	Thu Jul 15 18:50:18 2010 +0300
+++ b/cbsatplugin/atmisccmdplugin/inc/atcommandparser.h	Thu Aug 19 10:05:41 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	Thu Jul 15 18:50:18 2010 +0300
+++ b/cbsatplugin/atmisccmdplugin/inc/atmisccmdplugin.h	Thu Aug 19 10:05:41 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	Thu Jul 15 18:50:18 2010 +0300
+++ b/cbsatplugin/atmisccmdplugin/inc/atmisccmdpluginconsts.h	Thu Aug 19 10:05:41 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	Thu Aug 19 10:05:41 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	Thu Aug 19 10:05:41 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	Thu Aug 19 10:05:41 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	Thu Aug 19 10:05:41 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	Thu Aug 19 10:05:41 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	Thu Aug 19 10:05:41 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	Thu Aug 19 10:05:41 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	Thu Aug 19 10:05:41 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	Thu Aug 19 10:05:41 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	Thu Aug 19 10:05:41 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	Thu Aug 19 10:05:41 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	Thu Jul 15 18:50:18 2010 +0300
+++ b/cbsatplugin/atmisccmdplugin/rom/atmisccmdplugin.iby	Thu Aug 19 10:05:41 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	Thu Jul 15 18:50:18 2010 +0300
+++ b/cbsatplugin/atmisccmdplugin/src/atcommandparser.cpp	Thu Aug 19 10:05:41 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	Thu Jul 15 18:50:18 2010 +0300
+++ b/cbsatplugin/atmisccmdplugin/src/atmisccmdplugin.cpp	Thu Aug 19 10:05:41 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	Thu Aug 19 10:05:41 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	Thu Aug 19 10:05:41 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	Thu Aug 19 10:05:41 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	Thu Aug 19 10:05:41 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
+    }
+
+
--- a/cbsatplugin/atmisccmdplugin/src/clckcommandhandler.cpp	Thu Jul 15 18:50:18 2010 +0300
+++ b/cbsatplugin/atmisccmdplugin/src/clckcommandhandler.cpp	Thu Aug 19 10:05:41 2010 +0300
@@ -719,11 +719,6 @@
                 }
             break;
             }
-        default:
-            {
-            TRACE_FUNC_EXIT
-            return KErrArgument;
-            }
         }
     
     // if phone password is required it needs to be hashed before verification
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/cbsatplugin/atmisccmdplugin/src/cmgdcommandhandler.cpp	Thu Aug 19 10:05:41 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	Thu Aug 19 10:05:41 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	Thu Jul 15 18:50:18 2010 +0300
+++ b/cbsatplugin/atmisccmdplugin/src/cpincommandhandler.cpp	Thu Aug 19 10:05:41 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	Thu Aug 19 10:05:41 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	Thu Aug 19 10:05:41 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	Thu Aug 19 10:05:41 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	Thu Aug 19 10:05:41 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
+    }
+
+