2 * Marvell Wireless LAN device driver: functions for station ioctl
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.
30 * Copies the multicast address list from device to driver.
32 * This function does not validate the destination memory for
33 * size, and the calling function must ensure enough memory is
36 int mwifiex_copy_mcast_addr(struct mwifiex_multicast_list *mlist,
37 struct net_device *dev)
40 struct netdev_hw_addr *ha;
42 netdev_for_each_mc_addr(ha, dev)
43 memcpy(&mlist->mac_list[i++], ha->addr, ETH_ALEN);
49 * Wait queue completion handler.
51 * This function waits on a cmd wait queue. It also cancels the pending
52 * request after waking up, in case of errors.
54 int mwifiex_wait_queue_complete(struct mwifiex_adapter *adapter)
56 bool cancel_flag = false;
57 int status = adapter->cmd_wait_q.status;
58 struct cmd_ctrl_node *cmd_queued;
60 if (!adapter->cmd_queued)
63 cmd_queued = adapter->cmd_queued;
64 adapter->cmd_queued = NULL;
66 dev_dbg(adapter->dev, "cmd pending\n");
67 atomic_inc(&adapter->cmd_pending);
69 /* Status pending, wake up main process */
70 queue_work(adapter->workqueue, &adapter->main_work);
72 /* Wait for completion */
73 wait_event_interruptible(adapter->cmd_wait_q.wait,
74 *(cmd_queued->condition));
75 if (!*(cmd_queued->condition))
79 mwifiex_cancel_pending_ioctl(adapter);
80 dev_dbg(adapter->dev, "cmd cancel\n");
82 adapter->cmd_wait_q.status = 0;
88 * This function prepares the correct firmware command and
89 * issues it to set the multicast list.
91 * This function can be used to enable promiscuous mode, or enable all
92 * multicast packets, or to enable selective multicast.
94 int mwifiex_request_set_multicast_list(struct mwifiex_private *priv,
95 struct mwifiex_multicast_list *mcast_list)
100 old_pkt_filter = priv->curr_pkt_filter;
102 if (mcast_list->mode == MWIFIEX_PROMISC_MODE) {
103 dev_dbg(priv->adapter->dev, "info: Enable Promiscuous mode\n");
104 priv->curr_pkt_filter |= HostCmd_ACT_MAC_PROMISCUOUS_ENABLE;
105 priv->curr_pkt_filter &=
106 ~HostCmd_ACT_MAC_ALL_MULTICAST_ENABLE;
109 priv->curr_pkt_filter &= ~HostCmd_ACT_MAC_PROMISCUOUS_ENABLE;
110 if (mcast_list->mode == MWIFIEX_MULTICAST_MODE) {
111 dev_dbg(priv->adapter->dev,
112 "info: Enabling All Multicast!\n");
113 priv->curr_pkt_filter |=
114 HostCmd_ACT_MAC_ALL_MULTICAST_ENABLE;
116 priv->curr_pkt_filter &=
117 ~HostCmd_ACT_MAC_ALL_MULTICAST_ENABLE;
118 if (mcast_list->num_multicast_addr) {
119 dev_dbg(priv->adapter->dev,
120 "info: Set multicast list=%d\n",
121 mcast_list->num_multicast_addr);
122 /* Set multicast addresses to firmware */
123 if (old_pkt_filter == priv->curr_pkt_filter) {
124 /* Send request to firmware */
125 ret = mwifiex_send_cmd_async(priv,
126 HostCmd_CMD_MAC_MULTICAST_ADR,
127 HostCmd_ACT_GEN_SET, 0,
130 /* Send request to firmware */
131 ret = mwifiex_send_cmd_async(priv,
132 HostCmd_CMD_MAC_MULTICAST_ADR,
133 HostCmd_ACT_GEN_SET, 0,
139 dev_dbg(priv->adapter->dev,
140 "info: old_pkt_filter=%#x, curr_pkt_filter=%#x\n",
141 old_pkt_filter, priv->curr_pkt_filter);
142 if (old_pkt_filter != priv->curr_pkt_filter) {
143 ret = mwifiex_send_cmd_async(priv, HostCmd_CMD_MAC_CONTROL,
145 0, &priv->curr_pkt_filter);
152 * This function fills bss descriptor structure using provided
155 int mwifiex_fill_new_bss_desc(struct mwifiex_private *priv,
156 u8 *bssid, s32 rssi, u8 *ie_buf,
157 size_t ie_len, u16 beacon_period,
158 u16 cap_info_bitmap, u8 band,
159 struct mwifiex_bssdescriptor *bss_desc)
163 memcpy(bss_desc->mac_address, bssid, ETH_ALEN);
164 bss_desc->rssi = rssi;
165 bss_desc->beacon_buf = ie_buf;
166 bss_desc->beacon_buf_size = ie_len;
167 bss_desc->beacon_period = beacon_period;
168 bss_desc->cap_info_bitmap = cap_info_bitmap;
169 bss_desc->bss_band = band;
170 if (bss_desc->cap_info_bitmap & WLAN_CAPABILITY_PRIVACY) {
171 dev_dbg(priv->adapter->dev, "info: InterpretIE: AP WEP enabled\n");
172 bss_desc->privacy = MWIFIEX_802_11_PRIV_FILTER_8021X_WEP;
174 bss_desc->privacy = MWIFIEX_802_11_PRIV_FILTER_ACCEPT_ALL;
176 if (bss_desc->cap_info_bitmap & WLAN_CAPABILITY_IBSS)
177 bss_desc->bss_mode = NL80211_IFTYPE_ADHOC;
179 bss_desc->bss_mode = NL80211_IFTYPE_STATION;
181 ret = mwifiex_update_bss_desc_with_ie(priv->adapter, bss_desc,
188 * In Ad-Hoc mode, the IBSS is created if not found in scan list.
189 * In both Ad-Hoc and infra mode, an deauthentication is performed
192 int mwifiex_bss_start(struct mwifiex_private *priv, struct cfg80211_bss *bss,
193 struct mwifiex_802_11_ssid *req_ssid)
196 struct mwifiex_adapter *adapter = priv->adapter;
197 struct mwifiex_bssdescriptor *bss_desc = NULL;
198 u8 *beacon_ie = NULL;
200 priv->scan_block = false;
203 /* Allocate and fill new bss descriptor */
204 bss_desc = kzalloc(sizeof(struct mwifiex_bssdescriptor),
207 dev_err(priv->adapter->dev, " failed to alloc bss_desc\n");
211 beacon_ie = kmemdup(bss->information_elements,
212 bss->len_beacon_ies, GFP_KERNEL);
215 dev_err(priv->adapter->dev, " failed to alloc beacon_ie\n");
219 ret = mwifiex_fill_new_bss_desc(priv, bss->bssid, bss->signal,
220 beacon_ie, bss->len_beacon_ies,
221 bss->beacon_interval,
223 *(u8 *)bss->priv, bss_desc);
228 if (priv->bss_mode == NL80211_IFTYPE_STATION) {
230 ret = mwifiex_deauthenticate(priv, NULL);
234 ret = mwifiex_check_network_compatibility(priv, bss_desc);
238 dev_dbg(adapter->dev, "info: SSID found in scan list ... "
241 if (!netif_queue_stopped(priv->netdev))
242 mwifiex_stop_net_dev_queue(priv->netdev, adapter);
244 /* Clear any past association response stored for
245 * application retrieval */
246 priv->assoc_rsp_size = 0;
247 ret = mwifiex_associate(priv, bss_desc);
249 cfg80211_put_bss(bss);
252 /* If the requested SSID matches current SSID, return */
253 if (bss_desc && bss_desc->ssid.ssid_len &&
255 (&priv->curr_bss_params.bss_descriptor.ssid,
262 /* Exit Adhoc mode first */
263 dev_dbg(adapter->dev, "info: Sending Adhoc Stop\n");
264 ret = mwifiex_deauthenticate(priv, NULL);
268 priv->adhoc_is_link_sensed = false;
270 ret = mwifiex_check_network_compatibility(priv, bss_desc);
272 if (!netif_queue_stopped(priv->netdev))
273 mwifiex_stop_net_dev_queue(priv->netdev, adapter);
276 dev_dbg(adapter->dev, "info: network found in scan"
277 " list. Joining...\n");
278 ret = mwifiex_adhoc_join(priv, bss_desc);
280 cfg80211_put_bss(bss);
282 dev_dbg(adapter->dev, "info: Network not found in "
283 "the list, creating adhoc with ssid = %s\n",
285 ret = mwifiex_adhoc_start(priv, req_ssid);
296 * IOCTL request handler to set host sleep configuration.
298 * This function prepares the correct firmware command and
301 static int mwifiex_set_hs_params(struct mwifiex_private *priv, u16 action,
302 int cmd_type, struct mwifiex_ds_hs_cfg *hs_cfg)
305 struct mwifiex_adapter *adapter = priv->adapter;
313 case HostCmd_ACT_GEN_SET:
314 if (adapter->pps_uapsd_mode) {
315 dev_dbg(adapter->dev, "info: Host Sleep IOCTL"
316 " is blocked in UAPSD/PPS mode\n");
320 if (hs_cfg->is_invoke_hostcmd) {
321 if (hs_cfg->conditions == HOST_SLEEP_CFG_CANCEL) {
322 if (!adapter->is_hs_configured)
323 /* Already cancelled */
325 /* Save previous condition */
326 prev_cond = le32_to_cpu(adapter->hs_cfg
328 adapter->hs_cfg.conditions =
329 cpu_to_le32(hs_cfg->conditions);
330 } else if (hs_cfg->conditions) {
331 adapter->hs_cfg.conditions =
332 cpu_to_le32(hs_cfg->conditions);
333 adapter->hs_cfg.gpio = (u8)hs_cfg->gpio;
335 adapter->hs_cfg.gap = (u8)hs_cfg->gap;
336 } else if (adapter->hs_cfg.conditions ==
338 HOST_SLEEP_CFG_CANCEL)) {
339 /* Return failure if no parameters for HS
344 if (cmd_type == MWIFIEX_SYNC_CMD)
345 status = mwifiex_send_cmd_sync(priv,
346 HostCmd_CMD_802_11_HS_CFG_ENH,
347 HostCmd_ACT_GEN_SET, 0,
350 status = mwifiex_send_cmd_async(priv,
351 HostCmd_CMD_802_11_HS_CFG_ENH,
352 HostCmd_ACT_GEN_SET, 0,
354 if (hs_cfg->conditions == HOST_SLEEP_CFG_CANCEL)
355 /* Restore previous condition */
356 adapter->hs_cfg.conditions =
357 cpu_to_le32(prev_cond);
359 adapter->hs_cfg.conditions =
360 cpu_to_le32(hs_cfg->conditions);
361 adapter->hs_cfg.gpio = (u8)hs_cfg->gpio;
362 adapter->hs_cfg.gap = (u8)hs_cfg->gap;
365 case HostCmd_ACT_GEN_GET:
366 hs_cfg->conditions = le32_to_cpu(adapter->hs_cfg.conditions);
367 hs_cfg->gpio = adapter->hs_cfg.gpio;
368 hs_cfg->gap = adapter->hs_cfg.gap;
379 * Sends IOCTL request to cancel the existing Host Sleep configuration.
381 * This function allocates the IOCTL request buffer, fills it
382 * with requisite parameters and calls the IOCTL handler.
384 int mwifiex_cancel_hs(struct mwifiex_private *priv, int cmd_type)
386 struct mwifiex_ds_hs_cfg hscfg;
388 hscfg.conditions = HOST_SLEEP_CFG_CANCEL;
389 hscfg.is_invoke_hostcmd = true;
391 return mwifiex_set_hs_params(priv, HostCmd_ACT_GEN_SET,
394 EXPORT_SYMBOL_GPL(mwifiex_cancel_hs);
397 * Sends IOCTL request to cancel the existing Host Sleep configuration.
399 * This function allocates the IOCTL request buffer, fills it
400 * with requisite parameters and calls the IOCTL handler.
402 int mwifiex_enable_hs(struct mwifiex_adapter *adapter)
404 struct mwifiex_ds_hs_cfg hscfg;
406 if (adapter->hs_activated) {
407 dev_dbg(adapter->dev, "cmd: HS Already actived\n");
411 adapter->hs_activate_wait_q_woken = false;
413 memset(&hscfg, 0, sizeof(struct mwifiex_hs_config_param));
414 hscfg.is_invoke_hostcmd = true;
416 if (mwifiex_set_hs_params(mwifiex_get_priv(adapter,
417 MWIFIEX_BSS_ROLE_STA),
418 HostCmd_ACT_GEN_SET, MWIFIEX_SYNC_CMD,
420 dev_err(adapter->dev, "IOCTL request HS enable failed\n");
424 wait_event_interruptible(adapter->hs_activate_wait_q,
425 adapter->hs_activate_wait_q_woken);
429 EXPORT_SYMBOL_GPL(mwifiex_enable_hs);
432 * IOCTL request handler to get BSS information.
434 * This function collates the information from different driver structures
435 * to send to the user.
437 int mwifiex_get_bss_info(struct mwifiex_private *priv,
438 struct mwifiex_bss_info *info)
440 struct mwifiex_adapter *adapter = priv->adapter;
441 struct mwifiex_bssdescriptor *bss_desc;
446 bss_desc = &priv->curr_bss_params.bss_descriptor;
448 info->bss_mode = priv->bss_mode;
450 memcpy(&info->ssid, &bss_desc->ssid,
451 sizeof(struct mwifiex_802_11_ssid));
453 memcpy(&info->bssid, &bss_desc->mac_address, ETH_ALEN);
455 info->bss_chan = bss_desc->channel;
457 info->region_code = adapter->region_code;
459 info->media_connected = priv->media_connected;
461 info->max_power_level = priv->max_tx_power_level;
462 info->min_power_level = priv->min_tx_power_level;
464 info->adhoc_state = priv->adhoc_state;
466 info->bcn_nf_last = priv->bcn_nf_last;
468 if (priv->sec_info.wep_status == MWIFIEX_802_11_WEP_ENABLED)
469 info->wep_status = true;
471 info->wep_status = false;
473 info->is_hs_configured = adapter->is_hs_configured;
474 info->is_deep_sleep = adapter->is_deep_sleep;
480 * The function disables auto deep sleep mode.
482 int mwifiex_disable_auto_ds(struct mwifiex_private *priv)
484 struct mwifiex_ds_auto_ds auto_ds;
486 auto_ds.auto_ds = DEEP_SLEEP_OFF;
488 return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_PS_MODE_ENH,
489 DIS_AUTO_PS, BITMAP_AUTO_DS, &auto_ds);
491 EXPORT_SYMBOL_GPL(mwifiex_disable_auto_ds);
494 * IOCTL request handler to set/get active channel.
496 * This function performs validity checking on channel/frequency
497 * compatibility and returns failure if not valid.
499 int mwifiex_bss_set_channel(struct mwifiex_private *priv,
500 struct mwifiex_chan_freq_power *chan)
502 struct mwifiex_adapter *adapter = priv->adapter;
503 struct mwifiex_chan_freq_power *cfp = NULL;
508 if (!chan->channel && !chan->freq)
510 if (adapter->adhoc_start_band & BAND_AN)
511 adapter->adhoc_start_band = BAND_G | BAND_B | BAND_GN;
512 else if (adapter->adhoc_start_band & BAND_A)
513 adapter->adhoc_start_band = BAND_G | BAND_B;
515 if (chan->channel <= MAX_CHANNEL_BAND_BG)
516 cfp = mwifiex_get_cfp_by_band_and_channel_from_cfg80211
517 (priv, 0, (u16) chan->channel);
519 cfp = mwifiex_get_cfp_by_band_and_channel_from_cfg80211
520 (priv, BAND_A, (u16) chan->channel);
522 if (adapter->adhoc_11n_enabled)
523 adapter->adhoc_start_band = BAND_A
526 adapter->adhoc_start_band = BAND_A;
530 if (chan->freq <= MAX_FREQUENCY_BAND_BG)
531 cfp = mwifiex_get_cfp_by_band_and_freq_from_cfg80211(
532 priv, 0, chan->freq);
534 cfp = mwifiex_get_cfp_by_band_and_freq_from_cfg80211
535 (priv, BAND_A, chan->freq);
537 if (adapter->adhoc_11n_enabled)
538 adapter->adhoc_start_band = BAND_A
541 adapter->adhoc_start_band = BAND_A;
545 if (!cfp || !cfp->channel) {
546 dev_err(adapter->dev, "invalid channel/freq\n");
549 priv->adhoc_channel = (u8) cfp->channel;
550 chan->channel = cfp->channel;
551 chan->freq = cfp->freq;
557 * IOCTL request handler to set/get Ad-Hoc channel.
559 * This function prepares the correct firmware command and
560 * issues it to set or get the ad-hoc channel.
562 static int mwifiex_bss_ioctl_ibss_channel(struct mwifiex_private *priv,
563 u16 action, u16 *channel)
565 if (action == HostCmd_ACT_GEN_GET) {
566 if (!priv->media_connected) {
567 *channel = priv->adhoc_channel;
571 priv->adhoc_channel = (u8) *channel;
574 return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_RF_CHANNEL,
579 * IOCTL request handler to change Ad-Hoc channel.
581 * This function allocates the IOCTL request buffer, fills it
582 * with requisite parameters and calls the IOCTL handler.
584 * The function follows the following steps to perform the change -
585 * - Get current IBSS information
586 * - Get current channel
587 * - If no change is required, return
588 * - If not connected, change channel and return
592 * - Perform specific SSID scan with same SSID
593 * - Start/Join the IBSS
596 mwifiex_drv_change_adhoc_chan(struct mwifiex_private *priv, int channel)
599 struct mwifiex_bss_info bss_info;
600 struct mwifiex_ssid_bssid ssid_bssid;
602 struct cfg80211_bss *bss = NULL;
603 struct ieee80211_channel *chan;
604 enum ieee80211_band band;
606 memset(&bss_info, 0, sizeof(bss_info));
608 /* Get BSS information */
609 if (mwifiex_get_bss_info(priv, &bss_info))
612 /* Get current channel */
613 ret = mwifiex_bss_ioctl_ibss_channel(priv, HostCmd_ACT_GEN_GET,
616 if (curr_chan == channel) {
620 dev_dbg(priv->adapter->dev, "cmd: updating channel from %d to %d\n",
623 if (!bss_info.media_connected) {
629 memset(&ssid_bssid, 0, ETH_ALEN);
630 ret = mwifiex_deauthenticate(priv, ssid_bssid.bssid);
632 ret = mwifiex_bss_ioctl_ibss_channel(priv, HostCmd_ACT_GEN_SET,
635 /* Do specific SSID scanning */
636 if (mwifiex_request_scan(priv, &bss_info.ssid)) {
641 band = mwifiex_band_to_radio_type(priv->curr_bss_params.band);
642 chan = __ieee80211_get_channel(priv->wdev->wiphy,
643 ieee80211_channel_to_frequency(channel, band));
645 /* Find the BSS we want using available scan results */
646 bss = cfg80211_get_bss(priv->wdev->wiphy, chan, bss_info.bssid,
647 bss_info.ssid.ssid, bss_info.ssid.ssid_len,
648 WLAN_CAPABILITY_ESS, WLAN_CAPABILITY_ESS);
650 wiphy_warn(priv->wdev->wiphy, "assoc: bss %pM not in scan results\n",
653 ret = mwifiex_bss_start(priv, bss, &bss_info.ssid);
659 * IOCTL request handler to get rate.
661 * This function prepares the correct firmware command and
662 * issues it to get the current rate if it is connected,
663 * otherwise, the function returns the lowest supported rate
666 static int mwifiex_rate_ioctl_get_rate_value(struct mwifiex_private *priv,
667 struct mwifiex_rate_cfg *rate_cfg)
669 rate_cfg->is_rate_auto = priv->is_data_rate_auto;
670 return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_TX_RATE_QUERY,
671 HostCmd_ACT_GEN_GET, 0, NULL);
675 * IOCTL request handler to set rate.
677 * This function prepares the correct firmware command and
678 * issues it to set the current rate.
680 * The function also performs validation checking on the supplied value.
682 static int mwifiex_rate_ioctl_set_rate_value(struct mwifiex_private *priv,
683 struct mwifiex_rate_cfg *rate_cfg)
685 u8 rates[MWIFIEX_SUPPORTED_RATES];
688 u16 bitmap_rates[MAX_BITMAP_RATES_SIZE];
690 struct mwifiex_adapter *adapter = priv->adapter;
692 if (rate_cfg->is_rate_auto) {
693 memset(bitmap_rates, 0, sizeof(bitmap_rates));
694 /* Support all HR/DSSS rates */
695 bitmap_rates[0] = 0x000F;
696 /* Support all OFDM rates */
697 bitmap_rates[1] = 0x00FF;
698 /* Support all HT-MCSs rate */
699 for (i = 0; i < ARRAY_SIZE(priv->bitmap_rates) - 3; i++)
700 bitmap_rates[i + 2] = 0xFFFF;
701 bitmap_rates[9] = 0x3FFF;
703 memset(rates, 0, sizeof(rates));
704 mwifiex_get_active_data_rates(priv, rates);
706 for (i = 0; (rate[i] && i < MWIFIEX_SUPPORTED_RATES); i++) {
707 dev_dbg(adapter->dev, "info: rate=%#x wanted=%#x\n",
708 rate[i], rate_cfg->rate);
709 if ((rate[i] & 0x7f) == (rate_cfg->rate & 0x7f))
712 if ((i == MWIFIEX_SUPPORTED_RATES) || !rate[i]) {
713 dev_err(adapter->dev, "fixed data rate %#x is out "
714 "of range\n", rate_cfg->rate);
717 memset(bitmap_rates, 0, sizeof(bitmap_rates));
719 rate_index = mwifiex_data_rate_to_index(rate_cfg->rate);
721 /* Only allow b/g rates to be set */
722 if (rate_index >= MWIFIEX_RATE_INDEX_HRDSSS0 &&
723 rate_index <= MWIFIEX_RATE_INDEX_HRDSSS3) {
724 bitmap_rates[0] = 1 << rate_index;
726 rate_index -= 1; /* There is a 0x00 in the table */
727 if (rate_index >= MWIFIEX_RATE_INDEX_OFDM0 &&
728 rate_index <= MWIFIEX_RATE_INDEX_OFDM7)
729 bitmap_rates[1] = 1 << (rate_index -
730 MWIFIEX_RATE_INDEX_OFDM0);
734 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_TX_RATE_CFG,
735 HostCmd_ACT_GEN_SET, 0, bitmap_rates);
741 * IOCTL request handler to set/get rate.
743 * This function can be used to set/get either the rate value or the
746 static int mwifiex_rate_ioctl_cfg(struct mwifiex_private *priv,
747 struct mwifiex_rate_cfg *rate_cfg)
754 if (rate_cfg->action == HostCmd_ACT_GEN_GET)
755 status = mwifiex_rate_ioctl_get_rate_value(priv, rate_cfg);
757 status = mwifiex_rate_ioctl_set_rate_value(priv, rate_cfg);
763 * Sends IOCTL request to get the data rate.
765 * This function allocates the IOCTL request buffer, fills it
766 * with requisite parameters and calls the IOCTL handler.
768 int mwifiex_drv_get_data_rate(struct mwifiex_private *priv,
769 struct mwifiex_rate_cfg *rate)
773 memset(rate, 0, sizeof(struct mwifiex_rate_cfg));
774 rate->action = HostCmd_ACT_GEN_GET;
775 ret = mwifiex_rate_ioctl_cfg(priv, rate);
778 if (rate->is_rate_auto)
779 rate->rate = mwifiex_index_to_data_rate(priv,
780 priv->tx_rate, priv->tx_htinfo);
782 rate->rate = priv->data_rate;
791 * IOCTL request handler to set tx power configuration.
793 * This function prepares the correct firmware command and
796 * For non-auto power mode, all the following power groups are set -
797 * - Modulation class HR/DSSS
798 * - Modulation class OFDM
799 * - Modulation class HTBW20
800 * - Modulation class HTBW40
802 int mwifiex_set_tx_power(struct mwifiex_private *priv,
803 struct mwifiex_power_cfg *power_cfg)
806 struct host_cmd_ds_txpwr_cfg *txp_cfg;
807 struct mwifiex_types_power_group *pg_tlv;
808 struct mwifiex_power_group *pg;
812 if (!power_cfg->is_power_auto) {
813 dbm = (u16) power_cfg->power_level;
814 if ((dbm < priv->min_tx_power_level) ||
815 (dbm > priv->max_tx_power_level)) {
816 dev_err(priv->adapter->dev, "txpower value %d dBm"
817 " is out of range (%d dBm-%d dBm)\n",
818 dbm, priv->min_tx_power_level,
819 priv->max_tx_power_level);
823 buf = kzalloc(MWIFIEX_SIZE_OF_CMD_BUFFER, GFP_KERNEL);
825 dev_err(priv->adapter->dev, "%s: failed to alloc cmd buffer\n",
830 txp_cfg = (struct host_cmd_ds_txpwr_cfg *) buf;
831 txp_cfg->action = cpu_to_le16(HostCmd_ACT_GEN_SET);
832 if (!power_cfg->is_power_auto) {
833 txp_cfg->mode = cpu_to_le32(1);
834 pg_tlv = (struct mwifiex_types_power_group *) (buf +
835 sizeof(struct host_cmd_ds_txpwr_cfg));
836 pg_tlv->type = TLV_TYPE_POWER_GROUP;
837 pg_tlv->length = 4 * sizeof(struct mwifiex_power_group);
838 pg = (struct mwifiex_power_group *) (buf +
839 sizeof(struct host_cmd_ds_txpwr_cfg) +
840 sizeof(struct mwifiex_types_power_group));
841 /* Power group for modulation class HR/DSSS */
842 pg->first_rate_code = 0x00;
843 pg->last_rate_code = 0x03;
844 pg->modulation_class = MOD_CLASS_HR_DSSS;
846 pg->power_min = (s8) dbm;
847 pg->power_max = (s8) dbm;
849 /* Power group for modulation class OFDM */
850 pg->first_rate_code = 0x00;
851 pg->last_rate_code = 0x07;
852 pg->modulation_class = MOD_CLASS_OFDM;
854 pg->power_min = (s8) dbm;
855 pg->power_max = (s8) dbm;
857 /* Power group for modulation class HTBW20 */
858 pg->first_rate_code = 0x00;
859 pg->last_rate_code = 0x20;
860 pg->modulation_class = MOD_CLASS_HT;
862 pg->power_min = (s8) dbm;
863 pg->power_max = (s8) dbm;
864 pg->ht_bandwidth = HT_BW_20;
866 /* Power group for modulation class HTBW40 */
867 pg->first_rate_code = 0x00;
868 pg->last_rate_code = 0x20;
869 pg->modulation_class = MOD_CLASS_HT;
871 pg->power_min = (s8) dbm;
872 pg->power_max = (s8) dbm;
873 pg->ht_bandwidth = HT_BW_40;
875 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_TXPWR_CFG,
876 HostCmd_ACT_GEN_SET, 0, buf);
883 * IOCTL request handler to get power save mode.
885 * This function prepares the correct firmware command and
888 int mwifiex_drv_set_power(struct mwifiex_private *priv, u32 *ps_mode)
891 struct mwifiex_adapter *adapter = priv->adapter;
895 adapter->ps_mode = MWIFIEX_802_11_POWER_MODE_PSP;
897 adapter->ps_mode = MWIFIEX_802_11_POWER_MODE_CAM;
898 sub_cmd = (*ps_mode) ? EN_AUTO_PS : DIS_AUTO_PS;
899 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_PS_MODE_ENH,
900 sub_cmd, BITMAP_STA_PS, NULL);
901 if ((!ret) && (sub_cmd == DIS_AUTO_PS))
902 ret = mwifiex_send_cmd_async(priv,
903 HostCmd_CMD_802_11_PS_MODE_ENH, GET_PS,
910 * IOCTL request handler to set/reset WPA IE.
912 * The supplied WPA IE is treated as a opaque buffer. Only the first field
913 * is checked to determine WPA version. If buffer length is zero, the existing
916 static int mwifiex_set_wpa_ie_helper(struct mwifiex_private *priv,
917 u8 *ie_data_ptr, u16 ie_len)
920 if (ie_len > sizeof(priv->wpa_ie)) {
921 dev_err(priv->adapter->dev,
922 "failed to copy WPA IE, too big\n");
925 memcpy(priv->wpa_ie, ie_data_ptr, ie_len);
926 priv->wpa_ie_len = (u8) ie_len;
927 dev_dbg(priv->adapter->dev, "cmd: Set Wpa_ie_len=%d IE=%#x\n",
928 priv->wpa_ie_len, priv->wpa_ie[0]);
930 if (priv->wpa_ie[0] == WLAN_EID_WPA) {
931 priv->sec_info.wpa_enabled = true;
932 } else if (priv->wpa_ie[0] == WLAN_EID_RSN) {
933 priv->sec_info.wpa2_enabled = true;
935 priv->sec_info.wpa_enabled = false;
936 priv->sec_info.wpa2_enabled = false;
939 memset(priv->wpa_ie, 0, sizeof(priv->wpa_ie));
940 priv->wpa_ie_len = 0;
941 dev_dbg(priv->adapter->dev, "info: reset wpa_ie_len=%d IE=%#x\n",
942 priv->wpa_ie_len, priv->wpa_ie[0]);
943 priv->sec_info.wpa_enabled = false;
944 priv->sec_info.wpa2_enabled = false;
951 * IOCTL request handler to set/reset WAPI IE.
953 * The supplied WAPI IE is treated as a opaque buffer. Only the first field
954 * is checked to internally enable WAPI. If buffer length is zero, the existing
957 static int mwifiex_set_wapi_ie(struct mwifiex_private *priv,
958 u8 *ie_data_ptr, u16 ie_len)
961 if (ie_len > sizeof(priv->wapi_ie)) {
962 dev_dbg(priv->adapter->dev,
963 "info: failed to copy WAPI IE, too big\n");
966 memcpy(priv->wapi_ie, ie_data_ptr, ie_len);
967 priv->wapi_ie_len = ie_len;
968 dev_dbg(priv->adapter->dev, "cmd: Set wapi_ie_len=%d IE=%#x\n",
969 priv->wapi_ie_len, priv->wapi_ie[0]);
971 if (priv->wapi_ie[0] == WLAN_EID_BSS_AC_ACCESS_DELAY)
972 priv->sec_info.wapi_enabled = true;
974 memset(priv->wapi_ie, 0, sizeof(priv->wapi_ie));
975 priv->wapi_ie_len = ie_len;
976 dev_dbg(priv->adapter->dev,
977 "info: Reset wapi_ie_len=%d IE=%#x\n",
978 priv->wapi_ie_len, priv->wapi_ie[0]);
979 priv->sec_info.wapi_enabled = false;
985 * IOCTL request handler to set WAPI key.
987 * This function prepares the correct firmware command and
990 static int mwifiex_sec_ioctl_set_wapi_key(struct mwifiex_private *priv,
991 struct mwifiex_ds_encrypt_key *encrypt_key)
994 return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_KEY_MATERIAL,
995 HostCmd_ACT_GEN_SET, KEY_INFO_ENABLED,
1000 * IOCTL request handler to set WEP network key.
1002 * This function prepares the correct firmware command and
1003 * issues it, after validation checks.
1005 static int mwifiex_sec_ioctl_set_wep_key(struct mwifiex_private *priv,
1006 struct mwifiex_ds_encrypt_key *encrypt_key)
1009 struct mwifiex_wep_key *wep_key;
1012 if (priv->wep_key_curr_index >= NUM_WEP_KEYS)
1013 priv->wep_key_curr_index = 0;
1014 wep_key = &priv->wep_key[priv->wep_key_curr_index];
1015 index = encrypt_key->key_index;
1016 if (encrypt_key->key_disable) {
1017 priv->sec_info.wep_status = MWIFIEX_802_11_WEP_DISABLED;
1018 } else if (!encrypt_key->key_len) {
1019 /* Copy the required key as the current key */
1020 wep_key = &priv->wep_key[index];
1021 if (!wep_key->key_length) {
1022 dev_err(priv->adapter->dev,
1023 "key not set, so cannot enable it\n");
1026 priv->wep_key_curr_index = (u16) index;
1027 priv->sec_info.wep_status = MWIFIEX_802_11_WEP_ENABLED;
1029 wep_key = &priv->wep_key[index];
1030 memset(wep_key, 0, sizeof(struct mwifiex_wep_key));
1031 /* Copy the key in the driver */
1032 memcpy(wep_key->key_material,
1033 encrypt_key->key_material,
1034 encrypt_key->key_len);
1035 wep_key->key_index = index;
1036 wep_key->key_length = encrypt_key->key_len;
1037 priv->sec_info.wep_status = MWIFIEX_802_11_WEP_ENABLED;
1039 if (wep_key->key_length) {
1040 /* Send request to firmware */
1041 ret = mwifiex_send_cmd_async(priv,
1042 HostCmd_CMD_802_11_KEY_MATERIAL,
1043 HostCmd_ACT_GEN_SET, 0, NULL);
1047 if (priv->sec_info.wep_status == MWIFIEX_802_11_WEP_ENABLED)
1048 priv->curr_pkt_filter |= HostCmd_ACT_MAC_WEP_ENABLE;
1050 priv->curr_pkt_filter &= ~HostCmd_ACT_MAC_WEP_ENABLE;
1052 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_MAC_CONTROL,
1053 HostCmd_ACT_GEN_SET, 0,
1054 &priv->curr_pkt_filter);
1060 * IOCTL request handler to set WPA key.
1062 * This function prepares the correct firmware command and
1063 * issues it, after validation checks.
1065 * Current driver only supports key length of up to 32 bytes.
1067 * This function can also be used to disable a currently set key.
1069 static int mwifiex_sec_ioctl_set_wpa_key(struct mwifiex_private *priv,
1070 struct mwifiex_ds_encrypt_key *encrypt_key)
1073 u8 remove_key = false;
1074 struct host_cmd_ds_802_11_key_material *ibss_key;
1076 /* Current driver only supports key length of up to 32 bytes */
1077 if (encrypt_key->key_len > WLAN_MAX_KEY_LEN) {
1078 dev_err(priv->adapter->dev, "key length too long\n");
1082 if (priv->bss_mode == NL80211_IFTYPE_ADHOC) {
1084 * IBSS/WPA-None uses only one key (Group) for both receiving
1085 * and sending unicast and multicast packets.
1087 /* Send the key as PTK to firmware */
1088 encrypt_key->key_index = MWIFIEX_KEY_INDEX_UNICAST;
1089 ret = mwifiex_send_cmd_async(priv,
1090 HostCmd_CMD_802_11_KEY_MATERIAL,
1091 HostCmd_ACT_GEN_SET, KEY_INFO_ENABLED,
1096 ibss_key = &priv->aes_key;
1098 sizeof(struct host_cmd_ds_802_11_key_material));
1099 /* Copy the key in the driver */
1100 memcpy(ibss_key->key_param_set.key, encrypt_key->key_material,
1101 encrypt_key->key_len);
1102 memcpy(&ibss_key->key_param_set.key_len, &encrypt_key->key_len,
1103 sizeof(ibss_key->key_param_set.key_len));
1104 ibss_key->key_param_set.key_type_id
1105 = cpu_to_le16(KEY_TYPE_ID_TKIP);
1106 ibss_key->key_param_set.key_info = cpu_to_le16(KEY_ENABLED);
1108 /* Send the key as GTK to firmware */
1109 encrypt_key->key_index = ~MWIFIEX_KEY_INDEX_UNICAST;
1112 if (!encrypt_key->key_index)
1113 encrypt_key->key_index = MWIFIEX_KEY_INDEX_UNICAST;
1116 ret = mwifiex_send_cmd_sync(priv,
1117 HostCmd_CMD_802_11_KEY_MATERIAL,
1118 HostCmd_ACT_GEN_SET, !(KEY_INFO_ENABLED),
1121 ret = mwifiex_send_cmd_sync(priv,
1122 HostCmd_CMD_802_11_KEY_MATERIAL,
1123 HostCmd_ACT_GEN_SET, KEY_INFO_ENABLED,
1130 * IOCTL request handler to set/get network keys.
1132 * This is a generic key handling function which supports WEP, WPA
1136 mwifiex_sec_ioctl_encrypt_key(struct mwifiex_private *priv,
1137 struct mwifiex_ds_encrypt_key *encrypt_key)
1141 if (encrypt_key->is_wapi_key)
1142 status = mwifiex_sec_ioctl_set_wapi_key(priv, encrypt_key);
1143 else if (encrypt_key->key_len > WLAN_KEY_LEN_WEP104)
1144 status = mwifiex_sec_ioctl_set_wpa_key(priv, encrypt_key);
1146 status = mwifiex_sec_ioctl_set_wep_key(priv, encrypt_key);
1151 * This function returns the driver version.
1154 mwifiex_drv_get_driver_version(struct mwifiex_adapter *adapter, char *version,
1163 ver.l = adapter->fw_release_number;
1164 sprintf(fw_ver, "%u.%u.%u.p%u", ver.c[2], ver.c[1], ver.c[0], ver.c[3]);
1166 snprintf(version, max_len, driver_version, fw_ver);
1168 dev_dbg(adapter->dev, "info: MWIFIEX VERSION: %s\n", version);
1174 * Sends IOCTL request to get signal information.
1176 * This function allocates the IOCTL request buffer, fills it
1177 * with requisite parameters and calls the IOCTL handler.
1179 int mwifiex_get_signal_info(struct mwifiex_private *priv,
1180 struct mwifiex_ds_get_signal *signal)
1184 signal->selector = ALL_RSSI_INFO_MASK;
1186 /* Signal info can be obtained only if connected */
1187 if (!priv->media_connected) {
1188 dev_dbg(priv->adapter->dev,
1189 "info: Can not get signal in disconnected state\n");
1193 status = mwifiex_send_cmd_sync(priv, HostCmd_CMD_RSSI_INFO,
1194 HostCmd_ACT_GEN_GET, 0, signal);
1197 if (signal->selector & BCN_RSSI_AVG_MASK)
1198 priv->qual_level = signal->bcn_rssi_avg;
1199 if (signal->selector & BCN_NF_AVG_MASK)
1200 priv->qual_noise = signal->bcn_nf_avg;
1207 * Sends IOCTL request to set encoding parameters.
1209 * This function allocates the IOCTL request buffer, fills it
1210 * with requisite parameters and calls the IOCTL handler.
1212 int mwifiex_set_encode(struct mwifiex_private *priv, const u8 *key,
1213 int key_len, u8 key_index, int disable)
1215 struct mwifiex_ds_encrypt_key encrypt_key;
1217 memset(&encrypt_key, 0, sizeof(struct mwifiex_ds_encrypt_key));
1218 encrypt_key.key_len = key_len;
1220 encrypt_key.key_index = key_index;
1222 memcpy(encrypt_key.key_material, key, key_len);
1224 encrypt_key.key_disable = true;
1227 return mwifiex_sec_ioctl_encrypt_key(priv, &encrypt_key);
1231 * Sends IOCTL request to get extended version.
1233 * This function allocates the IOCTL request buffer, fills it
1234 * with requisite parameters and calls the IOCTL handler.
1237 mwifiex_get_ver_ext(struct mwifiex_private *priv)
1239 struct mwifiex_ver_ext ver_ext;
1241 memset(&ver_ext, 0, sizeof(struct host_cmd_ds_version_ext));
1242 if (mwifiex_send_cmd_sync(priv, HostCmd_CMD_VERSION_EXT,
1243 HostCmd_ACT_GEN_GET, 0, &ver_ext))
1250 * Sends IOCTL request to get statistics information.
1252 * This function allocates the IOCTL request buffer, fills it
1253 * with requisite parameters and calls the IOCTL handler.
1256 mwifiex_get_stats_info(struct mwifiex_private *priv,
1257 struct mwifiex_ds_get_stats *log)
1259 return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_GET_LOG,
1260 HostCmd_ACT_GEN_GET, 0, log);
1264 * IOCTL request handler to read/write register.
1266 * This function prepares the correct firmware command and
1269 * Access to the following registers are supported -
1276 static int mwifiex_reg_mem_ioctl_reg_rw(struct mwifiex_private *priv,
1277 struct mwifiex_ds_reg_rw *reg_rw,
1282 switch (le32_to_cpu(reg_rw->type)) {
1283 case MWIFIEX_REG_MAC:
1284 cmd_no = HostCmd_CMD_MAC_REG_ACCESS;
1286 case MWIFIEX_REG_BBP:
1287 cmd_no = HostCmd_CMD_BBP_REG_ACCESS;
1289 case MWIFIEX_REG_RF:
1290 cmd_no = HostCmd_CMD_RF_REG_ACCESS;
1292 case MWIFIEX_REG_PMIC:
1293 cmd_no = HostCmd_CMD_PMIC_REG_ACCESS;
1295 case MWIFIEX_REG_CAU:
1296 cmd_no = HostCmd_CMD_CAU_REG_ACCESS;
1302 return mwifiex_send_cmd_sync(priv, cmd_no, action, 0, reg_rw);
1307 * Sends IOCTL request to write to a register.
1309 * This function allocates the IOCTL request buffer, fills it
1310 * with requisite parameters and calls the IOCTL handler.
1313 mwifiex_reg_write(struct mwifiex_private *priv, u32 reg_type,
1314 u32 reg_offset, u32 reg_value)
1316 struct mwifiex_ds_reg_rw reg_rw;
1318 reg_rw.type = cpu_to_le32(reg_type);
1319 reg_rw.offset = cpu_to_le32(reg_offset);
1320 reg_rw.value = cpu_to_le32(reg_value);
1322 return mwifiex_reg_mem_ioctl_reg_rw(priv, ®_rw, HostCmd_ACT_GEN_SET);
1326 * Sends IOCTL request to read from a register.
1328 * This function allocates the IOCTL request buffer, fills it
1329 * with requisite parameters and calls the IOCTL handler.
1332 mwifiex_reg_read(struct mwifiex_private *priv, u32 reg_type,
1333 u32 reg_offset, u32 *value)
1336 struct mwifiex_ds_reg_rw reg_rw;
1338 reg_rw.type = cpu_to_le32(reg_type);
1339 reg_rw.offset = cpu_to_le32(reg_offset);
1340 ret = mwifiex_reg_mem_ioctl_reg_rw(priv, ®_rw, HostCmd_ACT_GEN_GET);
1345 *value = le32_to_cpu(reg_rw.value);
1352 * Sends IOCTL request to read from EEPROM.
1354 * This function allocates the IOCTL request buffer, fills it
1355 * with requisite parameters and calls the IOCTL handler.
1358 mwifiex_eeprom_read(struct mwifiex_private *priv, u16 offset, u16 bytes,
1362 struct mwifiex_ds_read_eeprom rd_eeprom;
1364 rd_eeprom.offset = cpu_to_le16((u16) offset);
1365 rd_eeprom.byte_count = cpu_to_le16((u16) bytes);
1367 /* Send request to firmware */
1368 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_EEPROM_ACCESS,
1369 HostCmd_ACT_GEN_GET, 0, &rd_eeprom);
1372 memcpy(value, rd_eeprom.value, MAX_EEPROM_DATA);
1377 * This function sets a generic IE. In addition to generic IE, it can
1378 * also handle WPA, WPA2 and WAPI IEs.
1381 mwifiex_set_gen_ie_helper(struct mwifiex_private *priv, u8 *ie_data_ptr,
1385 struct ieee_types_vendor_header *pvendor_ie;
1386 const u8 wpa_oui[] = { 0x00, 0x50, 0xf2, 0x01 };
1387 const u8 wps_oui[] = { 0x00, 0x50, 0xf2, 0x04 };
1389 /* If the passed length is zero, reset the buffer */
1391 priv->gen_ie_buf_len = 0;
1392 priv->wps.session_enable = false;
1395 } else if (!ie_data_ptr) {
1398 pvendor_ie = (struct ieee_types_vendor_header *) ie_data_ptr;
1399 /* Test to see if it is a WPA IE, if not, then it is a gen IE */
1400 if (((pvendor_ie->element_id == WLAN_EID_WPA)
1401 && (!memcmp(pvendor_ie->oui, wpa_oui, sizeof(wpa_oui))))
1402 || (pvendor_ie->element_id == WLAN_EID_RSN)) {
1404 /* IE is a WPA/WPA2 IE so call set_wpa function */
1405 ret = mwifiex_set_wpa_ie_helper(priv, ie_data_ptr, ie_len);
1406 priv->wps.session_enable = false;
1409 } else if (pvendor_ie->element_id == WLAN_EID_BSS_AC_ACCESS_DELAY) {
1410 /* IE is a WAPI IE so call set_wapi function */
1411 ret = mwifiex_set_wapi_ie(priv, ie_data_ptr, ie_len);
1416 * Verify that the passed length is not larger than the
1417 * available space remaining in the buffer
1419 if (ie_len < (sizeof(priv->gen_ie_buf) - priv->gen_ie_buf_len)) {
1421 /* Test to see if it is a WPS IE, if so, enable
1424 pvendor_ie = (struct ieee_types_vendor_header *) ie_data_ptr;
1425 if ((pvendor_ie->element_id == WLAN_EID_VENDOR_SPECIFIC)
1426 && (!memcmp(pvendor_ie->oui, wps_oui,
1427 sizeof(wps_oui)))) {
1428 priv->wps.session_enable = true;
1429 dev_dbg(priv->adapter->dev,
1430 "info: WPS Session Enabled.\n");
1433 /* Append the passed data to the end of the
1435 memcpy(priv->gen_ie_buf + priv->gen_ie_buf_len, ie_data_ptr,
1437 /* Increment the stored buffer length by the
1439 priv->gen_ie_buf_len += ie_len;
1441 /* Passed data does not fit in the remaining
1446 /* Return 0, or -1 for error case */
1451 * IOCTL request handler to set/get generic IE.
1453 * In addition to various generic IEs, this function can also be
1454 * used to set the ARP filter.
1456 static int mwifiex_misc_ioctl_gen_ie(struct mwifiex_private *priv,
1457 struct mwifiex_ds_misc_gen_ie *gen_ie,
1460 struct mwifiex_adapter *adapter = priv->adapter;
1462 switch (gen_ie->type) {
1463 case MWIFIEX_IE_TYPE_GEN_IE:
1464 if (action == HostCmd_ACT_GEN_GET) {
1465 gen_ie->len = priv->wpa_ie_len;
1466 memcpy(gen_ie->ie_data, priv->wpa_ie, gen_ie->len);
1468 mwifiex_set_gen_ie_helper(priv, gen_ie->ie_data,
1472 case MWIFIEX_IE_TYPE_ARP_FILTER:
1473 memset(adapter->arp_filter, 0, sizeof(adapter->arp_filter));
1474 if (gen_ie->len > ARP_FILTER_MAX_BUF_SIZE) {
1475 adapter->arp_filter_size = 0;
1476 dev_err(adapter->dev, "invalid ARP filter size\n");
1479 memcpy(adapter->arp_filter, gen_ie->ie_data,
1481 adapter->arp_filter_size = gen_ie->len;
1485 dev_err(adapter->dev, "invalid IE type\n");
1492 * Sends IOCTL request to set a generic IE.
1494 * This function allocates the IOCTL request buffer, fills it
1495 * with requisite parameters and calls the IOCTL handler.
1498 mwifiex_set_gen_ie(struct mwifiex_private *priv, u8 *ie, int ie_len)
1500 struct mwifiex_ds_misc_gen_ie gen_ie;
1502 if (ie_len > IEEE_MAX_IE_SIZE)
1505 gen_ie.type = MWIFIEX_IE_TYPE_GEN_IE;
1506 gen_ie.len = ie_len;
1507 memcpy(gen_ie.ie_data, ie, ie_len);
1508 if (mwifiex_misc_ioctl_gen_ie(priv, &gen_ie, HostCmd_ACT_GEN_SET))