summaryrefslogtreecommitdiffstats
path: root/epan/dissectors/packet-dpnet.c
blob: 8bfc9892bbc630e894c5a0e44410bb977be57811 (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
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
/* packet-dpnet.c
 * This is a dissector for the DirectPlay 8 protocol.
 *
 * Copyright 2017 - Alistair Leslie-Hughes
 *
 * Wireshark - Network traffic analyzer
 * By Gerald Combs <gerald@wireshark.org>
 * Copyright 1998 Gerald Combs
 *
 * SPDX-License-Identifier: GPL-2.0-or-later
 *
 */

#include "config.h"

#include <epan/packet.h>

void proto_register_dpnet(void);
void proto_reg_handoff_dpnet(void);

static dissector_handle_t dpnet_handle;

#define DPNET_PORT 6073

static int proto_dpnet = -1;

static int hf_dpnet_lead = -1;
static int hf_dpnet_command = -1;
static int hf_dpnet_payload = -1;
static int hf_dpnet_type = -1;
static int hf_dpnet_application = -1;
static int hf_dpnet_data = -1;
static int hf_dpnet_reply_offset = -1;
static int hf_dpnet_response_size = -1;

static int hf_dpnet_desc_size = -1;
static int hf_dpnet_desc_flags = -1;
static int hf_dpnet_max_players = -1;
static int hf_dpnet_current_players = -1;
static int hf_dpnet_session_offset = -1;
static int hf_dpnet_session_size = -1;
static int hf_dpnet_session_name = -1;
static int hf_dpnet_password_offset = -1;
static int hf_dpnet_password_size = -1;
static int hf_dpnet_reserved_offset = -1;
static int hf_dpnet_reserved_size = -1;
static int hf_dpnet_application_offset = -1;
static int hf_dpnet_application_size = -1;
static int hf_dpnet_application_data = -1;
static int hf_dpnet_instance = -1;
static int hf_dpnet_data_cframe_control = -1;
static int hf_dpnet_data_cframe_msgid = -1;
static int hf_dpnet_data_cframe_rspid = -1;
static int hf_dpnet_data_cframe_protocol = -1;
static int hf_dpnet_data_cframe_session = -1;
static int hf_dpnet_data_cframe_timestamp = -1;
static int hf_dpnet_data_cframe_padding = -1;
static int hf_dpnet_data_cframe_flags = -1;
static int hf_dpnet_data_cframe_retry = -1;
static int hf_dpnet_data_cframe_nseq = -1;
static int hf_dpnet_data_cframe_nrcv = -1;
static int hf_dpnet_data_cframe_sack_mask1 = -1;
static int hf_dpnet_data_cframe_sack_mask2 = -1;
static int hf_dpnet_data_cframe_send_mask1 = -1;
static int hf_dpnet_data_cframe_send_mask2 = -1;
static int hf_dpnet_data_cframe_signature = -1;
static int hf_dpnet_data_cframe_send_secret = -1;
static int hf_dpnet_data_cframe_recv_secret = -1;
static int hf_dpnet_data_cframe_signing_opts = -1;
static int hf_dpnet_data_cframe_echo_time = -1;
static int hf_dpnet_data_seq        = -1;
static int hf_dpnet_data_nseq       = -1;
static int hf_dpnet_data_command = -1;
static int hf_dpnet_command_data     = -1;
static int hf_dpnet_command_reliable = -1;
static int hf_dpnet_command_seq      = -1;
static int hf_dpnet_command_poll     = -1;
static int hf_dpnet_command_new_msg  = -1;
static int hf_dpnet_command_end_msg  = -1;
static int hf_dpnet_command_user1    = -1;
static int hf_dpnet_command_user2    = -1;
static int hf_dpnet_desc_client_server = -1;
static int hf_dpnet_desc_migrate_host  = -1;
static int hf_dpnet_desc_nodpnsvr      = -1;
static int hf_dpnet_desc_req_password  = -1;
static int hf_dpnet_desc_no_enums      = -1;
static int hf_dpnet_desc_fast_signed   = -1;
static int hf_dpnet_desc_full_signed   = -1;

static gint ett_dpnet = -1;
static gint ett_dpnet_command_flags = -1;
static gint ett_dpnet_desc_flags = -1;

#define DPNET_QUERY_GUID     0x01

#define DPNET_ENUM_QUERY     0x02
#define DPNET_ENUM_RESPONSE  0x03

#define DPNET_COMMAND_DATA                   0x01
#define DPNET_COMMAND_RELIABLE               0x02
#define DPNET_COMMAND_SEQUENTIAL             0x04
#define DPNET_COMMAND_POLL                   0x08
#define DPNET_COMMAND_NEW_MSG                0x10
#define DPNET_COMMAND_END_MSG                0x20
#define DPNET_COMMAND_USER_1                 0x40
#define DPNET_COMMAND_CFRAME                 0x80

#define DN_MSG_INTERNAL_PLAYER_CONNECT_INFO  0x000000c1
#define DN_MSG_INTERNAL_SEND_CONNECT_INFO    0x000000c2
#define DN_MSG_INTERNAL_ACK_CONNECT_INFO     0x000000c3

#define FRAME_EXOPCODE_CONNECT               0x01
#define FRAME_EXOPCODE_CONNECTED             0x02
#define FRAME_EXOPCODE_CONNECTED_SIGNED      0x03
#define FRAME_EXOPCODE_HARD_DISCONNECT       0x04
#define FRAME_EXOPCODE_SACK                  0x06

#define PROTOCOL_VER_0                       0x00010000
#define PROTOCOL_VER_1                       0x00010001
#define PROTOCOL_VER_2                       0x00010002
#define PROTOCOL_VER_3                       0x00010003
#define PROTOCOL_VER_4                       0x00010004
#define PROTOCOL_VER_5                       0x00010005
#define PROTOCOL_VER_6                       0x00010006

#define SACK_FLAGS_RESPONSE                  0x01
#define SACK_FLAGS_SACK_MASK1                0x02
#define SACK_FLAGS_SACK_MASK2                0x04
#define SACK_FLAGS_SEND_MASK1                0x08
#define SACK_FLAGS_SEND_MASK2                0x10

#define PACKET_SIGNING_FAST                  0x01
#define PACKET_SIGNING_FULL                  0x02

#define SESSION_CLIENT_SERVER                0x0001
#define SESSION_MIGRATE_HOST                 0x0004
#define SESSION_NODPNSVR                     0x0040
#define SESSION_REQUIREPASSWORD              0x0080
#define SESSION_NOENUMS                      0x0100
#define SESSION_FAST_SIGNED                  0x0200
#define SESSION_FULL_SIGNED                  0x0400

static const value_string packetenumttypes[] = {
    { 1, "Application GUID" },
    { 2, "All Applications" },
    { 0, NULL }
};

static const value_string packetquerytype[] = {
    { 2, "Enumeration Query" },
    { 3, "Enumeration Response" },
    { 0, NULL }
};

static const value_string msg_cframe_control[] = {
    {FRAME_EXOPCODE_CONNECT,              "FRAME_EXOPCODE_CONNECT"},
    {FRAME_EXOPCODE_CONNECTED,            "FRAME_EXOPCODE_CONNECTED"},
    {FRAME_EXOPCODE_CONNECTED_SIGNED,     "FRAME_EXOPCODE_CONNECTED_SIGNED"},
    {FRAME_EXOPCODE_HARD_DISCONNECT,      "FRAME_EXOPCODE_HARD_DISCONNECT"},
    {FRAME_EXOPCODE_SACK,                 "FRAME_EXOPCODE_SACK"},
    {0, NULL }
};

static const value_string protocol_versions[] = {
    {PROTOCOL_VER_0,                      "Supports Base Features"},
    {PROTOCOL_VER_1,                      "Supports Base Features"},
    {PROTOCOL_VER_2,                      "Supports Base Features"},
    {PROTOCOL_VER_3,                      "Supports Base Features"},
    {PROTOCOL_VER_4,                      "Supports Base Features"},
    {PROTOCOL_VER_5,                      "Supports Coalescence"},
    {PROTOCOL_VER_6,                      "Supports Coalescence and Signing"},
    {0, NULL }
};

static const value_string sack_flags[] = {
    {SACK_FLAGS_RESPONSE,                  "Retry field is valid"},
    {SACK_FLAGS_SACK_MASK1,                "Low 32 bits of the SACK mask are present in sack.mask1"},
    {SACK_FLAGS_SACK_MASK2,                "High 32 bits of the SACK mask are present in sack.mask2"},
    {SACK_FLAGS_SEND_MASK1,                "Low 32 bits of the Send mask are present in send.mask1"},
    {SACK_FLAGS_SEND_MASK2,                "High 32 bits of the Send mask are present in send.mask2"},
    {0, NULL }
};

static const value_string signing_opts[] = {
    {PACKET_SIGNING_FAST,                "Fasting signing"},
    {PACKET_SIGNING_FULL,                "Full signing"},
    {0, NULL }
};

static const true_false_string tfs_flags_game_client = {
    "Client/Server session",
    "Peer session"
};

static const true_false_string tfs_flags_migrate = {
    "Host Migrating allowed",
    "Host Migrating NOT allowed"
};

static const true_false_string tfs_flags_dpnsvr = {
    "NOT using dpnsvr.exe",
    "Using dpnsvr.exe"
};

static const true_false_string tfs_flags_password_required = {
    "Password required",
    "NO password required"
};

static const true_false_string tfs_flags_enumeration = {
    "Enumeration NOT allowed",
    "Enumeration allowed"
};

static const true_false_string tfs_flags_fast = {
    "Using Fast signing",
    "NOT using Fast signing"
};

static const true_false_string tfs_flags_full = {
    "Using Full signing",
    "NOT using Full signing"
};


static int * const desc_flags[] = {
    &hf_dpnet_desc_client_server,
    &hf_dpnet_desc_migrate_host,
    &hf_dpnet_desc_nodpnsvr,
    &hf_dpnet_desc_req_password,
    &hf_dpnet_desc_no_enums,
    &hf_dpnet_desc_fast_signed,
    &hf_dpnet_desc_full_signed,
    NULL
};

static int * const command_flags[] = {
    &hf_dpnet_command_data,
    &hf_dpnet_command_reliable,
    &hf_dpnet_command_seq,
    &hf_dpnet_command_poll,
    &hf_dpnet_command_new_msg,
    &hf_dpnet_command_end_msg,
    &hf_dpnet_command_user1,
    &hf_dpnet_command_user2,
    NULL
};

static void process_dpnet_query(proto_tree *dpnet_tree, tvbuff_t *tvb, packet_info *pinfo)
{
    gint offset = 0, data_tvb_len;
    guint8  has_guid;
    guint8  is_query;

    proto_tree_add_item(dpnet_tree, hf_dpnet_lead, tvb, 0, 1, ENC_BIG_ENDIAN); offset += 1;
    is_query = tvb_get_guint8(tvb, offset);
    proto_tree_add_item(dpnet_tree, hf_dpnet_command, tvb, offset, 1, ENC_BIG_ENDIAN); offset += 1;
    proto_tree_add_item(dpnet_tree, hf_dpnet_payload, tvb, offset, 2, ENC_LITTLE_ENDIAN); offset += 2;

    if(is_query == DPNET_ENUM_QUERY)
    {
        col_set_str(pinfo->cinfo, COL_INFO, "DPNET Enum Query");

        has_guid = tvb_get_guint8(tvb, offset);
        proto_tree_add_item(dpnet_tree, hf_dpnet_type, tvb, offset, 1, ENC_BIG_ENDIAN); offset += 1;

        if (has_guid & DPNET_QUERY_GUID) {
            proto_tree_add_item(dpnet_tree, hf_dpnet_application, tvb, offset, 16, ENC_BIG_ENDIAN);
            offset += 16;
        }

        data_tvb_len = tvb_reported_length_remaining(tvb, offset);
        if(data_tvb_len)
            proto_tree_add_item(dpnet_tree, hf_dpnet_data, tvb, offset, data_tvb_len, ENC_NA);

    }
    else if(is_query == DPNET_ENUM_RESPONSE)
    {
        guint32 session_offset, session_size;
        guint32 application_offset, application_size;

        col_set_str(pinfo->cinfo, COL_INFO, "DPNET Enum Response");

        proto_tree_add_item(dpnet_tree, hf_dpnet_reply_offset, tvb, offset, 4, ENC_LITTLE_ENDIAN); offset += 4;
        proto_tree_add_item(dpnet_tree, hf_dpnet_response_size, tvb, offset, 4, ENC_LITTLE_ENDIAN); offset += 4;
        proto_tree_add_item(dpnet_tree, hf_dpnet_desc_size, tvb, offset, 4, ENC_LITTLE_ENDIAN); offset += 4;
        proto_tree_add_bitmask(dpnet_tree, tvb, offset, hf_dpnet_desc_flags, ett_dpnet_desc_flags, desc_flags, ENC_LITTLE_ENDIAN);
        offset += 4;
        proto_tree_add_item(dpnet_tree, hf_dpnet_max_players, tvb, offset, 4, ENC_LITTLE_ENDIAN); offset += 4;
        proto_tree_add_item(dpnet_tree, hf_dpnet_current_players, tvb, offset, 4, ENC_LITTLE_ENDIAN); offset += 4;
        proto_tree_add_item_ret_uint(dpnet_tree, hf_dpnet_session_offset, tvb, offset, 4, ENC_LITTLE_ENDIAN, &session_offset); offset += 4;
        proto_tree_add_item_ret_uint(dpnet_tree, hf_dpnet_session_size, tvb, offset, 4, ENC_LITTLE_ENDIAN, &session_size); offset += 4;
        proto_tree_add_item(dpnet_tree, hf_dpnet_password_offset, tvb, offset, 4, ENC_LITTLE_ENDIAN); offset += 4;
        proto_tree_add_item(dpnet_tree, hf_dpnet_password_size, tvb, offset, 4, ENC_LITTLE_ENDIAN); offset += 4;
        proto_tree_add_item(dpnet_tree, hf_dpnet_reserved_offset, tvb, offset, 4, ENC_LITTLE_ENDIAN); offset += 4;
        proto_tree_add_item(dpnet_tree, hf_dpnet_reserved_size, tvb, offset, 4, ENC_LITTLE_ENDIAN); offset += 4;
        proto_tree_add_item_ret_uint(dpnet_tree, hf_dpnet_application_offset, tvb, offset, 4, ENC_LITTLE_ENDIAN, &application_offset); offset += 4;
        proto_tree_add_item_ret_uint(dpnet_tree, hf_dpnet_application_size, tvb, offset, 4, ENC_LITTLE_ENDIAN, &application_size); offset += 4;
        proto_tree_add_item(dpnet_tree, hf_dpnet_instance, tvb, offset, 16, ENC_LITTLE_ENDIAN); offset += 16;
        proto_tree_add_item(dpnet_tree, hf_dpnet_application, tvb, offset, 16, ENC_LITTLE_ENDIAN);

        if(session_offset)
        {
            /* session_offset starts from the hf_dpnet_payload */
            proto_tree_add_item(dpnet_tree, hf_dpnet_session_name, tvb, session_offset + 4, session_size, ENC_UTF_16|ENC_LITTLE_ENDIAN);
        }

        if(application_offset)
        {
            /* application_offset starts from the hf_dpnet_payload */
            proto_tree_add_item(dpnet_tree, hf_dpnet_application_data, tvb, application_offset + 4, application_size, ENC_NA);
        }
    }
}

static void
dpnet_process_data_frame(proto_tree *dpnet_tree, tvbuff_t *tvb, packet_info *pinfo)
{
    gint offset = 0;

    col_set_str(pinfo->cinfo, COL_INFO, "DPNET DFrame");

    proto_tree_add_bitmask(dpnet_tree, tvb, offset, hf_dpnet_data_command, ett_dpnet_command_flags, command_flags, ENC_BIG_ENDIAN);

    /* TODO */
}

static void
dpnet_process_control_frame(proto_tree *dpnet_tree, tvbuff_t *tvb, packet_info *pinfo)
{
    gint offset = 0;
    gint command;
    const gchar *command_str;
    gint flag;
    guint32 data_tvb_len;

    col_set_str(pinfo->cinfo, COL_INFO, "DPNET CFrame");

    proto_tree_add_bitmask(dpnet_tree, tvb, offset, hf_dpnet_data_command, ett_dpnet_command_flags, command_flags, ENC_BIG_ENDIAN);
    offset += 1;

    command = tvb_get_guint8(tvb, offset);
    command_str = val_to_str_const(command, msg_cframe_control, "Unknown Control (obsolete or malformed?)");
    col_append_fstr(pinfo->cinfo, COL_INFO, " - %s", command_str);

    proto_tree_add_item(dpnet_tree, hf_dpnet_data_cframe_control, tvb, offset, 1, ENC_LITTLE_ENDIAN);
    offset += 1;

    switch(command)
    {
        case FRAME_EXOPCODE_CONNECT:
        case FRAME_EXOPCODE_CONNECTED:
            proto_tree_add_item(dpnet_tree, hf_dpnet_data_cframe_msgid, tvb, offset, 1, ENC_LITTLE_ENDIAN);
            offset += 1;
            proto_tree_add_item(dpnet_tree, hf_dpnet_data_cframe_rspid, tvb, offset, 1, ENC_LITTLE_ENDIAN);
            offset += 1;
            proto_tree_add_item(dpnet_tree, hf_dpnet_data_cframe_protocol, tvb, offset, 4, ENC_LITTLE_ENDIAN);
            offset += 4;
            proto_tree_add_item(dpnet_tree, hf_dpnet_data_cframe_session, tvb, offset, 4, ENC_LITTLE_ENDIAN);
            offset += 4;
            proto_tree_add_item(dpnet_tree, hf_dpnet_data_cframe_timestamp, tvb, offset, 4, ENC_LITTLE_ENDIAN);
            break;
        case FRAME_EXOPCODE_CONNECTED_SIGNED:
            proto_tree_add_item(dpnet_tree, hf_dpnet_data_cframe_msgid, tvb, offset, 1, ENC_LITTLE_ENDIAN);
            offset += 1;
            proto_tree_add_item(dpnet_tree, hf_dpnet_data_cframe_rspid, tvb, offset, 1, ENC_LITTLE_ENDIAN);
            offset += 1;
            proto_tree_add_item(dpnet_tree, hf_dpnet_data_cframe_protocol, tvb, offset, 4, ENC_LITTLE_ENDIAN);
            offset += 4;
            proto_tree_add_item(dpnet_tree, hf_dpnet_data_cframe_session, tvb, offset, 4, ENC_LITTLE_ENDIAN);
            offset += 4;
            proto_tree_add_item(dpnet_tree, hf_dpnet_data_cframe_timestamp, tvb, offset, 4, ENC_LITTLE_ENDIAN);
            offset += 4;
            proto_tree_add_item(dpnet_tree, hf_dpnet_data_cframe_signature, tvb, offset, 8, ENC_NA);
            offset += 8;
            proto_tree_add_item(dpnet_tree, hf_dpnet_data_cframe_send_secret, tvb, offset, 8, ENC_NA);
            offset += 8;
            proto_tree_add_item(dpnet_tree, hf_dpnet_data_cframe_recv_secret, tvb, offset, 8, ENC_NA);
            offset += 8;
            proto_tree_add_item(dpnet_tree, hf_dpnet_data_cframe_signing_opts, tvb, offset, 4, ENC_LITTLE_ENDIAN);
            offset += 4;
            proto_tree_add_item(dpnet_tree, hf_dpnet_data_cframe_echo_time, tvb, offset, 4, ENC_LITTLE_ENDIAN);
            break;
        case FRAME_EXOPCODE_HARD_DISCONNECT:
            proto_tree_add_item(dpnet_tree, hf_dpnet_data_cframe_msgid, tvb, offset, 1, ENC_LITTLE_ENDIAN);
            offset += 1;
            proto_tree_add_item(dpnet_tree, hf_dpnet_data_cframe_rspid, tvb, offset, 1, ENC_LITTLE_ENDIAN);
            offset += 1;
            proto_tree_add_item(dpnet_tree, hf_dpnet_data_cframe_protocol, tvb, offset, 4, ENC_LITTLE_ENDIAN);
            offset += 4;
            proto_tree_add_item(dpnet_tree, hf_dpnet_data_cframe_session, tvb, offset, 4, ENC_LITTLE_ENDIAN);
            offset += 4;
            proto_tree_add_item(dpnet_tree, hf_dpnet_data_cframe_timestamp, tvb, offset, 4, ENC_LITTLE_ENDIAN);
            offset += 4;

            data_tvb_len = tvb_reported_length_remaining(tvb, offset);
            if(data_tvb_len)
                proto_tree_add_item(dpnet_tree, hf_dpnet_data_cframe_signature, tvb, offset, 8, ENC_NA);
            break;
        case FRAME_EXOPCODE_SACK:
            flag = tvb_get_guint8(tvb, offset);
            proto_tree_add_item(dpnet_tree, hf_dpnet_data_cframe_flags, tvb, offset, 1, ENC_LITTLE_ENDIAN);
            offset += 1;
            proto_tree_add_item(dpnet_tree, hf_dpnet_data_cframe_retry, tvb, offset, 1, ENC_LITTLE_ENDIAN);
            offset += 1;
            proto_tree_add_item(dpnet_tree, hf_dpnet_data_cframe_nseq, tvb, offset, 1, ENC_LITTLE_ENDIAN);
            offset += 1;
            proto_tree_add_item(dpnet_tree, hf_dpnet_data_cframe_nrcv, tvb, offset, 1, ENC_LITTLE_ENDIAN);
            offset += 1;
            proto_tree_add_item(dpnet_tree, hf_dpnet_data_cframe_padding, tvb, offset, 2, ENC_LITTLE_ENDIAN);
            offset += 2;
            proto_tree_add_item(dpnet_tree, hf_dpnet_data_cframe_timestamp, tvb, offset, 4, ENC_LITTLE_ENDIAN);
            offset += 4;

            if(flag & SACK_FLAGS_SACK_MASK1)
            {
                proto_tree_add_item(dpnet_tree, hf_dpnet_data_cframe_sack_mask1, tvb, offset, 4, ENC_LITTLE_ENDIAN);
                offset += 4;
            }
            if(flag & SACK_FLAGS_SACK_MASK2)
            {
                proto_tree_add_item(dpnet_tree, hf_dpnet_data_cframe_sack_mask2, tvb, offset, 4, ENC_LITTLE_ENDIAN);
                offset += 4;
            }
            if(flag & SACK_FLAGS_SEND_MASK1)
            {
                proto_tree_add_item(dpnet_tree, hf_dpnet_data_cframe_send_mask1, tvb, offset, 4, ENC_LITTLE_ENDIAN);
                offset += 4;
            }
            if(flag & SACK_FLAGS_SEND_MASK2)
            {
                proto_tree_add_item(dpnet_tree, hf_dpnet_data_cframe_send_mask2, tvb, offset, 4, ENC_LITTLE_ENDIAN);
            }
            break;
        default:
            break;
    }
}

static int
dissect_dpnet(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
{
    guint8  lead;

    col_set_str(pinfo->cinfo, COL_PROTOCOL, "DPNET");
    /* Clear out stuff in the info column */
    col_clear(pinfo->cinfo,COL_INFO);

    proto_item *ti = proto_tree_add_item(tree, proto_dpnet, tvb, 0, -1, ENC_NA);
    proto_tree *dpnet_tree = proto_item_add_subtree(ti, ett_dpnet);

    lead = tvb_get_guint8(tvb, 0);
    if(lead == 0)
    {
        process_dpnet_query(dpnet_tree, tvb, pinfo);
    }
    else
    {
        if(lead & DPNET_COMMAND_DATA)
            dpnet_process_data_frame(dpnet_tree, tvb, pinfo);
        else
            dpnet_process_control_frame(dpnet_tree, tvb, pinfo);
    }

    return tvb_captured_length(tvb);
}

void
proto_register_dpnet(void)
{
    static hf_register_info hf[] = {
        { &hf_dpnet_lead,
            { "Lead", "dpnet.lead",
            FT_UINT8, BASE_DEC,
            NULL, 0,
            NULL, HFILL }
        },
        { &hf_dpnet_command,
            { "Command", "dpnet.command",
            FT_UINT8, BASE_HEX,
            VALS(packetquerytype), 0,
            NULL, HFILL }
        },
        { &hf_dpnet_payload,
            { "Payload", "dpnet.payload",
            FT_UINT16, BASE_HEX,
            NULL, 0,
            NULL, HFILL }
        },
        { &hf_dpnet_type,
            { "Type", "dpnet.type",
            FT_UINT8, BASE_DEC,
            VALS(packetenumttypes), 0,
            NULL, HFILL }
        },
        { &hf_dpnet_application,
            { "Application GUID", "dpnet.application",
            FT_GUID, BASE_NONE,
            NULL, 0,
            NULL, HFILL }
        },
        { &hf_dpnet_data,
            { "Data", "dpnet.data",
            FT_BYTES, BASE_NONE,
            NULL, 0,
            NULL, HFILL }
        },
        { &hf_dpnet_reply_offset,
            { "Reply Offset", "dpnet.reply_offset",
            FT_UINT32, BASE_DEC,
            NULL, 0,
            NULL, HFILL }
        },
        { &hf_dpnet_response_size,
            { "Response Size", "dpnet.response_size",
            FT_UINT32, BASE_DEC,
            NULL, 0,
            NULL, HFILL }
        },
        { &hf_dpnet_desc_size,
            { "Description Size", "dpnet.desc_size",
            FT_UINT32, BASE_DEC,
            NULL, 0,
            NULL, HFILL }
        },
        { &hf_dpnet_desc_flags,
            { "Description Flags", "dpnet.desc_flags",
            FT_UINT16, BASE_HEX,
            NULL, 0,
            NULL, HFILL }
        },
        { &hf_dpnet_max_players,
            { "Max Players", "dpnet.max_players",
            FT_UINT32, BASE_DEC,
            NULL, 0,
            NULL, HFILL }
        },
        { &hf_dpnet_current_players,
            { "Current Players", "dpnet.current_players",
            FT_UINT32, BASE_DEC,
            NULL, 0,
            NULL, HFILL }
        },
        { &hf_dpnet_session_offset,
            { "Session Offset", "dpnet.session_offset",
            FT_UINT32, BASE_DEC,
            NULL, 0,
            NULL, HFILL }
        },
        { &hf_dpnet_session_size,
            { "Session Size", "dpnet.session_size",
            FT_UINT32, BASE_DEC,
            NULL, 0,
            NULL, HFILL }
        },
        { &hf_dpnet_session_name,
            { "Session name", "dpnet.session_name",
            FT_STRING, BASE_NONE,
            NULL, 0,
            NULL, HFILL }
        },
        { &hf_dpnet_password_offset,
            { "Password Offset", "dpnet.password_offset",
            FT_UINT32, BASE_DEC,
            NULL, 0,
            NULL, HFILL }
        },
        { &hf_dpnet_password_size,
            { "Password Size", "dpnet.password_size",
            FT_UINT32, BASE_DEC,
            NULL, 0,
            NULL, HFILL }
        },
        { &hf_dpnet_reserved_offset,
            { "Reserved Offset", "dpnet.reserved_offset",
            FT_UINT32, BASE_DEC,
            NULL, 0,
            NULL, HFILL }
        },
        { &hf_dpnet_reserved_size,
            { "Reserved Size", "dpnet.reserved_size",
            FT_UINT32, BASE_DEC,
            NULL, 0,
            NULL, HFILL }
        },
        { &hf_dpnet_application_offset,
            { "Application Offset", "dpnet.application_offset",
            FT_UINT32, BASE_DEC,
            NULL, 0,
            NULL, HFILL }
        },
        { &hf_dpnet_application_size,
            { "Application Size", "dpnet.application_size",
            FT_UINT32, BASE_DEC,
            NULL, 0,
            NULL, HFILL }
        },
        { &hf_dpnet_application_data,
            { "Application data", "dpnet.application_data",
            FT_BYTES, BASE_NONE,
            NULL, 0,
            NULL, HFILL }
        },
        { &hf_dpnet_instance,
            { "Instance GUID", "dpnet.instance",
            FT_GUID, BASE_NONE,
            NULL, 0,
            NULL, HFILL }
        },
        { &hf_dpnet_data_command,
            { "Command", "dpnet.command",
            FT_UINT8, BASE_HEX,
            NULL, 0,
            NULL, HFILL }
        },
        { &hf_dpnet_data_cframe_control,
            { "Control", "dpnet.cframe.control",
            FT_UINT8, BASE_HEX,
            VALS(msg_cframe_control), 0,
            NULL, HFILL }
        },
        { &hf_dpnet_data_cframe_msgid,
            { "Message ID", "dpnet.cframe.msg_id",
            FT_UINT8, BASE_HEX,
            NULL, 0,
            NULL, HFILL }
        },
        { &hf_dpnet_data_cframe_rspid,
            { "Response ID", "dpnet.cframe.rsp_id",
            FT_UINT8, BASE_HEX,
            NULL, 0,
            NULL, HFILL }
        },
        { &hf_dpnet_data_cframe_protocol,
            { "Protocol", "dpnet.cframe.protocol",
            FT_UINT32, BASE_HEX,
            VALS(protocol_versions), 0,
            NULL, HFILL }
        },
        { &hf_dpnet_data_cframe_session,
            { "Session", "dpnet.cframe.session",
            FT_UINT32, BASE_HEX,
            NULL, 0,
            NULL, HFILL }
        },
        { &hf_dpnet_data_cframe_timestamp,
            { "Timestamp", "dpnet.cframe.timestamp",
            FT_UINT32, BASE_DEC,
            NULL, 0,
            NULL, HFILL }
        },
        { &hf_dpnet_data_cframe_padding,
            { "Padding", "dpnet.cframe.padding",
            FT_UINT16, BASE_DEC,
            NULL, 0,
            NULL, HFILL }
        },
        { &hf_dpnet_data_cframe_flags,
            { "Flags", "dpnet.cframe.flags",
            FT_UINT8, BASE_HEX,
            VALS(sack_flags), 0,
            NULL, HFILL }
        },
        { &hf_dpnet_data_cframe_retry,
            { "Retry", "dpnet.cframe.retry",
            FT_UINT8, BASE_HEX,
            NULL, 0,
            NULL, HFILL }
        },
        { &hf_dpnet_data_cframe_nseq,
            { "Next Sequence", "dpnet.cframe.nseq",
            FT_UINT8, BASE_HEX,
            NULL, 0,
            NULL, HFILL }
        },
        { &hf_dpnet_data_cframe_nrcv,
            { "Received", "dpnet.cframe.nrcv",
            FT_UINT8, BASE_HEX,
            NULL, 0,
            NULL, HFILL }
        },
        { &hf_dpnet_data_cframe_sack_mask1,
            { "SACK Mask1", "dpnet.cframe.sack.mask1",
            FT_UINT32, BASE_HEX,
            NULL, 0,
            NULL, HFILL }
        },
        { &hf_dpnet_data_cframe_sack_mask2,
            { "SACK Mask2", "dpnet.cframe.sack.mask2",
            FT_UINT32, BASE_HEX,
            NULL, 0,
            NULL, HFILL }
        },
        { &hf_dpnet_data_cframe_send_mask1,
            { "Send Mask1", "dpnet.cframe.send.mask1",
            FT_UINT32, BASE_HEX,
            NULL, 0,
            NULL, HFILL }
        },
        { &hf_dpnet_data_cframe_send_mask2,
            { "Send Mask2", "dpnet.cframe.send.mask2",
            FT_UINT32, BASE_HEX,
            NULL, 0,
            NULL, HFILL }
        },
        { &hf_dpnet_data_cframe_signature,
            { "Signature", "dpnet.cframe.signature",
            FT_UINT64, BASE_HEX,
            NULL, 0,
            NULL, HFILL }
        },
        { &hf_dpnet_data_cframe_send_secret,
            { "Sender Secret", "dpnet.cframe.sender_secret",
            FT_UINT64, BASE_HEX,
            NULL, 0,
            NULL, HFILL }
        },
        { &hf_dpnet_data_cframe_recv_secret,
            { "Receiver Secret", "dpnet.cframe.receiver_secret",
            FT_UINT64, BASE_HEX,
            NULL, 0,
            NULL, HFILL }
        },
        { &hf_dpnet_data_cframe_signing_opts,
            { "Signing Options", "dpnet.cframe.sign_opt",
            FT_UINT32, BASE_HEX,
            VALS(signing_opts), 0,
            NULL, HFILL }
        },
        { &hf_dpnet_data_cframe_echo_time,
            { "Signing Options", "dpnet.cframe.echo_time",
            FT_UINT32, BASE_HEX,
            NULL, 0,
            NULL, HFILL }
        },
        { &hf_dpnet_data_seq,
            { "Sequence", "dpnet.sequence",
            FT_UINT8, BASE_HEX,
            NULL, 0,
            NULL, HFILL }
        },
        { &hf_dpnet_data_nseq,
            { "Next Sequence", "dpnet.next",
            FT_UINT8, BASE_HEX,
            NULL, 0,
            NULL, HFILL }
        },
        {&hf_dpnet_command_data,
            {"Control Data", "dpnet.control.data",
            FT_BOOLEAN, 8,
            NULL, DPNET_COMMAND_DATA,
            NULL, HFILL}
        },
        {&hf_dpnet_command_reliable,
            {"Reliable", "dpnet.control.reliable",
            FT_BOOLEAN, 8,
            NULL, DPNET_COMMAND_RELIABLE,
            NULL, HFILL}
        },
        {&hf_dpnet_command_seq,
            {"Sequential", "dpnet.control.sequential",
            FT_BOOLEAN, 8,
            NULL, DPNET_COMMAND_SEQUENTIAL,
            NULL, HFILL}
        },
        {&hf_dpnet_command_poll,
            {"Poll", "dpnet.control.poll",
            FT_BOOLEAN, 8,
            NULL, DPNET_COMMAND_POLL,
            NULL, HFILL}
        },
        {&hf_dpnet_command_new_msg,
            {"New Message", "dpnet.control.new_msg",
            FT_BOOLEAN, 8,
            NULL, DPNET_COMMAND_NEW_MSG,
            NULL, HFILL}
        },
        {&hf_dpnet_command_end_msg,
            {"End Message", "dpnet.control.end_msg",
            FT_BOOLEAN, 8,
            NULL, DPNET_COMMAND_END_MSG,
            NULL, HFILL}
        },
        {&hf_dpnet_command_user1,
            {"User 1", "dpnet.control.user1",
            FT_BOOLEAN, 8,
            NULL, DPNET_COMMAND_USER_1,
            NULL, HFILL}
        },
        {&hf_dpnet_command_user2,
            {"CFrame", "dpnet.control.cframe",
            FT_BOOLEAN, 8,
            NULL, DPNET_COMMAND_CFRAME,
            NULL, HFILL}
        },
        {&hf_dpnet_desc_client_server,
            {"Client", "dpnet.session.client",
            FT_BOOLEAN, 16,
            TFS(&tfs_flags_game_client), SESSION_CLIENT_SERVER,
            NULL, HFILL}
        },
        {&hf_dpnet_desc_migrate_host,
            {"Migrate", "dpnet.session.migrate",
            FT_BOOLEAN, 16,
            TFS(&tfs_flags_migrate), SESSION_MIGRATE_HOST,
            NULL, HFILL}
        },
        {&hf_dpnet_desc_nodpnsvr,
            {"dpnsvr", "dpnet.session.dpnsvr",
            FT_BOOLEAN, 16,
            TFS(&tfs_flags_dpnsvr), SESSION_NODPNSVR,
            NULL, HFILL}
        },
        {&hf_dpnet_desc_req_password,
            {"Password", "dpnet.session.password",
            FT_BOOLEAN, 16,
            TFS(&tfs_flags_password_required), SESSION_REQUIREPASSWORD,
            NULL, HFILL}
        },
        {&hf_dpnet_desc_no_enums,
            {"Enumeration", "dpnet.session.enumeration",
            FT_BOOLEAN, 16,
            TFS(&tfs_flags_enumeration), SESSION_NOENUMS,
            NULL, HFILL}
        },
        {&hf_dpnet_desc_fast_signed,
            {"Fast signing", "dpnet.session.fast_sign",
            FT_BOOLEAN, 16,
            TFS(&tfs_flags_fast), SESSION_FAST_SIGNED,
            NULL, HFILL}
        },
        {&hf_dpnet_desc_full_signed,
            {"Full signing", "dpnet.session.full_sign",
            FT_BOOLEAN, 16,
            TFS(&tfs_flags_full), SESSION_FULL_SIGNED,
            NULL, HFILL}
        },
    };

    /* Setup protocol subtree array */
    static gint *ett[] = {
        &ett_dpnet,
        &ett_dpnet_command_flags,
        &ett_dpnet_desc_flags
    };


    proto_dpnet = proto_register_protocol ("DirectPlay 8 protocol", "DPNET", "dpnet");

    proto_register_field_array(proto_dpnet, hf, array_length(hf));
    proto_register_subtree_array(ett, array_length(ett));

    dpnet_handle = register_dissector("dpnet", dissect_dpnet, proto_dpnet);
}

void
proto_reg_handoff_dpnet(void)
{
    dissector_add_uint("udp.port", DPNET_PORT, dpnet_handle);
}

/*
 * Editor modelines
 *
 * Local Variables:
 * c-basic-offset: 4
 * tab-width: 8
 * indent-tabs-mode: nil
 * End:
 *
 * ex: set shiftwidth=4 tabstop=8 expandtab:
 * :indentSize=4:tabSize=8:noTabs=true:
 */