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>
35 #define WL1271_TM_MAX_DATA_LENGTH 1024
37 enum wl1271_tm_commands {
40 WL1271_TM_CMD_INTERROGATE,
41 WL1271_TM_CMD_CONFIGURE,
42 WL1271_TM_CMD_NVS_PUSH, /* Not in use. Keep to not break ABI */
43 WL1271_TM_CMD_SET_PLT_MODE,
44 WL1271_TM_CMD_RECOVER,
45 WL1271_TM_CMD_GET_MAC,
47 __WL1271_TM_CMD_AFTER_LAST
49 #define WL1271_TM_CMD_MAX (__WL1271_TM_CMD_AFTER_LAST - 1)
51 enum wl1271_tm_attrs {
52 WL1271_TM_ATTR_UNSPEC,
53 WL1271_TM_ATTR_CMD_ID,
54 WL1271_TM_ATTR_ANSWER,
57 WL1271_TM_ATTR_PLT_MODE,
59 __WL1271_TM_ATTR_AFTER_LAST
61 #define WL1271_TM_ATTR_MAX (__WL1271_TM_ATTR_AFTER_LAST - 1)
63 static struct nla_policy wl1271_tm_policy[WL1271_TM_ATTR_MAX + 1] = {
64 [WL1271_TM_ATTR_CMD_ID] = { .type = NLA_U32 },
65 [WL1271_TM_ATTR_ANSWER] = { .type = NLA_U8 },
66 [WL1271_TM_ATTR_DATA] = { .type = NLA_BINARY,
67 .len = WL1271_TM_MAX_DATA_LENGTH },
68 [WL1271_TM_ATTR_IE_ID] = { .type = NLA_U32 },
69 [WL1271_TM_ATTR_PLT_MODE] = { .type = NLA_U32 },
73 static int wl1271_tm_cmd_test(struct wl1271 *wl, struct nlattr *tb[])
75 int buf_len, ret, len;
80 wl1271_debug(DEBUG_TESTMODE, "testmode cmd test");
82 if (!tb[WL1271_TM_ATTR_DATA])
85 buf = nla_data(tb[WL1271_TM_ATTR_DATA]);
86 buf_len = nla_len(tb[WL1271_TM_ATTR_DATA]);
88 if (tb[WL1271_TM_ATTR_ANSWER])
89 answer = nla_get_u8(tb[WL1271_TM_ATTR_ANSWER]);
91 if (buf_len > sizeof(struct wl1271_command))
94 mutex_lock(&wl->mutex);
96 if (wl->state == WL1271_STATE_OFF) {
101 ret = wl1271_ps_elp_wakeup(wl);
105 ret = wl1271_cmd_test(wl, buf, buf_len, answer);
107 wl1271_warning("testmode cmd test failed: %d", ret);
112 len = nla_total_size(buf_len);
113 skb = cfg80211_testmode_alloc_reply_skb(wl->hw->wiphy, len);
119 NLA_PUT(skb, WL1271_TM_ATTR_DATA, buf_len, buf);
120 ret = cfg80211_testmode_reply(skb);
126 wl1271_ps_elp_sleep(wl);
128 mutex_unlock(&wl->mutex);
138 static int wl1271_tm_cmd_interrogate(struct wl1271 *wl, struct nlattr *tb[])
141 struct wl1271_command *cmd;
145 wl1271_debug(DEBUG_TESTMODE, "testmode cmd interrogate");
147 if (!tb[WL1271_TM_ATTR_IE_ID])
150 ie_id = nla_get_u8(tb[WL1271_TM_ATTR_IE_ID]);
152 mutex_lock(&wl->mutex);
154 if (wl->state == WL1271_STATE_OFF) {
159 ret = wl1271_ps_elp_wakeup(wl);
163 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
169 ret = wl1271_cmd_interrogate(wl, ie_id, cmd, sizeof(*cmd));
171 wl1271_warning("testmode cmd interrogate failed: %d", ret);
175 skb = cfg80211_testmode_alloc_reply_skb(wl->hw->wiphy, sizeof(*cmd));
181 NLA_PUT(skb, WL1271_TM_ATTR_DATA, sizeof(*cmd), cmd);
182 ret = cfg80211_testmode_reply(skb);
189 wl1271_ps_elp_sleep(wl);
191 mutex_unlock(&wl->mutex);
201 static int wl1271_tm_cmd_configure(struct wl1271 *wl, struct nlattr *tb[])
207 wl1271_debug(DEBUG_TESTMODE, "testmode cmd configure");
209 if (!tb[WL1271_TM_ATTR_DATA])
211 if (!tb[WL1271_TM_ATTR_IE_ID])
214 ie_id = nla_get_u8(tb[WL1271_TM_ATTR_IE_ID]);
215 buf = nla_data(tb[WL1271_TM_ATTR_DATA]);
216 buf_len = nla_len(tb[WL1271_TM_ATTR_DATA]);
218 if (buf_len > sizeof(struct wl1271_command))
221 mutex_lock(&wl->mutex);
222 ret = wl1271_cmd_configure(wl, ie_id, buf, buf_len);
223 mutex_unlock(&wl->mutex);
226 wl1271_warning("testmode cmd configure failed: %d", ret);
233 static int wl1271_tm_cmd_set_plt_mode(struct wl1271 *wl, struct nlattr *tb[])
238 wl1271_debug(DEBUG_TESTMODE, "testmode cmd set plt mode");
240 if (!tb[WL1271_TM_ATTR_PLT_MODE])
243 val = nla_get_u32(tb[WL1271_TM_ATTR_PLT_MODE]);
247 ret = wl1271_plt_stop(wl);
250 ret = wl1271_plt_start(wl);
260 static int wl1271_tm_cmd_recover(struct wl1271 *wl, struct nlattr *tb[])
262 wl1271_debug(DEBUG_TESTMODE, "testmode cmd recover");
264 wl12xx_queue_recovery_work(wl);
269 static int wl12xx_tm_cmd_get_mac(struct wl1271 *wl, struct nlattr *tb[])
272 u8 mac_addr[ETH_ALEN];
275 mutex_lock(&wl->mutex);
282 if (wl->fuse_oui_addr == 0 && wl->fuse_nic_addr == 0) {
287 mac_addr[0] = (u8)(wl->fuse_oui_addr >> 16);
288 mac_addr[1] = (u8)(wl->fuse_oui_addr >> 8);
289 mac_addr[2] = (u8) wl->fuse_oui_addr;
290 mac_addr[3] = (u8)(wl->fuse_nic_addr >> 16);
291 mac_addr[4] = (u8)(wl->fuse_nic_addr >> 8);
292 mac_addr[5] = (u8) wl->fuse_nic_addr;
294 skb = cfg80211_testmode_alloc_reply_skb(wl->hw->wiphy, ETH_ALEN);
300 NLA_PUT(skb, WL1271_TM_ATTR_DATA, ETH_ALEN, mac_addr);
301 ret = cfg80211_testmode_reply(skb);
306 mutex_unlock(&wl->mutex);
315 int wl1271_tm_cmd(struct ieee80211_hw *hw, void *data, int len)
317 struct wl1271 *wl = hw->priv;
318 struct nlattr *tb[WL1271_TM_ATTR_MAX + 1];
321 err = nla_parse(tb, WL1271_TM_ATTR_MAX, data, len, wl1271_tm_policy);
325 if (!tb[WL1271_TM_ATTR_CMD_ID])
328 switch (nla_get_u32(tb[WL1271_TM_ATTR_CMD_ID])) {
329 case WL1271_TM_CMD_TEST:
330 return wl1271_tm_cmd_test(wl, tb);
331 case WL1271_TM_CMD_INTERROGATE:
332 return wl1271_tm_cmd_interrogate(wl, tb);
333 case WL1271_TM_CMD_CONFIGURE:
334 return wl1271_tm_cmd_configure(wl, tb);
335 case WL1271_TM_CMD_SET_PLT_MODE:
336 return wl1271_tm_cmd_set_plt_mode(wl, tb);
337 case WL1271_TM_CMD_RECOVER:
338 return wl1271_tm_cmd_recover(wl, tb);
339 case WL1271_TM_CMD_GET_MAC:
340 return wl12xx_tm_cmd_get_mac(wl, tb);