2 * NXP Wireless LAN device driver: CFG80211
4 * Copyright 2011-2020 NXP
6 * This software file (the "File") is distributed by NXP
7 * 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.
25 static char *reg_alpha2;
26 module_param(reg_alpha2, charp, 0);
28 static const struct ieee80211_iface_limit mwifiex_ap_sta_limits[] = {
30 .max = MWIFIEX_MAX_BSS_NUM,
31 .types = BIT(NL80211_IFTYPE_STATION) |
32 BIT(NL80211_IFTYPE_P2P_GO) |
33 BIT(NL80211_IFTYPE_P2P_CLIENT) |
34 BIT(NL80211_IFTYPE_AP),
38 static const struct ieee80211_iface_combination
39 mwifiex_iface_comb_ap_sta = {
40 .limits = mwifiex_ap_sta_limits,
41 .num_different_channels = 1,
42 .n_limits = ARRAY_SIZE(mwifiex_ap_sta_limits),
43 .max_interfaces = MWIFIEX_MAX_BSS_NUM,
44 .beacon_int_infra_match = true,
45 .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
46 BIT(NL80211_CHAN_WIDTH_20) |
47 BIT(NL80211_CHAN_WIDTH_40),
50 static const struct ieee80211_iface_combination
51 mwifiex_iface_comb_ap_sta_vht = {
52 .limits = mwifiex_ap_sta_limits,
53 .num_different_channels = 1,
54 .n_limits = ARRAY_SIZE(mwifiex_ap_sta_limits),
55 .max_interfaces = MWIFIEX_MAX_BSS_NUM,
56 .beacon_int_infra_match = true,
57 .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
58 BIT(NL80211_CHAN_WIDTH_20) |
59 BIT(NL80211_CHAN_WIDTH_40) |
60 BIT(NL80211_CHAN_WIDTH_80),
64 ieee80211_iface_combination mwifiex_iface_comb_ap_sta_drcs = {
65 .limits = mwifiex_ap_sta_limits,
66 .num_different_channels = 2,
67 .n_limits = ARRAY_SIZE(mwifiex_ap_sta_limits),
68 .max_interfaces = MWIFIEX_MAX_BSS_NUM,
69 .beacon_int_infra_match = true,
73 * This function maps the nl802.11 channel type into driver channel type.
75 * The mapping is as follows -
76 * NL80211_CHAN_NO_HT -> IEEE80211_HT_PARAM_CHA_SEC_NONE
77 * NL80211_CHAN_HT20 -> IEEE80211_HT_PARAM_CHA_SEC_NONE
78 * NL80211_CHAN_HT40PLUS -> IEEE80211_HT_PARAM_CHA_SEC_ABOVE
79 * NL80211_CHAN_HT40MINUS -> IEEE80211_HT_PARAM_CHA_SEC_BELOW
80 * Others -> IEEE80211_HT_PARAM_CHA_SEC_NONE
82 u8 mwifiex_chan_type_to_sec_chan_offset(enum nl80211_channel_type chan_type)
85 case NL80211_CHAN_NO_HT:
86 case NL80211_CHAN_HT20:
87 return IEEE80211_HT_PARAM_CHA_SEC_NONE;
88 case NL80211_CHAN_HT40PLUS:
89 return IEEE80211_HT_PARAM_CHA_SEC_ABOVE;
90 case NL80211_CHAN_HT40MINUS:
91 return IEEE80211_HT_PARAM_CHA_SEC_BELOW;
93 return IEEE80211_HT_PARAM_CHA_SEC_NONE;
97 /* This function maps IEEE HT secondary channel type to NL80211 channel type
99 u8 mwifiex_get_chan_type(struct mwifiex_private *priv)
101 struct mwifiex_channel_band channel_band;
104 ret = mwifiex_get_chan_info(priv, &channel_band);
107 switch (channel_band.band_config.chan_width) {
109 if (IS_11N_ENABLED(priv))
110 return NL80211_CHAN_HT20;
112 return NL80211_CHAN_NO_HT;
114 if (channel_band.band_config.chan2_offset ==
116 return NL80211_CHAN_HT40PLUS;
118 return NL80211_CHAN_HT40MINUS;
120 return NL80211_CHAN_HT20;
124 return NL80211_CHAN_HT20;
128 * This function checks whether WEP is set.
131 mwifiex_is_alg_wep(u32 cipher)
134 case WLAN_CIPHER_SUITE_WEP40:
135 case WLAN_CIPHER_SUITE_WEP104:
145 * This function retrieves the private structure from kernel wiphy structure.
147 static void *mwifiex_cfg80211_get_adapter(struct wiphy *wiphy)
149 return (void *) (*(unsigned long *) wiphy_priv(wiphy));
153 * CFG802.11 operation handler to delete a network key.
156 mwifiex_cfg80211_del_key(struct wiphy *wiphy, struct net_device *netdev,
157 u8 key_index, bool pairwise, const u8 *mac_addr)
159 struct mwifiex_private *priv = mwifiex_netdev_get_priv(netdev);
160 static const u8 bc_mac[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
161 const u8 *peer_mac = pairwise ? mac_addr : bc_mac;
163 if (mwifiex_set_encode(priv, NULL, NULL, 0, key_index, peer_mac, 1)) {
164 mwifiex_dbg(priv->adapter, ERROR, "deleting the crypto keys\n");
168 mwifiex_dbg(priv->adapter, INFO, "info: crypto keys deleted\n");
173 * This function forms an skb for management frame.
176 mwifiex_form_mgmt_frame(struct sk_buff *skb, const u8 *buf, size_t len)
178 u8 addr[ETH_ALEN] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
180 u32 tx_control = 0, pkt_type = PKT_TYPE_MGMT;
182 pkt_len = len + ETH_ALEN;
184 skb_reserve(skb, MWIFIEX_MIN_DATA_HEADER_LEN +
185 MWIFIEX_MGMT_FRAME_HEADER_SIZE + sizeof(pkt_len));
186 memcpy(skb_push(skb, sizeof(pkt_len)), &pkt_len, sizeof(pkt_len));
188 memcpy(skb_push(skb, sizeof(tx_control)),
189 &tx_control, sizeof(tx_control));
191 memcpy(skb_push(skb, sizeof(pkt_type)), &pkt_type, sizeof(pkt_type));
193 /* Add packet data and address4 */
194 skb_put_data(skb, buf, sizeof(struct ieee80211_hdr_3addr));
195 skb_put_data(skb, addr, ETH_ALEN);
196 skb_put_data(skb, buf + sizeof(struct ieee80211_hdr_3addr),
197 len - sizeof(struct ieee80211_hdr_3addr));
199 skb->priority = LOW_PRIO_TID;
200 __net_timestamp(skb);
206 * CFG802.11 operation handler to transmit a management frame.
209 mwifiex_cfg80211_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev,
210 struct cfg80211_mgmt_tx_params *params, u64 *cookie)
212 const u8 *buf = params->buf;
213 size_t len = params->len;
216 const struct ieee80211_mgmt *mgmt;
217 struct mwifiex_txinfo *tx_info;
218 struct mwifiex_private *priv = mwifiex_netdev_get_priv(wdev->netdev);
221 mwifiex_dbg(priv->adapter, ERROR, "invalid buffer and length\n");
225 mgmt = (const struct ieee80211_mgmt *)buf;
226 if (GET_BSS_ROLE(priv) != MWIFIEX_BSS_ROLE_STA &&
227 ieee80211_is_probe_resp(mgmt->frame_control)) {
228 /* Since we support offload probe resp, we need to skip probe
229 * resp in AP or GO mode */
230 mwifiex_dbg(priv->adapter, INFO,
231 "info: skip to send probe resp in AP or GO mode\n");
235 pkt_len = len + ETH_ALEN;
236 skb = dev_alloc_skb(MWIFIEX_MIN_DATA_HEADER_LEN +
237 MWIFIEX_MGMT_FRAME_HEADER_SIZE +
238 pkt_len + sizeof(pkt_len));
241 mwifiex_dbg(priv->adapter, ERROR,
242 "allocate skb failed for management frame\n");
246 tx_info = MWIFIEX_SKB_TXCB(skb);
247 memset(tx_info, 0, sizeof(*tx_info));
248 tx_info->bss_num = priv->bss_num;
249 tx_info->bss_type = priv->bss_type;
250 tx_info->pkt_len = pkt_len;
252 mwifiex_form_mgmt_frame(skb, buf, len);
253 *cookie = prandom_u32() | 1;
255 if (ieee80211_is_action(mgmt->frame_control))
256 skb = mwifiex_clone_skb_for_tx_status(priv,
258 MWIFIEX_BUF_FLAG_ACTION_TX_STATUS, cookie);
260 cfg80211_mgmt_tx_status(wdev, *cookie, buf, len, true,
263 mwifiex_queue_tx_pkt(priv, skb);
265 mwifiex_dbg(priv->adapter, INFO, "info: management frame transmitted\n");
270 * CFG802.11 operation handler to register a mgmt frame.
273 mwifiex_cfg80211_update_mgmt_frame_registrations(struct wiphy *wiphy,
274 struct wireless_dev *wdev,
275 struct mgmt_frame_regs *upd)
277 struct mwifiex_private *priv = mwifiex_netdev_get_priv(wdev->netdev);
278 u32 mask = upd->interface_stypes;
280 if (mask != priv->mgmt_frame_mask) {
281 priv->mgmt_frame_mask = mask;
282 mwifiex_send_cmd(priv, HostCmd_CMD_MGMT_FRAME_REG,
283 HostCmd_ACT_GEN_SET, 0,
284 &priv->mgmt_frame_mask, false);
285 mwifiex_dbg(priv->adapter, INFO, "info: mgmt frame registered\n");
290 * CFG802.11 operation handler to remain on channel.
293 mwifiex_cfg80211_remain_on_channel(struct wiphy *wiphy,
294 struct wireless_dev *wdev,
295 struct ieee80211_channel *chan,
296 unsigned int duration, u64 *cookie)
298 struct mwifiex_private *priv = mwifiex_netdev_get_priv(wdev->netdev);
301 if (!chan || !cookie) {
302 mwifiex_dbg(priv->adapter, ERROR, "Invalid parameter for ROC\n");
306 if (priv->roc_cfg.cookie) {
307 mwifiex_dbg(priv->adapter, INFO,
308 "info: ongoing ROC, cookie = 0x%llx\n",
309 priv->roc_cfg.cookie);
313 ret = mwifiex_remain_on_chan_cfg(priv, HostCmd_ACT_GEN_SET, chan,
317 *cookie = prandom_u32() | 1;
318 priv->roc_cfg.cookie = *cookie;
319 priv->roc_cfg.chan = *chan;
321 cfg80211_ready_on_channel(wdev, *cookie, chan,
322 duration, GFP_ATOMIC);
324 mwifiex_dbg(priv->adapter, INFO,
325 "info: ROC, cookie = 0x%llx\n", *cookie);
332 * CFG802.11 operation handler to cancel remain on channel.
335 mwifiex_cfg80211_cancel_remain_on_channel(struct wiphy *wiphy,
336 struct wireless_dev *wdev, u64 cookie)
338 struct mwifiex_private *priv = mwifiex_netdev_get_priv(wdev->netdev);
341 if (cookie != priv->roc_cfg.cookie)
344 ret = mwifiex_remain_on_chan_cfg(priv, HostCmd_ACT_GEN_REMOVE,
345 &priv->roc_cfg.chan, 0);
348 cfg80211_remain_on_channel_expired(wdev, cookie,
352 memset(&priv->roc_cfg, 0, sizeof(struct mwifiex_roc_cfg));
354 mwifiex_dbg(priv->adapter, INFO,
355 "info: cancel ROC, cookie = 0x%llx\n", cookie);
362 * CFG802.11 operation handler to set Tx power.
365 mwifiex_cfg80211_set_tx_power(struct wiphy *wiphy,
366 struct wireless_dev *wdev,
367 enum nl80211_tx_power_setting type,
370 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
371 struct mwifiex_private *priv;
372 struct mwifiex_power_cfg power_cfg;
373 int dbm = MBM_TO_DBM(mbm);
376 case NL80211_TX_POWER_FIXED:
377 power_cfg.is_power_auto = 0;
378 power_cfg.is_power_fixed = 1;
379 power_cfg.power_level = dbm;
381 case NL80211_TX_POWER_LIMITED:
382 power_cfg.is_power_auto = 0;
383 power_cfg.is_power_fixed = 0;
384 power_cfg.power_level = dbm;
386 case NL80211_TX_POWER_AUTOMATIC:
387 power_cfg.is_power_auto = 1;
391 priv = mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY);
393 return mwifiex_set_tx_power(priv, &power_cfg);
397 * CFG802.11 operation handler to get Tx power.
400 mwifiex_cfg80211_get_tx_power(struct wiphy *wiphy,
401 struct wireless_dev *wdev,
404 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
405 struct mwifiex_private *priv = mwifiex_get_priv(adapter,
406 MWIFIEX_BSS_ROLE_ANY);
407 int ret = mwifiex_send_cmd(priv, HostCmd_CMD_RF_TX_PWR,
408 HostCmd_ACT_GEN_GET, 0, NULL, true);
413 /* tx_power_level is set in HostCmd_CMD_RF_TX_PWR command handler */
414 *dbm = priv->tx_power_level;
420 * CFG802.11 operation handler to set Power Save option.
422 * The timeout value, if provided, is currently ignored.
425 mwifiex_cfg80211_set_power_mgmt(struct wiphy *wiphy,
426 struct net_device *dev,
427 bool enabled, int timeout)
429 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
433 mwifiex_dbg(priv->adapter, INFO,
434 "info: ignore timeout value for IEEE Power Save\n");
438 return mwifiex_drv_set_power(priv, &ps_mode);
442 * CFG802.11 operation handler to set the default network key.
445 mwifiex_cfg80211_set_default_key(struct wiphy *wiphy, struct net_device *netdev,
446 u8 key_index, bool unicast,
449 struct mwifiex_private *priv = mwifiex_netdev_get_priv(netdev);
451 /* Return if WEP key not configured */
452 if (!priv->sec_info.wep_enabled)
455 if (priv->bss_type == MWIFIEX_BSS_TYPE_UAP) {
456 priv->wep_key_curr_index = key_index;
457 } else if (mwifiex_set_encode(priv, NULL, NULL, 0, key_index,
459 mwifiex_dbg(priv->adapter, ERROR, "set default Tx key index\n");
467 * CFG802.11 operation handler to add a network key.
470 mwifiex_cfg80211_add_key(struct wiphy *wiphy, struct net_device *netdev,
471 u8 key_index, bool pairwise, const u8 *mac_addr,
472 struct key_params *params)
474 struct mwifiex_private *priv = mwifiex_netdev_get_priv(netdev);
475 struct mwifiex_wep_key *wep_key;
476 static const u8 bc_mac[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
477 const u8 *peer_mac = pairwise ? mac_addr : bc_mac;
479 if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_UAP &&
480 (params->cipher == WLAN_CIPHER_SUITE_WEP40 ||
481 params->cipher == WLAN_CIPHER_SUITE_WEP104)) {
482 if (params->key && params->key_len) {
483 wep_key = &priv->wep_key[key_index];
484 memset(wep_key, 0, sizeof(struct mwifiex_wep_key));
485 memcpy(wep_key->key_material, params->key,
487 wep_key->key_index = key_index;
488 wep_key->key_length = params->key_len;
489 priv->sec_info.wep_enabled = 1;
494 if (mwifiex_set_encode(priv, params, params->key, params->key_len,
495 key_index, peer_mac, 0)) {
496 mwifiex_dbg(priv->adapter, ERROR, "crypto keys added\n");
504 * CFG802.11 operation handler to set default mgmt key.
507 mwifiex_cfg80211_set_default_mgmt_key(struct wiphy *wiphy,
508 struct net_device *netdev,
511 struct mwifiex_private *priv = mwifiex_netdev_get_priv(netdev);
512 struct mwifiex_ds_encrypt_key encrypt_key;
514 wiphy_dbg(wiphy, "set default mgmt key, key index=%d\n", key_index);
516 memset(&encrypt_key, 0, sizeof(struct mwifiex_ds_encrypt_key));
517 encrypt_key.key_len = WLAN_KEY_LEN_CCMP;
518 encrypt_key.key_index = key_index;
519 encrypt_key.is_igtk_def_key = true;
520 eth_broadcast_addr(encrypt_key.mac_addr);
522 if (mwifiex_send_cmd(priv, HostCmd_CMD_802_11_KEY_MATERIAL,
523 HostCmd_ACT_GEN_SET, true, &encrypt_key, true)) {
524 mwifiex_dbg(priv->adapter, ERROR,
525 "Sending KEY_MATERIAL command failed\n");
533 * This function sends domain information to the firmware.
535 * The following information are passed to the firmware -
537 * - Sub bands (first channel, number of channels, maximum Tx power)
539 int mwifiex_send_domain_info_cmd_fw(struct wiphy *wiphy)
541 u8 no_of_triplet = 0;
542 struct ieee80211_country_ie_triplet *t;
543 u8 no_of_parsed_chan = 0;
544 u8 first_chan = 0, next_chan = 0, max_pwr = 0;
546 enum nl80211_band band;
547 struct ieee80211_supported_band *sband;
548 struct ieee80211_channel *ch;
549 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
550 struct mwifiex_private *priv;
551 struct mwifiex_802_11d_domain_reg *domain_info = &adapter->domain_reg;
553 /* Set country code */
554 domain_info->country_code[0] = adapter->country_code[0];
555 domain_info->country_code[1] = adapter->country_code[1];
556 domain_info->country_code[2] = ' ';
558 band = mwifiex_band_to_radio_type(adapter->config_bands);
559 if (!wiphy->bands[band]) {
560 mwifiex_dbg(adapter, ERROR,
561 "11D: setting domain info in FW\n");
565 sband = wiphy->bands[band];
567 for (i = 0; i < sband->n_channels ; i++) {
568 ch = &sband->channels[i];
569 if (ch->flags & IEEE80211_CHAN_DISABLED)
574 first_chan = (u32) ch->hw_value;
575 next_chan = first_chan;
576 max_pwr = ch->max_power;
577 no_of_parsed_chan = 1;
581 if (ch->hw_value == next_chan + 1 &&
582 ch->max_power == max_pwr) {
586 t = &domain_info->triplet[no_of_triplet];
587 t->chans.first_channel = first_chan;
588 t->chans.num_channels = no_of_parsed_chan;
589 t->chans.max_power = max_pwr;
591 first_chan = (u32) ch->hw_value;
592 next_chan = first_chan;
593 max_pwr = ch->max_power;
594 no_of_parsed_chan = 1;
599 t = &domain_info->triplet[no_of_triplet];
600 t->chans.first_channel = first_chan;
601 t->chans.num_channels = no_of_parsed_chan;
602 t->chans.max_power = max_pwr;
606 domain_info->no_of_triplet = no_of_triplet;
608 priv = mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY);
610 if (mwifiex_send_cmd(priv, HostCmd_CMD_802_11D_DOMAIN_INFO,
611 HostCmd_ACT_GEN_SET, 0, NULL, false)) {
612 mwifiex_dbg(adapter, INFO,
613 "11D: setting domain info in FW\n");
620 static void mwifiex_reg_apply_radar_flags(struct wiphy *wiphy)
622 struct ieee80211_supported_band *sband;
623 struct ieee80211_channel *chan;
626 if (!wiphy->bands[NL80211_BAND_5GHZ])
628 sband = wiphy->bands[NL80211_BAND_5GHZ];
630 for (i = 0; i < sband->n_channels; i++) {
631 chan = &sband->channels[i];
632 if ((!(chan->flags & IEEE80211_CHAN_DISABLED)) &&
633 (chan->flags & IEEE80211_CHAN_RADAR))
634 chan->flags |= IEEE80211_CHAN_NO_IR;
639 * CFG802.11 regulatory domain callback function.
641 * This function is called when the regulatory domain is changed due to the
642 * following reasons -
644 * - Set by system core
646 * - Set bt Country IE
648 static void mwifiex_reg_notifier(struct wiphy *wiphy,
649 struct regulatory_request *request)
651 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
652 struct mwifiex_private *priv = mwifiex_get_priv(adapter,
653 MWIFIEX_BSS_ROLE_ANY);
654 mwifiex_dbg(adapter, INFO,
655 "info: cfg80211 regulatory domain callback for %c%c\n",
656 request->alpha2[0], request->alpha2[1]);
657 mwifiex_reg_apply_radar_flags(wiphy);
659 switch (request->initiator) {
660 case NL80211_REGDOM_SET_BY_DRIVER:
661 case NL80211_REGDOM_SET_BY_CORE:
662 case NL80211_REGDOM_SET_BY_USER:
663 case NL80211_REGDOM_SET_BY_COUNTRY_IE:
666 mwifiex_dbg(adapter, ERROR,
667 "unknown regdom initiator: %d\n",
672 /* Don't send world or same regdom info to firmware */
673 if (strncmp(request->alpha2, "00", 2) &&
674 strncmp(request->alpha2, adapter->country_code,
675 sizeof(request->alpha2))) {
676 memcpy(adapter->country_code, request->alpha2,
677 sizeof(request->alpha2));
678 mwifiex_send_domain_info_cmd_fw(wiphy);
679 mwifiex_dnld_txpwr_table(priv);
684 * This function sets the fragmentation threshold.
686 * The fragmentation threshold value must lie between MWIFIEX_FRAG_MIN_VALUE
687 * and MWIFIEX_FRAG_MAX_VALUE.
690 mwifiex_set_frag(struct mwifiex_private *priv, u32 frag_thr)
692 if (frag_thr < MWIFIEX_FRAG_MIN_VALUE ||
693 frag_thr > MWIFIEX_FRAG_MAX_VALUE)
694 frag_thr = MWIFIEX_FRAG_MAX_VALUE;
696 return mwifiex_send_cmd(priv, HostCmd_CMD_802_11_SNMP_MIB,
697 HostCmd_ACT_GEN_SET, FRAG_THRESH_I,
702 * This function sets the RTS threshold.
704 * The rts value must lie between MWIFIEX_RTS_MIN_VALUE
705 * and MWIFIEX_RTS_MAX_VALUE.
708 mwifiex_set_rts(struct mwifiex_private *priv, u32 rts_thr)
710 if (rts_thr < MWIFIEX_RTS_MIN_VALUE || rts_thr > MWIFIEX_RTS_MAX_VALUE)
711 rts_thr = MWIFIEX_RTS_MAX_VALUE;
713 return mwifiex_send_cmd(priv, HostCmd_CMD_802_11_SNMP_MIB,
714 HostCmd_ACT_GEN_SET, RTS_THRESH_I,
719 * CFG802.11 operation handler to set wiphy parameters.
721 * This function can be used to set the RTS threshold and the
722 * Fragmentation threshold of the driver.
725 mwifiex_cfg80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
727 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
728 struct mwifiex_private *priv;
729 struct mwifiex_uap_bss_param *bss_cfg;
732 priv = mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY);
734 switch (priv->bss_role) {
735 case MWIFIEX_BSS_ROLE_UAP:
736 if (priv->bss_started) {
737 mwifiex_dbg(adapter, ERROR,
738 "cannot change wiphy params when bss started");
742 bss_cfg = kzalloc(sizeof(*bss_cfg), GFP_KERNEL);
746 mwifiex_set_sys_config_invalid_data(bss_cfg);
748 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
749 bss_cfg->rts_threshold = wiphy->rts_threshold;
750 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
751 bss_cfg->frag_threshold = wiphy->frag_threshold;
752 if (changed & WIPHY_PARAM_RETRY_LONG)
753 bss_cfg->retry_limit = wiphy->retry_long;
755 ret = mwifiex_send_cmd(priv, HostCmd_CMD_UAP_SYS_CONFIG,
757 UAP_BSS_PARAMS_I, bss_cfg,
762 mwifiex_dbg(adapter, ERROR,
763 "Failed to set wiphy phy params\n");
768 case MWIFIEX_BSS_ROLE_STA:
769 if (priv->media_connected) {
770 mwifiex_dbg(adapter, ERROR,
771 "cannot change wiphy params when connected");
774 if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
775 ret = mwifiex_set_rts(priv,
776 wiphy->rts_threshold);
780 if (changed & WIPHY_PARAM_FRAG_THRESHOLD) {
781 ret = mwifiex_set_frag(priv,
782 wiphy->frag_threshold);
793 mwifiex_cfg80211_deinit_p2p(struct mwifiex_private *priv)
795 u16 mode = P2P_MODE_DISABLE;
797 if (mwifiex_send_cmd(priv, HostCmd_CMD_P2P_MODE_CFG,
798 HostCmd_ACT_GEN_SET, 0, &mode, true))
805 * This function initializes the functionalities for P2P client.
806 * The P2P client initialization sequence is:
807 * disable -> device -> client
810 mwifiex_cfg80211_init_p2p_client(struct mwifiex_private *priv)
814 if (mwifiex_cfg80211_deinit_p2p(priv))
817 mode = P2P_MODE_DEVICE;
818 if (mwifiex_send_cmd(priv, HostCmd_CMD_P2P_MODE_CFG,
819 HostCmd_ACT_GEN_SET, 0, &mode, true))
822 mode = P2P_MODE_CLIENT;
823 if (mwifiex_send_cmd(priv, HostCmd_CMD_P2P_MODE_CFG,
824 HostCmd_ACT_GEN_SET, 0, &mode, true))
831 * This function initializes the functionalities for P2P GO.
832 * The P2P GO initialization sequence is:
833 * disable -> device -> GO
836 mwifiex_cfg80211_init_p2p_go(struct mwifiex_private *priv)
840 if (mwifiex_cfg80211_deinit_p2p(priv))
843 mode = P2P_MODE_DEVICE;
844 if (mwifiex_send_cmd(priv, HostCmd_CMD_P2P_MODE_CFG,
845 HostCmd_ACT_GEN_SET, 0, &mode, true))
849 if (mwifiex_send_cmd(priv, HostCmd_CMD_P2P_MODE_CFG,
850 HostCmd_ACT_GEN_SET, 0, &mode, true))
856 static int mwifiex_deinit_priv_params(struct mwifiex_private *priv)
858 struct mwifiex_adapter *adapter = priv->adapter;
861 priv->mgmt_frame_mask = 0;
862 if (mwifiex_send_cmd(priv, HostCmd_CMD_MGMT_FRAME_REG,
863 HostCmd_ACT_GEN_SET, 0,
864 &priv->mgmt_frame_mask, false)) {
865 mwifiex_dbg(adapter, ERROR,
866 "could not unregister mgmt frame rx\n");
870 mwifiex_deauthenticate(priv, NULL);
872 spin_lock_irqsave(&adapter->main_proc_lock, flags);
873 adapter->main_locked = true;
874 if (adapter->mwifiex_processing) {
875 spin_unlock_irqrestore(&adapter->main_proc_lock, flags);
876 flush_workqueue(adapter->workqueue);
878 spin_unlock_irqrestore(&adapter->main_proc_lock, flags);
881 spin_lock_bh(&adapter->rx_proc_lock);
882 adapter->rx_locked = true;
883 if (adapter->rx_processing) {
884 spin_unlock_bh(&adapter->rx_proc_lock);
885 flush_workqueue(adapter->rx_workqueue);
887 spin_unlock_bh(&adapter->rx_proc_lock);
890 mwifiex_free_priv(priv);
891 priv->wdev.iftype = NL80211_IFTYPE_UNSPECIFIED;
892 priv->bss_mode = NL80211_IFTYPE_UNSPECIFIED;
893 priv->sec_info.authentication_mode = NL80211_AUTHTYPE_OPEN_SYSTEM;
899 mwifiex_init_new_priv_params(struct mwifiex_private *priv,
900 struct net_device *dev,
901 enum nl80211_iftype type)
903 struct mwifiex_adapter *adapter = priv->adapter;
906 mwifiex_init_priv(priv);
908 priv->bss_mode = type;
909 priv->wdev.iftype = type;
911 mwifiex_init_priv_params(priv, priv->netdev);
912 priv->bss_started = 0;
915 case NL80211_IFTYPE_STATION:
916 case NL80211_IFTYPE_ADHOC:
917 priv->bss_role = MWIFIEX_BSS_ROLE_STA;
918 priv->bss_type = MWIFIEX_BSS_TYPE_STA;
920 case NL80211_IFTYPE_P2P_CLIENT:
921 priv->bss_role = MWIFIEX_BSS_ROLE_STA;
922 priv->bss_type = MWIFIEX_BSS_TYPE_P2P;
924 case NL80211_IFTYPE_P2P_GO:
925 priv->bss_role = MWIFIEX_BSS_ROLE_UAP;
926 priv->bss_type = MWIFIEX_BSS_TYPE_P2P;
928 case NL80211_IFTYPE_AP:
929 priv->bss_role = MWIFIEX_BSS_ROLE_UAP;
930 priv->bss_type = MWIFIEX_BSS_TYPE_UAP;
933 mwifiex_dbg(adapter, ERROR,
934 "%s: changing to %d not supported\n",
939 spin_lock_irqsave(&adapter->main_proc_lock, flags);
940 adapter->main_locked = false;
941 spin_unlock_irqrestore(&adapter->main_proc_lock, flags);
943 spin_lock_bh(&adapter->rx_proc_lock);
944 adapter->rx_locked = false;
945 spin_unlock_bh(&adapter->rx_proc_lock);
947 mwifiex_set_mac_address(priv, dev, false, NULL);
953 is_vif_type_change_allowed(struct mwifiex_adapter *adapter,
954 enum nl80211_iftype old_iftype,
955 enum nl80211_iftype new_iftype)
957 switch (old_iftype) {
958 case NL80211_IFTYPE_ADHOC:
959 switch (new_iftype) {
960 case NL80211_IFTYPE_STATION:
962 case NL80211_IFTYPE_P2P_CLIENT:
963 case NL80211_IFTYPE_P2P_GO:
964 return adapter->curr_iface_comb.p2p_intf !=
965 adapter->iface_limit.p2p_intf;
966 case NL80211_IFTYPE_AP:
967 return adapter->curr_iface_comb.uap_intf !=
968 adapter->iface_limit.uap_intf;
973 case NL80211_IFTYPE_STATION:
974 switch (new_iftype) {
975 case NL80211_IFTYPE_ADHOC:
977 case NL80211_IFTYPE_P2P_CLIENT:
978 case NL80211_IFTYPE_P2P_GO:
979 return adapter->curr_iface_comb.p2p_intf !=
980 adapter->iface_limit.p2p_intf;
981 case NL80211_IFTYPE_AP:
982 return adapter->curr_iface_comb.uap_intf !=
983 adapter->iface_limit.uap_intf;
988 case NL80211_IFTYPE_AP:
989 switch (new_iftype) {
990 case NL80211_IFTYPE_ADHOC:
991 case NL80211_IFTYPE_STATION:
992 return adapter->curr_iface_comb.sta_intf !=
993 adapter->iface_limit.sta_intf;
994 case NL80211_IFTYPE_P2P_CLIENT:
995 case NL80211_IFTYPE_P2P_GO:
996 return adapter->curr_iface_comb.p2p_intf !=
997 adapter->iface_limit.p2p_intf;
1002 case NL80211_IFTYPE_P2P_CLIENT:
1003 switch (new_iftype) {
1004 case NL80211_IFTYPE_ADHOC:
1005 case NL80211_IFTYPE_STATION:
1007 case NL80211_IFTYPE_P2P_GO:
1009 case NL80211_IFTYPE_AP:
1010 return adapter->curr_iface_comb.uap_intf !=
1011 adapter->iface_limit.uap_intf;
1016 case NL80211_IFTYPE_P2P_GO:
1017 switch (new_iftype) {
1018 case NL80211_IFTYPE_ADHOC:
1019 case NL80211_IFTYPE_STATION:
1021 case NL80211_IFTYPE_P2P_CLIENT:
1023 case NL80211_IFTYPE_AP:
1024 return adapter->curr_iface_comb.uap_intf !=
1025 adapter->iface_limit.uap_intf;
1038 update_vif_type_counter(struct mwifiex_adapter *adapter,
1039 enum nl80211_iftype iftype,
1043 case NL80211_IFTYPE_UNSPECIFIED:
1044 case NL80211_IFTYPE_ADHOC:
1045 case NL80211_IFTYPE_STATION:
1046 adapter->curr_iface_comb.sta_intf += change;
1048 case NL80211_IFTYPE_AP:
1049 adapter->curr_iface_comb.uap_intf += change;
1051 case NL80211_IFTYPE_P2P_CLIENT:
1052 case NL80211_IFTYPE_P2P_GO:
1053 adapter->curr_iface_comb.p2p_intf += change;
1056 mwifiex_dbg(adapter, ERROR,
1057 "%s: Unsupported iftype passed: %d\n",
1064 mwifiex_change_vif_to_p2p(struct net_device *dev,
1065 enum nl80211_iftype curr_iftype,
1066 enum nl80211_iftype type,
1067 struct vif_params *params)
1069 struct mwifiex_private *priv;
1070 struct mwifiex_adapter *adapter;
1072 priv = mwifiex_netdev_get_priv(dev);
1077 adapter = priv->adapter;
1079 mwifiex_dbg(adapter, INFO,
1080 "%s: changing role to p2p\n", dev->name);
1082 if (mwifiex_deinit_priv_params(priv))
1084 if (mwifiex_init_new_priv_params(priv, dev, type))
1087 update_vif_type_counter(adapter, curr_iftype, -1);
1088 update_vif_type_counter(adapter, type, +1);
1089 dev->ieee80211_ptr->iftype = type;
1092 case NL80211_IFTYPE_P2P_CLIENT:
1093 if (mwifiex_cfg80211_init_p2p_client(priv))
1096 case NL80211_IFTYPE_P2P_GO:
1097 if (mwifiex_cfg80211_init_p2p_go(priv))
1101 mwifiex_dbg(adapter, ERROR,
1102 "%s: changing to %d not supported\n",
1107 if (mwifiex_send_cmd(priv, HostCmd_CMD_SET_BSS_MODE,
1108 HostCmd_ACT_GEN_SET, 0, NULL, true))
1111 if (mwifiex_sta_init_cmd(priv, false, false))
1118 mwifiex_change_vif_to_sta_adhoc(struct net_device *dev,
1119 enum nl80211_iftype curr_iftype,
1120 enum nl80211_iftype type,
1121 struct vif_params *params)
1123 struct mwifiex_private *priv;
1124 struct mwifiex_adapter *adapter;
1126 priv = mwifiex_netdev_get_priv(dev);
1131 adapter = priv->adapter;
1133 if (type == NL80211_IFTYPE_STATION)
1134 mwifiex_dbg(adapter, INFO,
1135 "%s: changing role to station\n", dev->name);
1137 mwifiex_dbg(adapter, INFO,
1138 "%s: changing role to adhoc\n", dev->name);
1140 if (mwifiex_deinit_priv_params(priv))
1142 if (mwifiex_init_new_priv_params(priv, dev, type))
1145 update_vif_type_counter(adapter, curr_iftype, -1);
1146 update_vif_type_counter(adapter, type, +1);
1147 dev->ieee80211_ptr->iftype = type;
1149 if (mwifiex_send_cmd(priv, HostCmd_CMD_SET_BSS_MODE,
1150 HostCmd_ACT_GEN_SET, 0, NULL, true))
1152 if (mwifiex_sta_init_cmd(priv, false, false))
1159 mwifiex_change_vif_to_ap(struct net_device *dev,
1160 enum nl80211_iftype curr_iftype,
1161 enum nl80211_iftype type,
1162 struct vif_params *params)
1164 struct mwifiex_private *priv;
1165 struct mwifiex_adapter *adapter;
1167 priv = mwifiex_netdev_get_priv(dev);
1172 adapter = priv->adapter;
1174 mwifiex_dbg(adapter, INFO,
1175 "%s: changing role to AP\n", dev->name);
1177 if (mwifiex_deinit_priv_params(priv))
1179 if (mwifiex_init_new_priv_params(priv, dev, type))
1182 update_vif_type_counter(adapter, curr_iftype, -1);
1183 update_vif_type_counter(adapter, type, +1);
1184 dev->ieee80211_ptr->iftype = type;
1186 if (mwifiex_send_cmd(priv, HostCmd_CMD_SET_BSS_MODE,
1187 HostCmd_ACT_GEN_SET, 0, NULL, true))
1189 if (mwifiex_sta_init_cmd(priv, false, false))
1195 * CFG802.11 operation handler to change interface type.
1198 mwifiex_cfg80211_change_virtual_intf(struct wiphy *wiphy,
1199 struct net_device *dev,
1200 enum nl80211_iftype type,
1201 struct vif_params *params)
1203 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
1204 enum nl80211_iftype curr_iftype = dev->ieee80211_ptr->iftype;
1206 if (priv->scan_request) {
1207 mwifiex_dbg(priv->adapter, ERROR,
1208 "change virtual interface: scan in process\n");
1212 if (type == NL80211_IFTYPE_UNSPECIFIED) {
1213 mwifiex_dbg(priv->adapter, INFO,
1214 "%s: no new type specified, keeping old type %d\n",
1215 dev->name, curr_iftype);
1219 if (curr_iftype == type) {
1220 mwifiex_dbg(priv->adapter, INFO,
1221 "%s: interface already is of type %d\n",
1222 dev->name, curr_iftype);
1226 if (!is_vif_type_change_allowed(priv->adapter, curr_iftype, type)) {
1227 mwifiex_dbg(priv->adapter, ERROR,
1228 "%s: change from type %d to %d is not allowed\n",
1229 dev->name, curr_iftype, type);
1233 switch (curr_iftype) {
1234 case NL80211_IFTYPE_ADHOC:
1236 case NL80211_IFTYPE_STATION:
1237 priv->bss_mode = type;
1238 priv->sec_info.authentication_mode =
1239 NL80211_AUTHTYPE_OPEN_SYSTEM;
1240 dev->ieee80211_ptr->iftype = type;
1241 mwifiex_deauthenticate(priv, NULL);
1242 return mwifiex_send_cmd(priv, HostCmd_CMD_SET_BSS_MODE,
1243 HostCmd_ACT_GEN_SET, 0, NULL,
1245 case NL80211_IFTYPE_P2P_CLIENT:
1246 case NL80211_IFTYPE_P2P_GO:
1247 return mwifiex_change_vif_to_p2p(dev, curr_iftype,
1249 case NL80211_IFTYPE_AP:
1250 return mwifiex_change_vif_to_ap(dev, curr_iftype, type,
1256 case NL80211_IFTYPE_STATION:
1258 case NL80211_IFTYPE_ADHOC:
1259 priv->bss_mode = type;
1260 priv->sec_info.authentication_mode =
1261 NL80211_AUTHTYPE_OPEN_SYSTEM;
1262 dev->ieee80211_ptr->iftype = type;
1263 mwifiex_deauthenticate(priv, NULL);
1264 return mwifiex_send_cmd(priv, HostCmd_CMD_SET_BSS_MODE,
1265 HostCmd_ACT_GEN_SET, 0, NULL,
1267 case NL80211_IFTYPE_P2P_CLIENT:
1268 case NL80211_IFTYPE_P2P_GO:
1269 return mwifiex_change_vif_to_p2p(dev, curr_iftype,
1271 case NL80211_IFTYPE_AP:
1272 return mwifiex_change_vif_to_ap(dev, curr_iftype, type,
1278 case NL80211_IFTYPE_AP:
1280 case NL80211_IFTYPE_ADHOC:
1281 case NL80211_IFTYPE_STATION:
1282 return mwifiex_change_vif_to_sta_adhoc(dev, curr_iftype,
1285 case NL80211_IFTYPE_P2P_CLIENT:
1286 case NL80211_IFTYPE_P2P_GO:
1287 return mwifiex_change_vif_to_p2p(dev, curr_iftype,
1293 case NL80211_IFTYPE_P2P_CLIENT:
1294 if (mwifiex_cfg80211_deinit_p2p(priv))
1298 case NL80211_IFTYPE_ADHOC:
1299 case NL80211_IFTYPE_STATION:
1300 return mwifiex_change_vif_to_sta_adhoc(dev, curr_iftype,
1302 case NL80211_IFTYPE_P2P_GO:
1303 return mwifiex_change_vif_to_p2p(dev, curr_iftype,
1305 case NL80211_IFTYPE_AP:
1306 return mwifiex_change_vif_to_ap(dev, curr_iftype, type,
1312 case NL80211_IFTYPE_P2P_GO:
1313 if (mwifiex_cfg80211_deinit_p2p(priv))
1317 case NL80211_IFTYPE_ADHOC:
1318 case NL80211_IFTYPE_STATION:
1319 return mwifiex_change_vif_to_sta_adhoc(dev, curr_iftype,
1321 case NL80211_IFTYPE_P2P_CLIENT:
1322 return mwifiex_change_vif_to_p2p(dev, curr_iftype,
1324 case NL80211_IFTYPE_AP:
1325 return mwifiex_change_vif_to_ap(dev, curr_iftype, type,
1339 mwifiex_dbg(priv->adapter, ERROR,
1340 "unsupported interface type transition: %d to %d\n",
1346 mwifiex_parse_htinfo(struct mwifiex_private *priv, u8 rateinfo, u8 htinfo,
1347 struct rate_info *rate)
1349 struct mwifiex_adapter *adapter = priv->adapter;
1351 if (adapter->is_hw_11ac_capable) {
1352 /* bit[1-0]: 00=LG 01=HT 10=VHT */
1353 if (htinfo & BIT(0)) {
1355 rate->mcs = rateinfo;
1356 rate->flags |= RATE_INFO_FLAGS_MCS;
1358 if (htinfo & BIT(1)) {
1360 rate->mcs = rateinfo & 0x0F;
1361 rate->flags |= RATE_INFO_FLAGS_VHT_MCS;
1364 if (htinfo & (BIT(1) | BIT(0))) {
1366 switch (htinfo & (BIT(3) | BIT(2))) {
1368 rate->bw = RATE_INFO_BW_20;
1371 rate->bw = RATE_INFO_BW_40;
1374 rate->bw = RATE_INFO_BW_80;
1376 case (BIT(3) | BIT(2)):
1377 rate->bw = RATE_INFO_BW_160;
1381 if (htinfo & BIT(4))
1382 rate->flags |= RATE_INFO_FLAGS_SHORT_GI;
1384 if ((rateinfo >> 4) == 1)
1391 * Bit 0 in htinfo indicates that current rate is 11n. Valid
1392 * MCS index values for us are 0 to 15.
1394 if ((htinfo & BIT(0)) && (rateinfo < 16)) {
1395 rate->mcs = rateinfo;
1396 rate->flags |= RATE_INFO_FLAGS_MCS;
1397 rate->bw = RATE_INFO_BW_20;
1398 if (htinfo & BIT(1))
1399 rate->bw = RATE_INFO_BW_40;
1400 if (htinfo & BIT(2))
1401 rate->flags |= RATE_INFO_FLAGS_SHORT_GI;
1405 /* Decode legacy rates for non-HT. */
1406 if (!(htinfo & (BIT(0) | BIT(1)))) {
1407 /* Bitrates in multiples of 100kb/s. */
1408 static const int legacy_rates[] = {
1413 [4] = 60, /* MWIFIEX_RATE_INDEX_OFDM0 */
1423 if (rateinfo < ARRAY_SIZE(legacy_rates))
1424 rate->legacy = legacy_rates[rateinfo];
1429 * This function dumps the station information on a buffer.
1431 * The following information are shown -
1432 * - Total bytes transmitted
1433 * - Total bytes received
1434 * - Total packets transmitted
1435 * - Total packets received
1436 * - Signal quality level
1437 * - Transmission rate
1440 mwifiex_dump_station_info(struct mwifiex_private *priv,
1441 struct mwifiex_sta_node *node,
1442 struct station_info *sinfo)
1446 sinfo->filled = BIT_ULL(NL80211_STA_INFO_RX_BYTES) | BIT_ULL(NL80211_STA_INFO_TX_BYTES) |
1447 BIT_ULL(NL80211_STA_INFO_RX_PACKETS) | BIT_ULL(NL80211_STA_INFO_TX_PACKETS) |
1448 BIT_ULL(NL80211_STA_INFO_TX_BITRATE) |
1449 BIT_ULL(NL80211_STA_INFO_SIGNAL) | BIT_ULL(NL80211_STA_INFO_SIGNAL_AVG);
1451 if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_UAP) {
1455 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_INACTIVE_TIME) |
1456 BIT_ULL(NL80211_STA_INFO_TX_FAILED);
1457 sinfo->inactive_time =
1458 jiffies_to_msecs(jiffies - node->stats.last_rx);
1460 sinfo->signal = node->stats.rssi;
1461 sinfo->signal_avg = node->stats.rssi;
1462 sinfo->rx_bytes = node->stats.rx_bytes;
1463 sinfo->tx_bytes = node->stats.tx_bytes;
1464 sinfo->rx_packets = node->stats.rx_packets;
1465 sinfo->tx_packets = node->stats.tx_packets;
1466 sinfo->tx_failed = node->stats.tx_failed;
1468 mwifiex_parse_htinfo(priv, priv->tx_rate,
1469 node->stats.last_tx_htinfo,
1471 sinfo->txrate.legacy = node->stats.last_tx_rate * 5;
1476 /* Get signal information from the firmware */
1477 if (mwifiex_send_cmd(priv, HostCmd_CMD_RSSI_INFO,
1478 HostCmd_ACT_GEN_GET, 0, NULL, true)) {
1479 mwifiex_dbg(priv->adapter, ERROR,
1480 "failed to get signal information\n");
1484 if (mwifiex_drv_get_data_rate(priv, &rate)) {
1485 mwifiex_dbg(priv->adapter, ERROR,
1486 "getting data rate error\n");
1490 /* Get DTIM period information from firmware */
1491 mwifiex_send_cmd(priv, HostCmd_CMD_802_11_SNMP_MIB,
1492 HostCmd_ACT_GEN_GET, DTIM_PERIOD_I,
1493 &priv->dtim_period, true);
1495 mwifiex_parse_htinfo(priv, priv->tx_rate, priv->tx_htinfo,
1498 sinfo->signal_avg = priv->bcn_rssi_avg;
1499 sinfo->rx_bytes = priv->stats.rx_bytes;
1500 sinfo->tx_bytes = priv->stats.tx_bytes;
1501 sinfo->rx_packets = priv->stats.rx_packets;
1502 sinfo->tx_packets = priv->stats.tx_packets;
1503 sinfo->signal = priv->bcn_rssi_avg;
1504 /* bit rate is in 500 kb/s units. Convert it to 100kb/s units */
1505 sinfo->txrate.legacy = rate * 5;
1507 sinfo->filled |= BIT(NL80211_STA_INFO_RX_BITRATE);
1508 mwifiex_parse_htinfo(priv, priv->rxpd_rate, priv->rxpd_htinfo,
1511 if (priv->bss_mode == NL80211_IFTYPE_STATION) {
1512 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_BSS_PARAM);
1513 sinfo->bss_param.flags = 0;
1514 if (priv->curr_bss_params.bss_descriptor.cap_info_bitmap &
1515 WLAN_CAPABILITY_SHORT_PREAMBLE)
1516 sinfo->bss_param.flags |=
1517 BSS_PARAM_FLAGS_SHORT_PREAMBLE;
1518 if (priv->curr_bss_params.bss_descriptor.cap_info_bitmap &
1519 WLAN_CAPABILITY_SHORT_SLOT_TIME)
1520 sinfo->bss_param.flags |=
1521 BSS_PARAM_FLAGS_SHORT_SLOT_TIME;
1522 sinfo->bss_param.dtim_period = priv->dtim_period;
1523 sinfo->bss_param.beacon_interval =
1524 priv->curr_bss_params.bss_descriptor.beacon_period;
1531 * CFG802.11 operation handler to get station information.
1533 * This function only works in connected mode, and dumps the
1534 * requested station information, if available.
1537 mwifiex_cfg80211_get_station(struct wiphy *wiphy, struct net_device *dev,
1538 const u8 *mac, struct station_info *sinfo)
1540 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
1542 if (!priv->media_connected)
1544 if (memcmp(mac, priv->cfg_bssid, ETH_ALEN))
1547 return mwifiex_dump_station_info(priv, NULL, sinfo);
1551 * CFG802.11 operation handler to dump station information.
1554 mwifiex_cfg80211_dump_station(struct wiphy *wiphy, struct net_device *dev,
1555 int idx, u8 *mac, struct station_info *sinfo)
1557 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
1558 struct mwifiex_sta_node *node;
1561 if ((GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA) &&
1562 priv->media_connected && idx == 0) {
1563 ether_addr_copy(mac, priv->cfg_bssid);
1564 return mwifiex_dump_station_info(priv, NULL, sinfo);
1565 } else if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_UAP) {
1566 mwifiex_send_cmd(priv, HOST_CMD_APCMD_STA_LIST,
1567 HostCmd_ACT_GEN_GET, 0, NULL, true);
1570 list_for_each_entry(node, &priv->sta_list, list) {
1573 ether_addr_copy(mac, node->mac_addr);
1574 return mwifiex_dump_station_info(priv, node, sinfo);
1582 mwifiex_cfg80211_dump_survey(struct wiphy *wiphy, struct net_device *dev,
1583 int idx, struct survey_info *survey)
1585 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
1586 struct mwifiex_chan_stats *pchan_stats = priv->adapter->chan_stats;
1587 enum nl80211_band band;
1589 mwifiex_dbg(priv->adapter, DUMP, "dump_survey idx=%d\n", idx);
1591 memset(survey, 0, sizeof(struct survey_info));
1593 if ((GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA) &&
1594 priv->media_connected && idx == 0) {
1595 u8 curr_bss_band = priv->curr_bss_params.band;
1596 u32 chan = priv->curr_bss_params.bss_descriptor.channel;
1598 band = mwifiex_band_to_radio_type(curr_bss_band);
1599 survey->channel = ieee80211_get_channel(wiphy,
1600 ieee80211_channel_to_frequency(chan, band));
1602 if (priv->bcn_nf_last) {
1603 survey->filled = SURVEY_INFO_NOISE_DBM;
1604 survey->noise = priv->bcn_nf_last;
1609 if (idx >= priv->adapter->num_in_chan_stats)
1612 if (!pchan_stats[idx].cca_scan_dur)
1615 band = pchan_stats[idx].bandcfg;
1616 survey->channel = ieee80211_get_channel(wiphy,
1617 ieee80211_channel_to_frequency(pchan_stats[idx].chan_num, band));
1618 survey->filled = SURVEY_INFO_NOISE_DBM |
1620 SURVEY_INFO_TIME_BUSY;
1621 survey->noise = pchan_stats[idx].noise;
1622 survey->time = pchan_stats[idx].cca_scan_dur;
1623 survey->time_busy = pchan_stats[idx].cca_busy_dur;
1628 /* Supported rates to be advertised to the cfg80211 */
1629 static struct ieee80211_rate mwifiex_rates[] = {
1630 {.bitrate = 10, .hw_value = 2, },
1631 {.bitrate = 20, .hw_value = 4, },
1632 {.bitrate = 55, .hw_value = 11, },
1633 {.bitrate = 110, .hw_value = 22, },
1634 {.bitrate = 60, .hw_value = 12, },
1635 {.bitrate = 90, .hw_value = 18, },
1636 {.bitrate = 120, .hw_value = 24, },
1637 {.bitrate = 180, .hw_value = 36, },
1638 {.bitrate = 240, .hw_value = 48, },
1639 {.bitrate = 360, .hw_value = 72, },
1640 {.bitrate = 480, .hw_value = 96, },
1641 {.bitrate = 540, .hw_value = 108, },
1644 /* Channel definitions to be advertised to cfg80211 */
1645 static struct ieee80211_channel mwifiex_channels_2ghz[] = {
1646 {.center_freq = 2412, .hw_value = 1, },
1647 {.center_freq = 2417, .hw_value = 2, },
1648 {.center_freq = 2422, .hw_value = 3, },
1649 {.center_freq = 2427, .hw_value = 4, },
1650 {.center_freq = 2432, .hw_value = 5, },
1651 {.center_freq = 2437, .hw_value = 6, },
1652 {.center_freq = 2442, .hw_value = 7, },
1653 {.center_freq = 2447, .hw_value = 8, },
1654 {.center_freq = 2452, .hw_value = 9, },
1655 {.center_freq = 2457, .hw_value = 10, },
1656 {.center_freq = 2462, .hw_value = 11, },
1657 {.center_freq = 2467, .hw_value = 12, },
1658 {.center_freq = 2472, .hw_value = 13, },
1659 {.center_freq = 2484, .hw_value = 14, },
1662 static struct ieee80211_supported_band mwifiex_band_2ghz = {
1663 .channels = mwifiex_channels_2ghz,
1664 .n_channels = ARRAY_SIZE(mwifiex_channels_2ghz),
1665 .bitrates = mwifiex_rates,
1666 .n_bitrates = ARRAY_SIZE(mwifiex_rates),
1669 static struct ieee80211_channel mwifiex_channels_5ghz[] = {
1670 {.center_freq = 5040, .hw_value = 8, },
1671 {.center_freq = 5060, .hw_value = 12, },
1672 {.center_freq = 5080, .hw_value = 16, },
1673 {.center_freq = 5170, .hw_value = 34, },
1674 {.center_freq = 5190, .hw_value = 38, },
1675 {.center_freq = 5210, .hw_value = 42, },
1676 {.center_freq = 5230, .hw_value = 46, },
1677 {.center_freq = 5180, .hw_value = 36, },
1678 {.center_freq = 5200, .hw_value = 40, },
1679 {.center_freq = 5220, .hw_value = 44, },
1680 {.center_freq = 5240, .hw_value = 48, },
1681 {.center_freq = 5260, .hw_value = 52, },
1682 {.center_freq = 5280, .hw_value = 56, },
1683 {.center_freq = 5300, .hw_value = 60, },
1684 {.center_freq = 5320, .hw_value = 64, },
1685 {.center_freq = 5500, .hw_value = 100, },
1686 {.center_freq = 5520, .hw_value = 104, },
1687 {.center_freq = 5540, .hw_value = 108, },
1688 {.center_freq = 5560, .hw_value = 112, },
1689 {.center_freq = 5580, .hw_value = 116, },
1690 {.center_freq = 5600, .hw_value = 120, },
1691 {.center_freq = 5620, .hw_value = 124, },
1692 {.center_freq = 5640, .hw_value = 128, },
1693 {.center_freq = 5660, .hw_value = 132, },
1694 {.center_freq = 5680, .hw_value = 136, },
1695 {.center_freq = 5700, .hw_value = 140, },
1696 {.center_freq = 5745, .hw_value = 149, },
1697 {.center_freq = 5765, .hw_value = 153, },
1698 {.center_freq = 5785, .hw_value = 157, },
1699 {.center_freq = 5805, .hw_value = 161, },
1700 {.center_freq = 5825, .hw_value = 165, },
1703 static struct ieee80211_supported_band mwifiex_band_5ghz = {
1704 .channels = mwifiex_channels_5ghz,
1705 .n_channels = ARRAY_SIZE(mwifiex_channels_5ghz),
1706 .bitrates = mwifiex_rates + 4,
1707 .n_bitrates = ARRAY_SIZE(mwifiex_rates) - 4,
1711 /* Supported crypto cipher suits to be advertised to cfg80211 */
1712 static const u32 mwifiex_cipher_suites[] = {
1713 WLAN_CIPHER_SUITE_WEP40,
1714 WLAN_CIPHER_SUITE_WEP104,
1715 WLAN_CIPHER_SUITE_TKIP,
1716 WLAN_CIPHER_SUITE_CCMP,
1717 WLAN_CIPHER_SUITE_SMS4,
1718 WLAN_CIPHER_SUITE_AES_CMAC,
1721 /* Supported mgmt frame types to be advertised to cfg80211 */
1722 static const struct ieee80211_txrx_stypes
1723 mwifiex_mgmt_stypes[NUM_NL80211_IFTYPES] = {
1724 [NL80211_IFTYPE_STATION] = {
1725 .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
1726 BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
1727 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
1728 BIT(IEEE80211_STYPE_PROBE_REQ >> 4),
1730 [NL80211_IFTYPE_AP] = {
1731 .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
1732 BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
1733 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
1734 BIT(IEEE80211_STYPE_PROBE_REQ >> 4),
1736 [NL80211_IFTYPE_P2P_CLIENT] = {
1737 .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
1738 BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
1739 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
1740 BIT(IEEE80211_STYPE_PROBE_REQ >> 4),
1742 [NL80211_IFTYPE_P2P_GO] = {
1743 .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
1744 BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
1745 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
1746 BIT(IEEE80211_STYPE_PROBE_REQ >> 4),
1751 * CFG802.11 operation handler for setting bit rates.
1753 * Function configures data rates to firmware using bitrate mask
1754 * provided by cfg80211.
1756 static int mwifiex_cfg80211_set_bitrate_mask(struct wiphy *wiphy,
1757 struct net_device *dev,
1759 const struct cfg80211_bitrate_mask *mask)
1761 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
1762 u16 bitmap_rates[MAX_BITMAP_RATES_SIZE];
1763 enum nl80211_band band;
1764 struct mwifiex_adapter *adapter = priv->adapter;
1766 if (!priv->media_connected) {
1767 mwifiex_dbg(adapter, ERROR,
1768 "Can not set Tx data rate in disconnected state\n");
1772 band = mwifiex_band_to_radio_type(priv->curr_bss_params.band);
1774 memset(bitmap_rates, 0, sizeof(bitmap_rates));
1776 /* Fill HR/DSSS rates. */
1777 if (band == NL80211_BAND_2GHZ)
1778 bitmap_rates[0] = mask->control[band].legacy & 0x000f;
1780 /* Fill OFDM rates */
1781 if (band == NL80211_BAND_2GHZ)
1782 bitmap_rates[1] = (mask->control[band].legacy & 0x0ff0) >> 4;
1784 bitmap_rates[1] = mask->control[band].legacy;
1786 /* Fill HT MCS rates */
1787 bitmap_rates[2] = mask->control[band].ht_mcs[0];
1788 if (adapter->hw_dev_mcs_support == HT_STREAM_2X2)
1789 bitmap_rates[2] |= mask->control[band].ht_mcs[1] << 8;
1791 /* Fill VHT MCS rates */
1792 if (adapter->fw_api_ver == MWIFIEX_FW_V15) {
1793 bitmap_rates[10] = mask->control[band].vht_mcs[0];
1794 if (adapter->hw_dev_mcs_support == HT_STREAM_2X2)
1795 bitmap_rates[11] = mask->control[band].vht_mcs[1];
1798 return mwifiex_send_cmd(priv, HostCmd_CMD_TX_RATE_CFG,
1799 HostCmd_ACT_GEN_SET, 0, bitmap_rates, true);
1803 * CFG802.11 operation handler for connection quality monitoring.
1805 * This function subscribes/unsubscribes HIGH_RSSI and LOW_RSSI
1808 static int mwifiex_cfg80211_set_cqm_rssi_config(struct wiphy *wiphy,
1809 struct net_device *dev,
1810 s32 rssi_thold, u32 rssi_hyst)
1812 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
1813 struct mwifiex_ds_misc_subsc_evt subsc_evt;
1815 priv->cqm_rssi_thold = rssi_thold;
1816 priv->cqm_rssi_hyst = rssi_hyst;
1818 memset(&subsc_evt, 0x00, sizeof(struct mwifiex_ds_misc_subsc_evt));
1819 subsc_evt.events = BITMASK_BCN_RSSI_LOW | BITMASK_BCN_RSSI_HIGH;
1821 /* Subscribe/unsubscribe low and high rssi events */
1822 if (rssi_thold && rssi_hyst) {
1823 subsc_evt.action = HostCmd_ACT_BITWISE_SET;
1824 subsc_evt.bcn_l_rssi_cfg.abs_value = abs(rssi_thold);
1825 subsc_evt.bcn_h_rssi_cfg.abs_value = abs(rssi_thold);
1826 subsc_evt.bcn_l_rssi_cfg.evt_freq = 1;
1827 subsc_evt.bcn_h_rssi_cfg.evt_freq = 1;
1828 return mwifiex_send_cmd(priv,
1829 HostCmd_CMD_802_11_SUBSCRIBE_EVENT,
1830 0, 0, &subsc_evt, true);
1832 subsc_evt.action = HostCmd_ACT_BITWISE_CLR;
1833 return mwifiex_send_cmd(priv,
1834 HostCmd_CMD_802_11_SUBSCRIBE_EVENT,
1835 0, 0, &subsc_evt, true);
1841 /* cfg80211 operation handler for change_beacon.
1842 * Function retrieves and sets modified management IEs to FW.
1844 static int mwifiex_cfg80211_change_beacon(struct wiphy *wiphy,
1845 struct net_device *dev,
1846 struct cfg80211_beacon_data *data)
1848 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
1849 struct mwifiex_adapter *adapter = priv->adapter;
1851 mwifiex_cancel_scan(adapter);
1853 if (GET_BSS_ROLE(priv) != MWIFIEX_BSS_ROLE_UAP) {
1854 mwifiex_dbg(priv->adapter, ERROR,
1855 "%s: bss_type mismatched\n", __func__);
1859 if (!priv->bss_started) {
1860 mwifiex_dbg(priv->adapter, ERROR,
1861 "%s: bss not started\n", __func__);
1865 if (mwifiex_set_mgmt_ies(priv, data)) {
1866 mwifiex_dbg(priv->adapter, ERROR,
1867 "%s: setting mgmt ies failed\n", __func__);
1874 /* cfg80211 operation handler for del_station.
1875 * Function deauthenticates station which value is provided in mac parameter.
1876 * If mac is NULL/broadcast, all stations in associated station list are
1877 * deauthenticated. If bss is not started or there are no stations in
1878 * associated stations list, no action is taken.
1881 mwifiex_cfg80211_del_station(struct wiphy *wiphy, struct net_device *dev,
1882 struct station_del_parameters *params)
1884 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
1885 struct mwifiex_sta_node *sta_node;
1886 u8 deauth_mac[ETH_ALEN];
1888 if (!priv->bss_started && priv->wdev.cac_started) {
1889 mwifiex_dbg(priv->adapter, INFO, "%s: abort CAC!\n", __func__);
1890 mwifiex_abort_cac(priv);
1893 if (list_empty(&priv->sta_list) || !priv->bss_started)
1896 if (!params->mac || is_broadcast_ether_addr(params->mac))
1899 mwifiex_dbg(priv->adapter, INFO, "%s: mac address %pM\n",
1900 __func__, params->mac);
1902 eth_zero_addr(deauth_mac);
1904 spin_lock_bh(&priv->sta_list_spinlock);
1905 sta_node = mwifiex_get_sta_entry(priv, params->mac);
1907 ether_addr_copy(deauth_mac, params->mac);
1908 spin_unlock_bh(&priv->sta_list_spinlock);
1910 if (is_valid_ether_addr(deauth_mac)) {
1911 if (mwifiex_send_cmd(priv, HostCmd_CMD_UAP_STA_DEAUTH,
1912 HostCmd_ACT_GEN_SET, 0,
1921 mwifiex_cfg80211_set_antenna(struct wiphy *wiphy, u32 tx_ant, u32 rx_ant)
1923 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
1924 struct mwifiex_private *priv = mwifiex_get_priv(adapter,
1925 MWIFIEX_BSS_ROLE_ANY);
1926 struct mwifiex_ds_ant_cfg ant_cfg;
1928 if (!tx_ant || !rx_ant)
1931 if (adapter->hw_dev_mcs_support != HT_STREAM_2X2) {
1932 /* Not a MIMO chip. User should provide specific antenna number
1933 * for Tx/Rx path or enable all antennas for diversity
1935 if (tx_ant != rx_ant)
1938 if ((tx_ant & (tx_ant - 1)) &&
1939 (tx_ant != BIT(adapter->number_of_antenna) - 1))
1942 if ((tx_ant == BIT(adapter->number_of_antenna) - 1) &&
1943 (priv->adapter->number_of_antenna > 1)) {
1944 tx_ant = RF_ANTENNA_AUTO;
1945 rx_ant = RF_ANTENNA_AUTO;
1948 struct ieee80211_sta_ht_cap *ht_info;
1950 enum nl80211_band band;
1952 if ((tx_ant == 0x1 && rx_ant == 0x1)) {
1953 adapter->user_dev_mcs_support = HT_STREAM_1X1;
1954 if (adapter->is_hw_11ac_capable)
1955 adapter->usr_dot_11ac_mcs_support =
1956 MWIFIEX_11AC_MCS_MAP_1X1;
1958 adapter->user_dev_mcs_support = HT_STREAM_2X2;
1959 if (adapter->is_hw_11ac_capable)
1960 adapter->usr_dot_11ac_mcs_support =
1961 MWIFIEX_11AC_MCS_MAP_2X2;
1964 for (band = 0; band < NUM_NL80211_BANDS; band++) {
1965 if (!adapter->wiphy->bands[band])
1968 ht_info = &adapter->wiphy->bands[band]->ht_cap;
1970 GET_RXMCSSUPP(adapter->user_dev_mcs_support);
1971 memset(&ht_info->mcs, 0, adapter->number_of_antenna);
1972 memset(&ht_info->mcs, 0xff, rx_mcs_supp);
1976 ant_cfg.tx_ant = tx_ant;
1977 ant_cfg.rx_ant = rx_ant;
1979 return mwifiex_send_cmd(priv, HostCmd_CMD_RF_ANTENNA,
1980 HostCmd_ACT_GEN_SET, 0, &ant_cfg, true);
1984 mwifiex_cfg80211_get_antenna(struct wiphy *wiphy, u32 *tx_ant, u32 *rx_ant)
1986 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
1987 struct mwifiex_private *priv = mwifiex_get_priv(adapter,
1988 MWIFIEX_BSS_ROLE_ANY);
1989 mwifiex_send_cmd(priv, HostCmd_CMD_RF_ANTENNA,
1990 HostCmd_ACT_GEN_GET, 0, NULL, true);
1992 *tx_ant = priv->tx_ant;
1993 *rx_ant = priv->rx_ant;
1998 /* cfg80211 operation handler for stop ap.
1999 * Function stops BSS running at uAP interface.
2001 static int mwifiex_cfg80211_stop_ap(struct wiphy *wiphy, struct net_device *dev)
2003 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
2005 mwifiex_abort_cac(priv);
2007 if (mwifiex_del_mgmt_ies(priv))
2008 mwifiex_dbg(priv->adapter, ERROR,
2009 "Failed to delete mgmt IEs!\n");
2011 priv->ap_11n_enabled = 0;
2012 memset(&priv->bss_cfg, 0, sizeof(priv->bss_cfg));
2014 if (mwifiex_send_cmd(priv, HostCmd_CMD_UAP_BSS_STOP,
2015 HostCmd_ACT_GEN_SET, 0, NULL, true)) {
2016 mwifiex_dbg(priv->adapter, ERROR,
2017 "Failed to stop the BSS\n");
2021 if (mwifiex_send_cmd(priv, HOST_CMD_APCMD_SYS_RESET,
2022 HostCmd_ACT_GEN_SET, 0, NULL, true)) {
2023 mwifiex_dbg(priv->adapter, ERROR,
2024 "Failed to reset BSS\n");
2028 if (netif_carrier_ok(priv->netdev))
2029 netif_carrier_off(priv->netdev);
2030 mwifiex_stop_net_dev_queue(priv->netdev, priv->adapter);
2035 /* cfg80211 operation handler for start_ap.
2036 * Function sets beacon period, DTIM period, SSID and security into
2037 * AP config structure.
2038 * AP is configured with these settings and BSS is started.
2040 static int mwifiex_cfg80211_start_ap(struct wiphy *wiphy,
2041 struct net_device *dev,
2042 struct cfg80211_ap_settings *params)
2044 struct mwifiex_uap_bss_param *bss_cfg;
2045 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
2047 if (GET_BSS_ROLE(priv) != MWIFIEX_BSS_ROLE_UAP)
2050 bss_cfg = kzalloc(sizeof(struct mwifiex_uap_bss_param), GFP_KERNEL);
2054 mwifiex_set_sys_config_invalid_data(bss_cfg);
2056 if (params->beacon_interval)
2057 bss_cfg->beacon_period = params->beacon_interval;
2058 if (params->dtim_period)
2059 bss_cfg->dtim_period = params->dtim_period;
2061 if (params->ssid && params->ssid_len) {
2062 memcpy(bss_cfg->ssid.ssid, params->ssid, params->ssid_len);
2063 bss_cfg->ssid.ssid_len = params->ssid_len;
2065 if (params->inactivity_timeout > 0) {
2066 /* sta_ao_timer/ps_sta_ao_timer is in unit of 100ms */
2067 bss_cfg->sta_ao_timer = 10 * params->inactivity_timeout;
2068 bss_cfg->ps_sta_ao_timer = 10 * params->inactivity_timeout;
2071 switch (params->hidden_ssid) {
2072 case NL80211_HIDDEN_SSID_NOT_IN_USE:
2073 bss_cfg->bcast_ssid_ctl = 1;
2075 case NL80211_HIDDEN_SSID_ZERO_LEN:
2076 bss_cfg->bcast_ssid_ctl = 0;
2078 case NL80211_HIDDEN_SSID_ZERO_CONTENTS:
2079 bss_cfg->bcast_ssid_ctl = 2;
2086 mwifiex_uap_set_channel(priv, bss_cfg, params->chandef);
2087 mwifiex_set_uap_rates(bss_cfg, params);
2089 if (mwifiex_set_secure_params(priv, bss_cfg, params)) {
2090 mwifiex_dbg(priv->adapter, ERROR,
2091 "Failed to parse security parameters!\n");
2095 mwifiex_set_ht_params(priv, bss_cfg, params);
2097 if (priv->adapter->is_hw_11ac_capable) {
2098 mwifiex_set_vht_params(priv, bss_cfg, params);
2099 mwifiex_set_vht_width(priv, params->chandef.width,
2100 priv->ap_11ac_enabled);
2103 if (priv->ap_11ac_enabled)
2104 mwifiex_set_11ac_ba_params(priv);
2106 mwifiex_set_ba_params(priv);
2108 mwifiex_set_wmm_params(priv, bss_cfg, params);
2110 if (mwifiex_is_11h_active(priv))
2111 mwifiex_set_tpc_params(priv, bss_cfg, params);
2113 if (mwifiex_is_11h_active(priv) &&
2114 !cfg80211_chandef_dfs_required(wiphy, ¶ms->chandef,
2116 mwifiex_dbg(priv->adapter, INFO,
2117 "Disable 11h extensions in FW\n");
2118 if (mwifiex_11h_activate(priv, false)) {
2119 mwifiex_dbg(priv->adapter, ERROR,
2120 "Failed to disable 11h extensions!!");
2123 priv->state_11h.is_11h_active = false;
2126 mwifiex_config_uap_11d(priv, ¶ms->beacon);
2128 if (mwifiex_config_start_uap(priv, bss_cfg)) {
2129 mwifiex_dbg(priv->adapter, ERROR,
2130 "Failed to start AP\n");
2134 if (mwifiex_set_mgmt_ies(priv, ¶ms->beacon))
2137 if (!netif_carrier_ok(priv->netdev))
2138 netif_carrier_on(priv->netdev);
2139 mwifiex_wake_up_net_dev_queue(priv->netdev, priv->adapter);
2141 memcpy(&priv->bss_cfg, bss_cfg, sizeof(priv->bss_cfg));
2151 * CFG802.11 operation handler for disconnection request.
2153 * This function does not work when there is already a disconnection
2154 * procedure going on.
2157 mwifiex_cfg80211_disconnect(struct wiphy *wiphy, struct net_device *dev,
2160 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
2162 if (!mwifiex_stop_bg_scan(priv))
2163 cfg80211_sched_scan_stopped_locked(priv->wdev.wiphy, 0);
2165 if (mwifiex_deauthenticate(priv, NULL))
2168 eth_zero_addr(priv->cfg_bssid);
2169 priv->hs2_enabled = false;
2175 * This function informs the CFG802.11 subsystem of a new IBSS.
2177 * The following information are sent to the CFG802.11 subsystem
2178 * to register the new IBSS. If we do not register the new IBSS,
2179 * a kernel panic will result.
2185 static int mwifiex_cfg80211_inform_ibss_bss(struct mwifiex_private *priv)
2187 struct ieee80211_channel *chan;
2188 struct mwifiex_bss_info bss_info;
2189 struct cfg80211_bss *bss;
2191 u8 ie_buf[IEEE80211_MAX_SSID_LEN + sizeof(struct ieee_types_header)];
2192 enum nl80211_band band;
2194 if (mwifiex_get_bss_info(priv, &bss_info))
2197 ie_buf[0] = WLAN_EID_SSID;
2198 ie_buf[1] = bss_info.ssid.ssid_len;
2200 memcpy(&ie_buf[sizeof(struct ieee_types_header)],
2201 &bss_info.ssid.ssid, bss_info.ssid.ssid_len);
2202 ie_len = ie_buf[1] + sizeof(struct ieee_types_header);
2204 band = mwifiex_band_to_radio_type(priv->curr_bss_params.band);
2205 chan = ieee80211_get_channel(priv->wdev.wiphy,
2206 ieee80211_channel_to_frequency(bss_info.bss_chan,
2209 bss = cfg80211_inform_bss(priv->wdev.wiphy, chan,
2210 CFG80211_BSS_FTYPE_UNKNOWN,
2211 bss_info.bssid, 0, WLAN_CAPABILITY_IBSS,
2212 0, ie_buf, ie_len, 0, GFP_KERNEL);
2214 cfg80211_put_bss(priv->wdev.wiphy, bss);
2215 ether_addr_copy(priv->cfg_bssid, bss_info.bssid);
2222 * This function connects with a BSS.
2224 * This function handles both Infra and Ad-Hoc modes. It also performs
2225 * validity checking on the provided parameters, disconnects from the
2226 * current BSS (if any), sets up the association/scan parameters,
2227 * including security settings, and performs specific SSID scan before
2228 * trying to connect.
2230 * For Infra mode, the function returns failure if the specified SSID
2231 * is not found in scan table. However, for Ad-Hoc mode, it can create
2232 * the IBSS if it does not exist. On successful completion in either case,
2233 * the function notifies the CFG802.11 subsystem of the new BSS connection.
2236 mwifiex_cfg80211_assoc(struct mwifiex_private *priv, size_t ssid_len,
2237 const u8 *ssid, const u8 *bssid, int mode,
2238 struct ieee80211_channel *channel,
2239 struct cfg80211_connect_params *sme, bool privacy,
2240 struct cfg80211_bss **sel_bss)
2242 struct cfg80211_ssid req_ssid;
2243 int ret, auth_type = 0;
2244 struct cfg80211_bss *bss = NULL;
2245 u8 is_scanning_required = 0;
2247 memset(&req_ssid, 0, sizeof(struct cfg80211_ssid));
2249 req_ssid.ssid_len = ssid_len;
2250 if (ssid_len > IEEE80211_MAX_SSID_LEN) {
2251 mwifiex_dbg(priv->adapter, ERROR, "invalid SSID - aborting\n");
2255 memcpy(req_ssid.ssid, ssid, ssid_len);
2256 if (!req_ssid.ssid_len || req_ssid.ssid[0] < 0x20) {
2257 mwifiex_dbg(priv->adapter, ERROR, "invalid SSID - aborting\n");
2261 /* As this is new association, clear locally stored
2262 * keys and security related flags */
2263 priv->sec_info.wpa_enabled = false;
2264 priv->sec_info.wpa2_enabled = false;
2265 priv->wep_key_curr_index = 0;
2266 priv->sec_info.encryption_mode = 0;
2267 priv->sec_info.is_authtype_auto = 0;
2268 ret = mwifiex_set_encode(priv, NULL, NULL, 0, 0, NULL, 1);
2270 if (mode == NL80211_IFTYPE_ADHOC) {
2273 /* set ibss coalescing_status */
2274 ret = mwifiex_send_cmd(
2276 HostCmd_CMD_802_11_IBSS_COALESCING_STATUS,
2277 HostCmd_ACT_GEN_SET, 0, &enable, true);
2281 /* "privacy" is set only for ad-hoc mode */
2284 * Keep WLAN_CIPHER_SUITE_WEP104 for now so that
2285 * the firmware can find a matching network from the
2286 * scan. The cfg80211 does not give us the encryption
2287 * mode at this stage so just setting it to WEP here.
2289 priv->sec_info.encryption_mode =
2290 WLAN_CIPHER_SUITE_WEP104;
2291 priv->sec_info.authentication_mode =
2292 NL80211_AUTHTYPE_OPEN_SYSTEM;
2298 /* Now handle infra mode. "sme" is valid for infra mode only */
2299 if (sme->auth_type == NL80211_AUTHTYPE_AUTOMATIC) {
2300 auth_type = NL80211_AUTHTYPE_OPEN_SYSTEM;
2301 priv->sec_info.is_authtype_auto = 1;
2303 auth_type = sme->auth_type;
2306 if (sme->crypto.n_ciphers_pairwise) {
2307 priv->sec_info.encryption_mode =
2308 sme->crypto.ciphers_pairwise[0];
2309 priv->sec_info.authentication_mode = auth_type;
2312 if (sme->crypto.cipher_group) {
2313 priv->sec_info.encryption_mode = sme->crypto.cipher_group;
2314 priv->sec_info.authentication_mode = auth_type;
2317 ret = mwifiex_set_gen_ie(priv, sme->ie, sme->ie_len);
2320 if (mwifiex_is_alg_wep(priv->sec_info.encryption_mode)) {
2321 mwifiex_dbg(priv->adapter, INFO,
2322 "info: setting wep encryption\t"
2323 "with key len %d\n", sme->key_len);
2324 priv->wep_key_curr_index = sme->key_idx;
2325 ret = mwifiex_set_encode(priv, NULL, sme->key,
2326 sme->key_len, sme->key_idx,
2332 * Scan entries are valid for some time (15 sec). So we can save one
2333 * active scan time if we just try cfg80211_get_bss first. If it fails
2334 * then request scan and cfg80211_get_bss() again for final output.
2337 if (is_scanning_required) {
2338 /* Do specific SSID scanning */
2339 if (mwifiex_request_scan(priv, &req_ssid)) {
2340 mwifiex_dbg(priv->adapter, ERROR, "scan error\n");
2345 /* Find the BSS we want using available scan results */
2346 if (mode == NL80211_IFTYPE_ADHOC)
2347 bss = cfg80211_get_bss(priv->wdev.wiphy, channel,
2348 bssid, ssid, ssid_len,
2349 IEEE80211_BSS_TYPE_IBSS,
2350 IEEE80211_PRIVACY_ANY);
2352 bss = cfg80211_get_bss(priv->wdev.wiphy, channel,
2353 bssid, ssid, ssid_len,
2354 IEEE80211_BSS_TYPE_ESS,
2355 IEEE80211_PRIVACY_ANY);
2358 if (is_scanning_required) {
2359 mwifiex_dbg(priv->adapter, MSG,
2360 "assoc: requested bss not found in scan results\n");
2363 is_scanning_required = 1;
2365 mwifiex_dbg(priv->adapter, MSG,
2366 "info: trying to associate to bssid %pM\n",
2368 memcpy(&priv->cfg_bssid, bss->bssid, ETH_ALEN);
2374 cfg80211_ref_bss(priv->adapter->wiphy, bss);
2376 ret = mwifiex_bss_start(priv, bss, &req_ssid);
2380 if (mode == NL80211_IFTYPE_ADHOC) {
2381 /* Inform the BSS information to kernel, otherwise
2382 * kernel will give a panic after successful assoc */
2383 if (mwifiex_cfg80211_inform_ibss_bss(priv)) {
2389 /* Pass the selected BSS entry to caller. */
2397 cfg80211_put_bss(priv->adapter->wiphy, bss);
2402 * CFG802.11 operation handler for association request.
2404 * This function does not work when the current mode is set to Ad-Hoc, or
2405 * when there is already an association procedure going on. The given BSS
2406 * information is used to associate.
2409 mwifiex_cfg80211_connect(struct wiphy *wiphy, struct net_device *dev,
2410 struct cfg80211_connect_params *sme)
2412 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
2413 struct mwifiex_adapter *adapter = priv->adapter;
2414 struct cfg80211_bss *bss = NULL;
2417 if (GET_BSS_ROLE(priv) != MWIFIEX_BSS_ROLE_STA) {
2418 mwifiex_dbg(adapter, ERROR,
2419 "%s: reject infra assoc request in non-STA role\n",
2424 if (priv->wdev.current_bss) {
2425 mwifiex_dbg(adapter, ERROR,
2426 "%s: already connected\n", dev->name);
2430 if (priv->scan_block)
2431 priv->scan_block = false;
2433 if (test_bit(MWIFIEX_SURPRISE_REMOVED, &adapter->work_flags) ||
2434 test_bit(MWIFIEX_IS_CMD_TIMEDOUT, &adapter->work_flags)) {
2435 mwifiex_dbg(adapter, ERROR,
2436 "%s: Ignore connection.\t"
2437 "Card removed or FW in bad state\n",
2442 mwifiex_dbg(adapter, INFO,
2443 "info: Trying to associate to bssid %pM\n", sme->bssid);
2445 if (!mwifiex_stop_bg_scan(priv))
2446 cfg80211_sched_scan_stopped_locked(priv->wdev.wiphy, 0);
2448 ret = mwifiex_cfg80211_assoc(priv, sme->ssid_len, sme->ssid, sme->bssid,
2449 priv->bss_mode, sme->channel, sme, 0,
2452 cfg80211_connect_bss(priv->netdev, priv->cfg_bssid, bss, NULL,
2453 0, NULL, 0, WLAN_STATUS_SUCCESS,
2454 GFP_KERNEL, NL80211_TIMEOUT_UNSPECIFIED);
2455 mwifiex_dbg(priv->adapter, MSG,
2456 "info: associated to bssid %pM successfully\n",
2458 if (ISSUPP_TDLS_ENABLED(priv->adapter->fw_cap_info) &&
2459 priv->adapter->auto_tdls &&
2460 priv->bss_type == MWIFIEX_BSS_TYPE_STA)
2461 mwifiex_setup_auto_tdls_timer(priv);
2463 mwifiex_dbg(priv->adapter, ERROR,
2464 "info: association to bssid %pM failed\n",
2466 eth_zero_addr(priv->cfg_bssid);
2469 cfg80211_connect_result(priv->netdev, priv->cfg_bssid,
2470 NULL, 0, NULL, 0, ret,
2473 cfg80211_connect_result(priv->netdev, priv->cfg_bssid,
2475 WLAN_STATUS_UNSPECIFIED_FAILURE,
2483 * This function sets following parameters for ibss network.
2487 * - secondary channel offset
2489 static int mwifiex_set_ibss_params(struct mwifiex_private *priv,
2490 struct cfg80211_ibss_params *params)
2492 struct mwifiex_adapter *adapter = priv->adapter;
2494 u8 config_bands = 0;
2496 if (params->chandef.chan->band == NL80211_BAND_2GHZ) {
2497 if (!params->basic_rates) {
2498 config_bands = BAND_B | BAND_G;
2500 for (i = 0; i < mwifiex_band_2ghz.n_bitrates; i++) {
2502 * Rates below 6 Mbps in the table are CCK
2503 * rates; 802.11b and from 6 they are OFDM;
2506 if (mwifiex_rates[i].bitrate == 60) {
2512 if (params->basic_rates < index) {
2513 config_bands = BAND_B;
2515 config_bands = BAND_G;
2516 if (params->basic_rates % index)
2517 config_bands |= BAND_B;
2521 if (cfg80211_get_chandef_type(¶ms->chandef) !=
2523 config_bands |= BAND_G | BAND_GN;
2525 if (cfg80211_get_chandef_type(¶ms->chandef) ==
2527 config_bands = BAND_A;
2529 config_bands = BAND_AN | BAND_A;
2532 if (!((config_bands | adapter->fw_bands) & ~adapter->fw_bands)) {
2533 adapter->config_bands = config_bands;
2534 adapter->adhoc_start_band = config_bands;
2536 if ((config_bands & BAND_GN) || (config_bands & BAND_AN))
2537 adapter->adhoc_11n_enabled = true;
2539 adapter->adhoc_11n_enabled = false;
2542 adapter->sec_chan_offset =
2543 mwifiex_chan_type_to_sec_chan_offset(
2544 cfg80211_get_chandef_type(¶ms->chandef));
2545 priv->adhoc_channel = ieee80211_frequency_to_channel(
2546 params->chandef.chan->center_freq);
2548 mwifiex_dbg(adapter, INFO,
2549 "info: set ibss band %d, chan %d, chan offset %d\n",
2550 config_bands, priv->adhoc_channel,
2551 adapter->sec_chan_offset);
2557 * CFG802.11 operation handler to join an IBSS.
2559 * This function does not work in any mode other than Ad-Hoc, or if
2560 * a join operation is already in progress.
2563 mwifiex_cfg80211_join_ibss(struct wiphy *wiphy, struct net_device *dev,
2564 struct cfg80211_ibss_params *params)
2566 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
2569 if (priv->bss_mode != NL80211_IFTYPE_ADHOC) {
2570 mwifiex_dbg(priv->adapter, ERROR,
2571 "request to join ibss received\t"
2572 "when station is not in ibss mode\n");
2576 mwifiex_dbg(priv->adapter, MSG, "info: trying to join to bssid %pM\n",
2579 mwifiex_set_ibss_params(priv, params);
2581 ret = mwifiex_cfg80211_assoc(priv, params->ssid_len, params->ssid,
2582 params->bssid, priv->bss_mode,
2583 params->chandef.chan, NULL,
2584 params->privacy, NULL);
2587 cfg80211_ibss_joined(priv->netdev, priv->cfg_bssid,
2588 params->chandef.chan, GFP_KERNEL);
2589 mwifiex_dbg(priv->adapter, MSG,
2590 "info: joined/created adhoc network with bssid\t"
2591 "%pM successfully\n", priv->cfg_bssid);
2593 mwifiex_dbg(priv->adapter, ERROR,
2594 "info: failed creating/joining adhoc network\n");
2601 * CFG802.11 operation handler to leave an IBSS.
2603 * This function does not work if a leave operation is
2604 * already in progress.
2607 mwifiex_cfg80211_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
2609 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
2611 mwifiex_dbg(priv->adapter, MSG, "info: disconnecting from essid %pM\n",
2613 if (mwifiex_deauthenticate(priv, NULL))
2616 eth_zero_addr(priv->cfg_bssid);
2622 * CFG802.11 operation handler for scan request.
2624 * This function issues a scan request to the firmware based upon
2625 * the user specified scan configuration. On successful completion,
2626 * it also informs the results.
2629 mwifiex_cfg80211_scan(struct wiphy *wiphy,
2630 struct cfg80211_scan_request *request)
2632 struct net_device *dev = request->wdev->netdev;
2633 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
2635 struct ieee80211_channel *chan;
2636 struct ieee_types_header *ie;
2637 struct mwifiex_user_scan_cfg *user_scan_cfg;
2638 u8 mac_addr[ETH_ALEN];
2640 mwifiex_dbg(priv->adapter, CMD,
2641 "info: received scan request on %s\n", dev->name);
2643 /* Block scan request if scan operation or scan cleanup when interface
2644 * is disabled is in process
2646 if (priv->scan_request || priv->scan_aborting) {
2647 mwifiex_dbg(priv->adapter, WARN,
2648 "cmd: Scan already in process..\n");
2652 if (!priv->wdev.current_bss && priv->scan_block)
2653 priv->scan_block = false;
2655 if (!mwifiex_stop_bg_scan(priv))
2656 cfg80211_sched_scan_stopped_locked(priv->wdev.wiphy, 0);
2658 user_scan_cfg = kzalloc(sizeof(*user_scan_cfg), GFP_KERNEL);
2662 priv->scan_request = request;
2664 if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) {
2665 get_random_mask_addr(mac_addr, request->mac_addr,
2666 request->mac_addr_mask);
2667 ether_addr_copy(request->mac_addr, mac_addr);
2668 ether_addr_copy(user_scan_cfg->random_mac, mac_addr);
2671 user_scan_cfg->num_ssids = request->n_ssids;
2672 user_scan_cfg->ssid_list = request->ssids;
2674 if (request->ie && request->ie_len) {
2676 for (i = 0; i < MWIFIEX_MAX_VSIE_NUM; i++) {
2677 if (priv->vs_ie[i].mask != MWIFIEX_VSIE_MASK_CLEAR)
2679 priv->vs_ie[i].mask = MWIFIEX_VSIE_MASK_SCAN;
2680 ie = (struct ieee_types_header *)(request->ie + offset);
2681 memcpy(&priv->vs_ie[i].ie, ie, sizeof(*ie) + ie->len);
2682 offset += sizeof(*ie) + ie->len;
2684 if (offset >= request->ie_len)
2689 for (i = 0; i < min_t(u32, request->n_channels,
2690 MWIFIEX_USER_SCAN_CHAN_MAX); i++) {
2691 chan = request->channels[i];
2692 user_scan_cfg->chan_list[i].chan_number = chan->hw_value;
2693 user_scan_cfg->chan_list[i].radio_type = chan->band;
2695 if ((chan->flags & IEEE80211_CHAN_NO_IR) || !request->n_ssids)
2696 user_scan_cfg->chan_list[i].scan_type =
2697 MWIFIEX_SCAN_TYPE_PASSIVE;
2699 user_scan_cfg->chan_list[i].scan_type =
2700 MWIFIEX_SCAN_TYPE_ACTIVE;
2702 user_scan_cfg->chan_list[i].scan_time = 0;
2705 if (priv->adapter->scan_chan_gap_enabled &&
2706 mwifiex_is_any_intf_active(priv))
2707 user_scan_cfg->scan_chan_gap =
2708 priv->adapter->scan_chan_gap_time;
2710 ret = mwifiex_scan_networks(priv, user_scan_cfg);
2711 kfree(user_scan_cfg);
2713 mwifiex_dbg(priv->adapter, ERROR,
2714 "scan failed: %d\n", ret);
2715 priv->scan_aborting = false;
2716 priv->scan_request = NULL;
2720 if (request->ie && request->ie_len) {
2721 for (i = 0; i < MWIFIEX_MAX_VSIE_NUM; i++) {
2722 if (priv->vs_ie[i].mask == MWIFIEX_VSIE_MASK_SCAN) {
2723 priv->vs_ie[i].mask = MWIFIEX_VSIE_MASK_CLEAR;
2724 memset(&priv->vs_ie[i].ie, 0,
2725 MWIFIEX_MAX_VSIE_LEN);
2732 /* CFG802.11 operation handler for sched_scan_start.
2734 * This function issues a bgscan config request to the firmware based upon
2735 * the user specified sched_scan configuration. On successful completion,
2736 * firmware will generate BGSCAN_REPORT event, driver should issue bgscan
2737 * query command to get sched_scan results from firmware.
2740 mwifiex_cfg80211_sched_scan_start(struct wiphy *wiphy,
2741 struct net_device *dev,
2742 struct cfg80211_sched_scan_request *request)
2744 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
2746 struct ieee80211_channel *chan;
2747 struct mwifiex_bg_scan_cfg *bgscan_cfg;
2748 struct ieee_types_header *ie;
2750 if (!request || (!request->n_ssids && !request->n_match_sets)) {
2751 wiphy_err(wiphy, "%s : Invalid Sched_scan parameters",
2756 wiphy_info(wiphy, "sched_scan start : n_ssids=%d n_match_sets=%d ",
2757 request->n_ssids, request->n_match_sets);
2758 wiphy_info(wiphy, "n_channels=%d interval=%d ie_len=%d\n",
2759 request->n_channels, request->scan_plans->interval,
2760 (int)request->ie_len);
2762 bgscan_cfg = kzalloc(sizeof(*bgscan_cfg), GFP_KERNEL);
2766 if (priv->scan_request || priv->scan_aborting)
2767 bgscan_cfg->start_later = true;
2769 bgscan_cfg->num_ssids = request->n_match_sets;
2770 bgscan_cfg->ssid_list = request->match_sets;
2772 if (request->ie && request->ie_len) {
2774 for (i = 0; i < MWIFIEX_MAX_VSIE_NUM; i++) {
2775 if (priv->vs_ie[i].mask != MWIFIEX_VSIE_MASK_CLEAR)
2777 priv->vs_ie[i].mask = MWIFIEX_VSIE_MASK_BGSCAN;
2778 ie = (struct ieee_types_header *)(request->ie + offset);
2779 memcpy(&priv->vs_ie[i].ie, ie, sizeof(*ie) + ie->len);
2780 offset += sizeof(*ie) + ie->len;
2782 if (offset >= request->ie_len)
2787 for (i = 0; i < min_t(u32, request->n_channels,
2788 MWIFIEX_BG_SCAN_CHAN_MAX); i++) {
2789 chan = request->channels[i];
2790 bgscan_cfg->chan_list[i].chan_number = chan->hw_value;
2791 bgscan_cfg->chan_list[i].radio_type = chan->band;
2793 if ((chan->flags & IEEE80211_CHAN_NO_IR) || !request->n_ssids)
2794 bgscan_cfg->chan_list[i].scan_type =
2795 MWIFIEX_SCAN_TYPE_PASSIVE;
2797 bgscan_cfg->chan_list[i].scan_type =
2798 MWIFIEX_SCAN_TYPE_ACTIVE;
2800 bgscan_cfg->chan_list[i].scan_time = 0;
2803 bgscan_cfg->chan_per_scan = min_t(u32, request->n_channels,
2804 MWIFIEX_BG_SCAN_CHAN_MAX);
2806 /* Use at least 15 second for per scan cycle */
2807 bgscan_cfg->scan_interval = (request->scan_plans->interval >
2808 MWIFIEX_BGSCAN_INTERVAL) ?
2809 request->scan_plans->interval :
2810 MWIFIEX_BGSCAN_INTERVAL;
2812 bgscan_cfg->repeat_count = MWIFIEX_BGSCAN_REPEAT_COUNT;
2813 bgscan_cfg->report_condition = MWIFIEX_BGSCAN_SSID_MATCH |
2814 MWIFIEX_BGSCAN_WAIT_ALL_CHAN_DONE;
2815 bgscan_cfg->bss_type = MWIFIEX_BSS_MODE_INFRA;
2816 bgscan_cfg->action = MWIFIEX_BGSCAN_ACT_SET;
2817 bgscan_cfg->enable = true;
2818 if (request->min_rssi_thold != NL80211_SCAN_RSSI_THOLD_OFF) {
2819 bgscan_cfg->report_condition |= MWIFIEX_BGSCAN_SSID_RSSI_MATCH;
2820 bgscan_cfg->rssi_threshold = request->min_rssi_thold;
2823 if (mwifiex_send_cmd(priv, HostCmd_CMD_802_11_BG_SCAN_CONFIG,
2824 HostCmd_ACT_GEN_SET, 0, bgscan_cfg, true)) {
2829 priv->sched_scanning = true;
2835 /* CFG802.11 operation handler for sched_scan_stop.
2837 * This function issues a bgscan config command to disable
2838 * previous bgscan configuration in the firmware
2840 static int mwifiex_cfg80211_sched_scan_stop(struct wiphy *wiphy,
2841 struct net_device *dev, u64 reqid)
2843 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
2845 wiphy_info(wiphy, "sched scan stop!");
2846 mwifiex_stop_bg_scan(priv);
2851 static void mwifiex_setup_vht_caps(struct ieee80211_sta_vht_cap *vht_info,
2852 struct mwifiex_private *priv)
2854 struct mwifiex_adapter *adapter = priv->adapter;
2856 vht_info->vht_supported = true;
2858 vht_info->cap = adapter->hw_dot_11ac_dev_cap;
2859 /* Update MCS support for VHT */
2860 vht_info->vht_mcs.rx_mcs_map = cpu_to_le16(
2861 adapter->hw_dot_11ac_mcs_support & 0xFFFF);
2862 vht_info->vht_mcs.rx_highest = 0;
2863 vht_info->vht_mcs.tx_mcs_map = cpu_to_le16(
2864 adapter->hw_dot_11ac_mcs_support >> 16);
2865 vht_info->vht_mcs.tx_highest = 0;
2869 * This function sets up the CFG802.11 specific HT capability fields
2870 * with default values.
2872 * The following default values are set -
2873 * - HT Supported = True
2874 * - Maximum AMPDU length factor = IEEE80211_HT_MAX_AMPDU_64K
2875 * - Minimum AMPDU spacing = IEEE80211_HT_MPDU_DENSITY_NONE
2876 * - HT Capabilities supported by firmware
2877 * - MCS information, Rx mask = 0xff
2878 * - MCD information, Tx parameters = IEEE80211_HT_MCS_TX_DEFINED (0x01)
2881 mwifiex_setup_ht_caps(struct ieee80211_sta_ht_cap *ht_info,
2882 struct mwifiex_private *priv)
2885 struct ieee80211_mcs_info mcs_set;
2886 u8 *mcs = (u8 *)&mcs_set;
2887 struct mwifiex_adapter *adapter = priv->adapter;
2889 ht_info->ht_supported = true;
2890 ht_info->ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
2891 ht_info->ampdu_density = IEEE80211_HT_MPDU_DENSITY_NONE;
2893 memset(&ht_info->mcs, 0, sizeof(ht_info->mcs));
2895 /* Fill HT capability information */
2896 if (ISSUPP_CHANWIDTH40(adapter->hw_dot_11n_dev_cap))
2897 ht_info->cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
2899 ht_info->cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
2901 if (ISSUPP_SHORTGI20(adapter->hw_dot_11n_dev_cap))
2902 ht_info->cap |= IEEE80211_HT_CAP_SGI_20;
2904 ht_info->cap &= ~IEEE80211_HT_CAP_SGI_20;
2906 if (ISSUPP_SHORTGI40(adapter->hw_dot_11n_dev_cap))
2907 ht_info->cap |= IEEE80211_HT_CAP_SGI_40;
2909 ht_info->cap &= ~IEEE80211_HT_CAP_SGI_40;
2911 if (adapter->user_dev_mcs_support == HT_STREAM_2X2)
2912 ht_info->cap |= 2 << IEEE80211_HT_CAP_RX_STBC_SHIFT;
2914 ht_info->cap |= 1 << IEEE80211_HT_CAP_RX_STBC_SHIFT;
2916 if (ISSUPP_TXSTBC(adapter->hw_dot_11n_dev_cap))
2917 ht_info->cap |= IEEE80211_HT_CAP_TX_STBC;
2919 ht_info->cap &= ~IEEE80211_HT_CAP_TX_STBC;
2921 if (ISSUPP_GREENFIELD(adapter->hw_dot_11n_dev_cap))
2922 ht_info->cap |= IEEE80211_HT_CAP_GRN_FLD;
2924 ht_info->cap &= ~IEEE80211_HT_CAP_GRN_FLD;
2926 if (ISENABLED_40MHZ_INTOLERANT(adapter->hw_dot_11n_dev_cap))
2927 ht_info->cap |= IEEE80211_HT_CAP_40MHZ_INTOLERANT;
2929 ht_info->cap &= ~IEEE80211_HT_CAP_40MHZ_INTOLERANT;
2931 if (ISSUPP_RXLDPC(adapter->hw_dot_11n_dev_cap))
2932 ht_info->cap |= IEEE80211_HT_CAP_LDPC_CODING;
2934 ht_info->cap &= ~IEEE80211_HT_CAP_LDPC_CODING;
2936 ht_info->cap &= ~IEEE80211_HT_CAP_MAX_AMSDU;
2937 ht_info->cap |= IEEE80211_HT_CAP_SM_PS;
2939 rx_mcs_supp = GET_RXMCSSUPP(adapter->user_dev_mcs_support);
2940 /* Set MCS for 1x1/2x2 */
2941 memset(mcs, 0xff, rx_mcs_supp);
2942 /* Clear all the other values */
2943 memset(&mcs[rx_mcs_supp], 0,
2944 sizeof(struct ieee80211_mcs_info) - rx_mcs_supp);
2945 if (priv->bss_mode == NL80211_IFTYPE_STATION ||
2946 ISSUPP_CHANWIDTH40(adapter->hw_dot_11n_dev_cap))
2947 /* Set MCS32 for infra mode or ad-hoc mode with 40MHz support */
2948 SETHT_MCS32(mcs_set.rx_mask);
2950 memcpy((u8 *) &ht_info->mcs, mcs, sizeof(struct ieee80211_mcs_info));
2952 ht_info->mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED;
2956 * create a new virtual interface with the given name and name assign type
2958 struct wireless_dev *mwifiex_add_virtual_intf(struct wiphy *wiphy,
2960 unsigned char name_assign_type,
2961 enum nl80211_iftype type,
2962 struct vif_params *params)
2964 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
2965 struct mwifiex_private *priv;
2966 struct net_device *dev;
2971 return ERR_PTR(-EFAULT);
2974 case NL80211_IFTYPE_UNSPECIFIED:
2975 case NL80211_IFTYPE_STATION:
2976 case NL80211_IFTYPE_ADHOC:
2977 if (adapter->curr_iface_comb.sta_intf ==
2978 adapter->iface_limit.sta_intf) {
2979 mwifiex_dbg(adapter, ERROR,
2980 "cannot create multiple sta/adhoc ifaces\n");
2981 return ERR_PTR(-EINVAL);
2984 priv = mwifiex_get_unused_priv_by_bss_type(
2985 adapter, MWIFIEX_BSS_TYPE_STA);
2987 mwifiex_dbg(adapter, ERROR,
2988 "could not get free private struct\n");
2989 return ERR_PTR(-EFAULT);
2992 priv->wdev.wiphy = wiphy;
2993 priv->wdev.iftype = NL80211_IFTYPE_STATION;
2995 if (type == NL80211_IFTYPE_UNSPECIFIED)
2996 priv->bss_mode = NL80211_IFTYPE_STATION;
2998 priv->bss_mode = type;
3000 priv->bss_type = MWIFIEX_BSS_TYPE_STA;
3001 priv->frame_type = MWIFIEX_DATA_FRAME_TYPE_ETH_II;
3002 priv->bss_priority = 0;
3003 priv->bss_role = MWIFIEX_BSS_ROLE_STA;
3006 case NL80211_IFTYPE_AP:
3007 if (adapter->curr_iface_comb.uap_intf ==
3008 adapter->iface_limit.uap_intf) {
3009 mwifiex_dbg(adapter, ERROR,
3010 "cannot create multiple AP ifaces\n");
3011 return ERR_PTR(-EINVAL);
3014 priv = mwifiex_get_unused_priv_by_bss_type(
3015 adapter, MWIFIEX_BSS_TYPE_UAP);
3017 mwifiex_dbg(adapter, ERROR,
3018 "could not get free private struct\n");
3019 return ERR_PTR(-EFAULT);
3022 priv->wdev.wiphy = wiphy;
3023 priv->wdev.iftype = NL80211_IFTYPE_AP;
3025 priv->bss_type = MWIFIEX_BSS_TYPE_UAP;
3026 priv->frame_type = MWIFIEX_DATA_FRAME_TYPE_ETH_II;
3027 priv->bss_priority = 0;
3028 priv->bss_role = MWIFIEX_BSS_ROLE_UAP;
3029 priv->bss_started = 0;
3030 priv->bss_mode = type;
3033 case NL80211_IFTYPE_P2P_CLIENT:
3034 if (adapter->curr_iface_comb.p2p_intf ==
3035 adapter->iface_limit.p2p_intf) {
3036 mwifiex_dbg(adapter, ERROR,
3037 "cannot create multiple P2P ifaces\n");
3038 return ERR_PTR(-EINVAL);
3041 priv = mwifiex_get_unused_priv_by_bss_type(
3042 adapter, MWIFIEX_BSS_TYPE_P2P);
3044 mwifiex_dbg(adapter, ERROR,
3045 "could not get free private struct\n");
3046 return ERR_PTR(-EFAULT);
3049 priv->wdev.wiphy = wiphy;
3050 /* At start-up, wpa_supplicant tries to change the interface
3051 * to NL80211_IFTYPE_STATION if it is not managed mode.
3053 priv->wdev.iftype = NL80211_IFTYPE_P2P_CLIENT;
3054 priv->bss_mode = NL80211_IFTYPE_P2P_CLIENT;
3056 /* Setting bss_type to P2P tells firmware that this interface
3057 * is receiving P2P peers found during find phase and doing
3058 * action frame handshake.
3060 priv->bss_type = MWIFIEX_BSS_TYPE_P2P;
3062 priv->frame_type = MWIFIEX_DATA_FRAME_TYPE_ETH_II;
3063 priv->bss_priority = 0;
3064 priv->bss_role = MWIFIEX_BSS_ROLE_STA;
3065 priv->bss_started = 0;
3067 if (mwifiex_cfg80211_init_p2p_client(priv)) {
3068 memset(&priv->wdev, 0, sizeof(priv->wdev));
3069 priv->wdev.iftype = NL80211_IFTYPE_UNSPECIFIED;
3070 return ERR_PTR(-EFAULT);
3075 mwifiex_dbg(adapter, ERROR, "type not supported\n");
3076 return ERR_PTR(-EINVAL);
3079 dev = alloc_netdev_mqs(sizeof(struct mwifiex_private *), name,
3080 name_assign_type, ether_setup,
3081 IEEE80211_NUM_ACS, 1);
3083 mwifiex_dbg(adapter, ERROR,
3084 "no memory available for netdevice\n");
3086 goto err_alloc_netdev;
3089 mwifiex_init_priv_params(priv, dev);
3093 if (!adapter->mfg_mode) {
3094 mwifiex_set_mac_address(priv, dev, false, NULL);
3096 ret = mwifiex_send_cmd(priv, HostCmd_CMD_SET_BSS_MODE,
3097 HostCmd_ACT_GEN_SET, 0, NULL, true);
3099 goto err_set_bss_mode;
3101 ret = mwifiex_sta_init_cmd(priv, false, false);
3106 mwifiex_setup_ht_caps(&wiphy->bands[NL80211_BAND_2GHZ]->ht_cap, priv);
3107 if (adapter->is_hw_11ac_capable)
3108 mwifiex_setup_vht_caps(
3109 &wiphy->bands[NL80211_BAND_2GHZ]->vht_cap, priv);
3111 if (adapter->config_bands & BAND_A)
3112 mwifiex_setup_ht_caps(
3113 &wiphy->bands[NL80211_BAND_5GHZ]->ht_cap, priv);
3115 if ((adapter->config_bands & BAND_A) && adapter->is_hw_11ac_capable)
3116 mwifiex_setup_vht_caps(
3117 &wiphy->bands[NL80211_BAND_5GHZ]->vht_cap, priv);
3119 dev_net_set(dev, wiphy_net(wiphy));
3120 dev->ieee80211_ptr = &priv->wdev;
3121 dev->ieee80211_ptr->iftype = priv->bss_mode;
3122 SET_NETDEV_DEV(dev, wiphy_dev(wiphy));
3124 dev->flags |= IFF_BROADCAST | IFF_MULTICAST;
3125 dev->watchdog_timeo = MWIFIEX_DEFAULT_WATCHDOG_TIMEOUT;
3126 dev->needed_headroom = MWIFIEX_MIN_DATA_HEADER_LEN;
3127 dev->ethtool_ops = &mwifiex_ethtool_ops;
3129 mdev_priv = netdev_priv(dev);
3130 *((unsigned long *) mdev_priv) = (unsigned long) priv;
3132 SET_NETDEV_DEV(dev, adapter->dev);
3134 priv->dfs_cac_workqueue = alloc_workqueue("MWIFIEX_DFS_CAC%s",
3137 WQ_UNBOUND, 1, name);
3138 if (!priv->dfs_cac_workqueue) {
3139 mwifiex_dbg(adapter, ERROR, "cannot alloc DFS CAC queue\n");
3144 INIT_DELAYED_WORK(&priv->dfs_cac_work, mwifiex_dfs_cac_work_queue);
3146 priv->dfs_chan_sw_workqueue = alloc_workqueue("MWIFIEX_DFS_CHSW%s",
3147 WQ_HIGHPRI | WQ_UNBOUND |
3148 WQ_MEM_RECLAIM, 1, name);
3149 if (!priv->dfs_chan_sw_workqueue) {
3150 mwifiex_dbg(adapter, ERROR, "cannot alloc DFS channel sw queue\n");
3152 goto err_alloc_chsw;
3155 INIT_DELAYED_WORK(&priv->dfs_chan_sw_work,
3156 mwifiex_dfs_chan_sw_work_queue);
3158 mutex_init(&priv->async_mutex);
3160 /* Register network device */
3161 if (cfg80211_register_netdevice(dev)) {
3162 mwifiex_dbg(adapter, ERROR, "cannot register network device\n");
3164 goto err_reg_netdev;
3167 mwifiex_dbg(adapter, INFO,
3168 "info: %s: Marvell 802.11 Adapter\n", dev->name);
3170 #ifdef CONFIG_DEBUG_FS
3171 mwifiex_dev_debugfs_init(priv);
3174 update_vif_type_counter(adapter, type, +1);
3179 destroy_workqueue(priv->dfs_chan_sw_workqueue);
3180 priv->dfs_chan_sw_workqueue = NULL;
3182 destroy_workqueue(priv->dfs_cac_workqueue);
3183 priv->dfs_cac_workqueue = NULL;
3186 priv->netdev = NULL;
3190 memset(&priv->wdev, 0, sizeof(priv->wdev));
3191 priv->wdev.iftype = NL80211_IFTYPE_UNSPECIFIED;
3192 priv->bss_mode = NL80211_IFTYPE_UNSPECIFIED;
3193 return ERR_PTR(ret);
3195 EXPORT_SYMBOL_GPL(mwifiex_add_virtual_intf);
3198 * del_virtual_intf: remove the virtual interface determined by dev
3200 int mwifiex_del_virtual_intf(struct wiphy *wiphy, struct wireless_dev *wdev)
3202 struct mwifiex_private *priv = mwifiex_netdev_get_priv(wdev->netdev);
3203 struct mwifiex_adapter *adapter = priv->adapter;
3204 struct sk_buff *skb, *tmp;
3206 #ifdef CONFIG_DEBUG_FS
3207 mwifiex_dev_debugfs_remove(priv);
3210 if (priv->sched_scanning)
3211 priv->sched_scanning = false;
3213 mwifiex_stop_net_dev_queue(priv->netdev, adapter);
3215 skb_queue_walk_safe(&priv->bypass_txq, skb, tmp) {
3216 skb_unlink(skb, &priv->bypass_txq);
3217 mwifiex_write_data_complete(priv->adapter, skb, 0, -1);
3220 if (netif_carrier_ok(priv->netdev))
3221 netif_carrier_off(priv->netdev);
3223 if (wdev->netdev->reg_state == NETREG_REGISTERED)
3224 cfg80211_unregister_netdevice(wdev->netdev);
3226 if (priv->dfs_cac_workqueue) {
3227 destroy_workqueue(priv->dfs_cac_workqueue);
3228 priv->dfs_cac_workqueue = NULL;
3231 if (priv->dfs_chan_sw_workqueue) {
3232 destroy_workqueue(priv->dfs_chan_sw_workqueue);
3233 priv->dfs_chan_sw_workqueue = NULL;
3235 /* Clear the priv in adapter */
3236 priv->netdev = NULL;
3238 update_vif_type_counter(adapter, priv->bss_mode, -1);
3240 priv->bss_mode = NL80211_IFTYPE_UNSPECIFIED;
3242 if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA ||
3243 GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_UAP)
3244 kfree(priv->hist_data);
3248 EXPORT_SYMBOL_GPL(mwifiex_del_virtual_intf);
3251 mwifiex_is_pattern_supported(struct cfg80211_pkt_pattern *pat, s8 *byte_seq,
3254 int j, k, valid_byte_cnt = 0;
3255 bool dont_care_byte = false;
3257 for (j = 0; j < DIV_ROUND_UP(pat->pattern_len, 8); j++) {
3258 for (k = 0; k < 8; k++) {
3259 if (pat->mask[j] & 1 << k) {
3260 memcpy(byte_seq + valid_byte_cnt,
3261 &pat->pattern[j * 8 + k], 1);
3267 dont_care_byte = true;
3270 /* wildcard bytes record as the offset
3271 * before the valid byte
3273 if (!valid_byte_cnt && !dont_care_byte)
3276 if (valid_byte_cnt > max_byte_seq)
3281 byte_seq[max_byte_seq] = valid_byte_cnt;
3287 static void mwifiex_set_auto_arp_mef_entry(struct mwifiex_private *priv,
3288 struct mwifiex_mef_entry *mef_entry)
3290 int i, filt_num = 0, num_ipv4 = 0;
3291 struct in_device *in_dev;
3292 struct in_ifaddr *ifa;
3293 __be32 ips[MWIFIEX_MAX_SUPPORTED_IPADDR];
3294 struct mwifiex_adapter *adapter = priv->adapter;
3296 mef_entry->mode = MEF_MODE_HOST_SLEEP;
3297 mef_entry->action = MEF_ACTION_AUTO_ARP;
3299 /* Enable ARP offload feature */
3300 memset(ips, 0, sizeof(ips));
3301 for (i = 0; i < MWIFIEX_MAX_BSS_NUM; i++) {
3302 if (adapter->priv[i]->netdev) {
3303 in_dev = __in_dev_get_rtnl(adapter->priv[i]->netdev);
3306 ifa = rtnl_dereference(in_dev->ifa_list);
3307 if (!ifa || !ifa->ifa_local)
3309 ips[i] = ifa->ifa_local;
3314 for (i = 0; i < num_ipv4; i++) {
3317 mef_entry->filter[filt_num].repeat = 1;
3318 memcpy(mef_entry->filter[filt_num].byte_seq,
3319 (u8 *)&ips[i], sizeof(ips[i]));
3320 mef_entry->filter[filt_num].
3321 byte_seq[MWIFIEX_MEF_MAX_BYTESEQ] =
3323 mef_entry->filter[filt_num].offset = 46;
3324 mef_entry->filter[filt_num].filt_type = TYPE_EQ;
3326 mef_entry->filter[filt_num].filt_action =
3332 mef_entry->filter[filt_num].repeat = 1;
3333 mef_entry->filter[filt_num].byte_seq[0] = 0x08;
3334 mef_entry->filter[filt_num].byte_seq[1] = 0x06;
3335 mef_entry->filter[filt_num].byte_seq[MWIFIEX_MEF_MAX_BYTESEQ] = 2;
3336 mef_entry->filter[filt_num].offset = 20;
3337 mef_entry->filter[filt_num].filt_type = TYPE_EQ;
3338 mef_entry->filter[filt_num].filt_action = TYPE_AND;
3341 static int mwifiex_set_wowlan_mef_entry(struct mwifiex_private *priv,
3342 struct mwifiex_ds_mef_cfg *mef_cfg,
3343 struct mwifiex_mef_entry *mef_entry,
3344 struct cfg80211_wowlan *wowlan)
3346 int i, filt_num = 0, ret = 0;
3347 bool first_pat = true;
3348 u8 byte_seq[MWIFIEX_MEF_MAX_BYTESEQ + 1];
3349 static const u8 ipv4_mc_mac[] = {0x33, 0x33};
3350 static const u8 ipv6_mc_mac[] = {0x01, 0x00, 0x5e};
3352 mef_entry->mode = MEF_MODE_HOST_SLEEP;
3353 mef_entry->action = MEF_ACTION_ALLOW_AND_WAKEUP_HOST;
3355 for (i = 0; i < wowlan->n_patterns; i++) {
3356 memset(byte_seq, 0, sizeof(byte_seq));
3357 if (!mwifiex_is_pattern_supported(&wowlan->patterns[i],
3359 MWIFIEX_MEF_MAX_BYTESEQ)) {
3360 mwifiex_dbg(priv->adapter, ERROR,
3361 "Pattern not supported\n");
3365 if (!wowlan->patterns[i].pkt_offset) {
3366 if (!(byte_seq[0] & 0x01) &&
3367 (byte_seq[MWIFIEX_MEF_MAX_BYTESEQ] == 1)) {
3368 mef_cfg->criteria |= MWIFIEX_CRITERIA_UNICAST;
3370 } else if (is_broadcast_ether_addr(byte_seq)) {
3371 mef_cfg->criteria |= MWIFIEX_CRITERIA_BROADCAST;
3373 } else if ((!memcmp(byte_seq, ipv4_mc_mac, 2) &&
3374 (byte_seq[MWIFIEX_MEF_MAX_BYTESEQ] == 2)) ||
3375 (!memcmp(byte_seq, ipv6_mc_mac, 3) &&
3376 (byte_seq[MWIFIEX_MEF_MAX_BYTESEQ] == 3))) {
3377 mef_cfg->criteria |= MWIFIEX_CRITERIA_MULTICAST;
3381 mef_entry->filter[filt_num].repeat = 1;
3382 mef_entry->filter[filt_num].offset =
3383 wowlan->patterns[i].pkt_offset;
3384 memcpy(mef_entry->filter[filt_num].byte_seq, byte_seq,
3386 mef_entry->filter[filt_num].filt_type = TYPE_EQ;
3390 mwifiex_dbg(priv->adapter, INFO, "Wake on patterns\n");
3392 mef_entry->filter[filt_num].filt_action = TYPE_AND;
3398 if (wowlan->magic_pkt) {
3399 mef_cfg->criteria |= MWIFIEX_CRITERIA_UNICAST;
3400 mef_entry->filter[filt_num].repeat = 16;
3401 memcpy(mef_entry->filter[filt_num].byte_seq, priv->curr_addr,
3403 mef_entry->filter[filt_num].byte_seq[MWIFIEX_MEF_MAX_BYTESEQ] =
3405 mef_entry->filter[filt_num].offset = 28;
3406 mef_entry->filter[filt_num].filt_type = TYPE_EQ;
3408 mef_entry->filter[filt_num].filt_action = TYPE_OR;
3411 mef_entry->filter[filt_num].repeat = 16;
3412 memcpy(mef_entry->filter[filt_num].byte_seq, priv->curr_addr,
3414 mef_entry->filter[filt_num].byte_seq[MWIFIEX_MEF_MAX_BYTESEQ] =
3416 mef_entry->filter[filt_num].offset = 56;
3417 mef_entry->filter[filt_num].filt_type = TYPE_EQ;
3418 mef_entry->filter[filt_num].filt_action = TYPE_OR;
3419 mwifiex_dbg(priv->adapter, INFO, "Wake on magic packet\n");
3424 static int mwifiex_set_mef_filter(struct mwifiex_private *priv,
3425 struct cfg80211_wowlan *wowlan)
3427 int ret = 0, num_entries = 1;
3428 struct mwifiex_ds_mef_cfg mef_cfg;
3429 struct mwifiex_mef_entry *mef_entry;
3431 if (wowlan->n_patterns || wowlan->magic_pkt)
3434 mef_entry = kcalloc(num_entries, sizeof(*mef_entry), GFP_KERNEL);
3438 memset(&mef_cfg, 0, sizeof(mef_cfg));
3439 mef_cfg.criteria |= MWIFIEX_CRITERIA_BROADCAST |
3440 MWIFIEX_CRITERIA_UNICAST;
3441 mef_cfg.num_entries = num_entries;
3442 mef_cfg.mef_entry = mef_entry;
3444 mwifiex_set_auto_arp_mef_entry(priv, &mef_entry[0]);
3446 if (wowlan->n_patterns || wowlan->magic_pkt) {
3447 ret = mwifiex_set_wowlan_mef_entry(priv, &mef_cfg,
3448 &mef_entry[1], wowlan);
3453 if (!mef_cfg.criteria)
3454 mef_cfg.criteria = MWIFIEX_CRITERIA_BROADCAST |
3455 MWIFIEX_CRITERIA_UNICAST |
3456 MWIFIEX_CRITERIA_MULTICAST;
3458 ret = mwifiex_send_cmd(priv, HostCmd_CMD_MEF_CFG,
3459 HostCmd_ACT_GEN_SET, 0,
3467 static int mwifiex_cfg80211_suspend(struct wiphy *wiphy,
3468 struct cfg80211_wowlan *wowlan)
3470 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
3471 struct mwifiex_ds_hs_cfg hs_cfg;
3472 int i, ret = 0, retry_num = 10;
3473 struct mwifiex_private *priv;
3474 struct mwifiex_private *sta_priv =
3475 mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_STA);
3477 sta_priv->scan_aborting = true;
3478 for (i = 0; i < adapter->priv_num; i++) {
3479 priv = adapter->priv[i];
3480 mwifiex_abort_cac(priv);
3483 mwifiex_cancel_all_pending_cmd(adapter);
3485 for (i = 0; i < adapter->priv_num; i++) {
3486 priv = adapter->priv[i];
3487 if (priv && priv->netdev)
3488 netif_device_detach(priv->netdev);
3491 for (i = 0; i < retry_num; i++) {
3492 if (!mwifiex_wmm_lists_empty(adapter) ||
3493 !mwifiex_bypass_txlist_empty(adapter) ||
3494 !skb_queue_empty(&adapter->tx_data_q))
3495 usleep_range(10000, 15000);
3501 mwifiex_dbg(adapter, INFO,
3502 "None of the WOWLAN triggers enabled\n");
3507 if (!sta_priv->media_connected && !wowlan->nd_config) {
3508 mwifiex_dbg(adapter, ERROR,
3509 "Can not configure WOWLAN in disconnected state\n");
3514 ret = mwifiex_set_mef_filter(sta_priv, wowlan);
3516 mwifiex_dbg(adapter, ERROR, "Failed to set MEF filter\n");
3520 memset(&hs_cfg, 0, sizeof(hs_cfg));
3521 hs_cfg.conditions = le32_to_cpu(adapter->hs_cfg.conditions);
3523 if (wowlan->nd_config) {
3524 mwifiex_dbg(adapter, INFO, "Wake on net detect\n");
3525 hs_cfg.conditions |= HS_CFG_COND_MAC_EVENT;
3526 mwifiex_cfg80211_sched_scan_start(wiphy, sta_priv->netdev,
3530 if (wowlan->disconnect) {
3531 hs_cfg.conditions |= HS_CFG_COND_MAC_EVENT;
3532 mwifiex_dbg(sta_priv->adapter, INFO, "Wake on device disconnect\n");
3535 hs_cfg.is_invoke_hostcmd = false;
3536 hs_cfg.gpio = adapter->hs_cfg.gpio;
3537 hs_cfg.gap = adapter->hs_cfg.gap;
3538 ret = mwifiex_set_hs_params(sta_priv, HostCmd_ACT_GEN_SET,
3539 MWIFIEX_SYNC_CMD, &hs_cfg);
3541 mwifiex_dbg(adapter, ERROR, "Failed to set HS params\n");
3544 sta_priv->scan_aborting = false;
3548 static int mwifiex_cfg80211_resume(struct wiphy *wiphy)
3550 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
3551 struct mwifiex_private *priv;
3552 struct mwifiex_ds_wakeup_reason wakeup_reason;
3553 struct cfg80211_wowlan_wakeup wakeup_report;
3555 bool report_wakeup_reason = true;
3557 for (i = 0; i < adapter->priv_num; i++) {
3558 priv = adapter->priv[i];
3559 if (priv && priv->netdev)
3560 netif_device_attach(priv->netdev);
3563 if (!wiphy->wowlan_config)
3566 priv = mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_STA);
3567 mwifiex_get_wakeup_reason(priv, HostCmd_ACT_GEN_GET, MWIFIEX_SYNC_CMD,
3569 memset(&wakeup_report, 0, sizeof(struct cfg80211_wowlan_wakeup));
3571 wakeup_report.pattern_idx = -1;
3573 switch (wakeup_reason.hs_wakeup_reason) {
3574 case NO_HSWAKEUP_REASON:
3576 case BCAST_DATA_MATCHED:
3578 case MCAST_DATA_MATCHED:
3580 case UCAST_DATA_MATCHED:
3582 case MASKTABLE_EVENT_MATCHED:
3584 case NON_MASKABLE_EVENT_MATCHED:
3585 if (wiphy->wowlan_config->disconnect)
3586 wakeup_report.disconnect = true;
3587 if (wiphy->wowlan_config->nd_config)
3588 wakeup_report.net_detect = adapter->nd_info;
3590 case NON_MASKABLE_CONDITION_MATCHED:
3592 case MAGIC_PATTERN_MATCHED:
3593 if (wiphy->wowlan_config->magic_pkt)
3594 wakeup_report.magic_pkt = true;
3595 if (wiphy->wowlan_config->n_patterns)
3596 wakeup_report.pattern_idx = 1;
3598 case GTK_REKEY_FAILURE:
3599 if (wiphy->wowlan_config->gtk_rekey_failure)
3600 wakeup_report.gtk_rekey_failure = true;
3603 report_wakeup_reason = false;
3607 if (report_wakeup_reason)
3608 cfg80211_report_wowlan_wakeup(&priv->wdev, &wakeup_report,
3612 if (adapter->nd_info) {
3613 for (i = 0 ; i < adapter->nd_info->n_matches ; i++)
3614 kfree(adapter->nd_info->matches[i]);
3615 kfree(adapter->nd_info);
3616 adapter->nd_info = NULL;
3622 static void mwifiex_cfg80211_set_wakeup(struct wiphy *wiphy,
3625 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
3627 device_set_wakeup_enable(adapter->dev, enabled);
3630 static int mwifiex_set_rekey_data(struct wiphy *wiphy, struct net_device *dev,
3631 struct cfg80211_gtk_rekey_data *data)
3633 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
3635 if (!ISSUPP_FIRMWARE_SUPPLICANT(priv->adapter->fw_cap_info))
3638 return mwifiex_send_cmd(priv, HostCmd_CMD_GTK_REKEY_OFFLOAD_CFG,
3639 HostCmd_ACT_GEN_SET, 0, data, true);
3644 static int mwifiex_get_coalesce_pkt_type(u8 *byte_seq)
3646 static const u8 ipv4_mc_mac[] = {0x33, 0x33};
3647 static const u8 ipv6_mc_mac[] = {0x01, 0x00, 0x5e};
3648 static const u8 bc_mac[] = {0xff, 0xff, 0xff, 0xff};
3650 if ((byte_seq[0] & 0x01) &&
3651 (byte_seq[MWIFIEX_COALESCE_MAX_BYTESEQ] == 1))
3652 return PACKET_TYPE_UNICAST;
3653 else if (!memcmp(byte_seq, bc_mac, 4))
3654 return PACKET_TYPE_BROADCAST;
3655 else if ((!memcmp(byte_seq, ipv4_mc_mac, 2) &&
3656 byte_seq[MWIFIEX_COALESCE_MAX_BYTESEQ] == 2) ||
3657 (!memcmp(byte_seq, ipv6_mc_mac, 3) &&
3658 byte_seq[MWIFIEX_COALESCE_MAX_BYTESEQ] == 3))
3659 return PACKET_TYPE_MULTICAST;
3665 mwifiex_fill_coalesce_rule_info(struct mwifiex_private *priv,
3666 struct cfg80211_coalesce_rules *crule,
3667 struct mwifiex_coalesce_rule *mrule)
3669 u8 byte_seq[MWIFIEX_COALESCE_MAX_BYTESEQ + 1];
3670 struct filt_field_param *param;
3673 mrule->max_coalescing_delay = crule->delay;
3675 param = mrule->params;
3677 for (i = 0; i < crule->n_patterns; i++) {
3678 memset(byte_seq, 0, sizeof(byte_seq));
3679 if (!mwifiex_is_pattern_supported(&crule->patterns[i],
3681 MWIFIEX_COALESCE_MAX_BYTESEQ)) {
3682 mwifiex_dbg(priv->adapter, ERROR,
3683 "Pattern not supported\n");
3687 if (!crule->patterns[i].pkt_offset) {
3690 pkt_type = mwifiex_get_coalesce_pkt_type(byte_seq);
3691 if (pkt_type && mrule->pkt_type) {
3692 mwifiex_dbg(priv->adapter, ERROR,
3693 "Multiple packet types not allowed\n");
3695 } else if (pkt_type) {
3696 mrule->pkt_type = pkt_type;
3701 if (crule->condition == NL80211_COALESCE_CONDITION_MATCH)
3702 param->operation = RECV_FILTER_MATCH_TYPE_EQ;
3704 param->operation = RECV_FILTER_MATCH_TYPE_NE;
3706 param->operand_len = byte_seq[MWIFIEX_COALESCE_MAX_BYTESEQ];
3707 memcpy(param->operand_byte_stream, byte_seq,
3708 param->operand_len);
3709 param->offset = crule->patterns[i].pkt_offset;
3712 mrule->num_of_fields++;
3715 if (!mrule->pkt_type) {
3716 mwifiex_dbg(priv->adapter, ERROR,
3717 "Packet type can not be determined\n");
3724 static int mwifiex_cfg80211_set_coalesce(struct wiphy *wiphy,
3725 struct cfg80211_coalesce *coalesce)
3727 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
3729 struct mwifiex_ds_coalesce_cfg coalesce_cfg;
3730 struct mwifiex_private *priv =
3731 mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_STA);
3733 memset(&coalesce_cfg, 0, sizeof(coalesce_cfg));
3735 mwifiex_dbg(adapter, WARN,
3736 "Disable coalesce and reset all previous rules\n");
3737 return mwifiex_send_cmd(priv, HostCmd_CMD_COALESCE_CFG,
3738 HostCmd_ACT_GEN_SET, 0,
3739 &coalesce_cfg, true);
3742 coalesce_cfg.num_of_rules = coalesce->n_rules;
3743 for (i = 0; i < coalesce->n_rules; i++) {
3744 ret = mwifiex_fill_coalesce_rule_info(priv, &coalesce->rules[i],
3745 &coalesce_cfg.rule[i]);
3747 mwifiex_dbg(adapter, ERROR,
3748 "Recheck the patterns provided for rule %d\n",
3754 return mwifiex_send_cmd(priv, HostCmd_CMD_COALESCE_CFG,
3755 HostCmd_ACT_GEN_SET, 0, &coalesce_cfg, true);
3758 /* cfg80211 ops handler for tdls_mgmt.
3759 * Function prepares TDLS action frame packets and forwards them to FW
3762 mwifiex_cfg80211_tdls_mgmt(struct wiphy *wiphy, struct net_device *dev,
3763 const u8 *peer, u8 action_code, u8 dialog_token,
3764 u16 status_code, u32 peer_capability,
3765 bool initiator, const u8 *extra_ies,
3766 size_t extra_ies_len)
3768 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
3771 if (!(wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS))
3774 /* make sure we are in station mode and connected */
3775 if (!(priv->bss_type == MWIFIEX_BSS_TYPE_STA && priv->media_connected))
3778 switch (action_code) {
3779 case WLAN_TDLS_SETUP_REQUEST:
3780 mwifiex_dbg(priv->adapter, MSG,
3781 "Send TDLS Setup Request to %pM status_code=%d\n",
3783 mwifiex_add_auto_tdls_peer(priv, peer);
3784 ret = mwifiex_send_tdls_data_frame(priv, peer, action_code,
3785 dialog_token, status_code,
3786 extra_ies, extra_ies_len);
3788 case WLAN_TDLS_SETUP_RESPONSE:
3789 mwifiex_add_auto_tdls_peer(priv, peer);
3790 mwifiex_dbg(priv->adapter, MSG,
3791 "Send TDLS Setup Response to %pM status_code=%d\n",
3793 ret = mwifiex_send_tdls_data_frame(priv, peer, action_code,
3794 dialog_token, status_code,
3795 extra_ies, extra_ies_len);
3797 case WLAN_TDLS_SETUP_CONFIRM:
3798 mwifiex_dbg(priv->adapter, MSG,
3799 "Send TDLS Confirm to %pM status_code=%d\n", peer,
3801 ret = mwifiex_send_tdls_data_frame(priv, peer, action_code,
3802 dialog_token, status_code,
3803 extra_ies, extra_ies_len);
3805 case WLAN_TDLS_TEARDOWN:
3806 mwifiex_dbg(priv->adapter, MSG,
3807 "Send TDLS Tear down to %pM\n", peer);
3808 ret = mwifiex_send_tdls_data_frame(priv, peer, action_code,
3809 dialog_token, status_code,
3810 extra_ies, extra_ies_len);
3812 case WLAN_TDLS_DISCOVERY_REQUEST:
3813 mwifiex_dbg(priv->adapter, MSG,
3814 "Send TDLS Discovery Request to %pM\n", peer);
3815 ret = mwifiex_send_tdls_data_frame(priv, peer, action_code,
3816 dialog_token, status_code,
3817 extra_ies, extra_ies_len);
3819 case WLAN_PUB_ACTION_TDLS_DISCOVER_RES:
3820 mwifiex_dbg(priv->adapter, MSG,
3821 "Send TDLS Discovery Response to %pM\n", peer);
3822 ret = mwifiex_send_tdls_action_frame(priv, peer, action_code,
3823 dialog_token, status_code,
3824 extra_ies, extra_ies_len);
3827 mwifiex_dbg(priv->adapter, ERROR,
3828 "Unknown TDLS mgmt/action frame %pM\n", peer);
3837 mwifiex_cfg80211_tdls_oper(struct wiphy *wiphy, struct net_device *dev,
3838 const u8 *peer, enum nl80211_tdls_operation action)
3840 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
3842 if (!(wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
3843 !(wiphy->flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP))
3846 /* make sure we are in station mode and connected */
3847 if (!(priv->bss_type == MWIFIEX_BSS_TYPE_STA && priv->media_connected))
3850 mwifiex_dbg(priv->adapter, MSG,
3851 "TDLS peer=%pM, oper=%d\n", peer, action);
3854 case NL80211_TDLS_ENABLE_LINK:
3855 action = MWIFIEX_TDLS_ENABLE_LINK;
3857 case NL80211_TDLS_DISABLE_LINK:
3858 action = MWIFIEX_TDLS_DISABLE_LINK;
3860 case NL80211_TDLS_TEARDOWN:
3861 /* shouldn't happen!*/
3862 mwifiex_dbg(priv->adapter, ERROR,
3863 "tdls_oper: teardown from driver not supported\n");
3865 case NL80211_TDLS_SETUP:
3866 /* shouldn't happen!*/
3867 mwifiex_dbg(priv->adapter, ERROR,
3868 "tdls_oper: setup from driver not supported\n");
3870 case NL80211_TDLS_DISCOVERY_REQ:
3871 /* shouldn't happen!*/
3872 mwifiex_dbg(priv->adapter, ERROR,
3873 "tdls_oper: discovery from driver not supported\n");
3876 mwifiex_dbg(priv->adapter, ERROR,
3877 "tdls_oper: operation not supported\n");
3881 return mwifiex_tdls_oper(priv, peer, action);
3885 mwifiex_cfg80211_tdls_chan_switch(struct wiphy *wiphy, struct net_device *dev,
3886 const u8 *addr, u8 oper_class,
3887 struct cfg80211_chan_def *chandef)
3889 struct mwifiex_sta_node *sta_ptr;
3891 u8 second_chan_offset, band;
3892 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
3894 spin_lock_bh(&priv->sta_list_spinlock);
3895 sta_ptr = mwifiex_get_sta_entry(priv, addr);
3897 spin_unlock_bh(&priv->sta_list_spinlock);
3898 wiphy_err(wiphy, "%s: Invalid TDLS peer %pM\n",
3903 if (!(sta_ptr->tdls_cap.extcap.ext_capab[3] &
3904 WLAN_EXT_CAPA4_TDLS_CHAN_SWITCH)) {
3905 spin_unlock_bh(&priv->sta_list_spinlock);
3906 wiphy_err(wiphy, "%pM do not support tdls cs\n", addr);
3910 if (sta_ptr->tdls_status == TDLS_CHAN_SWITCHING ||
3911 sta_ptr->tdls_status == TDLS_IN_OFF_CHAN) {
3912 spin_unlock_bh(&priv->sta_list_spinlock);
3913 wiphy_err(wiphy, "channel switch is running, abort request\n");
3916 spin_unlock_bh(&priv->sta_list_spinlock);
3918 chan = chandef->chan->hw_value;
3919 second_chan_offset = mwifiex_get_sec_chan_offset(chan);
3920 band = chandef->chan->band;
3921 mwifiex_start_tdls_cs(priv, addr, chan, second_chan_offset, band);
3927 mwifiex_cfg80211_tdls_cancel_chan_switch(struct wiphy *wiphy,
3928 struct net_device *dev,
3931 struct mwifiex_sta_node *sta_ptr;
3932 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
3934 spin_lock_bh(&priv->sta_list_spinlock);
3935 sta_ptr = mwifiex_get_sta_entry(priv, addr);
3937 spin_unlock_bh(&priv->sta_list_spinlock);
3938 wiphy_err(wiphy, "%s: Invalid TDLS peer %pM\n",
3940 } else if (!(sta_ptr->tdls_status == TDLS_CHAN_SWITCHING ||
3941 sta_ptr->tdls_status == TDLS_IN_BASE_CHAN ||
3942 sta_ptr->tdls_status == TDLS_IN_OFF_CHAN)) {
3943 spin_unlock_bh(&priv->sta_list_spinlock);
3944 wiphy_err(wiphy, "tdls chan switch not initialize by %pM\n",
3947 spin_unlock_bh(&priv->sta_list_spinlock);
3948 mwifiex_stop_tdls_cs(priv, addr);
3953 mwifiex_cfg80211_add_station(struct wiphy *wiphy, struct net_device *dev,
3954 const u8 *mac, struct station_parameters *params)
3956 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
3958 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
3961 /* make sure we are in station mode and connected */
3962 if ((priv->bss_type != MWIFIEX_BSS_TYPE_STA) || !priv->media_connected)
3965 return mwifiex_tdls_oper(priv, mac, MWIFIEX_TDLS_CREATE_LINK);
3969 mwifiex_cfg80211_channel_switch(struct wiphy *wiphy, struct net_device *dev,
3970 struct cfg80211_csa_settings *params)
3972 struct ieee_types_header *chsw_ie;
3973 struct ieee80211_channel_sw_ie *channel_sw;
3975 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
3977 if (priv->adapter->scan_processing) {
3978 mwifiex_dbg(priv->adapter, ERROR,
3979 "radar detection: scan in process...\n");
3983 if (priv->wdev.cac_started)
3986 if (cfg80211_chandef_identical(¶ms->chandef,
3987 &priv->dfs_chandef))
3990 chsw_ie = (void *)cfg80211_find_ie(WLAN_EID_CHANNEL_SWITCH,
3991 params->beacon_csa.tail,
3992 params->beacon_csa.tail_len);
3994 mwifiex_dbg(priv->adapter, ERROR,
3995 "Could not parse channel switch announcement IE\n");
3999 channel_sw = (void *)(chsw_ie + 1);
4000 if (channel_sw->mode) {
4001 if (netif_carrier_ok(priv->netdev))
4002 netif_carrier_off(priv->netdev);
4003 mwifiex_stop_net_dev_queue(priv->netdev, priv->adapter);
4006 if (mwifiex_del_mgmt_ies(priv))
4007 mwifiex_dbg(priv->adapter, ERROR,
4008 "Failed to delete mgmt IEs!\n");
4010 if (mwifiex_set_mgmt_ies(priv, ¶ms->beacon_csa)) {
4011 mwifiex_dbg(priv->adapter, ERROR,
4012 "%s: setting mgmt ies failed\n", __func__);
4016 memcpy(&priv->dfs_chandef, ¶ms->chandef, sizeof(priv->dfs_chandef));
4017 memcpy(&priv->beacon_after, ¶ms->beacon_after,
4018 sizeof(priv->beacon_after));
4020 chsw_msec = max(channel_sw->count * priv->bss_cfg.beacon_period, 100);
4021 queue_delayed_work(priv->dfs_chan_sw_workqueue, &priv->dfs_chan_sw_work,
4022 msecs_to_jiffies(chsw_msec));
4026 static int mwifiex_cfg80211_get_channel(struct wiphy *wiphy,
4027 struct wireless_dev *wdev,
4028 struct cfg80211_chan_def *chandef)
4030 struct mwifiex_private *priv = mwifiex_netdev_get_priv(wdev->netdev);
4031 struct mwifiex_bssdescriptor *curr_bss;
4032 struct ieee80211_channel *chan;
4033 enum nl80211_channel_type chan_type;
4034 enum nl80211_band band;
4038 if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_UAP &&
4039 cfg80211_chandef_valid(&priv->bss_chandef)) {
4040 *chandef = priv->bss_chandef;
4042 } else if (priv->media_connected) {
4043 curr_bss = &priv->curr_bss_params.bss_descriptor;
4044 band = mwifiex_band_to_radio_type(priv->curr_bss_params.band);
4045 freq = ieee80211_channel_to_frequency(curr_bss->channel, band);
4046 chan = ieee80211_get_channel(wiphy, freq);
4048 if (priv->ht_param_present) {
4049 chan_type = mwifiex_get_chan_type(priv);
4050 cfg80211_chandef_create(chandef, chan, chan_type);
4052 cfg80211_chandef_create(chandef, chan,
4053 NL80211_CHAN_NO_HT);
4061 #ifdef CONFIG_NL80211_TESTMODE
4063 enum mwifiex_tm_attr {
4064 __MWIFIEX_TM_ATTR_INVALID = 0,
4065 MWIFIEX_TM_ATTR_CMD = 1,
4066 MWIFIEX_TM_ATTR_DATA = 2,
4069 __MWIFIEX_TM_ATTR_AFTER_LAST,
4070 MWIFIEX_TM_ATTR_MAX = __MWIFIEX_TM_ATTR_AFTER_LAST - 1,
4073 static const struct nla_policy mwifiex_tm_policy[MWIFIEX_TM_ATTR_MAX + 1] = {
4074 [MWIFIEX_TM_ATTR_CMD] = { .type = NLA_U32 },
4075 [MWIFIEX_TM_ATTR_DATA] = { .type = NLA_BINARY,
4076 .len = MWIFIEX_SIZE_OF_CMD_BUFFER },
4079 enum mwifiex_tm_command {
4080 MWIFIEX_TM_CMD_HOSTCMD = 0,
4083 static int mwifiex_tm_cmd(struct wiphy *wiphy, struct wireless_dev *wdev,
4084 void *data, int len)
4086 struct mwifiex_private *priv = mwifiex_netdev_get_priv(wdev->netdev);
4087 struct mwifiex_ds_misc_cmd *hostcmd;
4088 struct nlattr *tb[MWIFIEX_TM_ATTR_MAX + 1];
4089 struct sk_buff *skb;
4095 err = nla_parse_deprecated(tb, MWIFIEX_TM_ATTR_MAX, data, len,
4096 mwifiex_tm_policy, NULL);
4100 if (!tb[MWIFIEX_TM_ATTR_CMD])
4103 switch (nla_get_u32(tb[MWIFIEX_TM_ATTR_CMD])) {
4104 case MWIFIEX_TM_CMD_HOSTCMD:
4105 if (!tb[MWIFIEX_TM_ATTR_DATA])
4108 hostcmd = kzalloc(sizeof(*hostcmd), GFP_KERNEL);
4112 hostcmd->len = nla_len(tb[MWIFIEX_TM_ATTR_DATA]);
4113 memcpy(hostcmd->cmd, nla_data(tb[MWIFIEX_TM_ATTR_DATA]),
4116 if (mwifiex_send_cmd(priv, 0, 0, 0, hostcmd, true)) {
4117 dev_err(priv->adapter->dev, "Failed to process hostcmd\n");
4122 /* process hostcmd response*/
4123 skb = cfg80211_testmode_alloc_reply_skb(wiphy, hostcmd->len);
4128 err = nla_put(skb, MWIFIEX_TM_ATTR_DATA,
4129 hostcmd->len, hostcmd->cmd);
4136 err = cfg80211_testmode_reply(skb);
4146 mwifiex_cfg80211_start_radar_detection(struct wiphy *wiphy,
4147 struct net_device *dev,
4148 struct cfg80211_chan_def *chandef,
4151 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
4152 struct mwifiex_radar_params radar_params;
4154 if (priv->adapter->scan_processing) {
4155 mwifiex_dbg(priv->adapter, ERROR,
4156 "radar detection: scan already in process...\n");
4160 if (!mwifiex_is_11h_active(priv)) {
4161 mwifiex_dbg(priv->adapter, INFO,
4162 "Enable 11h extensions in FW\n");
4163 if (mwifiex_11h_activate(priv, true)) {
4164 mwifiex_dbg(priv->adapter, ERROR,
4165 "Failed to activate 11h extensions!!");
4168 priv->state_11h.is_11h_active = true;
4171 memset(&radar_params, 0, sizeof(struct mwifiex_radar_params));
4172 radar_params.chandef = chandef;
4173 radar_params.cac_time_ms = cac_time_ms;
4175 memcpy(&priv->dfs_chandef, chandef, sizeof(priv->dfs_chandef));
4177 if (mwifiex_send_cmd(priv, HostCmd_CMD_CHAN_REPORT_REQUEST,
4178 HostCmd_ACT_GEN_SET, 0, &radar_params, true))
4181 queue_delayed_work(priv->dfs_cac_workqueue, &priv->dfs_cac_work,
4182 msecs_to_jiffies(cac_time_ms));
4187 mwifiex_cfg80211_change_station(struct wiphy *wiphy, struct net_device *dev,
4189 struct station_parameters *params)
4192 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
4194 /* we support change_station handler only for TDLS peers*/
4195 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
4198 /* make sure we are in station mode and connected */
4199 if ((priv->bss_type != MWIFIEX_BSS_TYPE_STA) || !priv->media_connected)
4202 priv->sta_params = params;
4204 ret = mwifiex_tdls_oper(priv, mac, MWIFIEX_TDLS_CONFIG_LINK);
4205 priv->sta_params = NULL;
4210 /* station cfg80211 operations */
4211 static struct cfg80211_ops mwifiex_cfg80211_ops = {
4212 .add_virtual_intf = mwifiex_add_virtual_intf,
4213 .del_virtual_intf = mwifiex_del_virtual_intf,
4214 .change_virtual_intf = mwifiex_cfg80211_change_virtual_intf,
4215 .scan = mwifiex_cfg80211_scan,
4216 .connect = mwifiex_cfg80211_connect,
4217 .disconnect = mwifiex_cfg80211_disconnect,
4218 .get_station = mwifiex_cfg80211_get_station,
4219 .dump_station = mwifiex_cfg80211_dump_station,
4220 .dump_survey = mwifiex_cfg80211_dump_survey,
4221 .set_wiphy_params = mwifiex_cfg80211_set_wiphy_params,
4222 .join_ibss = mwifiex_cfg80211_join_ibss,
4223 .leave_ibss = mwifiex_cfg80211_leave_ibss,
4224 .add_key = mwifiex_cfg80211_add_key,
4225 .del_key = mwifiex_cfg80211_del_key,
4226 .set_default_mgmt_key = mwifiex_cfg80211_set_default_mgmt_key,
4227 .mgmt_tx = mwifiex_cfg80211_mgmt_tx,
4228 .update_mgmt_frame_registrations =
4229 mwifiex_cfg80211_update_mgmt_frame_registrations,
4230 .remain_on_channel = mwifiex_cfg80211_remain_on_channel,
4231 .cancel_remain_on_channel = mwifiex_cfg80211_cancel_remain_on_channel,
4232 .set_default_key = mwifiex_cfg80211_set_default_key,
4233 .set_power_mgmt = mwifiex_cfg80211_set_power_mgmt,
4234 .set_tx_power = mwifiex_cfg80211_set_tx_power,
4235 .get_tx_power = mwifiex_cfg80211_get_tx_power,
4236 .set_bitrate_mask = mwifiex_cfg80211_set_bitrate_mask,
4237 .start_ap = mwifiex_cfg80211_start_ap,
4238 .stop_ap = mwifiex_cfg80211_stop_ap,
4239 .change_beacon = mwifiex_cfg80211_change_beacon,
4240 .set_cqm_rssi_config = mwifiex_cfg80211_set_cqm_rssi_config,
4241 .set_antenna = mwifiex_cfg80211_set_antenna,
4242 .get_antenna = mwifiex_cfg80211_get_antenna,
4243 .del_station = mwifiex_cfg80211_del_station,
4244 .sched_scan_start = mwifiex_cfg80211_sched_scan_start,
4245 .sched_scan_stop = mwifiex_cfg80211_sched_scan_stop,
4247 .suspend = mwifiex_cfg80211_suspend,
4248 .resume = mwifiex_cfg80211_resume,
4249 .set_wakeup = mwifiex_cfg80211_set_wakeup,
4250 .set_rekey_data = mwifiex_set_rekey_data,
4252 .set_coalesce = mwifiex_cfg80211_set_coalesce,
4253 .tdls_mgmt = mwifiex_cfg80211_tdls_mgmt,
4254 .tdls_oper = mwifiex_cfg80211_tdls_oper,
4255 .tdls_channel_switch = mwifiex_cfg80211_tdls_chan_switch,
4256 .tdls_cancel_channel_switch = mwifiex_cfg80211_tdls_cancel_chan_switch,
4257 .add_station = mwifiex_cfg80211_add_station,
4258 .change_station = mwifiex_cfg80211_change_station,
4259 CFG80211_TESTMODE_CMD(mwifiex_tm_cmd)
4260 .get_channel = mwifiex_cfg80211_get_channel,
4261 .start_radar_detection = mwifiex_cfg80211_start_radar_detection,
4262 .channel_switch = mwifiex_cfg80211_channel_switch,
4266 static const struct wiphy_wowlan_support mwifiex_wowlan_support = {
4267 .flags = WIPHY_WOWLAN_MAGIC_PKT | WIPHY_WOWLAN_DISCONNECT |
4268 WIPHY_WOWLAN_NET_DETECT | WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
4269 WIPHY_WOWLAN_GTK_REKEY_FAILURE,
4270 .n_patterns = MWIFIEX_MEF_MAX_FILTERS,
4271 .pattern_min_len = 1,
4272 .pattern_max_len = MWIFIEX_MAX_PATTERN_LEN,
4273 .max_pkt_offset = MWIFIEX_MAX_OFFSET_LEN,
4274 .max_nd_match_sets = MWIFIEX_MAX_ND_MATCH_SETS,
4277 static const struct wiphy_wowlan_support mwifiex_wowlan_support_no_gtk = {
4278 .flags = WIPHY_WOWLAN_MAGIC_PKT | WIPHY_WOWLAN_DISCONNECT |
4279 WIPHY_WOWLAN_NET_DETECT,
4280 .n_patterns = MWIFIEX_MEF_MAX_FILTERS,
4281 .pattern_min_len = 1,
4282 .pattern_max_len = MWIFIEX_MAX_PATTERN_LEN,
4283 .max_pkt_offset = MWIFIEX_MAX_OFFSET_LEN,
4284 .max_nd_match_sets = MWIFIEX_MAX_ND_MATCH_SETS,
4288 static bool mwifiex_is_valid_alpha2(const char *alpha2)
4290 if (!alpha2 || strlen(alpha2) != 2)
4293 if (isalpha(alpha2[0]) && isalpha(alpha2[1]))
4299 static const struct wiphy_coalesce_support mwifiex_coalesce_support = {
4300 .n_rules = MWIFIEX_COALESCE_MAX_RULES,
4301 .max_delay = MWIFIEX_MAX_COALESCING_DELAY,
4302 .n_patterns = MWIFIEX_COALESCE_MAX_FILTERS,
4303 .pattern_min_len = 1,
4304 .pattern_max_len = MWIFIEX_MAX_PATTERN_LEN,
4305 .max_pkt_offset = MWIFIEX_MAX_OFFSET_LEN,
4308 int mwifiex_init_channel_scan_gap(struct mwifiex_adapter *adapter)
4310 u32 n_channels_bg, n_channels_a = 0;
4312 n_channels_bg = mwifiex_band_2ghz.n_channels;
4314 if (adapter->config_bands & BAND_A)
4315 n_channels_a = mwifiex_band_5ghz.n_channels;
4317 /* allocate twice the number total channels, since the driver issues an
4318 * additional active scan request for hidden SSIDs on passive channels.
4320 adapter->num_in_chan_stats = 2 * (n_channels_bg + n_channels_a);
4321 adapter->chan_stats = vmalloc(array_size(sizeof(*adapter->chan_stats),
4322 adapter->num_in_chan_stats));
4324 if (!adapter->chan_stats)
4331 * This function registers the device with CFG802.11 subsystem.
4333 * The function creates the wireless device/wiphy, populates it with
4334 * default parameters and handler function pointers, and finally
4335 * registers the device.
4338 int mwifiex_register_cfg80211(struct mwifiex_adapter *adapter)
4342 struct wiphy *wiphy;
4343 struct mwifiex_private *priv = adapter->priv[MWIFIEX_BSS_TYPE_STA];
4347 /* create a new wiphy for use with cfg80211 */
4348 wiphy = wiphy_new(&mwifiex_cfg80211_ops,
4349 sizeof(struct mwifiex_adapter *));
4351 mwifiex_dbg(adapter, ERROR,
4352 "%s: creating new wiphy\n", __func__);
4355 wiphy->max_scan_ssids = MWIFIEX_MAX_SSID_LIST_LENGTH;
4356 wiphy->max_scan_ie_len = MWIFIEX_MAX_VSIE_LEN;
4357 wiphy->mgmt_stypes = mwifiex_mgmt_stypes;
4358 wiphy->max_remain_on_channel_duration = 5000;
4359 wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
4360 BIT(NL80211_IFTYPE_P2P_CLIENT) |
4361 BIT(NL80211_IFTYPE_P2P_GO) |
4362 BIT(NL80211_IFTYPE_AP);
4364 if (ISSUPP_ADHOC_ENABLED(adapter->fw_cap_info))
4365 wiphy->interface_modes |= BIT(NL80211_IFTYPE_ADHOC);
4367 wiphy->bands[NL80211_BAND_2GHZ] = &mwifiex_band_2ghz;
4368 if (adapter->config_bands & BAND_A)
4369 wiphy->bands[NL80211_BAND_5GHZ] = &mwifiex_band_5ghz;
4371 wiphy->bands[NL80211_BAND_5GHZ] = NULL;
4373 if (adapter->drcs_enabled && ISSUPP_DRCS_ENABLED(adapter->fw_cap_info))
4374 wiphy->iface_combinations = &mwifiex_iface_comb_ap_sta_drcs;
4375 else if (adapter->is_hw_11ac_capable)
4376 wiphy->iface_combinations = &mwifiex_iface_comb_ap_sta_vht;
4378 wiphy->iface_combinations = &mwifiex_iface_comb_ap_sta;
4379 wiphy->n_iface_combinations = 1;
4381 if (adapter->max_sta_conn > adapter->max_p2p_conn)
4382 wiphy->max_ap_assoc_sta = adapter->max_sta_conn;
4384 wiphy->max_ap_assoc_sta = adapter->max_p2p_conn;
4386 /* Initialize cipher suits */
4387 wiphy->cipher_suites = mwifiex_cipher_suites;
4388 wiphy->n_cipher_suites = ARRAY_SIZE(mwifiex_cipher_suites);
4390 if (adapter->regd) {
4391 wiphy->regulatory_flags |= REGULATORY_CUSTOM_REG |
4392 REGULATORY_DISABLE_BEACON_HINTS |
4393 REGULATORY_COUNTRY_IE_IGNORE;
4394 wiphy_apply_custom_regulatory(wiphy, adapter->regd);
4397 ether_addr_copy(wiphy->perm_addr, adapter->perm_addr);
4398 wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
4399 wiphy->flags |= WIPHY_FLAG_HAVE_AP_SME |
4400 WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD |
4401 WIPHY_FLAG_AP_UAPSD |
4402 WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL |
4403 WIPHY_FLAG_HAS_CHANNEL_SWITCH |
4404 WIPHY_FLAG_PS_ON_BY_DEFAULT;
4406 if (ISSUPP_TDLS_ENABLED(adapter->fw_cap_info))
4407 wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS |
4408 WIPHY_FLAG_TDLS_EXTERNAL_SETUP;
4411 if (ISSUPP_FIRMWARE_SUPPLICANT(priv->adapter->fw_cap_info))
4412 wiphy->wowlan = &mwifiex_wowlan_support;
4414 wiphy->wowlan = &mwifiex_wowlan_support_no_gtk;
4417 wiphy->coalesce = &mwifiex_coalesce_support;
4419 wiphy->probe_resp_offload = NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS |
4420 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2 |
4421 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P;
4423 wiphy->max_sched_scan_reqs = 1;
4424 wiphy->max_sched_scan_ssids = MWIFIEX_MAX_SSID_LIST_LENGTH;
4425 wiphy->max_sched_scan_ie_len = MWIFIEX_MAX_VSIE_LEN;
4426 wiphy->max_match_sets = MWIFIEX_MAX_SSID_LIST_LENGTH;
4428 wiphy->available_antennas_tx = BIT(adapter->number_of_antenna) - 1;
4429 wiphy->available_antennas_rx = BIT(adapter->number_of_antenna) - 1;
4431 wiphy->features |= NL80211_FEATURE_INACTIVITY_TIMER |
4432 NL80211_FEATURE_LOW_PRIORITY_SCAN |
4433 NL80211_FEATURE_NEED_OBSS_SCAN;
4435 if (ISSUPP_ADHOC_ENABLED(adapter->fw_cap_info))
4436 wiphy->features |= NL80211_FEATURE_HT_IBSS;
4438 if (ISSUPP_RANDOM_MAC(adapter->fw_cap_info))
4439 wiphy->features |= NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR |
4440 NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR |
4441 NL80211_FEATURE_ND_RANDOM_MAC_ADDR;
4443 if (ISSUPP_TDLS_ENABLED(adapter->fw_cap_info))
4444 wiphy->features |= NL80211_FEATURE_TDLS_CHANNEL_SWITCH;
4446 if (adapter->fw_api_ver == MWIFIEX_FW_V15)
4447 wiphy->features |= NL80211_FEATURE_SK_TX_STATUS;
4449 /* Reserve space for mwifiex specific private data for BSS */
4450 wiphy->bss_priv_size = sizeof(struct mwifiex_bss_priv);
4452 wiphy->reg_notifier = mwifiex_reg_notifier;
4454 /* Set struct mwifiex_adapter pointer in wiphy_priv */
4455 wdev_priv = wiphy_priv(wiphy);
4456 *(unsigned long *)wdev_priv = (unsigned long)adapter;
4458 set_wiphy_dev(wiphy, priv->adapter->dev);
4460 ret = wiphy_register(wiphy);
4462 mwifiex_dbg(adapter, ERROR,
4463 "%s: wiphy_register failed: %d\n", __func__, ret);
4468 if (!adapter->regd) {
4469 if (reg_alpha2 && mwifiex_is_valid_alpha2(reg_alpha2)) {
4470 mwifiex_dbg(adapter, INFO,
4471 "driver hint alpha2: %2.2s\n", reg_alpha2);
4472 regulatory_hint(wiphy, reg_alpha2);
4474 if (adapter->region_code == 0x00) {
4475 mwifiex_dbg(adapter, WARN,
4476 "Ignore world regulatory domain\n");
4478 wiphy->regulatory_flags |=
4479 REGULATORY_DISABLE_BEACON_HINTS |
4480 REGULATORY_COUNTRY_IE_IGNORE;
4482 mwifiex_11d_code_2_region(
4483 adapter->region_code);
4485 regulatory_hint(wiphy, country_code))
4486 mwifiex_dbg(priv->adapter, ERROR,
4487 "regulatory_hint() failed\n");
4492 mwifiex_send_cmd(priv, HostCmd_CMD_802_11_SNMP_MIB,
4493 HostCmd_ACT_GEN_GET, FRAG_THRESH_I, &thr, true);
4494 wiphy->frag_threshold = thr;
4495 mwifiex_send_cmd(priv, HostCmd_CMD_802_11_SNMP_MIB,
4496 HostCmd_ACT_GEN_GET, RTS_THRESH_I, &thr, true);
4497 wiphy->rts_threshold = thr;
4498 mwifiex_send_cmd(priv, HostCmd_CMD_802_11_SNMP_MIB,
4499 HostCmd_ACT_GEN_GET, SHORT_RETRY_LIM_I, &retry, true);
4500 wiphy->retry_short = (u8) retry;
4501 mwifiex_send_cmd(priv, HostCmd_CMD_802_11_SNMP_MIB,
4502 HostCmd_ACT_GEN_GET, LONG_RETRY_LIM_I, &retry, true);
4503 wiphy->retry_long = (u8) retry;
4505 adapter->wiphy = wiphy;