|
1 // Copyright (c) 2005-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 // BT Host Resolver test code |
|
15 // |
|
16 // |
|
17 |
|
18 #include "teir.h" |
|
19 #include <utf.h> |
|
20 #include <btsdp.h> |
|
21 #include <e32math.h> |
|
22 |
|
23 #define USE_SMALL_CONSOLE 0 |
|
24 |
|
25 typedef TBuf<20> TBTDevAddrBuf; |
|
26 const TUint8 KEIRDataOffset = 1; |
|
27 //_LIT(KManufacturerData, "This is a very very very very very very very very very very very very very very very very very very very very very very very very very very long data from phone manufacturer!"); |
|
28 _LIT(KManufacturerData, "This is a very very long data from phone manufacturer!"); |
|
29 _LIT(KManufacturerData1, ""); |
|
30 |
|
31 |
|
32 GLDEF_D RTest test(_L("Extended Inquiry Response tests")); |
|
33 |
|
34 GLDEF_D TBTDevAddr gDevAddr(MAKE_TINT64(0x0002, 0x5b019a39)); // csr |
|
35 //GLDEF_D TBTDevAddr gDevAddr(MAKE_TINT64(0x001b, 0xdc0f5cae)); // EIR windows |
|
36 GLDEF_D TSize gSmallConsole(75,50); |
|
37 |
|
38 //TInt CActiveHostResolver::iHRNumber = 0; |
|
39 |
|
40 |
|
41 |
|
42 /** |
|
43 Appends a TDesC string to a TDes string. |
|
44 |
|
45 @param aDes String, which aOrg appends to |
|
46 @param aDesC String to be appended to aDest |
|
47 @return EFalse, if there not enough space in the TDes sting to contain the TDesC string. Otherwise, ETrue. |
|
48 */ |
|
49 TBool AppendDes(TDes& aDest, const TDesC& aOrg) |
|
50 { |
|
51 if((aDest.MaxLength() - aDest.Length()) < aOrg.Length()) |
|
52 return EFalse; |
|
53 |
|
54 aDest.Append(aOrg); |
|
55 |
|
56 return ETrue; |
|
57 } |
|
58 |
|
59 |
|
60 // ---------------------------------------------------------------------------- |
|
61 // EIR App |
|
62 // ---------------------------------------------------------------------------- |
|
63 |
|
64 CEirApp::CEirApp(CConsoleBase& aConsole) |
|
65 : iConsole(aConsole) |
|
66 { |
|
67 } |
|
68 |
|
69 CEirApp::~CEirApp() |
|
70 { |
|
71 iResolvers.ResetAndDestroy(); |
|
72 iResolvers.Close(); |
|
73 |
|
74 iDevicesFound.Close(); |
|
75 |
|
76 StopProtocols(); |
|
77 |
|
78 delete iActiveConsole; |
|
79 delete iNameRequester; |
|
80 |
|
81 if(iEirPublisherTestManuSpecific) |
|
82 { |
|
83 delete iManuNotifier; |
|
84 delete iEirPublisherTestManuSpecific; |
|
85 iManuNotifier = NULL; |
|
86 iEirPublisherTestManuSpecific = NULL; |
|
87 } |
|
88 iSdpDB.Close(); |
|
89 } |
|
90 |
|
91 CEirApp* CEirApp::NewL(CConsoleBase& aConsole) |
|
92 { |
|
93 CEirApp* thisapp = new (ELeave) CEirApp(aConsole); |
|
94 CleanupStack::PushL(thisapp); |
|
95 thisapp->ConstructL(aConsole); |
|
96 CleanupStack::Pop(thisapp); |
|
97 return thisapp; |
|
98 } |
|
99 |
|
100 void CEirApp::ConstructL(CConsoleBase& aConsole) |
|
101 { |
|
102 iConsole.Printf(_L("Using HCI_V2\n")); |
|
103 iConsole.Printf(_L("Bluetooth Protocols Loading...\n")); |
|
104 InitialiseL(); |
|
105 iConsole.Printf(_L("Bluetooth Protocols Loaded.\n")); |
|
106 ShowAddress(); |
|
107 iActiveConsole = CActiveConsole::NewL(aConsole, *this); |
|
108 iManuNotifier = CManufacturerDataNotifier::NewL(*this); |
|
109 iEirPublisherTestManuSpecific = CEirPublisherManufacturerSpecificData::NewL(*iManuNotifier); |
|
110 } |
|
111 |
|
112 void CEirApp::StartL() |
|
113 { |
|
114 // go .... |
|
115 CActiveScheduler::Start(); |
|
116 } |
|
117 |
|
118 void CEirApp::Stop() |
|
119 { |
|
120 CActiveScheduler::Stop(); |
|
121 } |
|
122 |
|
123 void CEirApp::SetPublishManuData(TUint aAvailableDataSize) |
|
124 { |
|
125 // TODO: some logic can be added here to cope with the given aAvailableDataSize |
|
126 // maybe truncating the intended data |
|
127 HBufC8* buf = HBufC8::NewL(240);// LocalName-granular truncation |
|
128 buf->Des().Append(KManufacturerData); |
|
129 if(buf->Des().Length() > aAvailableDataSize) |
|
130 { |
|
131 TPtrC8 ptr(buf->Left(aAvailableDataSize)); |
|
132 iEirPublisherTestManuSpecific->SetManufacturerSpecificData(ptr); |
|
133 } |
|
134 else |
|
135 { |
|
136 iEirPublisherTestManuSpecific->SetManufacturerSpecificData(*buf); |
|
137 } |
|
138 delete buf; |
|
139 } |
|
140 |
|
141 void CEirApp::NewEirPublisherTestL(TTestEirTag aTag) |
|
142 { |
|
143 switch(aTag) |
|
144 { |
|
145 case ETestDeviceName: |
|
146 iResolvers.Append(CActiveInquirer::NewL(iConsole, *this, 0, EFalse, EFalse, EFalse, EFalse)); |
|
147 iNameRequester->SetLocalNameL(); |
|
148 break; |
|
149 |
|
150 case ETestUuid16: |
|
151 |
|
152 Register16BitSDPRecordL(); |
|
153 break; |
|
154 |
|
155 case ETestUuid128: |
|
156 Register128BitSDPRecordL(); |
|
157 break; |
|
158 |
|
159 case ETestSetMSD: |
|
160 if(!iManuNotifier && !iEirPublisherTestManuSpecific) |
|
161 { |
|
162 iManuNotifier = CManufacturerDataNotifier::NewL(*this); |
|
163 iEirPublisherTestManuSpecific = CEirPublisherManufacturerSpecificData::NewL(*iManuNotifier); |
|
164 } |
|
165 iEirPublisherTestManuSpecific->RequestPublishDataSize(55); |
|
166 break; |
|
167 case ETestRemoveMSD: |
|
168 if(iEirPublisherTestManuSpecific) |
|
169 { |
|
170 delete iEirPublisherTestManuSpecific; |
|
171 } |
|
172 break; |
|
173 default: |
|
174 iConsole.Printf(_L("INVALID EIR TAG!\n")); |
|
175 //User::Panic(); |
|
176 break; |
|
177 } |
|
178 } |
|
179 |
|
180 void CEirApp::Register16BitSDPRecordL() |
|
181 { |
|
182 CreateSdpRecordL(0x1116); |
|
183 CreateSdpRecordL(0x1234, EFalse); |
|
184 CreateSdpRecordL(0xAABB); |
|
185 CreateSdpRecordL(0xF00D); |
|
186 CreateSdpRecordL(0x0E0D); |
|
187 } |
|
188 |
|
189 void CEirApp::Register128BitSDPRecordL() |
|
190 { |
|
191 // Set Attr 1 (service class list) to list with UUID = 0x0123456789abcdef |
|
192 TUUID uuid1280 = TUUID(0x00000000, 0x00000000, 0x00000000, 0x00000000); |
|
193 TUUID uuid1281 = TUUID(0x11111111, 0x11111111, 0x11111111, 0x11111111); |
|
194 TUUID uuid1282 = TUUID(0x22222222, 0x22222222, 0x22222222, 0x22222222); |
|
195 TUUID uuid1283 = TUUID(0x33333333, 0x33333333, 0x33333333, 0x33333333); |
|
196 TUUID uuid1284 = TUUID(0x44444444, 0x44444444, 0x44444444, 0x44444444); |
|
197 TUUID uuid1285 = TUUID(0x55555555, 0x55555555, 0x55555555, 0x55555555); |
|
198 TUUID uuid1286 = TUUID(0x66666666, 0x66666666, 0x66666666, 0x66666666); |
|
199 TUUID uuid1287 = TUUID(0x77777777, 0x77777777, 0x77777777, 0x77777777); |
|
200 TUUID uuid1288 = TUUID(0x88888888, 0x88888888, 0x88888888, 0x88888888); |
|
201 TUUID uuid1289 = TUUID(0x99999999, 0x99999999, 0x99999999, 0x99999999); |
|
202 |
|
203 CreateSdpRecordL(uuid1280); |
|
204 CreateSdpRecordL(uuid1281, EFalse, EFalse); |
|
205 CreateSdpRecordL(uuid1282); |
|
206 CreateSdpRecordL(uuid1283); |
|
207 CreateSdpRecordL(uuid1284); |
|
208 CreateSdpRecordL(uuid1285); |
|
209 CreateSdpRecordL(uuid1286); |
|
210 CreateSdpRecordL(uuid1287); |
|
211 CreateSdpRecordL(uuid1288); |
|
212 CreateSdpRecordL(uuid1289); |
|
213 } |
|
214 |
|
215 void CEirApp::CreateSdpRecordL(const TUUID& aUUID, |
|
216 TBool aIsPublicBrowseGroup, |
|
217 TBool aIsL2cap) |
|
218 { |
|
219 TSdpServRecordHandle recHandle; |
|
220 CSdpAttrValueDES* attrValDES = NULL; |
|
221 |
|
222 iSdpDB.CreateServiceRecordL(aUUID, recHandle); |
|
223 if(aIsPublicBrowseGroup) |
|
224 { |
|
225 // Browse Group List |
|
226 attrValDES = CSdpAttrValueDES::NewDESL(NULL); |
|
227 CleanupStack::PushL(attrValDES); |
|
228 attrValDES |
|
229 ->StartListL() |
|
230 ->BuildUUIDL(TUUID(TUint16(KPublicBrowseGroupUUID))) // Public Browse Group |
|
231 ->EndListL(); |
|
232 iSdpDB.UpdateAttributeL(recHandle, KSdpAttrIdBrowseGroupList, *attrValDES); |
|
233 CleanupStack::PopAndDestroy(attrValDES); |
|
234 } |
|
235 |
|
236 if(aIsL2cap) |
|
237 { |
|
238 // protocol Descriptor List |
|
239 attrValDES = CSdpAttrValueDES::NewDESL(NULL); |
|
240 CleanupStack::PushL(attrValDES); |
|
241 attrValDES |
|
242 ->StartListL() |
|
243 ->BuildUUIDL(TUUID(KL2CAPUUID)) |
|
244 ->EndListL(); |
|
245 iSdpDB.UpdateAttributeL(recHandle, KSdpAttrIdProtocolDescriptorList, *attrValDES); |
|
246 CleanupStack::PopAndDestroy(attrValDES); |
|
247 } |
|
248 } |
|
249 |
|
250 void CEirApp::NewNameRequesterL(TBool aEirInstead, TBool aIgnoreCache) |
|
251 { |
|
252 iResolvers.Append(CActiveNameRequester::NewL(iConsole, *this, aEirInstead, aIgnoreCache)); |
|
253 } |
|
254 |
|
255 void CEirApp::NewInquirerL(TUint aIAC, TBool aDoNames, TBool aIgnoreCache, TBool aDoEir, TBool forever) |
|
256 { |
|
257 iResolvers.Append(CActiveInquirer::NewL(iConsole, *this, aIAC, aDoNames, aIgnoreCache, aDoEir, forever)); |
|
258 } |
|
259 |
|
260 void CEirApp::CancelInquirer() |
|
261 { |
|
262 TInt numresolvers = iResolvers.Count(); |
|
263 if (numresolvers) |
|
264 iResolvers[numresolvers-1]->Cancel(); //FIXME! Cancel's the newest host resolver |
|
265 else |
|
266 iConsole.Printf(_L("No resolver to cancel!\n")); |
|
267 } |
|
268 |
|
269 void CEirApp::NewNameArrayRequesterL() |
|
270 { |
|
271 iResolvers.Append(CActiveNameArrayRequester::NewL(iConsole, *this, iDevicesFound)); |
|
272 } |
|
273 |
|
274 void CEirApp::DeviceFound(TBTDevAddr aAddress) |
|
275 { |
|
276 #if USE_SMALL_CONSOLE |
|
277 iConsole.Printf(_L("App: Found device.\n")); |
|
278 #endif |
|
279 iDevicesFound.Append(aAddress); |
|
280 } |
|
281 |
|
282 void CEirApp::InquiryComplete() |
|
283 { |
|
284 iConsole.Printf(_L("App: No more devices.\n")); |
|
285 iActiveConsole->DrawCursor(); |
|
286 } |
|
287 |
|
288 RSocketServ& CEirApp::SocketServ() |
|
289 { |
|
290 return iSocketServer; |
|
291 } |
|
292 |
|
293 void CEirApp::InitialiseL() |
|
294 { |
|
295 _LIT(KLDDName, "ECOMM"); |
|
296 |
|
297 #if defined (__WINS__) |
|
298 iConsole.Printf(_L("Initialise using EMULATOR PDD\n")); |
|
299 |
|
300 _LIT(KPDDName, "ECDRV"); |
|
301 #else |
|
302 iConsole.Printf(_L("Initialise using H2 PDD\n")); |
|
303 |
|
304 _LIT(KPDDName, "EUART1"); |
|
305 #endif |
|
306 |
|
307 TInt rerr = KErrNone; |
|
308 |
|
309 rerr = User::LoadPhysicalDevice(KPDDName); |
|
310 if(rerr != KErrNone && rerr != KErrAlreadyExists) |
|
311 { |
|
312 iConsole.Printf(_L("Failed Load Physical Device %d!\n") ,rerr); |
|
313 User::Leave(rerr); |
|
314 } |
|
315 else |
|
316 { |
|
317 iConsole.Printf(_L("Loaded LDD\n")); |
|
318 } |
|
319 |
|
320 rerr = User::LoadLogicalDevice(KLDDName); |
|
321 if(rerr != KErrNone && rerr != KErrAlreadyExists) |
|
322 { |
|
323 iConsole.Printf(_L("Failed Load Logical Device%d!\n") ,rerr); |
|
324 User::Leave(rerr); |
|
325 } |
|
326 else |
|
327 { |
|
328 iConsole.Printf(_L("Loaded PDD\n")); |
|
329 } |
|
330 User::LeaveIfError(iSocketServer.Connect()); |
|
331 |
|
332 rerr = iSdp.Connect(); |
|
333 if(rerr == KErrNone) |
|
334 { |
|
335 rerr = iSdpDB.Open(iSdp); |
|
336 } |
|
337 |
|
338 TProtocolDesc iProtocolInfo; |
|
339 TRequestStatus status; |
|
340 |
|
341 User::LeaveIfError(iSocketServer.FindProtocol(_L("L2CAP"), iProtocolInfo)); |
|
342 iSocketServer.StartProtocol(iProtocolInfo.iAddrFamily, iProtocolInfo.iSockType, iProtocolInfo.iProtocol, status); |
|
343 User::WaitForRequest(status); |
|
344 |
|
345 User::LeaveIfError(iSocketServer.FindProtocol(_L("RFCOMM"), iProtocolInfo)); |
|
346 |
|
347 User::LeaveIfError(iSocketServer.FindProtocol(_L("BTLinkManager"), iProtocolInfo)); |
|
348 } |
|
349 |
|
350 void CEirApp::StopProtocols() |
|
351 { |
|
352 TInt err; |
|
353 TProtocolDesc iProtocolInfo; |
|
354 TRequestStatus status; |
|
355 |
|
356 if(!iSocketServer.Handle()) |
|
357 { |
|
358 // if the socket server has not even been opened |
|
359 // then there is no point trying to unload protocols |
|
360 return; |
|
361 } |
|
362 |
|
363 err = iSocketServer.FindProtocol(_L("L2CAP"), iProtocolInfo); |
|
364 if(err) |
|
365 { |
|
366 iConsole.Printf(_L("Failed to find L2CAP protocol. ERROR %d\n"), err); |
|
367 } |
|
368 |
|
369 iSocketServer.StopProtocol(iProtocolInfo.iAddrFamily, iProtocolInfo.iSockType, iProtocolInfo.iProtocol, status); |
|
370 User::WaitForRequest(status); |
|
371 |
|
372 err = iSocketServer.FindProtocol(_L("RFCOMM"), iProtocolInfo); |
|
373 if(err) |
|
374 { |
|
375 iConsole.Printf(_L("Failed to find RFCOMM protocol. ERROR %d\n"), err); |
|
376 } |
|
377 |
|
378 iSocketServer.StopProtocol(iProtocolInfo.iAddrFamily, iProtocolInfo.iSockType, iProtocolInfo.iProtocol, status); |
|
379 User::WaitForRequest(status); |
|
380 } |
|
381 |
|
382 void CEirApp::ShowAddress() |
|
383 /** |
|
384 Shows the example of using a synchronous Get to retrieve local BTAddr |
|
385 |
|
386 */ |
|
387 { |
|
388 RProperty property; |
|
389 TBuf8<6> addr; |
|
390 TRequestStatus status; |
|
391 |
|
392 iConsole.Printf(_L("Waiting for Local BDADDR...\n")); |
|
393 // Wait for the address to be set |
|
394 TInt err = property.Attach(KPropertyUidBluetoothCategory, KPropertyKeyBluetoothGetLocalDeviceAddress); |
|
395 |
|
396 if(err) |
|
397 { |
|
398 iConsole.Printf(_L("P&S: ERROR attaching to local address\n")); |
|
399 return; |
|
400 } |
|
401 |
|
402 RTimer addrTimer; |
|
403 err = addrTimer.CreateLocal(); |
|
404 if(err != KErrNone) |
|
405 { |
|
406 iConsole.Printf(_L("Error creating P&S timer (%d)\n"), err); |
|
407 property.Close(); |
|
408 return; |
|
409 } |
|
410 TRequestStatus timerStatus; |
|
411 |
|
412 property.Subscribe(status); |
|
413 addrTimer.After(timerStatus, 5000000); // 5 seconds. |
|
414 User::WaitForRequest(status, timerStatus); |
|
415 |
|
416 addrTimer.Close(); // done with timer now. |
|
417 |
|
418 err = property.Get(addr); |
|
419 |
|
420 if (err) |
|
421 { |
|
422 iConsole.Printf(_L("P&S: ERROR getting local address\n")); |
|
423 } |
|
424 else |
|
425 { |
|
426 iConsole.Printf(_L("Local Address: %02X:%02X:%02X:%02X:%02X:%02X\n"), addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]); |
|
427 } |
|
428 |
|
429 // Set inquiry scan |
|
430 RProperty discprop; |
|
431 err=discprop.Set(KPropertyUidBluetoothCategory, KPropertyKeyBluetoothSetScanningStatus, EInquiryAndPageScan); |
|
432 if (err) |
|
433 { |
|
434 iConsole.Printf(_L("P&S: ERROR setting discoverability\n")); |
|
435 } |
|
436 else |
|
437 { |
|
438 iConsole.Printf(_L("Device now in discoverable mode\n")); |
|
439 } |
|
440 property.Close(); |
|
441 |
|
442 User::WaitForRequest(status, timerStatus); |
|
443 } |
|
444 |
|
445 |
|
446 |
|
447 |
|
448 |
|
449 // ---------------------------------------------------------------------------- |
|
450 // Active Host Resolver |
|
451 // ---------------------------------------------------------------------------- |
|
452 |
|
453 CActiveHostResolver::CActiveHostResolver(CConsoleBase& aConsole, CEirApp& aApp) |
|
454 : CActive(EPriorityStandard), iConsole(aConsole), iApp(aApp) |
|
455 { |
|
456 //++iHRNumber; |
|
457 CActiveScheduler::Add(this); |
|
458 } |
|
459 |
|
460 CActiveHostResolver::~CActiveHostResolver() |
|
461 { |
|
462 // if (iHostResolver.SubSessionHandle()) |
|
463 // iHostResolver.Cancel(); |
|
464 Cancel(); |
|
465 iHostResolver.Close(); |
|
466 #if USE_SMALL_CONSOLE |
|
467 delete iHROutputConsole; |
|
468 #endif |
|
469 } |
|
470 |
|
471 void CActiveHostResolver::StartServerL() |
|
472 /** |
|
473 Connect to socket server and get BTLinkManager protocol info |
|
474 **/ |
|
475 { |
|
476 iSocketServer = iApp.SocketServ(); |
|
477 } |
|
478 |
|
479 void CActiveHostResolver::StartHostResolverL() |
|
480 /** |
|
481 In future have a bunch of host resolvers |
|
482 */ |
|
483 { |
|
484 iConsole.Printf(_L("Opening Host Resolver ..\n")); |
|
485 |
|
486 User::LeaveIfError(iSocketServer.FindProtocol(_L("BTLinkManager"), iProtocolInfo)); |
|
487 User::LeaveIfError(iHostResolver.Open(iSocketServer, |
|
488 iProtocolInfo.iAddrFamily, |
|
489 iProtocolInfo.iProtocol)); |
|
490 //#if 0 |
|
491 // show Localname for free |
|
492 TBTDeviceName localName; |
|
493 iHostResolver.GetHostName(localName); |
|
494 iConsole.Printf(_L("Local hostname is %S\n"), &localName); |
|
495 //#endif |
|
496 } |
|
497 |
|
498 TInt CActiveHostResolver::RunError(TInt /*aError*/) |
|
499 { |
|
500 __DEBUGGER(); |
|
501 return KErrNone; |
|
502 } |
|
503 |
|
504 void CActiveHostResolver::SetLocalNameL() |
|
505 { |
|
506 iConsole.Printf(_L("Enter local device name (esc to finish)")); |
|
507 |
|
508 const TUint8 KMaxLength = 16; |
|
509 TBuf<KMaxLength> localName; |
|
510 localName.Zero(); |
|
511 FOREVER |
|
512 { |
|
513 TChar c = test.Getch(); |
|
514 if (c == EKeyEscape) |
|
515 break; |
|
516 else |
|
517 { |
|
518 TBuf<1> buf; |
|
519 buf.Append(c); |
|
520 iConsole.Printf(buf); |
|
521 localName.Append(c); |
|
522 } |
|
523 |
|
524 if(localName.Length() >= KMaxLength) |
|
525 // User entered too many characters... |
|
526 { |
|
527 // ...get them to start again |
|
528 iConsole.Printf(_L("\nToo many chars!\n")); |
|
529 iConsole.Printf(_L("(max %d chars) <ESC> to finish: "), KMaxLength); |
|
530 localName.Zero(); |
|
531 } |
|
532 } // END - FOREVER loop |
|
533 |
|
534 // If the name is OK, send it to the hardware... |
|
535 if (localName.Length()>0) |
|
536 { |
|
537 User::LeaveIfError(iHostResolver.SetHostName(localName)); |
|
538 } |
|
539 else |
|
540 { |
|
541 User::LeaveIfError(KErrGeneral); |
|
542 } |
|
543 } |
|
544 |
|
545 void CActiveHostResolver::SetIAC(TUint aIAC) |
|
546 { |
|
547 iInquiryRequest.SetIAC(aIAC); |
|
548 } |
|
549 |
|
550 |
|
551 void CActiveHostResolver::DoCancel() |
|
552 { |
|
553 iHROutputConsole->Printf(_L("Cancelled.\n")); |
|
554 iHostResolver.Cancel(); |
|
555 } |
|
556 |
|
557 void CActiveHostResolver::ConstructL() |
|
558 { |
|
559 #if USE_SMALL_CONSOLE |
|
560 iHROutputConsole = Console::NewL(_L("Host Resolver output"),gSmallConsole); |
|
561 #else |
|
562 iHROutputConsole = &iConsole; |
|
563 #endif |
|
564 |
|
565 StartServerL(); |
|
566 StartHostResolverL(); |
|
567 } |
|
568 |
|
569 // ---------------------------------------------------------------------------- |
|
570 // Active Inquirer |
|
571 // ---------------------------------------------------------------------------- |
|
572 |
|
573 CActiveInquirer::CActiveInquirer(CConsoleBase& aConsole, CEirApp& aApp, TBool aDoNames, TBool aIgnoreCache, TBool aDoEir, TBool forever) |
|
574 : CActiveHostResolver(aConsole, aApp), iDoNames(aDoNames), iIgnoreCache(aIgnoreCache), iDoEir(aDoEir), iForever(forever) |
|
575 { |
|
576 } |
|
577 |
|
578 CActiveInquirer* CActiveInquirer::NewL(CConsoleBase& aConsole, CEirApp& aApp, TUint aIAC, TBool aDoNames, TBool aIgnoreCache, TBool aDoEir, TBool forever) |
|
579 { |
|
580 CActiveInquirer* inquirer = new (ELeave) CActiveInquirer(aConsole, aApp, aDoNames, aIgnoreCache, aDoEir, forever); |
|
581 CleanupStack::PushL(inquirer); |
|
582 inquirer->ConstructL(aIAC); |
|
583 CleanupStack::Pop(inquirer); |
|
584 return inquirer; |
|
585 } |
|
586 |
|
587 void CActiveInquirer::ConstructL(TUint aIAC) |
|
588 { |
|
589 CActiveHostResolver::ConstructL(); |
|
590 |
|
591 // SetLocalNameL(); |
|
592 TUint action = KHostResInquiry; |
|
593 |
|
594 if (iDoNames) |
|
595 action |= KHostResName; |
|
596 |
|
597 if (iIgnoreCache) |
|
598 action |= KHostResIgnoreCache; |
|
599 |
|
600 if (iDoEir) |
|
601 action |= KHostResEir; |
|
602 |
|
603 iHROutputConsole->Printf(_L("Action: 0x%x\n"), action); |
|
604 iInquiryRequest.SetAction(action); |
|
605 iInquiryRequest.SetIAC(aIAC); |
|
606 |
|
607 Start(); |
|
608 } |
|
609 |
|
610 void CActiveInquirer::Start() |
|
611 /** |
|
612 Start an Inquiry |
|
613 **/ |
|
614 { |
|
615 TUint currentIAC; |
|
616 currentIAC = iInquiryRequest.IAC(); |
|
617 |
|
618 iHROutputConsole->Printf(_L("Inquiring [IAC 0x%06x]\n"), currentIAC); |
|
619 |
|
620 iHostResolver.GetByAddress(iInquiryRequest, iResult, iStatus); // async |
|
621 SetActive(); |
|
622 } |
|
623 |
|
624 void CActiveInquirer::RunL() |
|
625 { |
|
626 TReal passLoss = 0; |
|
627 TReal estimatedDistance = 0; |
|
628 if (iStatus.Int() == KErrNone) |
|
629 { |
|
630 TInquirySockAddr& sa = TInquirySockAddr::Cast(iResult().iAddr); |
|
631 const TBTDevAddr& bdaddr = sa.BTAddr(); |
|
632 |
|
633 iApp.DeviceFound(bdaddr); // notify app |
|
634 |
|
635 TBTDevAddrBuf bdaddrbuf; |
|
636 bdaddr.GetReadable(bdaddrbuf); |
|
637 |
|
638 iHROutputConsole->Printf(_L("Result: BdAddr = 0x%S"),&bdaddrbuf); |
|
639 |
|
640 if(sa.ResultFlags() & TInquirySockAddr::ERssiValid) |
|
641 { |
|
642 iHROutputConsole->Printf(_L(" RSSI: %d ["), sa.Rssi()); |
|
643 // store the rssi value in here |
|
644 passLoss = sa.Rssi(); |
|
645 #define KRssiBarNum 8 |
|
646 #define KRssiRange (127 + 20 + 1) |
|
647 TUint rssiBars = ((((TInt) sa.Rssi()) + 127 + 1) * KRssiBarNum) / KRssiRange; |
|
648 TUint i; |
|
649 |
|
650 for(i=1; i <= KRssiBarNum ; i++) |
|
651 { |
|
652 if(rssiBars >= i) |
|
653 { |
|
654 iHROutputConsole->Printf(_L("*")); |
|
655 } |
|
656 else |
|
657 { |
|
658 iHROutputConsole->Printf(_L(" ")); |
|
659 } |
|
660 } |
|
661 iHROutputConsole->Printf(_L("]\n")); |
|
662 } |
|
663 else |
|
664 { |
|
665 iHROutputConsole->Printf(_L("\n")); |
|
666 } |
|
667 |
|
668 if(iDoEir) |
|
669 { |
|
670 TBluetoothNameRecordWrapper eir(iResult()); |
|
671 //iHROutputConsole->Printf(_L("EIR Length: %d\n"), eir.Length()); |
|
672 TBool isNameComplete; |
|
673 TInt error = KErrNone; |
|
674 TInt length = 0; |
|
675 |
|
676 |
|
677 // Go and get name |
|
678 // This length could be used to create the TBuf to be passed into GetDeviceName() |
|
679 length = eir.GetDeviceNameLength(); |
|
680 TBuf<255> name; |
|
681 if(length >= 0) |
|
682 { |
|
683 // name will contain a Unicode encoded 16-bit string |
|
684 error = eir.GetDeviceName(name, isNameComplete); |
|
685 } |
|
686 else |
|
687 { |
|
688 error = length; |
|
689 } |
|
690 if(error == KErrNone) |
|
691 // Now we have name here |
|
692 { |
|
693 if(isNameComplete == EFalse) |
|
694 { |
|
695 iHROutputConsole->Printf(_L("%d Bytes [Partial] Name: "), length); |
|
696 } |
|
697 else |
|
698 { |
|
699 iHROutputConsole->Printf(_L("%d Bytes [Complete] Name: "), length); |
|
700 } |
|
701 iHROutputConsole->Printf(_L("%S \n"),&name); |
|
702 } |
|
703 |
|
704 // Get TxPowerLevel |
|
705 TInt8 txPowerLevel; |
|
706 error = eir.GetTxPowerLevel(txPowerLevel); |
|
707 if(error == KErrNone) |
|
708 // TxPowerLevel present |
|
709 { |
|
710 iHROutputConsole->Printf(_L("TxPowerLevel: %ddBm\n"), txPowerLevel); |
|
711 // NICE one, we can calculate the pass loss here then :) |
|
712 if(passLoss != 0) |
|
713 { |
|
714 passLoss = txPowerLevel - passLoss; |
|
715 iHROutputConsole->Printf(_L("Pass Loss: %fdBm\n"), passLoss); |
|
716 // Here comes the magic equation: |
|
717 TReal power = (passLoss / 20.0) - 2.00221; |
|
718 TReal src = 10.0; |
|
719 Math::Pow(estimatedDistance, src, power); |
|
720 iHROutputConsole->Printf(_L("Estimated distance: %fm\n"), estimatedDistance); |
|
721 } |
|
722 } |
|
723 // Get UUIDs |
|
724 RExtendedInquiryResponseUUIDContainer uuidContainer; |
|
725 error = eir.GetServiceClassUuids(uuidContainer); |
|
726 if(error >= KErrNone) |
|
727 { |
|
728 RArray<TUUID> uuids; |
|
729 TInt uuidCount = uuidContainer.UUIDs().Count(); |
|
730 if(uuidCount > 0) |
|
731 { |
|
732 iHROutputConsole->Printf(_L("*** UUID Count: %d\n"), uuidCount); |
|
733 TInt i; |
|
734 for(i=0;i<uuidCount;i++) |
|
735 { |
|
736 //iHROutputConsole->Printf(_L("*** UUID #%d minsz: %d value: 0x"), i, uuidContainer.UUIDs()[i].MinimumSize()); |
|
737 TInt j; |
|
738 TPtrC8 uuid(uuidContainer.UUIDs()[i].ShortestForm()); |
|
739 // Treat it as a big endian |
|
740 for(j=0;j<uuid.Length();j++) |
|
741 { |
|
742 iHROutputConsole->Printf(_L("%02X"), uuid[j]); |
|
743 } |
|
744 |
|
745 iHROutputConsole->Printf(_L(" \n")); |
|
746 } |
|
747 } |
|
748 } |
|
749 |
|
750 // Get Manufacturer Specific Data |
|
751 length = eir.GetVendorSpecificDataLength(); |
|
752 TBuf8<255> msd; |
|
753 if(length > 0) |
|
754 { |
|
755 error = eir.GetVendorSpecificData(msd); |
|
756 } |
|
757 else |
|
758 { |
|
759 error = length; |
|
760 } |
|
761 if(error == KErrNone) |
|
762 // we have Manufacturer Specific Data here |
|
763 { |
|
764 // This conversion is for display reason, in a real world this may not be necessary as |
|
765 // Manufacturer specific data can be just raw 8-bit data, however GetDeviceName() is |
|
766 // different as it always return Unicode encoded 16-bit string |
|
767 error = CnvUtfConverter::ConvertToUnicodeFromUtf8(name, msd); |
|
768 if(error >= KErrNone && length > 0) |
|
769 { |
|
770 iHROutputConsole->Printf(_L("%d Bytes Manufacturer Specific Data: %S\n"), length, &name); |
|
771 } |
|
772 } |
|
773 } |
|
774 |
|
775 if (iDoNames) |
|
776 { |
|
777 if(!iDoEir) |
|
778 { |
|
779 TBuf<255> namebuf; |
|
780 namebuf.Copy(iResult().iName); |
|
781 iHROutputConsole->Printf(_L("Remote name \"%S\""), &namebuf); |
|
782 if(iResult().iFlags & TNameRecord::EPartial) |
|
783 { |
|
784 iHROutputConsole->Printf(_L(" [PARTIAL]\n")); |
|
785 } |
|
786 else |
|
787 { |
|
788 iHROutputConsole->Printf(_L(" [COMPLETE]\n")); |
|
789 } |
|
790 } |
|
791 else |
|
792 { |
|
793 TBluetoothNameRecordWrapper eir(iResult()); |
|
794 TInt length = eir.GetDeviceNameLength(); |
|
795 TInt error = KErrNone; |
|
796 TBuf<255> name; |
|
797 TBool isNameComplete; |
|
798 |
|
799 if(length >= 0) |
|
800 { |
|
801 // name will contain a Unicode encoded 16-bit string |
|
802 error = eir.GetDeviceName(name, isNameComplete); |
|
803 } |
|
804 else |
|
805 { |
|
806 error = length; |
|
807 } |
|
808 if(error == KErrNone) |
|
809 // Now we have name here |
|
810 { |
|
811 if(isNameComplete == EFalse) |
|
812 { |
|
813 iHROutputConsole->Printf(_L("%d Bytes [Partial] Name (via EIR wrapper): "), length); |
|
814 } |
|
815 else |
|
816 { |
|
817 iHROutputConsole->Printf(_L("%d Bytes [Complete] Name (via EIR wrapper): "), length); |
|
818 } |
|
819 iHROutputConsole->Printf(_L("%S \n"),&name); |
|
820 } |
|
821 } |
|
822 } |
|
823 |
|
824 iHostResolver.Next(iResult, iStatus); // asynch |
|
825 SetActive(); |
|
826 } |
|
827 else if (iStatus.Int() == KErrEof) |
|
828 { |
|
829 iHROutputConsole->Printf(_L("Finished inquiry.\n")); |
|
830 |
|
831 if(iForever) |
|
832 { |
|
833 iHROutputConsole->Printf(_L("Restarting inquiry.\n")); |
|
834 Start(); |
|
835 } |
|
836 else |
|
837 { |
|
838 iApp.InquiryComplete(); |
|
839 } |
|
840 } |
|
841 else |
|
842 { |
|
843 iHROutputConsole->Printf(_L("Inquiry request failed with result %d.\n"), iStatus.Int()); |
|
844 } |
|
845 } |
|
846 |
|
847 |
|
848 // ---------------------------------------------------------------------------- |
|
849 // Active Name Requester |
|
850 // ---------------------------------------------------------------------------- |
|
851 |
|
852 void CActiveNameRequester::ConstructL() |
|
853 { |
|
854 CActiveHostResolver::ConstructL(); |
|
855 |
|
856 TUint action = iEirInstead ? KHostResEir : KHostResName; |
|
857 if (iIgnoreCache) |
|
858 action |= KHostResIgnoreCache; |
|
859 iInquiryRequest.SetAction(action); |
|
860 Start(); |
|
861 } |
|
862 |
|
863 CActiveNameRequester::CActiveNameRequester(CConsoleBase& aConsole, CEirApp& aApp, TBool aEirInstead, TBool aIgnoreCache) |
|
864 : CActiveHostResolver(aConsole, aApp), iEirInstead(aEirInstead), iIgnoreCache(aIgnoreCache) |
|
865 { |
|
866 } |
|
867 |
|
868 CActiveNameRequester* CActiveNameRequester::NewL(CConsoleBase& aConsole, CEirApp& aApp, TBool aEirInstead, TBool aIgnoreCache) |
|
869 { |
|
870 CActiveNameRequester* namerequester = new (ELeave) CActiveNameRequester(aConsole, aApp, aEirInstead, aIgnoreCache); |
|
871 CleanupStack::PushL(namerequester); |
|
872 namerequester->ConstructL(); |
|
873 CleanupStack::Pop(); |
|
874 return namerequester; |
|
875 } |
|
876 |
|
877 |
|
878 void CActiveNameRequester::Start() |
|
879 /** |
|
880 Get just the name |
|
881 **/ |
|
882 { |
|
883 iInquiryRequest.SetBTAddr(gDevAddr); // this object does the global addr for the moment |
|
884 |
|
885 TBTDevAddrBuf bdaddrbuf; |
|
886 gDevAddr.GetReadable(bdaddrbuf); |
|
887 |
|
888 iHROutputConsole->Printf(_L("Looking up address %S...\r\n"),&bdaddrbuf); |
|
889 |
|
890 iHostResolver.GetByAddress(iInquiryRequest, iResult, iStatus); // async |
|
891 SetActive(); |
|
892 } |
|
893 |
|
894 |
|
895 void CActiveNameRequester::PrintResults() |
|
896 { |
|
897 TInquirySockAddr& sa = TInquirySockAddr::Cast(iResult().iAddr); |
|
898 const TBTDevAddr& bdaddr = sa.BTAddr(); |
|
899 |
|
900 TBTDevAddrBuf bdaddrbuf; |
|
901 bdaddr.GetReadable(bdaddrbuf); |
|
902 |
|
903 iHROutputConsole->Printf(_L("Result: BdAddr = 0x%S"),&bdaddrbuf); |
|
904 |
|
905 if(sa.ResultFlags() & TInquirySockAddr::ERssiValid) |
|
906 { |
|
907 iHROutputConsole->Printf(_L(" RSSI: %d"), sa.Rssi()); |
|
908 } |
|
909 |
|
910 iHROutputConsole->Printf(_L("\n")); |
|
911 |
|
912 TBuf<255> buf; |
|
913 TBuf8<255> buf8; |
|
914 TBool isNameComplete = EFalse; |
|
915 TInt error = KErrNone; |
|
916 |
|
917 if(iEirInstead) |
|
918 { |
|
919 TBluetoothNameRecordWrapper eir(iResult()); |
|
920 |
|
921 iHROutputConsole->Printf(_L("*** EIR START ***\n")); |
|
922 |
|
923 error = eir.GetDeviceName(buf, isNameComplete); |
|
924 if(error == KErrNone) |
|
925 { |
|
926 if(isNameComplete == EFalse) |
|
927 { |
|
928 iHROutputConsole->Printf(_L("Partial Name: %S"), &buf); |
|
929 } |
|
930 else |
|
931 { |
|
932 iHROutputConsole->Printf(_L("Partial Name: %S"), &buf); |
|
933 } |
|
934 } |
|
935 |
|
936 if(eir.GetVendorSpecificDataLength() > 0) |
|
937 { |
|
938 eir.GetVendorSpecificData(buf8); |
|
939 if(buf.Size() > 0) |
|
940 { |
|
941 iHROutputConsole->Printf(_L("Manufacturer Specific Data: %S"), &buf8); |
|
942 } |
|
943 } |
|
944 |
|
945 TInt8 txPowerLevel; |
|
946 TInt err = txPowerLevel = eir.GetTxPowerLevel(txPowerLevel); |
|
947 if(err == KErrNone) |
|
948 { |
|
949 iHROutputConsole->Printf(_L("Tx Power Level: %d"), &txPowerLevel); |
|
950 } |
|
951 |
|
952 iHROutputConsole->Printf(_L("*** EIR END ***\n")); |
|
953 // Test EIR methods |
|
954 RArray<TUUID> uuids; |
|
955 |
|
956 TInt error = eir.GetDeviceName(buf, isNameComplete); |
|
957 iHROutputConsole->Printf(_L("*** GetLocalName returned: %d\n"), error); |
|
958 if(error >= KErrNone) |
|
959 { |
|
960 iHROutputConsole->Printf(_L("*** Retrieved Local Name: %S\n"),&buf); |
|
961 } |
|
962 |
|
963 RExtendedInquiryResponseUUIDContainer uuidContainer; |
|
964 error = eir.GetServiceClassUuids(uuidContainer); |
|
965 iHROutputConsole->Printf(_L("*** GetUUIDs returned: %d\n"), error); |
|
966 if(error >= KErrNone) |
|
967 { |
|
968 iHROutputConsole->Printf(_L("*** UUID Count: %d\n"), uuids.Count()); |
|
969 TInt i; |
|
970 for(i=0;i<uuids.Count();i++) |
|
971 { |
|
972 iHROutputConsole->Printf(_L("*** UUID #%d minsz: %d value: 0x"), i, uuids[i].MinimumSize()); |
|
973 TInt j; |
|
974 TPtrC8 uuid(uuids[i].ShortestForm()); |
|
975 for(j=0;j<uuid.Length();j++) |
|
976 { |
|
977 iHROutputConsole->Printf(_L("%02X"), uuid[j]); |
|
978 } |
|
979 |
|
980 iHROutputConsole->Printf(_L(" \n")); |
|
981 } |
|
982 } |
|
983 |
|
984 } |
|
985 else |
|
986 { |
|
987 if (iResult().iName != KNullDesC) |
|
988 buf.Copy(iResult().iName); |
|
989 else |
|
990 buf = _L("NOT AVAILABLE"); |
|
991 |
|
992 iHROutputConsole->Printf(_L("Result: Remote Name = \"%S\""),&buf); |
|
993 if(iResult().iFlags & TNameRecord::EPartial) |
|
994 { |
|
995 iHROutputConsole->Printf(_L(" [PARTIAL]\n")); |
|
996 } |
|
997 else |
|
998 { |
|
999 iHROutputConsole->Printf(_L(" [COMPLETE]\n")); |
|
1000 } |
|
1001 |
|
1002 } |
|
1003 |
|
1004 TInt majorCoD = sa.MajorClassOfDevice(); |
|
1005 if (majorCoD & (1 << 13)) |
|
1006 iHROutputConsole->Printf(_L("Device is Limited Discoverable\n")); |
|
1007 } |
|
1008 |
|
1009 void CActiveNameRequester::RunL() |
|
1010 { |
|
1011 if (iStatus.Int() == KErrNone) |
|
1012 { |
|
1013 PrintResults(); |
|
1014 } |
|
1015 else |
|
1016 { |
|
1017 iHROutputConsole->Printf(_L("GetByAddress failed with code %d\r\n"), iStatus.Int()); |
|
1018 } |
|
1019 } |
|
1020 |
|
1021 // ---------------------------------------------------------------------------- |
|
1022 // Active Name Array Requester |
|
1023 // ---------------------------------------------------------------------------- |
|
1024 |
|
1025 |
|
1026 CActiveNameArrayRequester* CActiveNameArrayRequester::NewL(CConsoleBase& aConsole, CEirApp& aApp, RArray<TBTDevAddr>& aNameArray) |
|
1027 { |
|
1028 CActiveNameArrayRequester* namesreq = new (ELeave) CActiveNameArrayRequester(aConsole, aApp, aNameArray); |
|
1029 CleanupStack::PushL(namesreq); |
|
1030 namesreq->ConstructL(); |
|
1031 CleanupStack::Pop(); |
|
1032 return namesreq; |
|
1033 } |
|
1034 |
|
1035 CActiveNameArrayRequester::CActiveNameArrayRequester(CConsoleBase& aConsole, CEirApp& aApp, RArray<TBTDevAddr>& aNameArray) |
|
1036 : CActiveNameRequester(aConsole, aApp, EFalse, EFalse), iNameArray(aNameArray) |
|
1037 { |
|
1038 } |
|
1039 |
|
1040 void CActiveNameArrayRequester::RunL() |
|
1041 { |
|
1042 if (iStatus.Int() == KErrNone || iStatus.Int() == KHCIErrorBase-EPageTimedOut) |
|
1043 { |
|
1044 PrintResults(); |
|
1045 // do next one if present |
|
1046 if (iCurrentNameIndex < iNameArray.Count()-1) |
|
1047 { |
|
1048 ++iCurrentNameIndex; |
|
1049 DoSingleNameRequest(); |
|
1050 } |
|
1051 } |
|
1052 else |
|
1053 { |
|
1054 iHROutputConsole->Printf(_L("GetByAddress failed with code %d\n"), iStatus.Int()); |
|
1055 } |
|
1056 } |
|
1057 |
|
1058 void CActiveNameArrayRequester::ConstructL() |
|
1059 { |
|
1060 CActiveHostResolver::ConstructL(); |
|
1061 |
|
1062 iInquiryRequest.SetAction(KHostResName); // NAME ONLY |
|
1063 iCurrentNameIndex = 0; |
|
1064 Start(); |
|
1065 } |
|
1066 |
|
1067 void CActiveNameArrayRequester::DoSingleNameRequest() |
|
1068 // FIXME make a member of NameRequester and sort out address ownsership |
|
1069 { |
|
1070 TBTDevAddr& currentAddr = iNameArray[iCurrentNameIndex]; |
|
1071 iInquiryRequest.SetBTAddr(currentAddr); // this object does the global addr for the moment |
|
1072 |
|
1073 TBTDevAddrBuf bdaddrbuf; |
|
1074 currentAddr.GetReadable(bdaddrbuf); |
|
1075 |
|
1076 iHROutputConsole->Printf(_L("Looking up address %S...\n"),&bdaddrbuf); |
|
1077 |
|
1078 iHostResolver.GetByAddress(iInquiryRequest, iResult, iStatus); // async |
|
1079 SetActive(); |
|
1080 } |
|
1081 |
|
1082 void CActiveNameArrayRequester::PrintResults() |
|
1083 { |
|
1084 TInquirySockAddr& sa = TInquirySockAddr::Cast(iResult().iAddr); |
|
1085 const TBTDevAddr& bdaddr = sa.BTAddr(); |
|
1086 |
|
1087 TBTDevAddrBuf bdaddrbuf; |
|
1088 bdaddr.GetReadable(bdaddrbuf); |
|
1089 |
|
1090 TBuf<255> buf; |
|
1091 |
|
1092 if (iResult().iName != KNullDesC) |
|
1093 buf.Copy(iResult().iName); |
|
1094 else |
|
1095 buf = _L("NOT AVAILABLE"); |
|
1096 |
|
1097 iHROutputConsole->Printf(_L("Result [HostResolver 0x%08x, Bdaddr %S]: Name: %S \n"), |
|
1098 &iHostResolver, &bdaddrbuf, &buf); |
|
1099 |
|
1100 } |
|
1101 |
|
1102 void CActiveNameArrayRequester::Start() |
|
1103 { |
|
1104 DoSingleNameRequest(); |
|
1105 } |
|
1106 |
|
1107 // ---------------------------------------------------------------------------- |
|
1108 // Active Console |
|
1109 // ---------------------------------------------------------------------------- |
|
1110 |
|
1111 |
|
1112 CActiveConsole::CActiveConsole(CConsoleBase& aConsole, CEirApp& aApp) |
|
1113 : CActive(EPriorityStandard), iConsole(aConsole), iApp(aApp) |
|
1114 { |
|
1115 } |
|
1116 |
|
1117 |
|
1118 CActiveConsole::~CActiveConsole() |
|
1119 { |
|
1120 // must cancel |
|
1121 Cancel(); |
|
1122 } |
|
1123 |
|
1124 CActiveConsole* CActiveConsole::NewL(CConsoleBase& aConsole, CEirApp& aApp) |
|
1125 { |
|
1126 CActiveConsole* console = new (ELeave) CActiveConsole(aConsole, aApp); |
|
1127 CleanupStack::PushL(console); |
|
1128 console->ConstructL(); |
|
1129 CleanupStack::Pop(); |
|
1130 return console; |
|
1131 } |
|
1132 |
|
1133 void CActiveConsole::ConstructL() |
|
1134 { |
|
1135 CActiveScheduler::Add(this); |
|
1136 TestMenu(); |
|
1137 RequestKey(); |
|
1138 } |
|
1139 |
|
1140 void CActiveConsole::DoCancel() |
|
1141 { |
|
1142 iConsole.ReadCancel(); |
|
1143 } |
|
1144 |
|
1145 void CActiveConsole::RequestKey() |
|
1146 { |
|
1147 DrawCursor(); |
|
1148 iConsole.Read(iStatus); |
|
1149 SetActive(); |
|
1150 } |
|
1151 |
|
1152 void CActiveConsole::DrawCursor() |
|
1153 { |
|
1154 iConsole.Printf(KNullDesC()); |
|
1155 } |
|
1156 |
|
1157 void CActiveConsole::TestMenu() |
|
1158 { |
|
1159 iConsole.Printf(_L("Choose action...\n\n")); |
|
1160 iConsole.Printf(_L("n.\t\tSingle Name Request\n")); |
|
1161 iConsole.Printf(_L("N.\t\tSingle Name Request; ignore Cache\n")); |
|
1162 |
|
1163 iConsole.Printf(_L("e.\t\tSingle EIR Request\n")); |
|
1164 iConsole.Printf(_L("E.\t\tSingle EIR Request; ignore Cache\n")); |
|
1165 |
|
1166 iConsole.Printf(_L("i.\t\tGeneral Inquiry no Names\n")); |
|
1167 iConsole.Printf(_L("I.\t\tGeneral Inquiry no Names; ignore Cache\n")); |
|
1168 |
|
1169 iConsole.Printf(_L("w.\t\tGeneral Inquiry with Names\n")); |
|
1170 iConsole.Printf(_L("W.\t\tGeneral Inquiry with Names; ignore Cache\n")); |
|
1171 |
|
1172 iConsole.Printf(_L("x.\t\tGeneral Inquiry with EIR\n")); |
|
1173 iConsole.Printf(_L("X.\t\tGeneral Inquiry with EIR; ignore Cache\n")); |
|
1174 |
|
1175 iConsole.Printf(_L("c.\t\tCancel Inquiry\n")); |
|
1176 |
|
1177 iConsole.Printf(_L("f.\t\tForever: general Inquiry with EIR; ignore Cache\n")); |
|
1178 |
|
1179 iConsole.Printf(_L("------------------------------------\n")); |
|
1180 |
|
1181 iConsole.Printf(_L("1.\t\tAdd EIR Publisher: Local Name\n")); |
|
1182 iConsole.Printf(_L("2.\t\tAdd new EIR Publisher: UUID 16\n")); |
|
1183 iConsole.Printf(_L("3.\t\tAdd new EIR Publisher: UUID 128\n")); |
|
1184 iConsole.Printf(_L("4.\t\tAdd EIR Publisher: Manufacturer Specific\n")); |
|
1185 |
|
1186 iConsole.Printf(_L("Esc.\tStop\n")); |
|
1187 } |
|
1188 |
|
1189 void CActiveConsole::RunL() |
|
1190 { |
|
1191 // key has been pressed |
|
1192 TChar ch = iConsole.KeyCode(); |
|
1193 TBool requestNextKey = ProcessKey(ch); |
|
1194 if ( requestNextKey ) |
|
1195 { |
|
1196 RequestKey(); |
|
1197 } |
|
1198 } |
|
1199 |
|
1200 TBool CActiveConsole::ProcessKey(TChar aCh) |
|
1201 { |
|
1202 TBool requestNextKey = ETrue; |
|
1203 TInt err; |
|
1204 switch (aCh) |
|
1205 { |
|
1206 case 'n': |
|
1207 iConsole.Printf(_L("Starting name request...\n")); |
|
1208 TRAP(err, iApp.NewNameRequesterL(EFalse, EFalse)); |
|
1209 if(err!=KErrNone) |
|
1210 iConsole.Printf(_L("name request failed - %d"), err); |
|
1211 break; |
|
1212 |
|
1213 case 'N': |
|
1214 iConsole.Printf(_L("Starting name request (ignoring cache)...\n")); |
|
1215 TRAP(err, iApp.NewNameRequesterL(EFalse, ETrue)); |
|
1216 if(err!=KErrNone) |
|
1217 iConsole.Printf(_L("name request (ignoring cache) failed - %d"), err); |
|
1218 break; |
|
1219 |
|
1220 case 'e': |
|
1221 iConsole.Printf(_L("Starting EIR request...\n")); |
|
1222 TRAP(err, iApp.NewNameRequesterL(ETrue, EFalse)); |
|
1223 if(err!=KErrNone) |
|
1224 iConsole.Printf(_L("EIR request failed - %d"), err); |
|
1225 break; |
|
1226 |
|
1227 case 'E': |
|
1228 iConsole.Printf(_L("Starting EIR request (ignoring cache)...\n")); |
|
1229 TRAP(err, iApp.NewNameRequesterL(ETrue, ETrue)); |
|
1230 if(err!=KErrNone) |
|
1231 iConsole.Printf(_L("EIR request (ignoring cache) failed - %d"), err); |
|
1232 break; |
|
1233 |
|
1234 case 'i': |
|
1235 iConsole.Printf(_L("Starting General Inquiry no names...\n")); |
|
1236 TRAP(err, iApp.NewInquirerL(KGIAC, EFalse, EFalse, EFalse)); |
|
1237 if(err!=KErrNone) |
|
1238 iConsole.Printf(_L("General Inquiry failed - %d"), err); |
|
1239 break; |
|
1240 |
|
1241 case 'I': |
|
1242 iConsole.Printf(_L("Starting General Inquiry, no names, ignoring cache...\n")); |
|
1243 TRAP(err, iApp.NewInquirerL(KGIAC, EFalse, ETrue, EFalse)); |
|
1244 if(err!=KErrNone) |
|
1245 iConsole.Printf(_L("General Inquiry, no names, ignoring cache failed - %d"), err); |
|
1246 break; |
|
1247 |
|
1248 |
|
1249 case 'w': |
|
1250 iConsole.Printf(_L("Starting General Inquiry with Names...\n")); |
|
1251 TRAP(err, iApp.NewInquirerL(KGIAC, ETrue, EFalse, EFalse)); |
|
1252 if(err!=KErrNone) |
|
1253 iConsole.Printf(_L("General Inquiry with Names failed - %d"), err); |
|
1254 break; |
|
1255 |
|
1256 case 'W': |
|
1257 iConsole.Printf(_L("Starting General Inquiry with names and no cache...\n")); |
|
1258 TRAP(err, iApp.NewInquirerL(KGIAC, ETrue, ETrue, EFalse)); |
|
1259 if(err!=KErrNone) |
|
1260 iConsole.Printf(_L("General Inquiry with names, ignoring cache failed - %d"), err); |
|
1261 break; |
|
1262 |
|
1263 case 'x': |
|
1264 iConsole.Printf(_L("Starting General Inquiry With EIR...\n")); |
|
1265 TRAP(err, iApp.NewInquirerL(KGIAC, EFalse, EFalse, ETrue)); |
|
1266 if(err!=KErrNone) |
|
1267 iConsole.Printf(_L("General Inquiry with EIR failed - %d"), err); |
|
1268 break; |
|
1269 |
|
1270 case 'X': |
|
1271 iConsole.Printf(_L("Starting General Inquiry With EIR, ignoring cache...\n")); |
|
1272 TRAP(err, iApp.NewInquirerL(KGIAC, EFalse, ETrue, ETrue)); |
|
1273 if(err!=KErrNone) |
|
1274 iConsole.Printf(_L("General Inquiry with EIR, ignoring cache failed - %d"), err); |
|
1275 break; |
|
1276 |
|
1277 case 'a': |
|
1278 iConsole.Printf(_L("Starting General Inquiry With both Name request and EIR...\n")); |
|
1279 TRAP(err, iApp.NewInquirerL(KGIAC, ETrue, EFalse, ETrue)); |
|
1280 if(err!=KErrNone) |
|
1281 iConsole.Printf(_L("General Inquiry with EIR failed - %d"), err); |
|
1282 break; |
|
1283 |
|
1284 case 'A': |
|
1285 iConsole.Printf(_L("Starting General Inquiry With both Name request and EIR, ignoring cache...\n")); |
|
1286 TRAP(err, iApp.NewInquirerL(KGIAC, ETrue, ETrue, ETrue)); |
|
1287 if(err!=KErrNone) |
|
1288 iConsole.Printf(_L("General Inquiry with EIR, ignoring cache failed - %d"), err); |
|
1289 break; |
|
1290 |
|
1291 case 'c': |
|
1292 // fixme - would be nice to enumerate the one to cancel |
|
1293 // and see what happens to the others... |
|
1294 iConsole.Printf(_L("Cancelling inquiry...\n")); |
|
1295 iApp.CancelInquirer(); |
|
1296 break; |
|
1297 |
|
1298 case 'f': |
|
1299 iConsole.Printf(_L("Neverending inquiry...\n")); |
|
1300 TRAP(err, iApp.NewInquirerL(KGIAC, EFalse, ETrue, ETrue, ETrue)); |
|
1301 break; |
|
1302 |
|
1303 case '1': |
|
1304 /* iConsole.Printf(_L("Change Local Name...\n")); |
|
1305 TRAP(err, iApp.NewEirPublisherTestL(ETestDeviceName)); |
|
1306 if(err!=KErrNone) |
|
1307 iConsole.Printf(_L("failed - %d"), err); |
|
1308 */ |
|
1309 iConsole.Printf(_L("to be supported in teir")); |
|
1310 break; |
|
1311 |
|
1312 case '2': |
|
1313 iConsole.Printf(_L("Creating an EIR UUID16 publisher...\n")); |
|
1314 TRAP(err, iApp.NewEirPublisherTestL(ETestUuid16)); |
|
1315 if(err!=KErrNone) |
|
1316 iConsole.Printf(_L("failed - %d"), err); |
|
1317 break; |
|
1318 |
|
1319 case '3': |
|
1320 iConsole.Printf(_L("Creating an EIR UUID128 publisher...\n")); |
|
1321 TRAP(err, iApp.NewEirPublisherTestL(ETestUuid128)); |
|
1322 if(err!=KErrNone) |
|
1323 iConsole.Printf(_L("failed - %d"), err); |
|
1324 break; |
|
1325 |
|
1326 case '4': |
|
1327 iConsole.Printf(_L("Creating an EIR Manufacturer Specific publisher...\n")); |
|
1328 TRAP(err, iApp.NewEirPublisherTestL(ETestSetMSD)); |
|
1329 if(err!=KErrNone) |
|
1330 iConsole.Printf(_L("failed - %d"), err); |
|
1331 break; |
|
1332 |
|
1333 case '?': |
|
1334 TestMenu(); |
|
1335 break; |
|
1336 |
|
1337 case EKeyEscape: |
|
1338 iApp.Stop(); // don't want another key press |
|
1339 requestNextKey = EFalse; |
|
1340 break; |
|
1341 |
|
1342 default: |
|
1343 iConsole.Printf(_L("Unknown command\r\n")); |
|
1344 } |
|
1345 |
|
1346 return requestNextKey; |
|
1347 } |
|
1348 |
|
1349 TInt CActiveConsole::SetHostName() |
|
1350 { |
|
1351 test.Printf(_L("Set Host Name to: ")); |
|
1352 TKeyCode key; |
|
1353 TBuf16<255> buf; |
|
1354 |
|
1355 while((key = test.Getch())!=EKeyEnter && buf.Length()<buf.MaxLength()) |
|
1356 { |
|
1357 if(key == EKeyBackspace&&buf.Length()!=0) |
|
1358 { |
|
1359 buf.SetLength(buf.Length()-1); |
|
1360 } |
|
1361 else |
|
1362 { |
|
1363 buf.Append(key); |
|
1364 } |
|
1365 |
|
1366 test.Printf(_L("%c"), key); |
|
1367 } |
|
1368 |
|
1369 // iHostResolver.SetHostName(buf); |
|
1370 test.Printf(_L("\n")); |
|
1371 return KErrNone; |
|
1372 } |
|
1373 |
|
1374 CManufacturerDataNotifier* CManufacturerDataNotifier::NewL(CEirApp& aEirApp) |
|
1375 { |
|
1376 CManufacturerDataNotifier* self = new (ELeave) CManufacturerDataNotifier(aEirApp); |
|
1377 CleanupStack::PushL(self); |
|
1378 self->ConstructL(); |
|
1379 CleanupStack::Pop(); |
|
1380 return self; |
|
1381 } |
|
1382 |
|
1383 CManufacturerDataNotifier::CManufacturerDataNotifier(CEirApp& aEirApp) |
|
1384 : iEirApp(aEirApp) |
|
1385 { |
|
1386 } |
|
1387 |
|
1388 CManufacturerDataNotifier::~CManufacturerDataNotifier() |
|
1389 { |
|
1390 } |
|
1391 |
|
1392 void CManufacturerDataNotifier::ConstructL() |
|
1393 { |
|
1394 } |
|
1395 |
|
1396 // From MManufacturerSpecificDataPublisherNotifier |
|
1397 void CManufacturerDataNotifier::MmsdpnNotifyAvailableDataSize(TUint aAvailableDataSize) |
|
1398 { |
|
1399 iEirApp.SetPublishManuData(aAvailableDataSize); |
|
1400 } |
|
1401 |
|
1402 void CManufacturerDataNotifier::MmsdpnNotifyError(TInt /*aResult*/) |
|
1403 { |
|
1404 // Check aResult == KErrNone |
|
1405 } |
|
1406 |
|
1407 |
|
1408 void StartL() |
|
1409 { |
|
1410 CEirApp* app = CEirApp::NewL(*test.Console()); |
|
1411 CleanupStack::PushL(app); |
|
1412 app->StartL(); |
|
1413 CleanupStack::PopAndDestroy(app); |
|
1414 } |
|
1415 |
|
1416 TInt E32Main() |
|
1417 { |
|
1418 TInt ret; |
|
1419 test.SetLogged(EFalse); |
|
1420 test.Title(); |
|
1421 |
|
1422 // For some reason, you have to do the following to |
|
1423 // ensure that the file server behaves properly. |
|
1424 RFs fs; |
|
1425 ret=fs.Connect(); |
|
1426 fs.Close(); |
|
1427 // Run through tests |
|
1428 |
|
1429 __UHEAP_MARK; |
|
1430 CTrapCleanup* cleanupStack=CTrapCleanup::New(); // Get CleanupStack |
|
1431 |
|
1432 CActiveScheduler* activescheduler=new CActiveScheduler; |
|
1433 CActiveScheduler::Install(activescheduler); |
|
1434 |
|
1435 TRAPD(err, StartL()); |
|
1436 |
|
1437 delete activescheduler; |
|
1438 delete cleanupStack; |
|
1439 __UHEAP_MARKEND; |
|
1440 |
|
1441 return err; |
|
1442 } |