aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorKalle Valo <kalle.valo@nokia.com>2010-02-18 06:25:53 -0500
committerJohn W. Linville <linville@tuxdriver.com>2010-02-19 15:52:47 -0500
commitc8c90873520ef4c201cfd03b4892ca8bbf551e2e (patch)
treeea61e48edb5abab0744a27ba11afb8a46e85b20d /drivers
parent1937e742639c03a6fe77239c3003ce9602302117 (diff)
wl1271: add testmode support
Testmode will be used to send PLT (Production Line Testing) commands from user space. Signed-off-by: Kalle Valo <kalle.valo@nokia.com> Reviewed-by: Juuso Oikarinen <juuso.oikarinen@nokia.com> Signed-off-by: Juuso Oikarinen <juuso.oikarinen@nokia.com> Signed-off-by: John W. Linville <linville@tuxdriver.com>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/net/wireless/wl12xx/Makefile1
-rw-r--r--drivers/net/wireless/wl12xx/wl1271.h2
-rw-r--r--drivers/net/wireless/wl12xx/wl1271_main.c2
-rw-r--r--drivers/net/wireless/wl12xx/wl1271_testmode.c283
-rw-r--r--drivers/net/wireless/wl12xx/wl1271_testmode.h31
5 files changed, 318 insertions, 1 deletions
diff --git a/drivers/net/wireless/wl12xx/Makefile b/drivers/net/wireless/wl12xx/Makefile
index 62e37ad01cc0..d089b5d6a513 100644
--- a/drivers/net/wireless/wl12xx/Makefile
+++ b/drivers/net/wireless/wl12xx/Makefile
@@ -11,4 +11,5 @@ wl1271-objs = wl1271_main.o wl1271_spi.o wl1271_cmd.o \
11 wl1271_event.o wl1271_tx.o wl1271_rx.o \ 11 wl1271_event.o wl1271_tx.o wl1271_rx.o \
12 wl1271_ps.o wl1271_acx.o wl1271_boot.o \ 12 wl1271_ps.o wl1271_acx.o wl1271_boot.o \
13 wl1271_init.o wl1271_debugfs.o 13 wl1271_init.o wl1271_debugfs.o
14wl1271-$(CONFIG_NL80211_TESTMODE) += wl1271_testmode.o
14obj-$(CONFIG_WL1271) += wl1271.o 15obj-$(CONFIG_WL1271) += wl1271.o
diff --git a/drivers/net/wireless/wl12xx/wl1271.h b/drivers/net/wireless/wl12xx/wl1271.h
index b3a3402593dd..97ea5096bc8c 100644
--- a/drivers/net/wireless/wl12xx/wl1271.h
+++ b/drivers/net/wireless/wl12xx/wl1271.h
@@ -43,7 +43,7 @@ enum {
43 DEBUG_SPI = BIT(1), 43 DEBUG_SPI = BIT(1),
44 DEBUG_BOOT = BIT(2), 44 DEBUG_BOOT = BIT(2),
45 DEBUG_MAILBOX = BIT(3), 45 DEBUG_MAILBOX = BIT(3),
46 DEBUG_NETLINK = BIT(4), 46 DEBUG_TESTMODE = BIT(4),
47 DEBUG_EVENT = BIT(5), 47 DEBUG_EVENT = BIT(5),
48 DEBUG_TX = BIT(6), 48 DEBUG_TX = BIT(6),
49 DEBUG_RX = BIT(7), 49 DEBUG_RX = BIT(7),
diff --git a/drivers/net/wireless/wl12xx/wl1271_main.c b/drivers/net/wireless/wl12xx/wl1271_main.c
index fb1e6a8088d8..aa8f79c4c98a 100644
--- a/drivers/net/wireless/wl12xx/wl1271_main.c
+++ b/drivers/net/wireless/wl12xx/wl1271_main.c
@@ -46,6 +46,7 @@
46#include "wl1271_debugfs.h" 46#include "wl1271_debugfs.h"
47#include "wl1271_cmd.h" 47#include "wl1271_cmd.h"
48#include "wl1271_boot.h" 48#include "wl1271_boot.h"
49#include "wl1271_testmode.h"
49 50
50#define WL1271_BOOT_RETRIES 3 51#define WL1271_BOOT_RETRIES 3
51 52
@@ -1955,6 +1956,7 @@ static const struct ieee80211_ops wl1271_ops = {
1955 .bss_info_changed = wl1271_op_bss_info_changed, 1956 .bss_info_changed = wl1271_op_bss_info_changed,
1956 .set_rts_threshold = wl1271_op_set_rts_threshold, 1957 .set_rts_threshold = wl1271_op_set_rts_threshold,
1957 .conf_tx = wl1271_op_conf_tx, 1958 .conf_tx = wl1271_op_conf_tx,
1959 CFG80211_TESTMODE_CMD(wl1271_tm_cmd)
1958}; 1960};
1959 1961
1960static int wl1271_register_hw(struct wl1271 *wl) 1962static int wl1271_register_hw(struct wl1271 *wl)
diff --git a/drivers/net/wireless/wl12xx/wl1271_testmode.c b/drivers/net/wireless/wl12xx/wl1271_testmode.c
new file mode 100644
index 000000000000..3919102e942e
--- /dev/null
+++ b/drivers/net/wireless/wl12xx/wl1271_testmode.c
@@ -0,0 +1,283 @@
1/*
2 * This file is part of wl1271
3 *
4 * Copyright (C) 2010 Nokia Corporation
5 *
6 * Contact: Luciano Coelho <luciano.coelho@nokia.com>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * version 2 as published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA
21 *
22 */
23#include "wl1271_testmode.h"
24
25#include <net/genetlink.h>
26
27#include "wl1271.h"
28#include "wl1271_spi.h"
29#include "wl1271_acx.h"
30
31#define WL1271_TM_MAX_DATA_LENGTH 1024
32
33enum wl1271_tm_commands {
34 WL1271_TM_CMD_UNSPEC,
35 WL1271_TM_CMD_TEST,
36 WL1271_TM_CMD_INTERROGATE,
37 WL1271_TM_CMD_CONFIGURE,
38 WL1271_TM_CMD_NVS_PUSH,
39 WL1271_TM_CMD_SET_PLT_MODE,
40
41 __WL1271_TM_CMD_AFTER_LAST
42};
43#define WL1271_TM_CMD_MAX (__WL1271_TM_CMD_AFTER_LAST - 1)
44
45enum wl1271_tm_attrs {
46 WL1271_TM_ATTR_UNSPEC,
47 WL1271_TM_ATTR_CMD_ID,
48 WL1271_TM_ATTR_ANSWER,
49 WL1271_TM_ATTR_DATA,
50 WL1271_TM_ATTR_IE_ID,
51 WL1271_TM_ATTR_PLT_MODE,
52
53 __WL1271_TM_ATTR_AFTER_LAST
54};
55#define WL1271_TM_ATTR_MAX (__WL1271_TM_ATTR_AFTER_LAST - 1)
56
57static struct nla_policy wl1271_tm_policy[WL1271_TM_ATTR_MAX + 1] = {
58 [WL1271_TM_ATTR_CMD_ID] = { .type = NLA_U32 },
59 [WL1271_TM_ATTR_ANSWER] = { .type = NLA_U8 },
60 [WL1271_TM_ATTR_DATA] = { .type = NLA_BINARY,
61 .len = WL1271_TM_MAX_DATA_LENGTH },
62 [WL1271_TM_ATTR_IE_ID] = { .type = NLA_U32 },
63 [WL1271_TM_ATTR_PLT_MODE] = { .type = NLA_U32 },
64};
65
66
67static int wl1271_tm_cmd_test(struct wl1271 *wl, struct nlattr *tb[])
68{
69 int buf_len, ret, len;
70 struct sk_buff *skb;
71 void *buf;
72 u8 answer = 0;
73
74 wl1271_debug(DEBUG_TESTMODE, "testmode cmd test");
75
76 if (!tb[WL1271_TM_ATTR_DATA])
77 return -EINVAL;
78
79 buf = nla_data(tb[WL1271_TM_ATTR_DATA]);
80 buf_len = nla_len(tb[WL1271_TM_ATTR_DATA]);
81
82 if (tb[WL1271_TM_ATTR_ANSWER])
83 answer = nla_get_u8(tb[WL1271_TM_ATTR_ANSWER]);
84
85 if (buf_len > sizeof(struct wl1271_command))
86 return -EMSGSIZE;
87
88 mutex_lock(&wl->mutex);
89 ret = wl1271_cmd_test(wl, buf, buf_len, answer);
90 mutex_unlock(&wl->mutex);
91
92 if (ret < 0) {
93 wl1271_warning("testmode cmd test failed: %d", ret);
94 return ret;
95 }
96
97 if (answer) {
98 len = nla_total_size(buf_len);
99 skb = cfg80211_testmode_alloc_reply_skb(wl->hw->wiphy, len);
100 if (!skb)
101 return -ENOMEM;
102
103 NLA_PUT(skb, WL1271_TM_ATTR_DATA, buf_len, buf);
104 ret = cfg80211_testmode_reply(skb);
105 if (ret < 0)
106 return ret;
107 }
108
109 return 0;
110
111nla_put_failure:
112 kfree_skb(skb);
113 return -EMSGSIZE;
114}
115
116static int wl1271_tm_cmd_interrogate(struct wl1271 *wl, struct nlattr *tb[])
117{
118 int ret;
119 struct wl1271_command *cmd;
120 struct sk_buff *skb;
121 u8 ie_id;
122
123 wl1271_debug(DEBUG_TESTMODE, "testmode cmd interrogate");
124
125 if (!tb[WL1271_TM_ATTR_IE_ID])
126 return -EINVAL;
127
128 ie_id = nla_get_u8(tb[WL1271_TM_ATTR_IE_ID]);
129
130 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
131 if (!cmd)
132 return -ENOMEM;
133
134 mutex_lock(&wl->mutex);
135 ret = wl1271_cmd_interrogate(wl, ie_id, cmd, sizeof(*cmd));
136 mutex_unlock(&wl->mutex);
137
138 if (ret < 0) {
139 wl1271_warning("testmode cmd interrogate failed: %d", ret);
140 return ret;
141 }
142
143 skb = cfg80211_testmode_alloc_reply_skb(wl->hw->wiphy, sizeof(*cmd));
144 if (!skb)
145 return -ENOMEM;
146
147 NLA_PUT(skb, WL1271_TM_ATTR_DATA, sizeof(*cmd), cmd);
148
149 return 0;
150
151nla_put_failure:
152 kfree_skb(skb);
153 return -EMSGSIZE;
154}
155
156static int wl1271_tm_cmd_configure(struct wl1271 *wl, struct nlattr *tb[])
157{
158 int buf_len, ret;
159 void *buf;
160 u8 ie_id;
161
162 wl1271_debug(DEBUG_TESTMODE, "testmode cmd configure");
163
164 if (!tb[WL1271_TM_ATTR_DATA])
165 return -EINVAL;
166 if (!tb[WL1271_TM_ATTR_IE_ID])
167 return -EINVAL;
168
169 ie_id = nla_get_u8(tb[WL1271_TM_ATTR_IE_ID]);
170 buf = nla_data(tb[WL1271_TM_ATTR_DATA]);
171 buf_len = nla_len(tb[WL1271_TM_ATTR_DATA]);
172
173 if (buf_len > sizeof(struct wl1271_command))
174 return -EMSGSIZE;
175
176 mutex_lock(&wl->mutex);
177 ret = wl1271_cmd_configure(wl, ie_id, buf, buf_len);
178 mutex_unlock(&wl->mutex);
179
180 if (ret < 0) {
181 wl1271_warning("testmode cmd configure failed: %d", ret);
182 return ret;
183 }
184
185 return 0;
186}
187
188static int wl1271_tm_cmd_nvs_push(struct wl1271 *wl, struct nlattr *tb[])
189{
190 int ret = 0;
191 size_t len;
192 void *buf;
193
194 wl1271_debug(DEBUG_TESTMODE, "testmode cmd nvs push");
195
196 if (!tb[WL1271_TM_ATTR_DATA])
197 return -EINVAL;
198
199 buf = nla_data(tb[WL1271_TM_ATTR_DATA]);
200 len = nla_len(tb[WL1271_TM_ATTR_DATA]);
201
202 if (len != sizeof(struct wl1271_nvs_file)) {
203 wl1271_error("nvs size is not as expected: %zu != %zu",
204 len, sizeof(struct wl1271_nvs_file));
205 return -EMSGSIZE;
206 }
207
208 mutex_lock(&wl->mutex);
209
210 kfree(wl->nvs);
211
212 wl->nvs = kmalloc(sizeof(struct wl1271_nvs_file), GFP_KERNEL);
213 if (!wl->nvs) {
214 wl1271_error("could not allocate memory for the nvs file");
215 ret = -ENOMEM;
216 goto out;
217 }
218
219 memcpy(wl->nvs, buf, len);
220
221 wl1271_debug(DEBUG_TESTMODE, "testmode pushed nvs");
222
223out:
224 mutex_unlock(&wl->mutex);
225
226 return ret;
227}
228
229static int wl1271_tm_cmd_set_plt_mode(struct wl1271 *wl, struct nlattr *tb[])
230{
231 u32 val;
232 int ret;
233
234 wl1271_debug(DEBUG_TESTMODE, "testmode cmd set plt mode");
235
236 if (!tb[WL1271_TM_ATTR_PLT_MODE])
237 return -EINVAL;
238
239 val = nla_get_u32(tb[WL1271_TM_ATTR_PLT_MODE]);
240
241 switch (val) {
242 case 0:
243 ret = wl1271_plt_stop(wl);
244 break;
245 case 1:
246 ret = wl1271_plt_start(wl);
247 break;
248 default:
249 ret = -EINVAL;
250 break;
251 }
252
253 return ret;
254}
255
256int wl1271_tm_cmd(struct ieee80211_hw *hw, void *data, int len)
257{
258 struct wl1271 *wl = hw->priv;
259 struct nlattr *tb[WL1271_TM_ATTR_MAX + 1];
260 int err;
261
262 err = nla_parse(tb, WL1271_TM_ATTR_MAX, data, len, wl1271_tm_policy);
263 if (err)
264 return err;
265
266 if (!tb[WL1271_TM_ATTR_CMD_ID])
267 return -EINVAL;
268
269 switch (nla_get_u32(tb[WL1271_TM_ATTR_CMD_ID])) {
270 case WL1271_TM_CMD_TEST:
271 return wl1271_tm_cmd_test(wl, tb);
272 case WL1271_TM_CMD_INTERROGATE:
273 return wl1271_tm_cmd_interrogate(wl, tb);
274 case WL1271_TM_CMD_CONFIGURE:
275 return wl1271_tm_cmd_configure(wl, tb);
276 case WL1271_TM_CMD_NVS_PUSH:
277 return wl1271_tm_cmd_nvs_push(wl, tb);
278 case WL1271_TM_CMD_SET_PLT_MODE:
279 return wl1271_tm_cmd_set_plt_mode(wl, tb);
280 default:
281 return -EOPNOTSUPP;
282 }
283}
diff --git a/drivers/net/wireless/wl12xx/wl1271_testmode.h b/drivers/net/wireless/wl12xx/wl1271_testmode.h
new file mode 100644
index 000000000000..c196d28f9d9d
--- /dev/null
+++ b/drivers/net/wireless/wl12xx/wl1271_testmode.h
@@ -0,0 +1,31 @@
1/*
2 * This file is part of wl1271
3 *
4 * Copyright (C) 2010 Nokia Corporation
5 *
6 * Contact: Luciano Coelho <luciano.coelho@nokia.com>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * version 2 as published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA
21 *
22 */
23
24#ifndef __WL1271_TESTMODE_H__
25#define __WL1271_TESTMODE_H__
26
27#include <net/mac80211.h>
28
29int wl1271_tm_cmd(struct ieee80211_hw *hw, void *data, int len);
30
31#endif /* __WL1271_TESTMODE_H__ */