• Home
  • Raw
  • Download

Lines Matching refs:f

63 static void fsm_rconfreq(fsm *f, u_char id, u_char *inp, int len);
64 static void fsm_rconfack(fsm *f, int id, u_char *inp, int len);
65 static void fsm_rconfnakrej(fsm *f, int code, int id, u_char *inp, int len);
66 static void fsm_rtermreq(fsm *f, int id, u_char *p, int len);
67 static void fsm_rtermack(fsm *f);
68 static void fsm_rcoderej(fsm *f, u_char *inp, int len);
69 static void fsm_sconfreq(fsm *f, int retransmit);
71 #define PROTO_NAME(f) ((f)->callbacks->proto_name) argument
78 void fsm_init(fsm *f) { in fsm_init() argument
79 ppp_pcb *pcb = f->pcb; in fsm_init()
80 f->state = PPP_FSM_INITIAL; in fsm_init()
81 f->flags = 0; in fsm_init()
82 f->id = 0; /* XXX Start with random id? */ in fsm_init()
83 f->maxnakloops = pcb->settings.fsm_max_nak_loops; in fsm_init()
84 f->term_reason_len = 0; in fsm_init()
91 void fsm_lowerup(fsm *f) { in fsm_lowerup() argument
92 switch( f->state ){ in fsm_lowerup()
94 f->state = PPP_FSM_CLOSED; in fsm_lowerup()
98 if( f->flags & OPT_SILENT ) in fsm_lowerup()
99 f->state = PPP_FSM_STOPPED; in fsm_lowerup()
102 fsm_sconfreq(f, 0); in fsm_lowerup()
103 f->state = PPP_FSM_REQSENT; in fsm_lowerup()
108 FSMDEBUG(("%s: Up event in state %d!", PROTO_NAME(f), f->state)); in fsm_lowerup()
119 void fsm_lowerdown(fsm *f) { in fsm_lowerdown() argument
120 switch( f->state ){ in fsm_lowerdown()
122 f->state = PPP_FSM_INITIAL; in fsm_lowerdown()
126 f->state = PPP_FSM_STARTING; in fsm_lowerdown()
127 if( f->callbacks->starting ) in fsm_lowerdown()
128 (*f->callbacks->starting)(f); in fsm_lowerdown()
132 f->state = PPP_FSM_INITIAL; in fsm_lowerdown()
133 UNTIMEOUT(fsm_timeout, f); /* Cancel timeout */ in fsm_lowerdown()
140 f->state = PPP_FSM_STARTING; in fsm_lowerdown()
141 UNTIMEOUT(fsm_timeout, f); /* Cancel timeout */ in fsm_lowerdown()
145 if( f->callbacks->down ) in fsm_lowerdown()
146 (*f->callbacks->down)(f); in fsm_lowerdown()
147 f->state = PPP_FSM_STARTING; in fsm_lowerdown()
151 FSMDEBUG(("%s: Down event in state %d!", PROTO_NAME(f), f->state)); in fsm_lowerdown()
160 void fsm_open(fsm *f) { in fsm_open() argument
161 switch( f->state ){ in fsm_open()
163 f->state = PPP_FSM_STARTING; in fsm_open()
164 if( f->callbacks->starting ) in fsm_open()
165 (*f->callbacks->starting)(f); in fsm_open()
169 if( f->flags & OPT_SILENT ) in fsm_open()
170 f->state = PPP_FSM_STOPPED; in fsm_open()
173 fsm_sconfreq(f, 0); in fsm_open()
174 f->state = PPP_FSM_REQSENT; in fsm_open()
179 f->state = PPP_FSM_STOPPING; in fsm_open()
184 if( f->flags & OPT_RESTART ){ in fsm_open()
185 fsm_lowerdown(f); in fsm_open()
186 fsm_lowerup(f); in fsm_open()
200 static void terminate_layer(fsm *f, int nextstate) { in terminate_layer() argument
201 ppp_pcb *pcb = f->pcb; in terminate_layer()
203 if( f->state != PPP_FSM_OPENED ) in terminate_layer()
204 UNTIMEOUT(fsm_timeout, f); /* Cancel timeout */ in terminate_layer()
205 else if( f->callbacks->down ) in terminate_layer()
206 (*f->callbacks->down)(f); /* Inform upper layers we're down */ in terminate_layer()
209 f->retransmits = pcb->settings.fsm_max_term_transmits; in terminate_layer()
210 fsm_sdata(f, TERMREQ, f->reqid = ++f->id, in terminate_layer()
211 (const u_char *) f->term_reason, f->term_reason_len); in terminate_layer()
213 if (f->retransmits == 0) { in terminate_layer()
219 f->state = nextstate == PPP_FSM_CLOSING ? PPP_FSM_CLOSED : PPP_FSM_STOPPED; in terminate_layer()
220 if( f->callbacks->finished ) in terminate_layer()
221 (*f->callbacks->finished)(f); in terminate_layer()
225 TIMEOUT(fsm_timeout, f, pcb->settings.fsm_timeout_time); in terminate_layer()
226 --f->retransmits; in terminate_layer()
228 f->state = nextstate; in terminate_layer()
237 void fsm_close(fsm *f, const char *reason) { in fsm_close() argument
238 f->term_reason = reason; in fsm_close()
239 f->term_reason_len = (reason == NULL? 0: (u8_t)LWIP_MIN(strlen(reason), 0xFF) ); in fsm_close()
240 switch( f->state ){ in fsm_close()
242 f->state = PPP_FSM_INITIAL; in fsm_close()
245 f->state = PPP_FSM_CLOSED; in fsm_close()
248 f->state = PPP_FSM_CLOSING; in fsm_close()
255 terminate_layer(f, PPP_FSM_CLOSING); in fsm_close()
267 fsm *f = (fsm *) arg; in fsm_timeout() local
268 ppp_pcb *pcb = f->pcb; in fsm_timeout()
270 switch (f->state) { in fsm_timeout()
273 if( f->retransmits <= 0 ){ in fsm_timeout()
277 f->state = (f->state == PPP_FSM_CLOSING)? PPP_FSM_CLOSED: PPP_FSM_STOPPED; in fsm_timeout()
278 if( f->callbacks->finished ) in fsm_timeout()
279 (*f->callbacks->finished)(f); in fsm_timeout()
282 fsm_sdata(f, TERMREQ, f->reqid = ++f->id, in fsm_timeout()
283 (const u_char *) f->term_reason, f->term_reason_len); in fsm_timeout()
284 TIMEOUT(fsm_timeout, f, pcb->settings.fsm_timeout_time); in fsm_timeout()
285 --f->retransmits; in fsm_timeout()
292 if (f->retransmits <= 0) { in fsm_timeout()
293 ppp_warn("%s: timeout sending Config-Requests", PROTO_NAME(f)); in fsm_timeout()
294 f->state = PPP_FSM_STOPPED; in fsm_timeout()
295 if( (f->flags & OPT_PASSIVE) == 0 && f->callbacks->finished ) in fsm_timeout()
296 (*f->callbacks->finished)(f); in fsm_timeout()
300 if (f->callbacks->retransmit) in fsm_timeout()
301 (*f->callbacks->retransmit)(f); in fsm_timeout()
302 fsm_sconfreq(f, 1); /* Re-send Configure-Request */ in fsm_timeout()
303 if( f->state == PPP_FSM_ACKRCVD ) in fsm_timeout()
304 f->state = PPP_FSM_REQSENT; in fsm_timeout()
309 FSMDEBUG(("%s: Timeout event in state %d!", PROTO_NAME(f), f->state)); in fsm_timeout()
318 void fsm_input(fsm *f, u_char *inpacket, int l) { in fsm_input() argument
329 FSMDEBUG(("fsm_input(%x): Rcvd short header.", f->protocol)); in fsm_input()
336 FSMDEBUG(("fsm_input(%x): Rcvd illegal length.", f->protocol)); in fsm_input()
340 FSMDEBUG(("fsm_input(%x): Rcvd short packet.", f->protocol)); in fsm_input()
345 if( f->state == PPP_FSM_INITIAL || f->state == PPP_FSM_STARTING ){ in fsm_input()
347 f->protocol, f->state)); in fsm_input()
356 fsm_rconfreq(f, id, inp, len); in fsm_input()
360 fsm_rconfack(f, id, inp, len); in fsm_input()
365 fsm_rconfnakrej(f, code, id, inp, len); in fsm_input()
369 fsm_rtermreq(f, id, inp, len); in fsm_input()
373 fsm_rtermack(f); in fsm_input()
377 fsm_rcoderej(f, inp, len); in fsm_input()
381 if( !f->callbacks->extcode in fsm_input()
382 || !(*f->callbacks->extcode)(f, code, id, inp, len) ) in fsm_input()
383 fsm_sdata(f, CODEREJ, ++f->id, inpacket, len + HEADERLEN); in fsm_input()
392 static void fsm_rconfreq(fsm *f, u_char id, u_char *inp, int len) { in fsm_rconfreq() argument
395 switch( f->state ){ in fsm_rconfreq()
398 fsm_sdata(f, TERMACK, id, NULL, 0); in fsm_rconfreq()
406 if( f->callbacks->down ) in fsm_rconfreq()
407 (*f->callbacks->down)(f); /* Inform upper layers */ in fsm_rconfreq()
408 fsm_sconfreq(f, 0); /* Send initial Configure-Request */ in fsm_rconfreq()
409 f->state = PPP_FSM_REQSENT; in fsm_rconfreq()
414 fsm_sconfreq(f, 0); /* Send initial Configure-Request */ in fsm_rconfreq()
415 f->state = PPP_FSM_REQSENT; in fsm_rconfreq()
425 if (f->callbacks->reqci){ /* Check CI */ in fsm_rconfreq()
426 reject_if_disagree = (f->nakloops >= f->maxnakloops); in fsm_rconfreq()
427 code = (*f->callbacks->reqci)(f, inp, &len, reject_if_disagree); in fsm_rconfreq()
434 fsm_sdata(f, code, id, inp, len); in fsm_rconfreq()
437 if (f->state == PPP_FSM_ACKRCVD) { in fsm_rconfreq()
438 UNTIMEOUT(fsm_timeout, f); /* Cancel timeout */ in fsm_rconfreq()
439 f->state = PPP_FSM_OPENED; in fsm_rconfreq()
440 if (f->callbacks->up) in fsm_rconfreq()
441 (*f->callbacks->up)(f); /* Inform upper layers */ in fsm_rconfreq()
443 f->state = PPP_FSM_ACKSENT; in fsm_rconfreq()
444 f->nakloops = 0; in fsm_rconfreq()
448 if (f->state != PPP_FSM_ACKRCVD) in fsm_rconfreq()
449 f->state = PPP_FSM_REQSENT; in fsm_rconfreq()
451 ++f->nakloops; in fsm_rconfreq()
459 static void fsm_rconfack(fsm *f, int id, u_char *inp, int len) { in fsm_rconfack() argument
460 ppp_pcb *pcb = f->pcb; in fsm_rconfack()
462 if (id != f->reqid || f->seen_ack) /* Expected id? */ in fsm_rconfack()
464 if( !(f->callbacks->ackci? (*f->callbacks->ackci)(f, inp, len): in fsm_rconfack()
470 f->seen_ack = 1; in fsm_rconfack()
471 f->rnakloops = 0; in fsm_rconfack()
473 switch (f->state) { in fsm_rconfack()
476 fsm_sdata(f, TERMACK, id, NULL, 0); in fsm_rconfack()
480 f->state = PPP_FSM_ACKRCVD; in fsm_rconfack()
481 f->retransmits = pcb->settings.fsm_max_conf_req_transmits; in fsm_rconfack()
486 UNTIMEOUT(fsm_timeout, f); /* Cancel timeout */ in fsm_rconfack()
487 fsm_sconfreq(f, 0); in fsm_rconfack()
488 f->state = PPP_FSM_REQSENT; in fsm_rconfack()
492 UNTIMEOUT(fsm_timeout, f); /* Cancel timeout */ in fsm_rconfack()
493 f->state = PPP_FSM_OPENED; in fsm_rconfack()
494 f->retransmits = pcb->settings.fsm_max_conf_req_transmits; in fsm_rconfack()
495 if (f->callbacks->up) in fsm_rconfack()
496 (*f->callbacks->up)(f); /* Inform upper layers */ in fsm_rconfack()
501 if (f->callbacks->down) in fsm_rconfack()
502 (*f->callbacks->down)(f); /* Inform upper layers */ in fsm_rconfack()
503 fsm_sconfreq(f, 0); /* Send initial Configure-Request */ in fsm_rconfack()
504 f->state = PPP_FSM_REQSENT; in fsm_rconfack()
515 static void fsm_rconfnakrej(fsm *f, int code, int id, u_char *inp, int len) { in fsm_rconfnakrej() argument
519 if (id != f->reqid || f->seen_ack) /* Expected id? */ in fsm_rconfnakrej()
523 ++f->rnakloops; in fsm_rconfnakrej()
524 treat_as_reject = (f->rnakloops >= f->maxnakloops); in fsm_rconfnakrej()
525 if (f->callbacks->nakci == NULL in fsm_rconfnakrej()
526 || !(ret = f->callbacks->nakci(f, inp, len, treat_as_reject))) { in fsm_rconfnakrej()
531 f->rnakloops = 0; in fsm_rconfnakrej()
532 if (f->callbacks->rejci == NULL in fsm_rconfnakrej()
533 || !(ret = f->callbacks->rejci(f, inp, len))) { in fsm_rconfnakrej()
539 f->seen_ack = 1; in fsm_rconfnakrej()
541 switch (f->state) { in fsm_rconfnakrej()
544 fsm_sdata(f, TERMACK, id, NULL, 0); in fsm_rconfnakrej()
550 UNTIMEOUT(fsm_timeout, f); /* Cancel timeout */ in fsm_rconfnakrej()
552 f->state = PPP_FSM_STOPPED; /* kludge for stopping CCP */ in fsm_rconfnakrej()
554 fsm_sconfreq(f, 0); /* Send Configure-Request */ in fsm_rconfnakrej()
559 UNTIMEOUT(fsm_timeout, f); /* Cancel timeout */ in fsm_rconfnakrej()
560 fsm_sconfreq(f, 0); in fsm_rconfnakrej()
561 f->state = PPP_FSM_REQSENT; in fsm_rconfnakrej()
566 if (f->callbacks->down) in fsm_rconfnakrej()
567 (*f->callbacks->down)(f); /* Inform upper layers */ in fsm_rconfnakrej()
568 fsm_sconfreq(f, 0); /* Send initial Configure-Request */ in fsm_rconfnakrej()
569 f->state = PPP_FSM_REQSENT; in fsm_rconfnakrej()
580 static void fsm_rtermreq(fsm *f, int id, u_char *p, int len) { in fsm_rtermreq() argument
581 ppp_pcb *pcb = f->pcb; in fsm_rtermreq()
583 switch (f->state) { in fsm_rtermreq()
586 f->state = PPP_FSM_REQSENT; /* Start over but keep trying */ in fsm_rtermreq()
591 ppp_info("%s terminated by peer (%0.*v)", PROTO_NAME(f), len, p); in fsm_rtermreq()
593 ppp_info("%s terminated by peer", PROTO_NAME(f)); in fsm_rtermreq()
594 f->retransmits = 0; in fsm_rtermreq()
595 f->state = PPP_FSM_STOPPING; in fsm_rtermreq()
596 if (f->callbacks->down) in fsm_rtermreq()
597 (*f->callbacks->down)(f); /* Inform upper layers */ in fsm_rtermreq()
598 TIMEOUT(fsm_timeout, f, pcb->settings.fsm_timeout_time); in fsm_rtermreq()
604 fsm_sdata(f, TERMACK, id, NULL, 0); in fsm_rtermreq()
611 static void fsm_rtermack(fsm *f) { in fsm_rtermack() argument
612 switch (f->state) { in fsm_rtermack()
614 UNTIMEOUT(fsm_timeout, f); in fsm_rtermack()
615 f->state = PPP_FSM_CLOSED; in fsm_rtermack()
616 if( f->callbacks->finished ) in fsm_rtermack()
617 (*f->callbacks->finished)(f); in fsm_rtermack()
620 UNTIMEOUT(fsm_timeout, f); in fsm_rtermack()
621 f->state = PPP_FSM_STOPPED; in fsm_rtermack()
622 if( f->callbacks->finished ) in fsm_rtermack()
623 (*f->callbacks->finished)(f); in fsm_rtermack()
627 f->state = PPP_FSM_REQSENT; in fsm_rtermack()
631 if (f->callbacks->down) in fsm_rtermack()
632 (*f->callbacks->down)(f); /* Inform upper layers */ in fsm_rtermack()
633 fsm_sconfreq(f, 0); in fsm_rtermack()
634 f->state = PPP_FSM_REQSENT; in fsm_rtermack()
645 static void fsm_rcoderej(fsm *f, u_char *inp, int len) { in fsm_rcoderej() argument
654 ppp_warn("%s: Rcvd Code-Reject for code %d, id %d", PROTO_NAME(f), code, id); in fsm_rcoderej()
656 if( f->state == PPP_FSM_ACKRCVD ) in fsm_rcoderej()
657 f->state = PPP_FSM_REQSENT; in fsm_rcoderej()
666 void fsm_protreject(fsm *f) { in fsm_protreject() argument
667 switch( f->state ){ in fsm_protreject()
669 UNTIMEOUT(fsm_timeout, f); /* Cancel timeout */ in fsm_protreject()
673 f->state = PPP_FSM_CLOSED; in fsm_protreject()
674 if( f->callbacks->finished ) in fsm_protreject()
675 (*f->callbacks->finished)(f); in fsm_protreject()
682 UNTIMEOUT(fsm_timeout, f); /* Cancel timeout */ in fsm_protreject()
686 f->state = PPP_FSM_STOPPED; in fsm_protreject()
687 if( f->callbacks->finished ) in fsm_protreject()
688 (*f->callbacks->finished)(f); in fsm_protreject()
692 terminate_layer(f, PPP_FSM_STOPPING); in fsm_protreject()
697 PROTO_NAME(f), f->state)); in fsm_protreject()
706 static void fsm_sconfreq(fsm *f, int retransmit) { in fsm_sconfreq() argument
707 ppp_pcb *pcb = f->pcb; in fsm_sconfreq()
712 if( f->state != PPP_FSM_REQSENT && f->state != PPP_FSM_ACKRCVD && f->state != PPP_FSM_ACKSENT ){ in fsm_sconfreq()
714 if( f->callbacks->resetci ) in fsm_sconfreq()
715 (*f->callbacks->resetci)(f); in fsm_sconfreq()
716 f->nakloops = 0; in fsm_sconfreq()
717 f->rnakloops = 0; in fsm_sconfreq()
722 f->retransmits = pcb->settings.fsm_max_conf_req_transmits; in fsm_sconfreq()
723 f->reqid = ++f->id; in fsm_sconfreq()
726 f->seen_ack = 0; in fsm_sconfreq()
731 if( f->callbacks->cilen && f->callbacks->addci ){ in fsm_sconfreq()
732 cilen = (*f->callbacks->cilen)(f); in fsm_sconfreq()
748 MAKEHEADER(outp, f->protocol); in fsm_sconfreq()
750 PUTCHAR(f->reqid, outp); in fsm_sconfreq()
753 (*f->callbacks->addci)(f, outp, &cilen); in fsm_sconfreq()
760 --f->retransmits; in fsm_sconfreq()
761 TIMEOUT(fsm_timeout, f, pcb->settings.fsm_timeout_time); in fsm_sconfreq()
770 void fsm_sdata(fsm *f, u_char code, u_char id, const u_char *data, int datalen) { in fsm_sdata() argument
771 ppp_pcb *pcb = f->pcb; in fsm_sdata()
792 MAKEHEADER(outp, f->protocol); in fsm_sdata()