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>
32 #define WL1271_TM_MAX_DATA_LENGTH 1024
34 enum wl1271_tm_commands
{
37 WL1271_TM_CMD_INTERROGATE
,
38 WL1271_TM_CMD_CONFIGURE
,
39 WL1271_TM_CMD_NVS_PUSH
, /* Not in use. Keep to not break ABI */
40 WL1271_TM_CMD_SET_PLT_MODE
,
41 WL1271_TM_CMD_RECOVER
,
43 __WL1271_TM_CMD_AFTER_LAST
45 #define WL1271_TM_CMD_MAX (__WL1271_TM_CMD_AFTER_LAST - 1)
47 enum wl1271_tm_attrs
{
48 WL1271_TM_ATTR_UNSPEC
,
49 WL1271_TM_ATTR_CMD_ID
,
50 WL1271_TM_ATTR_ANSWER
,
53 WL1271_TM_ATTR_PLT_MODE
,
55 __WL1271_TM_ATTR_AFTER_LAST
57 #define WL1271_TM_ATTR_MAX (__WL1271_TM_ATTR_AFTER_LAST - 1)
59 static struct nla_policy wl1271_tm_policy
[WL1271_TM_ATTR_MAX
+ 1] = {
60 [WL1271_TM_ATTR_CMD_ID
] = { .type
= NLA_U32
},
61 [WL1271_TM_ATTR_ANSWER
] = { .type
= NLA_U8
},
62 [WL1271_TM_ATTR_DATA
] = { .type
= NLA_BINARY
,
63 .len
= WL1271_TM_MAX_DATA_LENGTH
},
64 [WL1271_TM_ATTR_IE_ID
] = { .type
= NLA_U32
},
65 [WL1271_TM_ATTR_PLT_MODE
] = { .type
= NLA_U32
},
69 static int wl1271_tm_cmd_test(struct wl1271
*wl
, struct nlattr
*tb
[])
71 int buf_len
, ret
, len
;
76 wl1271_debug(DEBUG_TESTMODE
, "testmode cmd test");
78 if (!tb
[WL1271_TM_ATTR_DATA
])
81 buf
= nla_data(tb
[WL1271_TM_ATTR_DATA
]);
82 buf_len
= nla_len(tb
[WL1271_TM_ATTR_DATA
]);
84 if (tb
[WL1271_TM_ATTR_ANSWER
])
85 answer
= nla_get_u8(tb
[WL1271_TM_ATTR_ANSWER
]);
87 if (buf_len
> sizeof(struct wl1271_command
))
90 mutex_lock(&wl
->mutex
);
91 ret
= wl1271_cmd_test(wl
, buf
, buf_len
, answer
);
92 mutex_unlock(&wl
->mutex
);
95 wl1271_warning("testmode cmd test failed: %d", ret
);
100 len
= nla_total_size(buf_len
);
101 skb
= cfg80211_testmode_alloc_reply_skb(wl
->hw
->wiphy
, len
);
105 NLA_PUT(skb
, WL1271_TM_ATTR_DATA
, buf_len
, buf
);
106 ret
= cfg80211_testmode_reply(skb
);
118 static int wl1271_tm_cmd_interrogate(struct wl1271
*wl
, struct nlattr
*tb
[])
121 struct wl1271_command
*cmd
;
125 wl1271_debug(DEBUG_TESTMODE
, "testmode cmd interrogate");
127 if (!tb
[WL1271_TM_ATTR_IE_ID
])
130 ie_id
= nla_get_u8(tb
[WL1271_TM_ATTR_IE_ID
]);
132 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
136 mutex_lock(&wl
->mutex
);
137 ret
= wl1271_cmd_interrogate(wl
, ie_id
, cmd
, sizeof(*cmd
));
138 mutex_unlock(&wl
->mutex
);
141 wl1271_warning("testmode cmd interrogate failed: %d", ret
);
146 skb
= cfg80211_testmode_alloc_reply_skb(wl
->hw
->wiphy
, sizeof(*cmd
));
152 NLA_PUT(skb
, WL1271_TM_ATTR_DATA
, sizeof(*cmd
), cmd
);
161 static int wl1271_tm_cmd_configure(struct wl1271
*wl
, struct nlattr
*tb
[])
167 wl1271_debug(DEBUG_TESTMODE
, "testmode cmd configure");
169 if (!tb
[WL1271_TM_ATTR_DATA
])
171 if (!tb
[WL1271_TM_ATTR_IE_ID
])
174 ie_id
= nla_get_u8(tb
[WL1271_TM_ATTR_IE_ID
]);
175 buf
= nla_data(tb
[WL1271_TM_ATTR_DATA
]);
176 buf_len
= nla_len(tb
[WL1271_TM_ATTR_DATA
]);
178 if (buf_len
> sizeof(struct wl1271_command
))
181 mutex_lock(&wl
->mutex
);
182 ret
= wl1271_cmd_configure(wl
, ie_id
, buf
, buf_len
);
183 mutex_unlock(&wl
->mutex
);
186 wl1271_warning("testmode cmd configure failed: %d", ret
);
193 static int wl1271_tm_cmd_set_plt_mode(struct wl1271
*wl
, struct nlattr
*tb
[])
198 wl1271_debug(DEBUG_TESTMODE
, "testmode cmd set plt mode");
200 if (!tb
[WL1271_TM_ATTR_PLT_MODE
])
203 val
= nla_get_u32(tb
[WL1271_TM_ATTR_PLT_MODE
]);
207 ret
= wl1271_plt_stop(wl
);
210 ret
= wl1271_plt_start(wl
);
220 static int wl1271_tm_cmd_recover(struct wl1271
*wl
, struct nlattr
*tb
[])
222 wl1271_debug(DEBUG_TESTMODE
, "testmode cmd recover");
224 wl12xx_queue_recovery_work(wl
);
229 int wl1271_tm_cmd(struct ieee80211_hw
*hw
, void *data
, int len
)
231 struct wl1271
*wl
= hw
->priv
;
232 struct nlattr
*tb
[WL1271_TM_ATTR_MAX
+ 1];
235 err
= nla_parse(tb
, WL1271_TM_ATTR_MAX
, data
, len
, wl1271_tm_policy
);
239 if (!tb
[WL1271_TM_ATTR_CMD_ID
])
242 switch (nla_get_u32(tb
[WL1271_TM_ATTR_CMD_ID
])) {
243 case WL1271_TM_CMD_TEST
:
244 return wl1271_tm_cmd_test(wl
, tb
);
245 case WL1271_TM_CMD_INTERROGATE
:
246 return wl1271_tm_cmd_interrogate(wl
, tb
);
247 case WL1271_TM_CMD_CONFIGURE
:
248 return wl1271_tm_cmd_configure(wl
, tb
);
249 case WL1271_TM_CMD_SET_PLT_MODE
:
250 return wl1271_tm_cmd_set_plt_mode(wl
, tb
);
251 case WL1271_TM_CMD_RECOVER
:
252 return wl1271_tm_cmd_recover(wl
, tb
);