xref: /minix/external/bsd/tcpdump/dist/print-pptp.c (revision fb9c64b2)
1 /*
2  * Copyright (c) 1991, 1993, 1994, 1995, 1996, 1997
3  *      The Regents of the University of California.  All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that: (1) source code distributions
7  * retain the above copyright notice and this paragraph in its entirety, (2)
8  * distributions including binary code include the above copyright notice and
9  * this paragraph in its entirety in the documentation or other materials
10  * provided with the distribution, and (3) all advertising materials mentioning
11  * features or use of this software display the following acknowledgement:
12  * ``This product includes software developed by the University of California,
13  * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
14  * the University nor the names of its contributors may be used to endorse
15  * or promote products derived from this software without specific prior
16  * written permission.
17  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
18  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
19  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
20  *
21  * PPTP support contributed by Motonori Shindo (mshindo@mshindo.net)
22  */
23 
24 #include <sys/cdefs.h>
25 #ifndef lint
26 __RCSID("$NetBSD: print-pptp.c,v 1.4 2014/11/20 03:05:03 christos Exp $");
27 #endif
28 
29 #define NETDISSECT_REWORKED
30 #ifdef HAVE_CONFIG_H
31 #include "config.h"
32 #endif
33 
34 #include <tcpdump-stdinc.h>
35 
36 #include "interface.h"
37 #include "extract.h"
38 
39 static const char tstr[] = " [|pptp]";
40 
41 #define PPTP_MSG_TYPE_CTRL	1	/* Control Message */
42 #define PPTP_MSG_TYPE_MGMT	2	/* Management Message (currently not used */
43 #define PPTP_MAGIC_COOKIE	0x1a2b3c4d	/* for sanity check */
44 
45 #define PPTP_CTRL_MSG_TYPE_SCCRQ	1
46 #define PPTP_CTRL_MSG_TYPE_SCCRP	2
47 #define PPTP_CTRL_MSG_TYPE_StopCCRQ	3
48 #define PPTP_CTRL_MSG_TYPE_StopCCRP	4
49 #define PPTP_CTRL_MSG_TYPE_ECHORQ	5
50 #define PPTP_CTRL_MSG_TYPE_ECHORP	6
51 #define PPTP_CTRL_MSG_TYPE_OCRQ		7
52 #define PPTP_CTRL_MSG_TYPE_OCRP		8
53 #define PPTP_CTRL_MSG_TYPE_ICRQ		9
54 #define PPTP_CTRL_MSG_TYPE_ICRP		10
55 #define PPTP_CTRL_MSG_TYPE_ICCN		11
56 #define PPTP_CTRL_MSG_TYPE_CCRQ		12
57 #define PPTP_CTRL_MSG_TYPE_CDN		13
58 #define PPTP_CTRL_MSG_TYPE_WEN		14
59 #define PPTP_CTRL_MSG_TYPE_SLI		15
60 
61 #define PPTP_FRAMING_CAP_ASYNC_MASK	0x00000001      /* Aynchronous */
62 #define PPTP_FRAMING_CAP_SYNC_MASK	0x00000002      /* Synchronous */
63 
64 #define PPTP_BEARER_CAP_ANALOG_MASK	0x00000001      /* Analog */
65 #define PPTP_BEARER_CAP_DIGITAL_MASK	0x00000002      /* Digital */
66 
67 static const char *pptp_message_type_string[] = {
68 	"NOT_DEFINED",		/* 0  Not defined in the RFC2637 */
69 	"SCCRQ",		/* 1  Start-Control-Connection-Request */
70 	"SCCRP",		/* 2  Start-Control-Connection-Reply */
71 	"StopCCRQ",		/* 3  Stop-Control-Connection-Request */
72 	"StopCCRP",		/* 4  Stop-Control-Connection-Reply */
73 	"ECHORQ",		/* 5  Echo Request */
74 	"ECHORP",		/* 6  Echo Reply */
75 
76 	"OCRQ",			/* 7  Outgoing-Call-Request */
77 	"OCRP",			/* 8  Outgoing-Call-Reply */
78 	"ICRQ",			/* 9  Incoming-Call-Request */
79 	"ICRP",			/* 10 Incoming-Call-Reply */
80 	"ICCN",			/* 11 Incoming-Call-Connected */
81 	"CCRQ",			/* 12 Call-Clear-Request */
82 	"CDN",			/* 13 Call-Disconnect-Notify */
83 
84 	"WEN",			/* 14 WAN-Error-Notify */
85 
86 	"SLI"			/* 15 Set-Link-Info */
87 #define PPTP_MAX_MSGTYPE_INDEX	16
88 };
89 
90 /* common for all PPTP control messages */
91 struct pptp_hdr {
92 	uint16_t length;
93 	uint16_t msg_type;
94 	uint32_t magic_cookie;
95 	uint16_t ctrl_msg_type;
96 	uint16_t reserved0;
97 };
98 
99 struct pptp_msg_sccrq {
100 	uint16_t proto_ver;
101 	uint16_t reserved1;
102 	uint32_t framing_cap;
103 	uint32_t bearer_cap;
104 	uint16_t max_channel;
105 	uint16_t firm_rev;
106 	u_char hostname[64];
107 	u_char vendor[64];
108 };
109 
110 struct pptp_msg_sccrp {
111 	uint16_t proto_ver;
112 	uint8_t result_code;
113 	uint8_t err_code;
114 	uint32_t framing_cap;
115 	uint32_t bearer_cap;
116 	uint16_t max_channel;
117 	uint16_t firm_rev;
118 	u_char hostname[64];
119 	u_char vendor[64];
120 };
121 
122 struct pptp_msg_stopccrq {
123 	uint8_t reason;
124 	uint8_t reserved1;
125 	uint16_t reserved2;
126 };
127 
128 struct pptp_msg_stopccrp {
129 	uint8_t result_code;
130 	uint8_t err_code;
131 	uint16_t reserved1;
132 };
133 
134 struct pptp_msg_echorq {
135 	uint32_t id;
136 };
137 
138 struct pptp_msg_echorp {
139 	uint32_t id;
140 	uint8_t result_code;
141 	uint8_t err_code;
142 	uint16_t reserved1;
143 };
144 
145 struct pptp_msg_ocrq {
146 	uint16_t call_id;
147 	uint16_t call_ser;
148 	uint32_t min_bps;
149 	uint32_t max_bps;
150 	uint32_t bearer_type;
151 	uint32_t framing_type;
152 	uint16_t recv_winsiz;
153 	uint16_t pkt_proc_delay;
154 	uint16_t phone_no_len;
155 	uint16_t reserved1;
156 	u_char phone_no[64];
157 	u_char subaddr[64];
158 };
159 
160 struct pptp_msg_ocrp {
161 	uint16_t call_id;
162 	uint16_t peer_call_id;
163 	uint8_t result_code;
164 	uint8_t err_code;
165 	uint16_t cause_code;
166 	uint32_t conn_speed;
167 	uint16_t recv_winsiz;
168 	uint16_t pkt_proc_delay;
169 	uint32_t phy_chan_id;
170 };
171 
172 struct pptp_msg_icrq {
173 	uint16_t call_id;
174 	uint16_t call_ser;
175 	uint32_t bearer_type;
176 	uint32_t phy_chan_id;
177 	uint16_t dialed_no_len;
178 	uint16_t dialing_no_len;
179 	u_char dialed_no[64];		/* DNIS */
180 	u_char dialing_no[64];		/* CLID */
181 	u_char subaddr[64];
182 };
183 
184 struct pptp_msg_icrp {
185 	uint16_t call_id;
186 	uint16_t peer_call_id;
187 	uint8_t result_code;
188 	uint8_t err_code;
189 	uint16_t recv_winsiz;
190 	uint16_t pkt_proc_delay;
191 	uint16_t reserved1;
192 };
193 
194 struct pptp_msg_iccn {
195 	uint16_t peer_call_id;
196 	uint16_t reserved1;
197 	uint32_t conn_speed;
198 	uint16_t recv_winsiz;
199 	uint16_t pkt_proc_delay;
200 	uint32_t framing_type;
201 };
202 
203 struct pptp_msg_ccrq {
204 	uint16_t call_id;
205 	uint16_t reserved1;
206 };
207 
208 struct pptp_msg_cdn {
209 	uint16_t call_id;
210 	uint8_t result_code;
211 	uint8_t err_code;
212 	uint16_t cause_code;
213 	uint16_t reserved1;
214 	u_char call_stats[128];
215 };
216 
217 struct pptp_msg_wen {
218 	uint16_t peer_call_id;
219 	uint16_t reserved1;
220 	uint32_t crc_err;
221 	uint32_t framing_err;
222 	uint32_t hardware_overrun;
223 	uint32_t buffer_overrun;
224 	uint32_t timeout_err;
225 	uint32_t align_err;
226 };
227 
228 struct pptp_msg_sli {
229 	uint16_t peer_call_id;
230 	uint16_t reserved1;
231 	uint32_t send_accm;
232 	uint32_t recv_accm;
233 };
234 
235 /* attributes that appear more than once in above messages:
236 
237    Number of
238    occurence    attributes
239   --------------------------------------
240       2         uint32_t bearer_cap;
241       2         uint32_t bearer_type;
242       6         uint16_t call_id;
243       2         uint16_t call_ser;
244       2         uint16_t cause_code;
245       2         uint32_t conn_speed;
246       6         uint8_t err_code;
247       2         uint16_t firm_rev;
248       2         uint32_t framing_cap;
249       2         uint32_t framing_type;
250       2         u_char hostname[64];
251       2         uint32_t id;
252       2         uint16_t max_channel;
253       5         uint16_t peer_call_id;
254       2         uint32_t phy_chan_id;
255       4         uint16_t pkt_proc_delay;
256       2         uint16_t proto_ver;
257       4         uint16_t recv_winsiz;
258       2         uint8_t reserved1;
259       9         uint16_t reserved1;
260       6         uint8_t result_code;
261       2         u_char subaddr[64];
262       2         u_char vendor[64];
263 
264   so I will prepare print out functions for these attributes (except for
265   reserved*).
266 */
267 
268 /******************************************/
269 /* Attribute-specific print out functions */
270 /******************************************/
271 
272 /* In these attribute-specific print-out functions, it't not necessary
273    to do ND_TCHECK because they are already checked in the caller of
274    these functions. */
275 
276 static void
277 pptp_bearer_cap_print(netdissect_options *ndo,
278                       const uint32_t *bearer_cap)
279 {
280 	ND_PRINT((ndo, " BEARER_CAP(%s%s)",
281 	          EXTRACT_32BITS(bearer_cap) & PPTP_BEARER_CAP_DIGITAL_MASK ? "D" : "",
282 	          EXTRACT_32BITS(bearer_cap) & PPTP_BEARER_CAP_ANALOG_MASK ? "A" : ""));
283 }
284 
285 static const struct tok pptp_btype_str[] = {
286 	{ 1, "A"   }, /* Analog */
287 	{ 2, "D"   }, /* Digital */
288 	{ 3, "Any" },
289 	{ 0, NULL }
290 };
291 
292 static void
293 pptp_bearer_type_print(netdissect_options *ndo,
294                        const uint32_t *bearer_type)
295 {
296 	ND_PRINT((ndo, " BEARER_TYPE(%s)",
297 	          tok2str(pptp_btype_str, "?", EXTRACT_32BITS(bearer_type))));
298 }
299 
300 static void
301 pptp_call_id_print(netdissect_options *ndo,
302                    const uint16_t *call_id)
303 {
304 	ND_PRINT((ndo, " CALL_ID(%u)", EXTRACT_16BITS(call_id)));
305 }
306 
307 static void
308 pptp_call_ser_print(netdissect_options *ndo,
309                     const uint16_t *call_ser)
310 {
311 	ND_PRINT((ndo, " CALL_SER_NUM(%u)", EXTRACT_16BITS(call_ser)));
312 }
313 
314 static void
315 pptp_cause_code_print(netdissect_options *ndo,
316                       const uint16_t *cause_code)
317 {
318 	ND_PRINT((ndo, " CAUSE_CODE(%u)", EXTRACT_16BITS(cause_code)));
319 }
320 
321 static void
322 pptp_conn_speed_print(netdissect_options *ndo,
323                       const uint32_t *conn_speed)
324 {
325 	ND_PRINT((ndo, " CONN_SPEED(%u)", EXTRACT_32BITS(conn_speed)));
326 }
327 
328 static const struct tok pptp_errcode_str[] = {
329 	{ 0, "None"          },
330 	{ 1, "Not-Connected" },
331 	{ 2, "Bad-Format"    },
332 	{ 3, "Bad-Value"     },
333 	{ 4, "No-Resource"   },
334 	{ 5, "Bad-Call-ID"   },
335 	{ 6, "PAC-Error"     },
336 	{ 0, NULL }
337 };
338 
339 static void
340 pptp_err_code_print(netdissect_options *ndo,
341                     const uint8_t *err_code)
342 {
343 	ND_PRINT((ndo, " ERR_CODE(%u", *err_code));
344 	if (ndo->ndo_vflag) {
345 		ND_PRINT((ndo, ":%s", tok2str(pptp_errcode_str, "?", *err_code)));
346 	}
347 	ND_PRINT((ndo, ")"));
348 }
349 
350 static void
351 pptp_firm_rev_print(netdissect_options *ndo,
352                     const uint16_t *firm_rev)
353 {
354 	ND_PRINT((ndo, " FIRM_REV(%u)", EXTRACT_16BITS(firm_rev)));
355 }
356 
357 static void
358 pptp_framing_cap_print(netdissect_options *ndo,
359                        const uint32_t *framing_cap)
360 {
361 	ND_PRINT((ndo, " FRAME_CAP("));
362 	if (EXTRACT_32BITS(framing_cap) & PPTP_FRAMING_CAP_ASYNC_MASK) {
363                 ND_PRINT((ndo, "A"));		/* Async */
364         }
365         if (EXTRACT_32BITS(framing_cap) & PPTP_FRAMING_CAP_SYNC_MASK) {
366                 ND_PRINT((ndo, "S"));		/* Sync */
367         }
368 	ND_PRINT((ndo, ")"));
369 }
370 
371 static const struct tok pptp_ftype_str[] = {
372 	{ 1, "A" }, /* Async */
373 	{ 2, "S" }, /* Sync */
374 	{ 3, "E" }, /* Either */
375 	{ 0, NULL }
376 };
377 
378 static void
379 pptp_framing_type_print(netdissect_options *ndo,
380                         const uint32_t *framing_type)
381 {
382 	ND_PRINT((ndo, " FRAME_TYPE(%s)",
383 	          tok2str(pptp_ftype_str, "?", EXTRACT_32BITS(framing_type))));
384 }
385 
386 static void
387 pptp_hostname_print(netdissect_options *ndo,
388                     const u_char *hostname)
389 {
390 	ND_PRINT((ndo, " HOSTNAME(%.64s)", hostname));
391 }
392 
393 static void
394 pptp_id_print(netdissect_options *ndo,
395               const uint32_t *id)
396 {
397 	ND_PRINT((ndo, " ID(%u)", EXTRACT_32BITS(id)));
398 }
399 
400 static void
401 pptp_max_channel_print(netdissect_options *ndo,
402                        const uint16_t *max_channel)
403 {
404 	ND_PRINT((ndo, " MAX_CHAN(%u)", EXTRACT_16BITS(max_channel)));
405 }
406 
407 static void
408 pptp_peer_call_id_print(netdissect_options *ndo,
409                         const uint16_t *peer_call_id)
410 {
411 	ND_PRINT((ndo, " PEER_CALL_ID(%u)", EXTRACT_16BITS(peer_call_id)));
412 }
413 
414 static void
415 pptp_phy_chan_id_print(netdissect_options *ndo,
416                        const uint32_t *phy_chan_id)
417 {
418 	ND_PRINT((ndo, " PHY_CHAN_ID(%u)", EXTRACT_32BITS(phy_chan_id)));
419 }
420 
421 static void
422 pptp_pkt_proc_delay_print(netdissect_options *ndo,
423                           const uint16_t *pkt_proc_delay)
424 {
425 	ND_PRINT((ndo, " PROC_DELAY(%u)", EXTRACT_16BITS(pkt_proc_delay)));
426 }
427 
428 static void
429 pptp_proto_ver_print(netdissect_options *ndo,
430                      const uint16_t *proto_ver)
431 {
432 	ND_PRINT((ndo, " PROTO_VER(%u.%u)",	/* Version.Revision */
433 	       EXTRACT_16BITS(proto_ver) >> 8,
434 	       EXTRACT_16BITS(proto_ver) & 0xff));
435 }
436 
437 static void
438 pptp_recv_winsiz_print(netdissect_options *ndo,
439                        const uint16_t *recv_winsiz)
440 {
441 	ND_PRINT((ndo, " RECV_WIN(%u)", EXTRACT_16BITS(recv_winsiz)));
442 }
443 
444 static const struct tok pptp_scrrp_str[] = {
445 	{ 1, "Successful channel establishment"                           },
446 	{ 2, "General error"                                              },
447 	{ 3, "Command channel already exists"                             },
448 	{ 4, "Requester is not authorized to establish a command channel" },
449 	{ 5, "The protocol version of the requester is not supported"     },
450 	{ 0, NULL }
451 };
452 
453 static const struct tok pptp_echorp_str[] = {
454 	{ 1, "OK" },
455 	{ 2, "General Error" },
456 	{ 0, NULL }
457 };
458 
459 static const struct tok pptp_ocrp_str[] = {
460 	{ 1, "Connected"     },
461 	{ 2, "General Error" },
462 	{ 3, "No Carrier"    },
463 	{ 4, "Busy"          },
464 	{ 5, "No Dial Tone"  },
465 	{ 6, "Time-out"      },
466 	{ 7, "Do Not Accept" },
467 	{ 0, NULL }
468 };
469 
470 static const struct tok pptp_icrp_str[] = {
471 	{ 1, "Connect"       },
472 	{ 2, "General Error" },
473 	{ 3, "Do Not Accept" },
474 	{ 0, NULL }
475 };
476 
477 static const struct tok pptp_cdn_str[] = {
478 	{ 1, "Lost Carrier"   },
479 	{ 2, "General Error"  },
480 	{ 3, "Admin Shutdown" },
481 	{ 4, "Request"        },
482 	{ 0, NULL }
483 };
484 
485 static void
486 pptp_result_code_print(netdissect_options *ndo,
487                        const uint8_t *result_code, int ctrl_msg_type)
488 {
489 	ND_PRINT((ndo, " RESULT_CODE(%u", *result_code));
490 	if (ndo->ndo_vflag) {
491 		const struct tok *dict =
492 			ctrl_msg_type == PPTP_CTRL_MSG_TYPE_SCCRP    ? pptp_scrrp_str :
493 			ctrl_msg_type == PPTP_CTRL_MSG_TYPE_StopCCRP ? pptp_echorp_str :
494 			ctrl_msg_type == PPTP_CTRL_MSG_TYPE_ECHORP   ? pptp_echorp_str :
495 			ctrl_msg_type == PPTP_CTRL_MSG_TYPE_OCRP     ? pptp_ocrp_str :
496 			ctrl_msg_type == PPTP_CTRL_MSG_TYPE_ICRP     ? pptp_icrp_str :
497 			ctrl_msg_type == PPTP_CTRL_MSG_TYPE_CDN      ? pptp_cdn_str :
498 			NULL; /* assertion error */
499 		if (dict != NULL)
500 			ND_PRINT((ndo, ":%s", tok2str(dict, "?", *result_code)));
501 	}
502 	ND_PRINT((ndo, ")"));
503 }
504 
505 static void
506 pptp_subaddr_print(netdissect_options *ndo,
507                    const u_char *subaddr)
508 {
509 	ND_PRINT((ndo, " SUB_ADDR(%.64s)", subaddr));
510 }
511 
512 static void
513 pptp_vendor_print(netdissect_options *ndo,
514                   const u_char *vendor)
515 {
516 	ND_PRINT((ndo, " VENDOR(%.64s)", vendor));
517 }
518 
519 /************************************/
520 /* PPTP message print out functions */
521 /************************************/
522 static void
523 pptp_sccrq_print(netdissect_options *ndo,
524                  const u_char *dat)
525 {
526 	struct pptp_msg_sccrq *ptr = (struct pptp_msg_sccrq *)dat;
527 
528 	ND_TCHECK(ptr->proto_ver);
529 	pptp_proto_ver_print(ndo, &ptr->proto_ver);
530 	ND_TCHECK(ptr->reserved1);
531 	ND_TCHECK(ptr->framing_cap);
532 	pptp_framing_cap_print(ndo, &ptr->framing_cap);
533 	ND_TCHECK(ptr->bearer_cap);
534 	pptp_bearer_cap_print(ndo, &ptr->bearer_cap);
535 	ND_TCHECK(ptr->max_channel);
536 	pptp_max_channel_print(ndo, &ptr->max_channel);
537 	ND_TCHECK(ptr->firm_rev);
538 	pptp_firm_rev_print(ndo, &ptr->firm_rev);
539 	ND_TCHECK(ptr->hostname);
540 	pptp_hostname_print(ndo, &ptr->hostname[0]);
541 	ND_TCHECK(ptr->vendor);
542 	pptp_vendor_print(ndo, &ptr->vendor[0]);
543 
544 	return;
545 
546 trunc:
547 	ND_PRINT((ndo, "%s", tstr));
548 }
549 
550 static void
551 pptp_sccrp_print(netdissect_options *ndo,
552                  const u_char *dat)
553 {
554 	struct pptp_msg_sccrp *ptr = (struct pptp_msg_sccrp *)dat;
555 
556 	ND_TCHECK(ptr->proto_ver);
557 	pptp_proto_ver_print(ndo, &ptr->proto_ver);
558 	ND_TCHECK(ptr->result_code);
559 	pptp_result_code_print(ndo, &ptr->result_code, PPTP_CTRL_MSG_TYPE_SCCRP);
560 	ND_TCHECK(ptr->err_code);
561 	pptp_err_code_print(ndo, &ptr->err_code);
562 	ND_TCHECK(ptr->framing_cap);
563 	pptp_framing_cap_print(ndo, &ptr->framing_cap);
564 	ND_TCHECK(ptr->bearer_cap);
565 	pptp_bearer_cap_print(ndo, &ptr->bearer_cap);
566 	ND_TCHECK(ptr->max_channel);
567 	pptp_max_channel_print(ndo, &ptr->max_channel);
568 	ND_TCHECK(ptr->firm_rev);
569 	pptp_firm_rev_print(ndo, &ptr->firm_rev);
570 	ND_TCHECK(ptr->hostname);
571 	pptp_hostname_print(ndo, &ptr->hostname[0]);
572 	ND_TCHECK(ptr->vendor);
573 	pptp_vendor_print(ndo, &ptr->vendor[0]);
574 
575 	return;
576 
577 trunc:
578 	ND_PRINT((ndo, "%s", tstr));
579 }
580 
581 static void
582 pptp_stopccrq_print(netdissect_options *ndo,
583                     const u_char *dat)
584 {
585 	struct pptp_msg_stopccrq *ptr = (struct pptp_msg_stopccrq *)dat;
586 
587 	ND_TCHECK(ptr->reason);
588 	ND_PRINT((ndo, " REASON(%u", ptr->reason));
589 	if (ndo->ndo_vflag) {
590 		switch (ptr->reason) {
591 		case 1:
592 			ND_PRINT((ndo, ":None"));
593 			break;
594 		case 2:
595 			ND_PRINT((ndo, ":Stop-Protocol"));
596 			break;
597 		case 3:
598 			ND_PRINT((ndo, ":Stop-Local-Shutdown"));
599 			break;
600 		default:
601 			ND_PRINT((ndo, ":?"));
602 			break;
603 		}
604 	}
605 	ND_PRINT((ndo, ")"));
606 	ND_TCHECK(ptr->reserved1);
607 	ND_TCHECK(ptr->reserved2);
608 
609 	return;
610 
611 trunc:
612 	ND_PRINT((ndo, "%s", tstr));
613 }
614 
615 static void
616 pptp_stopccrp_print(netdissect_options *ndo,
617                     const u_char *dat)
618 {
619 	struct pptp_msg_stopccrp *ptr = (struct pptp_msg_stopccrp *)dat;
620 
621 	ND_TCHECK(ptr->result_code);
622 	pptp_result_code_print(ndo, &ptr->result_code, PPTP_CTRL_MSG_TYPE_StopCCRP);
623 	ND_TCHECK(ptr->err_code);
624 	pptp_err_code_print(ndo, &ptr->err_code);
625 	ND_TCHECK(ptr->reserved1);
626 
627 	return;
628 
629 trunc:
630 	ND_PRINT((ndo, "%s", tstr));
631 }
632 
633 static void
634 pptp_echorq_print(netdissect_options *ndo,
635                   const u_char *dat)
636 {
637 	struct pptp_msg_echorq *ptr = (struct pptp_msg_echorq *)dat;
638 
639 	ND_TCHECK(ptr->id);
640 	pptp_id_print(ndo, &ptr->id);
641 
642 	return;
643 
644 trunc:
645 	ND_PRINT((ndo, "%s", tstr));
646 }
647 
648 static void
649 pptp_echorp_print(netdissect_options *ndo,
650                   const u_char *dat)
651 {
652 	struct pptp_msg_echorp *ptr = (struct pptp_msg_echorp *)dat;
653 
654 	ND_TCHECK(ptr->id);
655 	pptp_id_print(ndo, &ptr->id);
656 	ND_TCHECK(ptr->result_code);
657 	pptp_result_code_print(ndo, &ptr->result_code, PPTP_CTRL_MSG_TYPE_ECHORP);
658 	ND_TCHECK(ptr->err_code);
659 	pptp_err_code_print(ndo, &ptr->err_code);
660 	ND_TCHECK(ptr->reserved1);
661 
662 	return;
663 
664 trunc:
665 	ND_PRINT((ndo, "%s", tstr));
666 }
667 
668 static void
669 pptp_ocrq_print(netdissect_options *ndo,
670                 const u_char *dat)
671 {
672 	struct pptp_msg_ocrq *ptr = (struct pptp_msg_ocrq *)dat;
673 
674 	ND_TCHECK(ptr->call_id);
675 	pptp_call_id_print(ndo, &ptr->call_id);
676 	ND_TCHECK(ptr->call_ser);
677 	pptp_call_ser_print(ndo, &ptr->call_ser);
678 	ND_TCHECK(ptr->min_bps);
679 	ND_PRINT((ndo, " MIN_BPS(%u)", EXTRACT_32BITS(&ptr->min_bps)));
680 	ND_TCHECK(ptr->max_bps);
681 	ND_PRINT((ndo, " MAX_BPS(%u)", EXTRACT_32BITS(&ptr->max_bps)));
682 	ND_TCHECK(ptr->bearer_type);
683 	pptp_bearer_type_print(ndo, &ptr->bearer_type);
684 	ND_TCHECK(ptr->framing_type);
685 	pptp_framing_type_print(ndo, &ptr->framing_type);
686 	ND_TCHECK(ptr->recv_winsiz);
687 	pptp_recv_winsiz_print(ndo, &ptr->recv_winsiz);
688 	ND_TCHECK(ptr->pkt_proc_delay);
689 	pptp_pkt_proc_delay_print(ndo, &ptr->pkt_proc_delay);
690 	ND_TCHECK(ptr->phone_no_len);
691 	ND_PRINT((ndo, " PHONE_NO_LEN(%u)", EXTRACT_16BITS(&ptr->phone_no_len)));
692 	ND_TCHECK(ptr->reserved1);
693 	ND_TCHECK(ptr->phone_no);
694 	ND_PRINT((ndo, " PHONE_NO(%.64s)", ptr->phone_no));
695 	ND_TCHECK(ptr->subaddr);
696 	pptp_subaddr_print(ndo, &ptr->subaddr[0]);
697 
698 	return;
699 
700 trunc:
701 	ND_PRINT((ndo, "%s", tstr));
702 }
703 
704 static void
705 pptp_ocrp_print(netdissect_options *ndo,
706                 const u_char *dat)
707 {
708 	struct pptp_msg_ocrp *ptr = (struct pptp_msg_ocrp *)dat;
709 
710 	ND_TCHECK(ptr->call_id);
711 	pptp_call_id_print(ndo, &ptr->call_id);
712 	ND_TCHECK(ptr->peer_call_id);
713 	pptp_peer_call_id_print(ndo, &ptr->peer_call_id);
714 	ND_TCHECK(ptr->result_code);
715 	pptp_result_code_print(ndo, &ptr->result_code, PPTP_CTRL_MSG_TYPE_OCRP);
716 	ND_TCHECK(ptr->err_code);
717 	pptp_err_code_print(ndo, &ptr->err_code);
718 	ND_TCHECK(ptr->cause_code);
719 	pptp_cause_code_print(ndo, &ptr->cause_code);
720 	ND_TCHECK(ptr->conn_speed);
721 	pptp_conn_speed_print(ndo, &ptr->conn_speed);
722 	ND_TCHECK(ptr->recv_winsiz);
723 	pptp_recv_winsiz_print(ndo, &ptr->recv_winsiz);
724 	ND_TCHECK(ptr->pkt_proc_delay);
725 	pptp_pkt_proc_delay_print(ndo, &ptr->pkt_proc_delay);
726 	ND_TCHECK(ptr->phy_chan_id);
727 	pptp_phy_chan_id_print(ndo, &ptr->phy_chan_id);
728 
729 	return;
730 
731 trunc:
732 	ND_PRINT((ndo, "%s", tstr));
733 }
734 
735 static void
736 pptp_icrq_print(netdissect_options *ndo,
737                 const u_char *dat)
738 {
739 	struct pptp_msg_icrq *ptr = (struct pptp_msg_icrq *)dat;
740 
741 	ND_TCHECK(ptr->call_id);
742 	pptp_call_id_print(ndo, &ptr->call_id);
743 	ND_TCHECK(ptr->call_ser);
744 	pptp_call_ser_print(ndo, &ptr->call_ser);
745 	ND_TCHECK(ptr->bearer_type);
746 	pptp_bearer_type_print(ndo, &ptr->bearer_type);
747 	ND_TCHECK(ptr->phy_chan_id);
748 	pptp_phy_chan_id_print(ndo, &ptr->phy_chan_id);
749 	ND_TCHECK(ptr->dialed_no_len);
750 	ND_PRINT((ndo, " DIALED_NO_LEN(%u)", EXTRACT_16BITS(&ptr->dialed_no_len)));
751 	ND_TCHECK(ptr->dialing_no_len);
752 	ND_PRINT((ndo, " DIALING_NO_LEN(%u)", EXTRACT_16BITS(&ptr->dialing_no_len)));
753 	ND_TCHECK(ptr->dialed_no);
754 	ND_PRINT((ndo, " DIALED_NO(%.64s)", ptr->dialed_no));
755 	ND_TCHECK(ptr->dialing_no);
756 	ND_PRINT((ndo, " DIALING_NO(%.64s)", ptr->dialing_no));
757 	ND_TCHECK(ptr->subaddr);
758 	pptp_subaddr_print(ndo, &ptr->subaddr[0]);
759 
760 	return;
761 
762 trunc:
763 	ND_PRINT((ndo, "%s", tstr));
764 }
765 
766 static void
767 pptp_icrp_print(netdissect_options *ndo,
768                 const u_char *dat)
769 {
770 	struct pptp_msg_icrp *ptr = (struct pptp_msg_icrp *)dat;
771 
772 	ND_TCHECK(ptr->call_id);
773 	pptp_call_id_print(ndo, &ptr->call_id);
774 	ND_TCHECK(ptr->peer_call_id);
775 	pptp_peer_call_id_print(ndo, &ptr->peer_call_id);
776 	ND_TCHECK(ptr->result_code);
777 	pptp_result_code_print(ndo, &ptr->result_code, PPTP_CTRL_MSG_TYPE_ICRP);
778 	ND_TCHECK(ptr->err_code);
779 	pptp_err_code_print(ndo, &ptr->err_code);
780 	ND_TCHECK(ptr->recv_winsiz);
781 	pptp_recv_winsiz_print(ndo, &ptr->recv_winsiz);
782 	ND_TCHECK(ptr->pkt_proc_delay);
783 	pptp_pkt_proc_delay_print(ndo, &ptr->pkt_proc_delay);
784 	ND_TCHECK(ptr->reserved1);
785 
786 	return;
787 
788 trunc:
789 	ND_PRINT((ndo, "%s", tstr));
790 }
791 
792 static void
793 pptp_iccn_print(netdissect_options *ndo,
794                 const u_char *dat)
795 {
796 	struct pptp_msg_iccn *ptr = (struct pptp_msg_iccn *)dat;
797 
798 	ND_TCHECK(ptr->peer_call_id);
799 	pptp_peer_call_id_print(ndo, &ptr->peer_call_id);
800 	ND_TCHECK(ptr->reserved1);
801 	ND_TCHECK(ptr->conn_speed);
802 	pptp_conn_speed_print(ndo, &ptr->conn_speed);
803 	ND_TCHECK(ptr->recv_winsiz);
804 	pptp_recv_winsiz_print(ndo, &ptr->recv_winsiz);
805 	ND_TCHECK(ptr->pkt_proc_delay);
806 	pptp_pkt_proc_delay_print(ndo, &ptr->pkt_proc_delay);
807 	ND_TCHECK(ptr->framing_type);
808 	pptp_framing_type_print(ndo, &ptr->framing_type);
809 
810 	return;
811 
812 trunc:
813 	ND_PRINT((ndo, "%s", tstr));
814 }
815 
816 static void
817 pptp_ccrq_print(netdissect_options *ndo,
818                 const u_char *dat)
819 {
820 	struct pptp_msg_ccrq *ptr = (struct pptp_msg_ccrq *)dat;
821 
822 	ND_TCHECK(ptr->call_id);
823 	pptp_call_id_print(ndo, &ptr->call_id);
824 	ND_TCHECK(ptr->reserved1);
825 
826 	return;
827 
828 trunc:
829 	ND_PRINT((ndo, "%s", tstr));
830 }
831 
832 static void
833 pptp_cdn_print(netdissect_options *ndo,
834                const u_char *dat)
835 {
836 	struct pptp_msg_cdn *ptr = (struct pptp_msg_cdn *)dat;
837 
838 	ND_TCHECK(ptr->call_id);
839 	pptp_call_id_print(ndo, &ptr->call_id);
840 	ND_TCHECK(ptr->result_code);
841 	pptp_result_code_print(ndo, &ptr->result_code, PPTP_CTRL_MSG_TYPE_CDN);
842 	ND_TCHECK(ptr->err_code);
843 	pptp_err_code_print(ndo, &ptr->err_code);
844 	ND_TCHECK(ptr->cause_code);
845 	pptp_cause_code_print(ndo, &ptr->cause_code);
846 	ND_TCHECK(ptr->reserved1);
847 	ND_TCHECK(ptr->call_stats);
848 	ND_PRINT((ndo, " CALL_STATS(%.128s)", ptr->call_stats));
849 
850 	return;
851 
852 trunc:
853 	ND_PRINT((ndo, "%s", tstr));
854 }
855 
856 static void
857 pptp_wen_print(netdissect_options *ndo,
858                const u_char *dat)
859 {
860 	struct pptp_msg_wen *ptr = (struct pptp_msg_wen *)dat;
861 
862 	ND_TCHECK(ptr->peer_call_id);
863 	pptp_peer_call_id_print(ndo, &ptr->peer_call_id);
864 	ND_TCHECK(ptr->reserved1);
865 	ND_TCHECK(ptr->crc_err);
866 	ND_PRINT((ndo, " CRC_ERR(%u)", EXTRACT_32BITS(&ptr->crc_err)));
867 	ND_TCHECK(ptr->framing_err);
868 	ND_PRINT((ndo, " FRAMING_ERR(%u)", EXTRACT_32BITS(&ptr->framing_err)));
869 	ND_TCHECK(ptr->hardware_overrun);
870 	ND_PRINT((ndo, " HARDWARE_OVERRUN(%u)", EXTRACT_32BITS(&ptr->hardware_overrun)));
871 	ND_TCHECK(ptr->buffer_overrun);
872 	ND_PRINT((ndo, " BUFFER_OVERRUN(%u)", EXTRACT_32BITS(&ptr->buffer_overrun)));
873 	ND_TCHECK(ptr->timeout_err);
874 	ND_PRINT((ndo, " TIMEOUT_ERR(%u)", EXTRACT_32BITS(&ptr->timeout_err)));
875 	ND_TCHECK(ptr->align_err);
876 	ND_PRINT((ndo, " ALIGN_ERR(%u)", EXTRACT_32BITS(&ptr->align_err)));
877 
878 	return;
879 
880 trunc:
881 	ND_PRINT((ndo, "%s", tstr));
882 }
883 
884 static void
885 pptp_sli_print(netdissect_options *ndo,
886                const u_char *dat)
887 {
888 	struct pptp_msg_sli *ptr = (struct pptp_msg_sli *)dat;
889 
890 	ND_TCHECK(ptr->peer_call_id);
891 	pptp_peer_call_id_print(ndo, &ptr->peer_call_id);
892 	ND_TCHECK(ptr->reserved1);
893 	ND_TCHECK(ptr->send_accm);
894 	ND_PRINT((ndo, " SEND_ACCM(0x%08x)", EXTRACT_32BITS(&ptr->send_accm)));
895 	ND_TCHECK(ptr->recv_accm);
896 	ND_PRINT((ndo, " RECV_ACCM(0x%08x)", EXTRACT_32BITS(&ptr->recv_accm)));
897 
898 	return;
899 
900 trunc:
901 	ND_PRINT((ndo, "%s", tstr));
902 }
903 
904 void
905 pptp_print(netdissect_options *ndo,
906            const u_char *dat)
907 {
908 	const struct pptp_hdr *hdr;
909 	uint32_t mc;
910 	uint16_t ctrl_msg_type;
911 
912 	ND_PRINT((ndo, ": pptp"));
913 
914 	hdr = (struct pptp_hdr *)dat;
915 
916 	ND_TCHECK(hdr->length);
917 	if (ndo->ndo_vflag) {
918 		ND_PRINT((ndo, " Length=%u", EXTRACT_16BITS(&hdr->length)));
919 	}
920 	ND_TCHECK(hdr->msg_type);
921 	if (ndo->ndo_vflag) {
922 		switch(EXTRACT_16BITS(&hdr->msg_type)) {
923 		case PPTP_MSG_TYPE_CTRL:
924 			ND_PRINT((ndo, " CTRL-MSG"));
925 			break;
926 		case PPTP_MSG_TYPE_MGMT:
927 			ND_PRINT((ndo, " MGMT-MSG"));
928 			break;
929 		default:
930 			ND_PRINT((ndo, " UNKNOWN-MSG-TYPE"));
931 			break;
932 		}
933 	}
934 
935 	ND_TCHECK(hdr->magic_cookie);
936 	mc = EXTRACT_32BITS(&hdr->magic_cookie);
937 	if (mc != PPTP_MAGIC_COOKIE) {
938 		ND_PRINT((ndo, " UNEXPECTED Magic-Cookie!!(%08x)", mc));
939 	}
940 	if (ndo->ndo_vflag || mc != PPTP_MAGIC_COOKIE) {
941 		ND_PRINT((ndo, " Magic-Cookie=%08x", mc));
942 	}
943 	ND_TCHECK(hdr->ctrl_msg_type);
944 	ctrl_msg_type = EXTRACT_16BITS(&hdr->ctrl_msg_type);
945 	if (ctrl_msg_type < PPTP_MAX_MSGTYPE_INDEX) {
946 		ND_PRINT((ndo, " CTRL_MSGTYPE=%s",
947 		       pptp_message_type_string[ctrl_msg_type]));
948 	} else {
949 		ND_PRINT((ndo, " UNKNOWN_CTRL_MSGTYPE(%u)", ctrl_msg_type));
950 	}
951 	ND_TCHECK(hdr->reserved0);
952 
953 	dat += 12;
954 
955 	switch(ctrl_msg_type) {
956 	case PPTP_CTRL_MSG_TYPE_SCCRQ:
957 		pptp_sccrq_print(ndo, dat);
958 		break;
959 	case PPTP_CTRL_MSG_TYPE_SCCRP:
960 		pptp_sccrp_print(ndo, dat);
961 		break;
962 	case PPTP_CTRL_MSG_TYPE_StopCCRQ:
963 		pptp_stopccrq_print(ndo, dat);
964 		break;
965 	case PPTP_CTRL_MSG_TYPE_StopCCRP:
966 		pptp_stopccrp_print(ndo, dat);
967 		break;
968 	case PPTP_CTRL_MSG_TYPE_ECHORQ:
969 		pptp_echorq_print(ndo, dat);
970 		break;
971 	case PPTP_CTRL_MSG_TYPE_ECHORP:
972 		pptp_echorp_print(ndo, dat);
973 		break;
974 	case PPTP_CTRL_MSG_TYPE_OCRQ:
975 		pptp_ocrq_print(ndo, dat);
976 		break;
977 	case PPTP_CTRL_MSG_TYPE_OCRP:
978 		pptp_ocrp_print(ndo, dat);
979 		break;
980 	case PPTP_CTRL_MSG_TYPE_ICRQ:
981 		pptp_icrq_print(ndo, dat);
982 		break;
983 	case PPTP_CTRL_MSG_TYPE_ICRP:
984 		pptp_icrp_print(ndo, dat);
985 		break;
986 	case PPTP_CTRL_MSG_TYPE_ICCN:
987 		pptp_iccn_print(ndo, dat);
988 		break;
989 	case PPTP_CTRL_MSG_TYPE_CCRQ:
990 		pptp_ccrq_print(ndo, dat);
991 		break;
992 	case PPTP_CTRL_MSG_TYPE_CDN:
993 		pptp_cdn_print(ndo, dat);
994 		break;
995 	case PPTP_CTRL_MSG_TYPE_WEN:
996 		pptp_wen_print(ndo, dat);
997 		break;
998 	case PPTP_CTRL_MSG_TYPE_SLI:
999 		pptp_sli_print(ndo, dat);
1000 		break;
1001 	default:
1002 		/* do nothing */
1003 		break;
1004 	}
1005 
1006 	return;
1007 
1008 trunc:
1009 	ND_PRINT((ndo, "%s", tstr));
1010 }
1011