adaptationlayer/tsy/simatktsy_dll/src/satmosmsctrl.cpp
changeset 0 63b37f68c1ce
child 5 8ccc39f9d787
equal deleted inserted replaced
-1:000000000000 0:63b37f68c1ce
       
     1 /*
       
     2 * Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 //  INCLUDE FILES
       
    21 #include "satmosmsctrl.h"       // sat mo sms control class
       
    22 #include "satmessaging.h"       // sat messaging class
       
    23 #include "satmesshandler.h"     // sat message handler class
       
    24 #include "ber_tlv.h"            // sat ber-tlv classes
       
    25 #include "satutil.h"            // sat utility class
       
    26 
       
    27 #include <pn_const.h>           // server id constants
       
    28 #include <tisi.h>               // isi message
       
    29 #include <uiccisi.h>            // UICC server
       
    30 #include <smsisi.h>             // sms server
       
    31 #include <atk_sharedisi.h>
       
    32 #include "osttracedefinitions.h"
       
    33 #ifdef OST_TRACE_COMPILER_IN_USE
       
    34 #include "satmosmsctrltraces.h"
       
    35 #endif
       
    36 
       
    37 
       
    38 
       
    39 // CONSTANTS
       
    40 const TUint8 KReservedTonNpi1           = 0x7F;
       
    41 const TUint8 KReservedTonNpi2           = 0xF7;
       
    42 const TUint8 KMaxLengthAddr1Addr2       = 249;
       
    43 const TUint8 KMaxLengthOfAtkSwDataNtf   = 255;
       
    44 const TUint8 KMaxLengthOfResourceReq    = 255;
       
    45 const TUint8 KSmControlAllowed          = 0;
       
    46 const TUint8 KSmControlNotAllowed       = 1;
       
    47 const TUint8 KSmControlAllowedWithModif = 2;
       
    48 
       
    49 // ==================== MEMBER FUNCTIONS ====================================
       
    50 
       
    51 // -----------------------------------------------------------------------------
       
    52 // CSatMoSmsCtrl::CSatMoSmsCtrl
       
    53 // C++ default constructor can NOT contain any code, that
       
    54 // might leave.
       
    55 // -----------------------------------------------------------------------------
       
    56 //
       
    57 CSatMoSmsCtrl::CSatMoSmsCtrl
       
    58         (
       
    59         CSatMessHandler*    aSatMessHandler,
       
    60         CTsySatMessaging*   aSatMessaging
       
    61         )
       
    62         :
       
    63         iSatMessHandler( aSatMessHandler ),
       
    64         iSatMessaging( aSatMessaging ),
       
    65         iWaitingForEnvelopeResp( EFalse ),
       
    66         iIsMoSmsCtrlActivated( EFalse ),
       
    67         iMoSmsCtrlEnvelopeTransactionId( KZero ),
       
    68         iMoSmsCtrlReqTransactionId( KZero ),
       
    69         iSenderObject( KZero )
       
    70     {
       
    71     OstTrace0( TRACE_NORMAL, CSATMOSMSCTRL_CSATMOSMSCTRL, "CSatMoSmsCtrl::CSatMoSmsCtrl" );
       
    72     }
       
    73 
       
    74 
       
    75 // -----------------------------------------------------------------------------
       
    76 // CSatMoSmsCtrl::ConstructL
       
    77 // Symbian 2nd phase constructor can leave.
       
    78 // -----------------------------------------------------------------------------
       
    79 //
       
    80 void CSatMoSmsCtrl::ConstructL()
       
    81     {
       
    82     OstTrace0( TRACE_NORMAL, CSATMOSMSCTRL_CONSTRUCTL, "CSatMoSmsCtrl::ConstructL" );
       
    83 #ifdef INFO_PP_ATK_MO_SM_CONTROL
       
    84     // Check MO SMS control is supported by ME's Product Profile
       
    85     iSatMessHandler->InfoPpReadReq( INFO_PP_ATK_MO_SM_CONTROL );
       
    86 #else
       
    87     // Check if MO-SMS control should be activated in SMS server
       
    88     // This is done by sending a request SimReadTableReq to Sim server, with
       
    89     // service type KSimStMoSmsSimControlAvail
       
    90     iSatMessHandler->SimReadTableReq( SIM_ST_MO_SMS_SIM_CONTROL_AVAIL );
       
    91 #endif // INFO_PP_ATK_MO_SM_CONTROL
       
    92     }
       
    93 
       
    94 
       
    95 // -----------------------------------------------------------------------------
       
    96 // CSatMoSmsCtrl::NewL
       
    97 // Two-phased constructor.
       
    98 // -----------------------------------------------------------------------------
       
    99 //
       
   100 CSatMoSmsCtrl* CSatMoSmsCtrl::NewL
       
   101         (
       
   102         CSatMessHandler*    aSatMessHandler,
       
   103         CTsySatMessaging*   aSatMessaging
       
   104         )
       
   105     {
       
   106     OstTrace0( TRACE_NORMAL, CSATMOSMSCTRL_NEWL, "CSatMoSmsCtrl::NewL" );
       
   107     TFLOGSTRING("TSY: CSatMoSmsCtrl::NewL");
       
   108 
       
   109     CSatMoSmsCtrl* self =
       
   110         new( ELeave ) CSatMoSmsCtrl( aSatMessHandler, aSatMessaging );
       
   111 
       
   112     CleanupStack::PushL( self );
       
   113     self->ConstructL();
       
   114     CleanupStack::Pop( self );
       
   115 
       
   116     return self;
       
   117     }
       
   118 
       
   119 
       
   120 // -----------------------------------------------------------------------------
       
   121 // CSatMoSmsCtrl::~CSatMoSmsCtrl
       
   122 // Destructor
       
   123 // -----------------------------------------------------------------------------
       
   124 //
       
   125 CSatMoSmsCtrl::~CSatMoSmsCtrl()
       
   126     {
       
   127     OstTrace0( TRACE_NORMAL, DUP1_CSATMOSMSCTRL_CSATMOSMSCTRL, "CSatMoSmsCtrl::~CSatMoSmsCtrl" );
       
   128     TFLOGSTRING("TSY: CSatMoSmsCtrl::~CSatMoSmsCtrl");
       
   129     }
       
   130 
       
   131 
       
   132 // -----------------------------------------------------------------------------
       
   133 // CSatMoSmsCtrl::IsActivated
       
   134 // Returns ETrue if MO-SMS Control is activated
       
   135 // -----------------------------------------------------------------------------
       
   136 //
       
   137 TBool CSatMoSmsCtrl::IsActivated()
       
   138     {
       
   139     OstTrace0( TRACE_NORMAL, CSATMOSMSCTRL_ISACTIVATED, "CSatMoSmsCtrl::IsActivated" );
       
   140     TFLOGSTRING("TSY: CSatMoSmsCtrl::IsActivated");
       
   141     return iIsMoSmsCtrlActivated;
       
   142     }
       
   143 
       
   144 // -----------------------------------------------------------------------------
       
   145 // CSatMoSmsCtrl::Activate
       
   146 // Set iIsMoSmsCtrlActivated to ETrue if MO-SMS Control has to be activated
       
   147 // -----------------------------------------------------------------------------
       
   148 //
       
   149 void CSatMoSmsCtrl::Activate()
       
   150     {
       
   151     OstTrace0( TRACE_NORMAL, CSATMOSMSCTRL_ACTIVATE, "CSatMoSmsCtrl::Activate" );
       
   152     TFLOGSTRING("TSY: CSatMoSmsCtrl::Activate");
       
   153     iIsMoSmsCtrlActivated = ETrue;
       
   154     }
       
   155 
       
   156 // -----------------------------------------------------------------------------
       
   157 // CSatMoSmsCtrl::Deactivate
       
   158 // Set iIsMoSmsCtrlActivated to EFalse if MO-SMS Control has to be deactivated
       
   159 // -----------------------------------------------------------------------------
       
   160 //
       
   161 void CSatMoSmsCtrl::Deactivate()
       
   162     {
       
   163     OstTrace0( TRACE_NORMAL, CSATMOSMSCTRL_DEACTIVATE, "CSatMoSmsCtrl::Deactivate" );
       
   164     TFLOGSTRING("TSY: CSatMoSmsCtrl::Deactivate");
       
   165     iIsMoSmsCtrlActivated = EFalse;
       
   166     }
       
   167 
       
   168 // -----------------------------------------------------------------------------
       
   169 // CSatMoSmsCtrl::UiccCatRespEnvelopeReceived
       
   170 // Handler function of incoming MO-SMS Control related data notification messages
       
   171 // -----------------------------------------------------------------------------
       
   172 //
       
   173 TInt CSatMoSmsCtrl::UiccCatRespEnvelopeReceived
       
   174         (
       
   175         const TIsiReceiveC& aIsiMessage //Received data notification
       
   176         )
       
   177     {
       
   178     OstTrace0( TRACE_NORMAL, CSATMOSMSCTRL_UICCCATRESPENVELOPERECEIVED, "CSatMoSmsCtrl::UiccCatRespEnvelopeReceived" );
       
   179     TFLOGSTRING("TSY:CSatMoSmsCtrl::UiccCatRespEnvelopeReceived");
       
   180     TBuf8<KMaxLengthOfAtkSwDataNtf> addr1;
       
   181     TBuf8<KMaxLengthOfAtkSwDataNtf> addr2;
       
   182     iWaitingForEnvelopeResp = EFalse;
       
   183 
       
   184     TUint8 status( aIsiMessage.Get8bit(
       
   185         ISI_HEADER_SIZE + UICC_CAT_RESP_OFFSET_STATUS ) );
       
   186     TBool simRespDataConsistent = ETrue;
       
   187     TUint8 resourceStatus = 0;
       
   188     TUint8 sw1( 0 );
       
   189     TUint8 sw2( 0 );
       
   190     TInt8 atkResult( 0 );
       
   191     TUint8 numSb( 3 ); // Mandatory no of subblocks
       
   192     TBuf8<SIZE_SMS_RESOURCE_REQ+SIZE_SMS_SB_RESOURCE+SIZE_SMS_SB_RESOURCE_SEQ_ID+
       
   193         SIZE_SMS_SB_ADDRESS+SMS_ADDRESS_MAX_LEN+SIZE_SMS_SB_TPDU_PACKING+
       
   194         SMS_TPDU_MAX_LEN+SIZE_SMS_SB_CAUSE> dataResp;
       
   195     TIsiSend resourceReq( dataResp );
       
   196     dataResp.AppendFill( KPadding, 1 ); // filler byte
       
   197     dataResp.Append( numSb ); // no of Subblocks
       
   198 
       
   199     if ( UICC_STATUS_OK == status )
       
   200         {
       
   201         TUint uiccSbApduOffset( 0 );
       
   202         if ( KErrNone == aIsiMessage.FindSubBlockOffsetById(
       
   203             ISI_HEADER_SIZE + SIZE_UICC_CAT_RESP,
       
   204             UICC_SB_APDU,
       
   205             EIsiSubBlockTypeId16Len16,
       
   206             uiccSbApduOffset ) )
       
   207             {
       
   208             TPtrC8 apduData;
       
   209             TUint16 apduLength( aIsiMessage.Get16bit(
       
   210                 uiccSbApduOffset + UICC_SB_APDU_OFFSET_APDULENGTH ) );
       
   211             apduData.Set( aIsiMessage.GetData(
       
   212                 uiccSbApduOffset + UICC_SB_APDU_OFFSET_APDU,
       
   213                 apduLength ) );
       
   214             // Status bytes are two last bytes in APDU
       
   215             sw1 = apduData[apduLength - 2];
       
   216             sw2 = apduData[apduLength - 1];
       
   217             // Get Call Control General Result
       
   218             atkResult = TSatUtility::Sw1Sw2Check( sw1, sw2 );
       
   219 
       
   220             if ( KError != atkResult ) // If ATK result is OK
       
   221                 {
       
   222                 TFLOGSTRING("TSY:CSatMoSmsCtrl::UiccCatRespEnvelopeReceived, Ok");
       
   223                 OstTrace0( TRACE_NORMAL, DUP1_CSATMOSMSCTRL_ATKSWDATANTFRECEIVED, "CSatMoSmsCtrl::UiccCatRespEnvelopeReceived, Ok" );
       
   224                 RSat::TAlphaId alphaId;
       
   225                 alphaId.iAlphaId.Zero();
       
   226                 TBool isAlphaIdEmpty( EFalse );
       
   227 
       
   228                 if ( KMaxLengthOfAtkSwDataNtf < apduLength ) // If data length greater than 255
       
   229                     {
       
   230                     TFLOGSTRING("TSY:CSatMoSmsCtrl::UiccCatRespEnvelopeReceived, the length of Sim resp data is > 255" );
       
   231                     OstTrace0( TRACE_NORMAL, DUP2_CSATMOSMSCTRL_ATKSWDATANTFRECEIVED, "CSatMoSmsCtrl::UiccCatRespEnvelopeReceived, the length of Sim resp data is > 255" );
       
   232                     // Data is not consistent, so not allowed condition
       
   233                     if( KSmControlNotAllowed == apduData[0] )
       
   234                         {
       
   235                         resourceStatus = SMS_RESOURCE_DENIED;
       
   236                         }
       
   237                     else
       
   238                         {
       
   239                         resourceStatus  = SMS_RESOURCE_ALLOWED;
       
   240                         }
       
   241                     FormSmsResourceReqSb( resourceStatus, dataResp, addr1, addr2 );
       
   242                     // Send resp to SMS server
       
   243                     // Return to the calling function right now, even if it's not
       
   244                     // a good thing to have several returns in the same method.
       
   245                     // To avoid it, more if statements would be needed and
       
   246                     // this doesn't make it any better.
       
   247                     return ( iSatMessHandler->SendSmsResourceReq(
       
   248                         iMoSmsCtrlReqTransactionId,
       
   249                         dataResp,
       
   250                         iSenderObject ) );
       
   251                     }
       
   252                 else if ( apduLength ) // If data length in non zero and less than 255
       
   253                     {
       
   254                     TFLOGSTRING("TSY:CSatMoSmsCtrl::UiccCatRespEnvelopeReceived, atkData.Length()!=0 ");
       
   255                     OstTrace0( TRACE_NORMAL, DUP3_CSATMOSMSCTRL_ATKSWDATANTFRECEIVED, "CSatMoSmsCtrl::UiccCatRespEnvelopeReceived, atkData.Length()!=0 " );
       
   256 
       
   257                     // Note: The alpha id can be provided by the SIM even if the addresses
       
   258                     // have not been modified.
       
   259                     ParseAtkSwDataNtf( apduData, addr1, addr2, alphaId, isAlphaIdEmpty );
       
   260 
       
   261                     if ( KSmControlAllowedWithModif == apduData[0] )
       
   262                         {
       
   263                         simRespDataConsistent = VerifySimRespData( addr1, addr2 );
       
   264                         }
       
   265                     if ( simRespDataConsistent )
       
   266                         {
       
   267                         if( KSmControlNotAllowed == apduData[0] )
       
   268                             {
       
   269                             resourceStatus = SMS_RESOURCE_DENIED;
       
   270                             }
       
   271                         else
       
   272                             {
       
   273                             resourceStatus  = SMS_RESOURCE_ALLOWED;
       
   274                             }
       
   275                         FormSmsResourceReqSb( resourceStatus, dataResp, addr1, addr2 );
       
   276                         TFLOGSTRING2("TSY:CSatMoSmsCtrl::UiccCatRespEnvelopeReceived, apduData[0]: %d",apduData[0] );
       
   277                         OstTrace1( TRACE_NORMAL, DUP4_CSATMOSMSCTRL_ATKSWDATANTFRECEIVED, "CSatMoSmsCtrl::UiccCatRespEnvelopeReceived, apduData[0]: %d", apduData[0] );
       
   278                        }
       
   279                     else
       
   280                        {
       
   281                        TFLOGSTRING("TSY:CSatMoSmsCtrl::UiccCatRespEnvelopeReceived, Sim response data not consistent" );
       
   282                        OstTrace0( TRACE_NORMAL, DUP5_CSATMOSMSCTRL_ATKSWDATANTFRECEIVED, "CSatMoSmsCtrl::UiccCatRespEnvelopeReceived, Sim response data not consistent" );
       
   283                        if( KSmControlNotAllowed == apduData[0] )
       
   284                            {
       
   285                            resourceStatus = SMS_RESOURCE_DENIED;
       
   286                            }
       
   287                        else
       
   288                            {
       
   289                            resourceStatus  = SMS_RESOURCE_ALLOWED;
       
   290                            }
       
   291                         FormSmsResourceReqSb( resourceStatus, dataResp, addr1, addr2 );
       
   292 
       
   293                         // Send resp to Sms server
       
   294                         // Return to the calling function right now, even if it's not
       
   295                         // a good thing to have several returns in the same method.
       
   296                         // To avoid it, more if statements would be needed and
       
   297                         // this doesn't make it any better.
       
   298                         return ( iSatMessHandler->SendSmsResourceReq(
       
   299                             iMoSmsCtrlReqTransactionId,
       
   300                             dataResp,
       
   301                             iSenderObject ) );
       
   302                         }
       
   303                     } // end of if statement for data length nonzero and less than 255
       
   304                 else  // block for data length zero
       
   305                     {
       
   306                     TFLOGSTRING("TSY:CSatMoSmsCtrl::UiccCatRespEnvelopeReceived, atkData.Length()=0 ");
       
   307                     OstTrace0( TRACE_NORMAL, DUP6_CSATMOSMSCTRL_ATKSWDATANTFRECEIVED, "CSatMoSmsCtrl::UiccCatRespEnvelopeReceived, atkData.Length()=0" );
       
   308                     TUint8 resourceStatus( SMS_RESOURCE_ALLOWED );
       
   309                     FormSmsResourceReqSb( resourceStatus, dataResp, addr1, addr2 );
       
   310                     }// end of block with data length zero
       
   311 
       
   312                 // If AlphaID is present, the client SatServer
       
   313                 // must be notified in order to inform it that the ETel
       
   314                 // API MO-SMS Control structure TMoSmControlV1 has been modified.
       
   315                 if ( alphaId.iAlphaId.Length() || isAlphaIdEmpty )
       
   316                     {
       
   317                     // Inform client
       
   318                     // Control result must be mapped to ETel API values.
       
   319                     TUint8 controlResult;
       
   320                     switch ( apduData[0] )
       
   321                         {
       
   322                         case KSmControlAllowed:
       
   323                             {
       
   324                             controlResult = RSat::EAllowedNoModification;
       
   325                             break;
       
   326                             }
       
   327                         case KSmControlAllowedWithModif:
       
   328                             {
       
   329                             controlResult = RSat::EAllowedWithModifications;
       
   330                             break;
       
   331                             }
       
   332                         case KSmControlNotAllowed:
       
   333                             {
       
   334                             controlResult = RSat::ENotAllowed;
       
   335                             break;
       
   336                             }
       
   337                         default:
       
   338                             {
       
   339                             controlResult = RSat::EControlResultNotSet;
       
   340                             break;
       
   341                             }
       
   342                         }
       
   343                     iSatMessaging->NotifyClientAboutMoSmControlEvent(
       
   344                     alphaId.iAlphaId, (RSat::TControlResult) controlResult );
       
   345                     }
       
   346                 }
       
   347             }
       
   348         else // else for UICC status not ok
       
   349             {
       
   350             TFLOGSTRING("TSY:CSatMoSmsCtrl::UiccCatRespEnvelopeReceived, KAtkError = atkResult ");
       
   351             OstTrace0( TRACE_NORMAL, DUP7_CSATMOSMSCTRL_ATKSWDATANTFRECEIVED, "CSatMoSmsCtrl::UiccCatRespEnvelopeReceived, KAtkError = atkResult" );
       
   352             TUint8 resourceStatus = SMS_RESOURCE_DENIED;
       
   353             FormSmsResourceReqSb( resourceStatus, dataResp, addr1, addr2 );
       
   354             }
       
   355         } // end if if UICC status is ok
       
   356 
       
   357     // Send resp to Sms server
       
   358     return ( iSatMessHandler->SendSmsResourceReq(
       
   359         iMoSmsCtrlReqTransactionId,
       
   360         dataResp,
       
   361         iSenderObject ) );
       
   362     }
       
   363 
       
   364 
       
   365 // -----------------------------------------------------------------------------
       
   366 // CSatMoSmsCtrl::SmsResourceIndReceived
       
   367 // Request received from SMS server with the SMS parameters
       
   368 // of the SMS to be sent by the Mobile Equipment.
       
   369 // The response will tell whether the SMS can be sent
       
   370 // to network or not.
       
   371 // -----------------------------------------------------------------------------
       
   372 //
       
   373 void CSatMoSmsCtrl::SmsResourceIndReceived
       
   374         (
       
   375         const TIsiReceiveC& aIsiMessage //Received data notification
       
   376         )
       
   377     {
       
   378     OstTrace0( TRACE_NORMAL, CSATMOSMSCTRL_SMSRESOURCEINDRECEIVED, "CSatMoSmsCtrl::SmsResourceIndReceived" );
       
   379     TFLOGSTRING("TSY:CSatMoSmsCtrl::SmsResourceIndReceived");
       
   380 
       
   381     TBuf8<256> addressData1;
       
   382     TBuf8<256> addressData2;
       
   383 
       
   384     // Save the transaction id, which is going to
       
   385     // be re-used in the resp.
       
   386     iMoSmsCtrlReqTransactionId = aIsiMessage.Get8bit( ISI_HEADER_OFFSET_TRANSID );
       
   387 
       
   388     // Save the sender object id, in order to re-use it
       
   389     // in the response to this request
       
   390     iSenderObject = aIsiMessage.Get8bit( ISI_HEADER_OFFSET_SENDEROBJECT );
       
   391 
       
   392     // Save Sequence id to send it in request message
       
   393     iSequenceId = aIsiMessage.Get8bit( ISI_HEADER_SIZE+SIZE_SMS_RESOURCE_IND+
       
   394             SIZE_SMS_SB_RESOURCE+SMS_SB_RESOURCE_SEQ_ID_OFFSET_SEQUENCEID );
       
   395 
       
   396     // save resource id to send it in request mesage
       
   397     iResourceId = aIsiMessage.Get16bit( ISI_HEADER_SIZE+SIZE_SMS_RESOURCE_IND+
       
   398                                          SMS_SB_RESOURCE_OFFSET_RESOURCES );
       
   399 
       
   400 
       
   401      // Save Service Centre Address Subblock to send it in request message if server has
       
   402      //denied to access
       
   403      iAddressSubblock = aIsiMessage.GetData( ISI_HEADER_SIZE+SIZE_SMS_RESOURCE_IND+SIZE_SMS_SB_RESOURCE+
       
   404                     SIZE_SMS_SB_RESOURCE_SEQ_ID+SMS_SB_ADDRESS_OFFSET_ADDRESSDATA ,
       
   405                     aIsiMessage.Get8bit(ISI_HEADER_SIZE+SIZE_SMS_RESOURCE_IND+SIZE_SMS_SB_RESOURCE+SIZE_SMS_SB_RESOURCE_SEQ_ID+
       
   406                     SMS_SB_ADDRESS_OFFSET_ADDRESSDATALENGTH) );
       
   407 
       
   408      // Calculate Address Subblock length
       
   409      TUint8 addrSbLen = aIsiMessage.Get16bit( ISI_HEADER_SIZE+SIZE_SMS_RESOURCE_IND+SIZE_SMS_SB_RESOURCE+SIZE_SMS_SB_RESOURCE_SEQ_ID+
       
   410                                              SMS_SB_ADDRESS_OFFSET_SUBBLOCKLENGTH );
       
   411 
       
   412      // Save Destination address TPDU to send it in request message if server has
       
   413      // Denied the access for that address
       
   414      iUserDataSubblock = ( aIsiMessage.GetData( ISI_HEADER_SIZE+SIZE_SMS_RESOURCE_IND+SIZE_SMS_SB_RESOURCE+
       
   415                     SIZE_SMS_SB_RESOURCE_SEQ_ID+addrSbLen+
       
   416                     SMS_SB_TPDU_OFFSET_DATABYTES,
       
   417                     aIsiMessage.Get8bit( ISI_HEADER_SIZE+SIZE_SMS_RESOURCE_IND+SIZE_SMS_SB_RESOURCE+
       
   418                                  SIZE_SMS_SB_RESOURCE_SEQ_ID+addrSbLen+SMS_SB_TPDU_OFFSET_DATALENGTH )));
       
   419 
       
   420 
       
   421      //Check if location data is present. Otherwise response to SmsResourceInd
       
   422      //is always ALLOWED.
       
   423      if ( !iSatMessHandler->ServiceAvailable() )
       
   424          {
       
   425          TBuf8<KMaxLengthOfResourceReq> dataResp;
       
   426          TIsiSend resourceReq( dataResp );
       
   427 
       
   428          dataResp.AppendFill( KPadding, 1);       // filer byte
       
   429          dataResp.Append( 5 );                // no of Subblocks
       
   430 
       
   431          // Add first SB Resource Subblock
       
   432          TIsiSubBlock resource( dataResp, SMS_SB_RESOURCE ,
       
   433              EIsiSubBlockTypeId16Len16 );                      // Message ID and Subblock length
       
   434 
       
   435          dataResp.Append( iResourceId >> 8 );        // SMS Resource IDs MSB
       
   436 
       
   437          dataResp.Append( iResourceId );           // SMS resource IDs LSB
       
   438 
       
   439          dataResp.AppendFill( KPadding,2 );           // Filler Bytes
       
   440          resource.CompleteSubBlock();
       
   441 
       
   442          // Add 2nd resource sequence ID subblock
       
   443 
       
   444          TIsiSubBlock resourceSeqId( dataResp, SMS_SB_RESOURCE_SEQ_ID ,
       
   445              EIsiSubBlockTypeId16Len16 );
       
   446          dataResp.Append(iSequenceId);                // Sequence ID
       
   447          dataResp.AppendFill( KPadding, 3 );
       
   448          resourceSeqId.CompleteSubBlock();
       
   449 
       
   450 
       
   451          // Add Third subblock SMS_SB_RESOURCE_STATUS
       
   452 
       
   453          TIsiSubBlock resourceStatus( dataResp, SMS_SB_RESOURCE_STATUS ,
       
   454              EIsiSubBlockTypeId16Len16 );
       
   455          dataResp.Append( SMS_RESOURCE_ALLOWED );            // Resource status
       
   456          dataResp.AppendFill( KPadding, 3 );
       
   457          resourceStatus.CompleteSubBlock();
       
   458 
       
   459          // Add 4th subblock SMS_SB_ADDRESS (SMSC)
       
   460          TIsiSubBlock addressSb( dataResp, SMS_SB_ADDRESS ,
       
   461              EIsiSubBlockTypeId16Len16 );
       
   462          dataResp.Append( SMS_SMSC_ADDRESS );            // Addrees Type
       
   463          dataResp.Append( iAddressSubblock.Length() );
       
   464          dataResp.Append( iAddressSubblock );
       
   465 
       
   466          // Filler bytes calculation for SMSC address subblock
       
   467          TUint8 fillbytes = 0;
       
   468          while(( iAddressSubblock.Length()+ 6 + fillbytes )%4)
       
   469              {
       
   470              fillbytes++;
       
   471              }
       
   472 
       
   473          dataResp.AppendFill( KPadding,fillbytes );
       
   474          addressSb.CompleteSubBlock();
       
   475 
       
   476         // Add 5th Subblock SMS_SB_TPDU (Destination address)
       
   477 
       
   478          TIsiSubBlock userDataSb( dataResp, SMS_SB_TPDU ,
       
   479              EIsiSubBlockTypeId16Len16 );
       
   480          dataResp.Append( iUserDataSubblock.Length() );            // Addrees Length
       
   481          dataResp.Append( KPadding );
       
   482          dataResp.Append( iUserDataSubblock );
       
   483 
       
   484          // Filler bytes calculation for user data subblock
       
   485          fillbytes = 0;
       
   486          while(( iUserDataSubblock.Length()+ 6 + fillbytes )%4 )
       
   487              {
       
   488              fillbytes++;
       
   489              }
       
   490 
       
   491          dataResp.AppendFill( KPadding,fillbytes );
       
   492          userDataSb.CompleteSubBlock();
       
   493 
       
   494           TFLOGSTRING("TSY:CSatMoSmsCtrl::SmsResourceIndReceived: Not Allowed Condition, Send response to SMS server");
       
   495           OstTrace0( TRACE_NORMAL, DUP1_CSATMOSMSCTRL_SMSRESOURCEINDRECEIVED, "CSatMoSmsCtrl::SmsResourceIndReceived: Not Allowed conditon, Send response to SMS server" );
       
   496 
       
   497           // Send Req to Sms server with allowed status
       
   498           iSatMessHandler->SendSmsResourceReq(
       
   499               iMoSmsCtrlReqTransactionId,
       
   500               dataResp,
       
   501               iSenderObject );
       
   502          }
       
   503      else
       
   504          {
       
   505         if( iIsMoSmsCtrlActivated )    // Check is MO SMS is activated or not
       
   506             {
       
   507             TDes8* addressData = NULL;
       
   508             if(SMS_SB_ADDRESS == aIsiMessage.Get16bit( ISI_HEADER_SIZE+SIZE_SMS_RESOURCE_IND+SIZE_SMS_SB_RESOURCE+
       
   509                     SIZE_SMS_SB_RESOURCE_SEQ_ID+SMS_SB_ADDRESS_OFFSET_SUBBLOCKID ))
       
   510                 {
       
   511                 addressData = &addressData1;
       
   512 
       
   513                 TPtrC8 phoneNumber = aIsiMessage.GetData( ISI_HEADER_SIZE+SIZE_SMS_RESOURCE_IND+SIZE_SMS_SB_RESOURCE+
       
   514                         SIZE_SMS_SB_RESOURCE_SEQ_ID+SMS_SB_ADDRESS_OFFSET_ADDRESSDATA,
       
   515                         aIsiMessage.Get8bit( ISI_HEADER_SIZE+SIZE_SMS_RESOURCE_IND+SIZE_SMS_SB_RESOURCE+
       
   516                         SIZE_SMS_SB_RESOURCE_SEQ_ID+SMS_SB_ADDRESS_OFFSET_ADDRESSDATALENGTH ) );
       
   517 
       
   518                 addressData->Append( phoneNumber.Mid( 0, phoneNumber.Length()) );
       
   519 
       
   520                 }
       
   521             if(SMS_SB_TPDU == aIsiMessage.Get16bit( ISI_HEADER_SIZE+SIZE_SMS_RESOURCE_IND+SIZE_SMS_SB_RESOURCE
       
   522                     +SIZE_SMS_SB_RESOURCE_SEQ_ID+addrSbLen+SMS_SB_TPDU_OFFSET_SUBBLOCKID ))
       
   523                 {
       
   524                 addressData =&addressData2;
       
   525 
       
   526                 // check for message type
       
   527                 // Whether its a command type message or Submit type
       
   528 
       
   529                 if(KSmsCommandType == ( iUserDataSubblock[0]& 0x03 ))
       
   530                     {
       
   531                     iMessageType = KSmsCommandType;
       
   532                     TPtrC8 phoneNumber = &iUserDataSubblock[5];
       
   533 
       
   534                     // Addition of two for Type of number semi octet
       
   535                     addressData->Append( phoneNumber.Mid( 1, (iUserDataSubblock[5]/2)+1 ));
       
   536                     }
       
   537                 else if( KSmsSubmitType == ( iUserDataSubblock[0] & 0x03 ))
       
   538                     {
       
   539                     iMessageType = KSmsSubmitType;
       
   540                     TPtrC8 phoneNumber = &iUserDataSubblock[2];
       
   541                     // Addition of two for Type of number semi octet
       
   542                     addressData->Append( phoneNumber.Mid( 1, (iUserDataSubblock[2]/2)+1 ));
       
   543                     }
       
   544                 }
       
   545             // Dialled Number String, the length has to be removed (first byte)
       
   546 
       
   547         iMoSmsCtrlEnvelopeTransactionId = iSatMessaging->GetTransactionId();
       
   548 
       
   549             TFLOGSTRING("TSY:CSatMoSmsCtrl::SmsResourceIndReceived, Send envelope");
       
   550             OstTrace0( TRACE_NORMAL, DUP3_CSATMOSMSCTRL_SMSRESOURCEINDRECEIVED, "CSatMoSmsCtrl::SmsResourceIndReceived, Send envelope" );
       
   551 
       
   552             // The envelope is sent if MO SMS is activated
       
   553             SendMoSmsCtrlEnvelope(
       
   554                 iMoSmsCtrlEnvelopeTransactionId,
       
   555                 addressData1,
       
   556                 addressData2
       
   557                 );
       
   558        }
       
   559         else        // If MO SMS is not activated
       
   560             {
       
   561             TBuf8<KMaxLengthOfResourceReq> dataResp;
       
   562             TIsiSend resourceReq( dataResp );
       
   563 
       
   564             dataResp.AppendFill( KPadding, 1 );       // filer byte
       
   565             dataResp.Append( 4 );                // no of Subblocks
       
   566 
       
   567             // Add first SB Resource Subblock
       
   568             TIsiSubBlock resource( dataResp, SMS_SB_RESOURCE ,
       
   569                 EIsiSubBlockTypeId16Len16 );          // Message ID and Subblock length
       
   570 
       
   571             dataResp.Append( iResourceId >> 8 );        // SMS Resource IDs MSB
       
   572 
       
   573             dataResp.Append( iResourceId );             // SMS resource IDs LSB
       
   574 
       
   575             dataResp.AppendFill( KPadding, 2 );         // Filler Bytes
       
   576             resource.CompleteSubBlock();
       
   577 
       
   578             // Add 2nd resource sequence ID subblock
       
   579 
       
   580             TIsiSubBlock resourceSeqId( dataResp, SMS_SB_RESOURCE_SEQ_ID ,
       
   581                 EIsiSubBlockTypeId16Len16 );
       
   582             dataResp.Append( iSequenceId );              // Sequence ID
       
   583             dataResp.AppendFill( KPadding, 3 );
       
   584             resourceSeqId.CompleteSubBlock();
       
   585 
       
   586             // Add Third subblock
       
   587 
       
   588             TIsiSubBlock resourceStatus( dataResp, SMS_SB_RESOURCE_STATUS ,
       
   589                 EIsiSubBlockTypeId16Len16 );
       
   590             dataResp.Append( SMS_RESOURCE_DENIED );      // Resource status
       
   591             dataResp.AppendFill( KPadding, 3 );
       
   592             resourceStatus.CompleteSubBlock();
       
   593 
       
   594             // No address and User data Subblocks because Here resource ID is not the activated
       
   595 
       
   596             // Add cause subblock
       
   597 
       
   598             TIsiSubBlock sbCause( dataResp,SMS_SB_CAUSE,
       
   599                     EIsiSubBlockTypeId16Len16 );
       
   600 
       
   601             dataResp.Append( SMS_CAUSE_TYPE_COMMON );
       
   602             dataResp.Append( SMS_ERR_ROUTE_NOT_ALLOWED );
       
   603             dataResp.Append( KPadding, 2 );
       
   604 
       
   605             // Send resp to Sms server with not allowed status
       
   606             iSatMessHandler->SendSmsResourceReq(
       
   607                 iMoSmsCtrlReqTransactionId,
       
   608                 dataResp,
       
   609                 iSenderObject );
       
   610 
       
   611             }
       
   612         }
       
   613 
       
   614     }
       
   615 
       
   616 // -----------------------------------------------------------------------------
       
   617 // CSatMoSmsCtrl::SendMoSmsCtrlEnvelope
       
   618 // Send an envelope to SIM server in order to check wheter the SMS
       
   619 // can be sent or not. The response will be used to send a response
       
   620 // to SMS server
       
   621 // -----------------------------------------------------------------------------
       
   622 //
       
   623 void CSatMoSmsCtrl::SendMoSmsCtrlEnvelope
       
   624         (
       
   625         TUint8 aTraId,
       
   626         TDes8& aAddressData1,
       
   627         TDes8& aAddressData2
       
   628         )
       
   629     {
       
   630     OstTrace0( TRACE_NORMAL, CSATMOSMSCTRL_SENDMOSMSCTRLENVELOPE, "CSatMoSmsCtrl::SendMoSmsCtrlEnvelope" );
       
   631     TFLOGSTRING("TSY:CSatMoSmsCtrl::SendMoSmsCtrlEnvelope");
       
   632 
       
   633     // Get location info
       
   634     const CSatMessHandler::TLocationInfo& locInfo
       
   635         = iSatMessHandler->LocationInfo();
       
   636 
       
   637     // A SwDataNtf is expected later
       
   638     iWaitingForEnvelopeResp = ETrue;
       
   639 
       
   640     TTlv envelope;
       
   641 
       
   642     envelope.Begin( KBerTlvMoShortMessageControlTag );
       
   643     //device identities
       
   644     envelope.AddTag( KTlvDeviceIdentityTag );
       
   645     envelope.AddByte( KMe );
       
   646     envelope.AddByte( KSim );
       
   647     // Address Data object 1
       
   648     // Ton and Npi is in the first byte of address data
       
   649     envelope.AddTag( KTlvAddressTag );
       
   650     envelope.AddData( aAddressData1 );
       
   651     // Address Data object 2
       
   652     // Ton and Npi is in the first byte of address data
       
   653     envelope.AddTag( KTlvAddressTag );
       
   654     envelope.AddData( aAddressData2 );
       
   655     // Location info
       
   656     envelope.AddTag(KTlvLocationInformationTag);
       
   657 
       
   658     // This part assumes that location info (NetCellInfoInd)
       
   659     // has been received
       
   660     // Mobile Country & Network Codes (MCC & MNC)
       
   661     envelope.AddData( locInfo.iOperatorCode );
       
   662     // Location Area Code (LAC)
       
   663     envelope.AddData( locInfo.iLac );
       
   664     // Cell Id
       
   665     envelope.AddData( locInfo.iCellId );
       
   666 
       
   667 
       
   668     // Send envelope only if its length is less than the maximum allowed
       
   669     // envelope length.
       
   670 
       
   671     iSatMessHandler->UiccCatReqEnvelope( aTraId, envelope.End() );
       
   672 
       
   673     }
       
   674 
       
   675 // -----------------------------------------------------------------------------
       
   676 // CSatMoSmsCtrl::ParseAtkSwDataNtf
       
   677 // Extracts data from AtkSwDataNtf message data part.
       
   678 // -----------------------------------------------------------------------------
       
   679 //
       
   680 void CSatMoSmsCtrl::ParseAtkSwDataNtf
       
   681         (
       
   682         TPtrC8& aAtkData,
       
   683         TDes8& aAddr1,
       
   684         TDes8& aAddr2,
       
   685         RSat::TAlphaId& aAlphaId,
       
   686         TBool& aEmptyAlphaId
       
   687         )
       
   688     {
       
   689     OstTrace0( TRACE_NORMAL, CSATMOSMSCTRL_PARSEATKSWDATANTF, "CSatMoSmsCtrl::ParseAtkSwDataNtf" );
       
   690     TFLOGSTRING("TSY:CSatMoSmsCtrl::ParseAtkSwDataNtf");
       
   691 
       
   692     // Input data:
       
   693     // aAtkData[0] : result
       
   694     // aAtkData[1][2] : length of BER-TLV, set n=1 if aAtkData[1]=0x81
       
   695     // aAtkData[2+n] : tag of first TLV
       
   696     // aAtkData[3+n][4+n] : length of first TLV, set nn=1 if aAtkData[3+n]=0x81
       
   697     // etc..
       
   698 
       
   699     // Comments drawn from SAT TS lab test cases:
       
   700     // - The SIM may insert a wild '0xD' character in addresses and therefore
       
   701     // the phone sw should prevent the sending of the SMS. At the time when this
       
   702     // comment is being written, it is not clear which part prevents it, and does
       
   703     // it really prevent it ? And this is not yet handled in SimAtkTsy.
       
   704     // - The SIM may insert a 0xF in addresses, and the phone sw should discard
       
   705     // all characters placed after the 0xF. At the time when this
       
   706     // comment is being written, it is not clear which part should do that,
       
   707     // and this is not yet handled in SimAtkTsy.
       
   708 
       
   709     // Check if the BER-TLV length is coded with 2 bytes.
       
   710     TInt indexInBerTlv( 1 );
       
   711     TUint8 tag( aAtkData[indexInBerTlv] );
       
   712     TUint8 lengthBerTlv( 0 );
       
   713     TInt n( (KTwoByteLengthCoding == tag)?1:0 );
       
   714     lengthBerTlv = aAtkData[1 + n];
       
   715     indexInBerTlv = 2 + n;
       
   716 
       
   717     // Extract TLVs and fill in output variables
       
   718     TBool address1_got( EFalse );
       
   719     while( lengthBerTlv )
       
   720         {
       
   721         // Get tag value without 'comprehension required' bit
       
   722         tag = aAtkData[indexInBerTlv]&0x7F;
       
   723         // Length of TLV with 2 bytes ?
       
   724         TInt nn( ( KTwoByteLengthCoding == aAtkData[indexInBerTlv+1] )?1:0 );
       
   725         // Length of TLV
       
   726         TInt lengthTlv( aAtkData[indexInBerTlv+nn+1] );
       
   727         // Check what TLV is received
       
   728         if ( ( KTlvAddressTag == tag )
       
   729             && ( !address1_got ) )
       
   730             {
       
   731             // RP address first
       
   732             address1_got = ETrue;
       
   733             // Copy data to output variable
       
   734             aAddr1.Copy( aAtkData.Mid( indexInBerTlv + nn + 2,
       
   735                 lengthTlv ) );
       
   736             if ( (1<lengthTlv) &&
       
   737                  KReservedTonNpi1!=aAddr1[0] && KReservedTonNpi2!=aAddr1[0] )
       
   738                 {
       
   739                 CleanAddressData( aAddr1 );
       
   740                 }
       
   741             }
       
   742         else if ( KTlvAddressTag == tag )
       
   743             {
       
   744             // TP address
       
   745             // Copy data to output variable
       
   746             aAddr2.Copy( aAtkData.Mid( indexInBerTlv + nn + 2,
       
   747                 lengthTlv ) );
       
   748             if ( (1<lengthTlv) &&
       
   749                  KReservedTonNpi1!=aAddr2[0] && KReservedTonNpi2!=aAddr2[0] )
       
   750                 {
       
   751                 CleanAddressData( aAddr2 );
       
   752                 }
       
   753             }
       
   754         else if ( KTlvAlphaIdentifierTag == tag )
       
   755             {
       
   756             // Alpha Id
       
   757             // Alpha id must be converted to TBuf16/unicode
       
   758             if ( lengthTlv )
       
   759                 {
       
   760                 TSatUtility::SetAlphaId( aAtkData.Mid( indexInBerTlv + nn + 2,
       
   761                     lengthTlv ), aAlphaId.iAlphaId );
       
   762                 }
       
   763             else
       
   764                 {
       
   765                 aEmptyAlphaId = ETrue;
       
   766                 }
       
   767 
       
   768             }
       
   769         else
       
   770             {
       
   771             TFLOGSTRING("TSY: CSatMoSmsCtrl::ParseAtkSwDataNtf, Tlv tag was not address/alpha id tag.");
       
   772             OstTrace0( TRACE_NORMAL, DUP1_CSATMOSMSCTRL_PARSEATKSWDATANTF, "CSatMoSmsCtrl::ParseAtkSwDataNtf, Tlv tag was not address/alpha id tag." );
       
   773 
       
   774             }
       
   775 
       
   776         // update length for the while loop
       
   777         lengthBerTlv -= ( lengthTlv+2+nn );
       
   778         // updata index for the while loop
       
   779         indexInBerTlv += ( lengthTlv+2+nn );
       
   780         }
       
   781     }
       
   782 
       
   783 // -----------------------------------------------------------------------------
       
   784 // CSatMoSmsCtrl::CleanAddressData
       
   785 // This method cleans the input address data, so that all the bytes found
       
   786 // after a 0xXF or a 0xFX are removed.
       
   787 // -----------------------------------------------------------------------------
       
   788 //
       
   789 void CSatMoSmsCtrl::CleanAddressData
       
   790         (
       
   791         TDes8& aAddr
       
   792         )
       
   793     {
       
   794     OstTrace0( TRACE_NORMAL, CSATMOSMSCTRL_CLEANADDRESSDATA, "CSatMoSmsCtrl::CleanAddressData" );
       
   795     TFLOGSTRING("TSY: CSatMoSmsCtrl::CleanAddressData");
       
   796     // Starts from index 1, since index 0 is for TON/NPI
       
   797     for ( TInt i=1; i < aAddr.Length(); i++ )
       
   798         {
       
   799         if ( 0xF0==(aAddr[i]&0xF0) )
       
   800             {
       
   801             if ( ( i+1 ) < aAddr.Length() )
       
   802                 {
       
   803                 aAddr.Delete( i+1, aAddr.Length() - i - 1 );
       
   804                 }
       
   805             break;
       
   806             }
       
   807         else if ( 0x0F==(aAddr[i]&0x0F) )
       
   808             {
       
   809             aAddr.Delete( i, aAddr.Length() - i );
       
   810             break;
       
   811             }
       
   812         }
       
   813 
       
   814     }
       
   815 
       
   816 // -----------------------------------------------------------------------------
       
   817 // CSatMoSmsCtrl::VerifySimRespData
       
   818 // This method checks the consistency of the data sent by the SIM to the ME,
       
   819 // when the call is allowed and modified.
       
   820 // -----------------------------------------------------------------------------
       
   821 //
       
   822 TBool CSatMoSmsCtrl::VerifySimRespData
       
   823         (
       
   824         TDes8& aRPAddr,
       
   825         TDes8& aTPAddr
       
   826         )
       
   827     {
       
   828     OstTrace0( TRACE_NORMAL, CSATMOSMSCTRL_VERIFYSIMRESPDATA, "CSatMoSmsCtrl::VerifySimRespData" );
       
   829     TBool ret( ETrue );
       
   830     if ( ( 0==aRPAddr.Length() && 0==aTPAddr.Length() )
       
   831        || ( KMaxLengthAddr1Addr2 <= ( aRPAddr.Length()+aTPAddr.Length() ) )
       
   832        )
       
   833         {
       
   834         ret = EFalse;
       
   835         }
       
   836     else
       
   837         {
       
   838         // detect the presence of 'wild' values in the digits of the addresses
       
   839         for ( TInt i=0; i<aRPAddr.Length(); i++)
       
   840             {
       
   841             if ( ( 0xA<(0x0F&aRPAddr[i]) && 0xF>(0x0F&aRPAddr[i]) )
       
   842                ||( 0xA0<(0xF0&aRPAddr[i]) && 0xF0>(0xF0&aRPAddr[i]) ) )
       
   843                 {
       
   844                 ret = EFalse;
       
   845                 break;
       
   846                 }
       
   847             }
       
   848         for ( TInt i=0; i<aTPAddr.Length(); i++)
       
   849             {
       
   850             if ( ( 0x9<(0x0F&aTPAddr[i]) && 0xF>(0x0F&aTPAddr[i]) )
       
   851                ||( 0x90<(0xF0&aTPAddr[i]) && 0xF0>(0xF0&aTPAddr[i]) ) )
       
   852                 {
       
   853                 ret = EFalse;
       
   854                 break;
       
   855                 }
       
   856             }
       
   857         }
       
   858     return ret;
       
   859     }
       
   860 
       
   861 // -----------------------------------------------------------------------------
       
   862 // CSatMoSmsCtrl::FormSmsResourceReqSb
       
   863 // Form subblock of SMS_RESOURCE_REQ
       
   864 // -----------------------------------------------------------------------------
       
   865 //
       
   866 
       
   867 void CSatMoSmsCtrl::FormSmsResourceReqSb
       
   868        (const TUint8 status,
       
   869         TDes8& data,
       
   870         const TDes8& address1,
       
   871         const TDes8& address2
       
   872         )
       
   873     {
       
   874     // First three mandatory subblocks
       
   875     TIsiSubBlock resource( data, SMS_SB_RESOURCE ,
       
   876         EIsiSubBlockTypeId16Len16 );    // Message ID and Subblock length
       
   877     data.Append( iResourceId >> 8 );      // SMS resource IDs MSB same as received in indication
       
   878     data.Append( iResourceId );           // SMS resource IDs LSB
       
   879     data.AppendFill( KPadding, 2 );       // Filler Bytes
       
   880     resource.CompleteSubBlock();
       
   881 
       
   882     // Add Sequence ID subblock
       
   883 
       
   884     TIsiSubBlock resourceSeqId( data, SMS_SB_RESOURCE_SEQ_ID ,
       
   885         EIsiSubBlockTypeId16Len16 );
       
   886     data.Append( iSequenceId );           // Sequence ID same as received in indication message
       
   887     data.AppendFill( KPadding, 3 );
       
   888     resourceSeqId.CompleteSubBlock();
       
   889 
       
   890     // Add Resource Status subblock
       
   891 
       
   892     TIsiSubBlock resourceStatus( data, SMS_SB_RESOURCE_STATUS ,
       
   893         EIsiSubBlockTypeId16Len16 );
       
   894     data.Append( status );                // Resource status
       
   895     data.AppendFill( KPadding, 3 );
       
   896     resourceStatus.CompleteSubBlock();
       
   897 
       
   898     if(iIsMoSmsCtrlActivated)
       
   899         {
       
   900 
       
   901             //Resource is disallowed   ||    Resource is allowed without modification
       
   902         if((SMS_RESOURCE_ALLOWED != status)||(0 == address1.Length()))
       
   903               {
       
   904               // Increment subblock
       
   905               data[1]++;
       
   906               // Copy address subblocks from Indication message
       
   907               // Add Address Subblock
       
   908               TIsiSubBlock address( data, SMS_SB_ADDRESS ,
       
   909               EIsiSubBlockTypeId16Len16 );
       
   910               data.Append( SMS_SMSC_ADDRESS );            // Address type
       
   911               data.Append( iAddressSubblock.Length() );     // Address data length
       
   912               data.Append( iAddressSubblock );
       
   913               // Filler Bytes calculation
       
   914               TUint8 fillbytes = 0;
       
   915               if((6 + iAddressSubblock.Length())%4)
       
   916                   fillbytes = 4 - (( 6 + iAddressSubblock.Length())%4 );
       
   917 
       
   918               data.AppendFill( KPadding,fillbytes );
       
   919               address.CompleteSubBlock();
       
   920 
       
   921               // increment subblock
       
   922               data[1]++;
       
   923               // Add User Data Subblock
       
   924               TIsiSubBlock userData( data, SMS_SB_TPDU ,
       
   925                   EIsiSubBlockTypeId16Len16 );
       
   926               data.Append( iUserDataSubblock.Length() );        // data Length
       
   927               data.Append( KPadding );        // Filler Byte
       
   928               data.Append( iUserDataSubblock ); // Data Bytes
       
   929 
       
   930               // Filler Bytes calculation
       
   931               fillbytes = 0;
       
   932               if((6 + iUserDataSubblock.Length())%4)
       
   933                   fillbytes = 4-(( 6 + iUserDataSubblock.Length())%4 );
       
   934 
       
   935               data.AppendFill( KPadding,fillbytes );
       
   936               userData.CompleteSubBlock();
       
   937 
       
   938               }
       
   939         else
       
   940               {
       
   941               // when resource is allowed with modification
       
   942               // then copy SIM data in address subblock
       
   943               TUint8 fillBytes = 0;
       
   944               if ( address1.Length() )
       
   945                   {
       
   946                   // Add Address subblock
       
   947                   data[1]++;          // increase no of subblocks
       
   948 
       
   949                   TIsiSubBlock address( data, SMS_SB_ADDRESS ,
       
   950                       EIsiSubBlockTypeId16Len16 );
       
   951                   data.Append(SMS_SMSC_ADDRESS);            // Address Type
       
   952 
       
   953                   // Calculate needed number of filler bytes
       
   954                   while ( ( fillBytes + 6 + address1.Length() ) % 4 )
       
   955                       {
       
   956                       fillBytes++;
       
   957                       }
       
   958                   // Data in bytes
       
   959                   // First byte is the address length in 3GPP, GSM_0411 format
       
   960                   // "data length in bytes, including TON & NPI"
       
   961                   data.Append( address1.Length() );
       
   962                   // Actual address data
       
   963                   data.Append( address1 );
       
   964                   // Filler bytes
       
   965                   data.AppendFill( KPadding, fillBytes );
       
   966 
       
   967                   address.CompleteSubBlock();
       
   968                   }       // end of Service centre Address Subblock
       
   969 
       
   970                   // Add subblock for Address2 (Destination address, TP) if present
       
   971                   if ( address2.Length() )
       
   972                       {
       
   973                       // Add subblock
       
   974                       data[1]++;
       
   975 
       
   976                       // For User Data Subblock
       
   977                       TIsiSubBlock userDataSb( data, SMS_SB_TPDU,
       
   978                           EIsiSubBlockTypeId16Len16 );
       
   979 
       
   980                       // Calculate needed number of filler bytes
       
   981                       fillBytes = 0;
       
   982                       while ( ( fillBytes + 6 + address2.Length() ) % 4 )
       
   983                           {
       
   984                           fillBytes++;
       
   985                           }
       
   986 
       
   987                       data.Append( fillBytes + 6 + address2.Length() );        // Data length
       
   988                       data.Append( KPadding );                  // Filler Byte
       
   989 
       
   990                       // Check what type of TPDU to be sent
       
   991                       switch( iMessageType )
       
   992                           {
       
   993                           case KSmsCommandType:
       
   994                               {
       
   995                               // Data in bytes
       
   996                               // First byte is the address length in 3GPP, GSM_0340 format
       
   997                               // "number of useful semioctets ( = digits ), excluding TON & NPI "
       
   998 
       
   999                               if ( 1 == address2.Length() ||
       
  1000                                  ( 1 < address2.Length() &&
       
  1001                                  ( KReservedTonNpi1 == address2[0]
       
  1002                                    || KReservedTonNpi2 == address2[0] ) )
       
  1003                                  )
       
  1004                                   {
       
  1005                                   // Only Ton&Npi is present
       
  1006                                   // or TON&NPI has a reserved value
       
  1007                                   iUserDataSubblock[6] = 0x00;
       
  1008                                   }
       
  1009                               else if ( 0xF0 == ( address2[address2.Length() - 1] & 0xF0 ) )
       
  1010                                   {
       
  1011                                   // Odd length destination address
       
  1012                                   // Destination address length ( in semioctets )
       
  1013                                   iUserDataSubblock[5] = ( ( address2.Length() * 2 ) - 1 );
       
  1014                                   }
       
  1015                               else
       
  1016                                   {
       
  1017                                   // Even length destination address
       
  1018                                   iUserDataSubblock[5] = ( address2.Length() * 2 );
       
  1019                                   }
       
  1020 
       
  1021 
       
  1022                               for( TUint8 i = 0; i < address2.Length(); i++)
       
  1023                                   {
       
  1024                                   iUserDataSubblock[i+6] = address2[i];
       
  1025                                   }
       
  1026                            break;
       
  1027                               }
       
  1028                           case KSmsSubmitType:
       
  1029                               {
       
  1030                                // Data in bytes
       
  1031                                // First byte is the address length in 3GPP, GSM_0340 format
       
  1032                                // "number of useful semioctets ( = digits ), excluding TON & NPI "
       
  1033                                if ( 1 == address2.Length() ||
       
  1034                                   ( 1 < address2.Length() &&
       
  1035                                   ( KReservedTonNpi1 == address2[0]
       
  1036                                   || KReservedTonNpi2 == address2[0] ) )
       
  1037                                   )
       
  1038                                    {
       
  1039                                    // Only Ton&Npi is present
       
  1040                                    // or TON6NPI has a reserved value
       
  1041                                    iUserDataSubblock[3] = 0x00;
       
  1042                                    }
       
  1043                                else if ( 0xF0 == ( address2[address2.Length() - 1] & 0xF0 ) )
       
  1044                                        {
       
  1045                                        // Odd length destination address
       
  1046                                        // Destination address lenght ( in semioctets )
       
  1047                                        iUserDataSubblock[2] = ( ( address2.Length() * 2 ) - 1 );
       
  1048                                        }
       
  1049                                     else
       
  1050                                        {
       
  1051                                        // Even length destination address
       
  1052                                        iUserDataSubblock[2] = ( address2.Length() * 2 );
       
  1053                                        }
       
  1054                                for(TUint8 i = 0; i<address2.Length(); i++)
       
  1055                                {
       
  1056                                     iUserDataSubblock[i+3] = address2[i];
       
  1057                                }
       
  1058                                break;
       
  1059                               }
       
  1060                           default:
       
  1061                               {
       
  1062                               break;
       
  1063                               }
       
  1064                           }
       
  1065                       data.Append(iUserDataSubblock);
       
  1066 
       
  1067                       userDataSb.CompleteSubBlock();
       
  1068                       }
       
  1069               }
       
  1070         if( SMS_RESOURCE_DENIED == status )
       
  1071             {
       
  1072             // Add SMS_SB_CAUSE subblock
       
  1073             data[1]++;           //Increment no of subblocks
       
  1074             TIsiSubBlock cause( data, SMS_SB_CAUSE ,
       
  1075             EIsiSubBlockTypeId16Len16 );
       
  1076             data.Append( SMS_CAUSE_TYPE_COMMON );            // Cause type
       
  1077             data.Append( SMS_ERR_ROUTE_NOT_ALLOWED );    // Cause
       
  1078             data.AppendFill( KPadding, 2 );
       
  1079             cause.CompleteSubBlock();
       
  1080             }
       
  1081         }
       
  1082     }
       
  1083 // -----------------------------------------------------------------------------
       
  1084 // CSatMoSmsCtrl::MessageReceived
       
  1085 // Handle received messages related to MO-SMS Control
       
  1086 // -----------------------------------------------------------------------------
       
  1087 //
       
  1088 TInt CSatMoSmsCtrl::MessageReceived
       
  1089         (
       
  1090         const TIsiReceiveC& aIsiMessage
       
  1091         )
       
  1092     {
       
  1093     OstTrace0( TRACE_NORMAL, CSATMOSMSCTRL_MESSAGERECEIVED, "CSatMoSmsCtrl::MessageReceived" );
       
  1094     TFLOGSTRING("TSY: CSatMoSmsCtrl::MessageReceived");
       
  1095     // SMS server -> SimAtkTsy  : MO-SMS request sent to SAT (KSmsResourceReq)
       
  1096     // UICC server <- SimAtkTsy  : Envelope sent to UICC server (KAtkEnvelopeNtf)
       
  1097     // UICC server -> SimAtkTsy  : AtkSwNtf send to SAT, with modified (or not)
       
  1098     //                            addresses and parameters  (KAtkSwDataNtf)
       
  1099     // SMS server <- SimAtkTsy  : SAT sends final decision to SMS server
       
  1100     //                            with modified (or not) addresses and parameters
       
  1101     //                            (KSmsResourceResp)
       
  1102 
       
  1103     // Note: When SendSms proactive command is issued, and MO-SMS control
       
  1104     // does not allow sending the SMS, then a terminal response with general result
       
  1105     // "interaction with call control by SIM or MO short message control by SIM,
       
  1106     // action not allowed".
       
  1107     TUint8 resource = aIsiMessage.Get8bit( ISI_HEADER_OFFSET_RESOURCEID );
       
  1108 
       
  1109     if ( PN_SMS == resource )
       
  1110         {
       
  1111         switch ( aIsiMessage.Get8bit( ISI_HEADER_OFFSET_MESSAGEID ) )
       
  1112             {
       
  1113             case SMS_RESOURCE_IND:
       
  1114                 {
       
  1115                 SmsResourceIndReceived( aIsiMessage );
       
  1116                 break;
       
  1117                 }
       
  1118             case SMS_RESOURCE_RESP:
       
  1119                 {
       
  1120                 // Take a log
       
  1121                 TFLOGSTRING("TSY:CSatMoSmsCtrl::SmsResourceRespReceived: Response for Resource Req, Receive response from SMS server");
       
  1122                 OstTrace0( TRACE_NORMAL, DUP1_CSATMOSMSCTRL_SMSRESOURCERESPRECEIVED, "CSatMoSmsCtrl::SmsResourceRespReceived: Response for Resource Req, Receive response from SMS server" );
       
  1123 
       
  1124                 break;
       
  1125                 }
       
  1126             default:
       
  1127                 {
       
  1128                 // none
       
  1129                 break;
       
  1130                 }
       
  1131             }
       
  1132         }
       
  1133     else if ( PN_UICC == resource )
       
  1134         {
       
  1135         switch( aIsiMessage.Get8bit( ISI_HEADER_OFFSET_MESSAGEID ) )
       
  1136             {
       
  1137             case UICC_CAT_RESP:
       
  1138                 {
       
  1139                 // In case of envelope response handle the data
       
  1140                 TUint8 serviceType(
       
  1141                     aIsiMessage.Get8bit(
       
  1142                         ISI_HEADER_SIZE + UICC_CAT_RESP_OFFSET_SERVICETYPE ) );
       
  1143                 if ( UICC_CAT_ENVELOPE == serviceType )
       
  1144                     {
       
  1145                     if ( iWaitingForEnvelopeResp &&
       
  1146                          ( iMoSmsCtrlEnvelopeTransactionId ==
       
  1147                             aIsiMessage.Get8bit( ISI_HEADER_OFFSET_TRANSID ) ) )
       
  1148                         {
       
  1149                         // Set flag iWaitingForEnvelopeResp false
       
  1150                         // since a response is received for the envelope
       
  1151                         // that was sent for a received sms-pp message
       
  1152                         iWaitingForEnvelopeResp = EFalse;
       
  1153                         UiccCatRespEnvelopeReceived( aIsiMessage );
       
  1154                         }
       
  1155                     }
       
  1156                 break;
       
  1157                 }
       
  1158             default:
       
  1159                 {
       
  1160                 break;
       
  1161                 }
       
  1162             }
       
  1163         }
       
  1164     return KErrNone;
       
  1165     }
       
  1166 
       
  1167 // End of File