|
1 // Copyright (c) 2000-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 // |
|
15 |
|
16 #include "BTTextNotifiers.h" |
|
17 #include <btdevice.h> |
|
18 #include <e32cons.h> |
|
19 #include <es_prot.h> |
|
20 #include <bluetooth/logger.h> |
|
21 #include "pannapuplinkauthorisationnotifier.h" |
|
22 |
|
23 #ifdef __FLOG_ACTIVE |
|
24 _LIT8(KLogComponent, "TextNotifiers"); |
|
25 #endif |
|
26 |
|
27 |
|
28 void CreateNotifiersL(CArrayPtrFlat<MNotifierBase2>& aNotifiers) |
|
29 { |
|
30 LOG_STATIC_FUNC |
|
31 // Utility macro to make this function simpler. |
|
32 #define ADD_BT_NOTIFIER(XType) \ |
|
33 {\ |
|
34 XType* notifier = XType::NewLC(); \ |
|
35 aNotifiers.AppendL(notifier); \ |
|
36 CleanupStack::Pop(notifier); \ |
|
37 } |
|
38 |
|
39 ADD_BT_NOTIFIER(CBTManPinNotifier); |
|
40 ADD_BT_NOTIFIER(CBTManAuthNotifier); |
|
41 ADD_BT_NOTIFIER(CBTManDeviceSelectionNotifier); |
|
42 ADD_BT_NOTIFIER(CBTPanDeviceSelectionNotifier); |
|
43 ADD_BT_NOTIFIER(CPbapAuthNotifier); |
|
44 ADD_BT_NOTIFIER(CPanNapUplinkAuthorisationNotifier); |
|
45 |
|
46 #ifndef __BT_TEXT_NOTIFIERS_NO_SSP__ |
|
47 ADD_BT_NOTIFIER(CBTUINumericComparison); |
|
48 ADD_BT_NOTIFIER(CBTUIPasskeyEntry); |
|
49 ADD_BT_NOTIFIER(CBTUIPinCodeEntry); |
|
50 #endif // __BT_TEXT_NOTIFIERS_NO_SSP__ |
|
51 |
|
52 #undef ADD_BT_NOTIFIER // This macro is local to this function |
|
53 } |
|
54 |
|
55 |
|
56 /** |
|
57 The main library entry point for a notifier implementation. |
|
58 */ |
|
59 EXPORT_C CArrayPtr<MNotifierBase2>* NotifierArray() |
|
60 { |
|
61 LOG_STATIC_FUNC |
|
62 FLOG(_L("RNot\tExported entry point")); |
|
63 CArrayPtrFlat<MNotifierBase2>* notifiers = new CArrayPtrFlat<MNotifierBase2>(5); |
|
64 if (notifiers) |
|
65 { |
|
66 TRAPD(err, CreateNotifiersL(*notifiers)); |
|
67 if(err) |
|
68 { |
|
69 FLOG(_L("RNot\tError Creating notifier")); |
|
70 TInt count = notifiers->Count(); |
|
71 while(count--) |
|
72 { |
|
73 (*notifiers)[count]->Release(); |
|
74 } |
|
75 delete notifiers, notifiers = NULL; |
|
76 } |
|
77 } |
|
78 return notifiers; |
|
79 } |
|
80 |
|
81 |
|
82 // |
|
83 // BTTextNotifiersConsole |
|
84 // |
|
85 |
|
86 CConsoleBase* BTTextNotifiersConsole::AutoSizeNewL(const TDesC& aTitle, TSize aSize) |
|
87 { |
|
88 LOG_STATIC_FUNC |
|
89 // Try to create a console of our preferred size, otherwise we |
|
90 // guess the screen is too small and use its entirety. |
|
91 CConsoleBase* console = NULL; |
|
92 TRAPD(err, console = Console::NewL(aTitle, aSize)); |
|
93 if (err != KErrNone) |
|
94 { |
|
95 // If we leave now it is not because of offscreen drawing. |
|
96 console = Console::NewL(aTitle, TSize(KConsFullScreen, KConsFullScreen)); |
|
97 } |
|
98 return console; |
|
99 } |
|
100 |
|
101 |
|
102 // |
|
103 // CBTManPinNotifier |
|
104 // |
|
105 |
|
106 CBTManPinNotifier* CBTManPinNotifier::NewLC() |
|
107 { |
|
108 LOG_STATIC_FUNC |
|
109 CBTManPinNotifier* self = new(ELeave) CBTManPinNotifier(); |
|
110 CleanupStack::PushL(self); |
|
111 self->ConstructL(); |
|
112 return self; |
|
113 } |
|
114 |
|
115 CBTManPinNotifier::CBTManPinNotifier() |
|
116 { |
|
117 LOG_FUNC |
|
118 } |
|
119 |
|
120 void CBTManPinNotifier::ConstructL() |
|
121 { |
|
122 LOG_FUNC |
|
123 iEngine = CBTManPinNotifierEngine::NewL(*this); |
|
124 } |
|
125 |
|
126 void CBTManPinNotifier::Release() |
|
127 { |
|
128 LOG_FUNC |
|
129 Cancel(); |
|
130 delete this; |
|
131 } |
|
132 |
|
133 void CBTManPinNotifier::Cancel() |
|
134 { |
|
135 LOG_FUNC |
|
136 iEngine->Stop(); |
|
137 |
|
138 if (iNeedToCompleteMessage) |
|
139 { |
|
140 iMessage.Complete(KErrCancel); |
|
141 iNeedToCompleteMessage = EFalse; |
|
142 } |
|
143 } |
|
144 |
|
145 |
|
146 CBTManPinNotifier::~CBTManPinNotifier() |
|
147 { |
|
148 LOG_FUNC |
|
149 delete iEngine; |
|
150 } |
|
151 |
|
152 |
|
153 CBTManPinNotifier::TNotifierInfo CBTManPinNotifier::RegisterL() |
|
154 { |
|
155 LOG_FUNC |
|
156 iInfo.iUid=KBTManPinNotifierUid; |
|
157 iInfo.iChannel=KScreenOutputChannel; |
|
158 iInfo.iPriority=ENotifierPriorityVHigh; |
|
159 return iInfo; |
|
160 } |
|
161 |
|
162 CBTManPinNotifier::TNotifierInfo CBTManPinNotifier::Info() const |
|
163 { |
|
164 LOG_FUNC |
|
165 return iInfo; |
|
166 } |
|
167 |
|
168 TPtrC8 CBTManPinNotifier::StartL(const TDesC8& /*aBuffer*/) |
|
169 { |
|
170 LOG_FUNC |
|
171 LOG(_L("The synchronous StartL overload is not used.")) |
|
172 LEAVEL(KErrNotSupported); |
|
173 return KNullDesC8(); |
|
174 } |
|
175 |
|
176 void CBTManPinNotifier::StartL(const TDesC8& aBuffer, TInt aReplySlot, const RMessagePtr2& aMessage) |
|
177 { |
|
178 LOG_FUNC |
|
179 iReplySlot = aReplySlot; |
|
180 iMessage = RMessage2(aMessage); |
|
181 iNeedToCompleteMessage = ETrue; |
|
182 |
|
183 TRAPD(err, iEngine->StartLegacyPinEntryL(aBuffer)); |
|
184 LOG1(_L("Pin Notifier started with result %d"), err); |
|
185 if(err != KErrNone) |
|
186 { |
|
187 aMessage.Complete(err); |
|
188 iNeedToCompleteMessage = EFalse; |
|
189 LEAVEL(err); |
|
190 } |
|
191 } |
|
192 |
|
193 |
|
194 |
|
195 TPtrC8 CBTManPinNotifier::UpdateL(const TDesC8& aBuffer) |
|
196 { |
|
197 LOG_FUNC |
|
198 return iEngine->LegacyUpdateL(aBuffer); |
|
199 } |
|
200 |
|
201 void CBTManPinNotifier::MbpceoPinInputComplete(const TBTPinCode& aPin, TInt aReason) |
|
202 { |
|
203 LOG_FUNC |
|
204 LOG1(_L("\taReason = %d"), aReason); |
|
205 if (aReason == KErrNone) |
|
206 { |
|
207 TInt err = iMessage.Write(iReplySlot, aPin); |
|
208 iMessage.Complete(err); |
|
209 } |
|
210 else |
|
211 { |
|
212 iMessage.Complete(aReason); |
|
213 } |
|
214 iNeedToCompleteMessage = EFalse; |
|
215 } |
|
216 |
|
217 |
|
218 #ifndef __BT_TEXT_NOTIFIERS_NO_SSP__ |
|
219 |
|
220 // |
|
221 // CBTUIPinCodeEntry |
|
222 // |
|
223 |
|
224 CBTUIPinCodeEntry* CBTUIPinCodeEntry::NewLC() |
|
225 { |
|
226 LOG_STATIC_FUNC |
|
227 CBTUIPinCodeEntry* self = new(ELeave) CBTUIPinCodeEntry(); |
|
228 CleanupStack::PushL(self); |
|
229 self->ConstructL(); |
|
230 return self; |
|
231 } |
|
232 |
|
233 CBTUIPinCodeEntry::CBTUIPinCodeEntry() |
|
234 { |
|
235 LOG_FUNC |
|
236 } |
|
237 |
|
238 void CBTUIPinCodeEntry::ConstructL() |
|
239 { |
|
240 LOG_FUNC |
|
241 iEngine = CBTManPinNotifierEngine::NewL(*this); |
|
242 } |
|
243 |
|
244 void CBTUIPinCodeEntry::Release() |
|
245 { |
|
246 LOG_FUNC |
|
247 Cancel(); |
|
248 delete this; |
|
249 } |
|
250 |
|
251 void CBTUIPinCodeEntry::Cancel() |
|
252 { |
|
253 LOG_FUNC |
|
254 iEngine->Stop(); |
|
255 |
|
256 if (iNeedToCompleteMessage) |
|
257 { |
|
258 iMessage.Complete(KErrCancel); |
|
259 iNeedToCompleteMessage = EFalse; |
|
260 } |
|
261 } |
|
262 |
|
263 CBTUIPinCodeEntry::~CBTUIPinCodeEntry() |
|
264 { |
|
265 LOG_FUNC |
|
266 delete iEngine; |
|
267 } |
|
268 |
|
269 |
|
270 CBTManPinNotifier::TNotifierInfo CBTUIPinCodeEntry::RegisterL() |
|
271 { |
|
272 LOG_FUNC |
|
273 iInfo.iUid = KBTPinCodeEntryNotifierUid; |
|
274 iInfo.iChannel = KScreenOutputChannel; |
|
275 iInfo.iPriority = ENotifierPriorityVHigh; |
|
276 return iInfo; |
|
277 } |
|
278 |
|
279 CBTManPinNotifier::TNotifierInfo CBTUIPinCodeEntry::Info() const |
|
280 { |
|
281 LOG_FUNC |
|
282 return iInfo; |
|
283 } |
|
284 |
|
285 TPtrC8 CBTUIPinCodeEntry::StartL(const TDesC8& /*aBuffer*/) |
|
286 { |
|
287 LOG_FUNC |
|
288 LOG(_L("The synchronous StartL overload is not used.")) |
|
289 LEAVEL(KErrNotSupported); |
|
290 return KNullDesC8(); |
|
291 } |
|
292 |
|
293 void CBTUIPinCodeEntry::StartL(const TDesC8& aBuffer, TInt aReplySlot, const RMessagePtr2& aMessage) |
|
294 { |
|
295 LOG_FUNC |
|
296 iReplySlot = aReplySlot; |
|
297 iMessage = RMessage2(aMessage); |
|
298 iNeedToCompleteMessage = ETrue; |
|
299 |
|
300 TRAPD(err, iEngine->StartPinEntryL(aBuffer)); |
|
301 LOG1(_L("Pin Notifier started with result %d"), err); |
|
302 if(err != KErrNone) |
|
303 { |
|
304 aMessage.Complete(err); |
|
305 iNeedToCompleteMessage = EFalse; |
|
306 LEAVEL(err); |
|
307 } |
|
308 } |
|
309 |
|
310 TPtrC8 CBTUIPinCodeEntry::UpdateL(const TDesC8& aBuffer) |
|
311 { |
|
312 LOG_FUNC |
|
313 return iEngine->UpdateL(aBuffer); |
|
314 } |
|
315 |
|
316 void CBTUIPinCodeEntry::MbpceoPinInputComplete(const TBTPinCode& aPin, TInt aReason) |
|
317 { |
|
318 LOG_FUNC |
|
319 LOG1(_L("\taReason = %d"), aReason); |
|
320 if (aReason == KErrNone) |
|
321 { |
|
322 TInt err = iMessage.Write(iReplySlot, aPin); |
|
323 iMessage.Complete(err); |
|
324 } |
|
325 else |
|
326 { |
|
327 iMessage.Complete(aReason); |
|
328 } |
|
329 iNeedToCompleteMessage = EFalse; |
|
330 } |
|
331 |
|
332 #endif // __BT_TEXT_NOTIFIERS_NO_SSP__ |
|
333 |
|
334 |
|
335 |
|
336 |
|
337 CBTManPinNotifierEngine* CBTManPinNotifierEngine::NewL(MBTPinCodeEntryObserver& aObserver) |
|
338 { |
|
339 LOG_STATIC_FUNC |
|
340 CBTManPinNotifierEngine* c = new (ELeave) CBTManPinNotifierEngine(aObserver); |
|
341 CleanupStack::PushL(c); |
|
342 c->ConstructL(); |
|
343 CleanupStack::Pop(c); |
|
344 return c; |
|
345 } |
|
346 |
|
347 void CBTManPinNotifierEngine::ConstructL() |
|
348 { |
|
349 LOG_FUNC |
|
350 } |
|
351 |
|
352 void CBTManPinNotifierEngine::StartPinEntryL(const TDesC8& aBuffer) |
|
353 { |
|
354 LOG_FUNC |
|
355 __ASSERT_DEBUG(((iHostResolverCacheProdder==NULL)&&(iGetPinFromConsole==NULL)), User::Panic(_L("BTPinProvider"), KErrGeneral)); |
|
356 |
|
357 __ASSERT_DEBUG(!IsActive(), User::Panic(_L("BTPinProvider"), KErrGeneral)); |
|
358 |
|
359 TBTPinCodeEntryNotifierParamsPckg pckg; |
|
360 if(aBuffer.Length() != sizeof(TBTPinCodeEntryNotifierParams)) |
|
361 { |
|
362 User::Leave(KErrArgument); |
|
363 } |
|
364 pckg.Copy(aBuffer); |
|
365 |
|
366 iDeviceAddress = pckg().DeviceAddress(); |
|
367 iDeviceName = pckg().DeviceName(); |
|
368 iPasskeyMinLength = pckg().PinCodeMinLength(); |
|
369 iLocallyInitiated = pckg().LocallyInitiated(); |
|
370 iStrongKeyRequired = pckg().StrongPinCodeRequired(); |
|
371 iRecommendedPasskeyMinLength = pckg().RecommendedPinCodeMinLength(); |
|
372 |
|
373 DoStartPinEntryL(); |
|
374 } |
|
375 |
|
376 void CBTManPinNotifierEngine::StartLegacyPinEntryL(const TDesC8& aBuffer) |
|
377 { |
|
378 LOG_FUNC |
|
379 __ASSERT_DEBUG(((iHostResolverCacheProdder==NULL)&&(iGetPinFromConsole==NULL)), User::Panic(_L("BTPinProvider"), KErrGeneral)); |
|
380 |
|
381 __ASSERT_DEBUG(!IsActive(), User::Panic(_L("BTPinProvider"), KErrGeneral)); |
|
382 |
|
383 TBTPasskeyNotifierParamsPckg pckg; |
|
384 if(aBuffer.Length() != sizeof(TBTPasskeyNotifierParams)) |
|
385 { |
|
386 User::Leave(KErrArgument); |
|
387 } |
|
388 pckg.Copy(aBuffer); |
|
389 |
|
390 iDeviceAddress = pckg().iBDAddr; |
|
391 iDeviceName = pckg().iName; |
|
392 iPasskeyMinLength = pckg().iPasskeyMinLength; |
|
393 iLocallyInitiated = pckg().iLocallyInitiated; |
|
394 iStrongKeyRequired = EFalse; // Cannot be signalled through legacy notifier. |
|
395 |
|
396 DoStartPinEntryL(); |
|
397 } |
|
398 |
|
399 void CBTManPinNotifierEngine::DoStartPinEntryL() |
|
400 { |
|
401 LOG_FUNC |
|
402 if(iDevice == NULL) |
|
403 { |
|
404 iDevice = CBTDevice::NewL(iDeviceAddress); |
|
405 FLOG(_L("RNot\tCBTManPinNotifierEngine::StartPinEntryL() - Create new CDevice")); |
|
406 } |
|
407 |
|
408 if (iDeviceName.Length()==0) |
|
409 { |
|
410 User::LeaveIfError(iRegistry.Connect()); |
|
411 User::LeaveIfError(iRegistryView.Open(iRegistry)); |
|
412 FLOG(_L("RNot\tPin Notifier looking for device in Registry")); |
|
413 // let's try the Registry for a name |
|
414 iRegistrySearch.FindAddress(iDeviceAddress); |
|
415 iRegistryView.CreateView(iRegistrySearch, iStatus); |
|
416 iRegistryState = EFinding; |
|
417 SetActive(); |
|
418 } |
|
419 else |
|
420 { |
|
421 //Just work with addresses and names |
|
422 iDevice->SetDeviceNameL(BTDeviceNameConverter::ToUTF8L(iDeviceName)); |
|
423 |
|
424 //Ask Host Resolver Inquiry Cache for CoD |
|
425 //DEF039276 Altered code - always try and get CoD |
|
426 iHostResolverCacheProdder = CHostResolverCacheProdder::NewL(this); |
|
427 iHostResolverCacheProdder->Start(iDeviceAddress); |
|
428 |
|
429 iGetPinFromConsole = CBTGetPinFromConsole::NewL(this, *iDevice, iPasskeyMinLength, iLocallyInitiated, iStrongKeyRequired, iRecommendedPasskeyMinLength); |
|
430 iGetPinFromConsole->GetPinL(); |
|
431 } |
|
432 } |
|
433 |
|
434 |
|
435 void CBTManPinNotifierEngine::RunL() |
|
436 { |
|
437 LOG_FUNC |
|
438 |
|
439 if(iStatus == KErrNotFound) |
|
440 { |
|
441 FLOG(_L("Device not found in Registry (OK)")) |
|
442 __ASSERT_DEBUG(iRegistryState == EFinding, User::Invariant()); |
|
443 |
|
444 // not to worry - just no name available for the UI |
|
445 iDevice->SetDeviceAddress(iDeviceAddress); |
|
446 iGetPinFromConsole = CBTGetPinFromConsole::NewL(this, *iDevice, iPasskeyMinLength, iLocallyInitiated, iStrongKeyRequired, iRecommendedPasskeyMinLength); |
|
447 iGetPinFromConsole->GetPinL(); |
|
448 } |
|
449 else if(iStatus >= KErrNone) |
|
450 { |
|
451 switch (iRegistryState) |
|
452 { |
|
453 case EFinding: |
|
454 { |
|
455 FLOG(_L("Device found in Registry - getting details")) |
|
456 iResponse = CBTRegistryResponse::NewL(iRegistryView); |
|
457 iResponse->Start(iStatus); |
|
458 SetActive(); |
|
459 iRegistryState = EGetting; |
|
460 } |
|
461 break; |
|
462 case EGetting: |
|
463 { |
|
464 FLOG(_L("Got device details, launching PIN console")) |
|
465 iGetPinFromConsole = CBTGetPinFromConsole::NewL(this, *(iResponse->Results()[0]), iPasskeyMinLength, iLocallyInitiated, iStrongKeyRequired, iRecommendedPasskeyMinLength); |
|
466 |
|
467 PerformNameUpdateL(KErrNone); |
|
468 |
|
469 iGetPinFromConsole->GetPinL(); |
|
470 } |
|
471 break; |
|
472 } |
|
473 } |
|
474 } |
|
475 |
|
476 void CBTManPinNotifierEngine::DoCancel() |
|
477 { |
|
478 LOG_FUNC |
|
479 if (iHostResolverCacheProdder) |
|
480 { |
|
481 iHostResolverCacheProdder->Cancel(); |
|
482 delete iHostResolverCacheProdder; |
|
483 iHostResolverCacheProdder = NULL; |
|
484 } |
|
485 iRegistryView.CancelRequest(iStatus); |
|
486 if (iResponse) |
|
487 { |
|
488 iResponse->Cancel(); |
|
489 } |
|
490 iGetPinFromConsole->Cancel(); |
|
491 } |
|
492 |
|
493 CBTManPinNotifierEngine::~CBTManPinNotifierEngine() |
|
494 { |
|
495 LOG_FUNC |
|
496 Cancel(); |
|
497 |
|
498 delete iHostResolverCacheProdder; |
|
499 delete iGetPinFromConsole; |
|
500 delete iDevice; |
|
501 |
|
502 iRegistryView.Close(); |
|
503 iRegistry.Close(); |
|
504 } |
|
505 |
|
506 void CBTManPinNotifierEngine::Stop() |
|
507 { |
|
508 LOG_FUNC |
|
509 Cancel(); |
|
510 |
|
511 if (iGetPinFromConsole) |
|
512 { |
|
513 iGetPinFromConsole->Cancel(); |
|
514 delete iGetPinFromConsole; |
|
515 iGetPinFromConsole = NULL; |
|
516 } |
|
517 |
|
518 if (iHostResolverCacheProdder) |
|
519 { |
|
520 iHostResolverCacheProdder->Cancel(); |
|
521 delete iHostResolverCacheProdder; |
|
522 iHostResolverCacheProdder = NULL; |
|
523 } |
|
524 |
|
525 //clean up iDevice... |
|
526 delete iDevice; |
|
527 iDevice = NULL; |
|
528 } |
|
529 |
|
530 TPtrC8 CBTManPinNotifierEngine::LegacyUpdateL(const TDesC8& aBuffer) |
|
531 { |
|
532 LOG_FUNC |
|
533 |
|
534 TBTNotifierUpdateParamsPckg pckg; |
|
535 pckg.Copy(aBuffer); |
|
536 |
|
537 if(iDevice) |
|
538 { |
|
539 //we only want to do this if our device doesn't have a valid device name... |
|
540 if (!iDevice->IsValidDeviceName()) |
|
541 { |
|
542 iDeviceName = pckg().iName; |
|
543 if(iGetPinFromConsole) |
|
544 { |
|
545 PerformNameUpdateL(pckg().iResult); |
|
546 } |
|
547 } |
|
548 } |
|
549 else |
|
550 { |
|
551 FLOG(_L("RNot\tCBTManPinNotifierEngine::UpdateL() called with iDevice == NULL")); |
|
552 } |
|
553 |
|
554 return KNullDesC8(); |
|
555 } |
|
556 |
|
557 TPtrC8 CBTManPinNotifierEngine::UpdateL(const TDesC8& aBuffer) |
|
558 { |
|
559 LOG_FUNC |
|
560 |
|
561 TBTNotifierUpdateParamsPckg2 pckgRaw; |
|
562 pckgRaw.Copy(aBuffer.Left(pckgRaw.MaxLength())); |
|
563 |
|
564 // We only expect device name updates |
|
565 if(pckgRaw().Type() != TBTNotifierUpdateParams2::EDeviceName) |
|
566 { |
|
567 User::Leave(KErrArgument); |
|
568 } |
|
569 |
|
570 TBTDeviceNameUpdateParamsPckg pckg; |
|
571 pckg.Copy(aBuffer); |
|
572 if(iDevice) |
|
573 { |
|
574 //we only want to do this if our device doesn't have a valid device name... |
|
575 if(!iDevice->IsValidDeviceName()) |
|
576 { |
|
577 iDeviceName = pckg().DeviceName(); |
|
578 if(iGetPinFromConsole) |
|
579 { |
|
580 PerformNameUpdateL(pckg().Result()); |
|
581 } |
|
582 } |
|
583 } |
|
584 else |
|
585 { |
|
586 FLOG(_L("RNot\tCBTManPinNotifierEngine::UpdateL() called with iDevice == NULL")); |
|
587 } |
|
588 |
|
589 return KNullDesC8(); |
|
590 } |
|
591 |
|
592 void CBTManPinNotifierEngine::PerformNameUpdateL(TInt aResult) |
|
593 { |
|
594 LOG_FUNC |
|
595 iGetPinFromConsole->DeviceNameRetrieved(iDeviceName, aResult); |
|
596 if(iDevice) |
|
597 { |
|
598 iDevice->SetDeviceNameL(BTDeviceNameConverter::ToUTF8L(iDeviceName)); |
|
599 } |
|
600 else |
|
601 { |
|
602 FLOG(_L("RNot\tCBTManPinNotifierEngine::PerformNameUpdateL() called with iDevice == NULL")); |
|
603 } |
|
604 } |
|
605 |
|
606 CBTManPinNotifierEngine::CBTManPinNotifierEngine(MBTPinCodeEntryObserver& aObserver) |
|
607 : CActive(EPriorityStandard) |
|
608 , iObserver(aObserver) |
|
609 { |
|
610 LOG_FUNC |
|
611 CActiveScheduler::Add(this); |
|
612 } |
|
613 |
|
614 |
|
615 void CBTManPinNotifierEngine::PinInputComplete(const TBTPinCode& aPin, TInt aReason) |
|
616 { |
|
617 LOG_FUNC |
|
618 iObserver.MbpceoPinInputComplete(aPin, aReason); |
|
619 delete iHostResolverCacheProdder; |
|
620 iHostResolverCacheProdder = NULL; |
|
621 delete iDevice; |
|
622 iDevice = NULL; |
|
623 delete iGetPinFromConsole; |
|
624 iGetPinFromConsole = NULL; |
|
625 } |
|
626 |
|
627 void CBTManPinNotifierEngine::HostResolverCacheInfoReceived(const TNameEntry& aResult) |
|
628 { |
|
629 LOG_FUNC |
|
630 __ASSERT_DEBUG(((iGetPinFromConsole!=NULL)), User::Panic(_L("BTPinProvider"), KErrGeneral)); |
|
631 |
|
632 TInquirySockAddr& sa = TInquirySockAddr::Cast(aResult().iAddr); |
|
633 TBTDeviceClass deviceClass(sa.MajorServiceClass(), sa.MajorClassOfDevice(), sa.MinorClassOfDevice()); |
|
634 iGetPinFromConsole->CoDRetrieved(deviceClass); |
|
635 } |
|
636 |
|
637 |
|
638 |
|
639 //------------------------------------------------------------------------// |
|
640 //Get CoD from HostResolver class |
|
641 //------------------------------------------------------------------------// |
|
642 CHostResolverCacheProdder* CHostResolverCacheProdder::NewL(CBTManPinNotifierEngine* aParent) |
|
643 { |
|
644 LOG_STATIC_FUNC |
|
645 CHostResolverCacheProdder* self = CHostResolverCacheProdder::NewLC(aParent); |
|
646 CleanupStack::Pop(); |
|
647 return self; |
|
648 } |
|
649 |
|
650 CHostResolverCacheProdder* CHostResolverCacheProdder::NewLC(CBTManPinNotifierEngine* aParent) |
|
651 { |
|
652 LOG_STATIC_FUNC |
|
653 CHostResolverCacheProdder* self = new (ELeave) CHostResolverCacheProdder(aParent); |
|
654 CleanupStack::PushL(self); |
|
655 return self; |
|
656 } |
|
657 |
|
658 CHostResolverCacheProdder::~CHostResolverCacheProdder() |
|
659 { |
|
660 LOG_FUNC |
|
661 Cancel(); |
|
662 } |
|
663 |
|
664 CHostResolverCacheProdder::CHostResolverCacheProdder(CBTManPinNotifierEngine* aParent) |
|
665 : CActive(EPriorityStandard), iParent(aParent) |
|
666 { |
|
667 LOG_FUNC |
|
668 CActiveScheduler::Add(this); |
|
669 } |
|
670 |
|
671 |
|
672 |
|
673 TInt CHostResolverCacheProdder::Start(const TBTDevAddr& aBDAddr) |
|
674 { |
|
675 LOG_FUNC |
|
676 __ASSERT_DEBUG(!IsActive(), User::Panic(_L("HostResolverCacheProdder"), KErrGeneral)); |
|
677 |
|
678 FLOG(_L("RNot\tCHostResolverCacheProdder::Start")); |
|
679 RSocketServ sockServer; |
|
680 sockServer.Connect(); |
|
681 TProtocolDesc info; |
|
682 /**/ |
|
683 TInt ret1 = sockServer.FindProtocol(_L("BTLinkManager"),info); |
|
684 if(ret1!=KErrNone) |
|
685 { |
|
686 FTRACE(FPrint(_L("RNot\tFailure to find btlinkmanager - error %d"), ret1)); |
|
687 TInquirySockAddr& sa = TInquirySockAddr::Cast(iResult().iAddr); |
|
688 sa.SetMajorServiceClass(0); |
|
689 sa.SetMajorClassOfDevice(0); |
|
690 sa.SetMinorClassOfDevice(0); |
|
691 iParent->HostResolverCacheInfoReceived(iResult); |
|
692 return ret1; |
|
693 } |
|
694 /**/ |
|
695 TInt ret = iHostResolver.Open(sockServer, KBTAddrFamily, KBTLinkManager); |
|
696 iAddr.SetBTAddr(aBDAddr); |
|
697 iAddr.SetIAC(KGIAC); |
|
698 iAddr.SetAction(KHostResCache); |
|
699 if(ret==KErrNone) |
|
700 { |
|
701 iHostResolver.GetByAddress(iAddr, iResult, iStatus); |
|
702 SetActive(); |
|
703 } |
|
704 return ret; |
|
705 } |
|
706 |
|
707 void CHostResolverCacheProdder::RunL() |
|
708 { |
|
709 LOG_FUNC |
|
710 if (iStatus.Int() == KErrNone) |
|
711 { |
|
712 iHostResolver.Close(); |
|
713 iParent->HostResolverCacheInfoReceived(iResult); |
|
714 } |
|
715 else |
|
716 { |
|
717 FTRACE(FPrint(_L("RNot\tNo CoD returned from Host Resolver - error %d"), iStatus.Int())); |
|
718 iHostResolver.Close(); |
|
719 } |
|
720 } |
|
721 |
|
722 |
|
723 |
|
724 //------------------------------------------------------------------------// |
|
725 //Get pin from a console window class |
|
726 //------------------------------------------------------------------------// |
|
727 |
|
728 |
|
729 CBTGetPinFromConsole* CBTGetPinFromConsole::NewL(CBTManPinNotifierEngine* aParent, const CBTDevice& aDevice, TUint aPasskeyMinLength, TBool aInternallyInitiated, TBool aStrongKeyRequired, TUint aRecommendedPasskeyMinLength) |
|
730 { |
|
731 LOG_STATIC_FUNC |
|
732 CBTGetPinFromConsole* self = new(ELeave) CBTGetPinFromConsole(aParent, aPasskeyMinLength, aInternallyInitiated, aStrongKeyRequired, aRecommendedPasskeyMinLength); |
|
733 CleanupStack::PushL(self); |
|
734 self->ConstructL(aDevice); |
|
735 CleanupStack::Pop(self); |
|
736 return self; |
|
737 } |
|
738 |
|
739 CBTGetPinFromConsole::CBTGetPinFromConsole(CBTManPinNotifierEngine* aParent, TUint aPasskeyMinLength, TBool aInternallyInitiated, TBool aStrongKeyRequired, TUint aRecommendedPasskeyMinLength) |
|
740 : CActive(EPriorityStandard) |
|
741 , iParent(aParent) |
|
742 , iPasskeyMinLength(aPasskeyMinLength) |
|
743 , iInternallyInitiated(aInternallyInitiated) |
|
744 , iStrongKeyRequired(aStrongKeyRequired) |
|
745 , iRecommendedPasskeyMinLength(aRecommendedPasskeyMinLength) |
|
746 { |
|
747 LOG_FUNC |
|
748 CActiveScheduler::Add(this); |
|
749 } |
|
750 |
|
751 void CBTGetPinFromConsole::ConstructL(const CBTDevice& aDevice) |
|
752 { |
|
753 LOG_FUNC |
|
754 iConsole = BTTextNotifiersConsole::AutoSizeNewL(_L("PIN Input"), TSize(KConsFullScreen,KConsFullScreen)); |
|
755 iDevice = &aDevice;//.CopyL(); |
|
756 |
|
757 #ifdef __BT_TEXT_NOTIFIERS_AUTO__ |
|
758 TCallBack autoNotifierCB(AutoNotifierCallBack, this); |
|
759 iAutoNotifierCallback = new (ELeave)CAsyncCallBack(autoNotifierCB, EActiveMedPriority); |
|
760 #endif // __BT_TEXT_NOTIFIERS_AUTO__ |
|
761 } |
|
762 |
|
763 CBTGetPinFromConsole::~CBTGetPinFromConsole() |
|
764 { |
|
765 LOG_FUNC |
|
766 Cancel(); |
|
767 delete iConsole; |
|
768 |
|
769 #ifdef __BT_TEXT_NOTIFIERS_AUTO__ |
|
770 delete iAutoNotifierCallback; |
|
771 #endif |
|
772 } |
|
773 |
|
774 void CBTGetPinFromConsole::RunL() |
|
775 { |
|
776 LOG_FUNC |
|
777 #ifdef __BT_TEXT_NOTIFIERS_AUTO__ |
|
778 |
|
779 // Set pin to 1234 |
|
780 iPin().iPIN[0] = 0x31; |
|
781 iPin().iPIN[1] = 0x32; |
|
782 iPin().iPIN[2] = 0x33; |
|
783 iPin().iPIN[3] = 0x34; |
|
784 |
|
785 iPin().iLength = 4; |
|
786 |
|
787 iParent->PinInputComplete(iPin, KErrNone); |
|
788 |
|
789 #else // __BT_TEXT_NOTIFIERS_AUTO__ |
|
790 |
|
791 TKeyCode key = iConsole->KeyCode(); |
|
792 if (key == EKeyEnter) |
|
793 { |
|
794 if (iPin().iLength >= iPasskeyMinLength) |
|
795 { |
|
796 iParent->PinInputComplete(iPin, KErrNone); |
|
797 } |
|
798 else |
|
799 { |
|
800 iConsole->Printf(_L("\nToo short!...\nPress any key to continue\n")); |
|
801 TRequestStatus stat; |
|
802 iConsole->Read(stat); |
|
803 User::WaitForRequest(stat); |
|
804 GetPinL(); |
|
805 return; |
|
806 } |
|
807 } |
|
808 else if (key == EKeyEscape) |
|
809 { |
|
810 iParent->PinInputComplete(iPin, KErrCancel); |
|
811 } |
|
812 else |
|
813 { |
|
814 if (iInsert < KHCIPINCodeSize) |
|
815 { |
|
816 TBuf<1> b; |
|
817 b.Append(key); |
|
818 iPin().iPIN[iInsert] = (TUint8)key; |
|
819 iConsole->Printf(b); |
|
820 iPin().iLength = (TUint8)++iInsert; |
|
821 } |
|
822 IssueRequestL(); |
|
823 /* |
|
824 else |
|
825 { |
|
826 iConsole->Printf(_L("\nToo many characters...\nPress any key to continue\n")); |
|
827 TRequestStatus stat; |
|
828 iConsole->Read(stat); |
|
829 User::WaitForRequest(stat); |
|
830 GetPinL(); |
|
831 } |
|
832 */ |
|
833 } |
|
834 #endif // __BT_TEXT_NOTIFIERS_AUTO__ |
|
835 } |
|
836 |
|
837 void CBTGetPinFromConsole::DoCancel() |
|
838 { |
|
839 LOG_FUNC |
|
840 #ifdef __BT_TEXT_NOTIFIERS_AUTO__ |
|
841 iConsole->ReadCancel(); |
|
842 #endif |
|
843 iConsole->Printf(_L("\nPin cancelled.\nPress any key to continue...\n")); |
|
844 iPin.Zero(); |
|
845 } |
|
846 |
|
847 void CBTGetPinFromConsole::GetPinL() |
|
848 { |
|
849 LOG_FUNC |
|
850 iInsert = 0; |
|
851 iConsole->ClearScreen(); |
|
852 iConsole->Printf(_L("Please enter pin for device:\nAddress: ")); |
|
853 TBTDevAddr a = iDevice->BDAddr(); |
|
854 iConsole->Printf(_L("0x%02x%02x%02x%02x%02x%02x"), a[0], a[1], a[2], a[3], a[4], a[5]); |
|
855 if (iDevice->IsValidDeviceName()) |
|
856 { |
|
857 TBTDeviceName dispBuf; |
|
858 dispBuf.Copy(iDevice->DeviceName()); |
|
859 iConsole->Printf(_L("\nName: %S"), &dispBuf); |
|
860 } |
|
861 |
|
862 // check if PINCodeLength is set |
|
863 if (0<iPasskeyMinLength && iPasskeyMinLength<=KHCIPINCodeSize) |
|
864 { |
|
865 iConsole->Printf(_L("\nRequired Minimal PIN code length: %d"), iPasskeyMinLength); |
|
866 } |
|
867 else |
|
868 { |
|
869 // set to 0 if we got some rubbish value... |
|
870 iPasskeyMinLength=0; |
|
871 } |
|
872 |
|
873 //check if RecommendedPinCodeMinLength is set |
|
874 if (0<iRecommendedPasskeyMinLength && iRecommendedPasskeyMinLength<=KHCIPINCodeSize) |
|
875 { |
|
876 iConsole->Printf(_L("\nRecommended Minimal PIN code length: %d"), iRecommendedPasskeyMinLength); |
|
877 } |
|
878 else |
|
879 { |
|
880 // set to 0 if we got some rubbish value... |
|
881 iRecommendedPasskeyMinLength=0; |
|
882 } |
|
883 |
|
884 if(iInternallyInitiated) |
|
885 { |
|
886 iConsole->Printf(_L("\nInternally initiated authentication.")); |
|
887 } |
|
888 else |
|
889 { |
|
890 iConsole->Printf(_L("\nRemote side initiated the authentication.")); |
|
891 } |
|
892 |
|
893 if(iStrongKeyRequired) |
|
894 { |
|
895 iConsole->Printf(_L("\n!!! Strong PIN Code Required !!!")); |
|
896 } |
|
897 |
|
898 iConsole->Printf(_L("\nand press [return] to accept or [esc] to cancel\n")); |
|
899 IssueRequestL(); |
|
900 } |
|
901 |
|
902 void CBTGetPinFromConsole::IssueRequestL() |
|
903 { |
|
904 LOG_FUNC |
|
905 __ASSERT_DEBUG(!IsActive(), User::Panic(_L("BTGetPinFromConsole"), KErrGeneral)); |
|
906 |
|
907 #ifdef __BT_TEXT_NOTIFIERS_AUTO__ |
|
908 iAutoNotifierCallback->CallBack(); |
|
909 iStatus = KRequestPending; |
|
910 #else //__BT_TEXT_NOTIFIERS_AUTO__ |
|
911 iConsole->Read(iStatus); |
|
912 #endif // __BT_TEXT_NOTIFIERS_AUTO__ |
|
913 |
|
914 SetActive(); |
|
915 } |
|
916 |
|
917 #ifdef __BT_TEXT_NOTIFIERS_AUTO__ |
|
918 /*static*/ TInt CBTGetPinFromConsole::AutoNotifierCallBack(TAny *aConsolePin) |
|
919 { |
|
920 LOG_STATIC_FUNC |
|
921 CBTGetAuthFromConsole* consolePin = static_cast<CBTGetAuthFromConsole*>(aConsolePin); |
|
922 if(consolePin->IsActive()) |
|
923 { |
|
924 TRequestStatus* stat = &(consolePin->iStatus); |
|
925 User::RequestComplete(stat, KErrNone); |
|
926 } |
|
927 return EFalse; |
|
928 } |
|
929 #endif // __BT_TEXT_NOTIFIERS_AUTO__ |
|
930 |
|
931 void CBTGetPinFromConsole::DeviceNameRetrieved(const TPtrC aName, TInt aResult) |
|
932 { |
|
933 LOG_FUNC |
|
934 iConsole->Printf(_L("\nDevice Name Retrieved (code %d): \n"), aResult); |
|
935 iConsole->Printf(aName); |
|
936 #ifdef _DEBUG |
|
937 iConsole->Printf(_L("\n")); |
|
938 #endif |
|
939 } |
|
940 |
|
941 void CBTGetPinFromConsole::CoDRetrieved(TBTDeviceClass& aCoD) |
|
942 { |
|
943 LOG_FUNC |
|
944 iConsole->Printf(_L("CoD Retrieved (MajorS MajorD MinorD):")); |
|
945 iConsole->Printf(_L("\t0x%04x 0x%02x 0x%02x\n"), |
|
946 aCoD.MajorServiceClass(), |
|
947 aCoD.MajorDeviceClass(), |
|
948 aCoD.MinorDeviceClass() |
|
949 ); |
|
950 } |
|
951 |
|
952 |
|
953 |
|
954 // |
|
955 // CBTManAuthNotifier |
|
956 // |
|
957 |
|
958 void CBTManAuthNotifier::Release() |
|
959 { |
|
960 LOG_FUNC |
|
961 Cancel(); |
|
962 delete this; |
|
963 } |
|
964 |
|
965 CBTManAuthNotifier::TNotifierInfo CBTManAuthNotifier::RegisterL() |
|
966 { |
|
967 LOG_FUNC |
|
968 iInfo.iUid=KBTManAuthNotifierUid; |
|
969 iInfo.iChannel=KScreenOutputChannel; |
|
970 iInfo.iPriority=ENotifierPriorityVHigh; |
|
971 return iInfo; |
|
972 } |
|
973 |
|
974 CBTManAuthNotifier::TNotifierInfo CBTManAuthNotifier::Info() const |
|
975 { |
|
976 LOG_FUNC |
|
977 return iInfo; |
|
978 } |
|
979 |
|
980 |
|
981 TPtrC8 CBTManAuthNotifier::StartL(const TDesC8& /*aBuffer*/) |
|
982 { |
|
983 LOG_FUNC |
|
984 LOG(_L("The synchronous StartL overload is not used.")) |
|
985 LEAVEL(KErrNotSupported); |
|
986 return KNullDesC8(); |
|
987 } |
|
988 |
|
989 void CBTManAuthNotifier::StartL(const TDesC8& aBuffer, TInt aReplySlot, const RMessagePtr2& aMessage) |
|
990 { |
|
991 LOG_FUNC |
|
992 iReplySlot = aReplySlot; |
|
993 iMessage = RMessage2(aMessage); |
|
994 iNeedToCompleteMessage = ETrue; |
|
995 |
|
996 TRAPD(err, iEngine->StartAuthorisationL(aBuffer)); |
|
997 if (err) |
|
998 { |
|
999 FLOG(_L("RNot\t** could not StartAuthorisation **")); |
|
1000 aMessage.Complete(err); |
|
1001 iNeedToCompleteMessage = EFalse; |
|
1002 User::Leave(err); |
|
1003 } |
|
1004 else |
|
1005 { |
|
1006 FLOG(_L("RNot\tCBTManAuthNotifier - Started authorisation OK")); |
|
1007 } |
|
1008 } |
|
1009 |
|
1010 |
|
1011 |
|
1012 CBTManAuthNotifier::~CBTManAuthNotifier() |
|
1013 { |
|
1014 LOG_FUNC |
|
1015 delete iEngine; |
|
1016 } |
|
1017 |
|
1018 void CBTManAuthNotifier::Cancel() |
|
1019 { |
|
1020 LOG_FUNC |
|
1021 |
|
1022 iEngine->Stop(); |
|
1023 |
|
1024 if (iNeedToCompleteMessage) |
|
1025 { |
|
1026 iMessage.Complete(KErrCancel); |
|
1027 iNeedToCompleteMessage = EFalse; |
|
1028 } |
|
1029 } |
|
1030 |
|
1031 TPtrC8 CBTManAuthNotifier::UpdateL(const TDesC8& aBuffer) |
|
1032 { |
|
1033 LOG_FUNC |
|
1034 return iEngine->UpdateL(aBuffer); |
|
1035 } |
|
1036 |
|
1037 void CBTManAuthNotifier::AuthorisationComplete(TBool aDecision, TInt aReason) |
|
1038 { |
|
1039 LOG_FUNC |
|
1040 if (aReason == KErrNone) |
|
1041 { |
|
1042 FTRACE(FPrint(_L("RNot\tCBTManAuthNotifier::AuthorisationComplete(TBool=%d)"), aDecision)); |
|
1043 |
|
1044 TInt err = iMessage.Write(iReplySlot, TPckgC<TBool>(aDecision)); |
|
1045 |
|
1046 iMessage.Complete(err); |
|
1047 } |
|
1048 else |
|
1049 { |
|
1050 FTRACE(FPrint(_L("RNot\tCBTManAuthNotifier::AuthorisationComplete(ERROR=%d)"), aReason)); |
|
1051 iMessage.Complete(aReason); |
|
1052 } |
|
1053 iNeedToCompleteMessage = EFalse; |
|
1054 } |
|
1055 |
|
1056 |
|
1057 CBTManAuthNotifier* CBTManAuthNotifier::NewLC() |
|
1058 { |
|
1059 LOG_STATIC_FUNC |
|
1060 CBTManAuthNotifier* self=new (ELeave) CBTManAuthNotifier(); |
|
1061 CleanupStack::PushL(self); |
|
1062 self->ConstructL(); |
|
1063 return self; |
|
1064 } |
|
1065 |
|
1066 void CBTManAuthNotifier::ConstructL() |
|
1067 { |
|
1068 LOG_FUNC |
|
1069 iEngine = CBTManAuthNotifierEngine::NewL(*this); |
|
1070 } |
|
1071 |
|
1072 CBTManAuthNotifierEngine::CBTManAuthNotifierEngine(CBTManAuthNotifier& aParent) |
|
1073 : CActive(EPriorityStandard), iParent(aParent) |
|
1074 { |
|
1075 LOG_FUNC |
|
1076 CActiveScheduler::Add(this); |
|
1077 } |
|
1078 |
|
1079 |
|
1080 // |
|
1081 // CBTManAuthNotifierEngine |
|
1082 // |
|
1083 |
|
1084 CBTManAuthNotifierEngine* CBTManAuthNotifierEngine::NewL(CBTManAuthNotifier& aParent) |
|
1085 { |
|
1086 LOG_STATIC_FUNC |
|
1087 CBTManAuthNotifierEngine* self=new (ELeave) CBTManAuthNotifierEngine(aParent); |
|
1088 return self; |
|
1089 } |
|
1090 |
|
1091 void CBTManAuthNotifierEngine::Stop() |
|
1092 { |
|
1093 LOG_FUNC |
|
1094 Cancel(); |
|
1095 if (iGetAuthFromConsole) |
|
1096 { |
|
1097 FLOG(_L("RNot\tCancelling authorisation console...")) |
|
1098 iGetAuthFromConsole->Cancel(); |
|
1099 delete iGetAuthFromConsole; |
|
1100 iGetAuthFromConsole = NULL; |
|
1101 } |
|
1102 |
|
1103 //clean up iDevice... |
|
1104 delete iDevice; |
|
1105 iDevice = NULL; |
|
1106 } |
|
1107 |
|
1108 void CBTManAuthNotifierEngine::DoCancel() |
|
1109 { |
|
1110 LOG_FUNC |
|
1111 |
|
1112 iRegistryView.CancelRequest(iStatus); |
|
1113 if (iResponse) |
|
1114 { |
|
1115 iResponse->Cancel(); |
|
1116 } |
|
1117 } |
|
1118 |
|
1119 CBTManAuthNotifierEngine::~CBTManAuthNotifierEngine() |
|
1120 { |
|
1121 LOG_FUNC |
|
1122 Cancel(); |
|
1123 |
|
1124 delete iGetAuthFromConsole; |
|
1125 |
|
1126 iRegistryView.Close(); |
|
1127 iRegistry.Close(); |
|
1128 } |
|
1129 |
|
1130 void CBTManAuthNotifierEngine::AuthorisationComplete(TBool aDecision, TInt aReason) |
|
1131 { |
|
1132 LOG_FUNC |
|
1133 iParent.AuthorisationComplete(aDecision, aReason); |
|
1134 delete iGetAuthFromConsole; |
|
1135 iGetAuthFromConsole = NULL; |
|
1136 delete iDevice; |
|
1137 iDevice = NULL; |
|
1138 } |
|
1139 |
|
1140 TPtrC8 CBTManAuthNotifierEngine::UpdateL(const TDesC8& aBuffer) |
|
1141 { |
|
1142 LOG_FUNC |
|
1143 if (iGetAuthFromConsole) |
|
1144 { |
|
1145 if (!iDevice) |
|
1146 { |
|
1147 iDevice = CBTDevice::NewL(); |
|
1148 } |
|
1149 //we only want to do this if our device doesn't have a valid device name... |
|
1150 if (!iDevice->IsValidDeviceName()) |
|
1151 { |
|
1152 TBTNotifierUpdateParams params; |
|
1153 TPckgC<TBTNotifierUpdateParams> pckg(params); |
|
1154 pckg.Set(aBuffer); |
|
1155 iGetAuthFromConsole->DeviceNameRetrieved(pckg().iName, pckg().iResult); |
|
1156 iDevice->SetDeviceNameL(BTDeviceNameConverter::ToUTF8L(pckg().iName)); |
|
1157 } |
|
1158 } |
|
1159 return KNullDesC8(); |
|
1160 } |
|
1161 |
|
1162 void CBTManAuthNotifierEngine::StartAuthorisationL(const TDesC8& aBuffer) |
|
1163 { |
|
1164 LOG_FUNC |
|
1165 // __ASSERT_DEBUG(((iGetAuthFromConsole==NULL)&&(iDevice==NULL)&&(iDeviceFromRegistry==NULL)), User::Panic(_L("BTAuthProvider"), KErrGeneral)); |
|
1166 __ASSERT_DEBUG(!IsActive(), User::Panic(_L("BTAuthProvider"), KErrGeneral)); |
|
1167 |
|
1168 iAuthPckg.Copy(aBuffer); |
|
1169 |
|
1170 TBTDeviceName name = iAuthPckg().iName; |
|
1171 |
|
1172 if (name.Length()==0) |
|
1173 { |
|
1174 // Find the device - need to get the full details for the name, so do a search |
|
1175 FTRACE(FPrint(_L("RNot\tStarting authorisation..."))); |
|
1176 User::LeaveIfError(iRegistry.Connect()); |
|
1177 User::LeaveIfError(iRegistryView.Open(iRegistry)); |
|
1178 iRegistrySearch.FindAddress(iAuthPckg().iBDAddr); |
|
1179 iRegistryView.CreateView(iRegistrySearch, iStatus); |
|
1180 iRegistryState = EFinding; |
|
1181 SetActive(); |
|
1182 } |
|
1183 else |
|
1184 { |
|
1185 // create our dummy device (didn't really need this could just work with addresses and names!) |
|
1186 delete iDevice; |
|
1187 iDevice = NULL; |
|
1188 iDevice = CBTDevice::NewL(iAuthPckg().iBDAddr); |
|
1189 iDevice->SetDeviceNameL(BTDeviceNameConverter::ToUTF8L(name)); |
|
1190 |
|
1191 iGetAuthFromConsole = CBTGetAuthFromConsole::NewL(this, *iDevice, iAuthPckg().iUid); |
|
1192 iGetAuthFromConsole->AuthoriseL(); |
|
1193 } |
|
1194 } |
|
1195 |
|
1196 void CBTManAuthNotifierEngine::RunL() |
|
1197 { |
|
1198 LOG_FUNC |
|
1199 if (iStatus >= KErrNone) |
|
1200 { |
|
1201 switch (iRegistryState) |
|
1202 { |
|
1203 case EFinding: |
|
1204 { |
|
1205 // search has completed, get the resultset |
|
1206 FLOG(_L("RNot\tCBTManAuthNotifier: Found device")) |
|
1207 iResponse = CBTRegistryResponse::NewL(iRegistryView); |
|
1208 iResponse->Start(iStatus); |
|
1209 iRegistryState = EGetting; |
|
1210 SetActive(); |
|
1211 } |
|
1212 break; |
|
1213 case EGetting: |
|
1214 { |
|
1215 // got the details, now launch the authorisor console |
|
1216 FLOG(_L("RNot\tCBTManAuthNotifier: Got device details")) |
|
1217 iGetAuthFromConsole = CBTGetAuthFromConsole::NewL(this, *(iResponse->Results()[0]), iAuthPckg().iUid); |
|
1218 iGetAuthFromConsole->AuthoriseL(); |
|
1219 delete iResponse; |
|
1220 iResponse = NULL; |
|
1221 } |
|
1222 break; |
|
1223 } |
|
1224 } |
|
1225 else if (iStatus == KErrNotFound) |
|
1226 { |
|
1227 __ASSERT_DEBUG(iRegistryState == EFinding, User::Invariant()); |
|
1228 FLOG(_L("RNot\tCBTManAuthNotifier: Device not in Registry (OK)")) |
|
1229 // not to worry - the device isn't in the Registry |
|
1230 // although strictly speaking we should only Authorise an Authenticated device |
|
1231 // which means it *should* be in the Registry. |
|
1232 // however we do allow authorisation of unauthenticated devices at BT level |
|
1233 |
|
1234 // so we don't have a name at this point, but not to worry |
|
1235 CBTDevice* device = CBTDevice::NewLC(iAuthPckg().iBDAddr); |
|
1236 iGetAuthFromConsole = CBTGetAuthFromConsole::NewL(this, *device, iAuthPckg().iUid); |
|
1237 iGetAuthFromConsole->AuthoriseL(); |
|
1238 CleanupStack::PopAndDestroy(device); |
|
1239 } |
|
1240 else |
|
1241 { |
|
1242 User::Invariant(); |
|
1243 } |
|
1244 } |
|
1245 |
|
1246 |
|
1247 //------------------------------------------------------------------------// |
|
1248 //Get Auth from a console window class |
|
1249 //------------------------------------------------------------------------// |
|
1250 |
|
1251 |
|
1252 CBTGetAuthFromConsole* CBTGetAuthFromConsole::NewL(CBTManAuthNotifierEngine* aParent, |
|
1253 const CBTDevice& aDevice, TUid aUid) |
|
1254 { |
|
1255 LOG_STATIC_FUNC |
|
1256 CBTGetAuthFromConsole* s = CBTGetAuthFromConsole::NewLC(aParent, aDevice, aUid); |
|
1257 CleanupStack::Pop(); |
|
1258 return s; |
|
1259 } |
|
1260 |
|
1261 CBTGetAuthFromConsole* CBTGetAuthFromConsole::NewLC(CBTManAuthNotifierEngine* aParent, |
|
1262 const CBTDevice& aDevice, TUid aUid) |
|
1263 { |
|
1264 LOG_STATIC_FUNC |
|
1265 CBTGetAuthFromConsole* s = new(ELeave) CBTGetAuthFromConsole(aParent); |
|
1266 CleanupStack::PushL(s); |
|
1267 s->ConstructL(aDevice, aUid); |
|
1268 return s; |
|
1269 } |
|
1270 |
|
1271 CBTGetAuthFromConsole::~CBTGetAuthFromConsole() |
|
1272 { |
|
1273 LOG_FUNC |
|
1274 Cancel(); |
|
1275 delete iConsole; |
|
1276 #ifdef __BT_TEXT_NOTIFIERS_AUTO__ |
|
1277 delete iAutoNotifierCallback; |
|
1278 #endif |
|
1279 } |
|
1280 |
|
1281 void CBTGetAuthFromConsole::RunL() |
|
1282 { |
|
1283 LOG_FUNC |
|
1284 #ifdef __BT_TEXT_NOTIFIERS_AUTO__ |
|
1285 |
|
1286 iParent->AuthorisationComplete(ETrue, KErrNone); |
|
1287 |
|
1288 #else // __BT_TEXT_NOTIFIERS_AUTO__ |
|
1289 |
|
1290 TKeyCode key = iConsole->KeyCode(); |
|
1291 if (key == 'y') |
|
1292 { |
|
1293 iParent->AuthorisationComplete(ETrue, KErrNone); |
|
1294 } |
|
1295 else if (key == 'n') |
|
1296 { |
|
1297 iParent->AuthorisationComplete(EFalse, KErrNone); |
|
1298 } |
|
1299 else |
|
1300 { |
|
1301 iConsole->Printf(_L("\nStop being a muppet and press 'y' or 'n'\n")); |
|
1302 IssueRequest(); |
|
1303 } |
|
1304 #endif // __BT_TEXT_NOTIFIERS_AUTO__ |
|
1305 } |
|
1306 |
|
1307 void CBTGetAuthFromConsole::DoCancel() |
|
1308 { |
|
1309 LOG_FUNC |
|
1310 #ifdef __BT_TEXT_NOTIFIERS_AUTO__ |
|
1311 FLOG(_L("RNot\tCBTGetAuthFromConsole::DoCancel()")) |
|
1312 iConsole->ReadCancel(); |
|
1313 #endif |
|
1314 } |
|
1315 |
|
1316 CBTGetAuthFromConsole::CBTGetAuthFromConsole(CBTManAuthNotifierEngine* aParent) : |
|
1317 CActive(EPriorityStandard), iParent(aParent) |
|
1318 { |
|
1319 LOG_FUNC |
|
1320 CActiveScheduler::Add(this); |
|
1321 } |
|
1322 |
|
1323 void CBTGetAuthFromConsole::ConstructL(const CBTDevice& aDevice, TUid aUid) |
|
1324 { |
|
1325 LOG_FUNC |
|
1326 iConsole = BTTextNotifiersConsole::AutoSizeNewL(_L("Authorisor"), TSize(KConsFullScreen,KConsFullScreen)); |
|
1327 iDevice = &aDevice; |
|
1328 iServiceUid = aUid; |
|
1329 |
|
1330 #ifdef __BT_TEXT_NOTIFIERS_AUTO__ |
|
1331 TCallBack autoNotifierCB(AutoNotifierCallBack, this); |
|
1332 iAutoNotifierCallback = new (ELeave)CAsyncCallBack(autoNotifierCB, EActiveMedPriority); |
|
1333 #endif // __BT_TEXT_NOTIFIERS_AUTO__ |
|
1334 } |
|
1335 |
|
1336 void CBTGetAuthFromConsole::AuthoriseL() |
|
1337 { |
|
1338 LOG_FUNC |
|
1339 iConsole->ClearScreen(); |
|
1340 iConsole->Printf(_L("Can the following device:\nAddress: ")); |
|
1341 TBTDevAddr a = iDevice->BDAddr(); |
|
1342 iConsole->Printf(_L("0x%02x%02x%02x%02x%02x%02x"), a[0], a[1], a[2], a[3], a[4], a[5]); |
|
1343 if (iDevice->IsValidDeviceName()) |
|
1344 { |
|
1345 iConsole->Printf(_L("\nName: ")); |
|
1346 THostName dispBuf; |
|
1347 dispBuf.Copy(iDevice->DeviceName()); |
|
1348 iConsole->Printf(dispBuf); |
|
1349 } |
|
1350 else |
|
1351 { |
|
1352 iConsole->Printf(_L("\n<No name>")); |
|
1353 } |
|
1354 iConsole->Printf(_L("\nuse the following service\nService Uid = 0x%08x\n[y/n]"), iServiceUid.iUid); |
|
1355 IssueRequest(); |
|
1356 } |
|
1357 |
|
1358 void CBTGetAuthFromConsole::IssueRequest() |
|
1359 { |
|
1360 LOG_FUNC |
|
1361 #ifdef __BT_TEXT_NOTIFIERS_AUTO__ |
|
1362 iAutoNotifierCallback->CallBack(); |
|
1363 iStatus = KRequestPending; |
|
1364 #else //__BT_TEXT_NOTIFIERS_AUTO__ |
|
1365 iConsole->Read(iStatus); |
|
1366 #endif // __BT_TEXT_NOTIFIERS_AUTO__ |
|
1367 |
|
1368 SetActive(); |
|
1369 } |
|
1370 |
|
1371 #ifdef __BT_TEXT_NOTIFIERS_AUTO__ |
|
1372 /*static*/ TInt CBTGetAuthFromConsole::AutoNotifierCallBack(TAny *aConsoleAuth) |
|
1373 { |
|
1374 LOG_STATIC_FUNC |
|
1375 CBTGetAuthFromConsole* consoleAuth = static_cast<CBTGetAuthFromConsole*>(aConsoleAuth); |
|
1376 if(consoleAuth->IsActive()) |
|
1377 { |
|
1378 TRequestStatus* stat = &(consoleAuth->iStatus); |
|
1379 User::RequestComplete(stat, KErrNone); |
|
1380 } |
|
1381 return EFalse; |
|
1382 } |
|
1383 #endif // __BT_TEXT_NOTIFIERS_AUTO__ |
|
1384 |
|
1385 void CBTGetAuthFromConsole::DeviceNameRetrieved(const TDesC& aName, TInt aResult) |
|
1386 { |
|
1387 LOG_FUNC |
|
1388 iConsole->Printf(_L("\nDevice Name Retrieved (code %d): "), aResult); |
|
1389 iConsole->Printf(aName); |
|
1390 iConsole->Printf(_L("\n")); |
|
1391 } |
|
1392 |
|
1393 |
|
1394 |
|
1395 // |
|
1396 // CBTManDeviceSelectionNotifier |
|
1397 // |
|
1398 |
|
1399 void CBTManDeviceSelectionNotifier::Release() |
|
1400 { |
|
1401 LOG_FUNC |
|
1402 delete this; |
|
1403 } |
|
1404 |
|
1405 CBTManDeviceSelectionNotifier::TNotifierInfo CBTManDeviceSelectionNotifier::RegisterL() |
|
1406 { |
|
1407 LOG_FUNC |
|
1408 iInfo.iUid=KDeviceSelectionNotifierUid; |
|
1409 iInfo.iChannel=KScreenOutputChannel; |
|
1410 iInfo.iPriority=ENotifierPriorityVLow; |
|
1411 |
|
1412 return iInfo; |
|
1413 } |
|
1414 |
|
1415 CBTManDeviceSelectionNotifier::TNotifierInfo CBTManDeviceSelectionNotifier::Info() const |
|
1416 { |
|
1417 LOG_FUNC |
|
1418 return iInfo; |
|
1419 } |
|
1420 |
|
1421 |
|
1422 TPtrC8 CBTManDeviceSelectionNotifier::StartL(const TDesC8& /*aBuffer*/) |
|
1423 { |
|
1424 LOG_FUNC |
|
1425 LOG(_L("The synchronous StartL overload is not used.")) |
|
1426 LEAVEL(KErrNotSupported); |
|
1427 return KNullDesC8(); |
|
1428 } |
|
1429 |
|
1430 void CBTManDeviceSelectionNotifier::StartL(const TDesC8& /*aBuffer*/, TInt aReplySlot, const RMessagePtr2& aMessage) |
|
1431 { |
|
1432 LOG_FUNC |
|
1433 |
|
1434 CBTManDeviceScanner* scanner = CBTManDeviceScanner::NewL(); |
|
1435 CleanupStack::PushL(scanner); |
|
1436 TKeyCode choice = GetResponseL(_L("Press 'm' to enter a devaddr,\nANY OTHER KEY for general inquiry \nfor discoverable devices."), KConsFullScreen, 3); |
|
1437 TInt err = 0; |
|
1438 TBTDeviceResponseParamsPckg pckg; |
|
1439 |
|
1440 if(choice=='m'||choice=='M') |
|
1441 { |
|
1442 TRAP(err, GetAddressL(iBDAddr)); |
|
1443 } |
|
1444 else |
|
1445 { |
|
1446 TRAP(err, scanner->GetByScanL(iBDAddr, iName, iClass)); |
|
1447 } |
|
1448 |
|
1449 if(err) |
|
1450 { |
|
1451 DisplayErrorMessageL(); |
|
1452 } |
|
1453 else |
|
1454 { |
|
1455 pckg().SetDeviceAddress(iBDAddr); |
|
1456 // pckg().SetDeviceName(iName); |
|
1457 pckg().SetDeviceClass(iClass); |
|
1458 /*TInt err = */aMessage.Write(aReplySlot, pckg); |
|
1459 } |
|
1460 aMessage.Complete(err); |
|
1461 CleanupStack::PopAndDestroy(); |
|
1462 return; |
|
1463 } |
|
1464 |
|
1465 |
|
1466 |
|
1467 CBTManDeviceSelectionNotifier::~CBTManDeviceSelectionNotifier() |
|
1468 { |
|
1469 LOG_FUNC |
|
1470 } |
|
1471 |
|
1472 void CBTManDeviceSelectionNotifier::Cancel() |
|
1473 { |
|
1474 LOG_FUNC |
|
1475 } |
|
1476 |
|
1477 TPtrC8 CBTManDeviceSelectionNotifier::UpdateL(const TDesC8& /*aBuffer*/) |
|
1478 { |
|
1479 LOG_FUNC |
|
1480 LOG(_L("The UpdateL is not supported.")) |
|
1481 LEAVEL(KErrNotSupported); |
|
1482 return KNullDesC8(); |
|
1483 } |
|
1484 |
|
1485 CBTManDeviceSelectionNotifier* CBTManDeviceSelectionNotifier::NewLC() |
|
1486 { |
|
1487 LOG_STATIC_FUNC |
|
1488 CBTManDeviceSelectionNotifier* self=new (ELeave) CBTManDeviceSelectionNotifier(); |
|
1489 CleanupStack::PushL(self); |
|
1490 self->ConstructL(); |
|
1491 return self; |
|
1492 } |
|
1493 |
|
1494 CBTManDeviceSelectionNotifier::CBTManDeviceSelectionNotifier() |
|
1495 { |
|
1496 LOG_FUNC |
|
1497 } |
|
1498 |
|
1499 void CBTManDeviceSelectionNotifier::ConstructL() |
|
1500 { |
|
1501 LOG_FUNC |
|
1502 } |
|
1503 |
|
1504 TKeyCode CBTManDeviceSelectionNotifier::GetResponseL(TRefByValue<const TDesC> aPrompt, TInt aWidth, TInt aHeight) |
|
1505 { |
|
1506 LOG_FUNC |
|
1507 CConsoleBase* console = BTTextNotifiersConsole::AutoSizeNewL(_L("Device Selector"), TSize(aWidth,aHeight)); |
|
1508 CleanupStack::PushL(console); |
|
1509 console->Printf(aPrompt); |
|
1510 TKeyCode ret = console->Getch(); |
|
1511 CleanupStack::PopAndDestroy(); |
|
1512 return ret; |
|
1513 } |
|
1514 |
|
1515 |
|
1516 void CBTManDeviceSelectionNotifier::GetAddressL(TBTDevAddr& aBDAddr) |
|
1517 { |
|
1518 LOG_FUNC |
|
1519 TBuf<12> addrAsText; |
|
1520 addrAsText.Zero(); |
|
1521 if (aBDAddr != TBTDevAddr(0)) |
|
1522 addrAsText.Format(_L("%02x%02x%02x%02x%02x%02x"), |
|
1523 aBDAddr[0], aBDAddr[1], aBDAddr[2], aBDAddr[3], aBDAddr[4], aBDAddr[5]); |
|
1524 CConsoleBase* console = BTTextNotifiersConsole::AutoSizeNewL(_L("Device Selector"), TSize(KConsFullScreen,6)); |
|
1525 CleanupStack::PushL(console); |
|
1526 |
|
1527 TKeyCode code; |
|
1528 TBuf<1> character; |
|
1529 console->Printf(_L("Enter a device address:\n\n 0x")); |
|
1530 if (addrAsText.Length()>0) |
|
1531 console->Printf(addrAsText); |
|
1532 FOREVER |
|
1533 { |
|
1534 code = console->Getch(); |
|
1535 character.SetLength(0); |
|
1536 character.Append(code); |
|
1537 |
|
1538 // If <CR> finish editing string |
|
1539 if (code == 0x0d) |
|
1540 break; |
|
1541 |
|
1542 // if <BS> remove last character |
|
1543 if ((code == 0x08)&&(addrAsText.Length() != 0)) |
|
1544 { |
|
1545 console->Printf(_L("%S"),&character); |
|
1546 addrAsText.SetLength((addrAsText.Length()-1)); |
|
1547 } |
|
1548 else |
|
1549 { |
|
1550 if (addrAsText.Length() < addrAsText.MaxLength()) |
|
1551 { |
|
1552 console->Printf(_L("%S"),&character); |
|
1553 addrAsText.Append(code); |
|
1554 } |
|
1555 } |
|
1556 } |
|
1557 //now extract the new address from the string... |
|
1558 if(!(addrAsText.Length())) |
|
1559 addrAsText.Append('0'); //null string causes TLex::Val to return an error |
|
1560 TLex lex(addrAsText); |
|
1561 TInt64 addrAsInt64 = 0; |
|
1562 TInt err = lex.Val(addrAsInt64, EHex); |
|
1563 User::LeaveIfError(err); |
|
1564 aBDAddr = TBTDevAddr(addrAsInt64); |
|
1565 CleanupStack::PopAndDestroy();//console |
|
1566 } |
|
1567 |
|
1568 void CBTManDeviceSelectionNotifier::GetNameL(TBTDeviceName& aName) |
|
1569 { |
|
1570 LOG_FUNC |
|
1571 CConsoleBase* console = BTTextNotifiersConsole::AutoSizeNewL(_L("Device Selector"), TSize(KConsFullScreen,6)); |
|
1572 CleanupStack::PushL(console); |
|
1573 |
|
1574 TKeyCode code; |
|
1575 TBuf<1> character; |
|
1576 console->Printf(_L("Enter a device name:\n\n ")); |
|
1577 if (aName.Length()>0) |
|
1578 { |
|
1579 THostName dispBuf; |
|
1580 dispBuf.Copy(aName); |
|
1581 console->Printf(dispBuf); |
|
1582 } |
|
1583 FOREVER |
|
1584 { |
|
1585 code = console->Getch(); |
|
1586 character.SetLength(0); |
|
1587 character.Append(code); |
|
1588 |
|
1589 // If <CR> finish editing string |
|
1590 if (code == 0x0d) |
|
1591 break; |
|
1592 |
|
1593 // if <BS> remove last character |
|
1594 if ((code == 0x08)&&(aName.Length() != 0)) |
|
1595 { |
|
1596 console->Printf(_L("%S"),&character); |
|
1597 aName.SetLength((aName.Length()-1)); |
|
1598 } |
|
1599 else |
|
1600 { |
|
1601 if (aName.Length() < aName.MaxLength()) |
|
1602 { |
|
1603 console->Printf(_L("%S"),&character); |
|
1604 aName.Append(code); |
|
1605 } |
|
1606 } |
|
1607 } |
|
1608 CleanupStack::PopAndDestroy();//console |
|
1609 } |
|
1610 |
|
1611 void CBTManDeviceSelectionNotifier::DisplayErrorMessageL() |
|
1612 { |
|
1613 LOG_FUNC |
|
1614 CConsoleBase* console = 0; |
|
1615 TRAPD(err, console = BTTextNotifiersConsole::AutoSizeNewL(_L("Error!"), TSize(KConsFullScreen,4))); |
|
1616 if(err) |
|
1617 return; |
|
1618 CleanupStack::PushL(console); |
|
1619 |
|
1620 // console->Printf(_L("Sorry! An error has occurred whilst the last\npiece of data was being entered.\n\nPress any key, and then re-enter ALL data.")); |
|
1621 console->Printf(_L("Sorry! An error has occurred. No new device\nselection has been recorded.\n\nPress any key.")); |
|
1622 // TKeyCode code; |
|
1623 (void) console->Getch(); |
|
1624 CleanupStack::PopAndDestroy();//console |
|
1625 } |
|
1626 |
|
1627 |
|
1628 |
|
1629 |
|
1630 // | | |
|
1631 // | Secure Simple Pairing Notifiers | |
|
1632 // v v |
|
1633 |
|
1634 #ifndef __BT_TEXT_NOTIFIERS_NO_SSP__ |
|
1635 |
|
1636 |
|
1637 CBTUINumericComparison* CBTUINumericComparison::NewLC() |
|
1638 { |
|
1639 LOG_STATIC_FUNC |
|
1640 CBTUINumericComparison* self=new (ELeave) CBTUINumericComparison(); |
|
1641 CleanupStack::PushL(self); |
|
1642 self->ConstructL(); |
|
1643 return self; |
|
1644 } |
|
1645 |
|
1646 void CBTUINumericComparison::ConstructL() |
|
1647 { |
|
1648 LOG_FUNC |
|
1649 iEngine = CBTUINumericComparisonEngine::NewL(*this); |
|
1650 } |
|
1651 |
|
1652 CBTUINumericComparison::~CBTUINumericComparison() |
|
1653 { |
|
1654 LOG_FUNC |
|
1655 delete iEngine; |
|
1656 } |
|
1657 |
|
1658 |
|
1659 void CBTUINumericComparison::Release() |
|
1660 { |
|
1661 LOG_FUNC |
|
1662 Cancel(); |
|
1663 delete this; |
|
1664 } |
|
1665 |
|
1666 CBTUINumericComparison::TNotifierInfo CBTUINumericComparison::RegisterL() |
|
1667 { |
|
1668 LOG_FUNC |
|
1669 iInfo.iUid=KBTNumericComparisonNotifierUid; |
|
1670 iInfo.iChannel=KScreenOutputChannel; |
|
1671 iInfo.iPriority=ENotifierPriorityVHigh; |
|
1672 return iInfo; |
|
1673 } |
|
1674 |
|
1675 CBTUINumericComparison::TNotifierInfo CBTUINumericComparison::Info() const |
|
1676 { |
|
1677 LOG_FUNC |
|
1678 return iInfo; |
|
1679 } |
|
1680 |
|
1681 |
|
1682 void CBTUINumericComparison::Cancel() |
|
1683 { |
|
1684 LOG_FUNC |
|
1685 |
|
1686 iEngine->Stop(); |
|
1687 |
|
1688 if (iNeedToCompleteMessage) |
|
1689 { |
|
1690 iMessage.Complete(KErrCancel); |
|
1691 iNeedToCompleteMessage = EFalse; |
|
1692 } |
|
1693 } |
|
1694 |
|
1695 TPtrC8 CBTUINumericComparison::UpdateL(const TDesC8& aBuffer) |
|
1696 { |
|
1697 LOG_FUNC |
|
1698 return iEngine->UpdateL(aBuffer); |
|
1699 } |
|
1700 |
|
1701 TPtrC8 CBTUINumericComparison::StartL(const TDesC8& /*aBuffer*/) |
|
1702 { |
|
1703 LOG_FUNC |
|
1704 LOG(_L("The synchronous StartL overload is not used.")) |
|
1705 LEAVEL(KErrNotSupported); |
|
1706 return KNullDesC8(); |
|
1707 } |
|
1708 |
|
1709 void CBTUINumericComparison::StartL(const TDesC8& aBuffer, TInt aReplySlot, const RMessagePtr2& aMessage) |
|
1710 { |
|
1711 LOG_FUNC |
|
1712 iReplySlot = aReplySlot; |
|
1713 iMessage = RMessage2(aMessage); |
|
1714 iNumericComparisonParamsPckg.Copy(aBuffer); |
|
1715 |
|
1716 iNeedToCompleteMessage = ETrue; |
|
1717 |
|
1718 TRAPD(err, iEngine->DoComparisonL(iNumericComparisonParamsPckg())); |
|
1719 if (err) |
|
1720 { |
|
1721 FLOG(_L("\t** TRAPD error - DoComparisonL() **")); |
|
1722 aMessage.Complete(err); |
|
1723 iNeedToCompleteMessage = EFalse; |
|
1724 User::Leave(err); |
|
1725 } |
|
1726 } |
|
1727 |
|
1728 void CBTUINumericComparison::NumericComparisonComplete(TBool aDecision, TInt aReason) |
|
1729 { |
|
1730 LOG_FUNC |
|
1731 if (aReason == KErrNone) |
|
1732 { |
|
1733 FTRACE(FPrint(_L("\tCBTUINumericComparison::NumericComparisonComplete(TBool=%d)"), aDecision)); |
|
1734 |
|
1735 TInt err = iMessage.Write(iReplySlot, TPckgC<TBool>(aDecision)); |
|
1736 |
|
1737 iMessage.Complete(err); |
|
1738 } |
|
1739 else |
|
1740 { |
|
1741 FTRACE(FPrint(_L("\tCBTUINumericComparison::NumericComparisonComplete(ERROR=%d)"), aReason)); |
|
1742 iMessage.Complete(aReason); |
|
1743 } |
|
1744 iNeedToCompleteMessage = EFalse; |
|
1745 } |
|
1746 |
|
1747 //------------------------------------------------------------------------// |
|
1748 // Do the numeric comparison... |
|
1749 //------------------------------------------------------------------------// |
|
1750 CBTUINumericComparisonEngine* CBTUINumericComparisonEngine::NewL(MBTGetNCResultFromConsoleObserver& aObserver) |
|
1751 { |
|
1752 LOG_STATIC_FUNC |
|
1753 CBTUINumericComparisonEngine* s = CBTUINumericComparisonEngine::NewLC(aObserver); |
|
1754 CleanupStack::Pop(); |
|
1755 return s; |
|
1756 } |
|
1757 |
|
1758 CBTUINumericComparisonEngine* CBTUINumericComparisonEngine::NewLC(MBTGetNCResultFromConsoleObserver& aObserver) |
|
1759 { |
|
1760 LOG_STATIC_FUNC |
|
1761 CBTUINumericComparisonEngine* s = new(ELeave) CBTUINumericComparisonEngine(aObserver); |
|
1762 CleanupStack::PushL(s); |
|
1763 s->ConstructL(); |
|
1764 return s; |
|
1765 } |
|
1766 |
|
1767 CBTUINumericComparisonEngine::CBTUINumericComparisonEngine(MBTGetNCResultFromConsoleObserver& aObserver) : |
|
1768 CActive(EPriorityStandard), iObserver(aObserver), iConsole(NULL) |
|
1769 { |
|
1770 LOG_FUNC |
|
1771 CActiveScheduler::Add(this); |
|
1772 } |
|
1773 |
|
1774 void CBTUINumericComparisonEngine::ConstructL() |
|
1775 { |
|
1776 LOG_FUNC |
|
1777 } |
|
1778 |
|
1779 CBTUINumericComparisonEngine::~CBTUINumericComparisonEngine() |
|
1780 { |
|
1781 LOG_FUNC |
|
1782 Cancel(); |
|
1783 delete iConsole; |
|
1784 } |
|
1785 |
|
1786 void CBTUINumericComparisonEngine::DoComparisonL(TBTNumericComparisonParams& aNumericComparisonParams) |
|
1787 { |
|
1788 LOG_FUNC |
|
1789 if(iConsole==NULL) |
|
1790 { |
|
1791 iConsole = BTTextNotifiersConsole::AutoSizeNewL(_L("Numeric Comparison"), TSize(KConsFullScreen,KConsFullScreen)); |
|
1792 } |
|
1793 iConsole->ClearScreen(); |
|
1794 if(aNumericComparisonParams.LocallyInitiated()) |
|
1795 { |
|
1796 iConsole->Printf(_L("\nLocally initiated Numeric Comparision \n")); |
|
1797 } |
|
1798 else |
|
1799 { |
|
1800 iConsole->Printf(_L("\nRemote initiated the Numeric Comparision \n")); |
|
1801 } |
|
1802 iConsole->Printf(_L("\nNumeric value to compare: %06d\n\n"), aNumericComparisonParams.NumericalValue()); |
|
1803 iConsole->Printf(_L("Numbers should be displayed on local and remote device.\n")); |
|
1804 switch(aNumericComparisonParams.ComparisonScenario()) |
|
1805 { |
|
1806 case TBTNumericComparisonParams::ERemoteCannotConfirm: |
|
1807 iConsole->Printf(_L("N.B. The remote device HOWEVER cannot receive input.\n")); |
|
1808 break; |
|
1809 case TBTNumericComparisonParams::ERemoteCanConfirm: |
|
1810 iConsole->Printf(_L("N.B. The remote device will ALSO expect input.\n")); |
|
1811 break; |
|
1812 default: |
|
1813 __ASSERT_DEBUG(EFalse, User::Panic(_L("CBTUINumericComparisonEngine"), KErrArgument)); |
|
1814 break; |
|
1815 } |
|
1816 iConsole->Printf(_L("Please compare the numbers now.\n")); |
|
1817 iConsole->Printf(_L("\n\nDo the numbers match?[y/n]")); |
|
1818 IssueRequest(); |
|
1819 } |
|
1820 |
|
1821 TPtrC8 CBTUINumericComparisonEngine::UpdateL(const TDesC8& /*aBuffer*/) |
|
1822 { |
|
1823 LOG_FUNC |
|
1824 // need something to update the name |
|
1825 return KNullDesC8(); |
|
1826 } |
|
1827 |
|
1828 void CBTUINumericComparisonEngine::Stop() |
|
1829 { |
|
1830 LOG_FUNC |
|
1831 Cancel(); |
|
1832 delete iConsole; |
|
1833 iConsole = NULL; |
|
1834 } |
|
1835 |
|
1836 void CBTUINumericComparisonEngine::IssueRequest() |
|
1837 { |
|
1838 LOG_FUNC |
|
1839 iConsole->Read(iStatus); |
|
1840 SetActive(); |
|
1841 } |
|
1842 |
|
1843 void CBTUINumericComparisonEngine::RunL() |
|
1844 { |
|
1845 LOG_FUNC |
|
1846 TKeyCode key = iConsole->KeyCode(); |
|
1847 if (key == 'y') |
|
1848 { |
|
1849 iObserver.NumericComparisonComplete(ETrue, KErrNone); |
|
1850 delete iConsole; |
|
1851 iConsole=NULL; |
|
1852 } |
|
1853 else if (key == 'n') |
|
1854 { |
|
1855 iObserver.NumericComparisonComplete(EFalse, KErrNone); |
|
1856 delete iConsole; |
|
1857 iConsole=NULL; |
|
1858 } |
|
1859 else |
|
1860 { |
|
1861 iConsole->Printf(_L("\nInvalid key pressed! Press 'y' or 'n'\n")); |
|
1862 IssueRequest(); |
|
1863 } |
|
1864 } |
|
1865 |
|
1866 void CBTUINumericComparisonEngine::DoCancel() |
|
1867 { |
|
1868 LOG_FUNC |
|
1869 if (iConsole) |
|
1870 { |
|
1871 iConsole->ReadCancel(); |
|
1872 } |
|
1873 } |
|
1874 |
|
1875 |
|
1876 // |
|
1877 // CBTUIPasskeyEntry |
|
1878 // |
|
1879 |
|
1880 CBTUIPasskeyEntry* CBTUIPasskeyEntry::NewLC() |
|
1881 { |
|
1882 LOG_STATIC_FUNC |
|
1883 CBTUIPasskeyEntry* self = new (ELeave) CBTUIPasskeyEntry(); |
|
1884 CleanupStack::PushL(self); |
|
1885 self->ConstructL(); |
|
1886 return self; |
|
1887 } |
|
1888 |
|
1889 void CBTUIPasskeyEntry::ConstructL() |
|
1890 { |
|
1891 LOG_FUNC |
|
1892 iEngine = CBTUIPasskeyEntryEngine::NewL(*this); |
|
1893 } |
|
1894 |
|
1895 CBTUIPasskeyEntry::~CBTUIPasskeyEntry() |
|
1896 { |
|
1897 LOG_FUNC |
|
1898 delete iEngine; |
|
1899 } |
|
1900 |
|
1901 |
|
1902 void CBTUIPasskeyEntry::Release() |
|
1903 { |
|
1904 LOG_FUNC |
|
1905 Cancel(); |
|
1906 delete this; |
|
1907 } |
|
1908 |
|
1909 CBTUIPasskeyEntry::TNotifierInfo CBTUIPasskeyEntry::RegisterL() |
|
1910 { |
|
1911 LOG_FUNC |
|
1912 iInfo.iUid=KBTPasskeyDisplayNotifierUid; |
|
1913 iInfo.iChannel=KScreenOutputChannel; |
|
1914 iInfo.iPriority=ENotifierPriorityVHigh; |
|
1915 return iInfo; |
|
1916 } |
|
1917 |
|
1918 CBTUIPasskeyEntry::TNotifierInfo CBTUIPasskeyEntry::Info() const |
|
1919 { |
|
1920 LOG_FUNC |
|
1921 return iInfo; |
|
1922 } |
|
1923 |
|
1924 |
|
1925 void CBTUIPasskeyEntry::Cancel() |
|
1926 { |
|
1927 LOG_FUNC |
|
1928 |
|
1929 iEngine->Stop(); |
|
1930 |
|
1931 if (iNeedToCompleteMessage) |
|
1932 { |
|
1933 iMessage.Complete(KErrCancel); |
|
1934 iNeedToCompleteMessage = EFalse; |
|
1935 } |
|
1936 } |
|
1937 |
|
1938 TPtrC8 CBTUIPasskeyEntry::UpdateL(const TDesC8& aBuffer) |
|
1939 { |
|
1940 LOG_FUNC |
|
1941 return iEngine->UpdateL(aBuffer); |
|
1942 } |
|
1943 |
|
1944 TPtrC8 CBTUIPasskeyEntry::StartL(const TDesC8& /*aBuffer*/) |
|
1945 { |
|
1946 LOG_FUNC |
|
1947 LOG(_L("The synchronous StartL overload is not used.")) |
|
1948 LEAVEL(KErrNotSupported); |
|
1949 return KNullDesC8(); |
|
1950 } |
|
1951 |
|
1952 void CBTUIPasskeyEntry::StartL(const TDesC8& aBuffer, TInt aReplySlot, const RMessagePtr2& aMessage) |
|
1953 { |
|
1954 LOG_FUNC |
|
1955 iReplySlot = aReplySlot; |
|
1956 iMessage = RMessage2(aMessage); |
|
1957 |
|
1958 iPasskeyDisplayParamsPckg.Copy(aBuffer); |
|
1959 iAddr = iPasskeyDisplayParamsPckg().DeviceAddress(); |
|
1960 iName = iPasskeyDisplayParamsPckg().DeviceName(); |
|
1961 iNumericValue = iPasskeyDisplayParamsPckg().NumericalValue(); |
|
1962 |
|
1963 iNeedToCompleteMessage = ETrue; |
|
1964 |
|
1965 TRAPD(err, iEngine->DoPasskeyL(iPasskeyDisplayParamsPckg())); |
|
1966 if (err) |
|
1967 { |
|
1968 FLOG(_L("\t** TRAPD error - DoComparisonL() **")); |
|
1969 aMessage.Complete(err); |
|
1970 iNeedToCompleteMessage = EFalse; |
|
1971 User::Leave(err); |
|
1972 } |
|
1973 } |
|
1974 |
|
1975 void CBTUIPasskeyEntry::PasskeyComplete(TInt aReason) |
|
1976 { |
|
1977 LOG_FUNC |
|
1978 LOG1(_L("\taReason = %d"), aReason) |
|
1979 iMessage.Complete(aReason); |
|
1980 iNeedToCompleteMessage = EFalse; |
|
1981 } |
|
1982 |
|
1983 |
|
1984 // |
|
1985 // CBTUIPasskeyEntryEngine |
|
1986 // |
|
1987 |
|
1988 CBTUIPasskeyEntryEngine* CBTUIPasskeyEntryEngine::NewL(MBTGetPasskeyResultFromConsoleObserver& aObserver) |
|
1989 { |
|
1990 LOG_STATIC_FUNC |
|
1991 CBTUIPasskeyEntryEngine* s = CBTUIPasskeyEntryEngine::NewLC(aObserver); |
|
1992 CleanupStack::Pop(); |
|
1993 return s; |
|
1994 } |
|
1995 |
|
1996 CBTUIPasskeyEntryEngine* CBTUIPasskeyEntryEngine::NewLC(MBTGetPasskeyResultFromConsoleObserver& aObserver) |
|
1997 { |
|
1998 LOG_STATIC_FUNC |
|
1999 CBTUIPasskeyEntryEngine* s = new(ELeave) CBTUIPasskeyEntryEngine(aObserver); |
|
2000 CleanupStack::PushL(s); |
|
2001 s->ConstructL(); |
|
2002 return s; |
|
2003 } |
|
2004 |
|
2005 CBTUIPasskeyEntryEngine::CBTUIPasskeyEntryEngine(MBTGetPasskeyResultFromConsoleObserver& aObserver) : |
|
2006 CActive(EPriorityStandard), iObserver(aObserver), iConsole(NULL) |
|
2007 { |
|
2008 LOG_FUNC |
|
2009 CActiveScheduler::Add(this); |
|
2010 } |
|
2011 |
|
2012 void CBTUIPasskeyEntryEngine::ConstructL() |
|
2013 { |
|
2014 LOG_FUNC |
|
2015 } |
|
2016 |
|
2017 CBTUIPasskeyEntryEngine::~CBTUIPasskeyEntryEngine() |
|
2018 { |
|
2019 LOG_FUNC |
|
2020 Cancel(); |
|
2021 delete iConsole; |
|
2022 } |
|
2023 |
|
2024 void CBTUIPasskeyEntryEngine::DoPasskeyL(TBTPasskeyDisplayParams& aPasskeyParams) |
|
2025 { |
|
2026 LOG_FUNC |
|
2027 if(iConsole==NULL) |
|
2028 { |
|
2029 iConsole = BTTextNotifiersConsole::AutoSizeNewL(_L("Numeric Comparison"), TSize(KConsFullScreen,KConsFullScreen)); |
|
2030 } |
|
2031 |
|
2032 if(aPasskeyParams.LocallyInitiated()) |
|
2033 { |
|
2034 iConsole->Printf(_L("\nLocally initiated Authentication \n")); |
|
2035 } |
|
2036 else |
|
2037 { |
|
2038 iConsole->Printf(_L("\nRemote initiated the Authentication \n")); |
|
2039 } |
|
2040 iConsole->ClearScreen(); |
|
2041 iConsole->Printf(_L("\nEnter the following number on the remote device: %06d\n\n"), aPasskeyParams.NumericalValue()); |
|
2042 iConsole->Printf(_L("Press [ESC] to cancel.\n")); |
|
2043 IssueRequest(); |
|
2044 } |
|
2045 |
|
2046 TPtrC8 CBTUIPasskeyEntryEngine::UpdateL(const TDesC8& aBuffer) |
|
2047 { |
|
2048 LOG_FUNC |
|
2049 |
|
2050 TBTNotifierUpdateParamsPckg2 pckgRaw; |
|
2051 pckgRaw.Copy(aBuffer.Left(pckgRaw.MaxLength())); |
|
2052 |
|
2053 if (iConsole) |
|
2054 { |
|
2055 if (pckgRaw().Type() == TBTNotifierUpdateParams2::EPasskeyDisplay) |
|
2056 { |
|
2057 TBTPasskeyDisplayUpdateParamsPckg pckg; |
|
2058 pckg.Copy(aBuffer); |
|
2059 THCIPasskeyEntryNotificationType keypressNotification = pckg().KeypressNotification(); |
|
2060 switch (keypressNotification) |
|
2061 { |
|
2062 case EPasskeyEntryStarted: |
|
2063 { |
|
2064 break; |
|
2065 } |
|
2066 case EPasskeyDigitEntered: |
|
2067 { |
|
2068 iConsole->Write(_L("*")); |
|
2069 break; |
|
2070 } |
|
2071 case EPasskeyDigitDeleted: |
|
2072 { |
|
2073 TInt xPos = iConsole->WhereX(); |
|
2074 if (xPos > 0) |
|
2075 { |
|
2076 iConsole->SetPos(xPos - 1); |
|
2077 } |
|
2078 iConsole->ClearToEndOfLine(); |
|
2079 break; |
|
2080 } |
|
2081 case EPasskeyCleared: |
|
2082 { |
|
2083 iConsole->SetPos(0); |
|
2084 iConsole->ClearToEndOfLine(); |
|
2085 break; |
|
2086 } |
|
2087 case EPasskeyEntryCompleted: |
|
2088 { |
|
2089 Cancel(); |
|
2090 iObserver.PasskeyComplete(KErrNone); |
|
2091 delete iConsole; |
|
2092 iConsole=NULL; |
|
2093 break; |
|
2094 } |
|
2095 } |
|
2096 } |
|
2097 else if(pckgRaw().Type() == TBTNotifierUpdateParams2::EDeviceName) |
|
2098 { |
|
2099 // handle the name update |
|
2100 } |
|
2101 } |
|
2102 return KNullDesC8(); |
|
2103 } |
|
2104 |
|
2105 void CBTUIPasskeyEntryEngine::Stop() |
|
2106 { |
|
2107 LOG_FUNC |
|
2108 Cancel(); |
|
2109 delete iConsole; |
|
2110 iConsole=NULL; |
|
2111 } |
|
2112 |
|
2113 void CBTUIPasskeyEntryEngine::IssueRequest() |
|
2114 { |
|
2115 LOG_FUNC |
|
2116 iConsole->Read(iStatus); |
|
2117 SetActive(); |
|
2118 } |
|
2119 |
|
2120 void CBTUIPasskeyEntryEngine::RunL() |
|
2121 { |
|
2122 LOG_FUNC |
|
2123 TKeyCode key = iConsole->KeyCode(); |
|
2124 if (key == EKeyEscape) |
|
2125 { |
|
2126 iObserver.PasskeyComplete(KErrCancel); |
|
2127 delete iConsole; |
|
2128 iConsole=NULL; |
|
2129 } |
|
2130 else |
|
2131 { |
|
2132 IssueRequest(); |
|
2133 } |
|
2134 } |
|
2135 |
|
2136 void CBTUIPasskeyEntryEngine::DoCancel() |
|
2137 { |
|
2138 LOG_FUNC |
|
2139 if (iConsole) |
|
2140 { |
|
2141 iConsole->ReadCancel(); |
|
2142 } |
|
2143 } |
|
2144 |
|
2145 |
|
2146 #endif // __BT_TEXT_NOTIFIERS_NO_SSP__ |