1 /* vi: set sw=4 ts=4: */
3 * rfkill implementation for busybox
5 * Copyright (C) 2010 Malek Degachi <malek-degachi@laposte.net>
7 * Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
10 #include <linux/rfkill.h>
13 OPT_b = (1 << 0), /* must be = 1 */
18 int rfkill_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
19 int rfkill_main(int argc UNUSED_PARAM, char **argv)
21 struct rfkill_event event;
30 /* Must have one or two params */
31 if (!argv[0] || (argv[1] && argv[2]))
34 mode = O_RDWR | O_NONBLOCK;
36 if (strcmp(argv[0], "list") == 0) {
38 mode = O_RDONLY | O_NONBLOCK;
39 } else if (strcmp(argv[0], "block") == 0 && rf_name) {
41 } else if (strcmp(argv[0], "unblock") == 0 && rf_name) {
46 rf_type = RFKILL_TYPE_ALL;
49 static const char rfkill_types[] ALIGN1 = "all\0wlan\0bluetooth\0uwb\0wimax\0wwan\0gps\0fm\0";
50 if (strcmp(rf_name, "wifi") == 0)
52 if (strcmp(rf_name, "ultrawideband") == 0)
54 rf_type = index_in_strings(rfkill_types, rf_name);
56 rf_idx = xatoi_u(rf_name);
60 rf_fd = device_open("/dev/rfkill", mode);
62 bb_perror_msg_and_die("/dev/rfkill");
65 while (full_read(rf_fd, &event, sizeof(event)) == RFKILL_EVENT_SIZE_V1) {
68 char rf_sysfs[sizeof("/sys/class/rfkill/rfkill%u/uevent") + sizeof(int)*3];
71 if (rf_type && rf_type != event.type && rf_idx < 0) {
75 if (rf_idx >= 0 && event.idx != rf_idx) {
81 sprintf(rf_sysfs, "/sys/class/rfkill/rfkill%u/uevent", event.idx);
82 parser = config_open2(rf_sysfs, fopen_for_read);
83 while (config_read(parser, tokens, 2, 2, "\n=", PARSE_NORMAL)) {
84 if (strcmp(tokens[0], "RFKILL_NAME") == 0) {
85 name = xstrdup(tokens[1]);
88 if (strcmp(tokens[0], "RFKILL_TYPE") == 0) {
89 type = xstrdup(tokens[1]);
95 printf("%u: %s: %s\n", event.idx, name, type);
96 printf("\tSoft blocked: %s\n", event.soft ? "yes" : "no");
97 printf("\tHard blocked: %s\n", event.hard ? "yes" : "no");
102 memset(&event, 0, sizeof(event));
104 event.type = rf_type;
105 event.op = RFKILL_OP_CHANGE_ALL;
110 event.op = RFKILL_OP_CHANGE;
113 /* Note: OPT_b == 1 */
114 event.soft = (rf_opt & OPT_b);
116 xwrite(rf_fd, &event, sizeof(event));