Coverage Report

Created: 2025-02-15 06:25

/src/wireshark/epan/dissectors/packet-pw-common.c
Line
Count
Source (jump to first uncovered line)
1
/* packet-pw-common.c
2
 * Common functions and objects for PWE3 dissectors.
3
 * Copyright 2009, Artem Tamazov <artem.tamazov@tellabs.com>
4
 *
5
 * Wireshark - Network traffic analyzer
6
 * By Gerald Combs <gerald@wireshark.org>
7
 * Copyright 1998 Gerald Combs
8
 *
9
 * SPDX-License-Identifier: GPL-2.0-or-later
10
 */
11
12
#include "config.h"
13
14
#include <epan/packet.h>
15
#include <wsutil/str_util.h>
16
#include "packet-pw-common.h"
17
18
void proto_register_pw_padding(void);
19
20
static const char string_ok[] = "Ok";
21
22
const value_string
23
pwc_vals_cw_l_bit[] = {
24
  { 0x0,  string_ok },
25
  { 0x1,  "Attachment Circuit Fault" },
26
  { 0,  NULL }
27
};
28
29
30
const value_string
31
pwc_vals_cw_r_bit[] = {
32
  { 0x0,  string_ok },
33
  { 0x1,  "Packet Loss State" },
34
  { 0,  NULL }
35
};
36
37
const value_string
38
pwc_vals_cw_frag[] = {
39
  { 0x0,  "Unfragmented" },
40
  { 0x1,  "First fragment" },
41
  { 0x2,  "Last fragment" },
42
  { 0x3,  "Intermediate fragment" },
43
  { 0,  NULL }
44
};
45
46
47
void pwc_item_append_cw(proto_item* item, const uint32_t cw, const bool append_text)
48
0
{
49
0
  if (item != NULL)
50
0
  {
51
0
    if (append_text)
52
0
    {
53
0
      proto_item_append_text(item, ", CW");
54
0
    }
55
0
    proto_item_append_text(item, ": 0x%.8" PRIx32, cw);
56
0
  }
57
0
  return;
58
0
}
59
60
61
void pwc_item_append_text_n_items(proto_item* item, const int n, const char * const item_text)
62
0
{
63
0
  if (item != NULL)
64
0
  {
65
0
    if (n >=0)
66
0
    {
67
0
      proto_item_append_text(item, ", %d %s%s", n, item_text, plurality(n,"","s"));
68
0
    }
69
0
  }
70
0
  return;
71
0
}
72
73
74
static int proto_pw_padding;
75
static int ett_pw_common;
76
static int hf_padding_len;
77
78
static
79
int dissect_pw_padding(tvbuff_t * tvb, packet_info * pinfo, proto_tree * tree, void* data _U_)
80
0
{
81
0
  int size;
82
0
  proto_item* item;
83
0
  proto_tree* tree_p;
84
0
  size = tvb_reported_length_remaining(tvb, 0);
85
0
  item = proto_tree_add_item(tree, proto_pw_padding, tvb, 0, -1, ENC_NA);
86
0
  pwc_item_append_text_n_items(item,size,"byte");
87
0
  tree_p = proto_item_add_subtree(item, ett_pw_common);
88
89
0
  call_data_dissector(tvb, pinfo, tree_p);
90
0
  item = proto_tree_add_int(tree_p, hf_padding_len, tvb, 0, 0, size);
91
0
  proto_item_set_hidden(item); /*allow filtering*/
92
93
0
  return tvb_captured_length(tvb);
94
0
}
95
96
void proto_register_pw_padding(void)
97
14
{
98
14
  static hf_register_info hfpadding[] = {
99
14
    {&hf_padding_len  ,{"Length"      ,"pw.padding.len"
100
14
          ,FT_INT32 ,BASE_DEC ,NULL   ,0
101
14
          ,NULL           ,HFILL }}
102
14
  };
103
14
  static int *ett_array[] = {
104
14
    &ett_pw_common
105
14
  };
106
14
  proto_pw_padding = proto_register_protocol("Pseudowire Padding","PW Padding","pw.padding");
107
14
  proto_register_field_array(proto_pw_padding, hfpadding, array_length(hfpadding));
108
14
  proto_register_subtree_array(ett_array, array_length(ett_array));
109
14
  register_dissector("pw_padding", dissect_pw_padding, proto_pw_padding);
110
14
}
111
112
113
/*
114
 * Editor modelines  -  https://www.wireshark.org/tools/modelines.html
115
 *
116
 * Local variables:
117
 * c-basic-offset: 8
118
 * tab-width: 8
119
 * indent-tabs-mode: t
120
 * End:
121
 *
122
 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
123
 * :indentSize=8:tabSize=8:noTabs=false:
124
 */