5 * Copyright (C) 2007-2010 Intel Corporation. All rights reserved.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
38 RFKILL_TYPE_BLUETOOTH,
44 enum rfkill_operation {
59 static GIOStatus rfkill_process(GIOChannel *chan)
61 GIOStatus status = G_IO_STATUS_NORMAL;
62 unsigned char buf[32];
63 struct rfkill_event *event = (void *) buf;
65 connman_bool_t blocked;
70 memset(buf, 0, sizeof(buf));
72 status = g_io_channel_read_chars(chan, (gchar *) buf,
73 sizeof(struct rfkill_event), &len, NULL);
75 if (status != G_IO_STATUS_NORMAL)
78 if (len != sizeof(struct rfkill_event))
81 DBG("idx %u type %u op %u soft %u hard %u",
82 event->idx, event->type, event->op,
83 event->soft, event->hard);
85 snprintf(sysname, sizeof(sysname) - 1, "rfkill%d", event->idx);
87 blocked = (event->soft || event->hard) ? TRUE : FALSE;
89 switch (event->type) {
91 case RFKILL_TYPE_WLAN:
92 __connman_udev_rfkill(sysname, blocked);
101 static gboolean rfkill_event(GIOChannel *chan,
102 GIOCondition cond, gpointer data)
104 if (cond & (G_IO_NVAL | G_IO_HUP | G_IO_ERR))
107 if (rfkill_process(chan) == G_IO_STATUS_ERROR)
113 static GIOChannel *channel = NULL;
115 int __connman_rfkill_init(void)
122 fd = open("/dev/rfkill", O_RDWR);
124 connman_error("Failed to open RFKILL control device");
128 channel = g_io_channel_unix_new(fd);
129 g_io_channel_set_close_on_unref(channel, TRUE);
131 flags = g_io_channel_get_flags(channel);
132 flags |= G_IO_FLAG_NONBLOCK;
133 g_io_channel_set_flags(channel, flags, NULL);
135 /* Process current RFKILL events sent on device open */
136 while (rfkill_process(channel) == G_IO_STATUS_NORMAL);
138 g_io_add_watch(channel, G_IO_IN | G_IO_NVAL | G_IO_HUP | G_IO_ERR,
144 void __connman_rfkill_cleanup(void)
151 g_io_channel_shutdown(channel, TRUE, NULL);
152 g_io_channel_unref(channel);