Commit | Line | Data |
---|---|---|
5e6e3a92 BZ |
1 | /* |
2 | * Marvell Wireless LAN device driver: station command handling | |
3 | * | |
4 | * Copyright (C) 2011, Marvell International Ltd. | |
5 | * | |
6 | * This software file (the "File") is distributed by Marvell International | |
7 | * Ltd. under the terms of the GNU General Public License Version 2, June 1991 | |
8 | * (the "License"). You may use, redistribute and/or modify this File in | |
9 | * accordance with the terms and conditions of the License, a copy of which | |
10 | * is available by writing to the Free Software Foundation, Inc., | |
11 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA or on the | |
12 | * worldwide web at http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt. | |
13 | * | |
14 | * THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE | |
15 | * IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE | |
16 | * ARE EXPRESSLY DISCLAIMED. The License provides additional details about | |
17 | * this warranty disclaimer. | |
18 | */ | |
19 | ||
20 | #include "decl.h" | |
21 | #include "ioctl.h" | |
22 | #include "util.h" | |
23 | #include "fw.h" | |
24 | #include "main.h" | |
25 | #include "wmm.h" | |
26 | #include "11n.h" | |
27 | ||
28 | /* | |
29 | * This function prepares command to set/get RSSI information. | |
30 | * | |
31 | * Preparation includes - | |
32 | * - Setting command ID, action and proper size | |
33 | * - Setting data/beacon average factors | |
34 | * - Resetting SNR/NF/RSSI values in private structure | |
35 | * - Ensuring correct endian-ness | |
36 | */ | |
37 | static int | |
38 | mwifiex_cmd_802_11_rssi_info(struct mwifiex_private *priv, | |
39 | struct host_cmd_ds_command *cmd, u16 cmd_action) | |
40 | { | |
41 | cmd->command = cpu_to_le16(HostCmd_CMD_RSSI_INFO); | |
42 | cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_802_11_rssi_info) + | |
43 | S_DS_GEN); | |
44 | cmd->params.rssi_info.action = cpu_to_le16(cmd_action); | |
45 | cmd->params.rssi_info.ndata = cpu_to_le16(priv->data_avg_factor); | |
46 | cmd->params.rssi_info.nbcn = cpu_to_le16(priv->bcn_avg_factor); | |
47 | ||
48 | /* Reset SNR/NF/RSSI values in private structure */ | |
49 | priv->data_rssi_last = 0; | |
50 | priv->data_nf_last = 0; | |
51 | priv->data_rssi_avg = 0; | |
52 | priv->data_nf_avg = 0; | |
53 | priv->bcn_rssi_last = 0; | |
54 | priv->bcn_nf_last = 0; | |
55 | priv->bcn_rssi_avg = 0; | |
56 | priv->bcn_nf_avg = 0; | |
57 | ||
58 | return 0; | |
59 | } | |
60 | ||
61 | /* | |
62 | * This function prepares command to set MAC control. | |
63 | * | |
64 | * Preparation includes - | |
65 | * - Setting command ID, action and proper size | |
66 | * - Ensuring correct endian-ness | |
67 | */ | |
68 | static int mwifiex_cmd_mac_control(struct mwifiex_private *priv, | |
69 | struct host_cmd_ds_command *cmd, | |
a5ffddb7 | 70 | u16 cmd_action, u16 *action) |
5e6e3a92 BZ |
71 | { |
72 | struct host_cmd_ds_mac_control *mac_ctrl = &cmd->params.mac_ctrl; | |
5e6e3a92 BZ |
73 | |
74 | if (cmd_action != HostCmd_ACT_GEN_SET) { | |
75 | dev_err(priv->adapter->dev, | |
76 | "mac_control: only support set cmd\n"); | |
77 | return -1; | |
78 | } | |
79 | ||
80 | cmd->command = cpu_to_le16(HostCmd_CMD_MAC_CONTROL); | |
81 | cmd->size = | |
82 | cpu_to_le16(sizeof(struct host_cmd_ds_mac_control) + S_DS_GEN); | |
a5ffddb7 | 83 | mac_ctrl->action = cpu_to_le16(*action); |
5e6e3a92 BZ |
84 | |
85 | return 0; | |
86 | } | |
87 | ||
88 | /* | |
89 | * This function prepares command to set/get SNMP MIB. | |
90 | * | |
91 | * Preparation includes - | |
92 | * - Setting command ID, action and proper size | |
93 | * - Setting SNMP MIB OID number and value | |
94 | * (as required) | |
95 | * - Ensuring correct endian-ness | |
96 | * | |
97 | * The following SNMP MIB OIDs are supported - | |
98 | * - FRAG_THRESH_I : Fragmentation threshold | |
99 | * - RTS_THRESH_I : RTS threshold | |
100 | * - SHORT_RETRY_LIM_I : Short retry limit | |
101 | * - DOT11D_I : 11d support | |
102 | */ | |
103 | static int mwifiex_cmd_802_11_snmp_mib(struct mwifiex_private *priv, | |
104 | struct host_cmd_ds_command *cmd, | |
105 | u16 cmd_action, u32 cmd_oid, | |
a5ffddb7 | 106 | u32 *ul_temp) |
5e6e3a92 BZ |
107 | { |
108 | struct host_cmd_ds_802_11_snmp_mib *snmp_mib = &cmd->params.smib; | |
5e6e3a92 BZ |
109 | |
110 | dev_dbg(priv->adapter->dev, "cmd: SNMP_CMD: cmd_oid = 0x%x\n", cmd_oid); | |
111 | cmd->command = cpu_to_le16(HostCmd_CMD_802_11_SNMP_MIB); | |
112 | cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_802_11_snmp_mib) | |
113 | - 1 + S_DS_GEN); | |
114 | ||
115 | if (cmd_action == HostCmd_ACT_GEN_GET) { | |
116 | snmp_mib->query_type = cpu_to_le16(HostCmd_ACT_GEN_GET); | |
117 | snmp_mib->buf_size = cpu_to_le16(MAX_SNMP_BUF_SIZE); | |
118 | cmd->size = cpu_to_le16(le16_to_cpu(cmd->size) | |
119 | + MAX_SNMP_BUF_SIZE); | |
120 | } | |
121 | ||
122 | switch (cmd_oid) { | |
123 | case FRAG_THRESH_I: | |
124 | snmp_mib->oid = cpu_to_le16((u16) FRAG_THRESH_I); | |
125 | if (cmd_action == HostCmd_ACT_GEN_SET) { | |
126 | snmp_mib->query_type = cpu_to_le16(HostCmd_ACT_GEN_SET); | |
127 | snmp_mib->buf_size = cpu_to_le16(sizeof(u16)); | |
5e6e3a92 | 128 | *((__le16 *) (snmp_mib->value)) = |
a5ffddb7 | 129 | cpu_to_le16((u16) *ul_temp); |
5e6e3a92 BZ |
130 | cmd->size = cpu_to_le16(le16_to_cpu(cmd->size) |
131 | + sizeof(u16)); | |
132 | } | |
133 | break; | |
134 | case RTS_THRESH_I: | |
135 | snmp_mib->oid = cpu_to_le16((u16) RTS_THRESH_I); | |
136 | if (cmd_action == HostCmd_ACT_GEN_SET) { | |
137 | snmp_mib->query_type = cpu_to_le16(HostCmd_ACT_GEN_SET); | |
138 | snmp_mib->buf_size = cpu_to_le16(sizeof(u16)); | |
5e6e3a92 | 139 | *(__le16 *) (snmp_mib->value) = |
a5ffddb7 | 140 | cpu_to_le16((u16) *ul_temp); |
5e6e3a92 BZ |
141 | cmd->size = cpu_to_le16(le16_to_cpu(cmd->size) |
142 | + sizeof(u16)); | |
143 | } | |
144 | break; | |
145 | ||
146 | case SHORT_RETRY_LIM_I: | |
147 | snmp_mib->oid = cpu_to_le16((u16) SHORT_RETRY_LIM_I); | |
148 | if (cmd_action == HostCmd_ACT_GEN_SET) { | |
149 | snmp_mib->query_type = cpu_to_le16(HostCmd_ACT_GEN_SET); | |
150 | snmp_mib->buf_size = cpu_to_le16(sizeof(u16)); | |
5e6e3a92 | 151 | *((__le16 *) (snmp_mib->value)) = |
a5ffddb7 | 152 | cpu_to_le16((u16) *ul_temp); |
5e6e3a92 BZ |
153 | cmd->size = cpu_to_le16(le16_to_cpu(cmd->size) |
154 | + sizeof(u16)); | |
155 | } | |
156 | break; | |
157 | case DOT11D_I: | |
158 | snmp_mib->oid = cpu_to_le16((u16) DOT11D_I); | |
159 | if (cmd_action == HostCmd_ACT_GEN_SET) { | |
160 | snmp_mib->query_type = cpu_to_le16(HostCmd_ACT_GEN_SET); | |
161 | snmp_mib->buf_size = cpu_to_le16(sizeof(u16)); | |
5e6e3a92 | 162 | *((__le16 *) (snmp_mib->value)) = |
a5ffddb7 | 163 | cpu_to_le16((u16) *ul_temp); |
5e6e3a92 BZ |
164 | cmd->size = cpu_to_le16(le16_to_cpu(cmd->size) |
165 | + sizeof(u16)); | |
166 | } | |
167 | break; | |
168 | default: | |
169 | break; | |
170 | } | |
171 | dev_dbg(priv->adapter->dev, | |
172 | "cmd: SNMP_CMD: Action=0x%x, OID=0x%x, OIDSize=0x%x," | |
173 | " Value=0x%x\n", | |
174 | cmd_action, cmd_oid, le16_to_cpu(snmp_mib->buf_size), | |
175 | le16_to_cpu(*(__le16 *) snmp_mib->value)); | |
176 | return 0; | |
177 | } | |
178 | ||
179 | /* | |
180 | * This function prepares command to get log. | |
181 | * | |
182 | * Preparation includes - | |
183 | * - Setting command ID and proper size | |
184 | * - Ensuring correct endian-ness | |
185 | */ | |
186 | static int | |
572e8f3e | 187 | mwifiex_cmd_802_11_get_log(struct host_cmd_ds_command *cmd) |
5e6e3a92 BZ |
188 | { |
189 | cmd->command = cpu_to_le16(HostCmd_CMD_802_11_GET_LOG); | |
190 | cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_802_11_get_log) + | |
191 | S_DS_GEN); | |
192 | return 0; | |
193 | } | |
194 | ||
195 | /* | |
196 | * This function prepares command to set/get Tx data rate configuration. | |
197 | * | |
198 | * Preparation includes - | |
199 | * - Setting command ID, action and proper size | |
200 | * - Setting configuration index, rate scope and rate drop pattern | |
201 | * parameters (as required) | |
202 | * - Ensuring correct endian-ness | |
203 | */ | |
204 | static int mwifiex_cmd_tx_rate_cfg(struct mwifiex_private *priv, | |
205 | struct host_cmd_ds_command *cmd, | |
a5ffddb7 | 206 | u16 cmd_action, u16 *pbitmap_rates) |
5e6e3a92 BZ |
207 | { |
208 | struct host_cmd_ds_tx_rate_cfg *rate_cfg = &cmd->params.tx_rate_cfg; | |
209 | struct mwifiex_rate_scope *rate_scope; | |
210 | struct mwifiex_rate_drop_pattern *rate_drop; | |
5e6e3a92 BZ |
211 | u32 i; |
212 | ||
213 | cmd->command = cpu_to_le16(HostCmd_CMD_TX_RATE_CFG); | |
214 | ||
215 | rate_cfg->action = cpu_to_le16(cmd_action); | |
216 | rate_cfg->cfg_index = 0; | |
217 | ||
218 | rate_scope = (struct mwifiex_rate_scope *) ((u8 *) rate_cfg + | |
219 | sizeof(struct host_cmd_ds_tx_rate_cfg)); | |
220 | rate_scope->type = cpu_to_le16(TLV_TYPE_RATE_SCOPE); | |
221 | rate_scope->length = cpu_to_le16(sizeof(struct mwifiex_rate_scope) - | |
222 | sizeof(struct mwifiex_ie_types_header)); | |
223 | if (pbitmap_rates != NULL) { | |
224 | rate_scope->hr_dsss_rate_bitmap = cpu_to_le16(pbitmap_rates[0]); | |
225 | rate_scope->ofdm_rate_bitmap = cpu_to_le16(pbitmap_rates[1]); | |
226 | for (i = 0; | |
227 | i < sizeof(rate_scope->ht_mcs_rate_bitmap) / sizeof(u16); | |
228 | i++) | |
229 | rate_scope->ht_mcs_rate_bitmap[i] = | |
230 | cpu_to_le16(pbitmap_rates[2 + i]); | |
231 | } else { | |
232 | rate_scope->hr_dsss_rate_bitmap = | |
233 | cpu_to_le16(priv->bitmap_rates[0]); | |
234 | rate_scope->ofdm_rate_bitmap = | |
235 | cpu_to_le16(priv->bitmap_rates[1]); | |
236 | for (i = 0; | |
237 | i < sizeof(rate_scope->ht_mcs_rate_bitmap) / sizeof(u16); | |
238 | i++) | |
239 | rate_scope->ht_mcs_rate_bitmap[i] = | |
240 | cpu_to_le16(priv->bitmap_rates[2 + i]); | |
241 | } | |
242 | ||
243 | rate_drop = (struct mwifiex_rate_drop_pattern *) ((u8 *) rate_scope + | |
244 | sizeof(struct mwifiex_rate_scope)); | |
245 | rate_drop->type = cpu_to_le16(TLV_TYPE_RATE_DROP_CONTROL); | |
246 | rate_drop->length = cpu_to_le16(sizeof(rate_drop->rate_drop_mode)); | |
247 | rate_drop->rate_drop_mode = 0; | |
248 | ||
249 | cmd->size = | |
250 | cpu_to_le16(S_DS_GEN + sizeof(struct host_cmd_ds_tx_rate_cfg) + | |
251 | sizeof(struct mwifiex_rate_scope) + | |
252 | sizeof(struct mwifiex_rate_drop_pattern)); | |
253 | ||
254 | return 0; | |
255 | } | |
256 | ||
257 | /* | |
258 | * This function prepares command to set/get Tx power configuration. | |
259 | * | |
260 | * Preparation includes - | |
261 | * - Setting command ID, action and proper size | |
262 | * - Setting Tx power mode, power group TLV | |
263 | * (as required) | |
264 | * - Ensuring correct endian-ness | |
265 | */ | |
572e8f3e | 266 | static int mwifiex_cmd_tx_power_cfg(struct host_cmd_ds_command *cmd, |
a5ffddb7 AK |
267 | u16 cmd_action, |
268 | struct host_cmd_ds_txpwr_cfg *txp) | |
5e6e3a92 | 269 | { |
270e58e8 | 270 | struct mwifiex_types_power_group *pg_tlv; |
5e6e3a92 BZ |
271 | struct host_cmd_ds_txpwr_cfg *cmd_txp_cfg = &cmd->params.txp_cfg; |
272 | ||
273 | cmd->command = cpu_to_le16(HostCmd_CMD_TXPWR_CFG); | |
274 | cmd->size = | |
275 | cpu_to_le16(S_DS_GEN + sizeof(struct host_cmd_ds_txpwr_cfg)); | |
276 | switch (cmd_action) { | |
277 | case HostCmd_ACT_GEN_SET: | |
5e6e3a92 BZ |
278 | if (txp->mode) { |
279 | pg_tlv = (struct mwifiex_types_power_group | |
a5ffddb7 | 280 | *) ((unsigned long) txp + |
5e6e3a92 | 281 | sizeof(struct host_cmd_ds_txpwr_cfg)); |
a5ffddb7 | 282 | memmove(cmd_txp_cfg, txp, |
5e6e3a92 BZ |
283 | sizeof(struct host_cmd_ds_txpwr_cfg) + |
284 | sizeof(struct mwifiex_types_power_group) + | |
285 | pg_tlv->length); | |
286 | ||
287 | pg_tlv = (struct mwifiex_types_power_group *) ((u8 *) | |
288 | cmd_txp_cfg + | |
289 | sizeof(struct host_cmd_ds_txpwr_cfg)); | |
290 | cmd->size = cpu_to_le16(le16_to_cpu(cmd->size) + | |
291 | sizeof(struct mwifiex_types_power_group) + | |
292 | pg_tlv->length); | |
293 | } else { | |
a5ffddb7 | 294 | memmove(cmd_txp_cfg, txp, sizeof(*txp)); |
5e6e3a92 BZ |
295 | } |
296 | cmd_txp_cfg->action = cpu_to_le16(cmd_action); | |
297 | break; | |
298 | case HostCmd_ACT_GEN_GET: | |
299 | cmd_txp_cfg->action = cpu_to_le16(cmd_action); | |
300 | break; | |
301 | } | |
302 | ||
303 | return 0; | |
304 | } | |
305 | ||
306 | /* | |
307 | * This function prepares command to set Host Sleep configuration. | |
308 | * | |
309 | * Preparation includes - | |
310 | * - Setting command ID and proper size | |
311 | * - Setting Host Sleep action, conditions, ARP filters | |
312 | * (as required) | |
313 | * - Ensuring correct endian-ness | |
314 | */ | |
a5ffddb7 AK |
315 | static int |
316 | mwifiex_cmd_802_11_hs_cfg(struct mwifiex_private *priv, | |
317 | struct host_cmd_ds_command *cmd, | |
318 | u16 cmd_action, | |
319 | struct mwifiex_hs_config_param *hscfg_param) | |
5e6e3a92 BZ |
320 | { |
321 | struct mwifiex_adapter *adapter = priv->adapter; | |
322 | struct host_cmd_ds_802_11_hs_cfg_enh *hs_cfg = &cmd->params.opt_hs_cfg; | |
323 | u16 hs_activate = false; | |
324 | ||
a5ffddb7 | 325 | if (!hscfg_param) |
5e6e3a92 BZ |
326 | /* New Activate command */ |
327 | hs_activate = true; | |
328 | cmd->command = cpu_to_le16(HostCmd_CMD_802_11_HS_CFG_ENH); | |
329 | ||
330 | if (!hs_activate && | |
a5ffddb7 | 331 | (hscfg_param->conditions |
5e6e3a92 BZ |
332 | != cpu_to_le32(HOST_SLEEP_CFG_CANCEL)) |
333 | && ((adapter->arp_filter_size > 0) | |
334 | && (adapter->arp_filter_size <= ARP_FILTER_MAX_BUF_SIZE))) { | |
335 | dev_dbg(adapter->dev, | |
336 | "cmd: Attach %d bytes ArpFilter to HSCfg cmd\n", | |
337 | adapter->arp_filter_size); | |
338 | memcpy(((u8 *) hs_cfg) + | |
339 | sizeof(struct host_cmd_ds_802_11_hs_cfg_enh), | |
340 | adapter->arp_filter, adapter->arp_filter_size); | |
341 | cmd->size = cpu_to_le16(adapter->arp_filter_size + | |
342 | sizeof(struct host_cmd_ds_802_11_hs_cfg_enh) | |
343 | + S_DS_GEN); | |
344 | } else { | |
345 | cmd->size = cpu_to_le16(S_DS_GEN + sizeof(struct | |
346 | host_cmd_ds_802_11_hs_cfg_enh)); | |
347 | } | |
348 | if (hs_activate) { | |
349 | hs_cfg->action = cpu_to_le16(HS_ACTIVATE); | |
350 | hs_cfg->params.hs_activate.resp_ctrl = RESP_NEEDED; | |
351 | } else { | |
352 | hs_cfg->action = cpu_to_le16(HS_CONFIGURE); | |
a5ffddb7 AK |
353 | hs_cfg->params.hs_config.conditions = hscfg_param->conditions; |
354 | hs_cfg->params.hs_config.gpio = hscfg_param->gpio; | |
355 | hs_cfg->params.hs_config.gap = hscfg_param->gap; | |
5e6e3a92 BZ |
356 | dev_dbg(adapter->dev, |
357 | "cmd: HS_CFG_CMD: condition:0x%x gpio:0x%x gap:0x%x\n", | |
358 | hs_cfg->params.hs_config.conditions, | |
359 | hs_cfg->params.hs_config.gpio, | |
360 | hs_cfg->params.hs_config.gap); | |
361 | } | |
362 | ||
363 | return 0; | |
364 | } | |
365 | ||
366 | /* | |
367 | * This function prepares command to set/get MAC address. | |
368 | * | |
369 | * Preparation includes - | |
370 | * - Setting command ID, action and proper size | |
371 | * - Setting MAC address (for SET only) | |
372 | * - Ensuring correct endian-ness | |
373 | */ | |
374 | static int mwifiex_cmd_802_11_mac_address(struct mwifiex_private *priv, | |
375 | struct host_cmd_ds_command *cmd, | |
376 | u16 cmd_action) | |
377 | { | |
378 | cmd->command = cpu_to_le16(HostCmd_CMD_802_11_MAC_ADDRESS); | |
379 | cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_802_11_mac_address) + | |
380 | S_DS_GEN); | |
381 | cmd->result = 0; | |
382 | ||
383 | cmd->params.mac_addr.action = cpu_to_le16(cmd_action); | |
384 | ||
385 | if (cmd_action == HostCmd_ACT_GEN_SET) | |
386 | memcpy(cmd->params.mac_addr.mac_addr, priv->curr_addr, | |
387 | ETH_ALEN); | |
388 | return 0; | |
389 | } | |
390 | ||
391 | /* | |
392 | * This function prepares command to set MAC multicast address. | |
393 | * | |
394 | * Preparation includes - | |
395 | * - Setting command ID, action and proper size | |
396 | * - Setting MAC multicast address | |
397 | * - Ensuring correct endian-ness | |
398 | */ | |
a5ffddb7 AK |
399 | static int |
400 | mwifiex_cmd_mac_multicast_adr(struct host_cmd_ds_command *cmd, | |
401 | u16 cmd_action, | |
402 | struct mwifiex_multicast_list *mcast_list) | |
5e6e3a92 | 403 | { |
5e6e3a92 BZ |
404 | struct host_cmd_ds_mac_multicast_adr *mcast_addr = &cmd->params.mc_addr; |
405 | ||
406 | cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_mac_multicast_adr) + | |
407 | S_DS_GEN); | |
408 | cmd->command = cpu_to_le16(HostCmd_CMD_MAC_MULTICAST_ADR); | |
409 | ||
410 | mcast_addr->action = cpu_to_le16(cmd_action); | |
411 | mcast_addr->num_of_adrs = | |
412 | cpu_to_le16((u16) mcast_list->num_multicast_addr); | |
413 | memcpy(mcast_addr->mac_list, mcast_list->mac_list, | |
414 | mcast_list->num_multicast_addr * ETH_ALEN); | |
415 | ||
416 | return 0; | |
417 | } | |
418 | ||
419 | /* | |
420 | * This function prepares command to deauthenticate. | |
421 | * | |
422 | * Preparation includes - | |
423 | * - Setting command ID and proper size | |
424 | * - Setting AP MAC address and reason code | |
425 | * - Ensuring correct endian-ness | |
426 | */ | |
427 | static int mwifiex_cmd_802_11_deauthenticate(struct mwifiex_private *priv, | |
428 | struct host_cmd_ds_command *cmd, | |
a5ffddb7 | 429 | u8 *mac) |
5e6e3a92 BZ |
430 | { |
431 | struct host_cmd_ds_802_11_deauthenticate *deauth = &cmd->params.deauth; | |
432 | ||
433 | cmd->command = cpu_to_le16(HostCmd_CMD_802_11_DEAUTHENTICATE); | |
434 | cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_802_11_deauthenticate) | |
435 | + S_DS_GEN); | |
436 | ||
437 | /* Set AP MAC address */ | |
a5ffddb7 | 438 | memcpy(deauth->mac_addr, mac, ETH_ALEN); |
5e6e3a92 BZ |
439 | |
440 | dev_dbg(priv->adapter->dev, "cmd: Deauth: %pM\n", deauth->mac_addr); | |
441 | ||
442 | deauth->reason_code = cpu_to_le16(WLAN_REASON_DEAUTH_LEAVING); | |
443 | ||
444 | return 0; | |
445 | } | |
446 | ||
447 | /* | |
448 | * This function prepares command to stop Ad-Hoc network. | |
449 | * | |
450 | * Preparation includes - | |
451 | * - Setting command ID and proper size | |
452 | * - Ensuring correct endian-ness | |
453 | */ | |
572e8f3e | 454 | static int mwifiex_cmd_802_11_ad_hoc_stop(struct host_cmd_ds_command *cmd) |
5e6e3a92 BZ |
455 | { |
456 | cmd->command = cpu_to_le16(HostCmd_CMD_802_11_AD_HOC_STOP); | |
457 | cmd->size = cpu_to_le16(S_DS_GEN); | |
458 | return 0; | |
459 | } | |
460 | ||
461 | /* | |
462 | * This function sets WEP key(s) to key parameter TLV(s). | |
463 | * | |
464 | * Multi-key parameter TLVs are supported, so we can send multiple | |
465 | * WEP keys in a single buffer. | |
466 | */ | |
467 | static int | |
468 | mwifiex_set_keyparamset_wep(struct mwifiex_private *priv, | |
469 | struct mwifiex_ie_type_key_param_set *key_param_set, | |
470 | u16 *key_param_len) | |
471 | { | |
270e58e8 | 472 | int cur_key_param_len; |
5e6e3a92 BZ |
473 | u8 i; |
474 | ||
475 | /* Multi-key_param_set TLV is supported */ | |
476 | for (i = 0; i < NUM_WEP_KEYS; i++) { | |
477 | if ((priv->wep_key[i].key_length == WLAN_KEY_LEN_WEP40) || | |
478 | (priv->wep_key[i].key_length == WLAN_KEY_LEN_WEP104)) { | |
479 | key_param_set->type = | |
480 | cpu_to_le16(TLV_TYPE_KEY_MATERIAL); | |
481 | /* Key_param_set WEP fixed length */ | |
482 | #define KEYPARAMSET_WEP_FIXED_LEN 8 | |
483 | key_param_set->length = cpu_to_le16((u16) | |
484 | (priv->wep_key[i]. | |
485 | key_length + | |
486 | KEYPARAMSET_WEP_FIXED_LEN)); | |
487 | key_param_set->key_type_id = | |
488 | cpu_to_le16(KEY_TYPE_ID_WEP); | |
489 | key_param_set->key_info = | |
6a35a0ac YAP |
490 | cpu_to_le16(KEY_ENABLED | KEY_UNICAST | |
491 | KEY_MCAST); | |
5e6e3a92 BZ |
492 | key_param_set->key_len = |
493 | cpu_to_le16(priv->wep_key[i].key_length); | |
494 | /* Set WEP key index */ | |
495 | key_param_set->key[0] = i; | |
496 | /* Set default Tx key flag */ | |
497 | if (i == | |
498 | (priv-> | |
499 | wep_key_curr_index & HostCmd_WEP_KEY_INDEX_MASK)) | |
500 | key_param_set->key[1] = 1; | |
501 | else | |
502 | key_param_set->key[1] = 0; | |
503 | memmove(&key_param_set->key[2], | |
504 | priv->wep_key[i].key_material, | |
505 | priv->wep_key[i].key_length); | |
506 | ||
507 | cur_key_param_len = priv->wep_key[i].key_length + | |
508 | KEYPARAMSET_WEP_FIXED_LEN + | |
509 | sizeof(struct mwifiex_ie_types_header); | |
510 | *key_param_len += (u16) cur_key_param_len; | |
511 | key_param_set = | |
512 | (struct mwifiex_ie_type_key_param_set *) | |
513 | ((u8 *)key_param_set + | |
514 | cur_key_param_len); | |
515 | } else if (!priv->wep_key[i].key_length) { | |
516 | continue; | |
517 | } else { | |
518 | dev_err(priv->adapter->dev, | |
519 | "key%d Length = %d is incorrect\n", | |
520 | (i + 1), priv->wep_key[i].key_length); | |
521 | return -1; | |
522 | } | |
523 | } | |
524 | ||
525 | return 0; | |
526 | } | |
527 | ||
528 | /* | |
529 | * This function prepares command to set/get/reset network key(s). | |
530 | * | |
531 | * Preparation includes - | |
532 | * - Setting command ID, action and proper size | |
533 | * - Setting WEP keys, WAPI keys or WPA keys along with required | |
534 | * encryption (TKIP, AES) (as required) | |
535 | * - Ensuring correct endian-ness | |
536 | */ | |
a5ffddb7 AK |
537 | static int |
538 | mwifiex_cmd_802_11_key_material(struct mwifiex_private *priv, | |
539 | struct host_cmd_ds_command *cmd, | |
540 | u16 cmd_action, u32 cmd_oid, | |
541 | struct mwifiex_ds_encrypt_key *enc_key) | |
5e6e3a92 BZ |
542 | { |
543 | struct host_cmd_ds_802_11_key_material *key_material = | |
544 | &cmd->params.key_material; | |
5e6e3a92 BZ |
545 | u16 key_param_len = 0; |
546 | int ret = 0; | |
547 | const u8 bc_mac[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; | |
548 | ||
549 | cmd->command = cpu_to_le16(HostCmd_CMD_802_11_KEY_MATERIAL); | |
550 | key_material->action = cpu_to_le16(cmd_action); | |
551 | ||
552 | if (cmd_action == HostCmd_ACT_GEN_GET) { | |
553 | cmd->size = | |
554 | cpu_to_le16(sizeof(key_material->action) + S_DS_GEN); | |
555 | return ret; | |
556 | } | |
557 | ||
558 | if (!enc_key) { | |
559 | memset(&key_material->key_param_set, 0, | |
560 | (NUM_WEP_KEYS * | |
561 | sizeof(struct mwifiex_ie_type_key_param_set))); | |
562 | ret = mwifiex_set_keyparamset_wep(priv, | |
563 | &key_material->key_param_set, | |
564 | &key_param_len); | |
565 | cmd->size = cpu_to_le16(key_param_len + | |
566 | sizeof(key_material->action) + S_DS_GEN); | |
567 | return ret; | |
568 | } else | |
569 | memset(&key_material->key_param_set, 0, | |
570 | sizeof(struct mwifiex_ie_type_key_param_set)); | |
571 | if (enc_key->is_wapi_key) { | |
572 | dev_dbg(priv->adapter->dev, "info: Set WAPI Key\n"); | |
573 | key_material->key_param_set.key_type_id = | |
574 | cpu_to_le16(KEY_TYPE_ID_WAPI); | |
575 | if (cmd_oid == KEY_INFO_ENABLED) | |
576 | key_material->key_param_set.key_info = | |
6a35a0ac | 577 | cpu_to_le16(KEY_ENABLED); |
5e6e3a92 BZ |
578 | else |
579 | key_material->key_param_set.key_info = | |
6a35a0ac | 580 | cpu_to_le16(!KEY_ENABLED); |
5e6e3a92 BZ |
581 | |
582 | key_material->key_param_set.key[0] = enc_key->key_index; | |
583 | if (!priv->sec_info.wapi_key_on) | |
584 | key_material->key_param_set.key[1] = 1; | |
585 | else | |
586 | /* set 0 when re-key */ | |
587 | key_material->key_param_set.key[1] = 0; | |
588 | ||
589 | if (0 != memcmp(enc_key->mac_addr, bc_mac, sizeof(bc_mac))) { | |
590 | /* WAPI pairwise key: unicast */ | |
591 | key_material->key_param_set.key_info |= | |
6a35a0ac | 592 | cpu_to_le16(KEY_UNICAST); |
5e6e3a92 BZ |
593 | } else { /* WAPI group key: multicast */ |
594 | key_material->key_param_set.key_info |= | |
6a35a0ac | 595 | cpu_to_le16(KEY_MCAST); |
5e6e3a92 BZ |
596 | priv->sec_info.wapi_key_on = true; |
597 | } | |
598 | ||
599 | key_material->key_param_set.type = | |
600 | cpu_to_le16(TLV_TYPE_KEY_MATERIAL); | |
601 | key_material->key_param_set.key_len = | |
602 | cpu_to_le16(WAPI_KEY_LEN); | |
603 | memcpy(&key_material->key_param_set.key[2], | |
604 | enc_key->key_material, enc_key->key_len); | |
605 | memcpy(&key_material->key_param_set.key[2 + enc_key->key_len], | |
606 | enc_key->wapi_rxpn, WAPI_RXPN_LEN); | |
607 | key_material->key_param_set.length = | |
608 | cpu_to_le16(WAPI_KEY_LEN + KEYPARAMSET_FIXED_LEN); | |
609 | ||
610 | key_param_len = (WAPI_KEY_LEN + KEYPARAMSET_FIXED_LEN) + | |
611 | sizeof(struct mwifiex_ie_types_header); | |
612 | cmd->size = cpu_to_le16(key_param_len + | |
613 | sizeof(key_material->action) + S_DS_GEN); | |
614 | return ret; | |
615 | } | |
616 | if (enc_key->key_len == WLAN_KEY_LEN_CCMP) { | |
617 | dev_dbg(priv->adapter->dev, "cmd: WPA_AES\n"); | |
618 | key_material->key_param_set.key_type_id = | |
619 | cpu_to_le16(KEY_TYPE_ID_AES); | |
620 | if (cmd_oid == KEY_INFO_ENABLED) | |
621 | key_material->key_param_set.key_info = | |
6a35a0ac | 622 | cpu_to_le16(KEY_ENABLED); |
5e6e3a92 BZ |
623 | else |
624 | key_material->key_param_set.key_info = | |
6a35a0ac | 625 | cpu_to_le16(!KEY_ENABLED); |
5e6e3a92 BZ |
626 | |
627 | if (enc_key->key_index & MWIFIEX_KEY_INDEX_UNICAST) | |
628 | /* AES pairwise key: unicast */ | |
629 | key_material->key_param_set.key_info |= | |
6a35a0ac | 630 | cpu_to_le16(KEY_UNICAST); |
5e6e3a92 BZ |
631 | else /* AES group key: multicast */ |
632 | key_material->key_param_set.key_info |= | |
6a35a0ac | 633 | cpu_to_le16(KEY_MCAST); |
5e6e3a92 BZ |
634 | } else if (enc_key->key_len == WLAN_KEY_LEN_TKIP) { |
635 | dev_dbg(priv->adapter->dev, "cmd: WPA_TKIP\n"); | |
636 | key_material->key_param_set.key_type_id = | |
637 | cpu_to_le16(KEY_TYPE_ID_TKIP); | |
638 | key_material->key_param_set.key_info = | |
6a35a0ac | 639 | cpu_to_le16(KEY_ENABLED); |
5e6e3a92 BZ |
640 | |
641 | if (enc_key->key_index & MWIFIEX_KEY_INDEX_UNICAST) | |
642 | /* TKIP pairwise key: unicast */ | |
643 | key_material->key_param_set.key_info |= | |
6a35a0ac | 644 | cpu_to_le16(KEY_UNICAST); |
5e6e3a92 BZ |
645 | else /* TKIP group key: multicast */ |
646 | key_material->key_param_set.key_info |= | |
6a35a0ac | 647 | cpu_to_le16(KEY_MCAST); |
5e6e3a92 BZ |
648 | } |
649 | ||
650 | if (key_material->key_param_set.key_type_id) { | |
651 | key_material->key_param_set.type = | |
652 | cpu_to_le16(TLV_TYPE_KEY_MATERIAL); | |
653 | key_material->key_param_set.key_len = | |
654 | cpu_to_le16((u16) enc_key->key_len); | |
655 | memcpy(key_material->key_param_set.key, enc_key->key_material, | |
656 | enc_key->key_len); | |
657 | key_material->key_param_set.length = | |
658 | cpu_to_le16((u16) enc_key->key_len + | |
659 | KEYPARAMSET_FIXED_LEN); | |
660 | ||
661 | key_param_len = (u16) (enc_key->key_len + KEYPARAMSET_FIXED_LEN) | |
662 | + sizeof(struct mwifiex_ie_types_header); | |
663 | ||
664 | cmd->size = cpu_to_le16(key_param_len + | |
665 | sizeof(key_material->action) + S_DS_GEN); | |
666 | } | |
667 | ||
668 | return ret; | |
669 | } | |
670 | ||
671 | /* | |
672 | * This function prepares command to set/get 11d domain information. | |
673 | * | |
674 | * Preparation includes - | |
675 | * - Setting command ID, action and proper size | |
676 | * - Setting domain information fields (for SET only) | |
677 | * - Ensuring correct endian-ness | |
678 | */ | |
679 | static int mwifiex_cmd_802_11d_domain_info(struct mwifiex_private *priv, | |
680 | struct host_cmd_ds_command *cmd, | |
681 | u16 cmd_action) | |
682 | { | |
683 | struct mwifiex_adapter *adapter = priv->adapter; | |
684 | struct host_cmd_ds_802_11d_domain_info *domain_info = | |
685 | &cmd->params.domain_info; | |
686 | struct mwifiex_ietypes_domain_param_set *domain = | |
687 | &domain_info->domain; | |
688 | u8 no_of_triplet = adapter->domain_reg.no_of_triplet; | |
689 | ||
690 | dev_dbg(adapter->dev, "info: 11D: no_of_triplet=0x%x\n", no_of_triplet); | |
691 | ||
692 | cmd->command = cpu_to_le16(HostCmd_CMD_802_11D_DOMAIN_INFO); | |
693 | domain_info->action = cpu_to_le16(cmd_action); | |
694 | if (cmd_action == HostCmd_ACT_GEN_GET) { | |
695 | cmd->size = cpu_to_le16(sizeof(domain_info->action) + S_DS_GEN); | |
696 | return 0; | |
697 | } | |
698 | ||
699 | /* Set domain info fields */ | |
700 | domain->header.type = cpu_to_le16(WLAN_EID_COUNTRY); | |
701 | memcpy(domain->country_code, adapter->domain_reg.country_code, | |
702 | sizeof(domain->country_code)); | |
703 | ||
704 | domain->header.len = cpu_to_le16((no_of_triplet * | |
705 | sizeof(struct ieee80211_country_ie_triplet)) + | |
706 | sizeof(domain->country_code)); | |
707 | ||
708 | if (no_of_triplet) { | |
709 | memcpy(domain->triplet, adapter->domain_reg.triplet, | |
710 | no_of_triplet * | |
711 | sizeof(struct ieee80211_country_ie_triplet)); | |
712 | ||
713 | cmd->size = cpu_to_le16(sizeof(domain_info->action) + | |
714 | le16_to_cpu(domain->header.len) + | |
715 | sizeof(struct mwifiex_ie_types_header) | |
716 | + S_DS_GEN); | |
717 | } else { | |
718 | cmd->size = cpu_to_le16(sizeof(domain_info->action) + S_DS_GEN); | |
719 | } | |
720 | ||
721 | return 0; | |
722 | } | |
723 | ||
724 | /* | |
725 | * This function prepares command to set/get RF channel. | |
726 | * | |
727 | * Preparation includes - | |
728 | * - Setting command ID, action and proper size | |
729 | * - Setting RF type and current RF channel (for SET only) | |
730 | * - Ensuring correct endian-ness | |
731 | */ | |
732 | static int mwifiex_cmd_802_11_rf_channel(struct mwifiex_private *priv, | |
733 | struct host_cmd_ds_command *cmd, | |
a5ffddb7 | 734 | u16 cmd_action, u16 *channel) |
5e6e3a92 BZ |
735 | { |
736 | struct host_cmd_ds_802_11_rf_channel *rf_chan = | |
737 | &cmd->params.rf_channel; | |
738 | uint16_t rf_type = le16_to_cpu(rf_chan->rf_type); | |
739 | ||
740 | cmd->command = cpu_to_le16(HostCmd_CMD_802_11_RF_CHANNEL); | |
741 | cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_802_11_rf_channel) | |
742 | + S_DS_GEN); | |
743 | ||
744 | if (cmd_action == HostCmd_ACT_GEN_SET) { | |
745 | if ((priv->adapter->adhoc_start_band & BAND_A) | |
746 | || (priv->adapter->adhoc_start_band & BAND_AN)) | |
747 | rf_chan->rf_type = | |
748 | cpu_to_le16(HostCmd_SCAN_RADIO_TYPE_A); | |
749 | ||
750 | rf_type = le16_to_cpu(rf_chan->rf_type); | |
751 | SET_SECONDARYCHAN(rf_type, priv->adapter->chan_offset); | |
a5ffddb7 | 752 | rf_chan->current_channel = cpu_to_le16(*channel); |
5e6e3a92 BZ |
753 | } |
754 | rf_chan->action = cpu_to_le16(cmd_action); | |
755 | return 0; | |
756 | } | |
757 | ||
758 | /* | |
759 | * This function prepares command to set/get IBSS coalescing status. | |
760 | * | |
761 | * Preparation includes - | |
762 | * - Setting command ID, action and proper size | |
763 | * - Setting status to enable or disable (for SET only) | |
764 | * - Ensuring correct endian-ness | |
765 | */ | |
572e8f3e | 766 | static int mwifiex_cmd_ibss_coalescing_status(struct host_cmd_ds_command *cmd, |
a5ffddb7 | 767 | u16 cmd_action, u16 *enable) |
5e6e3a92 BZ |
768 | { |
769 | struct host_cmd_ds_802_11_ibss_status *ibss_coal = | |
770 | &(cmd->params.ibss_coalescing); | |
5e6e3a92 BZ |
771 | |
772 | cmd->command = cpu_to_le16(HostCmd_CMD_802_11_IBSS_COALESCING_STATUS); | |
773 | cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_802_11_ibss_status) + | |
774 | S_DS_GEN); | |
775 | cmd->result = 0; | |
776 | ibss_coal->action = cpu_to_le16(cmd_action); | |
777 | ||
778 | switch (cmd_action) { | |
779 | case HostCmd_ACT_GEN_SET: | |
a5ffddb7 AK |
780 | if (enable) |
781 | ibss_coal->enable = cpu_to_le16(*enable); | |
a5e5aa6c DC |
782 | else |
783 | ibss_coal->enable = 0; | |
5e6e3a92 BZ |
784 | break; |
785 | ||
786 | /* In other case.. Nothing to do */ | |
787 | case HostCmd_ACT_GEN_GET: | |
788 | default: | |
789 | break; | |
790 | } | |
791 | ||
792 | return 0; | |
793 | } | |
794 | ||
795 | /* | |
796 | * This function prepares command to set/get register value. | |
797 | * | |
798 | * Preparation includes - | |
799 | * - Setting command ID, action and proper size | |
800 | * - Setting register offset (for both GET and SET) and | |
801 | * register value (for SET only) | |
802 | * - Ensuring correct endian-ness | |
803 | * | |
804 | * The following type of registers can be accessed with this function - | |
805 | * - MAC register | |
806 | * - BBP register | |
807 | * - RF register | |
808 | * - PMIC register | |
809 | * - CAU register | |
810 | * - EEPROM | |
811 | */ | |
812 | static int mwifiex_cmd_reg_access(struct host_cmd_ds_command *cmd, | |
813 | u16 cmd_action, void *data_buf) | |
814 | { | |
a5ffddb7 | 815 | struct mwifiex_ds_reg_rw *reg_rw = data_buf; |
5e6e3a92 | 816 | |
5e6e3a92 BZ |
817 | switch (le16_to_cpu(cmd->command)) { |
818 | case HostCmd_CMD_MAC_REG_ACCESS: | |
819 | { | |
820 | struct host_cmd_ds_mac_reg_access *mac_reg; | |
821 | ||
822 | cmd->size = cpu_to_le16(sizeof(*mac_reg) + S_DS_GEN); | |
823 | mac_reg = (struct host_cmd_ds_mac_reg_access *) &cmd-> | |
824 | params.mac_reg; | |
825 | mac_reg->action = cpu_to_le16(cmd_action); | |
826 | mac_reg->offset = | |
827 | cpu_to_le16((u16) le32_to_cpu(reg_rw->offset)); | |
828 | mac_reg->value = reg_rw->value; | |
829 | break; | |
830 | } | |
831 | case HostCmd_CMD_BBP_REG_ACCESS: | |
832 | { | |
833 | struct host_cmd_ds_bbp_reg_access *bbp_reg; | |
834 | ||
835 | cmd->size = cpu_to_le16(sizeof(*bbp_reg) + S_DS_GEN); | |
836 | bbp_reg = (struct host_cmd_ds_bbp_reg_access *) &cmd-> | |
837 | params.bbp_reg; | |
838 | bbp_reg->action = cpu_to_le16(cmd_action); | |
839 | bbp_reg->offset = | |
840 | cpu_to_le16((u16) le32_to_cpu(reg_rw->offset)); | |
841 | bbp_reg->value = (u8) le32_to_cpu(reg_rw->value); | |
842 | break; | |
843 | } | |
844 | case HostCmd_CMD_RF_REG_ACCESS: | |
845 | { | |
846 | struct host_cmd_ds_rf_reg_access *rf_reg; | |
847 | ||
848 | cmd->size = cpu_to_le16(sizeof(*rf_reg) + S_DS_GEN); | |
849 | rf_reg = (struct host_cmd_ds_rf_reg_access *) &cmd-> | |
850 | params.rf_reg; | |
851 | rf_reg->action = cpu_to_le16(cmd_action); | |
852 | rf_reg->offset = | |
853 | cpu_to_le16((u16) le32_to_cpu(reg_rw->offset)); | |
854 | rf_reg->value = (u8) le32_to_cpu(reg_rw->value); | |
855 | break; | |
856 | } | |
857 | case HostCmd_CMD_PMIC_REG_ACCESS: | |
858 | { | |
859 | struct host_cmd_ds_pmic_reg_access *pmic_reg; | |
860 | ||
861 | cmd->size = cpu_to_le16(sizeof(*pmic_reg) + S_DS_GEN); | |
862 | pmic_reg = (struct host_cmd_ds_pmic_reg_access *) &cmd-> | |
863 | params.pmic_reg; | |
864 | pmic_reg->action = cpu_to_le16(cmd_action); | |
865 | pmic_reg->offset = | |
866 | cpu_to_le16((u16) le32_to_cpu(reg_rw->offset)); | |
867 | pmic_reg->value = (u8) le32_to_cpu(reg_rw->value); | |
868 | break; | |
869 | } | |
870 | case HostCmd_CMD_CAU_REG_ACCESS: | |
871 | { | |
872 | struct host_cmd_ds_rf_reg_access *cau_reg; | |
873 | ||
874 | cmd->size = cpu_to_le16(sizeof(*cau_reg) + S_DS_GEN); | |
875 | cau_reg = (struct host_cmd_ds_rf_reg_access *) &cmd-> | |
876 | params.rf_reg; | |
877 | cau_reg->action = cpu_to_le16(cmd_action); | |
878 | cau_reg->offset = | |
879 | cpu_to_le16((u16) le32_to_cpu(reg_rw->offset)); | |
880 | cau_reg->value = (u8) le32_to_cpu(reg_rw->value); | |
881 | break; | |
882 | } | |
883 | case HostCmd_CMD_802_11_EEPROM_ACCESS: | |
884 | { | |
a5ffddb7 | 885 | struct mwifiex_ds_read_eeprom *rd_eeprom = data_buf; |
5e6e3a92 BZ |
886 | struct host_cmd_ds_802_11_eeprom_access *cmd_eeprom = |
887 | (struct host_cmd_ds_802_11_eeprom_access *) | |
888 | &cmd->params.eeprom; | |
889 | ||
890 | cmd->size = cpu_to_le16(sizeof(*cmd_eeprom) + S_DS_GEN); | |
891 | cmd_eeprom->action = cpu_to_le16(cmd_action); | |
892 | cmd_eeprom->offset = rd_eeprom->offset; | |
893 | cmd_eeprom->byte_count = rd_eeprom->byte_count; | |
894 | cmd_eeprom->value = 0; | |
895 | break; | |
896 | } | |
897 | default: | |
898 | return -1; | |
899 | } | |
900 | ||
901 | return 0; | |
902 | } | |
903 | ||
904 | /* | |
905 | * This function prepares the commands before sending them to the firmware. | |
906 | * | |
907 | * This is a generic function which calls specific command preparation | |
908 | * routines based upon the command number. | |
909 | */ | |
910 | int mwifiex_sta_prepare_cmd(struct mwifiex_private *priv, uint16_t cmd_no, | |
911 | u16 cmd_action, u32 cmd_oid, | |
912 | void *data_buf, void *cmd_buf) | |
913 | { | |
a5ffddb7 | 914 | struct host_cmd_ds_command *cmd_ptr = cmd_buf; |
5e6e3a92 BZ |
915 | int ret = 0; |
916 | ||
917 | /* Prepare command */ | |
918 | switch (cmd_no) { | |
919 | case HostCmd_CMD_GET_HW_SPEC: | |
920 | ret = mwifiex_cmd_get_hw_spec(priv, cmd_ptr); | |
921 | break; | |
922 | case HostCmd_CMD_MAC_CONTROL: | |
923 | ret = mwifiex_cmd_mac_control(priv, cmd_ptr, cmd_action, | |
924 | data_buf); | |
925 | break; | |
926 | case HostCmd_CMD_802_11_MAC_ADDRESS: | |
927 | ret = mwifiex_cmd_802_11_mac_address(priv, cmd_ptr, | |
928 | cmd_action); | |
929 | break; | |
930 | case HostCmd_CMD_MAC_MULTICAST_ADR: | |
572e8f3e | 931 | ret = mwifiex_cmd_mac_multicast_adr(cmd_ptr, cmd_action, |
5e6e3a92 BZ |
932 | data_buf); |
933 | break; | |
934 | case HostCmd_CMD_TX_RATE_CFG: | |
935 | ret = mwifiex_cmd_tx_rate_cfg(priv, cmd_ptr, cmd_action, | |
936 | data_buf); | |
937 | break; | |
938 | case HostCmd_CMD_TXPWR_CFG: | |
572e8f3e | 939 | ret = mwifiex_cmd_tx_power_cfg(cmd_ptr, cmd_action, |
5e6e3a92 BZ |
940 | data_buf); |
941 | break; | |
942 | case HostCmd_CMD_802_11_PS_MODE_ENH: | |
943 | ret = mwifiex_cmd_enh_power_mode(priv, cmd_ptr, cmd_action, | |
944 | (uint16_t)cmd_oid, data_buf); | |
945 | break; | |
946 | case HostCmd_CMD_802_11_HS_CFG_ENH: | |
947 | ret = mwifiex_cmd_802_11_hs_cfg(priv, cmd_ptr, cmd_action, | |
948 | (struct mwifiex_hs_config_param *) data_buf); | |
949 | break; | |
950 | case HostCmd_CMD_802_11_SCAN: | |
572e8f3e | 951 | ret = mwifiex_cmd_802_11_scan(cmd_ptr, data_buf); |
5e6e3a92 BZ |
952 | break; |
953 | case HostCmd_CMD_802_11_BG_SCAN_QUERY: | |
572e8f3e | 954 | ret = mwifiex_cmd_802_11_bg_scan_query(cmd_ptr); |
5e6e3a92 BZ |
955 | break; |
956 | case HostCmd_CMD_802_11_ASSOCIATE: | |
957 | ret = mwifiex_cmd_802_11_associate(priv, cmd_ptr, data_buf); | |
958 | break; | |
959 | case HostCmd_CMD_802_11_DEAUTHENTICATE: | |
960 | ret = mwifiex_cmd_802_11_deauthenticate(priv, cmd_ptr, | |
961 | data_buf); | |
962 | break; | |
963 | case HostCmd_CMD_802_11_AD_HOC_START: | |
964 | ret = mwifiex_cmd_802_11_ad_hoc_start(priv, cmd_ptr, | |
965 | data_buf); | |
966 | break; | |
967 | case HostCmd_CMD_802_11_GET_LOG: | |
572e8f3e | 968 | ret = mwifiex_cmd_802_11_get_log(cmd_ptr); |
5e6e3a92 BZ |
969 | break; |
970 | case HostCmd_CMD_802_11_AD_HOC_JOIN: | |
971 | ret = mwifiex_cmd_802_11_ad_hoc_join(priv, cmd_ptr, | |
972 | data_buf); | |
973 | break; | |
974 | case HostCmd_CMD_802_11_AD_HOC_STOP: | |
572e8f3e | 975 | ret = mwifiex_cmd_802_11_ad_hoc_stop(cmd_ptr); |
5e6e3a92 BZ |
976 | break; |
977 | case HostCmd_CMD_RSSI_INFO: | |
978 | ret = mwifiex_cmd_802_11_rssi_info(priv, cmd_ptr, cmd_action); | |
979 | break; | |
980 | case HostCmd_CMD_802_11_SNMP_MIB: | |
981 | ret = mwifiex_cmd_802_11_snmp_mib(priv, cmd_ptr, cmd_action, | |
982 | cmd_oid, data_buf); | |
983 | break; | |
984 | case HostCmd_CMD_802_11_TX_RATE_QUERY: | |
985 | cmd_ptr->command = | |
986 | cpu_to_le16(HostCmd_CMD_802_11_TX_RATE_QUERY); | |
987 | cmd_ptr->size = | |
988 | cpu_to_le16(sizeof(struct host_cmd_ds_tx_rate_query) + | |
989 | S_DS_GEN); | |
990 | priv->tx_rate = 0; | |
991 | ret = 0; | |
992 | break; | |
993 | case HostCmd_CMD_VERSION_EXT: | |
994 | cmd_ptr->command = cpu_to_le16(cmd_no); | |
995 | cmd_ptr->params.verext.version_str_sel = | |
996 | (u8) (*((u32 *) data_buf)); | |
997 | memcpy(&cmd_ptr->params, data_buf, | |
998 | sizeof(struct host_cmd_ds_version_ext)); | |
999 | cmd_ptr->size = | |
1000 | cpu_to_le16(sizeof(struct host_cmd_ds_version_ext) + | |
1001 | S_DS_GEN); | |
1002 | ret = 0; | |
1003 | break; | |
1004 | case HostCmd_CMD_802_11_RF_CHANNEL: | |
1005 | ret = mwifiex_cmd_802_11_rf_channel(priv, cmd_ptr, cmd_action, | |
1006 | data_buf); | |
1007 | break; | |
1008 | case HostCmd_CMD_FUNC_INIT: | |
1009 | if (priv->adapter->hw_status == MWIFIEX_HW_STATUS_RESET) | |
1010 | priv->adapter->hw_status = MWIFIEX_HW_STATUS_READY; | |
1011 | cmd_ptr->command = cpu_to_le16(cmd_no); | |
1012 | cmd_ptr->size = cpu_to_le16(S_DS_GEN); | |
1013 | break; | |
1014 | case HostCmd_CMD_FUNC_SHUTDOWN: | |
1015 | priv->adapter->hw_status = MWIFIEX_HW_STATUS_RESET; | |
1016 | cmd_ptr->command = cpu_to_le16(cmd_no); | |
1017 | cmd_ptr->size = cpu_to_le16(S_DS_GEN); | |
1018 | break; | |
1019 | case HostCmd_CMD_11N_ADDBA_REQ: | |
572e8f3e | 1020 | ret = mwifiex_cmd_11n_addba_req(cmd_ptr, data_buf); |
5e6e3a92 BZ |
1021 | break; |
1022 | case HostCmd_CMD_11N_DELBA: | |
572e8f3e | 1023 | ret = mwifiex_cmd_11n_delba(cmd_ptr, data_buf); |
5e6e3a92 BZ |
1024 | break; |
1025 | case HostCmd_CMD_11N_ADDBA_RSP: | |
1026 | ret = mwifiex_cmd_11n_addba_rsp_gen(priv, cmd_ptr, data_buf); | |
1027 | break; | |
1028 | case HostCmd_CMD_802_11_KEY_MATERIAL: | |
1029 | ret = mwifiex_cmd_802_11_key_material(priv, cmd_ptr, | |
1030 | cmd_action, cmd_oid, | |
1031 | data_buf); | |
1032 | break; | |
1033 | case HostCmd_CMD_802_11D_DOMAIN_INFO: | |
1034 | ret = mwifiex_cmd_802_11d_domain_info(priv, cmd_ptr, | |
1035 | cmd_action); | |
1036 | break; | |
1037 | case HostCmd_CMD_RECONFIGURE_TX_BUFF: | |
1038 | ret = mwifiex_cmd_recfg_tx_buf(priv, cmd_ptr, cmd_action, | |
1039 | data_buf); | |
1040 | break; | |
1041 | case HostCmd_CMD_AMSDU_AGGR_CTRL: | |
572e8f3e | 1042 | ret = mwifiex_cmd_amsdu_aggr_ctrl(cmd_ptr, cmd_action, |
5e6e3a92 BZ |
1043 | data_buf); |
1044 | break; | |
1045 | case HostCmd_CMD_11N_CFG: | |
572e8f3e | 1046 | ret = mwifiex_cmd_11n_cfg(cmd_ptr, cmd_action, |
5e6e3a92 BZ |
1047 | data_buf); |
1048 | break; | |
1049 | case HostCmd_CMD_WMM_GET_STATUS: | |
1050 | dev_dbg(priv->adapter->dev, | |
1051 | "cmd: WMM: WMM_GET_STATUS cmd sent\n"); | |
1052 | cmd_ptr->command = cpu_to_le16(HostCmd_CMD_WMM_GET_STATUS); | |
1053 | cmd_ptr->size = | |
1054 | cpu_to_le16(sizeof(struct host_cmd_ds_wmm_get_status) + | |
1055 | S_DS_GEN); | |
1056 | ret = 0; | |
1057 | break; | |
1058 | case HostCmd_CMD_802_11_IBSS_COALESCING_STATUS: | |
572e8f3e AK |
1059 | ret = mwifiex_cmd_ibss_coalescing_status(cmd_ptr, cmd_action, |
1060 | data_buf); | |
5e6e3a92 BZ |
1061 | break; |
1062 | case HostCmd_CMD_MAC_REG_ACCESS: | |
1063 | case HostCmd_CMD_BBP_REG_ACCESS: | |
1064 | case HostCmd_CMD_RF_REG_ACCESS: | |
1065 | case HostCmd_CMD_PMIC_REG_ACCESS: | |
1066 | case HostCmd_CMD_CAU_REG_ACCESS: | |
1067 | case HostCmd_CMD_802_11_EEPROM_ACCESS: | |
1068 | ret = mwifiex_cmd_reg_access(cmd_ptr, cmd_action, data_buf); | |
1069 | break; | |
1070 | case HostCmd_CMD_SET_BSS_MODE: | |
1071 | cmd_ptr->command = cpu_to_le16(cmd_no); | |
eecd8250 | 1072 | if (priv->bss_mode == NL80211_IFTYPE_ADHOC) |
5e6e3a92 BZ |
1073 | cmd_ptr->params.bss_mode.con_type = |
1074 | CONNECTION_TYPE_ADHOC; | |
eecd8250 | 1075 | else if (priv->bss_mode == NL80211_IFTYPE_STATION) |
5e6e3a92 BZ |
1076 | cmd_ptr->params.bss_mode.con_type = |
1077 | CONNECTION_TYPE_INFRA; | |
1078 | cmd_ptr->size = cpu_to_le16(sizeof(struct | |
1079 | host_cmd_ds_set_bss_mode) + S_DS_GEN); | |
1080 | ret = 0; | |
1081 | break; | |
1082 | default: | |
1083 | dev_err(priv->adapter->dev, | |
1084 | "PREP_CMD: unknown cmd- %#x\n", cmd_no); | |
1085 | ret = -1; | |
1086 | break; | |
1087 | } | |
1088 | return ret; | |
1089 | } | |
1090 | ||
1091 | /* | |
1092 | * This function issues commands to initialize firmware. | |
1093 | * | |
1094 | * This is called after firmware download to bring the card to | |
1095 | * working state. | |
1096 | * | |
1097 | * The following commands are issued sequentially - | |
1098 | * - Function init (for first interface only) | |
1099 | * - Read MAC address (for first interface only) | |
1100 | * - Reconfigure Tx buffer size (for first interface only) | |
1101 | * - Enable auto deep sleep (for first interface only) | |
1102 | * - Get Tx rate | |
1103 | * - Get Tx power | |
1104 | * - Set IBSS coalescing status | |
1105 | * - Set AMSDU aggregation control | |
1106 | * - Set 11d control | |
1107 | * - Set MAC control (this must be the last command to initialize firmware) | |
1108 | */ | |
1109 | int mwifiex_sta_init_cmd(struct mwifiex_private *priv, u8 first_sta) | |
1110 | { | |
270e58e8 | 1111 | int ret; |
5e6e3a92 BZ |
1112 | u16 enable = true; |
1113 | struct mwifiex_ds_11n_amsdu_aggr_ctrl amsdu_aggr_ctrl; | |
1114 | struct mwifiex_ds_auto_ds auto_ds; | |
1115 | enum state_11d_t state_11d; | |
cd27bc3c | 1116 | struct mwifiex_ds_11n_tx_cfg tx_cfg; |
5e6e3a92 BZ |
1117 | |
1118 | if (first_sta) { | |
1119 | ||
600f5d90 AK |
1120 | ret = mwifiex_send_cmd_async(priv, HostCmd_CMD_FUNC_INIT, |
1121 | HostCmd_ACT_GEN_SET, 0, NULL); | |
5e6e3a92 BZ |
1122 | if (ret) |
1123 | return -1; | |
1124 | /* Read MAC address from HW */ | |
600f5d90 AK |
1125 | ret = mwifiex_send_cmd_async(priv, HostCmd_CMD_GET_HW_SPEC, |
1126 | HostCmd_ACT_GEN_GET, 0, NULL); | |
5e6e3a92 BZ |
1127 | if (ret) |
1128 | return -1; | |
1129 | ||
1130 | /* Reconfigure tx buf size */ | |
600f5d90 AK |
1131 | ret = mwifiex_send_cmd_async(priv, |
1132 | HostCmd_CMD_RECONFIGURE_TX_BUFF, | |
1133 | HostCmd_ACT_GEN_SET, 0, | |
1134 | &priv->adapter->tx_buf_size); | |
5e6e3a92 BZ |
1135 | if (ret) |
1136 | return -1; | |
1137 | ||
1138 | /* Enable IEEE PS by default */ | |
1139 | priv->adapter->ps_mode = MWIFIEX_802_11_POWER_MODE_PSP; | |
600f5d90 AK |
1140 | ret = mwifiex_send_cmd_async(priv, |
1141 | HostCmd_CMD_802_11_PS_MODE_ENH, | |
1142 | EN_AUTO_PS, BITMAP_STA_PS, NULL); | |
5e6e3a92 BZ |
1143 | if (ret) |
1144 | return -1; | |
1145 | } | |
1146 | ||
1147 | /* get tx rate */ | |
600f5d90 AK |
1148 | ret = mwifiex_send_cmd_async(priv, HostCmd_CMD_TX_RATE_CFG, |
1149 | HostCmd_ACT_GEN_GET, 0, NULL); | |
5e6e3a92 BZ |
1150 | if (ret) |
1151 | return -1; | |
1152 | priv->data_rate = 0; | |
1153 | ||
1154 | /* get tx power */ | |
600f5d90 AK |
1155 | ret = mwifiex_send_cmd_async(priv, HostCmd_CMD_TXPWR_CFG, |
1156 | HostCmd_ACT_GEN_GET, 0, NULL); | |
5e6e3a92 BZ |
1157 | if (ret) |
1158 | return -1; | |
1159 | ||
1160 | /* set ibss coalescing_status */ | |
600f5d90 AK |
1161 | ret = mwifiex_send_cmd_async(priv, |
1162 | HostCmd_CMD_802_11_IBSS_COALESCING_STATUS, | |
1163 | HostCmd_ACT_GEN_SET, 0, &enable); | |
5e6e3a92 BZ |
1164 | if (ret) |
1165 | return -1; | |
1166 | ||
1167 | memset(&amsdu_aggr_ctrl, 0, sizeof(amsdu_aggr_ctrl)); | |
1168 | amsdu_aggr_ctrl.enable = true; | |
1169 | /* Send request to firmware */ | |
600f5d90 AK |
1170 | ret = mwifiex_send_cmd_async(priv, HostCmd_CMD_AMSDU_AGGR_CTRL, |
1171 | HostCmd_ACT_GEN_SET, 0, | |
a5ffddb7 | 1172 | &amsdu_aggr_ctrl); |
5e6e3a92 BZ |
1173 | if (ret) |
1174 | return -1; | |
1175 | /* MAC Control must be the last command in init_fw */ | |
1176 | /* set MAC Control */ | |
600f5d90 AK |
1177 | ret = mwifiex_send_cmd_async(priv, HostCmd_CMD_MAC_CONTROL, |
1178 | HostCmd_ACT_GEN_SET, 0, | |
1179 | &priv->curr_pkt_filter); | |
5e6e3a92 BZ |
1180 | if (ret) |
1181 | return -1; | |
1182 | ||
1183 | if (first_sta) { | |
1184 | /* Enable auto deep sleep */ | |
1185 | auto_ds.auto_ds = DEEP_SLEEP_ON; | |
1186 | auto_ds.idle_time = DEEP_SLEEP_IDLE_TIME; | |
600f5d90 AK |
1187 | ret = mwifiex_send_cmd_async(priv, |
1188 | HostCmd_CMD_802_11_PS_MODE_ENH, | |
1189 | EN_AUTO_PS, BITMAP_AUTO_DS, | |
1190 | &auto_ds); | |
5e6e3a92 BZ |
1191 | if (ret) |
1192 | return -1; | |
1193 | } | |
1194 | ||
1195 | /* Send cmd to FW to enable/disable 11D function */ | |
1196 | state_11d = ENABLE_11D; | |
600f5d90 AK |
1197 | ret = mwifiex_send_cmd_async(priv, HostCmd_CMD_802_11_SNMP_MIB, |
1198 | HostCmd_ACT_GEN_SET, DOT11D_I, &state_11d); | |
5e6e3a92 BZ |
1199 | if (ret) |
1200 | dev_err(priv->adapter->dev, "11D: failed to enable 11D\n"); | |
1201 | ||
cd27bc3c AK |
1202 | /* Send cmd to FW to configure 11n specific configuration |
1203 | * (Short GI, Channel BW, Green field support etc.) for transmit | |
1204 | */ | |
1205 | tx_cfg.tx_htcap = MWIFIEX_FW_DEF_HTTXCFG; | |
1206 | ret = mwifiex_send_cmd_async(priv, HostCmd_CMD_11N_CFG, | |
1207 | HostCmd_ACT_GEN_SET, 0, &tx_cfg); | |
1208 | ||
5e6e3a92 | 1209 | /* set last_init_cmd */ |
cd27bc3c | 1210 | priv->adapter->last_init_cmd = HostCmd_CMD_11N_CFG; |
5e6e3a92 BZ |
1211 | ret = -EINPROGRESS; |
1212 | ||
1213 | return ret; | |
1214 | } |