1 /*****************************************************************************
2 * lcp.c - Network Link Control Protocol program file.
4 * Copyright (c) 2003 by Marc Boucher, Services Informatiques (MBSI) inc.
5 * portions Copyright (c) 1997 by Global Election Systems Inc.
7 * The authors hereby grant permission to use, copy, modify, distribute,
8 * and license this software and its documentation for any purpose, provided
9 * that existing copyright notices are retained in all copies and that this
10 * notice and the following disclaimer are included verbatim in any
11 * distributions. No written agreement, license, or royalty fee is required
12 * for any of the authorized uses.
14 * THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS *AS IS* AND ANY EXPRESS OR
15 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17 * IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
18 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 ******************************************************************************
28 * 03-01-01 Marc Boucher <marc@mbsi.ca>
30 * 97-12-01 Guy Lancaster <lancasterg@acm.org>, Global Election Systems Inc.
32 *****************************************************************************/
35 * lcp.c - PPP Link Control Protocol.
37 * Copyright (c) 1989 Carnegie Mellon University.
38 * All rights reserved.
40 * Redistribution and use in source and binary forms are permitted
41 * provided that the above copyright notice and this paragraph are
42 * duplicated in all such forms and that any documentation,
43 * advertising materials, and other materials related to such
44 * distribution and use acknowledge that the software was developed
45 * by Carnegie Mellon University. The name of the
46 * University may not be used to endorse or promote products derived
47 * from this software without specific prior written permission.
48 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
49 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
50 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
56 #if PPP_SUPPORT /* don't build if not configured for use in lwipopts.h */
70 #include "netif/ppp_oe.h"
72 #define PPPOE_MAXMTU PPP_MAXMRU
77 * LCP-related command-line options.
79 int lcp_echo_interval
= 0; /* Interval between LCP echo-requests */
80 int lcp_echo_fails
= 0; /* Tolerance to unanswered echo-requests */
81 bool lax_recv
= 0; /* accept control chars in asyncmap */
83 static int setescape (char **);
85 static option_t lcp_option_list
[] = {
87 /* list stripped for simplicity */
93 LinkPhase lcp_phase
[NUM_PPP
]; /* Phase of link session (RFC 1661) */
94 static u_int lcp_echo_interval
= LCP_ECHOINTERVAL
; /* Interval between LCP echo-requests */
95 static u_int lcp_echo_fails
= LCP_MAXECHOFAILS
; /* Tolerance to unanswered echo-requests */
98 static fsm lcp_fsm
[NUM_PPP
]; /* LCP fsm structure (global)*/
99 lcp_options lcp_wantoptions
[NUM_PPP
]; /* Options that we want to request */
100 lcp_options lcp_gotoptions
[NUM_PPP
]; /* Options that peer ack'd */
101 lcp_options lcp_allowoptions
[NUM_PPP
]; /* Options we allow peer to request */
102 lcp_options lcp_hisoptions
[NUM_PPP
]; /* Options that we ack'd */
103 ext_accm xmit_accm
[NUM_PPP
]; /* extended transmit ACCM */
105 static u32_t lcp_echos_pending
= 0; /* Number of outstanding echo msgs */
106 static u32_t lcp_echo_number
= 0; /* ID number of next echo frame */
107 static u32_t lcp_echo_timer_running
= 0; /* TRUE if a timer is running */
109 /* @todo: do we really need such a large buffer? The typical 1500 bytes seem too much. */
110 static u_char nak_buffer
[PPP_MRU
]; /* where we construct a nak packet */
113 * Callbacks for fsm code. (CI = Configuration Information)
115 static void lcp_resetci (fsm
*); /* Reset our CI */
116 static int lcp_cilen (fsm
*); /* Return length of our CI */
117 static void lcp_addci (fsm
*, u_char
*, int*); /* Add our CI to pkt */
118 static int lcp_ackci (fsm
*, u_char
*, int); /* Peer ack'd our CI */
119 static int lcp_nakci (fsm
*, u_char
*, int); /* Peer nak'd our CI */
120 static int lcp_rejci (fsm
*, u_char
*, int); /* Peer rej'd our CI */
121 static int lcp_reqci (fsm
*, u_char
*, int*, int); /* Rcv peer CI */
122 static void lcp_up (fsm
*); /* We're UP */
123 static void lcp_down (fsm
*); /* We're DOWN */
124 static void lcp_starting (fsm
*); /* We need lower layer up */
125 static void lcp_finished (fsm
*); /* We need lower layer down */
126 static int lcp_extcode (fsm
*, int, u_char
, u_char
*, int);
127 static void lcp_rprotrej (fsm
*, u_char
*, int);
130 * routines to send LCP echos to peer
133 static void lcp_echo_lowerup (int);
134 static void lcp_echo_lowerdown (int);
135 static void LcpEchoTimeout (void*);
136 static void lcp_received_echo_reply (fsm
*, int, u_char
*, int);
137 static void LcpSendEchoRequest (fsm
*);
138 static void LcpLinkFailure (fsm
*);
139 static void LcpEchoCheck (fsm
*);
141 static fsm_callbacks lcp_callbacks
= { /* LCP callback routines */
142 lcp_resetci
, /* Reset our Configuration Information */
143 lcp_cilen
, /* Length of our Configuration Information */
144 lcp_addci
, /* Add our Configuration Information */
145 lcp_ackci
, /* ACK our Configuration Information */
146 lcp_nakci
, /* NAK our Configuration Information */
147 lcp_rejci
, /* Reject our Configuration Information */
148 lcp_reqci
, /* Request peer's Configuration Information */
149 lcp_up
, /* Called when fsm reaches LS_OPENED state */
150 lcp_down
, /* Called when fsm leaves LS_OPENED state */
151 lcp_starting
, /* Called when we want the lower layer up */
152 lcp_finished
, /* Called when we want the lower layer down */
153 NULL
, /* Called when Protocol-Reject received */
154 NULL
, /* Retransmission is necessary */
155 lcp_extcode
, /* Called to handle LCP-specific codes */
156 "LCP" /* String name of protocol */
160 * Protocol entry points.
161 * Some of these are called directly.
164 static void lcp_input (int, u_char
*, int);
165 static void lcp_protrej (int);
167 struct protent lcp_protent
= {
176 #if PPP_ADDITIONAL_CALLBACKS
179 #endif /* PPP_ADDITIONAL_CALLBACKS */
182 #if PPP_ADDITIONAL_CALLBACKS
186 #endif /* PPP_ADDITIONAL_CALLBACKS */
189 int lcp_loopbackfail
= DEFLOOPBACKFAIL
;
192 * Length of each type of configuration option (in octets)
196 #define CILEN_SHORT 4 /* CILEN_VOID + sizeof(short) */
197 #define CILEN_CHAP 5 /* CILEN_VOID + sizeof(short) + 1 */
198 #define CILEN_LONG 6 /* CILEN_VOID + sizeof(long) */
199 #define CILEN_LQR 8 /* CILEN_VOID + sizeof(short) + sizeof(long) */
202 #define CODENAME(x) ((x) == CONFACK ? "ACK" : (x) == CONFNAK ? "NAK" : "REJ")
206 * setescape - add chars to the set we escape on transmission.
218 n
= strtol(p
, &endp
, 16);
220 option_error("escape parameter contains invalid hex number '%s'", p
);
224 if (n
< 0 || n
== 0x5E || n
> 0xFF) {
225 option_error("can't escape character 0x%x", n
);
228 xmit_accm
[0][n
>> 5] |= 1 << (n
& 0x1F);
229 while (*p
== ',' || *p
== ' ')
237 * lcp_init - Initialize LCP.
242 fsm
*f
= &lcp_fsm
[unit
];
243 lcp_options
*wo
= &lcp_wantoptions
[unit
];
244 lcp_options
*ao
= &lcp_allowoptions
[unit
];
247 f
->protocol
= PPP_LCP
;
248 f
->callbacks
= &lcp_callbacks
;
254 wo
->restart
= 0; /* Set to 1 in kernels or multi-line implementations */
256 wo
->mru
= PPP_DEFMRU
;
257 wo
->neg_asyncmap
= 1;
258 wo
->asyncmap
= 0x00000000l
; /* Assume don't need to escape any ctl chars. */
259 wo
->neg_chap
= 0; /* Set to 1 on server */
260 wo
->neg_upap
= 0; /* Set to 1 on server */
261 wo
->chap_mdtype
= CHAP_DIGEST_MD5
;
262 wo
->neg_magicnumber
= 1;
263 wo
->neg_pcompression
= 1;
264 wo
->neg_accompression
= 1;
265 wo
->neg_lqr
= 0; /* no LQR implementation yet */
269 ao
->mru
= PPP_MAXMRU
;
270 ao
->neg_asyncmap
= 1;
271 ao
->asyncmap
= 0x00000000l
; /* Assume don't need to escape any ctl chars. */
272 ao
->neg_chap
= (CHAP_SUPPORT
!= 0);
273 ao
->chap_mdtype
= CHAP_DIGEST_MD5
;
274 ao
->neg_upap
= (PAP_SUPPORT
!= 0);
275 ao
->neg_magicnumber
= 1;
276 ao
->neg_pcompression
= 1;
277 ao
->neg_accompression
= 1;
278 ao
->neg_lqr
= 0; /* no LQR implementation yet */
279 ao
->neg_cbcp
= (CBCP_SUPPORT
!= 0);
282 * Set transmit escape for the flag and escape characters plus anything
283 * set for the allowable options.
285 memset(xmit_accm
[unit
], 0, sizeof(xmit_accm
[0]));
286 xmit_accm
[unit
][15] = 0x60;
287 xmit_accm
[unit
][0] = (u_char
)((ao
->asyncmap
& 0xFF));
288 xmit_accm
[unit
][1] = (u_char
)((ao
->asyncmap
>> 8) & 0xFF);
289 xmit_accm
[unit
][2] = (u_char
)((ao
->asyncmap
>> 16) & 0xFF);
290 xmit_accm
[unit
][3] = (u_char
)((ao
->asyncmap
>> 24) & 0xFF);
291 LCPDEBUG(LOG_INFO
, ("lcp_init: xmit_accm=%X %X %X %X\n",
295 xmit_accm
[unit
][3]));
297 lcp_phase
[unit
] = PHASE_INITIALIZE
;
302 * lcp_open - LCP is allowed to come up.
307 fsm
*f
= &lcp_fsm
[unit
];
308 lcp_options
*wo
= &lcp_wantoptions
[unit
];
312 f
->flags
|= OPT_PASSIVE
;
315 f
->flags
|= OPT_SILENT
;
319 lcp_phase
[unit
] = PHASE_ESTABLISH
;
324 * lcp_close - Take LCP down.
327 lcp_close(int unit
, char *reason
)
329 fsm
*f
= &lcp_fsm
[unit
];
331 if (lcp_phase
[unit
] != PHASE_DEAD
) {
332 lcp_phase
[unit
] = PHASE_TERMINATE
;
334 if (f
->state
== LS_STOPPED
&& f
->flags
& (OPT_PASSIVE
|OPT_SILENT
)) {
336 * This action is not strictly according to the FSM in RFC1548,
337 * but it does mean that the program terminates if you do an
338 * lcp_close() in passive/silent mode when a connection hasn't
341 f
->state
= LS_CLOSED
;
344 fsm_close(f
, reason
);
350 * lcp_lowerup - The lower layer is up.
353 lcp_lowerup(int unit
)
355 lcp_options
*wo
= &lcp_wantoptions
[unit
];
358 * Don't use A/C or protocol compression on transmission,
359 * but accept A/C and protocol compressed packets
360 * if we are going to ask for A/C and protocol compression.
362 ppp_set_xaccm(unit
, &xmit_accm
[unit
]);
363 ppp_send_config(unit
, PPP_MRU
, 0xffffffffl
, 0, 0);
364 ppp_recv_config(unit
, PPP_MRU
, 0x00000000l
,
365 wo
->neg_pcompression
, wo
->neg_accompression
);
366 peer_mru
[unit
] = PPP_MRU
;
367 lcp_allowoptions
[unit
].asyncmap
= (u_long
)xmit_accm
[unit
][0]
368 | ((u_long
)xmit_accm
[unit
][1] << 8)
369 | ((u_long
)xmit_accm
[unit
][2] << 16)
370 | ((u_long
)xmit_accm
[unit
][3] << 24);
371 LCPDEBUG(LOG_INFO
, ("lcp_lowerup: asyncmap=%X %X %X %X\n",
375 xmit_accm
[unit
][0]));
377 fsm_lowerup(&lcp_fsm
[unit
]);
382 * lcp_lowerdown - The lower layer is down.
385 lcp_lowerdown(int unit
)
387 fsm_lowerdown(&lcp_fsm
[unit
]);
392 * lcp_input - Input LCP packet.
395 lcp_input(int unit
, u_char
*p
, int len
)
397 fsm
*f
= &lcp_fsm
[unit
];
399 fsm_input(f
, p
, len
);
404 * lcp_extcode - Handle a LCP-specific code.
407 lcp_extcode(fsm
*f
, int code
, u_char id
, u_char
*inp
, int len
)
413 lcp_rprotrej(f
, inp
, len
);
417 if (f
->state
!= LS_OPENED
) {
420 LCPDEBUG(LOG_INFO
, ("lcp: Echo-Request, Rcvd id %d\n", id
));
422 PUTLONG(lcp_gotoptions
[f
->unit
].magicnumber
, magp
);
423 fsm_sdata(f
, ECHOREP
, id
, inp
, len
);
427 lcp_received_echo_reply(f
, id
, inp
, len
);
441 * lcp_rprotrej - Receive an Protocol-Reject.
443 * Figure out which protocol is rejected and inform it.
446 lcp_rprotrej(fsm
*f
, u_char
*inp
, int len
)
449 struct protent
*protp
;
452 if (len
< (int)sizeof (u_short
)) {
453 LCPDEBUG(LOG_INFO
, ("lcp_rprotrej: Rcvd short Protocol-Reject packet!\n"));
459 LCPDEBUG(LOG_INFO
, ("lcp_rprotrej: Rcvd Protocol-Reject packet for %x!\n", prot
));
462 * Protocol-Reject packets received in any state other than the LCP
463 * LS_OPENED state SHOULD be silently discarded.
465 if( f
->state
!= LS_OPENED
) {
466 LCPDEBUG(LOG_INFO
, ("Protocol-Reject discarded: LCP in state %d\n", f
->state
));
471 * Upcall the proper Protocol-Reject routine.
473 for (i
= 0; (protp
= ppp_protocols
[i
]) != NULL
; ++i
) {
474 if (protp
->protocol
== prot
&& protp
->enabled_flag
) {
475 (*protp
->protrej
)(f
->unit
);
480 LCPDEBUG(LOG_WARNING
, ("Protocol-Reject for unsupported protocol 0x%x\n", prot
));
485 * lcp_protrej - A Protocol-Reject was received.
488 lcp_protrej(int unit
)
490 LWIP_UNUSED_ARG(unit
);
494 LCPDEBUG(LOG_WARNING
, ("lcp_protrej: Received Protocol-Reject for LCP!\n"));
495 fsm_protreject(&lcp_fsm
[unit
]);
500 * lcp_sprotrej - Send a Protocol-Reject for some protocol.
503 lcp_sprotrej(int unit
, u_char
*p
, int len
)
506 * Send back the protocol and the information field of the
507 * rejected packet. We only get here if LCP is in the LS_OPENED state.
510 fsm_sdata(&lcp_fsm
[unit
], PROTREJ
, ++lcp_fsm
[unit
].id
, p
, len
);
515 * lcp_resetci - Reset our CI.
520 lcp_wantoptions
[f
->unit
].magicnumber
= magic();
521 lcp_wantoptions
[f
->unit
].numloops
= 0;
522 lcp_gotoptions
[f
->unit
] = lcp_wantoptions
[f
->unit
];
523 peer_mru
[f
->unit
] = PPP_MRU
;
529 * lcp_cilen - Return length of our CI.
534 lcp_options
*go
= &lcp_gotoptions
[f
->unit
];
536 #define LENCIVOID(neg) ((neg) ? CILEN_VOID : 0)
537 #define LENCICHAP(neg) ((neg) ? CILEN_CHAP : 0)
538 #define LENCISHORT(neg) ((neg) ? CILEN_SHORT : 0)
539 #define LENCILONG(neg) ((neg) ? CILEN_LONG : 0)
540 #define LENCILQR(neg) ((neg) ? CILEN_LQR: 0)
541 #define LENCICBCP(neg) ((neg) ? CILEN_CBCP: 0)
543 * NB: we only ask for one of CHAP and UPAP, even if we will
546 return (LENCISHORT(go
->neg_mru
&& go
->mru
!= PPP_DEFMRU
) +
547 LENCILONG(go
->neg_asyncmap
&& go
->asyncmap
!= 0xFFFFFFFFl
) +
548 LENCICHAP(go
->neg_chap
) +
549 LENCISHORT(!go
->neg_chap
&& go
->neg_upap
) +
550 LENCILQR(go
->neg_lqr
) +
551 LENCICBCP(go
->neg_cbcp
) +
552 LENCILONG(go
->neg_magicnumber
) +
553 LENCIVOID(go
->neg_pcompression
) +
554 LENCIVOID(go
->neg_accompression
));
559 * lcp_addci - Add our desired CIs to a packet.
562 lcp_addci(fsm
*f
, u_char
*ucp
, int *lenp
)
564 lcp_options
*go
= &lcp_gotoptions
[f
->unit
];
565 u_char
*start_ucp
= ucp
;
567 #define ADDCIVOID(opt, neg) \
569 LCPDEBUG(LOG_INFO, ("lcp_addci: opt=%d\n", opt)); \
571 PUTCHAR(CILEN_VOID, ucp); \
573 #define ADDCISHORT(opt, neg, val) \
575 LCPDEBUG(LOG_INFO, ("lcp_addci: INT opt=%d %X\n", opt, val)); \
577 PUTCHAR(CILEN_SHORT, ucp); \
578 PUTSHORT(val, ucp); \
580 #define ADDCICHAP(opt, neg, val, digest) \
582 LCPDEBUG(LOG_INFO, ("lcp_addci: CHAP opt=%d %X\n", opt, val)); \
584 PUTCHAR(CILEN_CHAP, ucp); \
585 PUTSHORT(val, ucp); \
586 PUTCHAR(digest, ucp); \
588 #define ADDCILONG(opt, neg, val) \
590 LCPDEBUG(LOG_INFO, ("lcp_addci: L opt=%d %lX\n", opt, val)); \
592 PUTCHAR(CILEN_LONG, ucp); \
595 #define ADDCILQR(opt, neg, val) \
597 LCPDEBUG(LOG_INFO, ("lcp_addci: LQR opt=%d %lX\n", opt, val)); \
599 PUTCHAR(CILEN_LQR, ucp); \
600 PUTSHORT(PPP_LQR, ucp); \
603 #define ADDCICHAR(opt, neg, val) \
605 LCPDEBUG(LOG_INFO, ("lcp_addci: CHAR opt=%d %X '%z'\n", opt, val, val)); \
607 PUTCHAR(CILEN_CHAR, ucp); \
611 ADDCISHORT(CI_MRU
, go
->neg_mru
&& go
->mru
!= PPP_DEFMRU
, go
->mru
);
612 ADDCILONG(CI_ASYNCMAP
, go
->neg_asyncmap
&& go
->asyncmap
!= 0xFFFFFFFFl
, go
->asyncmap
);
613 ADDCICHAP(CI_AUTHTYPE
, go
->neg_chap
, PPP_CHAP
, go
->chap_mdtype
);
614 ADDCISHORT(CI_AUTHTYPE
, !go
->neg_chap
&& go
->neg_upap
, PPP_PAP
);
615 ADDCILQR(CI_QUALITY
, go
->neg_lqr
, go
->lqr_period
);
616 ADDCICHAR(CI_CALLBACK
, go
->neg_cbcp
, CBCP_OPT
);
617 ADDCILONG(CI_MAGICNUMBER
, go
->neg_magicnumber
, go
->magicnumber
);
618 ADDCIVOID(CI_PCOMPRESSION
, go
->neg_pcompression
);
619 ADDCIVOID(CI_ACCOMPRESSION
, go
->neg_accompression
);
621 if (ucp
- start_ucp
!= *lenp
) {
622 /* this should never happen, because peer_mtu should be 1500 */
623 LCPDEBUG(LOG_ERR
, ("Bug in lcp_addci: wrong length\n"));
629 * lcp_ackci - Ack our CIs.
630 * This should not modify any state if the Ack is bad.
637 lcp_ackci(fsm
*f
, u_char
*p
, int len
)
639 lcp_options
*go
= &lcp_gotoptions
[f
->unit
];
640 u_char cilen
, citype
, cichar
;
645 * CIs must be in exactly the same order that we sent.
646 * Check packet length and CI length at each step.
647 * If we find any deviations, then this packet is bad.
649 #define ACKCIVOID(opt, neg) \
651 if ((len -= CILEN_VOID) < 0) \
653 GETCHAR(citype, p); \
655 if (cilen != CILEN_VOID || citype != opt) \
658 #define ACKCISHORT(opt, neg, val) \
660 if ((len -= CILEN_SHORT) < 0) \
662 GETCHAR(citype, p); \
664 if (cilen != CILEN_SHORT || citype != opt) \
666 GETSHORT(cishort, p); \
667 if (cishort != val) \
670 #define ACKCICHAR(opt, neg, val) \
672 if ((len -= CILEN_CHAR) < 0) \
674 GETCHAR(citype, p); \
676 if (cilen != CILEN_CHAR || citype != opt) \
678 GETCHAR(cichar, p); \
682 #define ACKCICHAP(opt, neg, val, digest) \
684 if ((len -= CILEN_CHAP) < 0) \
686 GETCHAR(citype, p); \
688 if (cilen != CILEN_CHAP || citype != opt) \
690 GETSHORT(cishort, p); \
691 if (cishort != val) \
693 GETCHAR(cichar, p); \
694 if (cichar != digest) \
697 #define ACKCILONG(opt, neg, val) \
699 if ((len -= CILEN_LONG) < 0) \
701 GETCHAR(citype, p); \
703 if (cilen != CILEN_LONG || citype != opt) \
705 GETLONG(cilong, p); \
709 #define ACKCILQR(opt, neg, val) \
711 if ((len -= CILEN_LQR) < 0) \
713 GETCHAR(citype, p); \
715 if (cilen != CILEN_LQR || citype != opt) \
717 GETSHORT(cishort, p); \
718 if (cishort != PPP_LQR) \
720 GETLONG(cilong, p); \
725 ACKCISHORT(CI_MRU
, go
->neg_mru
&& go
->mru
!= PPP_DEFMRU
, go
->mru
);
726 ACKCILONG(CI_ASYNCMAP
, go
->neg_asyncmap
&& go
->asyncmap
!= 0xFFFFFFFFl
, go
->asyncmap
);
727 ACKCICHAP(CI_AUTHTYPE
, go
->neg_chap
, PPP_CHAP
, go
->chap_mdtype
);
728 ACKCISHORT(CI_AUTHTYPE
, !go
->neg_chap
&& go
->neg_upap
, PPP_PAP
);
729 ACKCILQR(CI_QUALITY
, go
->neg_lqr
, go
->lqr_period
);
730 ACKCICHAR(CI_CALLBACK
, go
->neg_cbcp
, CBCP_OPT
);
731 ACKCILONG(CI_MAGICNUMBER
, go
->neg_magicnumber
, go
->magicnumber
);
732 ACKCIVOID(CI_PCOMPRESSION
, go
->neg_pcompression
);
733 ACKCIVOID(CI_ACCOMPRESSION
, go
->neg_accompression
);
736 * If there are any remaining CIs, then this packet is bad.
741 LCPDEBUG(LOG_INFO
, ("lcp_acki: Ack\n"));
744 LCPDEBUG(LOG_WARNING
, ("lcp_acki: received bad Ack!\n"));
750 * lcp_nakci - Peer has sent a NAK for some of our CIs.
751 * This should not modify any state if the Nak is bad
752 * or if LCP is in the LS_OPENED state.
759 lcp_nakci(fsm
*f
, u_char
*p
, int len
)
761 lcp_options
*go
= &lcp_gotoptions
[f
->unit
];
762 lcp_options
*wo
= &lcp_wantoptions
[f
->unit
];
763 u_char citype
, cichar
, *next
;
766 lcp_options no
; /* options we've seen Naks for */
767 lcp_options
try; /* options to request next time */
771 BZERO(&no
, sizeof(no
));
775 * Any Nak'd CIs must be in exactly the same order that we sent.
776 * Check packet length and CI length at each step.
777 * If we find any deviations, then this packet is bad.
779 #define NAKCIVOID(opt, neg, code) \
781 len >= CILEN_VOID && \
782 p[1] == CILEN_VOID && \
785 INCPTR(CILEN_VOID, p); \
789 #define NAKCICHAP(opt, neg, code) \
791 len >= CILEN_CHAP && \
792 p[1] == CILEN_CHAP && \
796 GETSHORT(cishort, p); \
797 GETCHAR(cichar, p); \
801 #define NAKCICHAR(opt, neg, code) \
803 len >= CILEN_CHAR && \
804 p[1] == CILEN_CHAR && \
808 GETCHAR(cichar, p); \
812 #define NAKCISHORT(opt, neg, code) \
814 len >= CILEN_SHORT && \
815 p[1] == CILEN_SHORT && \
817 len -= CILEN_SHORT; \
819 GETSHORT(cishort, p); \
823 #define NAKCILONG(opt, neg, code) \
825 len >= CILEN_LONG && \
826 p[1] == CILEN_LONG && \
830 GETLONG(cilong, p); \
834 #define NAKCILQR(opt, neg, code) \
836 len >= CILEN_LQR && \
837 p[1] == CILEN_LQR && \
841 GETSHORT(cishort, p); \
842 GETLONG(cilong, p); \
848 * We don't care if they want to send us smaller packets than
849 * we want. Therefore, accept any MRU less than what we asked for,
850 * but then ignore the new value when setting the MRU in the kernel.
851 * If they send us a bigger MRU than what we asked, accept it, up to
852 * the limit of the default MRU we'd get if we didn't negotiate.
854 if (go
->neg_mru
&& go
->mru
!= PPP_DEFMRU
) {
855 NAKCISHORT(CI_MRU
, neg_mru
,
856 if (cishort
<= wo
->mru
|| cishort
< PPP_DEFMRU
) {
863 * Add any characters they want to our (receive-side) asyncmap.
865 if (go
->neg_asyncmap
&& go
->asyncmap
!= 0xFFFFFFFFl
) {
866 NAKCILONG(CI_ASYNCMAP
, neg_asyncmap
,
867 try.asyncmap
= go
->asyncmap
| cilong
;
872 * If they've nak'd our authentication-protocol, check whether
873 * they are proposing a different protocol, or a different
874 * hash algorithm for CHAP.
876 if ((go
->neg_chap
|| go
->neg_upap
)
877 && len
>= CILEN_SHORT
878 && p
[0] == CI_AUTHTYPE
&& p
[1] >= CILEN_SHORT
&& p
[1] <= len
) {
881 no
.neg_chap
= go
->neg_chap
;
882 no
.neg_upap
= go
->neg_upap
;
884 GETSHORT(cishort
, p
);
885 if (cishort
== PPP_PAP
&& cilen
== CILEN_SHORT
) {
887 * If we were asking for CHAP, they obviously don't want to do it.
888 * If we weren't asking for CHAP, then we were asking for PAP,
889 * in which case this Nak is bad.
896 } else if (cishort
== PPP_CHAP
&& cilen
== CILEN_CHAP
) {
900 * We were asking for CHAP/MD5; they must want a different
901 * algorithm. If they can't do MD5, we'll have to stop
904 if (cichar
!= go
->chap_mdtype
) {
909 * Stop asking for PAP if we were asking for it.
916 * We don't recognize what they're suggesting.
917 * Stop asking for what we were asking for.
924 p
+= cilen
- CILEN_SHORT
;
929 * If they can't cope with our link quality protocol, we'll have
930 * to stop asking for LQR. We haven't got any other protocol.
931 * If they Nak the reporting period, take their value XXX ?
933 NAKCILQR(CI_QUALITY
, neg_lqr
,
934 if (cishort
!= PPP_LQR
) {
937 try.lqr_period
= cilong
;
942 * Only implementing CBCP...not the rest of the callback options
944 NAKCICHAR(CI_CALLBACK
, neg_cbcp
,
949 * Check for a looped-back line.
951 NAKCILONG(CI_MAGICNUMBER
, neg_magicnumber
,
952 try.magicnumber
= magic();
957 * Peer shouldn't send Nak for protocol compression or
958 * address/control compression requests; they should send
959 * a Reject instead. If they send a Nak, treat it as a Reject.
961 NAKCIVOID(CI_PCOMPRESSION
, neg_pcompression
,
962 try.neg_pcompression
= 0;
964 NAKCIVOID(CI_ACCOMPRESSION
, neg_accompression
,
965 try.neg_accompression
= 0;
969 * There may be remaining CIs, if the peer is requesting negotiation
970 * on an option that we didn't include in our request packet.
971 * If we see an option that we requested, or one we've already seen
972 * in this packet, then this packet is bad.
973 * If we wanted to respond by starting to negotiate on the requested
974 * option(s), we could, but we don't, because except for the
975 * authentication type and quality protocol, if we are not negotiating
976 * an option, it is because we were told not to.
977 * For the authentication type, the Nak from the peer means
978 * `let me authenticate myself with you' which is a bit pointless.
979 * For the quality protocol, the Nak means `ask me to send you quality
980 * reports', but if we didn't ask for them, we don't want them.
981 * An option we don't recognize represents the peer asking to
982 * negotiate some option we don't support, so ignore it.
984 while (len
> CILEN_VOID
) {
987 if (cilen
< CILEN_VOID
|| (len
-= cilen
) < 0) {
990 next
= p
+ cilen
- 2;
994 if ((go
->neg_mru
&& go
->mru
!= PPP_DEFMRU
)
995 || no
.neg_mru
|| cilen
!= CILEN_SHORT
) {
998 GETSHORT(cishort
, p
);
999 if (cishort
< PPP_DEFMRU
) {
1004 if ((go
->neg_asyncmap
&& go
->asyncmap
!= 0xFFFFFFFFl
)
1005 || no
.neg_asyncmap
|| cilen
!= CILEN_LONG
) {
1010 if (go
->neg_chap
|| no
.neg_chap
|| go
->neg_upap
|| no
.neg_upap
) {
1014 case CI_MAGICNUMBER
:
1015 if (go
->neg_magicnumber
|| no
.neg_magicnumber
||
1016 cilen
!= CILEN_LONG
) {
1020 case CI_PCOMPRESSION
:
1021 if (go
->neg_pcompression
|| no
.neg_pcompression
1022 || cilen
!= CILEN_VOID
) {
1026 case CI_ACCOMPRESSION
:
1027 if (go
->neg_accompression
|| no
.neg_accompression
1028 || cilen
!= CILEN_VOID
) {
1033 if (go
->neg_lqr
|| no
.neg_lqr
|| cilen
!= CILEN_LQR
) {
1041 /* If there is still anything left, this packet is bad. */
1047 * OK, the Nak is good. Now we can update state.
1049 if (f
->state
!= LS_OPENED
) {
1051 if (++try.numloops
>= lcp_loopbackfail
) {
1052 LCPDEBUG(LOG_NOTICE
, ("Serial line is looped back.\n"));
1053 lcp_close(f
->unit
, "Loopback detected");
1064 LCPDEBUG(LOG_WARNING
, ("lcp_nakci: received bad Nak!\n"));
1070 * lcp_rejci - Peer has Rejected some of our CIs.
1071 * This should not modify any state if the Reject is bad
1072 * or if LCP is in the LS_OPENED state.
1075 * 0 - Reject was bad.
1076 * 1 - Reject was good.
1079 lcp_rejci(fsm
*f
, u_char
*p
, int len
)
1081 lcp_options
*go
= &lcp_gotoptions
[f
->unit
];
1085 lcp_options
try; /* options to request next time */
1090 * Any Rejected CIs must be in exactly the same order that we sent.
1091 * Check packet length and CI length at each step.
1092 * If we find any deviations, then this packet is bad.
1094 #define REJCIVOID(opt, neg) \
1096 len >= CILEN_VOID && \
1097 p[1] == CILEN_VOID && \
1099 len -= CILEN_VOID; \
1100 INCPTR(CILEN_VOID, p); \
1102 LCPDEBUG(LOG_INFO, ("lcp_rejci: void opt %d rejected\n", opt)); \
1104 #define REJCISHORT(opt, neg, val) \
1106 len >= CILEN_SHORT && \
1107 p[1] == CILEN_SHORT && \
1109 len -= CILEN_SHORT; \
1111 GETSHORT(cishort, p); \
1112 /* Check rejected value. */ \
1113 if (cishort != val) { \
1117 LCPDEBUG(LOG_INFO, ("lcp_rejci: short opt %d rejected\n", opt)); \
1119 #define REJCICHAP(opt, neg, val, digest) \
1121 len >= CILEN_CHAP && \
1122 p[1] == CILEN_CHAP && \
1124 len -= CILEN_CHAP; \
1126 GETSHORT(cishort, p); \
1127 GETCHAR(cichar, p); \
1128 /* Check rejected value. */ \
1129 if (cishort != val || cichar != digest) { \
1134 LCPDEBUG(LOG_INFO, ("lcp_rejci: chap opt %d rejected\n", opt)); \
1136 #define REJCILONG(opt, neg, val) \
1138 len >= CILEN_LONG && \
1139 p[1] == CILEN_LONG && \
1141 len -= CILEN_LONG; \
1143 GETLONG(cilong, p); \
1144 /* Check rejected value. */ \
1145 if (cilong != val) { \
1149 LCPDEBUG(LOG_INFO, ("lcp_rejci: long opt %d rejected\n", opt)); \
1151 #define REJCILQR(opt, neg, val) \
1153 len >= CILEN_LQR && \
1154 p[1] == CILEN_LQR && \
1158 GETSHORT(cishort, p); \
1159 GETLONG(cilong, p); \
1160 /* Check rejected value. */ \
1161 if (cishort != PPP_LQR || cilong != val) { \
1165 LCPDEBUG(LOG_INFO, ("lcp_rejci: LQR opt %d rejected\n", opt)); \
1167 #define REJCICBCP(opt, neg, val) \
1169 len >= CILEN_CBCP && \
1170 p[1] == CILEN_CBCP && \
1172 len -= CILEN_CBCP; \
1174 GETCHAR(cichar, p); \
1175 /* Check rejected value. */ \
1176 if (cichar != val) { \
1180 LCPDEBUG(LOG_INFO, ("lcp_rejci: Callback opt %d rejected\n", opt)); \
1183 REJCISHORT(CI_MRU
, neg_mru
, go
->mru
);
1184 REJCILONG(CI_ASYNCMAP
, neg_asyncmap
, go
->asyncmap
);
1185 REJCICHAP(CI_AUTHTYPE
, neg_chap
, PPP_CHAP
, go
->chap_mdtype
);
1186 if (!go
->neg_chap
) {
1187 REJCISHORT(CI_AUTHTYPE
, neg_upap
, PPP_PAP
);
1189 REJCILQR(CI_QUALITY
, neg_lqr
, go
->lqr_period
);
1190 REJCICBCP(CI_CALLBACK
, neg_cbcp
, CBCP_OPT
);
1191 REJCILONG(CI_MAGICNUMBER
, neg_magicnumber
, go
->magicnumber
);
1192 REJCIVOID(CI_PCOMPRESSION
, neg_pcompression
);
1193 REJCIVOID(CI_ACCOMPRESSION
, neg_accompression
);
1196 * If there are any remaining CIs, then this packet is bad.
1202 * Now we can update state.
1204 if (f
->state
!= LS_OPENED
) {
1210 LCPDEBUG(LOG_WARNING
, ("lcp_rejci: received bad Reject!\n"));
1216 * lcp_reqci - Check the peer's requested CIs and send appropriate response.
1218 * Returns: CONFACK, CONFNAK or CONFREJ and input packet modified
1219 * appropriately. If reject_if_disagree is non-zero, doesn't return
1220 * CONFNAK; returns CONFREJ if it can't return CONFACK.
1224 u_char
*inp
, /* Requested CIs */
1225 int *lenp
, /* Length of requested CIs */
1226 int reject_if_disagree
)
1228 lcp_options
*go
= &lcp_gotoptions
[f
->unit
];
1229 lcp_options
*ho
= &lcp_hisoptions
[f
->unit
];
1230 lcp_options
*ao
= &lcp_allowoptions
[f
->unit
];
1231 u_char
*cip
, *next
; /* Pointer to current and next CIs */
1232 int cilen
, citype
; /* Parsed len, type */
1233 u_char cichar
; /* Parsed char value */
1234 u_short cishort
; /* Parsed short value */
1235 u32_t cilong
; /* Parse long value */
1236 int rc
= CONFACK
; /* Final packet return code */
1237 int orc
; /* Individual option return code */
1238 u_char
*p
; /* Pointer to next char to parse */
1239 u_char
*rejp
; /* Pointer to next char in reject frame */
1240 u_char
*nakp
; /* Pointer to next char in Nak frame */
1241 int l
= *lenp
; /* Length left */
1244 size_t traceNdx
= 0;
1248 * Reset all his options.
1250 BZERO(ho
, sizeof(*ho
));
1253 * Process all his options.
1259 orc
= CONFACK
; /* Assume success */
1260 cip
= p
= next
; /* Remember begining of CI */
1261 if (l
< 2 || /* Not enough data for CI header or */
1262 p
[1] < 2 || /* CI length too small or */
1263 p
[1] > l
) { /* CI length too big? */
1264 LCPDEBUG(LOG_WARNING
, ("lcp_reqci: bad CI length!\n"));
1265 orc
= CONFREJ
; /* Reject bad CI */
1266 cilen
= l
; /* Reject till end of packet */
1267 l
= 0; /* Don't loop again */
1271 GETCHAR(citype
, p
); /* Parse CI type */
1272 GETCHAR(cilen
, p
); /* Parse CI length */
1273 l
-= cilen
; /* Adjust remaining length */
1274 next
+= cilen
; /* Step to next CI */
1276 switch (citype
) { /* Check CI type */
1278 if (!ao
->neg_mru
) { /* Allow option? */
1279 LCPDEBUG(LOG_INFO
, ("lcp_reqci: Reject MRU - not allowed\n"));
1280 orc
= CONFREJ
; /* Reject CI */
1282 } else if (cilen
!= CILEN_SHORT
) { /* Check CI length */
1283 LCPDEBUG(LOG_INFO
, ("lcp_reqci: Reject MRU - bad length\n"));
1284 orc
= CONFREJ
; /* Reject CI */
1287 GETSHORT(cishort
, p
); /* Parse MRU */
1290 * He must be able to receive at least our minimum.
1291 * No need to check a maximum. If he sends a large number,
1292 * we'll just ignore it.
1294 if (cishort
< PPP_MINMRU
) {
1295 LCPDEBUG(LOG_INFO
, ("lcp_reqci: Nak - MRU too small\n"));
1296 orc
= CONFNAK
; /* Nak CI */
1297 PUTCHAR(CI_MRU
, nakp
);
1298 PUTCHAR(CILEN_SHORT
, nakp
);
1299 PUTSHORT(PPP_MINMRU
, nakp
); /* Give him a hint */
1302 ho
->neg_mru
= 1; /* Remember he sent MRU */
1303 ho
->mru
= cishort
; /* And remember value */
1305 snprintf(&traceBuf
[traceNdx
], sizeof(traceBuf
), " MRU %d", cishort
);
1306 traceNdx
= strlen(traceBuf
);
1311 if (!ao
->neg_asyncmap
) {
1312 LCPDEBUG(LOG_INFO
, ("lcp_reqci: Reject ASYNCMAP not allowed\n"));
1315 } else if (cilen
!= CILEN_LONG
) {
1316 LCPDEBUG(LOG_INFO
, ("lcp_reqci: Reject ASYNCMAP bad length\n"));
1323 * Asyncmap must have set at least the bits
1324 * which are set in lcp_allowoptions[unit].asyncmap.
1326 if ((ao
->asyncmap
& ~cilong
) != 0) {
1327 LCPDEBUG(LOG_INFO
, ("lcp_reqci: Nak ASYNCMAP %lX missing %lX\n",
1328 cilong
, ao
->asyncmap
));
1330 PUTCHAR(CI_ASYNCMAP
, nakp
);
1331 PUTCHAR(CILEN_LONG
, nakp
);
1332 PUTLONG(ao
->asyncmap
| cilong
, nakp
);
1335 ho
->neg_asyncmap
= 1;
1336 ho
->asyncmap
= cilong
;
1338 snprintf(&traceBuf
[traceNdx
], sizeof(traceBuf
), " ASYNCMAP=%lX", cilong
);
1339 traceNdx
= strlen(traceBuf
);
1344 if (cilen
< CILEN_SHORT
) {
1345 LCPDEBUG(LOG_INFO
, ("lcp_reqci: Reject AUTHTYPE missing arg\n"));
1348 } else if (!(ao
->neg_upap
|| ao
->neg_chap
)) {
1350 * Reject the option if we're not willing to authenticate.
1352 LCPDEBUG(LOG_INFO
, ("lcp_reqci: Reject AUTHTYPE not allowed\n"));
1356 GETSHORT(cishort
, p
);
1359 * Authtype must be UPAP or CHAP.
1361 * Note: if both ao->neg_upap and ao->neg_chap are set,
1362 * and the peer sends a Configure-Request with two
1363 * authenticate-protocol requests, one for CHAP and one
1364 * for UPAP, then we will reject the second request.
1365 * Whether we end up doing CHAP or UPAP depends then on
1366 * the ordering of the CIs in the peer's Configure-Request.
1369 if (cishort
== PPP_PAP
) {
1370 if (ho
->neg_chap
) { /* we've already accepted CHAP */
1371 LCPDEBUG(LOG_WARNING
, ("lcp_reqci: Reject AUTHTYPE PAP already accepted\n"));
1374 } else if (cilen
!= CILEN_SHORT
) {
1375 LCPDEBUG(LOG_WARNING
, ("lcp_reqci: Reject AUTHTYPE PAP bad len\n"));
1379 if (!ao
->neg_upap
) { /* we don't want to do PAP */
1380 LCPDEBUG(LOG_WARNING
, ("lcp_reqci: Nak AUTHTYPE PAP not allowed\n"));
1381 orc
= CONFNAK
; /* NAK it and suggest CHAP */
1382 PUTCHAR(CI_AUTHTYPE
, nakp
);
1383 PUTCHAR(CILEN_CHAP
, nakp
);
1384 PUTSHORT(PPP_CHAP
, nakp
);
1385 PUTCHAR(ao
->chap_mdtype
, nakp
);
1390 snprintf(&traceBuf
[traceNdx
], sizeof(traceBuf
), " PAP (%X)", cishort
);
1391 traceNdx
= strlen(traceBuf
);
1395 if (cishort
== PPP_CHAP
) {
1396 if (ho
->neg_upap
) { /* we've already accepted PAP */
1397 LCPDEBUG(LOG_WARNING
, ("lcp_reqci: Reject AUTHTYPE CHAP accepted PAP\n"));
1400 } else if (cilen
!= CILEN_CHAP
) {
1401 LCPDEBUG(LOG_WARNING
, ("lcp_reqci: Reject AUTHTYPE CHAP bad len\n"));
1405 if (!ao
->neg_chap
) { /* we don't want to do CHAP */
1406 LCPDEBUG(LOG_WARNING
, ("lcp_reqci: Nak AUTHTYPE CHAP not allowed\n"));
1407 orc
= CONFNAK
; /* NAK it and suggest PAP */
1408 PUTCHAR(CI_AUTHTYPE
, nakp
);
1409 PUTCHAR(CILEN_SHORT
, nakp
);
1410 PUTSHORT(PPP_PAP
, nakp
);
1413 GETCHAR(cichar
, p
); /* get digest type*/
1414 if (cichar
!= CHAP_DIGEST_MD5
1416 && cichar
!= CHAP_MICROSOFT
1419 LCPDEBUG(LOG_WARNING
, ("lcp_reqci: Nak AUTHTYPE CHAP digest=%d\n", (int)cichar
));
1421 PUTCHAR(CI_AUTHTYPE
, nakp
);
1422 PUTCHAR(CILEN_CHAP
, nakp
);
1423 PUTSHORT(PPP_CHAP
, nakp
);
1424 PUTCHAR(ao
->chap_mdtype
, nakp
);
1428 snprintf(&traceBuf
[traceNdx
], sizeof(traceBuf
), " CHAP %X,%d", cishort
, (int)cichar
);
1429 traceNdx
= strlen(traceBuf
);
1431 ho
->chap_mdtype
= cichar
; /* save md type */
1437 * We don't recognize the protocol they're asking for.
1438 * Nak it with something we're willing to do.
1439 * (At this point we know ao->neg_upap || ao->neg_chap.)
1442 PUTCHAR(CI_AUTHTYPE
, nakp
);
1444 LCPDEBUG(LOG_WARNING
, ("lcp_reqci: Nak AUTHTYPE %d req CHAP\n", cishort
));
1445 PUTCHAR(CILEN_CHAP
, nakp
);
1446 PUTSHORT(PPP_CHAP
, nakp
);
1447 PUTCHAR(ao
->chap_mdtype
, nakp
);
1449 LCPDEBUG(LOG_WARNING
, ("lcp_reqci: Nak AUTHTYPE %d req PAP\n", cishort
));
1450 PUTCHAR(CILEN_SHORT
, nakp
);
1451 PUTSHORT(PPP_PAP
, nakp
);
1456 GETSHORT(cishort
, p
);
1459 snprintf(&traceBuf
[traceNdx
], sizeof(traceBuf
), " QUALITY (%x %x)", cishort
, (unsigned int) cilong
);
1460 traceNdx
= strlen(traceBuf
);
1464 cilen
!= CILEN_LQR
) {
1470 * Check the protocol and the reporting period.
1471 * XXX When should we Nak this, and what with?
1473 if (cishort
!= PPP_LQR
) {
1475 PUTCHAR(CI_QUALITY
, nakp
);
1476 PUTCHAR(CILEN_LQR
, nakp
);
1477 PUTSHORT(PPP_LQR
, nakp
);
1478 PUTLONG(ao
->lqr_period
, nakp
);
1483 case CI_MAGICNUMBER
:
1484 if (!(ao
->neg_magicnumber
|| go
->neg_magicnumber
) ||
1485 cilen
!= CILEN_LONG
) {
1491 snprintf(&traceBuf
[traceNdx
], sizeof(traceBuf
), " MAGICNUMBER (%lX)", cilong
);
1492 traceNdx
= strlen(traceBuf
);
1496 * He must have a different magic number.
1498 if (go
->neg_magicnumber
&&
1499 cilong
== go
->magicnumber
) {
1500 cilong
= magic(); /* Don't put magic() inside macro! */
1502 PUTCHAR(CI_MAGICNUMBER
, nakp
);
1503 PUTCHAR(CILEN_LONG
, nakp
);
1504 PUTLONG(cilong
, nakp
);
1507 ho
->neg_magicnumber
= 1;
1508 ho
->magicnumber
= cilong
;
1512 case CI_PCOMPRESSION
:
1514 snprintf(&traceBuf
[traceNdx
], sizeof(traceBuf
), " PCOMPRESSION");
1515 traceNdx
= strlen(traceBuf
);
1517 if (!ao
->neg_pcompression
||
1518 cilen
!= CILEN_VOID
) {
1522 ho
->neg_pcompression
= 1;
1525 case CI_ACCOMPRESSION
:
1527 snprintf(&traceBuf
[traceNdx
], sizeof(traceBuf
), " ACCOMPRESSION");
1528 traceNdx
= strlen(traceBuf
);
1530 if (!ao
->neg_accompression
||
1531 cilen
!= CILEN_VOID
) {
1535 ho
->neg_accompression
= 1;
1540 snprintf(&traceBuf
[traceNdx
], sizeof(traceBuf
), " CI_MRRU");
1541 traceNdx
= strlen(traceBuf
);
1548 snprintf(&traceBuf
[traceNdx
], sizeof(traceBuf
), " CI_SSNHF");
1549 traceNdx
= strlen(traceBuf
);
1556 snprintf(&traceBuf
[traceNdx
], sizeof(traceBuf
), " CI_EPDISC");
1557 traceNdx
= strlen(traceBuf
);
1564 snprintf(&traceBuf
[traceNdx
], sizeof(traceBuf
), " unknown %d", citype
);
1565 traceNdx
= strlen(traceBuf
);
1573 if (traceNdx
>= 80 - 32) {
1574 LCPDEBUG(LOG_INFO
, ("lcp_reqci: rcvd%s\n", traceBuf
));
1578 if (orc
== CONFACK
&& /* Good CI */
1579 rc
!= CONFACK
) { /* but prior CI wasnt? */
1580 continue; /* Don't send this one */
1583 if (orc
== CONFNAK
) { /* Nak this CI? */
1584 if (reject_if_disagree
/* Getting fed up with sending NAKs? */
1585 && citype
!= CI_MAGICNUMBER
) {
1586 orc
= CONFREJ
; /* Get tough if so */
1588 if (rc
== CONFREJ
) { /* Rejecting prior CI? */
1589 continue; /* Don't send this one */
1594 if (orc
== CONFREJ
) { /* Reject this CI */
1596 if (cip
!= rejp
) { /* Need to move rejected CI? */
1597 BCOPY(cip
, rejp
, cilen
); /* Move it */
1599 INCPTR(cilen
, rejp
); /* Update output pointer */
1604 * If we wanted to send additional NAKs (for unsent CIs), the
1605 * code would go here. The extra NAKs would go at *nakp.
1606 * At present there are no cases where we want to ask the
1607 * peer to negotiate an option.
1612 *lenp
= (int)(next
- inp
);
1616 * Copy the Nak'd options from the nak_buffer to the caller's buffer.
1618 *lenp
= (int)(nakp
- nak_buffer
);
1619 BCOPY(nak_buffer
, inp
, *lenp
);
1622 *lenp
= (int)(rejp
- inp
);
1628 LCPDEBUG(LOG_INFO
, ("lcp_reqci: %s\n", traceBuf
));
1631 LCPDEBUG(LOG_INFO
, ("lcp_reqci: returning CONF%s.\n", CODENAME(rc
)));
1632 return (rc
); /* Return final code */
1637 * lcp_up - LCP has come UP.
1642 lcp_options
*wo
= &lcp_wantoptions
[f
->unit
];
1643 lcp_options
*ho
= &lcp_hisoptions
[f
->unit
];
1644 lcp_options
*go
= &lcp_gotoptions
[f
->unit
];
1645 lcp_options
*ao
= &lcp_allowoptions
[f
->unit
];
1647 if (!go
->neg_magicnumber
) {
1648 go
->magicnumber
= 0;
1650 if (!ho
->neg_magicnumber
) {
1651 ho
->magicnumber
= 0;
1655 * Set our MTU to the smaller of the MTU we wanted and
1656 * the MRU our peer wanted. If we negotiated an MRU,
1657 * set our MRU to the larger of value we wanted and
1658 * the value we got in the negotiation.
1660 ppp_send_config(f
->unit
, LWIP_MIN(ao
->mru
, (ho
->neg_mru
? ho
->mru
: PPP_MRU
)),
1661 (ho
->neg_asyncmap
? ho
->asyncmap
: 0xffffffffl
),
1662 ho
->neg_pcompression
, ho
->neg_accompression
);
1664 * If the asyncmap hasn't been negotiated, we really should
1665 * set the receive asyncmap to ffffffff, but we set it to 0
1666 * for backwards contemptibility.
1668 ppp_recv_config(f
->unit
, (go
->neg_mru
? LWIP_MAX(wo
->mru
, go
->mru
): PPP_MRU
),
1669 (go
->neg_asyncmap
? go
->asyncmap
: 0x00000000),
1670 go
->neg_pcompression
, go
->neg_accompression
);
1673 peer_mru
[f
->unit
] = ho
->mru
;
1676 lcp_echo_lowerup(f
->unit
); /* Enable echo messages */
1678 link_established(f
->unit
); /* The link is up; authenticate now */
1683 * lcp_down - LCP has gone DOWN.
1685 * Alert other protocols.
1690 lcp_options
*go
= &lcp_gotoptions
[f
->unit
];
1692 lcp_echo_lowerdown(f
->unit
);
1696 ppp_send_config(f
->unit
, PPP_MRU
, 0xffffffffl
, 0, 0);
1697 ppp_recv_config(f
->unit
, PPP_MRU
,
1698 (go
->neg_asyncmap
? go
->asyncmap
: 0x00000000),
1699 go
->neg_pcompression
, go
->neg_accompression
);
1700 peer_mru
[f
->unit
] = PPP_MRU
;
1705 * lcp_starting - LCP needs the lower layer up.
1708 lcp_starting(fsm
*f
)
1710 link_required(f
->unit
); /* lwip: currently does nothing */
1715 * lcp_finished - LCP has finished with the lower layer.
1718 lcp_finished(fsm
*f
)
1720 link_terminated(f
->unit
); /* we are finished with the link */
1724 #if PPP_ADDITIONAL_CALLBACKS
1726 * print_string - print a readable representation of a string using
1730 print_string( char *p
, int len
, void (*printer
) (void *, char *, ...), void *arg
)
1735 for (; len
> 0; --len
) {
1737 if (' ' <= c
&& c
<= '~') {
1738 if (c
== '\\' || c
== '"') {
1741 printer(arg
, "%c", c
);
1745 printer(arg
, "\\n");
1748 printer(arg
, "\\r");
1751 printer(arg
, "\\t");
1754 printer(arg
, "\\%.3o", c
);
1763 * lcp_printpkt - print the contents of an LCP packet.
1765 static char *lcp_codenames
[] = {
1766 "ConfReq", "ConfAck", "ConfNak", "ConfRej",
1767 "TermReq", "TermAck", "CodeRej", "ProtRej",
1768 "EchoReq", "EchoRep", "DiscReq"
1772 lcp_printpkt( u_char
*p
, int plen
, void (*printer
) (void *, char *, ...), void *arg
)
1774 int code
, id
, len
, olen
;
1775 u_char
*pstart
, *optend
;
1779 if (plen
< HEADERLEN
) {
1786 if (len
< HEADERLEN
|| len
> plen
) {
1790 if (code
>= 1 && code
<= sizeof(lcp_codenames
) / sizeof(char *)) {
1791 printer(arg
, " %s", lcp_codenames
[code
-1]);
1793 printer(arg
, " code=0x%x", code
);
1795 printer(arg
, " id=0x%x", id
);
1802 /* print option list */
1807 if (olen
< 2 || olen
> len
) {
1815 if (olen
== CILEN_SHORT
) {
1817 GETSHORT(cishort
, p
);
1818 printer(arg
, "mru %d", cishort
);
1822 if (olen
== CILEN_LONG
) {
1825 printer(arg
, "asyncmap 0x%lx", cilong
);
1829 if (olen
>= CILEN_SHORT
) {
1831 printer(arg
, "auth ");
1832 GETSHORT(cishort
, p
);
1835 printer(arg
, "pap");
1838 printer(arg
, "chap");
1841 printer(arg
, "0x%x", cishort
);
1846 if (olen
>= CILEN_SHORT
) {
1848 printer(arg
, "quality ");
1849 GETSHORT(cishort
, p
);
1852 printer(arg
, "lqr");
1855 printer(arg
, "0x%x", cishort
);
1860 if (olen
>= CILEN_CHAR
) {
1862 printer(arg
, "callback ");
1863 GETSHORT(cishort
, p
);
1866 printer(arg
, "CBCP");
1869 printer(arg
, "0x%x", cishort
);
1873 case CI_MAGICNUMBER
:
1874 if (olen
== CILEN_LONG
) {
1877 printer(arg
, "magic 0x%x", cilong
);
1880 case CI_PCOMPRESSION
:
1881 if (olen
== CILEN_VOID
) {
1883 printer(arg
, "pcomp");
1886 case CI_ACCOMPRESSION
:
1887 if (olen
== CILEN_VOID
) {
1889 printer(arg
, "accomp");
1893 while (p
< optend
) {
1895 printer(arg
, " %.2x", code
);
1903 if (len
> 0 && *p
>= ' ' && *p
< 0x7f) {
1905 print_string((char*)p
, len
, printer
, arg
);
1916 printer(arg
, " magic=0x%x", cilong
);
1923 /* print the rest of the bytes in the packet */
1924 for (; len
> 0; --len
) {
1926 printer(arg
, " %.2x", code
);
1929 return (int)(p
- pstart
);
1931 #endif /* PPP_ADDITIONAL_CALLBACKS */
1934 * Time to shut down the link because there is nothing out there.
1937 LcpLinkFailure (fsm
*f
)
1939 if (f
->state
== LS_OPENED
) {
1940 LCPDEBUG(LOG_INFO
, ("No response to %d echo-requests\n", lcp_echos_pending
));
1941 LCPDEBUG(LOG_NOTICE
, ("Serial link appears to be disconnected.\n"));
1942 lcp_close(f
->unit
, "Peer not responding");
1947 * Timer expired for the LCP echo requests from this process.
1950 LcpEchoCheck (fsm
*f
)
1952 LcpSendEchoRequest (f
);
1955 * Start the timer for the next interval.
1957 LWIP_ASSERT("lcp_echo_timer_running == 0", lcp_echo_timer_running
== 0);
1959 TIMEOUT (LcpEchoTimeout
, f
, lcp_echo_interval
);
1960 lcp_echo_timer_running
= 1;
1964 * LcpEchoTimeout - Timer expired on the LCP echo
1967 LcpEchoTimeout (void *arg
)
1969 if (lcp_echo_timer_running
!= 0) {
1970 lcp_echo_timer_running
= 0;
1971 LcpEchoCheck ((fsm
*) arg
);
1976 * LcpEchoReply - LCP has received a reply to the echo
1979 lcp_received_echo_reply (fsm
*f
, int id
, u_char
*inp
, int len
)
1983 LWIP_UNUSED_ARG(id
);
1985 /* Check the magic number - don't count replies from ourselves. */
1987 LCPDEBUG(LOG_WARNING
, ("lcp: received short Echo-Reply, length %d\n", len
));
1990 GETLONG(magic
, inp
);
1991 if (lcp_gotoptions
[f
->unit
].neg_magicnumber
&& magic
== lcp_gotoptions
[f
->unit
].magicnumber
) {
1992 LCPDEBUG(LOG_WARNING
, ("appear to have received our own echo-reply!\n"));
1996 /* Reset the number of outstanding echo frames */
1997 lcp_echos_pending
= 0;
2001 * LcpSendEchoRequest - Send an echo request frame to the peer
2004 LcpSendEchoRequest (fsm
*f
)
2007 u_char pkt
[4], *pktp
;
2010 * Detect the failure of the peer at this point.
2012 if (lcp_echo_fails
!= 0) {
2013 if (lcp_echos_pending
>= lcp_echo_fails
) {
2015 lcp_echos_pending
= 0;
2020 * Make and send the echo request frame.
2022 if (f
->state
== LS_OPENED
) {
2023 lcp_magic
= lcp_gotoptions
[f
->unit
].magicnumber
;
2025 PUTLONG(lcp_magic
, pktp
);
2026 fsm_sdata(f
, ECHOREQ
, (u_char
)(lcp_echo_number
++ & 0xFF), pkt
, (int)(pktp
- pkt
));
2027 ++lcp_echos_pending
;
2032 * lcp_echo_lowerup - Start the timer for the LCP frame
2036 lcp_echo_lowerup (int unit
)
2038 fsm
*f
= &lcp_fsm
[unit
];
2040 /* Clear the parameters for generating echo frames */
2041 lcp_echos_pending
= 0;
2042 lcp_echo_number
= 0;
2043 lcp_echo_timer_running
= 0;
2045 /* If a timeout interval is specified then start the timer */
2046 if (lcp_echo_interval
!= 0) {
2052 * lcp_echo_lowerdown - Stop the timer for the LCP frame
2056 lcp_echo_lowerdown (int unit
)
2058 fsm
*f
= &lcp_fsm
[unit
];
2060 if (lcp_echo_timer_running
!= 0) {
2061 UNTIMEOUT (LcpEchoTimeout
, f
);
2062 lcp_echo_timer_running
= 0;
2066 #endif /* PPP_SUPPORT */