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_get_chan_type(struct mwifiex_private *priv)
100 struct mwifiex_channel_band channel_band;
103 ret = mwifiex_get_chan_info(priv, &channel_band);
106 switch (channel_band.band_config.chan_width) {
108 if (IS_11N_ENABLED(priv))
109 return NL80211_CHAN_HT20;
111 return NL80211_CHAN_NO_HT;
113 if (channel_band.band_config.chan2_offset ==
115 return NL80211_CHAN_HT40PLUS;
117 return NL80211_CHAN_HT40MINUS;
119 return NL80211_CHAN_HT20;
123 return NL80211_CHAN_HT20;
127 * This function checks whether WEP is set.
130 mwifiex_is_alg_wep(u32 cipher)
133 case WLAN_CIPHER_SUITE_WEP40:
134 case WLAN_CIPHER_SUITE_WEP104:
144 * This function retrieves the private structure from kernel wiphy structure.
146 static void *mwifiex_cfg80211_get_adapter(struct wiphy *wiphy)
148 return (void *) (*(unsigned long *) wiphy_priv(wiphy));
152 * CFG802.11 operation handler to delete a network key.
155 mwifiex_cfg80211_del_key(struct wiphy *wiphy, struct net_device *netdev,
156 u8 key_index, bool pairwise, const u8 *mac_addr)
158 struct mwifiex_private *priv = mwifiex_netdev_get_priv(netdev);
159 static const u8 bc_mac[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
160 const u8 *peer_mac = pairwise ? mac_addr : bc_mac;
162 if (mwifiex_set_encode(priv, NULL, NULL, 0, key_index, peer_mac, 1)) {
163 mwifiex_dbg(priv->adapter, ERROR, "deleting the crypto keys\n");
167 mwifiex_dbg(priv->adapter, INFO, "info: crypto keys deleted\n");
172 * This function forms an skb for management frame.
175 mwifiex_form_mgmt_frame(struct sk_buff *skb, const u8 *buf, size_t len)
177 u8 addr[ETH_ALEN] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
179 u32 tx_control = 0, pkt_type = PKT_TYPE_MGMT;
181 pkt_len = len + ETH_ALEN;
183 skb_reserve(skb, MWIFIEX_MIN_DATA_HEADER_LEN +
184 MWIFIEX_MGMT_FRAME_HEADER_SIZE + sizeof(pkt_len));
185 memcpy(skb_push(skb, sizeof(pkt_len)), &pkt_len, sizeof(pkt_len));
187 memcpy(skb_push(skb, sizeof(tx_control)),
188 &tx_control, sizeof(tx_control));
190 memcpy(skb_push(skb, sizeof(pkt_type)), &pkt_type, sizeof(pkt_type));
192 /* Add packet data and address4 */
193 skb_put_data(skb, buf, sizeof(struct ieee80211_hdr_3addr));
194 skb_put_data(skb, addr, ETH_ALEN);
195 skb_put_data(skb, buf + sizeof(struct ieee80211_hdr_3addr),
196 len - sizeof(struct ieee80211_hdr_3addr));
198 skb->priority = LOW_PRIO_TID;
199 __net_timestamp(skb);
205 * CFG802.11 operation handler to transmit a management frame.
208 mwifiex_cfg80211_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev,
209 struct cfg80211_mgmt_tx_params *params, u64 *cookie)
211 const u8 *buf = params->buf;
212 size_t len = params->len;
215 const struct ieee80211_mgmt *mgmt;
216 struct mwifiex_txinfo *tx_info;
217 struct mwifiex_private *priv = mwifiex_netdev_get_priv(wdev->netdev);
220 mwifiex_dbg(priv->adapter, ERROR, "invalid buffer and length\n");
224 mgmt = (const struct ieee80211_mgmt *)buf;
225 if (GET_BSS_ROLE(priv) != MWIFIEX_BSS_ROLE_STA &&
226 ieee80211_is_probe_resp(mgmt->frame_control)) {
227 /* Since we support offload probe resp, we need to skip probe
228 * resp in AP or GO mode */
229 mwifiex_dbg(priv->adapter, INFO,
230 "info: skip to send probe resp in AP or GO mode\n");
234 pkt_len = len + ETH_ALEN;
235 skb = dev_alloc_skb(MWIFIEX_MIN_DATA_HEADER_LEN +
236 MWIFIEX_MGMT_FRAME_HEADER_SIZE +
237 pkt_len + sizeof(pkt_len));
240 mwifiex_dbg(priv->adapter, ERROR,
241 "allocate skb failed for management frame\n");
245 tx_info = MWIFIEX_SKB_TXCB(skb);
246 memset(tx_info, 0, sizeof(*tx_info));
247 tx_info->bss_num = priv->bss_num;
248 tx_info->bss_type = priv->bss_type;
249 tx_info->pkt_len = pkt_len;
251 mwifiex_form_mgmt_frame(skb, buf, len);
252 *cookie = prandom_u32() | 1;
254 if (ieee80211_is_action(mgmt->frame_control))
255 skb = mwifiex_clone_skb_for_tx_status(priv,
257 MWIFIEX_BUF_FLAG_ACTION_TX_STATUS, cookie);
259 cfg80211_mgmt_tx_status(wdev, *cookie, buf, len, true,
262 mwifiex_queue_tx_pkt(priv, skb);
264 mwifiex_dbg(priv->adapter, INFO, "info: management frame transmitted\n");
269 * CFG802.11 operation handler to register a mgmt frame.
272 mwifiex_cfg80211_mgmt_frame_register(struct wiphy *wiphy,
273 struct wireless_dev *wdev,
274 u16 frame_type, bool reg)
276 struct mwifiex_private *priv = mwifiex_netdev_get_priv(wdev->netdev);
280 mask = priv->mgmt_frame_mask | BIT(frame_type >> 4);
282 mask = priv->mgmt_frame_mask & ~BIT(frame_type >> 4);
284 if (mask != priv->mgmt_frame_mask) {
285 priv->mgmt_frame_mask = mask;
286 mwifiex_send_cmd(priv, HostCmd_CMD_MGMT_FRAME_REG,
287 HostCmd_ACT_GEN_SET, 0,
288 &priv->mgmt_frame_mask, false);
289 mwifiex_dbg(priv->adapter, INFO, "info: mgmt frame registered\n");
294 * CFG802.11 operation handler to remain on channel.
297 mwifiex_cfg80211_remain_on_channel(struct wiphy *wiphy,
298 struct wireless_dev *wdev,
299 struct ieee80211_channel *chan,
300 unsigned int duration, u64 *cookie)
302 struct mwifiex_private *priv = mwifiex_netdev_get_priv(wdev->netdev);
305 if (!chan || !cookie) {
306 mwifiex_dbg(priv->adapter, ERROR, "Invalid parameter for ROC\n");
310 if (priv->roc_cfg.cookie) {
311 mwifiex_dbg(priv->adapter, INFO,
312 "info: ongoing ROC, cookie = 0x%llx\n",
313 priv->roc_cfg.cookie);
317 ret = mwifiex_remain_on_chan_cfg(priv, HostCmd_ACT_GEN_SET, chan,
321 *cookie = prandom_u32() | 1;
322 priv->roc_cfg.cookie = *cookie;
323 priv->roc_cfg.chan = *chan;
325 cfg80211_ready_on_channel(wdev, *cookie, chan,
326 duration, GFP_ATOMIC);
328 mwifiex_dbg(priv->adapter, INFO,
329 "info: ROC, cookie = 0x%llx\n", *cookie);
336 * CFG802.11 operation handler to cancel remain on channel.
339 mwifiex_cfg80211_cancel_remain_on_channel(struct wiphy *wiphy,
340 struct wireless_dev *wdev, u64 cookie)
342 struct mwifiex_private *priv = mwifiex_netdev_get_priv(wdev->netdev);
345 if (cookie != priv->roc_cfg.cookie)
348 ret = mwifiex_remain_on_chan_cfg(priv, HostCmd_ACT_GEN_REMOVE,
349 &priv->roc_cfg.chan, 0);
352 cfg80211_remain_on_channel_expired(wdev, cookie,
356 memset(&priv->roc_cfg, 0, sizeof(struct mwifiex_roc_cfg));
358 mwifiex_dbg(priv->adapter, INFO,
359 "info: cancel ROC, cookie = 0x%llx\n", cookie);
366 * CFG802.11 operation handler to set Tx power.
369 mwifiex_cfg80211_set_tx_power(struct wiphy *wiphy,
370 struct wireless_dev *wdev,
371 enum nl80211_tx_power_setting type,
374 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
375 struct mwifiex_private *priv;
376 struct mwifiex_power_cfg power_cfg;
377 int dbm = MBM_TO_DBM(mbm);
380 case NL80211_TX_POWER_FIXED:
381 power_cfg.is_power_auto = 0;
382 power_cfg.is_power_fixed = 1;
383 power_cfg.power_level = dbm;
385 case NL80211_TX_POWER_LIMITED:
386 power_cfg.is_power_auto = 0;
387 power_cfg.is_power_fixed = 0;
388 power_cfg.power_level = dbm;
390 case NL80211_TX_POWER_AUTOMATIC:
391 power_cfg.is_power_auto = 1;
395 priv = mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY);
397 return mwifiex_set_tx_power(priv, &power_cfg);
401 * CFG802.11 operation handler to get Tx power.
404 mwifiex_cfg80211_get_tx_power(struct wiphy *wiphy,
405 struct wireless_dev *wdev,
408 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
409 struct mwifiex_private *priv = mwifiex_get_priv(adapter,
410 MWIFIEX_BSS_ROLE_ANY);
411 int ret = mwifiex_send_cmd(priv, HostCmd_CMD_RF_TX_PWR,
412 HostCmd_ACT_GEN_GET, 0, NULL, true);
417 /* tx_power_level is set in HostCmd_CMD_RF_TX_PWR command handler */
418 *dbm = priv->tx_power_level;
424 * CFG802.11 operation handler to set Power Save option.
426 * The timeout value, if provided, is currently ignored.
429 mwifiex_cfg80211_set_power_mgmt(struct wiphy *wiphy,
430 struct net_device *dev,
431 bool enabled, int timeout)
433 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
437 mwifiex_dbg(priv->adapter, INFO,
438 "info: ignore timeout value for IEEE Power Save\n");
442 return mwifiex_drv_set_power(priv, &ps_mode);
446 * CFG802.11 operation handler to set the default network key.
449 mwifiex_cfg80211_set_default_key(struct wiphy *wiphy, struct net_device *netdev,
450 u8 key_index, bool unicast,
453 struct mwifiex_private *priv = mwifiex_netdev_get_priv(netdev);
455 /* Return if WEP key not configured */
456 if (!priv->sec_info.wep_enabled)
459 if (priv->bss_type == MWIFIEX_BSS_TYPE_UAP) {
460 priv->wep_key_curr_index = key_index;
461 } else if (mwifiex_set_encode(priv, NULL, NULL, 0, key_index,
463 mwifiex_dbg(priv->adapter, ERROR, "set default Tx key index\n");
471 * CFG802.11 operation handler to add a network key.
474 mwifiex_cfg80211_add_key(struct wiphy *wiphy, struct net_device *netdev,
475 u8 key_index, bool pairwise, const u8 *mac_addr,
476 struct key_params *params)
478 struct mwifiex_private *priv = mwifiex_netdev_get_priv(netdev);
479 struct mwifiex_wep_key *wep_key;
480 static const u8 bc_mac[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
481 const u8 *peer_mac = pairwise ? mac_addr : bc_mac;
483 if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_UAP &&
484 (params->cipher == WLAN_CIPHER_SUITE_WEP40 ||
485 params->cipher == WLAN_CIPHER_SUITE_WEP104)) {
486 if (params->key && params->key_len) {
487 wep_key = &priv->wep_key[key_index];
488 memset(wep_key, 0, sizeof(struct mwifiex_wep_key));
489 memcpy(wep_key->key_material, params->key,
491 wep_key->key_index = key_index;
492 wep_key->key_length = params->key_len;
493 priv->sec_info.wep_enabled = 1;
498 if (mwifiex_set_encode(priv, params, params->key, params->key_len,
499 key_index, peer_mac, 0)) {
500 mwifiex_dbg(priv->adapter, ERROR, "crypto keys added\n");
508 * CFG802.11 operation handler to set default mgmt key.
511 mwifiex_cfg80211_set_default_mgmt_key(struct wiphy *wiphy,
512 struct net_device *netdev,
515 struct mwifiex_private *priv = mwifiex_netdev_get_priv(netdev);
516 struct mwifiex_ds_encrypt_key encrypt_key;
518 wiphy_dbg(wiphy, "set default mgmt key, key index=%d\n", key_index);
520 memset(&encrypt_key, 0, sizeof(struct mwifiex_ds_encrypt_key));
521 encrypt_key.key_len = WLAN_KEY_LEN_CCMP;
522 encrypt_key.key_index = key_index;
523 encrypt_key.is_igtk_def_key = true;
524 eth_broadcast_addr(encrypt_key.mac_addr);
526 return mwifiex_send_cmd(priv, HostCmd_CMD_802_11_KEY_MATERIAL,
527 HostCmd_ACT_GEN_SET, true, &encrypt_key, true);
531 * This function sends domain information to the firmware.
533 * The following information are passed to the firmware -
535 * - Sub bands (first channel, number of channels, maximum Tx power)
537 int mwifiex_send_domain_info_cmd_fw(struct wiphy *wiphy)
539 u8 no_of_triplet = 0;
540 struct ieee80211_country_ie_triplet *t;
541 u8 no_of_parsed_chan = 0;
542 u8 first_chan = 0, next_chan = 0, max_pwr = 0;
544 enum nl80211_band band;
545 struct ieee80211_supported_band *sband;
546 struct ieee80211_channel *ch;
547 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
548 struct mwifiex_private *priv;
549 struct mwifiex_802_11d_domain_reg *domain_info = &adapter->domain_reg;
551 /* Set country code */
552 domain_info->country_code[0] = adapter->country_code[0];
553 domain_info->country_code[1] = adapter->country_code[1];
554 domain_info->country_code[2] = ' ';
556 band = mwifiex_band_to_radio_type(adapter->config_bands);
557 if (!wiphy->bands[band]) {
558 mwifiex_dbg(adapter, ERROR,
559 "11D: setting domain info in FW\n");
563 sband = wiphy->bands[band];
565 for (i = 0; i < sband->n_channels ; i++) {
566 ch = &sband->channels[i];
567 if (ch->flags & IEEE80211_CHAN_DISABLED)
572 first_chan = (u32) ch->hw_value;
573 next_chan = first_chan;
574 max_pwr = ch->max_power;
575 no_of_parsed_chan = 1;
579 if (ch->hw_value == next_chan + 1 &&
580 ch->max_power == max_pwr) {
584 t = &domain_info->triplet[no_of_triplet];
585 t->chans.first_channel = first_chan;
586 t->chans.num_channels = no_of_parsed_chan;
587 t->chans.max_power = max_pwr;
589 first_chan = (u32) ch->hw_value;
590 next_chan = first_chan;
591 max_pwr = ch->max_power;
592 no_of_parsed_chan = 1;
597 t = &domain_info->triplet[no_of_triplet];
598 t->chans.first_channel = first_chan;
599 t->chans.num_channels = no_of_parsed_chan;
600 t->chans.max_power = max_pwr;
604 domain_info->no_of_triplet = no_of_triplet;
606 priv = mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY);
608 if (mwifiex_send_cmd(priv, HostCmd_CMD_802_11D_DOMAIN_INFO,
609 HostCmd_ACT_GEN_SET, 0, NULL, false)) {
610 mwifiex_dbg(adapter, INFO,
611 "11D: setting domain info in FW\n");
618 static void mwifiex_reg_apply_radar_flags(struct wiphy *wiphy)
620 struct ieee80211_supported_band *sband;
621 struct ieee80211_channel *chan;
624 if (!wiphy->bands[NL80211_BAND_5GHZ])
626 sband = wiphy->bands[NL80211_BAND_5GHZ];
628 for (i = 0; i < sband->n_channels; i++) {
629 chan = &sband->channels[i];
630 if ((!(chan->flags & IEEE80211_CHAN_DISABLED)) &&
631 (chan->flags & IEEE80211_CHAN_RADAR))
632 chan->flags |= IEEE80211_CHAN_NO_IR;
637 * CFG802.11 regulatory domain callback function.
639 * This function is called when the regulatory domain is changed due to the
640 * following reasons -
642 * - Set by system core
644 * - Set bt Country IE
646 static void mwifiex_reg_notifier(struct wiphy *wiphy,
647 struct regulatory_request *request)
649 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
650 struct mwifiex_private *priv = mwifiex_get_priv(adapter,
651 MWIFIEX_BSS_ROLE_ANY);
652 mwifiex_dbg(adapter, INFO,
653 "info: cfg80211 regulatory domain callback for %c%c\n",
654 request->alpha2[0], request->alpha2[1]);
655 mwifiex_reg_apply_radar_flags(wiphy);
657 switch (request->initiator) {
658 case NL80211_REGDOM_SET_BY_DRIVER:
659 case NL80211_REGDOM_SET_BY_CORE:
660 case NL80211_REGDOM_SET_BY_USER:
661 case NL80211_REGDOM_SET_BY_COUNTRY_IE:
664 mwifiex_dbg(adapter, ERROR,
665 "unknown regdom initiator: %d\n",
670 /* Don't send world or same regdom info to firmware */
671 if (strncmp(request->alpha2, "00", 2) &&
672 strncmp(request->alpha2, adapter->country_code,
673 sizeof(request->alpha2))) {
674 memcpy(adapter->country_code, request->alpha2,
675 sizeof(request->alpha2));
676 mwifiex_send_domain_info_cmd_fw(wiphy);
677 mwifiex_dnld_txpwr_table(priv);
682 * This function sets the fragmentation threshold.
684 * The fragmentation threshold value must lie between MWIFIEX_FRAG_MIN_VALUE
685 * and MWIFIEX_FRAG_MAX_VALUE.
688 mwifiex_set_frag(struct mwifiex_private *priv, u32 frag_thr)
690 if (frag_thr < MWIFIEX_FRAG_MIN_VALUE ||
691 frag_thr > MWIFIEX_FRAG_MAX_VALUE)
692 frag_thr = MWIFIEX_FRAG_MAX_VALUE;
694 return mwifiex_send_cmd(priv, HostCmd_CMD_802_11_SNMP_MIB,
695 HostCmd_ACT_GEN_SET, FRAG_THRESH_I,
700 * This function sets the RTS threshold.
702 * The rts value must lie between MWIFIEX_RTS_MIN_VALUE
703 * and MWIFIEX_RTS_MAX_VALUE.
706 mwifiex_set_rts(struct mwifiex_private *priv, u32 rts_thr)
708 if (rts_thr < MWIFIEX_RTS_MIN_VALUE || rts_thr > MWIFIEX_RTS_MAX_VALUE)
709 rts_thr = MWIFIEX_RTS_MAX_VALUE;
711 return mwifiex_send_cmd(priv, HostCmd_CMD_802_11_SNMP_MIB,
712 HostCmd_ACT_GEN_SET, RTS_THRESH_I,
717 * CFG802.11 operation handler to set wiphy parameters.
719 * This function can be used to set the RTS threshold and the
720 * Fragmentation threshold of the driver.
723 mwifiex_cfg80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
725 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
726 struct mwifiex_private *priv;
727 struct mwifiex_uap_bss_param *bss_cfg;
730 priv = mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY);
732 switch (priv->bss_role) {
733 case MWIFIEX_BSS_ROLE_UAP:
734 if (priv->bss_started) {
735 mwifiex_dbg(adapter, ERROR,
736 "cannot change wiphy params when bss started");
740 bss_cfg = kzalloc(sizeof(*bss_cfg), GFP_KERNEL);
744 mwifiex_set_sys_config_invalid_data(bss_cfg);
746 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
747 bss_cfg->rts_threshold = wiphy->rts_threshold;
748 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
749 bss_cfg->frag_threshold = wiphy->frag_threshold;
750 if (changed & WIPHY_PARAM_RETRY_LONG)
751 bss_cfg->retry_limit = wiphy->retry_long;
753 ret = mwifiex_send_cmd(priv, HostCmd_CMD_UAP_SYS_CONFIG,
755 UAP_BSS_PARAMS_I, bss_cfg,
760 mwifiex_dbg(adapter, ERROR,
761 "Failed to set wiphy phy params\n");
766 case MWIFIEX_BSS_ROLE_STA:
767 if (priv->media_connected) {
768 mwifiex_dbg(adapter, ERROR,
769 "cannot change wiphy params when connected");
772 if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
773 ret = mwifiex_set_rts(priv,
774 wiphy->rts_threshold);
778 if (changed & WIPHY_PARAM_FRAG_THRESHOLD) {
779 ret = mwifiex_set_frag(priv,
780 wiphy->frag_threshold);
791 mwifiex_cfg80211_deinit_p2p(struct mwifiex_private *priv)
793 u16 mode = P2P_MODE_DISABLE;
795 if (mwifiex_send_cmd(priv, HostCmd_CMD_P2P_MODE_CFG,
796 HostCmd_ACT_GEN_SET, 0, &mode, true))
803 * This function initializes the functionalities for P2P client.
804 * The P2P client initialization sequence is:
805 * disable -> device -> client
808 mwifiex_cfg80211_init_p2p_client(struct mwifiex_private *priv)
812 if (mwifiex_cfg80211_deinit_p2p(priv))
815 mode = P2P_MODE_DEVICE;
816 if (mwifiex_send_cmd(priv, HostCmd_CMD_P2P_MODE_CFG,
817 HostCmd_ACT_GEN_SET, 0, &mode, true))
820 mode = P2P_MODE_CLIENT;
821 if (mwifiex_send_cmd(priv, HostCmd_CMD_P2P_MODE_CFG,
822 HostCmd_ACT_GEN_SET, 0, &mode, true))
829 * This function initializes the functionalities for P2P GO.
830 * The P2P GO initialization sequence is:
831 * disable -> device -> GO
834 mwifiex_cfg80211_init_p2p_go(struct mwifiex_private *priv)
838 if (mwifiex_cfg80211_deinit_p2p(priv))
841 mode = P2P_MODE_DEVICE;
842 if (mwifiex_send_cmd(priv, HostCmd_CMD_P2P_MODE_CFG,
843 HostCmd_ACT_GEN_SET, 0, &mode, true))
847 if (mwifiex_send_cmd(priv, HostCmd_CMD_P2P_MODE_CFG,
848 HostCmd_ACT_GEN_SET, 0, &mode, true))
854 static int mwifiex_deinit_priv_params(struct mwifiex_private *priv)
856 struct mwifiex_adapter *adapter = priv->adapter;
859 priv->mgmt_frame_mask = 0;
860 if (mwifiex_send_cmd(priv, HostCmd_CMD_MGMT_FRAME_REG,
861 HostCmd_ACT_GEN_SET, 0,
862 &priv->mgmt_frame_mask, false)) {
863 mwifiex_dbg(adapter, ERROR,
864 "could not unregister mgmt frame rx\n");
868 mwifiex_deauthenticate(priv, NULL);
870 spin_lock_irqsave(&adapter->main_proc_lock, flags);
871 adapter->main_locked = true;
872 if (adapter->mwifiex_processing) {
873 spin_unlock_irqrestore(&adapter->main_proc_lock, flags);
874 flush_workqueue(adapter->workqueue);
876 spin_unlock_irqrestore(&adapter->main_proc_lock, flags);
879 spin_lock_irqsave(&adapter->rx_proc_lock, flags);
880 adapter->rx_locked = true;
881 if (adapter->rx_processing) {
882 spin_unlock_irqrestore(&adapter->rx_proc_lock, flags);
883 flush_workqueue(adapter->rx_workqueue);
885 spin_unlock_irqrestore(&adapter->rx_proc_lock, flags);
888 mwifiex_free_priv(priv);
889 priv->wdev.iftype = NL80211_IFTYPE_UNSPECIFIED;
890 priv->bss_mode = NL80211_IFTYPE_UNSPECIFIED;
891 priv->sec_info.authentication_mode = NL80211_AUTHTYPE_OPEN_SYSTEM;
897 mwifiex_init_new_priv_params(struct mwifiex_private *priv,
898 struct net_device *dev,
899 enum nl80211_iftype type)
901 struct mwifiex_adapter *adapter = priv->adapter;
904 mwifiex_init_priv(priv);
906 priv->bss_mode = type;
907 priv->wdev.iftype = type;
909 mwifiex_init_priv_params(priv, priv->netdev);
910 priv->bss_started = 0;
913 case NL80211_IFTYPE_STATION:
914 case NL80211_IFTYPE_ADHOC:
915 priv->bss_role = MWIFIEX_BSS_ROLE_STA;
917 case NL80211_IFTYPE_P2P_CLIENT:
918 priv->bss_role = MWIFIEX_BSS_ROLE_STA;
920 case NL80211_IFTYPE_P2P_GO:
921 priv->bss_role = MWIFIEX_BSS_ROLE_UAP;
923 case NL80211_IFTYPE_AP:
924 priv->bss_role = MWIFIEX_BSS_ROLE_UAP;
927 mwifiex_dbg(adapter, ERROR,
928 "%s: changing to %d not supported\n",
933 spin_lock_irqsave(&adapter->main_proc_lock, flags);
934 adapter->main_locked = false;
935 spin_unlock_irqrestore(&adapter->main_proc_lock, flags);
937 spin_lock_irqsave(&adapter->rx_proc_lock, flags);
938 adapter->rx_locked = false;
939 spin_unlock_irqrestore(&adapter->rx_proc_lock, flags);
941 mwifiex_set_mac_address(priv, dev, false, NULL);
947 mwifiex_change_vif_to_p2p(struct net_device *dev,
948 enum nl80211_iftype curr_iftype,
949 enum nl80211_iftype type,
950 struct vif_params *params)
952 struct mwifiex_private *priv;
953 struct mwifiex_adapter *adapter;
955 priv = mwifiex_netdev_get_priv(dev);
960 adapter = priv->adapter;
962 if (adapter->curr_iface_comb.p2p_intf ==
963 adapter->iface_limit.p2p_intf) {
964 mwifiex_dbg(adapter, ERROR,
965 "cannot create multiple P2P ifaces\n");
969 mwifiex_dbg(adapter, INFO,
970 "%s: changing role to p2p\n", dev->name);
972 if (mwifiex_deinit_priv_params(priv))
974 if (mwifiex_init_new_priv_params(priv, dev, type))
978 case NL80211_IFTYPE_P2P_CLIENT:
979 if (mwifiex_cfg80211_init_p2p_client(priv))
982 case NL80211_IFTYPE_P2P_GO:
983 if (mwifiex_cfg80211_init_p2p_go(priv))
987 mwifiex_dbg(adapter, ERROR,
988 "%s: changing to %d not supported\n",
993 if (mwifiex_send_cmd(priv, HostCmd_CMD_SET_BSS_MODE,
994 HostCmd_ACT_GEN_SET, 0, NULL, true))
997 if (mwifiex_sta_init_cmd(priv, false, false))
1000 switch (curr_iftype) {
1001 case NL80211_IFTYPE_STATION:
1002 case NL80211_IFTYPE_ADHOC:
1003 adapter->curr_iface_comb.sta_intf--;
1005 case NL80211_IFTYPE_AP:
1006 adapter->curr_iface_comb.uap_intf--;
1012 adapter->curr_iface_comb.p2p_intf++;
1013 dev->ieee80211_ptr->iftype = type;
1019 mwifiex_change_vif_to_sta_adhoc(struct net_device *dev,
1020 enum nl80211_iftype curr_iftype,
1021 enum nl80211_iftype type,
1022 struct vif_params *params)
1024 struct mwifiex_private *priv;
1025 struct mwifiex_adapter *adapter;
1027 priv = mwifiex_netdev_get_priv(dev);
1032 adapter = priv->adapter;
1034 if ((curr_iftype != NL80211_IFTYPE_P2P_CLIENT &&
1035 curr_iftype != NL80211_IFTYPE_P2P_GO) &&
1036 (adapter->curr_iface_comb.sta_intf ==
1037 adapter->iface_limit.sta_intf)) {
1038 mwifiex_dbg(adapter, ERROR,
1039 "cannot create multiple station/adhoc ifaces\n");
1043 if (type == NL80211_IFTYPE_STATION)
1044 mwifiex_dbg(adapter, INFO,
1045 "%s: changing role to station\n", dev->name);
1047 mwifiex_dbg(adapter, INFO,
1048 "%s: changing role to adhoc\n", dev->name);
1050 if (mwifiex_deinit_priv_params(priv))
1052 if (mwifiex_init_new_priv_params(priv, dev, type))
1054 if (mwifiex_send_cmd(priv, HostCmd_CMD_SET_BSS_MODE,
1055 HostCmd_ACT_GEN_SET, 0, NULL, true))
1057 if (mwifiex_sta_init_cmd(priv, false, false))
1060 switch (curr_iftype) {
1061 case NL80211_IFTYPE_P2P_CLIENT:
1062 case NL80211_IFTYPE_P2P_GO:
1063 adapter->curr_iface_comb.p2p_intf--;
1065 case NL80211_IFTYPE_AP:
1066 adapter->curr_iface_comb.uap_intf--;
1072 adapter->curr_iface_comb.sta_intf++;
1073 dev->ieee80211_ptr->iftype = type;
1078 mwifiex_change_vif_to_ap(struct net_device *dev,
1079 enum nl80211_iftype curr_iftype,
1080 enum nl80211_iftype type,
1081 struct vif_params *params)
1083 struct mwifiex_private *priv;
1084 struct mwifiex_adapter *adapter;
1086 priv = mwifiex_netdev_get_priv(dev);
1091 adapter = priv->adapter;
1093 if (adapter->curr_iface_comb.uap_intf ==
1094 adapter->iface_limit.uap_intf) {
1095 mwifiex_dbg(adapter, ERROR,
1096 "cannot create multiple AP ifaces\n");
1100 mwifiex_dbg(adapter, INFO,
1101 "%s: changing role to AP\n", dev->name);
1103 if (mwifiex_deinit_priv_params(priv))
1105 if (mwifiex_init_new_priv_params(priv, dev, type))
1107 if (mwifiex_send_cmd(priv, HostCmd_CMD_SET_BSS_MODE,
1108 HostCmd_ACT_GEN_SET, 0, NULL, true))
1110 if (mwifiex_sta_init_cmd(priv, false, false))
1113 switch (curr_iftype) {
1114 case NL80211_IFTYPE_P2P_CLIENT:
1115 case NL80211_IFTYPE_P2P_GO:
1116 adapter->curr_iface_comb.p2p_intf--;
1118 case NL80211_IFTYPE_STATION:
1119 case NL80211_IFTYPE_ADHOC:
1120 adapter->curr_iface_comb.sta_intf--;
1126 adapter->curr_iface_comb.uap_intf++;
1127 dev->ieee80211_ptr->iftype = type;
1131 * CFG802.11 operation handler to change interface type.
1134 mwifiex_cfg80211_change_virtual_intf(struct wiphy *wiphy,
1135 struct net_device *dev,
1136 enum nl80211_iftype type,
1137 struct vif_params *params)
1139 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
1140 enum nl80211_iftype curr_iftype = dev->ieee80211_ptr->iftype;
1142 if (priv->scan_request) {
1143 mwifiex_dbg(priv->adapter, ERROR,
1144 "change virtual interface: scan in process\n");
1148 switch (curr_iftype) {
1149 case NL80211_IFTYPE_ADHOC:
1151 case NL80211_IFTYPE_STATION:
1152 priv->bss_mode = type;
1153 priv->sec_info.authentication_mode =
1154 NL80211_AUTHTYPE_OPEN_SYSTEM;
1155 dev->ieee80211_ptr->iftype = type;
1156 mwifiex_deauthenticate(priv, NULL);
1157 return mwifiex_send_cmd(priv, HostCmd_CMD_SET_BSS_MODE,
1158 HostCmd_ACT_GEN_SET, 0, NULL,
1160 case NL80211_IFTYPE_P2P_CLIENT:
1161 case NL80211_IFTYPE_P2P_GO:
1162 return mwifiex_change_vif_to_p2p(dev, curr_iftype,
1164 case NL80211_IFTYPE_AP:
1165 return mwifiex_change_vif_to_ap(dev, curr_iftype, type,
1167 case NL80211_IFTYPE_UNSPECIFIED:
1168 mwifiex_dbg(priv->adapter, INFO,
1169 "%s: kept type as IBSS\n", dev->name);
1171 case NL80211_IFTYPE_ADHOC: /* This shouldn't happen */
1174 mwifiex_dbg(priv->adapter, ERROR,
1175 "%s: changing to %d not supported\n",
1180 case NL80211_IFTYPE_STATION:
1182 case NL80211_IFTYPE_ADHOC:
1183 priv->bss_mode = type;
1184 priv->sec_info.authentication_mode =
1185 NL80211_AUTHTYPE_OPEN_SYSTEM;
1186 dev->ieee80211_ptr->iftype = type;
1187 mwifiex_deauthenticate(priv, NULL);
1188 return mwifiex_send_cmd(priv, HostCmd_CMD_SET_BSS_MODE,
1189 HostCmd_ACT_GEN_SET, 0, NULL,
1191 case NL80211_IFTYPE_P2P_CLIENT:
1192 case NL80211_IFTYPE_P2P_GO:
1193 return mwifiex_change_vif_to_p2p(dev, curr_iftype,
1195 case NL80211_IFTYPE_AP:
1196 return mwifiex_change_vif_to_ap(dev, curr_iftype, type,
1198 case NL80211_IFTYPE_UNSPECIFIED:
1199 mwifiex_dbg(priv->adapter, INFO,
1200 "%s: kept type as STA\n", dev->name);
1202 case NL80211_IFTYPE_STATION: /* This shouldn't happen */
1205 mwifiex_dbg(priv->adapter, ERROR,
1206 "%s: changing to %d not supported\n",
1211 case NL80211_IFTYPE_AP:
1213 case NL80211_IFTYPE_ADHOC:
1214 return mwifiex_change_vif_to_sta_adhoc(dev, curr_iftype,
1217 case NL80211_IFTYPE_P2P_CLIENT:
1218 case NL80211_IFTYPE_P2P_GO:
1219 return mwifiex_change_vif_to_p2p(dev, curr_iftype,
1221 case NL80211_IFTYPE_UNSPECIFIED:
1222 mwifiex_dbg(priv->adapter, INFO,
1223 "%s: kept type as AP\n", dev->name);
1225 case NL80211_IFTYPE_AP: /* This shouldn't happen */
1228 mwifiex_dbg(priv->adapter, ERROR,
1229 "%s: changing to %d not supported\n",
1234 case NL80211_IFTYPE_P2P_CLIENT:
1235 case NL80211_IFTYPE_P2P_GO:
1237 case NL80211_IFTYPE_STATION:
1238 if (mwifiex_cfg80211_deinit_p2p(priv))
1240 priv->adapter->curr_iface_comb.p2p_intf--;
1241 priv->adapter->curr_iface_comb.sta_intf++;
1242 dev->ieee80211_ptr->iftype = type;
1243 if (mwifiex_deinit_priv_params(priv))
1245 if (mwifiex_init_new_priv_params(priv, dev, type))
1247 if (mwifiex_sta_init_cmd(priv, false, false))
1250 case NL80211_IFTYPE_ADHOC:
1251 if (mwifiex_cfg80211_deinit_p2p(priv))
1253 return mwifiex_change_vif_to_sta_adhoc(dev, curr_iftype,
1256 case NL80211_IFTYPE_AP:
1257 if (mwifiex_cfg80211_deinit_p2p(priv))
1259 return mwifiex_change_vif_to_ap(dev, curr_iftype, type,
1261 case NL80211_IFTYPE_UNSPECIFIED:
1262 mwifiex_dbg(priv->adapter, INFO,
1263 "%s: kept type as P2P\n", dev->name);
1265 case NL80211_IFTYPE_P2P_CLIENT:
1266 case NL80211_IFTYPE_P2P_GO:
1269 mwifiex_dbg(priv->adapter, ERROR,
1270 "%s: changing to %d not supported\n",
1276 mwifiex_dbg(priv->adapter, ERROR,
1277 "%s: unknown iftype: %d\n",
1278 dev->name, dev->ieee80211_ptr->iftype);
1287 mwifiex_parse_htinfo(struct mwifiex_private *priv, u8 tx_htinfo,
1288 struct rate_info *rate)
1290 struct mwifiex_adapter *adapter = priv->adapter;
1292 if (adapter->is_hw_11ac_capable) {
1293 /* bit[1-0]: 00=LG 01=HT 10=VHT */
1294 if (tx_htinfo & BIT(0)) {
1296 rate->mcs = priv->tx_rate;
1297 rate->flags |= RATE_INFO_FLAGS_MCS;
1299 if (tx_htinfo & BIT(1)) {
1301 rate->mcs = priv->tx_rate & 0x0F;
1302 rate->flags |= RATE_INFO_FLAGS_VHT_MCS;
1305 if (tx_htinfo & (BIT(1) | BIT(0))) {
1307 switch (tx_htinfo & (BIT(3) | BIT(2))) {
1309 rate->bw = RATE_INFO_BW_20;
1312 rate->bw = RATE_INFO_BW_40;
1315 rate->bw = RATE_INFO_BW_80;
1317 case (BIT(3) | BIT(2)):
1318 rate->bw = RATE_INFO_BW_160;
1322 if (tx_htinfo & BIT(4))
1323 rate->flags |= RATE_INFO_FLAGS_SHORT_GI;
1325 if ((priv->tx_rate >> 4) == 1)
1332 * Bit 0 in tx_htinfo indicates that current Tx rate
1333 * is 11n rate. Valid MCS index values for us are 0 to 15.
1335 if ((tx_htinfo & BIT(0)) && (priv->tx_rate < 16)) {
1336 rate->mcs = priv->tx_rate;
1337 rate->flags |= RATE_INFO_FLAGS_MCS;
1338 rate->bw = RATE_INFO_BW_20;
1339 if (tx_htinfo & BIT(1))
1340 rate->bw = RATE_INFO_BW_40;
1341 if (tx_htinfo & BIT(2))
1342 rate->flags |= RATE_INFO_FLAGS_SHORT_GI;
1348 * This function dumps the station information on a buffer.
1350 * The following information are shown -
1351 * - Total bytes transmitted
1352 * - Total bytes received
1353 * - Total packets transmitted
1354 * - Total packets received
1355 * - Signal quality level
1356 * - Transmission rate
1359 mwifiex_dump_station_info(struct mwifiex_private *priv,
1360 struct mwifiex_sta_node *node,
1361 struct station_info *sinfo)
1365 sinfo->filled = BIT_ULL(NL80211_STA_INFO_RX_BYTES) | BIT_ULL(NL80211_STA_INFO_TX_BYTES) |
1366 BIT_ULL(NL80211_STA_INFO_RX_PACKETS) | BIT_ULL(NL80211_STA_INFO_TX_PACKETS) |
1367 BIT_ULL(NL80211_STA_INFO_TX_BITRATE) |
1368 BIT_ULL(NL80211_STA_INFO_SIGNAL) | BIT_ULL(NL80211_STA_INFO_SIGNAL_AVG);
1370 if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_UAP) {
1374 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_INACTIVE_TIME) |
1375 BIT_ULL(NL80211_STA_INFO_TX_FAILED);
1376 sinfo->inactive_time =
1377 jiffies_to_msecs(jiffies - node->stats.last_rx);
1379 sinfo->signal = node->stats.rssi;
1380 sinfo->signal_avg = node->stats.rssi;
1381 sinfo->rx_bytes = node->stats.rx_bytes;
1382 sinfo->tx_bytes = node->stats.tx_bytes;
1383 sinfo->rx_packets = node->stats.rx_packets;
1384 sinfo->tx_packets = node->stats.tx_packets;
1385 sinfo->tx_failed = node->stats.tx_failed;
1387 mwifiex_parse_htinfo(priv, node->stats.last_tx_htinfo,
1389 sinfo->txrate.legacy = node->stats.last_tx_rate * 5;
1394 /* Get signal information from the firmware */
1395 if (mwifiex_send_cmd(priv, HostCmd_CMD_RSSI_INFO,
1396 HostCmd_ACT_GEN_GET, 0, NULL, true)) {
1397 mwifiex_dbg(priv->adapter, ERROR,
1398 "failed to get signal information\n");
1402 if (mwifiex_drv_get_data_rate(priv, &rate)) {
1403 mwifiex_dbg(priv->adapter, ERROR,
1404 "getting data rate error\n");
1408 /* Get DTIM period information from firmware */
1409 mwifiex_send_cmd(priv, HostCmd_CMD_802_11_SNMP_MIB,
1410 HostCmd_ACT_GEN_GET, DTIM_PERIOD_I,
1411 &priv->dtim_period, true);
1413 mwifiex_parse_htinfo(priv, priv->tx_htinfo, &sinfo->txrate);
1415 sinfo->signal_avg = priv->bcn_rssi_avg;
1416 sinfo->rx_bytes = priv->stats.rx_bytes;
1417 sinfo->tx_bytes = priv->stats.tx_bytes;
1418 sinfo->rx_packets = priv->stats.rx_packets;
1419 sinfo->tx_packets = priv->stats.tx_packets;
1420 sinfo->signal = priv->bcn_rssi_avg;
1421 /* bit rate is in 500 kb/s units. Convert it to 100kb/s units */
1422 sinfo->txrate.legacy = rate * 5;
1424 if (priv->bss_mode == NL80211_IFTYPE_STATION) {
1425 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_BSS_PARAM);
1426 sinfo->bss_param.flags = 0;
1427 if (priv->curr_bss_params.bss_descriptor.cap_info_bitmap &
1428 WLAN_CAPABILITY_SHORT_PREAMBLE)
1429 sinfo->bss_param.flags |=
1430 BSS_PARAM_FLAGS_SHORT_PREAMBLE;
1431 if (priv->curr_bss_params.bss_descriptor.cap_info_bitmap &
1432 WLAN_CAPABILITY_SHORT_SLOT_TIME)
1433 sinfo->bss_param.flags |=
1434 BSS_PARAM_FLAGS_SHORT_SLOT_TIME;
1435 sinfo->bss_param.dtim_period = priv->dtim_period;
1436 sinfo->bss_param.beacon_interval =
1437 priv->curr_bss_params.bss_descriptor.beacon_period;
1444 * CFG802.11 operation handler to get station information.
1446 * This function only works in connected mode, and dumps the
1447 * requested station information, if available.
1450 mwifiex_cfg80211_get_station(struct wiphy *wiphy, struct net_device *dev,
1451 const u8 *mac, struct station_info *sinfo)
1453 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
1455 if (!priv->media_connected)
1457 if (memcmp(mac, priv->cfg_bssid, ETH_ALEN))
1460 return mwifiex_dump_station_info(priv, NULL, sinfo);
1464 * CFG802.11 operation handler to dump station information.
1467 mwifiex_cfg80211_dump_station(struct wiphy *wiphy, struct net_device *dev,
1468 int idx, u8 *mac, struct station_info *sinfo)
1470 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
1471 struct mwifiex_sta_node *node;
1474 if ((GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA) &&
1475 priv->media_connected && idx == 0) {
1476 ether_addr_copy(mac, priv->cfg_bssid);
1477 return mwifiex_dump_station_info(priv, NULL, sinfo);
1478 } else if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_UAP) {
1479 mwifiex_send_cmd(priv, HOST_CMD_APCMD_STA_LIST,
1480 HostCmd_ACT_GEN_GET, 0, NULL, true);
1483 list_for_each_entry(node, &priv->sta_list, list) {
1486 ether_addr_copy(mac, node->mac_addr);
1487 return mwifiex_dump_station_info(priv, node, sinfo);
1495 mwifiex_cfg80211_dump_survey(struct wiphy *wiphy, struct net_device *dev,
1496 int idx, struct survey_info *survey)
1498 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
1499 struct mwifiex_chan_stats *pchan_stats = priv->adapter->chan_stats;
1500 enum nl80211_band band;
1502 mwifiex_dbg(priv->adapter, DUMP, "dump_survey idx=%d\n", idx);
1504 memset(survey, 0, sizeof(struct survey_info));
1506 if ((GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA) &&
1507 priv->media_connected && idx == 0) {
1508 u8 curr_bss_band = priv->curr_bss_params.band;
1509 u32 chan = priv->curr_bss_params.bss_descriptor.channel;
1511 band = mwifiex_band_to_radio_type(curr_bss_band);
1512 survey->channel = ieee80211_get_channel(wiphy,
1513 ieee80211_channel_to_frequency(chan, band));
1515 if (priv->bcn_nf_last) {
1516 survey->filled = SURVEY_INFO_NOISE_DBM;
1517 survey->noise = priv->bcn_nf_last;
1522 if (idx >= priv->adapter->num_in_chan_stats)
1525 if (!pchan_stats[idx].cca_scan_dur)
1528 band = pchan_stats[idx].bandcfg;
1529 survey->channel = ieee80211_get_channel(wiphy,
1530 ieee80211_channel_to_frequency(pchan_stats[idx].chan_num, band));
1531 survey->filled = SURVEY_INFO_NOISE_DBM |
1533 SURVEY_INFO_TIME_BUSY;
1534 survey->noise = pchan_stats[idx].noise;
1535 survey->time = pchan_stats[idx].cca_scan_dur;
1536 survey->time_busy = pchan_stats[idx].cca_busy_dur;
1541 /* Supported rates to be advertised to the cfg80211 */
1542 static struct ieee80211_rate mwifiex_rates[] = {
1543 {.bitrate = 10, .hw_value = 2, },
1544 {.bitrate = 20, .hw_value = 4, },
1545 {.bitrate = 55, .hw_value = 11, },
1546 {.bitrate = 110, .hw_value = 22, },
1547 {.bitrate = 60, .hw_value = 12, },
1548 {.bitrate = 90, .hw_value = 18, },
1549 {.bitrate = 120, .hw_value = 24, },
1550 {.bitrate = 180, .hw_value = 36, },
1551 {.bitrate = 240, .hw_value = 48, },
1552 {.bitrate = 360, .hw_value = 72, },
1553 {.bitrate = 480, .hw_value = 96, },
1554 {.bitrate = 540, .hw_value = 108, },
1557 /* Channel definitions to be advertised to cfg80211 */
1558 static struct ieee80211_channel mwifiex_channels_2ghz[] = {
1559 {.center_freq = 2412, .hw_value = 1, },
1560 {.center_freq = 2417, .hw_value = 2, },
1561 {.center_freq = 2422, .hw_value = 3, },
1562 {.center_freq = 2427, .hw_value = 4, },
1563 {.center_freq = 2432, .hw_value = 5, },
1564 {.center_freq = 2437, .hw_value = 6, },
1565 {.center_freq = 2442, .hw_value = 7, },
1566 {.center_freq = 2447, .hw_value = 8, },
1567 {.center_freq = 2452, .hw_value = 9, },
1568 {.center_freq = 2457, .hw_value = 10, },
1569 {.center_freq = 2462, .hw_value = 11, },
1570 {.center_freq = 2467, .hw_value = 12, },
1571 {.center_freq = 2472, .hw_value = 13, },
1572 {.center_freq = 2484, .hw_value = 14, },
1575 static struct ieee80211_supported_band mwifiex_band_2ghz = {
1576 .channels = mwifiex_channels_2ghz,
1577 .n_channels = ARRAY_SIZE(mwifiex_channels_2ghz),
1578 .bitrates = mwifiex_rates,
1579 .n_bitrates = ARRAY_SIZE(mwifiex_rates),
1582 static struct ieee80211_channel mwifiex_channels_5ghz[] = {
1583 {.center_freq = 5040, .hw_value = 8, },
1584 {.center_freq = 5060, .hw_value = 12, },
1585 {.center_freq = 5080, .hw_value = 16, },
1586 {.center_freq = 5170, .hw_value = 34, },
1587 {.center_freq = 5190, .hw_value = 38, },
1588 {.center_freq = 5210, .hw_value = 42, },
1589 {.center_freq = 5230, .hw_value = 46, },
1590 {.center_freq = 5180, .hw_value = 36, },
1591 {.center_freq = 5200, .hw_value = 40, },
1592 {.center_freq = 5220, .hw_value = 44, },
1593 {.center_freq = 5240, .hw_value = 48, },
1594 {.center_freq = 5260, .hw_value = 52, },
1595 {.center_freq = 5280, .hw_value = 56, },
1596 {.center_freq = 5300, .hw_value = 60, },
1597 {.center_freq = 5320, .hw_value = 64, },
1598 {.center_freq = 5500, .hw_value = 100, },
1599 {.center_freq = 5520, .hw_value = 104, },
1600 {.center_freq = 5540, .hw_value = 108, },
1601 {.center_freq = 5560, .hw_value = 112, },
1602 {.center_freq = 5580, .hw_value = 116, },
1603 {.center_freq = 5600, .hw_value = 120, },
1604 {.center_freq = 5620, .hw_value = 124, },
1605 {.center_freq = 5640, .hw_value = 128, },
1606 {.center_freq = 5660, .hw_value = 132, },
1607 {.center_freq = 5680, .hw_value = 136, },
1608 {.center_freq = 5700, .hw_value = 140, },
1609 {.center_freq = 5745, .hw_value = 149, },
1610 {.center_freq = 5765, .hw_value = 153, },
1611 {.center_freq = 5785, .hw_value = 157, },
1612 {.center_freq = 5805, .hw_value = 161, },
1613 {.center_freq = 5825, .hw_value = 165, },
1616 static struct ieee80211_supported_band mwifiex_band_5ghz = {
1617 .channels = mwifiex_channels_5ghz,
1618 .n_channels = ARRAY_SIZE(mwifiex_channels_5ghz),
1619 .bitrates = mwifiex_rates + 4,
1620 .n_bitrates = ARRAY_SIZE(mwifiex_rates) - 4,
1624 /* Supported crypto cipher suits to be advertised to cfg80211 */
1625 static const u32 mwifiex_cipher_suites[] = {
1626 WLAN_CIPHER_SUITE_WEP40,
1627 WLAN_CIPHER_SUITE_WEP104,
1628 WLAN_CIPHER_SUITE_TKIP,
1629 WLAN_CIPHER_SUITE_CCMP,
1630 WLAN_CIPHER_SUITE_SMS4,
1631 WLAN_CIPHER_SUITE_AES_CMAC,
1634 /* Supported mgmt frame types to be advertised to cfg80211 */
1635 static const struct ieee80211_txrx_stypes
1636 mwifiex_mgmt_stypes[NUM_NL80211_IFTYPES] = {
1637 [NL80211_IFTYPE_STATION] = {
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),
1643 [NL80211_IFTYPE_AP] = {
1644 .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
1645 BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
1646 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
1647 BIT(IEEE80211_STYPE_PROBE_REQ >> 4),
1649 [NL80211_IFTYPE_P2P_CLIENT] = {
1650 .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
1651 BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
1652 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
1653 BIT(IEEE80211_STYPE_PROBE_REQ >> 4),
1655 [NL80211_IFTYPE_P2P_GO] = {
1656 .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
1657 BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
1658 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
1659 BIT(IEEE80211_STYPE_PROBE_REQ >> 4),
1664 * CFG802.11 operation handler for setting bit rates.
1666 * Function configures data rates to firmware using bitrate mask
1667 * provided by cfg80211.
1669 static int mwifiex_cfg80211_set_bitrate_mask(struct wiphy *wiphy,
1670 struct net_device *dev,
1672 const struct cfg80211_bitrate_mask *mask)
1674 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
1675 u16 bitmap_rates[MAX_BITMAP_RATES_SIZE];
1676 enum nl80211_band band;
1677 struct mwifiex_adapter *adapter = priv->adapter;
1679 if (!priv->media_connected) {
1680 mwifiex_dbg(adapter, ERROR,
1681 "Can not set Tx data rate in disconnected state\n");
1685 band = mwifiex_band_to_radio_type(priv->curr_bss_params.band);
1687 memset(bitmap_rates, 0, sizeof(bitmap_rates));
1689 /* Fill HR/DSSS rates. */
1690 if (band == NL80211_BAND_2GHZ)
1691 bitmap_rates[0] = mask->control[band].legacy & 0x000f;
1693 /* Fill OFDM rates */
1694 if (band == NL80211_BAND_2GHZ)
1695 bitmap_rates[1] = (mask->control[band].legacy & 0x0ff0) >> 4;
1697 bitmap_rates[1] = mask->control[band].legacy;
1699 /* Fill HT MCS rates */
1700 bitmap_rates[2] = mask->control[band].ht_mcs[0];
1701 if (adapter->hw_dev_mcs_support == HT_STREAM_2X2)
1702 bitmap_rates[2] |= mask->control[band].ht_mcs[1] << 8;
1704 /* Fill VHT MCS rates */
1705 if (adapter->fw_api_ver == MWIFIEX_FW_V15) {
1706 bitmap_rates[10] = mask->control[band].vht_mcs[0];
1707 if (adapter->hw_dev_mcs_support == HT_STREAM_2X2)
1708 bitmap_rates[11] = mask->control[band].vht_mcs[1];
1711 return mwifiex_send_cmd(priv, HostCmd_CMD_TX_RATE_CFG,
1712 HostCmd_ACT_GEN_SET, 0, bitmap_rates, true);
1716 * CFG802.11 operation handler for connection quality monitoring.
1718 * This function subscribes/unsubscribes HIGH_RSSI and LOW_RSSI
1721 static int mwifiex_cfg80211_set_cqm_rssi_config(struct wiphy *wiphy,
1722 struct net_device *dev,
1723 s32 rssi_thold, u32 rssi_hyst)
1725 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
1726 struct mwifiex_ds_misc_subsc_evt subsc_evt;
1728 priv->cqm_rssi_thold = rssi_thold;
1729 priv->cqm_rssi_hyst = rssi_hyst;
1731 memset(&subsc_evt, 0x00, sizeof(struct mwifiex_ds_misc_subsc_evt));
1732 subsc_evt.events = BITMASK_BCN_RSSI_LOW | BITMASK_BCN_RSSI_HIGH;
1734 /* Subscribe/unsubscribe low and high rssi events */
1735 if (rssi_thold && rssi_hyst) {
1736 subsc_evt.action = HostCmd_ACT_BITWISE_SET;
1737 subsc_evt.bcn_l_rssi_cfg.abs_value = abs(rssi_thold);
1738 subsc_evt.bcn_h_rssi_cfg.abs_value = abs(rssi_thold);
1739 subsc_evt.bcn_l_rssi_cfg.evt_freq = 1;
1740 subsc_evt.bcn_h_rssi_cfg.evt_freq = 1;
1741 return mwifiex_send_cmd(priv,
1742 HostCmd_CMD_802_11_SUBSCRIBE_EVENT,
1743 0, 0, &subsc_evt, true);
1745 subsc_evt.action = HostCmd_ACT_BITWISE_CLR;
1746 return mwifiex_send_cmd(priv,
1747 HostCmd_CMD_802_11_SUBSCRIBE_EVENT,
1748 0, 0, &subsc_evt, true);
1754 /* cfg80211 operation handler for change_beacon.
1755 * Function retrieves and sets modified management IEs to FW.
1757 static int mwifiex_cfg80211_change_beacon(struct wiphy *wiphy,
1758 struct net_device *dev,
1759 struct cfg80211_beacon_data *data)
1761 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
1762 struct mwifiex_adapter *adapter = priv->adapter;
1764 mwifiex_cancel_scan(adapter);
1766 if (GET_BSS_ROLE(priv) != MWIFIEX_BSS_ROLE_UAP) {
1767 mwifiex_dbg(priv->adapter, ERROR,
1768 "%s: bss_type mismatched\n", __func__);
1772 if (!priv->bss_started) {
1773 mwifiex_dbg(priv->adapter, ERROR,
1774 "%s: bss not started\n", __func__);
1778 if (mwifiex_set_mgmt_ies(priv, data)) {
1779 mwifiex_dbg(priv->adapter, ERROR,
1780 "%s: setting mgmt ies failed\n", __func__);
1787 /* cfg80211 operation handler for del_station.
1788 * Function deauthenticates station which value is provided in mac parameter.
1789 * If mac is NULL/broadcast, all stations in associated station list are
1790 * deauthenticated. If bss is not started or there are no stations in
1791 * associated stations list, no action is taken.
1794 mwifiex_cfg80211_del_station(struct wiphy *wiphy, struct net_device *dev,
1795 struct station_del_parameters *params)
1797 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
1798 struct mwifiex_sta_node *sta_node;
1799 u8 deauth_mac[ETH_ALEN];
1800 unsigned long flags;
1802 if (!priv->bss_started && priv->wdev.cac_started) {
1803 mwifiex_dbg(priv->adapter, INFO, "%s: abort CAC!\n", __func__);
1804 mwifiex_abort_cac(priv);
1807 if (list_empty(&priv->sta_list) || !priv->bss_started)
1810 if (!params->mac || is_broadcast_ether_addr(params->mac))
1813 mwifiex_dbg(priv->adapter, INFO, "%s: mac address %pM\n",
1814 __func__, params->mac);
1816 eth_zero_addr(deauth_mac);
1818 spin_lock_irqsave(&priv->sta_list_spinlock, flags);
1819 sta_node = mwifiex_get_sta_entry(priv, params->mac);
1821 ether_addr_copy(deauth_mac, params->mac);
1822 spin_unlock_irqrestore(&priv->sta_list_spinlock, flags);
1824 if (is_valid_ether_addr(deauth_mac)) {
1825 if (mwifiex_send_cmd(priv, HostCmd_CMD_UAP_STA_DEAUTH,
1826 HostCmd_ACT_GEN_SET, 0,
1835 mwifiex_cfg80211_set_antenna(struct wiphy *wiphy, u32 tx_ant, u32 rx_ant)
1837 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
1838 struct mwifiex_private *priv = mwifiex_get_priv(adapter,
1839 MWIFIEX_BSS_ROLE_ANY);
1840 struct mwifiex_ds_ant_cfg ant_cfg;
1842 if (!tx_ant || !rx_ant)
1845 if (adapter->hw_dev_mcs_support != HT_STREAM_2X2) {
1846 /* Not a MIMO chip. User should provide specific antenna number
1847 * for Tx/Rx path or enable all antennas for diversity
1849 if (tx_ant != rx_ant)
1852 if ((tx_ant & (tx_ant - 1)) &&
1853 (tx_ant != BIT(adapter->number_of_antenna) - 1))
1856 if ((tx_ant == BIT(adapter->number_of_antenna) - 1) &&
1857 (priv->adapter->number_of_antenna > 1)) {
1858 tx_ant = RF_ANTENNA_AUTO;
1859 rx_ant = RF_ANTENNA_AUTO;
1862 struct ieee80211_sta_ht_cap *ht_info;
1864 enum nl80211_band band;
1866 if ((tx_ant == 0x1 && rx_ant == 0x1)) {
1867 adapter->user_dev_mcs_support = HT_STREAM_1X1;
1868 if (adapter->is_hw_11ac_capable)
1869 adapter->usr_dot_11ac_mcs_support =
1870 MWIFIEX_11AC_MCS_MAP_1X1;
1872 adapter->user_dev_mcs_support = HT_STREAM_2X2;
1873 if (adapter->is_hw_11ac_capable)
1874 adapter->usr_dot_11ac_mcs_support =
1875 MWIFIEX_11AC_MCS_MAP_2X2;
1878 for (band = 0; band < NUM_NL80211_BANDS; band++) {
1879 if (!adapter->wiphy->bands[band])
1882 ht_info = &adapter->wiphy->bands[band]->ht_cap;
1884 GET_RXMCSSUPP(adapter->user_dev_mcs_support);
1885 memset(&ht_info->mcs, 0, adapter->number_of_antenna);
1886 memset(&ht_info->mcs, 0xff, rx_mcs_supp);
1890 ant_cfg.tx_ant = tx_ant;
1891 ant_cfg.rx_ant = rx_ant;
1893 return mwifiex_send_cmd(priv, HostCmd_CMD_RF_ANTENNA,
1894 HostCmd_ACT_GEN_SET, 0, &ant_cfg, true);
1898 mwifiex_cfg80211_get_antenna(struct wiphy *wiphy, u32 *tx_ant, u32 *rx_ant)
1900 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
1901 struct mwifiex_private *priv = mwifiex_get_priv(adapter,
1902 MWIFIEX_BSS_ROLE_ANY);
1903 mwifiex_send_cmd(priv, HostCmd_CMD_RF_ANTENNA,
1904 HostCmd_ACT_GEN_GET, 0, NULL, true);
1906 *tx_ant = priv->tx_ant;
1907 *rx_ant = priv->rx_ant;
1912 /* cfg80211 operation handler for stop ap.
1913 * Function stops BSS running at uAP interface.
1915 static int mwifiex_cfg80211_stop_ap(struct wiphy *wiphy, struct net_device *dev)
1917 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
1919 mwifiex_abort_cac(priv);
1921 if (mwifiex_del_mgmt_ies(priv))
1922 mwifiex_dbg(priv->adapter, ERROR,
1923 "Failed to delete mgmt IEs!\n");
1925 priv->ap_11n_enabled = 0;
1926 memset(&priv->bss_cfg, 0, sizeof(priv->bss_cfg));
1928 if (mwifiex_send_cmd(priv, HostCmd_CMD_UAP_BSS_STOP,
1929 HostCmd_ACT_GEN_SET, 0, NULL, true)) {
1930 mwifiex_dbg(priv->adapter, ERROR,
1931 "Failed to stop the BSS\n");
1935 if (mwifiex_send_cmd(priv, HOST_CMD_APCMD_SYS_RESET,
1936 HostCmd_ACT_GEN_SET, 0, NULL, true)) {
1937 mwifiex_dbg(priv->adapter, ERROR,
1938 "Failed to reset BSS\n");
1942 if (netif_carrier_ok(priv->netdev))
1943 netif_carrier_off(priv->netdev);
1944 mwifiex_stop_net_dev_queue(priv->netdev, priv->adapter);
1949 /* cfg80211 operation handler for start_ap.
1950 * Function sets beacon period, DTIM period, SSID and security into
1951 * AP config structure.
1952 * AP is configured with these settings and BSS is started.
1954 static int mwifiex_cfg80211_start_ap(struct wiphy *wiphy,
1955 struct net_device *dev,
1956 struct cfg80211_ap_settings *params)
1958 struct mwifiex_uap_bss_param *bss_cfg;
1959 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
1961 if (GET_BSS_ROLE(priv) != MWIFIEX_BSS_ROLE_UAP)
1964 bss_cfg = kzalloc(sizeof(struct mwifiex_uap_bss_param), GFP_KERNEL);
1968 mwifiex_set_sys_config_invalid_data(bss_cfg);
1970 if (params->beacon_interval)
1971 bss_cfg->beacon_period = params->beacon_interval;
1972 if (params->dtim_period)
1973 bss_cfg->dtim_period = params->dtim_period;
1975 if (params->ssid && params->ssid_len) {
1976 memcpy(bss_cfg->ssid.ssid, params->ssid, params->ssid_len);
1977 bss_cfg->ssid.ssid_len = params->ssid_len;
1979 if (params->inactivity_timeout > 0) {
1980 /* sta_ao_timer/ps_sta_ao_timer is in unit of 100ms */
1981 bss_cfg->sta_ao_timer = 10 * params->inactivity_timeout;
1982 bss_cfg->ps_sta_ao_timer = 10 * params->inactivity_timeout;
1985 switch (params->hidden_ssid) {
1986 case NL80211_HIDDEN_SSID_NOT_IN_USE:
1987 bss_cfg->bcast_ssid_ctl = 1;
1989 case NL80211_HIDDEN_SSID_ZERO_LEN:
1990 bss_cfg->bcast_ssid_ctl = 0;
1992 case NL80211_HIDDEN_SSID_ZERO_CONTENTS:
1993 bss_cfg->bcast_ssid_ctl = 2;
2000 mwifiex_uap_set_channel(priv, bss_cfg, params->chandef);
2001 mwifiex_set_uap_rates(bss_cfg, params);
2003 if (mwifiex_set_secure_params(priv, bss_cfg, params)) {
2004 mwifiex_dbg(priv->adapter, ERROR,
2005 "Failed to parse security parameters!\n");
2009 mwifiex_set_ht_params(priv, bss_cfg, params);
2011 if (priv->adapter->is_hw_11ac_capable) {
2012 mwifiex_set_vht_params(priv, bss_cfg, params);
2013 mwifiex_set_vht_width(priv, params->chandef.width,
2014 priv->ap_11ac_enabled);
2017 if (priv->ap_11ac_enabled)
2018 mwifiex_set_11ac_ba_params(priv);
2020 mwifiex_set_ba_params(priv);
2022 mwifiex_set_wmm_params(priv, bss_cfg, params);
2024 if (mwifiex_is_11h_active(priv))
2025 mwifiex_set_tpc_params(priv, bss_cfg, params);
2027 if (mwifiex_is_11h_active(priv) &&
2028 !cfg80211_chandef_dfs_required(wiphy, ¶ms->chandef,
2030 mwifiex_dbg(priv->adapter, INFO,
2031 "Disable 11h extensions in FW\n");
2032 if (mwifiex_11h_activate(priv, false)) {
2033 mwifiex_dbg(priv->adapter, ERROR,
2034 "Failed to disable 11h extensions!!");
2037 priv->state_11h.is_11h_active = false;
2040 mwifiex_config_uap_11d(priv, ¶ms->beacon);
2042 if (mwifiex_config_start_uap(priv, bss_cfg)) {
2043 mwifiex_dbg(priv->adapter, ERROR,
2044 "Failed to start AP\n");
2048 if (mwifiex_set_mgmt_ies(priv, ¶ms->beacon))
2051 if (!netif_carrier_ok(priv->netdev))
2052 netif_carrier_on(priv->netdev);
2053 mwifiex_wake_up_net_dev_queue(priv->netdev, priv->adapter);
2055 memcpy(&priv->bss_cfg, bss_cfg, sizeof(priv->bss_cfg));
2065 * CFG802.11 operation handler for disconnection request.
2067 * This function does not work when there is already a disconnection
2068 * procedure going on.
2071 mwifiex_cfg80211_disconnect(struct wiphy *wiphy, struct net_device *dev,
2074 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
2076 if (!mwifiex_stop_bg_scan(priv))
2077 cfg80211_sched_scan_stopped_rtnl(priv->wdev.wiphy, 0);
2079 if (mwifiex_deauthenticate(priv, NULL))
2082 eth_zero_addr(priv->cfg_bssid);
2083 priv->hs2_enabled = false;
2089 * This function informs the CFG802.11 subsystem of a new IBSS.
2091 * The following information are sent to the CFG802.11 subsystem
2092 * to register the new IBSS. If we do not register the new IBSS,
2093 * a kernel panic will result.
2099 static int mwifiex_cfg80211_inform_ibss_bss(struct mwifiex_private *priv)
2101 struct ieee80211_channel *chan;
2102 struct mwifiex_bss_info bss_info;
2103 struct cfg80211_bss *bss;
2105 u8 ie_buf[IEEE80211_MAX_SSID_LEN + sizeof(struct ieee_types_header)];
2106 enum nl80211_band band;
2108 if (mwifiex_get_bss_info(priv, &bss_info))
2111 ie_buf[0] = WLAN_EID_SSID;
2112 ie_buf[1] = bss_info.ssid.ssid_len;
2114 memcpy(&ie_buf[sizeof(struct ieee_types_header)],
2115 &bss_info.ssid.ssid, bss_info.ssid.ssid_len);
2116 ie_len = ie_buf[1] + sizeof(struct ieee_types_header);
2118 band = mwifiex_band_to_radio_type(priv->curr_bss_params.band);
2119 chan = ieee80211_get_channel(priv->wdev.wiphy,
2120 ieee80211_channel_to_frequency(bss_info.bss_chan,
2123 bss = cfg80211_inform_bss(priv->wdev.wiphy, chan,
2124 CFG80211_BSS_FTYPE_UNKNOWN,
2125 bss_info.bssid, 0, WLAN_CAPABILITY_IBSS,
2126 0, ie_buf, ie_len, 0, GFP_KERNEL);
2128 cfg80211_put_bss(priv->wdev.wiphy, bss);
2129 ether_addr_copy(priv->cfg_bssid, bss_info.bssid);
2136 * This function connects with a BSS.
2138 * This function handles both Infra and Ad-Hoc modes. It also performs
2139 * validity checking on the provided parameters, disconnects from the
2140 * current BSS (if any), sets up the association/scan parameters,
2141 * including security settings, and performs specific SSID scan before
2142 * trying to connect.
2144 * For Infra mode, the function returns failure if the specified SSID
2145 * is not found in scan table. However, for Ad-Hoc mode, it can create
2146 * the IBSS if it does not exist. On successful completion in either case,
2147 * the function notifies the CFG802.11 subsystem of the new BSS connection.
2150 mwifiex_cfg80211_assoc(struct mwifiex_private *priv, size_t ssid_len,
2151 const u8 *ssid, const u8 *bssid, int mode,
2152 struct ieee80211_channel *channel,
2153 struct cfg80211_connect_params *sme, bool privacy)
2155 struct cfg80211_ssid req_ssid;
2156 int ret, auth_type = 0;
2157 struct cfg80211_bss *bss = NULL;
2158 u8 is_scanning_required = 0;
2160 memset(&req_ssid, 0, sizeof(struct cfg80211_ssid));
2162 req_ssid.ssid_len = ssid_len;
2163 if (ssid_len > IEEE80211_MAX_SSID_LEN) {
2164 mwifiex_dbg(priv->adapter, ERROR, "invalid SSID - aborting\n");
2168 memcpy(req_ssid.ssid, ssid, ssid_len);
2169 if (!req_ssid.ssid_len || req_ssid.ssid[0] < 0x20) {
2170 mwifiex_dbg(priv->adapter, ERROR, "invalid SSID - aborting\n");
2174 /* As this is new association, clear locally stored
2175 * keys and security related flags */
2176 priv->sec_info.wpa_enabled = false;
2177 priv->sec_info.wpa2_enabled = false;
2178 priv->wep_key_curr_index = 0;
2179 priv->sec_info.encryption_mode = 0;
2180 priv->sec_info.is_authtype_auto = 0;
2181 ret = mwifiex_set_encode(priv, NULL, NULL, 0, 0, NULL, 1);
2183 if (mode == NL80211_IFTYPE_ADHOC) {
2186 /* set ibss coalescing_status */
2187 ret = mwifiex_send_cmd(
2189 HostCmd_CMD_802_11_IBSS_COALESCING_STATUS,
2190 HostCmd_ACT_GEN_SET, 0, &enable, true);
2194 /* "privacy" is set only for ad-hoc mode */
2197 * Keep WLAN_CIPHER_SUITE_WEP104 for now so that
2198 * the firmware can find a matching network from the
2199 * scan. The cfg80211 does not give us the encryption
2200 * mode at this stage so just setting it to WEP here.
2202 priv->sec_info.encryption_mode =
2203 WLAN_CIPHER_SUITE_WEP104;
2204 priv->sec_info.authentication_mode =
2205 NL80211_AUTHTYPE_OPEN_SYSTEM;
2211 /* Now handle infra mode. "sme" is valid for infra mode only */
2212 if (sme->auth_type == NL80211_AUTHTYPE_AUTOMATIC) {
2213 auth_type = NL80211_AUTHTYPE_OPEN_SYSTEM;
2214 priv->sec_info.is_authtype_auto = 1;
2216 auth_type = sme->auth_type;
2219 if (sme->crypto.n_ciphers_pairwise) {
2220 priv->sec_info.encryption_mode =
2221 sme->crypto.ciphers_pairwise[0];
2222 priv->sec_info.authentication_mode = auth_type;
2225 if (sme->crypto.cipher_group) {
2226 priv->sec_info.encryption_mode = sme->crypto.cipher_group;
2227 priv->sec_info.authentication_mode = auth_type;
2230 ret = mwifiex_set_gen_ie(priv, sme->ie, sme->ie_len);
2233 if (mwifiex_is_alg_wep(priv->sec_info.encryption_mode)) {
2234 mwifiex_dbg(priv->adapter, INFO,
2235 "info: setting wep encryption\t"
2236 "with key len %d\n", sme->key_len);
2237 priv->wep_key_curr_index = sme->key_idx;
2238 ret = mwifiex_set_encode(priv, NULL, sme->key,
2239 sme->key_len, sme->key_idx,
2245 * Scan entries are valid for some time (15 sec). So we can save one
2246 * active scan time if we just try cfg80211_get_bss first. If it fails
2247 * then request scan and cfg80211_get_bss() again for final output.
2250 if (is_scanning_required) {
2251 /* Do specific SSID scanning */
2252 if (mwifiex_request_scan(priv, &req_ssid)) {
2253 mwifiex_dbg(priv->adapter, ERROR, "scan error\n");
2258 /* Find the BSS we want using available scan results */
2259 if (mode == NL80211_IFTYPE_ADHOC)
2260 bss = cfg80211_get_bss(priv->wdev.wiphy, channel,
2261 bssid, ssid, ssid_len,
2262 IEEE80211_BSS_TYPE_IBSS,
2263 IEEE80211_PRIVACY_ANY);
2265 bss = cfg80211_get_bss(priv->wdev.wiphy, channel,
2266 bssid, ssid, ssid_len,
2267 IEEE80211_BSS_TYPE_ESS,
2268 IEEE80211_PRIVACY_ANY);
2271 if (is_scanning_required) {
2272 mwifiex_dbg(priv->adapter, MSG,
2273 "assoc: requested bss not found in scan results\n");
2276 is_scanning_required = 1;
2278 mwifiex_dbg(priv->adapter, MSG,
2279 "info: trying to associate to '%.*s' bssid %pM\n",
2280 req_ssid.ssid_len, (char *)req_ssid.ssid,
2282 memcpy(&priv->cfg_bssid, bss->bssid, ETH_ALEN);
2287 ret = mwifiex_bss_start(priv, bss, &req_ssid);
2291 if (mode == NL80211_IFTYPE_ADHOC) {
2292 /* Inform the BSS information to kernel, otherwise
2293 * kernel will give a panic after successful assoc */
2294 if (mwifiex_cfg80211_inform_ibss_bss(priv))
2302 * CFG802.11 operation handler for association request.
2304 * This function does not work when the current mode is set to Ad-Hoc, or
2305 * when there is already an association procedure going on. The given BSS
2306 * information is used to associate.
2309 mwifiex_cfg80211_connect(struct wiphy *wiphy, struct net_device *dev,
2310 struct cfg80211_connect_params *sme)
2312 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
2313 struct mwifiex_adapter *adapter = priv->adapter;
2316 if (GET_BSS_ROLE(priv) != MWIFIEX_BSS_ROLE_STA) {
2317 mwifiex_dbg(adapter, ERROR,
2318 "%s: reject infra assoc request in non-STA role\n",
2323 if (priv->wdev.current_bss) {
2324 mwifiex_dbg(adapter, ERROR,
2325 "%s: already connected\n", dev->name);
2329 if (priv->scan_block)
2330 priv->scan_block = false;
2332 if (test_bit(MWIFIEX_SURPRISE_REMOVED, &adapter->work_flags) ||
2333 test_bit(MWIFIEX_IS_CMD_TIMEDOUT, &adapter->work_flags)) {
2334 mwifiex_dbg(adapter, ERROR,
2335 "%s: Ignore connection.\t"
2336 "Card removed or FW in bad state\n",
2341 mwifiex_dbg(adapter, INFO,
2342 "info: Trying to associate to %.*s and bssid %pM\n",
2343 (int)sme->ssid_len, (char *)sme->ssid, sme->bssid);
2345 if (!mwifiex_stop_bg_scan(priv))
2346 cfg80211_sched_scan_stopped_rtnl(priv->wdev.wiphy, 0);
2348 ret = mwifiex_cfg80211_assoc(priv, sme->ssid_len, sme->ssid, sme->bssid,
2349 priv->bss_mode, sme->channel, sme, 0);
2351 cfg80211_connect_result(priv->netdev, priv->cfg_bssid, NULL, 0,
2352 NULL, 0, WLAN_STATUS_SUCCESS,
2354 mwifiex_dbg(priv->adapter, MSG,
2355 "info: associated to bssid %pM successfully\n",
2357 if (ISSUPP_TDLS_ENABLED(priv->adapter->fw_cap_info) &&
2358 priv->adapter->auto_tdls &&
2359 priv->bss_type == MWIFIEX_BSS_TYPE_STA)
2360 mwifiex_setup_auto_tdls_timer(priv);
2362 mwifiex_dbg(priv->adapter, ERROR,
2363 "info: association to bssid %pM failed\n",
2365 eth_zero_addr(priv->cfg_bssid);
2368 cfg80211_connect_result(priv->netdev, priv->cfg_bssid,
2369 NULL, 0, NULL, 0, ret,
2372 cfg80211_connect_result(priv->netdev, priv->cfg_bssid,
2374 WLAN_STATUS_UNSPECIFIED_FAILURE,
2382 * This function sets following parameters for ibss network.
2386 * - secondary channel offset
2388 static int mwifiex_set_ibss_params(struct mwifiex_private *priv,
2389 struct cfg80211_ibss_params *params)
2391 struct mwifiex_adapter *adapter = priv->adapter;
2393 u8 config_bands = 0;
2395 if (params->chandef.chan->band == NL80211_BAND_2GHZ) {
2396 if (!params->basic_rates) {
2397 config_bands = BAND_B | BAND_G;
2399 for (i = 0; i < mwifiex_band_2ghz.n_bitrates; i++) {
2401 * Rates below 6 Mbps in the table are CCK
2402 * rates; 802.11b and from 6 they are OFDM;
2405 if (mwifiex_rates[i].bitrate == 60) {
2411 if (params->basic_rates < index) {
2412 config_bands = BAND_B;
2414 config_bands = BAND_G;
2415 if (params->basic_rates % index)
2416 config_bands |= BAND_B;
2420 if (cfg80211_get_chandef_type(¶ms->chandef) !=
2422 config_bands |= BAND_G | BAND_GN;
2424 if (cfg80211_get_chandef_type(¶ms->chandef) ==
2426 config_bands = BAND_A;
2428 config_bands = BAND_AN | BAND_A;
2431 if (!((config_bands | adapter->fw_bands) & ~adapter->fw_bands)) {
2432 adapter->config_bands = config_bands;
2433 adapter->adhoc_start_band = config_bands;
2435 if ((config_bands & BAND_GN) || (config_bands & BAND_AN))
2436 adapter->adhoc_11n_enabled = true;
2438 adapter->adhoc_11n_enabled = false;
2441 adapter->sec_chan_offset =
2442 mwifiex_chan_type_to_sec_chan_offset(
2443 cfg80211_get_chandef_type(¶ms->chandef));
2444 priv->adhoc_channel = ieee80211_frequency_to_channel(
2445 params->chandef.chan->center_freq);
2447 mwifiex_dbg(adapter, INFO,
2448 "info: set ibss band %d, chan %d, chan offset %d\n",
2449 config_bands, priv->adhoc_channel,
2450 adapter->sec_chan_offset);
2456 * CFG802.11 operation handler to join an IBSS.
2458 * This function does not work in any mode other than Ad-Hoc, or if
2459 * a join operation is already in progress.
2462 mwifiex_cfg80211_join_ibss(struct wiphy *wiphy, struct net_device *dev,
2463 struct cfg80211_ibss_params *params)
2465 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
2468 if (priv->bss_mode != NL80211_IFTYPE_ADHOC) {
2469 mwifiex_dbg(priv->adapter, ERROR,
2470 "request to join ibss received\t"
2471 "when station is not in ibss mode\n");
2475 mwifiex_dbg(priv->adapter, MSG,
2476 "info: trying to join to %.*s and bssid %pM\n",
2477 params->ssid_len, (char *)params->ssid, params->bssid);
2479 mwifiex_set_ibss_params(priv, params);
2481 ret = mwifiex_cfg80211_assoc(priv, params->ssid_len, params->ssid,
2482 params->bssid, priv->bss_mode,
2483 params->chandef.chan, NULL,
2487 cfg80211_ibss_joined(priv->netdev, priv->cfg_bssid,
2488 params->chandef.chan, GFP_KERNEL);
2489 mwifiex_dbg(priv->adapter, MSG,
2490 "info: joined/created adhoc network with bssid\t"
2491 "%pM successfully\n", priv->cfg_bssid);
2493 mwifiex_dbg(priv->adapter, ERROR,
2494 "info: failed creating/joining adhoc network\n");
2501 * CFG802.11 operation handler to leave an IBSS.
2503 * This function does not work if a leave operation is
2504 * already in progress.
2507 mwifiex_cfg80211_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
2509 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
2511 mwifiex_dbg(priv->adapter, MSG, "info: disconnecting from essid %pM\n",
2513 if (mwifiex_deauthenticate(priv, NULL))
2516 eth_zero_addr(priv->cfg_bssid);
2522 * CFG802.11 operation handler for scan request.
2524 * This function issues a scan request to the firmware based upon
2525 * the user specified scan configuration. On successful completion,
2526 * it also informs the results.
2529 mwifiex_cfg80211_scan(struct wiphy *wiphy,
2530 struct cfg80211_scan_request *request)
2532 struct net_device *dev = request->wdev->netdev;
2533 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
2535 struct ieee80211_channel *chan;
2536 struct ieee_types_header *ie;
2537 struct mwifiex_user_scan_cfg *user_scan_cfg;
2538 u8 mac_addr[ETH_ALEN];
2540 mwifiex_dbg(priv->adapter, CMD,
2541 "info: received scan request on %s\n", dev->name);
2543 /* Block scan request if scan operation or scan cleanup when interface
2544 * is disabled is in process
2546 if (priv->scan_request || priv->scan_aborting) {
2547 mwifiex_dbg(priv->adapter, WARN,
2548 "cmd: Scan already in process..\n");
2552 if (!priv->wdev.current_bss && priv->scan_block)
2553 priv->scan_block = false;
2555 if (!mwifiex_stop_bg_scan(priv))
2556 cfg80211_sched_scan_stopped_rtnl(priv->wdev.wiphy, 0);
2558 user_scan_cfg = kzalloc(sizeof(*user_scan_cfg), GFP_KERNEL);
2562 priv->scan_request = request;
2564 if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) {
2565 get_random_mask_addr(mac_addr, request->mac_addr,
2566 request->mac_addr_mask);
2567 ether_addr_copy(request->mac_addr, mac_addr);
2568 ether_addr_copy(user_scan_cfg->random_mac, mac_addr);
2571 user_scan_cfg->num_ssids = request->n_ssids;
2572 user_scan_cfg->ssid_list = request->ssids;
2574 if (request->ie && request->ie_len) {
2576 for (i = 0; i < MWIFIEX_MAX_VSIE_NUM; i++) {
2577 if (priv->vs_ie[i].mask != MWIFIEX_VSIE_MASK_CLEAR)
2579 priv->vs_ie[i].mask = MWIFIEX_VSIE_MASK_SCAN;
2580 ie = (struct ieee_types_header *)(request->ie + offset);
2581 memcpy(&priv->vs_ie[i].ie, ie, sizeof(*ie) + ie->len);
2582 offset += sizeof(*ie) + ie->len;
2584 if (offset >= request->ie_len)
2589 for (i = 0; i < min_t(u32, request->n_channels,
2590 MWIFIEX_USER_SCAN_CHAN_MAX); i++) {
2591 chan = request->channels[i];
2592 user_scan_cfg->chan_list[i].chan_number = chan->hw_value;
2593 user_scan_cfg->chan_list[i].radio_type = chan->band;
2595 if ((chan->flags & IEEE80211_CHAN_NO_IR) || !request->n_ssids)
2596 user_scan_cfg->chan_list[i].scan_type =
2597 MWIFIEX_SCAN_TYPE_PASSIVE;
2599 user_scan_cfg->chan_list[i].scan_type =
2600 MWIFIEX_SCAN_TYPE_ACTIVE;
2602 user_scan_cfg->chan_list[i].scan_time = 0;
2605 if (priv->adapter->scan_chan_gap_enabled &&
2606 mwifiex_is_any_intf_active(priv))
2607 user_scan_cfg->scan_chan_gap =
2608 priv->adapter->scan_chan_gap_time;
2610 ret = mwifiex_scan_networks(priv, user_scan_cfg);
2611 kfree(user_scan_cfg);
2613 mwifiex_dbg(priv->adapter, ERROR,
2614 "scan failed: %d\n", ret);
2615 priv->scan_aborting = false;
2616 priv->scan_request = NULL;
2620 if (request->ie && request->ie_len) {
2621 for (i = 0; i < MWIFIEX_MAX_VSIE_NUM; i++) {
2622 if (priv->vs_ie[i].mask == MWIFIEX_VSIE_MASK_SCAN) {
2623 priv->vs_ie[i].mask = MWIFIEX_VSIE_MASK_CLEAR;
2624 memset(&priv->vs_ie[i].ie, 0,
2625 MWIFIEX_MAX_VSIE_LEN);
2632 /* CFG802.11 operation handler for sched_scan_start.
2634 * This function issues a bgscan config request to the firmware based upon
2635 * the user specified sched_scan configuration. On successful completion,
2636 * firmware will generate BGSCAN_REPORT event, driver should issue bgscan
2637 * query command to get sched_scan results from firmware.
2640 mwifiex_cfg80211_sched_scan_start(struct wiphy *wiphy,
2641 struct net_device *dev,
2642 struct cfg80211_sched_scan_request *request)
2644 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
2646 struct ieee80211_channel *chan;
2647 struct mwifiex_bg_scan_cfg *bgscan_cfg;
2648 struct ieee_types_header *ie;
2650 if (!request || (!request->n_ssids && !request->n_match_sets)) {
2651 wiphy_err(wiphy, "%s : Invalid Sched_scan parameters",
2656 wiphy_info(wiphy, "sched_scan start : n_ssids=%d n_match_sets=%d ",
2657 request->n_ssids, request->n_match_sets);
2658 wiphy_info(wiphy, "n_channels=%d interval=%d ie_len=%d\n",
2659 request->n_channels, request->scan_plans->interval,
2660 (int)request->ie_len);
2662 bgscan_cfg = kzalloc(sizeof(*bgscan_cfg), GFP_KERNEL);
2666 if (priv->scan_request || priv->scan_aborting)
2667 bgscan_cfg->start_later = true;
2669 bgscan_cfg->num_ssids = request->n_match_sets;
2670 bgscan_cfg->ssid_list = request->match_sets;
2672 if (request->ie && request->ie_len) {
2674 for (i = 0; i < MWIFIEX_MAX_VSIE_NUM; i++) {
2675 if (priv->vs_ie[i].mask != MWIFIEX_VSIE_MASK_CLEAR)
2677 priv->vs_ie[i].mask = MWIFIEX_VSIE_MASK_BGSCAN;
2678 ie = (struct ieee_types_header *)(request->ie + offset);
2679 memcpy(&priv->vs_ie[i].ie, ie, sizeof(*ie) + ie->len);
2680 offset += sizeof(*ie) + ie->len;
2682 if (offset >= request->ie_len)
2687 for (i = 0; i < min_t(u32, request->n_channels,
2688 MWIFIEX_BG_SCAN_CHAN_MAX); i++) {
2689 chan = request->channels[i];
2690 bgscan_cfg->chan_list[i].chan_number = chan->hw_value;
2691 bgscan_cfg->chan_list[i].radio_type = chan->band;
2693 if ((chan->flags & IEEE80211_CHAN_NO_IR) || !request->n_ssids)
2694 bgscan_cfg->chan_list[i].scan_type =
2695 MWIFIEX_SCAN_TYPE_PASSIVE;
2697 bgscan_cfg->chan_list[i].scan_type =
2698 MWIFIEX_SCAN_TYPE_ACTIVE;
2700 bgscan_cfg->chan_list[i].scan_time = 0;
2703 bgscan_cfg->chan_per_scan = min_t(u32, request->n_channels,
2704 MWIFIEX_BG_SCAN_CHAN_MAX);
2706 /* Use at least 15 second for per scan cycle */
2707 bgscan_cfg->scan_interval = (request->scan_plans->interval >
2708 MWIFIEX_BGSCAN_INTERVAL) ?
2709 request->scan_plans->interval :
2710 MWIFIEX_BGSCAN_INTERVAL;
2712 bgscan_cfg->repeat_count = MWIFIEX_BGSCAN_REPEAT_COUNT;
2713 bgscan_cfg->report_condition = MWIFIEX_BGSCAN_SSID_MATCH |
2714 MWIFIEX_BGSCAN_WAIT_ALL_CHAN_DONE;
2715 bgscan_cfg->bss_type = MWIFIEX_BSS_MODE_INFRA;
2716 bgscan_cfg->action = MWIFIEX_BGSCAN_ACT_SET;
2717 bgscan_cfg->enable = true;
2718 if (request->min_rssi_thold != NL80211_SCAN_RSSI_THOLD_OFF) {
2719 bgscan_cfg->report_condition |= MWIFIEX_BGSCAN_SSID_RSSI_MATCH;
2720 bgscan_cfg->rssi_threshold = request->min_rssi_thold;
2723 if (mwifiex_send_cmd(priv, HostCmd_CMD_802_11_BG_SCAN_CONFIG,
2724 HostCmd_ACT_GEN_SET, 0, bgscan_cfg, true)) {
2729 priv->sched_scanning = true;
2735 /* CFG802.11 operation handler for sched_scan_stop.
2737 * This function issues a bgscan config command to disable
2738 * previous bgscan configuration in the firmware
2740 static int mwifiex_cfg80211_sched_scan_stop(struct wiphy *wiphy,
2741 struct net_device *dev, u64 reqid)
2743 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
2745 wiphy_info(wiphy, "sched scan stop!");
2746 mwifiex_stop_bg_scan(priv);
2751 static void mwifiex_setup_vht_caps(struct ieee80211_sta_vht_cap *vht_info,
2752 struct mwifiex_private *priv)
2754 struct mwifiex_adapter *adapter = priv->adapter;
2756 vht_info->vht_supported = true;
2758 vht_info->cap = adapter->hw_dot_11ac_dev_cap;
2759 /* Update MCS support for VHT */
2760 vht_info->vht_mcs.rx_mcs_map = cpu_to_le16(
2761 adapter->hw_dot_11ac_mcs_support & 0xFFFF);
2762 vht_info->vht_mcs.rx_highest = 0;
2763 vht_info->vht_mcs.tx_mcs_map = cpu_to_le16(
2764 adapter->hw_dot_11ac_mcs_support >> 16);
2765 vht_info->vht_mcs.tx_highest = 0;
2769 * This function sets up the CFG802.11 specific HT capability fields
2770 * with default values.
2772 * The following default values are set -
2773 * - HT Supported = True
2774 * - Maximum AMPDU length factor = IEEE80211_HT_MAX_AMPDU_64K
2775 * - Minimum AMPDU spacing = IEEE80211_HT_MPDU_DENSITY_NONE
2776 * - HT Capabilities supported by firmware
2777 * - MCS information, Rx mask = 0xff
2778 * - MCD information, Tx parameters = IEEE80211_HT_MCS_TX_DEFINED (0x01)
2781 mwifiex_setup_ht_caps(struct ieee80211_sta_ht_cap *ht_info,
2782 struct mwifiex_private *priv)
2785 struct ieee80211_mcs_info mcs_set;
2786 u8 *mcs = (u8 *)&mcs_set;
2787 struct mwifiex_adapter *adapter = priv->adapter;
2789 ht_info->ht_supported = true;
2790 ht_info->ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
2791 ht_info->ampdu_density = IEEE80211_HT_MPDU_DENSITY_NONE;
2793 memset(&ht_info->mcs, 0, sizeof(ht_info->mcs));
2795 /* Fill HT capability information */
2796 if (ISSUPP_CHANWIDTH40(adapter->hw_dot_11n_dev_cap))
2797 ht_info->cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
2799 ht_info->cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
2801 if (ISSUPP_SHORTGI20(adapter->hw_dot_11n_dev_cap))
2802 ht_info->cap |= IEEE80211_HT_CAP_SGI_20;
2804 ht_info->cap &= ~IEEE80211_HT_CAP_SGI_20;
2806 if (ISSUPP_SHORTGI40(adapter->hw_dot_11n_dev_cap))
2807 ht_info->cap |= IEEE80211_HT_CAP_SGI_40;
2809 ht_info->cap &= ~IEEE80211_HT_CAP_SGI_40;
2811 if (adapter->user_dev_mcs_support == HT_STREAM_2X2)
2812 ht_info->cap |= 2 << IEEE80211_HT_CAP_RX_STBC_SHIFT;
2814 ht_info->cap |= 1 << IEEE80211_HT_CAP_RX_STBC_SHIFT;
2816 if (ISSUPP_TXSTBC(adapter->hw_dot_11n_dev_cap))
2817 ht_info->cap |= IEEE80211_HT_CAP_TX_STBC;
2819 ht_info->cap &= ~IEEE80211_HT_CAP_TX_STBC;
2821 if (ISSUPP_GREENFIELD(adapter->hw_dot_11n_dev_cap))
2822 ht_info->cap |= IEEE80211_HT_CAP_GRN_FLD;
2824 ht_info->cap &= ~IEEE80211_HT_CAP_GRN_FLD;
2826 if (ISENABLED_40MHZ_INTOLERANT(adapter->hw_dot_11n_dev_cap))
2827 ht_info->cap |= IEEE80211_HT_CAP_40MHZ_INTOLERANT;
2829 ht_info->cap &= ~IEEE80211_HT_CAP_40MHZ_INTOLERANT;
2831 if (ISSUPP_RXLDPC(adapter->hw_dot_11n_dev_cap))
2832 ht_info->cap |= IEEE80211_HT_CAP_LDPC_CODING;
2834 ht_info->cap &= ~IEEE80211_HT_CAP_LDPC_CODING;
2836 ht_info->cap &= ~IEEE80211_HT_CAP_MAX_AMSDU;
2837 ht_info->cap |= IEEE80211_HT_CAP_SM_PS;
2839 rx_mcs_supp = GET_RXMCSSUPP(adapter->user_dev_mcs_support);
2840 /* Set MCS for 1x1/2x2 */
2841 memset(mcs, 0xff, rx_mcs_supp);
2842 /* Clear all the other values */
2843 memset(&mcs[rx_mcs_supp], 0,
2844 sizeof(struct ieee80211_mcs_info) - rx_mcs_supp);
2845 if (priv->bss_mode == NL80211_IFTYPE_STATION ||
2846 ISSUPP_CHANWIDTH40(adapter->hw_dot_11n_dev_cap))
2847 /* Set MCS32 for infra mode or ad-hoc mode with 40MHz support */
2848 SETHT_MCS32(mcs_set.rx_mask);
2850 memcpy((u8 *) &ht_info->mcs, mcs, sizeof(struct ieee80211_mcs_info));
2852 ht_info->mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED;
2856 * create a new virtual interface with the given name and name assign type
2858 struct wireless_dev *mwifiex_add_virtual_intf(struct wiphy *wiphy,
2860 unsigned char name_assign_type,
2861 enum nl80211_iftype type,
2862 struct vif_params *params)
2864 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
2865 struct mwifiex_private *priv;
2866 struct net_device *dev;
2871 return ERR_PTR(-EFAULT);
2874 case NL80211_IFTYPE_UNSPECIFIED:
2875 case NL80211_IFTYPE_STATION:
2876 case NL80211_IFTYPE_ADHOC:
2877 if (adapter->curr_iface_comb.sta_intf ==
2878 adapter->iface_limit.sta_intf) {
2879 mwifiex_dbg(adapter, ERROR,
2880 "cannot create multiple sta/adhoc ifaces\n");
2881 return ERR_PTR(-EINVAL);
2884 priv = mwifiex_get_unused_priv_by_bss_type(
2885 adapter, MWIFIEX_BSS_TYPE_STA);
2887 mwifiex_dbg(adapter, ERROR,
2888 "could not get free private struct\n");
2889 return ERR_PTR(-EFAULT);
2892 priv->wdev.wiphy = wiphy;
2893 priv->wdev.iftype = NL80211_IFTYPE_STATION;
2895 if (type == NL80211_IFTYPE_UNSPECIFIED)
2896 priv->bss_mode = NL80211_IFTYPE_STATION;
2898 priv->bss_mode = type;
2900 priv->bss_type = MWIFIEX_BSS_TYPE_STA;
2901 priv->frame_type = MWIFIEX_DATA_FRAME_TYPE_ETH_II;
2902 priv->bss_priority = 0;
2903 priv->bss_role = MWIFIEX_BSS_ROLE_STA;
2906 case NL80211_IFTYPE_AP:
2907 if (adapter->curr_iface_comb.uap_intf ==
2908 adapter->iface_limit.uap_intf) {
2909 mwifiex_dbg(adapter, ERROR,
2910 "cannot create multiple AP ifaces\n");
2911 return ERR_PTR(-EINVAL);
2914 priv = mwifiex_get_unused_priv_by_bss_type(
2915 adapter, MWIFIEX_BSS_TYPE_UAP);
2917 mwifiex_dbg(adapter, ERROR,
2918 "could not get free private struct\n");
2919 return ERR_PTR(-EFAULT);
2922 priv->wdev.wiphy = wiphy;
2923 priv->wdev.iftype = NL80211_IFTYPE_AP;
2925 priv->bss_type = MWIFIEX_BSS_TYPE_UAP;
2926 priv->frame_type = MWIFIEX_DATA_FRAME_TYPE_ETH_II;
2927 priv->bss_priority = 0;
2928 priv->bss_role = MWIFIEX_BSS_ROLE_UAP;
2929 priv->bss_started = 0;
2930 priv->bss_mode = type;
2933 case NL80211_IFTYPE_P2P_CLIENT:
2934 if (adapter->curr_iface_comb.p2p_intf ==
2935 adapter->iface_limit.p2p_intf) {
2936 mwifiex_dbg(adapter, ERROR,
2937 "cannot create multiple P2P ifaces\n");
2938 return ERR_PTR(-EINVAL);
2941 priv = mwifiex_get_unused_priv_by_bss_type(
2942 adapter, MWIFIEX_BSS_TYPE_P2P);
2944 mwifiex_dbg(adapter, ERROR,
2945 "could not get free private struct\n");
2946 return ERR_PTR(-EFAULT);
2949 priv->wdev.wiphy = wiphy;
2950 /* At start-up, wpa_supplicant tries to change the interface
2951 * to NL80211_IFTYPE_STATION if it is not managed mode.
2953 priv->wdev.iftype = NL80211_IFTYPE_P2P_CLIENT;
2954 priv->bss_mode = NL80211_IFTYPE_P2P_CLIENT;
2956 /* Setting bss_type to P2P tells firmware that this interface
2957 * is receiving P2P peers found during find phase and doing
2958 * action frame handshake.
2960 priv->bss_type = MWIFIEX_BSS_TYPE_P2P;
2962 priv->frame_type = MWIFIEX_DATA_FRAME_TYPE_ETH_II;
2963 priv->bss_priority = MWIFIEX_BSS_ROLE_STA;
2964 priv->bss_role = MWIFIEX_BSS_ROLE_STA;
2965 priv->bss_started = 0;
2967 if (mwifiex_cfg80211_init_p2p_client(priv)) {
2968 memset(&priv->wdev, 0, sizeof(priv->wdev));
2969 priv->wdev.iftype = NL80211_IFTYPE_UNSPECIFIED;
2970 return ERR_PTR(-EFAULT);
2975 mwifiex_dbg(adapter, ERROR, "type not supported\n");
2976 return ERR_PTR(-EINVAL);
2979 dev = alloc_netdev_mqs(sizeof(struct mwifiex_private *), name,
2980 name_assign_type, ether_setup,
2981 IEEE80211_NUM_ACS, 1);
2983 mwifiex_dbg(adapter, ERROR,
2984 "no memory available for netdevice\n");
2986 goto err_alloc_netdev;
2989 mwifiex_init_priv_params(priv, dev);
2993 if (!adapter->mfg_mode) {
2994 mwifiex_set_mac_address(priv, dev, false, NULL);
2996 ret = mwifiex_send_cmd(priv, HostCmd_CMD_SET_BSS_MODE,
2997 HostCmd_ACT_GEN_SET, 0, NULL, true);
2999 goto err_set_bss_mode;
3001 ret = mwifiex_sta_init_cmd(priv, false, false);
3006 mwifiex_setup_ht_caps(&wiphy->bands[NL80211_BAND_2GHZ]->ht_cap, priv);
3007 if (adapter->is_hw_11ac_capable)
3008 mwifiex_setup_vht_caps(
3009 &wiphy->bands[NL80211_BAND_2GHZ]->vht_cap, priv);
3011 if (adapter->config_bands & BAND_A)
3012 mwifiex_setup_ht_caps(
3013 &wiphy->bands[NL80211_BAND_5GHZ]->ht_cap, priv);
3015 if ((adapter->config_bands & BAND_A) && adapter->is_hw_11ac_capable)
3016 mwifiex_setup_vht_caps(
3017 &wiphy->bands[NL80211_BAND_5GHZ]->vht_cap, priv);
3019 dev_net_set(dev, wiphy_net(wiphy));
3020 dev->ieee80211_ptr = &priv->wdev;
3021 dev->ieee80211_ptr->iftype = priv->bss_mode;
3022 SET_NETDEV_DEV(dev, wiphy_dev(wiphy));
3024 dev->flags |= IFF_BROADCAST | IFF_MULTICAST;
3025 dev->watchdog_timeo = MWIFIEX_DEFAULT_WATCHDOG_TIMEOUT;
3026 dev->hard_header_len += MWIFIEX_MIN_DATA_HEADER_LEN;
3027 dev->ethtool_ops = &mwifiex_ethtool_ops;
3029 mdev_priv = netdev_priv(dev);
3030 *((unsigned long *) mdev_priv) = (unsigned long) priv;
3032 SET_NETDEV_DEV(dev, adapter->dev);
3034 priv->dfs_cac_workqueue = alloc_workqueue("MWIFIEX_DFS_CAC%s",
3037 WQ_UNBOUND, 1, name);
3038 if (!priv->dfs_cac_workqueue) {
3039 mwifiex_dbg(adapter, ERROR, "cannot alloc DFS CAC queue\n");
3044 INIT_DELAYED_WORK(&priv->dfs_cac_work, mwifiex_dfs_cac_work_queue);
3046 priv->dfs_chan_sw_workqueue = alloc_workqueue("MWIFIEX_DFS_CHSW%s",
3047 WQ_HIGHPRI | WQ_UNBOUND |
3048 WQ_MEM_RECLAIM, 1, name);
3049 if (!priv->dfs_chan_sw_workqueue) {
3050 mwifiex_dbg(adapter, ERROR, "cannot alloc DFS channel sw queue\n");
3052 goto err_alloc_chsw;
3055 INIT_DELAYED_WORK(&priv->dfs_chan_sw_work,
3056 mwifiex_dfs_chan_sw_work_queue);
3058 mutex_init(&priv->async_mutex);
3060 /* Register network device */
3061 if (register_netdevice(dev)) {
3062 mwifiex_dbg(adapter, ERROR, "cannot register network device\n");
3064 goto err_reg_netdev;
3067 mwifiex_dbg(adapter, INFO,
3068 "info: %s: Marvell 802.11 Adapter\n", dev->name);
3070 #ifdef CONFIG_DEBUG_FS
3071 mwifiex_dev_debugfs_init(priv);
3075 case NL80211_IFTYPE_UNSPECIFIED:
3076 case NL80211_IFTYPE_STATION:
3077 case NL80211_IFTYPE_ADHOC:
3078 adapter->curr_iface_comb.sta_intf++;
3080 case NL80211_IFTYPE_AP:
3081 adapter->curr_iface_comb.uap_intf++;
3083 case NL80211_IFTYPE_P2P_CLIENT:
3084 adapter->curr_iface_comb.p2p_intf++;
3087 /* This should be dead code; checked above */
3088 mwifiex_dbg(adapter, ERROR, "type not supported\n");
3089 return ERR_PTR(-EINVAL);
3095 destroy_workqueue(priv->dfs_chan_sw_workqueue);
3096 priv->dfs_chan_sw_workqueue = NULL;
3098 destroy_workqueue(priv->dfs_cac_workqueue);
3099 priv->dfs_cac_workqueue = NULL;
3102 priv->netdev = NULL;
3106 memset(&priv->wdev, 0, sizeof(priv->wdev));
3107 priv->wdev.iftype = NL80211_IFTYPE_UNSPECIFIED;
3108 priv->bss_mode = NL80211_IFTYPE_UNSPECIFIED;
3109 return ERR_PTR(ret);
3111 EXPORT_SYMBOL_GPL(mwifiex_add_virtual_intf);
3114 * del_virtual_intf: remove the virtual interface determined by dev
3116 int mwifiex_del_virtual_intf(struct wiphy *wiphy, struct wireless_dev *wdev)
3118 struct mwifiex_private *priv = mwifiex_netdev_get_priv(wdev->netdev);
3119 struct mwifiex_adapter *adapter = priv->adapter;
3120 struct sk_buff *skb, *tmp;
3122 #ifdef CONFIG_DEBUG_FS
3123 mwifiex_dev_debugfs_remove(priv);
3126 if (priv->sched_scanning)
3127 priv->sched_scanning = false;
3129 mwifiex_stop_net_dev_queue(priv->netdev, adapter);
3131 skb_queue_walk_safe(&priv->bypass_txq, skb, tmp) {
3132 skb_unlink(skb, &priv->bypass_txq);
3133 mwifiex_write_data_complete(priv->adapter, skb, 0, -1);
3136 if (netif_carrier_ok(priv->netdev))
3137 netif_carrier_off(priv->netdev);
3139 if (wdev->netdev->reg_state == NETREG_REGISTERED)
3140 unregister_netdevice(wdev->netdev);
3142 if (priv->dfs_cac_workqueue) {
3143 flush_workqueue(priv->dfs_cac_workqueue);
3144 destroy_workqueue(priv->dfs_cac_workqueue);
3145 priv->dfs_cac_workqueue = NULL;
3148 if (priv->dfs_chan_sw_workqueue) {
3149 flush_workqueue(priv->dfs_chan_sw_workqueue);
3150 destroy_workqueue(priv->dfs_chan_sw_workqueue);
3151 priv->dfs_chan_sw_workqueue = NULL;
3153 /* Clear the priv in adapter */
3154 priv->netdev = NULL;
3156 switch (priv->bss_mode) {
3157 case NL80211_IFTYPE_UNSPECIFIED:
3158 case NL80211_IFTYPE_STATION:
3159 case NL80211_IFTYPE_ADHOC:
3160 adapter->curr_iface_comb.sta_intf--;
3162 case NL80211_IFTYPE_AP:
3163 adapter->curr_iface_comb.uap_intf--;
3165 case NL80211_IFTYPE_P2P_CLIENT:
3166 case NL80211_IFTYPE_P2P_GO:
3167 adapter->curr_iface_comb.p2p_intf--;
3170 mwifiex_dbg(adapter, ERROR,
3171 "del_virtual_intf: type not supported\n");
3175 priv->bss_mode = NL80211_IFTYPE_UNSPECIFIED;
3177 if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA ||
3178 GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_UAP)
3179 kfree(priv->hist_data);
3183 EXPORT_SYMBOL_GPL(mwifiex_del_virtual_intf);
3186 mwifiex_is_pattern_supported(struct cfg80211_pkt_pattern *pat, s8 *byte_seq,
3189 int j, k, valid_byte_cnt = 0;
3190 bool dont_care_byte = false;
3192 for (j = 0; j < DIV_ROUND_UP(pat->pattern_len, 8); j++) {
3193 for (k = 0; k < 8; k++) {
3194 if (pat->mask[j] & 1 << k) {
3195 memcpy(byte_seq + valid_byte_cnt,
3196 &pat->pattern[j * 8 + k], 1);
3202 dont_care_byte = true;
3205 /* wildcard bytes record as the offset
3206 * before the valid byte
3208 if (!valid_byte_cnt && !dont_care_byte)
3211 if (valid_byte_cnt > max_byte_seq)
3216 byte_seq[max_byte_seq] = valid_byte_cnt;
3222 static void mwifiex_set_auto_arp_mef_entry(struct mwifiex_private *priv,
3223 struct mwifiex_mef_entry *mef_entry)
3225 int i, filt_num = 0, num_ipv4 = 0;
3226 struct in_device *in_dev;
3227 struct in_ifaddr *ifa;
3228 __be32 ips[MWIFIEX_MAX_SUPPORTED_IPADDR];
3229 struct mwifiex_adapter *adapter = priv->adapter;
3231 mef_entry->mode = MEF_MODE_HOST_SLEEP;
3232 mef_entry->action = MEF_ACTION_AUTO_ARP;
3234 /* Enable ARP offload feature */
3235 memset(ips, 0, sizeof(ips));
3236 for (i = 0; i < MWIFIEX_MAX_BSS_NUM; i++) {
3237 if (adapter->priv[i]->netdev) {
3238 in_dev = __in_dev_get_rtnl(adapter->priv[i]->netdev);
3241 ifa = in_dev->ifa_list;
3242 if (!ifa || !ifa->ifa_local)
3244 ips[i] = ifa->ifa_local;
3249 for (i = 0; i < num_ipv4; i++) {
3252 mef_entry->filter[filt_num].repeat = 1;
3253 memcpy(mef_entry->filter[filt_num].byte_seq,
3254 (u8 *)&ips[i], sizeof(ips[i]));
3255 mef_entry->filter[filt_num].
3256 byte_seq[MWIFIEX_MEF_MAX_BYTESEQ] =
3258 mef_entry->filter[filt_num].offset = 46;
3259 mef_entry->filter[filt_num].filt_type = TYPE_EQ;
3261 mef_entry->filter[filt_num].filt_action =
3267 mef_entry->filter[filt_num].repeat = 1;
3268 mef_entry->filter[filt_num].byte_seq[0] = 0x08;
3269 mef_entry->filter[filt_num].byte_seq[1] = 0x06;
3270 mef_entry->filter[filt_num].byte_seq[MWIFIEX_MEF_MAX_BYTESEQ] = 2;
3271 mef_entry->filter[filt_num].offset = 20;
3272 mef_entry->filter[filt_num].filt_type = TYPE_EQ;
3273 mef_entry->filter[filt_num].filt_action = TYPE_AND;
3276 static int mwifiex_set_wowlan_mef_entry(struct mwifiex_private *priv,
3277 struct mwifiex_ds_mef_cfg *mef_cfg,
3278 struct mwifiex_mef_entry *mef_entry,
3279 struct cfg80211_wowlan *wowlan)
3281 int i, filt_num = 0, ret = 0;
3282 bool first_pat = true;
3283 u8 byte_seq[MWIFIEX_MEF_MAX_BYTESEQ + 1];
3284 static const u8 ipv4_mc_mac[] = {0x33, 0x33};
3285 static const u8 ipv6_mc_mac[] = {0x01, 0x00, 0x5e};
3287 mef_entry->mode = MEF_MODE_HOST_SLEEP;
3288 mef_entry->action = MEF_ACTION_ALLOW_AND_WAKEUP_HOST;
3290 for (i = 0; i < wowlan->n_patterns; i++) {
3291 memset(byte_seq, 0, sizeof(byte_seq));
3292 if (!mwifiex_is_pattern_supported(&wowlan->patterns[i],
3294 MWIFIEX_MEF_MAX_BYTESEQ)) {
3295 mwifiex_dbg(priv->adapter, ERROR,
3296 "Pattern not supported\n");
3300 if (!wowlan->patterns[i].pkt_offset) {
3301 if (!(byte_seq[0] & 0x01) &&
3302 (byte_seq[MWIFIEX_MEF_MAX_BYTESEQ] == 1)) {
3303 mef_cfg->criteria |= MWIFIEX_CRITERIA_UNICAST;
3305 } else if (is_broadcast_ether_addr(byte_seq)) {
3306 mef_cfg->criteria |= MWIFIEX_CRITERIA_BROADCAST;
3308 } else if ((!memcmp(byte_seq, ipv4_mc_mac, 2) &&
3309 (byte_seq[MWIFIEX_MEF_MAX_BYTESEQ] == 2)) ||
3310 (!memcmp(byte_seq, ipv6_mc_mac, 3) &&
3311 (byte_seq[MWIFIEX_MEF_MAX_BYTESEQ] == 3))) {
3312 mef_cfg->criteria |= MWIFIEX_CRITERIA_MULTICAST;
3316 mef_entry->filter[filt_num].repeat = 1;
3317 mef_entry->filter[filt_num].offset =
3318 wowlan->patterns[i].pkt_offset;
3319 memcpy(mef_entry->filter[filt_num].byte_seq, byte_seq,
3321 mef_entry->filter[filt_num].filt_type = TYPE_EQ;
3325 mwifiex_dbg(priv->adapter, INFO, "Wake on patterns\n");
3327 mef_entry->filter[filt_num].filt_action = TYPE_AND;
3333 if (wowlan->magic_pkt) {
3334 mef_cfg->criteria |= MWIFIEX_CRITERIA_UNICAST;
3335 mef_entry->filter[filt_num].repeat = 16;
3336 memcpy(mef_entry->filter[filt_num].byte_seq, priv->curr_addr,
3338 mef_entry->filter[filt_num].byte_seq[MWIFIEX_MEF_MAX_BYTESEQ] =
3340 mef_entry->filter[filt_num].offset = 28;
3341 mef_entry->filter[filt_num].filt_type = TYPE_EQ;
3343 mef_entry->filter[filt_num].filt_action = TYPE_OR;
3346 mef_entry->filter[filt_num].repeat = 16;
3347 memcpy(mef_entry->filter[filt_num].byte_seq, priv->curr_addr,
3349 mef_entry->filter[filt_num].byte_seq[MWIFIEX_MEF_MAX_BYTESEQ] =
3351 mef_entry->filter[filt_num].offset = 56;
3352 mef_entry->filter[filt_num].filt_type = TYPE_EQ;
3353 mef_entry->filter[filt_num].filt_action = TYPE_OR;
3354 mwifiex_dbg(priv->adapter, INFO, "Wake on magic packet\n");
3359 static int mwifiex_set_mef_filter(struct mwifiex_private *priv,
3360 struct cfg80211_wowlan *wowlan)
3362 int ret = 0, num_entries = 1;
3363 struct mwifiex_ds_mef_cfg mef_cfg;
3364 struct mwifiex_mef_entry *mef_entry;
3366 if (wowlan->n_patterns || wowlan->magic_pkt)
3369 mef_entry = kcalloc(num_entries, sizeof(*mef_entry), GFP_KERNEL);
3373 memset(&mef_cfg, 0, sizeof(mef_cfg));
3374 mef_cfg.criteria |= MWIFIEX_CRITERIA_BROADCAST |
3375 MWIFIEX_CRITERIA_UNICAST;
3376 mef_cfg.num_entries = num_entries;
3377 mef_cfg.mef_entry = mef_entry;
3379 mwifiex_set_auto_arp_mef_entry(priv, &mef_entry[0]);
3381 if (wowlan->n_patterns || wowlan->magic_pkt) {
3382 ret = mwifiex_set_wowlan_mef_entry(priv, &mef_cfg,
3383 &mef_entry[1], wowlan);
3388 if (!mef_cfg.criteria)
3389 mef_cfg.criteria = MWIFIEX_CRITERIA_BROADCAST |
3390 MWIFIEX_CRITERIA_UNICAST |
3391 MWIFIEX_CRITERIA_MULTICAST;
3393 ret = mwifiex_send_cmd(priv, HostCmd_CMD_MEF_CFG,
3394 HostCmd_ACT_GEN_SET, 0,
3402 static int mwifiex_cfg80211_suspend(struct wiphy *wiphy,
3403 struct cfg80211_wowlan *wowlan)
3405 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
3406 struct mwifiex_ds_hs_cfg hs_cfg;
3407 int i, ret = 0, retry_num = 10;
3408 struct mwifiex_private *priv;
3409 struct mwifiex_private *sta_priv =
3410 mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_STA);
3412 sta_priv->scan_aborting = true;
3413 for (i = 0; i < adapter->priv_num; i++) {
3414 priv = adapter->priv[i];
3415 mwifiex_abort_cac(priv);
3418 mwifiex_cancel_all_pending_cmd(adapter);
3420 for (i = 0; i < adapter->priv_num; i++) {
3421 priv = adapter->priv[i];
3422 if (priv && priv->netdev)
3423 netif_device_detach(priv->netdev);
3426 for (i = 0; i < retry_num; i++) {
3427 if (!mwifiex_wmm_lists_empty(adapter) ||
3428 !mwifiex_bypass_txlist_empty(adapter) ||
3429 !skb_queue_empty(&adapter->tx_data_q))
3430 usleep_range(10000, 15000);
3436 mwifiex_dbg(adapter, ERROR,
3437 "None of the WOWLAN triggers enabled\n");
3442 if (!sta_priv->media_connected && !wowlan->nd_config) {
3443 mwifiex_dbg(adapter, ERROR,
3444 "Can not configure WOWLAN in disconnected state\n");
3449 ret = mwifiex_set_mef_filter(sta_priv, wowlan);
3451 mwifiex_dbg(adapter, ERROR, "Failed to set MEF filter\n");
3455 memset(&hs_cfg, 0, sizeof(hs_cfg));
3456 hs_cfg.conditions = le32_to_cpu(adapter->hs_cfg.conditions);
3458 if (wowlan->nd_config) {
3459 mwifiex_dbg(adapter, INFO, "Wake on net detect\n");
3460 hs_cfg.conditions |= HS_CFG_COND_MAC_EVENT;
3461 mwifiex_cfg80211_sched_scan_start(wiphy, sta_priv->netdev,
3465 if (wowlan->disconnect) {
3466 hs_cfg.conditions |= HS_CFG_COND_MAC_EVENT;
3467 mwifiex_dbg(sta_priv->adapter, INFO, "Wake on device disconnect\n");
3470 hs_cfg.is_invoke_hostcmd = false;
3471 hs_cfg.gpio = adapter->hs_cfg.gpio;
3472 hs_cfg.gap = adapter->hs_cfg.gap;
3473 ret = mwifiex_set_hs_params(sta_priv, HostCmd_ACT_GEN_SET,
3474 MWIFIEX_SYNC_CMD, &hs_cfg);
3476 mwifiex_dbg(adapter, ERROR, "Failed to set HS params\n");
3479 sta_priv->scan_aborting = false;
3483 static int mwifiex_cfg80211_resume(struct wiphy *wiphy)
3485 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
3486 struct mwifiex_private *priv;
3487 struct mwifiex_ds_wakeup_reason wakeup_reason;
3488 struct cfg80211_wowlan_wakeup wakeup_report;
3490 bool report_wakeup_reason = true;
3492 for (i = 0; i < adapter->priv_num; i++) {
3493 priv = adapter->priv[i];
3494 if (priv && priv->netdev)
3495 netif_device_attach(priv->netdev);
3498 if (!wiphy->wowlan_config)
3501 priv = mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_STA);
3502 mwifiex_get_wakeup_reason(priv, HostCmd_ACT_GEN_GET, MWIFIEX_SYNC_CMD,
3504 memset(&wakeup_report, 0, sizeof(struct cfg80211_wowlan_wakeup));
3506 wakeup_report.pattern_idx = -1;
3508 switch (wakeup_reason.hs_wakeup_reason) {
3509 case NO_HSWAKEUP_REASON:
3511 case BCAST_DATA_MATCHED:
3513 case MCAST_DATA_MATCHED:
3515 case UCAST_DATA_MATCHED:
3517 case MASKTABLE_EVENT_MATCHED:
3519 case NON_MASKABLE_EVENT_MATCHED:
3520 if (wiphy->wowlan_config->disconnect)
3521 wakeup_report.disconnect = true;
3522 if (wiphy->wowlan_config->nd_config)
3523 wakeup_report.net_detect = adapter->nd_info;
3525 case NON_MASKABLE_CONDITION_MATCHED:
3527 case MAGIC_PATTERN_MATCHED:
3528 if (wiphy->wowlan_config->magic_pkt)
3529 wakeup_report.magic_pkt = true;
3530 if (wiphy->wowlan_config->n_patterns)
3531 wakeup_report.pattern_idx = 1;
3533 case GTK_REKEY_FAILURE:
3534 if (wiphy->wowlan_config->gtk_rekey_failure)
3535 wakeup_report.gtk_rekey_failure = true;
3538 report_wakeup_reason = false;
3542 if (report_wakeup_reason)
3543 cfg80211_report_wowlan_wakeup(&priv->wdev, &wakeup_report,
3547 if (adapter->nd_info) {
3548 for (i = 0 ; i < adapter->nd_info->n_matches ; i++)
3549 kfree(adapter->nd_info->matches[i]);
3550 kfree(adapter->nd_info);
3551 adapter->nd_info = NULL;
3557 static void mwifiex_cfg80211_set_wakeup(struct wiphy *wiphy,
3560 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
3562 device_set_wakeup_enable(adapter->dev, enabled);
3565 static int mwifiex_set_rekey_data(struct wiphy *wiphy, struct net_device *dev,
3566 struct cfg80211_gtk_rekey_data *data)
3568 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
3570 if (!ISSUPP_FIRMWARE_SUPPLICANT(priv->adapter->fw_cap_info))
3573 return mwifiex_send_cmd(priv, HostCmd_CMD_GTK_REKEY_OFFLOAD_CFG,
3574 HostCmd_ACT_GEN_SET, 0, data, true);
3579 static int mwifiex_get_coalesce_pkt_type(u8 *byte_seq)
3581 static const u8 ipv4_mc_mac[] = {0x33, 0x33};
3582 static const u8 ipv6_mc_mac[] = {0x01, 0x00, 0x5e};
3583 static const u8 bc_mac[] = {0xff, 0xff, 0xff, 0xff};
3585 if ((byte_seq[0] & 0x01) &&
3586 (byte_seq[MWIFIEX_COALESCE_MAX_BYTESEQ] == 1))
3587 return PACKET_TYPE_UNICAST;
3588 else if (!memcmp(byte_seq, bc_mac, 4))
3589 return PACKET_TYPE_BROADCAST;
3590 else if ((!memcmp(byte_seq, ipv4_mc_mac, 2) &&
3591 byte_seq[MWIFIEX_COALESCE_MAX_BYTESEQ] == 2) ||
3592 (!memcmp(byte_seq, ipv6_mc_mac, 3) &&
3593 byte_seq[MWIFIEX_COALESCE_MAX_BYTESEQ] == 3))
3594 return PACKET_TYPE_MULTICAST;
3600 mwifiex_fill_coalesce_rule_info(struct mwifiex_private *priv,
3601 struct cfg80211_coalesce_rules *crule,
3602 struct mwifiex_coalesce_rule *mrule)
3604 u8 byte_seq[MWIFIEX_COALESCE_MAX_BYTESEQ + 1];
3605 struct filt_field_param *param;
3608 mrule->max_coalescing_delay = crule->delay;
3610 param = mrule->params;
3612 for (i = 0; i < crule->n_patterns; i++) {
3613 memset(byte_seq, 0, sizeof(byte_seq));
3614 if (!mwifiex_is_pattern_supported(&crule->patterns[i],
3616 MWIFIEX_COALESCE_MAX_BYTESEQ)) {
3617 mwifiex_dbg(priv->adapter, ERROR,
3618 "Pattern not supported\n");
3622 if (!crule->patterns[i].pkt_offset) {
3625 pkt_type = mwifiex_get_coalesce_pkt_type(byte_seq);
3626 if (pkt_type && mrule->pkt_type) {
3627 mwifiex_dbg(priv->adapter, ERROR,
3628 "Multiple packet types not allowed\n");
3630 } else if (pkt_type) {
3631 mrule->pkt_type = pkt_type;
3636 if (crule->condition == NL80211_COALESCE_CONDITION_MATCH)
3637 param->operation = RECV_FILTER_MATCH_TYPE_EQ;
3639 param->operation = RECV_FILTER_MATCH_TYPE_NE;
3641 param->operand_len = byte_seq[MWIFIEX_COALESCE_MAX_BYTESEQ];
3642 memcpy(param->operand_byte_stream, byte_seq,
3643 param->operand_len);
3644 param->offset = crule->patterns[i].pkt_offset;
3647 mrule->num_of_fields++;
3650 if (!mrule->pkt_type) {
3651 mwifiex_dbg(priv->adapter, ERROR,
3652 "Packet type can not be determined\n");
3659 static int mwifiex_cfg80211_set_coalesce(struct wiphy *wiphy,
3660 struct cfg80211_coalesce *coalesce)
3662 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
3664 struct mwifiex_ds_coalesce_cfg coalesce_cfg;
3665 struct mwifiex_private *priv =
3666 mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_STA);
3668 memset(&coalesce_cfg, 0, sizeof(coalesce_cfg));
3670 mwifiex_dbg(adapter, WARN,
3671 "Disable coalesce and reset all previous rules\n");
3672 return mwifiex_send_cmd(priv, HostCmd_CMD_COALESCE_CFG,
3673 HostCmd_ACT_GEN_SET, 0,
3674 &coalesce_cfg, true);
3677 coalesce_cfg.num_of_rules = coalesce->n_rules;
3678 for (i = 0; i < coalesce->n_rules; i++) {
3679 ret = mwifiex_fill_coalesce_rule_info(priv, &coalesce->rules[i],
3680 &coalesce_cfg.rule[i]);
3682 mwifiex_dbg(adapter, ERROR,
3683 "Recheck the patterns provided for rule %d\n",
3689 return mwifiex_send_cmd(priv, HostCmd_CMD_COALESCE_CFG,
3690 HostCmd_ACT_GEN_SET, 0, &coalesce_cfg, true);
3693 /* cfg80211 ops handler for tdls_mgmt.
3694 * Function prepares TDLS action frame packets and forwards them to FW
3697 mwifiex_cfg80211_tdls_mgmt(struct wiphy *wiphy, struct net_device *dev,
3698 const u8 *peer, u8 action_code, u8 dialog_token,
3699 u16 status_code, u32 peer_capability,
3700 bool initiator, const u8 *extra_ies,
3701 size_t extra_ies_len)
3703 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
3706 if (!(wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS))
3709 /* make sure we are in station mode and connected */
3710 if (!(priv->bss_type == MWIFIEX_BSS_TYPE_STA && priv->media_connected))
3713 switch (action_code) {
3714 case WLAN_TDLS_SETUP_REQUEST:
3715 mwifiex_dbg(priv->adapter, MSG,
3716 "Send TDLS Setup Request to %pM status_code=%d\n",
3718 mwifiex_add_auto_tdls_peer(priv, peer);
3719 ret = mwifiex_send_tdls_data_frame(priv, peer, action_code,
3720 dialog_token, status_code,
3721 extra_ies, extra_ies_len);
3723 case WLAN_TDLS_SETUP_RESPONSE:
3724 mwifiex_add_auto_tdls_peer(priv, peer);
3725 mwifiex_dbg(priv->adapter, MSG,
3726 "Send TDLS Setup Response to %pM status_code=%d\n",
3728 ret = mwifiex_send_tdls_data_frame(priv, peer, action_code,
3729 dialog_token, status_code,
3730 extra_ies, extra_ies_len);
3732 case WLAN_TDLS_SETUP_CONFIRM:
3733 mwifiex_dbg(priv->adapter, MSG,
3734 "Send TDLS Confirm to %pM status_code=%d\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_TDLS_TEARDOWN:
3741 mwifiex_dbg(priv->adapter, MSG,
3742 "Send TDLS Tear down to %pM\n", peer);
3743 ret = mwifiex_send_tdls_data_frame(priv, peer, action_code,
3744 dialog_token, status_code,
3745 extra_ies, extra_ies_len);
3747 case WLAN_TDLS_DISCOVERY_REQUEST:
3748 mwifiex_dbg(priv->adapter, MSG,
3749 "Send TDLS Discovery Request to %pM\n", peer);
3750 ret = mwifiex_send_tdls_data_frame(priv, peer, action_code,
3751 dialog_token, status_code,
3752 extra_ies, extra_ies_len);
3754 case WLAN_PUB_ACTION_TDLS_DISCOVER_RES:
3755 mwifiex_dbg(priv->adapter, MSG,
3756 "Send TDLS Discovery Response to %pM\n", peer);
3757 ret = mwifiex_send_tdls_action_frame(priv, peer, action_code,
3758 dialog_token, status_code,
3759 extra_ies, extra_ies_len);
3762 mwifiex_dbg(priv->adapter, ERROR,
3763 "Unknown TDLS mgmt/action frame %pM\n", peer);
3772 mwifiex_cfg80211_tdls_oper(struct wiphy *wiphy, struct net_device *dev,
3773 const u8 *peer, enum nl80211_tdls_operation action)
3775 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
3777 if (!(wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
3778 !(wiphy->flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP))
3781 /* make sure we are in station mode and connected */
3782 if (!(priv->bss_type == MWIFIEX_BSS_TYPE_STA && priv->media_connected))
3785 mwifiex_dbg(priv->adapter, MSG,
3786 "TDLS peer=%pM, oper=%d\n", peer, action);
3789 case NL80211_TDLS_ENABLE_LINK:
3790 action = MWIFIEX_TDLS_ENABLE_LINK;
3792 case NL80211_TDLS_DISABLE_LINK:
3793 action = MWIFIEX_TDLS_DISABLE_LINK;
3795 case NL80211_TDLS_TEARDOWN:
3796 /* shouldn't happen!*/
3797 mwifiex_dbg(priv->adapter, ERROR,
3798 "tdls_oper: teardown from driver not supported\n");
3800 case NL80211_TDLS_SETUP:
3801 /* shouldn't happen!*/
3802 mwifiex_dbg(priv->adapter, ERROR,
3803 "tdls_oper: setup from driver not supported\n");
3805 case NL80211_TDLS_DISCOVERY_REQ:
3806 /* shouldn't happen!*/
3807 mwifiex_dbg(priv->adapter, ERROR,
3808 "tdls_oper: discovery from driver not supported\n");
3811 mwifiex_dbg(priv->adapter, ERROR,
3812 "tdls_oper: operation not supported\n");
3816 return mwifiex_tdls_oper(priv, peer, action);
3820 mwifiex_cfg80211_tdls_chan_switch(struct wiphy *wiphy, struct net_device *dev,
3821 const u8 *addr, u8 oper_class,
3822 struct cfg80211_chan_def *chandef)
3824 struct mwifiex_sta_node *sta_ptr;
3825 unsigned long flags;
3827 u8 second_chan_offset, band;
3828 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
3830 spin_lock_irqsave(&priv->sta_list_spinlock, flags);
3831 sta_ptr = mwifiex_get_sta_entry(priv, addr);
3833 spin_unlock_irqrestore(&priv->sta_list_spinlock, flags);
3834 wiphy_err(wiphy, "%s: Invalid TDLS peer %pM\n",
3839 if (!(sta_ptr->tdls_cap.extcap.ext_capab[3] &
3840 WLAN_EXT_CAPA4_TDLS_CHAN_SWITCH)) {
3841 spin_unlock_irqrestore(&priv->sta_list_spinlock, flags);
3842 wiphy_err(wiphy, "%pM do not support tdls cs\n", addr);
3846 if (sta_ptr->tdls_status == TDLS_CHAN_SWITCHING ||
3847 sta_ptr->tdls_status == TDLS_IN_OFF_CHAN) {
3848 spin_unlock_irqrestore(&priv->sta_list_spinlock, flags);
3849 wiphy_err(wiphy, "channel switch is running, abort request\n");
3852 spin_unlock_irqrestore(&priv->sta_list_spinlock, flags);
3854 chan = chandef->chan->hw_value;
3855 second_chan_offset = mwifiex_get_sec_chan_offset(chan);
3856 band = chandef->chan->band;
3857 mwifiex_start_tdls_cs(priv, addr, chan, second_chan_offset, band);
3863 mwifiex_cfg80211_tdls_cancel_chan_switch(struct wiphy *wiphy,
3864 struct net_device *dev,
3867 struct mwifiex_sta_node *sta_ptr;
3868 unsigned long flags;
3869 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
3871 spin_lock_irqsave(&priv->sta_list_spinlock, flags);
3872 sta_ptr = mwifiex_get_sta_entry(priv, addr);
3874 spin_unlock_irqrestore(&priv->sta_list_spinlock, flags);
3875 wiphy_err(wiphy, "%s: Invalid TDLS peer %pM\n",
3877 } else if (!(sta_ptr->tdls_status == TDLS_CHAN_SWITCHING ||
3878 sta_ptr->tdls_status == TDLS_IN_BASE_CHAN ||
3879 sta_ptr->tdls_status == TDLS_IN_OFF_CHAN)) {
3880 spin_unlock_irqrestore(&priv->sta_list_spinlock, flags);
3881 wiphy_err(wiphy, "tdls chan switch not initialize by %pM\n",
3884 spin_unlock_irqrestore(&priv->sta_list_spinlock, flags);
3885 mwifiex_stop_tdls_cs(priv, addr);
3890 mwifiex_cfg80211_add_station(struct wiphy *wiphy, struct net_device *dev,
3891 const u8 *mac, struct station_parameters *params)
3893 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
3895 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
3898 /* make sure we are in station mode and connected */
3899 if ((priv->bss_type != MWIFIEX_BSS_TYPE_STA) || !priv->media_connected)
3902 return mwifiex_tdls_oper(priv, mac, MWIFIEX_TDLS_CREATE_LINK);
3906 mwifiex_cfg80211_channel_switch(struct wiphy *wiphy, struct net_device *dev,
3907 struct cfg80211_csa_settings *params)
3909 struct ieee_types_header *chsw_ie;
3910 struct ieee80211_channel_sw_ie *channel_sw;
3912 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
3914 if (priv->adapter->scan_processing) {
3915 mwifiex_dbg(priv->adapter, ERROR,
3916 "radar detection: scan in process...\n");
3920 if (priv->wdev.cac_started)
3923 if (cfg80211_chandef_identical(¶ms->chandef,
3924 &priv->dfs_chandef))
3927 chsw_ie = (void *)cfg80211_find_ie(WLAN_EID_CHANNEL_SWITCH,
3928 params->beacon_csa.tail,
3929 params->beacon_csa.tail_len);
3931 mwifiex_dbg(priv->adapter, ERROR,
3932 "Could not parse channel switch announcement IE\n");
3936 channel_sw = (void *)(chsw_ie + 1);
3937 if (channel_sw->mode) {
3938 if (netif_carrier_ok(priv->netdev))
3939 netif_carrier_off(priv->netdev);
3940 mwifiex_stop_net_dev_queue(priv->netdev, priv->adapter);
3943 if (mwifiex_del_mgmt_ies(priv))
3944 mwifiex_dbg(priv->adapter, ERROR,
3945 "Failed to delete mgmt IEs!\n");
3947 if (mwifiex_set_mgmt_ies(priv, ¶ms->beacon_csa)) {
3948 mwifiex_dbg(priv->adapter, ERROR,
3949 "%s: setting mgmt ies failed\n", __func__);
3953 memcpy(&priv->dfs_chandef, ¶ms->chandef, sizeof(priv->dfs_chandef));
3954 memcpy(&priv->beacon_after, ¶ms->beacon_after,
3955 sizeof(priv->beacon_after));
3957 chsw_msec = max(channel_sw->count * priv->bss_cfg.beacon_period, 100);
3958 queue_delayed_work(priv->dfs_chan_sw_workqueue, &priv->dfs_chan_sw_work,
3959 msecs_to_jiffies(chsw_msec));
3963 static int mwifiex_cfg80211_get_channel(struct wiphy *wiphy,
3964 struct wireless_dev *wdev,
3965 struct cfg80211_chan_def *chandef)
3967 struct mwifiex_private *priv = mwifiex_netdev_get_priv(wdev->netdev);
3968 struct mwifiex_bssdescriptor *curr_bss;
3969 struct ieee80211_channel *chan;
3970 enum nl80211_channel_type chan_type;
3971 enum nl80211_band band;
3975 if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_UAP &&
3976 cfg80211_chandef_valid(&priv->bss_chandef)) {
3977 *chandef = priv->bss_chandef;
3979 } else if (priv->media_connected) {
3980 curr_bss = &priv->curr_bss_params.bss_descriptor;
3981 band = mwifiex_band_to_radio_type(priv->curr_bss_params.band);
3982 freq = ieee80211_channel_to_frequency(curr_bss->channel, band);
3983 chan = ieee80211_get_channel(wiphy, freq);
3985 if (priv->ht_param_present) {
3986 chan_type = mwifiex_get_chan_type(priv);
3987 cfg80211_chandef_create(chandef, chan, chan_type);
3989 cfg80211_chandef_create(chandef, chan,
3990 NL80211_CHAN_NO_HT);
3998 #ifdef CONFIG_NL80211_TESTMODE
4000 enum mwifiex_tm_attr {
4001 __MWIFIEX_TM_ATTR_INVALID = 0,
4002 MWIFIEX_TM_ATTR_CMD = 1,
4003 MWIFIEX_TM_ATTR_DATA = 2,
4006 __MWIFIEX_TM_ATTR_AFTER_LAST,
4007 MWIFIEX_TM_ATTR_MAX = __MWIFIEX_TM_ATTR_AFTER_LAST - 1,
4010 static const struct nla_policy mwifiex_tm_policy[MWIFIEX_TM_ATTR_MAX + 1] = {
4011 [MWIFIEX_TM_ATTR_CMD] = { .type = NLA_U32 },
4012 [MWIFIEX_TM_ATTR_DATA] = { .type = NLA_BINARY,
4013 .len = MWIFIEX_SIZE_OF_CMD_BUFFER },
4016 enum mwifiex_tm_command {
4017 MWIFIEX_TM_CMD_HOSTCMD = 0,
4020 static int mwifiex_tm_cmd(struct wiphy *wiphy, struct wireless_dev *wdev,
4021 void *data, int len)
4023 struct mwifiex_private *priv = mwifiex_netdev_get_priv(wdev->netdev);
4024 struct mwifiex_ds_misc_cmd *hostcmd;
4025 struct nlattr *tb[MWIFIEX_TM_ATTR_MAX + 1];
4026 struct sk_buff *skb;
4032 err = nla_parse(tb, MWIFIEX_TM_ATTR_MAX, data, len, mwifiex_tm_policy,
4037 if (!tb[MWIFIEX_TM_ATTR_CMD])
4040 switch (nla_get_u32(tb[MWIFIEX_TM_ATTR_CMD])) {
4041 case MWIFIEX_TM_CMD_HOSTCMD:
4042 if (!tb[MWIFIEX_TM_ATTR_DATA])
4045 hostcmd = kzalloc(sizeof(*hostcmd), GFP_KERNEL);
4049 hostcmd->len = nla_len(tb[MWIFIEX_TM_ATTR_DATA]);
4050 memcpy(hostcmd->cmd, nla_data(tb[MWIFIEX_TM_ATTR_DATA]),
4053 if (mwifiex_send_cmd(priv, 0, 0, 0, hostcmd, true)) {
4054 dev_err(priv->adapter->dev, "Failed to process hostcmd\n");
4059 /* process hostcmd response*/
4060 skb = cfg80211_testmode_alloc_reply_skb(wiphy, hostcmd->len);
4065 err = nla_put(skb, MWIFIEX_TM_ATTR_DATA,
4066 hostcmd->len, hostcmd->cmd);
4073 err = cfg80211_testmode_reply(skb);
4083 mwifiex_cfg80211_start_radar_detection(struct wiphy *wiphy,
4084 struct net_device *dev,
4085 struct cfg80211_chan_def *chandef,
4088 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
4089 struct mwifiex_radar_params radar_params;
4091 if (priv->adapter->scan_processing) {
4092 mwifiex_dbg(priv->adapter, ERROR,
4093 "radar detection: scan already in process...\n");
4097 if (!mwifiex_is_11h_active(priv)) {
4098 mwifiex_dbg(priv->adapter, INFO,
4099 "Enable 11h extensions in FW\n");
4100 if (mwifiex_11h_activate(priv, true)) {
4101 mwifiex_dbg(priv->adapter, ERROR,
4102 "Failed to activate 11h extensions!!");
4105 priv->state_11h.is_11h_active = true;
4108 memset(&radar_params, 0, sizeof(struct mwifiex_radar_params));
4109 radar_params.chandef = chandef;
4110 radar_params.cac_time_ms = cac_time_ms;
4112 memcpy(&priv->dfs_chandef, chandef, sizeof(priv->dfs_chandef));
4114 if (mwifiex_send_cmd(priv, HostCmd_CMD_CHAN_REPORT_REQUEST,
4115 HostCmd_ACT_GEN_SET, 0, &radar_params, true))
4118 queue_delayed_work(priv->dfs_cac_workqueue, &priv->dfs_cac_work,
4119 msecs_to_jiffies(cac_time_ms));
4124 mwifiex_cfg80211_change_station(struct wiphy *wiphy, struct net_device *dev,
4126 struct station_parameters *params)
4129 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
4131 /* we support change_station handler only for TDLS peers*/
4132 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
4135 /* make sure we are in station mode and connected */
4136 if ((priv->bss_type != MWIFIEX_BSS_TYPE_STA) || !priv->media_connected)
4139 priv->sta_params = params;
4141 ret = mwifiex_tdls_oper(priv, mac, MWIFIEX_TDLS_CONFIG_LINK);
4142 priv->sta_params = NULL;
4147 /* station cfg80211 operations */
4148 static struct cfg80211_ops mwifiex_cfg80211_ops = {
4149 .add_virtual_intf = mwifiex_add_virtual_intf,
4150 .del_virtual_intf = mwifiex_del_virtual_intf,
4151 .change_virtual_intf = mwifiex_cfg80211_change_virtual_intf,
4152 .scan = mwifiex_cfg80211_scan,
4153 .connect = mwifiex_cfg80211_connect,
4154 .disconnect = mwifiex_cfg80211_disconnect,
4155 .get_station = mwifiex_cfg80211_get_station,
4156 .dump_station = mwifiex_cfg80211_dump_station,
4157 .dump_survey = mwifiex_cfg80211_dump_survey,
4158 .set_wiphy_params = mwifiex_cfg80211_set_wiphy_params,
4159 .join_ibss = mwifiex_cfg80211_join_ibss,
4160 .leave_ibss = mwifiex_cfg80211_leave_ibss,
4161 .add_key = mwifiex_cfg80211_add_key,
4162 .del_key = mwifiex_cfg80211_del_key,
4163 .set_default_mgmt_key = mwifiex_cfg80211_set_default_mgmt_key,
4164 .mgmt_tx = mwifiex_cfg80211_mgmt_tx,
4165 .mgmt_frame_register = mwifiex_cfg80211_mgmt_frame_register,
4166 .remain_on_channel = mwifiex_cfg80211_remain_on_channel,
4167 .cancel_remain_on_channel = mwifiex_cfg80211_cancel_remain_on_channel,
4168 .set_default_key = mwifiex_cfg80211_set_default_key,
4169 .set_power_mgmt = mwifiex_cfg80211_set_power_mgmt,
4170 .set_tx_power = mwifiex_cfg80211_set_tx_power,
4171 .get_tx_power = mwifiex_cfg80211_get_tx_power,
4172 .set_bitrate_mask = mwifiex_cfg80211_set_bitrate_mask,
4173 .start_ap = mwifiex_cfg80211_start_ap,
4174 .stop_ap = mwifiex_cfg80211_stop_ap,
4175 .change_beacon = mwifiex_cfg80211_change_beacon,
4176 .set_cqm_rssi_config = mwifiex_cfg80211_set_cqm_rssi_config,
4177 .set_antenna = mwifiex_cfg80211_set_antenna,
4178 .get_antenna = mwifiex_cfg80211_get_antenna,
4179 .del_station = mwifiex_cfg80211_del_station,
4180 .sched_scan_start = mwifiex_cfg80211_sched_scan_start,
4181 .sched_scan_stop = mwifiex_cfg80211_sched_scan_stop,
4183 .suspend = mwifiex_cfg80211_suspend,
4184 .resume = mwifiex_cfg80211_resume,
4185 .set_wakeup = mwifiex_cfg80211_set_wakeup,
4186 .set_rekey_data = mwifiex_set_rekey_data,
4188 .set_coalesce = mwifiex_cfg80211_set_coalesce,
4189 .tdls_mgmt = mwifiex_cfg80211_tdls_mgmt,
4190 .tdls_oper = mwifiex_cfg80211_tdls_oper,
4191 .tdls_channel_switch = mwifiex_cfg80211_tdls_chan_switch,
4192 .tdls_cancel_channel_switch = mwifiex_cfg80211_tdls_cancel_chan_switch,
4193 .add_station = mwifiex_cfg80211_add_station,
4194 .change_station = mwifiex_cfg80211_change_station,
4195 CFG80211_TESTMODE_CMD(mwifiex_tm_cmd)
4196 .get_channel = mwifiex_cfg80211_get_channel,
4197 .start_radar_detection = mwifiex_cfg80211_start_radar_detection,
4198 .channel_switch = mwifiex_cfg80211_channel_switch,
4202 static const struct wiphy_wowlan_support mwifiex_wowlan_support = {
4203 .flags = WIPHY_WOWLAN_MAGIC_PKT | WIPHY_WOWLAN_DISCONNECT |
4204 WIPHY_WOWLAN_NET_DETECT | WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
4205 WIPHY_WOWLAN_GTK_REKEY_FAILURE,
4206 .n_patterns = MWIFIEX_MEF_MAX_FILTERS,
4207 .pattern_min_len = 1,
4208 .pattern_max_len = MWIFIEX_MAX_PATTERN_LEN,
4209 .max_pkt_offset = MWIFIEX_MAX_OFFSET_LEN,
4210 .max_nd_match_sets = MWIFIEX_MAX_ND_MATCH_SETS,
4213 static const struct wiphy_wowlan_support mwifiex_wowlan_support_no_gtk = {
4214 .flags = WIPHY_WOWLAN_MAGIC_PKT | WIPHY_WOWLAN_DISCONNECT |
4215 WIPHY_WOWLAN_NET_DETECT,
4216 .n_patterns = MWIFIEX_MEF_MAX_FILTERS,
4217 .pattern_min_len = 1,
4218 .pattern_max_len = MWIFIEX_MAX_PATTERN_LEN,
4219 .max_pkt_offset = MWIFIEX_MAX_OFFSET_LEN,
4220 .max_nd_match_sets = MWIFIEX_MAX_ND_MATCH_SETS,
4224 static bool mwifiex_is_valid_alpha2(const char *alpha2)
4226 if (!alpha2 || strlen(alpha2) != 2)
4229 if (isalpha(alpha2[0]) && isalpha(alpha2[1]))
4235 static const struct wiphy_coalesce_support mwifiex_coalesce_support = {
4236 .n_rules = MWIFIEX_COALESCE_MAX_RULES,
4237 .max_delay = MWIFIEX_MAX_COALESCING_DELAY,
4238 .n_patterns = MWIFIEX_COALESCE_MAX_FILTERS,
4239 .pattern_min_len = 1,
4240 .pattern_max_len = MWIFIEX_MAX_PATTERN_LEN,
4241 .max_pkt_offset = MWIFIEX_MAX_OFFSET_LEN,
4244 int mwifiex_init_channel_scan_gap(struct mwifiex_adapter *adapter)
4246 u32 n_channels_bg, n_channels_a = 0;
4248 n_channels_bg = mwifiex_band_2ghz.n_channels;
4250 if (adapter->config_bands & BAND_A)
4251 n_channels_a = mwifiex_band_5ghz.n_channels;
4253 /* allocate twice the number total channels, since the driver issues an
4254 * additional active scan request for hidden SSIDs on passive channels.
4256 adapter->num_in_chan_stats = 2 * (n_channels_bg + n_channels_a);
4257 adapter->chan_stats = vmalloc(array_size(sizeof(*adapter->chan_stats),
4258 adapter->num_in_chan_stats));
4260 if (!adapter->chan_stats)
4267 * This function registers the device with CFG802.11 subsystem.
4269 * The function creates the wireless device/wiphy, populates it with
4270 * default parameters and handler function pointers, and finally
4271 * registers the device.
4274 int mwifiex_register_cfg80211(struct mwifiex_adapter *adapter)
4278 struct wiphy *wiphy;
4279 struct mwifiex_private *priv = adapter->priv[MWIFIEX_BSS_TYPE_STA];
4283 /* create a new wiphy for use with cfg80211 */
4284 wiphy = wiphy_new(&mwifiex_cfg80211_ops,
4285 sizeof(struct mwifiex_adapter *));
4287 mwifiex_dbg(adapter, ERROR,
4288 "%s: creating new wiphy\n", __func__);
4291 wiphy->max_scan_ssids = MWIFIEX_MAX_SSID_LIST_LENGTH;
4292 wiphy->max_scan_ie_len = MWIFIEX_MAX_VSIE_LEN;
4293 wiphy->mgmt_stypes = mwifiex_mgmt_stypes;
4294 wiphy->max_remain_on_channel_duration = 5000;
4295 wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
4296 BIT(NL80211_IFTYPE_P2P_CLIENT) |
4297 BIT(NL80211_IFTYPE_P2P_GO) |
4298 BIT(NL80211_IFTYPE_AP);
4300 if (ISSUPP_ADHOC_ENABLED(adapter->fw_cap_info))
4301 wiphy->interface_modes |= BIT(NL80211_IFTYPE_ADHOC);
4303 wiphy->bands[NL80211_BAND_2GHZ] = &mwifiex_band_2ghz;
4304 if (adapter->config_bands & BAND_A)
4305 wiphy->bands[NL80211_BAND_5GHZ] = &mwifiex_band_5ghz;
4307 wiphy->bands[NL80211_BAND_5GHZ] = NULL;
4309 if (adapter->drcs_enabled && ISSUPP_DRCS_ENABLED(adapter->fw_cap_info))
4310 wiphy->iface_combinations = &mwifiex_iface_comb_ap_sta_drcs;
4311 else if (adapter->is_hw_11ac_capable)
4312 wiphy->iface_combinations = &mwifiex_iface_comb_ap_sta_vht;
4314 wiphy->iface_combinations = &mwifiex_iface_comb_ap_sta;
4315 wiphy->n_iface_combinations = 1;
4317 /* Initialize cipher suits */
4318 wiphy->cipher_suites = mwifiex_cipher_suites;
4319 wiphy->n_cipher_suites = ARRAY_SIZE(mwifiex_cipher_suites);
4321 if (adapter->regd) {
4322 wiphy->regulatory_flags |= REGULATORY_CUSTOM_REG |
4323 REGULATORY_DISABLE_BEACON_HINTS |
4324 REGULATORY_COUNTRY_IE_IGNORE;
4325 wiphy_apply_custom_regulatory(wiphy, adapter->regd);
4328 ether_addr_copy(wiphy->perm_addr, adapter->perm_addr);
4329 wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
4330 wiphy->flags |= WIPHY_FLAG_HAVE_AP_SME |
4331 WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD |
4332 WIPHY_FLAG_AP_UAPSD |
4333 WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL |
4334 WIPHY_FLAG_HAS_CHANNEL_SWITCH |
4335 WIPHY_FLAG_PS_ON_BY_DEFAULT;
4337 if (ISSUPP_TDLS_ENABLED(adapter->fw_cap_info))
4338 wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS |
4339 WIPHY_FLAG_TDLS_EXTERNAL_SETUP;
4342 if (ISSUPP_FIRMWARE_SUPPLICANT(priv->adapter->fw_cap_info))
4343 wiphy->wowlan = &mwifiex_wowlan_support;
4345 wiphy->wowlan = &mwifiex_wowlan_support_no_gtk;
4348 wiphy->coalesce = &mwifiex_coalesce_support;
4350 wiphy->probe_resp_offload = NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS |
4351 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2 |
4352 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P;
4354 wiphy->max_sched_scan_reqs = 1;
4355 wiphy->max_sched_scan_ssids = MWIFIEX_MAX_SSID_LIST_LENGTH;
4356 wiphy->max_sched_scan_ie_len = MWIFIEX_MAX_VSIE_LEN;
4357 wiphy->max_match_sets = MWIFIEX_MAX_SSID_LIST_LENGTH;
4359 wiphy->available_antennas_tx = BIT(adapter->number_of_antenna) - 1;
4360 wiphy->available_antennas_rx = BIT(adapter->number_of_antenna) - 1;
4362 wiphy->features |= NL80211_FEATURE_INACTIVITY_TIMER |
4363 NL80211_FEATURE_LOW_PRIORITY_SCAN |
4364 NL80211_FEATURE_NEED_OBSS_SCAN;
4366 if (ISSUPP_ADHOC_ENABLED(adapter->fw_cap_info))
4367 wiphy->features |= NL80211_FEATURE_HT_IBSS;
4369 if (ISSUPP_RANDOM_MAC(adapter->fw_cap_info))
4370 wiphy->features |= NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR |
4371 NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR |
4372 NL80211_FEATURE_ND_RANDOM_MAC_ADDR;
4374 if (ISSUPP_TDLS_ENABLED(adapter->fw_cap_info))
4375 wiphy->features |= NL80211_FEATURE_TDLS_CHANNEL_SWITCH;
4377 if (adapter->fw_api_ver == MWIFIEX_FW_V15)
4378 wiphy->features |= NL80211_FEATURE_SK_TX_STATUS;
4380 /* Reserve space for mwifiex specific private data for BSS */
4381 wiphy->bss_priv_size = sizeof(struct mwifiex_bss_priv);
4383 wiphy->reg_notifier = mwifiex_reg_notifier;
4385 /* Set struct mwifiex_adapter pointer in wiphy_priv */
4386 wdev_priv = wiphy_priv(wiphy);
4387 *(unsigned long *)wdev_priv = (unsigned long)adapter;
4389 set_wiphy_dev(wiphy, priv->adapter->dev);
4391 ret = wiphy_register(wiphy);
4393 mwifiex_dbg(adapter, ERROR,
4394 "%s: wiphy_register failed: %d\n", __func__, ret);
4399 if (!adapter->regd) {
4400 if (reg_alpha2 && mwifiex_is_valid_alpha2(reg_alpha2)) {
4401 mwifiex_dbg(adapter, INFO,
4402 "driver hint alpha2: %2.2s\n", reg_alpha2);
4403 regulatory_hint(wiphy, reg_alpha2);
4405 if (adapter->region_code == 0x00) {
4406 mwifiex_dbg(adapter, WARN,
4407 "Ignore world regulatory domain\n");
4409 wiphy->regulatory_flags |=
4410 REGULATORY_DISABLE_BEACON_HINTS |
4411 REGULATORY_COUNTRY_IE_IGNORE;
4413 mwifiex_11d_code_2_region(
4414 adapter->region_code);
4416 regulatory_hint(wiphy, country_code))
4417 mwifiex_dbg(priv->adapter, ERROR,
4418 "regulatory_hint() failed\n");
4423 mwifiex_send_cmd(priv, HostCmd_CMD_802_11_SNMP_MIB,
4424 HostCmd_ACT_GEN_GET, FRAG_THRESH_I, &thr, true);
4425 wiphy->frag_threshold = thr;
4426 mwifiex_send_cmd(priv, HostCmd_CMD_802_11_SNMP_MIB,
4427 HostCmd_ACT_GEN_GET, RTS_THRESH_I, &thr, true);
4428 wiphy->rts_threshold = thr;
4429 mwifiex_send_cmd(priv, HostCmd_CMD_802_11_SNMP_MIB,
4430 HostCmd_ACT_GEN_GET, SHORT_RETRY_LIM_I, &retry, true);
4431 wiphy->retry_short = (u8) retry;
4432 mwifiex_send_cmd(priv, HostCmd_CMD_802_11_SNMP_MIB,
4433 HostCmd_ACT_GEN_GET, LONG_RETRY_LIM_I, &retry, true);
4434 wiphy->retry_long = (u8) retry;
4436 adapter->wiphy = wiphy;