Nut/OS  4.10.3
API Reference
ipcpout.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.7  2008/08/11 07:00:30  haraldkipp
00053  * BSD types replaced by stdint types (feature request #1282721).
00054  *
00055  * Revision 1.6  2008/04/18 13:32:00  haraldkipp
00056  * Changed size parameter from u_short to int, which is easier to handle
00057  * for 32-bit targets. You need to recompile your ARM code. No impact on
00058  * AVR expected
00059  * I changed u_int to int at some places to avoid some warnings during
00060  * compilation of Nut/Net.
00061  * libs.
00062  *
00063  * Revision 1.5  2006/10/08 16:48:22  haraldkipp
00064  * Documentation fixed
00065  *
00066  * Revision 1.4  2005/04/08 15:20:50  olereinhardt
00067  * added <sys/types.h> (__APPLE__) and <netinet/in.h> (__linux__)
00068  * for htons and simmilar.
00069  *
00070  * Revision 1.3  2003/08/14 15:17:50  haraldkipp
00071  * Caller controls ID increment
00072  *
00073  * Revision 1.2  2003/07/24 16:13:38  haraldkipp
00074  * Never request a rejected DNS
00075  *
00076  * Revision 1.1.1.1  2003/05/09 14:41:31  haraldkipp
00077  * Initial using 3.2.1
00078  *
00079  * Revision 1.1  2003/03/31 14:53:27  harald
00080  * Prepare release 3.1
00081  *
00082  */
00083 #include <string.h>
00084 
00085 #include <dev/ppp.h>
00086 
00087 #include <sys/heap.h>
00088 #include <sys/thread.h>
00089 #include <sys/types.h>
00090 #include <net/if_var.h>
00091 #include <netinet/if_ppp.h>
00092 #include <netinet/ppp_fsm.h>
00093 #include <netinet/in.h>
00094 #include <net/ppp.h>
00095 
00100 
00117 int NutIpcpOutput(NUTDEVICE * dev, uint8_t code, uint8_t id, NETBUF * nb)
00118 {
00119     XCPHDR *xcp;
00120 
00121     if ((nb = NutNetBufAlloc(nb, NBAF_NETWORK, sizeof(XCPHDR))) == 0)
00122         return -1;
00123 
00124     xcp = nb->nb_nw.vp;
00125     xcp->xch_code = code;
00126     xcp->xch_id = id;
00127     xcp->xch_len = htons(nb->nb_nw.sz + nb->nb_tp.sz + nb->nb_ap.sz);
00128 
00129     if (NutPppOutput(dev, PPP_IPCP, 0, nb) == 0) {
00130         NutNetBufFree(nb);
00131         return 0;
00132     }
00133     return -1;
00134 }
00135 
00136 /*
00137  * Send a Configure-Request.
00138  * TODO: May use preconfigured addresses.
00139  */
00140 void IpcpTxConfReq(NUTDEVICE *dev, uint8_t id)
00141 {
00142     PPPDCB *dcb = dev->dev_dcb;
00143     XCPOPT *xcpo;
00144     NETBUF *nb;
00145     int len;
00146 
00147     /*
00148      * Not currently negotiating.
00149      */
00150     if(dcb->dcb_ipcp_state != PPPS_REQSENT &&
00151        dcb->dcb_ipcp_state != PPPS_ACKRCVD &&
00152        dcb->dcb_ipcp_state != PPPS_ACKSENT) {
00153         dcb->dcb_ipcp_naks = 0;
00154     }
00155     dcb->dcb_acked = 0;
00156 
00157     /*
00158      * Create the request.
00159      */
00160     len = 6;
00161     if((dcb->dcb_rejects & REJ_IPCP_DNS1) == 0)
00162         len += 6;
00163     if((dcb->dcb_rejects & REJ_IPCP_DNS2) == 0)
00164         len += 6;
00165     if ((nb = NutNetBufAlloc(0, NBAF_APPLICATION, len)) != 0) {
00166         xcpo = nb->nb_ap.vp;
00167         xcpo->xcpo_type = IPCP_ADDR;
00168         xcpo->xcpo_len = 6;
00169         xcpo->xcpo_.ul = dcb->dcb_local_ip;
00170 
00171         if((dcb->dcb_rejects & REJ_IPCP_DNS1) == 0) {
00172             xcpo = (XCPOPT *)((char *)xcpo + xcpo->xcpo_len);
00173             xcpo->xcpo_type = IPCP_MS_DNS1;
00174             xcpo->xcpo_len = 6;
00175             xcpo->xcpo_.ul = dcb->dcb_ip_dns1;
00176         }
00177 
00178         if((dcb->dcb_rejects & REJ_IPCP_DNS2) == 0) {
00179             xcpo = (XCPOPT *)((char *)xcpo + xcpo->xcpo_len);
00180             xcpo->xcpo_type = IPCP_MS_DNS2;
00181             xcpo->xcpo_len = 6;
00182             xcpo->xcpo_.ul = dcb->dcb_ip_dns2;
00183         }
00184         NutIpcpOutput(dev, XCP_CONFREQ, id, nb);
00185     }
00186 }
00187