2 * lcp.c - PPP Link Control Protocol.
4 * Copyright (c) 1989 Carnegie Mellon University.
7 * Redistribution and use in source and binary forms are permitted
8 * provided that the above copyright notice and this paragraph are
9 * duplicated in all such forms and that any documentation,
10 * advertising materials, and other materials related to such
11 * distribution and use acknowledge that the software was developed
12 * by Carnegie Mellon University. The name of the
13 * University may not be used to endorse or promote products derived
14 * from this software without specific prior written permission.
15 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
17 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
20 #define RCSID "$Id: lcp.c,v 1.5 2006/11/24 03:33:52 andylin Exp $"
40 static const char rcsid[] = RCSID;
42 /*wilson add for MS-CHAPv2, 05/26/2005*/
43 extern bool refuse_chap;
47 * When the link comes up we want to be able to wait for a short while,
48 * or until seeing some input from the peer, before starting to send
49 * configure-requests. We do this by delaying the fsm_lowerup call.
51 /* steal a bit in fsm flags word */
52 #define DELAYED_UP 0x100
54 static void lcp_delayed_up __P((void *));
57 * LCP-related command-line options.
59 //Charles 09/01/2003, original=5, 5, 3
60 static int idle_for_echo=10;
61 //int lcp_echo_interval = 10; /* Interval between LCP echo-requests */
62 int lcp_echo_interval = 20;
63 int lcp_echo_fails = 6; /* Tolerance to unanswered echo-requests */
64 //int lcp_echo_interval = 0; /* Interval between LCP echo-requests */
65 //int lcp_echo_fails = 0; /* Tolerance to unanswered echo-requests */
66 bool lax_recv = 0; /* accept control chars in asyncmap */
67 bool noendpoint = 0; /* don't send/accept endpoint discriminator */
70 #if defined(INCLUDE_MTU_LAN_PPP)
71 extern glb_CONFIG_PPP_MTU;
74 extern int ppp_session; //andy add
76 static int noopt __P((char **));
79 static int setendpoint __P((char **));
80 static void printendpoint __P((option_t *, void (*)(void *, char *, ...),
82 #endif /* HAVE_MULTILINK */
84 static option_t lcp_option_list[] = {
86 { "-all", o_special_noarg, (void *)noopt,
87 "Don't request/allow any LCP options" },
89 { "noaccomp", o_bool, &lcp_wantoptions[0].neg_accompression,
90 "Disable address/control compression",
91 OPT_A2CLR, &lcp_allowoptions[0].neg_accompression },
92 { "-ac", o_bool, &lcp_wantoptions[0].neg_accompression,
93 "Disable address/control compression",
94 OPT_ALIAS | OPT_A2CLR, &lcp_allowoptions[0].neg_accompression },
96 { "asyncmap", o_uint32, &lcp_wantoptions[0].asyncmap,
97 "Set asyncmap (for received packets)",
98 OPT_OR, &lcp_wantoptions[0].neg_asyncmap },
99 { "-as", o_uint32, &lcp_wantoptions[0].asyncmap,
100 "Set asyncmap (for received packets)",
101 OPT_ALIAS | OPT_OR, &lcp_wantoptions[0].neg_asyncmap },
102 { "default-asyncmap", o_uint32, &lcp_wantoptions[0].asyncmap,
103 "Disable asyncmap negotiation",
104 OPT_OR | OPT_NOARG | OPT_VAL(~0U) | OPT_A2CLR,
105 &lcp_allowoptions[0].neg_asyncmap },
106 { "-am", o_uint32, &lcp_wantoptions[0].asyncmap,
107 "Disable asyncmap negotiation",
108 OPT_ALIAS | OPT_OR | OPT_NOARG | OPT_VAL(~0U) | OPT_A2CLR,
109 &lcp_allowoptions[0].neg_asyncmap },
111 { "nomagic", o_bool, &lcp_wantoptions[0].neg_magicnumber,
112 "Disable magic number negotiation (looped-back line detection)",
113 OPT_A2CLR, &lcp_allowoptions[0].neg_magicnumber },
114 { "-mn", o_bool, &lcp_wantoptions[0].neg_magicnumber,
115 "Disable magic number negotiation (looped-back line detection)",
116 OPT_ALIAS | OPT_A2CLR, &lcp_allowoptions[0].neg_magicnumber },
118 { "mru", o_int, &lcp_wantoptions[0].mru,
119 "Set MRU (maximum received packet size) for negotiation",
120 OPT_PRIO, &lcp_wantoptions[0].neg_mru },
121 { "default-mru", o_bool, &lcp_wantoptions[0].neg_mru,
122 "Disable MRU negotiation (use default 1500)",
123 OPT_PRIOSUB | OPT_A2CLR, &lcp_allowoptions[0].neg_mru },
124 { "-mru", o_bool, &lcp_wantoptions[0].neg_mru,
125 "Disable MRU negotiation (use default 1500)",
126 OPT_ALIAS | OPT_PRIOSUB | OPT_A2CLR, &lcp_allowoptions[0].neg_mru },
128 { "mtu", o_int, &lcp_allowoptions[0].mru,
129 "Set our MTU", OPT_LIMITS, NULL, MAXMRU, MINMRU },
131 { "nopcomp", o_bool, &lcp_wantoptions[0].neg_pcompression,
132 "Disable protocol field compression",
133 OPT_A2CLR, &lcp_allowoptions[0].neg_pcompression },
134 { "-pc", o_bool, &lcp_wantoptions[0].neg_pcompression,
135 "Disable protocol field compression",
136 OPT_ALIAS | OPT_A2CLR, &lcp_allowoptions[0].neg_pcompression },
138 { "passive", o_bool, &lcp_wantoptions[0].passive,
139 "Set passive mode", 1 },
140 { "-p", o_bool, &lcp_wantoptions[0].passive,
141 "Set passive mode", OPT_ALIAS | 1 },
143 { "silent", o_bool, &lcp_wantoptions[0].silent,
144 "Set silent mode", 1 },
146 { "lcp-echo-failure", o_int, &lcp_echo_fails,
147 "Set number of consecutive echo failures to indicate link failure",
149 { "lcp-echo-interval", o_int, &lcp_echo_interval,
150 "Set time in seconds between LCP echo requests", OPT_PRIO },
151 { "lcp-restart", o_int, &lcp_fsm[0].timeouttime,
152 "Set time in seconds between LCP retransmissions", OPT_PRIO },
153 { "lcp-max-terminate", o_int, &lcp_fsm[0].maxtermtransmits,
154 "Set maximum number of LCP terminate-request transmissions", OPT_PRIO },
155 { "lcp-max-configure", o_int, &lcp_fsm[0].maxconfreqtransmits,
156 "Set maximum number of LCP configure-request transmissions", OPT_PRIO },
157 { "lcp-max-failure", o_int, &lcp_fsm[0].maxnakloops,
158 "Set limit on number of LCP configure-naks", OPT_PRIO },
160 { "receive-all", o_bool, &lax_recv,
161 "Accept all received control characters", 1 },
163 #ifdef HAVE_MULTILINK
164 { "mrru", o_int, &lcp_wantoptions[0].mrru,
165 "Maximum received packet size for multilink bundle",
166 OPT_PRIO, &lcp_wantoptions[0].neg_mrru },
168 { "mpshortseq", o_bool, &lcp_wantoptions[0].neg_ssnhf,
169 "Use short sequence numbers in multilink headers",
170 OPT_PRIO | 1, &lcp_allowoptions[0].neg_ssnhf },
171 { "nompshortseq", o_bool, &lcp_wantoptions[0].neg_ssnhf,
172 "Don't use short sequence numbers in multilink headers",
173 OPT_PRIOSUB | OPT_A2CLR, &lcp_allowoptions[0].neg_ssnhf },
175 { "endpoint", o_special, (void *) setendpoint,
176 "Endpoint discriminator for multilink",
177 OPT_PRIO | OPT_A2PRINTER, (void *) printendpoint },
178 #endif /* HAVE_MULTILINK */
180 { "noendpoint", o_bool, &noendpoint,
181 "Don't send or accept multilink endpoint discriminator", 1 },
187 fsm lcp_fsm[NUM_PPP]; /* LCP fsm structure (global)*/
188 lcp_options lcp_wantoptions[NUM_PPP]; /* Options that we want to request */
189 lcp_options lcp_gotoptions[NUM_PPP]; /* Options that peer ack'd */
190 lcp_options lcp_allowoptions[NUM_PPP]; /* Options we allow peer to request */
191 lcp_options lcp_hisoptions[NUM_PPP]; /* Options that we ack'd */
193 static int lcp_echos_pending = 0; /* Number of outstanding echo msgs */
194 static int lcp_echo_number = 0; /* ID number of next echo frame */
195 static int lcp_echo_timer_running = 0; /* set if a timer is running */
197 static u_char nak_buffer[PPP_MRU]; /* where we construct a nak packet */
200 * Callbacks for fsm code. (CI = Configuration Information)
202 static void lcp_resetci __P((fsm *)); /* Reset our CI */
203 static int lcp_cilen __P((fsm *)); /* Return length of our CI */
204 static void lcp_addci __P((fsm *, u_char *, int *)); /* Add our CI to pkt */
205 static int lcp_ackci __P((fsm *, u_char *, int)); /* Peer ack'd our CI */
206 static int lcp_nakci __P((fsm *, u_char *, int)); /* Peer nak'd our CI */
207 static int lcp_rejci __P((fsm *, u_char *, int)); /* Peer rej'd our CI */
208 static int lcp_reqci __P((fsm *, u_char *, int *, int)); /* Rcv peer CI */
209 static void lcp_up __P((fsm *)); /* We're UP */
210 static void lcp_down __P((fsm *)); /* We're DOWN */
211 static void lcp_starting __P((fsm *)); /* We need lower layer up */
212 static void lcp_finished __P((fsm *)); /* We need lower layer down */
213 static int lcp_extcode __P((fsm *, int, int, u_char *, int));
214 static void lcp_rprotrej __P((fsm *, u_char *, int));
217 * routines to send LCP echos to peer
220 static void lcp_echo_lowerup __P((int));
221 static void lcp_echo_lowerdown __P((int));
222 static void LcpEchoTimeout __P((void *));
223 static void lcp_received_echo_reply __P((fsm *, int, u_char *, int));
224 static void LcpSendEchoRequest __P((fsm *));
225 static void LcpLinkFailure __P((fsm *));
226 static void LcpEchoCheck __P((fsm *));
228 static fsm_callbacks lcp_callbacks = { /* LCP callback routines */
229 lcp_resetci, /* Reset our Configuration Information */
230 lcp_cilen, /* Length of our Configuration Information */
231 lcp_addci, /* Add our Configuration Information */
232 lcp_ackci, /* ACK our Configuration Information */
233 lcp_nakci, /* NAK our Configuration Information */
234 lcp_rejci, /* Reject our Configuration Information */
235 lcp_reqci, /* Request peer's Configuration Information */
236 lcp_up, /* Called when fsm reaches OPENED state */
237 lcp_down, /* Called when fsm leaves OPENED state */
238 lcp_starting, /* Called when we want the lower layer up */
239 lcp_finished, /* Called when we want the lower layer down */
240 NULL, /* Called when Protocol-Reject received */
241 NULL, /* Retransmission is necessary */
242 lcp_extcode, /* Called to handle LCP-specific codes */
243 "LCP" /* String name of protocol */
247 * Protocol entry points.
248 * Some of these are called directly.
251 static void lcp_init __P((int));
252 static void lcp_input __P((int, u_char *, int));
253 static void lcp_protrej __P((int));
254 static int lcp_printpkt __P((u_char *, int,
255 void (*) __P((void *, char *, ...)), void *));
257 struct protent lcp_protent = {
277 int lcp_loopbackfail = DEFLOOPBACKFAIL;
280 * Length of each type of configuration option (in octets)
284 #define CILEN_SHORT 4 /* CILEN_VOID + 2 */
285 #define CILEN_CHAP 5 /* CILEN_VOID + 2 + 1 */
286 #define CILEN_LONG 6 /* CILEN_VOID + 4 */
287 #define CILEN_LQR 8 /* CILEN_VOID + 2 + 4 */
290 #define CODENAME(x) ((x) == CONFACK ? "ACK" : \
291 (x) == CONFNAK ? "NAK" : "REJ")
294 * noopt - Disable all options (why?).
300 BZERO((char *) &lcp_wantoptions[0], sizeof (struct lcp_options));
301 BZERO((char *) &lcp_allowoptions[0], sizeof (struct lcp_options));
306 #ifdef HAVE_MULTILINK
311 if (str_to_epdisc(&lcp_wantoptions[0].endpoint, *argv)) {
312 lcp_wantoptions[0].neg_endpoint = 1;
315 option_error("Can't parse '%s' as an endpoint discriminator", *argv);
320 printendpoint(opt, printer, arg)
322 void (*printer) __P((void *, char *, ...));
325 printer(arg, "%s", epdisc_to_str(&lcp_wantoptions[0].endpoint));
327 #endif /* HAVE_MULTILINK */
330 * lcp_init - Initialize LCP.
336 fsm *f = &lcp_fsm[unit];
337 lcp_options *wo = &lcp_wantoptions[unit];
338 lcp_options *ao = &lcp_allowoptions[unit];
341 f->protocol = PPP_LCP;
342 f->callbacks = &lcp_callbacks;
346 BZERO(wo, sizeof(*wo));
349 wo->neg_asyncmap = 1;
350 /*wilson modify for MS-CHAPv2, 05/26/2005*/
351 //wo->chap_mdtype = CHAP_DIGEST_MD5;
354 if(wo->use_chapms_v2)
355 wo->chap_mdtype = CHAP_MICROSOFT_V2;
356 else if(wo->use_chapms)
357 wo->chap_mdtype = CHAP_MICROSOFT;
361 wo->chap_mdtype = CHAP_DIGEST_MD5;
364 /*wilson modify end*/
365 wo->neg_magicnumber = 1;
366 wo->neg_pcompression = 1;
367 wo->neg_accompression = 1;
369 BZERO(ao, sizeof(*ao));
372 ao->neg_asyncmap = 1;
374 /*wilson modify for MS-CHAPv2, 05/26/2005*/
375 //ao->chap_mdtype = CHAP_DIGEST_MD5;
378 ao->use_chapms_v2 = ao->use_chapms = 1;
379 if(ao->use_chapms_v2)
380 ao->chap_mdtype = CHAP_MICROSOFT_V2;
381 else if(ao->use_chapms)
382 ao->chap_mdtype = CHAP_MICROSOFT;
386 ao->chap_mdtype = CHAP_DIGEST_MD5;
390 /*wilson modify end*/
392 ao->neg_magicnumber = 1;
393 ao->neg_pcompression = 1;
394 ao->neg_accompression = 1;
398 ao->neg_endpoint = 1;
404 * lcp_open - LCP is allowed to come up.
410 fsm *f = &lcp_fsm[unit];
411 lcp_options *wo = &lcp_wantoptions[unit];
412 lcp_options *ao = &lcp_allowoptions[unit];
423 ao->chap_mdtype = CHAP_DIGEST_MD5;
427 ao->chap_mdtype = CHAP_MICROSOFT;
429 else if (opflag==2) {
432 ao->chap_mdtype = CHAP_DIGEST_MD5;
434 else if (opflag==1) {
438 else if (opflag==0) {
447 f->flags &= ~(OPT_PASSIVE | OPT_SILENT);
449 f->flags |= OPT_PASSIVE;
451 f->flags |= OPT_SILENT;
457 * lcp_close - Take LCP down.
460 lcp_close(unit, reason)
464 fsm *f = &lcp_fsm[unit];
466 if (phase != PHASE_DEAD)
467 new_phase(PHASE_TERMINATE);
468 if (f->state == STOPPED && f->flags & (OPT_PASSIVE|OPT_SILENT)) {
470 * This action is not strictly according to the FSM in RFC1548,
471 * but it does mean that the program terminates if you do a
472 * lcp_close() in passive/silent mode when a connection hasn't
479 fsm_close(&lcp_fsm[unit], reason);
486 * lcp_lowerup - The lower layer is up.
492 lcp_options *wo = &lcp_wantoptions[unit];
493 fsm *f = &lcp_fsm[unit];
496 * Don't use A/C or protocol compression on transmission,
497 * but accept A/C and protocol compressed packets
498 * if we are going to ask for A/C and protocol compression.
500 ppp_send_config(unit, PPP_MRU, 0xffffffff, 0, 0);
501 ppp_recv_config(unit, PPP_MRU, (lax_recv? 0: 0xffffffff), wo->neg_pcompression, wo->neg_accompression);
502 peer_mru[unit] = PPP_MRU;
504 if (listen_time != 0) {
505 f->flags |= DELAYED_UP;
506 timeout(lcp_delayed_up, f, 0, listen_time * 1000);
513 * lcp_lowerdown - The lower layer is down.
519 fsm *f = &lcp_fsm[unit];
521 if (f->flags & DELAYED_UP)
522 f->flags &= ~DELAYED_UP;
524 fsm_lowerdown(&lcp_fsm[unit]);
529 * lcp_delayed_up - Bring the lower layer up now.
537 if (f->flags & DELAYED_UP) {
538 f->flags &= ~DELAYED_UP;
545 * lcp_input - Input LCP packet.
548 lcp_input(unit, p, len)
553 fsm *f = &lcp_fsm[unit];
555 if (f->flags & DELAYED_UP) {
556 f->flags &= ~DELAYED_UP;
559 fsm_input(f, p, len);
564 * lcp_extcode - Handle a LCP-specific code.
567 lcp_extcode(f, code, id, inp, len)
577 lcp_rprotrej(f, inp, len);
581 if (f->state != OPENED)
584 PUTLONG(lcp_gotoptions[f->unit].magicnumber, magp);
585 fsm_sdata(f, ECHOREP, id, inp, len);
589 lcp_received_echo_reply(f, id, inp, len);
603 * lcp_rprotrej - Receive an Protocol-Reject.
605 * Figure out which protocol is rejected and inform it.
608 lcp_rprotrej(f, inp, len)
614 struct protent *protp;
618 LCPDEBUG(("lcp_rprotrej: Rcvd short Protocol-Reject packet!"));
625 * Protocol-Reject packets received in any state other than the LCP
626 * OPENED state SHOULD be silently discarded.
628 if( f->state != OPENED ){
629 LCPDEBUG(("Protocol-Reject discarded: LCP in state %d", f->state));
634 * Upcall the proper Protocol-Reject routine.
636 for (i = 0; (protp = protocols[i]) != NULL; ++i)
637 if (protp->protocol == prot && protp->enabled_flag) {
638 (*protp->protrej)(f->unit);
642 warn("Protocol-Reject for unsupported protocol 0x%x", prot);
647 * lcp_protrej - A Protocol-Reject was received.
657 error("Received Protocol-Reject for LCP!");
658 fsm_protreject(&lcp_fsm[unit]);
663 * lcp_sprotrej - Send a Protocol-Reject for some protocol.
666 lcp_sprotrej(unit, p, len)
672 * Send back the protocol and the information field of the
673 * rejected packet. We only get here if LCP is in the OPENED state.
678 fsm_sdata(&lcp_fsm[unit], PROTREJ, ++lcp_fsm[unit].id, p, len);
683 * lcp_resetci - Reset our CI.
689 lcp_options *wo = &lcp_wantoptions[f->unit];
690 lcp_options *go = &lcp_gotoptions[f->unit];
691 lcp_options *ao = &lcp_allowoptions[f->unit];
693 wo->magicnumber = magic();
696 if (ppp_session == PPPOA)//Andy modify
705 go->neg_endpoint = 0;
708 ao->neg_endpoint = 0;
709 peer_mru[f->unit] = PPP_MRU;
711 //auth_reset(f->unit);
716 * lcp_cilen - Return length of our CI.
722 lcp_options *go = &lcp_gotoptions[f->unit];
724 #define LENCIVOID(neg) ((neg) ? CILEN_VOID : 0)
725 #define LENCICHAP(neg) ((neg) ? CILEN_CHAP : 0)
726 #define LENCISHORT(neg) ((neg) ? CILEN_SHORT : 0)
727 #define LENCILONG(neg) ((neg) ? CILEN_LONG : 0)
728 #define LENCILQR(neg) ((neg) ? CILEN_LQR: 0)
729 #define LENCICBCP(neg) ((neg) ? CILEN_CBCP: 0)
731 * NB: we only ask for one of CHAP and UPAP, even if we will
734 /*wilson add for MS-CHAPv2, 05/26/2005*/
736 if(go->use_chapms_v2)
737 go->chap_mdtype = CHAP_MICROSOFT_V2;
738 else if(go->use_chapms)
739 go->chap_mdtype = CHAP_MICROSOFT;
743 go->chap_mdtype = CHAP_DIGEST_MD5;
748 return (LENCISHORT(go->neg_mru /*&& go->mru != DEFMRU //andy modify it*/) +
749 LENCILONG(go->neg_asyncmap && go->asyncmap != 0xFFFFFFFF) +
750 LENCICHAP(go->neg_chap) +
751 LENCISHORT(!go->neg_chap && go->neg_upap) +
752 LENCILQR(go->neg_lqr) +
753 LENCICBCP(go->neg_cbcp) +
754 LENCILONG(go->neg_magicnumber) +
755 LENCIVOID(go->neg_pcompression) +
756 LENCIVOID(go->neg_accompression) +
757 LENCISHORT(go->neg_mrru) +
758 LENCIVOID(go->neg_ssnhf) +
759 (go->neg_endpoint? CILEN_CHAR + go->endpoint.length: 0));
764 * lcp_addci - Add our desired CIs to a packet.
767 lcp_addci(f, ucp, lenp)
772 lcp_options *go = &lcp_gotoptions[f->unit];
773 u_char *start_ucp = ucp;
774 #define ADDCIVOID(opt, neg) \
777 PUTCHAR(CILEN_VOID, ucp); \
779 #define ADDCISHORT(opt, neg, val) \
782 PUTCHAR(CILEN_SHORT, ucp); \
783 PUTSHORT(val, ucp); \
785 #define ADDCICHAP(opt, neg, val, digest) \
788 PUTCHAR(CILEN_CHAP, ucp); \
789 PUTSHORT(val, ucp); \
790 PUTCHAR(digest, ucp); \
792 #define ADDCILONG(opt, neg, val) \
795 PUTCHAR(CILEN_LONG, ucp); \
798 #define ADDCILQR(opt, neg, val) \
801 PUTCHAR(CILEN_LQR, ucp); \
802 PUTSHORT(PPP_LQR, ucp); \
805 #define ADDCICHAR(opt, neg, val) \
808 PUTCHAR(CILEN_CHAR, ucp); \
811 #define ADDCIENDP(opt, neg, class, val, len) \
815 PUTCHAR(CILEN_CHAR + len, ucp); \
816 PUTCHAR(class, ucp); \
817 for (i = 0; i < len; ++i) \
818 PUTCHAR(val[i], ucp); \
820 //go->mru = lcp_allowoptions[0].mru;
822 //ADDCISHORT(CI_MRU, go->neg_mru && go->mru != DEFMRU, go->mru);
823 ADDCISHORT(CI_MRU, go->neg_mru, go->mru);
824 ADDCILONG(CI_ASYNCMAP, go->neg_asyncmap && go->asyncmap != 0xFFFFFFFF,
826 ADDCICHAP(CI_AUTHTYPE, go->neg_chap, PPP_CHAP, go->chap_mdtype);
827 ADDCISHORT(CI_AUTHTYPE, !go->neg_chap && go->neg_upap, PPP_PAP);
828 ADDCILQR(CI_QUALITY, go->neg_lqr, go->lqr_period);
829 ADDCICHAR(CI_CALLBACK, go->neg_cbcp, CBCP_OPT);
830 ADDCILONG(CI_MAGICNUMBER, go->neg_magicnumber, go->magicnumber);
831 ADDCIVOID(CI_PCOMPRESSION, go->neg_pcompression);
832 ADDCIVOID(CI_ACCOMPRESSION, go->neg_accompression);
833 ADDCISHORT(CI_MRRU, go->neg_mrru, go->mrru);
834 ADDCIVOID(CI_SSNHF, go->neg_ssnhf);
835 ADDCIENDP(CI_EPDISC, go->neg_endpoint, go->endpoint.class,
836 go->endpoint.value, go->endpoint.length);
838 if (ucp - start_ucp != *lenp) {
839 /* this should never happen, because peer_mtu should be 1500 */
840 printf("Bug in lcp_addci: wrong length\n");
841 error("Bug in lcp_addci: wrong length");
847 * lcp_ackci - Ack our CIs.
848 * This should not modify any state if the Ack is bad.
860 lcp_options *go = &lcp_gotoptions[f->unit];
861 u_char cilen, citype, cichar;
866 * CIs must be in exactly the same order that we sent.
867 * Check packet length and CI length at each step.
868 * If we find any deviations, then this packet is bad.
870 #define ACKCIVOID(opt, neg) \
872 if ((len -= CILEN_VOID) < 0) \
874 GETCHAR(citype, p); \
876 if (cilen != CILEN_VOID || \
880 #define ACKCISHORT(opt, neg, val) \
882 if ((len -= CILEN_SHORT) < 0) \
884 GETCHAR(citype, p); \
886 if (cilen != CILEN_SHORT || \
889 GETSHORT(cishort, p); \
890 if (cishort != val) \
893 #define ACKCICHAR(opt, neg, val) \
895 if ((len -= CILEN_CHAR) < 0) \
897 GETCHAR(citype, p); \
899 if (cilen != CILEN_CHAR || \
902 GETCHAR(cichar, p); \
906 #define ACKCICHAP(opt, neg, val, digest) \
908 if ((len -= CILEN_CHAP) < 0) \
910 GETCHAR(citype, p); \
912 if (cilen != CILEN_CHAP || \
915 GETSHORT(cishort, p); \
916 if (cishort != val) \
918 GETCHAR(cichar, p); \
919 if (cichar != digest) \
922 #define ACKCILONG(opt, neg, val) \
924 if ((len -= CILEN_LONG) < 0) \
926 GETCHAR(citype, p); \
928 if (cilen != CILEN_LONG || \
931 GETLONG(cilong, p); \
935 #define ACKCILQR(opt, neg, val) \
937 if ((len -= CILEN_LQR) < 0) \
939 GETCHAR(citype, p); \
941 if (cilen != CILEN_LQR || \
944 GETSHORT(cishort, p); \
945 if (cishort != PPP_LQR) \
947 GETLONG(cilong, p); \
951 #define ACKCIENDP(opt, neg, class, val, vlen) \
954 if ((len -= CILEN_CHAR + vlen) < 0) \
956 GETCHAR(citype, p); \
958 if (cilen != CILEN_CHAR + vlen || \
961 GETCHAR(cichar, p); \
962 if (cichar != class) \
964 for (i = 0; i < vlen; ++i) { \
965 GETCHAR(cichar, p); \
966 if (cichar != val[i]) \
971 //ACKCISHORT(CI_MRU, go->neg_mru && go->mru != DEFMRU, go->mru);
972 ACKCISHORT(CI_MRU, go->neg_mru, go->mru);
973 ACKCILONG(CI_ASYNCMAP, go->neg_asyncmap && go->asyncmap != 0xFFFFFFFF,
975 ACKCICHAP(CI_AUTHTYPE, go->neg_chap, PPP_CHAP, go->chap_mdtype);
976 ACKCISHORT(CI_AUTHTYPE, !go->neg_chap && go->neg_upap, PPP_PAP);
977 ACKCILQR(CI_QUALITY, go->neg_lqr, go->lqr_period);
978 ACKCICHAR(CI_CALLBACK, go->neg_cbcp, CBCP_OPT);
979 ACKCILONG(CI_MAGICNUMBER, go->neg_magicnumber, go->magicnumber);
980 ACKCIVOID(CI_PCOMPRESSION, go->neg_pcompression);
981 ACKCIVOID(CI_ACCOMPRESSION, go->neg_accompression);
982 ACKCISHORT(CI_MRRU, go->neg_mrru, go->mrru);
983 ACKCIVOID(CI_SSNHF, go->neg_ssnhf);
984 ACKCIENDP(CI_EPDISC, go->neg_endpoint, go->endpoint.class,
985 go->endpoint.value, go->endpoint.length);
988 * If there are any remaining CIs, then this packet is bad.
994 LCPDEBUG(("lcp_acki: received bad Ack!"));
1000 * lcp_nakci - Peer has sent a NAK for some of our CIs.
1001 * This should not modify any state if the Nak is bad
1002 * or if LCP is in the OPENED state.
1009 lcp_nakci(f, p, len)
1014 lcp_options *go = &lcp_gotoptions[f->unit];
1015 lcp_options *wo = &lcp_wantoptions[f->unit];
1016 lcp_options *ho = &lcp_hisoptions[f->unit];//andy add
1017 u_char citype, cichar, *next;
1020 lcp_options no; /* options we've seen Naks for */
1021 lcp_options try; /* options to request next time */
1022 int looped_back = 0;
1024 BZERO(&no, sizeof(no));
1027 * Any Nak'd CIs must be in exactly the same order that we sent.
1028 * Check packet length and CI length at each step.
1029 * If we find any deviations, then this packet is bad.
1031 #define NAKCIVOID(opt, neg) \
1033 len >= CILEN_VOID && \
1034 p[1] == CILEN_VOID && \
1036 len -= CILEN_VOID; \
1037 INCPTR(CILEN_VOID, p); \
1041 #define NAKCICHAP(opt, neg, code) \
1043 len >= CILEN_CHAP && \
1044 p[1] == CILEN_CHAP && \
1046 len -= CILEN_CHAP; \
1048 GETSHORT(cishort, p); \
1049 GETCHAR(cichar, p); \
1053 #define NAKCICHAR(opt, neg, code) \
1055 len >= CILEN_CHAR && \
1056 p[1] == CILEN_CHAR && \
1058 len -= CILEN_CHAR; \
1060 GETCHAR(cichar, p); \
1064 #define NAKCISHORT(opt, neg, code) \
1066 len >= CILEN_SHORT && \
1067 p[1] == CILEN_SHORT && \
1069 len -= CILEN_SHORT; \
1071 GETSHORT(cishort, p); \
1075 #define NAKCILONG(opt, neg, code) \
1077 len >= CILEN_LONG && \
1078 p[1] == CILEN_LONG && \
1080 len -= CILEN_LONG; \
1082 GETLONG(cilong, p); \
1086 #define NAKCILQR(opt, neg, code) \
1088 len >= CILEN_LQR && \
1089 p[1] == CILEN_LQR && \
1093 GETSHORT(cishort, p); \
1094 GETLONG(cilong, p); \
1098 #define NAKCIENDP(opt, neg) \
1100 len >= CILEN_CHAR && \
1102 p[1] >= CILEN_CHAR && \
1111 * We don't care if they want to send us smaller packets than
1112 * we want. Therefore, accept any MRU less than what we asked for,
1113 * but then ignore the new value when setting the MRU in the kernel.
1114 * If they send us a bigger MRU than what we asked, accept it, up to
1115 * the limit of the default MRU we'd get if we didn't negotiate.
1117 if (go->neg_mru /*&& go->mru != DEFMRU */) {
1118 //lcp_allowoptions[0].mru = wo->mru;//andy add
1119 //go->mru = wo->mru;//andy add
1121 if (ho->mru != 0){//andy add
1122 lcp_allowoptions[0].mru = ho->mru;
1124 //lcp_allowoptions[0].mru = DEFMRU;
1125 if (wo->neg_mru == 1 && wo->mru != 0)
1126 lcp_allowoptions[0].mru = wo->mru;
1128 lcp_allowoptions[0].mru = DEFMRU;
1131 NAKCISHORT(CI_MRU, neg_mru,
1132 if (cishort <= wo->mru || cishort <= DEFMRU)
1136 /* Start andy add */
1137 if (cishort > 0 && cishort <= DEFMRU){
1138 lcp_allowoptions[0].mru = cishort;
1141 lcp_allowoptions[0].mru = ho->mru;
1143 if (wo->neg_mru == 1 && wo->mru != 0)
1144 lcp_allowoptions[0].mru = wo->mru;
1146 lcp_allowoptions[0].mru = DEFMRU;
1154 * Add any characters they want to our (receive-side) asyncmap.
1156 if (go->neg_asyncmap && go->asyncmap != 0xFFFFFFFF) {
1157 NAKCILONG(CI_ASYNCMAP, neg_asyncmap,
1158 try.asyncmap = go->asyncmap | cilong;
1163 * If they've nak'd our authentication-protocol, check whether
1164 * they are proposing a different protocol, or a different
1165 * hash algorithm for CHAP.
1167 if ((go->neg_chap || go->neg_upap)
1168 && len >= CILEN_SHORT
1169 && p[0] == CI_AUTHTYPE && p[1] >= CILEN_SHORT && p[1] <= len) {
1172 no.neg_chap = go->neg_chap;
1173 no.neg_upap = go->neg_upap;
1175 GETSHORT(cishort, p);
1176 if (cishort == PPP_PAP && cilen == CILEN_SHORT) {
1178 * If we were asking for CHAP, they obviously don't want to do it.
1179 * If we weren't asking for CHAP, then we were asking for PAP,
1180 * in which case this Nak is bad.
1186 } else if (cishort == PPP_CHAP && cilen == CILEN_CHAP) {
1190 * We were asking for CHAP/MD5; they must want a different
1191 * algorithm. If they can't do MD5, we can ask for M$-CHAP
1192 * if we support it, otherwise we'll have to stop
1195 /*wilson modify for MS-CHAPv2, 05/26/2005*/
1196 if (go->chap_mdtype == CHAP_MICROSOFT_V2)
1198 try.use_chapms_v2 = 0;
1200 try.chap_mdtype = CHAP_MICROSOFT;
1201 else if(try.use_digest)
1202 try.chap_mdtype = CHAP_DIGEST_MD5;
1206 else if(go->chap_mdtype == CHAP_MICROSOFT)
1210 try.chap_mdtype = CHAP_DIGEST_MD5;
1214 else if(go->chap_mdtype == CHAP_DIGEST_MD5)
1221 if ((cichar != CHAP_MICROSOFT_V2) &&
1222 (cichar != CHAP_MICROSOFT) &&
1223 (cichar != CHAP_DIGEST_MD5))
1225 // if (cichar != go->chap_mdtype) {
1227 // if (cichar == CHAP_MICROSOFT)
1228 // go->chap_mdtype = CHAP_MICROSOFT;
1230 //#endif /* CHAPMS */
1231 // try.neg_chap = 0;
1233 /*wilson modify end*/
1236 * Stop asking for PAP if we were asking for it.
1243 * We don't recognize what they're suggesting.
1244 * Stop asking for what we were asking for.
1250 p += cilen - CILEN_SHORT;
1255 * If they can't cope with our link quality protocol, we'll have
1256 * to stop asking for LQR. We haven't got any other protocol.
1257 * If they Nak the reporting period, take their value XXX ?
1259 NAKCILQR(CI_QUALITY, neg_lqr,
1260 if (cishort != PPP_LQR)
1263 try.lqr_period = cilong;
1267 * Only implementing CBCP...not the rest of the callback options
1269 NAKCICHAR(CI_CALLBACK, neg_cbcp,
1274 * Check for a looped-back line.
1276 NAKCILONG(CI_MAGICNUMBER, neg_magicnumber,
1277 try.magicnumber = magic();
1282 * Peer shouldn't send Nak for protocol compression or
1283 * address/control compression requests; they should send
1284 * a Reject instead. If they send a Nak, treat it as a Reject.
1286 NAKCIVOID(CI_PCOMPRESSION, neg_pcompression);
1287 NAKCIVOID(CI_ACCOMPRESSION, neg_accompression);
1290 * Nak for MRRU option - accept their value if it is smaller
1291 * than the one we want.
1294 NAKCISHORT(CI_MRRU, neg_mrru,
1295 if (cishort <= wo->mrru)
1301 * Nak for short sequence numbers shouldn't be sent, treat it
1304 NAKCIVOID(CI_SSNHF, neg_ssnhf);
1307 * Nak of the endpoint discriminator option is not permitted,
1308 * treat it like a reject.
1310 NAKCIENDP(CI_EPDISC, neg_endpoint);
1313 * There may be remaining CIs, if the peer is requesting negotiation
1314 * on an option that we didn't include in our request packet.
1315 * If we see an option that we requested, or one we've already seen
1316 * in this packet, then this packet is bad.
1317 * If we wanted to respond by starting to negotiate on the requested
1318 * option(s), we could, but we don't, because except for the
1319 * authentication type and quality protocol, if we are not negotiating
1320 * an option, it is because we were told not to.
1321 * For the authentication type, the Nak from the peer means
1322 * `let me authenticate myself with you' which is a bit pointless.
1323 * For the quality protocol, the Nak means `ask me to send you quality
1324 * reports', but if we didn't ask for them, we don't want them.
1325 * An option we don't recognize represents the peer asking to
1326 * negotiate some option we don't support, so ignore it.
1328 while (len > CILEN_VOID) {
1331 if (cilen < CILEN_VOID || (len -= cilen) < 0)
1333 next = p + cilen - 2;
1337 if ((go->neg_mru /* && go->mru != DEFMRU */)
1338 || no.neg_mru || cilen != CILEN_SHORT)
1340 GETSHORT(cishort, p);
1341 if (cishort < DEFMRU) {
1347 if ((go->neg_asyncmap && go->asyncmap != 0xFFFFFFFF)
1348 || no.neg_asyncmap || cilen != CILEN_LONG)
1352 if (go->neg_chap || no.neg_chap || go->neg_upap || no.neg_upap)
1355 case CI_MAGICNUMBER:
1356 if (go->neg_magicnumber || no.neg_magicnumber ||
1357 cilen != CILEN_LONG)
1360 case CI_PCOMPRESSION:
1361 if (go->neg_pcompression || no.neg_pcompression
1362 || cilen != CILEN_VOID)
1365 case CI_ACCOMPRESSION:
1366 if (go->neg_accompression || no.neg_accompression
1367 || cilen != CILEN_VOID)
1371 if (go->neg_lqr || no.neg_lqr || cilen != CILEN_LQR)
1375 if (go->neg_mrru || no.neg_mrru || cilen != CILEN_SHORT)
1379 if (go->neg_ssnhf || no.neg_ssnhf || cilen != CILEN_VOID)
1384 if (go->neg_endpoint || no.neg_endpoint || cilen < CILEN_CHAR)
1392 * OK, the Nak is good. Now we can update state.
1393 * If there are any options left we ignore them.
1395 if (f->state != OPENED) {
1397 if (++try.numloops >= lcp_loopbackfail) {
1398 notice("Serial line is looped back.");
1399 lcp_close(f->unit, "Loopback detected");
1400 status = EXIT_LOOPBACK;
1409 LCPDEBUG(("lcp_nakci: received bad Nak!"));
1410 printf("lcp_nakci: received bad Nak!\n");
1416 * lcp_rejci - Peer has Rejected some of our CIs.
1417 * This should not modify any state if the Reject is bad
1418 * or if LCP is in the OPENED state.
1421 * 0 - Reject was bad.
1422 * 1 - Reject was good.
1425 lcp_rejci(f, p, len)
1430 lcp_options *go = &lcp_gotoptions[f->unit];
1434 lcp_options try; /* options to request next time */
1439 * Any Rejected CIs must be in exactly the same order that we sent.
1440 * Check packet length and CI length at each step.
1441 * If we find any deviations, then this packet is bad.
1443 #define REJCIVOID(opt, neg) \
1445 len >= CILEN_VOID && \
1446 p[1] == CILEN_VOID && \
1448 len -= CILEN_VOID; \
1449 INCPTR(CILEN_VOID, p); \
1452 #define REJCISHORT(opt, neg, val) \
1454 len >= CILEN_SHORT && \
1455 p[1] == CILEN_SHORT && \
1457 len -= CILEN_SHORT; \
1459 GETSHORT(cishort, p); \
1460 /* Check rejected value. */ \
1461 if (cishort != val) \
1465 #define REJCICHAP(opt, neg, val, digest) \
1467 len >= CILEN_CHAP && \
1468 p[1] == CILEN_CHAP && \
1470 len -= CILEN_CHAP; \
1472 GETSHORT(cishort, p); \
1473 GETCHAR(cichar, p); \
1474 /* Check rejected value. */ \
1475 if (cishort != val || cichar != digest) \
1477 /*wilson modify for MS-CHAPv2, 05/26/2005*/ \
1480 case CHAP_MICROSOFT_V2: \
1481 try.use_chapms_v2 = 0; \
1483 case CHAP_MICROSOFT: \
1484 try.use_chapms = 0; \
1486 case CHAP_DIGEST_MD5: \
1487 try.use_digest = 0; \
1489 if(!try.use_chapms_v2 && !try.use_chapms && !try.use_digest) \
1494 /*wilson modify end*/ \
1496 #define REJCILONG(opt, neg, val) \
1498 len >= CILEN_LONG && \
1499 p[1] == CILEN_LONG && \
1501 len -= CILEN_LONG; \
1503 GETLONG(cilong, p); \
1504 /* Check rejected value. */ \
1505 if (cilong != val) \
1509 #define REJCILQR(opt, neg, val) \
1511 len >= CILEN_LQR && \
1512 p[1] == CILEN_LQR && \
1516 GETSHORT(cishort, p); \
1517 GETLONG(cilong, p); \
1518 /* Check rejected value. */ \
1519 if (cishort != PPP_LQR || cilong != val) \
1523 #define REJCICBCP(opt, neg, val) \
1525 len >= CILEN_CBCP && \
1526 p[1] == CILEN_CBCP && \
1528 len -= CILEN_CBCP; \
1530 GETCHAR(cichar, p); \
1531 /* Check rejected value. */ \
1532 if (cichar != val) \
1536 #define REJCIENDP(opt, neg, class, val, vlen) \
1538 len >= CILEN_CHAR + vlen && \
1540 p[1] == CILEN_CHAR + vlen) { \
1542 len -= CILEN_CHAR + vlen; \
1544 GETCHAR(cichar, p); \
1545 if (cichar != class) \
1547 for (i = 0; i < vlen; ++i) { \
1548 GETCHAR(cichar, p); \
1549 if (cichar != val[i]) \
1555 REJCISHORT(CI_MRU, neg_mru, go->mru);
1556 REJCILONG(CI_ASYNCMAP, neg_asyncmap, go->asyncmap);
1557 REJCICHAP(CI_AUTHTYPE, neg_chap, PPP_CHAP, go->chap_mdtype);
1558 if (!go->neg_chap) {
1559 REJCISHORT(CI_AUTHTYPE, neg_upap, PPP_PAP);
1561 REJCILQR(CI_QUALITY, neg_lqr, go->lqr_period);
1562 REJCICBCP(CI_CALLBACK, neg_cbcp, CBCP_OPT);
1563 REJCILONG(CI_MAGICNUMBER, neg_magicnumber, go->magicnumber);
1564 REJCIVOID(CI_PCOMPRESSION, neg_pcompression);
1565 REJCIVOID(CI_ACCOMPRESSION, neg_accompression);
1566 REJCISHORT(CI_MRRU, neg_mrru, go->mrru);
1567 REJCIVOID(CI_SSNHF, neg_ssnhf);
1568 REJCIENDP(CI_EPDISC, neg_endpoint, go->endpoint.class,
1569 go->endpoint.value, go->endpoint.length);
1572 * If there are any remaining CIs, then this packet is bad.
1577 * Now we can update state.
1579 if (f->state != OPENED)
1584 LCPDEBUG(("lcp_rejci: received bad Reject!"));
1590 * lcp_reqci - Check the peer's requested CIs and send appropriate response.
1592 * Returns: CONFACK, CONFNAK or CONFREJ and input packet modified
1593 * appropriately. If reject_if_disagree is non-zero, doesn't return
1594 * CONFNAK; returns CONFREJ if it can't return CONFACK.
1597 lcp_reqci(f, inp, lenp, reject_if_disagree)
1599 u_char *inp; /* Requested CIs */
1600 int *lenp; /* Length of requested CIs */
1601 int reject_if_disagree;
1603 lcp_options *go = &lcp_gotoptions[f->unit];
1604 lcp_options *ho = &lcp_hisoptions[f->unit];
1605 lcp_options *ao = &lcp_allowoptions[f->unit];
1606 u_char *cip, *next; /* Pointer to current and next CIs */
1607 int cilen, citype, cichar; /* Parsed len, type, char value */
1608 u_short cishort; /* Parsed short value */
1609 u_int32_t cilong; /* Parse long value */
1610 int rc = CONFACK; /* Final packet return code */
1611 int orc; /* Individual option return code */
1612 u_char *p; /* Pointer to next char to parse */
1613 u_char *rejp; /* Pointer to next char in reject frame */
1614 u_char *nakp; /* Pointer to next char in Nak frame */
1615 int l = *lenp; /* Length left */
1619 BZERO(ho, sizeof(*ho));
1622 * Process all his options.
1628 orc = CONFACK; /* Assume success */
1629 cip = p = next; /* Remember begining of CI */
1630 if (l < 2 || /* Not enough data for CI header or */
1631 p[1] < 2 || /* CI length too small or */
1632 p[1] > l) { /* CI length too big? */
1633 LCPDEBUG(("lcp_reqci: bad CI length!"));
1634 orc = CONFREJ; /* Reject bad CI */
1635 cilen = l; /* Reject till end of packet */
1636 l = 0; /* Don't loop again */
1640 GETCHAR(citype, p); /* Parse CI type */
1641 GETCHAR(cilen, p); /* Parse CI length */
1642 l -= cilen; /* Adjust remaining length */
1643 next += cilen; /* Step to next CI */
1645 switch (citype) { /* Check CI type */
1647 if (!ao->neg_mru || /* Allow option? */
1648 cilen != CILEN_SHORT) { /* Check CI length */
1649 orc = CONFREJ; /* Reject CI */
1652 GETSHORT(cishort, p); /* Parse MRU */
1655 * He must be able to receive at least our minimum.
1656 * No need to check a maximum. If he sends a large number,
1657 * we'll just ignore it.
1659 if (cishort < MINMRU) {
1660 orc = CONFNAK; /* Nak CI */
1661 PUTCHAR(CI_MRU, nakp);
1662 PUTCHAR(CILEN_SHORT, nakp);
1663 PUTSHORT(MINMRU, nakp); /* Give him a hint */
1666 ho->neg_mru = 1; /* Remember he sent MRU */
1667 ho->mru = cishort; /* And remember value */
1671 if (!ao->neg_asyncmap ||
1672 cilen != CILEN_LONG) {
1679 * Asyncmap must have set at least the bits
1680 * which are set in lcp_allowoptions[unit].asyncmap.
1682 if ((ao->asyncmap & ~cilong) != 0) {
1684 PUTCHAR(CI_ASYNCMAP, nakp);
1685 PUTCHAR(CILEN_LONG, nakp);
1686 PUTLONG(ao->asyncmap | cilong, nakp);
1689 ho->neg_asyncmap = 1;
1690 ho->asyncmap = cilong;
1694 if (cilen < CILEN_SHORT || !(ao->neg_upap || ao->neg_chap)) {
1696 * Reject the option if we're not willing to authenticate.
1701 GETSHORT(cishort, p);
1704 * Authtype must be PAP or CHAP.
1706 * Note: if both ao->neg_upap and ao->neg_chap are set,
1707 * and the peer sends a Configure-Request with two
1708 * authenticate-protocol requests, one for CHAP and one
1709 * for UPAP, then we will reject the second request.
1710 * Whether we end up doing CHAP or UPAP depends then on
1711 * the ordering of the CIs in the peer's Configure-Request.
1713 //Andy add for auto PVC
1714 if (autoscan == 1 && (cishort == PPP_PAP || cishort == PPP_CHAP)){
1715 create_msg(BCM_PPPOE_SERVICE_AVAILABLE);
1717 if (cishort == PPP_PAP) {
1718 if (ho->neg_chap || /* we've already accepted CHAP */
1719 cilen != CILEN_SHORT) {
1720 LCPDEBUG(("lcp_reqci: rcvd AUTHTYPE PAP, rejecting..."));
1724 if (!ao->neg_upap) { /* we don't want to do PAP */
1725 orc = CONFNAK; /* NAK it and suggest PAP */
1726 PUTCHAR(CI_AUTHTYPE, nakp);
1727 PUTCHAR(CILEN_CHAP, nakp);
1728 PUTSHORT(PPP_CHAP, nakp);
1729 PUTCHAR(ao->chap_mdtype, nakp);
1732 printf("PPP: Authentication failed.\n");
1733 create_msg(BCM_PPPOE_AUTH_FAILED);
1734 //syslog(LOG_ERR,"Authentication method failed.\n");
1736 lcp_close(0, "Auth failed");
1738 status = EXIT_PEER_AUTH_FAILED;
1742 /* XXX if we can do CHAP_MICROSOFT as well, we should
1743 probably put in another option saying so */
1749 if (cishort == PPP_CHAP) {
1750 if (ho->neg_upap || /* we've already accepted PAP */
1751 cilen != CILEN_CHAP) {
1752 LCPDEBUG(("lcp_reqci: rcvd AUTHTYPE CHAP, rejecting..."));
1756 if (!ao->neg_chap) { /* we don't want to do CHAP */
1757 orc = CONFNAK; /* NAK it and suggest PAP */
1758 PUTCHAR(CI_AUTHTYPE, nakp);
1759 PUTCHAR(CILEN_SHORT, nakp);
1760 PUTSHORT(PPP_PAP, nakp);
1763 printf("PPP: Authentication failed.\n");
1764 create_msg(BCM_PPPOE_AUTH_FAILED);
1765 //syslog(LOG_ERR,"Authentication method failed.\n");
1767 lcp_close(0, "Auth failed");
1774 GETCHAR(cichar, p); /* get digest type*/
1775 if (cichar != CHAP_DIGEST_MD5
1777 && cichar != CHAP_MICROSOFT
1778 && cichar != CHAP_MICROSOFT_V2 /*wilson add for MS-CHAPv2, 05/26/2005*/
1781 /*wilson modify for MS-CHAPv2, 05/26/2005*/
1783 orc = CONFREJ; /* !!! CONFNAK !!! */
1784 /*wilson modify end*/
1785 PUTCHAR(CI_AUTHTYPE, nakp);
1786 PUTCHAR(CILEN_CHAP, nakp);
1787 PUTSHORT(PPP_CHAP, nakp);
1788 PUTCHAR(ao->chap_mdtype, nakp);
1791 ho->chap_mdtype = cichar; /* save md type */
1797 * We don't recognize the protocol they're asking for.
1798 * Nak it with something we're willing to do.
1799 * (At this point we know ao->neg_upap || ao->neg_chap.)
1802 PUTCHAR(CI_AUTHTYPE, nakp);
1804 PUTCHAR(CILEN_CHAP, nakp);
1805 PUTSHORT(PPP_CHAP, nakp);
1806 PUTCHAR(ao->chap_mdtype, nakp);
1808 PUTCHAR(CILEN_SHORT, nakp);
1809 PUTSHORT(PPP_PAP, nakp);
1814 if (!ao->neg_lqr || cilen != CILEN_LQR) {
1819 GETSHORT(cishort, p);
1823 * Check the protocol and the reporting period.
1824 * XXX When should we Nak this, and what with?
1826 if (cishort != PPP_LQR) {
1828 PUTCHAR(CI_QUALITY, nakp);
1829 PUTCHAR(CILEN_LQR, nakp);
1830 PUTSHORT(PPP_LQR, nakp);
1831 PUTLONG(ao->lqr_period, nakp);
1836 case CI_MAGICNUMBER:
1837 if (!(ao->neg_magicnumber || go->neg_magicnumber) || cilen != CILEN_LONG) {
1844 * He must have a different magic number.
1846 if (go->neg_magicnumber && cilong == go->magicnumber) {
1847 cilong = magic(); /* Don't put magic() inside macro! */
1849 PUTCHAR(CI_MAGICNUMBER, nakp);
1850 PUTCHAR(CILEN_LONG, nakp);
1851 PUTLONG(cilong, nakp);
1854 ho->neg_magicnumber = 1;
1855 ho->magicnumber = cilong;
1859 case CI_PCOMPRESSION:
1860 if (!ao->neg_pcompression || cilen != CILEN_VOID) {
1864 ho->neg_pcompression = 1;
1867 case CI_ACCOMPRESSION:
1868 if (!ao->neg_accompression || cilen != CILEN_VOID) {
1872 ho->neg_accompression = 1;
1876 if (!ao->neg_mrru || !multilink || cilen != CILEN_SHORT) {
1881 GETSHORT(cishort, p);
1882 /* possibly should insist on a minimum/maximum MRRU here */
1888 if (!ao->neg_ssnhf || !multilink || cilen != CILEN_VOID) {
1896 if (!ao->neg_endpoint || cilen < CILEN_CHAR || cilen > CILEN_CHAR + MAX_ENDP_LEN) {
1901 cilen -= CILEN_CHAR;
1902 ho->neg_endpoint = 1;
1903 ho->endpoint.class = cichar;
1904 ho->endpoint.length = cilen;
1905 BCOPY(p, ho->endpoint.value, cilen);
1910 LCPDEBUG(("lcp_reqci: rcvd unknown option %d", citype));
1916 if (orc == CONFACK && /* Good CI */
1917 rc != CONFACK) /* but prior CI wasnt? */
1918 continue; /* Don't send this one */
1920 if (orc == CONFNAK) { /* Nak this CI? */
1921 if (reject_if_disagree /* Getting fed up with sending NAKs? */
1922 && citype != CI_MAGICNUMBER) {
1923 orc = CONFREJ; /* Get tough if so */
1925 if (rc == CONFREJ) /* Rejecting prior CI? */
1926 continue; /* Don't send this one */
1930 if (orc == CONFREJ) { /* Reject this CI */
1932 if (cip != rejp) /* Need to move rejected CI? */
1933 BCOPY(cip, rejp, cilen); /* Move it */
1934 INCPTR(cilen, rejp); /* Update output pointer */
1939 * If we wanted to send additional NAKs (for unsent CIs), the
1940 * code would go here. The extra NAKs would go at *nakp.
1941 * At present there are no cases where we want to ask the
1942 * peer to negotiate an option.
1951 * Copy the Nak'd options from the nak_buffer to the caller's buffer.
1953 *lenp = nakp - nak_buffer;
1954 BCOPY(nak_buffer, inp, *lenp);
1961 LCPDEBUG(("lcp_reqci: returning CONF%s.", CODENAME(rc)));
1962 return (rc); /* Return final code */
1967 * lcp_up - LCP has come UP.
1973 lcp_options *wo = &lcp_wantoptions[f->unit];
1974 lcp_options *ho = &lcp_hisoptions[f->unit];
1975 lcp_options *go = &lcp_gotoptions[f->unit];
1976 lcp_options *ao = &lcp_allowoptions[f->unit];
1978 if (!go->neg_magicnumber)
1979 go->magicnumber = 0;
1980 if (!ho->neg_magicnumber)
1981 ho->magicnumber = 0;
1984 * Set our MTU to the smaller of the MTU we wanted and
1985 * the MRU our peer wanted. If we negotiated an MRU,
1986 * set our MRU to the larger of value we wanted and
1987 * the value we got in the negotiation.
1988 * Note on the MTU: the link MTU can be the MRU the peer wanted,
1989 * the interface MTU is set to the lower of that and the
1990 * MTU we want to use.
1993 mtu = ho->neg_mru? ho->mru: PPP_MRU;
1995 #if defined(CONFIG_LANG_MMM) || defined(ODM_LANG_LLL)//Andy add (2005/06/20)
1996 mtu = glb_CONFIG_PPP_MTU;
1998 mtu = ho->neg_mru? ho->mru: glb_CONFIG_PPP_MTU;
2001 #ifdef HAVE_MULTILINK
2002 if (!(multilink && go->neg_mrru && ho->neg_mrru))
2003 #endif /* HAVE_MULTILINK */
2004 netif_set_mtu(f->unit, MIN(mtu, ao->mru));
2005 ppp_send_config(f->unit, mtu,
2006 (ho->neg_asyncmap? ho->asyncmap: 0xffffffff),
2007 ho->neg_pcompression, ho->neg_accompression);
2008 ppp_recv_config(f->unit, (go->neg_mru? MAX(wo->mru, go->mru): PPP_MRU),
2009 (lax_recv? 0: go->neg_asyncmap? go->asyncmap: 0xffffffff),
2010 go->neg_pcompression, go->neg_accompression);
2013 peer_mru[f->unit] = ho->mru;
2015 peer_mru[f->unit] = mtu;
2017 lcp_echo_lowerup(f->unit); /* Enable echo messages */
2019 link_established(f->unit);
2023 create_msg(BCM_PPPOE_SERVICE_AVAILABLE);
2024 syslog(LOG_NOTICE,"PPP LCP Up\n");
2029 * lcp_down - LCP has gone DOWN.
2031 * Alert other protocols.
2037 lcp_options *go = &lcp_gotoptions[f->unit];
2039 lcp_echo_lowerdown(f->unit);
2043 ppp_send_config(f->unit, PPP_MRU, 0xffffffff, 0, 0);
2044 ppp_recv_config(f->unit, PPP_MRU,
2045 (go->neg_asyncmap? go->asyncmap: 0xffffffff),
2046 go->neg_pcompression, go->neg_accompression);
2047 peer_mru[f->unit] = PPP_MRU;
2052 * lcp_starting - LCP needs the lower layer up.
2058 link_required(f->unit);
2063 * lcp_finished - LCP has finished with the lower layer.
2069 link_terminated(f->unit);
2074 * lcp_printpkt - print the contents of an LCP packet.
2076 static char *lcp_codenames[] = {
2077 "ConfReq", "ConfAck", "ConfNak", "ConfRej",
2078 "TermReq", "TermAck", "CodeRej", "ProtRej",
2079 "EchoReq", "EchoRep", "DiscReq"
2083 lcp_printpkt(p, plen, printer, arg)
2086 void (*printer) __P((void *, char *, ...));
2089 int code, id, len, olen, i;
2090 u_char *pstart, *optend;
2094 if (plen < HEADERLEN)
2100 if (len < HEADERLEN || len > plen)
2103 if (code >= 1 && code <= sizeof(lcp_codenames) / sizeof(char *))
2104 printer(arg, " %s", lcp_codenames[code-1]);
2106 printer(arg, " code=0x%x", code);
2107 printer(arg, " id=0x%x", id);
2114 /* print option list */
2119 if (olen < 2 || olen > len) {
2127 if (olen == CILEN_SHORT) {
2129 GETSHORT(cishort, p);
2130 printer(arg, "mru %d", cishort);
2134 if (olen == CILEN_LONG) {
2137 printer(arg, "asyncmap 0x%x", cilong);
2141 if (olen >= CILEN_SHORT) {
2143 printer(arg, "auth ");
2144 GETSHORT(cishort, p);
2147 printer(arg, "pap");
2150 printer(arg, "chap");
2153 case CHAP_DIGEST_MD5:
2154 printer(arg, " MD5");
2158 case CHAP_MICROSOFT:
2159 printer(arg, " m$oft");
2167 printer(arg, "0x%x", cishort);
2172 if (olen >= CILEN_SHORT) {
2174 printer(arg, "quality ");
2175 GETSHORT(cishort, p);
2178 printer(arg, "lqr");
2181 printer(arg, "0x%x", cishort);
2186 if (olen >= CILEN_CHAR) {
2188 printer(arg, "callback ");
2189 GETCHAR(cishort, p);
2192 printer(arg, "CBCP");
2195 printer(arg, "0x%x", cishort);
2199 case CI_MAGICNUMBER:
2200 if (olen == CILEN_LONG) {
2203 printer(arg, "magic 0x%x", cilong);
2206 case CI_PCOMPRESSION:
2207 if (olen == CILEN_VOID) {
2209 printer(arg, "pcomp");
2212 case CI_ACCOMPRESSION:
2213 if (olen == CILEN_VOID) {
2215 printer(arg, "accomp");
2219 if (olen == CILEN_SHORT) {
2221 GETSHORT(cishort, p);
2222 printer(arg, "mrru %d", cishort);
2226 if (olen == CILEN_VOID) {
2228 printer(arg, "ssnhf");
2232 #ifdef HAVE_MULTILINK
2233 if (olen >= CILEN_CHAR) {
2236 GETCHAR(epd.class, p);
2237 epd.length = olen - CILEN_CHAR;
2238 if (epd.length > MAX_ENDP_LEN)
2239 epd.length = MAX_ENDP_LEN;
2240 if (epd.length > 0) {
2241 BCOPY(p, epd.value, epd.length);
2244 printer(arg, "endpoint [%s]", epdisc_to_str(&epd));
2247 printer(arg, "endpoint");
2251 while (p < optend) {
2253 printer(arg, " %.2x", code);
2261 if (len > 0 && *p >= ' ' && *p < 0x7f) {
2263 print_string((char *)p, len, printer, arg);
2274 printer(arg, " magic=0x%x", cilong);
2281 /* print the rest of the bytes in the packet */
2282 for (i = 0; i < len && i < 32; ++i) {
2284 printer(arg, " %.2x", code);
2287 printer(arg, " ...");
2295 * Time to shut down the link because there is nothing out there.
2299 void LcpLinkFailure (f)
2302 if (f->state == OPENED) {
2303 info("No response to %d echo-requests", lcp_echos_pending);
2304 notice("Serial link appears to be disconnected.");
2305 lcp_close(f->unit, "Peer not responding");
2306 status = EXIT_PEER_DEAD;
2310 static int traffic()
2312 struct ppp_idle idle;
2316 get_idle_time(0, &idle);
2317 //tlim = MIN(idle.xmit_idle, idle.recv_idle);
2318 tlim = idle.recv_idle;
2319 if (tlim > idle_for_echo)
2327 * Timer expired for the LCP echo requests from this process.
2336 LcpSendEchoRequest (f);
2338 lcp_echos_pending= 0;
2340 if (f->state != OPENED)
2344 * Start the timer for the next interval.
2346 if (lcp_echo_timer_running)
2347 warn("assertion lcp_echo_timer_running==0 failed");
2348 TIMEOUT (LcpEchoTimeout, f, lcp_echo_interval);
2349 lcp_echo_timer_running = 1;
2353 * LcpEchoTimeout - Timer expired on the LCP echo
2357 LcpEchoTimeout (arg)
2360 if (lcp_echo_timer_running != 0) {
2361 lcp_echo_timer_running = 0;
2362 LcpEchoCheck ((fsm *) arg);
2367 * LcpEchoReply - LCP has received a reply to the echo
2371 lcp_received_echo_reply (f, id, inp, len)
2379 /* Check the magic number - don't count replies from ourselves. */
2381 dbglog("lcp: received short Echo-Reply, length %d", len);
2384 GETLONG(magic, inp);
2385 if (lcp_gotoptions[f->unit].neg_magicnumber
2386 && magic == lcp_gotoptions[f->unit].magicnumber) {
2387 warn("appear to have received our own echo-reply!");
2391 /* Reset the number of outstanding echo frames */
2392 lcp_echos_pending = 0;
2396 * LcpSendEchoRequest - Send an echo request frame to the peer
2400 LcpSendEchoRequest (f)
2403 u_int32_t lcp_magic;
2404 u_char pkt[4], *pktp;
2407 * Detect the failure of the peer at this point.
2409 if (lcp_echo_fails != 0) {
2410 if (lcp_echos_pending >= lcp_echo_fails) {
2412 lcp_echos_pending = 0;
2417 * Make and send the echo request frame.
2419 if (f->state == OPENED) {
2420 lcp_magic = lcp_gotoptions[f->unit].magicnumber;
2422 PUTLONG(lcp_magic, pktp);
2423 fsm_sdata(f, ECHOREQ, lcp_echo_number++ & 0xFF, pkt, pktp - pkt);
2424 ++lcp_echos_pending;
2429 * lcp_echo_lowerup - Start the timer for the LCP frame
2433 lcp_echo_lowerup (unit)
2436 fsm *f = &lcp_fsm[unit];
2438 /* Clear the parameters for generating echo frames */
2439 lcp_echos_pending = 0;
2440 lcp_echo_number = 0;
2441 lcp_echo_timer_running = 0;
2443 /* If a timeout interval is specified then start the timer */
2444 if (lcp_echo_interval != 0)
2449 * lcp_echo_lowerdown - Stop the timer for the LCP frame
2453 lcp_echo_lowerdown (unit)
2456 fsm *f = &lcp_fsm[unit];
2458 if (lcp_echo_timer_running != 0) {
2459 UNTIMEOUT (LcpEchoTimeout, f);
2460 lcp_echo_timer_running = 0;