3 * BlueZ - Bluetooth protocol stack for Linux
5 * Copyright (C) 2004-2010 Marcel Holtmann <marcel@holtmann.org>
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.
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.
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
46 RFKILL_TYPE_BLUETOOTH,
52 enum rfkill_operation {
67 static gboolean rfkill_event(GIOChannel *chan,
68 GIOCondition cond, gpointer data)
70 unsigned char buf[32];
71 struct rfkill_event *event = (void *) buf;
72 struct btd_adapter *adapter;
73 char sysname[PATH_MAX];
77 if (cond & (G_IO_NVAL | G_IO_HUP | G_IO_ERR))
80 fd = g_io_channel_unix_get_fd(chan);
82 memset(buf, 0, sizeof(buf));
84 len = read(fd, buf, sizeof(buf));
91 if (len != sizeof(struct rfkill_event))
94 DBG("RFKILL event idx %u type %u op %u soft %u hard %u",
95 event->idx, event->type, event->op,
96 event->soft, event->hard);
98 if (event->soft || event->hard)
101 if (event->op != RFKILL_OP_CHANGE)
104 if (event->type != RFKILL_TYPE_BLUETOOTH &&
105 event->type != RFKILL_TYPE_ALL)
108 snprintf(sysname, sizeof(sysname) - 1,
109 "/sys/class/rfkill/rfkill%u/name", event->idx);
111 fd = open(sysname, O_RDONLY);
115 memset(sysname, 0, sizeof(sysname));
117 #ifdef __TIZEN_PATCH__
118 if (read(fd, sysname, sizeof(sysname) - 1) < 4) {
123 if (read(fd, sysname, sizeof(sysname)) < 4) {
131 if (g_str_has_prefix(sysname, "hci") == FALSE)
134 id = atoi(sysname + 3);
138 adapter = manager_find_adapter_by_id(id);
142 DBG("RFKILL unblock for hci%d", id);
144 btd_adapter_restore_powered(adapter);
149 static GIOChannel *channel = NULL;
151 void rfkill_init(void)
155 if (!main_opts.remember_powered)
158 fd = open("/dev/rfkill", O_RDWR);
160 error("Failed to open RFKILL control device");
164 channel = g_io_channel_unix_new(fd);
165 g_io_channel_set_close_on_unref(channel, TRUE);
167 g_io_add_watch(channel, G_IO_IN | G_IO_NVAL | G_IO_HUP | G_IO_ERR,
171 void rfkill_exit(void)
176 g_io_channel_shutdown(channel, TRUE, NULL);
177 g_io_channel_unref(channel);