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