Search Linux Wireless

virtual rfkill button

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Just so I don't lose the code again ...

johannes

#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
#include <linux/uinput.h>

int main(int argc, char **argv)
{
	struct uinput_user_dev dev;
	struct input_event ev;
	int fd, ret;

	fd = open("/dev/input/uinput", O_WRONLY);
	if (fd < 0) {
		perror("open");
		if (errno == ENOENT)
			fprintf(stderr, "Try to \"modprobe uinput\".\n");
		return 1;
	}

	/* set up virtual device */
	memset(&dev, 0, sizeof(dev));
	strcpy(dev.name, "virt-rfkill");

	ioctl(fd, UI_SET_EVBIT, EV_KEY);
	ioctl(fd, UI_SET_KEYBIT, KEY_WLAN);

	ret = write(fd, &dev, sizeof(dev));
	if (ret != sizeof(dev)) {
		perror("write setup");
		return 1;
	}

	/* register device */
	ret = ioctl(fd, UI_DEV_CREATE);
	if (ret) {
		perror("create");
		return 1;
	}

	/* write event */
	memset(&ev, 0, sizeof(ev));
	ev.type = EV_KEY;
	ev.code = KEY_WLAN;
	ret = write(fd, &ev, sizeof(ev));
	if (ret != sizeof(ev)) {
		perror("write event");
		return 1;
	}

	return 0;
}


--
To unsubscribe from this list: send the line "unsubscribe linux-wireless" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Host AP]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [Linux Kernel]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Samba]     [Device Mapper]
  Powered by Linux