bluetoothengine/btnotif/btnotifsrv/inc/btnotifsecuritymanager.h
changeset 42 b72428996822
child 57 5ebadcda06cb
equal deleted inserted replaced
32:19bd632b5100 42:b72428996822
       
     1 /*
       
     2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 *
       
    16 */
       
    17 
       
    18 #ifndef BTNOTIFSECURITYMANAGER_H
       
    19 #define BTNOTIFSECURITYMANAGER_H
       
    20 
       
    21 #include <bttypes.h>
       
    22 #include <bt_sock.h>
       
    23 #include <bluetooth/pairing.h>
       
    24 #include <btservices/btsimpleactive.h>
       
    25 #include <btservices/btdevrepository.h>
       
    26 #include <btengconstants.h>
       
    27 
       
    28 class CBTNotifBasePairingHandler;
       
    29 class CBTNotifPairNotifier;
       
    30 class CBTNotifConnectionTracker;
       
    31 class CBtDevRepository;
       
    32 class CBTNotifServiceAuthorizer;
       
    33 
       
    34 /**
       
    35  *  Class CBTNotifSecurityManager
       
    36  *
       
    37  *  This class manages pairing with BT devices.
       
    38  *  The responsibility of handling incoming and outgoing pairings is
       
    39  *  delegated to CBTNotifIncomingPairingHandler and CBTNotifOutgoingPairingHandler 
       
    40  *  respectively.
       
    41  *
       
    42  *  @since Symbian^4
       
    43  */
       
    44 NONSHARABLE_CLASS( CBTNotifSecurityManager ) : 
       
    45     public CBase, 
       
    46     public MBtSimpleActiveObserver,
       
    47     public MBtDevRepositoryObserver
       
    48     {
       
    49 public:
       
    50 
       
    51     /**
       
    52      * Two-phase constructor
       
    53      */
       
    54     static CBTNotifSecurityManager* NewL( 
       
    55             CBTNotifConnectionTracker& aParent, 
       
    56             CBtDevRepository& aDevRepository );
       
    57 
       
    58     /**
       
    59      * Destructor
       
    60      */
       
    61     ~CBTNotifSecurityManager();
       
    62 
       
    63     /**
       
    64      * Cancels an outstanding pairing request.
       
    65      */
       
    66     void CancelOutgoingPair();    
       
    67     
       
    68     /**
       
    69      * Process commands relevant to pairing
       
    70      */
       
    71     void HandleBondingRequestL( const RMessage2& aMessage );
       
    72 
       
    73     void HandleNotifierRequestL( const RMessage2& aMessage );
       
    74     
       
    75     /**
       
    76      * Gets the instance of pairing server.
       
    77      * @return the server instance. NULL if dedicated bonding is unavailable.
       
    78      */
       
    79     RBluetoothPairingServer* PairingServer();
       
    80     
       
    81     /**
       
    82      * gets the reference of socket server session
       
    83      */
       
    84     RSocketServ& SocketServ();
       
    85     
       
    86     /**
       
    87      * gets the reference of devrepository.
       
    88      */
       
    89     CBtDevRepository& BTDevRepository();
       
    90     
       
    91     /**
       
    92      * gets the reference of connection tracker.
       
    93      */
       
    94     CBTNotifConnectionTracker& ConnectionTracker();
       
    95     
       
    96     /**
       
    97      *  Transfer responsiblity to the specified object.
       
    98      *  @param aPairer the object whose the responsibility is transfered.
       
    99      */
       
   100     void RenewPairingHandler( CBTNotifBasePairingHandler* aPairingHandler );
       
   101     
       
   102     /**
       
   103      * Be notified when handling of an outgoing pair has been completed.
       
   104      * @param aErr the result of pairing
       
   105      * 
       
   106      */
       
   107     void OutgoingPairCompleted( TInt aErr );
       
   108     
       
   109     /**
       
   110      * Be informed that a session will be closed.
       
   111      *
       
   112      * @since Symbian^4
       
   113      * @param aSession the session to be cloased.
       
   114      */
       
   115     void SessionClosed(CSession2* aSession );
       
   116     
       
   117     /**
       
   118      * Unpair a device via registry
       
   119      */
       
   120     void UnpairDevice( const TBTDevAddr& aAddr );
       
   121 
       
   122     /**
       
   123      * Block a device via registry
       
   124      */
       
   125     void BlockDevice( const TBTDevAddr& aAddr , TBool aBanned);
       
   126     
       
   127     /**
       
   128      * Add the bit indicating the device is user-aware Just worked paired to
       
   129      * UI cookie.
       
   130      */
       
   131     TInt AddUiCookieJustWorksPaired( const TBTNamelessDevice& aDev );
       
   132     
       
   133     /**
       
   134      * Update a nameless device in registry
       
   135      */
       
   136     TInt UpdateRegDevice( const TBTNamelessDevice& aDev );
       
   137     
       
   138     /**
       
   139      * Gets the pin code to be used for pairing a device.
       
   140      * @param aPin contains the pin code if it is not empty
       
   141      * @param aAddr the device to which pairing is performed.
       
   142      * @param the required minimum length of a pin code.
       
   143      */
       
   144     void GetPinCode( TBTPinCode& aPin, const TBTDevAddr& aAddr, TInt aMinPinLength );
       
   145     
       
   146     /**
       
   147      * Returns the service (limited to services managed in bteng scope)
       
   148      * level connection status of the specified device.
       
   149      *
       
   150      * @param aAddr the address of the device
       
   151      * @return one of TBTEngConnectionStatus enums
       
   152      */
       
   153     TBTEngConnectionStatus ConnectStatus( const TBTDevAddr& aAddr );
       
   154     
       
   155     /**
       
   156      * Activate / deactivate a pair observer
       
   157      */
       
   158     TInt SetPairObserver(const TBTDevAddr& aAddr, TBool aActivate);
       
   159     
       
   160     /**
       
   161      * Trust a device via the registry
       
   162      */
       
   163     void TrustDevice( const TBTDevAddr& aAddr );
       
   164     
       
   165 private: 
       
   166     
       
   167     // from base class MBtSimpleActiveObserver
       
   168 
       
   169     /**
       
   170      * 
       
   171      * Callback to notify that an outstanding request has completed.
       
   172      *
       
   173      * @since Symbian^4
       
   174      * @param aActive Pointer to the active object that completed.
       
   175      * @param aId The ID that identifies the outstanding request.
       
   176      * @param aStatus The status of the completed request.
       
   177      */
       
   178     virtual void RequestCompletedL( CBtSimpleActive* aActive, TInt aStatus );
       
   179 
       
   180     /**
       
   181      * Callback from Docancel() for handling cancelation of an outstanding request.
       
   182      *
       
   183      * @since Symbian^4
       
   184      * @param aId The ID that identifies the outstanding request.
       
   185      */
       
   186     virtual void CancelRequest( TInt aRequestId );
       
   187     
       
   188     /**
       
   189      * Callback to notify that an error has occurred in RunL.
       
   190      *
       
   191      * @since Symbian^4
       
   192      * @param aActive Pointer to the active object that completed.
       
   193      * @param aId The ID that identifies the outstanding request.
       
   194      * @param aStatus The status of the completed request.
       
   195      */
       
   196     virtual void HandleError( CBtSimpleActive* aActive, TInt aError );
       
   197 
       
   198     // From base class MBtDevRepositoryObserver
       
   199     
       
   200     /**
       
   201      * Callback to notify that the repository has finished initialization.
       
   202      * Initialization completion means the repository has retieved all
       
   203      * Bluetooth devices from BT registry, and it is subscribing to
       
   204      * registry update events.
       
   205      */
       
   206     virtual void RepositoryInitialized();    
       
   207     
       
   208     /**
       
   209      * Callback to notify that a device has been deleted from BT registry.
       
   210      * 
       
   211      *
       
   212      * @param aAddr the bd_addr of the deleted device
       
   213      */
       
   214     virtual void DeletedFromRegistry( const TBTDevAddr& aAddr );
       
   215     
       
   216     /**
       
   217      * Callback to notify that the device has been added to BT registry.
       
   218      *
       
   219      * @param aDevice the device that has been added to registry
       
   220      */
       
   221     virtual void AddedToRegistry( const CBtDevExtension& aDevice );
       
   222     
       
   223     /**
       
   224      * Callback to notify that the property of a device in BT registry has been
       
   225      * changed.
       
   226      *
       
   227      * @param aDevice the device that possesses the latest properties.
       
   228      * @param aSimilarity the similarity of the properties comparing to the ones
       
   229      *        prior to this change.
       
   230      *        Refer CBTDevice::TBTDeviceNameSelector and 
       
   231      *        TBTNamelessDevice::TBTDeviceSet for the meanings of the bits 
       
   232      *        in this parameter.
       
   233      */
       
   234     virtual void ChangedInRegistry(
       
   235             const CBtDevExtension& aDevice, TUint aSimilarity ); 
       
   236     
       
   237     /**
       
   238      * Callback to notify that the status of service (limited to 
       
   239      * services maintained in btengsrv scope) connections with 
       
   240      * a device has changed.
       
   241      *
       
   242      * @param aDevice the device to which the status change refers
       
   243      * @param aConnected ETrue if at least one service is currently connected.
       
   244      *        EFalse if no service is currently connected.
       
   245      */
       
   246     virtual void ServiceConnectionChanged(
       
   247             const CBtDevExtension& aDevice, TBool aConnected );
       
   248 
       
   249     
       
   250 private:
       
   251     
       
   252     /**
       
   253      * C++ default constructor
       
   254      */
       
   255     CBTNotifSecurityManager(
       
   256             CBTNotifConnectionTracker& aParent,
       
   257             CBtDevRepository& aDevRepository );
       
   258     
       
   259     /**
       
   260      * Symbian 2nd-phase constructor
       
   261      */
       
   262     void ConstructL();
       
   263 
       
   264     /**
       
   265      * Subscribe local device address for determining 
       
   266      * Bluetooth HW power status
       
   267      */
       
   268     void SubscribeLocalAddress();
       
   269 
       
   270     TBool IsLocalAddressAvailable();
       
   271    
       
   272     /**
       
   273      * Pair a BT device.
       
   274      */
       
   275     void PairDeviceL( const TBTDevAddr& aAddr, TUint32 aCod );
       
   276     
       
   277     /**
       
   278      * Cancel all subscribes to pairng server
       
   279      */
       
   280     void CancelSubscribePairingAuthenticate();
       
   281     
       
   282     /**
       
   283      * subscribe to receive SSP pairing result from pairing server
       
   284      */
       
   285     void SubscribeSspPairingResult();
       
   286     
       
   287     /**
       
   288      * Subscribe to receive authentication result from pairing server
       
   289      */
       
   290     void SubscribeAuthenticateResult();
       
   291 
       
   292     /**
       
   293      * Handle a pairing result from the pairing server.
       
   294      *
       
   295      * @since Symbian^4
       
   296      * @param aResult The status code of the authentication result.
       
   297      */
       
   298     void HandlePairingResultL( const TBTDevAddr& aAddr, TInt aResult );
       
   299     
       
   300     /**
       
   301      * Copy the paired devices to internal array storage.
       
   302      */
       
   303     void UpdatePairedDeviceListL();
       
   304     
       
   305     /**
       
   306      * Handles a new bonding event from Registry.
       
   307      */
       
   308     void HandleRegistryBondingL( const TBTNamelessDevice& aNameless );
       
   309     
       
   310    
       
   311 private:
       
   312 
       
   313     /**
       
   314      * Owner of this class.
       
   315      * Not owned.
       
   316      */
       
   317     CBTNotifConnectionTracker& iParent;
       
   318     
       
   319     /**
       
   320      * Reference to repository.
       
   321      * Not owned.
       
   322      */
       
   323     CBtDevRepository& iDevRepository;
       
   324     
       
   325     /**
       
   326      * The session with BT registry.
       
   327      * own.
       
   328      */
       
   329     RBTRegistry iRegistry;
       
   330     
       
   331     /**
       
   332      * contains the list of all paired devices.
       
   333      */
       
   334     RArray<TBTNamelessDevice> iPairedDevices;
       
   335 
       
   336     /**
       
   337      * Session with the pairing server.
       
   338      * Allocate it in heap to ease the handling for 
       
   339      * situation of unavailable dedicated pairing service.
       
   340      * 
       
   341      * own.
       
   342      */
       
   343     RBluetoothPairingServer* iPairingServ;
       
   344 
       
   345     /**
       
   346      * Subsession with the pairing server for 
       
   347      * getting the simple pairing result.
       
   348      * own
       
   349      */
       
   350     RBluetoothPairingResult iPairingResult;
       
   351 
       
   352     /**
       
   353      * Subsession with the pairing server for 
       
   354      * getting the authentication result.
       
   355      * own
       
   356      */
       
   357     RBluetoothAuthenticationResult iAuthenResult;
       
   358 
       
   359     /**
       
   360      * the address with which a simple pairing has been performed
       
   361      */
       
   362     TBTDevAddr iSimplePairingRemote;
       
   363 
       
   364     /**
       
   365      * the address with which an authentication has been performed
       
   366      */
       
   367     TBTDevAddr iAuthenticateRemote;
       
   368     
       
   369     /**
       
   370      * Active object helper for receiving simple pairing results.
       
   371      * Own.
       
   372      */
       
   373     CBtSimpleActive* iSSPResultActive;
       
   374 
       
   375     /**
       
   376      * Active object helper for receiving authentication results.
       
   377      * Own.
       
   378      */
       
   379     CBtSimpleActive* iAuthenResultActive;
       
   380 
       
   381     /**
       
   382      * pairing hanlder at the time.
       
   383      * Own.
       
   384      */
       
   385     CBTNotifBasePairingHandler* iPairingHandler;
       
   386     
       
   387     /**
       
   388      * The handler for pairing notifiers 
       
   389      */
       
   390     CBTNotifPairNotifier* iPairNotifier;
       
   391     
       
   392     /**
       
   393      * Client-server message for power change requests.
       
   394      */
       
   395     RMessage2 iMessage;
       
   396 
       
   397     /**
       
   398      * AO for local address updates.
       
   399      */
       
   400     CBtSimpleActive* iLocalAddrActive;
       
   401 
       
   402     /**
       
   403      * Provides access to the BT local device address.
       
   404      */
       
   405     RProperty iPropertyLocalAddr;
       
   406     
       
   407     CBTNotifServiceAuthorizer* iServiceAuthorizer;
       
   408     };
       
   409 
       
   410 #endif /*BTNOTIFSECURITYMANAGER_H*/
       
   411 
       
   412 
       
   413