2 * Routines for Session Multiplex Protocol (SMP) dissection
3 * January 2017 Uli Heilmeier with the help of Michael Mann
5 * Wireshark - Network traffic analyzer
6 * By Gerald Combs <gerald@wireshark.org>
7 * Copyright 1998 Gerald Combs
9 * SPDX-License-Identifier: GPL-2.0-or-later
14 * https://web.archive.org/web/20171009015219/https://msdn.microsoft.com/en-us/library/cc219643.aspx
15 * https://web.archive.org/web/20171223021159/https://msdn.microsoft.com/en-us/library/dd304523.aspx
16 * https://web.archive.org/web/20171005092351/https://docs.microsoft.com/en-us/sql/relational-databases/native-client/features/using-multiple-active-result-sets-mars
19 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
20 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
21 * | SMID | FLAGS | SID |
22 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
24 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
26 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
28 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
32 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
36 #include <epan/packet.h>
37 #include <epan/prefs.h>
38 #include <epan/decode_as.h>
40 #include "packet-tcp.h"
42 void proto_reg_handoff_smp(void);
43 void proto_register_smp(void);
45 static int proto_smp = -1;
47 static int hf_smp_smid = -1;
48 static int hf_smp_flags = -1;
49 static int hf_smp_flags_syn = -1;
50 static int hf_smp_flags_ack = -1;
51 static int hf_smp_flags_fin = -1;
52 static int hf_smp_flags_data = -1;
53 static int hf_smp_sid = -1;
54 static int hf_smp_length = -1;
55 static int hf_smp_seqnum = -1;
56 static int hf_smp_wndw = -1;
57 static int hf_smp_data = -1;
59 static gint ett_smp = -1;
60 static gint ett_smp_flags = -1;
62 #define SMP_FLAGS_SYN 0x01
63 #define SMP_FLAGS_ACK 0x02
64 #define SMP_FLAGS_FIN 0x04
65 #define SMP_FLAGS_DATA 0x08
67 #define SMP_MIN_LENGTH 16
69 static dissector_handle_t tds_handle;
70 static dissector_table_t smp_payload_table;
72 static gboolean reassemble_smp = TRUE;
74 static void smp_prompt(packet_info *pinfo _U_, gchar* result)
76 g_snprintf(result, MAX_DECODE_AS_PROMPT_LEN, "Payload as");
79 /* Code to actually dissect the packets */
81 dissect_smp_common(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, gboolean tds_payload)
84 guint remaining_bytes;
87 guint32 flags, sid, smp_length;
90 static const int *flag_fields[] = {
98 if (tvb_reported_length(tvb) < SMP_MIN_LENGTH)
101 col_set_str(pinfo->cinfo, COL_PROTOCOL, "SMP");
102 col_clear(pinfo->cinfo, COL_INFO);
104 ti = proto_tree_add_item(tree, proto_smp, tvb, 0, -1, ENC_NA);
105 smp_tree = proto_item_add_subtree(ti, ett_smp);
107 proto_tree_add_item(smp_tree, hf_smp_smid, tvb, offset, 1, ENC_NA);
110 proto_tree_add_bitmask(smp_tree, tvb, offset, hf_smp_flags, ett_smp_flags, flag_fields, ENC_NA);
111 flags = tvb_get_guint8(tvb, offset);
114 proto_tree_add_item_ret_uint(smp_tree, hf_smp_sid, tvb, offset, 2, ENC_LITTLE_ENDIAN, &sid);
115 col_append_fstr(pinfo->cinfo, COL_INFO, "SID: %u", sid);
118 if (flags & SMP_FLAGS_SYN)
119 col_append_str(pinfo->cinfo, COL_INFO, ", Syn");
120 if (flags & SMP_FLAGS_ACK)
121 col_append_str(pinfo->cinfo, COL_INFO, ", Ack");
122 if (flags & SMP_FLAGS_FIN)
123 col_append_str(pinfo->cinfo, COL_INFO, ", Fin");
124 if (flags & SMP_FLAGS_DATA)
125 col_append_str(pinfo->cinfo, COL_INFO, ", Data");
127 proto_tree_add_item_ret_uint(smp_tree, hf_smp_length, tvb, offset, 4, ENC_LITTLE_ENDIAN, &smp_length);
130 proto_tree_add_item(smp_tree, hf_smp_seqnum, tvb, offset, 4, ENC_LITTLE_ENDIAN);
133 proto_tree_add_item(smp_tree, hf_smp_wndw, tvb, offset, 4, ENC_LITTLE_ENDIAN);
136 if ((flags & SMP_FLAGS_DATA) && (tvb_reported_length(tvb) > SMP_MIN_LENGTH)) {
138 next_tvb = tvb_new_subset_remaining(tvb, offset);
140 parsed_bytes = call_dissector(tds_handle, next_tvb, pinfo, tree);
142 parsed_bytes = dissector_try_payload(smp_payload_table, next_tvb, pinfo, tree);
144 if (parsed_bytes <= 0)
146 remaining_bytes = tvb_reported_length_remaining(tvb, offset);
147 if ( remaining_bytes < (smp_length - SMP_MIN_LENGTH)) {
149 proto_tree_add_item(smp_tree, hf_smp_data, tvb, offset, remaining_bytes, ENC_NA);
150 offset += remaining_bytes;
153 proto_tree_add_item(smp_tree, hf_smp_data, tvb, offset, smp_length - SMP_MIN_LENGTH, ENC_NA);
154 offset += (smp_length - SMP_MIN_LENGTH);
158 offset += parsed_bytes;
165 static guint get_smp_pdu_len(packet_info *pinfo _U_, tvbuff_t *tvb, int offset, void *data _U_)
167 return tvb_get_letohl(tvb, offset + 4);
171 dissect_smp_pdu(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
173 return dissect_smp_common(tvb, pinfo, tree, FALSE);
176 static int dissect_smp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data)
178 if ((tvb_reported_length(tvb) > 0) && (tvb_get_guint8(tvb, 0) == 0x53)) {
179 tcp_dissect_pdus(tvb, pinfo, tree, reassemble_smp, SMP_MIN_LENGTH,
180 get_smp_pdu_len, dissect_smp_pdu, data);
182 return tvb_captured_length(tvb);
189 dissect_smp_tds(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
191 return dissect_smp_common(tvb, pinfo, tree, TRUE);
195 proto_register_smp(void)
197 static hf_register_info hf[] = {
199 { "Smid", "smp.smid", FT_UINT8, BASE_HEX, NULL, 0, NULL, HFILL }},
201 { "Flags", "smp.flags", FT_UINT8, BASE_HEX, NULL, 0, NULL, HFILL } },
203 { "Syn", "smp.flags.syn", FT_BOOLEAN, 8, TFS(&tfs_set_notset), SMP_FLAGS_SYN, NULL, HFILL }},
205 { "Ack", "smp.flags.ack", FT_BOOLEAN, 8, TFS(&tfs_set_notset), SMP_FLAGS_ACK, NULL, HFILL }},
207 { "Fin", "smp.flags.fin", FT_BOOLEAN, 8, TFS(&tfs_set_notset), SMP_FLAGS_FIN, NULL, HFILL }},
208 { &hf_smp_flags_data,
209 { "Data", "smp.flags.data", FT_BOOLEAN, 8, TFS(&tfs_set_notset), SMP_FLAGS_DATA, NULL, HFILL }},
211 { "SID", "smp.sid", FT_UINT16, BASE_DEC, NULL, 0, "Session ID", HFILL }},
213 { "Length", "smp.length", FT_UINT32, BASE_DEC, NULL, 0, NULL, HFILL }},
215 { "SeqNum", "smp.seqnum", FT_UINT32, BASE_HEX, NULL, 0, "Sequence Number", HFILL }},
217 { "Wndw", "smp.wndw", FT_UINT32, BASE_HEX, NULL, 0, "Window Size", HFILL }},
219 { "Data", "smp.data", FT_BYTES, BASE_NONE, NULL, 0, NULL, HFILL }},
222 static gint *ett[] = {
227 module_t *smp_module;
229 proto_smp = proto_register_protocol("Session Multiplex Protocol", "SMP", "smp");
231 proto_register_field_array(proto_smp, hf, array_length(hf));
232 proto_register_subtree_array(ett, array_length(ett));
233 register_dissector("smp_tds", dissect_smp_tds, proto_smp);
235 smp_payload_table = register_decode_as_next_proto(proto_smp, "SMP Payload", "smp.payload", "SMP Payload", (build_label_func*)&smp_prompt);
237 smp_module = prefs_register_protocol(proto_smp, NULL);
238 prefs_register_bool_preference(smp_module, "desegment",
239 "Reassemble SMP messages spanning multiple TCP segments",
240 "Whether the SMP dissector should reassemble messages spanning multiple TCP segments."
241 " To use this option, you must also enable \"Allow subdissectors to reassemble TCP streams\" in the TCP protocol settings.",
246 proto_reg_handoff_smp(void)
248 dissector_handle_t smp_handle;
249 smp_handle = create_dissector_handle(dissect_smp, proto_smp);
250 dissector_add_for_decode_as_with_preference("tcp.port", smp_handle);
252 tds_handle = find_dissector_add_dependency("tds", proto_smp);
256 * Editor modelines - https://www.wireshark.org/tools/modelines.html
261 * indent-tabs-mode: nil
264 * vi: set shiftwidth=4 tabstop=8 expandtab:
265 * :indentSize=4:tabSize=8:noTabs=true: