bluetoothengine/btnotif/btnotifsrv/src/btnotifconnection.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        : btnotifconnection.cpp
48ae3789ce00 201017_2
hgs
parents:
diff changeset
     4
*  Part of     : bluetoothengine / btnotif
48ae3789ce00 201017_2
hgs
parents:
diff changeset
     5
*  Description : Class for observing events of a single connection, and for 
48ae3789ce00 201017_2
hgs
parents:
diff changeset
     6
*                managing any user notifications related to the connection.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
     7
*
48ae3789ce00 201017_2
hgs
parents:
diff changeset
     8
*  Copyright © 2009 Nokia Corporation and/or its subsidiary(-ies).
48ae3789ce00 201017_2
hgs
parents:
diff changeset
     9
*  All rights reserved.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    10
*  This component and the accompanying materials are made available
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    11
*  under the terms of "Eclipse Public License v1.0"
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    12
*  which accompanies this distribution, and is available
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    13
*  at the URL "http://www.eclipse.org/legal/epl-v10.html".
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    14
*
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    15
*  Initial Contributors:
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    16
*  Nokia Corporation - initial contribution.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    17
*
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    18
*  Contributors:
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    19
*  Nokia Corporation
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    20
* ============================================================================
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    21
* Template version: 4.1
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    22
*/
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    23
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    24
#include "btnotifconnection.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 "btnotifconnectiontracker.h"
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    31
#include "btnotifpairinghelper.h"
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    32
#include "btnotificationmanager.h"
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    33
#include "btnotifclientserver.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 baseband connection watcher active object. */
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    37
const TInt KConnectionWatcher = 40;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    38
/**  Id for the registry watcher active object. */
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    39
const TInt KRegistryWatcher = 41;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    40
/**  Id for the active object for updating the registry. */
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    41
const TInt KRegistryRetriever = 42;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    42
/**  Event mask for subscribing to baseband connection events  
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    43
 * (need to check if these are appropriate). */
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    44
const TInt KBbEventMask = ENotifyAnyRole | ENotifyAuthenticationComplete |
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    45
    ENotifyPhysicalLinkUp | ENotifyPhysicalLinkDown | ENotifyPhysicalLinkError;
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
// Decide the device name to display from the device information, and 
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    52
// converts the name if necessary.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    53
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    54
//
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    55
void GetDeviceNameL( TBTDeviceName& aName, const CBTDevice& aDevice )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    56
    {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    57
    if( aDevice.IsValidFriendlyName() )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    58
        {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    59
        aName.Copy( aDevice.FriendlyName() );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    60
        }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    61
    else
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    62
        {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    63
        aName.Zero();
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    64
        if( aDevice.IsValidDeviceName() )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    65
            {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    66
            aName = BTDeviceNameConverter::ToUnicodeL( aDevice.DeviceName() );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    67
            }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    68
        }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    69
    }
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
// Compare 2 device records device pairing has succeeded.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    74
// aDev2 is the updated device record, aDev1 is the previous record.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    75
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    76
//
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    77
TBool CheckRegistryPairedStatus( const CBTDevice* aOrig, const CBTDevice* aNew )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    78
    {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    79
    TBool result = EFalse;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    80
    // Use the device class to check that this has any valid information.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    81
    if( aOrig->AsNamelessDevice().IsValidDeviceClass() &&
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    82
        !( aOrig->IsValidPaired() && aOrig->IsPaired() ) ||
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    83
        aOrig->LinkKeyType() == ELinkKeyUnauthenticatedUpgradable )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    84
        {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    85
        // Only consider the result if the original device is not marked as paired.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    86
        if( aNew->IsValidPaired() && aNew->IsPaired() && aNew->IsValidLinkKey() && 
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    87
            aNew->LinkKeyType() != ELinkKeyUnauthenticatedUpgradable )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    88
            {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    89
            // The new device record has valid pairing information, so
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    90
            // this device is now paired.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    91
            result = ETrue;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    92
            }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    93
        }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    94
    return result;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    95
    }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    96
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    97
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    98
// ======== MEMBER FUNCTIONS ========
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    99
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   100
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   101
// C++ default constructor
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   102
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   103
//
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   104
CBTNotifConnection::CBTNotifConnection(  const TBTDevAddr& aAddr,
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   105
    CBTNotifConnectionTracker* aTracker )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   106
:   iAddr( aAddr ),
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   107
    iTracker( aTracker )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   108
    {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   109
    }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   110
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   111
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   112
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   113
// Symbian 2nd-phase constructor
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   114
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   115
//
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   116
void CBTNotifConnection::ConstructL()
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   117
    {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   118
    BOstraceFunctionEntry0( DUMMY_DEVLIST );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   119
    iDevice = CBTDevice::NewL( iAddr );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   120
    iPhyActive = CBtSimpleActive::NewL(*this, KConnectionWatcher );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   121
    iRegActive = CBtSimpleActive::NewL( *this, KRegistryRetriever );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   122
    // ToDo: need to check if this succeeds if a connection is 
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   123
    // being created, in case of outgoing pairing.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   124
    User::LeaveIfError( iPhyLink.Open( iTracker->SocketServerSession(), iAddr ) );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   125
    // Subscribe to events.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   126
    iBasebandEvent.FillZ(); // To be sure that we are not reading false events.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   127
    iPhyLink.NotifyNextBasebandChangeEvent( iBasebandEvent,
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   128
                iPhyActive->RequestStatus(), KBbEventMask );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   129
    iPhyActive->GoActive();
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   130
    // Get the details from BT registry
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   131
    TBTRegistrySearch pattern;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   132
    pattern.FindAddress( iAddr );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   133
    User::LeaveIfError( iRegistry.Open( iTracker->RegistryServerSession() ) );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   134
    iRegistry.CreateView( pattern, iRegActive->RequestStatus() );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   135
    iRegActive->GoActive();
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   136
    iCurrentOp = EReadingRegistry;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   137
    iRegDevArray  = new CBTDeviceArray(1);  // only 1 entry ever used
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   138
    // ToDo: more initialization needed?
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   139
    BOstraceFunctionExit0( DUMMY_DEVLIST );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   140
    }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   141
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   142
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   143
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   144
// NewLC.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   145
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   146
//
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   147
CBTNotifConnection* CBTNotifConnection::NewLC( const TBTDevAddr& aAddr,
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   148
    CBTNotifConnectionTracker* aTracker )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   149
    {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   150
    CBTNotifConnection* self = new( ELeave ) CBTNotifConnection( aAddr, aTracker );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   151
    CleanupStack::PushL( self );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   152
    self->ConstructL();
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   153
    return self;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   154
    }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   155
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   156
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   157
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   158
// Destructor
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   159
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   160
//
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   161
CBTNotifConnection::~CBTNotifConnection()
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   162
    {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   163
    BOstraceFunctionEntry0( DUMMY_DEVLIST );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   164
    if( iNotification )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   165
        {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   166
        // Clear the notification callback, we cannot receive them anymore.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   167
        iNotification->RemoveObserver();
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   168
        iNotification->Close(); // Also dequeues the notification from the queue.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   169
        iNotification = NULL;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   170
        }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   171
    delete iRegActive;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   172
    delete iRegistryResponse;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   173
    iRegistry.Close();
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   174
    delete iDevMan;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   175
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   176
    delete iPhyActive;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   177
    iPhyLink.Close();
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   178
    delete iDevice;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   179
    delete iPairingHelper;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   180
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   181
    while( iMsgHandleQ.Count() )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   182
        {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   183
        CompleteClientRequest( KErrDisconnected, KNullDesC8 );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   184
        }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   185
    iMsgHandleQ.Close();
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   186
    iAcceptedConnections.Close();
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   187
    iDeniedConnections.Close();
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   188
    iRegDevArray->ResetAndDestroy(); 
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   189
    delete iRegDevArray;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   190
    BOstraceFunctionExit0( DUMMY_DEVLIST );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   191
    }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   192
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   193
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   194
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   195
// Check what to do next.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   196
// This function should be called whenever we may be ready for the next
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   197
// request/action, which is from any callback function i.e. 
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   198
// MBAORequestCompletedL, MBRNotificationClosed, HandleNotifierRequestL and
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   199
// CancelNotifierRequestL.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   200
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   201
//
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   202
void CBTNotifConnection::CheckNextOperationL()
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   203
    {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   204
    BOstraceFunctionEntry0( DUMMY_DEVLIST );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   205
    if( iCurrentOp == EIdle )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   206
        {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   207
        // Check the link state, to see if it has gone down already.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   208
        TUint32 linkState = 0;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   209
        TInt err = iPhyLink.PhysicalLinkState( linkState );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   210
        TBool linkDown = linkState & ENotifyPhysicalLinkDown;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   211
        if( ( !err && linkDown ) || err == KErrDisconnected )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   212
            {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   213
            // The link state tells us that the link is down,
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   214
            // inform the connection tracker the we are done.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   215
            iTracker->HandleLinkCountChangeL();
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   216
            // Note that we may be deleted now!
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   217
            }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   218
        else if( iMsgHandleQ.Count() )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   219
            {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   220
            // Get the next request and handle it.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   221
            // ToDo: differentiate between notifier and pairing message!
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   222
            const RMessage2* message = iTracker->Server()->FindMessageFromHandle( iMsgHandleQ[0] );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   223
            NOTIF_NOTHANDLED( message )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   224
            TInt opcode = message->Function();
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   225
            if( opcode <= EBTNotifUpdateNotifier )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   226
                {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   227
                TBuf8<0x250> paramsBuf;    // Size needs to be long enough to read all possible parameter sizes.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   228
                message->ReadL( EBTNotifSrvParamSlot, paramsBuf );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   229
                HandleNotifierRequestL( paramsBuf, *message );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   230
                }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   231
            else
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   232
                {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   233
                iMsgHandleQ.Remove( 0 );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   234
                StartBondingL( *message );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   235
                }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   236
            }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   237
        }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   238
    BOstraceFunctionExit0( DUMMY_DEVLIST );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   239
    }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   240
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   241
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   242
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   243
// Complete the first outstanding client request and removes it from the queue.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   244
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   245
//
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   246
void CBTNotifConnection::CompleteClientRequest( TInt aReason, const TDesC8& aReply )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   247
    {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   248
    BOstraceFunctionEntry0( DUMMY_DEVLIST );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   249
    NOTIF_NOTHANDLED( iMsgHandleQ.Count() )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   250
    TInt err = iTracker->Server()->CompleteMessage( iMsgHandleQ[0], aReason, aReply );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   251
    NOTIF_NOTHANDLED( !err )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   252
    iMsgHandleQ.Remove( 0 );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   253
    BOstraceFunctionExit0( DUMMY_DEVLIST );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   254
    }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   255
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   256
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   257
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   258
// Distinguish a request and pass to corresponding handle.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   259
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   260
//
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   261
void CBTNotifConnection::HandleNotifierRequestL( const TDesC8& aParams,
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   262
    const RMessage2& aMessage )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   263
    {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   264
    BOstraceFunctionEntryExt( DUMMY_DEVLIST, this, aMessage.Int0() );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   265
    if( !iMsgHandleQ.Count() || iMsgHandleQ[0] != aMessage.Handle() )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   266
        {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   267
        // If we are processing a queued request, we of course don't queue 
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   268
        // it again. In that case we are handling the first request from the queue.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   269
        iMsgHandleQ.AppendL( aMessage.Handle() );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   270
        }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   271
    if( iCurrentOp == EIdle || iCurrentOp == EBonding )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   272
        {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   273
        // ToDo: check non-pairing operation when bonding
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   274
        TInt uid = aMessage.Int0();
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   275
        if( uid == KBTManAuthNotifierUid.iUid )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   276
            {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   277
            HandleAuthorizationReqL( aParams );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   278
            }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   279
        else if( uid == KBTManPinNotifierUid.iUid ||
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   280
                 uid == KBTPinCodeEntryNotifierUid.iUid ||
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   281
                 uid == KBTNumericComparisonNotifierUid.iUid ||
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   282
                 uid == KBTPasskeyDisplayNotifierUid.iUid )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   283
            {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   284
            if( !iPairingHelper )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   285
                {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   286
                BOstrace0( TRACE_NORMAL, DUMMY_DEVLIST, 
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   287
                        "[BTNOTIF]\t CBTNotifConnection::HandleNotifierRequestL: creating CBTNotifPairingHelper");
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   288
                iPairingHelper = CBTNotifPairingHelper::NewL( this, iTracker );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   289
                }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   290
            if( iCurrentOp != EBonding  )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   291
                {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   292
                iCurrentOp = EPairing;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   293
                }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   294
            iPairingHelper->StartPairingNotifierL( uid, aParams );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   295
            }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   296
        // We may be done with the current request, proceed to the next one
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   297
        CheckNextOperationL();
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   298
        }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   299
    BOstraceFunctionExit1( DUMMY_DEVLIST, this );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   300
    }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   301
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   302
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   303
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   304
// Update a notifier, update the outstanding dialog if the notifier request 
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   305
// is currently being served.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   306
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   307
//
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   308
void CBTNotifConnection::HandleNotifierUpdateL( const TDesC8& aParams,
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   309
    const RMessage2& aMessage )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   310
    {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   311
    BOstraceFunctionEntry0( DUMMY_DEVLIST );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   312
    NOTIF_NOTHANDLED( iCurrentOp != EIdle )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   313
    (void) aParams;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   314
    TBuf8<0x250> paramsBuf;    // Size needs to be long enough to read all possible sizes.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   315
    aMessage.ReadL( EBTNotifSrvParamSlot, paramsBuf );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   316
    TInt uid = aMessage.Int0();
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   317
    if( uid == KBTManAuthNotifierUid.iUid )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   318
        {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   319
        TBTNotifierUpdateParams params;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   320
        TPckgC<TBTNotifierUpdateParams> paramsPckg( params );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   321
        paramsPckg.Set( paramsBuf );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   322
        // The result means result of conversion to unicode
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   323
        if( !paramsPckg().iResult )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   324
            {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   325
            // Only update locally, registry will update us with the same info later on.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   326
            iDevice->SetDeviceNameL( BTDeviceNameConverter::ToUTF8L( paramsPckg().iName ) );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   327
            if( iNotification )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   328
                {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   329
                // Update the dialog with the new name. It is up to the dialog to 
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   330
                // determine the validity (in case another dialog is shown).
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   331
                //iNotification->Update(  )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   332
                }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   333
            }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   334
        }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   335
    else if( iPairingHelper && ( uid == KBTPinCodeEntryNotifierUid.iUid ||
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   336
             uid == KBTNumericComparisonNotifierUid.iUid ||
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   337
             uid == KBTPasskeyDisplayNotifierUid.iUid ) )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   338
        {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   339
        // Just forward to pairing helper
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   340
        iPairingHelper->UpdatePairingNotifierL( uid, paramsBuf );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   341
        }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   342
    BOstraceFunctionExit0( DUMMY_DEVLIST );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   343
    }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   344
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   345
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   346
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   347
// Cancel a request, dismiss the outstanding dialog if the notifier request 
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   348
// is currently being served.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   349
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   350
//
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   351
void CBTNotifConnection::CancelNotifierRequestL( const RMessage2& aMessage )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   352
    {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   353
    BOstraceFunctionEntry0( DUMMY_DEVLIST );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   354
    NOTIF_NOTHANDLED( iCurrentOp != EIdle )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   355
    TInt pos = iMsgHandleQ.Find( aMessage.Handle() );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   356
    if( pos > KErrNotFound )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   357
        {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   358
        // We have queued the message, remove it from the queue.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   359
        iMsgHandleQ.Remove( pos );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   360
        // We use the supplied handle to remove it, as it may not be
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   361
        // the first in the queue.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   362
        TInt err = iTracker->Server()->CompleteMessage( aMessage.Handle(), KErrCancel, KNullDesC8 );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   363
        NOTIF_NOTHANDLED( !err )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   364
        if( pos == 0 )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   365
            {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   366
            // There could be the case that we are still post-processing
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   367
            // the previous request (e.g. blocking query), then the next
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   368
            // notification is not yet started but the first in the queue.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   369
            // We can see that from the current operation type.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   370
            if( iNotification && iCurrentOp < EAdditionalNotes )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   371
                {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   372
                // Cancel the user query
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   373
                // This will also unregister us from the notification.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   374
                TInt err = iNotification->Close();
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   375
                NOTIF_NOTHANDLED( !err )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   376
                iNotification = NULL;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   377
                iCurrentOp = EIdle;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   378
                }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   379
            if( iPairingHelper )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   380
                {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   381
                // The pairing helper calls back PairingCompleted and sets state.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   382
                iPairingHelper->CancelPairingNotifierL( aMessage.Int0() );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   383
                // The pairing helper may have now been deleted.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   384
                }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   385
            }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   386
        }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   387
    // We may be done with the current request, proceed to the next one
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   388
    CheckNextOperationL();
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   389
    BOstraceFunctionExit0( DUMMY_DEVLIST );
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
// Start a bonding operation with the remote device.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   395
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   396
//
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   397
void CBTNotifConnection::StartBondingL( const RMessage2& aMessage )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   398
    {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   399
    BOstraceFunctionEntryExt( DUMMY_DEVLIST, this, aMessage.Function() );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   400
    if( iCurrentOp == EIdle || iCurrentOp > EInternalOperations )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   401
        {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   402
        __ASSERT_ALWAYS( !iPairingHelper, PanicServer( EBTNotifPanicBadState ) );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   403
        iPairingHelper = CBTNotifPairingHelper::NewL( this, iTracker );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   404
        // The pairingg helper stored the handle, not in our queue here.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   405
        // This is because bonding will generate a pairing notifier request, which 
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   406
        // will be completed first. The bookkeeping gets complicated if we have to
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   407
        // re-order the queue here.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   408
        iPairingHelper->StartBondingL( aMessage.Handle() );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   409
        iCurrentOp = EBonding;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   410
        }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   411
    else if( iCurrentOp == EPairing || iCurrentOp == EBonding )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   412
        {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   413
        // We only do one pairing at the time.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   414
        User::Leave( KErrInUse );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   415
        }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   416
    else
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   417
        {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   418
        // We only store it here if it is not handled immediately.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   419
        iMsgHandleQ.AppendL( aMessage.Handle() );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   420
        }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   421
    BOstraceFunctionExit1( DUMMY_DEVLIST, this );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   422
    }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   423
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   424
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   425
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   426
// Cancel an ongoing bonding operation with the remote device.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   427
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   428
//
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   429
void CBTNotifConnection::CancelBondingL()
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   430
    {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   431
    BOstraceFunctionEntry0( DUMMY_DEVLIST );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   432
    if( iPairingHelper )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   433
        {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   434
        iPairingHelper->CancelBondingL();
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   435
        }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   436
    BOstraceFunctionExit0( DUMMY_DEVLIST );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   437
    }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   438
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   439
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   440
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   441
// The pairing handler has completed a pairing operation.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   442
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   443
//
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   444
void CBTNotifConnection::PairingCompleted()
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   445
    {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   446
    BOstraceFunctionEntry0( DUMMY_DEVLIST );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   447
    __ASSERT_ALWAYS( iPairingHelper, PanicServer( EBTNotifPanicNullMember ) );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   448
    if( iPairingHelper->CurrentOperation() == CBTNotifPairingHelper::EIdle )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   449
        {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   450
        // We are still idle. Remove the pairing helper
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   451
        delete iPairingHelper;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   452
        iPairingHelper = NULL;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   453
        }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   454
    if( iCurrentOp == EPairing || iCurrentOp == EBonding )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   455
        {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   456
        iCurrentOp = EIdle;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   457
        TRAP_IGNORE( CheckNextOperationL() );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   458
        }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   459
    BOstraceFunctionExit0( DUMMY_DEVLIST );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   460
    }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   461
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   462
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   463
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   464
// Process a new pairing result, and determine if we need to show 
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   465
// anything to the user.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   466
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   467
//
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   468
void CBTNotifConnection::PairingResult( TInt aError )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   469
    {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   470
    BOstraceFunctionEntry0( DUMMY_DEVLIST );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   471
    if( !iPairingHelper )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   472
        {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   473
        TRAP_IGNORE( iPairingHelper = CBTNotifPairingHelper::NewL( this, iTracker ) );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   474
        }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   475
    if( iPairingHelper )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   476
        {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   477
        iPairingHelper->HandleAuthenticationCompleteL( aError );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   478
        }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   479
    BOstraceFunctionExit0( DUMMY_DEVLIST );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   480
    }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   481
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   482
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   483
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   484
// Process the new service-level connection, and determine if we need to
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   485
// show anything to the user.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   486
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   487
//
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   488
void CBTNotifConnection::ServiceConnectedL( TBTProfile aProfile )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   489
    {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   490
    (void) aProfile;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   491
    }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   492
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   493
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   494
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   495
// Process the new service-level disconnection, and determine if we need to
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   496
// show anything to the user.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   497
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   498
//
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   499
void CBTNotifConnection::ServiceDisconnectedL( TBTProfile aProfile )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   500
    {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   501
    (void) aProfile;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   502
    }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   503
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   504
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   505
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   506
// Ask the user if he/she wants to block future connection requests. 
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   507
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   508
//
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   509
void CBTNotifConnection::LaunchBlockingQueryL()
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   510
    {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   511
    BOstraceFunctionEntry0( DUMMY_DEVLIST );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   512
    iCurrentOp = EBlocking;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   513
    TBTDialogResourceId resourceId = EBlockUnpairedDevice;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   514
    if( iDevice->IsValidPaired() && iDevice->IsPaired() &&
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   515
        iDevice->LinkKeyType() != ELinkKeyUnauthenticatedUpgradable )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   516
        {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   517
        resourceId = EBlockPairedDevice;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   518
        }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   519
    PrepareNotificationL( TBluetoothDialogParams::EQuery, resourceId );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   520
    BOstraceFunctionExit0( DUMMY_DEVLIST );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   521
    }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   522
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   523
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   524
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   525
// Modify the record for the remote device in BTRegistry, with the changes 
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   526
// already made in the local record.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   527
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   528
//
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   529
void CBTNotifConnection::UpdateRegistryEntryL()
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   530
    {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   531
    BOstraceFunctionEntry0( DUMMY_DEVLIST );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   532
    // We use CBTEngDevMan here. We could use the registry API directly, however,
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   533
    // using this convenience API makes the registry processing much simpler.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   534
    if( !iDevMan )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   535
        {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   536
        iDevMan = CBTEngDevMan::NewL( this );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   537
        }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   538
    iDevMan->ModifyDevice( *iDevice );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   539
    if( iCurrentOp == EIdle ||
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   540
        ( ( iCurrentOp == EPairing || iCurrentOp == EBonding ) &&
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   541
          iPairingHelper->CurrentOperation() == CBTNotifPairingHelper::EIdle ) )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   542
        {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   543
        // To make sure that we don't get deleted while updating.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   544
        iCurrentOp = EUpdatingRegistry;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   545
        }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   546
    BOstraceFunctionExit0( DUMMY_DEVLIST );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   547
    }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   548
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   549
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   550
// Modify the record for the remote device in BTRegistry, if aTrusted == true, then
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   551
// update trusted status after reading device info from registry
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   552
//
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   553
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   554
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   555
void CBTNotifConnection::UpdateRegistryEntryL( TBool aTrusted )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   556
    {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   557
    BOstraceFunctionEntryExt( DUMMY_DEVLIST, this, aTrusted );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   558
    if (!aTrusted) {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   559
        UpdateRegistryEntryL();
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   560
        return;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   561
        }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   562
    // We use CBTEngDevMan here. We could use the registry API directly, however,
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   563
    // using this convenience API makes the registry processing much simpler.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   564
    if( !iDevMan )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   565
        {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   566
        iDevMan = CBTEngDevMan::NewL( this );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   567
        }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   568
    // first read device info from registry, to make sure we have up-to-date local info
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   569
    iCurrentOp = EReadingRegistry;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   570
    GetDeviceFromRegistry( iDevice->BDAddr() );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   571
    BOstraceFunctionExit1( DUMMY_DEVLIST, this );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   572
    }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   573
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   574
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   575
// From class MBTNotificationResult.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   576
// Handle a result from a user query.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   577
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   578
//
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   579
void CBTNotifConnection::MBRDataReceived( CHbSymbianVariantMap & aData )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   580
    {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   581
    (void) aData;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   582
    NOTIF_NOTIMPL
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   583
    }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   584
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   585
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   586
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   587
// From class MBTNotificationResult.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   588
// The notification is finished.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   589
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   590
//
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   591
void CBTNotifConnection::MBRNotificationClosed( TInt aError, const TDesC8& aData )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   592
    {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   593
    BOstraceFunctionEntry0( DUMMY_DEVLIST );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   594
    // ToDo: call leaving function from here!
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   595
    __ASSERT_ALWAYS( iCurrentOp != EIdle, PanicServer( EBTNotifPanicBadState ) );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   596
    // First unregister from the notification, so we can already get the next one.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   597
    iNotification->RemoveObserver();
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   598
    iNotification = NULL;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   599
    TRAP_IGNORE( NotificationClosedL( aError, aData ) );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   600
    BOstraceFunctionExit0( DUMMY_DEVLIST );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   601
    }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   602
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   603
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   604
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   605
// From class MBtSimpleActiveObserver.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   606
// Handle the active object completion.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   607
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   608
//
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   609
void CBTNotifConnection::RequestCompletedL( CBtSimpleActive* aActive,
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   610
    TInt aStatus )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   611
    {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   612
    BOstraceFunctionEntryExt( DUMMY_DEVLIST, this, aActive->RequestId() );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   613
    switch( aActive->RequestId() )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   614
        {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   615
        case KRegistryRetriever:
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   616
            {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   617
            BOstrace0( TRACE_NORMAL, DUMMY_DEVLIST,  
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   618
                    "[BTNOTIF]\t CBTNotifConnection::MBAORequestCompletedL: KRegistryRetriever" );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   619
            if( !iRegistryResponse )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   620
                {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   621
                // We have just created the view, now get the results.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   622
                // There can only be one result, as the address is unique.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   623
                // (note: how about LE random addresses?)
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   624
                // Or then we have tried to re-open an existing view, so we get KErrInuse.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   625
                // We anyway just get the results.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   626
                __ASSERT_ALWAYS( aStatus < 2, PanicServer( EBTNotifPanicCorrupt ) );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   627
                iRegistryResponse = CBTRegistryResponse::NewL( iRegistry );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   628
                iRegistryResponse->Start( iRegActive->RequestStatus() );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   629
                iRegActive->GoActive();
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   630
                }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   631
            else
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   632
                {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   633
                if( !aStatus )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   634
                    {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   635
                    // There can be only one result.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   636
                    __ASSERT_ALWAYS( iRegistryResponse->Results().Count() == 1, PanicServer( EBTNotifPanicCorrupt ) );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   637
                    CBTDevice* regDevice = iRegistryResponse->Results()[0];
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   638
                    TBool paired = CheckRegistryPairedStatus( iDevice, regDevice );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   639
                    iDevice->UpdateL( *regDevice );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   640
                    if( paired )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   641
                        {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   642
                        __ASSERT_ALWAYS( iPairingHelper, PanicServer( EBTNotifPanicNullMember ) );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   643
                        iPairingHelper->HandleAuthenticationCompleteL( KErrNone );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   644
                        }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   645
                    }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   646
                // ToDo: error handling of registry response result?
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   647
                delete iRegistryResponse;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   648
                iRegistryResponse = NULL;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   649
                }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   650
            if( iCurrentOp == EReadingRegistry && !iRegActive->IsActive() )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   651
                {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   652
                // If this is part of the sequence of operations, we are done.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   653
                // Otherwise we just update with the latest info from registry,
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   654
                // and then we don't interrupt or change the state.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   655
                iCurrentOp = EIdle;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   656
                }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   657
            }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   658
            // ToDo: start registry watching (preferably using registry API when this is available)
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   659
           break;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   660
       case KRegistryWatcher:
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   661
           {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   662
           BOstrace0( TRACE_NORMAL, DUMMY_DEVLIST,  
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   663
                   "[BTNOTIF]\t CBTNotifConnection::MBAORequestCompletedL: KRegistryWatcher" );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   664
           NOTIF_NOTHANDLED( !aStatus )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   665
           // Ignore updates while we are already retrieving.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   666
           if( !iRegActive->IsActive() )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   667
               {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   668
               // Refresh our information with the latest from registry
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   669
               iRegActive->SetRequestId( KRegistryRetriever );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   670
               TBTRegistrySearch pattern;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   671
               pattern.FindAddress( iAddr );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   672
               iRegistry.CreateView( pattern, iRegActive->RequestStatus() );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   673
               iRegActive->GoActive();
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   674
               }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   675
           }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   676
           break;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   677
        case KConnectionWatcher:
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   678
            {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   679
            BOstrace0( TRACE_NORMAL, DUMMY_DEVLIST, 
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   680
                    "[BTNOTIF]\t CBTNotifConnection::MBAORequestCompletedL: KConnectionWatcher" );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   681
            TUint32 event = iBasebandEvent().EventType();
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   682
            // First subscribe to the next event notification.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   683
            // This will overwrite iBasebandEvent().EventType() with KBbEventMask
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   684
            iPhyLink.NotifyNextBasebandChangeEvent( iBasebandEvent,
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   685
                        iPhyActive->RequestStatus(), KBbEventMask );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   686
            iPhyActive->GoActive();
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   687
            // Link down and link error are handled in CheckNextOperationL below.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   688
            // ToDo: handle events!
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   689
            if( event & ( ENotifyPhysicalLinkDown | ENotifyPhysicalLinkError ) )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   690
                {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   691
                // We re-use the error code to store the indication that the 
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   692
                // link has disconnected. This will only be overridden by next 
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   693
                // event, which can only be a connection up event.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   694
                iBasebandEvent().SetErrorCode( KErrDisconnected );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   695
                }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   696
            if( iPairingHelper )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   697
                {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   698
                if( event & ( ENotifyPhysicalLinkDown | ENotifyPhysicalLinkError |
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   699
                    ENotifyAuthenticationComplete ) )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   700
                    {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   701
                    // Results interesting for pairing result processing.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   702
                    iPairingHelper->HandleAuthenticationCompleteL( iBasebandEvent().SymbianErrorCode() );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   703
                    }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   704
                else if( event & ENotifyPhysicalLinkUp &&
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   705
                        iPairingHelper->CurrentOperation() == CBTNotifPairingHelper::EDedicatedBonding )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   706
                    {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   707
                    iPairingHelper->StartBondingL( 0 );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   708
                    }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   709
                }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   710
            }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   711
            break;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   712
        default:
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   713
            PanicServer( EBTNotifPanicBadState );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   714
            break;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   715
        }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   716
    // We may be done with the current request, proceed to the next one
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   717
    CheckNextOperationL();
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   718
    BOstraceFunctionExit1( DUMMY_DEVLIST, this );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   719
    }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   720
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   721
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   722
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   723
// From class MBtSimpleActiveObserver.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   724
// Cancel and clean up all requests related to the active object.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   725
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   726
//
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   727
void CBTNotifConnection::CancelRequest( TInt aRequestId )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   728
    {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   729
    BOstraceFunctionEntry0( DUMMY_DEVLIST );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   730
    if ( aRequestId == KConnectionWatcher )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   731
        {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   732
        iPhyLink.CancelNextBasebandChangeEventNotifier();
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   733
        }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   734
    else if ( aRequestId == KRegistryWatcher && iRegistryResponse )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   735
        {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   736
        iRegistryResponse->Cancel();
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   737
        }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   738
    else if ( aRequestId == KRegistryRetriever )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   739
        {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   740
        iRegistry.CancelRequest( iRegActive->RequestStatus());
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   741
        }    
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   742
    BOstraceFunctionExit0( DUMMY_DEVLIST );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   743
    }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   744
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   745
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   746
// From class MBtSimpleActiveObserver.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   747
// 
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   748
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   749
//
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   750
void CBTNotifConnection::HandleError( CBtSimpleActive* aActive, 
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   751
        TInt aError )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   752
    {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   753
    (void) aActive;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   754
    (void) aError;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   755
    }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   756
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   757
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   758
// From class MBTEngDevmanObserver.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   759
// Registry modification has completed.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   760
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   761
//
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   762
void CBTNotifConnection::HandleDevManComplete( TInt aErr )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   763
    {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   764
    BOstraceFunctionEntry0( DUMMY_DEVLIST );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   765
    (void) aErr;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   766
    NOTIF_NOTHANDLED( !aErr )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   767
    if( iCurrentOp == EUpdatingRegistry )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   768
        {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   769
        // To make sure that we don't get deleted while updating.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   770
        iCurrentOp = EIdle;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   771
        }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   772
    // Refresh is done separately, we will get notified through 
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   773
    // the registry watcher of the change.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   774
    BOstraceFunctionExit0( DUMMY_DEVLIST );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   775
    }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   776
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   777
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   778
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   779
// From class MBTEngDevmanObserver.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   780
// Callback for getting a device from the registry
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   781
//
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   782
// Currently only used in context of setting device to trusted
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   783
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   784
//
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   785
void CBTNotifConnection::HandleGetDevicesComplete( 
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   786
        TInt err, CBTDeviceArray* deviceArray ) 
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   787
    {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   788
    BOstraceFunctionEntryExt( DUMMY_DEVLIST, this, err );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   789
    // err is not used here very much, -1 could be returned if there is no device in registry,
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   790
    // but this case is covered by examing mRegDevArray.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   791
    if (!err && (iCurrentOp == EReadingRegistry) ) {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   792
        CBTDevice* dev (0);
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   793
        if ( deviceArray->Count() ) {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   794
            dev = deviceArray->At( 0 );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   795
            }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   796
        if ( dev ) {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   797
            iDevice = dev->CopyL();
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   798
            }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   799
        // Set device to trusted
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   800
        // Copy the existing security settings.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   801
        TBTDeviceSecurity sec( iDevice->GlobalSecurity().SecurityValue(),
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   802
                      iDevice->GlobalSecurity().PasskeyMinLength() );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   803
        sec.SetNoAuthorise( ETrue );  // new value:  set device as trusted
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   804
        iDevice->SetGlobalSecurity( sec );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   805
        iDevMan->ModifyDevice( *iDevice );   // write trusted (& paired) status to registry
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   806
        // To make sure that we don't get deleted while updating.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   807
        iCurrentOp = EUpdatingRegistry;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   808
        }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   809
    BOstraceFunctionExit1( DUMMY_DEVLIST, this );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   810
    }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   811
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   812
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   813
// Retrieves device from registry based on BT address parameter
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   814
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   815
//
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   816
void CBTNotifConnection::GetDeviceFromRegistry( const TBTDevAddr &addr )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   817
{
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   818
    BOstraceFunctionEntry1( DUMMY_DEVLIST, this );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   819
    TBTRegistrySearch searchPattern;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   820
    searchPattern.FindAddress( addr );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   821
    // and get this device from registry
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   822
    iRegDevArray->ResetAndDestroy();
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   823
    iDevMan->GetDevices(searchPattern, iRegDevArray);
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   824
    BOstraceFunctionExit1( DUMMY_DEVLIST, this );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   825
}
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   826
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   827
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   828
// Get and configure a notification.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   829
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   830
//
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   831
void CBTNotifConnection::PrepareNotificationL( TBluetoothDialogParams::TBTDialogType aType,
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   832
    TBTDialogResourceId aResourceId )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   833
    {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   834
    BOstraceFunctionEntry0( DUMMY_DEVLIST );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   835
    iNotification = iTracker->NotificationManager()->GetNotification();
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   836
    User::LeaveIfNull( iNotification ); // For OOM exception, leaves with KErrNoMemory
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   837
    iNotification->SetObserver( this );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   838
    iNotification->SetNotificationType( aType, aResourceId );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   839
    // Set the address of the remote device
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   840
    TBuf<KBTDevAddrSize> addr;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   841
    addr.Copy( iAddr.Des() );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   842
    TInt err = iNotification->SetData( TBluetoothDialogParams::EAddress, addr );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   843
    NOTIF_NOTHANDLED( !err )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   844
    // Set the name of the remote device
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   845
    TBTDeviceName name;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   846
    GetDeviceNameL( name, *iDevice );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   847
    // ToDo: handle leave in name conversion!
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   848
    err = iNotification->SetData( (TInt) TBluetoothDeviceDialog::EDeviceName, name );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   849
    NOTIF_NOTHANDLED( !err )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   850
    // Queue the notification for displaying to the user
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   851
    err = iTracker->NotificationManager()->QueueNotification( iNotification );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   852
    NOTIF_NOTHANDLED( !err )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   853
    BOstraceFunctionExit0( DUMMY_DEVLIST );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   854
    }
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
// The notification is finished, handle the result.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   859
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   860
//
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   861
void CBTNotifConnection::NotificationClosedL( TInt aError, const TDesC8& aData )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   862
    {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   863
    BOstraceFunctionEntry0( DUMMY_DEVLIST );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   864
    switch( iCurrentOp )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   865
        {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   866
        case EAuthorizing:
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   867
            CompleteAuthorizationReqL( aError, aData );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   868
            break;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   869
        case EBlocking:
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   870
            CompleteBlockingReqL( aError, aData );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   871
            break;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   872
        default:
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   873
            NOTIF_NOTIMPL
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   874
            break;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   875
        }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   876
    // We may be done with the current request, proceed to the next one
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   877
    CheckNextOperationL();
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   878
    BOstraceFunctionExit0( DUMMY_DEVLIST );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   879
    }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   880
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   881
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   882
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   883
// Handle a request for authorization of this connection.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   884
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   885
//
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   886
void CBTNotifConnection::HandleAuthorizationReqL( const TDesC8& aParams )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   887
    {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   888
    BOstraceFunctionEntry0( DUMMY_DEVLIST );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   889
    __ASSERT_ALWAYS( iCurrentOp == EIdle, PanicServer( EBTNotifPanicBadState ) );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   890
    __ASSERT_ALWAYS( !iNotification, PanicServer( EBTNotifPanicCorrupt ) );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   891
    TBTAuthorisationParams params;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   892
    TPckgC<TBTAuthorisationParams> paramsPckg( params );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   893
    paramsPckg.Set( aParams );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   894
    iCurrentOp = EAuthorizing;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   895
    // The name in the parameter package is the latest one, retrieved from 
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   896
    // the remote device during this connection.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   897
    if( paramsPckg().iName.Length() )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   898
        {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   899
        // Update the local device record. No need to update the registry,
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   900
        // that will be done by the stack, and we will receive the update 
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   901
        // information when that has completed.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   902
        iDevice->SetDeviceNameL( BTDeviceNameConverter::ToUTF8L( paramsPckg().iName ) );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   903
        }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   904
    PrepareNotificationL( TBluetoothDialogParams::EQuery, EAuthorization );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   905
    BOstraceFunctionExit0( DUMMY_DEVLIST );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   906
    }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   907
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   908
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   909
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   910
// Process the user input and complete the outstanding authorization request. 
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   911
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   912
//
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   913
void CBTNotifConnection::CompleteAuthorizationReqL( TInt aError, const TDesC8& aData )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   914
    {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   915
    BOstraceFunctionEntry0( DUMMY_DEVLIST );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   916
    // Set our state to idle for now. This may get changed if the user just chose 
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   917
    // to block, or if we have a pending request.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   918
    iCurrentOp = EIdle;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   919
    if( !aError )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   920
        {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   921
        TPckgC<TBool> result( EFalse );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   922
        result.Set( aData );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   923
        TBool proceed = iTracker->UpdateBlockingHistoryL( iDevice, result() );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   924
        if( result() == EFalse && proceed )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   925
            {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   926
            // The user denied the connection, ask to block the device.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   927
            LaunchBlockingQueryL();
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   928
            }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   929
        CompleteClientRequest( KErrNone, aData );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   930
        }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   931
    else
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   932
        {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   933
        CompleteClientRequest( aError, KNullDesC8 );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   934
        }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   935
    BOstraceFunctionExit0( DUMMY_DEVLIST );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   936
    }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   937
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   938
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   939
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   940
// Process the user input for blocking a device.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   941
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   942
//
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   943
void CBTNotifConnection::CompleteBlockingReqL( TInt aError, const TDesC8& aData )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   944
    {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   945
    BOstraceFunctionEntry0( DUMMY_DEVLIST );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   946
    TPckgC<TBool> result( EFalse );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   947
    result.Set( KNullDesC8 );    // to test!
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   948
    result.Set( aData );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   949
    iCurrentOp = EIdle; // May get changed if we have a pending request.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   950
    if( !aError && result() )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   951
        {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   952
        // The user accepted to block this device.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   953
        TBTDeviceSecurity sec;  // use default values when setting as banned.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   954
        sec.SetBanned( ETrue );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   955
        iDevice->SetGlobalSecurity( sec );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   956
        if( iDevice->IsValidPaired() && iDevice->IsPaired() )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   957
            {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   958
            // Deleting the link key will also set the device as unpaired.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   959
            iDevice->DeleteLinkKey();
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   960
            }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   961
        UpdateRegistryEntryL();
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   962
        }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   963
    BOstraceFunctionExit0( DUMMY_DEVLIST );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   964
    }