Thank you for the reply,
Ok, I corrected the 1st attempt and send a 2nd patch
diff -urpN busybox.orig/include/applets.h busybox/include/applets.h
--- busybox.orig/include/applets.h 2010-04-09 14:58:40.000000000 +0200
+++ busybox/include/applets.h 2010-04-10 13:57:39.517609079 +0200
@@ -321,6 +321,7 @@ IF_RENICE(APPLET(renice, _BB_DIR_USR_BIN
IF_RESET(APPLET(reset, _BB_DIR_USR_BIN, _BB_SUID_DROP))
IF_RESIZE(APPLET(resize, _BB_DIR_USR_BIN, _BB_SUID_DROP))
IF_RESTORECON(APPLET_ODDNAME(restorecon, setfiles, _BB_DIR_SBIN, _BB_SUID_DROP, restorecon))
+IF_RFKILL(APPLET(rfkill, _BB_DIR_USR_SBIN, _BB_SUID_DROP))
IF_RM(APPLET_NOFORK(rm, rm, _BB_DIR_BIN, _BB_SUID_DROP, rm))
IF_RMDIR(APPLET_NOFORK(rmdir, rmdir, _BB_DIR_BIN, _BB_SUID_DROP, rmdir))
IF_RMMOD(APPLET(rmmod, _BB_DIR_SBIN, _BB_SUID_DROP))
diff -urpN busybox.orig/include/usage.h busybox/include/usage.h
--- busybox.orig/include/usage.h 2010-04-09 14:58:40.000000000 +0200
+++ busybox/include/usage.h 2010-04-10 13:58:42.835503721 +0200
@@ -3741,6 +3741,18 @@
"\n for customizable files, or the user section," \
"\n if it has changed" \
+#define rfkill_trivial_usage \
+ "COMMAND [index|type]"
+#define rfkill_full_usage "\n\n" \
+ "Enable and disable wireless devices\n" \
+ "\nCommands:" \
+ "\n list [index|type] List the current state of rfkill devices" \
+ "\n block <index|type> Disable the device corresponding to the given index or type" \
+ "\n unblock <index|type> Enable the device corresponding to the given index or type" \
+ "\n" \
+ "\n accepted types : all, wlan(wifi), bluetooth, uwb(ultrawideband)," \
+ "\n wimax, wwan, gps, fm" \
+
#define rm_trivial_usage \
"[OPTIONS] FILE..."
#define rm_full_usage "\n\n" \
diff -urpN busybox.orig/miscutils/Config.in busybox/miscutils/Config.in
--- busybox.orig/miscutils/Config.in 2010-04-09 14:58:40.000000000 +0200
+++ busybox/miscutils/Config.in 2010-04-10 13:55:53.430703866 +0200
@@ -545,6 +545,17 @@ config READAHEAD
As readahead(2) blocks until each file has been read, it is best to
run this applet as a background job.
+config RFKILL
+ bool "rfkill"
+ default n
+ help
+ Enable/disable wireless devices.
+
+ rfkill list : list all wireless devices
+ rfkill list bluetooth : list all bluetooth devices
+ rfkill list 1 : list device corresponding to the given index
+ rfkill block|unblock wlan : block/unblock all wlan devices(you can use wifi instead)
+
config RUNLEVEL
bool "runlevel"
default n
diff -urpN busybox.orig/miscutils/Kbuild busybox/miscutils/Kbuild
--- busybox.orig/miscutils/Kbuild 2010-04-09 14:58:40.000000000 +0200
+++ busybox/miscutils/Kbuild 2010-04-10 13:56:28.499483948 +0200
@@ -34,6 +34,7 @@ lib-$(CONFIG_MOUNTPOINT) += mountpoint.
lib-$(CONFIG_MT) += mt.o
lib-$(CONFIG_RAIDAUTORUN) += raidautorun.o
lib-$(CONFIG_READAHEAD) += readahead.o
+lib-$(CONFIG_RFKILL) += rfkill.o
lib-$(CONFIG_RUNLEVEL) += runlevel.o
lib-$(CONFIG_RX) += rx.o
lib-$(CONFIG_SETSID) += setsid.o
diff -urpN busybox.orig/miscutils/rfkill.c busybox/miscutils/rfkill.c
--- busybox.orig/miscutils/rfkill.c 1970-01-01 01:00:00.000000000 +0100
+++ busybox/miscutils/rfkill.c 2010-04-10 13:46:29.000000000 +0200
@@ -0,0 +1,124 @@
+/* vi: set sw=4 ts=4: */
+/*
+* rfkill implementation for busybox
+*
+* Copyright (C) 2010 Malek Degachi <[email protected]>
+*
+* Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
+*/
+#include "libbb.h"
+#include <linux/rfkill.h>
+
+enum {
+ OPT_l = (1 << 0),
+ OPT_b = (1 << 1),
+ OPT_u = (1 << 2),
+};
+
+int rfkill_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
+int rfkill_main(int argc, char **argv)
+{
+ struct rfkill_event event;
+ static const char rfkill_types[] ALIGN1 = "all\0wlan\0bluetooth\0uwb\0wimax\0wwan\0gps\0fm\0";
+ const char *rf_name = NULL;
+ int rf_fd;
+ int mode = O_RDWR | O_NONBLOCK;
+ int rf_type = RFKILL_TYPE_ALL;
+ int rf_idx = -1;
+ smalluint rf_opt = 0;
+
+ if (argc < 2 || argc > 3)
+ bb_show_usage();
+
+ argc--;
+ argv++;
+
+ if (strcmp(*argv, "list") == 0) {
+ rf_opt |= OPT_l;
+ } else if (strcmp(*argv, "block") == 0 && argc > 1) {
+ rf_opt |= OPT_b;
+ } else if (strcmp(*argv, "unblock") == 0 && argc > 1) {
+ rf_opt |= OPT_u;
+ } else
+ bb_show_usage();
+
+ argv++;
+
+ if (*argv) {
+ rf_name = *argv;
+ if (strcmp(rf_name, "wifi") == 0)
+ rf_name = "wlan";
+ if (strcmp(rf_name, "ultrawideband") == 0)
+ rf_name = "uwb";
+ rf_type = index_in_strings(rfkill_types, rf_name);
+ if (rf_type < 0) {
+ rf_idx = xstrtou(rf_name, 10);
+ }
+ }
+
+ if (rf_opt & OPT_l) {
+ mode = O_RDONLY | O_NONBLOCK;
+ }
+
+ rf_fd = device_open("/dev/rfkill", mode);
+ if (rf_fd < 0)
+ bb_perror_msg_and_die("/dev/rfkill");
+
+ if (rf_opt & OPT_l) {
+ parser_t *parser;
+ char *tokens[2];
+ while (full_read(rf_fd, &event, sizeof(event)) == RFKILL_EVENT_SIZE_V1) {
+ char rf_sysfs[sizeof("/sys/class/rfkill/rfkill%u/uevent") + sizeof(int)*3];
+ char *name = NULL, *type = NULL;
+
+ if (rf_type && rf_type != event.type && rf_idx < 0) {
+ continue;
+ }
+
+ if (rf_idx >= 0 && event.idx != rf_idx) {
+ continue;
+ }
+
+ sprintf(rf_sysfs, "/sys/class/rfkill/rfkill%u/uevent", event.idx);
+ parser = config_open2(rf_sysfs, fopen_for_read);
+
+ while (config_read(parser, tokens, 2, 2, "\n=", PARSE_NORMAL)) {
+ if (strcmp(tokens[0], "RFKILL_NAME") == 0) {
+ name = xstrdup(tokens[1]);
+ continue;
+ }
+ if (strcmp(tokens[0], "RFKILL_TYPE") == 0) {
+ type = xstrdup(tokens[1]);
+ continue;
+ }
+ }
+ config_close(parser);
+
+ printf("%u: %s: %s\n", event.idx, name, type);
+ printf("\tSoft blocked: %s\n", event.soft ? "yes" : "no");
+ printf("\tHard blocked: %s\n", event.hard ? "yes" : "no");
+ free(name);
+ free(type);
+ }
+ } else {
+ memset(&event, 0, sizeof(event));
+ if (rf_type >=0) {
+ event.type = rf_type;
+ event.op = RFKILL_OP_CHANGE_ALL;
+ }
+
+ if (rf_idx >= 0) {
+ event.idx = rf_idx;
+ event.op = RFKILL_OP_CHANGE;
+ }
+
+ if (rf_opt & OPT_b)
+ event.soft = 1;
+ else
+ event.soft = 0;
+
+ xwrite(rf_fd, &event, sizeof(event));
+ }
+
+ return EXIT_SUCCESS;
+}
_______________________________________________
busybox mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/busybox