/src/wireshark/epan/dissectors/packet-hci_h4.c
Line | Count | Source |
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 | | * Wireshark - Network traffic analyzer |
11 | | * By Gerald Combs <gerald@wireshark.org> |
12 | | * Copyright 1998 Gerald Combs |
13 | | * |
14 | | * SPDX-License-Identifier: GPL-2.0-or-later |
15 | | */ |
16 | | |
17 | | #include "config.h" |
18 | | |
19 | | #include <epan/packet.h> |
20 | | #include <wiretap/wtap.h> |
21 | | #include "packet-bluetooth.h" |
22 | | |
23 | | static int proto_hci_h4; |
24 | | static int hf_hci_h4_type; |
25 | | static int hf_hci_h4_direction; |
26 | | |
27 | | static int ett_hci_h4; |
28 | | |
29 | | static dissector_handle_t hci_h4_handle; |
30 | | |
31 | | static dissector_table_t hci_h4_table; |
32 | | |
33 | | static const value_string hci_h4_type_vals[] = { |
34 | | {HCI_H4_TYPE_CMD, "HCI Command"}, |
35 | | {HCI_H4_TYPE_ACL, "ACL Data"}, |
36 | | {HCI_H4_TYPE_SCO, "SCO Data"}, |
37 | | {HCI_H4_TYPE_EVT, "HCI Event"}, |
38 | | {HCI_H4_TYPE_ISO, "ISO Data"}, |
39 | | {0, NULL } |
40 | | }; |
41 | | static const value_string hci_h4_direction_vals[] = { |
42 | | {P2P_DIR_SENT, "Sent"}, |
43 | | {P2P_DIR_RECV, "Rcvd"}, |
44 | | {P2P_DIR_UNKNOWN, "Unspecified"}, |
45 | | {0, NULL} |
46 | | }; |
47 | | |
48 | | void proto_register_hci_h4(void); |
49 | | void proto_reg_handoff_hci_h4(void); |
50 | | |
51 | | static int |
52 | | dissect_hci_h4(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data) |
53 | 146 | { |
54 | 146 | uint8_t type; |
55 | 146 | tvbuff_t *next_tvb; |
56 | 146 | proto_item *main_item; |
57 | 146 | proto_tree *main_tree; |
58 | 146 | proto_item *sub_item; |
59 | 146 | bluetooth_data_t *bluetooth_data; |
60 | | |
61 | 146 | bluetooth_data = (bluetooth_data_t *) data; |
62 | | |
63 | 146 | col_set_str(pinfo->cinfo, COL_PROTOCOL, "HCI H4"); |
64 | 146 | switch (pinfo->p2p_dir) { |
65 | | |
66 | 1 | case P2P_DIR_SENT: |
67 | 1 | col_set_str(pinfo->cinfo, COL_INFO, "Sent "); |
68 | 1 | break; |
69 | | |
70 | 0 | case P2P_DIR_RECV: |
71 | 0 | col_set_str(pinfo->cinfo, COL_INFO, "Rcvd "); |
72 | 0 | break; |
73 | | |
74 | 145 | case P2P_DIR_UNKNOWN: |
75 | 145 | break; |
76 | | |
77 | 0 | default: |
78 | 0 | col_add_fstr(pinfo->cinfo, COL_INFO, "Unknown direction %d ", |
79 | 0 | pinfo->p2p_dir); |
80 | 0 | break; |
81 | 146 | } |
82 | | |
83 | 146 | type = tvb_get_uint8(tvb, 0); |
84 | | |
85 | 146 | main_item = proto_tree_add_item(tree, proto_hci_h4, tvb, 0, 1, ENC_NA); |
86 | 146 | main_tree = proto_item_add_subtree(main_item, ett_hci_h4); |
87 | | |
88 | 146 | sub_item = proto_tree_add_uint(main_tree, hf_hci_h4_direction, tvb, 0, 0, pinfo->p2p_dir); |
89 | 146 | proto_item_set_generated(sub_item); |
90 | | |
91 | 146 | proto_tree_add_item(main_tree, hf_hci_h4_type, |
92 | 146 | tvb, 0, 1, ENC_LITTLE_ENDIAN); |
93 | 146 | col_append_str(pinfo->cinfo, COL_INFO, |
94 | 146 | val_to_str(pinfo->pool, type, hci_h4_type_vals, "Unknown HCI packet type 0x%02x")); |
95 | | |
96 | 146 | next_tvb = tvb_new_subset_remaining(tvb, 1); |
97 | 146 | if (!dissector_try_uint_with_data(hci_h4_table, type, next_tvb, pinfo, tree, true, bluetooth_data)) { |
98 | 4 | call_data_dissector(next_tvb, pinfo, tree); |
99 | 4 | } |
100 | | |
101 | 146 | return 1; |
102 | 146 | } |
103 | | |
104 | | |
105 | | void |
106 | | proto_register_hci_h4(void) |
107 | 14 | { |
108 | 14 | static hf_register_info hf[] = { |
109 | 14 | { &hf_hci_h4_type, |
110 | 14 | { "HCI Packet Type", "hci_h4.type", |
111 | 14 | FT_UINT8, BASE_HEX, VALS(hci_h4_type_vals), 0x0, |
112 | 14 | NULL, HFILL } |
113 | 14 | }, |
114 | 14 | { &hf_hci_h4_direction, |
115 | 14 | { "Direction", "hci_h4.direction", |
116 | 14 | FT_UINT8, BASE_HEX, VALS(hci_h4_direction_vals), 0x0, |
117 | 14 | "HCI Packet Direction Sent/Rcvd", HFILL } |
118 | 14 | } |
119 | 14 | }; |
120 | | |
121 | 14 | static int *ett[] = { |
122 | 14 | &ett_hci_h4, |
123 | 14 | }; |
124 | | |
125 | 14 | proto_hci_h4 = proto_register_protocol("Bluetooth HCI H4", "HCI_H4", "hci_h4"); |
126 | | |
127 | 14 | hci_h4_handle = register_dissector("hci_h4", dissect_hci_h4, proto_hci_h4); |
128 | | |
129 | 14 | proto_register_field_array(proto_hci_h4, hf, array_length(hf)); |
130 | 14 | proto_register_subtree_array(ett, array_length(ett)); |
131 | | |
132 | 14 | hci_h4_table = register_dissector_table("hci_h4.type", |
133 | 14 | "HCI H4 pdu type", proto_hci_h4, FT_UINT8, BASE_HEX); |
134 | 14 | } |
135 | | |
136 | | void |
137 | | proto_reg_handoff_hci_h4(void) |
138 | 14 | { |
139 | 14 | dissector_add_uint("bluetooth.encap", WTAP_ENCAP_BLUETOOTH_H4, hci_h4_handle); |
140 | 14 | dissector_add_uint("bluetooth.encap", WTAP_ENCAP_BLUETOOTH_H4_WITH_PHDR, hci_h4_handle); |
141 | 14 | } |
142 | | |
143 | | /* |
144 | | * Editor modelines - https://www.wireshark.org/tools/modelines.html |
145 | | * |
146 | | * Local variables: |
147 | | * c-basic-offset: 4 |
148 | | * tab-width: 8 |
149 | | * indent-tabs-mode: nil |
150 | | * End: |
151 | | * |
152 | | * vi: set shiftwidth=4 tabstop=8 expandtab: |
153 | | * :indentSize=4:tabSize=8:noTabs=true: |
154 | | */ |