Coverage Report

Created: 2025-02-15 06:25

/src/wireshark/epan/dissectors/packet-v5ef.c
Line
Count
Source (jump to first uncovered line)
1
/* packet-v5ef.c
2
 * Routines for V5 envelope function frame disassembly
3
 * Rolf Fiedler <rolf.fiedler@innoventif.de>
4
 *
5
 * Wireshark - Network traffic analyzer
6
 * By Gerald Combs <gerald@wireshark.org>
7
 * Copyright 1998
8
 *
9
 * SPDX-License-Identifier: GPL-2.0-or-later
10
 */
11
/*
12
 * V5 bitstream over HDLC handling
13
 *
14
 * V5 references:
15
 *
16
 * ETS 300 324-1
17
 * ETS 300 347-1
18
 */
19
20
#include "config.h"
21
22
#include <epan/packet.h>
23
#include <wiretap/wtap.h>
24
25
void proto_register_v5ef(void);
26
void proto_reg_handoff_v5ef(void);
27
28
static int proto_v5ef;
29
static int hf_v5ef_direction;
30
static int hf_v5ef_address;
31
static int hf_v5ef_eah;
32
static int hf_v5ef_ea1;
33
static int hf_v5ef_eal;
34
static int hf_v5ef_ea2;
35
36
static int ett_v5ef;
37
static int ett_v5ef_address;
38
39
static dissector_handle_t v5dl_handle, lapd_phdr_handle, v5ef_handle;
40
41
42
/*
43
 * Bits in the address field.
44
 */
45
66
#define V5EF_EAH    0xfc00  /* Service Access Point Identifier */
46
52
#define V5EF_EAH_SHIFT    10
47
14
#define V5EF_EA1    0x0100  /* First Address Extension bit */
48
66
#define V5EF_EAL    0x00fe  /* Terminal Endpoint Identifier */
49
52
#define V5EF_EAL_SHIFT    1
50
14
#define V5EF_EA2    0x0001  /* Second Address Extension bit */
51
52
static const value_string v5ef_direction_vals[] = {
53
  { 0,    "AN->LE"},
54
  { 1,    "LE->AN"},
55
  { 0,    NULL }
56
};
57
58
#define MAX_V5EF_PACKET_LEN 1024
59
60
static int
61
dissect_v5ef(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data)
62
52
{
63
52
  struct isdn_phdr *isdn = (struct isdn_phdr *)data;
64
52
  proto_tree  *v5ef_tree, *addr_tree;
65
52
  proto_item  *v5ef_ti, *addr_ti;
66
52
  int    direction;
67
52
  int    v5ef_header_len;
68
52
  uint16_t     addr, eah, eal, efaddr;
69
52
  tvbuff_t  *next_tvb;
70
52
  const char  *srcname = "src";
71
52
  const char  *dstname = "dst";
72
73
52
  col_set_str(pinfo->cinfo, COL_PROTOCOL, "V5-EF");
74
52
  col_clear(pinfo->cinfo, COL_INFO);
75
76
52
  addr    = tvb_get_ntohs(tvb, 0);
77
52
  eah   = (addr & V5EF_EAH) >> V5EF_EAH_SHIFT;
78
52
  eal   = (addr & V5EF_EAL) >> V5EF_EAL_SHIFT;
79
52
  efaddr    = (eah << 7) + eal;
80
52
  v5ef_header_len = 2;  /* addr */
81
82
52
  direction = isdn->uton;
83
52
  if (direction==0) {
84
49
          srcname = "LE";
85
49
          dstname = "AN";
86
49
   } else if (direction > 0) {
87
3
          srcname = "AN";
88
3
          dstname = "LE";
89
3
  }
90
52
  col_set_str(pinfo->cinfo, COL_RES_DL_SRC, srcname);
91
52
  col_set_str(pinfo->cinfo, COL_RES_DL_DST, dstname);
92
93
52
  if (tree) {
94
52
    proto_item *direction_ti;
95
96
52
    v5ef_ti = proto_tree_add_item(tree, proto_v5ef, tvb, 0, -1,
97
52
        ENC_NA);
98
52
    v5ef_tree = proto_item_add_subtree(v5ef_ti, ett_v5ef);
99
100
    /*
101
     * Don't show the direction if we don't know it.
102
     */
103
52
    if (direction != P2P_DIR_UNKNOWN) {
104
52
      direction_ti = proto_tree_add_uint(v5ef_tree, hf_v5ef_direction,
105
52
                                         tvb, 0, 0, direction);
106
52
      proto_item_set_generated(direction_ti);
107
52
    }
108
109
52
    addr_ti = proto_tree_add_uint(v5ef_tree, hf_v5ef_address, tvb,
110
52
        0, 2, addr);
111
52
    addr_tree = proto_item_add_subtree(addr_ti, ett_v5ef_address);
112
113
52
    proto_tree_add_uint(addr_tree, hf_v5ef_eah,  tvb, 0, 1, addr);
114
52
    proto_tree_add_uint(addr_tree, hf_v5ef_ea1, tvb, 0, 1, addr);
115
52
    proto_tree_add_uint(addr_tree, hf_v5ef_eal, tvb, 1, 1, addr);
116
52
    proto_tree_add_uint(addr_tree, hf_v5ef_ea2, tvb, 1, 1, addr);
117
52
  }
118
0
  else {
119
0
    v5ef_ti   = NULL;
120
0
    v5ef_tree = NULL;
121
0
  }
122
123
52
  if (tree)
124
52
    proto_item_set_len(v5ef_ti, v5ef_header_len);
125
126
52
  next_tvb = tvb_new_subset_remaining(tvb, v5ef_header_len);
127
128
52
  if (efaddr>8175)
129
40
    call_dissector(v5dl_handle,next_tvb, pinfo, tree);
130
12
  else
131
12
    call_dissector_with_data(lapd_phdr_handle, next_tvb, pinfo, tree, isdn);
132
133
52
  return tvb_captured_length(tvb);
134
52
}
135
136
void
137
proto_register_v5ef(void)
138
14
{
139
14
  static hf_register_info hf[] = {
140
141
14
  { &hf_v5ef_direction,
142
14
    { "Direction", "v5ef.direction", FT_UINT8, BASE_DEC, VALS(v5ef_direction_vals), 0x0,
143
14
      NULL, HFILL }},
144
145
14
  { &hf_v5ef_address,
146
14
    { "Address Field", "v5ef.address", FT_UINT16, BASE_HEX, NULL, 0x0,
147
14
    NULL, HFILL }},
148
149
14
  { &hf_v5ef_eah,
150
14
    { "EAH", "v5ef.eah", FT_UINT16, BASE_DEC, NULL, V5EF_EAH,
151
14
      "Envelope Address High Part", HFILL }},
152
153
14
  { &hf_v5ef_ea1,
154
14
    { "EA1", "v5ef.ea1", FT_UINT16, BASE_DEC, NULL, V5EF_EA1,
155
14
      "First Address Extension bit", HFILL }},
156
157
14
  { &hf_v5ef_eal,
158
14
    { "EAL", "v5ef.eal", FT_UINT16, BASE_DEC, NULL, V5EF_EAL,
159
14
      "Envelope Address Low Part", HFILL }},
160
161
14
  { &hf_v5ef_ea2,
162
14
    { "EA2", "v5ef.ea2", FT_UINT16, BASE_DEC, NULL, V5EF_EA2,
163
14
      "Second Address Extension bit", HFILL }},
164
14
  };
165
166
14
  static int *ett[] = {
167
14
    &ett_v5ef,
168
14
    &ett_v5ef_address,
169
14
  };
170
171
14
  proto_v5ef = proto_register_protocol("V5 Envelope Function (v5ef)",
172
14
           "v5ef", "v5ef");
173
14
  proto_register_field_array (proto_v5ef, hf, array_length(hf));
174
14
  proto_register_subtree_array(ett, array_length(ett));
175
176
14
  v5ef_handle = register_dissector("v5ef", dissect_v5ef, proto_v5ef);
177
14
}
178
179
void
180
proto_reg_handoff_v5ef(void)
181
14
{
182
14
  dissector_add_uint("wtap_encap", WTAP_ENCAP_V5_EF, v5ef_handle);
183
184
14
  lapd_phdr_handle = find_dissector_add_dependency("lapd-phdr", proto_v5ef);
185
14
  v5dl_handle = find_dissector_add_dependency("v5dl", proto_v5ef);
186
14
}
187
188
/*
189
 * Editor modelines  -  https://www.wireshark.org/tools/modelines.html
190
 *
191
 * Local variables:
192
 * c-basic-offset: 8
193
 * tab-width: 8
194
 * indent-tabs-mode: t
195
 * End:
196
 *
197
 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
198
 * :indentSize=8:tabSize=8:noTabs=false:
199
 */