On Sunday 28 March 2010 22:27, Souf Oued wrote:
> 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.
looks like it has incompatible interface. Manpage I found says:
rfkill [options] command
OPTIONS
--version
Show the version of rfkill.
COMMANDS
help Show rfkill's built-in help text.
event Listen for rfkill events and display them on stdout.
list [type]
List the current state of all available rfkill-using devices, or
just all of the given type.
block index|type
Disable the device corresponding to the given index. type is
one of "all", "wifi", "wlan", "bluetooth", "uwb", "ultrawide-
band", "wimax", "wwan", "gps" or "fm".
unblock index|type
Enable the device corresponding to the given index. If the
device is hard-blocked, e.g. via a hardware switch, it will
remain unavailable though it is now soft-unblocked.
I think we need to match upstream.
> accepted types : all, wlan(wifi), bluetooth, uwb(ultrawideband), wimax,
> wwan, gps, fm
+int rfkill_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
+int rfkill_main(int argc UNUSED_PARAM, char **argv)
^^^^^^^^^^^^
wrong, you do use argc.
+{
+ 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();
Simpler:
opt_complementary = "-2:?3"; /* minimum 2, maximum 3 args */
+
+ getopt32(argv, "l::b:u:", &rf_name, &rf_name, &rf_name);
use local variable ("opts = getopt32(...)") instead of option_mask32,
this way code will be smaller.
+ 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); ///vda
+ }
+ }
+
+ if (option_mask32 & OPT_l) {
+ mode = O_RDONLY;
+ }
+
+ rf_fd = device_open("/dev/rfkill", mode | O_NONBLOCK);
You can add O_NONBLOCK in previous mode = FOO assignments instead.
+ char rf_sysfs[64];
+ sprintf(rf_sysfs, "/sys/class/rfkill/rfkill%u/uevent",
event.idx);
Use rf_sysfs[sizeof("/sys/class/rfkill/rfkill%u/uevent") + sizeof(int)*3]
for correct and safer estimation of size.
+ close(rf_fd);
+
+ return EXIT_SUCCESS;
close() is superfluous, exit closes everything anyway.
--
vda
_______________________________________________
busybox mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/busybox