mwifiex: add set_antenna handler support
[linux-2.6/btrfs-unstable.git] / drivers / net / wireless / mwifiex / sta_cmdresp.c
blob71c9b5b92e6dc2e6384013400d1ac72f11bc065b
1 /*
2 * Marvell Wireless LAN device driver: station command response handling
4 * Copyright (C) 2011, Marvell International Ltd.
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.
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.
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"
30 * This function handles the command response error case.
32 * For scan response error, the function cancels all the pending
33 * scan commands and generates an event to inform the applications
34 * of the scan completion.
36 * For Power Save command failure, we do not retry enter PS
37 * command in case of Ad-hoc mode.
39 * For all other response errors, the current command buffer is freed
40 * and returned to the free command queue.
42 static void
43 mwifiex_process_cmdresp_error(struct mwifiex_private *priv,
44 struct host_cmd_ds_command *resp)
46 struct cmd_ctrl_node *cmd_node = NULL, *tmp_node;
47 struct mwifiex_adapter *adapter = priv->adapter;
48 struct host_cmd_ds_802_11_ps_mode_enh *pm;
49 unsigned long flags;
51 dev_err(adapter->dev, "CMD_RESP: cmd %#x error, result=%#x\n",
52 resp->command, resp->result);
54 if (adapter->curr_cmd->wait_q_enabled)
55 adapter->cmd_wait_q.status = -1;
57 switch (le16_to_cpu(resp->command)) {
58 case HostCmd_CMD_802_11_PS_MODE_ENH:
59 pm = &resp->params.psmode_enh;
60 dev_err(adapter->dev,
61 "PS_MODE_ENH cmd failed: result=0x%x action=0x%X\n",
62 resp->result, le16_to_cpu(pm->action));
63 /* We do not re-try enter-ps command in ad-hoc mode. */
64 if (le16_to_cpu(pm->action) == EN_AUTO_PS &&
65 (le16_to_cpu(pm->params.ps_bitmap) & BITMAP_STA_PS) &&
66 priv->bss_mode == NL80211_IFTYPE_ADHOC)
67 adapter->ps_mode = MWIFIEX_802_11_POWER_MODE_CAM;
69 break;
70 case HostCmd_CMD_802_11_SCAN:
71 /* Cancel all pending scan command */
72 spin_lock_irqsave(&adapter->scan_pending_q_lock, flags);
73 list_for_each_entry_safe(cmd_node, tmp_node,
74 &adapter->scan_pending_q, list) {
75 list_del(&cmd_node->list);
76 spin_unlock_irqrestore(&adapter->scan_pending_q_lock,
77 flags);
78 mwifiex_insert_cmd_to_free_q(adapter, cmd_node);
79 spin_lock_irqsave(&adapter->scan_pending_q_lock, flags);
81 spin_unlock_irqrestore(&adapter->scan_pending_q_lock, flags);
83 spin_lock_irqsave(&adapter->mwifiex_cmd_lock, flags);
84 adapter->scan_processing = false;
85 spin_unlock_irqrestore(&adapter->mwifiex_cmd_lock, flags);
86 if (priv->report_scan_result)
87 priv->report_scan_result = false;
88 if (priv->scan_pending_on_block) {
89 priv->scan_pending_on_block = false;
90 up(&priv->async_sem);
92 break;
94 case HostCmd_CMD_MAC_CONTROL:
95 break;
97 default:
98 break;
100 /* Handling errors here */
101 mwifiex_insert_cmd_to_free_q(adapter, adapter->curr_cmd);
103 spin_lock_irqsave(&adapter->mwifiex_cmd_lock, flags);
104 adapter->curr_cmd = NULL;
105 spin_unlock_irqrestore(&adapter->mwifiex_cmd_lock, flags);
109 * This function handles the command response of get RSSI info.
111 * Handling includes changing the header fields into CPU format
112 * and saving the following parameters in driver -
113 * - Last data and beacon RSSI value
114 * - Average data and beacon RSSI value
115 * - Last data and beacon NF value
116 * - Average data and beacon NF value
118 * The parameters are send to the application as well, along with
119 * calculated SNR values.
121 static int mwifiex_ret_802_11_rssi_info(struct mwifiex_private *priv,
122 struct host_cmd_ds_command *resp)
124 struct host_cmd_ds_802_11_rssi_info_rsp *rssi_info_rsp =
125 &resp->params.rssi_info_rsp;
126 struct mwifiex_ds_misc_subsc_evt subsc_evt;
128 priv->data_rssi_last = le16_to_cpu(rssi_info_rsp->data_rssi_last);
129 priv->data_nf_last = le16_to_cpu(rssi_info_rsp->data_nf_last);
131 priv->data_rssi_avg = le16_to_cpu(rssi_info_rsp->data_rssi_avg);
132 priv->data_nf_avg = le16_to_cpu(rssi_info_rsp->data_nf_avg);
134 priv->bcn_rssi_last = le16_to_cpu(rssi_info_rsp->bcn_rssi_last);
135 priv->bcn_nf_last = le16_to_cpu(rssi_info_rsp->bcn_nf_last);
137 priv->bcn_rssi_avg = le16_to_cpu(rssi_info_rsp->bcn_rssi_avg);
138 priv->bcn_nf_avg = le16_to_cpu(rssi_info_rsp->bcn_nf_avg);
140 if (priv->subsc_evt_rssi_state == EVENT_HANDLED)
141 return 0;
143 /* Resubscribe low and high rssi events with new thresholds */
144 memset(&subsc_evt, 0x00, sizeof(struct mwifiex_ds_misc_subsc_evt));
145 subsc_evt.events = BITMASK_BCN_RSSI_LOW | BITMASK_BCN_RSSI_HIGH;
146 subsc_evt.action = HostCmd_ACT_BITWISE_SET;
147 if (priv->subsc_evt_rssi_state == RSSI_LOW_RECVD) {
148 subsc_evt.bcn_l_rssi_cfg.abs_value = abs(priv->bcn_rssi_avg -
149 priv->cqm_rssi_hyst);
150 subsc_evt.bcn_h_rssi_cfg.abs_value = abs(priv->cqm_rssi_thold);
151 } else if (priv->subsc_evt_rssi_state == RSSI_HIGH_RECVD) {
152 subsc_evt.bcn_l_rssi_cfg.abs_value = abs(priv->cqm_rssi_thold);
153 subsc_evt.bcn_h_rssi_cfg.abs_value = abs(priv->bcn_rssi_avg +
154 priv->cqm_rssi_hyst);
156 subsc_evt.bcn_l_rssi_cfg.evt_freq = 1;
157 subsc_evt.bcn_h_rssi_cfg.evt_freq = 1;
159 priv->subsc_evt_rssi_state = EVENT_HANDLED;
161 mwifiex_send_cmd_async(priv, HostCmd_CMD_802_11_SUBSCRIBE_EVENT,
162 0, 0, &subsc_evt);
164 return 0;
168 * This function handles the command response of set/get SNMP
169 * MIB parameters.
171 * Handling includes changing the header fields into CPU format
172 * and saving the parameter in driver.
174 * The following parameters are supported -
175 * - Fragmentation threshold
176 * - RTS threshold
177 * - Short retry limit
179 static int mwifiex_ret_802_11_snmp_mib(struct mwifiex_private *priv,
180 struct host_cmd_ds_command *resp,
181 u32 *data_buf)
183 struct host_cmd_ds_802_11_snmp_mib *smib = &resp->params.smib;
184 u16 oid = le16_to_cpu(smib->oid);
185 u16 query_type = le16_to_cpu(smib->query_type);
186 u32 ul_temp;
188 dev_dbg(priv->adapter->dev, "info: SNMP_RESP: oid value = %#x,"
189 " query_type = %#x, buf size = %#x\n",
190 oid, query_type, le16_to_cpu(smib->buf_size));
191 if (query_type == HostCmd_ACT_GEN_GET) {
192 ul_temp = le16_to_cpu(*((__le16 *) (smib->value)));
193 if (data_buf)
194 *data_buf = ul_temp;
195 switch (oid) {
196 case FRAG_THRESH_I:
197 dev_dbg(priv->adapter->dev,
198 "info: SNMP_RESP: FragThsd =%u\n", ul_temp);
199 break;
200 case RTS_THRESH_I:
201 dev_dbg(priv->adapter->dev,
202 "info: SNMP_RESP: RTSThsd =%u\n", ul_temp);
203 break;
204 case SHORT_RETRY_LIM_I:
205 dev_dbg(priv->adapter->dev,
206 "info: SNMP_RESP: TxRetryCount=%u\n", ul_temp);
207 break;
208 case DTIM_PERIOD_I:
209 dev_dbg(priv->adapter->dev,
210 "info: SNMP_RESP: DTIM period=%u\n", ul_temp);
211 default:
212 break;
216 return 0;
220 * This function handles the command response of get log request
222 * Handling includes changing the header fields into CPU format
223 * and sending the received parameters to application.
225 static int mwifiex_ret_get_log(struct mwifiex_private *priv,
226 struct host_cmd_ds_command *resp,
227 struct mwifiex_ds_get_stats *stats)
229 struct host_cmd_ds_802_11_get_log *get_log =
230 (struct host_cmd_ds_802_11_get_log *) &resp->params.get_log;
232 if (stats) {
233 stats->mcast_tx_frame = le32_to_cpu(get_log->mcast_tx_frame);
234 stats->failed = le32_to_cpu(get_log->failed);
235 stats->retry = le32_to_cpu(get_log->retry);
236 stats->multi_retry = le32_to_cpu(get_log->multi_retry);
237 stats->frame_dup = le32_to_cpu(get_log->frame_dup);
238 stats->rts_success = le32_to_cpu(get_log->rts_success);
239 stats->rts_failure = le32_to_cpu(get_log->rts_failure);
240 stats->ack_failure = le32_to_cpu(get_log->ack_failure);
241 stats->rx_frag = le32_to_cpu(get_log->rx_frag);
242 stats->mcast_rx_frame = le32_to_cpu(get_log->mcast_rx_frame);
243 stats->fcs_error = le32_to_cpu(get_log->fcs_error);
244 stats->tx_frame = le32_to_cpu(get_log->tx_frame);
245 stats->wep_icv_error[0] =
246 le32_to_cpu(get_log->wep_icv_err_cnt[0]);
247 stats->wep_icv_error[1] =
248 le32_to_cpu(get_log->wep_icv_err_cnt[1]);
249 stats->wep_icv_error[2] =
250 le32_to_cpu(get_log->wep_icv_err_cnt[2]);
251 stats->wep_icv_error[3] =
252 le32_to_cpu(get_log->wep_icv_err_cnt[3]);
255 return 0;
259 * This function handles the command response of set/get Tx rate
260 * configurations.
262 * Handling includes changing the header fields into CPU format
263 * and saving the following parameters in driver -
264 * - DSSS rate bitmap
265 * - OFDM rate bitmap
266 * - HT MCS rate bitmaps
268 * Based on the new rate bitmaps, the function re-evaluates if
269 * auto data rate has been activated. If not, it sends another
270 * query to the firmware to get the current Tx data rate and updates
271 * the driver value.
273 static int mwifiex_ret_tx_rate_cfg(struct mwifiex_private *priv,
274 struct host_cmd_ds_command *resp,
275 struct mwifiex_rate_cfg *ds_rate)
277 struct host_cmd_ds_tx_rate_cfg *rate_cfg = &resp->params.tx_rate_cfg;
278 struct mwifiex_rate_scope *rate_scope;
279 struct mwifiex_ie_types_header *head;
280 u16 tlv, tlv_buf_len;
281 u8 *tlv_buf;
282 u32 i;
283 int ret = 0;
285 tlv_buf = (u8 *) ((u8 *) rate_cfg) +
286 sizeof(struct host_cmd_ds_tx_rate_cfg);
287 tlv_buf_len = *(u16 *) (tlv_buf + sizeof(u16));
289 while (tlv_buf && tlv_buf_len > 0) {
290 tlv = (*tlv_buf);
291 tlv = tlv | (*(tlv_buf + 1) << 8);
293 switch (tlv) {
294 case TLV_TYPE_RATE_SCOPE:
295 rate_scope = (struct mwifiex_rate_scope *) tlv_buf;
296 priv->bitmap_rates[0] =
297 le16_to_cpu(rate_scope->hr_dsss_rate_bitmap);
298 priv->bitmap_rates[1] =
299 le16_to_cpu(rate_scope->ofdm_rate_bitmap);
300 for (i = 0;
302 sizeof(rate_scope->ht_mcs_rate_bitmap) /
303 sizeof(u16); i++)
304 priv->bitmap_rates[2 + i] =
305 le16_to_cpu(rate_scope->
306 ht_mcs_rate_bitmap[i]);
307 break;
308 /* Add RATE_DROP tlv here */
311 head = (struct mwifiex_ie_types_header *) tlv_buf;
312 tlv_buf += le16_to_cpu(head->len) + sizeof(*head);
313 tlv_buf_len -= le16_to_cpu(head->len);
316 priv->is_data_rate_auto = mwifiex_is_rate_auto(priv);
318 if (priv->is_data_rate_auto)
319 priv->data_rate = 0;
320 else
321 ret = mwifiex_send_cmd_async(priv,
322 HostCmd_CMD_802_11_TX_RATE_QUERY,
323 HostCmd_ACT_GEN_GET, 0, NULL);
325 if (!ds_rate)
326 return ret;
328 if (le16_to_cpu(rate_cfg->action) == HostCmd_ACT_GEN_GET) {
329 if (priv->is_data_rate_auto) {
330 ds_rate->is_rate_auto = 1;
331 return ret;
333 ds_rate->rate = mwifiex_get_rate_index(priv->bitmap_rates,
334 sizeof(priv->bitmap_rates));
336 if (ds_rate->rate >= MWIFIEX_RATE_BITMAP_OFDM0 &&
337 ds_rate->rate <= MWIFIEX_RATE_BITMAP_OFDM7)
338 ds_rate->rate -= (MWIFIEX_RATE_BITMAP_OFDM0 -
339 MWIFIEX_RATE_INDEX_OFDM0);
341 if (ds_rate->rate >= MWIFIEX_RATE_BITMAP_MCS0 &&
342 ds_rate->rate <= MWIFIEX_RATE_BITMAP_MCS127)
343 ds_rate->rate -= (MWIFIEX_RATE_BITMAP_MCS0 -
344 MWIFIEX_RATE_INDEX_MCS0);
347 return ret;
351 * This function handles the command response of get Tx power level.
353 * Handling includes saving the maximum and minimum Tx power levels
354 * in driver, as well as sending the values to user.
356 static int mwifiex_get_power_level(struct mwifiex_private *priv, void *data_buf)
358 int length, max_power = -1, min_power = -1;
359 struct mwifiex_types_power_group *pg_tlv_hdr;
360 struct mwifiex_power_group *pg;
362 if (!data_buf)
363 return -1;
365 pg_tlv_hdr = (struct mwifiex_types_power_group *)
366 ((u8 *) data_buf + sizeof(struct host_cmd_ds_txpwr_cfg));
367 pg = (struct mwifiex_power_group *)
368 ((u8 *) pg_tlv_hdr + sizeof(struct mwifiex_types_power_group));
369 length = pg_tlv_hdr->length;
370 if (length > 0) {
371 max_power = pg->power_max;
372 min_power = pg->power_min;
373 length -= sizeof(struct mwifiex_power_group);
375 while (length) {
376 pg++;
377 if (max_power < pg->power_max)
378 max_power = pg->power_max;
380 if (min_power > pg->power_min)
381 min_power = pg->power_min;
383 length -= sizeof(struct mwifiex_power_group);
385 if (pg_tlv_hdr->length > 0) {
386 priv->min_tx_power_level = (u8) min_power;
387 priv->max_tx_power_level = (u8) max_power;
390 return 0;
394 * This function handles the command response of set/get Tx power
395 * configurations.
397 * Handling includes changing the header fields into CPU format
398 * and saving the current Tx power level in driver.
400 static int mwifiex_ret_tx_power_cfg(struct mwifiex_private *priv,
401 struct host_cmd_ds_command *resp)
403 struct mwifiex_adapter *adapter = priv->adapter;
404 struct host_cmd_ds_txpwr_cfg *txp_cfg = &resp->params.txp_cfg;
405 struct mwifiex_types_power_group *pg_tlv_hdr;
406 struct mwifiex_power_group *pg;
407 u16 action = le16_to_cpu(txp_cfg->action);
409 switch (action) {
410 case HostCmd_ACT_GEN_GET:
411 pg_tlv_hdr = (struct mwifiex_types_power_group *)
412 ((u8 *) txp_cfg +
413 sizeof(struct host_cmd_ds_txpwr_cfg));
415 pg = (struct mwifiex_power_group *)
416 ((u8 *) pg_tlv_hdr +
417 sizeof(struct mwifiex_types_power_group));
419 if (adapter->hw_status == MWIFIEX_HW_STATUS_INITIALIZING)
420 mwifiex_get_power_level(priv, txp_cfg);
422 priv->tx_power_level = (u16) pg->power_min;
423 break;
425 case HostCmd_ACT_GEN_SET:
426 if (!le32_to_cpu(txp_cfg->mode))
427 break;
429 pg_tlv_hdr = (struct mwifiex_types_power_group *)
430 ((u8 *) txp_cfg +
431 sizeof(struct host_cmd_ds_txpwr_cfg));
433 pg = (struct mwifiex_power_group *)
434 ((u8 *) pg_tlv_hdr +
435 sizeof(struct mwifiex_types_power_group));
437 if (pg->power_max == pg->power_min)
438 priv->tx_power_level = (u16) pg->power_min;
439 break;
440 default:
441 dev_err(adapter->dev, "CMD_RESP: unknown cmd action %d\n",
442 action);
443 return 0;
445 dev_dbg(adapter->dev,
446 "info: Current TxPower Level = %d, Max Power=%d, Min Power=%d\n",
447 priv->tx_power_level, priv->max_tx_power_level,
448 priv->min_tx_power_level);
450 return 0;
454 * This function handles the command response of get RF Tx power.
456 static int mwifiex_ret_rf_tx_power(struct mwifiex_private *priv,
457 struct host_cmd_ds_command *resp)
459 struct host_cmd_ds_rf_tx_pwr *txp = &resp->params.txp;
460 u16 action = le16_to_cpu(txp->action);
462 priv->tx_power_level = le16_to_cpu(txp->cur_level);
464 if (action == HostCmd_ACT_GEN_GET) {
465 priv->max_tx_power_level = txp->max_power;
466 priv->min_tx_power_level = txp->min_power;
469 dev_dbg(priv->adapter->dev,
470 "Current TxPower Level=%d, Max Power=%d, Min Power=%d\n",
471 priv->tx_power_level, priv->max_tx_power_level,
472 priv->min_tx_power_level);
474 return 0;
478 * This function handles the command response of set rf antenna
480 static int mwifiex_ret_rf_antenna(struct mwifiex_private *priv,
481 struct host_cmd_ds_command *resp)
483 struct host_cmd_ds_rf_ant_mimo *ant_mimo = &resp->params.ant_mimo;
484 struct host_cmd_ds_rf_ant_siso *ant_siso = &resp->params.ant_siso;
485 struct mwifiex_adapter *adapter = priv->adapter;
487 if (adapter->hw_dev_mcs_support == HT_STREAM_2X2)
488 dev_dbg(adapter->dev,
489 "RF_ANT_RESP: Tx action = 0x%x, Tx Mode = 0x%04x"
490 " Rx action = 0x%x, Rx Mode = 0x%04x\n",
491 le16_to_cpu(ant_mimo->action_tx),
492 le16_to_cpu(ant_mimo->tx_ant_mode),
493 le16_to_cpu(ant_mimo->action_rx),
494 le16_to_cpu(ant_mimo->rx_ant_mode));
495 else
496 dev_dbg(adapter->dev,
497 "RF_ANT_RESP: action = 0x%x, Mode = 0x%04x\n",
498 le16_to_cpu(ant_siso->action),
499 le16_to_cpu(ant_siso->ant_mode));
501 return 0;
505 * This function handles the command response of set/get MAC address.
507 * Handling includes saving the MAC address in driver.
509 static int mwifiex_ret_802_11_mac_address(struct mwifiex_private *priv,
510 struct host_cmd_ds_command *resp)
512 struct host_cmd_ds_802_11_mac_address *cmd_mac_addr =
513 &resp->params.mac_addr;
515 memcpy(priv->curr_addr, cmd_mac_addr->mac_addr, ETH_ALEN);
517 dev_dbg(priv->adapter->dev,
518 "info: set mac address: %pM\n", priv->curr_addr);
520 return 0;
524 * This function handles the command response of set/get MAC multicast
525 * address.
527 static int mwifiex_ret_mac_multicast_adr(struct mwifiex_private *priv,
528 struct host_cmd_ds_command *resp)
530 return 0;
534 * This function handles the command response of get Tx rate query.
536 * Handling includes changing the header fields into CPU format
537 * and saving the Tx rate and HT information parameters in driver.
539 * Both rate configuration and current data rate can be retrieved
540 * with this request.
542 static int mwifiex_ret_802_11_tx_rate_query(struct mwifiex_private *priv,
543 struct host_cmd_ds_command *resp)
545 priv->tx_rate = resp->params.tx_rate.tx_rate;
546 priv->tx_htinfo = resp->params.tx_rate.ht_info;
547 if (!priv->is_data_rate_auto)
548 priv->data_rate =
549 mwifiex_index_to_data_rate(priv, priv->tx_rate,
550 priv->tx_htinfo);
552 return 0;
556 * This function handles the command response of a deauthenticate
557 * command.
559 * If the deauthenticated MAC matches the current BSS MAC, the connection
560 * state is reset.
562 static int mwifiex_ret_802_11_deauthenticate(struct mwifiex_private *priv,
563 struct host_cmd_ds_command *resp)
565 struct mwifiex_adapter *adapter = priv->adapter;
567 adapter->dbg.num_cmd_deauth++;
568 if (!memcmp(resp->params.deauth.mac_addr,
569 &priv->curr_bss_params.bss_descriptor.mac_address,
570 sizeof(resp->params.deauth.mac_addr)))
571 mwifiex_reset_connect_state(priv);
573 return 0;
577 * This function handles the command response of ad-hoc stop.
579 * The function resets the connection state in driver.
581 static int mwifiex_ret_802_11_ad_hoc_stop(struct mwifiex_private *priv,
582 struct host_cmd_ds_command *resp)
584 mwifiex_reset_connect_state(priv);
585 return 0;
589 * This function handles the command response of set/get key material.
591 * Handling includes updating the driver parameters to reflect the
592 * changes.
594 static int mwifiex_ret_802_11_key_material(struct mwifiex_private *priv,
595 struct host_cmd_ds_command *resp)
597 struct host_cmd_ds_802_11_key_material *key =
598 &resp->params.key_material;
600 if (le16_to_cpu(key->action) == HostCmd_ACT_GEN_SET) {
601 if ((le16_to_cpu(key->key_param_set.key_info) & KEY_MCAST)) {
602 dev_dbg(priv->adapter->dev, "info: key: GTK is set\n");
603 priv->wpa_is_gtk_set = true;
604 priv->scan_block = false;
608 memset(priv->aes_key.key_param_set.key, 0,
609 sizeof(key->key_param_set.key));
610 priv->aes_key.key_param_set.key_len = key->key_param_set.key_len;
611 memcpy(priv->aes_key.key_param_set.key, key->key_param_set.key,
612 le16_to_cpu(priv->aes_key.key_param_set.key_len));
614 return 0;
618 * This function handles the command response of get 11d domain information.
620 static int mwifiex_ret_802_11d_domain_info(struct mwifiex_private *priv,
621 struct host_cmd_ds_command *resp)
623 struct host_cmd_ds_802_11d_domain_info_rsp *domain_info =
624 &resp->params.domain_info_resp;
625 struct mwifiex_ietypes_domain_param_set *domain = &domain_info->domain;
626 u16 action = le16_to_cpu(domain_info->action);
627 u8 no_of_triplet;
629 no_of_triplet = (u8) ((le16_to_cpu(domain->header.len)
630 - IEEE80211_COUNTRY_STRING_LEN)
631 / sizeof(struct ieee80211_country_ie_triplet));
633 dev_dbg(priv->adapter->dev,
634 "info: 11D Domain Info Resp: no_of_triplet=%d\n",
635 no_of_triplet);
637 if (no_of_triplet > MWIFIEX_MAX_TRIPLET_802_11D) {
638 dev_warn(priv->adapter->dev,
639 "11D: invalid number of triplets %d returned\n",
640 no_of_triplet);
641 return -1;
644 switch (action) {
645 case HostCmd_ACT_GEN_SET: /* Proc Set Action */
646 break;
647 case HostCmd_ACT_GEN_GET:
648 break;
649 default:
650 dev_err(priv->adapter->dev,
651 "11D: invalid action:%d\n", domain_info->action);
652 return -1;
655 return 0;
659 * This function handles the command response of get RF channel.
661 * Handling includes changing the header fields into CPU format
662 * and saving the new channel in driver.
664 static int mwifiex_ret_802_11_rf_channel(struct mwifiex_private *priv,
665 struct host_cmd_ds_command *resp,
666 u16 *data_buf)
668 struct host_cmd_ds_802_11_rf_channel *rf_channel =
669 &resp->params.rf_channel;
670 u16 new_channel = le16_to_cpu(rf_channel->current_channel);
672 if (priv->curr_bss_params.bss_descriptor.channel != new_channel) {
673 dev_dbg(priv->adapter->dev, "cmd: Channel Switch: %d to %d\n",
674 priv->curr_bss_params.bss_descriptor.channel,
675 new_channel);
676 /* Update the channel again */
677 priv->curr_bss_params.bss_descriptor.channel = new_channel;
680 if (data_buf)
681 *data_buf = new_channel;
683 return 0;
687 * This function handles the command response of get extended version.
689 * Handling includes forming the extended version string and sending it
690 * to application.
692 static int mwifiex_ret_ver_ext(struct mwifiex_private *priv,
693 struct host_cmd_ds_command *resp,
694 struct host_cmd_ds_version_ext *version_ext)
696 struct host_cmd_ds_version_ext *ver_ext = &resp->params.verext;
698 if (version_ext) {
699 version_ext->version_str_sel = ver_ext->version_str_sel;
700 memcpy(version_ext->version_str, ver_ext->version_str,
701 sizeof(char) * 128);
702 memcpy(priv->version_str, ver_ext->version_str, 128);
704 return 0;
708 * This function handles the command response of register access.
710 * The register value and offset are returned to the user. For EEPROM
711 * access, the byte count is also returned.
713 static int mwifiex_ret_reg_access(u16 type, struct host_cmd_ds_command *resp,
714 void *data_buf)
716 struct mwifiex_ds_reg_rw *reg_rw;
717 struct mwifiex_ds_read_eeprom *eeprom;
718 union reg {
719 struct host_cmd_ds_mac_reg_access *mac;
720 struct host_cmd_ds_bbp_reg_access *bbp;
721 struct host_cmd_ds_rf_reg_access *rf;
722 struct host_cmd_ds_pmic_reg_access *pmic;
723 struct host_cmd_ds_802_11_eeprom_access *eeprom;
724 } r;
726 if (!data_buf)
727 return 0;
729 reg_rw = data_buf;
730 eeprom = data_buf;
731 switch (type) {
732 case HostCmd_CMD_MAC_REG_ACCESS:
733 r.mac = (struct host_cmd_ds_mac_reg_access *)
734 &resp->params.mac_reg;
735 reg_rw->offset = cpu_to_le32((u32) le16_to_cpu(r.mac->offset));
736 reg_rw->value = r.mac->value;
737 break;
738 case HostCmd_CMD_BBP_REG_ACCESS:
739 r.bbp = (struct host_cmd_ds_bbp_reg_access *)
740 &resp->params.bbp_reg;
741 reg_rw->offset = cpu_to_le32((u32) le16_to_cpu(r.bbp->offset));
742 reg_rw->value = cpu_to_le32((u32) r.bbp->value);
743 break;
745 case HostCmd_CMD_RF_REG_ACCESS:
746 r.rf = (struct host_cmd_ds_rf_reg_access *)
747 &resp->params.rf_reg;
748 reg_rw->offset = cpu_to_le32((u32) le16_to_cpu(r.rf->offset));
749 reg_rw->value = cpu_to_le32((u32) r.bbp->value);
750 break;
751 case HostCmd_CMD_PMIC_REG_ACCESS:
752 r.pmic = (struct host_cmd_ds_pmic_reg_access *)
753 &resp->params.pmic_reg;
754 reg_rw->offset = cpu_to_le32((u32) le16_to_cpu(r.pmic->offset));
755 reg_rw->value = cpu_to_le32((u32) r.pmic->value);
756 break;
757 case HostCmd_CMD_CAU_REG_ACCESS:
758 r.rf = (struct host_cmd_ds_rf_reg_access *)
759 &resp->params.rf_reg;
760 reg_rw->offset = cpu_to_le32((u32) le16_to_cpu(r.rf->offset));
761 reg_rw->value = cpu_to_le32((u32) r.rf->value);
762 break;
763 case HostCmd_CMD_802_11_EEPROM_ACCESS:
764 r.eeprom = (struct host_cmd_ds_802_11_eeprom_access *)
765 &resp->params.eeprom;
766 pr_debug("info: EEPROM read len=%x\n", r.eeprom->byte_count);
767 if (le16_to_cpu(eeprom->byte_count) <
768 le16_to_cpu(r.eeprom->byte_count)) {
769 eeprom->byte_count = cpu_to_le16(0);
770 pr_debug("info: EEPROM read length is too big\n");
771 return -1;
773 eeprom->offset = r.eeprom->offset;
774 eeprom->byte_count = r.eeprom->byte_count;
775 if (le16_to_cpu(eeprom->byte_count) > 0)
776 memcpy(&eeprom->value, &r.eeprom->value,
777 le16_to_cpu(r.eeprom->byte_count));
779 break;
780 default:
781 return -1;
783 return 0;
787 * This function handles the command response of get IBSS coalescing status.
789 * If the received BSSID is different than the current one, the current BSSID,
790 * beacon interval, ATIM window and ERP information are updated, along with
791 * changing the ad-hoc state accordingly.
793 static int mwifiex_ret_ibss_coalescing_status(struct mwifiex_private *priv,
794 struct host_cmd_ds_command *resp)
796 struct host_cmd_ds_802_11_ibss_status *ibss_coal_resp =
797 &(resp->params.ibss_coalescing);
798 u8 zero_mac[ETH_ALEN] = { 0, 0, 0, 0, 0, 0 };
800 if (le16_to_cpu(ibss_coal_resp->action) == HostCmd_ACT_GEN_SET)
801 return 0;
803 dev_dbg(priv->adapter->dev,
804 "info: new BSSID %pM\n", ibss_coal_resp->bssid);
806 /* If rsp has NULL BSSID, Just return..... No Action */
807 if (!memcmp(ibss_coal_resp->bssid, zero_mac, ETH_ALEN)) {
808 dev_warn(priv->adapter->dev, "new BSSID is NULL\n");
809 return 0;
812 /* If BSSID is diff, modify current BSS parameters */
813 if (memcmp(priv->curr_bss_params.bss_descriptor.mac_address,
814 ibss_coal_resp->bssid, ETH_ALEN)) {
815 /* BSSID */
816 memcpy(priv->curr_bss_params.bss_descriptor.mac_address,
817 ibss_coal_resp->bssid, ETH_ALEN);
819 /* Beacon Interval */
820 priv->curr_bss_params.bss_descriptor.beacon_period
821 = le16_to_cpu(ibss_coal_resp->beacon_interval);
823 /* ERP Information */
824 priv->curr_bss_params.bss_descriptor.erp_flags =
825 (u8) le16_to_cpu(ibss_coal_resp->use_g_rate_protect);
827 priv->adhoc_state = ADHOC_COALESCED;
830 return 0;
834 * This function handles the command response for subscribe event command.
836 static int mwifiex_ret_subsc_evt(struct mwifiex_private *priv,
837 struct host_cmd_ds_command *resp,
838 struct mwifiex_ds_misc_subsc_evt *sub_event)
840 struct host_cmd_ds_802_11_subsc_evt *cmd_sub_event =
841 (struct host_cmd_ds_802_11_subsc_evt *)&resp->params.subsc_evt;
843 /* For every subscribe event command (Get/Set/Clear), FW reports the
844 * current set of subscribed events*/
845 dev_dbg(priv->adapter->dev, "Bitmap of currently subscribed events: %16x\n",
846 le16_to_cpu(cmd_sub_event->events));
848 /*Return the subscribed event info for a Get request*/
849 if (sub_event)
850 sub_event->events = le16_to_cpu(cmd_sub_event->events);
852 return 0;
856 * This function handles the command responses.
858 * This is a generic function, which calls command specific
859 * response handlers based on the command ID.
861 int mwifiex_process_sta_cmdresp(struct mwifiex_private *priv, u16 cmdresp_no,
862 struct host_cmd_ds_command *resp)
864 int ret = 0;
865 struct mwifiex_adapter *adapter = priv->adapter;
866 void *data_buf = adapter->curr_cmd->data_buf;
868 /* If the command is not successful, cleanup and return failure */
869 if (resp->result != HostCmd_RESULT_OK) {
870 mwifiex_process_cmdresp_error(priv, resp);
871 return -1;
873 /* Command successful, handle response */
874 switch (cmdresp_no) {
875 case HostCmd_CMD_GET_HW_SPEC:
876 ret = mwifiex_ret_get_hw_spec(priv, resp);
877 break;
878 case HostCmd_CMD_MAC_CONTROL:
879 break;
880 case HostCmd_CMD_802_11_MAC_ADDRESS:
881 ret = mwifiex_ret_802_11_mac_address(priv, resp);
882 break;
883 case HostCmd_CMD_MAC_MULTICAST_ADR:
884 ret = mwifiex_ret_mac_multicast_adr(priv, resp);
885 break;
886 case HostCmd_CMD_TX_RATE_CFG:
887 ret = mwifiex_ret_tx_rate_cfg(priv, resp, data_buf);
888 break;
889 case HostCmd_CMD_802_11_SCAN:
890 ret = mwifiex_ret_802_11_scan(priv, resp);
891 adapter->curr_cmd->wait_q_enabled = false;
892 break;
893 case HostCmd_CMD_802_11_BG_SCAN_QUERY:
894 ret = mwifiex_ret_802_11_scan(priv, resp);
895 dev_dbg(adapter->dev,
896 "info: CMD_RESP: BG_SCAN result is ready!\n");
897 break;
898 case HostCmd_CMD_TXPWR_CFG:
899 ret = mwifiex_ret_tx_power_cfg(priv, resp);
900 break;
901 case HostCmd_CMD_RF_TX_PWR:
902 ret = mwifiex_ret_rf_tx_power(priv, resp);
903 break;
904 case HostCmd_CMD_RF_ANTENNA:
905 ret = mwifiex_ret_rf_antenna(priv, resp);
906 break;
907 case HostCmd_CMD_802_11_PS_MODE_ENH:
908 ret = mwifiex_ret_enh_power_mode(priv, resp, data_buf);
909 break;
910 case HostCmd_CMD_802_11_HS_CFG_ENH:
911 ret = mwifiex_ret_802_11_hs_cfg(priv, resp);
912 break;
913 case HostCmd_CMD_802_11_ASSOCIATE:
914 ret = mwifiex_ret_802_11_associate(priv, resp);
915 break;
916 case HostCmd_CMD_802_11_DEAUTHENTICATE:
917 ret = mwifiex_ret_802_11_deauthenticate(priv, resp);
918 break;
919 case HostCmd_CMD_802_11_AD_HOC_START:
920 case HostCmd_CMD_802_11_AD_HOC_JOIN:
921 ret = mwifiex_ret_802_11_ad_hoc(priv, resp);
922 break;
923 case HostCmd_CMD_802_11_AD_HOC_STOP:
924 ret = mwifiex_ret_802_11_ad_hoc_stop(priv, resp);
925 break;
926 case HostCmd_CMD_802_11_GET_LOG:
927 ret = mwifiex_ret_get_log(priv, resp, data_buf);
928 break;
929 case HostCmd_CMD_RSSI_INFO:
930 ret = mwifiex_ret_802_11_rssi_info(priv, resp);
931 break;
932 case HostCmd_CMD_802_11_SNMP_MIB:
933 ret = mwifiex_ret_802_11_snmp_mib(priv, resp, data_buf);
934 break;
935 case HostCmd_CMD_802_11_TX_RATE_QUERY:
936 ret = mwifiex_ret_802_11_tx_rate_query(priv, resp);
937 break;
938 case HostCmd_CMD_802_11_RF_CHANNEL:
939 ret = mwifiex_ret_802_11_rf_channel(priv, resp, data_buf);
940 break;
941 case HostCmd_CMD_VERSION_EXT:
942 ret = mwifiex_ret_ver_ext(priv, resp, data_buf);
943 break;
944 case HostCmd_CMD_FUNC_INIT:
945 case HostCmd_CMD_FUNC_SHUTDOWN:
946 break;
947 case HostCmd_CMD_802_11_KEY_MATERIAL:
948 ret = mwifiex_ret_802_11_key_material(priv, resp);
949 break;
950 case HostCmd_CMD_802_11D_DOMAIN_INFO:
951 ret = mwifiex_ret_802_11d_domain_info(priv, resp);
952 break;
953 case HostCmd_CMD_11N_ADDBA_REQ:
954 ret = mwifiex_ret_11n_addba_req(priv, resp);
955 break;
956 case HostCmd_CMD_11N_DELBA:
957 ret = mwifiex_ret_11n_delba(priv, resp);
958 break;
959 case HostCmd_CMD_11N_ADDBA_RSP:
960 ret = mwifiex_ret_11n_addba_resp(priv, resp);
961 break;
962 case HostCmd_CMD_RECONFIGURE_TX_BUFF:
963 adapter->tx_buf_size = (u16) le16_to_cpu(resp->params.
964 tx_buf.buff_size);
965 adapter->tx_buf_size = (adapter->tx_buf_size
966 / MWIFIEX_SDIO_BLOCK_SIZE)
967 * MWIFIEX_SDIO_BLOCK_SIZE;
968 adapter->curr_tx_buf_size = adapter->tx_buf_size;
969 dev_dbg(adapter->dev,
970 "cmd: max_tx_buf_size=%d, tx_buf_size=%d\n",
971 adapter->max_tx_buf_size, adapter->tx_buf_size);
973 if (adapter->if_ops.update_mp_end_port)
974 adapter->if_ops.update_mp_end_port(adapter,
975 le16_to_cpu(resp->params.tx_buf.mp_end_port));
976 break;
977 case HostCmd_CMD_AMSDU_AGGR_CTRL:
978 ret = mwifiex_ret_amsdu_aggr_ctrl(resp, data_buf);
979 break;
980 case HostCmd_CMD_WMM_GET_STATUS:
981 ret = mwifiex_ret_wmm_get_status(priv, resp);
982 break;
983 case HostCmd_CMD_802_11_IBSS_COALESCING_STATUS:
984 ret = mwifiex_ret_ibss_coalescing_status(priv, resp);
985 break;
986 case HostCmd_CMD_MAC_REG_ACCESS:
987 case HostCmd_CMD_BBP_REG_ACCESS:
988 case HostCmd_CMD_RF_REG_ACCESS:
989 case HostCmd_CMD_PMIC_REG_ACCESS:
990 case HostCmd_CMD_CAU_REG_ACCESS:
991 case HostCmd_CMD_802_11_EEPROM_ACCESS:
992 ret = mwifiex_ret_reg_access(cmdresp_no, resp, data_buf);
993 break;
994 case HostCmd_CMD_SET_BSS_MODE:
995 break;
996 case HostCmd_CMD_11N_CFG:
997 ret = mwifiex_ret_11n_cfg(resp, data_buf);
998 break;
999 case HostCmd_CMD_PCIE_DESC_DETAILS:
1000 break;
1001 case HostCmd_CMD_802_11_SUBSCRIBE_EVENT:
1002 ret = mwifiex_ret_subsc_evt(priv, resp, data_buf);
1003 break;
1004 case HostCmd_CMD_UAP_SYS_CONFIG:
1005 break;
1006 case HostCmd_CMD_UAP_BSS_START:
1007 priv->bss_started = 1;
1008 break;
1009 case HostCmd_CMD_UAP_BSS_STOP:
1010 priv->bss_started = 0;
1011 break;
1012 default:
1013 dev_err(adapter->dev, "CMD_RESP: unknown cmd response %#x\n",
1014 resp->command);
1015 break;
1018 return ret;