bluetoothengine/btnotif/btnotifsrv/src/btnotifoutgoingpairinghandler.cpp
changeset 40 997690c3397a
parent 33 837dcc42fd6a
child 41 0b2439c3e397
equal deleted inserted replaced
37:91746b151f97 40:997690c3397a
    16 */
    16 */
    17 
    17 
    18 #include "btnotifoutgoingpairinghandler.h"
    18 #include "btnotifoutgoingpairinghandler.h"
    19 #include <btengconstants.h>
    19 #include <btengconstants.h>
    20 #include <btservices/btdevextension.h>
    20 #include <btservices/btdevextension.h>
    21 #include "btnotifpairingmanager.h"
    21 #include "btnotifsecuritymanager.h"
       
    22 #include "bluetoothtrace.h"
    22 
    23 
    23 /**  Length of the default PIN. */
    24 /**  Length of the default PIN. */
    24 const TInt KDefaultHeadsetPinLength = 4;
    25 const TInt KDefaultHeadsetPinLength = 4;
    25 
    26 
    26 enum TPairingStageId
    27 enum TPairingStageId
    68 
    69 
    69 // ---------------------------------------------------------------------------
    70 // ---------------------------------------------------------------------------
    70 // C++ default constructor
    71 // C++ default constructor
    71 // ---------------------------------------------------------------------------
    72 // ---------------------------------------------------------------------------
    72 //
    73 //
    73 CBTNotifOutgoingPairingHandler::CBTNotifOutgoingPairingHandler( CBTNotifPairingManager& aParent, const TBTDevAddr& aAddr)
    74 CBTNotifOutgoingPairingHandler::CBTNotifOutgoingPairingHandler( CBTNotifSecurityManager& aParent, const TBTDevAddr& aAddr)
    74     :  CBTNotifBasePairingHandler( aParent, aAddr )
    75     :  CBTNotifBasePairingHandler( aParent, aAddr )
    75     {
    76     {
    76     }
    77     }
    77 
    78 
    78 // ---------------------------------------------------------------------------
    79 // ---------------------------------------------------------------------------
    87 
    88 
    88 // ---------------------------------------------------------------------------
    89 // ---------------------------------------------------------------------------
    89 // NewL
    90 // NewL
    90 // ---------------------------------------------------------------------------
    91 // ---------------------------------------------------------------------------
    91 //
    92 //
    92 CBTNotifBasePairingHandler* CBTNotifOutgoingPairingHandler::NewL( CBTNotifPairingManager& aParent, 
    93 CBTNotifBasePairingHandler* CBTNotifOutgoingPairingHandler::NewL( CBTNotifSecurityManager& aParent, 
    93         const TBTDevAddr& aAddr )
    94         const TBTDevAddr& aAddr )
    94     {
    95     {
    95     CBTNotifOutgoingPairingHandler* self = new( ELeave ) CBTNotifOutgoingPairingHandler( aParent, aAddr );
    96     CBTNotifOutgoingPairingHandler* self = new( ELeave ) CBTNotifOutgoingPairingHandler( aParent, aAddr );
    96     CleanupStack::PushL( self );
    97     CleanupStack::PushL( self );
    97     self->ConstructL();
    98     self->ConstructL();
   127 // Accept the request only this device is not busy with another pairing request.
   128 // Accept the request only this device is not busy with another pairing request.
   128 // ---------------------------------------------------------------------------
   129 // ---------------------------------------------------------------------------
   129 //
   130 //
   130 void CBTNotifOutgoingPairingHandler::HandleOutgoingPairL( const TBTDevAddr& aAddr, TUint aCod )
   131 void CBTNotifOutgoingPairingHandler::HandleOutgoingPairL( const TBTDevAddr& aAddr, TUint aCod )
   131     {
   132     {
   132     // TRACE_FUNC_ARG( ( _L(" cod 0x%08x"), aCod ) )
   133     BOstrace1(TRACE_DEBUG,DUMMY_DEVLIST," cod 0x%08x", aCod );
   133     if ( iActive->IsActive() || aAddr != iAddr )
   134     if ( iActive->IsActive() || aAddr != iAddr )
   134         {
   135         {
   135         // we don't allow another pairing request.
   136         // we don't allow another pairing request.
   136         User::Leave( KErrServerBusy );
   137         User::Leave( KErrServerBusy );
   137         }
   138         }
   147         }
   148         }
   148     else
   149     else
   149         {
   150         {
   150         iPairMode = EBTOutgoingNoneHeadsetPairing;
   151         iPairMode = EBTOutgoingNoneHeadsetPairing;
   151         }
   152         }
   152     // SetOutgoPairProperty( iOutgoProperty, iAddr, iPairMode );
       
   153     DoPairingL();
   153     DoPairingL();
   154     }
   154     }
   155 
   155 
   156 // ---------------------------------------------------------------------------
   156 // ---------------------------------------------------------------------------
   157 // Cancels an outstanding pair request by self-destruct
   157 // Cancels an outstanding pair request by self-destruct
   158 // ---------------------------------------------------------------------------
   158 // ---------------------------------------------------------------------------
   159 //
   159 //
   160 void CBTNotifOutgoingPairingHandler::CancelOutgoingPair()
   160 void CBTNotifOutgoingPairingHandler::CancelOutgoingPair()
   161     {
   161     {
       
   162     BOstraceFunctionEntry0( DUMMY_DEVLIST );
   162     iParent.RenewPairingHandler( NULL );
   163     iParent.RenewPairingHandler( NULL );
   163     }
   164     }
   164 
   165 
   165 
   166 
   166 // ---------------------------------------------------------------------------
   167 // ---------------------------------------------------------------------------
   169 // ---------------------------------------------------------------------------
   170 // ---------------------------------------------------------------------------
   170 //
   171 //
   171 void CBTNotifOutgoingPairingHandler::GetPinCode( 
   172 void CBTNotifOutgoingPairingHandler::GetPinCode( 
   172         TBTPinCode& aPin, const TBTDevAddr& aAddr, TInt aMinPinLength )
   173         TBTPinCode& aPin, const TBTDevAddr& aAddr, TInt aMinPinLength )
   173     {
   174     {
       
   175     BOstraceFunctionEntry0( DUMMY_DEVLIST );
   174     aPin().iLength = 0;
   176     aPin().iLength = 0;
   175     if ( aMinPinLength <= KDefaultHeadsetPinLength 
   177     if ( aMinPinLength <= KDefaultHeadsetPinLength 
   176             && aAddr == iAddr
   178             && aAddr == iAddr
   177             && iPairMode == EBTOutgoingHeadsetAutoPairing)
   179             && iPairMode == EBTOutgoingHeadsetAutoPairing)
   178         {
   180         {
   193 // Abort pairing handling, request the owner to destroy this.
   195 // Abort pairing handling, request the owner to destroy this.
   194 // ---------------------------------------------------------------------------
   196 // ---------------------------------------------------------------------------
   195 //
   197 //
   196 void CBTNotifOutgoingPairingHandler::StopPairHandling( const TBTDevAddr& aAddr )
   198 void CBTNotifOutgoingPairingHandler::StopPairHandling( const TBTDevAddr& aAddr )
   197     {
   199     {
       
   200     BOstraceFunctionEntry0( DUMMY_DEVLIST );
   198     if ( aAddr == iAddr )
   201     if ( aAddr == iAddr )
   199         {
   202         {
   200         iParent.OutgoingPairCompleted( KErrCancel );
   203         iParent.OutgoingPairCompleted( KErrCancel );
   201         iParent.RenewPairingHandler( NULL );
   204         iParent.RenewPairingHandler( NULL );
   202         }
   205         }
   206 // Pairing result will be received when pairing operation completes.
   209 // Pairing result will be received when pairing operation completes.
   207 // ---------------------------------------------------------------------------
   210 // ---------------------------------------------------------------------------
   208 //
   211 //
   209 void CBTNotifOutgoingPairingHandler::DoHandlePairServerResult( TInt aResult )
   212 void CBTNotifOutgoingPairingHandler::DoHandlePairServerResult( TInt aResult )
   210     {
   213     {
       
   214     BOstraceFunctionEntry0( DUMMY_DEVLIST );
   211 	if (aResult == (KHCIErrorBase-EPairingNotAllowed))
   215 	if (aResult == (KHCIErrorBase-EPairingNotAllowed))
   212 		{
   216 		{
   213 		// if EPairingNotAllowed is recieved then any further pairing attempts will fail
   217 		// if EPairingNotAllowed is recieved then any further pairing attempts will fail
   214 		// so don't attampt to pair
   218 		// so don't attampt to pair
   215         iPairMode = EBTOutgoingPairNone;
   219         iPairMode = EBTOutgoingPairNone;
   221 // ---------------------------------------------------------------------------
   225 // ---------------------------------------------------------------------------
   222 //
   226 //
   223 void CBTNotifOutgoingPairingHandler::DoHandleRegistryNewPairedEvent( 
   227 void CBTNotifOutgoingPairingHandler::DoHandleRegistryNewPairedEvent( 
   224         const TBTNamelessDevice& aDev )
   228         const TBTNamelessDevice& aDev )
   225     {
   229     {
       
   230     BOstraceFunctionEntry0( DUMMY_DEVLIST );
   226     TInt err( KErrNone );
   231     TInt err( KErrNone );
   227     // If pairing was performed using Just Works mode, we set a 
   232     // If pairing was performed using Just Works mode, we set a 
   228     // UICookie to indicate that the device is successfully 
   233     // UICookie to indicate that the device is successfully 
   229     // bonded so that this device will be listed in paired device view of
   234     // bonded so that this device will be listed in paired device view of
   230     // bluetooth application:
   235     // bluetooth application:
   231     if ( aDev.LinkKeyType() == ELinkKeyUnauthenticatedNonUpgradable )
   236     if ( aDev.LinkKeyType() == ELinkKeyUnauthenticatedNonUpgradable )
   232         {
   237         {
   233         // TRACE_INFO( ( _L( "[BTENG] CBTEngOtgPair, Just Works pairing" ) ) );
   238         BOstrace0(TRACE_DEBUG,DUMMY_DEVLIST,"[BTNOTIF] Outgoing Pairing, Just Works pairing");
   234         err = iParent.AddUiCookieJustWorksPaired( aDev );
   239         err = iParent.AddUiCookieJustWorksPaired( aDev );
   235         }
   240         }
   236     iActive->Cancel();
   241     iActive->Cancel();
   237     SetPairResult( err ? err : KErrNone );
   242     SetPairResult( err ? err : KErrNone );
       
   243     if(err == KErrNone){
       
   244     TRAP_IGNORE(ShowPairingResultNoteL(err));
       
   245     }
   238     iParent.OutgoingPairCompleted( err );
   246     iParent.OutgoingPairCompleted( err );
   239     iParent.RenewPairingHandler( NULL );
   247     iParent.RenewPairingHandler( NULL );
   240     }
   248     }
   241 
   249 
   242 // ---------------------------------------------------------------------------
   250 // ---------------------------------------------------------------------------
   246 // ---------------------------------------------------------------------------
   254 // ---------------------------------------------------------------------------
   247 //
   255 //
   248 void CBTNotifOutgoingPairingHandler::RequestCompletedL( 
   256 void CBTNotifOutgoingPairingHandler::RequestCompletedL( 
   249         CBtSimpleActive* aActive, TInt aStatus )
   257         CBtSimpleActive* aActive, TInt aStatus )
   250     {
   258     {
   251     // TRACE_FUNC_ARG( ( _L( "reqid %d, status: %d, pair mode %d " ), aId, aStatus, iPairMode ) )
   259     BOstraceFunctionEntry0( DUMMY_DEVLIST );
       
   260     BOstraceExt3(TRACE_DEBUG,DUMMY_DEVLIST,"reqid %d, status: %d, pair mode %d ", aActive->RequestId(), aStatus, iPairMode);
   252     if( aActive->RequestId() == EDedicatedBonding && 
   261     if( aActive->RequestId() == EDedicatedBonding && 
   253 				( aStatus == KErrRemoteDeviceIndicatedNoBonding || 
   262 				( aStatus == KErrRemoteDeviceIndicatedNoBonding || 
   254 					( aStatus && iPairMode != EBTOutgoingNoneHeadsetPairing && iPairMode != EBTOutgoingPairNone ) )   )
   263 					( aStatus && iPairMode != EBTOutgoingNoneHeadsetPairing && iPairMode != EBTOutgoingPairNone ) )   )
   255         {
   264         {
   256         // try general pairing if the remote doesn't have dedicated bonding, or
   265         // try general pairing if the remote doesn't have dedicated bonding, or
   259         }
   268         }
   260     else if ( aStatus && iPairMode == EBTOutgoingHeadsetAutoPairing )
   269     else if ( aStatus && iPairMode == EBTOutgoingHeadsetAutoPairing )
   261         {
   270         {
   262         iPairMode = EBTOutgoingHeadsetManualPairing;
   271         iPairMode = EBTOutgoingHeadsetManualPairing;
   263         // auto pairing with headset failed, try to pair again with manual pin:
   272         // auto pairing with headset failed, try to pair again with manual pin:
   264         // ( void ) SetOutgoPairProperty( iOutgoProperty, iAddr, iPairMode );
   273         BOstrace0(TRACE_DEBUG,DUMMY_DEVLIST," auto pairing failed, switch to manual pairing");     
   265         // TRACE_INFO( _L( " auto pairing failed, switch to manual pairing") );     
       
   266         DoPairingL();
   274         DoPairingL();
   267         }
   275         }
   268     else if ( aStatus && aActive->RequestId() == EGeneralBonding && 
   276     else if ( aStatus && aActive->RequestId() == EGeneralBonding && 
   269               iPairMode == EBTOutgoingHeadsetManualPairing )
   277               iPairMode == EBTOutgoingHeadsetManualPairing )
   270         {
   278         {
   286             {
   294             {
   287             SetPairResult( aStatus );
   295             SetPairResult( aStatus );
   288             }
   296             }
   289         if ( aStatus )
   297         if ( aStatus )
   290             {
   298             {
   291             // todo: show error note?
       
   292             iParent.OutgoingPairCompleted( aStatus );
   299             iParent.OutgoingPairCompleted( aStatus );
   293             }
   300             }
   294         }
   301         }
   295     }
   302     }
   296 
   303 
   299 // cancels an outstanding request according to the given id.
   306 // cancels an outstanding request according to the given id.
   300 // ---------------------------------------------------------------------------
   307 // ---------------------------------------------------------------------------
   301 //
   308 //
   302 void CBTNotifOutgoingPairingHandler::CancelRequest( TInt aRequestId )
   309 void CBTNotifOutgoingPairingHandler::CancelRequest( TInt aRequestId )
   303     {
   310     {
       
   311     BOstraceFunctionEntry0( DUMMY_DEVLIST );
   304     switch ( aRequestId )
   312     switch ( aRequestId )
   305         {
   313         {
   306         case EDedicatedBonding:
   314         case EDedicatedBonding:
   307             {
   315             {
   308             iBondingSession.Close();
   316             iBondingSession.Close();
   326 // ---------------------------------------------------------------------------
   334 // ---------------------------------------------------------------------------
   327 //
   335 //
   328 void CBTNotifOutgoingPairingHandler::HandleError( 
   336 void CBTNotifOutgoingPairingHandler::HandleError( 
   329         CBtSimpleActive* aActive, TInt aError )
   337         CBtSimpleActive* aActive, TInt aError )
   330     {
   338     {
   331     // TRACE_FUNC_ARG( ( _L( "error: %d" ), aError ) )
   339     BOstrace1(TRACE_DEBUG,DUMMY_DEVLIST,"error: %d", aError );
   332     // Our RunL can actually not leave, so we should never reach here.
   340     // Our RunL can actually not leave, so we should never reach here.
   333     (void) aActive;
   341     (void) aActive;
   334     iParent.OutgoingPairCompleted( aError );
   342     iParent.OutgoingPairCompleted( aError );
   335     iParent.RenewPairingHandler( NULL );
   343     iParent.RenewPairingHandler( NULL );
   336     }
   344     }
   339 // decide the next state and issue pair request
   347 // decide the next state and issue pair request
   340 // ---------------------------------------------------------------------------
   348 // ---------------------------------------------------------------------------
   341 //
   349 //
   342 void CBTNotifOutgoingPairingHandler::DoPairingL()
   350 void CBTNotifOutgoingPairingHandler::DoPairingL()
   343     {
   351     {
   344     // TRACE_FUNC_ENTRY
   352     BOstraceFunctionEntry0( DUMMY_DEVLIST );
   345     TPairingStageId currentMode = ( TPairingStageId ) iActive->RequestId();
   353     TPairingStageId currentMode = ( TPairingStageId ) iActive->RequestId();
   346     ASSERT( !iActive->IsActive() );
   354     ASSERT( !iActive->IsActive() );
   347     TPairingStageId nextMode( EGeneralBonding );
   355     TPairingStageId nextMode( EGeneralBonding );
   348     
   356     
   349     // if running BTv2.0 stack, dedicated bonding method 
   357     // if running BTv2.0 stack, dedicated bonding method 
   355     else if(currentMode == EGeneralBondingRetryTimer)
   363     else if(currentMode == EGeneralBondingRetryTimer)
   356         {
   364         {
   357         nextMode = EGeneralBondingRetry;
   365         nextMode = EGeneralBondingRetry;
   358         }
   366         }
   359     
   367     
   360     // TRACE_INFO( ( _L( "[BTENG] CBTEngOtgPair::DoPairingL: bonding mode: pre %d, next %d"), currentMode, nextMode ) );
   368     BOstraceExt2(TRACE_DEBUG,DUMMY_DEVLIST,"[BTENG] CBTEngOtgPair::DoPairingL: bonding mode: pre %d, next %d", currentMode, nextMode);
   361     
   369     
   362     iActive->SetRequestId( nextMode );
   370     iActive->SetRequestId( nextMode );
   363     if ( nextMode == EDedicatedBonding )
   371     if ( nextMode == EDedicatedBonding )
   364         {
   372         {
   365         iBondingSession.Start( *iParent.PairingServer(), iAddr, iActive->RequestStatus() );          
   373         iBondingSession.Start( *iParent.PairingServer(), iAddr, iActive->RequestStatus() );          
   374         iSocket.Close();
   382         iSocket.Close();
   375         User::LeaveIfError( iSocket.Open( iParent.SocketServ(), KL2CAPDesC ) );
   383         User::LeaveIfError( iSocket.Open( iParent.SocketServ(), KL2CAPDesC ) );
   376         iSocket.Connect( iSockAddr, iActive->RequestStatus() );
   384         iSocket.Connect( iSockAddr, iActive->RequestStatus() );
   377         }
   385         }
   378     iActive->GoActive();
   386     iActive->GoActive();
   379     // TRACE_FUNC_EXIT
   387     BOstraceFunctionExit0( DUMMY_DEVLIST );
   380     }
   388     }
   381 
   389