telephonyserverplugins/simatktsy/exportinc/utility/ttlv.h
changeset 0 3553901f7fa8
child 24 6638e7f4bd8f
equal deleted inserted replaced
-1:000000000000 0:3553901f7fa8
       
     1 /*
       
     2 * Copyright (c) 2005-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        : TTlv.h
       
    16 * Part of     : Series 60 / utility
       
    17 * Based on 3GPP TS 11.14 V8.8.0 
       
    18 * Version     : 1.0
       
    19 *
       
    20 */
       
    21 
       
    22 
       
    23 
       
    24 //  INCLUDES
       
    25 #ifndef TTLV_H
       
    26 #define TTLV_H
       
    27 
       
    28 #include <cstktsy/bertlv_defs.h>			// BerTlv constants
       
    29 
       
    30 //  CONSTANTS 
       
    31 
       
    32     //none
       
    33 
       
    34 //  MACROS  
       
    35 
       
    36     //none
       
    37 
       
    38 //  DATA TYPES  
       
    39 
       
    40     //none
       
    41 
       
    42 //  EXTERNAL DATA STRUCTURES  
       
    43 
       
    44     //none
       
    45 
       
    46 //  FUNCTION PROTOTYPES  
       
    47 
       
    48     //none
       
    49 
       
    50 //  FORWARD DECLARATIONS
       
    51 
       
    52     //none
       
    53 
       
    54 // DESCRIPTION
       
    55 // TLV type: Tag Length Value(s)
       
    56 // Generic BER-TLV constructor class, can be used to create TLVs
       
    57 // You do not need to worry about lenghts; Example usage: 
       
    58 //                 TTlv tlv;
       
    59 //                 tlv.Begin( KxxBerTag);  <--- top level tag
       
    60 //                 tlv.AddTag( KxxxTag )   <--- simple tags
       
    61 //                 tlv.AddByte(...)        <--- add values for this tag
       
    62 //                 tlv.AddByte(...)
       
    63 //                 .... add more simple tags and values..
       
    64 //                 result = tlv.End();     <--- ends construction and returns 
       
    65 //                                              the BER-TLV
       
    66 
       
    67 class TTlvBase
       
    68     {
       
    69     public: // Constructor
       
    70 
       
    71         /**
       
    72         * Constructor
       
    73         * @param aData: data to be inserted
       
    74         */
       
    75         IMPORT_C TTlvBase( TDes8& aData );
       
    76 
       
    77     public:
       
    78 
       
    79         /**
       
    80         * Begin TLV construction
       
    81         * @param aTag:  BER-TLV tag
       
    82         * @return None
       
    83         */
       
    84         IMPORT_C void Begin( TUint8 aTag );
       
    85 
       
    86         /**
       
    87         * Start new simple TLV
       
    88         * @param aTag:  simple tag
       
    89         * @return None
       
    90         */
       
    91         IMPORT_C void AddTag( TUint8 aTag );
       
    92 
       
    93         /**
       
    94         * Add byte value to simple TLV
       
    95         * @param aValue: byte value
       
    96         * @return None
       
    97         */
       
    98         IMPORT_C void AddByte( TUint8 aValue );
       
    99 
       
   100         /**
       
   101         * Add descriptor value to simple TLV
       
   102         * @param aValue: descriptor value
       
   103         * @return None
       
   104         */
       
   105         IMPORT_C void AddData( const TDesC8& aValue );
       
   106 
       
   107         /**
       
   108         * End TLV construction
       
   109         * @param None
       
   110         * @return descriptor containing BER-TLV
       
   111         */
       
   112         IMPORT_C const TDesC8& End();
       
   113 
       
   114         /**
       
   115         * Return data, calculated without
       
   116         * top level tag. 
       
   117         * @param None
       
   118         * @return descriptor containing BER-TLV
       
   119         */
       
   120         IMPORT_C const TDesC8& GetDataWithoutTopLevelTag();
       
   121 
       
   122     protected: // Data
       
   123         TInt       iLenIndex;
       
   124         TDes8&     iData;
       
   125     };
       
   126 
       
   127 // DESCRIPTION
       
   128 // Type for Tag Length Value buffer.
       
   129 // Define TLV that is smaller than default max size of 255
       
   130 
       
   131 template <TInt S>
       
   132 class TTlvBuf : public TTlvBase
       
   133     {
       
   134     public: // Constructor
       
   135 
       
   136         /**
       
   137         * Default constructor
       
   138         */
       
   139         TTlvBuf():TTlvBase(iBuffer)
       
   140         	{
       
   141         	}
       
   142     private: // Data
       
   143 
       
   144         TBuf8<S>   iBuffer;
       
   145     };
       
   146 
       
   147 // DESCRIPTION
       
   148 // Type for Tag Length Value buffer
       
   149 // default TLV with size of 255
       
   150 
       
   151 class TTlv : public TTlvBase
       
   152     {
       
   153     public:
       
   154     
       
   155         /**
       
   156         * Default constructor
       
   157         */        
       
   158         TTlv() : TTlvBase(iBuffer)
       
   159         	{
       
   160         	}
       
   161  
       
   162     private:
       
   163         // TLV must fit in APDU limits (255 bytes)
       
   164         // therefore the maximum possible TLV size is 255
       
   165         TBuf8<KTlvMaxSize>   iBuffer;
       
   166     };
       
   167 
       
   168 #endif // TTLV_H
       
   169 
       
   170 // End of File