Nut/OS  4.10.3
API Reference
papin.c
Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2001-2003 by egnite Software GmbH. All rights reserved.
00003  *
00004  * Redistribution and use in source and binary forms, with or without
00005  * modification, are permitted provided that the following conditions
00006  * are met:
00007  *
00008  * 1. Redistributions of source code must retain the above copyright
00009  *    notice, this list of conditions and the following disclaimer.
00010  * 2. Redistributions in binary form must reproduce the above copyright
00011  *    notice, this list of conditions and the following disclaimer in the
00012  *    documentation and/or other materials provided with the distribution.
00013  * 3. Neither the name of the copyright holders nor the names of
00014  *    contributors may be used to endorse or promote products derived
00015  *    from this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY EGNITE SOFTWARE GMBH AND CONTRIBUTORS
00018  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00019  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00020  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL EGNITE
00021  * SOFTWARE GMBH OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00022  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00023  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
00024  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
00025  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00026  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
00027  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00028  * SUCH DAMAGE.
00029  *
00030  * For additional information see http://www.ethernut.de/
00031  *
00032  * -
00033  * Portions are 
00034  * Copyright (c) 1989 by Carnegie Mellon University.
00035  * All rights reserved.
00036  *
00037  * Redistribution and use in source and binary forms are permitted
00038  * provided that the above copyright notice and this paragraph are
00039  * duplicated in all such forms and that any documentation,
00040  * advertising materials, and other materials related to such
00041  * distribution and use acknowledge that the software was developed
00042  * by Carnegie Mellon University.  The name of the
00043  * University may not be used to endorse or promote products derived
00044  * from this software without specific prior written permission.
00045  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
00046  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
00047  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00048  */
00049 
00050 /*
00051  * $Log$
00052  * Revision 1.3  2008/08/11 07:00:31  haraldkipp
00053  * BSD types replaced by stdint types (feature request #1282721).
00054  *
00055  * Revision 1.2  2005/04/08 15:20:51  olereinhardt
00056  * added <sys/types.h> (__APPLE__) and <netinet/in.h> (__linux__)
00057  * for htons and simmilar.
00058  *
00059  * Revision 1.1.1.1  2003/05/09 14:41:35  haraldkipp
00060  * Initial using 3.2.1
00061  *
00062  * Revision 1.2  2003/05/06 18:16:41  harald
00063  * PPP IP config to DCB
00064  *
00065  * Revision 1.1  2003/03/31 14:53:28  harald
00066  * Prepare release 3.1
00067  *
00068  */
00069 
00070 #include <dev/ppp.h>
00071 #include <sys/types.h>
00072 #include <net/if_var.h>
00073 #include <netinet/if_ppp.h>
00074 #include <netinet/ppp_fsm.h>
00075 #include <netinet/in.h>
00081 
00082 
00083 /*
00084  * No server support.
00085  */
00086 void PapRxAuthReq(NUTDEVICE *dev, uint8_t id, NETBUF *nb)
00087 {
00088     NutPapOutput(dev, XCP_CONFACK, id, nb);
00089 }
00090 
00091 void PapRxAuthAck(NUTDEVICE *dev, uint8_t id, NETBUF *nb)
00092 {
00093     PPPDCB *dcb = dev->dev_dcb;
00094 
00095     if(dcb->dcb_auth_state == PAPCS_AUTHREQ) {
00096         /*
00097          * Flag us open and start the network.
00098          */
00099         dcb->dcb_auth_state = PAPCS_OPEN;
00100         IpcpLowerUp(dev);
00101     }
00102 }
00103 
00104 void PapRxAuthNak(NUTDEVICE *dev, uint8_t id, NETBUF *nb)
00105 {
00106     PPPDCB *dcb = dev->dev_dcb;
00107 
00108     if(dcb->dcb_auth_state == PAPCS_AUTHREQ) {
00109         dcb->dcb_auth_state = PAPCS_BADAUTH;
00110         IpcpLowerDown(dev);
00111     }
00112 }
00113 
00122 void NutPapInput(NUTDEVICE * dev, NETBUF * nb)
00123 {
00124     XCPHDR *pap;
00125     uint16_t len;
00126 
00127     /*
00128      * Drop packets with illegal lengths.
00129      */
00130     if (nb->nb_nw.sz < sizeof(XCPHDR)) {
00131         NutNetBufFree(nb);
00132         return;
00133     }
00134     pap = (XCPHDR *) nb->nb_nw.vp;
00135     if ((len = htons(pap->xch_len)) < sizeof(XCPHDR) || len > nb->nb_nw.sz) {
00136         NutNetBufFree(nb);
00137         return;
00138     }
00139 
00140     /*
00141      * Split the PAP packet.
00142      */
00143     nb->nb_ap.vp = pap + 1;
00144     nb->nb_ap.sz = htons(pap->xch_len) - sizeof(XCPHDR);
00145 
00146     /*
00147      * Action depends on code.
00148      */
00149     switch (pap->xch_code) {
00150     case XCP_CONFREQ:
00151         PapRxAuthReq(dev, pap->xch_id, nb);
00152         break;
00153 
00154     case XCP_CONFACK:
00155         PapRxAuthAck(dev, pap->xch_id, nb);
00156         break;
00157 
00158     case XCP_CONFNAK:
00159         PapRxAuthNak(dev, pap->xch_id, nb);
00160         break;
00161 
00162     default:
00163         break;
00164     }
00165     NutNetBufFree(nb);
00166 }
00167