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
23 #include "wl1271_testmode.h"
25 #include <linux/slab.h>
26 #include <net/genetlink.h>
29 #include "wl1271_acx.h"
31 #define WL1271_TM_MAX_DATA_LENGTH 1024
33 enum wl1271_tm_commands {
36 WL1271_TM_CMD_INTERROGATE,
37 WL1271_TM_CMD_CONFIGURE,
38 WL1271_TM_CMD_NVS_PUSH,
39 WL1271_TM_CMD_SET_PLT_MODE,
41 __WL1271_TM_CMD_AFTER_LAST
43 #define WL1271_TM_CMD_MAX (__WL1271_TM_CMD_AFTER_LAST - 1)
45 enum wl1271_tm_attrs {
46 WL1271_TM_ATTR_UNSPEC,
47 WL1271_TM_ATTR_CMD_ID,
48 WL1271_TM_ATTR_ANSWER,
51 WL1271_TM_ATTR_PLT_MODE,
53 __WL1271_TM_ATTR_AFTER_LAST
55 #define WL1271_TM_ATTR_MAX (__WL1271_TM_ATTR_AFTER_LAST - 1)
57 static 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 },
67 static int wl1271_tm_cmd_test(struct wl1271 *wl, struct nlattr *tb[])
69 int buf_len, ret, len;
74 wl1271_debug(DEBUG_TESTMODE, "testmode cmd test");
76 if (!tb[WL1271_TM_ATTR_DATA])
79 buf = nla_data(tb[WL1271_TM_ATTR_DATA]);
80 buf_len = nla_len(tb[WL1271_TM_ATTR_DATA]);
82 if (tb[WL1271_TM_ATTR_ANSWER])
83 answer = nla_get_u8(tb[WL1271_TM_ATTR_ANSWER]);
85 if (buf_len > sizeof(struct wl1271_command))
88 mutex_lock(&wl->mutex);
89 ret = wl1271_cmd_test(wl, buf, buf_len, answer);
90 mutex_unlock(&wl->mutex);
93 wl1271_warning("testmode cmd test failed: %d", ret);
98 len = nla_total_size(buf_len);
99 skb = cfg80211_testmode_alloc_reply_skb(wl->hw->wiphy, len);
103 NLA_PUT(skb, WL1271_TM_ATTR_DATA, buf_len, buf);
104 ret = cfg80211_testmode_reply(skb);
116 static int wl1271_tm_cmd_interrogate(struct wl1271 *wl, struct nlattr *tb[])
119 struct wl1271_command *cmd;
123 wl1271_debug(DEBUG_TESTMODE, "testmode cmd interrogate");
125 if (!tb[WL1271_TM_ATTR_IE_ID])
128 ie_id = nla_get_u8(tb[WL1271_TM_ATTR_IE_ID]);
130 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
134 mutex_lock(&wl->mutex);
135 ret = wl1271_cmd_interrogate(wl, ie_id, cmd, sizeof(*cmd));
136 mutex_unlock(&wl->mutex);
139 wl1271_warning("testmode cmd interrogate failed: %d", ret);
143 skb = cfg80211_testmode_alloc_reply_skb(wl->hw->wiphy, sizeof(*cmd));
147 NLA_PUT(skb, WL1271_TM_ATTR_DATA, sizeof(*cmd), cmd);
156 static int wl1271_tm_cmd_configure(struct wl1271 *wl, struct nlattr *tb[])
162 wl1271_debug(DEBUG_TESTMODE, "testmode cmd configure");
164 if (!tb[WL1271_TM_ATTR_DATA])
166 if (!tb[WL1271_TM_ATTR_IE_ID])
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]);
173 if (buf_len > sizeof(struct wl1271_command))
176 mutex_lock(&wl->mutex);
177 ret = wl1271_cmd_configure(wl, ie_id, buf, buf_len);
178 mutex_unlock(&wl->mutex);
181 wl1271_warning("testmode cmd configure failed: %d", ret);
188 static int wl1271_tm_cmd_nvs_push(struct wl1271 *wl, struct nlattr *tb[])
194 wl1271_debug(DEBUG_TESTMODE, "testmode cmd nvs push");
196 if (!tb[WL1271_TM_ATTR_DATA])
199 buf = nla_data(tb[WL1271_TM_ATTR_DATA]);
200 len = nla_len(tb[WL1271_TM_ATTR_DATA]);
202 mutex_lock(&wl->mutex);
206 wl->nvs = kzalloc(sizeof(struct wl1271_nvs_file), GFP_KERNEL);
208 wl1271_error("could not allocate memory for the nvs file");
213 memcpy(wl->nvs, buf, len);
216 wl1271_debug(DEBUG_TESTMODE, "testmode pushed nvs");
219 mutex_unlock(&wl->mutex);
224 static int wl1271_tm_cmd_set_plt_mode(struct wl1271 *wl, struct nlattr *tb[])
229 wl1271_debug(DEBUG_TESTMODE, "testmode cmd set plt mode");
231 if (!tb[WL1271_TM_ATTR_PLT_MODE])
234 val = nla_get_u32(tb[WL1271_TM_ATTR_PLT_MODE]);
238 ret = wl1271_plt_stop(wl);
241 ret = wl1271_plt_start(wl);
251 int wl1271_tm_cmd(struct ieee80211_hw *hw, void *data, int len)
253 struct wl1271 *wl = hw->priv;
254 struct nlattr *tb[WL1271_TM_ATTR_MAX + 1];
257 err = nla_parse(tb, WL1271_TM_ATTR_MAX, data, len, wl1271_tm_policy);
261 if (!tb[WL1271_TM_ATTR_CMD_ID])
264 switch (nla_get_u32(tb[WL1271_TM_ATTR_CMD_ID])) {
265 case WL1271_TM_CMD_TEST:
266 return wl1271_tm_cmd_test(wl, tb);
267 case WL1271_TM_CMD_INTERROGATE:
268 return wl1271_tm_cmd_interrogate(wl, tb);
269 case WL1271_TM_CMD_CONFIGURE:
270 return wl1271_tm_cmd_configure(wl, tb);
271 case WL1271_TM_CMD_NVS_PUSH:
272 return wl1271_tm_cmd_nvs_push(wl, tb);
273 case WL1271_TM_CMD_SET_PLT_MODE:
274 return wl1271_tm_cmd_set_plt_mode(wl, tb);