summaryrefslogtreecommitdiffstats
path: root/epan/dissectors/packet-dpauxmon.c
blob: 4de83e9adafe1ed2e0d930bb02d00eba8fb82b63 (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
/* packet-dpauxmon.c
 * Routines for DisplayPort AUX-Channel monitor dissection
 * Copyright 2018, Dirk Eibach, Guntermann & Drunck GmbH <dirk.eibach@gdsys.cc>
 *
 * 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>
#include <epan/conversation.h>
#include <epan/proto_data.h>
#include <wiretap/wtap.h>

#include "packet-dpaux.h"

enum {
    DPAUXMON_DATA = 0x00,
    DPAUXMON_DATA_END = 0x01,
    DPAUXMON_EVENT = 0x02,
    DPAUXMON_START = 0x03,
    DPAUXMON_STOP = 0x04,
    DPAUXMON_TS_OVERFLOW = 0x84,
};

void proto_reg_handoff_dpauxmon(void);
void proto_register_dpauxmon(void);

static dissector_handle_t dpaux_handle;
static dissector_handle_t dpauxmon_handle;

/* Initialize the protocol and registered fields */
static int proto_dpauxmon;

static int hf_packet_type;
static int hf_origin;
static int hf_inputs;
static int hf_hpd;
static int hf_in0;
static int hf_in1;
static int hf_in2;

static int * const input_fields[] = {
    &hf_hpd,
    &hf_in0,
    &hf_in1,
    &hf_in2,
    NULL
};

/* Initialize the subtree pointers */
static int ett_dpauxmon;

static const value_string packet_type_vals[] = {
    { DPAUXMON_DATA, "Data" },
    { DPAUXMON_EVENT, "Event" },
    { DPAUXMON_START, "Start" },
    { DPAUXMON_STOP, "Stop" },
    { DPAUXMON_TS_OVERFLOW, "Timestamp Overflow" },
    { 0, NULL }
};

static const value_string origin_vals[] = {
    { 0, "Sink" },
    { 1, "Source" },
    { 0, NULL }
};

static int
dissect_dpauxmon(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
        void *data _U_)
{
    proto_item *ti;
    proto_tree *dpauxmon_tree;
    uint32_t packet_type;

    col_set_str(pinfo->cinfo, COL_PROTOCOL, "DPAUXMON");
    col_set_str(pinfo->cinfo, COL_RES_DL_DST, "N/A");
    col_set_str(pinfo->cinfo, COL_RES_DL_SRC, "Internal");

    /* create display subtree for the protocol */
    ti = proto_tree_add_item(tree, proto_dpauxmon, tvb, 0, -1, ENC_NA);
    dpauxmon_tree = proto_item_add_subtree(ti, ett_dpauxmon);

    proto_tree_add_item_ret_uint(dpauxmon_tree, hf_packet_type, tvb, 0, 1, ENC_NA, &packet_type);
    col_add_fstr(pinfo->cinfo, COL_INFO, "DisplayPort AUX channel - %s", val_to_str_const(packet_type, packet_type_vals, "Unknown"));

    switch (packet_type) {
    case DPAUXMON_DATA: {
        struct dpaux_info dpaux_info;

        dpaux_info.from_source = tvb_get_uint8(tvb, 1);
        proto_tree_add_uint(dpauxmon_tree, hf_origin, tvb, 1, 1, dpaux_info.from_source);

        call_dissector_with_data(dpaux_handle, tvb_new_subset_remaining(tvb, 2),
                 pinfo, dpauxmon_tree, &dpaux_info);
        break;
        }
    case DPAUXMON_EVENT:
    case DPAUXMON_START:
        proto_tree_add_bitmask(dpauxmon_tree, tvb, 1, hf_inputs, 0, input_fields,
                               ENC_BIG_ENDIAN);
        break;
    case DPAUXMON_STOP:
        break;
    case DPAUXMON_TS_OVERFLOW:
        break;
    };

    return tvb_captured_length(tvb);
}

void
proto_register_dpauxmon(void)
{
    /* Setup protocol subtree array */
    static int *ett[] = {
        &ett_dpauxmon
    };

    /* Setup list of header fields  See Section 1.5 of README.dissector for
     * details. */
    static hf_register_info hf[] = {
        { &hf_packet_type,
          { "Packet Type", "dpauxmon.packet_type",
            FT_UINT8, BASE_DEC, VALS(packet_type_vals), 0,
            NULL, HFILL }
        },
        { &hf_origin,
          { "Origin", "dpauxmon.origin",
            FT_UINT8, BASE_DEC, VALS(origin_vals), 0,
            NULL, HFILL }
        },
        { &hf_inputs,
          { "Inputs", "dpauxmon.inputs",
            FT_UINT8, BASE_HEX, NULL, 0,
            NULL, HFILL }
        },
        { &hf_hpd,
          { "Hotplug Detect", "dpauxmon.hpd",
            FT_BOOLEAN, 4, NULL, 0x1,
            NULL, HFILL }
        },
        { &hf_in0,
          { "IN0", "dpauxmon.in0",
            FT_BOOLEAN, 4, NULL, 0x2,
            NULL, HFILL }
        },
        { &hf_in1,
          { "IN1", "dpauxmon.in1",
            FT_BOOLEAN, 4, NULL, 0x4,
            NULL, HFILL }
        },
        { &hf_in2,
          { "IN2", "dpauxmon.in2",
            FT_BOOLEAN, 4, NULL, 0x8,
            NULL, HFILL }
        },
    };

    /* Register the protocol name and description */
    proto_dpauxmon = proto_register_protocol("DPAUXMON DisplayPort AUX channel monitor", "DPAUXMON", "dpauxmon");
    proto_register_field_array(proto_dpauxmon, hf, array_length(hf));
    proto_register_subtree_array(ett, array_length(ett));

    dpauxmon_handle = register_dissector("dpauxmon", dissect_dpauxmon, proto_dpauxmon);
}

void
proto_reg_handoff_dpauxmon(void)
{
    static bool initialized = false;

    dpaux_handle = find_dissector_add_dependency("dpaux", proto_dpauxmon);

    if (!initialized) {
        initialized = true;
    } else {
        dissector_delete_uint("wtap_encap", WTAP_ENCAP_DPAUXMON, dpauxmon_handle);
    }

    dissector_add_uint("wtap_encap", WTAP_ENCAP_DPAUXMON, dpauxmon_handle);
}

/*
 * Editor modelines  -  https://www.wireshark.org/tools/modelines.html
 *
 * Local variables:
 * c-basic-offset: 4
 * tab-width: 8
 * indent-tabs-mode: nil
 * End:
 *
 * vi: set shiftwidth=4 tabstop=8 expandtab:
 * :indentSize=4:tabSize=8:noTabs=true:
 */