ppp_debug.c
Go to the documentation of this file.
1 /**
2  * @file ppp_debug.c
3  * @brief Data logging functions for debugging purpose (PPP)
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2010-2019 Oryx Embedded SARL. All rights reserved.
10  *
11  * This file is part of CycloneTCP Open.
12  *
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software Foundation,
25  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26  *
27  * @author Oryx Embedded SARL (www.oryx-embedded.com)
28  * @version 1.9.6
29  **/
30 
31 //Dependencies
32 #include "core/net.h"
33 #include "ppp/ppp_debug.h"
34 #include "debug.h"
35 
36 //Check TCP/IP stack configuration
37 #if (PPP_SUPPORT == ENABLED && PPP_TRACE_LEVEL >= TRACE_LEVEL_DEBUG)
38 
39 //LCP codes
40 static const char_t *lcpCodeLabel[] =
41 {
42  "", //0
43  "Configure-Request", //1
44  "Configure-Ack", //2
45  "Configure-Nak", //3
46  "Configure-Reject", //4
47  "Terminate-Request", //5
48  "Terminate-Ack", //6
49  "Code-Reject", //7
50  "Protocol-Reject", //8
51  "Echo-Request", //9
52  "Echo-Reply", //10
53  "Discard-Request" //11
54 };
55 
56 //NCP codes
57 static const char_t *ncpCodeLabel[] =
58 {
59  "", //0
60  "Configure-Request", //1
61  "Configure-Ack", //2
62  "Configure-Nak", //3
63  "Configure-Reject", //4
64  "Terminate-Request", //5
65  "Terminate-Ack", //6
66  "Code-Reject" //7
67 };
68 
69 //PAP codes
70 static const char_t *papCodeLabel[] =
71 {
72  "", //0
73  "Authenticate-Request", //1
74  "Authenticate-Ack", //2
75  "Authenticate-Nak" //3
76 };
77 
78 //CHAP codes
79 static const char_t *chapCodeLabel[] =
80 {
81  "", //0
82  "Challenge", //1
83  "Response", //2
84  "Success", //3
85  "Failure" //4
86 };
87 
88 //LCP options
89 static const char_t *lcpOptionLabel[] =
90 {
91  "", //0
92  "Maximum-Receive-Unit", //1
93  "Async-Control-Character-Map", //2
94  "Authentication-Protocol", //3
95  "Quality-Protocol", //4
96  "Magic-Number", //5
97  "", //6
98  "Protocol-Field-Compression", //7
99  "Address-and-Control-Field-Compression", //8
100  "FCS-Alternatives", //9
101  "Self-Describing-Pad", //10
102  "Numbered-Mode", //11
103  "", //12
104  "Callback" //13
105 };
106 
107 //IPCP options
108 static const char_t *ipcpOptionLabel[] =
109 {
110  "", //0
111  "IP-Addresses", //1
112  "IP-Compression-Protocol", //2
113  "IP-Address", //3
114  "Mobile-IPv4", //4
115 };
116 
117 static const char_t *ipcpOptionLabel2[] =
118 {
119  "", //128
120  "Primary-DNS-Server-Address", //129
121  "Primary-NBNS-Server-Address", //130
122  "Secondary-DNS-Server-Address", //131
123  "Secondary-NBNS-Server-Address" //132
124 };
125 
126 //IPV6CP options
127 static const char_t *ipv6cpOptionLabel[] =
128 {
129  "", //0
130  "Interface-Identifier", //1
131  "IPv6-Compression-Protocol" //2
132 };
133 
134 
135 /**
136  * @brief Dump LCP/NCP packet for debugging purpose
137  * @param[in] packet Pointer to the LCP packet
138  * @param[in] length Length of the packet, in bytes
139  * @param[in] protocol Protocol field
140  * @return Error code
141  **/
142 
144 {
145  error_t error;
146 
147  //Check protocol field
148  switch(protocol)
149  {
150  //LCP packet?
151  case PPP_PROTOCOL_LCP:
152  error = lcpDumpPacket(packet, length);
153  break;
154  //NCP packet?
155  case PPP_PROTOCOL_IPCP:
156  case PPP_PROTOCOL_IPV6CP:
157  error = ncpDumpPacket(packet, length, protocol);
158  break;
159  //PAP packet?
160  case PPP_PROTOCOL_PAP:
161  error = papDumpPacket(packet, length);
162  break;
163  //CHAP packet?
164  case PPP_PROTOCOL_CHAP:
165  error = chapDumpPacket(packet, length);
166  break;
167  //Unknown protocol?
168  default:
169  error = ERROR_FAILURE;
170  break;
171  }
172 
173  //Return status code
174  return error;
175 }
176 
177 
178 /**
179  * @brief Dump LCP packet for debugging purpose
180  * @param[in] packet Pointer to the LCP packet
181  * @param[in] length Length of the packet, in bytes
182  * @return Error code
183  **/
184 
185 error_t lcpDumpPacket(const PppPacket *packet, size_t length)
186 {
187  error_t error;
188  const char_t *label;
189 
190  //Make sure the LCP packet is valid
191  if(length < sizeof(PppPacket))
192  return ERROR_INVALID_LENGTH;
193 
194  //Check the length field
195  if(ntohs(packet->length) > length)
196  return ERROR_INVALID_LENGTH;
197  if(ntohs(packet->length) < sizeof(PppPacket))
198  return ERROR_INVALID_LENGTH;
199 
200  //Save the length of the LCP packet
201  length = ntohs(packet->length);
202 
203  //Retrieve the name of the LCP packet
204  if(packet->code < arraysize(lcpCodeLabel))
205  label = lcpCodeLabel[packet->code];
206  else
207  label = "Unknown";
208 
209  //Dump LCP packet header
210  TRACE_DEBUG(" Code = %" PRIu8 " (%s)\r\n", packet->code, label);
211  TRACE_DEBUG(" Identifier = %" PRIu8 "\r\n", packet->identifier);
212  TRACE_DEBUG(" Length = %" PRIu16 "\r\n", ntohs(packet->length));
213 
214  //Configure-Request, Configure-Ack, Configure-Nak or Configure-Reject packet?
215  if(packet->code == PPP_CODE_CONFIGURE_REQ ||
216  packet->code == PPP_CODE_CONFIGURE_ACK ||
217  packet->code == PPP_CODE_CONFIGURE_NAK ||
218  packet->code == PPP_CODE_CONFIGURE_REJ)
219  {
220  //Cast LCP packet
222 
223  //Valid packet length?
224  if(length < sizeof(PppConfigurePacket))
225  return ERROR_INVALID_LENGTH;
226 
227  //Retrieve the length of the option list
228  length -= sizeof(PppConfigurePacket);
229 
230  //Dump options
231  error = lcpDumpOptions((PppOption *) p->options, length);
232  //Any error to report?
233  if(error)
234  return error;
235  }
236  //Terminate-Request or Terminate-Ack packet?
237  else if(packet->code == PPP_CODE_TERMINATE_REQ ||
238  packet->code == PPP_CODE_TERMINATE_ACK)
239  {
240  //Cast LCP packet
242 
243  //Valid packet length?
244  if(length < sizeof(PppTerminatePacket))
245  return ERROR_INVALID_LENGTH;
246 
247  //Retrieve the length of data
248  length -= sizeof(PppTerminatePacket);
249 
250  //Any data?
251  if(length > 0)
252  {
253  //Dump data
254  TRACE_DEBUG(" Data (%" PRIuSIZE " bytes)\r\n", length);
255  TRACE_DEBUG_ARRAY(" ", p->data, length);
256  }
257  }
258  //Code-Reject packet?
259  else if(packet->code == PPP_CODE_CODE_REJ)
260  {
261  //Cast LCP packet
262  PppCodeRejPacket *p = (PppCodeRejPacket *) packet;
263 
264  //Valid packet length?
265  if(length < sizeof(PppCodeRejPacket))
266  return ERROR_INVALID_LENGTH;
267 
268  //Retrieve the length of Rejected-Packet field
269  length -= sizeof(PppCodeRejPacket);
270 
271  //Rejected-Packet
272  TRACE_DEBUG(" Rejected-Packet (%" PRIuSIZE " bytes)\r\n", length);
273  TRACE_DEBUG_ARRAY(" ", p->rejectedPacket, length);
274  }
275  //Protocol-Reject packet?
276  else if(packet->code == PPP_CODE_PROTOCOL_REJ)
277  {
278  //Cast LCP packet
280 
281  //Valid packet length?
282  if(length < sizeof(PppProtocolRejPacket))
283  return ERROR_INVALID_LENGTH;
284 
285  //Retrieve the length of Rejected-Information field
286  length -= sizeof(PppProtocolRejPacket);
287 
288  //Rejected-Protocol
289  TRACE_DEBUG(" Rejected-Protocol = %" PRIu16 "\r\n", htons(p->rejectedProtocol));
290  //Rejected-Information
291  TRACE_DEBUG(" Rejected-Information (%" PRIuSIZE " bytes)\r\n", length);
292  TRACE_DEBUG_ARRAY(" ", p->rejectedInfo, length);
293  }
294  //Echo-Request, Echo-Reply or Discard-Request packet?
295  else if(packet->code == PPP_CODE_ECHO_REQ ||
296  packet->code == PPP_CODE_ECHO_REP ||
297  packet->code == PPP_CODE_DISCARD_REQ)
298  {
299  //Cast LCP packet
300  PppEchoPacket *p = (PppEchoPacket *) packet;
301 
302  //Valid packet length?
303  if(length < sizeof(PppEchoPacket))
304  return ERROR_INVALID_LENGTH;
305 
306  //Retrieve the length of data
307  length -= sizeof(PppEchoPacket);
308 
309  //Magic-Number
310  TRACE_DEBUG(" Magic-Number = %" PRIu32 "\r\n", htonl(p->magicNumber));
311  //Data
312  TRACE_DEBUG(" Data (%" PRIuSIZE " bytes)\r\n", length);
313  TRACE_DEBUG_ARRAY(" ", p->data, length);
314  }
315  //Unknown packet?
316  else
317  {
318  //Retrieve the length of data
319  length -= sizeof(PppPacket);
320 
321  //Any data?
322  if(length > 0)
323  {
324  //Dump data
325  TRACE_DEBUG(" Data (%" PRIuSIZE " bytes)\r\n", length);
326  TRACE_DEBUG_ARRAY(" ", packet->data, length);
327  }
328  }
329 
330  //No error to report
331  return NO_ERROR;
332 }
333 
334 
335 /**
336  * @brief Dump NCP packet for debugging purpose
337  * @param[in] packet Pointer to the NCP packet
338  * @param[in] length Length of the packet, in bytes
339  * @param[in] protocol Protocol field
340  * @return Error code
341  **/
342 
344 {
345  error_t error;
346  const char_t *label;
347 
348  //Make sure the NDP packet is valid
349  if(length < sizeof(PppPacket))
350  return ERROR_INVALID_LENGTH;
351 
352  //Check the length field
353  if(ntohs(packet->length) > length)
354  return ERROR_INVALID_LENGTH;
355  if(ntohs(packet->length) < sizeof(PppPacket))
356  return ERROR_INVALID_LENGTH;
357 
358  //Save the length of the NDP packet
359  length = ntohs(packet->length);
360 
361  //Retrieve the name of the NDP packet
362  if(packet->code < arraysize(ncpCodeLabel))
363  label = ncpCodeLabel[packet->code];
364  else
365  label = "Unknown";
366 
367  //Dump NDP packet header
368  TRACE_DEBUG(" Code = %" PRIu8 " (%s)\r\n", packet->code, label);
369  TRACE_DEBUG(" Identifier = %" PRIu8 "\r\n", packet->identifier);
370  TRACE_DEBUG(" Length = %" PRIu16 "\r\n", ntohs(packet->length));
371 
372  //Configure-Request, Configure-Ack, Configure-Nak or Configure-Reject packet?
373  if(packet->code == PPP_CODE_CONFIGURE_REQ ||
374  packet->code == PPP_CODE_CONFIGURE_ACK ||
375  packet->code == PPP_CODE_CONFIGURE_NAK ||
376  packet->code == PPP_CODE_CONFIGURE_REJ)
377  {
378  //Cast NDP packet
380 
381  //Valid packet length?
382  if(length < sizeof(PppConfigurePacket))
383  return ERROR_INVALID_LENGTH;
384 
385  //Retrieve the length of the option list
386  length -= sizeof(PppConfigurePacket);
387 
388  //IPCP protocol?
390  {
391  //Dump options
392  error = ipcpDumpOptions((PppOption *) p->options, length);
393  //Any error to report?
394  if(error)
395  return error;
396  }
397  //IPV6CP protocol?
398  else if(protocol == PPP_PROTOCOL_IPV6CP)
399  {
400  //Dump options
401  error = ipv6cpDumpOptions((PppOption *) p->options, length);
402  //Any error to report?
403  if(error)
404  return error;
405  }
406  }
407  //Terminate-Request or Terminate-Ack packet?
408  else if(packet->code == PPP_CODE_TERMINATE_REQ ||
409  packet->code == PPP_CODE_TERMINATE_ACK)
410  {
411  //Cast NDP packet
413 
414  //Valid packet length?
415  if(length < sizeof(PppTerminatePacket))
416  return ERROR_INVALID_LENGTH;
417 
418  //Retrieve the length of data
419  length -= sizeof(PppTerminatePacket);
420 
421  //Any data?
422  if(length > 0)
423  {
424  //Dump data
425  TRACE_DEBUG(" Data (%" PRIuSIZE " bytes)\r\n", length);
426  TRACE_DEBUG_ARRAY(" ", p->data, length);
427  }
428  }
429  //Code-Reject packet?
430  else if(packet->code == PPP_CODE_CODE_REJ)
431  {
432  //Cast NDP packet
433  PppCodeRejPacket *p = (PppCodeRejPacket *) packet;
434 
435  //Valid packet length?
436  if(length < sizeof(PppCodeRejPacket))
437  return ERROR_INVALID_LENGTH;
438 
439  //Retrieve the length of Rejected-Packet field
440  length -= sizeof(PppCodeRejPacket);
441 
442  //Rejected-Packet
443  TRACE_DEBUG(" Rejected-Packet (%" PRIuSIZE " bytes)\r\n", length);
444  TRACE_DEBUG_ARRAY(" ", p->rejectedPacket, length);
445  }
446  //Unknown packet?
447  else
448  {
449  //Retrieve the length of data
450  length -= sizeof(PppPacket);
451 
452  //Any data?
453  if(length > 0)
454  {
455  //Dump data
456  TRACE_DEBUG(" Data (%" PRIuSIZE " bytes)\r\n", length);
457  TRACE_DEBUG_ARRAY(" ", packet->data, length);
458  }
459  }
460 
461  //No error to report
462  return NO_ERROR;
463 }
464 
465 
466 /**
467  * @brief Dump PAP packet for debugging purpose
468  * @param[in] packet Pointer to the PAP packet
469  * @param[in] length Length of the packet, in bytes
470  * @return Error code
471  **/
472 
473 error_t papDumpPacket(const PppPacket *packet, size_t length)
474 {
475  const char_t *label;
476 
477  //Make sure the PAP packet is valid
478  if(length < sizeof(PppPacket))
479  return ERROR_INVALID_LENGTH;
480 
481  //Check the length field
482  if(ntohs(packet->length) > length)
483  return ERROR_INVALID_LENGTH;
484  if(ntohs(packet->length) < sizeof(PppPacket))
485  return ERROR_INVALID_LENGTH;
486 
487  //Save the length of the PAP packet
488  length = ntohs(packet->length);
489 
490  //Retrieve the name of the PAP packet
491  if(packet->code < arraysize(papCodeLabel))
492  label = papCodeLabel[packet->code];
493  else
494  label = "Unknown";
495 
496  //Dump PAP packet header
497  TRACE_DEBUG(" Code = %" PRIu8 " (%s)\r\n", packet->code, label);
498  TRACE_DEBUG(" Identifier = %" PRIu8 "\r\n", packet->identifier);
499  TRACE_DEBUG(" Length = %" PRIu16 "\r\n", ntohs(packet->length));
500 
501  //Authenticate-Request packet?
502  if(packet->code == PAP_CODE_AUTH_REQ)
503  {
504  uint8_t *q;
506 
507  //Cast PAP packet
508  p = (PapAuthReqPacket *) packet;
509 
510  //Valid packet length?
511  if(length < sizeof(PapAuthReqPacket))
512  return ERROR_INVALID_LENGTH;
513 
514  //Peer-ID-Length field
515  TRACE_DEBUG(" Peer-ID-Length = %" PRIu8 "\r\n", p->peerIdLength);
516 
517  //Check the length of the Peer-ID field
518  if(length < (sizeof(PapAuthAckPacket) + 1 + p->peerIdLength))
519  return ERROR_INVALID_LENGTH;
520 
521  //Peer-ID field
522  TRACE_DEBUG(" Peer-ID\r\n");
523  TRACE_DEBUG_ARRAY(" ", p->peerId, p->peerIdLength);
524 
525  //Point to the Passwd-Length field
526  q = p->peerId + p->peerIdLength;
527 
528  //Passwd-Length field
529  TRACE_DEBUG(" Passwd-Length = %" PRIu8 "\r\n", q[0]);
530 
531  //Check the length of the Password field
532  if(length < (sizeof(PapAuthAckPacket) + 1 + p->peerIdLength + q[0]))
533  return ERROR_INVALID_LENGTH;
534 
535  //Password field
536  TRACE_DEBUG(" Password\r\n");
537  TRACE_DEBUG_ARRAY(" ", q + 1, q[0]);
538  }
539  //Authenticate-Ack or Authenticate-Nak packet?
540  else if(packet->code == PAP_CODE_AUTH_ACK ||
541  packet->code == PAP_CODE_AUTH_NAK)
542  {
544 
545  //Cast PAP packet
546  p = (PapAuthAckPacket *) packet;
547 
548  //Valid packet length?
549  if(length < sizeof(PapAuthAckPacket))
550  return ERROR_INVALID_LENGTH;
551 
552  //Msg-Length field
553  TRACE_DEBUG(" Msg-Length = %" PRIu8 "\r\n", p->msgLength);
554 
555  //Check the length of the Message field
556  if(length < (sizeof(PapAuthAckPacket) + p->msgLength))
557  return ERROR_INVALID_LENGTH;
558 
559  if(length > 0)
560  {
561  //Message field
562  TRACE_DEBUG(" Message\r\n");
563  TRACE_DEBUG_ARRAY(" ", p->message, p->msgLength);
564  }
565  }
566  //Unknown packet?
567  else
568  {
569  //Retrieve the length of data
570  length -= sizeof(PppPacket);
571 
572  //Any data?
573  if(length > 0)
574  {
575  //Dump data
576  TRACE_DEBUG(" Data (%" PRIuSIZE " bytes)\r\n", length);
577  TRACE_DEBUG_ARRAY(" ", packet->data, length);
578  }
579  }
580 
581  //No error to report
582  return NO_ERROR;
583 }
584 
585 
586 /**
587  * @brief Dump CHAP packet for debugging purpose
588  * @param[in] packet Pointer to the PAP packet
589  * @param[in] length Length of the packet, in bytes
590  * @return Error code
591  **/
592 
593 error_t chapDumpPacket(const PppPacket *packet, size_t length)
594 {
595  const char_t *label;
596 
597  //Make sure the CHAP packet is valid
598  if(length < sizeof(PppPacket))
599  return ERROR_INVALID_LENGTH;
600 
601  //Check the length field
602  if(ntohs(packet->length) > length)
603  return ERROR_INVALID_LENGTH;
604  if(ntohs(packet->length) < sizeof(PppPacket))
605  return ERROR_INVALID_LENGTH;
606 
607  //Save the length of the CHAP packet
608  length = ntohs(packet->length);
609 
610  //Retrieve the name of the CHAP packet
611  if(packet->code < arraysize(chapCodeLabel))
612  label = chapCodeLabel[packet->code];
613  else
614  label = "Unknown";
615 
616  //Dump CHAP packet header
617  TRACE_DEBUG(" Code = %" PRIu8 " (%s)\r\n", packet->code, label);
618  TRACE_DEBUG(" Identifier = %" PRIu8 "\r\n", packet->identifier);
619  TRACE_DEBUG(" Length = %" PRIu16 "\r\n", ntohs(packet->length));
620 
621  //Challenge or Response packet?
622  if(packet->code == CHAP_CODE_CHALLENGE ||
623  packet->code == CHAP_CODE_RESPONSE)
624  {
625  uint8_t *q;
627 
628  //Cast CHAP packet
629  p = (ChapChallengePacket *) packet;
630 
631  //Valid packet length?
632  if(length < sizeof(ChapChallengePacket))
633  return ERROR_INVALID_LENGTH;
634 
635  //Value-Size field
636  TRACE_DEBUG(" Value-Size = %" PRIu8 "\r\n", p->valueSize);
637 
638  //Check the length of the Value field
639  if(length < (sizeof(ChapChallengePacket) + p->valueSize))
640  return ERROR_INVALID_LENGTH;
641 
642  //Value field
643  TRACE_DEBUG(" Value\r\n");
644  TRACE_DEBUG_ARRAY(" ", p->value, p->valueSize);
645 
646  //Point to the Name field
647  q = p->value + p->valueSize;
648  //Retrieve the length of the Name field
649  length -= sizeof(ChapChallengePacket) + p->valueSize;
650 
651  //Name field
652  TRACE_DEBUG(" Name (%" PRIuSIZE " bytes)\r\n", length);
653  TRACE_DEBUG_ARRAY(" ", q, length);
654  }
655  //Success or Failure packet?
656  else if(packet->code == CHAP_CODE_SUCCESS ||
657  packet->code == CHAP_CODE_FAILURE)
658  {
660 
661  //Cast CHAP packet
662  p = (ChapSuccessPacket *) packet;
663 
664  //Valid packet length?
665  if(length < sizeof(ChapSuccessPacket))
666  return ERROR_INVALID_LENGTH;
667 
668  //Retrieve the length of Message field
669  length -= sizeof(ChapSuccessPacket);
670 
671  //Message field
672  TRACE_DEBUG(" Message (%" PRIuSIZE " bytes)\r\n", length);
673  TRACE_DEBUG_ARRAY(" ", p->message, length);
674  }
675  //Unknown packet?
676  else
677  {
678  //Retrieve the length of data
679  length -= sizeof(PppPacket);
680 
681  //Any data?
682  if(length > 0)
683  {
684  //Dump data
685  TRACE_DEBUG(" Data (%" PRIuSIZE " bytes)\r\n", length);
686  TRACE_DEBUG_ARRAY(" ", packet->data, length);
687  }
688  }
689 
690  //No error to report
691  return NO_ERROR;
692 }
693 
694 
695 /**
696  * @brief Dump LCP options for debugging purpose
697  * @param[in] option Pointer to the option list
698  * @param[in] length Length of the option list, in bytes
699  * @return Error code
700  **/
701 
702 error_t lcpDumpOptions(const PppOption *option, size_t length)
703 {
704  uint32_t value;
705 
706  //Parse options
707  while(length > 0)
708  {
709  //Malformed LCP packet?
710  if(length < sizeof(PppOption))
711  return ERROR_INVALID_LENGTH;
712 
713  //Check option length
714  if(option->length < sizeof(PppOption))
715  return ERROR_INVALID_LENGTH;
716  if(option->length > length)
717  return ERROR_INVALID_LENGTH;
718 
719  //Display the name of the current option
720  if(option->type < arraysize(lcpOptionLabel))
721  TRACE_DEBUG(" %s option (%" PRIu8 " bytes)\r\n", lcpOptionLabel[option->type], option->length);
722  else
723  TRACE_DEBUG(" Option %" PRIu8 " (%" PRIu8 " bytes)\r\n", option->type, option->length);
724 
725  //Check option code
726  switch(option->type)
727  {
728  //16-bit unsigned value?
729  case LCP_OPTION_MRU:
730  //Check length field
731  if(option->length != (sizeof(PppOption) + sizeof(uint16_t)))
732  return ERROR_INVALID_OPTION;
733  //Retrieve 16-bit value
734  value = LOAD16BE(option->data);
735  //Dump option contents
736  TRACE_DEBUG(" %" PRIu32 "\r\n", value);
737  break;
738 
739  //32-bit unsigned value?
740  case LCP_OPTION_ACCM:
742  //Check length field
743  if(option->length != (sizeof(PppOption) + sizeof(uint32_t)))
744  return ERROR_INVALID_OPTION;
745  //Retrieve 32-bit value
746  value = LOAD32BE(option->data);
747  //Dump option contents
748  TRACE_DEBUG(" 0x%08" PRIX32 "\r\n", value);
749  break;
750 
751  //Raw data?
752  default:
753  //Dump option contents
754  TRACE_DEBUG_ARRAY(" ", option->data, option->length - sizeof(PppOption));
755  break;
756  }
757 
758  //Remaining bytes to process
759  length -= option->length;
760  //Jump to the next option
761  option = (PppOption *) ((uint8_t *) option + option->length);
762  }
763 
764  //No error to report
765  return NO_ERROR;
766 }
767 
768 /**
769  * @brief Dump IPCP options for debugging purpose
770  * @param[in] option Pointer to the option list
771  * @param[in] length Length of the option list, in bytes
772  * @return Error code
773  **/
774 
775 error_t ipcpDumpOptions(const PppOption *option, size_t length)
776 {
777 #if (IPV4_SUPPORT == ENABLED)
779 #endif
780 
781  //Parse options
782  while(length > 0)
783  {
784  //Malformed IPCP packet?
785  if(length < sizeof(PppOption))
786  return ERROR_INVALID_LENGTH;
787 
788  //Check option length
789  if(option->length < sizeof(PppOption))
790  return ERROR_INVALID_LENGTH;
791  if(option->length > length)
792  return ERROR_INVALID_LENGTH;
793 
794  //Display the name of the current option
795  if(option->type < arraysize(ipcpOptionLabel))
796  TRACE_DEBUG(" %s option (%" PRIu8 " bytes)\r\n", ipcpOptionLabel[option->type], option->length);
797  else if(option->type >= 128 && option->type < (128 + arraysize(ipcpOptionLabel2)))
798  TRACE_DEBUG(" %s option (%" PRIu8 " bytes)\r\n", ipcpOptionLabel2[option->type - 128], option->length);
799  else
800  TRACE_DEBUG(" Option %" PRIu8 " (%" PRIu8 " bytes)\r\n", option->type, option->length);
801 
802  //Check option code
803  switch(option->type)
804  {
805 #if (IPV4_SUPPORT == ENABLED)
806  //IP address?
812  //Check length field
813  if(option->length != (sizeof(PppOption) + sizeof(Ipv4Addr)))
814  return ERROR_INVALID_OPTION;
815  //Retrieve IPv4 address
816  ipv4CopyAddr(&ipAddr, option->data);
817  //Dump option contents
818  TRACE_DEBUG(" %s\r\n", ipv4AddrToString(ipAddr, NULL));
819  break;
820 #endif
821  //Raw data?
822  default:
823  //Dump option contents
824  TRACE_DEBUG_ARRAY(" ", option->data, option->length - sizeof(PppOption));
825  break;
826  }
827 
828  //Remaining bytes to process
829  length -= option->length;
830  //Jump to the next option
831  option = (PppOption *) ((uint8_t *) option + option->length);
832  }
833 
834  //No error to report
835  return NO_ERROR;
836 }
837 
838 
839 /**
840  * @brief Dump IPV6CP options for debugging purpose
841  * @param[in] option Pointer to the option list
842  * @param[in] length Length of the option list, in bytes
843  * @return Error code
844  **/
845 
847 {
848  //Parse options
849  while(length > 0)
850  {
851  //Malformed IPV6CP packet?
852  if(length < sizeof(PppOption))
853  return ERROR_INVALID_LENGTH;
854 
855  //Check option length
856  if(option->length < sizeof(PppOption))
857  return ERROR_INVALID_LENGTH;
858  if(option->length > length)
859  return ERROR_INVALID_LENGTH;
860 
861  //Display the name of the current option
862  if(option->type < arraysize(ipv6cpOptionLabel))
863  TRACE_DEBUG(" %s option (%" PRIu8 " bytes)\r\n", ipv6cpOptionLabel[option->type], option->length);
864  else
865  TRACE_DEBUG(" Option %" PRIu8 " (%" PRIu8 " bytes)\r\n", option->type, option->length);
866 
867  //Check option code
868  switch(option->type)
869  {
870  //Raw data?
871  default:
872  //Dump option contents
873  TRACE_DEBUG_ARRAY(" ", option->data, option->length - sizeof(PppOption));
874  break;
875  }
876 
877  //Remaining bytes to process
878  length -= option->length;
879  //Jump to the next option
880  option = (PppOption *) ((uint8_t *) option + option->length);
881  }
882 
883  //No error to report
884  return NO_ERROR;
885 }
886 
887 #endif
#define htons(value)
Definition: cpu_endian.h:392
uint8_t length
Definition: dtls_misc.h:149
Data logging functions for debugging purpose (PPP)
@ PPP_CODE_CONFIGURE_REJ
Configure-Reject.
Definition: ppp.h:219
error_t papDumpPacket(const PppPacket *packet, size_t length)
Dump PAP packet for debugging purpose.
Definition: ppp_debug.c:473
#define PppPacket
Definition: ppp.h:37
@ PPP_CODE_CONFIGURE_ACK
Configure-Ack.
Definition: ppp.h:217
@ LCP_OPTION_ACCM
Async-Control-Character-Map.
Definition: lcp.h:51
__start_packed struct @286 PppTerminatePacket
Terminate-Request and Terminate-Ack packet.
error_t lcpDumpPacket(const PppPacket *packet, size_t length)
Dump LCP packet for debugging purpose.
Definition: ppp_debug.c:185
PppProtocol
Protocol field values.
Definition: ppp.h:197
#define LOAD32BE(p)
Definition: cpu_endian.h:194
@ PPP_CODE_PROTOCOL_REJ
Protocol-Reject.
Definition: ppp.h:223
@ CHAP_CODE_SUCCESS
Success.
Definition: chap.h:92
@ PPP_PROTOCOL_CHAP
Challenge Handshake Authentication Protocol.
Definition: ppp.h:206
uint8_t p
Definition: ndp.h:298
@ IPCP_OPTION_PRIMARY_DNS
Primary-DNS-Server-Address.
Definition: ipcp.h:56
__start_packed struct @291 PppOption
LCP/NCP option.
@ CHAP_CODE_CHALLENGE
Challenge.
Definition: chap.h:90
@ CHAP_CODE_RESPONSE
Response.
Definition: chap.h:91
__start_packed struct @289 PppEchoPacket
Echo-Request and Echo-Reply packet.
uint32_t Ipv4Addr
IPv4 network address.
Definition: ipv4.h:239
@ PPP_CODE_CODE_REJ
Code-Reject.
Definition: ppp.h:222
@ PPP_CODE_CONFIGURE_REQ
Configure-Request.
Definition: ppp.h:216
#define htonl(value)
Definition: cpu_endian.h:393
error_t ipv6cpDumpOptions(const PppOption *option, size_t length)
Dump IPV6CP options for debugging purpose.
Definition: ppp_debug.c:846
@ PPP_CODE_ECHO_REP
Echo-Reply.
Definition: ppp.h:225
@ PAP_CODE_AUTH_REQ
Authenticate-Request.
Definition: pap.h:88
error_t
Error codes.
Definition: error.h:42
uint8_t protocol
@ CHAP_CODE_FAILURE
Failure.
Definition: chap.h:93
@ ERROR_FAILURE
Generic error code.
Definition: error.h:45
error_t lcpDumpOptions(const PppOption *option, size_t length)
Dump LCP options for debugging purpose.
Definition: ppp_debug.c:702
@ ERROR_INVALID_LENGTH
Definition: error.h:109
@ PPP_CODE_CONFIGURE_NAK
Configure-Nak.
Definition: ppp.h:218
__start_packed struct @288 PppProtocolRejPacket
Protocol-Reject packet.
__start_packed struct @264 ChapSuccessPacket
Success packet.
@ PAP_CODE_AUTH_ACK
Authenticate-Ack.
Definition: pap.h:89
@ PPP_PROTOCOL_IPV6CP
IPv6 Control Protocol.
Definition: ppp.h:202
__start_packed struct @283 PapAuthAckPacket
Authenticate-Ack packet.
@ PPP_CODE_TERMINATE_ACK
Terminate-Ack.
Definition: ppp.h:221
@ IPCP_OPTION_PRIMARY_NBNS
Primary-NBNS-Server-Address.
Definition: ipcp.h:57
@ PPP_CODE_DISCARD_REQ
Discard-Request.
Definition: ppp.h:226
#define ntohs(value)
Definition: cpu_endian.h:398
#define TRACE_DEBUG(...)
Definition: debug.h:106
char char_t
Definition: compiler_port.h:43
@ PPP_PROTOCOL_LCP
Link Control Protocol.
Definition: ppp.h:203
__start_packed struct @285 PppConfigurePacket
Configure-Request, Configure-Ack, Configure-Nak and Configure-Reject packets.
@ PPP_CODE_ECHO_REQ
Echo-Request.
Definition: ppp.h:224
error_t ncpDumpPacket(const PppPacket *packet, size_t length, PppProtocol protocol)
Dump NCP packet for debugging purpose.
Definition: ppp_debug.c:343
#define TRACE_DEBUG_ARRAY(p, a, n)
Definition: debug.h:107
@ PPP_PROTOCOL_IPCP
IP Control Protocol.
Definition: ppp.h:201
error_t chapDumpPacket(const PppPacket *packet, size_t length)
Dump CHAP packet for debugging purpose.
Definition: ppp_debug.c:593
__start_packed struct @262 ChapChallengePacket
Challenge packet.
error_t pppDumpPacket(const PppPacket *packet, size_t length, PppProtocol protocol)
Dump LCP/NCP packet for debugging purpose.
Definition: ppp_debug.c:143
@ IPCP_OPTION_SECONDARY_NBNS
Secondary-NBNS-Server-Address.
Definition: ipcp.h:59
@ LCP_OPTION_MRU
Maximum-Receive-Unit.
Definition: lcp.h:50
__start_packed struct @282 PapAuthReqPacket
Authenticate-Request packet.
#define ipv4CopyAddr(destIpAddr, srcIpAddr)
Definition: ipv4.h:142
@ LCP_OPTION_MAGIC_NUMBER
Magic-Number.
Definition: lcp.h:54
@ ERROR_INVALID_OPTION
Definition: error.h:97
@ IPCP_OPTION_SECONDARY_DNS
Secondary-DNS-Server-Address.
Definition: ipcp.h:58
uint8_t value[]
Definition: dtls_misc.h:150
#define PRIuSIZE
Definition: compiler_port.h:78
#define LOAD16BE(p)
Definition: cpu_endian.h:170
@ IPCP_OPTION_IP_ADDRESS
IP-Address.
Definition: ipcp.h:55
TCP/IP stack core.
error_t ipcpDumpOptions(const PppOption *option, size_t length)
Dump IPCP options for debugging purpose.
Definition: ppp_debug.c:775
char_t * ipv4AddrToString(Ipv4Addr ipAddr, char_t *str)
Convert a binary IPv4 address to dot-decimal notation.
Definition: ipv4.c:1466
uint8_t ipAddr[4]
Definition: mib_common.h:187
@ NO_ERROR
Success.
Definition: error.h:44
@ PPP_CODE_TERMINATE_REQ
Terminate-Request.
Definition: ppp.h:220
@ PAP_CODE_AUTH_NAK
Authenticate-Nak.
Definition: pap.h:90
Debugging facilities.
#define arraysize(a)
Definition: os_port.h:70
@ PPP_PROTOCOL_PAP
Password Authentication Protocol.
Definition: ppp.h:204
__start_packed struct @287 PppCodeRejPacket
Code-Reject packet.