|
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 "T_L2CapSockAddrData.h" |
|
19 #include "T_BTServiceSecurityData.h" |
|
20 #include "T_BTDevAddrData.h" |
|
21 |
|
22 |
|
23 /*@{*/ |
|
24 //Parameters |
|
25 _LIT(KFamily, "family"); |
|
26 _LIT(KTSockAddr, "sockaddr"); |
|
27 _LIT(KPort, "port"); |
|
28 _LIT(KSecurity, "security"); |
|
29 _LIT(KBTAddr, "btaddr"); |
|
30 _LIT(KTBTDevAddr, "tbtdevaddr"); |
|
31 |
|
32 _LIT(KHexBTAddrL, "hex_btaddr_l"); |
|
33 _LIT(KHexBTAddrR, "hex_btaddr_r"); |
|
34 |
|
35 _LIT(KSection, "section"); |
|
36 _LIT(KConfigHexBTAddrL, "hex_btaddr_l"); |
|
37 _LIT(KConfigHexBTAddrR, "hex_btaddr_r"); |
|
38 |
|
39 //Commands |
|
40 _LIT(KCmdTL2CAPSockAddr, "TL2CAPSockAddr"); |
|
41 _LIT(KCmdCast, "Cast"); |
|
42 _LIT(KCmdSetPort, "SetPort"); |
|
43 _LIT(KCmdPort, "Port"); |
|
44 _LIT(KCmdSetSecurity, "SetSecurity"); |
|
45 _LIT(KCmdSetBTAddr, "SetBTAddr"); |
|
46 _LIT(KCmdBTAddr, "BTAddr"); |
|
47 _LIT(KCmdSetFamily, "SetFamily"); |
|
48 |
|
49 // Logging |
|
50 _LIT(KLogMissingParameter, "Missing parameter '%S'"); |
|
51 |
|
52 /*@}*/ |
|
53 |
|
54 ////////////////////////////////////////////////////////////////////// |
|
55 // Construction/Destruction |
|
56 ////////////////////////////////////////////////////////////////////// |
|
57 |
|
58 CT_L2CAPSockAddrData* CT_L2CAPSockAddrData::NewL() |
|
59 { |
|
60 CT_L2CAPSockAddrData* ret=new (ELeave) CT_L2CAPSockAddrData(); |
|
61 CleanupStack::PushL(ret); |
|
62 ret->ConstructL(); |
|
63 CleanupStack::Pop(ret); |
|
64 return ret; |
|
65 } |
|
66 |
|
67 CT_L2CAPSockAddrData::CT_L2CAPSockAddrData() |
|
68 : iData(NULL) |
|
69 { |
|
70 } |
|
71 |
|
72 void CT_L2CAPSockAddrData::ConstructL() |
|
73 { |
|
74 } |
|
75 |
|
76 CT_L2CAPSockAddrData::~CT_L2CAPSockAddrData() |
|
77 { |
|
78 DestroyData(); |
|
79 } |
|
80 |
|
81 TAny* CT_L2CAPSockAddrData::GetObject() |
|
82 { |
|
83 return iData; |
|
84 } |
|
85 |
|
86 void CT_L2CAPSockAddrData::SetObjectL(TAny* aAny) |
|
87 { |
|
88 DestroyData(); |
|
89 iData = static_cast<TL2CAPSockAddr*> (aAny); |
|
90 } |
|
91 |
|
92 void CT_L2CAPSockAddrData::DisownObjectL() |
|
93 { |
|
94 iData = NULL; |
|
95 } |
|
96 |
|
97 void CT_L2CAPSockAddrData::DestroyData() |
|
98 { |
|
99 delete iData; |
|
100 iData=NULL; |
|
101 } |
|
102 |
|
103 inline TCleanupOperation CT_L2CAPSockAddrData::CleanupOperation() |
|
104 { |
|
105 return CleanupOperation; |
|
106 } |
|
107 |
|
108 void CT_L2CAPSockAddrData::CleanupOperation(TAny* aAny) |
|
109 { |
|
110 //may be unnecessary |
|
111 TL2CAPSockAddr* arg=static_cast<TL2CAPSockAddr*>(aAny); |
|
112 delete arg; |
|
113 } |
|
114 |
|
115 TBool CT_L2CAPSockAddrData::DoCommandL(const TTEFFunction& aCommand, const TTEFSectionName& aSection, const TInt /*aAsyncErrorIndex*/) |
|
116 { |
|
117 TBool ret = ETrue; |
|
118 |
|
119 if ( aCommand==KCmdTL2CAPSockAddr ) |
|
120 { |
|
121 DoCmdTL2CAPSockAddr(aSection); |
|
122 } |
|
123 else if ( aCommand==KCmdCast ) |
|
124 { |
|
125 DoCmdCast(aSection); |
|
126 } |
|
127 else if ( aCommand==KCmdPort ) |
|
128 { |
|
129 DoCmdPort(aSection); |
|
130 } |
|
131 else if ( aCommand==KCmdSetPort ) |
|
132 { |
|
133 DoCmdSetPort(aSection); |
|
134 } |
|
135 else if ( aCommand==KCmdSetSecurity ) |
|
136 { |
|
137 DoCmdSetSecurity(aSection); |
|
138 } |
|
139 else if ( aCommand==KCmdSetBTAddr ) |
|
140 { |
|
141 DoCmdSetBTAddr(aSection); |
|
142 } |
|
143 else if ( aCommand==KCmdBTAddr ) |
|
144 { |
|
145 DoCmdBTAddr(aSection); |
|
146 } |
|
147 else if ( aCommand==KCmdSetFamily ) |
|
148 { |
|
149 DoCmdSetFamily(aSection); |
|
150 } |
|
151 |
|
152 else |
|
153 { |
|
154 ret=EFalse; |
|
155 } |
|
156 return ret; |
|
157 } |
|
158 |
|
159 |
|
160 /** |
|
161 Test TL2CAPSockAddr() |
|
162 */ |
|
163 void CT_L2CAPSockAddrData::DoCmdTL2CAPSockAddr(const TDesC& aSection) |
|
164 { |
|
165 |
|
166 TPtrC myTSockAddrName; |
|
167 |
|
168 if ( !GetStringFromConfig(aSection, KTSockAddr(), myTSockAddrName) ) |
|
169 { |
|
170 DestroyData(); |
|
171 //Use default constructor |
|
172 INFO_PRINTF1(_L("TL2CAPSockAddr Constructor Call")); |
|
173 iData = new (ELeave) TL2CAPSockAddr(); |
|
174 } |
|
175 else |
|
176 { |
|
177 TSockAddr* myTSockAddr = static_cast<TSockAddr*>(GetDataObjectL(myTSockAddrName)); |
|
178 |
|
179 if ( myTSockAddr!=NULL ) |
|
180 { |
|
181 DestroyData(); |
|
182 INFO_PRINTF1(_L("TL2CAPSockAddr Constructor Call")); |
|
183 iData = new (ELeave) TL2CAPSockAddr(*myTSockAddr); |
|
184 } |
|
185 else |
|
186 { |
|
187 ERR_PRINTF1(_L("TL2CAPSockAddr Construct From TSockAddr. TSockAddr is NULL")); |
|
188 SetBlockResult(EFail); |
|
189 } |
|
190 } |
|
191 } |
|
192 |
|
193 |
|
194 /** |
|
195 Test Cast() |
|
196 */ |
|
197 void CT_L2CAPSockAddrData::DoCmdCast(const TDesC& aSection) |
|
198 { |
|
199 TPtrC myTSockAddrName; |
|
200 |
|
201 if (GetStringFromConfig(aSection, KTSockAddr(), myTSockAddrName) ) |
|
202 { |
|
203 TSockAddr* myTSockAddr = static_cast<TSockAddr*>(GetDataObjectL(myTSockAddrName)); |
|
204 if ( myTSockAddr!=NULL ) |
|
205 { |
|
206 INFO_PRINTF1(_L("TL2CAPSockAddr Cast Call")); |
|
207 TL2CAPSockAddr& tl2CAPSockAddr = TL2CAPSockAddr::Cast(*myTSockAddr); |
|
208 INFO_PRINTF1(_L("Downcast a TSockAddr to a TL2CAPSockAddr succeeded")); |
|
209 } |
|
210 else |
|
211 { |
|
212 ERR_PRINTF1(_L("TSockAddr is NULL")); |
|
213 SetBlockResult(EFail); |
|
214 } |
|
215 } |
|
216 else |
|
217 { |
|
218 ERR_PRINTF2(KLogMissingParameter, &KTSockAddr()); |
|
219 SetBlockResult(EFail); |
|
220 } |
|
221 } |
|
222 |
|
223 |
|
224 /** |
|
225 Test Port() |
|
226 */ |
|
227 void CT_L2CAPSockAddrData::DoCmdPort(const TDesC& aSection) |
|
228 { |
|
229 INFO_PRINTF1(_L("TL2CAPSockAddr Port Call")); |
|
230 TL2CAPPort portReceived = iData->Port(); |
|
231 INFO_PRINTF2(_L("TL2CAPSockAddr Port: actual (%d)" ), portReceived); |
|
232 |
|
233 TInt port=0; |
|
234 if(GetIntFromConfig(aSection, KPort(), port)) |
|
235 { |
|
236 INFO_PRINTF2(_L("TL2CAPSockAddr Port: expected (%d)" ), port); |
|
237 |
|
238 if(port != portReceived) |
|
239 { |
|
240 ERR_PRINTF1(_L("Port is not as expected!")); |
|
241 SetBlockResult(EFail); |
|
242 } |
|
243 } |
|
244 else |
|
245 { |
|
246 ERR_PRINTF2(KLogMissingParameter, &KPort()); |
|
247 SetBlockResult(EFail); |
|
248 } |
|
249 } |
|
250 |
|
251 |
|
252 /** |
|
253 Test SetPort() |
|
254 */ |
|
255 void CT_L2CAPSockAddrData::DoCmdSetPort(const TDesC& aSection) |
|
256 { |
|
257 TInt port=0; |
|
258 if(GetIntFromConfig(aSection, KPort(), port)) |
|
259 { |
|
260 INFO_PRINTF1(_L("TL2CAPSockAddr SetPort Call")); |
|
261 iData->SetPort((TL2CAPPort)port); |
|
262 } |
|
263 else |
|
264 { |
|
265 ERR_PRINTF2(KLogMissingParameter, &KPort()); |
|
266 SetBlockResult(EFail); |
|
267 } |
|
268 } |
|
269 |
|
270 |
|
271 void CT_L2CAPSockAddrData::DoCmdSetSecurity(const TDesC& aSection) |
|
272 { |
|
273 INFO_PRINTF1(_L("TL2CAPSockAddr SetSecurity to current iBTServiceSecurity")); |
|
274 TPtrC myBTServiceSecurityName; |
|
275 TBTServiceSecurity* myBTServiceSecurity=NULL; |
|
276 if ( !GetStringFromConfig(aSection, KSecurity(), myBTServiceSecurityName) ) |
|
277 { |
|
278 ERR_PRINTF2(KLogMissingParameter, &KSecurity()); |
|
279 SetBlockResult(EFail); |
|
280 } |
|
281 else |
|
282 { |
|
283 myBTServiceSecurity=static_cast<TBTServiceSecurity*>(GetDataObjectL(myBTServiceSecurityName)); |
|
284 } |
|
285 if ( myBTServiceSecurity!=NULL ) |
|
286 { |
|
287 iData->SetSecurity(*myBTServiceSecurity); |
|
288 } |
|
289 else |
|
290 { |
|
291 ERR_PRINTF1(_L("TL2CAPSockAddr SetSecurity TBTServiceSecurity is NULL")); |
|
292 SetBlockResult(EFail); |
|
293 } |
|
294 } |
|
295 |
|
296 |
|
297 |
|
298 void CT_L2CAPSockAddrData::DoCmdSetBTAddr(const TDesC& aSection) |
|
299 { |
|
300 TInt devId; |
|
301 if(GetIntFromConfig(aSection, KBTAddr(), devId)) |
|
302 { |
|
303 INFO_PRINTF2(_L("TBTSockAddr SetBTAddr (%d)"), devId); |
|
304 iData->SetBTAddr(devId); |
|
305 } |
|
306 else |
|
307 { |
|
308 TPtrC configSectionName; |
|
309 if(GetStringFromConfig(aSection, KSection(), configSectionName)) |
|
310 { |
|
311 INFO_PRINTF2(_L("Getting BT Adress from config section: (%S)"), &configSectionName); |
|
312 TInt lhs; |
|
313 TInt rhs; |
|
314 if ( !GetHexFromConfig(aSection, KConfigHexBTAddrL(), lhs )) |
|
315 { |
|
316 ERR_PRINTF1(_L("TBTSockAddrSetBTAddr GetHexFromConfig failed")); |
|
317 SetBlockResult(EFail); |
|
318 } |
|
319 if ( !GetHexFromConfig(aSection, KConfigHexBTAddrR(), rhs )) |
|
320 { |
|
321 ERR_PRINTF1(_L("TBTSockAddrSetBTAddr GetHexFromConfig failed")); |
|
322 SetBlockResult(EFail); |
|
323 } |
|
324 TBTDevAddr btDevAddr (MAKE_TINT64(lhs, rhs)); |
|
325 iData->SetBTAddr(btDevAddr); |
|
326 } |
|
327 else |
|
328 { |
|
329 TPtrC myTBTDevAddrName; |
|
330 if(GetStringFromConfig(aSection, KTBTDevAddr(), myTBTDevAddrName)) |
|
331 { |
|
332 CT_BTDevAddrData* myTBTDevAddrData=static_cast<CT_BTDevAddrData*>(GetDataWrapperL(myTBTDevAddrName)); |
|
333 iData->SetBTAddr(*myTBTDevAddrData->GetAddress()); |
|
334 TBTDevAddr retrivedDevAddr = *myTBTDevAddrData->GetAddress(); |
|
335 TBuf<KMaxSockAddrSize> tmpBuf; |
|
336 retrivedDevAddr.GetReadable(tmpBuf); |
|
337 INFO_PRINTF2(_L("Bluetooth address from stored object: actual = 0x%S"),&tmpBuf); |
|
338 } |
|
339 else |
|
340 { |
|
341 TInt lhs; |
|
342 TInt rhs; |
|
343 if ( !GetHexFromConfig(aSection, KHexBTAddrL(), lhs )) |
|
344 { |
|
345 ERR_PRINTF1(_L("TL2CAPSockAddr GetHexFromConfig failed")); |
|
346 SetBlockResult(EFail); |
|
347 } |
|
348 if ( !GetHexFromConfig(aSection, KHexBTAddrR(), rhs )) |
|
349 { |
|
350 ERR_PRINTF1(_L("TL2CAPSockAddr SetBTAddr GetHexFromConfig failed")); |
|
351 SetBlockResult(EFail); |
|
352 } |
|
353 TBTDevAddr btDevAddr (MAKE_TINT64(lhs, rhs)); |
|
354 iData->SetBTAddr(btDevAddr); |
|
355 } |
|
356 } |
|
357 } |
|
358 } |
|
359 |
|
360 void CT_L2CAPSockAddrData::DoCmdBTAddr(const TDesC& aSection) |
|
361 { |
|
362 TInt devId; |
|
363 |
|
364 TBTDevAddr retrivedDevAddr = iData->BTAddr(); |
|
365 TBuf<KMaxSockAddrSize> tmpBuf; |
|
366 retrivedDevAddr.GetReadable(tmpBuf); |
|
367 INFO_PRINTF2(_L("Bluetooth address: actual = 0x%S"),&tmpBuf); |
|
368 |
|
369 if(GetIntFromConfig(aSection, KBTAddr(), devId)) |
|
370 { |
|
371 TBTDevAddr devAddr= TBTDevAddr(devId); |
|
372 TBuf<KMaxSockAddrSize> tmpBuf2; |
|
373 devAddr.GetReadable(tmpBuf2); |
|
374 INFO_PRINTF2(_L("Bluetooth address: expected = 0x%S"),&tmpBuf2); |
|
375 |
|
376 if(devAddr != retrivedDevAddr) |
|
377 { |
|
378 ERR_PRINTF1(_L("BTAddr is not as expected!")); |
|
379 SetBlockResult(EFail); |
|
380 } |
|
381 else |
|
382 { |
|
383 INFO_PRINTF1(_L("TBTSockAddr BTAddr as expected")); |
|
384 } |
|
385 } |
|
386 else |
|
387 { |
|
388 TPtrC configSectionName; |
|
389 if(GetStringFromConfig(aSection, KSection(), configSectionName)) |
|
390 { |
|
391 INFO_PRINTF2(_L("Getting BT Adress from config section: (%S)"), &configSectionName); |
|
392 TInt lhs; |
|
393 TInt rhs; |
|
394 if ( !GetHexFromConfig(aSection, KConfigHexBTAddrL(), lhs )) |
|
395 { |
|
396 ERR_PRINTF1(_L("TBTSockAddrSetBTAddr GetHexFromConfig failed")); |
|
397 SetBlockResult(EFail); |
|
398 } |
|
399 if ( !GetHexFromConfig(aSection, KConfigHexBTAddrR(), rhs )) |
|
400 { |
|
401 ERR_PRINTF1(_L("TBTSockAddrSetBTAddr GetHexFromConfig failed")); |
|
402 SetBlockResult(EFail); |
|
403 } |
|
404 TBTDevAddr devAddr (MAKE_TINT64(lhs, rhs)); |
|
405 if(devAddr != retrivedDevAddr) |
|
406 { |
|
407 ERR_PRINTF1(_L("BTAddr is not as expected!")); |
|
408 SetBlockResult(EFail); |
|
409 } |
|
410 else |
|
411 { |
|
412 INFO_PRINTF1(_L("TBTSockAddr BTAddr as expected")); |
|
413 } |
|
414 } |
|
415 |
|
416 else |
|
417 { |
|
418 TPtrC myTBTDevAddrName; |
|
419 if(GetStringFromConfig(aSection, KTBTDevAddr(), myTBTDevAddrName)) |
|
420 { |
|
421 CT_BTDevAddrData* myTBTDevAddrData=static_cast<CT_BTDevAddrData*>(GetDataWrapperL(myTBTDevAddrName)); |
|
422 TBTDevAddr btDevAddr = *myTBTDevAddrData->GetAddress(); |
|
423 TBuf<KMaxSockAddrSize> tmpBuf2; |
|
424 btDevAddr.GetReadable(tmpBuf2); |
|
425 if (tmpBuf2 != tmpBuf) |
|
426 { |
|
427 ERR_PRINTF3(_L("Expected address (%S) != actual address (%S)"),&tmpBuf2,&tmpBuf); |
|
428 SetBlockResult(EFail); |
|
429 } |
|
430 } |
|
431 else |
|
432 { |
|
433 TInt lhs; |
|
434 TInt rhs; |
|
435 if (GetHexFromConfig(aSection, KHexBTAddrL(), lhs )) |
|
436 { |
|
437 if ( !GetHexFromConfig(aSection, KHexBTAddrR(), rhs )) |
|
438 { |
|
439 ERR_PRINTF1(_L("TBTSockAddrBTAddr GetHexFromConfig failed")); |
|
440 SetBlockResult(EFail); |
|
441 } |
|
442 TBTDevAddr devAddr (MAKE_TINT64(lhs, rhs)); |
|
443 if(devAddr != retrivedDevAddr) |
|
444 { |
|
445 ERR_PRINTF1(_L("BTAddr is not as expected!")); |
|
446 SetBlockResult(EFail); |
|
447 } |
|
448 else |
|
449 { |
|
450 INFO_PRINTF1(_L("TBTSockAddr BTAddr as expected")); |
|
451 } |
|
452 } |
|
453 } |
|
454 } |
|
455 } |
|
456 } |
|
457 |
|
458 |
|
459 void CT_L2CAPSockAddrData::DoCmdSetFamily(const TDesC& aSection) |
|
460 { |
|
461 TInt family; |
|
462 if(GetIntFromConfig(aSection, KFamily(), family)) |
|
463 { |
|
464 INFO_PRINTF2(_L("TL2CAPSockAddr SetFamily (%d)"), family); |
|
465 iData->SetFamily(family); |
|
466 } |
|
467 else |
|
468 { |
|
469 ERR_PRINTF2(KLogMissingParameter, &KFamily()); |
|
470 SetBlockResult(EFail); |
|
471 } |
|
472 } |
|
473 |