2 * Routines for IEEE 802.2 LLC layer
3 * Gilbert Ramirez <gram@alumni.rice.edu>
5 * $Id: packet-llc.c,v 1.100 2002/08/28 21:00:20 jmayer 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-ip.h"
39 #include "packet-ipx.h"
40 #include "packet-netbios.h"
41 #include <epan/sna-utils.h>
43 #include "packet-llc.h"
45 #define UDP_PORT_LLC1 12000
46 #define UDP_PORT_LLC2 12001
47 #define UDP_PORT_LLC3 12002
48 #define UDP_PORT_LLC4 12003
49 #define UDP_PORT_LLC5 12004
51 static int proto_llc = -1;
52 static int hf_llc_dsap = -1;
53 static int hf_llc_ssap = -1;
54 static int hf_llc_dsap_ig = -1;
55 static int hf_llc_ssap_cr = -1;
56 static int hf_llc_ctrl = -1;
57 static int hf_llc_type = -1;
58 static int hf_llc_oui = -1;
59 static int hf_llc_pid = -1;
61 static gint ett_llc = -1;
62 static gint ett_llc_ctrl = -1;
64 static dissector_table_t subdissector_table;
65 static dissector_table_t cisco_subdissector_table;
67 static dissector_handle_t bpdu_handle;
68 static dissector_handle_t eth_handle;
69 static dissector_handle_t fddi_handle;
70 static dissector_handle_t tr_handle;
71 static dissector_handle_t data_handle;
74 * Group/Individual bit, in the DSAP.
76 #define DSAP_GI_BIT 0x01
79 * Command/Response bit, in the SSAP.
81 * The low-order bit of the SSAP apparently determines whether this
82 * is a request or a response. (RFC 1390, "Transmission of IP and
83 * ARP over FDDI Networks", says
85 * Command frames are identified by having the low order
86 * bit of the SSAP address reset to zero. Response frames
87 * have the low order bit of the SSAP address set to one.
89 * and a page I've seen seems to imply that's part of 802.2.)
91 #define SSAP_CR_BIT 0x01
94 * Mask to extrace the SAP number from the DSAP or the SSAP.
99 * These are for SSAP and DSAP, wth last bit always zero.
100 * XXX - some DSAPs come in separate "individual" and "group" versions,
101 * with the last bit 0 and 1, respectively (e.g., LLC Sub-layer Management,
102 * IBM SNA Path Control, IBM Net Management), but, whilst 0xFE is
103 * the ISO Network Layer Protocol, 0xFF is the Global LSAP.
105 static const value_string sap_vals[] = {
106 { SAP_NULL, "NULL LSAP" },
107 { SAP_LLC_SLMGMT, "LLC Sub-Layer Management" },
108 { SAP_SNA_PATHCTRL, "SNA Path Control" },
109 { SAP_IP, "TCP/IP" },
112 { SAP_PROWAY_NM_INIT, "PROWAY (IEC955) Network Management and Initialization" },
113 { SAP_TI, "Texas Instruments" },
114 { SAP_BPDU, "Spanning Tree BPDU" },
115 { SAP_RS511, "EIA RS-511 Manufacturing Message Service" },
116 { SAP_X25, "ISO 8208 (X.25 over 802.2)" },
118 * XXX - setting the group bit of SAP_X25 make 0x7F; is this just
119 * a group version of that?
121 { 0x7F, "ISO 802.2" },
123 { SAP_NESTAR, "Nestar" },
124 { SAP_PROWAY_ASLM, "PROWAY (IEC955) Active Station List Maintenance" },
125 { SAP_ARP, "ARP" }, /* XXX - hand to "dissect_arp()"? */
126 { SAP_SNAP, "SNAP" },
127 { SAP_VINES1, "Banyan Vines" },
128 { SAP_VINES2, "Banyan Vines" },
129 { SAP_NETWARE, "NetWare" },
130 { SAP_NETBIOS, "NetBIOS" },
131 { SAP_IBMNM, "IBM Net Management" },
132 { SAP_RPL1, "Remote Program Load" },
133 { SAP_UB, "Ungermann-Bass" },
134 { SAP_RPL2, "Remote Program Load" },
135 { SAP_OSINL, "ISO Network Layer" },
136 { SAP_GLOBAL, "Global LSAP" },
143 * http://www.cisco.com/univercd/cc/td/doc/product/lan/trsrb/vlan.htm
145 * for the PIDs for VTP and DRiP that go with an OUI of OUI_CISCO.
147 const value_string oui_vals[] = {
148 { OUI_ENCAP_ETHER, "Encapsulated Ethernet" },
150 http://www.cisco.com/univercd/cc/td/doc/product/software/ios113ed/113ed_cr/ibm_r/brprt1/brsrb.htm
152 { OUI_CISCO, "Cisco" },
153 { OUI_CISCO_90, "Cisco IOS 9.0 Compatible" },
154 { OUI_BRIDGED, "Frame Relay or ATM bridged frames" },
155 /* RFC 2427, RFC 2684 */
156 { OUI_ATM_FORUM, "ATM Forum" },
157 { OUI_CABLE_BPDU, "DOCSIS Spanning Tree" }, /* DOCSIS spanning tree BPDU */
158 { OUI_APPLE_ATALK, "Apple (AppleTalk)" },
163 capture_llc(const guchar *pd, int offset, int len, packet_counts *ld) {
171 if (!BYTES_ARE_IN_FRAME(offset, len, 2)) {
175 is_snap = (pd[offset] == SAP_SNAP) && (pd[offset+1] == SAP_SNAP);
176 llc_header_len = 2; /* DSAP + SSAP */
179 * XXX - the page referred to in the comment above about the
180 * Command/Response bit also implies that LLC Type 2 always
181 * uses extended operation, so we don't need to determine
182 * whether it's basic or extended operation; is that the case?
184 control = get_xdlc_control(pd, offset+2, pd[offset+1] & SSAP_CR_BIT);
185 llc_header_len += XDLC_CONTROL_LEN(control, TRUE);
187 llc_header_len += 5; /* 3 bytes of OUI, 2 bytes of protocol ID */
188 if (!BYTES_ARE_IN_FRAME(offset, len, llc_header_len)) {
194 oui = pd[offset+3] << 16 | pd[offset+4] << 8 | pd[offset+5];
195 if (XDLC_IS_INFORMATION(control)) {
196 etype = pntohs(&pd[offset+6]);
199 case OUI_ENCAP_ETHER:
201 case OUI_APPLE_ATALK:
202 /* No, I have no idea why Apple used
203 one of their own OUIs, rather than
204 OUI_ENCAP_ETHER, and an Ethernet
205 packet type as protocol ID, for
206 AppleTalk data packets - but used
207 OUI_ENCAP_ETHER and an Ethernet
208 packet type for AARP packets. */
209 capture_ethertype(etype, pd, offset+8, len,
213 capture_ethertype(etype, pd, offset + 8, len,
224 if (XDLC_IS_INFORMATION(control)) {
225 switch (pd[offset]) {
228 capture_ip(pd, offset + llc_header_len, len,
249 dissect_llc(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
251 proto_tree *llc_tree = NULL;
252 proto_item *ti = NULL;
259 if (check_col(pinfo->cinfo, COL_PROTOCOL)) {
260 col_set_str(pinfo->cinfo, COL_PROTOCOL, "LLC");
262 if (check_col(pinfo->cinfo, COL_INFO)) {
263 col_clear(pinfo->cinfo, COL_INFO);
266 dsap = tvb_get_guint8(tvb, 0);
268 ti = proto_tree_add_item(tree, proto_llc, tvb, 0, -1, FALSE);
269 llc_tree = proto_item_add_subtree(ti, ett_llc);
270 proto_tree_add_uint(llc_tree, hf_llc_dsap, tvb, 0,
272 proto_tree_add_boolean(llc_tree, hf_llc_dsap_ig, tvb, 0,
273 1, dsap & DSAP_GI_BIT);
277 ssap = tvb_get_guint8(tvb, 1);
279 proto_tree_add_uint(llc_tree, hf_llc_ssap, tvb, 1,
281 proto_tree_add_boolean(llc_tree, hf_llc_ssap_cr, tvb, 1,
282 1, ssap & SSAP_CR_BIT);
286 is_snap = (dsap == SAP_SNAP) && (ssap == SAP_SNAP);
287 llc_header_len = 2; /* DSAP + SSAP */
290 * XXX - the page referred to in the comment above about the
291 * Command/Response bit also implies that LLC Type 2 always
292 * uses extended operation, so we don't need to determine
293 * whether it's basic or extended operation; is that the case?
295 control = dissect_xdlc_control(tvb, 2, pinfo, llc_tree,
296 hf_llc_ctrl, ett_llc_ctrl,
297 ssap & SSAP_CR_BIT, TRUE);
298 llc_header_len += XDLC_CONTROL_LEN(control, TRUE);
300 llc_header_len += 5; /* 3 bytes of OUI, 2 bytes of protocol ID */
303 proto_item_set_len(ti, llc_header_len);
306 dissect_snap(tvb, 3, pinfo, tree, llc_tree, control,
307 hf_llc_oui, hf_llc_type, hf_llc_pid, 2);
310 if (check_col(pinfo->cinfo, COL_INFO)) {
311 col_append_fstr(pinfo->cinfo, COL_INFO,
312 "; DSAP %s %s, SSAP %s %s",
313 val_to_str(dsap & SAP_MASK, sap_vals, "%02x"),
315 "Group" : "Individual",
316 val_to_str(ssap & SAP_MASK, sap_vals, "%02x"),
318 "Response" : "Command"
322 next_tvb = tvb_new_subset(tvb, llc_header_len, -1, -1);
323 if (XDLC_IS_INFORMATION(control)) {
325 /* do lookup with the subdissector table */
326 if (!dissector_try_port(subdissector_table, dsap,
327 next_tvb, pinfo, tree)) {
328 call_dissector(data_handle,next_tvb, pinfo, tree);
331 call_dissector(data_handle,next_tvb, pinfo, tree);
337 * Dissect SNAP header; used elsewhere, e.g. in the Frame Relay dissector.
340 dissect_snap(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree,
341 proto_tree *snap_tree, int control, int hf_oui, int hf_type, int hf_pid,
348 oui = tvb_get_ntoh24(tvb, offset);
349 etype = tvb_get_ntohs(tvb, offset+3);
351 if (check_col(pinfo->cinfo, COL_INFO)) {
352 col_append_fstr(pinfo->cinfo, COL_INFO,
353 "; SNAP, OUI 0x%06X (%s), PID 0x%04X",
354 oui, val_to_str(oui, oui_vals, "Unknown"), etype);
357 proto_tree_add_uint(snap_tree, hf_oui, tvb, offset, 3, oui);
362 case OUI_ENCAP_ETHER:
364 case OUI_APPLE_ATALK:
365 /* No, I have no idea why Apple used
366 one of their own OUIs, rather than
367 OUI_ENCAP_ETHER, and an Ethernet
368 packet type as protocol ID, for
369 AppleTalk data packets - but used
370 OUI_ENCAP_ETHER and an Ethernet
371 packet type for AARP packets. */
372 if (XDLC_IS_INFORMATION(control)) {
373 ethertype(etype, tvb, offset+5,
374 pinfo, tree, snap_tree, hf_type, -1);
376 next_tvb = tvb_new_subset(tvb, offset+5, -1, -1);
377 call_dissector(data_handle,next_tvb, pinfo, tree);
383 * MAC frames bridged over ATM (RFC 2684) or Frame Relay
386 * We have to figure out how much padding to put
387 * into the frame. We were handed a "bridge_pad"
388 * argument which should be 0 for Frame Relay and
389 * 2 for ATM; we add to that the amount of padding
390 * common to both bridging types.
393 proto_tree_add_uint(snap_tree, hf_pid, tvb, offset+3, 2,
399 case BPID_ETH_WITH_FCS:
400 case BPID_ETH_WITHOUT_FCS:
401 next_tvb = tvb_new_subset(tvb, offset+5+bridge_pad,
403 call_dissector(eth_handle, next_tvb, pinfo, tree);
406 case BPID_802_5_WITH_FCS:
407 case BPID_802_5_WITHOUT_FCS:
409 * We treat the last padding byte as the Access
410 * Control byte, as that's what the Token
411 * Ring dissector expects the first byte to
414 next_tvb = tvb_new_subset(tvb, offset+5+bridge_pad,
416 call_dissector(tr_handle, next_tvb, pinfo, tree);
419 case BPID_FDDI_WITH_FCS:
420 case BPID_FDDI_WITHOUT_FCS:
421 next_tvb = tvb_new_subset(tvb, offset+5+1+bridge_pad,
423 call_dissector(fddi_handle, next_tvb, pinfo, tree);
427 next_tvb = tvb_new_subset(tvb, offset+5, -1, -1);
428 call_dissector(bpdu_handle, next_tvb, pinfo, tree);
432 next_tvb = tvb_new_subset(tvb, offset+5, -1, -1);
433 call_dissector(data_handle,next_tvb, pinfo, tree);
439 /* So are all CDP packets LLC packets
440 with an OUI of OUI_CISCO and a
441 protocol ID of 0x2000, or
442 are some of them raw or encapsulated
445 proto_tree_add_uint(snap_tree, hf_pid, tvb, offset+3, 2,
448 next_tvb = tvb_new_subset(tvb, offset+5, -1, -1);
449 if (XDLC_IS_INFORMATION(control)) {
450 /* do lookup with the subdissector table */
451 /* for future reference, 0x0102 is Cisco DRIP */
452 if (!dissector_try_port(cisco_subdissector_table,
453 etype, next_tvb, pinfo, tree))
454 call_dissector(data_handle,next_tvb, pinfo, tree);
456 call_dissector(data_handle,next_tvb, pinfo, tree);
459 case OUI_CABLE_BPDU: /* DOCSIS cable modem spanning tree BPDU */
461 proto_tree_add_uint(snap_tree, hf_pid, tvb, offset+3, 2,
464 next_tvb = tvb_new_subset(tvb, offset+5, -1, -1);
465 call_dissector(bpdu_handle, next_tvb, pinfo, tree);
470 proto_tree_add_uint(snap_tree, hf_pid, tvb, offset+3, 2,
473 next_tvb = tvb_new_subset(tvb, offset+5, -1, -1);
474 call_dissector(data_handle,next_tvb, pinfo, tree);
480 proto_register_llc(void)
482 static struct true_false_string ig_bit = { "Group", "Individual" };
483 static struct true_false_string cr_bit = { "Response", "Command" };
485 static hf_register_info hf[] = {
487 { "DSAP", "llc.dsap", FT_UINT8, BASE_HEX,
488 VALS(sap_vals), 0x0, "", HFILL }},
491 { "IG Bit", "llc.dsap.ig", FT_BOOLEAN, BASE_HEX,
492 &ig_bit, 0x0, "Individual/Group", HFILL }},
495 { "SSAP", "llc.ssap", FT_UINT8, BASE_HEX,
496 VALS(sap_vals), 0x0, "", HFILL }},
499 { "CR Bit", "llc.ssap.cr", FT_BOOLEAN, BASE_HEX,
500 &cr_bit, 0x0, "Command/Response", HFILL }},
503 { "Control", "llc.control", FT_UINT16, BASE_HEX,
504 NULL, 0x0, "", HFILL }},
506 /* registered here but handled in ethertype.c */
508 { "Type", "llc.type", FT_UINT16, BASE_HEX,
509 VALS(etype_vals), 0x0, "", HFILL }},
512 { "Organization Code", "llc.oui", FT_UINT24, BASE_HEX,
513 VALS(oui_vals), 0x0, "", HFILL }},
516 { "Protocol ID", "llc.pid", FT_UINT16, BASE_HEX,
517 NULL, 0x0, "", HFILL }}
519 static gint *ett[] = {
524 proto_llc = proto_register_protocol("Logical-Link Control", "LLC", "llc");
525 proto_register_field_array(proto_llc, hf, array_length(hf));
526 proto_register_subtree_array(ett, array_length(ett));
528 /* subdissector code */
529 subdissector_table = register_dissector_table("llc.dsap",
530 "LLC SAP", FT_UINT8, BASE_HEX);
531 cisco_subdissector_table = register_dissector_table("llc.cisco_pid",
532 "Cisco OUI PID", FT_UINT16, BASE_HEX);
534 register_dissector("llc", dissect_llc, proto_llc);
538 proto_reg_handoff_llc(void)
540 dissector_handle_t llc_handle;
543 * Get handles for the BPDU, Ethernet, FDDI, and Token Ring
546 bpdu_handle = find_dissector("bpdu");
547 eth_handle = find_dissector("eth");
548 fddi_handle = find_dissector("fddi");
549 tr_handle = find_dissector("tr");
550 data_handle = find_dissector("data");
552 llc_handle = find_dissector("llc");
553 dissector_add("wtap_encap", WTAP_ENCAP_ATM_RFC1483, llc_handle);
555 dissector_add("ppp.protocol", PPP_LLC, llc_handle);
557 dissector_add("udp.port", UDP_PORT_LLC1, llc_handle);
558 dissector_add("udp.port", UDP_PORT_LLC2, llc_handle);
559 dissector_add("udp.port", UDP_PORT_LLC3, llc_handle);
560 dissector_add("udp.port", UDP_PORT_LLC4, llc_handle);
561 dissector_add("udp.port", UDP_PORT_LLC5, llc_handle);