Coverage Report

Created: 2026-08-14 06:45

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/wireshark/epan/dissectors/packet-mdp.c
Line
Count
Source
1
/* packet-mdp.c
2
 * Routines for the disassembly of the "Meraki Discovery Protocol (MDP)"
3
 *
4
 * Wireshark - Network traffic analyzer
5
 * By Gerald Combs <gerald@wireshark.org>
6
 * Copyright 1998 Gerald Combs
7
 *
8
 * SPDX-License-Identifier: GPL-2.0-or-later
9
 */
10
11
#include "config.h"
12
#include <epan/packet.h>
13
14
2.24k
#define MDP_TLV_TYPE            0
15
1.12k
#define MDP_TLV_LENGTH          1
16
50
#define MDP_TLV_DEVICE_INFO     2
17
75
#define MDP_TLV_NETWORK_INFO    3
18
41
#define MDP_TLV_LONGITUDE       4
19
31
#define MDP_TLV_LATITUDE        5
20
44
#define MDP_TLV_TYPE_SIX        6
21
46
#define MDP_TLV_TYPE_SEVEN      7
22
28
#define MDP_TLV_END             255
23
24
void proto_register_mdp(void);
25
void proto_reg_handoff_mdp(void);
26
27
static int proto_mdp;
28
static int hf_mdp_preamble_data;
29
static int hf_mdp_device_info;
30
static int hf_mdp_network_info;
31
static int hf_mdp_type;
32
static int hf_mdp_length;
33
static int hf_mdp_longitude;
34
static int hf_mdp_latitude;
35
static int hf_mdp_type_six;
36
static int hf_mdp_type_seven;
37
static int hf_mdp_data;
38
39
static int ett_mdp;
40
static int ett_mdp_tlv;
41
42
static dissector_handle_t mdp_handle;
43
44
/* Format Identifier */
45
static const value_string type_vals[] = {
46
    { MDP_TLV_DEVICE_INFO, "Device Info" },
47
    { MDP_TLV_NETWORK_INFO, "Network Info" },
48
    { MDP_TLV_LONGITUDE, "Longitude" },
49
    { MDP_TLV_LATITUDE, "Latitude" },
50
    { MDP_TLV_TYPE_SIX, "Type 6 UID" },
51
    { MDP_TLV_TYPE_SEVEN, "Type 7 UID" },
52
    { MDP_TLV_END, "End" },
53
    { 0, NULL }
54
};
55
56
static int
57
dissect_mdp(tvbuff_t *mdp_tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
58
61
{
59
61
    proto_tree  *mdp_tree, *tlv_tree;
60
61
    proto_item  *mdp_item, *tlv_item;
61
61
    uint32_t    mdp_type, mdp_length;
62
61
    unsigned offset = 0;
63
64
61
    col_set_str(pinfo->cinfo, COL_PROTOCOL, "MDP");
65
61
    col_set_str(pinfo->cinfo, COL_INFO, "MDP");
66
67
61
    mdp_item = proto_tree_add_item(tree, proto_mdp, mdp_tvb, 0, -1, ENC_NA);
68
61
    mdp_tree = proto_item_add_subtree(mdp_item, ett_mdp);
69
70
61
    proto_tree_add_item(mdp_tree, hf_mdp_preamble_data, mdp_tvb, 0, 28, ENC_NA);
71
61
    offset += 28;
72
73
1.13k
    while(tvb_reported_length_remaining(mdp_tvb, offset) != 0){
74
1.12k
  tlv_tree = proto_tree_add_subtree(mdp_tree, mdp_tvb, offset + MDP_TLV_TYPE, -1, ett_mdp_tlv, &tlv_item, "");
75
1.12k
        proto_tree_add_item_ret_uint(tlv_tree, hf_mdp_type, mdp_tvb, offset + MDP_TLV_TYPE, 1, ENC_BIG_ENDIAN, &mdp_type);
76
1.12k
        proto_item_set_text(tlv_tree, "%s", val_to_str_const(mdp_type, type_vals, "Unknown type"));
77
1.12k
        proto_tree_add_item_ret_uint(tlv_tree, hf_mdp_length, mdp_tvb, offset + MDP_TLV_LENGTH, 1, ENC_BIG_ENDIAN, &mdp_length);
78
79
1.12k
        offset += 2;
80
81
1.12k
        switch(mdp_type){
82
50
          case MDP_TLV_DEVICE_INFO:
83
50
            proto_tree_add_item(tlv_tree, hf_mdp_device_info, mdp_tvb, offset, mdp_length, ENC_UTF_8);
84
50
            break;
85
75
          case MDP_TLV_NETWORK_INFO:
86
75
            proto_tree_add_item(tlv_tree, hf_mdp_network_info, mdp_tvb, offset, mdp_length, ENC_UTF_8);
87
75
             break;
88
41
          case MDP_TLV_LONGITUDE:
89
41
            proto_tree_add_item(tlv_tree, hf_mdp_longitude, mdp_tvb, offset, mdp_length, ENC_UTF_8);
90
41
            break;
91
31
          case MDP_TLV_LATITUDE:
92
31
            proto_tree_add_item(tlv_tree, hf_mdp_latitude, mdp_tvb, offset, mdp_length, ENC_UTF_8);
93
31
            break;
94
44
          case MDP_TLV_TYPE_SIX:
95
44
            proto_tree_add_item(tlv_tree, hf_mdp_type_six, mdp_tvb, offset, mdp_length, ENC_UTF_8);
96
44
            break;
97
46
          case MDP_TLV_TYPE_SEVEN:
98
46
            proto_tree_add_item(tlv_tree, hf_mdp_type_seven, mdp_tvb, offset, mdp_length, ENC_UTF_8);
99
46
            break;
100
28
          case MDP_TLV_END:
101
28
            break;
102
801
          default:
103
801
            proto_tree_add_item(mdp_tree, hf_mdp_data, mdp_tvb, offset, mdp_length, ENC_NA);
104
801
            break;
105
1.12k
        }
106
1.07k
        proto_item_set_len(tlv_item, mdp_length + 2);
107
1.07k
        offset += mdp_length;
108
1.07k
    }
109
13
    return tvb_captured_length(mdp_tvb);
110
61
}
111
112
void
113
proto_register_mdp(void)
114
16
{
115
116
16
    static hf_register_info hf[] = {
117
16
        { &hf_mdp_preamble_data, {"Preamble Data","mdp.preamble_data", FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL }},
118
16
        { &hf_mdp_device_info, {"Device Info", "mdp.device_info", FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL }},
119
16
        { &hf_mdp_network_info, {"Network Info", "mdp.network_info", FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL }},
120
16
        { &hf_mdp_longitude, {"Longitude", "mdp.longitude", FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL }},
121
16
        { &hf_mdp_latitude, {"Latitude", "mdp.latitude", FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL }},
122
16
        { &hf_mdp_type, {"Type", "mdp.type", FT_UINT8, BASE_DEC, VALS(type_vals), 0x0, NULL, HFILL }},
123
16
        { &hf_mdp_type_six, {"Type 6 UID", "mdp.type_six", FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL }},
124
16
        { &hf_mdp_type_seven, {"Type 7 UID", "mdp.type_seven", FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL }},
125
16
        { &hf_mdp_length, {"Length", "mdp.length", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }},
126
16
        { &hf_mdp_data, {"Unknown Data", "mdp.data", FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL }}
127
16
    };
128
129
16
    static int *ett[] = {
130
16
        &ett_mdp,
131
16
        &ett_mdp_tlv
132
16
    };
133
134
16
    proto_mdp = proto_register_protocol("Meraki Discovery Protocol", "MDP", "mdp");
135
16
    proto_register_field_array(proto_mdp, hf, array_length(hf));
136
16
    proto_register_subtree_array(ett, array_length(ett));
137
138
16
    mdp_handle = register_dissector("mdp", dissect_mdp, proto_mdp);
139
16
}
140
141
void
142
proto_reg_handoff_mdp(void)
143
16
{
144
16
    dissector_add_uint("ethertype", 0x0712, mdp_handle);
145
16
    dissector_add_uint("ethertype", 0x0713, mdp_handle);
146
16
}
147
148
/*
149
 * Editor modelines  -  https://www.wireshark.org/tools/modelines.html
150
 *
151
 * Local variables:
152
 * c-basic-offset: 4
153
 * tab-width: 8
154
 * indent-tabs-mode: nil
155
 * End:
156
 *
157
 * vi: set shiftwidth=4 tabstop=8 expandtab:
158
 * :indentSize=4:tabSize=8:noTabs=true:
159
 */