- some radcom files seem to have a different magic key than the one we
[obnox/wireshark/wip.git] / packet-bacapp.c
1 /* packet-bacapp.c
2  * Routines for BACnet (APDU) dissection
3  * Copyright 2001, Hartmut Mueller <hartmut@abmlinux.org>, FH Dortmund
4  *
5  * $Id: packet-bacapp.c,v 1.13 2002/08/28 21:00:07 jmayer Exp $
6  *
7  * Ethereal - Network traffic analyzer
8  * By Gerald Combs <gerald@ethereal.com>
9  * Copyright 1998 Gerald Combs
10  *
11  * Copied from README.developer,v 1.23
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 #ifdef HAVE_CONFIG_H
29 # include "config.h"
30 #endif
31
32 #include <stdio.h>
33 #include <stdlib.h>
34 #include <string.h>
35
36 #include <glib.h>
37
38 #include <epan/packet.h>
39
40 static const char*
41 bacapp_type_name (guint8 bacapp_type){
42   static const char *type_names[] = {
43         "Confirmed-Request-PDU",
44         "Unconfirmed-Request-PDU",
45         "SimpleACK-PDU",
46         "ComplexACK-PDU",
47         "SegmentACK-PDU",
48         "Error-PDU",
49         "Reject-PDU",
50         "Abort-PDU"
51         };
52         return (bacapp_type > 7)? "unknown PDU" : type_names[bacapp_type];
53 }
54
55 static int proto_bacapp = -1;
56 static int hf_bacapp_type = -1;
57
58 static gint ett_bacapp = -1;
59
60 static dissector_handle_t data_handle;
61
62 static void
63 dissect_bacapp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
64 {
65         proto_item *ti;
66         proto_tree *bacapp_tree;
67         guint8 offset;
68         guint8 bacapp_type;
69         tvbuff_t *next_tvb;
70
71         if (check_col(pinfo->cinfo, COL_PROTOCOL))
72                 col_set_str(pinfo->cinfo, COL_PROTOCOL, "BACnet-APDU");
73         if (check_col(pinfo->cinfo, COL_INFO))
74                 col_add_str(pinfo->cinfo, COL_INFO, "BACnet APDU ");
75
76         offset  = 0;
77         bacapp_type = (tvb_get_guint8(tvb, offset) >> 4) & 0x0f;
78
79         if (check_col(pinfo->cinfo, COL_INFO))
80                 col_append_fstr(pinfo->cinfo, COL_INFO, "(%s)",
81                 bacapp_type_name(bacapp_type));
82         if (tree) {
83                 ti = proto_tree_add_item(tree, proto_bacapp, tvb, offset, -1, FALSE);
84
85                 bacapp_tree = proto_item_add_subtree(ti, ett_bacapp);
86
87                 proto_tree_add_uint_format(bacapp_tree, hf_bacapp_type, tvb,
88                         offset, 1, bacapp_type, "APDU Type: %u (%s)", bacapp_type,
89                                 bacapp_type_name(bacapp_type));
90                 offset ++;
91
92         }
93         next_tvb = tvb_new_subset(tvb,offset,-1,-1);
94         call_dissector(data_handle,next_tvb, pinfo, tree);
95 }
96
97
98 void
99 proto_register_bacapp(void)
100 {
101         static hf_register_info hf[] = {
102                 { &hf_bacapp_type,
103                         { "APDU Type",           "bacapp.bacapp_type",
104                         FT_UINT8, BASE_DEC, NULL, 0xf0, "APDU Type", HFILL }
105                 },
106         };
107         static gint *ett[] = {
108                 &ett_bacapp,
109         };
110         proto_bacapp = proto_register_protocol("Building Automation and Control Network APDU",
111             "BACapp", "bacapp");
112         proto_register_field_array(proto_bacapp, hf, array_length(hf));
113         proto_register_subtree_array(ett, array_length(ett));
114         register_dissector("bacapp", dissect_bacapp, proto_bacapp);
115 }
116
117 void
118 proto_reg_handoff_bacapp(void)
119 {
120         data_handle = find_dissector("data");
121 }
122