/src/wireshark/epan/dissectors/packet-hci_h1.c
Line | Count | Source |
1 | | /* packet-hci_h1.c |
2 | | * Routines for the Bluetooth HCI H1 dissection |
3 | | * |
4 | | * Wireshark - Network traffic analyzer |
5 | | * By Gerald Combs <gerald@wireshark.org> |
6 | | * Copyright 1998 Gerald Combs |
7 | | * |
8 | | * SPDX-License-Identifier: GPL-2.0-or-later |
9 | | */ |
10 | | |
11 | | #include "config.h" |
12 | | |
13 | | #include <epan/packet.h> |
14 | | #include <wiretap/wtap.h> |
15 | | |
16 | | #include "packet-bluetooth.h" |
17 | | |
18 | | static int proto_hci_h1; |
19 | | |
20 | | static int hf_hci_h1_direction; |
21 | | |
22 | | static int ett_hci_h1; |
23 | | |
24 | | static dissector_table_t hci_h1_table; |
25 | | |
26 | | static dissector_handle_t hci_h1_handle; |
27 | | |
28 | | static const value_string hci_h1_type_vals[] = { |
29 | | {BTHCI_CHANNEL_COMMAND, "HCI Command"}, |
30 | | {BTHCI_CHANNEL_ACL, "ACL Data"}, |
31 | | {BTHCI_CHANNEL_SCO, "SCO Data"}, |
32 | | {BTHCI_CHANNEL_EVENT, "HCI Event"}, |
33 | | {BTHCI_CHANNEL_ISO, "ISO Data"}, |
34 | | {0, NULL } |
35 | | }; |
36 | | static const value_string hci_h1_direction_vals[] = { |
37 | | {-1, "Unknown"}, |
38 | | {0, "Sent"}, |
39 | | {1, "Rcvd"}, |
40 | | {0, NULL} |
41 | | }; |
42 | | |
43 | | void proto_register_hci_h1(void); |
44 | | void proto_reg_handoff_hci_h1(void); |
45 | | |
46 | | static int |
47 | | dissect_hci_h1(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data) |
48 | 0 | { |
49 | 0 | uint8_t type; |
50 | 0 | tvbuff_t *next_tvb; |
51 | 0 | proto_item *ti = NULL; |
52 | 0 | proto_tree *hci_h1_tree = NULL; |
53 | 0 | bluetooth_data_t *bluetooth_data; |
54 | |
|
55 | 0 | bluetooth_data = (bluetooth_data_t *) data; |
56 | |
|
57 | 0 | col_set_str(pinfo->cinfo, COL_PROTOCOL, "HCI"); |
58 | |
|
59 | 0 | col_clear(pinfo->cinfo, COL_INFO); |
60 | |
|
61 | 0 | DISSECTOR_ASSERT(bluetooth_data->previous_protocol_data_type == BT_PD_BTHCI); |
62 | 0 | type = bluetooth_data->previous_protocol_data.bthci->channel; |
63 | |
|
64 | 0 | if (tree) { |
65 | 0 | ti = proto_tree_add_item(tree, proto_hci_h1, tvb, 0, 0, ENC_NA); |
66 | 0 | hci_h1_tree = proto_item_add_subtree(ti, ett_hci_h1); |
67 | |
|
68 | 0 | if(pinfo->p2p_dir == P2P_DIR_SENT || |
69 | 0 | pinfo->p2p_dir == P2P_DIR_RECV) |
70 | 0 | proto_item_append_text(hci_h1_tree, " %s %s", |
71 | 0 | val_to_str(pinfo->pool, pinfo->p2p_dir, |
72 | 0 | hci_h1_direction_vals, "Unknown: %d"), |
73 | 0 | val_to_str(pinfo->pool, type, |
74 | 0 | hci_h1_type_vals, |
75 | 0 | "Unknown 0x%02x")); |
76 | 0 | else |
77 | 0 | proto_item_append_text(hci_h1_tree, " %s", |
78 | 0 | val_to_str(pinfo->pool, type, |
79 | 0 | hci_h1_type_vals, |
80 | 0 | "Unknown 0x%02x")); |
81 | 0 | } |
82 | |
|
83 | 0 | if(pinfo->p2p_dir == P2P_DIR_SENT || |
84 | 0 | pinfo->p2p_dir == P2P_DIR_RECV) |
85 | 0 | col_add_fstr(pinfo->cinfo, COL_INFO, "%s %s", |
86 | 0 | val_to_str(pinfo->pool, pinfo->p2p_dir, |
87 | 0 | hci_h1_direction_vals, "Unknown: %d"), |
88 | 0 | val_to_str(pinfo->pool, type, hci_h1_type_vals, |
89 | 0 | "Unknown 0x%02x")); |
90 | 0 | else |
91 | 0 | col_add_str(pinfo->cinfo, COL_INFO, |
92 | 0 | val_to_str(pinfo->pool, type, hci_h1_type_vals, |
93 | 0 | "Unknown 0x%02x")); |
94 | |
|
95 | 0 | ti = proto_tree_add_int(hci_h1_tree, hf_hci_h1_direction, tvb, 0, 0, pinfo->p2p_dir); |
96 | 0 | proto_item_set_generated(ti); |
97 | |
|
98 | 0 | next_tvb = tvb_new_subset_remaining(tvb, 0); |
99 | 0 | if (!dissector_try_uint_with_data(hci_h1_table, type, next_tvb, pinfo, tree, true, bluetooth_data)) { |
100 | 0 | call_data_dissector(next_tvb, pinfo, tree); |
101 | 0 | } |
102 | |
|
103 | 0 | return tvb_reported_length(tvb); |
104 | 0 | } |
105 | | |
106 | | |
107 | | void |
108 | | proto_register_hci_h1(void) |
109 | 16 | { |
110 | 16 | static hf_register_info hf[] = { |
111 | 16 | { &hf_hci_h1_direction, |
112 | 16 | { "Direction", "hci_h1.direction", |
113 | 16 | FT_INT8, BASE_DEC, VALS(hci_h1_direction_vals), 0x0, |
114 | 16 | "HCI Packet Direction Sent/Rcvd/Unknown", HFILL } |
115 | 16 | } |
116 | 16 | }; |
117 | | |
118 | 16 | static int *ett[] = { |
119 | 16 | &ett_hci_h1, |
120 | 16 | }; |
121 | | |
122 | 16 | proto_hci_h1 = proto_register_protocol("Bluetooth HCI H1", |
123 | 16 | "HCI_H1", "hci_h1"); |
124 | | |
125 | 16 | hci_h1_handle = register_dissector("hci_h1", dissect_hci_h1, proto_hci_h1); |
126 | | |
127 | 16 | proto_register_field_array(proto_hci_h1, hf, array_length(hf)); |
128 | 16 | proto_register_subtree_array(ett, array_length(ett)); |
129 | | |
130 | 16 | hci_h1_table = register_dissector_table("hci_h1.type", |
131 | 16 | "HCI h1 pdu type", proto_hci_h1, FT_UINT8, BASE_HEX); |
132 | 16 | } |
133 | | |
134 | | void |
135 | | proto_reg_handoff_hci_h1(void) |
136 | 16 | { |
137 | 16 | dissector_add_uint("bluetooth.encap", WTAP_ENCAP_BLUETOOTH_HCI, hci_h1_handle); |
138 | 16 | } |
139 | | |
140 | | /* |
141 | | * Editor modelines - https://www.wireshark.org/tools/modelines.html |
142 | | * |
143 | | * Local variables: |
144 | | * c-basic-offset: 4 |
145 | | * tab-width: 8 |
146 | | * indent-tabs-mode: nil |
147 | | * End: |
148 | | * |
149 | | * vi: set shiftwidth=4 tabstop=8 expandtab: |
150 | | * :indentSize=4:tabSize=8:noTabs=true: |
151 | | */ |