public inbox for linux-wireless@vger.kernel.org
 help / color / mirror / Atom feed
From: Johannes Berg <johannes@sipsolutions.net>
To: linux-wireless@vger.kernel.org
Subject: virtual rfkill button
Date: Tue, 05 May 2009 02:12:33 +0200	[thread overview]
Message-ID: <1241482353.8683.111.camel@johannes.local> (raw)

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



             reply	other threads:[~2009-05-05  0:13 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-05-05  0:12 Johannes Berg [this message]
2009-05-05 21:48 ` virtual rfkill button Johannes Berg

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1241482353.8683.111.camel@johannes.local \
    --to=johannes@sipsolutions.net \
    --cc=linux-wireless@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox