epan/dissectors/pidl/samr/samr.cnf cnf_dissect_lsa_BinaryString => lsarpc_dissect_str...
[wireshark-sm.git] / epan / dissectors / packet-sscop.c
bloba9e7535397243c9e84f29890b875801c1d0e2a10
1 /* packet-sscop.c
2 * Routines for SSCOP (Q.2110, Q.SAAL) frame disassembly
3 * Guy Harris <guy@alum.mit.edu>
5 * Wireshark - Network traffic analyzer
6 * By Gerald Combs <gerald@wireshark.org>
7 * Copyright 1998
10 * SPDX-License-Identifier: GPL-2.0-or-later
13 #include "config.h"
15 #include <epan/packet.h>
16 #include <epan/prefs.h>
17 #include <epan/proto_data.h>
19 #include <wiretap/wtap.h>
20 #include "packet-sscop.h"
22 void proto_register_sscop(void);
23 void proto_reg_handoff_sscop(void);
25 int proto_sscop;
27 static int hf_sscop_type;
28 static int hf_sscop_sq;
29 static int hf_sscop_mr;
30 static int hf_sscop_s;
31 static int hf_sscop_ps;
32 static int hf_sscop_r;
33 static int hf_sscop_stat_s;
34 static int hf_sscop_pad_length;
35 static int hf_sscop_source;
36 /* static int hf_sscop_stat_count; */
38 static int ett_sscop;
39 static int ett_stat;
41 static dissector_handle_t q2931_handle;
42 static dissector_handle_t data_handle;
43 static dissector_handle_t sscf_nni_handle;
44 static dissector_handle_t alcap_handle;
45 static dissector_handle_t nbap_handle;
47 static dissector_handle_t sscop_handle;
50 static const enum_val_t sscop_payload_dissector_options[] = {
51 { "data", "Data (no further dissection)", DATA_DISSECTOR },
52 { "Q.2931", "Q.2931", Q2931_DISSECTOR },
53 { "SSCF-NNI", "SSCF-NNI (MTP3-b)", SSCF_NNI_DISSECTOR },
54 { "ALCAP", "ALCAP", ALCAP_DISSECTOR },
55 { "NBAP", "NBAP", NBAP_DISSECTOR },
56 { NULL, NULL, 0 }
59 static unsigned sscop_payload_dissector = Q2931_DISSECTOR;
60 static dissector_handle_t default_handle;
62 static sscop_info_t sscop_info;
64 * See
66 * http://web.archive.org/web/20150408122122/http://www.protocols.com/pbook/atmsig.htm
68 * for some information on SSCOP, although, alas, not the actual PDU
69 * type values - those I got from the FreeBSD 3.2 ATM code.
73 * SSCOP PDU types.
75 #define SSCOP_TYPE_MASK 0x0f
77 #define SSCOP_BGN 0x01 /* Begin */
78 #define SSCOP_BGAK 0x02 /* Begin Acknowledge */
79 #define SSCOP_END 0x03 /* End */
80 #define SSCOP_ENDAK 0x04 /* End Acknowledge */
81 #define SSCOP_RS 0x05 /* Resynchronization */
82 #define SSCOP_RSAK 0x06 /* Resynchronization Acknowledge */
83 #define SSCOP_BGREJ 0x07 /* Begin Reject */
84 #define SSCOP_SD 0x08 /* Sequenced Data */
85 #if 0
86 #define SSCOP_SDP 0x09 /* Sequenced Data with Poll */
87 #endif
88 #define SSCOP_ER 0x09 /* Error Recovery */
89 #define SSCOP_POLL 0x0a /* Status Request */
90 #define SSCOP_STAT 0x0b /* Solicited Status Response */
91 #define SSCOP_USTAT 0x0c /* Unsolicited Status Response */
92 #define SSCOP_UD 0x0d /* Unnumbered Data */
93 #define SSCOP_MD 0x0e /* Management Data */
94 #define SSCOP_ERAK 0x0f /* Error Acknowledge */
96 #define SSCOP_S 0x10 /* Source bit in End PDU */
99 * XXX - how to distinguish SDP from ER?
101 static const value_string sscop_type_vals[] = {
102 { SSCOP_BGN, "Begin" },
103 { SSCOP_BGAK, "Begin Acknowledge" },
104 { SSCOP_END, "End" },
105 { SSCOP_ENDAK, "End Acknowledge" },
106 { SSCOP_RS, "Resynchronization" },
107 { SSCOP_RSAK, "Resynchronization Acknowledge" },
108 { SSCOP_BGREJ, "Begin Reject" },
109 { SSCOP_SD, "Sequenced Data" },
110 #if 0
111 { SSCOP_SDP, "Sequenced Data with Poll" },
112 #endif
113 { SSCOP_ER, "Error Recovery" },
114 { SSCOP_POLL, "Status Request" },
115 { SSCOP_STAT, "Solicited Status Response" },
116 { SSCOP_USTAT, "Unsolicited Status Response" },
117 { SSCOP_UD, "Unnumbered Data" },
118 { SSCOP_MD, "Management Data" },
119 { SSCOP_ERAK, "Error Acknowledge" },
120 { 0, NULL }
122 static value_string_ext sscop_type_vals_ext = VALUE_STRING_EXT_INIT(sscop_type_vals);
125 * The SSCOP "header" is a trailer, so the "offsets" are computed based
126 * on the length of the packet.
130 * PDU type.
132 #define SSCOP_PDU_TYPE (reported_length - 4) /* single byte */
135 * Begin PDU, Begin Acknowledge PDU (no N(SQ) in it), Resynchronization
136 * PDU, Resynchronization Acknowledge PDU (no N(SQ) in it in Q.SAAL),
137 * Error Recovery PDU, Error Recovery Acknoledge PDU (no N(SQ) in it).
139 #define SSCOP_N_SQ (reported_length - 5) /* One byte */
140 #define SSCOP_N_MR (reported_length - 4) /* lower 3 bytes thereof */
143 * Sequenced Data PDU (no N(PS) in it), Sequenced Data with Poll PDU,
144 * Poll PDU.
146 #define SSCOP_N_PS (reported_length - 8) /* lower 3 bytes thereof */
147 #define SSCOP_N_S (reported_length - 4) /* lower 3 bytes thereof */
150 * Solicited Status PDU, Unsolicited Status PDU (no N(PS) in it).
152 #define SSCOP_SS_N_PS (reported_length - 12) /* lower 3 bytes thereof */
153 #define SSCOP_SS_N_MR (reported_length - 8) /* lower 3 bytes thereof */
154 #define SSCOP_SS_N_R (reported_length - 4) /* lower 3 bytes thereof */
156 static void dissect_stat_list(proto_tree *tree, tvbuff_t *tvb,unsigned h) {
157 int n,i;
159 if ((n = (tvb_reported_length(tvb))/4 - h)) {
160 tree = proto_tree_add_subtree(tree,tvb,0,n*4,ett_stat,NULL,"SD List");
162 for (i = 0; i < n; i++) {
163 proto_tree_add_item(tree, hf_sscop_stat_s, tvb, i*4 + 1,3,ENC_BIG_ENDIAN);
168 extern void
169 dissect_sscop_and_payload(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, dissector_handle_t payload_handle)
171 unsigned reported_length;
172 proto_item *ti;
173 proto_tree *sscop_tree = NULL;
174 uint8_t sscop_pdu_type;
175 int pdu_len;
176 int pad_len;
177 tvbuff_t *next_tvb;
179 reported_length = tvb_reported_length(tvb); /* frame length */
180 sscop_pdu_type = tvb_get_uint8(tvb, SSCOP_PDU_TYPE);
181 sscop_info.type = sscop_pdu_type & SSCOP_TYPE_MASK;
183 col_set_str(pinfo->cinfo, COL_PROTOCOL, "SSCOP");
184 col_add_str(pinfo->cinfo, COL_INFO, val_to_str_ext(sscop_info.type, &sscop_type_vals_ext,
185 "Unknown PDU type (0x%02x)"));
188 * Find the length of the PDU and, if there's any payload and
189 * padding, the length of the padding.
191 switch (sscop_info.type) {
193 case SSCOP_SD:
194 pad_len = (sscop_pdu_type >> 6) & 0x03;
195 pdu_len = 4;
196 break;
198 case SSCOP_BGN:
199 case SSCOP_BGAK:
200 case SSCOP_BGREJ:
201 case SSCOP_END:
202 case SSCOP_RS:
203 #if 0
204 case SSCOP_SDP:
205 #endif
206 pad_len = (sscop_pdu_type >> 6) & 0x03;
207 sscop_info.payload_len = pdu_len = 8;
208 break;
210 case SSCOP_UD:
211 pad_len = (sscop_pdu_type >> 6) & 0x03;
212 sscop_info.payload_len = pdu_len = 4;
213 break;
215 default:
216 pad_len = 0;
217 pdu_len = reported_length; /* No payload, just SSCOP */
218 sscop_info.payload_len = 0;
219 break;
222 if (tree) {
223 ti = proto_tree_add_protocol_format(tree, proto_sscop, tvb,
224 reported_length - pdu_len,
225 pdu_len, "SSCOP");
226 sscop_tree = proto_item_add_subtree(ti, ett_sscop);
228 proto_tree_add_item(sscop_tree, hf_sscop_type, tvb, SSCOP_PDU_TYPE, 1,ENC_BIG_ENDIAN);
230 switch (sscop_info.type) {
232 case SSCOP_BGN:
233 case SSCOP_RS:
234 case SSCOP_ER:
235 proto_tree_add_item(sscop_tree, hf_sscop_sq, tvb, SSCOP_N_SQ, 1,ENC_BIG_ENDIAN);
236 proto_tree_add_item(sscop_tree, hf_sscop_mr, tvb, SSCOP_N_MR + 1, 3, ENC_BIG_ENDIAN);
237 break;
239 case SSCOP_END:
240 proto_tree_add_string(sscop_tree, hf_sscop_source, tvb, SSCOP_PDU_TYPE, 1,
241 (sscop_pdu_type & SSCOP_S) ? "SSCOP" : "User");
242 break;
244 case SSCOP_BGAK:
245 case SSCOP_RSAK:
246 proto_tree_add_item(sscop_tree, hf_sscop_mr, tvb, SSCOP_N_MR + 1, 3, ENC_BIG_ENDIAN);
247 break;
249 case SSCOP_ERAK:
250 proto_tree_add_item(sscop_tree, hf_sscop_mr, tvb, SSCOP_N_MR + 1, 3, ENC_BIG_ENDIAN);
251 break;
253 case SSCOP_SD:
254 proto_tree_add_item(sscop_tree, hf_sscop_s, tvb, SSCOP_N_S + 1, 3, ENC_BIG_ENDIAN);
255 break;
257 #if 0
258 case SSCOP_SDP:
259 #endif
260 case SSCOP_POLL:
261 proto_tree_add_item(sscop_tree, hf_sscop_ps, tvb, SSCOP_N_PS + 1, 3,ENC_BIG_ENDIAN);
262 proto_tree_add_item(sscop_tree, hf_sscop_s, tvb, SSCOP_N_S + 1, 3,ENC_BIG_ENDIAN);
263 break;
265 case SSCOP_STAT:
266 proto_tree_add_item(sscop_tree, hf_sscop_ps, tvb, SSCOP_SS_N_PS + 1, 3,ENC_BIG_ENDIAN);
267 proto_tree_add_item(sscop_tree, hf_sscop_mr, tvb, SSCOP_SS_N_MR + 1, 3, ENC_BIG_ENDIAN);
268 proto_tree_add_item(sscop_tree, hf_sscop_r, tvb, SSCOP_SS_N_R + 1, 3,ENC_BIG_ENDIAN);
269 dissect_stat_list(sscop_tree,tvb,3);
270 break;
272 case SSCOP_USTAT:
273 proto_tree_add_item(sscop_tree, hf_sscop_mr, tvb, SSCOP_SS_N_MR + 1, 3, ENC_BIG_ENDIAN);
274 proto_tree_add_item(sscop_tree, hf_sscop_r, tvb, SSCOP_SS_N_R + 1, 3,ENC_BIG_ENDIAN);
275 dissect_stat_list(sscop_tree,tvb,2);
276 break;
281 * Dissect the payload, if any.
283 * XXX - what about a Management Data PDU?
285 switch (sscop_info.type) {
287 case SSCOP_SD:
288 case SSCOP_UD:
289 case SSCOP_BGN:
290 case SSCOP_BGAK:
291 case SSCOP_BGREJ:
292 case SSCOP_END:
293 case SSCOP_RS:
294 #if 0
295 case SSCOP_SDP:
296 #endif
297 if (tree) {
298 proto_tree_add_uint(sscop_tree, hf_sscop_pad_length, tvb, SSCOP_PDU_TYPE, 1, pad_len);
302 * Compute length of data in PDU - subtract the trailer length
303 * and the pad length from the reported length.
305 reported_length -= (pdu_len + pad_len);
307 if (reported_length != 0) {
309 * We know that we have all of the payload, because we know we have
310 * at least 4 bytes of data after the payload, i.e. the SSCOP trailer.
311 * Therefore, we know that the captured length of the payload is
312 * equal to the length of the payload.
314 next_tvb = tvb_new_subset_length(tvb, 0, reported_length);
315 if (sscop_info.type == SSCOP_SD)
317 call_dissector(payload_handle, next_tvb, pinfo, tree);
319 break;
324 static int dissect_sscop(tvbuff_t* tvb, packet_info* pinfo,proto_tree* tree, void* data _U_)
326 struct _sscop_payload_info *p_sscop_info;
327 dissector_handle_t subdissector;
329 /* Look for packet info for subdissector information */
330 p_sscop_info = (struct _sscop_payload_info *)p_get_proto_data(wmem_file_scope(), pinfo, proto_sscop, 0);
332 if ( p_sscop_info
333 && ( subdissector = p_sscop_info->subdissector )
334 && ( subdissector == data_handle
335 || subdissector == q2931_handle
336 || subdissector == sscf_nni_handle
337 || subdissector == alcap_handle
338 || subdissector == nbap_handle) )
339 dissect_sscop_and_payload(tvb,pinfo,tree,subdissector);
340 else
341 dissect_sscop_and_payload(tvb,pinfo,tree,default_handle);
343 return tvb_captured_length(tvb);
346 /* Make sure handles for various protocols are initialized */
347 static void initialize_handles_once(void) {
348 static bool initialized = false;
349 if (!initialized) {
350 q2931_handle = find_dissector("q2931");
351 data_handle = find_dissector("data");
352 sscf_nni_handle = find_dissector("sscf-nni");
353 alcap_handle = find_dissector("alcap");
354 nbap_handle = find_dissector("nbap");
356 initialized = true;
360 bool sscop_allowed_subdissector(dissector_handle_t handle)
362 initialize_handles_once();
363 if (handle == q2931_handle || handle == data_handle
364 || handle == sscf_nni_handle || handle == alcap_handle
365 || handle == nbap_handle)
366 return true;
367 return false;
370 void
371 proto_reg_handoff_sscop(void)
373 static bool prefs_initialized = false;
375 if (!prefs_initialized) {
376 initialize_handles_once();
377 dissector_add_uint_range_with_preference("udp.port", "", sscop_handle);
378 dissector_add_uint("atm.aal5.type", TRAF_SSCOP, sscop_handle);
380 prefs_initialized = true;
383 switch(sscop_payload_dissector) {
384 case DATA_DISSECTOR: default_handle = data_handle; break;
385 case Q2931_DISSECTOR: default_handle = q2931_handle; break;
386 case SSCF_NNI_DISSECTOR: default_handle = sscf_nni_handle; break;
387 case ALCAP_DISSECTOR: default_handle = alcap_handle; break;
388 case NBAP_DISSECTOR: default_handle = nbap_handle; break;
393 void
394 proto_register_sscop(void)
396 static hf_register_info hf[] = {
397 { &hf_sscop_type, { "PDU Type", "sscop.type", FT_UINT8, BASE_HEX|BASE_EXT_STRING, &sscop_type_vals_ext, SSCOP_TYPE_MASK, NULL, HFILL }},
398 { &hf_sscop_sq, { "N(SQ)", "sscop.sq", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }},
399 { &hf_sscop_mr, { "N(MR)", "sscop.mr", FT_UINT24, BASE_DEC, NULL, 0x0, NULL, HFILL }},
400 { &hf_sscop_s, { "N(S)", "sscop.s", FT_UINT24, BASE_DEC, NULL, 0x0, NULL, HFILL }},
401 { &hf_sscop_ps, { "N(PS)", "sscop.ps", FT_UINT24, BASE_DEC, NULL, 0x0, NULL, HFILL }},
402 { &hf_sscop_r, { "N(R)", "sscop.r", FT_UINT24, BASE_DEC, NULL, 0x0, NULL, HFILL }},
403 { &hf_sscop_stat_s, { "N(S)", "sscop.stat.s", FT_UINT24, BASE_DEC, NULL, 0x0,NULL, HFILL }},
404 { &hf_sscop_pad_length, { "Pad length", "sscop.pad_length", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }},
405 { &hf_sscop_source, { "Source", "sscop.source", FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL }},
406 #if 0
407 { &hf_sscop_stat_count, { "Number of NACKed pdus", "sscop.stat.count", FT_UINT32, BASE_DEC, NULL, 0x0,NULL, HFILL }}
408 #endif
411 static int *ett[] = {
412 &ett_sscop,
413 &ett_stat
416 module_t *sscop_module;
418 proto_sscop = proto_register_protocol("SSCOP", "SSCOP", "sscop");
419 proto_register_field_array(proto_sscop, hf, array_length(hf));
420 proto_register_subtree_array(ett, array_length(ett));
422 sscop_handle = register_dissector("sscop", dissect_sscop, proto_sscop);
424 sscop_module = prefs_register_protocol(proto_sscop, proto_reg_handoff_sscop);
426 prefs_register_enum_preference(sscop_module, "payload",
427 "SSCOP payload protocol",
428 "SSCOP payload (dissector to call on SSCOP payload)",
429 (int *)&sscop_payload_dissector,
430 sscop_payload_dissector_options, false);
434 * Editor modelines - https://www.wireshark.org/tools/modelines.html
436 * Local Variables:
437 * c-basic-offset: 2
438 * tab-width: 8
439 * indent-tabs-mode: nil
440 * End:
442 * ex: set shiftwidth=2 tabstop=8 expandtab:
443 * :indentSize=2:tabSize=8:noTabs=true: