|
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 #include <bluetoothav.h> |
|
19 |
|
20 // User Includes |
|
21 #include "T_AvdtpSockAddrData.h" |
|
22 #include "T_BTSockAddrData.h" |
|
23 #include "T_BTServiceSecurityData.h" |
|
24 #include "T_BTDevAddrData.h" |
|
25 #include "T_BTUtil.h" |
|
26 /*@{*/ |
|
27 //Parameters |
|
28 |
|
29 //Fields |
|
30 _LIT(KFldExpected, "expected"); |
|
31 |
|
32 _LIT(KFldSockAddr, "sockaddr"); |
|
33 _LIT(KFldSession, "session"); |
|
34 _LIT(KFldSeid, "seid"); |
|
35 |
|
36 _LIT(KFldFamily, "family"); |
|
37 _LIT(KFldBTAddr, "btaddr"); |
|
38 _LIT(KFldUserlen, "userlen"); |
|
39 _LIT(KFldPort, "port"); |
|
40 _LIT(KFldSecurity, "security"); |
|
41 _LIT(KFldTBTDevAddr, "tbtdevaddr"); |
|
42 |
|
43 _LIT(KFldHexBTAddrL, "hex_btaddr_l"); |
|
44 _LIT(KFldHexBTAddrR, "hex_btaddr_r"); |
|
45 |
|
46 _LIT(KFldSection, "section"); |
|
47 _LIT(KFldConfigHexBTAddrL, "hex_btaddr_l"); |
|
48 _LIT(KFldConfigHexBTAddrR, "hex_btaddr_r"); |
|
49 |
|
50 //Commands |
|
51 _LIT(KCmdnew, "new"); |
|
52 _LIT(KCmdBTAddr, "BTAddr"); |
|
53 _LIT(KCmdBTSecurity, "BTSecurity"); |
|
54 _LIT(KCmdCast, "Cast"); |
|
55 _LIT(KCmdFamily, "Family"); |
|
56 _LIT(KCmdGetUserLen, "GetUserLen"); |
|
57 _LIT(KCmdPort, "Port"); |
|
58 _LIT(KCmdSetSession, "SetSession"); |
|
59 _LIT(KCmdSession, "Session"); |
|
60 _LIT(KCmdSetSEID, "SetSEID"); |
|
61 _LIT(KCmdSEID, "SEID"); |
|
62 _LIT(KCmdDestructor, "~"); |
|
63 |
|
64 // Logging |
|
65 _LIT(KLogMissingParameter, "Missing parameter '%S'"); |
|
66 _LIT(KLogError, "Error=%d"); |
|
67 /*@}*/ |
|
68 |
|
69 ////////////////////////////////////////////////////////////////////// |
|
70 // Construction/Destruction |
|
71 ////////////////////////////////////////////////////////////////////// |
|
72 |
|
73 CT_AvdtpSockAddrData* CT_AvdtpSockAddrData::NewL() |
|
74 { |
|
75 CT_AvdtpSockAddrData* ret=new (ELeave) CT_AvdtpSockAddrData(); |
|
76 CleanupStack::PushL(ret); |
|
77 ret->ConstructL(); |
|
78 CleanupStack::Pop(ret); |
|
79 return ret; |
|
80 } |
|
81 |
|
82 CT_AvdtpSockAddrData::CT_AvdtpSockAddrData() |
|
83 : iData(NULL), iDataOwned(EFalse) |
|
84 { |
|
85 } |
|
86 |
|
87 void CT_AvdtpSockAddrData::ConstructL() |
|
88 { |
|
89 } |
|
90 |
|
91 CT_AvdtpSockAddrData::~CT_AvdtpSockAddrData() |
|
92 { |
|
93 DestroyData(); |
|
94 } |
|
95 |
|
96 TAny* CT_AvdtpSockAddrData::GetObject() |
|
97 { |
|
98 return iData; |
|
99 } |
|
100 |
|
101 |
|
102 void CT_AvdtpSockAddrData::SetObject(TAvdtpSockAddr* aAvdtpSockAddr, TBool aTransferOwnership) |
|
103 { |
|
104 DestroyData(); |
|
105 iData = aAvdtpSockAddr; |
|
106 iDataOwned = aTransferOwnership; |
|
107 } |
|
108 |
|
109 void CT_AvdtpSockAddrData::DisownObjectL() |
|
110 { |
|
111 iData = NULL; |
|
112 } |
|
113 |
|
114 void CT_AvdtpSockAddrData::DestroyData() |
|
115 { |
|
116 if(iDataOwned) |
|
117 { |
|
118 delete iData; |
|
119 } |
|
120 |
|
121 iData=NULL; |
|
122 } |
|
123 |
|
124 inline TCleanupOperation CT_AvdtpSockAddrData::CleanupOperation() |
|
125 { |
|
126 return CleanupOperation; |
|
127 } |
|
128 |
|
129 void CT_AvdtpSockAddrData::CleanupOperation(TAny* aAny) |
|
130 { |
|
131 //may be unnecessary |
|
132 TAvdtpSockAddr* arg=static_cast<TAvdtpSockAddr*>(aAny); |
|
133 delete arg; |
|
134 } |
|
135 |
|
136 |
|
137 TBool CT_AvdtpSockAddrData::DoCommandL(const TTEFFunction& aCommand, const TTEFSectionName& aSection, const TInt /*aAsyncErrorIndex*/) |
|
138 { |
|
139 TBool ret = ETrue; |
|
140 |
|
141 if ( aCommand==KCmdnew ) |
|
142 { |
|
143 DoCmdnewL(aSection); |
|
144 } |
|
145 else if( aCommand== KCmdCast) |
|
146 { |
|
147 DoCmdCast(aSection); |
|
148 } |
|
149 else if( aCommand== KCmdSetSession) |
|
150 { |
|
151 DoCmdSetSession(aSection); |
|
152 } |
|
153 else if( aCommand== KCmdSession) |
|
154 { |
|
155 DoCmdSession(aSection); |
|
156 } |
|
157 else if( aCommand== KCmdSetSEID) |
|
158 { |
|
159 DoCmdSetSEID(aSection); |
|
160 } |
|
161 else if( aCommand== KCmdSEID) |
|
162 { |
|
163 DoCmdSEID(aSection); |
|
164 } |
|
165 else if( aCommand== KCmdFamily) |
|
166 { |
|
167 DoCmdFamily(aSection); |
|
168 } |
|
169 else if( aCommand== KCmdGetUserLen) |
|
170 { |
|
171 DoCmdGetUserLen(aSection); |
|
172 } |
|
173 else if( aCommand== KCmdPort) |
|
174 { |
|
175 DoCmdPort(aSection); |
|
176 } |
|
177 else if( aCommand== KCmdBTAddr) |
|
178 { |
|
179 DoCmdBTAddr(aSection); |
|
180 } |
|
181 else if( aCommand== KCmdBTSecurity) |
|
182 { |
|
183 DoCmdBTSecurity(aSection); |
|
184 } |
|
185 else if ( aCommand==KCmdDestructor ) |
|
186 { |
|
187 DestroyData(); |
|
188 } |
|
189 else |
|
190 { |
|
191 ret=EFalse; |
|
192 } |
|
193 |
|
194 return ret; |
|
195 } |
|
196 |
|
197 /** |
|
198 Test TAvdtpSockAddr() |
|
199 */ |
|
200 void CT_AvdtpSockAddrData::DoCmdnewL(const TDesC& aSection) |
|
201 { |
|
202 INFO_PRINTF1(_L("TAvdtpSockAddr constructor call")); |
|
203 DestroyData(); |
|
204 |
|
205 TInt err = KErrNone; |
|
206 TSockAddr* sockAddr = NULL; |
|
207 TPtrC strSockAddr; |
|
208 |
|
209 if ( GetStringFromConfig(aSection, KFldSockAddr, strSockAddr) ) |
|
210 { |
|
211 INFO_PRINTF1(_L("TAvdtpSockAddr construct with TSockAddr object")); |
|
212 sockAddr = static_cast<TSockAddr*>(GetDataObjectL(strSockAddr)); |
|
213 } |
|
214 |
|
215 if(sockAddr != NULL) |
|
216 { |
|
217 TRAP(err, iData = new ( ELeave ) TAvdtpSockAddr( *sockAddr )); |
|
218 } |
|
219 else |
|
220 { |
|
221 INFO_PRINTF1(_L("TAvdtpSockAddr default constructor")); |
|
222 TRAP(err, iData = new ( ELeave ) TAvdtpSockAddr()); |
|
223 } |
|
224 |
|
225 if (err!= KErrNone) |
|
226 { |
|
227 ERR_PRINTF2(KLogError, err); |
|
228 SetBlockResult(EFail); |
|
229 } |
|
230 else |
|
231 { |
|
232 iDataOwned = ETrue; |
|
233 } |
|
234 } |
|
235 |
|
236 /** |
|
237 Test Cast() |
|
238 */ |
|
239 void CT_AvdtpSockAddrData::DoCmdCast(const TDesC& aSection) |
|
240 { |
|
241 INFO_PRINTF1(_L("TAvdtpSockAddr Cast from TSockAddr Call")); |
|
242 TPtrC myTSockAddrName; |
|
243 TSockAddr* myTSockAddr=NULL; |
|
244 if ( !GetStringFromConfig(aSection, KFldSockAddr(), myTSockAddrName) ) |
|
245 { |
|
246 ERR_PRINTF2(KLogMissingParameter, &KFldSockAddr()); |
|
247 SetBlockResult(EFail); |
|
248 } |
|
249 else |
|
250 { |
|
251 myTSockAddr=static_cast<TSockAddr*>(GetDataObjectL(myTSockAddrName)); |
|
252 |
|
253 if ( myTSockAddr!=NULL ) |
|
254 { |
|
255 DestroyData(); |
|
256 iData = &TAvdtpSockAddr::Cast(*myTSockAddr); |
|
257 iDataOwned = EFalse; |
|
258 } |
|
259 else |
|
260 { |
|
261 ERR_PRINTF1(_L("TSockAddr pointer is NULL")); |
|
262 SetBlockResult(EFail); |
|
263 } |
|
264 } |
|
265 } |
|
266 |
|
267 /** |
|
268 Test SetSession() |
|
269 */ |
|
270 void CT_AvdtpSockAddrData::DoCmdSetSession(const TDesC& aSection) |
|
271 { |
|
272 INFO_PRINTF1(_L("TAvdtpSockAddr SetSession call")); |
|
273 |
|
274 TAvdtpTransportSessionType session; |
|
275 |
|
276 if(CT_BTUtil::ReadAvdtpTransportSessionType(*this, aSection, KFldSession, session)) |
|
277 { |
|
278 INFO_PRINTF2(_L("TAvdtpSockAddr SetSession: session = %d"),session); |
|
279 iData->SetSession(session); |
|
280 } |
|
281 else |
|
282 { |
|
283 ERR_PRINTF2(KLogMissingParameter, &KFldSession()); |
|
284 SetBlockResult(EFail); |
|
285 } |
|
286 } |
|
287 |
|
288 /** |
|
289 Test Session() |
|
290 */ |
|
291 void CT_AvdtpSockAddrData::DoCmdSession(const TDesC& aSection) |
|
292 { |
|
293 TAvdtpTransportSessionType actual; |
|
294 TAvdtpTransportSessionType expected; |
|
295 |
|
296 INFO_PRINTF1(_L("TAvdtpSockAddr Session call")); |
|
297 actual = iData->Session(); |
|
298 |
|
299 if (CT_BTUtil::ReadAvdtpTransportSessionType(*this, aSection, KFldExpected, expected)) |
|
300 { |
|
301 if ( actual != expected ) |
|
302 { |
|
303 ERR_PRINTF1(_L("Session not match as expected")); |
|
304 SetBlockResult(EFail); |
|
305 } |
|
306 } |
|
307 else |
|
308 { |
|
309 ERR_PRINTF2(KLogMissingParameter, &KFldExpected()); |
|
310 SetBlockResult(EFail); |
|
311 } |
|
312 } |
|
313 |
|
314 /** |
|
315 Test SetSEID() |
|
316 */ |
|
317 void CT_AvdtpSockAddrData::DoCmdSetSEID(const TDesC& aSection) |
|
318 { |
|
319 INFO_PRINTF1(_L("TAvdtpSockAddr SetSEID call")); |
|
320 TSEID* seid = NULL; |
|
321 TPtrC strSeid; |
|
322 |
|
323 if(GetStringFromConfig(aSection, KFldSeid, strSeid)) |
|
324 { |
|
325 seid = static_cast<TSEID*>(GetDataObjectL(strSeid)); |
|
326 |
|
327 if (seid != NULL) |
|
328 { |
|
329 iData->SetSEID(*seid); |
|
330 } |
|
331 else |
|
332 { |
|
333 ERR_PRINTF1(_L("TSEID pointer is NULL")); |
|
334 SetBlockResult(EFail); |
|
335 } |
|
336 } |
|
337 else |
|
338 { |
|
339 ERR_PRINTF2(KLogMissingParameter, &KFldSeid()); |
|
340 SetBlockResult(EFail); |
|
341 } |
|
342 |
|
343 |
|
344 |
|
345 } |
|
346 |
|
347 /** |
|
348 Test SEID() |
|
349 */ |
|
350 void CT_AvdtpSockAddrData::DoCmdSEID(const TDesC& aSection) |
|
351 { |
|
352 INFO_PRINTF1(_L("TAvdtpSockAddr SEID call")); |
|
353 TSEID* expectedSEID = NULL; |
|
354 TPtrC strSeid; |
|
355 |
|
356 if(GetStringFromConfig(aSection, KFldExpected, strSeid)) |
|
357 { |
|
358 expectedSEID = static_cast<TSEID*>(GetDataObjectL(strSeid)); |
|
359 |
|
360 if(expectedSEID != NULL) |
|
361 { |
|
362 TSEID actual = iData->SEID(); |
|
363 if(*expectedSEID != actual) |
|
364 { |
|
365 ERR_PRINTF1(_L("Result is not as expected")); |
|
366 SetBlockResult(EFail); |
|
367 } |
|
368 } |
|
369 else |
|
370 { |
|
371 ERR_PRINTF1(_L("TSEID pointer is NULL")); |
|
372 SetBlockResult(EFail); |
|
373 } |
|
374 } |
|
375 else |
|
376 { |
|
377 ERR_PRINTF2(KLogMissingParameter, &KFldExpected()); |
|
378 SetBlockResult(EFail); |
|
379 } |
|
380 } |
|
381 |
|
382 void CT_AvdtpSockAddrData::DoCmdFamily(const TDesC& aSection) |
|
383 { |
|
384 INFO_PRINTF1(_L("TAvdtpSockAddr Family call")); |
|
385 TInt family; |
|
386 |
|
387 TInt familyReceived = static_cast<TInt>(iData->Family()); |
|
388 INFO_PRINTF2(_L("TBTSockAddr Family: actual (%d)" ), familyReceived); |
|
389 |
|
390 if( GetIntFromConfig(aSection, KFldFamily(), family)) |
|
391 { |
|
392 INFO_PRINTF2(_L("TBTSockAddr Family: expected (%d)" ), family); |
|
393 |
|
394 if(family != familyReceived) |
|
395 { |
|
396 ERR_PRINTF1(_L("Family is not as expected!")); |
|
397 SetBlockResult(EFail); |
|
398 } |
|
399 } |
|
400 else |
|
401 { |
|
402 ERR_PRINTF1(_L("TBTSockAddrFamily GetIntFromConfig failed")); |
|
403 SetBlockResult(EFail); |
|
404 } |
|
405 } |
|
406 |
|
407 void CT_AvdtpSockAddrData::DoCmdGetUserLen(const TDesC& aSection) |
|
408 { |
|
409 INFO_PRINTF1(_L("TAvdtpSockAddr GetUserLen call")); |
|
410 |
|
411 TInt userLen; |
|
412 |
|
413 TInt userLenReceived = static_cast<TInt>(iData->GetUserLen()); |
|
414 INFO_PRINTF2(_L("TBTSockAddr Protected UserLen: actual (%d)"), userLenReceived); |
|
415 |
|
416 if( GetIntFromConfig(aSection, KFldUserlen(), userLen)) |
|
417 { |
|
418 INFO_PRINTF2(_L("TBTSockAddr Protected UserLen: expected (%d)" ), userLen); |
|
419 if(userLen != userLenReceived) |
|
420 { |
|
421 ERR_PRINTF1(_L("UserLen is not as expected!")); |
|
422 SetBlockResult(EFail); |
|
423 } |
|
424 } |
|
425 else |
|
426 { |
|
427 ERR_PRINTF1(_L("TBTSockAddrGetUserLen GetIntFromConfig failed")); |
|
428 SetBlockResult(EFail); |
|
429 } |
|
430 } |
|
431 void CT_AvdtpSockAddrData::DoCmdPort(const TDesC& aSection) |
|
432 { |
|
433 INFO_PRINTF1(_L("TAvdtpSockAddr Port call")); |
|
434 |
|
435 TInt port; |
|
436 |
|
437 TInt portReceived = static_cast<TInt>(iData->Port()); |
|
438 INFO_PRINTF2(_L("TBTSockAddr Port: actual (%d)" ), portReceived); |
|
439 |
|
440 if( GetIntFromConfig(aSection, KFldPort(), port)) |
|
441 { |
|
442 INFO_PRINTF2(_L("TBTSockAddr Port: expected (%d)" ), port); |
|
443 if(port != portReceived) |
|
444 { |
|
445 ERR_PRINTF1(_L("Port is not as expected!")); |
|
446 SetBlockResult(EFail); |
|
447 } |
|
448 } |
|
449 else |
|
450 { |
|
451 ERR_PRINTF1(_L("TBTSockAddrPort GetIntFromConfig failed")); |
|
452 SetBlockResult(EFail); |
|
453 } |
|
454 } |
|
455 void CT_AvdtpSockAddrData::DoCmdBTAddr(const TDesC& aSection) |
|
456 { |
|
457 INFO_PRINTF1(_L("TAvdtpSockAddr BTAddr call")); |
|
458 |
|
459 TInt devId; |
|
460 |
|
461 TBTDevAddr retrivedDevAddr = iData->BTAddr(); |
|
462 TBuf<KMaxSockAddrSize> tmpBuf; |
|
463 retrivedDevAddr.GetReadable(tmpBuf); |
|
464 INFO_PRINTF2(_L("Bluetooth address: actual = 0x%S"),&tmpBuf); |
|
465 |
|
466 if( GetIntFromConfig(aSection, KFldBTAddr(), devId)) |
|
467 { |
|
468 TBTDevAddr devAddr= TBTDevAddr(devId); |
|
469 TBuf<KMaxSockAddrSize> tmpBuf2; |
|
470 devAddr.GetReadable(tmpBuf2); |
|
471 INFO_PRINTF2(_L("Bluetooth address: expected = 0x%S"),&tmpBuf2); |
|
472 |
|
473 |
|
474 if(devAddr != retrivedDevAddr) |
|
475 { |
|
476 ERR_PRINTF1(_L("BTAddr is not as expected!")); |
|
477 SetBlockResult(EFail); |
|
478 } |
|
479 else |
|
480 { |
|
481 INFO_PRINTF1(_L("TBTSockAddr BTAddr as expected")); |
|
482 } |
|
483 } |
|
484 else |
|
485 { |
|
486 TPtrC configSectionName; |
|
487 if( GetStringFromConfig(aSection, KFldSection(), configSectionName)) |
|
488 { |
|
489 INFO_PRINTF2(_L("Getting BT Adress from config section: (%S)"), &configSectionName); |
|
490 TInt lhs; |
|
491 TInt rhs; |
|
492 if ( !GetHexFromConfig(configSectionName, KFldConfigHexBTAddrL(), lhs )) |
|
493 { |
|
494 ERR_PRINTF1(_L("TBTSockAddrSetBTAddr GetHexFromConfig failed")); |
|
495 SetBlockResult(EFail); |
|
496 } |
|
497 if ( !GetHexFromConfig(configSectionName, KFldConfigHexBTAddrR(), rhs )) |
|
498 { |
|
499 ERR_PRINTF1(_L("TBTSockAddrSetBTAddr GetHexFromConfig failed")); |
|
500 SetBlockResult(EFail); |
|
501 } |
|
502 TBTDevAddr devAddr (MAKE_TINT64(lhs, rhs)); |
|
503 if(devAddr != retrivedDevAddr) |
|
504 { |
|
505 ERR_PRINTF1(_L("BTAddr is not as expected!")); |
|
506 SetBlockResult(EFail); |
|
507 } |
|
508 else |
|
509 { |
|
510 INFO_PRINTF1(_L("TBTSockAddr BTAddr as expected")); |
|
511 } |
|
512 } |
|
513 |
|
514 else |
|
515 { |
|
516 TPtrC myTBTDevAddrName; |
|
517 if( GetStringFromConfig(aSection, KFldTBTDevAddr(), myTBTDevAddrName)) |
|
518 { |
|
519 CT_BTDevAddrData* myTBTDevAddrData=static_cast<CT_BTDevAddrData*>(GetDataWrapperL(myTBTDevAddrName)); |
|
520 TBTDevAddr btDevAddr = *myTBTDevAddrData->GetAddress(); |
|
521 TBuf<KMaxSockAddrSize> tmpBuf2; |
|
522 btDevAddr.GetReadable(tmpBuf2); |
|
523 if (tmpBuf2 != tmpBuf) |
|
524 { |
|
525 ERR_PRINTF3(_L("Expected address (%S) != actual address (%S)"),&tmpBuf2,&tmpBuf); |
|
526 SetBlockResult(EFail); |
|
527 } |
|
528 } |
|
529 else |
|
530 { |
|
531 TInt lhs; |
|
532 TInt rhs; |
|
533 if ( GetHexFromConfig(aSection, KFldHexBTAddrL(), lhs )) |
|
534 { |
|
535 if ( !GetHexFromConfig(aSection, KFldHexBTAddrR(), rhs )) |
|
536 { |
|
537 ERR_PRINTF1(_L("TBTSockAddrBTAddr GetHexFromConfig failed")); |
|
538 SetBlockResult(EFail); |
|
539 } |
|
540 TBTDevAddr devAddr (MAKE_TINT64(lhs, rhs)); |
|
541 if(devAddr != retrivedDevAddr) |
|
542 { |
|
543 ERR_PRINTF1(_L("BTAddr is not as expected!")); |
|
544 SetBlockResult(EFail); |
|
545 } |
|
546 else |
|
547 { |
|
548 INFO_PRINTF1(_L("TBTSockAddr BTAddr as expected")); |
|
549 } |
|
550 } |
|
551 } |
|
552 } |
|
553 } |
|
554 } |
|
555 void CT_AvdtpSockAddrData::DoCmdBTSecurity(const TDesC& aSection) |
|
556 { |
|
557 INFO_PRINTF1(_L("TAvdtpSockAddr BTSecurity call")); |
|
558 |
|
559 TPtrC myBTServiceSecurityName; |
|
560 CT_BTServiceSecurityData* myBTServiceSecurityData=NULL; |
|
561 if ( !GetStringFromConfig(aSection, KFldSecurity(), myBTServiceSecurityName) ) |
|
562 { |
|
563 ERR_PRINTF2(_L("No %S"), &KFldSecurity()); |
|
564 SetBlockResult(EFail); |
|
565 } |
|
566 else |
|
567 { |
|
568 myBTServiceSecurityData=static_cast<CT_BTServiceSecurityData*>(GetDataWrapperL(myBTServiceSecurityName)); |
|
569 } |
|
570 if ( myBTServiceSecurityData!=NULL ) |
|
571 { |
|
572 TBTServiceSecurity tmp = iData->BTSecurity(); |
|
573 myBTServiceSecurityData->CopyObjectL(&tmp); |
|
574 } |
|
575 else |
|
576 { |
|
577 ERR_PRINTF1(_L("TBTSockAddrBTSecurity BTServiceSecurity is NULL")); |
|
578 SetBlockResult(EFail); |
|
579 } |
|
580 } |