|
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 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "T_BTServiceSecurityData.h" |
|
20 |
|
21 |
|
22 //Constant Literals used. |
|
23 |
|
24 //Parameters |
|
25 _LIT(KAuthentication, "authentication"); |
|
26 _LIT(KAuthorisation, "authorisation"); |
|
27 _LIT(KDenied, "denied"); |
|
28 _LIT(KEncryption, "encryption"); |
|
29 _LIT(KPasskeyminlength, "passkeyminlength"); |
|
30 _LIT(KUid, "uid"); |
|
31 _LIT(KServiceSecurity, "btservicesecurity"); |
|
32 |
|
33 // Unfortunate fact of life |
|
34 // authorisation TRUE = 2 |
|
35 // encryption TRUE = 4 |
|
36 // denied TRUE = 8 |
|
37 // Therefore this additional parameters are neaded so that TRUE can be verified |
|
38 _LIT(KAuthorisationInt, "authorisation_int"); |
|
39 _LIT(KEncryptionInt, "encryption_int"); |
|
40 _LIT(KDeniedInt, "denied_int"); |
|
41 |
|
42 |
|
43 //TBTServiceSecurity |
|
44 _LIT(KCmdConstruct, "Construct"); |
|
45 _LIT(KCmdSetAuthentication, "SetAuthentication"); |
|
46 _LIT(KCmdAuthenticationRequired, "AuthenticationRequired"); |
|
47 _LIT(KCmdSetAuthorisation, "SetAuthorisation"); |
|
48 _LIT(KCmdAuthorisationRequired, "AuthorisationRequired"); |
|
49 _LIT(KCmdSetDenied, "SetDenied"); |
|
50 _LIT(KCmdDenied, "Denied"); |
|
51 _LIT(KCmdSetEncryption, "SetEncryption"); |
|
52 _LIT(KCmdEncryptionRequired, "EncryptionRequired"); |
|
53 _LIT(KCmdSetPasskeyMinLength, "SetPasskeyMinLength"); |
|
54 _LIT(KCmdPasskeyMinLength, "PasskeyMinLength"); |
|
55 _LIT(KCmdSetUid, "SetUid"); |
|
56 _LIT(KCmdUid, "Uid"); |
|
57 _LIT(KCmdDistructor, "~"); |
|
58 |
|
59 /*@}*/ |
|
60 |
|
61 CT_BTServiceSecurityData* CT_BTServiceSecurityData::NewL() |
|
62 { |
|
63 CT_BTServiceSecurityData* ret=new (ELeave) CT_BTServiceSecurityData(); |
|
64 return ret; |
|
65 } |
|
66 |
|
67 CT_BTServiceSecurityData::CT_BTServiceSecurityData() |
|
68 : iBTServiceSecurity(NULL) |
|
69 { |
|
70 } |
|
71 |
|
72 CT_BTServiceSecurityData::~CT_BTServiceSecurityData() |
|
73 { |
|
74 Cleanup(); |
|
75 } |
|
76 |
|
77 void CT_BTServiceSecurityData::Cleanup() |
|
78 { |
|
79 delete iBTServiceSecurity; |
|
80 iBTServiceSecurity=NULL; |
|
81 } |
|
82 |
|
83 inline TCleanupOperation CT_BTServiceSecurityData::CleanupOperation() |
|
84 { |
|
85 return CleanupOperation; |
|
86 } |
|
87 |
|
88 void CT_BTServiceSecurityData::CleanupOperation(TAny* aAny) |
|
89 { |
|
90 TBTServiceSecurity* arg=static_cast<TBTServiceSecurity*>(aAny); |
|
91 delete arg; |
|
92 } |
|
93 |
|
94 |
|
95 TBool CT_BTServiceSecurityData::DoCommandL(const TTEFFunction& aCommand, const TTEFSectionName& aSection, const TInt /*aAsyncErrorIndex*/) |
|
96 { |
|
97 TBool retVal=ETrue; |
|
98 |
|
99 if ( aCommand==KCmdConstruct ) |
|
100 { |
|
101 TBTSSConstruct(aSection); |
|
102 } |
|
103 else if ( aCommand==KCmdSetAuthentication ) |
|
104 { |
|
105 TBTSSSetAuthentication(aSection); |
|
106 } |
|
107 else if ( aCommand==KCmdAuthenticationRequired ) |
|
108 { |
|
109 TBTSSAuthenticationRequired(aSection); |
|
110 } |
|
111 else if ( aCommand==KCmdSetAuthorisation ) |
|
112 { |
|
113 TBTSSSetAuthorisation(aSection); |
|
114 } |
|
115 else if ( aCommand==KCmdAuthorisationRequired ) |
|
116 { |
|
117 TBTSSAuthorisationRequired(aSection); |
|
118 } |
|
119 else if ( aCommand==KCmdSetDenied ) |
|
120 { |
|
121 TBTSSSetDenied(aSection); |
|
122 } |
|
123 else if ( aCommand==KCmdDenied ) |
|
124 { |
|
125 TBTSSDenied(aSection); |
|
126 } |
|
127 else if ( aCommand==KCmdSetEncryption ) |
|
128 { |
|
129 TBTSSSetEncryption(aSection); |
|
130 } |
|
131 else if ( aCommand==KCmdEncryptionRequired ) |
|
132 { |
|
133 TBTSSEncryptionRequired(aSection); |
|
134 } |
|
135 else if ( aCommand==KCmdSetPasskeyMinLength ) |
|
136 { |
|
137 TBTSSSetPasskeyMinLength(aSection); |
|
138 } |
|
139 else if ( aCommand==KCmdPasskeyMinLength ) |
|
140 { |
|
141 TBTSSPasskeyMinLength(aSection); |
|
142 } |
|
143 else if ( aCommand==KCmdSetUid ) |
|
144 { |
|
145 TBTSSSetUid(aSection); |
|
146 } |
|
147 else if ( aCommand==KCmdUid ) |
|
148 { |
|
149 TBTSSUid(aSection); |
|
150 } |
|
151 else if ( aCommand==KCmdDistructor ) |
|
152 { |
|
153 Cleanup(); |
|
154 } |
|
155 else |
|
156 { |
|
157 retVal=EFalse; |
|
158 } |
|
159 return retVal; |
|
160 } |
|
161 |
|
162 void CT_BTServiceSecurityData::TBTSSConstruct(const TDesC& aSection) |
|
163 { |
|
164 INFO_PRINTF1(_L("TBTServiceSecurity Constructor Call")); |
|
165 TPtrC myServiceSecurityName; |
|
166 TBTServiceSecurity* myServiceSecurity=NULL; |
|
167 if ( !GetStringFromConfig(aSection, KServiceSecurity(), myServiceSecurityName) ) |
|
168 { |
|
169 //Use default constructor |
|
170 Cleanup(); |
|
171 TRAPD( err, iBTServiceSecurity = new (ELeave) TBTServiceSecurity() ); |
|
172 SetError( err); |
|
173 } |
|
174 else |
|
175 { |
|
176 TRAPD( err, myServiceSecurity=static_cast<TBTServiceSecurity*>(GetDataObjectL(myServiceSecurityName)) ); |
|
177 |
|
178 if ( (!err) && (myServiceSecurity!=NULL) ) |
|
179 { |
|
180 Cleanup(); |
|
181 TRAP( err, iBTServiceSecurity = new (ELeave) TBTServiceSecurity(*myServiceSecurity) ); |
|
182 SetError( err); |
|
183 } |
|
184 else |
|
185 { |
|
186 ERR_PRINTF2(_L("TBTSSConstructFromServiceSecurity TSockAddr is NULL and err = %d"), err); |
|
187 SetBlockResult(EFail); |
|
188 } |
|
189 } |
|
190 } |
|
191 |
|
192 |
|
193 void CT_BTServiceSecurityData::TBTSSSetAuthentication(const TDesC& aSection) |
|
194 { |
|
195 TBool authentication; |
|
196 if( GetBoolFromConfig(aSection, KAuthentication(), authentication)) |
|
197 { |
|
198 INFO_PRINTF2(_L("TBTServiceSecurity SetAuthentication (%d)"), authentication); |
|
199 iBTServiceSecurity->SetAuthentication(authentication); |
|
200 } |
|
201 else |
|
202 { |
|
203 ERR_PRINTF1(_L("GetBoolFromConfig failed")); |
|
204 SetBlockResult(EFail); |
|
205 } |
|
206 } |
|
207 |
|
208 void CT_BTServiceSecurityData::TBTSSAuthenticationRequired(const TDesC& aSection) |
|
209 { |
|
210 TBool authentication; |
|
211 TBool authenticationReceived = iBTServiceSecurity->AuthenticationRequired(); |
|
212 INFO_PRINTF2(_L("TBTServiceSecurity Authentication: actual (%d)" ), authenticationReceived); |
|
213 if( GetBoolFromConfig(aSection, KAuthentication(), authentication)) |
|
214 { |
|
215 INFO_PRINTF2(_L("TBTServiceSecurity Authentication: expected (%d)" ), authentication); |
|
216 if(authentication != authenticationReceived) |
|
217 { |
|
218 ERR_PRINTF1(_L("Authentication is not as expected!")); |
|
219 SetBlockResult(EFail); |
|
220 } |
|
221 } |
|
222 else |
|
223 { |
|
224 ERR_PRINTF1(_L("GetBoolFromConfig failed")); |
|
225 SetBlockResult(EFail); |
|
226 } |
|
227 } |
|
228 |
|
229 void CT_BTServiceSecurityData::TBTSSSetAuthorisation(const TDesC& aSection) |
|
230 { |
|
231 TBool authorisation; |
|
232 if( GetBoolFromConfig(aSection, KAuthorisation(), authorisation)) |
|
233 { |
|
234 INFO_PRINTF2(_L("TBTServiceSecurity SetAuthorisation (%d)"), authorisation); |
|
235 iBTServiceSecurity->SetAuthorisation(authorisation); |
|
236 } |
|
237 else |
|
238 { |
|
239 ERR_PRINTF1(_L("GetBoolFromConfig failed")); |
|
240 SetBlockResult(EFail); |
|
241 } |
|
242 } |
|
243 |
|
244 void CT_BTServiceSecurityData::TBTSSAuthorisationRequired(const TDesC& aSection) |
|
245 { |
|
246 TBool authorisation; |
|
247 TBool authorisationReceived = iBTServiceSecurity->AuthorisationRequired(); |
|
248 INFO_PRINTF2(_L("TBTServiceSecurity Authorisation: actual (%d)" ), authorisationReceived); |
|
249 |
|
250 if( GetBoolFromConfig(aSection, KAuthorisation(), authorisation)) |
|
251 { |
|
252 INFO_PRINTF2(_L("TBTServiceSecurity Authorisation: expected (%d)" ), authorisation); |
|
253 if(authorisation != authorisationReceived) |
|
254 { |
|
255 ERR_PRINTF1(_L("Authorisation is not as expected!")); |
|
256 SetBlockResult(EFail); |
|
257 } |
|
258 } |
|
259 else |
|
260 { |
|
261 // Try reading the Int version |
|
262 if (GetIntFromConfig(aSection, KAuthorisationInt(), authorisation)) |
|
263 { |
|
264 INFO_PRINTF2(_L("TBTServiceSecurity Authorisation: expected (%d)" ), authorisation); |
|
265 if(authorisation != authorisationReceived) |
|
266 { |
|
267 ERR_PRINTF1(_L("Authorisation is not as expected!")); |
|
268 SetBlockResult(EFail); |
|
269 } |
|
270 } |
|
271 else |
|
272 { |
|
273 ERR_PRINTF1(_L("GetBoolFromConfig and GetIntFromConfig failed")); |
|
274 SetBlockResult(EFail); |
|
275 } |
|
276 } |
|
277 } |
|
278 |
|
279 void CT_BTServiceSecurityData::TBTSSSetDenied(const TDesC& aSection) |
|
280 { |
|
281 TBool denied; |
|
282 if( GetBoolFromConfig(aSection, KDenied(), denied)) |
|
283 { |
|
284 INFO_PRINTF2(_L("TBTServiceSecurity SetDenied (%d)"), denied); |
|
285 iBTServiceSecurity->SetDenied(denied); |
|
286 } |
|
287 else |
|
288 { |
|
289 ERR_PRINTF1(_L("GetBoolFromConfig failed")); |
|
290 SetBlockResult(EFail); |
|
291 } |
|
292 } |
|
293 |
|
294 void CT_BTServiceSecurityData::TBTSSDenied(const TDesC& aSection) |
|
295 { |
|
296 TBool denied; |
|
297 TBool deniedReceived = iBTServiceSecurity->Denied(); |
|
298 INFO_PRINTF2(_L("TBTServiceSecurity Denied: actual (%d)" ), deniedReceived); |
|
299 |
|
300 if( GetBoolFromConfig(aSection, KDenied(), denied)) |
|
301 { |
|
302 INFO_PRINTF2(_L("TBTServiceSecurity Denied: expected (%d)" ), denied); |
|
303 if(denied != deniedReceived) |
|
304 { |
|
305 ERR_PRINTF1(_L("Denied is not as expected!")); |
|
306 SetBlockResult(EFail); |
|
307 } |
|
308 } |
|
309 else |
|
310 { |
|
311 // Try reading the Int version |
|
312 if (GetIntFromConfig(aSection, KDeniedInt(), denied)) |
|
313 { |
|
314 INFO_PRINTF2(_L("TBTServiceSecurity Denied: expected (%d)" ), denied); |
|
315 if(denied != deniedReceived) |
|
316 { |
|
317 ERR_PRINTF1(_L("Denied is not as expected!")); |
|
318 SetBlockResult(EFail); |
|
319 } |
|
320 } |
|
321 else |
|
322 { |
|
323 ERR_PRINTF1(_L("GetBoolFromConfig and GetIntFromConfig failed")); |
|
324 SetBlockResult(EFail); |
|
325 } |
|
326 } |
|
327 } |
|
328 |
|
329 void CT_BTServiceSecurityData::TBTSSSetEncryption(const TDesC& aSection) |
|
330 { |
|
331 TBool encryption; |
|
332 if( GetBoolFromConfig(aSection, KEncryption(), encryption)) |
|
333 { |
|
334 INFO_PRINTF2(_L("TBTServiceSecurity SetEncryption (%d)"), encryption); |
|
335 iBTServiceSecurity->SetEncryption(encryption); |
|
336 } |
|
337 else |
|
338 { |
|
339 ERR_PRINTF1(_L("GetBoolFromConfig failed")); |
|
340 SetBlockResult(EFail); |
|
341 } |
|
342 } |
|
343 |
|
344 void CT_BTServiceSecurityData::TBTSSEncryptionRequired(const TDesC& aSection) |
|
345 { |
|
346 TBool encryption; |
|
347 TBool encryptionReceived = iBTServiceSecurity->EncryptionRequired(); |
|
348 INFO_PRINTF2(_L("TBTServiceSecurity Encryption: actual (%d)" ), encryptionReceived); |
|
349 if( GetBoolFromConfig(aSection, KEncryption(), encryption)) |
|
350 { |
|
351 INFO_PRINTF2(_L("TBTServiceSecurity Encryption: expected (%d)" ), encryption); |
|
352 if(encryption != encryptionReceived) |
|
353 { |
|
354 ERR_PRINTF1(_L("Encryption is not as expected!")); |
|
355 SetBlockResult(EFail); |
|
356 } |
|
357 } |
|
358 else |
|
359 { |
|
360 // Try reading the Int version |
|
361 if (GetIntFromConfig(aSection, KEncryptionInt(), encryption)) |
|
362 { |
|
363 INFO_PRINTF2(_L("TBTServiceSecurity Encryption: expected (%d)" ), encryption); |
|
364 if(encryption != encryptionReceived) |
|
365 { |
|
366 ERR_PRINTF1(_L("Encryption is not as expected!")); |
|
367 SetBlockResult(EFail); |
|
368 } |
|
369 } |
|
370 else |
|
371 { |
|
372 ERR_PRINTF1(_L("GetBoolFromConfig and GetIntFromConfig failed")); |
|
373 SetBlockResult(EFail); |
|
374 } |
|
375 } |
|
376 } |
|
377 |
|
378 void CT_BTServiceSecurityData::TBTSSSetPasskeyMinLength(const TDesC& aSection) |
|
379 { |
|
380 TInt passkeyMinLength; |
|
381 if( GetIntFromConfig(aSection, KPasskeyminlength(), passkeyMinLength)) |
|
382 { |
|
383 INFO_PRINTF2(_L("TBTServiceSecurity SetPasskeyMinLength (%d)"), passkeyMinLength); |
|
384 iBTServiceSecurity->SetPasskeyMinLength(passkeyMinLength); |
|
385 } |
|
386 else |
|
387 { |
|
388 ERR_PRINTF1(_L("GetIntFromConfig failed")); |
|
389 SetBlockResult(EFail); |
|
390 } |
|
391 } |
|
392 |
|
393 void CT_BTServiceSecurityData::TBTSSPasskeyMinLength(const TDesC& aSection) |
|
394 { |
|
395 TInt passkeyMinLength; |
|
396 TInt passkeyMinLengthReceived = static_cast<TInt>(iBTServiceSecurity->PasskeyMinLength()); |
|
397 INFO_PRINTF2(_L("TBTServiceSecurity PasskeyMinLength: actual (%d)" ), passkeyMinLengthReceived); |
|
398 if( GetIntFromConfig(aSection, KPasskeyminlength(), passkeyMinLength)) |
|
399 { |
|
400 INFO_PRINTF2(_L("TBTServiceSecurity PasskeyMinLength: expected (%d)" ), passkeyMinLength); |
|
401 if(passkeyMinLength != passkeyMinLengthReceived) |
|
402 { |
|
403 ERR_PRINTF1(_L("PasskeyMinLength is not as expected!")); |
|
404 SetBlockResult(EFail); |
|
405 } |
|
406 } |
|
407 else |
|
408 { |
|
409 ERR_PRINTF1(_L("GetIntFromConfig failed")); |
|
410 SetBlockResult(EFail); |
|
411 } |
|
412 } |
|
413 |
|
414 void CT_BTServiceSecurityData::TBTSSSetUid(const TDesC& aSection) |
|
415 { |
|
416 TInt tmp; |
|
417 if( GetIntFromConfig(aSection, KUid(), tmp)) |
|
418 { |
|
419 TUid uid=TUid::Uid(tmp); |
|
420 INFO_PRINTF2(_L("TBTServiceSecurity SetUid (%d)"), uid.iUid); |
|
421 iBTServiceSecurity->SetUid(uid); |
|
422 } |
|
423 else |
|
424 { |
|
425 ERR_PRINTF1(_L("GetIntFromConfig failed")); |
|
426 SetBlockResult(EFail); |
|
427 } |
|
428 } |
|
429 void CT_BTServiceSecurityData::TBTSSUid(const TDesC& aSection) |
|
430 { |
|
431 TInt tmp; |
|
432 TUid uidReceived = iBTServiceSecurity->Uid(); |
|
433 INFO_PRINTF2(_L("TBTServiceSecurity Uid: actual (%i)" ), uidReceived.iUid ); |
|
434 if( GetIntFromConfig(aSection, KUid(), tmp)) |
|
435 { |
|
436 TUid uid=TUid::Uid(tmp); |
|
437 INFO_PRINTF2(_L("TBTServiceSecurity Uid: expected (%i)" ), uid.iUid ); |
|
438 if(uid != uidReceived) |
|
439 { |
|
440 ERR_PRINTF1(_L("Uid is not as expected!")); |
|
441 SetBlockResult(EFail); |
|
442 } |
|
443 } |
|
444 else |
|
445 { |
|
446 ERR_PRINTF1(_L("GetIntFromConfig failed")); |
|
447 SetBlockResult(EFail); |
|
448 } |
|
449 } |
|
450 |
|
451 TAny* CT_BTServiceSecurityData::GetObject() |
|
452 { |
|
453 return iBTServiceSecurity; |
|
454 } |
|
455 |
|
456 void CT_BTServiceSecurityData::SetObjectL(TAny* aObject) |
|
457 { |
|
458 delete iBTServiceSecurity; |
|
459 iBTServiceSecurity = static_cast<TBTServiceSecurity*>(aObject); |
|
460 } |
|
461 |
|
462 void CT_BTServiceSecurityData::DisownObjectL() |
|
463 { |
|
464 iBTServiceSecurity=NULL; |
|
465 } |
|
466 |
|
467 void CT_BTServiceSecurityData::CopyObjectL(TAny* aObjectPtr) |
|
468 { |
|
469 Cleanup(); |
|
470 TBTServiceSecurity* tmp = static_cast<TBTServiceSecurity*>(aObjectPtr); |
|
471 iBTServiceSecurity =new (ELeave) TBTServiceSecurity(*tmp); |
|
472 } |