Coverage Report

Created: 2026-05-14 06:28

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/wireshark/epan/dissectors/packet-cosine.c
Line
Count
Source
1
/* packet-cosine.c
2
 * Routines for decoding CoSine IPNOS L2 debug output
3
 *
4
 * Motonori Shindo <motonori@shin.do>
5
 *
6
 * Wireshark - Network traffic analyzer
7
 * By Gerald Combs <gerald@wireshark.org>
8
 *
9
 * SPDX-License-Identifier: GPL-2.0-or-later
10
 */
11
12
/*
13
 * XXX TODO:
14
 *    o PPoATM and PPoFR encapsulation needs more test.
15
 *
16
 */
17
18
#include "config.h"
19
20
#include <epan/packet.h>
21
#include <wiretap/wtap.h>
22
23
void proto_register_cosine(void);
24
void proto_reg_handoff_cosine(void);
25
26
static int proto_cosine;
27
static int hf_pro;
28
static int hf_off;
29
static int hf_pri;
30
static int hf_rm;
31
static int hf_err;
32
static int hf_sar;
33
static int hf_channel_id;
34
35
static int ett_raw;
36
37
static dissector_handle_t cosine_handle;
38
static dissector_handle_t eth_withoutfcs_handle;
39
static dissector_handle_t ppp_hdlc_handle;
40
static dissector_handle_t llc_handle;
41
static dissector_handle_t chdlc_handle;
42
static dissector_handle_t fr_handle;
43
44
static int
45
dissect_cosine(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
46
0
{
47
0
  proto_tree               *fh_tree;
48
0
  proto_item               *ti;
49
0
  union wtap_pseudo_header *pseudo_header = pinfo->pseudo_header;
50
51
  /* load the top pane info. This should be overwritten by
52
     the next protocol in the stack */
53
0
  col_set_str(pinfo->cinfo, COL_RES_DL_SRC, "N/A");
54
0
  col_set_str(pinfo->cinfo, COL_RES_DL_DST, "N/A");
55
0
  col_set_str(pinfo->cinfo, COL_PROTOCOL, "N/A");
56
0
  col_set_str(pinfo->cinfo, COL_INFO, "CoSine IPNOS L2 debug output");
57
58
  /* populate a tree in the second pane with the status of the link
59
     layer (ie none) */
60
0
  if(tree) {
61
0
    ti = proto_tree_add_protocol_format(tree, proto_cosine, tvb, 0, 0,
62
0
                                        "CoSine IPNOS L2 debug output (%s)",
63
0
                                        pseudo_header->cosine.if_name);
64
0
    fh_tree = proto_item_add_subtree(ti, ett_raw);
65
0
    proto_tree_add_uint(fh_tree, hf_pro, tvb, 0, 0, pseudo_header->cosine.pro);
66
0
    proto_tree_add_uint(fh_tree, hf_off, tvb, 0, 0, pseudo_header->cosine.off);
67
0
    proto_tree_add_uint(fh_tree, hf_pri, tvb, 0, 0, pseudo_header->cosine.pri);
68
0
    proto_tree_add_uint(fh_tree, hf_rm,  tvb, 0, 0, pseudo_header->cosine.rm);
69
0
    proto_tree_add_uint(fh_tree, hf_err, tvb, 0, 0, pseudo_header->cosine.err);
70
71
0
    switch (pseudo_header->cosine.encap) {
72
0
      case COSINE_ENCAP_ETH:
73
0
        break;
74
0
      case COSINE_ENCAP_ATM:
75
0
      case COSINE_ENCAP_PPoATM:
76
0
        proto_tree_add_item(fh_tree, hf_sar, tvb, 0, 16, ENC_NA);
77
0
        break;
78
0
      case COSINE_ENCAP_PPP:
79
0
      case COSINE_ENCAP_FR:
80
0
      case COSINE_ENCAP_PPoFR:
81
0
        proto_tree_add_item(fh_tree, hf_channel_id, tvb, 0, 4, ENC_NA);
82
0
        break;
83
0
      case COSINE_ENCAP_HDLC:
84
0
        if (pseudo_header->cosine.direction == COSINE_DIR_TX) {
85
0
          proto_tree_add_item(fh_tree, hf_channel_id, tvb, 0, 2, ENC_NA);
86
0
        } else if (pseudo_header->cosine.direction == COSINE_DIR_RX) {
87
0
          proto_tree_add_item(fh_tree, hf_channel_id, tvb, 0, 4, ENC_NA);
88
0
        }
89
0
        break;
90
0
      default:
91
0
        break;
92
0
    }
93
0
  }
94
95
0
  switch (pseudo_header->cosine.encap) {
96
0
    case COSINE_ENCAP_ETH:
97
0
      call_dissector(eth_withoutfcs_handle, tvb_new_subset_remaining(tvb, 0),
98
0
                     pinfo, tree);
99
0
      break;
100
0
    case COSINE_ENCAP_ATM:
101
0
    case COSINE_ENCAP_PPoATM:
102
0
      call_dissector(llc_handle, tvb_new_subset_remaining(tvb, 16),
103
0
                     pinfo, tree);
104
0
      break;
105
0
    case COSINE_ENCAP_PPP:
106
0
      call_dissector(ppp_hdlc_handle, tvb_new_subset_remaining(tvb, 4),
107
0
                     pinfo, tree);
108
0
      break;
109
0
    case COSINE_ENCAP_HDLC:
110
0
      if (pseudo_header->cosine.direction == COSINE_DIR_TX) {
111
0
        call_dissector(chdlc_handle, tvb_new_subset_remaining(tvb, 2),
112
0
                       pinfo, tree);
113
0
      } else if (pseudo_header->cosine.direction == COSINE_DIR_RX) {
114
0
        call_dissector(chdlc_handle, tvb_new_subset_remaining(tvb, 4),
115
0
                       pinfo, tree);
116
0
      }
117
0
      break;
118
0
    case COSINE_ENCAP_FR:
119
0
    case COSINE_ENCAP_PPoFR:
120
0
      call_dissector(fr_handle, tvb_new_subset_remaining(tvb, 4),
121
0
                     pinfo, tree);
122
0
      break;
123
0
    case COSINE_ENCAP_TEST:
124
0
    case COSINE_ENCAP_UNKNOWN:
125
0
      call_data_dissector(tvb, pinfo, tree);
126
0
      break;
127
0
    default:
128
0
      break;
129
0
  }
130
0
  return tvb_captured_length(tvb);
131
0
}
132
133
void
134
proto_register_cosine(void)
135
15
{
136
15
  static hf_register_info hf[] = {
137
15
    { &hf_pro,
138
15
      { "Protocol", "cosine.pro", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL}},
139
15
    { &hf_off,
140
15
      { "Offset", "cosine.off", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL}},
141
15
    { &hf_pri,
142
15
      { "Priority", "cosine.pri", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL}},
143
15
    { &hf_rm,
144
15
      { "Rate Marking", "cosine.rm",  FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL}},
145
15
    { &hf_err,
146
15
      { "Error Code", "cosine.err", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL}},
147
15
    { &hf_sar,
148
15
      { "SAR header", "cosine.sar", FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL}},
149
15
    { &hf_channel_id,
150
15
      { "Channel handle ID", "cosine.channel_id", FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL}},
151
15
  };
152
153
15
  static int *ett[] = {
154
15
    &ett_raw,
155
15
  };
156
157
15
  proto_cosine = proto_register_protocol("CoSine IPNOS L2 debug output",
158
15
                                         "CoSine", "cosine");
159
15
  proto_register_field_array(proto_cosine, hf, array_length(hf));
160
15
  proto_register_subtree_array(ett, array_length(ett));
161
162
15
  cosine_handle = register_dissector("cosine", dissect_cosine, proto_cosine);
163
15
}
164
165
void
166
proto_reg_handoff_cosine(void)
167
15
{
168
169
  /*
170
   * Get handles for dissectors.
171
   */
172
15
  eth_withoutfcs_handle = find_dissector_add_dependency("eth_withoutfcs", proto_cosine);
173
15
  ppp_hdlc_handle       = find_dissector_add_dependency("ppp_hdlc", proto_cosine);
174
15
  llc_handle            = find_dissector_add_dependency("llc", proto_cosine);
175
15
  chdlc_handle          = find_dissector_add_dependency("chdlc", proto_cosine);
176
15
  fr_handle             = find_dissector_add_dependency("fr", proto_cosine);
177
178
15
  dissector_add_uint("wtap_encap", WTAP_ENCAP_COSINE, cosine_handle);
179
15
}
180
181
/*
182
 * Editor modelines  -  https://www.wireshark.org/tools/modelines.html
183
 *
184
 * Local Variables:
185
 * c-basic-offset: 2
186
 * tab-width: 8
187
 * indent-tabs-mode: nil
188
 * End:
189
 *
190
 * ex: set shiftwidth=2 tabstop=8 expandtab:
191
 * :indentSize=2:tabSize=8:noTabs=true:
192
 */