2 * PPP Finite State Machine for LCP/IPCP
4 * Written by Toshiharu OHNO (tony-o@iij.ad.jp)
6 * Copyright (C) 1993, Internet Initiative Japan, Inc. All rights reserverd.
8 * Redistribution and use in source and binary forms are permitted
9 * provided that the above copyright notice and this paragraph are
10 * duplicated in all such forms and that any documentation,
11 * advertising materials, and other materials related to such
12 * distribution and use acknowledge that the software was developed
13 * by the Internet Initiative Japan, Inc. The name of the
14 * IIJ may not be used to endorse or promote products derived
15 * from this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
18 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
25 #include <sys/param.h>
26 #include <netinet/in.h>
27 #include <netinet/in_systm.h>
28 #include <netinet/ip.h>
44 #include "throughput.h"
45 #include "slcompress.h"
48 #include "descriptor.h"
61 static void FsmSendConfigReq(struct fsm *);
62 static void FsmSendTerminateReq(struct fsm *);
63 static void FsmInitRestartCounter(struct fsm *, int);
65 typedef void (recvfn)(struct fsm *, struct fsmheader *, struct mbuf *);
66 static recvfn FsmRecvConfigReq, FsmRecvConfigAck, FsmRecvConfigNak,
67 FsmRecvConfigRej, FsmRecvTermReq, FsmRecvTermAck,
68 FsmRecvCodeRej, FsmRecvProtoRej, FsmRecvEchoReq,
69 FsmRecvEchoRep, FsmRecvDiscReq, FsmRecvIdent,
70 FsmRecvTimeRemain, FsmRecvResetReq, FsmRecvResetAck;
72 static const struct fsmcodedesc {
74 unsigned check_reqid : 1;
75 unsigned inc_reqid : 1;
78 { FsmRecvConfigReq, 0, 0, "ConfigReq" },
79 { FsmRecvConfigAck, 1, 1, "ConfigAck" },
80 { FsmRecvConfigNak, 1, 1, "ConfigNak" },
81 { FsmRecvConfigRej, 1, 1, "ConfigRej" },
82 { FsmRecvTermReq, 0, 0, "TerminateReq" },
83 { FsmRecvTermAck, 1, 1, "TerminateAck" },
84 { FsmRecvCodeRej, 0, 0, "CodeRej" },
85 { FsmRecvProtoRej, 0, 0, "ProtocolRej" },
86 { FsmRecvEchoReq, 0, 0, "EchoRequest" },
87 { FsmRecvEchoRep, 0, 0, "EchoReply" },
88 { FsmRecvDiscReq, 0, 0, "DiscardReq" },
89 { FsmRecvIdent, 0, 1, "Ident" },
90 { FsmRecvTimeRemain,0, 0, "TimeRemain" },
91 { FsmRecvResetReq, 0, 0, "ResetReq" },
92 { FsmRecvResetAck, 0, 1, "ResetAck" }
98 if (code == 0 || code > sizeof FsmCodes / sizeof FsmCodes[0])
100 return FsmCodes[code-1].name;
104 State2Nam(u_int state)
106 static const char * const StateNames[] = {
107 "Initial", "Starting", "Closed", "Stopped", "Closing", "Stopping",
108 "Req-Sent", "Ack-Rcvd", "Ack-Sent", "Opened",
111 if (state >= sizeof StateNames / sizeof StateNames[0])
113 return StateNames[state];
117 StoppedTimeout(void *v)
119 struct fsm *fp = (struct fsm *)v;
121 log_Printf(fp->LogLevel, "%s: Stopped timer expired\n", fp->link->name);
122 if (fp->OpenTimer.state == TIMER_RUNNING) {
123 log_Printf(LogWARN, "%s: %s: aborting open delay due to stopped timer\n",
124 fp->link->name, fp->name);
125 timer_Stop(&fp->OpenTimer);
127 if (fp->state == ST_STOPPED)
132 fsm_Init(struct fsm *fp, const char *name, u_short proto, int mincode,
133 int maxcode, int LogLevel, struct bundle *bundle,
134 struct link *l, const struct fsm_parent *parent,
135 struct fsm_callbacks *fn, const char * const timer_names[3])
139 fp->min_code = mincode;
140 fp->max_code = maxcode;
141 fp->state = fp->min_code > CODE_TERMACK ? ST_OPENED : ST_INITIAL;
144 fp->more.reqs = fp->more.naks = fp->more.rejs = 3;
145 memset(&fp->FsmTimer, '\0', sizeof fp->FsmTimer);
146 memset(&fp->OpenTimer, '\0', sizeof fp->OpenTimer);
147 memset(&fp->StoppedTimer, '\0', sizeof fp->StoppedTimer);
148 fp->LogLevel = LogLevel;
153 fp->FsmTimer.name = timer_names[0];
154 fp->OpenTimer.name = timer_names[1];
155 fp->StoppedTimer.name = timer_names[2];
159 NewState(struct fsm *fp, int new)
161 log_Printf(fp->LogLevel, "%s: State change %s --> %s\n",
162 fp->link->name, State2Nam(fp->state), State2Nam(new));
163 if (fp->state == ST_STOPPED && fp->StoppedTimer.state == TIMER_RUNNING)
164 timer_Stop(&fp->StoppedTimer);
166 if ((new >= ST_INITIAL && new <= ST_STOPPED) || (new == ST_OPENED)) {
167 timer_Stop(&fp->FsmTimer);
168 if (new == ST_STOPPED && fp->StoppedTimer.load) {
169 timer_Stop(&fp->StoppedTimer);
170 fp->StoppedTimer.func = StoppedTimeout;
171 fp->StoppedTimer.arg = (void *) fp;
172 timer_Start(&fp->StoppedTimer);
178 fsm_Output(struct fsm *fp, u_int code, u_int id, u_char *ptr, int count,
185 if (log_IsKept(fp->LogLevel)) {
186 log_Printf(fp->LogLevel, "%s: Send%s(%d) state = %s\n",
187 fp->link->name, Code2Nam(code), id, State2Nam(fp->state));
193 (*fp->fn->DecodeConfig)(fp, ptr, count, MODE_NOP, NULL);
194 if (count < sizeof(struct fsmconfig))
195 log_Printf(fp->LogLevel, " [EMPTY]\n");
200 plen = sizeof(struct fsmheader) + count;
203 lh.length = htons(plen);
204 bp = m_get(plen, mtype);
205 memcpy(MBUF_CTOP(bp), &lh, sizeof(struct fsmheader));
207 memcpy(MBUF_CTOP(bp) + sizeof(struct fsmheader), ptr, count);
208 log_DumpBp(LogDEBUG, "fsm_Output", bp);
209 link_PushPacket(fp->link, bp, fp->bundle, LINK_QUEUES(fp->link) - 1,
212 if (code == CODE_CONFIGREJ)
213 lcp_SendIdentification(&fp->link->lcp);
219 struct fsm *fp = (struct fsm *)v;
221 timer_Stop(&fp->OpenTimer);
222 if (fp->state <= ST_STOPPED) {
223 if (fp->state != ST_STARTING) {
225 * In practice, we're only here in ST_STOPPED (when delaying the
226 * first config request) or ST_CLOSED (when openmode == 0).
228 * The ST_STOPPED bit is breaking the RFC already :-(
230 * According to the RFC (1661) state transition table, a TLS isn't
231 * required for an Open event when state == Closed, but the RFC
232 * must be wrong as TLS hasn't yet been called (since the last TLF)
233 * ie, Initial gets an `Up' event, Closing gets a RTA etc.
235 (*fp->fn->LayerStart)(fp);
236 (*fp->parent->LayerStart)(fp->parent->object, fp);
238 FsmInitRestartCounter(fp, FSM_REQ_TIMER);
239 FsmSendConfigReq(fp);
240 NewState(fp, ST_REQSENT);
245 fsm_Open(struct fsm *fp)
249 NewState(fp, ST_STARTING);
250 (*fp->fn->LayerStart)(fp);
251 (*fp->parent->LayerStart)(fp->parent->object, fp);
254 if (fp->open_mode == OPEN_PASSIVE) {
255 NewState(fp, ST_STOPPED); /* XXX: This is a hack ! */
256 } else if (fp->open_mode > 0) {
257 if (fp->open_mode > 1)
258 log_Printf(LogPHASE, "%s: Entering STOPPED state for %d seconds\n",
259 fp->link->name, fp->open_mode);
260 NewState(fp, ST_STOPPED); /* XXX: This is a not-so-bad hack ! */
261 timer_Stop(&fp->OpenTimer);
262 fp->OpenTimer.load = fp->open_mode * SECTICKS;
263 fp->OpenTimer.func = FsmOpenNow;
264 fp->OpenTimer.arg = (void *)fp;
265 timer_Start(&fp->OpenTimer);
269 case ST_STOPPED: /* XXX: restart option */
273 case ST_OPENED: /* XXX: restart option */
275 case ST_CLOSING: /* XXX: restart option */
276 case ST_STOPPING: /* XXX: restart option */
277 NewState(fp, ST_STOPPING);
283 fsm_Up(struct fsm *fp)
287 log_Printf(fp->LogLevel, "FSM: Using \"%s\" as a transport\n",
289 NewState(fp, ST_CLOSED);
292 FsmInitRestartCounter(fp, FSM_REQ_TIMER);
293 FsmSendConfigReq(fp);
294 NewState(fp, ST_REQSENT);
297 log_Printf(fp->LogLevel, "%s: Oops, Up at %s\n",
298 fp->link->name, State2Nam(fp->state));
304 fsm_Down(struct fsm *fp)
308 NewState(fp, ST_INITIAL);
311 /* This TLF contradicts the RFC (1661), which ``misses it out'' ! */
312 (*fp->fn->LayerFinish)(fp);
313 NewState(fp, ST_INITIAL);
314 (*fp->parent->LayerFinish)(fp->parent->object, fp);
317 NewState(fp, ST_STARTING);
318 (*fp->fn->LayerStart)(fp);
319 (*fp->parent->LayerStart)(fp->parent->object, fp);
325 NewState(fp, ST_STARTING);
328 (*fp->fn->LayerDown)(fp);
329 NewState(fp, ST_STARTING);
330 (*fp->parent->LayerDown)(fp->parent->object, fp);
336 fsm_Close(struct fsm *fp)
340 (*fp->fn->LayerFinish)(fp);
341 NewState(fp, ST_INITIAL);
342 (*fp->parent->LayerFinish)(fp->parent->object, fp);
345 NewState(fp, ST_CLOSED);
348 NewState(fp, ST_CLOSING);
351 (*fp->fn->LayerDown)(fp);
352 FsmInitRestartCounter(fp, FSM_TRM_TIMER);
353 FsmSendTerminateReq(fp);
354 NewState(fp, ST_CLOSING);
355 (*fp->parent->LayerDown)(fp->parent->object, fp);
360 FsmInitRestartCounter(fp, FSM_TRM_TIMER);
361 FsmSendTerminateReq(fp);
362 NewState(fp, ST_CLOSING);
371 FsmSendConfigReq(struct fsm *fp)
373 if (fp->more.reqs-- > 0 && fp->restart-- > 0) {
374 (*fp->fn->SendConfigReq)(fp);
375 timer_Start(&fp->FsmTimer); /* Start restart timer */
377 if (fp->more.reqs < 0)
378 log_Printf(LogPHASE, "%s: Too many %s REQs sent - abandoning "
379 "negotiation\n", fp->link->name, fp->name);
380 lcp_SendIdentification(&fp->link->lcp);
386 FsmSendTerminateReq(struct fsm *fp)
388 fsm_Output(fp, CODE_TERMREQ, fp->reqid, NULL, 0, MB_UNKNOWN);
389 (*fp->fn->SentTerminateReq)(fp);
390 timer_Start(&fp->FsmTimer); /* Start restart timer */
391 fp->restart--; /* Decrement restart counter */
400 struct fsm *fp = (struct fsm *)v;
406 FsmSendTerminateReq(fp);
410 FsmSendConfigReq(fp);
413 FsmSendConfigReq(fp);
414 NewState(fp, ST_REQSENT);
417 timer_Start(&fp->FsmTimer);
421 (*fp->fn->LayerFinish)(fp);
422 NewState(fp, ST_CLOSED);
423 (*fp->parent->LayerFinish)(fp->parent->object, fp);
426 (*fp->fn->LayerFinish)(fp);
427 NewState(fp, ST_STOPPED);
428 (*fp->parent->LayerFinish)(fp->parent->object, fp);
430 case ST_REQSENT: /* XXX: 3p */
433 (*fp->fn->LayerFinish)(fp);
434 NewState(fp, ST_STOPPED);
435 (*fp->parent->LayerFinish)(fp->parent->object, fp);
442 FsmInitRestartCounter(struct fsm *fp, int what)
444 timer_Stop(&fp->FsmTimer);
445 fp->FsmTimer.func = FsmTimeout;
446 fp->FsmTimer.arg = (void *)fp;
447 (*fp->fn->InitRestartCounter)(fp, what);
451 * Actions when receive packets
454 FsmRecvConfigReq(struct fsm *fp, struct fsmheader *lhp, struct mbuf *bp)
457 struct fsm_decode dec;
462 flen = ntohs(lhp->length) - sizeof *lhp;
464 log_Printf(LogWARN, "%s: FsmRecvConfigReq: plen (%d) < flen (%d)\n",
465 fp->link->name, plen, flen);
470 /* Check and process easy case */
473 if (fp->proto == PROTO_CCP && fp->link->lcp.fsm.state == ST_OPENED) {
475 * ccp_SetOpenMode() leaves us in initial if we're disabling
476 * & denying everything.
478 bp = m_prepend(bp, lhp, sizeof *lhp, 2);
479 bp = proto_Prepend(bp, fp->proto, 0, 0);
481 lcp_SendProtoRej(&fp->link->lcp, MBUF_CTOP(bp), bp->m_len);
487 log_Printf(fp->LogLevel, "%s: Oops, RCR in %s.\n",
488 fp->link->name, State2Nam(fp->state));
492 (*fp->fn->SendTerminateAck)(fp, lhp->id);
496 log_Printf(fp->LogLevel, "%s: Error: Got ConfigReq while state = %s\n",
497 fp->link->name, State2Nam(fp->state));
502 (*fp->fn->LayerDown)(fp);
503 (*fp->parent->LayerDown)(fp->parent->object, fp);
508 dec.ackend = dec.ack;
509 dec.nakend = dec.nak;
510 dec.rejend = dec.rej;
511 (*fp->fn->DecodeConfig)(fp, MBUF_CTOP(bp), flen, MODE_REQ, &dec);
512 if (flen < sizeof(struct fsmconfig))
513 log_Printf(fp->LogLevel, " [EMPTY]\n");
515 if (dec.nakend == dec.nak && dec.rejend == dec.rej)
520 FsmInitRestartCounter(fp, FSM_REQ_TIMER);
524 FsmSendConfigReq(fp);
528 if (dec.rejend != dec.rej)
529 fsm_Output(fp, CODE_CONFIGREJ, lhp->id, dec.rej, dec.rejend - dec.rej,
531 if (dec.nakend != dec.nak)
532 fsm_Output(fp, CODE_CONFIGNAK, lhp->id, dec.nak, dec.nakend - dec.nak,
535 fsm_Output(fp, CODE_CONFIGACK, lhp->id, dec.ack, dec.ackend - dec.ack,
541 * According to the RFC (1661) state transition table, a TLS isn't
542 * required for a RCR when state == ST_STOPPED, but the RFC
543 * must be wrong as TLS hasn't yet been called (since the last TLF)
545 (*fp->fn->LayerStart)(fp);
546 (*fp->parent->LayerStart)(fp->parent->object, fp);
551 NewState(fp, ST_ACKSENT);
553 NewState(fp, ST_REQSENT);
557 NewState(fp, ST_ACKSENT);
561 NewState(fp, ST_OPENED);
562 if ((*fp->fn->LayerUp)(fp))
563 (*fp->parent->LayerUp)(fp->parent->object, fp);
565 (*fp->fn->LayerDown)(fp);
566 FsmInitRestartCounter(fp, FSM_TRM_TIMER);
567 FsmSendTerminateReq(fp);
568 NewState(fp, ST_CLOSING);
569 lcp_SendIdentification(&fp->link->lcp);
575 NewState(fp, ST_REQSENT);
580 if (dec.rejend != dec.rej && --fp->more.rejs <= 0) {
581 log_Printf(LogPHASE, "%s: Too many %s REJs sent - abandoning negotiation\n",
582 fp->link->name, fp->name);
583 lcp_SendIdentification(&fp->link->lcp);
587 if (dec.nakend != dec.nak && --fp->more.naks <= 0) {
588 log_Printf(LogPHASE, "%s: Too many %s NAKs sent - abandoning negotiation\n",
589 fp->link->name, fp->name);
590 lcp_SendIdentification(&fp->link->lcp);
596 FsmRecvConfigAck(struct fsm *fp, struct fsmheader *lhp, struct mbuf *bp)
602 (*fp->fn->SendTerminateAck)(fp, lhp->id);
608 FsmInitRestartCounter(fp, FSM_REQ_TIMER);
609 NewState(fp, ST_ACKRCVD);
612 FsmSendConfigReq(fp);
613 NewState(fp, ST_REQSENT);
616 FsmInitRestartCounter(fp, FSM_REQ_TIMER);
617 NewState(fp, ST_OPENED);
618 if ((*fp->fn->LayerUp)(fp))
619 (*fp->parent->LayerUp)(fp->parent->object, fp);
621 (*fp->fn->LayerDown)(fp);
622 FsmInitRestartCounter(fp, FSM_TRM_TIMER);
623 FsmSendTerminateReq(fp);
624 NewState(fp, ST_CLOSING);
625 lcp_SendIdentification(&fp->link->lcp);
629 (*fp->fn->LayerDown)(fp);
630 FsmSendConfigReq(fp);
631 NewState(fp, ST_REQSENT);
632 (*fp->parent->LayerDown)(fp->parent->object, fp);
639 FsmRecvConfigNak(struct fsm *fp, struct fsmheader *lhp, struct mbuf *bp)
642 struct fsm_decode dec;
646 flen = ntohs(lhp->length) - sizeof *lhp;
653 * Check and process easy case
658 log_Printf(fp->LogLevel, "%s: Oops, RCN in %s.\n",
659 fp->link->name, State2Nam(fp->state));
664 (*fp->fn->SendTerminateAck)(fp, lhp->id);
674 dec.ackend = dec.ack;
675 dec.nakend = dec.nak;
676 dec.rejend = dec.rej;
677 (*fp->fn->DecodeConfig)(fp, MBUF_CTOP(bp), flen, MODE_NAK, &dec);
678 if (flen < sizeof(struct fsmconfig))
679 log_Printf(fp->LogLevel, " [EMPTY]\n");
684 FsmInitRestartCounter(fp, FSM_REQ_TIMER);
685 FsmSendConfigReq(fp);
688 (*fp->fn->LayerDown)(fp);
689 FsmSendConfigReq(fp);
690 NewState(fp, ST_REQSENT);
691 (*fp->parent->LayerDown)(fp->parent->object, fp);
694 FsmSendConfigReq(fp);
695 NewState(fp, ST_REQSENT);
703 FsmRecvTermReq(struct fsm *fp, struct fsmheader *lhp, struct mbuf *bp)
709 log_Printf(fp->LogLevel, "%s: Oops, RTR in %s\n",
710 fp->link->name, State2Nam(fp->state));
717 (*fp->fn->SendTerminateAck)(fp, lhp->id);
721 (*fp->fn->SendTerminateAck)(fp, lhp->id);
722 NewState(fp, ST_REQSENT);
725 (*fp->fn->LayerDown)(fp);
726 (*fp->fn->SendTerminateAck)(fp, lhp->id);
727 FsmInitRestartCounter(fp, FSM_TRM_TIMER);
728 timer_Start(&fp->FsmTimer); /* Start restart timer */
730 NewState(fp, ST_STOPPING);
731 (*fp->parent->LayerDown)(fp->parent->object, fp);
732 /* A delayed ST_STOPPED is now scheduled */
739 FsmRecvTermAck(struct fsm *fp, struct fsmheader *lhp, struct mbuf *bp)
744 (*fp->fn->LayerFinish)(fp);
745 NewState(fp, ST_CLOSED);
746 (*fp->parent->LayerFinish)(fp->parent->object, fp);
749 (*fp->fn->LayerFinish)(fp);
750 NewState(fp, ST_STOPPED);
751 (*fp->parent->LayerFinish)(fp->parent->object, fp);
754 NewState(fp, ST_REQSENT);
757 (*fp->fn->LayerDown)(fp);
758 FsmSendConfigReq(fp);
759 NewState(fp, ST_REQSENT);
760 (*fp->parent->LayerDown)(fp->parent->object, fp);
767 FsmRecvConfigRej(struct fsm *fp, struct fsmheader *lhp, struct mbuf *bp)
770 struct fsm_decode dec;
774 flen = ntohs(lhp->length) - sizeof *lhp;
780 lcp_SendIdentification(&fp->link->lcp);
783 * Check and process easy case
788 log_Printf(fp->LogLevel, "%s: Oops, RCJ in %s.\n",
789 fp->link->name, State2Nam(fp->state));
794 (*fp->fn->SendTerminateAck)(fp, lhp->id);
804 dec.ackend = dec.ack;
805 dec.nakend = dec.nak;
806 dec.rejend = dec.rej;
807 (*fp->fn->DecodeConfig)(fp, MBUF_CTOP(bp), flen, MODE_REJ, &dec);
808 if (flen < sizeof(struct fsmconfig))
809 log_Printf(fp->LogLevel, " [EMPTY]\n");
814 FsmInitRestartCounter(fp, FSM_REQ_TIMER);
815 FsmSendConfigReq(fp);
818 (*fp->fn->LayerDown)(fp);
819 FsmSendConfigReq(fp);
820 NewState(fp, ST_REQSENT);
821 (*fp->parent->LayerDown)(fp->parent->object, fp);
824 FsmSendConfigReq(fp);
825 NewState(fp, ST_REQSENT);
832 FsmRecvCodeRej(struct fsm *fp, struct fsmheader *lhp, struct mbuf *bp)
838 FsmRecvProtoRej(struct fsm *fp, struct fsmheader *lhp, struct mbuf *bp)
840 struct physical *p = link2physical(fp->link);
843 if (m_length(bp) < 2) {
847 bp = mbuf_Read(bp, &proto, 2);
848 proto = ntohs(proto);
849 log_Printf(fp->LogLevel, "%s: -- Protocol 0x%04x (%s) was rejected!\n",
850 fp->link->name, proto, hdlc_Protocol2Nam(proto));
855 lqr_Stop(p, LQM_LQR);
857 log_Printf(LogERROR, "%s: FsmRecvProtoRej: Not a physical link !\n",
861 if (fp->proto == PROTO_LCP) {
862 fp = &fp->link->ccp.fsm;
863 /* Despite the RFC (1661), don't do an out-of-place TLF */
864 /* (*fp->fn->LayerFinish)(fp); */
868 NewState(fp, ST_CLOSED);
870 NewState(fp, ST_STOPPED);
874 /* (*fp->parent->LayerFinish)(fp->parent->object, fp); */
878 if (fp->proto == PROTO_LCP) {
879 log_Printf(LogPHASE, "%s: IPCP protocol reject closes IPCP !\n",
881 fsm_Close(&fp->bundle->ncp.ipcp.fsm);
885 if (fp->proto == PROTO_LCP) {
886 struct lcp *lcp = fsm2lcp(fp);
888 if (lcp->want_mrru && lcp->his_mrru) {
889 log_Printf(LogPHASE, "%s: MP protocol reject is fatal !\n",
900 FsmRecvEchoReq(struct fsm *fp, struct fsmheader *lhp, struct mbuf *bp)
902 struct lcp *lcp = fsm2lcp(fp);
907 m_settype(bp, MB_ECHOIN);
909 if (lcp && ntohs(lhp->length) - sizeof *lhp >= 4) {
911 ua_ntohl(cp, &magic);
912 if (magic != lcp->his_magic) {
913 log_Printf(fp->LogLevel, "%s: RecvEchoReq: magic 0x%08lx is wrong,"
914 " expecting 0x%08lx\n", fp->link->name, (u_long)magic,
915 (u_long)lcp->his_magic);
916 /* XXX: We should send terminate request */
918 if (fp->state == ST_OPENED) {
919 ua_htonl(&lcp->want_magic, cp); /* local magic */
920 fsm_Output(fp, CODE_ECHOREP, lhp->id, cp,
921 ntohs(lhp->length) - sizeof *lhp, MB_ECHOOUT);
928 FsmRecvEchoRep(struct fsm *fp, struct fsmheader *lhp, struct mbuf *bp)
931 bp = lqr_RecvEcho(fp, bp);
937 FsmRecvDiscReq(struct fsm *fp, struct fsmheader *lhp, struct mbuf *bp)
943 FsmRecvIdent(struct fsm *fp, struct fsmheader *lhp, struct mbuf *bp)
949 len = ntohs(lhp->length) - sizeof *lhp;
951 bp = m_pullup(m_append(bp, "", 1));
953 ua_ntohl(cp, &magic);
954 if (magic != fp->link->lcp.his_magic)
955 log_Printf(fp->LogLevel, "%s: RecvIdent: magic 0x%08lx is wrong,"
956 " expecting 0x%08lx\n", fp->link->name, (u_long)magic,
957 (u_long)fp->link->lcp.his_magic);
959 lcp_RecvIdentification(&fp->link->lcp, cp + 4);
965 FsmRecvTimeRemain(struct fsm *fp, struct fsmheader *lhp, struct mbuf *bp)
971 FsmRecvResetReq(struct fsm *fp, struct fsmheader *lhp, struct mbuf *bp)
973 (*fp->fn->RecvResetReq)(fp);
975 * All sendable compressed packets are queued in the first (lowest
976 * priority) modem output queue.... dump 'em to the priority queue
977 * so that they arrive at the peer before our ResetAck.
979 link_SequenceQueue(fp->link);
980 fsm_Output(fp, CODE_RESETACK, lhp->id, NULL, 0, MB_CCPOUT);
985 FsmRecvResetAck(struct fsm *fp, struct fsmheader *lhp, struct mbuf *bp)
987 (*fp->fn->RecvResetAck)(fp, lhp->id);
992 fsm_Input(struct fsm *fp, struct mbuf *bp)
996 const struct fsmcodedesc *codep;
999 if (len < sizeof(struct fsmheader)) {
1003 bp = mbuf_Read(bp, &lh, sizeof lh);
1005 if (ntohs(lh.length) > len) {
1006 log_Printf(LogWARN, "%s: Oops: Got %d bytes but %d byte payload "
1007 "- dropped\n", fp->link->name, len, (int)ntohs(lh.length));
1012 if (lh.code < fp->min_code || lh.code > fp->max_code ||
1013 lh.code > sizeof FsmCodes / sizeof *FsmCodes) {
1015 * Use a private id. This is really a response-type packet, but we
1016 * MUST send a unique id for each REQ....
1020 bp = m_prepend(bp, &lh, sizeof lh, 0);
1022 fsm_Output(fp, CODE_CODEREJ, id++, MBUF_CTOP(bp), bp->m_len, MB_UNKNOWN);
1027 codep = FsmCodes + lh.code - 1;
1028 if (lh.id != fp->reqid && codep->check_reqid &&
1029 Enabled(fp->bundle, OPT_IDCHECK)) {
1030 log_Printf(fp->LogLevel, "%s: Recv%s(%d), dropped (expected %d)\n",
1031 fp->link->name, codep->name, lh.id, fp->reqid);
1035 log_Printf(fp->LogLevel, "%s: Recv%s(%d) state = %s\n",
1036 fp->link->name, codep->name, lh.id, State2Nam(fp->state));
1038 if (codep->inc_reqid && (lh.id == fp->reqid ||
1039 (!Enabled(fp->bundle, OPT_IDCHECK) && codep->check_reqid)))
1040 fp->reqid++; /* That's the end of that ``exchange''.... */
1042 (*codep->recv)(fp, &lh, bp);
1046 fsm_NullRecvResetReq(struct fsm *fp)
1048 log_Printf(fp->LogLevel, "%s: Oops - received unexpected reset req\n",
1053 fsm_NullRecvResetAck(struct fsm *fp, u_char id)
1055 log_Printf(fp->LogLevel, "%s: Oops - received unexpected reset ack\n",
1060 fsm_Reopen(struct fsm *fp)
1062 if (fp->state == ST_OPENED) {
1063 (*fp->fn->LayerDown)(fp);
1064 FsmInitRestartCounter(fp, FSM_REQ_TIMER);
1065 FsmSendConfigReq(fp);
1066 NewState(fp, ST_REQSENT);
1067 (*fp->parent->LayerDown)(fp->parent->object, fp);
1072 fsm2initial(struct fsm *fp)
1074 timer_Stop(&fp->FsmTimer);
1075 timer_Stop(&fp->OpenTimer);
1076 timer_Stop(&fp->StoppedTimer);
1077 if (fp->state == ST_STOPPED)
1079 if (fp->state > ST_INITIAL)
1081 if (fp->state > ST_INITIAL)