2 * Routines for IEEE 802.2 LLC layer
3 * Gilbert Ramirez <gram@alumni.rice.edu>
5 * $Id: packet-llc.c,v 1.105 2002/12/10 02:49:31 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.
31 #include <epan/packet.h>
36 #include "bridged_pids.h"
38 #include "packet-fc.h"
39 #include "packet-ip.h"
40 #include "packet-ipx.h"
41 #include "packet-netbios.h"
42 #include <epan/sna-utils.h>
44 #include "packet-llc.h"
46 #define UDP_PORT_LLC1 12000
47 #define UDP_PORT_LLC2 12001
48 #define UDP_PORT_LLC3 12002
49 #define UDP_PORT_LLC4 12003
50 #define UDP_PORT_LLC5 12004
52 static int proto_llc = -1;
53 static int hf_llc_dsap = -1;
54 static int hf_llc_ssap = -1;
55 static int hf_llc_dsap_ig = -1;
56 static int hf_llc_ssap_cr = -1;
57 static int hf_llc_ctrl = -1;
58 static int hf_llc_type = -1;
59 static int hf_llc_oui = -1;
60 static int hf_llc_pid = -1;
62 static gint ett_llc = -1;
63 static gint ett_llc_ctrl = -1;
65 static dissector_table_t subdissector_table;
66 static dissector_table_t cisco_subdissector_table;
68 static dissector_handle_t bpdu_handle;
69 static dissector_handle_t eth_handle;
70 static dissector_handle_t fddi_handle;
71 static dissector_handle_t tr_handle;
72 static dissector_handle_t data_handle;
75 * Group/Individual bit, in the DSAP.
77 #define DSAP_GI_BIT 0x01
80 * Command/Response bit, in the SSAP.
82 * The low-order bit of the SSAP apparently determines whether this
83 * is a request or a response. (RFC 1390, "Transmission of IP and
84 * ARP over FDDI Networks", says
86 * Command frames are identified by having the low order
87 * bit of the SSAP address reset to zero. Response frames
88 * have the low order bit of the SSAP address set to one.
90 * and a page I've seen seems to imply that's part of 802.2.)
92 #define SSAP_CR_BIT 0x01
95 * Mask to extrace the SAP number from the DSAP or the SSAP.
100 * These are for SSAP and DSAP, wth last bit always zero.
101 * XXX - some DSAPs come in separate "individual" and "group" versions,
102 * with the last bit 0 and 1, respectively (e.g., LLC Sub-layer Management,
103 * IBM SNA Path Control, IBM Net Management), but, whilst 0xFE is
104 * the ISO Network Layer Protocol, 0xFF is the Global LSAP.
106 const value_string sap_vals[] = {
107 { SAP_NULL, "NULL LSAP" },
108 { SAP_LLC_SLMGMT, "LLC Sub-Layer Management" },
109 { SAP_SNA_PATHCTRL, "SNA Path Control" },
110 { SAP_IP, "TCP/IP" },
113 { SAP_PROWAY_NM_INIT, "PROWAY (IEC955) Network Management and Initialization" },
114 { SAP_TI, "Texas Instruments" },
115 { SAP_BPDU, "Spanning Tree BPDU" },
116 { SAP_RS511, "EIA RS-511 Manufacturing Message Service" },
117 { SAP_X25, "ISO 8208 (X.25 over 802.2)" },
119 * XXX - setting the group bit of SAP_X25 make 0x7F; is this just
120 * a group version of that?
122 { 0x7F, "ISO 802.2" },
124 { SAP_BACNET, "BACnet" },
125 { SAP_NESTAR, "Nestar" },
126 { SAP_PROWAY_ASLM, "PROWAY (IEC955) Active Station List Maintenance" },
127 { SAP_ARP, "ARP" }, /* XXX - hand to "dissect_arp()"? */
128 { SAP_SNAP, "SNAP" },
129 { SAP_VINES1, "Banyan Vines" },
130 { SAP_VINES2, "Banyan Vines" },
131 { SAP_NETWARE, "NetWare" },
132 { SAP_NETBIOS, "NetBIOS" },
133 { SAP_IBMNM, "IBM Net Management" },
134 { SAP_RPL1, "Remote Program Load" },
135 { SAP_UB, "Ungermann-Bass" },
136 { SAP_RPL2, "Remote Program Load" },
137 { SAP_OSINL, "ISO Network Layer" },
138 { SAP_GLOBAL, "Global LSAP" },
145 * http://www.cisco.com/univercd/cc/td/doc/product/lan/trsrb/vlan.htm
147 * for the PIDs for VTP and DRiP that go with an OUI of OUI_CISCO.
149 const value_string oui_vals[] = {
150 { OUI_ENCAP_ETHER, "Encapsulated Ethernet" },
152 http://www.cisco.com/univercd/cc/td/doc/product/software/ios113ed/113ed_cr/ibm_r/brprt1/brsrb.htm
154 { OUI_CISCO, "Cisco" },
155 { OUI_CISCO_90, "Cisco IOS 9.0 Compatible" },
156 { OUI_BRIDGED, "Frame Relay or ATM bridged frames" },
157 /* RFC 2427, RFC 2684 */
158 { OUI_ATM_FORUM, "ATM Forum" },
159 { OUI_CABLE_BPDU, "DOCSIS Spanning Tree" }, /* DOCSIS spanning tree BPDU */
160 { OUI_APPLE_ATALK, "Apple (AppleTalk)" },
165 capture_llc(const guchar *pd, int offset, int len, packet_counts *ld) {
173 if (!BYTES_ARE_IN_FRAME(offset, len, 2)) {
177 is_snap = (pd[offset] == SAP_SNAP) && (pd[offset+1] == SAP_SNAP);
178 llc_header_len = 2; /* DSAP + SSAP */
181 * XXX - the page referred to in the comment above about the
182 * Command/Response bit also implies that LLC Type 2 always
183 * uses extended operation, so we don't need to determine
184 * whether it's basic or extended operation; is that the case?
186 control = get_xdlc_control(pd, offset+2, pd[offset+1] & SSAP_CR_BIT);
187 llc_header_len += XDLC_CONTROL_LEN(control, TRUE);
189 llc_header_len += 5; /* 3 bytes of OUI, 2 bytes of protocol ID */
190 if (!BYTES_ARE_IN_FRAME(offset, len, llc_header_len)) {
196 oui = pd[offset+3] << 16 | pd[offset+4] << 8 | pd[offset+5];
197 if (XDLC_IS_INFORMATION(control)) {
198 etype = pntohs(&pd[offset+6]);
201 case OUI_ENCAP_ETHER:
203 case OUI_APPLE_ATALK:
204 /* No, I have no idea why Apple used
205 one of their own OUIs, rather than
206 OUI_ENCAP_ETHER, and an Ethernet
207 packet type as protocol ID, for
208 AppleTalk data packets - but used
209 OUI_ENCAP_ETHER and an Ethernet
210 packet type for AARP packets. */
211 capture_ethertype(etype, pd, offset+8, len,
215 capture_ethertype(etype, pd, offset + 8, len,
226 if (XDLC_IS_INFORMATION(control)) {
227 switch (pd[offset]) {
230 capture_ip(pd, offset + llc_header_len, len,
251 dissect_llc(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
253 proto_tree *llc_tree = NULL;
254 proto_item *ti = NULL;
261 if (check_col(pinfo->cinfo, COL_PROTOCOL)) {
262 col_set_str(pinfo->cinfo, COL_PROTOCOL, "LLC");
264 if (check_col(pinfo->cinfo, COL_INFO)) {
265 col_clear(pinfo->cinfo, COL_INFO);
268 dsap = tvb_get_guint8(tvb, 0);
270 ti = proto_tree_add_item(tree, proto_llc, tvb, 0, -1, FALSE);
271 llc_tree = proto_item_add_subtree(ti, ett_llc);
272 proto_tree_add_uint(llc_tree, hf_llc_dsap, tvb, 0,
274 proto_tree_add_boolean(llc_tree, hf_llc_dsap_ig, tvb, 0,
275 1, dsap & DSAP_GI_BIT);
279 ssap = tvb_get_guint8(tvb, 1);
281 proto_tree_add_uint(llc_tree, hf_llc_ssap, tvb, 1,
283 proto_tree_add_boolean(llc_tree, hf_llc_ssap_cr, tvb, 1,
284 1, ssap & SSAP_CR_BIT);
288 is_snap = (dsap == SAP_SNAP) && (ssap == SAP_SNAP);
289 llc_header_len = 2; /* DSAP + SSAP */
292 * XXX - the page referred to in the comment above about the
293 * Command/Response bit also implies that LLC Type 2 always
294 * uses extended operation, so we don't need to determine
295 * whether it's basic or extended operation; is that the case?
297 control = dissect_xdlc_control(tvb, 2, pinfo, llc_tree,
298 hf_llc_ctrl, ett_llc_ctrl,
299 ssap & SSAP_CR_BIT, TRUE);
300 llc_header_len += XDLC_CONTROL_LEN(control, TRUE);
302 llc_header_len += 5; /* 3 bytes of OUI, 2 bytes of protocol ID */
305 proto_item_set_len(ti, llc_header_len);
308 dissect_snap(tvb, 3, pinfo, tree, llc_tree, control,
309 hf_llc_oui, hf_llc_type, hf_llc_pid, 2);
312 if (check_col(pinfo->cinfo, COL_INFO)) {
313 col_append_fstr(pinfo->cinfo, COL_INFO,
314 "; DSAP %s %s, SSAP %s %s",
315 val_to_str(dsap & SAP_MASK, sap_vals, "%02x"),
317 "Group" : "Individual",
318 val_to_str(ssap & SAP_MASK, sap_vals, "%02x"),
320 "Response" : "Command"
324 next_tvb = tvb_new_subset(tvb, llc_header_len, -1, -1);
325 if (XDLC_IS_INFORMATION(control)) {
327 /* do lookup with the subdissector table */
328 if (!dissector_try_port(subdissector_table, dsap,
329 next_tvb, pinfo, tree)) {
330 call_dissector(data_handle,next_tvb, pinfo, tree);
333 call_dissector(data_handle,next_tvb, pinfo, tree);
339 * Dissect SNAP header; used elsewhere, e.g. in the Frame Relay dissector.
342 dissect_snap(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree,
343 proto_tree *snap_tree, int control, int hf_oui, int hf_type, int hf_pid,
350 oui = tvb_get_ntoh24(tvb, offset);
351 etype = tvb_get_ntohs(tvb, offset+3);
353 if (check_col(pinfo->cinfo, COL_INFO)) {
354 col_append_fstr(pinfo->cinfo, COL_INFO,
355 "; SNAP, OUI 0x%06X (%s), PID 0x%04X",
356 oui, val_to_str(oui, oui_vals, "Unknown"), etype);
359 proto_tree_add_uint(snap_tree, hf_oui, tvb, offset, 3, oui);
364 case OUI_ENCAP_ETHER:
366 case OUI_APPLE_ATALK:
367 /* No, I have no idea why Apple used
368 one of their own OUIs, rather than
369 OUI_ENCAP_ETHER, and an Ethernet
370 packet type as protocol ID, for
371 AppleTalk data packets - but used
372 OUI_ENCAP_ETHER and an Ethernet
373 packet type for AARP packets. */
374 if (XDLC_IS_INFORMATION(control)) {
375 ethertype(etype, tvb, offset+5,
376 pinfo, tree, snap_tree, hf_type, -1);
378 next_tvb = tvb_new_subset(tvb, offset+5, -1, -1);
379 call_dissector(data_handle,next_tvb, pinfo, tree);
385 * MAC frames bridged over ATM (RFC 2684) or Frame Relay
388 * We have to figure out how much padding to put
389 * into the frame. We were handed a "bridge_pad"
390 * argument which should be 0 for Frame Relay and
391 * 2 for ATM; we add to that the amount of padding
392 * common to both bridging types.
395 proto_tree_add_uint(snap_tree, hf_pid, tvb, offset+3, 2,
401 case BPID_ETH_WITH_FCS:
402 case BPID_ETH_WITHOUT_FCS:
403 next_tvb = tvb_new_subset(tvb, offset+5+bridge_pad,
405 call_dissector(eth_handle, next_tvb, pinfo, tree);
408 case BPID_802_5_WITH_FCS:
409 case BPID_802_5_WITHOUT_FCS:
411 * We treat the last padding byte as the Access
412 * Control byte, as that's what the Token
413 * Ring dissector expects the first byte to
416 next_tvb = tvb_new_subset(tvb, offset+5+bridge_pad,
418 call_dissector(tr_handle, next_tvb, pinfo, tree);
421 case BPID_FDDI_WITH_FCS:
422 case BPID_FDDI_WITHOUT_FCS:
423 next_tvb = tvb_new_subset(tvb, offset+5+1+bridge_pad,
425 call_dissector(fddi_handle, next_tvb, pinfo, tree);
429 next_tvb = tvb_new_subset(tvb, offset+5, -1, -1);
430 call_dissector(bpdu_handle, next_tvb, pinfo, tree);
434 next_tvb = tvb_new_subset(tvb, offset+5, -1, -1);
435 call_dissector(data_handle,next_tvb, pinfo, tree);
441 /* So are all CDP packets LLC packets
442 with an OUI of OUI_CISCO and a
443 protocol ID of 0x2000, or
444 are some of them raw or encapsulated
447 proto_tree_add_uint(snap_tree, hf_pid, tvb, offset+3, 2,
450 next_tvb = tvb_new_subset(tvb, offset+5, -1, -1);
451 if (XDLC_IS_INFORMATION(control)) {
452 /* do lookup with the subdissector table */
453 /* for future reference, 0x0102 is Cisco DRIP */
454 if (!dissector_try_port(cisco_subdissector_table,
455 etype, next_tvb, pinfo, tree))
456 call_dissector(data_handle,next_tvb, pinfo, tree);
458 call_dissector(data_handle,next_tvb, pinfo, tree);
461 case OUI_CABLE_BPDU: /* DOCSIS cable modem spanning tree BPDU */
463 proto_tree_add_uint(snap_tree, hf_pid, tvb, offset+3, 2,
466 next_tvb = tvb_new_subset(tvb, offset+5, -1, -1);
467 call_dissector(bpdu_handle, next_tvb, pinfo, tree);
472 proto_tree_add_uint(snap_tree, hf_pid, tvb, offset+3, 2,
475 next_tvb = tvb_new_subset(tvb, offset+5, -1, -1);
476 call_dissector(data_handle,next_tvb, pinfo, tree);
482 proto_register_llc(void)
484 static struct true_false_string ig_bit = { "Group", "Individual" };
485 static struct true_false_string cr_bit = { "Response", "Command" };
487 static hf_register_info hf[] = {
489 { "DSAP", "llc.dsap", FT_UINT8, BASE_HEX,
490 VALS(sap_vals), 0x0, "", HFILL }},
493 { "IG Bit", "llc.dsap.ig", FT_BOOLEAN, BASE_HEX,
494 &ig_bit, 0x0, "Individual/Group", HFILL }},
497 { "SSAP", "llc.ssap", FT_UINT8, BASE_HEX,
498 VALS(sap_vals), 0x0, "", HFILL }},
501 { "CR Bit", "llc.ssap.cr", FT_BOOLEAN, BASE_HEX,
502 &cr_bit, 0x0, "Command/Response", HFILL }},
505 { "Control", "llc.control", FT_UINT16, BASE_HEX,
506 NULL, 0x0, "", HFILL }},
508 /* registered here but handled in ethertype.c */
510 { "Type", "llc.type", FT_UINT16, BASE_HEX,
511 VALS(etype_vals), 0x0, "", HFILL }},
514 { "Organization Code", "llc.oui", FT_UINT24, BASE_HEX,
515 VALS(oui_vals), 0x0, "", HFILL }},
518 { "Protocol ID", "llc.pid", FT_UINT16, BASE_HEX,
519 NULL, 0x0, "", HFILL }}
521 static gint *ett[] = {
526 proto_llc = proto_register_protocol("Logical-Link Control", "LLC", "llc");
527 proto_register_field_array(proto_llc, hf, array_length(hf));
528 proto_register_subtree_array(ett, array_length(ett));
530 /* subdissector code */
531 subdissector_table = register_dissector_table("llc.dsap",
532 "LLC SAP", FT_UINT8, BASE_HEX);
533 cisco_subdissector_table = register_dissector_table("llc.cisco_pid",
534 "Cisco OUI PID", FT_UINT16, BASE_HEX);
536 register_dissector("llc", dissect_llc, proto_llc);
540 proto_reg_handoff_llc(void)
542 dissector_handle_t llc_handle;
545 * Get handles for the BPDU, Ethernet, FDDI, and Token Ring
548 bpdu_handle = find_dissector("bpdu");
549 eth_handle = find_dissector("eth");
550 fddi_handle = find_dissector("fddi");
551 tr_handle = find_dissector("tr");
552 data_handle = find_dissector("data");
554 llc_handle = find_dissector("llc");
555 dissector_add("wtap_encap", WTAP_ENCAP_ATM_RFC1483, llc_handle);
557 dissector_add("ppp.protocol", PPP_LLC, llc_handle);
559 dissector_add("udp.port", UDP_PORT_LLC1, llc_handle);
560 dissector_add("udp.port", UDP_PORT_LLC2, llc_handle);
561 dissector_add("udp.port", UDP_PORT_LLC3, llc_handle);
562 dissector_add("udp.port", UDP_PORT_LLC4, llc_handle);
563 dissector_add("udp.port", UDP_PORT_LLC5, llc_handle);
564 /* IP-over-FC when we have the full FC frame */
565 dissector_add("fc.ftype", FC_FTYPE_IP, llc_handle);