[prev in list] [next in list] [prev in thread] [next in thread]
List: busybox
Subject: [PATCH] add rfkill applet
From: Souf Oued <souf_oued () yahoo ! fr>
Date: 2010-03-28 20:27:02
Message-ID: 4BAFBB96.9020004 () yahoo ! fr
[Download RAW message or body]
Hi,
this patch adds new applet: rfkill
usage:
rfkill [-l|-b|-u]
rfkill -l : list all wireless devices.
rfkill -l wlan : list all wlan devices, we can use wifi as alias.
rfkill -l 1 : list device corresponding to the given index.
rfkill -b|-u bluetooth : block/unblock all bluetooth devices.
rfkill -b|-u 0 : block/unblock device corresponding to the given index.
accepted types : all, wlan(wifi), bluetooth, uwb(ultrawideband), wimax,
wwan, gps, fm
scripts/bloat-o-meter busybox_unstripped ../comp/busybox_unstripped
function old new delta
rfkill_main - 646 +646
.rodata 48042 48395 +353
packed_usage 12026 12168 +142
static.rfkill_types - 42 +42
applet_names 1083 1090 +7
applet_main 664 668 +4
applet_nameofs 332 334 +2
applet_install_loc 83 84 +1
------------------------------------------------------------------------------
(add/remove: 3/0 grow/shrink: 6/0 up/down: 1197/0) Total: 1197 bytes
Best regards
["rfkill.patch" (text/x-patch)]
diff -urpN busybox.orig/include/applets.h busybox/include/applets.h
--- busybox.orig/include/applets.h 2010-03-28 00:30:35.000000000 +0100
+++ busybox/include/applets.h 2010-03-28 21:56:52.308493245 +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-03-28 00:30:35.000000000 +0100
+++ busybox/include/usage.h 2010-03-28 21:57:43.918742690 +0200
@@ -3726,6 +3726,18 @@
"\n for customizable files, or the user section," \
"\n if it has changed" \
+#define rfkill_trivial_usage \
+ "[-l|-b|-u]"
+#define rfkill_full_usage "\n\n" \
+ "Enable and disable wireless devices\n" \
+ "\nOptions:" \
+ "\n -l List the current state of all rfkill-using devices" \
+ "\n -b <index|type> Disable the device corresponding to the given index" \
+ "\n -u <index|type> Enable the device corresponding to the given index" \
+ "\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-03-28 00:30:35.000000000 +0100
+++ busybox/miscutils/Config.in 2010-03-28 21:55:48.563492748 +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 -l : list all wireless devices
+ rfkill -l bluetooth : list all bluetooth devices
+ rfkill -l 1 : list device corresponding to the given index
+ rfkill -[b|u] 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-03-28 00:30:35.000000000 +0100
+++ busybox/miscutils/Kbuild 2010-03-28 21:54:45.909492420 +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-03-28 21:50:28.000000000 +0200
@@ -0,0 +1,116 @@
+/* vi: set sw=4 ts=4: */
+/*
+* rfkill implementation for busybox
+*
+* Copyright (C) 2010 Malek Degachi <malek-degachi@laposte.net>
+*
+* 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 UNUSED_PARAM, 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;
+ int rf_type = RFKILL_TYPE_ALL;
+ int rf_idx = -1;
+
+ if (argc < 2 || argc > 3)
+ bb_show_usage();
+
+ getopt32(argv, "l::b:u:", &rf_name, &rf_name, &rf_name);
+ argv += optind;
+
+ if (!rf_name)
+ rf_name = *argv;
+
+ if (rf_name) {
+ 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 (option_mask32 & OPT_l) {
+ mode = O_RDONLY;
+ }
+
+ rf_fd = device_open("/dev/rfkill", mode | O_NONBLOCK);
+ if (rf_fd < 0)
+ bb_perror_msg_and_die("/dev/rfkill");
+
+ if (option_mask32 & OPT_l) {
+ parser_t *parser;
+ char *tokens[2];
+ while (full_read(rf_fd, &event, sizeof(event)) == RFKILL_EVENT_SIZE_V1) {
+ char rf_sysfs[64];
+ 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 (option_mask32 & OPT_b)
+ event.soft = 1;
+ else
+ event.soft = 0;
+
+ xwrite(rf_fd, &event, sizeof(event));
+
+ }
+ close(rf_fd);
+
+ return EXIT_SUCCESS;
+}
_______________________________________________
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic