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