Trivial warning fixes
[obnox/wireshark/wip.git] / epan / dissectors / packet-hci_h1.c
1 /* packet-hci_h1.c
2  * Routines for the Bluetooth HCI h1 dissection
3  *
4  * $Id$
5  *
6  * Wireshark - Network traffic analyzer
7  * By Gerald Combs <gerald@wireshark.org>
8  * Copyright 1998 Gerald Combs
9  *
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.
14  *
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.
19  *
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23  */
24
25 #ifdef HAVE_CONFIG_H
26 #include "config.h"
27 #endif
28
29 #include <epan/packet.h>
30
31 #include "packet-hci_h1.h"
32
33
34 static int proto_hci_h1 = -1;
35 static int hf_hci_h1_type = -1;
36 static int hf_hci_h1_direction = -1;
37
38 static gint ett_hci_h1 = -1;
39
40 static dissector_table_t hci_h1_table;
41 static dissector_handle_t data_handle;
42
43
44 static const value_string hci_h1_type_vals[] = {
45         {BTHCI_CHANNEL_COMMAND, "HCI Command"},
46         {BTHCI_CHANNEL_ACL, "ACL Data"},
47         {BTHCI_CHANNEL_SCO, "SCO Data"},
48         {BTHCI_CHANNEL_EVENT, "HCI Event"},
49         {0, NULL }
50 };
51 static const value_string hci_h1_direction_vals[] = {
52         {0,     "Sent"},
53         {1,     "Rcvd"},
54         {0, NULL}
55 };
56
57 static void
58 dissect_hci_h1(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
59 {
60         guint8 type;
61         tvbuff_t *next_tvb;
62         proto_item *ti=NULL;
63         proto_tree *hci_h1_tree=NULL;
64
65         if(check_col(pinfo->cinfo, COL_PROTOCOL))
66                 col_set_str(pinfo->cinfo, COL_PROTOCOL, "HCI");
67
68         if(check_col(pinfo->cinfo, COL_INFO))
69                 col_clear(pinfo->cinfo, COL_INFO);
70
71         type = pinfo->pseudo_header->bthci.channel;
72
73         if(tree){
74                 ti = proto_tree_add_item(tree, proto_hci_h1, tvb, 0, 1, FALSE);
75                 hci_h1_tree = proto_item_add_subtree(ti, ett_hci_h1);
76         }
77
78         if(check_col(pinfo->cinfo, COL_INFO)){
79                 col_add_fstr(pinfo->cinfo, COL_INFO, "%s %s",pinfo->p2p_dir==P2P_DIR_SENT?"Sent":"Rcvd",val_to_str(type, hci_h1_type_vals, "Unknown 0x%02x"));
80         }
81         ti=proto_tree_add_uint(hci_h1_tree, hf_hci_h1_direction, tvb, 0, 0, pinfo->p2p_dir);
82         PROTO_ITEM_SET_GENERATED(ti);
83         proto_item_append_text(hci_h1_tree, " %s %s", val_to_str(pinfo->p2p_dir, hci_h1_direction_vals, "0x%02x"), val_to_str(type, hci_h1_type_vals, "Unknown 0x%02x"));
84
85         next_tvb = tvb_new_subset(tvb, 0, -1, -1);
86         if(!dissector_try_port(hci_h1_table, type, next_tvb, pinfo, tree)) {
87                 call_dissector(data_handle, next_tvb, pinfo, tree);
88         }
89 }
90
91
92 void
93 proto_register_hci_h1(void)
94 {
95         static hf_register_info hf[] = {
96         { &hf_hci_h1_type,
97                 { "HCI Packet Type",           "hci_h1.type",
98                 FT_UINT8, BASE_HEX, VALS(hci_h1_type_vals), 0x0,
99                 "HCI Packet Type", HFILL }},
100
101         { &hf_hci_h1_direction,
102                 { "Direction",           "hci_h1.direction",
103                 FT_UINT8, BASE_HEX, VALS(hci_h1_direction_vals), 0x0,
104                 "HCI Packet Direction Sent/Rcvd", HFILL }},
105
106         };
107
108         static gint *ett[] = {
109                 &ett_hci_h1,
110         };
111
112         proto_hci_h1 = proto_register_protocol("Bluetooth HCI",
113             "HCI_H1", "hci_h1");
114
115         register_dissector("hci_h1", dissect_hci_h1, proto_hci_h1);
116
117         proto_register_field_array(proto_hci_h1, hf, array_length(hf));
118         proto_register_subtree_array(ett, array_length(ett));
119
120         hci_h1_table = register_dissector_table("hci_h1.type",
121                 "HCI h1 pdu type", FT_UINT8, BASE_HEX);
122 }
123
124 void
125 proto_reg_handoff_hci_h1(void)
126 {
127         dissector_handle_t hci_h1_handle;
128
129         data_handle = find_dissector("data");
130         hci_h1_handle = find_dissector("hci_h1");
131         dissector_add("wtap_encap", WTAP_ENCAP_BLUETOOTH_HCI, hci_h1_handle);
132 }
133
134