Clean up white space.
[obnox/wireshark/wip.git] / packet-mip.c
1 /* packet-mip.c
2  * Routines for Mobile IP dissection
3  * Copyright 2000, Stefan Raab <Stefan.Raab@nextel.com>
4  *
5  * $Id: packet-mip.c,v 1.11 2001/01/03 16:41:06 gram Exp $
6  *
7  * Ethereal - Network traffic analyzer
8  * By Gerald Combs <gerald@unicom.net>
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 <stdio.h>
31 #include <stdlib.h>
32
33 #ifdef HAVE_SYS_TYPES_H
34 # include <sys/types.h>
35 #endif
36
37 #ifdef HAVE_NETINET_IN_H
38 # include <netinet/in.h>
39 #endif
40
41 #include <string.h>
42 #include <glib.h>
43
44 #ifdef NEED_SNPRINTF_H
45 # include "snprintf.h"
46 #endif
47
48 #include "packet.h"
49
50 /* Initialize the protocol and registered fields */
51 static int proto_mip = -1;
52 static int hf_mip_type = -1;
53 static int hf_mip_s = -1;
54 static int hf_mip_b = -1;
55 static int hf_mip_d = -1;
56 static int hf_mip_m = -1;
57 static int hf_mip_g = -1;
58 static int hf_mip_v = -1;
59 static int hf_mip_code = -1;
60 static int hf_mip_life = -1;
61 static int hf_mip_homeaddr = -1;
62 static int hf_mip_haaddr = -1;
63 static int hf_mip_coa = -1;
64 static int hf_mip_ident = -1;
65
66 /* Initialize the subtree pointers */
67 static gint ett_mip = -1;
68
69 /* Port used for Mobile IP */
70 #define UDP_PORT_MIP    434
71
72
73 /*
74 struct mip_packet{
75   unsigned char type;
76 };
77
78
79 struct mip_request_packet{
80   unsigned char type;
81   unsigned char code;
82   unsigned char life[2];
83   unsigned char homeaddr[4];
84   unsigned char haaddr[4];
85   unsigned char coa[4];
86   unsigned char ident[8];
87
88 };
89
90
91 struct mip_reply_packet{
92   unsigned char type;
93   unsigned char code;
94   unsigned char life[2];
95   unsigned char homeaddr[4];
96   unsigned char haaddr[4];
97   unsigned char ident[8];
98
99 };
100 */
101
102 static const value_string mip_types[] = {
103   {1, "Registration Request"},
104   {3, "Registration Reply"},
105   {0, NULL},
106 };
107
108 static const value_string mip_reply_codes[]= {
109   {0, "Registration Accepted"},
110   {1, "Registration Accepted, no simul bindings"},
111   {64, "Registration Denied by FA, unspecified reason"},
112   {65, "Registration Denied by FA, Admin Prohibit"},
113   {66, "Registration Denied by FA, Insufficient Resources"},
114   {67, "Registration Denied by FA, MN failed Auth"},
115   {68, "Registration Denied by FA, HA failed Auth"},
116   {69, "Registration Denied by FA, Lifetime to long"},
117   {70, "Registration Denied by FA, Poorly Formed Request"},
118   {71, "Registration Denied by FA, Poorly Formed Reply"},
119   {72, "Registration Denied by FA, encap unavailable"},
120   {73, "Registration Denied by FA, VJ unavailable"},
121   {80, "Registration Denied by FA, Home net unreachable"},
122   {81, "Registration Denied by FA, Home Agent host unreachable"},
123   {82, "Registration Denied by FA, Home Agent port unreachable"},
124   {88, "Registration Denied by FA, Home Agent unreachable"},
125   {128, "Registration Denied by HA, unspecified"},
126   {129, "Registration Denied by HA, Admin Prohibit"},
127   {130, "Registration Denied by HA, insufficient resources"},
128   {131, "Registration Denied by HA, MN failed Auth"},
129   {132, "Registration Denied by HA, FA failed Auth"},
130   {133, "Registration Denied by HA, registration ID Mismatch"},
131   {134, "Registration Denied by HA, poorly formed request"},
132   {135, "Registration Denied by HA, too many simul bindings"},
133   {136, "Registration Denied by HA, unknown HA address"},
134   {0, NULL},
135 };
136
137 /* Code to actually dissect the packets */
138 static void
139 dissect_mip(const u_char *pd, int offset, frame_data *fd, proto_tree *tree)
140 {
141
142 /* Set up structures we will need to add the protocol subtree and manage it */
143         proto_item      *ti;
144         proto_tree      *mip_tree;
145         guint8          type, code;
146
147         /* Make our own tvb until the function call includes one */
148         tvbuff_t        *tvb;
149         packet_info     *pinfo = &pi;
150         tvb = tvb_create_from_top(offset);
151
152         CHECK_DISPLAY_AS_DATA(proto_mip, tvb, pinfo, tree);
153
154 /* Make entries in Protocol column and Info column on summary display */
155
156         pinfo->current_proto = "Mobile IP";
157         if (check_col(fd, COL_PROTOCOL)) 
158                 col_set_str(fd, COL_PROTOCOL, "mip");
159     
160         type = tvb_get_guint8(tvb, 0);
161
162         if (type==1) {
163
164           if (check_col(fd, COL_INFO)) 
165                  col_set_str(fd, COL_INFO, "Mobile IP Registration Request");
166         
167           if (tree) {
168                  ti = proto_tree_add_item(tree, proto_mip, tvb, 0, tvb_length(tvb), FALSE);
169                  mip_tree = proto_item_add_subtree(ti, ett_mip);
170                  proto_tree_add_int(mip_tree, hf_mip_type, tvb, 0, 1, type);
171
172                  code = tvb_get_guint8(tvb, 1);
173                  proto_tree_add_boolean(mip_tree, hf_mip_s, tvb, 1, 1, code);
174                  proto_tree_add_boolean(mip_tree, hf_mip_b, tvb, 1, 1, code);
175                  proto_tree_add_boolean(mip_tree, hf_mip_d, tvb, 1, 1, code);
176                  proto_tree_add_boolean(mip_tree, hf_mip_m, tvb, 1, 1, code);
177                  proto_tree_add_boolean(mip_tree, hf_mip_g, tvb, 1, 1, code);
178                  proto_tree_add_boolean(mip_tree, hf_mip_v, tvb, 1, 1, code);
179
180                  proto_tree_add_int(mip_tree, hf_mip_life, tvb, 2, 2, tvb_get_ntohs(tvb, 2));
181                  proto_tree_add_ipv4(mip_tree, hf_mip_homeaddr, tvb, 4, 4, tvb_get_letohl(tvb, 4));
182                  proto_tree_add_ipv4(mip_tree, hf_mip_haaddr, tvb, 8, 4, tvb_get_letohl(tvb, 8));
183                  proto_tree_add_ipv4(mip_tree, hf_mip_coa, tvb, 12, 4, tvb_get_letohl(tvb, 12));
184                  proto_tree_add_bytes(mip_tree, hf_mip_ident, tvb, 16, 8, tvb_get_ptr(tvb, 16, 8));
185           }
186         }
187
188
189         if (type==3){
190           if (check_col(fd, COL_INFO)) 
191                  col_set_str(fd, COL_INFO, "Mobile IP Registration Reply");
192
193           if (tree) {
194                  ti = proto_tree_add_item(tree, proto_mip, tvb, 0, tvb_length(tvb), FALSE);
195                  mip_tree = proto_item_add_subtree(ti, ett_mip);
196                  proto_tree_add_int(mip_tree, hf_mip_type, tvb, 0, 1, type);
197
198                  code = tvb_get_guint8(tvb, 1);
199                  proto_tree_add_uint(mip_tree, hf_mip_code, tvb, 1, 1, code);
200                  proto_tree_add_int(mip_tree, hf_mip_life, tvb, 2, 2, tvb_get_ntohs(tvb, 2));
201                  proto_tree_add_ipv4(mip_tree, hf_mip_homeaddr, tvb, 4, 4, tvb_get_letohl(tvb, 4));
202                  proto_tree_add_ipv4(mip_tree, hf_mip_haaddr, tvb, 8, 4, tvb_get_letohl(tvb, 8));
203                  proto_tree_add_bytes(mip_tree, hf_mip_ident, tvb, 12, 8, tvb_get_ptr(tvb, 12, 8));
204           }
205         }
206 }
207
208 /* Register the protocol with Ethereal */
209 void proto_register_mip(void)
210 {                 
211
212 /* Setup list of header fields */
213         static hf_register_info hf[] = {
214           { &hf_mip_type,
215                  { "Message Type",           "mip.type",
216                         FT_INT8, BASE_DEC, VALS(mip_types), 0,          
217                         "Mobile IP Message type." }
218           },
219           { &hf_mip_s,
220                  {"Simultaneous Bindings",           "mip.s",
221                    FT_BOOLEAN, 8, NULL, 128,          
222                    "Simultaneous Bindings Allowed" }
223           },
224           { &hf_mip_b,
225                  {"Broadcast Datagrams",           "mip.b",
226                    FT_BOOLEAN, 8, NULL, 64,          
227                    "Broadcast Datagrams requested" }
228           },
229           { &hf_mip_d,
230                  { "Co-lcated Care-of Address",           "mip.d",
231                    FT_BOOLEAN, 8, NULL, 32,          
232                    "MN using Co-located Care-of address" }
233           },
234           { &hf_mip_m,
235                  {"Minimal Encapsulation",           "mip.m",
236                    FT_BOOLEAN, 8, NULL, 16,          
237                    "MN wants Minimal encapsulation" }
238           },
239           { &hf_mip_g,
240                  {"GRE",           "mip.g",
241                    FT_BOOLEAN, 8, NULL, 8,          
242                    "MN wants GRE encapsulation" }
243           },
244           { &hf_mip_v,
245                  { "Van Jacobson",           "mip.v",
246                    FT_BOOLEAN, 8, NULL, 4,          
247                    "Van Jacobson" }
248           },
249           { &hf_mip_code,
250                  { "Reply Code",           "mip.code",
251                         FT_UINT8, BASE_DEC, VALS(mip_reply_codes), 0,          
252                         "Mobile IP Reply code." }
253           },
254           { &hf_mip_life,
255                  { "Lifetime",           "mip.life",
256                         FT_INT16, BASE_DEC, NULL, 0,          
257                         "Mobile IP Lifetime." }
258           },
259           { &hf_mip_homeaddr,
260                  { "Home Address",           "mip.homeaddr",
261                         FT_IPv4, BASE_NONE, NULL, 0,          
262                         "Mobile Node's home address." }
263           },
264           
265           { &hf_mip_haaddr,
266                  { "Home Agent",           "mip.haaddr",
267                         FT_IPv4, BASE_NONE, NULL, 0,          
268                         "Home agent IP Address." }
269           },
270           { &hf_mip_coa,
271                  { "Care of Address",           "mip.coa",
272                         FT_IPv4, BASE_NONE, NULL, 0,          
273                         "Care of Address." }
274           },
275           { &hf_mip_ident,
276                  { "Identification",           "mip.ident",
277                         FT_BYTES, BASE_NONE, NULL, 0,          
278                         "MN Identification." }
279           },
280
281
282
283
284         };
285
286 /* Setup protocol subtree array */
287         static gint *ett[] = {
288                 &ett_mip,
289         };
290
291 /* Register the protocol name and description */
292         proto_mip = proto_register_protocol("Mobile IP", "Mobile IP", "mip");
293
294 /* Required function calls to register the header fields and subtrees used */
295         proto_register_field_array(proto_mip, hf, array_length(hf));
296         proto_register_subtree_array(ett, array_length(ett));
297 };
298
299 void
300 proto_reg_handoff_mip(void)
301 {
302         old_dissector_add("udp.port", UDP_PORT_MIP, dissect_mip);
303 }