Coverage Report

Created: 2025-12-27 06:52

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/wireshark/epan/dissectors/packet-spp.c
Line
Count
Source
1
/* packet-spp.c
2
 * Routines for XNS SPP
3
 * Based on the Netware SPX dissector by Gilbert Ramirez <gram@alumni.rice.edu>
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 "packet-idp.h"
16
17
void proto_register_spp(void);
18
void proto_reg_handoff_spp(void);
19
static dissector_handle_t spp_handle;
20
21
static int proto_spp;
22
static int hf_spp_connection_control;
23
static int hf_spp_connection_control_sys;
24
static int hf_spp_connection_control_send_ack;
25
static int hf_spp_connection_control_attn;
26
static int hf_spp_connection_control_eom;
27
static int hf_spp_datastream_type;
28
static int hf_spp_src_id;
29
static int hf_spp_dst_id;
30
static int hf_spp_seq_nr;
31
static int hf_spp_ack_nr;
32
static int hf_spp_all_nr;
33
/* static int hf_spp_rexmt_frame; */
34
35
static int ett_spp;
36
static int ett_spp_connctrl;
37
38
static dissector_table_t spp_socket_dissector_table;
39
40
/*
41
 * See
42
 *
43
 *  "Internet Transport Protocols", XSIS 028112, December 1981
44
 *
45
 * if you can find it; this is based on the headers in the BSD XNS
46
 * implementation.
47
 */
48
49
20
#define SPP_SYS_PACKET  0x80
50
23
#define SPP_SEND_ACK  0x40
51
17
#define SPP_ATTN  0x20
52
20
#define SPP_EOM   0x10
53
54
static const char*
55
spp_conn_ctrl(uint8_t ctrl)
56
3
{
57
3
  static const value_string conn_vals[] = {
58
3
    { 0x00,                        "Data, No Ack Required" },
59
3
    { SPP_EOM,                     "End-of-Message" },
60
3
    { SPP_ATTN,                    "Attention" },
61
3
    { SPP_SEND_ACK,                "Acknowledgment Required"},
62
3
    { SPP_SEND_ACK|SPP_EOM,        "Send Ack: End Message"},
63
3
    { SPP_SYS_PACKET,              "System Packet"},
64
3
    { SPP_SYS_PACKET|SPP_SEND_ACK, "System Packet: Send Ack"},
65
3
    { 0x00,                        NULL }
66
3
  };
67
68
3
  return val_to_str_const((ctrl & 0xf0), conn_vals, "Unknown");
69
3
}
70
71
static const char*
72
spp_datastream(uint8_t type)
73
3
{
74
3
  switch (type) {
75
0
    case 0xfe:
76
0
      return "End-of-Connection";
77
0
    case 0xff:
78
0
      return "End-of-Connection Acknowledgment";
79
3
    default:
80
3
      return NULL;
81
3
  }
82
3
}
83
84
9
#define SPP_HEADER_LEN  12
85
86
/*
87
 * XXX - do reassembly, using the EOM flag.  (Then do that in the Netware
88
 * SPX implementation, too.)
89
 *
90
 * XXX - hand off to subdissectors based on the socket number.
91
 */
92
static int
93
dissect_spp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
94
3
{
95
3
  proto_tree *spp_tree;
96
3
  proto_item *ti;
97
3
  tvbuff_t   *next_tvb;
98
3
  uint8_t     conn_ctrl;
99
3
  uint8_t     datastream_type;
100
3
  const char *datastream_type_string;
101
3
  uint16_t    spp_seq;
102
3
  const char *spp_msg_string;
103
3
  uint16_t      low_socket, high_socket;
104
3
  static int * const ctrl[] = {
105
3
    &hf_spp_connection_control_sys,
106
3
    &hf_spp_connection_control_send_ack,
107
3
    &hf_spp_connection_control_attn,
108
3
    &hf_spp_connection_control_eom,
109
3
    NULL
110
3
  };
111
112
3
  col_set_str(pinfo->cinfo, COL_PROTOCOL, "SPP");
113
3
  col_set_str(pinfo->cinfo, COL_INFO, "SPP");
114
115
3
  ti = proto_tree_add_item(tree, proto_spp, tvb, 0, SPP_HEADER_LEN, ENC_NA);
116
3
  spp_tree = proto_item_add_subtree(ti, ett_spp);
117
118
3
  conn_ctrl = tvb_get_uint8(tvb, 0);
119
3
  spp_msg_string = spp_conn_ctrl(conn_ctrl);
120
3
  col_append_fstr(pinfo->cinfo, COL_INFO, " %s", spp_msg_string);
121
122
3
  proto_tree_add_bitmask_with_flags(spp_tree, tvb, 0, hf_spp_connection_control, ett_spp_connctrl,
123
3
                ctrl, ENC_NA, BMT_NO_FALSE);
124
125
3
  datastream_type = tvb_get_uint8(tvb, 1);
126
3
  datastream_type_string = spp_datastream(datastream_type);
127
3
  if (datastream_type_string != NULL) {
128
0
    col_append_fstr(pinfo->cinfo, COL_INFO, " (%s)", datastream_type_string);
129
0
  }
130
3
  if (tree) {
131
3
    if (datastream_type_string != NULL) {
132
0
      proto_tree_add_uint_format_value(spp_tree, hf_spp_datastream_type, tvb,
133
0
               1, 1, datastream_type,
134
0
               "%s (0x%02X)",
135
0
               datastream_type_string,
136
0
               datastream_type);
137
3
    } else {
138
3
      proto_tree_add_uint(spp_tree, hf_spp_datastream_type, tvb,
139
3
               1, 1, datastream_type);
140
3
    }
141
3
    proto_tree_add_item(spp_tree, hf_spp_src_id, tvb,  2, 2, ENC_BIG_ENDIAN);
142
3
    proto_tree_add_item(spp_tree, hf_spp_dst_id, tvb,  4, 2, ENC_BIG_ENDIAN);
143
3
  }
144
3
  spp_seq = tvb_get_ntohs(tvb, 6);
145
3
  if (tree) {
146
3
    proto_tree_add_uint(spp_tree, hf_spp_seq_nr, tvb,  6, 2, spp_seq);
147
3
    proto_tree_add_item(spp_tree, hf_spp_ack_nr, tvb,  8, 2, ENC_BIG_ENDIAN);
148
3
    proto_tree_add_item(spp_tree, hf_spp_all_nr, tvb, 10, 2, ENC_BIG_ENDIAN);
149
3
  }
150
151
3
  if (tvb_reported_length_remaining(tvb, SPP_HEADER_LEN) > 0) {
152
3
    if (pinfo->srcport > pinfo->destport) {
153
1
      low_socket = pinfo->destport;
154
1
      high_socket = pinfo->srcport;
155
2
    } else {
156
2
      low_socket = pinfo->srcport;
157
2
      high_socket = pinfo->destport;
158
2
    }
159
160
3
    next_tvb = tvb_new_subset_remaining(tvb, SPP_HEADER_LEN);
161
3
    if (dissector_try_uint(spp_socket_dissector_table, low_socket,
162
3
        next_tvb, pinfo, tree))
163
0
      return tvb_captured_length(tvb);
164
165
3
    if (dissector_try_uint(spp_socket_dissector_table, high_socket,
166
3
        next_tvb, pinfo, tree))
167
0
      return tvb_captured_length(tvb);
168
169
3
    call_data_dissector(next_tvb, pinfo, tree);
170
3
  }
171
3
  return tvb_captured_length(tvb);
172
3
}
173
174
175
void
176
proto_register_spp(void)
177
14
{
178
14
  static hf_register_info hf_spp[] = {
179
14
    { &hf_spp_connection_control,
180
14
    { "Connection Control",   "spp.ctl",
181
14
      FT_UINT8, BASE_HEX, NULL, 0x0,
182
14
      NULL, HFILL }},
183
184
14
    { &hf_spp_connection_control_sys,
185
14
    { "System Packet",    "spp.ctl.sys",
186
14
      FT_BOOLEAN, 8,  NULL, SPP_SYS_PACKET,
187
14
      NULL, HFILL }},
188
189
14
    { &hf_spp_connection_control_send_ack,
190
14
    { "Send Ack",   "spp.ctl.send_ack",
191
14
      FT_BOOLEAN, 8,  NULL, SPP_SEND_ACK,
192
14
      NULL, HFILL }},
193
194
14
    { &hf_spp_connection_control_attn,
195
14
    { "Attention",    "spp.ctl.attn",
196
14
      FT_BOOLEAN, 8,  NULL, SPP_ATTN,
197
14
      NULL, HFILL }},
198
199
14
    { &hf_spp_connection_control_eom,
200
14
    { "End of Message", "spp.ctl.eom",
201
14
      FT_BOOLEAN, 8,  NULL, SPP_EOM,
202
14
      NULL, HFILL }},
203
204
14
    { &hf_spp_datastream_type,
205
14
    { "Datastream Type",          "spp.type",
206
14
      FT_UINT8, BASE_HEX, NULL, 0x0,
207
14
      NULL, HFILL }},
208
209
14
    { &hf_spp_src_id,
210
14
    { "Source Connection ID", "spp.src",
211
14
      FT_UINT16,  BASE_DEC, NULL, 0x0,
212
14
      NULL, HFILL }},
213
214
14
    { &hf_spp_dst_id,
215
14
    { "Destination Connection ID",  "spp.dst",
216
14
      FT_UINT16,  BASE_DEC, NULL, 0x0,
217
14
      NULL, HFILL }},
218
219
14
    { &hf_spp_seq_nr,
220
14
    { "Sequence Number",    "spp.seq",
221
14
      FT_UINT16,  BASE_DEC, NULL, 0x0,
222
14
      NULL, HFILL }},
223
224
14
    { &hf_spp_ack_nr,
225
14
    { "Acknowledgment Number",  "spp.ack",
226
14
      FT_UINT16,  BASE_DEC, NULL, 0x0,
227
14
      NULL, HFILL }},
228
229
14
    { &hf_spp_all_nr,
230
14
    { "Allocation Number",    "spp.alloc",
231
14
      FT_UINT16,  BASE_DEC, NULL, 0x0,
232
14
      NULL, HFILL }},
233
234
#if 0
235
    { &hf_spp_rexmt_frame,
236
    { "Retransmitted Frame Number", "spp.rexmt_frame",
237
      FT_FRAMENUM,  BASE_NONE,  NULL, 0x0,
238
      NULL, HFILL }},
239
#endif
240
14
  };
241
242
14
  static int *ett[] = {
243
14
    &ett_spp,
244
14
    &ett_spp_connctrl,
245
14
  };
246
247
14
  proto_spp = proto_register_protocol("Sequenced Packet Protocol",
248
14
      "SPP", "spp");
249
14
  proto_register_field_array(proto_spp, hf_spp, array_length(hf_spp));
250
14
  proto_register_subtree_array(ett, array_length(ett));
251
14
  spp_handle = register_dissector("spp", dissect_spp, proto_spp);
252
253
14
  spp_socket_dissector_table = register_dissector_table("spp.socket",
254
14
      "SPP socket", proto_spp, FT_UINT16, BASE_HEX);
255
14
}
256
257
void
258
proto_reg_handoff_spp(void)
259
14
{
260
14
  dissector_add_uint("idp.packet_type", IDP_PACKET_TYPE_SPP, spp_handle);
261
14
}
262
263
/*
264
 * Editor modelines  -  https://www.wireshark.org/tools/modelines.html
265
 *
266
 * Local variables:
267
 * c-basic-offset: 8
268
 * tab-width: 8
269
 * indent-tabs-mode: t
270
 * End:
271
 *
272
 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
273
 * :indentSize=8:tabSize=8:noTabs=false:
274
 */