From Andreas Sikkema:
[metze/wireshark/wip.git] / 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: packet-llc.c,v 1.112 2003/08/28 01:29:15 guy Exp $
6  *
7  * Ethereal - Network traffic analyzer
8  * By Gerald Combs <gerald@ethereal.com>
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 "oui.h"
33 #include "xdlc.h"
34 #include "etypes.h"
35 #include "llcsaps.h"
36 #include "bridged_pids.h"
37 #include "ppptypes.h"
38 #include "arcnet_pids.h"
39 #include "packet-fc.h"
40 #include "packet-ip.h"
41 #include "packet-ipx.h"
42 #include "packet-netbios.h"
43 #include "packet-vines.h"
44 #include <epan/sna-utils.h>
45
46 #include "packet-llc.h"
47
48 #define UDP_PORT_LLC1   12000
49 #define UDP_PORT_LLC2   12001
50 #define UDP_PORT_LLC3   12002
51 #define UDP_PORT_LLC4   12003
52 #define UDP_PORT_LLC5   12004
53
54 static int proto_llc = -1;
55 static int hf_llc_dsap = -1;
56 static int hf_llc_ssap = -1;
57 static int hf_llc_dsap_ig = -1;
58 static int hf_llc_ssap_cr = -1;
59 static int hf_llc_ctrl = -1;
60 static int hf_llc_type = -1;
61 static int hf_llc_oui = -1;
62 static int hf_llc_pid = -1;
63
64 static gint ett_llc = -1;
65 static gint ett_llc_ctrl = -1;
66
67 static dissector_table_t subdissector_table;
68 static dissector_table_t cisco_subdissector_table;
69 static dissector_table_t xid_subdissector_table;
70
71 static dissector_table_t nortel_subdissector_table;
72
73 static dissector_handle_t bpdu_handle;
74 static dissector_handle_t eth_handle;
75 static dissector_handle_t fddi_handle;
76 static dissector_handle_t tr_handle;
77 static dissector_handle_t data_handle;
78
79 /*
80  * Group/Individual bit, in the DSAP.
81  */
82 #define DSAP_GI_BIT     0x01
83
84 /*
85  * Command/Response bit, in the SSAP.
86  *
87  * The low-order bit of the SSAP apparently determines whether this
88  * is a request or a response.  (RFC 1390, "Transmission of IP and
89  * ARP over FDDI Networks", says
90  *
91  *      Command frames are identified by having the low order
92  *      bit of the SSAP address reset to zero.  Response frames
93  *      have the low order bit of the SSAP address set to one.
94  *
95  * and a page I've seen seems to imply that's part of 802.2.)
96  */
97 #define SSAP_CR_BIT     0x01
98
99 /*
100  * Mask to extrace the SAP number from the DSAP or the SSAP.
101  */
102 #define SAP_MASK        0xFE
103
104 /*
105  * These are for SSAP and DSAP, wth last bit always zero.
106  * XXX - some DSAPs come in separate "individual" and "group" versions,
107  * with the last bit 0 and 1, respectively (e.g., LLC Sub-layer Management,
108  * IBM SNA Path Control, IBM Net Management), but, whilst 0xFE is
109  * the ISO Network Layer Protocol, 0xFF is the Global LSAP.
110  */
111 const value_string sap_vals[] = {
112         { SAP_NULL,           "NULL LSAP" },
113         { SAP_LLC_SLMGMT,     "LLC Sub-Layer Management" },
114         { SAP_SNA_PATHCTRL,   "SNA Path Control" },
115         { SAP_IP,             "TCP/IP" },
116         { SAP_SNA1,           "SNA" },
117         { SAP_SNA2,           "SNA" },
118         { SAP_PROWAY_NM_INIT, "PROWAY (IEC955) Network Management and Initialization" },
119         { SAP_NETWARE1,       "NetWare (unofficial?)" },
120         { SAP_OSINL1,         "ISO Network Layer (OSLAN 1)" },
121         { SAP_TI,             "Texas Instruments" },
122         { SAP_OSINL2,         "ISO Network Layer (unofficial?)" },
123         { SAP_OSINL3,         "ISO Network Layer (unofficial?)" },
124         { SAP_BPDU,           "Spanning Tree BPDU" },
125         { SAP_RS511,          "EIA RS-511 Manufacturing Message Service" },
126         { SAP_OSINL4,         "ISO Network Layer (OSLAN 2)" },
127         { SAP_X25,            "ISO 8208 (X.25 over 802.2)" },
128         /*
129          * XXX - setting the group bit of SAP_X25 make 0x7F; is this just
130          * a group version of that?
131          */
132         { 0x7F,               "ISO 802.2" },
133         { SAP_XNS,            "XNS" },
134         { SAP_BACNET,         "BACnet" },
135         { SAP_NESTAR,         "Nestar" },
136         { SAP_PROWAY_ASLM,    "PROWAY (IEC955) Active Station List Maintenance" },
137         { SAP_ARP,            "ARP" },  /* XXX - hand to "dissect_arp()"? */
138         { SAP_SNAP,           "SNAP" },
139         { SAP_VINES1,         "Banyan Vines" },
140         { SAP_VINES2,         "Banyan Vines" },
141         { SAP_NETWARE2,       "NetWare" },
142         { SAP_NETBIOS,        "NetBIOS" },
143         { SAP_IBMNM,          "IBM Net Management" },
144         { SAP_HPEXT,          "HP Extended LLC" },
145         { SAP_UB,             "Ungermann-Bass" },
146         { SAP_RPL,            "Remote Program Load" },
147         { SAP_OSINL5,         "ISO Network Layer" },
148         { SAP_GLOBAL,         "Global LSAP" },
149         { 0x00,               NULL }
150 };
151
152 /*
153  * See
154  *
155  * http://www.cisco.com/univercd/cc/td/doc/product/lan/trsrb/vlan.htm
156  *
157  * for the PIDs for VTP and DRiP that go with an OUI of OUI_CISCO.
158  */
159 const value_string oui_vals[] = {
160         { OUI_ENCAP_ETHER, "Encapsulated Ethernet" },
161 /*
162 http://www.cisco.com/univercd/cc/td/doc/product/software/ios113ed/113ed_cr/ibm_r/brprt1/brsrb.htm
163 */
164         { OUI_CISCO,       "Cisco" },
165         { OUI_CISCO_90,    "Cisco IOS 9.0 Compatible" },
166         { OUI_BRIDGED,     "Frame Relay or ATM bridged frames" },
167                                 /* RFC 2427, RFC 2684 */
168         { OUI_ATM_FORUM,   "ATM Forum" },
169         { OUI_CABLE_BPDU,  "DOCSIS Spanning Tree" }, /* DOCSIS spanning tree BPDU */
170         { OUI_APPLE_ATALK, "Apple (AppleTalk)" },
171         { OUI_NORTEL,   "Nortel Networks SONMP" },
172         { 0,               NULL }
173 };
174
175 /*
176  * Hash table for translating OUIs to a dissector table/field ID pair;
177  * the dissector table maps PID values to dissectors, and the field
178  * corresponds to the PID for that OUI.
179  */
180 typedef struct {
181         dissector_table_t table;
182         int     field_id;
183 } oui_info_t;
184
185 static GHashTable *oui_dissector_tables = NULL;
186
187 /*
188  * Add an entry for a new OID.
189  */
190 void
191 llc_add_oid(guint32 oid, const char *table_name, char *table_ui_name,
192     int field_id)
193 {
194         oui_info_t *new_info;
195
196         new_info = g_malloc(sizeof (oui_info_t));
197         new_info->table = register_dissector_table(table_name,
198             table_ui_name, FT_UINT16, BASE_HEX);
199         new_info->field_id = field_id;
200
201         /*
202          * Create the hash table for OUI information, if it doesn't
203          * already exist.
204          */
205         if (oui_dissector_tables == NULL) {
206                 oui_dissector_tables = g_hash_table_new(g_direct_hash,
207                     g_direct_equal);
208         }
209         g_hash_table_insert(oui_dissector_tables, (gpointer)oid,
210             new_info->table);
211 }
212
213 void
214 capture_llc(const guchar *pd, int offset, int len, packet_counts *ld) {
215
216         int             is_snap;
217         guint16         control;
218         int             llc_header_len;
219         guint32         oui;
220         guint16         etype;
221
222         if (!BYTES_ARE_IN_FRAME(offset, len, 2)) {
223                 ld->other++;
224                 return;
225         }
226         is_snap = (pd[offset] == SAP_SNAP) && (pd[offset+1] == SAP_SNAP);
227         llc_header_len = 2;     /* DSAP + SSAP */
228
229         /*
230          * XXX - the page referred to in the comment above about the
231          * Command/Response bit also implies that LLC Type 2 always
232          * uses extended operation, so we don't need to determine
233          * whether it's basic or extended operation; is that the case?
234          */
235         control = get_xdlc_control(pd, offset+2, pd[offset+1] & SSAP_CR_BIT);
236         llc_header_len += XDLC_CONTROL_LEN(control, TRUE);
237         if (is_snap)
238                 llc_header_len += 5;    /* 3 bytes of OUI, 2 bytes of protocol ID */
239         if (!BYTES_ARE_IN_FRAME(offset, len, llc_header_len)) {
240                 ld->other++;
241                 return;
242         }
243
244         if (is_snap) {
245                 oui = pd[offset+3] << 16 | pd[offset+4] << 8 | pd[offset+5];
246                 if (XDLC_IS_INFORMATION(control)) {
247                         etype = pntohs(&pd[offset+6]);
248                         switch (oui) {
249
250                         case OUI_ENCAP_ETHER:
251                         case OUI_CISCO_90:
252                         case OUI_APPLE_ATALK:
253                                 /* No, I have no idea why Apple used
254                                    one of their own OUIs, rather than
255                                    OUI_ENCAP_ETHER, and an Ethernet
256                                    packet type as protocol ID, for
257                                    AppleTalk data packets - but used
258                                    OUI_ENCAP_ETHER and an Ethernet
259                                    packet type for AARP packets. */
260                                 capture_ethertype(etype, pd, offset+8, len,
261                                     ld);
262                                 break;
263                         case OUI_CISCO:
264                                 capture_ethertype(etype, pd, offset + 8, len,
265                                     ld);
266                                 break;
267                         default:
268                                 ld->other++;
269                                 break;
270                         }
271                 }
272         }
273         else {
274                 /* non-SNAP */
275                 if (XDLC_IS_INFORMATION(control)) {
276                         switch (pd[offset]) {
277
278                         case SAP_IP:
279                                 capture_ip(pd, offset + llc_header_len, len,
280                                     ld);
281                                 break;
282
283                         case SAP_NETWARE1:
284                         case SAP_NETWARE2:
285                                 capture_ipx(ld);
286                                 break;
287
288                         case SAP_NETBIOS:
289                                 capture_netbios(ld);
290                                 break;
291
292                         case SAP_VINES1:
293                         case SAP_VINES2:
294                                 capture_vines(ld);
295                                 break;
296
297                         default:
298                                 ld->other++;
299                                 break;
300                         }
301                 }
302         }
303 }
304
305 static void
306 dissect_llc(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
307 {
308         proto_tree      *llc_tree = NULL;
309         proto_item      *ti = NULL;
310         int             is_snap;
311         guint16         control;
312         int             llc_header_len;
313         guint8          dsap, ssap;
314         tvbuff_t        *next_tvb;
315
316         if (check_col(pinfo->cinfo, COL_PROTOCOL)) {
317                 col_set_str(pinfo->cinfo, COL_PROTOCOL, "LLC");
318         }
319         if (check_col(pinfo->cinfo, COL_INFO)) {
320                 col_clear(pinfo->cinfo, COL_INFO);
321         }
322
323         dsap = tvb_get_guint8(tvb, 0);
324         if (tree) {
325                 ti = proto_tree_add_item(tree, proto_llc, tvb, 0, -1, FALSE);
326                 llc_tree = proto_item_add_subtree(ti, ett_llc);
327                 proto_tree_add_uint(llc_tree, hf_llc_dsap, tvb, 0,
328                         1, dsap & SAP_MASK);
329                 proto_tree_add_boolean(llc_tree, hf_llc_dsap_ig, tvb, 0,
330                         1, dsap & DSAP_GI_BIT);
331         } else
332                 llc_tree = NULL;
333
334         ssap = tvb_get_guint8(tvb, 1);
335         if (tree) {
336                 proto_tree_add_uint(llc_tree, hf_llc_ssap, tvb, 1,
337                         1, ssap & SAP_MASK);
338                 proto_tree_add_boolean(llc_tree, hf_llc_ssap_cr, tvb, 1,
339                         1, ssap & SSAP_CR_BIT);
340         } else
341                 llc_tree = NULL;
342
343         is_snap = (dsap == SAP_SNAP) && (ssap == SAP_SNAP);
344         llc_header_len = 2;     /* DSAP + SSAP */
345
346         /*
347          * XXX - the page referred to in the comment above about the
348          * Command/Response bit also implies that LLC Type 2 always
349          * uses extended operation, so we don't need to determine
350          * whether it's basic or extended operation; is that the case?
351          */
352         control = dissect_xdlc_control(tvb, 2, pinfo, llc_tree,
353                                 hf_llc_ctrl, ett_llc_ctrl,
354                                 ssap & SSAP_CR_BIT, TRUE);
355         llc_header_len += XDLC_CONTROL_LEN(control, TRUE);
356         if (is_snap)
357                 llc_header_len += 5;    /* 3 bytes of OUI, 2 bytes of protocol ID */
358
359         if (tree)
360                 proto_item_set_len(ti, llc_header_len);
361
362         if (is_snap) {
363                 dissect_snap(tvb, 3, pinfo, tree, llc_tree, control,
364                     hf_llc_oui, hf_llc_type, hf_llc_pid, 2);
365         }
366         else {
367                 if (check_col(pinfo->cinfo, COL_INFO)) {
368                         col_append_fstr(pinfo->cinfo, COL_INFO,
369                             "; DSAP %s %s, SSAP %s %s",
370                             val_to_str(dsap & SAP_MASK, sap_vals, "%02x"),
371                             dsap & DSAP_GI_BIT ?
372                               "Group" : "Individual",
373                             val_to_str(ssap & SAP_MASK, sap_vals, "%02x"),
374                             ssap & SSAP_CR_BIT ?
375                               "Response" : "Command"
376                         );
377                 }
378
379                 if (tvb_length_remaining(tvb, llc_header_len) > 0) {
380                         next_tvb = tvb_new_subset(tvb, llc_header_len, -1, -1);
381                         if (XDLC_IS_INFORMATION(control)) {
382                                 /*
383                                  * Non-SNAP I or UI frame.
384                                  * Try the regular LLC subdissector table
385                                  * with the DSAP.
386                                  */
387                                 if (!dissector_try_port(subdissector_table,
388                                     dsap, next_tvb, pinfo, tree)) {
389                                         call_dissector(data_handle, next_tvb,
390                                             pinfo, tree);
391                                 }
392                         } else if ((control & (XDLC_U_MODIFIER_MASK|XDLC_U))
393                             == (XDLC_XID|XDLC_U)) {
394                                 /*
395                                  * Non-SNAP XID frame.
396                                  * Try the XID LLC subdissector table
397                                  * with the DSAP.
398                                  */
399                                 if (!dissector_try_port(xid_subdissector_table,
400                                     dsap, next_tvb, pinfo, tree)) {
401                                         call_dissector(data_handle, next_tvb,
402                                             pinfo, tree);
403                                 }
404                         } else {
405                                 call_dissector(data_handle, next_tvb, pinfo,
406                                     tree);
407                         }
408                 }
409         }
410 }
411
412 /*
413  * Dissect SNAP header; used elsewhere, e.g. in the Frame Relay dissector.
414  */
415 void
416 dissect_snap(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree,
417     proto_tree *snap_tree, int control, int hf_oui, int hf_type, int hf_pid,
418     int bridge_pad)
419 {
420         guint32         oui;
421         guint16         etype;
422         tvbuff_t        *next_tvb;
423         oui_info_t      *oui_info;
424         dissector_table_t subdissector_table;
425         int             hf;
426
427         oui =   tvb_get_ntoh24(tvb, offset);
428         etype = tvb_get_ntohs(tvb, offset+3);
429
430         if (check_col(pinfo->cinfo, COL_INFO)) {
431                 col_append_fstr(pinfo->cinfo, COL_INFO,
432                     "; SNAP, OUI 0x%06X (%s), PID 0x%04X",
433                     oui, val_to_str(oui, oui_vals, "Unknown"), etype);
434         }
435         if (tree) {
436                 proto_tree_add_uint(snap_tree, hf_oui, tvb, offset, 3, oui);
437         }
438
439         switch (oui) {
440
441         case OUI_ENCAP_ETHER:
442         case OUI_CISCO_90:
443         case OUI_APPLE_ATALK:
444                 /* No, I have no idea why Apple used
445                    one of their own OUIs, rather than
446                    OUI_ENCAP_ETHER, and an Ethernet
447                    packet type as protocol ID, for
448                    AppleTalk data packets - but used
449                    OUI_ENCAP_ETHER and an Ethernet
450                    packet type for AARP packets. */
451                 if (XDLC_IS_INFORMATION(control)) {
452                         ethertype(etype, tvb, offset+5,
453                             pinfo, tree, snap_tree, hf_type, -1);
454                 } else {
455                         next_tvb = tvb_new_subset(tvb, offset+5, -1, -1);
456                         call_dissector(data_handle,next_tvb, pinfo, tree);
457                 }
458                 break;
459
460         case OUI_BRIDGED:
461                 /*
462                  * MAC frames bridged over ATM (RFC 2684) or Frame Relay
463                  * (RFC 2427).
464                  *
465                  * We have to figure out how much padding to put
466                  * into the frame.  We were handed a "bridge_pad"
467                  * argument which should be 0 for Frame Relay and
468                  * 2 for ATM; we add to that the amount of padding
469                  * common to both bridging types.
470                  */
471                 if (tree) {
472                         proto_tree_add_uint(snap_tree, hf_pid, tvb, offset+3, 2,
473                             etype);
474                 }
475
476                 switch (etype) {
477
478                 case BPID_ETH_WITH_FCS:
479                 case BPID_ETH_WITHOUT_FCS:
480                         next_tvb = tvb_new_subset(tvb, offset+5+bridge_pad,
481                             -1, -1);
482                         call_dissector(eth_handle, next_tvb, pinfo, tree);
483                         break;
484
485                 case BPID_802_5_WITH_FCS:
486                 case BPID_802_5_WITHOUT_FCS:
487                         /*
488                          * We treat the last padding byte as the Access
489                          * Control byte, as that's what the Token
490                          * Ring dissector expects the first byte to
491                          * be.
492                          */
493                         next_tvb = tvb_new_subset(tvb, offset+5+bridge_pad,
494                             -1, -1);
495                         call_dissector(tr_handle, next_tvb, pinfo, tree);
496                         break;
497
498                 case BPID_FDDI_WITH_FCS:
499                 case BPID_FDDI_WITHOUT_FCS:
500                         next_tvb = tvb_new_subset(tvb, offset+5+1+bridge_pad,
501                             -1, -1);
502                         call_dissector(fddi_handle, next_tvb, pinfo, tree);
503                         break;
504
505                 case BPID_BPDU:
506                         next_tvb = tvb_new_subset(tvb, offset+5, -1, -1);
507                         call_dissector(bpdu_handle, next_tvb, pinfo, tree);
508                         break;
509
510                 default:
511                         next_tvb = tvb_new_subset(tvb, offset+5, -1, -1);
512                         call_dissector(data_handle,next_tvb, pinfo, tree);
513                         break;
514                 }
515                 break;
516
517         case OUI_CISCO:
518                 /* So are all CDP packets LLC packets
519                    with an OUI of OUI_CISCO and a
520                    protocol ID of 0x2000, or
521                    are some of them raw or encapsulated
522                    Ethernet? */
523                 if (tree) {
524                         proto_tree_add_uint(snap_tree, hf_pid, tvb, offset+3, 2,
525                             etype);
526                 }
527                 next_tvb = tvb_new_subset(tvb, offset+5, -1, -1);
528                 if (XDLC_IS_INFORMATION(control)) {
529                         /* do lookup with the subdissector table */
530                         /* for future reference, 0x0102 is Cisco DRIP */
531                         if (!dissector_try_port(cisco_subdissector_table,
532                             etype, next_tvb, pinfo, tree))
533                                 call_dissector(data_handle,next_tvb, pinfo, tree);
534                 } else
535                         call_dissector(data_handle,next_tvb, pinfo, tree);
536                 break;
537
538         case OUI_CABLE_BPDU:    /* DOCSIS cable modem spanning tree BPDU */
539                 if (tree) {
540                         proto_tree_add_uint(snap_tree, hf_pid, tvb, offset+3, 2,
541                             etype);
542                 }
543                 next_tvb = tvb_new_subset(tvb, offset+5, -1, -1);
544                 call_dissector(bpdu_handle, next_tvb, pinfo, tree);
545                 break;
546
547         case OUI_NORTEL:
548                 /* Nortel Networks
549                  * Synoptics Networks Management Protocol
550                  * protocol ID's 0x01a1, 0x01a2, 0x01a3
551                  */
552                 if (tree) {
553                         proto_tree_add_uint(snap_tree, hf_pid,tvb, offset+3,2, etype);
554                 }
555                 next_tvb = tvb_new_subset(tvb, offset + 5, -1, -1);
556                 if (XDLC_IS_INFORMATION(control)) {
557                         /* do lookup with the subdissector table */
558                         if (!dissector_try_port(nortel_subdissector_table,
559                                 etype, next_tvb, pinfo, tree))
560                                         call_dissector(data_handle, next_tvb, pinfo, tree);
561                 } else
562                         call_dissector(data_handle, next_tvb, pinfo, tree);
563                 break;
564
565         default:
566                 /*
567                  * Do we have information for this OUI?
568                  */
569                 oui_info = g_hash_table_lookup(oui_dissector_tables,
570                     (gpointer)oui);
571                 if (oui_info != NULL) {
572                         /*
573                          * Yes - use it.
574                          */
575                         hf = oui_info->field_id;
576                         subdissector_table = oui_info->table;
577                 } else {
578                         /*
579                          * No, use hf_pid for the PID and just dissect
580                          * the payload as data.
581                          */
582                         hf = hf_pid;
583                         subdissector_table = NULL;
584                 }
585                 if (tree) {
586                         proto_tree_add_uint(snap_tree, hf, tvb, offset+3, 2,
587                             etype);
588                 }
589                 next_tvb = tvb_new_subset(tvb, offset+5, -1, -1);
590                 if (XDLC_IS_INFORMATION(control)) {
591                         if (subdissector_table != NULL) {
592                                 /* do lookup with the subdissector table */
593                                 if (dissector_try_port(subdissector_table,
594                                     etype, next_tvb, pinfo, tree))
595                                         break;
596                         }
597                 }
598                 call_dissector(data_handle, next_tvb, pinfo, tree);
599                 break;
600         }
601 }
602
603 void
604 proto_register_llc(void)
605 {
606         static struct true_false_string ig_bit = { "Group", "Individual" };
607         static struct true_false_string cr_bit = { "Response", "Command" };
608
609         static hf_register_info hf[] = {
610                 { &hf_llc_dsap,
611                 { "DSAP",       "llc.dsap", FT_UINT8, BASE_HEX,
612                         VALS(sap_vals), 0x0, "", HFILL }},
613
614                 { &hf_llc_dsap_ig,
615                 { "IG Bit",     "llc.dsap.ig", FT_BOOLEAN, BASE_HEX,
616                         &ig_bit, 0x0, "Individual/Group", HFILL }},
617
618                 { &hf_llc_ssap,
619                 { "SSAP", "llc.ssap", FT_UINT8, BASE_HEX,
620                         VALS(sap_vals), 0x0, "", HFILL }},
621
622                 { &hf_llc_ssap_cr,
623                 { "CR Bit", "llc.ssap.cr", FT_BOOLEAN, BASE_HEX,
624                         &cr_bit, 0x0, "Command/Response", HFILL }},
625
626                 { &hf_llc_ctrl,
627                 { "Control", "llc.control", FT_UINT16, BASE_HEX,
628                         NULL, 0x0, "", HFILL }},
629
630                 /* registered here but handled in ethertype.c */
631                 { &hf_llc_type,
632                 { "Type", "llc.type", FT_UINT16, BASE_HEX,
633                         VALS(etype_vals), 0x0, "", HFILL }},
634
635                 { &hf_llc_oui,
636                 { "Organization Code",  "llc.oui", FT_UINT24, BASE_HEX,
637                         VALS(oui_vals), 0x0, "", HFILL }},
638
639                 { &hf_llc_pid,
640                 { "Protocol ID", "llc.pid", FT_UINT16, BASE_HEX,
641                         NULL, 0x0, "", HFILL }}
642         };
643         static gint *ett[] = {
644                 &ett_llc,
645                 &ett_llc_ctrl,
646         };
647
648         proto_llc = proto_register_protocol("Logical-Link Control", "LLC", "llc");
649         proto_register_field_array(proto_llc, hf, array_length(hf));
650         proto_register_subtree_array(ett, array_length(ett));
651
652 /* subdissector code */
653         subdissector_table = register_dissector_table("llc.dsap",
654           "LLC SAP", FT_UINT8, BASE_HEX);
655         cisco_subdissector_table = register_dissector_table("llc.cisco_pid",
656           "Cisco OUI PID", FT_UINT16, BASE_HEX);
657         xid_subdissector_table = register_dissector_table("llc.xid_dsap",
658           "LLC XID SAP", FT_UINT8, BASE_HEX);
659         nortel_subdissector_table = register_dissector_table("llc.nortel_pid",
660           "Nortel OUI PID", FT_UINT16, BASE_HEX);
661
662         register_dissector("llc", dissect_llc, proto_llc);
663 }
664
665 void
666 proto_reg_handoff_llc(void)
667 {
668         dissector_handle_t llc_handle;
669
670         /*
671          * Get handles for the BPDU, Ethernet, FDDI, and Token Ring
672          * dissectors.
673          */
674         bpdu_handle = find_dissector("bpdu");
675         eth_handle = find_dissector("eth");
676         fddi_handle = find_dissector("fddi");
677         tr_handle = find_dissector("tr");
678         data_handle = find_dissector("data");
679
680         llc_handle = find_dissector("llc");
681         dissector_add("wtap_encap", WTAP_ENCAP_ATM_RFC1483, llc_handle);
682         /* RFC 2043 */
683         dissector_add("ppp.protocol", PPP_LLC, llc_handle);
684         /* RFC 2353 */
685         dissector_add("udp.port", UDP_PORT_LLC1, llc_handle);
686         dissector_add("udp.port", UDP_PORT_LLC2, llc_handle);
687         dissector_add("udp.port", UDP_PORT_LLC3, llc_handle);
688         dissector_add("udp.port", UDP_PORT_LLC4, llc_handle);
689         dissector_add("udp.port", UDP_PORT_LLC5, llc_handle);
690         /* IP-over-FC when we have the full FC frame */
691         dissector_add("fc.ftype", FC_FTYPE_IP, llc_handle);
692
693         /*
694          * BACNET-over-ARCNET is really BACNET-over-802.2 LLC-over-ARCNET,
695          * apparently.
696          */
697         dissector_add("arcnet.protocol_id", ARCNET_PROTO_BACNET, llc_handle);
698 }