1218885Sdim/*
2218885Sdim * Copyright (c) 1991, 1993, 1994, 1995, 1996, 1997
3218885Sdim *      The Regents of the University of California.  All rights reserved.
4218885Sdim *
5218885Sdim * Redistribution and use in source and binary forms, with or without
6218885Sdim * modification, are permitted provided that: (1) source code distributions
7218885Sdim * retain the above copyright notice and this paragraph in its entirety, (2)
8218885Sdim * distributions including binary code include the above copyright notice and
9218885Sdim * this paragraph in its entirety in the documentation or other materials
10218885Sdim * provided with the distribution, and (3) all advertising materials mentioning
11218885Sdim * features or use of this software display the following acknowledgement:
12218885Sdim * ``This product includes software developed by the University of California,
13218885Sdim * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
14252723Sdim * the University nor the names of its contributors may be used to endorse
15252723Sdim * or promote products derived from this software without specific prior
16252723Sdim * written permission.
17218885Sdim * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
18218885Sdim * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
19218885Sdim * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
20218885Sdim *
21218885Sdim * PPTP support contributed by Motonori Shindo (mshindo@mshindo.net)
22218885Sdim */
23218885Sdim
24218885Sdim/* \summary: Point-to-Point Tunnelling Protocol (PPTP) printer */
25218885Sdim
26218885Sdim/* specification: RFC 2637 */
27218885Sdim
28218885Sdim#ifdef HAVE_CONFIG_H
29218885Sdim#include <config.h>
30218885Sdim#endif
31218885Sdim
32218885Sdim#include "netdissect-stdinc.h"
33218885Sdim
34218885Sdim#include "netdissect.h"
35218885Sdim#include "extract.h"
36218885Sdim
37218885Sdim
38221345Sdim#define PPTP_MSG_TYPE_CTRL	1	/* Control Message */
39218885Sdim#define PPTP_MSG_TYPE_MGMT	2	/* Management Message (currently not used */
40218885Sdim#define PPTP_MAGIC_COOKIE	0x1a2b3c4d	/* for sanity check */
41218885Sdim
42218885Sdim#define PPTP_CTRL_MSG_TYPE_SCCRQ	1
43218885Sdim#define PPTP_CTRL_MSG_TYPE_SCCRP	2
44221345Sdim#define PPTP_CTRL_MSG_TYPE_StopCCRQ	3
45218885Sdim#define PPTP_CTRL_MSG_TYPE_StopCCRP	4
46218885Sdim#define PPTP_CTRL_MSG_TYPE_ECHORQ	5
47218885Sdim#define PPTP_CTRL_MSG_TYPE_ECHORP	6
48218885Sdim#define PPTP_CTRL_MSG_TYPE_OCRQ		7
49218885Sdim#define PPTP_CTRL_MSG_TYPE_OCRP		8
50218885Sdim#define PPTP_CTRL_MSG_TYPE_ICRQ		9
51218885Sdim#define PPTP_CTRL_MSG_TYPE_ICRP		10
52218885Sdim#define PPTP_CTRL_MSG_TYPE_ICCN		11
53218885Sdim#define PPTP_CTRL_MSG_TYPE_CCRQ		12
54218885Sdim#define PPTP_CTRL_MSG_TYPE_CDN		13
55218885Sdim#define PPTP_CTRL_MSG_TYPE_WEN		14
56218885Sdim#define PPTP_CTRL_MSG_TYPE_SLI		15
57218885Sdim
58218885Sdim#define PPTP_FRAMING_CAP_ASYNC_MASK	0x00000001      /* Asynchronous */
59218885Sdim#define PPTP_FRAMING_CAP_SYNC_MASK	0x00000002      /* Synchronous */
60218885Sdim
61218885Sdim#define PPTP_BEARER_CAP_ANALOG_MASK	0x00000001      /* Analog */
62218885Sdim#define PPTP_BEARER_CAP_DIGITAL_MASK	0x00000002      /* Digital */
63218885Sdim
64218885Sdimstatic const char *pptp_message_type_string[] = {
65218885Sdim	"NOT_DEFINED",		/* 0  Not defined in the RFC2637 */
66218885Sdim	"SCCRQ",		/* 1  Start-Control-Connection-Request */
67218885Sdim	"SCCRP",		/* 2  Start-Control-Connection-Reply */
68218885Sdim	"StopCCRQ",		/* 3  Stop-Control-Connection-Request */
69218885Sdim	"StopCCRP",		/* 4  Stop-Control-Connection-Reply */
70218885Sdim	"ECHORQ",		/* 5  Echo Request */
71218885Sdim	"ECHORP",		/* 6  Echo Reply */
72218885Sdim
73218885Sdim	"OCRQ",			/* 7  Outgoing-Call-Request */
74218885Sdim	"OCRP",			/* 8  Outgoing-Call-Reply */
75218885Sdim	"ICRQ",			/* 9  Incoming-Call-Request */
76218885Sdim	"ICRP",			/* 10 Incoming-Call-Reply */
77218885Sdim	"ICCN",			/* 11 Incoming-Call-Connected */
78218885Sdim	"CCRQ",			/* 12 Call-Clear-Request */
79218885Sdim	"CDN",			/* 13 Call-Disconnect-Notify */
80218885Sdim
81218885Sdim	"WEN",			/* 14 WAN-Error-Notify */
82218885Sdim
83218885Sdim	"SLI"			/* 15 Set-Link-Info */
84218885Sdim#define PPTP_MAX_MSGTYPE_INDEX	16
85252723Sdim};
86252723Sdim
87252723Sdim/* common for all PPTP control messages */
88218885Sdimstruct pptp_hdr {
89218885Sdim	nd_uint16_t length;
90218885Sdim	nd_uint16_t msg_type;
91218885Sdim	nd_uint32_t magic_cookie;
92218885Sdim	nd_uint16_t ctrl_msg_type;
93218885Sdim	nd_uint16_t reserved0;
94218885Sdim};
95218885Sdim
96218885Sdimstruct pptp_msg_sccrq {
97218885Sdim	nd_uint16_t proto_ver;
98218885Sdim	nd_uint16_t reserved1;
99218885Sdim	nd_uint32_t framing_cap;
100218885Sdim	nd_uint32_t bearer_cap;
101218885Sdim	nd_uint16_t max_channel;
102218885Sdim	nd_uint16_t firm_rev;
103218885Sdim	nd_byte     hostname[64];
104218885Sdim	nd_byte     vendor[64];
105218885Sdim};
106218885Sdim
107218885Sdimstruct pptp_msg_sccrp {
108218885Sdim	nd_uint16_t proto_ver;
109218885Sdim	nd_uint8_t  result_code;
110218885Sdim	nd_uint8_t  err_code;
111218885Sdim	nd_uint32_t framing_cap;
112218885Sdim	nd_uint32_t bearer_cap;
113218885Sdim	nd_uint16_t max_channel;
114218885Sdim	nd_uint16_t firm_rev;
115218885Sdim	nd_byte     hostname[64];
116218885Sdim	nd_byte     vendor[64];
117218885Sdim};
118218885Sdim
119218885Sdimstruct pptp_msg_stopccrq {
120218885Sdim	nd_uint8_t  reason;
121218885Sdim	nd_uint8_t  reserved1;
122218885Sdim	nd_uint16_t reserved2;
123218885Sdim};
124218885Sdim
125218885Sdimstruct pptp_msg_stopccrp {
126218885Sdim	nd_uint8_t  result_code;
127218885Sdim	nd_uint8_t  err_code;
128218885Sdim	nd_uint16_t reserved1;
129218885Sdim};
130218885Sdim
131218885Sdimstruct pptp_msg_echorq {
132218885Sdim	nd_uint32_t id;
133218885Sdim};
134218885Sdim
135218885Sdimstruct pptp_msg_echorp {
136218885Sdim	nd_uint32_t id;
137218885Sdim	nd_uint8_t  result_code;
138218885Sdim	nd_uint8_t  err_code;
139218885Sdim	nd_uint16_t reserved1;
140218885Sdim};
141218885Sdim
142218885Sdimstruct pptp_msg_ocrq {
143218885Sdim	nd_uint16_t call_id;
144218885Sdim	nd_uint16_t call_ser;
145218885Sdim	nd_uint32_t min_bps;
146218885Sdim	nd_uint32_t max_bps;
147218885Sdim	nd_uint32_t bearer_type;
148218885Sdim	nd_uint32_t framing_type;
149218885Sdim	nd_uint16_t recv_winsiz;
150218885Sdim	nd_uint16_t pkt_proc_delay;
151218885Sdim	nd_uint16_t phone_no_len;
152218885Sdim	nd_uint16_t reserved1;
153218885Sdim	nd_byte     phone_no[64];
154218885Sdim	nd_byte     subaddr[64];
155218885Sdim};
156218885Sdim
157218885Sdimstruct pptp_msg_ocrp {
158218885Sdim	nd_uint16_t call_id;
159218885Sdim	nd_uint16_t peer_call_id;
160218885Sdim	nd_uint8_t  result_code;
161218885Sdim	nd_uint8_t  err_code;
162218885Sdim	nd_uint16_t cause_code;
163218885Sdim	nd_uint32_t conn_speed;
164218885Sdim	nd_uint16_t recv_winsiz;
165218885Sdim	nd_uint16_t pkt_proc_delay;
166218885Sdim	nd_uint32_t phy_chan_id;
167218885Sdim};
168218885Sdim
169245431Sdimstruct pptp_msg_icrq {
170218885Sdim	nd_uint16_t call_id;
171218885Sdim	nd_uint16_t call_ser;
172218885Sdim	nd_uint32_t bearer_type;
173218885Sdim	nd_uint32_t phy_chan_id;
174218885Sdim	nd_uint16_t dialed_no_len;
175218885Sdim	nd_uint16_t dialing_no_len;
176218885Sdim	nd_byte     dialed_no[64];		/* DNIS */
177245431Sdim	nd_byte     dialing_no[64];		/* CLID */
178218885Sdim	nd_byte     subaddr[64];
179218885Sdim};
180218885Sdim
181218885Sdimstruct pptp_msg_icrp {
182218885Sdim	nd_uint16_t call_id;
183218885Sdim	nd_uint16_t peer_call_id;
184218885Sdim	nd_uint8_t  result_code;
185218885Sdim	nd_uint8_t  err_code;
186218885Sdim	nd_uint16_t recv_winsiz;
187218885Sdim	nd_uint16_t pkt_proc_delay;
188218885Sdim	nd_uint16_t reserved1;
189218885Sdim};
190218885Sdim
191218885Sdimstruct pptp_msg_iccn {
192218885Sdim	nd_uint16_t peer_call_id;
193218885Sdim	nd_uint16_t reserved1;
194218885Sdim	nd_uint32_t conn_speed;
195218885Sdim	nd_uint16_t recv_winsiz;
196218885Sdim	nd_uint16_t pkt_proc_delay;
197218885Sdim	nd_uint32_t framing_type;
198218885Sdim};
199218885Sdim
200218885Sdimstruct pptp_msg_ccrq {
201218885Sdim	nd_uint16_t call_id;
202218885Sdim	nd_uint16_t reserved1;
203218885Sdim};
204218885Sdim
205218885Sdimstruct pptp_msg_cdn {
206218885Sdim	nd_uint16_t call_id;
207218885Sdim	nd_uint8_t  result_code;
208218885Sdim	nd_uint8_t  err_code;
209218885Sdim	nd_uint16_t cause_code;
210218885Sdim	nd_uint16_t reserved1;
211218885Sdim	nd_byte     call_stats[128];
212218885Sdim};
213218885Sdim
214218885Sdimstruct pptp_msg_wen {
215218885Sdim	nd_uint16_t peer_call_id;
216218885Sdim	nd_uint16_t reserved1;
217218885Sdim	nd_uint32_t crc_err;
218218885Sdim	nd_uint32_t framing_err;
219218885Sdim	nd_uint32_t hardware_overrun;
220218885Sdim	nd_uint32_t buffer_overrun;
221218885Sdim	nd_uint32_t timeout_err;
222218885Sdim	nd_uint32_t align_err;
223218885Sdim};
224218885Sdim
225218885Sdimstruct pptp_msg_sli {
226218885Sdim	nd_uint16_t peer_call_id;
227218885Sdim	nd_uint16_t reserved1;
228218885Sdim	nd_uint32_t send_accm;
229218885Sdim	nd_uint32_t recv_accm;
230218885Sdim};
231218885Sdim
232218885Sdim/* attributes that appear more than once in above messages:
233218885Sdim
234218885Sdim   Number of
235218885Sdim   occurrence    attributes
236218885Sdim  --------------------------------------
237218885Sdim      2         uint32_t bearer_cap;
238218885Sdim      2         uint32_t bearer_type;
239218885Sdim      6         uint16_t call_id;
240218885Sdim      2         uint16_t call_ser;
241218885Sdim      2         uint16_t cause_code;
242218885Sdim      2         uint32_t conn_speed;
243252723Sdim      6         uint8_t err_code;
244218885Sdim      2         uint16_t firm_rev;
245218885Sdim      2         uint32_t framing_cap;
246218885Sdim      2         uint32_t framing_type;
247218885Sdim      2         u_char hostname[64];
248218885Sdim      2         uint32_t id;
249218885Sdim      2         uint16_t max_channel;
250218885Sdim      5         uint16_t peer_call_id;
251252723Sdim      2         uint32_t phy_chan_id;
252218885Sdim      4         uint16_t pkt_proc_delay;
253218885Sdim      2         uint16_t proto_ver;
254218885Sdim      4         uint16_t recv_winsiz;
255218885Sdim      2         uint8_t reserved1;
256263509Sdim      9         uint16_t reserved1;
257263509Sdim      6         uint8_t result_code;
258218885Sdim      2         u_char subaddr[64];
259263509Sdim      2         u_char vendor[64];
260218885Sdim
261218885Sdim  so I will prepare print out functions for these attributes (except for
262218885Sdim  reserved*).
263218885Sdim*/
264218885Sdim
265218885Sdim#define PRINT_RESERVED_IF_NOT_ZERO_1(reserved) \
266218885Sdim        if (GET_U_1(reserved)) \
267218885Sdim		ND_PRINT(" [ERROR: reserved=%u must be zero]", \
268252723Sdim			 GET_U_1(reserved));
269218885Sdim
270218885Sdim#define PRINT_RESERVED_IF_NOT_ZERO_2(reserved) \
271218885Sdim        if (GET_BE_U_2(reserved)) \
272218885Sdim		ND_PRINT(" [ERROR: reserved=%u must be zero]", \
273218885Sdim			 GET_BE_U_2(reserved));
274218885Sdim
275218885Sdim/******************************************/
276218885Sdim/* Attribute-specific print out functions */
277218885Sdim/******************************************/
278218885Sdim
279218885Sdimstatic void
280218885Sdimpptp_bearer_cap_print(netdissect_options *ndo,
281218885Sdim                      const nd_uint32_t bearer_cap)
282218885Sdim{
283218885Sdim	ND_PRINT(" BEARER_CAP(%s%s)",
284218885Sdim	          GET_BE_U_4(bearer_cap) & PPTP_BEARER_CAP_DIGITAL_MASK ? "D" : "",
285218885Sdim	          GET_BE_U_4(bearer_cap) & PPTP_BEARER_CAP_ANALOG_MASK ? "A" : "");
286218885Sdim}
287218885Sdim
288218885Sdimstatic const struct tok pptp_btype_str[] = {
289218885Sdim	{ 1, "A"   }, /* Analog */
290218885Sdim	{ 2, "D"   }, /* Digital */
291218885Sdim	{ 3, "Any" },
292218885Sdim	{ 0, NULL }
293218885Sdim};
294218885Sdim
295218885Sdimstatic void
296218885Sdimpptp_bearer_type_print(netdissect_options *ndo,
297218885Sdim                       const nd_uint32_t bearer_type)
298218885Sdim{
299218885Sdim	ND_PRINT(" BEARER_TYPE(%s)",
300218885Sdim	          tok2str(pptp_btype_str, "?", GET_BE_U_4(bearer_type)));
301218885Sdim}
302218885Sdim
303218885Sdimstatic void
304218885Sdimpptp_call_id_print(netdissect_options *ndo,
305218885Sdim                   const nd_uint16_t call_id)
306218885Sdim{
307218885Sdim	ND_PRINT(" CALL_ID(%u)", GET_BE_U_2(call_id));
308218885Sdim}
309218885Sdim
310218885Sdimstatic void
311218885Sdimpptp_call_ser_print(netdissect_options *ndo,
312218885Sdim                    const nd_uint16_t call_ser)
313218885Sdim{
314218885Sdim	ND_PRINT(" CALL_SER_NUM(%u)", GET_BE_U_2(call_ser));
315218885Sdim}
316218885Sdim
317218885Sdimstatic void
318218885Sdimpptp_cause_code_print(netdissect_options *ndo,
319218885Sdim                      const nd_uint16_t cause_code)
320218885Sdim{
321218885Sdim	ND_PRINT(" CAUSE_CODE(%u)", GET_BE_U_2(cause_code));
322218885Sdim}
323218885Sdim
324218885Sdimstatic void
325218885Sdimpptp_conn_speed_print(netdissect_options *ndo,
326218885Sdim                      const nd_uint32_t conn_speed)
327218885Sdim{
328218885Sdim	ND_PRINT(" CONN_SPEED(%u)", GET_BE_U_4(conn_speed));
329218885Sdim}
330218885Sdim
331218885Sdimstatic const struct tok pptp_errcode_str[] = {
332218885Sdim	{ 0, "None"          },
333218885Sdim	{ 1, "Not-Connected" },
334218885Sdim	{ 2, "Bad-Format"    },
335252723Sdim	{ 3, "Bad-Value"     },
336218885Sdim	{ 4, "No-Resource"   },
337218885Sdim	{ 5, "Bad-Call-ID"   },
338218885Sdim	{ 6, "PAC-Error"     },
339218885Sdim	{ 0, NULL }
340218885Sdim};
341218885Sdim
342218885Sdimstatic void
343218885Sdimpptp_err_code_print(netdissect_options *ndo,
344252723Sdim                    const nd_uint8_t err_code)
345218885Sdim{
346218885Sdim	ND_PRINT(" ERR_CODE(%u", GET_U_1(err_code));
347218885Sdim	if (ndo->ndo_vflag) {
348218885Sdim		ND_PRINT(":%s",
349218885Sdim			 tok2str(pptp_errcode_str, "?", GET_U_1(err_code)));
350218885Sdim	}
351218885Sdim	ND_PRINT(")");
352218885Sdim}
353218885Sdim
354218885Sdimstatic void
355218885Sdimpptp_firm_rev_print(netdissect_options *ndo,
356218885Sdim                    const nd_uint16_t firm_rev)
357218885Sdim{
358218885Sdim	ND_PRINT(" FIRM_REV(%u)", GET_BE_U_2(firm_rev));
359218885Sdim}
360218885Sdim
361218885Sdimstatic void
362218885Sdimpptp_framing_cap_print(netdissect_options *ndo,
363218885Sdim                       const nd_uint32_t framing_cap)
364252723Sdim{
365252723Sdim	ND_PRINT(" FRAME_CAP(");
366252723Sdim	if (GET_BE_U_4(framing_cap) & PPTP_FRAMING_CAP_ASYNC_MASK) {
367218885Sdim                ND_PRINT("A");		/* Async */
368218885Sdim        }
369218885Sdim        if (GET_BE_U_4(framing_cap) & PPTP_FRAMING_CAP_SYNC_MASK) {
370218885Sdim                ND_PRINT("S");		/* Sync */
371218885Sdim        }
372218885Sdim	ND_PRINT(")");
373218885Sdim}
374218885Sdim
375218885Sdimstatic const struct tok pptp_ftype_str[] = {
376218885Sdim	{ 1, "A" }, /* Async */
377218885Sdim	{ 2, "S" }, /* Sync */
378218885Sdim	{ 3, "E" }, /* Either */
379218885Sdim	{ 0, NULL }
380218885Sdim};
381218885Sdim
382218885Sdimstatic void
383218885Sdimpptp_framing_type_print(netdissect_options *ndo,
384218885Sdim                        const nd_uint32_t framing_type)
385218885Sdim{
386218885Sdim	ND_PRINT(" FRAME_TYPE(%s)",
387	          tok2str(pptp_ftype_str, "?", GET_BE_U_4(framing_type)));
388}
389
390static void
391pptp_hostname_print(netdissect_options *ndo,
392                    const u_char *hostname)
393{
394	ND_PRINT(" HOSTNAME(");
395	nd_printjnp(ndo, hostname, 64);
396	ND_PRINT(")");
397}
398
399static void
400pptp_id_print(netdissect_options *ndo,
401              const nd_uint32_t id)
402{
403	ND_PRINT(" ID(%u)", GET_BE_U_4(id));
404}
405
406static void
407pptp_max_channel_print(netdissect_options *ndo,
408                       const nd_uint16_t max_channel)
409{
410	ND_PRINT(" MAX_CHAN(%u)", GET_BE_U_2(max_channel));
411}
412
413static void
414pptp_peer_call_id_print(netdissect_options *ndo,
415                        const nd_uint16_t peer_call_id)
416{
417	ND_PRINT(" PEER_CALL_ID(%u)", GET_BE_U_2(peer_call_id));
418}
419
420static void
421pptp_phy_chan_id_print(netdissect_options *ndo,
422                       const nd_uint32_t phy_chan_id)
423{
424	ND_PRINT(" PHY_CHAN_ID(%u)", GET_BE_U_4(phy_chan_id));
425}
426
427static void
428pptp_pkt_proc_delay_print(netdissect_options *ndo,
429                          const nd_uint16_t pkt_proc_delay)
430{
431	ND_PRINT(" PROC_DELAY(%u)", GET_BE_U_2(pkt_proc_delay));
432}
433
434static void
435pptp_proto_ver_print(netdissect_options *ndo,
436                     const nd_uint16_t proto_ver)
437{
438	ND_PRINT(" PROTO_VER(%u.%u)",	/* Version.Revision */
439	       GET_BE_U_2(proto_ver) >> 8,
440	       GET_BE_U_2(proto_ver) & 0xff);
441}
442
443static void
444pptp_recv_winsiz_print(netdissect_options *ndo,
445                       const nd_uint16_t recv_winsiz)
446{
447	ND_PRINT(" RECV_WIN(%u)", GET_BE_U_2(recv_winsiz));
448}
449
450static const struct tok pptp_scrrp_str[] = {
451	{ 1, "Successful channel establishment"                           },
452	{ 2, "General error"                                              },
453	{ 3, "Command channel already exists"                             },
454	{ 4, "Requester is not authorized to establish a command channel" },
455	{ 5, "The protocol version of the requester is not supported"     },
456	{ 0, NULL }
457};
458
459static const struct tok pptp_echorp_str[] = {
460	{ 1, "OK" },
461	{ 2, "General Error" },
462	{ 0, NULL }
463};
464
465static const struct tok pptp_ocrp_str[] = {
466	{ 1, "Connected"     },
467	{ 2, "General Error" },
468	{ 3, "No Carrier"    },
469	{ 4, "Busy"          },
470	{ 5, "No Dial Tone"  },
471	{ 6, "Time-out"      },
472	{ 7, "Do Not Accept" },
473	{ 0, NULL }
474};
475
476static const struct tok pptp_icrp_str[] = {
477	{ 1, "Connect"       },
478	{ 2, "General Error" },
479	{ 3, "Do Not Accept" },
480	{ 0, NULL }
481};
482
483static const struct tok pptp_cdn_str[] = {
484	{ 1, "Lost Carrier"   },
485	{ 2, "General Error"  },
486	{ 3, "Admin Shutdown" },
487	{ 4, "Request"        },
488	{ 0, NULL }
489};
490
491static void
492pptp_result_code_print(netdissect_options *ndo,
493                       const nd_uint8_t result_code, int ctrl_msg_type)
494{
495	ND_PRINT(" RESULT_CODE(%u", GET_U_1(result_code));
496	if (ndo->ndo_vflag) {
497		const struct tok *dict =
498			ctrl_msg_type == PPTP_CTRL_MSG_TYPE_SCCRP    ? pptp_scrrp_str :
499			ctrl_msg_type == PPTP_CTRL_MSG_TYPE_StopCCRP ? pptp_echorp_str :
500			ctrl_msg_type == PPTP_CTRL_MSG_TYPE_ECHORP   ? pptp_echorp_str :
501			ctrl_msg_type == PPTP_CTRL_MSG_TYPE_OCRP     ? pptp_ocrp_str :
502			ctrl_msg_type == PPTP_CTRL_MSG_TYPE_ICRP     ? pptp_icrp_str :
503			ctrl_msg_type == PPTP_CTRL_MSG_TYPE_CDN      ? pptp_cdn_str :
504			NULL; /* assertion error */
505		if (dict != NULL)
506			ND_PRINT(":%s",
507				 tok2str(dict, "?", GET_U_1(result_code)));
508	}
509	ND_PRINT(")");
510}
511
512static void
513pptp_subaddr_print(netdissect_options *ndo,
514                   const u_char *subaddr)
515{
516	ND_PRINT(" SUB_ADDR(");
517	nd_printjnp(ndo, subaddr, 64);
518	ND_PRINT(")");
519}
520
521static void
522pptp_vendor_print(netdissect_options *ndo,
523                  const u_char *vendor)
524{
525	ND_PRINT(" VENDOR(");
526	nd_printjnp(ndo, vendor, 64);
527	ND_PRINT(")");
528}
529
530/************************************/
531/* PPTP message print out functions */
532/************************************/
533static void
534pptp_sccrq_print(netdissect_options *ndo,
535                 const u_char *dat)
536{
537	const struct pptp_msg_sccrq *ptr = (const struct pptp_msg_sccrq *)dat;
538
539	pptp_proto_ver_print(ndo, ptr->proto_ver);
540	PRINT_RESERVED_IF_NOT_ZERO_2(ptr->reserved1);
541	pptp_framing_cap_print(ndo, ptr->framing_cap);
542	pptp_bearer_cap_print(ndo, ptr->bearer_cap);
543	pptp_max_channel_print(ndo, ptr->max_channel);
544	pptp_firm_rev_print(ndo, ptr->firm_rev);
545	pptp_hostname_print(ndo, ptr->hostname);
546	pptp_vendor_print(ndo, ptr->vendor);
547}
548
549static void
550pptp_sccrp_print(netdissect_options *ndo,
551                 const u_char *dat)
552{
553	const struct pptp_msg_sccrp *ptr = (const struct pptp_msg_sccrp *)dat;
554
555	pptp_proto_ver_print(ndo, ptr->proto_ver);
556	pptp_result_code_print(ndo, ptr->result_code, PPTP_CTRL_MSG_TYPE_SCCRP);
557	pptp_err_code_print(ndo, ptr->err_code);
558	pptp_framing_cap_print(ndo, ptr->framing_cap);
559	pptp_bearer_cap_print(ndo, ptr->bearer_cap);
560	pptp_max_channel_print(ndo, ptr->max_channel);
561	pptp_firm_rev_print(ndo, ptr->firm_rev);
562	pptp_hostname_print(ndo, ptr->hostname);
563	pptp_vendor_print(ndo, ptr->vendor);
564}
565
566static void
567pptp_stopccrq_print(netdissect_options *ndo,
568                    const u_char *dat)
569{
570	const struct pptp_msg_stopccrq *ptr = (const struct pptp_msg_stopccrq *)dat;
571
572	ND_PRINT(" REASON(%u", GET_U_1(ptr->reason));
573	if (ndo->ndo_vflag) {
574		switch (GET_U_1(ptr->reason)) {
575		case 1:
576			ND_PRINT(":None");
577			break;
578		case 2:
579			ND_PRINT(":Stop-Protocol");
580			break;
581		case 3:
582			ND_PRINT(":Stop-Local-Shutdown");
583			break;
584		default:
585			ND_PRINT(":?");
586			break;
587		}
588	}
589	ND_PRINT(")");
590	PRINT_RESERVED_IF_NOT_ZERO_1(ptr->reserved1);
591	PRINT_RESERVED_IF_NOT_ZERO_2(ptr->reserved2);
592}
593
594static void
595pptp_stopccrp_print(netdissect_options *ndo,
596                    const u_char *dat)
597{
598	const struct pptp_msg_stopccrp *ptr = (const struct pptp_msg_stopccrp *)dat;
599
600	pptp_result_code_print(ndo, ptr->result_code, PPTP_CTRL_MSG_TYPE_StopCCRP);
601	pptp_err_code_print(ndo, ptr->err_code);
602	PRINT_RESERVED_IF_NOT_ZERO_2(ptr->reserved1);
603}
604
605static void
606pptp_echorq_print(netdissect_options *ndo,
607                  const u_char *dat)
608{
609	const struct pptp_msg_echorq *ptr = (const struct pptp_msg_echorq *)dat;
610
611	pptp_id_print(ndo, ptr->id);
612}
613
614static void
615pptp_echorp_print(netdissect_options *ndo,
616                  const u_char *dat)
617{
618	const struct pptp_msg_echorp *ptr = (const struct pptp_msg_echorp *)dat;
619
620	pptp_id_print(ndo, ptr->id);
621	pptp_result_code_print(ndo, ptr->result_code, PPTP_CTRL_MSG_TYPE_ECHORP);
622	pptp_err_code_print(ndo, ptr->err_code);
623	PRINT_RESERVED_IF_NOT_ZERO_2(ptr->reserved1);
624}
625
626static void
627pptp_ocrq_print(netdissect_options *ndo,
628                const u_char *dat)
629{
630	const struct pptp_msg_ocrq *ptr = (const struct pptp_msg_ocrq *)dat;
631
632	pptp_call_id_print(ndo, ptr->call_id);
633	pptp_call_ser_print(ndo, ptr->call_ser);
634	ND_PRINT(" MIN_BPS(%u)", GET_BE_U_4(ptr->min_bps));
635	ND_PRINT(" MAX_BPS(%u)", GET_BE_U_4(ptr->max_bps));
636	pptp_bearer_type_print(ndo, ptr->bearer_type);
637	pptp_framing_type_print(ndo, ptr->framing_type);
638	pptp_recv_winsiz_print(ndo, ptr->recv_winsiz);
639	pptp_pkt_proc_delay_print(ndo, ptr->pkt_proc_delay);
640	ND_PRINT(" PHONE_NO_LEN(%u)", GET_BE_U_2(ptr->phone_no_len));
641	PRINT_RESERVED_IF_NOT_ZERO_2(ptr->reserved1);
642	ND_PRINT(" PHONE_NO(");
643	nd_printjnp(ndo, ptr->phone_no,
644		    ND_MIN(64, GET_BE_U_2(ptr->phone_no_len)));
645	ND_PRINT(")");
646	pptp_subaddr_print(ndo, ptr->subaddr);
647}
648
649static void
650pptp_ocrp_print(netdissect_options *ndo,
651                const u_char *dat)
652{
653	const struct pptp_msg_ocrp *ptr = (const struct pptp_msg_ocrp *)dat;
654
655	pptp_call_id_print(ndo, ptr->call_id);
656	pptp_peer_call_id_print(ndo, ptr->peer_call_id);
657	pptp_result_code_print(ndo, ptr->result_code, PPTP_CTRL_MSG_TYPE_OCRP);
658	pptp_err_code_print(ndo, ptr->err_code);
659	pptp_cause_code_print(ndo, ptr->cause_code);
660	pptp_conn_speed_print(ndo, ptr->conn_speed);
661	pptp_recv_winsiz_print(ndo, ptr->recv_winsiz);
662	pptp_pkt_proc_delay_print(ndo, ptr->pkt_proc_delay);
663	pptp_phy_chan_id_print(ndo, ptr->phy_chan_id);
664}
665
666static void
667pptp_icrq_print(netdissect_options *ndo,
668                const u_char *dat)
669{
670	const struct pptp_msg_icrq *ptr = (const struct pptp_msg_icrq *)dat;
671
672	pptp_call_id_print(ndo, ptr->call_id);
673	pptp_call_ser_print(ndo, ptr->call_ser);
674	pptp_bearer_type_print(ndo, ptr->bearer_type);
675	pptp_phy_chan_id_print(ndo, ptr->phy_chan_id);
676	ND_PRINT(" DIALED_NO_LEN(%u)", GET_BE_U_2(ptr->dialed_no_len));
677	ND_PRINT(" DIALING_NO_LEN(%u)", GET_BE_U_2(ptr->dialing_no_len));
678	ND_PRINT(" DIALED_NO(");
679	nd_printjnp(ndo, ptr->dialed_no,
680		    ND_MIN(64, GET_BE_U_2(ptr->dialed_no_len)));
681	ND_PRINT(")");
682	ND_PRINT(" DIALING_NO(");
683	nd_printjnp(ndo, ptr->dialing_no,
684		    ND_MIN(64, GET_BE_U_2(ptr->dialing_no_len)));
685	ND_PRINT(")");
686	pptp_subaddr_print(ndo, ptr->subaddr);
687}
688
689static void
690pptp_icrp_print(netdissect_options *ndo,
691                const u_char *dat)
692{
693	const struct pptp_msg_icrp *ptr = (const struct pptp_msg_icrp *)dat;
694
695	pptp_call_id_print(ndo, ptr->call_id);
696	pptp_peer_call_id_print(ndo, ptr->peer_call_id);
697	pptp_result_code_print(ndo, ptr->result_code, PPTP_CTRL_MSG_TYPE_ICRP);
698	pptp_err_code_print(ndo, ptr->err_code);
699	pptp_recv_winsiz_print(ndo, ptr->recv_winsiz);
700	pptp_pkt_proc_delay_print(ndo, ptr->pkt_proc_delay);
701	PRINT_RESERVED_IF_NOT_ZERO_2(ptr->reserved1);
702}
703
704static void
705pptp_iccn_print(netdissect_options *ndo,
706                const u_char *dat)
707{
708	const struct pptp_msg_iccn *ptr = (const struct pptp_msg_iccn *)dat;
709
710	pptp_peer_call_id_print(ndo, ptr->peer_call_id);
711	PRINT_RESERVED_IF_NOT_ZERO_2(ptr->reserved1);
712	pptp_conn_speed_print(ndo, ptr->conn_speed);
713	pptp_recv_winsiz_print(ndo, ptr->recv_winsiz);
714	pptp_pkt_proc_delay_print(ndo, ptr->pkt_proc_delay);
715	pptp_framing_type_print(ndo, ptr->framing_type);
716}
717
718static void
719pptp_ccrq_print(netdissect_options *ndo,
720                const u_char *dat)
721{
722	const struct pptp_msg_ccrq *ptr = (const struct pptp_msg_ccrq *)dat;
723
724	pptp_call_id_print(ndo, ptr->call_id);
725	PRINT_RESERVED_IF_NOT_ZERO_2(ptr->reserved1);
726}
727
728static void
729pptp_cdn_print(netdissect_options *ndo,
730               const u_char *dat)
731{
732	const struct pptp_msg_cdn *ptr = (const struct pptp_msg_cdn *)dat;
733
734	pptp_call_id_print(ndo, ptr->call_id);
735	pptp_result_code_print(ndo, ptr->result_code, PPTP_CTRL_MSG_TYPE_CDN);
736	pptp_err_code_print(ndo, ptr->err_code);
737	pptp_cause_code_print(ndo, ptr->cause_code);
738	PRINT_RESERVED_IF_NOT_ZERO_2(ptr->reserved1);
739	ND_PRINT(" CALL_STATS(");
740	nd_printjnp(ndo, ptr->call_stats, 128);
741	ND_PRINT(")");
742}
743
744static void
745pptp_wen_print(netdissect_options *ndo,
746               const u_char *dat)
747{
748	const struct pptp_msg_wen *ptr = (const struct pptp_msg_wen *)dat;
749
750	pptp_peer_call_id_print(ndo, ptr->peer_call_id);
751	PRINT_RESERVED_IF_NOT_ZERO_2(ptr->reserved1);
752	ND_PRINT(" CRC_ERR(%u)", GET_BE_U_4(ptr->crc_err));
753	ND_PRINT(" FRAMING_ERR(%u)", GET_BE_U_4(ptr->framing_err));
754	ND_PRINT(" HARDWARE_OVERRUN(%u)", GET_BE_U_4(ptr->hardware_overrun));
755	ND_PRINT(" BUFFER_OVERRUN(%u)", GET_BE_U_4(ptr->buffer_overrun));
756	ND_PRINT(" TIMEOUT_ERR(%u)", GET_BE_U_4(ptr->timeout_err));
757	ND_PRINT(" ALIGN_ERR(%u)", GET_BE_U_4(ptr->align_err));
758}
759
760static void
761pptp_sli_print(netdissect_options *ndo,
762               const u_char *dat)
763{
764	const struct pptp_msg_sli *ptr = (const struct pptp_msg_sli *)dat;
765
766	pptp_peer_call_id_print(ndo, ptr->peer_call_id);
767	PRINT_RESERVED_IF_NOT_ZERO_2(ptr->reserved1);
768	ND_PRINT(" SEND_ACCM(0x%08x)", GET_BE_U_4(ptr->send_accm));
769	ND_PRINT(" RECV_ACCM(0x%08x)", GET_BE_U_4(ptr->recv_accm));
770}
771
772void
773pptp_print(netdissect_options *ndo,
774           const u_char *dat)
775{
776	const struct pptp_hdr *hdr;
777	uint32_t mc;
778	uint16_t ctrl_msg_type;
779
780	ndo->ndo_protocol = "pptp";
781	ND_PRINT(": ");
782	nd_print_protocol(ndo);
783
784	hdr = (const struct pptp_hdr *)dat;
785
786	if (ndo->ndo_vflag) {
787		ND_PRINT(" Length=%u", GET_BE_U_2(hdr->length));
788	}
789	if (ndo->ndo_vflag) {
790		switch(GET_BE_U_2(hdr->msg_type)) {
791		case PPTP_MSG_TYPE_CTRL:
792			ND_PRINT(" CTRL-MSG");
793			break;
794		case PPTP_MSG_TYPE_MGMT:
795			ND_PRINT(" MGMT-MSG");
796			break;
797		default:
798			ND_PRINT(" UNKNOWN-MSG-TYPE");
799			break;
800		}
801	}
802
803	mc = GET_BE_U_4(hdr->magic_cookie);
804	if (mc != PPTP_MAGIC_COOKIE) {
805		ND_PRINT(" UNEXPECTED Magic-Cookie!!(%08x)", mc);
806	}
807	if (ndo->ndo_vflag || mc != PPTP_MAGIC_COOKIE) {
808		ND_PRINT(" Magic-Cookie=%08x", mc);
809	}
810	ctrl_msg_type = GET_BE_U_2(hdr->ctrl_msg_type);
811	if (ctrl_msg_type < PPTP_MAX_MSGTYPE_INDEX) {
812		ND_PRINT(" CTRL_MSGTYPE=%s",
813		       pptp_message_type_string[ctrl_msg_type]);
814	} else {
815		ND_PRINT(" UNKNOWN_CTRL_MSGTYPE(%u)", ctrl_msg_type);
816	}
817	PRINT_RESERVED_IF_NOT_ZERO_2(hdr->reserved0);
818
819	dat += 12;
820
821	switch(ctrl_msg_type) {
822	case PPTP_CTRL_MSG_TYPE_SCCRQ:
823		pptp_sccrq_print(ndo, dat);
824		break;
825	case PPTP_CTRL_MSG_TYPE_SCCRP:
826		pptp_sccrp_print(ndo, dat);
827		break;
828	case PPTP_CTRL_MSG_TYPE_StopCCRQ:
829		pptp_stopccrq_print(ndo, dat);
830		break;
831	case PPTP_CTRL_MSG_TYPE_StopCCRP:
832		pptp_stopccrp_print(ndo, dat);
833		break;
834	case PPTP_CTRL_MSG_TYPE_ECHORQ:
835		pptp_echorq_print(ndo, dat);
836		break;
837	case PPTP_CTRL_MSG_TYPE_ECHORP:
838		pptp_echorp_print(ndo, dat);
839		break;
840	case PPTP_CTRL_MSG_TYPE_OCRQ:
841		pptp_ocrq_print(ndo, dat);
842		break;
843	case PPTP_CTRL_MSG_TYPE_OCRP:
844		pptp_ocrp_print(ndo, dat);
845		break;
846	case PPTP_CTRL_MSG_TYPE_ICRQ:
847		pptp_icrq_print(ndo, dat);
848		break;
849	case PPTP_CTRL_MSG_TYPE_ICRP:
850		pptp_icrp_print(ndo, dat);
851		break;
852	case PPTP_CTRL_MSG_TYPE_ICCN:
853		pptp_iccn_print(ndo, dat);
854		break;
855	case PPTP_CTRL_MSG_TYPE_CCRQ:
856		pptp_ccrq_print(ndo, dat);
857		break;
858	case PPTP_CTRL_MSG_TYPE_CDN:
859		pptp_cdn_print(ndo, dat);
860		break;
861	case PPTP_CTRL_MSG_TYPE_WEN:
862		pptp_wen_print(ndo, dat);
863		break;
864	case PPTP_CTRL_MSG_TYPE_SLI:
865		pptp_sli_print(ndo, dat);
866		break;
867	default:
868		/* do nothing */
869		break;
870	}
871}
872