[En-Nut-Discussion] PPP

Tarmo Fimberg tarmo at kaugotsing.ee
Mon Mar 17 11:38:20 CET 2003


Hi!
My previous implementation of ACFC and PFC was incomplete.
So here is correction that works for me.

There are still some problems with PPP and socket interface, specially with 
NutUdpReceiveFrom, if queries are longer, but I'll return to this later...

If there is any further work done on the PPP driver, I might be interested...

#define ODD(x) (((x) & 1) == 1)

void PPPInput(NUTDEVICE *dev, NETBUF *nb)
{
	u_short prot_type;
	u_short acf;
 	int n = 4;
	//
	// Split the PPP frame.
	// Ignore the address and control bytes and extract the protocol...
	//
        memcpy(&acf, ((u_char *) nb->nb_dl.vp), 2);

        //Check for Address-and-Control-Field-Compression
 	if((acf & 0xff) != 0xff) n--;  //If 1st byte is not 0xff, ACFC
	if(((acf>>8) & 0xff) != 0x03) n--;  //If 2nd byte is not 0x03, ACFC

	memcpy(&prot_type, ((u_char *)nb->nb_dl.vp) + n - 2, 2);
 	//Check for Protocol-Field-Compression
  	if(ODD(prot_type & 0xff)) {  //If 1st byte is odd, PFC is used
                n--;
                prot_type >>= 8;
        }

	nb->nb_nw.vp = ((u_char *)nb->nb_dl.vp) + n;
	nb->nb_nw.sz = nb->nb_dl.sz - n;
	nb->nb_dl.sz = n;

	//NutPrintString_P(dev_debug, PSTR("Enter PPPInput prot = %x\r\n"), 
ntohs(prot_type));
	//
	// Route frame to the correct handler.
	//
    switch(ntohs(prot_type))
        {
    case PROT_IP:
        NutIpInput(dev, nb);
        break;
    case PROT_LCP:
        NutLCPInput(dev, nb);
        break;
        case PROT_IPCP:
        NutIPCPInput(dev, nb);
        break;
        case PROT_PAP:
        NutPAPInput(dev, nb);
        break;
    default:
        NutNetBufFree(nb);
        break;
    }
}


Best Rgds,
Tarmo Fimberg
<tarmo_at_kaugotsing_dot_ee>




More information about the En-Nut-Discussion mailing list