Add tvbuff class.
[metze/wireshark/wip.git] / packet-llc.c
index ccf7b1930611148a7c7418d7f35865509ee62e03..463a5aa4e64f6884b508ca072720a9f8aaf96e16 100644 (file)
@@ -1,8 +1,8 @@
 /* packet-llc.c
  * Routines for IEEE 802.2 LLC layer
- * Gilbert Ramirez <gramirez@tivoli.com>
+ * Gilbert Ramirez <gram@xiexie.org>
  *
- * $Id: packet-llc.c,v 1.40 2000/01/22 21:49:50 gerald Exp $
+ * $Id: packet-llc.c,v 1.56 2000/05/11 08:15:22 gram Exp $
  *
  * Ethereal - Network traffic analyzer
  * By Gerald Combs <gerald@zing.org>
 #include "oui.h"
 #include "xdlc.h"
 #include "etypes.h"
-       
+#include "llcsaps.h"
+#include "packet-bpdu.h"
+#include "packet-cdp.h"
+#include "packet-cgmp.h"
+#include "packet-ip.h"
+#include "packet-ipx.h"
+#include "packet-netbios.h"
+#include "packet-osi.h"
+#include "packet-sna.h"
+#include "packet-vtp.h"
+
 static int proto_llc = -1;
 static int hf_llc_dsap = -1;
 static int hf_llc_ssap = -1;
@@ -51,16 +61,17 @@ 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 *);
+static dissector_table_t subdissector_table;
+
+typedef void (capture_func_t)(const u_char *, int, packet_counts *);
 
-/* The SAP info is split into two tables, one value_string table and one table of sap_info. This is
- * so that the value_string can be used in the header field registration.
+/* The SAP info is split into two tables, one value_string table and one
+ * table of sap_info. This is so that the value_string can be used in the
+ * header field registration.
  */
 struct sap_info {
        guint8  sap;
        capture_func_t *capture_func;
-       dissect_func_t *dissect_func;
 };
 
 /*
@@ -92,66 +103,58 @@ struct sap_info {
  * 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
+ * IBM SNA Path Control, IBM Net Management), but, 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" },
-       { 0x04, "SNA Path Control" },
-       { 0x06, "TCP/IP" },
-       { 0x08, "SNA" },
-       { 0x0C, "SNA" },
-       { 0x42, "Spanning Tree BPDU" },
-       { 0x7F, "ISO 802.2" },
-       { 0x80, "XNS" },
-       { 0xAA, "SNAP" },
-       { 0xBA, "Banyan Vines" },
-       { 0xBC, "Banyan Vines" },
-       { 0xE0, "NetWare" },
-       { 0xF0, "NetBIOS" },
-       { 0xF4, "IBM Net Management" },
-       { 0xF8, "Remote Program Load" },
-       { 0xFC, "Remote Program Load" },
-       { 0xFE, "ISO Network Layer" },
-       { 0xFF, "Global LSAP" },
-       { 0x00, NULL }
+       { SAP_NULL,           "NULL LSAP" },
+       { SAP_LLC_SLMGMT,     "LLC Sub-Layer Management" },
+       { SAP_SNA_PATHCTRL,   "SNA Path Control" },
+       { SAP_IP,             "TCP/IP" },
+       { SAP_SNA1,           "SNA" },
+       { SAP_SNA2,           "SNA" },
+       { SAP_PROWAY_NM_INIT, "PROWAY (IEC955) Network Management and Initialization" },
+       { SAP_TI,             "Texas Instruments" },
+       { SAP_BPDU,           "Spanning Tree BPDU" },
+       { SAP_RS511,          "EIA RS-511 Manufacturing Message Service" },
+#if 0
+       /* XXX - setting the group bit makes this 0x7F; is that just
+          a group version of this? */
+       { 0x7E,               "ISO 8208 (X.25 over 802.2 Type 2)" },
+#endif
+       { 0x7F,               "ISO 802.2" },
+       { SAP_XNS,            "XNS" },
+       { SAP_NESTAR,         "Nestar" },
+       { SAP_PROWAY_ASLM,    "PROWAY (IEC955) Active Station List Maintenance" },
+       { SAP_ARP,            "ARP" },  /* XXX - hand to "dissect_arp()"? */
+       { SAP_SNAP,           "SNAP" },
+       { SAP_VINES1,         "Banyan Vines" },
+       { SAP_VINES2,         "Banyan Vines" },
+       { SAP_NETWARE,        "NetWare" },
+       { SAP_NETBIOS,        "NetBIOS" },
+       { SAP_IBMNM,          "IBM Net Management" },
+       { SAP_RPL1,           "Remote Program Load" },
+       { SAP_UB,             "Ungermann-Bass" },
+       { SAP_RPL2,           "Remote Program Load" },
+       { SAP_OSINL,          "ISO Network Layer" },
+       { SAP_GLOBAL,         "Global LSAP" },
+       { 0x00,               NULL }
 };
 
 static struct sap_info saps[] = {
-       { 0x00, NULL,           NULL },
-       { 0x02, NULL,           NULL },
-       { 0x03, NULL,           NULL },
-       { 0x04, NULL,           dissect_sna },
-       { 0x05, NULL,           NULL },
-       { 0x06, capture_ip,     dissect_ip },
-       { 0x08, NULL,           NULL },
-       { 0x0C, NULL,           NULL },
-       { 0x42, NULL,           dissect_bpdu },
-       { 0x7F, NULL,           NULL },
-       { 0x80, NULL,           NULL },
-       { 0xAA, NULL,           NULL },
-       { 0xBA, NULL,           NULL },
-       { 0xBC, NULL,           NULL },
-       { 0xE0, capture_ipx,    dissect_ipx },
-       { 0xF0, capture_netbios, dissect_netbios },
-       { 0xF4, NULL,           NULL },
-       { 0xF5, NULL,           NULL },
-       { 0xF8, NULL,           NULL },
-       { 0xFC, NULL,           NULL },
-       { 0xFE, NULL,           dissect_osi },
-       { 0xFF, NULL,           NULL },
-       { 0x00, NULL,           NULL}
-};
-
-static const value_string llc_ctrl_vals[] = {
-       { 0, "Information Transfer" },
-       { 1, "Supervisory" },
-       { 2, "Unknown" },
-       { 3, "Unnumbered Information" },
-       { 0, NULL }
+       { SAP_IP,                       capture_ip },
+       { SAP_NETWARE,                  capture_ipx },
+       { SAP_NETBIOS,                  capture_netbios },
+       { 0x00,                         NULL}
 };
 
+/*
+ * See
+ *
+ * http://www.cisco.com/univercd/cc/td/doc/product/lan/trsrb/vlan.htm
+ *
+ * for the PIDs for VTP and DRiP that go with an OUI of OUI_CISCO.
+ */
 const value_string oui_vals[] = {
        { OUI_ENCAP_ETHER, "Encapsulated Ethernet" },
 /*
@@ -162,6 +165,7 @@ http://www.cisco.com/univercd/cc/td/doc/product/software/ios113ed/113ed_cr/ibm_r
        { OUI_BFR,         "Bridged Frame-Relay" }, /* RFC 2427 */
        { OUI_ATM_FORUM,   "ATM Forum" },
        { OUI_APPLE_ATALK, "Apple (AppleTalk)" },
+       { OUI_CABLE_BPDU,  "DOCSIS Spanning Tree" }, /* DOCSIS spanning tree BPDU */
        { 0,               NULL }
 };
 
@@ -181,24 +185,8 @@ sap_capture_func(u_char sap) {
        return NULL;
 }
 
-static dissect_func_t *
-sap_dissect_func(u_char sap) {
-       int i=0;
-
-       /* look for the second record where sap == 0, which should
-        * be the last record
-        */
-       while (saps[i].sap > 0 || i == 0) {
-               if (saps[i].sap == sap) {
-                       return saps[i].dissect_func;
-               }
-               i++;
-       }
-       return dissect_data;
-}
-
 void
-capture_llc(const u_char *pd, int offset, guint32 cap_len, packet_counts *ld) {
+capture_llc(const u_char *pd, int offset, packet_counts *ld) {
 
        int             is_snap;
        guint16         control;
@@ -211,7 +199,7 @@ capture_llc(const u_char *pd, int offset, guint32 cap_len, packet_counts *ld) {
                ld->other++;
                return;
        }
-       is_snap = (pd[offset] == 0xAA) && (pd[offset+1] == 0xAA);
+       is_snap = (pd[offset] == SAP_SNAP) && (pd[offset+1] == SAP_SNAP);
        llc_header_len = 2;     /* DSAP + SSAP */
 
        /*
@@ -232,10 +220,7 @@ capture_llc(const u_char *pd, int offset, guint32 cap_len, packet_counts *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.
-                        */
+               if (XDLC_IS_INFORMATION(control)) {
                        etype = pntohs(&pd[offset+6]);
                        switch (oui) {
 
@@ -249,11 +234,11 @@ capture_llc(const u_char *pd, int offset, guint32 cap_len, packet_counts *ld) {
                                   OUI_ENCAP_ETHER and an Ethernet
                                   packet type for AARP packets. */
                                capture_ethertype(etype, offset+8, pd,
-                                   cap_len, ld);
+                                   ld);
                                break;
                        case OUI_CISCO:
                                capture_ethertype(etype,
-                                               offset + 8, pd, cap_len, ld);
+                                               offset + 8, pd, ld);
                                break;
                        default:
                                ld->other++;
@@ -262,17 +247,14 @@ capture_llc(const u_char *pd, int offset, guint32 cap_len, packet_counts *ld) {
                }
        }               
        else {
-               if (XDLC_HAS_PAYLOAD(control)) {
-                       /*
-                        * This frame has a payload to be analyzed.
-                        */
+               if (XDLC_IS_INFORMATION(control)) {
                        capture = sap_capture_func(pd[offset]);
 
                        /* non-SNAP */
                        offset += llc_header_len;
 
                        if (capture) {
-                               capture(pd, offset, cap_len, ld);
+                               capture(pd, offset, ld);
                        }
                        else {
                                ld->other++;
@@ -291,13 +273,13 @@ dissect_llc(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
        int             llc_header_len;
        guint32         oui;
        guint16         etype;
-       dissect_func_t  *dissect;
+       guint8          dsap;
 
        if (!BYTES_ARE_IN_FRAME(offset, 2)) {
                dissect_data(pd, offset, fd, tree);
                return;
        }
-       is_snap = (pd[offset] == 0xAA) && (pd[offset+1] == 0xAA);
+       is_snap = (pd[offset] == SAP_SNAP) && (pd[offset+1] == SAP_SNAP);
        llc_header_len = 2;     /* DSAP + SSAP */
 
        if (check_col(fd, COL_PROTOCOL)) {
@@ -305,15 +287,15 @@ dissect_llc(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
        }
 
        if (tree) {
-               ti = proto_tree_add_item(tree, proto_llc, offset, 0, NULL);
+               ti = proto_tree_add_item(tree, proto_llc, NullTVB, offset, 0, NULL);
                llc_tree = proto_item_add_subtree(ti, ett_llc);
-               proto_tree_add_item(llc_tree, hf_llc_dsap, offset, 
+               proto_tree_add_item(llc_tree, hf_llc_dsap, NullTVB, offset, 
                        1, pd[offset] & SAP_MASK);
-               proto_tree_add_item(llc_tree, hf_llc_dsap_ig, offset, 
+               proto_tree_add_item(llc_tree, hf_llc_dsap_ig, NullTVB, offset, 
                        1, pd[offset] & DSAP_GI_BIT);
-               proto_tree_add_item(llc_tree, hf_llc_ssap, offset+1, 
+               proto_tree_add_item(llc_tree, hf_llc_ssap, NullTVB, offset+1, 
                        1, pd[offset+1] & SAP_MASK);
-               proto_tree_add_item(llc_tree, hf_llc_ssap_cr, offset+1, 
+               proto_tree_add_item(llc_tree, hf_llc_ssap_cr, NullTVB, offset+1, 
                        1, pd[offset+1] & SSAP_CR_BIT);
        } else
                llc_tree = NULL;
@@ -351,55 +333,81 @@ dissect_llc(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
                            etype);
                }
                if (tree) {
-                       proto_tree_add_item(llc_tree, hf_llc_oui, offset+3, 3,
+                       proto_tree_add_item(llc_tree, hf_llc_oui, NullTVB, offset+3, 3,
                                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. */
+               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. */
+                       if (XDLC_IS_INFORMATION(control)) {
                                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);
-                               }
+                       } else
+                               dissect_data(pd, offset+8, fd, tree);
+                       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, NullTVB, offset+6, 2, etype);
+                       }
+                       if (XDLC_IS_INFORMATION(control)) {
                                switch (etype) {
 
+#if 0
+                               case 0x0102:
+                                       dissect_drip(pd, offset+8, fd, tree);
+                                       break;
+#endif
+
                                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);
+                               case 0x2001:
+                                       dissect_cgmp(pd, offset+8, fd, tree);
+                                       break;
+
+                               case 0x2003:
+                                       dissect_vtp(pd, offset+8, fd, tree);
+                                       break;
+
+                               default:
+                                       dissect_data(pd, offset+8, fd, tree);
+                                       break;
                                }
+                       } else
                                dissect_data(pd, offset+8, fd, tree);
-                               break;
+                       break;
+
+               case OUI_CABLE_BPDU:    /* DOCSIS cable modem spanning tree BPDU */
+                       if (tree) {
+                               proto_tree_add_item(llc_tree,
+                               hf_llc_pid, NullTVB, offset+6, 2, etype);
                        }
+                       dissect_bpdu(pd, offset+8, fd, tree);
+                       break;
+
+               default:
+                       if (tree) {
+                               proto_tree_add_item(llc_tree,
+                                   hf_llc_pid, NullTVB, offset+6, 2, etype);
+                       }
+                       dissect_data(pd, offset+8, fd, tree);
+                       break;
                }
        }               
        else {
@@ -411,25 +419,23 @@ dissect_llc(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
                              "Group" : "Individual",
                            val_to_str(pd[offset+1] & SAP_MASK, sap_vals, "%02x"),
                            pd[offset+1] & SSAP_CR_BIT ?
-                             "Command" : "Response"
+                             "Response" : "Command"
                        );
                }
 
-               if (XDLC_HAS_PAYLOAD(control)) {
-                       /*
-                        * This frame has a payload to be analyzed.
-                        */
-                       dissect = sap_dissect_func(pd[offset]);
-
+               if (XDLC_IS_INFORMATION(control)) {
                        /* non-SNAP */
+                       dsap = pd[offset];
                        offset += llc_header_len;
 
-                       if (dissect) {
-                               dissect(pd, offset, fd, tree);
-                       }
-                       else {
+                       /* do lookup with the subdissector table */
+                       if (!dissector_try_port(subdissector_table, dsap,
+                           pd, offset, fd, tree)) {
                                dissect_data(pd, offset, fd, tree);
                        }
+               } else {
+                       offset += llc_header_len;
+                       dissect_data(pd, offset, fd, tree);
                }
        }
 }
@@ -458,8 +464,8 @@ proto_register_llc(void)
                        &cr_bit, 0x0, "Command/Response" }},
 
                { &hf_llc_ctrl,
-               { "Control", "llc.control", FT_UINT8, BASE_HEX, 
-                       VALS(llc_ctrl_vals), 0x0, "" }},
+               { "Control", "llc.control", FT_UINT16, BASE_HEX, 
+                       NULL, 0x0, "" }},
 
                /* registered here but handled in ethertype.c */
                { &hf_llc_type,
@@ -482,4 +488,7 @@ proto_register_llc(void)
        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));
+
+/* subdissector code */
+       subdissector_table = register_dissector_table("llc.dsap");
 }