2 * Routines for the Bluetooth HCI H4 dissection
4 * Copyright 2002, Christoph Scholz <scholz@cs.uni-bonn.de>
5 * From: http://affix.sourceforge.net/archive/ethereal_affix-3.patch
7 * Refactored for wireshark checkin
10 * Wireshark - Network traffic analyzer
11 * By Gerald Combs <gerald@wireshark.org>
12 * Copyright 1998 Gerald Combs
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License
16 * as published by the Free Software Foundation; either version 2
17 * of the License, or (at your option) any later version.
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
31 #include <epan/packet.h>
32 #include <wiretap/wtap.h>
33 #include <epan/wmem/wmem.h>
35 #include "packet-bluetooth-hci.h"
37 static int proto_hci_h4 = -1;
38 static int hf_hci_h4_type = -1;
39 static int hf_hci_h4_direction = -1;
41 static gint ett_hci_h4 = -1;
43 static dissector_table_t hci_h4_table;
44 static dissector_handle_t data_handle;
46 static wmem_tree_t *chandle_to_bdaddr_table = NULL;
47 static wmem_tree_t *bdaddr_to_name_table = NULL;
48 static wmem_tree_t *localhost_name = NULL;
49 static wmem_tree_t *localhost_bdaddr = NULL;
51 static const value_string hci_h4_type_vals[] = {
52 {HCI_H4_TYPE_CMD, "HCI Command"},
53 {HCI_H4_TYPE_ACL, "ACL Data"},
54 {HCI_H4_TYPE_SCO, "SCO Data"},
55 {HCI_H4_TYPE_EVT, "HCI Event"},
58 static const value_string hci_h4_direction_vals[] = {
59 {P2P_DIR_SENT, "Sent"},
60 {P2P_DIR_RECV, "Rcvd"},
61 {P2P_DIR_UNKNOWN, "Unspecified"},
65 void proto_register_hci_h4(void);
66 void proto_reg_handoff_hci_h4(void);
69 dissect_hci_h4(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
73 proto_item *ti = NULL;
74 proto_tree *hci_h4_tree = NULL;
77 col_set_str(pinfo->cinfo, COL_PROTOCOL, "HCI H4");
78 switch (pinfo->p2p_dir) {
81 col_add_fstr(pinfo->cinfo, COL_INFO, "Sent ");
85 col_add_fstr(pinfo->cinfo, COL_INFO, "Rcvd ");
92 col_add_fstr(pinfo->cinfo, COL_INFO, "Unknown direction %d ",
97 type = tvb_get_guint8(tvb, 0);
100 ti = proto_tree_add_item(tree, proto_hci_h4, tvb, 0, 1, ENC_NA);
101 hci_h4_tree = proto_item_add_subtree(ti, ett_hci_h4);
104 hci_data = (hci_data_t *) wmem_new(wmem_packet_scope(), hci_data_t);
105 hci_data->interface_id = HCI_INTERFACE_H4;
106 hci_data->adapter_id = HCI_ADAPTER_DEFAULT;
107 hci_data->chandle_to_bdaddr_table = chandle_to_bdaddr_table;
108 hci_data->bdaddr_to_name_table = bdaddr_to_name_table;
109 hci_data->localhost_bdaddr = localhost_bdaddr;
110 hci_data->localhost_name = localhost_name;
112 pinfo->ptype = PT_BLUETOOTH;
114 ti = proto_tree_add_uint(hci_h4_tree, hf_hci_h4_direction, tvb, 0, 0, pinfo->p2p_dir);
115 PROTO_ITEM_SET_GENERATED(ti);
117 proto_tree_add_item(hci_h4_tree, hf_hci_h4_type,
118 tvb, 0, 1, ENC_LITTLE_ENDIAN);
119 col_append_fstr(pinfo->cinfo, COL_INFO, "%s",
120 val_to_str(type, hci_h4_type_vals, "Unknown HCI packet type 0x%02x"));
122 next_tvb = tvb_new_subset_remaining(tvb, 1);
123 if (!dissector_try_uint_new(hci_h4_table, type, next_tvb, pinfo, tree, TRUE, hci_data)) {
124 call_dissector(data_handle, next_tvb, pinfo, tree);
127 return tvb_length(tvb);
132 proto_register_hci_h4(void)
134 static hf_register_info hf[] = {
136 { "HCI Packet Type", "hci_h4.type",
137 FT_UINT8, BASE_HEX, VALS(hci_h4_type_vals), 0x0,
140 { &hf_hci_h4_direction,
141 { "Direction", "hci_h4.direction",
142 FT_UINT8, BASE_HEX, VALS(hci_h4_direction_vals), 0x0,
143 "HCI Packet Direction Sent/Rcvd", HFILL }
147 static gint *ett[] = {
151 proto_hci_h4 = proto_register_protocol("Bluetooth HCI H4",
154 new_register_dissector("hci_h4", dissect_hci_h4, proto_hci_h4);
156 proto_register_field_array(proto_hci_h4, hf, array_length(hf));
157 proto_register_subtree_array(ett, array_length(ett));
159 hci_h4_table = register_dissector_table("hci_h4.type",
160 "HCI H4 pdu type", FT_UINT8, BASE_HEX);
162 chandle_to_bdaddr_table = wmem_tree_new_autoreset(wmem_epan_scope(), wmem_file_scope()); /* adapter, chandle: bdaddr */
163 bdaddr_to_name_table = wmem_tree_new_autoreset(wmem_epan_scope(), wmem_file_scope()); /* bdaddr: name */
164 localhost_bdaddr = wmem_tree_new_autoreset(wmem_epan_scope(), wmem_file_scope()); /* adapter, frame: bdaddr */
165 localhost_name = wmem_tree_new_autoreset(wmem_epan_scope(), wmem_file_scope()); /* adapter, frame: name */
169 proto_reg_handoff_hci_h4(void)
171 dissector_handle_t hci_h4_handle;
173 data_handle = find_dissector("data");
174 hci_h4_handle = find_dissector("hci_h4");
175 dissector_add_uint("wtap_encap", WTAP_ENCAP_BLUETOOTH_H4, hci_h4_handle);
176 dissector_add_uint("wtap_encap", WTAP_ENCAP_BLUETOOTH_H4_WITH_PHDR, hci_h4_handle);
180 * Editor modelines - http://www.wireshark.org/tools/modelines.html
185 * indent-tabs-mode: nil
188 * vi: set shiftwidth=4 tabstop=8 expandtab:
189 * :indentSize=4:tabSize=8:noTabs=true: