2 * Routines for Cisco HDLC packet disassembly
4 * $Id: packet-chdlc.c,v 1.21 2003/10/25 07:17:26 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.
30 #include <epan/packet.h>
33 #include "chdlctypes.h"
34 #include <epan/resolv.h>
35 #include "packet-chdlc.h"
36 #include "packet-ppp.h"
37 #include "packet-ip.h"
40 * See section 4.3.1 of RFC 1547, and
42 * http://www.nethelp.no/net/cisco-hdlc.txt
45 static int proto_chdlc = -1;
46 static int hf_chdlc_addr = -1;
47 static int hf_chdlc_proto = -1;
49 static gint ett_chdlc = -1;
51 static int proto_slarp = -1;
52 static int hf_slarp_ptype = -1;
53 static int hf_slarp_address = -1;
54 static int hf_slarp_mysequence = -1;
55 static int hf_slarp_yoursequence = -1;
57 static gint ett_slarp = -1;
59 static dissector_handle_t data_handle;
62 * Protocol types for the Cisco HDLC format.
64 * As per the above, according to RFC 1547, these are "standard 16 bit
65 * Ethernet protocol type code[s]", but 0x8035 is Reverse ARP, and
66 * that is (at least according to the Linux ISDN code) not the
67 * same as Cisco SLARP.
69 * In addition, 0x2000 is apparently the Cisco Discovery Protocol, but
70 * on Ethernet those are encapsulated inside SNAP with an OUI of
71 * OUI_CISCO, not OUI_ENCAP_ETHER.
73 * Perhaps we should set up a protocol table for those protocols
74 * that differ between Ethernet and Cisco HDLC, and have the PPP
75 * code first try that table and, if it finds nothing in that
76 * table, call "ethertype()". (Unfortunately, that means that -
77 * assuming we had a Cisco SLARP dissector - said dissector were
78 * disabled, SLARP packets would be dissected as Reverse ARP
79 * packets, not as data.)
81 #define CISCO_SLARP 0x8035 /* Cisco SLARP protocol */
83 static dissector_table_t subdissector_table;
85 static const value_string chdlc_address_vals[] = {
86 {CHDLC_ADDR_UNICAST, "Unicast"},
87 {CHDLC_ADDR_MULTICAST, "Multicast"},
91 const value_string chdlc_vals[] = {
92 {0x2000, "Cisco Discovery Protocol"},
94 {CISCO_SLARP, "SLARP"},
95 {ETHERTYPE_DEC_LB, "DEC LanBridge"},
96 {CHDLCTYPE_BPDU, "Spanning Tree BPDU"},
97 {ETHERTYPE_ATALK, "Appletalk"},
98 {ETHERTYPE_AARP, "AARP"},
99 {ETHERTYPE_IPX, "Netware IPX/SPX"},
100 {ETHERTYPE_ETHBRIDGE, "Transparent Ethernet bridging" },
101 {CHDLCTYPE_OSI, "OSI" },
102 {ETHERTYPE_MPLS, "MPLS unicast"},
103 {ETHERTYPE_MPLS_MULTI, "MPLS multicast"},
108 capture_chdlc( const guchar *pd, int offset, int len, packet_counts *ld ) {
109 if (!BYTES_ARE_IN_FRAME(offset, len, 4)) {
113 switch (pntohs(&pd[offset + 2])) {
115 capture_ip(pd, offset + 4, len, ld);
124 chdlctype(guint16 chdlctype, tvbuff_t *tvb, int offset_after_chdlctype,
125 packet_info *pinfo, proto_tree *tree, proto_tree *fh_tree,
131 proto_tree_add_uint(fh_tree, chdlctype_id, tvb,
132 offset_after_chdlctype - 2, 2, chdlctype);
135 next_tvb = tvb_new_subset(tvb, offset_after_chdlctype, -1, -1);
137 /* do lookup with the subdissector table */
138 if (!dissector_try_port(subdissector_table, chdlctype, next_tvb, pinfo, tree)) {
139 if (check_col(pinfo->cinfo, COL_PROTOCOL))
140 col_add_fstr(pinfo->cinfo, COL_PROTOCOL, "0x%04x", chdlctype);
141 call_dissector(data_handle,next_tvb, pinfo, tree);
145 static gint chdlc_fcs_decode = 0; /* 0 = No FCS, 1 = 16 bit FCS, 2 = 32 bit FCS */
148 dissect_chdlc(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
151 proto_tree *fh_tree = NULL;
155 if (check_col(pinfo->cinfo, COL_PROTOCOL))
156 col_set_str(pinfo->cinfo, COL_PROTOCOL, "CHDLC");
157 if (check_col(pinfo->cinfo, COL_INFO))
158 col_clear(pinfo->cinfo, COL_INFO);
160 switch (pinfo->p2p_dir) {
163 if (check_col(pinfo->cinfo, COL_RES_DL_SRC))
164 col_set_str(pinfo->cinfo, COL_RES_DL_SRC, "DTE");
165 if (check_col(pinfo->cinfo, COL_RES_DL_DST))
166 col_set_str(pinfo->cinfo, COL_RES_DL_DST, "DCE");
170 if (check_col(pinfo->cinfo, COL_RES_DL_SRC))
171 col_set_str(pinfo->cinfo, COL_RES_DL_SRC, "DCE");
172 if (check_col(pinfo->cinfo, COL_RES_DL_DST))
173 col_set_str(pinfo->cinfo, COL_RES_DL_DST, "DTE");
177 if (check_col(pinfo->cinfo, COL_RES_DL_SRC))
178 col_set_str(pinfo->cinfo, COL_RES_DL_SRC, "N/A");
179 if (check_col(pinfo->cinfo, COL_RES_DL_DST))
180 col_set_str(pinfo->cinfo, COL_RES_DL_DST, "N/A");
184 addr = tvb_get_guint8(tvb, 0);
185 proto = tvb_get_ntohs(tvb, 2);
188 ti = proto_tree_add_item(tree, proto_chdlc, tvb, 0, 4, FALSE);
189 fh_tree = proto_item_add_subtree(ti, ett_chdlc);
191 proto_tree_add_uint(fh_tree, hf_chdlc_addr, tvb, 0, 1, addr);
194 decode_fcs(tvb, fh_tree, chdlc_fcs_decode, 2);
196 chdlctype(proto, tvb, 4, pinfo, tree, fh_tree, hf_chdlc_proto);
200 proto_register_chdlc(void)
202 static hf_register_info hf[] = {
204 { "Address", "chdlc.address", FT_UINT8, BASE_HEX,
205 VALS(chdlc_address_vals), 0x0, "", HFILL }},
207 { "Protocol", "chdlc.protocol", FT_UINT16, BASE_HEX,
208 VALS(chdlc_vals), 0x0, "", HFILL }},
210 static gint *ett[] = {
214 module_t *chdlc_module;
216 proto_chdlc = proto_register_protocol("Cisco HDLC", "CHDLC", "chdlc");
217 proto_register_field_array(proto_chdlc, hf, array_length(hf));
218 proto_register_subtree_array(ett, array_length(ett));
220 /* subdissector code */
221 subdissector_table = register_dissector_table("chdlctype",
222 "Cisco HDLC frame type", FT_UINT16, BASE_HEX);
224 register_dissector("chdlc", dissect_chdlc, proto_chdlc);
226 /* Register the preferences for the chdlc protocol */
227 chdlc_module = prefs_register_protocol(proto_chdlc, NULL);
229 prefs_register_enum_preference(chdlc_module,
231 "CHDLC Frame Checksum Type",
232 "The type of CHDLC frame checksum (none, 16-bit, 32-bit)",
239 proto_reg_handoff_chdlc(void)
241 dissector_handle_t chdlc_handle;
243 data_handle = find_dissector("data");
244 chdlc_handle = find_dissector("chdlc");
245 dissector_add("wtap_encap", WTAP_ENCAP_CHDLC, chdlc_handle);
246 dissector_add("wtap_encap", WTAP_ENCAP_CHDLC_WITH_PHDR, chdlc_handle);
249 #define SLARP_REQUEST 0
250 #define SLARP_REPLY 1
251 #define SLARP_LINECHECK 2
253 static const value_string slarp_ptype_vals[] = {
254 {SLARP_REQUEST, "Request"},
255 {SLARP_REPLY, "Reply"},
256 {SLARP_LINECHECK, "Line keepalive"},
261 dissect_slarp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
264 proto_tree *slarp_tree = NULL;
268 guint32 yoursequence;
270 if (check_col(pinfo->cinfo, COL_PROTOCOL))
271 col_set_str(pinfo->cinfo, COL_PROTOCOL, "SLARP");
272 if (check_col(pinfo->cinfo, COL_INFO))
273 col_clear(pinfo->cinfo, COL_INFO);
275 code = tvb_get_ntohl(tvb, 0);
278 ti = proto_tree_add_item(tree, proto_slarp, tvb, 0, 14, FALSE);
279 slarp_tree = proto_item_add_subtree(ti, ett_slarp);
286 if (check_col(pinfo->cinfo, COL_INFO)) {
287 tvb_memcpy(tvb, (guint8 *)&address, 4, 4);
288 col_add_fstr(pinfo->cinfo, COL_INFO, "%s, from %s, mask %s",
289 match_strval(code, slarp_ptype_vals),
290 get_hostname(address),
291 ip_to_str(tvb_get_ptr(tvb, 8, 4)));
294 proto_tree_add_uint(slarp_tree, hf_slarp_ptype, tvb, 0, 4, code);
295 proto_tree_add_item(slarp_tree, hf_slarp_address, tvb, 4, 4, FALSE);
296 proto_tree_add_text(slarp_tree, tvb, 8, 4,
297 "Netmask: %s", ip_to_str(tvb_get_ptr(tvb, 8, 4)));
301 case SLARP_LINECHECK:
302 mysequence = tvb_get_ntohl(tvb, 4);
303 yoursequence = tvb_get_ntohl(tvb, 8);
304 if (check_col(pinfo->cinfo, COL_INFO)) {
305 col_add_fstr(pinfo->cinfo, COL_INFO,
306 "%s, outgoing sequence %u, returned sequence %u",
307 match_strval(code, slarp_ptype_vals),
308 mysequence, yoursequence);
311 proto_tree_add_uint(slarp_tree, hf_slarp_ptype, tvb, 0, 4, code);
312 proto_tree_add_uint(slarp_tree, hf_slarp_mysequence, tvb, 4, 4,
314 proto_tree_add_uint(slarp_tree, hf_slarp_mysequence, tvb, 8, 4,
320 if (check_col(pinfo->cinfo, COL_INFO))
321 col_add_fstr(pinfo->cinfo, COL_INFO, "Unknown packet type 0x%08X", code);
323 proto_tree_add_uint(slarp_tree, hf_slarp_ptype, tvb, 0, 4, code);
324 call_dissector(data_handle, tvb_new_subset(tvb, 4, -1, -1), pinfo,
332 proto_register_slarp(void)
334 static hf_register_info hf[] = {
336 { "Packet type", "slarp.ptype", FT_UINT32, BASE_DEC,
337 VALS(slarp_ptype_vals), 0x0, "", HFILL }},
339 { "Address", "slarp.address", FT_IPv4, BASE_NONE,
340 NULL, 0x0, "", HFILL }},
341 /* XXX - need an FT_ for netmasks, which is like FT_IPV4 but doesn't
342 get translated to a host name. */
343 { &hf_slarp_mysequence,
344 { "Outgoing sequence number", "slarp.mysequence", FT_UINT32, BASE_DEC,
345 NULL, 0x0, "", HFILL }},
346 { &hf_slarp_yoursequence,
347 { "Returned sequence number", "slarp.yoursequence", FT_UINT32, BASE_DEC,
348 NULL, 0x0, "", HFILL }},
350 static gint *ett[] = {
355 proto_slarp = proto_register_protocol("Cisco SLARP", "SLARP", "slarp");
356 proto_register_field_array(proto_slarp, hf, array_length(hf));
357 proto_register_subtree_array(ett, array_length(ett));
361 proto_reg_handoff_slarp(void)
363 dissector_handle_t slarp_handle;
365 slarp_handle = create_dissector_handle(dissect_slarp, proto_slarp);
366 dissector_add("chdlctype", CISCO_SLARP, slarp_handle);