bluetoothengine/btnotif/btnotifsrv/src/btnotifpairnotifier.cpp
changeset 31 a0ea99b6fa53
child 40 997690c3397a
equal deleted inserted replaced
30:df7a93ede42e 31:a0ea99b6fa53
       
     1 /*
       
     2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 *
       
    16 */
       
    17 
       
    18 #include "btnotifpairnotifier.h"
       
    19 #include "btnotifclientserver.h"
       
    20 #include <btextnotifiers.h>
       
    21 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS
       
    22 #include <btextnotifierspartner.h>
       
    23 #endif
       
    24 #include "btnotifconnectiontracker.h"
       
    25 #include "btnotifpairingmanager.h"
       
    26 #include "btnotificationmanager.h"
       
    27 #include "bluetoothnotification.h"
       
    28 #include "btnotifserver.h"
       
    29 #include "bluetoothtrace.h"
       
    30 
       
    31 
       
    32 /**  Format syntax for numeric comparison value. */
       
    33 _LIT( KNumCompFormat, "%06u" );
       
    34 /**  Format syntax for passkey display value. */
       
    35 _LIT( KPassKeyFormat, "%06u" );
       
    36 
       
    37 
       
    38 // ======== MEMBER FUNCTIONS ========
       
    39 
       
    40 // ---------------------------------------------------------------------------
       
    41 // C++ default constructor.
       
    42 // ---------------------------------------------------------------------------
       
    43 //
       
    44 CBTNotifPairNotifier::CBTNotifPairNotifier(
       
    45         CBTNotifPairingManager& aParent )
       
    46 :   iParent( aParent )
       
    47     {
       
    48     }
       
    49 
       
    50 // ---------------------------------------------------------------------------
       
    51 // Symbian 2nd-phase constructor.
       
    52 // ---------------------------------------------------------------------------
       
    53 //
       
    54 void CBTNotifPairNotifier::ConstructL()
       
    55     {
       
    56     }
       
    57 
       
    58 // ---------------------------------------------------------------------------
       
    59 // NewL
       
    60 // ---------------------------------------------------------------------------
       
    61 //
       
    62 CBTNotifPairNotifier* CBTNotifPairNotifier::NewL(
       
    63         CBTNotifPairingManager& aParent )
       
    64     {
       
    65     BOstraceFunctionEntry0( DUMMY_DEVLIST );
       
    66     CBTNotifPairNotifier* self = new( ELeave ) CBTNotifPairNotifier( aParent );
       
    67     CleanupStack::PushL( self );
       
    68     self->ConstructL();
       
    69     CleanupStack::Pop( self );
       
    70     BOstraceFunctionExit0( DUMMY_DEVLIST );
       
    71     return self;
       
    72     }
       
    73 
       
    74 
       
    75 // ---------------------------------------------------------------------------
       
    76 // Destructor.
       
    77 // ---------------------------------------------------------------------------
       
    78 //
       
    79 CBTNotifPairNotifier::~CBTNotifPairNotifier()
       
    80     {
       
    81     BOstraceFunctionEntry0( DUMMY_DEVLIST );
       
    82     if( iNotification )
       
    83         {
       
    84         // Clear the notification callback, we cannot receive them anymore.
       
    85         iNotification->RemoveObserver();
       
    86         iNotification->Close(); // Also dequeues the notification from the queue.
       
    87         iNotification = NULL;
       
    88         }
       
    89     iParams.Close();
       
    90     if ( !iNotifierMessage.IsNull() )
       
    91         {
       
    92         iNotifierMessage.Complete( KErrServerTerminated );
       
    93         }
       
    94     BOstraceFunctionExit0( DUMMY_DEVLIST );
       
    95     }
       
    96 
       
    97 // ---------------------------------------------------------------------------
       
    98 // Handle a notifier request for pairing with a remote device.
       
    99 // ---------------------------------------------------------------------------
       
   100 //
       
   101 void CBTNotifPairNotifier::StartPairingNotifierL(const RMessage2& aMessage )
       
   102     {
       
   103     BOstraceFunctionEntry0( DUMMY_DEVLIST );
       
   104     
       
   105     // todo: move Authorize notifier to a separate class
       
   106     TInt uid = aMessage.Int0();
       
   107     if ( KBTManAuthNotifierUid.iUid == uid )
       
   108         {
       
   109         TPckgBuf<TBool> answer;
       
   110         answer() = ETrue;
       
   111         TInt err = aMessage.Write( EBTNotifSrvReplySlot, answer);
       
   112         aMessage.Complete( KErrNone );
       
   113         return;
       
   114         }
       
   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     
       
   123     // Store the parameters locally, we need them later again.
       
   124     iParams.CreateL( aMessage.GetDesLengthL( EBTNotifSrvParamSlot ) );
       
   125     aMessage.ReadL( EBTNotifSrvParamSlot, iParams );
       
   126     iNotifierMessage = aMessage;
       
   127     
       
   128     // Read the notifier parameters
       
   129     ParseNotifierReqParamsL();
       
   130     
       
   131     const CBtDevExtension* dev = iParent.BTDevRepository().Device(iRemote);
       
   132     if(dev)
       
   133         {
       
   134         if (!iLocallyInitiated && dev->Device().GlobalSecurity().Banned() )
       
   135             {
       
   136             // If the device is banned and pairing is not locally initiated
       
   137             // then we ignore.
       
   138             aMessage.Complete( KErrNone );
       
   139             }
       
   140         if (iLocallyInitiated && dev->Device().GlobalSecurity().Banned())
       
   141             {
       
   142             // Remove the banned device from the blocking history
       
   143             iParent.ConnectionTracker().UpdateBlockingHistoryL(&dev->Device(),ETrue);
       
   144             }
       
   145         if(0 != dev->Device().FriendlyName().Length()&& dev->Device().IsValidFriendlyName())
       
   146             {
       
   147             // If we have a friendly name use it for the UI
       
   148             iCurrentDeviceName = dev->Device().FriendlyName();
       
   149             }
       
   150         else
       
   151             {
       
   152             // We don't have any friendly name then chek if we have the device name
       
   153             // otherwise use the Alias
       
   154             if(0 >= iCurrentDeviceName.Length())
       
   155                 {
       
   156                 iCurrentDeviceName = dev->Alias();
       
   157                 }
       
   158             }
       
   159         }
       
   160     else
       
   161         {
       
   162         //If we didn't get a name then we make one from the Bluetooth device address
       
   163         if(0 >= iCurrentDeviceName.Length())
       
   164             {
       
   165             iRemote.GetReadable(iCurrentDeviceName);
       
   166             }
       
   167         }
       
   168     // If this is an incoming pairing, we first ask the user to accept it.
       
   169     if( !iLocallyInitiated  )
       
   170         {
       
   171         StartAcceptPairingQueryL();
       
   172         }
       
   173     else
       
   174         {
       
   175         TInt uid = iNotifierMessage.Int0();
       
   176         if(uid == KBTNumericComparisonNotifierUid.iUid)
       
   177             {
       
   178             StartPairingUserInputL();
       
   179             }
       
   180         else
       
   181             {
       
   182             TBTPinCode pinCode;
       
   183             if ( iMinPinLength > -1 )
       
   184                 {
       
   185                 // Legacy Pin pairing. Check if a pin code is already available
       
   186                 // in pairing manager for this device:
       
   187                 iParent.GetPinCode( pinCode, iRemote, iMinPinLength );
       
   188                 }
       
   189             if ( pinCode().iLength != 0 )        
       
   190                 {
       
   191                 // a pin is ready for this pairing.
       
   192                 // write it back to client (stack)
       
   193                 TInt err = iNotifierMessage.Write( EBTNotifSrvReplySlot, pinCode );
       
   194                 iNotifierMessage.Complete( err );
       
   195                 }
       
   196             else
       
   197                 {
       
   198                 // no pin code is available or a pin code does not meet
       
   199                 // the security requirement.
       
   200                 // User need to interact:
       
   201                 StartPairingUserInputL();
       
   202                 }
       
   203             }
       
   204         }
       
   205     BOstraceFunctionExit1( DUMMY_DEVLIST, this );
       
   206     }
       
   207 
       
   208 // ---------------------------------------------------------------------------
       
   209 // Update a notifier, update the outstanding dialog if the notifier request 
       
   210 // is currently being served.
       
   211 // ---------------------------------------------------------------------------
       
   212 //
       
   213 void CBTNotifPairNotifier::UpdatePairingNotifierL( TInt aUid, const TDesC8& aParams )
       
   214     {
       
   215     BOstraceFunctionEntry0( DUMMY_DEVLIST );
       
   216     (void) aUid;
       
   217     TBTNotifierUpdateParams2 params;    // Enough for reading the base class type parameter
       
   218     TPckgC<TBTNotifierUpdateParams2> paramsPckg( params );
       
   219     paramsPckg.Set( aParams );
       
   220     if( paramsPckg().Type() == TBTNotifierUpdateParams2::EPasskeyDisplay )
       
   221         {
       
   222         // Paskey display update - keypress on remote device.
       
   223         }
       
   224     else
       
   225         {
       
   226         // name update
       
   227         TBTDeviceNameUpdateParams nameUpdate;
       
   228         TPckgC<TBTDeviceNameUpdateParams> nameUpdatePckg( nameUpdate );
       
   229         nameUpdatePckg.Set( aParams );
       
   230         // The result means result of conversion to unicode
       
   231         if( !nameUpdatePckg().Result() )
       
   232             {
       
   233             // Check first if we already have a friendly name
       
   234             const CBtDevExtension* dev = iParent.BTDevRepository().Device(iRemote);
       
   235             if(dev)
       
   236                 {
       
   237                 if(0 != dev->Device().FriendlyName().Length()&& dev->Device().IsValidFriendlyName())
       
   238                     {
       
   239                     return;
       
   240                     }
       
   241                 // We don't have a friendly name then use this name
       
   242                 iCurrentDeviceName = nameUpdatePckg().DeviceName();
       
   243                 if(0 == iCurrentDeviceName.Length())
       
   244                     {
       
   245                     // The new name is empty then use the Alias
       
   246                     iCurrentDeviceName = dev->Alias();
       
   247                     }
       
   248                 }
       
   249             else
       
   250                 {
       
   251                 // We don't have a friendly name then use this name
       
   252                 iCurrentDeviceName = nameUpdatePckg().DeviceName();
       
   253                 if(0 == iCurrentDeviceName.Length())
       
   254                     {
       
   255                     // The new name is empty then use the Alias
       
   256                     iRemote.GetReadable(iCurrentDeviceName);
       
   257                     }
       
   258                 }
       
   259             if( iNotification )
       
   260                 {
       
   261                 // Update the dialog with the new name. It is up to the dialog to 
       
   262                 // determine the validity (in case another dialog is shown).
       
   263                 iNotification->Update(iCurrentDeviceName);
       
   264                 }
       
   265             }
       
   266         }
       
   267     BOstraceFunctionExit0( DUMMY_DEVLIST );
       
   268     }
       
   269 
       
   270 // ---------------------------------------------------------------------------
       
   271 // Cancel a request, dismiss the outstanding dialog if the notifier request 
       
   272 // is currently being served.
       
   273 // ---------------------------------------------------------------------------
       
   274 //
       
   275 void CBTNotifPairNotifier::CancelPairingNotifierL( TInt aUid )
       
   276     {
       
   277     BOstraceFunctionEntry0( DUMMY_DEVLIST );
       
   278     if(  iNotifierMessage.Int0() == aUid )
       
   279         {
       
   280         if( iNotification )
       
   281             {
       
   282             // Cancel the user query
       
   283             // This will also unregister us from the notification.
       
   284             TInt err = iNotification->Close();
       
   285             NOTIF_NOTHANDLED( !err )
       
   286             iNotification = NULL;
       
   287             }
       
   288         // todo: Any bonding requester needs to be informed.
       
   289         // Currently we don't show any "Unable to pair" note
       
   290         // so no need to inform any bonding requester.
       
   291         if ( !iNotifierMessage.IsNull() )
       
   292             {
       
   293             iNotifierMessage.Complete( KErrCancel );
       
   294             }
       
   295         }
       
   296     BOstraceFunctionExit0( DUMMY_DEVLIST );
       
   297     }
       
   298 
       
   299 // ---------------------------------------------------------------------------
       
   300 // From class MBTNotificationResult.
       
   301 // Handle a result from a user query.
       
   302 // ---------------------------------------------------------------------------
       
   303 //
       
   304 void CBTNotifPairNotifier::MBRDataReceived( CHbSymbianVariantMap& aData )
       
   305     {
       
   306     BOstraceFunctionEntry0( DUMMY_DEVLIST );
       
   307     (void) aData;
       
   308     NOTIF_NOTIMPL
       
   309     BOstraceFunctionExit0( DUMMY_DEVLIST );
       
   310     }
       
   311 
       
   312 // ---------------------------------------------------------------------------
       
   313 // From class MBTNotificationResult.
       
   314 // The notification is finished.
       
   315 // ---------------------------------------------------------------------------
       
   316 //
       
   317 void CBTNotifPairNotifier::MBRNotificationClosed( TInt aError, const TDesC8& aData )
       
   318     {
       
   319     BOstraceFunctionEntryExt( DUMMY_DEVLIST, this, aError );
       
   320     // First unregister from the notification, so we can already get the next one.
       
   321     //iNotification->RemoveObserver();
       
   322     //iNotification = NULL;
       
   323     TRAP_IGNORE( NotificationClosedL( aError, aData ) );
       
   324     iNotification = NULL;
       
   325     BOstraceFunctionExit1( DUMMY_DEVLIST, this );
       
   326     }
       
   327 
       
   328 // ---------------------------------------------------------------------------
       
   329 // Request a user input for the outstanding pairing request.
       
   330 // ---------------------------------------------------------------------------
       
   331 //
       
   332 void CBTNotifPairNotifier::StartPairingUserInputL()
       
   333     {
       
   334     BOstraceFunctionEntry0( DUMMY_DEVLIST );
       
   335     PrepareNotificationL( iDialog, iDialogResource );
       
   336     iState = EPairingInputConfirm;
       
   337     BOstraceFunctionExit0( DUMMY_DEVLIST );
       
   338     }
       
   339 
       
   340 // ---------------------------------------------------------------------------
       
   341 // Process the user input and complete the outstanding pairing request.
       
   342 // ---------------------------------------------------------------------------
       
   343 //
       
   344 void CBTNotifPairNotifier::CompletePairingNotifierL( TInt aError, TBool aResult,
       
   345     const TDesC8& aData )
       
   346     {
       
   347     BOstraceFunctionEntryExt( DUMMY_DEVLIST, this, aError );
       
   348     if ( iNotifierMessage.IsNull() )
       
   349         {
       
   350         // Request not anymore active -> ignore
       
   351         return;
       
   352         }
       
   353     TInt err = aError;
       
   354     TPtrC8 resultData(KNullDesC8);
       
   355     TBTPinCode pinCode;
       
   356     TPckgBuf<TBool> userAcceptance;
       
   357     if( !err )
       
   358         {
       
   359         TInt uid = iNotifierMessage.Int0();
       
   360         // The returned data is the entered passkey.
       
   361         // const CBtDevExtension* dev = iParent.BTDevRepository().Device(iRemote);
       
   362         // TBool proceed = iParent.ConnectionTracker().UpdateBlockingHistoryL(&dev->Device(),aResult);
       
   363         if( uid == KBTNumericComparisonNotifierUid.iUid )
       
   364             {
       
   365             // Numeric comparison needs the boolean result passed back.
       
   366             userAcceptance() = aResult;
       
   367             resultData.Set( userAcceptance );
       
   368             }
       
   369         if( aResult )
       
   370             {
       
   371             if( uid == KBTManPinNotifierUid.iUid 
       
   372                 || uid == KBTPinCodeEntryNotifierUid.iUid )
       
   373                 {
       
   374                 // Check the passkey entered by the user.
       
   375                 // The length of the returned data equals the number of characters
       
   376                 // entered by the user.
       
   377                 pinCode().iLength = aData.Length();
       
   378                 // Check that the length of the passkey meets the minimum 
       
   379                 // required pin code length
       
   380                 if( aData.Length() >= iMinPinLength )
       
   381                     {
       
   382                     for( TInt i = 0; i < aData.Length(); i++ )
       
   383                         {
       
   384                         pinCode().iPIN[i] = aData[i];
       
   385                         }
       
   386                     resultData.Set( pinCode );
       
   387                     }
       
   388                 else
       
   389                     {
       
   390                     // todo: PIN wasn't long enough. This should be handled by the dialog though.
       
   391                     err = KErrCompletion;
       
   392                     }
       
   393                 }
       
   394             }
       
   395         else
       
   396             {
       
   397             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             }
       
   414         }
       
   415     // Complete the message with the result, and result data if any.
       
   416     if ( !err && resultData.Length() )
       
   417         {
       
   418         err = iNotifierMessage.Write( EBTNotifSrvReplySlot, resultData );
       
   419         }
       
   420     iNotifierMessage.Complete( err );
       
   421     BOstraceFunctionExit1( DUMMY_DEVLIST, this );
       
   422     }
       
   423 
       
   424 // ---------------------------------------------------------------------------
       
   425 // Ask the user to allow incoming pairing.
       
   426 // ---------------------------------------------------------------------------
       
   427 //
       
   428 void CBTNotifPairNotifier::StartAcceptPairingQueryL()
       
   429     {
       
   430     BOstraceFunctionEntry0( DUMMY_DEVLIST );
       
   431     PrepareNotificationL( TBluetoothDialogParams::EQuery, EIncomingPairing );
       
   432     iState = EIncomingPairingAcceptconfirm;
       
   433     // if rejected, the client message is completed in CompleteAcceptPairingQueryL
       
   434     BOstraceFunctionExit0( DUMMY_DEVLIST );
       
   435     }
       
   436 
       
   437 // ---------------------------------------------------------------------------
       
   438 // The user was asked to accept an incoming pairing. Process and proceed. 
       
   439 // ---------------------------------------------------------------------------
       
   440 //
       
   441 void CBTNotifPairNotifier::CompleteAcceptPairingQueryL( TInt aError, TBool aResult )
       
   442     {
       
   443     BOstraceFunctionEntry0( DUMMY_DEVLIST );
       
   444     TInt err = aError;
       
   445     if( !err )
       
   446         {
       
   447         // const CBtDevExtension* dev = iParent.BTDevRepository().Device(iRemote);
       
   448         // TBool proceed = iParent.ConnectionTracker().UpdateBlockingHistoryL(&dev->Device(),aResult);
       
   449         if( aResult )
       
   450             {
       
   451             // User accepted, continue to show pairing query.
       
   452             StartPairingUserInputL();
       
   453             if( iDialogNumeric.Length() )
       
   454                 {
       
   455                 err = iNotification->SetData( 
       
   456                 TBluetoothDeviceDialog::EAdditionalDesc, iDialogNumeric );
       
   457                 }            
       
   458              }
       
   459         else
       
   460             {
       
   461             err = KErrCancel;
       
   462             // if( proceed )
       
   463             //    {
       
   464             //    //ask to block the device.
       
   465             //    LaunchBlockingQueryL();
       
   466             //    }
       
   467             }
       
   468         }
       
   469     if( err )
       
   470         {
       
   471         // The user denied the connection, or something else prevented completion.
       
   472         CompletePairingNotifierL( err, EFalse, KNullDesC8 );
       
   473         }
       
   474     BOstraceFunctionExit0( DUMMY_DEVLIST );
       
   475     }
       
   476 
       
   477 // ---------------------------------------------------------------------------
       
   478 // Parse the parameters of a request for pairing.
       
   479 // ---------------------------------------------------------------------------
       
   480 //
       
   481 void CBTNotifPairNotifier::ParseNotifierReqParamsL()
       
   482     {
       
   483     BOstraceFunctionEntry0( DUMMY_DEVLIST );
       
   484     // Reset to make sure all vars contain initial values.
       
   485     iLocallyInitiated = EFalse;
       
   486     iDialogNumeric.Zero();
       
   487     iDialog = TBluetoothDialogParams::EInvalidDialog;
       
   488     iDialogResource = ENoResource;
       
   489     iRemote = TBTDevAddr();
       
   490     iMinPinLength = -1;
       
   491     
       
   492     TInt uid = iNotifierMessage.Int0();
       
   493     // Reset for other pairing modes than PIN code.
       
   494     // Determine the notifier type by the length of the parameter buffer
       
   495     if( uid == KBTManPinNotifierUid.iUid || uid == KBTPinCodeEntryNotifierUid.iUid )
       
   496         {
       
   497         if ( uid == KBTManPinNotifierUid.iUid ) 
       
   498             {
       
   499             ParseLegacyPinCodeReqParamsL( iLocallyInitiated, iMinPinLength, iRemote );
       
   500             }
       
   501         else
       
   502             {
       
   503             ParsePinCodeReqParamsL( iLocallyInitiated, iMinPinLength, iRemote );
       
   504             }
       
   505         iDialog = TBluetoothDialogParams::EInput;
       
   506         iDialogResource = EPinInput;
       
   507         }
       
   508     else if( uid == KBTNumericComparisonNotifierUid.iUid )
       
   509         {
       
   510         ParseNumericCompReqParamsL( iLocallyInitiated, iDialogNumeric, iRemote );
       
   511         iDialog = TBluetoothDialogParams::EQuery;
       
   512         iDialogResource = ENumericComparison;
       
   513         }
       
   514     else if( uid == KBTPasskeyDisplayNotifierUid.iUid )
       
   515         {
       
   516         ParsePasskeyDisplayReqParamsL( iLocallyInitiated, iDialogNumeric, iRemote );
       
   517         iDialog = TBluetoothDialogParams::EQuery;
       
   518         iDialogResource = EPasskeyDisplay;
       
   519         }
       
   520     BOstraceFunctionExit0( DUMMY_DEVLIST );
       
   521     }
       
   522 
       
   523 // ---------------------------------------------------------------------------
       
   524 // Parse the parameters of a request for pairing using pin query.
       
   525 // ---------------------------------------------------------------------------
       
   526 //
       
   527 void CBTNotifPairNotifier::ParseLegacyPinCodeReqParamsL( TBool& aLocallyInitiated,
       
   528     TInt& aMinPinLength, TBTDevAddr& aAddr )
       
   529     {
       
   530     BOstraceFunctionEntry0( DUMMY_DEVLIST );
       
   531     TBTPasskeyNotifierParams params;
       
   532     TPckgC<TBTPasskeyNotifierParams> paramsPckg( params );
       
   533     paramsPckg.Set( iParams );
       
   534     aLocallyInitiated = paramsPckg().iLocallyInitiated;
       
   535     aMinPinLength = paramsPckg().iPasskeyMinLength;
       
   536     aAddr = paramsPckg().iBDAddr;
       
   537     iCurrentDeviceName = paramsPckg().iName;
       
   538     BOstraceFunctionExit0( DUMMY_DEVLIST );
       
   539     }
       
   540 
       
   541 // ---------------------------------------------------------------------------
       
   542 // Parse the parameters of a request for pairing using pin query.
       
   543 // ---------------------------------------------------------------------------
       
   544 //
       
   545 void CBTNotifPairNotifier::ParsePinCodeReqParamsL( TBool& aLocallyInitiated,
       
   546     TInt& aMinPinLength, TBTDevAddr& aAddr )
       
   547     {
       
   548     BOstraceFunctionEntry0( DUMMY_DEVLIST );
       
   549     TBTPinCodeEntryNotifierParams params;
       
   550     TPckgC<TBTPinCodeEntryNotifierParams> paramsPckg( params );
       
   551     paramsPckg.Set( iParams );
       
   552     aLocallyInitiated = paramsPckg().LocallyInitiated();
       
   553     aMinPinLength = paramsPckg().PinCodeMinLength();
       
   554     aAddr = paramsPckg().DeviceAddress();
       
   555     iCurrentDeviceName = paramsPckg().DeviceName();
       
   556     BOstraceFunctionExit0( DUMMY_DEVLIST );
       
   557     }
       
   558 
       
   559 // ---------------------------------------------------------------------------
       
   560 // Parse the parameters of a request for pairing using numeric comparison.
       
   561 // ---------------------------------------------------------------------------
       
   562 //
       
   563 void CBTNotifPairNotifier::ParseNumericCompReqParamsL( TBool& aLocallyInitiated,
       
   564     TDes& aNumVal, TBTDevAddr& aAddr )
       
   565     {
       
   566     BOstraceFunctionEntry0( DUMMY_DEVLIST );
       
   567     TBTNumericComparisonParams params;
       
   568     TPckgC<TBTNumericComparisonParams> paramsPckg( params );
       
   569     paramsPckg.Set( iParams );
       
   570     aLocallyInitiated = paramsPckg().LocallyInitiated();
       
   571     TBTNumericComparisonParams::TComparisonScenario scenario =
       
   572                 paramsPckg().ComparisonScenario();
       
   573     aNumVal.Format( KNumCompFormat, paramsPckg().NumericalValue() );
       
   574     aAddr = paramsPckg().DeviceAddress();
       
   575     iCurrentDeviceName = paramsPckg().DeviceName();
       
   576     BOstraceFunctionExit0( DUMMY_DEVLIST );
       
   577     }
       
   578 
       
   579 // ---------------------------------------------------------------------------
       
   580 // Parse the parameters of a request for pairing using passkey display.
       
   581 // ---------------------------------------------------------------------------
       
   582 //
       
   583 void CBTNotifPairNotifier::ParsePasskeyDisplayReqParamsL( TBool& aLocallyInitiated,
       
   584     TDes& aNumVal, TBTDevAddr& aAddr )
       
   585     {
       
   586     BOstraceFunctionEntry0( DUMMY_DEVLIST );
       
   587     TBTPasskeyDisplayParams params;
       
   588     TPckgC<TBTPasskeyDisplayParams> paramsPckg( params );
       
   589     paramsPckg.Set( iParams );
       
   590     aLocallyInitiated = paramsPckg().LocallyInitiated();
       
   591     aNumVal.Format( KPassKeyFormat, paramsPckg().NumericalValue() );
       
   592     aAddr = paramsPckg().DeviceAddress();
       
   593     iCurrentDeviceName = paramsPckg().DeviceName();
       
   594     BOstraceFunctionExit0( DUMMY_DEVLIST );
       
   595     }
       
   596 
       
   597 // ---------------------------------------------------------------------------
       
   598 // Get and configure a notification.
       
   599 // ---------------------------------------------------------------------------
       
   600 //
       
   601 void CBTNotifPairNotifier::PrepareNotificationL( TBluetoothDialogParams::TBTDialogType aType,
       
   602     TBTDialogResourceId aResourceId )
       
   603     {
       
   604     BOstraceFunctionEntry0( DUMMY_DEVLIST );
       
   605     iNotification = 
       
   606             iParent.ConnectionTracker().NotificationManager()->GetNotification();
       
   607     User::LeaveIfNull( iNotification ); // For OOM exception, leaves with KErrNoMemory
       
   608     iNotification->SetObserver( this );
       
   609     iNotification->SetNotificationType( aType, aResourceId );
       
   610     TInt err = iNotification->SetData( TBluetoothDeviceDialog::EDeviceName, iCurrentDeviceName );
       
   611     NOTIF_NOTHANDLED( !err )
       
   612     TBTDeviceName name;
       
   613     iRemote.GetReadable(name);
       
   614     err = iNotification->SetData( TBluetoothDialogParams::EAddress, name );
       
   615     NOTIF_NOTHANDLED( !err )
       
   616     const CBtDevExtension* dev = iParent.BTDevRepository().Device(iRemote);
       
   617     TInt classofdevice = 0;
       
   618     if(dev)
       
   619         {
       
   620             if(dev->Device().IsValidDeviceClass())
       
   621                 {
       
   622                 classofdevice = dev->Device().DeviceClass().DeviceClass();
       
   623                 }
       
   624         }
       
   625     err = iNotification->SetData( (TInt) TBluetoothDeviceDialog::EDeviceClass, 
       
   626                 classofdevice );
       
   627     iParent.ConnectionTracker().NotificationManager()->QueueNotificationL( iNotification);
       
   628     NOTIF_NOTHANDLED( !err )
       
   629     BOstraceFunctionExit0( DUMMY_DEVLIST );
       
   630     }
       
   631 
       
   632 // ---------------------------------------------------------------------------
       
   633 // The notification is finished, handle the result.
       
   634 // ---------------------------------------------------------------------------
       
   635 //
       
   636 void CBTNotifPairNotifier::NotificationClosedL( TInt aError, const TDesC8& aData )
       
   637     {
       
   638     BOstraceFunctionEntryExt( DUMMY_DEVLIST, this, aError );
       
   639     // Read the result.
       
   640     TPckgC<TBool> result( EFalse );
       
   641     result.Set( aData.Ptr(), result.Length() ); // Read the part containing the result
       
   642     // Set a pointer descriptor to capture the remaining data, if any.
       
   643     TPtrC8 dataPtr( aData.Mid( result.Length() ) );
       
   644     if ( iState == EIncomingPairingAcceptconfirm )
       
   645         {
       
   646         CompleteAcceptPairingQueryL(aError, result());
       
   647         }
       
   648     else
       
   649         {
       
   650         CompletePairingNotifierL( aError, result(), dataPtr );
       
   651         }
       
   652     BOstraceFunctionExit1( DUMMY_DEVLIST, this );
       
   653     }
       
   654 
       
   655 // ---------------------------------------------------------------------------
       
   656 // Ask the user if he/she wants to block future connection requests. 
       
   657 // ---------------------------------------------------------------------------
       
   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