Integrating the ublox LISA C200 modem

Fork of SprintUSBModemHTTPClientTest by Donatien Garnier

Committer:
sam_grove
Date:
Thu Sep 26 00:44:20 2013 -0500
Revision:
5:3f93dd1d4cb3
Exported program and replaced contents of the repo with the source
to build and debug using keil mdk. Libs NOT upto date are lwip, lwip-sys
and socket. these have newer versions under mbed_official but were starting
from a know working point

Who changed what in which revision?

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