2
* Copyright 2007, Intel Corporation
4
* This file is part of PowerTOP
6
* This program file is free software; you can redistribute it and/or modify it
7
* under the terms of the GNU General Public License as published by the
8
* Free Software Foundation; version 2 of the License.
10
* This program is distributed in the hope that it will be useful, but WITHOUT
11
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15
* You should have received a copy of the GNU General Public License
16
* along with this program in a file named COPYING; if not, write to the
17
* Free Software Foundation, Inc.,
18
* 51 Franklin Street, Fifth Floor,
19
* Boston, MA 02110-1301 USA
22
* Arjan van de Ven <arjan@linux.intel.com>
30
#include <sys/types.h>
32
#include <sys/types.h>
33
#include <sys/socket.h>
34
#include <sys/ioctl.h>
40
/* structure definitions copied from include/net/bluetooth/hci.h from the 2.6.20 kernel */
41
#define HCIGETDEVINFO _IOR('H', 211, int)
44
#define __u16 uint16_t
46
#define __u32 uint32_t
48
static int suggested = 0;
52
} __attribute__((packed)) bdaddr_t;
54
struct hci_dev_stats {
88
struct hci_dev_stats stat;
91
static int previous_bytes = -1;
93
void turn_bluetooth_off(void)
96
system("/usr/sbin/hciconfig hci0 down &> /dev/null");
97
system("/sbin/rmmod hci_usb &> /dev/null");
100
void suggest_bluetooth_off(void)
102
struct hci_dev_info devinfo;
111
/* first check if /sys/modules/bluetooth exists, if not, don't probe bluetooth because
112
it would trigger an autoload */
114
if (access("/sys/module/bluetooth",F_OK))
117
fd = socket(AF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI);
121
memset(&devinfo, 0, sizeof(devinfo));
122
strcpy(devinfo.name, "hci0");
123
ret = ioctl(fd, HCIGETDEVINFO, (void *) &devinfo);
127
if ( (devinfo.flags & 1) == 0 &&
128
access("/sys/module/hci_usb",F_OK)) /* interface down already */
131
thisbytes += devinfo.stat.byte_rx;
132
thisbytes += devinfo.stat.byte_tx;
134
if (thisbytes != previous_bytes)
137
/* now, also check for active connections */
138
file = popen("/usr/bin/hcitool con 2> /dev/null", "r");
141
/* first line is standard header */
142
fgets(line,2048,file);
143
memset(line, 0, 2048);
144
fgets(line, 2047, file);
150
add_suggestion( _("Suggestion: Disable the unused bluetooth interface with the following command:\n"
151
" hciconfig hci0 down ; rmmod hci_usb\n"
152
"Bluetooth is a radio and consumes quite some power, and keeps USB busy as well.\n"), 40, 'B' , _(" B - Turn Bluetooth off "), turn_bluetooth_off);
154
previous_bytes = thisbytes;