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