satengine/SatServer/Engine/src/CSatBIPGPRSDataChannel.cpp
changeset 0 ff3b6d0fd310
equal deleted inserted replaced
-1:000000000000 0:ff3b6d0fd310
       
     1 /*
       
     2 * Copyright (c) 2002-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 "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:  GPRS Data channel for BIP
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <etelqos.h>
       
    20 #include <cmmanager.h>
       
    21 #include <cmconnectionmethod.h>
       
    22 #include <cmpluginpacketdatadef.h>
       
    23 #include <cs_subconevents.h>                    // For subconnection events
       
    24 #include <networking/qos3gpp_subconparams.h>    // For extension parameters
       
    25 #include <e32std.h>                             // TRealFormat
       
    26 #include <e32cmn.h>
       
    27 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS
       
    28 #include <in_sock_internal.h>                   // For KSoUdpRecvBuf contant
       
    29 #endif
       
    30 #include "CSatBIPUtils.h"
       
    31 #include "CSatBIPGPRSDataChannel.h"
       
    32 #include "SatLog.h"
       
    33 #include "EnginePanic.h"
       
    34 #include "CSatBIPDataSender.h"
       
    35 #include "CSatBIPDataReceiver.h"
       
    36 #include "MSatSendDataObserver.h"
       
    37 #include "MSatConnectionObserver.h"
       
    38 #include "TSatChannelIDInfo.h"
       
    39 #include "TSatQoSParser.h"
       
    40 #include "csatbipsubconneventobserver.h"
       
    41 #include "csatsactivewrapper.h"
       
    42  
       
    43 // Required GPRS parameters
       
    44 const TUint8 KReqGprsQoSParams = 6;
       
    45 // Required packet protocol type is always 02 for GPRS -> IP Protocol
       
    46 const TUint8 KReqPacketProtType = 0x02;
       
    47 // Position of the protocol type in the array
       
    48 const TUint8 KProtocolPos = 5;
       
    49 // Lengths of IP address
       
    50 const TUint8 KIPv4Length = 4;
       
    51 const TUint8 KIPv6Length = 16;
       
    52 
       
    53 #ifdef SAT_USE_DUMMY_TSY
       
    54 const TUint8 KIpAddressSize( 15 );
       
    55 const TUint8 KIpv4Length( 4 );
       
    56 const TUint8 KIpv6Length( 16 );
       
    57 const TUint8 KIpAddressA( 0 );
       
    58 const TUint KIpAddressAValue( 127 );
       
    59 const TUint8 KIpAddressB( 1 );
       
    60 const TUint KIpAddressBValue( 0 );
       
    61 const TUint8 KIpAddressC( 2 );
       
    62 const TUint KIpAddressCValue( 0 );
       
    63 const TUint8 KIpAddressD( 3 );
       
    64 const TUint KIpAddressDValueDestination( 2 );
       
    65 const TUint KIpAddressDValueLocal( 3 );
       
    66 #endif
       
    67 
       
    68 #ifdef ENABLE_SAT_LOGGING
       
    69 const TUint8 KIpAddressLogSize( 40 );
       
    70 #endif
       
    71 
       
    72 const TInt KReCheckStatusDelay = 100000; // 100ms
       
    73 const TInt KMaxAttempts = 20;            // 20*100ms= 2s 
       
    74 // ======== MEMBER FUNCTIONS ========
       
    75 
       
    76 // ---------------------------------------------------------------------------
       
    77 // Two-phased constructor.
       
    78 // ---------------------------------------------------------------------------
       
    79 //
       
    80 CSatBIPGPRSDataChannel* CSatBIPGPRSDataChannel::NewL(
       
    81     CSatBIPUtils& aUtils,
       
    82     RSocketServ& aSocketServer,
       
    83     TSatChannelIdInfo& aChannelId,
       
    84     RConnection& aConnection,
       
    85     RSubConnection& aSubConnection )
       
    86     {
       
    87     LOG( SIMPLE, "SATENGINE: CSatBIPGPRSDataChannel::NewL calling" )
       
    88 
       
    89     CSatBIPGPRSDataChannel* self = new( ELeave ) CSatBIPGPRSDataChannel( 
       
    90         aUtils, aSocketServer, aChannelId, aConnection, aSubConnection );
       
    91 
       
    92     CleanupStack::PushL( self );
       
    93     self->ConstructL();
       
    94     CleanupStack::Pop( self );
       
    95 
       
    96     LOG( SIMPLE, "SATENGINE: CSatBIPGPRSDataChannel::NewL exiting" )
       
    97     return self;
       
    98     }
       
    99 
       
   100 // ---------------------------------------------------------------------------
       
   101 // Two-phased constructor.
       
   102 // ---------------------------------------------------------------------------
       
   103 //
       
   104 CSatBIPGPRSDataChannel* CSatBIPGPRSDataChannel::NewLC(
       
   105     CSatBIPUtils& aUtils,
       
   106     RSocketServ& aSocketServer,
       
   107     TSatChannelIdInfo& aChannelId,
       
   108     RConnection& aConnection,
       
   109     RSubConnection& aSubConnection )
       
   110     {
       
   111     LOG( SIMPLE, "SATENGINE: CSatBIPGPRSDataChannel::NewLC calling" )
       
   112 
       
   113     CSatBIPGPRSDataChannel* self = new ( ELeave ) CSatBIPGPRSDataChannel( 
       
   114         aUtils, aSocketServer, aChannelId, aConnection, aSubConnection );
       
   115 
       
   116     CleanupStack::PushL( self );
       
   117     self->ConstructL();
       
   118 
       
   119     LOG( SIMPLE, "SATENGINE: CSatBIPGPRSDataChannel::NewLC exiting" )
       
   120     return self;
       
   121     }
       
   122 
       
   123 // ---------------------------------------------------------------------------
       
   124 // destructor.
       
   125 // ---------------------------------------------------------------------------
       
   126 //
       
   127 CSatBIPGPRSDataChannel::~CSatBIPGPRSDataChannel()
       
   128     {
       
   129     LOG( SIMPLE,
       
   130          "SATENGINE: CSatBIPGPRSDataChannel::~CSatBIPGPRSDataChannel calling" )
       
   131 
       
   132     // Close sender
       
   133     delete iSender;
       
   134     
       
   135     // Close receiver
       
   136     delete iReceiver;
       
   137     
       
   138     // Close receiver
       
   139     delete iSubConnEventObserver;
       
   140     
       
   141     // Close Socket
       
   142     iSocket.Close();
       
   143     
       
   144     // Delete buffers
       
   145     delete iSendStore;
       
   146     iRcvBuffer.Zero();
       
   147     
       
   148     LOG( SIMPLE,
       
   149          "SATENGINE: CSatBIPGPRSDataChannel::~CSatBIPGPRSDataChannel exiting" )
       
   150     }
       
   151 
       
   152 // ---------------------------------------------------------------------------
       
   153 // Sets up connection
       
   154 // ---------------------------------------------------------------------------
       
   155 //
       
   156 void CSatBIPGPRSDataChannel::SetupConnectionL( 
       
   157     const TSatBipConnectionInfo& aConnParams )
       
   158     {
       
   159     LOG( SIMPLE, 
       
   160         "SATENGINE: CSatBIPGPRSDataChannel::SetupConnectionL calling" )
       
   161 
       
   162     // Allocate Send buffer
       
   163     iSendStore = HBufC8::NewL( aConnParams.iBufferSize );
       
   164 
       
   165     // Store the rest of connection information
       
   166     iConnInfo = aConnParams;
       
   167 
       
   168     // Define used protocol
       
   169     iUseTcpProtocol = ( RSat::ETcp == iConnInfo.iProtocol.iTransportProto );
       
   170 
       
   171     // Set connection stage
       
   172     iConnStage = ESatBIPClosed;
       
   173 
       
   174     LOG( SIMPLE, 
       
   175         "SATENGINE: CSatBIPGPRSDataChannel::SetupConnectionL exiting" )
       
   176     }
       
   177 
       
   178 // ---------------------------------------------------------------------------
       
   179 // Opens the connection
       
   180 // ---------------------------------------------------------------------------
       
   181 //
       
   182 void CSatBIPGPRSDataChannel::ActivateConnectionL(
       
   183     MSatConnectionObserver* aObserver )
       
   184     {
       
   185     LOG( SIMPLE,
       
   186         "SATENGINE: CSatBIPGPRSDataChannel::ActivateConnectionL calling" )
       
   187     
       
   188     TInt errCode( KErrNone );               // errCode
       
   189     RPacketQoS::TQoSGPRSNegotiated negQoS;  // The negotiated QoS
       
   190     
       
   191     // If the connection has not been setup or already connecting, leave
       
   192     if ( ESatBIPClosed != iConnStage )
       
   193         {
       
   194         LOG( SIMPLE,
       
   195         "SATENGINE: CSatBIPGPRSDataChannel::ActivateConnectionL \
       
   196         ESatBIPClosed != iConnStage" )
       
   197         User::Leave( KErrCancel );
       
   198         }
       
   199 
       
   200     iConnectionObserver = aObserver;
       
   201 
       
   202     if ( RSat::EIPv4Address == iConnInfo.iDestination.iType )
       
   203         {
       
   204         LOG( NORMAL, 
       
   205              "SATENGINE: CSatBIPGPRSDataChannel::ActivateConnectionL\
       
   206              Using IPv4" )
       
   207         }
       
   208     else if ( RSat::EIPv6Address == iConnInfo.iDestination.iType )
       
   209         {
       
   210         LOG( NORMAL, 
       
   211              "SATENGINE: CSatBIPGPRSDataChannel::ActivateConnectionL\
       
   212              Using IPv6" )
       
   213         }
       
   214     else
       
   215         {
       
   216         LOG( NORMAL, "  Unknown IP type" )
       
   217         User::Leave( KErrUnknown );
       
   218         }
       
   219     
       
   220     // Open connection if it is inactive
       
   221     if ( !iUtils.IsConnectionActivated() )
       
   222         {
       
   223         LOG( NORMAL, 
       
   224              "SATENGINE: CSatBIPGPRSDataChannel::ActivateConnectionL\
       
   225              Connection is inactive, open connection " )
       
   226         // Write the primary PDP Context QoS Parameters to CMManager
       
   227         // before activating the primary PDP Context.  
       
   228         WritePrimaryPDPContextQoSParamsL();
       
   229         
       
   230         // Open sub-session to SocketServer    
       
   231         errCode = iConnection.Open( iSocketServ );
       
   232         LOG2( NORMAL, 
       
   233               "SATENGINE: CSatBIPGPRSDataChannel::ActivateConnectionL\
       
   234               RConnection opened with code: %i", errCode )
       
   235         User::LeaveIfError( errCode );
       
   236         
       
   237         // Start connection. If there are no override settings, 
       
   238         // use default settings
       
   239         if ( iConnInfo.iOverrideSet )
       
   240             {
       
   241             LOG( NORMAL, "Starting connection with override settings" )
       
   242             TConnPrefList prefList;
       
   243             TExtendedConnPref extPrefs;
       
   244             
       
   245             extPrefs.SetNoteBehaviour( 
       
   246                     iConnInfo.iOverrideSet->NoteBehaviour() );
       
   247             extPrefs.SetIapId( iConnInfo.iOverrideSet->IapId() );
       
   248             prefList.AppendL( &extPrefs );
       
   249             
       
   250             errCode = iConnection.Start( prefList );
       
   251             }
       
   252         else
       
   253             {
       
   254             LOG( NORMAL, "Starting connection with default settings" )
       
   255             errCode = iConnection.Start();
       
   256             }
       
   257         
       
   258         LOG2( NORMAL, 
       
   259               "SATENGINE: CSatBIPGPRSDataChannel::ActivateConnectionL\
       
   260               RConnection started with code: %i", errCode )
       
   261         User::LeaveIfError( errCode );
       
   262         
       
   263         // Erase the primary PDP Context QoS Parameters from CMManager 
       
   264         WriteDefaultQoSParamsL();
       
   265         
       
   266         // Set Connection activated
       
   267         iUtils.SetConnectionActivated( ETrue );
       
   268         // Make sure the subconnection is inactive.
       
   269         iUtils.SetSubConnectionActivated( EFalse );
       
   270         }
       
   271     else    
       
   272         {
       
   273         LOG( NORMAL, 
       
   274              "SATENGINE: CSatBIPGPRSDataChannel::ActivateConnectionL\
       
   275              Connection is active " )
       
   276         // Connection is active, open SubConnection if it is inactive
       
   277         if ( !iUtils.IsSubConnectionActivated() ) 
       
   278             {
       
   279             LOG( NORMAL, "SATENGINE: CSatBIPGPRSDataChannel::\
       
   280             ActivateConnectionL SubConnection is inactive, open \
       
   281             subconnection" )
       
   282             // Open SubConnection 
       
   283             OpenSubConnection();
       
   284             }
       
   285         }
       
   286     
       
   287     // Set up QoS values
       
   288     SetConnQoSParamsL();
       
   289     
       
   290     // Open socket
       
   291     OpenSocketL();
       
   292     
       
   293     // UDP Socket doesn't need ActiveObject, so we don't have to wait.
       
   294     if ( !iUseTcpProtocol )
       
   295         {
       
   296         LOG( NORMAL, 
       
   297              "SATENGINE: CSatBIPGPRSDataChannel::ActivateConnectionL\
       
   298              UDP protocol " )
       
   299         StartReceiveL();
       
   300         iConnStage = ESatBIPConnected;
       
   301         
       
   302         // Notify ConnectionObserver
       
   303         iConnectionObserver->ConnectionNotification( KErrNone );
       
   304         }
       
   305     
       
   306     LOG( SIMPLE,
       
   307         "SATENGINE: CSatBIPGPRSDataChannel::ActivateConnectionL exiting" )
       
   308     }
       
   309 
       
   310 // ---------------------------------------------------------------------------
       
   311 // ends or stores the data.
       
   312 // ---------------------------------------------------------------------------
       
   313 //
       
   314 void CSatBIPGPRSDataChannel::GetNegotiatedQoSParams( 
       
   315     RSat::TBearerParams& aResult ) const
       
   316     {
       
   317     LOG( SIMPLE, "SATENGINE: CSatBIPGPRSDataChannel::NegotiatedQoSParams\
       
   318         calling - exiting" )
       
   319     aResult = iConnInfo.iBearerParams;
       
   320     }
       
   321 
       
   322 // ---------------------------------------------------------------------------
       
   323 // Sends or stores the data.
       
   324 // ---------------------------------------------------------------------------
       
   325 //
       
   326 TInt CSatBIPGPRSDataChannel::SendDataL( const TDes8& aData,
       
   327     const TBool aSendImmediately,
       
   328     TInt& aFreeBufferSize,
       
   329     MSatSendDataObserver* aObserver )
       
   330     {
       
   331     LOG( SIMPLE, "SATENGINE: CSatBIPGPRSDataChannel::SendDataL calling" )
       
   332 
       
   333     TInt errCode( MSatBIPUtils::ESatBIPSuccess );
       
   334     CSatSActiveWrapper* delay = NULL;
       
   335     TInt numberOfTries( 1 );
       
   336     // Check status of connection
       
   337     TBool suspended( RPacketService::EStatusSuspended == 
       
   338         iUtils.ConnectionStatus() );
       
   339 
       
   340     // Check that does the data fit in buffer
       
   341     const TInt bufsize( iSendStore->Length() );
       
   342 
       
   343     LOG2( NORMAL,
       
   344         "SATENGINE: CSatBIPGPRSDataChannel::SendDataL iSendBuffer size: %i",
       
   345         bufsize )
       
   346     LOG2( NORMAL,
       
   347         "SATENGINE: CSatBIPGPRSDataChannel::SendDataL aData size: %i",
       
   348         aData.Length() )
       
   349     if ( suspended )
       
   350         {
       
   351         // for async wait
       
   352         delay = new ( ELeave ) CSatSActiveWrapper();
       
   353         }
       
   354     
       
   355     while ( suspended && KMaxAttempts >= numberOfTries ) 
       
   356         {
       
   357         // In cases of SMS or Call suspend the pdp context, we need to 
       
   358         // evaluate the status of context after a small delay
       
   359         LOG2( NORMAL, "SATENGINE: CSatBIPGPRSDataChannel::SendDataL, wait, %d "\
       
   360             , numberOfTries )
       
   361         delay->After( KReCheckStatusDelay );
       
   362         suspended = RPacketService::EStatusSuspended == iUtils.ConnectionStatus();
       
   363         numberOfTries++;
       
   364         }
       
   365     
       
   366     delete delay;
       
   367     delay = NULL;
       
   368             
       
   369     if ( suspended && aSendImmediately )
       
   370         {
       
   371         LOG( NORMAL, "SATENGINE: CSatBIPGPRSDataChannel::SendDataL \
       
   372             Connection suspended" )
       
   373         errCode = MSatBIPUtils::ESatBIPServiceError;
       
   374         }
       
   375     else if ( iConnInfo.iBufferSize < ( aData.Length() + bufsize ) )
       
   376         {
       
   377         LOG( NORMAL,
       
   378             "SATENGINE: CSatBIPGPRSDataChannel::SendDataL Buffer overflow" )
       
   379         errCode = MSatBIPUtils::ESatBIPReqBufSizeNotAvail;
       
   380         }
       
   381     else
       
   382         {
       
   383 
       
   384         // Append data to send buffer
       
   385         TPtr8 ptr = iSendStore->Des();
       
   386         ptr.Append( aData );
       
   387 
       
   388         // Send immediately, if required
       
   389         if ( aSendImmediately )
       
   390             {
       
   391             LOG( NORMAL,
       
   392                 "SATENGINE: CSatBIPGPRSDataChannel::SendDataL Sending data" )
       
   393 
       
   394             // If Sender object is NULL, create it
       
   395             if ( !iSender && aObserver )
       
   396                 {
       
   397                 LOG( NORMAL, "SATENGINE: CSatBIPGPRSDataChannel::SendDataL \
       
   398                 create iSender" )
       
   399                 iSender = new ( ELeave ) CSatBIPDataSender(
       
   400                         *aObserver, iSocket, iUseTcpProtocol,
       
   401                         iConnInfo.iBufferSize );
       
   402                 }
       
   403 
       
   404             if ( iSender )
       
   405                 {
       
   406                 LOG( NORMAL, "SATENGINE: CSatBIPGPRSDataChannel::SendDataL \
       
   407                 iSender true" )
       
   408                 // Send data
       
   409                 iSender->SendData( ptr, iDestAddr );
       
   410 
       
   411                 // Remove data from buffer.
       
   412                 iSendStore = HBufC8::NewL( iConnInfo.iBufferSize );
       
   413                 }
       
   414             }
       
   415         }
       
   416 
       
   417     // Place the number of bytes of empty space in the buffer to aFreeBufferSize
       
   418     aFreeBufferSize = ( iConnInfo.iBufferSize - iSendStore->Length() );
       
   419 
       
   420     LOG2( SIMPLE, "SATENGINE: CSatBIPGPRSDataChannel::SendDataL exiting, \
       
   421           errCode: %d", errCode )
       
   422     return errCode;
       
   423     }
       
   424 
       
   425 // ---------------------------------------------------------------------------
       
   426 // Returns the received data in param aData
       
   427 // ---------------------------------------------------------------------------
       
   428 //
       
   429 TInt CSatBIPGPRSDataChannel::ReceiveDataL( TDes8& aData,
       
   430     const TInt aBytesToRead, TInt& aAvailableBytes )
       
   431     {
       
   432     LOG( SIMPLE, "SATENGINE: CSatBIPGPRSDataChannel::ReceiveDataL calling" )
       
   433 
       
   434     TInt errCode( MSatBIPUtils::ESatBIPSuccess );
       
   435 
       
   436     // Number of bytes to return, may not be the same as requested
       
   437     TInt bytesToReturn( aBytesToRead );
       
   438 
       
   439     const TInt bytesAvail( iRcvBuffer.Length() );
       
   440 
       
   441     // Compare the number of bytes received and the number of bytes requested.
       
   442     if ( bytesToReturn > bytesAvail )
       
   443         {
       
   444         LOG( SIMPLE, "SATENGINE: CSatBIPGPRSDataChannel::ReceiveDataL \
       
   445         bytesToReturn > bytesAvail" )
       
   446         // There are no requested bytes availabe, we return all we have.
       
   447         errCode = MSatBIPUtils::ESatBIPReqBufSizeNotAvail;
       
   448         bytesToReturn = bytesAvail;
       
   449         }
       
   450 
       
   451     LOG2( NORMAL, "  ReceiveDataL: Data available for receive: %i", bytesAvail )
       
   452 
       
   453     // Put the data into param aData.
       
   454     aData = iRcvBuffer.Left( bytesToReturn );
       
   455     // Remove read data from receive store
       
   456     iRcvBuffer.Delete( 0, bytesToReturn );
       
   457     // Put the number of unread bytes into param aAvailableBytes.
       
   458     aAvailableBytes = iRcvBuffer.Length();
       
   459     
       
   460     LOG2( SIMPLE, "SATENGINE: CSatBIPGPRSDataChannel::ReceiveDataL \
       
   461           aAvailableBytes: %d", aAvailableBytes )
       
   462     // Notify receiver if store is empty to get the next datagram in UDP sockets
       
   463     if ( ( 0 == aAvailableBytes ) && iReceiver )
       
   464         {
       
   465         iReceiver->ReceiveStoreEmptyNotificationL();
       
   466         }
       
   467 
       
   468     LOG2( SIMPLE, "SATENGINE: CSatBIPGPRSDataChannel::ReceiveDataL exiting. \
       
   469           errCode: %d", errCode )
       
   470     return errCode;
       
   471     }
       
   472 
       
   473 // ---------------------------------------------------------------------------
       
   474 // Returns the identifier of this channel
       
   475 // ---------------------------------------------------------------------------
       
   476 //
       
   477 TInt CSatBIPGPRSDataChannel::ChannelId() const
       
   478     {
       
   479     LOG2( SIMPLE,
       
   480     "SATENGINE: CSatBIPGPRSDataChannel::ChannelId calling - exiting,\
       
   481     ChannelId: %i", iChannelId.ChannelId() )
       
   482     return iChannelId.ChannelId();
       
   483     }
       
   484 
       
   485 // ---------------------------------------------------------------------------
       
   486 // Returns the identifier of this channel. This function is used only when
       
   487 // generating ChannelStatus TLV object
       
   488 // ---------------------------------------------------------------------------
       
   489 //
       
   490 TUint8 CSatBIPGPRSDataChannel::ChannelStatusChannelId() const
       
   491     {
       
   492     LOG( SIMPLE,
       
   493         "SATENGINE: CSatBIPGPRSDataChannel::ChannelStatusChannelId calling" )
       
   494 
       
   495     TUint8 channelId( iChannelId.ShortChannelId() );
       
   496 
       
   497     LOG2( SIMPLE,
       
   498         "SATENGINE: CSatBIPGPRSDataChannel::ChannelStatusChannelId exiting \
       
   499         with channel id: %i", channelId )
       
   500     return channelId;
       
   501     }
       
   502 
       
   503 // ---------------------------------------------------------------------------
       
   504 // Returns the status of this data channel
       
   505 // ---------------------------------------------------------------------------
       
   506 //
       
   507 TInt CSatBIPGPRSDataChannel::Status() const
       
   508     {
       
   509     LOG2( SIMPLE, 
       
   510     "SATENGINE: CSatBIPGPRSDataChannel::Status calling - exiting,\
       
   511     iChannelStatus: %i", iChannelStatus )
       
   512     return iChannelStatus;
       
   513     }
       
   514 
       
   515 // ---------------------------------------------------------------------------
       
   516 // Closes this data channel
       
   517 // ---------------------------------------------------------------------------
       
   518 //
       
   519 void CSatBIPGPRSDataChannel::CloseChannel()
       
   520     {
       
   521     LOG( SIMPLE, "SATENGINE: CSatBIPGPRSDataChannel::CloseChannel calling" )
       
   522 
       
   523     if ( ESatBIPConnected == iConnStage ||
       
   524          ESatBIPCancelled == iConnStage )
       
   525         {
       
   526         LOG( NORMAL, "SATENGINE: CSatBIPGPRSDataChannel::CloseChannel \
       
   527             Channel is connected" )
       
   528         CancelAll();
       
   529         // Close socket
       
   530         iSocket.Close();
       
   531 
       
   532         iConnStage = ESatBIPClosed;
       
   533         }
       
   534     else if ( iConnStage == ESatBIPConnect &&
       
   535               iUseTcpProtocol )
       
   536         {
       
   537         LOG( NORMAL, "SATENGINE: CSatBIPGPRSDataChannel::CloseChannel \
       
   538             Channel is connecting" )
       
   539         // If Channel is connecting and protocol is TCP,
       
   540         // have to call Cancel instead of CancelAll since this is an active
       
   541         // object in this situation
       
   542         Cancel();
       
   543         // Close socket
       
   544         iSocket.Close();
       
   545         
       
   546         iConnStage = ESatBIPClosed;
       
   547         }
       
   548     else
       
   549         {
       
   550         LOG( NORMAL, "SATENGINE: CSatBIPGPRSDataChannel::CloseChannel \
       
   551             Channel already closed" )
       
   552         }
       
   553 
       
   554     // Release channel ID
       
   555     iChannelId.ReleaseChannel();
       
   556 
       
   557     LOG( SIMPLE, "SATENGINE: CSatBIPGPRSDataChannel::CloseChannel exiting" )
       
   558     }
       
   559 
       
   560 // ---------------------------------------------------------------------------
       
   561 // Performs cancel actions.
       
   562 // ---------------------------------------------------------------------------
       
   563 //
       
   564 void CSatBIPGPRSDataChannel::CancelAll()
       
   565     {
       
   566     LOG( SIMPLE, "SATENGINE: CSatBIPGPRSDataChannel::CancelAll calling" )
       
   567 
       
   568     // Cancel all activity in sockets
       
   569     if ( iConnStage == ESatBIPConnected )
       
   570         {
       
   571         LOG( SIMPLE, "SATENGINE: CSatBIPGPRSDataChannel::CancelAll \
       
   572         iConnStage == ESatBIPConnected" )
       
   573         // Cancel sender
       
   574         if ( iSender )
       
   575             {
       
   576             LOG( SIMPLE, "SATENGINE: CSatBIPGPRSDataChannel::CancelAll \
       
   577             cancel iSender" )
       
   578             iSender->Cancel();
       
   579             }
       
   580 
       
   581         // Cancel receiver
       
   582         if ( iReceiver )
       
   583             {
       
   584             LOG( SIMPLE, "SATENGINE: CSatBIPGPRSDataChannel::CancelAll \
       
   585             cancel iReceiver" )
       
   586             iReceiver->Cancel();
       
   587             }
       
   588 
       
   589         // Cancel all actions
       
   590         iSocket.CancelAll();
       
   591         // Link dropped, when socket cancels all
       
   592         iChannelStatus = MSatBIPUtils::ESatLinkDropped;
       
   593         iConnStage = ESatBIPCancelled;
       
   594         }
       
   595     else if ( iConnStage == ESatBIPConnect )
       
   596         {
       
   597         LOG( NORMAL, "SATENGINE: CSatBIPGPRSDataChannel::CancelAll \
       
   598             Cancelling connect" )
       
   599         // Cancel connection negotiations
       
   600         iSocket.CancelConnect();
       
   601         iConnStage = ESatBIPCancelled;
       
   602         }
       
   603     else
       
   604         {
       
   605         LOG( NORMAL, "SATENGINE: CSatBIPGPRSDataChannel::CancelAll \
       
   606             Channel already cancelled or closed" )
       
   607         }
       
   608 
       
   609     LOG( SIMPLE, "SATENGINE: CSatBIPGPRSDataChannel::CancelAll exiting" )
       
   610     }
       
   611 
       
   612 // ---------------------------------------------------------------------------
       
   613 // Returns the status of this data channel
       
   614 // ---------------------------------------------------------------------------
       
   615 //
       
   616 TBool CSatBIPGPRSDataChannel::IsContextActive() const
       
   617     {
       
   618     LOG2( SIMPLE,
       
   619     "SATENGINE: CSatBIPGPRSDataChannel::IsContextActive calling - exiting,\
       
   620     return: %d", ESatBIPConnected == iConnStage )
       
   621     return ESatBIPConnected == iConnStage;
       
   622     }
       
   623 
       
   624 // ---------------------------------------------------------------------------
       
   625 // Returns the status of this data channel
       
   626 // ---------------------------------------------------------------------------
       
   627 //
       
   628 const MSatBIPDataChannel::TSatBipConnectionInfo& CSatBIPGPRSDataChannel::ConnInfo() const
       
   629     {
       
   630     LOG( SIMPLE,
       
   631         "SATENGINE: CSatBIPGPRSDataChannel::ConnInfo calling - exiting" )
       
   632     return iConnInfo;
       
   633     }
       
   634 
       
   635 // -----------------------------------------------------------------------------
       
   636 // CSatBIPGPRSDataChannel::StopUdpSocket
       
   637 // -----------------------------------------------------------------------------
       
   638 //
       
   639 void CSatBIPGPRSDataChannel::StopUdpSocket()
       
   640     {
       
   641     LOG( SIMPLE, "SATENGINE: CSatBIPGPRSDataChannel::StopUdpSocket calling" )
       
   642     
       
   643     if ( !iUseTcpProtocol )
       
   644     {
       
   645     LOG( SIMPLE, "SATENGINE: CSatBIPGPRSDataChannel::StopUdpSocket UDP" )
       
   646     iSocket.Close();
       
   647     }
       
   648         
       
   649     LOG( SIMPLE, "SATENGINE: CSatBIPGPRSDataChannel::StopUdpSocket exiting" )
       
   650     }
       
   651 
       
   652 // ---------------------------------------------------------------------------
       
   653 // From CActive
       
   654 // ---------------------------------------------------------------------------
       
   655 //
       
   656 void CSatBIPGPRSDataChannel::RunL()
       
   657     {
       
   658     LOG( SIMPLE, "SATENGINE: CSatBIPGPRSDataChannel::RunL calling " )
       
   659 
       
   660     if ( KErrNone == iStatus.Int() )
       
   661         {
       
   662         LOG( SIMPLE, "SATENGINE: CSatBIPGPRSDataChannel::RunL \
       
   663         KErrNone == iStatus.Int() " )
       
   664         // Check connection stage
       
   665         switch ( iConnStage )
       
   666             {
       
   667             case ESatBIPConnect:
       
   668                 {
       
   669                 LOG( SIMPLE, "SATENGINE: CSatBIPGPRSDataChannel::RunL \
       
   670                     Connect OK" )
       
   671                     
       
   672                 // Start receiving data
       
   673                 StartReceiveL();
       
   674                 iConnStage = ESatBIPConnected;
       
   675                 // Notify ConnectionObserver
       
   676                 iConnectionObserver->ConnectionNotification( KErrNone );
       
   677                 break;
       
   678                 }
       
   679 
       
   680             case ESatBIPCancelled:
       
   681                 {
       
   682                 LOG( SIMPLE, "SATENGINE: CSatBIPGPRSDataChannel::RunL \
       
   683                     Connection Cancelled" )
       
   684                 // Notify ConnectionObserver
       
   685                 iConnectionObserver->ConnectionNotification( KErrCancel );
       
   686                 break;
       
   687                 }
       
   688 
       
   689             default:
       
   690                 {
       
   691                 LOG( SIMPLE, "SATENGINE: CSatBIPGPRSDataChannel::RunL default" )
       
   692                 PanicSatEngine( ESatBIPAccessViolation );
       
   693                 }
       
   694             }
       
   695         }
       
   696     else
       
   697         {
       
   698         // Notify ConnectionObserver with error
       
   699         iConnectionObserver->ConnectionNotification( iStatus.Int() );
       
   700         }
       
   701 
       
   702     LOG( SIMPLE, "SATENGINE: CSatBIPGPRSDataChannel::RunL exiting " )
       
   703     }
       
   704 
       
   705 // ---------------------------------------------------------------------------
       
   706 // DoCancel
       
   707 // ---------------------------------------------------------------------------
       
   708 //
       
   709 void CSatBIPGPRSDataChannel::DoCancel()
       
   710     {
       
   711     LOG( SIMPLE, "SATENGINE: CSatBIPGPRSDataChannel::DoCancel calling" )
       
   712 
       
   713     CancelAll();
       
   714 
       
   715     LOG( SIMPLE, "SATENGINE: CSatBIPGPRSDataChannel::DoCancel calling" )
       
   716     }
       
   717 
       
   718 // ---------------------------------------------------------------------------
       
   719 // RunError
       
   720 // ---------------------------------------------------------------------------
       
   721 //
       
   722 TInt CSatBIPGPRSDataChannel::RunError( TInt aError )
       
   723     {
       
   724     LOG( SIMPLE, "SATENGINE: CSatBIPGPRSDataChannel::RunError calling" )
       
   725 
       
   726     if ( iConnectionObserver )
       
   727         {
       
   728         LOG( SIMPLE, "SATENGINE: CSatBIPGPRSDataChannel::RunError \
       
   729         iConnectionObserver true" )
       
   730         iConnectionObserver->ConnectionNotification( aError );
       
   731         }
       
   732 
       
   733     LOG( SIMPLE, "SATENGINE: CSatBIPGPRSDataChannel::RunError calling" )
       
   734     return KErrNone;
       
   735     }
       
   736 
       
   737 // ---------------------------------------------------------------------------
       
   738 // Stores received data into buffer.
       
   739 // ---------------------------------------------------------------------------
       
   740 //
       
   741 void CSatBIPGPRSDataChannel::DataReceivedNotificationL( const TDesC8& aData )
       
   742     {
       
   743     LOG( SIMPLE,
       
   744         "SATENGINE: CSatBIPGPRSDataChannel::DataReceivedNotification calling" )
       
   745 
       
   746     // Check do we have to report data receive
       
   747     const TInt bufsize( iRcvBuffer.Length() );
       
   748 #ifdef ENABLE_SAT_LOGGING
       
   749     TBuf<KIpAddressLogSize> addressForLog;
       
   750 #endif
       
   751     // LOG values
       
   752     LOG2( NORMAL, "SATENGINE: CSatBIPGPRSDataChannel::RunL\
       
   753         ReceiveStore length: %i", bufsize )
       
   754 
       
   755     // In UDP context, we can store only one datagram at a time. If there is
       
   756     // previous datagram in store, we'll have to wait for the UICC to get all
       
   757     // before storing the netx datagram and to start receive again. If there are
       
   758     // more than one datagrams pending, they are stored in RSockets queue.
       
   759     if ( bufsize == 0 || RSat::ETcp == iConnInfo.iProtocol.iTransportProto )
       
   760         {
       
   761 #ifdef ENABLE_SAT_LOGGING
       
   762         iSourceAddr.Output( addressForLog );
       
   763         LOG2( NORMAL, "SATENGINE: CSatBIPGPRSDataChannel::RunL\
       
   764             Received data length: %i", aData.Length() )
       
   765         LOG2( NORMAL, "SATENGINE: CSatBIPGPRSDataChannel::RunL\
       
   766             Received from address: %S", &addressForLog )
       
   767         LOG2( NORMAL, "SATENGINE: CSatBIPGPRSDataChannel::RunL\
       
   768             Received from port: %i", iSourceAddr.Port() )
       
   769 #endif
       
   770         // Store data, if it fits into store, else, do not receive until store
       
   771         // is empty.
       
   772         if ( KSatBIPMinReceiveBufferSize >= ( aData.Length() + bufsize ) )
       
   773             {
       
   774             LOG( SIMPLE, "SATENGINE: CSatBIPGPRSDataChannel::\
       
   775                  DataReceivedNotification store data" )
       
   776             iRcvBuffer.Append( aData );
       
   777 
       
   778             // It is possible that aData is empty, because this function 
       
   779             // is called
       
   780             // every time when SIM gets the final bytes from ReceiveStore.
       
   781             if ( 0 == bufsize && aData.Length() > 0 )
       
   782                 {
       
   783                 LOG( SIMPLE,
       
   784                 "SATENGINE: CSatBIPGPRSDataChannel::DataReceivedNotification \
       
   785                 aData.Length() > 0" )
       
   786                 // If the store is empty, send event download
       
   787                 iUtils.DataAvailable( ChannelId(), aData.Length() );
       
   788                 }
       
   789 
       
   790             // Start to receive again. This should never leave, because Receiver
       
   791             // object is already created.
       
   792             StartReceiveL();
       
   793             }
       
   794         }
       
   795 
       
   796     LOG( SIMPLE,
       
   797         "SATENGINE: CSatBIPGPRSDataChannel::DataReceivedNotification exiting" )
       
   798     }
       
   799 
       
   800 // ---------------------------------------------------------------------------
       
   801 // Error while receiving data
       
   802 // ---------------------------------------------------------------------------
       
   803 //
       
   804 void CSatBIPGPRSDataChannel::DataReceiveError( TInt aError )
       
   805     {
       
   806     LOG( SIMPLE, "SATENGINE: CSatBIPGPRSDataChannel::DataReceiveError calling" )
       
   807 
       
   808     if ( KErrCancel != aError ) // Don't do anything if cancelled
       
   809         {
       
   810         LOG2( NORMAL, "SATENGINE: CSatBIPGPRSDataChannel::DataReceiveError\
       
   811              Error: %i", aError )
       
   812         // Report error
       
   813         iConnStage = ESatBIPCancelled; 
       
   814         iChannelStatus = MSatBIPUtils::ESatLinkDropped;
       
   815         iUtils.ChannelStatus( ChannelId(), iChannelStatus );
       
   816         }
       
   817     else
       
   818         {
       
   819         // Cancelled
       
   820         LOG( SIMPLE, "SATENGINE: CSatBIPGPRSDataChannel::DataReceiveError\
       
   821             Receive has been cancelled cancelled" )
       
   822         }
       
   823 
       
   824     LOG( SIMPLE, "SATENGINE: CSatBIPGPRSDataChannel::DataReceiveError exiting" )
       
   825     }
       
   826 
       
   827 // ---------------------------------------------------------------------------
       
   828 // C++ default constructor can NOT contain any code, that
       
   829 // might leave.
       
   830 // ---------------------------------------------------------------------------
       
   831 //
       
   832 CSatBIPGPRSDataChannel::CSatBIPGPRSDataChannel( CSatBIPUtils& aUtils,
       
   833     RSocketServ& aSocketServer,
       
   834     TSatChannelIdInfo& aChannelId,
       
   835     RConnection& aConnection,
       
   836     RSubConnection& aSubConnection) :
       
   837     CActive( EPriorityStandard ),
       
   838     iUtils( aUtils ),
       
   839     iSocketServ( aSocketServer ),
       
   840     iChannelId( aChannelId ),
       
   841     iConnection( aConnection ),
       
   842     iSubConnection( aSubConnection )
       
   843     {
       
   844     LOG( SIMPLE,
       
   845         "SATENGINE: CSatBIPGPRSDataChannel::CSatBIPGPRSDataChannel calling" )
       
   846 
       
   847     CActiveScheduler::Add( this );
       
   848 
       
   849     LOG( SIMPLE,
       
   850         "SATENGINE: CSatBIPGPRSDataChannel::CSatBIPGPRSDataChannel exiting" )
       
   851     }
       
   852 
       
   853 // ---------------------------------------------------------------------------
       
   854 // Symbian 2nd phase constructor can leave.
       
   855 // ---------------------------------------------------------------------------
       
   856 //
       
   857 void CSatBIPGPRSDataChannel::ConstructL()
       
   858     {
       
   859     LOG( SIMPLE, "SATENGINE: CSatBIPGPRSDataChannel::ConstructL calling" )
       
   860 
       
   861     iChannelStatus = MSatBIPUtils::ESatNoFurtherInformation;
       
   862     
       
   863     LOG( SIMPLE, "SATENGINE: CSatBIPGPRSDataChannel::ConstructL exiting" )
       
   864     }
       
   865 
       
   866 // ---------------------------------------------------------------------------
       
   867 // Opens and connects / binds Socket
       
   868 // ---------------------------------------------------------------------------
       
   869 //
       
   870 void CSatBIPGPRSDataChannel::OpenSocketL()
       
   871     {
       
   872     LOG( SIMPLE, "SATENGINE: CSatBIPGPRSDataChannel::OpenSocketL calling" )
       
   873 
       
   874     TInt errCode( KErrNone );
       
   875 
       
   876     // Define Destination address
       
   877     // Create InetAddress to hold remote device information
       
   878     LOG2( NORMAL, "SATENGINE: CSatBIPGPRSDataChannel::OpenSocketL\
       
   879          Port from SIM: %d", iConnInfo.iProtocol.iPrtNumber )
       
   880 
       
   881     // Remote server's IP Address
       
   882 #ifdef SAT_USE_DUMMY_TSY
       
   883     TBuf8<RSat::KPcktAddressMaxSize> destAddr( RSat::KPcktAddressMaxSize );
       
   884     
       
   885     // KAfInet or KAfInet6
       
   886     if ( RSat::EIPv6Address == iConnInfo.iDestination.iType )
       
   887         {
       
   888         LOG( SIMPLE, "SATENGINE: CSatBIPGPRSDataChannel::OpenSocketL IPv6" )
       
   889         // 0:0:0:0:0:0:0:2 is equivalent to 127, 0, 0, 2
       
   890         for ( TInt ndx = 0 ; ndx < KIpAddressSize ; ndx++ )
       
   891             {
       
   892             destAddr[ndx] = 0;
       
   893             }
       
   894         destAddr[KIpAddressSize] = KIpAddressDValueDestination;
       
   895         destAddr.SetLength( KIpv6Length );
       
   896         }
       
   897     else //ipv4
       
   898         {
       
   899         LOG( SIMPLE, "SATENGINE: CSatBIPGPRSDataChannel::OpenSocketL IPv4" )
       
   900         destAddr[KIpAddressA] = KIpAddressAValue;
       
   901         destAddr[KIpAddressB] = KIpAddressBValue;
       
   902         destAddr[KIpAddressC] = KIpAddressCValue;
       
   903         destAddr[KIpAddressD] = KIpAddressDValueDestination;
       
   904         destAddr.SetLength( KIpv4Length );
       
   905         }
       
   906     iDestAddr = DestAddress( destAddr );
       
   907 #else
       
   908     iDestAddr = DestAddress( iConnInfo.iDestination.iAddress );
       
   909 #endif // SAT_USE_DUMMY_TSY
       
   910     
       
   911     LOG( NORMAL, "SATENGINE: CSatBIPGPRSDataChannel::OpenSocketL\
       
   912          Complete defining destination address" )
       
   913     
       
   914     iSourceAddr = iDestAddr;
       
   915     
       
   916     TUint socketType( KSockStream );
       
   917     TUint protocol( KProtocolInetTcp );
       
   918     
       
   919     // Check is it UDP or TCP
       
   920     if ( !iUseTcpProtocol )
       
   921         {
       
   922         LOG( NORMAL, "SATENGINE: CSatBIPGPRSDataChannel::OpenSocketL\
       
   923             Opening UDP datagram socket" )
       
   924         socketType = KSockDatagram;
       
   925         protocol = KProtocolInetUdp;
       
   926         }
       
   927     else
       
   928         {
       
   929         LOG( NORMAL, "SATENGINE: CSatBIPGPRSDataChannel::OpenSocketL\
       
   930             Opening TCP stream socket" )
       
   931         }
       
   932         
       
   933     // Open socket
       
   934     if ( iUtils.IsSubConnectionActivated() )
       
   935         {
       
   936         LOG( NORMAL, "SATENGINE: CSatBIPGPRSDataChannel::OpenSocketL\
       
   937         using subconnection" )
       
   938         errCode = iSocket.Open( iSocketServ, KAfInet, socketType,
       
   939             protocol, iSubConnection );
       
   940         }
       
   941     else
       
   942         {
       
   943         LOG( NORMAL, "SATENGINE: CSatBIPGPRSDataChannel::OpenSocketL\
       
   944         using connection" )
       
   945         errCode = iSocket.Open( iSocketServ, KAfInet, socketType,
       
   946             protocol, iConnection );
       
   947         }
       
   948         
       
   949     // Check socket activation
       
   950     LOG2( NORMAL, "SATENGINE: CSatBIPGPRSDataChannel::OpenSocketL\
       
   951         Socket opened with code: %i", errCode )
       
   952     User::LeaveIfError( errCode );
       
   953     
       
   954     // Define local address. Local port is obtained automatically
       
   955     TInetAddr localAddress( KInetPortAny );
       
   956     
       
   957 #ifdef SAT_USE_DUMMY_TSY
       
   958         // win2000 doesn't support IPv6, so force to IPv4
       
   959         localAddress.SetFamily( KAfInet );
       
   960         // KAfInet or KAfInet6
       
   961         if ( RSat::EIPv6Address == iConnInfo.iDestination.iType )
       
   962             {
       
   963             LOG( NORMAL, "SATENGINE: CSatBIPGPRSDataChannel::OpenSocketL\
       
   964                 IPv6" )
       
   965             // 0:0:0:0:0:0:0:3 is equivalent to 127, 0, 0, 3
       
   966             TIp6Addr ip6Adrr;
       
   967             
       
   968             for ( TInt index = 0 ; index < KIpAddressSize ; index++ )
       
   969                 {
       
   970                 ip6Adrr.u.iAddr8[index] = 0;
       
   971                 }
       
   972                 
       
   973             ip6Adrr.u.iAddr8[KIpAddressSize] = KIpAddressDValueLocal;
       
   974             localAddress.SetAddress( ip6Adrr );
       
   975             }
       
   976         else //ipv4
       
   977             {
       
   978             LOG( NORMAL, "SATENGINE: CSatBIPGPRSDataChannel::OpenSocketL\
       
   979                 IPv4" )
       
   980             localAddress.SetAddress( INET_ADDR(
       
   981                 KIpAddressAValue,
       
   982                 KIpAddressBValue,
       
   983                 KIpAddressCValue,
       
   984                 KIpAddressDValueLocal ) );
       
   985             }
       
   986 #else
       
   987     // Check does the SIM provide a local address
       
   988     if ( 0 < iConnInfo.iSource.iAddress.Length() )
       
   989         {
       
   990         LOG( NORMAL, "SATENGINE: CSatBIPGPRSDataChannel::OpenSocketL\
       
   991             Setting pre-defined local address" )
       
   992         localAddress = DestAddress( iConnInfo.iSource.iAddress );
       
   993         localAddress.SetPort( KInetPortAny );
       
   994         }
       
   995     else
       
   996         {
       
   997         LOG( NORMAL, "SATENGINE: CSatBIPGPRSDataChannel::OpenSocketL\
       
   998             Setting automatic local address" )
       
   999         // Unspecified. Local address is obtained automatically.
       
  1000         localAddress.SetFamily( KAFUnspec );
       
  1001         }
       
  1002 #endif       
       
  1003     LOG( NORMAL, "SATENGINE: CSatBIPGPRSDataChannel::OpenSocketL\
       
  1004         Bind local address" )
       
  1005     errCode = iSocket.Bind( localAddress );  
       
  1006         
       
  1007     // Check what was the response from "Bind"
       
  1008     if ( KErrNone == errCode )
       
  1009         {
       
  1010         // Set status to indicate that connection attempt ongoing
       
  1011         iConnStage = ESatBIPConnect;
       
  1012         
       
  1013         if ( iUseTcpProtocol )
       
  1014             {
       
  1015             // Connect the socket
       
  1016             iSocket.Connect( iDestAddr, iStatus );
       
  1017             SetActive();
       
  1018             }
       
  1019         else
       
  1020             {
       
  1021             // This option redefines the receive buffer size
       
  1022             iSocket.SetOpt( KSoUdpRecvBuf, KSolInetUdp, 
       
  1023                 KSatBIPMinReceiveBufferSize );
       
  1024             // Connect the socket
       
  1025             iSocket.Connect( iDestAddr, iStatus );
       
  1026             // UDP sockets dont need active object
       
  1027             User::WaitForRequest( iStatus );
       
  1028             LOG2( NORMAL, "SATENGINE: CSatBIPGPRSDataChannel::OpenSocketL\
       
  1029                 UDP Socket connect status  %i", iStatus.Int() )
       
  1030             }
       
  1031         }
       
  1032     else
       
  1033         {
       
  1034         // Send Terminal Response indicating that static address allocation
       
  1035         // could not be done (KErrNotFound) or Bind failed for some other 
       
  1036         // reason
       
  1037         LOG2( NORMAL, "SATENGINE: CSatBIPGPRSDataChannel::OpenSocketL\
       
  1038             Bind error:  %i", errCode )
       
  1039         iConnectionObserver->ConnectionNotification( errCode );
       
  1040         }
       
  1041 
       
  1042     LOG( SIMPLE, "SATENGINE: CSatBIPGPRSDataChannel::OpenSocketL exiting" )
       
  1043     }
       
  1044 
       
  1045 // ---------------------------------------------------------------------------
       
  1046 // Opens SubConnection and attaches socket into it
       
  1047 // ---------------------------------------------------------------------------
       
  1048 //
       
  1049 void CSatBIPGPRSDataChannel::OpenSubConnection()
       
  1050     {
       
  1051     LOG( SIMPLE,
       
  1052         "SATENGINE: CSatBIPGPRSDataChannel::OpenSubConnection calling" )
       
  1053     
       
  1054     TInt errCode( KErrNone );
       
  1055     
       
  1056     // Create SubConnection. This is mandatory for multiple PDP Context support
       
  1057     LOG( NORMAL, "SATENGINE: CSatBIPGPRSDataChannel::OpenSubConnection\
       
  1058         Opening Sub-connection" )
       
  1059     
       
  1060     errCode = iSubConnection.Open( iSocketServ, RSubConnection::ECreateNew, 
       
  1061                                    iConnection );
       
  1062     
       
  1063     LOG2( NORMAL, "SATENGINE: CSatBIPGPRSDataChannel::OpenSubConnection\
       
  1064         RSubConnection opened with code: %i", errCode )
       
  1065     
       
  1066     if ( KErrNone != errCode )
       
  1067         {
       
  1068         // No subconnections, Affects on sockets
       
  1069         LOG( NORMAL, "SATENGINE: CSatBIPGPRSDataChannel::OpenSubConnection\
       
  1070                 RSubConnection is opened incorrectly" )
       
  1071         iSubConnection.Close();
       
  1072         iUtils.SetSubConnectionActivated( EFalse );
       
  1073         }
       
  1074     else 
       
  1075         {
       
  1076         LOG( NORMAL, "SATENGINE: CSatBIPGPRSDataChannel::OpenSubConnection\
       
  1077                 RSubConnection is opened correctly" )
       
  1078         iUtils.SetSubConnectionActivated( ETrue );
       
  1079         }
       
  1080         
       
  1081     LOG( SIMPLE,
       
  1082         "SATENGINE: CSatBIPGPRSDataChannel::OpenSubConnection exiting" )
       
  1083     }
       
  1084 
       
  1085 // ---------------------------------------------------------------------------
       
  1086 // Sets QoS parameters to active SubConnection
       
  1087 // ---------------------------------------------------------------------------
       
  1088 //
       
  1089 void CSatBIPGPRSDataChannel::SetSubConQoSParamsL()
       
  1090     {
       
  1091     LOG( SIMPLE,
       
  1092         "SATENGINE: CSatBIPGPRSDataChannel::SetSubConQoSParamsL calling" )
       
  1093     
       
  1094     const TInt paramLength( iConnInfo.iBearerParams.Length() );
       
  1095     TInt errCode( KErrNone );
       
  1096 
       
  1097     LOG2( NORMAL, "  QoS Parameters length: %i", paramLength )
       
  1098 
       
  1099     // GPRS requires 6 parameters from SIM
       
  1100     if ( KReqGprsQoSParams == paramLength )
       
  1101         {
       
  1102         // Check that is packet protocol valid, ie. IP protocol
       
  1103         if ( KReqPacketProtType != iConnInfo.iBearerParams[KProtocolPos] )
       
  1104             {
       
  1105             LOG( NORMAL, 
       
  1106                 "SATENGINE: CSatBIPGPRSDataChannel::SetSubConQoSParamsL\
       
  1107                 Requested packet protocol is not valid" )
       
  1108             User::Leave( KErrNotSupported );
       
  1109             }
       
  1110         }
       
  1111     else
       
  1112         {
       
  1113         LOG( NORMAL, 
       
  1114             "SATENGINE: CSatBIPGPRSDataChannel::SetSubConQoSParamsL\
       
  1115             Requested packet protocol is valid, not support" )
       
  1116         User::Leave( KErrNotSupported );
       
  1117         }
       
  1118 
       
  1119     // Creating and setting properties for a sub-connection
       
  1120     // Create a parameter bundle and add to the cleanup stack
       
  1121     RSubConParameterBundle parameterBundle;
       
  1122     CleanupClosePushL( parameterBundle );
       
  1123         
       
  1124     // Create a family owned by parameterBundle
       
  1125     CSubConParameterFamily* parameterFamily = 
       
  1126         CSubConParameterFamily::NewL( parameterBundle, KSubConQoSFamily );
       
  1127     
       
  1128     // Create extension paramset(Rel5) owned by parameterFamily
       
  1129     CSubConQosR5ParamSet* requestedQoSRel5 = 
       
  1130         CSubConQosR5ParamSet::NewL( *parameterFamily, 
       
  1131                                     CSubConParameterFamily::ERequested );
       
  1132     
       
  1133     if( requestedQoSRel5 )
       
  1134         {
       
  1135         RPacketQoS::TQoSGPRSRequested reqQoS;
       
  1136         TSatQoSParser::GetRequestedQoSValues( iConnInfo.iBearerParams, 
       
  1137             reqQoS );
       
  1138         TSatQoSParser::TQoSRel5 qosRel5 = TSatQoSParser::ConvertQoS( reqQoS );
       
  1139         // Set some requested QoS values
       
  1140         requestedQoSRel5->SetTrafficClass( 
       
  1141             static_cast<RPacketQoS::TTrafficClass>( qosRel5.iTrafficClass ) );
       
  1142         requestedQoSRel5->SetTrafficHandlingPriority( 
       
  1143             static_cast<RPacketQoS::TTrafficHandlingPriority>( 
       
  1144                 qosRel5.iTrafficHandlingPriority ) );
       
  1145         requestedQoSRel5->SetSDUErrorRatio( 
       
  1146             static_cast<RPacketQoS::TSDUErrorRatio>( qosRel5.iSduErrorRatio ) );
       
  1147         requestedQoSRel5->SetResidualBitErrorRatio( 
       
  1148             static_cast<RPacketQoS::TBitErrorRatio>( qosRel5.iResidualBer ) );
       
  1149         requestedQoSRel5->SetErroneousSDUDelivery( 
       
  1150             static_cast<RPacketQoS::TErroneousSDUDelivery>( 
       
  1151                 qosRel5.iDeliveryErroneousSdu ) );
       
  1152         requestedQoSRel5->SetMaxBitrateUplink( qosRel5.iMaxBitRate );
       
  1153         requestedQoSRel5->SetMaxBitrateDownlink( qosRel5.iMaxBitRate );
       
  1154         requestedQoSRel5->SetMaxSduSize( qosRel5.iMaximumSDUSize );
       
  1155         requestedQoSRel5->SetDeliveryOrder( 
       
  1156             static_cast<RPacketQoS::TDeliveryOrder>( qosRel5.iDeliveryOrder ) );
       
  1157         LOG( SIMPLE, 
       
  1158             "SATENGINE: CSatBIPGPRSDataChannel::SetSubConQoSParamsL\
       
  1159             Setting requested QoS values for subconn" )
       
  1160         
       
  1161         // Start observing granted event.
       
  1162         if( !iSubConnEventObserver )
       
  1163             {
       
  1164             LOG( SIMPLE, 
       
  1165             "SATENGINE: CSatBIPGPRSDataChannel::SetSubConQoSParamsL\
       
  1166             iSubConnEventObserver false" )
       
  1167             iSubConnEventObserver = 
       
  1168                 new ( ELeave ) CSatBIPSubConnEventObserver( *this );
       
  1169             }
       
  1170         iSubConnEventObserver->StartObservSubConnEvent();
       
  1171         
       
  1172         // Set parameters
       
  1173         errCode = iSubConnection.SetParameters( parameterBundle );
       
  1174         LOG2( NORMAL, 
       
  1175             "SATENGINE: CSatBIPGPRSDataChannel::SetSubConQoSParamsL\
       
  1176 	        calling iSubConnection.SetParameters (parameterBundle) = %d", 
       
  1177 	        errCode )
       
  1178         }
       
  1179     else
       
  1180         {
       
  1181         LOG( SIMPLE,
       
  1182             "SATENGINE: CSatBIPGPRSDataChannel::SetSubConQoSParamsL\
       
  1183             Can't create CSubConQosR5ParamSet" )
       
  1184         errCode = KErrNotSupported;
       
  1185         }
       
  1186     
       
  1187     // Pop and close parameterBundle
       
  1188     CleanupStack::PopAndDestroy();
       
  1189     
       
  1190     User::LeaveIfError( errCode );
       
  1191         
       
  1192     LOG( SIMPLE,
       
  1193         "SATENGINE: CSatBIPGPRSDataChannel::SetSubConQoSParamsL exiting" )
       
  1194     }
       
  1195 
       
  1196 // ---------------------------------------------------------------------------
       
  1197 // Starts to receive data from Socket
       
  1198 // ---------------------------------------------------------------------------
       
  1199 //
       
  1200 void CSatBIPGPRSDataChannel::StartReceiveL()
       
  1201     {
       
  1202     LOG( SIMPLE, "SATENGINE: CSatBIPGPRSDataChannel::StartReceiveL calling" )
       
  1203 
       
  1204     // If receiver is NULL, create it
       
  1205     if ( NULL == iReceiver )
       
  1206         {
       
  1207         LOG( SIMPLE, "SATENGINE: CSatBIPGPRSDataChannel::StartReceiveL \
       
  1208         create iReceiver" )
       
  1209         iReceiver = new ( ELeave ) CSatBIPDataReceiver(
       
  1210             *this, iSocket, iUseTcpProtocol );
       
  1211         }
       
  1212 
       
  1213     // Tell receiver to start receive
       
  1214     iReceiver->StartReceive( iSourceAddr );
       
  1215 
       
  1216     LOG( SIMPLE, "SATENGINE: CSatBIPGPRSDataChannel::StartReceiveL exiting" )
       
  1217     }
       
  1218 
       
  1219 // ---------------------------------------------------------------------------
       
  1220 // Defines address
       
  1221 // ---------------------------------------------------------------------------
       
  1222 //
       
  1223 TInetAddr CSatBIPGPRSDataChannel::DestAddress( const TPtrC8& aAddr )
       
  1224     {
       
  1225     LOG( SIMPLE, "SATENGINE: CSatBIPGPRSDataChannel::DestAddress calling" )
       
  1226 
       
  1227     TInetAddr destinationAddress;
       
  1228 
       
  1229     const TInt addLength( aAddr.Length() );
       
  1230     LOG2( NORMAL, "  Address length is %i", addLength )
       
  1231 
       
  1232 #ifdef ENABLE_SAT_LOGGING
       
  1233     TBuf<KIpAddressLogSize> addressForLog;
       
  1234 #endif
       
  1235     // Check IPv4 address
       
  1236     if ( KIPv4Length == addLength )
       
  1237         {
       
  1238         TInt index = 0;
       
  1239         TUint8 first( aAddr[index++] );
       
  1240         TUint8 second( aAddr[index++] );
       
  1241         TUint8 third( aAddr[index++] );
       
  1242         TUint8 fourth( aAddr[index++] );
       
  1243 
       
  1244         // This macro creates IPAddress into TUint32 format.
       
  1245         //lint -e{1924} Problem inside epoc macro, nothing to do.
       
  1246         destinationAddress = TInetAddr( INET_ADDR( first, second, third, fourth ),
       
  1247             iConnInfo.iProtocol.iPrtNumber );
       
  1248         destinationAddress.SetFamily( KAfInet );
       
  1249 #ifdef ENABLE_SAT_LOGGING
       
  1250         destinationAddress.Output( addressForLog );
       
  1251         LOG2( NORMAL, "  Using IPv4, Address is %S", &addressForLog )
       
  1252 #endif
       
  1253         }
       
  1254     // Check IPv6 address
       
  1255     else if ( KIPv6Length == addLength )
       
  1256         {
       
  1257         TIp6Addr ip6Adrr;
       
  1258         for ( TInt index = 0 ; index < addLength ; index++ )
       
  1259             {
       
  1260             ip6Adrr.u.iAddr8[index] = aAddr[index];
       
  1261             }
       
  1262 
       
  1263         destinationAddress = TInetAddr( ip6Adrr, iConnInfo.iProtocol.iPrtNumber );
       
  1264         destinationAddress.SetFamily( KAfInet6 );
       
  1265 #ifdef ENABLE_SAT_LOGGING
       
  1266         destinationAddress.Output( addressForLog );
       
  1267         LOG2( NORMAL, "  Using IPv6, Address is %S", &addressForLog )
       
  1268 #endif
       
  1269 #ifdef SAT_USE_DUMMY_TSY
       
  1270         // Using Dummy TSY, overwriting IPv6 address to IPv4 since
       
  1271         // Windows 2000 doesn't support IPv6
       
  1272         destinationAddress.ConvertToV4();
       
  1273         destinationAddress.SetFamily( KAfInet );
       
  1274 #ifdef ENABLE_SAT_LOGGING
       
  1275         destinationAddress.Output( addressForLog );
       
  1276         LOG2( NORMAL, "  Converted IPv6 address to IPv4,\
       
  1277              Address is %S", &addressForLog )
       
  1278 #endif
       
  1279         destinationAddress.SetAddress( INET_ADDR(
       
  1280             KIpAddressAValue,
       
  1281             KIpAddressBValue,
       
  1282             KIpAddressCValue,
       
  1283             KIpAddressDValueDestination ) );
       
  1284 #ifdef ENABLE_SAT_LOGGING
       
  1285         destinationAddress.Output( addressForLog );
       
  1286         LOG2( NORMAL, "  Overwrited IPv4 localhost,\
       
  1287              Address is %S", &addressForLog )
       
  1288 #endif
       
  1289 #endif //SAT_USE_DUMMY_TSY
       
  1290         }
       
  1291     else // Invalid IP address length
       
  1292         {
       
  1293         LOG( SIMPLE, "SATENGINE: CSatBIPGPRSDataChannel::DestAddress \
       
  1294         invalid IP address" )
       
  1295         destinationAddress = TInetAddr( 0 , 0 );
       
  1296         destinationAddress.SetFamily( KAFUnspec );
       
  1297         }
       
  1298 
       
  1299     LOG( SIMPLE, "SATENGINE: CSatBIPGPRSDataChannel::DestAddress exiting" )
       
  1300     return destinationAddress;
       
  1301     }
       
  1302 
       
  1303 // ---------------------------------------------------------------------------
       
  1304 // Write Primary PDP Context QoS parameters to RCmManager
       
  1305 // ---------------------------------------------------------------------------
       
  1306 //
       
  1307 void CSatBIPGPRSDataChannel::WritePrimaryPDPContextQoSParamsL()
       
  1308     {
       
  1309     LOG( SIMPLE,
       
  1310         "SATENGINE: CSatBIPGPRSDataChannel::WritePrimaryPDPContextQoSParamsL \
       
  1311         calling" )
       
  1312 
       
  1313     if ( iConnInfo.iOverrideSet )
       
  1314         {
       
  1315         LOG( SIMPLE,
       
  1316         "SATENGINE: CSatBIPGPRSDataChannel::WritePrimaryPDPContextQoSParamsL \
       
  1317         iConnInfo.iOverrideSet true" )
       
  1318         
       
  1319         TUint32 iapId( iConnInfo.iOverrideSet->IapId() );
       
  1320         LOG2( SIMPLE, 
       
  1321               "SATENGINE: CSatBIPGPRSDataChannel::WritePrimaryPDPContextQoSParamsL \
       
  1322               IAP id = %d", iapId )
       
  1323         
       
  1324         RPacketQoS::TQoSGPRSRequested reqQoS;
       
  1325         TSatQoSParser::GetRequestedQoSValues( iConnInfo.iBearerParams, 
       
  1326             reqQoS );
       
  1327         TSatQoSParser::TQoSRel5 qosRel5 = TSatQoSParser::ConvertQoS( reqQoS );    
       
  1328         
       
  1329         RCmManager cmManager;
       
  1330         cmManager.OpenLC();
       
  1331 
       
  1332         RCmConnectionMethod cm = cmManager.ConnectionMethodL( iapId );
       
  1333         CleanupClosePushL( cm );
       
  1334         
       
  1335         // Requested traffic class.
       
  1336         // Type of application for which the UMTS bearer service is optimised
       
  1337         cm.SetIntAttributeL( CMManager::EGPRSReqTrafficClass, 
       
  1338                              qosRel5.iTrafficClass );
       
  1339         LOG2( SIMPLE, "  EGPRSReqTrafficClass:    0x%x", 
       
  1340               qosRel5.iTrafficClass )
       
  1341         
       
  1342         // Requested traffic handling priority.                     
       
  1343         // Specifies the relative importance for handling of all SDUs belonging
       
  1344         // to the UMTS bearer compared to the SDUs of other bearers.
       
  1345         cm.SetIntAttributeL( CMManager::EGPRSReqTrafficHandlingPriority, 
       
  1346                              qosRel5.iTrafficHandlingPriority );
       
  1347         LOG2( SIMPLE, "  EGPRSReqTrafficHandlingPriority:    0x%x", 
       
  1348               qosRel5.iTrafficHandlingPriority )                
       
  1349         
       
  1350         // Requested target SDU error ratio.
       
  1351         // Indicates the fraction of SDUs lost or detected as erroneous.               
       
  1352         cm.SetIntAttributeL( CMManager::EGPRSReqSDUErrorRatio, 
       
  1353                              qosRel5.iSduErrorRatio );
       
  1354         LOG2( SIMPLE, "  EGPRSReqSDUErrorRatio:    0x%x", 
       
  1355               qosRel5.iSduErrorRatio )                         
       
  1356                              
       
  1357         // Requested target Bit error ratio.
       
  1358         // Indicates the undetected bit error ratio in the delivered SDU.
       
  1359         cm.SetIntAttributeL( CMManager::EGPRSReqBER, 
       
  1360                              qosRel5.iResidualBer);
       
  1361         LOG2( SIMPLE, "  EGPRSReqBER:    0x%x", 
       
  1362               qosRel5.iResidualBer )                          
       
  1363               
       
  1364         // Requested value for erroneous SDU delivery. 
       
  1365         // Indicates whether SDUs detected as erroneous shall be
       
  1366         // delivered or discarded
       
  1367         cm.SetIntAttributeL( CMManager::EGPRSReqDeliverErroneousSDU, 
       
  1368                              qosRel5.iDeliveryErroneousSdu );
       
  1369         LOG2( SIMPLE, "  EGPRSReqDeliverErroneousSDU:    0x%x", 
       
  1370               qosRel5.iDeliveryErroneousSdu )
       
  1371         
       
  1372         // Requested maximum bit rates on downlink.                     
       
  1373         cm.SetIntAttributeL( CMManager::EGPRSReqMaxDownlinkRate, 
       
  1374                              qosRel5.iMaxBitRate );
       
  1375         LOG2( SIMPLE, "  EGPRSReqMaxDownlinkRate:    0x%x", 
       
  1376               qosRel5.iMaxBitRate )
       
  1377         
       
  1378         // Requested maximum bit rates on uplink      
       
  1379         cm.SetIntAttributeL( CMManager::EGPRSReqMaxUplinkRate, 
       
  1380                              qosRel5.iMaxBitRate );
       
  1381         LOG2( SIMPLE, "  EGPRSReqMaxUplinkRate:    0x%x", 
       
  1382               qosRel5.iMaxBitRate )       
       
  1383         
       
  1384         // Request maximum SDU size.
       
  1385         // The maximum SDU size for which the network shall 
       
  1386         // satisfy the negotiated QoS
       
  1387         cm.SetIntAttributeL( CMManager::EGPRSReqMaxSDUSize, 
       
  1388                              qosRel5.iMaximumSDUSize );
       
  1389         LOG2( SIMPLE, "  EGPRSReqMaxSDUSize:    0x%x", 
       
  1390               qosRel5.iMaximumSDUSize )
       
  1391         
       
  1392         // Requested value for sequential SDU delivery.
       
  1393         // Indicates whether the UMTS bearer shall provide 
       
  1394         // in-sequence SDU delivery or not.
       
  1395         cm.SetIntAttributeL( CMManager::EGPRSReqDeliveryOrder, 
       
  1396                              qosRel5.iDeliveryOrder );
       
  1397         LOG2( SIMPLE, "  EGPRSReqDeliveryOrder:    0x%x", 
       
  1398               qosRel5.iDeliveryOrder )
       
  1399 
       
  1400         cm.UpdateL();
       
  1401         
       
  1402         CleanupStack::PopAndDestroy( &cm );
       
  1403         CleanupStack::PopAndDestroy( &cmManager );
       
  1404         }
       
  1405    
       
  1406     LOG( SIMPLE,
       
  1407         "SATENGINE: CSatBIPGPRSDataChannel::WritePrimaryPDPContextQoSParamsL \
       
  1408         exiting" )
       
  1409     }
       
  1410 
       
  1411 // ---------------------------------------------------------------------------
       
  1412 // Write default QoS Parameters to RCmManager
       
  1413 // ---------------------------------------------------------------------------
       
  1414 //
       
  1415 void CSatBIPGPRSDataChannel::WriteDefaultQoSParamsL()
       
  1416     {
       
  1417     LOG( SIMPLE,
       
  1418         "SATENGINE: CSatBIPGPRSDataChannel::WriteDefaultQoSParamsL \
       
  1419         calling" )
       
  1420         
       
  1421     if ( iConnInfo.iOverrideSet )
       
  1422         {
       
  1423         LOG( SIMPLE,
       
  1424         "SATENGINE: CSatBIPGPRSDataChannel::WriteDefaultQoSParamsL \
       
  1425         iConnInfo.iOverrideSet true" );
       
  1426         TUint32 iapId( iConnInfo.iOverrideSet->IapId() ); 
       
  1427         LOG2( SIMPLE, 
       
  1428               "SATENGINE: CSatBIPGPRSDataChannel::WriteDefaultQoSParamsL \
       
  1429               IAP id = %d", iapId )        
       
  1430         
       
  1431         RCmManager cmManager;
       
  1432         cmManager.OpenLC();
       
  1433 
       
  1434         RCmConnectionMethod cm = cmManager.ConnectionMethodL( iapId );
       
  1435         CleanupClosePushL( cm );
       
  1436         
       
  1437         cm.SetIntAttributeL( CMManager::EGPRSReqTrafficClass, 
       
  1438                              RPacketQoS::ETrafficClassUnspecified );
       
  1439                              
       
  1440         cm.SetIntAttributeL( CMManager::EGPRSReqTrafficHandlingPriority, 
       
  1441                              RPacketQoS::ETrafficPriorityUnspecified );
       
  1442                              
       
  1443         cm.SetIntAttributeL( CMManager::EGPRSReqSDUErrorRatio, 
       
  1444                              RPacketQoS::ESDUErrorRatioUnspecified );
       
  1445                              
       
  1446         cm.SetIntAttributeL( CMManager::EGPRSReqBER, 
       
  1447                              RPacketQoS::EBERUnspecified );
       
  1448         
       
  1449         cm.SetIntAttributeL( CMManager::EGPRSReqDeliverErroneousSDU, 
       
  1450                              RPacketQoS::EErroneousSDUDeliveryUnspecified );
       
  1451                              
       
  1452         cm.SetIntAttributeL( CMManager::EGPRSReqMaxDownlinkRate, 0 );
       
  1453         
       
  1454         cm.SetIntAttributeL( CMManager::EGPRSReqMaxUplinkRate, 0 );
       
  1455         
       
  1456         cm.SetIntAttributeL( CMManager::EGPRSReqMaxSDUSize, 0 );
       
  1457         
       
  1458         cm.SetIntAttributeL( CMManager::EGPRSReqDeliveryOrder, 
       
  1459                              RPacketQoS::EDeliveryOrderUnspecified );
       
  1460 
       
  1461         LOG( SIMPLE,
       
  1462         "SATENGINE: CSatBIPGPRSDataChannel::WriteDefaultQoSParamsL \
       
  1463         set default QoS params" );
       
  1464 
       
  1465         cm.UpdateL();
       
  1466         
       
  1467         CleanupStack::PopAndDestroy( &cm );
       
  1468         CleanupStack::PopAndDestroy( &cmManager );
       
  1469         }
       
  1470     
       
  1471     LOG( SIMPLE,
       
  1472         "SATENGINE: CSatBIPGPRSDataChannel::WriteDefaultQoSParamsL \
       
  1473         exiting" )
       
  1474     }
       
  1475 
       
  1476 // ---------------------------------------------------------------------------
       
  1477 // Set QoS for connection or subconnection
       
  1478 // ---------------------------------------------------------------------------
       
  1479 //
       
  1480 void CSatBIPGPRSDataChannel::SetConnQoSParamsL()
       
  1481     {
       
  1482     LOG( SIMPLE,
       
  1483         "SATENGINE: CSatBIPGPRSDataChannel::SetConnQoSParamsL calling" )
       
  1484     
       
  1485     RPacketQoS::TQoSGPRSNegotiated negQoS;  // The negotiated QoS
       
  1486     
       
  1487     // If using Dummy TSY, set the negotiated QoS directly by hard-codes,
       
  1488     // otherwise, fetch negotiated QoS for primary context(by ETel API), set QoS
       
  1489     // for secondary context. 
       
  1490 #ifdef SAT_USE_DUMMY_TSY    
       
  1491     // Set the negotiated QoS directly if using Dummy TSY
       
  1492     LOG( NORMAL, "SATENGINE: CSatBIPGPRSDataChannel::ActivateConnectionL\
       
  1493         don't need to set qos for dummy tsy" )
       
  1494     negQoS.iPrecedence = RPacketQoS::EPriorityHighPrecedence;
       
  1495     negQoS.iDelay = RPacketQoS::EDelayClass4;
       
  1496     negQoS.iReliability = RPacketQoS::EReliabilityClass3;
       
  1497     negQoS.iPeakThroughput = RPacketQoS::EPeakThroughput256000;
       
  1498     negQoS.iMeanThroughput = RPacketQoS::EUnspecifiedMeanThroughput;
       
  1499     TSatQoSParser::GetNegotiatedQoSValues( negQoS, iConnInfo.iBearerParams );
       
  1500     // Set last bearer param to IP Protocol
       
  1501     iConnInfo.iBearerParams[KProtocolPos] = KReqPacketProtType;     
       
  1502 #else   // Set QoS for channels
       
  1503     if ( iUtils.IsSubConnectionActivated() ) 
       
  1504         {
       
  1505         // Set QoS params, granted QoS will be fetched after connected
       
  1506          LOG( NORMAL, "SATENGINE: CSatBIPGPRSDataChannel::ActivateConnectionL\
       
  1507                 Set QoS values for SubConnection" )
       
  1508         SetSubConQoSParamsL();
       
  1509         }
       
  1510     else
       
  1511         {
       
  1512         // Primary PDP Context need to be fetched by ETel API
       
  1513          RPacketQoS::TQoSGPRSRequested reqQoS;
       
  1514          TSatQoSParser::GetRequestedQoSValues( iConnInfo.iBearerParams, 
       
  1515             reqQoS );
       
  1516         negQoS = iUtils.ProposeQoSParametersL( reqQoS );
       
  1517         TSatQoSParser::GetNegotiatedQoSValues( negQoS, 
       
  1518             iConnInfo.iBearerParams );
       
  1519         // Set last bearer param to IP Protocol
       
  1520         iConnInfo.iBearerParams[KProtocolPos] = KReqPacketProtType;      
       
  1521         }
       
  1522 #endif
       
  1523         
       
  1524     LOG( SIMPLE,
       
  1525         "SATENGINE: CSatBIPGPRSDataChannel::SetConnQoSParamsL exiting" )
       
  1526     }
       
  1527 
       
  1528 // ---------------------------------------------------------------------------
       
  1529 // GetSubConQoSR5ParamsFromEvent
       
  1530 // ---------------------------------------------------------------------------
       
  1531 //
       
  1532 TInt CSatBIPGPRSDataChannel::GetSubConQoSR5ParamsFromEvent(
       
  1533     CSubConNotificationEvent& aEvent, 
       
  1534     TSatQoSParser::TQoSRel5& aNegQoSRel5 )
       
  1535     {
       
  1536     LOG( SIMPLE, 
       
  1537         "SATENGINE: CSatBIPGPRSDataChannel::GetSubConQoSR5ParamsFromEvent \
       
  1538         calling" )
       
  1539     TInt errCode( KErrNone );
       
  1540     
       
  1541     CSubConGenEventParamsGranted* grantedEvent = 
       
  1542         static_cast<CSubConGenEventParamsGranted*>( &aEvent );
       
  1543     
       
  1544     TInt extSetNum = grantedEvent->GetNumExtensionSets();
       
  1545     LOG2( NORMAL, 
       
  1546         "SATENGINE: GetSubConQoSR5ParamsFromEvent extSetNum :%d ", extSetNum )
       
  1547                  
       
  1548     const CSubConExtensionParameterSet* grantedExtParams = 
       
  1549         grantedEvent->GetExtensionSet( extSetNum-1 );
       
  1550     
       
  1551     if ( grantedExtParams )
       
  1552         {
       
  1553         CSubConQosR5ParamSet* paramSet;
       
  1554         paramSet = ( CSubConQosR5ParamSet* )grantedExtParams;
       
  1555         
       
  1556         if ( paramSet )
       
  1557             {
       
  1558             aNegQoSRel5.iTrafficClass = paramSet->GetTrafficClass();
       
  1559             aNegQoSRel5.iTrafficHandlingPriority =
       
  1560                 paramSet->GetTrafficHandlingPriority();
       
  1561             aNegQoSRel5.iSduErrorRatio = paramSet->GetSDUErrorRatio();
       
  1562             aNegQoSRel5.iResidualBer = paramSet->GetResidualBitErrorRatio();
       
  1563             aNegQoSRel5.iDeliveryErroneousSdu = 
       
  1564                 paramSet->GetErroneousSDUDelivery();
       
  1565             aNegQoSRel5.iMaxBitRate = Max( paramSet->GetMaxBitrateUplink(),
       
  1566                                         paramSet->GetMaxBitrateDownlink() );
       
  1567             aNegQoSRel5.iMaximumSDUSize = paramSet->GetMaxSduSize();
       
  1568             aNegQoSRel5.iDeliveryOrder = paramSet->GetDeliveryOrder();
       
  1569                 
       
  1570             LOG2( SIMPLE, "Negotiated TrafficClass: %d", 
       
  1571                 aNegQoSRel5.iTrafficClass )
       
  1572             LOG2( SIMPLE, "Negotiated TrafficHandlingPriority: %d", 
       
  1573                 aNegQoSRel5.iTrafficHandlingPriority )
       
  1574             LOG2( SIMPLE, "Negotiated SDUErrorRatio: %d", 
       
  1575                 aNegQoSRel5.iSduErrorRatio )
       
  1576             LOG2( SIMPLE, "Negotiated ResidualBitErrorRatio: %d", 
       
  1577                 aNegQoSRel5.iResidualBer )
       
  1578             LOG2( SIMPLE, "Negotiated ErroneousSDUDelivery: %d", 
       
  1579                 aNegQoSRel5.iDeliveryErroneousSdu )
       
  1580             LOG2( SIMPLE, "Negotiated Maxbitrate: %d", 
       
  1581                 aNegQoSRel5.iMaxBitRate )
       
  1582             LOG2( SIMPLE, "Negotiated MaximumSDUSize: %d", 
       
  1583                 aNegQoSRel5.iMaximumSDUSize )
       
  1584             LOG2( SIMPLE, "Negotiated DeliveryOrder: %d", 
       
  1585                 aNegQoSRel5.iDeliveryOrder )
       
  1586             }
       
  1587         else
       
  1588             {
       
  1589             LOG( NORMAL, "SATENGINE: GetSubConQoSR5ParamsFromEvent\
       
  1590                 Can't get CSubConQosR5ParamSet " )
       
  1591             errCode = KErrNotSupported;
       
  1592             }
       
  1593         }
       
  1594     else
       
  1595         {
       
  1596         LOG( NORMAL, "SATENGINE: GetSubConQoSR5ParamsFromEvent\
       
  1597                 Can't get granted CSubConExtensionParameterSet " )
       
  1598         errCode = KErrNotSupported;
       
  1599         }
       
  1600      
       
  1601     LOG2( SIMPLE,
       
  1602         "SATENGINE: CSatBIPGPRSDataChannel::GetSubConQoSR5ParamsFromEvent \
       
  1603         exiting, errCode: %d", errCode )
       
  1604     return errCode;
       
  1605     }
       
  1606     
       
  1607 // ---------------------------------------------------------------------------
       
  1608 // GrantedEventReceivedL
       
  1609 // ---------------------------------------------------------------------------
       
  1610 //   
       
  1611 void CSatBIPGPRSDataChannel::GrantedEventReceivedL( 
       
  1612     const TNotificationEventBuf& aEventBuffer )
       
  1613     {
       
  1614     LOG( SIMPLE, 
       
  1615         "SATENGINE: CSatBIPGPRSDataChannel::GrantedEventReceivedL calling" )
       
  1616     TInt errCode( KErrNone );
       
  1617     RPacketQoS::TQoSGPRSNegotiated negQoS;
       
  1618     
       
  1619     // Exacting information from receieved events
       
  1620 	CSubConNotificationEvent* event = 
       
  1621         CSubConNotificationEvent::NewL( aEventBuffer );
       
  1622         
       
  1623     if ( KSubConnGenericEventsImplUid == event->GroupId() )
       
  1624         {
       
  1625         LOG( NORMAL, "SATENGINE: GrantedEventReceivedL \
       
  1626             event->GroupId() == KSubConnGenericEventsImplUid" )
       
  1627         TSatQoSParser::TQoSRel5 negQoSRel5;
       
  1628                 
       
  1629         switch ( event->Id() )
       
  1630             {
       
  1631             case KSubConGenericEventParamsGranted:
       
  1632                 {
       
  1633                 LOG( NORMAL, 
       
  1634                     "SATENGINE: GrantedEventReceivedL Request granted" )
       
  1635                       
       
  1636                 // Get the granted param set from event
       
  1637                 errCode = GetSubConQoSR5ParamsFromEvent( *event, negQoSRel5 );
       
  1638                 LOG2( NORMAL, 
       
  1639                        "SATENGINE: GetSubConQoSR5ParamsFromEvent errCode %d ", 
       
  1640                        errCode )
       
  1641                 User::LeaveIfError( errCode );
       
  1642                 break;
       
  1643                 }
       
  1644             case KSubConGenericEventParamsRejected:
       
  1645                 {
       
  1646                 LOG( NORMAL, 
       
  1647                         "SATENGINE: GrantedEventReceivedL Request Rejected" )
       
  1648                         
       
  1649                 CSubConGenEventParamsRejected* rejectedEvent = 
       
  1650                      static_cast<CSubConGenEventParamsRejected*>( event );
       
  1651                 errCode = rejectedEvent->Error();
       
  1652                      
       
  1653                 LOG2( NORMAL, 
       
  1654                         "SATENGINE: GrantedEventReceivedL\
       
  1655 	                        rejectedEvent->Error() = %d", errCode )
       
  1656 	            User::LeaveIfError( errCode );
       
  1657 	            break;
       
  1658                 }
       
  1659             default:
       
  1660                 {
       
  1661                 LOG( NORMAL, 
       
  1662                     "SATENGINE: GrantedEventReceivedL. EventId \
       
  1663                     not in KSubConGenericEventParamsRejected/Granted " )
       
  1664                 // Do nothing
       
  1665                 break;
       
  1666                 }
       
  1667             }                
       
  1668         // convert negQoSRel5 to negQoS
       
  1669         negQoS = TSatQoSParser::ConvertNegotiatedQoS( negQoSRel5 );
       
  1670                              
       
  1671         TSatQoSParser::GetNegotiatedQoSValues( negQoS, 
       
  1672             iConnInfo.iBearerParams );
       
  1673                 
       
  1674         // Set last bearer param to IP Protocol
       
  1675         iConnInfo.iBearerParams[KProtocolPos] = KReqPacketProtType;
       
  1676         }
       
  1677 
       
  1678     LOG( SIMPLE, 
       
  1679         "SATENGINE: CSatBIPGPRSDataChannel::GrantedEventReceivedL exiting" )
       
  1680     }
       
  1681     
       
  1682 // ---------------------------------------------------------------------------
       
  1683 // Returns sub connection
       
  1684 // ---------------------------------------------------------------------------
       
  1685 //
       
  1686 RSubConnection& CSatBIPGPRSDataChannel::SubConnection() const
       
  1687     {
       
  1688     LOG( SIMPLE, "SATENGINE: CSatBIPGPRSDataChannel::SubConnection\
       
  1689         calling - exiting" )
       
  1690     return iSubConnection;
       
  1691     }
       
  1692