|
1 /* |
|
2 * Copyright (c) 2003-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: WIM OMA Provisioning functionality. Reads OMA Provisioning |
|
15 * documents from Smart Card. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include "WimOmaProvisioning.h" |
|
22 #include "Wimi.h" // WIMI |
|
23 #include "WimClsv.h" |
|
24 #include "WimUtilityFuncs.h" |
|
25 #include "WimResponse.h" // Callback response message |
|
26 #include "WimTrace.h" |
|
27 |
|
28 |
|
29 // ============================ MEMBER FUNCTIONS =============================== |
|
30 |
|
31 // ----------------------------------------------------------------------------- |
|
32 // CWimOmaProvisioning::CWimOmaProvisioning |
|
33 // C++ default constructor can NOT contain any code, that |
|
34 // might leave. |
|
35 // ----------------------------------------------------------------------------- |
|
36 // |
|
37 CWimOmaProvisioning::CWimOmaProvisioning() |
|
38 { |
|
39 _WIMTRACE(_L("WIM | WIMServer | CWimOmaProvisioning::CWimOmaProvisioning | Begin")); |
|
40 } |
|
41 |
|
42 // ----------------------------------------------------------------------------- |
|
43 // CWimOmaProvisioning::ConstructL |
|
44 // Symbian 2nd phase constructor can leave. |
|
45 // ----------------------------------------------------------------------------- |
|
46 // |
|
47 void CWimOmaProvisioning::ConstructL() |
|
48 { |
|
49 _WIMTRACE(_L("WIM | WIMServer | CWimOmaProvisioning::ConstructL | Begin")); |
|
50 iWimUtilityFuncs = CWimUtilityFuncs::NewL(); |
|
51 } |
|
52 |
|
53 // ----------------------------------------------------------------------------- |
|
54 // CWimOmaProvisioning::NewL |
|
55 // Two-phased constructor. |
|
56 // ----------------------------------------------------------------------------- |
|
57 // |
|
58 CWimOmaProvisioning* CWimOmaProvisioning::NewL() |
|
59 { |
|
60 _WIMTRACE(_L("WIM | WIMServer | CWimOmaProvisioning::NewL | Begin")); |
|
61 CWimOmaProvisioning* self = new( ELeave ) CWimOmaProvisioning; |
|
62 CleanupStack::PushL( self ); |
|
63 self->ConstructL(); |
|
64 CleanupStack::Pop( self ); |
|
65 return self; |
|
66 } |
|
67 |
|
68 // Destructor |
|
69 CWimOmaProvisioning::~CWimOmaProvisioning() |
|
70 { |
|
71 _WIMTRACE(_L("WIM | WIMServer | CWimOmaProvisioning::~CWimOmaProvisioning | Begin")); |
|
72 delete iWimUtilityFuncs; |
|
73 free_WIMI_Ref_t( iWimRef ); |
|
74 } |
|
75 |
|
76 // ----------------------------------------------------------------------------- |
|
77 // CWimOmaProvisioning::OmaFileSizeL |
|
78 // Get OMA Provisioning file size |
|
79 // ----------------------------------------------------------------------------- |
|
80 // |
|
81 void CWimOmaProvisioning::OmaFileSizeL( const RMessage2& aMessage ) |
|
82 { |
|
83 _WIMTRACE(_L("WIM | WIMServer | CWimOmaProvisioning::OmaFileSizeL | Begin")); |
|
84 |
|
85 InitializePathsAndSizes(); |
|
86 |
|
87 TOmaProv omaProvisioning; |
|
88 omaProvisioning.iSize = 0; |
|
89 TPckgBuf<TOmaProv> omaFilePckg( omaProvisioning ); |
|
90 aMessage.ReadL( 0, omaFilePckg ); |
|
91 |
|
92 TInt fileSize = 0; |
|
93 TInt err = KErrNone; |
|
94 |
|
95 switch ( omaFilePckg().iOmaType ) |
|
96 { |
|
97 case EBootStrap: |
|
98 { |
|
99 fileSize = iBootstrapFileSize; |
|
100 break; |
|
101 } |
|
102 |
|
103 case EConfig1: |
|
104 { |
|
105 fileSize = iConfig1FileSize; |
|
106 break; |
|
107 } |
|
108 |
|
109 case EConfig2: |
|
110 { |
|
111 fileSize = iConfig2FileSize; |
|
112 break; |
|
113 } |
|
114 |
|
115 default: |
|
116 { |
|
117 err = KErrArgument; |
|
118 break; |
|
119 } |
|
120 } |
|
121 |
|
122 _WIMTRACE3(_L("WIM | WIMServer | CWimOmaProvisioning::OmaFileSizeL | FileType=%d, FileSize=%d"), omaFilePckg().iOmaType, fileSize); |
|
123 |
|
124 if ( err == KErrNone ) |
|
125 { |
|
126 omaFilePckg().iSize = ( TInt )fileSize; |
|
127 aMessage.WriteL( 0, omaFilePckg ); |
|
128 } |
|
129 aMessage.Complete( err ); |
|
130 } |
|
131 |
|
132 // ----------------------------------------------------------------------------- |
|
133 // CWimOmaProvisioning::OmaFileContentL |
|
134 // Write content of OMA provisioning file to client memory |
|
135 // ----------------------------------------------------------------------------- |
|
136 // |
|
137 void CWimOmaProvisioning::OmaFileContentL( const RMessage2& aMessage ) |
|
138 { |
|
139 _WIMTRACE(_L("WIM | WIMServer | CWimOmaProvisioning::OmaFileContentL | Begin")); |
|
140 |
|
141 TUint16 callStatus = KErrNone; |
|
142 WIMI_BinData_t pt_path; |
|
143 WIMI_BinData_t fileContent; |
|
144 TUint16 fileSize = 0; |
|
145 TPtrC8 path; |
|
146 |
|
147 // Do initialization |
|
148 InitializePathsAndSizes(); |
|
149 |
|
150 TOmaProv omaProvisioning; |
|
151 omaProvisioning.iSize = 0; |
|
152 TPckgBuf<TOmaProv> omaFilePckg( omaProvisioning ); |
|
153 aMessage.ReadL( 0, omaFilePckg ); |
|
154 |
|
155 if ( !iWimRef ) |
|
156 { |
|
157 callStatus = WIMI_ERR_KeyNotFound; // Mapped to KErrNotFound |
|
158 } |
|
159 |
|
160 if ( callStatus == KErrNone ) |
|
161 { |
|
162 switch ( omaFilePckg().iOmaType ) |
|
163 { |
|
164 case EBootStrap: |
|
165 { |
|
166 path.Set( iPathBootstrap.Ptr() ); |
|
167 fileSize = ( TUint16 )iBootstrapFileSize; |
|
168 break; |
|
169 } |
|
170 |
|
171 case EConfig1: |
|
172 { |
|
173 path.Set( iPathConfig1.Ptr() ); |
|
174 fileSize = ( TUint16 )iConfig1FileSize; |
|
175 break; |
|
176 } |
|
177 |
|
178 case EConfig2: |
|
179 { |
|
180 path.Set( iPathConfig2.Ptr() ); |
|
181 fileSize = ( TUint16 )iConfig2FileSize; |
|
182 break; |
|
183 } |
|
184 |
|
185 default: |
|
186 { |
|
187 callStatus = WIMI_ERR_BadParameters; |
|
188 break; |
|
189 } |
|
190 } |
|
191 } |
|
192 |
|
193 if ( callStatus == KErrNone ) |
|
194 { |
|
195 if ( path.Length() == 0 ) |
|
196 { |
|
197 callStatus = WIMI_ERR_KeyNotFound; // Mapped to KErrNotFound |
|
198 } |
|
199 } |
|
200 |
|
201 _WIMTRACE3(_L("WIM | WIMServer | CWimOmaProvisioning::OmaFileContentL | FileType=%d, FileSize=%d"), omaFilePckg().iOmaType, fileSize); |
|
202 |
|
203 if ( callStatus == KErrNone ) |
|
204 { |
|
205 pt_path.ui_buf_length = ( TUint16 )path.Length(); |
|
206 pt_path.pb_buf = ( TUint8* )path.Ptr(); |
|
207 |
|
208 WIMI_TransactId_t trId = ( void* )EOMAProvContentSync; |
|
209 |
|
210 fileContent.pb_buf = NULL; |
|
211 fileContent.ui_buf_length = 0; |
|
212 // Get OMA Provisioning file from card |
|
213 callStatus = WIMI_GetOMAFileSync( trId, |
|
214 iWimRef, |
|
215 &pt_path, |
|
216 0, |
|
217 &fileContent ); |
|
218 |
|
219 if ( callStatus == KErrNone ) |
|
220 { |
|
221 //Use filesize here, should be equal or smaller than fileContent.ui_length |
|
222 TPtrC8 omaFilePtr( fileContent.pb_buf, fileSize ); |
|
223 TInt err = aMessage.Write( 1, omaFilePtr ); |
|
224 if( err ) |
|
225 { |
|
226 WSL_OS_Free( fileContent.pb_buf ); |
|
227 User::Leave( err ); |
|
228 } |
|
229 aMessage.Complete( KErrNone ); |
|
230 } |
|
231 else |
|
232 { |
|
233 aMessage.Complete( CWimUtilityFuncs::MapWIMError( callStatus ) ); |
|
234 } |
|
235 |
|
236 WSL_OS_Free( fileContent.pb_buf ); // Deallocate file content buffer |
|
237 } |
|
238 |
|
239 _WIMTRACE(_L("WIM | WIMServer | CWimOmaProvisioning::OmaFileContentL | End")); |
|
240 } |
|
241 |
|
242 // ----------------------------------------------------------------------------- |
|
243 // CWimOmaProvisioning::InitializePathsAndSizes |
|
244 // Initializes the path and size data members |
|
245 // ----------------------------------------------------------------------------- |
|
246 // |
|
247 void CWimOmaProvisioning::InitializePathsAndSizes() |
|
248 { |
|
249 _WIMTRACE(_L("WIM | WIMServer | CWimOmaProvisioning::InitializePathsAndSizesL | Begin")); |
|
250 |
|
251 // Do initialization only if initialization is not done |
|
252 if ( !iFileInfosInitialized ) |
|
253 { |
|
254 TUint16 callStatus = KErrNone; |
|
255 |
|
256 TBuf8<KWimProvFileOidLength> bootstrapOid; |
|
257 TBuf8<KWimProvFileOidLength> config1Oid; |
|
258 TBuf8<KWimProvFileOidLength> config2Oid; |
|
259 |
|
260 bootstrapOid.Copy( KWimProvBootstrapFileOID, KWimProvFileOidLength ); |
|
261 config1Oid.Copy( KWimProvConfig1FileOID, KWimProvFileOidLength ); |
|
262 config2Oid.Copy( KWimProvConfig2FileOID, KWimProvFileOidLength ); |
|
263 |
|
264 TBuf8<KWimProvFileOidLengthTaged> bootstrapOidTaged; |
|
265 TBuf8<KWimProvFileOidLengthTaged> config1OidTaged; |
|
266 TBuf8<KWimProvFileOidLengthTaged> config2OidTaged; |
|
267 |
|
268 bootstrapOidTaged.Copy( KWimProvBootstrapFileOIDTaged, |
|
269 KWimProvFileOidLengthTaged ); |
|
270 config1OidTaged.Copy( KWimProvConfig1FileOIDTaged, |
|
271 KWimProvFileOidLengthTaged ); |
|
272 config2OidTaged.Copy( KWimProvConfig2FileOIDTaged, |
|
273 KWimProvFileOidLengthTaged ); |
|
274 |
|
275 WIMI_BinData_t path; |
|
276 path.pb_buf = NULL; |
|
277 path.ui_buf_length = 0; |
|
278 |
|
279 WIMI_File_Info* fileInfos = NULL; |
|
280 |
|
281 TUint16 fileCount = 0; |
|
282 |
|
283 WIMI_BinData_t fileOid; |
|
284 fileOid.pb_buf = NULL; |
|
285 fileOid.ui_buf_length = 0; |
|
286 |
|
287 // Get WIM reference, reader is always 0 |
|
288 iWimRef = WIMI_GetWIMRef( 0 ); |
|
289 |
|
290 if ( !iWimRef ) |
|
291 { |
|
292 callStatus = WIMI_ERR_BadReference; |
|
293 } |
|
294 |
|
295 if ( callStatus == KErrNone ) |
|
296 { |
|
297 |
|
298 // Get OMA file info from Wimlib |
|
299 callStatus = WIMI_OMAFileInfo( iWimRef, |
|
300 &fileInfos, |
|
301 &fileCount ); |
|
302 } |
|
303 |
|
304 if ( callStatus == KErrNone ) |
|
305 { |
|
306 TBuf8<KWimOidLengthTaged> oidBuf; // Buffer for OID |
|
307 |
|
308 // Loop all file infos and safe path to each file |
|
309 for ( TInt i = 0; i < fileCount; i++ ) |
|
310 { |
|
311 // Get file OID from infos |
|
312 fileOid.pb_buf = fileInfos[i].t_oid.pb_buf; |
|
313 fileOid.ui_buf_length = fileInfos[i].t_oid.ui_buf_length; |
|
314 oidBuf.Copy( fileOid.pb_buf, fileOid.ui_buf_length ); |
|
315 |
|
316 // File path |
|
317 path.pb_buf = fileInfos[i].b_path.pb_buf; |
|
318 path.ui_buf_length = fileInfos[i].b_path.ui_buf_length; |
|
319 |
|
320 // Compare OIDs |
|
321 if ( !oidBuf.Compare( bootstrapOid ) |
|
322 || !oidBuf.Compare( bootstrapOidTaged ) ) // Bootstrap File |
|
323 { |
|
324 // Copy file path to member |
|
325 iPathBootstrap.Copy( path.pb_buf, path.ui_buf_length ); |
|
326 // Set file size |
|
327 iBootstrapFileSize = fileInfos[i].ui_file_size; |
|
328 |
|
329 // Check if path is given but size not. If path exists and |
|
330 // size == 0 then parse size from fetched file |
|
331 if ( iPathBootstrap.Length() > 0 && |
|
332 iBootstrapFileSize == 0 ) |
|
333 { |
|
334 ParseFileSize( EBootStrap ); |
|
335 } |
|
336 } |
|
337 else if ( !oidBuf.Compare( config1Oid ) |
|
338 || !oidBuf.Compare( config1OidTaged ) ) // Config1 File |
|
339 { |
|
340 // Copy file path to member |
|
341 iPathConfig1.Copy( path.pb_buf, path.ui_buf_length ); |
|
342 // Set file size |
|
343 iConfig1FileSize = fileInfos[i].ui_file_size; |
|
344 |
|
345 // Check if path is given but size not. If path exists and |
|
346 // size == 0 then parse size from fetched file |
|
347 if ( iPathConfig1.Length() > 0 && iConfig1FileSize == 0 ) |
|
348 { |
|
349 ParseFileSize( EConfig1 ); |
|
350 } |
|
351 } |
|
352 else if ( !oidBuf.Compare( config2Oid ) |
|
353 || !oidBuf.Compare( config2OidTaged ) ) // Config2 File |
|
354 { |
|
355 // Copy file path to member |
|
356 iPathConfig2.Copy( path.pb_buf, path.ui_buf_length ); |
|
357 // Set file size |
|
358 iConfig2FileSize = fileInfos[i].ui_file_size; |
|
359 |
|
360 // Check if path is given but size not. If path exists and |
|
361 // size == 0 then parse size from fetched file |
|
362 if ( iPathConfig2.Length() > 0 && iConfig2FileSize == 0 ) |
|
363 { |
|
364 ParseFileSize( EConfig2 ); |
|
365 } |
|
366 } |
|
367 } |
|
368 } |
|
369 iFileInfosInitialized = ETrue; |
|
370 } |
|
371 } |
|
372 |
|
373 // ----------------------------------------------------------------------------- |
|
374 // CWimOmaProvisioning::ParseFileSize |
|
375 // Get content of file and parse size of it. For WIM size is mandatory in |
|
376 // DODF-PROV file but for SIM implementation it is not mandatory. |
|
377 // ----------------------------------------------------------------------------- |
|
378 // |
|
379 void CWimOmaProvisioning::ParseFileSize( TOMAType aOmaType ) |
|
380 { |
|
381 _WIMTRACE(_L("WIM | WIMServer | CWimOmaProvisioning::ParseFileSize | Begin")); |
|
382 WIMI_BinData_t path; |
|
383 WIMI_BinData_t fileContent; |
|
384 TInt fileSize; |
|
385 TPtrC8 pathPtr; |
|
386 |
|
387 // Set path to file |
|
388 switch ( aOmaType ) |
|
389 { |
|
390 case EBootStrap: |
|
391 { |
|
392 pathPtr.Set( iPathBootstrap.Ptr() ); |
|
393 break; |
|
394 } |
|
395 |
|
396 case EConfig1: |
|
397 { |
|
398 pathPtr.Set( iPathConfig1.Ptr() ); |
|
399 break; |
|
400 } |
|
401 |
|
402 case EConfig2: |
|
403 { |
|
404 pathPtr.Set( iPathConfig2.Ptr() ); |
|
405 break; |
|
406 } |
|
407 |
|
408 default: |
|
409 { |
|
410 return; |
|
411 } |
|
412 } |
|
413 |
|
414 path.ui_buf_length = ( TUint16 )pathPtr.Length(); |
|
415 path.pb_buf = ( TUint8* )pathPtr.Ptr(); |
|
416 |
|
417 |
|
418 WIMI_TransactId_t trId = ( void* )EOMAProvContentSync; |
|
419 |
|
420 TPtr8 contentPtr = TPtr8( NULL, 0, 0 ); |
|
421 |
|
422 fileContent.pb_buf = NULL; |
|
423 fileContent.ui_buf_length = 0; |
|
424 // Get OMA Provisioning file from card |
|
425 WIMI_STAT callStatus = WIMI_GetOMAFileSync( trId, |
|
426 iWimRef, |
|
427 &path, |
|
428 0, |
|
429 &fileContent ); |
|
430 |
|
431 if ( callStatus != KErrNone ) |
|
432 { |
|
433 fileSize = 0; |
|
434 } |
|
435 else |
|
436 { |
|
437 contentPtr.Set( fileContent.pb_buf, |
|
438 fileContent.ui_buf_length, |
|
439 fileContent.ui_buf_length ); |
|
440 |
|
441 fileSize = fileContent.ui_buf_length; |
|
442 } |
|
443 |
|
444 // Set file size |
|
445 switch ( aOmaType ) |
|
446 { |
|
447 case EBootStrap: |
|
448 { |
|
449 iBootstrapFileSize = fileSize; |
|
450 _WIMTRACE2( _L("WIM | WIMServer | CWimOmaProvisioning::ParseFileSize | Bootstrap size=%d"), |
|
451 fileSize ); |
|
452 break; |
|
453 } |
|
454 |
|
455 case EConfig1: |
|
456 { |
|
457 iConfig1FileSize = fileSize; |
|
458 _WIMTRACE2( _L("WIM | WIMServer | CWimOmaProvisioning::ParseFileSize | Config1 size=%d"), |
|
459 fileSize ); |
|
460 break; |
|
461 } |
|
462 |
|
463 case EConfig2: |
|
464 { |
|
465 iConfig2FileSize = fileSize; |
|
466 _WIMTRACE2( _L("WIM | WIMServer | CWimOmaProvisioning::ParseFileSize | Config2 size=%d"), |
|
467 fileSize ); |
|
468 break; |
|
469 } |
|
470 |
|
471 default: |
|
472 { |
|
473 break; |
|
474 } |
|
475 } |
|
476 |
|
477 WSL_OS_Free( fileContent.pb_buf ); // Deallocate file content buffer |
|
478 } |
|
479 |
|
480 // End of File |