public inbox for linux-wireless@vger.kernel.org
 help / color / mirror / Atom feed
* virtual rfkill button
@ 2009-05-05  0:12 Johannes Berg
  2009-05-05 21:48 ` Johannes Berg
  0 siblings, 1 reply; 2+ messages in thread
From: Johannes Berg @ 2009-05-05  0:12 UTC (permalink / raw)
  To: linux-wireless

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;
}



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2009-05-05 21:49 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-05-05  0:12 virtual rfkill button Johannes Berg
2009-05-05 21:48 ` Johannes Berg

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox