Revert "TODO epan/dissectors/asn1/kerberos/packet-kerberos-template.c new GSS flags"
[wireshark-sm.git] / epan / dissectors / packet-hci_h4.c
blob05ba4d0949a16924054321bb645c31e17c18f324
1 /* packet-hci_h4.c
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
8 * Ronnie Sahlberg 2006
10 * Wireshark - Network traffic analyzer
11 * By Gerald Combs <gerald@wireshark.org>
12 * Copyright 1998 Gerald Combs
14 * SPDX-License-Identifier: GPL-2.0-or-later
17 #include "config.h"
19 #include <epan/packet.h>
20 #include <wiretap/wtap.h>
21 #include "packet-bluetooth.h"
23 static int proto_hci_h4;
24 static int hf_hci_h4_type;
25 static int hf_hci_h4_direction;
27 static int ett_hci_h4;
29 static dissector_handle_t hci_h4_handle;
31 static dissector_table_t hci_h4_table;
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 }
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}
48 void proto_register_hci_h4(void);
49 void proto_reg_handoff_hci_h4(void);
51 static int
52 dissect_hci_h4(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data)
54 uint8_t type;
55 tvbuff_t *next_tvb;
56 proto_item *main_item;
57 proto_tree *main_tree;
58 proto_item *sub_item;
59 bluetooth_data_t *bluetooth_data;
61 bluetooth_data = (bluetooth_data_t *) data;
63 col_set_str(pinfo->cinfo, COL_PROTOCOL, "HCI H4");
64 switch (pinfo->p2p_dir) {
66 case P2P_DIR_SENT:
67 col_set_str(pinfo->cinfo, COL_INFO, "Sent ");
68 break;
70 case P2P_DIR_RECV:
71 col_set_str(pinfo->cinfo, COL_INFO, "Rcvd ");
72 break;
74 case P2P_DIR_UNKNOWN:
75 break;
77 default:
78 col_add_fstr(pinfo->cinfo, COL_INFO, "Unknown direction %d ",
79 pinfo->p2p_dir);
80 break;
83 type = tvb_get_uint8(tvb, 0);
85 main_item = proto_tree_add_item(tree, proto_hci_h4, tvb, 0, 1, ENC_NA);
86 main_tree = proto_item_add_subtree(main_item, ett_hci_h4);
88 sub_item = proto_tree_add_uint(main_tree, hf_hci_h4_direction, tvb, 0, 0, pinfo->p2p_dir);
89 proto_item_set_generated(sub_item);
91 proto_tree_add_item(main_tree, hf_hci_h4_type,
92 tvb, 0, 1, ENC_LITTLE_ENDIAN);
93 col_append_str(pinfo->cinfo, COL_INFO,
94 val_to_str(type, hci_h4_type_vals, "Unknown HCI packet type 0x%02x"));
96 next_tvb = tvb_new_subset_remaining(tvb, 1);
97 if (!dissector_try_uint_with_data(hci_h4_table, type, next_tvb, pinfo, tree, true, bluetooth_data)) {
98 call_data_dissector(next_tvb, pinfo, tree);
101 return 1;
105 void
106 proto_register_hci_h4(void)
108 static hf_register_info hf[] = {
109 { &hf_hci_h4_type,
110 { "HCI Packet Type", "hci_h4.type",
111 FT_UINT8, BASE_HEX, VALS(hci_h4_type_vals), 0x0,
112 NULL, HFILL }
114 { &hf_hci_h4_direction,
115 { "Direction", "hci_h4.direction",
116 FT_UINT8, BASE_HEX, VALS(hci_h4_direction_vals), 0x0,
117 "HCI Packet Direction Sent/Rcvd", HFILL }
121 static int *ett[] = {
122 &ett_hci_h4,
125 proto_hci_h4 = proto_register_protocol("Bluetooth HCI H4", "HCI_H4", "hci_h4");
127 hci_h4_handle = register_dissector("hci_h4", dissect_hci_h4, proto_hci_h4);
129 proto_register_field_array(proto_hci_h4, hf, array_length(hf));
130 proto_register_subtree_array(ett, array_length(ett));
132 hci_h4_table = register_dissector_table("hci_h4.type",
133 "HCI H4 pdu type", proto_hci_h4, FT_UINT8, BASE_HEX);
136 void
137 proto_reg_handoff_hci_h4(void)
139 dissector_add_uint("bluetooth.encap", WTAP_ENCAP_BLUETOOTH_H4, hci_h4_handle);
140 dissector_add_uint("bluetooth.encap", WTAP_ENCAP_BLUETOOTH_H4_WITH_PHDR, hci_h4_handle);
144 * Editor modelines - https://www.wireshark.org/tools/modelines.html
146 * Local variables:
147 * c-basic-offset: 4
148 * tab-width: 8
149 * indent-tabs-mode: nil
150 * End:
152 * vi: set shiftwidth=4 tabstop=8 expandtab:
153 * :indentSize=4:tabSize=8:noTabs=true: