aboutsummaryrefslogtreecommitdiffstats
path: root/ubuntu/omnibook/wireless.c
blob: 71b0c41b37a0971464433d28279bbfdb88b0ea35 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/*
 * wireless.c Wifi feature
 * 
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation; either version 2, or (at your option) any
 * later version.
 * 
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * General Public License for more details.
 *
 * Written by Mathieu Bérard <mathieu.berard@crans.org>, 2006
 *
 */

#include "omnibook.h"
#include "hardware.h"

static int omnibook_wifi_read(char *buffer, struct omnibook_operation *io_op)
{
	int len = 0;
	int retval;
	unsigned int state;

	if ((retval = backend_aerial_get(io_op, &state)))
		return retval;

	len +=
	    sprintf(buffer + len, "Wifi adapter is %s", (state & WIFI_EX) ? "present" : "absent");
	if (state & WIFI_EX)
		len +=
		    sprintf(buffer + len, " and %s", (state & WIFI_STA) ? "enabled" : "disabled");
	len += sprintf(buffer + len, ".\n");
	len +=
	    sprintf(buffer + len, "Wifi Kill switch is %s.\n", (state & KILLSWITCH) ? "on" : "off");

	return len;

}

static int omnibook_wifi_write(char *buffer, struct omnibook_operation *io_op)
{
	int retval = 0;
	unsigned int state;

	if(mutex_lock_interruptible(&io_op->backend->mutex))
		return -ERESTARTSYS;	

	if ((retval = __backend_aerial_get(io_op, &state)))
		goto out;

	if (*buffer == '0')
		state &= ~WIFI_STA;
	else if (*buffer == '1')
		state |= WIFI_STA;
	else {
		retval = -EINVAL;
		goto out;
	}

	if ((retval = __backend_aerial_set(io_op, state)))
		return retval;

	out:		
	mutex_unlock(&io_op->backend->mutex);
	return retval;
}

static struct omnibook_feature wifi_driver;

static int __init omnibook_wifi_init(struct omnibook_operation *io_op)
{
	int retval = 0;
	unsigned int state;

/*
 *  Refuse enabling/disabling a non-existent device
 */

	if ((retval = backend_aerial_get(io_op, &state)))
		return retval;

	if (!(state & WIFI_EX))
		wifi_driver.write = NULL;

	return retval;
}

static struct omnibook_tbl wireless_table[] __initdata = {
	{TSM70 | TSX205, {ACPI,}},	/* stubs to select backend */
	{TSM40, {SMI,}},		/* stubs to select backend */
	{0,}
};

static struct omnibook_feature __declared_feature wifi_driver = {
	.name = "wifi",
	.enabled = 1,
	.read = omnibook_wifi_read,
	.write = omnibook_wifi_write,
	.init = omnibook_wifi_init,
	.ectypes = TSM70 | TSM40 | TSX205,
	.tbl = wireless_table,
};

module_param_named(wifi, wifi_driver.enabled, int, S_IRUGO);
MODULE_PARM_DESC(wifi, "Use 0 to disable, 1 to enable Wifi adapter control");