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