2 * Marvell Wireless LAN device driver: CFG80211
4 * Copyright (C) 2011-2014, Marvell International Ltd.
6 * This software file (the "File") is distributed by Marvell International
7 * Ltd. under the terms of the GNU General Public License Version 2, June 1991
8 * (the "License"). You may use, redistribute and/or modify this File in
9 * accordance with the terms and conditions of the License, a copy of which
10 * is available by writing to the Free Software Foundation, Inc.,
11 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA or on the
12 * worldwide web at http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
14 * THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE
16 * ARE EXPRESSLY DISCLAIMED. The License provides additional details about
17 * this warranty disclaimer.
25 static char *reg_alpha2;
26 module_param(reg_alpha2, charp, 0);
28 static const struct ieee80211_iface_limit mwifiex_ap_sta_limits[] = {
30 .max = 3, .types = BIT(NL80211_IFTYPE_STATION) |
31 BIT(NL80211_IFTYPE_P2P_GO) |
32 BIT(NL80211_IFTYPE_P2P_CLIENT) |
33 BIT(NL80211_IFTYPE_AP),
37 static const struct ieee80211_iface_combination
38 mwifiex_iface_comb_ap_sta = {
39 .limits = mwifiex_ap_sta_limits,
40 .num_different_channels = 1,
41 .n_limits = ARRAY_SIZE(mwifiex_ap_sta_limits),
42 .max_interfaces = MWIFIEX_MAX_BSS_NUM,
43 .beacon_int_infra_match = true,
44 .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
45 BIT(NL80211_CHAN_WIDTH_20) |
46 BIT(NL80211_CHAN_WIDTH_40),
49 static const struct ieee80211_iface_combination
50 mwifiex_iface_comb_ap_sta_vht = {
51 .limits = mwifiex_ap_sta_limits,
52 .num_different_channels = 1,
53 .n_limits = ARRAY_SIZE(mwifiex_ap_sta_limits),
54 .max_interfaces = MWIFIEX_MAX_BSS_NUM,
55 .beacon_int_infra_match = true,
56 .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
57 BIT(NL80211_CHAN_WIDTH_20) |
58 BIT(NL80211_CHAN_WIDTH_40) |
59 BIT(NL80211_CHAN_WIDTH_80),
63 ieee80211_iface_combination mwifiex_iface_comb_ap_sta_drcs = {
64 .limits = mwifiex_ap_sta_limits,
65 .num_different_channels = 2,
66 .n_limits = ARRAY_SIZE(mwifiex_ap_sta_limits),
67 .max_interfaces = MWIFIEX_MAX_BSS_NUM,
68 .beacon_int_infra_match = true,
72 * This function maps the nl802.11 channel type into driver channel type.
74 * The mapping is as follows -
75 * NL80211_CHAN_NO_HT -> IEEE80211_HT_PARAM_CHA_SEC_NONE
76 * NL80211_CHAN_HT20 -> IEEE80211_HT_PARAM_CHA_SEC_NONE
77 * NL80211_CHAN_HT40PLUS -> IEEE80211_HT_PARAM_CHA_SEC_ABOVE
78 * NL80211_CHAN_HT40MINUS -> IEEE80211_HT_PARAM_CHA_SEC_BELOW
79 * Others -> IEEE80211_HT_PARAM_CHA_SEC_NONE
81 u8 mwifiex_chan_type_to_sec_chan_offset(enum nl80211_channel_type chan_type)
84 case NL80211_CHAN_NO_HT:
85 case NL80211_CHAN_HT20:
86 return IEEE80211_HT_PARAM_CHA_SEC_NONE;
87 case NL80211_CHAN_HT40PLUS:
88 return IEEE80211_HT_PARAM_CHA_SEC_ABOVE;
89 case NL80211_CHAN_HT40MINUS:
90 return IEEE80211_HT_PARAM_CHA_SEC_BELOW;
92 return IEEE80211_HT_PARAM_CHA_SEC_NONE;
96 /* This function maps IEEE HT secondary channel type to NL80211 channel type
98 u8 mwifiex_sec_chan_offset_to_chan_type(u8 second_chan_offset)
100 switch (second_chan_offset) {
101 case IEEE80211_HT_PARAM_CHA_SEC_NONE:
102 return NL80211_CHAN_HT20;
103 case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
104 return NL80211_CHAN_HT40PLUS;
105 case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
106 return NL80211_CHAN_HT40MINUS;
108 return NL80211_CHAN_HT20;
113 * This function checks whether WEP is set.
116 mwifiex_is_alg_wep(u32 cipher)
119 case WLAN_CIPHER_SUITE_WEP40:
120 case WLAN_CIPHER_SUITE_WEP104:
130 * This function retrieves the private structure from kernel wiphy structure.
132 static void *mwifiex_cfg80211_get_adapter(struct wiphy *wiphy)
134 return (void *) (*(unsigned long *) wiphy_priv(wiphy));
138 * CFG802.11 operation handler to delete a network key.
141 mwifiex_cfg80211_del_key(struct wiphy *wiphy, struct net_device *netdev,
142 u8 key_index, bool pairwise, const u8 *mac_addr)
144 struct mwifiex_private *priv = mwifiex_netdev_get_priv(netdev);
145 const u8 bc_mac[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
146 const u8 *peer_mac = pairwise ? mac_addr : bc_mac;
148 if (mwifiex_set_encode(priv, NULL, NULL, 0, key_index, peer_mac, 1)) {
149 mwifiex_dbg(priv->adapter, ERROR, "deleting the crypto keys\n");
153 mwifiex_dbg(priv->adapter, INFO, "info: crypto keys deleted\n");
158 * This function forms an skb for management frame.
161 mwifiex_form_mgmt_frame(struct sk_buff *skb, const u8 *buf, size_t len)
163 u8 addr[ETH_ALEN] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
165 u32 tx_control = 0, pkt_type = PKT_TYPE_MGMT;
167 pkt_len = len + ETH_ALEN;
169 skb_reserve(skb, MWIFIEX_MIN_DATA_HEADER_LEN +
170 MWIFIEX_MGMT_FRAME_HEADER_SIZE + sizeof(pkt_len));
171 memcpy(skb_push(skb, sizeof(pkt_len)), &pkt_len, sizeof(pkt_len));
173 memcpy(skb_push(skb, sizeof(tx_control)),
174 &tx_control, sizeof(tx_control));
176 memcpy(skb_push(skb, sizeof(pkt_type)), &pkt_type, sizeof(pkt_type));
178 /* Add packet data and address4 */
179 memcpy(skb_put(skb, sizeof(struct ieee80211_hdr_3addr)), buf,
180 sizeof(struct ieee80211_hdr_3addr));
181 memcpy(skb_put(skb, ETH_ALEN), addr, ETH_ALEN);
182 memcpy(skb_put(skb, len - sizeof(struct ieee80211_hdr_3addr)),
183 buf + sizeof(struct ieee80211_hdr_3addr),
184 len - sizeof(struct ieee80211_hdr_3addr));
186 skb->priority = LOW_PRIO_TID;
187 __net_timestamp(skb);
193 * CFG802.11 operation handler to transmit a management frame.
196 mwifiex_cfg80211_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev,
197 struct cfg80211_mgmt_tx_params *params, u64 *cookie)
199 const u8 *buf = params->buf;
200 size_t len = params->len;
203 const struct ieee80211_mgmt *mgmt;
204 struct mwifiex_txinfo *tx_info;
205 struct mwifiex_private *priv = mwifiex_netdev_get_priv(wdev->netdev);
208 mwifiex_dbg(priv->adapter, ERROR, "invalid buffer and length\n");
212 mgmt = (const struct ieee80211_mgmt *)buf;
213 if (GET_BSS_ROLE(priv) != MWIFIEX_BSS_ROLE_STA &&
214 ieee80211_is_probe_resp(mgmt->frame_control)) {
215 /* Since we support offload probe resp, we need to skip probe
216 * resp in AP or GO mode */
217 mwifiex_dbg(priv->adapter, INFO,
218 "info: skip to send probe resp in AP or GO mode\n");
222 pkt_len = len + ETH_ALEN;
223 skb = dev_alloc_skb(MWIFIEX_MIN_DATA_HEADER_LEN +
224 MWIFIEX_MGMT_FRAME_HEADER_SIZE +
225 pkt_len + sizeof(pkt_len));
228 mwifiex_dbg(priv->adapter, ERROR,
229 "allocate skb failed for management frame\n");
233 tx_info = MWIFIEX_SKB_TXCB(skb);
234 memset(tx_info, 0, sizeof(*tx_info));
235 tx_info->bss_num = priv->bss_num;
236 tx_info->bss_type = priv->bss_type;
237 tx_info->pkt_len = pkt_len;
239 mwifiex_form_mgmt_frame(skb, buf, len);
240 *cookie = prandom_u32() | 1;
242 if (ieee80211_is_action(mgmt->frame_control))
243 skb = mwifiex_clone_skb_for_tx_status(priv,
245 MWIFIEX_BUF_FLAG_ACTION_TX_STATUS, cookie);
247 cfg80211_mgmt_tx_status(wdev, *cookie, buf, len, true,
250 mwifiex_queue_tx_pkt(priv, skb);
252 mwifiex_dbg(priv->adapter, INFO, "info: management frame transmitted\n");
257 * CFG802.11 operation handler to register a mgmt frame.
260 mwifiex_cfg80211_mgmt_frame_register(struct wiphy *wiphy,
261 struct wireless_dev *wdev,
262 u16 frame_type, bool reg)
264 struct mwifiex_private *priv = mwifiex_netdev_get_priv(wdev->netdev);
268 mask = priv->mgmt_frame_mask | BIT(frame_type >> 4);
270 mask = priv->mgmt_frame_mask & ~BIT(frame_type >> 4);
272 if (mask != priv->mgmt_frame_mask) {
273 priv->mgmt_frame_mask = mask;
274 mwifiex_send_cmd(priv, HostCmd_CMD_MGMT_FRAME_REG,
275 HostCmd_ACT_GEN_SET, 0,
276 &priv->mgmt_frame_mask, false);
277 mwifiex_dbg(priv->adapter, INFO, "info: mgmt frame registered\n");
282 * CFG802.11 operation handler to remain on channel.
285 mwifiex_cfg80211_remain_on_channel(struct wiphy *wiphy,
286 struct wireless_dev *wdev,
287 struct ieee80211_channel *chan,
288 unsigned int duration, u64 *cookie)
290 struct mwifiex_private *priv = mwifiex_netdev_get_priv(wdev->netdev);
293 if (!chan || !cookie) {
294 mwifiex_dbg(priv->adapter, ERROR, "Invalid parameter for ROC\n");
298 if (priv->roc_cfg.cookie) {
299 mwifiex_dbg(priv->adapter, INFO,
300 "info: ongoing ROC, cookie = 0x%llx\n",
301 priv->roc_cfg.cookie);
305 ret = mwifiex_remain_on_chan_cfg(priv, HostCmd_ACT_GEN_SET, chan,
309 *cookie = prandom_u32() | 1;
310 priv->roc_cfg.cookie = *cookie;
311 priv->roc_cfg.chan = *chan;
313 cfg80211_ready_on_channel(wdev, *cookie, chan,
314 duration, GFP_ATOMIC);
316 mwifiex_dbg(priv->adapter, INFO,
317 "info: ROC, cookie = 0x%llx\n", *cookie);
324 * CFG802.11 operation handler to cancel remain on channel.
327 mwifiex_cfg80211_cancel_remain_on_channel(struct wiphy *wiphy,
328 struct wireless_dev *wdev, u64 cookie)
330 struct mwifiex_private *priv = mwifiex_netdev_get_priv(wdev->netdev);
333 if (cookie != priv->roc_cfg.cookie)
336 ret = mwifiex_remain_on_chan_cfg(priv, HostCmd_ACT_GEN_REMOVE,
337 &priv->roc_cfg.chan, 0);
340 cfg80211_remain_on_channel_expired(wdev, cookie,
344 memset(&priv->roc_cfg, 0, sizeof(struct mwifiex_roc_cfg));
346 mwifiex_dbg(priv->adapter, INFO,
347 "info: cancel ROC, cookie = 0x%llx\n", cookie);
354 * CFG802.11 operation handler to set Tx power.
357 mwifiex_cfg80211_set_tx_power(struct wiphy *wiphy,
358 struct wireless_dev *wdev,
359 enum nl80211_tx_power_setting type,
362 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
363 struct mwifiex_private *priv;
364 struct mwifiex_power_cfg power_cfg;
365 int dbm = MBM_TO_DBM(mbm);
368 case NL80211_TX_POWER_FIXED:
369 power_cfg.is_power_auto = 0;
370 power_cfg.is_power_fixed = 1;
371 power_cfg.power_level = dbm;
373 case NL80211_TX_POWER_LIMITED:
374 power_cfg.is_power_auto = 0;
375 power_cfg.is_power_fixed = 0;
376 power_cfg.power_level = dbm;
378 case NL80211_TX_POWER_AUTOMATIC:
379 power_cfg.is_power_auto = 1;
383 priv = mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY);
385 return mwifiex_set_tx_power(priv, &power_cfg);
389 * CFG802.11 operation handler to get Tx power.
392 mwifiex_cfg80211_get_tx_power(struct wiphy *wiphy,
393 struct wireless_dev *wdev,
396 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
397 struct mwifiex_private *priv = mwifiex_get_priv(adapter,
398 MWIFIEX_BSS_ROLE_ANY);
399 int ret = mwifiex_send_cmd(priv, HostCmd_CMD_RF_TX_PWR,
400 HostCmd_ACT_GEN_GET, 0, NULL, true);
405 /* tx_power_level is set in HostCmd_CMD_RF_TX_PWR command handler */
406 *dbm = priv->tx_power_level;
412 * CFG802.11 operation handler to set Power Save option.
414 * The timeout value, if provided, is currently ignored.
417 mwifiex_cfg80211_set_power_mgmt(struct wiphy *wiphy,
418 struct net_device *dev,
419 bool enabled, int timeout)
421 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
425 mwifiex_dbg(priv->adapter, INFO,
426 "info: ignore timeout value for IEEE Power Save\n");
430 return mwifiex_drv_set_power(priv, &ps_mode);
434 * CFG802.11 operation handler to set the default network key.
437 mwifiex_cfg80211_set_default_key(struct wiphy *wiphy, struct net_device *netdev,
438 u8 key_index, bool unicast,
441 struct mwifiex_private *priv = mwifiex_netdev_get_priv(netdev);
443 /* Return if WEP key not configured */
444 if (!priv->sec_info.wep_enabled)
447 if (priv->bss_type == MWIFIEX_BSS_TYPE_UAP) {
448 priv->wep_key_curr_index = key_index;
449 } else if (mwifiex_set_encode(priv, NULL, NULL, 0, key_index,
451 mwifiex_dbg(priv->adapter, ERROR, "set default Tx key index\n");
459 * CFG802.11 operation handler to add a network key.
462 mwifiex_cfg80211_add_key(struct wiphy *wiphy, struct net_device *netdev,
463 u8 key_index, bool pairwise, const u8 *mac_addr,
464 struct key_params *params)
466 struct mwifiex_private *priv = mwifiex_netdev_get_priv(netdev);
467 struct mwifiex_wep_key *wep_key;
468 const u8 bc_mac[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
469 const u8 *peer_mac = pairwise ? mac_addr : bc_mac;
471 if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_UAP &&
472 (params->cipher == WLAN_CIPHER_SUITE_WEP40 ||
473 params->cipher == WLAN_CIPHER_SUITE_WEP104)) {
474 if (params->key && params->key_len) {
475 wep_key = &priv->wep_key[key_index];
476 memset(wep_key, 0, sizeof(struct mwifiex_wep_key));
477 memcpy(wep_key->key_material, params->key,
479 wep_key->key_index = key_index;
480 wep_key->key_length = params->key_len;
481 priv->sec_info.wep_enabled = 1;
486 if (mwifiex_set_encode(priv, params, params->key, params->key_len,
487 key_index, peer_mac, 0)) {
488 mwifiex_dbg(priv->adapter, ERROR, "crypto keys added\n");
496 * CFG802.11 operation handler to set default mgmt key.
499 mwifiex_cfg80211_set_default_mgmt_key(struct wiphy *wiphy,
500 struct net_device *netdev,
503 struct mwifiex_private *priv = mwifiex_netdev_get_priv(netdev);
504 struct mwifiex_ds_encrypt_key encrypt_key;
506 wiphy_dbg(wiphy, "set default mgmt key, key index=%d\n", key_index);
508 memset(&encrypt_key, 0, sizeof(struct mwifiex_ds_encrypt_key));
509 encrypt_key.key_len = WLAN_KEY_LEN_CCMP;
510 encrypt_key.key_index = key_index;
511 encrypt_key.is_igtk_def_key = true;
512 eth_broadcast_addr(encrypt_key.mac_addr);
514 return mwifiex_send_cmd(priv, HostCmd_CMD_802_11_KEY_MATERIAL,
515 HostCmd_ACT_GEN_SET, true, &encrypt_key, true);
519 * This function sends domain information to the firmware.
521 * The following information are passed to the firmware -
523 * - Sub bands (first channel, number of channels, maximum Tx power)
525 int mwifiex_send_domain_info_cmd_fw(struct wiphy *wiphy)
527 u8 no_of_triplet = 0;
528 struct ieee80211_country_ie_triplet *t;
529 u8 no_of_parsed_chan = 0;
530 u8 first_chan = 0, next_chan = 0, max_pwr = 0;
532 enum nl80211_band band;
533 struct ieee80211_supported_band *sband;
534 struct ieee80211_channel *ch;
535 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
536 struct mwifiex_private *priv;
537 struct mwifiex_802_11d_domain_reg *domain_info = &adapter->domain_reg;
539 /* Set country code */
540 domain_info->country_code[0] = adapter->country_code[0];
541 domain_info->country_code[1] = adapter->country_code[1];
542 domain_info->country_code[2] = ' ';
544 band = mwifiex_band_to_radio_type(adapter->config_bands);
545 if (!wiphy->bands[band]) {
546 mwifiex_dbg(adapter, ERROR,
547 "11D: setting domain info in FW\n");
551 sband = wiphy->bands[band];
553 for (i = 0; i < sband->n_channels ; i++) {
554 ch = &sband->channels[i];
555 if (ch->flags & IEEE80211_CHAN_DISABLED)
560 first_chan = (u32) ch->hw_value;
561 next_chan = first_chan;
562 max_pwr = ch->max_power;
563 no_of_parsed_chan = 1;
567 if (ch->hw_value == next_chan + 1 &&
568 ch->max_power == max_pwr) {
572 t = &domain_info->triplet[no_of_triplet];
573 t->chans.first_channel = first_chan;
574 t->chans.num_channels = no_of_parsed_chan;
575 t->chans.max_power = max_pwr;
577 first_chan = (u32) ch->hw_value;
578 next_chan = first_chan;
579 max_pwr = ch->max_power;
580 no_of_parsed_chan = 1;
585 t = &domain_info->triplet[no_of_triplet];
586 t->chans.first_channel = first_chan;
587 t->chans.num_channels = no_of_parsed_chan;
588 t->chans.max_power = max_pwr;
592 domain_info->no_of_triplet = no_of_triplet;
594 priv = mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY);
596 if (mwifiex_send_cmd(priv, HostCmd_CMD_802_11D_DOMAIN_INFO,
597 HostCmd_ACT_GEN_SET, 0, NULL, false)) {
598 mwifiex_dbg(adapter, INFO,
599 "11D: setting domain info in FW\n");
607 * CFG802.11 regulatory domain callback function.
609 * This function is called when the regulatory domain is changed due to the
610 * following reasons -
612 * - Set by system core
614 * - Set bt Country IE
616 static void mwifiex_reg_notifier(struct wiphy *wiphy,
617 struct regulatory_request *request)
619 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
620 struct mwifiex_private *priv = mwifiex_get_priv(adapter,
621 MWIFIEX_BSS_ROLE_ANY);
622 mwifiex_dbg(adapter, INFO,
623 "info: cfg80211 regulatory domain callback for %c%c\n",
624 request->alpha2[0], request->alpha2[1]);
626 switch (request->initiator) {
627 case NL80211_REGDOM_SET_BY_DRIVER:
628 case NL80211_REGDOM_SET_BY_CORE:
629 case NL80211_REGDOM_SET_BY_USER:
630 case NL80211_REGDOM_SET_BY_COUNTRY_IE:
633 mwifiex_dbg(adapter, ERROR,
634 "unknown regdom initiator: %d\n",
639 /* Don't send world or same regdom info to firmware */
640 if (strncmp(request->alpha2, "00", 2) &&
641 strncmp(request->alpha2, adapter->country_code,
642 sizeof(request->alpha2))) {
643 memcpy(adapter->country_code, request->alpha2,
644 sizeof(request->alpha2));
645 mwifiex_send_domain_info_cmd_fw(wiphy);
646 mwifiex_dnld_txpwr_table(priv);
651 * This function sets the fragmentation threshold.
653 * The fragmentation threshold value must lie between MWIFIEX_FRAG_MIN_VALUE
654 * and MWIFIEX_FRAG_MAX_VALUE.
657 mwifiex_set_frag(struct mwifiex_private *priv, u32 frag_thr)
659 if (frag_thr < MWIFIEX_FRAG_MIN_VALUE ||
660 frag_thr > MWIFIEX_FRAG_MAX_VALUE)
661 frag_thr = MWIFIEX_FRAG_MAX_VALUE;
663 return mwifiex_send_cmd(priv, HostCmd_CMD_802_11_SNMP_MIB,
664 HostCmd_ACT_GEN_SET, FRAG_THRESH_I,
669 * This function sets the RTS threshold.
671 * The rts value must lie between MWIFIEX_RTS_MIN_VALUE
672 * and MWIFIEX_RTS_MAX_VALUE.
675 mwifiex_set_rts(struct mwifiex_private *priv, u32 rts_thr)
677 if (rts_thr < MWIFIEX_RTS_MIN_VALUE || rts_thr > MWIFIEX_RTS_MAX_VALUE)
678 rts_thr = MWIFIEX_RTS_MAX_VALUE;
680 return mwifiex_send_cmd(priv, HostCmd_CMD_802_11_SNMP_MIB,
681 HostCmd_ACT_GEN_SET, RTS_THRESH_I,
686 * CFG802.11 operation handler to set wiphy parameters.
688 * This function can be used to set the RTS threshold and the
689 * Fragmentation threshold of the driver.
692 mwifiex_cfg80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
694 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
695 struct mwifiex_private *priv;
696 struct mwifiex_uap_bss_param *bss_cfg;
699 priv = mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY);
701 switch (priv->bss_role) {
702 case MWIFIEX_BSS_ROLE_UAP:
703 if (priv->bss_started) {
704 mwifiex_dbg(adapter, ERROR,
705 "cannot change wiphy params when bss started");
709 bss_cfg = kzalloc(sizeof(*bss_cfg), GFP_KERNEL);
713 mwifiex_set_sys_config_invalid_data(bss_cfg);
715 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
716 bss_cfg->rts_threshold = wiphy->rts_threshold;
717 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
718 bss_cfg->frag_threshold = wiphy->frag_threshold;
719 if (changed & WIPHY_PARAM_RETRY_LONG)
720 bss_cfg->retry_limit = wiphy->retry_long;
722 ret = mwifiex_send_cmd(priv, HostCmd_CMD_UAP_SYS_CONFIG,
724 UAP_BSS_PARAMS_I, bss_cfg,
729 mwifiex_dbg(adapter, ERROR,
730 "Failed to set wiphy phy params\n");
735 case MWIFIEX_BSS_ROLE_STA:
736 if (priv->media_connected) {
737 mwifiex_dbg(adapter, ERROR,
738 "cannot change wiphy params when connected");
741 if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
742 ret = mwifiex_set_rts(priv,
743 wiphy->rts_threshold);
747 if (changed & WIPHY_PARAM_FRAG_THRESHOLD) {
748 ret = mwifiex_set_frag(priv,
749 wiphy->frag_threshold);
760 mwifiex_cfg80211_deinit_p2p(struct mwifiex_private *priv)
762 u16 mode = P2P_MODE_DISABLE;
764 if (mwifiex_send_cmd(priv, HostCmd_CMD_P2P_MODE_CFG,
765 HostCmd_ACT_GEN_SET, 0, &mode, true))
772 * This function initializes the functionalities for P2P client.
773 * The P2P client initialization sequence is:
774 * disable -> device -> client
777 mwifiex_cfg80211_init_p2p_client(struct mwifiex_private *priv)
781 if (mwifiex_cfg80211_deinit_p2p(priv))
784 mode = P2P_MODE_DEVICE;
785 if (mwifiex_send_cmd(priv, HostCmd_CMD_P2P_MODE_CFG,
786 HostCmd_ACT_GEN_SET, 0, &mode, true))
789 mode = P2P_MODE_CLIENT;
790 if (mwifiex_send_cmd(priv, HostCmd_CMD_P2P_MODE_CFG,
791 HostCmd_ACT_GEN_SET, 0, &mode, true))
798 * This function initializes the functionalities for P2P GO.
799 * The P2P GO initialization sequence is:
800 * disable -> device -> GO
803 mwifiex_cfg80211_init_p2p_go(struct mwifiex_private *priv)
807 if (mwifiex_cfg80211_deinit_p2p(priv))
810 mode = P2P_MODE_DEVICE;
811 if (mwifiex_send_cmd(priv, HostCmd_CMD_P2P_MODE_CFG,
812 HostCmd_ACT_GEN_SET, 0, &mode, true))
816 if (mwifiex_send_cmd(priv, HostCmd_CMD_P2P_MODE_CFG,
817 HostCmd_ACT_GEN_SET, 0, &mode, true))
823 static int mwifiex_deinit_priv_params(struct mwifiex_private *priv)
825 struct mwifiex_adapter *adapter = priv->adapter;
828 priv->mgmt_frame_mask = 0;
829 if (mwifiex_send_cmd(priv, HostCmd_CMD_MGMT_FRAME_REG,
830 HostCmd_ACT_GEN_SET, 0,
831 &priv->mgmt_frame_mask, false)) {
832 mwifiex_dbg(adapter, ERROR,
833 "could not unregister mgmt frame rx\n");
837 mwifiex_deauthenticate(priv, NULL);
839 spin_lock_irqsave(&adapter->main_proc_lock, flags);
840 adapter->main_locked = true;
841 if (adapter->mwifiex_processing) {
842 spin_unlock_irqrestore(&adapter->main_proc_lock, flags);
843 flush_workqueue(adapter->workqueue);
845 spin_unlock_irqrestore(&adapter->main_proc_lock, flags);
848 spin_lock_irqsave(&adapter->rx_proc_lock, flags);
849 adapter->rx_locked = true;
850 if (adapter->rx_processing) {
851 spin_unlock_irqrestore(&adapter->rx_proc_lock, flags);
852 flush_workqueue(adapter->rx_workqueue);
854 spin_unlock_irqrestore(&adapter->rx_proc_lock, flags);
857 mwifiex_free_priv(priv);
858 priv->wdev.iftype = NL80211_IFTYPE_UNSPECIFIED;
859 priv->bss_mode = NL80211_IFTYPE_UNSPECIFIED;
860 priv->sec_info.authentication_mode = NL80211_AUTHTYPE_OPEN_SYSTEM;
866 mwifiex_init_new_priv_params(struct mwifiex_private *priv,
867 struct net_device *dev,
868 enum nl80211_iftype type)
870 struct mwifiex_adapter *adapter = priv->adapter;
873 mwifiex_init_priv(priv);
875 priv->bss_mode = type;
876 priv->wdev.iftype = type;
878 mwifiex_init_priv_params(priv, priv->netdev);
879 priv->bss_started = 0;
882 case NL80211_IFTYPE_STATION:
883 case NL80211_IFTYPE_ADHOC:
884 priv->bss_num = mwifiex_get_unused_bss_num(adapter,
885 MWIFIEX_BSS_TYPE_STA);
886 priv->bss_role = MWIFIEX_BSS_ROLE_STA;
887 priv->bss_type = MWIFIEX_BSS_TYPE_STA;
889 case NL80211_IFTYPE_P2P_CLIENT:
890 priv->bss_num = mwifiex_get_unused_bss_num(adapter,
891 MWIFIEX_BSS_TYPE_P2P);
892 priv->bss_role = MWIFIEX_BSS_ROLE_STA;
893 priv->bss_type = MWIFIEX_BSS_TYPE_P2P;
895 case NL80211_IFTYPE_P2P_GO:
896 priv->bss_num = mwifiex_get_unused_bss_num(adapter,
897 MWIFIEX_BSS_TYPE_P2P);
898 priv->bss_role = MWIFIEX_BSS_ROLE_UAP;
899 priv->bss_type = MWIFIEX_BSS_TYPE_P2P;
901 case NL80211_IFTYPE_AP:
902 priv->bss_num = mwifiex_get_unused_bss_num(adapter,
903 MWIFIEX_BSS_TYPE_UAP);
904 priv->bss_type = MWIFIEX_BSS_TYPE_UAP;
905 priv->bss_role = MWIFIEX_BSS_ROLE_UAP;
908 mwifiex_dbg(adapter, ERROR,
909 "%s: changing to %d not supported\n",
914 spin_lock_irqsave(&adapter->main_proc_lock, flags);
915 adapter->main_locked = false;
916 spin_unlock_irqrestore(&adapter->main_proc_lock, flags);
918 spin_lock_irqsave(&adapter->rx_proc_lock, flags);
919 adapter->rx_locked = false;
920 spin_unlock_irqrestore(&adapter->rx_proc_lock, flags);
926 mwifiex_change_vif_to_p2p(struct net_device *dev,
927 enum nl80211_iftype curr_iftype,
928 enum nl80211_iftype type, u32 *flags,
929 struct vif_params *params)
931 struct mwifiex_private *priv;
932 struct mwifiex_adapter *adapter;
934 priv = mwifiex_netdev_get_priv(dev);
939 adapter = priv->adapter;
941 if (adapter->curr_iface_comb.p2p_intf ==
942 adapter->iface_limit.p2p_intf) {
943 mwifiex_dbg(adapter, ERROR,
944 "cannot create multiple P2P ifaces\n");
948 mwifiex_dbg(adapter, INFO,
949 "%s: changing role to p2p\n", dev->name);
951 if (mwifiex_deinit_priv_params(priv))
953 if (mwifiex_init_new_priv_params(priv, dev, type))
957 case NL80211_IFTYPE_P2P_CLIENT:
958 if (mwifiex_cfg80211_init_p2p_client(priv))
961 case NL80211_IFTYPE_P2P_GO:
962 if (mwifiex_cfg80211_init_p2p_go(priv))
966 mwifiex_dbg(adapter, ERROR,
967 "%s: changing to %d not supported\n",
972 if (mwifiex_send_cmd(priv, HostCmd_CMD_SET_BSS_MODE,
973 HostCmd_ACT_GEN_SET, 0, NULL, true))
976 if (mwifiex_sta_init_cmd(priv, false, false))
979 switch (curr_iftype) {
980 case NL80211_IFTYPE_STATION:
981 case NL80211_IFTYPE_ADHOC:
982 adapter->curr_iface_comb.sta_intf--;
984 case NL80211_IFTYPE_AP:
985 adapter->curr_iface_comb.uap_intf--;
991 adapter->curr_iface_comb.p2p_intf++;
992 dev->ieee80211_ptr->iftype = type;
998 mwifiex_change_vif_to_sta_adhoc(struct net_device *dev,
999 enum nl80211_iftype curr_iftype,
1000 enum nl80211_iftype type, u32 *flags,
1001 struct vif_params *params)
1003 struct mwifiex_private *priv;
1004 struct mwifiex_adapter *adapter;
1006 priv = mwifiex_netdev_get_priv(dev);
1011 adapter = priv->adapter;
1013 if ((curr_iftype != NL80211_IFTYPE_P2P_CLIENT &&
1014 curr_iftype != NL80211_IFTYPE_P2P_GO) &&
1015 (adapter->curr_iface_comb.sta_intf ==
1016 adapter->iface_limit.sta_intf)) {
1017 mwifiex_dbg(adapter, ERROR,
1018 "cannot create multiple station/adhoc ifaces\n");
1022 if (type == NL80211_IFTYPE_STATION)
1023 mwifiex_dbg(adapter, INFO,
1024 "%s: changing role to station\n", dev->name);
1026 mwifiex_dbg(adapter, INFO,
1027 "%s: changing role to adhoc\n", dev->name);
1029 if (mwifiex_deinit_priv_params(priv))
1031 if (mwifiex_init_new_priv_params(priv, dev, type))
1033 if (mwifiex_send_cmd(priv, HostCmd_CMD_SET_BSS_MODE,
1034 HostCmd_ACT_GEN_SET, 0, NULL, true))
1036 if (mwifiex_sta_init_cmd(priv, false, false))
1039 switch (curr_iftype) {
1040 case NL80211_IFTYPE_P2P_CLIENT:
1041 case NL80211_IFTYPE_P2P_GO:
1042 adapter->curr_iface_comb.p2p_intf--;
1044 case NL80211_IFTYPE_AP:
1045 adapter->curr_iface_comb.uap_intf--;
1051 adapter->curr_iface_comb.sta_intf++;
1052 dev->ieee80211_ptr->iftype = type;
1057 mwifiex_change_vif_to_ap(struct net_device *dev,
1058 enum nl80211_iftype curr_iftype,
1059 enum nl80211_iftype type, u32 *flags,
1060 struct vif_params *params)
1062 struct mwifiex_private *priv;
1063 struct mwifiex_adapter *adapter;
1065 priv = mwifiex_netdev_get_priv(dev);
1070 adapter = priv->adapter;
1072 if (adapter->curr_iface_comb.uap_intf ==
1073 adapter->iface_limit.uap_intf) {
1074 mwifiex_dbg(adapter, ERROR,
1075 "cannot create multiple AP ifaces\n");
1079 mwifiex_dbg(adapter, INFO,
1080 "%s: changing role to AP\n", dev->name);
1082 if (mwifiex_deinit_priv_params(priv))
1084 if (mwifiex_init_new_priv_params(priv, dev, type))
1086 if (mwifiex_send_cmd(priv, HostCmd_CMD_SET_BSS_MODE,
1087 HostCmd_ACT_GEN_SET, 0, NULL, true))
1089 if (mwifiex_sta_init_cmd(priv, false, false))
1092 switch (curr_iftype) {
1093 case NL80211_IFTYPE_P2P_CLIENT:
1094 case NL80211_IFTYPE_P2P_GO:
1095 adapter->curr_iface_comb.p2p_intf--;
1097 case NL80211_IFTYPE_STATION:
1098 case NL80211_IFTYPE_ADHOC:
1099 adapter->curr_iface_comb.sta_intf--;
1105 adapter->curr_iface_comb.uap_intf++;
1106 dev->ieee80211_ptr->iftype = type;
1110 * CFG802.11 operation handler to change interface type.
1113 mwifiex_cfg80211_change_virtual_intf(struct wiphy *wiphy,
1114 struct net_device *dev,
1115 enum nl80211_iftype type, u32 *flags,
1116 struct vif_params *params)
1118 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
1119 enum nl80211_iftype curr_iftype = dev->ieee80211_ptr->iftype;
1121 if (priv->scan_request) {
1122 mwifiex_dbg(priv->adapter, ERROR,
1123 "change virtual interface: scan in process\n");
1127 switch (curr_iftype) {
1128 case NL80211_IFTYPE_ADHOC:
1130 case NL80211_IFTYPE_STATION:
1131 priv->bss_mode = type;
1132 priv->sec_info.authentication_mode =
1133 NL80211_AUTHTYPE_OPEN_SYSTEM;
1134 dev->ieee80211_ptr->iftype = type;
1135 mwifiex_deauthenticate(priv, NULL);
1136 return mwifiex_send_cmd(priv, HostCmd_CMD_SET_BSS_MODE,
1137 HostCmd_ACT_GEN_SET, 0, NULL,
1139 case NL80211_IFTYPE_P2P_CLIENT:
1140 case NL80211_IFTYPE_P2P_GO:
1141 return mwifiex_change_vif_to_p2p(dev, curr_iftype,
1142 type, flags, params);
1143 case NL80211_IFTYPE_AP:
1144 return mwifiex_change_vif_to_ap(dev, curr_iftype, type,
1146 case NL80211_IFTYPE_UNSPECIFIED:
1147 mwifiex_dbg(priv->adapter, INFO,
1148 "%s: kept type as IBSS\n", dev->name);
1149 case NL80211_IFTYPE_ADHOC: /* This shouldn't happen */
1152 mwifiex_dbg(priv->adapter, ERROR,
1153 "%s: changing to %d not supported\n",
1158 case NL80211_IFTYPE_STATION:
1160 case NL80211_IFTYPE_ADHOC:
1161 priv->bss_mode = type;
1162 priv->sec_info.authentication_mode =
1163 NL80211_AUTHTYPE_OPEN_SYSTEM;
1164 dev->ieee80211_ptr->iftype = type;
1165 mwifiex_deauthenticate(priv, NULL);
1166 return mwifiex_send_cmd(priv, HostCmd_CMD_SET_BSS_MODE,
1167 HostCmd_ACT_GEN_SET, 0, NULL,
1169 case NL80211_IFTYPE_P2P_CLIENT:
1170 case NL80211_IFTYPE_P2P_GO:
1171 return mwifiex_change_vif_to_p2p(dev, curr_iftype,
1172 type, flags, params);
1173 case NL80211_IFTYPE_AP:
1174 return mwifiex_change_vif_to_ap(dev, curr_iftype, type,
1176 case NL80211_IFTYPE_UNSPECIFIED:
1177 mwifiex_dbg(priv->adapter, INFO,
1178 "%s: kept type as STA\n", dev->name);
1179 case NL80211_IFTYPE_STATION: /* This shouldn't happen */
1182 mwifiex_dbg(priv->adapter, ERROR,
1183 "%s: changing to %d not supported\n",
1188 case NL80211_IFTYPE_AP:
1190 case NL80211_IFTYPE_ADHOC:
1191 case NL80211_IFTYPE_STATION:
1192 return mwifiex_change_vif_to_sta_adhoc(dev, curr_iftype,
1196 case NL80211_IFTYPE_P2P_CLIENT:
1197 case NL80211_IFTYPE_P2P_GO:
1198 return mwifiex_change_vif_to_p2p(dev, curr_iftype,
1199 type, flags, params);
1200 case NL80211_IFTYPE_UNSPECIFIED:
1201 mwifiex_dbg(priv->adapter, INFO,
1202 "%s: kept type as AP\n", dev->name);
1203 case NL80211_IFTYPE_AP: /* This shouldn't happen */
1206 mwifiex_dbg(priv->adapter, ERROR,
1207 "%s: changing to %d not supported\n",
1212 case NL80211_IFTYPE_P2P_CLIENT:
1213 case NL80211_IFTYPE_P2P_GO:
1215 case NL80211_IFTYPE_STATION:
1216 if (mwifiex_cfg80211_deinit_p2p(priv))
1218 priv->adapter->curr_iface_comb.p2p_intf--;
1219 priv->adapter->curr_iface_comb.sta_intf++;
1220 dev->ieee80211_ptr->iftype = type;
1221 if (mwifiex_deinit_priv_params(priv))
1223 if (mwifiex_init_new_priv_params(priv, dev, type))
1225 if (mwifiex_sta_init_cmd(priv, false, false))
1228 case NL80211_IFTYPE_ADHOC:
1229 if (mwifiex_cfg80211_deinit_p2p(priv))
1231 return mwifiex_change_vif_to_sta_adhoc(dev, curr_iftype,
1235 case NL80211_IFTYPE_AP:
1236 if (mwifiex_cfg80211_deinit_p2p(priv))
1238 return mwifiex_change_vif_to_ap(dev, curr_iftype, type,
1240 case NL80211_IFTYPE_UNSPECIFIED:
1241 mwifiex_dbg(priv->adapter, INFO,
1242 "%s: kept type as P2P\n", dev->name);
1243 case NL80211_IFTYPE_P2P_CLIENT:
1244 case NL80211_IFTYPE_P2P_GO:
1247 mwifiex_dbg(priv->adapter, ERROR,
1248 "%s: changing to %d not supported\n",
1254 mwifiex_dbg(priv->adapter, ERROR,
1255 "%s: unknown iftype: %d\n",
1256 dev->name, dev->ieee80211_ptr->iftype);
1265 mwifiex_parse_htinfo(struct mwifiex_private *priv, u8 tx_htinfo,
1266 struct rate_info *rate)
1268 struct mwifiex_adapter *adapter = priv->adapter;
1270 if (adapter->is_hw_11ac_capable) {
1271 /* bit[1-0]: 00=LG 01=HT 10=VHT */
1272 if (tx_htinfo & BIT(0)) {
1274 rate->mcs = priv->tx_rate;
1275 rate->flags |= RATE_INFO_FLAGS_MCS;
1277 if (tx_htinfo & BIT(1)) {
1279 rate->mcs = priv->tx_rate & 0x0F;
1280 rate->flags |= RATE_INFO_FLAGS_VHT_MCS;
1283 if (tx_htinfo & (BIT(1) | BIT(0))) {
1285 switch (tx_htinfo & (BIT(3) | BIT(2))) {
1287 rate->bw = RATE_INFO_BW_20;
1290 rate->bw = RATE_INFO_BW_40;
1293 rate->bw = RATE_INFO_BW_80;
1295 case (BIT(3) | BIT(2)):
1296 rate->bw = RATE_INFO_BW_160;
1300 if (tx_htinfo & BIT(4))
1301 rate->flags |= RATE_INFO_FLAGS_SHORT_GI;
1303 if ((priv->tx_rate >> 4) == 1)
1310 * Bit 0 in tx_htinfo indicates that current Tx rate
1311 * is 11n rate. Valid MCS index values for us are 0 to 15.
1313 if ((tx_htinfo & BIT(0)) && (priv->tx_rate < 16)) {
1314 rate->mcs = priv->tx_rate;
1315 rate->flags |= RATE_INFO_FLAGS_MCS;
1316 rate->bw = RATE_INFO_BW_20;
1317 if (tx_htinfo & BIT(1))
1318 rate->bw = RATE_INFO_BW_40;
1319 if (tx_htinfo & BIT(2))
1320 rate->flags |= RATE_INFO_FLAGS_SHORT_GI;
1326 * This function dumps the station information on a buffer.
1328 * The following information are shown -
1329 * - Total bytes transmitted
1330 * - Total bytes received
1331 * - Total packets transmitted
1332 * - Total packets received
1333 * - Signal quality level
1334 * - Transmission rate
1337 mwifiex_dump_station_info(struct mwifiex_private *priv,
1338 struct mwifiex_sta_node *node,
1339 struct station_info *sinfo)
1343 sinfo->filled = BIT(NL80211_STA_INFO_RX_BYTES) | BIT(NL80211_STA_INFO_TX_BYTES) |
1344 BIT(NL80211_STA_INFO_RX_PACKETS) | BIT(NL80211_STA_INFO_TX_PACKETS) |
1345 BIT(NL80211_STA_INFO_TX_BITRATE) |
1346 BIT(NL80211_STA_INFO_SIGNAL) | BIT(NL80211_STA_INFO_SIGNAL_AVG);
1348 if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_UAP) {
1352 sinfo->filled |= BIT(NL80211_STA_INFO_INACTIVE_TIME) |
1353 BIT(NL80211_STA_INFO_TX_FAILED);
1354 sinfo->inactive_time =
1355 jiffies_to_msecs(jiffies - node->stats.last_rx);
1357 sinfo->signal = node->stats.rssi;
1358 sinfo->signal_avg = node->stats.rssi;
1359 sinfo->rx_bytes = node->stats.rx_bytes;
1360 sinfo->tx_bytes = node->stats.tx_bytes;
1361 sinfo->rx_packets = node->stats.rx_packets;
1362 sinfo->tx_packets = node->stats.tx_packets;
1363 sinfo->tx_failed = node->stats.tx_failed;
1365 mwifiex_parse_htinfo(priv, node->stats.last_tx_htinfo,
1367 sinfo->txrate.legacy = node->stats.last_tx_rate * 5;
1372 /* Get signal information from the firmware */
1373 if (mwifiex_send_cmd(priv, HostCmd_CMD_RSSI_INFO,
1374 HostCmd_ACT_GEN_GET, 0, NULL, true)) {
1375 mwifiex_dbg(priv->adapter, ERROR,
1376 "failed to get signal information\n");
1380 if (mwifiex_drv_get_data_rate(priv, &rate)) {
1381 mwifiex_dbg(priv->adapter, ERROR,
1382 "getting data rate error\n");
1386 /* Get DTIM period information from firmware */
1387 mwifiex_send_cmd(priv, HostCmd_CMD_802_11_SNMP_MIB,
1388 HostCmd_ACT_GEN_GET, DTIM_PERIOD_I,
1389 &priv->dtim_period, true);
1391 mwifiex_parse_htinfo(priv, priv->tx_htinfo, &sinfo->txrate);
1393 sinfo->signal_avg = priv->bcn_rssi_avg;
1394 sinfo->rx_bytes = priv->stats.rx_bytes;
1395 sinfo->tx_bytes = priv->stats.tx_bytes;
1396 sinfo->rx_packets = priv->stats.rx_packets;
1397 sinfo->tx_packets = priv->stats.tx_packets;
1398 sinfo->signal = priv->bcn_rssi_avg;
1399 /* bit rate is in 500 kb/s units. Convert it to 100kb/s units */
1400 sinfo->txrate.legacy = rate * 5;
1402 if (priv->bss_mode == NL80211_IFTYPE_STATION) {
1403 sinfo->filled |= BIT(NL80211_STA_INFO_BSS_PARAM);
1404 sinfo->bss_param.flags = 0;
1405 if (priv->curr_bss_params.bss_descriptor.cap_info_bitmap &
1406 WLAN_CAPABILITY_SHORT_PREAMBLE)
1407 sinfo->bss_param.flags |=
1408 BSS_PARAM_FLAGS_SHORT_PREAMBLE;
1409 if (priv->curr_bss_params.bss_descriptor.cap_info_bitmap &
1410 WLAN_CAPABILITY_SHORT_SLOT_TIME)
1411 sinfo->bss_param.flags |=
1412 BSS_PARAM_FLAGS_SHORT_SLOT_TIME;
1413 sinfo->bss_param.dtim_period = priv->dtim_period;
1414 sinfo->bss_param.beacon_interval =
1415 priv->curr_bss_params.bss_descriptor.beacon_period;
1422 * CFG802.11 operation handler to get station information.
1424 * This function only works in connected mode, and dumps the
1425 * requested station information, if available.
1428 mwifiex_cfg80211_get_station(struct wiphy *wiphy, struct net_device *dev,
1429 const u8 *mac, struct station_info *sinfo)
1431 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
1433 if (!priv->media_connected)
1435 if (memcmp(mac, priv->cfg_bssid, ETH_ALEN))
1438 return mwifiex_dump_station_info(priv, NULL, sinfo);
1442 * CFG802.11 operation handler to dump station information.
1445 mwifiex_cfg80211_dump_station(struct wiphy *wiphy, struct net_device *dev,
1446 int idx, u8 *mac, struct station_info *sinfo)
1448 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
1449 struct mwifiex_sta_node *node;
1452 if ((GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA) &&
1453 priv->media_connected && idx == 0) {
1454 ether_addr_copy(mac, priv->cfg_bssid);
1455 return mwifiex_dump_station_info(priv, NULL, sinfo);
1456 } else if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_UAP) {
1457 mwifiex_send_cmd(priv, HOST_CMD_APCMD_STA_LIST,
1458 HostCmd_ACT_GEN_GET, 0, NULL, true);
1461 list_for_each_entry(node, &priv->sta_list, list) {
1464 ether_addr_copy(mac, node->mac_addr);
1465 return mwifiex_dump_station_info(priv, node, sinfo);
1473 mwifiex_cfg80211_dump_survey(struct wiphy *wiphy, struct net_device *dev,
1474 int idx, struct survey_info *survey)
1476 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
1477 struct mwifiex_chan_stats *pchan_stats = priv->adapter->chan_stats;
1478 enum nl80211_band band;
1480 mwifiex_dbg(priv->adapter, DUMP, "dump_survey idx=%d\n", idx);
1482 memset(survey, 0, sizeof(struct survey_info));
1484 if ((GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA) &&
1485 priv->media_connected && idx == 0) {
1486 u8 curr_bss_band = priv->curr_bss_params.band;
1487 u32 chan = priv->curr_bss_params.bss_descriptor.channel;
1489 band = mwifiex_band_to_radio_type(curr_bss_band);
1490 survey->channel = ieee80211_get_channel(wiphy,
1491 ieee80211_channel_to_frequency(chan, band));
1493 if (priv->bcn_nf_last) {
1494 survey->filled = SURVEY_INFO_NOISE_DBM;
1495 survey->noise = priv->bcn_nf_last;
1500 if (idx >= priv->adapter->num_in_chan_stats)
1503 if (!pchan_stats[idx].cca_scan_dur)
1506 band = pchan_stats[idx].bandcfg;
1507 survey->channel = ieee80211_get_channel(wiphy,
1508 ieee80211_channel_to_frequency(pchan_stats[idx].chan_num, band));
1509 survey->filled = SURVEY_INFO_NOISE_DBM |
1511 SURVEY_INFO_TIME_BUSY;
1512 survey->noise = pchan_stats[idx].noise;
1513 survey->time = pchan_stats[idx].cca_scan_dur;
1514 survey->time_busy = pchan_stats[idx].cca_busy_dur;
1519 /* Supported rates to be advertised to the cfg80211 */
1520 static struct ieee80211_rate mwifiex_rates[] = {
1521 {.bitrate = 10, .hw_value = 2, },
1522 {.bitrate = 20, .hw_value = 4, },
1523 {.bitrate = 55, .hw_value = 11, },
1524 {.bitrate = 110, .hw_value = 22, },
1525 {.bitrate = 60, .hw_value = 12, },
1526 {.bitrate = 90, .hw_value = 18, },
1527 {.bitrate = 120, .hw_value = 24, },
1528 {.bitrate = 180, .hw_value = 36, },
1529 {.bitrate = 240, .hw_value = 48, },
1530 {.bitrate = 360, .hw_value = 72, },
1531 {.bitrate = 480, .hw_value = 96, },
1532 {.bitrate = 540, .hw_value = 108, },
1535 /* Channel definitions to be advertised to cfg80211 */
1536 static struct ieee80211_channel mwifiex_channels_2ghz[] = {
1537 {.center_freq = 2412, .hw_value = 1, },
1538 {.center_freq = 2417, .hw_value = 2, },
1539 {.center_freq = 2422, .hw_value = 3, },
1540 {.center_freq = 2427, .hw_value = 4, },
1541 {.center_freq = 2432, .hw_value = 5, },
1542 {.center_freq = 2437, .hw_value = 6, },
1543 {.center_freq = 2442, .hw_value = 7, },
1544 {.center_freq = 2447, .hw_value = 8, },
1545 {.center_freq = 2452, .hw_value = 9, },
1546 {.center_freq = 2457, .hw_value = 10, },
1547 {.center_freq = 2462, .hw_value = 11, },
1548 {.center_freq = 2467, .hw_value = 12, },
1549 {.center_freq = 2472, .hw_value = 13, },
1550 {.center_freq = 2484, .hw_value = 14, },
1553 static struct ieee80211_supported_band mwifiex_band_2ghz = {
1554 .channels = mwifiex_channels_2ghz,
1555 .n_channels = ARRAY_SIZE(mwifiex_channels_2ghz),
1556 .bitrates = mwifiex_rates,
1557 .n_bitrates = ARRAY_SIZE(mwifiex_rates),
1560 static struct ieee80211_channel mwifiex_channels_5ghz[] = {
1561 {.center_freq = 5040, .hw_value = 8, },
1562 {.center_freq = 5060, .hw_value = 12, },
1563 {.center_freq = 5080, .hw_value = 16, },
1564 {.center_freq = 5170, .hw_value = 34, },
1565 {.center_freq = 5190, .hw_value = 38, },
1566 {.center_freq = 5210, .hw_value = 42, },
1567 {.center_freq = 5230, .hw_value = 46, },
1568 {.center_freq = 5180, .hw_value = 36, },
1569 {.center_freq = 5200, .hw_value = 40, },
1570 {.center_freq = 5220, .hw_value = 44, },
1571 {.center_freq = 5240, .hw_value = 48, },
1572 {.center_freq = 5260, .hw_value = 52, },
1573 {.center_freq = 5280, .hw_value = 56, },
1574 {.center_freq = 5300, .hw_value = 60, },
1575 {.center_freq = 5320, .hw_value = 64, },
1576 {.center_freq = 5500, .hw_value = 100, },
1577 {.center_freq = 5520, .hw_value = 104, },
1578 {.center_freq = 5540, .hw_value = 108, },
1579 {.center_freq = 5560, .hw_value = 112, },
1580 {.center_freq = 5580, .hw_value = 116, },
1581 {.center_freq = 5600, .hw_value = 120, },
1582 {.center_freq = 5620, .hw_value = 124, },
1583 {.center_freq = 5640, .hw_value = 128, },
1584 {.center_freq = 5660, .hw_value = 132, },
1585 {.center_freq = 5680, .hw_value = 136, },
1586 {.center_freq = 5700, .hw_value = 140, },
1587 {.center_freq = 5745, .hw_value = 149, },
1588 {.center_freq = 5765, .hw_value = 153, },
1589 {.center_freq = 5785, .hw_value = 157, },
1590 {.center_freq = 5805, .hw_value = 161, },
1591 {.center_freq = 5825, .hw_value = 165, },
1594 static struct ieee80211_supported_band mwifiex_band_5ghz = {
1595 .channels = mwifiex_channels_5ghz,
1596 .n_channels = ARRAY_SIZE(mwifiex_channels_5ghz),
1597 .bitrates = mwifiex_rates + 4,
1598 .n_bitrates = ARRAY_SIZE(mwifiex_rates) - 4,
1602 /* Supported crypto cipher suits to be advertised to cfg80211 */
1603 static const u32 mwifiex_cipher_suites[] = {
1604 WLAN_CIPHER_SUITE_WEP40,
1605 WLAN_CIPHER_SUITE_WEP104,
1606 WLAN_CIPHER_SUITE_TKIP,
1607 WLAN_CIPHER_SUITE_CCMP,
1608 WLAN_CIPHER_SUITE_SMS4,
1609 WLAN_CIPHER_SUITE_AES_CMAC,
1612 /* Supported mgmt frame types to be advertised to cfg80211 */
1613 static const struct ieee80211_txrx_stypes
1614 mwifiex_mgmt_stypes[NUM_NL80211_IFTYPES] = {
1615 [NL80211_IFTYPE_STATION] = {
1616 .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
1617 BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
1618 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
1619 BIT(IEEE80211_STYPE_PROBE_REQ >> 4),
1621 [NL80211_IFTYPE_AP] = {
1622 .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
1623 BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
1624 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
1625 BIT(IEEE80211_STYPE_PROBE_REQ >> 4),
1627 [NL80211_IFTYPE_P2P_CLIENT] = {
1628 .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
1629 BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
1630 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
1631 BIT(IEEE80211_STYPE_PROBE_REQ >> 4),
1633 [NL80211_IFTYPE_P2P_GO] = {
1634 .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
1635 BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
1636 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
1637 BIT(IEEE80211_STYPE_PROBE_REQ >> 4),
1642 * CFG802.11 operation handler for setting bit rates.
1644 * Function configures data rates to firmware using bitrate mask
1645 * provided by cfg80211.
1647 static int mwifiex_cfg80211_set_bitrate_mask(struct wiphy *wiphy,
1648 struct net_device *dev,
1650 const struct cfg80211_bitrate_mask *mask)
1652 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
1653 u16 bitmap_rates[MAX_BITMAP_RATES_SIZE];
1654 enum nl80211_band band;
1655 struct mwifiex_adapter *adapter = priv->adapter;
1657 if (!priv->media_connected) {
1658 mwifiex_dbg(adapter, ERROR,
1659 "Can not set Tx data rate in disconnected state\n");
1663 band = mwifiex_band_to_radio_type(priv->curr_bss_params.band);
1665 memset(bitmap_rates, 0, sizeof(bitmap_rates));
1667 /* Fill HR/DSSS rates. */
1668 if (band == NL80211_BAND_2GHZ)
1669 bitmap_rates[0] = mask->control[band].legacy & 0x000f;
1671 /* Fill OFDM rates */
1672 if (band == NL80211_BAND_2GHZ)
1673 bitmap_rates[1] = (mask->control[band].legacy & 0x0ff0) >> 4;
1675 bitmap_rates[1] = mask->control[band].legacy;
1677 /* Fill HT MCS rates */
1678 bitmap_rates[2] = mask->control[band].ht_mcs[0];
1679 if (adapter->hw_dev_mcs_support == HT_STREAM_2X2)
1680 bitmap_rates[2] |= mask->control[band].ht_mcs[1] << 8;
1682 /* Fill VHT MCS rates */
1683 if (adapter->fw_api_ver == MWIFIEX_FW_V15) {
1684 bitmap_rates[10] = mask->control[band].vht_mcs[0];
1685 if (adapter->hw_dev_mcs_support == HT_STREAM_2X2)
1686 bitmap_rates[11] = mask->control[band].vht_mcs[1];
1689 return mwifiex_send_cmd(priv, HostCmd_CMD_TX_RATE_CFG,
1690 HostCmd_ACT_GEN_SET, 0, bitmap_rates, true);
1694 * CFG802.11 operation handler for connection quality monitoring.
1696 * This function subscribes/unsubscribes HIGH_RSSI and LOW_RSSI
1699 static int mwifiex_cfg80211_set_cqm_rssi_config(struct wiphy *wiphy,
1700 struct net_device *dev,
1701 s32 rssi_thold, u32 rssi_hyst)
1703 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
1704 struct mwifiex_ds_misc_subsc_evt subsc_evt;
1706 priv->cqm_rssi_thold = rssi_thold;
1707 priv->cqm_rssi_hyst = rssi_hyst;
1709 memset(&subsc_evt, 0x00, sizeof(struct mwifiex_ds_misc_subsc_evt));
1710 subsc_evt.events = BITMASK_BCN_RSSI_LOW | BITMASK_BCN_RSSI_HIGH;
1712 /* Subscribe/unsubscribe low and high rssi events */
1713 if (rssi_thold && rssi_hyst) {
1714 subsc_evt.action = HostCmd_ACT_BITWISE_SET;
1715 subsc_evt.bcn_l_rssi_cfg.abs_value = abs(rssi_thold);
1716 subsc_evt.bcn_h_rssi_cfg.abs_value = abs(rssi_thold);
1717 subsc_evt.bcn_l_rssi_cfg.evt_freq = 1;
1718 subsc_evt.bcn_h_rssi_cfg.evt_freq = 1;
1719 return mwifiex_send_cmd(priv,
1720 HostCmd_CMD_802_11_SUBSCRIBE_EVENT,
1721 0, 0, &subsc_evt, true);
1723 subsc_evt.action = HostCmd_ACT_BITWISE_CLR;
1724 return mwifiex_send_cmd(priv,
1725 HostCmd_CMD_802_11_SUBSCRIBE_EVENT,
1726 0, 0, &subsc_evt, true);
1732 /* cfg80211 operation handler for change_beacon.
1733 * Function retrieves and sets modified management IEs to FW.
1735 static int mwifiex_cfg80211_change_beacon(struct wiphy *wiphy,
1736 struct net_device *dev,
1737 struct cfg80211_beacon_data *data)
1739 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
1740 struct mwifiex_adapter *adapter = priv->adapter;
1742 mwifiex_cancel_scan(adapter);
1744 if (GET_BSS_ROLE(priv) != MWIFIEX_BSS_ROLE_UAP) {
1745 mwifiex_dbg(priv->adapter, ERROR,
1746 "%s: bss_type mismatched\n", __func__);
1750 if (!priv->bss_started) {
1751 mwifiex_dbg(priv->adapter, ERROR,
1752 "%s: bss not started\n", __func__);
1756 if (mwifiex_set_mgmt_ies(priv, data)) {
1757 mwifiex_dbg(priv->adapter, ERROR,
1758 "%s: setting mgmt ies failed\n", __func__);
1765 /* cfg80211 operation handler for del_station.
1766 * Function deauthenticates station which value is provided in mac parameter.
1767 * If mac is NULL/broadcast, all stations in associated station list are
1768 * deauthenticated. If bss is not started or there are no stations in
1769 * associated stations list, no action is taken.
1772 mwifiex_cfg80211_del_station(struct wiphy *wiphy, struct net_device *dev,
1773 struct station_del_parameters *params)
1775 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
1776 struct mwifiex_sta_node *sta_node;
1777 u8 deauth_mac[ETH_ALEN];
1778 unsigned long flags;
1780 if (!priv->bss_started && priv->wdev.cac_started) {
1781 mwifiex_dbg(priv->adapter, INFO, "%s: abort CAC!\n", __func__);
1782 mwifiex_abort_cac(priv);
1785 if (list_empty(&priv->sta_list) || !priv->bss_started)
1788 if (!params->mac || is_broadcast_ether_addr(params->mac))
1791 mwifiex_dbg(priv->adapter, INFO, "%s: mac address %pM\n",
1792 __func__, params->mac);
1794 eth_zero_addr(deauth_mac);
1796 spin_lock_irqsave(&priv->sta_list_spinlock, flags);
1797 sta_node = mwifiex_get_sta_entry(priv, params->mac);
1799 ether_addr_copy(deauth_mac, params->mac);
1800 spin_unlock_irqrestore(&priv->sta_list_spinlock, flags);
1802 if (is_valid_ether_addr(deauth_mac)) {
1803 if (mwifiex_send_cmd(priv, HostCmd_CMD_UAP_STA_DEAUTH,
1804 HostCmd_ACT_GEN_SET, 0,
1813 mwifiex_cfg80211_set_antenna(struct wiphy *wiphy, u32 tx_ant, u32 rx_ant)
1815 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
1816 struct mwifiex_private *priv = mwifiex_get_priv(adapter,
1817 MWIFIEX_BSS_ROLE_ANY);
1818 struct mwifiex_ds_ant_cfg ant_cfg;
1820 if (!tx_ant || !rx_ant)
1823 if (adapter->hw_dev_mcs_support != HT_STREAM_2X2) {
1824 /* Not a MIMO chip. User should provide specific antenna number
1825 * for Tx/Rx path or enable all antennas for diversity
1827 if (tx_ant != rx_ant)
1830 if ((tx_ant & (tx_ant - 1)) &&
1831 (tx_ant != BIT(adapter->number_of_antenna) - 1))
1834 if ((tx_ant == BIT(adapter->number_of_antenna) - 1) &&
1835 (priv->adapter->number_of_antenna > 1)) {
1836 tx_ant = RF_ANTENNA_AUTO;
1837 rx_ant = RF_ANTENNA_AUTO;
1840 struct ieee80211_sta_ht_cap *ht_info;
1842 enum nl80211_band band;
1844 if ((tx_ant == 0x1 && rx_ant == 0x1)) {
1845 adapter->user_dev_mcs_support = HT_STREAM_1X1;
1846 if (adapter->is_hw_11ac_capable)
1847 adapter->usr_dot_11ac_mcs_support =
1848 MWIFIEX_11AC_MCS_MAP_1X1;
1850 adapter->user_dev_mcs_support = HT_STREAM_2X2;
1851 if (adapter->is_hw_11ac_capable)
1852 adapter->usr_dot_11ac_mcs_support =
1853 MWIFIEX_11AC_MCS_MAP_2X2;
1856 for (band = 0; band < NUM_NL80211_BANDS; band++) {
1857 if (!adapter->wiphy->bands[band])
1860 ht_info = &adapter->wiphy->bands[band]->ht_cap;
1862 GET_RXMCSSUPP(adapter->user_dev_mcs_support);
1863 memset(&ht_info->mcs, 0, adapter->number_of_antenna);
1864 memset(&ht_info->mcs, 0xff, rx_mcs_supp);
1868 ant_cfg.tx_ant = tx_ant;
1869 ant_cfg.rx_ant = rx_ant;
1871 return mwifiex_send_cmd(priv, HostCmd_CMD_RF_ANTENNA,
1872 HostCmd_ACT_GEN_SET, 0, &ant_cfg, true);
1876 mwifiex_cfg80211_get_antenna(struct wiphy *wiphy, u32 *tx_ant, u32 *rx_ant)
1878 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
1879 struct mwifiex_private *priv = mwifiex_get_priv(adapter,
1880 MWIFIEX_BSS_ROLE_ANY);
1881 mwifiex_send_cmd(priv, HostCmd_CMD_RF_ANTENNA,
1882 HostCmd_ACT_GEN_GET, 0, NULL, true);
1884 *tx_ant = priv->tx_ant;
1885 *rx_ant = priv->rx_ant;
1890 /* cfg80211 operation handler for stop ap.
1891 * Function stops BSS running at uAP interface.
1893 static int mwifiex_cfg80211_stop_ap(struct wiphy *wiphy, struct net_device *dev)
1895 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
1897 mwifiex_abort_cac(priv);
1899 if (mwifiex_del_mgmt_ies(priv))
1900 mwifiex_dbg(priv->adapter, ERROR,
1901 "Failed to delete mgmt IEs!\n");
1903 priv->ap_11n_enabled = 0;
1904 memset(&priv->bss_cfg, 0, sizeof(priv->bss_cfg));
1906 if (mwifiex_send_cmd(priv, HostCmd_CMD_UAP_BSS_STOP,
1907 HostCmd_ACT_GEN_SET, 0, NULL, true)) {
1908 mwifiex_dbg(priv->adapter, ERROR,
1909 "Failed to stop the BSS\n");
1913 if (mwifiex_send_cmd(priv, HOST_CMD_APCMD_SYS_RESET,
1914 HostCmd_ACT_GEN_SET, 0, NULL, true)) {
1915 mwifiex_dbg(priv->adapter, ERROR,
1916 "Failed to reset BSS\n");
1920 if (netif_carrier_ok(priv->netdev))
1921 netif_carrier_off(priv->netdev);
1922 mwifiex_stop_net_dev_queue(priv->netdev, priv->adapter);
1927 /* cfg80211 operation handler for start_ap.
1928 * Function sets beacon period, DTIM period, SSID and security into
1929 * AP config structure.
1930 * AP is configured with these settings and BSS is started.
1932 static int mwifiex_cfg80211_start_ap(struct wiphy *wiphy,
1933 struct net_device *dev,
1934 struct cfg80211_ap_settings *params)
1936 struct mwifiex_uap_bss_param *bss_cfg;
1937 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
1939 if (GET_BSS_ROLE(priv) != MWIFIEX_BSS_ROLE_UAP)
1942 bss_cfg = kzalloc(sizeof(struct mwifiex_uap_bss_param), GFP_KERNEL);
1946 mwifiex_set_sys_config_invalid_data(bss_cfg);
1948 if (params->beacon_interval)
1949 bss_cfg->beacon_period = params->beacon_interval;
1950 if (params->dtim_period)
1951 bss_cfg->dtim_period = params->dtim_period;
1953 if (params->ssid && params->ssid_len) {
1954 memcpy(bss_cfg->ssid.ssid, params->ssid, params->ssid_len);
1955 bss_cfg->ssid.ssid_len = params->ssid_len;
1957 if (params->inactivity_timeout > 0) {
1958 /* sta_ao_timer/ps_sta_ao_timer is in unit of 100ms */
1959 bss_cfg->sta_ao_timer = 10 * params->inactivity_timeout;
1960 bss_cfg->ps_sta_ao_timer = 10 * params->inactivity_timeout;
1963 switch (params->hidden_ssid) {
1964 case NL80211_HIDDEN_SSID_NOT_IN_USE:
1965 bss_cfg->bcast_ssid_ctl = 1;
1967 case NL80211_HIDDEN_SSID_ZERO_LEN:
1968 bss_cfg->bcast_ssid_ctl = 0;
1970 case NL80211_HIDDEN_SSID_ZERO_CONTENTS:
1971 /* firmware doesn't support this type of hidden SSID */
1977 mwifiex_uap_set_channel(priv, bss_cfg, params->chandef);
1978 mwifiex_set_uap_rates(bss_cfg, params);
1980 if (mwifiex_set_secure_params(priv, bss_cfg, params)) {
1981 mwifiex_dbg(priv->adapter, ERROR,
1982 "Failed to parse secuirty parameters!\n");
1986 mwifiex_set_ht_params(priv, bss_cfg, params);
1988 if (priv->adapter->is_hw_11ac_capable) {
1989 mwifiex_set_vht_params(priv, bss_cfg, params);
1990 mwifiex_set_vht_width(priv, params->chandef.width,
1991 priv->ap_11ac_enabled);
1994 if (priv->ap_11ac_enabled)
1995 mwifiex_set_11ac_ba_params(priv);
1997 mwifiex_set_ba_params(priv);
1999 mwifiex_set_wmm_params(priv, bss_cfg, params);
2001 if (mwifiex_is_11h_active(priv))
2002 mwifiex_set_tpc_params(priv, bss_cfg, params);
2004 if (mwifiex_is_11h_active(priv) &&
2005 !cfg80211_chandef_dfs_required(wiphy, ¶ms->chandef,
2007 mwifiex_dbg(priv->adapter, INFO,
2008 "Disable 11h extensions in FW\n");
2009 if (mwifiex_11h_activate(priv, false)) {
2010 mwifiex_dbg(priv->adapter, ERROR,
2011 "Failed to disable 11h extensions!!");
2014 priv->state_11h.is_11h_active = false;
2017 if (mwifiex_config_start_uap(priv, bss_cfg)) {
2018 mwifiex_dbg(priv->adapter, ERROR,
2019 "Failed to start AP\n");
2023 if (mwifiex_set_mgmt_ies(priv, ¶ms->beacon))
2026 if (!netif_carrier_ok(priv->netdev))
2027 netif_carrier_on(priv->netdev);
2028 mwifiex_wake_up_net_dev_queue(priv->netdev, priv->adapter);
2030 memcpy(&priv->bss_cfg, bss_cfg, sizeof(priv->bss_cfg));
2040 * CFG802.11 operation handler for disconnection request.
2042 * This function does not work when there is already a disconnection
2043 * procedure going on.
2046 mwifiex_cfg80211_disconnect(struct wiphy *wiphy, struct net_device *dev,
2049 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
2051 if (!mwifiex_stop_bg_scan(priv))
2052 cfg80211_sched_scan_stopped_rtnl(priv->wdev.wiphy);
2054 if (mwifiex_deauthenticate(priv, NULL))
2057 eth_zero_addr(priv->cfg_bssid);
2058 priv->hs2_enabled = false;
2064 * This function informs the CFG802.11 subsystem of a new IBSS.
2066 * The following information are sent to the CFG802.11 subsystem
2067 * to register the new IBSS. If we do not register the new IBSS,
2068 * a kernel panic will result.
2074 static int mwifiex_cfg80211_inform_ibss_bss(struct mwifiex_private *priv)
2076 struct ieee80211_channel *chan;
2077 struct mwifiex_bss_info bss_info;
2078 struct cfg80211_bss *bss;
2080 u8 ie_buf[IEEE80211_MAX_SSID_LEN + sizeof(struct ieee_types_header)];
2081 enum nl80211_band band;
2083 if (mwifiex_get_bss_info(priv, &bss_info))
2086 ie_buf[0] = WLAN_EID_SSID;
2087 ie_buf[1] = bss_info.ssid.ssid_len;
2089 memcpy(&ie_buf[sizeof(struct ieee_types_header)],
2090 &bss_info.ssid.ssid, bss_info.ssid.ssid_len);
2091 ie_len = ie_buf[1] + sizeof(struct ieee_types_header);
2093 band = mwifiex_band_to_radio_type(priv->curr_bss_params.band);
2094 chan = __ieee80211_get_channel(priv->wdev.wiphy,
2095 ieee80211_channel_to_frequency(bss_info.bss_chan,
2098 bss = cfg80211_inform_bss(priv->wdev.wiphy, chan,
2099 CFG80211_BSS_FTYPE_UNKNOWN,
2100 bss_info.bssid, 0, WLAN_CAPABILITY_IBSS,
2101 0, ie_buf, ie_len, 0, GFP_KERNEL);
2103 cfg80211_put_bss(priv->wdev.wiphy, bss);
2104 ether_addr_copy(priv->cfg_bssid, bss_info.bssid);
2111 * This function connects with a BSS.
2113 * This function handles both Infra and Ad-Hoc modes. It also performs
2114 * validity checking on the provided parameters, disconnects from the
2115 * current BSS (if any), sets up the association/scan parameters,
2116 * including security settings, and performs specific SSID scan before
2117 * trying to connect.
2119 * For Infra mode, the function returns failure if the specified SSID
2120 * is not found in scan table. However, for Ad-Hoc mode, it can create
2121 * the IBSS if it does not exist. On successful completion in either case,
2122 * the function notifies the CFG802.11 subsystem of the new BSS connection.
2125 mwifiex_cfg80211_assoc(struct mwifiex_private *priv, size_t ssid_len,
2126 const u8 *ssid, const u8 *bssid, int mode,
2127 struct ieee80211_channel *channel,
2128 struct cfg80211_connect_params *sme, bool privacy)
2130 struct cfg80211_ssid req_ssid;
2131 int ret, auth_type = 0;
2132 struct cfg80211_bss *bss = NULL;
2133 u8 is_scanning_required = 0;
2135 memset(&req_ssid, 0, sizeof(struct cfg80211_ssid));
2137 req_ssid.ssid_len = ssid_len;
2138 if (ssid_len > IEEE80211_MAX_SSID_LEN) {
2139 mwifiex_dbg(priv->adapter, ERROR, "invalid SSID - aborting\n");
2143 memcpy(req_ssid.ssid, ssid, ssid_len);
2144 if (!req_ssid.ssid_len || req_ssid.ssid[0] < 0x20) {
2145 mwifiex_dbg(priv->adapter, ERROR, "invalid SSID - aborting\n");
2149 /* As this is new association, clear locally stored
2150 * keys and security related flags */
2151 priv->sec_info.wpa_enabled = false;
2152 priv->sec_info.wpa2_enabled = false;
2153 priv->wep_key_curr_index = 0;
2154 priv->sec_info.encryption_mode = 0;
2155 priv->sec_info.is_authtype_auto = 0;
2156 ret = mwifiex_set_encode(priv, NULL, NULL, 0, 0, NULL, 1);
2158 if (mode == NL80211_IFTYPE_ADHOC) {
2159 /* "privacy" is set only for ad-hoc mode */
2162 * Keep WLAN_CIPHER_SUITE_WEP104 for now so that
2163 * the firmware can find a matching network from the
2164 * scan. The cfg80211 does not give us the encryption
2165 * mode at this stage so just setting it to WEP here.
2167 priv->sec_info.encryption_mode =
2168 WLAN_CIPHER_SUITE_WEP104;
2169 priv->sec_info.authentication_mode =
2170 NL80211_AUTHTYPE_OPEN_SYSTEM;
2176 /* Now handle infra mode. "sme" is valid for infra mode only */
2177 if (sme->auth_type == NL80211_AUTHTYPE_AUTOMATIC) {
2178 auth_type = NL80211_AUTHTYPE_OPEN_SYSTEM;
2179 priv->sec_info.is_authtype_auto = 1;
2181 auth_type = sme->auth_type;
2184 if (sme->crypto.n_ciphers_pairwise) {
2185 priv->sec_info.encryption_mode =
2186 sme->crypto.ciphers_pairwise[0];
2187 priv->sec_info.authentication_mode = auth_type;
2190 if (sme->crypto.cipher_group) {
2191 priv->sec_info.encryption_mode = sme->crypto.cipher_group;
2192 priv->sec_info.authentication_mode = auth_type;
2195 ret = mwifiex_set_gen_ie(priv, sme->ie, sme->ie_len);
2198 if (mwifiex_is_alg_wep(priv->sec_info.encryption_mode)) {
2199 mwifiex_dbg(priv->adapter, INFO,
2200 "info: setting wep encryption\t"
2201 "with key len %d\n", sme->key_len);
2202 priv->wep_key_curr_index = sme->key_idx;
2203 ret = mwifiex_set_encode(priv, NULL, sme->key,
2204 sme->key_len, sme->key_idx,
2210 * Scan entries are valid for some time (15 sec). So we can save one
2211 * active scan time if we just try cfg80211_get_bss first. If it fails
2212 * then request scan and cfg80211_get_bss() again for final output.
2215 if (is_scanning_required) {
2216 /* Do specific SSID scanning */
2217 if (mwifiex_request_scan(priv, &req_ssid)) {
2218 mwifiex_dbg(priv->adapter, ERROR, "scan error\n");
2223 /* Find the BSS we want using available scan results */
2224 if (mode == NL80211_IFTYPE_ADHOC)
2225 bss = cfg80211_get_bss(priv->wdev.wiphy, channel,
2226 bssid, ssid, ssid_len,
2227 IEEE80211_BSS_TYPE_IBSS,
2228 IEEE80211_PRIVACY_ANY);
2230 bss = cfg80211_get_bss(priv->wdev.wiphy, channel,
2231 bssid, ssid, ssid_len,
2232 IEEE80211_BSS_TYPE_ESS,
2233 IEEE80211_PRIVACY_ANY);
2236 if (is_scanning_required) {
2237 mwifiex_dbg(priv->adapter, WARN,
2238 "assoc: requested bss not found in scan results\n");
2241 is_scanning_required = 1;
2243 mwifiex_dbg(priv->adapter, MSG,
2244 "info: trying to associate to '%.*s' bssid %pM\n",
2245 req_ssid.ssid_len, (char *)req_ssid.ssid,
2247 memcpy(&priv->cfg_bssid, bss->bssid, ETH_ALEN);
2252 ret = mwifiex_bss_start(priv, bss, &req_ssid);
2256 if (mode == NL80211_IFTYPE_ADHOC) {
2257 /* Inform the BSS information to kernel, otherwise
2258 * kernel will give a panic after successful assoc */
2259 if (mwifiex_cfg80211_inform_ibss_bss(priv))
2267 * CFG802.11 operation handler for association request.
2269 * This function does not work when the current mode is set to Ad-Hoc, or
2270 * when there is already an association procedure going on. The given BSS
2271 * information is used to associate.
2274 mwifiex_cfg80211_connect(struct wiphy *wiphy, struct net_device *dev,
2275 struct cfg80211_connect_params *sme)
2277 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
2278 struct mwifiex_adapter *adapter = priv->adapter;
2281 if (GET_BSS_ROLE(priv) != MWIFIEX_BSS_ROLE_STA) {
2282 mwifiex_dbg(adapter, ERROR,
2283 "%s: reject infra assoc request in non-STA role\n",
2288 if (priv->wdev.current_bss) {
2289 mwifiex_dbg(adapter, ERROR,
2290 "%s: already connected\n", dev->name);
2294 if (priv->scan_block)
2295 priv->scan_block = false;
2297 if (adapter->surprise_removed || adapter->is_cmd_timedout) {
2298 mwifiex_dbg(adapter, ERROR,
2299 "%s: Ignore connection.\t"
2300 "Card removed or FW in bad state\n",
2305 mwifiex_dbg(adapter, INFO,
2306 "info: Trying to associate to %.*s and bssid %pM\n",
2307 (int)sme->ssid_len, (char *)sme->ssid, sme->bssid);
2309 if (!mwifiex_stop_bg_scan(priv))
2310 cfg80211_sched_scan_stopped_rtnl(priv->wdev.wiphy);
2312 ret = mwifiex_cfg80211_assoc(priv, sme->ssid_len, sme->ssid, sme->bssid,
2313 priv->bss_mode, sme->channel, sme, 0);
2315 cfg80211_connect_result(priv->netdev, priv->cfg_bssid, NULL, 0,
2316 NULL, 0, WLAN_STATUS_SUCCESS,
2318 mwifiex_dbg(priv->adapter, MSG,
2319 "info: associated to bssid %pM successfully\n",
2321 if (ISSUPP_TDLS_ENABLED(priv->adapter->fw_cap_info) &&
2322 priv->adapter->auto_tdls &&
2323 priv->bss_type == MWIFIEX_BSS_TYPE_STA)
2324 mwifiex_setup_auto_tdls_timer(priv);
2326 mwifiex_dbg(priv->adapter, ERROR,
2327 "info: association to bssid %pM failed\n",
2329 eth_zero_addr(priv->cfg_bssid);
2332 cfg80211_connect_result(priv->netdev, priv->cfg_bssid,
2333 NULL, 0, NULL, 0, ret,
2336 cfg80211_connect_result(priv->netdev, priv->cfg_bssid,
2338 WLAN_STATUS_UNSPECIFIED_FAILURE,
2346 * This function sets following parameters for ibss network.
2350 * - secondary channel offset
2352 static int mwifiex_set_ibss_params(struct mwifiex_private *priv,
2353 struct cfg80211_ibss_params *params)
2355 struct mwifiex_adapter *adapter = priv->adapter;
2357 u8 config_bands = 0;
2359 if (params->chandef.chan->band == NL80211_BAND_2GHZ) {
2360 if (!params->basic_rates) {
2361 config_bands = BAND_B | BAND_G;
2363 for (i = 0; i < mwifiex_band_2ghz.n_bitrates; i++) {
2365 * Rates below 6 Mbps in the table are CCK
2366 * rates; 802.11b and from 6 they are OFDM;
2369 if (mwifiex_rates[i].bitrate == 60) {
2375 if (params->basic_rates < index) {
2376 config_bands = BAND_B;
2378 config_bands = BAND_G;
2379 if (params->basic_rates % index)
2380 config_bands |= BAND_B;
2384 if (cfg80211_get_chandef_type(¶ms->chandef) !=
2386 config_bands |= BAND_G | BAND_GN;
2388 if (cfg80211_get_chandef_type(¶ms->chandef) ==
2390 config_bands = BAND_A;
2392 config_bands = BAND_AN | BAND_A;
2395 if (!((config_bands | adapter->fw_bands) & ~adapter->fw_bands)) {
2396 adapter->config_bands = config_bands;
2397 adapter->adhoc_start_band = config_bands;
2399 if ((config_bands & BAND_GN) || (config_bands & BAND_AN))
2400 adapter->adhoc_11n_enabled = true;
2402 adapter->adhoc_11n_enabled = false;
2405 adapter->sec_chan_offset =
2406 mwifiex_chan_type_to_sec_chan_offset(
2407 cfg80211_get_chandef_type(¶ms->chandef));
2408 priv->adhoc_channel = ieee80211_frequency_to_channel(
2409 params->chandef.chan->center_freq);
2411 mwifiex_dbg(adapter, INFO,
2412 "info: set ibss band %d, chan %d, chan offset %d\n",
2413 config_bands, priv->adhoc_channel,
2414 adapter->sec_chan_offset);
2420 * CFG802.11 operation handler to join an IBSS.
2422 * This function does not work in any mode other than Ad-Hoc, or if
2423 * a join operation is already in progress.
2426 mwifiex_cfg80211_join_ibss(struct wiphy *wiphy, struct net_device *dev,
2427 struct cfg80211_ibss_params *params)
2429 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
2432 if (priv->bss_mode != NL80211_IFTYPE_ADHOC) {
2433 mwifiex_dbg(priv->adapter, ERROR,
2434 "request to join ibss received\t"
2435 "when station is not in ibss mode\n");
2439 mwifiex_dbg(priv->adapter, MSG,
2440 "info: trying to join to %.*s and bssid %pM\n",
2441 params->ssid_len, (char *)params->ssid, params->bssid);
2443 mwifiex_set_ibss_params(priv, params);
2445 ret = mwifiex_cfg80211_assoc(priv, params->ssid_len, params->ssid,
2446 params->bssid, priv->bss_mode,
2447 params->chandef.chan, NULL,
2451 cfg80211_ibss_joined(priv->netdev, priv->cfg_bssid,
2452 params->chandef.chan, GFP_KERNEL);
2453 mwifiex_dbg(priv->adapter, MSG,
2454 "info: joined/created adhoc network with bssid\t"
2455 "%pM successfully\n", priv->cfg_bssid);
2457 mwifiex_dbg(priv->adapter, ERROR,
2458 "info: failed creating/joining adhoc network\n");
2465 * CFG802.11 operation handler to leave an IBSS.
2467 * This function does not work if a leave operation is
2468 * already in progress.
2471 mwifiex_cfg80211_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
2473 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
2475 mwifiex_dbg(priv->adapter, MSG, "info: disconnecting from essid %pM\n",
2477 if (mwifiex_deauthenticate(priv, NULL))
2480 eth_zero_addr(priv->cfg_bssid);
2486 * CFG802.11 operation handler for scan request.
2488 * This function issues a scan request to the firmware based upon
2489 * the user specified scan configuration. On successful completion,
2490 * it also informs the results.
2493 mwifiex_cfg80211_scan(struct wiphy *wiphy,
2494 struct cfg80211_scan_request *request)
2496 struct net_device *dev = request->wdev->netdev;
2497 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
2499 struct ieee80211_channel *chan;
2500 struct ieee_types_header *ie;
2501 struct mwifiex_user_scan_cfg *user_scan_cfg;
2503 mwifiex_dbg(priv->adapter, CMD,
2504 "info: received scan request on %s\n", dev->name);
2506 /* Block scan request if scan operation or scan cleanup when interface
2507 * is disabled is in process
2509 if (priv->scan_request || priv->scan_aborting) {
2510 mwifiex_dbg(priv->adapter, WARN,
2511 "cmd: Scan already in process..\n");
2515 if (!priv->wdev.current_bss && priv->scan_block)
2516 priv->scan_block = false;
2518 if (!mwifiex_stop_bg_scan(priv))
2519 cfg80211_sched_scan_stopped_rtnl(priv->wdev.wiphy);
2521 user_scan_cfg = kzalloc(sizeof(*user_scan_cfg), GFP_KERNEL);
2525 priv->scan_request = request;
2527 if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) {
2528 ether_addr_copy(priv->random_mac, request->mac_addr);
2529 for (i = 0; i < ETH_ALEN; i++) {
2530 priv->random_mac[i] &= request->mac_addr_mask[i];
2531 priv->random_mac[i] |= get_random_int() &
2532 ~(request->mac_addr_mask[i]);
2534 ether_addr_copy(user_scan_cfg->random_mac, priv->random_mac);
2536 eth_zero_addr(priv->random_mac);
2539 user_scan_cfg->num_ssids = request->n_ssids;
2540 user_scan_cfg->ssid_list = request->ssids;
2542 if (request->ie && request->ie_len) {
2544 for (i = 0; i < MWIFIEX_MAX_VSIE_NUM; i++) {
2545 if (priv->vs_ie[i].mask != MWIFIEX_VSIE_MASK_CLEAR)
2547 priv->vs_ie[i].mask = MWIFIEX_VSIE_MASK_SCAN;
2548 ie = (struct ieee_types_header *)(request->ie + offset);
2549 memcpy(&priv->vs_ie[i].ie, ie, sizeof(*ie) + ie->len);
2550 offset += sizeof(*ie) + ie->len;
2552 if (offset >= request->ie_len)
2557 for (i = 0; i < min_t(u32, request->n_channels,
2558 MWIFIEX_USER_SCAN_CHAN_MAX); i++) {
2559 chan = request->channels[i];
2560 user_scan_cfg->chan_list[i].chan_number = chan->hw_value;
2561 user_scan_cfg->chan_list[i].radio_type = chan->band;
2563 if ((chan->flags & IEEE80211_CHAN_NO_IR) || !request->n_ssids)
2564 user_scan_cfg->chan_list[i].scan_type =
2565 MWIFIEX_SCAN_TYPE_PASSIVE;
2567 user_scan_cfg->chan_list[i].scan_type =
2568 MWIFIEX_SCAN_TYPE_ACTIVE;
2570 user_scan_cfg->chan_list[i].scan_time = 0;
2573 if (priv->adapter->scan_chan_gap_enabled &&
2574 mwifiex_is_any_intf_active(priv))
2575 user_scan_cfg->scan_chan_gap =
2576 priv->adapter->scan_chan_gap_time;
2578 ret = mwifiex_scan_networks(priv, user_scan_cfg);
2579 kfree(user_scan_cfg);
2581 mwifiex_dbg(priv->adapter, ERROR,
2582 "scan failed: %d\n", ret);
2583 priv->scan_aborting = false;
2584 priv->scan_request = NULL;
2588 if (request->ie && request->ie_len) {
2589 for (i = 0; i < MWIFIEX_MAX_VSIE_NUM; i++) {
2590 if (priv->vs_ie[i].mask == MWIFIEX_VSIE_MASK_SCAN) {
2591 priv->vs_ie[i].mask = MWIFIEX_VSIE_MASK_CLEAR;
2592 memset(&priv->vs_ie[i].ie, 0,
2593 MWIFIEX_MAX_VSIE_LEN);
2600 /* CFG802.11 operation handler for sched_scan_start.
2602 * This function issues a bgscan config request to the firmware based upon
2603 * the user specified sched_scan configuration. On successful completion,
2604 * firmware will generate BGSCAN_REPORT event, driver should issue bgscan
2605 * query command to get sched_scan results from firmware.
2608 mwifiex_cfg80211_sched_scan_start(struct wiphy *wiphy,
2609 struct net_device *dev,
2610 struct cfg80211_sched_scan_request *request)
2612 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
2614 struct ieee80211_channel *chan;
2615 struct mwifiex_bg_scan_cfg *bgscan_cfg;
2616 struct ieee_types_header *ie;
2618 if (!request || (!request->n_ssids && !request->n_match_sets)) {
2619 wiphy_err(wiphy, "%s : Invalid Sched_scan parameters",
2624 wiphy_info(wiphy, "sched_scan start : n_ssids=%d n_match_sets=%d ",
2625 request->n_ssids, request->n_match_sets);
2626 wiphy_info(wiphy, "n_channels=%d interval=%d ie_len=%d\n",
2627 request->n_channels, request->scan_plans->interval,
2628 (int)request->ie_len);
2630 bgscan_cfg = kzalloc(sizeof(*bgscan_cfg), GFP_KERNEL);
2634 if (priv->scan_request || priv->scan_aborting)
2635 bgscan_cfg->start_later = true;
2637 bgscan_cfg->num_ssids = request->n_match_sets;
2638 bgscan_cfg->ssid_list = request->match_sets;
2640 if (request->ie && request->ie_len) {
2642 for (i = 0; i < MWIFIEX_MAX_VSIE_NUM; i++) {
2643 if (priv->vs_ie[i].mask != MWIFIEX_VSIE_MASK_CLEAR)
2645 priv->vs_ie[i].mask = MWIFIEX_VSIE_MASK_BGSCAN;
2646 ie = (struct ieee_types_header *)(request->ie + offset);
2647 memcpy(&priv->vs_ie[i].ie, ie, sizeof(*ie) + ie->len);
2648 offset += sizeof(*ie) + ie->len;
2650 if (offset >= request->ie_len)
2655 for (i = 0; i < min_t(u32, request->n_channels,
2656 MWIFIEX_BG_SCAN_CHAN_MAX); i++) {
2657 chan = request->channels[i];
2658 bgscan_cfg->chan_list[i].chan_number = chan->hw_value;
2659 bgscan_cfg->chan_list[i].radio_type = chan->band;
2661 if ((chan->flags & IEEE80211_CHAN_NO_IR) || !request->n_ssids)
2662 bgscan_cfg->chan_list[i].scan_type =
2663 MWIFIEX_SCAN_TYPE_PASSIVE;
2665 bgscan_cfg->chan_list[i].scan_type =
2666 MWIFIEX_SCAN_TYPE_ACTIVE;
2668 bgscan_cfg->chan_list[i].scan_time = 0;
2671 bgscan_cfg->chan_per_scan = min_t(u32, request->n_channels,
2672 MWIFIEX_BG_SCAN_CHAN_MAX);
2674 /* Use at least 15 second for per scan cycle */
2675 bgscan_cfg->scan_interval = (request->scan_plans->interval >
2676 MWIFIEX_BGSCAN_INTERVAL) ?
2677 request->scan_plans->interval :
2678 MWIFIEX_BGSCAN_INTERVAL;
2680 bgscan_cfg->repeat_count = MWIFIEX_BGSCAN_REPEAT_COUNT;
2681 bgscan_cfg->report_condition = MWIFIEX_BGSCAN_SSID_MATCH |
2682 MWIFIEX_BGSCAN_WAIT_ALL_CHAN_DONE;
2683 bgscan_cfg->bss_type = MWIFIEX_BSS_MODE_INFRA;
2684 bgscan_cfg->action = MWIFIEX_BGSCAN_ACT_SET;
2685 bgscan_cfg->enable = true;
2686 if (request->min_rssi_thold != NL80211_SCAN_RSSI_THOLD_OFF) {
2687 bgscan_cfg->report_condition |= MWIFIEX_BGSCAN_SSID_RSSI_MATCH;
2688 bgscan_cfg->rssi_threshold = request->min_rssi_thold;
2691 if (mwifiex_send_cmd(priv, HostCmd_CMD_802_11_BG_SCAN_CONFIG,
2692 HostCmd_ACT_GEN_SET, 0, bgscan_cfg, true)) {
2697 priv->sched_scanning = true;
2703 /* CFG802.11 operation handler for sched_scan_stop.
2705 * This function issues a bgscan config command to disable
2706 * previous bgscan configuration in the firmware
2708 static int mwifiex_cfg80211_sched_scan_stop(struct wiphy *wiphy,
2709 struct net_device *dev)
2711 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
2713 wiphy_info(wiphy, "sched scan stop!");
2714 mwifiex_stop_bg_scan(priv);
2719 static void mwifiex_setup_vht_caps(struct ieee80211_sta_vht_cap *vht_info,
2720 struct mwifiex_private *priv)
2722 struct mwifiex_adapter *adapter = priv->adapter;
2724 vht_info->vht_supported = true;
2726 vht_info->cap = adapter->hw_dot_11ac_dev_cap;
2727 /* Update MCS support for VHT */
2728 vht_info->vht_mcs.rx_mcs_map = cpu_to_le16(
2729 adapter->hw_dot_11ac_mcs_support & 0xFFFF);
2730 vht_info->vht_mcs.rx_highest = 0;
2731 vht_info->vht_mcs.tx_mcs_map = cpu_to_le16(
2732 adapter->hw_dot_11ac_mcs_support >> 16);
2733 vht_info->vht_mcs.tx_highest = 0;
2737 * This function sets up the CFG802.11 specific HT capability fields
2738 * with default values.
2740 * The following default values are set -
2741 * - HT Supported = True
2742 * - Maximum AMPDU length factor = IEEE80211_HT_MAX_AMPDU_64K
2743 * - Minimum AMPDU spacing = IEEE80211_HT_MPDU_DENSITY_NONE
2744 * - HT Capabilities supported by firmware
2745 * - MCS information, Rx mask = 0xff
2746 * - MCD information, Tx parameters = IEEE80211_HT_MCS_TX_DEFINED (0x01)
2749 mwifiex_setup_ht_caps(struct ieee80211_sta_ht_cap *ht_info,
2750 struct mwifiex_private *priv)
2753 struct ieee80211_mcs_info mcs_set;
2754 u8 *mcs = (u8 *)&mcs_set;
2755 struct mwifiex_adapter *adapter = priv->adapter;
2757 ht_info->ht_supported = true;
2758 ht_info->ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
2759 ht_info->ampdu_density = IEEE80211_HT_MPDU_DENSITY_NONE;
2761 memset(&ht_info->mcs, 0, sizeof(ht_info->mcs));
2763 /* Fill HT capability information */
2764 if (ISSUPP_CHANWIDTH40(adapter->hw_dot_11n_dev_cap))
2765 ht_info->cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
2767 ht_info->cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
2769 if (ISSUPP_SHORTGI20(adapter->hw_dot_11n_dev_cap))
2770 ht_info->cap |= IEEE80211_HT_CAP_SGI_20;
2772 ht_info->cap &= ~IEEE80211_HT_CAP_SGI_20;
2774 if (ISSUPP_SHORTGI40(adapter->hw_dot_11n_dev_cap))
2775 ht_info->cap |= IEEE80211_HT_CAP_SGI_40;
2777 ht_info->cap &= ~IEEE80211_HT_CAP_SGI_40;
2779 if (adapter->user_dev_mcs_support == HT_STREAM_2X2)
2780 ht_info->cap |= 2 << IEEE80211_HT_CAP_RX_STBC_SHIFT;
2782 ht_info->cap |= 1 << IEEE80211_HT_CAP_RX_STBC_SHIFT;
2784 if (ISSUPP_TXSTBC(adapter->hw_dot_11n_dev_cap))
2785 ht_info->cap |= IEEE80211_HT_CAP_TX_STBC;
2787 ht_info->cap &= ~IEEE80211_HT_CAP_TX_STBC;
2789 if (ISSUPP_GREENFIELD(adapter->hw_dot_11n_dev_cap))
2790 ht_info->cap |= IEEE80211_HT_CAP_GRN_FLD;
2792 ht_info->cap &= ~IEEE80211_HT_CAP_GRN_FLD;
2794 if (ISENABLED_40MHZ_INTOLERANT(adapter->hw_dot_11n_dev_cap))
2795 ht_info->cap |= IEEE80211_HT_CAP_40MHZ_INTOLERANT;
2797 ht_info->cap &= ~IEEE80211_HT_CAP_40MHZ_INTOLERANT;
2799 if (ISSUPP_RXLDPC(adapter->hw_dot_11n_dev_cap))
2800 ht_info->cap |= IEEE80211_HT_CAP_LDPC_CODING;
2802 ht_info->cap &= ~IEEE80211_HT_CAP_LDPC_CODING;
2804 ht_info->cap &= ~IEEE80211_HT_CAP_MAX_AMSDU;
2805 ht_info->cap |= IEEE80211_HT_CAP_SM_PS;
2807 rx_mcs_supp = GET_RXMCSSUPP(adapter->user_dev_mcs_support);
2808 /* Set MCS for 1x1/2x2 */
2809 memset(mcs, 0xff, rx_mcs_supp);
2810 /* Clear all the other values */
2811 memset(&mcs[rx_mcs_supp], 0,
2812 sizeof(struct ieee80211_mcs_info) - rx_mcs_supp);
2813 if (priv->bss_mode == NL80211_IFTYPE_STATION ||
2814 ISSUPP_CHANWIDTH40(adapter->hw_dot_11n_dev_cap))
2815 /* Set MCS32 for infra mode or ad-hoc mode with 40MHz support */
2816 SETHT_MCS32(mcs_set.rx_mask);
2818 memcpy((u8 *) &ht_info->mcs, mcs, sizeof(struct ieee80211_mcs_info));
2820 ht_info->mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED;
2824 * create a new virtual interface with the given name and name assign type
2826 struct wireless_dev *mwifiex_add_virtual_intf(struct wiphy *wiphy,
2828 unsigned char name_assign_type,
2829 enum nl80211_iftype type,
2831 struct vif_params *params)
2833 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
2834 struct mwifiex_private *priv;
2835 struct net_device *dev;
2840 return ERR_PTR(-EFAULT);
2843 case NL80211_IFTYPE_UNSPECIFIED:
2844 case NL80211_IFTYPE_STATION:
2845 case NL80211_IFTYPE_ADHOC:
2846 if (adapter->curr_iface_comb.sta_intf ==
2847 adapter->iface_limit.sta_intf) {
2848 mwifiex_dbg(adapter, ERROR,
2849 "cannot create multiple sta/adhoc ifaces\n");
2850 return ERR_PTR(-EINVAL);
2853 priv = mwifiex_get_unused_priv_by_bss_type(
2854 adapter, MWIFIEX_BSS_TYPE_STA);
2856 mwifiex_dbg(adapter, ERROR,
2857 "could not get free private struct\n");
2858 return ERR_PTR(-EFAULT);
2861 priv->wdev.wiphy = wiphy;
2862 priv->wdev.iftype = NL80211_IFTYPE_STATION;
2864 if (type == NL80211_IFTYPE_UNSPECIFIED)
2865 priv->bss_mode = NL80211_IFTYPE_STATION;
2867 priv->bss_mode = type;
2869 priv->bss_type = MWIFIEX_BSS_TYPE_STA;
2870 priv->frame_type = MWIFIEX_DATA_FRAME_TYPE_ETH_II;
2871 priv->bss_priority = 0;
2872 priv->bss_role = MWIFIEX_BSS_ROLE_STA;
2875 case NL80211_IFTYPE_AP:
2876 if (adapter->curr_iface_comb.uap_intf ==
2877 adapter->iface_limit.uap_intf) {
2878 mwifiex_dbg(adapter, ERROR,
2879 "cannot create multiple AP ifaces\n");
2880 return ERR_PTR(-EINVAL);
2883 priv = mwifiex_get_unused_priv_by_bss_type(
2884 adapter, MWIFIEX_BSS_TYPE_UAP);
2886 mwifiex_dbg(adapter, ERROR,
2887 "could not get free private struct\n");
2888 return ERR_PTR(-EFAULT);
2891 priv->wdev.wiphy = wiphy;
2892 priv->wdev.iftype = NL80211_IFTYPE_AP;
2894 priv->bss_type = MWIFIEX_BSS_TYPE_UAP;
2895 priv->frame_type = MWIFIEX_DATA_FRAME_TYPE_ETH_II;
2896 priv->bss_priority = 0;
2897 priv->bss_role = MWIFIEX_BSS_ROLE_UAP;
2898 priv->bss_started = 0;
2899 priv->bss_mode = type;
2902 case NL80211_IFTYPE_P2P_CLIENT:
2903 if (adapter->curr_iface_comb.p2p_intf ==
2904 adapter->iface_limit.p2p_intf) {
2905 mwifiex_dbg(adapter, ERROR,
2906 "cannot create multiple P2P ifaces\n");
2907 return ERR_PTR(-EINVAL);
2910 priv = mwifiex_get_unused_priv_by_bss_type(
2911 adapter, MWIFIEX_BSS_TYPE_P2P);
2913 mwifiex_dbg(adapter, ERROR,
2914 "could not get free private struct\n");
2915 return ERR_PTR(-EFAULT);
2918 priv->wdev.wiphy = wiphy;
2919 /* At start-up, wpa_supplicant tries to change the interface
2920 * to NL80211_IFTYPE_STATION if it is not managed mode.
2922 priv->wdev.iftype = NL80211_IFTYPE_P2P_CLIENT;
2923 priv->bss_mode = NL80211_IFTYPE_P2P_CLIENT;
2925 /* Setting bss_type to P2P tells firmware that this interface
2926 * is receiving P2P peers found during find phase and doing
2927 * action frame handshake.
2929 priv->bss_type = MWIFIEX_BSS_TYPE_P2P;
2931 priv->frame_type = MWIFIEX_DATA_FRAME_TYPE_ETH_II;
2932 priv->bss_priority = MWIFIEX_BSS_ROLE_STA;
2933 priv->bss_role = MWIFIEX_BSS_ROLE_STA;
2934 priv->bss_started = 0;
2936 if (mwifiex_cfg80211_init_p2p_client(priv)) {
2937 memset(&priv->wdev, 0, sizeof(priv->wdev));
2938 priv->wdev.iftype = NL80211_IFTYPE_UNSPECIFIED;
2939 return ERR_PTR(-EFAULT);
2944 mwifiex_dbg(adapter, ERROR, "type not supported\n");
2945 return ERR_PTR(-EINVAL);
2948 dev = alloc_netdev_mqs(sizeof(struct mwifiex_private *), name,
2949 name_assign_type, ether_setup,
2950 IEEE80211_NUM_ACS, 1);
2952 mwifiex_dbg(adapter, ERROR,
2953 "no memory available for netdevice\n");
2954 memset(&priv->wdev, 0, sizeof(priv->wdev));
2955 priv->wdev.iftype = NL80211_IFTYPE_UNSPECIFIED;
2956 priv->bss_mode = NL80211_IFTYPE_UNSPECIFIED;
2957 return ERR_PTR(-ENOMEM);
2960 mwifiex_init_priv_params(priv, dev);
2963 ret = mwifiex_send_cmd(priv, HostCmd_CMD_SET_BSS_MODE,
2964 HostCmd_ACT_GEN_SET, 0, NULL, true);
2966 return ERR_PTR(ret);
2968 ret = mwifiex_sta_init_cmd(priv, false, false);
2970 return ERR_PTR(ret);
2972 mwifiex_setup_ht_caps(&wiphy->bands[NL80211_BAND_2GHZ]->ht_cap, priv);
2973 if (adapter->is_hw_11ac_capable)
2974 mwifiex_setup_vht_caps(
2975 &wiphy->bands[NL80211_BAND_2GHZ]->vht_cap, priv);
2977 if (adapter->config_bands & BAND_A)
2978 mwifiex_setup_ht_caps(
2979 &wiphy->bands[NL80211_BAND_5GHZ]->ht_cap, priv);
2981 if ((adapter->config_bands & BAND_A) && adapter->is_hw_11ac_capable)
2982 mwifiex_setup_vht_caps(
2983 &wiphy->bands[NL80211_BAND_5GHZ]->vht_cap, priv);
2985 dev_net_set(dev, wiphy_net(wiphy));
2986 dev->ieee80211_ptr = &priv->wdev;
2987 dev->ieee80211_ptr->iftype = priv->bss_mode;
2988 memcpy(dev->dev_addr, wiphy->perm_addr, ETH_ALEN);
2989 SET_NETDEV_DEV(dev, wiphy_dev(wiphy));
2991 dev->flags |= IFF_BROADCAST | IFF_MULTICAST;
2992 dev->watchdog_timeo = MWIFIEX_DEFAULT_WATCHDOG_TIMEOUT;
2993 dev->hard_header_len += MWIFIEX_MIN_DATA_HEADER_LEN;
2994 dev->ethtool_ops = &mwifiex_ethtool_ops;
2996 mdev_priv = netdev_priv(dev);
2997 *((unsigned long *) mdev_priv) = (unsigned long) priv;
2999 SET_NETDEV_DEV(dev, adapter->dev);
3001 /* Register network device */
3002 if (register_netdevice(dev)) {
3003 mwifiex_dbg(adapter, ERROR,
3004 "cannot register virtual network device\n");
3006 priv->bss_mode = NL80211_IFTYPE_UNSPECIFIED;
3007 priv->netdev = NULL;
3008 memset(&priv->wdev, 0, sizeof(priv->wdev));
3009 priv->wdev.iftype = NL80211_IFTYPE_UNSPECIFIED;
3010 return ERR_PTR(-EFAULT);
3013 priv->dfs_cac_workqueue = alloc_workqueue("MWIFIEX_DFS_CAC%s",
3016 WQ_UNBOUND, 1, name);
3017 if (!priv->dfs_cac_workqueue) {
3018 mwifiex_dbg(adapter, ERROR,
3019 "cannot register virtual network device\n");
3021 priv->bss_mode = NL80211_IFTYPE_UNSPECIFIED;
3022 priv->netdev = NULL;
3023 memset(&priv->wdev, 0, sizeof(priv->wdev));
3024 priv->wdev.iftype = NL80211_IFTYPE_UNSPECIFIED;
3025 return ERR_PTR(-ENOMEM);
3028 INIT_DELAYED_WORK(&priv->dfs_cac_work, mwifiex_dfs_cac_work_queue);
3030 priv->dfs_chan_sw_workqueue = alloc_workqueue("MWIFIEX_DFS_CHSW%s",
3031 WQ_HIGHPRI | WQ_UNBOUND |
3032 WQ_MEM_RECLAIM, 1, name);
3033 if (!priv->dfs_chan_sw_workqueue) {
3034 mwifiex_dbg(adapter, ERROR,
3035 "cannot register virtual network device\n");
3037 priv->bss_mode = NL80211_IFTYPE_UNSPECIFIED;
3038 priv->netdev = NULL;
3039 memset(&priv->wdev, 0, sizeof(priv->wdev));
3040 priv->wdev.iftype = NL80211_IFTYPE_UNSPECIFIED;
3041 return ERR_PTR(-ENOMEM);
3044 INIT_DELAYED_WORK(&priv->dfs_chan_sw_work,
3045 mwifiex_dfs_chan_sw_work_queue);
3047 sema_init(&priv->async_sem, 1);
3049 mwifiex_dbg(adapter, INFO,
3050 "info: %s: Marvell 802.11 Adapter\n", dev->name);
3052 #ifdef CONFIG_DEBUG_FS
3053 mwifiex_dev_debugfs_init(priv);
3057 case NL80211_IFTYPE_UNSPECIFIED:
3058 case NL80211_IFTYPE_STATION:
3059 case NL80211_IFTYPE_ADHOC:
3060 adapter->curr_iface_comb.sta_intf++;
3062 case NL80211_IFTYPE_AP:
3063 adapter->curr_iface_comb.uap_intf++;
3065 case NL80211_IFTYPE_P2P_CLIENT:
3066 adapter->curr_iface_comb.p2p_intf++;
3069 mwifiex_dbg(adapter, ERROR, "type not supported\n");
3070 return ERR_PTR(-EINVAL);
3075 EXPORT_SYMBOL_GPL(mwifiex_add_virtual_intf);
3078 * del_virtual_intf: remove the virtual interface determined by dev
3080 int mwifiex_del_virtual_intf(struct wiphy *wiphy, struct wireless_dev *wdev)
3082 struct mwifiex_private *priv = mwifiex_netdev_get_priv(wdev->netdev);
3083 struct mwifiex_adapter *adapter = priv->adapter;
3084 struct sk_buff *skb, *tmp;
3086 #ifdef CONFIG_DEBUG_FS
3087 mwifiex_dev_debugfs_remove(priv);
3090 if (priv->sched_scanning)
3091 priv->sched_scanning = false;
3093 mwifiex_stop_net_dev_queue(priv->netdev, adapter);
3095 skb_queue_walk_safe(&priv->bypass_txq, skb, tmp) {
3096 skb_unlink(skb, &priv->bypass_txq);
3097 mwifiex_write_data_complete(priv->adapter, skb, 0, -1);
3100 if (netif_carrier_ok(priv->netdev))
3101 netif_carrier_off(priv->netdev);
3103 if (wdev->netdev->reg_state == NETREG_REGISTERED)
3104 unregister_netdevice(wdev->netdev);
3106 if (priv->dfs_cac_workqueue) {
3107 flush_workqueue(priv->dfs_cac_workqueue);
3108 destroy_workqueue(priv->dfs_cac_workqueue);
3109 priv->dfs_cac_workqueue = NULL;
3112 if (priv->dfs_chan_sw_workqueue) {
3113 flush_workqueue(priv->dfs_chan_sw_workqueue);
3114 destroy_workqueue(priv->dfs_chan_sw_workqueue);
3115 priv->dfs_chan_sw_workqueue = NULL;
3117 /* Clear the priv in adapter */
3118 priv->netdev->ieee80211_ptr = NULL;
3119 priv->netdev = NULL;
3120 priv->wdev.iftype = NL80211_IFTYPE_UNSPECIFIED;
3122 priv->media_connected = false;
3124 switch (priv->bss_mode) {
3125 case NL80211_IFTYPE_UNSPECIFIED:
3126 case NL80211_IFTYPE_STATION:
3127 case NL80211_IFTYPE_ADHOC:
3128 adapter->curr_iface_comb.sta_intf--;
3130 case NL80211_IFTYPE_AP:
3131 adapter->curr_iface_comb.uap_intf--;
3133 case NL80211_IFTYPE_P2P_CLIENT:
3134 case NL80211_IFTYPE_P2P_GO:
3135 adapter->curr_iface_comb.p2p_intf--;
3138 mwifiex_dbg(adapter, ERROR,
3139 "del_virtual_intf: type not supported\n");
3143 priv->bss_mode = NL80211_IFTYPE_UNSPECIFIED;
3145 if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA ||
3146 GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_UAP)
3147 kfree(priv->hist_data);
3151 EXPORT_SYMBOL_GPL(mwifiex_del_virtual_intf);
3154 mwifiex_is_pattern_supported(struct cfg80211_pkt_pattern *pat, s8 *byte_seq,
3157 int j, k, valid_byte_cnt = 0;
3158 bool dont_care_byte = false;
3160 for (j = 0; j < DIV_ROUND_UP(pat->pattern_len, 8); j++) {
3161 for (k = 0; k < 8; k++) {
3162 if (pat->mask[j] & 1 << k) {
3163 memcpy(byte_seq + valid_byte_cnt,
3164 &pat->pattern[j * 8 + k], 1);
3170 dont_care_byte = true;
3173 /* wildcard bytes record as the offset
3174 * before the valid byte
3176 if (!valid_byte_cnt && !dont_care_byte)
3179 if (valid_byte_cnt > max_byte_seq)
3184 byte_seq[max_byte_seq] = valid_byte_cnt;
3190 static void mwifiex_set_auto_arp_mef_entry(struct mwifiex_private *priv,
3191 struct mwifiex_mef_entry *mef_entry)
3193 int i, filt_num = 0, num_ipv4 = 0;
3194 struct in_device *in_dev;
3195 struct in_ifaddr *ifa;
3196 __be32 ips[MWIFIEX_MAX_SUPPORTED_IPADDR];
3197 struct mwifiex_adapter *adapter = priv->adapter;
3199 mef_entry->mode = MEF_MODE_HOST_SLEEP;
3200 mef_entry->action = MEF_ACTION_AUTO_ARP;
3202 /* Enable ARP offload feature */
3203 memset(ips, 0, sizeof(ips));
3204 for (i = 0; i < MWIFIEX_MAX_BSS_NUM; i++) {
3205 if (adapter->priv[i]->netdev) {
3206 in_dev = __in_dev_get_rtnl(adapter->priv[i]->netdev);
3209 ifa = in_dev->ifa_list;
3210 if (!ifa || !ifa->ifa_local)
3212 ips[i] = ifa->ifa_local;
3217 for (i = 0; i < num_ipv4; i++) {
3220 mef_entry->filter[filt_num].repeat = 1;
3221 memcpy(mef_entry->filter[filt_num].byte_seq,
3222 (u8 *)&ips[i], sizeof(ips[i]));
3223 mef_entry->filter[filt_num].
3224 byte_seq[MWIFIEX_MEF_MAX_BYTESEQ] =
3226 mef_entry->filter[filt_num].offset = 46;
3227 mef_entry->filter[filt_num].filt_type = TYPE_EQ;
3229 mef_entry->filter[filt_num].filt_action =
3235 mef_entry->filter[filt_num].repeat = 1;
3236 mef_entry->filter[filt_num].byte_seq[0] = 0x08;
3237 mef_entry->filter[filt_num].byte_seq[1] = 0x06;
3238 mef_entry->filter[filt_num].byte_seq[MWIFIEX_MEF_MAX_BYTESEQ] = 2;
3239 mef_entry->filter[filt_num].offset = 20;
3240 mef_entry->filter[filt_num].filt_type = TYPE_EQ;
3241 mef_entry->filter[filt_num].filt_action = TYPE_AND;
3244 static int mwifiex_set_wowlan_mef_entry(struct mwifiex_private *priv,
3245 struct mwifiex_ds_mef_cfg *mef_cfg,
3246 struct mwifiex_mef_entry *mef_entry,
3247 struct cfg80211_wowlan *wowlan)
3249 int i, filt_num = 0, ret = 0;
3250 bool first_pat = true;
3251 u8 byte_seq[MWIFIEX_MEF_MAX_BYTESEQ + 1];
3252 const u8 ipv4_mc_mac[] = {0x33, 0x33};
3253 const u8 ipv6_mc_mac[] = {0x01, 0x00, 0x5e};
3255 mef_entry->mode = MEF_MODE_HOST_SLEEP;
3256 mef_entry->action = MEF_ACTION_ALLOW_AND_WAKEUP_HOST;
3258 for (i = 0; i < wowlan->n_patterns; i++) {
3259 memset(byte_seq, 0, sizeof(byte_seq));
3260 if (!mwifiex_is_pattern_supported(&wowlan->patterns[i],
3262 MWIFIEX_MEF_MAX_BYTESEQ)) {
3263 mwifiex_dbg(priv->adapter, ERROR,
3264 "Pattern not supported\n");
3268 if (!wowlan->patterns[i].pkt_offset) {
3269 if (!(byte_seq[0] & 0x01) &&
3270 (byte_seq[MWIFIEX_MEF_MAX_BYTESEQ] == 1)) {
3271 mef_cfg->criteria |= MWIFIEX_CRITERIA_UNICAST;
3273 } else if (is_broadcast_ether_addr(byte_seq)) {
3274 mef_cfg->criteria |= MWIFIEX_CRITERIA_BROADCAST;
3276 } else if ((!memcmp(byte_seq, ipv4_mc_mac, 2) &&
3277 (byte_seq[MWIFIEX_MEF_MAX_BYTESEQ] == 2)) ||
3278 (!memcmp(byte_seq, ipv6_mc_mac, 3) &&
3279 (byte_seq[MWIFIEX_MEF_MAX_BYTESEQ] == 3))) {
3280 mef_cfg->criteria |= MWIFIEX_CRITERIA_MULTICAST;
3284 mef_entry->filter[filt_num].repeat = 1;
3285 mef_entry->filter[filt_num].offset =
3286 wowlan->patterns[i].pkt_offset;
3287 memcpy(mef_entry->filter[filt_num].byte_seq, byte_seq,
3289 mef_entry->filter[filt_num].filt_type = TYPE_EQ;
3293 mwifiex_dbg(priv->adapter, INFO, "Wake on patterns\n");
3295 mef_entry->filter[filt_num].filt_action = TYPE_AND;
3301 if (wowlan->magic_pkt) {
3302 mef_cfg->criteria |= MWIFIEX_CRITERIA_UNICAST;
3303 mef_entry->filter[filt_num].repeat = 16;
3304 memcpy(mef_entry->filter[filt_num].byte_seq, priv->curr_addr,
3306 mef_entry->filter[filt_num].byte_seq[MWIFIEX_MEF_MAX_BYTESEQ] =
3308 mef_entry->filter[filt_num].offset = 28;
3309 mef_entry->filter[filt_num].filt_type = TYPE_EQ;
3311 mef_entry->filter[filt_num].filt_action = TYPE_OR;
3314 mef_entry->filter[filt_num].repeat = 16;
3315 memcpy(mef_entry->filter[filt_num].byte_seq, priv->curr_addr,
3317 mef_entry->filter[filt_num].byte_seq[MWIFIEX_MEF_MAX_BYTESEQ] =
3319 mef_entry->filter[filt_num].offset = 56;
3320 mef_entry->filter[filt_num].filt_type = TYPE_EQ;
3321 mef_entry->filter[filt_num].filt_action = TYPE_OR;
3322 mwifiex_dbg(priv->adapter, INFO, "Wake on magic packet\n");
3327 static int mwifiex_set_mef_filter(struct mwifiex_private *priv,
3328 struct cfg80211_wowlan *wowlan)
3330 int ret = 0, num_entries = 1;
3331 struct mwifiex_ds_mef_cfg mef_cfg;
3332 struct mwifiex_mef_entry *mef_entry;
3334 if (wowlan->n_patterns || wowlan->magic_pkt)
3337 mef_entry = kcalloc(num_entries, sizeof(*mef_entry), GFP_KERNEL);
3341 memset(&mef_cfg, 0, sizeof(mef_cfg));
3342 mef_cfg.criteria |= MWIFIEX_CRITERIA_BROADCAST |
3343 MWIFIEX_CRITERIA_UNICAST;
3344 mef_cfg.num_entries = num_entries;
3345 mef_cfg.mef_entry = mef_entry;
3347 mwifiex_set_auto_arp_mef_entry(priv, &mef_entry[0]);
3349 if (wowlan->n_patterns || wowlan->magic_pkt) {
3350 ret = mwifiex_set_wowlan_mef_entry(priv, &mef_cfg,
3351 &mef_entry[1], wowlan);
3356 if (!mef_cfg.criteria)
3357 mef_cfg.criteria = MWIFIEX_CRITERIA_BROADCAST |
3358 MWIFIEX_CRITERIA_UNICAST |
3359 MWIFIEX_CRITERIA_MULTICAST;
3361 ret = mwifiex_send_cmd(priv, HostCmd_CMD_MEF_CFG,
3362 HostCmd_ACT_GEN_SET, 0,
3370 static int mwifiex_cfg80211_suspend(struct wiphy *wiphy,
3371 struct cfg80211_wowlan *wowlan)
3373 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
3374 struct mwifiex_ds_hs_cfg hs_cfg;
3375 int i, ret = 0, retry_num = 10;
3376 struct mwifiex_private *priv;
3377 struct mwifiex_private *sta_priv =
3378 mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_STA);
3380 sta_priv->scan_aborting = true;
3381 for (i = 0; i < adapter->priv_num; i++) {
3382 priv = adapter->priv[i];
3383 mwifiex_abort_cac(priv);
3386 mwifiex_cancel_all_pending_cmd(adapter);
3388 for (i = 0; i < adapter->priv_num; i++) {
3389 priv = adapter->priv[i];
3390 if (priv && priv->netdev) {
3391 mwifiex_stop_net_dev_queue(priv->netdev, adapter);
3392 if (netif_carrier_ok(priv->netdev))
3393 netif_carrier_off(priv->netdev);
3397 for (i = 0; i < retry_num; i++) {
3398 if (!mwifiex_wmm_lists_empty(adapter) ||
3399 !mwifiex_bypass_txlist_empty(adapter) ||
3400 !skb_queue_empty(&adapter->tx_data_q))
3401 usleep_range(10000, 15000);
3407 mwifiex_dbg(adapter, ERROR,
3408 "None of the WOWLAN triggers enabled\n");
3413 if (!sta_priv->media_connected && !wowlan->nd_config) {
3414 mwifiex_dbg(adapter, ERROR,
3415 "Can not configure WOWLAN in disconnected state\n");
3420 ret = mwifiex_set_mef_filter(sta_priv, wowlan);
3422 mwifiex_dbg(adapter, ERROR, "Failed to set MEF filter\n");
3426 memset(&hs_cfg, 0, sizeof(hs_cfg));
3427 hs_cfg.conditions = le32_to_cpu(adapter->hs_cfg.conditions);
3429 if (wowlan->nd_config) {
3430 mwifiex_dbg(adapter, INFO, "Wake on net detect\n");
3431 hs_cfg.conditions |= HS_CFG_COND_MAC_EVENT;
3432 mwifiex_cfg80211_sched_scan_start(wiphy, sta_priv->netdev,
3436 if (wowlan->disconnect) {
3437 hs_cfg.conditions |= HS_CFG_COND_MAC_EVENT;
3438 mwifiex_dbg(sta_priv->adapter, INFO, "Wake on device disconnect\n");
3441 hs_cfg.is_invoke_hostcmd = false;
3442 hs_cfg.gpio = adapter->hs_cfg.gpio;
3443 hs_cfg.gap = adapter->hs_cfg.gap;
3444 ret = mwifiex_set_hs_params(sta_priv, HostCmd_ACT_GEN_SET,
3445 MWIFIEX_SYNC_CMD, &hs_cfg);
3447 mwifiex_dbg(adapter, ERROR, "Failed to set HS params\n");
3450 sta_priv->scan_aborting = false;
3454 static int mwifiex_cfg80211_resume(struct wiphy *wiphy)
3456 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
3457 struct mwifiex_private *priv;
3458 struct mwifiex_ds_wakeup_reason wakeup_reason;
3459 struct cfg80211_wowlan_wakeup wakeup_report;
3461 bool report_wakeup_reason = true;
3463 for (i = 0; i < adapter->priv_num; i++) {
3464 priv = adapter->priv[i];
3465 if (priv && priv->netdev) {
3466 if (!netif_carrier_ok(priv->netdev))
3467 netif_carrier_on(priv->netdev);
3468 mwifiex_wake_up_net_dev_queue(priv->netdev, adapter);
3472 if (!wiphy->wowlan_config)
3475 priv = mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_STA);
3476 mwifiex_get_wakeup_reason(priv, HostCmd_ACT_GEN_GET, MWIFIEX_SYNC_CMD,
3478 memset(&wakeup_report, 0, sizeof(struct cfg80211_wowlan_wakeup));
3480 wakeup_report.pattern_idx = -1;
3482 switch (wakeup_reason.hs_wakeup_reason) {
3483 case NO_HSWAKEUP_REASON:
3485 case BCAST_DATA_MATCHED:
3487 case MCAST_DATA_MATCHED:
3489 case UCAST_DATA_MATCHED:
3491 case MASKTABLE_EVENT_MATCHED:
3493 case NON_MASKABLE_EVENT_MATCHED:
3494 if (wiphy->wowlan_config->disconnect)
3495 wakeup_report.disconnect = true;
3496 if (wiphy->wowlan_config->nd_config)
3497 wakeup_report.net_detect = adapter->nd_info;
3499 case NON_MASKABLE_CONDITION_MATCHED:
3501 case MAGIC_PATTERN_MATCHED:
3502 if (wiphy->wowlan_config->magic_pkt)
3503 wakeup_report.magic_pkt = true;
3504 if (wiphy->wowlan_config->n_patterns)
3505 wakeup_report.pattern_idx = 1;
3507 case GTK_REKEY_FAILURE:
3508 if (wiphy->wowlan_config->gtk_rekey_failure)
3509 wakeup_report.gtk_rekey_failure = true;
3512 report_wakeup_reason = false;
3516 if (report_wakeup_reason)
3517 cfg80211_report_wowlan_wakeup(&priv->wdev, &wakeup_report,
3521 if (adapter->nd_info) {
3522 for (i = 0 ; i < adapter->nd_info->n_matches ; i++)
3523 kfree(adapter->nd_info->matches[i]);
3524 kfree(adapter->nd_info);
3525 adapter->nd_info = NULL;
3531 static void mwifiex_cfg80211_set_wakeup(struct wiphy *wiphy,
3534 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
3536 device_set_wakeup_enable(adapter->dev, enabled);
3539 static int mwifiex_set_rekey_data(struct wiphy *wiphy, struct net_device *dev,
3540 struct cfg80211_gtk_rekey_data *data)
3542 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
3544 return mwifiex_send_cmd(priv, HostCmd_CMD_GTK_REKEY_OFFLOAD_CFG,
3545 HostCmd_ACT_GEN_SET, 0, data, true);
3550 static int mwifiex_get_coalesce_pkt_type(u8 *byte_seq)
3552 const u8 ipv4_mc_mac[] = {0x33, 0x33};
3553 const u8 ipv6_mc_mac[] = {0x01, 0x00, 0x5e};
3554 const u8 bc_mac[] = {0xff, 0xff, 0xff, 0xff};
3556 if ((byte_seq[0] & 0x01) &&
3557 (byte_seq[MWIFIEX_COALESCE_MAX_BYTESEQ] == 1))
3558 return PACKET_TYPE_UNICAST;
3559 else if (!memcmp(byte_seq, bc_mac, 4))
3560 return PACKET_TYPE_BROADCAST;
3561 else if ((!memcmp(byte_seq, ipv4_mc_mac, 2) &&
3562 byte_seq[MWIFIEX_COALESCE_MAX_BYTESEQ] == 2) ||
3563 (!memcmp(byte_seq, ipv6_mc_mac, 3) &&
3564 byte_seq[MWIFIEX_COALESCE_MAX_BYTESEQ] == 3))
3565 return PACKET_TYPE_MULTICAST;
3571 mwifiex_fill_coalesce_rule_info(struct mwifiex_private *priv,
3572 struct cfg80211_coalesce_rules *crule,
3573 struct mwifiex_coalesce_rule *mrule)
3575 u8 byte_seq[MWIFIEX_COALESCE_MAX_BYTESEQ + 1];
3576 struct filt_field_param *param;
3579 mrule->max_coalescing_delay = crule->delay;
3581 param = mrule->params;
3583 for (i = 0; i < crule->n_patterns; i++) {
3584 memset(byte_seq, 0, sizeof(byte_seq));
3585 if (!mwifiex_is_pattern_supported(&crule->patterns[i],
3587 MWIFIEX_COALESCE_MAX_BYTESEQ)) {
3588 mwifiex_dbg(priv->adapter, ERROR,
3589 "Pattern not supported\n");
3593 if (!crule->patterns[i].pkt_offset) {
3596 pkt_type = mwifiex_get_coalesce_pkt_type(byte_seq);
3597 if (pkt_type && mrule->pkt_type) {
3598 mwifiex_dbg(priv->adapter, ERROR,
3599 "Multiple packet types not allowed\n");
3601 } else if (pkt_type) {
3602 mrule->pkt_type = pkt_type;
3607 if (crule->condition == NL80211_COALESCE_CONDITION_MATCH)
3608 param->operation = RECV_FILTER_MATCH_TYPE_EQ;
3610 param->operation = RECV_FILTER_MATCH_TYPE_NE;
3612 param->operand_len = byte_seq[MWIFIEX_COALESCE_MAX_BYTESEQ];
3613 memcpy(param->operand_byte_stream, byte_seq,
3614 param->operand_len);
3615 param->offset = crule->patterns[i].pkt_offset;
3618 mrule->num_of_fields++;
3621 if (!mrule->pkt_type) {
3622 mwifiex_dbg(priv->adapter, ERROR,
3623 "Packet type can not be determined\n");
3630 static int mwifiex_cfg80211_set_coalesce(struct wiphy *wiphy,
3631 struct cfg80211_coalesce *coalesce)
3633 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
3635 struct mwifiex_ds_coalesce_cfg coalesce_cfg;
3636 struct mwifiex_private *priv =
3637 mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_STA);
3639 memset(&coalesce_cfg, 0, sizeof(coalesce_cfg));
3641 mwifiex_dbg(adapter, WARN,
3642 "Disable coalesce and reset all previous rules\n");
3643 return mwifiex_send_cmd(priv, HostCmd_CMD_COALESCE_CFG,
3644 HostCmd_ACT_GEN_SET, 0,
3645 &coalesce_cfg, true);
3648 coalesce_cfg.num_of_rules = coalesce->n_rules;
3649 for (i = 0; i < coalesce->n_rules; i++) {
3650 ret = mwifiex_fill_coalesce_rule_info(priv, &coalesce->rules[i],
3651 &coalesce_cfg.rule[i]);
3653 mwifiex_dbg(adapter, ERROR,
3654 "Recheck the patterns provided for rule %d\n",
3660 return mwifiex_send_cmd(priv, HostCmd_CMD_COALESCE_CFG,
3661 HostCmd_ACT_GEN_SET, 0, &coalesce_cfg, true);
3664 /* cfg80211 ops handler for tdls_mgmt.
3665 * Function prepares TDLS action frame packets and forwards them to FW
3668 mwifiex_cfg80211_tdls_mgmt(struct wiphy *wiphy, struct net_device *dev,
3669 const u8 *peer, u8 action_code, u8 dialog_token,
3670 u16 status_code, u32 peer_capability,
3671 bool initiator, const u8 *extra_ies,
3672 size_t extra_ies_len)
3674 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
3677 if (!(wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS))
3680 /* make sure we are in station mode and connected */
3681 if (!(priv->bss_type == MWIFIEX_BSS_TYPE_STA && priv->media_connected))
3684 switch (action_code) {
3685 case WLAN_TDLS_SETUP_REQUEST:
3686 mwifiex_dbg(priv->adapter, MSG,
3687 "Send TDLS Setup Request to %pM status_code=%d\n",
3689 mwifiex_add_auto_tdls_peer(priv, peer);
3690 ret = mwifiex_send_tdls_data_frame(priv, peer, action_code,
3691 dialog_token, status_code,
3692 extra_ies, extra_ies_len);
3694 case WLAN_TDLS_SETUP_RESPONSE:
3695 mwifiex_add_auto_tdls_peer(priv, peer);
3696 mwifiex_dbg(priv->adapter, MSG,
3697 "Send TDLS Setup Response to %pM status_code=%d\n",
3699 ret = mwifiex_send_tdls_data_frame(priv, peer, action_code,
3700 dialog_token, status_code,
3701 extra_ies, extra_ies_len);
3703 case WLAN_TDLS_SETUP_CONFIRM:
3704 mwifiex_dbg(priv->adapter, MSG,
3705 "Send TDLS Confirm to %pM status_code=%d\n", peer,
3707 ret = mwifiex_send_tdls_data_frame(priv, peer, action_code,
3708 dialog_token, status_code,
3709 extra_ies, extra_ies_len);
3711 case WLAN_TDLS_TEARDOWN:
3712 mwifiex_dbg(priv->adapter, MSG,
3713 "Send TDLS Tear down to %pM\n", peer);
3714 ret = mwifiex_send_tdls_data_frame(priv, peer, action_code,
3715 dialog_token, status_code,
3716 extra_ies, extra_ies_len);
3718 case WLAN_TDLS_DISCOVERY_REQUEST:
3719 mwifiex_dbg(priv->adapter, MSG,
3720 "Send TDLS Discovery Request to %pM\n", peer);
3721 ret = mwifiex_send_tdls_data_frame(priv, peer, action_code,
3722 dialog_token, status_code,
3723 extra_ies, extra_ies_len);
3725 case WLAN_PUB_ACTION_TDLS_DISCOVER_RES:
3726 mwifiex_dbg(priv->adapter, MSG,
3727 "Send TDLS Discovery Response to %pM\n", peer);
3728 ret = mwifiex_send_tdls_action_frame(priv, peer, action_code,
3729 dialog_token, status_code,
3730 extra_ies, extra_ies_len);
3733 mwifiex_dbg(priv->adapter, ERROR,
3734 "Unknown TDLS mgmt/action frame %pM\n", peer);
3743 mwifiex_cfg80211_tdls_oper(struct wiphy *wiphy, struct net_device *dev,
3744 const u8 *peer, enum nl80211_tdls_operation action)
3746 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
3748 if (!(wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
3749 !(wiphy->flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP))
3752 /* make sure we are in station mode and connected */
3753 if (!(priv->bss_type == MWIFIEX_BSS_TYPE_STA && priv->media_connected))
3756 mwifiex_dbg(priv->adapter, MSG,
3757 "TDLS peer=%pM, oper=%d\n", peer, action);
3760 case NL80211_TDLS_ENABLE_LINK:
3761 action = MWIFIEX_TDLS_ENABLE_LINK;
3763 case NL80211_TDLS_DISABLE_LINK:
3764 action = MWIFIEX_TDLS_DISABLE_LINK;
3766 case NL80211_TDLS_TEARDOWN:
3767 /* shouldn't happen!*/
3768 mwifiex_dbg(priv->adapter, ERROR,
3769 "tdls_oper: teardown from driver not supported\n");
3771 case NL80211_TDLS_SETUP:
3772 /* shouldn't happen!*/
3773 mwifiex_dbg(priv->adapter, ERROR,
3774 "tdls_oper: setup from driver not supported\n");
3776 case NL80211_TDLS_DISCOVERY_REQ:
3777 /* shouldn't happen!*/
3778 mwifiex_dbg(priv->adapter, ERROR,
3779 "tdls_oper: discovery from driver not supported\n");
3782 mwifiex_dbg(priv->adapter, ERROR,
3783 "tdls_oper: operation not supported\n");
3787 return mwifiex_tdls_oper(priv, peer, action);
3791 mwifiex_cfg80211_tdls_chan_switch(struct wiphy *wiphy, struct net_device *dev,
3792 const u8 *addr, u8 oper_class,
3793 struct cfg80211_chan_def *chandef)
3795 struct mwifiex_sta_node *sta_ptr;
3796 unsigned long flags;
3798 u8 second_chan_offset, band;
3799 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
3801 spin_lock_irqsave(&priv->sta_list_spinlock, flags);
3802 sta_ptr = mwifiex_get_sta_entry(priv, addr);
3803 spin_unlock_irqrestore(&priv->sta_list_spinlock, flags);
3806 wiphy_err(wiphy, "%s: Invalid TDLS peer %pM\n",
3811 if (!(sta_ptr->tdls_cap.extcap.ext_capab[3] &
3812 WLAN_EXT_CAPA4_TDLS_CHAN_SWITCH)) {
3813 wiphy_err(wiphy, "%pM do not support tdls cs\n", addr);
3817 if (sta_ptr->tdls_status == TDLS_CHAN_SWITCHING ||
3818 sta_ptr->tdls_status == TDLS_IN_OFF_CHAN) {
3819 wiphy_err(wiphy, "channel switch is running, abort request\n");
3823 chan = chandef->chan->hw_value;
3824 second_chan_offset = mwifiex_get_sec_chan_offset(chan);
3825 band = chandef->chan->band;
3826 mwifiex_start_tdls_cs(priv, addr, chan, second_chan_offset, band);
3832 mwifiex_cfg80211_tdls_cancel_chan_switch(struct wiphy *wiphy,
3833 struct net_device *dev,
3836 struct mwifiex_sta_node *sta_ptr;
3837 unsigned long flags;
3838 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
3840 spin_lock_irqsave(&priv->sta_list_spinlock, flags);
3841 sta_ptr = mwifiex_get_sta_entry(priv, addr);
3842 spin_unlock_irqrestore(&priv->sta_list_spinlock, flags);
3845 wiphy_err(wiphy, "%s: Invalid TDLS peer %pM\n",
3847 } else if (!(sta_ptr->tdls_status == TDLS_CHAN_SWITCHING ||
3848 sta_ptr->tdls_status == TDLS_IN_BASE_CHAN ||
3849 sta_ptr->tdls_status == TDLS_IN_OFF_CHAN)) {
3850 wiphy_err(wiphy, "tdls chan switch not initialize by %pM\n",
3853 mwifiex_stop_tdls_cs(priv, addr);
3857 mwifiex_cfg80211_add_station(struct wiphy *wiphy, struct net_device *dev,
3858 const u8 *mac, struct station_parameters *params)
3860 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
3862 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
3865 /* make sure we are in station mode and connected */
3866 if ((priv->bss_type != MWIFIEX_BSS_TYPE_STA) || !priv->media_connected)
3869 return mwifiex_tdls_oper(priv, mac, MWIFIEX_TDLS_CREATE_LINK);
3873 mwifiex_cfg80211_channel_switch(struct wiphy *wiphy, struct net_device *dev,
3874 struct cfg80211_csa_settings *params)
3876 struct ieee_types_header *chsw_ie;
3877 struct ieee80211_channel_sw_ie *channel_sw;
3879 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
3881 if (priv->adapter->scan_processing) {
3882 mwifiex_dbg(priv->adapter, ERROR,
3883 "radar detection: scan in process...\n");
3887 if (priv->wdev.cac_started)
3890 if (cfg80211_chandef_identical(¶ms->chandef,
3891 &priv->dfs_chandef))
3894 chsw_ie = (void *)cfg80211_find_ie(WLAN_EID_CHANNEL_SWITCH,
3895 params->beacon_csa.tail,
3896 params->beacon_csa.tail_len);
3898 mwifiex_dbg(priv->adapter, ERROR,
3899 "Could not parse channel switch announcement IE\n");
3903 channel_sw = (void *)(chsw_ie + 1);
3904 if (channel_sw->mode) {
3905 if (netif_carrier_ok(priv->netdev))
3906 netif_carrier_off(priv->netdev);
3907 mwifiex_stop_net_dev_queue(priv->netdev, priv->adapter);
3910 if (mwifiex_del_mgmt_ies(priv))
3911 mwifiex_dbg(priv->adapter, ERROR,
3912 "Failed to delete mgmt IEs!\n");
3914 if (mwifiex_set_mgmt_ies(priv, ¶ms->beacon_csa)) {
3915 mwifiex_dbg(priv->adapter, ERROR,
3916 "%s: setting mgmt ies failed\n", __func__);
3920 memcpy(&priv->dfs_chandef, ¶ms->chandef, sizeof(priv->dfs_chandef));
3921 memcpy(&priv->beacon_after, ¶ms->beacon_after,
3922 sizeof(priv->beacon_after));
3924 chsw_msec = max(channel_sw->count * priv->bss_cfg.beacon_period, 100);
3925 queue_delayed_work(priv->dfs_chan_sw_workqueue, &priv->dfs_chan_sw_work,
3926 msecs_to_jiffies(chsw_msec));
3930 static int mwifiex_cfg80211_get_channel(struct wiphy *wiphy,
3931 struct wireless_dev *wdev,
3932 struct cfg80211_chan_def *chandef)
3934 struct mwifiex_private *priv = mwifiex_netdev_get_priv(wdev->netdev);
3935 struct mwifiex_bssdescriptor *curr_bss;
3936 struct ieee80211_channel *chan;
3937 u8 second_chan_offset;
3938 enum nl80211_channel_type chan_type;
3939 enum nl80211_band band;
3943 if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_UAP &&
3944 cfg80211_chandef_valid(&priv->bss_chandef)) {
3945 *chandef = priv->bss_chandef;
3947 } else if (priv->media_connected) {
3948 curr_bss = &priv->curr_bss_params.bss_descriptor;
3949 band = mwifiex_band_to_radio_type(priv->curr_bss_params.band);
3950 freq = ieee80211_channel_to_frequency(curr_bss->channel, band);
3951 chan = ieee80211_get_channel(wiphy, freq);
3953 if (priv->ht_param_present) {
3954 second_chan_offset = priv->assoc_resp_ht_param &
3955 IEEE80211_HT_PARAM_CHA_SEC_OFFSET;
3956 chan_type = mwifiex_sec_chan_offset_to_chan_type
3957 (second_chan_offset);
3958 cfg80211_chandef_create(chandef, chan, chan_type);
3960 cfg80211_chandef_create(chandef, chan,
3961 NL80211_CHAN_NO_HT);
3969 #ifdef CONFIG_NL80211_TESTMODE
3971 enum mwifiex_tm_attr {
3972 __MWIFIEX_TM_ATTR_INVALID = 0,
3973 MWIFIEX_TM_ATTR_CMD = 1,
3974 MWIFIEX_TM_ATTR_DATA = 2,
3977 __MWIFIEX_TM_ATTR_AFTER_LAST,
3978 MWIFIEX_TM_ATTR_MAX = __MWIFIEX_TM_ATTR_AFTER_LAST - 1,
3981 static const struct nla_policy mwifiex_tm_policy[MWIFIEX_TM_ATTR_MAX + 1] = {
3982 [MWIFIEX_TM_ATTR_CMD] = { .type = NLA_U32 },
3983 [MWIFIEX_TM_ATTR_DATA] = { .type = NLA_BINARY,
3984 .len = MWIFIEX_SIZE_OF_CMD_BUFFER },
3987 enum mwifiex_tm_command {
3988 MWIFIEX_TM_CMD_HOSTCMD = 0,
3991 static int mwifiex_tm_cmd(struct wiphy *wiphy, struct wireless_dev *wdev,
3992 void *data, int len)
3994 struct mwifiex_private *priv = mwifiex_netdev_get_priv(wdev->netdev);
3995 struct mwifiex_ds_misc_cmd *hostcmd;
3996 struct nlattr *tb[MWIFIEX_TM_ATTR_MAX + 1];
3997 struct mwifiex_adapter *adapter;
3998 struct sk_buff *skb;
4003 adapter = priv->adapter;
4005 err = nla_parse(tb, MWIFIEX_TM_ATTR_MAX, data, len,
4010 if (!tb[MWIFIEX_TM_ATTR_CMD])
4013 switch (nla_get_u32(tb[MWIFIEX_TM_ATTR_CMD])) {
4014 case MWIFIEX_TM_CMD_HOSTCMD:
4015 if (!tb[MWIFIEX_TM_ATTR_DATA])
4018 hostcmd = kzalloc(sizeof(*hostcmd), GFP_KERNEL);
4022 hostcmd->len = nla_len(tb[MWIFIEX_TM_ATTR_DATA]);
4023 memcpy(hostcmd->cmd, nla_data(tb[MWIFIEX_TM_ATTR_DATA]),
4026 if (mwifiex_send_cmd(priv, 0, 0, 0, hostcmd, true)) {
4027 dev_err(priv->adapter->dev, "Failed to process hostcmd\n");
4032 /* process hostcmd response*/
4033 skb = cfg80211_testmode_alloc_reply_skb(wiphy, hostcmd->len);
4038 err = nla_put(skb, MWIFIEX_TM_ATTR_DATA,
4039 hostcmd->len, hostcmd->cmd);
4046 err = cfg80211_testmode_reply(skb);
4056 mwifiex_cfg80211_start_radar_detection(struct wiphy *wiphy,
4057 struct net_device *dev,
4058 struct cfg80211_chan_def *chandef,
4061 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
4062 struct mwifiex_radar_params radar_params;
4064 if (priv->adapter->scan_processing) {
4065 mwifiex_dbg(priv->adapter, ERROR,
4066 "radar detection: scan already in process...\n");
4070 if (!mwifiex_is_11h_active(priv)) {
4071 mwifiex_dbg(priv->adapter, INFO,
4072 "Enable 11h extensions in FW\n");
4073 if (mwifiex_11h_activate(priv, true)) {
4074 mwifiex_dbg(priv->adapter, ERROR,
4075 "Failed to activate 11h extensions!!");
4078 priv->state_11h.is_11h_active = true;
4081 memset(&radar_params, 0, sizeof(struct mwifiex_radar_params));
4082 radar_params.chandef = chandef;
4083 radar_params.cac_time_ms = cac_time_ms;
4085 memcpy(&priv->dfs_chandef, chandef, sizeof(priv->dfs_chandef));
4087 if (mwifiex_send_cmd(priv, HostCmd_CMD_CHAN_REPORT_REQUEST,
4088 HostCmd_ACT_GEN_SET, 0, &radar_params, true))
4091 queue_delayed_work(priv->dfs_cac_workqueue, &priv->dfs_cac_work,
4092 msecs_to_jiffies(cac_time_ms));
4097 mwifiex_cfg80211_change_station(struct wiphy *wiphy, struct net_device *dev,
4099 struct station_parameters *params)
4102 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
4104 /* we support change_station handler only for TDLS peers*/
4105 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
4108 /* make sure we are in station mode and connected */
4109 if ((priv->bss_type != MWIFIEX_BSS_TYPE_STA) || !priv->media_connected)
4112 priv->sta_params = params;
4114 ret = mwifiex_tdls_oper(priv, mac, MWIFIEX_TDLS_CONFIG_LINK);
4115 priv->sta_params = NULL;
4120 /* station cfg80211 operations */
4121 static struct cfg80211_ops mwifiex_cfg80211_ops = {
4122 .add_virtual_intf = mwifiex_add_virtual_intf,
4123 .del_virtual_intf = mwifiex_del_virtual_intf,
4124 .change_virtual_intf = mwifiex_cfg80211_change_virtual_intf,
4125 .scan = mwifiex_cfg80211_scan,
4126 .connect = mwifiex_cfg80211_connect,
4127 .disconnect = mwifiex_cfg80211_disconnect,
4128 .get_station = mwifiex_cfg80211_get_station,
4129 .dump_station = mwifiex_cfg80211_dump_station,
4130 .dump_survey = mwifiex_cfg80211_dump_survey,
4131 .set_wiphy_params = mwifiex_cfg80211_set_wiphy_params,
4132 .join_ibss = mwifiex_cfg80211_join_ibss,
4133 .leave_ibss = mwifiex_cfg80211_leave_ibss,
4134 .add_key = mwifiex_cfg80211_add_key,
4135 .del_key = mwifiex_cfg80211_del_key,
4136 .set_default_mgmt_key = mwifiex_cfg80211_set_default_mgmt_key,
4137 .mgmt_tx = mwifiex_cfg80211_mgmt_tx,
4138 .mgmt_frame_register = mwifiex_cfg80211_mgmt_frame_register,
4139 .remain_on_channel = mwifiex_cfg80211_remain_on_channel,
4140 .cancel_remain_on_channel = mwifiex_cfg80211_cancel_remain_on_channel,
4141 .set_default_key = mwifiex_cfg80211_set_default_key,
4142 .set_power_mgmt = mwifiex_cfg80211_set_power_mgmt,
4143 .set_tx_power = mwifiex_cfg80211_set_tx_power,
4144 .get_tx_power = mwifiex_cfg80211_get_tx_power,
4145 .set_bitrate_mask = mwifiex_cfg80211_set_bitrate_mask,
4146 .start_ap = mwifiex_cfg80211_start_ap,
4147 .stop_ap = mwifiex_cfg80211_stop_ap,
4148 .change_beacon = mwifiex_cfg80211_change_beacon,
4149 .set_cqm_rssi_config = mwifiex_cfg80211_set_cqm_rssi_config,
4150 .set_antenna = mwifiex_cfg80211_set_antenna,
4151 .get_antenna = mwifiex_cfg80211_get_antenna,
4152 .del_station = mwifiex_cfg80211_del_station,
4153 .sched_scan_start = mwifiex_cfg80211_sched_scan_start,
4154 .sched_scan_stop = mwifiex_cfg80211_sched_scan_stop,
4156 .suspend = mwifiex_cfg80211_suspend,
4157 .resume = mwifiex_cfg80211_resume,
4158 .set_wakeup = mwifiex_cfg80211_set_wakeup,
4159 .set_rekey_data = mwifiex_set_rekey_data,
4161 .set_coalesce = mwifiex_cfg80211_set_coalesce,
4162 .tdls_mgmt = mwifiex_cfg80211_tdls_mgmt,
4163 .tdls_oper = mwifiex_cfg80211_tdls_oper,
4164 .tdls_channel_switch = mwifiex_cfg80211_tdls_chan_switch,
4165 .tdls_cancel_channel_switch = mwifiex_cfg80211_tdls_cancel_chan_switch,
4166 .add_station = mwifiex_cfg80211_add_station,
4167 .change_station = mwifiex_cfg80211_change_station,
4168 CFG80211_TESTMODE_CMD(mwifiex_tm_cmd)
4169 .get_channel = mwifiex_cfg80211_get_channel,
4170 .start_radar_detection = mwifiex_cfg80211_start_radar_detection,
4171 .channel_switch = mwifiex_cfg80211_channel_switch,
4175 static const struct wiphy_wowlan_support mwifiex_wowlan_support = {
4176 .flags = WIPHY_WOWLAN_MAGIC_PKT | WIPHY_WOWLAN_DISCONNECT |
4177 WIPHY_WOWLAN_NET_DETECT | WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
4178 WIPHY_WOWLAN_GTK_REKEY_FAILURE,
4179 .n_patterns = MWIFIEX_MEF_MAX_FILTERS,
4180 .pattern_min_len = 1,
4181 .pattern_max_len = MWIFIEX_MAX_PATTERN_LEN,
4182 .max_pkt_offset = MWIFIEX_MAX_OFFSET_LEN,
4183 .max_nd_match_sets = MWIFIEX_MAX_ND_MATCH_SETS,
4187 static bool mwifiex_is_valid_alpha2(const char *alpha2)
4189 if (!alpha2 || strlen(alpha2) != 2)
4192 if (isalpha(alpha2[0]) && isalpha(alpha2[1]))
4198 static const struct wiphy_coalesce_support mwifiex_coalesce_support = {
4199 .n_rules = MWIFIEX_COALESCE_MAX_RULES,
4200 .max_delay = MWIFIEX_MAX_COALESCING_DELAY,
4201 .n_patterns = MWIFIEX_COALESCE_MAX_FILTERS,
4202 .pattern_min_len = 1,
4203 .pattern_max_len = MWIFIEX_MAX_PATTERN_LEN,
4204 .max_pkt_offset = MWIFIEX_MAX_OFFSET_LEN,
4207 int mwifiex_init_channel_scan_gap(struct mwifiex_adapter *adapter)
4209 u32 n_channels_bg, n_channels_a = 0;
4211 n_channels_bg = mwifiex_band_2ghz.n_channels;
4213 if (adapter->config_bands & BAND_A)
4214 n_channels_a = mwifiex_band_5ghz.n_channels;
4216 adapter->num_in_chan_stats = n_channels_bg + n_channels_a;
4217 adapter->chan_stats = vmalloc(sizeof(*adapter->chan_stats) *
4218 adapter->num_in_chan_stats);
4220 if (!adapter->chan_stats)
4227 * This function registers the device with CFG802.11 subsystem.
4229 * The function creates the wireless device/wiphy, populates it with
4230 * default parameters and handler function pointers, and finally
4231 * registers the device.
4234 int mwifiex_register_cfg80211(struct mwifiex_adapter *adapter)
4238 struct wiphy *wiphy;
4239 struct mwifiex_private *priv = adapter->priv[MWIFIEX_BSS_TYPE_STA];
4243 /* create a new wiphy for use with cfg80211 */
4244 wiphy = wiphy_new(&mwifiex_cfg80211_ops,
4245 sizeof(struct mwifiex_adapter *));
4247 mwifiex_dbg(adapter, ERROR,
4248 "%s: creating new wiphy\n", __func__);
4251 wiphy->max_scan_ssids = MWIFIEX_MAX_SSID_LIST_LENGTH;
4252 wiphy->max_scan_ie_len = MWIFIEX_MAX_VSIE_LEN;
4253 wiphy->mgmt_stypes = mwifiex_mgmt_stypes;
4254 wiphy->max_remain_on_channel_duration = 5000;
4255 wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
4256 BIT(NL80211_IFTYPE_ADHOC) |
4257 BIT(NL80211_IFTYPE_P2P_CLIENT) |
4258 BIT(NL80211_IFTYPE_P2P_GO) |
4259 BIT(NL80211_IFTYPE_AP);
4261 wiphy->bands[NL80211_BAND_2GHZ] = &mwifiex_band_2ghz;
4262 if (adapter->config_bands & BAND_A)
4263 wiphy->bands[NL80211_BAND_5GHZ] = &mwifiex_band_5ghz;
4265 wiphy->bands[NL80211_BAND_5GHZ] = NULL;
4267 if (adapter->drcs_enabled && ISSUPP_DRCS_ENABLED(adapter->fw_cap_info))
4268 wiphy->iface_combinations = &mwifiex_iface_comb_ap_sta_drcs;
4269 else if (adapter->is_hw_11ac_capable)
4270 wiphy->iface_combinations = &mwifiex_iface_comb_ap_sta_vht;
4272 wiphy->iface_combinations = &mwifiex_iface_comb_ap_sta;
4273 wiphy->n_iface_combinations = 1;
4275 /* Initialize cipher suits */
4276 wiphy->cipher_suites = mwifiex_cipher_suites;
4277 wiphy->n_cipher_suites = ARRAY_SIZE(mwifiex_cipher_suites);
4279 if (adapter->regd) {
4280 wiphy->regulatory_flags |= REGULATORY_CUSTOM_REG |
4281 REGULATORY_DISABLE_BEACON_HINTS |
4282 REGULATORY_COUNTRY_IE_IGNORE;
4283 wiphy_apply_custom_regulatory(wiphy, adapter->regd);
4286 ether_addr_copy(wiphy->perm_addr, adapter->perm_addr);
4287 wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
4288 wiphy->flags |= WIPHY_FLAG_HAVE_AP_SME |
4289 WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD |
4290 WIPHY_FLAG_AP_UAPSD |
4291 WIPHY_FLAG_SUPPORTS_SCHED_SCAN |
4292 WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL |
4293 WIPHY_FLAG_HAS_CHANNEL_SWITCH |
4294 WIPHY_FLAG_PS_ON_BY_DEFAULT;
4296 if (ISSUPP_TDLS_ENABLED(adapter->fw_cap_info))
4297 wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS |
4298 WIPHY_FLAG_TDLS_EXTERNAL_SETUP;
4301 wiphy->wowlan = &mwifiex_wowlan_support;
4304 wiphy->coalesce = &mwifiex_coalesce_support;
4306 wiphy->probe_resp_offload = NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS |
4307 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2 |
4308 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P;
4310 wiphy->max_sched_scan_ssids = MWIFIEX_MAX_SSID_LIST_LENGTH;
4311 wiphy->max_sched_scan_ie_len = MWIFIEX_MAX_VSIE_LEN;
4312 wiphy->max_match_sets = MWIFIEX_MAX_SSID_LIST_LENGTH;
4314 wiphy->available_antennas_tx = BIT(adapter->number_of_antenna) - 1;
4315 wiphy->available_antennas_rx = BIT(adapter->number_of_antenna) - 1;
4317 wiphy->features |= NL80211_FEATURE_HT_IBSS |
4318 NL80211_FEATURE_INACTIVITY_TIMER |
4319 NL80211_FEATURE_LOW_PRIORITY_SCAN |
4320 NL80211_FEATURE_NEED_OBSS_SCAN |
4321 NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR |
4322 NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR |
4323 NL80211_FEATURE_ND_RANDOM_MAC_ADDR;
4325 if (ISSUPP_TDLS_ENABLED(adapter->fw_cap_info))
4326 wiphy->features |= NL80211_FEATURE_TDLS_CHANNEL_SWITCH;
4328 if (adapter->fw_api_ver == MWIFIEX_FW_V15)
4329 wiphy->features |= NL80211_FEATURE_SK_TX_STATUS;
4331 /* Reserve space for mwifiex specific private data for BSS */
4332 wiphy->bss_priv_size = sizeof(struct mwifiex_bss_priv);
4334 wiphy->reg_notifier = mwifiex_reg_notifier;
4336 /* Set struct mwifiex_adapter pointer in wiphy_priv */
4337 wdev_priv = wiphy_priv(wiphy);
4338 *(unsigned long *)wdev_priv = (unsigned long)adapter;
4340 set_wiphy_dev(wiphy, priv->adapter->dev);
4342 ret = wiphy_register(wiphy);
4344 mwifiex_dbg(adapter, ERROR,
4345 "%s: wiphy_register failed: %d\n", __func__, ret);
4350 if (!adapter->regd) {
4351 if (reg_alpha2 && mwifiex_is_valid_alpha2(reg_alpha2)) {
4352 mwifiex_dbg(adapter, INFO,
4353 "driver hint alpha2: %2.2s\n", reg_alpha2);
4354 regulatory_hint(wiphy, reg_alpha2);
4356 if (adapter->region_code == 0x00) {
4357 mwifiex_dbg(adapter, WARN,
4358 "Ignore world regulatory domain\n");
4360 wiphy->regulatory_flags |=
4361 REGULATORY_DISABLE_BEACON_HINTS |
4362 REGULATORY_COUNTRY_IE_IGNORE;
4364 mwifiex_11d_code_2_region(
4365 adapter->region_code);
4367 regulatory_hint(wiphy, country_code))
4368 mwifiex_dbg(priv->adapter, ERROR,
4369 "regulatory_hint() failed\n");
4374 mwifiex_send_cmd(priv, HostCmd_CMD_802_11_SNMP_MIB,
4375 HostCmd_ACT_GEN_GET, FRAG_THRESH_I, &thr, true);
4376 wiphy->frag_threshold = thr;
4377 mwifiex_send_cmd(priv, HostCmd_CMD_802_11_SNMP_MIB,
4378 HostCmd_ACT_GEN_GET, RTS_THRESH_I, &thr, true);
4379 wiphy->rts_threshold = thr;
4380 mwifiex_send_cmd(priv, HostCmd_CMD_802_11_SNMP_MIB,
4381 HostCmd_ACT_GEN_GET, SHORT_RETRY_LIM_I, &retry, true);
4382 wiphy->retry_short = (u8) retry;
4383 mwifiex_send_cmd(priv, HostCmd_CMD_802_11_SNMP_MIB,
4384 HostCmd_ACT_GEN_GET, LONG_RETRY_LIM_I, &retry, true);
4385 wiphy->retry_long = (u8) retry;
4387 adapter->wiphy = wiphy;