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
12 * ---------------------------------
13 * 16.03.2009 initial implementation for MPLS
14 * 14.08.2009 added: support for IP/UDP demultiplexing
16 * - All PW modes, except Basic NxDS0 mode.
17 * - <Optional> RTP Headers (RFC3550)
18 * - Decoding of PW payload
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 gint proto = -1;
33 static gint ett_pw_cesopsn = -1;
35 static int hf_cw = -1;
36 static int hf_cw_bits03 = -1;
37 static int hf_cw_lm = -1;
38 static int hf_cw_r = -1;
39 static int hf_cw_frg = -1;
40 static int hf_cw_len = -1;
41 static int hf_cw_seq = -1;
42 static int hf_payload = -1;
43 static int hf_payload_l = -1;
45 static expert_field ei_payload_size_invalid_undecoded = EI_INIT;
46 static expert_field ei_cw_frg = EI_INIT;
47 static expert_field ei_payload_size_invalid_error = EI_INIT;
48 static expert_field ei_cw_bits03 = EI_INIT;
49 static expert_field ei_pref_cw_len = EI_INIT;
50 static expert_field ei_cw_lm = EI_INIT;
51 static expert_field ei_packet_size_too_small = EI_INIT;
53 static dissector_handle_t pw_padding_handle;
54 static dissector_handle_t pw_cesopsn_udp_handle;
57 const char pwc_longname_pw_cesopsn[] = "CESoPSN basic NxDS0 mode (no RTP support)";
58 static const char shortname[] = "CESoPSN basic (no RTP)";
60 static const value_string vals_cw_lm[] = {
61 /* note that bitmask in hs_register_info is 0xb == 1011B */
62 /* this is why 0x8 comes just after 0x3 */
63 { 0x0, "Normal situation - no AC faults" },
64 /*{ 0x1, "Reserved combination" },*/
65 { 0x2, "AC Fault - RDI condition" },
66 { 0x3, "Reserved for CESoPSN signaling" },
67 { 0x8, "AC Fault - TDM data is invalid" },
68 /*{ 0x9, "Reserved combination" },*/
69 /*{ 0xa, "Reserved combination" },*/
70 /*{ 0xb, "Reserved combination" },*/
76 void dissect_pw_cesopsn( tvbuff_t * tvb_original
79 ,pwc_demux_type_t demux)
81 const int encaps_size = 4; /*RTP header in encapsulation is not supported yet*/
87 packet_size = tvb_reported_length_remaining(tvb_original, 0);
91 * "4" below should be replaced by something like "min_packet_size_this_dissector"
92 * Also call to dissect_try_cw_first_nibble() should be moved before this block
94 if (packet_size < 4) /* 4 is smallest size which may be sensible (for PWACH dissector) */
97 item = proto_tree_add_item(tree, proto, tvb_original, 0, -1, ENC_NA);
98 expert_add_info_format(pinfo, item, &ei_packet_size_too_small,
99 "PW packet size (%d) is too small to carry sensible information"
101 col_set_str(pinfo->cinfo, COL_PROTOCOL, shortname);
102 col_set_str(pinfo->cinfo, COL_INFO, "Malformed: PW packet is too small");
109 if (dissect_try_cw_first_nibble(tvb_original, pinfo, tree))
117 DISSECTOR_ASSERT_NOT_REACHED();
121 /* check how "good" is this packet */
122 /* also decide payload length from packet size and CW */
123 properties = PWC_PACKET_PROPERTIES_T_INITIALIZER;
124 if (0 != (tvb_get_guint8(tvb_original, 0) & 0xf0 /*bits03*/))
126 properties |= PWC_CW_BAD_BITS03;
128 if (0 != (tvb_get_guint8(tvb_original, 1) & 0xc0 /*frag*/))
130 properties |= PWC_CW_BAD_FRAG;
134 * [LEN (bits (10 to 15) MAY be used to carry the length of the CESoPSN
135 * packet (defined as the size of the CESoPSN header + the payload size)
136 * if it is less than 64 bytes, and MUST be set to zero otherwise.
137 * Note: If fixed RTP header is used in the encapsulation, it is
138 * considered part of the CESoPSN header.]
140 * Note that this differs from RFC4385's definition of length:
141 * [ If the MPLS payload is less than 64 bytes, the length field
142 * MUST be set to the length of the PW payload...]
144 * We will use RFC5086's definition here.
147 gint payload_size_from_packet;
149 cw_len = tvb_get_guint8(tvb_original, 1) & 0x3f;
150 payload_size_from_packet = packet_size - encaps_size;
153 gint payload_size_from_cw;
154 payload_size_from_cw = cw_len - encaps_size;
156 * Assumptions for error case,
157 * will be overwritten if no errors found:
159 payload_size = payload_size_from_packet;
162 if (payload_size_from_cw < 0)
164 properties |= PWC_CW_BAD_PAYLEN_LT_0;
166 else if (payload_size_from_cw > payload_size_from_packet)
168 properties |= PWC_CW_BAD_PAYLEN_GT_PACKET;
170 else if (payload_size_from_packet >= 64)
172 properties |= PWC_CW_BAD_LEN_MUST_BE_0;
176 payload_size = payload_size_from_cw;
177 padding_size = payload_size_from_packet - payload_size_from_cw; /* >=0 */
182 payload_size = payload_size_from_packet;
189 cw_lm = tvb_get_guint8(tvb_original, 0) & 0x0b /*l+mod*/;
190 if (NULL == try_val_to_str(cw_lm, vals_cw_lm))
192 properties |= PWC_CW_SUSPECT_LM;
196 guint8 l_bit, m_bits;
197 l_bit = (cw_lm & 0x08) >> 3;
198 m_bits = (cw_lm & 0x03) >> 0;
199 if ((l_bit == 0 && m_bits == 0x0) /*CESoPSN data packet - normal situation*/
200 ||(l_bit == 0 && m_bits == 0x2) /*CESoPSN data packet - RDI on the AC*/ )
202 if ((payload_size == 0) || ((payload_size % 8) != 0))
204 properties |= PWC_PAY_SIZE_BAD;
207 else if (l_bit == 1 && m_bits == 0x0) /*TDM data is invalid; payload MAY be omitted*/
209 /*allow any size of payload*/
211 else /*reserved combinations*/
213 /*allow any size of payload*/
219 col_set_str(pinfo->cinfo, COL_PROTOCOL, shortname);
220 col_clear(pinfo->cinfo, COL_INFO);
221 if (properties & PWC_ANYOF_CW_BAD)
223 col_set_str(pinfo->cinfo, COL_INFO, "CW:Bad, ");
225 else if (properties & PWC_ANYOF_CW_SUSPECT)
227 col_append_str(pinfo->cinfo, COL_INFO, "CW:Suspect, ");
230 if (properties & PWC_PAY_SIZE_BAD)
232 col_append_str(pinfo->cinfo, COL_INFO, "Payload size:Bad, ");
235 col_append_fstr(pinfo->cinfo, COL_INFO, "TDM octets:%d", (int)payload_size);
237 if (padding_size != 0)
239 col_append_fstr(pinfo->cinfo, COL_INFO, ", Padding:%d", (int)padding_size);
244 item = proto_tree_add_item(tree, proto, tvb_original, 0, -1, ENC_NA);
245 pwc_item_append_cw(item,tvb_get_ntohl(tvb_original, 0),TRUE);
246 pwc_item_append_text_n_items(item,(int)payload_size,"octet");
249 tree2 = proto_item_add_subtree(item, ett_pw_cesopsn);
253 tvb = tvb_new_subset_length(tvb_original, 0, PWC_SIZEOF_CW);
254 item2 = proto_tree_add_item(tree2, hf_cw, tvb, 0, -1, ENC_NA);
255 pwc_item_append_cw(item2,tvb_get_ntohl(tvb, 0),FALSE);
258 tree3 = proto_item_add_subtree(item, ett_pw_cesopsn);
261 if (properties & PWC_CW_BAD_BITS03) /*display only if value is wrong*/
263 item3 = proto_tree_add_item(tree3, hf_cw_bits03, tvb, 0, 1, ENC_BIG_ENDIAN);
264 expert_add_info(pinfo, item3, &ei_cw_bits03);
267 item3 = proto_tree_add_item(tree3, hf_cw_lm, tvb, 0, 1, ENC_BIG_ENDIAN);
268 if (properties & PWC_CW_SUSPECT_LM)
270 expert_add_info(pinfo, item3, &ei_cw_lm);
273 proto_tree_add_item(tree3, hf_cw_r, tvb, 0, 1, ENC_BIG_ENDIAN);
275 item3 = proto_tree_add_item(tree3, hf_cw_frg, tvb, 1, 1, ENC_BIG_ENDIAN);
276 if (properties & PWC_CW_BAD_FRAG)
278 expert_add_info(pinfo, item3, &ei_cw_frg);
281 item3 = proto_tree_add_item(tree3, hf_cw_len, tvb, 1, 1, ENC_BIG_ENDIAN);
282 if (properties & PWC_CW_BAD_PAYLEN_LT_0)
284 expert_add_info_format(pinfo, item3, &ei_pref_cw_len,
285 "Bad Length: too small, must be > %d",
288 if (properties & PWC_CW_BAD_PAYLEN_GT_PACKET)
290 expert_add_info_format(pinfo, item3, &ei_pref_cw_len,
291 "Bad Length: must be <= than PSN packet size (%d)",
294 if (properties & PWC_CW_BAD_LEN_MUST_BE_0)
296 expert_add_info_format(pinfo, item3, &ei_pref_cw_len,
297 "Bad Length: must be 0 if CESoPSN packet size (%d) is > 64",
301 proto_tree_add_item(tree3, hf_cw_seq, tvb, 2, 2, ENC_BIG_ENDIAN);
309 if (payload_size == 0)
311 if (properties & PWC_PAY_SIZE_BAD)
313 expert_add_info_format(pinfo, item, &ei_payload_size_invalid_error,
314 "CESoPSN payload: none found. Size of payload must be <> 0");
318 expert_add_info_format(pinfo, item, &ei_payload_size_invalid_undecoded,
319 "CESoPSN payload: omitted to conserve bandwidth");
325 tree2 = proto_item_add_subtree(item, ett_pw_cesopsn);
329 tvb = tvb_new_subset_length(tvb_original, PWC_SIZEOF_CW, payload_size);
330 item2 = proto_tree_add_item(tree2, hf_payload, tvb, 0, -1, ENC_NA);
331 pwc_item_append_text_n_items(item2,(int)payload_size,"octet");
332 if (properties & PWC_PAY_SIZE_BAD)
334 expert_add_info_format(pinfo, item2, &ei_payload_size_invalid_error,
335 "CESoPSN packet payload size must be multiple of 8");
337 tree2 = proto_item_add_subtree(item2, ett_pw_cesopsn);
338 call_data_dissector(tvb, pinfo, tree2);
339 item2 = proto_tree_add_int(tree2, hf_payload_l, tvb, 0, 0
340 ,(int)payload_size); /* allow filtering */
341 proto_item_set_hidden(item2);
346 if (padding_size > 0)
349 tree2 = proto_item_add_subtree(item, ett_pw_cesopsn);
352 tvb = tvb_new_subset_length_caplen(tvb_original, PWC_SIZEOF_CW + payload_size, padding_size, -1);
353 call_dissector(pw_padding_handle, tvb, pinfo, tree2);
362 int dissect_pw_cesopsn_mpls( tvbuff_t * tvb_original, packet_info * pinfo, proto_tree * tree, void* data _U_)
364 dissect_pw_cesopsn(tvb_original,pinfo,tree,PWC_DEMUX_MPLS);
365 return tvb_captured_length(tvb_original);
370 int dissect_pw_cesopsn_udp( tvbuff_t * tvb, packet_info * pinfo, proto_tree * tree, void* data _U_)
372 dissect_pw_cesopsn(tvb,pinfo,tree,PWC_DEMUX_UDP);
373 return tvb_captured_length(tvb);
377 void proto_register_pw_cesopsn(void)
379 static hf_register_info hf[] = {
380 { &hf_cw ,{"Control Word" ,"pwcesopsn.cw"
381 ,FT_NONE ,BASE_NONE ,NULL
384 {&hf_cw_bits03,{"Bits 0 to 3" ,"pwcesopsn.cw.bits03"
385 ,FT_UINT8 ,BASE_DEC ,NULL
386 ,0xf0 ,NULL ,HFILL }},
388 { &hf_cw_lm, {"L+M bits" ,"pwcesopsn.cw.lm"
389 ,FT_UINT8 ,BASE_HEX ,VALS(vals_cw_lm)
390 ,0x0b ,NULL ,HFILL }},
392 {&hf_cw_r, {"R bit: Local CE-bound IWF" ,"pwcesopsn.cw.rbit"
393 ,FT_UINT8 ,BASE_DEC ,VALS(pwc_vals_cw_r_bit)
394 ,0x04 ,NULL ,HFILL }},
396 {&hf_cw_frg, {"Fragmentation" ,"pwcesopsn.cw.frag"
397 ,FT_UINT8 ,BASE_DEC ,VALS(pwc_vals_cw_frag)
398 ,0xc0 ,NULL ,HFILL }},
400 {&hf_cw_len, {"Length" ,"pwcesopsn.cw.length"
401 ,FT_UINT8 ,BASE_DEC ,NULL
402 ,0x3f ,NULL ,HFILL }},
404 {&hf_cw_seq, {"Sequence number" ,"pwcesopsn.cw.seqno"
405 ,FT_UINT16 ,BASE_DEC ,NULL
408 {&hf_payload ,{"TDM payload" ,"pwcesopsn.payload"
409 ,FT_BYTES ,BASE_NONE ,NULL
412 {&hf_payload_l ,{"TDM payload length" ,"pwcesopsn.payload.len"
413 ,FT_INT32 ,BASE_DEC ,NULL
417 static gint *ett_array[] = {
420 static ei_register_info ei[] = {
421 { &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 }},
422 { &ei_cw_bits03, { "pwcesopsn.cw.bits03.not_zero", PI_MALFORMED, PI_ERROR, "Bits 0..3 of Control Word must be 0", EXPFILL }},
423 { &ei_cw_lm, { "pwcesopsn.cw.lm.reserved", PI_UNDECODED, PI_WARN, "Reserved combination of L and Modifier bits", EXPFILL }},
424 { &ei_cw_frg, { "pwcesopsn.cw.frag.not_allowed", PI_MALFORMED, PI_ERROR, "Fragmentation of payload is not allowed for basic CESoPSN mode", EXPFILL }},
425 { &ei_pref_cw_len, { "pwcesopsn.cw.length.invalid", PI_MALFORMED, PI_ERROR, "Bad Length: too small", EXPFILL }},
426 { &ei_payload_size_invalid_error, { "pwcesopsn.payload.size_invalid", PI_MALFORMED, PI_ERROR, "CESoPSN payload size invalid", EXPFILL }},
427 { &ei_payload_size_invalid_undecoded, { "pwcesopsn.payload.undecoded", PI_UNDECODED, PI_NOTE, "CESoPSN payload: omitted to conserve bandwidth", EXPFILL }},
429 expert_module_t* expert_pwcesopsn;
431 proto = proto_register_protocol(pwc_longname_pw_cesopsn, shortname, "pwcesopsn");
432 proto_register_field_array(proto, hf, array_length(hf));
433 proto_register_subtree_array(ett_array, array_length(ett_array));
434 expert_pwcesopsn = expert_register_protocol(proto);
435 expert_register_field_array(expert_pwcesopsn, ei, array_length(ei));
436 register_dissector("pw_cesopsn_mpls", dissect_pw_cesopsn_mpls, proto);
437 pw_cesopsn_udp_handle = register_dissector("pw_cesopsn_udp", dissect_pw_cesopsn_udp, proto);
441 void proto_reg_handoff_pw_cesopsn(void)
443 dissector_handle_t pw_cesopsn_mpls_handle;
445 pw_padding_handle = find_dissector_add_dependency("pw_padding", proto);
448 pw_cesopsn_mpls_handle = create_dissector_handle( dissect_pw_cesopsn_mpls, proto );
449 dissector_add_for_decode_as("mpls.label", pw_cesopsn_mpls_handle);
451 dissector_add_for_decode_as_with_preference("udp.port", pw_cesopsn_udp_handle);
455 * Editor modelines - https://www.wireshark.org/tools/modelines.html
460 * indent-tabs-mode: t
463 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
464 * :indentSize=8:tabSize=8:noTabs=false: