Revert "TODO epan/dissectors/asn1/kerberos/packet-kerberos-template.c new GSS flags"
[wireshark-sm.git] / epan / dissectors / packet-pw-cesopsn.c
blob5c152ffc7ef0e730143f4c13859a2ed6ee0b29f1
1 /* packet-pw-satop.c
2 * Routines for CESoPSN PW dissection as per RFC5086.
3 * Copyright 2009, Dmitry Trebich, Artem Tamazov <artem.tamazov@tellabs.com>
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
11 * History:
12 * ---------------------------------
13 * 16.03.2009 initial implementation for MPLS
14 * 14.08.2009 added: support for IP/UDP demultiplexing
15 * Not supported yet:
16 * - All PW modes, except Basic NxDS0 mode.
17 * - <Optional> RTP Headers (RFC3550)
18 * - Decoding of PW payload
21 #include "config.h"
23 #include <epan/packet.h>
24 #include <epan/expert.h>
26 #include "packet-mpls.h"
27 #include "packet-pw-common.h"
29 void proto_register_pw_cesopsn(void);
30 void proto_reg_handoff_pw_cesopsn(void);
32 static int proto = -1;
33 static int ett_pw_cesopsn;
35 static int hf_cw;
36 static int hf_cw_bits03;
37 static int hf_cw_lm;
38 static int hf_cw_r;
39 static int hf_cw_frg;
40 static int hf_cw_len;
41 static int hf_cw_seq;
42 static int hf_payload;
43 static int hf_payload_l;
45 static expert_field ei_payload_size_invalid_undecoded;
46 static expert_field ei_cw_frg;
47 static expert_field ei_payload_size_invalid_error;
48 static expert_field ei_cw_bits03;
49 static expert_field ei_pref_cw_len;
50 static expert_field ei_cw_lm;
51 static expert_field ei_packet_size_too_small;
53 static dissector_handle_t pw_padding_handle;
54 static dissector_handle_t pw_cesopsn_udp_handle;
55 static dissector_handle_t pw_cesopsn_mpls_handle;
58 const char pwc_longname_pw_cesopsn[] = "CESoPSN basic NxDS0 mode (no RTP support)";
59 static const char shortname[] = "CESoPSN basic (no RTP)";
61 static const value_string vals_cw_lm[] = {
62 /* note that bitmask in hs_register_info is 0xb == 1011B */
63 /* this is why 0x8 comes just after 0x3 */
64 { 0x0, "Normal situation - no AC faults" },
65 /*{ 0x1, "Reserved combination" },*/
66 { 0x2, "AC Fault - RDI condition" },
67 { 0x3, "Reserved for CESoPSN signaling" },
68 { 0x8, "AC Fault - TDM data is invalid" },
69 /*{ 0x9, "Reserved combination" },*/
70 /*{ 0xa, "Reserved combination" },*/
71 /*{ 0xb, "Reserved combination" },*/
72 { 0, NULL }
76 static
77 void dissect_pw_cesopsn( tvbuff_t * tvb_original
78 ,packet_info * pinfo
79 ,proto_tree * tree
80 ,pwc_demux_type_t demux)
82 const int encaps_size = 4; /*RTP header in encapsulation is not supported yet*/
83 int packet_size;
84 int payload_size;
85 int padding_size;
86 int properties;
88 packet_size = tvb_reported_length_remaining(tvb_original, 0);
91 * FIXME
92 * "4" below should be replaced by something like "min_packet_size_this_dissector"
93 * Also call to dissect_try_cw_first_nibble() should be moved before this block
95 if (packet_size < 4) /* 4 is smallest size which may be sensible (for PWACH dissector) */
97 proto_item *item;
98 item = proto_tree_add_item(tree, proto, tvb_original, 0, -1, ENC_NA);
99 expert_add_info_format(pinfo, item, &ei_packet_size_too_small,
100 "PW packet size (%d) is too small to carry sensible information"
101 ,(int)packet_size);
102 col_set_str(pinfo->cinfo, COL_PROTOCOL, shortname);
103 col_set_str(pinfo->cinfo, COL_INFO, "Malformed: PW packet is too small");
104 return;
107 switch (demux)
109 case PWC_DEMUX_MPLS:
110 if (dissect_try_cw_first_nibble(tvb_original, pinfo, tree))
112 return;
114 break;
115 case PWC_DEMUX_UDP:
116 break;
117 default:
118 DISSECTOR_ASSERT_NOT_REACHED();
119 return;
122 /* check how "good" is this packet */
123 /* also decide payload length from packet size and CW */
124 properties = PWC_PACKET_PROPERTIES_T_INITIALIZER;
125 if (0 != (tvb_get_uint8(tvb_original, 0) & 0xf0 /*bits03*/))
127 properties |= PWC_CW_BAD_BITS03;
129 if (0 != (tvb_get_uint8(tvb_original, 1) & 0xc0 /*frag*/))
131 properties |= PWC_CW_BAD_FRAG;
134 /* RFC5086:
135 * [LEN (bits (10 to 15) MAY be used to carry the length of the CESoPSN
136 * packet (defined as the size of the CESoPSN header + the payload size)
137 * if it is less than 64 bytes, and MUST be set to zero otherwise.
138 * Note: If fixed RTP header is used in the encapsulation, it is
139 * considered part of the CESoPSN header.]
141 * Note that this differs from RFC4385's definition of length:
142 * [ If the MPLS payload is less than 64 bytes, the length field
143 * MUST be set to the length of the PW payload...]
145 * We will use RFC5086's definition here.
147 int cw_len;
148 int payload_size_from_packet;
150 cw_len = tvb_get_uint8(tvb_original, 1) & 0x3f;
151 payload_size_from_packet = packet_size - encaps_size;
152 if (cw_len != 0)
154 int payload_size_from_cw;
155 payload_size_from_cw = cw_len - encaps_size;
157 * Assumptions for error case,
158 * will be overwritten if no errors found:
160 payload_size = payload_size_from_packet;
161 padding_size = 0;
163 if (payload_size_from_cw < 0)
165 properties |= PWC_CW_BAD_PAYLEN_LT_0;
167 else if (payload_size_from_cw > payload_size_from_packet)
169 properties |= PWC_CW_BAD_PAYLEN_GT_PACKET;
171 else if (payload_size_from_packet >= 64)
173 properties |= PWC_CW_BAD_LEN_MUST_BE_0;
175 else /* ok */
177 payload_size = payload_size_from_cw;
178 padding_size = payload_size_from_packet - payload_size_from_cw; /* >=0 */
181 else
183 payload_size = payload_size_from_packet;
184 padding_size = 0;
189 uint8_t cw_lm;
190 cw_lm = tvb_get_uint8(tvb_original, 0) & 0x0b /*l+mod*/;
191 if (NULL == try_val_to_str(cw_lm, vals_cw_lm))
193 properties |= PWC_CW_SUSPECT_LM;
197 uint8_t l_bit, m_bits;
198 l_bit = (cw_lm & 0x08) >> 3;
199 m_bits = (cw_lm & 0x03) >> 0;
200 if ((l_bit == 0 && m_bits == 0x0) /*CESoPSN data packet - normal situation*/
201 ||(l_bit == 0 && m_bits == 0x2) /*CESoPSN data packet - RDI on the AC*/ )
203 if ((payload_size == 0) || ((payload_size % 8) != 0))
205 properties |= PWC_PAY_SIZE_BAD;
208 else if (l_bit == 1 && m_bits == 0x0) /*TDM data is invalid; payload MAY be omitted*/
210 /*allow any size of payload*/
212 else /*reserved combinations*/
214 /*allow any size of payload*/
219 /* fill up columns*/
220 col_set_str(pinfo->cinfo, COL_PROTOCOL, shortname);
221 col_clear(pinfo->cinfo, COL_INFO);
222 if (properties & PWC_ANYOF_CW_BAD)
224 col_set_str(pinfo->cinfo, COL_INFO, "CW:Bad, ");
226 else if (properties & PWC_ANYOF_CW_SUSPECT)
228 col_append_str(pinfo->cinfo, COL_INFO, "CW:Suspect, ");
231 if (properties & PWC_PAY_SIZE_BAD)
233 col_append_str(pinfo->cinfo, COL_INFO, "Payload size:Bad, ");
236 col_append_fstr(pinfo->cinfo, COL_INFO, "TDM octets:%d", (int)payload_size);
238 if (padding_size != 0)
240 col_append_fstr(pinfo->cinfo, COL_INFO, ", Padding:%d", (int)padding_size);
244 proto_item* item;
245 item = proto_tree_add_item(tree, proto, tvb_original, 0, -1, ENC_NA);
246 pwc_item_append_cw(item,tvb_get_ntohl(tvb_original, 0),true);
247 pwc_item_append_text_n_items(item,(int)payload_size,"octet");
249 proto_tree* tree2;
250 tree2 = proto_item_add_subtree(item, ett_pw_cesopsn);
252 tvbuff_t* tvb;
253 proto_item* item2;
254 tvb = tvb_new_subset_length(tvb_original, 0, PWC_SIZEOF_CW);
255 item2 = proto_tree_add_item(tree2, hf_cw, tvb, 0, -1, ENC_NA);
256 pwc_item_append_cw(item2,tvb_get_ntohl(tvb, 0),false);
258 proto_tree* tree3;
259 tree3 = proto_item_add_subtree(item, ett_pw_cesopsn);
261 proto_item* item3;
262 if (properties & PWC_CW_BAD_BITS03) /*display only if value is wrong*/
264 item3 = proto_tree_add_item(tree3, hf_cw_bits03, tvb, 0, 1, ENC_BIG_ENDIAN);
265 expert_add_info(pinfo, item3, &ei_cw_bits03);
268 item3 = proto_tree_add_item(tree3, hf_cw_lm, tvb, 0, 1, ENC_BIG_ENDIAN);
269 if (properties & PWC_CW_SUSPECT_LM)
271 expert_add_info(pinfo, item3, &ei_cw_lm);
274 proto_tree_add_item(tree3, hf_cw_r, tvb, 0, 1, ENC_BIG_ENDIAN);
276 item3 = proto_tree_add_item(tree3, hf_cw_frg, tvb, 1, 1, ENC_BIG_ENDIAN);
277 if (properties & PWC_CW_BAD_FRAG)
279 expert_add_info(pinfo, item3, &ei_cw_frg);
282 item3 = proto_tree_add_item(tree3, hf_cw_len, tvb, 1, 1, ENC_BIG_ENDIAN);
283 if (properties & PWC_CW_BAD_PAYLEN_LT_0)
285 expert_add_info_format(pinfo, item3, &ei_pref_cw_len,
286 "Bad Length: too small, must be > %d",
287 (int)encaps_size);
289 if (properties & PWC_CW_BAD_PAYLEN_GT_PACKET)
291 expert_add_info_format(pinfo, item3, &ei_pref_cw_len,
292 "Bad Length: must be <= than PSN packet size (%d)",
293 (int)packet_size);
295 if (properties & PWC_CW_BAD_LEN_MUST_BE_0)
297 expert_add_info_format(pinfo, item3, &ei_pref_cw_len,
298 "Bad Length: must be 0 if CESoPSN packet size (%d) is > 64",
299 (int)packet_size);
302 proto_tree_add_item(tree3, hf_cw_seq, tvb, 2, 2, ENC_BIG_ENDIAN);
309 /* payload */
310 if (payload_size == 0)
312 if (properties & PWC_PAY_SIZE_BAD)
314 expert_add_info_format(pinfo, item, &ei_payload_size_invalid_error,
315 "CESoPSN payload: none found. Size of payload must be <> 0");
317 else
319 expert_add_info_format(pinfo, item, &ei_payload_size_invalid_undecoded,
320 "CESoPSN payload: omitted to conserve bandwidth");
323 else
325 proto_tree* tree2;
326 tree2 = proto_item_add_subtree(item, ett_pw_cesopsn);
328 proto_item* item2;
329 tvbuff_t* tvb;
330 tvb = tvb_new_subset_length(tvb_original, PWC_SIZEOF_CW, payload_size);
331 item2 = proto_tree_add_item(tree2, hf_payload, tvb, 0, -1, ENC_NA);
332 pwc_item_append_text_n_items(item2,(int)payload_size,"octet");
333 if (properties & PWC_PAY_SIZE_BAD)
335 expert_add_info_format(pinfo, item2, &ei_payload_size_invalid_error,
336 "CESoPSN packet payload size must be multiple of 8");
338 tree2 = proto_item_add_subtree(item2, ett_pw_cesopsn);
339 call_data_dissector(tvb, pinfo, tree2);
340 item2 = proto_tree_add_int(tree2, hf_payload_l, tvb, 0, 0
341 ,(int)payload_size); /* allow filtering */
342 proto_item_set_hidden(item2);
346 /* padding */
347 if (padding_size > 0)
349 proto_tree* tree2;
350 tree2 = proto_item_add_subtree(item, ett_pw_cesopsn);
352 tvbuff_t* tvb;
353 tvb = tvb_new_subset_length_caplen(tvb_original, PWC_SIZEOF_CW + payload_size, padding_size, -1);
354 call_dissector(pw_padding_handle, tvb, pinfo, tree2);
358 return;
362 static
363 int dissect_pw_cesopsn_mpls( tvbuff_t * tvb_original, packet_info * pinfo, proto_tree * tree, void* data _U_)
365 dissect_pw_cesopsn(tvb_original,pinfo,tree,PWC_DEMUX_MPLS);
366 return tvb_captured_length(tvb_original);
370 static
371 int dissect_pw_cesopsn_udp( tvbuff_t * tvb, packet_info * pinfo, proto_tree * tree, void* data _U_)
373 dissect_pw_cesopsn(tvb,pinfo,tree,PWC_DEMUX_UDP);
374 return tvb_captured_length(tvb);
378 void proto_register_pw_cesopsn(void)
380 static hf_register_info hf[] = {
381 { &hf_cw ,{"Control Word" ,"pwcesopsn.cw"
382 ,FT_NONE ,BASE_NONE ,NULL
383 ,0 ,NULL ,HFILL }},
385 {&hf_cw_bits03,{"Bits 0 to 3" ,"pwcesopsn.cw.bits03"
386 ,FT_UINT8 ,BASE_DEC ,NULL
387 ,0xf0 ,NULL ,HFILL }},
389 { &hf_cw_lm, {"L+M bits" ,"pwcesopsn.cw.lm"
390 ,FT_UINT8 ,BASE_HEX ,VALS(vals_cw_lm)
391 ,0x0b ,NULL ,HFILL }},
393 {&hf_cw_r, {"R bit: Local CE-bound IWF" ,"pwcesopsn.cw.rbit"
394 ,FT_UINT8 ,BASE_DEC ,VALS(pwc_vals_cw_r_bit)
395 ,0x04 ,NULL ,HFILL }},
397 {&hf_cw_frg, {"Fragmentation" ,"pwcesopsn.cw.frag"
398 ,FT_UINT8 ,BASE_DEC ,VALS(pwc_vals_cw_frag)
399 ,0xc0 ,NULL ,HFILL }},
401 {&hf_cw_len, {"Length" ,"pwcesopsn.cw.length"
402 ,FT_UINT8 ,BASE_DEC ,NULL
403 ,0x3f ,NULL ,HFILL }},
405 {&hf_cw_seq, {"Sequence number" ,"pwcesopsn.cw.seqno"
406 ,FT_UINT16 ,BASE_DEC ,NULL
407 ,0 ,NULL ,HFILL }},
409 {&hf_payload ,{"TDM payload" ,"pwcesopsn.payload"
410 ,FT_BYTES ,BASE_NONE ,NULL
411 ,0 ,NULL ,HFILL }},
413 {&hf_payload_l ,{"TDM payload length" ,"pwcesopsn.payload.len"
414 ,FT_INT32 ,BASE_DEC ,NULL
415 ,0 ,NULL ,HFILL }}
418 static int *ett_array[] = {
419 &ett_pw_cesopsn
421 static ei_register_info ei[] = {
422 { &ei_packet_size_too_small, { "pwcesopsn.packet_size_too_small", PI_MALFORMED, PI_ERROR, "PW packet size is too small to carry sensible information", EXPFILL }},
423 { &ei_cw_bits03, { "pwcesopsn.cw.bits03.not_zero", PI_MALFORMED, PI_ERROR, "Bits 0..3 of Control Word must be 0", EXPFILL }},
424 { &ei_cw_lm, { "pwcesopsn.cw.lm.reserved", PI_UNDECODED, PI_WARN, "Reserved combination of L and Modifier bits", EXPFILL }},
425 { &ei_cw_frg, { "pwcesopsn.cw.frag.not_allowed", PI_MALFORMED, PI_ERROR, "Fragmentation of payload is not allowed for basic CESoPSN mode", EXPFILL }},
426 { &ei_pref_cw_len, { "pwcesopsn.cw.length.invalid", PI_MALFORMED, PI_ERROR, "Bad Length: too small", EXPFILL }},
427 { &ei_payload_size_invalid_error, { "pwcesopsn.payload.size_invalid", PI_MALFORMED, PI_ERROR, "CESoPSN payload size invalid", EXPFILL }},
428 { &ei_payload_size_invalid_undecoded, { "pwcesopsn.payload.undecoded", PI_UNDECODED, PI_NOTE, "CESoPSN payload: omitted to conserve bandwidth", EXPFILL }},
430 expert_module_t* expert_pwcesopsn;
432 proto = proto_register_protocol(pwc_longname_pw_cesopsn, shortname, "pwcesopsn");
433 proto_register_field_array(proto, hf, array_length(hf));
434 proto_register_subtree_array(ett_array, array_length(ett_array));
435 expert_pwcesopsn = expert_register_protocol(proto);
436 expert_register_field_array(expert_pwcesopsn, ei, array_length(ei));
437 pw_cesopsn_mpls_handle = register_dissector("pw_cesopsn_mpls", dissect_pw_cesopsn_mpls, proto);
438 pw_cesopsn_udp_handle = register_dissector("pw_cesopsn_udp", dissect_pw_cesopsn_udp, proto);
442 void proto_reg_handoff_pw_cesopsn(void)
444 pw_padding_handle = find_dissector_add_dependency("pw_padding", proto);
446 /* For Decode As */
447 dissector_add_for_decode_as("mpls.label", pw_cesopsn_mpls_handle);
448 dissector_add_for_decode_as("mpls.pfn", pw_cesopsn_mpls_handle);
450 dissector_add_for_decode_as_with_preference("udp.port", pw_cesopsn_udp_handle);
454 * Editor modelines - https://www.wireshark.org/tools/modelines.html
456 * Local variables:
457 * c-basic-offset: 8
458 * tab-width: 8
459 * indent-tabs-mode: t
460 * End:
462 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
463 * :indentSize=8:tabSize=8:noTabs=false: