bluetoothengine/btnotif/btnotifsrv/src/btnotifpairinghelper.cpp
author hgs
Wed, 05 May 2010 09:56:48 +0300
changeset 30 df7a93ede42e
parent 29 48ae3789ce00
permissions -rw-r--r--
201017_3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
29
48ae3789ce00 201017_2
hgs
parents:
diff changeset
     1
/*
48ae3789ce00 201017_2
hgs
parents:
diff changeset
     2
* ============================================================================
48ae3789ce00 201017_2
hgs
parents:
diff changeset
     3
*  Name        : btnotifpairinghelper.cpp
48ae3789ce00 201017_2
hgs
parents:
diff changeset
     4
*  Part of     : bluetoothengine / btnotif
48ae3789ce00 201017_2
hgs
parents:
diff changeset
     5
*  Description : Helper class for processing pairing requests and results, as extended functionality for CBTNotifConnection.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
     6
*
48ae3789ce00 201017_2
hgs
parents:
diff changeset
     7
*  Copyright © 2009 Nokia Corporation and/or its subsidiary(-ies).
48ae3789ce00 201017_2
hgs
parents:
diff changeset
     8
*  All rights reserved.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
     9
*  This component and the accompanying materials are made available
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    10
*  under the terms of "Eclipse Public License v1.0"
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    11
*  which accompanies this distribution, and is available
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    12
*  at the URL "http://www.eclipse.org/legal/epl-v10.html".
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    13
*
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    14
*  Initial Contributors:
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    15
*  Nokia Corporation - initial contribution.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    16
*
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    17
*  Contributors:
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    18
*  Nokia Corporation
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    19
* ============================================================================
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    20
* Template version: 4.1
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    21
*/
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    22
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    23
#include "btnotifpairinghelper.h"
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    24
#include <bt_sock.h>
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    25
#include <btextnotifiers.h>
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    26
#ifdef SYMBIAN_ENABLE_SPLIT_HEADERS
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    27
#include <btextnotifierspartner.h>
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    28
#endif
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    29
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    30
#include "btnotifconnection.h"
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    31
#include "btnotifconnectiontracker.h"
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    32
#include "btnotificationmanager.h"
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    33
#include "btnotifserver.h"
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    34
#include "bluetoothtrace.h"
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    35
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    36
/**  Id for the active object for a dedicated bonding session. */
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    37
const TInt KDedicatedBonding = 50;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    38
/**  Length of the default PIN. */
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    39
const TInt KDefaultPinLength = 4;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    40
/**  Default PIN character. */
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    41
const TText8 KDefaultPinValue = '0';
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    42
/**  Format syntax for numeric comparison value. */
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    43
_LIT( KNumCompFormat, "%06u" );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    44
/**  Format syntax for passkey display value. */
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    45
_LIT( KPassKeyFormat, "%06u" );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    46
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    47
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    48
// ======== LOCAL FUNCTIONS ========
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    49
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    50
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    51
// ?description
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    52
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    53
//
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    54
/*?type ?function_name( ?arg_type ?arg,
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    55
                      ?arg_type ?arg )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    56
    {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    57
    }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    58
*/
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    59
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    60
// ======== MEMBER FUNCTIONS ========
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    61
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    62
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    63
// C++ default constructor.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    64
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    65
//
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    66
CBTNotifPairingHelper::CBTNotifPairingHelper( CBTNotifConnection* aConnection,
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    67
    CBTNotifConnectionTracker* aTracker )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    68
:   iConnection( aConnection ),
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    69
    iTracker( aTracker )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    70
    {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    71
    }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    72
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    73
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    74
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    75
// Symbian 2nd-phase constructor.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    76
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    77
//
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    78
void CBTNotifPairingHelper::ConstructL()
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    79
    {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    80
    if( iConnection )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    81
        {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    82
        iDevice = iConnection->BTDevice();
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    83
        }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    84
    }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    85
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    86
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    87
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    88
// NewL
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    89
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    90
//
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    91
CBTNotifPairingHelper* CBTNotifPairingHelper::NewL( CBTNotifConnection* aConnection,
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    92
    CBTNotifConnectionTracker* aTracker )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    93
    {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    94
    BOstraceFunctionEntry0( DUMMY_DEVLIST );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    95
    CBTNotifPairingHelper* self = new( ELeave ) CBTNotifPairingHelper( aConnection, aTracker );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    96
    CleanupStack::PushL( self );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    97
    self->ConstructL();
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    98
    CleanupStack::Pop( self );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    99
    BOstraceFunctionExit0( DUMMY_DEVLIST );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   100
    return self;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   101
    }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   102
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   103
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   104
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   105
// Destructor.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   106
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   107
//
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   108
CBTNotifPairingHelper::~CBTNotifPairingHelper()
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   109
    {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   110
    BOstraceFunctionEntry0( DUMMY_DEVLIST );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   111
    if( iNotification )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   112
        {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   113
        // Clear the notification callback, we cannot receive them anymore.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   114
        iNotification->RemoveObserver();
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   115
        iNotification->Close(); // Also dequeues the notification from the queue.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   116
        iNotification = NULL;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   117
        }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   118
    delete iParams;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   119
    if( iBondingActive )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   120
        {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   121
        iBondingActive->Cancel();   // Will close subsession;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   122
        }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   123
    delete iBondingActive;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   124
    iBondingSession.Close();
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   125
    iBondingSocket.Close();
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   126
    BOstraceFunctionExit0( DUMMY_DEVLIST );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   127
    }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   128
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   129
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   130
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   131
// Handle the authentication result from the baseband. Show the result in a note.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   132
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   133
//
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   134
void CBTNotifPairingHelper::HandleAuthenticationCompleteL( TInt aError )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   135
    {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   136
    BOstraceFunctionEntryExt( DUMMY_DEVLIST, this, aError );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   137
    if( iOperation == EDedicatedBonding || iOperation == EAwaitingPairingResult ||
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   138
        iOperation == EAutoPairing )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   139
        {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   140
        // Default case (aError == 0): Success, we are now paired.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   141
        TBTDialogResourceId resourceId = EPairingSuccess;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   142
        TBool autoPairing = ( iOperation == EAutoPairing ); // Remember the autopairing state
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   143
        iOperation = EShowPairingSuccess;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   144
        if( aError && aError != KHCIErrorBase )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   145
            {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   146
            // Authentication failure, means pairing failed.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   147
            resourceId = EPairingFailure;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   148
            iOperation = EShowPairingFailure;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   149
            // Communicate the error now that we still remember it.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   150
            if( iDedicatedBonding )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   151
                {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   152
                if( autoPairing && aError == KHCIErrorBase - EAuthenticationFailure )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   153
                    {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   154
                    BOstrace0( TRACE_NORMAL, DUMMY_DEVLIST, 
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   155
                            "[BTNOTIF]\t CBTNotifPairingHelper::HandleAuthenticationCompleteL: Autopairing failed, we need to try again.");
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   156
                    // Autopairing failed, we need to try again.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   157
                    iOperation = EAutoPairing;  // Reset back
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   158
                    resourceId = ENoResource;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   159
                    }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   160
                CompleteBondingL( aError );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   161
                }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   162
            }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   163
        if( resourceId )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   164
            {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   165
            // Inform the user of the result.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   166
            BOstrace0( TRACE_NORMAL, DUMMY_DEVLIST,  
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   167
                    "[BTNOTIF]\t CBTNotifPairingHelper::HandleAuthenticationCompleteL: pairing successful, inform user" );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   168
            PrepareNotificationL( TBluetoothDialogParams::EGlobalNotif, resourceId );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   169
            // MBRNotificationClosed will be called from this, which will 
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   170
            // check the next stage.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   171
            }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   172
        }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   173
    BOstraceFunctionExit1( DUMMY_DEVLIST, this );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   174
    }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   175
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   176
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   177
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   178
// Start a bonding operation with the remote device.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   179
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   180
//
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   181
void CBTNotifPairingHelper::StartBondingL( TInt aHandle )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   182
    {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   183
    BOstraceFunctionEntryExt( DUMMY_DEVLIST, this, aHandle );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   184
    __ASSERT_ALWAYS( iOperation == EIdle || iOperation == EDedicatedBonding
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   185
                || iOperation == EAutoPairing, PanicServer( EBTNotifPanicBadState ) );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   186
    if( !iBondingActive )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   187
        {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   188
        iBondingActive = CBtSimpleActive::NewL( *this, KDedicatedBonding );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   189
        }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   190
    if( aHandle )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   191
        {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   192
        iDedicatedBonding = aHandle;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   193
        }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   194
    if( iOperation == EIdle )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   195
        {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   196
        iOperation = EDedicatedBonding;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   197
        }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   198
    if( iOperation == EDedicatedBonding && iTracker->PairingServerSession() )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   199
        {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   200
        if( !iBondingActive->IsActive() )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   201
            {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   202
            BtTraceBtAddr1( TRACE_DEBUG,DUMMY_LIST,"CBTNotifPairingHelper::StartBondingL()",iDevice->BDAddr() );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   203
            iBondingSession.Start( *iTracker->PairingServerSession(),
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   204
                        iDevice->BDAddr(), iBondingActive->RequestStatus() );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   205
            iBondingActive->GoActive();
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   206
            }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   207
        }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   208
    else
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   209
        {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   210
        // We are doing autopairing (or the unlikely situation that the pairing server is unavailable)
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   211
        CompleteBondingL( KErrServerTerminated );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   212
        }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   213
    BOstraceFunctionExit1( DUMMY_DEVLIST, this);
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   214
    }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   215
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   216
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   217
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   218
// Cancel an ongoing bonding operation with the remote device.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   219
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   220
//
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   221
void CBTNotifPairingHelper::CancelBondingL()
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   222
    {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   223
    BOstraceFunctionEntry0( DUMMY_DEVLIST );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   224
    if( iDedicatedBonding )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   225
        {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   226
        CompleteBondingL( KErrCancel ); // Closes sessions
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   227
        if( iNotification )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   228
            {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   229
            // Cancel the outstanding user query
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   230
            // This will also unregister us from the notification.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   231
            TInt err = iNotification->Close();
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   232
            NOTIF_NOTHANDLED( !err )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   233
            iNotification = NULL;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   234
            }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   235
        if( iNotifierUid )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   236
            {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   237
            // Also finish up the notifier processing.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   238
            CompletePairingNotifierL( KErrCancel, EFalse, KNullDesC8 );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   239
            }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   240
        iOperation = EIdle;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   241
        iConnection->PairingCompleted();   // This may delete us.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   242
        }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   243
    BOstraceFunctionExit0( DUMMY_DEVLIST );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   244
    }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   245
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   246
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   247
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   248
// Handle a notifier request for pairing with the remote device of this connection.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   249
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   250
//
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   251
void CBTNotifPairingHelper::StartPairingNotifierL( TInt aUid, const TDesC8& aParams )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   252
    {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   253
    BOstraceFunctionEntryExt( DUMMY_DEVLIST, this, aUid );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   254
    if( iDevice->GlobalSecurity().Banned() && !iDedicatedBonding )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   255
        {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   256
        // ToDo: should this case actually be ignored, and presume that
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   257
        // the caller will take care of unblocking the device?
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   258
        iOperation = EIdle;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   259
        User::Leave( KErrAccessDenied );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   260
        }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   261
    // Store the parameters locally, we need them later again.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   262
    delete iParams;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   263
    iParams = NULL;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   264
    iParams = HBufC8::NewL( aParams.Length() );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   265
    *iParams = aParams;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   266
    iNotifierUid = aUid;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   267
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   268
    if( iDevice->IsValidPaired() && iDevice->IsPaired() )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   269
        {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   270
        // The device is still paired, we unpair it first.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   271
        // Deleting the link key will set the device as unpaired.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   272
        iDevice->DeleteLinkKey();
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   273
        iOperation = EUnpairing;    // So that parent state does not get changed.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   274
        iConnection->UpdateRegistryEntryL();
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   275
        // Note that this will only be done before trying autopairing, so
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   276
        // it not interfere with a second attempt;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   277
        }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   278
    // Update the device name
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   279
    TBTPasskeyDisplayParams params; // Enough for reading the base class type parameter
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   280
    TPckgC<TBTPasskeyDisplayParams> paramsPckg( params );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   281
    paramsPckg.Set( *iParams );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   282
    if( paramsPckg().DeviceName().Length() )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   283
        {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   284
        // The name in the parameter package is the latest one, retrieved from 
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   285
        // the remote device during this connection. Update locally.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   286
        iDevice->SetDeviceNameL( BTDeviceNameConverter::ToUTF8L( paramsPckg().DeviceName() ) );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   287
        }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   288
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   289
    TBool locallyInitiated = EFalse;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   290
    TBuf<8> numVal;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   291
    TBluetoothDialogParams::TBTDialogType dialog = TBluetoothDialogParams::EInvalidDialog;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   292
    TBTDialogResourceId resource = ENoResource;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   293
    // Read the notifier parameters (sets iOperation as well)
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   294
    ParseNotifierReqParamsL( locallyInitiated, numVal, dialog, resource );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   295
    // If this is an incoming pairing, we first ask the user to accept it.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   296
    if( !locallyInitiated && !iDedicatedBonding )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   297
        {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   298
        // Ignore the initatior if we initiated bonding.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   299
        StartAcceptPairingQueryL(); // Overrides iOperation
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   300
        }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   301
    else
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   302
        {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   303
        __ASSERT_ALWAYS( resource != ENoResource, PanicServer( EBTNotifPanicBadState ) );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   304
        CheckAutoPairingL( locallyInitiated, numVal );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   305
        // CheckAutoPairingL sets 
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   306
        if( iOperation != EAutoPairing )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   307
            {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   308
            PrepareNotificationL( dialog, resource );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   309
            if( numVal.Length() )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   310
                {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   311
                TInt err = iNotification->SetData( TBluetoothDeviceDialog::EAdditionalDesc, numVal );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   312
                NOTIF_NOTHANDLED( !err )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   313
                }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   314
            }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   315
        }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   316
    BOstraceFunctionExit1( DUMMY_DEVLIST, this );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   317
    }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   318
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   319
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   320
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   321
// Update a notifier, update the outstanding dialog if the notifier request 
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   322
// is currently being served.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   323
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   324
//
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   325
void CBTNotifPairingHelper::UpdatePairingNotifierL( TInt aUid, const TDesC8& aParams )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   326
    {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   327
    (void) aUid;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   328
    TBTNotifierUpdateParams2 params;    // Enough for reading the base class type parameter
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   329
    TPckgC<TBTNotifierUpdateParams2> paramsPckg( params );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   330
    paramsPckg.Set( aParams );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   331
    if( paramsPckg().Type() == TBTNotifierUpdateParams2::EPasskeyDisplay )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   332
        {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   333
        // Paskey display update - keypress on remote device.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   334
        }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   335
    else
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   336
        {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   337
        // name update
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   338
        TBTDeviceNameUpdateParams nameUpdate;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   339
        TPckgC<TBTDeviceNameUpdateParams> nameUpdatePckg( nameUpdate );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   340
        nameUpdatePckg.Set( aParams );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   341
        // The result means result of conversion to unicode
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   342
        if( !nameUpdatePckg().Result() )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   343
            {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   344
            // Only update locally, registry will update us with the same info later on.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   345
            iDevice->SetDeviceNameL( BTDeviceNameConverter::ToUTF8L( nameUpdatePckg().DeviceName() ) );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   346
            if( iNotification )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   347
                {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   348
                // Update the dialog with the new name. It is up to the dialog to 
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   349
                // determine the validity (in case another dialog is shown).
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   350
                //iNotification->Update(  )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   351
                }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   352
            }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   353
        }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   354
    }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   355
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   356
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   357
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   358
// Cancel a request, dismiss the outstanding dialog if the notifier request 
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   359
// is currently being served.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   360
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   361
//
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   362
void CBTNotifPairingHelper::CancelPairingNotifierL( TInt aUid )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   363
    {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   364
    BOstraceFunctionEntry0( DUMMY_DEVLIST );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   365
    // ToDo: we need to check that the UID and the outstanding notification
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   366
    // type are matching?
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   367
    if( iOperation > EIdle && iOperation < EPostPairingOperations && aUid == iNotifierUid &&
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   368
        ( aUid == KBTPinCodeEntryNotifierUid.iUid ||
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   369
          aUid == KBTNumericComparisonNotifierUid.iUid ||
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   370
          aUid == KBTPasskeyDisplayNotifierUid.iUid ) )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   371
        {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   372
        if( iNotification )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   373
            {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   374
            // Cancel the user query
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   375
            // This will also unregister us from the notification.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   376
            TInt err = iNotification->Close();
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   377
            NOTIF_NOTHANDLED( !err )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   378
            iNotification = NULL;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   379
            }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   380
        iOperation = EIdle;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   381
        iNotifierUid = 0;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   382
        // We do not call pairing completed from here, our parent will
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   383
        // check our status by itself, and may delete us.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   384
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   385
        // Any bonding requester needs to be informed though.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   386
        CancelBondingL();
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   387
        }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   388
    BOstraceFunctionExit0( DUMMY_DEVLIST );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   389
    }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   390
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   391
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   392
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   393
// 
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   394
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   395
//
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   396
void CBTNotifPairingHelper::StartJustWorksProcessingL()
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   397
    {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   398
    }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   399
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   400
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   401
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   402
// 
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   403
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   404
//
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   405
void CBTNotifPairingHelper::CancelJustWorksProcessingL()
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   406
    {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   407
    }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   408
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   409
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   410
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   411
// From class MBTNotificationResult.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   412
// Handle a result from a user query.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   413
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   414
//
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   415
void CBTNotifPairingHelper::MBRDataReceived( CHbSymbianVariantMap& aData )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   416
    {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   417
    (void) aData;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   418
    NOTIF_NOTIMPL
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   419
    }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   420
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   421
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   422
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   423
// From class MBTNotificationResult.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   424
// The notification is finished.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   425
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   426
//
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   427
void CBTNotifPairingHelper::MBRNotificationClosed( TInt aError, const TDesC8& aData )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   428
    {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   429
    BOstraceFunctionEntryExt( DUMMY_DEVLIST, this, aError );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   430
    // First unregister from the notification, so we can already get the next one.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   431
    iNotification->RemoveObserver();
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   432
    iNotification = NULL;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   433
    TRAP_IGNORE( NotificationClosedL( aError, aData ) );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   434
    if( iOperation == EIdle )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   435
        {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   436
        // Any error has been communicated already.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   437
        iConnection->PairingCompleted();   // This may delete us.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   438
        }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   439
    BOstraceFunctionExit1( DUMMY_DEVLIST, this );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   440
    }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   441
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   442
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   443
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   444
// From class MBtSimpleActiveObserver.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   445
// Handle the active object completion.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   446
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   447
//
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   448
void CBTNotifPairingHelper::RequestCompletedL( CBtSimpleActive* aActive,
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   449
    TInt aStatus )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   450
    {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   451
    BOstraceFunctionEntry0( DUMMY_DEVLIST );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   452
    switch( aActive->RequestId() )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   453
        {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   454
        case KDedicatedBonding:
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   455
            {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   456
            if( iDedicatedBonding )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   457
                {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   458
                // If the result hasn't been processed already.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   459
                HandleAuthenticationCompleteL( aStatus );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   460
                }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   461
            }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   462
            break;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   463
        default:
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   464
            NOTIF_NOTIMPL
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   465
            break;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   466
        }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   467
    BOstraceFunctionExit0( DUMMY_DEVLIST );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   468
    }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   469
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   470
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   471
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   472
// From class MBtSimpleActiveObserver.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   473
// Cancel and clean up all requests related to the active object.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   474
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   475
//
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   476
void CBTNotifPairingHelper::CancelRequest( TInt aRequestId )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   477
    {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   478
    BOstraceFunctionEntry0( DUMMY_DEVLIST );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   479
    switch( aRequestId )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   480
        {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   481
        case KDedicatedBonding:
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   482
            iBondingSession.Close();
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   483
            break;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   484
        default:
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   485
            NOTIF_NOTIMPL
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   486
            break;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   487
        }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   488
    BOstraceFunctionExit0( DUMMY_DEVLIST );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   489
    }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   490
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   491
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   492
// From class MBtSimpleActiveObserver.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   493
// 
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   494
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   495
//
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   496
void CBTNotifPairingHelper::HandleError( CBtSimpleActive* aActive, 
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   497
        TInt aError )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   498
    {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   499
    (void) aActive;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   500
    (void) aError;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   501
    }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   502
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   503
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   504
// Process the user input and complete the outstanding pairing request.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   505
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   506
//
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   507
void CBTNotifPairingHelper::CompletePairingNotifierL( TInt aError, TBool aResult,
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   508
    const TDesC8& aData )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   509
    {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   510
    BOstraceFunctionEntryExt( DUMMY_DEVLIST, this, aError );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   511
    TInt err = aError;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   512
    TPtrC8 resultData;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   513
    if( !err )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   514
        {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   515
        // The returned data is the entered passkey.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   516
        TBool proceed = iTracker->UpdateBlockingHistoryL( iDevice, aResult );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   517
        if( iOperation == ESspPairing && iNotifierUid == KBTNumericComparisonNotifierUid.iUid )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   518
            {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   519
            // Numeric comparison needs the boolean result passed back.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   520
            TPckgBuf<TBool> userAcceptance( aResult );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   521
            resultData.Set( userAcceptance );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   522
            }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   523
        if( aResult )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   524
            {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   525
            if( iOperation == ELegacyPairing || iOperation == EAutoPairing )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   526
                {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   527
                // Check the passkey entered by the user.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   528
                // The length of the returned data equals the number of characters
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   529
                // entered by the user.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   530
                TBTPinCode pinCode;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   531
                pinCode().iLength = aData.Length();
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   532
                TUint minLen = 0;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   533
                TBool locallyInitiated = EFalse; // Not used here.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   534
                ParsePinCodeReqParamsL( locallyInitiated, minLen );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   535
                if( aData.Length() >= minLen )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   536
                    {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   537
                    // Check that the length of the passkey meets the minimum 
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   538
                    // required pin code length
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   539
                    for( TInt i = 0; i < aData.Length(); i++ )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   540
                        {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   541
                        pinCode().iPIN[i] = aData[i];
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   542
                        }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   543
                    resultData.Set( pinCode );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   544
                    }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   545
                else
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   546
                    {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   547
                    // PIN wasn't long enough. This should be handled by the dialog though.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   548
                    err = KErrCompletion;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   549
                    }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   550
                }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   551
            // Now we just wait for the result to come in.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   552
            if( iOperation != EAutoPairing )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   553
                {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   554
                iOperation = EAwaitingPairingResult; 
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   555
                }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   556
            }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   557
        else
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   558
            {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   559
            err = KErrCancel;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   560
            TBool locallyInitiated = EFalse;    // Needed below
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   561
            TBuf<8> numVal;     // Not needed here.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   562
            TBluetoothDialogParams::TBTDialogType type = TBluetoothDialogParams::EInvalidDialog;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   563
            TBTDialogResourceId resource = ENoResource; // Resources and type are not needed here.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   564
            // Check the notifier parameters
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   565
            ParseNotifierReqParamsL( locallyInitiated, numVal, type, resource );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   566
            if( proceed && locallyInitiated && !iDedicatedBonding )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   567
                {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   568
                // The user denied the connection, ask to block the device.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   569
                // This is only for pairing (and not bonding) initiated by us,
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   570
                // as the user already gets the opportunity to block when
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   571
                // rejecting an incoming pairing request.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   572
                // This case may be for someone requesting to access a service
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   573
                // which requires authentication by us, but not by the remote device.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   574
                iConnection->LaunchBlockingQueryL();
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   575
                // For incoming pairing, blocking is asked after rejecting the 
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   576
                // pairing request. This is done in CompleteAcceptPairingQueryL
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   577
                }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   578
            CompleteBondingL( err );    // Notify the client if there was a bonding request.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   579
            }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   580
        }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   581
    iNotifierUid = 0;   // Clean up notifier data
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   582
    delete iParams;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   583
    iParams = NULL;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   584
    if( err )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   585
        {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   586
        iOperation = EIdle; // We are done now.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   587
        }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   588
    // Complete the message with the result, and result data if any.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   589
    iConnection->CompleteClientRequest( err, resultData );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   590
    BOstraceFunctionExit1( DUMMY_DEVLIST, this );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   591
    }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   592
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   593
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   594
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   595
// Completes a bonding operation.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   596
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   597
//
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   598
void CBTNotifPairingHelper::CompleteBondingL( TInt aError )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   599
    {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   600
    BOstraceFunctionEntryExt( DUMMY_DEVLIST, this, aError );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   601
    if( iDedicatedBonding )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   602
        {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   603
        if( iBondingActive )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   604
            {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   605
            iBondingActive->Cancel();   // Will close subsession;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   606
            }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   607
        iBondingSession.Close();    // In case not active
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   608
        iBondingSocket.Close();
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   609
        }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   610
    // Determine if we try another time.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   611
    if( ( iOperation == EAutoPairing && aError == KHCIErrorBase - EAuthenticationFailure ) ||
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   612
        ( iDedicatedBonding && iOperation == EAwaitingPairingResult &&
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   613
          aError == KErrRemoteDeviceIndicatedNoBonding ) ||
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   614
        aError == KErrServerTerminated )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   615
        {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   616
        // The cases are: 2) autopairing with a headset that has a non-default passkey
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   617
        // 2) SSP dedicated bonding with a device that does not allow that.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   618
        // 3) the pairing server is unavailable (unlikely)
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   619
        // Then we try another time, requesting authentication on a 
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   620
        // RBTPhysicialLinkAdapter
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   621
        BOstrace0( TRACE_NORMAL, DUMMY_DEVLIST,  
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   622
                "[BTNOTIF]\t CBTNotifPairingHelper::CompleteBondingL: trying another time." );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   623
        TInt err = iBondingSocket.Open( iTracker->SocketServerSession(), iConnection->Address() );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   624
        TUint32 linkState = 0;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   625
        if( !err )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   626
            {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   627
            err = iBondingSocket.PhysicalLinkState( linkState );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   628
            }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   629
        if( !err && linkState & ENotifyPhysicalLinkUp )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   630
            {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   631
            err = iBondingSocket.Authenticate();
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   632
            // Now wait for the dialog and then the link state notification
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   633
            }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   634
        else
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   635
            {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   636
            // We need to wait for the link to come up. We wait until our
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   637
            // parent calls us again.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   638
            iBondingSocket.Close();
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   639
            }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   640
        if( err )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   641
            {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   642
            // Cannot continue, show the result to the user.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   643
            BOstrace0( TRACE_NORMAL, DUMMY_DEVLIST,  
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   644
                    "[BTNOTIF]\t CBTNotifPairingHelper::HandleAuthenticationCompleteL: pairing failed, complete message." );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   645
            iOperation = EShowPairingFailure;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   646
            PrepareNotificationL( TBluetoothDialogParams::ENote, EPairingFailure );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   647
            }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   648
        }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   649
    if( iDedicatedBonding && iOperation != EAutoPairing )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   650
        {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   651
        BOstrace0( TRACE_NORMAL, DUMMY_DEVLIST,      
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   652
                "[BTNOTIF]\t CBTNotifPairingHelper::CompleteBondingL: complete message." );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   653
        TInt err = iTracker->Server()->CompleteMessage( iDedicatedBonding, aError, KNullDesC8 );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   654
        NOTIF_NOTHANDLED( !err )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   655
        iDedicatedBonding = 0;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   656
        }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   657
    BOstraceFunctionExit1( DUMMY_DEVLIST, this );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   658
    }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   659
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   660
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   661
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   662
// 
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   663
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   664
//
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   665
void CBTNotifPairingHelper::CompleteJustWorksProcessingL( TInt aError )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   666
    {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   667
    (void) aError;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   668
    }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   669
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   670
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   671
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   672
// Ask the user to allow incoming pairing.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   673
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   674
//
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   675
void CBTNotifPairingHelper::StartAcceptPairingQueryL()
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   676
    {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   677
    iOperation = EAcceptPairing;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   678
    PrepareNotificationL( TBluetoothDialogParams::EQuery, EIncomingPairing );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   679
    // if rejected, the client message is completed in CompleteAcceptPairingQueryL
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   680
    }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   681
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   682
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   683
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   684
// The user was asked to accept an incoming pairing. Process and proceed. 
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   685
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   686
//
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   687
void CBTNotifPairingHelper::CompleteAcceptPairingQueryL( TInt aError, TBool aResult )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   688
    {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   689
    BOstraceFunctionEntry0( DUMMY_DEVLIST );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   690
    // Set our state to idle for now. This may get changed if the user just chose 
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   691
    // to block, or if we have a pending request.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   692
    iOperation = EIdle;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   693
    TInt err = aError;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   694
    if( !err )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   695
        {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   696
        TBool proceed = iTracker->UpdateBlockingHistoryL( iDevice, aResult );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   697
        if( aResult )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   698
            {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   699
            // User accepted, continue to show pairing query.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   700
            // Minimum lenght does not apply, should only be set on outgoing pairing
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   701
            TBool locallyInitiated = EFalse;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   702
            TBuf<8> numVal;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   703
            TBluetoothDialogParams::TBTDialogType dialog = TBluetoothDialogParams::EInvalidDialog;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   704
            TBTDialogResourceId resource = ENoResource;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   705
            // Read the notifier parameters
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   706
            ParseNotifierReqParamsL( locallyInitiated, numVal, dialog, resource );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   707
            __ASSERT_ALWAYS( resource != ENoResource, PanicServer( EBTNotifPanicBadState ) );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   708
            PrepareNotificationL( dialog, resource );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   709
            if( numVal.Length() )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   710
                {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   711
                TInt err = iNotification->SetData( TBluetoothDeviceDialog::EAdditionalDesc, numVal );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   712
                NOTIF_NOTHANDLED( !err )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   713
                }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   714
            }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   715
        else
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   716
            {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   717
            err = KErrCancel;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   718
            if( proceed )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   719
                {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   720
                // The user denied the connection, ask to block the device.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   721
                iConnection->LaunchBlockingQueryL();
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   722
                }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   723
            }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   724
        }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   725
    if( err )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   726
        {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   727
        // The user denied the connection, or something else prevented completion.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   728
        CompletePairingNotifierL( err, EFalse, KNullDesC8 );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   729
        }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   730
    BOstraceFunctionExit0( DUMMY_DEVLIST );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   731
    }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   732
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   733
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   734
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   735
// Launch a dialog for setting the device as trusted.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   736
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   737
//
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   738
void CBTNotifPairingHelper::StartTrustedQueryL()
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   739
    {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   740
    BOstraceFunctionEntry0( DUMMY_DEVLIST );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   741
    // Assume that the registry update has come through by now.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   742
    iOperation = EQueryTrust;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   743
    PrepareNotificationL( TBluetoothDialogParams::EQuery, ESetTrusted );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   744
    BOstraceFunctionExit0( DUMMY_DEVLIST );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   745
    }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   746
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   747
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   748
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   749
// Process the user input for setting the device as trusted.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   750
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   751
//
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   752
void CBTNotifPairingHelper::CompleteTrustedQueryL( TInt aError, TBool aResult )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   753
    {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   754
    BOstraceFunctionEntryExt( DUMMY_DEVLIST, this, aError );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   755
    BOstraceExt2( TRACE_DEBUG, DUMMY_DEVLIST, 
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   756
            "CBTNotifPairingHelper::CompleteTrustedQueryL() err=%d result=%d", aError, aResult );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   757
    iOperation = EIdle; // We are done with pairing now.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   758
    if( !aError && aResult )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   759
        {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   760
        // need to update pairing info from registry before writing trusted status
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   761
        iConnection->UpdateRegistryEntryL(true);
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   762
        }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   763
    CompleteBondingL( KErrNone );   // Notify the client if there was a bonding request.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   764
    BOstraceFunctionExit1( DUMMY_DEVLIST, this );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   765
    }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   766
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   767
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   768
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   769
// Parse the parameters of a request for pairing.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   770
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   771
//
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   772
void CBTNotifPairingHelper::ParseNotifierReqParamsL( TBool& aLocallyInitiated,
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   773
    TDes& aNumVal, TBluetoothDialogParams::TBTDialogType& aDialogType,
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   774
    TBTDialogResourceId& aResourceId )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   775
    {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   776
    // Determine the notifier type by the length of the parameter buffer
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   777
    if( iNotifierUid == KBTPinCodeEntryNotifierUid.iUid )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   778
        {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   779
        aNumVal.Zero();
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   780
        TUint minLen = 0;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   781
        ParsePinCodeReqParamsL( aLocallyInitiated, minLen );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   782
        if( minLen )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   783
            {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   784
            // Don't set zero to this buffer, the buffer length serves for this.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   785
            aNumVal.Num( minLen );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   786
            }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   787
        aDialogType = TBluetoothDialogParams::EInput;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   788
        aResourceId = EPinInput;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   789
        if( iOperation != EAutoPairing )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   790
            {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   791
            iOperation = ELegacyPairing;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   792
            }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   793
        }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   794
    else if( iNotifierUid == KBTNumericComparisonNotifierUid.iUid )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   795
        {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   796
        ParseNumericCompReqParamsL( aLocallyInitiated, aNumVal );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   797
        aDialogType = TBluetoothDialogParams::EQuery;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   798
        aResourceId = ENumericComparison;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   799
        iOperation = ESspPairing;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   800
        }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   801
    else if( iNotifierUid == KBTPasskeyDisplayNotifierUid.iUid )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   802
        {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   803
        ParsePasskeyDisplayReqParamsL( aLocallyInitiated, aNumVal );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   804
        aDialogType = TBluetoothDialogParams::EQuery;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   805
        aResourceId = EPasskeyDisplay;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   806
        iOperation = ESspPairing;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   807
        }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   808
    }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   809
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   810
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   811
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   812
// Parse the parameters of a request for pairing using pin query.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   813
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   814
//
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   815
void CBTNotifPairingHelper::ParsePinCodeReqParamsL( TBool& aLocallyInitiated,
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   816
    TUint& aNumVal )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   817
    {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   818
    TBTPinCodeEntryNotifierParams params;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   819
    TPckgC<TBTPinCodeEntryNotifierParams> paramsPckg( params );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   820
    paramsPckg.Set( *iParams );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   821
    aLocallyInitiated = paramsPckg().LocallyInitiated();
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   822
    aNumVal = paramsPckg().PinCodeMinLength();
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   823
    }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   824
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   825
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   826
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   827
// Parse the parameters of a request for pairing using numeric comparison.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   828
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   829
//
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   830
void CBTNotifPairingHelper::ParseNumericCompReqParamsL( TBool& aLocallyInitiated,
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   831
    TDes& aNumVal )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   832
    {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   833
    TBTNumericComparisonParams params;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   834
    TPckgC<TBTNumericComparisonParams> paramsPckg( params );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   835
    paramsPckg.Set( *iParams );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   836
    aLocallyInitiated = paramsPckg().LocallyInitiated();
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   837
    TBTNumericComparisonParams::TComparisonScenario scenario =
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   838
                paramsPckg().ComparisonScenario();
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   839
    aNumVal.Format( KNumCompFormat, paramsPckg().NumericalValue() );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   840
    }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   841
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   842
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   843
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   844
// Parse the parameters of a request for pairing using passkey display.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   845
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   846
//
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   847
void CBTNotifPairingHelper::ParsePasskeyDisplayReqParamsL( TBool& aLocallyInitiated,
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   848
    TDes& aNumVal )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   849
    {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   850
    TBTPasskeyDisplayParams params;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   851
    TPckgC<TBTPasskeyDisplayParams> paramsPckg( params );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   852
    paramsPckg.Set( *iParams );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   853
    aLocallyInitiated = paramsPckg().LocallyInitiated();
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   854
    aNumVal.Format( KPassKeyFormat, paramsPckg().NumericalValue() );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   855
    }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   856
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   857
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   858
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   859
// Check if we can guess the PIN and complete the notifier without user interaction.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   860
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   861
//
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   862
void CBTNotifPairingHelper::CheckAutoPairingL( TBool aLocallyInitiated, const TDesC& aNumVal )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   863
    {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   864
    TUint minLen = 0;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   865
    if( aNumVal.Length() )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   866
        {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   867
        ParsePinCodeReqParamsL( aLocallyInitiated, minLen );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   868
        }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   869
    // ToDo: Add support for NFC OOB pairing
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   870
    if( iDedicatedBonding && iOperation == ELegacyPairing &&
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   871
        iDevice->DeviceClass().MajorDeviceClass() == EMajorDeviceAV &&
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   872
        iDevice->DeviceClass().MinorDeviceClass() != EMinorDeviceAVHandsfree &&
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   873
        minLen <= KDefaultPinLength )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   874
        {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   875
        // Outgoing bonding with headset and no passkey requirement => AutomatedPairing
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   876
        // Complete message with 0000 and return.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   877
        iOperation = EAutoPairing;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   878
        TBuf8<KDefaultPinLength + sizeof( TPckgBuf<TBool> )> defaultPin( KDefaultPinLength );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   879
        for( TInt i = 0; i < KDefaultPinLength; i++ )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   880
            {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   881
            defaultPin[i] = KDefaultPinValue;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   882
            }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   883
        // Complete the pairing through the function dedicated to that.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   884
        CompletePairingNotifierL( KErrNone, ETrue, defaultPin );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   885
        }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   886
    else if( iOperation == EAutoPairing )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   887
        {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   888
        iOperation = ELegacyPairing;    // Reset the autopairing status
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   889
        }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   890
    }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   891
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   892
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   893
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   894
// Get and configure a notification.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   895
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   896
//
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   897
void CBTNotifPairingHelper::PrepareNotificationL( TBluetoothDialogParams::TBTDialogType aType,
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   898
    TBTDialogResourceId aResourceId )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   899
    {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   900
    BOstraceFunctionEntry0( DUMMY_DEVLIST );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   901
    __ASSERT_ALWAYS( iOperation != EIdle || aType == TBluetoothDialogParams::ENote, PanicServer( EBTNotifPanicBadState ) );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   902
    iNotification = iTracker->NotificationManager()->GetNotification();
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   903
    User::LeaveIfNull( iNotification ); // For OOM exception, leaves with KErrNoMemory
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   904
    iNotification->SetObserver( this );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   905
    iNotification->SetNotificationType( aType, aResourceId );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   906
    TBTDeviceName name;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   907
    GetDeviceNameL( name, *iDevice );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   908
    TInt err = iNotification->SetData( TBluetoothDeviceDialog::EDeviceName, name );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   909
    NOTIF_NOTHANDLED( !err )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   910
    // Re-use name buffer for 16-bit descriptor representation of remote address.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   911
    iConnection->Address().GetReadable( name );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   912
    err = iNotification->SetData( TBluetoothDialogParams::EAddress, name );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   913
    NOTIF_NOTHANDLED( !err )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   914
    err = iNotification->SetData( (TInt) TBluetoothDeviceDialog::EDeviceClass,
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   915
                iDevice->DeviceClass().DeviceClass() );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   916
    err = iTracker->NotificationManager()->QueueNotification( iNotification );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   917
    NOTIF_NOTHANDLED( !err )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   918
    BOstraceFunctionExit0( DUMMY_DEVLIST );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   919
    }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   920
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   921
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   922
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   923
// The notification is finished, handle the result.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   924
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   925
//
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   926
void CBTNotifPairingHelper::NotificationClosedL( TInt aError, const TDesC8& aData )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   927
    {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   928
    BOstraceFunctionEntryExt( DUMMY_DEVLIST, this, aError );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   929
    // Read the result.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   930
    TPckgC<TBool> result( EFalse );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   931
    result.Set( aData.Ptr(), result.Length() ); // Read the part containing the result
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   932
    // Set a pointer descriptor to capture the remaining data, if any.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   933
    TPtrC8 dataPtr( aData.Mid( result.Length() ) );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   934
    switch( iOperation )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   935
        {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   936
        case EAcceptPairing:
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   937
            CompleteAcceptPairingQueryL( aError, result() );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   938
            break;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   939
        case ELegacyPairing:
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   940
        case ESspPairing:
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   941
            CompletePairingNotifierL( aError, result(), dataPtr );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   942
            break;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   943
        case EQueryTrust:
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   944
            CompleteTrustedQueryL( aError, result() );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   945
            break;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   946
        case EShowPairingSuccess:
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   947
            StartTrustedQueryL();
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   948
            break;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   949
        case EShowPairingFailure:
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   950
            // Pairing failure, we are done.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   951
            iOperation = EIdle;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   952
            break;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   953
        default:
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   954
            NOTIF_NOTIMPL
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   955
            break;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   956
        }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   957
    BOstraceFunctionExit1( DUMMY_DEVLIST, this );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   958
    }