2 * Routines for CESoPSN PW dissection as per RFC5086.
3 * Copyright 2009, Dmitry Trebich, Artem Tamazov <artem.tamazov@tellabs.com>
7 * Wireshark - Network traffic analyzer
8 * By Gerald Combs <gerald@wireshark.org>
9 * Copyright 1998 Gerald Combs
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version 2
14 * of the License, or (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26 * ---------------------------------
27 * 16.03.2009 initial implementation for MPLS
28 * 14.08.2009 added: support for IP/UDP demultiplexing
30 * - All PW modes, except Basic NxDS0 mode.
31 * - <Optional> RTP Headers (RFC3550)
32 * - Decoding of PW payload
41 #include <epan/packet.h>
42 #include <epan/expert.h>
44 #include "packet-mpls.h"
45 #include "packet-pw-common.h"
47 static gint proto = -1;
50 static int hf_cw = -1;
51 static int hf_cw_bits03 = -1;
52 static int hf_cw_lm = -1;
53 static int hf_cw_r = -1;
54 static int hf_cw_frg = -1;
55 static int hf_cw_len = -1;
56 static int hf_cw_seq = -1;
57 static int hf_payload = -1;
58 static int hf_payload_l = -1;
60 static dissector_handle_t data_handle;
61 static dissector_handle_t pw_padding_handle;
63 const char pwc_longname_pw_cesopsn[] = "CESoPSN basic NxDS0 mode (no RTP support)";
64 static const char shortname[] = "CESoPSN basic (no RTP)";
66 static const value_string vals_cw_lm[] = {
67 /* note that bitmask in hs_register_info is 0xb == 1011B */
68 /* this is why 0x8 comes just after 0x3 */
69 { 0x0, "Normal situation - no AC faults" },
70 /*{ 0x1, "Reserved combination" },*/
71 { 0x2, "AC Fault - RDI condition" },
72 { 0x3, "Reserved for CESoPSN signaling" },
73 { 0x8, "AC Fault - TDM data is invalid" },
74 /*{ 0x9, "Reserved combination" },*/
75 /*{ 0xa, "Reserved combination" },*/
76 /*{ 0xb, "Reserved combination" },*/
82 void dissect_pw_cesopsn( tvbuff_t * tvb_original
85 ,pwc_demux_type_t demux)
87 const int encaps_size = 4; /*RTP header in encapsulation is not supported yet*/
91 pwc_packet_properties_t properties;
93 packet_size = tvb_reported_length_remaining(tvb_original, 0);
97 * "4" below should be replaced by something like "min_packet_size_this_dissector"
98 * Also call to dissect_try_cw_first_nibble() should be moved before this block
100 if (packet_size < 4) /* 4 is smallest size which may be sensible (for PWACH dissector) */
105 item = proto_tree_add_item(tree, proto, tvb_original, 0, -1, ENC_NA);
106 expert_add_info_format(pinfo, item, PI_MALFORMED, PI_ERROR,
107 "PW packet size (%d) is too small to carry sensible information"
110 if (check_col(pinfo->cinfo, COL_PROTOCOL))
112 col_set_str(pinfo->cinfo, COL_PROTOCOL, shortname);
114 col_set_str(pinfo->cinfo, COL_INFO, "Malformed: PW packet is too small");
121 if (dissect_try_cw_first_nibble(tvb_original, pinfo, tree))
129 DISSECTOR_ASSERT_NOT_REACHED();
133 /* check how "good" is this packet */
134 /* also decide payload length from packet size and CW */
135 properties = PWC_PACKET_PROPERTIES_T_INITIALIZER;
136 if (0 != (tvb_get_guint8(tvb_original, 0) & 0xf0 /*bits03*/))
138 properties |= PWC_CW_BAD_BITS03;
140 if (0 != (tvb_get_guint8(tvb_original, 1) & 0xc0 /*frag*/))
142 properties |= PWC_CW_BAD_FRAG;
146 * [LEN (bits (10 to 15) MAY be used to carry the length of the CESoPSN
147 * packet (defined as the size of the CESoPSN header + the payload size)
148 * if it is less than 64 bytes, and MUST be set to zero otherwise.
149 * Note: If fixed RTP header is used in the encapsulation, it is
150 * considered part of the CESoPSN header.]
152 * Note that this differs from RFC4385's definition of length:
153 * [ If the MPLS payload is less than 64 bytes, the length field
154 * MUST be set to the length of the PW payload...]
156 * We will use RFC5086's definition here.
159 gint payload_size_from_packet;
161 cw_len = tvb_get_guint8(tvb_original, 1) & 0x3f;
162 payload_size_from_packet = packet_size - encaps_size;
165 gint payload_size_from_cw;
166 payload_size_from_cw = cw_len - encaps_size;
168 * Assumptions for error case,
169 * will be overwritten if no errors found:
171 payload_size = payload_size_from_packet;
174 if (payload_size_from_cw < 0)
176 properties |= PWC_CW_BAD_PAYLEN_LT_0;
178 else if (payload_size_from_cw > payload_size_from_packet)
180 properties |= PWC_CW_BAD_PAYLEN_GT_PACKET;
182 else if (payload_size_from_packet >= 64)
184 properties |= PWC_CW_BAD_LEN_MUST_BE_0;
188 payload_size = payload_size_from_cw;
189 padding_size = payload_size_from_packet - payload_size_from_cw; /* >=0 */
194 payload_size = payload_size_from_packet;
201 cw_lm = tvb_get_guint8(tvb_original, 0) & 0x0b /*l+mod*/;
202 if (NULL == match_strval(cw_lm, vals_cw_lm))
204 properties |= PWC_CW_SUSPECT_LM;
208 guint8 l_bit, m_bits;
209 l_bit = (cw_lm & 0x08) >> 3;
210 m_bits = (cw_lm & 0x03) >> 0;
211 if ((l_bit == 0 && m_bits == 0x0) /*CESoPSN data packet - normal situation*/
212 ||(l_bit == 0 && m_bits == 0x2) /*CESoPSN data packet - RDI on the AC*/ )
214 if ((payload_size == 0) || ((payload_size % 8) != 0))
216 properties |= PWC_PAY_SIZE_BAD;
219 else if (l_bit == 1 && m_bits == 0x0) /*TDM data is invalid; payload MAY be omitted*/
221 /*allow any size of payload*/
223 else /*reserved combinations*/
225 /*allow any size of payload*/
231 if (check_col(pinfo->cinfo, COL_PROTOCOL))
233 col_set_str(pinfo->cinfo, COL_PROTOCOL, shortname);
235 if (check_col(pinfo->cinfo, COL_INFO))
237 col_clear(pinfo->cinfo, COL_INFO);
238 if (properties & PWC_ANYOF_CW_BAD)
240 col_append_str(pinfo->cinfo, COL_INFO, "CW:Bad, ");
242 else if (properties & PWC_ANYOF_CW_SUSPECT)
244 col_append_str(pinfo->cinfo, COL_INFO, "CW:Suspect, ");
247 if (properties & PWC_PAY_SIZE_BAD)
249 col_append_str(pinfo->cinfo, COL_INFO, "Payload size:Bad, ");
252 col_append_fstr(pinfo->cinfo, COL_INFO, "TDM octets:%d", (int)payload_size);
254 if (padding_size != 0)
256 col_append_fstr(pinfo->cinfo, COL_INFO, ", Padding:%d", (int)padding_size);
262 item = proto_tree_add_item(tree, proto, tvb_original, 0, -1, ENC_NA);
263 pwc_item_append_cw(item,tvb_get_ntohl(tvb_original, 0),TRUE);
264 pwc_item_append_text_n_items(item,(int)payload_size,"octet");
267 tree2 = proto_item_add_subtree(item, ett);
271 tvb = tvb_new_subset(tvb_original, 0, PWC_SIZEOF_CW, PWC_SIZEOF_CW);
272 item2 = proto_tree_add_item(tree2, hf_cw, tvb, 0, -1, ENC_NA);
273 pwc_item_append_cw(item2,tvb_get_ntohl(tvb, 0),FALSE);
276 tree3 = proto_item_add_subtree(item, ett);
279 if (properties & PWC_CW_BAD_BITS03) /*display only if value is wrong*/
281 item3 = proto_tree_add_item(tree3, hf_cw_bits03, tvb, 0, 1, ENC_BIG_ENDIAN);
282 expert_add_info_format(pinfo, item3, PI_MALFORMED, PI_ERROR
283 ,"Bits 0..3 of Control Word must be 0");
286 item3 = proto_tree_add_item(tree3, hf_cw_lm, tvb, 0, 1, ENC_BIG_ENDIAN);
287 if (properties & PWC_CW_SUSPECT_LM)
289 expert_add_info_format(pinfo, item3, PI_UNDECODED, PI_WARN
290 ,"Reserved combination of L and Modifier bits");
293 proto_tree_add_item(tree3, hf_cw_r, tvb, 0, 1, ENC_BIG_ENDIAN);
295 item3 = proto_tree_add_item(tree3, hf_cw_frg, tvb, 1, 1, ENC_BIG_ENDIAN);
296 if (properties & PWC_CW_BAD_FRAG)
298 expert_add_info_format(pinfo, item3, PI_MALFORMED, PI_ERROR
299 ,"Fragmentation of payload is not allowed"
300 " for basic CESoPSN mode");
303 item3 = proto_tree_add_item(tree3, hf_cw_len, tvb, 1, 1, ENC_BIG_ENDIAN);
304 if (properties & PWC_CW_BAD_PAYLEN_LT_0)
306 expert_add_info_format(pinfo, item3, PI_MALFORMED, PI_ERROR
307 ,"Bad Length: too small, must be > %d"
310 if (properties & PWC_CW_BAD_PAYLEN_GT_PACKET)
312 expert_add_info_format(pinfo, item3, PI_MALFORMED, PI_ERROR
313 ,"Bad Length: must be <= than PSN packet size (%d)"
316 if (properties & PWC_CW_BAD_LEN_MUST_BE_0)
318 expert_add_info_format(pinfo, item3, PI_MALFORMED, PI_ERROR
319 ,"Bad Length: must be 0 if CESoPSN packet size (%d) is > 64"
323 proto_tree_add_item(tree3, hf_cw_seq, tvb, 2, 2, ENC_BIG_ENDIAN);
331 if (payload_size == 0)
333 if (properties & PWC_PAY_SIZE_BAD)
335 expert_add_info_format(pinfo, item, PI_MALFORMED, PI_ERROR
336 ,"CESoPSN payload: none found. Size of payload must be <> 0");
340 expert_add_info_format(pinfo, item, PI_UNDECODED, PI_NOTE
341 ,"CESoPSN payload: omitted to conserve bandwidth");
347 tree2 = proto_item_add_subtree(item, ett);
351 tvb = tvb_new_subset(tvb_original, PWC_SIZEOF_CW, payload_size, payload_size);
352 item2 = proto_tree_add_item(tree2, hf_payload, tvb, 0, -1, ENC_NA);
353 pwc_item_append_text_n_items(item2,(int)payload_size,"octet");
354 if (properties & PWC_PAY_SIZE_BAD)
356 expert_add_info_format(pinfo, item2, PI_MALFORMED, PI_ERROR
357 ,"CESoPSN packet payload size must be multiple of 8");
359 tree2 = proto_item_add_subtree(item2, ett);
360 call_dissector(data_handle, tvb, pinfo, tree2);
361 item2 = proto_tree_add_int(tree2, hf_payload_l, tvb, 0, 0
362 ,(int)payload_size); /* allow filtering */
363 PROTO_ITEM_SET_HIDDEN(item2);
368 if (padding_size > 0)
371 tree2 = proto_item_add_subtree(item, ett);
374 tvb = tvb_new_subset(tvb_original, PWC_SIZEOF_CW + payload_size, padding_size, -1);
375 call_dissector(pw_padding_handle, tvb, pinfo, tree2);
384 void dissect_pw_cesopsn_mpls( tvbuff_t * tvb_original, packet_info * pinfo, proto_tree * tree)
386 dissect_pw_cesopsn(tvb_original,pinfo,tree,PWC_DEMUX_MPLS);
392 void dissect_pw_cesopsn_udp( tvbuff_t * tvb_original, packet_info * pinfo, proto_tree * tree)
394 dissect_pw_cesopsn(tvb_original,pinfo,tree,PWC_DEMUX_UDP);
399 void proto_register_pw_cesopsn(void)
401 static hf_register_info hf[] = {
402 { &hf_cw ,{"Control Word" ,"pwcesopsn.cw"
403 ,FT_NONE ,BASE_NONE ,NULL
405 ,{&hf_cw_bits03,{"Bits 0 to 3" ,"pwcesopsn.cw.bits03"
406 ,FT_UINT8 ,BASE_DEC ,NULL
407 ,0xf0 ,NULL ,HFILL }}
408 ,{ &hf_cw_lm, {"L+M bits" ,"pwcesopsn.cw.lm"
409 ,FT_UINT8 ,BASE_HEX ,VALS(vals_cw_lm)
410 ,0x0b ,NULL ,HFILL }}
411 ,{&hf_cw_r, {"R bit: Local CE-bound IWF" ,"pwcesopsn.cw.rbit"
412 ,FT_UINT8 ,BASE_DEC ,VALS(pwc_vals_cw_r_bit)
413 ,0x04 ,NULL ,HFILL }}
414 ,{&hf_cw_frg, {"Fragmentation" ,"pwcesopsn.cw.frag"
415 ,FT_UINT8 ,BASE_DEC ,VALS(pwc_vals_cw_frag)
416 ,0xc0 ,NULL ,HFILL }}
417 ,{&hf_cw_len, {"Length" ,"pwcesopsn.cw.length"
418 ,FT_UINT8 ,BASE_DEC ,NULL
419 ,0x3f ,NULL ,HFILL }}
420 ,{&hf_cw_seq, {"Sequence number" ,"pwcesopsn.cw.seqno"
421 ,FT_UINT16 ,BASE_DEC ,NULL
423 ,{&hf_payload ,{"TDM payload" ,"pwcesopsn.payload"
424 ,FT_BYTES ,BASE_NONE ,NULL
426 ,{&hf_payload_l ,{"TDM payload length" ,"pwcesopsn.payload.len"
427 ,FT_INT32 ,BASE_DEC ,NULL
431 static gint *ett_array[] = {
435 proto = proto_register_protocol(pwc_longname_pw_cesopsn, shortname, "pwcesopsn");
436 proto_register_field_array(proto, hf, array_length(hf));
437 proto_register_subtree_array(ett_array, array_length(ett_array));
438 register_dissector("pw_cesopsn_mpls", dissect_pw_cesopsn_mpls, proto);
439 register_dissector("pw_cesopsn_udp", dissect_pw_cesopsn_udp, proto);
444 void proto_reg_handoff_pw_cesopsn(void)
446 data_handle = find_dissector("data");
447 pw_padding_handle = find_dissector("pw_padding");
448 dissector_add_uint("mpls.label", LABEL_INVALID, find_dissector("pw_cesopsn_mpls"));
449 dissector_add_handle("udp.port", find_dissector("pw_cesopsn_udp")); /* For Decode-As */