aboutsummaryrefslogtreecommitdiffstats
path: root/packet-pptp.c
blob: 2c36c7efa36f04484e2c4e34a69451e0b6dfc99a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
/* packet-pptp.c
 * Routines for the Point-to-Point Tunnelling Protocol (PPTP) (RFC 2637)
 * Brad Robel-Forrest <brad.robel-forrest@watchguard.com>
 *
 * $Id: packet-pptp.c,v 1.29 2003/08/12 02:05:41 gerald Exp $
 *
 * Ethereal - Network traffic analyzer
 * By Gerald Combs <gerald@ethereal.com>
 * Copyright 1998 Gerald Combs
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */

#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

#include <stdio.h>

#include <glib.h>
#include <epan/packet.h>

static int proto_pptp = -1;
static int hf_pptp_message_type = -1;

static gint ett_pptp = -1;

static dissector_handle_t data_handle;

#define TCP_PORT_PPTP			1723

#define MAGIC_COOKIE		0x1A2B3C4D

static const value_string msgtype_vals[] = {
  { 1, "Control Message" },
  { 2, "Management Message" },
  { 0, NULL }
};

#define NUM_FRAME_TYPES		4
#define frametype2str(t)	\
  ((t < NUM_FRAME_TYPES) ? frametypestr[t] : "Unknown framing type")

static const char *frametypestr[NUM_FRAME_TYPES] = {
  "Unknown framing type",
  "Asynchronous Framing supported",
  "Synchronous Framing supported",
  "Either Framing supported"
};

#define NUM_BEARER_TYPES	4
#define bearertype2str(t)	\
  ((t < NUM_BEARER_TYPES) ? bearertypestr[t] : "Unknown bearer type")

static const char *bearertypestr[NUM_BEARER_TYPES] = {
  "Unknown bearer type",
  "Analog access supported",
  "Digital access supported",
  "Either access supported"
};

#define NUM_CNTRLRESULT_TYPES	6
#define cntrlresulttype2str(t)	\
  ((t < NUM_CNTRLRESULT_TYPES) ? cntrlresulttypestr[t] : "Unknown Start-Control-connection-Reply result code")

static const char *cntrlresulttypestr[NUM_CNTRLRESULT_TYPES] = {
  "Unknown Start-Control-connection-Reply result code",
  "Successful channel establishment",
  "General error",
  "Command channel already exists",
  "Requester not authorized",
  "Protocol version not supported"
};

#define NUM_ERROR_TYPES		7
#define errortype2str(t)	\
  ((t < NUM_ERROR_TYPES) ? errortypestr[t] : "Unknown general error code")

static const char *errortypestr[NUM_ERROR_TYPES] = {
  "None",
  "Not-Connected",
  "Bad-Format",
  "Bad-Value",
  "No-Resource",
  "Bad-Call ID",
  "PAC-Error"
};

#define NUM_REASON_TYPES	4
#define reasontype2str(t)	\
  ((t < NUM_REASON_TYPES) ? reasontypestr[t] : "Unknown Stop-Control-Connection-Request reason code")

static const char *reasontypestr[NUM_REASON_TYPES] = {
  "Unknown Stop-Control-Connection-Request reason code",
  "None",
  "Stop-Protocol",
  "Stop-Local-Shutdown"
};

#define NUM_STOPRESULT_TYPES	3
#define stopresulttype2str(t)	\
  ((t < NUM_STOPRESULT_TYPES) ? stopresulttypestr[t] : "Unknown Stop-Control-Connection-Reply result code")

static const char *stopresulttypestr[NUM_STOPRESULT_TYPES] = {
  "Unknown Stop-Control-Connection-Reply result code",
  "OK",
  "General error"
};

#define NUM_ECHORESULT_TYPES	3
#define echoresulttype2str(t)	\
  ((t < NUM_ECHORESULT_TYPES) ? echoresulttypestr[t] : "Unknown Echo-Reply result code")

static const char *echoresulttypestr[NUM_ECHORESULT_TYPES] = {
  "Unknown Echo-Reply result code",
  "OK",
  "General error"
};

#define NUM_OUTRESULT_TYPES	8
#define outresulttype2str(t)	\
  ((t < NUM_OUTRESULT_TYPES) ? outresulttypestr[t] : "Unknown Outgoing-Call-Reply result code")

static const char *outresulttypestr[NUM_OUTRESULT_TYPES] = {
  "Unknown Outgoing-Call-Reply result code",
  "Connected",
  "General Error",
  "No Carrier",
  "Busy",
  "No Dial Tone",
  "Time-out",
  "Do Not Accept"
};

#define NUM_INRESULT_TYPES	4
#define inresulttype2str(t)	\
  ((t < NUM_INRESULT_TYPES) ? inresulttypestr[t] : "Unknown Incoming-Call-Reply result code")

static const char *inresulttypestr[NUM_INRESULT_TYPES] = {
  "Unknown Incoming-Call-Reply result code",
  "Connect",
  "General Error",
  "Do Not Accept"
};

#define NUM_DISCRESULT_TYPES	5
#define discresulttype2str(t)	\
  ((t < NUM_DISCRESULT_TYPES) ? discresulttypestr[t] : "Unknown Call-Disconnect-Notify result code")

static const char *discresulttypestr[NUM_DISCRESULT_TYPES] = {
  "Unknown Call-Disconnect-Notify result code",
  "Lost Carrier",
  "General Error",
  "Admin Shutdown",
  "Request"
};

static void dissect_unknown(tvbuff_t *, int, packet_info *, proto_tree *);
static void dissect_cntrl_req(tvbuff_t *, int, packet_info *, proto_tree *);
static void dissect_cntrl_reply(tvbuff_t *, int, packet_info *, proto_tree *);
static void dissect_stop_req(tvbuff_t *, int, packet_info *, proto_tree *);
static void dissect_stop_reply(tvbuff_t *, int, packet_info *, proto_tree *);
static void dissect_echo_req(tvbuff_t *, int, packet_info *, proto_tree *);
static void dissect_echo_reply(tvbuff_t *, int, packet_info *, proto_tree *);
static void dissect_out_req(tvbuff_t *, int, packet_info *, proto_tree *);
static void dissect_out_reply(tvbuff_t *, int, packet_info *, proto_tree *);
static void dissect_in_req(tvbuff_t *, int, packet_info *, proto_tree *);
static void dissect_in_reply(tvbuff_t *, int, packet_info *, proto_tree *);
static void dissect_in_connected(tvbuff_t *, int, packet_info *, proto_tree *);
static void dissect_clear_req(tvbuff_t *, int, packet_info *, proto_tree *);
static void dissect_disc_notify(tvbuff_t *, int, packet_info *, proto_tree *);
static void dissect_error_notify(tvbuff_t *, int, packet_info *, proto_tree *);
static void dissect_set_link(tvbuff_t *, int, packet_info *, proto_tree *);

#define NUM_CNTRL_TYPES		16
#define cntrltype2str(t)	\
  ((t < NUM_CNTRL_TYPES) ? strfuncs[t].str : "UNKNOWN-CONTROL-TYPE")

static struct strfunc {
  const char *	str;
  void          (*func)(tvbuff_t *, int, packet_info *, proto_tree *);
} strfuncs[NUM_CNTRL_TYPES] = {
  {"Unknown control type",    dissect_unknown      },
  {"Start-Control-Connection-Request",   dissect_cntrl_req    },
  {"Start-Control-Connection-Reply",     dissect_cntrl_reply  },
  {"Stop-Control-Connection-Request",    dissect_stop_req     },
  {"Stop-Control-Connection-Reply",      dissect_stop_reply   },
  {"Echo-Request",                       dissect_echo_req     },
  {"Echo-Reply",                         dissect_echo_reply   },
  {"Outgoing-Call-Request",              dissect_out_req      },
  {"Outgoing-Call-Reply",                dissect_out_reply    },
  {"Incoming-Call-Request",              dissect_in_req       },
  {"Incoming-Call-Reply",                dissect_in_reply     },
  {"Incoming-Call-Connected",            dissect_in_connected },
  {"Call-Clear-Request",                 dissect_clear_req    },
  {"Call-Disconnect-Notify",             dissect_disc_notify  },
  {"WAN-Error-Notify",                   dissect_error_notify },
  {"Set-Link-Info",                      dissect_set_link     }
};

/*
 * Length of host name and vendor name strings in control requests and
 * replies.
 */
#define HOSTLEN		64
#define VENDORLEN	64

/*
 * Length of phone number(s) and subaddress in call requests.
 */
#define PHONELEN	64
#define SUBADDRLEN	64

/*
 * Length of statistics in a Call-Disconnect-Notify message.
 */
#define STATSLEN	128

static void
dissect_pptp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
{
  int			offset = 0;
  guint16		len;
  guint16		cntrl_type;

  if (check_col(pinfo->cinfo, COL_PROTOCOL))
    col_set_str(pinfo->cinfo, COL_PROTOCOL, "PPTP");
  if (check_col(pinfo->cinfo, COL_INFO))
    col_clear(pinfo->cinfo, COL_INFO);

  len	     = tvb_get_ntohs(tvb, offset);
  cntrl_type = tvb_get_ntohs(tvb, offset + 8);

  if (check_col(pinfo->cinfo, COL_INFO))
    col_add_fstr(pinfo->cinfo, COL_INFO, "%s", cntrltype2str(cntrl_type));

  if (tree) {
    guint32		cookie;
    proto_item *	ti;
    proto_tree *	pptp_tree;

    ti = proto_tree_add_item(tree, proto_pptp, tvb, offset, len, FALSE);
    pptp_tree = proto_item_add_subtree(ti, ett_pptp);

    proto_tree_add_text(pptp_tree, tvb, offset, 2, "Length: %u", len);
    offset += 2;

    proto_tree_add_item(pptp_tree, hf_pptp_message_type, tvb,
			       offset, 2, FALSE);
    offset += 2;

    cookie = tvb_get_ntohl(tvb, offset);

    if (cookie == MAGIC_COOKIE)
      proto_tree_add_text(pptp_tree, tvb, offset, 4,
			  "Cookie: %#08x (correct)", cookie);
    else
      proto_tree_add_text(pptp_tree, tvb, offset, 4,
			  "Cookie: %#08x (incorrect)", cookie);
    offset += 4;

    proto_tree_add_text(pptp_tree, tvb, offset, 2,
			"Control type: %s (%u)", cntrltype2str(cntrl_type), cntrl_type);
    offset += 2;

    proto_tree_add_text(pptp_tree, tvb, offset, 2,
			"Reserved: %u", tvb_get_ntohs(tvb, offset));
    offset += 2;

    if (cntrl_type < NUM_CNTRL_TYPES)
      ( *(strfuncs[cntrl_type].func))(tvb, offset, pinfo, pptp_tree);
    else
      call_dissector(data_handle,tvb_new_subset(tvb, offset, -1, -1), pinfo, pptp_tree);
  }
}

static void
dissect_unknown(tvbuff_t *tvb, int offset, packet_info *pinfo,
		proto_tree *tree)
{
  call_dissector(data_handle,tvb_new_subset(tvb, offset, -1, -1), pinfo, tree);
}

static void
dissect_cntrl_req(tvbuff_t *tvb, int offset, packet_info *pinfo _U_,
		  proto_tree *tree)
{
  guint8		major_ver;
  guint8		minor_ver;
  guint32		frame;
  guint32		bearer;
  guint8		host[HOSTLEN+1];
  guint8		vendor[VENDORLEN+1];

  major_ver = tvb_get_guint8(tvb, offset);
  minor_ver = tvb_get_guint8(tvb, offset + 1);
  proto_tree_add_text(tree, tvb, offset, 2,
		      "Protocol version: %u.%u", major_ver, minor_ver);
  offset += 2;

  proto_tree_add_text(tree, tvb, offset, 2,
		      "Reserved: %u", tvb_get_ntohs(tvb, offset));
  offset += 2;

  frame = tvb_get_ntohl(tvb, offset);
  proto_tree_add_text(tree, tvb, offset, 4,
		      "Framing capabilities: %s (%u)", frametype2str(frame), frame);
  offset += 4;

  bearer = tvb_get_ntohl(tvb, offset);
  proto_tree_add_text(tree, tvb, offset, 4,
		      "Bearer capabilities: %s (%u)", bearertype2str(bearer), bearer);
  offset += 4;

  proto_tree_add_text(tree, tvb, offset, 2,
		      "Maximum channels: %u", tvb_get_ntohs(tvb, offset));
  offset += 2;

  proto_tree_add_text(tree, tvb, offset, 2,
		      "Firmware revision: %u", tvb_get_ntohs(tvb, offset));
  offset += 2;

  tvb_memcpy(tvb, host, offset, HOSTLEN);
  host[HOSTLEN] = '\0';
  proto_tree_add_text(tree, tvb, offset, HOSTLEN,
		      "Hostname: %s", host);
  offset += HOSTLEN;

  tvb_memcpy(tvb, vendor, offset, VENDORLEN);
  vendor[VENDORLEN] = '\0';
  proto_tree_add_text(tree, tvb, offset, VENDORLEN,
		      "Vendor: %s", vendor);
}

static void
dissect_cntrl_reply(tvbuff_t *tvb, int offset, packet_info *pinfo _U_,
		    proto_tree *tree)
{
  guint8		major_ver;
  guint8		minor_ver;
  guint8		result;
  guint8		error;
  guint32		frame;
  guint32		bearer;
  guint8		host[HOSTLEN+1];
  guint8		vendor[VENDORLEN+1];

  major_ver = tvb_get_guint8(tvb, offset);
  minor_ver = tvb_get_guint8(tvb, offset + 1);
  proto_tree_add_text(tree, tvb, offset, 2,
		      "Protocol version: %u.%u", major_ver, minor_ver);
  offset += 2;

  result = tvb_get_guint8(tvb, offset);
  proto_tree_add_text(tree, tvb, offset, 1,
		      "Result: %s (%u)", cntrlresulttype2str(result), result);
  offset += 1;

  error = tvb_get_guint8(tvb, offset);
  proto_tree_add_text(tree, tvb, offset, 1,
		      "Error: %s (%u)", errortype2str(error), error);
  offset += 1;

  frame = tvb_get_ntohl(tvb, offset);
  proto_tree_add_text(tree, tvb, offset, 4,
		      "Framing capabilities: %s (%u)", frametype2str(frame), frame);
  offset += 4;

  bearer = tvb_get_ntohl(tvb, offset);
  proto_tree_add_text(tree, tvb, offset, 4,
		      "Bearer capabilities: %s (%u)", bearertype2str(bearer), bearer);
  offset += 4;

  proto_tree_add_text(tree, tvb, offset, 2,
		      "Maximum channels: %u", tvb_get_ntohs(tvb, offset));
  offset += 2;

  proto_tree_add_text(tree, tvb, offset, 2,
		      "Firmware revision: %u", tvb_get_ntohs(tvb, offset));
  offset += 2;

  tvb_memcpy(tvb, host, offset, HOSTLEN);
  host[HOSTLEN] = '\0';
  proto_tree_add_text(tree, tvb, offset, HOSTLEN,
		      "Hostname: %s", host);
  offset += HOSTLEN;

  tvb_memcpy(tvb, vendor, offset, VENDORLEN);
  vendor[VENDORLEN] = '\0';
  proto_tree_add_text(tree, tvb, offset, VENDORLEN,
		      "Vendor: %s", vendor);
}

static void
dissect_stop_req(tvbuff_t *tvb, int offset, packet_info *pinfo _U_,
		 proto_tree *tree)
{
  guint8		reason;

  reason = tvb_get_guint8(tvb, offset);
  proto_tree_add_text(tree, tvb, offset, 1,
		      "Reason: %s (%u)", reasontype2str(reason), reason);
  offset += 1;

  proto_tree_add_text(tree, tvb, offset, 1,
		      "Reserved: %u", tvb_get_guint8(tvb, offset));
  offset += 1;

  proto_tree_add_text(tree, tvb, offset, 2,
		      "Reserved: %u", tvb_get_ntohs(tvb, offset));
}

static void
dissect_stop_reply(tvbuff_t *tvb, int offset, packet_info *pinfo _U_,
		   proto_tree *tree)
{
  guint8		result;
  guint8		error;

  result = tvb_get_guint8(tvb, offset);
  proto_tree_add_text(tree, tvb, offset, 1,
		      "Result: %s (%u)", stopresulttype2str(result), result);
  offset += 1;

  error = tvb_get_guint8(tvb, offset);
  proto_tree_add_text(tree, tvb, offset, 1,
		      "Error: %s (%u)", errortype2str(error), error);
  offset += 1;

  proto_tree_add_text(tree, tvb, offset, 2,
		      "Reserved: %u", tvb_get_ntohs(tvb, offset));
}

static void
dissect_echo_req(tvbuff_t *tvb, int offset, packet_info *pinfo _U_,
		 proto_tree *tree)
{
  proto_tree_add_text(tree, tvb, offset, 4,
		      "Identifier: %u", tvb_get_ntohl(tvb, offset));
}

static void
dissect_echo_reply(tvbuff_t *tvb, int offset, packet_info *pinfo _U_,
		   proto_tree *tree)
{
  guint8		result;
  guint8		error;

  proto_tree_add_text(tree, tvb, offset, 4,
		      "Identifier: %u", tvb_get_ntohl(tvb, offset));
  offset += 4;

  result = tvb_get_guint8(tvb, offset);
  proto_tree_add_text(tree, tvb, offset, 1,
		      "Result: %s (%u)", echoresulttype2str(result), result);
  offset += 1;

  error = tvb_get_guint8(tvb, offset);
  proto_tree_add_text(tree, tvb, offset, sizeof(error),
		      "Error: %s (%u)", errortype2str(error), error);
  offset += 1;

  proto_tree_add_text(tree, tvb, offset, 2,
		      "Reserved: %u", tvb_get_ntohs(tvb, offset));
}

static void
dissect_out_req(tvbuff_t *tvb, int offset, packet_info *pinfo _U_,
		proto_tree *tree)
{
  guint32		bearer;
  guint32		frame;
  guint8		phone[PHONELEN+1];
  guint8		subaddr[SUBADDRLEN+1];

  proto_tree_add_text(tree, tvb, offset, 2,
		      "Call ID: %u", tvb_get_ntohs(tvb, offset));
  offset += 2;

  proto_tree_add_text(tree, tvb, offset, 2,
		      "Call Serial Number: %u", tvb_get_ntohs(tvb, offset));
  offset += 2;

  proto_tree_add_text(tree, tvb, offset, 4,
		      "Minimum BPS: %u", tvb_get_ntohl(tvb, offset));
  offset += 4;

  proto_tree_add_text(tree, tvb, offset, 4,
		      "Maximum BPS: %u", tvb_get_ntohl(tvb, offset));
  offset += 4;

  bearer = tvb_get_ntohl(tvb, offset);
  proto_tree_add_text(tree, tvb, offset, 4,
		      "Bearer capabilities: %s (%u)", bearertype2str(bearer), bearer);
  offset += 4;

  frame = tvb_get_ntohl(tvb, offset);
  proto_tree_add_text(tree, tvb, offset, 4,
		      "Framing capabilities: %s (%u)", frametype2str(frame), frame);
  offset += 4;

  proto_tree_add_text(tree, tvb, offset, 2,
		      "Receive window size: %u", tvb_get_ntohs(tvb, offset));
  offset += 2;

  proto_tree_add_text(tree, tvb, offset, 2,
		      "Processing delay: %u", tvb_get_ntohs(tvb, offset));
  offset += 2;

  proto_tree_add_text(tree, tvb, offset, 2,
		      "Phone number length: %u", tvb_get_ntohs(tvb, offset));
  offset += 2;

  proto_tree_add_text(tree, tvb, offset, 2,
		      "Reserved: %u", tvb_get_ntohs(tvb, offset));
  offset += 2;

  tvb_memcpy(tvb, phone, offset, PHONELEN);
  phone[PHONELEN] = '\0';
  proto_tree_add_text(tree, tvb, offset, PHONELEN,
		      "Phone number: %s", phone);
  offset += PHONELEN;

  tvb_memcpy(tvb, subaddr, offset, SUBADDRLEN);
  subaddr[SUBADDRLEN] = '\0';
  proto_tree_add_text(tree, tvb, offset, SUBADDRLEN,
		      "Subaddress: %s", subaddr);
}

static void
dissect_out_reply(tvbuff_t *tvb, int offset, packet_info *pinfo _U_,
		  proto_tree *tree)
{
  guint8		result;
  guint8		error;

  proto_tree_add_text(tree, tvb, offset, 2,
		      "Call ID: %u", tvb_get_ntohs(tvb, offset));
  offset += 2;

  proto_tree_add_text(tree, tvb, offset, 2,
		      "Peer's call ID: %u", tvb_get_ntohs(tvb, offset));
  offset += 2;

  result = tvb_get_guint8(tvb, offset);
  proto_tree_add_text(tree, tvb, offset, 1,
		      "Result: %s (%u)", outresulttype2str(result), result);
  offset += 1;

  error = tvb_get_guint8(tvb, offset);
  proto_tree_add_text(tree, tvb, offset, 1,
		      "Error: %s (%u)", errortype2str(error), error);
  offset += 1;

  proto_tree_add_text(tree, tvb, offset, 2,
		      "Cause code: %u", tvb_get_ntohs(tvb, offset));
  offset += 2;

  proto_tree_add_text(tree, tvb, offset, 4,
		      "Connect speed: %u", tvb_get_ntohl(tvb, offset));
  offset += 4;

  proto_tree_add_text(tree, tvb, offset, 2,
		      "Receive window size: %u", tvb_get_ntohs(tvb, offset));
  offset += 2;

  proto_tree_add_text(tree, tvb, offset, 2,
		      "Processing delay: %u", tvb_get_ntohs(tvb, offset));
  offset += 2;

  proto_tree_add_text(tree, tvb, offset, 4,
		      "Physical channel ID: %u", tvb_get_ntohl(tvb, offset));
}

static void
dissect_in_req(tvbuff_t *tvb, int offset, packet_info *pinfo _U_,
	       proto_tree *tree)
{
  guint32		bearer;
  guint8		dialed[PHONELEN+1];
  guint8		dialing[PHONELEN+1];
  guint8		subaddr[SUBADDRLEN+1];

  proto_tree_add_text(tree, tvb, offset, 2,
		      "Call ID: %u", tvb_get_ntohs(tvb, offset));
  offset += 2;

  proto_tree_add_text(tree, tvb, offset, 2,
		      "Call serial number: %u", tvb_get_ntohs(tvb, offset));
  offset += 2;

  bearer = tvb_get_ntohl(tvb, offset);
  proto_tree_add_text(tree, tvb, offset, 4,
		      "Bearer capabilities: %s (%u)", bearertype2str(bearer), bearer);
  offset += 4;

  proto_tree_add_text(tree, tvb, offset, 4,
		      "Physical channel ID: %u", tvb_get_ntohl(tvb, offset));
  offset += 4;

  proto_tree_add_text(tree, tvb, offset, 2,
		      "Dialed number length: %u", tvb_get_ntohs(tvb, offset));
  offset += 2;

  proto_tree_add_text(tree, tvb, offset, 2,
		      "Dialing number length: %u", tvb_get_ntohs(tvb, offset));
  offset += 2;

  tvb_memcpy(tvb, dialing, offset, PHONELEN);
  dialed[PHONELEN] = '\0';
  proto_tree_add_text(tree, tvb, offset, PHONELEN,
		      "Dialed number: %s", dialed);
  offset += PHONELEN;

  tvb_memcpy(tvb, dialing, offset, PHONELEN);
  dialing[PHONELEN] = '\0';
  proto_tree_add_text(tree, tvb, offset, PHONELEN,
		      "Dialing number: %s", dialing);
  offset += PHONELEN;

  tvb_memcpy(tvb, subaddr, offset, SUBADDRLEN);
  subaddr[SUBADDRLEN] = '\0';
  proto_tree_add_text(tree, tvb, offset, SUBADDRLEN,
		      "Subaddress: %s", subaddr);
}

static void
dissect_in_reply(tvbuff_t *tvb, int offset, packet_info *pinfo _U_,
		 proto_tree *tree)
{
  guint8		result;
  guint8		error;

  proto_tree_add_text(tree, tvb, offset, 2,
		      "Call ID: %u", tvb_get_ntohs(tvb, offset));
  offset += 2;

  proto_tree_add_text(tree, tvb, offset, 2,
		      "Peer's call ID: %u", tvb_get_ntohs(tvb, offset));
  offset += 2;

  result = tvb_get_guint8(tvb, offset);
  proto_tree_add_text(tree, tvb, offset, 1,
		      "Result: %s (%u)", inresulttype2str(result), result);
  offset += 1;

  error = tvb_get_guint8(tvb, offset);
  proto_tree_add_text(tree, tvb, offset, 1,
		      "Error: %s (%u)", errortype2str(error), error);
  offset += 1;

  proto_tree_add_text(tree, tvb, offset, 2,
		      "Receive window size: %u", tvb_get_ntohs(tvb, offset));
  offset += 2;

  proto_tree_add_text(tree, tvb, offset, 2,
		      "Processing delay: %u", tvb_get_ntohs(tvb, offset));
  offset += 2;

  proto_tree_add_text(tree, tvb, offset, 2,
		      "Reserved: %u", tvb_get_ntohs(tvb, offset));
}

static void
dissect_in_connected(tvbuff_t *tvb, int offset, packet_info *pinfo _U_,
		     proto_tree *tree)
{
  guint32		frame;

  proto_tree_add_text(tree, tvb, offset, 2,
		      "Peer's call ID: %u", tvb_get_ntohs(tvb, offset));
  offset += 2;

  proto_tree_add_text(tree, tvb, offset, 2,
		      "Reserved: %u", tvb_get_ntohs(tvb, offset));
  offset += 2;

  proto_tree_add_text(tree, tvb, offset, 4,
		      "Connect speed: %u", tvb_get_ntohl(tvb, offset));
  offset += 4;

  proto_tree_add_text(tree, tvb, offset, 2,
		      "Receive window size: %u", tvb_get_ntohs(tvb, offset));
  offset += 2;

  proto_tree_add_text(tree, tvb, offset, 2,
		      "Processing delay: %u", tvb_get_ntohs(tvb, offset));
  offset += 2;

  frame = tvb_get_ntohl(tvb, offset);
  proto_tree_add_text(tree, tvb, offset, 4,
		      "Framing capabilities: %s (%u)", frametype2str(frame), frame);
}

static void
dissect_clear_req(tvbuff_t *tvb, int offset, packet_info *pinfo _U_,
		  proto_tree *tree)
{
  proto_tree_add_text(tree, tvb, offset, 2,
		      "Call ID: %u", tvb_get_ntohs(tvb, offset));
  offset += 2;

  proto_tree_add_text(tree, tvb, offset, 2,
		      "Reserved: %u", tvb_get_ntohs(tvb, offset));
}

static void
dissect_disc_notify(tvbuff_t *tvb, int offset, packet_info *pinfo _U_,
		    proto_tree *tree)
{
  guint8		result;
  guint8		error;
  guint8		stats[STATSLEN+1];

  proto_tree_add_text(tree, tvb, offset, 2,
		      "Call ID: %u", tvb_get_ntohs(tvb, offset));
  offset += 2;

  result = tvb_get_guint8(tvb, offset);
  proto_tree_add_text(tree, tvb, offset, 1,
		      "Result: %s (%u)", discresulttype2str(result), result);
  offset += 1;

  error = tvb_get_guint8(tvb, offset);
  proto_tree_add_text(tree, tvb, offset, 1,
		      "Error: %s (%u)", errortype2str(error), error);
  offset += 1;

  proto_tree_add_text(tree, tvb, offset, 2,
		      "Cause code: %u", tvb_get_ntohs(tvb, offset));
  offset += 2;

  proto_tree_add_text(tree, tvb, offset, 2,
		      "Reserved: %u", tvb_get_ntohs(tvb, offset));
  offset += 2;

  tvb_memcpy(tvb, stats, offset, STATSLEN);
  stats[STATSLEN] = '\0';
  proto_tree_add_text(tree, tvb, offset, STATSLEN,
		      "Call statistics: %s", stats);
}

static void
dissect_error_notify(tvbuff_t *tvb, int offset, packet_info *pinfo _U_,
		     proto_tree *tree)
{
  proto_tree_add_text(tree, tvb, offset, 2,
		      "Peer's call ID: %u", tvb_get_ntohs(tvb, offset));
  offset += 2;

  proto_tree_add_text(tree, tvb, offset, 2,
		      "Reserved: %u", tvb_get_ntohs(tvb, offset));
  offset += 2;

  proto_tree_add_text(tree, tvb, offset, 4,
		      "CRC errors: %u", tvb_get_ntohl(tvb, offset));
  offset += 4;

  proto_tree_add_text(tree, tvb, offset, 4,
		      "Framing errors: %u", tvb_get_ntohl(tvb, offset));
  offset += 4;

  proto_tree_add_text(tree, tvb, offset, 4,
		      "Hardware overruns: %u", tvb_get_ntohl(tvb, offset));
  offset += 4;

  proto_tree_add_text(tree, tvb, offset, 4,
		      "Buffer overruns: %u", tvb_get_ntohl(tvb, offset));
  offset += 4;

  proto_tree_add_text(tree, tvb, offset, 4,
		      "Time-out errors: %u", tvb_get_ntohl(tvb, offset));
  offset += 4;

  proto_tree_add_text(tree, tvb, offset, 4,
		      "Alignment errors: %u", tvb_get_ntohl(tvb, offset));
}

static void
dissect_set_link(tvbuff_t *tvb, int offset, packet_info *pinfo _U_,
		 proto_tree *tree)
{
  proto_tree_add_text(tree, tvb, offset, 2,
		      "Peer's call ID: %u", tvb_get_ntohs(tvb, offset));
  offset += 2;

  proto_tree_add_text(tree, tvb, offset, 2,
		      "Reserved: %u", tvb_get_ntohs(tvb, offset));
  offset += 2;

  proto_tree_add_text(tree, tvb, offset, 4,
		      "Send ACCM: %#08x", tvb_get_ntohl(tvb, offset));
  offset += 4;

  proto_tree_add_text(tree, tvb, offset, 4,
		      "Recv ACCM: %#08x", tvb_get_ntohl(tvb, offset));
}

void
proto_register_pptp(void)
{
  static gint *ett[] = {
    &ett_pptp,
  };

  static hf_register_info hf[] = {
    { &hf_pptp_message_type,
      { "Message type",			"pptp.type",
	FT_UINT16,	BASE_DEC,	VALS(msgtype_vals),	0x0,
      	"PPTP message type", HFILL }}
  };

  proto_pptp = proto_register_protocol("Point-to-Point Tunnelling Protocol",
				       "PPTP", "pptp");
  proto_register_field_array(proto_pptp, hf, array_length(hf));
  proto_register_subtree_array(ett, array_length(ett));
}

void
proto_reg_handoff_pptp(void)
{
  dissector_handle_t pptp_handle;

  pptp_handle = create_dissector_handle(dissect_pptp, proto_pptp);
  dissector_add("tcp.port", TCP_PORT_PPTP, pptp_handle);
  data_handle = find_dissector("data");
}