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 Copyright (C) 2000 David J. Hudson <dave@humbug.demon.co.uk> 00034 * 00035 * This file is distributed in the hope that it will be useful, but WITHOUT 00036 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00037 * FITNESS FOR A PARTICULAR PURPOSE. 00038 * 00039 * You can redistribute this file and/or modify it under the terms of the GNU 00040 * General Public License (GPL) as published by the Free Software Foundation; 00041 * either version 2 of the License, or (at your discretion) any later version. 00042 * See the accompanying file "copying-gpl.txt" for more details. 00043 * 00044 * As a special exception to the GPL, permission is granted for additional 00045 * uses of the text contained in this file. See the accompanying file 00046 * "copying-liquorice.txt" for details. 00047 * - 00048 * Portions Copyright (c) 1983, 1993 by 00049 * The Regents of the University of California. All rights reserved. 00050 * 00051 * Redistribution and use in source and binary forms, with or without 00052 * modification, are permitted provided that the following conditions 00053 * are met: 00054 * 1. Redistributions of source code must retain the above copyright 00055 * notice, this list of conditions and the following disclaimer. 00056 * 2. Redistributions in binary form must reproduce the above copyright 00057 * notice, this list of conditions and the following disclaimer in the 00058 * documentation and/or other materials provided with the distribution. 00059 * 3. Neither the name of the University nor the names of its contributors 00060 * may be used to endorse or promote products derived from this software 00061 * without specific prior written permission. 00062 * 00063 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 00064 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00065 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00066 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 00067 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00068 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 00069 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 00070 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00071 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 00072 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 00073 * SUCH DAMAGE. 00074 * - 00075 * Portions Copyright (c) 1993 by Digital Equipment Corporation. 00076 * 00077 * Permission to use, copy, modify, and distribute this software for any 00078 * purpose with or without fee is hereby granted, provided that the above 00079 * copyright notice and this permission notice appear in all copies, and that 00080 * the name of Digital Equipment Corporation not be used in advertising or 00081 * publicity pertaining to distribution of the document or software without 00082 * specific, written prior permission. 00083 * 00084 * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL 00085 * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES 00086 * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT 00087 * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL 00088 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR 00089 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS 00090 * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS 00091 * SOFTWARE. 00092 */ 00093 00094 /* 00095 * $Log: papout.c,v $ 00096 * Revision 1.6 2008/04/18 13:32:00 haraldkipp 00097 * Changed size parameter from u_short to int, which is easier to handle 00098 * for 32-bit targets. You need to recompile your ARM code. No impact on 00099 * AVR expected 00100 * I changed u_int to int at some places to avoid some warnings during 00101 * compilation of Nut/Net. 00102 * libs. 00103 * 00104 * Revision 1.5 2006/10/08 16:48:22 haraldkipp 00105 * Documentation fixed 00106 * 00107 * Revision 1.4 2006/03/29 01:23:52 olereinhardt 00108 * Signednes of strings 00109 * 00110 * Revision 1.3 2005/04/08 15:20:51 olereinhardt 00111 * added <sys/types.h> (__APPLE__) and <netinet/in.h> (__linux__) 00112 * for htons and simmilar. 00113 * 00114 * Revision 1.2 2003/08/14 15:17:50 haraldkipp 00115 * Caller controls ID increment 00116 * 00117 * Revision 1.1.1.1 2003/05/09 14:41:35 haraldkipp 00118 * Initial using 3.2.1 00119 * 00120 * Revision 1.1 2003/03/31 14:53:28 harald 00121 * Prepare release 3.1 00122 * 00123 * Revision 1.10 2003/02/04 18:14:56 harald 00124 * Version 3 released 00125 * 00126 * Revision 1.9 2002/06/26 17:29:35 harald 00127 * First pre-release with 2.4 stack 00128 * 00129 */ 00130 00131 #include <string.h> 00132 00133 #include <dev/ppp.h> 00134 00135 #include <sys/heap.h> 00136 #include <sys/thread.h> 00137 #include <sys/types.h> 00138 #include <net/if_var.h> 00139 #include <net/ppp.h> 00140 #include <netinet/if_ppp.h> 00141 #include <netinet/ppp_fsm.h> 00142 #include <netinet/in.h> 00147 00164 int NutPapOutput(NUTDEVICE * dev, u_char code, u_char id, NETBUF * nb) 00165 { 00166 XCPHDR *xch; 00167 00168 if ((nb = NutNetBufAlloc(nb, NBAF_NETWORK, sizeof(XCPHDR))) == 0) 00169 return -1; 00170 00171 xch = nb->nb_nw.vp; 00172 xch->xch_code = code; 00173 xch->xch_id = id; 00174 xch->xch_len = htons(nb->nb_nw.sz + nb->nb_tp.sz + nb->nb_ap.sz); 00175 00176 if (NutPppOutput(dev, PPP_PAP, 0, nb) == 0) 00177 NutNetBufFree(nb); 00178 00179 return 0; 00180 } 00181 00182 /* 00183 * Send a Configure-Request. 00184 */ 00185 void PapTxAuthReq(NUTDEVICE *dev, u_char id) 00186 { 00187 PPPDCB *dcb = dev->dev_dcb; 00188 NETBUF *nb; 00189 char *cp; 00190 int len; 00191 00192 /* 00193 * Create the request. 00194 */ 00195 len = 2; 00196 if(dcb->dcb_user) 00197 len += strlen((char*)dcb->dcb_user); 00198 if(dcb->dcb_pass) 00199 len += strlen((char*)dcb->dcb_pass); 00200 if ((nb = NutNetBufAlloc(0, NBAF_APPLICATION, len)) != 0) { 00201 cp = nb->nb_ap.vp; 00202 *cp = dcb->dcb_user ? (char)strlen((char*)dcb->dcb_user) : 0; 00203 if(*cp) 00204 memcpy(cp + 1, dcb->dcb_user, *cp); 00205 00206 cp += *cp + 1; 00207 *cp = dcb->dcb_pass ? (char)strlen((char*)dcb->dcb_pass) : 0; 00208 if(*cp) 00209 memcpy(cp + 1, dcb->dcb_pass, *cp); 00210 00211 dcb->dcb_auth_state = PAPCS_AUTHREQ; 00212 NutPapOutput(dev, XCP_CONFREQ, ++dcb->dcb_reqid, nb); 00213 } 00214 } 00215