24
|
1 |
// Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
2 |
// All rights reserved.
|
|
3 |
// This component and the accompanying materials are made available
|
|
4 |
// under the terms of "Eclipse Public License v1.0"
|
|
5 |
// which accompanies this distribution, and is available
|
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
7 |
//
|
|
8 |
// Initial Contributors:
|
|
9 |
// Nokia Corporation - initial contribution.
|
|
10 |
//
|
|
11 |
// Contributors:
|
|
12 |
//
|
|
13 |
// Description:
|
|
14 |
// Name : CBerTlv.cpp
|
|
15 |
// Part of : Series 60 / utility
|
|
16 |
// Based on 3GPP TS 11.14 V8.8.0
|
|
17 |
// Version : 1.0
|
|
18 |
// EXTERNAL RESOURCES
|
|
19 |
//
|
|
20 |
|
|
21 |
|
|
22 |
|
|
23 |
// Include Files
|
|
24 |
#include "CBerTlv.h" // Header of this class
|
|
25 |
#include "tflogger.h" // For logging
|
|
26 |
|
|
27 |
// External Data Structures
|
|
28 |
// none
|
|
29 |
|
|
30 |
// External Function Prototypes
|
|
31 |
// none
|
|
32 |
|
|
33 |
// LOCAL CONSTANTS AND MACROS
|
|
34 |
// none
|
|
35 |
|
|
36 |
// MODULE DATA STRUCTURES
|
|
37 |
// none
|
|
38 |
|
|
39 |
// Local Data Structures
|
|
40 |
// none
|
|
41 |
|
|
42 |
// Local Function Prototypes
|
|
43 |
// none
|
|
44 |
|
|
45 |
// LOCAL FUNCTIONS
|
|
46 |
// none
|
|
47 |
|
|
48 |
// MEMBER FUNCTIONS
|
|
49 |
|
|
50 |
//=============================================================================
|
|
51 |
|
|
52 |
// -----------------------------------------------------------------------------
|
|
53 |
// CBerTlv::CBerTlv
|
|
54 |
// Constructor
|
|
55 |
// -----------------------------------------------------------------------------
|
|
56 |
//
|
|
57 |
EXPORT_C CBerTlv::CBerTlv
|
|
58 |
(
|
|
59 |
// None
|
|
60 |
)
|
|
61 |
{
|
|
62 |
// None
|
|
63 |
}
|
|
64 |
|
|
65 |
// -----------------------------------------------------------------------------
|
|
66 |
// CBerTlv::TlvByTagValue
|
|
67 |
// Find TLV by tag value. aTlv is set to point to found TLV. If there are more
|
|
68 |
// than one TLV with the same tag then itemNbr can be used to select which one
|
|
69 |
// is returned. If no tags are found return KErrNotFound else KErrNone.
|
|
70 |
// -----------------------------------------------------------------------------
|
|
71 |
//
|
|
72 |
EXPORT_C TInt CBerTlv::TlvByTagValue
|
|
73 |
(
|
|
74 |
CTlv* aTlv, // TLV
|
|
75 |
TUint8 aTlvTagValue, // TLV identifier
|
|
76 |
TInt itemNbr // Item number
|
|
77 |
)
|
|
78 |
{
|
|
79 |
TFLOGSTRING("UTILITY: CBerTlv::TlvByTagValue");
|
|
80 |
TInt currentTlv( 0 );
|
|
81 |
TInt tlvLength( 0 );
|
|
82 |
TInt index( 0 );
|
|
83 |
|
|
84 |
// TLV start index
|
|
85 |
TInt ind( KCommonTlvHeaderLength );
|
|
86 |
TUint8 berTlvLength( 0 );
|
|
87 |
if ( KTwoByteLengthCoding == iData[KTlvLengthStartPosition] )
|
|
88 |
{
|
|
89 |
berTlvLength = iData[KTlvLengthStartPosition + 1];
|
|
90 |
ind = ind + 1;
|
|
91 |
}
|
|
92 |
else
|
|
93 |
{
|
|
94 |
berTlvLength = iData[KTlvLengthStartPosition];
|
|
95 |
}
|
|
96 |
|
|
97 |
for ( TInt i = 0; i < berTlvLength; i += tlvLength )
|
|
98 |
{
|
|
99 |
// First determine if the length of the TLV is coded with 1 or 2 bytes.
|
|
100 |
if ( KTwoByteLengthCoding == iData[ind + 1] )
|
|
101 |
{
|
|
102 |
// Length is coded with 2 bytes -> 1 extra byte required to be
|
|
103 |
// added to total length. Also TLV header bytes (2) must be added
|
|
104 |
// to total length
|
|
105 |
tlvLength = iData[ind + 2] + KTlvHeaderLength + 1;
|
|
106 |
}
|
|
107 |
else
|
|
108 |
{
|
|
109 |
// TLV header bytes (2) must be added to total length
|
|
110 |
tlvLength = iData[ind + 1] + KTlvHeaderLength;
|
|
111 |
}
|
|
112 |
|
|
113 |
currentTlv = iData[ind]&KTagValueMask;
|
|
114 |
|
|
115 |
// Check if TLV in current index is the one that we are searching for
|
|
116 |
if ( aTlvTagValue == currentTlv )
|
|
117 |
{
|
|
118 |
if( index == itemNbr)
|
|
119 |
{
|
|
120 |
TPtrC8 data = ( iData.Mid( ind , tlvLength ) );
|
|
121 |
aTlv->SetData( data );
|
|
122 |
return KErrNone;
|
|
123 |
}
|
|
124 |
else
|
|
125 |
{
|
|
126 |
index++;
|
|
127 |
}
|
|
128 |
}
|
|
129 |
|
|
130 |
ind += tlvLength;
|
|
131 |
}
|
|
132 |
|
|
133 |
return KErrNotFound;
|
|
134 |
}
|
|
135 |
|
|
136 |
// -----------------------------------------------------------------------------
|
|
137 |
// CBerTlv::TlvByTagValueMulti
|
|
138 |
// Find several TLVs by tag value. It is assumed that TLVs are sequential. aTlv
|
|
139 |
// is set to point to TLV sequence. If no tags are found return KErrNotFound
|
|
140 |
// else KErrNone.
|
|
141 |
// -----------------------------------------------------------------------------
|
|
142 |
//
|
|
143 |
EXPORT_C TInt CBerTlv::TlvByTagValueMulti
|
|
144 |
(
|
|
145 |
CTlv* aTlv, // TLV to fill
|
|
146 |
TUint8 aTlvTagValue // Tag of TLV to find
|
|
147 |
)
|
|
148 |
{
|
|
149 |
TFLOGSTRING("UTILITY: CBerTlv::TlvByTagValueMulti");
|
|
150 |
TInt currentTlv( 0 );
|
|
151 |
TInt16 tlvLength( 0 );
|
|
152 |
TInt indMulti( 0 );
|
|
153 |
TInt16 multiLength( 0 );
|
|
154 |
// TLV start index
|
|
155 |
TInt ind( KCommonTlvHeaderLength );
|
|
156 |
TUint8 berTlvLength;
|
|
157 |
// First determine if the length of the BerTLV is coded with 1 or 2 bytes.
|
|
158 |
if ( KTwoByteLengthCoding == iData[KTlvLengthStartPosition] )
|
|
159 |
{
|
|
160 |
berTlvLength = iData[KTlvLengthStartPosition + 1];
|
|
161 |
ind = ind + 1;
|
|
162 |
}
|
|
163 |
else
|
|
164 |
{
|
|
165 |
berTlvLength = iData[KTlvLengthStartPosition];
|
|
166 |
}
|
|
167 |
|
|
168 |
for ( TInt i = 0; i < berTlvLength; i+= tlvLength )
|
|
169 |
{
|
|
170 |
// First determine if the length of the TLV is coded with 1 or 2 bytes.
|
|
171 |
if ( KTwoByteLengthCoding == iData[ind + 1] )
|
|
172 |
{
|
|
173 |
// Length is coded with 2 bytes -> real length is in second byte.
|
|
174 |
// first byte is 81 and it is tag for 2 byte length coding.
|
|
175 |
tlvLength = static_cast<TInt16>( iData[ind + 0x02] +
|
|
176 |
KTlvHeaderLength + 1 );
|
|
177 |
}
|
|
178 |
else
|
|
179 |
{
|
|
180 |
// TLV header bytes (2) must be added to total length
|
|
181 |
tlvLength = static_cast<TInt16>( iData[ind + 1] +
|
|
182 |
KTlvHeaderLength );
|
|
183 |
}
|
|
184 |
|
|
185 |
currentTlv = iData[ind]&KTagValueMask;
|
|
186 |
|
|
187 |
// Check if TLV in current index is the one that we are searching for
|
|
188 |
if ( aTlvTagValue == currentTlv && multiLength == 0x00 )
|
|
189 |
{
|
|
190 |
// Save first tag position
|
|
191 |
indMulti = ind;
|
|
192 |
multiLength = tlvLength;
|
|
193 |
}
|
|
194 |
// Add length
|
|
195 |
if ( aTlvTagValue == currentTlv && indMulti != ind )
|
|
196 |
{
|
|
197 |
multiLength = static_cast<TInt16>( multiLength + tlvLength );
|
|
198 |
}
|
|
199 |
|
|
200 |
// If last tag, return
|
|
201 |
if ( (i + tlvLength) >= berTlvLength )
|
|
202 |
{
|
|
203 |
TPtrC8 data = ( iData.Mid( indMulti , multiLength ) );
|
|
204 |
aTlv->SetData( data );
|
|
205 |
break;
|
|
206 |
}
|
|
207 |
ind += tlvLength;
|
|
208 |
}
|
|
209 |
|
|
210 |
if( 0 == indMulti)
|
|
211 |
{
|
|
212 |
return KErrNotFound;
|
|
213 |
}
|
|
214 |
else
|
|
215 |
{
|
|
216 |
return KErrNone;
|
|
217 |
}
|
|
218 |
}
|
|
219 |
|
|
220 |
|
|
221 |
//End Of File
|