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
, /* Not in use. Keep to not break ABI */
44 WL1271_TM_CMD_GET_MAC
,
46 __WL1271_TM_CMD_AFTER_LAST
48 #define WL1271_TM_CMD_MAX (__WL1271_TM_CMD_AFTER_LAST - 1)
50 enum wl1271_tm_attrs
{
51 WL1271_TM_ATTR_UNSPEC
,
52 WL1271_TM_ATTR_CMD_ID
,
53 WL1271_TM_ATTR_ANSWER
,
56 WL1271_TM_ATTR_PLT_MODE
,
58 __WL1271_TM_ATTR_AFTER_LAST
60 #define WL1271_TM_ATTR_MAX (__WL1271_TM_ATTR_AFTER_LAST - 1)
62 static struct nla_policy wl1271_tm_policy
[WL1271_TM_ATTR_MAX
+ 1] = {
63 [WL1271_TM_ATTR_CMD_ID
] = { .type
= NLA_U32
},
64 [WL1271_TM_ATTR_ANSWER
] = { .type
= NLA_U8
},
65 [WL1271_TM_ATTR_DATA
] = { .type
= NLA_BINARY
,
66 .len
= WL1271_TM_MAX_DATA_LENGTH
},
67 [WL1271_TM_ATTR_IE_ID
] = { .type
= NLA_U32
},
68 [WL1271_TM_ATTR_PLT_MODE
] = { .type
= NLA_U32
},
72 static int wl1271_tm_cmd_test(struct wl1271
*wl
, struct nlattr
*tb
[])
74 int buf_len
, ret
, len
;
79 wl1271_debug(DEBUG_TESTMODE
, "testmode cmd test");
81 if (!tb
[WL1271_TM_ATTR_DATA
])
84 buf
= nla_data(tb
[WL1271_TM_ATTR_DATA
]);
85 buf_len
= nla_len(tb
[WL1271_TM_ATTR_DATA
]);
87 if (tb
[WL1271_TM_ATTR_ANSWER
])
88 answer
= nla_get_u8(tb
[WL1271_TM_ATTR_ANSWER
]);
90 if (buf_len
> sizeof(struct wl1271_command
))
93 mutex_lock(&wl
->mutex
);
95 if (unlikely(wl
->state
!= WLCORE_STATE_ON
)) {
100 ret
= wl1271_ps_elp_wakeup(wl
);
104 ret
= wl1271_cmd_test(wl
, buf
, buf_len
, answer
);
106 wl1271_warning("testmode cmd test failed: %d", ret
);
111 /* If we got bip calibration answer print radio status */
112 struct wl1271_cmd_cal_p2g
*params
=
113 (struct wl1271_cmd_cal_p2g
*) buf
;
115 s16 radio_status
= (s16
) le16_to_cpu(params
->radio_status
);
117 if (params
->test
.id
== TEST_CMD_P2G_CAL
&&
119 wl1271_warning("testmode cmd: radio status=%d",
122 wl1271_info("testmode cmd: radio status=%d",
125 len
= nla_total_size(buf_len
);
126 skb
= cfg80211_testmode_alloc_reply_skb(wl
->hw
->wiphy
, len
);
132 if (nla_put(skb
, WL1271_TM_ATTR_DATA
, buf_len
, buf
)) {
138 ret
= cfg80211_testmode_reply(skb
);
144 wl1271_ps_elp_sleep(wl
);
146 mutex_unlock(&wl
->mutex
);
151 static int wl1271_tm_cmd_interrogate(struct wl1271
*wl
, struct nlattr
*tb
[])
154 struct wl1271_command
*cmd
;
158 wl1271_debug(DEBUG_TESTMODE
, "testmode cmd interrogate");
160 if (!tb
[WL1271_TM_ATTR_IE_ID
])
163 ie_id
= nla_get_u8(tb
[WL1271_TM_ATTR_IE_ID
]);
165 mutex_lock(&wl
->mutex
);
167 if (unlikely(wl
->state
!= WLCORE_STATE_ON
)) {
172 ret
= wl1271_ps_elp_wakeup(wl
);
176 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
182 ret
= wl1271_cmd_interrogate(wl
, ie_id
, cmd
,
183 sizeof(struct acx_header
), sizeof(*cmd
));
185 wl1271_warning("testmode cmd interrogate failed: %d", ret
);
189 skb
= cfg80211_testmode_alloc_reply_skb(wl
->hw
->wiphy
, sizeof(*cmd
));
195 if (nla_put(skb
, WL1271_TM_ATTR_DATA
, sizeof(*cmd
), cmd
)) {
201 ret
= cfg80211_testmode_reply(skb
);
208 wl1271_ps_elp_sleep(wl
);
210 mutex_unlock(&wl
->mutex
);
215 static int wl1271_tm_cmd_configure(struct wl1271
*wl
, struct nlattr
*tb
[])
221 wl1271_debug(DEBUG_TESTMODE
, "testmode cmd configure");
223 if (!tb
[WL1271_TM_ATTR_DATA
])
225 if (!tb
[WL1271_TM_ATTR_IE_ID
])
228 ie_id
= nla_get_u8(tb
[WL1271_TM_ATTR_IE_ID
]);
229 buf
= nla_data(tb
[WL1271_TM_ATTR_DATA
]);
230 buf_len
= nla_len(tb
[WL1271_TM_ATTR_DATA
]);
232 if (buf_len
> sizeof(struct wl1271_command
))
235 mutex_lock(&wl
->mutex
);
236 ret
= wl1271_cmd_configure(wl
, ie_id
, buf
, buf_len
);
237 mutex_unlock(&wl
->mutex
);
240 wl1271_warning("testmode cmd configure failed: %d", ret
);
247 static int wl1271_tm_detect_fem(struct wl1271
*wl
, struct nlattr
*tb
[])
249 /* return FEM type */
253 ret
= wl1271_plt_start(wl
, PLT_FEM_DETECT
);
257 mutex_lock(&wl
->mutex
);
259 len
= nla_total_size(sizeof(wl
->fem_manuf
));
260 skb
= cfg80211_testmode_alloc_reply_skb(wl
->hw
->wiphy
, len
);
266 if (nla_put(skb
, WL1271_TM_ATTR_DATA
, sizeof(wl
->fem_manuf
),
273 ret
= cfg80211_testmode_reply(skb
);
276 mutex_unlock(&wl
->mutex
);
278 /* We always stop plt after DETECT mode */
284 static int wl1271_tm_cmd_set_plt_mode(struct wl1271
*wl
, struct nlattr
*tb
[])
289 wl1271_debug(DEBUG_TESTMODE
, "testmode cmd set plt mode");
291 if (!tb
[WL1271_TM_ATTR_PLT_MODE
])
294 val
= nla_get_u32(tb
[WL1271_TM_ATTR_PLT_MODE
]);
298 ret
= wl1271_plt_stop(wl
);
302 ret
= wl1271_plt_start(wl
, val
);
305 ret
= wl1271_tm_detect_fem(wl
, tb
);
315 static int wl12xx_tm_cmd_get_mac(struct wl1271
*wl
, struct nlattr
*tb
[])
318 u8 mac_addr
[ETH_ALEN
];
321 mutex_lock(&wl
->mutex
);
328 if (wl
->fuse_oui_addr
== 0 && wl
->fuse_nic_addr
== 0) {
333 mac_addr
[0] = (u8
)(wl
->fuse_oui_addr
>> 16);
334 mac_addr
[1] = (u8
)(wl
->fuse_oui_addr
>> 8);
335 mac_addr
[2] = (u8
) wl
->fuse_oui_addr
;
336 mac_addr
[3] = (u8
)(wl
->fuse_nic_addr
>> 16);
337 mac_addr
[4] = (u8
)(wl
->fuse_nic_addr
>> 8);
338 mac_addr
[5] = (u8
) wl
->fuse_nic_addr
;
340 skb
= cfg80211_testmode_alloc_reply_skb(wl
->hw
->wiphy
, ETH_ALEN
);
346 if (nla_put(skb
, WL1271_TM_ATTR_DATA
, ETH_ALEN
, mac_addr
)) {
352 ret
= cfg80211_testmode_reply(skb
);
357 mutex_unlock(&wl
->mutex
);
361 int wl1271_tm_cmd(struct ieee80211_hw
*hw
, struct ieee80211_vif
*vif
,
364 struct wl1271
*wl
= hw
->priv
;
365 struct nlattr
*tb
[WL1271_TM_ATTR_MAX
+ 1];
369 err
= nla_parse(tb
, WL1271_TM_ATTR_MAX
, data
, len
, wl1271_tm_policy
);
373 if (!tb
[WL1271_TM_ATTR_CMD_ID
])
376 nla_cmd
= nla_get_u32(tb
[WL1271_TM_ATTR_CMD_ID
]);
378 /* Only SET_PLT_MODE is allowed in case of mode PLT_CHIP_AWAKE */
379 if (wl
->plt_mode
== PLT_CHIP_AWAKE
&&
380 nla_cmd
!= WL1271_TM_CMD_SET_PLT_MODE
)
384 case WL1271_TM_CMD_TEST
:
385 return wl1271_tm_cmd_test(wl
, tb
);
386 case WL1271_TM_CMD_INTERROGATE
:
387 return wl1271_tm_cmd_interrogate(wl
, tb
);
388 case WL1271_TM_CMD_CONFIGURE
:
389 return wl1271_tm_cmd_configure(wl
, tb
);
390 case WL1271_TM_CMD_SET_PLT_MODE
:
391 return wl1271_tm_cmd_set_plt_mode(wl
, tb
);
392 case WL1271_TM_CMD_GET_MAC
:
393 return wl12xx_tm_cmd_get_mac(wl
, tb
);