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