]>
Commit | Line | Data |
---|---|---|
876c9d3a MT |
1 | /** |
2 | * This file contains the handling of command. | |
3 | * It prepares command and sends it to firmware when it is ready. | |
4 | */ | |
5 | ||
6 | #include <net/iw_handler.h> | |
7 | #include "host.h" | |
8 | #include "hostcmd.h" | |
876c9d3a MT |
9 | #include "decl.h" |
10 | #include "defs.h" | |
11 | #include "dev.h" | |
12 | #include "join.h" | |
13 | #include "wext.h" | |
14 | ||
15 | static void cleanup_cmdnode(struct cmd_ctrl_node *ptempnode); | |
0d61d042 HS |
16 | struct cmd_ctrl_node *lbs_get_cmd_ctrl_node(struct lbs_private *priv); |
17 | void lbs_set_cmd_ctrl_node(struct lbs_private *priv, | |
18 | struct cmd_ctrl_node *ptempnode, | |
19 | u16 wait_option, void *pdata_buf); | |
20 | ||
876c9d3a MT |
21 | |
22 | static u16 commands_allowed_in_ps[] = { | |
0aef64d7 | 23 | CMD_802_11_RSSI, |
876c9d3a MT |
24 | }; |
25 | ||
26 | /** | |
27 | * @brief This function checks if the commans is allowed | |
28 | * in PS mode not. | |
29 | * | |
30 | * @param command the command ID | |
31 | * @return TRUE or FALSE | |
32 | */ | |
981f187b | 33 | static u8 is_command_allowed_in_ps(__le16 command) |
876c9d3a | 34 | { |
876c9d3a MT |
35 | int i; |
36 | ||
981f187b | 37 | for (i = 0; i < ARRAY_SIZE(commands_allowed_in_ps); i++) { |
876c9d3a MT |
38 | if (command == cpu_to_le16(commands_allowed_in_ps[i])) |
39 | return 1; | |
40 | } | |
41 | ||
42 | return 0; | |
43 | } | |
44 | ||
69f9032d | 45 | static int lbs_cmd_hw_spec(struct lbs_private *priv, struct cmd_ds_command *cmd) |
876c9d3a MT |
46 | { |
47 | struct cmd_ds_get_hw_spec *hwspec = &cmd->params.hwspec; | |
48 | ||
9012b28a | 49 | lbs_deb_enter(LBS_DEB_CMD); |
876c9d3a | 50 | |
0aef64d7 | 51 | cmd->command = cpu_to_le16(CMD_GET_HW_SPEC); |
981f187b | 52 | cmd->size = cpu_to_le16(sizeof(struct cmd_ds_get_hw_spec) + S_DS_GEN); |
876c9d3a MT |
53 | memcpy(hwspec->permanentaddr, priv->adapter->current_addr, ETH_ALEN); |
54 | ||
9012b28a | 55 | lbs_deb_leave(LBS_DEB_CMD); |
876c9d3a MT |
56 | return 0; |
57 | } | |
58 | ||
69f9032d | 59 | static int lbs_cmd_802_11_ps_mode(struct lbs_private *priv, |
876c9d3a MT |
60 | struct cmd_ds_command *cmd, |
61 | u16 cmd_action) | |
62 | { | |
63 | struct cmd_ds_802_11_ps_mode *psm = &cmd->params.psmode; | |
876c9d3a | 64 | |
9012b28a | 65 | lbs_deb_enter(LBS_DEB_CMD); |
876c9d3a | 66 | |
0aef64d7 | 67 | cmd->command = cpu_to_le16(CMD_802_11_PS_MODE); |
981f187b DW |
68 | cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_ps_mode) + |
69 | S_DS_GEN); | |
876c9d3a MT |
70 | psm->action = cpu_to_le16(cmd_action); |
71 | psm->multipledtim = 0; | |
981f187b | 72 | switch (cmd_action) { |
0aef64d7 | 73 | case CMD_SUBCMD_ENTER_PS: |
9012b28a | 74 | lbs_deb_cmd("PS command:" "SubCode- Enter PS\n"); |
876c9d3a | 75 | |
252cf0d1 | 76 | psm->locallisteninterval = 0; |
97605c3e | 77 | psm->nullpktinterval = 0; |
876c9d3a | 78 | psm->multipledtim = |
56c4656e | 79 | cpu_to_le16(MRVDRV_DEFAULT_MULTIPLE_DTIM); |
876c9d3a MT |
80 | break; |
81 | ||
0aef64d7 | 82 | case CMD_SUBCMD_EXIT_PS: |
9012b28a | 83 | lbs_deb_cmd("PS command:" "SubCode- Exit PS\n"); |
876c9d3a MT |
84 | break; |
85 | ||
0aef64d7 | 86 | case CMD_SUBCMD_SLEEP_CONFIRMED: |
9012b28a | 87 | lbs_deb_cmd("PS command: SubCode- sleep confirm\n"); |
876c9d3a MT |
88 | break; |
89 | ||
90 | default: | |
91 | break; | |
92 | } | |
93 | ||
9012b28a | 94 | lbs_deb_leave(LBS_DEB_CMD); |
876c9d3a MT |
95 | return 0; |
96 | } | |
97 | ||
69f9032d | 98 | static int lbs_cmd_802_11_inactivity_timeout(struct lbs_private *priv, |
876c9d3a MT |
99 | struct cmd_ds_command *cmd, |
100 | u16 cmd_action, void *pdata_buf) | |
101 | { | |
102 | u16 *timeout = pdata_buf; | |
103 | ||
8ff12da1 HS |
104 | lbs_deb_enter(LBS_DEB_CMD); |
105 | ||
0aef64d7 | 106 | cmd->command = cpu_to_le16(CMD_802_11_INACTIVITY_TIMEOUT); |
876c9d3a MT |
107 | cmd->size = |
108 | cpu_to_le16(sizeof(struct cmd_ds_802_11_inactivity_timeout) | |
109 | + S_DS_GEN); | |
110 | ||
111 | cmd->params.inactivity_timeout.action = cpu_to_le16(cmd_action); | |
112 | ||
113 | if (cmd_action) | |
981f187b | 114 | cmd->params.inactivity_timeout.timeout = cpu_to_le16(*timeout); |
876c9d3a MT |
115 | else |
116 | cmd->params.inactivity_timeout.timeout = 0; | |
117 | ||
8ff12da1 | 118 | lbs_deb_leave(LBS_DEB_CMD); |
876c9d3a MT |
119 | return 0; |
120 | } | |
121 | ||
69f9032d | 122 | static int lbs_cmd_802_11_sleep_params(struct lbs_private *priv, |
876c9d3a MT |
123 | struct cmd_ds_command *cmd, |
124 | u16 cmd_action) | |
125 | { | |
69f9032d | 126 | struct lbs_adapter *adapter = priv->adapter; |
876c9d3a MT |
127 | struct cmd_ds_802_11_sleep_params *sp = &cmd->params.sleep_params; |
128 | ||
9012b28a | 129 | lbs_deb_enter(LBS_DEB_CMD); |
876c9d3a | 130 | |
981f187b DW |
131 | cmd->size = cpu_to_le16((sizeof(struct cmd_ds_802_11_sleep_params)) + |
132 | S_DS_GEN); | |
0aef64d7 | 133 | cmd->command = cpu_to_le16(CMD_802_11_SLEEP_PARAMS); |
876c9d3a | 134 | |
0aef64d7 | 135 | if (cmd_action == CMD_ACT_GET) { |
876c9d3a MT |
136 | memset(&adapter->sp, 0, sizeof(struct sleep_params)); |
137 | memset(sp, 0, sizeof(struct cmd_ds_802_11_sleep_params)); | |
138 | sp->action = cpu_to_le16(cmd_action); | |
0aef64d7 | 139 | } else if (cmd_action == CMD_ACT_SET) { |
876c9d3a MT |
140 | sp->action = cpu_to_le16(cmd_action); |
141 | sp->error = cpu_to_le16(adapter->sp.sp_error); | |
142 | sp->offset = cpu_to_le16(adapter->sp.sp_offset); | |
143 | sp->stabletime = cpu_to_le16(adapter->sp.sp_stabletime); | |
144 | sp->calcontrol = (u8) adapter->sp.sp_calcontrol; | |
145 | sp->externalsleepclk = (u8) adapter->sp.sp_extsleepclk; | |
146 | sp->reserved = cpu_to_le16(adapter->sp.sp_reserved); | |
147 | } | |
148 | ||
9012b28a | 149 | lbs_deb_leave(LBS_DEB_CMD); |
876c9d3a MT |
150 | return 0; |
151 | } | |
152 | ||
69f9032d | 153 | static int lbs_cmd_802_11_set_wep(struct lbs_private *priv, |
876c9d3a MT |
154 | struct cmd_ds_command *cmd, |
155 | u32 cmd_act, | |
156 | void * pdata_buf) | |
157 | { | |
158 | struct cmd_ds_802_11_set_wep *wep = &cmd->params.wep; | |
69f9032d | 159 | struct lbs_adapter *adapter = priv->adapter; |
876c9d3a MT |
160 | int ret = 0; |
161 | struct assoc_request * assoc_req = pdata_buf; | |
162 | ||
9012b28a | 163 | lbs_deb_enter(LBS_DEB_CMD); |
876c9d3a | 164 | |
0aef64d7 | 165 | cmd->command = cpu_to_le16(CMD_802_11_SET_WEP); |
981f187b | 166 | cmd->size = cpu_to_le16(sizeof(*wep) + S_DS_GEN); |
876c9d3a | 167 | |
0aef64d7 | 168 | if (cmd_act == CMD_ACT_ADD) { |
876c9d3a MT |
169 | int i; |
170 | ||
171 | if (!assoc_req) { | |
9012b28a | 172 | lbs_deb_cmd("Invalid association request!"); |
876c9d3a MT |
173 | ret = -1; |
174 | goto done; | |
175 | } | |
176 | ||
0aef64d7 | 177 | wep->action = cpu_to_le16(CMD_ACT_ADD); |
876c9d3a MT |
178 | |
179 | /* default tx key index */ | |
981f187b | 180 | wep->keyindex = cpu_to_le16((u16)(assoc_req->wep_tx_keyidx & |
0aef64d7 | 181 | (u32)CMD_WEP_KEY_INDEX_MASK)); |
876c9d3a | 182 | |
876c9d3a MT |
183 | /* Copy key types and material to host command structure */ |
184 | for (i = 0; i < 4; i++) { | |
1443b653 | 185 | struct enc_key * pkey = &assoc_req->wep_keys[i]; |
876c9d3a MT |
186 | |
187 | switch (pkey->len) { | |
188 | case KEY_LEN_WEP_40: | |
6470a89d | 189 | wep->keytype[i] = CMD_TYPE_WEP_40_BIT; |
876c9d3a MT |
190 | memmove(&wep->keymaterial[i], pkey->key, |
191 | pkey->len); | |
8ff12da1 | 192 | lbs_deb_cmd("SET_WEP: add key %d (40 bit)\n", i); |
876c9d3a MT |
193 | break; |
194 | case KEY_LEN_WEP_104: | |
6470a89d | 195 | wep->keytype[i] = CMD_TYPE_WEP_104_BIT; |
876c9d3a MT |
196 | memmove(&wep->keymaterial[i], pkey->key, |
197 | pkey->len); | |
8ff12da1 | 198 | lbs_deb_cmd("SET_WEP: add key %d (104 bit)\n", i); |
876c9d3a MT |
199 | break; |
200 | case 0: | |
201 | break; | |
202 | default: | |
8ff12da1 | 203 | lbs_deb_cmd("SET_WEP: invalid key %d, length %d\n", |
876c9d3a MT |
204 | i, pkey->len); |
205 | ret = -1; | |
206 | goto done; | |
207 | break; | |
208 | } | |
209 | } | |
0aef64d7 | 210 | } else if (cmd_act == CMD_ACT_REMOVE) { |
876c9d3a | 211 | /* ACT_REMOVE clears _all_ WEP keys */ |
0aef64d7 | 212 | wep->action = cpu_to_le16(CMD_ACT_REMOVE); |
876c9d3a MT |
213 | |
214 | /* default tx key index */ | |
981f187b | 215 | wep->keyindex = cpu_to_le16((u16)(adapter->wep_tx_keyidx & |
0aef64d7 | 216 | (u32)CMD_WEP_KEY_INDEX_MASK)); |
8ff12da1 | 217 | lbs_deb_cmd("SET_WEP: remove key %d\n", adapter->wep_tx_keyidx); |
876c9d3a MT |
218 | } |
219 | ||
220 | ret = 0; | |
221 | ||
222 | done: | |
9012b28a | 223 | lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret); |
876c9d3a MT |
224 | return ret; |
225 | } | |
226 | ||
69f9032d | 227 | static int lbs_cmd_802_11_enable_rsn(struct lbs_private *priv, |
876c9d3a | 228 | struct cmd_ds_command *cmd, |
90a42210 DW |
229 | u16 cmd_action, |
230 | void * pdata_buf) | |
876c9d3a MT |
231 | { |
232 | struct cmd_ds_802_11_enable_rsn *penableRSN = &cmd->params.enbrsn; | |
18c96c34 | 233 | u32 * enable = pdata_buf; |
90a42210 DW |
234 | |
235 | lbs_deb_enter(LBS_DEB_CMD); | |
876c9d3a | 236 | |
0aef64d7 | 237 | cmd->command = cpu_to_le16(CMD_802_11_ENABLE_RSN); |
981f187b | 238 | cmd->size = cpu_to_le16(sizeof(*penableRSN) + S_DS_GEN); |
876c9d3a | 239 | penableRSN->action = cpu_to_le16(cmd_action); |
18c96c34 | 240 | |
0aef64d7 | 241 | if (cmd_action == CMD_ACT_SET) { |
18c96c34 | 242 | if (*enable) |
0aef64d7 | 243 | penableRSN->enable = cpu_to_le16(CMD_ENABLE_RSN); |
18c96c34 | 244 | else |
0aef64d7 | 245 | penableRSN->enable = cpu_to_le16(CMD_DISABLE_RSN); |
8ff12da1 | 246 | lbs_deb_cmd("ENABLE_RSN: %d\n", *enable); |
876c9d3a MT |
247 | } |
248 | ||
90a42210 | 249 | lbs_deb_leave(LBS_DEB_CMD); |
876c9d3a MT |
250 | return 0; |
251 | } | |
252 | ||
253 | ||
3a188649 HS |
254 | static ssize_t lbs_tlv_size(const u8 *tlv, u16 size) |
255 | { | |
256 | ssize_t pos = 0; | |
257 | struct mrvlietypesheader *tlv_h; | |
258 | while (pos < size) { | |
259 | u16 length; | |
260 | tlv_h = (struct mrvlietypesheader *) tlv; | |
261 | if (tlv_h->len == 0) | |
262 | return pos; | |
263 | length = le16_to_cpu(tlv_h->len) + | |
264 | sizeof(struct mrvlietypesheader); | |
265 | pos += length; | |
266 | tlv += length; | |
267 | } | |
268 | return pos; | |
269 | } | |
270 | ||
271 | ||
272 | static void lbs_cmd_802_11_subscribe_event(struct lbs_private *priv, | |
273 | struct cmd_ds_command *cmd, u16 cmd_action, | |
274 | void *pdata_buf) | |
275 | { | |
276 | struct cmd_ds_802_11_subscribe_event *events = | |
277 | (struct cmd_ds_802_11_subscribe_event *) pdata_buf; | |
278 | ||
279 | /* pdata_buf points to a struct cmd_ds_802_11_subscribe_event and room | |
280 | * for various Marvell TLVs */ | |
281 | ||
282 | lbs_deb_enter(LBS_DEB_CMD); | |
283 | ||
284 | cmd->size = cpu_to_le16(sizeof(*events) | |
285 | - sizeof(events->tlv) | |
286 | + S_DS_GEN); | |
287 | cmd->params.subscribe_event.action = cpu_to_le16(cmd_action); | |
288 | if (cmd_action == CMD_ACT_GET) { | |
289 | cmd->params.subscribe_event.events = 0; | |
290 | } else { | |
291 | ssize_t sz = lbs_tlv_size(events->tlv, sizeof(events->tlv)); | |
292 | cmd->size = cpu_to_le16(le16_to_cpu(cmd->size) + sz); | |
293 | cmd->params.subscribe_event.events = events->events; | |
294 | memcpy(cmd->params.subscribe_event.tlv, events->tlv, sz); | |
295 | } | |
296 | ||
297 | lbs_deb_leave(LBS_DEB_CMD); | |
298 | } | |
299 | ||
876c9d3a | 300 | static void set_one_wpa_key(struct MrvlIEtype_keyParamSet * pkeyparamset, |
1443b653 | 301 | struct enc_key * pkey) |
876c9d3a | 302 | { |
8ff12da1 HS |
303 | lbs_deb_enter(LBS_DEB_CMD); |
304 | ||
876c9d3a | 305 | if (pkey->flags & KEY_INFO_WPA_ENABLED) { |
90a42210 | 306 | pkeyparamset->keyinfo |= cpu_to_le16(KEY_INFO_WPA_ENABLED); |
876c9d3a | 307 | } |
876c9d3a MT |
308 | if (pkey->flags & KEY_INFO_WPA_UNICAST) { |
309 | pkeyparamset->keyinfo |= cpu_to_le16(KEY_INFO_WPA_UNICAST); | |
90a42210 DW |
310 | } |
311 | if (pkey->flags & KEY_INFO_WPA_MCAST) { | |
876c9d3a MT |
312 | pkeyparamset->keyinfo |= cpu_to_le16(KEY_INFO_WPA_MCAST); |
313 | } | |
314 | ||
315 | pkeyparamset->type = cpu_to_le16(TLV_TYPE_KEY_MATERIAL); | |
1443b653 | 316 | pkeyparamset->keytypeid = cpu_to_le16(pkey->type); |
876c9d3a MT |
317 | pkeyparamset->keylen = cpu_to_le16(pkey->len); |
318 | memcpy(pkeyparamset->key, pkey->key, pkey->len); | |
319 | pkeyparamset->length = cpu_to_le16( sizeof(pkeyparamset->keytypeid) | |
320 | + sizeof(pkeyparamset->keyinfo) | |
321 | + sizeof(pkeyparamset->keylen) | |
322 | + sizeof(pkeyparamset->key)); | |
8ff12da1 | 323 | lbs_deb_leave(LBS_DEB_CMD); |
876c9d3a MT |
324 | } |
325 | ||
69f9032d | 326 | static int lbs_cmd_802_11_key_material(struct lbs_private *priv, |
876c9d3a MT |
327 | struct cmd_ds_command *cmd, |
328 | u16 cmd_action, | |
329 | u32 cmd_oid, void *pdata_buf) | |
330 | { | |
876c9d3a MT |
331 | struct cmd_ds_802_11_key_material *pkeymaterial = |
332 | &cmd->params.keymaterial; | |
90a42210 | 333 | struct assoc_request * assoc_req = pdata_buf; |
876c9d3a MT |
334 | int ret = 0; |
335 | int index = 0; | |
336 | ||
9012b28a | 337 | lbs_deb_enter(LBS_DEB_CMD); |
876c9d3a | 338 | |
0aef64d7 | 339 | cmd->command = cpu_to_le16(CMD_802_11_KEY_MATERIAL); |
876c9d3a MT |
340 | pkeymaterial->action = cpu_to_le16(cmd_action); |
341 | ||
0aef64d7 | 342 | if (cmd_action == CMD_ACT_GET) { |
90a42210 | 343 | cmd->size = cpu_to_le16(S_DS_GEN + sizeof (pkeymaterial->action)); |
876c9d3a MT |
344 | ret = 0; |
345 | goto done; | |
346 | } | |
347 | ||
348 | memset(&pkeymaterial->keyParamSet, 0, sizeof(pkeymaterial->keyParamSet)); | |
349 | ||
90a42210 | 350 | if (test_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags)) { |
876c9d3a | 351 | set_one_wpa_key(&pkeymaterial->keyParamSet[index], |
90a42210 | 352 | &assoc_req->wpa_unicast_key); |
876c9d3a MT |
353 | index++; |
354 | } | |
355 | ||
90a42210 | 356 | if (test_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags)) { |
876c9d3a | 357 | set_one_wpa_key(&pkeymaterial->keyParamSet[index], |
90a42210 | 358 | &assoc_req->wpa_mcast_key); |
876c9d3a MT |
359 | index++; |
360 | } | |
361 | ||
362 | cmd->size = cpu_to_le16( S_DS_GEN | |
90a42210 DW |
363 | + sizeof (pkeymaterial->action) |
364 | + (index * sizeof(struct MrvlIEtype_keyParamSet))); | |
876c9d3a MT |
365 | |
366 | ret = 0; | |
367 | ||
368 | done: | |
9012b28a | 369 | lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret); |
876c9d3a MT |
370 | return ret; |
371 | } | |
372 | ||
69f9032d | 373 | static int lbs_cmd_802_11_reset(struct lbs_private *priv, |
876c9d3a MT |
374 | struct cmd_ds_command *cmd, int cmd_action) |
375 | { | |
376 | struct cmd_ds_802_11_reset *reset = &cmd->params.reset; | |
377 | ||
8ff12da1 HS |
378 | lbs_deb_enter(LBS_DEB_CMD); |
379 | ||
0aef64d7 | 380 | cmd->command = cpu_to_le16(CMD_802_11_RESET); |
876c9d3a MT |
381 | cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_reset) + S_DS_GEN); |
382 | reset->action = cpu_to_le16(cmd_action); | |
383 | ||
8ff12da1 | 384 | lbs_deb_leave(LBS_DEB_CMD); |
876c9d3a MT |
385 | return 0; |
386 | } | |
387 | ||
69f9032d | 388 | static int lbs_cmd_802_11_get_log(struct lbs_private *priv, |
876c9d3a MT |
389 | struct cmd_ds_command *cmd) |
390 | { | |
8ff12da1 | 391 | lbs_deb_enter(LBS_DEB_CMD); |
0aef64d7 | 392 | cmd->command = cpu_to_le16(CMD_802_11_GET_LOG); |
876c9d3a MT |
393 | cmd->size = |
394 | cpu_to_le16(sizeof(struct cmd_ds_802_11_get_log) + S_DS_GEN); | |
395 | ||
8ff12da1 | 396 | lbs_deb_leave(LBS_DEB_CMD); |
876c9d3a MT |
397 | return 0; |
398 | } | |
399 | ||
69f9032d | 400 | static int lbs_cmd_802_11_get_stat(struct lbs_private *priv, |
876c9d3a MT |
401 | struct cmd_ds_command *cmd) |
402 | { | |
8ff12da1 | 403 | lbs_deb_enter(LBS_DEB_CMD); |
0aef64d7 | 404 | cmd->command = cpu_to_le16(CMD_802_11_GET_STAT); |
876c9d3a | 405 | cmd->size = |
981f187b | 406 | cpu_to_le16(sizeof(struct cmd_ds_802_11_get_stat) + S_DS_GEN); |
876c9d3a | 407 | |
8ff12da1 | 408 | lbs_deb_leave(LBS_DEB_CMD); |
876c9d3a MT |
409 | return 0; |
410 | } | |
411 | ||
69f9032d | 412 | static int lbs_cmd_802_11_snmp_mib(struct lbs_private *priv, |
876c9d3a MT |
413 | struct cmd_ds_command *cmd, |
414 | int cmd_action, | |
415 | int cmd_oid, void *pdata_buf) | |
416 | { | |
417 | struct cmd_ds_802_11_snmp_mib *pSNMPMIB = &cmd->params.smib; | |
69f9032d | 418 | struct lbs_adapter *adapter = priv->adapter; |
876c9d3a MT |
419 | u8 ucTemp; |
420 | ||
9012b28a | 421 | lbs_deb_enter(LBS_DEB_CMD); |
876c9d3a | 422 | |
9012b28a | 423 | lbs_deb_cmd("SNMP_CMD: cmd_oid = 0x%x\n", cmd_oid); |
876c9d3a | 424 | |
0aef64d7 | 425 | cmd->command = cpu_to_le16(CMD_802_11_SNMP_MIB); |
981f187b | 426 | cmd->size = cpu_to_le16(sizeof(*pSNMPMIB) + S_DS_GEN); |
876c9d3a MT |
427 | |
428 | switch (cmd_oid) { | |
429 | case OID_802_11_INFRASTRUCTURE_MODE: | |
430 | { | |
0dc5a290 | 431 | u8 mode = (u8) (size_t) pdata_buf; |
0aef64d7 DW |
432 | pSNMPMIB->querytype = cpu_to_le16(CMD_ACT_SET); |
433 | pSNMPMIB->oid = cpu_to_le16((u16) DESIRED_BSSTYPE_I); | |
876c9d3a | 434 | pSNMPMIB->bufsize = sizeof(u8); |
0dc5a290 | 435 | if (mode == IW_MODE_ADHOC) { |
876c9d3a | 436 | ucTemp = SNMP_MIB_VALUE_ADHOC; |
0dc5a290 DW |
437 | } else { |
438 | /* Infra and Auto modes */ | |
439 | ucTemp = SNMP_MIB_VALUE_INFRA; | |
440 | } | |
876c9d3a MT |
441 | |
442 | memmove(pSNMPMIB->value, &ucTemp, sizeof(u8)); | |
443 | ||
444 | break; | |
445 | } | |
446 | ||
447 | case OID_802_11D_ENABLE: | |
448 | { | |
449 | u32 ulTemp; | |
450 | ||
0aef64d7 | 451 | pSNMPMIB->oid = cpu_to_le16((u16) DOT11D_I); |
876c9d3a | 452 | |
0aef64d7 DW |
453 | if (cmd_action == CMD_ACT_SET) { |
454 | pSNMPMIB->querytype = CMD_ACT_SET; | |
876c9d3a MT |
455 | pSNMPMIB->bufsize = sizeof(u16); |
456 | ulTemp = *(u32 *)pdata_buf; | |
981f187b | 457 | *((__le16 *)(pSNMPMIB->value)) = |
876c9d3a MT |
458 | cpu_to_le16((u16) ulTemp); |
459 | } | |
460 | break; | |
461 | } | |
462 | ||
463 | case OID_802_11_FRAGMENTATION_THRESHOLD: | |
464 | { | |
465 | u32 ulTemp; | |
466 | ||
0aef64d7 | 467 | pSNMPMIB->oid = cpu_to_le16((u16) FRAGTHRESH_I); |
876c9d3a | 468 | |
0aef64d7 DW |
469 | if (cmd_action == CMD_ACT_GET) { |
470 | pSNMPMIB->querytype = cpu_to_le16(CMD_ACT_GET); | |
471 | } else if (cmd_action == CMD_ACT_SET) { | |
472 | pSNMPMIB->querytype = cpu_to_le16(CMD_ACT_SET); | |
981f187b | 473 | pSNMPMIB->bufsize = cpu_to_le16(sizeof(u16)); |
876c9d3a | 474 | ulTemp = *((u32 *) pdata_buf); |
981f187b | 475 | *((__le16 *)(pSNMPMIB->value)) = |
876c9d3a MT |
476 | cpu_to_le16((u16) ulTemp); |
477 | ||
478 | } | |
479 | ||
480 | break; | |
481 | } | |
482 | ||
483 | case OID_802_11_RTS_THRESHOLD: | |
484 | { | |
485 | ||
486 | u32 ulTemp; | |
0aef64d7 | 487 | pSNMPMIB->oid = le16_to_cpu((u16) RTSTHRESH_I); |
876c9d3a | 488 | |
0aef64d7 DW |
489 | if (cmd_action == CMD_ACT_GET) { |
490 | pSNMPMIB->querytype = cpu_to_le16(CMD_ACT_GET); | |
491 | } else if (cmd_action == CMD_ACT_SET) { | |
492 | pSNMPMIB->querytype = cpu_to_le16(CMD_ACT_SET); | |
981f187b DW |
493 | pSNMPMIB->bufsize = cpu_to_le16(sizeof(u16)); |
494 | ulTemp = *((u32 *)pdata_buf); | |
495 | *(__le16 *)(pSNMPMIB->value) = | |
876c9d3a MT |
496 | cpu_to_le16((u16) ulTemp); |
497 | ||
498 | } | |
499 | break; | |
500 | } | |
501 | case OID_802_11_TX_RETRYCOUNT: | |
0aef64d7 | 502 | pSNMPMIB->oid = cpu_to_le16((u16) SHORT_RETRYLIM_I); |
876c9d3a | 503 | |
0aef64d7 DW |
504 | if (cmd_action == CMD_ACT_GET) { |
505 | pSNMPMIB->querytype = cpu_to_le16(CMD_ACT_GET); | |
506 | } else if (cmd_action == CMD_ACT_SET) { | |
507 | pSNMPMIB->querytype = cpu_to_le16(CMD_ACT_SET); | |
876c9d3a | 508 | pSNMPMIB->bufsize = cpu_to_le16(sizeof(u16)); |
981f187b | 509 | *((__le16 *)(pSNMPMIB->value)) = |
876c9d3a MT |
510 | cpu_to_le16((u16) adapter->txretrycount); |
511 | } | |
512 | ||
513 | break; | |
514 | default: | |
515 | break; | |
516 | } | |
517 | ||
9012b28a | 518 | lbs_deb_cmd( |
876c9d3a | 519 | "SNMP_CMD: command=0x%x, size=0x%x, seqnum=0x%x, result=0x%x\n", |
981f187b DW |
520 | le16_to_cpu(cmd->command), le16_to_cpu(cmd->size), |
521 | le16_to_cpu(cmd->seqnum), le16_to_cpu(cmd->result)); | |
876c9d3a | 522 | |
9012b28a | 523 | lbs_deb_cmd( |
8ff12da1 | 524 | "SNMP_CMD: action 0x%x, oid 0x%x, oidsize 0x%x, value 0x%x\n", |
981f187b DW |
525 | le16_to_cpu(pSNMPMIB->querytype), le16_to_cpu(pSNMPMIB->oid), |
526 | le16_to_cpu(pSNMPMIB->bufsize), | |
527 | le16_to_cpu(*(__le16 *) pSNMPMIB->value)); | |
876c9d3a | 528 | |
9012b28a | 529 | lbs_deb_leave(LBS_DEB_CMD); |
876c9d3a MT |
530 | return 0; |
531 | } | |
532 | ||
69f9032d | 533 | static int lbs_cmd_802_11_radio_control(struct lbs_private *priv, |
876c9d3a MT |
534 | struct cmd_ds_command *cmd, |
535 | int cmd_action) | |
536 | { | |
69f9032d | 537 | struct lbs_adapter *adapter = priv->adapter; |
981f187b | 538 | struct cmd_ds_802_11_radio_control *pradiocontrol = &cmd->params.radio; |
876c9d3a | 539 | |
9012b28a | 540 | lbs_deb_enter(LBS_DEB_CMD); |
876c9d3a MT |
541 | |
542 | cmd->size = | |
543 | cpu_to_le16((sizeof(struct cmd_ds_802_11_radio_control)) + | |
544 | S_DS_GEN); | |
0aef64d7 | 545 | cmd->command = cpu_to_le16(CMD_802_11_RADIO_CONTROL); |
876c9d3a MT |
546 | |
547 | pradiocontrol->action = cpu_to_le16(cmd_action); | |
548 | ||
549 | switch (adapter->preamble) { | |
0aef64d7 | 550 | case CMD_TYPE_SHORT_PREAMBLE: |
876c9d3a MT |
551 | pradiocontrol->control = cpu_to_le16(SET_SHORT_PREAMBLE); |
552 | break; | |
553 | ||
0aef64d7 | 554 | case CMD_TYPE_LONG_PREAMBLE: |
876c9d3a MT |
555 | pradiocontrol->control = cpu_to_le16(SET_LONG_PREAMBLE); |
556 | break; | |
557 | ||
0aef64d7 | 558 | case CMD_TYPE_AUTO_PREAMBLE: |
876c9d3a MT |
559 | default: |
560 | pradiocontrol->control = cpu_to_le16(SET_AUTO_PREAMBLE); | |
561 | break; | |
562 | } | |
563 | ||
564 | if (adapter->radioon) | |
565 | pradiocontrol->control |= cpu_to_le16(TURN_ON_RF); | |
566 | else | |
567 | pradiocontrol->control &= cpu_to_le16(~TURN_ON_RF); | |
568 | ||
9012b28a | 569 | lbs_deb_leave(LBS_DEB_CMD); |
876c9d3a MT |
570 | return 0; |
571 | } | |
572 | ||
69f9032d | 573 | static int lbs_cmd_802_11_rf_tx_power(struct lbs_private *priv, |
876c9d3a MT |
574 | struct cmd_ds_command *cmd, |
575 | u16 cmd_action, void *pdata_buf) | |
576 | { | |
577 | ||
578 | struct cmd_ds_802_11_rf_tx_power *prtp = &cmd->params.txp; | |
579 | ||
9012b28a | 580 | lbs_deb_enter(LBS_DEB_CMD); |
876c9d3a MT |
581 | |
582 | cmd->size = | |
981f187b | 583 | cpu_to_le16((sizeof(struct cmd_ds_802_11_rf_tx_power)) + S_DS_GEN); |
0aef64d7 | 584 | cmd->command = cpu_to_le16(CMD_802_11_RF_TX_POWER); |
981f187b | 585 | prtp->action = cpu_to_le16(cmd_action); |
876c9d3a | 586 | |
981f187b DW |
587 | lbs_deb_cmd("RF_TX_POWER_CMD: size:%d cmd:0x%x Act:%d\n", |
588 | le16_to_cpu(cmd->size), le16_to_cpu(cmd->command), | |
589 | le16_to_cpu(prtp->action)); | |
876c9d3a MT |
590 | |
591 | switch (cmd_action) { | |
0aef64d7 DW |
592 | case CMD_ACT_TX_POWER_OPT_GET: |
593 | prtp->action = cpu_to_le16(CMD_ACT_GET); | |
876c9d3a MT |
594 | prtp->currentlevel = 0; |
595 | break; | |
596 | ||
0aef64d7 DW |
597 | case CMD_ACT_TX_POWER_OPT_SET_HIGH: |
598 | prtp->action = cpu_to_le16(CMD_ACT_SET); | |
599 | prtp->currentlevel = cpu_to_le16(CMD_ACT_TX_POWER_INDEX_HIGH); | |
876c9d3a MT |
600 | break; |
601 | ||
0aef64d7 DW |
602 | case CMD_ACT_TX_POWER_OPT_SET_MID: |
603 | prtp->action = cpu_to_le16(CMD_ACT_SET); | |
604 | prtp->currentlevel = cpu_to_le16(CMD_ACT_TX_POWER_INDEX_MID); | |
876c9d3a MT |
605 | break; |
606 | ||
0aef64d7 DW |
607 | case CMD_ACT_TX_POWER_OPT_SET_LOW: |
608 | prtp->action = cpu_to_le16(CMD_ACT_SET); | |
876c9d3a MT |
609 | prtp->currentlevel = cpu_to_le16(*((u16 *) pdata_buf)); |
610 | break; | |
611 | } | |
9012b28a HS |
612 | |
613 | lbs_deb_leave(LBS_DEB_CMD); | |
876c9d3a MT |
614 | return 0; |
615 | } | |
616 | ||
69f9032d | 617 | static int lbs_cmd_802_11_monitor_mode(struct lbs_private *priv, |
965f8bbc LCC |
618 | struct cmd_ds_command *cmd, |
619 | u16 cmd_action, void *pdata_buf) | |
620 | { | |
621 | struct cmd_ds_802_11_monitor_mode *monitor = &cmd->params.monitor; | |
622 | ||
623 | cmd->command = cpu_to_le16(CMD_802_11_MONITOR_MODE); | |
624 | cmd->size = | |
625 | cpu_to_le16(sizeof(struct cmd_ds_802_11_monitor_mode) + | |
626 | S_DS_GEN); | |
627 | ||
628 | monitor->action = cpu_to_le16(cmd_action); | |
629 | if (cmd_action == CMD_ACT_SET) { | |
630 | monitor->mode = | |
631 | cpu_to_le16((u16) (*(u32 *) pdata_buf)); | |
632 | } | |
633 | ||
634 | return 0; | |
635 | } | |
636 | ||
69f9032d | 637 | static int lbs_cmd_802_11_rate_adapt_rateset(struct lbs_private *priv, |
876c9d3a MT |
638 | struct cmd_ds_command *cmd, |
639 | u16 cmd_action) | |
640 | { | |
641 | struct cmd_ds_802_11_rate_adapt_rateset | |
642 | *rateadapt = &cmd->params.rateset; | |
69f9032d | 643 | struct lbs_adapter *adapter = priv->adapter; |
876c9d3a | 644 | |
8ff12da1 | 645 | lbs_deb_enter(LBS_DEB_CMD); |
876c9d3a MT |
646 | cmd->size = |
647 | cpu_to_le16(sizeof(struct cmd_ds_802_11_rate_adapt_rateset) | |
648 | + S_DS_GEN); | |
0aef64d7 | 649 | cmd->command = cpu_to_le16(CMD_802_11_RATE_ADAPT_RATESET); |
876c9d3a | 650 | |
981f187b DW |
651 | rateadapt->action = cpu_to_le16(cmd_action); |
652 | rateadapt->enablehwauto = cpu_to_le16(adapter->enablehwauto); | |
653 | rateadapt->bitmap = cpu_to_le16(adapter->ratebitmap); | |
876c9d3a | 654 | |
9012b28a | 655 | lbs_deb_leave(LBS_DEB_CMD); |
876c9d3a MT |
656 | return 0; |
657 | } | |
658 | ||
69f9032d | 659 | static int lbs_cmd_802_11_data_rate(struct lbs_private *priv, |
876c9d3a MT |
660 | struct cmd_ds_command *cmd, |
661 | u16 cmd_action) | |
662 | { | |
663 | struct cmd_ds_802_11_data_rate *pdatarate = &cmd->params.drate; | |
69f9032d | 664 | struct lbs_adapter *adapter = priv->adapter; |
876c9d3a | 665 | |
9012b28a | 666 | lbs_deb_enter(LBS_DEB_CMD); |
876c9d3a | 667 | |
981f187b | 668 | cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_data_rate) + |
876c9d3a | 669 | S_DS_GEN); |
0aef64d7 | 670 | cmd->command = cpu_to_le16(CMD_802_11_DATA_RATE); |
876c9d3a | 671 | memset(pdatarate, 0, sizeof(struct cmd_ds_802_11_data_rate)); |
876c9d3a MT |
672 | pdatarate->action = cpu_to_le16(cmd_action); |
673 | ||
ffcae953 | 674 | if (cmd_action == CMD_ACT_SET_TX_FIX_RATE) { |
10078321 | 675 | pdatarate->rates[0] = lbs_data_rate_to_fw_index(adapter->cur_rate); |
8ff12da1 | 676 | lbs_deb_cmd("DATA_RATE: set fixed 0x%02X\n", |
8c512765 | 677 | adapter->cur_rate); |
ffcae953 | 678 | } else if (cmd_action == CMD_ACT_SET_TX_AUTO) { |
8ff12da1 | 679 | lbs_deb_cmd("DATA_RATE: setting auto\n"); |
876c9d3a MT |
680 | } |
681 | ||
9012b28a | 682 | lbs_deb_leave(LBS_DEB_CMD); |
876c9d3a MT |
683 | return 0; |
684 | } | |
685 | ||
69f9032d | 686 | static int lbs_cmd_mac_multicast_adr(struct lbs_private *priv, |
876c9d3a MT |
687 | struct cmd_ds_command *cmd, |
688 | u16 cmd_action) | |
689 | { | |
690 | struct cmd_ds_mac_multicast_adr *pMCastAdr = &cmd->params.madr; | |
69f9032d | 691 | struct lbs_adapter *adapter = priv->adapter; |
876c9d3a | 692 | |
8ff12da1 | 693 | lbs_deb_enter(LBS_DEB_CMD); |
981f187b | 694 | cmd->size = cpu_to_le16(sizeof(struct cmd_ds_mac_multicast_adr) + |
876c9d3a | 695 | S_DS_GEN); |
0aef64d7 | 696 | cmd->command = cpu_to_le16(CMD_MAC_MULTICAST_ADR); |
876c9d3a | 697 | |
8ff12da1 | 698 | lbs_deb_cmd("MULTICAST_ADR: setting %d addresses\n", pMCastAdr->nr_of_adrs); |
876c9d3a MT |
699 | pMCastAdr->action = cpu_to_le16(cmd_action); |
700 | pMCastAdr->nr_of_adrs = | |
701 | cpu_to_le16((u16) adapter->nr_of_multicastmacaddr); | |
702 | memcpy(pMCastAdr->maclist, adapter->multicastlist, | |
703 | adapter->nr_of_multicastmacaddr * ETH_ALEN); | |
704 | ||
8ff12da1 | 705 | lbs_deb_leave(LBS_DEB_CMD); |
876c9d3a MT |
706 | return 0; |
707 | } | |
708 | ||
69f9032d | 709 | static int lbs_cmd_802_11_rf_channel(struct lbs_private *priv, |
876c9d3a MT |
710 | struct cmd_ds_command *cmd, |
711 | int option, void *pdata_buf) | |
712 | { | |
713 | struct cmd_ds_802_11_rf_channel *rfchan = &cmd->params.rfchannel; | |
714 | ||
8ff12da1 | 715 | lbs_deb_enter(LBS_DEB_CMD); |
0aef64d7 | 716 | cmd->command = cpu_to_le16(CMD_802_11_RF_CHANNEL); |
981f187b DW |
717 | cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_rf_channel) + |
718 | S_DS_GEN); | |
876c9d3a | 719 | |
0aef64d7 | 720 | if (option == CMD_OPT_802_11_RF_CHANNEL_SET) { |
876c9d3a MT |
721 | rfchan->currentchannel = cpu_to_le16(*((u16 *) pdata_buf)); |
722 | } | |
723 | ||
724 | rfchan->action = cpu_to_le16(option); | |
725 | ||
8ff12da1 | 726 | lbs_deb_leave(LBS_DEB_CMD); |
876c9d3a MT |
727 | return 0; |
728 | } | |
729 | ||
69f9032d | 730 | static int lbs_cmd_802_11_rssi(struct lbs_private *priv, |
876c9d3a MT |
731 | struct cmd_ds_command *cmd) |
732 | { | |
69f9032d | 733 | struct lbs_adapter *adapter = priv->adapter; |
876c9d3a | 734 | |
8ff12da1 | 735 | lbs_deb_enter(LBS_DEB_CMD); |
0aef64d7 | 736 | cmd->command = cpu_to_le16(CMD_802_11_RSSI); |
981f187b | 737 | cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_rssi) + S_DS_GEN); |
a783f1ee | 738 | cmd->params.rssi.N = cpu_to_le16(DEFAULT_BCN_AVG_FACTOR); |
876c9d3a MT |
739 | |
740 | /* reset Beacon SNR/NF/RSSI values */ | |
741 | adapter->SNR[TYPE_BEACON][TYPE_NOAVG] = 0; | |
742 | adapter->SNR[TYPE_BEACON][TYPE_AVG] = 0; | |
743 | adapter->NF[TYPE_BEACON][TYPE_NOAVG] = 0; | |
744 | adapter->NF[TYPE_BEACON][TYPE_AVG] = 0; | |
745 | adapter->RSSI[TYPE_BEACON][TYPE_NOAVG] = 0; | |
746 | adapter->RSSI[TYPE_BEACON][TYPE_AVG] = 0; | |
747 | ||
8ff12da1 | 748 | lbs_deb_leave(LBS_DEB_CMD); |
876c9d3a MT |
749 | return 0; |
750 | } | |
751 | ||
69f9032d | 752 | static int lbs_cmd_reg_access(struct lbs_private *priv, |
876c9d3a MT |
753 | struct cmd_ds_command *cmdptr, |
754 | u8 cmd_action, void *pdata_buf) | |
755 | { | |
10078321 | 756 | struct lbs_offset_value *offval; |
876c9d3a | 757 | |
9012b28a | 758 | lbs_deb_enter(LBS_DEB_CMD); |
876c9d3a | 759 | |
10078321 | 760 | offval = (struct lbs_offset_value *)pdata_buf; |
876c9d3a MT |
761 | |
762 | switch (cmdptr->command) { | |
0aef64d7 | 763 | case CMD_MAC_REG_ACCESS: |
876c9d3a MT |
764 | { |
765 | struct cmd_ds_mac_reg_access *macreg; | |
766 | ||
767 | cmdptr->size = | |
981f187b DW |
768 | cpu_to_le16(sizeof (struct cmd_ds_mac_reg_access) |
769 | + S_DS_GEN); | |
876c9d3a MT |
770 | macreg = |
771 | (struct cmd_ds_mac_reg_access *)&cmdptr->params. | |
772 | macreg; | |
773 | ||
774 | macreg->action = cpu_to_le16(cmd_action); | |
775 | macreg->offset = cpu_to_le16((u16) offval->offset); | |
776 | macreg->value = cpu_to_le32(offval->value); | |
777 | ||
778 | break; | |
779 | } | |
780 | ||
0aef64d7 | 781 | case CMD_BBP_REG_ACCESS: |
876c9d3a MT |
782 | { |
783 | struct cmd_ds_bbp_reg_access *bbpreg; | |
784 | ||
785 | cmdptr->size = | |
786 | cpu_to_le16(sizeof | |
787 | (struct cmd_ds_bbp_reg_access) | |
788 | + S_DS_GEN); | |
789 | bbpreg = | |
790 | (struct cmd_ds_bbp_reg_access *)&cmdptr->params. | |
791 | bbpreg; | |
792 | ||
793 | bbpreg->action = cpu_to_le16(cmd_action); | |
794 | bbpreg->offset = cpu_to_le16((u16) offval->offset); | |
795 | bbpreg->value = (u8) offval->value; | |
796 | ||
797 | break; | |
798 | } | |
799 | ||
0aef64d7 | 800 | case CMD_RF_REG_ACCESS: |
876c9d3a MT |
801 | { |
802 | struct cmd_ds_rf_reg_access *rfreg; | |
803 | ||
804 | cmdptr->size = | |
805 | cpu_to_le16(sizeof | |
806 | (struct cmd_ds_rf_reg_access) + | |
807 | S_DS_GEN); | |
808 | rfreg = | |
809 | (struct cmd_ds_rf_reg_access *)&cmdptr->params. | |
810 | rfreg; | |
811 | ||
812 | rfreg->action = cpu_to_le16(cmd_action); | |
813 | rfreg->offset = cpu_to_le16((u16) offval->offset); | |
814 | rfreg->value = (u8) offval->value; | |
815 | ||
816 | break; | |
817 | } | |
818 | ||
819 | default: | |
820 | break; | |
821 | } | |
822 | ||
9012b28a | 823 | lbs_deb_leave(LBS_DEB_CMD); |
876c9d3a MT |
824 | return 0; |
825 | } | |
826 | ||
69f9032d | 827 | static int lbs_cmd_802_11_mac_address(struct lbs_private *priv, |
876c9d3a MT |
828 | struct cmd_ds_command *cmd, |
829 | u16 cmd_action) | |
830 | { | |
69f9032d | 831 | struct lbs_adapter *adapter = priv->adapter; |
876c9d3a | 832 | |
8ff12da1 | 833 | lbs_deb_enter(LBS_DEB_CMD); |
0aef64d7 | 834 | cmd->command = cpu_to_le16(CMD_802_11_MAC_ADDRESS); |
981f187b | 835 | cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_mac_address) + |
876c9d3a MT |
836 | S_DS_GEN); |
837 | cmd->result = 0; | |
838 | ||
839 | cmd->params.macadd.action = cpu_to_le16(cmd_action); | |
840 | ||
0aef64d7 | 841 | if (cmd_action == CMD_ACT_SET) { |
876c9d3a MT |
842 | memcpy(cmd->params.macadd.macadd, |
843 | adapter->current_addr, ETH_ALEN); | |
ece56191 | 844 | lbs_deb_hex(LBS_DEB_CMD, "SET_CMD: MAC addr", adapter->current_addr, 6); |
876c9d3a MT |
845 | } |
846 | ||
8ff12da1 | 847 | lbs_deb_leave(LBS_DEB_CMD); |
876c9d3a MT |
848 | return 0; |
849 | } | |
850 | ||
69f9032d | 851 | static int lbs_cmd_802_11_eeprom_access(struct lbs_private *priv, |
876c9d3a MT |
852 | struct cmd_ds_command *cmd, |
853 | int cmd_action, void *pdata_buf) | |
854 | { | |
10078321 | 855 | struct lbs_ioctl_regrdwr *ea = pdata_buf; |
876c9d3a | 856 | |
9012b28a | 857 | lbs_deb_enter(LBS_DEB_CMD); |
876c9d3a | 858 | |
0aef64d7 | 859 | cmd->command = cpu_to_le16(CMD_802_11_EEPROM_ACCESS); |
981f187b DW |
860 | cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_eeprom_access) + |
861 | S_DS_GEN); | |
876c9d3a MT |
862 | cmd->result = 0; |
863 | ||
864 | cmd->params.rdeeprom.action = cpu_to_le16(ea->action); | |
865 | cmd->params.rdeeprom.offset = cpu_to_le16(ea->offset); | |
866 | cmd->params.rdeeprom.bytecount = cpu_to_le16(ea->NOB); | |
867 | cmd->params.rdeeprom.value = 0; | |
868 | ||
8ff12da1 | 869 | lbs_deb_leave(LBS_DEB_CMD); |
876c9d3a MT |
870 | return 0; |
871 | } | |
872 | ||
69f9032d | 873 | static int lbs_cmd_bt_access(struct lbs_private *priv, |
876c9d3a MT |
874 | struct cmd_ds_command *cmd, |
875 | u16 cmd_action, void *pdata_buf) | |
876 | { | |
877 | struct cmd_ds_bt_access *bt_access = &cmd->params.bt; | |
8ff12da1 | 878 | lbs_deb_enter_args(LBS_DEB_CMD, "action %d", cmd_action); |
876c9d3a | 879 | |
0aef64d7 | 880 | cmd->command = cpu_to_le16(CMD_BT_ACCESS); |
981f187b | 881 | cmd->size = cpu_to_le16(sizeof(struct cmd_ds_bt_access) + S_DS_GEN); |
876c9d3a MT |
882 | cmd->result = 0; |
883 | bt_access->action = cpu_to_le16(cmd_action); | |
884 | ||
885 | switch (cmd_action) { | |
0aef64d7 | 886 | case CMD_ACT_BT_ACCESS_ADD: |
876c9d3a | 887 | memcpy(bt_access->addr1, pdata_buf, 2 * ETH_ALEN); |
ece56191 | 888 | lbs_deb_hex(LBS_DEB_MESH, "BT_ADD: blinded MAC addr", bt_access->addr1, 6); |
876c9d3a | 889 | break; |
0aef64d7 | 890 | case CMD_ACT_BT_ACCESS_DEL: |
876c9d3a | 891 | memcpy(bt_access->addr1, pdata_buf, 1 * ETH_ALEN); |
ece56191 | 892 | lbs_deb_hex(LBS_DEB_MESH, "BT_DEL: blinded MAC addr", bt_access->addr1, 6); |
876c9d3a | 893 | break; |
0aef64d7 | 894 | case CMD_ACT_BT_ACCESS_LIST: |
876c9d3a MT |
895 | bt_access->id = cpu_to_le32(*(u32 *) pdata_buf); |
896 | break; | |
0aef64d7 | 897 | case CMD_ACT_BT_ACCESS_RESET: |
876c9d3a | 898 | break; |
0aef64d7 | 899 | case CMD_ACT_BT_ACCESS_SET_INVERT: |
90e8eafc LCC |
900 | bt_access->id = cpu_to_le32(*(u32 *) pdata_buf); |
901 | break; | |
0aef64d7 | 902 | case CMD_ACT_BT_ACCESS_GET_INVERT: |
90e8eafc | 903 | break; |
876c9d3a MT |
904 | default: |
905 | break; | |
906 | } | |
8ff12da1 | 907 | lbs_deb_leave(LBS_DEB_CMD); |
876c9d3a MT |
908 | return 0; |
909 | } | |
910 | ||
69f9032d | 911 | static int lbs_cmd_fwt_access(struct lbs_private *priv, |
876c9d3a MT |
912 | struct cmd_ds_command *cmd, |
913 | u16 cmd_action, void *pdata_buf) | |
914 | { | |
915 | struct cmd_ds_fwt_access *fwt_access = &cmd->params.fwt; | |
8ff12da1 | 916 | lbs_deb_enter_args(LBS_DEB_CMD, "action %d", cmd_action); |
876c9d3a | 917 | |
0aef64d7 | 918 | cmd->command = cpu_to_le16(CMD_FWT_ACCESS); |
981f187b | 919 | cmd->size = cpu_to_le16(sizeof(struct cmd_ds_fwt_access) + S_DS_GEN); |
876c9d3a MT |
920 | cmd->result = 0; |
921 | ||
922 | if (pdata_buf) | |
923 | memcpy(fwt_access, pdata_buf, sizeof(*fwt_access)); | |
924 | else | |
925 | memset(fwt_access, 0, sizeof(*fwt_access)); | |
926 | ||
927 | fwt_access->action = cpu_to_le16(cmd_action); | |
928 | ||
8ff12da1 | 929 | lbs_deb_leave(LBS_DEB_CMD); |
876c9d3a MT |
930 | return 0; |
931 | } | |
932 | ||
69f9032d | 933 | static int lbs_cmd_mesh_access(struct lbs_private *priv, |
876c9d3a MT |
934 | struct cmd_ds_command *cmd, |
935 | u16 cmd_action, void *pdata_buf) | |
936 | { | |
937 | struct cmd_ds_mesh_access *mesh_access = &cmd->params.mesh; | |
8ff12da1 | 938 | lbs_deb_enter_args(LBS_DEB_CMD, "action %d", cmd_action); |
876c9d3a | 939 | |
0aef64d7 | 940 | cmd->command = cpu_to_le16(CMD_MESH_ACCESS); |
981f187b | 941 | cmd->size = cpu_to_le16(sizeof(struct cmd_ds_mesh_access) + S_DS_GEN); |
876c9d3a MT |
942 | cmd->result = 0; |
943 | ||
944 | if (pdata_buf) | |
945 | memcpy(mesh_access, pdata_buf, sizeof(*mesh_access)); | |
946 | else | |
947 | memset(mesh_access, 0, sizeof(*mesh_access)); | |
948 | ||
949 | mesh_access->action = cpu_to_le16(cmd_action); | |
950 | ||
8ff12da1 | 951 | lbs_deb_leave(LBS_DEB_CMD); |
876c9d3a MT |
952 | return 0; |
953 | } | |
954 | ||
96287ac4 BD |
955 | static int lbs_cmd_bcn_ctrl(struct lbs_private * priv, |
956 | struct cmd_ds_command *cmd, | |
957 | u16 cmd_action) | |
958 | { | |
959 | struct cmd_ds_802_11_beacon_control | |
960 | *bcn_ctrl = &cmd->params.bcn_ctrl; | |
961 | struct lbs_adapter *adapter = priv->adapter; | |
962 | ||
963 | lbs_deb_enter(LBS_DEB_CMD); | |
964 | cmd->size = | |
965 | cpu_to_le16(sizeof(struct cmd_ds_802_11_beacon_control) | |
966 | + S_DS_GEN); | |
967 | cmd->command = cpu_to_le16(CMD_802_11_BEACON_CTRL); | |
968 | ||
969 | bcn_ctrl->action = cpu_to_le16(cmd_action); | |
970 | bcn_ctrl->beacon_enable = cpu_to_le16(adapter->beacon_enable); | |
971 | bcn_ctrl->beacon_period = cpu_to_le16(adapter->beacon_period); | |
972 | ||
973 | lbs_deb_leave(LBS_DEB_CMD); | |
974 | return 0; | |
975 | } | |
976 | ||
69f9032d | 977 | static int lbs_cmd_set_boot2_ver(struct lbs_private *priv, |
63f0023b LCC |
978 | struct cmd_ds_command *cmd, |
979 | u16 cmd_action, void *pdata_buf) | |
980 | { | |
981 | struct cmd_ds_set_boot2_ver *boot2_ver = &cmd->params.boot2_ver; | |
982 | cmd->command = cpu_to_le16(CMD_SET_BOOT2_VER); | |
983 | cmd->size = cpu_to_le16(sizeof(struct cmd_ds_set_boot2_ver) + S_DS_GEN); | |
984 | boot2_ver->version = priv->boot2_version; | |
985 | return 0; | |
986 | } | |
987 | ||
29f5f2a1 | 988 | /* |
10078321 | 989 | * Note: NEVER use lbs_queue_cmd() with addtail==0 other than for |
29f5f2a1 MT |
990 | * the command timer, because it does not account for queued commands. |
991 | */ | |
69f9032d HS |
992 | void lbs_queue_cmd(struct lbs_adapter *adapter, |
993 | struct cmd_ctrl_node *cmdnode, | |
994 | u8 addtail) | |
876c9d3a MT |
995 | { |
996 | unsigned long flags; | |
997 | struct cmd_ds_command *cmdptr; | |
998 | ||
8ff12da1 | 999 | lbs_deb_enter(LBS_DEB_HOST); |
876c9d3a MT |
1000 | |
1001 | if (!cmdnode) { | |
8ff12da1 | 1002 | lbs_deb_host("QUEUE_CMD: cmdnode is NULL\n"); |
876c9d3a MT |
1003 | goto done; |
1004 | } | |
1005 | ||
1006 | cmdptr = (struct cmd_ds_command *)cmdnode->bufvirtualaddr; | |
1007 | if (!cmdptr) { | |
8ff12da1 | 1008 | lbs_deb_host("QUEUE_CMD: cmdptr is NULL\n"); |
876c9d3a MT |
1009 | goto done; |
1010 | } | |
1011 | ||
1012 | /* Exit_PS command needs to be queued in the header always. */ | |
0aef64d7 | 1013 | if (cmdptr->command == CMD_802_11_PS_MODE) { |
876c9d3a | 1014 | struct cmd_ds_802_11_ps_mode *psm = &cmdptr->params.psmode; |
0aef64d7 | 1015 | if (psm->action == cpu_to_le16(CMD_SUBCMD_EXIT_PS)) { |
876c9d3a MT |
1016 | if (adapter->psstate != PS_STATE_FULL_POWER) |
1017 | addtail = 0; | |
1018 | } | |
1019 | } | |
1020 | ||
1021 | spin_lock_irqsave(&adapter->driver_lock, flags); | |
1022 | ||
29f5f2a1 | 1023 | if (addtail) { |
876c9d3a MT |
1024 | list_add_tail((struct list_head *)cmdnode, |
1025 | &adapter->cmdpendingq); | |
29f5f2a1 MT |
1026 | adapter->nr_cmd_pending++; |
1027 | } else | |
876c9d3a MT |
1028 | list_add((struct list_head *)cmdnode, &adapter->cmdpendingq); |
1029 | ||
1030 | spin_unlock_irqrestore(&adapter->driver_lock, flags); | |
1031 | ||
8ff12da1 | 1032 | lbs_deb_host("QUEUE_CMD: inserted command 0x%04x into cmdpendingq\n", |
981f187b | 1033 | le16_to_cpu(((struct cmd_ds_gen*)cmdnode->bufvirtualaddr)->command)); |
876c9d3a MT |
1034 | |
1035 | done: | |
8ff12da1 | 1036 | lbs_deb_leave(LBS_DEB_HOST); |
876c9d3a MT |
1037 | } |
1038 | ||
1039 | /* | |
1040 | * TODO: Fix the issue when DownloadcommandToStation is being called the | |
8ff12da1 | 1041 | * second time when the command times out. All the cmdptr->xxx are in little |
876c9d3a MT |
1042 | * endian and therefore all the comparissions will fail. |
1043 | * For now - we are not performing the endian conversion the second time - but | |
1044 | * for PS and DEEP_SLEEP we need to worry | |
1045 | */ | |
69f9032d | 1046 | static int DownloadcommandToStation(struct lbs_private *priv, |
876c9d3a MT |
1047 | struct cmd_ctrl_node *cmdnode) |
1048 | { | |
1049 | unsigned long flags; | |
1050 | struct cmd_ds_command *cmdptr; | |
69f9032d | 1051 | struct lbs_adapter *adapter = priv->adapter; |
b031ac10 | 1052 | int ret = -1; |
876c9d3a MT |
1053 | u16 cmdsize; |
1054 | u16 command; | |
1055 | ||
8ff12da1 | 1056 | lbs_deb_enter(LBS_DEB_HOST); |
876c9d3a MT |
1057 | |
1058 | if (!adapter || !cmdnode) { | |
8ff12da1 | 1059 | lbs_deb_host("DNLD_CMD: adapter or cmdmode is NULL\n"); |
876c9d3a MT |
1060 | goto done; |
1061 | } | |
1062 | ||
1063 | cmdptr = (struct cmd_ds_command *)cmdnode->bufvirtualaddr; | |
1064 | ||
876c9d3a MT |
1065 | spin_lock_irqsave(&adapter->driver_lock, flags); |
1066 | if (!cmdptr || !cmdptr->size) { | |
8ff12da1 | 1067 | lbs_deb_host("DNLD_CMD: cmdptr is NULL or zero\n"); |
10078321 | 1068 | __lbs_cleanup_and_insert_cmd(priv, cmdnode); |
876c9d3a | 1069 | spin_unlock_irqrestore(&adapter->driver_lock, flags); |
876c9d3a MT |
1070 | goto done; |
1071 | } | |
1072 | ||
1073 | adapter->cur_cmd = cmdnode; | |
1074 | adapter->cur_cmd_retcode = 0; | |
1075 | spin_unlock_irqrestore(&adapter->driver_lock, flags); | |
876c9d3a MT |
1076 | |
1077 | cmdsize = cmdptr->size; | |
876c9d3a MT |
1078 | command = cpu_to_le16(cmdptr->command); |
1079 | ||
8ff12da1 HS |
1080 | lbs_deb_host("DNLD_CMD: command 0x%04x, size %d, jiffies %lu\n", |
1081 | command, le16_to_cpu(cmdptr->size), jiffies); | |
1082 | lbs_deb_hex(LBS_DEB_HOST, "DNLD_CMD", cmdnode->bufvirtualaddr, cmdsize); | |
1083 | ||
876c9d3a MT |
1084 | cmdnode->cmdwaitqwoken = 0; |
1085 | cmdsize = cpu_to_le16(cmdsize); | |
1086 | ||
208fdd2f | 1087 | ret = priv->hw_host_to_card(priv, MVMS_CMD, (u8 *) cmdptr, cmdsize); |
876c9d3a MT |
1088 | |
1089 | if (ret != 0) { | |
8ff12da1 | 1090 | lbs_deb_host("DNLD_CMD: hw_host_to_card failed\n"); |
876c9d3a | 1091 | spin_lock_irqsave(&adapter->driver_lock, flags); |
794760f7 | 1092 | adapter->cur_cmd_retcode = ret; |
10078321 | 1093 | __lbs_cleanup_and_insert_cmd(priv, adapter->cur_cmd); |
794760f7 | 1094 | adapter->nr_cmd_pending--; |
876c9d3a MT |
1095 | adapter->cur_cmd = NULL; |
1096 | spin_unlock_irqrestore(&adapter->driver_lock, flags); | |
876c9d3a MT |
1097 | goto done; |
1098 | } | |
1099 | ||
8ff12da1 | 1100 | lbs_deb_cmd("DNLD_CMD: sent command 0x%04x, jiffies %lu\n", command, jiffies); |
876c9d3a MT |
1101 | |
1102 | /* Setup the timer after transmit command */ | |
0aef64d7 DW |
1103 | if (command == CMD_802_11_SCAN || command == CMD_802_11_AUTHENTICATE |
1104 | || command == CMD_802_11_ASSOCIATE) | |
876c9d3a MT |
1105 | mod_timer(&adapter->command_timer, jiffies + (10*HZ)); |
1106 | else | |
1107 | mod_timer(&adapter->command_timer, jiffies + (5*HZ)); | |
1108 | ||
1109 | ret = 0; | |
1110 | ||
9012b28a | 1111 | done: |
8ff12da1 | 1112 | lbs_deb_leave_args(LBS_DEB_HOST, "ret %d", ret); |
876c9d3a MT |
1113 | return ret; |
1114 | } | |
1115 | ||
69f9032d | 1116 | static int lbs_cmd_mac_control(struct lbs_private *priv, |
876c9d3a MT |
1117 | struct cmd_ds_command *cmd) |
1118 | { | |
1119 | struct cmd_ds_mac_control *mac = &cmd->params.macctrl; | |
1120 | ||
9012b28a | 1121 | lbs_deb_enter(LBS_DEB_CMD); |
876c9d3a | 1122 | |
0aef64d7 | 1123 | cmd->command = cpu_to_le16(CMD_MAC_CONTROL); |
981f187b | 1124 | cmd->size = cpu_to_le16(sizeof(struct cmd_ds_mac_control) + S_DS_GEN); |
876c9d3a MT |
1125 | mac->action = cpu_to_le16(priv->adapter->currentpacketfilter); |
1126 | ||
8ff12da1 | 1127 | lbs_deb_cmd("MAC_CONTROL: action 0x%x, size %d\n", |
981f187b | 1128 | le16_to_cpu(mac->action), le16_to_cpu(cmd->size)); |
876c9d3a | 1129 | |
9012b28a | 1130 | lbs_deb_leave(LBS_DEB_CMD); |
876c9d3a MT |
1131 | return 0; |
1132 | } | |
1133 | ||
1134 | /** | |
1135 | * This function inserts command node to cmdfreeq | |
1136 | * after cleans it. Requires adapter->driver_lock held. | |
1137 | */ | |
69f9032d HS |
1138 | void __lbs_cleanup_and_insert_cmd(struct lbs_private *priv, |
1139 | struct cmd_ctrl_node *ptempcmd) | |
876c9d3a | 1140 | { |
69f9032d | 1141 | struct lbs_adapter *adapter = priv->adapter; |
876c9d3a MT |
1142 | |
1143 | if (!ptempcmd) | |
8ff12da1 | 1144 | return; |
876c9d3a MT |
1145 | |
1146 | cleanup_cmdnode(ptempcmd); | |
1147 | list_add_tail((struct list_head *)ptempcmd, &adapter->cmdfreeq); | |
876c9d3a MT |
1148 | } |
1149 | ||
69f9032d HS |
1150 | static void lbs_cleanup_and_insert_cmd(struct lbs_private *priv, |
1151 | struct cmd_ctrl_node *ptempcmd) | |
876c9d3a MT |
1152 | { |
1153 | unsigned long flags; | |
1154 | ||
1155 | spin_lock_irqsave(&priv->adapter->driver_lock, flags); | |
10078321 | 1156 | __lbs_cleanup_and_insert_cmd(priv, ptempcmd); |
876c9d3a MT |
1157 | spin_unlock_irqrestore(&priv->adapter->driver_lock, flags); |
1158 | } | |
1159 | ||
69f9032d | 1160 | int lbs_set_radio_control(struct lbs_private *priv) |
876c9d3a MT |
1161 | { |
1162 | int ret = 0; | |
1163 | ||
9012b28a | 1164 | lbs_deb_enter(LBS_DEB_CMD); |
876c9d3a | 1165 | |
10078321 | 1166 | ret = lbs_prepare_and_send_command(priv, |
0aef64d7 DW |
1167 | CMD_802_11_RADIO_CONTROL, |
1168 | CMD_ACT_SET, | |
1169 | CMD_OPTION_WAITFORRSP, 0, NULL); | |
876c9d3a | 1170 | |
8ff12da1 | 1171 | lbs_deb_cmd("RADIO_SET: radio %d, preamble %d\n", |
876c9d3a MT |
1172 | priv->adapter->radioon, priv->adapter->preamble); |
1173 | ||
9012b28a | 1174 | lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret); |
876c9d3a MT |
1175 | return ret; |
1176 | } | |
1177 | ||
69f9032d | 1178 | int lbs_set_mac_packet_filter(struct lbs_private *priv) |
876c9d3a MT |
1179 | { |
1180 | int ret = 0; | |
1181 | ||
9012b28a | 1182 | lbs_deb_enter(LBS_DEB_CMD); |
876c9d3a | 1183 | |
876c9d3a | 1184 | /* Send MAC control command to station */ |
10078321 | 1185 | ret = lbs_prepare_and_send_command(priv, |
0aef64d7 | 1186 | CMD_MAC_CONTROL, 0, 0, 0, NULL); |
876c9d3a | 1187 | |
9012b28a | 1188 | lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret); |
876c9d3a MT |
1189 | return ret; |
1190 | } | |
1191 | ||
1192 | /** | |
1193 | * @brief This function prepare the command before send to firmware. | |
1194 | * | |
69f9032d | 1195 | * @param priv A pointer to struct lbs_private structure |
876c9d3a MT |
1196 | * @param cmd_no command number |
1197 | * @param cmd_action command action: GET or SET | |
1198 | * @param wait_option wait option: wait response or not | |
1199 | * @param cmd_oid cmd oid: treated as sub command | |
1200 | * @param pdata_buf A pointer to informaion buffer | |
1201 | * @return 0 or -1 | |
1202 | */ | |
69f9032d | 1203 | int lbs_prepare_and_send_command(struct lbs_private *priv, |
876c9d3a MT |
1204 | u16 cmd_no, |
1205 | u16 cmd_action, | |
1206 | u16 wait_option, u32 cmd_oid, void *pdata_buf) | |
1207 | { | |
1208 | int ret = 0; | |
69f9032d | 1209 | struct lbs_adapter *adapter = priv->adapter; |
876c9d3a MT |
1210 | struct cmd_ctrl_node *cmdnode; |
1211 | struct cmd_ds_command *cmdptr; | |
1212 | unsigned long flags; | |
1213 | ||
8ff12da1 | 1214 | lbs_deb_enter(LBS_DEB_HOST); |
876c9d3a MT |
1215 | |
1216 | if (!adapter) { | |
8ff12da1 | 1217 | lbs_deb_host("PREP_CMD: adapter is NULL\n"); |
876c9d3a MT |
1218 | ret = -1; |
1219 | goto done; | |
1220 | } | |
1221 | ||
1222 | if (adapter->surpriseremoved) { | |
8ff12da1 | 1223 | lbs_deb_host("PREP_CMD: card removed\n"); |
876c9d3a MT |
1224 | ret = -1; |
1225 | goto done; | |
1226 | } | |
1227 | ||
0d61d042 | 1228 | cmdnode = lbs_get_cmd_ctrl_node(priv); |
876c9d3a MT |
1229 | |
1230 | if (cmdnode == NULL) { | |
8ff12da1 | 1231 | lbs_deb_host("PREP_CMD: cmdnode is NULL\n"); |
876c9d3a MT |
1232 | |
1233 | /* Wake up main thread to execute next command */ | |
fe336150 | 1234 | wake_up_interruptible(&priv->waitq); |
876c9d3a MT |
1235 | ret = -1; |
1236 | goto done; | |
1237 | } | |
1238 | ||
f5ece8fc | 1239 | lbs_set_cmd_ctrl_node(priv, cmdnode, wait_option, pdata_buf); |
876c9d3a MT |
1240 | |
1241 | cmdptr = (struct cmd_ds_command *)cmdnode->bufvirtualaddr; | |
1242 | ||
8ff12da1 | 1243 | lbs_deb_host("PREP_CMD: command 0x%04x\n", cmd_no); |
876c9d3a MT |
1244 | |
1245 | if (!cmdptr) { | |
8ff12da1 | 1246 | lbs_deb_host("PREP_CMD: cmdptr is NULL\n"); |
10078321 | 1247 | lbs_cleanup_and_insert_cmd(priv, cmdnode); |
876c9d3a MT |
1248 | ret = -1; |
1249 | goto done; | |
1250 | } | |
1251 | ||
1252 | /* Set sequence number, command and INT option */ | |
1253 | adapter->seqnum++; | |
1254 | cmdptr->seqnum = cpu_to_le16(adapter->seqnum); | |
1255 | ||
981f187b | 1256 | cmdptr->command = cpu_to_le16(cmd_no); |
876c9d3a MT |
1257 | cmdptr->result = 0; |
1258 | ||
1259 | switch (cmd_no) { | |
0aef64d7 | 1260 | case CMD_GET_HW_SPEC: |
10078321 | 1261 | ret = lbs_cmd_hw_spec(priv, cmdptr); |
876c9d3a | 1262 | break; |
0aef64d7 | 1263 | case CMD_802_11_PS_MODE: |
10078321 | 1264 | ret = lbs_cmd_802_11_ps_mode(priv, cmdptr, cmd_action); |
876c9d3a MT |
1265 | break; |
1266 | ||
0aef64d7 | 1267 | case CMD_802_11_SCAN: |
10078321 | 1268 | ret = lbs_cmd_80211_scan(priv, cmdptr, pdata_buf); |
876c9d3a MT |
1269 | break; |
1270 | ||
0aef64d7 | 1271 | case CMD_MAC_CONTROL: |
10078321 | 1272 | ret = lbs_cmd_mac_control(priv, cmdptr); |
876c9d3a MT |
1273 | break; |
1274 | ||
0aef64d7 DW |
1275 | case CMD_802_11_ASSOCIATE: |
1276 | case CMD_802_11_REASSOCIATE: | |
10078321 | 1277 | ret = lbs_cmd_80211_associate(priv, cmdptr, pdata_buf); |
876c9d3a MT |
1278 | break; |
1279 | ||
0aef64d7 | 1280 | case CMD_802_11_DEAUTHENTICATE: |
10078321 | 1281 | ret = lbs_cmd_80211_deauthenticate(priv, cmdptr); |
876c9d3a MT |
1282 | break; |
1283 | ||
0aef64d7 | 1284 | case CMD_802_11_SET_WEP: |
10078321 | 1285 | ret = lbs_cmd_802_11_set_wep(priv, cmdptr, cmd_action, pdata_buf); |
876c9d3a MT |
1286 | break; |
1287 | ||
0aef64d7 | 1288 | case CMD_802_11_AD_HOC_START: |
10078321 | 1289 | ret = lbs_cmd_80211_ad_hoc_start(priv, cmdptr, pdata_buf); |
876c9d3a | 1290 | break; |
0aef64d7 | 1291 | case CMD_CODE_DNLD: |
876c9d3a MT |
1292 | break; |
1293 | ||
0aef64d7 | 1294 | case CMD_802_11_RESET: |
10078321 | 1295 | ret = lbs_cmd_802_11_reset(priv, cmdptr, cmd_action); |
876c9d3a MT |
1296 | break; |
1297 | ||
0aef64d7 | 1298 | case CMD_802_11_GET_LOG: |
10078321 | 1299 | ret = lbs_cmd_802_11_get_log(priv, cmdptr); |
876c9d3a MT |
1300 | break; |
1301 | ||
0aef64d7 | 1302 | case CMD_802_11_AUTHENTICATE: |
10078321 | 1303 | ret = lbs_cmd_80211_authenticate(priv, cmdptr, pdata_buf); |
876c9d3a MT |
1304 | break; |
1305 | ||
0aef64d7 | 1306 | case CMD_802_11_GET_STAT: |
10078321 | 1307 | ret = lbs_cmd_802_11_get_stat(priv, cmdptr); |
876c9d3a MT |
1308 | break; |
1309 | ||
0aef64d7 | 1310 | case CMD_802_11_SNMP_MIB: |
10078321 | 1311 | ret = lbs_cmd_802_11_snmp_mib(priv, cmdptr, |
876c9d3a MT |
1312 | cmd_action, cmd_oid, pdata_buf); |
1313 | break; | |
1314 | ||
0aef64d7 DW |
1315 | case CMD_MAC_REG_ACCESS: |
1316 | case CMD_BBP_REG_ACCESS: | |
1317 | case CMD_RF_REG_ACCESS: | |
10078321 | 1318 | ret = lbs_cmd_reg_access(priv, cmdptr, cmd_action, pdata_buf); |
876c9d3a MT |
1319 | break; |
1320 | ||
0aef64d7 | 1321 | case CMD_802_11_RF_CHANNEL: |
10078321 | 1322 | ret = lbs_cmd_802_11_rf_channel(priv, cmdptr, |
876c9d3a MT |
1323 | cmd_action, pdata_buf); |
1324 | break; | |
1325 | ||
0aef64d7 | 1326 | case CMD_802_11_RF_TX_POWER: |
10078321 | 1327 | ret = lbs_cmd_802_11_rf_tx_power(priv, cmdptr, |
876c9d3a MT |
1328 | cmd_action, pdata_buf); |
1329 | break; | |
1330 | ||
0aef64d7 | 1331 | case CMD_802_11_RADIO_CONTROL: |
10078321 | 1332 | ret = lbs_cmd_802_11_radio_control(priv, cmdptr, cmd_action); |
876c9d3a MT |
1333 | break; |
1334 | ||
0aef64d7 | 1335 | case CMD_802_11_DATA_RATE: |
10078321 | 1336 | ret = lbs_cmd_802_11_data_rate(priv, cmdptr, cmd_action); |
876c9d3a | 1337 | break; |
0aef64d7 | 1338 | case CMD_802_11_RATE_ADAPT_RATESET: |
10078321 | 1339 | ret = lbs_cmd_802_11_rate_adapt_rateset(priv, |
876c9d3a MT |
1340 | cmdptr, cmd_action); |
1341 | break; | |
1342 | ||
0aef64d7 | 1343 | case CMD_MAC_MULTICAST_ADR: |
10078321 | 1344 | ret = lbs_cmd_mac_multicast_adr(priv, cmdptr, cmd_action); |
876c9d3a MT |
1345 | break; |
1346 | ||
965f8bbc | 1347 | case CMD_802_11_MONITOR_MODE: |
10078321 | 1348 | ret = lbs_cmd_802_11_monitor_mode(priv, cmdptr, |
965f8bbc LCC |
1349 | cmd_action, pdata_buf); |
1350 | break; | |
1351 | ||
0aef64d7 | 1352 | case CMD_802_11_AD_HOC_JOIN: |
10078321 | 1353 | ret = lbs_cmd_80211_ad_hoc_join(priv, cmdptr, pdata_buf); |
876c9d3a MT |
1354 | break; |
1355 | ||
0aef64d7 | 1356 | case CMD_802_11_RSSI: |
10078321 | 1357 | ret = lbs_cmd_802_11_rssi(priv, cmdptr); |
876c9d3a MT |
1358 | break; |
1359 | ||
0aef64d7 | 1360 | case CMD_802_11_AD_HOC_STOP: |
10078321 | 1361 | ret = lbs_cmd_80211_ad_hoc_stop(priv, cmdptr); |
876c9d3a MT |
1362 | break; |
1363 | ||
0aef64d7 | 1364 | case CMD_802_11_ENABLE_RSN: |
10078321 | 1365 | ret = lbs_cmd_802_11_enable_rsn(priv, cmdptr, cmd_action, |
90a42210 | 1366 | pdata_buf); |
876c9d3a MT |
1367 | break; |
1368 | ||
0aef64d7 | 1369 | case CMD_802_11_KEY_MATERIAL: |
10078321 | 1370 | ret = lbs_cmd_802_11_key_material(priv, cmdptr, cmd_action, |
90a42210 | 1371 | cmd_oid, pdata_buf); |
876c9d3a MT |
1372 | break; |
1373 | ||
0aef64d7 | 1374 | case CMD_802_11_PAIRWISE_TSC: |
876c9d3a | 1375 | break; |
0aef64d7 | 1376 | case CMD_802_11_GROUP_TSC: |
876c9d3a MT |
1377 | break; |
1378 | ||
0aef64d7 | 1379 | case CMD_802_11_MAC_ADDRESS: |
10078321 | 1380 | ret = lbs_cmd_802_11_mac_address(priv, cmdptr, cmd_action); |
876c9d3a MT |
1381 | break; |
1382 | ||
0aef64d7 | 1383 | case CMD_802_11_EEPROM_ACCESS: |
10078321 | 1384 | ret = lbs_cmd_802_11_eeprom_access(priv, cmdptr, |
876c9d3a MT |
1385 | cmd_action, pdata_buf); |
1386 | break; | |
1387 | ||
0aef64d7 DW |
1388 | case CMD_802_11_SET_AFC: |
1389 | case CMD_802_11_GET_AFC: | |
876c9d3a MT |
1390 | |
1391 | cmdptr->command = cpu_to_le16(cmd_no); | |
981f187b DW |
1392 | cmdptr->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_afc) + |
1393 | S_DS_GEN); | |
876c9d3a MT |
1394 | |
1395 | memmove(&cmdptr->params.afc, | |
1396 | pdata_buf, sizeof(struct cmd_ds_802_11_afc)); | |
1397 | ||
1398 | ret = 0; | |
1399 | goto done; | |
1400 | ||
0aef64d7 | 1401 | case CMD_802_11D_DOMAIN_INFO: |
10078321 | 1402 | ret = lbs_cmd_802_11d_domain_info(priv, cmdptr, |
876c9d3a MT |
1403 | cmd_no, cmd_action); |
1404 | break; | |
1405 | ||
0aef64d7 | 1406 | case CMD_802_11_SLEEP_PARAMS: |
10078321 | 1407 | ret = lbs_cmd_802_11_sleep_params(priv, cmdptr, cmd_action); |
876c9d3a | 1408 | break; |
0aef64d7 | 1409 | case CMD_802_11_INACTIVITY_TIMEOUT: |
10078321 | 1410 | ret = lbs_cmd_802_11_inactivity_timeout(priv, cmdptr, |
876c9d3a | 1411 | cmd_action, pdata_buf); |
f5ece8fc | 1412 | lbs_set_cmd_ctrl_node(priv, cmdnode, 0, pdata_buf); |
876c9d3a MT |
1413 | break; |
1414 | ||
0aef64d7 DW |
1415 | case CMD_802_11_TPC_CFG: |
1416 | cmdptr->command = cpu_to_le16(CMD_802_11_TPC_CFG); | |
876c9d3a MT |
1417 | cmdptr->size = |
1418 | cpu_to_le16(sizeof(struct cmd_ds_802_11_tpc_cfg) + | |
1419 | S_DS_GEN); | |
1420 | ||
1421 | memmove(&cmdptr->params.tpccfg, | |
1422 | pdata_buf, sizeof(struct cmd_ds_802_11_tpc_cfg)); | |
1423 | ||
1424 | ret = 0; | |
1425 | break; | |
0aef64d7 | 1426 | case CMD_802_11_LED_GPIO_CTRL: |
876c9d3a MT |
1427 | { |
1428 | struct mrvlietypes_ledgpio *gpio = | |
1429 | (struct mrvlietypes_ledgpio*) | |
1430 | cmdptr->params.ledgpio.data; | |
1431 | ||
1432 | memmove(&cmdptr->params.ledgpio, | |
1433 | pdata_buf, | |
1434 | sizeof(struct cmd_ds_802_11_led_ctrl)); | |
1435 | ||
1436 | cmdptr->command = | |
0aef64d7 | 1437 | cpu_to_le16(CMD_802_11_LED_GPIO_CTRL); |
876c9d3a MT |
1438 | |
1439 | #define ACTION_NUMLED_TLVTYPE_LEN_FIELDS_LEN 8 | |
1440 | cmdptr->size = | |
1441 | cpu_to_le16(gpio->header.len + S_DS_GEN + | |
1442 | ACTION_NUMLED_TLVTYPE_LEN_FIELDS_LEN); | |
1443 | gpio->header.len = cpu_to_le16(gpio->header.len); | |
1444 | ||
1445 | ret = 0; | |
1446 | break; | |
1447 | } | |
3a188649 HS |
1448 | case CMD_802_11_SUBSCRIBE_EVENT: |
1449 | lbs_cmd_802_11_subscribe_event(priv, cmdptr, | |
1450 | cmd_action, pdata_buf); | |
1451 | break; | |
0aef64d7 DW |
1452 | case CMD_802_11_PWR_CFG: |
1453 | cmdptr->command = cpu_to_le16(CMD_802_11_PWR_CFG); | |
876c9d3a MT |
1454 | cmdptr->size = |
1455 | cpu_to_le16(sizeof(struct cmd_ds_802_11_pwr_cfg) + | |
1456 | S_DS_GEN); | |
1457 | memmove(&cmdptr->params.pwrcfg, pdata_buf, | |
1458 | sizeof(struct cmd_ds_802_11_pwr_cfg)); | |
1459 | ||
1460 | ret = 0; | |
1461 | break; | |
0aef64d7 | 1462 | case CMD_BT_ACCESS: |
10078321 | 1463 | ret = lbs_cmd_bt_access(priv, cmdptr, cmd_action, pdata_buf); |
876c9d3a MT |
1464 | break; |
1465 | ||
0aef64d7 | 1466 | case CMD_FWT_ACCESS: |
10078321 | 1467 | ret = lbs_cmd_fwt_access(priv, cmdptr, cmd_action, pdata_buf); |
876c9d3a MT |
1468 | break; |
1469 | ||
0aef64d7 | 1470 | case CMD_MESH_ACCESS: |
10078321 | 1471 | ret = lbs_cmd_mesh_access(priv, cmdptr, cmd_action, pdata_buf); |
876c9d3a MT |
1472 | break; |
1473 | ||
63f0023b | 1474 | case CMD_SET_BOOT2_VER: |
10078321 | 1475 | ret = lbs_cmd_set_boot2_ver(priv, cmdptr, cmd_action, pdata_buf); |
63f0023b LCC |
1476 | break; |
1477 | ||
0aef64d7 DW |
1478 | case CMD_GET_TSF: |
1479 | cmdptr->command = cpu_to_le16(CMD_GET_TSF); | |
981f187b DW |
1480 | cmdptr->size = cpu_to_le16(sizeof(struct cmd_ds_get_tsf) + |
1481 | S_DS_GEN); | |
876c9d3a MT |
1482 | ret = 0; |
1483 | break; | |
96287ac4 BD |
1484 | case CMD_802_11_BEACON_CTRL: |
1485 | ret = lbs_cmd_bcn_ctrl(priv, cmdptr, cmd_action); | |
1486 | break; | |
876c9d3a | 1487 | default: |
8ff12da1 | 1488 | lbs_deb_host("PREP_CMD: unknown command 0x%04x\n", cmd_no); |
876c9d3a MT |
1489 | ret = -1; |
1490 | break; | |
1491 | } | |
1492 | ||
1493 | /* return error, since the command preparation failed */ | |
1494 | if (ret != 0) { | |
8ff12da1 | 1495 | lbs_deb_host("PREP_CMD: command preparation failed\n"); |
10078321 | 1496 | lbs_cleanup_and_insert_cmd(priv, cmdnode); |
876c9d3a MT |
1497 | ret = -1; |
1498 | goto done; | |
1499 | } | |
1500 | ||
1501 | cmdnode->cmdwaitqwoken = 0; | |
1502 | ||
10078321 | 1503 | lbs_queue_cmd(adapter, cmdnode, 1); |
fe336150 | 1504 | wake_up_interruptible(&priv->waitq); |
876c9d3a | 1505 | |
0aef64d7 | 1506 | if (wait_option & CMD_OPTION_WAITFORRSP) { |
8ff12da1 | 1507 | lbs_deb_host("PREP_CMD: wait for response\n"); |
876c9d3a MT |
1508 | might_sleep(); |
1509 | wait_event_interruptible(cmdnode->cmdwait_q, | |
1510 | cmdnode->cmdwaitqwoken); | |
1511 | } | |
1512 | ||
1513 | spin_lock_irqsave(&adapter->driver_lock, flags); | |
1514 | if (adapter->cur_cmd_retcode) { | |
8ff12da1 | 1515 | lbs_deb_host("PREP_CMD: command failed with return code %d\n", |
876c9d3a MT |
1516 | adapter->cur_cmd_retcode); |
1517 | adapter->cur_cmd_retcode = 0; | |
1518 | ret = -1; | |
1519 | } | |
1520 | spin_unlock_irqrestore(&adapter->driver_lock, flags); | |
1521 | ||
1522 | done: | |
8ff12da1 | 1523 | lbs_deb_leave_args(LBS_DEB_HOST, "ret %d", ret); |
876c9d3a MT |
1524 | return ret; |
1525 | } | |
10078321 | 1526 | EXPORT_SYMBOL_GPL(lbs_prepare_and_send_command); |
876c9d3a MT |
1527 | |
1528 | /** | |
1529 | * @brief This function allocates the command buffer and link | |
1530 | * it to command free queue. | |
1531 | * | |
69f9032d | 1532 | * @param priv A pointer to struct lbs_private structure |
876c9d3a MT |
1533 | * @return 0 or -1 |
1534 | */ | |
69f9032d | 1535 | int lbs_allocate_cmd_buffer(struct lbs_private *priv) |
876c9d3a MT |
1536 | { |
1537 | int ret = 0; | |
1538 | u32 ulbufsize; | |
1539 | u32 i; | |
1540 | struct cmd_ctrl_node *tempcmd_array; | |
1541 | u8 *ptempvirtualaddr; | |
69f9032d | 1542 | struct lbs_adapter *adapter = priv->adapter; |
876c9d3a | 1543 | |
8ff12da1 | 1544 | lbs_deb_enter(LBS_DEB_HOST); |
876c9d3a MT |
1545 | |
1546 | /* Allocate and initialize cmdCtrlNode */ | |
1547 | ulbufsize = sizeof(struct cmd_ctrl_node) * MRVDRV_NUM_OF_CMD_BUFFER; | |
1548 | ||
fb3dddf2 | 1549 | if (!(tempcmd_array = kzalloc(ulbufsize, GFP_KERNEL))) { |
8ff12da1 | 1550 | lbs_deb_host("ALLOC_CMD_BUF: tempcmd_array is NULL\n"); |
876c9d3a MT |
1551 | ret = -1; |
1552 | goto done; | |
1553 | } | |
876c9d3a | 1554 | adapter->cmd_array = tempcmd_array; |
876c9d3a MT |
1555 | |
1556 | /* Allocate and initialize command buffers */ | |
1557 | ulbufsize = MRVDRV_SIZE_OF_CMD_BUFFER; | |
1558 | for (i = 0; i < MRVDRV_NUM_OF_CMD_BUFFER; i++) { | |
fb3dddf2 | 1559 | if (!(ptempvirtualaddr = kzalloc(ulbufsize, GFP_KERNEL))) { |
8ff12da1 | 1560 | lbs_deb_host("ALLOC_CMD_BUF: ptempvirtualaddr is NULL\n"); |
876c9d3a MT |
1561 | ret = -1; |
1562 | goto done; | |
1563 | } | |
1564 | ||
876c9d3a MT |
1565 | /* Update command buffer virtual */ |
1566 | tempcmd_array[i].bufvirtualaddr = ptempvirtualaddr; | |
1567 | } | |
1568 | ||
1569 | for (i = 0; i < MRVDRV_NUM_OF_CMD_BUFFER; i++) { | |
1570 | init_waitqueue_head(&tempcmd_array[i].cmdwait_q); | |
10078321 | 1571 | lbs_cleanup_and_insert_cmd(priv, &tempcmd_array[i]); |
876c9d3a MT |
1572 | } |
1573 | ||
1574 | ret = 0; | |
9012b28a HS |
1575 | |
1576 | done: | |
8ff12da1 | 1577 | lbs_deb_leave_args(LBS_DEB_HOST, "ret %d", ret); |
876c9d3a MT |
1578 | return ret; |
1579 | } | |
1580 | ||
1581 | /** | |
1582 | * @brief This function frees the command buffer. | |
1583 | * | |
69f9032d | 1584 | * @param priv A pointer to struct lbs_private structure |
876c9d3a MT |
1585 | * @return 0 or -1 |
1586 | */ | |
69f9032d | 1587 | int lbs_free_cmd_buffer(struct lbs_private *priv) |
876c9d3a | 1588 | { |
981f187b | 1589 | u32 ulbufsize; /* Someone needs to die for this. Slowly and painfully */ |
876c9d3a MT |
1590 | unsigned int i; |
1591 | struct cmd_ctrl_node *tempcmd_array; | |
69f9032d | 1592 | struct lbs_adapter *adapter = priv->adapter; |
876c9d3a | 1593 | |
8ff12da1 | 1594 | lbs_deb_enter(LBS_DEB_HOST); |
876c9d3a MT |
1595 | |
1596 | /* need to check if cmd array is allocated or not */ | |
1597 | if (adapter->cmd_array == NULL) { | |
8ff12da1 | 1598 | lbs_deb_host("FREE_CMD_BUF: cmd_array is NULL\n"); |
876c9d3a MT |
1599 | goto done; |
1600 | } | |
1601 | ||
1602 | tempcmd_array = adapter->cmd_array; | |
1603 | ||
1604 | /* Release shared memory buffers */ | |
1605 | ulbufsize = MRVDRV_SIZE_OF_CMD_BUFFER; | |
1606 | for (i = 0; i < MRVDRV_NUM_OF_CMD_BUFFER; i++) { | |
1607 | if (tempcmd_array[i].bufvirtualaddr) { | |
876c9d3a MT |
1608 | kfree(tempcmd_array[i].bufvirtualaddr); |
1609 | tempcmd_array[i].bufvirtualaddr = NULL; | |
1610 | } | |
1611 | } | |
1612 | ||
1613 | /* Release cmd_ctrl_node */ | |
1614 | if (adapter->cmd_array) { | |
876c9d3a MT |
1615 | kfree(adapter->cmd_array); |
1616 | adapter->cmd_array = NULL; | |
1617 | } | |
1618 | ||
1619 | done: | |
8ff12da1 | 1620 | lbs_deb_leave(LBS_DEB_HOST); |
876c9d3a MT |
1621 | return 0; |
1622 | } | |
1623 | ||
1624 | /** | |
1625 | * @brief This function gets a free command node if available in | |
1626 | * command free queue. | |
1627 | * | |
69f9032d | 1628 | * @param priv A pointer to struct lbs_private structure |
876c9d3a MT |
1629 | * @return cmd_ctrl_node A pointer to cmd_ctrl_node structure or NULL |
1630 | */ | |
0d61d042 | 1631 | struct cmd_ctrl_node *lbs_get_cmd_ctrl_node(struct lbs_private *priv) |
876c9d3a MT |
1632 | { |
1633 | struct cmd_ctrl_node *tempnode; | |
69f9032d | 1634 | struct lbs_adapter *adapter = priv->adapter; |
876c9d3a MT |
1635 | unsigned long flags; |
1636 | ||
8ff12da1 HS |
1637 | lbs_deb_enter(LBS_DEB_HOST); |
1638 | ||
876c9d3a MT |
1639 | if (!adapter) |
1640 | return NULL; | |
1641 | ||
1642 | spin_lock_irqsave(&adapter->driver_lock, flags); | |
1643 | ||
1644 | if (!list_empty(&adapter->cmdfreeq)) { | |
1645 | tempnode = (struct cmd_ctrl_node *)adapter->cmdfreeq.next; | |
1646 | list_del((struct list_head *)tempnode); | |
1647 | } else { | |
8ff12da1 | 1648 | lbs_deb_host("GET_CMD_NODE: cmd_ctrl_node is not available\n"); |
876c9d3a MT |
1649 | tempnode = NULL; |
1650 | } | |
1651 | ||
1652 | spin_unlock_irqrestore(&adapter->driver_lock, flags); | |
1653 | ||
8ff12da1 | 1654 | if (tempnode) |
876c9d3a | 1655 | cleanup_cmdnode(tempnode); |
876c9d3a | 1656 | |
8ff12da1 | 1657 | lbs_deb_leave(LBS_DEB_HOST); |
876c9d3a MT |
1658 | return tempnode; |
1659 | } | |
1660 | ||
1661 | /** | |
1662 | * @brief This function cleans command node. | |
1663 | * | |
1664 | * @param ptempnode A pointer to cmdCtrlNode structure | |
1665 | * @return n/a | |
1666 | */ | |
1667 | static void cleanup_cmdnode(struct cmd_ctrl_node *ptempnode) | |
1668 | { | |
8ff12da1 HS |
1669 | lbs_deb_enter(LBS_DEB_HOST); |
1670 | ||
876c9d3a MT |
1671 | if (!ptempnode) |
1672 | return; | |
1673 | ptempnode->cmdwaitqwoken = 1; | |
1674 | wake_up_interruptible(&ptempnode->cmdwait_q); | |
876c9d3a MT |
1675 | ptempnode->wait_option = 0; |
1676 | ptempnode->pdata_buf = NULL; | |
ad9de291 | 1677 | ptempnode->pdata_size = 0; |
876c9d3a MT |
1678 | |
1679 | if (ptempnode->bufvirtualaddr != NULL) | |
1680 | memset(ptempnode->bufvirtualaddr, 0, MRVDRV_SIZE_OF_CMD_BUFFER); | |
8ff12da1 HS |
1681 | |
1682 | lbs_deb_leave(LBS_DEB_HOST); | |
876c9d3a MT |
1683 | } |
1684 | ||
1685 | /** | |
1686 | * @brief This function initializes the command node. | |
1687 | * | |
69f9032d | 1688 | * @param priv A pointer to struct lbs_private structure |
876c9d3a | 1689 | * @param ptempnode A pointer to cmd_ctrl_node structure |
876c9d3a MT |
1690 | * @param wait_option wait option: wait response or not |
1691 | * @param pdata_buf A pointer to informaion buffer | |
1692 | * @return 0 or -1 | |
1693 | */ | |
69f9032d | 1694 | void lbs_set_cmd_ctrl_node(struct lbs_private *priv, |
876c9d3a | 1695 | struct cmd_ctrl_node *ptempnode, |
f5ece8fc | 1696 | u16 wait_option, void *pdata_buf) |
876c9d3a | 1697 | { |
8ff12da1 | 1698 | lbs_deb_enter(LBS_DEB_HOST); |
876c9d3a MT |
1699 | |
1700 | if (!ptempnode) | |
1701 | return; | |
1702 | ||
876c9d3a MT |
1703 | ptempnode->wait_option = wait_option; |
1704 | ptempnode->pdata_buf = pdata_buf; | |
ad9de291 | 1705 | ptempnode->pdata_size = 0; |
876c9d3a | 1706 | |
8ff12da1 | 1707 | lbs_deb_leave(LBS_DEB_HOST); |
876c9d3a MT |
1708 | } |
1709 | ||
1710 | /** | |
1711 | * @brief This function executes next command in command | |
1712 | * pending queue. It will put fimware back to PS mode | |
1713 | * if applicable. | |
1714 | * | |
69f9032d | 1715 | * @param priv A pointer to struct lbs_private structure |
876c9d3a MT |
1716 | * @return 0 or -1 |
1717 | */ | |
69f9032d | 1718 | int lbs_execute_next_command(struct lbs_private *priv) |
876c9d3a | 1719 | { |
69f9032d | 1720 | struct lbs_adapter *adapter = priv->adapter; |
876c9d3a MT |
1721 | struct cmd_ctrl_node *cmdnode = NULL; |
1722 | struct cmd_ds_command *cmdptr; | |
1723 | unsigned long flags; | |
1724 | int ret = 0; | |
1725 | ||
8ff12da1 | 1726 | // Debug group is LBS_DEB_THREAD and not LBS_DEB_HOST, because the |
10078321 | 1727 | // only caller to us is lbs_thread() and we get even when a |
8ff12da1 HS |
1728 | // data packet is received |
1729 | lbs_deb_enter(LBS_DEB_THREAD); | |
876c9d3a MT |
1730 | |
1731 | spin_lock_irqsave(&adapter->driver_lock, flags); | |
1732 | ||
1733 | if (adapter->cur_cmd) { | |
8ff12da1 | 1734 | lbs_pr_alert( "EXEC_NEXT_CMD: already processing command!\n"); |
876c9d3a MT |
1735 | spin_unlock_irqrestore(&adapter->driver_lock, flags); |
1736 | ret = -1; | |
1737 | goto done; | |
1738 | } | |
1739 | ||
1740 | if (!list_empty(&adapter->cmdpendingq)) { | |
1741 | cmdnode = (struct cmd_ctrl_node *) | |
1742 | adapter->cmdpendingq.next; | |
1743 | } | |
1744 | ||
1745 | spin_unlock_irqrestore(&adapter->driver_lock, flags); | |
1746 | ||
1747 | if (cmdnode) { | |
876c9d3a MT |
1748 | cmdptr = (struct cmd_ds_command *)cmdnode->bufvirtualaddr; |
1749 | ||
1750 | if (is_command_allowed_in_ps(cmdptr->command)) { | |
981f187b DW |
1751 | if ((adapter->psstate == PS_STATE_SLEEP) || |
1752 | (adapter->psstate == PS_STATE_PRE_SLEEP)) { | |
8ff12da1 HS |
1753 | lbs_deb_host( |
1754 | "EXEC_NEXT_CMD: cannot send cmd 0x%04x in psstate %d\n", | |
981f187b DW |
1755 | le16_to_cpu(cmdptr->command), |
1756 | adapter->psstate); | |
876c9d3a MT |
1757 | ret = -1; |
1758 | goto done; | |
1759 | } | |
8ff12da1 HS |
1760 | lbs_deb_host("EXEC_NEXT_CMD: OK to send command " |
1761 | "0x%04x in psstate %d\n", | |
981f187b DW |
1762 | le16_to_cpu(cmdptr->command), |
1763 | adapter->psstate); | |
876c9d3a MT |
1764 | } else if (adapter->psstate != PS_STATE_FULL_POWER) { |
1765 | /* | |
1766 | * 1. Non-PS command: | |
1767 | * Queue it. set needtowakeup to TRUE if current state | |
10078321 | 1768 | * is SLEEP, otherwise call lbs_ps_wakeup to send Exit_PS. |
876c9d3a MT |
1769 | * 2. PS command but not Exit_PS: |
1770 | * Ignore it. | |
1771 | * 3. PS command Exit_PS: | |
1772 | * Set needtowakeup to TRUE if current state is SLEEP, | |
1773 | * otherwise send this command down to firmware | |
1774 | * immediately. | |
1775 | */ | |
1776 | if (cmdptr->command != | |
0aef64d7 | 1777 | cpu_to_le16(CMD_802_11_PS_MODE)) { |
876c9d3a MT |
1778 | /* Prepare to send Exit PS, |
1779 | * this non PS command will be sent later */ | |
1780 | if ((adapter->psstate == PS_STATE_SLEEP) | |
1781 | || (adapter->psstate == PS_STATE_PRE_SLEEP) | |
1782 | ) { | |
1783 | /* w/ new scheme, it will not reach here. | |
1784 | since it is blocked in main_thread. */ | |
1785 | adapter->needtowakeup = 1; | |
1786 | } else | |
10078321 | 1787 | lbs_ps_wakeup(priv, 0); |
876c9d3a MT |
1788 | |
1789 | ret = 0; | |
1790 | goto done; | |
1791 | } else { | |
1792 | /* | |
1793 | * PS command. Ignore it if it is not Exit_PS. | |
1794 | * otherwise send it down immediately. | |
1795 | */ | |
1796 | struct cmd_ds_802_11_ps_mode *psm = | |
1797 | &cmdptr->params.psmode; | |
1798 | ||
8ff12da1 HS |
1799 | lbs_deb_host( |
1800 | "EXEC_NEXT_CMD: PS cmd, action 0x%02x\n", | |
876c9d3a MT |
1801 | psm->action); |
1802 | if (psm->action != | |
0aef64d7 | 1803 | cpu_to_le16(CMD_SUBCMD_EXIT_PS)) { |
8ff12da1 HS |
1804 | lbs_deb_host( |
1805 | "EXEC_NEXT_CMD: ignore ENTER_PS cmd\n"); | |
876c9d3a | 1806 | list_del((struct list_head *)cmdnode); |
10078321 | 1807 | lbs_cleanup_and_insert_cmd(priv, cmdnode); |
876c9d3a MT |
1808 | |
1809 | ret = 0; | |
1810 | goto done; | |
1811 | } | |
1812 | ||
981f187b DW |
1813 | if ((adapter->psstate == PS_STATE_SLEEP) || |
1814 | (adapter->psstate == PS_STATE_PRE_SLEEP)) { | |
8ff12da1 HS |
1815 | lbs_deb_host( |
1816 | "EXEC_NEXT_CMD: ignore EXIT_PS cmd in sleep\n"); | |
876c9d3a | 1817 | list_del((struct list_head *)cmdnode); |
10078321 | 1818 | lbs_cleanup_and_insert_cmd(priv, cmdnode); |
876c9d3a MT |
1819 | adapter->needtowakeup = 1; |
1820 | ||
1821 | ret = 0; | |
1822 | goto done; | |
1823 | } | |
1824 | ||
8ff12da1 HS |
1825 | lbs_deb_host( |
1826 | "EXEC_NEXT_CMD: sending EXIT_PS\n"); | |
876c9d3a MT |
1827 | } |
1828 | } | |
1829 | list_del((struct list_head *)cmdnode); | |
8ff12da1 | 1830 | lbs_deb_host("EXEC_NEXT_CMD: sending command 0x%04x\n", |
981f187b | 1831 | le16_to_cpu(cmdptr->command)); |
876c9d3a MT |
1832 | DownloadcommandToStation(priv, cmdnode); |
1833 | } else { | |
1834 | /* | |
1835 | * check if in power save mode, if yes, put the device back | |
1836 | * to PS mode | |
1837 | */ | |
10078321 | 1838 | if ((adapter->psmode != LBS802_11POWERMODECAM) && |
876c9d3a | 1839 | (adapter->psstate == PS_STATE_FULL_POWER) && |
01d77d8d BD |
1840 | ((adapter->connect_status == LBS_CONNECTED) || |
1841 | (adapter->mesh_connect_status == LBS_CONNECTED))) { | |
981f187b DW |
1842 | if (adapter->secinfo.WPAenabled || |
1843 | adapter->secinfo.WPA2enabled) { | |
876c9d3a | 1844 | /* check for valid WPA group keys */ |
981f187b DW |
1845 | if (adapter->wpa_mcast_key.len || |
1846 | adapter->wpa_unicast_key.len) { | |
8ff12da1 | 1847 | lbs_deb_host( |
876c9d3a MT |
1848 | "EXEC_NEXT_CMD: WPA enabled and GTK_SET" |
1849 | " go back to PS_SLEEP"); | |
10078321 | 1850 | lbs_ps_sleep(priv, 0); |
876c9d3a MT |
1851 | } |
1852 | } else { | |
8ff12da1 HS |
1853 | lbs_deb_host( |
1854 | "EXEC_NEXT_CMD: cmdpendingq empty, " | |
1855 | "go back to PS_SLEEP"); | |
10078321 | 1856 | lbs_ps_sleep(priv, 0); |
876c9d3a MT |
1857 | } |
1858 | } | |
1859 | } | |
1860 | ||
1861 | ret = 0; | |
1862 | done: | |
8ff12da1 | 1863 | lbs_deb_leave(LBS_DEB_THREAD); |
876c9d3a MT |
1864 | return ret; |
1865 | } | |
1866 | ||
69f9032d | 1867 | void lbs_send_iwevcustom_event(struct lbs_private *priv, s8 *str) |
876c9d3a MT |
1868 | { |
1869 | union iwreq_data iwrq; | |
1870 | u8 buf[50]; | |
1871 | ||
8ff12da1 | 1872 | lbs_deb_enter(LBS_DEB_WEXT); |
876c9d3a MT |
1873 | |
1874 | memset(&iwrq, 0, sizeof(union iwreq_data)); | |
1875 | memset(buf, 0, sizeof(buf)); | |
1876 | ||
1877 | snprintf(buf, sizeof(buf) - 1, "%s", str); | |
1878 | ||
1879 | iwrq.data.length = strlen(buf) + 1 + IW_EV_LCP_LEN; | |
1880 | ||
1881 | /* Send Event to upper layer */ | |
8ff12da1 HS |
1882 | lbs_deb_wext("event indication string %s\n", (char *)buf); |
1883 | lbs_deb_wext("event indication length %d\n", iwrq.data.length); | |
1884 | lbs_deb_wext("sending wireless event IWEVCUSTOM for %s\n", str); | |
876c9d3a | 1885 | |
634b8f49 | 1886 | wireless_send_event(priv->dev, IWEVCUSTOM, &iwrq, buf); |
876c9d3a | 1887 | |
8ff12da1 | 1888 | lbs_deb_leave(LBS_DEB_WEXT); |
876c9d3a MT |
1889 | } |
1890 | ||
69f9032d | 1891 | static int sendconfirmsleep(struct lbs_private *priv, u8 *cmdptr, u16 size) |
876c9d3a MT |
1892 | { |
1893 | unsigned long flags; | |
69f9032d | 1894 | struct lbs_adapter *adapter = priv->adapter; |
876c9d3a MT |
1895 | int ret = 0; |
1896 | ||
8ff12da1 | 1897 | lbs_deb_enter(LBS_DEB_HOST); |
876c9d3a | 1898 | |
8ff12da1 | 1899 | lbs_deb_host("SEND_SLEEPC_CMD: before download, cmd size %d\n", |
876c9d3a MT |
1900 | size); |
1901 | ||
8ff12da1 | 1902 | lbs_deb_hex(LBS_DEB_HOST, "sleep confirm command", cmdptr, size); |
876c9d3a | 1903 | |
208fdd2f | 1904 | ret = priv->hw_host_to_card(priv, MVMS_CMD, cmdptr, size); |
634b8f49 | 1905 | priv->dnld_sent = DNLD_RES_RECEIVED; |
876c9d3a MT |
1906 | |
1907 | spin_lock_irqsave(&adapter->driver_lock, flags); | |
1908 | if (adapter->intcounter || adapter->currenttxskb) | |
8ff12da1 | 1909 | lbs_deb_host("SEND_SLEEPC_CMD: intcounter %d, currenttxskb %p\n", |
876c9d3a MT |
1910 | adapter->intcounter, adapter->currenttxskb); |
1911 | spin_unlock_irqrestore(&adapter->driver_lock, flags); | |
1912 | ||
1913 | if (ret) { | |
1914 | lbs_pr_alert( | |
1915 | "SEND_SLEEPC_CMD: Host to Card failed for Confirm Sleep\n"); | |
1916 | } else { | |
1917 | spin_lock_irqsave(&adapter->driver_lock, flags); | |
1918 | if (!adapter->intcounter) { | |
1919 | adapter->psstate = PS_STATE_SLEEP; | |
1920 | } else { | |
8ff12da1 | 1921 | lbs_deb_host("SEND_SLEEPC_CMD: after sent, intcounter %d\n", |
876c9d3a MT |
1922 | adapter->intcounter); |
1923 | } | |
1924 | spin_unlock_irqrestore(&adapter->driver_lock, flags); | |
1925 | ||
8ff12da1 | 1926 | lbs_deb_host("SEND_SLEEPC_CMD: sent confirm sleep\n"); |
876c9d3a MT |
1927 | } |
1928 | ||
8ff12da1 | 1929 | lbs_deb_leave_args(LBS_DEB_HOST, "ret %d", ret); |
876c9d3a MT |
1930 | return ret; |
1931 | } | |
1932 | ||
69f9032d | 1933 | void lbs_ps_sleep(struct lbs_private *priv, int wait_option) |
876c9d3a | 1934 | { |
8ff12da1 | 1935 | lbs_deb_enter(LBS_DEB_HOST); |
876c9d3a MT |
1936 | |
1937 | /* | |
1938 | * PS is currently supported only in Infrastructure mode | |
1939 | * Remove this check if it is to be supported in IBSS mode also | |
1940 | */ | |
1941 | ||
10078321 | 1942 | lbs_prepare_and_send_command(priv, CMD_802_11_PS_MODE, |
0aef64d7 | 1943 | CMD_SUBCMD_ENTER_PS, wait_option, 0, NULL); |
876c9d3a | 1944 | |
8ff12da1 | 1945 | lbs_deb_leave(LBS_DEB_HOST); |
876c9d3a MT |
1946 | } |
1947 | ||
1948 | /** | |
8ff12da1 | 1949 | * @brief This function sends Exit_PS command to firmware. |
876c9d3a | 1950 | * |
69f9032d | 1951 | * @param priv A pointer to struct lbs_private structure |
876c9d3a MT |
1952 | * @param wait_option wait response or not |
1953 | * @return n/a | |
1954 | */ | |
69f9032d | 1955 | void lbs_ps_wakeup(struct lbs_private *priv, int wait_option) |
876c9d3a | 1956 | { |
981f187b | 1957 | __le32 Localpsmode; |
876c9d3a | 1958 | |
8ff12da1 | 1959 | lbs_deb_enter(LBS_DEB_HOST); |
876c9d3a | 1960 | |
10078321 | 1961 | Localpsmode = cpu_to_le32(LBS802_11POWERMODECAM); |
876c9d3a | 1962 | |
10078321 | 1963 | lbs_prepare_and_send_command(priv, CMD_802_11_PS_MODE, |
0aef64d7 | 1964 | CMD_SUBCMD_EXIT_PS, |
876c9d3a MT |
1965 | wait_option, 0, &Localpsmode); |
1966 | ||
8ff12da1 | 1967 | lbs_deb_leave(LBS_DEB_HOST); |
876c9d3a MT |
1968 | } |
1969 | ||
1970 | /** | |
1971 | * @brief This function checks condition and prepares to | |
1972 | * send sleep confirm command to firmware if ok. | |
1973 | * | |
69f9032d | 1974 | * @param priv A pointer to struct lbs_private structure |
876c9d3a MT |
1975 | * @param psmode Power Saving mode |
1976 | * @return n/a | |
1977 | */ | |
69f9032d | 1978 | void lbs_ps_confirm_sleep(struct lbs_private *priv, u16 psmode) |
876c9d3a MT |
1979 | { |
1980 | unsigned long flags =0; | |
69f9032d | 1981 | struct lbs_adapter *adapter = priv->adapter; |
876c9d3a MT |
1982 | u8 allowed = 1; |
1983 | ||
8ff12da1 | 1984 | lbs_deb_enter(LBS_DEB_HOST); |
876c9d3a | 1985 | |
634b8f49 | 1986 | if (priv->dnld_sent) { |
876c9d3a | 1987 | allowed = 0; |
8ff12da1 | 1988 | lbs_deb_host("dnld_sent was set"); |
876c9d3a MT |
1989 | } |
1990 | ||
1991 | spin_lock_irqsave(&adapter->driver_lock, flags); | |
1992 | if (adapter->cur_cmd) { | |
1993 | allowed = 0; | |
8ff12da1 | 1994 | lbs_deb_host("cur_cmd was set"); |
876c9d3a MT |
1995 | } |
1996 | if (adapter->intcounter > 0) { | |
1997 | allowed = 0; | |
8ff12da1 | 1998 | lbs_deb_host("intcounter %d", adapter->intcounter); |
876c9d3a MT |
1999 | } |
2000 | spin_unlock_irqrestore(&adapter->driver_lock, flags); | |
2001 | ||
2002 | if (allowed) { | |
10078321 HS |
2003 | lbs_deb_host("sending lbs_ps_confirm_sleep\n"); |
2004 | sendconfirmsleep(priv, (u8 *) & adapter->lbs_ps_confirm_sleep, | |
876c9d3a MT |
2005 | sizeof(struct PS_CMD_ConfirmSleep)); |
2006 | } else { | |
8ff12da1 | 2007 | lbs_deb_host("sleep confirm has been delayed\n"); |
876c9d3a MT |
2008 | } |
2009 | ||
8ff12da1 | 2010 | lbs_deb_leave(LBS_DEB_HOST); |
876c9d3a | 2011 | } |
675787e2 HS |
2012 | |
2013 | ||
2014 | /** | |
2015 | * @brief Simple way to call firmware functions | |
2016 | * | |
2017 | * @param priv A pointer to struct lbs_private structure | |
2018 | * @param psmode one of the many CMD_802_11_xxxx | |
2019 | * @param cmd pointer to the parameters structure for above command | |
2020 | * (this should not include the command, size, sequence | |
2021 | * and result fields from struct cmd_ds_gen) | |
2022 | * @param cmd_size size structure pointed to by cmd | |
2023 | * @param rsp pointer to an area where the result should be placed | |
2024 | * @param rsp_size pointer to the size of the rsp area. If the firmware | |
2025 | * returns fewer bytes, then this *rsp_size will be | |
2026 | * changed to the actual size. | |
2027 | * @return -1 in case of a higher level error, otherwise | |
2028 | * the result code from the firmware | |
2029 | */ | |
2030 | int lbs_cmd(struct lbs_private *priv, | |
2031 | u16 command, | |
2032 | void *cmd, int cmd_size, | |
2033 | void *rsp, int *rsp_size) | |
2034 | { | |
2035 | struct lbs_adapter *adapter = priv->adapter; | |
2036 | struct cmd_ctrl_node *cmdnode; | |
2037 | struct cmd_ds_gen *cmdptr; | |
2038 | unsigned long flags; | |
2039 | int ret = 0; | |
2040 | ||
2041 | lbs_deb_enter(LBS_DEB_HOST); | |
2042 | lbs_deb_host("rsp at %p, rsp_size at %p\n", rsp, rsp_size); | |
2043 | ||
2044 | if (!adapter || !rsp_size) { | |
2045 | lbs_deb_host("PREP_CMD: adapter is NULL\n"); | |
2046 | ret = -1; | |
2047 | goto done; | |
2048 | } | |
2049 | ||
2050 | if (adapter->surpriseremoved) { | |
2051 | lbs_deb_host("PREP_CMD: card removed\n"); | |
2052 | ret = -1; | |
2053 | goto done; | |
2054 | } | |
2055 | ||
2056 | cmdnode = lbs_get_cmd_ctrl_node(priv); | |
2057 | ||
2058 | if (cmdnode == NULL) { | |
2059 | lbs_deb_host("PREP_CMD: cmdnode is NULL\n"); | |
2060 | ||
2061 | /* Wake up main thread to execute next command */ | |
2062 | wake_up_interruptible(&priv->waitq); | |
2063 | ret = -1; | |
2064 | goto done; | |
2065 | } | |
2066 | ||
2067 | cmdptr = (struct cmd_ds_gen *)cmdnode->bufvirtualaddr; | |
2068 | cmdnode->wait_option = CMD_OPTION_WAITFORRSP; | |
2069 | cmdnode->pdata_buf = rsp; | |
2070 | cmdnode->pdata_size = rsp_size; | |
2071 | ||
2072 | /* Set sequence number, clean result, move to buffer */ | |
2073 | adapter->seqnum++; | |
2074 | cmdptr->command = cpu_to_le16(command); | |
6228c0ae | 2075 | cmdptr->size = cpu_to_le16(cmd_size + S_DS_GEN); |
675787e2 HS |
2076 | cmdptr->seqnum = cpu_to_le16(adapter->seqnum); |
2077 | cmdptr->result = 0; | |
2078 | memcpy(cmdptr->cmdresp, cmd, cmd_size); | |
2079 | ||
2080 | lbs_deb_host("PREP_CMD: command 0x%04x\n", command); | |
2081 | ||
2082 | /* here was the big old switch() statement, which is now obsolete, | |
2083 | * because the caller of lbs_cmd() sets up all of *cmd for us. */ | |
2084 | ||
2085 | cmdnode->cmdwaitqwoken = 0; | |
2086 | lbs_queue_cmd(adapter, cmdnode, 1); | |
2087 | wake_up_interruptible(&priv->waitq); | |
2088 | ||
2089 | might_sleep(); | |
2090 | wait_event_interruptible(cmdnode->cmdwait_q, cmdnode->cmdwaitqwoken); | |
2091 | ||
2092 | spin_lock_irqsave(&adapter->driver_lock, flags); | |
2093 | if (adapter->cur_cmd_retcode) { | |
2094 | lbs_deb_host("PREP_CMD: command failed with return code %d\n", | |
2095 | adapter->cur_cmd_retcode); | |
2096 | adapter->cur_cmd_retcode = 0; | |
2097 | ret = -1; | |
2098 | } | |
2099 | spin_unlock_irqrestore(&adapter->driver_lock, flags); | |
2100 | ||
2101 | done: | |
2102 | lbs_deb_leave_args(LBS_DEB_HOST, "ret %d", ret); | |
2103 | return ret; | |
2104 | } | |
2105 | EXPORT_SYMBOL_GPL(lbs_cmd); | |
2106 | ||
2107 |