bluetoothengine/btnotif/src/btnssppasskeyentrynotifier.cpp
changeset 0 f63038272f30
child 6 6a29d5ad0713
equal deleted inserted replaced
-1:000000000000 0:f63038272f30
       
     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 
       
    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         HBufC* update = GenerateQueryPromoptLC();
       
   188         iNotifUiUtil->UpdateQueryDlgL( *update );
       
   189         CleanupStack::PopAndDestroy( update ); 
       
   190         }        
       
   191     
       
   192     FLOG(_L("[BTNOTIF]\t CBTSSPPasskeyEntryNotifier::UpdateL() completed"));
       
   193     TPtrC8 ret(KNullDesC8);
       
   194     return (ret);
       
   195     }
       
   196 
       
   197 // ----------------------------------------------------------
       
   198 // CBTSSPPasskeyEntryNotifier::HandleGetDeviceCompletedL
       
   199 // Ask user response and return it to caller.
       
   200 // Store device into registry if user rejects the incoming pairing.
       
   201 // ----------------------------------------------------------
       
   202 //
       
   203 void CBTSSPPasskeyEntryNotifier::HandleGetDeviceCompletedL(const CBTDevice* /*aDev*/)
       
   204     {
       
   205     FLOG(_L("[BTNOTIF]\t CBTSSPPasskeyEntryNotifier::HandleGetDeviceCompletedL()"));
       
   206     iAnswer = 0;
       
   207     
       
   208     // Check if blocked device. 
       
   209     if( CheckBlockedDeviceL() )
       
   210         return;
       
   211 
       
   212     // For pairing request from remote device
       
   213     if ( !iLocallyInitiated )
       
   214         {
       
   215         TBool keypress = AuthoriseIncomingPairingL();
       
   216         if( !keypress )
       
   217             {
       
   218             //User rejects the incoming pairing, complete message in QueryBlockDevice.
       
   219             FLOG(_L("[BTNOTIF]\t CBTSSPPasskeyEntryNotifier::HandleGetDeviceCompletedL() <<"));
       
   220             return;
       
   221             }
       
   222         }
       
   223    
       
   224     TBTDeviceName nameCoverUi( KNullDesC );
       
   225     
       
   226     iBuf.Zero();
       
   227     iBuf.Append(iPasskey);
       
   228     iBuf.Append(_L("    "));
       
   229     HBufC* prompt = GenerateQueryPromoptLC();
       
   230     
       
   231     TInt answer = iNotifUiUtil->ShowQueryL( *prompt, R_BT_PASSKEY_QUERY, 
       
   232             ECmdBTnotifUnavailable, nameCoverUi );    
       
   233     CleanupStack::PopAndDestroy( prompt );  
       
   234 
       
   235     if( iAnswer ) // user pressed entry key from remote keyboard.
       
   236         {
       
   237         CompleteMessage(KErrNone);
       
   238         }
       
   239     else 
       
   240         {
       
   241         // If the outgoing pairing mode is set, then this is bonding initiated by the user.
       
   242         TBool incomingConn = ( OutgoPairingMode( iBTAddr ) == EBTOutgoingPairNone );
       
   243         if( !iMessage.IsNull() )
       
   244             {
       
   245             // No need to inform the user of the pairing result if the user cancelled it.
       
   246             // If user doesn't answer anything but stack cancels, pairing result is needed 
       
   247             // to show for outgoing pairing. In this case, don't stop pairng observer.
       
   248             (void) CBTEngConnMan::StopPairingObserver( iBTAddr );
       
   249             }
       
   250         // We may be asking for pairing (locally initiated), because a remote device is requesting
       
   251         // accesss to a service for which we require authentication.
       
   252         if( iLocallyInitiated && incomingConn )
       
   253             {
       
   254             CheckAndHandleQueryIntervalL();
       
   255             }
       
   256         CompleteMessage(KErrCancel);
       
   257         }
       
   258     
       
   259      FLOG(_L("[BTNOTIF]\t CBTSSPPasskeyEntryNotifier::HandleGetDeviceCompletedL() completed"));
       
   260     }
       
   261 
       
   262 // ----------------------------------------------------------
       
   263 // CBTSSPPasskeyEntryNotifier::GenerateQueryPromoptLC
       
   264 // ----------------------------------------------------------
       
   265 //
       
   266 HBufC* CBTSSPPasskeyEntryNotifier::GenerateQueryPromoptLC()
       
   267     {
       
   268     FLOG(_L("[BTNOTIF]\t CBTSSPPasskeyEntryNotifier::GenerateQueryPromoptLC()"));
       
   269     TBTDeviceName devName; 
       
   270     BtNotifNameUtils::GetDeviceDisplayName(devName, iDevice);   
       
   271     
       
   272     CPtrCArray* subsPrompt = new (ELeave) CPtrCArray(2);
       
   273     CleanupStack::PushL( subsPrompt );
       
   274     subsPrompt->AppendL( devName );
       
   275     subsPrompt->AppendL( iBuf );
       
   276     HBufC* prompt = StringLoader::LoadL( R_BT_SSP_PASSKEY_ENTRY , *subsPrompt );
       
   277     CleanupStack::PopAndDestroy( subsPrompt );
       
   278     CleanupStack::PushL( prompt );
       
   279     FLOG(_L("[BTNOTIF]\t CBTSSPPasskeyEntryNotifier::GenerateQueryPromoptLC() << "));
       
   280     return prompt;
       
   281     }
       
   282 // End of File