2 * Routines for X.29 packet dissection
4 * $Id: packet-x29.c,v 1.1 2003/01/06 02:24:57 guy Exp $
6 * Ethereal - Network traffic analyzer
7 * By Gerald Combs <gerald@ethereal.com>
8 * Copyright 1998 Gerald Combs
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
33 #include <epan/packet.h>
34 #include <epan/strutil.h>
37 static int proto_x29 = -1;
38 static int hf_msg_code = -1;
39 static int hf_error_type = -1;
40 static int hf_inv_msg_code = -1;
42 static gint ett_x29 = -1;
49 #define SET_AND_READ_MSG 0x06
50 #define PARAMETER_IND_MSG 0x00
51 #define INV_TO_CLEAR_MSG 0x01
52 #define BREAK_IND_MSG 0x03
53 #define RESELECTION_MSG 0x07
54 #define ERROR_MSG 0x05
55 #define RESEL_WITH_TOA_NPI_MSG 0x08
57 static const value_string message_code_vals[] = {
60 { SET_AND_READ_MSG, "Set and read" },
61 { PARAMETER_IND_MSG, "Parameter indication" },
62 { INV_TO_CLEAR_MSG, "Invitation to clear" },
63 { BREAK_IND_MSG, "Indication of break" },
64 { RESELECTION_MSG, "Reselection" },
65 { ERROR_MSG, "Error" },
66 { RESEL_WITH_TOA_NPI_MSG, "Reselection with TOA/NPI" },
70 static const value_string error_type_vals[] = {
71 { 0x00, "Received PAD message contained less than eight bits" },
72 { 0x02, "Unrecognized message code in received PAD message" },
73 { 0x04, "Parameter field format was incorrect or incompatible with message code" },
74 { 0x06, "Received PAD message did not contain an integral number of octets" },
75 { 0x08, "Received Parameter Indication PAD message was unsolicited" },
76 { 0x0A, "Received PAD message was too long" },
77 { 0x0C, "Unauthorized reselection PAD message" },
82 dissect_x29(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
85 proto_tree *x29_tree = NULL;
87 gboolean *q_bit_set = pinfo->private_data;
94 if (check_col(pinfo->cinfo, COL_PROTOCOL))
95 col_set_str(pinfo->cinfo, COL_PROTOCOL, "X.29");
96 if (check_col(pinfo->cinfo, COL_INFO))
97 col_clear(pinfo->cinfo, COL_INFO);
100 ti = proto_tree_add_item(tree, proto_x29, tvb, offset, -1,
102 x29_tree = proto_item_add_subtree(ti, ett_x29);
107 * Q bit set - this is a PAD message.
109 msg_code = tvb_get_guint8(tvb, offset);
110 if (check_col(pinfo->cinfo, COL_INFO)) {
111 col_add_fstr(pinfo->cinfo, COL_INFO, "%s PAD message",
112 val_to_str(msg_code, message_code_vals,
113 "Unknown (0x%02x)"));
115 proto_tree_add_uint(x29_tree, hf_msg_code, tvb,
116 offset, 1, msg_code);
123 case SET_AND_READ_MSG:
124 case PARAMETER_IND_MSG:
126 * XXX - dissect the references as per X.3.
128 while (tvb_reported_length_remaining(tvb, offset) > 0) {
129 proto_tree_add_text(x29_tree, tvb, offset, 2,
130 "Parameter %u, value %u",
131 tvb_get_guint8(tvb, offset),
132 tvb_get_guint8(tvb, offset + 1));
137 case INV_TO_CLEAR_MSG:
139 * No data for this message.
144 error_type = tvb_get_guint8(tvb, offset);
145 proto_tree_add_uint(x29_tree, hf_error_type, tvb,
146 offset, 1, error_type);
148 if (error_type != 0) {
149 proto_tree_add_item(x29_tree, hf_inv_msg_code,
150 tvb, offset, 1, FALSE);
155 if (tvb_reported_length_remaining(tvb, offset) > 0) {
156 type_ref = tvb_get_guint8(tvb, offset);
159 case 0x01: /* change in PAD Aspect */
161 * XXX - dissect as per X.28.
163 proto_tree_add_text(x29_tree, tvb,
164 offset, 1, "Type reference: Change in PAD Aspect");
166 proto_tree_add_text(x29_tree, tvb,
167 offset, 1, "Type of aspect: 0x%02x",
172 case 0x08: /* break */
173 proto_tree_add_text(x29_tree, tvb,
174 offset, 1, "Type reference: Break");
176 proto_tree_add_text(x29_tree, tvb,
177 offset, 1, "Break value: 0x%02x",
183 proto_tree_add_text(x29_tree, tvb,
184 offset, 1, "Unknown type reference (0x%02x)",
187 proto_tree_add_text(x29_tree, tvb,
188 offset, 1, "Type value: 0x%02x",
196 case RESELECTION_MSG:
200 proto_tree_add_text(x29_tree, tvb, offset, -1,
201 "Reselection message data");
204 case RESEL_WITH_TOA_NPI_MSG:
208 proto_tree_add_text(x29_tree, tvb, offset, -1,
209 "Reselection message data");
213 proto_tree_add_text(x29_tree, tvb, offset, -1,
219 * Q bit not set - this is data.
221 if (check_col(pinfo->cinfo, COL_INFO))
222 col_add_fstr(pinfo->cinfo, COL_INFO, "Data ...");
225 while (tvb_offset_exists(tvb, offset)) {
227 * Find the end of the line.
229 linelen = tvb_find_line_end(tvb, offset, -1,
230 &next_offset, FALSE);
233 * Now compute the length of the line
234 * *including* the end-of-line indication,
235 * if any; we display it all.
237 linelen = next_offset - offset;
239 proto_tree_add_text(x29_tree, tvb, offset,
241 tvb_format_text(tvb, offset, linelen));
242 offset = next_offset;
249 proto_register_x29(void)
251 static hf_register_info hf[] = {
253 { "Message code", "x29.msg_code", FT_UINT8, BASE_HEX,
254 VALS(message_code_vals), 0x0, "X.29 PAD message code",
257 { "Error type", "x29.error_type", FT_UINT8, BASE_HEX,
258 VALS(error_type_vals), 0x0, "X.29 error PAD message error type",
261 { "Invalid message code", "x29.inv_msg_code", FT_UINT8, BASE_HEX,
262 VALS(message_code_vals), 0x0, "X.29 Error PAD message invalid message code",
265 static gint *ett[] = {
269 proto_x29 = proto_register_protocol("X.29", "X.29", "x.29");
270 proto_register_field_array(proto_x29, hf, array_length(hf));
271 proto_register_subtree_array(ett, array_length(ett));
275 proto_reg_handoff_x29(void)
277 dissector_handle_t x29_handle;
279 x29_handle = create_dissector_handle(dissect_x29, proto_x29);
280 dissector_add("x.25.spi", NLPID_SPI_X_29, x29_handle);