20 #include <btextnotifiers.h> |
20 #include <btextnotifiers.h> |
21 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS |
21 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS |
22 #include <btextnotifierspartner.h> |
22 #include <btextnotifierspartner.h> |
23 #endif |
23 #endif |
24 #include "btnotifconnectiontracker.h" |
24 #include "btnotifconnectiontracker.h" |
25 #include "btnotifpairingmanager.h" |
25 #include "btnotifsecuritymanager.h" |
26 #include "btnotificationmanager.h" |
26 #include "btnotificationmanager.h" |
27 #include "bluetoothnotification.h" |
27 #include "bluetoothnotification.h" |
28 #include "btnotifserver.h" |
28 #include "btnotifserver.h" |
29 #include "bluetoothtrace.h" |
29 #include "bluetoothtrace.h" |
30 |
30 |
58 // --------------------------------------------------------------------------- |
58 // --------------------------------------------------------------------------- |
59 // NewL |
59 // NewL |
60 // --------------------------------------------------------------------------- |
60 // --------------------------------------------------------------------------- |
61 // |
61 // |
62 CBTNotifPairNotifier* CBTNotifPairNotifier::NewL( |
62 CBTNotifPairNotifier* CBTNotifPairNotifier::NewL( |
63 CBTNotifPairingManager& aParent ) |
63 CBTNotifSecurityManager& aParent ) |
64 { |
64 { |
65 BOstraceFunctionEntry0( DUMMY_DEVLIST ); |
65 BOstraceFunctionEntry0( DUMMY_DEVLIST ); |
66 CBTNotifPairNotifier* self = new( ELeave ) CBTNotifPairNotifier( aParent ); |
66 CBTNotifPairNotifier* self = new( ELeave ) CBTNotifPairNotifier( aParent ); |
67 CleanupStack::PushL( self ); |
67 CleanupStack::PushL( self ); |
68 self->ConstructL(); |
68 self->ConstructL(); |
100 // |
100 // |
101 void CBTNotifPairNotifier::StartPairingNotifierL(const RMessage2& aMessage ) |
101 void CBTNotifPairNotifier::StartPairingNotifierL(const RMessage2& aMessage ) |
102 { |
102 { |
103 BOstraceFunctionEntry0( DUMMY_DEVLIST ); |
103 BOstraceFunctionEntry0( DUMMY_DEVLIST ); |
104 |
104 |
105 // todo: move Authorize notifier to a separate class |
|
106 TInt uid = aMessage.Int0(); |
105 TInt uid = aMessage.Int0(); |
107 if ( KBTManAuthNotifierUid.iUid == uid ) |
106 TInt opCode = aMessage.Function(); |
108 { |
107 BOstrace1(TRACE_DEBUG,DUMMY_DEVLIST,"[BTNotif]:Opcode: %d",opCode); |
109 TPckgBuf<TBool> answer; |
108 |
110 answer() = ETrue; |
109 if ( (!iNotifierMessage.IsNull()) && |
111 TInt err = aMessage.Write( EBTNotifSrvReplySlot, answer); |
110 (opCode != EBTNotifCancelNotifier )&&(opCode != EBTNotifUpdateNotifier)) |
112 aMessage.Complete( KErrNone ); |
111 { |
|
112 // todo: do we allow concurrent pairing? |
|
113 BOstrace0(TRACE_DEBUG,DUMMY_DEVLIST,"[BTNotif]:We are busy"); |
|
114 User::Leave(KErrServerBusy ); |
|
115 } |
|
116 |
|
117 if(opCode == EBTNotifCancelNotifier){ |
|
118 CancelPairingNotifierL(uid); |
|
119 aMessage.Complete(KErrNone); |
113 return; |
120 return; |
114 } |
121 } |
115 |
|
116 //BOstraceFunctionEntryExt( DUMMY_DEVLIST, this, aUid ); |
|
117 if ( !iNotifierMessage.IsNull() ) |
|
118 { |
|
119 // todo: do we allow concurrent pairing? |
|
120 User::Leave(KErrServerBusy ); |
|
121 } |
|
122 |
122 |
123 // Store the parameters locally, we need them later again. |
123 // Store the parameters locally, we need them later again. |
124 iParams.CreateL( aMessage.GetDesLengthL( EBTNotifSrvParamSlot ) ); |
124 iParams.CreateL( aMessage.GetDesLengthL( EBTNotifSrvParamSlot ) ); |
125 aMessage.ReadL( EBTNotifSrvParamSlot, iParams ); |
125 aMessage.ReadL( EBTNotifSrvParamSlot, iParams ); |
126 iNotifierMessage = aMessage; |
126 iNotifierMessage = aMessage; |
127 |
127 |
128 // Read the notifier parameters |
128 // Read the notifier parameters |
129 ParseNotifierReqParamsL(); |
129 ParseNotifierReqParamsL(); |
|
130 |
|
131 if(opCode ==EBTNotifUpdateNotifier ){ |
|
132 UpdatePairingNotifierL(uid,iParams); |
|
133 aMessage.Complete(KErrNone); |
|
134 return; |
|
135 } |
130 |
136 |
131 const CBtDevExtension* dev = iParent.BTDevRepository().Device(iRemote); |
137 const CBtDevExtension* dev = iParent.BTDevRepository().Device(iRemote); |
132 if(dev) |
138 if(dev) |
133 { |
139 { |
134 if (!iLocallyInitiated && dev->Device().GlobalSecurity().Banned() ) |
140 if (!iLocallyInitiated && dev->Device().GlobalSecurity().Banned() ) |
135 { |
141 { |
136 // If the device is banned and pairing is not locally initiated |
142 // If the device is banned and pairing is not locally initiated |
137 // then we ignore. |
143 // then we reject. |
138 aMessage.Complete( KErrNone ); |
144 BOstrace0(TRACE_DEBUG,DUMMY_DEVLIST,"[BTNotif]:Device is banned"); |
|
145 iNotifierMessage.Complete( KErrCancel ); |
|
146 return; |
139 } |
147 } |
140 if (iLocallyInitiated && dev->Device().GlobalSecurity().Banned()) |
148 if (iLocallyInitiated && dev->Device().GlobalSecurity().Banned()) |
141 { |
149 { |
142 // Remove the banned device from the blocking history |
150 // Remove the banned device from the blocking history |
143 iParent.ConnectionTracker().UpdateBlockingHistoryL(&dev->Device(),ETrue); |
151 iParent.ConnectionTracker().UpdateBlockingHistoryL(&dev->Device(),ETrue); |
|
152 iParent.BlockDevice(dev->Addr(),EFalse); |
144 } |
153 } |
145 if(0 != dev->Device().FriendlyName().Length()&& dev->Device().IsValidFriendlyName()) |
154 if(0 != dev->Device().FriendlyName().Length()&& dev->Device().IsValidFriendlyName()) |
146 { |
155 { |
147 // If we have a friendly name use it for the UI |
156 // If we have a friendly name use it for the UI |
148 iCurrentDeviceName = dev->Device().FriendlyName(); |
157 iCurrentDeviceName = dev->Device().FriendlyName(); |
302 // --------------------------------------------------------------------------- |
312 // --------------------------------------------------------------------------- |
303 // |
313 // |
304 void CBTNotifPairNotifier::MBRDataReceived( CHbSymbianVariantMap& aData ) |
314 void CBTNotifPairNotifier::MBRDataReceived( CHbSymbianVariantMap& aData ) |
305 { |
315 { |
306 BOstraceFunctionEntry0( DUMMY_DEVLIST ); |
316 BOstraceFunctionEntry0( DUMMY_DEVLIST ); |
307 (void) aData; |
317 if(aData.Keys().MdcaPoint(0).Compare(_L("actionResult")) == 0) |
308 NOTIF_NOTIMPL |
318 { |
|
319 TInt val = *(static_cast<TInt*>(aData.Get(_L("actionResult"))->Data())); |
|
320 if(val) |
|
321 { |
|
322 iAcceptPairingResult = ETrue; |
|
323 } |
|
324 else |
|
325 { |
|
326 iAcceptPairingResult = EFalse; |
|
327 } |
|
328 } |
|
329 else if(aData.Keys().MdcaPoint(0).Compare(_L("checkBoxState")) == 0) |
|
330 { |
|
331 iCheckBoxState = *(static_cast<TInt*>(aData.Get(_L("checkBoxState"))->Data())); |
|
332 } |
309 BOstraceFunctionExit0( DUMMY_DEVLIST ); |
333 BOstraceFunctionExit0( DUMMY_DEVLIST ); |
310 } |
334 } |
311 |
335 |
312 // --------------------------------------------------------------------------- |
336 // --------------------------------------------------------------------------- |
313 // From class MBTNotificationResult. |
337 // From class MBTNotificationResult. |
316 // |
340 // |
317 void CBTNotifPairNotifier::MBRNotificationClosed( TInt aError, const TDesC8& aData ) |
341 void CBTNotifPairNotifier::MBRNotificationClosed( TInt aError, const TDesC8& aData ) |
318 { |
342 { |
319 BOstraceFunctionEntryExt( DUMMY_DEVLIST, this, aError ); |
343 BOstraceFunctionEntryExt( DUMMY_DEVLIST, this, aError ); |
320 // First unregister from the notification, so we can already get the next one. |
344 // First unregister from the notification, so we can already get the next one. |
321 //iNotification->RemoveObserver(); |
345 iNotification->RemoveObserver(); |
322 //iNotification = NULL; |
346 iNotification = NULL; |
323 TRAP_IGNORE( NotificationClosedL( aError, aData ) ); |
347 TRAP_IGNORE( NotificationClosedL( aError, aData ) ); |
324 iNotification = NULL; |
|
325 BOstraceFunctionExit1( DUMMY_DEVLIST, this ); |
348 BOstraceFunctionExit1( DUMMY_DEVLIST, this ); |
326 } |
349 } |
327 |
350 |
328 // --------------------------------------------------------------------------- |
351 // --------------------------------------------------------------------------- |
329 // Request a user input for the outstanding pairing request. |
352 // Request a user input for the outstanding pairing request. |
352 } |
375 } |
353 TInt err = aError; |
376 TInt err = aError; |
354 TPtrC8 resultData(KNullDesC8); |
377 TPtrC8 resultData(KNullDesC8); |
355 TBTPinCode pinCode; |
378 TBTPinCode pinCode; |
356 TPckgBuf<TBool> userAcceptance; |
379 TPckgBuf<TBool> userAcceptance; |
|
380 TInt uid = iNotifierMessage.Int0(); |
|
381 |
357 if( !err ) |
382 if( !err ) |
358 { |
383 { |
359 TInt uid = iNotifierMessage.Int0(); |
|
360 // The returned data is the entered passkey. |
384 // The returned data is the entered passkey. |
361 // const CBtDevExtension* dev = iParent.BTDevRepository().Device(iRemote); |
385 const CBtDevExtension* dev = iParent.BTDevRepository().Device(iRemote); |
362 // TBool proceed = iParent.ConnectionTracker().UpdateBlockingHistoryL(&dev->Device(),aResult); |
386 if(dev) |
363 if( uid == KBTNumericComparisonNotifierUid.iUid ) |
387 { |
|
388 iParent.ConnectionTracker().UpdateBlockingHistoryL(&dev->Device(),aResult); |
|
389 } |
|
390 if( uid == KBTNumericComparisonNotifierUid.iUid ) |
364 { |
391 { |
365 // Numeric comparison needs the boolean result passed back. |
392 // Numeric comparison needs the boolean result passed back. |
366 userAcceptance() = aResult; |
393 userAcceptance() = aResult; |
367 resultData.Set( userAcceptance ); |
394 resultData.Set( userAcceptance ); |
368 } |
395 } |
372 || uid == KBTPinCodeEntryNotifierUid.iUid ) |
399 || uid == KBTPinCodeEntryNotifierUid.iUid ) |
373 { |
400 { |
374 // Check the passkey entered by the user. |
401 // Check the passkey entered by the user. |
375 // The length of the returned data equals the number of characters |
402 // The length of the returned data equals the number of characters |
376 // entered by the user. |
403 // entered by the user. |
377 pinCode().iLength = aData.Length(); |
404 // Check that the passkey length do not exceed the maximum allowed size |
|
405 TInt pinCodeLength = aData.Length(); |
|
406 if(pinCodeLength > KHCIPINCodeSize) |
|
407 { |
|
408 pinCodeLength = KHCIPINCodeSize; |
|
409 } |
|
410 pinCode().iLength = pinCodeLength; |
378 // Check that the length of the passkey meets the minimum |
411 // Check that the length of the passkey meets the minimum |
379 // required pin code length |
412 // required pin code length |
380 if( aData.Length() >= iMinPinLength ) |
413 if( pinCodeLength >= iMinPinLength ) |
381 { |
414 { |
382 for( TInt i = 0; i < aData.Length(); i++ ) |
415 for( TInt i = 0; i < pinCodeLength; i++ ) |
383 { |
416 { |
384 pinCode().iPIN[i] = aData[i]; |
417 pinCode().iPIN[i] = aData[i]; |
385 } |
418 } |
386 resultData.Set( pinCode ); |
419 resultData.Set( pinCode ); |
387 } |
420 } |
388 else |
421 else |
389 { |
422 { |
390 // todo: PIN wasn't long enough. This should be handled by the dialog though. |
423 // shouldn't happen since the length is checked in the dialog |
391 err = KErrCompletion; |
424 err = KErrCompletion; |
392 } |
425 } |
393 } |
426 } |
394 } |
427 } |
395 else |
428 else |
396 { |
429 { |
397 err = KErrCancel; |
430 err = KErrCancel; |
398 if( iLocallyInitiated ) |
|
399 { |
|
400 // The user denied the connection, ask to block the device. |
|
401 // This is only for pairing (and not bonding) initiated by us, |
|
402 // as the user already gets the opportunity to block when |
|
403 // rejecting an incoming pairing request. |
|
404 // This case may be for someone requesting to access a service |
|
405 // which requires authentication by us, but not by the remote device. |
|
406 // if(proceed) |
|
407 // { |
|
408 // LaunchBlockingQueryL(); |
|
409 // } |
|
410 // For incoming pairing, blocking is asked after rejecting the |
|
411 // pairing request. This is done in CompleteAcceptPairingQueryL |
|
412 } |
|
413 } |
431 } |
414 } |
432 } |
415 // Complete the message with the result, and result data if any. |
433 // Complete the message with the result, and result data if any. |
416 if ( !err && resultData.Length() ) |
434 if ( !err && resultData.Length() ) |
417 { |
435 { |
418 err = iNotifierMessage.Write( EBTNotifSrvReplySlot, resultData ); |
436 err = iNotifierMessage.Write( EBTNotifSrvReplySlot, resultData ); |
419 } |
437 } |
|
438 if(err && (uid == KBTNumericComparisonNotifierUid.iUid)) |
|
439 { |
|
440 // We need to reject the numeric comparaison otherwise |
|
441 // the link will remain active |
|
442 userAcceptance() = aResult; |
|
443 resultData.Set( userAcceptance ); |
|
444 err = iNotifierMessage.Write( EBTNotifSrvReplySlot, resultData ); |
|
445 } |
420 iNotifierMessage.Complete( err ); |
446 iNotifierMessage.Complete( err ); |
421 BOstraceFunctionExit1( DUMMY_DEVLIST, this ); |
447 BOstraceFunctionExit1( DUMMY_DEVLIST, this ); |
422 } |
448 } |
423 |
449 |
424 // --------------------------------------------------------------------------- |
450 // --------------------------------------------------------------------------- |
426 // --------------------------------------------------------------------------- |
452 // --------------------------------------------------------------------------- |
427 // |
453 // |
428 void CBTNotifPairNotifier::StartAcceptPairingQueryL() |
454 void CBTNotifPairNotifier::StartAcceptPairingQueryL() |
429 { |
455 { |
430 BOstraceFunctionEntry0( DUMMY_DEVLIST ); |
456 BOstraceFunctionEntry0( DUMMY_DEVLIST ); |
431 PrepareNotificationL( TBluetoothDialogParams::EQuery, EIncomingPairing ); |
457 PrepareNotificationL( TBluetoothDialogParams::EUserAuthorization, EAuthorization ); |
432 iState = EIncomingPairingAcceptconfirm; |
458 iState = EIncomingPairingAcceptconfirm; |
433 // if rejected, the client message is completed in CompleteAcceptPairingQueryL |
459 // if rejected, the client message is completed in CompleteAcceptPairingQueryL |
434 BOstraceFunctionExit0( DUMMY_DEVLIST ); |
460 BOstraceFunctionExit0( DUMMY_DEVLIST ); |
435 } |
461 } |
436 |
462 |
437 // --------------------------------------------------------------------------- |
463 // --------------------------------------------------------------------------- |
438 // The user was asked to accept an incoming pairing. Process and proceed. |
464 // The user was asked to accept an incoming pairing. Process and proceed. |
439 // --------------------------------------------------------------------------- |
465 // --------------------------------------------------------------------------- |
440 // |
466 // |
441 void CBTNotifPairNotifier::CompleteAcceptPairingQueryL( TInt aError, TBool aResult ) |
467 void CBTNotifPairNotifier::CompleteAcceptPairingQueryL( TInt aError) |
442 { |
468 { |
443 BOstraceFunctionEntry0( DUMMY_DEVLIST ); |
469 BOstraceFunctionEntry0( DUMMY_DEVLIST ); |
444 TInt err = aError; |
470 TInt err = aError; |
|
471 TBool proceed = EFalse; |
|
472 |
445 if( !err ) |
473 if( !err ) |
446 { |
474 { |
447 // const CBtDevExtension* dev = iParent.BTDevRepository().Device(iRemote); |
475 const CBtDevExtension* dev = iParent.BTDevRepository().Device(iRemote); |
448 // TBool proceed = iParent.ConnectionTracker().UpdateBlockingHistoryL(&dev->Device(),aResult); |
476 if(dev) |
449 if( aResult ) |
477 { |
|
478 proceed = iParent.ConnectionTracker().UpdateBlockingHistoryL(&dev->Device(),iAcceptPairingResult); |
|
479 } |
|
480 if( iAcceptPairingResult ) |
450 { |
481 { |
451 // User accepted, continue to show pairing query. |
482 // User accepted, continue to show pairing query. |
|
483 // Trust the device |
|
484 if(iCheckBoxState){ |
|
485 iParent.TrustDevice(iRemote); |
|
486 } |
452 StartPairingUserInputL(); |
487 StartPairingUserInputL(); |
453 if( iDialogNumeric.Length() ) |
488 } |
454 { |
|
455 err = iNotification->SetData( |
|
456 TBluetoothDeviceDialog::EAdditionalDesc, iDialogNumeric ); |
|
457 } |
|
458 } |
|
459 else |
489 else |
460 { |
490 { |
461 err = KErrCancel; |
491 if( proceed && iCheckBoxState ) |
462 // if( proceed ) |
492 { |
463 // { |
493 //ask to block the device. |
464 // //ask to block the device. |
494 iParent.BlockDevice(iRemote,proceed); |
465 // LaunchBlockingQueryL(); |
495 } |
466 // } |
496 err = iParent.SetPairObserver(iRemote,EFalse); |
|
497 err = KErrCancel; // We need to complete the pairing request here |
467 } |
498 } |
468 } |
499 } |
469 if( err ) |
500 if( err ) |
470 { |
501 { |
471 // The user denied the connection, or something else prevented completion. |
502 // The user denied the connection, or something else prevented completion. |
569 paramsPckg.Set( iParams ); |
600 paramsPckg.Set( iParams ); |
570 aLocallyInitiated = paramsPckg().LocallyInitiated(); |
601 aLocallyInitiated = paramsPckg().LocallyInitiated(); |
571 TBTNumericComparisonParams::TComparisonScenario scenario = |
602 TBTNumericComparisonParams::TComparisonScenario scenario = |
572 paramsPckg().ComparisonScenario(); |
603 paramsPckg().ComparisonScenario(); |
573 aNumVal.Format( KNumCompFormat, paramsPckg().NumericalValue() ); |
604 aNumVal.Format( KNumCompFormat, paramsPckg().NumericalValue() ); |
|
605 aNumVal.Insert(3,_L(" ")); |
574 aAddr = paramsPckg().DeviceAddress(); |
606 aAddr = paramsPckg().DeviceAddress(); |
575 iCurrentDeviceName = paramsPckg().DeviceName(); |
607 iCurrentDeviceName = paramsPckg().DeviceName(); |
576 BOstraceFunctionExit0( DUMMY_DEVLIST ); |
608 BOstraceFunctionExit0( DUMMY_DEVLIST ); |
577 } |
609 } |
578 |
610 |
622 classofdevice = dev->Device().DeviceClass().DeviceClass(); |
654 classofdevice = dev->Device().DeviceClass().DeviceClass(); |
623 } |
655 } |
624 } |
656 } |
625 err = iNotification->SetData( (TInt) TBluetoothDeviceDialog::EDeviceClass, |
657 err = iNotification->SetData( (TInt) TBluetoothDeviceDialog::EDeviceClass, |
626 classofdevice ); |
658 classofdevice ); |
|
659 if( iDialogNumeric.Length() ) |
|
660 { |
|
661 err = iNotification->SetData( |
|
662 TBluetoothDeviceDialog::EAdditionalDesc, iDialogNumeric ); |
|
663 } |
|
664 err = iNotification->SetData( TBluetoothDialogParams::EDialogTitle, TBluetoothDialogParams::EPairingRequest); |
|
665 iCheckBoxState = ETrue; |
|
666 iAcceptPairingResult = EFalse; |
627 iParent.ConnectionTracker().NotificationManager()->QueueNotificationL( iNotification); |
667 iParent.ConnectionTracker().NotificationManager()->QueueNotificationL( iNotification); |
628 NOTIF_NOTHANDLED( !err ) |
668 NOTIF_NOTHANDLED( !err ) |
629 BOstraceFunctionExit0( DUMMY_DEVLIST ); |
669 BOstraceFunctionExit0( DUMMY_DEVLIST ); |
630 } |
670 } |
631 |
671 |
639 // Read the result. |
679 // Read the result. |
640 TPckgC<TBool> result( EFalse ); |
680 TPckgC<TBool> result( EFalse ); |
641 result.Set( aData.Ptr(), result.Length() ); // Read the part containing the result |
681 result.Set( aData.Ptr(), result.Length() ); // Read the part containing the result |
642 // Set a pointer descriptor to capture the remaining data, if any. |
682 // Set a pointer descriptor to capture the remaining data, if any. |
643 TPtrC8 dataPtr( aData.Mid( result.Length() ) ); |
683 TPtrC8 dataPtr( aData.Mid( result.Length() ) ); |
|
684 |
644 if ( iState == EIncomingPairingAcceptconfirm ) |
685 if ( iState == EIncomingPairingAcceptconfirm ) |
645 { |
686 { |
646 CompleteAcceptPairingQueryL(aError, result()); |
687 CompleteAcceptPairingQueryL(aError); |
647 } |
688 } |
648 else |
689 else |
649 { |
690 { |
650 CompletePairingNotifierL( aError, result(), dataPtr ); |
691 CompletePairingNotifierL( aError, result(), dataPtr ); |
651 } |
692 } |
652 BOstraceFunctionExit1( DUMMY_DEVLIST, this ); |
693 BOstraceFunctionExit1( DUMMY_DEVLIST, this ); |
653 } |
694 } |
654 |
695 |
655 // --------------------------------------------------------------------------- |
696 |
656 // Ask the user if he/she wants to block future connection requests. |
697 |
657 // --------------------------------------------------------------------------- |
698 |
658 // |
|
659 void CBTNotifPairNotifier::LaunchBlockingQueryL() |
|
660 { |
|
661 BOstraceFunctionEntry0( DUMMY_DEVLIST ); |
|
662 TBTDialogResourceId resourceId = EBlockUnpairedDevice; |
|
663 const CBtDevExtension* dev = iParent.BTDevRepository().Device(iRemote); |
|
664 if(dev->Device().IsValidPaired() && dev->Device().IsPaired() && |
|
665 dev->Device().LinkKeyType() != ELinkKeyUnauthenticatedUpgradable ) |
|
666 { |
|
667 resourceId = EBlockPairedDevice; |
|
668 } |
|
669 PrepareNotificationL( TBluetoothDialogParams::EQuery, resourceId ); |
|
670 BOstraceFunctionExit0( DUMMY_DEVLIST ); |
|
671 } |
|
672 |
|
673 |
|
674 |
|
675 |
|
676 |
|