bluetoothengine/btnotif/btnotifsrv/src/btnotifoutgoingpairinghandler.cpp
author hgs
Fri, 23 Jul 2010 15:57:13 +0300
changeset 47 9e2a905b887f
parent 42 b72428996822
child 57 5ebadcda06cb
permissions -rw-r--r--
201029_02
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
31
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
     1
/*
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
     2
* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
     3
* All rights reserved.
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
     4
* This component and the accompanying materials are made available
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
     5
* under the terms of "Eclipse Public License v1.0"
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
     6
* which accompanies this distribution, and is available
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
     8
*
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
     9
* Initial Contributors:
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    10
* Nokia Corporation - initial contribution.
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    11
*
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    12
* Contributors:
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    13
*
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    14
* Description: Pairing handler for local device initiated pairing
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    15
*
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    16
*/
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    17
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    18
#include "btnotifoutgoingpairinghandler.h"
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    19
#include <btengconstants.h>
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    20
#include <btservices/btdevextension.h>
42
hgs
parents: 31
diff changeset
    21
#include "btnotifsecuritymanager.h"
hgs
parents: 31
diff changeset
    22
#include "bluetoothtrace.h"
47
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
    23
#include "bluetoothnotification.h"
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
    24
#include "btnotifserver.h"
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
    25
#include "btnotifconnectiontracker.h"
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
    26
#include "btnotificationmanager.h"
31
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    27
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    28
/**  Length of the default PIN. */
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    29
const TInt KDefaultHeadsetPinLength = 4;
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    30
47
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
    31
/** Maximum repeated outgoing pairing attempt.
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
    32
 *  if the pairing fails the UI specs says
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
    33
 *  we can ask twice the user if he/she want 
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
    34
 *  to retry pairing. 
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
    35
 */
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
    36
const TInt KMaxRepeatedPairingAttempt = 2;
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
    37
31
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    38
enum TPairingStageId
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    39
    {
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    40
    /**
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    41
     * no pairing operation ongoing
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    42
     */
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    43
    ENoBonding = 0,
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    44
    
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    45
    /**
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    46
     * pair with dedicated bonding method
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    47
     */
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    48
    EDedicatedBonding = 200,
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    49
    
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    50
    /**
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    51
     * pair with general bonding by establishing L2CAP connection.
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    52
     */
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    53
    EGeneralBonding,  
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    54
    
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    55
    /**
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    56
     * delaying next pairing request for a while
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    57
     */
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    58
    EGeneralBondingRetryTimer,
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    59
    
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    60
    /**
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    61
     * The last pairing retry
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    62
     */
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    63
    EGeneralBondingRetry,
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    64
    
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    65
    /**
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    66
     * disconnecting physical link after pairing operation.
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    67
     * 
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    68
     * todo: not used yet.
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    69
     */
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    70
    EDisconnectLinkAfterBonding,
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    71
    };
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    72
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    73
/**  SDP PSM (used for pairing) */
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    74
const TInt KSDPPSM = 0x0001;
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    75
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    76
// Delay time to void Repeated Attempts on pairing
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    77
const TInt KGeneralBondingRetryDelayMicroSeconds = 5000000; // 5.0s
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    78
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    79
// ======== MEMBER FUNCTIONS ========
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    80
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    81
// ---------------------------------------------------------------------------
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    82
// C++ default constructor
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    83
// ---------------------------------------------------------------------------
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    84
//
42
hgs
parents: 31
diff changeset
    85
CBTNotifOutgoingPairingHandler::CBTNotifOutgoingPairingHandler( CBTNotifSecurityManager& aParent, const TBTDevAddr& aAddr)
31
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    86
    :  CBTNotifBasePairingHandler( aParent, aAddr )
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    87
    {
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    88
    }
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    89
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    90
// ---------------------------------------------------------------------------
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    91
// Symbian 2nd-phase constructor
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    92
// ---------------------------------------------------------------------------
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    93
//
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    94
void CBTNotifOutgoingPairingHandler::ConstructL()
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    95
    {
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    96
    BaseConstructL();
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    97
    User::LeaveIfError( iTimer.CreateLocal() );
47
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
    98
    iPairingAttempt = KMaxRepeatedPairingAttempt;
31
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    99
    }
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   100
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   101
// ---------------------------------------------------------------------------
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   102
// NewL
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   103
// ---------------------------------------------------------------------------
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   104
//
42
hgs
parents: 31
diff changeset
   105
CBTNotifBasePairingHandler* CBTNotifOutgoingPairingHandler::NewL( CBTNotifSecurityManager& aParent, 
31
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   106
        const TBTDevAddr& aAddr )
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   107
    {
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   108
    CBTNotifOutgoingPairingHandler* self = new( ELeave ) CBTNotifOutgoingPairingHandler( aParent, aAddr );
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   109
    CleanupStack::PushL( self );
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   110
    self->ConstructL();
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   111
    CleanupStack::Pop( self );
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   112
    return self;
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   113
    }
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   114
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   115
// ---------------------------------------------------------------------------
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   116
// Destructor
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   117
// ---------------------------------------------------------------------------
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   118
//
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   119
CBTNotifOutgoingPairingHandler::~CBTNotifOutgoingPairingHandler()
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   120
    {
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   121
    if ( iActive ) 
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   122
        {
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   123
        iActive->Cancel();
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   124
        }
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   125
    iBondingSession.Close();
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   126
    iSocket.Close();
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   127
    iTimer.Close();
47
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   128
    if( iNotification )
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   129
        {
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   130
        // Clear the notification callback, we cannot receive them anymore.
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   131
        iNotification->RemoveObserver();
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   132
        iNotification->Close(); // Also dequeues the notification from the queue.
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   133
        iNotification = NULL;
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   134
        }
31
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   135
    }
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   136
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   137
// ---------------------------------------------------------------------------
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   138
// Simply deny the request as this is handing outgoing pairing
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   139
// ---------------------------------------------------------------------------
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   140
//
47
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   141
TInt CBTNotifOutgoingPairingHandler::ObserveIncomingPair( const TBTDevAddr& aAddr )
31
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   142
    {
47
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   143
    (void)aAddr;
31
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   144
    return KErrServerBusy;
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   145
    }
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   146
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   147
// ---------------------------------------------------------------------------
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   148
// Accept the request only this device is not busy with another pairing request.
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   149
// ---------------------------------------------------------------------------
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   150
//
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   151
void CBTNotifOutgoingPairingHandler::HandleOutgoingPairL( const TBTDevAddr& aAddr, TUint aCod )
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   152
    {
42
hgs
parents: 31
diff changeset
   153
    BOstrace1(TRACE_DEBUG,DUMMY_DEVLIST," cod 0x%08x", aCod );
31
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   154
    if ( iActive->IsActive() || aAddr != iAddr )
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   155
        {
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   156
        // we don't allow another pairing request.
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   157
        User::Leave( KErrServerBusy );
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   158
        }
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   159
    iAddr = aAddr;
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   160
    iCod = TBTDeviceClass( aCod );
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   161
    UnSetPairResult();
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   162
    iParent.UnpairDevice( iAddr );
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   163
    if ( CBtDevExtension::IsHeadset( iCod ) )
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   164
        {
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   165
        // If the devie is a headset, set to 0000 pin auto pairing
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   166
        iPairMode = EBTOutgoingHeadsetAutoPairing;
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   167
        }
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   168
    else
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   169
        {
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   170
        iPairMode = EBTOutgoingNoneHeadsetPairing;
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   171
        }
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   172
    DoPairingL();
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   173
    }
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   174
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   175
// ---------------------------------------------------------------------------
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   176
// Cancels an outstanding pair request by self-destruct
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   177
// ---------------------------------------------------------------------------
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   178
//
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   179
void CBTNotifOutgoingPairingHandler::CancelOutgoingPair()
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   180
    {
42
hgs
parents: 31
diff changeset
   181
    BOstraceFunctionEntry0( DUMMY_DEVLIST );
31
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   182
    iParent.RenewPairingHandler( NULL );
47
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   183
    if( iNotification )
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   184
        {
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   185
        // Cancel the user query
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   186
        // This will also unregister us from the notification.
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   187
        TInt err = iNotification->Close();
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   188
        NOTIF_NOTHANDLED( !err )
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   189
        iNotification = NULL;
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   190
        }
31
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   191
    }
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   192
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   193
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   194
// ---------------------------------------------------------------------------
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   195
// when phone initiated a pairing request towards a headset,
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   196
// Pin code 0000 is first tried.
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   197
// ---------------------------------------------------------------------------
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   198
//
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   199
void CBTNotifOutgoingPairingHandler::GetPinCode( 
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   200
        TBTPinCode& aPin, const TBTDevAddr& aAddr, TInt aMinPinLength )
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   201
    {
42
hgs
parents: 31
diff changeset
   202
    BOstraceFunctionEntry0( DUMMY_DEVLIST );
31
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   203
    aPin().iLength = 0;
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   204
    if ( aMinPinLength <= KDefaultHeadsetPinLength 
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   205
            && aAddr == iAddr
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   206
            && iPairMode == EBTOutgoingHeadsetAutoPairing)
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   207
        {
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   208
        // if the pairing requires a stronger security level (indicated
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   209
        // by aMinPinLength), 
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   210
        // 0000 will not be supplied as it does not mmet the security
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   211
        // requirements
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   212
        const TUint8 KZeroPinValue = '0';
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   213
        for (TInt i = 0; i < KDefaultHeadsetPinLength; ++i)
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   214
            {
47
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   215
                aPin().iPIN[i] = KZeroPinValue;
31
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   216
            }
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   217
        aPin().iLength = KDefaultHeadsetPinLength;
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   218
        }
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   219
    }
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   220
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   221
// ---------------------------------------------------------------------------
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   222
// Abort pairing handling, request the owner to destroy this.
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   223
// ---------------------------------------------------------------------------
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   224
//
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   225
void CBTNotifOutgoingPairingHandler::StopPairHandling( const TBTDevAddr& aAddr )
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   226
    {
42
hgs
parents: 31
diff changeset
   227
    BOstraceFunctionEntry0( DUMMY_DEVLIST );
31
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   228
    if ( aAddr == iAddr )
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   229
        {
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   230
        iParent.OutgoingPairCompleted( KErrCancel );
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   231
        iParent.RenewPairingHandler( NULL );
47
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   232
        if( iNotification )
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   233
            {
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   234
            // Cancel the user query
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   235
            // This will also unregister us from the notification.
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   236
            TInt err = iNotification->Close();
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   237
            NOTIF_NOTHANDLED( !err )
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   238
            iNotification = NULL;
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   239
            }
31
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   240
        }
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   241
    }
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   242
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   243
// ---------------------------------------------------------------------------
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   244
// Pairing result will be received when pairing operation completes.
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   245
// ---------------------------------------------------------------------------
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   246
//
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   247
void CBTNotifOutgoingPairingHandler::DoHandlePairServerResult( TInt aResult )
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   248
    {
42
hgs
parents: 31
diff changeset
   249
    BOstraceFunctionEntry0( DUMMY_DEVLIST );
31
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   250
	if (aResult == (KHCIErrorBase-EPairingNotAllowed))
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   251
		{
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   252
		// if EPairingNotAllowed is recieved then any further pairing attempts will fail
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   253
		// so don't attampt to pair
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   254
        iPairMode = EBTOutgoingPairNone;
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   255
		}
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   256
    }
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   257
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   258
// ---------------------------------------------------------------------------
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   259
// Cancels possible outstanding pairing and notify user pair success.
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   260
// ---------------------------------------------------------------------------
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   261
//
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   262
void CBTNotifOutgoingPairingHandler::DoHandleRegistryNewPairedEvent( 
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   263
        const TBTNamelessDevice& aDev )
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   264
    {
42
hgs
parents: 31
diff changeset
   265
    BOstraceFunctionEntry0( DUMMY_DEVLIST );
31
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   266
    TInt err( KErrNone );
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   267
    // If pairing was performed using Just Works mode, we set a 
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   268
    // UICookie to indicate that the device is successfully 
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   269
    // bonded so that this device will be listed in paired device view of
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   270
    // bluetooth application:
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   271
    if ( aDev.LinkKeyType() == ELinkKeyUnauthenticatedNonUpgradable )
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   272
        {
42
hgs
parents: 31
diff changeset
   273
        BOstrace0(TRACE_DEBUG,DUMMY_DEVLIST,"[BTNOTIF] Outgoing Pairing, Just Works pairing");
31
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   274
        err = iParent.AddUiCookieJustWorksPaired( aDev );
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   275
        }
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   276
    iActive->Cancel();
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   277
    SetPairResult( err ? err : KErrNone );
42
hgs
parents: 31
diff changeset
   278
    if(err == KErrNone){
hgs
parents: 31
diff changeset
   279
    TRAP_IGNORE(ShowPairingResultNoteL(err));
hgs
parents: 31
diff changeset
   280
    }
31
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   281
    iParent.OutgoingPairCompleted( err );
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   282
    iParent.RenewPairingHandler( NULL );
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   283
    }
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   284
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   285
// ---------------------------------------------------------------------------
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   286
// From class MBTNotifPairingAOObserver.
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   287
// Based on the result code, decides the next operation, either try pairing 
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   288
// with another mode, or complete pair request.
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   289
// ---------------------------------------------------------------------------
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   290
//
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   291
void CBTNotifOutgoingPairingHandler::RequestCompletedL( 
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   292
        CBtSimpleActive* aActive, TInt aStatus )
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   293
    {
42
hgs
parents: 31
diff changeset
   294
    BOstraceFunctionEntry0( DUMMY_DEVLIST );
hgs
parents: 31
diff changeset
   295
    BOstraceExt3(TRACE_DEBUG,DUMMY_DEVLIST,"reqid %d, status: %d, pair mode %d ", aActive->RequestId(), aStatus, iPairMode);
31
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   296
    if( aActive->RequestId() == EDedicatedBonding && 
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   297
				( aStatus == KErrRemoteDeviceIndicatedNoBonding || 
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   298
					( aStatus && iPairMode != EBTOutgoingNoneHeadsetPairing && iPairMode != EBTOutgoingPairNone ) )   )
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   299
        {
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   300
        // try general pairing if the remote doesn't have dedicated bonding, or
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   301
        // pairing fails with a headset.
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   302
        DoPairingL();
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   303
        }
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   304
    else if ( aStatus && iPairMode == EBTOutgoingHeadsetAutoPairing )
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   305
        {
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   306
        iPairMode = EBTOutgoingHeadsetManualPairing;
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   307
        // auto pairing with headset failed, try to pair again with manual pin:
42
hgs
parents: 31
diff changeset
   308
        BOstrace0(TRACE_DEBUG,DUMMY_DEVLIST," auto pairing failed, switch to manual pairing");     
31
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   309
        DoPairingL();
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   310
        }
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   311
    else if ( aStatus && aActive->RequestId() == EGeneralBonding && 
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   312
              iPairMode == EBTOutgoingHeadsetManualPairing )
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   313
        {
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   314
        // pairing headset with manual pin failed, wait for a while and try again:
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   315
        iActive->SetRequestId( EGeneralBondingRetryTimer );
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   316
        iTimer.After( iActive->iStatus, KGeneralBondingRetryDelayMicroSeconds );
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   317
        iActive->GoActive();
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   318
        }
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   319
    else if( aActive->RequestId() == EGeneralBondingRetryTimer )
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   320
        {
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   321
        // try to pair headset again with manual pin again:
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   322
        DoPairingL();
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   323
        }
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   324
    else if ( aStatus )
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   325
        {
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   326
        // we only starts showing note if pairing failed.
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   327
        // For a successful pair, we must wait until registry has been updated.
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   328
        if ( !IsPairResultSet() )
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   329
            {
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   330
            SetPairResult( aStatus );
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   331
            }
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   332
        if ( aStatus )
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   333
            {
47
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   334
            // retry pairing
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   335
            if(aStatus && iPairingAttempt > 0)
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   336
                {
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   337
                if(aActive->RequestId() == EGeneralBondingRetry && iPairMode == EBTOutgoingHeadsetManualPairing)
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   338
                    {
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   339
                    // Headset pairing failed, reset and try again from auto pairing
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   340
                    iActive->SetRequestId(EGeneralBonding);
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   341
                    }
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   342
                iPairingAttempt --;
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   343
                ShowPairingRetryDialog();
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   344
                }
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   345
            else
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   346
                {
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   347
                iPairingAttempt --;
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   348
                ShowPairingFailureDialog();
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   349
                }
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   350
             }
31
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   351
        }
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   352
    }
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   353
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   354
// ---------------------------------------------------------------------------
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   355
// From class MBTEngActiveObserver.
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   356
// cancels an outstanding request according to the given id.
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   357
// ---------------------------------------------------------------------------
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   358
//
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   359
void CBTNotifOutgoingPairingHandler::CancelRequest( TInt aRequestId )
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   360
    {
42
hgs
parents: 31
diff changeset
   361
    BOstraceFunctionEntry0( DUMMY_DEVLIST );
31
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   362
    switch ( aRequestId )
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   363
        {
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   364
        case EDedicatedBonding:
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   365
            {
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   366
            iBondingSession.Close();
42
hgs
parents: 31
diff changeset
   367
            break;
31
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   368
            }
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   369
        case EGeneralBonding:
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   370
        case EGeneralBondingRetry:
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   371
            {
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   372
            iSocket.CancelConnect();
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   373
            iSocket.Close();
42
hgs
parents: 31
diff changeset
   374
            break;
31
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   375
            }
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   376
        case EGeneralBondingRetryTimer:
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   377
            {
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   378
            iTimer.Cancel();
42
hgs
parents: 31
diff changeset
   379
            break;
31
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   380
            }     
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   381
        }
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   382
    }
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   383
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   384
// ---------------------------------------------------------------------------
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   385
// From class MBTEngActiveObserver.
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   386
// Handles a leave in RequestCompleted by self-destructing.
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   387
// ---------------------------------------------------------------------------
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   388
//
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   389
void CBTNotifOutgoingPairingHandler::HandleError( 
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   390
        CBtSimpleActive* aActive, TInt aError )
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   391
    {
42
hgs
parents: 31
diff changeset
   392
    BOstrace1(TRACE_DEBUG,DUMMY_DEVLIST,"error: %d", aError );
31
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   393
    // Our RunL can actually not leave, so we should never reach here.
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   394
    (void) aActive;
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   395
    iParent.OutgoingPairCompleted( aError );
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   396
    iParent.RenewPairingHandler( NULL );
47
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   397
    if( iNotification )
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   398
        {
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   399
        // Cancel the user query
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   400
        // This will also unregister us from the notification.
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   401
        TInt err = iNotification->Close();
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   402
        NOTIF_NOTHANDLED( !err )
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   403
        iNotification = NULL;
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   404
        }
31
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   405
    }
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   406
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   407
// ---------------------------------------------------------------------------
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   408
// decide the next state and issue pair request
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   409
// ---------------------------------------------------------------------------
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   410
//
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   411
void CBTNotifOutgoingPairingHandler::DoPairingL()
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   412
    {
42
hgs
parents: 31
diff changeset
   413
    BOstraceFunctionEntry0( DUMMY_DEVLIST );
31
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   414
    TPairingStageId currentMode = ( TPairingStageId ) iActive->RequestId();
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   415
    ASSERT( !iActive->IsActive() );
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   416
    TPairingStageId nextMode( EGeneralBonding );
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   417
    
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   418
    // if running BTv2.0 stack, dedicated bonding method 
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   419
    // is not available.
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   420
    if ( currentMode == ENoBonding && iParent.PairingServer() != NULL )
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   421
        {
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   422
        nextMode = EDedicatedBonding;
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   423
        }
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   424
    else if(currentMode == EGeneralBondingRetryTimer)
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   425
        {
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   426
        nextMode = EGeneralBondingRetry;
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   427
        }
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   428
    
42
hgs
parents: 31
diff changeset
   429
    BOstraceExt2(TRACE_DEBUG,DUMMY_DEVLIST,"[BTENG] CBTEngOtgPair::DoPairingL: bonding mode: pre %d, next %d", currentMode, nextMode);
31
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   430
    
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   431
    iActive->SetRequestId( nextMode );
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   432
    if ( nextMode == EDedicatedBonding )
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   433
        {
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   434
        iBondingSession.Start( *iParent.PairingServer(), iAddr, iActive->RequestStatus() );          
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   435
        }
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   436
    else
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   437
        {
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   438
        TBTServiceSecurity sec;
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   439
        sec.SetAuthentication( ETrue );
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   440
        iSockAddr.SetBTAddr( iAddr );
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   441
        iSockAddr.SetPort(KSDPPSM);
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   442
        iSockAddr.SetSecurity( sec );    
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   443
        iSocket.Close();
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   444
        User::LeaveIfError( iSocket.Open( iParent.SocketServ(), KL2CAPDesC ) );
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   445
        iSocket.Connect( iSockAddr, iActive->RequestStatus() );
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   446
        }
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   447
    iActive->GoActive();
42
hgs
parents: 31
diff changeset
   448
    BOstraceFunctionExit0( DUMMY_DEVLIST );
31
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   449
    }
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   450
47
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   451
// ---------------------------------------------------------------------------
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   452
// From class MBTNotificationResult.
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   453
// Handle a result from a user query.
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   454
// ---------------------------------------------------------------------------
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   455
//
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   456
void CBTNotifOutgoingPairingHandler::MBRDataReceived( CHbSymbianVariantMap& aData )
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   457
    {
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   458
    BOstraceFunctionEntry0( DUMMY_DEVLIST );
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   459
    (void) aData;
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   460
    BOstraceFunctionExit0( DUMMY_DEVLIST );
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   461
    }
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   462
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   463
// ---------------------------------------------------------------------------
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   464
// From class MBTNotificationResult.
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   465
// The notification is finished.
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   466
// ---------------------------------------------------------------------------
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   467
//
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   468
void CBTNotifOutgoingPairingHandler::MBRNotificationClosed( TInt aError, const TDesC8& aData )
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   469
    {
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   470
    BOstraceFunctionEntryExt( DUMMY_DEVLIST, this, aError );
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   471
    // First unregister from the notification, so we can already get the next one.
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   472
    iNotification->RemoveObserver();
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   473
    iNotification = NULL;
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   474
    TRAP_IGNORE( NotificationClosedL( aError, aData ) );
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   475
    BOstraceFunctionExit1( DUMMY_DEVLIST, this );
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   476
    }
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   477
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   478
// ---------------------------------------------------------------------------
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   479
// Get and configure a notification.
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   480
// ---------------------------------------------------------------------------
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   481
//
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   482
void CBTNotifOutgoingPairingHandler::PrepareNotificationL( TBluetoothDialogParams::TBTDialogType aType,
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   483
    TBTDialogResourceId aResourceId )
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   484
    {
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   485
    BOstraceFunctionEntry0( DUMMY_DEVLIST );
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   486
    iNotification = 
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   487
            iParent.ConnectionTracker().NotificationManager()->GetNotification();
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   488
    User::LeaveIfNull( iNotification ); // For OOM exception, leaves with KErrNoMemory
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   489
    iNotification->SetObserver( this );
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   490
    iNotification->SetNotificationType( aType, aResourceId );
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   491
    const CBtDevExtension* dev = iParent.BTDevRepository().Device(iAddr);
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   492
    if(dev)
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   493
        {
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   494
        User::LeaveIfError(iNotification->SetData( TBluetoothDeviceDialog::EDeviceName, dev->Alias()));
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   495
        }
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   496
    else
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   497
        {
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   498
        TBTDeviceName name;
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   499
        iAddr.GetReadable(name);
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   500
        User::LeaveIfError(iNotification->SetData( TBluetoothDeviceDialog::EDeviceName, name));
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   501
        NOTIF_NOTHANDLED( !err )            
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   502
        }
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   503
    iParent.ConnectionTracker().NotificationManager()->QueueNotificationL( iNotification);
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   504
    NOTIF_NOTHANDLED( !err )
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   505
    BOstraceFunctionExit0( DUMMY_DEVLIST );
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   506
    }
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   507
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   508
// ---------------------------------------------------------------------------
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   509
// The notification is finished, handle the result.
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   510
// ---------------------------------------------------------------------------
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   511
//
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   512
void CBTNotifOutgoingPairingHandler::NotificationClosedL( TInt aError, const TDesC8& aData )
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   513
    {
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   514
    BOstraceFunctionEntryExt( DUMMY_DEVLIST, this, aError );
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   515
    // Read the result.
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   516
    TPckgC<TBool> result( EFalse );
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   517
    result.Set( aData.Ptr(), result.Length() ); // Read the part containing the result
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   518
    // Set a pointer descriptor to capture the remaining data, if any.
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   519
    TPtrC8 dataPtr( aData.Mid( result.Length() ) );
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   520
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   521
    if(result() && iPairingAttempt >= 0)
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   522
        {
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   523
            HandleOutgoingPairL(iAddr,iCod.DeviceClass());
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   524
        }
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   525
    else
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   526
        {
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   527
            iPairingAttempt = KMaxRepeatedPairingAttempt; // reset the counter
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   528
            iParent.OutgoingPairCompleted( KErrCancel );
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   529
            iParent.RenewPairingHandler( NULL );
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   530
        }
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   531
    BOstraceFunctionExit1( DUMMY_DEVLIST, this );
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   532
    }
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   533
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   534
// ---------------------------------------------------------------------------
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   535
// Show a dialog to ask the user to retry the pairing
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   536
// ---------------------------------------------------------------------------
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   537
//
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   538
void CBTNotifOutgoingPairingHandler::ShowPairingRetryDialog()
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   539
    {
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   540
    PrepareNotificationL( TBluetoothDialogParams::EQuery, EPairingFailureRetry);
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   541
    }
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   542
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   543
// ---------------------------------------------------------------------------
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   544
// Show a dialog to tell the user pairing retry attempt failed
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   545
// ---------------------------------------------------------------------------
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   546
//
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   547
void CBTNotifOutgoingPairingHandler::ShowPairingFailureDialog()
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   548
    {
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   549
    PrepareNotificationL( TBluetoothDialogParams::EQuery, EPairingFailureOk );
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   550
    }
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   551
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   552
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   553