epan/dissectors/pidl/samr/samr.cnf cnf_dissect_lsa_BinaryString => lsarpc_dissect_str...
[wireshark-sm.git] / epan / dissectors / packet-db-lsp.c
blob83f47c2deb6931a51cc1e056f12ef4bb9cc9d2c8
1 /* packet-db-lsp.c
2 * Routines for Dropbox LAN sync Protocol
4 * Copyright 2010, Stig Bjorlykke <stig@bjorlykke.org>
6 * Wireshark - Network traffic analyzer
7 * By Gerald Combs <gerald@wireshark.org>
8 * Copyright 1998 Gerald Combs
10 * SPDX-License-Identifier: GPL-2.0-or-later
13 #include "config.h"
15 #include <epan/packet.h>
16 #include <epan/asn1.h>
17 #include <epan/prefs.h>
19 #include "packet-tcp.h"
20 #include "packet-x509af.h"
22 #define PNAME "Dropbox LAN sync Protocol"
23 #define PSNAME "DB-LSP"
24 #define PFNAME "db-lsp"
26 #define PNAME_DISC "Dropbox LAN sync Discovery Protocol"
27 #define PSNAME_DISC "DB-LSP-DISC"
28 #define PFNAME_DISC "db-lsp-disc"
30 #define DB_LSP_PORT 17500
32 void proto_register_db_lsp(void);
33 void proto_reg_handoff_db_lsp(void);
35 static int proto_db_lsp;
36 static int proto_db_lsp_disc;
38 static int hf_type;
39 static int hf_magic;
40 static int hf_length;
41 static int hf_opvalue;
42 static int hf_data;
43 static int hf_value;
44 static int hf_text;
46 static int ett_db_lsp;
48 static heur_dissector_list_t heur_subdissector_list;
50 static dissector_handle_t db_lsp_tcp_handle;
51 static dissector_handle_t db_lsp_udp_handle;
53 /* Use heuristic */
54 static bool try_heuristic = true;
55 /* desegmentation of tcp payload */
56 static bool db_lsp_desegment = true;
58 #define TYPE_CONFIG 0x16
59 #define TYPE_DATA 0x17
61 static const value_string type_vals[] = {
62 { TYPE_CONFIG, "Configuration" },
63 { TYPE_DATA, "Data" },
64 { 0, NULL }
67 #define OP_CERT 0x0B
69 static const value_string op_vals[] = {
70 { OP_CERT, "Certificate" },
71 { 0, NULL }
74 static int
75 dissect_db_lsp_pdu (tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
77 proto_tree *db_lsp_tree;
78 proto_item *db_lsp_item;
79 int offset = 0;
80 uint8_t type, opvalue;
81 uint16_t magic, length;
83 col_set_str (pinfo->cinfo, COL_PROTOCOL, PSNAME);
84 col_set_str (pinfo->cinfo, COL_INFO, PNAME);
86 db_lsp_item = proto_tree_add_item (tree, proto_db_lsp, tvb, offset, -1, ENC_NA);
87 db_lsp_tree = proto_item_add_subtree (db_lsp_item, ett_db_lsp);
89 type = tvb_get_uint8 (tvb, offset);
90 proto_tree_add_item (db_lsp_tree, hf_type, tvb, offset, 1, ENC_BIG_ENDIAN);
91 offset += 1;
93 if (type == 0x80) {
94 /* Two unknown bytes */
95 offset += 2;
98 magic = tvb_get_ntohs (tvb, offset);
99 proto_tree_add_item (db_lsp_tree, hf_magic, tvb, offset, 2, ENC_BIG_ENDIAN);
100 offset += 2;
102 length = tvb_get_ntohs (tvb, offset);
103 proto_tree_add_item (db_lsp_tree, hf_length, tvb, offset, 2, ENC_BIG_ENDIAN);
104 offset += 2;
106 if (magic != 0x0301 || length > tvb_reported_length_remaining (tvb, offset)) {
107 /* Probably an unknown packet */
108 /* expert_add_info_format (pinfo, db_lsp_item, PI_UNDECODED, PI_WARN, "Unknown packet"); */
109 return 0;
112 if (type == TYPE_CONFIG) {
113 opvalue = tvb_get_uint8 (tvb, offset);
114 proto_tree_add_item (db_lsp_tree, hf_opvalue, tvb, offset, 1, ENC_BIG_ENDIAN);
116 if (opvalue == OP_CERT) {
117 /* X509 Certificate */
118 tvbuff_t *cert_tvb = tvb_new_subset_length (tvb, offset+10, length-10);
119 dissect_x509af_Certificate_PDU (cert_tvb, pinfo, db_lsp_tree, NULL);
120 } else {
121 proto_tree_add_item (db_lsp_tree, hf_value, tvb, offset, length, ENC_NA);
123 } else if (type == TYPE_DATA) {
124 proto_tree_add_item (db_lsp_tree, hf_data, tvb, offset, length, ENC_NA);
125 } else {
126 proto_tree_add_item (db_lsp_tree, hf_value, tvb, offset, length, ENC_NA);
128 /*offset += length;*/
130 proto_item_append_text (db_lsp_item, ", Type: %d, Length: %d", type, length);
131 proto_item_set_len (db_lsp_item, length + 5);
132 return tvb_reported_length(tvb);
135 static unsigned
136 get_db_lsp_pdu_len (packet_info *pinfo _U_, tvbuff_t *tvb,
137 int offset, void *data _U_)
139 if (tvb_get_ntohs (tvb, offset + 1) != 0x0301) {
140 /* Unknown data, eat remaining data for this frame */
141 return tvb_reported_length_remaining (tvb, offset);
144 return tvb_get_ntohs (tvb, offset + 3) + 5;
147 static int
148 dissect_db_lsp_tcp (tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data)
150 tcp_dissect_pdus (tvb, pinfo, tree, db_lsp_desegment, 5,
151 get_db_lsp_pdu_len, dissect_db_lsp_pdu, data);
152 return tvb_reported_length(tvb);
155 static int
156 dissect_db_lsp_disc (tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
158 proto_tree *db_lsp_tree;
159 proto_item *db_lsp_item;
160 int offset = 0;
161 heur_dtbl_entry_t *hdtbl_entry;
162 proto_tree *data_subtree;
164 col_set_str (pinfo->cinfo, COL_PROTOCOL, PSNAME_DISC);
165 col_set_str (pinfo->cinfo, COL_INFO, PNAME_DISC);
167 db_lsp_item = proto_tree_add_item (tree, proto_db_lsp_disc, tvb, offset, -1, ENC_NA);
168 db_lsp_tree = proto_item_add_subtree (db_lsp_item, ett_db_lsp);
170 /* try the heuristic dissectors */
171 if (try_heuristic) {
172 data_subtree = proto_item_add_subtree(db_lsp_item, ett_db_lsp);
173 if (dissector_try_heuristic(heur_subdissector_list, tvb, pinfo, data_subtree, &hdtbl_entry, NULL)) {
174 return tvb_captured_length(tvb);
178 /* heuristic failed. Print remaining bytes as text */
179 proto_tree_add_item (db_lsp_tree, hf_text, tvb, offset, -1, ENC_ASCII);
180 return tvb_captured_length(tvb);
183 void
184 proto_register_db_lsp (void)
186 static hf_register_info hf[] = {
187 { &hf_type,
188 { "Type", "db-lsp.type",
189 FT_UINT8, BASE_DEC_HEX, VALS(type_vals), 0x0,
190 NULL, HFILL } },
192 { &hf_magic,
193 { "Magic", "db-lsp.magic",
194 FT_UINT16, BASE_DEC_HEX, NULL, 0x0,
195 "Magic number", HFILL } },
197 { &hf_length,
198 { "Length", "db-lsp.length",
199 FT_UINT16, BASE_DEC_HEX, NULL, 0x0,
200 "Length in bytes", HFILL } },
202 { &hf_opvalue,
203 { "OP Value", "db-lsp.op",
204 FT_UINT8, BASE_DEC_HEX, VALS(op_vals), 0x0,
205 NULL, HFILL } },
207 { &hf_value,
208 { "Value", "db-lsp.value",
209 FT_BYTES, BASE_NONE, NULL, 0x0,
210 NULL, HFILL } },
212 { &hf_data,
213 { "Data", "db-lsp.data",
214 FT_BYTES, BASE_NONE, NULL, 0x0,
215 NULL, HFILL } },
217 { &hf_text,
218 { "Text", "db-lsp.text",
219 FT_STRING, BASE_NONE, NULL, 0x0,
220 NULL, HFILL } },
223 static int *ett[] = {
224 &ett_db_lsp,
227 module_t *db_lsp_module;
229 proto_db_lsp = proto_register_protocol (PNAME, PSNAME, PFNAME);
230 proto_db_lsp_disc = proto_register_protocol (PNAME_DISC, PSNAME_DISC, PFNAME_DISC);
231 db_lsp_tcp_handle = register_dissector ("db-lsp.tcp", dissect_db_lsp_tcp, proto_db_lsp);
232 db_lsp_udp_handle = register_dissector ("db-lsp.udp", dissect_db_lsp_disc, proto_db_lsp_disc);
234 heur_subdissector_list = register_heur_dissector_list_with_description("db-lsp", PSNAME_DISC " payload", proto_db_lsp);
236 proto_register_field_array (proto_db_lsp, hf, array_length (hf));
237 proto_register_subtree_array (ett, array_length (ett));
239 /* Register our configuration options */
240 db_lsp_module = prefs_register_protocol (proto_db_lsp, NULL);
242 prefs_register_bool_preference (db_lsp_module, "desegment_pdus",
243 "Reassemble PDUs spanning multiple TCP segments",
244 "Whether the LAN sync dissector should reassemble PDUs"
245 " spanning multiple TCP segments."
246 " To use this option, you must also enable \"Allow subdissectors"
247 " to reassemble TCP streams\" in the TCP protocol settings.",
248 &db_lsp_desegment);
250 prefs_register_bool_preference(db_lsp_module, "try_heuristic",
251 "Try heuristic sub-dissectors",
252 "Try to decode the payload using an heuristic sub-dissector",
253 &try_heuristic);
256 void
257 proto_reg_handoff_db_lsp (void)
259 dissector_add_uint_with_preference("tcp.port", DB_LSP_PORT, db_lsp_tcp_handle);
260 dissector_add_uint_with_preference("udp.port", DB_LSP_PORT, db_lsp_udp_handle);
264 * Editor modelines
266 * Local Variables:
267 * c-basic-offset: 2
268 * tab-width: 8
269 * indent-tabs-mode: nil
270 * End:
272 * ex: set shiftwidth=2 tabstop=8 expandtab:
273 * :indentSize=2:tabSize=8:noTabs=true: