localconnectivityservice/dun/plugins/src/bt/DunBtPlugin.cpp
branchRCL_3
changeset 19 0aa8cc770c8a
equal deleted inserted replaced
18:453dfc402455 19:0aa8cc770c8a
       
     1 /*
       
     2 * Copyright (c) 2006-2008 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:  DUN Bluetooth plugin
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <bt_sock.h>
       
    20 #include <c32comm.h>
       
    21 #include "DunPlugin.h"
       
    22 #include "DunBtListen.h"
       
    23 #include "DunBtPlugin.h"
       
    24 #include "DunDebug.h"
       
    25 #include "DunTransporter.h"
       
    26 
       
    27 _LIT( KBtChannelName, "DUNBT::"  );
       
    28 
       
    29 const TInt KCharactersInTInt = 10;  // For "2147483648"
       
    30 
       
    31 // ======== MEMBER FUNCTIONS ========
       
    32 
       
    33 // ---------------------------------------------------------------------------
       
    34 // CDunBtPlugin::CDunBtPlugin()
       
    35 // ---------------------------------------------------------------------------
       
    36 //
       
    37 CDunBtPlugin::CDunBtPlugin() :
       
    38     iServer( NULL ),
       
    39     iBTListen( NULL ),
       
    40     iTransporter( NULL )
       
    41     {
       
    42     }
       
    43 
       
    44 // ---------------------------------------------------------------------------
       
    45 // Destructor.
       
    46 // ---------------------------------------------------------------------------
       
    47 //
       
    48 CDunBtPlugin::~CDunBtPlugin()
       
    49     {
       
    50     FTRACE(FPrint( _L( "CDunBtPlugin::~CDunBtPlugin()" ) ));
       
    51     Uninitialize();
       
    52     FTRACE(FPrint( _L( "CDunBtPlugin::~CDunBtPlugin() complete" ) ));
       
    53     }
       
    54 
       
    55 // ---------------------------------------------------------------------------
       
    56 // State of this plugin
       
    57 // ---------------------------------------------------------------------------
       
    58 //
       
    59 TDunPluginState CDunBtPlugin::PluginState()
       
    60     {
       
    61     return iServer->GetPluginStateByUid( KDunBtPluginUid );
       
    62     }
       
    63 
       
    64 // ---------------------------------------------------------------------------
       
    65 // Constructs a listener object for this plugin
       
    66 // ---------------------------------------------------------------------------
       
    67 //
       
    68 void CDunBtPlugin::ConstructListenerL()
       
    69     {
       
    70     FTRACE(FPrint(_L("CDunBtPlugin::ConstructListenerL()")));
       
    71     if ( PluginState() != EDunStateLoaded )
       
    72         {
       
    73         FTRACE(FPrint(_L("CDunBtPlugin::ConstructListenerL() (not ready) complete")));
       
    74         User::Leave( KErrNotReady );
       
    75         }
       
    76     ReportStateChangeUp( EDunStateTryListen );
       
    77     if ( iBTListen )
       
    78         {
       
    79         FTRACE(FPrint(_L("CDunBtPlugin::ConstructListenerL() (already exists) complete")));
       
    80         User::Leave( KErrAlreadyExists );
       
    81         }
       
    82     CDunBtListen* listen = CDunBtListen::NewL( iServer,
       
    83                                                this,
       
    84                                                iTransporter,
       
    85                                                iEntity );
       
    86     CleanupStack::PushL( listen );
       
    87     listen->IssueRequestL();
       
    88     CleanupStack::Pop( listen );
       
    89     iBTListen = listen;
       
    90     ReportStateChangeUp( EDunStateListening );
       
    91     FTRACE(FPrint(_L("CDunBtPlugin::ConstructListenerL() complete")));
       
    92     }
       
    93 
       
    94 // ---------------------------------------------------------------------------
       
    95 // Sets new state
       
    96 // New state must be one more than the old state
       
    97 // ---------------------------------------------------------------------------
       
    98 //
       
    99 TInt CDunBtPlugin::ReportStateChangeUp( TDunPluginState aPluginState )
       
   100     {
       
   101     FTRACE(FPrint(_L("CDunBtPlugin::ReportStateChangeUp()")));
       
   102     TInt retTemp = iServer->NotifyPluginStateChangeUp( aPluginState,
       
   103                                                        KDunBtPluginUid );
       
   104     if ( retTemp != KErrNone )
       
   105         {
       
   106         FTRACE(FPrint(_L("CDunBtPlugin::ReportStateChangeUp() (ERROR) complete")));
       
   107         return retTemp;
       
   108         }
       
   109     FTRACE(FPrint(_L("CDunBtPlugin::ReportStateChangeUp() complete")));
       
   110     return KErrNone;
       
   111     }
       
   112 
       
   113 // ---------------------------------------------------------------------------
       
   114 // Sets new state
       
   115 // New state must be one less than the old state
       
   116 // ---------------------------------------------------------------------------
       
   117 //
       
   118 TInt CDunBtPlugin::ReportStateChangeDown( TDunPluginState aPluginState )
       
   119     {
       
   120     FTRACE(FPrint(_L("CDunBtPlugin::ReportStateChangeDown()")));
       
   121     TInt retTemp = iServer->NotifyPluginStateChangeDown( aPluginState,
       
   122                                                          KDunBtPluginUid );
       
   123     if ( retTemp != KErrNone )
       
   124         {
       
   125         FTRACE(FPrint(_L("CDunBtPlugin::ReportStateChangeDown() (ERROR) complete")));
       
   126         return retTemp;
       
   127         }
       
   128     FTRACE(FPrint(_L("CDunBtPlugin::ReportStateChangeDown() complete")));
       
   129     return KErrNone;
       
   130     }
       
   131 
       
   132 // ---------------------------------------------------------------------------
       
   133 // Allocates a free channel
       
   134 // ---------------------------------------------------------------------------
       
   135 //
       
   136 void CDunBtPlugin::AllocateChannelL( TBool& aNoFreeChans,
       
   137                                      TBtCleanupInfo& aCleanupInfo )
       
   138     {
       
   139     FTRACE(FPrint(_L("CDunBtPlugin::AllocateChannelL()")));
       
   140     // iDataSocket has new data socket information so copy it to iBTPorts
       
   141     TBtPortEntity* foundEntity = NULL;
       
   142     TInt foundIndex = GetFirstFreePort( foundEntity );
       
   143     if ( !foundEntity )  // free not found so add new
       
   144         {
       
   145         TBtPortEntity newEntity;
       
   146         iBTPorts.AppendL( newEntity );
       
   147         aCleanupInfo.iNewEntity = ETrue;
       
   148         aCleanupInfo.iEntityIndex = iBTPorts.Count() - 1;
       
   149         foundEntity = &iBTPorts[ aCleanupInfo.iEntityIndex ];
       
   150         }
       
   151     else  // free found so change array
       
   152         {
       
   153         aCleanupInfo.iNewEntity = EFalse;
       
   154         aCleanupInfo.iEntityIndex = foundIndex;
       
   155         foundEntity = &iBTPorts[ foundIndex ];
       
   156         }
       
   157     foundEntity->iChannelNum = iEntity.iChannelNum;
       
   158     foundEntity->iBTPort = iEntity.iBTPort;
       
   159     RSocket* socket = &foundEntity->iBTPort;
       
   160     HBufC8* channelName = HBufC8::NewMaxLC( KBtChannelName().Length() +
       
   161                           KCharactersInTInt );
       
   162     TPtr8 channelNamePtr = channelName->Des();
       
   163     channelNamePtr.Copy( KBtChannelName );
       
   164     channelNamePtr.AppendNum( iEntity.iChannelNum );
       
   165     iTransporter->AllocateChannelL( socket,
       
   166                                     KDunBtPluginUid,
       
   167                                     channelNamePtr,
       
   168                                     EFalse,
       
   169                                     aNoFreeChans );
       
   170     iTransporter->AddConnMonCallbackL( socket,
       
   171                                        this,
       
   172                                        EDunReaderUpstream,
       
   173                                        EFalse );
       
   174     iTransporter->AddConnMonCallbackL( socket,
       
   175                                        this,
       
   176                                        EDunWriterUpstream,
       
   177                                        EFalse );
       
   178     iTransporter->AddConnMonCallbackL( socket,
       
   179                                        this,
       
   180                                        EDunReaderDownstream,
       
   181                                        ETrue );
       
   182     iTransporter->AddConnMonCallbackL( socket,
       
   183                                        this,
       
   184                                        EDunWriterDownstream,
       
   185                                        EFalse );
       
   186     iTransporter->IssueTransferRequestsL( socket );
       
   187     CleanupStack::PopAndDestroy( channelName );
       
   188     FTRACE(FPrint(_L("CDunBtPlugin::AllocateChannelL() complete")));
       
   189     }
       
   190 
       
   191 // ---------------------------------------------------------------------------
       
   192 // Frees an existing channel
       
   193 // ---------------------------------------------------------------------------
       
   194 //
       
   195 TInt CDunBtPlugin::FreeChannels()
       
   196     {
       
   197     FTRACE(FPrint(_L("CDunBtPlugin::FreeChannels()")));
       
   198     if ( PluginState() != EDunStateTryUninitialize )
       
   199         {
       
   200         FTRACE(FPrint(_L("CDunBtPlugin::FreeChannels() (not ready) complete")));
       
   201         return KErrNotReady;
       
   202         }
       
   203     TInt i;
       
   204     TInt count = iBTPorts.Count();
       
   205     for ( i=0; i<count; i++ )
       
   206         {
       
   207         if ( iBTPorts[i].iBTPort.SubSessionHandle() )
       
   208             {
       
   209             iTransporter->FreeChannel( &iBTPorts[i].iBTPort );
       
   210             iBTPorts[i].iBTPort.Close();
       
   211             // All channels freed and this is for Uninitialize() so don't touch
       
   212             // advertisement monitor here!
       
   213             }
       
   214         iBTPorts[i].iChannelNum = KErrNotFound;
       
   215         }
       
   216     iBTPorts.Close();
       
   217     FTRACE(FPrint(_L("CDunBtPlugin::FreeChannels() complete")));
       
   218     return KErrNone;
       
   219     }
       
   220 
       
   221 // ---------------------------------------------------------------------------
       
   222 // Uninitializes this plugin
       
   223 // ---------------------------------------------------------------------------
       
   224 //
       
   225 TInt CDunBtPlugin::Uninitialize()
       
   226     {
       
   227     FTRACE(FPrint( _L( "CDunBtPlugin::Uninitialize()" ) ));
       
   228     ReportStateChangeDown( EDunStateTryUninitialize );
       
   229     // Free channels (ignore errors)
       
   230     FreeChannels();
       
   231     // Delete listening object (also advertisement monitor)
       
   232     delete iBTListen;
       
   233     iBTListen = NULL;
       
   234     // Set state back to loaded
       
   235     ReportStateChangeUp( EDunStateUninitialized );
       
   236     ReportStateChangeUp( EDunStateTryLoad );
       
   237     ReportStateChangeUp( EDunStateLoaded );
       
   238     FTRACE(FPrint( _L( "CDunBtPlugin::Uninitialize() complete" ) ));
       
   239     return KErrNone;
       
   240     }
       
   241 
       
   242 // ---------------------------------------------------------------------------
       
   243 // Gets port's index and entity by connection ID
       
   244 // ---------------------------------------------------------------------------
       
   245 //
       
   246 TInt CDunBtPlugin::GetPortByConnId( TConnId aConnId, TBtPortEntity*& aEntity )
       
   247     {
       
   248     FTRACE(FPrint( _L( "CDunBtPlugin::GetPortByConnId()")) );
       
   249     TInt i;
       
   250     TInt count = iBTPorts.Count();
       
   251     for ( i=0; i<count; i++ )
       
   252         {
       
   253         if ( &iBTPorts[i].iBTPort == aConnId )
       
   254             {
       
   255             aEntity = &iBTPorts[i];
       
   256             FTRACE(FPrint( _L( "CDunBtPlugin::GetPortByConnId() complete")) );
       
   257             return i;
       
   258             }
       
   259         }
       
   260     aEntity = NULL;
       
   261     FTRACE(FPrint( _L( "CDunBtPlugin::GetPortByConnId() (not found) complete")) );
       
   262     return KErrNotFound;
       
   263     }
       
   264 
       
   265 // ---------------------------------------------------------------------------
       
   266 // Gets first free port's index and entity
       
   267 // ---------------------------------------------------------------------------
       
   268 //
       
   269 TInt CDunBtPlugin::GetFirstFreePort( TBtPortEntity*& aEntity )
       
   270     {
       
   271     FTRACE(FPrint( _L( "CDunBtPlugin::GetFirstFreePort()")) );
       
   272     TInt i;
       
   273     TInt count = iBTPorts.Count();
       
   274     for ( i=0; i<count; i++ )
       
   275         {
       
   276         if ( !iBTPorts[i].iBTPort.SubSessionHandle() )
       
   277             {
       
   278             aEntity = &iBTPorts[i];
       
   279             FTRACE(FPrint( _L( "CDunBtPlugin::GetFirstFreePort() complete")) );
       
   280             return i;
       
   281             }
       
   282         }
       
   283     aEntity = NULL;
       
   284     FTRACE(FPrint( _L( "CDunBtPlugin::GetFirstFreePort() (not found) complete")) );
       
   285     return KErrNotFound;
       
   286     }
       
   287 
       
   288 // ---------------------------------------------------------------------------
       
   289 // Sets modem's MSC (Modem Status Command)
       
   290 // ---------------------------------------------------------------------------
       
   291 //
       
   292 TInt CDunBtPlugin::SetRFCOMMStatusCommand( TBtPortEntity& aEntity,
       
   293                                            TUint8 aSignal,
       
   294                                            TBool aSignalOn )
       
   295     {
       
   296     FTRACE(FPrint( _L( "CDunBtPlugin::SetRFCOMMStatusCommand()" ) ));
       
   297     // Get existing Modem Status Command (MSC)
       
   298     // Ref.: 3GPP TS 07.10 V7.2.0 (2002-03)
       
   299     // Table 6,7, (5.4.6.3.7)
       
   300     TUint8 modemStatus = 0;
       
   301     TPckgBuf<TUint8> pkg( modemStatus );
       
   302     TInt retTemp = aEntity.iBTPort.GetOpt( KRFCOMMLocalModemStatus,
       
   303                                            KSolBtRFCOMM,
       
   304                                            pkg );
       
   305     if ( retTemp != KErrNone )
       
   306         {
       
   307         FTRACE(FPrint( _L( "CDunBtPlugin::SetRFCOMMStatusCommand() (GetOpt failed!) complete" ) ));
       
   308         return retTemp;
       
   309         }
       
   310     modemStatus = pkg();
       
   311     FTRACE(FPrint( _L( "CDunBtPlugin::SetRFCOMMStatusCommand() signals are: 0x%02X" ), modemStatus));
       
   312     TBool changed = EFalse;
       
   313     TUint8 signal = modemStatus & aSignal;
       
   314     if ( aSignalOn )
       
   315         {
       
   316         if ( !signal )
       
   317             {
       
   318             modemStatus |= aSignal;
       
   319             changed = ETrue;
       
   320             }
       
   321         }
       
   322     else
       
   323         {
       
   324         if ( signal )
       
   325             {
       
   326             modemStatus &= ( ~aSignal );
       
   327             changed = ETrue;
       
   328             }
       
   329         }
       
   330     if ( changed )
       
   331         {
       
   332         pkg = modemStatus;
       
   333         retTemp = aEntity.iBTPort.SetOpt( KRFCOMMLocalModemStatus,
       
   334                                           KSolBtRFCOMM,
       
   335                                           pkg );
       
   336         if ( retTemp != KErrNone )
       
   337             {
       
   338             FTRACE(FPrint( _L( "CDunBtPlugin::SetRFCOMMStatusCommand() (SetOpt failed!) complete" ) ));
       
   339             return retTemp;
       
   340             }
       
   341         }
       
   342     FTRACE(FPrint( _L( "CDunBtPlugin::SetRFCOMMStatusCommand() complete" ) ));
       
   343     return KErrNone;
       
   344     }
       
   345 
       
   346 // ---------------------------------------------------------------------------
       
   347 // Manages advertiser for channel free operation
       
   348 // ---------------------------------------------------------------------------
       
   349 //
       
   350 void CDunBtPlugin::ManageAdvertiserFreeOperationL()
       
   351     {
       
   352     FTRACE(FPrint(_L("CDunBtPlugin::ManageAdvertiserFreeOperationL()")));
       
   353     TInt numOfChans = iTransporter->NumberOfAllocatedChannels();
       
   354     // Remove of last CDunTransporter channel removes also the
       
   355     // advertisement monitor so set it now if necessary
       
   356     if ( numOfChans == 0 )
       
   357         {
       
   358         iTransporter->SetAdvertisementMonitorL( KDunBtPluginUid, iBTListen );
       
   359         }
       
   360     FTRACE(FPrint(_L("CDunBtPlugin::ManageAdvertiserFreeOperationL() complete")));
       
   361     }
       
   362 
       
   363 // ---------------------------------------------------------------------------
       
   364 // Cleans partial created channel data based on TATExtCleanupInfo
       
   365 // ---------------------------------------------------------------------------
       
   366 //
       
   367 void CDunBtPlugin::CleanPartialChanneldata( TBtCleanupInfo& aCleanupInfo )
       
   368     {
       
   369     FTRACE(FPrint(_L("CDunBtPlugin::CleanPartialChanneldata()")));
       
   370     RSocket* socket = &iBTPorts[aCleanupInfo.iEntityIndex].iBTPort;
       
   371     iTransporter->FreeChannel( socket );
       
   372     iBTPorts[aCleanupInfo.iEntityIndex].iChannelNum = KErrNotFound;
       
   373     socket->Close();
       
   374     if ( aCleanupInfo.iNewEntity )
       
   375         {
       
   376         iBTPorts.Remove( aCleanupInfo.iEntityIndex );
       
   377         }
       
   378     FTRACE(FPrint(_L("CDunBtPlugin::CleanPartialChanneldata() complete")));
       
   379     }
       
   380 
       
   381 // ---------------------------------------------------------------------------
       
   382 // From class MDunLocalMediaPlugin.
       
   383 // CDunBtPlugin::ConstructL
       
   384 // ---------------------------------------------------------------------------
       
   385 //
       
   386 void CDunBtPlugin::ConstructL( MDunServerCallback* aServer,
       
   387                                CDunTransporter* aTransporter )
       
   388     {
       
   389     FTRACE(FPrint( _L( "CDunBtPlugin::ConstructL()" ) ));
       
   390     if ( !aServer || !aTransporter )
       
   391         {
       
   392         FTRACE(FPrint(_L("CDunBtPlugin::ConstructL() not initialized!")));
       
   393         User::Leave( KErrBadHandle );
       
   394         }
       
   395     iServer = aServer;
       
   396     iTransporter = aTransporter;
       
   397     FTRACE(FPrint( _L( "CDunBtPlugin::ConstructL() complete" ) ));
       
   398     }
       
   399 
       
   400 // ---------------------------------------------------------------------------
       
   401 // From class MDunLocalMediaPlugin.
       
   402 // Gets called when server changes a plugin's state
       
   403 // ---------------------------------------------------------------------------
       
   404 //
       
   405 TInt CDunBtPlugin::NotifyServerStateChange( TDunPluginState aPluginState )
       
   406     {
       
   407     FTRACE(FPrint(_L("CDunBtPlugin::NotifyServerStateChange()")));
       
   408     TInt retTemp;
       
   409     switch ( aPluginState )
       
   410         {
       
   411         case EDunStateTryListen:
       
   412             if ( PluginState() != EDunStateLoaded )
       
   413                 {
       
   414                 FTRACE(FPrint(_L("CDunBtPlugin::NotifyServerStateChange() (not ready) complete")));
       
   415                 return KErrNotReady;
       
   416                 }
       
   417             // Change to listening mode
       
   418             TRAPD( retTrap, ConstructListenerL() );
       
   419             if ( retTrap != KErrNone )
       
   420                 {
       
   421                 FTRACE(FPrint(_L("CDunBtPlugin::NotifyServerStateChange() (ERROR) complete (%d)"), retTrap));
       
   422                 return retTrap;
       
   423                 }
       
   424             break;
       
   425         case EDunStateTryUninitialize:
       
   426             if ( PluginState() == EDunStateUninitialized )
       
   427                 {
       
   428                 FTRACE(FPrint(_L("CDunBtPlugin::NotifyServerStateChange() (not ready) complete")));
       
   429                 return KErrNotReady;
       
   430                 }
       
   431             // Uninitialize
       
   432             retTemp = Uninitialize();
       
   433             if ( retTemp != KErrNone )
       
   434                 {
       
   435                 FTRACE(FPrint(_L("CDunBtPlugin::NotifyServerStateChange() (not ready) complete (%d)"), retTemp));
       
   436                 return KErrNotReady;
       
   437                 }
       
   438             break;
       
   439         default:
       
   440             FTRACE(FPrint(_L("CDunBtPlugin::NotifyServerStateChange() (unknown state) complete")));
       
   441             return KErrNotSupported;
       
   442         }
       
   443     FTRACE(FPrint(_L("CDunBtPlugin::NotifyServerStateChange() complete")));
       
   444     return KErrNone;
       
   445     }
       
   446 
       
   447 // ---------------------------------------------------------------------------
       
   448 // From class MDunLocalMediaPlugin.
       
   449 // Gets called when server needs to know the active connection
       
   450 // ---------------------------------------------------------------------------
       
   451 //
       
   452 TConnId CDunBtPlugin::ActiveConnection()
       
   453     {
       
   454     FTRACE(FPrint(_L("CDunBtPlugin::ActiveConnection()")));
       
   455     if ( iBTPorts.Count() >= 1 )
       
   456         {
       
   457         FTRACE(FPrint(_L("CDunBtPlugin::ActiveConnection() complete")));
       
   458         return &iBTPorts[0];
       
   459         }
       
   460     FTRACE(FPrint(_L("CDunBtPlugin::ActiveConnection() (not found) complete")));
       
   461     return NULL;
       
   462     }
       
   463 
       
   464 // ---------------------------------------------------------------------------
       
   465 // From class MDunListenCallback.
       
   466 // Gets called when new channel must be created
       
   467 // ---------------------------------------------------------------------------
       
   468 //
       
   469 TInt CDunBtPlugin::NotifyChannelAllocate( TBool& aNoFreeChans )
       
   470     {
       
   471     // Now state can be either EDunStateListening (no channels) or
       
   472     // EDunStateChanneled (one or more channels). Support both states
       
   473     TDunPluginState startState = PluginState();
       
   474     if ( startState!=EDunStateListening && startState!=EDunStateChanneled )
       
   475         {
       
   476         FTRACE(FPrint(_L("CDunBtPlugin::NotifyChannelAllocate() (not ready) complete")));
       
   477         return KErrNotReady;
       
   478         }
       
   479     if ( startState == EDunStateListening )
       
   480         {
       
   481         ReportStateChangeUp( EDunStateTryChannel );
       
   482         }
       
   483     TBtCleanupInfo cleanupInfo;
       
   484     TRAPD( retTrap, AllocateChannelL(aNoFreeChans,cleanupInfo) );
       
   485     if ( retTrap != KErrNone )
       
   486         {
       
   487         CleanPartialChanneldata( cleanupInfo );
       
   488         FTRACE(FPrint(_L("CDunBtPlugin::NotifyChannelAllocate() (trapped!) complete")));
       
   489         return retTrap;
       
   490         }
       
   491     if ( startState == EDunStateListening )
       
   492         {
       
   493         ReportStateChangeUp( EDunStateChanneled );
       
   494         }
       
   495     FTRACE(FPrint(_L("CDunBtPlugin::NotifyChannelAllocate() complete")));
       
   496     return KErrNone;
       
   497     }
       
   498 
       
   499 // ---------------------------------------------------------------------------
       
   500 // From class MDunListenCallback.
       
   501 // Gets called when an existing channel must be freed
       
   502 // ---------------------------------------------------------------------------
       
   503 //
       
   504 TInt CDunBtPlugin::NotifyChannelFree()
       
   505     {
       
   506     // No implementation needed here
       
   507     return KErrNotSupported;
       
   508     }
       
   509 
       
   510 // ---------------------------------------------------------------------------
       
   511 // From class MDunConnMon.
       
   512 // Gets called when line status changes or when any type of error is detected
       
   513 // ---------------------------------------------------------------------------
       
   514 //
       
   515 void CDunBtPlugin::NotifyProgressChangeL( TConnId aConnId,
       
   516                                           TDunConnectionReason aConnReason )
       
   517     {
       
   518     FTRACE(FPrint( _L( "CDunBtPlugin::NotifyProgressChangeL()" ) ));
       
   519     // Find matching failed ID
       
   520     TBtPortEntity* foundEntity = NULL;
       
   521     TInt foundIndex = GetPortByConnId( aConnId, foundEntity );
       
   522     if ( !foundEntity )
       
   523         {
       
   524         FTRACE(FPrint( _L( "CDunBtPlugin::NotifyProgressChangeL() (not found) complete")) );
       
   525         User::Leave( KErrNotFound );
       
   526         }
       
   527     if ( aConnReason.iReasonType == EDunReasonTypeSignal )
       
   528         {
       
   529         if ( aConnReason.iContext != EDunMediaContextNetwork )
       
   530             {
       
   531             // Should never come here as other signals are for RComm
       
   532             FTRACE(FPrint( _L( "CDunBtPlugin::NotifyProgressChangeL() (ERROR) complete")) );
       
   533             User::Leave( KErrGeneral );
       
   534             }
       
   535         // Signal change detected on network side -> process change
       
   536         if ( aConnReason.iSignalType == KSignalDCD )
       
   537             {
       
   538             SetRFCOMMStatusCommand( *foundEntity,
       
   539                                     KModemSignalDV,
       
   540                                     aConnReason.iSignalHigh );
       
   541             FTRACE(FPrint( _L( "CDunBtPlugin::NotifyProgressChangeL() DV changed")) );
       
   542             }
       
   543         else if ( aConnReason.iSignalType == KSignalRNG )
       
   544             {
       
   545             SetRFCOMMStatusCommand( *foundEntity,
       
   546                                     KModemSignalIC,
       
   547                                     aConnReason.iSignalHigh );
       
   548             FTRACE(FPrint( _L( "CDunBtPlugin::NotifyProgressChangeL() IC changed")) );
       
   549             }
       
   550         // Omit other signals
       
   551         }
       
   552     else
       
   553         {
       
   554         // All other cases are down indications from local media side
       
   555         if ( foundEntity->iBTPort.SubSessionHandle() )
       
   556             {
       
   557             iTransporter->FreeChannel( &foundEntity->iBTPort );
       
   558             // CDunTransporter will notify the listener about advertisement
       
   559             // status change after FreeChannel() so no need to do
       
   560             // IssueRequestL() for CDunBtListen here after this.
       
   561             foundEntity->iBTPort.Close();
       
   562             }
       
   563         ManageAdvertiserFreeOperationL();
       
   564         // Now resources are freed so command server to reopen possibly
       
   565         // existing queued plugins
       
   566         iServer->NotifyPluginReopenRequest();
       
   567         }
       
   568     FTRACE(FPrint( _L( "CDunBtPlugin::NotifyProgressChangeL() complete")) );
       
   569     }
       
   570 
       
   571 // ======== GLOBAL FUNCTIONS ========
       
   572 
       
   573 // ---------------------------------------------------------------------------
       
   574 // NewLocalPluginL implements factory construction for
       
   575 // the class CDunBtPlugin.
       
   576 // The function is exported at ordinal 1.
       
   577 // ---------------------------------------------------------------------------
       
   578 //
       
   579 EXPORT_C MDunLocalMediaPlugin* NewLocalPluginL()
       
   580     {
       
   581     return new (ELeave) CDunBtPlugin;
       
   582     }