bluetoothengine/btnotif/btnotifsrv/src/btnotifsecuritymanager.cpp
author hgs
Fri, 23 Jul 2010 15:57:13 +0300
changeset 47 9e2a905b887f
parent 42 b72428996822
child 57 5ebadcda06cb
permissions -rw-r--r--
201029_02
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
42
hgs
parents:
diff changeset
     1
/*
hgs
parents:
diff changeset
     2
* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
hgs
parents:
diff changeset
     3
* All rights reserved.
hgs
parents:
diff changeset
     4
* This component and the accompanying materials are made available
hgs
parents:
diff changeset
     5
* under the terms of "Eclipse Public License v1.0"
hgs
parents:
diff changeset
     6
* which accompanies this distribution, and is available
hgs
parents:
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
hgs
parents:
diff changeset
     8
*
hgs
parents:
diff changeset
     9
* Initial Contributors:
hgs
parents:
diff changeset
    10
* Nokia Corporation - initial contribution.
hgs
parents:
diff changeset
    11
*
hgs
parents:
diff changeset
    12
* Contributors:
hgs
parents:
diff changeset
    13
*
hgs
parents:
diff changeset
    14
* Description: 
hgs
parents:
diff changeset
    15
*
hgs
parents:
diff changeset
    16
*/
hgs
parents:
diff changeset
    17
hgs
parents:
diff changeset
    18
#include "btnotifsecuritymanager.h"
hgs
parents:
diff changeset
    19
#include "btnotifoutgoingpairinghandler.h"
hgs
parents:
diff changeset
    20
#include "btnotifincomingpairinghandler.h"
hgs
parents:
diff changeset
    21
#include "btnotifpairnotifier.h"
hgs
parents:
diff changeset
    22
#include "btnotifclientserver.h"
hgs
parents:
diff changeset
    23
#include <e32property.h>
hgs
parents:
diff changeset
    24
#include "btnotifconnectiontracker.h"
hgs
parents:
diff changeset
    25
#include "btnotifserviceauthorizer.h"
hgs
parents:
diff changeset
    26
hgs
parents:
diff changeset
    27
/**  Identification for active object */
hgs
parents:
diff changeset
    28
enum TPairManActiveRequestId
hgs
parents:
diff changeset
    29
    {
hgs
parents:
diff changeset
    30
    ESimplePairingResult,
hgs
parents:
diff changeset
    31
    EAuthenticationResult,
hgs
parents:
diff changeset
    32
    ERegistryGetLocalAddress,
hgs
parents:
diff changeset
    33
    };
hgs
parents:
diff changeset
    34
hgs
parents:
diff changeset
    35
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
    36
// Tells if two TBTNamelessDevice instances are for the same remote device
hgs
parents:
diff changeset
    37
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
    38
//
hgs
parents:
diff changeset
    39
TBool CompareDeviceByAddress( const TBTNamelessDevice& aDevA, const TBTNamelessDevice& aDevB )
hgs
parents:
diff changeset
    40
    {
hgs
parents:
diff changeset
    41
    return aDevA.Address() == aDevB.Address();
hgs
parents:
diff changeset
    42
    }
hgs
parents:
diff changeset
    43
hgs
parents:
diff changeset
    44
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
    45
// Tells if these two instances are for the same remote device
hgs
parents:
diff changeset
    46
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
    47
//
hgs
parents:
diff changeset
    48
TBool MatchDeviceAddress(const TBTDevAddr* aAddr, const TBTNamelessDevice& aDev)
hgs
parents:
diff changeset
    49
    {
hgs
parents:
diff changeset
    50
    return *aAddr == aDev.Address();
hgs
parents:
diff changeset
    51
    }
hgs
parents:
diff changeset
    52
hgs
parents:
diff changeset
    53
// ======== MEMBER FUNCTIONS ========
hgs
parents:
diff changeset
    54
hgs
parents:
diff changeset
    55
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
    56
// C++ default constructor
hgs
parents:
diff changeset
    57
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
    58
//
hgs
parents:
diff changeset
    59
CBTNotifSecurityManager::CBTNotifSecurityManager(
hgs
parents:
diff changeset
    60
        CBTNotifConnectionTracker& aParent,
hgs
parents:
diff changeset
    61
        CBtDevRepository& aDevRepository)
hgs
parents:
diff changeset
    62
    : iParent( aParent ), iDevRepository( aDevRepository )
hgs
parents:
diff changeset
    63
    {
hgs
parents:
diff changeset
    64
    }
hgs
parents:
diff changeset
    65
hgs
parents:
diff changeset
    66
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
    67
// Symbian 2nd-phase constructor
hgs
parents:
diff changeset
    68
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
    69
//
hgs
parents:
diff changeset
    70
void CBTNotifSecurityManager::ConstructL()
hgs
parents:
diff changeset
    71
    {
hgs
parents:
diff changeset
    72
    // Connect to pairing server for authentication & simple pairing 
hgs
parents:
diff changeset
    73
    // results directly from the BT stack.
hgs
parents:
diff changeset
    74
    // Pairing server doesn't exist if we run BT 2.0 stack:
hgs
parents:
diff changeset
    75
    iPairingServ = new (ELeave) RBluetoothPairingServer;
hgs
parents:
diff changeset
    76
    TInt err = iPairingServ->Connect();
hgs
parents:
diff changeset
    77
    if ( err)
hgs
parents:
diff changeset
    78
        {
hgs
parents:
diff changeset
    79
        delete iPairingServ;
hgs
parents:
diff changeset
    80
        iPairingServ = NULL;
hgs
parents:
diff changeset
    81
        }
hgs
parents:
diff changeset
    82
    else
hgs
parents:
diff changeset
    83
        {
hgs
parents:
diff changeset
    84
        User::LeaveIfError( iPairingResult.Open( *iPairingServ ) );
hgs
parents:
diff changeset
    85
        User::LeaveIfError( iAuthenResult.Open( *iPairingServ ) );
hgs
parents:
diff changeset
    86
        iSSPResultActive = CBtSimpleActive::NewL( *this, ESimplePairingResult );
hgs
parents:
diff changeset
    87
        iAuthenResultActive = CBtSimpleActive::NewL( *this, EAuthenticationResult );
hgs
parents:
diff changeset
    88
        SubscribeSspPairingResult();
hgs
parents:
diff changeset
    89
        SubscribeAuthenticateResult();
hgs
parents:
diff changeset
    90
        }
hgs
parents:
diff changeset
    91
    User::LeaveIfError( iRegistry.Open( iParent.RegistryServerSession() ) );
hgs
parents:
diff changeset
    92
    // RProperty for accessing the local device address
hgs
parents:
diff changeset
    93
    User::LeaveIfError( iPropertyLocalAddr.Attach(
hgs
parents:
diff changeset
    94
            KPropertyUidBluetoothCategory, KPropertyKeyBluetoothGetLocalDeviceAddress) );
hgs
parents:
diff changeset
    95
    // Initialise paired devices list
hgs
parents:
diff changeset
    96
    iLocalAddrActive = CBtSimpleActive::NewL( *this, ERegistryGetLocalAddress );
hgs
parents:
diff changeset
    97
    SubscribeLocalAddress();
hgs
parents:
diff changeset
    98
    iPairNotifier = CBTNotifPairNotifier::NewL( *this );
hgs
parents:
diff changeset
    99
    iDevRepository.AddObserverL( this );
hgs
parents:
diff changeset
   100
    iServiceAuthorizer = CBTNotifServiceAuthorizer::NewL(*this);
hgs
parents:
diff changeset
   101
    }
hgs
parents:
diff changeset
   102
hgs
parents:
diff changeset
   103
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
   104
// NewL
hgs
parents:
diff changeset
   105
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
   106
//
hgs
parents:
diff changeset
   107
CBTNotifSecurityManager* CBTNotifSecurityManager::NewL(
hgs
parents:
diff changeset
   108
        CBTNotifConnectionTracker& aParent,
hgs
parents:
diff changeset
   109
        CBtDevRepository& aDevRepository )
hgs
parents:
diff changeset
   110
    {
hgs
parents:
diff changeset
   111
    CBTNotifSecurityManager* self = NULL;
hgs
parents:
diff changeset
   112
    self = new  CBTNotifSecurityManager( aParent, aDevRepository );
hgs
parents:
diff changeset
   113
    CleanupStack::PushL( self );
hgs
parents:
diff changeset
   114
    self->ConstructL();
hgs
parents:
diff changeset
   115
    CleanupStack::Pop( self );
hgs
parents:
diff changeset
   116
    return self;
hgs
parents:
diff changeset
   117
    }
hgs
parents:
diff changeset
   118
hgs
parents:
diff changeset
   119
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
   120
// Destructor
hgs
parents:
diff changeset
   121
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
   122
//
hgs
parents:
diff changeset
   123
CBTNotifSecurityManager::~CBTNotifSecurityManager()
hgs
parents:
diff changeset
   124
    {
hgs
parents:
diff changeset
   125
    delete iSSPResultActive;
hgs
parents:
diff changeset
   126
    delete iAuthenResultActive;
hgs
parents:
diff changeset
   127
    delete iPairNotifier;
hgs
parents:
diff changeset
   128
    delete iPairingHandler;
hgs
parents:
diff changeset
   129
    iPairedDevices.Close();
hgs
parents:
diff changeset
   130
    iPairingResult.Close();
hgs
parents:
diff changeset
   131
    iAuthenResult.Close();
hgs
parents:
diff changeset
   132
    if ( iPairingServ )
hgs
parents:
diff changeset
   133
        {
hgs
parents:
diff changeset
   134
        iPairingServ->Close();
hgs
parents:
diff changeset
   135
        delete iPairingServ;
hgs
parents:
diff changeset
   136
        }
hgs
parents:
diff changeset
   137
    iRegistry.Close();
hgs
parents:
diff changeset
   138
    delete iLocalAddrActive;
hgs
parents:
diff changeset
   139
    iPropertyLocalAddr.Close();
hgs
parents:
diff changeset
   140
    if ( !iMessage.IsNull() )
hgs
parents:
diff changeset
   141
        {
hgs
parents:
diff changeset
   142
        iMessage.Complete( KErrCancel );
hgs
parents:
diff changeset
   143
        }
hgs
parents:
diff changeset
   144
    delete iServiceAuthorizer;
hgs
parents:
diff changeset
   145
    }
hgs
parents:
diff changeset
   146
hgs
parents:
diff changeset
   147
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
   148
// Initialises the paired devices list.
hgs
parents:
diff changeset
   149
// If the local address is not available from the P&S key 
hgs
parents:
diff changeset
   150
// KPropertyKeyBluetoothGetLocalDeviceAddress, then the list may need to be 
hgs
parents:
diff changeset
   151
// updated once the H/W is switched on. This is so that any registry update 
hgs
parents:
diff changeset
   152
// from a restore operation can be included in the list, without mistaking the 
hgs
parents:
diff changeset
   153
// new devices for new pairings.
hgs
parents:
diff changeset
   154
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
   155
//
hgs
parents:
diff changeset
   156
void CBTNotifSecurityManager::SubscribeLocalAddress()
hgs
parents:
diff changeset
   157
    {
hgs
parents:
diff changeset
   158
    // Check that we have the Bluetooth local address. If we don't then initialise anyway, but subscribe for an update.
hgs
parents:
diff changeset
   159
    // This allows us to refresh our paired devices list to include updates made to the remote devices table of the 
hgs
parents:
diff changeset
   160
    // Bluetooth registry from a restore operation. We need to include these devices without mistaking them for new 
hgs
parents:
diff changeset
   161
    // pairings. We look solely at the P&S key for the address to avoid the condition whereby the address has been
hgs
parents:
diff changeset
   162
    // entered into the reigstry but the Bluetooth Manager server has not begun the restore process yet. The signalling
hgs
parents:
diff changeset
   163
    // of the P&S key will cause Bluetooth Manager to update the registry with any restored devices before fulfilling
hgs
parents:
diff changeset
   164
    // any further requests.
hgs
parents:
diff changeset
   165
hgs
parents:
diff changeset
   166
    // Subscribe to local address property in case we need an update.
hgs
parents:
diff changeset
   167
    iPropertyLocalAddr.Subscribe( iLocalAddrActive->iStatus );
hgs
parents:
diff changeset
   168
    iLocalAddrActive->SetRequestId( ERegistryGetLocalAddress );
hgs
parents:
diff changeset
   169
    iLocalAddrActive->GoActive();
hgs
parents:
diff changeset
   170
    }
hgs
parents:
diff changeset
   171
hgs
parents:
diff changeset
   172
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
   173
// Tells whether the local address is available from the P&S key 
hgs
parents:
diff changeset
   174
// KPropertyKeyBluetoothGetLocalDeviceAddress.
hgs
parents:
diff changeset
   175
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
   176
//
hgs
parents:
diff changeset
   177
TBool CBTNotifSecurityManager::IsLocalAddressAvailable()
hgs
parents:
diff changeset
   178
    {
hgs
parents:
diff changeset
   179
    // Attempt to read address from P&S key.
hgs
parents:
diff changeset
   180
    TBuf8<KBTDevAddrSize> btAddrDes;
hgs
parents:
diff changeset
   181
    TInt err = iPropertyLocalAddr.Get( btAddrDes );
hgs
parents:
diff changeset
   182
hgs
parents:
diff changeset
   183
    // Is the P&S key defined yet? (if not, stack not up yet)
hgs
parents:
diff changeset
   184
    if ( err == KErrNone )
hgs
parents:
diff changeset
   185
        {
hgs
parents:
diff changeset
   186
        // P&S key defined, is local address set? (if not, H/W not initialised yet)
hgs
parents:
diff changeset
   187
        if ( btAddrDes.Length() == KBTDevAddrSize )
hgs
parents:
diff changeset
   188
            {
hgs
parents:
diff changeset
   189
            TBTDevAddr btAddr = btAddrDes;
hgs
parents:
diff changeset
   190
            if ( btAddr != TBTDevAddr() )
hgs
parents:
diff changeset
   191
                {
hgs
parents:
diff changeset
   192
                return ETrue;
hgs
parents:
diff changeset
   193
                }
hgs
parents:
diff changeset
   194
            }
hgs
parents:
diff changeset
   195
        }
hgs
parents:
diff changeset
   196
    return EFalse;
hgs
parents:
diff changeset
   197
    }
hgs
parents:
diff changeset
   198
hgs
parents:
diff changeset
   199
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
   200
// Handles pairing related requests from BTNotif clients.
hgs
parents:
diff changeset
   201
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
   202
//
hgs
parents:
diff changeset
   203
void CBTNotifSecurityManager::HandleBondingRequestL( const RMessage2& aMessage )
hgs
parents:
diff changeset
   204
    {
hgs
parents:
diff changeset
   205
    TInt opcode = aMessage.Function();
hgs
parents:
diff changeset
   206
    TBTDevAddrPckgBuf addrPkg;
hgs
parents:
diff changeset
   207
    switch( opcode )
hgs
parents:
diff changeset
   208
        {
hgs
parents:
diff changeset
   209
        case EBTNotifPairDevice:
hgs
parents:
diff changeset
   210
            {
hgs
parents:
diff changeset
   211
            if ( !iMessage.IsNull() )
hgs
parents:
diff changeset
   212
                {
hgs
parents:
diff changeset
   213
                User::Leave( KErrServerBusy );
hgs
parents:
diff changeset
   214
                }
hgs
parents:
diff changeset
   215
            TBTDevAddrPckgBuf addrPkg;
hgs
parents:
diff changeset
   216
            aMessage.ReadL( EBTNotifSrvParamSlot, addrPkg );
hgs
parents:
diff changeset
   217
            BlockDevice(addrPkg(),EFalse);
hgs
parents:
diff changeset
   218
            UnpairDevice( addrPkg() );
hgs
parents:
diff changeset
   219
            PairDeviceL( addrPkg(), aMessage.Int2() );
hgs
parents:
diff changeset
   220
            iMessage = RMessage2( aMessage );
hgs
parents:
diff changeset
   221
            break;
hgs
parents:
diff changeset
   222
            }
hgs
parents:
diff changeset
   223
        case EBTNotifCancelPairDevice:
hgs
parents:
diff changeset
   224
            {
hgs
parents:
diff changeset
   225
            // Only the client who requested pairing can cancel it:
hgs
parents:
diff changeset
   226
            if ( !iMessage.IsNull() && aMessage.Session() == iMessage.Session() )
hgs
parents:
diff changeset
   227
                {
hgs
parents:
diff changeset
   228
                iPairingHandler->CancelOutgoingPair();
hgs
parents:
diff changeset
   229
                iMessage.Complete( KErrCancel );
hgs
parents:
diff changeset
   230
                }
hgs
parents:
diff changeset
   231
            aMessage.Complete( KErrNone );
hgs
parents:
diff changeset
   232
            break;
hgs
parents:
diff changeset
   233
            }
hgs
parents:
diff changeset
   234
        default:
hgs
parents:
diff changeset
   235
            {
hgs
parents:
diff changeset
   236
            User::Leave( KErrArgument );
hgs
parents:
diff changeset
   237
            }
hgs
parents:
diff changeset
   238
        }
hgs
parents:
diff changeset
   239
    }
hgs
parents:
diff changeset
   240
hgs
parents:
diff changeset
   241
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
   242
// Process a client message related to notifiers.
hgs
parents:
diff changeset
   243
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
   244
//
hgs
parents:
diff changeset
   245
void CBTNotifSecurityManager::HandleNotifierRequestL( const RMessage2& aMessage )
hgs
parents:
diff changeset
   246
    {
hgs
parents:
diff changeset
   247
    if(aMessage.Int0() == KBTManAuthNotifierUid.iUid)
hgs
parents:
diff changeset
   248
        {
hgs
parents:
diff changeset
   249
        iServiceAuthorizer->StartNotifierL( aMessage );
hgs
parents:
diff changeset
   250
        }
hgs
parents:
diff changeset
   251
    else
hgs
parents:
diff changeset
   252
        {
hgs
parents:
diff changeset
   253
        iPairNotifier->StartPairingNotifierL( aMessage );
hgs
parents:
diff changeset
   254
        }
hgs
parents:
diff changeset
   255
    
hgs
parents:
diff changeset
   256
    BOstraceFunctionExit0( DUMMY_DEVLIST);
hgs
parents:
diff changeset
   257
    }
hgs
parents:
diff changeset
   258
hgs
parents:
diff changeset
   259
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
   260
// Returns the RBluetoothPairingServer instance.
hgs
parents:
diff changeset
   261
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
   262
//
hgs
parents:
diff changeset
   263
RBluetoothPairingServer* CBTNotifSecurityManager::PairingServer()
hgs
parents:
diff changeset
   264
    {
hgs
parents:
diff changeset
   265
    return iPairingServ;
hgs
parents:
diff changeset
   266
    }
hgs
parents:
diff changeset
   267
hgs
parents:
diff changeset
   268
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
   269
// Access the reference of RSockServ
hgs
parents:
diff changeset
   270
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
   271
//
hgs
parents:
diff changeset
   272
RSocketServ& CBTNotifSecurityManager::SocketServ()
hgs
parents:
diff changeset
   273
    {
hgs
parents:
diff changeset
   274
    return iParent.SocketServerSession();
hgs
parents:
diff changeset
   275
    }
hgs
parents:
diff changeset
   276
hgs
parents:
diff changeset
   277
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
   278
// Access the reference of RBTRegSrv
hgs
parents:
diff changeset
   279
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
   280
//
hgs
parents:
diff changeset
   281
CBtDevRepository& CBTNotifSecurityManager::BTDevRepository()
hgs
parents:
diff changeset
   282
    {
hgs
parents:
diff changeset
   283
    return iDevRepository;
hgs
parents:
diff changeset
   284
    }
hgs
parents:
diff changeset
   285
hgs
parents:
diff changeset
   286
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
   287
// Access the reference of CBTNotifConnectionTracker
hgs
parents:
diff changeset
   288
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
   289
//
hgs
parents:
diff changeset
   290
CBTNotifConnectionTracker& CBTNotifSecurityManager::ConnectionTracker()
hgs
parents:
diff changeset
   291
    {
hgs
parents:
diff changeset
   292
    return iParent;
hgs
parents:
diff changeset
   293
    }
hgs
parents:
diff changeset
   294
hgs
parents:
diff changeset
   295
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
   296
// Deletes the current pairing handler and transfer the responsibility
hgs
parents:
diff changeset
   297
// to the specified.
hgs
parents:
diff changeset
   298
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
   299
//
hgs
parents:
diff changeset
   300
void CBTNotifSecurityManager::RenewPairingHandler( 
hgs
parents:
diff changeset
   301
        CBTNotifBasePairingHandler* aPairingHandler )
hgs
parents:
diff changeset
   302
    {
hgs
parents:
diff changeset
   303
    delete iPairingHandler;
hgs
parents:
diff changeset
   304
    iPairingHandler = aPairingHandler;
hgs
parents:
diff changeset
   305
    }
hgs
parents:
diff changeset
   306
hgs
parents:
diff changeset
   307
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
   308
// Find the session who requested this and completes its request.
hgs
parents:
diff changeset
   309
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
   310
//
hgs
parents:
diff changeset
   311
void CBTNotifSecurityManager::OutgoingPairCompleted( TInt aErr )
hgs
parents:
diff changeset
   312
    {
hgs
parents:
diff changeset
   313
    // the meaning of KHCIErrorBase equals KErrNone. Hide this specific BT stack
hgs
parents:
diff changeset
   314
	// detail from clients:
hgs
parents:
diff changeset
   315
    if ( !iMessage.IsNull()  )
hgs
parents:
diff changeset
   316
        {
hgs
parents:
diff changeset
   317
        iMessage.Complete( (aErr == KHCIErrorBase) ? KErrNone : aErr );
hgs
parents:
diff changeset
   318
        }
hgs
parents:
diff changeset
   319
    }
hgs
parents:
diff changeset
   320
hgs
parents:
diff changeset
   321
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
   322
// A session will be ended, completes the pending request for this session.
hgs
parents:
diff changeset
   323
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
   324
//
hgs
parents:
diff changeset
   325
void CBTNotifSecurityManager::SessionClosed( CSession2* aSession )
hgs
parents:
diff changeset
   326
    {
hgs
parents:
diff changeset
   327
    BOstrace1(TRACE_DEBUG,DUMMY_DEVLIST," session %x", aSession);
hgs
parents:
diff changeset
   328
    if ( !iMessage.IsNull() && iMessage.Session() == aSession )
hgs
parents:
diff changeset
   329
        {
hgs
parents:
diff changeset
   330
        iMessage.Complete( KErrCancel );
hgs
parents:
diff changeset
   331
        }
hgs
parents:
diff changeset
   332
    }
hgs
parents:
diff changeset
   333
hgs
parents:
diff changeset
   334
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
   335
// Unpair the device from registry
hgs
parents:
diff changeset
   336
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
   337
//
hgs
parents:
diff changeset
   338
void CBTNotifSecurityManager::UnpairDevice( const TBTDevAddr& aAddr )
hgs
parents:
diff changeset
   339
    {
hgs
parents:
diff changeset
   340
    TIdentityRelation<TBTNamelessDevice> addrComp( CompareDeviceByAddress );
hgs
parents:
diff changeset
   341
    TBTNamelessDevice dev;
hgs
parents:
diff changeset
   342
    dev.SetAddress( aAddr );
hgs
parents:
diff changeset
   343
    // only do unpairing if the we have a link key with it.
hgs
parents:
diff changeset
   344
    TInt index = iPairedDevices.Find( dev, addrComp );
hgs
parents:
diff changeset
   345
    if ( index > KErrNotFound )
hgs
parents:
diff changeset
   346
        {
hgs
parents:
diff changeset
   347
        dev = iPairedDevices[index];
hgs
parents:
diff changeset
   348
        TRequestStatus status( KRequestPending );
hgs
parents:
diff changeset
   349
        // Unpair the device in registry (synchronously)
hgs
parents:
diff changeset
   350
        iRegistry.UnpairDevice( dev.Address(), status );
hgs
parents:
diff changeset
   351
        User::WaitForRequest( status );
hgs
parents:
diff changeset
   352
        BOstrace1(TRACE_DEBUG,DUMMY_DEVLIST,"Delete link key, res %d", status.Int());
hgs
parents:
diff changeset
   353
        if ( status == KErrNone )
hgs
parents:
diff changeset
   354
            {
hgs
parents:
diff changeset
   355
            TBTDeviceSecurity security = dev.GlobalSecurity();
hgs
parents:
diff changeset
   356
            // Clear trust setting so that correct icon will be shown in ui applications.
hgs
parents:
diff changeset
   357
            security.SetNoAuthenticate(EFalse );
hgs
parents:
diff changeset
   358
            security.SetNoAuthorise(EFalse );
hgs
parents:
diff changeset
   359
            dev.SetGlobalSecurity(security);
hgs
parents:
diff changeset
   360
            dev.DeleteLinkKey();
hgs
parents:
diff changeset
   361
            if ( dev.IsValidUiCookie() && 
hgs
parents:
diff changeset
   362
                 ( dev.UiCookie() & EBTUiCookieJustWorksPaired ) )
hgs
parents:
diff changeset
   363
                {
hgs
parents:
diff changeset
   364
                // Remove the UI cookie bit for Just Works pairing.
hgs
parents:
diff changeset
   365
                TInt32 cookie = dev.UiCookie() & ~EBTUiCookieJustWorksPaired;
hgs
parents:
diff changeset
   366
                dev.SetUiCookie( cookie );
hgs
parents:
diff changeset
   367
                BOstrace1(TRACE_DEBUG,DUMMY_DEVLIST,"UI cookie %x cleared", EBTUiCookieJustWorksPaired );
hgs
parents:
diff changeset
   368
                }
hgs
parents:
diff changeset
   369
            // modify the device in registry synchronously
hgs
parents:
diff changeset
   370
            // status.Int() could be -1 if the device is not in registry 
hgs
parents:
diff changeset
   371
            // which is totally fine for us.
hgs
parents:
diff changeset
   372
            (void) UpdateRegDevice( dev );
hgs
parents:
diff changeset
   373
            }
hgs
parents:
diff changeset
   374
        }
hgs
parents:
diff changeset
   375
    }
hgs
parents:
diff changeset
   376
hgs
parents:
diff changeset
   377
void CBTNotifSecurityManager::BlockDevice( const TBTDevAddr& aAddr , TBool aBanned)
hgs
parents:
diff changeset
   378
    {
hgs
parents:
diff changeset
   379
    TIdentityRelation<TBTNamelessDevice> addrComp( CompareDeviceByAddress );
hgs
parents:
diff changeset
   380
    TBTNamelessDevice dev;
hgs
parents:
diff changeset
   381
    dev.SetAddress( aAddr );
hgs
parents:
diff changeset
   382
    TRequestStatus status( KRequestPending );
hgs
parents:
diff changeset
   383
    // Unpair the device in registry (synchronously)
hgs
parents:
diff changeset
   384
    iRegistry.GetDevice(dev,status);
hgs
parents:
diff changeset
   385
    User::WaitForRequest( status ); 
hgs
parents:
diff changeset
   386
    if(status == KErrNone)
hgs
parents:
diff changeset
   387
        {
hgs
parents:
diff changeset
   388
        TBTDeviceSecurity security = dev.GlobalSecurity();
hgs
parents:
diff changeset
   389
        security.SetBanned(aBanned);
hgs
parents:
diff changeset
   390
        if ( aBanned )
hgs
parents:
diff changeset
   391
            {
hgs
parents:
diff changeset
   392
            security.SetNoAuthorise(EFalse);
hgs
parents:
diff changeset
   393
            }
hgs
parents:
diff changeset
   394
        dev.SetGlobalSecurity(security);
hgs
parents:
diff changeset
   395
        (void)UpdateRegDevice(dev);
hgs
parents:
diff changeset
   396
        }
hgs
parents:
diff changeset
   397
    }
hgs
parents:
diff changeset
   398
hgs
parents:
diff changeset
   399
TInt CBTNotifSecurityManager::AddUiCookieJustWorksPaired( const TBTNamelessDevice& aDev )
hgs
parents:
diff changeset
   400
    {
hgs
parents:
diff changeset
   401
    TInt err( KErrNone );
hgs
parents:
diff changeset
   402
    // There might be UI cookies used by other applications,
hgs
parents:
diff changeset
   403
    // we should not overwrite them. 
hgs
parents:
diff changeset
   404
    TInt32 cookie = aDev.IsValidUiCookie() ? aDev.UiCookie() : EBTUiCookieUndefined;
hgs
parents:
diff changeset
   405
    if ( !( cookie & EBTUiCookieJustWorksPaired ) )
hgs
parents:
diff changeset
   406
        {
hgs
parents:
diff changeset
   407
        // Only update the cookie if the wanted one is not in registry yet
hgs
parents:
diff changeset
   408
        // to keep minimal operations with registry.
hgs
parents:
diff changeset
   409
        TBTNamelessDevice dev = aDev;		
hgs
parents:
diff changeset
   410
        cookie |= EBTUiCookieJustWorksPaired;
hgs
parents:
diff changeset
   411
        dev.SetUiCookie( cookie );
hgs
parents:
diff changeset
   412
        err = UpdateRegDevice( dev );
hgs
parents:
diff changeset
   413
        BOstrace1(TRACE_DEBUG,DUMMY_DEVLIST,"Outgoing Pairing write Ui cookie ret %d", err );
hgs
parents:
diff changeset
   414
        }
hgs
parents:
diff changeset
   415
    return err;
hgs
parents:
diff changeset
   416
    }
hgs
parents:
diff changeset
   417
hgs
parents:
diff changeset
   418
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
   419
// update a nameless device in registry
hgs
parents:
diff changeset
   420
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
   421
//
hgs
parents:
diff changeset
   422
TInt CBTNotifSecurityManager::UpdateRegDevice( const TBTNamelessDevice& aDev )
hgs
parents:
diff changeset
   423
    {
hgs
parents:
diff changeset
   424
    TRequestStatus status( KRequestPending );
hgs
parents:
diff changeset
   425
    // update the device in registry synchronously
hgs
parents:
diff changeset
   426
    iRegistry.ModifyDevice( aDev, status );
hgs
parents:
diff changeset
   427
    User::WaitForRequest( status );
hgs
parents:
diff changeset
   428
    BOstrace1(TRACE_DEBUG,DUMMY_DEVLIST,"UpdateRegDevice, ret %d", status.Int());
hgs
parents:
diff changeset
   429
    return status.Int();
hgs
parents:
diff changeset
   430
    }
hgs
parents:
diff changeset
   431
hgs
parents:
diff changeset
   432
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
   433
// 0000 for outgoing pairing with a headset.
hgs
parents:
diff changeset
   434
// The placeholder for future extension (pin code passed in for pairing)
hgs
parents:
diff changeset
   435
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
   436
//
hgs
parents:
diff changeset
   437
void CBTNotifSecurityManager::GetPinCode(
hgs
parents:
diff changeset
   438
        TBTPinCode& aPin, const TBTDevAddr& aAddr, TInt aMinPinLength )
hgs
parents:
diff changeset
   439
    {
hgs
parents:
diff changeset
   440
    if ( iPairingHandler )
hgs
parents:
diff changeset
   441
        {
hgs
parents:
diff changeset
   442
        iPairingHandler->GetPinCode( aPin, aAddr, aMinPinLength );
hgs
parents:
diff changeset
   443
        }
hgs
parents:
diff changeset
   444
    else
hgs
parents:
diff changeset
   445
        {
hgs
parents:
diff changeset
   446
        // make sure not to leave any text as PIN.
hgs
parents:
diff changeset
   447
        aPin.Zero();
47
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   448
        aPin().iLength = 0;
42
hgs
parents:
diff changeset
   449
        }
hgs
parents:
diff changeset
   450
    }
hgs
parents:
diff changeset
   451
hgs
parents:
diff changeset
   452
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
   453
// Ask server class the connection status of the specified device
hgs
parents:
diff changeset
   454
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
   455
//
hgs
parents:
diff changeset
   456
TBTEngConnectionStatus CBTNotifSecurityManager::ConnectStatus( const TBTDevAddr& aAddr )
hgs
parents:
diff changeset
   457
    {
hgs
parents:
diff changeset
   458
    const CBtDevExtension* devExt = iDevRepository.Device(aAddr);
hgs
parents:
diff changeset
   459
    TBTEngConnectionStatus status = EBTEngNotConnected;
hgs
parents:
diff changeset
   460
    if ( devExt ) 
hgs
parents:
diff changeset
   461
        {
hgs
parents:
diff changeset
   462
        status = devExt->ServiceConnectionStatus();
hgs
parents:
diff changeset
   463
        }
hgs
parents:
diff changeset
   464
    return status;
hgs
parents:
diff changeset
   465
    }
hgs
parents:
diff changeset
   466
hgs
parents:
diff changeset
   467
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
   468
// From class MBTNotifPairingAOObserver.
hgs
parents:
diff changeset
   469
// Checks if there is an authentication result.
hgs
parents:
diff changeset
   470
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
   471
//
hgs
parents:
diff changeset
   472
void CBTNotifSecurityManager::RequestCompletedL( CBtSimpleActive* aActive, TInt aStatus )
hgs
parents:
diff changeset
   473
    {
hgs
parents:
diff changeset
   474
    BOstraceExt2(TRACE_DEBUG,DUMMY_DEVLIST,"aId: %d, aStatus: %d", aActive->RequestId(), aStatus);
hgs
parents:
diff changeset
   475
    // Check which request is completed.
hgs
parents:
diff changeset
   476
    switch( aActive->RequestId() )
hgs
parents:
diff changeset
   477
        {
hgs
parents:
diff changeset
   478
        case ESimplePairingResult:
hgs
parents:
diff changeset
   479
            {
hgs
parents:
diff changeset
   480
            TBTDevAddr tmpAddr = iSimplePairingRemote;
hgs
parents:
diff changeset
   481
            if (aStatus != KErrServerTerminated)
hgs
parents:
diff changeset
   482
                {
hgs
parents:
diff changeset
   483
                SubscribeSspPairingResult();
hgs
parents:
diff changeset
   484
                }
hgs
parents:
diff changeset
   485
            HandlePairingResultL( tmpAddr, aStatus );
hgs
parents:
diff changeset
   486
            break;
hgs
parents:
diff changeset
   487
            }
hgs
parents:
diff changeset
   488
        case EAuthenticationResult:
hgs
parents:
diff changeset
   489
            {
hgs
parents:
diff changeset
   490
            TBTDevAddr tmpAddr = iAuthenticateRemote;
hgs
parents:
diff changeset
   491
            if (aStatus != KErrServerTerminated)
hgs
parents:
diff changeset
   492
                {
hgs
parents:
diff changeset
   493
                SubscribeAuthenticateResult();
hgs
parents:
diff changeset
   494
                }
hgs
parents:
diff changeset
   495
            HandlePairingResultL( tmpAddr, aStatus );
hgs
parents:
diff changeset
   496
            break;
hgs
parents:
diff changeset
   497
            }
hgs
parents:
diff changeset
   498
        case ERegistryGetLocalAddress:
hgs
parents:
diff changeset
   499
            {
hgs
parents:
diff changeset
   500
            TBool value = IsLocalAddressAvailable();
hgs
parents:
diff changeset
   501
            SubscribeLocalAddress();
hgs
parents:
diff changeset
   502
            if ( value ) 
hgs
parents:
diff changeset
   503
                {
hgs
parents:
diff changeset
   504
                // Refresh paired devices list to include any restored devices.
hgs
parents:
diff changeset
   505
                iDevRepository.ReInitialize();
hgs
parents:
diff changeset
   506
                }
hgs
parents:
diff changeset
   507
            break;
hgs
parents:
diff changeset
   508
            }
hgs
parents:
diff changeset
   509
        default:
hgs
parents:
diff changeset
   510
            // Should not be possible, but no need for handling.
hgs
parents:
diff changeset
   511
            break;
hgs
parents:
diff changeset
   512
        }
hgs
parents:
diff changeset
   513
    }
hgs
parents:
diff changeset
   514
hgs
parents:
diff changeset
   515
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
   516
// From class MBTEngActiveObserver.
hgs
parents:
diff changeset
   517
// cancels an outstanding request according to the given id.
hgs
parents:
diff changeset
   518
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
   519
//
hgs
parents:
diff changeset
   520
void CBTNotifSecurityManager::CancelRequest( TInt aRequestId )
hgs
parents:
diff changeset
   521
    {
hgs
parents:
diff changeset
   522
    switch ( aRequestId )
hgs
parents:
diff changeset
   523
        {
hgs
parents:
diff changeset
   524
        case ESimplePairingResult:
hgs
parents:
diff changeset
   525
            {
hgs
parents:
diff changeset
   526
            // Cancel listening Simple pairing result
hgs
parents:
diff changeset
   527
            iPairingResult.CancelSimplePairingResult();
hgs
parents:
diff changeset
   528
            break;
hgs
parents:
diff changeset
   529
            }
hgs
parents:
diff changeset
   530
        case EAuthenticationResult:
hgs
parents:
diff changeset
   531
            {
hgs
parents:
diff changeset
   532
            // Cancel listening authentication result
hgs
parents:
diff changeset
   533
            iAuthenResult.CancelAuthenticationResult();
hgs
parents:
diff changeset
   534
            break;
hgs
parents:
diff changeset
   535
            }
hgs
parents:
diff changeset
   536
        case ERegistryGetLocalAddress:
hgs
parents:
diff changeset
   537
            {
hgs
parents:
diff changeset
   538
            // cancel listening local address status change
hgs
parents:
diff changeset
   539
            iPropertyLocalAddr.Cancel();
hgs
parents:
diff changeset
   540
            break;
hgs
parents:
diff changeset
   541
            }
hgs
parents:
diff changeset
   542
        }
hgs
parents:
diff changeset
   543
    }
hgs
parents:
diff changeset
   544
hgs
parents:
diff changeset
   545
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
   546
// From class MBtSimpleActiveObserver.
hgs
parents:
diff changeset
   547
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
   548
//
hgs
parents:
diff changeset
   549
void CBTNotifSecurityManager::HandleError( CBtSimpleActive* aActive, TInt aError )
hgs
parents:
diff changeset
   550
    {
hgs
parents:
diff changeset
   551
    BOstraceExt2(TRACE_DEBUG,DUMMY_DEVLIST,"request id: %d, error: %d", aActive->RequestId(), aError);
hgs
parents:
diff changeset
   552
    (void) aActive;
hgs
parents:
diff changeset
   553
    (void) aError;
hgs
parents:
diff changeset
   554
    }
hgs
parents:
diff changeset
   555
hgs
parents:
diff changeset
   556
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
   557
// From class MBtDevRepositoryObserver.
hgs
parents:
diff changeset
   558
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
   559
//
hgs
parents:
diff changeset
   560
void CBTNotifSecurityManager::RepositoryInitialized()
hgs
parents:
diff changeset
   561
    {
hgs
parents:
diff changeset
   562
    TRAPD(err, UpdatePairedDeviceListL() );
hgs
parents:
diff changeset
   563
    if ( !err && iPairingHandler )
hgs
parents:
diff changeset
   564
        {
hgs
parents:
diff changeset
   565
        // non-null pairing handler means we are involved in a
hgs
parents:
diff changeset
   566
        // pairing operation already.
hgs
parents:
diff changeset
   567
        // todo: is some handling for above case needed?
hgs
parents:
diff changeset
   568
        }
hgs
parents:
diff changeset
   569
    }
hgs
parents:
diff changeset
   570
hgs
parents:
diff changeset
   571
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
   572
// From class MBtDevRepositoryObserver.
hgs
parents:
diff changeset
   573
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
   574
//
hgs
parents:
diff changeset
   575
void CBTNotifSecurityManager::DeletedFromRegistry( const TBTDevAddr& aAddr )
hgs
parents:
diff changeset
   576
    {
hgs
parents:
diff changeset
   577
    // We are only interested in the removal of a paired device.
hgs
parents:
diff changeset
   578
    // thus check whether it is in our local paired list:
hgs
parents:
diff changeset
   579
    TInt i = iPairedDevices.Find( aAddr, MatchDeviceAddress);
hgs
parents:
diff changeset
   580
    if ( i > KErrNotFound )
hgs
parents:
diff changeset
   581
        {
hgs
parents:
diff changeset
   582
        iPairedDevices.Remove( i );
hgs
parents:
diff changeset
   583
        }
hgs
parents:
diff changeset
   584
    }
hgs
parents:
diff changeset
   585
hgs
parents:
diff changeset
   586
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
   587
// From class MBtDevRepositoryObserver.
hgs
parents:
diff changeset
   588
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
   589
//
hgs
parents:
diff changeset
   590
void CBTNotifSecurityManager::AddedToRegistry( const CBtDevExtension& aDevice )
hgs
parents:
diff changeset
   591
    {
hgs
parents:
diff changeset
   592
    // We are only interested in paired device.
hgs
parents:
diff changeset
   593
    if ( CBtDevExtension::IsBonded( aDevice.Device().AsNamelessDevice() ) )
hgs
parents:
diff changeset
   594
        {
hgs
parents:
diff changeset
   595
        TRAP_IGNORE( 
hgs
parents:
diff changeset
   596
                HandleRegistryBondingL( aDevice.Device().AsNamelessDevice() ) );
hgs
parents:
diff changeset
   597
        }
hgs
parents:
diff changeset
   598
    }
hgs
parents:
diff changeset
   599
hgs
parents:
diff changeset
   600
hgs
parents:
diff changeset
   601
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
   602
// From class MBtDevRepositoryObserver.
hgs
parents:
diff changeset
   603
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
   604
//
hgs
parents:
diff changeset
   605
void CBTNotifSecurityManager::ChangedInRegistry(
hgs
parents:
diff changeset
   606
        const CBtDevExtension& aDevice, TUint aSimilarity )
hgs
parents:
diff changeset
   607
    {
hgs
parents:
diff changeset
   608
    // We are only interested in paired device.
hgs
parents:
diff changeset
   609
    // thus check whether it is in our local paired list:
hgs
parents:
diff changeset
   610
    TInt i = iPairedDevices.Find( aDevice.Addr(), MatchDeviceAddress);
hgs
parents:
diff changeset
   611
    TBool bonded = CBtDevExtension::IsBonded( aDevice.Device().AsNamelessDevice() );
hgs
parents:
diff changeset
   612
    if ( i == KErrNotFound )
hgs
parents:
diff changeset
   613
        {
hgs
parents:
diff changeset
   614
        if ( bonded ) 
hgs
parents:
diff changeset
   615
            {
hgs
parents:
diff changeset
   616
            TRAP_IGNORE(
hgs
parents:
diff changeset
   617
                    HandleRegistryBondingL( 
hgs
parents:
diff changeset
   618
                            aDevice.Device().AsNamelessDevice() ) );                
hgs
parents:
diff changeset
   619
            }
hgs
parents:
diff changeset
   620
        return;
hgs
parents:
diff changeset
   621
        }
hgs
parents:
diff changeset
   622
    // Device was inregistry before, but we need to evaluate its bonding
hgs
parents:
diff changeset
   623
    // status.
hgs
parents:
diff changeset
   624
    // The given similarity will tell if the linkkey and paired is changed
hgs
parents:
diff changeset
   625
    // or not.
hgs
parents:
diff changeset
   626
    TInt pairingProperty = TBTNamelessDevice::EIsPaired 
hgs
parents:
diff changeset
   627
            | TBTNamelessDevice::ELinkKey;
hgs
parents:
diff changeset
   628
    if ( ( pairingProperty & aSimilarity) == pairingProperty )
hgs
parents:
diff changeset
   629
        {
hgs
parents:
diff changeset
   630
        // no pairing or linkkey change. Nothing to do for pairing handling.
hgs
parents:
diff changeset
   631
        // but we'd better update local copy just in case other data
hgs
parents:
diff changeset
   632
        // of this device is needed by someone:
hgs
parents:
diff changeset
   633
        iPairedDevices[i] = aDevice.Device().AsNamelessDevice();
hgs
parents:
diff changeset
   634
        return;
hgs
parents:
diff changeset
   635
        }
hgs
parents:
diff changeset
   636
    if ( !CBtDevExtension::IsBonded( aDevice.Device().AsNamelessDevice() ) )
hgs
parents:
diff changeset
   637
        {
hgs
parents:
diff changeset
   638
        // device is not user-bonded.
hgs
parents:
diff changeset
   639
        iPairedDevices.Remove( i );
hgs
parents:
diff changeset
   640
        return;
hgs
parents:
diff changeset
   641
        }
hgs
parents:
diff changeset
   642
    // it is a new paired device if its link-key has been upgraded
hgs
parents:
diff changeset
   643
    if ( aDevice.Device().LinkKeyType() != ELinkKeyUnauthenticatedUpgradable )
hgs
parents:
diff changeset
   644
        {
hgs
parents:
diff changeset
   645
        iPairedDevices.Remove( i );
hgs
parents:
diff changeset
   646
        TRAP_IGNORE(
hgs
parents:
diff changeset
   647
                HandleRegistryBondingL( 
hgs
parents:
diff changeset
   648
                        aDevice.Device().AsNamelessDevice() ) );                
hgs
parents:
diff changeset
   649
        }
hgs
parents:
diff changeset
   650
    }
hgs
parents:
diff changeset
   651
hgs
parents:
diff changeset
   652
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
   653
// From class MBtDevRepositoryObserver.
hgs
parents:
diff changeset
   654
// This class is not interested in such events.
hgs
parents:
diff changeset
   655
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
   656
//
hgs
parents:
diff changeset
   657
void CBTNotifSecurityManager::ServiceConnectionChanged(
hgs
parents:
diff changeset
   658
        const CBtDevExtension& aDevice, TBool aConnected )
hgs
parents:
diff changeset
   659
    {
hgs
parents:
diff changeset
   660
    (void) aDevice;
hgs
parents:
diff changeset
   661
    (void) aConnected;
hgs
parents:
diff changeset
   662
    }
hgs
parents:
diff changeset
   663
hgs
parents:
diff changeset
   664
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
   665
// Activate or deactivate a pairing handler
hgs
parents:
diff changeset
   666
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
   667
//
hgs
parents:
diff changeset
   668
TInt CBTNotifSecurityManager::SetPairObserver(const TBTDevAddr& aAddr, TBool aActivate)
hgs
parents:
diff changeset
   669
    {
hgs
parents:
diff changeset
   670
    BOstrace1(TRACE_DEBUG,DUMMY_DEVLIST,"%d", aActivate);
hgs
parents:
diff changeset
   671
    BtTraceBtAddr0(TRACE_DEBUG,DUMMY_DEVLIST, aAddr );
hgs
parents:
diff changeset
   672
    TInt err( KErrNone );
hgs
parents:
diff changeset
   673
    if ( !aActivate )
hgs
parents:
diff changeset
   674
        {
hgs
parents:
diff changeset
   675
        if ( iPairingHandler )
hgs
parents:
diff changeset
   676
            {
hgs
parents:
diff changeset
   677
            iPairingHandler->StopPairHandling( aAddr );
hgs
parents:
diff changeset
   678
            }
hgs
parents:
diff changeset
   679
        return err;
hgs
parents:
diff changeset
   680
        }
hgs
parents:
diff changeset
   681
    
hgs
parents:
diff changeset
   682
    if ( !iPairingHandler)
hgs
parents:
diff changeset
   683
        {
hgs
parents:
diff changeset
   684
        // This is an incoming pair, unpair it from registry and 
hgs
parents:
diff changeset
   685
        // create the handler:
hgs
parents:
diff changeset
   686
        UnpairDevice( aAddr );
hgs
parents:
diff changeset
   687
        TRAP( err, iPairingHandler = CBTNotifIncomingPairingHandler::NewL( *this, aAddr ));     
hgs
parents:
diff changeset
   688
        }
hgs
parents:
diff changeset
   689
    if ( iPairingHandler)
hgs
parents:
diff changeset
   690
        {
hgs
parents:
diff changeset
   691
        // let the handler decide what to do:
hgs
parents:
diff changeset
   692
        err = iPairingHandler->ObserveIncomingPair( aAddr );
hgs
parents:
diff changeset
   693
        }
hgs
parents:
diff changeset
   694
    return err;
hgs
parents:
diff changeset
   695
    }
hgs
parents:
diff changeset
   696
hgs
parents:
diff changeset
   697
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
   698
// Delegates the request to current pair handler
hgs
parents:
diff changeset
   699
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
   700
//
hgs
parents:
diff changeset
   701
void CBTNotifSecurityManager::PairDeviceL( const TBTDevAddr& aAddr, TUint32 aCod )
hgs
parents:
diff changeset
   702
    {
hgs
parents:
diff changeset
   703
    if ( !iPairingHandler)
hgs
parents:
diff changeset
   704
        {
hgs
parents:
diff changeset
   705
        // no existing pair handling, create one:
hgs
parents:
diff changeset
   706
        iPairingHandler = CBTNotifOutgoingPairingHandler::NewL( *this, aAddr );
hgs
parents:
diff changeset
   707
        }
hgs
parents:
diff changeset
   708
    // let pair handler decide what to do:
hgs
parents:
diff changeset
   709
    iPairingHandler->HandleOutgoingPairL( aAddr, aCod );
hgs
parents:
diff changeset
   710
    }
hgs
parents:
diff changeset
   711
hgs
parents:
diff changeset
   712
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
   713
// cancel Subscribings to simple pairing result and authentication result from
hgs
parents:
diff changeset
   714
// Pairing Server
hgs
parents:
diff changeset
   715
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
   716
//
hgs
parents:
diff changeset
   717
void CBTNotifSecurityManager::CancelSubscribePairingAuthenticate()
hgs
parents:
diff changeset
   718
    {
hgs
parents:
diff changeset
   719
    if( iSSPResultActive )
hgs
parents:
diff changeset
   720
        {
hgs
parents:
diff changeset
   721
        // Cancel listening Simple pairing result
hgs
parents:
diff changeset
   722
        iSSPResultActive->Cancel();
hgs
parents:
diff changeset
   723
        }
hgs
parents:
diff changeset
   724
    if( iAuthenResultActive )
hgs
parents:
diff changeset
   725
        {
hgs
parents:
diff changeset
   726
        iAuthenResultActive->Cancel();
hgs
parents:
diff changeset
   727
        }
hgs
parents:
diff changeset
   728
    }
hgs
parents:
diff changeset
   729
hgs
parents:
diff changeset
   730
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
   731
// Subscribes to simple pairing result from Pairing Server (if not already 
hgs
parents:
diff changeset
   732
// subscribed).
hgs
parents:
diff changeset
   733
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
   734
//
hgs
parents:
diff changeset
   735
void CBTNotifSecurityManager::SubscribeSspPairingResult()
hgs
parents:
diff changeset
   736
    {
hgs
parents:
diff changeset
   737
    if ( !iSSPResultActive->IsActive() )
hgs
parents:
diff changeset
   738
        {
hgs
parents:
diff changeset
   739
        iPairingResult.SimplePairingResult( iSimplePairingRemote, iSSPResultActive->RequestStatus() );
hgs
parents:
diff changeset
   740
        iSSPResultActive->GoActive();
hgs
parents:
diff changeset
   741
        }
hgs
parents:
diff changeset
   742
    }
hgs
parents:
diff changeset
   743
hgs
parents:
diff changeset
   744
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
   745
// Subscribes to authentication result from Pairing Server (if not already
hgs
parents:
diff changeset
   746
// subscribed).
hgs
parents:
diff changeset
   747
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
   748
//
hgs
parents:
diff changeset
   749
void CBTNotifSecurityManager::SubscribeAuthenticateResult()
hgs
parents:
diff changeset
   750
    {
hgs
parents:
diff changeset
   751
    if ( !iAuthenResultActive->IsActive() )
hgs
parents:
diff changeset
   752
        {
hgs
parents:
diff changeset
   753
        // Subscribe authentication result (which requires pairing for unpaired devices)
hgs
parents:
diff changeset
   754
        iAuthenResult.AuthenticationResult( iAuthenticateRemote, iAuthenResultActive->RequestStatus() );
hgs
parents:
diff changeset
   755
        iAuthenResultActive->GoActive();
hgs
parents:
diff changeset
   756
        }
hgs
parents:
diff changeset
   757
    }
hgs
parents:
diff changeset
   758
hgs
parents:
diff changeset
   759
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
   760
// Handle a pairing result from the pairing server.
hgs
parents:
diff changeset
   761
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
   762
//
hgs
parents:
diff changeset
   763
void CBTNotifSecurityManager::HandlePairingResultL( const TBTDevAddr& aAddr, TInt aResult )
hgs
parents:
diff changeset
   764
    {
hgs
parents:
diff changeset
   765
    BOstrace1(TRACE_DEBUG,DUMMY_DEVLIST,"result %d", aResult);
hgs
parents:
diff changeset
   766
    BtTraceBtAddr0(TRACE_DEBUG,DUMMY_DEVLIST, aAddr );
hgs
parents:
diff changeset
   767
 
hgs
parents:
diff changeset
   768
    if ( !iPairingHandler && ( aResult == KErrNone || aResult == KHCIErrorBase ) )
hgs
parents:
diff changeset
   769
        {
hgs
parents:
diff changeset
   770
        // we only create new handler if incoming pairing succeeds.
hgs
parents:
diff changeset
   771
        // Pairing failure could be caused by user local cancellation, as the  
hgs
parents:
diff changeset
   772
        // result, the handler was destroyed by notifier. We shall not
hgs
parents:
diff changeset
   773
        // instantiate the handler again.
hgs
parents:
diff changeset
   774
        // If a pairing failed due to other reasons than user local cancelling,
hgs
parents:
diff changeset
   775
        // it will be catched by the already started handler 
hgs
parents:
diff changeset
   776
        // (except Just Works pairing - no handler for it at all until we receive
hgs
parents:
diff changeset
   777
        // registry change event. Thus if incoming JWs pairing failed, no user
hgs
parents:
diff changeset
   778
        // notification will be shown.)
hgs
parents:
diff changeset
   779
        iPairedDevices.Find( aAddr, MatchDeviceAddress);
hgs
parents:
diff changeset
   780
        TInt index = iPairedDevices.Find( aAddr, MatchDeviceAddress);
hgs
parents:
diff changeset
   781
        // If the device is not found in the old paired device list, it is a new
hgs
parents:
diff changeset
   782
        // paired device:
hgs
parents:
diff changeset
   783
        if ( index == KErrNotFound)
hgs
parents:
diff changeset
   784
            {
hgs
parents:
diff changeset
   785
            // No handler yet, create incoming pairing handler:
hgs
parents:
diff changeset
   786
            iPairingHandler = CBTNotifIncomingPairingHandler::NewL( *this, aAddr );
hgs
parents:
diff changeset
   787
            }
hgs
parents:
diff changeset
   788
        }
hgs
parents:
diff changeset
   789
    if ( iPairingHandler )
hgs
parents:
diff changeset
   790
        {
hgs
parents:
diff changeset
   791
        iPairingHandler->HandlePairServerResult( aAddr, aResult );
hgs
parents:
diff changeset
   792
        }
hgs
parents:
diff changeset
   793
    }
hgs
parents:
diff changeset
   794
hgs
parents:
diff changeset
   795
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
   796
// copy the nameless devices to local array
hgs
parents:
diff changeset
   797
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
   798
//
hgs
parents:
diff changeset
   799
void CBTNotifSecurityManager::UpdatePairedDeviceListL()
hgs
parents:
diff changeset
   800
    {
hgs
parents:
diff changeset
   801
    iPairedDevices.Reset();
hgs
parents:
diff changeset
   802
    const RDevExtensionArray& alldevs = iDevRepository.AllDevices();
hgs
parents:
diff changeset
   803
    for ( TInt i = 0; i < alldevs.Count(); i++ )
hgs
parents:
diff changeset
   804
        {
hgs
parents:
diff changeset
   805
        if ( CBtDevExtension::IsBonded( alldevs[i]->Device().AsNamelessDevice() ) )
hgs
parents:
diff changeset
   806
            {
hgs
parents:
diff changeset
   807
            iPairedDevices.AppendL( alldevs[i]->Device().AsNamelessDevice() );
hgs
parents:
diff changeset
   808
            }
hgs
parents:
diff changeset
   809
        }
hgs
parents:
diff changeset
   810
    }
hgs
parents:
diff changeset
   811
hgs
parents:
diff changeset
   812
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
   813
// Create incoming pairing handler if no one exists yet.
hgs
parents:
diff changeset
   814
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
   815
//
hgs
parents:
diff changeset
   816
void CBTNotifSecurityManager::HandleRegistryBondingL(
hgs
parents:
diff changeset
   817
        const TBTNamelessDevice& aNameless)
hgs
parents:
diff changeset
   818
    {
hgs
parents:
diff changeset
   819
    TInt err = iPairedDevices.Append( aNameless );
hgs
parents:
diff changeset
   820
    if ( !err && !iPairingHandler)
hgs
parents:
diff changeset
   821
        {
hgs
parents:
diff changeset
   822
        // New paired device, but no pairing handler yet.
hgs
parents:
diff changeset
   823
        // this means an incoming pairing has occured:
hgs
parents:
diff changeset
   824
        TRAP( err, iPairingHandler = 
hgs
parents:
diff changeset
   825
                CBTNotifIncomingPairingHandler::NewL( *this, aNameless.Address() ) );
hgs
parents:
diff changeset
   826
        }
hgs
parents:
diff changeset
   827
    if ( !err )
hgs
parents:
diff changeset
   828
        {
hgs
parents:
diff changeset
   829
        // We have a pairing handler now.
hgs
parents:
diff changeset
   830
        // Ask pair handler to decide what to do:
hgs
parents:
diff changeset
   831
        iPairingHandler->HandleRegistryNewPairedEvent( 
hgs
parents:
diff changeset
   832
                aNameless );
hgs
parents:
diff changeset
   833
        }
hgs
parents:
diff changeset
   834
    else if ( iPairingHandler )
hgs
parents:
diff changeset
   835
        {
hgs
parents:
diff changeset
   836
        // error could occur due to no memory, 
hgs
parents:
diff changeset
   837
        // let us try aborting pairing handling
hgs
parents:
diff changeset
   838
        iPairingHandler->StopPairHandling( aNameless.Address() );
hgs
parents:
diff changeset
   839
        }
hgs
parents:
diff changeset
   840
    }
hgs
parents:
diff changeset
   841
hgs
parents:
diff changeset
   842
void CBTNotifSecurityManager::TrustDevice( const TBTDevAddr& aAddr )
hgs
parents:
diff changeset
   843
    {
hgs
parents:
diff changeset
   844
    TIdentityRelation<TBTNamelessDevice> addrComp( CompareDeviceByAddress );
hgs
parents:
diff changeset
   845
    TBTNamelessDevice dev;
hgs
parents:
diff changeset
   846
    dev.SetAddress( aAddr );
hgs
parents:
diff changeset
   847
    TRequestStatus status( KRequestPending );
hgs
parents:
diff changeset
   848
    
hgs
parents:
diff changeset
   849
    iRegistry.GetDevice(dev,status);
hgs
parents:
diff changeset
   850
    User::WaitForRequest( status ); 
hgs
parents:
diff changeset
   851
    if(status == KErrNone)
hgs
parents:
diff changeset
   852
        {
hgs
parents:
diff changeset
   853
        TBTDeviceSecurity security = dev.GlobalSecurity();
hgs
parents:
diff changeset
   854
        security.SetNoAuthorise(ETrue);
hgs
parents:
diff changeset
   855
        security.SetBanned(EFalse);
hgs
parents:
diff changeset
   856
        dev.SetGlobalSecurity(security);
hgs
parents:
diff changeset
   857
        (void)UpdateRegDevice(dev);
hgs
parents:
diff changeset
   858
        }
hgs
parents:
diff changeset
   859
    }
hgs
parents:
diff changeset
   860