Fix various typos and spelling errors (mostly in text strings)
[metze/wireshark/wip.git] / epan / dissectors / packet-nsrp.c
1 /* packet-nsrp.c
2  * Routines for the Juniper Netscreen Redundant Protocol (NSRP)
3  *
4  * Secfire <secfire@gmail.com>
5  *
6  * $Id$
7  *
8  * Wireshark - Network traffic analyzer
9  * By Gerald Combs <gerald@wireshark.org>
10  * Copyright 1998 Gerald Combs
11  *
12  *
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software
25  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
26  */
27
28 /* 
29  *
30  * NSRP update information can be found at www.juniper.net
31  *
32  *
33  *           
34  *    NSRP Packet Header is defined as follow:
35  *                  
36  *       1         2       3        4        5         6       7        8 
37  *   +--------+--------+--------+--------+--------+--------+--------+--------+
38  *   |Version | Type   |Clust ID|MSG Flag|     Length      |HA Port |Not Used|
39  *   +--------+--------+--------+--------+--------+--------+--------+--------+
40  *   |          Destination Unit         |             Source Unit           |
41  *   +--------+--------+--------+--------+--------+--------+--------+--------+
42  *
43  *
44  *
45  */
46
47 #ifdef HAVE_CONFIG_H
48 # include "config.h"
49 #endif
50
51 #include <glib.h>
52
53 #include <epan/packet.h>
54 #include <epan/etypes.h>
55
56 #define NSRP_MIN_LEN    32
57
58 /* Initialize the protocol and registered fields */
59 static int proto_nsrp       = -1;
60
61 static int hf_nsrp_version       = -1;
62 static int hf_nsrp_msg_type      = -1;
63 static int hf_nsrp_clust_id      = -1;
64 static int hf_nsrp_msg_flag      = -1;
65 static int hf_nsrp_len           = -1;
66 static int hf_nsrp_ha_port       = -1;
67 static int hf_nsrp_not_used      = -1;
68 static int hf_nsrp_dst_unit      = -1;
69 static int hf_nsrp_src_unit      = -1;
70 static int hf_nsrp_msgtype       = -1;
71 static int hf_nsrp_wst_group     = -1;
72 static int hf_nsrp_hst_group     = -1;
73 static int hf_nsrp_msgflag     = -1;
74 static int hf_nsrp_authflag      = -1;
75 static int hf_nsrp_priority      = -1;
76 static int hf_nsrp_dummy         = -1;
77 static int hf_nsrp_authchecksum  = -1;
78 static int hf_nsrp_ifnum         = -1;
79
80
81 /* Dada defined for HA Message */
82 static int hf_nsrp_msglen      = -1;
83 static int hf_nsrp_encflag      = -1;
84 static int hf_nsrp_notused = -1;
85
86 static int hf_nsrp_total_size = -1;
87
88 static int hf_nsrp_ns = -1;
89 static int hf_nsrp_nr = -1;
90
91 static int hf_nsrp_no_used = -1;
92 static int hf_nsrp_checksum = -1;
93
94 static int hf_nsrp_data = -1;
95
96
97 static const value_string nsrp_msg_type_vals[] = {
98         { 0x01, "HA MESSAGE" },
99         { 0x02, "MNG MESSAGE" },
100         { 0x03, "DADA MESSAGE" },
101         { 0,                    NULL }
102 };
103
104 static const value_string nsrp_msgtype_vals[] = {
105         { 0x01, "CREATE SESSION" },
106         { 0x02, "CLOSE SESSION" },
107         { 0x03, "CHANG SESSION" },
108         { 0x04, "CREATE SP SESSION" },
109         { 0x05, "SYS CONFIG" },
110         { 0x06, "FILE SYS" },
111         { 0x07, "CMD WEB" },
112         { 0x08, "SAVE SLAVE" },
113         { 0x09, "VPN SPI" },
114         { 0x0a, "ARP" },
115         { 0x0b, "HEALTH CHECK" },
116         { 0x0c, "EMW DATA" },
117         { 0x0d, "INVITE SYNC" },
118         { 0x0e, "DOWNLOAD CONFIG" },
119         { 0x0f, "L2TP TUNL CREATE" },
120         { 0x10, "L2TP TUNL DELETE" },
121         { 0x11, "L2TP CALL CREATE" },
122         { 0x12, "L2TP CALL DELETE" },
123         { 0x13, "PKI SYNC" },
124         { 0x14, "VPN SEQ" },
125         { 0x15, "MAX" },
126         { 0,                    NULL }
127 };
128
129 static const value_string nsrp_flag_vals[] = {
130         { 0x80, "ENCRPT MESSAGE" },
131         { 0x40, "CLOSE SESSION" },
132         { 0x20, "CHANG SESSION" },
133         { 0x10, "CREATE SP SESSION" },
134         { 0x08, "SYS CONFIG" },
135         { 0x04, "FILE SYS" },
136         { 0x02, "CMD WEB" },
137         { 0,                    NULL }
138 };
139
140 static const value_string nsrp_encflag_vals[] = {
141         { 0xf0, "ENCRYPT METHOD MASK" },
142         { 0x0f, "ENCRYPT PAD BIT MASK" },
143         { 0,                    NULL }
144 };
145
146
147 /* Initialize the subtree pointers */
148 static gint ett_nsrp = -1;
149
150 /* Code to actually dissect the packets */
151 static void
152 dissect_nsrp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
153 {
154     proto_item  *ti;
155     proto_tree  *nsrp_tree = NULL;
156     gint        offset = 0;
157     guint8      msgtype = 0;
158
159     if (check_col(pinfo->cinfo, COL_PROTOCOL))
160                         col_set_str(pinfo->cinfo, COL_PROTOCOL, "NSRP");
161
162     if (check_col(pinfo->cinfo, COL_INFO))
163     {
164                         col_clear(pinfo->cinfo, COL_INFO);
165                         col_set_str(pinfo->cinfo, COL_INFO, "NSRP Protocol");
166                 }
167
168     if (tree) {
169                         ti = proto_tree_add_item(tree, proto_nsrp, tvb, 0, -1, FALSE);
170                         nsrp_tree = proto_item_add_subtree(ti, ett_nsrp);
171                         
172                         
173                         proto_tree_add_item(nsrp_tree, hf_nsrp_version, tvb, offset, 1, FALSE);
174                         offset += 1;
175
176                         msgtype = tvb_get_guint8(tvb, offset);
177                         proto_tree_add_item(nsrp_tree, hf_nsrp_msg_type, tvb, offset, 1, FALSE);
178                         offset += 1;
179                 
180                         proto_tree_add_item(nsrp_tree, hf_nsrp_clust_id, tvb, offset, 1, FALSE);
181                         offset += 1;
182                         
183                         proto_tree_add_item(nsrp_tree, hf_nsrp_msg_flag, tvb, offset, 1, FALSE);
184                         offset += 1;
185
186                         proto_tree_add_item(nsrp_tree, hf_nsrp_len, tvb, offset, 2, FALSE);
187                         offset += 2;
188                 
189                         proto_tree_add_item(nsrp_tree, hf_nsrp_ha_port, tvb, offset, 1, FALSE);
190                         offset += 1;
191                         
192                         proto_tree_add_item(nsrp_tree, hf_nsrp_not_used, tvb, offset, 1, FALSE);
193                         offset += 1;
194
195                         proto_tree_add_item(nsrp_tree, hf_nsrp_dst_unit, tvb, offset, 4, FALSE);
196                         offset += 4;
197
198                         proto_tree_add_item(nsrp_tree, hf_nsrp_src_unit, tvb, offset, 4, FALSE);
199                         offset += 4;
200                 }
201                 
202 /*
203  *
204  *
205  *    NSRP HA Packet is defined as follow:
206  * 
207  *       1         2       3        4        5         6       7        8 
208  *   +--------+--------+--------+--------+--------+--------+--------+--------+
209  *   | Type   |WstGroup|HstGroup|MSG Flag|     Length      |Enc Flag|Not Used|
210  *   +--------+--------+--------+--------+--------+--------+--------+--------+
211  *   |            Total Size             |        NS       |        NR       |
212  *   +--------+--------+--------+--------+--------+--------+--------+--------+
213  *   |     No Used     |    Checksum     |              Data                 |
214  *   +--------+--------+--------+--------+-----------------------------------+
215  *
216  *
217  */
218
219                 if ( msgtype == 0x00 ) {
220                         
221                         proto_tree_add_item(nsrp_tree, hf_nsrp_msgtype, tvb, offset, 1, FALSE);
222                         offset += 1;
223
224                         proto_tree_add_item(nsrp_tree, hf_nsrp_wst_group, tvb, offset, 1, FALSE);
225                         offset += 1;
226
227                         proto_tree_add_item(nsrp_tree, hf_nsrp_hst_group, tvb, offset, 1, FALSE);
228                         offset += 1;
229
230                         proto_tree_add_item(nsrp_tree, hf_nsrp_msgflag, tvb, offset, 1, FALSE);
231                         offset += 1;
232                 
233                         proto_tree_add_item(nsrp_tree, hf_nsrp_msglen, tvb, offset, 2, FALSE);
234                         offset += 2;
235                         
236                         proto_tree_add_item(nsrp_tree, hf_nsrp_encflag, tvb, offset, 1, FALSE);
237                         offset += 1;
238
239                         proto_tree_add_item(nsrp_tree, hf_nsrp_not_used, tvb, offset, 1, FALSE);
240                         offset += 1;
241
242                         proto_tree_add_item(nsrp_tree, hf_nsrp_total_size, tvb, offset, 4, FALSE);
243                         offset += 4;
244                 
245                         proto_tree_add_item(nsrp_tree, hf_nsrp_ns, tvb, offset, 2, FALSE);
246                         offset += 2;
247                         
248                         proto_tree_add_item(nsrp_tree, hf_nsrp_nr, tvb, offset, 2, FALSE);
249                         offset += 2;
250
251                         proto_tree_add_item(nsrp_tree, hf_nsrp_no_used, tvb, offset, 2, FALSE);
252                         offset += 2;
253                 
254                         proto_tree_add_item(nsrp_tree, hf_nsrp_checksum, tvb, offset, 2, FALSE);
255                         offset += 2;
256                         
257                         proto_tree_add_item(nsrp_tree, hf_nsrp_data, tvb, offset, -1, FALSE);
258                         
259     }
260     
261 /*
262  *  
263  *    NSRP MNG Packet is defined as follow:
264  * 
265  *       1         2       3        4        5         6       7        8 
266  *   +--------+--------+--------+--------+--------+--------+--------+--------+
267  *   | Type   |WstGroup|HstGroup|MSG Flag|     Length      |AuthFlag|Not Used|
268  *   +--------+--------+--------+--------+--------+--------+--------+--------+
269  *   |Priority+ Dummy  +   Auth CheckSum +                Data               |
270  *   +--------+--------+--------+--------+-----------------------------------+
271  *  
272  *
273  */
274
275                 if ( msgtype == 0x02 ) {
276                         
277                         proto_tree_add_item(nsrp_tree, hf_nsrp_msgtype, tvb, offset, 1, FALSE);
278                         offset += 1;
279
280                         proto_tree_add_item(nsrp_tree, hf_nsrp_wst_group, tvb, offset, 1, FALSE);
281                         offset += 1;
282
283                         proto_tree_add_item(nsrp_tree, hf_nsrp_hst_group, tvb, offset, 1, FALSE);
284                         offset += 1;
285
286                         proto_tree_add_item(nsrp_tree, hf_nsrp_msgflag, tvb, offset, 1, FALSE);
287                         offset += 1;
288                 
289                         proto_tree_add_item(nsrp_tree, hf_nsrp_msglen, tvb, offset, 2, FALSE);
290                         offset += 2;
291                         
292                         proto_tree_add_item(nsrp_tree, hf_nsrp_authflag, tvb, offset, 1, FALSE);
293                         offset += 1;
294
295                         proto_tree_add_item(nsrp_tree, hf_nsrp_not_used, tvb, offset, 1, FALSE);
296                         offset += 1;
297
298                         proto_tree_add_item(nsrp_tree, hf_nsrp_priority, tvb, offset, 1, FALSE);
299                         offset += 1;
300                 
301                         proto_tree_add_item(nsrp_tree, hf_nsrp_dummy, tvb, offset, 1, FALSE);
302                         offset += 1;
303                         
304                         proto_tree_add_item(nsrp_tree, hf_nsrp_authchecksum, tvb, offset, 2, FALSE);
305                         offset += 2;
306
307                         proto_tree_add_item(nsrp_tree, hf_nsrp_data, tvb, offset, -1, FALSE);
308                         
309     }
310     
311         
312     
313     
314 /*   
315  *    NSRP DATA Packet is defined as follow:
316  * 
317  *       1         2       3        4        5         6       7        8 
318  *   +--------+--------+--------+--------+--------+--------+--------+--------+
319  *   | Type   |WstGroup|HstGroup|MSG Flag|     Length      | Ifnum  |Not Used|
320  *   +--------+--------+--------+--------+--------+--------+--------+--------+
321  *   |            Total Size             |                Data               |
322  *   +--------+--------+--------+--------+-----------------------------------+
323  *
324  *
325  */
326    if ( msgtype == 0x03 ) {
327                         
328                         proto_tree_add_item(nsrp_tree, hf_nsrp_msgtype, tvb, offset, 1, FALSE);
329                         offset += 1;
330
331                         proto_tree_add_item(nsrp_tree, hf_nsrp_wst_group, tvb, offset, 1, FALSE);
332                         offset += 1;
333
334                         proto_tree_add_item(nsrp_tree, hf_nsrp_hst_group, tvb, offset, 1, FALSE);
335                         offset += 1;
336
337                         proto_tree_add_item(nsrp_tree, hf_nsrp_msgflag, tvb, offset, 1, FALSE);
338                         offset += 1;
339                 
340                         proto_tree_add_item(nsrp_tree, hf_nsrp_msglen, tvb, offset, 2, FALSE);
341                         offset += 2;
342                         
343                         proto_tree_add_item(nsrp_tree, hf_nsrp_ifnum, tvb, offset, 1, FALSE);
344                         offset += 1;
345
346                         proto_tree_add_item(nsrp_tree, hf_nsrp_not_used, tvb, offset, 1, FALSE);
347                         offset += 1;
348
349                         proto_tree_add_item(nsrp_tree, hf_nsrp_total_size, tvb, offset, 4, FALSE);
350                         offset += 4;
351                 
352                         proto_tree_add_item(nsrp_tree, hf_nsrp_data, tvb, offset, -1, FALSE);
353                         
354     }
355
356 }
357
358
359 void
360 proto_register_nsrp(void)
361 {
362
363     static hf_register_info hf[] = {
364         { &hf_nsrp_version,
365           { "Version", "nsrp.version",
366             FT_UINT8, BASE_DEC, NULL, 0,
367             "NSRP Version", HFILL }
368         },
369                 { &hf_nsrp_msg_type,
370           { "Type", "nsrp.type",
371             FT_UINT8, BASE_DEC, nsrp_msg_type_vals, 0,
372             "NSRP Message Type", HFILL }
373         },
374                 { &hf_nsrp_clust_id,
375           { "Clust ID", "nsrp.clustid",
376             FT_UINT8, BASE_DEC, NULL, 0,
377             "NSRP CLUST ID", HFILL }
378         },
379                 { &hf_nsrp_msg_flag,
380           { "Flag", "nsrp.flag",
381             FT_UINT8, BASE_DEC, NULL, 0,
382             "NSRP FLAG", HFILL }
383         },
384         { &hf_nsrp_len,
385           { "Length", "nsrp.length",
386             FT_UINT16, BASE_DEC, NULL, 0,
387             "NSRP Length", HFILL }
388         },
389                 { &hf_nsrp_ha_port,
390           { "Port", "nsrp.haport",
391             FT_UINT8, BASE_DEC, NULL, 0,
392             "NSRP HA Port", HFILL }
393         },
394                 { &hf_nsrp_not_used,
395           { "Not used", "nsrp.notused",
396             FT_UINT8, BASE_DEC, NULL, 0,
397             "NOT USED", HFILL }
398         },
399                 { &hf_nsrp_dst_unit,
400           { "Destination", "nsrp.dst",
401             FT_UINT32, BASE_DEC, NULL, 0,
402             "DESTINATION UNIT INFORMATION", HFILL }
403         },
404         { &hf_nsrp_src_unit,
405           { "Source", "nsrp.src",
406             FT_UINT32, BASE_DEC, NULL, 0,
407             "SOURCE UNIT INFORMATION", HFILL }
408         },
409                 { &hf_nsrp_msgtype,
410           { "MsgType", "nsrp.msgtype",
411             FT_UINT8, BASE_DEC, VALS(nsrp_msgtype_vals), 0,
412             "Message Type", HFILL }
413         },
414                 { &hf_nsrp_wst_group,
415           { "Wst group", "nsrp.wst",
416             FT_UINT8, BASE_DEC, NULL, 0,
417             "NSRP WST GROUP", HFILL }
418         },
419                 { &hf_nsrp_hst_group,
420           { "Hst group", "nsrp.hst",
421             FT_UINT8, BASE_DEC, NULL, 0,
422             "NSRP HST GROUP", HFILL }
423         },
424         { &hf_nsrp_msgflag,
425           { "Msgflag", "nsrp.msgflag",
426             FT_UINT8, BASE_DEC, VALS(nsrp_flag_vals), 0,
427             "NSRP MSG FLAG", HFILL }
428         },
429         { &hf_nsrp_msglen,
430           { "Msg Length", "nsrp.msglen",
431             FT_UINT16, BASE_DEC, NULL, 0,
432             "NSRP MESSAGE LENGTH", HFILL }
433         },
434                 
435         { &hf_nsrp_encflag,
436           { "Enc Flag", "nsrp.encflag",
437             FT_UINT8, BASE_DEC, VALS(nsrp_encflag_vals), 0,
438             "NSRP ENCRYPT FLAG", HFILL }
439         },
440                 { &hf_nsrp_notused,
441           { "Not Used", "nsrp.notused",
442             FT_UINT8, BASE_DEC, NULL, 0,
443             "NOT USED", HFILL }
444         },
445                 { &hf_nsrp_total_size,
446           { "Total Size", "nsrp.totalsize",
447             FT_UINT32, BASE_DEC, NULL, 0,
448             "NSRP MSG TOTAL MESSAGE", HFILL }
449         },
450                 { &hf_nsrp_ns,
451           { "Ns", "nsrp.ns",
452             FT_UINT16, BASE_DEC, NULL, 0,
453             "Ns", HFILL }
454         },
455                 { &hf_nsrp_nr,
456           { "Nr", "nsrp.nr",
457             FT_UINT16, BASE_DEC, NULL, 0,
458             "Nr", HFILL }
459         },
460                 { &hf_nsrp_no_used,
461           { "Reserved", "nsrp.reserved",
462             FT_UINT16, BASE_DEC, NULL, 0,
463             "RESERVED", HFILL }
464         },
465                 { &hf_nsrp_checksum,
466           { "Checksum", "nsrp.checksum",
467             FT_UINT16, BASE_HEX, NULL, 0,
468             "NSRP PACKET CHECKSUM", HFILL }
469         },
470                 { &hf_nsrp_authflag,
471           { "AuthFlag", "nsrp.authflag",
472             FT_UINT8, BASE_HEX, NULL, 0,
473             "NSRP Auth Flag", HFILL }
474         },
475                         { &hf_nsrp_priority,
476           { "Priority", "nsrp.priority",
477             FT_UINT8, BASE_HEX, NULL, 0,
478             "NSRP Priority", HFILL }
479         },
480                         { &hf_nsrp_dummy,
481           { "Dummy", "nsrp.dummy",
482             FT_UINT8, BASE_HEX, NULL, 0,
483             "NSRP Dummy", HFILL }
484         },
485                 { &hf_nsrp_authchecksum,
486           { "Checksum", "nsrp.authchecksum",
487             FT_UINT16, BASE_HEX, NULL, 0,
488             "NSRP AUTH CHECKSUM", HFILL }
489         },
490                 { &hf_nsrp_ifnum,
491           { "Ifnum", "nsrp.ifnum",
492             FT_UINT16, BASE_HEX, NULL, 0,
493             "NSRP IfNum", HFILL }
494         },
495         { &hf_nsrp_data,
496           { "Data", "nsrp.data",
497             FT_STRING, 0, NULL, 0,
498             "PADDING", HFILL }
499         }
500     };
501
502     static gint *ett[] = {
503         &ett_nsrp
504     };
505
506     proto_nsrp = proto_register_protocol("Juniper Netscreen Redundant Protocol",
507         "NSRP", "nsrp");
508     proto_register_field_array(proto_nsrp, hf, array_length(hf));
509     proto_register_subtree_array(ett, array_length(ett));
510 }
511
512
513 void
514 proto_reg_handoff_nsrp(void)
515 {
516     dissector_handle_t nsrp_handle;
517
518     nsrp_handle = create_dissector_handle(dissect_nsrp, proto_nsrp);
519     dissector_add("ethertype", ETHERTYPE_NSRP, nsrp_handle);
520 }