diff options
author | Souf Oued <souf_oued@yahoo.fr> | 2010-05-02 18:45:02 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2010-05-02 18:45:02 +0200 |
commit | 43afd75ea8de1c891c3c0a520cbb117e3f1ad49e (patch) | |
tree | 4e72a22fa71c0615f464f91e34bb0c5a10bf76ba | |
parent | fde3fb3009765b273d4d717a7e4609ff7f9461ae (diff) | |
download | busybox-w32-43afd75ea8de1c891c3c0a520cbb117e3f1ad49e.tar.gz busybox-w32-43afd75ea8de1c891c3c0a520cbb117e3f1ad49e.tar.bz2 busybox-w32-43afd75ea8de1c891c3c0a520cbb117e3f1ad49e.zip |
rfkill: new applet
function old new delta
rfkill_main - 683 +683
packed_usage 26824 26966 +142
static.rfkill_types - 42 +42
applet_names 2216 2223 +7
applet_main 1300 1304 +4
applet_nameofs 650 652 +2
Signed-off-by: Souf Oued <souf_oued@yahoo.fr>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | include/applets.h | 1 | ||||
-rw-r--r-- | include/usage.h | 12 | ||||
-rw-r--r-- | miscutils/Config.in | 11 | ||||
-rw-r--r-- | miscutils/Kbuild | 1 | ||||
-rw-r--r-- | miscutils/rfkill.c | 120 |
5 files changed, 145 insertions, 0 deletions
diff --git a/include/applets.h b/include/applets.h index 83c1792ac..ef5dd781d 100644 --- a/include/applets.h +++ b/include/applets.h | |||
@@ -321,6 +321,7 @@ IF_RENICE(APPLET(renice, _BB_DIR_USR_BIN, _BB_SUID_DROP)) | |||
321 | IF_RESET(APPLET(reset, _BB_DIR_USR_BIN, _BB_SUID_DROP)) | 321 | IF_RESET(APPLET(reset, _BB_DIR_USR_BIN, _BB_SUID_DROP)) |
322 | IF_RESIZE(APPLET(resize, _BB_DIR_USR_BIN, _BB_SUID_DROP)) | 322 | IF_RESIZE(APPLET(resize, _BB_DIR_USR_BIN, _BB_SUID_DROP)) |
323 | IF_RESTORECON(APPLET_ODDNAME(restorecon, setfiles, _BB_DIR_SBIN, _BB_SUID_DROP, restorecon)) | 323 | IF_RESTORECON(APPLET_ODDNAME(restorecon, setfiles, _BB_DIR_SBIN, _BB_SUID_DROP, restorecon)) |
324 | IF_RFKILL(APPLET(rfkill, _BB_DIR_USR_SBIN, _BB_SUID_DROP)) | ||
324 | IF_RM(APPLET_NOFORK(rm, rm, _BB_DIR_BIN, _BB_SUID_DROP, rm)) | 325 | IF_RM(APPLET_NOFORK(rm, rm, _BB_DIR_BIN, _BB_SUID_DROP, rm)) |
325 | IF_RMDIR(APPLET_NOFORK(rmdir, rmdir, _BB_DIR_BIN, _BB_SUID_DROP, rmdir)) | 326 | IF_RMDIR(APPLET_NOFORK(rmdir, rmdir, _BB_DIR_BIN, _BB_SUID_DROP, rmdir)) |
326 | IF_RMMOD(APPLET(rmmod, _BB_DIR_SBIN, _BB_SUID_DROP)) | 327 | IF_RMMOD(APPLET(rmmod, _BB_DIR_SBIN, _BB_SUID_DROP)) |
diff --git a/include/usage.h b/include/usage.h index 38594811e..2c2a90d16 100644 --- a/include/usage.h +++ b/include/usage.h | |||
@@ -3738,6 +3738,18 @@ | |||
3738 | "\n for customizable files, or the user section," \ | 3738 | "\n for customizable files, or the user section," \ |
3739 | "\n if it has changed" \ | 3739 | "\n if it has changed" \ |
3740 | 3740 | ||
3741 | #define rfkill_trivial_usage \ | ||
3742 | "COMMAND [INDEX|TYPE]" | ||
3743 | #define rfkill_full_usage "\n\n" \ | ||
3744 | "Enable/disable wireless devices\n" \ | ||
3745 | "\nCommands:" \ | ||
3746 | "\n list [INDEX|TYPE] List current state" \ | ||
3747 | "\n block INDEX|TYPE Disable device" \ | ||
3748 | "\n unblock INDEX|TYPE Enable device" \ | ||
3749 | "\n" \ | ||
3750 | "\n TYPE: all, wlan(wifi), bluetooth, uwb(ultrawideband)," \ | ||
3751 | "\n wimax, wwan, gps, fm" \ | ||
3752 | |||
3741 | #define rm_trivial_usage \ | 3753 | #define rm_trivial_usage \ |
3742 | "[OPTIONS] FILE..." | 3754 | "[OPTIONS] FILE..." |
3743 | #define rm_full_usage "\n\n" \ | 3755 | #define rm_full_usage "\n\n" \ |
diff --git a/miscutils/Config.in b/miscutils/Config.in index 0469b6399..7a69dd10f 100644 --- a/miscutils/Config.in +++ b/miscutils/Config.in | |||
@@ -545,6 +545,17 @@ config READAHEAD | |||
545 | As readahead(2) blocks until each file has been read, it is best to | 545 | As readahead(2) blocks until each file has been read, it is best to |
546 | run this applet as a background job. | 546 | run this applet as a background job. |
547 | 547 | ||
548 | config RFKILL | ||
549 | bool "rfkill" | ||
550 | default n | ||
551 | help | ||
552 | Enable/disable wireless devices. | ||
553 | |||
554 | rfkill list : list all wireless devices | ||
555 | rfkill list bluetooth : list all bluetooth devices | ||
556 | rfkill list 1 : list device corresponding to the given index | ||
557 | rfkill block|unblock wlan : block/unblock all wlan(wifi) devices | ||
558 | |||
548 | config RUNLEVEL | 559 | config RUNLEVEL |
549 | bool "runlevel" | 560 | bool "runlevel" |
550 | default n | 561 | default n |
diff --git a/miscutils/Kbuild b/miscutils/Kbuild index bbfa93dc7..3c8ce42ba 100644 --- a/miscutils/Kbuild +++ b/miscutils/Kbuild | |||
@@ -34,6 +34,7 @@ lib-$(CONFIG_MOUNTPOINT) += mountpoint.o | |||
34 | lib-$(CONFIG_MT) += mt.o | 34 | lib-$(CONFIG_MT) += mt.o |
35 | lib-$(CONFIG_RAIDAUTORUN) += raidautorun.o | 35 | lib-$(CONFIG_RAIDAUTORUN) += raidautorun.o |
36 | lib-$(CONFIG_READAHEAD) += readahead.o | 36 | lib-$(CONFIG_READAHEAD) += readahead.o |
37 | lib-$(CONFIG_RFKILL) += rfkill.o | ||
37 | lib-$(CONFIG_RUNLEVEL) += runlevel.o | 38 | lib-$(CONFIG_RUNLEVEL) += runlevel.o |
38 | lib-$(CONFIG_RX) += rx.o | 39 | lib-$(CONFIG_RX) += rx.o |
39 | lib-$(CONFIG_SETSID) += setsid.o | 40 | lib-$(CONFIG_SETSID) += setsid.o |
diff --git a/miscutils/rfkill.c b/miscutils/rfkill.c new file mode 100644 index 000000000..0f5817b76 --- /dev/null +++ b/miscutils/rfkill.c | |||
@@ -0,0 +1,120 @@ | |||
1 | /* vi: set sw=4 ts=4: */ | ||
2 | /* | ||
3 | * rfkill implementation for busybox | ||
4 | * | ||
5 | * Copyright (C) 2010 Malek Degachi <malek-degachi@laposte.net> | ||
6 | * | ||
7 | * Licensed under the GPL v2 or later, see the file LICENSE in this tarball. | ||
8 | */ | ||
9 | #include "libbb.h" | ||
10 | #include <linux/rfkill.h> | ||
11 | |||
12 | enum { | ||
13 | OPT_b = (1 << 0), /* must be = 1 */ | ||
14 | OPT_u = (1 << 1), | ||
15 | OPT_l = (1 << 2), | ||
16 | }; | ||
17 | |||
18 | int rfkill_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | ||
19 | int rfkill_main(int argc UNUSED_PARAM, char **argv) | ||
20 | { | ||
21 | struct rfkill_event event; | ||
22 | const char *rf_name; | ||
23 | int rf_fd; | ||
24 | int mode; | ||
25 | int rf_type; | ||
26 | int rf_idx; | ||
27 | unsigned rf_opt = 0; | ||
28 | |||
29 | argv++; | ||
30 | /* Must have one or two params */ | ||
31 | if (!argv[0] || (argv[1] && argv[2])) | ||
32 | bb_show_usage(); | ||
33 | |||
34 | mode = O_RDWR | O_NONBLOCK; | ||
35 | rf_name = argv[1]; | ||
36 | if (strcmp(argv[0], "list") == 0) { | ||
37 | rf_opt |= OPT_l; | ||
38 | mode = O_RDONLY | O_NONBLOCK; | ||
39 | } else if (strcmp(argv[0], "block") == 0 && rf_name) { | ||
40 | rf_opt |= OPT_b; | ||
41 | } else if (strcmp(argv[0], "unblock") == 0 && rf_name) { | ||
42 | rf_opt |= OPT_u; | ||
43 | } else | ||
44 | bb_show_usage(); | ||
45 | |||
46 | rf_type = RFKILL_TYPE_ALL; | ||
47 | rf_idx = -1; | ||
48 | if (rf_name) { | ||
49 | static const char rfkill_types[] ALIGN1 = "all\0wlan\0bluetooth\0uwb\0wimax\0wwan\0gps\0fm\0"; | ||
50 | if (strcmp(rf_name, "wifi") == 0) | ||
51 | rf_name = "wlan"; | ||
52 | if (strcmp(rf_name, "ultrawideband") == 0) | ||
53 | rf_name = "uwb"; | ||
54 | rf_type = index_in_strings(rfkill_types, rf_name); | ||
55 | if (rf_type < 0) { | ||
56 | rf_idx = xatoi_u(rf_name); | ||
57 | } | ||
58 | } | ||
59 | |||
60 | rf_fd = device_open("/dev/rfkill", mode); | ||
61 | if (rf_fd < 0) | ||
62 | bb_perror_msg_and_die("/dev/rfkill"); | ||
63 | |||
64 | if (rf_opt & OPT_l) { | ||
65 | while (full_read(rf_fd, &event, sizeof(event)) == RFKILL_EVENT_SIZE_V1) { | ||
66 | parser_t *parser; | ||
67 | char *tokens[2]; | ||
68 | char rf_sysfs[sizeof("/sys/class/rfkill/rfkill%u/uevent") + sizeof(int)*3]; | ||
69 | char *name, *type; | ||
70 | |||
71 | if (rf_type && rf_type != event.type && rf_idx < 0) { | ||
72 | continue; | ||
73 | } | ||
74 | |||
75 | if (rf_idx >= 0 && event.idx != rf_idx) { | ||
76 | continue; | ||
77 | } | ||
78 | |||
79 | name = NULL; | ||
80 | type = NULL; | ||
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]); | ||
86 | continue; | ||
87 | } | ||
88 | if (strcmp(tokens[0], "RFKILL_TYPE") == 0) { | ||
89 | type = xstrdup(tokens[1]); | ||
90 | continue; | ||
91 | } | ||
92 | } | ||
93 | config_close(parser); | ||
94 | |||
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"); | ||
98 | free(name); | ||
99 | free(type); | ||
100 | } | ||
101 | } else { | ||
102 | memset(&event, 0, sizeof(event)); | ||
103 | if (rf_type >= 0) { | ||
104 | event.type = rf_type; | ||
105 | event.op = RFKILL_OP_CHANGE_ALL; | ||
106 | } | ||
107 | |||
108 | if (rf_idx >= 0) { | ||
109 | event.idx = rf_idx; | ||
110 | event.op = RFKILL_OP_CHANGE; | ||
111 | } | ||
112 | |||
113 | /* Note: OPT_b == 1 */ | ||
114 | event.soft = (rf_opt & OPT_b); | ||
115 | |||
116 | xwrite(rf_fd, &event, sizeof(event)); | ||
117 | } | ||
118 | |||
119 | return EXIT_SUCCESS; | ||
120 | } | ||