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