Lines Matching refs:f
69 #define PROTO_NAME(f) ((f)->callbacks->proto_name) argument
80 fsm_init(f) in fsm_init() argument
81 fsm *f; in fsm_init()
83 f->state = INITIAL;
84 f->flags = 0;
85 f->id = 0; /* XXX Start with random id? */
86 f->timeouttime = DEFTIMEOUT;
87 f->maxconfreqtransmits = DEFMAXCONFREQS;
88 f->maxtermtransmits = DEFMAXTERMREQS;
89 f->maxnakloops = DEFMAXNAKLOOPS;
90 f->term_reason_len = 0;
98 fsm_lowerup(f) in fsm_lowerup() argument
99 fsm *f; in fsm_lowerup()
101 switch( f->state ){
103 f->state = CLOSED;
107 if( f->flags & OPT_SILENT )
108 f->state = STOPPED;
111 fsm_sconfreq(f, 0);
112 f->state = REQSENT;
117 FSMDEBUG(("%s: Up event in state %d!", PROTO_NAME(f), f->state));
128 fsm_lowerdown(f) in fsm_lowerdown() argument
129 fsm *f; in fsm_lowerdown()
131 switch( f->state ){
133 f->state = INITIAL;
137 f->state = STARTING;
138 if( f->callbacks->starting )
139 (*f->callbacks->starting)(f);
143 f->state = INITIAL;
144 UNTIMEOUT(fsm_timeout, f); /* Cancel timeout */
151 f->state = STARTING;
152 UNTIMEOUT(fsm_timeout, f); /* Cancel timeout */
156 if( f->callbacks->down )
157 (*f->callbacks->down)(f);
158 f->state = STARTING;
162 FSMDEBUG(("%s: Down event in state %d!", PROTO_NAME(f), f->state));
171 fsm_open(f) in fsm_open() argument
172 fsm *f; in fsm_open()
174 switch( f->state ){
176 f->state = STARTING;
177 if( f->callbacks->starting )
178 (*f->callbacks->starting)(f);
182 if( f->flags & OPT_SILENT )
183 f->state = STOPPED;
186 fsm_sconfreq(f, 0);
187 f->state = REQSENT;
192 f->state = STOPPING;
196 if( f->flags & OPT_RESTART ){
197 fsm_lowerdown(f);
198 fsm_lowerup(f);
211 terminate_layer(f, nextstate) in terminate_layer() argument
212 fsm *f; in terminate_layer()
215 if( f->state != OPENED )
216 UNTIMEOUT(fsm_timeout, f); /* Cancel timeout */
217 else if( f->callbacks->down )
218 (*f->callbacks->down)(f); /* Inform upper layers we're down */
221 f->retransmits = f->maxtermtransmits;
222 fsm_sdata(f, TERMREQ, f->reqid = ++f->id,
223 (u_char *) f->term_reason, f->term_reason_len);
225 if (f->retransmits == 0) {
231 f->state = nextstate == CLOSING ? CLOSED : STOPPED;
232 if( f->callbacks->finished )
233 (*f->callbacks->finished)(f);
237 TIMEOUT(fsm_timeout, f, f->timeouttime);
238 --f->retransmits;
240 f->state = nextstate;
250 fsm_close(f, reason) in fsm_close() argument
251 fsm *f; in fsm_close()
254 f->term_reason = reason;
255 f->term_reason_len = (reason == NULL? 0: strlen(reason));
256 switch( f->state ){
258 f->state = INITIAL;
261 f->state = CLOSED;
264 f->state = CLOSING;
271 terminate_layer(f, CLOSING);
284 fsm *f = (fsm *) arg; local
286 switch (f->state) {
289 if( f->retransmits <= 0 ){
293 f->state = (f->state == CLOSING)? CLOSED: STOPPED;
294 if( f->callbacks->finished )
295 (*f->callbacks->finished)(f);
298 fsm_sdata(f, TERMREQ, f->reqid = ++f->id,
299 (u_char *) f->term_reason, f->term_reason_len);
300 TIMEOUT(fsm_timeout, f, f->timeouttime);
301 --f->retransmits;
308 if (f->retransmits <= 0) {
309 warn("%s: timeout sending Config-Requests\n", PROTO_NAME(f));
310 f->state = STOPPED;
311 if( (f->flags & OPT_PASSIVE) == 0 && f->callbacks->finished )
312 (*f->callbacks->finished)(f);
316 if (f->callbacks->retransmit)
317 (*f->callbacks->retransmit)(f);
318 fsm_sconfreq(f, 1); /* Re-send Configure-Request */
319 if( f->state == ACKRCVD )
320 f->state = REQSENT;
325 FSMDEBUG(("%s: Timeout event in state %d!", PROTO_NAME(f), f->state));
334 fsm_input(f, inpacket, l) in fsm_input() argument
335 fsm *f; in fsm_input()
349 FSMDEBUG(("fsm_input(%x): Rcvd short header.", f->protocol));
356 FSMDEBUG(("fsm_input(%x): Rcvd illegal length.", f->protocol));
360 FSMDEBUG(("fsm_input(%x): Rcvd short packet.", f->protocol));
365 if( f->state == INITIAL || f->state == STARTING ){
367 f->protocol, f->state));
376 fsm_rconfreq(f, id, inp, len);
380 fsm_rconfack(f, id, inp, len);
385 fsm_rconfnakrej(f, code, id, inp, len);
389 fsm_rtermreq(f, id, inp, len);
393 fsm_rtermack(f);
397 fsm_rcoderej(f, inp, len);
401 if( !f->callbacks->extcode
402 || !(*f->callbacks->extcode)(f, code, id, inp, len) )
403 fsm_sdata(f, CODEREJ, ++f->id, inpacket, len + HEADERLEN);
413 fsm_rconfreq(f, id, inp, len) in fsm_rconfreq() argument
414 fsm *f; in fsm_rconfreq()
421 switch( f->state ){
424 fsm_sdata(f, TERMACK, id, NULL, 0);
432 if( f->callbacks->down )
433 (*f->callbacks->down)(f); /* Inform upper layers */
434 fsm_sconfreq(f, 0); /* Send initial Configure-Request */
435 f->state = REQSENT;
440 fsm_sconfreq(f, 0); /* Send initial Configure-Request */
441 f->state = REQSENT;
449 if (f->callbacks->reqci){ /* Check CI */
450 reject_if_disagree = (f->nakloops >= f->maxnakloops);
451 code = (*f->callbacks->reqci)(f, inp, &len, reject_if_disagree);
458 fsm_sdata(f, code, id, inp, len);
461 if (f->state == ACKRCVD) {
462 UNTIMEOUT(fsm_timeout, f); /* Cancel timeout */
463 f->state = OPENED;
464 if (f->callbacks->up)
465 (*f->callbacks->up)(f); /* Inform upper layers */
467 f->state = ACKSENT;
468 f->nakloops = 0;
472 if (f->state != ACKRCVD)
473 f->state = REQSENT;
475 ++f->nakloops;
484 fsm_rconfack(f, id, inp, len) in fsm_rconfack() argument
485 fsm *f; in fsm_rconfack()
490 if (id != f->reqid || f->seen_ack) /* Expected id? */
492 if( !(f->callbacks->ackci? (*f->callbacks->ackci)(f, inp, len):
498 f->seen_ack = 1;
499 f->rnakloops = 0;
501 switch (f->state) {
504 fsm_sdata(f, TERMACK, id, NULL, 0);
508 f->state = ACKRCVD;
509 f->retransmits = f->maxconfreqtransmits;
514 UNTIMEOUT(fsm_timeout, f); /* Cancel timeout */
515 fsm_sconfreq(f, 0);
516 f->state = REQSENT;
520 UNTIMEOUT(fsm_timeout, f); /* Cancel timeout */
521 f->state = OPENED;
522 f->retransmits = f->maxconfreqtransmits;
523 if (f->callbacks->up)
524 (*f->callbacks->up)(f); /* Inform upper layers */
529 if (f->callbacks->down)
530 (*f->callbacks->down)(f); /* Inform upper layers */
531 fsm_sconfreq(f, 0); /* Send initial Configure-Request */
532 f->state = REQSENT;
542 fsm_rconfnakrej(f, code, id, inp, len) in fsm_rconfnakrej() argument
543 fsm *f; in fsm_rconfnakrej()
551 if (id != f->reqid || f->seen_ack) /* Expected id? */
555 ++f->rnakloops;
556 treat_as_reject = (f->rnakloops >= f->maxnakloops);
557 if (f->callbacks->nakci == NULL
558 || !(ret = f->callbacks->nakci(f, inp, len, treat_as_reject))) {
563 f->rnakloops = 0;
564 if (f->callbacks->rejci == NULL
565 || !(ret = f->callbacks->rejci(f, inp, len))) {
571 f->seen_ack = 1;
573 switch (f->state) {
576 fsm_sdata(f, TERMACK, id, NULL, 0);
582 UNTIMEOUT(fsm_timeout, f); /* Cancel timeout */
584 f->state = STOPPED; /* kludge for stopping CCP */
586 fsm_sconfreq(f, 0); /* Send Configure-Request */
591 UNTIMEOUT(fsm_timeout, f); /* Cancel timeout */
592 fsm_sconfreq(f, 0);
593 f->state = REQSENT;
598 if (f->callbacks->down)
599 (*f->callbacks->down)(f); /* Inform upper layers */
600 fsm_sconfreq(f, 0); /* Send initial Configure-Request */
601 f->state = REQSENT;
611 fsm_rtermreq(f, id, p, len) in fsm_rtermreq() argument
612 fsm *f; in fsm_rtermreq()
617 switch (f->state) {
620 f->state = REQSENT; /* Start over but keep trying */
625 info("%s terminated by peer (%0.*v)", PROTO_NAME(f), len, p);
627 info("%s terminated by peer", PROTO_NAME(f));
628 f->retransmits = 0;
629 f->state = STOPPING;
630 if (f->callbacks->down)
631 (*f->callbacks->down)(f); /* Inform upper layers */
632 TIMEOUT(fsm_timeout, f, f->timeouttime);
636 fsm_sdata(f, TERMACK, id, NULL, 0);
644 fsm_rtermack(f) in fsm_rtermack() argument
645 fsm *f; in fsm_rtermack()
647 switch (f->state) {
649 UNTIMEOUT(fsm_timeout, f);
650 f->state = CLOSED;
651 if( f->callbacks->finished )
652 (*f->callbacks->finished)(f);
655 UNTIMEOUT(fsm_timeout, f);
656 f->state = STOPPED;
657 if( f->callbacks->finished )
658 (*f->callbacks->finished)(f);
662 f->state = REQSENT;
666 if (f->callbacks->down)
667 (*f->callbacks->down)(f); /* Inform upper layers */
668 fsm_sconfreq(f, 0);
669 f->state = REQSENT;
679 fsm_rcoderej(f, inp, len) in fsm_rcoderej() argument
680 fsm *f; in fsm_rcoderej()
692 warn("%s: Rcvd Code-Reject for code %d, id %d", PROTO_NAME(f), code, id);
694 if( f->state == ACKRCVD )
695 f->state = REQSENT;
705 fsm_protreject(f) in fsm_protreject() argument
706 fsm *f; in fsm_protreject()
708 switch( f->state ){
710 UNTIMEOUT(fsm_timeout, f); /* Cancel timeout */
713 f->state = CLOSED;
714 if( f->callbacks->finished )
715 (*f->callbacks->finished)(f);
722 UNTIMEOUT(fsm_timeout, f); /* Cancel timeout */
725 f->state = STOPPED;
726 if( f->callbacks->finished )
727 (*f->callbacks->finished)(f);
731 terminate_layer(f, STOPPING);
736 PROTO_NAME(f), f->state));
745 fsm_sconfreq(f, retransmit) in fsm_sconfreq() argument
746 fsm *f; in fsm_sconfreq()
752 if( f->state != REQSENT && f->state != ACKRCVD && f->state != ACKSENT ){
754 if( f->callbacks->resetci )
755 (*f->callbacks->resetci)(f);
756 f->nakloops = 0;
757 f->rnakloops = 0;
762 f->retransmits = f->maxconfreqtransmits;
763 f->reqid = ++f->id;
766 f->seen_ack = 0;
772 if( f->callbacks->cilen && f->callbacks->addci ){
773 cilen = (*f->callbacks->cilen)(f);
774 if( cilen > peer_mru[f->unit] - HEADERLEN )
775 cilen = peer_mru[f->unit] - HEADERLEN;
776 if (f->callbacks->addci)
777 (*f->callbacks->addci)(f, outp, &cilen);
782 fsm_sdata(f, CONFREQ, f->reqid, outp, cilen);
785 --f->retransmits;
786 TIMEOUT(fsm_timeout, f, f->timeouttime);
796 fsm_sdata(f, code, id, data, datalen) in fsm_sdata() argument
797 fsm *f; in fsm_sdata()
807 if (datalen > peer_mru[f->unit] - HEADERLEN)
808 datalen = peer_mru[f->unit] - HEADERLEN;
812 MAKEHEADER(outp, f->protocol);
816 output(f->unit, outpacket_buf, outlen + PPP_HDRLEN);