2 * Marvell Wireless LAN device driver: CFG80211
4 * Copyright (C) 2011-2014, Marvell International Ltd.
6 * This software file (the "File") is distributed by Marvell International
7 * Ltd. under the terms of the GNU General Public License Version 2, June 1991
8 * (the "License"). You may use, redistribute and/or modify this File in
9 * accordance with the terms and conditions of the License, a copy of which
10 * is available by writing to the Free Software Foundation, Inc.,
11 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA or on the
12 * worldwide web at http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
14 * THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE
16 * ARE EXPRESSLY DISCLAIMED. The License provides additional details about
17 * this warranty disclaimer.
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 = 3, .types = BIT(NL80211_IFTYPE_STATION) |
31 BIT(NL80211_IFTYPE_P2P_GO) |
32 BIT(NL80211_IFTYPE_P2P_CLIENT) |
33 BIT(NL80211_IFTYPE_AP),
37 static const struct ieee80211_iface_combination
38 mwifiex_iface_comb_ap_sta = {
39 .limits = mwifiex_ap_sta_limits,
40 .num_different_channels = 1,
41 .n_limits = ARRAY_SIZE(mwifiex_ap_sta_limits),
42 .max_interfaces = MWIFIEX_MAX_BSS_NUM,
43 .beacon_int_infra_match = true,
44 .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
45 BIT(NL80211_CHAN_WIDTH_20) |
46 BIT(NL80211_CHAN_WIDTH_40),
49 static const struct ieee80211_iface_combination
50 mwifiex_iface_comb_ap_sta_vht = {
51 .limits = mwifiex_ap_sta_limits,
52 .num_different_channels = 1,
53 .n_limits = ARRAY_SIZE(mwifiex_ap_sta_limits),
54 .max_interfaces = MWIFIEX_MAX_BSS_NUM,
55 .beacon_int_infra_match = true,
56 .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
57 BIT(NL80211_CHAN_WIDTH_20) |
58 BIT(NL80211_CHAN_WIDTH_40) |
59 BIT(NL80211_CHAN_WIDTH_80),
63 ieee80211_iface_combination mwifiex_iface_comb_ap_sta_drcs = {
64 .limits = mwifiex_ap_sta_limits,
65 .num_different_channels = 2,
66 .n_limits = ARRAY_SIZE(mwifiex_ap_sta_limits),
67 .max_interfaces = MWIFIEX_MAX_BSS_NUM,
68 .beacon_int_infra_match = true,
72 * This function maps the nl802.11 channel type into driver channel type.
74 * The mapping is as follows -
75 * NL80211_CHAN_NO_HT -> IEEE80211_HT_PARAM_CHA_SEC_NONE
76 * NL80211_CHAN_HT20 -> IEEE80211_HT_PARAM_CHA_SEC_NONE
77 * NL80211_CHAN_HT40PLUS -> IEEE80211_HT_PARAM_CHA_SEC_ABOVE
78 * NL80211_CHAN_HT40MINUS -> IEEE80211_HT_PARAM_CHA_SEC_BELOW
79 * Others -> IEEE80211_HT_PARAM_CHA_SEC_NONE
81 u8 mwifiex_chan_type_to_sec_chan_offset(enum nl80211_channel_type chan_type)
84 case NL80211_CHAN_NO_HT:
85 case NL80211_CHAN_HT20:
86 return IEEE80211_HT_PARAM_CHA_SEC_NONE;
87 case NL80211_CHAN_HT40PLUS:
88 return IEEE80211_HT_PARAM_CHA_SEC_ABOVE;
89 case NL80211_CHAN_HT40MINUS:
90 return IEEE80211_HT_PARAM_CHA_SEC_BELOW;
92 return IEEE80211_HT_PARAM_CHA_SEC_NONE;
96 /* This function maps IEEE HT secondary channel type to NL80211 channel type
98 u8 mwifiex_sec_chan_offset_to_chan_type(u8 second_chan_offset)
100 switch (second_chan_offset) {
101 case IEEE80211_HT_PARAM_CHA_SEC_NONE:
102 return NL80211_CHAN_HT20;
103 case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
104 return NL80211_CHAN_HT40PLUS;
105 case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
106 return NL80211_CHAN_HT40MINUS;
108 return NL80211_CHAN_HT20;
113 * This function checks whether WEP is set.
116 mwifiex_is_alg_wep(u32 cipher)
119 case WLAN_CIPHER_SUITE_WEP40:
120 case WLAN_CIPHER_SUITE_WEP104:
130 * This function retrieves the private structure from kernel wiphy structure.
132 static void *mwifiex_cfg80211_get_adapter(struct wiphy *wiphy)
134 return (void *) (*(unsigned long *) wiphy_priv(wiphy));
138 * CFG802.11 operation handler to delete a network key.
141 mwifiex_cfg80211_del_key(struct wiphy *wiphy, struct net_device *netdev,
142 u8 key_index, bool pairwise, const u8 *mac_addr)
144 struct mwifiex_private *priv = mwifiex_netdev_get_priv(netdev);
145 const u8 bc_mac[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
146 const u8 *peer_mac = pairwise ? mac_addr : bc_mac;
148 if (mwifiex_set_encode(priv, NULL, NULL, 0, key_index, peer_mac, 1)) {
149 mwifiex_dbg(priv->adapter, ERROR, "deleting the crypto keys\n");
153 mwifiex_dbg(priv->adapter, INFO, "info: crypto keys deleted\n");
158 * This function forms an skb for management frame.
161 mwifiex_form_mgmt_frame(struct sk_buff *skb, const u8 *buf, size_t len)
163 u8 addr[ETH_ALEN] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
165 u32 tx_control = 0, pkt_type = PKT_TYPE_MGMT;
167 pkt_len = len + ETH_ALEN;
169 skb_reserve(skb, MWIFIEX_MIN_DATA_HEADER_LEN +
170 MWIFIEX_MGMT_FRAME_HEADER_SIZE + sizeof(pkt_len));
171 memcpy(skb_push(skb, sizeof(pkt_len)), &pkt_len, sizeof(pkt_len));
173 memcpy(skb_push(skb, sizeof(tx_control)),
174 &tx_control, sizeof(tx_control));
176 memcpy(skb_push(skb, sizeof(pkt_type)), &pkt_type, sizeof(pkt_type));
178 /* Add packet data and address4 */
179 memcpy(skb_put(skb, sizeof(struct ieee80211_hdr_3addr)), buf,
180 sizeof(struct ieee80211_hdr_3addr));
181 memcpy(skb_put(skb, ETH_ALEN), addr, ETH_ALEN);
182 memcpy(skb_put(skb, len - sizeof(struct ieee80211_hdr_3addr)),
183 buf + sizeof(struct ieee80211_hdr_3addr),
184 len - sizeof(struct ieee80211_hdr_3addr));
186 skb->priority = LOW_PRIO_TID;
187 __net_timestamp(skb);
193 * CFG802.11 operation handler to transmit a management frame.
196 mwifiex_cfg80211_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev,
197 struct cfg80211_mgmt_tx_params *params, u64 *cookie)
199 const u8 *buf = params->buf;
200 size_t len = params->len;
203 const struct ieee80211_mgmt *mgmt;
204 struct mwifiex_txinfo *tx_info;
205 struct mwifiex_private *priv = mwifiex_netdev_get_priv(wdev->netdev);
208 mwifiex_dbg(priv->adapter, ERROR, "invalid buffer and length\n");
212 mgmt = (const struct ieee80211_mgmt *)buf;
213 if (GET_BSS_ROLE(priv) != MWIFIEX_BSS_ROLE_STA &&
214 ieee80211_is_probe_resp(mgmt->frame_control)) {
215 /* Since we support offload probe resp, we need to skip probe
216 * resp in AP or GO mode */
217 mwifiex_dbg(priv->adapter, INFO,
218 "info: skip to send probe resp in AP or GO mode\n");
222 pkt_len = len + ETH_ALEN;
223 skb = dev_alloc_skb(MWIFIEX_MIN_DATA_HEADER_LEN +
224 MWIFIEX_MGMT_FRAME_HEADER_SIZE +
225 pkt_len + sizeof(pkt_len));
228 mwifiex_dbg(priv->adapter, ERROR,
229 "allocate skb failed for management frame\n");
233 tx_info = MWIFIEX_SKB_TXCB(skb);
234 memset(tx_info, 0, sizeof(*tx_info));
235 tx_info->bss_num = priv->bss_num;
236 tx_info->bss_type = priv->bss_type;
237 tx_info->pkt_len = pkt_len;
239 mwifiex_form_mgmt_frame(skb, buf, len);
240 *cookie = prandom_u32() | 1;
242 if (ieee80211_is_action(mgmt->frame_control))
243 skb = mwifiex_clone_skb_for_tx_status(priv,
245 MWIFIEX_BUF_FLAG_ACTION_TX_STATUS, cookie);
247 cfg80211_mgmt_tx_status(wdev, *cookie, buf, len, true,
250 mwifiex_queue_tx_pkt(priv, skb);
252 mwifiex_dbg(priv->adapter, INFO, "info: management frame transmitted\n");
257 * CFG802.11 operation handler to register a mgmt frame.
260 mwifiex_cfg80211_mgmt_frame_register(struct wiphy *wiphy,
261 struct wireless_dev *wdev,
262 u16 frame_type, bool reg)
264 struct mwifiex_private *priv = mwifiex_netdev_get_priv(wdev->netdev);
268 mask = priv->mgmt_frame_mask | BIT(frame_type >> 4);
270 mask = priv->mgmt_frame_mask & ~BIT(frame_type >> 4);
272 if (mask != priv->mgmt_frame_mask) {
273 priv->mgmt_frame_mask = mask;
274 mwifiex_send_cmd(priv, HostCmd_CMD_MGMT_FRAME_REG,
275 HostCmd_ACT_GEN_SET, 0,
276 &priv->mgmt_frame_mask, false);
277 mwifiex_dbg(priv->adapter, INFO, "info: mgmt frame registered\n");
282 * CFG802.11 operation handler to remain on channel.
285 mwifiex_cfg80211_remain_on_channel(struct wiphy *wiphy,
286 struct wireless_dev *wdev,
287 struct ieee80211_channel *chan,
288 unsigned int duration, u64 *cookie)
290 struct mwifiex_private *priv = mwifiex_netdev_get_priv(wdev->netdev);
293 if (!chan || !cookie) {
294 mwifiex_dbg(priv->adapter, ERROR, "Invalid parameter for ROC\n");
298 if (priv->roc_cfg.cookie) {
299 mwifiex_dbg(priv->adapter, INFO,
300 "info: ongoing ROC, cookie = 0x%llx\n",
301 priv->roc_cfg.cookie);
305 ret = mwifiex_remain_on_chan_cfg(priv, HostCmd_ACT_GEN_SET, chan,
309 *cookie = prandom_u32() | 1;
310 priv->roc_cfg.cookie = *cookie;
311 priv->roc_cfg.chan = *chan;
313 cfg80211_ready_on_channel(wdev, *cookie, chan,
314 duration, GFP_ATOMIC);
316 mwifiex_dbg(priv->adapter, INFO,
317 "info: ROC, cookie = 0x%llx\n", *cookie);
324 * CFG802.11 operation handler to cancel remain on channel.
327 mwifiex_cfg80211_cancel_remain_on_channel(struct wiphy *wiphy,
328 struct wireless_dev *wdev, u64 cookie)
330 struct mwifiex_private *priv = mwifiex_netdev_get_priv(wdev->netdev);
333 if (cookie != priv->roc_cfg.cookie)
336 ret = mwifiex_remain_on_chan_cfg(priv, HostCmd_ACT_GEN_REMOVE,
337 &priv->roc_cfg.chan, 0);
340 cfg80211_remain_on_channel_expired(wdev, cookie,
344 memset(&priv->roc_cfg, 0, sizeof(struct mwifiex_roc_cfg));
346 mwifiex_dbg(priv->adapter, INFO,
347 "info: cancel ROC, cookie = 0x%llx\n", cookie);
354 * CFG802.11 operation handler to set Tx power.
357 mwifiex_cfg80211_set_tx_power(struct wiphy *wiphy,
358 struct wireless_dev *wdev,
359 enum nl80211_tx_power_setting type,
362 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
363 struct mwifiex_private *priv;
364 struct mwifiex_power_cfg power_cfg;
365 int dbm = MBM_TO_DBM(mbm);
367 if (type == NL80211_TX_POWER_FIXED) {
368 power_cfg.is_power_auto = 0;
369 power_cfg.power_level = dbm;
371 power_cfg.is_power_auto = 1;
374 priv = mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY);
376 return mwifiex_set_tx_power(priv, &power_cfg);
380 * CFG802.11 operation handler to get Tx power.
383 mwifiex_cfg80211_get_tx_power(struct wiphy *wiphy,
384 struct wireless_dev *wdev,
387 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
388 struct mwifiex_private *priv = mwifiex_get_priv(adapter,
389 MWIFIEX_BSS_ROLE_ANY);
390 int ret = mwifiex_send_cmd(priv, HostCmd_CMD_RF_TX_PWR,
391 HostCmd_ACT_GEN_GET, 0, NULL, true);
396 /* tx_power_level is set in HostCmd_CMD_RF_TX_PWR command handler */
397 *dbm = priv->tx_power_level;
403 * CFG802.11 operation handler to set Power Save option.
405 * The timeout value, if provided, is currently ignored.
408 mwifiex_cfg80211_set_power_mgmt(struct wiphy *wiphy,
409 struct net_device *dev,
410 bool enabled, int timeout)
412 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
416 mwifiex_dbg(priv->adapter, INFO,
417 "info: ignore timeout value for IEEE Power Save\n");
421 return mwifiex_drv_set_power(priv, &ps_mode);
425 * CFG802.11 operation handler to set the default network key.
428 mwifiex_cfg80211_set_default_key(struct wiphy *wiphy, struct net_device *netdev,
429 u8 key_index, bool unicast,
432 struct mwifiex_private *priv = mwifiex_netdev_get_priv(netdev);
434 /* Return if WEP key not configured */
435 if (!priv->sec_info.wep_enabled)
438 if (priv->bss_type == MWIFIEX_BSS_TYPE_UAP) {
439 priv->wep_key_curr_index = key_index;
440 } else if (mwifiex_set_encode(priv, NULL, NULL, 0, key_index,
442 mwifiex_dbg(priv->adapter, ERROR, "set default Tx key index\n");
450 * CFG802.11 operation handler to add a network key.
453 mwifiex_cfg80211_add_key(struct wiphy *wiphy, struct net_device *netdev,
454 u8 key_index, bool pairwise, const u8 *mac_addr,
455 struct key_params *params)
457 struct mwifiex_private *priv = mwifiex_netdev_get_priv(netdev);
458 struct mwifiex_wep_key *wep_key;
459 const u8 bc_mac[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
460 const u8 *peer_mac = pairwise ? mac_addr : bc_mac;
462 if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_UAP &&
463 (params->cipher == WLAN_CIPHER_SUITE_WEP40 ||
464 params->cipher == WLAN_CIPHER_SUITE_WEP104)) {
465 if (params->key && params->key_len) {
466 wep_key = &priv->wep_key[key_index];
467 memset(wep_key, 0, sizeof(struct mwifiex_wep_key));
468 memcpy(wep_key->key_material, params->key,
470 wep_key->key_index = key_index;
471 wep_key->key_length = params->key_len;
472 priv->sec_info.wep_enabled = 1;
477 if (mwifiex_set_encode(priv, params, params->key, params->key_len,
478 key_index, peer_mac, 0)) {
479 mwifiex_dbg(priv->adapter, ERROR, "crypto keys added\n");
487 * CFG802.11 operation handler to set default mgmt key.
490 mwifiex_cfg80211_set_default_mgmt_key(struct wiphy *wiphy,
491 struct net_device *netdev,
494 struct mwifiex_private *priv = mwifiex_netdev_get_priv(netdev);
495 struct mwifiex_ds_encrypt_key encrypt_key;
497 wiphy_dbg(wiphy, "set default mgmt key, key index=%d\n", key_index);
499 memset(&encrypt_key, 0, sizeof(struct mwifiex_ds_encrypt_key));
500 encrypt_key.key_len = WLAN_KEY_LEN_CCMP;
501 encrypt_key.key_index = key_index;
502 encrypt_key.is_igtk_def_key = true;
503 eth_broadcast_addr(encrypt_key.mac_addr);
505 return mwifiex_send_cmd(priv, HostCmd_CMD_802_11_KEY_MATERIAL,
506 HostCmd_ACT_GEN_SET, true, &encrypt_key, true);
510 * This function sends domain information to the firmware.
512 * The following information are passed to the firmware -
514 * - Sub bands (first channel, number of channels, maximum Tx power)
516 int mwifiex_send_domain_info_cmd_fw(struct wiphy *wiphy)
518 u8 no_of_triplet = 0;
519 struct ieee80211_country_ie_triplet *t;
520 u8 no_of_parsed_chan = 0;
521 u8 first_chan = 0, next_chan = 0, max_pwr = 0;
523 enum nl80211_band band;
524 struct ieee80211_supported_band *sband;
525 struct ieee80211_channel *ch;
526 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
527 struct mwifiex_private *priv;
528 struct mwifiex_802_11d_domain_reg *domain_info = &adapter->domain_reg;
530 /* Set country code */
531 domain_info->country_code[0] = adapter->country_code[0];
532 domain_info->country_code[1] = adapter->country_code[1];
533 domain_info->country_code[2] = ' ';
535 band = mwifiex_band_to_radio_type(adapter->config_bands);
536 if (!wiphy->bands[band]) {
537 mwifiex_dbg(adapter, ERROR,
538 "11D: setting domain info in FW\n");
542 sband = wiphy->bands[band];
544 for (i = 0; i < sband->n_channels ; i++) {
545 ch = &sband->channels[i];
546 if (ch->flags & IEEE80211_CHAN_DISABLED)
551 first_chan = (u32) ch->hw_value;
552 next_chan = first_chan;
553 max_pwr = ch->max_power;
554 no_of_parsed_chan = 1;
558 if (ch->hw_value == next_chan + 1 &&
559 ch->max_power == max_pwr) {
563 t = &domain_info->triplet[no_of_triplet];
564 t->chans.first_channel = first_chan;
565 t->chans.num_channels = no_of_parsed_chan;
566 t->chans.max_power = max_pwr;
568 first_chan = (u32) ch->hw_value;
569 next_chan = first_chan;
570 max_pwr = ch->max_power;
571 no_of_parsed_chan = 1;
576 t = &domain_info->triplet[no_of_triplet];
577 t->chans.first_channel = first_chan;
578 t->chans.num_channels = no_of_parsed_chan;
579 t->chans.max_power = max_pwr;
583 domain_info->no_of_triplet = no_of_triplet;
585 priv = mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY);
587 if (mwifiex_send_cmd(priv, HostCmd_CMD_802_11D_DOMAIN_INFO,
588 HostCmd_ACT_GEN_SET, 0, NULL, false)) {
589 mwifiex_dbg(adapter, INFO,
590 "11D: setting domain info in FW\n");
597 static void mwifiex_reg_apply_radar_flags(struct wiphy *wiphy)
599 struct ieee80211_supported_band *sband;
600 struct ieee80211_channel *chan;
603 if (!wiphy->bands[NL80211_BAND_5GHZ])
605 sband = wiphy->bands[NL80211_BAND_5GHZ];
607 for (i = 0; i < sband->n_channels; i++) {
608 chan = &sband->channels[i];
609 if ((!(chan->flags & IEEE80211_CHAN_DISABLED)) &&
610 (chan->flags & IEEE80211_CHAN_RADAR))
611 chan->flags |= IEEE80211_CHAN_NO_IR;
616 * CFG802.11 regulatory domain callback function.
618 * This function is called when the regulatory domain is changed due to the
619 * following reasons -
621 * - Set by system core
623 * - Set bt Country IE
625 static void mwifiex_reg_notifier(struct wiphy *wiphy,
626 struct regulatory_request *request)
628 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
629 struct mwifiex_private *priv = mwifiex_get_priv(adapter,
630 MWIFIEX_BSS_ROLE_ANY);
631 mwifiex_dbg(adapter, INFO,
632 "info: cfg80211 regulatory domain callback for %c%c\n",
633 request->alpha2[0], request->alpha2[1]);
634 mwifiex_reg_apply_radar_flags(wiphy);
636 switch (request->initiator) {
637 case NL80211_REGDOM_SET_BY_DRIVER:
638 case NL80211_REGDOM_SET_BY_CORE:
639 case NL80211_REGDOM_SET_BY_USER:
640 case NL80211_REGDOM_SET_BY_COUNTRY_IE:
643 mwifiex_dbg(adapter, ERROR,
644 "unknown regdom initiator: %d\n",
649 /* Don't send world or same regdom info to firmware */
650 if (strncmp(request->alpha2, "00", 2) &&
651 strncmp(request->alpha2, adapter->country_code,
652 sizeof(request->alpha2))) {
653 memcpy(adapter->country_code, request->alpha2,
654 sizeof(request->alpha2));
655 mwifiex_send_domain_info_cmd_fw(wiphy);
656 mwifiex_dnld_txpwr_table(priv);
661 * This function sets the fragmentation threshold.
663 * The fragmentation threshold value must lie between MWIFIEX_FRAG_MIN_VALUE
664 * and MWIFIEX_FRAG_MAX_VALUE.
667 mwifiex_set_frag(struct mwifiex_private *priv, u32 frag_thr)
669 if (frag_thr < MWIFIEX_FRAG_MIN_VALUE ||
670 frag_thr > MWIFIEX_FRAG_MAX_VALUE)
671 frag_thr = MWIFIEX_FRAG_MAX_VALUE;
673 return mwifiex_send_cmd(priv, HostCmd_CMD_802_11_SNMP_MIB,
674 HostCmd_ACT_GEN_SET, FRAG_THRESH_I,
679 * This function sets the RTS threshold.
681 * The rts value must lie between MWIFIEX_RTS_MIN_VALUE
682 * and MWIFIEX_RTS_MAX_VALUE.
685 mwifiex_set_rts(struct mwifiex_private *priv, u32 rts_thr)
687 if (rts_thr < MWIFIEX_RTS_MIN_VALUE || rts_thr > MWIFIEX_RTS_MAX_VALUE)
688 rts_thr = MWIFIEX_RTS_MAX_VALUE;
690 return mwifiex_send_cmd(priv, HostCmd_CMD_802_11_SNMP_MIB,
691 HostCmd_ACT_GEN_SET, RTS_THRESH_I,
696 * CFG802.11 operation handler to set wiphy parameters.
698 * This function can be used to set the RTS threshold and the
699 * Fragmentation threshold of the driver.
702 mwifiex_cfg80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
704 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
705 struct mwifiex_private *priv;
706 struct mwifiex_uap_bss_param *bss_cfg;
709 priv = mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY);
711 switch (priv->bss_role) {
712 case MWIFIEX_BSS_ROLE_UAP:
713 if (priv->bss_started) {
714 mwifiex_dbg(adapter, ERROR,
715 "cannot change wiphy params when bss started");
719 bss_cfg = kzalloc(sizeof(*bss_cfg), GFP_KERNEL);
723 mwifiex_set_sys_config_invalid_data(bss_cfg);
725 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
726 bss_cfg->rts_threshold = wiphy->rts_threshold;
727 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
728 bss_cfg->frag_threshold = wiphy->frag_threshold;
729 if (changed & WIPHY_PARAM_RETRY_LONG)
730 bss_cfg->retry_limit = wiphy->retry_long;
732 ret = mwifiex_send_cmd(priv, HostCmd_CMD_UAP_SYS_CONFIG,
734 UAP_BSS_PARAMS_I, bss_cfg,
739 mwifiex_dbg(adapter, ERROR,
740 "Failed to set wiphy phy params\n");
745 case MWIFIEX_BSS_ROLE_STA:
746 if (priv->media_connected) {
747 mwifiex_dbg(adapter, ERROR,
748 "cannot change wiphy params when connected");
751 if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
752 ret = mwifiex_set_rts(priv,
753 wiphy->rts_threshold);
757 if (changed & WIPHY_PARAM_FRAG_THRESHOLD) {
758 ret = mwifiex_set_frag(priv,
759 wiphy->frag_threshold);
770 mwifiex_cfg80211_deinit_p2p(struct mwifiex_private *priv)
772 u16 mode = P2P_MODE_DISABLE;
774 if (mwifiex_send_cmd(priv, HostCmd_CMD_P2P_MODE_CFG,
775 HostCmd_ACT_GEN_SET, 0, &mode, true))
782 * This function initializes the functionalities for P2P client.
783 * The P2P client initialization sequence is:
784 * disable -> device -> client
787 mwifiex_cfg80211_init_p2p_client(struct mwifiex_private *priv)
791 if (mwifiex_cfg80211_deinit_p2p(priv))
794 mode = P2P_MODE_DEVICE;
795 if (mwifiex_send_cmd(priv, HostCmd_CMD_P2P_MODE_CFG,
796 HostCmd_ACT_GEN_SET, 0, &mode, true))
799 mode = P2P_MODE_CLIENT;
800 if (mwifiex_send_cmd(priv, HostCmd_CMD_P2P_MODE_CFG,
801 HostCmd_ACT_GEN_SET, 0, &mode, true))
808 * This function initializes the functionalities for P2P GO.
809 * The P2P GO initialization sequence is:
810 * disable -> device -> GO
813 mwifiex_cfg80211_init_p2p_go(struct mwifiex_private *priv)
817 if (mwifiex_cfg80211_deinit_p2p(priv))
820 mode = P2P_MODE_DEVICE;
821 if (mwifiex_send_cmd(priv, HostCmd_CMD_P2P_MODE_CFG,
822 HostCmd_ACT_GEN_SET, 0, &mode, true))
826 if (mwifiex_send_cmd(priv, HostCmd_CMD_P2P_MODE_CFG,
827 HostCmd_ACT_GEN_SET, 0, &mode, true))
833 static int mwifiex_deinit_priv_params(struct mwifiex_private *priv)
835 struct mwifiex_adapter *adapter = priv->adapter;
838 priv->mgmt_frame_mask = 0;
839 if (mwifiex_send_cmd(priv, HostCmd_CMD_MGMT_FRAME_REG,
840 HostCmd_ACT_GEN_SET, 0,
841 &priv->mgmt_frame_mask, false)) {
842 mwifiex_dbg(adapter, ERROR,
843 "could not unregister mgmt frame rx\n");
847 mwifiex_deauthenticate(priv, NULL);
849 spin_lock_irqsave(&adapter->main_proc_lock, flags);
850 adapter->main_locked = true;
851 if (adapter->mwifiex_processing) {
852 spin_unlock_irqrestore(&adapter->main_proc_lock, flags);
853 flush_workqueue(adapter->workqueue);
855 spin_unlock_irqrestore(&adapter->main_proc_lock, flags);
858 spin_lock_irqsave(&adapter->rx_proc_lock, flags);
859 adapter->rx_locked = true;
860 if (adapter->rx_processing) {
861 spin_unlock_irqrestore(&adapter->rx_proc_lock, flags);
862 flush_workqueue(adapter->rx_workqueue);
864 spin_unlock_irqrestore(&adapter->rx_proc_lock, flags);
867 mwifiex_free_priv(priv);
868 priv->wdev.iftype = NL80211_IFTYPE_UNSPECIFIED;
869 priv->bss_mode = NL80211_IFTYPE_UNSPECIFIED;
870 priv->sec_info.authentication_mode = NL80211_AUTHTYPE_OPEN_SYSTEM;
876 mwifiex_init_new_priv_params(struct mwifiex_private *priv,
877 struct net_device *dev,
878 enum nl80211_iftype type)
880 struct mwifiex_adapter *adapter = priv->adapter;
883 mwifiex_init_priv(priv);
885 priv->bss_mode = type;
886 priv->wdev.iftype = type;
888 mwifiex_init_priv_params(priv, priv->netdev);
889 priv->bss_started = 0;
892 case NL80211_IFTYPE_STATION:
893 case NL80211_IFTYPE_ADHOC:
894 priv->bss_num = mwifiex_get_unused_bss_num(adapter,
895 MWIFIEX_BSS_TYPE_STA);
896 priv->bss_role = MWIFIEX_BSS_ROLE_STA;
897 priv->bss_type = MWIFIEX_BSS_TYPE_STA;
899 case NL80211_IFTYPE_P2P_CLIENT:
900 priv->bss_num = mwifiex_get_unused_bss_num(adapter,
901 MWIFIEX_BSS_TYPE_P2P);
902 priv->bss_role = MWIFIEX_BSS_ROLE_STA;
903 priv->bss_type = MWIFIEX_BSS_TYPE_P2P;
905 case NL80211_IFTYPE_P2P_GO:
906 priv->bss_num = mwifiex_get_unused_bss_num(adapter,
907 MWIFIEX_BSS_TYPE_P2P);
908 priv->bss_role = MWIFIEX_BSS_ROLE_UAP;
909 priv->bss_type = MWIFIEX_BSS_TYPE_P2P;
911 case NL80211_IFTYPE_AP:
912 priv->bss_num = mwifiex_get_unused_bss_num(adapter,
913 MWIFIEX_BSS_TYPE_UAP);
914 priv->bss_type = MWIFIEX_BSS_TYPE_UAP;
915 priv->bss_role = MWIFIEX_BSS_ROLE_UAP;
918 mwifiex_dbg(adapter, ERROR,
919 "%s: changing to %d not supported\n",
924 spin_lock_irqsave(&adapter->main_proc_lock, flags);
925 adapter->main_locked = false;
926 spin_unlock_irqrestore(&adapter->main_proc_lock, flags);
928 spin_lock_irqsave(&adapter->rx_proc_lock, flags);
929 adapter->rx_locked = false;
930 spin_unlock_irqrestore(&adapter->rx_proc_lock, flags);
936 mwifiex_change_vif_to_p2p(struct net_device *dev,
937 enum nl80211_iftype curr_iftype,
938 enum nl80211_iftype type,
939 struct vif_params *params)
941 struct mwifiex_private *priv;
942 struct mwifiex_adapter *adapter;
944 priv = mwifiex_netdev_get_priv(dev);
949 adapter = priv->adapter;
951 if (adapter->curr_iface_comb.p2p_intf ==
952 adapter->iface_limit.p2p_intf) {
953 mwifiex_dbg(adapter, ERROR,
954 "cannot create multiple P2P ifaces\n");
958 mwifiex_dbg(adapter, INFO,
959 "%s: changing role to p2p\n", dev->name);
961 if (mwifiex_deinit_priv_params(priv))
963 if (mwifiex_init_new_priv_params(priv, dev, type))
967 case NL80211_IFTYPE_P2P_CLIENT:
968 if (mwifiex_cfg80211_init_p2p_client(priv))
971 case NL80211_IFTYPE_P2P_GO:
972 if (mwifiex_cfg80211_init_p2p_go(priv))
976 mwifiex_dbg(adapter, ERROR,
977 "%s: changing to %d not supported\n",
982 if (mwifiex_send_cmd(priv, HostCmd_CMD_SET_BSS_MODE,
983 HostCmd_ACT_GEN_SET, 0, NULL, true))
986 if (mwifiex_sta_init_cmd(priv, false, false))
989 switch (curr_iftype) {
990 case NL80211_IFTYPE_STATION:
991 case NL80211_IFTYPE_ADHOC:
992 adapter->curr_iface_comb.sta_intf--;
994 case NL80211_IFTYPE_AP:
995 adapter->curr_iface_comb.uap_intf--;
1001 adapter->curr_iface_comb.p2p_intf++;
1002 dev->ieee80211_ptr->iftype = type;
1008 mwifiex_change_vif_to_sta_adhoc(struct net_device *dev,
1009 enum nl80211_iftype curr_iftype,
1010 enum nl80211_iftype type,
1011 struct vif_params *params)
1013 struct mwifiex_private *priv;
1014 struct mwifiex_adapter *adapter;
1016 priv = mwifiex_netdev_get_priv(dev);
1021 adapter = priv->adapter;
1023 if ((curr_iftype != NL80211_IFTYPE_P2P_CLIENT &&
1024 curr_iftype != NL80211_IFTYPE_P2P_GO) &&
1025 (adapter->curr_iface_comb.sta_intf ==
1026 adapter->iface_limit.sta_intf)) {
1027 mwifiex_dbg(adapter, ERROR,
1028 "cannot create multiple station/adhoc ifaces\n");
1032 if (type == NL80211_IFTYPE_STATION)
1033 mwifiex_dbg(adapter, INFO,
1034 "%s: changing role to station\n", dev->name);
1036 mwifiex_dbg(adapter, INFO,
1037 "%s: changing role to adhoc\n", dev->name);
1039 if (mwifiex_deinit_priv_params(priv))
1041 if (mwifiex_init_new_priv_params(priv, dev, type))
1043 if (mwifiex_send_cmd(priv, HostCmd_CMD_SET_BSS_MODE,
1044 HostCmd_ACT_GEN_SET, 0, NULL, true))
1046 if (mwifiex_sta_init_cmd(priv, false, false))
1049 switch (curr_iftype) {
1050 case NL80211_IFTYPE_P2P_CLIENT:
1051 case NL80211_IFTYPE_P2P_GO:
1052 adapter->curr_iface_comb.p2p_intf--;
1054 case NL80211_IFTYPE_AP:
1055 adapter->curr_iface_comb.uap_intf--;
1061 adapter->curr_iface_comb.sta_intf++;
1062 dev->ieee80211_ptr->iftype = type;
1067 mwifiex_change_vif_to_ap(struct net_device *dev,
1068 enum nl80211_iftype curr_iftype,
1069 enum nl80211_iftype type,
1070 struct vif_params *params)
1072 struct mwifiex_private *priv;
1073 struct mwifiex_adapter *adapter;
1075 priv = mwifiex_netdev_get_priv(dev);
1080 adapter = priv->adapter;
1082 if (adapter->curr_iface_comb.uap_intf ==
1083 adapter->iface_limit.uap_intf) {
1084 mwifiex_dbg(adapter, ERROR,
1085 "cannot create multiple AP ifaces\n");
1089 mwifiex_dbg(adapter, INFO,
1090 "%s: changing role to AP\n", dev->name);
1092 if (mwifiex_deinit_priv_params(priv))
1094 if (mwifiex_init_new_priv_params(priv, dev, type))
1096 if (mwifiex_send_cmd(priv, HostCmd_CMD_SET_BSS_MODE,
1097 HostCmd_ACT_GEN_SET, 0, NULL, true))
1099 if (mwifiex_sta_init_cmd(priv, false, false))
1102 switch (curr_iftype) {
1103 case NL80211_IFTYPE_P2P_CLIENT:
1104 case NL80211_IFTYPE_P2P_GO:
1105 adapter->curr_iface_comb.p2p_intf--;
1107 case NL80211_IFTYPE_STATION:
1108 case NL80211_IFTYPE_ADHOC:
1109 adapter->curr_iface_comb.sta_intf--;
1115 adapter->curr_iface_comb.uap_intf++;
1116 dev->ieee80211_ptr->iftype = type;
1120 * CFG802.11 operation handler to change interface type.
1123 mwifiex_cfg80211_change_virtual_intf(struct wiphy *wiphy,
1124 struct net_device *dev,
1125 enum nl80211_iftype type,
1126 struct vif_params *params)
1128 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
1129 enum nl80211_iftype curr_iftype = dev->ieee80211_ptr->iftype;
1131 switch (curr_iftype) {
1132 case NL80211_IFTYPE_ADHOC:
1134 case NL80211_IFTYPE_STATION:
1135 priv->bss_mode = type;
1136 priv->sec_info.authentication_mode =
1137 NL80211_AUTHTYPE_OPEN_SYSTEM;
1138 dev->ieee80211_ptr->iftype = type;
1139 mwifiex_deauthenticate(priv, NULL);
1140 return mwifiex_send_cmd(priv, HostCmd_CMD_SET_BSS_MODE,
1141 HostCmd_ACT_GEN_SET, 0, NULL,
1143 case NL80211_IFTYPE_P2P_CLIENT:
1144 case NL80211_IFTYPE_P2P_GO:
1145 return mwifiex_change_vif_to_p2p(dev, curr_iftype,
1147 case NL80211_IFTYPE_AP:
1148 return mwifiex_change_vif_to_ap(dev, curr_iftype, type,
1150 case NL80211_IFTYPE_UNSPECIFIED:
1151 mwifiex_dbg(priv->adapter, INFO,
1152 "%s: kept type as IBSS\n", dev->name);
1153 case NL80211_IFTYPE_ADHOC: /* This shouldn't happen */
1156 mwifiex_dbg(priv->adapter, ERROR,
1157 "%s: changing to %d not supported\n",
1162 case NL80211_IFTYPE_STATION:
1164 case NL80211_IFTYPE_ADHOC:
1165 priv->bss_mode = type;
1166 priv->sec_info.authentication_mode =
1167 NL80211_AUTHTYPE_OPEN_SYSTEM;
1168 dev->ieee80211_ptr->iftype = type;
1169 mwifiex_deauthenticate(priv, NULL);
1170 return mwifiex_send_cmd(priv, HostCmd_CMD_SET_BSS_MODE,
1171 HostCmd_ACT_GEN_SET, 0, NULL,
1173 case NL80211_IFTYPE_P2P_CLIENT:
1174 case NL80211_IFTYPE_P2P_GO:
1175 return mwifiex_change_vif_to_p2p(dev, curr_iftype,
1177 case NL80211_IFTYPE_AP:
1178 return mwifiex_change_vif_to_ap(dev, curr_iftype, type,
1180 case NL80211_IFTYPE_UNSPECIFIED:
1181 mwifiex_dbg(priv->adapter, INFO,
1182 "%s: kept type as STA\n", dev->name);
1183 case NL80211_IFTYPE_STATION: /* This shouldn't happen */
1186 mwifiex_dbg(priv->adapter, ERROR,
1187 "%s: changing to %d not supported\n",
1192 case NL80211_IFTYPE_AP:
1194 case NL80211_IFTYPE_ADHOC:
1195 case NL80211_IFTYPE_STATION:
1196 return mwifiex_change_vif_to_sta_adhoc(dev, curr_iftype,
1199 case NL80211_IFTYPE_P2P_CLIENT:
1200 case NL80211_IFTYPE_P2P_GO:
1201 return mwifiex_change_vif_to_p2p(dev, curr_iftype,
1203 case NL80211_IFTYPE_UNSPECIFIED:
1204 mwifiex_dbg(priv->adapter, INFO,
1205 "%s: kept type as AP\n", dev->name);
1206 case NL80211_IFTYPE_AP: /* This shouldn't happen */
1209 mwifiex_dbg(priv->adapter, ERROR,
1210 "%s: changing to %d not supported\n",
1215 case NL80211_IFTYPE_P2P_CLIENT:
1216 case NL80211_IFTYPE_P2P_GO:
1218 case NL80211_IFTYPE_STATION:
1219 if (mwifiex_cfg80211_deinit_p2p(priv))
1221 priv->adapter->curr_iface_comb.p2p_intf--;
1222 priv->adapter->curr_iface_comb.sta_intf++;
1223 dev->ieee80211_ptr->iftype = type;
1224 if (mwifiex_deinit_priv_params(priv))
1226 if (mwifiex_init_new_priv_params(priv, dev, type))
1228 if (mwifiex_sta_init_cmd(priv, false, false))
1231 case NL80211_IFTYPE_ADHOC:
1232 if (mwifiex_cfg80211_deinit_p2p(priv))
1234 return mwifiex_change_vif_to_sta_adhoc(dev, curr_iftype,
1237 case NL80211_IFTYPE_AP:
1238 if (mwifiex_cfg80211_deinit_p2p(priv))
1240 return mwifiex_change_vif_to_ap(dev, curr_iftype, type,
1242 case NL80211_IFTYPE_UNSPECIFIED:
1243 mwifiex_dbg(priv->adapter, INFO,
1244 "%s: kept type as P2P\n", dev->name);
1245 case NL80211_IFTYPE_P2P_CLIENT:
1246 case NL80211_IFTYPE_P2P_GO:
1249 mwifiex_dbg(priv->adapter, ERROR,
1250 "%s: changing to %d not supported\n",
1256 mwifiex_dbg(priv->adapter, ERROR,
1257 "%s: unknown iftype: %d\n",
1258 dev->name, dev->ieee80211_ptr->iftype);
1267 mwifiex_parse_htinfo(struct mwifiex_private *priv, u8 tx_htinfo,
1268 struct rate_info *rate)
1270 struct mwifiex_adapter *adapter = priv->adapter;
1272 if (adapter->is_hw_11ac_capable) {
1273 /* bit[1-0]: 00=LG 01=HT 10=VHT */
1274 if (tx_htinfo & BIT(0)) {
1276 rate->mcs = priv->tx_rate;
1277 rate->flags |= RATE_INFO_FLAGS_MCS;
1279 if (tx_htinfo & BIT(1)) {
1281 rate->mcs = priv->tx_rate & 0x0F;
1282 rate->flags |= RATE_INFO_FLAGS_VHT_MCS;
1285 if (tx_htinfo & (BIT(1) | BIT(0))) {
1287 switch (tx_htinfo & (BIT(3) | BIT(2))) {
1289 rate->bw = RATE_INFO_BW_20;
1292 rate->bw = RATE_INFO_BW_40;
1295 rate->bw = RATE_INFO_BW_80;
1297 case (BIT(3) | BIT(2)):
1298 rate->bw = RATE_INFO_BW_160;
1302 if (tx_htinfo & BIT(4))
1303 rate->flags |= RATE_INFO_FLAGS_SHORT_GI;
1305 if ((priv->tx_rate >> 4) == 1)
1312 * Bit 0 in tx_htinfo indicates that current Tx rate
1313 * is 11n rate. Valid MCS index values for us are 0 to 15.
1315 if ((tx_htinfo & BIT(0)) && (priv->tx_rate < 16)) {
1316 rate->mcs = priv->tx_rate;
1317 rate->flags |= RATE_INFO_FLAGS_MCS;
1318 rate->bw = RATE_INFO_BW_20;
1319 if (tx_htinfo & BIT(1))
1320 rate->bw = RATE_INFO_BW_40;
1321 if (tx_htinfo & BIT(2))
1322 rate->flags |= RATE_INFO_FLAGS_SHORT_GI;
1328 * This function dumps the station information on a buffer.
1330 * The following information are shown -
1331 * - Total bytes transmitted
1332 * - Total bytes received
1333 * - Total packets transmitted
1334 * - Total packets received
1335 * - Signal quality level
1336 * - Transmission rate
1339 mwifiex_dump_station_info(struct mwifiex_private *priv,
1340 struct mwifiex_sta_node *node,
1341 struct station_info *sinfo)
1345 sinfo->filled = BIT(NL80211_STA_INFO_RX_BYTES) | BIT(NL80211_STA_INFO_TX_BYTES) |
1346 BIT(NL80211_STA_INFO_RX_PACKETS) | BIT(NL80211_STA_INFO_TX_PACKETS) |
1347 BIT(NL80211_STA_INFO_TX_BITRATE) |
1348 BIT(NL80211_STA_INFO_SIGNAL) | BIT(NL80211_STA_INFO_SIGNAL_AVG);
1350 if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_UAP) {
1354 sinfo->filled |= BIT(NL80211_STA_INFO_INACTIVE_TIME) |
1355 BIT(NL80211_STA_INFO_TX_FAILED);
1356 sinfo->inactive_time =
1357 jiffies_to_msecs(jiffies - node->stats.last_rx);
1359 sinfo->signal = node->stats.rssi;
1360 sinfo->signal_avg = node->stats.rssi;
1361 sinfo->rx_bytes = node->stats.rx_bytes;
1362 sinfo->tx_bytes = node->stats.tx_bytes;
1363 sinfo->rx_packets = node->stats.rx_packets;
1364 sinfo->tx_packets = node->stats.tx_packets;
1365 sinfo->tx_failed = node->stats.tx_failed;
1367 mwifiex_parse_htinfo(priv, node->stats.last_tx_htinfo,
1369 sinfo->txrate.legacy = node->stats.last_tx_rate * 5;
1374 /* Get signal information from the firmware */
1375 if (mwifiex_send_cmd(priv, HostCmd_CMD_RSSI_INFO,
1376 HostCmd_ACT_GEN_GET, 0, NULL, true)) {
1377 mwifiex_dbg(priv->adapter, ERROR,
1378 "failed to get signal information\n");
1382 if (mwifiex_drv_get_data_rate(priv, &rate)) {
1383 mwifiex_dbg(priv->adapter, ERROR,
1384 "getting data rate error\n");
1388 /* Get DTIM period information from firmware */
1389 mwifiex_send_cmd(priv, HostCmd_CMD_802_11_SNMP_MIB,
1390 HostCmd_ACT_GEN_GET, DTIM_PERIOD_I,
1391 &priv->dtim_period, true);
1393 mwifiex_parse_htinfo(priv, priv->tx_htinfo, &sinfo->txrate);
1395 sinfo->signal_avg = priv->bcn_rssi_avg;
1396 sinfo->rx_bytes = priv->stats.rx_bytes;
1397 sinfo->tx_bytes = priv->stats.tx_bytes;
1398 sinfo->rx_packets = priv->stats.rx_packets;
1399 sinfo->tx_packets = priv->stats.tx_packets;
1400 sinfo->signal = priv->bcn_rssi_avg;
1401 /* bit rate is in 500 kb/s units. Convert it to 100kb/s units */
1402 sinfo->txrate.legacy = rate * 5;
1404 if (priv->bss_mode == NL80211_IFTYPE_STATION) {
1405 sinfo->filled |= BIT(NL80211_STA_INFO_BSS_PARAM);
1406 sinfo->bss_param.flags = 0;
1407 if (priv->curr_bss_params.bss_descriptor.cap_info_bitmap &
1408 WLAN_CAPABILITY_SHORT_PREAMBLE)
1409 sinfo->bss_param.flags |=
1410 BSS_PARAM_FLAGS_SHORT_PREAMBLE;
1411 if (priv->curr_bss_params.bss_descriptor.cap_info_bitmap &
1412 WLAN_CAPABILITY_SHORT_SLOT_TIME)
1413 sinfo->bss_param.flags |=
1414 BSS_PARAM_FLAGS_SHORT_SLOT_TIME;
1415 sinfo->bss_param.dtim_period = priv->dtim_period;
1416 sinfo->bss_param.beacon_interval =
1417 priv->curr_bss_params.bss_descriptor.beacon_period;
1424 * CFG802.11 operation handler to get station information.
1426 * This function only works in connected mode, and dumps the
1427 * requested station information, if available.
1430 mwifiex_cfg80211_get_station(struct wiphy *wiphy, struct net_device *dev,
1431 const u8 *mac, struct station_info *sinfo)
1433 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
1435 if (!priv->media_connected)
1437 if (memcmp(mac, priv->cfg_bssid, ETH_ALEN))
1440 return mwifiex_dump_station_info(priv, NULL, sinfo);
1444 * CFG802.11 operation handler to dump station information.
1447 mwifiex_cfg80211_dump_station(struct wiphy *wiphy, struct net_device *dev,
1448 int idx, u8 *mac, struct station_info *sinfo)
1450 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
1451 static struct mwifiex_sta_node *node;
1453 if ((GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA) &&
1454 priv->media_connected && idx == 0) {
1455 ether_addr_copy(mac, priv->cfg_bssid);
1456 return mwifiex_dump_station_info(priv, NULL, sinfo);
1457 } else if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_UAP) {
1458 mwifiex_send_cmd(priv, HOST_CMD_APCMD_STA_LIST,
1459 HostCmd_ACT_GEN_GET, 0, NULL, true);
1461 if (node && (&node->list == &priv->sta_list)) {
1466 node = list_prepare_entry(node, &priv->sta_list, list);
1467 list_for_each_entry_continue(node, &priv->sta_list, list) {
1468 ether_addr_copy(mac, node->mac_addr);
1469 return mwifiex_dump_station_info(priv, node, sinfo);
1477 mwifiex_cfg80211_dump_survey(struct wiphy *wiphy, struct net_device *dev,
1478 int idx, struct survey_info *survey)
1480 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
1481 struct mwifiex_chan_stats *pchan_stats = priv->adapter->chan_stats;
1482 enum nl80211_band band;
1484 mwifiex_dbg(priv->adapter, DUMP, "dump_survey idx=%d\n", idx);
1486 memset(survey, 0, sizeof(struct survey_info));
1488 if ((GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA) &&
1489 priv->media_connected && idx == 0) {
1490 u8 curr_bss_band = priv->curr_bss_params.band;
1491 u32 chan = priv->curr_bss_params.bss_descriptor.channel;
1493 band = mwifiex_band_to_radio_type(curr_bss_band);
1494 survey->channel = ieee80211_get_channel(wiphy,
1495 ieee80211_channel_to_frequency(chan, band));
1497 if (priv->bcn_nf_last) {
1498 survey->filled = SURVEY_INFO_NOISE_DBM;
1499 survey->noise = priv->bcn_nf_last;
1504 if (idx >= priv->adapter->num_in_chan_stats)
1507 if (!pchan_stats[idx].cca_scan_dur)
1510 band = pchan_stats[idx].bandcfg;
1511 survey->channel = ieee80211_get_channel(wiphy,
1512 ieee80211_channel_to_frequency(pchan_stats[idx].chan_num, band));
1513 survey->filled = SURVEY_INFO_NOISE_DBM |
1515 SURVEY_INFO_TIME_BUSY;
1516 survey->noise = pchan_stats[idx].noise;
1517 survey->time = pchan_stats[idx].cca_scan_dur;
1518 survey->time_busy = pchan_stats[idx].cca_busy_dur;
1523 /* Supported rates to be advertised to the cfg80211 */
1524 static struct ieee80211_rate mwifiex_rates[] = {
1525 {.bitrate = 10, .hw_value = 2, },
1526 {.bitrate = 20, .hw_value = 4, },
1527 {.bitrate = 55, .hw_value = 11, },
1528 {.bitrate = 110, .hw_value = 22, },
1529 {.bitrate = 60, .hw_value = 12, },
1530 {.bitrate = 90, .hw_value = 18, },
1531 {.bitrate = 120, .hw_value = 24, },
1532 {.bitrate = 180, .hw_value = 36, },
1533 {.bitrate = 240, .hw_value = 48, },
1534 {.bitrate = 360, .hw_value = 72, },
1535 {.bitrate = 480, .hw_value = 96, },
1536 {.bitrate = 540, .hw_value = 108, },
1539 /* Channel definitions to be advertised to cfg80211 */
1540 static struct ieee80211_channel mwifiex_channels_2ghz[] = {
1541 {.center_freq = 2412, .hw_value = 1, },
1542 {.center_freq = 2417, .hw_value = 2, },
1543 {.center_freq = 2422, .hw_value = 3, },
1544 {.center_freq = 2427, .hw_value = 4, },
1545 {.center_freq = 2432, .hw_value = 5, },
1546 {.center_freq = 2437, .hw_value = 6, },
1547 {.center_freq = 2442, .hw_value = 7, },
1548 {.center_freq = 2447, .hw_value = 8, },
1549 {.center_freq = 2452, .hw_value = 9, },
1550 {.center_freq = 2457, .hw_value = 10, },
1551 {.center_freq = 2462, .hw_value = 11, },
1552 {.center_freq = 2467, .hw_value = 12, },
1553 {.center_freq = 2472, .hw_value = 13, },
1554 {.center_freq = 2484, .hw_value = 14, },
1557 static struct ieee80211_supported_band mwifiex_band_2ghz = {
1558 .channels = mwifiex_channels_2ghz,
1559 .n_channels = ARRAY_SIZE(mwifiex_channels_2ghz),
1560 .bitrates = mwifiex_rates,
1561 .n_bitrates = ARRAY_SIZE(mwifiex_rates),
1564 static struct ieee80211_channel mwifiex_channels_5ghz[] = {
1565 {.center_freq = 5040, .hw_value = 8, },
1566 {.center_freq = 5060, .hw_value = 12, },
1567 {.center_freq = 5080, .hw_value = 16, },
1568 {.center_freq = 5170, .hw_value = 34, },
1569 {.center_freq = 5190, .hw_value = 38, },
1570 {.center_freq = 5210, .hw_value = 42, },
1571 {.center_freq = 5230, .hw_value = 46, },
1572 {.center_freq = 5180, .hw_value = 36, },
1573 {.center_freq = 5200, .hw_value = 40, },
1574 {.center_freq = 5220, .hw_value = 44, },
1575 {.center_freq = 5240, .hw_value = 48, },
1576 {.center_freq = 5260, .hw_value = 52, },
1577 {.center_freq = 5280, .hw_value = 56, },
1578 {.center_freq = 5300, .hw_value = 60, },
1579 {.center_freq = 5320, .hw_value = 64, },
1580 {.center_freq = 5500, .hw_value = 100, },
1581 {.center_freq = 5520, .hw_value = 104, },
1582 {.center_freq = 5540, .hw_value = 108, },
1583 {.center_freq = 5560, .hw_value = 112, },
1584 {.center_freq = 5580, .hw_value = 116, },
1585 {.center_freq = 5600, .hw_value = 120, },
1586 {.center_freq = 5620, .hw_value = 124, },
1587 {.center_freq = 5640, .hw_value = 128, },
1588 {.center_freq = 5660, .hw_value = 132, },
1589 {.center_freq = 5680, .hw_value = 136, },
1590 {.center_freq = 5700, .hw_value = 140, },
1591 {.center_freq = 5745, .hw_value = 149, },
1592 {.center_freq = 5765, .hw_value = 153, },
1593 {.center_freq = 5785, .hw_value = 157, },
1594 {.center_freq = 5805, .hw_value = 161, },
1595 {.center_freq = 5825, .hw_value = 165, },
1598 static struct ieee80211_supported_band mwifiex_band_5ghz = {
1599 .channels = mwifiex_channels_5ghz,
1600 .n_channels = ARRAY_SIZE(mwifiex_channels_5ghz),
1601 .bitrates = mwifiex_rates + 4,
1602 .n_bitrates = ARRAY_SIZE(mwifiex_rates) - 4,
1606 /* Supported crypto cipher suits to be advertised to cfg80211 */
1607 static const u32 mwifiex_cipher_suites[] = {
1608 WLAN_CIPHER_SUITE_WEP40,
1609 WLAN_CIPHER_SUITE_WEP104,
1610 WLAN_CIPHER_SUITE_TKIP,
1611 WLAN_CIPHER_SUITE_CCMP,
1612 WLAN_CIPHER_SUITE_SMS4,
1613 WLAN_CIPHER_SUITE_AES_CMAC,
1616 /* Supported mgmt frame types to be advertised to cfg80211 */
1617 static const struct ieee80211_txrx_stypes
1618 mwifiex_mgmt_stypes[NUM_NL80211_IFTYPES] = {
1619 [NL80211_IFTYPE_STATION] = {
1620 .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
1621 BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
1622 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
1623 BIT(IEEE80211_STYPE_PROBE_REQ >> 4),
1625 [NL80211_IFTYPE_AP] = {
1626 .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
1627 BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
1628 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
1629 BIT(IEEE80211_STYPE_PROBE_REQ >> 4),
1631 [NL80211_IFTYPE_P2P_CLIENT] = {
1632 .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
1633 BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
1634 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
1635 BIT(IEEE80211_STYPE_PROBE_REQ >> 4),
1637 [NL80211_IFTYPE_P2P_GO] = {
1638 .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
1639 BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
1640 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
1641 BIT(IEEE80211_STYPE_PROBE_REQ >> 4),
1646 * CFG802.11 operation handler for setting bit rates.
1648 * Function configures data rates to firmware using bitrate mask
1649 * provided by cfg80211.
1651 static int mwifiex_cfg80211_set_bitrate_mask(struct wiphy *wiphy,
1652 struct net_device *dev,
1654 const struct cfg80211_bitrate_mask *mask)
1656 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
1657 u16 bitmap_rates[MAX_BITMAP_RATES_SIZE];
1658 enum nl80211_band band;
1659 struct mwifiex_adapter *adapter = priv->adapter;
1661 if (!priv->media_connected) {
1662 mwifiex_dbg(adapter, ERROR,
1663 "Can not set Tx data rate in disconnected state\n");
1667 band = mwifiex_band_to_radio_type(priv->curr_bss_params.band);
1669 memset(bitmap_rates, 0, sizeof(bitmap_rates));
1671 /* Fill HR/DSSS rates. */
1672 if (band == NL80211_BAND_2GHZ)
1673 bitmap_rates[0] = mask->control[band].legacy & 0x000f;
1675 /* Fill OFDM rates */
1676 if (band == NL80211_BAND_2GHZ)
1677 bitmap_rates[1] = (mask->control[band].legacy & 0x0ff0) >> 4;
1679 bitmap_rates[1] = mask->control[band].legacy;
1681 /* Fill HT MCS rates */
1682 bitmap_rates[2] = mask->control[band].ht_mcs[0];
1683 if (adapter->hw_dev_mcs_support == HT_STREAM_2X2)
1684 bitmap_rates[2] |= mask->control[band].ht_mcs[1] << 8;
1686 /* Fill VHT MCS rates */
1687 if (adapter->fw_api_ver == MWIFIEX_FW_V15) {
1688 bitmap_rates[10] = mask->control[band].vht_mcs[0];
1689 if (adapter->hw_dev_mcs_support == HT_STREAM_2X2)
1690 bitmap_rates[11] = mask->control[band].vht_mcs[1];
1693 return mwifiex_send_cmd(priv, HostCmd_CMD_TX_RATE_CFG,
1694 HostCmd_ACT_GEN_SET, 0, bitmap_rates, true);
1698 * CFG802.11 operation handler for connection quality monitoring.
1700 * This function subscribes/unsubscribes HIGH_RSSI and LOW_RSSI
1703 static int mwifiex_cfg80211_set_cqm_rssi_config(struct wiphy *wiphy,
1704 struct net_device *dev,
1705 s32 rssi_thold, u32 rssi_hyst)
1707 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
1708 struct mwifiex_ds_misc_subsc_evt subsc_evt;
1710 priv->cqm_rssi_thold = rssi_thold;
1711 priv->cqm_rssi_hyst = rssi_hyst;
1713 memset(&subsc_evt, 0x00, sizeof(struct mwifiex_ds_misc_subsc_evt));
1714 subsc_evt.events = BITMASK_BCN_RSSI_LOW | BITMASK_BCN_RSSI_HIGH;
1716 /* Subscribe/unsubscribe low and high rssi events */
1717 if (rssi_thold && rssi_hyst) {
1718 subsc_evt.action = HostCmd_ACT_BITWISE_SET;
1719 subsc_evt.bcn_l_rssi_cfg.abs_value = abs(rssi_thold);
1720 subsc_evt.bcn_h_rssi_cfg.abs_value = abs(rssi_thold);
1721 subsc_evt.bcn_l_rssi_cfg.evt_freq = 1;
1722 subsc_evt.bcn_h_rssi_cfg.evt_freq = 1;
1723 return mwifiex_send_cmd(priv,
1724 HostCmd_CMD_802_11_SUBSCRIBE_EVENT,
1725 0, 0, &subsc_evt, true);
1727 subsc_evt.action = HostCmd_ACT_BITWISE_CLR;
1728 return mwifiex_send_cmd(priv,
1729 HostCmd_CMD_802_11_SUBSCRIBE_EVENT,
1730 0, 0, &subsc_evt, true);
1736 /* cfg80211 operation handler for change_beacon.
1737 * Function retrieves and sets modified management IEs to FW.
1739 static int mwifiex_cfg80211_change_beacon(struct wiphy *wiphy,
1740 struct net_device *dev,
1741 struct cfg80211_beacon_data *data)
1743 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
1744 struct mwifiex_adapter *adapter = priv->adapter;
1746 mwifiex_cancel_scan(adapter);
1748 if (GET_BSS_ROLE(priv) != MWIFIEX_BSS_ROLE_UAP) {
1749 mwifiex_dbg(priv->adapter, ERROR,
1750 "%s: bss_type mismatched\n", __func__);
1754 if (!priv->bss_started) {
1755 mwifiex_dbg(priv->adapter, ERROR,
1756 "%s: bss not started\n", __func__);
1760 if (mwifiex_set_mgmt_ies(priv, data)) {
1761 mwifiex_dbg(priv->adapter, ERROR,
1762 "%s: setting mgmt ies failed\n", __func__);
1769 /* cfg80211 operation handler for del_station.
1770 * Function deauthenticates station which value is provided in mac parameter.
1771 * If mac is NULL/broadcast, all stations in associated station list are
1772 * deauthenticated. If bss is not started or there are no stations in
1773 * associated stations list, no action is taken.
1776 mwifiex_cfg80211_del_station(struct wiphy *wiphy, struct net_device *dev,
1777 struct station_del_parameters *params)
1779 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
1780 struct mwifiex_sta_node *sta_node;
1781 u8 deauth_mac[ETH_ALEN];
1782 unsigned long flags;
1784 if (!priv->bss_started && priv->wdev.cac_started) {
1785 mwifiex_dbg(priv->adapter, INFO, "%s: abort CAC!\n", __func__);
1786 mwifiex_abort_cac(priv);
1789 if (list_empty(&priv->sta_list) || !priv->bss_started)
1792 if (!params->mac || is_broadcast_ether_addr(params->mac))
1795 mwifiex_dbg(priv->adapter, INFO, "%s: mac address %pM\n",
1796 __func__, params->mac);
1798 eth_zero_addr(deauth_mac);
1800 spin_lock_irqsave(&priv->sta_list_spinlock, flags);
1801 sta_node = mwifiex_get_sta_entry(priv, params->mac);
1803 ether_addr_copy(deauth_mac, params->mac);
1804 spin_unlock_irqrestore(&priv->sta_list_spinlock, flags);
1806 if (is_valid_ether_addr(deauth_mac)) {
1807 if (mwifiex_send_cmd(priv, HostCmd_CMD_UAP_STA_DEAUTH,
1808 HostCmd_ACT_GEN_SET, 0,
1817 mwifiex_cfg80211_set_antenna(struct wiphy *wiphy, u32 tx_ant, u32 rx_ant)
1819 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
1820 struct mwifiex_private *priv = mwifiex_get_priv(adapter,
1821 MWIFIEX_BSS_ROLE_ANY);
1822 struct mwifiex_ds_ant_cfg ant_cfg;
1824 if (!tx_ant || !rx_ant)
1827 if (adapter->hw_dev_mcs_support != HT_STREAM_2X2) {
1828 /* Not a MIMO chip. User should provide specific antenna number
1829 * for Tx/Rx path or enable all antennas for diversity
1831 if (tx_ant != rx_ant)
1834 if ((tx_ant & (tx_ant - 1)) &&
1835 (tx_ant != BIT(adapter->number_of_antenna) - 1))
1838 if ((tx_ant == BIT(adapter->number_of_antenna) - 1) &&
1839 (priv->adapter->number_of_antenna > 1)) {
1840 tx_ant = RF_ANTENNA_AUTO;
1841 rx_ant = RF_ANTENNA_AUTO;
1844 struct ieee80211_sta_ht_cap *ht_info;
1846 enum nl80211_band band;
1848 if ((tx_ant == 0x1 && rx_ant == 0x1)) {
1849 adapter->user_dev_mcs_support = HT_STREAM_1X1;
1850 if (adapter->is_hw_11ac_capable)
1851 adapter->usr_dot_11ac_mcs_support =
1852 MWIFIEX_11AC_MCS_MAP_1X1;
1854 adapter->user_dev_mcs_support = HT_STREAM_2X2;
1855 if (adapter->is_hw_11ac_capable)
1856 adapter->usr_dot_11ac_mcs_support =
1857 MWIFIEX_11AC_MCS_MAP_2X2;
1860 for (band = 0; band < NUM_NL80211_BANDS; band++) {
1861 if (!adapter->wiphy->bands[band])
1864 ht_info = &adapter->wiphy->bands[band]->ht_cap;
1866 GET_RXMCSSUPP(adapter->user_dev_mcs_support);
1867 memset(&ht_info->mcs, 0, adapter->number_of_antenna);
1868 memset(&ht_info->mcs, 0xff, rx_mcs_supp);
1872 ant_cfg.tx_ant = tx_ant;
1873 ant_cfg.rx_ant = rx_ant;
1875 return mwifiex_send_cmd(priv, HostCmd_CMD_RF_ANTENNA,
1876 HostCmd_ACT_GEN_SET, 0, &ant_cfg, true);
1880 mwifiex_cfg80211_get_antenna(struct wiphy *wiphy, u32 *tx_ant, u32 *rx_ant)
1882 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
1883 struct mwifiex_private *priv = mwifiex_get_priv(adapter,
1884 MWIFIEX_BSS_ROLE_ANY);
1885 mwifiex_send_cmd(priv, HostCmd_CMD_RF_ANTENNA,
1886 HostCmd_ACT_GEN_GET, 0, NULL, true);
1888 *tx_ant = priv->tx_ant;
1889 *rx_ant = priv->rx_ant;
1894 /* cfg80211 operation handler for stop ap.
1895 * Function stops BSS running at uAP interface.
1897 static int mwifiex_cfg80211_stop_ap(struct wiphy *wiphy, struct net_device *dev)
1899 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
1901 mwifiex_abort_cac(priv);
1903 if (mwifiex_del_mgmt_ies(priv))
1904 mwifiex_dbg(priv->adapter, ERROR,
1905 "Failed to delete mgmt IEs!\n");
1907 priv->ap_11n_enabled = 0;
1908 memset(&priv->bss_cfg, 0, sizeof(priv->bss_cfg));
1910 if (mwifiex_send_cmd(priv, HostCmd_CMD_UAP_BSS_STOP,
1911 HostCmd_ACT_GEN_SET, 0, NULL, true)) {
1912 mwifiex_dbg(priv->adapter, ERROR,
1913 "Failed to stop the BSS\n");
1917 if (mwifiex_send_cmd(priv, HOST_CMD_APCMD_SYS_RESET,
1918 HostCmd_ACT_GEN_SET, 0, NULL, true)) {
1919 mwifiex_dbg(priv->adapter, ERROR,
1920 "Failed to reset BSS\n");
1924 if (netif_carrier_ok(priv->netdev))
1925 netif_carrier_off(priv->netdev);
1926 mwifiex_stop_net_dev_queue(priv->netdev, priv->adapter);
1931 /* cfg80211 operation handler for start_ap.
1932 * Function sets beacon period, DTIM period, SSID and security into
1933 * AP config structure.
1934 * AP is configured with these settings and BSS is started.
1936 static int mwifiex_cfg80211_start_ap(struct wiphy *wiphy,
1937 struct net_device *dev,
1938 struct cfg80211_ap_settings *params)
1940 struct mwifiex_uap_bss_param *bss_cfg;
1941 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
1943 if (GET_BSS_ROLE(priv) != MWIFIEX_BSS_ROLE_UAP)
1946 bss_cfg = kzalloc(sizeof(struct mwifiex_uap_bss_param), GFP_KERNEL);
1950 mwifiex_set_sys_config_invalid_data(bss_cfg);
1952 if (params->beacon_interval)
1953 bss_cfg->beacon_period = params->beacon_interval;
1954 if (params->dtim_period)
1955 bss_cfg->dtim_period = params->dtim_period;
1957 if (params->ssid && params->ssid_len) {
1958 memcpy(bss_cfg->ssid.ssid, params->ssid, params->ssid_len);
1959 bss_cfg->ssid.ssid_len = params->ssid_len;
1961 if (params->inactivity_timeout > 0) {
1962 /* sta_ao_timer/ps_sta_ao_timer is in unit of 100ms */
1963 bss_cfg->sta_ao_timer = 10 * params->inactivity_timeout;
1964 bss_cfg->ps_sta_ao_timer = 10 * params->inactivity_timeout;
1967 switch (params->hidden_ssid) {
1968 case NL80211_HIDDEN_SSID_NOT_IN_USE:
1969 bss_cfg->bcast_ssid_ctl = 1;
1971 case NL80211_HIDDEN_SSID_ZERO_LEN:
1972 bss_cfg->bcast_ssid_ctl = 0;
1974 case NL80211_HIDDEN_SSID_ZERO_CONTENTS:
1975 /* firmware doesn't support this type of hidden SSID */
1981 mwifiex_uap_set_channel(priv, bss_cfg, params->chandef);
1982 mwifiex_set_uap_rates(bss_cfg, params);
1984 if (mwifiex_set_secure_params(priv, bss_cfg, params)) {
1985 mwifiex_dbg(priv->adapter, ERROR,
1986 "Failed to parse secuirty parameters!\n");
1990 mwifiex_set_ht_params(priv, bss_cfg, params);
1992 if (priv->adapter->is_hw_11ac_capable) {
1993 mwifiex_set_vht_params(priv, bss_cfg, params);
1994 mwifiex_set_vht_width(priv, params->chandef.width,
1995 priv->ap_11ac_enabled);
1998 if (priv->ap_11ac_enabled)
1999 mwifiex_set_11ac_ba_params(priv);
2001 mwifiex_set_ba_params(priv);
2003 mwifiex_set_wmm_params(priv, bss_cfg, params);
2005 if (mwifiex_is_11h_active(priv))
2006 mwifiex_set_tpc_params(priv, bss_cfg, params);
2008 if (mwifiex_is_11h_active(priv) &&
2009 !cfg80211_chandef_dfs_required(wiphy, ¶ms->chandef,
2011 mwifiex_dbg(priv->adapter, INFO,
2012 "Disable 11h extensions in FW\n");
2013 if (mwifiex_11h_activate(priv, false)) {
2014 mwifiex_dbg(priv->adapter, ERROR,
2015 "Failed to disable 11h extensions!!");
2018 priv->state_11h.is_11h_active = false;
2021 if (mwifiex_config_start_uap(priv, bss_cfg)) {
2022 mwifiex_dbg(priv->adapter, ERROR,
2023 "Failed to start AP\n");
2027 if (mwifiex_set_mgmt_ies(priv, ¶ms->beacon))
2030 if (!netif_carrier_ok(priv->netdev))
2031 netif_carrier_on(priv->netdev);
2032 mwifiex_wake_up_net_dev_queue(priv->netdev, priv->adapter);
2034 memcpy(&priv->bss_cfg, bss_cfg, sizeof(priv->bss_cfg));
2044 * CFG802.11 operation handler for disconnection request.
2046 * This function does not work when there is already a disconnection
2047 * procedure going on.
2050 mwifiex_cfg80211_disconnect(struct wiphy *wiphy, struct net_device *dev,
2053 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
2055 if (!mwifiex_stop_bg_scan(priv))
2056 cfg80211_sched_scan_stopped_rtnl(priv->wdev.wiphy);
2058 if (mwifiex_deauthenticate(priv, NULL))
2061 eth_zero_addr(priv->cfg_bssid);
2062 priv->hs2_enabled = false;
2068 * This function informs the CFG802.11 subsystem of a new IBSS.
2070 * The following information are sent to the CFG802.11 subsystem
2071 * to register the new IBSS. If we do not register the new IBSS,
2072 * a kernel panic will result.
2078 static int mwifiex_cfg80211_inform_ibss_bss(struct mwifiex_private *priv)
2080 struct ieee80211_channel *chan;
2081 struct mwifiex_bss_info bss_info;
2082 struct cfg80211_bss *bss;
2084 u8 ie_buf[IEEE80211_MAX_SSID_LEN + sizeof(struct ieee_types_header)];
2085 enum nl80211_band band;
2087 if (mwifiex_get_bss_info(priv, &bss_info))
2090 ie_buf[0] = WLAN_EID_SSID;
2091 ie_buf[1] = bss_info.ssid.ssid_len;
2093 memcpy(&ie_buf[sizeof(struct ieee_types_header)],
2094 &bss_info.ssid.ssid, bss_info.ssid.ssid_len);
2095 ie_len = ie_buf[1] + sizeof(struct ieee_types_header);
2097 band = mwifiex_band_to_radio_type(priv->curr_bss_params.band);
2098 chan = ieee80211_get_channel(priv->wdev.wiphy,
2099 ieee80211_channel_to_frequency(bss_info.bss_chan,
2102 bss = cfg80211_inform_bss(priv->wdev.wiphy, chan,
2103 CFG80211_BSS_FTYPE_UNKNOWN,
2104 bss_info.bssid, 0, WLAN_CAPABILITY_IBSS,
2105 0, ie_buf, ie_len, 0, GFP_KERNEL);
2107 cfg80211_put_bss(priv->wdev.wiphy, bss);
2108 ether_addr_copy(priv->cfg_bssid, bss_info.bssid);
2115 * This function connects with a BSS.
2117 * This function handles both Infra and Ad-Hoc modes. It also performs
2118 * validity checking on the provided parameters, disconnects from the
2119 * current BSS (if any), sets up the association/scan parameters,
2120 * including security settings, and performs specific SSID scan before
2121 * trying to connect.
2123 * For Infra mode, the function returns failure if the specified SSID
2124 * is not found in scan table. However, for Ad-Hoc mode, it can create
2125 * the IBSS if it does not exist. On successful completion in either case,
2126 * the function notifies the CFG802.11 subsystem of the new BSS connection.
2129 mwifiex_cfg80211_assoc(struct mwifiex_private *priv, size_t ssid_len,
2130 const u8 *ssid, const u8 *bssid, int mode,
2131 struct ieee80211_channel *channel,
2132 struct cfg80211_connect_params *sme, bool privacy)
2134 struct cfg80211_ssid req_ssid;
2135 int ret, auth_type = 0;
2136 struct cfg80211_bss *bss = NULL;
2137 u8 is_scanning_required = 0;
2139 memset(&req_ssid, 0, sizeof(struct cfg80211_ssid));
2141 req_ssid.ssid_len = ssid_len;
2142 if (ssid_len > IEEE80211_MAX_SSID_LEN) {
2143 mwifiex_dbg(priv->adapter, ERROR, "invalid SSID - aborting\n");
2147 memcpy(req_ssid.ssid, ssid, ssid_len);
2148 if (!req_ssid.ssid_len || req_ssid.ssid[0] < 0x20) {
2149 mwifiex_dbg(priv->adapter, ERROR, "invalid SSID - aborting\n");
2153 /* As this is new association, clear locally stored
2154 * keys and security related flags */
2155 priv->sec_info.wpa_enabled = false;
2156 priv->sec_info.wpa2_enabled = false;
2157 priv->wep_key_curr_index = 0;
2158 priv->sec_info.encryption_mode = 0;
2159 priv->sec_info.is_authtype_auto = 0;
2160 ret = mwifiex_set_encode(priv, NULL, NULL, 0, 0, NULL, 1);
2162 if (mode == NL80211_IFTYPE_ADHOC) {
2165 /* set ibss coalescing_status */
2166 ret = mwifiex_send_cmd(
2168 HostCmd_CMD_802_11_IBSS_COALESCING_STATUS,
2169 HostCmd_ACT_GEN_SET, 0, &enable, true);
2173 /* "privacy" is set only for ad-hoc mode */
2176 * Keep WLAN_CIPHER_SUITE_WEP104 for now so that
2177 * the firmware can find a matching network from the
2178 * scan. The cfg80211 does not give us the encryption
2179 * mode at this stage so just setting it to WEP here.
2181 priv->sec_info.encryption_mode =
2182 WLAN_CIPHER_SUITE_WEP104;
2183 priv->sec_info.authentication_mode =
2184 NL80211_AUTHTYPE_OPEN_SYSTEM;
2190 /* Now handle infra mode. "sme" is valid for infra mode only */
2191 if (sme->auth_type == NL80211_AUTHTYPE_AUTOMATIC) {
2192 auth_type = NL80211_AUTHTYPE_OPEN_SYSTEM;
2193 priv->sec_info.is_authtype_auto = 1;
2195 auth_type = sme->auth_type;
2198 if (sme->crypto.n_ciphers_pairwise) {
2199 priv->sec_info.encryption_mode =
2200 sme->crypto.ciphers_pairwise[0];
2201 priv->sec_info.authentication_mode = auth_type;
2204 if (sme->crypto.cipher_group) {
2205 priv->sec_info.encryption_mode = sme->crypto.cipher_group;
2206 priv->sec_info.authentication_mode = auth_type;
2209 ret = mwifiex_set_gen_ie(priv, sme->ie, sme->ie_len);
2212 if (mwifiex_is_alg_wep(priv->sec_info.encryption_mode)) {
2213 mwifiex_dbg(priv->adapter, INFO,
2214 "info: setting wep encryption\t"
2215 "with key len %d\n", sme->key_len);
2216 priv->wep_key_curr_index = sme->key_idx;
2217 ret = mwifiex_set_encode(priv, NULL, sme->key,
2218 sme->key_len, sme->key_idx,
2224 * Scan entries are valid for some time (15 sec). So we can save one
2225 * active scan time if we just try cfg80211_get_bss first. If it fails
2226 * then request scan and cfg80211_get_bss() again for final output.
2229 if (is_scanning_required) {
2230 /* Do specific SSID scanning */
2231 if (mwifiex_request_scan(priv, &req_ssid)) {
2232 mwifiex_dbg(priv->adapter, ERROR, "scan error\n");
2237 /* Find the BSS we want using available scan results */
2238 if (mode == NL80211_IFTYPE_ADHOC)
2239 bss = cfg80211_get_bss(priv->wdev.wiphy, channel,
2240 bssid, ssid, ssid_len,
2241 IEEE80211_BSS_TYPE_IBSS,
2242 IEEE80211_PRIVACY_ANY);
2244 bss = cfg80211_get_bss(priv->wdev.wiphy, channel,
2245 bssid, ssid, ssid_len,
2246 IEEE80211_BSS_TYPE_ESS,
2247 IEEE80211_PRIVACY_ANY);
2250 if (is_scanning_required) {
2251 mwifiex_dbg(priv->adapter, WARN,
2252 "assoc: requested bss not found in scan results\n");
2255 is_scanning_required = 1;
2257 mwifiex_dbg(priv->adapter, MSG,
2258 "info: trying to associate to '%.*s' bssid %pM\n",
2259 req_ssid.ssid_len, (char *)req_ssid.ssid,
2261 memcpy(&priv->cfg_bssid, bss->bssid, ETH_ALEN);
2266 ret = mwifiex_bss_start(priv, bss, &req_ssid);
2270 if (mode == NL80211_IFTYPE_ADHOC) {
2271 /* Inform the BSS information to kernel, otherwise
2272 * kernel will give a panic after successful assoc */
2273 if (mwifiex_cfg80211_inform_ibss_bss(priv))
2281 * CFG802.11 operation handler for association request.
2283 * This function does not work when the current mode is set to Ad-Hoc, or
2284 * when there is already an association procedure going on. The given BSS
2285 * information is used to associate.
2288 mwifiex_cfg80211_connect(struct wiphy *wiphy, struct net_device *dev,
2289 struct cfg80211_connect_params *sme)
2291 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
2292 struct mwifiex_adapter *adapter = priv->adapter;
2295 if (GET_BSS_ROLE(priv) != MWIFIEX_BSS_ROLE_STA) {
2296 mwifiex_dbg(adapter, ERROR,
2297 "%s: reject infra assoc request in non-STA role\n",
2302 if (priv->wdev.current_bss) {
2303 mwifiex_dbg(adapter, ERROR,
2304 "%s: already connected\n", dev->name);
2308 if (priv->scan_block)
2309 priv->scan_block = false;
2311 if (adapter->surprise_removed || adapter->is_cmd_timedout) {
2312 mwifiex_dbg(adapter, ERROR,
2313 "%s: Ignore connection.\t"
2314 "Card removed or FW in bad state\n",
2319 mwifiex_dbg(adapter, INFO,
2320 "info: Trying to associate to %.*s and bssid %pM\n",
2321 (int)sme->ssid_len, (char *)sme->ssid, sme->bssid);
2323 if (!mwifiex_stop_bg_scan(priv))
2324 cfg80211_sched_scan_stopped_rtnl(priv->wdev.wiphy);
2326 ret = mwifiex_cfg80211_assoc(priv, sme->ssid_len, sme->ssid, sme->bssid,
2327 priv->bss_mode, sme->channel, sme, 0);
2329 cfg80211_connect_result(priv->netdev, priv->cfg_bssid, NULL, 0,
2330 NULL, 0, WLAN_STATUS_SUCCESS,
2332 mwifiex_dbg(priv->adapter, MSG,
2333 "info: associated to bssid %pM successfully\n",
2335 if (ISSUPP_TDLS_ENABLED(priv->adapter->fw_cap_info) &&
2336 priv->adapter->auto_tdls &&
2337 priv->bss_type == MWIFIEX_BSS_TYPE_STA)
2338 mwifiex_setup_auto_tdls_timer(priv);
2340 mwifiex_dbg(priv->adapter, ERROR,
2341 "info: association to bssid %pM failed\n",
2343 eth_zero_addr(priv->cfg_bssid);
2346 cfg80211_connect_result(priv->netdev, priv->cfg_bssid,
2347 NULL, 0, NULL, 0, ret,
2350 cfg80211_connect_result(priv->netdev, priv->cfg_bssid,
2352 WLAN_STATUS_UNSPECIFIED_FAILURE,
2360 * This function sets following parameters for ibss network.
2364 * - secondary channel offset
2366 static int mwifiex_set_ibss_params(struct mwifiex_private *priv,
2367 struct cfg80211_ibss_params *params)
2369 struct mwifiex_adapter *adapter = priv->adapter;
2371 u8 config_bands = 0;
2373 if (params->chandef.chan->band == NL80211_BAND_2GHZ) {
2374 if (!params->basic_rates) {
2375 config_bands = BAND_B | BAND_G;
2377 for (i = 0; i < mwifiex_band_2ghz.n_bitrates; i++) {
2379 * Rates below 6 Mbps in the table are CCK
2380 * rates; 802.11b and from 6 they are OFDM;
2383 if (mwifiex_rates[i].bitrate == 60) {
2389 if (params->basic_rates < index) {
2390 config_bands = BAND_B;
2392 config_bands = BAND_G;
2393 if (params->basic_rates % index)
2394 config_bands |= BAND_B;
2398 if (cfg80211_get_chandef_type(¶ms->chandef) !=
2400 config_bands |= BAND_G | BAND_GN;
2402 if (cfg80211_get_chandef_type(¶ms->chandef) ==
2404 config_bands = BAND_A;
2406 config_bands = BAND_AN | BAND_A;
2409 if (!((config_bands | adapter->fw_bands) & ~adapter->fw_bands)) {
2410 adapter->config_bands = config_bands;
2411 adapter->adhoc_start_band = config_bands;
2413 if ((config_bands & BAND_GN) || (config_bands & BAND_AN))
2414 adapter->adhoc_11n_enabled = true;
2416 adapter->adhoc_11n_enabled = false;
2419 adapter->sec_chan_offset =
2420 mwifiex_chan_type_to_sec_chan_offset(
2421 cfg80211_get_chandef_type(¶ms->chandef));
2422 priv->adhoc_channel = ieee80211_frequency_to_channel(
2423 params->chandef.chan->center_freq);
2425 mwifiex_dbg(adapter, INFO,
2426 "info: set ibss band %d, chan %d, chan offset %d\n",
2427 config_bands, priv->adhoc_channel,
2428 adapter->sec_chan_offset);
2434 * CFG802.11 operation handler to join an IBSS.
2436 * This function does not work in any mode other than Ad-Hoc, or if
2437 * a join operation is already in progress.
2440 mwifiex_cfg80211_join_ibss(struct wiphy *wiphy, struct net_device *dev,
2441 struct cfg80211_ibss_params *params)
2443 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
2446 if (priv->bss_mode != NL80211_IFTYPE_ADHOC) {
2447 mwifiex_dbg(priv->adapter, ERROR,
2448 "request to join ibss received\t"
2449 "when station is not in ibss mode\n");
2453 mwifiex_dbg(priv->adapter, MSG,
2454 "info: trying to join to %.*s and bssid %pM\n",
2455 params->ssid_len, (char *)params->ssid, params->bssid);
2457 mwifiex_set_ibss_params(priv, params);
2459 ret = mwifiex_cfg80211_assoc(priv, params->ssid_len, params->ssid,
2460 params->bssid, priv->bss_mode,
2461 params->chandef.chan, NULL,
2465 cfg80211_ibss_joined(priv->netdev, priv->cfg_bssid,
2466 params->chandef.chan, GFP_KERNEL);
2467 mwifiex_dbg(priv->adapter, MSG,
2468 "info: joined/created adhoc network with bssid\t"
2469 "%pM successfully\n", priv->cfg_bssid);
2471 mwifiex_dbg(priv->adapter, ERROR,
2472 "info: failed creating/joining adhoc network\n");
2479 * CFG802.11 operation handler to leave an IBSS.
2481 * This function does not work if a leave operation is
2482 * already in progress.
2485 mwifiex_cfg80211_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
2487 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
2489 mwifiex_dbg(priv->adapter, MSG, "info: disconnecting from essid %pM\n",
2491 if (mwifiex_deauthenticate(priv, NULL))
2494 eth_zero_addr(priv->cfg_bssid);
2500 * CFG802.11 operation handler for scan request.
2502 * This function issues a scan request to the firmware based upon
2503 * the user specified scan configuration. On successful completion,
2504 * it also informs the results.
2507 mwifiex_cfg80211_scan(struct wiphy *wiphy,
2508 struct cfg80211_scan_request *request)
2510 struct net_device *dev = request->wdev->netdev;
2511 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
2513 struct ieee80211_channel *chan;
2514 struct ieee_types_header *ie;
2515 struct mwifiex_user_scan_cfg *user_scan_cfg;
2517 mwifiex_dbg(priv->adapter, CMD,
2518 "info: received scan request on %s\n", dev->name);
2520 /* Block scan request if scan operation or scan cleanup when interface
2521 * is disabled is in process
2523 if (priv->scan_request || priv->scan_aborting) {
2524 mwifiex_dbg(priv->adapter, WARN,
2525 "cmd: Scan already in process..\n");
2529 if (!priv->wdev.current_bss && priv->scan_block)
2530 priv->scan_block = false;
2532 if (!mwifiex_stop_bg_scan(priv))
2533 cfg80211_sched_scan_stopped_rtnl(priv->wdev.wiphy);
2535 user_scan_cfg = kzalloc(sizeof(*user_scan_cfg), GFP_KERNEL);
2539 priv->scan_request = request;
2541 if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) {
2542 ether_addr_copy(priv->random_mac, request->mac_addr);
2543 for (i = 0; i < ETH_ALEN; i++) {
2544 priv->random_mac[i] &= request->mac_addr_mask[i];
2545 priv->random_mac[i] |= get_random_int() &
2546 ~(request->mac_addr_mask[i]);
2548 ether_addr_copy(user_scan_cfg->random_mac, priv->random_mac);
2550 eth_zero_addr(priv->random_mac);
2553 user_scan_cfg->num_ssids = request->n_ssids;
2554 user_scan_cfg->ssid_list = request->ssids;
2556 if (request->ie && request->ie_len) {
2558 for (i = 0; i < MWIFIEX_MAX_VSIE_NUM; i++) {
2559 if (priv->vs_ie[i].mask != MWIFIEX_VSIE_MASK_CLEAR)
2561 priv->vs_ie[i].mask = MWIFIEX_VSIE_MASK_SCAN;
2562 ie = (struct ieee_types_header *)(request->ie + offset);
2563 memcpy(&priv->vs_ie[i].ie, ie, sizeof(*ie) + ie->len);
2564 offset += sizeof(*ie) + ie->len;
2566 if (offset >= request->ie_len)
2571 for (i = 0; i < min_t(u32, request->n_channels,
2572 MWIFIEX_USER_SCAN_CHAN_MAX); i++) {
2573 chan = request->channels[i];
2574 user_scan_cfg->chan_list[i].chan_number = chan->hw_value;
2575 user_scan_cfg->chan_list[i].radio_type = chan->band;
2577 if ((chan->flags & IEEE80211_CHAN_NO_IR) || !request->n_ssids)
2578 user_scan_cfg->chan_list[i].scan_type =
2579 MWIFIEX_SCAN_TYPE_PASSIVE;
2581 user_scan_cfg->chan_list[i].scan_type =
2582 MWIFIEX_SCAN_TYPE_ACTIVE;
2584 user_scan_cfg->chan_list[i].scan_time = 0;
2587 if (priv->adapter->scan_chan_gap_enabled &&
2588 mwifiex_is_any_intf_active(priv))
2589 user_scan_cfg->scan_chan_gap =
2590 priv->adapter->scan_chan_gap_time;
2592 ret = mwifiex_scan_networks(priv, user_scan_cfg);
2593 kfree(user_scan_cfg);
2595 mwifiex_dbg(priv->adapter, ERROR,
2596 "scan failed: %d\n", ret);
2597 priv->scan_aborting = false;
2598 priv->scan_request = NULL;
2602 if (request->ie && request->ie_len) {
2603 for (i = 0; i < MWIFIEX_MAX_VSIE_NUM; i++) {
2604 if (priv->vs_ie[i].mask == MWIFIEX_VSIE_MASK_SCAN) {
2605 priv->vs_ie[i].mask = MWIFIEX_VSIE_MASK_CLEAR;
2606 memset(&priv->vs_ie[i].ie, 0,
2607 MWIFIEX_MAX_VSIE_LEN);
2614 /* CFG802.11 operation handler for sched_scan_start.
2616 * This function issues a bgscan config request to the firmware based upon
2617 * the user specified sched_scan configuration. On successful completion,
2618 * firmware will generate BGSCAN_REPORT event, driver should issue bgscan
2619 * query command to get sched_scan results from firmware.
2622 mwifiex_cfg80211_sched_scan_start(struct wiphy *wiphy,
2623 struct net_device *dev,
2624 struct cfg80211_sched_scan_request *request)
2626 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
2628 struct ieee80211_channel *chan;
2629 struct mwifiex_bg_scan_cfg *bgscan_cfg;
2630 struct ieee_types_header *ie;
2632 if (!request || (!request->n_ssids && !request->n_match_sets)) {
2633 wiphy_err(wiphy, "%s : Invalid Sched_scan parameters",
2638 wiphy_info(wiphy, "sched_scan start : n_ssids=%d n_match_sets=%d ",
2639 request->n_ssids, request->n_match_sets);
2640 wiphy_info(wiphy, "n_channels=%d interval=%d ie_len=%d\n",
2641 request->n_channels, request->scan_plans->interval,
2642 (int)request->ie_len);
2644 bgscan_cfg = kzalloc(sizeof(*bgscan_cfg), GFP_KERNEL);
2648 if (priv->scan_request || priv->scan_aborting)
2649 bgscan_cfg->start_later = true;
2651 bgscan_cfg->num_ssids = request->n_match_sets;
2652 bgscan_cfg->ssid_list = request->match_sets;
2654 if (request->ie && request->ie_len) {
2656 for (i = 0; i < MWIFIEX_MAX_VSIE_NUM; i++) {
2657 if (priv->vs_ie[i].mask != MWIFIEX_VSIE_MASK_CLEAR)
2659 priv->vs_ie[i].mask = MWIFIEX_VSIE_MASK_BGSCAN;
2660 ie = (struct ieee_types_header *)(request->ie + offset);
2661 memcpy(&priv->vs_ie[i].ie, ie, sizeof(*ie) + ie->len);
2662 offset += sizeof(*ie) + ie->len;
2664 if (offset >= request->ie_len)
2669 for (i = 0; i < min_t(u32, request->n_channels,
2670 MWIFIEX_BG_SCAN_CHAN_MAX); i++) {
2671 chan = request->channels[i];
2672 bgscan_cfg->chan_list[i].chan_number = chan->hw_value;
2673 bgscan_cfg->chan_list[i].radio_type = chan->band;
2675 if ((chan->flags & IEEE80211_CHAN_NO_IR) || !request->n_ssids)
2676 bgscan_cfg->chan_list[i].scan_type =
2677 MWIFIEX_SCAN_TYPE_PASSIVE;
2679 bgscan_cfg->chan_list[i].scan_type =
2680 MWIFIEX_SCAN_TYPE_ACTIVE;
2682 bgscan_cfg->chan_list[i].scan_time = 0;
2685 bgscan_cfg->chan_per_scan = min_t(u32, request->n_channels,
2686 MWIFIEX_BG_SCAN_CHAN_MAX);
2688 /* Use at least 15 second for per scan cycle */
2689 bgscan_cfg->scan_interval = (request->scan_plans->interval >
2690 MWIFIEX_BGSCAN_INTERVAL) ?
2691 request->scan_plans->interval :
2692 MWIFIEX_BGSCAN_INTERVAL;
2694 bgscan_cfg->repeat_count = MWIFIEX_BGSCAN_REPEAT_COUNT;
2695 bgscan_cfg->report_condition = MWIFIEX_BGSCAN_SSID_MATCH |
2696 MWIFIEX_BGSCAN_WAIT_ALL_CHAN_DONE;
2697 bgscan_cfg->bss_type = MWIFIEX_BSS_MODE_INFRA;
2698 bgscan_cfg->action = MWIFIEX_BGSCAN_ACT_SET;
2699 bgscan_cfg->enable = true;
2700 if (request->min_rssi_thold != NL80211_SCAN_RSSI_THOLD_OFF) {
2701 bgscan_cfg->report_condition |= MWIFIEX_BGSCAN_SSID_RSSI_MATCH;
2702 bgscan_cfg->rssi_threshold = request->min_rssi_thold;
2705 if (mwifiex_send_cmd(priv, HostCmd_CMD_802_11_BG_SCAN_CONFIG,
2706 HostCmd_ACT_GEN_SET, 0, bgscan_cfg, true)) {
2711 priv->sched_scanning = true;
2717 /* CFG802.11 operation handler for sched_scan_stop.
2719 * This function issues a bgscan config command to disable
2720 * previous bgscan configuration in the firmware
2722 static int mwifiex_cfg80211_sched_scan_stop(struct wiphy *wiphy,
2723 struct net_device *dev)
2725 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
2727 wiphy_info(wiphy, "sched scan stop!");
2728 mwifiex_stop_bg_scan(priv);
2733 static void mwifiex_setup_vht_caps(struct ieee80211_sta_vht_cap *vht_info,
2734 struct mwifiex_private *priv)
2736 struct mwifiex_adapter *adapter = priv->adapter;
2738 vht_info->vht_supported = true;
2740 vht_info->cap = adapter->hw_dot_11ac_dev_cap;
2741 /* Update MCS support for VHT */
2742 vht_info->vht_mcs.rx_mcs_map = cpu_to_le16(
2743 adapter->hw_dot_11ac_mcs_support & 0xFFFF);
2744 vht_info->vht_mcs.rx_highest = 0;
2745 vht_info->vht_mcs.tx_mcs_map = cpu_to_le16(
2746 adapter->hw_dot_11ac_mcs_support >> 16);
2747 vht_info->vht_mcs.tx_highest = 0;
2751 * This function sets up the CFG802.11 specific HT capability fields
2752 * with default values.
2754 * The following default values are set -
2755 * - HT Supported = True
2756 * - Maximum AMPDU length factor = IEEE80211_HT_MAX_AMPDU_64K
2757 * - Minimum AMPDU spacing = IEEE80211_HT_MPDU_DENSITY_NONE
2758 * - HT Capabilities supported by firmware
2759 * - MCS information, Rx mask = 0xff
2760 * - MCD information, Tx parameters = IEEE80211_HT_MCS_TX_DEFINED (0x01)
2763 mwifiex_setup_ht_caps(struct ieee80211_sta_ht_cap *ht_info,
2764 struct mwifiex_private *priv)
2767 struct ieee80211_mcs_info mcs_set;
2768 u8 *mcs = (u8 *)&mcs_set;
2769 struct mwifiex_adapter *adapter = priv->adapter;
2771 ht_info->ht_supported = true;
2772 ht_info->ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
2773 ht_info->ampdu_density = IEEE80211_HT_MPDU_DENSITY_NONE;
2775 memset(&ht_info->mcs, 0, sizeof(ht_info->mcs));
2777 /* Fill HT capability information */
2778 if (ISSUPP_CHANWIDTH40(adapter->hw_dot_11n_dev_cap))
2779 ht_info->cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
2781 ht_info->cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
2783 if (ISSUPP_SHORTGI20(adapter->hw_dot_11n_dev_cap))
2784 ht_info->cap |= IEEE80211_HT_CAP_SGI_20;
2786 ht_info->cap &= ~IEEE80211_HT_CAP_SGI_20;
2788 if (ISSUPP_SHORTGI40(adapter->hw_dot_11n_dev_cap))
2789 ht_info->cap |= IEEE80211_HT_CAP_SGI_40;
2791 ht_info->cap &= ~IEEE80211_HT_CAP_SGI_40;
2793 if (adapter->user_dev_mcs_support == HT_STREAM_2X2)
2794 ht_info->cap |= 2 << IEEE80211_HT_CAP_RX_STBC_SHIFT;
2796 ht_info->cap |= 1 << IEEE80211_HT_CAP_RX_STBC_SHIFT;
2798 if (ISSUPP_TXSTBC(adapter->hw_dot_11n_dev_cap))
2799 ht_info->cap |= IEEE80211_HT_CAP_TX_STBC;
2801 ht_info->cap &= ~IEEE80211_HT_CAP_TX_STBC;
2803 if (ISSUPP_GREENFIELD(adapter->hw_dot_11n_dev_cap))
2804 ht_info->cap |= IEEE80211_HT_CAP_GRN_FLD;
2806 ht_info->cap &= ~IEEE80211_HT_CAP_GRN_FLD;
2808 if (ISENABLED_40MHZ_INTOLERANT(adapter->hw_dot_11n_dev_cap))
2809 ht_info->cap |= IEEE80211_HT_CAP_40MHZ_INTOLERANT;
2811 ht_info->cap &= ~IEEE80211_HT_CAP_40MHZ_INTOLERANT;
2813 if (ISSUPP_RXLDPC(adapter->hw_dot_11n_dev_cap))
2814 ht_info->cap |= IEEE80211_HT_CAP_LDPC_CODING;
2816 ht_info->cap &= ~IEEE80211_HT_CAP_LDPC_CODING;
2818 ht_info->cap &= ~IEEE80211_HT_CAP_MAX_AMSDU;
2819 ht_info->cap |= IEEE80211_HT_CAP_SM_PS;
2821 rx_mcs_supp = GET_RXMCSSUPP(adapter->user_dev_mcs_support);
2822 /* Set MCS for 1x1/2x2 */
2823 memset(mcs, 0xff, rx_mcs_supp);
2824 /* Clear all the other values */
2825 memset(&mcs[rx_mcs_supp], 0,
2826 sizeof(struct ieee80211_mcs_info) - rx_mcs_supp);
2827 if (priv->bss_mode == NL80211_IFTYPE_STATION ||
2828 ISSUPP_CHANWIDTH40(adapter->hw_dot_11n_dev_cap))
2829 /* Set MCS32 for infra mode or ad-hoc mode with 40MHz support */
2830 SETHT_MCS32(mcs_set.rx_mask);
2832 memcpy((u8 *) &ht_info->mcs, mcs, sizeof(struct ieee80211_mcs_info));
2834 ht_info->mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED;
2838 * create a new virtual interface with the given name and name assign type
2840 struct wireless_dev *mwifiex_add_virtual_intf(struct wiphy *wiphy,
2842 unsigned char name_assign_type,
2843 enum nl80211_iftype type,
2844 struct vif_params *params)
2846 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
2847 struct mwifiex_private *priv;
2848 struct net_device *dev;
2853 return ERR_PTR(-EFAULT);
2856 case NL80211_IFTYPE_UNSPECIFIED:
2857 case NL80211_IFTYPE_STATION:
2858 case NL80211_IFTYPE_ADHOC:
2859 if (adapter->curr_iface_comb.sta_intf ==
2860 adapter->iface_limit.sta_intf) {
2861 mwifiex_dbg(adapter, ERROR,
2862 "cannot create multiple sta/adhoc ifaces\n");
2863 return ERR_PTR(-EINVAL);
2866 priv = mwifiex_get_unused_priv_by_bss_type(
2867 adapter, MWIFIEX_BSS_TYPE_STA);
2869 mwifiex_dbg(adapter, ERROR,
2870 "could not get free private struct\n");
2871 return ERR_PTR(-EFAULT);
2874 priv->wdev.wiphy = wiphy;
2875 priv->wdev.iftype = NL80211_IFTYPE_STATION;
2877 if (type == NL80211_IFTYPE_UNSPECIFIED)
2878 priv->bss_mode = NL80211_IFTYPE_STATION;
2880 priv->bss_mode = type;
2882 priv->bss_type = MWIFIEX_BSS_TYPE_STA;
2883 priv->frame_type = MWIFIEX_DATA_FRAME_TYPE_ETH_II;
2884 priv->bss_priority = 0;
2885 priv->bss_role = MWIFIEX_BSS_ROLE_STA;
2888 case NL80211_IFTYPE_AP:
2889 if (adapter->curr_iface_comb.uap_intf ==
2890 adapter->iface_limit.uap_intf) {
2891 mwifiex_dbg(adapter, ERROR,
2892 "cannot create multiple AP ifaces\n");
2893 return ERR_PTR(-EINVAL);
2896 priv = mwifiex_get_unused_priv_by_bss_type(
2897 adapter, MWIFIEX_BSS_TYPE_UAP);
2899 mwifiex_dbg(adapter, ERROR,
2900 "could not get free private struct\n");
2901 return ERR_PTR(-EFAULT);
2904 priv->wdev.wiphy = wiphy;
2905 priv->wdev.iftype = NL80211_IFTYPE_AP;
2907 priv->bss_type = MWIFIEX_BSS_TYPE_UAP;
2908 priv->frame_type = MWIFIEX_DATA_FRAME_TYPE_ETH_II;
2909 priv->bss_priority = 0;
2910 priv->bss_role = MWIFIEX_BSS_ROLE_UAP;
2911 priv->bss_started = 0;
2912 priv->bss_mode = type;
2915 case NL80211_IFTYPE_P2P_CLIENT:
2916 if (adapter->curr_iface_comb.p2p_intf ==
2917 adapter->iface_limit.p2p_intf) {
2918 mwifiex_dbg(adapter, ERROR,
2919 "cannot create multiple P2P ifaces\n");
2920 return ERR_PTR(-EINVAL);
2923 priv = mwifiex_get_unused_priv_by_bss_type(
2924 adapter, MWIFIEX_BSS_TYPE_P2P);
2926 mwifiex_dbg(adapter, ERROR,
2927 "could not get free private struct\n");
2928 return ERR_PTR(-EFAULT);
2931 priv->wdev.wiphy = wiphy;
2932 /* At start-up, wpa_supplicant tries to change the interface
2933 * to NL80211_IFTYPE_STATION if it is not managed mode.
2935 priv->wdev.iftype = NL80211_IFTYPE_P2P_CLIENT;
2936 priv->bss_mode = NL80211_IFTYPE_P2P_CLIENT;
2938 /* Setting bss_type to P2P tells firmware that this interface
2939 * is receiving P2P peers found during find phase and doing
2940 * action frame handshake.
2942 priv->bss_type = MWIFIEX_BSS_TYPE_P2P;
2944 priv->frame_type = MWIFIEX_DATA_FRAME_TYPE_ETH_II;
2945 priv->bss_priority = MWIFIEX_BSS_ROLE_STA;
2946 priv->bss_role = MWIFIEX_BSS_ROLE_STA;
2947 priv->bss_started = 0;
2949 if (mwifiex_cfg80211_init_p2p_client(priv)) {
2950 memset(&priv->wdev, 0, sizeof(priv->wdev));
2951 priv->wdev.iftype = NL80211_IFTYPE_UNSPECIFIED;
2952 return ERR_PTR(-EFAULT);
2957 mwifiex_dbg(adapter, ERROR, "type not supported\n");
2958 return ERR_PTR(-EINVAL);
2961 dev = alloc_netdev_mqs(sizeof(struct mwifiex_private *), name,
2962 name_assign_type, ether_setup,
2963 IEEE80211_NUM_ACS, 1);
2965 mwifiex_dbg(adapter, ERROR,
2966 "no memory available for netdevice\n");
2967 memset(&priv->wdev, 0, sizeof(priv->wdev));
2968 priv->wdev.iftype = NL80211_IFTYPE_UNSPECIFIED;
2969 priv->bss_mode = NL80211_IFTYPE_UNSPECIFIED;
2970 return ERR_PTR(-ENOMEM);
2973 mwifiex_init_priv_params(priv, dev);
2976 ret = mwifiex_send_cmd(priv, HostCmd_CMD_SET_BSS_MODE,
2977 HostCmd_ACT_GEN_SET, 0, NULL, true);
2979 return ERR_PTR(ret);
2981 ret = mwifiex_sta_init_cmd(priv, false, false);
2983 return ERR_PTR(ret);
2985 mwifiex_setup_ht_caps(&wiphy->bands[NL80211_BAND_2GHZ]->ht_cap, priv);
2986 if (adapter->is_hw_11ac_capable)
2987 mwifiex_setup_vht_caps(
2988 &wiphy->bands[NL80211_BAND_2GHZ]->vht_cap, priv);
2990 if (adapter->config_bands & BAND_A)
2991 mwifiex_setup_ht_caps(
2992 &wiphy->bands[NL80211_BAND_5GHZ]->ht_cap, priv);
2994 if ((adapter->config_bands & BAND_A) && adapter->is_hw_11ac_capable)
2995 mwifiex_setup_vht_caps(
2996 &wiphy->bands[NL80211_BAND_5GHZ]->vht_cap, priv);
2998 dev_net_set(dev, wiphy_net(wiphy));
2999 dev->ieee80211_ptr = &priv->wdev;
3000 dev->ieee80211_ptr->iftype = priv->bss_mode;
3001 memcpy(dev->dev_addr, wiphy->perm_addr, ETH_ALEN);
3002 SET_NETDEV_DEV(dev, wiphy_dev(wiphy));
3004 dev->flags |= IFF_BROADCAST | IFF_MULTICAST;
3005 dev->watchdog_timeo = MWIFIEX_DEFAULT_WATCHDOG_TIMEOUT;
3006 dev->hard_header_len += MWIFIEX_MIN_DATA_HEADER_LEN;
3007 dev->ethtool_ops = &mwifiex_ethtool_ops;
3009 mdev_priv = netdev_priv(dev);
3010 *((unsigned long *) mdev_priv) = (unsigned long) priv;
3012 SET_NETDEV_DEV(dev, adapter->dev);
3014 /* Register network device */
3015 if (register_netdevice(dev)) {
3016 mwifiex_dbg(adapter, ERROR,
3017 "cannot register virtual network device\n");
3019 priv->bss_mode = NL80211_IFTYPE_UNSPECIFIED;
3020 priv->netdev = NULL;
3021 memset(&priv->wdev, 0, sizeof(priv->wdev));
3022 priv->wdev.iftype = NL80211_IFTYPE_UNSPECIFIED;
3023 return ERR_PTR(-EFAULT);
3026 priv->dfs_cac_workqueue = alloc_workqueue("MWIFIEX_DFS_CAC%s",
3029 WQ_UNBOUND, 1, name);
3030 if (!priv->dfs_cac_workqueue) {
3031 mwifiex_dbg(adapter, ERROR,
3032 "cannot register virtual network device\n");
3034 priv->bss_mode = NL80211_IFTYPE_UNSPECIFIED;
3035 priv->netdev = NULL;
3036 memset(&priv->wdev, 0, sizeof(priv->wdev));
3037 priv->wdev.iftype = NL80211_IFTYPE_UNSPECIFIED;
3038 return ERR_PTR(-ENOMEM);
3041 INIT_DELAYED_WORK(&priv->dfs_cac_work, mwifiex_dfs_cac_work_queue);
3043 priv->dfs_chan_sw_workqueue = alloc_workqueue("MWIFIEX_DFS_CHSW%s",
3044 WQ_HIGHPRI | WQ_UNBOUND |
3045 WQ_MEM_RECLAIM, 1, name);
3046 if (!priv->dfs_chan_sw_workqueue) {
3047 mwifiex_dbg(adapter, ERROR,
3048 "cannot register virtual network device\n");
3050 priv->bss_mode = NL80211_IFTYPE_UNSPECIFIED;
3051 priv->netdev = NULL;
3052 memset(&priv->wdev, 0, sizeof(priv->wdev));
3053 priv->wdev.iftype = NL80211_IFTYPE_UNSPECIFIED;
3054 destroy_workqueue(priv->dfs_cac_workqueue);
3055 priv->dfs_cac_workqueue = NULL;
3056 return ERR_PTR(-ENOMEM);
3059 INIT_DELAYED_WORK(&priv->dfs_chan_sw_work,
3060 mwifiex_dfs_chan_sw_work_queue);
3062 sema_init(&priv->async_sem, 1);
3064 mwifiex_dbg(adapter, INFO,
3065 "info: %s: Marvell 802.11 Adapter\n", dev->name);
3067 #ifdef CONFIG_DEBUG_FS
3068 mwifiex_dev_debugfs_init(priv);
3072 case NL80211_IFTYPE_UNSPECIFIED:
3073 case NL80211_IFTYPE_STATION:
3074 case NL80211_IFTYPE_ADHOC:
3075 adapter->curr_iface_comb.sta_intf++;
3077 case NL80211_IFTYPE_AP:
3078 adapter->curr_iface_comb.uap_intf++;
3080 case NL80211_IFTYPE_P2P_CLIENT:
3081 adapter->curr_iface_comb.p2p_intf++;
3084 mwifiex_dbg(adapter, ERROR, "type not supported\n");
3085 return ERR_PTR(-EINVAL);
3090 EXPORT_SYMBOL_GPL(mwifiex_add_virtual_intf);
3093 * del_virtual_intf: remove the virtual interface determined by dev
3095 int mwifiex_del_virtual_intf(struct wiphy *wiphy, struct wireless_dev *wdev)
3097 struct mwifiex_private *priv = mwifiex_netdev_get_priv(wdev->netdev);
3098 struct mwifiex_adapter *adapter = priv->adapter;
3099 struct sk_buff *skb, *tmp;
3101 #ifdef CONFIG_DEBUG_FS
3102 mwifiex_dev_debugfs_remove(priv);
3105 if (priv->sched_scanning)
3106 priv->sched_scanning = false;
3108 mwifiex_stop_net_dev_queue(priv->netdev, adapter);
3110 skb_queue_walk_safe(&priv->bypass_txq, skb, tmp) {
3111 skb_unlink(skb, &priv->bypass_txq);
3112 mwifiex_write_data_complete(priv->adapter, skb, 0, -1);
3115 if (netif_carrier_ok(priv->netdev))
3116 netif_carrier_off(priv->netdev);
3118 if (wdev->netdev->reg_state == NETREG_REGISTERED)
3119 unregister_netdevice(wdev->netdev);
3121 if (priv->dfs_cac_workqueue) {
3122 flush_workqueue(priv->dfs_cac_workqueue);
3123 destroy_workqueue(priv->dfs_cac_workqueue);
3124 priv->dfs_cac_workqueue = NULL;
3127 if (priv->dfs_chan_sw_workqueue) {
3128 flush_workqueue(priv->dfs_chan_sw_workqueue);
3129 destroy_workqueue(priv->dfs_chan_sw_workqueue);
3130 priv->dfs_chan_sw_workqueue = NULL;
3132 /* Clear the priv in adapter */
3133 priv->netdev->ieee80211_ptr = NULL;
3134 priv->netdev = NULL;
3135 priv->wdev.iftype = NL80211_IFTYPE_UNSPECIFIED;
3137 priv->media_connected = false;
3139 switch (priv->bss_mode) {
3140 case NL80211_IFTYPE_UNSPECIFIED:
3141 case NL80211_IFTYPE_STATION:
3142 case NL80211_IFTYPE_ADHOC:
3143 adapter->curr_iface_comb.sta_intf--;
3145 case NL80211_IFTYPE_AP:
3146 adapter->curr_iface_comb.uap_intf--;
3148 case NL80211_IFTYPE_P2P_CLIENT:
3149 case NL80211_IFTYPE_P2P_GO:
3150 adapter->curr_iface_comb.p2p_intf--;
3153 mwifiex_dbg(adapter, ERROR,
3154 "del_virtual_intf: type not supported\n");
3158 priv->bss_mode = NL80211_IFTYPE_UNSPECIFIED;
3160 if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA ||
3161 GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_UAP)
3162 kfree(priv->hist_data);
3166 EXPORT_SYMBOL_GPL(mwifiex_del_virtual_intf);
3169 mwifiex_is_pattern_supported(struct cfg80211_pkt_pattern *pat, s8 *byte_seq,
3172 int j, k, valid_byte_cnt = 0;
3173 bool dont_care_byte = false;
3175 for (j = 0; j < DIV_ROUND_UP(pat->pattern_len, 8); j++) {
3176 for (k = 0; k < 8; k++) {
3177 if (pat->mask[j] & 1 << k) {
3178 memcpy(byte_seq + valid_byte_cnt,
3179 &pat->pattern[j * 8 + k], 1);
3185 dont_care_byte = true;
3188 /* wildcard bytes record as the offset
3189 * before the valid byte
3191 if (!valid_byte_cnt && !dont_care_byte)
3194 if (valid_byte_cnt > max_byte_seq)
3199 byte_seq[max_byte_seq] = valid_byte_cnt;
3205 static void mwifiex_set_auto_arp_mef_entry(struct mwifiex_private *priv,
3206 struct mwifiex_mef_entry *mef_entry)
3208 int i, filt_num = 0, num_ipv4 = 0;
3209 struct in_device *in_dev;
3210 struct in_ifaddr *ifa;
3211 __be32 ips[MWIFIEX_MAX_SUPPORTED_IPADDR];
3212 struct mwifiex_adapter *adapter = priv->adapter;
3214 mef_entry->mode = MEF_MODE_HOST_SLEEP;
3215 mef_entry->action = MEF_ACTION_AUTO_ARP;
3217 /* Enable ARP offload feature */
3218 memset(ips, 0, sizeof(ips));
3219 for (i = 0; i < MWIFIEX_MAX_BSS_NUM; i++) {
3220 if (adapter->priv[i]->netdev) {
3221 in_dev = __in_dev_get_rtnl(adapter->priv[i]->netdev);
3224 ifa = in_dev->ifa_list;
3225 if (!ifa || !ifa->ifa_local)
3227 ips[i] = ifa->ifa_local;
3232 for (i = 0; i < num_ipv4; i++) {
3235 mef_entry->filter[filt_num].repeat = 1;
3236 memcpy(mef_entry->filter[filt_num].byte_seq,
3237 (u8 *)&ips[i], sizeof(ips[i]));
3238 mef_entry->filter[filt_num].
3239 byte_seq[MWIFIEX_MEF_MAX_BYTESEQ] =
3241 mef_entry->filter[filt_num].offset = 46;
3242 mef_entry->filter[filt_num].filt_type = TYPE_EQ;
3244 mef_entry->filter[filt_num].filt_action =
3250 mef_entry->filter[filt_num].repeat = 1;
3251 mef_entry->filter[filt_num].byte_seq[0] = 0x08;
3252 mef_entry->filter[filt_num].byte_seq[1] = 0x06;
3253 mef_entry->filter[filt_num].byte_seq[MWIFIEX_MEF_MAX_BYTESEQ] = 2;
3254 mef_entry->filter[filt_num].offset = 20;
3255 mef_entry->filter[filt_num].filt_type = TYPE_EQ;
3256 mef_entry->filter[filt_num].filt_action = TYPE_AND;
3259 static int mwifiex_set_wowlan_mef_entry(struct mwifiex_private *priv,
3260 struct mwifiex_ds_mef_cfg *mef_cfg,
3261 struct mwifiex_mef_entry *mef_entry,
3262 struct cfg80211_wowlan *wowlan)
3264 int i, filt_num = 0, ret = 0;
3265 bool first_pat = true;
3266 u8 byte_seq[MWIFIEX_MEF_MAX_BYTESEQ + 1];
3267 const u8 ipv4_mc_mac[] = {0x33, 0x33};
3268 const u8 ipv6_mc_mac[] = {0x01, 0x00, 0x5e};
3270 mef_entry->mode = MEF_MODE_HOST_SLEEP;
3271 mef_entry->action = MEF_ACTION_ALLOW_AND_WAKEUP_HOST;
3273 for (i = 0; i < wowlan->n_patterns; i++) {
3274 memset(byte_seq, 0, sizeof(byte_seq));
3275 if (!mwifiex_is_pattern_supported(&wowlan->patterns[i],
3277 MWIFIEX_MEF_MAX_BYTESEQ)) {
3278 mwifiex_dbg(priv->adapter, ERROR,
3279 "Pattern not supported\n");
3283 if (!wowlan->patterns[i].pkt_offset) {
3284 if (!(byte_seq[0] & 0x01) &&
3285 (byte_seq[MWIFIEX_MEF_MAX_BYTESEQ] == 1)) {
3286 mef_cfg->criteria |= MWIFIEX_CRITERIA_UNICAST;
3288 } else if (is_broadcast_ether_addr(byte_seq)) {
3289 mef_cfg->criteria |= MWIFIEX_CRITERIA_BROADCAST;
3291 } else if ((!memcmp(byte_seq, ipv4_mc_mac, 2) &&
3292 (byte_seq[MWIFIEX_MEF_MAX_BYTESEQ] == 2)) ||
3293 (!memcmp(byte_seq, ipv6_mc_mac, 3) &&
3294 (byte_seq[MWIFIEX_MEF_MAX_BYTESEQ] == 3))) {
3295 mef_cfg->criteria |= MWIFIEX_CRITERIA_MULTICAST;
3299 mef_entry->filter[filt_num].repeat = 1;
3300 mef_entry->filter[filt_num].offset =
3301 wowlan->patterns[i].pkt_offset;
3302 memcpy(mef_entry->filter[filt_num].byte_seq, byte_seq,
3304 mef_entry->filter[filt_num].filt_type = TYPE_EQ;
3308 mwifiex_dbg(priv->adapter, INFO, "Wake on patterns\n");
3310 mef_entry->filter[filt_num].filt_action = TYPE_AND;
3316 if (wowlan->magic_pkt) {
3317 mef_cfg->criteria |= MWIFIEX_CRITERIA_UNICAST;
3318 mef_entry->filter[filt_num].repeat = 16;
3319 memcpy(mef_entry->filter[filt_num].byte_seq, priv->curr_addr,
3321 mef_entry->filter[filt_num].byte_seq[MWIFIEX_MEF_MAX_BYTESEQ] =
3323 mef_entry->filter[filt_num].offset = 28;
3324 mef_entry->filter[filt_num].filt_type = TYPE_EQ;
3326 mef_entry->filter[filt_num].filt_action = TYPE_OR;
3329 mef_entry->filter[filt_num].repeat = 16;
3330 memcpy(mef_entry->filter[filt_num].byte_seq, priv->curr_addr,
3332 mef_entry->filter[filt_num].byte_seq[MWIFIEX_MEF_MAX_BYTESEQ] =
3334 mef_entry->filter[filt_num].offset = 56;
3335 mef_entry->filter[filt_num].filt_type = TYPE_EQ;
3336 mef_entry->filter[filt_num].filt_action = TYPE_OR;
3337 mwifiex_dbg(priv->adapter, INFO, "Wake on magic packet\n");
3342 static int mwifiex_set_mef_filter(struct mwifiex_private *priv,
3343 struct cfg80211_wowlan *wowlan)
3345 int ret = 0, num_entries = 1;
3346 struct mwifiex_ds_mef_cfg mef_cfg;
3347 struct mwifiex_mef_entry *mef_entry;
3349 if (wowlan->n_patterns || wowlan->magic_pkt)
3352 mef_entry = kcalloc(num_entries, sizeof(*mef_entry), GFP_KERNEL);
3356 memset(&mef_cfg, 0, sizeof(mef_cfg));
3357 mef_cfg.criteria |= MWIFIEX_CRITERIA_BROADCAST |
3358 MWIFIEX_CRITERIA_UNICAST;
3359 mef_cfg.num_entries = num_entries;
3360 mef_cfg.mef_entry = mef_entry;
3362 mwifiex_set_auto_arp_mef_entry(priv, &mef_entry[0]);
3364 if (wowlan->n_patterns || wowlan->magic_pkt) {
3365 ret = mwifiex_set_wowlan_mef_entry(priv, &mef_cfg,
3366 &mef_entry[1], wowlan);
3371 if (!mef_cfg.criteria)
3372 mef_cfg.criteria = MWIFIEX_CRITERIA_BROADCAST |
3373 MWIFIEX_CRITERIA_UNICAST |
3374 MWIFIEX_CRITERIA_MULTICAST;
3376 ret = mwifiex_send_cmd(priv, HostCmd_CMD_MEF_CFG,
3377 HostCmd_ACT_GEN_SET, 0,
3385 static int mwifiex_cfg80211_suspend(struct wiphy *wiphy,
3386 struct cfg80211_wowlan *wowlan)
3388 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
3389 struct mwifiex_ds_hs_cfg hs_cfg;
3390 int i, ret = 0, retry_num = 10;
3391 struct mwifiex_private *priv;
3392 struct mwifiex_private *sta_priv =
3393 mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_STA);
3395 sta_priv->scan_aborting = true;
3396 for (i = 0; i < adapter->priv_num; i++) {
3397 priv = adapter->priv[i];
3398 mwifiex_abort_cac(priv);
3401 mwifiex_cancel_all_pending_cmd(adapter);
3403 for (i = 0; i < adapter->priv_num; i++) {
3404 priv = adapter->priv[i];
3405 if (priv && priv->netdev) {
3406 mwifiex_stop_net_dev_queue(priv->netdev, adapter);
3407 if (netif_carrier_ok(priv->netdev))
3408 netif_carrier_off(priv->netdev);
3412 for (i = 0; i < retry_num; i++) {
3413 if (!mwifiex_wmm_lists_empty(adapter) ||
3414 !mwifiex_bypass_txlist_empty(adapter) ||
3415 !skb_queue_empty(&adapter->tx_data_q))
3416 usleep_range(10000, 15000);
3422 mwifiex_dbg(adapter, ERROR,
3423 "None of the WOWLAN triggers enabled\n");
3428 if (!sta_priv->media_connected && !wowlan->nd_config) {
3429 mwifiex_dbg(adapter, ERROR,
3430 "Can not configure WOWLAN in disconnected state\n");
3435 ret = mwifiex_set_mef_filter(sta_priv, wowlan);
3437 mwifiex_dbg(adapter, ERROR, "Failed to set MEF filter\n");
3441 memset(&hs_cfg, 0, sizeof(hs_cfg));
3442 hs_cfg.conditions = le32_to_cpu(adapter->hs_cfg.conditions);
3444 if (wowlan->nd_config) {
3445 mwifiex_dbg(adapter, INFO, "Wake on net detect\n");
3446 hs_cfg.conditions |= HS_CFG_COND_MAC_EVENT;
3447 mwifiex_cfg80211_sched_scan_start(wiphy, sta_priv->netdev,
3451 if (wowlan->disconnect) {
3452 hs_cfg.conditions |= HS_CFG_COND_MAC_EVENT;
3453 mwifiex_dbg(sta_priv->adapter, INFO, "Wake on device disconnect\n");
3456 hs_cfg.is_invoke_hostcmd = false;
3457 hs_cfg.gpio = adapter->hs_cfg.gpio;
3458 hs_cfg.gap = adapter->hs_cfg.gap;
3459 ret = mwifiex_set_hs_params(sta_priv, HostCmd_ACT_GEN_SET,
3460 MWIFIEX_SYNC_CMD, &hs_cfg);
3462 mwifiex_dbg(adapter, ERROR, "Failed to set HS params\n");
3465 sta_priv->scan_aborting = false;
3469 static int mwifiex_cfg80211_resume(struct wiphy *wiphy)
3471 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
3472 struct mwifiex_private *priv;
3473 struct mwifiex_ds_wakeup_reason wakeup_reason;
3474 struct cfg80211_wowlan_wakeup wakeup_report;
3476 bool report_wakeup_reason = true;
3478 for (i = 0; i < adapter->priv_num; i++) {
3479 priv = adapter->priv[i];
3480 if (priv && priv->netdev) {
3481 if (!netif_carrier_ok(priv->netdev))
3482 netif_carrier_on(priv->netdev);
3483 mwifiex_wake_up_net_dev_queue(priv->netdev, adapter);
3487 if (!wiphy->wowlan_config)
3490 priv = mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_STA);
3491 mwifiex_get_wakeup_reason(priv, HostCmd_ACT_GEN_GET, MWIFIEX_SYNC_CMD,
3493 memset(&wakeup_report, 0, sizeof(struct cfg80211_wowlan_wakeup));
3495 wakeup_report.pattern_idx = -1;
3497 switch (wakeup_reason.hs_wakeup_reason) {
3498 case NO_HSWAKEUP_REASON:
3500 case BCAST_DATA_MATCHED:
3502 case MCAST_DATA_MATCHED:
3504 case UCAST_DATA_MATCHED:
3506 case MASKTABLE_EVENT_MATCHED:
3508 case NON_MASKABLE_EVENT_MATCHED:
3509 if (wiphy->wowlan_config->disconnect)
3510 wakeup_report.disconnect = true;
3511 if (wiphy->wowlan_config->nd_config)
3512 wakeup_report.net_detect = adapter->nd_info;
3514 case NON_MASKABLE_CONDITION_MATCHED:
3516 case MAGIC_PATTERN_MATCHED:
3517 if (wiphy->wowlan_config->magic_pkt)
3518 wakeup_report.magic_pkt = true;
3519 if (wiphy->wowlan_config->n_patterns)
3520 wakeup_report.pattern_idx = 1;
3522 case GTK_REKEY_FAILURE:
3523 if (wiphy->wowlan_config->gtk_rekey_failure)
3524 wakeup_report.gtk_rekey_failure = true;
3527 report_wakeup_reason = false;
3531 if (report_wakeup_reason)
3532 cfg80211_report_wowlan_wakeup(&priv->wdev, &wakeup_report,
3536 if (adapter->nd_info) {
3537 for (i = 0 ; i < adapter->nd_info->n_matches ; i++)
3538 kfree(adapter->nd_info->matches[i]);
3539 kfree(adapter->nd_info);
3540 adapter->nd_info = NULL;
3546 static void mwifiex_cfg80211_set_wakeup(struct wiphy *wiphy,
3549 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
3551 device_set_wakeup_enable(adapter->dev, enabled);
3554 static int mwifiex_set_rekey_data(struct wiphy *wiphy, struct net_device *dev,
3555 struct cfg80211_gtk_rekey_data *data)
3557 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
3559 return mwifiex_send_cmd(priv, HostCmd_CMD_GTK_REKEY_OFFLOAD_CFG,
3560 HostCmd_ACT_GEN_SET, 0, data, true);
3565 static int mwifiex_get_coalesce_pkt_type(u8 *byte_seq)
3567 const u8 ipv4_mc_mac[] = {0x33, 0x33};
3568 const u8 ipv6_mc_mac[] = {0x01, 0x00, 0x5e};
3569 const u8 bc_mac[] = {0xff, 0xff, 0xff, 0xff};
3571 if ((byte_seq[0] & 0x01) &&
3572 (byte_seq[MWIFIEX_COALESCE_MAX_BYTESEQ] == 1))
3573 return PACKET_TYPE_UNICAST;
3574 else if (!memcmp(byte_seq, bc_mac, 4))
3575 return PACKET_TYPE_BROADCAST;
3576 else if ((!memcmp(byte_seq, ipv4_mc_mac, 2) &&
3577 byte_seq[MWIFIEX_COALESCE_MAX_BYTESEQ] == 2) ||
3578 (!memcmp(byte_seq, ipv6_mc_mac, 3) &&
3579 byte_seq[MWIFIEX_COALESCE_MAX_BYTESEQ] == 3))
3580 return PACKET_TYPE_MULTICAST;
3586 mwifiex_fill_coalesce_rule_info(struct mwifiex_private *priv,
3587 struct cfg80211_coalesce_rules *crule,
3588 struct mwifiex_coalesce_rule *mrule)
3590 u8 byte_seq[MWIFIEX_COALESCE_MAX_BYTESEQ + 1];
3591 struct filt_field_param *param;
3594 mrule->max_coalescing_delay = crule->delay;
3596 param = mrule->params;
3598 for (i = 0; i < crule->n_patterns; i++) {
3599 memset(byte_seq, 0, sizeof(byte_seq));
3600 if (!mwifiex_is_pattern_supported(&crule->patterns[i],
3602 MWIFIEX_COALESCE_MAX_BYTESEQ)) {
3603 mwifiex_dbg(priv->adapter, ERROR,
3604 "Pattern not supported\n");
3608 if (!crule->patterns[i].pkt_offset) {
3611 pkt_type = mwifiex_get_coalesce_pkt_type(byte_seq);
3612 if (pkt_type && mrule->pkt_type) {
3613 mwifiex_dbg(priv->adapter, ERROR,
3614 "Multiple packet types not allowed\n");
3616 } else if (pkt_type) {
3617 mrule->pkt_type = pkt_type;
3622 if (crule->condition == NL80211_COALESCE_CONDITION_MATCH)
3623 param->operation = RECV_FILTER_MATCH_TYPE_EQ;
3625 param->operation = RECV_FILTER_MATCH_TYPE_NE;
3627 param->operand_len = byte_seq[MWIFIEX_COALESCE_MAX_BYTESEQ];
3628 memcpy(param->operand_byte_stream, byte_seq,
3629 param->operand_len);
3630 param->offset = crule->patterns[i].pkt_offset;
3633 mrule->num_of_fields++;
3636 if (!mrule->pkt_type) {
3637 mwifiex_dbg(priv->adapter, ERROR,
3638 "Packet type can not be determined\n");
3645 static int mwifiex_cfg80211_set_coalesce(struct wiphy *wiphy,
3646 struct cfg80211_coalesce *coalesce)
3648 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
3650 struct mwifiex_ds_coalesce_cfg coalesce_cfg;
3651 struct mwifiex_private *priv =
3652 mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_STA);
3654 memset(&coalesce_cfg, 0, sizeof(coalesce_cfg));
3656 mwifiex_dbg(adapter, WARN,
3657 "Disable coalesce and reset all previous rules\n");
3658 return mwifiex_send_cmd(priv, HostCmd_CMD_COALESCE_CFG,
3659 HostCmd_ACT_GEN_SET, 0,
3660 &coalesce_cfg, true);
3663 coalesce_cfg.num_of_rules = coalesce->n_rules;
3664 for (i = 0; i < coalesce->n_rules; i++) {
3665 ret = mwifiex_fill_coalesce_rule_info(priv, &coalesce->rules[i],
3666 &coalesce_cfg.rule[i]);
3668 mwifiex_dbg(adapter, ERROR,
3669 "Recheck the patterns provided for rule %d\n",
3675 return mwifiex_send_cmd(priv, HostCmd_CMD_COALESCE_CFG,
3676 HostCmd_ACT_GEN_SET, 0, &coalesce_cfg, true);
3679 /* cfg80211 ops handler for tdls_mgmt.
3680 * Function prepares TDLS action frame packets and forwards them to FW
3683 mwifiex_cfg80211_tdls_mgmt(struct wiphy *wiphy, struct net_device *dev,
3684 const u8 *peer, u8 action_code, u8 dialog_token,
3685 u16 status_code, u32 peer_capability,
3686 bool initiator, const u8 *extra_ies,
3687 size_t extra_ies_len)
3689 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
3692 if (!(wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS))
3695 /* make sure we are in station mode and connected */
3696 if (!(priv->bss_type == MWIFIEX_BSS_TYPE_STA && priv->media_connected))
3699 switch (action_code) {
3700 case WLAN_TDLS_SETUP_REQUEST:
3701 mwifiex_dbg(priv->adapter, MSG,
3702 "Send TDLS Setup Request to %pM status_code=%d\n",
3704 mwifiex_add_auto_tdls_peer(priv, peer);
3705 ret = mwifiex_send_tdls_data_frame(priv, peer, action_code,
3706 dialog_token, status_code,
3707 extra_ies, extra_ies_len);
3709 case WLAN_TDLS_SETUP_RESPONSE:
3710 mwifiex_add_auto_tdls_peer(priv, peer);
3711 mwifiex_dbg(priv->adapter, MSG,
3712 "Send TDLS Setup Response to %pM status_code=%d\n",
3714 ret = mwifiex_send_tdls_data_frame(priv, peer, action_code,
3715 dialog_token, status_code,
3716 extra_ies, extra_ies_len);
3718 case WLAN_TDLS_SETUP_CONFIRM:
3719 mwifiex_dbg(priv->adapter, MSG,
3720 "Send TDLS Confirm to %pM status_code=%d\n", peer,
3722 ret = mwifiex_send_tdls_data_frame(priv, peer, action_code,
3723 dialog_token, status_code,
3724 extra_ies, extra_ies_len);
3726 case WLAN_TDLS_TEARDOWN:
3727 mwifiex_dbg(priv->adapter, MSG,
3728 "Send TDLS Tear down to %pM\n", peer);
3729 ret = mwifiex_send_tdls_data_frame(priv, peer, action_code,
3730 dialog_token, status_code,
3731 extra_ies, extra_ies_len);
3733 case WLAN_TDLS_DISCOVERY_REQUEST:
3734 mwifiex_dbg(priv->adapter, MSG,
3735 "Send TDLS Discovery Request to %pM\n", peer);
3736 ret = mwifiex_send_tdls_data_frame(priv, peer, action_code,
3737 dialog_token, status_code,
3738 extra_ies, extra_ies_len);
3740 case WLAN_PUB_ACTION_TDLS_DISCOVER_RES:
3741 mwifiex_dbg(priv->adapter, MSG,
3742 "Send TDLS Discovery Response to %pM\n", peer);
3743 ret = mwifiex_send_tdls_action_frame(priv, peer, action_code,
3744 dialog_token, status_code,
3745 extra_ies, extra_ies_len);
3748 mwifiex_dbg(priv->adapter, ERROR,
3749 "Unknown TDLS mgmt/action frame %pM\n", peer);
3758 mwifiex_cfg80211_tdls_oper(struct wiphy *wiphy, struct net_device *dev,
3759 const u8 *peer, enum nl80211_tdls_operation action)
3761 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
3763 if (!(wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
3764 !(wiphy->flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP))
3767 /* make sure we are in station mode and connected */
3768 if (!(priv->bss_type == MWIFIEX_BSS_TYPE_STA && priv->media_connected))
3771 mwifiex_dbg(priv->adapter, MSG,
3772 "TDLS peer=%pM, oper=%d\n", peer, action);
3775 case NL80211_TDLS_ENABLE_LINK:
3776 action = MWIFIEX_TDLS_ENABLE_LINK;
3778 case NL80211_TDLS_DISABLE_LINK:
3779 action = MWIFIEX_TDLS_DISABLE_LINK;
3781 case NL80211_TDLS_TEARDOWN:
3782 /* shouldn't happen!*/
3783 mwifiex_dbg(priv->adapter, ERROR,
3784 "tdls_oper: teardown from driver not supported\n");
3786 case NL80211_TDLS_SETUP:
3787 /* shouldn't happen!*/
3788 mwifiex_dbg(priv->adapter, ERROR,
3789 "tdls_oper: setup from driver not supported\n");
3791 case NL80211_TDLS_DISCOVERY_REQ:
3792 /* shouldn't happen!*/
3793 mwifiex_dbg(priv->adapter, ERROR,
3794 "tdls_oper: discovery from driver not supported\n");
3797 mwifiex_dbg(priv->adapter, ERROR,
3798 "tdls_oper: operation not supported\n");
3802 return mwifiex_tdls_oper(priv, peer, action);
3806 mwifiex_cfg80211_tdls_chan_switch(struct wiphy *wiphy, struct net_device *dev,
3807 const u8 *addr, u8 oper_class,
3808 struct cfg80211_chan_def *chandef)
3810 struct mwifiex_sta_node *sta_ptr;
3811 unsigned long flags;
3813 u8 second_chan_offset, band;
3814 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
3816 spin_lock_irqsave(&priv->sta_list_spinlock, flags);
3817 sta_ptr = mwifiex_get_sta_entry(priv, addr);
3818 spin_unlock_irqrestore(&priv->sta_list_spinlock, flags);
3821 wiphy_err(wiphy, "%s: Invalid TDLS peer %pM\n",
3826 if (!(sta_ptr->tdls_cap.extcap.ext_capab[3] &
3827 WLAN_EXT_CAPA4_TDLS_CHAN_SWITCH)) {
3828 wiphy_err(wiphy, "%pM do not support tdls cs\n", addr);
3832 if (sta_ptr->tdls_status == TDLS_CHAN_SWITCHING ||
3833 sta_ptr->tdls_status == TDLS_IN_OFF_CHAN) {
3834 wiphy_err(wiphy, "channel switch is running, abort request\n");
3838 chan = chandef->chan->hw_value;
3839 second_chan_offset = mwifiex_get_sec_chan_offset(chan);
3840 band = chandef->chan->band;
3841 mwifiex_start_tdls_cs(priv, addr, chan, second_chan_offset, band);
3847 mwifiex_cfg80211_tdls_cancel_chan_switch(struct wiphy *wiphy,
3848 struct net_device *dev,
3851 struct mwifiex_sta_node *sta_ptr;
3852 unsigned long flags;
3853 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
3855 spin_lock_irqsave(&priv->sta_list_spinlock, flags);
3856 sta_ptr = mwifiex_get_sta_entry(priv, addr);
3857 spin_unlock_irqrestore(&priv->sta_list_spinlock, flags);
3860 wiphy_err(wiphy, "%s: Invalid TDLS peer %pM\n",
3862 } else if (!(sta_ptr->tdls_status == TDLS_CHAN_SWITCHING ||
3863 sta_ptr->tdls_status == TDLS_IN_BASE_CHAN ||
3864 sta_ptr->tdls_status == TDLS_IN_OFF_CHAN)) {
3865 wiphy_err(wiphy, "tdls chan switch not initialize by %pM\n",
3868 mwifiex_stop_tdls_cs(priv, addr);
3872 mwifiex_cfg80211_add_station(struct wiphy *wiphy, struct net_device *dev,
3873 const u8 *mac, struct station_parameters *params)
3875 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
3877 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
3880 /* make sure we are in station mode and connected */
3881 if ((priv->bss_type != MWIFIEX_BSS_TYPE_STA) || !priv->media_connected)
3884 return mwifiex_tdls_oper(priv, mac, MWIFIEX_TDLS_CREATE_LINK);
3888 mwifiex_cfg80211_channel_switch(struct wiphy *wiphy, struct net_device *dev,
3889 struct cfg80211_csa_settings *params)
3891 struct ieee_types_header *chsw_ie;
3892 struct ieee80211_channel_sw_ie *channel_sw;
3894 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
3896 if (priv->adapter->scan_processing) {
3897 mwifiex_dbg(priv->adapter, ERROR,
3898 "radar detection: scan in process...\n");
3902 if (priv->wdev.cac_started)
3905 if (cfg80211_chandef_identical(¶ms->chandef,
3906 &priv->dfs_chandef))
3909 chsw_ie = (void *)cfg80211_find_ie(WLAN_EID_CHANNEL_SWITCH,
3910 params->beacon_csa.tail,
3911 params->beacon_csa.tail_len);
3913 mwifiex_dbg(priv->adapter, ERROR,
3914 "Could not parse channel switch announcement IE\n");
3918 channel_sw = (void *)(chsw_ie + 1);
3919 if (channel_sw->mode) {
3920 if (netif_carrier_ok(priv->netdev))
3921 netif_carrier_off(priv->netdev);
3922 mwifiex_stop_net_dev_queue(priv->netdev, priv->adapter);
3925 if (mwifiex_del_mgmt_ies(priv))
3926 mwifiex_dbg(priv->adapter, ERROR,
3927 "Failed to delete mgmt IEs!\n");
3929 if (mwifiex_set_mgmt_ies(priv, ¶ms->beacon_csa)) {
3930 mwifiex_dbg(priv->adapter, ERROR,
3931 "%s: setting mgmt ies failed\n", __func__);
3935 memcpy(&priv->dfs_chandef, ¶ms->chandef, sizeof(priv->dfs_chandef));
3936 memcpy(&priv->beacon_after, ¶ms->beacon_after,
3937 sizeof(priv->beacon_after));
3939 chsw_msec = max(channel_sw->count * priv->bss_cfg.beacon_period, 100);
3940 queue_delayed_work(priv->dfs_chan_sw_workqueue, &priv->dfs_chan_sw_work,
3941 msecs_to_jiffies(chsw_msec));
3945 static int mwifiex_cfg80211_get_channel(struct wiphy *wiphy,
3946 struct wireless_dev *wdev,
3947 struct cfg80211_chan_def *chandef)
3949 struct mwifiex_private *priv = mwifiex_netdev_get_priv(wdev->netdev);
3950 struct mwifiex_bssdescriptor *curr_bss;
3951 struct ieee80211_channel *chan;
3952 u8 second_chan_offset;
3953 enum nl80211_channel_type chan_type;
3954 enum nl80211_band band;
3958 if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_UAP &&
3959 cfg80211_chandef_valid(&priv->bss_chandef)) {
3960 *chandef = priv->bss_chandef;
3962 } else if (priv->media_connected) {
3963 curr_bss = &priv->curr_bss_params.bss_descriptor;
3964 band = mwifiex_band_to_radio_type(priv->curr_bss_params.band);
3965 freq = ieee80211_channel_to_frequency(curr_bss->channel, band);
3966 chan = ieee80211_get_channel(wiphy, freq);
3968 if (priv->ht_param_present) {
3969 second_chan_offset = priv->assoc_resp_ht_param &
3970 IEEE80211_HT_PARAM_CHA_SEC_OFFSET;
3971 chan_type = mwifiex_sec_chan_offset_to_chan_type
3972 (second_chan_offset);
3973 cfg80211_chandef_create(chandef, chan, chan_type);
3975 cfg80211_chandef_create(chandef, chan,
3976 NL80211_CHAN_NO_HT);
3984 #ifdef CONFIG_NL80211_TESTMODE
3986 enum mwifiex_tm_attr {
3987 __MWIFIEX_TM_ATTR_INVALID = 0,
3988 MWIFIEX_TM_ATTR_CMD = 1,
3989 MWIFIEX_TM_ATTR_DATA = 2,
3992 __MWIFIEX_TM_ATTR_AFTER_LAST,
3993 MWIFIEX_TM_ATTR_MAX = __MWIFIEX_TM_ATTR_AFTER_LAST - 1,
3996 static const struct nla_policy mwifiex_tm_policy[MWIFIEX_TM_ATTR_MAX + 1] = {
3997 [MWIFIEX_TM_ATTR_CMD] = { .type = NLA_U32 },
3998 [MWIFIEX_TM_ATTR_DATA] = { .type = NLA_BINARY,
3999 .len = MWIFIEX_SIZE_OF_CMD_BUFFER },
4002 enum mwifiex_tm_command {
4003 MWIFIEX_TM_CMD_HOSTCMD = 0,
4006 static int mwifiex_tm_cmd(struct wiphy *wiphy, struct wireless_dev *wdev,
4007 void *data, int len)
4009 struct mwifiex_private *priv = mwifiex_netdev_get_priv(wdev->netdev);
4010 struct mwifiex_ds_misc_cmd *hostcmd;
4011 struct nlattr *tb[MWIFIEX_TM_ATTR_MAX + 1];
4012 struct sk_buff *skb;
4018 err = nla_parse(tb, MWIFIEX_TM_ATTR_MAX, data, len, mwifiex_tm_policy,
4023 if (!tb[MWIFIEX_TM_ATTR_CMD])
4026 switch (nla_get_u32(tb[MWIFIEX_TM_ATTR_CMD])) {
4027 case MWIFIEX_TM_CMD_HOSTCMD:
4028 if (!tb[MWIFIEX_TM_ATTR_DATA])
4031 hostcmd = kzalloc(sizeof(*hostcmd), GFP_KERNEL);
4035 hostcmd->len = nla_len(tb[MWIFIEX_TM_ATTR_DATA]);
4036 memcpy(hostcmd->cmd, nla_data(tb[MWIFIEX_TM_ATTR_DATA]),
4039 if (mwifiex_send_cmd(priv, 0, 0, 0, hostcmd, true)) {
4040 dev_err(priv->adapter->dev, "Failed to process hostcmd\n");
4044 /* process hostcmd response*/
4045 skb = cfg80211_testmode_alloc_reply_skb(wiphy, hostcmd->len);
4048 err = nla_put(skb, MWIFIEX_TM_ATTR_DATA,
4049 hostcmd->len, hostcmd->cmd);
4055 err = cfg80211_testmode_reply(skb);
4065 mwifiex_cfg80211_start_radar_detection(struct wiphy *wiphy,
4066 struct net_device *dev,
4067 struct cfg80211_chan_def *chandef,
4070 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
4071 struct mwifiex_radar_params radar_params;
4073 if (priv->adapter->scan_processing) {
4074 mwifiex_dbg(priv->adapter, ERROR,
4075 "radar detection: scan already in process...\n");
4079 if (!mwifiex_is_11h_active(priv)) {
4080 mwifiex_dbg(priv->adapter, INFO,
4081 "Enable 11h extensions in FW\n");
4082 if (mwifiex_11h_activate(priv, true)) {
4083 mwifiex_dbg(priv->adapter, ERROR,
4084 "Failed to activate 11h extensions!!");
4087 priv->state_11h.is_11h_active = true;
4090 memset(&radar_params, 0, sizeof(struct mwifiex_radar_params));
4091 radar_params.chandef = chandef;
4092 radar_params.cac_time_ms = cac_time_ms;
4094 memcpy(&priv->dfs_chandef, chandef, sizeof(priv->dfs_chandef));
4096 if (mwifiex_send_cmd(priv, HostCmd_CMD_CHAN_REPORT_REQUEST,
4097 HostCmd_ACT_GEN_SET, 0, &radar_params, true))
4100 queue_delayed_work(priv->dfs_cac_workqueue, &priv->dfs_cac_work,
4101 msecs_to_jiffies(cac_time_ms));
4106 mwifiex_cfg80211_change_station(struct wiphy *wiphy, struct net_device *dev,
4108 struct station_parameters *params)
4111 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
4113 /* we support change_station handler only for TDLS peers*/
4114 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
4117 /* make sure we are in station mode and connected */
4118 if ((priv->bss_type != MWIFIEX_BSS_TYPE_STA) || !priv->media_connected)
4121 priv->sta_params = params;
4123 ret = mwifiex_tdls_oper(priv, mac, MWIFIEX_TDLS_CONFIG_LINK);
4124 priv->sta_params = NULL;
4129 /* station cfg80211 operations */
4130 static struct cfg80211_ops mwifiex_cfg80211_ops = {
4131 .add_virtual_intf = mwifiex_add_virtual_intf,
4132 .del_virtual_intf = mwifiex_del_virtual_intf,
4133 .change_virtual_intf = mwifiex_cfg80211_change_virtual_intf,
4134 .scan = mwifiex_cfg80211_scan,
4135 .connect = mwifiex_cfg80211_connect,
4136 .disconnect = mwifiex_cfg80211_disconnect,
4137 .get_station = mwifiex_cfg80211_get_station,
4138 .dump_station = mwifiex_cfg80211_dump_station,
4139 .dump_survey = mwifiex_cfg80211_dump_survey,
4140 .set_wiphy_params = mwifiex_cfg80211_set_wiphy_params,
4141 .join_ibss = mwifiex_cfg80211_join_ibss,
4142 .leave_ibss = mwifiex_cfg80211_leave_ibss,
4143 .add_key = mwifiex_cfg80211_add_key,
4144 .del_key = mwifiex_cfg80211_del_key,
4145 .set_default_mgmt_key = mwifiex_cfg80211_set_default_mgmt_key,
4146 .mgmt_tx = mwifiex_cfg80211_mgmt_tx,
4147 .mgmt_frame_register = mwifiex_cfg80211_mgmt_frame_register,
4148 .remain_on_channel = mwifiex_cfg80211_remain_on_channel,
4149 .cancel_remain_on_channel = mwifiex_cfg80211_cancel_remain_on_channel,
4150 .set_default_key = mwifiex_cfg80211_set_default_key,
4151 .set_power_mgmt = mwifiex_cfg80211_set_power_mgmt,
4152 .set_tx_power = mwifiex_cfg80211_set_tx_power,
4153 .get_tx_power = mwifiex_cfg80211_get_tx_power,
4154 .set_bitrate_mask = mwifiex_cfg80211_set_bitrate_mask,
4155 .start_ap = mwifiex_cfg80211_start_ap,
4156 .stop_ap = mwifiex_cfg80211_stop_ap,
4157 .change_beacon = mwifiex_cfg80211_change_beacon,
4158 .set_cqm_rssi_config = mwifiex_cfg80211_set_cqm_rssi_config,
4159 .set_antenna = mwifiex_cfg80211_set_antenna,
4160 .get_antenna = mwifiex_cfg80211_get_antenna,
4161 .del_station = mwifiex_cfg80211_del_station,
4162 .sched_scan_start = mwifiex_cfg80211_sched_scan_start,
4163 .sched_scan_stop = mwifiex_cfg80211_sched_scan_stop,
4165 .suspend = mwifiex_cfg80211_suspend,
4166 .resume = mwifiex_cfg80211_resume,
4167 .set_wakeup = mwifiex_cfg80211_set_wakeup,
4168 .set_rekey_data = mwifiex_set_rekey_data,
4170 .set_coalesce = mwifiex_cfg80211_set_coalesce,
4171 .tdls_mgmt = mwifiex_cfg80211_tdls_mgmt,
4172 .tdls_oper = mwifiex_cfg80211_tdls_oper,
4173 .tdls_channel_switch = mwifiex_cfg80211_tdls_chan_switch,
4174 .tdls_cancel_channel_switch = mwifiex_cfg80211_tdls_cancel_chan_switch,
4175 .add_station = mwifiex_cfg80211_add_station,
4176 .change_station = mwifiex_cfg80211_change_station,
4177 CFG80211_TESTMODE_CMD(mwifiex_tm_cmd)
4178 .get_channel = mwifiex_cfg80211_get_channel,
4179 .start_radar_detection = mwifiex_cfg80211_start_radar_detection,
4180 .channel_switch = mwifiex_cfg80211_channel_switch,
4184 static const struct wiphy_wowlan_support mwifiex_wowlan_support = {
4185 .flags = WIPHY_WOWLAN_MAGIC_PKT | WIPHY_WOWLAN_DISCONNECT |
4186 WIPHY_WOWLAN_NET_DETECT | WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
4187 WIPHY_WOWLAN_GTK_REKEY_FAILURE,
4188 .n_patterns = MWIFIEX_MEF_MAX_FILTERS,
4189 .pattern_min_len = 1,
4190 .pattern_max_len = MWIFIEX_MAX_PATTERN_LEN,
4191 .max_pkt_offset = MWIFIEX_MAX_OFFSET_LEN,
4192 .max_nd_match_sets = MWIFIEX_MAX_ND_MATCH_SETS,
4196 static bool mwifiex_is_valid_alpha2(const char *alpha2)
4198 if (!alpha2 || strlen(alpha2) != 2)
4201 if (isalpha(alpha2[0]) && isalpha(alpha2[1]))
4207 static const struct wiphy_coalesce_support mwifiex_coalesce_support = {
4208 .n_rules = MWIFIEX_COALESCE_MAX_RULES,
4209 .max_delay = MWIFIEX_MAX_COALESCING_DELAY,
4210 .n_patterns = MWIFIEX_COALESCE_MAX_FILTERS,
4211 .pattern_min_len = 1,
4212 .pattern_max_len = MWIFIEX_MAX_PATTERN_LEN,
4213 .max_pkt_offset = MWIFIEX_MAX_OFFSET_LEN,
4216 int mwifiex_init_channel_scan_gap(struct mwifiex_adapter *adapter)
4218 u32 n_channels_bg, n_channels_a = 0;
4220 n_channels_bg = mwifiex_band_2ghz.n_channels;
4222 if (adapter->config_bands & BAND_A)
4223 n_channels_a = mwifiex_band_5ghz.n_channels;
4225 adapter->num_in_chan_stats = max_t(u32, n_channels_bg, n_channels_a);
4226 adapter->chan_stats = vmalloc(sizeof(*adapter->chan_stats) *
4227 adapter->num_in_chan_stats);
4229 if (!adapter->chan_stats)
4236 * This function registers the device with CFG802.11 subsystem.
4238 * The function creates the wireless device/wiphy, populates it with
4239 * default parameters and handler function pointers, and finally
4240 * registers the device.
4243 int mwifiex_register_cfg80211(struct mwifiex_adapter *adapter)
4247 struct wiphy *wiphy;
4248 struct mwifiex_private *priv = adapter->priv[MWIFIEX_BSS_TYPE_STA];
4252 /* create a new wiphy for use with cfg80211 */
4253 wiphy = wiphy_new(&mwifiex_cfg80211_ops,
4254 sizeof(struct mwifiex_adapter *));
4256 mwifiex_dbg(adapter, ERROR,
4257 "%s: creating new wiphy\n", __func__);
4260 wiphy->max_scan_ssids = MWIFIEX_MAX_SSID_LIST_LENGTH;
4261 wiphy->max_scan_ie_len = MWIFIEX_MAX_VSIE_LEN;
4262 wiphy->mgmt_stypes = mwifiex_mgmt_stypes;
4263 wiphy->max_remain_on_channel_duration = 5000;
4264 wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
4265 BIT(NL80211_IFTYPE_ADHOC) |
4266 BIT(NL80211_IFTYPE_P2P_CLIENT) |
4267 BIT(NL80211_IFTYPE_P2P_GO) |
4268 BIT(NL80211_IFTYPE_AP);
4270 wiphy->bands[NL80211_BAND_2GHZ] = &mwifiex_band_2ghz;
4271 if (adapter->config_bands & BAND_A)
4272 wiphy->bands[NL80211_BAND_5GHZ] = &mwifiex_band_5ghz;
4274 wiphy->bands[NL80211_BAND_5GHZ] = NULL;
4276 if (adapter->drcs_enabled && ISSUPP_DRCS_ENABLED(adapter->fw_cap_info))
4277 wiphy->iface_combinations = &mwifiex_iface_comb_ap_sta_drcs;
4278 else if (adapter->is_hw_11ac_capable)
4279 wiphy->iface_combinations = &mwifiex_iface_comb_ap_sta_vht;
4281 wiphy->iface_combinations = &mwifiex_iface_comb_ap_sta;
4282 wiphy->n_iface_combinations = 1;
4284 /* Initialize cipher suits */
4285 wiphy->cipher_suites = mwifiex_cipher_suites;
4286 wiphy->n_cipher_suites = ARRAY_SIZE(mwifiex_cipher_suites);
4288 if (adapter->regd) {
4289 wiphy->regulatory_flags |= REGULATORY_CUSTOM_REG |
4290 REGULATORY_DISABLE_BEACON_HINTS |
4291 REGULATORY_COUNTRY_IE_IGNORE;
4292 wiphy_apply_custom_regulatory(wiphy, adapter->regd);
4295 ether_addr_copy(wiphy->perm_addr, adapter->perm_addr);
4296 wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
4297 wiphy->flags |= WIPHY_FLAG_HAVE_AP_SME |
4298 WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD |
4299 WIPHY_FLAG_AP_UAPSD |
4300 WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL |
4301 WIPHY_FLAG_HAS_CHANNEL_SWITCH |
4302 WIPHY_FLAG_PS_ON_BY_DEFAULT;
4304 if (ISSUPP_TDLS_ENABLED(adapter->fw_cap_info))
4305 wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS |
4306 WIPHY_FLAG_TDLS_EXTERNAL_SETUP;
4309 wiphy->wowlan = &mwifiex_wowlan_support;
4312 wiphy->coalesce = &mwifiex_coalesce_support;
4314 wiphy->probe_resp_offload = NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS |
4315 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2 |
4316 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P;
4318 wiphy->max_sched_scan_reqs = 1;
4319 wiphy->max_sched_scan_ssids = MWIFIEX_MAX_SSID_LIST_LENGTH;
4320 wiphy->max_sched_scan_ie_len = MWIFIEX_MAX_VSIE_LEN;
4321 wiphy->max_match_sets = MWIFIEX_MAX_SSID_LIST_LENGTH;
4323 wiphy->available_antennas_tx = BIT(adapter->number_of_antenna) - 1;
4324 wiphy->available_antennas_rx = BIT(adapter->number_of_antenna) - 1;
4326 wiphy->features |= NL80211_FEATURE_HT_IBSS |
4327 NL80211_FEATURE_INACTIVITY_TIMER |
4328 NL80211_FEATURE_LOW_PRIORITY_SCAN |
4329 NL80211_FEATURE_NEED_OBSS_SCAN |
4330 NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR |
4331 NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR |
4332 NL80211_FEATURE_ND_RANDOM_MAC_ADDR;
4334 if (ISSUPP_TDLS_ENABLED(adapter->fw_cap_info))
4335 wiphy->features |= NL80211_FEATURE_TDLS_CHANNEL_SWITCH;
4337 if (adapter->fw_api_ver == MWIFIEX_FW_V15)
4338 wiphy->features |= NL80211_FEATURE_SK_TX_STATUS;
4340 /* Reserve space for mwifiex specific private data for BSS */
4341 wiphy->bss_priv_size = sizeof(struct mwifiex_bss_priv);
4343 wiphy->reg_notifier = mwifiex_reg_notifier;
4345 /* Set struct mwifiex_adapter pointer in wiphy_priv */
4346 wdev_priv = wiphy_priv(wiphy);
4347 *(unsigned long *)wdev_priv = (unsigned long)adapter;
4349 set_wiphy_dev(wiphy, priv->adapter->dev);
4351 ret = wiphy_register(wiphy);
4353 mwifiex_dbg(adapter, ERROR,
4354 "%s: wiphy_register failed: %d\n", __func__, ret);
4359 if (!adapter->regd) {
4360 if (reg_alpha2 && mwifiex_is_valid_alpha2(reg_alpha2)) {
4361 mwifiex_dbg(adapter, INFO,
4362 "driver hint alpha2: %2.2s\n", reg_alpha2);
4363 regulatory_hint(wiphy, reg_alpha2);
4365 if (adapter->region_code == 0x00) {
4366 mwifiex_dbg(adapter, WARN,
4367 "Ignore world regulatory domain\n");
4369 wiphy->regulatory_flags |=
4370 REGULATORY_DISABLE_BEACON_HINTS |
4371 REGULATORY_COUNTRY_IE_IGNORE;
4373 mwifiex_11d_code_2_region(
4374 adapter->region_code);
4376 regulatory_hint(wiphy, country_code))
4377 mwifiex_dbg(priv->adapter, ERROR,
4378 "regulatory_hint() failed\n");
4383 mwifiex_send_cmd(priv, HostCmd_CMD_802_11_SNMP_MIB,
4384 HostCmd_ACT_GEN_GET, FRAG_THRESH_I, &thr, true);
4385 wiphy->frag_threshold = thr;
4386 mwifiex_send_cmd(priv, HostCmd_CMD_802_11_SNMP_MIB,
4387 HostCmd_ACT_GEN_GET, RTS_THRESH_I, &thr, true);
4388 wiphy->rts_threshold = thr;
4389 mwifiex_send_cmd(priv, HostCmd_CMD_802_11_SNMP_MIB,
4390 HostCmd_ACT_GEN_GET, SHORT_RETRY_LIM_I, &retry, true);
4391 wiphy->retry_short = (u8) retry;
4392 mwifiex_send_cmd(priv, HostCmd_CMD_802_11_SNMP_MIB,
4393 HostCmd_ACT_GEN_GET, LONG_RETRY_LIM_I, &retry, true);
4394 wiphy->retry_long = (u8) retry;
4396 adapter->wiphy = wiphy;