Coverage Report

Created: 2026-06-30 07:22

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/wireshark/epan/dissectors/packet-pw-hdlc.c
Line
Count
Source
1
/* packet-pw-hdlc.c
2
 * Routines for HDLC PW dissection as per RFC4618.
3
 * Copyright 2009, Dmitry Trebich, 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
 * History:
12
 * ---------------------------------
13
 * 02.03.2009 Initial implementation, supports:
14
 * - HDLC mode (rfc4618 5.1), no CW, payload is PPP (PPP in HDLC-like Framing (rfc1662)).
15
 * - FR port mode (rfc4618 5.2), no CW.
16
 *
17
 * [informative: Not supported yet:
18
 * - All kinds of HDLC PW with CW.
19
 * - PPP mode (rfc4618 5.3).
20
 * - For HDLC mode, decoding payloads other than PPP.]
21
 */
22
23
#include "config.h"
24
25
#include <epan/packet.h>
26
27
28
void proto_register_pw_hdlc(void);
29
void proto_reg_handoff_pw_hdlc(void);
30
31
static dissector_handle_t ppp_handle;
32
static dissector_handle_t fr_handle;
33
static dissector_handle_t pw_hdlc_nocw_fr_handle;
34
static dissector_handle_t pw_ppp_handle;
35
36
static int proto_pw_hdlc_nocw_fr;
37
static int proto_pw_hdlc_nocw_hdlc_ppp;
38
39
static int ett_pw_hdlc;
40
41
/* static int hf_pw_hdlc; */
42
static int hf_pw_hdlc_address_field;
43
static int hf_pw_hdlc_address;
44
static int hf_pw_hdlc_cr_bit;
45
static int hf_pw_hdlc_control_field;
46
static int hf_pw_hdlc_pf_bit;
47
static int hf_pw_hdlc_modifier;
48
static int hf_pw_hdlc_frame;
49
50
static const value_string pw_hdlc_modifier_vals[] = {
51
  {0x00, "UI - Unnumbered information" },
52
  {0x08, "UP - Unnumbered poll" },
53
  {0x10, "DISC/RD - Disconnect/Request disconnect" },
54
  {0x18, "UA - Unnumbered acknowledgment" },
55
  {0x20, "SNRM - Set normal response mode" },
56
  {0x38, "TEST - Test" },
57
  {0x01, "SIM/RIM - Set initialization mode/Request initialization mode" },
58
  {0x21, "FRMR - Frame reject" },
59
  {0x03, "SARM/DM - Set asynchronous response mode/Disconnect mode" },
60
  {0x0B, "SABM - Set asynchronous balanced mode" },
61
  {0x13, "SARME - Set asynchronous response extended mode" },
62
  {0x1B, "SABME - Set asynchronous balanced extended mode" },
63
  {0x23, "RSET - Reset" },
64
  {0x2B, "XID - Exchange identification" },
65
  {0x33, "SNRME - Set normal response extended mode" },
66
  {0, NULL }
67
};
68
69
static int dissect_pw_hdlc_nocw_fr( tvbuff_t * tvb, packet_info * pinfo, proto_tree * tree, void* data _U_ )
70
0
{
71
0
  return call_dissector( fr_handle, tvb, pinfo, tree );
72
0
}
73
74
75
static int dissect_pw_hdlc_nocw_hdlc_ppp( tvbuff_t * tvb, packet_info * pinfo, proto_tree * tree, void* data _U_ )
76
0
{
77
0
  if (tvb_reported_length_remaining(tvb, 0) < 2)
78
0
  {
79
0
    return 0;
80
0
  }
81
82
0
  if (tree)
83
0
  {
84
0
    proto_tree  *tr;
85
0
    proto_item  *item;
86
0
    proto_item  *item_address;
87
0
    proto_item  *item_control;
88
0
    uint8_t     addr;
89
0
    uint8_t     control;
90
91
0
    addr  = tvb_get_uint8(tvb, 0);
92
0
    control = tvb_get_uint8(tvb, 1);
93
94
0
    item = proto_tree_add_item( tree, proto_pw_hdlc_nocw_hdlc_ppp, tvb, 0, 2, ENC_NA );
95
96
0
    tr = proto_item_add_subtree( item, ett_pw_hdlc );
97
98
0
    item_address = proto_tree_add_item( tr, hf_pw_hdlc_address_field, tvb, 0, 1, ENC_BIG_ENDIAN );
99
0
    item_control = proto_tree_add_item( tr, hf_pw_hdlc_control_field, tvb, 1, 1, ENC_BIG_ENDIAN );
100
101
0
    tr = proto_item_add_subtree( item_address, ett_pw_hdlc );
102
103
0
    if ( 0x3F == (( addr & 0xFC ) >> 2 ))
104
0
      proto_tree_add_uint_format_value( tr, hf_pw_hdlc_address, tvb, 0, 1, 0xFC, "0x%x (All stations)", 0x3F );
105
0
    else
106
0
      proto_tree_add_uint( tr, hf_pw_hdlc_address, tvb, 0, 1, ( addr & 0xFC ) >> 2 );
107
108
0
    proto_tree_add_uint( tr, hf_pw_hdlc_cr_bit, tvb, 0, 1, ( addr & 2 ) >> 1 );
109
110
0
    tr = proto_item_add_subtree( item_control, ett_pw_hdlc );
111
112
0
    if ( control & 1 )
113
0
    {
114
0
      if ( control & 2 )
115
0
      {
116
0
        proto_tree_add_uint_format( tr, hf_pw_hdlc_frame, tvb, 1, 1, control, "U frame" );
117
118
0
        proto_tree_add_uint( tr, hf_pw_hdlc_pf_bit, tvb, 1, 1, ( control & 0x10 ) >> 4 );
119
0
        proto_tree_add_uint( tr, hf_pw_hdlc_modifier, tvb, 1, 1, (control & 0xEC) >> 2);
120
0
      }
121
0
      else
122
0
      {
123
0
        proto_tree_add_uint_format( tr, hf_pw_hdlc_frame, tvb, 1, 1, control, "S frame" );
124
0
      }
125
0
    }
126
0
    else
127
0
    {
128
0
      proto_tree_add_uint_format( tr, hf_pw_hdlc_frame, tvb, 1, 1, control, "I frame" );
129
0
    }
130
0
  }
131
132
0
  call_dissector( ppp_handle, tvb_new_subset_remaining(tvb, 2), pinfo, tree );
133
0
  return tvb_captured_length(tvb);
134
0
}
135
136
void proto_register_pw_hdlc(void)
137
14
{
138
14
  static hf_register_info hf[] = {
139
#if 0
140
    {
141
      &hf_pw_hdlc,
142
      {
143
        "PW HDLC", "pw_hdlc", FT_NONE, BASE_NONE, NULL, 0x0, NULL, HFILL
144
      }
145
    },
146
#endif
147
14
    {
148
14
      &hf_pw_hdlc_address_field,
149
14
      {
150
14
        "Address field", "pw_hdlc.address_field",
151
14
        FT_UINT8, BASE_HEX, NULL, 0x0, NULL, HFILL
152
14
      }
153
14
    },
154
14
    {
155
14
      &hf_pw_hdlc_address,
156
14
      {
157
14
        "Address", "pw_hdlc.address",
158
14
        FT_UINT8, BASE_HEX, NULL, 0x0, NULL, HFILL
159
14
      }
160
14
    },
161
14
    {
162
14
      &hf_pw_hdlc_cr_bit,
163
14
      {
164
14
        "C/R bit", "pw_hdlc.cr_bit",
165
14
        FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL
166
14
      }
167
14
    },
168
14
    {
169
14
      &hf_pw_hdlc_control_field,
170
14
      {
171
14
        "Control field", "pw_hdlc.control_field",
172
14
        FT_UINT8, BASE_HEX, NULL, 0x0, NULL, HFILL
173
14
      }
174
14
    },
175
14
    {
176
14
      &hf_pw_hdlc_pf_bit,
177
14
      {
178
14
        "Poll/Final bit", "pw_hdlc.pf_bit",
179
14
        FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL
180
14
      }
181
14
    },
182
14
    {
183
14
      &hf_pw_hdlc_modifier,
184
14
      {
185
14
        "Modifier", "pw_hdlc.modifier",
186
14
        FT_UINT8, BASE_HEX, VALS(pw_hdlc_modifier_vals), 0x0, NULL, HFILL
187
14
      }
188
14
    },
189
14
    {
190
14
      &hf_pw_hdlc_frame,
191
14
      {
192
14
        "Frame type", "pw_hdlc.frame",
193
14
        FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL
194
14
      }
195
14
    },
196
14
  };
197
198
14
  static int *ett[] = {
199
14
    &ett_pw_hdlc
200
14
  };
201
202
14
  proto_pw_hdlc_nocw_fr = proto_register_protocol("HDLC PW, FR port mode (no CW)", /*not displayed*/
203
14
              "HDLC PW, FR port mode (no CW)",
204
14
              "pw_hdlc_nocw_fr" );
205
14
  proto_pw_hdlc_nocw_hdlc_ppp = proto_register_protocol("HDLC-like framing for PPP",
206
14
                    "HDLC PW with PPP payload (no CW)",
207
14
                    "pw_hdlc_nocw_hdlc_ppp" );
208
209
14
  proto_register_field_array(proto_pw_hdlc_nocw_fr, hf, array_length(hf));
210
14
  proto_register_subtree_array(ett, array_length(ett));
211
212
14
  pw_hdlc_nocw_fr_handle = register_dissector("pw_hdlc_nocw_fr", dissect_pw_hdlc_nocw_fr, proto_pw_hdlc_nocw_fr );
213
14
  pw_ppp_handle = register_dissector("pw_hdlc_nocw_hdlc_ppp", dissect_pw_hdlc_nocw_hdlc_ppp, proto_pw_hdlc_nocw_hdlc_ppp );
214
14
}
215
216
void proto_reg_handoff_pw_hdlc(void)
217
14
{
218
14
  dissector_add_for_decode_as( "mpls.label", pw_hdlc_nocw_fr_handle );
219
14
  dissector_add_for_decode_as( "mpls.label", pw_ppp_handle );
220
14
  dissector_add_for_decode_as( "mpls.pfn", pw_hdlc_nocw_fr_handle );
221
14
  dissector_add_for_decode_as( "mpls.pfn", pw_ppp_handle );
222
223
14
  ppp_handle = find_dissector_add_dependency( "ppp", proto_pw_hdlc_nocw_hdlc_ppp );
224
14
  fr_handle = find_dissector_add_dependency( "fr", proto_pw_hdlc_nocw_fr );
225
14
}
226
227
/*
228
 * Editor modelines  -  https://www.wireshark.org/tools/modelines.html
229
 *
230
 * Local variables:
231
 * c-basic-offset: 8
232
 * tab-width: 8
233
 * indent-tabs-mode: t
234
 * End:
235
 *
236
 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
237
 * :indentSize=8:tabSize=8:noTabs=false:
238
 */