Leest de waarde van een sensor binnen een maakt deze beschikbaar via internet

Dependencies:   NTPClient_NetServices mbed

Committer:
hendrikvincent
Date:
Mon Dec 02 09:01:23 2013 +0000
Revision:
0:05ccbd4f84f1
eerste programma;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
hendrikvincent 0:05ccbd4f84f1 1 /*****************************************************************************
hendrikvincent 0:05ccbd4f84f1 2 * pap.c - Network Password Authentication Protocol program file.
hendrikvincent 0:05ccbd4f84f1 3 *
hendrikvincent 0:05ccbd4f84f1 4 * Copyright (c) 2003 by Marc Boucher, Services Informatiques (MBSI) inc.
hendrikvincent 0:05ccbd4f84f1 5 * portions Copyright (c) 1997 by Global Election Systems Inc.
hendrikvincent 0:05ccbd4f84f1 6 *
hendrikvincent 0:05ccbd4f84f1 7 * The authors hereby grant permission to use, copy, modify, distribute,
hendrikvincent 0:05ccbd4f84f1 8 * and license this software and its documentation for any purpose, provided
hendrikvincent 0:05ccbd4f84f1 9 * that existing copyright notices are retained in all copies and that this
hendrikvincent 0:05ccbd4f84f1 10 * notice and the following disclaimer are included verbatim in any
hendrikvincent 0:05ccbd4f84f1 11 * distributions. No written agreement, license, or royalty fee is required
hendrikvincent 0:05ccbd4f84f1 12 * for any of the authorized uses.
hendrikvincent 0:05ccbd4f84f1 13 *
hendrikvincent 0:05ccbd4f84f1 14 * THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS *AS IS* AND ANY EXPRESS OR
hendrikvincent 0:05ccbd4f84f1 15 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
hendrikvincent 0:05ccbd4f84f1 16 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
hendrikvincent 0:05ccbd4f84f1 17 * IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
hendrikvincent 0:05ccbd4f84f1 18 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
hendrikvincent 0:05ccbd4f84f1 19 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
hendrikvincent 0:05ccbd4f84f1 20 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
hendrikvincent 0:05ccbd4f84f1 21 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
hendrikvincent 0:05ccbd4f84f1 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
hendrikvincent 0:05ccbd4f84f1 23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
hendrikvincent 0:05ccbd4f84f1 24 *
hendrikvincent 0:05ccbd4f84f1 25 ******************************************************************************
hendrikvincent 0:05ccbd4f84f1 26 * REVISION HISTORY
hendrikvincent 0:05ccbd4f84f1 27 *
hendrikvincent 0:05ccbd4f84f1 28 * 03-01-01 Marc Boucher <marc@mbsi.ca>
hendrikvincent 0:05ccbd4f84f1 29 * Ported to lwIP.
hendrikvincent 0:05ccbd4f84f1 30 * 97-12-12 Guy Lancaster <lancasterg@acm.org>, Global Election Systems Inc.
hendrikvincent 0:05ccbd4f84f1 31 * Original.
hendrikvincent 0:05ccbd4f84f1 32 *****************************************************************************/
hendrikvincent 0:05ccbd4f84f1 33 /*
hendrikvincent 0:05ccbd4f84f1 34 * upap.c - User/Password Authentication Protocol.
hendrikvincent 0:05ccbd4f84f1 35 *
hendrikvincent 0:05ccbd4f84f1 36 * Copyright (c) 1989 Carnegie Mellon University.
hendrikvincent 0:05ccbd4f84f1 37 * All rights reserved.
hendrikvincent 0:05ccbd4f84f1 38 *
hendrikvincent 0:05ccbd4f84f1 39 * Redistribution and use in source and binary forms are permitted
hendrikvincent 0:05ccbd4f84f1 40 * provided that the above copyright notice and this paragraph are
hendrikvincent 0:05ccbd4f84f1 41 * duplicated in all such forms and that any documentation,
hendrikvincent 0:05ccbd4f84f1 42 * advertising materials, and other materials related to such
hendrikvincent 0:05ccbd4f84f1 43 * distribution and use acknowledge that the software was developed
hendrikvincent 0:05ccbd4f84f1 44 * by Carnegie Mellon University. The name of the
hendrikvincent 0:05ccbd4f84f1 45 * University may not be used to endorse or promote products derived
hendrikvincent 0:05ccbd4f84f1 46 * from this software without specific prior written permission.
hendrikvincent 0:05ccbd4f84f1 47 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
hendrikvincent 0:05ccbd4f84f1 48 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
hendrikvincent 0:05ccbd4f84f1 49 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
hendrikvincent 0:05ccbd4f84f1 50 */
hendrikvincent 0:05ccbd4f84f1 51
hendrikvincent 0:05ccbd4f84f1 52 #include "lwip/opt.h"
hendrikvincent 0:05ccbd4f84f1 53
hendrikvincent 0:05ccbd4f84f1 54 #if PPP_SUPPORT /* don't build if not configured for use in lwipopts.h */
hendrikvincent 0:05ccbd4f84f1 55
hendrikvincent 0:05ccbd4f84f1 56 #if PAP_SUPPORT /* don't build if not configured for use in lwipopts.h */
hendrikvincent 0:05ccbd4f84f1 57
hendrikvincent 0:05ccbd4f84f1 58 #include "ppp.h"
hendrikvincent 0:05ccbd4f84f1 59 #include "pppdebug.h"
hendrikvincent 0:05ccbd4f84f1 60
hendrikvincent 0:05ccbd4f84f1 61 #include "auth.h"
hendrikvincent 0:05ccbd4f84f1 62 #include "pap.h"
hendrikvincent 0:05ccbd4f84f1 63
hendrikvincent 0:05ccbd4f84f1 64 #include <string.h>
hendrikvincent 0:05ccbd4f84f1 65
hendrikvincent 0:05ccbd4f84f1 66 #if 0 /* UNUSED */
hendrikvincent 0:05ccbd4f84f1 67 static bool hide_password = 1;
hendrikvincent 0:05ccbd4f84f1 68
hendrikvincent 0:05ccbd4f84f1 69 /*
hendrikvincent 0:05ccbd4f84f1 70 * Command-line options.
hendrikvincent 0:05ccbd4f84f1 71 */
hendrikvincent 0:05ccbd4f84f1 72 static option_t pap_option_list[] = {
hendrikvincent 0:05ccbd4f84f1 73 { "hide-password", o_bool, &hide_password,
hendrikvincent 0:05ccbd4f84f1 74 "Don't output passwords to log", 1 },
hendrikvincent 0:05ccbd4f84f1 75 { "show-password", o_bool, &hide_password,
hendrikvincent 0:05ccbd4f84f1 76 "Show password string in debug log messages", 0 },
hendrikvincent 0:05ccbd4f84f1 77 { "pap-restart", o_int, &upap[0].us_timeouttime,
hendrikvincent 0:05ccbd4f84f1 78 "Set retransmit timeout for PAP" },
hendrikvincent 0:05ccbd4f84f1 79 { "pap-max-authreq", o_int, &upap[0].us_maxtransmits,
hendrikvincent 0:05ccbd4f84f1 80 "Set max number of transmissions for auth-reqs" },
hendrikvincent 0:05ccbd4f84f1 81 { "pap-timeout", o_int, &upap[0].us_reqtimeout,
hendrikvincent 0:05ccbd4f84f1 82 "Set time limit for peer PAP authentication" },
hendrikvincent 0:05ccbd4f84f1 83 { NULL }
hendrikvincent 0:05ccbd4f84f1 84 };
hendrikvincent 0:05ccbd4f84f1 85 #endif
hendrikvincent 0:05ccbd4f84f1 86
hendrikvincent 0:05ccbd4f84f1 87 /*
hendrikvincent 0:05ccbd4f84f1 88 * Protocol entry points.
hendrikvincent 0:05ccbd4f84f1 89 */
hendrikvincent 0:05ccbd4f84f1 90 static void upap_init (int);
hendrikvincent 0:05ccbd4f84f1 91 static void upap_lowerup (int);
hendrikvincent 0:05ccbd4f84f1 92 static void upap_lowerdown (int);
hendrikvincent 0:05ccbd4f84f1 93 static void upap_input (int, u_char *, int);
hendrikvincent 0:05ccbd4f84f1 94 static void upap_protrej (int);
hendrikvincent 0:05ccbd4f84f1 95 #if PPP_ADDITIONAL_CALLBACKS
hendrikvincent 0:05ccbd4f84f1 96 static int upap_printpkt (u_char *, int, void (*)(void *, char *, ...), void *);
hendrikvincent 0:05ccbd4f84f1 97 #endif /* PPP_ADDITIONAL_CALLBACKS */
hendrikvincent 0:05ccbd4f84f1 98
hendrikvincent 0:05ccbd4f84f1 99 struct protent pap_protent = {
hendrikvincent 0:05ccbd4f84f1 100 PPP_PAP,
hendrikvincent 0:05ccbd4f84f1 101 upap_init,
hendrikvincent 0:05ccbd4f84f1 102 upap_input,
hendrikvincent 0:05ccbd4f84f1 103 upap_protrej,
hendrikvincent 0:05ccbd4f84f1 104 upap_lowerup,
hendrikvincent 0:05ccbd4f84f1 105 upap_lowerdown,
hendrikvincent 0:05ccbd4f84f1 106 NULL,
hendrikvincent 0:05ccbd4f84f1 107 NULL,
hendrikvincent 0:05ccbd4f84f1 108 #if PPP_ADDITIONAL_CALLBACKS
hendrikvincent 0:05ccbd4f84f1 109 upap_printpkt,
hendrikvincent 0:05ccbd4f84f1 110 NULL,
hendrikvincent 0:05ccbd4f84f1 111 #endif /* PPP_ADDITIONAL_CALLBACKS */
hendrikvincent 0:05ccbd4f84f1 112 1,
hendrikvincent 0:05ccbd4f84f1 113 "PAP",
hendrikvincent 0:05ccbd4f84f1 114 #if PPP_ADDITIONAL_CALLBACKS
hendrikvincent 0:05ccbd4f84f1 115 NULL,
hendrikvincent 0:05ccbd4f84f1 116 NULL,
hendrikvincent 0:05ccbd4f84f1 117 NULL
hendrikvincent 0:05ccbd4f84f1 118 #endif /* PPP_ADDITIONAL_CALLBACKS */
hendrikvincent 0:05ccbd4f84f1 119 };
hendrikvincent 0:05ccbd4f84f1 120
hendrikvincent 0:05ccbd4f84f1 121 upap_state upap[NUM_PPP]; /* UPAP state; one for each unit */
hendrikvincent 0:05ccbd4f84f1 122
hendrikvincent 0:05ccbd4f84f1 123 static void upap_timeout (void *);
hendrikvincent 0:05ccbd4f84f1 124 static void upap_reqtimeout(void *);
hendrikvincent 0:05ccbd4f84f1 125 static void upap_rauthreq (upap_state *, u_char *, u_char, int);
hendrikvincent 0:05ccbd4f84f1 126 static void upap_rauthack (upap_state *, u_char *, int, int);
hendrikvincent 0:05ccbd4f84f1 127 static void upap_rauthnak (upap_state *, u_char *, int, int);
hendrikvincent 0:05ccbd4f84f1 128 static void upap_sauthreq (upap_state *);
hendrikvincent 0:05ccbd4f84f1 129 static void upap_sresp (upap_state *, u_char, u_char, char *, int);
hendrikvincent 0:05ccbd4f84f1 130
hendrikvincent 0:05ccbd4f84f1 131
hendrikvincent 0:05ccbd4f84f1 132 /*
hendrikvincent 0:05ccbd4f84f1 133 * upap_init - Initialize a UPAP unit.
hendrikvincent 0:05ccbd4f84f1 134 */
hendrikvincent 0:05ccbd4f84f1 135 static void
hendrikvincent 0:05ccbd4f84f1 136 upap_init(int unit)
hendrikvincent 0:05ccbd4f84f1 137 {
hendrikvincent 0:05ccbd4f84f1 138 upap_state *u = &upap[unit];
hendrikvincent 0:05ccbd4f84f1 139
hendrikvincent 0:05ccbd4f84f1 140 UPAPDEBUG(LOG_INFO, ("upap_init: %d\n", unit));
hendrikvincent 0:05ccbd4f84f1 141 u->us_unit = unit;
hendrikvincent 0:05ccbd4f84f1 142 u->us_user = NULL;
hendrikvincent 0:05ccbd4f84f1 143 u->us_userlen = 0;
hendrikvincent 0:05ccbd4f84f1 144 u->us_passwd = NULL;
hendrikvincent 0:05ccbd4f84f1 145 u->us_passwdlen = 0;
hendrikvincent 0:05ccbd4f84f1 146 u->us_clientstate = UPAPCS_INITIAL;
hendrikvincent 0:05ccbd4f84f1 147 u->us_serverstate = UPAPSS_INITIAL;
hendrikvincent 0:05ccbd4f84f1 148 u->us_id = 0;
hendrikvincent 0:05ccbd4f84f1 149 u->us_timeouttime = UPAP_DEFTIMEOUT;
hendrikvincent 0:05ccbd4f84f1 150 u->us_maxtransmits = 10;
hendrikvincent 0:05ccbd4f84f1 151 u->us_reqtimeout = UPAP_DEFREQTIME;
hendrikvincent 0:05ccbd4f84f1 152 }
hendrikvincent 0:05ccbd4f84f1 153
hendrikvincent 0:05ccbd4f84f1 154 /*
hendrikvincent 0:05ccbd4f84f1 155 * upap_authwithpeer - Authenticate us with our peer (start client).
hendrikvincent 0:05ccbd4f84f1 156 *
hendrikvincent 0:05ccbd4f84f1 157 * Set new state and send authenticate's.
hendrikvincent 0:05ccbd4f84f1 158 */
hendrikvincent 0:05ccbd4f84f1 159 void
hendrikvincent 0:05ccbd4f84f1 160 upap_authwithpeer(int unit, char *user, char *password)
hendrikvincent 0:05ccbd4f84f1 161 {
hendrikvincent 0:05ccbd4f84f1 162 upap_state *u = &upap[unit];
hendrikvincent 0:05ccbd4f84f1 163
hendrikvincent 0:05ccbd4f84f1 164 UPAPDEBUG(LOG_INFO, ("upap_authwithpeer: %d user=%s password=%s s=%d\n",
hendrikvincent 0:05ccbd4f84f1 165 unit, user, password, u->us_clientstate));
hendrikvincent 0:05ccbd4f84f1 166
hendrikvincent 0:05ccbd4f84f1 167 /* Save the username and password we're given */
hendrikvincent 0:05ccbd4f84f1 168 u->us_user = user;
hendrikvincent 0:05ccbd4f84f1 169 u->us_userlen = (int)strlen(user);
hendrikvincent 0:05ccbd4f84f1 170 u->us_passwd = password;
hendrikvincent 0:05ccbd4f84f1 171 u->us_passwdlen = (int)strlen(password);
hendrikvincent 0:05ccbd4f84f1 172
hendrikvincent 0:05ccbd4f84f1 173 u->us_transmits = 0;
hendrikvincent 0:05ccbd4f84f1 174
hendrikvincent 0:05ccbd4f84f1 175 /* Lower layer up yet? */
hendrikvincent 0:05ccbd4f84f1 176 if (u->us_clientstate == UPAPCS_INITIAL ||
hendrikvincent 0:05ccbd4f84f1 177 u->us_clientstate == UPAPCS_PENDING) {
hendrikvincent 0:05ccbd4f84f1 178 u->us_clientstate = UPAPCS_PENDING;
hendrikvincent 0:05ccbd4f84f1 179 return;
hendrikvincent 0:05ccbd4f84f1 180 }
hendrikvincent 0:05ccbd4f84f1 181
hendrikvincent 0:05ccbd4f84f1 182 upap_sauthreq(u); /* Start protocol */
hendrikvincent 0:05ccbd4f84f1 183 }
hendrikvincent 0:05ccbd4f84f1 184
hendrikvincent 0:05ccbd4f84f1 185
hendrikvincent 0:05ccbd4f84f1 186 /*
hendrikvincent 0:05ccbd4f84f1 187 * upap_authpeer - Authenticate our peer (start server).
hendrikvincent 0:05ccbd4f84f1 188 *
hendrikvincent 0:05ccbd4f84f1 189 * Set new state.
hendrikvincent 0:05ccbd4f84f1 190 */
hendrikvincent 0:05ccbd4f84f1 191 void
hendrikvincent 0:05ccbd4f84f1 192 upap_authpeer(int unit)
hendrikvincent 0:05ccbd4f84f1 193 {
hendrikvincent 0:05ccbd4f84f1 194 upap_state *u = &upap[unit];
hendrikvincent 0:05ccbd4f84f1 195
hendrikvincent 0:05ccbd4f84f1 196 /* Lower layer up yet? */
hendrikvincent 0:05ccbd4f84f1 197 if (u->us_serverstate == UPAPSS_INITIAL ||
hendrikvincent 0:05ccbd4f84f1 198 u->us_serverstate == UPAPSS_PENDING) {
hendrikvincent 0:05ccbd4f84f1 199 u->us_serverstate = UPAPSS_PENDING;
hendrikvincent 0:05ccbd4f84f1 200 return;
hendrikvincent 0:05ccbd4f84f1 201 }
hendrikvincent 0:05ccbd4f84f1 202
hendrikvincent 0:05ccbd4f84f1 203 u->us_serverstate = UPAPSS_LISTEN;
hendrikvincent 0:05ccbd4f84f1 204 if (u->us_reqtimeout > 0) {
hendrikvincent 0:05ccbd4f84f1 205 TIMEOUT(upap_reqtimeout, u, u->us_reqtimeout);
hendrikvincent 0:05ccbd4f84f1 206 }
hendrikvincent 0:05ccbd4f84f1 207 }
hendrikvincent 0:05ccbd4f84f1 208
hendrikvincent 0:05ccbd4f84f1 209 /*
hendrikvincent 0:05ccbd4f84f1 210 * upap_timeout - Retransmission timer for sending auth-reqs expired.
hendrikvincent 0:05ccbd4f84f1 211 */
hendrikvincent 0:05ccbd4f84f1 212 static void
hendrikvincent 0:05ccbd4f84f1 213 upap_timeout(void *arg)
hendrikvincent 0:05ccbd4f84f1 214 {
hendrikvincent 0:05ccbd4f84f1 215 upap_state *u = (upap_state *) arg;
hendrikvincent 0:05ccbd4f84f1 216
hendrikvincent 0:05ccbd4f84f1 217 UPAPDEBUG(LOG_INFO, ("upap_timeout: %d timeout %d expired s=%d\n",
hendrikvincent 0:05ccbd4f84f1 218 u->us_unit, u->us_timeouttime, u->us_clientstate));
hendrikvincent 0:05ccbd4f84f1 219
hendrikvincent 0:05ccbd4f84f1 220 if (u->us_clientstate != UPAPCS_AUTHREQ) {
hendrikvincent 0:05ccbd4f84f1 221 UPAPDEBUG(LOG_INFO, ("upap_timeout: not in AUTHREQ state!\n"));
hendrikvincent 0:05ccbd4f84f1 222 return;
hendrikvincent 0:05ccbd4f84f1 223 }
hendrikvincent 0:05ccbd4f84f1 224
hendrikvincent 0:05ccbd4f84f1 225 if (u->us_transmits >= u->us_maxtransmits) {
hendrikvincent 0:05ccbd4f84f1 226 /* give up in disgust */
hendrikvincent 0:05ccbd4f84f1 227 UPAPDEBUG(LOG_ERR, ("No response to PAP authenticate-requests\n"));
hendrikvincent 0:05ccbd4f84f1 228 u->us_clientstate = UPAPCS_BADAUTH;
hendrikvincent 0:05ccbd4f84f1 229 auth_withpeer_fail(u->us_unit, PPP_PAP);
hendrikvincent 0:05ccbd4f84f1 230 return;
hendrikvincent 0:05ccbd4f84f1 231 }
hendrikvincent 0:05ccbd4f84f1 232
hendrikvincent 0:05ccbd4f84f1 233 upap_sauthreq(u); /* Send Authenticate-Request and set upap timeout*/
hendrikvincent 0:05ccbd4f84f1 234 }
hendrikvincent 0:05ccbd4f84f1 235
hendrikvincent 0:05ccbd4f84f1 236
hendrikvincent 0:05ccbd4f84f1 237 /*
hendrikvincent 0:05ccbd4f84f1 238 * upap_reqtimeout - Give up waiting for the peer to send an auth-req.
hendrikvincent 0:05ccbd4f84f1 239 */
hendrikvincent 0:05ccbd4f84f1 240 static void
hendrikvincent 0:05ccbd4f84f1 241 upap_reqtimeout(void *arg)
hendrikvincent 0:05ccbd4f84f1 242 {
hendrikvincent 0:05ccbd4f84f1 243 upap_state *u = (upap_state *) arg;
hendrikvincent 0:05ccbd4f84f1 244
hendrikvincent 0:05ccbd4f84f1 245 if (u->us_serverstate != UPAPSS_LISTEN) {
hendrikvincent 0:05ccbd4f84f1 246 return; /* huh?? */
hendrikvincent 0:05ccbd4f84f1 247 }
hendrikvincent 0:05ccbd4f84f1 248
hendrikvincent 0:05ccbd4f84f1 249 auth_peer_fail(u->us_unit, PPP_PAP);
hendrikvincent 0:05ccbd4f84f1 250 u->us_serverstate = UPAPSS_BADAUTH;
hendrikvincent 0:05ccbd4f84f1 251 }
hendrikvincent 0:05ccbd4f84f1 252
hendrikvincent 0:05ccbd4f84f1 253
hendrikvincent 0:05ccbd4f84f1 254 /*
hendrikvincent 0:05ccbd4f84f1 255 * upap_lowerup - The lower layer is up.
hendrikvincent 0:05ccbd4f84f1 256 *
hendrikvincent 0:05ccbd4f84f1 257 * Start authenticating if pending.
hendrikvincent 0:05ccbd4f84f1 258 */
hendrikvincent 0:05ccbd4f84f1 259 static void
hendrikvincent 0:05ccbd4f84f1 260 upap_lowerup(int unit)
hendrikvincent 0:05ccbd4f84f1 261 {
hendrikvincent 0:05ccbd4f84f1 262 upap_state *u = &upap[unit];
hendrikvincent 0:05ccbd4f84f1 263
hendrikvincent 0:05ccbd4f84f1 264 UPAPDEBUG(LOG_INFO, ("upap_lowerup: init %d clientstate s=%d\n", unit, u->us_clientstate));
hendrikvincent 0:05ccbd4f84f1 265
hendrikvincent 0:05ccbd4f84f1 266 if (u->us_clientstate == UPAPCS_INITIAL) {
hendrikvincent 0:05ccbd4f84f1 267 u->us_clientstate = UPAPCS_CLOSED;
hendrikvincent 0:05ccbd4f84f1 268 } else if (u->us_clientstate == UPAPCS_PENDING) {
hendrikvincent 0:05ccbd4f84f1 269 upap_sauthreq(u); /* send an auth-request */
hendrikvincent 0:05ccbd4f84f1 270 /* now client state is UPAPCS__AUTHREQ */
hendrikvincent 0:05ccbd4f84f1 271 }
hendrikvincent 0:05ccbd4f84f1 272
hendrikvincent 0:05ccbd4f84f1 273 if (u->us_serverstate == UPAPSS_INITIAL) {
hendrikvincent 0:05ccbd4f84f1 274 u->us_serverstate = UPAPSS_CLOSED;
hendrikvincent 0:05ccbd4f84f1 275 } else if (u->us_serverstate == UPAPSS_PENDING) {
hendrikvincent 0:05ccbd4f84f1 276 u->us_serverstate = UPAPSS_LISTEN;
hendrikvincent 0:05ccbd4f84f1 277 if (u->us_reqtimeout > 0) {
hendrikvincent 0:05ccbd4f84f1 278 TIMEOUT(upap_reqtimeout, u, u->us_reqtimeout);
hendrikvincent 0:05ccbd4f84f1 279 }
hendrikvincent 0:05ccbd4f84f1 280 }
hendrikvincent 0:05ccbd4f84f1 281 }
hendrikvincent 0:05ccbd4f84f1 282
hendrikvincent 0:05ccbd4f84f1 283
hendrikvincent 0:05ccbd4f84f1 284 /*
hendrikvincent 0:05ccbd4f84f1 285 * upap_lowerdown - The lower layer is down.
hendrikvincent 0:05ccbd4f84f1 286 *
hendrikvincent 0:05ccbd4f84f1 287 * Cancel all timeouts.
hendrikvincent 0:05ccbd4f84f1 288 */
hendrikvincent 0:05ccbd4f84f1 289 static void
hendrikvincent 0:05ccbd4f84f1 290 upap_lowerdown(int unit)
hendrikvincent 0:05ccbd4f84f1 291 {
hendrikvincent 0:05ccbd4f84f1 292 upap_state *u = &upap[unit];
hendrikvincent 0:05ccbd4f84f1 293
hendrikvincent 0:05ccbd4f84f1 294 UPAPDEBUG(LOG_INFO, ("upap_lowerdown: %d s=%d\n", unit, u->us_clientstate));
hendrikvincent 0:05ccbd4f84f1 295
hendrikvincent 0:05ccbd4f84f1 296 if (u->us_clientstate == UPAPCS_AUTHREQ) { /* Timeout pending? */
hendrikvincent 0:05ccbd4f84f1 297 UNTIMEOUT(upap_timeout, u); /* Cancel timeout */
hendrikvincent 0:05ccbd4f84f1 298 }
hendrikvincent 0:05ccbd4f84f1 299 if (u->us_serverstate == UPAPSS_LISTEN && u->us_reqtimeout > 0) {
hendrikvincent 0:05ccbd4f84f1 300 UNTIMEOUT(upap_reqtimeout, u);
hendrikvincent 0:05ccbd4f84f1 301 }
hendrikvincent 0:05ccbd4f84f1 302
hendrikvincent 0:05ccbd4f84f1 303 u->us_clientstate = UPAPCS_INITIAL;
hendrikvincent 0:05ccbd4f84f1 304 u->us_serverstate = UPAPSS_INITIAL;
hendrikvincent 0:05ccbd4f84f1 305 }
hendrikvincent 0:05ccbd4f84f1 306
hendrikvincent 0:05ccbd4f84f1 307
hendrikvincent 0:05ccbd4f84f1 308 /*
hendrikvincent 0:05ccbd4f84f1 309 * upap_protrej - Peer doesn't speak this protocol.
hendrikvincent 0:05ccbd4f84f1 310 *
hendrikvincent 0:05ccbd4f84f1 311 * This shouldn't happen. In any case, pretend lower layer went down.
hendrikvincent 0:05ccbd4f84f1 312 */
hendrikvincent 0:05ccbd4f84f1 313 static void
hendrikvincent 0:05ccbd4f84f1 314 upap_protrej(int unit)
hendrikvincent 0:05ccbd4f84f1 315 {
hendrikvincent 0:05ccbd4f84f1 316 upap_state *u = &upap[unit];
hendrikvincent 0:05ccbd4f84f1 317
hendrikvincent 0:05ccbd4f84f1 318 if (u->us_clientstate == UPAPCS_AUTHREQ) {
hendrikvincent 0:05ccbd4f84f1 319 UPAPDEBUG(LOG_ERR, ("PAP authentication failed due to protocol-reject\n"));
hendrikvincent 0:05ccbd4f84f1 320 auth_withpeer_fail(unit, PPP_PAP);
hendrikvincent 0:05ccbd4f84f1 321 }
hendrikvincent 0:05ccbd4f84f1 322 if (u->us_serverstate == UPAPSS_LISTEN) {
hendrikvincent 0:05ccbd4f84f1 323 UPAPDEBUG(LOG_ERR, ("PAP authentication of peer failed (protocol-reject)\n"));
hendrikvincent 0:05ccbd4f84f1 324 auth_peer_fail(unit, PPP_PAP);
hendrikvincent 0:05ccbd4f84f1 325 }
hendrikvincent 0:05ccbd4f84f1 326 upap_lowerdown(unit);
hendrikvincent 0:05ccbd4f84f1 327 }
hendrikvincent 0:05ccbd4f84f1 328
hendrikvincent 0:05ccbd4f84f1 329
hendrikvincent 0:05ccbd4f84f1 330 /*
hendrikvincent 0:05ccbd4f84f1 331 * upap_input - Input UPAP packet.
hendrikvincent 0:05ccbd4f84f1 332 */
hendrikvincent 0:05ccbd4f84f1 333 static void
hendrikvincent 0:05ccbd4f84f1 334 upap_input(int unit, u_char *inpacket, int l)
hendrikvincent 0:05ccbd4f84f1 335 {
hendrikvincent 0:05ccbd4f84f1 336 upap_state *u = &upap[unit];
hendrikvincent 0:05ccbd4f84f1 337 u_char *inp;
hendrikvincent 0:05ccbd4f84f1 338 u_char code, id;
hendrikvincent 0:05ccbd4f84f1 339 int len;
hendrikvincent 0:05ccbd4f84f1 340
hendrikvincent 0:05ccbd4f84f1 341 /*
hendrikvincent 0:05ccbd4f84f1 342 * Parse header (code, id and length).
hendrikvincent 0:05ccbd4f84f1 343 * If packet too short, drop it.
hendrikvincent 0:05ccbd4f84f1 344 */
hendrikvincent 0:05ccbd4f84f1 345 inp = inpacket;
hendrikvincent 0:05ccbd4f84f1 346 if (l < (int)UPAP_HEADERLEN) {
hendrikvincent 0:05ccbd4f84f1 347 UPAPDEBUG(LOG_INFO, ("pap_input: rcvd short header.\n"));
hendrikvincent 0:05ccbd4f84f1 348 return;
hendrikvincent 0:05ccbd4f84f1 349 }
hendrikvincent 0:05ccbd4f84f1 350 GETCHAR(code, inp);
hendrikvincent 0:05ccbd4f84f1 351 GETCHAR(id, inp);
hendrikvincent 0:05ccbd4f84f1 352 GETSHORT(len, inp);
hendrikvincent 0:05ccbd4f84f1 353 if (len < (int)UPAP_HEADERLEN) {
hendrikvincent 0:05ccbd4f84f1 354 UPAPDEBUG(LOG_INFO, ("pap_input: rcvd illegal length.\n"));
hendrikvincent 0:05ccbd4f84f1 355 return;
hendrikvincent 0:05ccbd4f84f1 356 }
hendrikvincent 0:05ccbd4f84f1 357 if (len > l) {
hendrikvincent 0:05ccbd4f84f1 358 UPAPDEBUG(LOG_INFO, ("pap_input: rcvd short packet.\n"));
hendrikvincent 0:05ccbd4f84f1 359 return;
hendrikvincent 0:05ccbd4f84f1 360 }
hendrikvincent 0:05ccbd4f84f1 361 len -= UPAP_HEADERLEN;
hendrikvincent 0:05ccbd4f84f1 362
hendrikvincent 0:05ccbd4f84f1 363 /*
hendrikvincent 0:05ccbd4f84f1 364 * Action depends on code.
hendrikvincent 0:05ccbd4f84f1 365 */
hendrikvincent 0:05ccbd4f84f1 366 switch (code) {
hendrikvincent 0:05ccbd4f84f1 367 case UPAP_AUTHREQ:
hendrikvincent 0:05ccbd4f84f1 368 upap_rauthreq(u, inp, id, len);
hendrikvincent 0:05ccbd4f84f1 369 break;
hendrikvincent 0:05ccbd4f84f1 370
hendrikvincent 0:05ccbd4f84f1 371 case UPAP_AUTHACK:
hendrikvincent 0:05ccbd4f84f1 372 upap_rauthack(u, inp, id, len);
hendrikvincent 0:05ccbd4f84f1 373 break;
hendrikvincent 0:05ccbd4f84f1 374
hendrikvincent 0:05ccbd4f84f1 375 case UPAP_AUTHNAK:
hendrikvincent 0:05ccbd4f84f1 376 upap_rauthnak(u, inp, id, len);
hendrikvincent 0:05ccbd4f84f1 377 break;
hendrikvincent 0:05ccbd4f84f1 378
hendrikvincent 0:05ccbd4f84f1 379 default: /* XXX Need code reject */
hendrikvincent 0:05ccbd4f84f1 380 UPAPDEBUG(LOG_INFO, ("pap_input: UNHANDLED default: code: %d, id: %d, len: %d.\n", code, id, len));
hendrikvincent 0:05ccbd4f84f1 381 break;
hendrikvincent 0:05ccbd4f84f1 382 }
hendrikvincent 0:05ccbd4f84f1 383 }
hendrikvincent 0:05ccbd4f84f1 384
hendrikvincent 0:05ccbd4f84f1 385
hendrikvincent 0:05ccbd4f84f1 386 /*
hendrikvincent 0:05ccbd4f84f1 387 * upap_rauth - Receive Authenticate.
hendrikvincent 0:05ccbd4f84f1 388 */
hendrikvincent 0:05ccbd4f84f1 389 static void
hendrikvincent 0:05ccbd4f84f1 390 upap_rauthreq(upap_state *u, u_char *inp, u_char id, int len)
hendrikvincent 0:05ccbd4f84f1 391 {
hendrikvincent 0:05ccbd4f84f1 392 u_char ruserlen, rpasswdlen;
hendrikvincent 0:05ccbd4f84f1 393 char *ruser, *rpasswd;
hendrikvincent 0:05ccbd4f84f1 394 u_char retcode;
hendrikvincent 0:05ccbd4f84f1 395 char *msg;
hendrikvincent 0:05ccbd4f84f1 396 int msglen;
hendrikvincent 0:05ccbd4f84f1 397
hendrikvincent 0:05ccbd4f84f1 398 UPAPDEBUG(LOG_INFO, ("pap_rauth: Rcvd id %d.\n", id));
hendrikvincent 0:05ccbd4f84f1 399
hendrikvincent 0:05ccbd4f84f1 400 if (u->us_serverstate < UPAPSS_LISTEN) {
hendrikvincent 0:05ccbd4f84f1 401 return;
hendrikvincent 0:05ccbd4f84f1 402 }
hendrikvincent 0:05ccbd4f84f1 403
hendrikvincent 0:05ccbd4f84f1 404 /*
hendrikvincent 0:05ccbd4f84f1 405 * If we receive a duplicate authenticate-request, we are
hendrikvincent 0:05ccbd4f84f1 406 * supposed to return the same status as for the first request.
hendrikvincent 0:05ccbd4f84f1 407 */
hendrikvincent 0:05ccbd4f84f1 408 if (u->us_serverstate == UPAPSS_OPEN) {
hendrikvincent 0:05ccbd4f84f1 409 upap_sresp(u, UPAP_AUTHACK, id, "", 0); /* return auth-ack */
hendrikvincent 0:05ccbd4f84f1 410 return;
hendrikvincent 0:05ccbd4f84f1 411 }
hendrikvincent 0:05ccbd4f84f1 412 if (u->us_serverstate == UPAPSS_BADAUTH) {
hendrikvincent 0:05ccbd4f84f1 413 upap_sresp(u, UPAP_AUTHNAK, id, "", 0); /* return auth-nak */
hendrikvincent 0:05ccbd4f84f1 414 return;
hendrikvincent 0:05ccbd4f84f1 415 }
hendrikvincent 0:05ccbd4f84f1 416
hendrikvincent 0:05ccbd4f84f1 417 /*
hendrikvincent 0:05ccbd4f84f1 418 * Parse user/passwd.
hendrikvincent 0:05ccbd4f84f1 419 */
hendrikvincent 0:05ccbd4f84f1 420 if (len < (int)sizeof (u_char)) {
hendrikvincent 0:05ccbd4f84f1 421 UPAPDEBUG(LOG_INFO, ("pap_rauth: rcvd short packet.\n"));
hendrikvincent 0:05ccbd4f84f1 422 return;
hendrikvincent 0:05ccbd4f84f1 423 }
hendrikvincent 0:05ccbd4f84f1 424 GETCHAR(ruserlen, inp);
hendrikvincent 0:05ccbd4f84f1 425 len -= sizeof (u_char) + ruserlen + sizeof (u_char);
hendrikvincent 0:05ccbd4f84f1 426 if (len < 0) {
hendrikvincent 0:05ccbd4f84f1 427 UPAPDEBUG(LOG_INFO, ("pap_rauth: rcvd short packet.\n"));
hendrikvincent 0:05ccbd4f84f1 428 return;
hendrikvincent 0:05ccbd4f84f1 429 }
hendrikvincent 0:05ccbd4f84f1 430 ruser = (char *) inp;
hendrikvincent 0:05ccbd4f84f1 431 INCPTR(ruserlen, inp);
hendrikvincent 0:05ccbd4f84f1 432 GETCHAR(rpasswdlen, inp);
hendrikvincent 0:05ccbd4f84f1 433 if (len < rpasswdlen) {
hendrikvincent 0:05ccbd4f84f1 434 UPAPDEBUG(LOG_INFO, ("pap_rauth: rcvd short packet.\n"));
hendrikvincent 0:05ccbd4f84f1 435 return;
hendrikvincent 0:05ccbd4f84f1 436 }
hendrikvincent 0:05ccbd4f84f1 437 rpasswd = (char *) inp;
hendrikvincent 0:05ccbd4f84f1 438
hendrikvincent 0:05ccbd4f84f1 439 /*
hendrikvincent 0:05ccbd4f84f1 440 * Check the username and password given.
hendrikvincent 0:05ccbd4f84f1 441 */
hendrikvincent 0:05ccbd4f84f1 442 retcode = check_passwd(u->us_unit, ruser, ruserlen, rpasswd, rpasswdlen, &msg, &msglen);
hendrikvincent 0:05ccbd4f84f1 443 /* lwip: currently retcode is always UPAP_AUTHACK */
hendrikvincent 0:05ccbd4f84f1 444 BZERO(rpasswd, rpasswdlen);
hendrikvincent 0:05ccbd4f84f1 445
hendrikvincent 0:05ccbd4f84f1 446 upap_sresp(u, retcode, id, msg, msglen);
hendrikvincent 0:05ccbd4f84f1 447
hendrikvincent 0:05ccbd4f84f1 448 if (retcode == UPAP_AUTHACK) {
hendrikvincent 0:05ccbd4f84f1 449 u->us_serverstate = UPAPSS_OPEN;
hendrikvincent 0:05ccbd4f84f1 450 auth_peer_success(u->us_unit, PPP_PAP, ruser, ruserlen);
hendrikvincent 0:05ccbd4f84f1 451 } else {
hendrikvincent 0:05ccbd4f84f1 452 u->us_serverstate = UPAPSS_BADAUTH;
hendrikvincent 0:05ccbd4f84f1 453 auth_peer_fail(u->us_unit, PPP_PAP);
hendrikvincent 0:05ccbd4f84f1 454 }
hendrikvincent 0:05ccbd4f84f1 455
hendrikvincent 0:05ccbd4f84f1 456 if (u->us_reqtimeout > 0) {
hendrikvincent 0:05ccbd4f84f1 457 UNTIMEOUT(upap_reqtimeout, u);
hendrikvincent 0:05ccbd4f84f1 458 }
hendrikvincent 0:05ccbd4f84f1 459 }
hendrikvincent 0:05ccbd4f84f1 460
hendrikvincent 0:05ccbd4f84f1 461
hendrikvincent 0:05ccbd4f84f1 462 /*
hendrikvincent 0:05ccbd4f84f1 463 * upap_rauthack - Receive Authenticate-Ack.
hendrikvincent 0:05ccbd4f84f1 464 */
hendrikvincent 0:05ccbd4f84f1 465 static void
hendrikvincent 0:05ccbd4f84f1 466 upap_rauthack(upap_state *u, u_char *inp, int id, int len)
hendrikvincent 0:05ccbd4f84f1 467 {
hendrikvincent 0:05ccbd4f84f1 468 u_char msglen;
hendrikvincent 0:05ccbd4f84f1 469 char *msg;
hendrikvincent 0:05ccbd4f84f1 470
hendrikvincent 0:05ccbd4f84f1 471 LWIP_UNUSED_ARG(id);
hendrikvincent 0:05ccbd4f84f1 472
hendrikvincent 0:05ccbd4f84f1 473 UPAPDEBUG(LOG_INFO, ("pap_rauthack: Rcvd id %d s=%d\n", id, u->us_clientstate));
hendrikvincent 0:05ccbd4f84f1 474
hendrikvincent 0:05ccbd4f84f1 475 if (u->us_clientstate != UPAPCS_AUTHREQ) { /* XXX */
hendrikvincent 0:05ccbd4f84f1 476 UPAPDEBUG(LOG_INFO, ("pap_rauthack: us_clientstate != UPAPCS_AUTHREQ\n"));
hendrikvincent 0:05ccbd4f84f1 477 return;
hendrikvincent 0:05ccbd4f84f1 478 }
hendrikvincent 0:05ccbd4f84f1 479
hendrikvincent 0:05ccbd4f84f1 480 /*
hendrikvincent 0:05ccbd4f84f1 481 * Parse message.
hendrikvincent 0:05ccbd4f84f1 482 */
hendrikvincent 0:05ccbd4f84f1 483 if (len < (int)sizeof (u_char)) {
hendrikvincent 0:05ccbd4f84f1 484 UPAPDEBUG(LOG_INFO, ("pap_rauthack: ignoring missing msg-length.\n"));
hendrikvincent 0:05ccbd4f84f1 485 } else {
hendrikvincent 0:05ccbd4f84f1 486 GETCHAR(msglen, inp);
hendrikvincent 0:05ccbd4f84f1 487 if (msglen > 0) {
hendrikvincent 0:05ccbd4f84f1 488 len -= sizeof (u_char);
hendrikvincent 0:05ccbd4f84f1 489 if (len < msglen) {
hendrikvincent 0:05ccbd4f84f1 490 UPAPDEBUG(LOG_INFO, ("pap_rauthack: rcvd short packet.\n"));
hendrikvincent 0:05ccbd4f84f1 491 return;
hendrikvincent 0:05ccbd4f84f1 492 }
hendrikvincent 0:05ccbd4f84f1 493 msg = (char *) inp;
hendrikvincent 0:05ccbd4f84f1 494 PRINTMSG(msg, msglen);
hendrikvincent 0:05ccbd4f84f1 495 }
hendrikvincent 0:05ccbd4f84f1 496 }
hendrikvincent 0:05ccbd4f84f1 497 UNTIMEOUT(upap_timeout, u); /* Cancel timeout */
hendrikvincent 0:05ccbd4f84f1 498 u->us_clientstate = UPAPCS_OPEN;
hendrikvincent 0:05ccbd4f84f1 499
hendrikvincent 0:05ccbd4f84f1 500 auth_withpeer_success(u->us_unit, PPP_PAP);
hendrikvincent 0:05ccbd4f84f1 501 }
hendrikvincent 0:05ccbd4f84f1 502
hendrikvincent 0:05ccbd4f84f1 503
hendrikvincent 0:05ccbd4f84f1 504 /*
hendrikvincent 0:05ccbd4f84f1 505 * upap_rauthnak - Receive Authenticate-Nak.
hendrikvincent 0:05ccbd4f84f1 506 */
hendrikvincent 0:05ccbd4f84f1 507 static void
hendrikvincent 0:05ccbd4f84f1 508 upap_rauthnak(upap_state *u, u_char *inp, int id, int len)
hendrikvincent 0:05ccbd4f84f1 509 {
hendrikvincent 0:05ccbd4f84f1 510 u_char msglen;
hendrikvincent 0:05ccbd4f84f1 511 char *msg;
hendrikvincent 0:05ccbd4f84f1 512
hendrikvincent 0:05ccbd4f84f1 513 LWIP_UNUSED_ARG(id);
hendrikvincent 0:05ccbd4f84f1 514
hendrikvincent 0:05ccbd4f84f1 515 UPAPDEBUG(LOG_INFO, ("pap_rauthnak: Rcvd id %d s=%d\n", id, u->us_clientstate));
hendrikvincent 0:05ccbd4f84f1 516
hendrikvincent 0:05ccbd4f84f1 517 if (u->us_clientstate != UPAPCS_AUTHREQ) { /* XXX */
hendrikvincent 0:05ccbd4f84f1 518 return;
hendrikvincent 0:05ccbd4f84f1 519 }
hendrikvincent 0:05ccbd4f84f1 520
hendrikvincent 0:05ccbd4f84f1 521 /*
hendrikvincent 0:05ccbd4f84f1 522 * Parse message.
hendrikvincent 0:05ccbd4f84f1 523 */
hendrikvincent 0:05ccbd4f84f1 524 if (len < sizeof (u_char)) {
hendrikvincent 0:05ccbd4f84f1 525 UPAPDEBUG(LOG_INFO, ("pap_rauthnak: ignoring missing msg-length.\n"));
hendrikvincent 0:05ccbd4f84f1 526 } else {
hendrikvincent 0:05ccbd4f84f1 527 GETCHAR(msglen, inp);
hendrikvincent 0:05ccbd4f84f1 528 if(msglen > 0) {
hendrikvincent 0:05ccbd4f84f1 529 len -= sizeof (u_char);
hendrikvincent 0:05ccbd4f84f1 530 if (len < msglen) {
hendrikvincent 0:05ccbd4f84f1 531 UPAPDEBUG(LOG_INFO, ("pap_rauthnak: rcvd short packet.\n"));
hendrikvincent 0:05ccbd4f84f1 532 return;
hendrikvincent 0:05ccbd4f84f1 533 }
hendrikvincent 0:05ccbd4f84f1 534 msg = (char *) inp;
hendrikvincent 0:05ccbd4f84f1 535 PRINTMSG(msg, msglen);
hendrikvincent 0:05ccbd4f84f1 536 }
hendrikvincent 0:05ccbd4f84f1 537 }
hendrikvincent 0:05ccbd4f84f1 538
hendrikvincent 0:05ccbd4f84f1 539 u->us_clientstate = UPAPCS_BADAUTH;
hendrikvincent 0:05ccbd4f84f1 540
hendrikvincent 0:05ccbd4f84f1 541 UPAPDEBUG(LOG_ERR, ("PAP authentication failed\n"));
hendrikvincent 0:05ccbd4f84f1 542 auth_withpeer_fail(u->us_unit, PPP_PAP);
hendrikvincent 0:05ccbd4f84f1 543 }
hendrikvincent 0:05ccbd4f84f1 544
hendrikvincent 0:05ccbd4f84f1 545
hendrikvincent 0:05ccbd4f84f1 546 /*
hendrikvincent 0:05ccbd4f84f1 547 * upap_sauthreq - Send an Authenticate-Request.
hendrikvincent 0:05ccbd4f84f1 548 */
hendrikvincent 0:05ccbd4f84f1 549 static void
hendrikvincent 0:05ccbd4f84f1 550 upap_sauthreq(upap_state *u)
hendrikvincent 0:05ccbd4f84f1 551 {
hendrikvincent 0:05ccbd4f84f1 552 u_char *outp;
hendrikvincent 0:05ccbd4f84f1 553 int outlen;
hendrikvincent 0:05ccbd4f84f1 554
hendrikvincent 0:05ccbd4f84f1 555 outlen = UPAP_HEADERLEN + 2 * sizeof (u_char)
hendrikvincent 0:05ccbd4f84f1 556 + u->us_userlen + u->us_passwdlen;
hendrikvincent 0:05ccbd4f84f1 557 outp = outpacket_buf[u->us_unit];
hendrikvincent 0:05ccbd4f84f1 558
hendrikvincent 0:05ccbd4f84f1 559 MAKEHEADER(outp, PPP_PAP);
hendrikvincent 0:05ccbd4f84f1 560
hendrikvincent 0:05ccbd4f84f1 561 PUTCHAR(UPAP_AUTHREQ, outp);
hendrikvincent 0:05ccbd4f84f1 562 PUTCHAR(++u->us_id, outp);
hendrikvincent 0:05ccbd4f84f1 563 PUTSHORT(outlen, outp);
hendrikvincent 0:05ccbd4f84f1 564 PUTCHAR(u->us_userlen, outp);
hendrikvincent 0:05ccbd4f84f1 565 BCOPY(u->us_user, outp, u->us_userlen);
hendrikvincent 0:05ccbd4f84f1 566 INCPTR(u->us_userlen, outp);
hendrikvincent 0:05ccbd4f84f1 567 PUTCHAR(u->us_passwdlen, outp);
hendrikvincent 0:05ccbd4f84f1 568 BCOPY(u->us_passwd, outp, u->us_passwdlen);
hendrikvincent 0:05ccbd4f84f1 569
hendrikvincent 0:05ccbd4f84f1 570 pppWrite(u->us_unit, outpacket_buf[u->us_unit], outlen + PPP_HDRLEN);
hendrikvincent 0:05ccbd4f84f1 571
hendrikvincent 0:05ccbd4f84f1 572 UPAPDEBUG(LOG_INFO, ("pap_sauth: Sent id %d\n", u->us_id));
hendrikvincent 0:05ccbd4f84f1 573
hendrikvincent 0:05ccbd4f84f1 574 TIMEOUT(upap_timeout, u, u->us_timeouttime);
hendrikvincent 0:05ccbd4f84f1 575 ++u->us_transmits;
hendrikvincent 0:05ccbd4f84f1 576 u->us_clientstate = UPAPCS_AUTHREQ;
hendrikvincent 0:05ccbd4f84f1 577 }
hendrikvincent 0:05ccbd4f84f1 578
hendrikvincent 0:05ccbd4f84f1 579
hendrikvincent 0:05ccbd4f84f1 580 /*
hendrikvincent 0:05ccbd4f84f1 581 * upap_sresp - Send a response (ack or nak).
hendrikvincent 0:05ccbd4f84f1 582 */
hendrikvincent 0:05ccbd4f84f1 583 static void
hendrikvincent 0:05ccbd4f84f1 584 upap_sresp(upap_state *u, u_char code, u_char id, char *msg, int msglen)
hendrikvincent 0:05ccbd4f84f1 585 {
hendrikvincent 0:05ccbd4f84f1 586 u_char *outp;
hendrikvincent 0:05ccbd4f84f1 587 int outlen;
hendrikvincent 0:05ccbd4f84f1 588
hendrikvincent 0:05ccbd4f84f1 589 outlen = UPAP_HEADERLEN + sizeof (u_char) + msglen;
hendrikvincent 0:05ccbd4f84f1 590 outp = outpacket_buf[u->us_unit];
hendrikvincent 0:05ccbd4f84f1 591 MAKEHEADER(outp, PPP_PAP);
hendrikvincent 0:05ccbd4f84f1 592
hendrikvincent 0:05ccbd4f84f1 593 PUTCHAR(code, outp);
hendrikvincent 0:05ccbd4f84f1 594 PUTCHAR(id, outp);
hendrikvincent 0:05ccbd4f84f1 595 PUTSHORT(outlen, outp);
hendrikvincent 0:05ccbd4f84f1 596 PUTCHAR(msglen, outp);
hendrikvincent 0:05ccbd4f84f1 597 BCOPY(msg, outp, msglen);
hendrikvincent 0:05ccbd4f84f1 598 pppWrite(u->us_unit, outpacket_buf[u->us_unit], outlen + PPP_HDRLEN);
hendrikvincent 0:05ccbd4f84f1 599
hendrikvincent 0:05ccbd4f84f1 600 UPAPDEBUG(LOG_INFO, ("pap_sresp: Sent code %d, id %d s=%d\n", code, id, u->us_clientstate));
hendrikvincent 0:05ccbd4f84f1 601 }
hendrikvincent 0:05ccbd4f84f1 602
hendrikvincent 0:05ccbd4f84f1 603 #if PPP_ADDITIONAL_CALLBACKS
hendrikvincent 0:05ccbd4f84f1 604 static char *upap_codenames[] = {
hendrikvincent 0:05ccbd4f84f1 605 "AuthReq", "AuthAck", "AuthNak"
hendrikvincent 0:05ccbd4f84f1 606 };
hendrikvincent 0:05ccbd4f84f1 607
hendrikvincent 0:05ccbd4f84f1 608 /*
hendrikvincent 0:05ccbd4f84f1 609 * upap_printpkt - print the contents of a PAP packet.
hendrikvincent 0:05ccbd4f84f1 610 */
hendrikvincent 0:05ccbd4f84f1 611 static int upap_printpkt(
hendrikvincent 0:05ccbd4f84f1 612 u_char *p,
hendrikvincent 0:05ccbd4f84f1 613 int plen,
hendrikvincent 0:05ccbd4f84f1 614 void (*printer) (void *, char *, ...),
hendrikvincent 0:05ccbd4f84f1 615 void *arg
hendrikvincent 0:05ccbd4f84f1 616 )
hendrikvincent 0:05ccbd4f84f1 617 {
hendrikvincent 0:05ccbd4f84f1 618 LWIP_UNUSED_ARG(p);
hendrikvincent 0:05ccbd4f84f1 619 LWIP_UNUSED_ARG(plen);
hendrikvincent 0:05ccbd4f84f1 620 LWIP_UNUSED_ARG(printer);
hendrikvincent 0:05ccbd4f84f1 621 LWIP_UNUSED_ARG(arg);
hendrikvincent 0:05ccbd4f84f1 622 return 0;
hendrikvincent 0:05ccbd4f84f1 623 }
hendrikvincent 0:05ccbd4f84f1 624 #endif /* PPP_ADDITIONAL_CALLBACKS */
hendrikvincent 0:05ccbd4f84f1 625
hendrikvincent 0:05ccbd4f84f1 626 #endif /* PAP_SUPPORT */
hendrikvincent 0:05ccbd4f84f1 627
hendrikvincent 0:05ccbd4f84f1 628 #endif /* PPP_SUPPORT */