ppp_fsm.c
Go to the documentation of this file.
1 /**
2  * @file ppp_fsm.c
3  * @brief PPP finite state machine
4  *
5  * @section License
6  *
7  * Copyright (C) 2010-2018 Oryx Embedded SARL. All rights reserved.
8  *
9  * This file is part of CycloneTCP Open.
10  *
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public License
13  * as published by the Free Software Foundation; either version 2
14  * of the License, or (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software Foundation,
23  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24  *
25  * @author Oryx Embedded SARL (www.oryx-embedded.com)
26  * @version 1.9.0
27  **/
28 
29 //Switch to the appropriate trace level
30 #define TRACE_LEVEL PPP_TRACE_LEVEL
31 
32 //Dependencies
33 #include "core/net.h"
34 #include "ppp/ppp_fsm.h"
35 #include "debug.h"
36 
37 //Check TCP/IP stack configuration
38 #if (PPP_SUPPORT == ENABLED)
39 
40 
41 /**
42  * @brief Process Up event
43  * @param[in] context PPP context
44  * @param[in,out] fsm Finite state machine
45  * @param[in] callbacks FSM actions
46  **/
47 
48 void pppUpEvent(PppContext *context, PppFsm *fsm,
49  const PppCallbacks *callbacks)
50 {
51  //Check current state
52  switch(fsm->state)
53  {
55  //Switch to the Closed state
57  break;
59  //Initialize restart counter
60  callbacks->initRestartCount(context, PPP_MAX_CONFIGURE);
61  //Send Configure-Request packet
62  callbacks->sendConfigureReq(context);
63  //Switch to the Req-Sent state
65  break;
66  default:
67  //This event cannot occur in a properly implemented automaton.
68  //No transition is taken, and the implementation should not
69  //reset or freeze
70  break;
71  }
72 }
73 
74 
75 /**
76  * @brief Process Down event
77  * @param[in] context PPP context
78  * @param[in,out] fsm Finite state machine
79  * @param[in] callbacks FSM actions
80  **/
81 
82 void pppDownEvent(PppContext *context, PppFsm *fsm,
83  const PppCallbacks *callbacks)
84 {
85  //Check current state
86  switch(fsm->state)
87  {
88  case PPP_STATE_2_CLOSED:
89  //Switch to the Initial state
91  break;
93  //Switch to the Starting state
95  //Indicate to the lower layers that the automaton is entering the
96  //Starting state. The lower layer is needed for the link
97  callbacks->thisLayerStarted(context);
98  break;
100  //Switch to the Initial state
102  break;
107  //Switch to the Starting state
109  break;
110  case PPP_STATE_9_OPENED:
111  //Switch to the Starting state
113  //Indicate to the upper layers that the automaton is leaving the Opened
114  //state. The link is no longer available for network traffic
115  callbacks->thisLayerDown(context);
116  break;
117  default:
118  //This event cannot occur in a properly implemented automaton.
119  //No transition is taken, and the implementation should not
120  //reset or freeze
121  break;
122  }
123 }
124 
125 
126 /**
127  * @brief Process Open event
128  * @param[in] context PPP context
129  * @param[in,out] fsm Finite state machine
130  * @param[in] callbacks FSM actions
131  **/
132 
133 void pppOpenEvent(PppContext *context, PppFsm *fsm,
134  const PppCallbacks *callbacks)
135 {
136  //Check current state
137  switch(fsm->state)
138  {
139  case PPP_STATE_0_INITIAL:
140  //Switch to the Starting state
142  //Indicate to the lower layers that the automaton is entering the
143  //Starting state. The lower layer is needed for the link
144  callbacks->thisLayerStarted(context);
145  break;
147  //Stay in current state
148  break;
149  case PPP_STATE_2_CLOSED:
150  //Initialize restart counter
151  callbacks->initRestartCount(context, PPP_MAX_CONFIGURE);
152  //Send Configure-Request packet
153  callbacks->sendConfigureReq(context);
154  //Switch to the Req-Sent state
156  break;
157  case PPP_STATE_3_STOPPED:
158  //Stay in current state
159  break;
160  case PPP_STATE_4_CLOSING:
161  //Switch to the Stopping state
163  break;
168  case PPP_STATE_9_OPENED:
169  //Stay in current state
170  break;
171  default:
172  //This event cannot occur in a properly implemented automaton.
173  //No transition is taken, and the implementation should not
174  //reset or freeze
175  break;
176  }
177 }
178 
179 
180 /**
181  * @brief Process Close event
182  * @param[in] context PPP context
183  * @param[in,out] fsm Finite state machine
184  * @param[in] callbacks FSM actions
185  **/
186 
187 void pppCloseEvent(PppContext *context, PppFsm *fsm,
188  const PppCallbacks *callbacks)
189 {
190  //Check current state
191  switch(fsm->state)
192  {
193  case PPP_STATE_0_INITIAL:
194  //Stay in current state
195  break;
197  //Switch to the Initial state
199  //Indicate to the lower layers that the automaton is entering the
200  //Initial, Closed or Stopped states. The lower layer is no longer
201  //needed for the link
202  callbacks->thisLayerFinished(context);
203  break;
204  case PPP_STATE_2_CLOSED:
205  //Stay in current state
206  break;
207  case PPP_STATE_3_STOPPED:
208  //Switch to the Closed state
210  break;
211  case PPP_STATE_4_CLOSING:
212  //Stay in current state
213  break;
215  //Switch to the Closing state
217  break;
221  //Initialize restart counter
222  callbacks->initRestartCount(context, PPP_MAX_TERMINATE);
223  //Send Terminate-Request packet
224  callbacks->sendTerminateReq(context);
225  //Switch to the Closing state
227  break;
228  case PPP_STATE_9_OPENED:
229  //Initialize restart counter
230  callbacks->initRestartCount(context, PPP_MAX_TERMINATE);
231  //Send Terminate-Request packet
232  callbacks->sendTerminateReq(context);
233  //Switch to the Closing state
235  //Indicate to the upper layers that the automaton is leaving the Opened
236  //state. The link is no longer available for network traffic
237  callbacks->thisLayerDown(context);
238  break;
239  default:
240  //This event cannot occur in a properly implemented automaton.
241  //No transition is taken, and the implementation should not
242  //reset or freeze
243  break;
244  }
245 }
246 
247 
248 /**
249  * @brief Process Timeout event
250  * @param[in] context PPP context
251  * @param[in,out] fsm Finite state machine
252  * @param[in] callbacks FSM actions
253  **/
254 
255 void pppTimeoutEvent(PppContext *context, PppFsm *fsm,
256  const PppCallbacks *callbacks)
257 {
258  //The restart counter is greater than zero (TO+ event)
259  if(fsm->restartCounter > 0)
260  {
261  //Check current state
262  switch(fsm->state)
263  {
264  case PPP_STATE_4_CLOSING:
266  //Send Terminate-Request packet
267  callbacks->sendTerminateReq(context);
268  //Stay in current state
269  break;
272  //Send Configuration-Request packet
273  callbacks->sendConfigureReq(context);
274  //Switch to the Req-Sent state
276  break;
278  //Send Configuration-Request packet
279  callbacks->sendConfigureReq(context);
280  //Stay in current state
281  break;
282  default:
283  //This event cannot occur in a properly implemented automaton.
284  //No transition is taken, and the implementation should not
285  //reset or freeze
286  break;
287  }
288  }
289  //The restart counter is not greater than zero (TO- event)
290  else
291  {
292  //Check current state
293  switch(fsm->state)
294  {
295  case PPP_STATE_4_CLOSING:
296  //Switch to the Closed state
298  //Indicate to the lower layers that the automaton is entering the
299  //Initial, Closed or Stopped states. The lower layer is no longer
300  //needed for the link
301  callbacks->thisLayerFinished(context);
302  break;
307  //Switch to the Stopped state
309  //Indicate to the lower layers that the automaton is entering the
310  //Initial, Closed or Stopped states. The lower layer is no longer
311  //needed for the link
312  callbacks->thisLayerFinished(context);
313  break;
314  default:
315  //This event cannot occur in a properly implemented automaton.
316  //No transition is taken, and the implementation should not
317  //reset or freeze
318  break;
319  }
320  }
321 }
322 
323 
324 /**
325  * @brief Process Receive-Configure-Request event
326  * @param[in] context PPP context
327  * @param[in,out] fsm Finite state machine
328  * @param[in] callbacks FSM actions
329  * @param[in] configureReqPacket Configure-Request packet received from the peer
330  * @param[in] code Tells whether the configuration options are acceptable
331  **/
332 
333 void pppRcvConfigureReqEvent(PppContext *context, PppFsm *fsm, const PppCallbacks *callbacks,
334  const PppConfigurePacket *configureReqPacket, PppCode code)
335 {
336  //Check whether the configuration options are acceptable
338  {
339  //If every configuration option received in the Configure-Request is
340  //recognizable and all values are acceptable, then the implementation
341  //must transmit a Configure-Ack
342  switch(fsm->state)
343  {
344  case PPP_STATE_2_CLOSED:
345  //Send Terminate-Ack packet
346  callbacks->sendTerminateAck(context, NULL);
347  //Stay in current state
348  break;
349  case PPP_STATE_3_STOPPED:
350  //Initialize restart counter
351  callbacks->initRestartCount(context, PPP_MAX_CONFIGURE);
352  //Send Configure-Request packet
353  callbacks->sendConfigureReq(context);
354  //Send Configure-Ack packet
355  callbacks->sendConfigureAck(context, configureReqPacket);
356  //Switch to the Ack-Sent state
358  break;
359  case PPP_STATE_4_CLOSING:
361  //Stay in current state
362  break;
364  //Send Configure-Ack packet
365  callbacks->sendConfigureAck(context, configureReqPacket);
366  //Switch to the Ack-Sent state
368  break;
370  //Send Configure-Ack packet
371  callbacks->sendConfigureAck(context, configureReqPacket);
372  //Switch to the Opened state
374  //Indicate to the upper layers that the automaton is entering the
375  //Opened state. The link is available for network traffic
376  callbacks->thisLayerUp(context);
377  break;
379  //Send Configure-Ack packet
380  callbacks->sendConfigureAck(context, configureReqPacket);
381  //Stay in current state
382  break;
383  case PPP_STATE_9_OPENED:
384  //Send Configure-Request packet
385  callbacks->sendConfigureReq(context);
386  //Send Configure-Ack packet
387  callbacks->sendConfigureAck(context, configureReqPacket);
388  //Switch to the Ack-Sent state
390  //Indicate to the upper layers that the automaton is leaving the Opened
391  //state. The link is no longer available for network traffic
392  callbacks->thisLayerDown(context);
393  break;
394  default:
395  //This event cannot occur in a properly implemented automaton.
396  //No transition is taken, and the implementation should not
397  //reset or freeze
398  break;
399  }
400  }
401  else if(code == PPP_CODE_CONFIGURE_NAK)
402  {
403  //If all configuration options are recognizable, but some values are not
404  //acceptable, then the implementation must transmit a Configure-Nak
405  switch(fsm->state)
406  {
407  case PPP_STATE_2_CLOSED:
408  //Send Terminate-Ack packet
409  callbacks->sendTerminateAck(context, NULL);
410  //Stay in current state
411  break;
412  case PPP_STATE_3_STOPPED:
413  //Initialize restart counter
414  callbacks->initRestartCount(context, PPP_MAX_CONFIGURE);
415  //Send Configure-Request packet
416  callbacks->sendConfigureReq(context);
417  //Send Configure-Nak packet
418  callbacks->sendConfigureNak(context, configureReqPacket);
419  //Switch to the Req-Sent state
421  break;
422  case PPP_STATE_4_CLOSING:
424  //Stay in current state
425  break;
428  //Send Configure-Nak packet
429  callbacks->sendConfigureNak(context, configureReqPacket);
430  //Stay in current state
431  break;
433  //Send Configure-Nak packet
434  callbacks->sendConfigureNak(context, configureReqPacket);
435  //Switch to the Req-Sent state
437  break;
438  case PPP_STATE_9_OPENED:
439  //Send Configure-Request packet
440  callbacks->sendConfigureReq(context);
441  //Send Configure-Nak packet
442  callbacks->sendConfigureNak(context, configureReqPacket);
443  //Switch to the Req-Sent state
445  //Indicate to the upper layers that the automaton is leaving the Opened
446  //state. The link is no longer available for network traffic
447  callbacks->thisLayerDown(context);
448  break;
449  default:
450  //This event cannot occur in a properly implemented automaton.
451  //No transition is taken, and the implementation should not
452  //reset or freeze
453  break;
454  }
455  }
456  else if(code == PPP_CODE_CONFIGURE_REJ)
457  {
458  //If some configuration options received in the Configure-Request are not
459  //recognizable or not acceptable for negotiation, then the implementation
460  //must transmit a Configure-Reject
461  switch(fsm->state)
462  {
463  case PPP_STATE_2_CLOSED:
464  //Send Terminate-Ack packet
465  callbacks->sendTerminateAck(context, NULL);
466  //Stay in current state
467  break;
468  case PPP_STATE_3_STOPPED:
469  //Initialize restart counter
470  callbacks->initRestartCount(context, PPP_MAX_CONFIGURE);
471  //Send Configure-Request packet
472  callbacks->sendConfigureReq(context);
473  //Send Configure-Reject packet
474  callbacks->sendConfigureRej(context, configureReqPacket);
475  //Switch to the Req-Sent state
477  break;
478  case PPP_STATE_4_CLOSING:
480  //Stay in current state
481  break;
484  //Send Configure-Reject packet
485  callbacks->sendConfigureRej(context, configureReqPacket);
486  //Stay in current state
487  break;
489  //Send Configure-Reject packet
490  callbacks->sendConfigureRej(context, configureReqPacket);
491  //Switch to the Req-Sent state
493  break;
494  case PPP_STATE_9_OPENED:
495  //Send Configure-Request packet
496  callbacks->sendConfigureReq(context);
497  //Send Configure-Reject packet
498  callbacks->sendConfigureRej(context, configureReqPacket);
499  //Switch to the Req-Sent state
501  //Indicate to the upper layers that the automaton is leaving the Opened
502  //state. The link is no longer available for network traffic
503  callbacks->thisLayerDown(context);
504  break;
505  default:
506  //This event cannot occur in a properly implemented automaton.
507  //No transition is taken, and the implementation should not
508  //reset or freeze
509  break;
510  }
511  }
512 }
513 
514 
515 /**
516  * @brief Process Receive-Configure-Ack event
517  * @param[in] context PPP context
518  * @param[in,out] fsm Finite state machine
519  * @param[in] callbacks FSM actions
520  **/
521 
523  const PppCallbacks *callbacks)
524 {
525  //Check current state
526  switch(fsm->state)
527  {
528  case PPP_STATE_2_CLOSED:
529  case PPP_STATE_3_STOPPED:
530  //Send Terminate-Ack packet
531  callbacks->sendTerminateAck(context, NULL);
532  //Stay in current state
533  break;
534  case PPP_STATE_4_CLOSING:
536  //Stay in current state
537  break;
539  //Initialize restart counter
540  callbacks->initRestartCount(context, PPP_MAX_CONFIGURE);
541  //Switch to the Ack-Rcvd state
543  break;
545  //Send Configure-Request packet
546  callbacks->sendConfigureReq(context);
547  //Switch to the Req-Sent state
549  break;
551  //Initialize restart counter
552  callbacks->initRestartCount(context, PPP_MAX_CONFIGURE);
553  //Switch to the Opened state
555  //Indicate to the upper layers that the automaton is entering the
556  //Opened state. The link is available for network traffic
557  callbacks->thisLayerUp(context);
558  break;
559  case PPP_STATE_9_OPENED:
560  //Send Configure-Request packet
561  callbacks->sendConfigureReq(context);
562  //Switch to the Req-Sent state
564  //Indicate to the upper layers that the automaton is leaving the Opened
565  //state. The link is no longer available for network traffic
566  callbacks->thisLayerDown(context);
567  break;
568  default:
569  //This event cannot occur in a properly implemented automaton.
570  //No transition is taken, and the implementation should not
571  //reset or freeze
572  break;
573  }
574 }
575 
576 
577 /**
578  * @brief Process Receive-Configure-Nak event
579  * @param[in] context PPP context
580  * @param[in,out] fsm Finite state machine
581  * @param[in] callbacks FSM actions
582  **/
583 
585  const PppCallbacks *callbacks)
586 {
587  //Check current state
588  switch(fsm->state)
589  {
590  case PPP_STATE_2_CLOSED:
591  case PPP_STATE_3_STOPPED:
592  //Send Terminate-Ack packet
593  callbacks->sendTerminateAck(context, NULL);
594  //Stay in current state
595  break;
596  case PPP_STATE_4_CLOSING:
598  //Stay in current state
599  break;
601  //Initialize restart counter
602  callbacks->initRestartCount(context, PPP_MAX_CONFIGURE);
603  //Send Configure-Request packet
604  callbacks->sendConfigureReq(context);
605  //Stay in current state
606  break;
608  //Send Configure-Request packet
609  callbacks->sendConfigureReq(context);
610  //Switch to the Req-Sent state
612  break;
614  //Initialize restart counter
615  callbacks->initRestartCount(context, PPP_MAX_CONFIGURE);
616  //Send Configure-Request packet
617  callbacks->sendConfigureReq(context);
618  //Stay in current state
619  break;
620  case PPP_STATE_9_OPENED:
621  //Send Configure-Request packet
622  callbacks->sendConfigureReq(context);
623  //Switch to the Req-Sent state
625  //Indicate to the upper layers that the automaton is leaving the Opened
626  //state. The link is no longer available for network traffic
627  callbacks->thisLayerDown(context);
628  break;
629  default:
630  //This event cannot occur in a properly implemented automaton.
631  //No transition is taken, and the implementation should not
632  //reset or freeze
633  break;
634  }
635 }
636 
637 
638 /**
639  * @brief Process Receive-Terminate-Req event
640  * @param[in] context PPP context
641  * @param[in,out] fsm Finite state machine
642  * @param[in] callbacks FSM actions
643  * @param[in] terminateReqPacket Terminate-Request packet received from the peer
644  **/
645 
647  const PppCallbacks *callbacks, const PppTerminatePacket *terminateReqPacket)
648 {
649  //Check current state
650  switch(fsm->state)
651  {
652  case PPP_STATE_2_CLOSED:
653  case PPP_STATE_3_STOPPED:
654  case PPP_STATE_4_CLOSING:
656  //Send Terminate-Ack packet
657  callbacks->sendTerminateAck(context, terminateReqPacket);
658  //Stay in current state
659  break;
663  //Send Terminate-Ack packet
664  callbacks->sendTerminateAck(context, terminateReqPacket);
665  //Switch to the Req-Sent state
667  break;
668  case PPP_STATE_9_OPENED:
669  //Zero restart counter
670  callbacks->zeroRestartCount(context);
671  //Send Terminate-Ack packet
672  callbacks->sendTerminateAck(context, terminateReqPacket);
673  //Switch to the Stopping state
675  //Indicate to the upper layers that the automaton is leaving the Opened
676  //state. The link is no longer available for network traffic
677  callbacks->thisLayerDown(context);
678  break;
679  default:
680  //This event cannot occur in a properly implemented automaton.
681  //No transition is taken, and the implementation should not
682  //reset or freeze
683  break;
684  }
685 }
686 
687 
688 /**
689  * @brief Process Receive-Terminate-Ack event
690  * @param[in] context PPP context
691  * @param[in,out] fsm Finite state machine
692  * @param[in] callbacks FSM actions
693  **/
694 
696  const PppCallbacks *callbacks)
697 {
698  //Check current state
699  switch(fsm->state)
700  {
701  case PPP_STATE_2_CLOSED:
702  case PPP_STATE_3_STOPPED:
703  //Stay in current state
704  break;
705  case PPP_STATE_4_CLOSING:
706  //Switch to the Closed state
708  //Indicate to the lower layers that the automaton is entering the
709  //Initial, Closed or Stopped states. The lower layer is no longer
710  //needed for the link
711  callbacks->thisLayerFinished(context);
712  break;
714  //Switch to the Stopped state
716  //Indicate to the lower layers that the automaton is entering the
717  //Initial, Closed or Stopped states. The lower layer is no longer
718  //needed for the link
719  callbacks->thisLayerFinished(context);
720  break;
723  //Switch to the Req-Sent state
725  break;
727  //Stay in current state
728  break;
729  case PPP_STATE_9_OPENED:
730  //Send Configure-Req packet
731  callbacks->sendConfigureReq(context);
732  //Switch to the Req-Sent state
734  //Indicate to the upper layers that the automaton is leaving the Opened
735  //state. The link is no longer available for network traffic
736  callbacks->thisLayerDown(context);
737  break;
738  default:
739  //This event cannot occur in a properly implemented automaton.
740  //No transition is taken, and the implementation should not
741  //reset or freeze
742  break;
743  }
744 }
745 
746 
747 /**
748  * @brief Process Receive-Unknown-Code event
749  * @param[in] context PPP context
750  * @param[in,out] fsm Finite state machine
751  * @param[in] callbacks FSM actions
752  * @param[in] packet Un-interpretable packet received from the peer
753  **/
754 
756  const PppCallbacks *callbacks, const PppPacket *packet)
757 {
758  //Check current state
759  switch(fsm->state)
760  {
761  case PPP_STATE_2_CLOSED:
762  case PPP_STATE_3_STOPPED:
763  case PPP_STATE_4_CLOSING:
768  case PPP_STATE_9_OPENED:
769  //Send Reject-Code packet
770  callbacks->sendCodeRej(context, packet);
771  //Stay in current state
772  break;
773  default:
774  //This event cannot occur in a properly implemented automaton.
775  //No transition is taken, and the implementation should not
776  //reset or freeze
777  break;
778  }
779 }
780 
781 /**
782  * @brief Process Receive-Code-Reject or Receive-Protocol-Reject event
783  * @param[in] context PPP context
784  * @param[in,out] fsm Finite state machine
785  * @param[in] callbacks FSM actions
786  * @param[in] acceptable This parameter tells whether the rejected value
787  * is acceptable or catastrophic
788  **/
789 
791  const PppCallbacks *callbacks, bool_t acceptable)
792 {
793  //Check whether the rejected value is acceptable or catastrophic
794  if(acceptable)
795  {
796  //The RXJ+ event arises when the rejected value is acceptable, such
797  //as a Code-Reject of an extended code, or a Protocol-Reject of a
798  //NCP. These are within the scope of normal operation
799  switch(fsm->state)
800  {
801  case PPP_STATE_2_CLOSED:
802  case PPP_STATE_3_STOPPED:
803  case PPP_STATE_4_CLOSING:
806  //Stay in current state
807  break;
809  //Switch to the Req-Sent state
811  break;
813  case PPP_STATE_9_OPENED:
814  //Stay in current state
815  break;
816  default:
817  //This event cannot occur in a properly implemented automaton.
818  //No transition is taken, and the implementation should not
819  //reset or freeze
820  break;
821  }
822  }
823  else
824  {
825  //The RXJ- event arises when the rejected value is catastrophic,
826  //such as a Code-Reject of Configure-Request, or a Protocol-Reject
827  //of LCP! This event communicates an unrecoverable error that
828  //terminates the connection
829  switch(fsm->state)
830  {
831  case PPP_STATE_2_CLOSED:
832  case PPP_STATE_3_STOPPED:
833  //Indicate to the lower layers that the automaton is entering the
834  //Initial, Closed or Stopped states. The lower layer is no longer
835  //needed for the link
836  callbacks->thisLayerFinished(context);
837  //Stay in current state
838  break;
839  case PPP_STATE_4_CLOSING:
840  //Switch to the Closed state
842  //Indicate to the lower layers that the automaton is entering the
843  //Initial, Closed or Stopped states. The lower layer is no longer
844  //needed for the link
845  callbacks->thisLayerFinished(context);
846  break;
851  //Switch to the Stopped state
853  //Indicate to the lower layers that the automaton is entering the
854  //Initial, Closed or Stopped states. The lower layer is no longer
855  //needed for the link
856  callbacks->thisLayerFinished(context);
857  break;
858  case PPP_STATE_9_OPENED:
859  //Initialize restart counter
860  callbacks->initRestartCount(context, PPP_MAX_TERMINATE);
861  //Send Terminate-Req packet
862  callbacks->sendTerminateReq(context);
863  //Switch to the Stopping state
865  //Indicate to the upper layers that the automaton is leaving the Opened
866  //state. The link is no longer available for network traffic
867  callbacks->thisLayerDown(context);
868  break;
869  default:
870  //This event cannot occur in a properly implemented automaton.
871  //No transition is taken, and the implementation should not
872  //reset or freeze
873  break;
874  }
875  }
876 }
877 
878 
879 /**
880  * @brief Process Receive-Echo-Request event
881  * @param[in] context PPP context
882  * @param[in,out] fsm Finite state machine
883  * @param[in] callbacks FSM actions
884  * @param[in] echoReqPacket Echo-Request packet received from the peer
885  **/
886 
888  const PppCallbacks *callbacks, const PppEchoPacket *echoReqPacket)
889 {
890  //Check current state
891  switch(fsm->state)
892  {
893  case PPP_STATE_2_CLOSED:
894  case PPP_STATE_3_STOPPED:
895  case PPP_STATE_4_CLOSING:
900  //Stay in current state
901  break;
902  case PPP_STATE_9_OPENED:
903  //Send Echo-Reply packet
904  callbacks->sendEchoRep(context, echoReqPacket);
905  //Stay in current state
906  break;
907  default:
908  //This event cannot occur in a properly implemented automaton.
909  //No transition is taken, and the implementation should not
910  //reset or freeze
911  break;
912  }
913 }
914 
915 
916 /**
917  * @brief Update PPP FSM state
918  * @param[in,out] fsm Finite state machine
919  * @param[in] newState New PPP state to switch to
920  **/
921 
922 void pppChangeState(PppFsm *fsm, PppState newState)
923 {
924 #if (PPP_TRACE_LEVEL >= TRACE_LEVEL_INFO)
925  //PPP FSM states
926  static const char_t *stateLabel[] =
927  {
928  "INITIAL", //0
929  "STARTING", //1
930  "CLOSED", //2
931  "STOPPED", //3
932  "CLOSING", //4
933  "STOPPING", //5
934  "REQ_SENT", //6
935  "ACK_RCVD", //7
936  "ACK_SENT", //8
937  "OPENED" //9
938  };
939 
940  //Sanity check
941  if(fsm->state < arraysize(stateLabel) && newState < arraysize(stateLabel))
942  {
943  //Debug message
944  TRACE_INFO("PPP FSM: %s (%u) -> %s (%u)\r\n", stateLabel[fsm->state],
945  fsm->state, stateLabel[newState], newState);
946  }
947 #endif
948 
949  //Switch to the new state
950  fsm->state = newState;
951 }
952 
953 #endif
__start_packed struct @289 PppTerminatePacket
Terminate-Request and Terminate-Ack packet.
#define PPP_MAX_CONFIGURE
Definition: ppp.h:101
void pppOpenEvent(PppContext *context, PppFsm *fsm, const PppCallbacks *callbacks)
Process Open event.
Definition: ppp_fsm.c:133
PppThisLayerUp thisLayerUp
Definition: ppp_fsm.h:152
PppSendEchoRep sendEchoRep
Definition: ppp_fsm.h:165
char char_t
Definition: compiler_port.h:41
PppSendTerminateAck sendTerminateAck
Definition: ppp_fsm.h:163
void pppRcvTerminateAckEvent(PppContext *context, PppFsm *fsm, const PppCallbacks *callbacks)
Process Receive-Terminate-Ack event.
Definition: ppp_fsm.c:695
TCP/IP stack core.
Debugging facilities.
__start_packed struct @292 PppEchoPacket
Echo-Request and Echo-Reply packet.
PppCode
Code field values.
Definition: ppp.h:212
PPP finite state machine.
Definition: ppp.h:393
PPP FSM actions.
Definition: ppp_fsm.h:150
PppSendConfigureNak sendConfigureNak
Definition: ppp_fsm.h:160
void pppRcvTerminateReqEvent(PppContext *context, PppFsm *fsm, const PppCallbacks *callbacks, const PppTerminatePacket *terminateReqPacket)
Process Receive-Terminate-Req event.
Definition: ppp_fsm.c:646
PppSendCodeRej sendCodeRej
Definition: ppp_fsm.h:164
PppSendConfigureRej sendConfigureRej
Definition: ppp_fsm.h:161
#define PppPacket
Definition: ppp.h:35
PppZeroRestartCount zeroRestartCount
Definition: ppp_fsm.h:157
PppThisLayerFinished thisLayerFinished
Definition: ppp_fsm.h:155
#define arraysize(a)
Definition: os_port.h:68
void pppUpEvent(PppContext *context, PppFsm *fsm, const PppCallbacks *callbacks)
Process Up event.
Definition: ppp_fsm.c:48
uint_t restartCounter
Restart counter.
Definition: ppp.h:397
PppInitRestartCount initRestartCount
Definition: ppp_fsm.h:156
PppThisLayerStarted thisLayerStarted
Definition: ppp_fsm.h:154
void pppRcvConfigureAckEvent(PppContext *context, PppFsm *fsm, const PppCallbacks *callbacks)
Process Receive-Configure-Ack event.
Definition: ppp_fsm.c:522
uint_t state
FSM state.
Definition: ppp.h:395
void pppChangeState(PppFsm *fsm, PppState newState)
Update PPP FSM state.
Definition: ppp_fsm.c:922
void pppDownEvent(PppContext *context, PppFsm *fsm, const PppCallbacks *callbacks)
Process Down event.
Definition: ppp_fsm.c:82
void pppRcvConfigureReqEvent(PppContext *context, PppFsm *fsm, const PppCallbacks *callbacks, const PppConfigurePacket *configureReqPacket, PppCode code)
Process Receive-Configure-Request event.
Definition: ppp_fsm.c:333
PppThisLayerDown thisLayerDown
Definition: ppp_fsm.h:153
#define PppContext
Definition: ppp.h:36
PppSendConfigureReq sendConfigureReq
Definition: ppp_fsm.h:158
#define TRACE_INFO(...)
Definition: debug.h:86
PPP finite state machine.
Configure-Ack.
Definition: ppp.h:215
uint8_t code
Definition: coap_common.h:179
PppSendConfigureAck sendConfigureAck
Definition: ppp_fsm.h:159
PppSendTerminateReq sendTerminateReq
Definition: ppp_fsm.h:162
void pppRcvUnknownCodeEvent(PppContext *context, PppFsm *fsm, const PppCallbacks *callbacks, const PppPacket *packet)
Process Receive-Unknown-Code event.
Definition: ppp_fsm.c:755
PppState
LCP/NCP states.
Definition: ppp.h:176
#define PPP_MAX_TERMINATE
Definition: ppp.h:108
void pppRcvConfigureNakEvent(PppContext *context, PppFsm *fsm, const PppCallbacks *callbacks)
Process Receive-Configure-Nak event.
Definition: ppp_fsm.c:584
void pppRcvEchoReqEvent(PppContext *context, PppFsm *fsm, const PppCallbacks *callbacks, const PppEchoPacket *echoReqPacket)
Process Receive-Echo-Request event.
Definition: ppp_fsm.c:887
void pppTimeoutEvent(PppContext *context, PppFsm *fsm, const PppCallbacks *callbacks)
Process Timeout event.
Definition: ppp_fsm.c:255
void pppRcvCodeRejEvent(PppContext *context, PppFsm *fsm, const PppCallbacks *callbacks, bool_t acceptable)
Process Receive-Code-Reject or Receive-Protocol-Reject event.
Definition: ppp_fsm.c:790
Configure-Nak.
Definition: ppp.h:216
Configure-Reject.
Definition: ppp.h:217
__start_packed struct @288 PppConfigurePacket
Configure-Request, Configure-Ack, Configure-Nak and Configure-Reject packets.
int bool_t
Definition: compiler_port.h:47
void pppCloseEvent(PppContext *context, PppFsm *fsm, const PppCallbacks *callbacks)
Process Close event.
Definition: ppp_fsm.c:187