telephonyserverplugins/simatktsy/exportinc/utility/tsatutility.h
changeset 0 3553901f7fa8
child 24 6638e7f4bd8f
equal deleted inserted replaced
-1:000000000000 0:3553901f7fa8
       
     1 /*
       
     2 * Copyright (c) 2006-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:
       
    15 * Name        : TSatUtility.h
       
    16 * Part of     : Common SIM ATK TSY / commonsimatktsy
       
    17 * This file contains the Sat Utility class definition.
       
    18 * Version     : 1.0
       
    19 *
       
    20 */
       
    21 
       
    22 
       
    23 
       
    24 #ifndef TSATUTILITY_H
       
    25 #define TSATUTILITY_H
       
    26 
       
    27 //  INCLUDES
       
    28 #include <etelsat.h>    // Symbian Etel Sat related types
       
    29 #include <cstktsy/CBerTlv.h>    // BerTlv    
       
    30 
       
    31 // CONSTANTS
       
    32 const TUint8 KZeroCharacterCode		        = 0x30;
       
    33 const TUint8 KPacked7BitTextMask	        = 0x0C;
       
    34 const TUint8 KCrShiftedOneBitToLeft 	    = 0x1A;
       
    35 const TUint8 KUCS2TextCodingMask    	    = 0x08;
       
    36 const TUint8 KUCS2ArabicCoding 	    	    = 0x80;
       
    37 const TUint8 KUCS2GreekCoding	    	    = 0x81;
       
    38 const TUint8 KUCS2TurkishCoding	    	    = 0x82;
       
    39 // The card ID is always zero as long as only one supported
       
    40 const TUint8 KCardId0                        = 0x00;
       
    41 
       
    42 // From 3GPP TS 51.11, 9.4.2 Responses to commands which are postponed
       
    43 const TUint8 KSw1SatBusy 		    	    = 0x93;
       
    44 
       
    45 // From 3GPP TS 03.40, 9.2.3.22	TP Failure Cause (TP FCS) 
       
    46 // SMS-PP SIM DDL error
       
    47 const TUint8 KSmsPpSimDdlError 	    	    = 0xD5;
       
    48 // SMSP-PP SAT busy
       
    49 const TUint8 KSmsPpSatBusy 		    	    = 0xD4;
       
    50 
       
    51 // From 3GPP TS 11.11, 9.4	Status conditions returned by the card
       
    52 const TUint8 KSw1NormalEnding               = 0x90;
       
    53 const TUint8 KSw2NormalEnding               = 0x00;
       
    54 
       
    55 // From 3GPP TS 11.10-4, 27.22.8 MO SHORT MESSAGE CONTROL BY SIM 
       
    56 const TUint8 KMoSmCtrlResultAllowed 					= 0x00;
       
    57 const TUint8 KMoSmCtrlResultNotAllowed 					= 0x01;
       
    58 const TUint8 KMoSmCtrlResultAllowedWithModifications 	= 0x02;
       
    59 
       
    60 // From 3GPP TS 22.030 7.0.0 Structure of the MMI (Annex B)
       
    61 const TUint16 KSsAllForwardings             = 0x0002; 
       
    62 const TUint16 KSsAllCondForwardings         = 0x0004; 
       
    63 const TUint16 KSsForwUnconditional          = 0x0015; 
       
    64 const TUint16 KSsForwBusy                   = 0x0043; 
       
    65 const TUint16 KSsForwNoReply                = 0x003D; 
       
    66 const TUint16 KSsForwNotReachable           = 0x003E;
       
    67  
       
    68 // TON NPI
       
    69 // This just indicates that the TON NPI value is not set, TSY specific def.
       
    70 const TUint8 KTonNpiNotSet                  = 0xff;               
       
    71 // From 3GPP TS 27.007-460, 8.33 Set Voice Call Number +CSVM
       
    72 const TUint8 KTonNpiInternational           = 0x91;
       
    73 const TUint8 KTonNpiUnknown                 = 0x81;
       
    74 
       
    75 // General string length limitations
       
    76 const TUint8 KMaxAddressLength          	= 255;
       
    77 // From 3GPP TS 23.038-450, 6.1.2.3	USSD packing
       
    78 // String max length 160b + additional info in TR (1b) and DCS in PCmd (1b)
       
    79 const TUint8 KMaxUssdStringLengthInChars    = 182;
       
    80 const TUint8 KMaxUssdStringLengthInBytes    = 161;
       
    81 // Etel accepts SS strings with maximum length 242
       
    82 const TUint8 KMaxSSStringLength             = 242;
       
    83 const TUint8 KSizeOfConversionArray         = 63;
       
    84 const TUint8 KNumberMaxLength 		        = 123;
       
    85 const TUint8 KOperatorCodeLength            = 3;
       
    86 const TUint8 KAsciiBcdTableLength           = 15;
       
    87 
       
    88 // This applies for Parameters, DCS and Protocol ID (3GPP TS 23.038, 5 CBS Data
       
    89 // Coding Scheme; 3GPP TS 23.040, 9.2.3.9 TP Protocol Identifier (TP PID);
       
    90 // 3GPP TS 23.040, 9.2.3.1 - 9.2.3.5
       
    91 const TUint8 KSmsTpduByteUnknownOrReserved  = 0xFF;
       
    92 
       
    93 // Constants used in bit operations
       
    94 const TUint8 KMaskF0                        = 0xF0;
       
    95 
       
    96 // Bcd->ascii translation table
       
    97 static const TUint8 KAscii[16] =
       
    98     {
       
    99      '0', '1', '2', '3', '4', '5', '6', '7',
       
   100      '8', '9', '*', '#', 'p', 'w', '.',  0
       
   101     };
       
   102 
       
   103 // 3GPP TS 11.11, EFadn
       
   104 static const TUint8 KAsciiToBCD[KAsciiBcdTableLength][2] =
       
   105     { 
       
   106     { '0', 0x00 }, { '1', 0x01 }, { '2', 0x02 }, { '3', 0x03 },
       
   107     { '4', 0x04 }, { '5', 0x05 }, { '6', 0x06 }, { '7', 0x07 },
       
   108     { '8', 0x08 }, { '9', 0x09 }, { '*', 0x0A }, { '#', 0x0B },
       
   109     { 'p', 0x0C }, /*DTMF*/ 
       
   110     { 'w', 0x0D }, /*Wild*/ 
       
   111     { '.', 0x0E }, /*RFU*/ };
       
   112     
       
   113 // GSM 7-bit ->unicode translation table
       
   114 // See 3GPP TS 23.038
       
   115 static const TUint16 KUnicode[128] =
       
   116     {
       
   117     0x0040, 0x00A3, 0x0024, 0x00A5, 0x00E8, 0x00E9, 0x00F9, 0x00EC, 
       
   118     0x00F2, 0x00C7, 0x000A, 0x00D8, 0x00F8, 0x000D, 0x00C5, 0x00E5,
       
   119     0x0394, 0x005F, 0x03A6, 0x0393, 0x039B, 0x03A9, 0x03A0, 0x03A8, 
       
   120     0x03A3, 0x0398, 0x039E, 0x001B, 0x00C6, 0x00E6, 0x00DF, 0x00C9,
       
   121     0x0020, 0x0021, 0x0022, 0x0023, 0x00A4, 0x0025, 0x0026, 0x0027,
       
   122     0x0028, 0x0029, 0x002A, 0x002B, 0x002C, 0x002D, 0x002E, 0x002F,
       
   123     0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0037,
       
   124     0x0038, 0x0039, 0x003A, 0x003B, 0x003C, 0x003D, 0x003E, 0x003F,
       
   125     0x00A1, 0x0041, 0x0042, 0x0043, 0x0044, 0x0045, 0x0046, 0x0047,
       
   126     0x0048, 0x0049, 0x004A, 0x004B, 0x004C, 0x004D, 0x004E, 0x004F,
       
   127     0x0050, 0x0051, 0x0052, 0x0053, 0x0054, 0x0055, 0x0056, 0x0057, 
       
   128     0x0058, 0x0059, 0x005A, 0x00C4, 0x00D6, 0x00D1, 0x00DC, 0x00A7, 
       
   129     0x00BF, 0x0061, 0x0062, 0x0063, 0x0064, 0x0065, 0x0066, 0x0067, 
       
   130     0x0068, 0x0069, 0x006A, 0x006B, 0x006C, 0x006D, 0x006E, 0x006F,
       
   131     0x0070, 0x0071, 0x0072, 0x0073, 0x0074, 0x0075, 0x0076, 0x0077, 
       
   132     0x0078, 0x0079, 0x007A, 0x00E4, 0x00F6, 0x00F1, 0x00FC, 0x00E0  
       
   133     };
       
   134 
       
   135 
       
   136 static const TUint16 KUnicode16ToSms7[63][2] =
       
   137     { 
       
   138     { 0x0040, 0x00 }, { 0x00A3, 0x01 }, { 0x0024, 0x02 }, { 0x00A5, 0x03 },
       
   139     { 0x00E8, 0x04 }, { 0x00E9, 0x05 }, { 0x00F9, 0x06 }, { 0x00EC, 0x07 },
       
   140     { 0x00F2, 0x08 }, { 0x00C7, 0x09 }, { 0x00D8, 0x0B }, { 0x00F8, 0x0C },
       
   141     { 0x21B5, 0x0D }, { 0x000D, 0x0D }, { 0x2029, 0x0D }, { 0x00C5, 0x0E },
       
   142     { 0x00E5, 0x0F }, { 0x0394, 0x10 }, { 0x005F, 0x11 }, { 0x03A6, 0x12 },
       
   143     { 0x0393, 0x13 }, { 0x039B, 0x14 }, { 0x03A9, 0x15 }, { 0x03A0, 0x16 },
       
   144     { 0x03A8, 0x17 }, { 0x03A3, 0x18 }, { 0x0398, 0x19 }, { 0x039E, 0x1A },
       
   145     { 0x00C6, 0x1C }, { 0x00E6, 0x1D }, { 0x00DF, 0x1E }, { 0x00C9, 0x1F },
       
   146     { 0x00A4, 0x24 }, { 0x00A1, 0x40 }, { 0x00C4, 0x5B }, { 0x00D6, 0x5C },
       
   147     { 0x00D1, 0x5D }, { 0x00DC, 0x5E }, { 0x00A7, 0x5F }, { 0x00BF, 0x60 },
       
   148     { 0x00E4, 0x7B }, { 0x00F6, 0x7C }, { 0x00F1, 0x7D }, { 0x00FC, 0x7E },
       
   149     { 0x00E0, 0x7F }, { 0x007B, 0x1B }, { 0x007B, 0x28 }, { 0x007D, 0x1B },
       
   150     { 0x007D, 0x29 }, { 0x005B, 0x1B }, { 0x005B, 0x3C }, { 0x007E, 0x1B },
       
   151     { 0x007E, 0x3D }, { 0x005D, 0x1B }, { 0x005D, 0x3E }, { 0x005C, 0x1B },
       
   152     { 0x005C, 0x2F }, { 0x005E, 0x1B }, { 0x005E, 0x14 }, { 0x007C, 0x1B },
       
   153     { 0x007C, 0x40 }, { 0x20AC, 0x1B }, { 0x20AC, 0x65 } 
       
   154     };
       
   155 
       
   156 // SMS data coding schemes
       
   157 enum TSmsDcs
       
   158 	{
       
   159 	ESmsUnknownOrReservedDcs = KSmsTpduByteUnknownOrReserved,
       
   160 	ESms7BitDcs = 0x00,
       
   161 	ESms8BitDcs = 0x04,
       
   162 	ESms16BitDcs = 0x08
       
   163 	};
       
   164 
       
   165 // DESCRIPTION
       
   166 /**
       
   167 * This class includes small aid fuctions
       
   168 * @lib simatktsy
       
   169 * @since S60 3.1
       
   170 */
       
   171 class TSatUtility
       
   172     {
       
   173 
       
   174     public: // New functions
       
   175 
       
   176         /**
       
   177         * Map TON and NPI to RSat TON and NPI values
       
   178         * @param aTonAndNpi: Source TON and NPI
       
   179         * @param aTon: Mapped Type of number
       
   180         * @param aNpi: Mapped Numbering plan
       
   181         */
       
   182 		IMPORT_C static void TonAndNpi( TInt aTonAndNpi, 
       
   183             RSat::TTypeOfNumber* aTon,
       
   184             RSat::TNumberingPlan* aNpi );
       
   185 
       
   186         /**
       
   187         * Converts 7-bit packed string to 8-bit unpacked format
       
   188         * @param aSource: Pointer to the const data
       
   189         * @param aTarget converted 8-bit unpacked string
       
   190         * @return KErrNone or KErrOverflow if string was too long
       
   191         */
       
   192         IMPORT_C static TInt Packed7to8Unpacked( const TPtrC8 aSource, 
       
   193             TDes8& aTarget );
       
   194 
       
   195         /**
       
   196         * Converts UCS2 string to 7-bit packed format
       
   197         * @param aInput: is source
       
   198         * @param aOutput: converted 7-bit packed string
       
   199         */
       
   200         IMPORT_C static void UCSToPacked7( const TPtrC aInput, 
       
   201             TDes8& aOutput );
       
   202         
       
   203         /**
       
   204         * Converts Binary Coded Decimal to ASCII
       
   205         * @param aInput is source
       
   206         * @param aOutput converted 8-bit string
       
   207         * @return KErrNone or KErrOverflow if string was too long
       
   208         */
       
   209         IMPORT_C static TInt BCDToAscii( const TPtrC8 aInput, TDes8& aOutput );	
       
   210 
       
   211         /**
       
   212         * Converts Ascii string to Binary Coded Decimal
       
   213         * @param aInput is source
       
   214         * @param aOutput converted 8-bit string
       
   215         * @return KErrNone or KErrOverflow if string was too long
       
   216         */
       
   217         IMPORT_C static TInt AsciiToBCD( const TDesC8& aInput, 
       
   218             TDes8& aOutput );
       
   219 
       
   220         /**
       
   221         * Remove Wild 'w' and Expansion digit '.' from EFadn string.
       
   222         * @param aInput is source
       
   223         * @param aOutput converted 8-bit string
       
   224         */
       
   225         IMPORT_C static void RemoveWildAndExpansionDigit( const TPtrC8 aInput,
       
   226             TDes8& aOutput );
       
   227 
       
   228         /**
       
   229         * Set Alpha identifier as a Unicode text string
       
   230         * and according to the alphabet used
       
   231         * @param aRawData input data that was extracted with 
       
   232         * ETLV_AlphaIdentifier
       
   233         * @param aAlphaId output
       
   234         */
       
   235         IMPORT_C static void SetAlphaId( const TPtrC8 aRawData, TDes& aAlphaId );		
       
   236 
       
   237         /**
       
   238         * Convert integer to BCD format. If number is more than 100 only last
       
   239         * two digits is converted.
       
   240         * @param aTime time
       
   241         * @return converted BCD value
       
   242         */
       
   243         IMPORT_C static TUint8 ConvertToSemiOctet( const TInt aTime );
       
   244 
       
   245         /**
       
   246         * Browse a text in Unicode format, and for some specific characters 
       
   247         * replace with the correct byte value
       
   248         * @param aInput: GSM 7 bit default alphabet string
       
   249         * @param aOutput: Unicode 16 string
       
   250         */
       
   251         IMPORT_C static void Convert7BitToUnicode16( const TDesC8& aInput,
       
   252             TDes16& aOutput );
       
   253 
       
   254         /**
       
   255         * Converts unicode16 string to 7 bit character mode
       
   256         * @param aInput: Unicode 16 string
       
   257         * @param aOutput: Resulting GSM 7 bit default alphabet string
       
   258         * @return KErrNone or KErrOverflow (input string is too long) 
       
   259         */
       
   260         IMPORT_C static TInt ConvertUnicode16To7Bit( const TDesC16& aInput,
       
   261             TDes8& aOutput );
       
   262 
       
   263         /**
       
   264         * Fill in a TDuration structure
       
   265         * @param aBerTlv tlv containing duration data
       
   266         * @param aTDuration duration structure
       
   267         */
       
   268         IMPORT_C static void FillDurationStructure( CBerTlv& aBerTlv, 
       
   269             RSat::TDuration& aTDuration );
       
   270 
       
   271         /**
       
   272         * Fill in a TIconId structure
       
   273         * @param aBerTlv data containing icon address data
       
   274         * @param aTIconId icon id structure
       
   275         * @param aItemNmb item number
       
   276         */
       
   277         IMPORT_C static void FillIconStructure( CBerTlv& aBerTlv, 
       
   278             RSat::TIconId& aTIconId, const TInt aItemNmb = 0 );
       
   279 
       
   280         /**
       
   281         * Set Text string as a Unicode text string
       
   282         * @param aTextString text string
       
   283         * @param aText unicode output text string
       
   284         */
       
   285         IMPORT_C static void SetText( CTlv& aTextTlv, TDes& aUnicodeOutput );
       
   286 
       
   287         /**
       
   288         * Convert Alpha field text string to a Unicode text string. 
       
   289         * @param aSource text string
       
   290         * @param aText unicode output text string
       
   291         */
       
   292         IMPORT_C static void ConvertAlphaFieldsToUnicode( 
       
   293             const TDesC8& aSource, TDes& aTarget );
       
   294             
       
   295         /**
       
   296         * Copy from 16 bit descriptor to 8 bit descriptor with little endian.
       
   297         * Function uses Append method.
       
   298         * @param aSource: source
       
   299         * @param aTarget: target
       
   300         * @return KErrNone or KErrOverflow if string was too long
       
   301         */
       
   302 		IMPORT_C static TInt Copy16to8LE( const TDesC16& aSource, 
       
   303             TDes8& aTarget );
       
   304 
       
   305         /**
       
   306         * Copy from 8 bit descriptor to 16 bit descriptor with little endian.
       
   307         * Function uses Append method.
       
   308         * @param aSource: source
       
   309         * @param aTarget: target
       
   310         * @return KErrNone or KErrOverflow if string was too long
       
   311         */
       
   312         IMPORT_C static TInt Copy8to16LE( const TDesC8& aSource, 
       
   313             TDes16& aTarget );
       
   314 
       
   315         /**
       
   316         * Finds whether the data coding scheme, coded in CBS format,
       
   317         * is 7-bit, 8-bit or 16-bit
       
   318         * @param aDcs Input data coding scheme
       
   319         * @return Converted DCS ( SMS format )
       
   320         */
       
   321         IMPORT_C static TSmsDcs DecodeCbsDcs( const TUint8 aDcs ); 
       
   322         
       
   323         /**
       
   324         * Gets 8 bit byte and copy it to the 16 bit byte with right endian.
       
   325         * @param aSource: source
       
   326         * @param aTarget: target
       
   327         * @param aIndex: index
       
   328         * @return KErrNone or KErrOverflow if string was too long
       
   329         */
       
   330         IMPORT_C static TInt CopyTwo8toOne16LE( const TDesC8& aSource, 
       
   331             TUint16& aTarget, const TInt aIndex ); 
       
   332 	};
       
   333 
       
   334 
       
   335 #endif // TSATUTILITY_H
       
   336 
       
   337 // End of File