2 * Routines for the Bluetooth HCI h1 dissection
6 * Wireshark - Network traffic analyzer
7 * By Gerald Combs <gerald@wireshark.org>
8 * Copyright 1998 Gerald Combs
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 #include <epan/packet.h>
28 #include <epan/wmem/wmem.h>
30 #include "packet-bluetooth-hci.h"
32 static int proto_hci_h1
= -1;
34 static int hf_hci_h1_direction
= -1;
36 static gint ett_hci_h1
= -1;
38 static dissector_table_t hci_h1_table
;
39 static dissector_handle_t data_handle
;
41 static wmem_tree_t
*chandle_to_bdaddr_table
= NULL
;
42 static wmem_tree_t
*bdaddr_to_name_table
= NULL
;
43 static wmem_tree_t
*localhost_name
= NULL
;
44 static wmem_tree_t
*localhost_bdaddr
= NULL
;
46 static const value_string hci_h1_type_vals
[] = {
47 {BTHCI_CHANNEL_COMMAND
, "HCI Command"},
48 {BTHCI_CHANNEL_ACL
, "ACL Data"},
49 {BTHCI_CHANNEL_SCO
, "SCO Data"},
50 {BTHCI_CHANNEL_EVENT
, "HCI Event"},
53 static const value_string hci_h1_direction_vals
[] = {
60 void proto_register_hci_h1(void);
61 void proto_reg_handoff_hci_h1(void);
64 dissect_hci_h1(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
, void *data _U_
)
68 proto_item
*ti
= NULL
;
69 proto_tree
*hci_h1_tree
= NULL
;
72 col_set_str(pinfo
->cinfo
, COL_PROTOCOL
, "HCI");
74 col_clear(pinfo
->cinfo
, COL_INFO
);
76 type
= pinfo
->pseudo_header
->bthci
.channel
;
79 ti
= proto_tree_add_item(tree
, proto_hci_h1
, tvb
, 0, 0, ENC_NA
);
80 hci_h1_tree
= proto_item_add_subtree(ti
, ett_hci_h1
);
82 if(pinfo
->p2p_dir
== P2P_DIR_SENT
||
83 pinfo
->p2p_dir
== P2P_DIR_RECV
)
84 proto_item_append_text(hci_h1_tree
, " %s %s",
85 val_to_str(pinfo
->p2p_dir
,
86 hci_h1_direction_vals
, "Unknown: %d"),
91 proto_item_append_text(hci_h1_tree
, " %s",
97 if(pinfo
->p2p_dir
== P2P_DIR_SENT
||
98 pinfo
->p2p_dir
== P2P_DIR_RECV
)
99 col_add_fstr(pinfo
->cinfo
, COL_INFO
, "%s %s",
100 val_to_str(pinfo
->p2p_dir
,
101 hci_h1_direction_vals
, "Unknown: %d"),
102 val_to_str(type
, hci_h1_type_vals
,
105 col_add_fstr(pinfo
->cinfo
, COL_INFO
, "%s",
106 val_to_str(type
, hci_h1_type_vals
,
109 hci_data
= wmem_new(wmem_packet_scope(), hci_data_t
);
110 hci_data
->interface_id
= HCI_INTERFACE_H4
;
111 hci_data
->adapter_id
= HCI_ADAPTER_DEFAULT
;
112 hci_data
->chandle_to_bdaddr_table
= chandle_to_bdaddr_table
;
113 hci_data
->bdaddr_to_name_table
= bdaddr_to_name_table
;
114 hci_data
->localhost_bdaddr
= localhost_bdaddr
;
115 hci_data
->localhost_name
= localhost_name
;
117 pinfo
->ptype
= PT_BLUETOOTH
;
119 ti
= proto_tree_add_int(hci_h1_tree
, hf_hci_h1_direction
, tvb
, 0, 0, pinfo
->p2p_dir
);
120 PROTO_ITEM_SET_GENERATED(ti
);
122 next_tvb
= tvb_new_subset_remaining(tvb
, 0);
123 if (!dissector_try_uint_new(hci_h1_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_h1(void)
134 static hf_register_info hf
[] = {
135 { &hf_hci_h1_direction
,
136 { "Direction", "hci_h1.direction",
137 FT_INT8
, BASE_DEC
, VALS(hci_h1_direction_vals
), 0x0,
138 "HCI Packet Direction Sent/Rcvd/Unknown", HFILL
}
142 static gint
*ett
[] = {
146 proto_hci_h1
= proto_register_protocol("Bluetooth HCI H1",
149 new_register_dissector("hci_h1", dissect_hci_h1
, proto_hci_h1
);
151 proto_register_field_array(proto_hci_h1
, hf
, array_length(hf
));
152 proto_register_subtree_array(ett
, array_length(ett
));
154 hci_h1_table
= register_dissector_table("hci_h1.type",
155 "HCI h1 pdu type", FT_UINT8
, BASE_HEX
);
157 chandle_to_bdaddr_table
= wmem_tree_new_autoreset(wmem_epan_scope(), wmem_file_scope()); /* adapter, chandle: bdaddr */
158 bdaddr_to_name_table
= wmem_tree_new_autoreset(wmem_epan_scope(), wmem_file_scope()); /* bdaddr: name */
159 localhost_bdaddr
= wmem_tree_new_autoreset(wmem_epan_scope(), wmem_file_scope()); /* adaper, frame: bdaddr */
160 localhost_name
= wmem_tree_new_autoreset(wmem_epan_scope(), wmem_file_scope()); /* adaper, frame: name */
164 proto_reg_handoff_hci_h1(void)
166 dissector_handle_t hci_h1_handle
;
168 data_handle
= find_dissector("data");
169 hci_h1_handle
= find_dissector("hci_h1");
170 dissector_add_uint("wtap_encap", WTAP_ENCAP_BLUETOOTH_HCI
, hci_h1_handle
);
174 * Editor modelines - http://www.wireshark.org/tools/modelines.html
179 * indent-tabs-mode: nil
182 * vi: set shiftwidth=4 tabstop=8 expandtab:
183 * :indentSize=4:tabSize=8:noTabs=true: