lcp.c
Go to the documentation of this file.
1 /**
2  * @file lcp.c
3  * @brief LCP (PPP Link Control Protocol)
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2010-2023 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 2.2.4
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 "ppp/ppp_misc.h"
38 #include "ppp/ppp_debug.h"
39 #include "ppp/lcp.h"
40 #include "ppp/ipcp.h"
41 #include "ppp/ipv6cp.h"
42 #include "ppp/pap.h"
43 #include "ppp/chap.h"
44 #include "debug.h"
45 
46 //Check TCP/IP stack configuration
47 #if (PPP_SUPPORT == ENABLED)
48 
49 
50 /**
51  * @brief LCP FSM callbacks
52  **/
53 
55 {
70 };
71 
72 
73 /**
74  * @brief LCP Open event
75  * @param[in] context PPP context
76  * @return Error code
77  **/
78 
80 {
81  //Debug message
82  TRACE_INFO("\r\nLCP Open event\r\n");
83 
84  //Advance to the Establish phase
85  context->pppPhase = PPP_PHASE_ESTABLISH;
86 
87  //The link is administratively available for traffic
88  pppOpenEvent(context, &context->lcpFsm, &lcpCallbacks);
89  //The lower layer is ready to carry packets
90  pppUpEvent(context, &context->lcpFsm, &lcpCallbacks);
91 
92  //Successful processing
93  return NO_ERROR;
94 }
95 
96 
97 /**
98  * @brief LCP Close event
99  * @param[in] context PPP context
100  * @return Error code
101  **/
102 
104 {
105  //Debug message
106  TRACE_INFO("\r\nLCP Close event\r\n");
107 
108  //The link is no longer available for traffic
109  pppCloseEvent(context, &context->lcpFsm, &lcpCallbacks);
110 
111  //Successful processing
112  return NO_ERROR;
113 }
114 
115 
116 /**
117  * @brief LCP timer handler
118  *
119  * This routine must be periodically called by the TCP/IP stack to
120  * manage retransmissions
121  *
122  * @param[in] context PPP context
123  **/
124 
125 void lcpTick(PppContext *context)
126 {
127  //Check whether the restart timer is running
128  if(context->lcpFsm.state >= PPP_STATE_4_CLOSING &&
129  context->lcpFsm.state <= PPP_STATE_8_ACK_SENT)
130  {
131  //Get current time
133 
134  //Check restart timer
135  if((time - context->lcpFsm.timestamp) >= PPP_RESTART_TIMER)
136  {
137  //Debug message
138  TRACE_INFO("\r\nLCP Timeout event\r\n");
139 
140  //The restart timer is used to retransmit Configure-Request
141  //and Terminate-Request packets
142  pppTimeoutEvent(context, &context->lcpFsm, &lcpCallbacks);
143  }
144  }
145 }
146 
147 
148 /**
149  * @brief Process an incoming LCP packet
150  * @param[in] context PPP context
151  * @param[in] packet LCP packet received from the peer
152  * @param[in] length Length of the packet, in bytes
153  **/
154 
155 void lcpProcessPacket(PppContext *context, const PppPacket *packet, size_t length)
156 {
157  //Ensure the length of the incoming LCP packet is valid
158  if(length < sizeof(PppPacket))
159  return;
160 
161  //Check the length field
162  if(ntohs(packet->length) > length)
163  return;
164  if(ntohs(packet->length) < sizeof(PppPacket))
165  return;
166 
167  //Save the length of the LCP packet
168  length = ntohs(packet->length);
169 
170  //Debug message
171  TRACE_INFO("LCP packet received (%" PRIuSIZE " bytes)...\r\n", length);
172  //Dump LCP packet contents for debugging purpose
174 
175  //Check LCP code field
176  switch(packet->code)
177  {
178  //Configure-Request packet?
180  //Process Configure-Request packet
181  lcpProcessConfigureReq(context, (PppConfigurePacket *) packet);
182  break;
183  //Configure-Ack packet?
185  //Process Configure-Ack packet
186  lcpProcessConfigureAck(context, (PppConfigurePacket *) packet);
187  break;
188  //Configure-Nak packet?
190  //Process Configure-Nak packet
191  lcpProcessConfigureNak(context, (PppConfigurePacket *) packet);
192  break;
193  //Configure-Reject packet?
195  //Process Configure-Reject packet
196  lcpProcessConfigureReject(context, (PppConfigurePacket *) packet);
197  break;
198  //Terminate-Request packet?
200  //Process Terminate-Request packet
201  lcpProcessTerminateReq(context, (PppTerminatePacket *) packet);
202  break;
203  //Terminate-Ack packet?
205  //Process Terminate-Ack packet
206  lcpProcessTerminateAck(context, (PppTerminatePacket *) packet);
207  break;
208  //Code-Reject packet?
209  case PPP_CODE_CODE_REJ:
210  //Process Code-Reject packet
211  lcpProcessCodeRej(context, (PppCodeRejPacket *) packet);
212  break;
213  //Protocol-Reject packet?
215  //Process Protocol-Reject packet
216  lcpProcessProtocolRej(context, (PppProtocolRejPacket *) packet);
217  break;
218  //Echo-Request packet?
219  case PPP_CODE_ECHO_REQ:
220  //Process Echo-Request packet
221  lcpProcessEchoReq(context, (PppEchoPacket *) packet);
222  break;
223  //Echo-Reply packet?
224  case PPP_CODE_ECHO_REP:
225  //Process Echo-Reply packet
226  lcpProcessEchoRep(context, (PppEchoPacket *) packet);
227  break;
228  //Discard-Request packet?
230  //Process Discard-Request packet
231  lcpProcessDiscardReq(context, (PppDiscardReqPacket *) packet);
232  break;
233  //Unknown code field
234  default:
235  //The packet is un-interpretable
236  lcpProcessUnknownCode(context, packet);
237  break;
238  }
239 }
240 
241 
242 /**
243  * @brief Process Configure-Request packet
244  * @param[in] context PPP context
245  * @param[in] configureReqPacket Packet received from the peer
246  * @return Error code
247  **/
248 
250  const PppConfigurePacket *configureReqPacket)
251 {
252  error_t error;
253  size_t length;
254  bool_t notRecognizable;
255  bool_t notAcceptable;
256  PppOption *option;
257 
258  //Debug message
259  TRACE_INFO("\r\nLCP Receive-Configure-Request event\r\n");
260 
261  //Initialize variables
262  error = NO_ERROR;
263  notRecognizable = FALSE;
264  notAcceptable = FALSE;
265 
266  //Retrieve the length of the option list
267  length = ntohs(configureReqPacket->length) - sizeof(PppConfigurePacket);
268  //Point to the first option
269  option = (PppOption *) configureReqPacket->options;
270 
271  //Parse configuration options
272  while(length > 0)
273  {
274  //Parse current option
275  error = lcpParseOption(context, option, length, NULL);
276 
277  //Any error to report?
278  if(error == ERROR_INVALID_TYPE)
279  {
280  //Option not recognizable
281  notRecognizable = TRUE;
282  //Catch error
283  error = NO_ERROR;
284  }
285  else if(error == ERROR_INVALID_VALUE)
286  {
287  //Option not acceptable for configuration
288  notAcceptable = TRUE;
289  //Catch error
290  error = NO_ERROR;
291  }
292  else if(error)
293  {
294  //Malformed Configure-Request packet
295  break;
296  }
297 
298  //Remaining bytes to process
299  length -= option->length;
300  //Jump to the next option
301  option = (PppOption *) ((uint8_t *) option + option->length);
302  }
303 
304  //Valid Configure-Request packet received from the peer?
305  if(!error)
306  {
307  //Check flags
308  if(notRecognizable)
309  {
310  //If some configuration options received in the Configure-Request are not
311  //recognizable or not acceptable for negotiation, then the implementation
312  //must transmit a Configure-Reject
313  pppRcvConfigureReqEvent(context, &context->lcpFsm, &lcpCallbacks,
314  configureReqPacket, PPP_CODE_CONFIGURE_REJ);
315  }
316  else if(notAcceptable)
317  {
318  //If all configuration options are recognizable, but some values are not
319  //acceptable, then the implementation must transmit a Configure-Nak
320  pppRcvConfigureReqEvent(context, &context->lcpFsm, &lcpCallbacks,
321  configureReqPacket, PPP_CODE_CONFIGURE_NAK);
322  }
323  else
324  {
325  //If every configuration option received in the Configure-Request is
326  //recognizable and all values are acceptable, then the implementation
327  //must transmit a Configure-Ack
328  pppRcvConfigureReqEvent(context, &context->lcpFsm, &lcpCallbacks,
329  configureReqPacket, PPP_CODE_CONFIGURE_ACK);
330  }
331  }
332 
333  //Return status code
334  return error;
335 }
336 
337 
338 /**
339  * @brief Process Configure-Ack packet
340  * @param[in] context PPP context
341  * @param[in] configureAckPacket Packet received from the peer
342  * @return Error code
343  **/
344 
346  const PppConfigurePacket *configureAckPacket)
347 {
348  //Debug message
349  TRACE_INFO("\r\nLCP Receive-Configure-Ack event\r\n");
350 
351  //When a packet is received with an invalid Identifier field, the
352  //packet is silently discarded without affecting the automaton
353  if(configureAckPacket->identifier != context->lcpFsm.identifier)
354  return ERROR_WRONG_IDENTIFIER;
355 
356  //A valid Configure-Ack packet has been received from the peer
357  pppRcvConfigureAckEvent(context, &context->lcpFsm, &lcpCallbacks);
358 
359  //Successful processing
360  return NO_ERROR;
361 }
362 
363 
364 /**
365  * @brief Process Configure-Nak packet
366  * @param[in] context PPP context
367  * @param[in] configureNakPacket Packet received from the peer
368  * @return Error code
369  **/
370 
372  const PppConfigurePacket *configureNakPacket)
373 {
374  size_t length;
375  PppOption *option;
376 
377  //Debug message
378  TRACE_INFO("LCP Receive-Configure-Nak event\r\n");
379 
380  //When a packet is received with an invalid Identifier field, the
381  //packet is silently discarded without affecting the automaton
382  if(configureNakPacket->identifier != context->lcpFsm.identifier)
383  return ERROR_WRONG_IDENTIFIER;
384 
385  //Retrieve the length of the option list
386  length = ntohs(configureNakPacket->length) - sizeof(PppConfigurePacket);
387  //Point to the first option
388  option = (PppOption *) configureNakPacket->options;
389 
390  //Parse configuration options
391  while(length > 0)
392  {
393  //Check option length
394  if(option->length < sizeof(PppOption))
395  return ERROR_INVALID_LENGTH;
396  if(option->length > length)
397  return ERROR_INVALID_LENGTH;
398 
399  //Maximum-Receive-Unit option?
400  if(option->type == LCP_OPTION_MRU)
401  {
402  //Cast option
403  LcpMruOption *mruOption = (LcpMruOption *) option;
404 
405  //Check option length
406  if(mruOption->length != sizeof(LcpMruOption))
407  return ERROR_INVALID_LENGTH;
408 
409  //Save value
410  context->localConfig.mru = ntohs(mruOption->mru);
411  //Make sure the MRU is acceptable
412  context->localConfig.mru = MAX(context->localConfig.mru, PPP_MIN_MRU);
413  context->localConfig.mru = MIN(context->localConfig.mru, PPP_MAX_MRU);
414  }
415  else if(option->type == LCP_OPTION_ACCM)
416  {
417  //Cast option
418  LcpAccmOption *accmOption = (LcpAccmOption *) option;
419 
420  //Check option length
421  if(accmOption->length != sizeof(LcpAccmOption))
422  return ERROR_INVALID_LENGTH;
423 
424  //Save value
425  context->localConfig.accm = ntohl(accmOption->accm);
426  }
427  //Authentication-Protocol option?
428  else if(option->type == LCP_OPTION_AUTH_PROTOCOL)
429  {
430  //Cast option
431  LcpAuthProtocolOption *authProtocolOption = (LcpAuthProtocolOption *) option;
432 
433  //Check option length
434  if(authProtocolOption->length < sizeof(LcpAuthProtocolOption))
435  return ERROR_INVALID_LENGTH;
436 
437  //Check the value provided by the peer
438  if(ntohs(authProtocolOption->protocol) == PPP_PROTOCOL_PAP)
439  {
440 #if (PAP_SUPPORT == ENABLED)
441  //Manage authentication policy
442  if(context->settings.authProtocol & PPP_AUTH_PROTOCOL_PAP)
443  {
444  //Select PAP authentication protocol
445  context->localConfig.authProtocol = PPP_PROTOCOL_PAP;
446  }
447 #endif
448  }
449  else if(ntohs(authProtocolOption->protocol) == PPP_PROTOCOL_CHAP)
450  {
451 #if (CHAP_SUPPORT == ENABLED)
452  //Make sure that the length of the option is correct
453  if(authProtocolOption->length > sizeof(LcpAuthProtocolOption))
454  {
455  //Check the algorithm identifier
456  if(authProtocolOption->data[0] == CHAP_ALGO_ID_CHAP_MD5)
457  {
458  //Manage authentication policy
459  if(context->settings.authProtocol & PPP_AUTH_PROTOCOL_CHAP_MD5)
460  {
461  //Select CHAP with MD5 authentication protocol
462  context->localConfig.authProtocol = PPP_PROTOCOL_CHAP;
463  context->localConfig.authAlgo = CHAP_ALGO_ID_CHAP_MD5;
464  }
465  }
466  }
467 #endif
468  }
469  }
470 
471  //Remaining bytes to process
472  length -= option->length;
473  //Jump to the next option
474  option = (PppOption *) ((uint8_t *) option + option->length);
475  }
476 
477  //A valid Configure-Nak or Configure-Reject packet has been received from the peer
478  pppRcvConfigureNakEvent(context, &context->lcpFsm, &lcpCallbacks);
479 
480  //Successful processing
481  return NO_ERROR;
482 }
483 
484 
485 /**
486  * @brief Process Configure-Reject packet
487  * @param[in] context PPP context
488  * @param[in] configureRejPacket Packet received from the peer
489  * @return Error code
490  **/
491 
493  const PppConfigurePacket *configureRejPacket)
494 {
495  size_t length;
496  PppOption *option;
497 
498  //Debug message
499  TRACE_INFO("\r\nLCP Receive-Configure-Reject event\r\n");
500 
501  //When a packet is received with an invalid Identifier field, the
502  //packet is silently discarded without affecting the automaton
503  if(configureRejPacket->identifier != context->lcpFsm.identifier)
504  return ERROR_WRONG_IDENTIFIER;
505 
506  //Retrieve the length of the option list
507  length = ntohs(configureRejPacket->length) - sizeof(PppConfigurePacket);
508  //Point to the first option
509  option = (PppOption *) configureRejPacket->options;
510 
511  //Parse configuration options
512  while(length > 0)
513  {
514  //Check option length
515  if(option->length < sizeof(PppOption))
516  return ERROR_INVALID_LENGTH;
517  if(option->length > length)
518  return ERROR_INVALID_LENGTH;
519 
520  //Maximum-Receive-Unit option?
521  if(option->type == LCP_OPTION_MRU)
522  {
523  //The option is not recognized by the peer
524  context->localConfig.mruRejected = TRUE;
525  //Restore default value
526  context->localConfig.mru = PPP_DEFAULT_MRU;
527  }
528  //Async-Control-Character-Map option?
529  else if(option->type == LCP_OPTION_ACCM)
530  {
531  //The option is not recognized by the peer
532  context->localConfig.accmRejected = TRUE;
533  //Restore default value
534  context->localConfig.accm = PPP_DEFAULT_ACCM;
535  }
536  //Authentication-Protocol option?
537  else if(option->type == LCP_OPTION_AUTH_PROTOCOL)
538  {
539  //This is an unrecoverable error that terminates the connection
540  pppRcvCodeRejEvent(context, &context->lcpFsm, &lcpCallbacks, FALSE);
541  //Exit immediately
542  return ERROR_FAILURE;
543  }
544  //Magic-Number option?
545  else if(option->type == LCP_OPTION_MAGIC_NUMBER)
546  {
547  //The option is not recognized by the peer
548  context->localConfig.magicNumberRejected = TRUE;
549  //Restore default value
550  context->localConfig.magicNumber = PPP_DEFAULT_MAGIC_NUMBER;
551  }
552  //Protocol-Field-Compression option?
553  else if(option->type == LCP_OPTION_PFC)
554  {
555  //The option is not recognized by the peer
556  context->localConfig.pfcRejected = TRUE;
557  //Restore default value
558  context->localConfig.pfc = FALSE;
559  }
560  //Address-and-Control-Field-Compression option?
561  else if(option->type == LCP_OPTION_ACFC)
562  {
563  //The option is not recognized by the peer
564  context->localConfig.acfcRejected = TRUE;
565  //Restore default value
566  context->localConfig.acfc = FALSE;
567  }
568 
569  //Remaining bytes to process
570  length -= option->length;
571  //Jump to the next option
572  option = (PppOption *) ((uint8_t *) option + option->length);
573  }
574 
575  //A valid Configure-Nak or Configure-Reject packet has been received from the peer
576  pppRcvConfigureNakEvent(context, &context->lcpFsm, &lcpCallbacks);
577 
578  //Successful processing
579  return NO_ERROR;
580 }
581 
582 
583 /**
584  * @brief Process Terminate-Request packet
585  * @param[in] context PPP context
586  * @param[in] terminateReqPacket Packet received from the peer
587  * @return Error code
588  **/
589 
591  const PppTerminatePacket *terminateReqPacket)
592 {
593  //Debug message
594  TRACE_INFO("\r\nLCP Receive-Terminate-Request event\r\n");
595 
596  //The Terminate-Request indicates the desire of the peer to close the connection
597  pppRcvTerminateReqEvent(context, &context->lcpFsm,
598  &lcpCallbacks, terminateReqPacket);
599 
600  //Successful processing
601  return NO_ERROR;
602 }
603 
604 
605 /**
606  * @brief Process Terminate-Ack packet
607  * @param[in] context PPP context
608  * @param[in] terminateAckPacket Packet received from the peer
609  * @return Error code
610  **/
611 
613  const PppTerminatePacket *terminateAckPacket)
614 {
615  //Debug message
616  TRACE_INFO("\r\nLCP Receive-Terminate-Ack event\r\n");
617 
618  //The Terminate-Ack packet is usually a response to a Terminate-Request
619  //packet. This packet may also indicate that the peer is in Closed or
620  //Stopped states, and serves to re-synchronize the link configuration
621  pppRcvTerminateAckEvent(context, &context->lcpFsm, &lcpCallbacks);
622 
623  //Successful processing
624  return NO_ERROR;
625 }
626 
627 
628 /**
629  * @brief Process Code-Reject packet
630  * @param[in] context PPP context
631  * @param[in] codeRejPacket Packet received from the peer
632  * @return Error code
633  **/
634 
636  const PppCodeRejPacket *codeRejPacket)
637 {
638  size_t length;
639  PppPacket *packet;
640 
641  //Debug message
642  TRACE_INFO("\r\nLCP Receive-Code-Reject event\r\n");
643 
644  //Point to the rejected packet
645  packet = (PppPacket *) codeRejPacket->rejectedPacket;
646  //Retrieve the length of the rejected packet
647  length = ntohs(codeRejPacket->length) - sizeof(PppCodeRejPacket);
648 
649  //Make sure the length of the rejected packet is valid
650  if(length < sizeof(PppPacket))
651  return ERROR_INVALID_LENGTH;
652 
653  //Check whether the rejected value is acceptable or catastrophic
654  if(packet->code < PPP_CODE_CONFIGURE_REQ ||
655  packet->code > PPP_CODE_DISCARD_REQ)
656  {
657  //The RXJ+ event arises when the rejected value is acceptable, such
658  //as a Code-Reject of an extended code, or a Protocol-Reject of a
659  //NCP. These are within the scope of normal operation
660  pppRcvCodeRejEvent(context, &context->lcpFsm, &lcpCallbacks, TRUE);
661  }
662  else
663  {
664  //The RXJ- event arises when the rejected value is catastrophic, such
665  //as a Code-Reject of Configure-Request! This event communicates an
666  //unrecoverable error that terminates the connection
667  pppRcvCodeRejEvent(context, &context->lcpFsm, &lcpCallbacks, FALSE);
668  }
669 
670  //Successful processing
671  return NO_ERROR;
672 }
673 
674 
675 /**
676  * @brief Process Protocol-Reject packet
677  * @param[in] context PPP context
678  * @param[in] protocolRejPacket Packet received from the peer
679  * @return Error code
680  **/
681 
683  const PppProtocolRejPacket *protocolRejPacket)
684 {
685  size_t length;
686  uint16_t protocol;
687 
688  //Debug message
689  TRACE_INFO("\r\nLCP Receive-Protocol-Reject event\r\n");
690 
691  //Retrieve the length of the packet
692  length = ntohs(protocolRejPacket->length);
693 
694  //Make sure the length of the Protocol-Reject packet is valid
695  if(length < sizeof(PppProtocolRejPacket))
696  return ERROR_INVALID_LENGTH;
697 
698  //Convert the Rejected-Protocol field to host byte order
699  protocol = ntohs(protocolRejPacket->rejectedProtocol);
700 
701  //Check Rejected-Protocol field value
702  switch(protocol)
703  {
704  //LCP protocol?
705  case PPP_PROTOCOL_LCP:
706  //The rejected value is catastrophic. This event communicates
707  //an unrecoverable error that terminates the connection
708  pppRcvCodeRejEvent(context, &context->lcpFsm, &lcpCallbacks, FALSE);
709  break;
710 
711  //IPv4 or IPCP protocol?
712  case PPP_PROTOCOL_IP:
713  case PPP_PROTOCOL_IPCP:
714  //The implementation must stop sending the offending packet type
715  context->ipRejected = TRUE;
716  //This is within the scope of normal operation...
717  pppRcvCodeRejEvent(context, &context->lcpFsm, &lcpCallbacks, TRUE);
718  break;
719 
720  //IPv6 or IPV6CP protocol?
721  case PPP_PROTOCOL_IPV6:
722  case PPP_PROTOCOL_IPV6CP:
723  //The implementation must stop sending the offending packet type
724  context->ipv6Rejected = TRUE;
725  //This is within the scope of normal operation...
726  pppRcvCodeRejEvent(context, &context->lcpFsm, &lcpCallbacks, TRUE);
727  break;
728 
729  //Unknown protocol?
730  default:
731  //Just for sanity's sake...
732  break;
733  }
734 
735  //Successful processing
736  return NO_ERROR;
737 }
738 
739 
740 /**
741  * @brief Process Echo-Request packet
742  * @param[in] context PPP context
743  * @param[in] echoReqPacket Packet received from the peer
744  * @return Error code
745  **/
746 
748  const PppEchoPacket *echoReqPacket)
749 {
750  //Debug message
751  TRACE_INFO("\r\nLCP Receive-Echo-Request event\r\n");
752 
753  //An Echo-Reply packet is transmitted to acknowledge the
754  //reception of the Echo-Request packet
755  pppRcvEchoReqEvent(context, &context->lcpFsm,
756  &lcpCallbacks, echoReqPacket);
757 
758  //Successful processing
759  return NO_ERROR;
760 }
761 
762 
763 /**
764  * @brief Process Echo-Reply packet
765  * @param[in] context PPP context
766  * @param[in] echoRepPacket Packet received from the peer
767  * @return Error code
768  **/
769 
771  const PppEchoPacket *echoRepPacket)
772 {
773  //Debug message
774  TRACE_INFO("\r\nLCP Receive-Echo-Reply event\r\n");
775 
776  //Successful processing
777  return NO_ERROR;
778 }
779 
780 
781 /**
782  * @brief Process Discard-Request packet
783  * @param[in] context PPP context
784  * @param[in] discardReqPacket Packet received from the peer
785  * @return Error code
786  **/
787 
789  const PppDiscardReqPacket *discardReqPacket)
790 {
791  //Debug message
792  TRACE_INFO("\r\nLCP Receive-Discard-Request event\r\n");
793 
794  //The receiver must silently discard any Discard-Request that it receives
795  return NO_ERROR;
796 }
797 
798 
799 /**
800  * @brief Process packet with unknown code
801  * @param[in] context PPP context
802  * @param[in] packet Un-interpretable packet received from the peer
803  * @return Error code
804  **/
805 
807  const PppPacket *packet)
808 {
809  //Debug message
810  TRACE_INFO("\r\nLCP Receive-Unknown-Code event\r\n");
811 
812  //This event occurs when an un-interpretable packet is received from
813  //the peer. A Code-Reject packet is sent in response
814  pppRcvUnknownCodeEvent(context, &context->lcpFsm, &lcpCallbacks, packet);
815 
816  //Successful processing
817  return NO_ERROR;
818 }
819 
820 
821 /**
822  * @brief Process PPP frame with unknown protocol
823  * @param[in] context PPP context
824  * @param[in] protocol Rejected protocol
825  * @param[in] information Rejected information
826  * @param[in] length Length of the rejected information
827  * @return Error code
828  **/
829 
831  uint16_t protocol, const uint8_t *information, size_t length)
832 {
833  //Debug message
834  TRACE_INFO("\r\nLCP Receive-Unknown-Protocol event\r\n");
835 
836  //The peer is attempting to use a protocol which is unsupported
837  if(context->lcpFsm.state == PPP_STATE_9_OPENED)
838  {
839  //The Identifier field must be changed for each Protocol-Reject sent
840  context->lcpFsm.identifier++;
841 
842  //If the LCP automaton is in the Opened state, then this must be
843  //reported back to the peer by transmitting a Protocol-Reject
844  pppSendProtocolRej(context, context->lcpFsm.identifier,
845  protocol, information, length);
846  }
847 
848  //Successful processing
849  return NO_ERROR;
850 }
851 
852 
853 /**
854  * @brief This-Layer-Up callback function
855  * @param[in] context PPP context
856  **/
857 
859 {
860  //Debug message
861  TRACE_INFO("LCP This-Layer-Up callback\r\n");
862 
863  //Check whether the other end of the PPP link is being authenticated
864  if(context->localConfig.authProtocol != 0)
865  context->localAuthDone = FALSE;
866  else
867  context->localAuthDone = TRUE;
868 
869  //Check whether the other end of the PPP link is the authenticator
870  if(context->peerConfig.authProtocol != 0)
871  context->peerAuthDone = FALSE;
872  else
873  context->peerAuthDone = TRUE;
874 
875 #if (PAP_SUPPORT == ENABLED)
876  //PAP authentication required?
877  if(context->localConfig.authProtocol == PPP_PROTOCOL_PAP ||
878  context->peerConfig.authProtocol == PPP_PROTOCOL_PAP)
879  {
880  //Advance to the Authentication phase
881  context->pppPhase = PPP_PHASE_AUTHENTICATE;
882  //Start PAP authentication process
883  papStartAuth(context);
884  }
885 #endif
886 #if (CHAP_SUPPORT == ENABLED)
887  //CHAP authentication required?
888  if(context->localConfig.authProtocol == PPP_PROTOCOL_CHAP ||
889  context->peerConfig.authProtocol == PPP_PROTOCOL_CHAP)
890  {
891  //Advance to the Authentication phase
892  context->pppPhase = PPP_PHASE_AUTHENTICATE;
893  //Start CHAP authentication process
894  chapStartAuth(context);
895  }
896 #endif
897 
898  //Check whether PPP authentication is complete
899  if(context->localAuthDone && context->peerAuthDone)
900  {
901  //Advance to the Network phase
902  context->pppPhase = PPP_PHASE_NETWORK;
903 
904 #if (IPV4_SUPPORT == ENABLED)
905  //IPCP Open event
906  ipcpOpen(context);
907 #endif
908 #if (IPV6_SUPPORT == ENABLED)
909  //IPV6CP Open event
910  ipv6cpOpen(context);
911 #endif
912  }
913 }
914 
915 
916 /**
917  * @brief This-Layer-Down callback function
918  * @param[in] context PPP context
919  **/
920 
922 {
923  //Debug message
924  TRACE_INFO("LCP This-Layer-Down callback\r\n");
925 
926  //Advance to the Terminate phase
927  context->pppPhase = PPP_PHASE_TERMINATE;
928 
929 #if (IPV4_SUPPORT == ENABLED)
930  //IPCP Close event
931  ipcpClose(context);
932 #endif
933 #if (IPV6_SUPPORT == ENABLED)
934  //IPV6CP Close event
935  ipv6cpClose(context);
936 #endif
937 
938 #if (PAP_SUPPORT == ENABLED)
939  //Abort PAP authentication process
940  papAbortAuth(context);
941 #endif
942 
943 #if (CHAP_SUPPORT == ENABLED)
944  //Abort CHAP authentication process
945  chapAbortAuth(context);
946 #endif
947 }
948 
949 
950 /**
951  * @brief This-Layer-Started callback function
952  * @param[in] context PPP context
953  **/
954 
956 {
957  //Debug message
958  TRACE_INFO("LCP This-Layer-Started callback\r\n");
959 }
960 
961 
962 /**
963  * @brief This-Layer-Finished callback function
964  * @param[in] context PPP context
965  **/
966 
968 {
969  //Debug message
970  TRACE_INFO("LCP This-Layer-Finished callback\r\n");
971 
972  //The link is no longer available for traffic
973  pppCloseEvent(context, &context->lcpFsm, &lcpCallbacks);
974  //The lower layer is no longer ready to carry packets
975  pppDownEvent(context, &context->lcpFsm, &lcpCallbacks);
976 
977  //Advance to the Link Dead phase
978  context->pppPhase = PPP_PHASE_DEAD;
979 }
980 
981 
982 /**
983  * @brief Initialize-Restart-Count callback function
984  * @param[in] context PPP context
985  * @param[in] value Restart counter value
986  **/
987 
989 {
990  //Debug message
991  TRACE_INFO("LCP Initialize-Restart-Count callback\r\n");
992 
993  //Initialize restart counter
994  context->lcpFsm.restartCounter = value;
995 }
996 
997 
998 /**
999  * @brief Zero-Restart-Count callback function
1000  * @param[in] context PPP context
1001  **/
1002 
1004 {
1005  //Debug message
1006  TRACE_INFO("LCP Zero-Restart-Count callback\r\n");
1007 
1008  //Zero restart counter
1009  context->lcpFsm.restartCounter = 0;
1010 
1011  //The receiver of a Terminate-Request should wait for the peer to
1012  //disconnect, and must not disconnect until at least one Restart
1013  //time has passed after sending a Terminate-Ack
1014  context->lcpFsm.timestamp = osGetSystemTime();
1015 }
1016 
1017 
1018 /**
1019  * @brief Send-Configure-Request callback function
1020  * @param[in] context PPP context
1021  * @return Error code
1022  **/
1023 
1025 {
1026  error_t error;
1027  size_t length;
1028  size_t offset;
1029  NetBuffer *buffer;
1030  PppConfigurePacket *configureReqPacket;
1031 
1032  //Debug message
1033  TRACE_INFO("LCP Send-Configure-Request callback\r\n");
1034 
1035  //Allocate a buffer memory to hold the Configure-Request packet
1036  buffer = pppAllocBuffer(PPP_MAX_CONF_REQ_SIZE, &offset);
1037  //Failed to allocate memory?
1038  if(buffer == NULL)
1039  return ERROR_OUT_OF_MEMORY;
1040 
1041  //Point to the Configure-Request packet
1042  configureReqPacket = netBufferAt(buffer, offset);
1043 
1044  //Format packet header
1045  configureReqPacket->code = PPP_CODE_CONFIGURE_REQ;
1046  configureReqPacket->identifier = ++context->lcpFsm.identifier;
1047  configureReqPacket->length = sizeof(PppConfigurePacket);
1048 
1049  //Make sure the Maximum-Receive-Unit option has not been
1050  //previously rejected
1051  if(!context->localConfig.mruRejected)
1052  {
1053  //Convert MRU to network byte order
1054  uint16_t value = htons(context->localConfig.mru);
1055  //Add option
1056  pppAddOption(configureReqPacket, LCP_OPTION_MRU, &value, sizeof(uint16_t));
1057  }
1058 
1059  //Make sure the Async-Control-Character-Map option has not been
1060  //previously rejected
1061  if(!context->localConfig.accmRejected)
1062  {
1063  //Convert ACCM to network byte order
1064  uint32_t value = htonl(context->localConfig.accm);
1065  //Add option
1066  pppAddOption(configureReqPacket, LCP_OPTION_ACCM, &value, sizeof(uint32_t));
1067  }
1068 
1069  //Make sure the Authentication-Protocol option has not been
1070  //previously rejected
1071  if(!context->localConfig.authProtocolRejected)
1072  {
1073  uint8_t value[3];
1074 
1075  //PAP authentication protocol?
1076  if(context->localConfig.authProtocol == PPP_PROTOCOL_PAP)
1077  {
1078  //Format Authentication-Protocol option
1079  value[0] = MSB(PPP_PROTOCOL_PAP);
1080  value[1] = LSB(PPP_PROTOCOL_PAP);
1081 
1082  //Add option
1083  pppAddOption(configureReqPacket, LCP_OPTION_AUTH_PROTOCOL, &value, 2);
1084  }
1085  //CHAP authentication protocol?
1086  else if(context->localConfig.authProtocol == PPP_PROTOCOL_CHAP)
1087  {
1088  //Format Authentication-Protocol option
1089  value[0] = MSB(PPP_PROTOCOL_CHAP);
1090  value[1] = LSB(PPP_PROTOCOL_CHAP);
1091  value[2] = context->localConfig.authAlgo;
1092 
1093  //Add option
1094  pppAddOption(configureReqPacket, LCP_OPTION_AUTH_PROTOCOL, &value, 3);
1095  }
1096  }
1097 
1098  //Make sure the Protocol-Field-Compression option has not been
1099  //previously rejected
1100  if(!context->localConfig.pfcRejected)
1101  {
1102  //Check whether compression of the Protocol field is supported
1103  if(context->localConfig.pfc)
1104  {
1105  //Add option
1106  pppAddOption(configureReqPacket, LCP_OPTION_PFC, NULL, 0);
1107  }
1108  }
1109 
1110  //Make sure the Address-and-Control-Field-Compression option has not been
1111  //previously rejected
1112  if(!context->localConfig.acfcRejected)
1113  {
1114  //Check whether compression of the Address and Control fields is supported
1115  if(context->localConfig.acfc)
1116  {
1117  //Add option
1118  pppAddOption(configureReqPacket, LCP_OPTION_ACFC, NULL, 0);
1119  }
1120  }
1121 
1122  //Save packet length
1123  length = configureReqPacket->length;
1124  //Convert length field to network byte order
1125  configureReqPacket->length = htons(length);
1126 
1127  //Adjust the length of the multi-part buffer
1128  netBufferSetLength(buffer, offset + length);
1129 
1130  //Debug message
1131  TRACE_INFO("Sending Configure-Request packet (%" PRIuSIZE " bytes)...\r\n", length);
1132  //Dump packet contents for debugging purpose
1133  pppDumpPacket((PppPacket *) configureReqPacket, length, PPP_PROTOCOL_LCP);
1134 
1135  //Send PPP frame
1136  error = pppSendFrame(context->interface, buffer, offset, PPP_PROTOCOL_LCP);
1137 
1138  //The restart counter is decremented each time a Configure-Request is sent
1139  if(context->lcpFsm.restartCounter > 0)
1140  context->lcpFsm.restartCounter--;
1141 
1142  //Save the time at which the packet was sent
1143  context->lcpFsm.timestamp = osGetSystemTime();
1144 
1145  //Free previously allocated memory block
1146  netBufferFree(buffer);
1147  //Return status code
1148  return error;
1149 }
1150 
1151 
1152 /**
1153  * @brief Send-Configure-Ack callback function
1154  * @param[in] context PPP context
1155  * @param[in] configureReqPacket Configure-Request packet received from the peer
1156  * @return Error code
1157  **/
1158 
1160  const PppConfigurePacket *configureReqPacket)
1161 {
1162  //Debug message
1163  TRACE_INFO("LCP Send-Configure-Ack callback\r\n");
1164 
1165  //Send Configure-Ack packet
1166  return pppSendConfigureAckNak(context, configureReqPacket,
1168 }
1169 
1170 
1171 /**
1172  * @brief Send-Configure-Nak callback function
1173  * @param[in] context PPP context
1174  * @param[in] configureReqPacket Configure-Request packet received from the peer
1175  * @return Error code
1176  **/
1177 
1179  const PppConfigurePacket *configureReqPacket)
1180 {
1181  //Debug message
1182  TRACE_INFO("LCP Send-Configure-Nak callback\r\n");
1183 
1184  //Send Configure-Nak packet
1185  return pppSendConfigureAckNak(context, configureReqPacket,
1187 }
1188 
1189 
1190 /**
1191  * @brief Send-Configure-Reject callback function
1192  * @param[in] context PPP context
1193  * @param[in] configureReqPacket Configure-Request packet received from the peer
1194  * @return Error code
1195  **/
1196 
1198  const PppConfigurePacket *configureReqPacket)
1199 {
1200  //Debug message
1201  TRACE_INFO("LCP Send-Configure-Reject callback\r\n");
1202 
1203  //Send Configure-Reject packet
1204  return pppSendConfigureAckNak(context, configureReqPacket,
1206 }
1207 
1208 
1209 /**
1210  * @brief Send-Terminate-Request callback function
1211  * @param[in] context PPP context
1212  * @return Error code
1213  **/
1214 
1216 {
1217  error_t error;
1218 
1219  //Debug message
1220  TRACE_INFO("LCP Send-Terminate-Request callback\r\n");
1221 
1222  //On transmission, the Identifier field must be changed
1223  context->lcpFsm.identifier++;
1224 
1225  //Send Terminate-Request packet
1226  error = pppSendTerminateReq(context, context->lcpFsm.identifier, PPP_PROTOCOL_LCP);
1227 
1228  //The restart counter is decremented each time a Terminate-Request is sent
1229  if(context->lcpFsm.restartCounter > 0)
1230  context->lcpFsm.restartCounter--;
1231 
1232  //Save the time at which the packet was sent
1233  context->lcpFsm.timestamp = osGetSystemTime();
1234 
1235  //Return status code
1236  return error;
1237 }
1238 
1239 
1240 /**
1241  * @brief Send-Terminate-Ack callback function
1242  * @param[in] context PPP context
1243  * @param[in] terminateReqPacket Terminate-Request packet received from the peer
1244  * @return Error code
1245  **/
1246 
1248  const PppTerminatePacket *terminateReqPacket)
1249 {
1250  uint8_t identifier;
1251 
1252  //Debug message
1253  TRACE_INFO("LCP Send-Terminate-Ack callback\r\n");
1254 
1255  //Check whether this Terminate-Ack acknowledges the reception of a
1256  //Terminate-Request packet
1257  if(terminateReqPacket != NULL)
1258  {
1259  //The Identifier field of the Terminate-Request is copied into the
1260  //Identifier field of the Terminate-Ack packet
1261  identifier = terminateReqPacket->identifier;
1262  }
1263  else
1264  {
1265  //This Terminate-Ack packet serves to synchronize the automatons
1266  identifier = ++context->lcpFsm.identifier;
1267  }
1268 
1269  //Send Terminate-Ack packet
1271 }
1272 
1273 
1274 /**
1275  * @brief Send-Code-Reject callback function
1276  * @param[in] context PPP context
1277  * @param[in] packet Un-interpretable packet received from the peer
1278  * @return Error code
1279  **/
1280 
1281 error_t lcpSendCodeRej(PppContext *context, const PppPacket *packet)
1282 {
1283  //Debug message
1284  TRACE_INFO("LCP Send-Code-Reject callback\r\n");
1285 
1286  //The Identifier field must be changed for each Code-Reject sent
1287  context->lcpFsm.identifier++;
1288 
1289  //Send Code-Reject packet
1290  return pppSendCodeRej(context, packet, context->lcpFsm.identifier, PPP_PROTOCOL_LCP);
1291 }
1292 
1293 
1294 /**
1295  * @brief Send-Echo-Reply callback function
1296  * @param[in] context PPP context
1297  * @param[in] echoReqPacket Echo-Request packet received from the peer
1298  * @return Error code
1299  **/
1300 
1301 error_t lcpSendEchoRep(PppContext *context, const PppEchoPacket *echoReqPacket)
1302 {
1303  //Debug message
1304  TRACE_INFO("LCP Send-Echo-Reply callback\r\n");
1305 
1306  //Send Echo-Reply packet
1307  return pppSendEchoRep(context, echoReqPacket, PPP_PROTOCOL_LCP);
1308 }
1309 
1310 
1311 /**
1312  * @brief Parse LCP configuration option
1313  * @param[in] context PPP context
1314  * @param[in] option Option to be checked
1315  * @param[in] inPacketLen Remaining bytes to process in the incoming packet
1316  * @param[out] outPacket Pointer to the Configure-Ack, Nak or Reject packet
1317  * @return Error code
1318  **/
1319 
1321  size_t inPacketLen, PppConfigurePacket *outPacket)
1322 {
1323  error_t error;
1324 
1325  //Malformed LCP packet?
1326  if(inPacketLen < sizeof(PppOption))
1327  return ERROR_INVALID_LENGTH;
1328 
1329  //Check option length
1330  if(option->length < sizeof(PppOption))
1331  return ERROR_INVALID_LENGTH;
1332  if(option->length > inPacketLen)
1333  return ERROR_INVALID_LENGTH;
1334 
1335  //Check option type
1336  switch(option->type)
1337  {
1338  case LCP_OPTION_MRU:
1339  //Check Maximum-Receive-Unit option
1340  error = lcpParseMruOption(context, (LcpMruOption *) option, outPacket);
1341  break;
1342  case LCP_OPTION_ACCM:
1343  //Check Async-Control-Character-Map option
1344  error = lcpParseAccmOption(context, (LcpAccmOption *) option, outPacket);
1345  break;
1347  //Check Authentication-Protocol option
1348  error = lcpParseAuthProtocolOption(context, (LcpAuthProtocolOption *) option, outPacket);
1349  break;
1351  //Check Magic-Number option
1352  error = lcpParseMagicNumberOption(context, (LcpMagicNumberOption *) option, outPacket);
1353  break;
1354  case LCP_OPTION_PFC:
1355  //Check Protocol-Field-Compression option
1356  error = lcpParsePfcOption(context, (LcpPfcOption *) option, outPacket);
1357  break;
1358  case LCP_OPTION_ACFC:
1359  //Check Address-and-Control-Field-Compression option
1360  error = lcpParseAcfcOption(context, (LcpAcfcOption *) option, outPacket);
1361  break;
1362  default:
1363  //If some configuration options received in the Configure-Request are not
1364  //recognizable or not acceptable for negotiation, then the implementation
1365  //must transmit a Configure-Reject
1366  if(outPacket != NULL && outPacket->code == PPP_CODE_CONFIGURE_REJ)
1367  {
1368  //The options field of the Configure-Reject packet is filled
1369  //with the unrecognized options from the Configure-Request
1370  pppAddOption(outPacket, option->type, option->data,
1371  option->length - sizeof(PppOption));
1372  }
1373 
1374  //The option is not acceptable for negotiation
1375  error = ERROR_INVALID_TYPE;
1376  break;
1377  }
1378 
1379  //Return status code
1380  return error;
1381 }
1382 
1383 
1384 /**
1385  * @brief Parse Maximum-Receive-Unit option
1386  * @param[in] context PPP context
1387  * @param[in] option Option to be checked
1388  * @param[out] outPacket Pointer to the Configure-Nak or Configure-Reject packet
1389  * @return Error code
1390  **/
1391 
1393  LcpMruOption *option, PppConfigurePacket *outPacket)
1394 {
1395  error_t error;
1396  uint16_t value;
1397 
1398  //Check length field
1399  if(option->length == sizeof(LcpMruOption))
1400  {
1401  //Check whether the option value is acceptable
1402  if(ntohs(option->mru) >= PPP_MIN_MRU)
1403  {
1404  //If every configuration option received in the Configure-Request is
1405  //recognizable and all values are acceptable, then the implementation
1406  //must transmit a Configure-Ack
1407  if(outPacket != NULL && outPacket->code == PPP_CODE_CONFIGURE_ACK)
1408  {
1409  //Save Maximum-Receive-Unit option
1410  context->peerConfig.mru = ntohl(option->mru);
1411 
1412  //The options field of the Configure-Ack packet contains the
1413  //configuration options that the sender is acknowledging
1414  pppAddOption(outPacket, LCP_OPTION_MRU, (void *) &option->mru,
1415  option->length - sizeof(PppOption));
1416  }
1417 
1418  //The value is acceptable
1419  error = NO_ERROR;
1420  }
1421  else
1422  {
1423  //If all configuration options are recognizable, but some values are not
1424  //acceptable, then the implementation must transmit a Configure-Nak
1425  if(outPacket != NULL && outPacket->code == PPP_CODE_CONFIGURE_NAK)
1426  {
1427  //Use default value
1429 
1430  //The option must be modified to a value acceptable to the
1431  //Configure-Nak sender
1432  pppAddOption(outPacket, LCP_OPTION_MRU, &value, sizeof(uint16_t));
1433  }
1434 
1435  //The value is not acceptable
1436  error = ERROR_INVALID_VALUE;
1437  }
1438  }
1439  else
1440  {
1441  //Invalid length field
1442  error = ERROR_INVALID_LENGTH;
1443  }
1444 
1445  //Return status code
1446  return error;
1447 }
1448 
1449 
1450 /**
1451  * @brief Parse Async-Control-Character-Map option
1452  * @param[in] context PPP context
1453  * @param[in] option Option to be checked
1454  * @param[out] outPacket Pointer to the Configure-Nak or Configure-Reject packet
1455  * @return Error code
1456  **/
1457 
1459  LcpAccmOption *option, PppConfigurePacket *outPacket)
1460 {
1461  error_t error;
1462 
1463  //Check length field
1464  if(option->length == sizeof(LcpAccmOption))
1465  {
1466  //If every configuration option received in the Configure-Request is
1467  //recognizable and all values are acceptable, then the implementation
1468  //must transmit a Configure-Ack
1469  if(outPacket != NULL && outPacket->code == PPP_CODE_CONFIGURE_ACK)
1470  {
1471  //Save Async-Control-Character-Map option
1472  context->peerConfig.accm = ntohl(option->accm);
1473 
1474  //The options field of the Configure-Ack packet contains the
1475  //configuration options that the sender is acknowledging
1476  pppAddOption(outPacket, LCP_OPTION_ACCM, (void *) &option->accm,
1477  option->length - sizeof(PppOption));
1478  }
1479 
1480  //The value is acceptable
1481  error = NO_ERROR;
1482  }
1483  else
1484  {
1485  //Invalid length field
1486  error = ERROR_INVALID_LENGTH;
1487  }
1488 
1489  //Return status code
1490  return error;
1491 }
1492 
1493 
1494 /**
1495  * @brief Parse Authentication-Protocol option
1496  * @param[in] context PPP context
1497  * @param[in] option Option to be checked
1498  * @param[out] outPacket Pointer to the Configure-Nak or Configure-Reject packet
1499  * @return Error code
1500  **/
1501 
1503  LcpAuthProtocolOption *option, PppConfigurePacket *outPacket)
1504 {
1505  error_t error;
1506  uint8_t value[3];
1507 
1508  //Assume an error condition...
1509  error = ERROR_INVALID_LENGTH;
1510 
1511  //Check the length of the option
1512  if(option->length >= sizeof(LcpAuthProtocolOption))
1513  {
1514  //The Authentication-Protocol option for PAP must be exactly 4 bytes
1515  if(ntohs(option->protocol) == PPP_PROTOCOL_PAP)
1516  {
1517  if(option->length == 4)
1518  error = NO_ERROR;
1519  }
1520  //The Authentication-Protocol option for CHAP must be exactly 5 bytes
1521  else if(ntohs(option->protocol) == PPP_PROTOCOL_CHAP)
1522  {
1523  if(option->length == 5)
1524  error = NO_ERROR;
1525  }
1526  }
1527 
1528  //Make sure the length field is valid
1529  if(!error)
1530  {
1531  //PAP authentication protocol?
1532  if(context->settings.authProtocol & PPP_AUTH_PROTOCOL_PAP &&
1533  ntohs(option->protocol) == PPP_PROTOCOL_PAP)
1534  {
1535  //If every configuration option received in the Configure-Request is
1536  //recognizable and all values are acceptable, then the implementation
1537  //must transmit a Configure-Ack
1538  if(outPacket != NULL && outPacket->code == PPP_CODE_CONFIGURE_ACK)
1539  {
1540  //Save the authentication protocol to be used
1541  context->peerConfig.authProtocol = PPP_PROTOCOL_PAP;
1542 
1543  //The options field of the Configure-Ack packet contains the
1544  //configuration options that the sender is acknowledging
1545  pppAddOption(outPacket, option->type, (void *) &option->protocol,
1546  option->length - sizeof(PppOption));
1547  }
1548 
1549  //The value is acceptable
1550  error = NO_ERROR;
1551  }
1552  //CHAP with MD5 authentication protocol?
1553  else if(context->settings.authProtocol & PPP_AUTH_PROTOCOL_CHAP_MD5 &&
1554  ntohs(option->protocol) == PPP_PROTOCOL_CHAP &&
1555  option->data[0] == CHAP_ALGO_ID_CHAP_MD5)
1556  {
1557  //If every configuration option received in the Configure-Request is
1558  //recognizable and all values are acceptable, then the implementation
1559  //must transmit a Configure-Ack
1560  if(outPacket != NULL && outPacket->code == PPP_CODE_CONFIGURE_ACK)
1561  {
1562  //Save the authentication protocol to be used
1563  context->peerConfig.authProtocol = PPP_PROTOCOL_CHAP;
1564  context->peerConfig.authAlgo = CHAP_ALGO_ID_CHAP_MD5;
1565 
1566  //The options field of the Configure-Ack packet contains the
1567  //configuration options that the sender is acknowledging
1568  pppAddOption(outPacket, option->type, (void *) &option->protocol,
1569  option->length - sizeof(PppOption));
1570  }
1571 
1572  //The value is acceptable
1573  error = NO_ERROR;
1574  }
1575  else
1576  {
1577  //PAP authentication protocol allowed?
1578  if(context->settings.authProtocol & PPP_AUTH_PROTOCOL_PAP)
1579  {
1580  //If all configuration options are recognizable, but some values are not
1581  //acceptable, then the implementation must transmit a Configure-Nak
1582  if(outPacket != NULL && outPacket->code == PPP_CODE_CONFIGURE_NAK)
1583  {
1584  //Format Authentication-Protocol option
1585  value[0] = MSB(PPP_PROTOCOL_PAP);
1586  value[1] = LSB(PPP_PROTOCOL_PAP);
1587 
1588  //The option must be modified to a value acceptable to the
1589  //Configure-Nak sender
1591  }
1592 
1593  //The value is not acceptable
1594  error = ERROR_INVALID_VALUE;
1595  }
1596  //CHAP with MD5 authentication protocol allowed?
1597  else if(context->settings.authProtocol & PPP_AUTH_PROTOCOL_CHAP_MD5)
1598  {
1599  //If all configuration options are recognizable, but some values are not
1600  //acceptable, then the implementation must transmit a Configure-Nak
1601  if(outPacket != NULL && outPacket->code == PPP_CODE_CONFIGURE_NAK)
1602  {
1603  //Format Authentication-Protocol option
1604  value[0] = MSB(PPP_PROTOCOL_CHAP);
1605  value[1] = LSB(PPP_PROTOCOL_CHAP);
1607 
1608  //The option must be modified to a value acceptable to the
1609  //Configure-Nak sender
1611  }
1612 
1613  //The value is not acceptable
1614  error = ERROR_INVALID_VALUE;
1615  }
1616  else
1617  {
1618  //If some configuration options received in the Configure-Request are not
1619  //recognizable or not acceptable for negotiation, then the implementation
1620  //must transmit a Configure-Reject
1621  if(outPacket != NULL && outPacket->code == PPP_CODE_CONFIGURE_REJ)
1622  {
1623  //The options field of the Configure-Reject packet is filled
1624  //with the unrecognized options from the Configure-Request
1625  pppAddOption(outPacket, option->type, (void *) &option->protocol,
1626  option->length - sizeof(PppOption));
1627  }
1628 
1629  //The option is not acceptable for negotiation
1630  error = ERROR_INVALID_TYPE;
1631  }
1632  }
1633  }
1634 
1635  //Return status code
1636  return error;
1637 }
1638 
1639 
1640 /**
1641  * @brief Parse Magic-Number option
1642  * @param[in] context PPP context
1643  * @param[in] option Option to be checked
1644  * @param[out] outPacket Pointer to the Configure-Nak or Configure-Reject packet
1645  * @return Error code
1646  **/
1647 
1649  LcpMagicNumberOption *option, PppConfigurePacket *outPacket)
1650 {
1651  error_t error;
1652 
1653  //Check length field
1654  if(option->length == sizeof(LcpMagicNumberOption))
1655  {
1656  //If every configuration option received in the Configure-Request is
1657  //recognizable and all values are acceptable, then the implementation
1658  //must transmit a Configure-Ack
1659  if(outPacket != NULL && outPacket->code == PPP_CODE_CONFIGURE_ACK)
1660  {
1661  //Save Magic-Number option
1662  context->peerConfig.magicNumber = ntohl(option->magicNumber);
1663 
1664  //The options field of the Configure-Ack packet contains the
1665  //configuration options that the sender is acknowledging
1666  pppAddOption(outPacket, LCP_OPTION_MAGIC_NUMBER, (void *) &option->magicNumber,
1667  option->length - sizeof(PppOption));
1668  }
1669 
1670  //The value is acceptable
1671  error = NO_ERROR;
1672  }
1673  else
1674  {
1675  //Invalid length field
1676  error = ERROR_INVALID_LENGTH;
1677  }
1678 
1679  //Return status code
1680  return error;
1681 }
1682 
1683 
1684 /**
1685  * @brief Parse Protocol-Field-Compression option
1686  * @param[in] context PPP context
1687  * @param[in] option Option to be checked
1688  * @param[out] outPacket Pointer to the Configure-Nak or Configure-Reject packet
1689  * @return Error code
1690  **/
1691 
1693  LcpPfcOption *option, PppConfigurePacket *outPacket)
1694 {
1695  error_t error;
1696 
1697  //Check length field
1698  if(option->length == sizeof(LcpPfcOption))
1699  {
1700  //If every configuration option received in the Configure-Request is
1701  //recognizable and all values are acceptable, then the implementation
1702  //must transmit a Configure-Ack
1703  if(outPacket != NULL && outPacket->code == PPP_CODE_CONFIGURE_ACK)
1704  {
1705  //Save Protocol-Field-Compression option
1706  context->peerConfig.pfc = TRUE;
1707 
1708  //The options field of the Configure-Ack packet contains the
1709  //configuration options that the sender is acknowledging
1710  pppAddOption(outPacket, LCP_OPTION_PFC, NULL, 0);
1711  }
1712 
1713  //The value is acceptable
1714  error = NO_ERROR;
1715  }
1716  else
1717  {
1718  //Invalid length field
1719  error = ERROR_INVALID_LENGTH;
1720  }
1721 
1722  //Return status code
1723  return error;
1724 }
1725 
1726 
1727 /**
1728  * @brief Parse Address-and-Control-Field-Compression option
1729  * @param[in] context PPP context
1730  * @param[in] option Option to be checked
1731  * @param[out] outPacket Pointer to the Configure-Nak or Configure-Reject packet
1732  * @return Error code
1733  **/
1734 
1736  LcpAcfcOption *option, PppConfigurePacket *outPacket)
1737 {
1738  error_t error;
1739 
1740  //Check length field
1741  if(option->length == sizeof(LcpAcfcOption))
1742  {
1743  //If every configuration option received in the Configure-Request is
1744  //recognizable and all values are acceptable, then the implementation
1745  //must transmit a Configure-Ack
1746  if(outPacket != NULL && outPacket->code == PPP_CODE_CONFIGURE_ACK)
1747  {
1748  //Save Address-and-Control-Field-Compression option
1749  context->peerConfig.acfc = TRUE;
1750 
1751  //The options field of the Configure-Ack packet contains the
1752  //configuration options that the sender is acknowledging
1753  pppAddOption(outPacket, LCP_OPTION_ACFC, NULL, 0);
1754  }
1755 
1756  //The value is acceptable
1757  error = NO_ERROR;
1758  }
1759  else
1760  {
1761  //Invalid length field
1762  error = ERROR_INVALID_LENGTH;
1763  }
1764 
1765  //Return status code
1766  return error;
1767 }
1768 
1769 #endif
error_t lcpProcessCodeRej(PppContext *context, const PppCodeRejPacket *codeRejPacket)
Process Code-Reject packet.
Definition: lcp.c:635
uint8_t length
Definition: coap_common.h:193
#define htons(value)
Definition: cpu_endian.h:413
Data logging functions for debugging purpose (PPP)
__start_packed struct @4 LcpMagicNumberOption
Magic-Number option.
@ PPP_CODE_CONFIGURE_REJ
Configure-Reject.
Definition: ppp.h:219
@ CHAP_ALGO_ID_CHAP_MD5
Definition: chap.h:103
error_t lcpParsePfcOption(PppContext *context, LcpPfcOption *option, PppConfigurePacket *outPacket)
Parse Protocol-Field-Compression option.
Definition: lcp.c:1692
int bool_t
Definition: compiler_port.h:53
#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
error_t lcpProcessProtocolRej(PppContext *context, const PppProtocolRejPacket *protocolRejPacket)
Process Protocol-Reject packet.
Definition: lcp.c:682
@ LCP_OPTION_ACCM
Async-Control-Character-Map.
Definition: lcp.h:51
__start_packed struct @2 PppCodeRejPacket
Code-Reject packet.
void pppRcvUnknownCodeEvent(PppContext *context, PppFsm *fsm, const PppCallbacks *callbacks, const PppPacket *packet)
Process Receive-Unknown-Code event.
Definition: ppp_fsm.c:757
void lcpProcessPacket(PppContext *context, const PppPacket *packet, size_t length)
Process an incoming LCP packet.
Definition: lcp.c:155
void lcpTick(PppContext *context)
LCP timer handler.
Definition: lcp.c:125
@ PPP_CODE_PROTOCOL_REJ
Protocol-Reject.
Definition: ppp.h:223
CHAP (Challenge Handshake Authentication Protocol)
void pppUpEvent(PppContext *context, PppFsm *fsm, const PppCallbacks *callbacks)
Process Up event.
Definition: ppp_fsm.c:50
@ PPP_PROTOCOL_CHAP
Challenge Handshake Authentication Protocol.
Definition: ppp.h:206
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
Structure describing a buffer that spans multiple chunks.
Definition: net_mem.h:89
PPP finite state machine.
#define TRUE
Definition: os_port.h:52
__start_packed struct @6 PppOption
LCP/NCP option.
error_t ipv6cpClose(PppContext *context)
IPV6CP Close event.
Definition: ipv6cp.c:98
error_t lcpSendTerminateReq(PppContext *context)
Send-Terminate-Request callback function.
Definition: lcp.c:1215
IPV6CP (PPP IPv6 Control Protocol)
error_t pppSendProtocolRej(PppContext *context, uint8_t identifier, uint16_t protocol, const uint8_t *information, size_t length)
Send Protocol-Reject packet.
Definition: ppp_misc.c:325
error_t lcpSendConfigureRej(PppContext *context, const PppConfigurePacket *configureReqPacket)
Send-Configure-Reject callback function.
Definition: lcp.c:1197
error_t lcpProcessTerminateReq(PppContext *context, const PppTerminatePacket *terminateReqPacket)
Process Terminate-Request packet.
Definition: lcp.c:590
error_t lcpOpen(PppContext *context)
LCP Open event.
Definition: lcp.c:79
@ ERROR_OUT_OF_MEMORY
Definition: error.h:63
error_t lcpSendCodeRej(PppContext *context, const PppPacket *packet)
Send-Code-Reject callback function.
Definition: lcp.c:1281
__start_packed struct @5 LcpPfcOption
Protocol-Field-Compression option.
@ PPP_PHASE_NETWORK
Network-layer protocol phase.
Definition: ppp.h:169
__start_packed struct @5 PppDiscardReqPacket
PPP Discard-Request packet.
NetBuffer * pppAllocBuffer(size_t length, size_t *offset)
Allocate a buffer to hold a PPP frame.
Definition: ppp.c:1292
error_t lcpProcessConfigureReq(PppContext *context, const PppConfigurePacket *configureReqPacket)
Process Configure-Request packet.
Definition: lcp.c:249
error_t lcpSendEchoRep(PppContext *context, const PppEchoPacket *echoReqPacket)
Send-Echo-Reply callback function.
Definition: lcp.c:1301
void pppCloseEvent(PppContext *context, PppFsm *fsm, const PppCallbacks *callbacks)
Process Close event.
Definition: ppp_fsm.c:189
#define PppContext
Definition: ppp.h:38
void pppOpenEvent(PppContext *context, PppFsm *fsm, const PppCallbacks *callbacks)
Process Open event.
Definition: ppp_fsm.c:135
error_t pppSendCodeRej(PppContext *context, const PppPacket *packet, uint8_t identifier, PppProtocol protocol)
Send Code-Reject packet.
Definition: ppp_misc.c:265
PPP FSM actions.
Definition: ppp_fsm.h:153
error_t lcpParseMagicNumberOption(PppContext *context, LcpMagicNumberOption *option, PppConfigurePacket *outPacket)
Parse Magic-Number option.
Definition: lcp.c:1648
IPCP (PPP Internet Protocol Control Protocol)
void pppRcvEchoReqEvent(PppContext *context, PppFsm *fsm, const PppCallbacks *callbacks, const PppEchoPacket *echoReqPacket)
Process Receive-Echo-Request event.
Definition: ppp_fsm.c:889
@ PPP_CODE_CODE_REJ
Code-Reject.
Definition: ppp.h:222
LCP (PPP Link Control Protocol)
error_t pppAddOption(PppConfigurePacket *packet, uint8_t optionType, const void *optionValue, uint8_t optionLen)
Add an option to a Configure packet.
Definition: ppp_misc.c:448
@ PPP_CODE_CONFIGURE_REQ
Configure-Request.
Definition: ppp.h:216
error_t lcpProcessUnknownProtocol(PppContext *context, uint16_t protocol, const uint8_t *information, size_t length)
Process PPP frame with unknown protocol.
Definition: lcp.c:830
error_t lcpParseOption(PppContext *context, PppOption *option, size_t inPacketLen, PppConfigurePacket *outPacket)
Parse LCP configuration option.
Definition: lcp.c:1320
error_t papAbortAuth(PppContext *context)
Abort PAP authentication.
Definition: pap.c:87
const PppCallbacks lcpCallbacks
LCP FSM callbacks.
Definition: lcp.c:54
#define FALSE
Definition: os_port.h:48
#define htonl(value)
Definition: cpu_endian.h:414
error_t lcpParseAcfcOption(PppContext *context, LcpAcfcOption *option, PppConfigurePacket *outPacket)
Parse Address-and-Control-Field-Compression option.
Definition: lcp.c:1735
error_t lcpSendTerminateAck(PppContext *context, const PppTerminatePacket *terminateReqPacket)
Send-Terminate-Ack callback function.
Definition: lcp.c:1247
@ PPP_STATE_9_OPENED
Definition: ppp.h:189
@ PPP_CODE_ECHO_REP
Echo-Reply.
Definition: ppp.h:225
error_t
Error codes.
Definition: error.h:43
@ PPP_AUTH_PROTOCOL_PAP
Definition: ppp.h:236
error_t lcpProcessConfigureNak(PppContext *context, const PppConfigurePacket *configureNakPacket)
Process Configure-Nak packet.
Definition: lcp.c:371
error_t lcpParseAccmOption(PppContext *context, LcpAccmOption *option, PppConfigurePacket *outPacket)
Parse Async-Control-Character-Map option.
Definition: lcp.c:1458
uint8_t protocol
error_t lcpParseAuthProtocolOption(PppContext *context, LcpAuthProtocolOption *option, PppConfigurePacket *outPacket)
Parse Authentication-Protocol option.
Definition: lcp.c:1502
void lcpThisLayerUp(PppContext *context)
This-Layer-Up callback function.
Definition: lcp.c:858
#define PPP_DEFAULT_ACCM
Definition: ppp.h:130
void * netBufferAt(const NetBuffer *buffer, size_t offset)
Returns a pointer to the data at the specified position.
Definition: net_mem.c:413
@ LCP_OPTION_ACFC
Address-and-Control-Field-Compression.
Definition: lcp.h:56
error_t chapAbortAuth(PppContext *context)
Abort CHAP authentication.
Definition: chap.c:91
uint8_t value[]
Definition: tcp.h:367
void pppRcvConfigureAckEvent(PppContext *context, PppFsm *fsm, const PppCallbacks *callbacks)
Process Receive-Configure-Ack event.
Definition: ppp_fsm.c:524
@ PPP_PHASE_AUTHENTICATE
Authentication phase.
Definition: ppp.h:168
@ ERROR_FAILURE
Generic error code.
Definition: error.h:45
uint8_t identifier[]
error_t lcpProcessEchoReq(PppContext *context, const PppEchoPacket *echoReqPacket)
Process Echo-Request packet.
Definition: lcp.c:747
void netBufferFree(NetBuffer *buffer)
Dispose a multi-part buffer.
Definition: net_mem.c:282
@ ERROR_INVALID_LENGTH
Definition: error.h:111
void lcpThisLayerFinished(PppContext *context)
This-Layer-Finished callback function.
Definition: lcp.c:967
#define PPP_RESTART_TIMER
Definition: ppp.h:96
error_t lcpSendConfigureAck(PppContext *context, const PppConfigurePacket *configureReqPacket)
Send-Configure-Ack callback function.
Definition: lcp.c:1159
#define PPP_DEFAULT_MAGIC_NUMBER
Definition: ppp.h:132
@ PPP_PHASE_DEAD
Link dead.
Definition: ppp.h:166
@ PPP_CODE_CONFIGURE_NAK
Configure-Nak.
Definition: ppp.h:218
#define MSB(x)
Definition: os_port.h:61
@ ERROR_INVALID_TYPE
Definition: error.h:115
@ PPP_PROTOCOL_IPV6
Internet Protocol version 6.
Definition: ppp.h:200
#define TRACE_INFO(...)
Definition: debug.h:95
__start_packed struct @1 PppTerminatePacket
Terminate-Request and Terminate-Ack packet.
error_t lcpProcessDiscardReq(PppContext *context, const PppDiscardReqPacket *discardReqPacket)
Process Discard-Request packet.
Definition: lcp.c:788
void pppRcvTerminateReqEvent(PppContext *context, PppFsm *fsm, const PppCallbacks *callbacks, const PppTerminatePacket *terminateReqPacket)
Process Receive-Terminate-Req event.
Definition: ppp_fsm.c:648
#define LSB(x)
Definition: os_port.h:57
@ PPP_PROTOCOL_IPV6CP
IPv6 Control Protocol.
Definition: ppp.h:202
#define MIN(a, b)
Definition: os_port.h:65
error_t ipcpOpen(PppContext *context)
IPCP Open event.
Definition: ipcp.c:76
error_t lcpProcessConfigureReject(PppContext *context, const PppConfigurePacket *configureRejPacket)
Process Configure-Reject packet.
Definition: lcp.c:492
@ LCP_OPTION_PFC
Protocol-Field-Compression.
Definition: lcp.h:55
error_t pppSendTerminateAck(PppContext *context, uint8_t identifier, PppProtocol protocol)
Send Terminate-Ack packet.
Definition: ppp_misc.c:215
@ PPP_STATE_8_ACK_SENT
Definition: ppp.h:188
@ PPP_CODE_TERMINATE_ACK
Terminate-Ack.
Definition: ppp.h:221
void lcpZeroRestartCount(PppContext *context)
Zero-Restart-Count callback function.
Definition: lcp.c:1003
@ PPP_CODE_DISCARD_REQ
Discard-Request.
Definition: ppp.h:226
uint32_t systime_t
System time.
#define ntohs(value)
Definition: cpu_endian.h:421
error_t lcpParseMruOption(PppContext *context, LcpMruOption *option, PppConfigurePacket *outPacket)
Parse Maximum-Receive-Unit option.
Definition: lcp.c:1392
error_t lcpProcessConfigureAck(PppContext *context, const PppConfigurePacket *configureAckPacket)
Process Configure-Ack packet.
Definition: lcp.c:345
__start_packed struct @2 LcpAuthProtocolOption
Authentication-Protocol option.
#define MAX(a, b)
Definition: os_port.h:69
error_t pppSendEchoRep(PppContext *context, const PppEchoPacket *echoReqPacket, PppProtocol protocol)
Send Echo-Reply packet.
Definition: ppp_misc.c:385
@ PPP_PROTOCOL_LCP
Link Control Protocol.
Definition: ppp.h:203
uint32_t time
@ PPP_CODE_ECHO_REQ
Echo-Request.
Definition: ppp.h:224
__start_packed struct @3 PppProtocolRejPacket
Protocol-Reject packet.
#define PPP_MAX_MRU
Definition: ppp.h:137
@ PPP_PROTOCOL_IPCP
IP Control Protocol.
Definition: ppp.h:201
error_t pppSendFrame(NetInterface *interface, NetBuffer *buffer, size_t offset, uint16_t protocol)
Send a PPP frame.
Definition: ppp.c:1022
@ PPP_AUTH_PROTOCOL_CHAP_MD5
Definition: ppp.h:237
void pppRcvConfigureReqEvent(PppContext *context, PppFsm *fsm, const PppCallbacks *callbacks, const PppConfigurePacket *configureReqPacket, PppCode code)
Process Receive-Configure-Request event.
Definition: ppp_fsm.c:335
@ ERROR_INVALID_VALUE
Definition: error.h:116
error_t pppDumpPacket(const PppPacket *packet, size_t length, PppProtocol protocol)
Dump LCP/NCP packet for debugging purpose.
Definition: ppp_debug.c:143
PPP miscellaneous functions.
error_t pppSendConfigureAckNak(PppContext *context, const PppConfigurePacket *configureReqPacket, PppProtocol protocol, PppCode code)
Send Configure-Ack, Nak or Reject packet.
Definition: ppp_misc.c:56
__start_packed struct @6 LcpAcfcOption
Address-and-Control-Field-Compression option.
error_t lcpProcessTerminateAck(PppContext *context, const PppTerminatePacket *terminateAckPacket)
Process Terminate-Ack packet.
Definition: lcp.c:612
error_t netBufferSetLength(NetBuffer *buffer, size_t length)
Adjust the length of a multi-part buffer.
Definition: net_mem.c:320
@ LCP_OPTION_AUTH_PROTOCOL
Authentication-Protocol.
Definition: lcp.h:52
@ LCP_OPTION_MRU
Maximum-Receive-Unit.
Definition: lcp.h:50
error_t papStartAuth(PppContext *context)
Start PAP authentication.
Definition: pap.c:53
error_t ipcpClose(PppContext *context)
IPCP Close event.
Definition: ipcp.c:97
@ ERROR_WRONG_IDENTIFIER
Definition: error.h:89
void lcpInitRestartCount(PppContext *context, uint_t value)
Initialize-Restart-Count callback function.
Definition: lcp.c:988
error_t ipv6cpOpen(PppContext *context)
IPV6CP Open event.
Definition: ipv6cp.c:77
error_t chapStartAuth(PppContext *context)
Start CHAP authentication.
Definition: chap.c:57
@ LCP_OPTION_MAGIC_NUMBER
Magic-Number.
Definition: lcp.h:54
error_t pppSendTerminateReq(PppContext *context, uint8_t identifier, PppProtocol protocol)
Send Terminate-Request packet.
Definition: ppp_misc.c:166
__start_packed struct @1 LcpAccmOption
Async-Control-Character-Map option.
void lcpThisLayerStarted(PppContext *context)
This-Layer-Started callback function.
Definition: lcp.c:955
error_t lcpSendConfigureNak(PppContext *context, const PppConfigurePacket *configureReqPacket)
Send-Configure-Nak callback function.
Definition: lcp.c:1178
@ PPP_STATE_4_CLOSING
Definition: ppp.h:184
error_t lcpProcessUnknownCode(PppContext *context, const PppPacket *packet)
Process packet with unknown code.
Definition: lcp.c:806
void pppDownEvent(PppContext *context, PppFsm *fsm, const PppCallbacks *callbacks)
Process Down event.
Definition: ppp_fsm.c:84
error_t lcpProcessEchoRep(PppContext *context, const PppEchoPacket *echoRepPacket)
Process Echo-Reply packet.
Definition: lcp.c:770
@ PPP_PHASE_TERMINATE
Link termination phase.
Definition: ppp.h:170
@ PPP_PROTOCOL_IP
Internet Protocol.
Definition: ppp.h:199
error_t lcpClose(PppContext *context)
LCP Close event.
Definition: lcp.c:103
#define PRIuSIZE
void pppRcvTerminateAckEvent(PppContext *context, PppFsm *fsm, const PppCallbacks *callbacks)
Process Receive-Terminate-Ack event.
Definition: ppp_fsm.c:697
unsigned int uint_t
Definition: compiler_port.h:50
TCP/IP stack core.
error_t lcpSendConfigureReq(PppContext *context)
Send-Configure-Request callback function.
Definition: lcp.c:1024
#define PPP_MAX_CONF_REQ_SIZE
Definition: ppp.h:140
void lcpThisLayerDown(PppContext *context)
This-Layer-Down callback function.
Definition: lcp.c:921
__start_packed struct @0 PppConfigurePacket
Configure-Request, Configure-Ack, Configure-Nak and Configure-Reject packets.
__start_packed struct @4 PppEchoPacket
Echo-Request and Echo-Reply packet.
PAP (Password Authentication Protocol)
#define ntohl(value)
Definition: cpu_endian.h:422
#define PPP_MIN_MRU
Definition: ppp.h:135
#define PPP_DEFAULT_MRU
Definition: ppp.h:128
@ NO_ERROR
Success.
Definition: error.h:44
@ PPP_CODE_TERMINATE_REQ
Terminate-Request.
Definition: ppp.h:220
Debugging facilities.
void pppTimeoutEvent(PppContext *context, PppFsm *fsm, const PppCallbacks *callbacks)
Process Timeout event.
Definition: ppp_fsm.c:257
__start_packed struct @0 LcpMruOption
Maximum-Receive-Unit option.
@ PPP_PROTOCOL_PAP
Password Authentication Protocol.
Definition: ppp.h:204
systime_t osGetSystemTime(void)
Retrieve system time.
@ PPP_PHASE_ESTABLISH
Link establishment phase.
Definition: ppp.h:167