From Joerg Mayer:
[obnox/wireshark/wip.git] / packet-bvlc.c
index 148002c5d648966d9c19ec747d8829657f7d7bc4..232a60fca286fc1b71188a91d63d1f9cd3670284 100644 (file)
@@ -2,7 +2,7 @@
  * Routines for BACnet/IP (BVLL, BVLC) dissection
  * Copyright 2001, Hartmut Mueller <hartmut@abmlinux.org>, FH Dortmund
  *
- * $Id: packet-bvlc.c,v 1.2 2001/04/20 20:34:28 guy Exp $
+ * $Id: packet-bvlc.c,v 1.11 2002/07/17 00:42:40 guy Exp $
  *
  * Ethereal - Network traffic analyzer
  * By Gerald Combs <gerald@ethereal.com>
@@ -33,7 +33,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include "prefs.h"
-#include "strutil.h"
+#include <epan/strutil.h>
 
 #ifdef HAVE_SYS_TYPES_H
 # include <sys/types.h>
 
 #include <glib.h>
 
-#ifdef NEED_SNPRINTF_H
-# include "snprintf.h"
-#endif
-
-#include "packet.h"
+#include <epan/packet.h>
 
 static int proto_bvlc = -1;
 static int hf_bvlc_type = -1;
@@ -67,42 +63,36 @@ static int hf_bvlc_fdt_timeout = -1;
 static int hf_bvlc_fwd_ip = -1;
 static int hf_bvlc_fwd_port = -1;
 
-
+static dissector_handle_t data_handle;
 
 static dissector_table_t bvlc_dissector_table;
 
-static const char*
-bvlc_function_name (guint8 bvlc_function){
-  static const char *type_names[] = {
-       "BVLC-Result",
-       "Write-Broadcast-Distribution-Table",
-       "Read-Broadcast-Distribution-Table",
-       "Read-Broadcast-Distribution-Table-Ack",
-       "Forwarded-NPDU",
-       "Register-Foreign-Device",
-       "Read-Foreign-Device-Table",
-       "Read-Foreign-Device-Table-Ack",
-       "Delete-Foreign-Device-Table-Entry",
-       "Distribute-Broadcast-To-Network",
-       "Original-Unicast-NPDU",
-       "Original-Broadcast-NPDU"
-  };
-  return (bvlc_function > 0xb)? "unknown" : type_names[bvlc_function];
-}
+static const value_string bvlc_function_names[] = {
+       { 0x00, "BVLC-Result", },
+       { 0x01, "Write-Broadcast-Distribution-Table", },
+       { 0x02, "Read-Broadcast-Distribution-Table", },
+       { 0x03, "Read-Broadcast-Distribution-Table-Ack", },
+       { 0x04, "Forwarded-NPDU", },
+       { 0x05, "Register-Foreign-Device", },
+       { 0x06, "Read-Foreign-Device-Table", },
+       { 0x07, "Read-Foreign-Device-Table-Ack", },
+       { 0x08, "Delete-Foreign-Device-Table-Entry", },
+       { 0x09, "Distribute-Broadcast-To-Network", },
+       { 0x0a, "Original-Unicast-NPDU", },
+       { 0x0b, "Original-Broadcast-NPDU" },
+       { 0,    NULL }
+};
 
-static const char*
-bvlc_result_name (guint16 bvlc_result){
-  static const char *result_names[] = {
-       "Successful completion",
-       "Write-Broadcast-Distribution-Table NAK",
-       "Read-Broadcast-Distribution-Table NAK",
-       "Register-Foreign-Device NAK",
-       "Read-Foreign-Device-Table NAK",
-       "Delete-Foreign-Device-Table-Entry NAK",
-       "Distribute-Broadcast-To-Network NAK"
-  };
-  return (bvlc_result > 0x0060)? "unknown" : result_names[bvlc_result];
-}
+static const value_string bvlc_result_names[] = {
+       { 0x00, "Successful completion" },
+       { 0x10, "Write-Broadcast-Distribution-Table NAK" },
+       { 0x20, "Read-Broadcast-Distribution-Table NAK" },
+       { 0x30, "Register-Foreign-Device NAK" },
+       { 0x40, "Read-Foreign-Device-Table NAK" },
+       { 0x50, "Delete-Foreign-Device-Table-Entry NAK" },
+       { 0x60, "Distribute-Broadcast-To-Network NAK" },
+       { 0,    NULL }
+};
 
 static gint ett_bvlc = -1;
 static gint ett_bdt = -1;
@@ -128,13 +118,11 @@ dissect_bvlc(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
        guint16 bvlc_result;
        tvbuff_t *next_tvb;
 
-       pinfo->current_proto = "BACnet virtual link control";
-
-       if (check_col(pinfo->fd, COL_PROTOCOL))
-               col_set_str(pinfo->fd, COL_PROTOCOL, "BVLC");
+       if (check_col(pinfo->cinfo, COL_PROTOCOL))
+               col_set_str(pinfo->cinfo, COL_PROTOCOL, "BVLC");
 
-       if (check_col(pinfo->fd, COL_INFO))
-               col_set_str(pinfo->fd, COL_INFO, "BACnet Virtual Link Control");
+       if (check_col(pinfo->cinfo, COL_INFO))
+               col_set_str(pinfo->cinfo, COL_INFO, "BACnet Virtual Link Control");
 
        offset = 0;
 
@@ -171,7 +159,8 @@ dissect_bvlc(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
                offset ++;
                proto_tree_add_uint_format(bvlc_tree, hf_bvlc_function, tvb, 
                        offset, 1, bvlc_function,"Function: 0x%02x (%s)", 
-                       bvlc_function, bvlc_function_name(bvlc_function));
+                       bvlc_function, val_to_str (bvlc_function,
+                               bvlc_function_names, "Unknown"));
                offset ++;
                proto_tree_add_uint_format(bvlc_tree, hf_bvlc_length, tvb, offset, 
                        2, bvlc_length, "BVLC-Length: %d of %d bytes BACnet packet length", 
@@ -187,7 +176,8 @@ dissect_bvlc(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
                        * packet to dissect, see README.developer, 1.6.2, FID */
                        proto_tree_add_uint_format(bvlc_tree, hf_bvlc_result, tvb, 
                                offset, 2, bvlc_result,"Result: 0x%04x (%s)", 
-                               bvlc_result, bvlc_result_name(bvlc_result << 4));
+                               bvlc_result, val_to_str(bvlc_result << 4, 
+                                       bvlc_result_names, "Unknown"));
                        offset += 2;
                        break;
                case 0x01: /* Write-Broadcast-Distribution-Table */
@@ -295,7 +285,7 @@ dissect_bvlc(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
        if (!dissector_try_port(bvlc_dissector_table, 
        bvlc_function, next_tvb, pinfo, tree)) {
                /* Unknown function - dissect the paylod as data */
-               dissect_data(next_tvb, 0, pinfo, tree);
+               call_dissector(data_handle,next_tvb, pinfo, tree);
        }
 }
 
@@ -306,74 +296,74 @@ proto_register_bvlc(void)
                { &hf_bvlc_type,
                        { "Type",           "bvlc.type",
                        FT_UINT8, BASE_HEX, NULL, 0,
-                       "Type" }
+                       "Type", HFILL }
                },
                { &hf_bvlc_function,
                        { "Function",           "bvlc.function",
                        FT_UINT8, BASE_HEX, NULL, 0,
-                       "BLVC Function" }
+                       "BLVC Function", HFILL }
                },
                { &hf_bvlc_length,
                        { "Length",           "bvlc.length",
                        FT_UINT16, BASE_DEC, NULL, 0,
-                       "Length of BVLC" }
+                       "Length of BVLC", HFILL }
                },
                /* We should bitmask the result correctly when we have a
                 * packet to dissect */
                { &hf_bvlc_result,
                        { "Result",           "bvlc.result",
                        FT_UINT16, BASE_HEX, NULL, 0xffff,
-                       "Result Code" }
+                       "Result Code", HFILL }
                },
                { &hf_bvlc_bdt_ip,
                        { "IP",           "bvlc.bdt_ip",
                        FT_IPv4, BASE_NONE, NULL, 0,
-                       "BDT IP" }
+                       "BDT IP", HFILL }
                },
                { &hf_bvlc_bdt_port,
                        { "Port",           "bvlc.bdt_port",
                        FT_UINT16, BASE_DEC, NULL, 0,
-                       "BDT Port" }
+                       "BDT Port", HFILL }
                },
                { &hf_bvlc_bdt_mask,
                        { "Mask",           "bvlc.bdt_mask",
                        FT_BYTES, BASE_HEX, NULL, 0,
-                       "BDT Broadcast Distribution Mask" }
+                       "BDT Broadcast Distribution Mask", HFILL }
                },
                { &hf_bvlc_reg_ttl,
                        { "TTL",           "bvlc.reg_ttl",
                        FT_UINT16, BASE_DEC, NULL, 0,
-                       "Foreign Device Time To Live" }
+                       "Foreign Device Time To Live", HFILL }
                },
                { &hf_bvlc_fdt_ip,
                        { "IP",           "bvlc.fdt_ip",
                        FT_IPv4, BASE_NONE, NULL, 0,
-                       "FDT IP" }
+                       "FDT IP", HFILL }
                },
                { &hf_bvlc_fdt_port,
                        { "Port",           "bvlc.fdt_port",
                        FT_UINT16, BASE_DEC, NULL, 0,
-                       "FDT Port" }
+                       "FDT Port", HFILL }
                },
                { &hf_bvlc_fdt_ttl,
                        { "TTL",           "bvlc.fdt_ttl",
                        FT_UINT16, BASE_DEC, NULL, 0,
-                       "Foreign Device Time To Live" }
+                       "Foreign Device Time To Live", HFILL }
                },
                { &hf_bvlc_fdt_timeout,
                        { "Timeout",           "bvlc.fdt_timeout",
                        FT_UINT16, BASE_DEC, NULL, 0,
-                       "Foreign Device Timeout (seconds)" }
+                       "Foreign Device Timeout (seconds)", HFILL }
                },
                { &hf_bvlc_fwd_ip,
                        { "IP",           "bvlc.fwd_ip",
                        FT_IPv4, BASE_NONE, NULL, 0,
-                       "FWD IP" }
+                       "FWD IP", HFILL }
                },
                { &hf_bvlc_fwd_port,
                        { "Port",           "bvlc.fwd_port",
                        FT_UINT16, BASE_DEC, NULL, 0,
-                       "FWD Port" }
+                       "FWD Port", HFILL }
                },
        };
 
@@ -391,13 +381,18 @@ proto_register_bvlc(void)
 
        register_dissector("bvlc", dissect_bvlc, proto_bvlc);
 
-       bvlc_dissector_table = register_dissector_table("bvlc.function");
+       bvlc_dissector_table = register_dissector_table("bvlc.function",
+           "BVLC Function", FT_UINT8, BASE_HEX);
 }
 
 void
 proto_reg_handoff_bvlc(void)
 {
-       dissector_add("udp.port", 0xBAC0, dissect_bvlc, proto_bvlc); /* added proto_bvlc */
+       dissector_handle_t bvlc_handle;
+
+       bvlc_handle = find_dissector("bvlc");
+       dissector_add("udp.port", 0xBAC0, bvlc_handle);
+       data_handle = find_dissector("data");
 }
 /* Taken from add-135a (BACnet-IP-standard paper):
  *
@@ -412,4 +407,3 @@ proto_reg_handoff_bvlc(void)
  * If you changed your BACnet port locally, use the ethereal feature
  * "Decode As".
  */
-