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-2024 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.4.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  {
866  context->localAuthDone = FALSE;
867  }
868  else
869  {
870  context->localAuthDone = TRUE;
871  }
872 
873  //Check whether the other end of the PPP link is the authenticator
874  if(context->peerConfig.authProtocol != 0)
875  {
876  context->peerAuthDone = FALSE;
877  }
878  else
879  {
880  context->peerAuthDone = TRUE;
881  }
882 
883 #if (PAP_SUPPORT == ENABLED)
884  //PAP authentication required?
885  if(context->localConfig.authProtocol == PPP_PROTOCOL_PAP ||
886  context->peerConfig.authProtocol == PPP_PROTOCOL_PAP)
887  {
888  //Advance to the Authentication phase
889  context->pppPhase = PPP_PHASE_AUTHENTICATE;
890  //Start PAP authentication process
891  papStartAuth(context);
892  }
893 #endif
894 #if (CHAP_SUPPORT == ENABLED)
895  //CHAP authentication required?
896  if(context->localConfig.authProtocol == PPP_PROTOCOL_CHAP ||
897  context->peerConfig.authProtocol == PPP_PROTOCOL_CHAP)
898  {
899  //Advance to the Authentication phase
900  context->pppPhase = PPP_PHASE_AUTHENTICATE;
901  //Start CHAP authentication process
902  chapStartAuth(context);
903  }
904 #endif
905 
906  //Check whether PPP authentication is complete
907  if(context->localAuthDone && context->peerAuthDone)
908  {
909  //Advance to the Network phase
910  context->pppPhase = PPP_PHASE_NETWORK;
911 
912 #if (IPV4_SUPPORT == ENABLED)
913  //IPCP Open event
914  ipcpOpen(context);
915 #endif
916 #if (IPV6_SUPPORT == ENABLED)
917  //IPV6CP Open event
918  ipv6cpOpen(context);
919 #endif
920  }
921 }
922 
923 
924 /**
925  * @brief This-Layer-Down callback function
926  * @param[in] context PPP context
927  **/
928 
930 {
931  //Debug message
932  TRACE_INFO("LCP This-Layer-Down callback\r\n");
933 
934  //Advance to the Terminate phase
935  context->pppPhase = PPP_PHASE_TERMINATE;
936 
937 #if (IPV4_SUPPORT == ENABLED)
938  //IPCP Close event
939  ipcpClose(context);
940 #endif
941 #if (IPV6_SUPPORT == ENABLED)
942  //IPV6CP Close event
943  ipv6cpClose(context);
944 #endif
945 
946 #if (PAP_SUPPORT == ENABLED)
947  //Abort PAP authentication process
948  papAbortAuth(context);
949 #endif
950 
951 #if (CHAP_SUPPORT == ENABLED)
952  //Abort CHAP authentication process
953  chapAbortAuth(context);
954 #endif
955 }
956 
957 
958 /**
959  * @brief This-Layer-Started callback function
960  * @param[in] context PPP context
961  **/
962 
964 {
965  //Debug message
966  TRACE_INFO("LCP This-Layer-Started callback\r\n");
967 }
968 
969 
970 /**
971  * @brief This-Layer-Finished callback function
972  * @param[in] context PPP context
973  **/
974 
976 {
977  //Debug message
978  TRACE_INFO("LCP This-Layer-Finished callback\r\n");
979 
980  //The link is no longer available for traffic
981  pppCloseEvent(context, &context->lcpFsm, &lcpCallbacks);
982  //The lower layer is no longer ready to carry packets
983  pppDownEvent(context, &context->lcpFsm, &lcpCallbacks);
984 
985  //Advance to the Link Dead phase
986  context->pppPhase = PPP_PHASE_DEAD;
987 }
988 
989 
990 /**
991  * @brief Initialize-Restart-Count callback function
992  * @param[in] context PPP context
993  * @param[in] value Restart counter value
994  **/
995 
997 {
998  //Debug message
999  TRACE_INFO("LCP Initialize-Restart-Count callback\r\n");
1000 
1001  //Initialize restart counter
1002  context->lcpFsm.restartCounter = value;
1003 }
1004 
1005 
1006 /**
1007  * @brief Zero-Restart-Count callback function
1008  * @param[in] context PPP context
1009  **/
1010 
1012 {
1013  //Debug message
1014  TRACE_INFO("LCP Zero-Restart-Count callback\r\n");
1015 
1016  //Zero restart counter
1017  context->lcpFsm.restartCounter = 0;
1018 
1019  //The receiver of a Terminate-Request should wait for the peer to
1020  //disconnect, and must not disconnect until at least one Restart
1021  //time has passed after sending a Terminate-Ack
1022  context->lcpFsm.timestamp = osGetSystemTime();
1023 }
1024 
1025 
1026 /**
1027  * @brief Send-Configure-Request callback function
1028  * @param[in] context PPP context
1029  * @return Error code
1030  **/
1031 
1033 {
1034  error_t error;
1035  size_t length;
1036  size_t offset;
1037  NetBuffer *buffer;
1038  PppConfigurePacket *configureReqPacket;
1039 
1040  //Debug message
1041  TRACE_INFO("LCP Send-Configure-Request callback\r\n");
1042 
1043  //Allocate a buffer memory to hold the Configure-Request packet
1044  buffer = pppAllocBuffer(PPP_MAX_CONF_REQ_SIZE, &offset);
1045  //Failed to allocate memory?
1046  if(buffer == NULL)
1047  return ERROR_OUT_OF_MEMORY;
1048 
1049  //Point to the Configure-Request packet
1050  configureReqPacket = netBufferAt(buffer, offset, 0);
1051 
1052  //Format packet header
1053  configureReqPacket->code = PPP_CODE_CONFIGURE_REQ;
1054  configureReqPacket->identifier = ++context->lcpFsm.identifier;
1055  configureReqPacket->length = sizeof(PppConfigurePacket);
1056 
1057  //Make sure the Maximum-Receive-Unit option has not been
1058  //previously rejected
1059  if(!context->localConfig.mruRejected)
1060  {
1061  //Convert MRU to network byte order
1062  uint16_t value = htons(context->localConfig.mru);
1063  //Add option
1064  pppAddOption(configureReqPacket, LCP_OPTION_MRU, &value, sizeof(uint16_t));
1065  }
1066 
1067  //Make sure the Async-Control-Character-Map option has not been
1068  //previously rejected
1069  if(!context->localConfig.accmRejected)
1070  {
1071  //Convert ACCM to network byte order
1072  uint32_t value = htonl(context->localConfig.accm);
1073  //Add option
1074  pppAddOption(configureReqPacket, LCP_OPTION_ACCM, &value, sizeof(uint32_t));
1075  }
1076 
1077  //Make sure the Authentication-Protocol option has not been
1078  //previously rejected
1079  if(!context->localConfig.authProtocolRejected)
1080  {
1081  uint8_t value[3];
1082 
1083  //PAP authentication protocol?
1084  if(context->localConfig.authProtocol == PPP_PROTOCOL_PAP)
1085  {
1086  //Format Authentication-Protocol option
1087  value[0] = MSB(PPP_PROTOCOL_PAP);
1088  value[1] = LSB(PPP_PROTOCOL_PAP);
1089 
1090  //Add option
1091  pppAddOption(configureReqPacket, LCP_OPTION_AUTH_PROTOCOL, &value, 2);
1092  }
1093  //CHAP authentication protocol?
1094  else if(context->localConfig.authProtocol == PPP_PROTOCOL_CHAP)
1095  {
1096  //Format Authentication-Protocol option
1097  value[0] = MSB(PPP_PROTOCOL_CHAP);
1098  value[1] = LSB(PPP_PROTOCOL_CHAP);
1099  value[2] = context->localConfig.authAlgo;
1100 
1101  //Add option
1102  pppAddOption(configureReqPacket, LCP_OPTION_AUTH_PROTOCOL, &value, 3);
1103  }
1104  }
1105 
1106  //Make sure the Protocol-Field-Compression option has not been
1107  //previously rejected
1108  if(!context->localConfig.pfcRejected)
1109  {
1110  //Check whether compression of the Protocol field is supported
1111  if(context->localConfig.pfc)
1112  {
1113  //Add option
1114  pppAddOption(configureReqPacket, LCP_OPTION_PFC, NULL, 0);
1115  }
1116  }
1117 
1118  //Make sure the Address-and-Control-Field-Compression option has not been
1119  //previously rejected
1120  if(!context->localConfig.acfcRejected)
1121  {
1122  //Check whether compression of the Address and Control fields is supported
1123  if(context->localConfig.acfc)
1124  {
1125  //Add option
1126  pppAddOption(configureReqPacket, LCP_OPTION_ACFC, NULL, 0);
1127  }
1128  }
1129 
1130  //Save packet length
1131  length = configureReqPacket->length;
1132  //Convert length field to network byte order
1133  configureReqPacket->length = htons(length);
1134 
1135  //Adjust the length of the multi-part buffer
1136  netBufferSetLength(buffer, offset + length);
1137 
1138  //Debug message
1139  TRACE_INFO("Sending Configure-Request packet (%" PRIuSIZE " bytes)...\r\n", length);
1140  //Dump packet contents for debugging purpose
1141  pppDumpPacket((PppPacket *) configureReqPacket, length, PPP_PROTOCOL_LCP);
1142 
1143  //Send PPP frame
1144  error = pppSendFrame(context->interface, buffer, offset, PPP_PROTOCOL_LCP);
1145 
1146  //The restart counter is decremented each time a Configure-Request is sent
1147  if(context->lcpFsm.restartCounter > 0)
1148  context->lcpFsm.restartCounter--;
1149 
1150  //Save the time at which the packet was sent
1151  context->lcpFsm.timestamp = osGetSystemTime();
1152 
1153  //Free previously allocated memory block
1154  netBufferFree(buffer);
1155 
1156  //Return status code
1157  return error;
1158 }
1159 
1160 
1161 /**
1162  * @brief Send-Configure-Ack callback function
1163  * @param[in] context PPP context
1164  * @param[in] configureReqPacket Configure-Request packet received from the peer
1165  * @return Error code
1166  **/
1167 
1169  const PppConfigurePacket *configureReqPacket)
1170 {
1171  //Debug message
1172  TRACE_INFO("LCP Send-Configure-Ack callback\r\n");
1173 
1174  //Send Configure-Ack packet
1175  return pppSendConfigureAckNak(context, configureReqPacket,
1177 }
1178 
1179 
1180 /**
1181  * @brief Send-Configure-Nak callback function
1182  * @param[in] context PPP context
1183  * @param[in] configureReqPacket Configure-Request packet received from the peer
1184  * @return Error code
1185  **/
1186 
1188  const PppConfigurePacket *configureReqPacket)
1189 {
1190  //Debug message
1191  TRACE_INFO("LCP Send-Configure-Nak callback\r\n");
1192 
1193  //Send Configure-Nak packet
1194  return pppSendConfigureAckNak(context, configureReqPacket,
1196 }
1197 
1198 
1199 /**
1200  * @brief Send-Configure-Reject callback function
1201  * @param[in] context PPP context
1202  * @param[in] configureReqPacket Configure-Request packet received from the peer
1203  * @return Error code
1204  **/
1205 
1207  const PppConfigurePacket *configureReqPacket)
1208 {
1209  //Debug message
1210  TRACE_INFO("LCP Send-Configure-Reject callback\r\n");
1211 
1212  //Send Configure-Reject packet
1213  return pppSendConfigureAckNak(context, configureReqPacket,
1215 }
1216 
1217 
1218 /**
1219  * @brief Send-Terminate-Request callback function
1220  * @param[in] context PPP context
1221  * @return Error code
1222  **/
1223 
1225 {
1226  error_t error;
1227 
1228  //Debug message
1229  TRACE_INFO("LCP Send-Terminate-Request callback\r\n");
1230 
1231  //On transmission, the Identifier field must be changed
1232  context->lcpFsm.identifier++;
1233 
1234  //Send Terminate-Request packet
1235  error = pppSendTerminateReq(context, context->lcpFsm.identifier, PPP_PROTOCOL_LCP);
1236 
1237  //The restart counter is decremented each time a Terminate-Request is sent
1238  if(context->lcpFsm.restartCounter > 0)
1239  context->lcpFsm.restartCounter--;
1240 
1241  //Save the time at which the packet was sent
1242  context->lcpFsm.timestamp = osGetSystemTime();
1243 
1244  //Return status code
1245  return error;
1246 }
1247 
1248 
1249 /**
1250  * @brief Send-Terminate-Ack callback function
1251  * @param[in] context PPP context
1252  * @param[in] terminateReqPacket Terminate-Request packet received from the peer
1253  * @return Error code
1254  **/
1255 
1257  const PppTerminatePacket *terminateReqPacket)
1258 {
1259  uint8_t identifier;
1260 
1261  //Debug message
1262  TRACE_INFO("LCP Send-Terminate-Ack callback\r\n");
1263 
1264  //Check whether this Terminate-Ack acknowledges the reception of a
1265  //Terminate-Request packet
1266  if(terminateReqPacket != NULL)
1267  {
1268  //The Identifier field of the Terminate-Request is copied into the
1269  //Identifier field of the Terminate-Ack packet
1270  identifier = terminateReqPacket->identifier;
1271  }
1272  else
1273  {
1274  //This Terminate-Ack packet serves to synchronize the automatons
1275  identifier = ++context->lcpFsm.identifier;
1276  }
1277 
1278  //Send Terminate-Ack packet
1280 }
1281 
1282 
1283 /**
1284  * @brief Send-Code-Reject callback function
1285  * @param[in] context PPP context
1286  * @param[in] packet Un-interpretable packet received from the peer
1287  * @return Error code
1288  **/
1289 
1290 error_t lcpSendCodeRej(PppContext *context, const PppPacket *packet)
1291 {
1292  //Debug message
1293  TRACE_INFO("LCP Send-Code-Reject callback\r\n");
1294 
1295  //The Identifier field must be changed for each Code-Reject sent
1296  context->lcpFsm.identifier++;
1297 
1298  //Send Code-Reject packet
1299  return pppSendCodeRej(context, packet, context->lcpFsm.identifier, PPP_PROTOCOL_LCP);
1300 }
1301 
1302 
1303 /**
1304  * @brief Send-Echo-Reply callback function
1305  * @param[in] context PPP context
1306  * @param[in] echoReqPacket Echo-Request packet received from the peer
1307  * @return Error code
1308  **/
1309 
1310 error_t lcpSendEchoRep(PppContext *context, const PppEchoPacket *echoReqPacket)
1311 {
1312  //Debug message
1313  TRACE_INFO("LCP Send-Echo-Reply callback\r\n");
1314 
1315  //Send Echo-Reply packet
1316  return pppSendEchoRep(context, echoReqPacket, PPP_PROTOCOL_LCP);
1317 }
1318 
1319 
1320 /**
1321  * @brief Parse LCP configuration option
1322  * @param[in] context PPP context
1323  * @param[in] option Option to be checked
1324  * @param[in] inPacketLen Remaining bytes to process in the incoming packet
1325  * @param[out] outPacket Pointer to the Configure-Ack, Nak or Reject packet
1326  * @return Error code
1327  **/
1328 
1330  size_t inPacketLen, PppConfigurePacket *outPacket)
1331 {
1332  error_t error;
1333 
1334  //Malformed LCP packet?
1335  if(inPacketLen < sizeof(PppOption))
1336  return ERROR_INVALID_LENGTH;
1337 
1338  //Check option length
1339  if(option->length < sizeof(PppOption))
1340  return ERROR_INVALID_LENGTH;
1341  if(option->length > inPacketLen)
1342  return ERROR_INVALID_LENGTH;
1343 
1344  //Check option type
1345  switch(option->type)
1346  {
1347  case LCP_OPTION_MRU:
1348  //Check Maximum-Receive-Unit option
1349  error = lcpParseMruOption(context, (LcpMruOption *) option, outPacket);
1350  break;
1351  case LCP_OPTION_ACCM:
1352  //Check Async-Control-Character-Map option
1353  error = lcpParseAccmOption(context, (LcpAccmOption *) option, outPacket);
1354  break;
1356  //Check Authentication-Protocol option
1357  error = lcpParseAuthProtocolOption(context, (LcpAuthProtocolOption *) option, outPacket);
1358  break;
1360  //Check Magic-Number option
1361  error = lcpParseMagicNumberOption(context, (LcpMagicNumberOption *) option, outPacket);
1362  break;
1363  case LCP_OPTION_PFC:
1364  //Check Protocol-Field-Compression option
1365  error = lcpParsePfcOption(context, (LcpPfcOption *) option, outPacket);
1366  break;
1367  case LCP_OPTION_ACFC:
1368  //Check Address-and-Control-Field-Compression option
1369  error = lcpParseAcfcOption(context, (LcpAcfcOption *) option, outPacket);
1370  break;
1371  default:
1372  //If some configuration options received in the Configure-Request are not
1373  //recognizable or not acceptable for negotiation, then the implementation
1374  //must transmit a Configure-Reject
1375  if(outPacket != NULL && outPacket->code == PPP_CODE_CONFIGURE_REJ)
1376  {
1377  //The options field of the Configure-Reject packet is filled
1378  //with the unrecognized options from the Configure-Request
1379  pppAddOption(outPacket, option->type, option->data,
1380  option->length - sizeof(PppOption));
1381  }
1382 
1383  //The option is not acceptable for negotiation
1384  error = ERROR_INVALID_TYPE;
1385  break;
1386  }
1387 
1388  //Return status code
1389  return error;
1390 }
1391 
1392 
1393 /**
1394  * @brief Parse Maximum-Receive-Unit option
1395  * @param[in] context PPP context
1396  * @param[in] option Option to be checked
1397  * @param[out] outPacket Pointer to the Configure-Nak or Configure-Reject packet
1398  * @return Error code
1399  **/
1400 
1402  LcpMruOption *option, PppConfigurePacket *outPacket)
1403 {
1404  error_t error;
1405  uint16_t value;
1406 
1407  //Check length field
1408  if(option->length == sizeof(LcpMruOption))
1409  {
1410  //Check whether the option value is acceptable
1411  if(ntohs(option->mru) >= PPP_MIN_MRU)
1412  {
1413  //If every configuration option received in the Configure-Request is
1414  //recognizable and all values are acceptable, then the implementation
1415  //must transmit a Configure-Ack
1416  if(outPacket != NULL && outPacket->code == PPP_CODE_CONFIGURE_ACK)
1417  {
1418  //Save Maximum-Receive-Unit option
1419  context->peerConfig.mru = ntohl(option->mru);
1420 
1421  //The options field of the Configure-Ack packet contains the
1422  //configuration options that the sender is acknowledging
1423  pppAddOption(outPacket, LCP_OPTION_MRU, (void *) &option->mru,
1424  option->length - sizeof(PppOption));
1425  }
1426 
1427  //The value is acceptable
1428  error = NO_ERROR;
1429  }
1430  else
1431  {
1432  //If all configuration options are recognizable, but some values are not
1433  //acceptable, then the implementation must transmit a Configure-Nak
1434  if(outPacket != NULL && outPacket->code == PPP_CODE_CONFIGURE_NAK)
1435  {
1436  //Use default value
1438 
1439  //The option must be modified to a value acceptable to the
1440  //Configure-Nak sender
1441  pppAddOption(outPacket, LCP_OPTION_MRU, &value, sizeof(uint16_t));
1442  }
1443 
1444  //The value is not acceptable
1445  error = ERROR_INVALID_VALUE;
1446  }
1447  }
1448  else
1449  {
1450  //Invalid length field
1451  error = ERROR_INVALID_LENGTH;
1452  }
1453 
1454  //Return status code
1455  return error;
1456 }
1457 
1458 
1459 /**
1460  * @brief Parse Async-Control-Character-Map option
1461  * @param[in] context PPP context
1462  * @param[in] option Option to be checked
1463  * @param[out] outPacket Pointer to the Configure-Nak or Configure-Reject packet
1464  * @return Error code
1465  **/
1466 
1468  LcpAccmOption *option, PppConfigurePacket *outPacket)
1469 {
1470  error_t error;
1471 
1472  //Check length field
1473  if(option->length == sizeof(LcpAccmOption))
1474  {
1475  //If every configuration option received in the Configure-Request is
1476  //recognizable and all values are acceptable, then the implementation
1477  //must transmit a Configure-Ack
1478  if(outPacket != NULL && outPacket->code == PPP_CODE_CONFIGURE_ACK)
1479  {
1480  //Save Async-Control-Character-Map option
1481  context->peerConfig.accm = ntohl(option->accm);
1482 
1483  //The options field of the Configure-Ack packet contains the
1484  //configuration options that the sender is acknowledging
1485  pppAddOption(outPacket, LCP_OPTION_ACCM, (void *) &option->accm,
1486  option->length - sizeof(PppOption));
1487  }
1488 
1489  //The value is acceptable
1490  error = NO_ERROR;
1491  }
1492  else
1493  {
1494  //Invalid length field
1495  error = ERROR_INVALID_LENGTH;
1496  }
1497 
1498  //Return status code
1499  return error;
1500 }
1501 
1502 
1503 /**
1504  * @brief Parse Authentication-Protocol option
1505  * @param[in] context PPP context
1506  * @param[in] option Option to be checked
1507  * @param[out] outPacket Pointer to the Configure-Nak or Configure-Reject packet
1508  * @return Error code
1509  **/
1510 
1512  LcpAuthProtocolOption *option, PppConfigurePacket *outPacket)
1513 {
1514  error_t error;
1515  uint8_t value[3];
1516 
1517  //Assume an error condition...
1518  error = ERROR_INVALID_LENGTH;
1519 
1520  //Check the length of the option
1521  if(option->length >= sizeof(LcpAuthProtocolOption))
1522  {
1523  //The Authentication-Protocol option for PAP must be exactly 4 bytes
1524  if(ntohs(option->protocol) == PPP_PROTOCOL_PAP)
1525  {
1526  if(option->length == 4)
1527  error = NO_ERROR;
1528  }
1529  //The Authentication-Protocol option for CHAP must be exactly 5 bytes
1530  else if(ntohs(option->protocol) == PPP_PROTOCOL_CHAP)
1531  {
1532  if(option->length == 5)
1533  error = NO_ERROR;
1534  }
1535  }
1536 
1537  //Make sure the length field is valid
1538  if(!error)
1539  {
1540  //PAP authentication protocol?
1541  if(context->settings.authProtocol & PPP_AUTH_PROTOCOL_PAP &&
1542  ntohs(option->protocol) == PPP_PROTOCOL_PAP)
1543  {
1544  //If every configuration option received in the Configure-Request is
1545  //recognizable and all values are acceptable, then the implementation
1546  //must transmit a Configure-Ack
1547  if(outPacket != NULL && outPacket->code == PPP_CODE_CONFIGURE_ACK)
1548  {
1549  //Save the authentication protocol to be used
1550  context->peerConfig.authProtocol = PPP_PROTOCOL_PAP;
1551 
1552  //The options field of the Configure-Ack packet contains the
1553  //configuration options that the sender is acknowledging
1554  pppAddOption(outPacket, option->type, (void *) &option->protocol,
1555  option->length - sizeof(PppOption));
1556  }
1557 
1558  //The value is acceptable
1559  error = NO_ERROR;
1560  }
1561  //CHAP with MD5 authentication protocol?
1562  else if(context->settings.authProtocol & PPP_AUTH_PROTOCOL_CHAP_MD5 &&
1563  ntohs(option->protocol) == PPP_PROTOCOL_CHAP &&
1564  option->data[0] == CHAP_ALGO_ID_CHAP_MD5)
1565  {
1566  //If every configuration option received in the Configure-Request is
1567  //recognizable and all values are acceptable, then the implementation
1568  //must transmit a Configure-Ack
1569  if(outPacket != NULL && outPacket->code == PPP_CODE_CONFIGURE_ACK)
1570  {
1571  //Save the authentication protocol to be used
1572  context->peerConfig.authProtocol = PPP_PROTOCOL_CHAP;
1573  context->peerConfig.authAlgo = CHAP_ALGO_ID_CHAP_MD5;
1574 
1575  //The options field of the Configure-Ack packet contains the
1576  //configuration options that the sender is acknowledging
1577  pppAddOption(outPacket, option->type, (void *) &option->protocol,
1578  option->length - sizeof(PppOption));
1579  }
1580 
1581  //The value is acceptable
1582  error = NO_ERROR;
1583  }
1584  else
1585  {
1586  //PAP authentication protocol allowed?
1587  if(context->settings.authProtocol & PPP_AUTH_PROTOCOL_PAP)
1588  {
1589  //If all configuration options are recognizable, but some values are not
1590  //acceptable, then the implementation must transmit a Configure-Nak
1591  if(outPacket != NULL && outPacket->code == PPP_CODE_CONFIGURE_NAK)
1592  {
1593  //Format Authentication-Protocol option
1594  value[0] = MSB(PPP_PROTOCOL_PAP);
1595  value[1] = LSB(PPP_PROTOCOL_PAP);
1596 
1597  //The option must be modified to a value acceptable to the
1598  //Configure-Nak sender
1600  }
1601 
1602  //The value is not acceptable
1603  error = ERROR_INVALID_VALUE;
1604  }
1605  //CHAP with MD5 authentication protocol allowed?
1606  else if(context->settings.authProtocol & PPP_AUTH_PROTOCOL_CHAP_MD5)
1607  {
1608  //If all configuration options are recognizable, but some values are not
1609  //acceptable, then the implementation must transmit a Configure-Nak
1610  if(outPacket != NULL && outPacket->code == PPP_CODE_CONFIGURE_NAK)
1611  {
1612  //Format Authentication-Protocol option
1613  value[0] = MSB(PPP_PROTOCOL_CHAP);
1614  value[1] = LSB(PPP_PROTOCOL_CHAP);
1616 
1617  //The option must be modified to a value acceptable to the
1618  //Configure-Nak sender
1620  }
1621 
1622  //The value is not acceptable
1623  error = ERROR_INVALID_VALUE;
1624  }
1625  else
1626  {
1627  //If some configuration options received in the Configure-Request are not
1628  //recognizable or not acceptable for negotiation, then the implementation
1629  //must transmit a Configure-Reject
1630  if(outPacket != NULL && outPacket->code == PPP_CODE_CONFIGURE_REJ)
1631  {
1632  //The options field of the Configure-Reject packet is filled
1633  //with the unrecognized options from the Configure-Request
1634  pppAddOption(outPacket, option->type, (void *) &option->protocol,
1635  option->length - sizeof(PppOption));
1636  }
1637 
1638  //The option is not acceptable for negotiation
1639  error = ERROR_INVALID_TYPE;
1640  }
1641  }
1642  }
1643 
1644  //Return status code
1645  return error;
1646 }
1647 
1648 
1649 /**
1650  * @brief Parse Magic-Number option
1651  * @param[in] context PPP context
1652  * @param[in] option Option to be checked
1653  * @param[out] outPacket Pointer to the Configure-Nak or Configure-Reject packet
1654  * @return Error code
1655  **/
1656 
1658  LcpMagicNumberOption *option, PppConfigurePacket *outPacket)
1659 {
1660  error_t error;
1661 
1662  //Check length field
1663  if(option->length == sizeof(LcpMagicNumberOption))
1664  {
1665  //If every configuration option received in the Configure-Request is
1666  //recognizable and all values are acceptable, then the implementation
1667  //must transmit a Configure-Ack
1668  if(outPacket != NULL && outPacket->code == PPP_CODE_CONFIGURE_ACK)
1669  {
1670  //Save Magic-Number option
1671  context->peerConfig.magicNumber = ntohl(option->magicNumber);
1672 
1673  //The options field of the Configure-Ack packet contains the
1674  //configuration options that the sender is acknowledging
1675  pppAddOption(outPacket, LCP_OPTION_MAGIC_NUMBER, (void *) &option->magicNumber,
1676  option->length - sizeof(PppOption));
1677  }
1678 
1679  //The value is acceptable
1680  error = NO_ERROR;
1681  }
1682  else
1683  {
1684  //Invalid length field
1685  error = ERROR_INVALID_LENGTH;
1686  }
1687 
1688  //Return status code
1689  return error;
1690 }
1691 
1692 
1693 /**
1694  * @brief Parse Protocol-Field-Compression option
1695  * @param[in] context PPP context
1696  * @param[in] option Option to be checked
1697  * @param[out] outPacket Pointer to the Configure-Nak or Configure-Reject packet
1698  * @return Error code
1699  **/
1700 
1702  LcpPfcOption *option, PppConfigurePacket *outPacket)
1703 {
1704  error_t error;
1705 
1706  //Check length field
1707  if(option->length == sizeof(LcpPfcOption))
1708  {
1709  //If every configuration option received in the Configure-Request is
1710  //recognizable and all values are acceptable, then the implementation
1711  //must transmit a Configure-Ack
1712  if(outPacket != NULL && outPacket->code == PPP_CODE_CONFIGURE_ACK)
1713  {
1714  //Save Protocol-Field-Compression option
1715  context->peerConfig.pfc = TRUE;
1716 
1717  //The options field of the Configure-Ack packet contains the
1718  //configuration options that the sender is acknowledging
1719  pppAddOption(outPacket, LCP_OPTION_PFC, NULL, 0);
1720  }
1721 
1722  //The value is acceptable
1723  error = NO_ERROR;
1724  }
1725  else
1726  {
1727  //Invalid length field
1728  error = ERROR_INVALID_LENGTH;
1729  }
1730 
1731  //Return status code
1732  return error;
1733 }
1734 
1735 
1736 /**
1737  * @brief Parse Address-and-Control-Field-Compression option
1738  * @param[in] context PPP context
1739  * @param[in] option Option to be checked
1740  * @param[out] outPacket Pointer to the Configure-Nak or Configure-Reject packet
1741  * @return Error code
1742  **/
1743 
1745  LcpAcfcOption *option, PppConfigurePacket *outPacket)
1746 {
1747  error_t error;
1748 
1749  //Check length field
1750  if(option->length == sizeof(LcpAcfcOption))
1751  {
1752  //If every configuration option received in the Configure-Request is
1753  //recognizable and all values are acceptable, then the implementation
1754  //must transmit a Configure-Ack
1755  if(outPacket != NULL && outPacket->code == PPP_CODE_CONFIGURE_ACK)
1756  {
1757  //Save Address-and-Control-Field-Compression option
1758  context->peerConfig.acfc = TRUE;
1759 
1760  //The options field of the Configure-Ack packet contains the
1761  //configuration options that the sender is acknowledging
1762  pppAddOption(outPacket, LCP_OPTION_ACFC, NULL, 0);
1763  }
1764 
1765  //The value is acceptable
1766  error = NO_ERROR;
1767  }
1768  else
1769  {
1770  //Invalid length field
1771  error = ERROR_INVALID_LENGTH;
1772  }
1773 
1774  //Return status code
1775  return error;
1776 }
1777 
1778 #endif
error_t lcpProcessCodeRej(PppContext *context, const PppCodeRejPacket *codeRejPacket)
Process Code-Reject packet.
Definition: lcp.c:635
#define htons(value)
Definition: cpu_endian.h:413
Data logging functions for debugging purpose (PPP)
@ 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:1701
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
void pppRcvUnknownCodeEvent(PppContext *context, PppFsm *fsm, const PppCallbacks *callbacks, const PppPacket *packet)
Process Receive-Unknown-Code event.
Definition: ppp_fsm.c:757
uint8_t protocol
Definition: ipv4.h:326
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
LcpPfcOption
Definition: lcp.h:138
@ 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:50
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:1224
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:329
error_t lcpSendConfigureRej(PppContext *context, const PppConfigurePacket *configureReqPacket)
Send-Configure-Reject callback function.
Definition: lcp.c:1206
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
PppConfigurePacket
Definition: ppp.h:274
@ ERROR_OUT_OF_MEMORY
Definition: error.h:63
error_t lcpSendCodeRej(PppContext *context, const PppPacket *packet)
Send-Code-Reject callback function.
Definition: lcp.c:1290
@ PPP_PHASE_NETWORK
Network-layer protocol phase.
Definition: ppp.h:169
NetBuffer * pppAllocBuffer(size_t length, size_t *offset)
Allocate a buffer to hold a PPP frame.
Definition: ppp.c:1305
error_t lcpProcessConfigureReq(PppContext *context, const PppConfigurePacket *configureReqPacket)
Process Configure-Request packet.
Definition: lcp.c:249
PppDiscardReqPacket
Definition: ppp.h:342
error_t lcpSendEchoRep(PppContext *context, const PppEchoPacket *echoReqPacket)
Send-Echo-Reply callback function.
Definition: lcp.c:1310
void pppCloseEvent(PppContext *context, PppFsm *fsm, const PppCallbacks *callbacks)
Process Close event.
Definition: ppp_fsm.c:189
LcpAcfcOption
Definition: lcp.h:149
#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:268
PPP FSM actions.
Definition: ppp_fsm.h:153
PppCodeRejPacket
Definition: ppp.h:300
error_t lcpParseMagicNumberOption(PppContext *context, LcpMagicNumberOption *option, PppConfigurePacket *outPacket)
Parse Magic-Number option.
Definition: lcp.c:1657
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:454
@ 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:1329
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:46
#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:1744
error_t lcpSendTerminateAck(PppContext *context, const PppTerminatePacket *terminateReqPacket)
Send-Terminate-Ack callback function.
Definition: lcp.c:1256
@ 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
LcpAccmOption
Definition: lcp.h:89
@ 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:1467
error_t lcpParseAuthProtocolOption(PppContext *context, LcpAuthProtocolOption *option, PppConfigurePacket *outPacket)
Parse Authentication-Protocol option.
Definition: lcp.c:1511
LcpMruOption
Definition: lcp.h:77
void lcpThisLayerUp(PppContext *context)
This-Layer-Up callback function.
Definition: lcp.c:858
#define PPP_DEFAULT_ACCM
Definition: ppp.h:130
@ LCP_OPTION_ACFC
Address-and-Control-Field-Compression.
Definition: lcp.h:56
error_t chapAbortAuth(PppContext *context)
Abort CHAP authentication.
Definition: chap.c:91
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
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:975
#define PPP_RESTART_TIMER
Definition: ppp.h:96
error_t lcpSendConfigureAck(PppContext *context, const PppConfigurePacket *configureReqPacket)
Send-Configure-Ack callback function.
Definition: lcp.c:1168
#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:59
@ 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
error_t lcpProcessDiscardReq(PppContext *context, const PppDiscardReqPacket *discardReqPacket)
Process Discard-Request packet.
Definition: lcp.c:788
uint8_t length
Definition: tcp.h:368
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:55
@ PPP_PROTOCOL_IPV6CP
IPv6 Control Protocol.
Definition: ppp.h:202
#define MIN(a, b)
Definition: os_port.h:63
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:217
@ 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:1011
@ 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:1401
error_t lcpProcessConfigureAck(PppContext *context, const PppConfigurePacket *configureAckPacket)
Process Configure-Ack packet.
Definition: lcp.c:345
#define MAX(a, b)
Definition: os_port.h:67
error_t pppSendEchoRep(PppContext *context, const PppEchoPacket *echoReqPacket, PppProtocol protocol)
Send Echo-Reply packet.
Definition: ppp_misc.c:390
@ PPP_PROTOCOL_LCP
Link Control Protocol.
Definition: ppp.h:203
LcpMagicNumberOption
Definition: lcp.h:127
PppEchoPacket
Definition: ppp.h:328
uint32_t time
@ PPP_CODE_ECHO_REQ
Echo-Request.
Definition: ppp.h:224
#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:1035
@ 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.
LcpAuthProtocolOption
Definition: lcp.h:102
error_t pppSendConfigureAckNak(PppContext *context, const PppConfigurePacket *configureReqPacket, PppProtocol protocol, PppCode code)
Send Configure-Ack, Nak or Reject packet.
Definition: ppp_misc.c:56
PppTerminatePacket
Definition: ppp.h:287
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:322
uint8_t value[]
Definition: tcp.h:369
@ 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
uint8_t identifier[]
void lcpInitRestartCount(PppContext *context, uint_t value)
Initialize-Restart-Count callback function.
Definition: lcp.c:996
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
void * netBufferAt(const NetBuffer *buffer, size_t offset, size_t length)
Returns a pointer to a data segment.
Definition: net_mem.c:418
error_t pppSendTerminateReq(PppContext *context, uint8_t identifier, PppProtocol protocol)
Send Terminate-Request packet.
Definition: ppp_misc.c:167
void lcpThisLayerStarted(PppContext *context)
This-Layer-Started callback function.
Definition: lcp.c:963
error_t lcpSendConfigureNak(PppContext *context, const PppConfigurePacket *configureReqPacket)
Send-Configure-Nak callback function.
Definition: lcp.c:1187
PppOption
Definition: ppp.h:354
@ 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:1032
#define PPP_MAX_CONF_REQ_SIZE
Definition: ppp.h:140
void lcpThisLayerDown(PppContext *context)
This-Layer-Down callback function.
Definition: lcp.c:929
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
PppProtocolRejPacket
Definition: ppp.h:314
@ 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