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