For proto_tree_add_item(..., proto_xxx, ...)use ENC_NA as the encoding arg.
[obnox/wireshark/wip.git] / epan / dissectors / packet-hci_h4.c
1 /* packet-hci_h4.c
2  * Routines for the Bluetooth HCI H4 dissection
3  *
4  * Copyright 2002, Christoph Scholz <scholz@cs.uni-bonn.de>
5  *  From: http://affix.sourceforge.net/archive/ethereal_affix-3.patch
6  *
7  * Refactored for wireshark checkin
8  *   Ronnie Sahlberg 2006
9  *
10  * $Id$
11  *
12  * Wireshark - Network traffic analyzer
13  * By Gerald Combs <gerald@wireshark.org>
14  * Copyright 1998 Gerald Combs
15  *
16  * This program is free software; you can redistribute it and/or
17  * modify it under the terms of the GNU General Public License
18  * as published by the Free Software Foundation; either version 2
19  * of the License, or (at your option) any later version.
20  *
21  * This program is distributed in the hope that it will be useful,
22  * but WITHOUT ANY WARRANTY; without even the implied warranty of
23  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24  * GNU General Public License for more details.
25  *
26  * You should have received a copy of the GNU General Public License
27  * along with this program; if not, write to the Free Software
28  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
29  */
30
31 #ifdef HAVE_CONFIG_H
32 #include "config.h"
33 #endif
34
35 #include <epan/packet.h>
36
37 #include "packet-hci_h4.h"
38
39
40 static int proto_hci_h4 = -1;
41 static int hf_hci_h4_type = -1;
42 static int hf_hci_h4_direction = -1;
43
44 static gint ett_hci_h4 = -1;
45
46 static dissector_table_t hci_h4_table;
47 static dissector_handle_t data_handle;
48
49
50 static const value_string hci_h4_type_vals[] = {
51         {HCI_H4_TYPE_CMD, "HCI Command"},
52         {HCI_H4_TYPE_ACL, "ACL Data"},
53         {HCI_H4_TYPE_SCO, "SCO Data"},
54         {HCI_H4_TYPE_EVT, "HCI Event"},
55         {0, NULL }
56 };
57 static const value_string hci_h4_direction_vals[] = {
58         {P2P_DIR_SENT,          "Sent"},
59         {P2P_DIR_RECV,          "Rcvd"},
60         {P2P_DIR_UNKNOWN,       "Unspecified"},
61         {0, NULL}
62 };
63
64 static void
65 dissect_hci_h4(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
66 {
67         guint8 type;
68         tvbuff_t *next_tvb;
69         proto_item *ti=NULL;
70         proto_tree *hci_h4_tree=NULL;
71
72         col_set_str(pinfo->cinfo, COL_PROTOCOL, "HCI H4");
73         switch (pinfo->p2p_dir) {
74
75         case P2P_DIR_SENT:
76                 col_add_fstr(pinfo->cinfo, COL_INFO, "Sent ");
77                 break;
78
79         case P2P_DIR_RECV:
80                 col_add_fstr(pinfo->cinfo, COL_INFO, "Rcvd ");
81                 break;
82
83         case P2P_DIR_UNKNOWN:
84                 break;
85
86         default:
87                 col_add_fstr(pinfo->cinfo, COL_INFO, "Unknown direction %d ",
88                     pinfo->p2p_dir);
89                 break;
90         }
91
92         type = tvb_get_guint8(tvb, 0);
93
94         if(tree){
95                 ti = proto_tree_add_item(tree, proto_hci_h4, tvb, 0, 1, ENC_NA);
96                 hci_h4_tree = proto_item_add_subtree(ti, ett_hci_h4);
97         }
98
99         ti=proto_tree_add_uint(hci_h4_tree, hf_hci_h4_direction, tvb, 0, 0, pinfo->p2p_dir);
100         PROTO_ITEM_SET_GENERATED(ti);
101
102         proto_tree_add_item(hci_h4_tree, hf_hci_h4_type,
103                 tvb, 0, 1, ENC_LITTLE_ENDIAN);
104         col_append_fstr(pinfo->cinfo, COL_INFO, "%s",
105                         val_to_str(type, hci_h4_type_vals, "Unknown HCI packet type 0x%02x"));
106
107         next_tvb = tvb_new_subset_remaining(tvb, 1);
108         if(!dissector_try_uint(hci_h4_table, type, next_tvb, pinfo, tree)) {
109                 call_dissector(data_handle, next_tvb, pinfo, tree);
110         }
111 }
112
113
114 void
115 proto_register_hci_h4(void)
116 {
117         static hf_register_info hf[] = {
118         { &hf_hci_h4_type,
119                 { "HCI Packet Type",           "hci_h4.type",
120                 FT_UINT8, BASE_HEX, VALS(hci_h4_type_vals), 0x0,
121                 NULL, HFILL }},
122
123         { &hf_hci_h4_direction,
124                 { "Direction",           "hci_h4.direction",
125                 FT_UINT8, BASE_HEX, VALS(hci_h4_direction_vals), 0x0,
126                 "HCI Packet Direction Sent/Rcvd", HFILL }},
127
128         };
129
130         static gint *ett[] = {
131                 &ett_hci_h4,
132         };
133
134         proto_hci_h4 = proto_register_protocol("Bluetooth HCI H4",
135             "HCI_H4", "hci_h4");
136
137         register_dissector("hci_h4", dissect_hci_h4, proto_hci_h4);
138
139         proto_register_field_array(proto_hci_h4, hf, array_length(hf));
140         proto_register_subtree_array(ett, array_length(ett));
141
142         hci_h4_table = register_dissector_table("hci_h4.type",
143                 "HCI H4 pdu type", FT_UINT8, BASE_HEX);
144 }
145
146 void
147 proto_reg_handoff_hci_h4(void)
148 {
149         dissector_handle_t hci_h4_handle;
150
151         data_handle = find_dissector("data");
152         hci_h4_handle = find_dissector("hci_h4");
153         dissector_add_uint("wtap_encap", WTAP_ENCAP_BLUETOOTH_H4, hci_h4_handle);
154         dissector_add_uint("wtap_encap", WTAP_ENCAP_BLUETOOTH_H4_WITH_PHDR, hci_h4_handle);
155 }
156
157