Fix build break for rpm
[framework/connectivity/bluez.git] / tools / hcieventmask.c
1 /*
2  *
3  *  BlueZ - Bluetooth protocol stack for Linux
4  *
5  *  Copyright (C) 2002-2010  Marcel Holtmann <marcel@holtmann.org>
6  *
7  *
8  *  This program is free software; you can redistribute it and/or modify
9  *  it under the terms of the GNU General Public License as published by
10  *  the Free Software Foundation; either version 2 of the License, or
11  *  (at your option) any later version.
12  *
13  *  This program is distributed in the hope that it will be useful,
14  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  *  GNU General Public License for more details.
17  *
18  *  You should have received a copy of the GNU General Public License
19  *  along with this program; if not, write to the Free Software
20  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
21  *
22  */
23
24 #ifdef HAVE_CONFIG_H
25 #include <config.h>
26 #endif
27
28 #include <stdio.h>
29 #include <errno.h>
30 #include <stdlib.h>
31 #include <getopt.h>
32 #include <sys/socket.h>
33
34 #include <bluetooth/bluetooth.h>
35 #include <bluetooth/hci.h>
36 #include <bluetooth/hci_lib.h>
37
38 static struct option main_options[] = {
39         { "device",     1, 0, 'i' },
40         { 0, 0, 0, 0 }
41 };
42
43 int main(int argc, char *argv[])
44 {
45         uint8_t events[8] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, 0x00, 0x00 };
46         struct hci_dev_info di;
47         struct hci_version ver;
48         int dd, opt, dev = 0;
49
50         while ((opt=getopt_long(argc, argv, "+i:", main_options, NULL)) != -1) {
51                 switch (opt) {
52                 case 'i':
53                         dev = hci_devid(optarg);
54                         if (dev < 0) {
55                                 perror("Invalid device");
56                                 exit(1);
57                         }
58                         break;
59                 }
60         }
61
62         dd = hci_open_dev(dev);
63         if (dd < 0) {
64                 fprintf(stderr, "Can't open device hci%d: %s (%d)\n",
65                                                 dev, strerror(errno), errno);
66                 exit(1);
67         }
68
69         if (hci_devinfo(dev, &di) < 0) {
70                 fprintf(stderr, "Can't get device info for hci%d: %s (%d)\n",
71                                                 dev, strerror(errno), errno);
72                 hci_close_dev(dd);
73                 exit(1);
74         }
75
76         if (hci_read_local_version(dd, &ver, 1000) < 0) {
77                 fprintf(stderr, "Can't read version info for hci%d: %s (%d)\n",
78                                                 dev, strerror(errno), errno);
79                 hci_close_dev(dd);
80                 exit(1);
81         }
82
83         hci_close_dev(dd);
84
85         if (ver.hci_ver > 1) {
86                 if (di.features[5] & LMP_SNIFF_SUBR)
87                         events[5] |= 0x20;
88
89                 if (di.features[5] & LMP_PAUSE_ENC)
90                         events[5] |= 0x80;
91
92                 if (di.features[6] & LMP_EXT_INQ)
93                         events[5] |= 0x40;
94
95                 if (di.features[6] & LMP_NFLUSH_PKTS)
96                         events[7] |= 0x01;
97
98                 if (di.features[7] & LMP_LSTO)
99                         events[6] |= 0x80;
100
101                 if (di.features[6] & LMP_SIMPLE_PAIR) {
102                         events[6] |= 0x01;      /* IO Capability Request */
103                         events[6] |= 0x02;      /* IO Capability Response */
104                         events[6] |= 0x04;      /* User Confirmation Request */
105                         events[6] |= 0x08;      /* User Passkey Request */
106                         events[6] |= 0x10;      /* Remote OOB Data Request */
107                         events[6] |= 0x20;      /* Simple Pairing Complete */
108                         events[7] |= 0x04;      /* User Passkey Notification */
109                         events[7] |= 0x08;      /* Keypress Notification */
110                         events[7] |= 0x10;      /* Remote Host Supported
111                                                  * Features Notification */
112                 }
113
114                 if (di.features[4] & LMP_LE)
115                         events[7] |= 0x20;
116
117                 if (di.features[6] & LMP_LE_BREDR)
118                         events[7] |= 0x20;
119         }
120
121         printf("Setting event mask:\n");
122         printf("\thcitool cmd 0x%02x 0x%04x  "
123                                         "0x%02x 0x%02x 0x%02x 0x%02x "
124                                         "0x%02x 0x%02x 0x%02x 0x%02x\n",
125                                 OGF_HOST_CTL, OCF_SET_EVENT_MASK,
126                                 events[0], events[1], events[2], events[3],
127                                 events[4], events[5], events[6], events[7]);
128
129         return 0;
130 }