epan/dissectors/pidl/samr/samr.cnf cnf_dissect_lsa_BinaryString => lsarpc_dissect_str...
[wireshark-sm.git] / epan / dissectors / packet-x29.c
blob18f6973d0979a839de1cf3a8e95d2bf228472e88
1 /* packet-x29.c
2 * Routines for X.29 packet dissection
4 * Wireshark - Network traffic analyzer
5 * By Gerald Combs <gerald@wireshark.org>
6 * Copyright 1998 Gerald Combs
8 * SPDX-License-Identifier: GPL-2.0-or-later
9 */
11 #include "config.h"
13 #include <epan/packet.h>
14 #include <epan/nlpid.h>
16 void proto_register_x29(void);
17 void proto_reg_handoff_x29(void);
19 static dissector_handle_t x29_handle;
21 static int proto_x29;
22 static int hf_msg_code;
23 static int hf_error_type;
24 static int hf_inv_msg_code;
26 /* Generated from convert_proto_tree_add_text.pl */
27 static int hf_x29_pad_message_data;
28 static int hf_x29_type_reference_value;
29 static int hf_x29_type_reference;
30 static int hf_x29_data;
31 static int hf_x29_type_of_aspect;
32 static int hf_x29_reselection_message_data;
33 static int hf_x29_break_value;
34 static int hf_x29_parameter;
35 static int hf_x29_value;
37 static int ett_x29;
40 * PAD messages.
42 #define SET_MSG 0x02
43 #define READ_MSG 0x04
44 #define SET_AND_READ_MSG 0x06
45 #define PARAMETER_IND_MSG 0x00
46 #define INV_TO_CLEAR_MSG 0x01
47 #define BREAK_IND_MSG 0x03
48 #define RESELECTION_MSG 0x07
49 #define ERROR_MSG 0x05
50 #define RESEL_WITH_TOA_NPI_MSG 0x08
52 static const value_string message_code_vals[] = {
53 { SET_MSG, "Set" },
54 { READ_MSG, "Read" },
55 { SET_AND_READ_MSG, "Set and read" },
56 { PARAMETER_IND_MSG, "Parameter indication" },
57 { INV_TO_CLEAR_MSG, "Invitation to clear" },
58 { BREAK_IND_MSG, "Indication of break" },
59 { RESELECTION_MSG, "Reselection" },
60 { ERROR_MSG, "Error" },
61 { RESEL_WITH_TOA_NPI_MSG, "Reselection with TOA/NPI" },
62 { 0, NULL }
65 static const value_string error_type_vals[] = {
66 { 0x00, "Received PAD message contained less than eight bits" },
67 { 0x02, "Unrecognized message code in received PAD message" },
68 { 0x04, "Parameter field format was incorrect or incompatible with message code" },
69 { 0x06, "Received PAD message did not contain an integral number of octets" },
70 { 0x08, "Received Parameter Indication PAD message was unsolicited" },
71 { 0x0A, "Received PAD message was too long" },
72 { 0x0C, "Unauthorized reselection PAD message" },
73 { 0, NULL },
76 static const value_string reference_type_vals[] = {
77 { 0x01, "Change in PAD Aspect" },
78 { 0x08, "Break" },
79 { 0, NULL },
82 static int
83 dissect_x29(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data)
85 int offset = 0;
86 proto_tree *x29_tree;
87 proto_item *ti;
88 bool *q_bit_set;
89 uint8_t msg_code;
90 uint8_t error_type;
91 uint8_t type_ref;
92 int next_offset;
93 int linelen;
95 /* Reject the packet if data is NULL */
96 if (data == NULL)
97 return 0;
98 q_bit_set = (bool *)data;
100 col_set_str(pinfo->cinfo, COL_PROTOCOL, "X.29");
101 col_clear(pinfo->cinfo, COL_INFO);
103 ti = proto_tree_add_item(tree, proto_x29, tvb, offset, -1, ENC_NA);
104 x29_tree = proto_item_add_subtree(ti, ett_x29);
106 if (*q_bit_set) {
108 * Q bit set - this is a PAD message.
110 msg_code = tvb_get_uint8(tvb, offset);
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);
117 offset++;
119 switch (msg_code) {
121 case SET_MSG:
122 case READ_MSG:
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_item(x29_tree, hf_x29_parameter, tvb, offset, 1, ENC_BIG_ENDIAN);
130 offset++;
131 proto_tree_add_item(x29_tree, hf_x29_value, tvb, offset, 1, ENC_BIG_ENDIAN);
132 offset++;
134 break;
136 case INV_TO_CLEAR_MSG:
138 * No data for this message.
140 break;
142 case ERROR_MSG:
143 error_type = tvb_get_uint8(tvb, offset);
144 proto_tree_add_uint(x29_tree, hf_error_type, tvb,
145 offset, 1, error_type);
146 offset++;
147 if (error_type != 0) {
148 proto_tree_add_item(x29_tree, hf_inv_msg_code,
149 tvb, offset, 1, ENC_BIG_ENDIAN);
151 break;
153 case BREAK_IND_MSG:
154 if (tvb_reported_length_remaining(tvb, offset) > 0) {
155 type_ref = tvb_get_uint8(tvb, offset);
156 proto_tree_add_item(x29_tree, hf_x29_type_reference, tvb, offset, 1, ENC_BIG_ENDIAN);
157 offset++;
158 switch (type_ref) {
160 case 0x01: /* change in PAD Aspect */
162 * XXX - dissect as per X.28.
164 proto_tree_add_item(x29_tree, hf_x29_type_of_aspect, tvb, offset, 1, ENC_BIG_ENDIAN);
165 offset++;
166 break;
168 case 0x08: /* break */
169 proto_tree_add_item(x29_tree, hf_x29_break_value, tvb, offset, 1, ENC_BIG_ENDIAN);
170 offset++;
171 break;
173 default:
174 proto_tree_add_item(x29_tree, hf_x29_type_reference_value, tvb, offset, 1, ENC_BIG_ENDIAN);
175 offset++;
176 break;
179 break;
181 case RESELECTION_MSG:
183 * XXX - dissect me.
185 proto_tree_add_item(x29_tree, hf_x29_reselection_message_data, tvb, offset, -1, ENC_NA);
186 break;
188 case RESEL_WITH_TOA_NPI_MSG:
190 * XXX - dissect me.
192 proto_tree_add_item(x29_tree, hf_x29_reselection_message_data, tvb, offset, -1, ENC_NA);
193 break;
195 default:
196 proto_tree_add_item(x29_tree, hf_x29_pad_message_data, tvb, offset, -1, ENC_NA);
197 break;
199 } else {
201 * Q bit not set - this is data.
203 col_set_str(pinfo->cinfo, COL_INFO, "Data ...");
205 if (tree) {
206 while (tvb_offset_exists(tvb, offset)) {
208 * Find the end of the line.
210 tvb_find_line_end(tvb, offset, -1,
211 &next_offset, false);
214 * Now compute the length of the line
215 * *including* the end-of-line indication,
216 * if any; we display it all.
218 linelen = next_offset - offset;
220 proto_tree_add_item(x29_tree, hf_x29_data, tvb, offset, linelen, ENC_NA|ENC_ASCII);
221 offset = next_offset;
226 return tvb_captured_length(tvb);
229 void
230 proto_register_x29(void)
232 static hf_register_info hf[] = {
233 { &hf_msg_code,
234 { "Message code", "x29.msg_code", FT_UINT8, BASE_HEX,
235 VALS(message_code_vals), 0x0, "X.29 PAD message code",
236 HFILL }},
237 { &hf_error_type,
238 { "Error type", "x29.error_type", FT_UINT8, BASE_HEX,
239 VALS(error_type_vals), 0x0, "X.29 error PAD message error type",
240 HFILL }},
241 { &hf_inv_msg_code,
242 { "Invalid message code", "x29.inv_msg_code", FT_UINT8, BASE_HEX,
243 VALS(message_code_vals), 0x0, "X.29 Error PAD message invalid message code",
244 HFILL }},
246 /* Generated from convert_proto_tree_add_text.pl */
247 { &hf_x29_type_reference, { "Type reference", "x29.type_reference", FT_UINT8, BASE_DEC, VALS(reference_type_vals), 0x0, NULL, HFILL }},
248 { &hf_x29_type_of_aspect, { "Type of aspect", "x29.type_of_aspect", FT_UINT8, BASE_HEX, NULL, 0x0, NULL, HFILL }},
249 { &hf_x29_break_value, { "Break value", "x29.break_value", FT_UINT8, BASE_HEX, NULL, 0x0, NULL, HFILL }},
250 { &hf_x29_type_reference_value, { "Type value", "x29.type_reference.value", FT_UINT8, BASE_HEX, NULL, 0x0, NULL, HFILL }},
251 { &hf_x29_reselection_message_data, { "Reselection message data", "x29.reselection_message_data", FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL }},
252 { &hf_x29_pad_message_data, { "PAD message data", "x29.pad_message_data", FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL }},
253 { &hf_x29_data, { "Data", "x29.data", FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL }},
254 { &hf_x29_parameter, { "Parameter", "x29.parameter", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }},
255 { &hf_x29_value, { "Value", "x29.value", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }},
257 static int *ett[] = {
258 &ett_x29,
261 proto_x29 = proto_register_protocol("X.29", "X.29", "x29");
262 x29_handle = register_dissector("x29", dissect_x29, proto_x29);
263 proto_register_field_array(proto_x29, hf, array_length(hf));
264 proto_register_subtree_array(ett, array_length(ett));
267 void
268 proto_reg_handoff_x29(void)
270 dissector_add_uint("x.25.spi", NLPID_SPI_X_29, x29_handle);
274 * Editor modelines - https://www.wireshark.org/tools/modelines.html
276 * Local variables:
277 * c-basic-offset: 8
278 * tab-width: 8
279 * indent-tabs-mode: t
280 * End:
282 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
283 * :indentSize=8:tabSize=8:noTabs=false: