HACK: 2nd try to match RowsetProperties
[wireshark-wip.git] / epan / dissectors / packet-spp.c
blob745c7b1425aac8871e7bdb920345cbb4f9610aac
1 /* packet-spp.c
2 * Routines for XNS SPP
3 * Based on the Netware SPX dissector by Gilbert Ramirez <gram@alumni.rice.edu>
5 * $Id$
7 * Wireshark - Network traffic analyzer
8 * By Gerald Combs <gerald@wireshark.org>
9 * Copyright 1998 Gerald Combs
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version 2
14 * of the License, or (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 #include "config.h"
28 #include <glib.h>
29 #include <epan/packet.h>
30 #include "packet-idp.h"
32 static int proto_spp = -1;
33 static int hf_spp_connection_control = -1;
34 static int hf_spp_connection_control_sys = -1;
35 static int hf_spp_connection_control_send_ack = -1;
36 static int hf_spp_connection_control_attn = -1;
37 static int hf_spp_connection_control_eom = -1;
38 static int hf_spp_datastream_type = -1;
39 static int hf_spp_src_id = -1;
40 static int hf_spp_dst_id = -1;
41 static int hf_spp_seq_nr = -1;
42 static int hf_spp_ack_nr = -1;
43 static int hf_spp_all_nr = -1;
44 /* static int hf_spp_rexmt_frame = -1; */
46 static gint ett_spp = -1;
47 static gint ett_spp_connctrl = -1;
49 static dissector_handle_t data_handle;
51 static dissector_table_t spp_socket_dissector_table;
54 * See
56 * "Internet Transport Protocols", XSIS 028112, December 1981
58 * if you can find it; this is based on the headers in the BSD XNS
59 * implementation.
62 #define SPP_SYS_PACKET 0x80
63 #define SPP_SEND_ACK 0x40
64 #define SPP_ATTN 0x20
65 #define SPP_EOM 0x10
67 static const char*
68 spp_conn_ctrl(guint8 ctrl)
70 static const value_string conn_vals[] = {
71 { 0x00, "Data, No Ack Required" },
72 { SPP_EOM, "End-of-Message" },
73 { SPP_ATTN, "Attention" },
74 { SPP_SEND_ACK, "Acknowledgment Required"},
75 { SPP_SEND_ACK|SPP_EOM, "Send Ack: End Message"},
76 { SPP_SYS_PACKET, "System Packet"},
77 { SPP_SYS_PACKET|SPP_SEND_ACK, "System Packet: Send Ack"},
78 { 0x00, NULL }
81 return val_to_str_const((ctrl & 0xf0), conn_vals, "Unknown");
84 static const char*
85 spp_datastream(guint8 type)
87 switch (type) {
88 case 0xfe:
89 return "End-of-Connection";
90 case 0xff:
91 return "End-of-Connection Acknowledgment";
92 default:
93 return NULL;
97 #define SPP_HEADER_LEN 12
100 * XXX - do reassembly, using the EOM flag. (Then do that in the Netware
101 * SPX implementation, too.)
103 * XXX - hand off to subdissectors based on the socket number.
105 static void
106 dissect_spp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
108 proto_tree *spp_tree = NULL;
109 proto_item *ti;
110 tvbuff_t *next_tvb;
111 guint8 conn_ctrl;
112 proto_tree *cc_tree;
113 guint8 datastream_type;
114 const char *datastream_type_string;
115 guint16 spp_seq;
116 const char *spp_msg_string;
117 guint16 low_socket, high_socket;
119 col_set_str(pinfo->cinfo, COL_PROTOCOL, "SPP");
120 col_set_str(pinfo->cinfo, COL_INFO, "SPP");
122 if (tree) {
123 ti = proto_tree_add_item(tree, proto_spp, tvb, 0, SPP_HEADER_LEN, ENC_NA);
124 spp_tree = proto_item_add_subtree(ti, ett_spp);
127 conn_ctrl = tvb_get_guint8(tvb, 0);
128 spp_msg_string = spp_conn_ctrl(conn_ctrl);
129 col_append_fstr(pinfo->cinfo, COL_INFO, " %s", spp_msg_string);
130 if (tree) {
131 ti = proto_tree_add_uint_format_value(spp_tree, hf_spp_connection_control, tvb,
132 0, 1, conn_ctrl,
133 "%s (0x%02X)",
134 spp_msg_string, conn_ctrl);
135 cc_tree = proto_item_add_subtree(ti, ett_spp_connctrl);
136 proto_tree_add_boolean(cc_tree, hf_spp_connection_control_sys, tvb,
137 0, 1, conn_ctrl);
138 proto_tree_add_boolean(cc_tree, hf_spp_connection_control_send_ack, tvb,
139 0, 1, conn_ctrl);
140 proto_tree_add_boolean(cc_tree, hf_spp_connection_control_attn, tvb,
141 0, 1, conn_ctrl);
142 proto_tree_add_boolean(cc_tree, hf_spp_connection_control_eom, tvb,
143 0, 1, conn_ctrl);
146 datastream_type = tvb_get_guint8(tvb, 1);
147 datastream_type_string = spp_datastream(datastream_type);
148 if (datastream_type_string != NULL) {
149 col_append_fstr(pinfo->cinfo, COL_INFO, " (%s)", datastream_type_string);
151 if (tree) {
152 if (datastream_type_string != NULL) {
153 proto_tree_add_uint_format_value(spp_tree, hf_spp_datastream_type, tvb,
154 1, 1, datastream_type,
155 "%s (0x%02X)",
156 datastream_type_string,
157 datastream_type);
158 } else {
159 proto_tree_add_uint(spp_tree, hf_spp_datastream_type, tvb,
160 1, 1, datastream_type);
162 proto_tree_add_item(spp_tree, hf_spp_src_id, tvb, 2, 2, ENC_BIG_ENDIAN);
163 proto_tree_add_item(spp_tree, hf_spp_dst_id, tvb, 4, 2, ENC_BIG_ENDIAN);
165 spp_seq = tvb_get_ntohs(tvb, 6);
166 if (tree) {
167 proto_tree_add_uint(spp_tree, hf_spp_seq_nr, tvb, 6, 2, spp_seq);
168 proto_tree_add_item(spp_tree, hf_spp_ack_nr, tvb, 8, 2, ENC_BIG_ENDIAN);
169 proto_tree_add_item(spp_tree, hf_spp_all_nr, tvb, 10, 2, ENC_BIG_ENDIAN);
172 if (tvb_reported_length_remaining(tvb, SPP_HEADER_LEN) > 0) {
173 if (pinfo->srcport > pinfo->destport) {
174 low_socket = pinfo->destport;
175 high_socket = pinfo->srcport;
176 } else {
177 low_socket = pinfo->srcport;
178 high_socket = pinfo->destport;
181 next_tvb = tvb_new_subset_remaining(tvb, SPP_HEADER_LEN);
182 if (dissector_try_uint(spp_socket_dissector_table, low_socket,
183 next_tvb, pinfo, tree))
184 return;
185 if (dissector_try_uint(spp_socket_dissector_table, high_socket,
186 next_tvb, pinfo, tree))
187 return;
188 call_dissector(data_handle, next_tvb, pinfo, tree);
193 void
194 proto_register_spp(void)
196 static hf_register_info hf_spp[] = {
197 { &hf_spp_connection_control,
198 { "Connection Control", "spp.ctl",
199 FT_UINT8, BASE_HEX, NULL, 0x0,
200 NULL, HFILL }},
202 { &hf_spp_connection_control_sys,
203 { "System Packet", "spp.ctl.sys",
204 FT_BOOLEAN, 8, NULL, SPP_SYS_PACKET,
205 NULL, HFILL }},
207 { &hf_spp_connection_control_send_ack,
208 { "Send Ack", "spp.ctl.send_ack",
209 FT_BOOLEAN, 8, NULL, SPP_SEND_ACK,
210 NULL, HFILL }},
212 { &hf_spp_connection_control_attn,
213 { "Attention", "spp.ctl.attn",
214 FT_BOOLEAN, 8, NULL, SPP_ATTN,
215 NULL, HFILL }},
217 { &hf_spp_connection_control_eom,
218 { "End of Message", "spp.ctl.eom",
219 FT_BOOLEAN, 8, NULL, SPP_EOM,
220 NULL, HFILL }},
222 { &hf_spp_datastream_type,
223 { "Datastream Type", "spp.type",
224 FT_UINT8, BASE_HEX, NULL, 0x0,
225 NULL, HFILL }},
227 { &hf_spp_src_id,
228 { "Source Connection ID", "spp.src",
229 FT_UINT16, BASE_DEC, NULL, 0x0,
230 NULL, HFILL }},
232 { &hf_spp_dst_id,
233 { "Destination Connection ID", "spp.dst",
234 FT_UINT16, BASE_DEC, NULL, 0x0,
235 NULL, HFILL }},
237 { &hf_spp_seq_nr,
238 { "Sequence Number", "spp.seq",
239 FT_UINT16, BASE_DEC, NULL, 0x0,
240 NULL, HFILL }},
242 { &hf_spp_ack_nr,
243 { "Acknowledgment Number", "spp.ack",
244 FT_UINT16, BASE_DEC, NULL, 0x0,
245 NULL, HFILL }},
247 { &hf_spp_all_nr,
248 { "Allocation Number", "spp.alloc",
249 FT_UINT16, BASE_DEC, NULL, 0x0,
250 NULL, HFILL }},
252 #if 0
253 { &hf_spp_rexmt_frame,
254 { "Retransmitted Frame Number", "spp.rexmt_frame",
255 FT_FRAMENUM, BASE_NONE, NULL, 0x0,
256 NULL, HFILL }},
257 #endif
260 static gint *ett[] = {
261 &ett_spp,
262 &ett_spp_connctrl,
265 proto_spp = proto_register_protocol("Sequenced Packet Protocol",
266 "SPP", "spp");
267 proto_register_field_array(proto_spp, hf_spp, array_length(hf_spp));
268 proto_register_subtree_array(ett, array_length(ett));
270 spp_socket_dissector_table = register_dissector_table("spp.socket",
271 "SPP socket", FT_UINT16, BASE_HEX);
274 void
275 proto_reg_handoff_spp(void)
277 dissector_handle_t spp_handle;
279 spp_handle = create_dissector_handle(dissect_spp, proto_spp);
280 dissector_add_uint("idp.packet_type", IDP_PACKET_TYPE_SPP, spp_handle);
282 data_handle = find_dissector("data");