bluetoothengine/btnotif/src/btnssppasskeyentrynotifier.cpp
branchRCL_3
changeset 56 9386f31cc85b
child 61 269724087bed
equal deleted inserted replaced
55:613943a21004 56:9386f31cc85b
       
     1 /*
       
     2 * Copyright (c) 2002 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:  Declares authentication (PIN query) notifier class.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <StringLoader.h>    // Localisation stringloader
       
    21 #include <utf.h>             // Unicode character conversion utilities
       
    22 #include <avkon.mbg>
       
    23 #include <btengdevman.h>
       
    24 #include <btengconnman.h>
       
    25 #include <btotgpairpub.inl>
       
    26 #ifndef SYMBIAN_ENABLE_SPLIT_HEADERS
       
    27 #include <btextnotifiers.h>
       
    28 #else
       
    29 #include <btextnotifiers.h>
       
    30 #include <btextnotifierspartner.h>
       
    31 #endif
       
    32 #include <BTNotif.rsg>       // Own resources
       
    33 #include <SecondaryDisplay/BTnotifSecondaryDisplayAPI.h>
       
    34 #include <bluetoothuiutil.h>
       
    35 #include "btnotif.hrh"       // Own resource header
       
    36 #include "btnssppasskeyentrynotifier.h"  // Own class definition
       
    37 #include "btNotifDebug.h"    // Debugging macros
       
    38 #include "btnotifnameutils.h"
       
    39 
       
    40 #ifdef __SERIES60_HELP
       
    41 #include <hlplch.h>
       
    42 #include <csxhelp/bt.hlp.hrh> // The bt hrh info is needed, for help launching
       
    43 #endif
       
    44 
       
    45 
       
    46 // ================= MEMBER FUNCTIONS =======================
       
    47 
       
    48 // ----------------------------------------------------------
       
    49 // CBTSSPPasskeyEntryNotifier::NewL
       
    50 // Two-phased constructor.
       
    51 // ----------------------------------------------------------
       
    52 //
       
    53 CBTSSPPasskeyEntryNotifier* CBTSSPPasskeyEntryNotifier::NewL()
       
    54     {
       
    55     CBTSSPPasskeyEntryNotifier* self=new (ELeave) CBTSSPPasskeyEntryNotifier();
       
    56     CleanupStack::PushL(self);
       
    57     self->ConstructL();
       
    58     CleanupStack::Pop(self);
       
    59     return self;
       
    60     }
       
    61 
       
    62 // ----------------------------------------------------------
       
    63 // CBTSSPPasskeyEntryNotifier::CBTSSPPasskeyEntryNotifier
       
    64 // C++ default constructor can NOT contain any code, that
       
    65 // might leave.
       
    66 // ----------------------------------------------------------
       
    67 //
       
    68 CBTSSPPasskeyEntryNotifier::CBTSSPPasskeyEntryNotifier()
       
    69     {
       
    70     iPasskey.Zero();
       
    71     }
       
    72 
       
    73 // ----------------------------------------------------------
       
    74 // Destructor
       
    75 // ----------------------------------------------------------
       
    76 //
       
    77 CBTSSPPasskeyEntryNotifier::~CBTSSPPasskeyEntryNotifier()
       
    78     {
       
    79     }
       
    80 
       
    81 // ----------------------------------------------------------
       
    82 // CBTSSPPasskeyEntryNotifier::RegisterL
       
    83 // Register notifier.
       
    84 // ----------------------------------------------------------
       
    85 //
       
    86 CBTSSPPasskeyEntryNotifier::TNotifierInfo CBTSSPPasskeyEntryNotifier::RegisterL()
       
    87     {
       
    88     iInfo.iUid = KBTPasskeyDisplayNotifierUid;
       
    89     iInfo.iChannel = KBTPasskeyDisplayNotifierUid;
       
    90     iInfo.iPriority = ENotifierPriorityVHigh;
       
    91     return iInfo;
       
    92     }
       
    93 
       
    94 // ----------------------------------------------------------
       
    95 // CBTSSPPasskeyEntryNotifier::GetParamsL
       
    96 // Initialize parameters and check if device is already
       
    97 // in registry. Jump to RunL as soon as possible.
       
    98 // ----------------------------------------------------------
       
    99 //
       
   100 void CBTSSPPasskeyEntryNotifier::GetParamsL(const TDesC8& aBuffer, TInt aReplySlot, const RMessagePtr2& aMessage)
       
   101     {
       
   102     FLOG(_L("[BTNOTIF]\t CBTSSPPasskeyEntryNotifier::GetParamsL()"));
       
   103 
       
   104     CBTNPairNotifierBase::GetParamsL( aBuffer, aReplySlot, aMessage );
       
   105     
       
   106     TBTPasskeyDisplayParamsPckg pckg;
       
   107     pckg.Copy(aBuffer);
       
   108     iBTAddr = pckg().DeviceAddress();
       
   109     if ( OtherOutgoPairing(iBTAddr) )
       
   110         {
       
   111         // We won't allow incoming pairing during outgoing pairing:
       
   112         FLOG(_L("[BTNOTIF]\t CBTSSPPasskeyEntryNotifier: outgoing pair in progress, reject incoming pair"));
       
   113         CompleteMessage(KErrCancel);
       
   114         return;
       
   115         }
       
   116 
       
   117     iLocallyInitiated = pckg().LocallyInitiated();
       
   118     iPasskey.AppendNumFixedWidth(pckg().NumericalValue(), EDecimal, KPassKeylength);
       
   119     iPasskey.Insert(3,_L(" "));
       
   120 
       
   121     ProcessParamsGetDeviceL( iBTAddr, pckg().DeviceName() );
       
   122     
       
   123     FLOG(_L("[BTNOTIF]\t CBTSSPPasskeyEntryNotifier::GetParamsL() completed"));
       
   124     }
       
   125 
       
   126 // ----------------------------------------------------------
       
   127 // CBTSSPPasskeyEntryNotifier::UpdateL
       
   128 // Notifier update. Stores the received bluetooth
       
   129 // device name into registry and show it on screen.
       
   130 // ----------------------------------------------------------
       
   131 //
       
   132 TPtrC8 CBTSSPPasskeyEntryNotifier::UpdateL(const TDesC8& aBuffer)
       
   133     {
       
   134     FLOG(_L("[BTNOTIF]\t CBTSSPPasskeyEntryNotifier::UpdateL()"));
       
   135     
       
   136     TBTPasskeyDisplayUpdateParamsPckg pckg;
       
   137     pckg.Copy(aBuffer);
       
   138   
       
   139     if(pckg().Type() != TBTNotifierUpdateParams2::EPasskeyDisplay)
       
   140         {
       
   141         TPtrC8 ret(KNullDesC8);
       
   142         return (ret);
       
   143         }
       
   144     
       
   145     switch (pckg().KeypressNotification())
       
   146         {
       
   147         case EPasskeyEntryStarted:
       
   148             {
       
   149             iBuf.Zero();
       
   150             iBuf.Append(iPasskey);
       
   151             iBuf.Append(_L("    "));
       
   152             break;
       
   153             }
       
   154         case EPasskeyDigitEntered:
       
   155             {
       
   156             // show an '*'
       
   157             iBuf.Append(_L("*"));
       
   158             break;
       
   159             }
       
   160         case EPasskeyDigitDeleted:
       
   161             {
       
   162             // remove an '*' from the tail of iBuf
       
   163             iBuf.Delete(iBuf.Length()-1, 1);  
       
   164             break;
       
   165             }
       
   166         case EPasskeyCleared:
       
   167             {
       
   168             // remove all '*'
       
   169             iBuf.Zero();
       
   170             iBuf.Append(iPasskey);
       
   171             iBuf.Append(_L("    "));
       
   172             break;
       
   173             }
       
   174         case EPasskeyEntryCompleted:
       
   175             {                                  
       
   176             // complete passkey entry
       
   177             // Set iAnswer to 1 ,
       
   178             // Continue pairing in Run()
       
   179             iAnswer = 1;
       
   180             //iPasskeyDlg->DismissQueryL();
       
   181             iNotifUiUtil->DismissDialog();
       
   182             break;
       
   183             }
       
   184         }
       
   185     if ( !iNotifUiUtil->IsQueryReleased() )
       
   186         {
       
   187         RBuf prompt;
       
   188         prompt.CleanupClosePushL();
       
   189         GenerateQueryPromptL( prompt );
       
   190         iNotifUiUtil->UpdateQueryDlgL( prompt );
       
   191         CleanupStack::PopAndDestroy( &prompt ); 
       
   192         }        
       
   193     
       
   194     FLOG(_L("[BTNOTIF]\t CBTSSPPasskeyEntryNotifier::UpdateL() completed"));
       
   195     TPtrC8 ret(KNullDesC8);
       
   196     return (ret);
       
   197     }
       
   198 
       
   199 // ----------------------------------------------------------
       
   200 // CBTSSPPasskeyEntryNotifier::HandleGetDeviceCompletedL
       
   201 // Ask user response and return it to caller.
       
   202 // Store device into registry if user rejects the incoming pairing.
       
   203 // ----------------------------------------------------------
       
   204 //
       
   205 void CBTSSPPasskeyEntryNotifier::HandleGetDeviceCompletedL(const CBTDevice* /*aDev*/)
       
   206     {
       
   207     FLOG(_L("[BTNOTIF]\t CBTSSPPasskeyEntryNotifier::HandleGetDeviceCompletedL()"));
       
   208     iAnswer = 0;
       
   209     
       
   210     // Check if blocked device. 
       
   211     if( CheckBlockedDeviceL() )
       
   212         return;
       
   213 
       
   214     // For pairing request from remote device
       
   215     if ( !iLocallyInitiated )
       
   216         {
       
   217         TBool keypress = AuthoriseIncomingPairingL();
       
   218         if( !keypress )
       
   219             {
       
   220             //User rejects the incoming pairing, complete message in QueryBlockDevice.
       
   221             FLOG(_L("[BTNOTIF]\t CBTSSPPasskeyEntryNotifier::HandleGetDeviceCompletedL() <<"));
       
   222             return;
       
   223             }
       
   224         }
       
   225    
       
   226     TBTDeviceName nameCoverUi( KNullDesC );
       
   227     
       
   228     iBuf.Zero();
       
   229     iBuf.Append(iPasskey);
       
   230     iBuf.Append(_L("    "));
       
   231     
       
   232     RBuf prompt;
       
   233     prompt.CleanupClosePushL();
       
   234     GenerateQueryPromptL( prompt );
       
   235     
       
   236     TInt answer = iNotifUiUtil->ShowQueryL( prompt, R_BT_PASSKEY_QUERY, 
       
   237             ECmdBTnotifUnavailable, nameCoverUi );    
       
   238     CleanupStack::PopAndDestroy( &prompt );  
       
   239 
       
   240     if( iAnswer ) // user pressed entry key from remote keyboard.
       
   241         {
       
   242         CompleteMessage(KErrNone);
       
   243         }
       
   244     else 
       
   245         {
       
   246         // If the outgoing pairing mode is set, then this is bonding initiated by the user.
       
   247         TBool incomingConn = ( OutgoPairingMode( iBTAddr ) == EBTOutgoingPairNone );
       
   248         if( !iMessage.IsNull() )
       
   249             {
       
   250             // No need to inform the user of the pairing result if the user cancelled it.
       
   251             // If user doesn't answer anything but stack cancels, pairing result is needed 
       
   252             // to show for outgoing pairing. In this case, don't stop pairng observer.
       
   253             (void) CBTEngConnMan::StopPairingObserver( iBTAddr );
       
   254             }
       
   255         // We may be asking for pairing (locally initiated), because a remote device is requesting
       
   256         // accesss to a service for which we require authentication.
       
   257         if( iLocallyInitiated && incomingConn )
       
   258             {
       
   259             CheckAndHandleQueryIntervalL();
       
   260             }
       
   261         CompleteMessage(KErrCancel);
       
   262         }
       
   263     
       
   264      FLOG(_L("[BTNOTIF]\t CBTSSPPasskeyEntryNotifier::HandleGetDeviceCompletedL() completed"));
       
   265     }
       
   266 
       
   267 // ----------------------------------------------------------
       
   268 // CBTSSPPasskeyEntryNotifier::GenerateQueryPromptL
       
   269 // ----------------------------------------------------------
       
   270 //
       
   271 void CBTSSPPasskeyEntryNotifier::GenerateQueryPromptL(  RBuf& aRBuf )
       
   272     {
       
   273     FLOG(_L("[BTNOTIF]\t CBTSSPPasskeyEntryNotifier::GenerateQueryPromptL()"));
       
   274     TBTDeviceName devName; 
       
   275     BtNotifNameUtils::GetDeviceDisplayName(devName, iDevice);   
       
   276     BluetoothUiUtil::LoadResourceAndSubstringL( 
       
   277             aRBuf, R_BT_SSP_PASSKEY_ENTRY, devName, 0 );
       
   278     BluetoothUiUtil::AddSubstringL( aRBuf, iBuf, 1 );
       
   279     FLOG(_L("[BTNOTIF]\t CBTSSPPasskeyEntryNotifier::GenerateQueryPromptL() << "));
       
   280 
       
   281     }
       
   282 // End of File