* Routines for IEEE 802.2 LLC layer
* Gilbert Ramirez <gramirez@tivoli.com>
*
- * $Id: packet-llc.c,v 1.19 1999/08/10 20:05:40 guy Exp $
+ * $Id: packet-llc.c,v 1.39 2000/01/12 20:00:19 guy Exp $
*
* Ethereal - Network traffic analyzer
- * By Gerald Combs <gerald@unicom.net>
+ * By Gerald Combs <gerald@zing.org>
* Copyright 1998 Gerald Combs
*
*
#include <glib.h>
#include "packet.h"
+#include "oui.h"
#include "xdlc.h"
static int proto_llc = -1;
static int hf_llc_dsap = -1;
static int hf_llc_ssap = -1;
+static int hf_llc_dsap_ig = -1;
+static int hf_llc_ssap_cr = -1;
static int hf_llc_ctrl = -1;
static int hf_llc_type = -1;
static int hf_llc_oui = -1;
+static int hf_llc_pid = -1;
+
+static gint ett_llc = -1;
+static gint ett_llc_ctrl = -1;
typedef void (capture_func_t)(const u_char *, int, guint32, packet_counts *);
typedef void (dissect_func_t)(const u_char *, int, frame_data *, proto_tree *);
dissect_func_t *dissect_func;
};
+/*
+ * Group/Individual bit, in the DSAP.
+ */
+#define DSAP_GI_BIT 0x01
+
+/*
+ * Command/Response bit, in the SSAP.
+ *
+ * The low-order bit of the SSAP apparently determines whether this
+ * is a request or a response. (RFC 1390, "Transmission of IP and
+ * ARP over FDDI Networks", says
+ *
+ * Command frames are identified by having the low order
+ * bit of the SSAP address reset to zero. Response frames
+ * have the low order bit of the SSAP address set to one.
+ *
+ * and a page I've seen seems to imply that's part of 802.2.)
+ */
+#define SSAP_CR_BIT 0x01
+
+/*
+ * Mask to extrace the SAP number from the DSAP or the SSAP.
+ */
+#define SAP_MASK 0xFE
+
+/*
+ * These are for SSAP and DSAP, wth last bit always zero.
+ * XXX - some DSAPs come in separate "individual" and "group" versions,
+ * with the last bit 0 and 1, respectively (e.g., LLC Sub-layer Management,
+ * IBM SNA Path Control, IBM Net Management), and, whilst 0xFE is
+ * the ISO Network Layer Protocol, 0xFF is the Global LSAP.
+ */
static const value_string sap_vals[] = {
{ 0x00, "NULL LSAP" },
- { 0x02, "LLC Sub-Layer Management Individual" },
- { 0x03, "LLC Sub-Layer Management Group" },
- { 0x04, "SNA Path Control Individual" },
- { 0x05, "SNA Path Control Group" },
+ { 0x02, "LLC Sub-Layer Management" },
+ { 0x04, "SNA Path Control" },
{ 0x06, "TCP/IP" },
{ 0x08, "SNA" },
{ 0x0C, "SNA" },
{ 0xBC, "Banyan Vines" },
{ 0xE0, "NetWare" },
{ 0xF0, "NetBIOS" },
- { 0xF4, "IBM Net Management Individual" },
- { 0xF5, "IBM Net Management Group" },
+ { 0xF4, "IBM Net Management" },
{ 0xF8, "Remote Program Load" },
{ 0xFC, "Remote Program Load" },
{ 0xFE, "ISO Network Layer" },
{ 0x00, NULL, NULL },
{ 0x02, NULL, NULL },
{ 0x03, NULL, NULL },
- { 0x04, NULL, NULL },
+ { 0x04, NULL, dissect_sna },
{ 0x05, NULL, NULL },
{ 0x06, capture_ip, dissect_ip },
{ 0x08, NULL, NULL },
{ 0x0C, NULL, NULL },
- { 0x42, NULL, NULL },
+ { 0x42, NULL, dissect_bpdu },
{ 0x7F, NULL, NULL },
{ 0x80, NULL, NULL },
{ 0xAA, NULL, NULL },
{ 0xBA, NULL, NULL },
{ 0xBC, NULL, NULL },
- { 0xE0, NULL, dissect_ipx },
+ { 0xE0, capture_ipx, dissect_ipx },
{ 0xF0, capture_netbios, dissect_netbios },
{ 0xF4, NULL, NULL },
{ 0xF5, NULL, NULL },
{ 0, NULL }
};
-static const value_string llc_oui_vals[] = {
- { 0x000000, "Encapsulated Ethernet" },
+const value_string oui_vals[] = {
+ { OUI_ENCAP_ETHER, "Encapsulated Ethernet" },
/*
http://www.cisco.com/univercd/cc/td/doc/product/software/ios113ed/113ed_cr/ibm_r/brprt1/brsrb.htm
*/
- { 0x0000f8, "Cisco 90-Compatible" },
- { 0x0000c0, "Cisco" },
- { 0x0080c2, "Bridged Frame-Relay" }, /* RFC 2427 */
- { 0, NULL }
+ { OUI_CISCO, "Cisco" },
+ { 0x0000f8, "Cisco 90-Compatible" },
+ { 0x0080c2, "Bridged Frame-Relay" }, /* RFC 2427 */
+ { OUI_ATM_FORUM, "ATM Forum" },
+ { OUI_APPLE_ATALK, "Apple (AppleTalk)" },
+ { 0, NULL }
};
static capture_func_t *
return dissect_data;
}
-
void
capture_llc(const u_char *pd, int offset, guint32 cap_len, packet_counts *ld) {
- guint16 etype;
int is_snap;
+ guint16 control;
+ int llc_header_len;
+ guint32 oui;
+ guint16 etype;
capture_func_t *capture;
+ if (!BYTES_ARE_IN_FRAME(offset, 2)) {
+ ld->other++;
+ return;
+ }
is_snap = (pd[offset] == 0xAA) && (pd[offset+1] == 0xAA);
- if (is_snap) {
- etype = (pd[offset+6] << 8) | pd[offset+7];
- offset += 8;
- capture_ethertype(etype, offset, pd, cap_len, ld);
- }
- else {
- capture = sap_capture_func(pd[offset]);
+ llc_header_len = 2; /* DSAP + SSAP */
- /* non-SNAP */
- offset += 3;
+ /*
+ * XXX - the page referred to in the comment above about the
+ * Command/Response bit also implies that LLC Type 2 always
+ * uses extended operation, so we don't need to determine
+ * whether it's basic or extended operation; is that the case?
+ */
+ control = get_xdlc_control(pd, offset+2, pd[offset+1] & SSAP_CR_BIT,
+ TRUE);
+ llc_header_len += XDLC_CONTROL_LEN(control, TRUE);
+ if (is_snap)
+ llc_header_len += 5; /* 3 bytes of OUI, 2 bytes of protocol ID */
+ if (!BYTES_ARE_IN_FRAME(offset, llc_header_len)) {
+ ld->other++;
+ return;
+ }
- if (capture) {
- capture(pd, offset, cap_len, ld);
+ if (is_snap) {
+ oui = pd[offset+3] << 16 | pd[offset+4] << 8 | pd[offset+5];
+ if (XDLC_HAS_PAYLOAD(control)) {
+ /*
+ * This frame has a payload to be analyzed.
+ */
+ etype = pntohs(&pd[offset+6]);
+ switch (oui) {
+
+ case OUI_ENCAP_ETHER:
+ case OUI_APPLE_ATALK:
+ /* No, I have no idea why Apple used
+ one of their own OUIs, rather than
+ OUI_ENCAP_ETHER, and an Ethernet
+ packet type as protocol ID, for
+ AppleTalk data packets - but used
+ OUI_ENCAP_ETHER and an Ethernet
+ packet type for AARP packets. */
+ capture_ethertype(etype, offset+8, pd,
+ cap_len, ld);
+ break;
+
+ default:
+ ld->other++;
+ break;
+ }
}
- else {
- ld->other++;
+ }
+ else {
+ if (XDLC_HAS_PAYLOAD(control)) {
+ /*
+ * This frame has a payload to be analyzed.
+ */
+ capture = sap_capture_func(pd[offset]);
+
+ /* non-SNAP */
+ offset += llc_header_len;
+
+ if (capture) {
+ capture(pd, offset, cap_len, ld);
+ }
+ else {
+ ld->other++;
+ }
}
-
}
}
dissect_llc(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
proto_tree *llc_tree = NULL;
- proto_item *ti;
- guint16 etype;
+ proto_item *ti = NULL;
int is_snap;
+ guint16 control;
+ int llc_header_len;
+ guint32 oui;
+ guint16 etype;
dissect_func_t *dissect;
+ if (!BYTES_ARE_IN_FRAME(offset, 2)) {
+ dissect_data(pd, offset, fd, tree);
+ return;
+ }
is_snap = (pd[offset] == 0xAA) && (pd[offset+1] == 0xAA);
+ llc_header_len = 2; /* DSAP + SSAP */
if (check_col(fd, COL_PROTOCOL)) {
col_add_str(fd, COL_PROTOCOL, "LLC");
}
-
+
if (tree) {
- ti = proto_tree_add_item(tree, proto_llc, offset, (is_snap ? 8 : 3), NULL);
- llc_tree = proto_item_add_subtree(ti, ETT_LLC);
- proto_tree_add_item(llc_tree, hf_llc_dsap, offset, 1, pd[offset]);
- proto_tree_add_item(llc_tree, hf_llc_ssap, offset+1, 1, pd[offset+1]);
+ ti = proto_tree_add_item(tree, proto_llc, offset, 0, NULL);
+ llc_tree = proto_item_add_subtree(ti, ett_llc);
+ proto_tree_add_item(llc_tree, hf_llc_dsap, offset,
+ 1, pd[offset] & SAP_MASK);
+ proto_tree_add_item(llc_tree, hf_llc_dsap_ig, offset,
+ 1, pd[offset] & DSAP_GI_BIT);
+ proto_tree_add_item(llc_tree, hf_llc_ssap, offset+1,
+ 1, pd[offset+1] & SAP_MASK);
+ proto_tree_add_item(llc_tree, hf_llc_ssap_cr, offset+1,
+ 1, pd[offset+1] & SSAP_CR_BIT);
} else
llc_tree = NULL;
/*
- * The low-order bit of the SSAP apparently determines whether this
- * is a request or a response. (RFC 1390, "Transmission of IP and
- * ARP over FDDI Networks", says
- *
- * Command frames are identified by having the low order
- * bit of the SSAP address reset to zero. Response frames
- * have the low order bit of the SSAP address set to one.
- *
- * and a page I've seen seems to imply that's part of 802.2.)
- *
- * XXX - that page also implies that LLC Type 2 always uses
- * extended operation, so we don't need to determine whether
- * it's basic or extended operation; is that the case?
+ * XXX - the page referred to in the comment above about the
+ * Command/Response bit also implies that LLC Type 2 always
+ * uses extended operation, so we don't need to determine
+ * whether it's basic or extended operation; is that the case?
*/
- dissect_xdlc_control(pd, offset+2, fd, llc_tree, hf_llc_ctrl,
- pd[offset+1] & 0x01, TRUE);
+ control = dissect_xdlc_control(pd, offset+2, fd, llc_tree,
+ hf_llc_ctrl, ett_llc_ctrl,
+ pd[offset+1] & SSAP_CR_BIT, TRUE);
+ llc_header_len += XDLC_CONTROL_LEN(control, TRUE);
+ if (is_snap)
+ llc_header_len += 5; /* 3 bytes of OUI, 2 bytes of protocol ID */
+ if (!BYTES_ARE_IN_FRAME(offset, llc_header_len)) {
+ dissect_data(pd, offset, fd, tree);
+ return;
+ }
+ if (tree)
+ proto_item_set_len(ti, llc_header_len);
/*
* XXX - do we want to append the SAP information to the stuff
* "dissect_xdlc_control()" put in the COL_INFO column, rather
* than overwriting it?
- *
- * XXX - we shouldn't, as far as I know, pass S frames to
- * "ethertype" or "dissect", and we may have to treat I frames
- * differently from U frames.
*/
if (is_snap) {
+ oui = pd[offset+3] << 16 | pd[offset+4] << 8 | pd[offset+5];
+ etype = pntohs(&pd[offset+6]);
if (check_col(fd, COL_INFO)) {
- col_add_str(fd, COL_INFO, "802.2 LLC (SNAP)");
+ col_add_fstr(fd, COL_INFO, "SNAP, OUI 0x%06X (%s), PID 0x%04X",
+ oui, val_to_str(oui, oui_vals, "Unknown"),
+ etype);
}
if (tree) {
proto_tree_add_item(llc_tree, hf_llc_oui, offset+3, 3,
- pd[offset+3] << 16 | pd[offset+4] << 8 | pd[offset+5]);
+ oui);
+ }
+ if (XDLC_HAS_PAYLOAD(control)) {
+ /*
+ * This frame has a payload to be analyzed.
+ */
+ switch (oui) {
+
+ case OUI_ENCAP_ETHER:
+ case OUI_APPLE_ATALK:
+ /* No, I have no idea why Apple used
+ one of their own OUIs, rather than
+ OUI_ENCAP_ETHER, and an Ethernet
+ packet type as protocol ID, for
+ AppleTalk data packets - but used
+ OUI_ENCAP_ETHER and an Ethernet
+ packet type for AARP packets. */
+ ethertype(etype, offset+8, pd,
+ fd, tree, llc_tree, hf_llc_type);
+ break;
+
+
+ case OUI_CISCO:
+ /* So are all CDP packets LLC packets
+ with an OUI of OUI_CISCO and a
+ protocol ID of 0x2000, or
+ are some of them raw or encapsulated
+ Ethernet? */
+ if (tree) {
+ proto_tree_add_item(llc_tree,
+ hf_llc_pid, offset+6, 2, etype);
+ }
+ switch (etype) {
+
+ case 0x2000:
+ dissect_cdp(pd, offset+8, fd, tree);
+ break;
+ }
+ break;
+
+ default:
+ if (tree) {
+ proto_tree_add_item(llc_tree,
+ hf_llc_pid, offset+6, 2, etype);
+ }
+ dissect_data(pd, offset+8, fd, tree);
+ break;
+ }
}
- etype = pntohs(&pd[offset+6]);
- offset += 8;
- /* w/o even checking, assume OUI is ethertype */
- ethertype(etype, offset, pd, fd, tree, llc_tree, hf_llc_type);
}
else {
if (check_col(fd, COL_INFO)) {
- col_add_fstr(fd, COL_INFO, "802.2 LLC (%s)",
- val_to_str(pd[offset], sap_vals, "%02x"));
+ col_add_fstr(fd, COL_INFO,
+ "DSAP %s %s, SSAP %s %s",
+ val_to_str(pd[offset] & SAP_MASK, sap_vals, "%02x"),
+ pd[offset] & DSAP_GI_BIT ?
+ "Group" : "Individual",
+ val_to_str(pd[offset+1] & SAP_MASK, sap_vals, "%02x"),
+ pd[offset+1] & SSAP_CR_BIT ?
+ "Command" : "Response"
+ );
}
- dissect = sap_dissect_func(pd[offset]);
-
- /* non-SNAP */
- offset += 3;
-
- if (dissect) {
- dissect(pd, offset, fd, tree);
- }
- else {
- dissect_data(pd, offset, fd, tree);
+ if (XDLC_HAS_PAYLOAD(control)) {
+ /*
+ * This frame has a payload to be analyzed.
+ */
+ dissect = sap_dissect_func(pd[offset]);
+
+ /* non-SNAP */
+ offset += llc_header_len;
+
+ if (dissect) {
+ dissect(pd, offset, fd, tree);
+ }
+ else {
+ dissect_data(pd, offset, fd, tree);
+ }
}
-
}
}
void
proto_register_llc(void)
{
+ static struct true_false_string ig_bit = { "Group", "Individual" };
+ static struct true_false_string cr_bit = { "Response", "Command" };
+
static hf_register_info hf[] = {
{ &hf_llc_dsap,
- { "DSAP", "llc.dsap", FT_VALS_UINT8, VALS(sap_vals) }},
+ { "DSAP", "llc.dsap", FT_UINT8, BASE_HEX,
+ VALS(sap_vals), 0x0, "" }},
+
+ { &hf_llc_dsap_ig,
+ { "IG Bit", "llc.dsap.ig", FT_BOOLEAN, BASE_HEX,
+ &ig_bit, 0x0, "Individual/Group" }},
{ &hf_llc_ssap,
- { "SSAP", "llc.ssap", FT_VALS_UINT8, VALS(sap_vals) }},
+ { "SSAP", "llc.ssap", FT_UINT8, BASE_HEX,
+ VALS(sap_vals), 0x0, "" }},
+
+ { &hf_llc_ssap_cr,
+ { "CR Bit", "llc.ssap.cr", FT_BOOLEAN, BASE_HEX,
+ &cr_bit, 0x0, "Command/Response" }},
{ &hf_llc_ctrl,
- { "Control", "llc.control", FT_VALS_UINT8, VALS(llc_ctrl_vals) }},
+ { "Control", "llc.control", FT_UINT8, BASE_HEX,
+ VALS(llc_ctrl_vals), 0x0, "" }},
/* registered here but handled in ethertype.c */
{ &hf_llc_type,
- { "Type", "llc.type", FT_VALS_UINT16, VALS(etype_vals) }},
+ { "Type", "llc.type", FT_UINT16, BASE_HEX,
+ VALS(etype_vals), 0x0, "" }},
{ &hf_llc_oui,
- { "Organization Code", "llc.oui", FT_VALS_UINT24, VALS(llc_oui_vals) }}
+ { "Organization Code", "llc.oui", FT_UINT24, BASE_HEX,
+ VALS(oui_vals), 0x0, ""}},
+
+ { &hf_llc_pid,
+ { "Protocol ID", "llc.pid", FT_UINT16, BASE_HEX,
+ NULL, 0x0, ""}}
+ };
+ static gint *ett[] = {
+ &ett_llc,
+ &ett_llc_ctrl,
};
proto_llc = proto_register_protocol ("Logical-Link Control", "llc" );
proto_register_field_array(proto_llc, hf, array_length(hf));
+ proto_register_subtree_array(ett, array_length(ett));
}