bd2c791d999b08e6fceb7f2ba3231e4096a18b62
[obnox/wireshark/wip.git] / packet-ans.c
1 /* packet-ans.c
2  * Routines for Intel ANS probe dissection
3  *
4  * $Id$
5  *
6  * Ethereal - Network traffic analyzer
7  * By Gerald Combs <gerald@ethereal.com>
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 <epan/proto.h>
54 #include <etypes.h>
55
56 /* Initialize the protocol and registered fields */
57 static int proto_ans        = -1;
58
59 static int hf_ans_app_id    = -1;
60 static int hf_ans_rev_id    = -1;
61 static int hf_ans_seq_num   = -1;
62 static int hf_ans_sender_id = -1;
63 static int hf_ans_team_id   = -1;
64
65 /* Initialize the subtree pointers */
66 static gint ett_ans = -1;
67
68 /* Code to actually dissect the packets */
69 static void
70 dissect_ans(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
71 {
72         proto_item  *ti;
73         proto_tree  *ans_tree = NULL;
74         guint16      sender_id;
75         guint32      seq_num;
76         gchar        team_id[6];
77
78         if (check_col(pinfo->cinfo, COL_PROTOCOL))
79                 col_set_str(pinfo->cinfo, COL_PROTOCOL, "Intel ANS probe");
80
81         if (check_col(pinfo->cinfo, COL_INFO)) {
82                 col_clear(pinfo->cinfo, COL_INFO);
83                 
84                 seq_num = tvb_get_ntohl(tvb, 4);
85                 sender_id = tvb_get_ntohs(tvb, 8);
86                 tvb_memcpy(tvb, team_id, 10, 6);
87
88                 col_append_fstr(pinfo->cinfo, COL_INFO, "Sequence: %u, Sender ID %u, Team ID %s",
89                         seq_num, sender_id, ether_to_str(team_id));
90         }
91
92         if (tree) {
93                 ti = proto_tree_add_item(tree, proto_ans, tvb, 0, -1, FALSE);
94                 ans_tree = proto_item_add_subtree(ti, ett_ans);
95
96                 proto_tree_add_item(ans_tree, hf_ans_app_id, tvb, 0, 2, FALSE);
97                 proto_tree_add_item(ans_tree, hf_ans_rev_id, tvb, 2, 2, FALSE);
98                 proto_tree_add_item(ans_tree, hf_ans_seq_num, tvb, 4, 4, FALSE);
99                 proto_tree_add_item(ans_tree, hf_ans_sender_id, tvb, 8, 2, FALSE);
100                 proto_tree_add_item(ans_tree, hf_ans_team_id, tvb, 10, 6, FALSE);
101         }
102 }
103
104
105 void
106 proto_register_ans(void)
107 {
108         static hf_register_info hf[] = {
109                 { &hf_ans_app_id,
110                         { "Application ID", "ans.app_id",
111                                 FT_UINT16, BASE_HEX, NULL, 0,
112                                 "Intel ANS Application ID", HFILL }
113                 },
114                 { &hf_ans_rev_id,
115                         { "Revision ID", "ans.rev_id",
116                                 FT_UINT16, BASE_HEX, NULL, 0,
117                                 "Intel ANS Revision ID", HFILL }
118                 },
119                 { &hf_ans_seq_num,
120                         { "Sequence Number", "ans.seq_num",
121                                 FT_UINT32, BASE_DEC, NULL, 0,
122                                 "Intel ANS Sequence Number", HFILL }
123                 },
124                 { &hf_ans_sender_id,
125                         { "Sender ID", "ans.sender_id",
126                                 FT_UINT16, BASE_DEC, NULL, 0,
127                                 "Intel ANS Sender ID", HFILL }
128                 },
129                 { &hf_ans_team_id,
130                         { "Team ID", "ans.team_id",
131                                 FT_ETHER, BASE_HEX, NULL, 0,
132                                 "Intel ANS Team ID", HFILL }
133                 },
134         };
135
136         static gint *ett[] = {
137                 &ett_ans,
138         };
139
140         proto_ans = proto_register_protocol("Intel ANS probe", "ANS", "ans");
141         proto_register_field_array(proto_ans, hf, array_length(hf));
142         proto_register_subtree_array(ett, array_length(ett));
143 }
144
145
146 void
147 proto_reg_handoff_ans(void)
148 {
149         dissector_handle_t ans_handle;
150
151         ans_handle = create_dissector_handle(dissect_ans, proto_ans);
152         dissector_add("ethertype", ETHERTYPE_INTEL_ANS, ans_handle);
153 }