proto_register/proto_reg_handoff; Various small cleanup and bug-fixing
[obnox/wireshark/wip.git] / plugins / rtnet / packet-rtnet.c
1 /* packet-rtnet.c
2  * Routines for RTnet packet disassembly
3  *
4  * $Id$
5  *
6  * Copyright (c) 2003 by Erwin Rol <erwin@erwinrol.com>
7  * Copyright (c) 2004 by Jan Kiszka <jan.kiszka@web.de>
8  *
9  * Wireshark - Network traffic analyzer
10  * By Gerald Combs <gerald@wireshark.org>
11  * Copyright 1999 Gerald Combs
12  *
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software
25  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
26  */
27
28 /* Include files */
29
30 #ifdef HAVE_CONFIG_H
31 #include "config.h"
32 #endif
33
34 #include "moduleinfo.h"
35
36 #include <stdio.h>
37 #include <stdlib.h>
38 #include <ctype.h>
39 #include <time.h>
40 #include <string.h>
41
42 #include <glib.h>
43 #include <epan/packet.h>
44 #include <epan/addr_resolv.h>
45 #include <epan/etypes.h>
46 #include <epan/strutil.h>
47
48 /*
49  * See
50  *
51  *      http://www.rts.uni-hannover.de/rtnet/
52  */
53
54 #define RTMAC_TYPE_TDMA     0x0001 /* since version 2    */
55 #define RTMAC_TYPE_TDMA_V1  0x9031 /* first TDMA version */
56
57 static const value_string rtmac_type_vals[] = {
58   { RTMAC_TYPE_TDMA,    "TDMA" },
59   { RTMAC_TYPE_TDMA_V1, "TDMA-V1" },
60   { 0, NULL }
61 };
62
63 #define RTMAC_FLAG_TUNNEL   0x01
64 #define RTMAC_FLAGS_RES     0xFE
65
66 #define RTCFG_MSG_S1_CONFIG    0x0
67 #define RTCFG_MSG_ANN_NEW      0x1
68 #define RTCFG_MSG_ANN_REPLY    0x2
69 #define RTCFG_MSG_S2_CONFIG    0x3
70 #define RTCFG_MSG_S2_FRAG      0x4
71 #define RTCFG_MSG_ACK          0x5
72 #define RTCFG_MSG_READY        0x6
73 #define RTCFG_MSG_HBEAT        0x7
74 #define RTCFG_MSG_DEAD_STN     0x8
75
76 static const value_string rtcfg_msg_vals[] = {
77   { RTCFG_MSG_S1_CONFIG, "Stage 1 Config" },
78   { RTCFG_MSG_ANN_NEW,   "New Announce" },
79   { RTCFG_MSG_ANN_REPLY, "Reply Announce" },
80   { RTCFG_MSG_S2_CONFIG, "Stage 2 Config" },
81   { RTCFG_MSG_S2_FRAG,   "Stage 2 Fragment" },
82   { RTCFG_MSG_ACK,       "Acknowledge" },
83   { RTCFG_MSG_READY,     "Ready" },
84   { RTCFG_MSG_HBEAT,     "Heartbeat" },
85   { RTCFG_MSG_DEAD_STN,  "Dead Station" },
86   { 0, NULL }
87 };
88
89 #define RTCFG_ADDRESS_TYPE_MAC  0x00
90 #define RTCFG_ADDRESS_TYPE_IP   0x01
91
92 static const value_string rtcfg_address_type_vals[] = {
93   { RTCFG_ADDRESS_TYPE_MAC,    "MAC" },
94   { RTCFG_ADDRESS_TYPE_IP,     "IP" },
95   { 0, NULL }
96 };
97
98 #define TDMA_V1_MSG_NOTIFY_MASTER          0x10
99 #define TDMA_V1_MSG_REQUEST_TEST           0x11
100 #define TDMA_V1_MSG_ACK_TEST               0x12
101 #define TDMA_V1_MSG_REQUEST_CONF           0x13
102 #define TDMA_V1_MSG_ACK_CONF               0x14
103 #define TDMA_V1_MSG_ACK_ACK_CONF           0x15
104 #define TDMA_V1_MSG_STATION_LIST           0x16
105 #define TDMA_V1_MSG_REQUEST_CHANGE_OFFSET  0x17
106 #define TDMA_V1_MSG_START_OF_FRAME         0x18
107
108 static const value_string tdma_v1_msg_vals[] = {
109   { TDMA_V1_MSG_NOTIFY_MASTER,         "Notify Master" },
110   { TDMA_V1_MSG_REQUEST_TEST,          "Request Test" },
111   { TDMA_V1_MSG_ACK_TEST,              "Acknowledge Test" },
112   { TDMA_V1_MSG_REQUEST_CONF,          "Request Config" },
113   { TDMA_V1_MSG_ACK_CONF,              "Acknowledge Config" },
114   { TDMA_V1_MSG_ACK_ACK_CONF,          "Ack Ack Config" },
115   { TDMA_V1_MSG_STATION_LIST,          "Station List" },
116   { TDMA_V1_MSG_REQUEST_CHANGE_OFFSET, "Request Change Offset" },
117   { TDMA_V1_MSG_START_OF_FRAME,        "Start of Frame" },
118   { 0, NULL }
119 };
120
121 #define TDMA_MSG_SYNC           0x0000
122 #define TDMA_MSG_CAL_REQUEST    0x0010
123 #define TDMA_MSG_CAL_REPLY      0x0011
124
125 static const value_string tdma_msg_vals[] = {
126   { TDMA_MSG_SYNC,              "Synchronisation" },
127   { TDMA_MSG_CAL_REQUEST,       "Request Calibration" },
128   { TDMA_MSG_CAL_REPLY,         "Reply Calibration" },
129   { 0, NULL }
130 };
131
132 static dissector_table_t ethertype_table;
133 static dissector_handle_t data_handle;
134
135 /* Define the rtnet proto */
136 static int proto_rtmac = -1;
137 static int proto_tdma = -1;
138 static int proto_rtcfg = -1;
139
140 /* RTmac Header */
141 static int hf_rtmac_header_type = -1;
142 static int hf_rtmac_header_ver = -1;
143 static int hf_rtmac_header_flags = -1;
144 static int hf_rtmac_header_flags_tunnel = -1;
145 static int hf_rtmac_header_flags_res = -1;
146 static int hf_rtmac_header_res_v1 = -1;
147
148
149 /* RTcfg */
150 static int hf_rtcfg_vers_id = -1;
151 static int hf_rtcfg_vers = -1;
152 static int hf_rtcfg_id = -1;
153 static int hf_rtcfg_address_type = -1;
154 static int hf_rtcfg_client_ip_address = -1;
155 static int hf_rtcfg_server_ip_address = -1;
156 static int hf_rtcfg_burst_rate = -1;
157 static int hf_rtcfg_padding = -1;
158 static int hf_rtcfg_s1_config_length = -1;
159 static int hf_rtcfg_config_data = -1;
160 static int hf_rtcfg_client_flags = -1;
161 static int hf_rtcfg_client_flags_available = -1;
162 static int hf_rtcfg_client_flags_ready = -1;
163 static int hf_rtcfg_client_flags_res = -1;
164 static int hf_rtcfg_server_flags = -1;
165 static int hf_rtcfg_server_flags_res0 = -1;
166 static int hf_rtcfg_server_flags_ready = -1;
167 static int hf_rtcfg_server_flags_res2 = -1;
168 static int hf_rtcfg_active_stations = -1;
169 static int hf_rtcfg_heartbeat_period = -1;
170 static int hf_rtcfg_s2_config_length = -1;
171 static int hf_rtcfg_config_offset = -1;
172 static int hf_rtcfg_ack_length = -1;
173 static int hf_rtcfg_client_hw_address = -1;
174
175
176 /* TDMA-V1 */
177 static int hf_tdma_v1_msg = -1;
178
179 /* TDMA REQUEST_CONF */
180 static int hf_tdma_v1_msg_request_conf_station = -1;
181 static int hf_tdma_v1_msg_request_conf_padding = -1;
182 static int hf_tdma_v1_msg_request_conf_mtu = -1;
183 static int hf_tdma_v1_msg_request_conf_cycle = -1;
184
185 /* TDMA ACK_CONF */
186 static int hf_tdma_v1_msg_ack_conf_station = -1;
187 static int hf_tdma_v1_msg_ack_conf_padding = -1;
188 static int hf_tdma_v1_msg_ack_conf_mtu = -1;
189 static int hf_tdma_v1_msg_ack_conf_cycle = -1;
190
191 /* TDMA ACK_ACK_CONF */
192 static int hf_tdma_v1_msg_ack_ack_conf_station = -1;
193 static int hf_tdma_v1_msg_ack_ack_conf_padding = -1;
194
195 /* TDMA REQUEST_TEST */
196 static int hf_tdma_v1_msg_request_test_counter = -1;
197 static int hf_tdma_v1_msg_request_test_tx = -1;
198
199 /* TDMA ACK_TEST */
200 static int hf_tdma_v1_msg_ack_test_counter = -1;
201 static int hf_tdma_v1_msg_ack_test_tx = -1;
202
203 /* TDMA STATION_LIST */
204 static int hf_tdma_v1_msg_station_list_nr_stations = -1;
205 static int hf_tdma_v1_msg_station_list_padding = -1;
206
207 static int hf_tdma_v1_msg_station_list_ip = -1;
208 static int hf_tdma_v1_msg_station_list_nr = -1;
209
210 /* TDMA CHANGE_OFFSET */
211 static int hf_tdma_v1_msg_request_change_offset_offset = -1;
212
213 /* TDMA START_OF_FRAME */
214 static int hf_tdma_v1_msg_start_of_frame_timestamp = -1;
215
216
217 /* TDMA since version 2 */
218 static int hf_tdma_ver = -1;
219 static int hf_tdma_id = -1;
220
221 /* TDMA Sync */
222 static int hf_tdma_sync_cycle = -1;
223 static int hf_tdma_sync_xmit_stamp = -1;
224 static int hf_tdma_sync_sched_xmit = -1;
225
226 /* TDMA Request Calibration */
227 static int hf_tdma_req_cal_xmit_stamp = -1;
228 static int hf_tdma_req_cal_rpl_cycle = -1;
229 static int hf_tdma_req_cal_rpl_slot = -1;
230
231 /* TDMA Reply Calibration */
232 static int hf_tdma_rpl_cal_req_stamp = -1;
233 static int hf_tdma_rpl_cal_rcv_stamp = -1;
234 static int hf_tdma_rpl_cal_xmit_stamp = -1;
235
236
237 /* Define the tree for rtnet */
238 static int ett_rtmac = -1;
239 static int ett_rtmac_flags = -1;
240 static int ett_tdma = -1;
241 static int ett_rtcfg = -1;
242
243 static guint
244 dissect_rtnet_tdma_notify_master(tvbuff_t *tvb _U_, guint offset, proto_tree *tree _U_)
245 {
246   return offset;
247 }
248
249 static guint
250 dissect_rtnet_tdma_request_test(tvbuff_t *tvb, guint offset, proto_tree *tree)
251 {
252   proto_tree_add_item(tree, hf_tdma_v1_msg_request_test_counter, tvb,
253                        offset, 4, TRUE );
254   offset += 4;
255
256   proto_tree_add_item(tree, hf_tdma_v1_msg_request_test_tx, tvb,
257                        offset, 8, TRUE );
258   offset += 8;
259
260   return offset;
261 }
262
263 static guint
264 dissect_rtnet_tdma_ack_test(tvbuff_t *tvb, guint offset, proto_tree *tree)
265 {
266   proto_tree_add_item(tree, hf_tdma_v1_msg_ack_test_counter, tvb,
267                        offset, 4, TRUE );
268   offset += 4;
269
270   proto_tree_add_item(tree, hf_tdma_v1_msg_ack_test_tx, tvb,
271                        offset, 8, TRUE );
272   offset += 8;
273
274   return offset;
275 }
276
277 static guint
278 dissect_rtnet_tdma_request_conf(tvbuff_t *tvb, guint offset, proto_tree *tree)
279 {
280   proto_tree_add_item(tree, hf_tdma_v1_msg_request_conf_station, tvb,
281                        offset, 1, FALSE );
282   offset += 1;
283
284   proto_tree_add_item(tree, hf_tdma_v1_msg_request_conf_padding, tvb,
285                        offset, 1, FALSE );
286   offset += 1;
287
288   proto_tree_add_item(tree, hf_tdma_v1_msg_request_conf_mtu, tvb,
289                        offset, 2, FALSE );
290   offset += 2;
291
292   proto_tree_add_item(tree, hf_tdma_v1_msg_request_conf_cycle, tvb,
293                        offset, 4, FALSE );
294   offset += 4;
295
296   return offset;
297 }
298
299
300 static guint
301 dissect_rtnet_tdma_ack_conf(tvbuff_t *tvb, guint offset, proto_tree *tree)
302 {
303   proto_tree_add_item(tree, hf_tdma_v1_msg_ack_conf_station, tvb,
304                        offset, 1, FALSE );
305   offset += 1;
306
307   proto_tree_add_item(tree, hf_tdma_v1_msg_ack_conf_padding, tvb,
308                        offset, 1, FALSE );
309   offset += 1;
310
311   proto_tree_add_item(tree, hf_tdma_v1_msg_ack_conf_mtu, tvb,
312                        offset, 2, FALSE );
313   offset += 2;
314
315   proto_tree_add_item(tree, hf_tdma_v1_msg_ack_conf_cycle, tvb,
316                        offset, 4, FALSE );
317   offset += 4;
318
319   return offset;
320 }
321
322 static guint
323 dissect_rtnet_tdma_ack_ack_conf(tvbuff_t *tvb, guint offset, proto_tree *tree) {
324
325   proto_tree_add_item(tree, hf_tdma_v1_msg_ack_ack_conf_station, tvb,
326                        offset, 1, FALSE );
327
328   offset += 1;
329
330   proto_tree_add_item(tree, hf_tdma_v1_msg_ack_ack_conf_padding, tvb,
331                        offset, 3, FALSE );
332   offset += 3;
333
334   return offset;
335 }
336
337 static guint
338 dissect_rtnet_tdma_station_list(tvbuff_t *tvb, guint offset, proto_tree *tree)
339 {
340   guint8 nr_stations;
341   guint8 i;
342
343   nr_stations = tvb_get_guint8(tvb, offset);
344   proto_tree_add_uint(tree, hf_tdma_v1_msg_station_list_nr_stations, tvb,
345                       offset, 1, nr_stations);
346
347   offset += 1;
348
349   proto_tree_add_item(tree, hf_tdma_v1_msg_station_list_padding, tvb,
350                        offset, 3, FALSE );
351   offset += 3;
352
353
354   for( i = 0; i < nr_stations; i++ )
355   {
356     proto_tree_add_item(tree, hf_tdma_v1_msg_station_list_ip, tvb,
357                         offset, 4, FALSE );
358
359     offset += 4;
360
361     proto_tree_add_item(tree, hf_tdma_v1_msg_station_list_nr, tvb,
362                         offset, 1, FALSE );
363
364     offset += 1;
365
366     proto_tree_add_item(tree, hf_tdma_v1_msg_station_list_padding, tvb,
367                         offset, 3, FALSE );
368     offset += 3;
369   }
370
371   return offset;
372 }
373
374 static guint
375 dissect_rtnet_tdma_request_change_offset(tvbuff_t *tvb, guint offset, proto_tree *tree)
376 {
377   proto_tree_add_item(tree, hf_tdma_v1_msg_request_change_offset_offset, tvb,
378                        offset, 4, FALSE );
379
380   offset += 4;
381
382   return offset;
383 }
384
385 static guint
386 dissect_rtnet_tdma_start_of_frame(tvbuff_t *tvb, guint offset, proto_tree *tree)
387 {
388   proto_tree_add_item(tree, hf_tdma_v1_msg_start_of_frame_timestamp, tvb,
389                        offset, 8, FALSE );
390   offset += 8;
391
392   return offset;
393 }
394
395 static void
396 dissect_rtnet_tdma_v1(tvbuff_t *tvb, packet_info *pinfo, proto_tree *root) {
397   guint offset = 0;
398   guint32 msg;
399   proto_tree *tree;
400   proto_item *ti;
401
402   msg = tvb_get_ntohl(tvb, offset);
403
404   /* Set the protocol column */
405   if (check_col(pinfo->cinfo,COL_PROTOCOL)){
406     col_set_str(pinfo->cinfo,COL_PROTOCOL,"TDMA-V1");
407   }
408
409   /* set the info column */
410   if (check_col(pinfo->cinfo, COL_INFO)) {
411     col_add_fstr(pinfo->cinfo, COL_INFO, "%s",
412       val_to_str(msg, tdma_v1_msg_vals, "Unknown (0x%04x)"));
413   }
414
415   if (root) {
416     ti = proto_tree_add_item(root, proto_tdma, tvb, 0, -1, FALSE);
417     tree = proto_item_add_subtree(ti, ett_tdma);
418
419     proto_item_append_text(ti, ", Version 1, %s",
420       val_to_str(msg, tdma_v1_msg_vals, "Unknown (0x%04x)"));
421
422     proto_tree_add_item(tree, hf_tdma_v1_msg, tvb,
423                         offset, 4, FALSE);
424     offset += 4;
425
426     switch( msg ) {
427       case TDMA_V1_MSG_NOTIFY_MASTER:
428         dissect_rtnet_tdma_notify_master(tvb, offset, tree);
429         break;
430
431       case TDMA_V1_MSG_REQUEST_TEST:
432         dissect_rtnet_tdma_request_test(tvb, offset, tree);
433         break;
434
435       case TDMA_V1_MSG_ACK_TEST:
436         dissect_rtnet_tdma_ack_test(tvb, offset, tree);
437         break;
438
439       case TDMA_V1_MSG_REQUEST_CONF:
440         dissect_rtnet_tdma_request_conf(tvb, offset, tree);
441         break;
442
443       case TDMA_V1_MSG_ACK_CONF:
444         dissect_rtnet_tdma_ack_conf(tvb, offset, tree);
445         break;
446
447       case TDMA_V1_MSG_ACK_ACK_CONF:
448         dissect_rtnet_tdma_ack_ack_conf(tvb, offset, tree);
449         break;
450
451       case TDMA_V1_MSG_STATION_LIST:
452         dissect_rtnet_tdma_station_list (tvb, offset, tree);
453         break;
454
455       case TDMA_V1_MSG_REQUEST_CHANGE_OFFSET:
456         dissect_rtnet_tdma_request_change_offset(tvb, offset, tree);
457         break;
458
459       case TDMA_V1_MSG_START_OF_FRAME:
460         dissect_rtnet_tdma_start_of_frame(tvb, offset, tree);
461         break;
462
463       default:
464         break;
465     }
466   }
467 }
468
469 static void
470 dissect_tdma_sync(tvbuff_t *tvb, guint offset, proto_tree *tree) {
471   gint64 time;
472   proto_item *ti;
473
474   proto_tree_add_item(tree, hf_tdma_sync_cycle, tvb, offset, 4, FALSE);
475   offset += 4;
476
477   ti = proto_tree_add_item(tree, hf_tdma_sync_xmit_stamp, tvb, offset, 8, FALSE);
478   time = tvb_get_ntoh64(tvb, offset) - tvb_get_ntoh64(tvb, offset+8);
479   proto_item_append_text(ti, " (%s%" G_GINT64_MODIFIER "d)", (time > 0) ? "+" : "", time);
480   offset += 8;
481
482   proto_tree_add_item(tree, hf_tdma_sync_sched_xmit, tvb, offset, 8, FALSE);
483 }
484
485 static void
486 dissect_tdma_request_cal(tvbuff_t *tvb, guint offset, proto_tree *tree) {
487
488   proto_tree_add_item(tree, hf_tdma_req_cal_xmit_stamp, tvb, offset, 8, FALSE);
489   offset += 8;
490
491   proto_tree_add_item(tree, hf_tdma_req_cal_rpl_cycle, tvb, offset, 4, FALSE);
492   offset += 4;
493
494   proto_tree_add_item(tree, hf_tdma_req_cal_rpl_slot, tvb, offset, 8, FALSE);
495 }
496
497 static void
498 dissect_tdma_reply_cal(tvbuff_t *tvb, guint offset, proto_tree *tree) {
499   gint64 time;
500   proto_item *ti;
501
502   proto_tree_add_item(tree, hf_tdma_rpl_cal_req_stamp, tvb, offset, 8, FALSE);
503   offset += 8;
504
505   proto_tree_add_item(tree, hf_tdma_rpl_cal_rcv_stamp, tvb, offset, 8, FALSE);
506
507   time = tvb_get_ntoh64(tvb, offset+8) - tvb_get_ntoh64(tvb, offset);
508   offset += 8;
509
510   ti = proto_tree_add_item(tree, hf_tdma_rpl_cal_xmit_stamp, tvb, offset, 8, FALSE);
511   proto_item_append_text(ti, " (%s%" G_GINT64_MODIFIER "d)", (time > 0) ? "+" : "", time);
512 }
513
514 static void
515 dissect_rtnet_tdma(tvbuff_t *tvb, packet_info *pinfo, proto_tree *root) {
516   guint offset = 0;
517   guint16 msg;
518   proto_item *ti;
519   proto_tree *tree;
520
521   msg = tvb_get_ntohs(tvb, 2);
522
523   /* Set the protocol column */
524   if (check_col(pinfo->cinfo,COL_PROTOCOL)){
525     col_set_str(pinfo->cinfo,COL_PROTOCOL,"TDMA");
526   }
527
528   /* Set the info column */
529   if (check_col(pinfo->cinfo, COL_INFO)) {
530     col_add_fstr(pinfo->cinfo, COL_INFO, "%s",
531                  val_to_str(msg, tdma_msg_vals, "Unknown (0x%04x)"));
532   }
533
534   if (root) {
535     ti = proto_tree_add_item(root, proto_tdma, tvb, 0, -1, FALSE);
536     tree = proto_item_add_subtree(ti, ett_tdma);
537
538     proto_item_append_text(ti, ", %s", val_to_str(msg, tdma_msg_vals, "Unknown (0x%04x)"));
539
540     proto_tree_add_item(tree, hf_tdma_ver, tvb, offset, 2, FALSE);
541     offset += 2;
542
543     proto_tree_add_item(tree, hf_tdma_id, tvb, offset, 2, FALSE);
544     offset += 2;
545
546     switch (msg) {
547       case TDMA_MSG_SYNC:
548         dissect_tdma_sync(tvb, offset, tree);
549         break;
550
551       case TDMA_MSG_CAL_REQUEST:
552         dissect_tdma_request_cal(tvb, offset, tree);
553         break;
554
555       case TDMA_MSG_CAL_REPLY:
556         dissect_tdma_reply_cal(tvb, offset, tree);
557         break;
558
559       default:
560         break;
561     }
562   }
563 }
564
565 static void
566 dissect_rtmac(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) {
567   gint offset = 0;
568   guint8 ver,flags;
569   guint16 type;
570   tvbuff_t *next_tvb;
571   proto_tree *ti=NULL, *rtmac_tree=NULL;
572   proto_item *item;
573   dissector_handle_t dissector=NULL;
574   const gchar *type_str=NULL;
575
576   /* Read the header */
577   type = tvb_get_ntohs(tvb, offset);
578   ver = tvb_get_guint8(tvb, offset+2);
579   flags = tvb_get_guint8(tvb, offset+3);
580
581   if (ver == 1) {
582     type_str = match_strval(type, rtmac_type_vals);
583     if (!type_str) {
584       dissector = dissector_get_port_handle(ethertype_table, type);
585     }
586   } else {
587     if (flags & RTMAC_FLAG_TUNNEL) {
588       dissector = dissector_get_port_handle(ethertype_table, type);
589     }
590   }
591   if (!dissector)
592     dissector = data_handle;
593
594   if (tree) {
595     ti = proto_tree_add_item(tree, proto_rtmac, tvb, offset, 4, FALSE);
596     rtmac_tree = proto_item_add_subtree(ti, ett_rtmac);
597     proto_item_append_text(ti, ", Version %d", ver);
598   }
599
600   /* Set the protocol column */
601   if (check_col(pinfo->cinfo, COL_PROTOCOL)) {
602     col_set_str(pinfo->cinfo, COL_PROTOCOL, "RTmac");
603   }
604
605   /* set the info column */
606   if (check_col(pinfo->cinfo, COL_INFO)) {
607     col_clear(pinfo->cinfo,COL_INFO);
608     col_add_fstr(pinfo->cinfo, COL_INFO, "Unknown (0x%04x)",type);
609   }
610
611   if (rtmac_tree) {
612     if (ver == 1) {
613       if (!type_str) {
614         if (dissector != data_handle)
615           type_str = dissector_handle_get_short_name(dissector);
616         else
617           type_str = "Unknown";
618       }
619     } else {
620       if (!(flags & RTMAC_FLAG_TUNNEL))
621         type_str = val_to_str(type, rtmac_type_vals, "Unknown");
622       else {
623         if (dissector != data_handle)
624           type_str = dissector_handle_get_short_name(dissector);
625         else
626           type_str = "Unknown";
627       }
628     }
629     proto_tree_add_string_format(rtmac_tree, hf_rtmac_header_type, tvb, offset, 2,
630                                  type_str, "Type: %s (0x%04x)", type_str, type);
631     offset += 2;
632
633     proto_tree_add_item(rtmac_tree, hf_rtmac_header_ver, tvb, offset, 1, FALSE);
634     offset += 1;
635
636     if (ver == 1)
637       proto_tree_add_item(rtmac_tree, hf_rtmac_header_res_v1, tvb, offset, 1, FALSE);
638     else {
639       item = proto_tree_add_item(rtmac_tree, hf_rtmac_header_flags, tvb, offset, 1, FALSE);
640       ti = proto_item_add_subtree(item, ett_rtmac_flags);
641       proto_tree_add_item(ti, hf_rtmac_header_flags_res, tvb, offset, 1, FALSE);
642       proto_tree_add_item(ti, hf_rtmac_header_flags_tunnel, tvb, offset, 1, FALSE);
643     }
644     offset += 1;
645   }
646   else
647     offset += 4;
648
649   next_tvb = tvb_new_subset(tvb, offset, -1, -1);
650
651   if (ver == 1)
652     switch (type) {
653       case RTMAC_TYPE_TDMA_V1:
654         dissect_rtnet_tdma_v1(next_tvb, pinfo, tree);
655         break;
656
657       default:
658         call_dissector(dissector, next_tvb, pinfo, tree);
659         break;
660     }
661   else
662     if (flags & RTMAC_FLAG_TUNNEL)
663       call_dissector(dissector, next_tvb, pinfo, tree);
664     else
665       switch (type) {
666         case RTMAC_TYPE_TDMA:
667           dissect_rtnet_tdma(next_tvb, pinfo, tree);
668           break;
669
670         default:
671           call_dissector(data_handle, next_tvb, pinfo, tree);
672           break;
673       }
674 }
675
676 static void
677 dissect_rtcfg(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) {
678   gint offset = 0;
679   proto_tree *vers_id_tree, *vers_id_item, *flags_tree, *flags_item;
680   guint8 vers_id;
681   guint8 address_type;
682   guint32 config_length,len;
683   proto_tree *ti=NULL,*rtcfg_tree=NULL;
684   const guint8 *haddr;
685
686   /* Set the protocol column */
687   if(check_col(pinfo->cinfo,COL_PROTOCOL)){
688     col_set_str(pinfo->cinfo,COL_PROTOCOL,"RTcfg");
689   }
690
691   /* Clear out stuff in the info column */
692   if(check_col(pinfo->cinfo,COL_INFO)){
693     col_clear(pinfo->cinfo,COL_INFO);
694   }
695
696   if (tree) {
697     ti = proto_tree_add_item(tree, proto_rtcfg, tvb, offset, -1, FALSE);
698     rtcfg_tree = proto_item_add_subtree(ti, ett_rtcfg);
699   }
700
701   vers_id = tvb_get_guint8(tvb, offset);
702
703   if (check_col(pinfo->cinfo, COL_INFO)) {
704     col_add_fstr(pinfo->cinfo, COL_INFO, "%s",
705            val_to_str(vers_id, rtcfg_msg_vals, "Unknown (0x%04x)"));
706   }
707
708   if( rtcfg_tree )
709   {
710     vers_id_item = proto_tree_add_uint(rtcfg_tree, hf_rtcfg_vers_id, tvb,
711                                        offset, 1, vers_id);
712
713     vers_id_tree=proto_item_add_subtree(vers_id_item, ett_rtcfg);
714     proto_tree_add_item(vers_id_tree, hf_rtcfg_vers, tvb, offset, 1, FALSE);
715     proto_tree_add_item(vers_id_tree, hf_rtcfg_id, tvb, offset, 1, FALSE);
716     offset += 1;
717
718     proto_item_append_text(ti, ", Version %d, %s",
719              (vers_id >> 5),
720              val_to_str(vers_id, rtcfg_msg_vals, "Unknown (0x%04x)"));
721
722     switch( vers_id & 0x1f )
723     {
724        case RTCFG_MSG_S1_CONFIG:
725          address_type = tvb_get_guint8(tvb, offset);
726          proto_tree_add_item( rtcfg_tree, hf_rtcfg_address_type, tvb, offset, 1, FALSE );
727          offset += 1;
728
729          switch( address_type )
730          {
731            case RTCFG_ADDRESS_TYPE_MAC:
732              /* nothing */
733              break;
734
735            case RTCFG_ADDRESS_TYPE_IP:
736              proto_tree_add_item( rtcfg_tree, hf_rtcfg_client_ip_address, tvb, offset, 4, FALSE );
737              offset += 4;
738
739              proto_tree_add_item( rtcfg_tree, hf_rtcfg_server_ip_address, tvb, offset, 4, FALSE );
740              offset += 4;
741
742              break;
743          }
744
745          proto_tree_add_item( rtcfg_tree, hf_rtcfg_burst_rate, tvb, offset, 1, FALSE );
746          offset += 1;
747
748          config_length = tvb_get_ntohs( tvb, offset );
749          proto_tree_add_item( rtcfg_tree, hf_rtcfg_s1_config_length, tvb, offset, 2, FALSE );
750          offset += 2;
751
752          if( config_length > 0 ) {
753            proto_tree_add_item( rtcfg_tree, hf_rtcfg_config_data, tvb, offset, config_length, FALSE );
754            offset += config_length;
755          }
756
757          break;
758
759        case RTCFG_MSG_ANN_NEW:
760          address_type = tvb_get_guint8(tvb, offset);
761          proto_tree_add_item( rtcfg_tree, hf_rtcfg_address_type, tvb, offset, 1, FALSE );
762          offset += 1;
763
764          switch( address_type )
765          {
766            case RTCFG_ADDRESS_TYPE_MAC:
767              /* nothing */
768              break;
769
770            case RTCFG_ADDRESS_TYPE_IP:
771              proto_tree_add_item( rtcfg_tree, hf_rtcfg_client_ip_address, tvb, offset, 4, FALSE );
772              offset += 4;
773              break;
774          }
775
776          flags_item = proto_tree_add_item(rtcfg_tree, hf_rtcfg_client_flags, tvb,
777                                           offset, 1, FALSE);
778
779          flags_tree=proto_item_add_subtree(flags_item, ett_rtcfg);
780          proto_tree_add_item(flags_tree, hf_rtcfg_client_flags_available, tvb, offset, 1, FALSE);
781          proto_tree_add_item(flags_tree, hf_rtcfg_client_flags_ready, tvb, offset, 1, FALSE);
782          proto_tree_add_item(flags_tree, hf_rtcfg_client_flags_res, tvb, offset, 1, FALSE);
783          offset += 1;
784
785          proto_tree_add_item( rtcfg_tree, hf_rtcfg_burst_rate, tvb, offset, 1, FALSE );
786          offset += 1;
787
788          break;
789
790        case RTCFG_MSG_ANN_REPLY:
791          address_type = tvb_get_guint8(tvb, offset);
792          proto_tree_add_item( rtcfg_tree, hf_rtcfg_address_type, tvb, offset, 1, FALSE );
793          offset += 1;
794
795          switch( address_type )
796          {
797            case RTCFG_ADDRESS_TYPE_MAC:
798              /* nothing */
799              break;
800
801            case RTCFG_ADDRESS_TYPE_IP:
802              proto_tree_add_item( rtcfg_tree, hf_rtcfg_client_ip_address, tvb, offset, 4, FALSE );
803              offset += 4;
804              break;
805          }
806
807          flags_item = proto_tree_add_item(rtcfg_tree, hf_rtcfg_client_flags, tvb,
808                                           offset, 1, FALSE);
809
810          flags_tree=proto_item_add_subtree(flags_item, ett_rtcfg);
811          proto_tree_add_item(flags_tree, hf_rtcfg_client_flags_available, tvb, offset, 1, FALSE);
812          proto_tree_add_item(flags_tree, hf_rtcfg_client_flags_ready, tvb, offset, 1, FALSE);
813          proto_tree_add_item(flags_tree, hf_rtcfg_client_flags_res, tvb, offset, 1, FALSE);
814          offset += 1;
815
816          proto_tree_add_item( rtcfg_tree, hf_rtcfg_padding, tvb, offset, 1, FALSE );
817          offset += 1;
818
819          break;
820
821        case RTCFG_MSG_S2_CONFIG:
822          flags_item = proto_tree_add_item(rtcfg_tree, hf_rtcfg_server_flags, tvb,
823                                           offset, 1, FALSE);
824
825          flags_tree=proto_item_add_subtree(flags_item, ett_rtcfg);
826          proto_tree_add_item(flags_tree, hf_rtcfg_server_flags_res0, tvb, offset, 1, FALSE);
827          proto_tree_add_item(flags_tree, hf_rtcfg_server_flags_ready, tvb, offset, 1, FALSE);
828          proto_tree_add_item(flags_tree, hf_rtcfg_server_flags_res2, tvb, offset, 1, FALSE);
829          offset += 1;
830
831          proto_tree_add_item( rtcfg_tree, hf_rtcfg_active_stations, tvb, offset, 4, FALSE );
832          offset += 4;
833
834          proto_tree_add_item( rtcfg_tree, hf_rtcfg_heartbeat_period, tvb, offset, 2, FALSE );
835          offset += 2;
836
837          config_length = tvb_get_ntohl( tvb, offset );
838          proto_tree_add_item( rtcfg_tree, hf_rtcfg_s2_config_length, tvb, offset, 4, FALSE );
839          offset += 4;
840
841          if( config_length > 0 ) {
842            len = tvb_reported_length_remaining(tvb, offset);
843            proto_tree_add_item( rtcfg_tree, hf_rtcfg_config_data, tvb, offset, len, FALSE );
844            offset += len;
845          }
846
847          break;
848
849        case RTCFG_MSG_S2_FRAG:
850          proto_tree_add_item( rtcfg_tree, hf_rtcfg_config_offset, tvb, offset, 4, FALSE );
851          offset += 4;
852
853          len = tvb_reported_length_remaining(tvb, offset);
854          proto_tree_add_item( rtcfg_tree, hf_rtcfg_config_data, tvb, offset, len, FALSE );
855          offset += len;
856          break;
857
858        case RTCFG_MSG_ACK:
859          proto_tree_add_item( rtcfg_tree, hf_rtcfg_ack_length, tvb, offset, 4, FALSE );
860          offset += 4;
861
862          break;
863
864        case RTCFG_MSG_READY:
865          break;
866
867        case RTCFG_MSG_HBEAT:
868          break;
869
870        case RTCFG_MSG_DEAD_STN:
871          address_type = tvb_get_guint8(tvb, offset);
872          proto_tree_add_item( rtcfg_tree, hf_rtcfg_address_type, tvb, offset, 1, FALSE );
873          offset += 1;
874
875          switch( address_type )
876          {
877            case RTCFG_ADDRESS_TYPE_MAC:
878              /* nothing */
879              break;
880
881            case RTCFG_ADDRESS_TYPE_IP:
882              proto_tree_add_item( rtcfg_tree, hf_rtcfg_client_ip_address, tvb, offset, 4, FALSE );
883              offset += 4;
884              break;
885          }
886
887          switch (pinfo->fd->lnk_t) {
888            case WTAP_ENCAP_ETHERNET:
889              haddr = tvb_get_ptr(tvb, offset, 6);
890              proto_tree_add_bytes_format( rtcfg_tree, hf_rtcfg_client_hw_address, tvb, offset, 32,
891                                           haddr, "Client Hardware Address: %02X:%02X:%02X:%02X:%02X:%02X",
892                                           *haddr, *(haddr+1), *(haddr+2),
893                                           *(haddr+3), *(haddr+4), *(haddr+5) );
894              break;
895
896            default:
897              proto_tree_add_item( rtcfg_tree, hf_rtcfg_client_hw_address, tvb, offset, 32, FALSE );
898              break;
899          }
900          offset += 32;
901
902          break;
903
904     }
905   }
906 }
907
908 void
909 proto_register_rtmac(void) {
910   static const true_false_string rtnet_flags_set_truth = {
911     "Set",
912     "Not set"
913   };
914
915   static hf_register_info hf_array_rtmac[] = {
916
917     /* RTmac header */
918     { &hf_rtmac_header_type,
919       { "Type",
920         "rtmac.header.type",
921         FT_STRING, BASE_NONE, NULL, 0x0,
922         "RTmac Type", HFILL }},
923
924     { &hf_rtmac_header_ver,
925       { "Version",
926         "rtmac.header.ver",
927         FT_UINT16, BASE_DEC, NULL, 0x0,
928         "RTmac Version", HFILL }},
929
930     { &hf_rtmac_header_flags,
931       { "Flags",
932         "rtmac.header.flags",
933         FT_UINT8, BASE_HEX, NULL, 0x0,
934         "RTmac Flags", HFILL }},
935
936     { &hf_rtmac_header_flags_tunnel,
937       { "Tunnelling Flag",
938         "rtmac.header.flags.tunnel",
939         FT_BOOLEAN, 8, TFS(&rtnet_flags_set_truth), RTMAC_FLAG_TUNNEL,
940         "RTmac Tunnelling Flag", HFILL }},
941
942     { &hf_rtmac_header_flags_res,
943       { "Reserved Flags",
944         "rtmac.header.flags.res",
945         FT_UINT8, BASE_HEX, NULL, RTMAC_FLAGS_RES,
946         "RTmac Reserved Flags", HFILL }},
947
948     { &hf_rtmac_header_res_v1,
949       { "Reserved",
950         "rtmac.header.res",
951         FT_UINT8, BASE_HEX, NULL, 0x0,
952         "RTmac Reserved", HFILL }},
953   };
954
955   static hf_register_info hf_array_tdma[] = {
956
957     /* TDMA msg */
958     { &hf_tdma_v1_msg,
959       { "Message",
960         "tdma-v1.msg",
961         FT_UINT32, BASE_HEX, VALS(tdma_v1_msg_vals), 0x0,
962         "TDMA-V1 Message", HFILL }},
963
964     /* TDMA request conf */
965
966     { &hf_tdma_v1_msg_request_conf_station,
967       { "Station",
968         "tdma-v1.msg.request_conf.station",
969         FT_UINT8, BASE_DEC, NULL, 0x0,
970         "TDMA Station", HFILL }},
971
972     { &hf_tdma_v1_msg_request_conf_padding,
973       { "Padding",
974         "tdma-v1.msg.request_conf.padding",
975         FT_UINT8, BASE_HEX, NULL, 0x0,
976         "TDMA Padding", HFILL }},
977
978     { &hf_tdma_v1_msg_request_conf_mtu,
979       { "MTU",
980         "tdma-v1.msg.request_conf.mtu",
981         FT_UINT8, BASE_DEC, NULL, 0x0,
982         "TDMA MTU", HFILL }},
983
984     { &hf_tdma_v1_msg_request_conf_cycle,
985       { "Cycle",
986         "tdma-v1.msg.request_conf.cycle",
987         FT_UINT8, BASE_DEC, NULL, 0x0,
988         "TDMA Cycle", HFILL }},
989
990     /* TDMA ack conf */
991
992     { &hf_tdma_v1_msg_ack_conf_station,
993       { "Station",
994         "tdma-v1.msg.ack_conf.station",
995         FT_UINT8, BASE_DEC, NULL, 0x0,
996         "TDMA Station", HFILL }},
997
998     { &hf_tdma_v1_msg_ack_conf_padding,
999       { "Padding",
1000         "tdma-v1.msg.ack_conf.padding",
1001         FT_UINT8, BASE_HEX, NULL, 0x0,
1002         "TDMA PAdding", HFILL }},
1003
1004     { &hf_tdma_v1_msg_ack_conf_mtu,
1005       { "MTU",
1006         "tdma-v1.msg.ack_conf.mtu",
1007         FT_UINT8, BASE_DEC, NULL, 0x0,
1008         "TDMA MTU", HFILL }},
1009
1010     { &hf_tdma_v1_msg_ack_conf_cycle,
1011       { "Cycle",
1012         "tdma-v1.msg.ack_conf.cycle",
1013         FT_UINT8, BASE_DEC, NULL, 0x0,
1014         "TDMA Cycle", HFILL }},
1015
1016     /* TDMA ack ack conf */
1017
1018     { &hf_tdma_v1_msg_ack_ack_conf_station,
1019       { "Station",
1020         "tdma-v1.msg.ack_ack_conf.station",
1021         FT_UINT8, BASE_DEC, NULL, 0x0,
1022         "TDMA Station", HFILL }},
1023
1024     { &hf_tdma_v1_msg_ack_ack_conf_padding,
1025       { "Padding",
1026         "tdma-v1.msg.ack_ack_conf.padding",
1027         FT_BYTES, BASE_HEX, NULL, 0x0,
1028         "TDMA Padding", HFILL }},
1029
1030     /* TDMA request test */
1031
1032     { &hf_tdma_v1_msg_request_test_counter,
1033       { "Counter",
1034         "tdma-v1.msg.request_test.counter",
1035         FT_UINT32, BASE_DEC, NULL, 0x0,
1036         "TDMA Counter", HFILL }},
1037
1038     { &hf_tdma_v1_msg_request_test_tx,
1039       { "TX",
1040         "tdma-v1.msg.request_test.tx",
1041         FT_UINT64, BASE_DEC, NULL, 0x0,
1042         "TDMA TX", HFILL }},
1043
1044     /* TDMA ack test */
1045
1046     { &hf_tdma_v1_msg_ack_test_counter,
1047       { "Counter",
1048         "tdma-v1.msg.ack_test.counter",
1049         FT_UINT32, BASE_DEC, NULL, 0x0,
1050         "TDMA Counter", HFILL }},
1051
1052     { &hf_tdma_v1_msg_ack_test_tx,
1053       { "TX",
1054         "tdma-v1.msg.ack_test.tx",
1055         FT_UINT64, BASE_DEC, NULL, 0x0,
1056         "TDMA TX", HFILL }},
1057
1058     /* TDMA ack test */
1059
1060     { &hf_tdma_v1_msg_request_change_offset_offset,
1061       { "Offset",
1062         "tdma-v1.msg.request_change_offset.offset",
1063         FT_UINT32, BASE_DEC, NULL, 0x0,
1064         "TDMA Offset", HFILL }},
1065
1066     /* TDMA start of frame */
1067
1068
1069     { &hf_tdma_v1_msg_start_of_frame_timestamp,
1070       { "Timestamp",
1071         "tdma-v1.msg.start_of_frame.timestamp",
1072         FT_UINT64, BASE_DEC, NULL, 0x0,
1073         "TDMA Timestamp", HFILL }},
1074
1075     /* TDMA station list */
1076
1077     { &hf_tdma_v1_msg_station_list_nr_stations,
1078       { "Nr. Stations",
1079         "tdma-v1.msg.station_list.nr_stations",
1080         FT_UINT8, BASE_DEC, NULL, 0x0,
1081         "TDMA Nr. Stations", HFILL }},
1082
1083     { &hf_tdma_v1_msg_station_list_nr,
1084       { "Nr.",
1085         "tdma-v1.msg.station_list.nr",
1086         FT_UINT8, BASE_DEC, NULL, 0x0,
1087         "TDMA Station Number", HFILL }},
1088
1089     { &hf_tdma_v1_msg_station_list_ip,
1090       { "IP",
1091         "tdma-v1.msg.station_list.ip",
1092         FT_IPv4, BASE_DEC, NULL, 0x0,
1093         "TDMA Station IP", HFILL }},
1094
1095     { &hf_tdma_v1_msg_station_list_padding,
1096       { "Padding",
1097         "tdma-v1.msg.station_list.padding",
1098         FT_BYTES, BASE_HEX, NULL, 0x0,
1099         "TDMA Padding", HFILL }},
1100
1101
1102     /* TDMA since version 2 */
1103
1104     { &hf_tdma_ver,
1105       { "Version",
1106         "tdma.ver",
1107         FT_UINT16, BASE_HEX, NULL, 0x0,
1108         "TDMA Version", HFILL }},
1109
1110     { &hf_tdma_id,
1111       { "Message ID",
1112         "tdma.id",
1113         FT_UINT16, BASE_HEX, VALS(tdma_msg_vals), 0x0,
1114         "TDMA Message ID", HFILL }},
1115
1116     /* TDMA sync */
1117
1118     { &hf_tdma_sync_cycle,
1119       { "Cycle Number",
1120         "tdma.sync.cycle",
1121         FT_UINT32, BASE_DEC, NULL, 0x0,
1122         "TDMA Sync Cycle Number", HFILL }},
1123
1124     { &hf_tdma_sync_xmit_stamp,
1125       { "Transmission Time Stamp",
1126         "tdma.sync.xmit_stamp",
1127         FT_UINT64, BASE_DEC, NULL, 0x0,
1128         "TDMA Sync Transmission Time Stamp", HFILL }},
1129
1130     { &hf_tdma_sync_sched_xmit,
1131       { "Scheduled Transmission Time",
1132         "tdma.sync.sched_xmit",
1133         FT_UINT64, BASE_DEC, NULL, 0x0,
1134         "TDMA Sync Scheduled Transmission Time", HFILL }},
1135
1136     /* TDMA request calibration */
1137
1138     { &hf_tdma_req_cal_xmit_stamp,
1139       { "Transmission Time Stamp",
1140         "tdma.req_cal.xmit_stamp",
1141         FT_UINT64, BASE_DEC, NULL, 0x0,
1142         "TDMA Request Calibration Transmission Time Stamp", HFILL }},
1143
1144     { &hf_tdma_req_cal_rpl_cycle,
1145       { "Reply Cycle Number",
1146         "tdma.req_cal.rpl_cycle",
1147         FT_UINT32, BASE_DEC, NULL, 0x0,
1148         "TDMA Request Calibration Reply Cycle Number", HFILL }},
1149
1150     { &hf_tdma_req_cal_rpl_slot,
1151       { "Reply Slot Offset",
1152         "tdma.req_cal.rpl_slot",
1153         FT_UINT64, BASE_DEC, NULL, 0x0,
1154         "TDMA Request Calibration Reply Slot Offset", HFILL }},
1155
1156     /* TDMA reply calibration */
1157
1158     { &hf_tdma_rpl_cal_req_stamp,
1159       { "Request Transmission Time",
1160         "tdma.rpl_cal.req_stamp",
1161         FT_UINT64, BASE_DEC, NULL, 0x0,
1162         "TDMA Reply Calibration Request Transmission Time", HFILL }},
1163
1164     { &hf_tdma_rpl_cal_rcv_stamp,
1165       { "Reception Time Stamp",
1166         "tdma.rpl_cal.rcv_stamp",
1167         FT_UINT64, BASE_DEC, NULL, 0x0,
1168         "TDMA Reply Calibration Reception Time Stamp", HFILL }},
1169
1170     { &hf_tdma_rpl_cal_xmit_stamp,
1171       { "Transmission Time Stamp",
1172         "tdma.rpl_cal.xmit_stamp",
1173         FT_UINT64, BASE_DEC, NULL, 0x0,
1174         "TDMA Reply Calibration Transmission Time Stamp", HFILL }},
1175   };
1176
1177   static gint *ett_array_rtmac[] = {
1178     &ett_rtmac,
1179     &ett_rtmac_flags,
1180   };
1181
1182   static gint *ett_array_tdma[] = {
1183     &ett_tdma,
1184   };
1185
1186   proto_rtmac = proto_register_protocol("Real-Time Media Access Control", "RTmac", "rtmac");
1187   proto_register_field_array(proto_rtmac, hf_array_rtmac, array_length(hf_array_rtmac));
1188   proto_register_subtree_array(ett_array_rtmac, array_length(ett_array_rtmac));
1189
1190   proto_tdma = proto_register_protocol("TDMA RTmac Discipline", "TDMA", "tdma");
1191   proto_register_field_array(proto_rtmac, hf_array_tdma, array_length(hf_array_tdma));
1192   proto_register_subtree_array(ett_array_tdma, array_length(ett_array_tdma));
1193 }
1194
1195
1196 void
1197 proto_register_rtcfg(void) {
1198   static hf_register_info hf[] = {
1199     { &hf_rtcfg_vers_id,
1200       { "Version and ID",
1201         "rtcfg.vers_id",
1202         FT_UINT8, BASE_HEX, NULL, 0x0,
1203         "RTcfg Version and ID", HFILL }},
1204
1205     { &hf_rtcfg_vers,
1206       { "Version",
1207         "rtcfg.vers",
1208         FT_UINT8, BASE_DEC, NULL, 0xe0,
1209         "RTcfg Version", HFILL }},
1210
1211     { &hf_rtcfg_id,
1212       { "ID",
1213         "rtcfg.id",
1214         FT_UINT8, BASE_HEX, VALS(rtcfg_msg_vals), 0x1f,
1215         "RTcfg ID", HFILL }},
1216
1217     { &hf_rtcfg_address_type,
1218       { "Address Type",
1219         "rtcfg.address_type",
1220         FT_UINT8, BASE_DEC, VALS(rtcfg_address_type_vals), 0x00,
1221         "RTcfg Address Type", HFILL }},
1222
1223     { &hf_rtcfg_client_ip_address,
1224       { "Client IP Address",
1225         "rtcfg.client_ip_address",
1226         FT_IPv4, BASE_DEC, NULL, 0x0,
1227         "RTcfg Client IP Address", HFILL }},
1228
1229     { &hf_rtcfg_server_ip_address,
1230       { "Server IP Address",
1231         "rtcfg.server_ip_address",
1232         FT_IPv4, BASE_DEC, NULL, 0x0,
1233         "RTcfg Server IP Address", HFILL }},
1234
1235     { &hf_rtcfg_burst_rate,
1236       { "Stage 2 Burst Rate",
1237         "rtcfg.burst_rate",
1238         FT_UINT8, BASE_DEC, NULL, 0x00,
1239         "RTcfg Stage 2 Burst Rate", HFILL }},
1240
1241     { &hf_rtcfg_s1_config_length,
1242       { "Stage 1 Config Length",
1243         "rtcfg.s1_config_length",
1244         FT_UINT16, BASE_DEC, NULL, 0x00,
1245         "RTcfg Stage 1 Config Length", HFILL }},
1246
1247     { &hf_rtcfg_config_data,
1248       { "Config Data",
1249         "rtcfg.config_data",
1250         FT_BYTES, BASE_DEC, NULL, 0x00,
1251         "RTcfg Config Data", HFILL }},
1252
1253     { &hf_rtcfg_padding,
1254       { "Padding",
1255         "rtcfg.padding",
1256         FT_UINT8, BASE_DEC, NULL, 0x00,
1257         "RTcfg Padding", HFILL }},
1258
1259     { &hf_rtcfg_client_flags,
1260       { "Flags",
1261         "rtcfg.client_flags",
1262         FT_UINT8, BASE_HEX, NULL, 0x00,
1263         "RTcfg Client Flags", HFILL }},
1264
1265     { &hf_rtcfg_client_flags_available,
1266       { "Req. Available",
1267         "rtcfg.client_flags.available",
1268         FT_UINT8, BASE_DEC, NULL, 0x01,
1269         "Request Available", HFILL }},
1270
1271     { &hf_rtcfg_client_flags_ready,
1272       { "Client Ready",
1273         "rtcfg.client_flags.ready",
1274         FT_UINT8, BASE_DEC, NULL, 0x02,
1275         "Client Ready", HFILL }},
1276
1277     { &hf_rtcfg_client_flags_res,
1278       { "Reserved",
1279         "rtcfg.client_flags.res",
1280         FT_UINT8, BASE_HEX, NULL, 0xfc,
1281         "Reserved", HFILL }},
1282
1283     { &hf_rtcfg_server_flags,
1284       { "Flags",
1285         "rtcfg.server_flags",
1286         FT_UINT8, BASE_HEX, NULL, 0x00,
1287         "RTcfg Server Flags", HFILL }},
1288
1289     { &hf_rtcfg_server_flags_res0,
1290       { "Reserved",
1291         "rtcfg.server_flags.res0",
1292         FT_UINT8, BASE_HEX, NULL, 0x01,
1293         "Reserved", HFILL }},
1294
1295     { &hf_rtcfg_server_flags_ready,
1296       { "Server Ready",
1297         "rtcfg.server_flags.ready",
1298         FT_UINT8, BASE_DEC, NULL, 0x02,
1299         "Server Ready", HFILL }},
1300
1301     { &hf_rtcfg_server_flags_res2,
1302       { "Reserved",
1303         "rtcfg.server_flags.res2",
1304         FT_UINT8, BASE_HEX, NULL, 0xfc,
1305         "Reserved", HFILL }},
1306
1307     { &hf_rtcfg_active_stations,
1308       { "Active Stations",
1309         "rtcfg.active_stations",
1310         FT_UINT32, BASE_DEC, NULL, 0x00,
1311         "RTcfg Active Stations", HFILL }},
1312
1313     { &hf_rtcfg_heartbeat_period,
1314       { "Heartbeat Period",
1315         "rtcfg.hearbeat_period",
1316         FT_UINT16, BASE_DEC, NULL, 0x00,
1317         "RTcfg Heartbeat Period", HFILL }},
1318
1319     { &hf_rtcfg_s2_config_length,
1320       { "Stage 2 Config Length",
1321         "rtcfg.s2_config_length",
1322         FT_UINT32, BASE_DEC, NULL, 0x00,
1323         "RTcfg Stage 2 Config Length", HFILL }},
1324
1325     { &hf_rtcfg_config_offset,
1326       { "Config Offset",
1327         "rtcfg.config_offset",
1328         FT_UINT32, BASE_DEC, NULL, 0x00,
1329         "RTcfg Config Offset", HFILL }},
1330
1331     { &hf_rtcfg_ack_length,
1332       { "Ack Length",
1333         "rtcfg.ack_length",
1334         FT_UINT32, BASE_DEC, NULL, 0x00,
1335         "RTcfg Ack Length", HFILL }},
1336
1337     { &hf_rtcfg_client_hw_address,
1338       { "Client Hardware Address",
1339         "rtcfg.client_ip_address",
1340         FT_BYTES, BASE_NONE, NULL, 0x00,
1341         "RTcfg Client Hardware Address", HFILL }}
1342   };
1343
1344   static gint *ett[] = {
1345     &ett_rtcfg,
1346   };
1347
1348   proto_rtcfg = proto_register_protocol("RTcfg","RTcfg","rtcfg");
1349   proto_register_field_array(proto_rtcfg,hf,array_length(hf));
1350   proto_register_subtree_array(ett,array_length(ett));
1351 }
1352
1353 /* The registration hand-off routing */
1354
1355 void
1356 proto_reg_handoff_rtmac(void) {
1357   dissector_handle_t rtmac_handle;
1358
1359   rtmac_handle = create_dissector_handle(dissect_rtmac, proto_rtmac);
1360   dissector_add("ethertype", ETHERTYPE_RTMAC, rtmac_handle);
1361   ethertype_table = find_dissector_table("ethertype");
1362 }
1363
1364 void
1365 proto_reg_handoff_rtcfg(void) {
1366   dissector_handle_t rtcfg_handle;
1367
1368   data_handle = find_dissector("data");
1369   rtcfg_handle = create_dissector_handle(dissect_rtcfg, proto_rtcfg);
1370   dissector_add("ethertype", ETHERTYPE_RTCFG, rtcfg_handle);
1371 }