[En-Nut-Discussion] Closing PPP properly: The solution (I hope)

Eduardo Serantes eserantes at telefonica.net
Fri Jan 14 07:07:08 CET 2005


Hi all,

After 100 coffees and 1000 cigarrettes (who has written the "easy" PPP
code?), I think I have found a solution to restart the ppp driver
succesfully. The solution is a little bit "dirty" (in spanish we say
"casposa"), but it seems no memory remains allocated and the system works
very well. The changes are only applied to ahdlcavr.c and I have marked
them:


THREAD(AhdlcRx, arg)
{
    NUTDEVICE *dev = arg;
    NUTDEVICE *netdev;
    AHDLCDCB *dcb = dev->dev_dcb;
    IFNET *ifn;
    NETBUF *nb;
    u_char *rxbuf;
    u_char *rxptr = 0;
    u_short rxcnt = 0;
    u_char ch;
    u_short tbx;
    u_char inframe;
    u_char escaped = 0;
    u_short rxfcs = AHDLC_INITFCS;

    NutThreadSetPriority(9);
    for (;;) {

	/* Added by Edu */
	rxptr = 0;
	rxcnt = 0;
	escaped = 0;
	rxfcs = AHDLC_INITFCS;
	/* End*/
	
        for (;;) {

	............

	for (;;) {
            /*
             * If we are still connected to a network, fetch the next
             * character from the buffer.
             */
            while (dcb->dcb_rd_idx == dcb->dcb_rx_idx) {
                if (dev->dev_icb == 0)
                    break;
                /* TODO: Check for idle timeout. */
                if (NutEventWait(&dcb->dcb_rx_rdy, dcb->dcb_rtimeout)) {
                    continue;
                	}
                }

			/* Added by Edu */
			if (dev->dev_icb == 0)
                    break;
			/* End */
					
            ch = dcb->dcb_rx_buf[dcb->dcb_rd_idx++];

	.............

/* Signal the link driver that we are down. */
        netdev->dev_ioctl(netdev, LCP_LOWERDOWN, 0);
		
        /* Disconnected, clean up. */
        if (rxbuf) {
            NutHeapFree(rxbuf);
            rxbuf = 0;
        	}

        /* Added by Edu */
      	if (nb) {
		   NutHeapFree(nb);
		   nb=0;
		   }
	  /* End */
    }
}

I hope it helps... and if you find any bug, please keep me posted!!

Regards,

Eduardo




More information about the En-Nut-Discussion mailing list