2
* This file is part of wl1271
4
* Copyright (C) 2010 Nokia Corporation
6
* Contact: Luciano Coelho <luciano.coelho@nokia.com>
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.
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.
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
25
#include <linux/slab.h>
26
#include <net/genetlink.h>
34
#define WL1271_TM_MAX_DATA_LENGTH 1024
36
enum wl1271_tm_commands {
39
WL1271_TM_CMD_INTERROGATE,
40
WL1271_TM_CMD_CONFIGURE,
41
WL1271_TM_CMD_NVS_PUSH, /* Not in use. Keep to not break ABI */
42
WL1271_TM_CMD_SET_PLT_MODE,
43
WL1271_TM_CMD_RECOVER,
45
__WL1271_TM_CMD_AFTER_LAST
47
#define WL1271_TM_CMD_MAX (__WL1271_TM_CMD_AFTER_LAST - 1)
49
enum wl1271_tm_attrs {
50
WL1271_TM_ATTR_UNSPEC,
51
WL1271_TM_ATTR_CMD_ID,
52
WL1271_TM_ATTR_ANSWER,
55
WL1271_TM_ATTR_PLT_MODE,
57
__WL1271_TM_ATTR_AFTER_LAST
59
#define WL1271_TM_ATTR_MAX (__WL1271_TM_ATTR_AFTER_LAST - 1)
61
static struct nla_policy wl1271_tm_policy[WL1271_TM_ATTR_MAX + 1] = {
62
[WL1271_TM_ATTR_CMD_ID] = { .type = NLA_U32 },
63
[WL1271_TM_ATTR_ANSWER] = { .type = NLA_U8 },
64
[WL1271_TM_ATTR_DATA] = { .type = NLA_BINARY,
65
.len = WL1271_TM_MAX_DATA_LENGTH },
66
[WL1271_TM_ATTR_IE_ID] = { .type = NLA_U32 },
67
[WL1271_TM_ATTR_PLT_MODE] = { .type = NLA_U32 },
71
static int wl1271_tm_cmd_test(struct wl1271 *wl, struct nlattr *tb[])
73
int buf_len, ret, len;
78
wl1271_debug(DEBUG_TESTMODE, "testmode cmd test");
80
if (!tb[WL1271_TM_ATTR_DATA])
83
buf = nla_data(tb[WL1271_TM_ATTR_DATA]);
84
buf_len = nla_len(tb[WL1271_TM_ATTR_DATA]);
86
if (tb[WL1271_TM_ATTR_ANSWER])
87
answer = nla_get_u8(tb[WL1271_TM_ATTR_ANSWER]);
89
if (buf_len > sizeof(struct wl1271_command))
92
mutex_lock(&wl->mutex);
94
if (wl->state == WL1271_STATE_OFF) {
99
ret = wl1271_ps_elp_wakeup(wl);
103
ret = wl1271_cmd_test(wl, buf, buf_len, answer);
105
wl1271_warning("testmode cmd test failed: %d", ret);
110
len = nla_total_size(buf_len);
111
skb = cfg80211_testmode_alloc_reply_skb(wl->hw->wiphy, len);
117
NLA_PUT(skb, WL1271_TM_ATTR_DATA, buf_len, buf);
118
ret = cfg80211_testmode_reply(skb);
124
wl1271_ps_elp_sleep(wl);
126
mutex_unlock(&wl->mutex);
136
static int wl1271_tm_cmd_interrogate(struct wl1271 *wl, struct nlattr *tb[])
139
struct wl1271_command *cmd;
143
wl1271_debug(DEBUG_TESTMODE, "testmode cmd interrogate");
145
if (!tb[WL1271_TM_ATTR_IE_ID])
148
ie_id = nla_get_u8(tb[WL1271_TM_ATTR_IE_ID]);
150
mutex_lock(&wl->mutex);
152
if (wl->state == WL1271_STATE_OFF) {
157
ret = wl1271_ps_elp_wakeup(wl);
161
cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
167
ret = wl1271_cmd_interrogate(wl, ie_id, cmd, sizeof(*cmd));
169
wl1271_warning("testmode cmd interrogate failed: %d", ret);
173
skb = cfg80211_testmode_alloc_reply_skb(wl->hw->wiphy, sizeof(*cmd));
179
NLA_PUT(skb, WL1271_TM_ATTR_DATA, sizeof(*cmd), cmd);
180
ret = cfg80211_testmode_reply(skb);
187
wl1271_ps_elp_sleep(wl);
189
mutex_unlock(&wl->mutex);
199
static int wl1271_tm_cmd_configure(struct wl1271 *wl, struct nlattr *tb[])
205
wl1271_debug(DEBUG_TESTMODE, "testmode cmd configure");
207
if (!tb[WL1271_TM_ATTR_DATA])
209
if (!tb[WL1271_TM_ATTR_IE_ID])
212
ie_id = nla_get_u8(tb[WL1271_TM_ATTR_IE_ID]);
213
buf = nla_data(tb[WL1271_TM_ATTR_DATA]);
214
buf_len = nla_len(tb[WL1271_TM_ATTR_DATA]);
216
if (buf_len > sizeof(struct wl1271_command))
219
mutex_lock(&wl->mutex);
220
ret = wl1271_cmd_configure(wl, ie_id, buf, buf_len);
221
mutex_unlock(&wl->mutex);
224
wl1271_warning("testmode cmd configure failed: %d", ret);
231
static int wl1271_tm_cmd_set_plt_mode(struct wl1271 *wl, struct nlattr *tb[])
236
wl1271_debug(DEBUG_TESTMODE, "testmode cmd set plt mode");
238
if (!tb[WL1271_TM_ATTR_PLT_MODE])
241
val = nla_get_u32(tb[WL1271_TM_ATTR_PLT_MODE]);
245
ret = wl1271_plt_stop(wl);
248
ret = wl1271_plt_start(wl);
258
static int wl1271_tm_cmd_recover(struct wl1271 *wl, struct nlattr *tb[])
260
wl1271_debug(DEBUG_TESTMODE, "testmode cmd recover");
262
wl12xx_queue_recovery_work(wl);
267
int wl1271_tm_cmd(struct ieee80211_hw *hw, void *data, int len)
269
struct wl1271 *wl = hw->priv;
270
struct nlattr *tb[WL1271_TM_ATTR_MAX + 1];
273
err = nla_parse(tb, WL1271_TM_ATTR_MAX, data, len, wl1271_tm_policy);
277
if (!tb[WL1271_TM_ATTR_CMD_ID])
280
switch (nla_get_u32(tb[WL1271_TM_ATTR_CMD_ID])) {
281
case WL1271_TM_CMD_TEST:
282
return wl1271_tm_cmd_test(wl, tb);
283
case WL1271_TM_CMD_INTERROGATE:
284
return wl1271_tm_cmd_interrogate(wl, tb);
285
case WL1271_TM_CMD_CONFIGURE:
286
return wl1271_tm_cmd_configure(wl, tb);
287
case WL1271_TM_CMD_SET_PLT_MODE:
288
return wl1271_tm_cmd_set_plt_mode(wl, tb);
289
case WL1271_TM_CMD_RECOVER:
290
return wl1271_tm_cmd_recover(wl, tb);