change a whole bunch of ethereal into wireshark
[obnox/wireshark/wip.git] / epan / dissectors / packet-tipc.c
1 /* packet-tipc.c
2  * Routines for Transparent Inter Process Communication packet dissection
3  *
4  * $Id$
5  *
6  * Copyright 2005, Anders Broman <anders.broman@ericsson.com>
7  * 
8  * Wireshark - Network traffic analyzer
9  * By Gerald Combs <gerald@wireshark.org>
10  * Copyright 1998 Gerald Combs
11  *
12  * This program is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU General Public License
14  * as published by the Free Software Foundation; either version 2
15  * of the License, or (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program; if not, write to the Free Software
24  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25  * Protocol ref:
26  * http://tipc.sourceforge.net/
27  */
28
29
30 #ifdef HAVE_CONFIG_H
31 # include "config.h"
32 #endif
33
34 #include <stdio.h>
35 #include <stdlib.h>
36 #include <string.h>
37 #include <ctype.h>
38
39 #include <epan/prefs.h>
40
41 #include <glib.h>
42 #include <epan/packet.h>
43 #include <epan/etypes.h>
44 #include <epan/emem.h>
45 #include <epan/reassemble.h>
46
47 static int proto_tipc = -1;
48
49 static int hf_tipc_msg_fragments = -1;
50 static int hf_tipc_msg_fragment = -1;
51 static int hf_tipc_msg_fragment_overlap = -1;
52 static int hf_tipc_msg_fragment_overlap_conflicts = -1;
53 static int hf_tipc_msg_fragment_multiple_tails = -1;
54 static int hf_tipc_msg_fragment_too_long_fragment = -1;
55 static int hf_tipc_msg_fragment_error = -1;
56 static int hf_tipc_msg_reassembled_in = -1;
57
58 static int hf_tipc_ver = -1;
59 static int hf_tipc_usr = -1;
60 static int hf_tipcv2_usr = -1;
61 static int hf_tipc_hdr_size = -1;
62 static int hf_tipc_nonsequenced = -1;
63 static int hf_tipc_destdrop;
64 static int hf_tipc_unused = -1;
65 static int hf_tipc_msg_size = -1;
66 static int hf_tipc_ack_link_lev_seq = -1;
67 static int hf_tipc_link_lev_seq = -1;
68 static int hf_tipc_prev_proc = -1;
69 static int hf_tipc_org_port = -1;
70 static int hf_tipc_dst_port = -1;
71 static int hf_tipc_data_msg_type = -1;
72 static int hf_tipc_err_code = -1;
73 static int hf_tipc_reroute_cnt = -1;
74 static int hf_tipc_act_id = -1;
75 static int hf_tipc_org_proc = -1;
76 static int hf_tipc_dst_proc = -1;
77 static int hf_tipc_unused2 = -1;
78 static int hf_tipc_importance = -1;
79 static int hf_tipc_link_selector = -1;
80 static int hf_tipc_msg_cnt = -1;
81 static int hf_tipc_probe = -1;
82 static int hf_tipc_bearer_id = -1;
83 static int hf_tipc_link_selector2 = -1;
84 static int hf_tipc_remote_addr = -1;
85 static int hf_tipc_rm_msg_type = -1;
86 static int hf_tipc_nd_msg_type = -1;
87 static int hf_tipc_cm_msg_type = -1;
88 static int hf_tipc_lp_msg_type = -1;
89 static int hf_tipc_cng_prot_msg_type = -1;
90 static int hf_tipc_sm_msg_type = -1;
91 static int hf_tipc_unknown_msg_type = -1;
92 static int hf_tipc_seq_gap = -1;
93 static int hf_tipc_nxt_snt_pkg = -1;
94 static int hf_tipc_unused3 = -1;
95 static int hf_tipc_bearer_name = -1;
96
97 static int hf_tipc_name_dist_type = -1;
98 static int hf_tipc_name_dist_lower = -1;
99 static int hf_tipc_name_dist_upper = -1;
100 static int hf_tipc_name_dist_port = -1;
101 static int hf_tipc_name_dist_key = -1;
102
103 static int hf_tipcv2_data_msg_type = -1;
104 static int hf_tipcv2_bcast_mtype = -1;
105 static int hf_tipcv2_link_mtype = -1;
106 static int hf_tipcv2_connmgr_mtype = -1;
107 static int hf_tipcv2_route_mtype = -1;
108 static int hf_tipcv2_changeover_mtype = -1;
109 static int hf_tipcv2_naming_mtype = -1;
110 static int hf_tipcv2_fragmenter_mtype = -1;
111 static int hf_tipcv2_neighbour_mtype = -1;
112 static int hf_tipcv2_errorcode = -1;
113 static int hf_tipcv2_rer_cnt = -1;
114 static int hf_tipcv2_lookup_scope = -1;
115 static int hf_tipcv2_opt_p = -1;
116 static int hf_tipcv2_broadcast_ack_no = -1;
117 static int hf_tipcv2_link_level_ack_no = -1;
118 static int hf_tipcv2_link_level_seq_no = -1;
119 static int hf_tipcv2_bcast_seq_no = -1;
120 static int hf_tipcv2_prev_node = -1;
121 static int hf_tipcv2_orig_node = -1;
122 static int hf_tipcv2_dest_node = -1;
123 static int hf_tipcv2_port_name_type = -1;
124 static int hf_tipcv2_port_name_instance = -1;
125
126 static int hf_tipcv2_bcast_seq_gap = -1;
127 static int hf_tipcv2_sequence_gap = -1;
128 static int hf_tipcv2_next_sent_broadcast = -1;
129 static int hf_tipcv2_fragment_number = -1;
130 static int hf_tipcv2_next_sent_packet = -1;
131 static int hf_tipcv2_session_no = -1;
132 static int hf_tipcv2_link_prio = -1;
133 static int hf_tipcv2_network_plane = -1;
134 static int hf_tipcv2_probe = -1;
135 static int hf_tipcv2_link_tolerance = -1;
136 static int hf_tipcv2_bearer_instance = -1;
137 static int hf_tipcv2_bearer_level_orig_addr = -1;
138 static int hf_tipcv2_cluster_address = -1;
139 static int hf_tipcv2_bitmap = -1;
140 static int hf_tipcv2_node_address = -1;
141 static int hf_tipcv2_destination_domain = -1;
142 static int hf_tipcv2_network_id = -1;
143
144 static gint ett_tipc_msg_fragment = -1;
145 static gint ett_tipc_msg_fragments = -1;
146
147 /* Initialize the subtree pointer */
148 static gint ett_tipc = -1;
149 static gint ett_tipc_data = -1;
150
151 static gboolean tipc_defragment = TRUE;
152 static gboolean dissect_tipc_data = FALSE;
153
154 static gboolean extra_ethertype = FALSE;
155
156 #define ETHERTYPE_TIPC2  0x0807
157
158 dissector_handle_t ip_handle;
159
160 static proto_tree *top_tree;
161
162 static const fragment_items tipc_msg_frag_items = {
163         /* Fragment subtrees */
164         &ett_tipc_msg_fragment,
165         &ett_tipc_msg_fragments,
166         /* Fragment fields */
167         &hf_tipc_msg_fragments,
168         &hf_tipc_msg_fragment,
169         &hf_tipc_msg_fragment_overlap,
170         &hf_tipc_msg_fragment_overlap_conflicts,
171         &hf_tipc_msg_fragment_multiple_tails,
172         &hf_tipc_msg_fragment_too_long_fragment,
173         &hf_tipc_msg_fragment_error,
174         /* Reassembled in field */
175         &hf_tipc_msg_reassembled_in,
176         /* Tag */
177         "TIPC Message fragments"
178 };
179
180
181 #define MAX_TIPC_ADDRESS_STR_LEN        15
182 #define TIPCv1 1
183 #define TIPCv2 2
184 /* Users */
185 #define TIPC_DATA_PRIO_0                        0
186 #define TIPC_DATA_PRIO_1                        1
187 #define TIPC_DATA_PRIO_2                        2
188 #define TIPC_DATA_NON_REJECTABLE        3
189
190 #define TIPC_ROUTING_MANAGER            8
191 #define TIPC_NAME_DISTRIBUTOR           9
192 #define TIPC_CONNECTION_MANAGER         10
193 #define TIPC_LINK_PROTOCOL                      11
194 #define TIPC_CHANGEOVER_PROTOCOL        13
195 #define TIPC_SEGMENTATION_MANAGER       14
196 #define TIPC_MSG_BUNDLER                        15
197
198 #define TIPC_LINK_PROTOCO_STATE_MSG 0
199
200 const value_string tipc_user_values[] = {
201         { 0,    "DATA_PRIO_0"},
202         { 1,    "DATA_PRIO_1"},
203         { 2,    "DATA_PRIO_2"},
204         { 3,    "DATA_NON_REJECTABLE"},
205         { TIPC_ROUTING_MANAGER,                 "ROUTING_MANAGER"},
206         { TIPC_NAME_DISTRIBUTOR,                "NAME_DISTRIBUTOR"},
207         { TIPC_CONNECTION_MANAGER,              "CONNECTION_MANAGER"},
208         { TIPC_LINK_PROTOCOL,                   "LINK_PROTOCOL"},
209         { TIPC_CHANGEOVER_PROTOCOL,             "CHANGEOVER_PROTOCOL"},
210         { TIPC_SEGMENTATION_MANAGER,    "SEGMENTATION_MANAGER"},
211         { TIPC_MSG_BUNDLER,                             "MSG_BUNDLER"},
212         { 0,    NULL},
213 };
214
215 #define TIPCv2_BCAST_PROTOCOL                   5
216 #define TIPCv2_MSG_BUNDLER                              6
217 #define TIPCv2_LINK_PROTOCOL                    7
218 #define TIPCv2_CONN_MANAGER                             8
219 #define TIPCv2_ROUTE_DISTRIBUTOR                9
220 #define TIPCv2_CHANGEOVER_PROTOCOL              10
221 #define TIPCv2_NAME_DISTRIBUTOR                 11
222 #define TIPCv2_MSG_FRAGMENTER                   12
223 #define TIPCv2_LINK_CONFIGURATION               13
224
225 const value_string tipcv2_user_values[] = {
226     { 0,                                                                "Low Priority Payload Data"},
227     { 1,                                                                "Normal Priority Payload Data"},
228     { 2,                                                                "High Priority Payload Data"},
229     { 3,                                                                "Non-Rejectable Payload Data"},
230         { TIPCv2_BCAST_PROTOCOL,                        "Broadcast Maintenance Protocol"},
231         { TIPCv2_MSG_BUNDLER,                           "Message Bundler Protocol"},
232         { TIPCv2_LINK_PROTOCOL,                         "Link State Maintenance Protocol"},
233         { TIPCv2_CONN_MANAGER,                          "Connection Manager"},
234         { TIPCv2_ROUTE_DISTRIBUTOR,                     "Routing Table Update Protocol"},
235         { TIPCv2_CHANGEOVER_PROTOCOL,           "Link Changeover Protocol"},
236         { TIPCv2_NAME_DISTRIBUTOR,                      "Name Table Update Protocol"},
237         { TIPCv2_MSG_FRAGMENTER,                        "Message Fragmentation Protocol"},
238     { TIPCv2_LINK_CONFIGURATION,                "Link Configuration Protocol"},
239         { 0,    NULL},
240 };
241
242 #define TIPC_CONNECTED_MSG      0
243 #define TIPC_NAMED_MSG          2
244 #define TIPC_DIRECT_MSG         3
245 #define TIPC_OVERLOAD_W_MSG 4
246
247 static const value_string tipc_data_msg_type_values[] = {
248         { 0,    "CONN_MSG"},
249         { 2,    "NAMED_MSG"},
250         { 3,    "DIRECT_MSG"},
251         { 4,    "OVERLOAD_W_MSG"},
252         { 0,    NULL},
253 };
254
255 static const value_string tipcv2_data_msg_type_values[] = {
256         { 0,    "Sent on connection (CONN_MSG)"},
257         { 1,    "Logical multicast (MCAST_MSG)"},
258         { 2,    "Port name destination address (NAMED_MSG)"},
259         { 3,    "Port identity destination address (DIRECT_MSG)"},
260         { 0,    NULL},
261 };
262 static const value_string tipc_error_code_values[] = {
263         { 0,    "MSG_OK"},
264         { 1,    "NO_PORT_NAME"},
265         { 2,    "NO_REMOTE_PORT"},
266         { 3,    "NO_REMOTE_PROCESSOR"},
267         { 4,    "DEST_OVERLOADED"},
268         { 6,    "NO_CONNECTION"},
269         { 7,    "COMMUNICATION_ERROR"},
270         { 0,    NULL},
271 };
272 static const value_string tipcv2_error_code_strings[]={
273     { 0           ,"No error (TIPC_OK)"},
274     { 1           ,"Destination port name unknown (TIPC_ERR_NO_NAME)"}, 
275     { 2           ,"Destination port does not exist (TIPC_ERR_NO_PORT)"},
276     { 3           ,"Destination node unavailable (TIPC_ERR_NO_NODE)"},
277     { 4           ,"Destination node overloaded (TIPC_ERR_OVERLOAD)"},
278     { 5           ,"Connection Shutdown (No error) (TIPC_CONN_SHUTDOWN)"},
279     { 6           ,"Communication Error (TIPC_CONN_ERROR)"},
280         { 0,    NULL},
281 };
282
283 static const value_string tipcv2_lookup_scope_strings[]={
284     { 0           ,"Zone Scope"},
285     { 1           ,"Cluster Scope"},
286     { 2           ,"Node Scope"},
287         { 0,    NULL},
288 };
289 static const value_string tipc_routing_mgr_msg_type_values[] = {
290         { 0,    "EXT_ROUTING_TABLE"},
291         { 1,    "LOCAL_ROUTING_TABLE"},
292         { 2,    "DP_ROUTING_TABLE"},
293         { 3,    "ROUTE_ADDITION"},
294         { 4,    "ROUTE_REMOVAL"},
295         { 0,    NULL},
296 };
297 static const value_string tipc_name_dist_msg_type_values[] = {
298         { 0,    "PUBLICATION"},
299         { 1,    "WITHDRAWAL"},
300         { 0,    NULL},
301 };
302 /* CONNECTION_MANAGER */
303 static const value_string tipc_cm_msg_type_values[] = {
304         { 0,    "CONNECTION_PROBE"},
305         { 1,    "CONNECTION_PROBE_REPLY"},
306         { 0,    NULL},
307 };
308 static const value_string tipc_link_prot_msg_type_values[] = {
309         { 10,   "RESET_MSG"},
310         { 11,   "ACTIVATE_MSG"},
311         { 12,   "STATE_MSG"},
312         { 0,    NULL},
313 };
314 /* CHANGEOVER_PROTOCOL */
315 static const value_string tipc_cng_prot_msg_type_values[] = {
316         { 0,    "DUPLICATE_MSG"},
317         { 1,    "ORIGINAL_MSG"},
318         { 2,    "INFO_MSG"},
319         { 0,    NULL},
320 };
321 /* SEGMENTATION_MANAGER */
322 #define TIPC_FIRST_SEGMENT      1
323 #define TIPC_SEGMENT            2
324 const value_string tipc_sm_msg_type_values[] = {
325         { 1,    "FIRST_SEGMENT"},
326         { 2,    "SEGMENT"},
327         { 0,    NULL},
328 };
329
330 /* TIPCv2_BCAST_PROTOCOL - Broadcast Maintenance Protocol */
331 static const value_string tipcv2_bcast_mtype_strings[]={
332     { 0           ,"Tunneled, retransmitted broadcast packet (BCAST_MSG)"},
333         { 0,    NULL},
334 };
335
336 /* TIPCv2_MSG_BUNDLER - Message Bundler Protocol */
337
338 /* No message types */
339
340 /* TIPCv2_LINK_PROTOCOL - Link State Maintenance Protocol */
341 #define TIPCv2_STATE_MSG 0
342 #define TIPCv2_RESET_MSG 1
343
344 static const value_string tipcv2_link_mtype_strings[]={
345     { TIPCv2_STATE_MSG, "STATE_MSG"},
346     { TIPCv2_RESET_MSG, "RESET_MSG"},
347     { 2,                                "ACTIVATE_MSG"},
348         { 0,    NULL},
349 };
350 /* TIPCv2_CONN_MANAGER - Connection Manager */
351 static const value_string tipcv2_connmgr_mtype_strings[]={
352     { 0           ,"CONN_PROBE"},
353     { 1           ,"CONN_PROBE_REPLY"},
354     { 2           ,"(MSG_ACK)"},
355         { 0,    NULL},
356 };
357 /* TIPCv2_ROUTE_DISTRIBUTOR - Routing Table Update Protocol */
358
359 #define TIPCv2_EXT_ROUTING_TABLE                0
360 #define TIPCv2_LOCAL_ROUTING_TABLE              1
361 #define TIPCv2_SEC_ROUTING_TABLE                2
362 #define TIPCv2_ROUTE_ADDITION                   3
363 #define TIPCv2_ROUTE_REMOVAL                    4
364 static const value_string tipcv2_route_mtype_strings[]={
365     { 0           ,"EXT_ROUTING_TABLE"},
366     { 1           ,"LOCAL_ROUTING_TABLE"},
367     { 2           ,"SEC_ROUTING_TABLE"},
368     { 3           ,"ROUTE_ADDITION"},
369     { 4           ,"ROUTE_REMOVAL"},
370         { 0,    NULL},
371 };
372 /* TIPCv2_CHANGEOVER_PROTOCOL - Link Changeover Protocol */
373 static const value_string tipcv2_changeover_mtype_strings[]={
374     { 0           ,"DUPLICATE_MSG"},
375     { 1           ,"ORIGINAL_MSG"},
376         { 0,    NULL},
377 };
378 /* TIPCv2_NAME_DISTRIBUTOR - Name Table Update Protocol */
379 static const value_string tipcv2_naming_mtype_strings[]={
380     { 0           ,"PUBLICATION"},
381     { 1           ,"WITHDRAWAL"},
382         { 0,    NULL},
383 };
384 /* TIPCv2_MSG_FRAGMENTER - Message Fragmentation Protocol" */
385 static const value_string tipcv2_fragmenter_mtype_strings[]={
386     { 0           ,"FIRST_FRAGMENT"},
387     { 1           ,"FRAGMENT"},
388     { 2           ,"LAST_FRAGMENT"},
389         { 0,    NULL},
390 };
391
392 /* TIPCv2_LINK_CONFIGURATION - Link Configuration Protocol
393  * 4.3.9 Neighbour Detection Protocol
394  */
395
396 static const value_string tipcv2_neighbour_mtype_strings[]={
397     { 0           ,"Link_Request"},
398     { 1           ,"Link_Response"},
399         { 0,    NULL},
400 };
401
402
403 static const value_string tipcv2_networkplane_strings[]={
404     { 0           ,"A"},
405     { 1           ,"B"},
406     { 2           ,"C"},
407     { 3           ,"D"},
408     { 4           ,"E"},
409     { 5           ,"F"},
410         { 0,    NULL},
411 };
412
413
414 static void dissect_tipc(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);
415
416
417 static GHashTable *tipc_msg_fragment_table = NULL;
418 static GHashTable *tipc_msg_reassembled_table = NULL;
419
420
421 static void
422 tipc_defragment_init(void)
423 {
424         fragment_table_init (&tipc_msg_fragment_table);
425         reassembled_table_init(&tipc_msg_reassembled_table);
426 }
427
428
429 static gchar*
430 tipc_addr_to_str(guint tipc_address)
431 {
432         guint8 zone;
433         guint16 subnetwork;
434         guint16 processor;
435         gchar *buff;
436
437         buff=ep_alloc(MAX_TIPC_ADDRESS_STR_LEN);
438
439         processor = tipc_address & 0x0fff;
440
441         tipc_address = tipc_address >> 12;
442         subnetwork = tipc_address & 0x0fff;
443
444         tipc_address = tipc_address >> 12;
445         zone = tipc_address & 0xff;
446
447         g_snprintf(buff,MAX_TIPC_ADDRESS_STR_LEN,"%u.%u.%u",zone,subnetwork,processor);
448
449         return buff;
450 }
451
452 /*
453 All name distributor messages have a data part containing one or more table elements with
454 the following five-word structure:
455 struct DistributionItem{
456         unsigned int type; / Published port name type /
457         unsigned int lower; / Lower bound of published sequence /
458         unsigned int upper; / Upper bound of published sequence /
459         unsigned int port; / Random number part of port identity /
460         unsigned int key; / Use for verification at withdrawal /
461 };
462 */
463 static void
464 dissect_tipc_name_dist_data(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree){
465         int offset = 0;
466  
467         while ( tvb_reported_length_remaining(tvb,offset) > 0){
468                  proto_tree_add_item(tree, hf_tipc_name_dist_type, tvb, offset, 4, FALSE);
469                  offset = offset+4;
470                  proto_tree_add_item(tree, hf_tipc_name_dist_lower, tvb, offset, 4, FALSE);
471                  offset = offset+4;
472                  proto_tree_add_item(tree, hf_tipc_name_dist_upper, tvb, offset, 4, FALSE);
473                  offset = offset+4;
474                  proto_tree_add_item(tree, hf_tipc_name_dist_port, tvb, offset, 4, FALSE);
475                  offset = offset+4;
476                  proto_tree_add_item(tree, hf_tipc_name_dist_key, tvb, offset, 4, FALSE);
477                  offset = offset+4;
478         }
479 }
480
481 /* Set message type in COL INFO and return type of message ( data or Internal message type */
482 static gboolean
483 tipc_v2_set_col_msgtype(packet_info *pinfo, guint8 user,guint8 msg_type){
484
485         gboolean datatype_hdr = FALSE;
486
487         switch (user){
488                 case TIPC_DATA_PRIO_0:  
489                 case TIPC_DATA_PRIO_1:
490                 case TIPC_DATA_PRIO_2:
491                 case TIPC_DATA_NON_REJECTABLE:
492                         /* 
493                          * src and dest address will be found at different location depending on User ad hdr_size
494                          */
495                         datatype_hdr = TRUE;
496                         if (check_col(pinfo->cinfo, COL_INFO))
497                                 col_append_fstr(pinfo->cinfo, COL_INFO, "%s(%u) ", val_to_str(msg_type, tipcv2_data_msg_type_values, "unknown"),msg_type);
498                         break;
499                 case TIPCv2_BCAST_PROTOCOL:
500                         if (check_col(pinfo->cinfo, COL_INFO))
501                                 col_append_fstr(pinfo->cinfo, COL_INFO, "%s(%u) ", val_to_str(msg_type, tipcv2_bcast_mtype_strings, "unknown"),msg_type);
502                         break;
503                 case TIPCv2_MSG_BUNDLER:
504                         /* No message types */
505                         break;
506                 case TIPCv2_LINK_PROTOCOL:
507                         if (check_col(pinfo->cinfo, COL_INFO))
508                                 col_append_fstr(pinfo->cinfo, COL_INFO, "%s(%u) ", val_to_str(msg_type, tipcv2_link_mtype_strings, "unknown"),msg_type);
509                         break;
510                 case TIPCv2_CONN_MANAGER:
511                         if (check_col(pinfo->cinfo, COL_INFO))
512                                 col_append_fstr(pinfo->cinfo, COL_INFO, "%s(%u) ", val_to_str(msg_type, tipcv2_connmgr_mtype_strings, "unknown"),msg_type);
513                         break;
514                 case TIPCv2_ROUTE_DISTRIBUTOR:
515                         if (check_col(pinfo->cinfo, COL_INFO))
516                                 col_append_fstr(pinfo->cinfo, COL_INFO, "%s(%u) ", val_to_str(msg_type, tipcv2_route_mtype_strings, "unknown"),msg_type);
517                         break;
518                 case TIPCv2_CHANGEOVER_PROTOCOL:
519                         if (check_col(pinfo->cinfo, COL_INFO))
520                                 col_append_fstr(pinfo->cinfo, COL_INFO, "%s(%u) ", val_to_str(msg_type, tipcv2_changeover_mtype_strings, "unknown"),msg_type);
521                         break;
522                 case TIPCv2_NAME_DISTRIBUTOR:
523                         if (check_col(pinfo->cinfo, COL_INFO))
524                                 col_append_fstr(pinfo->cinfo, COL_INFO, "%s(%u) ", val_to_str(msg_type, tipcv2_naming_mtype_strings, "unknown"),msg_type);
525                         break;
526                 case TIPCv2_MSG_FRAGMENTER:
527                         if (check_col(pinfo->cinfo, COL_INFO))
528                                 col_append_fstr(pinfo->cinfo, COL_INFO, "%s(%u) ", val_to_str(msg_type, tipcv2_fragmenter_mtype_strings, "unknown"),msg_type);
529                         break;
530                 case TIPCv2_LINK_CONFIGURATION:
531                         if (check_col(pinfo->cinfo, COL_INFO))
532                                 col_append_fstr(pinfo->cinfo, COL_INFO, "%s(%u) ", val_to_str(msg_type, tipcv2_neighbour_mtype_strings, "unknown"),msg_type);
533                         break;
534                 default:
535                         break;           
536         }
537         return datatype_hdr;
538 }
539
540 /* Set message type in COL INFO and return type of message ( data or Internal message type */
541 static gboolean
542 tipc_v1_set_col_msgtype(packet_info *pinfo, guint8 user,guint8 msg_type){
543
544         gboolean datatype_hdr = FALSE;
545
546         switch (user){
547                 case TIPC_DATA_PRIO_0:  
548                 case TIPC_DATA_PRIO_1:
549                 case TIPC_DATA_PRIO_2:
550                 case TIPC_DATA_NON_REJECTABLE:
551                         /* 
552                          * src and dest address will be found at different location depending on User ad hdr_size
553                          */
554                         datatype_hdr = TRUE;
555                         if (check_col(pinfo->cinfo, COL_INFO))
556                                 col_append_fstr(pinfo->cinfo, COL_INFO, "%s(%u) ", val_to_str(msg_type, tipc_data_msg_type_values, "unknown"),msg_type);
557                         break;
558                 case TIPC_NAME_DISTRIBUTOR:
559                         if (check_col(pinfo->cinfo, COL_INFO))
560                                 col_append_fstr(pinfo->cinfo, COL_INFO, "%s(%u) ", val_to_str(msg_type, tipc_name_dist_msg_type_values, "unknown"),msg_type);
561                         break;
562                 case TIPC_CONNECTION_MANAGER:
563                         if (check_col(pinfo->cinfo, COL_INFO))
564                                 col_append_fstr(pinfo->cinfo, COL_INFO, "%s(%u) ", val_to_str(msg_type, tipc_cm_msg_type_values, "unknown"),msg_type);
565                         break;
566                 case TIPC_ROUTING_MANAGER:
567                         if (check_col(pinfo->cinfo, COL_INFO))
568                                 col_append_fstr(pinfo->cinfo, COL_INFO, "%s(%u) ", val_to_str(msg_type, tipc_routing_mgr_msg_type_values, "unknown"),msg_type);
569                         break;
570                 case TIPC_LINK_PROTOCOL:
571                         if (check_col(pinfo->cinfo, COL_INFO))
572                                 col_append_fstr(pinfo->cinfo, COL_INFO, "%s(%u) ", val_to_str(msg_type, tipc_link_prot_msg_type_values, "unknown"),msg_type);
573                         break;
574                 case TIPC_CHANGEOVER_PROTOCOL:
575                         if (check_col(pinfo->cinfo, COL_INFO))
576                                 col_append_fstr(pinfo->cinfo, COL_INFO, "%s(%u) ", val_to_str(msg_type, tipc_cng_prot_msg_type_values, "unknown"),msg_type);
577                         break;
578                 case TIPC_SEGMENTATION_MANAGER:
579                         if (check_col(pinfo->cinfo, COL_INFO))
580                                 col_append_fstr(pinfo->cinfo, COL_INFO, "%s(%u) ", val_to_str(msg_type, tipc_sm_msg_type_values, "unknown"),msg_type);
581                         break;
582                 case TIPC_MSG_BUNDLER:
583                         break;
584                 default:
585                         break;           
586         }
587         return datatype_hdr;
588 }
589
590
591 /*
592           Version 2(draft-maloy-tipc-01.txt):
593
594 4.2.1 Internal Message Header Format
595
596
597
598        0                   1                   2                   3
599        0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
600       +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
601    w0:|vers |msg usr|hdr sz |n|resrv|            packet size          |
602       +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
603    w1:|m typ|bcstsqgap| sequence gap  |       broadcast ack no        |
604       +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
605    w2:|        link level ack no      |   broadcast/link level seq no |
606       +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
607    w3:|                       previous node                           |
608       +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
609    w4:|  next sent broadcast/fragm no | next sent pkt/ fragm msg no   |
610       +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
611    w5:|          session no           | res |r|berid|link prio|netpl|p|
612       +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
613    w6:|                      originating node                         |
614       +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
615    w7:|                      destination node                         |
616       +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
617    w8:|                  transport sequence number                    |
618       +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
619    w9:|          msg count            |       link tolerance          |
620       +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
621       \                                                               \
622       /                     User Specific Data                        /
623       \                                                               \
624       +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
625
626   */
627 static void
628 dissect_tipc_v2_internal_msg(tvbuff_t *tipc_tvb, packet_info *pinfo, proto_tree *tipc_tree, int offset, guint8 user, guint32 msg_size)
629 {
630
631         guint32 dword;
632         gchar *addr_str_ptr;
633         guint8 message_type;
634         tvbuff_t *data_tvb;
635
636         dword = tvb_get_ntohl(tipc_tvb,offset+8);
637         addr_str_ptr = tipc_addr_to_str(dword);
638         message_type = tvb_get_guint8(tipc_tvb,offset) >>1;  
639
640         switch (user){
641                 case TIPCv2_BCAST_PROTOCOL:
642                         /* W1 */
643                         proto_tree_add_item(tipc_tree, hf_tipcv2_bcast_mtype, tipc_tvb, offset, 4, FALSE);
644                         offset = offset + 4;
645                         /* W2 */
646                         offset = offset + 4;
647                         /* W3 */
648                         proto_tree_add_string(tipc_tree, hf_tipcv2_prev_node, tipc_tvb, offset, 4,      addr_str_ptr);
649                         offset = offset + 4;
650                         /* W4 */
651                         offset = offset + 4;
652                         /* W5 */
653                         offset = offset + 4;
654                         /* W6 */
655                         proto_tree_add_text(tipc_tree, tipc_tvb, offset, 4,"Word 6 Unused for this user");
656                         offset = offset + 4;
657                         /* W7 */
658                         proto_tree_add_text(tipc_tree, tipc_tvb, offset, 4,"Word 7 Unused for this user");
659                         offset = offset + 4;
660                         break;
661                 case TIPCv2_MSG_BUNDLER:
662                         /* W1 */
663                         /* No message types */
664                         offset = offset + 4;
665                         /* W2 */
666                         offset = offset + 4;
667                         /* W3 */
668                         proto_tree_add_string(tipc_tree, hf_tipcv2_prev_node, tipc_tvb, offset, 4,      addr_str_ptr);
669                         offset = offset + 4;
670                         /* W5 */
671                         offset = offset + 4;
672                         /* W6 */
673                         proto_tree_add_text(tipc_tree, tipc_tvb, offset, 4,"Word 6 Unused for this user");
674                         offset = offset + 4;
675                         /* W7 */
676                         proto_tree_add_text(tipc_tree, tipc_tvb, offset, 4,"Word 7 Unused for this user");
677                         offset = offset + 4;
678                         /* W8 */
679                         proto_tree_add_text(tipc_tree, tipc_tvb, offset, 4,"Word 8 Unused for this user");
680                         offset = offset + 4;
681                         /* W9 */
682                         /* Message Count: 16 bits. */
683                         offset = offset + 4;
684                         break;
685                 case TIPCv2_LINK_PROTOCOL:
686                         /* W1 */
687                         proto_tree_add_item(tipc_tree, hf_tipcv2_link_mtype, tipc_tvb, offset, 4, FALSE);
688                         /*  Broadcast Sequence Gap: 5 bits. */
689                         proto_tree_add_item(tipc_tree, hf_tipcv2_bcast_seq_gap, tipc_tvb, offset, 4, FALSE);
690                         /* Sequence Gap:  8 bits. */
691                         proto_tree_add_item(tipc_tree, hf_tipcv2_sequence_gap, tipc_tvb, offset, 4, FALSE);
692                         offset = offset + 4;
693                         /* W2 */
694                         offset = offset + 4;
695                         /* W3 */
696                         proto_tree_add_string(tipc_tree, hf_tipcv2_prev_node, tipc_tvb, offset, 4,      addr_str_ptr);
697                         offset = offset + 4;
698                         /* W4 */
699                         /* Next Sent Broadcast: 16 bits */
700                         proto_tree_add_item(tipc_tree, hf_tipcv2_next_sent_broadcast, tipc_tvb, offset, 4, FALSE);
701                         /* Next Sent Packet:  16 bits. */
702                         proto_tree_add_item(tipc_tree, hf_tipcv2_next_sent_packet, tipc_tvb, offset, 4, FALSE);
703                         offset = offset + 4;
704                         /* W5 */
705                         /* Session Number: 16 bits. */
706                         proto_tree_add_item(tipc_tree, hf_tipcv2_session_no, tipc_tvb, offset, 4, FALSE);
707                         /* Reserved: 3 bits Must be set to zero. */
708                         /* Redundant Link: 1 bit */
709                         /* Bearer Identity: 3 bits */
710                         /* Link Priority: 5 bits. */
711                         proto_tree_add_item(tipc_tree, hf_tipcv2_link_prio, tipc_tvb, offset, 4, FALSE);
712                         /* Network Plane: 3 bits. */
713                         proto_tree_add_item(tipc_tree, hf_tipcv2_network_plane, tipc_tvb, offset, 4, FALSE);
714                         /* Probe: 1 bit. */
715                         proto_tree_add_item(tipc_tree, hf_tipcv2_probe, tipc_tvb, offset, 4, FALSE);
716                         offset = offset + 4;
717
718                         /* W6 */
719                         proto_tree_add_text(tipc_tree, tipc_tvb, offset, 4,"Word 6 Unused for this user");
720                         offset = offset + 4;
721                         /* W7 */
722                         proto_tree_add_text(tipc_tree, tipc_tvb, offset, 4,"Word 7 Unused for this user");
723                         offset = offset + 4;
724                         /* W8 */
725                         proto_tree_add_text(tipc_tree, tipc_tvb, offset, 4,"Word 8 Unused for this user");
726                         offset = offset + 4;
727                         /* W9 */
728                         /* Link Tolerance:  16 bits */
729                         proto_tree_add_item(tipc_tree, hf_tipcv2_link_tolerance, tipc_tvb, offset, 4, FALSE);
730                         offset = offset + 4;
731                         
732                         if (message_type == TIPCv2_RESET_MSG)
733                                 proto_tree_add_item(tipc_tree, hf_tipcv2_bearer_instance, tipc_tvb, offset, -1, FALSE);
734                         break;
735                 case TIPCv2_CONN_MANAGER:
736                         /* W1 */
737                         proto_tree_add_item(tipc_tree, hf_tipcv2_connmgr_mtype, tipc_tvb, offset, 4, FALSE);
738                         offset = offset + 4;
739                         /* W2 */
740                         offset = offset + 4;
741                         /* W3 */
742                         proto_tree_add_string(tipc_tree, hf_tipcv2_prev_node, tipc_tvb, offset, 4,      addr_str_ptr);
743                         offset = offset + 4;
744                         /* W4 */
745                         offset = offset + 4;
746                         /* W5 */
747                         offset = offset + 4;
748                         /* W6 */
749                         proto_tree_add_text(tipc_tree, tipc_tvb, offset, 4,"Word 6 Unused for this user");
750                         offset = offset + 4;
751                         /* W7 */
752                         proto_tree_add_text(tipc_tree, tipc_tvb, offset, 4,"Word 7 Unused for this user");
753                         break;
754                 case TIPCv2_ROUTE_DISTRIBUTOR:
755                         /* W1 */
756                         proto_tree_add_item(tipc_tree, hf_tipcv2_route_mtype, tipc_tvb, offset, 4, FALSE);
757                         offset = offset + 4;
758                         /* W2 */
759                         offset = offset + 4;
760                         /* W3 */
761                         proto_tree_add_string(tipc_tree, hf_tipcv2_prev_node, tipc_tvb, offset, 4,      addr_str_ptr);
762                         offset = offset + 4;
763                         /* W4 */
764                         offset = offset + 4;
765                         /* W5 */
766                         offset = offset + 4;
767                         /* W6 */
768                         proto_tree_add_text(tipc_tree, tipc_tvb, offset, 4,"Word 6 Unused for this user");
769                         offset = offset + 4;
770                         /* W7 */
771                         proto_tree_add_text(tipc_tree, tipc_tvb, offset, 4,"Word 7 Unused for this user");
772                         offset = offset + 4;
773                         /* W8 */
774                         offset = offset + 4;
775                         /* W9 */
776                         offset = offset + 4;
777                         /* W10 */
778                         switch (message_type){
779                         case TIPCv2_EXT_ROUTING_TABLE:          /* 0  */
780                         case TIPCv2_LOCAL_ROUTING_TABLE:        /* 1  */
781                         case TIPCv2_SEC_ROUTING_TABLE:          /* 2  */
782                                 /* Cluster Address */
783                                 dword = tvb_get_ntohl(tipc_tvb,offset+8);
784                                 addr_str_ptr = tipc_addr_to_str(dword);
785                                 proto_tree_add_string(tipc_tree, hf_tipcv2_cluster_address, tipc_tvb, offset, 4,        addr_str_ptr);
786                                 offset = offset + 4;
787                                 /* bitmap */
788                                 proto_tree_add_item(tipc_tree, hf_tipcv2_bitmap, tipc_tvb, offset, -1, FALSE);
789                                 break;
790                         case TIPCv2_ROUTE_ADDITION:                     /* 3  */
791                         case TIPCv2_ROUTE_REMOVAL:                      /* 4  */
792                                 /* Node Address */
793                                 dword = tvb_get_ntohl(tipc_tvb,offset+8);
794                                 addr_str_ptr = tipc_addr_to_str(dword);
795                                 proto_tree_add_string(tipc_tree, hf_tipcv2_node_address, tipc_tvb, offset, 4,   addr_str_ptr);
796                                 offset = offset + 4;
797                         default:
798                                 break;
799                         }
800                         break;
801                 case TIPCv2_CHANGEOVER_PROTOCOL:
802                         /* W1 */
803                         proto_tree_add_item(tipc_tree, hf_tipcv2_changeover_mtype, tipc_tvb, offset, 4, FALSE);
804                         offset = offset + 4;
805                         /* W2 */
806                         offset = offset + 4;
807                         /* W3 */
808                         proto_tree_add_string(tipc_tree, hf_tipcv2_prev_node, tipc_tvb, offset, 4,      addr_str_ptr);
809                         offset = offset + 4;
810                         /* W4 */
811                         offset = offset + 4;
812                         /* W5 */
813                         offset = offset + 4;
814                         /* W6 */
815                         proto_tree_add_text(tipc_tree, tipc_tvb, offset, 4,"Word 6 Unused for this user");
816                         offset = offset + 4;
817                         /* W7 */
818                         proto_tree_add_text(tipc_tree, tipc_tvb, offset, 4,"Word 7 Unused for this user");
819                         offset = offset + 4;
820                         /* W8 */
821                         offset = offset + 4;
822                         /* W9 */
823                         /* Message Count: 16 bits. */
824                         offset = offset + 4;
825                         break;
826                 case TIPCv2_NAME_DISTRIBUTOR:
827                         /* W1 */
828                         proto_tree_add_item(tipc_tree, hf_tipcv2_naming_mtype, tipc_tvb, offset, 4, FALSE);
829                         offset = offset + 4;
830                         /* W2 */
831                         offset = offset + 4;
832                         /* W3 */
833                         proto_tree_add_string(tipc_tree, hf_tipcv2_prev_node, tipc_tvb, offset, 4,      addr_str_ptr);
834                         offset = offset + 4;
835                         /* W4 */
836                         offset = offset + 4;
837                         /* W5 */
838                         offset = offset + 4;
839                         /* W6 */
840                         /* Originating Node: 32 bits. */
841                         dword = tvb_get_ntohl(tipc_tvb,offset);
842                         addr_str_ptr = tipc_addr_to_str(dword);
843                         proto_tree_add_string(tipc_tree, hf_tipcv2_dest_node, tipc_tvb, offset, 4,      addr_str_ptr);
844                         offset = offset + 4;
845                         /* W7 */
846                         /* Destination Node: 32 bits.  */
847                         dword = tvb_get_ntohl(tipc_tvb,offset);
848                         addr_str_ptr = tipc_addr_to_str(dword);
849                         proto_tree_add_string(tipc_tree, hf_tipcv2_orig_node, tipc_tvb, offset, 4,      addr_str_ptr);
850                         offset = offset + 4;
851                         /* W8 */
852                         /* Transport Level Sequence Number: 32 bits */
853                         offset = offset + 4;
854                         /* W9 */
855                         /* Message Count: 16 bits. */
856                         offset = offset + 4;
857                         /* W10 */
858                         data_tvb = tvb_new_subset(tipc_tvb, offset, -1, -1);
859                         dissect_tipc_name_dist_data(data_tvb, pinfo, tipc_tree);
860                         break;
861                 case TIPCv2_MSG_FRAGMENTER:
862                         /* W1 */
863                         proto_tree_add_item(tipc_tree, hf_tipcv2_fragmenter_mtype, tipc_tvb, offset, 4, FALSE);
864                         /* Last 16 bits */
865                         proto_tree_add_item(tipc_tree, hf_tipcv2_fragment_number, tipc_tvb, offset, 4, FALSE);
866                         offset = offset + 4;
867                         /* W2 */
868                         offset = offset + 4;
869                         /* W3 */
870                         proto_tree_add_string(tipc_tree, hf_tipcv2_prev_node, tipc_tvb, offset, 4,      addr_str_ptr);
871                         offset = offset + 4;
872                         /* W4 */
873                         /* Fragment Number: 16 Bits. */
874                         /* Fragment (msg?) Number: 16 bits */
875                         offset = offset + 4;
876                         /* W5 */
877                         offset = offset + 4;
878                         /* W6 */
879                         proto_tree_add_text(tipc_tree, tipc_tvb, offset, 4,"Word 6 Unused for this user");
880                         offset = offset + 4;
881                         /* W7 */
882                         proto_tree_add_text(tipc_tree, tipc_tvb, offset, 4,"Word 7 Unused for this user");
883                         offset = offset + 4;
884                         break;
885                 case TIPCv2_LINK_CONFIGURATION:
886 /*
887 The protocol for neighbour detection
888    uses a special message format, with the following generic structure:
889
890         0                   1                   2                   3
891        0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
892       +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
893    w0:|vers |msg usr|hdr sz |n|resrv|            packet size          |
894       +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
895    w1:|m typ|0| requested links       |       broadcast ack no        |
896       +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
897    w2:|                      destination domain                       |
898       +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
899    w3:|                       previous node                           |
900       +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
901    w4:|                      network identity                         |
902       +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
903    w5:|                                                               |
904       +-+-+-+-+-+-+-                                    +-+-+-+-+-+-+-+
905    w6:|                                                               |
906       +-+-+-+-+-+-+-  bearer level originating address  +-+-+-+-+-+-+-+
907    w7:|                                                               |
908       +-+-+-+-+-+-+-                                    +-+-+-+-+-+-+-+
909    w8:|                                                               |
910       +-+-+-+-+-+-+-                                    +-+-+-+-+-+-+-+
911    w9:|                                                               |
912       +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
913       \                                                               \
914       /                 vendor specific data  (optional)              /
915       \                                                               \
916       +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
917           */
918                         /* W1 */
919                         proto_tree_add_item(tipc_tree, hf_tipcv2_neighbour_mtype, tipc_tvb, offset, 4, FALSE);
920                         /* Requested Links (12 bits) */
921                         proto_tree_add_item(tipc_tree, hf_tipcv2_broadcast_ack_no , tipc_tvb, offset, 4, FALSE);
922                         offset = offset + 4;
923                         /* W2 */
924                         /* Destination Domain */
925                         dword = tvb_get_ntohl(tipc_tvb,offset);
926                         addr_str_ptr = tipc_addr_to_str(dword);
927                         proto_tree_add_string(tipc_tree, hf_tipcv2_destination_domain, tipc_tvb, offset, 4,     addr_str_ptr);
928                         offset = offset + 4;
929                         /* W3 */
930                         dword = tvb_get_ntohl(tipc_tvb,offset);
931                         addr_str_ptr = tipc_addr_to_str(dword);
932                         proto_tree_add_string(tipc_tree, hf_tipcv2_prev_node, tipc_tvb, offset, 4,      addr_str_ptr);
933                         offset = offset + 4;
934                         /* W4 */
935                         /* Network Identity: */
936                         dword = tvb_get_ntohl(tipc_tvb,offset);
937                         addr_str_ptr = tipc_addr_to_str(dword);
938                         proto_tree_add_string(tipc_tree, hf_tipcv2_network_id, tipc_tvb, offset, 4,     addr_str_ptr);
939                         offset = offset + 4;
940                         /* W5 - W9 Bearer Level Originating Address: */
941                         proto_tree_add_item(tipc_tree, hf_tipcv2_bearer_level_orig_addr, tipc_tvb, offset, 20, FALSE);
942                         offset = offset + 20;
943                         /*
944                         proto_tree_add_text(tipc_tree, tipc_tvb, offset, -1,"Vendor specific data");
945                         */
946                         break;
947                 default:
948                         break;           
949         }
950
951 }
952
953 /* Version 2 Header (draft-maloy-tipc-01.txt):
954 4.1.1 Payload Message Header Format
955
956
957        0                   1                   2                   3
958        0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
959       +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
960    w0:|vers | user  |hdr sz |n|d|rsv|          message size           |
961       +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
962    w1:|mstyp| error |rer cnt|lsc|opt p|      broadcast ack no         |
963       +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
964    w2:|        link level ack no      |   broadcast/link level seq no |
965       +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
966    w3:|                       previous node                           |
967       +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
968    w4:|                      originating port                         |
969       +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
970    w5:|                      destination port                         |
971       +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
972    w6:|                      originating node                         |
973       +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
974    w7:|                      destination node                         |
975       +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
976    w8:|             name type / transport sequence number             |
977       +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
978    w9:|              name instance/multicast lower bound              |
979       +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
980    wA:|                    multicast upper bound                      |
981       +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
982       /                                                               /
983       \                           options                             \
984       /                                                               /
985       +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
986
987   */
988
989 static void
990 dissect_tipc_v2(tvbuff_t *tipc_tvb, packet_info *pinfo, proto_tree *tipc_tree, int offset, guint8 user, guint32 msg_size, guint8 hdr_size,  gboolean datatype_hdr)
991 {
992         guint32 dword;
993         gchar *addr_str_ptr;
994         guint8 opt_p;
995         /* The unit used is 32 bit words */
996         guint8 orig_hdr_size;
997
998         orig_hdr_size = hdr_size;
999
1000         /*
1001          * Word 0
1002          */
1003         /* Version: 3 bits */
1004         proto_tree_add_item(tipc_tree, hf_tipc_ver, tipc_tvb, offset, 4, FALSE);
1005         /* User: 4 bits */
1006         proto_tree_add_item(tipc_tree, hf_tipcv2_usr, tipc_tvb, offset, 4, FALSE);
1007         /* Header Size: 4 bits */
1008         proto_tree_add_item(tipc_tree, hf_tipc_hdr_size, tipc_tvb, offset, 4, FALSE);
1009         /* Non-sequenced: 1 bit */
1010         proto_tree_add_item(tipc_tree,hf_tipc_nonsequenced, tipc_tvb,offset,4, FALSE);
1011         if (datatype_hdr)
1012                 /* Drop: 1 bit */
1013                 proto_tree_add_item(tipc_tree,hf_tipc_destdrop, tipc_tvb,offset,4, FALSE);
1014         /* Reserved: 2 bits */
1015
1016         /* Message Size: 17 bits */
1017         proto_tree_add_item(tipc_tree, hf_tipc_msg_size, tipc_tvb, offset, 4, FALSE);
1018         offset = offset + 4;
1019         
1020         if (!datatype_hdr){
1021                 dissect_tipc_v2_internal_msg(tipc_tvb, pinfo, tipc_tree, offset, user, msg_size);
1022                 return;
1023         }
1024
1025         /* Word 1 */ 
1026         /* Message Type: 3 bits */
1027         proto_tree_add_item(tipc_tree, hf_tipcv2_data_msg_type , tipc_tvb, offset, 4, FALSE);
1028         /* Error Code: 4 bits */
1029         proto_tree_add_item(tipc_tree, hf_tipcv2_errorcode , tipc_tvb, offset, 4, FALSE);
1030         /* Reroute Counter: 4 bits */
1031         proto_tree_add_item(tipc_tree, hf_tipcv2_rer_cnt , tipc_tvb, offset, 4, FALSE);
1032         /* Lookup Scope: 2 bits */
1033         proto_tree_add_item(tipc_tree, hf_tipcv2_lookup_scope , tipc_tvb, offset, 4, FALSE);
1034
1035         /* Options Position: 3 bits */
1036         opt_p = tvb_get_guint8(tipc_tvb, offset+1) & 0x7;
1037         proto_tree_add_item(tipc_tree, hf_tipcv2_opt_p , tipc_tvb, offset, 4, FALSE);
1038         if (opt_p != 0){
1039                 hdr_size = hdr_size - (opt_p << 2);     
1040         }
1041         /* Broadcast Acknowledge Number: 16 bits */
1042         proto_tree_add_item(tipc_tree, hf_tipcv2_broadcast_ack_no , tipc_tvb, offset, 4, FALSE);
1043         offset = offset + 4;
1044
1045         /* W2 */        
1046         /* Link Level Acknowledge Number: 16 bits */
1047         proto_tree_add_item(tipc_tree, hf_tipcv2_link_level_ack_no , tipc_tvb, offset, 4, FALSE);
1048         /* broadcast/link level seq no */
1049         proto_tree_add_item(tipc_tree, hf_tipcv2_link_level_seq_no , tipc_tvb, offset, 4, FALSE);
1050         offset = offset + 4;
1051         /* W3 previous node */
1052         dword = tvb_get_ntohl(tipc_tvb,offset);
1053         addr_str_ptr = tipc_addr_to_str(dword);
1054         proto_tree_add_string(tipc_tree, hf_tipcv2_prev_node, tipc_tvb, offset, 4,      addr_str_ptr);
1055         offset = offset + 4;
1056
1057         /* W4 Originating Port: 32 bits */
1058         proto_tree_add_item(tipc_tree, hf_tipc_org_port , tipc_tvb, offset, 4, FALSE);
1059         offset = offset + 4;
1060
1061         /* W5 Destination Port: 32 bits */
1062         proto_tree_add_item(tipc_tree, hf_tipc_dst_port , tipc_tvb, offset, 4, FALSE);
1063         offset = offset + 4;
1064         if (hdr_size > 6 ){
1065
1066                 /* W6 Originating Node: 32 bits */
1067                 dword = tvb_get_ntohl(tipc_tvb,offset);
1068                 addr_str_ptr = tipc_addr_to_str(dword);
1069                 proto_tree_add_string(tipc_tree, hf_tipcv2_orig_node, tipc_tvb, offset, 4,      addr_str_ptr);
1070                 offset = offset + 4;
1071                 /* W7 Destination Node: 32 bits */
1072                 dword = tvb_get_ntohl(tipc_tvb,offset);
1073                 addr_str_ptr = tipc_addr_to_str(dword);
1074                 proto_tree_add_string(tipc_tree, hf_tipcv2_dest_node, tipc_tvb, offset, 4,      addr_str_ptr);
1075                 offset = offset + 4;
1076                 if (hdr_size > 8 ){
1077                         /* W8 name type / transport sequence number */
1078                         /* Transport Level Sequence Number: 32 bits */
1079                         /* Port Name Type: 32 bits */
1080                         proto_tree_add_item(tipc_tree, hf_tipcv2_port_name_type , tipc_tvb, offset, 4, FALSE);
1081                         offset = offset + 4;
1082                         
1083                         if (hdr_size > 9 ){
1084                                 /* W9 name instance/multicast lower bound  */
1085                                 /*  Port Name Instance: 32 bits */
1086                                 proto_tree_add_item(tipc_tree, hf_tipcv2_port_name_instance , tipc_tvb, offset, 4, FALSE);
1087                                 /*  Port Name Sequence Lower: 32 bits */
1088                                 offset = offset + 4;
1089                                 if (hdr_size > 10 ){
1090
1091                                         /* W10 multicast upper bound */
1092                                         /* Port Name Sequence Upper: 32 bits */
1093                                         offset = offset + 4;
1094                                 }                                               
1095                         }
1096                 }
1097         }
1098         /* Options */
1099         if (opt_p != 0){
1100                 proto_tree_add_text(tipc_tree, tipc_tvb, offset,(opt_p >> 2),"Options");
1101                 offset = offset + (opt_p << 2);
1102         }
1103         /* TIPCv2 data */
1104         if ( msg_size > (orig_hdr_size<<2))
1105                 proto_tree_add_text(tipc_tree, tipc_tvb, offset, -1,"TIPCv2 data");
1106
1107 }
1108
1109 /*  From message.h (http://cvs.sourceforge.net/viewcvs.py/tipc/source/stable_ericsson/TIPC_SCC/src/Message.h?rev=1.2&view=markup)
1110         ////////////////////////////////////////////////////////////////////
1111                 TIPC internal header format, version 1:
1112
1113    :                                                               :
1114    |                 Word 0-2: common to all users                 |
1115    |                                                               |
1116    +-------+-------+-------+-------+-------+-------+-------+-------+
1117    |netw-|imp|link |                               | |p|bea- |link |
1118 w3:|ork  |ort|sel- |        message count          | |r|rer  |sel- | 
1119    |id   |anc|ector|                               | |b|id   |ector| 
1120    +-------+-------+-------+-------+-------+-------+-------+-------+
1121    |                                                               |
1122 w4:|                        remote address                         |
1123    |                                                               |
1124    +-------+-------+-------+-------+-------+-------+-------+-------+
1125    | msg   |                       |                               |
1126 w5:| type  |           gap         |           next sent           |
1127    |       |                       |                               |
1128    +-------+-------+-------+-------+-------+-------+-------+-------+
1129    |                       | link    |                             |
1130 w6:|        reserve        | prio-   |        link tolerance       |
1131    |                       | ity     |                             |
1132    +-------+-------+-------+-------+-------+-------+-------+-------+
1133    |                                                               |
1134 w7:|                                                               |
1135    |                                                               |
1136    +-------+-------+                               +-------+-------+
1137    |                                                               |
1138 w8:|                                                               |
1139    |                                                               |
1140    +-------+-------+       bearer name             +-------+-------+
1141    |                                                               |
1142 w9:|                                                               |
1143    |                                                               |
1144    +-------+-------+                               +-------+-------+
1145    |                                                               |
1146 wa:|                                                               |
1147    |                                                               |
1148    +-------+-------+-------+-------+-------+-------+-------+-------+
1149
1150  NB: Connection Manager and Name Distributor use data message format.
1151   
1152         
1153
1154 */
1155
1156 static void
1157 dissect_tipc_int_prot_msg(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tipc_tree,int offset,guint8 user, guint32 msg_size)
1158 {       
1159         guint8 msg_type;
1160         tvbuff_t *data_tvb;
1161         guint16 message_count;
1162         guint32 msg_in_bundle_size;
1163         guint32 dword;
1164         guint msg_no = 0;
1165         guint8 link_sel;
1166         guint16 link_lev_seq_no;
1167         guint32 reassembled_msg_length = 0;
1168         guint32 no_of_segments = 0;
1169
1170         gboolean   save_fragmented;
1171         tvbuff_t* new_tvb = NULL;
1172         tvbuff_t* next_tvb = NULL;
1173         fragment_data *frag_msg = NULL;
1174         proto_item *item;
1175         
1176         link_lev_seq_no = tvb_get_ntohl(tvb,4) & 0xffff;
1177         /* Internal Protocol Header */
1178         /* Unused */
1179
1180         msg_type = tvb_get_guint8(tvb,20)>>4;
1181         /* W3 */
1182         dword = tvb_get_ntohl(tvb,offset);
1183         link_sel = dword & 0x7;
1184         proto_tree_add_item(tipc_tree, hf_tipc_unused2, tvb, offset, 4, FALSE);
1185         /* Importance */
1186         if ( user == TIPC_SEGMENTATION_MANAGER)
1187                 proto_tree_add_item(tipc_tree, hf_tipc_importance, tvb, offset, 4, FALSE);
1188         /* Link selector */
1189         if ( user == TIPC_SEGMENTATION_MANAGER || user == TIPC_NAME_DISTRIBUTOR || user == TIPC_CHANGEOVER_PROTOCOL )
1190                 proto_tree_add_item(tipc_tree, hf_tipc_link_selector, tvb, offset, 4, FALSE);
1191         /* Message count */
1192         if ( user == TIPC_MSG_BUNDLER || user == TIPC_CHANGEOVER_PROTOCOL ){
1193                 message_count = tvb_get_ntohs(tvb,offset+2);
1194                 proto_tree_add_item(tipc_tree, hf_tipc_msg_cnt, tvb, offset, 4, FALSE);
1195         }
1196         /* Unused */
1197         /* Probe */
1198         if ( user == TIPC_LINK_PROTOCOL )
1199                 proto_tree_add_item(tipc_tree, hf_tipc_probe, tvb, offset, 4, FALSE);
1200         /* Bearer identity */
1201         if ( user == TIPC_LINK_PROTOCOL || user == TIPC_CHANGEOVER_PROTOCOL )
1202                 proto_tree_add_item(tipc_tree, hf_tipc_bearer_id, tvb, offset, 4, FALSE);
1203         /* Link selector */
1204         if ( user == TIPC_SEGMENTATION_MANAGER || user == TIPC_NAME_DISTRIBUTOR || user == TIPC_CHANGEOVER_PROTOCOL )
1205                 proto_tree_add_item(tipc_tree, hf_tipc_link_selector2, tvb, offset, 4, FALSE);
1206         
1207         offset = offset + 4;
1208
1209         /* W4 */
1210         /* Remote address */
1211         if ( user == TIPC_ROUTING_MANAGER )
1212                 proto_tree_add_item(tipc_tree, hf_tipc_remote_addr, tvb, offset, 4, FALSE);
1213         offset = offset + 4;
1214         
1215         /* W5 */
1216         /* Message type */
1217         switch (user){
1218         case TIPC_ROUTING_MANAGER:
1219                 proto_tree_add_item(tipc_tree, hf_tipc_rm_msg_type, tvb, offset, 4, FALSE);
1220                 break;
1221         case TIPC_NAME_DISTRIBUTOR:
1222                 proto_tree_add_item(tipc_tree, hf_tipc_nd_msg_type, tvb, offset, 4, FALSE);
1223                 break;
1224         case TIPC_CONNECTION_MANAGER:
1225                 break;
1226         case TIPC_LINK_PROTOCOL:
1227                 proto_tree_add_item(tipc_tree, hf_tipc_lp_msg_type, tvb, offset, 4, FALSE);
1228                 break;
1229         case TIPC_CHANGEOVER_PROTOCOL:
1230                 proto_tree_add_item(tipc_tree, hf_tipc_cng_prot_msg_type, tvb, offset, 4, FALSE);
1231                 break;
1232         case TIPC_SEGMENTATION_MANAGER:
1233                 proto_tree_add_item(tipc_tree, hf_tipc_sm_msg_type, tvb, offset, 4, FALSE);
1234                 break;
1235         default:
1236                 proto_tree_add_item(tipc_tree, hf_tipc_unknown_msg_type, tvb, offset, 4, FALSE);
1237                 break;
1238         }
1239         /* Sequence gap */
1240         if ( user == TIPC_LINK_PROTOCOL && msg_type == TIPC_LINK_PROTOCO_STATE_MSG )
1241                 proto_tree_add_item(tipc_tree, hf_tipc_seq_gap, tvb, offset, 4, FALSE);
1242         /* Next sent packet */
1243         proto_tree_add_item(tipc_tree, hf_tipc_nxt_snt_pkg, tvb, offset, 4, FALSE);
1244
1245         offset = offset + 4;
1246         /* W6 */
1247         /* Unused */
1248         proto_tree_add_item(tipc_tree, hf_tipc_unused3, tvb, offset, 4, FALSE);
1249         offset = offset + 4;
1250         /*W7 */
1251         if (msg_size == 28) /* No data */
1252                 return;
1253
1254         switch (user){
1255                 case TIPC_LINK_PROTOCOL:
1256                         proto_tree_add_item(tipc_tree, hf_tipc_bearer_name, tvb, offset, -1, FALSE);
1257                         break;
1258                 case TIPC_CHANGEOVER_PROTOCOL:
1259                         switch (msg_type){
1260                         case 0: /* DUPLICATE_MSG */
1261                         case 1: /* ORIGINAL_MSG */
1262                                 proto_tree_add_text(tipc_tree, tvb, offset, -1,"TIPC_CHANGEOVER_PROTOCOL %s (%u)",val_to_str(msg_type, tipc_cng_prot_msg_type_values, "unknown"),msg_type);
1263                                 data_tvb = tvb_new_subset(tvb, offset, -1, -1);
1264                                 if (check_col(pinfo->cinfo, COL_INFO))
1265                                         col_set_fence(pinfo->cinfo, COL_INFO);
1266                                 dissect_tipc(data_tvb, pinfo, tipc_tree);
1267                                 break;
1268                         default:
1269                                 /*      INFO_MSG: Even when there are no packets in the send queue of a removed link, the other
1270                                         endpoint must be informed about this fact, so it can be unblocked when it has terminated its
1271                                         part of the changeover procedure. This message type may be regarded as an empty
1272                                         ORIGINAL_MSG, where message count is zero, and no packet is wrapped inside.
1273                                 */
1274                                 proto_tree_add_text(tipc_tree, tvb, offset, -1,"TIPC_CHANGEOVER_PROTOCOL Protol/dissection Error");
1275                                 return;
1276                                 break;
1277                         }
1278                         break;
1279                 case TIPC_SEGMENTATION_MANAGER:
1280                         save_fragmented = pinfo->fragmented;
1281                         if (tipc_defragment){
1282                                 pinfo->fragmented = TRUE;
1283                         
1284                                 frag_msg = fragment_add_seq_next(tvb, offset, pinfo,
1285                                                 link_sel,                                                       /* ID for fragments belonging together - NEEDS IMPROVING? */  
1286                                                 tipc_msg_fragment_table,                        /* list of message fragments */
1287                                                 tipc_msg_reassembled_table,                     /* list of reassembled messages */
1288                                                 tvb_length_remaining(tvb, offset),      /* fragment length - to the end */
1289                                                 TRUE);                                                          /* More fragments? */
1290                                 if (msg_type == TIPC_FIRST_SEGMENT ){
1291                                         reassembled_msg_length = tvb_get_ntohl(tvb,offset) & 0x1ffff;
1292                                         /* The number of segments needed fot he complete message (Including header) will be
1293                                          * The size of the data section of the first message, divided by the complete message size
1294                                          * + one segment for the remainder (if any).
1295                                          */
1296                                         no_of_segments = reassembled_msg_length/(msg_size - 28);
1297                                         if (reassembled_msg_length > (no_of_segments * (msg_size - 28)))
1298                                                 no_of_segments++;
1299                                         fragment_set_tot_len(pinfo, link_sel, tipc_msg_fragment_table, no_of_segments-1);
1300                                         item = proto_tree_add_text(tipc_tree, tvb, offset, -1,"Segmented message size %u bytes -> No segments = %i",reassembled_msg_length,no_of_segments);
1301                                         PROTO_ITEM_SET_GENERATED(item);
1302                                 }
1303
1304                                 new_tvb = process_reassembled_data(tvb, offset, pinfo,
1305                                         "Reassembled Message", frag_msg, &tipc_msg_frag_items,
1306                                         NULL, tipc_tree);
1307
1308                                 if (frag_msg) { /* Reassembled */
1309                                         if (check_col(pinfo->cinfo, COL_INFO))
1310                                                 col_append_str(pinfo->cinfo, COL_INFO, 
1311                                                 " (Message Reassembled)");
1312                                 } else { /* Not last packet of reassembled Short Message */
1313                                         if (check_col(pinfo->cinfo, COL_INFO))
1314                                                 col_append_fstr(pinfo->cinfo, COL_INFO,
1315                                                 " (Message fragment %u)", link_lev_seq_no);
1316                                 }
1317                         }
1318
1319                         if (new_tvb) { /* take it all */
1320                                 next_tvb = new_tvb;
1321                         } else { /* make a new subset */
1322                                 next_tvb = tvb_new_subset(tvb, offset, -1, -1);
1323                         }
1324                         pinfo->fragmented = save_fragmented;
1325                         if (new_tvb){
1326                                 if (check_col(pinfo->cinfo, COL_INFO))
1327                                         col_set_fence(pinfo->cinfo, COL_INFO);
1328                                 dissect_tipc(next_tvb, pinfo, tipc_tree);
1329                                 return;
1330                         }
1331                 
1332                         proto_tree_add_text(tipc_tree, next_tvb, 0, -1,"%u bytes Data Fragment",(msg_size - 28));
1333                         return;
1334                         break;
1335                 case TIPC_MSG_BUNDLER:
1336                         proto_tree_add_text(tipc_tree, tvb, offset, -1,"Message Bundle");
1337                         while ((guint32)offset < msg_size ){
1338                                 msg_no++;
1339                                 msg_in_bundle_size = tvb_get_ntohl(tvb,offset);
1340                                 proto_tree_add_text(tipc_tree, tvb, offset, msg_in_bundle_size,"%u Message in Bundle",msg_no);
1341                                 data_tvb = tvb_new_subset(tvb, offset, msg_in_bundle_size, msg_in_bundle_size);
1342                                 if (check_col(pinfo->cinfo, COL_INFO))
1343                                         col_set_fence(pinfo->cinfo, COL_INFO);
1344                                 dissect_tipc(data_tvb, pinfo, tipc_tree);
1345                                 offset = offset + msg_in_bundle_size;
1346                         }
1347                         break;
1348                 default:
1349                         proto_tree_add_text(tipc_tree, tvb, offset, -1,"%u bytes Data",(msg_size - 28));
1350                         break;
1351         }
1352         return;
1353 }
1354
1355
1356 static void
1357 dissect_tipc(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
1358 {
1359
1360         proto_item *ti, *tipc_data_item;
1361         proto_tree *tipc_tree, *tipc_data_tree;
1362         int offset = 0;
1363         int previous_offset;
1364         guint32 dword;
1365         guint8 version;
1366         guint32 msg_size;
1367         guint8 hdr_size;
1368         guint8 user;
1369         gchar *addr_str_ptr;
1370         const guchar            *src_addr, *dst_addr;
1371         tvbuff_t *data_tvb, *tipc_tvb;
1372         gboolean datatype_hdr = FALSE;
1373         guint8 msg_type = 0;
1374
1375                 /* Make entry in Protocol column on summary display */
1376         if (check_col(pinfo->cinfo, COL_PROTOCOL)) 
1377                 col_set_str(pinfo->cinfo, COL_PROTOCOL, "TIPC");
1378
1379         if (check_col(pinfo->cinfo, COL_INFO)) 
1380                 col_clear(pinfo->cinfo, COL_INFO);
1381
1382         top_tree = tree;
1383         dword = tvb_get_ntohl(tvb,offset);
1384         version = (dword >>29) & 0xf;
1385         hdr_size = (dword >>21) & 0xf;
1386         user = (dword>>25) & 0xf;
1387         msg_size = dword & 0x1ffff;
1388
1389         if ( (guint32)tvb_length_remaining(tvb,offset) < msg_size){
1390                 tipc_tvb = tvb;
1391         }else{
1392                 tipc_tvb = tvb_new_subset(tvb, offset, msg_size, msg_size);
1393         }
1394         /* Set User values in COL INFO different in V1 and V2 */
1395         switch (version){
1396         case 0:
1397         case TIPCv1:
1398                 msg_type = tvb_get_guint8(tipc_tvb,offset + 20)>>4;
1399                 if (check_col(pinfo->cinfo, COL_INFO)){
1400                         col_append_fstr(pinfo->cinfo, COL_INFO, " %s(%u) ", val_to_str(user, tipc_user_values, "unknown"),user);
1401                 }
1402                 /* Set msg type in info col and find out if its a data hdr or not */
1403                 datatype_hdr = tipc_v1_set_col_msgtype(pinfo, user, msg_type);
1404                 if ( datatype_hdr ){
1405                         /* Data type header */
1406                         if ( hdr_size > 5 && user <4){
1407                                 /* W6 Originating Processor */
1408                                 src_addr = tvb_get_ptr(tipc_tvb, offset + 24, 4);
1409                                 SET_ADDRESS(&pinfo->src, AT_TIPC, 4, src_addr);
1410         
1411                                 /* W7 Destination Processor */
1412                                 dst_addr = tvb_get_ptr(tipc_tvb, offset + 28, 4);
1413                                 SET_ADDRESS(&pinfo->dst, AT_TIPC, 4, dst_addr);
1414                         }else{
1415                                 /* Short data hdr */
1416                                 /* W2 Previous Processor */
1417                                 src_addr = tvb_get_ptr(tipc_tvb, offset + 8, 4);
1418                                 SET_ADDRESS(&pinfo->src, AT_TIPC, 4, src_addr);
1419                         }
1420                 }else{
1421                         /* W2 Previous Processor */
1422                         src_addr = tvb_get_ptr(tipc_tvb, offset + 8, 4);
1423                         SET_ADDRESS(&pinfo->src, AT_TIPC, 4, src_addr);
1424                 }
1425                 break;
1426         case TIPCv2:
1427                 msg_type = tvb_get_guint8(tipc_tvb,offset + 4)>>5;
1428                 if (check_col(pinfo->cinfo, COL_INFO)){
1429                         col_append_fstr(pinfo->cinfo, COL_INFO, " %s(%u) ", val_to_str(user, tipcv2_user_values, "unknown"),user);
1430                 }
1431                 /* Set msg type in info col and find out if its a data hdr or not */
1432                 datatype_hdr = tipc_v2_set_col_msgtype(pinfo, user, msg_type);
1433                 if ( datatype_hdr ){
1434                         if (hdr_size > 5){
1435                                 /* W6 Originating Processor */
1436                                 src_addr = tvb_get_ptr(tipc_tvb, offset + 24, 4);
1437                                 SET_ADDRESS(&pinfo->src, AT_TIPC, 4, src_addr);
1438         
1439                                 /* W7 Destination Processor */
1440                                 dst_addr = tvb_get_ptr(tipc_tvb, offset + 28, 4);
1441                                 SET_ADDRESS(&pinfo->dst, AT_TIPC, 4, dst_addr);
1442                         }else{
1443                                 /* W2 Previous Processor */
1444                                 src_addr = tvb_get_ptr(tipc_tvb, offset + 8, 4);
1445                                 SET_ADDRESS(&pinfo->src, AT_TIPC, 4, src_addr);
1446                         }
1447
1448                 }else{
1449                         if (user != TIPCv2_LINK_CONFIGURATION){
1450                                 /* W6 Originating Processor */
1451                                 src_addr = tvb_get_ptr(tipc_tvb, offset + 24, 4);
1452                                 SET_ADDRESS(&pinfo->src, AT_TIPC, 4, src_addr);
1453         
1454                                 /* W7 Destination Processor */
1455                                 dst_addr = tvb_get_ptr(tipc_tvb, offset + 28, 4);
1456                                 SET_ADDRESS(&pinfo->dst, AT_TIPC, 4, dst_addr);
1457                         }else{
1458
1459                         }
1460                 }
1461                 break;
1462         default:
1463                 break;
1464         }
1465
1466         ti = proto_tree_add_item(tree, proto_tipc, tipc_tvb, offset, -1, FALSE);
1467         tipc_tree = proto_item_add_subtree(ti, ett_tipc);
1468         if ( version == TIPCv2){
1469                 dissect_tipc_v2(tipc_tvb, pinfo, tipc_tree, offset, user, msg_size, hdr_size, datatype_hdr);
1470                 return;
1471         }
1472         /* Word 0-2 common for all messages
1473          * Word 0
1474          */
1475
1476
1477         proto_tree_add_item(tipc_tree, hf_tipc_ver, tipc_tvb, offset, 4, FALSE);
1478         proto_tree_add_item(tipc_tree, hf_tipc_usr, tipc_tvb, offset, 4, FALSE);
1479         proto_tree_add_item(tipc_tree, hf_tipc_hdr_size, tipc_tvb, offset, 4, FALSE);
1480         proto_tree_add_item(tipc_tree, hf_tipc_unused, tipc_tvb, offset, 4, FALSE);
1481         proto_tree_add_item(tipc_tree,hf_tipc_nonsequenced, tipc_tvb,offset,4, FALSE);
1482         if (datatype_hdr)
1483                 proto_tree_add_item(tipc_tree,hf_tipc_destdrop, tipc_tvb,offset,4, FALSE);
1484
1485         proto_tree_add_item(tipc_tree, hf_tipc_msg_size, tipc_tvb, offset, 4, FALSE);
1486         offset = offset + 4;
1487                 
1488         /* Word 1 */
1489         proto_tree_add_item(tipc_tree, hf_tipc_ack_link_lev_seq, tipc_tvb, offset, 4, FALSE);
1490         proto_tree_add_item(tipc_tree, hf_tipc_link_lev_seq, tipc_tvb, offset, 4, FALSE);
1491         offset = offset + 4;
1492                 
1493         /* Word 2 */
1494         dword = tvb_get_ntohl(tipc_tvb,offset);
1495         addr_str_ptr = tipc_addr_to_str(dword);
1496         proto_tree_add_string(tipc_tree, hf_tipc_prev_proc, tipc_tvb, offset, 4,        addr_str_ptr);
1497
1498         offset = offset + 4;
1499         switch (user){
1500                 case TIPC_ROUTING_MANAGER:
1501                 case TIPC_LINK_PROTOCOL:
1502                 case TIPC_CHANGEOVER_PROTOCOL:
1503                 case TIPC_SEGMENTATION_MANAGER:
1504                 case TIPC_MSG_BUNDLER:
1505                         dissect_tipc_int_prot_msg(tipc_tvb, pinfo, tipc_tree, offset, user, msg_size);
1506                         return;
1507                         break;
1508                 default:
1509                 break;           
1510         }
1511
1512         dword = tvb_get_ntohl(tipc_tvb,offset);
1513         pinfo->ptype = PT_TIPC;
1514         pinfo->srcport = dword;
1515         proto_tree_add_item(tipc_tree, hf_tipc_org_port, tipc_tvb, offset, 4, FALSE);
1516         offset = offset + 4;
1517         if(user != TIPC_NAME_DISTRIBUTOR){
1518                 dword = tvb_get_ntohl(tipc_tvb,offset);
1519                 pinfo->destport = dword;
1520                 proto_tree_add_item(tipc_tree, hf_tipc_dst_port, tipc_tvb, offset, 4, FALSE);
1521         }
1522         offset = offset + 4;
1523         /* 20 - 24 Bytes 
1524                 20 bytes: Used in subnetwork local, connection oriented messages, where error code, reroute
1525                 counter and activity identity are zero. A recipient finding that the header size field is 20 does
1526                 by default know both user (DATA), message type (CONNECTED_MSG), error code
1527                 (MSG_OK), reroute counter (0), and activity identity (undefined). Since no more testing for
1528                 this is needed these fields can be left out in the header. Furthermore, since such messages
1529                 only will do zero or one inter-processor hop, we know that previous processor is the real
1530                 origin of the message. Hence the field originating processor can be omitted. For the same
1531                 reason, the recipient processor will know that it is identical to destination processor, so even
1532                 this field can be skipped. Finally, because the link layer guarantees delivery and sequence
1533                 order for this single hop, even the connection sequence number is redundant. So the message
1534                 can just be passed directly on to the destination port. Since this type of message statistically
1535                 should be by far the most frequent one this small optimization pays off.
1536         */
1537         if ( hdr_size <= 5 ){
1538                 proto_tree_add_text(tipc_tree, tipc_tvb, offset, -1,"%u bytes Data",(msg_size - hdr_size *4));
1539         }else{
1540                 switch (user){
1541                         case TIPC_NAME_DISTRIBUTOR:
1542                                 proto_tree_add_item(tipc_tree, hf_tipc_nd_msg_type, tipc_tvb, offset, 4, FALSE);
1543                                 break;
1544                         case TIPC_CONNECTION_MANAGER:
1545                                 proto_tree_add_item(tipc_tree, hf_tipc_cm_msg_type, tipc_tvb, offset, 4, FALSE);
1546                                 break;
1547                         default:
1548                                 proto_tree_add_item(tipc_tree, hf_tipc_data_msg_type, tipc_tvb, offset, 4, FALSE);
1549                                 break;
1550                         }
1551                         proto_tree_add_item(tipc_tree, hf_tipc_err_code, tipc_tvb, offset, 4, FALSE);
1552                         proto_tree_add_item(tipc_tree, hf_tipc_reroute_cnt, tipc_tvb, offset, 4, FALSE);
1553                         proto_tree_add_item(tipc_tree, hf_tipc_act_id, tipc_tvb, offset, 4, FALSE);
1554                         offset = offset + 4;
1555
1556                         dword = tvb_get_ntohl(tipc_tvb,offset);
1557                         addr_str_ptr = tipc_addr_to_str(dword);
1558
1559                         proto_tree_add_string(tipc_tree, hf_tipc_org_proc, tipc_tvb, offset, 4, addr_str_ptr);
1560                         offset = offset + 4;
1561
1562                         dword = tvb_get_ntohl(tipc_tvb,offset);
1563                         addr_str_ptr = tipc_addr_to_str(dword);
1564
1565                         proto_tree_add_string(tipc_tree, hf_tipc_dst_proc, tipc_tvb, offset, 4, addr_str_ptr);
1566                         offset = offset + 4;
1567                                 /* 32 bytes 
1568                                 32 bytes: The size of all data messages containing an explicit port identity as destination
1569                                 address.
1570                                 */
1571                         if ( hdr_size > 8){
1572                                 if (user == TIPC_NAME_DISTRIBUTOR ){
1573                                         /*
1574                                                 Although an internal service, the name distributor uses the full 40-byte "external" data header
1575                                                 format when updating the naming table instances. This is because its messages may need
1576                                                 routing, - all system processor must contain the publications from all device processors and
1577                                                 vice versa, whether they are directly linked or not. The fields name type, name instance, and
1578                                                 destination port of that header have no meaning for such messages
1579                                                 */
1580                                         offset = offset + 8;
1581                                         tipc_data_item = proto_tree_add_text(tipc_tree, tvb, offset, -1,"TIPC_NAME_DISTRIBUTOR %u bytes User Data",(msg_size - hdr_size *4));
1582                                         tipc_data_tree = proto_item_add_subtree(tipc_data_item , ett_tipc_data);
1583                                         data_tvb = tvb_new_subset(tipc_tvb, offset, -1, -1);
1584                                         dissect_tipc_name_dist_data(data_tvb, pinfo, tipc_data_tree);
1585                                         return;
1586                                 }else{
1587                                         /* Port name type / Connection level sequence number */
1588                                         proto_tree_add_text(tipc_tree, tipc_tvb, offset, 4,"Port name type / Connection level sequence number");
1589                                         offset = offset + 4;
1590                                         /* Port name instance */
1591                                         proto_tree_add_text(tipc_tree, tipc_tvb, offset, 4,"Port name instance");
1592                                         offset = offset + 4;
1593                                 }
1594                         }
1595
1596                         if (user < 4 && dissect_tipc_data){ /* DATA type user */
1597                                 switch (msg_type){
1598                                 case TIPC_CONNECTED_MSG:
1599                                         proto_tree_add_text(tipc_tree, tipc_tvb, offset, -1,"%u bytes Data",(msg_size - hdr_size *4));
1600                                         break;
1601                                 case TIPC_NAMED_MSG:
1602                                         data_tvb = tvb_new_subset(tipc_tvb, offset+14, -1, -1);
1603                                         proto_tree_add_text(tipc_tree, tipc_tvb, offset, 14,"TIPC_NAMED_MSG Hdr");
1604                                         proto_tree_add_text(tipc_tree, data_tvb,0, -1,"%u bytes Data",(msg_size - hdr_size *4));
1605                                         return;
1606                                         break;
1607                                 case TIPC_DIRECT_MSG:
1608                                         previous_offset = offset;
1609                                         while (tvb_reported_length_remaining(tipc_tvb,offset) > 0){
1610                                                 dword = tvb_get_ntohl(tipc_tvb,offset);
1611                                                 if ((dword & 0xff000000) == 0x45000000){ /* && ((dword & 0x0000ffff)== tvb_reported_length_remaining(tvb,offset+2)))*/
1612                                                         data_tvb = tvb_new_subset(tipc_tvb, offset, -1, -1);
1613                                                         call_dissector(ip_handle, data_tvb, pinfo, top_tree);
1614                                                         return;
1615                                                 }
1616                                                 offset = offset+4;
1617                                         }
1618                                         proto_tree_add_text(tipc_tree, tipc_tvb, previous_offset, -1,"%u bytes Data",(msg_size - hdr_size *4));
1619                                         return;
1620                                         break;
1621                                 default:
1622                                         proto_tree_add_text(tipc_tree, tipc_tvb, offset, -1,"%u bytes Data",(msg_size - hdr_size *4));
1623                                         break;
1624                                 }
1625                         }                       
1626                         
1627                 }/*if ( hdr_size <= 5 ) */
1628         /*}if tree */
1629
1630 }
1631
1632
1633
1634
1635 /* Register TIPC with Wireshark */
1636 void
1637 proto_register_tipc(void)
1638 {                 
1639
1640         static hf_register_info hf[] = {
1641
1642                 {&hf_tipc_msg_fragments,
1643                         {"Message fragments", "tipc.msg.fragments",
1644                         FT_NONE, BASE_NONE, NULL, 0x00, NULL, HFILL } 
1645                 },
1646                 {&hf_tipc_msg_fragment,
1647                         {"Message fragment", "tipc.msg.fragment",
1648                         FT_FRAMENUM, BASE_NONE, NULL, 0x00, NULL, HFILL } 
1649                 },
1650                 {&hf_tipc_msg_fragment_overlap,
1651                         {"Message fragment overlap", "tipc.msg.fragment.overlap",
1652                         FT_BOOLEAN, BASE_NONE, NULL, 0x00, NULL, HFILL } 
1653                 },
1654                 {&hf_tipc_msg_fragment_overlap_conflicts,
1655                         {"Message fragment overlapping with conflicting data","tipc.msg.fragment.overlap.conflicts",
1656                         FT_BOOLEAN, BASE_NONE, NULL, 0x00, NULL, HFILL } 
1657                 },
1658                 {&hf_tipc_msg_fragment_multiple_tails,
1659                         {"Message has multiple tail fragments", "tipc.msg.fragment.multiple_tails", 
1660                         FT_BOOLEAN, BASE_NONE, NULL, 0x00, NULL, HFILL } 
1661                 },
1662                 {&hf_tipc_msg_fragment_too_long_fragment,
1663                         {"Message fragment too long", "tipc.msg.fragment.too_long_fragment",
1664                         FT_BOOLEAN, BASE_NONE, NULL, 0x00, NULL, HFILL } 
1665                 },
1666                 {&hf_tipc_msg_fragment_error,
1667                         {"Message defragmentation error", "tipc.msg.fragment.error",
1668                         FT_FRAMENUM, BASE_NONE, NULL, 0x00, NULL, HFILL } 
1669                 },
1670                 {&hf_tipc_msg_reassembled_in,
1671                         {"Reassembled in", "tipc.msg.reassembled.in",
1672                         FT_FRAMENUM, BASE_NONE, NULL, 0x00, NULL, HFILL } 
1673                 },
1674                 { &hf_tipc_ver,
1675                         { "Version",           "tipc.ver",
1676                         FT_UINT32, BASE_DEC, NULL, 0xe0000000,          
1677                         "TIPC protocol version", HFILL }
1678                 },
1679                 { &hf_tipc_usr,
1680                         { "User",           "tipc.usr",
1681                         FT_UINT32, BASE_DEC, VALS(tipc_user_values), 0x1e000000,          
1682                         "TIPC User", HFILL }
1683                 },
1684                 { &hf_tipcv2_usr,
1685                         { "User",           "tipc.usr",
1686                         FT_UINT32, BASE_DEC, VALS(tipcv2_user_values), 0x1e000000,          
1687                         "TIPC User", HFILL }
1688                 },
1689                 { &hf_tipc_hdr_size,
1690                         { "Header size",           "tipc.hdr_size",
1691                         FT_UINT32, BASE_DEC, NULL, 0x01e00000,          
1692                         "TIPC Header size", HFILL }
1693                 },
1694                 { &hf_tipc_nonsequenced,
1695                         { "Non-sequenced","tipc.non_sequenced",
1696                         FT_UINT32,BASE_DEC,NULL,0x00100000,
1697                         "Non-sequenced Bit",HFILL }
1698                 },
1699                 { &hf_tipc_destdrop,
1700                         { "Destination Droppable","tipc.destdrop",
1701                         FT_UINT32,BASE_DEC,NULL,0x00080000,
1702                         "Destination Droppable Bit",HFILL }
1703                 },
1704                 { &hf_tipc_unused,
1705                         { "Unused",           "tipc.hdr_unused",
1706                         FT_UINT32, BASE_DEC, NULL, 0x001e0000,          
1707                         "TIPC Unused", HFILL }
1708                 },
1709                 { &hf_tipc_msg_size,
1710                         { "Message size",           "tipc.msg_size",
1711                         FT_UINT32, BASE_DEC, NULL, 0x0001ffff,          
1712                         "TIPC Message size", HFILL }
1713                 },
1714                 { &hf_tipc_ack_link_lev_seq,
1715                         { "Acknowledged link level sequence number",           "tipc.ack_link_lev_seq",
1716                         FT_UINT32, BASE_DEC, NULL, 0xffff0000,          
1717                         "TIPC Acknowledged link level sequence number", HFILL }
1718                 },
1719                 { &hf_tipc_link_lev_seq,
1720                         { "Link level sequence number",           "tipc.link_lev_seq",
1721                         FT_UINT32, BASE_DEC, NULL, 0x0000ffff,          
1722                         "TIPC Link level sequence number", HFILL }
1723                 },
1724                 { &hf_tipc_prev_proc,
1725                         { "Previous processor",           "tipc.prev_proc",
1726                         FT_STRING, BASE_NONE, NULL, 0x0,          
1727                         "TIPC Previous processor", HFILL }
1728                 },
1729                 { &hf_tipc_org_port,
1730                         { "Originating port",           "tipc.org_port",
1731                         FT_UINT32, BASE_DEC, NULL, 0x0,          
1732                         "TIPC Oiginating port", HFILL }
1733                 },
1734                 { &hf_tipc_dst_port,
1735                         { "Destination port",           "tipc.dst_port",
1736                         FT_UINT32, BASE_DEC, NULL, 0x0,          
1737                         "TIPC Destination port", HFILL }
1738                 },
1739                 { &hf_tipc_data_msg_type,
1740                         { "Message type",           "tipc.msg_type",
1741                         FT_UINT32, BASE_DEC, VALS(tipc_data_msg_type_values), 0xf0000000,          
1742                         "TIPC Message type", HFILL }
1743                 },
1744                 { &hf_tipc_err_code,
1745                         { "Error code",           "tipc.err_code",
1746                         FT_UINT32, BASE_DEC, VALS(tipc_error_code_values), 0x0f000000,          
1747                         "TIPC Error code", HFILL }
1748                 },
1749                 { &hf_tipc_reroute_cnt,
1750                         { "Reroute counter",           "tipc.route_cnt",
1751                         FT_UINT32, BASE_DEC, NULL, 0x00f00000,          
1752                         "TIPC Reroute counter", HFILL }
1753                 },
1754                 { &hf_tipc_act_id,
1755                         { "Activity identity",           "tipc.act_id",
1756                         FT_UINT32, BASE_DEC, NULL, 0x000fffff,          
1757                         "TIPC Activity identity", HFILL }
1758                 },              
1759                 { &hf_tipc_org_proc,
1760                         { "Originating processor",           "tipc.org_proc",
1761                         FT_STRING, BASE_NONE, NULL, 0x0,          
1762                         "TIPC Originating processor", HFILL }
1763                 },
1764                 { &hf_tipc_dst_proc,
1765                         { "Destination processor",           "tipc.dst_proc",
1766                         FT_STRING, BASE_NONE, NULL, 0x0,          
1767                         "TIPC Destination processor", HFILL }
1768                 },
1769                 { &hf_tipc_unused2,
1770                         { "Unused",           "tipc.unused2",
1771                         FT_UINT32, BASE_DEC, NULL, 0xe0000000,          
1772                         "TIPC Unused", HFILL }
1773                 },
1774                 { &hf_tipc_importance,
1775                         { "Importance",           "tipc.importance",
1776                         FT_UINT32, BASE_DEC, NULL, 0x18000000,          
1777                         "TIPC Importance", HFILL }
1778                 },
1779                 { &hf_tipc_link_selector,
1780                         { "Link selector",           "tipc.link_selector",
1781                         FT_UINT32, BASE_DEC, NULL, 0x07000000,          
1782                         "TIPC Link selector", HFILL }
1783                 },
1784                 { &hf_tipc_msg_cnt,
1785                         { "Message count",           "tipc.imsg_cnt",
1786                         FT_UINT32, BASE_DEC, NULL, 0x00ffff00,          
1787                         "TIPC Message count", HFILL }
1788                 },
1789                 { &hf_tipc_probe,
1790                         { "Probe",           "tipc.probe",
1791                         FT_UINT32, BASE_DEC, NULL, 0x00000040,          
1792                         "TIPC Probe", HFILL }
1793                 },
1794                 { &hf_tipc_bearer_id,
1795                         { "Bearer identity",           "tipc.bearer_id",
1796                         FT_UINT32, BASE_DEC, NULL, 0x00000038,          
1797                         "TIPC Bearer identity", HFILL }
1798                 },
1799                 { &hf_tipc_link_selector2,
1800                         { "Link selector",           "tipc.link_selector",
1801                         FT_UINT32, BASE_DEC, NULL, 0x00000007,          
1802                         "TIPC Link selector", HFILL }
1803                 },
1804                 { &hf_tipc_remote_addr,
1805                         { "Remote address",           "tipc.remote_addr",
1806                         FT_UINT32, BASE_DEC, NULL, 0x0,          
1807                         "TIPC Remote address", HFILL }
1808                 },
1809                 { &hf_tipc_rm_msg_type,
1810                         { "Message type",           "tipc.rm_msg_type",
1811                         FT_UINT32, BASE_DEC, VALS(tipc_routing_mgr_msg_type_values), 0xf0000000,          
1812                         "TIPC Message type", HFILL }
1813                 },
1814                 { &hf_tipc_nd_msg_type,
1815                         { "Message type",           "tipc.nd_msg_type",
1816                         FT_UINT32, BASE_DEC, VALS(tipc_name_dist_msg_type_values), 0xf0000000,          
1817                         "TIPC Message type", HFILL }
1818                 },
1819                 { &hf_tipc_cm_msg_type,
1820                         { "Message type",           "tipc.nd_msg_type",
1821                         FT_UINT32, BASE_DEC, VALS(tipc_cm_msg_type_values), 0xf0000000,          
1822                         "TIPC Message type", HFILL }
1823                 },
1824                 { &hf_tipc_lp_msg_type,
1825                         { "Message type",           "tipc.lp_msg_type",
1826                         FT_UINT32, BASE_DEC, VALS(tipc_link_prot_msg_type_values), 0xf0000000,          
1827                         "TIPC Message type", HFILL }
1828                 },
1829                 { &hf_tipc_cng_prot_msg_type,
1830                         { "Message type",           "tipc.cng_prot_msg_type",
1831                         FT_UINT32, BASE_DEC, VALS(tipc_cng_prot_msg_type_values), 0xf0000000,          
1832                         "TIPC Message type", HFILL }
1833                 },
1834                 { &hf_tipc_sm_msg_type,
1835                         { "Message type",           "tipc.sm_msg_type",
1836                         FT_UINT32, BASE_DEC, VALS(tipc_sm_msg_type_values), 0xf0000000,          
1837                         "TIPC Message type", HFILL }
1838                 },
1839                 { &hf_tipc_unknown_msg_type,
1840                         { "Message type",           "tipc.unknown_msg_type",
1841                         FT_UINT32, BASE_DEC, NULL, 0xf0000000,          
1842                         "TIPC Message type", HFILL }
1843                 },
1844                 { &hf_tipc_seq_gap,
1845                         { "Sequence gap",           "tipc.seq_gap",
1846                         FT_UINT32, BASE_DEC, NULL, 0x0fff0000,          
1847                         "TIPC Sequence gap", HFILL }
1848                 },
1849                 { &hf_tipc_nxt_snt_pkg,
1850                         { "Next sent packet",           "tipc.nxt_snt_pkg",
1851                         FT_UINT32, BASE_DEC, NULL, 0x0000ffff,          
1852                         "TIPC Next sent packet", HFILL }
1853                 },
1854                 { &hf_tipc_unused3,
1855                         { "Unused",           "tipc.unused3",
1856                         FT_UINT32, BASE_DEC, NULL, 0x0,          
1857                         "TIPC Unused", HFILL }
1858                 },
1859                 { &hf_tipc_bearer_name,
1860                         { "Bearer name",           "tipc.bearer_name",
1861                         FT_STRINGZ, BASE_NONE, NULL, 0x0,          
1862                         "TIPC Bearer name", HFILL }
1863                 },
1864                 { &hf_tipc_name_dist_type,
1865                         { "Published port name type", "tipc.name_dist_type",
1866                         FT_UINT32, BASE_DEC, NULL, 0x0,          
1867                         "TIPC Published port name type", HFILL }
1868                 },
1869                 { &hf_tipc_name_dist_lower,
1870                         { "Lower bound of published sequence",  "tipc.ame_dist_lower",
1871                         FT_UINT32, BASE_DEC, NULL, 0x0,          
1872                         "TIPC Lower bound of published sequence", HFILL }
1873                 },
1874                 { &hf_tipc_name_dist_upper,
1875                         { "Upper bound of published sequence",  "tipc.name_dist_upper",
1876                         FT_UINT32, BASE_DEC, NULL, 0x0,          
1877                         "TIPC Upper bound of published sequence", HFILL }
1878                 },
1879                 { &hf_tipc_name_dist_port,
1880                         { "Random number part of port identity", "tipc.dist_port",
1881                         FT_UINT32, BASE_DEC, NULL, 0x0,          
1882                         "TIPC Random number part of port identity", HFILL }
1883                 },
1884                 { &hf_tipc_name_dist_key,
1885                         { "Key (Use for verification at withdrawal)",  "tipc.dist_key",
1886                         FT_UINT32, BASE_DEC, NULL, 0x0,          
1887                         "TIPC key", HFILL }
1888                 },
1889                 { &hf_tipcv2_data_msg_type ,
1890                         { "Message type",           "tipc.data_type",
1891                         FT_UINT32, BASE_DEC, VALS(tipc_data_msg_type_values), 0xe0000000,          
1892                         "TIPC Message type", HFILL }
1893                 },
1894                 { &hf_tipcv2_bcast_mtype ,
1895                         { "Message type",           "tipcv2.bcast_msg_type",
1896                         FT_UINT32, BASE_DEC, VALS(tipcv2_bcast_mtype_strings), 0xe0000000,          
1897                         "TIPC Message type", HFILL }
1898                 },
1899                 { &hf_tipcv2_link_mtype ,
1900                         { "Message type",           "tipcv2.link_msg_type",
1901                         FT_UINT32, BASE_DEC, VALS(tipcv2_link_mtype_strings), 0xe0000000,          
1902                         "TIPC Message type", HFILL }
1903                 },
1904                 { &hf_tipcv2_connmgr_mtype ,
1905                         { "Message type",           "tipcv2.connmgr_msg_type",
1906                         FT_UINT32, BASE_DEC, VALS(tipcv2_connmgr_mtype_strings), 0xe0000000,          
1907                         "TIPC Message type", HFILL }
1908                 },
1909                 { &hf_tipcv2_route_mtype ,
1910                         { "Message type",           "tipcv2.route_msg_type",
1911                         FT_UINT32, BASE_DEC, VALS(tipcv2_route_mtype_strings), 0xe0000000,          
1912                         "TIPC Message type", HFILL }
1913                 },
1914                 { &hf_tipcv2_changeover_mtype ,
1915                         { "Message type",           "tipcv2.changeover_msg_type",
1916                         FT_UINT32, BASE_DEC, VALS(tipcv2_changeover_mtype_strings), 0xe0000000,          
1917                         "TIPC Message type", HFILL }
1918                 },
1919                 { &hf_tipcv2_naming_mtype ,
1920                         { "Message type",           "tipcv2.naming_msg_type",
1921                         FT_UINT32, BASE_DEC, VALS(tipcv2_naming_mtype_strings), 0xe0000000,          
1922                         "TIPC Message type", HFILL }
1923                 },
1924                 { &hf_tipcv2_fragmenter_mtype ,
1925                         { "Message type",           "tipcv2.fragmenter_msg_type",
1926                         FT_UINT32, BASE_DEC, VALS(tipcv2_fragmenter_mtype_strings), 0xe0000000,          
1927                         "TIPC Message type", HFILL }
1928                 },
1929                 { &hf_tipcv2_neighbour_mtype ,
1930                         { "Message type",           "tipcv2.data_msg_type",
1931                         FT_UINT32, BASE_DEC, VALS(tipcv2_neighbour_mtype_strings), 0xe0000000,          
1932                         "TIPC Message type", HFILL }
1933                 },
1934                 { &hf_tipcv2_errorcode ,
1935                         { "Error code",           "tipcv2.errorcode",
1936                         FT_UINT32, BASE_DEC, VALS(tipcv2_error_code_strings), 0x1e000000,          
1937                         "Error code", HFILL }
1938                 },
1939                 { &hf_tipcv2_rer_cnt,
1940                         { "Lookup Scope",           "tipcv2.rer_cnt",
1941                         FT_UINT32, BASE_DEC, NULL, 0x01e00000,          
1942                         "Lookup Scope", HFILL }
1943                 },
1944                 { &hf_tipcv2_lookup_scope,
1945                         { "Reroute Counter",           "tipcv2.lookup_scope",
1946                         FT_UINT32, BASE_DEC, VALS(tipcv2_lookup_scope_strings), 0x00180000,          
1947                         "Reroute Counter", HFILL }
1948                 },
1949                 { &hf_tipcv2_opt_p,
1950                         { "Options Position",           "tipcv2.opt_p",
1951                         FT_UINT32, BASE_DEC, NULL, 0x00070000,          
1952                         "Options Position", HFILL }
1953                 },
1954                 { &hf_tipcv2_broadcast_ack_no,
1955                         { "Broadcast Acknowledge Number",           "tipcv2.broadcast_ack_no",
1956                         FT_UINT32, BASE_DEC, NULL, 0x0000FFFF,          
1957                         "Broadcast Acknowledge Number", HFILL }
1958                 },
1959
1960                 { &hf_tipcv2_link_level_ack_no,
1961                         { "link level ack no",           "tipcv2.link_level_ack_no",
1962                         FT_UINT32, BASE_DEC, NULL, 0xFFFF0000,          
1963                         "link level ack no", HFILL }
1964                 },
1965                 { &hf_tipcv2_link_level_seq_no,
1966                         { "Link Level Sequence Number",           "tipcv2.link_level_seq_no",
1967                         FT_UINT32, BASE_DEC, NULL, 0x0000FFFF,          
1968                         "Link Level Sequence Number", HFILL }
1969                 },
1970                 { &hf_tipcv2_bcast_seq_no,
1971                         { "Broadcast Sequence Number",           "tipcv2.bcast_seq_no",
1972                         FT_UINT32, BASE_DEC, NULL, 0x0000FFFF,          
1973                         "Broadcast Sequence Number", HFILL }
1974                 },
1975                 { &hf_tipcv2_prev_node,
1976                         { "Previous Node",           "tipcv2.prev_node",
1977                         FT_STRING, BASE_NONE, NULL, 0x0,          
1978                         "TIPC Previous Node", HFILL }
1979                 },
1980                 { &hf_tipcv2_orig_node,
1981                         { "Originating Node",           "tipcv2.orig_node",
1982                         FT_STRING, BASE_NONE, NULL, 0x0,          
1983                         "TIPC Originating Node", HFILL }
1984                 },
1985                 { &hf_tipcv2_dest_node,
1986                         { "Destination Node",           "tipcv2.dest_node",
1987                         FT_STRING, BASE_NONE, NULL, 0x0,          
1988                         "TIPC Destination Node", HFILL }
1989                 },
1990                 { &hf_tipcv2_port_name_type,
1991                         { "Port name type",           "tipcv2.port_name_type",
1992                         FT_UINT32, BASE_DEC, NULL, 0,          
1993                         "Port name type", HFILL }
1994                 },
1995                 { &hf_tipcv2_port_name_instance,
1996                         { "Port name instance",           "tipcv2.port_name_instance",
1997                         FT_UINT32, BASE_DEC, NULL, 0,          
1998                         "Port name instance", HFILL }
1999                 },
2000                 { &hf_tipcv2_bcast_seq_gap,
2001                         { "Broadcast Sequence Gap",           "tipcv2.bcast_seq_gap",
2002                         FT_UINT32, BASE_DEC, NULL, 0x1F000000,          
2003                         "Broadcast Sequence Gap", HFILL }
2004                 },
2005                 { &hf_tipcv2_sequence_gap,
2006                         { "Sequence Gap",           "tipcv2.seq_gap",
2007                         FT_UINT32, BASE_DEC, NULL, 0x00FF0000,          
2008                         "Sequence Gap", HFILL }
2009                 },
2010                 { &hf_tipcv2_next_sent_broadcast,
2011                         { "Next Sent Broadcast",           "tipcv2.next_sent_broadcast",
2012                         FT_UINT32, BASE_DEC, NULL, 0x0000FFFF,          
2013                         "Next Sent Broadcast", HFILL }
2014                 },
2015                 { &hf_tipcv2_fragment_number,
2016                         { "Fragment Number",           "tipcv2.fragment_number",
2017                         FT_UINT32, BASE_DEC, NULL, 0x0000FFFF,          
2018                         "Fragment Number", HFILL }
2019                 },
2020                 { &hf_tipcv2_next_sent_packet,
2021                         { "Next Sent Packet",           "tipcv2.next_sent_packet",
2022                         FT_UINT32, BASE_DEC, NULL, 0x0000FFFF,          
2023                         "Next Sent Packet", HFILL }
2024                 },
2025                 { &hf_tipcv2_session_no,
2026                         { "Session Number",           "tipcv2.session_no",
2027                         FT_UINT32, BASE_DEC, NULL, 0xFFFF0000,          
2028                         "Session Number", HFILL }
2029                 },
2030                 { &hf_tipcv2_link_prio,
2031                         { "Link Priority",           "tipcv2.link_prio",
2032                         FT_UINT32, BASE_DEC, NULL, 0x000001F0,          
2033                         "Link Priority", HFILL }
2034                 },
2035                 { &hf_tipcv2_network_plane,
2036                         { "Network Plane",           "tipcv2.network_plane",
2037                         FT_UINT32, BASE_DEC, VALS(tipcv2_networkplane_strings), 0x0000000E,          
2038                         "Network Plane", HFILL }
2039                 },
2040                 { &hf_tipcv2_probe,
2041                         { "Probe",           "tipcv2.probe",
2042                         FT_UINT32, BASE_DEC, NULL, 0x00000001,          
2043                         "probe", HFILL }
2044                 },
2045                 { &hf_tipcv2_link_tolerance,
2046                         { "Link Tolerance (ms)",           "tipcv2.link_tolerance",
2047                         FT_UINT32, BASE_DEC, NULL, 0x0000FFFF,          
2048                         "Link Tolerance in ms", HFILL }
2049                 },
2050                 { &hf_tipcv2_bearer_instance,
2051                         { "Bearer Instance",           "tipcv2.bearer_instance",
2052                         FT_STRINGZ, BASE_NONE, NULL, 0,          
2053                         "Bearer instance used by the sender node for this link", HFILL }
2054                 },
2055                 { &hf_tipcv2_bearer_level_orig_addr,
2056                         { "Bearer Level Originating Address",           "tipcv2.bearer_level_orig_addr",
2057                         FT_BYTES, BASE_HEX, NULL, 0,          
2058                         "Bearer Level Originating Address", HFILL }
2059                 },
2060                 { &hf_tipcv2_cluster_address,
2061                         { "Cluster Address",           "tipcv2.cluster_address",
2062                         FT_STRING, BASE_NONE, NULL, 0x0,          
2063                         "The remote cluster concerned by the table", HFILL }
2064                 },
2065                 { &hf_tipcv2_bitmap,
2066                         { "Bitmap",           "tipcv2.bitmap",
2067                         FT_BYTES, BASE_HEX, NULL, 0,          
2068                         "Bitmap, indicating to which nodes within that cluster the sending node has direct links", HFILL }
2069                 },
2070                 { &hf_tipcv2_node_address,
2071                         { "Node Address",           "tipcv2.node_address",
2072                         FT_STRING, BASE_NONE, NULL, 0x0,
2073                         "Which node the route addition/loss concern", HFILL }
2074                 },
2075                 { &hf_tipcv2_destination_domain,
2076                         { "Destination Domain",           "tipcv2.destination_domain",
2077                         FT_STRING, BASE_NONE, NULL, 0x0,
2078                         "The domain to which the link request is directed", HFILL }
2079                 },
2080                 { &hf_tipcv2_network_id,
2081                         { "Network Identity",           "tipcv2.network_id",
2082                         FT_STRING, BASE_NONE, NULL, 0x0,
2083                         "The sender node's network identity", HFILL }
2084                 },
2085         };
2086
2087 /* Setup protocol subtree array */
2088         static gint *ett[] = {
2089                 &ett_tipc,
2090                 &ett_tipc_data,
2091                 &ett_tipc_msg_fragment,
2092                 &ett_tipc_msg_fragments,
2093         };
2094
2095         module_t *tipc_module;
2096
2097 /* Register the protocol name and description */
2098         proto_tipc = proto_register_protocol("Transparent Inter Process Communication(TIPC)",
2099             "TIPC", "tipc");
2100
2101 /* Required function calls to register the header fields and subtrees used */
2102         proto_register_field_array(proto_tipc, hf, array_length(hf));
2103         proto_register_subtree_array(ett, array_length(ett));
2104
2105         register_init_routine(tipc_defragment_init);
2106
2107         /* Register configuration options */
2108         tipc_module = prefs_register_protocol(proto_tipc, NULL);
2109
2110         prefs_register_bool_preference(tipc_module, "defragment",
2111                 "Reassemble SEGMENTATION_MANAGER datagrams",
2112                 "Whether SEGMENTATION_MANAGER datagrams should be reassembled",
2113                 &tipc_defragment);
2114
2115         prefs_register_bool_preference(tipc_module, "dissect_tipc_data",
2116                 "Dissect TIPC data",
2117                 "Whether to try to dissect TIPC data or not",
2118                 &dissect_tipc_data);
2119 }
2120
2121 void
2122 proto_reg_handoff_tipc(void)
2123 {
2124         dissector_handle_t tipc_handle;
2125
2126         tipc_handle = create_dissector_handle(dissect_tipc, proto_tipc);
2127         dissector_add("ethertype", ETHERTYPE_TIPC,     tipc_handle);
2128         if (extra_ethertype)
2129                 dissector_add("ethertype", ETHERTYPE_TIPC2,     tipc_handle);
2130         
2131         ip_handle = find_dissector("ip");
2132 }