3 * Routine to dissect X.224
4 * Copyright 2007, Ronnie Sahlberg
8 * Wireshark - Network traffic analyzer
9 * By Gerald Combs <gerald@wireshark.org>
10 * Copyright 1998 Gerald Combs
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
30 #include <epan/packet.h>
32 #include "packet-tpkt.h"
33 #include <epan/conversation.h>
34 #include <epan/wmem/wmem.h>
36 void proto_register_x224(void);
37 void proto_reg_handoff_x224(void);
39 /* X.224 header fields */
40 static int proto_x224
= -1;
41 static int hf_x224_length
= -1;
42 static int hf_x224_code
= -1;
43 static int hf_x224_src_ref
= -1;
44 static int hf_x224_dst_ref
= -1;
45 static int hf_x224_class
= -1;
46 static int hf_x224_rdp_rt
= -1;
47 static int hf_x224_nr
= -1;
48 static int hf_x224_eot
= -1;
52 /* X.224 fields defining a sub tree */
53 static gint ett_x224
= -1;
56 /* find the dissector for T.125 */
57 static dissector_handle_t t125_handle
;
60 typedef struct _x224_conv_info_t
{
65 #define X224_CODE_CR 0xE
66 #define X224_CODE_CC 0xD
67 #define X224_CODE_DR 0x8
68 #define X224_CODE_DC 0xC
69 #define X224_CODE_DT 0xF
70 #define X224_CODE_ED 0x1
71 #define X224_CODE_AK 0x6
72 #define X224_CODE_EA 0x2
73 #define X224_CODE_RJ 0x5
74 #define X224_CODE_ER 0x7
76 static const value_string code_vals
[] = {
77 {X224_CODE_CR
, "Connection Request"},
78 {X224_CODE_CC
, "Connection Confirm"},
79 {X224_CODE_DR
, "Disconnect Request"},
80 {X224_CODE_DC
, "Disconnect Confirm"},
81 {X224_CODE_DT
, "Data"},
82 {X224_CODE_ED
, "Expedited Data"},
83 {X224_CODE_AK
, "Data Ack"},
84 {X224_CODE_EA
, "Expedited Data Ack"},
85 {X224_CODE_RJ
, "Reject"},
86 {X224_CODE_ER
, "Error"},
90 static const value_string class_option_vals
[] = {
100 dissect_x224_cr(packet_info
*pinfo _U_
, proto_tree
*tree
, tvbuff_t
*tvb
, int offset
, x224_conv_info_t
*x224_info _U_
)
103 gint len
, next_offset
;
105 /*DST-REF is always 0 */
109 proto_tree_add_item(tree
, hf_x224_src_ref
, tvb
, offset
, 2, ENC_BIG_ENDIAN
);
113 /*class = tvb_get_guint8(tvb, offset);*/
114 proto_tree_add_item(tree
, hf_x224_class
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
117 if(tvb_length_remaining(tvb
, offset
) > 0) {
118 len
= tvb_find_line_end(tvb
, offset
, -1, &next_offset
, TRUE
);
119 proto_tree_add_item(tree
, hf_x224_rdp_rt
, tvb
, offset
, len
,
121 offset
= next_offset
;
128 dissect_x224_cc(packet_info
*pinfo _U_
, proto_tree
*tree
, tvbuff_t
*tvb
, int offset
, x224_conv_info_t
*x224_info
)
133 proto_tree_add_item(tree
, hf_x224_dst_ref
, tvb
, offset
, 2, ENC_BIG_ENDIAN
);
137 proto_tree_add_item(tree
, hf_x224_src_ref
, tvb
, offset
, 2, ENC_BIG_ENDIAN
);
141 klass
= tvb_get_guint8(tvb
, offset
);
142 proto_tree_add_item(tree
, hf_x224_class
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
143 x224_info
->klass
= klass
;
150 dissect_x224_dt(packet_info
*pinfo _U_
, proto_tree
*tree
, tvbuff_t
*tvb
, int offset
, x224_conv_info_t
*x224_info
, proto_tree
*parent_tree
)
152 proto_item
*item
= NULL
;
155 switch (x224_info
->klass
>>4) {
160 proto_tree_add_item(tree
, hf_x224_dst_ref
, tvb
, offset
, 2, ENC_BIG_ENDIAN
);
165 item
= proto_tree_add_uint(tree
, hf_x224_class
, tvb
, 0, 0, x224_info
->klass
);
166 PROTO_ITEM_SET_GENERATED(item
);
170 proto_tree_add_item(tree
, hf_x224_eot
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
171 proto_tree_add_item(tree
, hf_x224_nr
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
175 next_tvb
= tvb_new_subset_remaining(tvb
, offset
);
176 call_dissector(t125_handle
, next_tvb
, pinfo
, parent_tree
);
182 dissect_x224(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*parent_tree
, void *data _U_
)
184 proto_tree
*tree
= NULL
;
185 proto_item
*item
= NULL
;
188 conversation_t
*conversation
;
189 x224_conv_info_t
*x224_info
;
191 col_set_str(pinfo
->cinfo
, COL_PROTOCOL
, "X.224");
192 col_clear(pinfo
->cinfo
, COL_INFO
);
194 length
= tvb_get_guint8(tvb
, offset
);
196 item
= proto_tree_add_item(parent_tree
, proto_x224
, tvb
, offset
, length
+1, ENC_NA
);
197 tree
= proto_item_add_subtree(item
, ett_x224
);
201 /* length indicator */
202 proto_tree_add_item(tree
, hf_x224_length
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
206 code
= tvb_get_guint8(tvb
, offset
);
207 proto_tree_add_item(tree
, hf_x224_code
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
210 col_add_fstr(pinfo
->cinfo
, COL_INFO
, "%s (0x%02x)",
211 val_to_str(code
>>4, code_vals
, "Unknown code :%x"),
217 * We need to track some state for this protocol on a per conversation
218 * basis so we can do neat things like request/response tracking
220 conversation
= find_or_create_conversation(pinfo
);
223 * Do we already have a state structure for this conv
225 x224_info
= (x224_conv_info_t
*)conversation_get_proto_data(conversation
, proto_x224
);
227 /* No. Attach that information to the conversation, and add
228 * it to the list of information structures.
230 x224_info
= wmem_new(wmem_file_scope(), x224_conv_info_t
);
233 conversation_add_proto_data(conversation
, proto_x224
, x224_info
);
238 offset
= dissect_x224_cr(pinfo
, tree
, tvb
, offset
, x224_info
);
241 offset
= dissect_x224_cc(pinfo
, tree
, tvb
, offset
, x224_info
);
244 /* XXX not implemented yet */
247 /* XXX not implemented yet */
250 offset
= dissect_x224_dt(pinfo
, tree
, tvb
, offset
, x224_info
, parent_tree
);
253 /* XXX not implemented yet */
256 /* XXX not implemented yet */
259 /* XXX not implemented yet */
262 /* XXX not implemented yet */
265 /* XXX not implemented yet */
272 proto_register_x224(void)
274 static hf_register_info hf
[] =
277 "Length", "x224.length", FT_UINT8
, BASE_DEC
,
278 NULL
, 0, NULL
, HFILL
}},
281 "Code", "x224.code", FT_UINT8
, BASE_HEX
,
282 VALS(code_vals
), 0xf0, NULL
, HFILL
}},
284 { &hf_x224_src_ref
, {
285 "SRC-REF", "x224.src_ref", FT_UINT16
, BASE_HEX
,
286 NULL
, 0, NULL
, HFILL
}},
288 { &hf_x224_dst_ref
, {
289 "DST-REF", "x224.dst_ref", FT_UINT16
, BASE_HEX
,
290 NULL
, 0, NULL
, HFILL
}},
293 "Class", "x224.class", FT_UINT8
, BASE_HEX
,
294 VALS(class_option_vals
), 0xf0, NULL
, HFILL
}},
297 "RDP Routing Token", "x224.rdp_rt", FT_STRING
, BASE_NONE
, NULL
, 0,
298 "Used for Remote Desktop Protocol (RDP) load balancing", HFILL
}},
301 "NR", "x224.nr", FT_UINT8
, BASE_HEX
,
302 NULL
, 0x7f, NULL
, HFILL
}},
305 "EOT", "x224.eot", FT_BOOLEAN
, 8,
306 NULL
, 0x80, NULL
, HFILL
}},
315 proto_x224
= proto_register_protocol("ITU-T Rec X.224", "X.224", "x224");
316 proto_register_field_array(proto_x224
, hf
, array_length(hf
));
317 proto_register_subtree_array(ett
, array_length(ett
));
318 new_register_dissector("x224", dissect_x224
, proto_x224
);
323 proto_reg_handoff_x224(void)
325 t125_handle
= find_dissector("t125");