|
1 // Copyright (c) 2006-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 : CTlv.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 "tflogger.h" // For logging |
|
25 #include "CTlv.h" // Header of this class |
|
26 #include "TSatUtility.h" // Utility methods |
|
27 |
|
28 // ----------------------------------------------------------------------------- |
|
29 // CTlvBase::CTlvBase |
|
30 // Default constructor |
|
31 // ----------------------------------------------------------------------------- |
|
32 // |
|
33 CTlvBase::CTlvBase |
|
34 ( |
|
35 // None |
|
36 ) : iData(0,0) |
|
37 { |
|
38 // Do nothing. |
|
39 } |
|
40 |
|
41 // ----------------------------------------------------------------------------- |
|
42 // CTlvBase::Data |
|
43 // return iData Pointer to TLV data |
|
44 // ----------------------------------------------------------------------------- |
|
45 // |
|
46 EXPORT_C TPtrC8 CTlvBase::Data |
|
47 ( |
|
48 // None |
|
49 ) const |
|
50 { |
|
51 TFLOGSTRING("UTILITY: CTlvBase::Data"); |
|
52 return iData; |
|
53 } |
|
54 |
|
55 |
|
56 // ----------------------------------------------------------------------------- |
|
57 // CTlvBase::SetData |
|
58 // Set TLV data |
|
59 // ----------------------------------------------------------------------------- |
|
60 // |
|
61 EXPORT_C void CTlvBase::SetData |
|
62 ( |
|
63 TPtrC8 aData |
|
64 ) |
|
65 { |
|
66 TFLOGSTRING("UTILITY: CTlvBase::SetData"); |
|
67 iData.Set( aData ); |
|
68 } |
|
69 |
|
70 // ----------------------------------------------------------------------------- |
|
71 // CTlvBase::GetSize |
|
72 // Get total size, including tag |
|
73 // ----------------------------------------------------------------------------- |
|
74 // |
|
75 EXPORT_C TInt CTlvBase::GetSize |
|
76 ( |
|
77 // None |
|
78 ) const |
|
79 { |
|
80 TFLOGSTRING("UTILITY: CTlvBase::GetSize"); |
|
81 return iData.Length(); |
|
82 } |
|
83 |
|
84 // ----------------------------------------------------------------------------- |
|
85 // CTlvBase::GetTag |
|
86 // Get tag part of TLV |
|
87 // ----------------------------------------------------------------------------- |
|
88 // |
|
89 EXPORT_C TUint8 CTlvBase::GetTag |
|
90 ( |
|
91 // None |
|
92 ) const |
|
93 { |
|
94 TFLOGSTRING("UTILITY: CTlvBase::GetTag"); |
|
95 return TUint8(iData[0] & KTagValueMask); |
|
96 } |
|
97 |
|
98 // ----------------------------------------------------------------------------- |
|
99 // CTlvBase::GetComprehensionRequired |
|
100 // Returns true if comprehension flag is on |
|
101 // ----------------------------------------------------------------------------- |
|
102 // |
|
103 EXPORT_C TBool CTlvBase::GetComprehensionRequired |
|
104 ( |
|
105 // None |
|
106 ) const |
|
107 { |
|
108 TFLOGSTRING("UTILITY: CTlvBase::GetComprehensionRequired"); |
|
109 return (iData[0] & KTagCrMask) ? ETrue : EFalse; |
|
110 } |
|
111 |
|
112 // ----------------------------------------------------------------------------- |
|
113 // CTlvBase::GetLength |
|
114 // Get length part of TLV |
|
115 // ----------------------------------------------------------------------------- |
|
116 // |
|
117 EXPORT_C TUint8 CTlvBase::GetLength |
|
118 ( |
|
119 // None |
|
120 ) const |
|
121 { |
|
122 TFLOGSTRING("UTILITY: CTlvBase::GetLength"); |
|
123 return (KTwoByteLengthCoding == iData[KTlvLengthStartPosition]) ? |
|
124 iData[KTlvLengthStartPosition + 1] : |
|
125 iData[KTlvLengthStartPosition]; |
|
126 } |
|
127 |
|
128 // ----------------------------------------------------------------------------- |
|
129 // CTlvBase::GetValue |
|
130 // Get value part of TLV |
|
131 // ----------------------------------------------------------------------------- |
|
132 // |
|
133 EXPORT_C TPtrC8 CTlvBase::GetValue |
|
134 ( |
|
135 // None |
|
136 ) const |
|
137 { |
|
138 TFLOGSTRING("UTILITY: CTlvBase::GetValue"); |
|
139 TInt offset = (KTwoByteLengthCoding == iData[1]) ? 1 : 0; |
|
140 return iData.Mid(2+offset, iData[1+offset]); |
|
141 } |
|
142 |
|
143 // ----------------------------------------------------------------------------- |
|
144 // CTlv::CTlv |
|
145 // Constructor |
|
146 // ----------------------------------------------------------------------------- |
|
147 // |
|
148 EXPORT_C CTlv::CTlv |
|
149 ( |
|
150 // None |
|
151 ) |
|
152 { |
|
153 // None |
|
154 } |
|
155 |
|
156 // ----------------------------------------------------------------------------- |
|
157 // CTlv::GetShortInfo |
|
158 // Returns the short info (one byte). Returned data depends on data type. |
|
159 // ----------------------------------------------------------------------------- |
|
160 // |
|
161 EXPORT_C TUint8 CTlv::GetShortInfo |
|
162 ( |
|
163 TTlvSpesificDataType aType // Info spesific data type |
|
164 ) |
|
165 { |
|
166 TFLOGSTRING2("UTILITY: CTlv::GetShortInfo, type: %d", aType); |
|
167 // Information is generally at index 2. |
|
168 TInt ind ( KTlvDataAreaStartPosition ); |
|
169 TUint8 offset( 0 ); |
|
170 |
|
171 // First determine if the length of the TLV is coded with 1 or 2 bytes to |
|
172 // determine the offset |
|
173 if ( KTwoByteLengthCoding == iData[KTlvLengthStartPosition] ) |
|
174 { |
|
175 offset = 1; |
|
176 } |
|
177 |
|
178 // Start getting the contents of TLV data |
|
179 switch( aType ) |
|
180 { |
|
181 case ETLV_SourceDeviceIdentity: |
|
182 case ETLV_TimeUnit: |
|
183 case ETLV_IdentifierOfItemChosen: |
|
184 case ETLV_MinimumLengthOfResponse: |
|
185 case ETLV_Tone: |
|
186 case ETLV_LocationStatus: |
|
187 case ETLV_IconQualifier: |
|
188 case ETLV_IconListQualifier: |
|
189 case ETLV_CardReaderStatus: |
|
190 case ETLV_TimerIdentifier: |
|
191 case ETLV_BcRepeatIndicatorValues: |
|
192 case ETLV_MeStatus: |
|
193 case ETLV_BrowserIdentity: |
|
194 case ETLV_BrowserTerminationCause: |
|
195 case ETLV_BearerType: |
|
196 case ETLV_ChannelDataLength: |
|
197 case ETLV_TypeOfAddress: |
|
198 case ETLV_TransportProtocolType: |
|
199 { |
|
200 ind = KTlvDataAreaStartPosition; |
|
201 break; |
|
202 } |
|
203 case ETLV_DestinationDeviceIdentity: |
|
204 case ETLV_TimeInterval: |
|
205 case ETLV_MaximumLengthOfResponse: |
|
206 case ETLV_IconIdentifier: |
|
207 case ETLV_TimingAdvance: |
|
208 { |
|
209 ind = KTlvDataAreaStartPosition + 1; |
|
210 break; |
|
211 } |
|
212 case ETLV_TonAndNpi: |
|
213 case ETLV_CommandNumber: |
|
214 case ETLV_IdentifierOfItem: |
|
215 case ETLV_GeneralResult: |
|
216 case ETLV_DataCodingScheme: |
|
217 case ETLV_NumberOfFiles: |
|
218 case ETLV_CommandClassCLA: |
|
219 { |
|
220 ind = KTlvDataAreaStartPosition + offset; |
|
221 break; |
|
222 } |
|
223 |
|
224 case ETLV_TypeOfCommand: |
|
225 case ETLV_CommandInstructionCodeIns: |
|
226 { |
|
227 ind = KTlvDataAreaStartPosition + offset + 1; |
|
228 break; |
|
229 } |
|
230 case ETLV_CommandQualifier: |
|
231 case ETLV_P1Parameter: |
|
232 { |
|
233 ind = KTlvDataAreaStartPosition + offset + 2; |
|
234 break; |
|
235 } |
|
236 case ETLV_P2Parameter: |
|
237 { |
|
238 ind = KTlvDataAreaStartPosition + offset + 3; |
|
239 break; |
|
240 } |
|
241 case ETLV_Lc: |
|
242 { |
|
243 if ( GetLongInfo( ETLV_Lc ) > KCApduLengthWithoutLc ) |
|
244 { |
|
245 ind = KTlvDataAreaStartPosition + offset + 4; |
|
246 } |
|
247 else |
|
248 { |
|
249 return 0; |
|
250 } |
|
251 break; |
|
252 } |
|
253 case ETLV_Le: |
|
254 { |
|
255 ind = KTlvDataAreaStartPosition + offset + 5 + GetShortInfo( ETLV_Lc ); |
|
256 break; |
|
257 } |
|
258 case ETLV_StatusWordSW1: |
|
259 { |
|
260 ind = KTlvDataAreaStartPosition + offset + GetLength() - 2 + 1; |
|
261 break; |
|
262 } |
|
263 case ETLV_StatusWordSW2: |
|
264 { |
|
265 ind = KTlvDataAreaStartPosition + offset + GetLength() - 2 + 2; |
|
266 break; |
|
267 } |
|
268 default: |
|
269 { |
|
270 TFLOGSTRING("UTILITY: CTlv::GetShortInfo, Type unknown"); |
|
271 break; |
|
272 } |
|
273 } |
|
274 |
|
275 return iData[ind]; |
|
276 } |
|
277 |
|
278 // ----------------------------------------------------------------------------- |
|
279 // CTlv::GetData |
|
280 // Returns the data. Returned data depends on data type. |
|
281 // ----------------------------------------------------------------------------- |
|
282 // |
|
283 EXPORT_C TPtrC8 CTlv::GetData |
|
284 ( |
|
285 TTlvSpesificDataType aType //Info spesific data type |
|
286 ) |
|
287 { |
|
288 TFLOGSTRING2("UTILITY: CTlv::GetData, Data length: %d", iData.Length()); |
|
289 // Information is generally at index 2. |
|
290 TInt ind ( 2 ); |
|
291 TUint8 offset( 0 ); |
|
292 TInt length( 1 ); |
|
293 |
|
294 // First determine if the length of the TLV is coded with 1 or 2 bytes. |
|
295 if ( KTwoByteLengthCoding == iData[KTlvLengthStartPosition] ) |
|
296 { |
|
297 offset = 1; |
|
298 } |
|
299 |
|
300 // Start getting TLV data elements |
|
301 switch( aType ) |
|
302 { |
|
303 case ETLV_CellBroadcastPage: |
|
304 case ETLV_Imei: |
|
305 case ETLV_NetworkMeasurementResults: |
|
306 case ETLV_ItemsNextActionIndicator: |
|
307 case ETLV_BcchChannelList: |
|
308 case ETLV_Atr: |
|
309 case ETLV_TimerValue: |
|
310 case ETLV_DateTimeAndTimeZone: |
|
311 case ETLV_IdentifierOfCardReader: |
|
312 case ETLV_NetworkAccessName: |
|
313 case ETLV_AID: |
|
314 case ETLV_TransactionIdentifier: |
|
315 { |
|
316 ind = KTlvDataAreaStartPosition; |
|
317 length = GetLength(); |
|
318 break; |
|
319 } |
|
320 case ETLV_MccAndMnc: |
|
321 { |
|
322 ind = KTlvDataAreaStartPosition; |
|
323 length = KMccAndMncLength; |
|
324 break; |
|
325 } |
|
326 case ETLV_IconIdentifierList: |
|
327 case ETLV_Address: |
|
328 { |
|
329 ind = KTlvDataAreaStartPosition + 1; |
|
330 length = GetLength() - 1; |
|
331 break; |
|
332 } |
|
333 case ETLV_AlphaIdentifier: |
|
334 case ETLV_SubAddress: |
|
335 case ETLV_CapabilityConfigurationParameters: |
|
336 case ETLV_SmsTPdu: |
|
337 case ETLV_EventList: |
|
338 case ETLV_Cause: |
|
339 case ETLV_CallControlRequestedAction: |
|
340 case ETLV_AtCommand: |
|
341 case ETLV_AtResponse: |
|
342 case ETLV_DtmfString: |
|
343 case ETLV_Url: |
|
344 case ETLV_ListOfBearers: |
|
345 case ETLV_PathToProvisioningFile: |
|
346 case ETLV_ChannelDataString: |
|
347 { |
|
348 ind = KTlvDataAreaStartPosition + offset; |
|
349 length = GetLength(); |
|
350 break; |
|
351 } |
|
352 case ETLV_RApduData: |
|
353 { |
|
354 ind = KTlvDataAreaStartPosition + offset; |
|
355 length = GetLength() - 2; |
|
356 break; |
|
357 } |
|
358 case ETLV_AdditionalInformationOnResult: |
|
359 case ETLV_SsOrUssdString: |
|
360 case ETLV_TextString: |
|
361 case ETLV_DefaultText: |
|
362 case ETLV_UssdString: |
|
363 case ETLV_Files: |
|
364 case ETLV_BearerParameters: |
|
365 case ETLV_TextStringOfItem: |
|
366 case ETLV_DiallingNumberString: |
|
367 { |
|
368 ind = KTlvDataAreaStartPosition + offset + 1; |
|
369 length = GetLength() - 1; |
|
370 break; |
|
371 } |
|
372 case ETLV_Data: |
|
373 { |
|
374 TUint8 dataLength( GetShortInfo( ETLV_Lc ) ); |
|
375 if ( dataLength ) |
|
376 { |
|
377 ind = KTlvDataAreaStartPosition + offset + 5; |
|
378 length = dataLength; |
|
379 } |
|
380 else |
|
381 { |
|
382 TFLOGSTRING("UTILITY: CTlv::GetData, Data length 0"); |
|
383 return 0; |
|
384 } |
|
385 break; |
|
386 } |
|
387 default: |
|
388 { |
|
389 TFLOGSTRING("UTILITY: CTlv::GetData, Type unknown"); |
|
390 break; |
|
391 } |
|
392 } |
|
393 |
|
394 TFLOGSTRING3("UTILITY: CTlv::GetData, length: %d, ind: %d", |
|
395 length, ind); |
|
396 return iData.Mid( ind, length ); |
|
397 } |
|
398 |
|
399 // ----------------------------------------------------------------------------- |
|
400 // CTlv::GetLongInfo |
|
401 // Returns the data. Returned data depends on data type. |
|
402 // ----------------------------------------------------------------------------- |
|
403 // |
|
404 EXPORT_C TUint16 CTlv::GetLongInfo |
|
405 ( |
|
406 TTlvSpesificDataType aType // Info spesific data type |
|
407 ) |
|
408 { |
|
409 TFLOGSTRING2("UTILITY: CTlv::GetLongInfo, type: %d", aType); |
|
410 TUint16 ret( 0x0000 ); |
|
411 |
|
412 switch( aType ) |
|
413 { |
|
414 case ETLV_LocationAreaCode: |
|
415 { |
|
416 TSatUtility::CopyTwo8toOne16LE( iData, ret, |
|
417 KTlvLengthStartPosition + KMccAndMncLength ); |
|
418 break; |
|
419 } |
|
420 case ETLV_CellIdentityValue: |
|
421 { |
|
422 TSatUtility::CopyTwo8toOne16LE( iData, ret, |
|
423 KTlvLengthStartPosition + KMccAndMncLength + |
|
424 KLocationAreaCodeLength ); |
|
425 break; |
|
426 } |
|
427 case ETLV_Language: |
|
428 { |
|
429 TSatUtility::CopyTwo8toOne16LE( iData, ret, |
|
430 KTlvDataAreaStartPosition ); |
|
431 break; |
|
432 } |
|
433 case ETLV_BufferSize: |
|
434 { |
|
435 TSatUtility::CopyTwo8toOne16LE( iData, ret, |
|
436 KTlvDataAreaStartPosition ); |
|
437 break; |
|
438 } |
|
439 case ETLV_ChannelStatus: |
|
440 { |
|
441 TSatUtility::CopyTwo8toOne16LE( iData, ret, |
|
442 KTlvLengthStartPosition ); |
|
443 break; |
|
444 } |
|
445 case ETLV_PortNumber: |
|
446 { |
|
447 TSatUtility::CopyTwo8toOne16LE( iData, ret, |
|
448 KTlvDataAreaStartPosition + 1 ); |
|
449 break; |
|
450 } |
|
451 default: |
|
452 { |
|
453 TFLOGSTRING("UTILITY: CTlv::GetLongInfo, Type unknown"); |
|
454 break; |
|
455 } |
|
456 } |
|
457 |
|
458 return ret; |
|
459 } |
|
460 |
|
461 //End Of File |