2 * Routines for IEEE 802.2 LLC layer
3 * Gilbert Ramirez <gram@alumni.rice.edu>
5 * $Id: packet-llc.c,v 1.98 2002/05/29 03:08:01 guy Exp $
7 * Ethereal - Network traffic analyzer
8 * By Gerald Combs <gerald@ethereal.com>
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
30 #ifdef HAVE_SYS_TYPES_H
31 # include <sys/types.h>
35 #include <epan/packet.h>
40 #include "bridged_pids.h"
42 #include "packet-ip.h"
43 #include "packet-ipx.h"
44 #include "packet-netbios.h"
45 #include <epan/sna-utils.h>
47 #include "packet-llc.h"
49 #define UDP_PORT_LLC1 12000
50 #define UDP_PORT_LLC2 12001
51 #define UDP_PORT_LLC3 12002
52 #define UDP_PORT_LLC4 12003
53 #define UDP_PORT_LLC5 12004
55 static int proto_llc = -1;
56 static int hf_llc_dsap = -1;
57 static int hf_llc_ssap = -1;
58 static int hf_llc_dsap_ig = -1;
59 static int hf_llc_ssap_cr = -1;
60 static int hf_llc_ctrl = -1;
61 static int hf_llc_type = -1;
62 static int hf_llc_oui = -1;
63 static int hf_llc_pid = -1;
65 static gint ett_llc = -1;
66 static gint ett_llc_ctrl = -1;
68 static dissector_table_t subdissector_table;
69 static dissector_table_t cisco_subdissector_table;
71 static dissector_handle_t bpdu_handle;
72 static dissector_handle_t eth_handle;
73 static dissector_handle_t fddi_handle;
74 static dissector_handle_t tr_handle;
75 static dissector_handle_t data_handle;
78 * Group/Individual bit, in the DSAP.
80 #define DSAP_GI_BIT 0x01
83 * Command/Response bit, in the SSAP.
85 * The low-order bit of the SSAP apparently determines whether this
86 * is a request or a response. (RFC 1390, "Transmission of IP and
87 * ARP over FDDI Networks", says
89 * Command frames are identified by having the low order
90 * bit of the SSAP address reset to zero. Response frames
91 * have the low order bit of the SSAP address set to one.
93 * and a page I've seen seems to imply that's part of 802.2.)
95 #define SSAP_CR_BIT 0x01
98 * Mask to extrace the SAP number from the DSAP or the SSAP.
100 #define SAP_MASK 0xFE
103 * These are for SSAP and DSAP, wth last bit always zero.
104 * XXX - some DSAPs come in separate "individual" and "group" versions,
105 * with the last bit 0 and 1, respectively (e.g., LLC Sub-layer Management,
106 * IBM SNA Path Control, IBM Net Management), but, whilst 0xFE is
107 * the ISO Network Layer Protocol, 0xFF is the Global LSAP.
109 static const value_string sap_vals[] = {
110 { SAP_NULL, "NULL LSAP" },
111 { SAP_LLC_SLMGMT, "LLC Sub-Layer Management" },
112 { SAP_SNA_PATHCTRL, "SNA Path Control" },
113 { SAP_IP, "TCP/IP" },
116 { SAP_PROWAY_NM_INIT, "PROWAY (IEC955) Network Management and Initialization" },
117 { SAP_TI, "Texas Instruments" },
118 { SAP_BPDU, "Spanning Tree BPDU" },
119 { SAP_RS511, "EIA RS-511 Manufacturing Message Service" },
120 { SAP_X25, "ISO 8208 (X.25 over 802.2)" },
122 * XXX - setting the group bit of SAP_X25 make 0x7F; is this just
123 * a group version of that?
125 { 0x7F, "ISO 802.2" },
127 { SAP_NESTAR, "Nestar" },
128 { SAP_PROWAY_ASLM, "PROWAY (IEC955) Active Station List Maintenance" },
129 { SAP_ARP, "ARP" }, /* XXX - hand to "dissect_arp()"? */
130 { SAP_SNAP, "SNAP" },
131 { SAP_VINES1, "Banyan Vines" },
132 { SAP_VINES2, "Banyan Vines" },
133 { SAP_NETWARE, "NetWare" },
134 { SAP_NETBIOS, "NetBIOS" },
135 { SAP_IBMNM, "IBM Net Management" },
136 { SAP_RPL1, "Remote Program Load" },
137 { SAP_UB, "Ungermann-Bass" },
138 { SAP_RPL2, "Remote Program Load" },
139 { SAP_OSINL, "ISO Network Layer" },
140 { SAP_GLOBAL, "Global LSAP" },
147 * http://www.cisco.com/univercd/cc/td/doc/product/lan/trsrb/vlan.htm
149 * for the PIDs for VTP and DRiP that go with an OUI of OUI_CISCO.
151 const value_string oui_vals[] = {
152 { OUI_ENCAP_ETHER, "Encapsulated Ethernet" },
154 http://www.cisco.com/univercd/cc/td/doc/product/software/ios113ed/113ed_cr/ibm_r/brprt1/brsrb.htm
156 { OUI_CISCO, "Cisco" },
157 { OUI_CISCO_90, "Cisco IOS 9.0 Compatible" },
158 { OUI_BRIDGED, "Frame Relay or ATM bridged frames" },
159 /* RFC 2427, RFC 2684 */
160 { OUI_ATM_FORUM, "ATM Forum" },
161 { OUI_CABLE_BPDU, "DOCSIS Spanning Tree" }, /* DOCSIS spanning tree BPDU */
162 { OUI_APPLE_ATALK, "Apple (AppleTalk)" },
167 capture_llc(const u_char *pd, int offset, int len, packet_counts *ld) {
175 if (!BYTES_ARE_IN_FRAME(offset, len, 2)) {
179 is_snap = (pd[offset] == SAP_SNAP) && (pd[offset+1] == SAP_SNAP);
180 llc_header_len = 2; /* DSAP + SSAP */
183 * XXX - the page referred to in the comment above about the
184 * Command/Response bit also implies that LLC Type 2 always
185 * uses extended operation, so we don't need to determine
186 * whether it's basic or extended operation; is that the case?
188 control = get_xdlc_control(pd, offset+2, pd[offset+1] & SSAP_CR_BIT);
189 llc_header_len += XDLC_CONTROL_LEN(control, TRUE);
191 llc_header_len += 5; /* 3 bytes of OUI, 2 bytes of protocol ID */
192 if (!BYTES_ARE_IN_FRAME(offset, len, llc_header_len)) {
198 oui = pd[offset+3] << 16 | pd[offset+4] << 8 | pd[offset+5];
199 if (XDLC_IS_INFORMATION(control)) {
200 etype = pntohs(&pd[offset+6]);
203 case OUI_ENCAP_ETHER:
205 case OUI_APPLE_ATALK:
206 /* No, I have no idea why Apple used
207 one of their own OUIs, rather than
208 OUI_ENCAP_ETHER, and an Ethernet
209 packet type as protocol ID, for
210 AppleTalk data packets - but used
211 OUI_ENCAP_ETHER and an Ethernet
212 packet type for AARP packets. */
213 capture_ethertype(etype, pd, offset+8, len,
217 capture_ethertype(etype, pd, offset + 8, len,
228 if (XDLC_IS_INFORMATION(control)) {
229 switch (pd[offset]) {
232 capture_ip(pd, offset + llc_header_len, len,
253 dissect_llc(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
255 proto_tree *llc_tree = NULL;
256 proto_item *ti = NULL;
263 if (check_col(pinfo->cinfo, COL_PROTOCOL)) {
264 col_set_str(pinfo->cinfo, COL_PROTOCOL, "LLC");
266 if (check_col(pinfo->cinfo, COL_INFO)) {
267 col_clear(pinfo->cinfo, COL_INFO);
270 dsap = tvb_get_guint8(tvb, 0);
272 ti = proto_tree_add_item(tree, proto_llc, tvb, 0, -1, FALSE);
273 llc_tree = proto_item_add_subtree(ti, ett_llc);
274 proto_tree_add_uint(llc_tree, hf_llc_dsap, tvb, 0,
276 proto_tree_add_boolean(llc_tree, hf_llc_dsap_ig, tvb, 0,
277 1, dsap & DSAP_GI_BIT);
281 ssap = tvb_get_guint8(tvb, 1);
283 proto_tree_add_uint(llc_tree, hf_llc_ssap, tvb, 1,
285 proto_tree_add_boolean(llc_tree, hf_llc_ssap_cr, tvb, 1,
286 1, ssap & SSAP_CR_BIT);
290 is_snap = (dsap == SAP_SNAP) && (ssap == SAP_SNAP);
291 llc_header_len = 2; /* DSAP + SSAP */
294 * XXX - the page referred to in the comment above about the
295 * Command/Response bit also implies that LLC Type 2 always
296 * uses extended operation, so we don't need to determine
297 * whether it's basic or extended operation; is that the case?
299 control = dissect_xdlc_control(tvb, 2, pinfo, llc_tree,
300 hf_llc_ctrl, ett_llc_ctrl,
301 ssap & SSAP_CR_BIT, TRUE);
302 llc_header_len += XDLC_CONTROL_LEN(control, TRUE);
304 llc_header_len += 5; /* 3 bytes of OUI, 2 bytes of protocol ID */
307 proto_item_set_len(ti, llc_header_len);
310 dissect_snap(tvb, 3, pinfo, tree, llc_tree, control,
311 hf_llc_oui, hf_llc_type, hf_llc_pid, 2);
314 if (check_col(pinfo->cinfo, COL_INFO)) {
315 col_append_fstr(pinfo->cinfo, COL_INFO,
316 "; DSAP %s %s, SSAP %s %s",
317 val_to_str(dsap & SAP_MASK, sap_vals, "%02x"),
319 "Group" : "Individual",
320 val_to_str(ssap & SAP_MASK, sap_vals, "%02x"),
322 "Response" : "Command"
326 next_tvb = tvb_new_subset(tvb, llc_header_len, -1, -1);
327 if (XDLC_IS_INFORMATION(control)) {
329 /* do lookup with the subdissector table */
330 if (!dissector_try_port(subdissector_table, dsap,
331 next_tvb, pinfo, tree)) {
332 call_dissector(data_handle,next_tvb, pinfo, tree);
335 call_dissector(data_handle,next_tvb, pinfo, tree);
341 * Dissect SNAP header; used elsewhere, e.g. in the Frame Relay dissector.
344 dissect_snap(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree,
345 proto_tree *snap_tree, int control, int hf_oui, int hf_type, int hf_pid,
352 oui = tvb_get_ntoh24(tvb, offset);
353 etype = tvb_get_ntohs(tvb, offset+3);
355 if (check_col(pinfo->cinfo, COL_INFO)) {
356 col_append_fstr(pinfo->cinfo, COL_INFO,
357 "; SNAP, OUI 0x%06X (%s), PID 0x%04X",
358 oui, val_to_str(oui, oui_vals, "Unknown"), etype);
361 proto_tree_add_uint(snap_tree, hf_oui, tvb, offset, 3, oui);
366 case OUI_ENCAP_ETHER:
368 case OUI_APPLE_ATALK:
369 /* No, I have no idea why Apple used
370 one of their own OUIs, rather than
371 OUI_ENCAP_ETHER, and an Ethernet
372 packet type as protocol ID, for
373 AppleTalk data packets - but used
374 OUI_ENCAP_ETHER and an Ethernet
375 packet type for AARP packets. */
376 if (XDLC_IS_INFORMATION(control)) {
377 ethertype(etype, tvb, offset+5,
378 pinfo, tree, snap_tree, hf_type, -1);
380 next_tvb = tvb_new_subset(tvb, offset+5, -1, -1);
381 call_dissector(data_handle,next_tvb, pinfo, tree);
387 * MAC frames bridged over ATM (RFC 2684) or Frame Relay
390 * We have to figure out how much padding to put
391 * into the frame. We were handed a "bridge_pad"
392 * argument which should be 0 for Frame Relay and
393 * 2 for ATM; we add to that the amount of padding
394 * common to both bridging types.
397 proto_tree_add_uint(snap_tree, hf_pid, tvb, offset+3, 2,
403 case BPID_ETH_WITH_FCS:
404 case BPID_ETH_WITHOUT_FCS:
405 next_tvb = tvb_new_subset(tvb, offset+5+bridge_pad,
407 call_dissector(eth_handle, next_tvb, pinfo, tree);
410 case BPID_802_5_WITH_FCS:
411 case BPID_802_5_WITHOUT_FCS:
413 * We treat the last padding byte as the Access
414 * Control byte, as that's what the Token
415 * Ring dissector expects the first byte to
418 next_tvb = tvb_new_subset(tvb, offset+5+bridge_pad,
420 call_dissector(tr_handle, next_tvb, pinfo, tree);
423 case BPID_FDDI_WITH_FCS:
424 case BPID_FDDI_WITHOUT_FCS:
425 next_tvb = tvb_new_subset(tvb, offset+5+1+bridge_pad,
427 call_dissector(fddi_handle, next_tvb, pinfo, tree);
431 next_tvb = tvb_new_subset(tvb, offset+5, -1, -1);
432 call_dissector(bpdu_handle, next_tvb, pinfo, tree);
436 next_tvb = tvb_new_subset(tvb, offset+5, -1, -1);
437 call_dissector(data_handle,next_tvb, pinfo, tree);
443 /* So are all CDP packets LLC packets
444 with an OUI of OUI_CISCO and a
445 protocol ID of 0x2000, or
446 are some of them raw or encapsulated
449 proto_tree_add_uint(snap_tree, hf_pid, tvb, offset+3, 2,
452 next_tvb = tvb_new_subset(tvb, offset+5, -1, -1);
453 if (XDLC_IS_INFORMATION(control)) {
454 /* do lookup with the subdissector table */
455 /* for future reference, 0x0102 is Cisco DRIP */
456 if (!dissector_try_port(cisco_subdissector_table,
457 etype, next_tvb, pinfo, tree))
458 call_dissector(data_handle,next_tvb, pinfo, tree);
460 call_dissector(data_handle,next_tvb, pinfo, tree);
463 case OUI_CABLE_BPDU: /* DOCSIS cable modem spanning tree BPDU */
465 proto_tree_add_uint(snap_tree, hf_pid, tvb, offset+3, 2,
468 next_tvb = tvb_new_subset(tvb, offset+5, -1, -1);
469 call_dissector(bpdu_handle, next_tvb, pinfo, tree);
474 proto_tree_add_uint(snap_tree, hf_pid, tvb, offset+3, 2,
477 next_tvb = tvb_new_subset(tvb, offset+5, -1, -1);
478 call_dissector(data_handle,next_tvb, pinfo, tree);
484 proto_register_llc(void)
486 static struct true_false_string ig_bit = { "Group", "Individual" };
487 static struct true_false_string cr_bit = { "Response", "Command" };
489 static hf_register_info hf[] = {
491 { "DSAP", "llc.dsap", FT_UINT8, BASE_HEX,
492 VALS(sap_vals), 0x0, "", HFILL }},
495 { "IG Bit", "llc.dsap.ig", FT_BOOLEAN, BASE_HEX,
496 &ig_bit, 0x0, "Individual/Group", HFILL }},
499 { "SSAP", "llc.ssap", FT_UINT8, BASE_HEX,
500 VALS(sap_vals), 0x0, "", HFILL }},
503 { "CR Bit", "llc.ssap.cr", FT_BOOLEAN, BASE_HEX,
504 &cr_bit, 0x0, "Command/Response", HFILL }},
507 { "Control", "llc.control", FT_UINT16, BASE_HEX,
508 NULL, 0x0, "", HFILL }},
510 /* registered here but handled in ethertype.c */
512 { "Type", "llc.type", FT_UINT16, BASE_HEX,
513 VALS(etype_vals), 0x0, "", HFILL }},
516 { "Organization Code", "llc.oui", FT_UINT24, BASE_HEX,
517 VALS(oui_vals), 0x0, "", HFILL }},
520 { "Protocol ID", "llc.pid", FT_UINT16, BASE_HEX,
521 NULL, 0x0, "", HFILL }}
523 static gint *ett[] = {
528 proto_llc = proto_register_protocol("Logical-Link Control", "LLC", "llc");
529 proto_register_field_array(proto_llc, hf, array_length(hf));
530 proto_register_subtree_array(ett, array_length(ett));
532 /* subdissector code */
533 subdissector_table = register_dissector_table("llc.dsap",
534 "LLC SAP", FT_UINT8, BASE_HEX);
535 cisco_subdissector_table = register_dissector_table("llc.cisco_pid",
536 "Cisco OUI PID", FT_UINT16, BASE_HEX);
538 register_dissector("llc", dissect_llc, proto_llc);
542 proto_reg_handoff_llc(void)
544 dissector_handle_t llc_handle;
547 * Get handles for the BPDU, Ethernet, FDDI, and Token Ring
550 bpdu_handle = find_dissector("bpdu");
551 eth_handle = find_dissector("eth");
552 fddi_handle = find_dissector("fddi");
553 tr_handle = find_dissector("tr");
554 data_handle = find_dissector("data");
556 llc_handle = find_dissector("llc");
557 dissector_add("wtap_encap", WTAP_ENCAP_ATM_RFC1483, llc_handle);
559 dissector_add("ppp.protocol", PPP_LLC, llc_handle);
561 dissector_add("udp.port", UDP_PORT_LLC1, llc_handle);
562 dissector_add("udp.port", UDP_PORT_LLC2, llc_handle);
563 dissector_add("udp.port", UDP_PORT_LLC3, llc_handle);
564 dissector_add("udp.port", UDP_PORT_LLC4, llc_handle);
565 dissector_add("udp.port", UDP_PORT_LLC5, llc_handle);