From: Johannes Berg <johannes@sipsolutions.net>
To: linux-wireless@vger.kernel.org
Subject: Re: virtual rfkill button
Date: Tue, 05 May 2009 23:48:58 +0200 [thread overview]
Message-ID: <1241560138.4969.4.camel@johannes.local> (raw)
In-Reply-To: <1241482353.8683.111.camel@johannes.local>
[-- Attachment #1.1: Type: text/plain, Size: 271 bytes --]
That didn't work, the attached one does... Also a module to show rfkill
working (for my new API rfkill).
The Makefile for the test module is a simple:
obj-m += fake-rfkill.o
and then you do
make -f /lib/modules/$(uname -r)/build/Makefile M=$(pwd)
johannes
[-- Attachment #1.2: fake-rfkill.c --]
[-- Type: text/x-csrc, Size: 1004 bytes --]
#include <linux/rfkill.h>
#include <linux/module.h>
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Johannes Berg <johannes@sipsolutions.net>");
static struct rfkill *rfk;
static void test_poll(struct rfkill *rfkill, void *data)
{
printk(KERN_DEBUG "poll test rfkill\n");
}
static void test_query(struct rfkill *rfkill, void *data)
{
printk(KERN_DEBUG "query test rfkill\n");
}
static int test_set_block(void *data, bool blocked)
{
printk(KERN_DEBUG "set test rfkill (%s)\n",
blocked ? "blocked" : "active");
return 0;
}
static struct rfkill_ops ops = {
.poll = test_poll,
.query = test_query,
.set_block = test_set_block,
};
int mod_init(void)
{
int err;
rfk = rfkill_alloc("fake", NULL, RFKILL_TYPE_WLAN, &ops, NULL);
if (!rfk)
return -ENOMEM;
err = rfkill_register(rfk);
if (err)
rfkill_destroy(rfk);
return err;
}
module_init(mod_init);
void mod_exit(void)
{
rfkill_unregister(rfk);
rfkill_destroy(rfk);
}
module_exit(mod_exit);
[-- Attachment #1.3: virt-rfkill.c --]
[-- Type: text/x-csrc, Size: 2633 bytes --]
/*
* Copyright (c) 2009 Johannes Berg
* Copyright (c) 2009 Luis R. Rodriguez
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <fcntl.h>
#include <linux/uinput.h>
#include <unistd.h>
/*
* You will need CONFIG_INPUT_UINPUT enabled, if
* enabled as a module modprobe uinput
*/
int main(int argc, char **argv)
{
struct uinput_user_dev dev;
struct input_event ev;
int fd, ret;
/* Tells the kernel to kmalloc() a uinput device for us */
fd = open("/dev/input/uinput", O_WRONLY | O_NDELAY);
if (fd < 0) {
perror("open uinput");
if (errno == ENOENT)
fprintf(stderr, "Try \"modprobe uinput\".\n");
return 1;
}
memset(&dev, 0, sizeof(dev));
strcpy(dev.name, "virt-rfkill");
/* sets up uinput device, all we need is a name */
ret = write(fd, &dev, sizeof(dev));
if (ret != sizeof(dev)) {
perror("write setup");
return 1;
}
/* sets "EV_KEY" bit on the the uinput dev's evbit */
if (ioctl(fd, UI_SET_EVBIT, EV_KEY)) {
perror("set key event");
return 1;
}
/* sets "KEY_WLAN" bit on the the uinput dev's keybit */
if (ioctl(fd, UI_SET_KEYBIT, KEY_WLAN)) {
perror("set wlan key");
return 1;
}
/* create an input device for uinput device */
ret = ioctl(fd, UI_DEV_CREATE);
if (ret) {
perror("create input device");
return 1;
}
/*
* write events -- once a uinput device has been set up writes
* inject events which show up in the virtual input device.
*/
memset(&ev, 0, sizeof(ev));
ev.type = EV_KEY;
ev.code = KEY_WLAN;
/* button down */
ev.value = 1;
ret = write(fd, &ev, sizeof(ev));
if (ret != sizeof(ev)) {
perror("write event");
return 1;
}
/* and up again - that's a press */
ev.value = 0;
ret = write(fd, &ev, sizeof(ev));
if (ret != sizeof(ev)) {
perror("write event");
return 1;
}
return 0;
}
[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 836 bytes --]
prev parent reply other threads:[~2009-05-05 21:49 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-05-05 0:12 virtual rfkill button Johannes Berg
2009-05-05 21:48 ` Johannes Berg [this message]
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=1241560138.4969.4.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