f837f38deb5a3aa3d9ccf59616cf082657f66312
[obnox/wireshark/wip.git] / epan / dissectors / packet-ans.c
1 /* packet-ans.c
2  * Routines for Intel ANS probe dissection
3  *
4  * $Id$
5  *
6  * Wireshark - Network traffic analyzer
7  * By Gerald Combs <gerald@wireshark.org>
8  * Copyright 2003 Gerald Combs
9  *
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU General Public License
12  * as published by the Free Software Foundation; either version 2
13  * of the License, or (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23  *
24  * The following information was graciously provided by Intel:
25  * Offset    Size (bytes)    Contents
26  * 0         6               Destination Broadcast probes: {FF,FF,FF,FF,FF,FF}
27  *                           Multicast probes: {01,AA,00,00,00,00}
28  * 6         6               Source Matches the CurrentMACAddress of the
29  *                           adapter sending the probe.
30  * 8         2               Type Network order is 0x886D, Intel's reserved
31  *                           packet type.
32  * 10 (0)    2               ApplicationID Network order is 0x0001, identifies
33  *                           it as fault tolerance probe.
34  * 12 (2)    2               RevID Network order, identifies the revision id
35  *                           of Teaming software.
36  * 16 (4)    4               ProbeSequenceNumber Ascending sequence number
37  *                           that identifies the current probing cycle.
38  * 20 (8)    2               SenderID Unique ID within a team identifying
39  *                           the member that originally sent the probe.
40  * 22 (10)   6               TeamID Unique ID identifying the team in charge
41  *                           of this probe.
42  * 28        Padding         Reserved
43  *
44  */
45
46 #ifdef HAVE_CONFIG_H
47 # include "config.h"
48 #endif
49
50 #include <glib.h>
51
52 #include <epan/packet.h>
53 #include <etypes.h>
54
55 /* Initialize the protocol and registered fields */
56 static int proto_ans        = -1;
57
58 static int hf_ans_app_id    = -1;
59 static int hf_ans_rev_id    = -1;
60 static int hf_ans_seq_num   = -1;
61 static int hf_ans_sender_id = -1;
62 static int hf_ans_team_id   = -1;
63
64 /* Initialize the subtree pointers */
65 static gint ett_ans = -1;
66
67 /* Code to actually dissect the packets */
68 static void
69 dissect_ans(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
70 {
71         proto_item  *ti;
72         proto_tree  *ans_tree = NULL;
73         guint16      sender_id;
74         guint32      seq_num;
75         guint8       team_id[6];
76
77         col_set_str(pinfo->cinfo, COL_PROTOCOL, "Intel ANS probe");
78
79         seq_num = tvb_get_ntohl(tvb, 4);
80         sender_id = tvb_get_ntohs(tvb, 8);
81         tvb_memcpy(tvb, team_id, 10, 6);
82
83         col_add_fstr(pinfo->cinfo, COL_INFO, "Sequence: %u, Sender ID %u, Team ID %s",
84                 seq_num, sender_id, ether_to_str(team_id));
85
86         if (tree) {
87                 ti = proto_tree_add_item(tree, proto_ans, tvb, 0, -1, ENC_BIG_ENDIAN);
88                 ans_tree = proto_item_add_subtree(ti, ett_ans);
89
90                 proto_tree_add_item(ans_tree, hf_ans_app_id, tvb, 0, 2, ENC_BIG_ENDIAN);
91                 proto_tree_add_item(ans_tree, hf_ans_rev_id, tvb, 2, 2, ENC_BIG_ENDIAN);
92                 proto_tree_add_item(ans_tree, hf_ans_seq_num, tvb, 4, 4, ENC_BIG_ENDIAN);
93                 proto_tree_add_item(ans_tree, hf_ans_sender_id, tvb, 8, 2, ENC_BIG_ENDIAN);
94                 proto_tree_add_item(ans_tree, hf_ans_team_id, tvb, 10, 6, ENC_NA);
95         }
96 }
97
98
99 void
100 proto_register_ans(void)
101 {
102         static hf_register_info hf[] = {
103                 { &hf_ans_app_id,
104                         { "Application ID", "ans.app_id",
105                                 FT_UINT16, BASE_HEX, NULL, 0,
106                                 "Intel ANS Application ID", HFILL }
107                 },
108                 { &hf_ans_rev_id,
109                         { "Revision ID", "ans.rev_id",
110                                 FT_UINT16, BASE_HEX, NULL, 0,
111                                 "Intel ANS Revision ID", HFILL }
112                 },
113                 { &hf_ans_seq_num,
114                         { "Sequence Number", "ans.seq_num",
115                                 FT_UINT32, BASE_DEC, NULL, 0,
116                                 "Intel ANS Sequence Number", HFILL }
117                 },
118                 { &hf_ans_sender_id,
119                         { "Sender ID", "ans.sender_id",
120                                 FT_UINT16, BASE_DEC, NULL, 0,
121                                 "Intel ANS Sender ID", HFILL }
122                 },
123                 { &hf_ans_team_id,
124                         { "Team ID", "ans.team_id",
125                                 FT_ETHER, BASE_NONE, NULL, 0,
126                                 "Intel ANS Team ID", HFILL }
127                 },
128         };
129
130         static gint *ett[] = {
131                 &ett_ans,
132         };
133
134         proto_ans = proto_register_protocol("Intel ANS probe", "ANS", "ans");
135         proto_register_field_array(proto_ans, hf, array_length(hf));
136         proto_register_subtree_array(ett, array_length(ett));
137 }
138
139
140 void
141 proto_reg_handoff_ans(void)
142 {
143         dissector_handle_t ans_handle;
144
145         ans_handle = create_dissector_handle(dissect_ans, proto_ans);
146         dissector_add_uint("ethertype", ETHERTYPE_INTEL_ANS, ans_handle);
147 }
148