bluetoothengine/btnotif/btnotifsrv/src/btnotifsecuritymanager.cpp
changeset 70 f5508c13dfe0
parent 57 5ebadcda06cb
equal deleted inserted replaced
67:16e4b9007960 70:f5508c13dfe0
   335 // ---------------------------------------------------------------------------
   335 // ---------------------------------------------------------------------------
   336 //
   336 //
   337 void CBTNotifSecurityManager::SessionClosed( CSession2* aSession )
   337 void CBTNotifSecurityManager::SessionClosed( CSession2* aSession )
   338     {
   338     {
   339     BOstraceFunctionEntry0( DUMMY_DEVLIST );
   339     BOstraceFunctionEntry0( DUMMY_DEVLIST );
   340     BOstrace1(TRACE_DEBUG,DUMMY_DEVLIST," session %x", aSession);
   340     BOstrace1(TRACE_DEBUG,DUMMY_DEVLIST,_L(" session %x"), aSession);
   341     if ( !iMessage.IsNull() && iMessage.Session() == aSession )
   341     if ( !iMessage.IsNull() && iMessage.Session() == aSession )
   342         {
   342         {
   343         iMessage.Complete( KErrCancel );
   343         iMessage.Complete( KErrCancel );
   344         }
   344         }
   345     BOstraceFunctionExit0( DUMMY_DEVLIST);
   345     BOstraceFunctionExit0( DUMMY_DEVLIST);
   362         dev = iPairedDevices[index];
   362         dev = iPairedDevices[index];
   363         TRequestStatus status( KRequestPending );
   363         TRequestStatus status( KRequestPending );
   364         // Unpair the device in registry (synchronously)
   364         // Unpair the device in registry (synchronously)
   365         iRegistry.UnpairDevice( dev.Address(), status );
   365         iRegistry.UnpairDevice( dev.Address(), status );
   366         User::WaitForRequest( status );
   366         User::WaitForRequest( status );
   367         BOstrace1(TRACE_DEBUG,DUMMY_DEVLIST,"Delete link key, res %d", status.Int());
   367         BOstrace1(TRACE_DEBUG,DUMMY_DEVLIST,_L("Delete link key, res %d"), status.Int());
   368         if ( status == KErrNone )
   368         if ( status == KErrNone )
   369             {
   369             {
   370             TBTDeviceSecurity security = dev.GlobalSecurity();
   370             TBTDeviceSecurity security = dev.GlobalSecurity();
   371             // Clear trust setting so that correct icon will be shown in ui applications.
   371             // Clear trust setting so that correct icon will be shown in ui applications.
   372             security.SetNoAuthenticate(EFalse );
   372             security.SetNoAuthenticate(EFalse );
   377                  ( dev.UiCookie() & EBTUiCookieJustWorksPaired ) )
   377                  ( dev.UiCookie() & EBTUiCookieJustWorksPaired ) )
   378                 {
   378                 {
   379                 // Remove the UI cookie bit for Just Works pairing.
   379                 // Remove the UI cookie bit for Just Works pairing.
   380                 TInt32 cookie = dev.UiCookie() & ~EBTUiCookieJustWorksPaired;
   380                 TInt32 cookie = dev.UiCookie() & ~EBTUiCookieJustWorksPaired;
   381                 dev.SetUiCookie( cookie );
   381                 dev.SetUiCookie( cookie );
   382                 BOstrace1(TRACE_DEBUG,DUMMY_DEVLIST,"UI cookie %x cleared", EBTUiCookieJustWorksPaired );
   382                 BOstrace1(TRACE_DEBUG,DUMMY_DEVLIST,_L("UI cookie %x cleared"), EBTUiCookieJustWorksPaired );
   383                 }
   383                 }
   384             // modify the device in registry synchronously
   384             // modify the device in registry synchronously
   385             // status.Int() could be -1 if the device is not in registry 
   385             // status.Int() could be -1 if the device is not in registry 
   386             // which is totally fine for us.
   386             // which is totally fine for us.
   387             (void) UpdateRegDevice( dev );
   387             (void) UpdateRegDevice( dev );
   427         // to keep minimal operations with registry.
   427         // to keep minimal operations with registry.
   428         TBTNamelessDevice dev = aDev;		
   428         TBTNamelessDevice dev = aDev;		
   429         cookie |= EBTUiCookieJustWorksPaired;
   429         cookie |= EBTUiCookieJustWorksPaired;
   430         dev.SetUiCookie( cookie );
   430         dev.SetUiCookie( cookie );
   431         err = UpdateRegDevice( dev );
   431         err = UpdateRegDevice( dev );
   432         BOstrace1(TRACE_DEBUG,DUMMY_DEVLIST,"Outgoing Pairing write Ui cookie ret %d", err );
   432         BOstrace1(TRACE_DEBUG,DUMMY_DEVLIST,_L("Outgoing Pairing write Ui cookie ret %d"), err );
   433         }
   433         }
   434     BOstraceFunctionExit0( DUMMY_DEVLIST);
   434     BOstraceFunctionExit0( DUMMY_DEVLIST);
   435     return err;
   435     return err;
   436     }
   436     }
   437 
   437 
   444     BOstraceFunctionEntry0( DUMMY_DEVLIST );
   444     BOstraceFunctionEntry0( DUMMY_DEVLIST );
   445     TRequestStatus status( KRequestPending );
   445     TRequestStatus status( KRequestPending );
   446     // update the device in registry synchronously
   446     // update the device in registry synchronously
   447     iRegistry.ModifyDevice( aDev, status );
   447     iRegistry.ModifyDevice( aDev, status );
   448     User::WaitForRequest( status );
   448     User::WaitForRequest( status );
   449     BOstrace1(TRACE_DEBUG,DUMMY_DEVLIST,"UpdateRegDevice, ret %d", status.Int());
   449     BOstrace1(TRACE_DEBUG,DUMMY_DEVLIST,_L("UpdateRegDevice, ret %d"), status.Int());
   450     BOstraceFunctionExit0( DUMMY_DEVLIST);
   450     BOstraceFunctionExit0( DUMMY_DEVLIST);
   451     return status.Int();
   451     return status.Int();
   452     }
   452     }
   453 
   453 
   454 // ---------------------------------------------------------------------------
   454 // ---------------------------------------------------------------------------
   496 // ---------------------------------------------------------------------------
   496 // ---------------------------------------------------------------------------
   497 //
   497 //
   498 void CBTNotifSecurityManager::RequestCompletedL( CBtSimpleActive* aActive, TInt aStatus )
   498 void CBTNotifSecurityManager::RequestCompletedL( CBtSimpleActive* aActive, TInt aStatus )
   499     {
   499     {
   500     BOstraceFunctionEntry0( DUMMY_DEVLIST );
   500     BOstraceFunctionEntry0( DUMMY_DEVLIST );
   501     BOstraceExt2(TRACE_DEBUG,DUMMY_DEVLIST,"aId: %d, aStatus: %d", aActive->RequestId(), aStatus);
   501     BOstraceExt2(TRACE_DEBUG,DUMMY_DEVLIST,_L("aId: %d, aStatus: %d"), aActive->RequestId(), aStatus);
   502     // Check which request is completed.
   502     // Check which request is completed.
   503     switch( aActive->RequestId() )
   503     switch( aActive->RequestId() )
   504         {
   504         {
   505         case ESimplePairingResult:
   505         case ESimplePairingResult:
   506             {
   506             {
   577 // ---------------------------------------------------------------------------
   577 // ---------------------------------------------------------------------------
   578 //
   578 //
   579 void CBTNotifSecurityManager::HandleError( CBtSimpleActive* aActive, TInt aError )
   579 void CBTNotifSecurityManager::HandleError( CBtSimpleActive* aActive, TInt aError )
   580     {
   580     {
   581     BOstraceFunctionEntry0( DUMMY_DEVLIST );
   581     BOstraceFunctionEntry0( DUMMY_DEVLIST );
   582     BOstraceExt2(TRACE_DEBUG,DUMMY_DEVLIST,"request id: %d, error: %d", aActive->RequestId(), aError);
   582     BOstraceExt2(TRACE_DEBUG,DUMMY_DEVLIST,_L("request id: %d, error: %d"), aActive->RequestId(), aError);
   583     (void) aActive;
   583     (void) aActive;
   584     (void) aError;
   584     (void) aError;
   585     BOstraceFunctionExit0( DUMMY_DEVLIST);
   585     BOstraceFunctionExit0( DUMMY_DEVLIST);
   586     }
   586     }
   587 
   587 
   648     // thus check whether it is in our local paired list:
   648     // thus check whether it is in our local paired list:
   649     TInt i = iPairedDevices.Find( aDevice.Addr(), MatchDeviceAddress);
   649     TInt i = iPairedDevices.Find( aDevice.Addr(), MatchDeviceAddress);
   650     TBool bonded = CBtDevExtension::IsBonded( aDevice.Device().AsNamelessDevice() );
   650     TBool bonded = CBtDevExtension::IsBonded( aDevice.Device().AsNamelessDevice() );
   651     if ( i == KErrNotFound )
   651     if ( i == KErrNotFound )
   652         {
   652         {
   653         BOstrace0(TRACE_DEBUG,DUMMY_DEVLIST,"Not found");
   653         BOstrace0(TRACE_DEBUG,DUMMY_DEVLIST,_L("Not found"));
   654         if ( bonded ) 
   654         if ( bonded ) 
   655             {
   655             {
   656             BOstrace0(TRACE_DEBUG,DUMMY_DEVLIST,"Not found but bonded");
   656             BOstrace0(TRACE_DEBUG,DUMMY_DEVLIST,_L("Not found but bonded"));
   657             TRAP_IGNORE(
   657             TRAP_IGNORE(
   658                     HandleRegistryBondingL( 
   658                     HandleRegistryBondingL( 
   659                             aDevice.Device().AsNamelessDevice() ) );                
   659                             aDevice.Device().AsNamelessDevice() ) );                
   660             }
   660             }
   661         BOstraceFunctionExit0( DUMMY_DEVLIST);
   661         BOstraceFunctionExit0( DUMMY_DEVLIST);
   670     if ( ( pairingProperty & aSimilarity) == pairingProperty )
   670     if ( ( pairingProperty & aSimilarity) == pairingProperty )
   671         {
   671         {
   672         // no pairing or linkkey change. Nothing to do for pairing handling.
   672         // no pairing or linkkey change. Nothing to do for pairing handling.
   673         // but we'd better update local copy just in case other data
   673         // but we'd better update local copy just in case other data
   674         // of this device is needed by someone:
   674         // of this device is needed by someone:
   675         BOstrace0(TRACE_DEBUG,DUMMY_DEVLIST,"No pairing or link key change");
   675         BOstrace0(TRACE_DEBUG,DUMMY_DEVLIST,_L("No pairing or link key change"));
   676         iPairedDevices[i] = aDevice.Device().AsNamelessDevice();
   676         iPairedDevices[i] = aDevice.Device().AsNamelessDevice();
   677         BOstraceFunctionExit0( DUMMY_DEVLIST);
   677         BOstraceFunctionExit0( DUMMY_DEVLIST);
   678         return;
   678         return;
   679         }
   679         }
   680     if ( !bonded )
   680     if ( !bonded )
   715 // ---------------------------------------------------------------------------
   715 // ---------------------------------------------------------------------------
   716 //
   716 //
   717 TInt CBTNotifSecurityManager::SetPairObserver(const TBTDevAddr& aAddr, TBool aActivate)
   717 TInt CBTNotifSecurityManager::SetPairObserver(const TBTDevAddr& aAddr, TBool aActivate)
   718     {
   718     {
   719     BOstraceFunctionEntry0( DUMMY_DEVLIST );
   719     BOstraceFunctionEntry0( DUMMY_DEVLIST );
   720     BOstrace1(TRACE_DEBUG,DUMMY_DEVLIST,"%d", aActivate);
   720     BOstrace1(TRACE_DEBUG,DUMMY_DEVLIST,_L("%d"), aActivate);
   721     BtTraceBtAddr0(TRACE_DEBUG,DUMMY_DEVLIST, aAddr );
   721     BtTraceBtAddr0(TRACE_DEBUG,DUMMY_DEVLIST, aAddr );
   722     TInt err( KErrNone );
   722     TInt err( KErrNone );
   723     if ( !aActivate )
   723     if ( !aActivate )
   724         {
   724         {
   725         if ( iPairingHandler )
   725         if ( iPairingHandler )
   821 // ---------------------------------------------------------------------------
   821 // ---------------------------------------------------------------------------
   822 //
   822 //
   823 void CBTNotifSecurityManager::HandlePairingResultL( const TBTDevAddr& aAddr, TInt aResult )
   823 void CBTNotifSecurityManager::HandlePairingResultL( const TBTDevAddr& aAddr, TInt aResult )
   824     {
   824     {
   825     BOstraceFunctionEntry0( DUMMY_DEVLIST );
   825     BOstraceFunctionEntry0( DUMMY_DEVLIST );
   826     BOstrace1(TRACE_DEBUG,DUMMY_DEVLIST,"result %d", aResult);
   826     BOstrace1(TRACE_DEBUG,DUMMY_DEVLIST,_L("result %d"), aResult);
   827     BtTraceBtAddr0(TRACE_DEBUG,DUMMY_DEVLIST, aAddr );
   827     BtTraceBtAddr0(TRACE_DEBUG,DUMMY_DEVLIST, aAddr );
   828  
   828  
   829     if ( !iPairingHandler && ( aResult == KErrNone || aResult == KHCIErrorBase ) )
   829     if ( !iPairingHandler && ( aResult == KErrNone || aResult == KHCIErrorBase ) )
   830         {
   830         {
   831         // we only create new handler if incoming pairing succeeds.
   831         // we only create new handler if incoming pairing succeeds.