This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

NDK PPP LCP Disconnect

I have a project running under TIRTOS with NDK_2_23_01_01 using PPP Client to talk to a 3G modem via serial.

This is all working fine but I wish to drop the PPP layer by doing an LCP disconnect so that I can do clean shut down of a PPP session.

The PPP library only has pppNew, pppFree, pppInput, pppTimer, pppTxIpPacket functions.

The status function tells me if the PPP has disconnected, I want to initiate the disconnection.  Would appreciate being advised how this is done, or if it can be done?

  • Hi Barry,

    Sorry for the delayed response.

    If I understand you correctly, you want a means to call pppFree in the event of a LCP disconnect.  Unfortunately, this is not supported in the NDK.  

    Regards,

    -- Emmanuel

  • Not quite correct.

    I already have code which handles the receipt of the disconnect message and as per the examples it does call pppFree. 

    My issue is that I wish to be able to tell the PPP session that I wish to end from the client side so that it will then send an LCP disconnect message and when I receive the disconnect state on the PPP status handler it will then clear the PPP stack using pppFree.

    I don't wish to wind up with orphaned PPP interfaces by just discarding them and calling pppFree when it is still required by the stack will probably cause exceptions.

  • Just for further information.

    Part of handling the PPP interface is the requirement for a function to handle status callbacks

    static void hdlcSI( HANDLE hSI, uint Msg, UINT32 Aux, PBM_Handle hPkt )

    This function handles

    case SI_MSG_CALLSTATUS:

    case SI_MSG_PEERCMAP:

    case SI_MSG_SENDPACKET:

    Part of handling disconnect is to clear the handle for the ppp instance

    pi->Status = (uint)Aux;
    if( Aux >= SI_CSTATUS_DISCONNECT )
    {
    // Close PPP - we clear the handle to make sure we
    // only call pppFree() once. (We may get multiple
    // disconnect messages - one from each protocol.)
    if( pi->hPPP )
    {
    hTmp = pi->hPPP;
    pi->hPPP = 0;
    pppFree( hTmp );
    }
    }

    This is as per the examples in the NDK and all works fine when the network drops the LCP link.  I have verified this by removing the antenna from the 3G modem so it loses network connectivity and I eventually get the disconnect message and all is handled fine.

    What I want is to be able to call the close function for the PPP stack so I can get it to send the LCP disconnect, the modem to respond with disconnected and then the PPP instance is all cleared correctly and neatly.

  • Just following up on this to see if anyone has any suggestion as to how I can drop an existing PPP session so that I can connect to another service.

    I know PPP is probably not used by many people but hoping that someone can direct me in the right direction.

    If the PPP link is dropped from the modem end the stack already handles this and the interface is correctly closed.

    I need to be able to do this myself if a session fails so I can switch to a secondary host system.

    I have tried calling the stop function on the PPP NETIF_DEVICE but that stops the entire stack, not just the PPP interface.

    I have also tried calling lcpClose which does return a NO CARRIER from the modem but the PPP state machine just keeps rolling along and doesn't properly close itself?

    Any help would be appreciated.

  • Finally have an answer to this.

    It can be done and quite easily as it turns out.

    What I was missing was a function to monitor the status of the HDLC link and delete the pointer to the HDLC com port.  This is needed in the task which calls hdlcNew to create the PPP interface in the first place.

                status = hdlcGetStatus( hHDLC );

                // If disconnected, print message and close
                if( status >= SI_CSTATUS_DISCONNECT )
                {
                    printf("SCtrl: Disconnected (%d)\n",status);
                    hdlcFree( hHDLC );
                    hHDLC = 0;
                    fConnectMsg = 0;
                }

    In order to disconnect at any time I created a function called hdlcStop

    void hdlcStop(HANDLE hHDLC)
    {
      HDLC_INSTANCE *pi = (HDLC_INSTANCE *)hHDLC;
    
      if (pi)
      {
        // Enter kernel mode
        llEnter();
    
        if( pi && (pi->Type == HDLC_INST_CLIENT || pi->Type == HDLC_INST_SERVER)  )
        {
    	// This message will close PPP
    	hdlcSI( hHDLC, SI_MSG_CALLSTATUS, SI_CSTATUS_DISCONNECT, 0 );
        }
        // Exit kernel mode
        llExit();
      }
    }
    

    This will cause the NDK to stop the PPP session and remove the interface and the previously mentioned check in the HDLC task then cleans up the HDLC pointer so you can create a new one when you wish to start a new HDLC (PPP) session.

    Example output from Console as I close one session and start another:

    Network Added: If-2:10.106.21.207

    Network Removed: If-2:10.106.21.207

    Network Added: If-2:10.106.37.156

    Network Removed: If-2:10.106.37.156

    Network Added: If-2:10.106.52.246

    Network Removed: If-2:10.106.52.246

    Network Added: If-2:10.107.38.209

    Network Removed: If-2:10.107.38.209

    Network Added: If-2:10.106.82.148

    Network Removed: If-2:10.106.82.148

    Network Added: If-2:10.107.72.22

    Network Removed: If-2:10.107.72.22

    Network Added: If-2:10.107.91.241

    Network Removed: If-2:10.107.91.241

    Network Added: If-2:10.107.111.112

    Network Removed: If-2:10.107.111.112

    Network Added: If-2:10.106.31.25

    Network Removed: If-2:10.106.31.25

    Network Added: If-2:10.107.113.186

    Network Removed: If-2:10.107.113.186

    Network Added: If-2:10.107.115.53

    Network Removed: If-2:10.107.115.53

    Network Added: If-2:10.107.12.144

    Network Removed: If-2:10.107.12.144

    Network Added: If-2:10.107.30.202

    Network Removed: If-2:10.107.30.202

    Network Added: If-2:10.106.111.202

    Network Removed: If-2:10.106.111.202