For proto_tree_add_item(..., proto_xxx, ...)use ENC_NA as the encoding arg.
[obnox/wireshark/wip.git] / epan / dissectors / packet-llc.c
1 /* packet-llc.c
2  * Routines for IEEE 802.2 LLC layer
3  * Gilbert Ramirez <gram@alumni.rice.edu>
4  *
5  * $Id$
6  *
7  * Wireshark - Network traffic analyzer
8  * By Gerald Combs <gerald@wireshark.org>
9  * Copyright 1998 Gerald Combs
10  *
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.
15  *
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.
20  *
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.
24  */
25
26 #ifdef HAVE_CONFIG_H
27 # include "config.h"
28 #endif
29
30 #include <glib.h>
31 #include <epan/packet.h>
32 #include <epan/oui.h>
33 #include <epan/xdlc.h>
34 #include <epan/etypes.h>
35 #include <epan/llcsaps.h>
36 #include <epan/bridged_pids.h>
37 #include <epan/ppptypes.h>
38 #include <epan/arcnet_pids.h>
39 #include <epan/conversation.h>
40 #include "packet-scsi.h"
41 #include "packet-fc.h"
42 #include "packet-ip.h"
43 #include "packet-ipx.h"
44 #include "packet-netbios.h"
45 #include "packet-vines.h"
46 #include "packet-sll.h"
47 #include <epan/sna-utils.h>
48
49 #include "packet-llc.h"
50
51 #define UDP_PORT_LLC1   12000
52 #define UDP_PORT_LLC2   12001
53 #define UDP_PORT_LLC3   12002
54 #define UDP_PORT_LLC4   12003
55 #define UDP_PORT_LLC5   12004
56
57 static int proto_llc = -1;
58 static int hf_llc_dsap = -1;
59 static int hf_llc_ssap = -1;
60 static int hf_llc_dsap_ig = -1;
61 static int hf_llc_ssap_cr = -1;
62 static int hf_llc_ctrl = -1;
63 static int hf_llc_n_r = -1;
64 static int hf_llc_n_s = -1;
65 static int hf_llc_p = -1;
66 static int hf_llc_p_ext = -1;
67 static int hf_llc_f = -1;
68 static int hf_llc_f_ext = -1;
69 static int hf_llc_s_ftype = -1;
70 static int hf_llc_u_modifier_cmd = -1;
71 static int hf_llc_u_modifier_resp = -1;
72 static int hf_llc_ftype_i = -1;
73 static int hf_llc_ftype_s_u = -1;
74 static int hf_llc_ftype_s_u_ext = -1;
75 static int hf_llc_type = -1;
76 static int hf_llc_oui = -1;
77 static int hf_llc_pid = -1;
78
79 static int proto_basicxid = -1;
80 static int hf_llc_xid_format = -1;
81 static int hf_llc_xid_types = -1;
82 static int hf_llc_xid_wsize = -1;
83
84 static gint ett_llc = -1;
85 static gint ett_llc_ctrl = -1;
86 static gint ett_llc_basicxid = -1;
87
88 static dissector_table_t dsap_subdissector_table;
89 static dissector_table_t xid_subdissector_table;
90
91 static dissector_table_t ethertype_subdissector_table;
92 static dissector_table_t hpteam_subdissector_table;
93
94 static dissector_handle_t bpdu_handle;
95 static dissector_handle_t eth_withoutfcs_handle;
96 static dissector_handle_t eth_withfcs_handle;
97 static dissector_handle_t fddi_handle;
98 static dissector_handle_t tr_handle;
99 static dissector_handle_t turbo_handle;
100 static dissector_handle_t mesh_handle;
101 static dissector_handle_t data_handle;
102
103 /*
104  * Group/Individual bit, in the DSAP.
105  */
106 #define DSAP_GI_BIT     0x01
107
108 /*
109  * Command/Response bit, in the SSAP.
110  *
111  * The low-order bit of the SSAP apparently determines whether this
112  * is a request or a response.  (RFC 1390, "Transmission of IP and
113  * ARP over FDDI Networks", says
114  *
115  *      Command frames are identified by having the low order
116  *      bit of the SSAP address reset to zero.  Response frames
117  *      have the low order bit of the SSAP address set to one.
118  *
119  * and a page I've seen seems to imply that's part of 802.2.)
120  */
121 #define SSAP_CR_BIT     0x01
122
123 /*
124  * Mask to extrace the SAP number from the DSAP or the SSAP.
125  */
126 #define SAP_MASK        0xFE
127
128 /*
129  * These are for SSAP and DSAP, wth last bit always zero.
130  * XXX - some DSAPs come in separate "individual" and "group" versions,
131  * with the last bit 0 and 1, respectively (e.g., LLC Sub-layer Management,
132  * IBM SNA Path Control, IBM Net Management), but, whilst 0xFE is
133  * the ISO Network Layer Protocol, 0xFF is the Global LSAP.
134  */
135 const value_string sap_vals[] = {
136         { SAP_NULL,           "NULL LSAP" },
137         { SAP_LLC_SLMGMT,     "LLC Sub-Layer Management" },
138         { SAP_SNA_PATHCTRL,   "SNA Path Control" },
139         { SAP_IP,             "TCP/IP" },
140         { SAP_SNA1,           "SNA" },
141         { SAP_SNA2,           "SNA" },
142         { SAP_PROWAY_NM_INIT, "PROWAY (IEC955) Network Management and Initialization" },
143         { SAP_NETWARE1,       "NetWare (unofficial?)" },
144         { SAP_OSINL1,         "ISO Network Layer (OSLAN 1)" },
145         { SAP_TI,             "Texas Instruments" },
146         { SAP_OSINL2,         "ISO Network Layer (unofficial?)" },
147         { SAP_OSINL3,         "ISO Network Layer (unofficial?)" },
148         { SAP_BPDU,           "Spanning Tree BPDU" },
149         { SAP_RS511,          "EIA RS-511 Manufacturing Message Service" },
150         { SAP_OSINL4,         "ISO Network Layer (OSLAN 2)" },
151         { SAP_X25,            "ISO 8208 (X.25 over 802.2)" },
152         /*
153          * XXX - setting the group bit of SAP_X25 make 0x7F; is this just
154          * a group version of that?
155          */
156         { 0x7F,               "ISO 802.2" },
157         { SAP_XNS,            "XNS" },
158         { SAP_BACNET,         "BACnet" },
159         { SAP_NESTAR,         "Nestar" },
160         { SAP_PROWAY_ASLM,    "PROWAY (IEC955) Active Station List Maintenance" },
161         { SAP_ARP,            "ARP" },  /* XXX - hand to "dissect_arp()"? */
162         { SAP_HPJD,           "HP JetDirect Printer" },
163         { SAP_SNAP,           "SNAP" },
164         { SAP_VINES1,         "Banyan Vines" },
165         { SAP_VINES2,         "Banyan Vines" },
166         { SAP_NETWARE2,       "NetWare" },
167         { SAP_NETBIOS,        "NetBIOS" },
168         { SAP_IBMNM,          "IBM Net Management" },
169         { SAP_HPEXT,          "HP Extended LLC" },
170         { SAP_UB,             "Ungermann-Bass" },
171         { SAP_RPL,            "Remote Program Load" },
172         { SAP_OSINL5,         "ISO Network Layer" },
173         { SAP_GLOBAL,         "Global LSAP" },
174         { 0x00,               NULL }
175 };
176
177 /*
178  * See
179  *
180  * http://standards.ieee.org/regauth/oui/oui.txt
181  *
182  * http://www.cisco.com/univercd/cc/td/doc/product/lan/trsrb/vlan.htm
183  *
184  * for the PIDs for VTP and DRiP that go with an OUI of OUI_CISCO.
185  */
186 const value_string oui_vals[] = {
187         { OUI_ENCAP_ETHER,      "Encapsulated Ethernet" },
188         { OUI_XEROX,            "Xerox" },
189 /*
190 http://www.cisco.com/univercd/cc/td/doc/product/software/ios113ed/113ed_cr/ibm_r/brprt1/brsrb.htm
191 */
192         { OUI_CISCO,                    "Cisco" },
193         { OUI_NORTEL,                   "Nortel Discovery Protocol" },
194         { OUI_CISCO_90,                 "Cisco IOS 9.0 Compatible" },
195         { OUI_FORCE10,                  "Force10 Networks" },
196         { OUI_ERICSSON,                 "Ericsson Group" },
197         { OUI_CATENA,                   "Catena Networks" },
198         { OUI_SONY_ERICSSON,    "Sony Ericsson Mobile Communications AB" },
199         { OUI_SONY_ERICSSON_2,  "Sony Ericsson Mobile Communications AB" },
200         { OUI_PROFINET,                 "PROFIBUS Nutzerorganisation e.V." },
201         { OUI_SONY_ERICSSON_3,  "Sony Ericsson Mobile Communications AB" },
202         { OUI_CIMETRICS,                "Cimetrics" },
203         { OUI_IEEE_802_3,               "IEEE 802.3" },
204         { OUI_MEDIA_ENDPOINT,   "Media (TIA TR-41 Committee)" },
205         { OUI_SONY_ERICSSON_4,  "Sony Ericsson Mobile Communications AB" },
206         { OUI_ERICSSON_MOBILE,  "Ericsson Mobile Platforms" },
207         { OUI_SONY_ERICSSON_5,  "Sony Ericsson Mobile Communications AB" },
208         { OUI_SONY_ERICSSON_6,  "Sony Ericsson Mobile Communications AB" },
209         { OUI_SONY_ERICSSON_7,  "Sony Ericsson Mobile Communications AB" },
210         { OUI_SONY_ERICSSON_8,  "Sony Ericsson Mobile Communications AB" },
211         { OUI_TURBOCELL,                "Karlnet (Turbocell)" },
212         { OUI_CISCOWL,                  "Cisco Wireless (Aironet) L2" },
213         { OUI_MARVELL,                  "Marvell Semiconductor" },
214         { OUI_BRIDGED,                  "Frame Relay or ATM bridged frames" },
215         { OUI_IEEE_802_1,               "IEEE 802.1 Committee" },
216         { OUI_ATM_FORUM,                "ATM Forum" },
217         { OUI_EXTREME,                  "Extreme Networks" },
218         /* RFC 2427, RFC 2684 */
219         { OUI_CABLE_BPDU,               "DOCSIS Spanning Tree" }, /* DOCSIS spanning tree BPDU */
220         { OUI_SIEMENS,                  "Siemens AG" },
221         { OUI_APPLE_ATALK,              "Apple (AppleTalk)" },
222         { OUI_HP,                               "Hewlett-Packard" },
223         { OUI_HP_2,                             "Hewlett-Packard" },
224         /* Registry Name: PPP Vendor Specific OUI Options */
225         { OUI_3GPP2,                    "3GPP2 Vendor specific packet ID" },
226         { OUI_ERICSSON_2,               "Ericsson Group" },
227         { 0,    NULL }
228 };
229
230 static const value_string format_vals[] = {
231         { 0x81,        "LLC basic format" },
232         { 0,           NULL }
233 };
234
235 /*
236  * Mask to extract the type from XID frame.
237  */
238 #define TYPES_MASK      0x1F
239
240 static const value_string type_vals[] = {
241         { 1,           "Type 1 LLC (Class I LLC)" },
242         { 2,           "Type 2 LLC" },
243         { 3,           "Type 1 and Type 2 LLCs (Class II LLC)" },
244         { 4,           "Type 3 LLC" },
245         { 5,           "Type 1 and Type 3 LLCs (Class III LLC)" },
246         { 6,           "Type 2 and Type 3 LLCs" },
247         { 7,           "Type 1 and Type 2 and Type 3 LLCs (Class IV LLC)" },
248         { 0,           NULL }
249 };
250
251 /*
252  * Hash table for translating OUIs to an oui_info_t.
253  */
254 static GHashTable *oui_info_table = NULL;
255
256 /*
257  * Add an entry for a new OUI.
258  */
259 void
260 llc_add_oui(guint32 oui, const char *table_name, const char *table_ui_name,
261     hf_register_info *hf_item)
262 {
263         oui_info_t *new_info;
264
265         new_info = g_malloc(sizeof (oui_info_t));
266         new_info->table = register_dissector_table(table_name,
267             table_ui_name, FT_UINT16, BASE_HEX);
268         new_info->field_info = hf_item;
269
270         /*
271          * Create the hash table for OUI information, if it doesn't
272          * already exist.
273          */
274         if (oui_info_table == NULL) {
275                 oui_info_table = g_hash_table_new(g_direct_hash,
276                     g_direct_equal);
277         }
278         g_hash_table_insert(oui_info_table, GUINT_TO_POINTER(oui), new_info);
279 }
280
281 void
282 capture_llc(const guchar *pd, int offset, int len, packet_counts *ld) {
283
284         int             is_snap;
285         guint16         control;
286         int             llc_header_len;
287
288         if (!BYTES_ARE_IN_FRAME(offset, len, 2)) {
289                 ld->other++;
290                 return;
291         }
292         is_snap = (pd[offset] == SAP_SNAP) && (pd[offset+1] == SAP_SNAP);
293         llc_header_len = 2;     /* DSAP + SSAP */
294
295         /*
296          * XXX - the page referred to in the comment above about the
297          * Command/Response bit also implies that LLC Type 2 always
298          * uses extended operation, so we don't need to determine
299          * whether it's basic or extended operation; is that the case?
300          */
301         control = get_xdlc_control(pd, offset+2, pd[offset+1] & SSAP_CR_BIT);
302         llc_header_len += XDLC_CONTROL_LEN(control, TRUE);
303         if (!BYTES_ARE_IN_FRAME(offset, len, llc_header_len)) {
304                 ld->other++;
305                 return;
306         }
307
308         if (!XDLC_IS_INFORMATION(control)) {
309                 ld->other++;
310                 return;
311         }
312         if (is_snap)
313                 capture_snap(pd, offset+llc_header_len, len, ld);
314         else {
315                 /* non-SNAP */
316                 switch (pd[offset]) {
317
318                 case SAP_IP:
319                         capture_ip(pd, offset + llc_header_len, len, ld);
320                         break;
321
322                 case SAP_NETWARE1:
323                 case SAP_NETWARE2:
324                         capture_ipx(ld);
325                         break;
326
327                 case SAP_NETBIOS:
328                         capture_netbios(ld);
329                         break;
330
331                 case SAP_VINES1:
332                 case SAP_VINES2:
333                         capture_vines(ld);
334                         break;
335
336                 default:
337                         ld->other++;
338                         break;
339                 }
340         }
341 }
342
343 void
344 capture_snap(const guchar *pd, int offset, int len, packet_counts *ld)
345 {
346         guint32         oui;
347         guint16         etype;
348
349         if (!BYTES_ARE_IN_FRAME(offset, len, 5)) {
350                 ld->other++;
351                 return;
352         }
353
354         oui = pd[offset] << 16 | pd[offset+1] << 8 | pd[offset+2];
355         etype = pntohs(&pd[offset+3]);
356         switch (oui) {
357
358         case OUI_ENCAP_ETHER:
359         case OUI_CISCO_90:
360         case OUI_APPLE_ATALK:
361                 /* No, I have no idea why Apple used
362                    one of their own OUIs, rather than
363                    OUI_ENCAP_ETHER, and an Ethernet
364                    packet type as protocol ID, for
365                    AppleTalk data packets - but used
366                    OUI_ENCAP_ETHER and an Ethernet
367                    packet type for AARP packets. */
368                 capture_ethertype(etype, pd, offset+5, len, ld);
369                 break;
370
371         case OUI_CISCO:
372                 capture_ethertype(etype, pd, offset+5, len, ld);
373                 break;
374
375         case OUI_MARVELL:
376                 /*
377                  * OLPC packet.  The PID is an Ethertype, but
378                  * there's a mesh header between the PID and
379                  * the payload.  (We assume the header is
380                  * 5 bytes, for now).
381                  */
382                 capture_ethertype(etype, pd, offset+5+5, len, ld);
383                 break;
384
385         default:
386                 ld->other++;
387                 break;
388         }
389 }
390
391 /* Used only for U frames */
392 static const xdlc_cf_items llc_cf_items = {
393         NULL,
394         NULL,
395         &hf_llc_p,
396         &hf_llc_f,
397         NULL,
398         &hf_llc_u_modifier_cmd,
399         &hf_llc_u_modifier_resp,
400         NULL,
401         &hf_llc_ftype_s_u
402 };
403
404 /* Used only for I and S frames */
405 static const xdlc_cf_items llc_cf_items_ext = {
406         &hf_llc_n_r,
407         &hf_llc_n_s,
408         &hf_llc_p_ext,
409         &hf_llc_f_ext,
410         &hf_llc_s_ftype,
411         NULL,
412         NULL,
413         &hf_llc_ftype_i,
414         &hf_llc_ftype_s_u_ext
415 };
416
417 static void
418 dissect_basicxid(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
419 {
420         proto_tree      *xid_tree = NULL;
421         proto_item      *ti = NULL;
422         guint8          format, types, wsize;
423
424         col_set_str(pinfo->cinfo, COL_PROTOCOL, "XID");
425         col_clear(pinfo->cinfo, COL_INFO);
426
427         format = tvb_get_guint8(tvb, 0);
428         if (tree) {
429                 ti = proto_tree_add_item(tree, proto_basicxid, tvb, 0, -1, ENC_NA);
430                 xid_tree = proto_item_add_subtree(ti, ett_llc_basicxid);
431                 proto_tree_add_uint(xid_tree, hf_llc_xid_format, tvb, 0,
432                         1, format);
433         } else
434                 xid_tree = NULL;
435         col_append_str(pinfo->cinfo, COL_INFO,
436                     "Basic Format");
437
438         types = tvb_get_guint8(tvb, 1);
439         if (tree) {
440                 proto_tree_add_uint(xid_tree, hf_llc_xid_types, tvb, 1,
441                         1, types & TYPES_MASK);
442         }
443         if (check_col(pinfo->cinfo, COL_INFO)) {
444                 col_append_fstr(pinfo->cinfo, COL_INFO,
445                     "; %s", val_to_str(types & TYPES_MASK, type_vals, "0x%02x")
446                 );
447         }
448         wsize = tvb_get_guint8(tvb, 2);
449         if (tree) {
450                 proto_tree_add_uint(xid_tree, hf_llc_xid_wsize, tvb, 2,
451                         1, (wsize & 0xFE) >> 1);
452         }
453         if (check_col(pinfo->cinfo, COL_INFO)) {
454                 col_append_fstr(pinfo->cinfo, COL_INFO,
455                     "; Window Size %d", (wsize & 0xFE) >> 1);
456         }
457 }
458
459 static void
460 dissect_llc(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
461 {
462         proto_tree      *llc_tree = NULL;
463         proto_item      *ti = NULL;
464         int             is_snap;
465         guint16         control;
466         int             llc_header_len;
467         guint8          dsap, ssap, format;
468         tvbuff_t        *next_tvb;
469
470         col_set_str(pinfo->cinfo, COL_PROTOCOL, "LLC");
471         col_clear(pinfo->cinfo, COL_INFO);
472
473         dsap = tvb_get_guint8(tvb, 0);
474         if (tree) {
475                 ti = proto_tree_add_item(tree, proto_llc, tvb, 0, -1, ENC_NA);
476                 llc_tree = proto_item_add_subtree(ti, ett_llc);
477                 proto_tree_add_uint(llc_tree, hf_llc_dsap, tvb, 0,
478                         1, dsap & SAP_MASK);
479                 proto_tree_add_boolean(llc_tree, hf_llc_dsap_ig, tvb, 0,
480                         1, dsap & DSAP_GI_BIT);
481         } else
482                 llc_tree = NULL;
483
484         ssap = tvb_get_guint8(tvb, 1);
485         if (tree) {
486                 proto_tree_add_uint(llc_tree, hf_llc_ssap, tvb, 1,
487                         1, ssap & SAP_MASK);
488                 proto_tree_add_boolean(llc_tree, hf_llc_ssap_cr, tvb, 1,
489                         1, ssap & SSAP_CR_BIT);
490         } else
491                 llc_tree = NULL;
492
493         is_snap = (dsap == SAP_SNAP) && (ssap == SAP_SNAP);
494         llc_header_len = 2;     /* DSAP + SSAP */
495
496         /*
497          * XXX - the page referred to in the comment above about the
498          * Command/Response bit also implies that LLC Type 2 always
499          * uses extended operation, so we don't need to determine
500          * whether it's basic or extended operation; is that the case?
501          */
502         control = dissect_xdlc_control(tvb, 2, pinfo, llc_tree,
503                                 hf_llc_ctrl, ett_llc_ctrl,
504                                 &llc_cf_items, &llc_cf_items_ext,
505                                 NULL, NULL, ssap & SSAP_CR_BIT, TRUE, FALSE);
506         llc_header_len += XDLC_CONTROL_LEN(control, TRUE);
507         if (is_snap)
508                 llc_header_len += 5;    /* 3 bytes of OUI, 2 bytes of protocol ID */
509
510         if (tree)
511                 proto_item_set_len(ti, llc_header_len);
512
513         if (is_snap) {
514                 dissect_snap(tvb, 2+XDLC_CONTROL_LEN(control, TRUE), pinfo, tree, llc_tree, control,
515                     hf_llc_oui, hf_llc_type, hf_llc_pid, 2);
516         }
517         else {
518                 if (check_col(pinfo->cinfo, COL_INFO)) {
519                         col_append_fstr(pinfo->cinfo, COL_INFO,
520                             "; DSAP %s %s, SSAP %s %s",
521                             val_to_str(dsap & SAP_MASK, sap_vals, "0x%02x"),
522                             dsap & DSAP_GI_BIT ?
523                               "Group" : "Individual",
524                             val_to_str(ssap & SAP_MASK, sap_vals, "0x%02x"),
525                             ssap & SSAP_CR_BIT ?
526                               "Response" : "Command"
527                         );
528                 }
529
530                 if (tvb_length_remaining(tvb, llc_header_len) > 0) {
531                         next_tvb = tvb_new_subset_remaining(tvb, llc_header_len);
532                         if (XDLC_IS_INFORMATION(control)) {
533                                 /*
534                                  * Non-SNAP I or UI frame.
535                                  * Try the regular LLC subdissector table
536                                  * with the DSAP.
537                                  */
538                                 if (!dissector_try_uint(dsap_subdissector_table,
539                                     dsap, next_tvb, pinfo, tree)) {
540                                         call_dissector(data_handle, next_tvb,
541                                             pinfo, tree);
542                                 }
543                         } else if ((control & (XDLC_U_MODIFIER_MASK|XDLC_U))
544                             == (XDLC_XID|XDLC_U)) {
545                                 /*
546                                  * Non-SNAP XID frame.
547                                  * Test for LLC basic format first
548                                  */
549                                 format = tvb_get_guint8(next_tvb, 0);
550                                 if (format == 0x81) {
551                                     dissect_basicxid(next_tvb, pinfo, tree);
552                                 } else {
553                                 /*
554                                  * Try the XID LLC subdissector table
555                                  * with the DSAP.
556                                  */
557                                     if (!dissector_try_uint(
558                                         xid_subdissector_table, dsap, next_tvb,
559                                         pinfo, tree)) {
560                                             call_dissector(data_handle,
561                                                 next_tvb, pinfo, tree);
562                                     }
563                                 }
564                         } else {
565                                 call_dissector(data_handle, next_tvb, pinfo,
566                                     tree);
567                         }
568                 }
569         }
570 }
571
572 /*
573  * Dissect SNAP header; used elsewhere, e.g. in the Frame Relay dissector.
574  */
575 void
576 dissect_snap(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree,
577     proto_tree *snap_tree, int control, int hf_oui, int hf_type, int hf_pid,
578     int bridge_pad)
579 {
580         guint32         oui;
581         guint16         etype;
582         tvbuff_t        *next_tvb;
583         oui_info_t      *oui_info;
584         dissector_table_t subdissector_table;
585         int             hf;
586         int             mesh_header_len;
587
588         /*
589          * XXX - what about non-UI frames?
590          */
591         oui =   tvb_get_ntoh24(tvb, offset);
592         etype = tvb_get_ntohs(tvb, offset+3);
593
594         if (check_col(pinfo->cinfo, COL_INFO)) {
595                 col_append_fstr(pinfo->cinfo, COL_INFO,
596                     "; SNAP, OUI 0x%06X (%s), PID 0x%04X",
597                     oui, val_to_str(oui, oui_vals, "Unknown"), etype);
598         }
599         if (tree) {
600                 proto_tree_add_uint(snap_tree, hf_oui, tvb, offset, 3, oui);
601         }
602
603         switch (oui) {
604
605         case OUI_HP_2:
606                 oui_info = get_snap_oui_info(oui);
607                 hf = *oui_info->field_info->p_id;
608                 subdissector_table = oui_info->table;
609                 proto_tree_add_uint(snap_tree, hf, tvb, offset+3, 2, etype);
610                 next_tvb = tvb_new_subset_remaining(tvb, offset+5);
611
612                 if(!dissector_try_uint(hpteam_subdissector_table,etype, next_tvb, pinfo, tree))
613                         call_dissector(data_handle, next_tvb, pinfo, tree);
614                 break;
615
616         case OUI_ENCAP_ETHER:
617         case OUI_CISCO_90:
618         case OUI_APPLE_ATALK:
619                 /* No, I have no idea why Apple used
620                    one of their own OUIs, rather than
621                    OUI_ENCAP_ETHER, and an Ethernet
622                    packet type as protocol ID, for
623                    AppleTalk data packets - but used
624                    OUI_ENCAP_ETHER and an Ethernet
625                    packet type for AARP packets. */
626                 if (XDLC_IS_INFORMATION(control)) {
627                         if (tree) {
628                                 proto_tree_add_uint(snap_tree, hf_type,
629                                     tvb, offset+3, 2, etype);
630                         }
631                         next_tvb = tvb_new_subset_remaining(tvb, offset+5);
632                         if (!dissector_try_uint(ethertype_subdissector_table,
633                             etype, next_tvb, pinfo, tree))
634                                 call_dissector(data_handle, next_tvb, pinfo,
635                                     tree);
636                 } else {
637                         next_tvb = tvb_new_subset_remaining(tvb, offset+5);
638                         call_dissector(data_handle, next_tvb, pinfo, tree);
639                 }
640                 break;
641
642         case OUI_BRIDGED:
643                 /*
644                  * MAC frames bridged over ATM (RFC 2684) or Frame Relay
645                  * (RFC 2427).
646                  *
647                  * We have to figure out how much padding to put
648                  * into the frame.  We were handed a "bridge_pad"
649                  * argument which should be 0 for Frame Relay and
650                  * 2 for ATM; we add to that the amount of padding
651                  * common to both bridging types.
652                  */
653                 if (tree) {
654                         proto_tree_add_uint(snap_tree, hf_pid, tvb, offset+3, 2,
655                             etype);
656                 }
657
658                 switch (etype) {
659
660                 case BPID_ETH_WITH_FCS:
661                         next_tvb = tvb_new_subset_remaining(tvb, offset+5+bridge_pad);
662                         call_dissector(eth_withfcs_handle, next_tvb, pinfo,
663                             tree);
664                         break;
665
666                 case BPID_ETH_WITHOUT_FCS:
667                         next_tvb = tvb_new_subset_remaining(tvb, offset+5+bridge_pad);
668                         call_dissector(eth_withoutfcs_handle, next_tvb, pinfo, tree);
669                         break;
670
671                 case BPID_802_5_WITH_FCS:
672                 case BPID_802_5_WITHOUT_FCS:
673                         /*
674                          * We treat the last padding byte as the Access
675                          * Control byte, as that's what the Token
676                          * Ring dissector expects the first byte to
677                          * be.
678                          */
679                         next_tvb = tvb_new_subset_remaining(tvb, offset+5+bridge_pad);
680                         call_dissector(tr_handle, next_tvb, pinfo, tree);
681                         break;
682
683                 case BPID_FDDI_WITH_FCS:
684                 case BPID_FDDI_WITHOUT_FCS:
685                         next_tvb = tvb_new_subset_remaining(tvb, offset+5+1+bridge_pad);
686                         call_dissector(fddi_handle, next_tvb, pinfo, tree);
687                         break;
688
689                 case BPID_BPDU:
690                         next_tvb = tvb_new_subset_remaining(tvb, offset+5);
691                         call_dissector(bpdu_handle, next_tvb, pinfo, tree);
692                         break;
693
694                 default:
695                         next_tvb = tvb_new_subset_remaining(tvb, offset+5);
696                         call_dissector(data_handle, next_tvb, pinfo, tree);
697                         break;
698                 }
699                 break;
700
701         case OUI_CABLE_BPDU:    /* DOCSIS cable modem spanning tree BPDU */
702                 if (tree) {
703                         proto_tree_add_uint(snap_tree, hf_pid, tvb, offset+3, 2,
704                             etype);
705                 }
706                 next_tvb = tvb_new_subset_remaining(tvb, offset+5);
707                 call_dissector(bpdu_handle, next_tvb, pinfo, tree);
708                 break;
709
710         case OUI_TURBOCELL:
711                 next_tvb = tvb_new_subset_remaining(tvb, offset+3);
712                 call_dissector(turbo_handle, next_tvb, pinfo, tree);
713                 break;
714
715         case OUI_MARVELL:
716                 /*
717                  * OLPC packet.  The PID is an Ethertype, but
718                  * there's a mesh header between the PID and
719                  * the payload.
720                  */
721                 if (XDLC_IS_INFORMATION(control)) {
722                         if (tree) {
723                                 proto_tree_add_uint(snap_tree, hf_type,
724                                     tvb, offset+3, 2, etype);
725                         }
726                         next_tvb = tvb_new_subset_remaining(tvb, offset+5);
727                         mesh_header_len = call_dissector(mesh_handle,
728                             next_tvb, pinfo, tree);
729                         next_tvb = tvb_new_subset_remaining(tvb, offset+5+mesh_header_len);
730                         if (!dissector_try_uint(ethertype_subdissector_table,
731                             etype, next_tvb, pinfo, tree))
732                                 call_dissector(data_handle, next_tvb, pinfo,
733                                     tree);
734                 } else {
735                         next_tvb = tvb_new_subset_remaining(tvb, offset+5);
736                         call_dissector(data_handle, next_tvb, pinfo, tree);
737                 }
738                 break;
739
740         default:
741                 /*
742                  * Do we have information for this OUI?
743                  */
744                 oui_info = get_snap_oui_info(oui);
745                 if (oui_info != NULL) {
746                         /*
747                          * Yes - use it.
748                          */
749                         hf = *oui_info->field_info->p_id;
750                         subdissector_table = oui_info->table;
751                 } else {
752                         /*
753                          * No, use hf_pid for the PID and just dissect
754                          * the payload as data.
755                          */
756                         hf = hf_pid;
757                         subdissector_table = NULL;
758                 }
759                 if (tree) {
760                         proto_tree_add_uint(snap_tree, hf, tvb, offset+3, 2,
761                             etype);
762                 }
763                 next_tvb = tvb_new_subset_remaining(tvb, offset+5);
764                 if (XDLC_IS_INFORMATION(control)) {
765                         if (subdissector_table != NULL) {
766                                 /* do lookup with the subdissector table */
767                                 if (dissector_try_uint(subdissector_table,
768                                     etype, next_tvb, pinfo, tree))
769                                         break;
770                         }
771                 }
772                 call_dissector(data_handle, next_tvb, pinfo, tree);
773                 break;
774         }
775 }
776
777 /*
778  * Return the oui_info_t for the PID for a particular OUI value, or NULL
779  * if there isn't one.
780  */
781 oui_info_t *
782 get_snap_oui_info(guint32 oui)
783 {
784         if (oui_info_table != NULL) {
785                 return g_hash_table_lookup(oui_info_table,
786                     GUINT_TO_POINTER(oui));
787         } else
788                 return NULL;
789 }
790
791 void
792 proto_register_llc(void)
793 {
794         static struct true_false_string ig_bit = { "Group", "Individual" };
795         static struct true_false_string cr_bit = { "Response", "Command" };
796
797         static hf_register_info hf[] = {
798                 { &hf_llc_dsap,
799                 { "DSAP",       "llc.dsap", FT_UINT8, BASE_HEX,
800                         VALS(sap_vals), 0x0, "DSAP - 7 Most Significant Bits only", HFILL }},
801
802                 { &hf_llc_dsap_ig,
803                 { "IG Bit",     "llc.dsap.ig", FT_BOOLEAN, BASE_NONE,
804                         TFS(&ig_bit), 0x0, "Individual/Group - Least Significant Bit only", HFILL }},
805
806                 { &hf_llc_ssap,
807                 { "SSAP", "llc.ssap", FT_UINT8, BASE_HEX,
808                         VALS(sap_vals), 0x0, "SSAP - 7 Most Significant Bits only", HFILL }},
809
810                 { &hf_llc_ssap_cr,
811                 { "CR Bit", "llc.ssap.cr", FT_BOOLEAN, BASE_NONE,
812                         TFS(&cr_bit), 0x0, "Command/Response - Least Significant Bit only", HFILL }},
813
814                 { &hf_llc_ctrl,
815                 { "Control", "llc.control", FT_UINT16, BASE_HEX,
816                         NULL, 0x0, NULL, HFILL }},
817
818                 { &hf_llc_n_r,
819                 { "N(R)", "llc.control.n_r", FT_UINT16, BASE_DEC,
820                         NULL, XDLC_N_R_EXT_MASK, NULL, HFILL }},
821
822                 { &hf_llc_n_s,
823                 { "N(S)", "llc.control.n_s", FT_UINT16, BASE_DEC,
824                         NULL, XDLC_N_S_EXT_MASK, NULL, HFILL }},
825
826                 { &hf_llc_p,
827                 { "Poll", "llc.control.p", FT_BOOLEAN, 8,
828                         TFS(&tfs_set_notset), XDLC_P_F, NULL, HFILL }},
829
830                 { &hf_llc_p_ext,
831                 { "Poll", "llc.control.p", FT_BOOLEAN, 16,
832                         TFS(&tfs_set_notset), XDLC_P_F_EXT, NULL, HFILL }},
833
834                 { &hf_llc_f,
835                 { "Final", "llc.control.f", FT_BOOLEAN, 8,
836                         TFS(&tfs_set_notset), XDLC_P_F, NULL, HFILL }},
837
838                 { &hf_llc_f_ext,
839                 { "Final", "llc.control.f", FT_BOOLEAN, 16,
840                         TFS(&tfs_set_notset), XDLC_P_F_EXT, NULL, HFILL }},
841
842                 { &hf_llc_s_ftype,
843                 { "Supervisory frame type", "llc.control.s_ftype", FT_UINT16, BASE_HEX,
844                         VALS(stype_vals), XDLC_S_FTYPE_MASK, NULL, HFILL }},
845
846                 { &hf_llc_u_modifier_cmd,
847                 { "Command", "llc.control.u_modifier_cmd", FT_UINT8, BASE_HEX,
848                         VALS(modifier_vals_cmd), XDLC_U_MODIFIER_MASK, NULL, HFILL }},
849
850                 { &hf_llc_u_modifier_resp,
851                 { "Response", "llc.control.u_modifier_resp", FT_UINT8, BASE_HEX,
852                         VALS(modifier_vals_resp), XDLC_U_MODIFIER_MASK, NULL, HFILL }},
853
854                 { &hf_llc_ftype_i,
855                 { "Frame type", "llc.control.ftype", FT_UINT16, BASE_HEX,
856                         VALS(ftype_vals), XDLC_I_MASK, NULL, HFILL }},
857
858                 { &hf_llc_ftype_s_u,
859                 { "Frame type", "llc.control.ftype", FT_UINT8, BASE_HEX,
860                         VALS(ftype_vals), XDLC_S_U_MASK, NULL, HFILL }},
861
862                 { &hf_llc_ftype_s_u_ext,
863                 { "Frame type", "llc.control.ftype", FT_UINT16, BASE_HEX,
864                         VALS(ftype_vals), XDLC_S_U_MASK, NULL, HFILL }},
865
866                 /* registered here but handled in ethertype.c */
867                 { &hf_llc_type,
868                 { "Type", "llc.type", FT_UINT16, BASE_HEX,
869                         VALS(etype_vals), 0x0, NULL, HFILL }},
870
871                 { &hf_llc_oui,
872                 { "Organization Code",  "llc.oui", FT_UINT24, BASE_HEX,
873                         VALS(oui_vals), 0x0, NULL, HFILL }},
874
875                 { &hf_llc_pid,
876                 { "Protocol ID", "llc.pid", FT_UINT16, BASE_HEX,
877                         NULL, 0x0, NULL, HFILL }}
878         };
879         static gint *ett[] = {
880                 &ett_llc,
881                 &ett_llc_ctrl
882         };
883
884         proto_llc = proto_register_protocol("Logical-Link Control", "LLC", "llc");
885         proto_register_field_array(proto_llc, hf, array_length(hf));
886         proto_register_subtree_array(ett, array_length(ett));
887
888         /* subdissector code */
889         dsap_subdissector_table = register_dissector_table("llc.dsap",
890           "LLC SAP", FT_UINT8, BASE_HEX);
891         xid_subdissector_table = register_dissector_table("llc.xid_dsap",
892           "LLC XID SAP", FT_UINT8, BASE_HEX);
893
894         register_dissector("llc", dissect_llc, proto_llc);
895 }
896
897 void
898 proto_register_basicxid(void)
899 {
900         static hf_register_info hf[] = {
901                 { &hf_llc_xid_format,
902                 { "XID Format", "basicxid.llc.xid.format", FT_UINT8, BASE_HEX,
903                         VALS(format_vals), 0x0, NULL, HFILL }},
904
905                 { &hf_llc_xid_types,
906                 { "LLC Types/Classes", "basicxid.llc.xid.types", FT_UINT8, BASE_HEX,
907                         VALS(type_vals), 0x0, NULL, HFILL }},
908
909                 { &hf_llc_xid_wsize,
910                 { "Receive Window Size", "basicxid.llc.xid.wsize", FT_UINT8, BASE_DEC,
911                         NULL, 0x0, NULL, HFILL }}
912         };
913         static gint *ett[] = {
914                 &ett_llc_basicxid
915         };
916
917         proto_basicxid = proto_register_protocol("Logical-Link Control Basic Format XID", "Basic Format XID", "basicxid");
918         proto_register_field_array(proto_basicxid, hf, array_length(hf));
919         proto_register_subtree_array(ett, array_length(ett));
920
921         register_dissector("basicxid", dissect_basicxid, proto_basicxid);
922 }
923
924 static void
925 register_hf(gpointer key _U_, gpointer value, gpointer user_data _U_)
926 {
927         oui_info_t *info = value;
928
929         proto_register_field_array(proto_llc, info->field_info, 1);
930 }
931
932 void
933 proto_reg_handoff_llc(void)
934 {
935         dissector_handle_t llc_handle;
936
937         /*
938          * Get handles for the BPDU, Ethernet, FDDI, Token Ring and
939          * Turbocell dissectors.
940          */
941         bpdu_handle = find_dissector("bpdu");
942         eth_withoutfcs_handle = find_dissector("eth_withoutfcs");
943         eth_withfcs_handle = find_dissector("eth_withfcs");
944         fddi_handle = find_dissector("fddi");
945         tr_handle = find_dissector("tr");
946         turbo_handle = find_dissector("turbocell");
947         mesh_handle = find_dissector("mesh");
948         data_handle = find_dissector("data");
949
950         /*
951          * Get the Ethertype dissector table.
952          */
953         ethertype_subdissector_table = find_dissector_table("ethertype");
954         hpteam_subdissector_table = find_dissector_table("llc.hpteam_pid");
955
956         llc_handle = find_dissector("llc");
957         dissector_add_uint("wtap_encap", WTAP_ENCAP_ATM_RFC1483, llc_handle);
958         dissector_add_uint("sll.ltype", LINUX_SLL_P_802_2, llc_handle);
959         /* RFC 2043 */
960         dissector_add_uint("ppp.protocol", PPP_LLC, llc_handle);
961         /* RFC 2353 */
962         dissector_add_uint("udp.port", UDP_PORT_LLC1, llc_handle);
963         dissector_add_uint("udp.port", UDP_PORT_LLC2, llc_handle);
964         dissector_add_uint("udp.port", UDP_PORT_LLC3, llc_handle);
965         dissector_add_uint("udp.port", UDP_PORT_LLC4, llc_handle);
966         dissector_add_uint("udp.port", UDP_PORT_LLC5, llc_handle);
967         /* IP-over-FC when we have the full FC frame */
968         dissector_add_uint("fc.ftype", FC_FTYPE_IP, llc_handle);
969
970         /*
971          * BACNET-over-ARCNET is really BACNET-over-802.2 LLC-over-ARCNET,
972          * apparently.
973          */
974         dissector_add_uint("arcnet.protocol_id", ARCNET_PROTO_BACNET, llc_handle);
975         dissector_add_uint("ethertype", ETHERTYPE_JUMBO_LLC, llc_handle);
976
977         /*
978          * Register all the fields for PIDs for various OUIs.
979          */
980         if (oui_info_table != NULL)
981                 g_hash_table_foreach(oui_info_table, register_hf, NULL);
982 }