1 /* packet-ap1394.c
2  * Routines for Apple IP-over-IEEE 1394 packet disassembly
3  *
4  * Wireshark - Network traffic analyzer
5  * By Gerald Combs <gerald@wireshark.org>
6  * Copyright 1998 Gerald Combs
7  *
8  * SPDX-License-Identifier: GPL-2.0-or-later
9  */
10 
11 #include "config.h"
12 
13 #include <epan/packet.h>
14 #include <epan/capture_dissectors.h>
15 #include <wsutil/pint.h>
16 #include <epan/addr_resolv.h>
17 
18 #include <epan/etypes.h>
19 
20 void proto_register_ap1394(void);
21 void proto_reg_handoff_ap1394(void);
22 
23 static int proto_ap1394 = -1;
24 static int hf_ap1394_dst = -1;
25 static int hf_ap1394_src = -1;
26 static int hf_ap1394_type = -1;
27 
28 static gint ett_ap1394 = -1;
29 
30 static dissector_table_t ethertype_subdissector_table;
31 
32 static gboolean
capture_ap1394(const guchar * pd,int offset,int len,capture_packet_info_t * cpinfo,const union wtap_pseudo_header * pseudo_header)33 capture_ap1394(const guchar *pd, int offset, int len, capture_packet_info_t *cpinfo, const union wtap_pseudo_header *pseudo_header)
34 {
35   guint16    etype;
36 
37   if (!BYTES_ARE_IN_FRAME(offset, len, 18)) {
38     return FALSE;
39   }
40 
41   /* Skip destination and source addresses */
42   offset += 16;
43 
44   etype = pntoh16(&pd[offset]);
45   offset += 2;
46   return try_capture_dissector("ethertype", etype, pd, offset, len, cpinfo, pseudo_header);
47 }
48 
49 static int
dissect_ap1394(tvbuff_t * tvb,packet_info * pinfo,proto_tree * tree,void * data _U_)50 dissect_ap1394(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
51 {
52   proto_item *ti;
53   proto_tree *fh_tree = NULL;
54   guint16    etype;
55   tvbuff_t *next_tvb;
56 
57   col_set_str(pinfo->cinfo, COL_PROTOCOL, "IP/IEEE1394");
58   col_clear(pinfo->cinfo, COL_INFO);
59 
60   set_address_tvb(&pinfo->dl_src,   AT_EUI64, 8, tvb, 8);
61   copy_address_shallow(&pinfo->src, &pinfo->dl_src);
62   set_address_tvb(&pinfo->dl_dst,   AT_EUI64, 8, tvb, 0);
63   copy_address_shallow(&pinfo->dst, &pinfo->dl_dst);
64 
65   if (tree) {
66     ti = proto_tree_add_protocol_format(tree, proto_ap1394, tvb, 0, 18,
67                 "Apple IP-over-IEEE 1394, Src: %s, Dst: %s",
68                 address_to_str(pinfo->pool, &pinfo->src), address_to_str(pinfo->pool, &pinfo->dst));
69     fh_tree = proto_item_add_subtree(ti, ett_ap1394);
70     proto_tree_add_item(fh_tree, hf_ap1394_dst, tvb, 0, 8, ENC_NA);
71     proto_tree_add_item(fh_tree, hf_ap1394_src, tvb, 8, 8, ENC_NA);
72   }
73   etype = tvb_get_ntohs(tvb, 16);
74   proto_tree_add_uint(fh_tree, hf_ap1394_type, tvb, 16, 2, etype);
75   next_tvb = tvb_new_subset_remaining(tvb, 18);
76   if (!dissector_try_uint(ethertype_subdissector_table, etype, next_tvb,
77                 pinfo, tree))
78   {
79       call_data_dissector(next_tvb, pinfo, tree);
80   }
81   return tvb_captured_length(tvb);
82 }
83 
84 void
proto_register_ap1394(void)85 proto_register_ap1394(void)
86 {
87   static hf_register_info hf[] = {
88     { &hf_ap1394_dst,
89       { "Destination", "ap1394.dst", FT_BYTES, BASE_NONE,
90         NULL, 0x0, "Destination address", HFILL }},
91     { &hf_ap1394_src,
92       { "Source", "ap1394.src", FT_BYTES, BASE_NONE,
93         NULL, 0x0, "Source address", HFILL }},
94     /* registered here but handled in ethertype.c */
95     { &hf_ap1394_type,
96       { "Type", "ap1394.type", FT_UINT16, BASE_HEX,
97         VALS(etype_vals), 0x0, NULL, HFILL }},
98   };
99   static gint *ett[] = {
100     &ett_ap1394,
101   };
102 
103   proto_ap1394 = proto_register_protocol("Apple IP-over-IEEE 1394", "IP/IEEE1394", "ap1394");
104   proto_register_field_array(proto_ap1394, hf, array_length(hf));
105   proto_register_subtree_array(ett, array_length(ett));
106 }
107 
108 void
proto_reg_handoff_ap1394(void)109 proto_reg_handoff_ap1394(void)
110 {
111   dissector_handle_t ap1394_handle;
112   capture_dissector_handle_t ap1394_cap_handle;
113 
114   ethertype_subdissector_table = find_dissector_table("ethertype");
115 
116   ap1394_handle = create_dissector_handle(dissect_ap1394, proto_ap1394);
117   dissector_add_uint("wtap_encap", WTAP_ENCAP_APPLE_IP_OVER_IEEE1394, ap1394_handle);
118 
119   ap1394_cap_handle = create_capture_dissector_handle(capture_ap1394, proto_ap1394);
120   capture_dissector_add_uint("wtap_encap", WTAP_ENCAP_APPLE_IP_OVER_IEEE1394, ap1394_cap_handle);
121 }
122 
123 /*
124  * Editor modelines  -  https://www.wireshark.org/tools/modelines.html
125  *
126  * Local Variables:
127  * c-basic-offset: 2
128  * tab-width: 8
129  * indent-tabs-mode: nil
130  * End:
131  *
132  * ex: set shiftwidth=2 tabstop=8 expandtab:
133  * :indentSize=2:tabSize=8:noTabs=true:
134  */
135