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