2 * Marvell Wireless LAN device driver: CFG80211
4 * Copyright (C) 2011-2014, Marvell International Ltd.
6 * This software file (the "File") is distributed by Marvell International
7 * Ltd. under the terms of the GNU General Public License Version 2, June 1991
8 * (the "License"). You may use, redistribute and/or modify this File in
9 * accordance with the terms and conditions of the License, a copy of which
10 * is available by writing to the Free Software Foundation, Inc.,
11 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA or on the
12 * worldwide web at http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
14 * THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE
16 * ARE EXPRESSLY DISCLAIMED. The License provides additional details about
17 * this warranty disclaimer.
25 static char *reg_alpha2;
26 module_param(reg_alpha2, charp, 0);
28 static const struct ieee80211_iface_limit mwifiex_ap_sta_limits[] = {
30 .max = 3, .types = BIT(NL80211_IFTYPE_STATION) |
31 BIT(NL80211_IFTYPE_P2P_GO) |
32 BIT(NL80211_IFTYPE_P2P_CLIENT) |
33 BIT(NL80211_IFTYPE_AP),
37 static const struct ieee80211_iface_combination
38 mwifiex_iface_comb_ap_sta = {
39 .limits = mwifiex_ap_sta_limits,
40 .num_different_channels = 1,
41 .n_limits = ARRAY_SIZE(mwifiex_ap_sta_limits),
42 .max_interfaces = MWIFIEX_MAX_BSS_NUM,
43 .beacon_int_infra_match = true,
44 .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
45 BIT(NL80211_CHAN_WIDTH_20) |
46 BIT(NL80211_CHAN_WIDTH_40),
49 static const struct ieee80211_iface_combination
50 mwifiex_iface_comb_ap_sta_vht = {
51 .limits = mwifiex_ap_sta_limits,
52 .num_different_channels = 1,
53 .n_limits = ARRAY_SIZE(mwifiex_ap_sta_limits),
54 .max_interfaces = MWIFIEX_MAX_BSS_NUM,
55 .beacon_int_infra_match = true,
56 .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
57 BIT(NL80211_CHAN_WIDTH_20) |
58 BIT(NL80211_CHAN_WIDTH_40) |
59 BIT(NL80211_CHAN_WIDTH_80),
63 ieee80211_iface_combination mwifiex_iface_comb_ap_sta_drcs = {
64 .limits = mwifiex_ap_sta_limits,
65 .num_different_channels = 2,
66 .n_limits = ARRAY_SIZE(mwifiex_ap_sta_limits),
67 .max_interfaces = MWIFIEX_MAX_BSS_NUM,
68 .beacon_int_infra_match = true,
72 * This function maps the nl802.11 channel type into driver channel type.
74 * The mapping is as follows -
75 * NL80211_CHAN_NO_HT -> IEEE80211_HT_PARAM_CHA_SEC_NONE
76 * NL80211_CHAN_HT20 -> IEEE80211_HT_PARAM_CHA_SEC_NONE
77 * NL80211_CHAN_HT40PLUS -> IEEE80211_HT_PARAM_CHA_SEC_ABOVE
78 * NL80211_CHAN_HT40MINUS -> IEEE80211_HT_PARAM_CHA_SEC_BELOW
79 * Others -> IEEE80211_HT_PARAM_CHA_SEC_NONE
81 u8 mwifiex_chan_type_to_sec_chan_offset(enum nl80211_channel_type chan_type)
84 case NL80211_CHAN_NO_HT:
85 case NL80211_CHAN_HT20:
86 return IEEE80211_HT_PARAM_CHA_SEC_NONE;
87 case NL80211_CHAN_HT40PLUS:
88 return IEEE80211_HT_PARAM_CHA_SEC_ABOVE;
89 case NL80211_CHAN_HT40MINUS:
90 return IEEE80211_HT_PARAM_CHA_SEC_BELOW;
92 return IEEE80211_HT_PARAM_CHA_SEC_NONE;
96 /* This function maps IEEE HT secondary channel type to NL80211 channel type
98 u8 mwifiex_sec_chan_offset_to_chan_type(u8 second_chan_offset)
100 switch (second_chan_offset) {
101 case IEEE80211_HT_PARAM_CHA_SEC_NONE:
102 return NL80211_CHAN_HT20;
103 case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
104 return NL80211_CHAN_HT40PLUS;
105 case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
106 return NL80211_CHAN_HT40MINUS;
108 return NL80211_CHAN_HT20;
113 * This function checks whether WEP is set.
116 mwifiex_is_alg_wep(u32 cipher)
119 case WLAN_CIPHER_SUITE_WEP40:
120 case WLAN_CIPHER_SUITE_WEP104:
130 * This function retrieves the private structure from kernel wiphy structure.
132 static void *mwifiex_cfg80211_get_adapter(struct wiphy *wiphy)
134 return (void *) (*(unsigned long *) wiphy_priv(wiphy));
138 * CFG802.11 operation handler to delete a network key.
141 mwifiex_cfg80211_del_key(struct wiphy *wiphy, struct net_device *netdev,
142 u8 key_index, bool pairwise, const u8 *mac_addr)
144 struct mwifiex_private *priv = mwifiex_netdev_get_priv(netdev);
145 const u8 bc_mac[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
146 const u8 *peer_mac = pairwise ? mac_addr : bc_mac;
148 if (mwifiex_set_encode(priv, NULL, NULL, 0, key_index, peer_mac, 1)) {
149 mwifiex_dbg(priv->adapter, ERROR, "deleting the crypto keys\n");
153 mwifiex_dbg(priv->adapter, INFO, "info: crypto keys deleted\n");
158 * This function forms an skb for management frame.
161 mwifiex_form_mgmt_frame(struct sk_buff *skb, const u8 *buf, size_t len)
163 u8 addr[ETH_ALEN] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
165 u32 tx_control = 0, pkt_type = PKT_TYPE_MGMT;
167 pkt_len = len + ETH_ALEN;
169 skb_reserve(skb, MWIFIEX_MIN_DATA_HEADER_LEN +
170 MWIFIEX_MGMT_FRAME_HEADER_SIZE + sizeof(pkt_len));
171 memcpy(skb_push(skb, sizeof(pkt_len)), &pkt_len, sizeof(pkt_len));
173 memcpy(skb_push(skb, sizeof(tx_control)),
174 &tx_control, sizeof(tx_control));
176 memcpy(skb_push(skb, sizeof(pkt_type)), &pkt_type, sizeof(pkt_type));
178 /* Add packet data and address4 */
179 memcpy(skb_put(skb, sizeof(struct ieee80211_hdr_3addr)), buf,
180 sizeof(struct ieee80211_hdr_3addr));
181 memcpy(skb_put(skb, ETH_ALEN), addr, ETH_ALEN);
182 memcpy(skb_put(skb, len - sizeof(struct ieee80211_hdr_3addr)),
183 buf + sizeof(struct ieee80211_hdr_3addr),
184 len - sizeof(struct ieee80211_hdr_3addr));
186 skb->priority = LOW_PRIO_TID;
187 __net_timestamp(skb);
193 * CFG802.11 operation handler to transmit a management frame.
196 mwifiex_cfg80211_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev,
197 struct cfg80211_mgmt_tx_params *params, u64 *cookie)
199 const u8 *buf = params->buf;
200 size_t len = params->len;
203 const struct ieee80211_mgmt *mgmt;
204 struct mwifiex_txinfo *tx_info;
205 struct mwifiex_private *priv = mwifiex_netdev_get_priv(wdev->netdev);
208 mwifiex_dbg(priv->adapter, ERROR, "invalid buffer and length\n");
212 mgmt = (const struct ieee80211_mgmt *)buf;
213 if (GET_BSS_ROLE(priv) != MWIFIEX_BSS_ROLE_STA &&
214 ieee80211_is_probe_resp(mgmt->frame_control)) {
215 /* Since we support offload probe resp, we need to skip probe
216 * resp in AP or GO mode */
217 mwifiex_dbg(priv->adapter, INFO,
218 "info: skip to send probe resp in AP or GO mode\n");
222 pkt_len = len + ETH_ALEN;
223 skb = dev_alloc_skb(MWIFIEX_MIN_DATA_HEADER_LEN +
224 MWIFIEX_MGMT_FRAME_HEADER_SIZE +
225 pkt_len + sizeof(pkt_len));
228 mwifiex_dbg(priv->adapter, ERROR,
229 "allocate skb failed for management frame\n");
233 tx_info = MWIFIEX_SKB_TXCB(skb);
234 memset(tx_info, 0, sizeof(*tx_info));
235 tx_info->bss_num = priv->bss_num;
236 tx_info->bss_type = priv->bss_type;
237 tx_info->pkt_len = pkt_len;
239 mwifiex_form_mgmt_frame(skb, buf, len);
240 *cookie = prandom_u32() | 1;
242 if (ieee80211_is_action(mgmt->frame_control))
243 skb = mwifiex_clone_skb_for_tx_status(priv,
245 MWIFIEX_BUF_FLAG_ACTION_TX_STATUS, cookie);
247 cfg80211_mgmt_tx_status(wdev, *cookie, buf, len, true,
250 mwifiex_queue_tx_pkt(priv, skb);
252 mwifiex_dbg(priv->adapter, INFO, "info: management frame transmitted\n");
257 * CFG802.11 operation handler to register a mgmt frame.
260 mwifiex_cfg80211_mgmt_frame_register(struct wiphy *wiphy,
261 struct wireless_dev *wdev,
262 u16 frame_type, bool reg)
264 struct mwifiex_private *priv = mwifiex_netdev_get_priv(wdev->netdev);
268 mask = priv->mgmt_frame_mask | BIT(frame_type >> 4);
270 mask = priv->mgmt_frame_mask & ~BIT(frame_type >> 4);
272 if (mask != priv->mgmt_frame_mask) {
273 priv->mgmt_frame_mask = mask;
274 mwifiex_send_cmd(priv, HostCmd_CMD_MGMT_FRAME_REG,
275 HostCmd_ACT_GEN_SET, 0,
276 &priv->mgmt_frame_mask, false);
277 mwifiex_dbg(priv->adapter, INFO, "info: mgmt frame registered\n");
282 * CFG802.11 operation handler to remain on channel.
285 mwifiex_cfg80211_remain_on_channel(struct wiphy *wiphy,
286 struct wireless_dev *wdev,
287 struct ieee80211_channel *chan,
288 unsigned int duration, u64 *cookie)
290 struct mwifiex_private *priv = mwifiex_netdev_get_priv(wdev->netdev);
293 if (!chan || !cookie) {
294 mwifiex_dbg(priv->adapter, ERROR, "Invalid parameter for ROC\n");
298 if (priv->roc_cfg.cookie) {
299 mwifiex_dbg(priv->adapter, INFO,
300 "info: ongoing ROC, cookie = 0x%llx\n",
301 priv->roc_cfg.cookie);
305 ret = mwifiex_remain_on_chan_cfg(priv, HostCmd_ACT_GEN_SET, chan,
309 *cookie = prandom_u32() | 1;
310 priv->roc_cfg.cookie = *cookie;
311 priv->roc_cfg.chan = *chan;
313 cfg80211_ready_on_channel(wdev, *cookie, chan,
314 duration, GFP_ATOMIC);
316 mwifiex_dbg(priv->adapter, INFO,
317 "info: ROC, cookie = 0x%llx\n", *cookie);
324 * CFG802.11 operation handler to cancel remain on channel.
327 mwifiex_cfg80211_cancel_remain_on_channel(struct wiphy *wiphy,
328 struct wireless_dev *wdev, u64 cookie)
330 struct mwifiex_private *priv = mwifiex_netdev_get_priv(wdev->netdev);
333 if (cookie != priv->roc_cfg.cookie)
336 ret = mwifiex_remain_on_chan_cfg(priv, HostCmd_ACT_GEN_REMOVE,
337 &priv->roc_cfg.chan, 0);
340 cfg80211_remain_on_channel_expired(wdev, cookie,
344 memset(&priv->roc_cfg, 0, sizeof(struct mwifiex_roc_cfg));
346 mwifiex_dbg(priv->adapter, INFO,
347 "info: cancel ROC, cookie = 0x%llx\n", cookie);
354 * CFG802.11 operation handler to set Tx power.
357 mwifiex_cfg80211_set_tx_power(struct wiphy *wiphy,
358 struct wireless_dev *wdev,
359 enum nl80211_tx_power_setting type,
362 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
363 struct mwifiex_private *priv;
364 struct mwifiex_power_cfg power_cfg;
365 int dbm = MBM_TO_DBM(mbm);
367 if (type == NL80211_TX_POWER_FIXED) {
368 power_cfg.is_power_auto = 0;
369 power_cfg.power_level = dbm;
371 power_cfg.is_power_auto = 1;
374 priv = mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY);
376 return mwifiex_set_tx_power(priv, &power_cfg);
380 * CFG802.11 operation handler to set Power Save option.
382 * The timeout value, if provided, is currently ignored.
385 mwifiex_cfg80211_set_power_mgmt(struct wiphy *wiphy,
386 struct net_device *dev,
387 bool enabled, int timeout)
389 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
393 mwifiex_dbg(priv->adapter, INFO,
394 "info: ignore timeout value for IEEE Power Save\n");
398 return mwifiex_drv_set_power(priv, &ps_mode);
402 * CFG802.11 operation handler to set the default network key.
405 mwifiex_cfg80211_set_default_key(struct wiphy *wiphy, struct net_device *netdev,
406 u8 key_index, bool unicast,
409 struct mwifiex_private *priv = mwifiex_netdev_get_priv(netdev);
411 /* Return if WEP key not configured */
412 if (!priv->sec_info.wep_enabled)
415 if (priv->bss_type == MWIFIEX_BSS_TYPE_UAP) {
416 priv->wep_key_curr_index = key_index;
417 } else if (mwifiex_set_encode(priv, NULL, NULL, 0, key_index,
419 mwifiex_dbg(priv->adapter, ERROR, "set default Tx key index\n");
427 * CFG802.11 operation handler to add a network key.
430 mwifiex_cfg80211_add_key(struct wiphy *wiphy, struct net_device *netdev,
431 u8 key_index, bool pairwise, const u8 *mac_addr,
432 struct key_params *params)
434 struct mwifiex_private *priv = mwifiex_netdev_get_priv(netdev);
435 struct mwifiex_wep_key *wep_key;
436 const u8 bc_mac[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
437 const u8 *peer_mac = pairwise ? mac_addr : bc_mac;
439 if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_UAP &&
440 (params->cipher == WLAN_CIPHER_SUITE_WEP40 ||
441 params->cipher == WLAN_CIPHER_SUITE_WEP104)) {
442 if (params->key && params->key_len) {
443 wep_key = &priv->wep_key[key_index];
444 memset(wep_key, 0, sizeof(struct mwifiex_wep_key));
445 memcpy(wep_key->key_material, params->key,
447 wep_key->key_index = key_index;
448 wep_key->key_length = params->key_len;
449 priv->sec_info.wep_enabled = 1;
454 if (mwifiex_set_encode(priv, params, params->key, params->key_len,
455 key_index, peer_mac, 0)) {
456 mwifiex_dbg(priv->adapter, ERROR, "crypto keys added\n");
464 * This function sends domain information to the firmware.
466 * The following information are passed to the firmware -
468 * - Sub bands (first channel, number of channels, maximum Tx power)
470 int mwifiex_send_domain_info_cmd_fw(struct wiphy *wiphy)
472 u8 no_of_triplet = 0;
473 struct ieee80211_country_ie_triplet *t;
474 u8 no_of_parsed_chan = 0;
475 u8 first_chan = 0, next_chan = 0, max_pwr = 0;
477 enum ieee80211_band band;
478 struct ieee80211_supported_band *sband;
479 struct ieee80211_channel *ch;
480 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
481 struct mwifiex_private *priv;
482 struct mwifiex_802_11d_domain_reg *domain_info = &adapter->domain_reg;
484 /* Set country code */
485 domain_info->country_code[0] = adapter->country_code[0];
486 domain_info->country_code[1] = adapter->country_code[1];
487 domain_info->country_code[2] = ' ';
489 band = mwifiex_band_to_radio_type(adapter->config_bands);
490 if (!wiphy->bands[band]) {
491 mwifiex_dbg(adapter, ERROR,
492 "11D: setting domain info in FW\n");
496 sband = wiphy->bands[band];
498 for (i = 0; i < sband->n_channels ; i++) {
499 ch = &sband->channels[i];
500 if (ch->flags & IEEE80211_CHAN_DISABLED)
505 first_chan = (u32) ch->hw_value;
506 next_chan = first_chan;
507 max_pwr = ch->max_power;
508 no_of_parsed_chan = 1;
512 if (ch->hw_value == next_chan + 1 &&
513 ch->max_power == max_pwr) {
517 t = &domain_info->triplet[no_of_triplet];
518 t->chans.first_channel = first_chan;
519 t->chans.num_channels = no_of_parsed_chan;
520 t->chans.max_power = max_pwr;
522 first_chan = (u32) ch->hw_value;
523 next_chan = first_chan;
524 max_pwr = ch->max_power;
525 no_of_parsed_chan = 1;
530 t = &domain_info->triplet[no_of_triplet];
531 t->chans.first_channel = first_chan;
532 t->chans.num_channels = no_of_parsed_chan;
533 t->chans.max_power = max_pwr;
537 domain_info->no_of_triplet = no_of_triplet;
539 priv = mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY);
541 if (mwifiex_send_cmd(priv, HostCmd_CMD_802_11D_DOMAIN_INFO,
542 HostCmd_ACT_GEN_SET, 0, NULL, false)) {
543 mwifiex_dbg(adapter, INFO,
544 "11D: setting domain info in FW\n");
552 * CFG802.11 regulatory domain callback function.
554 * This function is called when the regulatory domain is changed due to the
555 * following reasons -
557 * - Set by system core
559 * - Set bt Country IE
561 static void mwifiex_reg_notifier(struct wiphy *wiphy,
562 struct regulatory_request *request)
564 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
565 struct mwifiex_private *priv = mwifiex_get_priv(adapter,
566 MWIFIEX_BSS_ROLE_ANY);
567 mwifiex_dbg(adapter, INFO,
568 "info: cfg80211 regulatory domain callback for %c%c\n",
569 request->alpha2[0], request->alpha2[1]);
571 switch (request->initiator) {
572 case NL80211_REGDOM_SET_BY_DRIVER:
573 case NL80211_REGDOM_SET_BY_CORE:
574 case NL80211_REGDOM_SET_BY_USER:
575 case NL80211_REGDOM_SET_BY_COUNTRY_IE:
578 mwifiex_dbg(adapter, ERROR,
579 "unknown regdom initiator: %d\n",
584 /* Don't send world or same regdom info to firmware */
585 if (strncmp(request->alpha2, "00", 2) &&
586 strncmp(request->alpha2, adapter->country_code,
587 sizeof(request->alpha2))) {
588 memcpy(adapter->country_code, request->alpha2,
589 sizeof(request->alpha2));
590 mwifiex_send_domain_info_cmd_fw(wiphy);
591 mwifiex_dnld_txpwr_table(priv);
596 * This function sets the fragmentation threshold.
598 * The fragmentation threshold value must lie between MWIFIEX_FRAG_MIN_VALUE
599 * and MWIFIEX_FRAG_MAX_VALUE.
602 mwifiex_set_frag(struct mwifiex_private *priv, u32 frag_thr)
604 if (frag_thr < MWIFIEX_FRAG_MIN_VALUE ||
605 frag_thr > MWIFIEX_FRAG_MAX_VALUE)
606 frag_thr = MWIFIEX_FRAG_MAX_VALUE;
608 return mwifiex_send_cmd(priv, HostCmd_CMD_802_11_SNMP_MIB,
609 HostCmd_ACT_GEN_SET, FRAG_THRESH_I,
614 * This function sets the RTS threshold.
616 * The rts value must lie between MWIFIEX_RTS_MIN_VALUE
617 * and MWIFIEX_RTS_MAX_VALUE.
620 mwifiex_set_rts(struct mwifiex_private *priv, u32 rts_thr)
622 if (rts_thr < MWIFIEX_RTS_MIN_VALUE || rts_thr > MWIFIEX_RTS_MAX_VALUE)
623 rts_thr = MWIFIEX_RTS_MAX_VALUE;
625 return mwifiex_send_cmd(priv, HostCmd_CMD_802_11_SNMP_MIB,
626 HostCmd_ACT_GEN_SET, RTS_THRESH_I,
631 * CFG802.11 operation handler to set wiphy parameters.
633 * This function can be used to set the RTS threshold and the
634 * Fragmentation threshold of the driver.
637 mwifiex_cfg80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
639 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
640 struct mwifiex_private *priv;
641 struct mwifiex_uap_bss_param *bss_cfg;
644 priv = mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY);
646 switch (priv->bss_role) {
647 case MWIFIEX_BSS_ROLE_UAP:
648 if (priv->bss_started) {
649 mwifiex_dbg(adapter, ERROR,
650 "cannot change wiphy params when bss started");
654 bss_cfg = kzalloc(sizeof(*bss_cfg), GFP_KERNEL);
658 mwifiex_set_sys_config_invalid_data(bss_cfg);
660 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
661 bss_cfg->rts_threshold = wiphy->rts_threshold;
662 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
663 bss_cfg->frag_threshold = wiphy->frag_threshold;
664 if (changed & WIPHY_PARAM_RETRY_LONG)
665 bss_cfg->retry_limit = wiphy->retry_long;
667 ret = mwifiex_send_cmd(priv, HostCmd_CMD_UAP_SYS_CONFIG,
669 UAP_BSS_PARAMS_I, bss_cfg,
674 mwifiex_dbg(adapter, ERROR,
675 "Failed to set wiphy phy params\n");
680 case MWIFIEX_BSS_ROLE_STA:
681 if (priv->media_connected) {
682 mwifiex_dbg(adapter, ERROR,
683 "cannot change wiphy params when connected");
686 if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
687 ret = mwifiex_set_rts(priv,
688 wiphy->rts_threshold);
692 if (changed & WIPHY_PARAM_FRAG_THRESHOLD) {
693 ret = mwifiex_set_frag(priv,
694 wiphy->frag_threshold);
705 mwifiex_cfg80211_deinit_p2p(struct mwifiex_private *priv)
707 u16 mode = P2P_MODE_DISABLE;
709 if (mwifiex_send_cmd(priv, HostCmd_CMD_P2P_MODE_CFG,
710 HostCmd_ACT_GEN_SET, 0, &mode, true))
717 * This function initializes the functionalities for P2P client.
718 * The P2P client initialization sequence is:
719 * disable -> device -> client
722 mwifiex_cfg80211_init_p2p_client(struct mwifiex_private *priv)
726 if (mwifiex_cfg80211_deinit_p2p(priv))
729 mode = P2P_MODE_DEVICE;
730 if (mwifiex_send_cmd(priv, HostCmd_CMD_P2P_MODE_CFG,
731 HostCmd_ACT_GEN_SET, 0, &mode, true))
734 mode = P2P_MODE_CLIENT;
735 if (mwifiex_send_cmd(priv, HostCmd_CMD_P2P_MODE_CFG,
736 HostCmd_ACT_GEN_SET, 0, &mode, true))
743 * This function initializes the functionalities for P2P GO.
744 * The P2P GO initialization sequence is:
745 * disable -> device -> GO
748 mwifiex_cfg80211_init_p2p_go(struct mwifiex_private *priv)
752 if (mwifiex_cfg80211_deinit_p2p(priv))
755 mode = P2P_MODE_DEVICE;
756 if (mwifiex_send_cmd(priv, HostCmd_CMD_P2P_MODE_CFG,
757 HostCmd_ACT_GEN_SET, 0, &mode, true))
761 if (mwifiex_send_cmd(priv, HostCmd_CMD_P2P_MODE_CFG,
762 HostCmd_ACT_GEN_SET, 0, &mode, true))
768 static int mwifiex_deinit_priv_params(struct mwifiex_private *priv)
770 struct mwifiex_adapter *adapter = priv->adapter;
773 priv->mgmt_frame_mask = 0;
774 if (mwifiex_send_cmd(priv, HostCmd_CMD_MGMT_FRAME_REG,
775 HostCmd_ACT_GEN_SET, 0,
776 &priv->mgmt_frame_mask, false)) {
777 mwifiex_dbg(adapter, ERROR,
778 "could not unregister mgmt frame rx\n");
782 mwifiex_deauthenticate(priv, NULL);
784 spin_lock_irqsave(&adapter->main_proc_lock, flags);
785 adapter->main_locked = true;
786 if (adapter->mwifiex_processing) {
787 spin_unlock_irqrestore(&adapter->main_proc_lock, flags);
788 flush_workqueue(adapter->workqueue);
790 spin_unlock_irqrestore(&adapter->main_proc_lock, flags);
793 spin_lock_irqsave(&adapter->rx_proc_lock, flags);
794 adapter->rx_locked = true;
795 if (adapter->rx_processing) {
796 spin_unlock_irqrestore(&adapter->rx_proc_lock, flags);
797 flush_workqueue(adapter->rx_workqueue);
799 spin_unlock_irqrestore(&adapter->rx_proc_lock, flags);
802 mwifiex_free_priv(priv);
803 priv->wdev.iftype = NL80211_IFTYPE_UNSPECIFIED;
804 priv->bss_mode = NL80211_IFTYPE_UNSPECIFIED;
805 priv->sec_info.authentication_mode = NL80211_AUTHTYPE_OPEN_SYSTEM;
811 mwifiex_init_new_priv_params(struct mwifiex_private *priv,
812 struct net_device *dev,
813 enum nl80211_iftype type)
815 struct mwifiex_adapter *adapter = priv->adapter;
818 mwifiex_init_priv(priv);
820 priv->bss_mode = type;
821 priv->wdev.iftype = type;
823 mwifiex_init_priv_params(priv, priv->netdev);
824 priv->bss_started = 0;
827 case NL80211_IFTYPE_STATION:
828 case NL80211_IFTYPE_ADHOC:
829 priv->bss_num = mwifiex_get_unused_bss_num(adapter,
830 MWIFIEX_BSS_TYPE_STA);
831 priv->bss_role = MWIFIEX_BSS_ROLE_STA;
832 priv->bss_type = MWIFIEX_BSS_TYPE_STA;
834 case NL80211_IFTYPE_P2P_CLIENT:
835 priv->bss_num = mwifiex_get_unused_bss_num(adapter,
836 MWIFIEX_BSS_TYPE_P2P);
837 priv->bss_role = MWIFIEX_BSS_ROLE_STA;
838 priv->bss_type = MWIFIEX_BSS_TYPE_P2P;
840 case NL80211_IFTYPE_P2P_GO:
841 priv->bss_num = mwifiex_get_unused_bss_num(adapter,
842 MWIFIEX_BSS_TYPE_P2P);
843 priv->bss_role = MWIFIEX_BSS_ROLE_UAP;
844 priv->bss_type = MWIFIEX_BSS_TYPE_P2P;
846 case NL80211_IFTYPE_AP:
847 priv->bss_num = mwifiex_get_unused_bss_num(adapter,
848 MWIFIEX_BSS_TYPE_UAP);
849 priv->bss_type = MWIFIEX_BSS_TYPE_UAP;
850 priv->bss_role = MWIFIEX_BSS_ROLE_UAP;
853 mwifiex_dbg(adapter, ERROR,
854 "%s: changing to %d not supported\n",
859 spin_lock_irqsave(&adapter->main_proc_lock, flags);
860 adapter->main_locked = false;
861 spin_unlock_irqrestore(&adapter->main_proc_lock, flags);
863 spin_lock_irqsave(&adapter->rx_proc_lock, flags);
864 adapter->rx_locked = false;
865 spin_unlock_irqrestore(&adapter->rx_proc_lock, flags);
871 mwifiex_change_vif_to_p2p(struct net_device *dev,
872 enum nl80211_iftype curr_iftype,
873 enum nl80211_iftype type, u32 *flags,
874 struct vif_params *params)
876 struct mwifiex_private *priv;
877 struct mwifiex_adapter *adapter;
879 priv = mwifiex_netdev_get_priv(dev);
884 adapter = priv->adapter;
886 if (adapter->curr_iface_comb.p2p_intf ==
887 adapter->iface_limit.p2p_intf) {
888 mwifiex_dbg(adapter, ERROR,
889 "cannot create multiple P2P ifaces\n");
893 mwifiex_dbg(adapter, INFO,
894 "%s: changing role to p2p\n", dev->name);
896 if (mwifiex_deinit_priv_params(priv))
898 if (mwifiex_init_new_priv_params(priv, dev, type))
902 case NL80211_IFTYPE_P2P_CLIENT:
903 if (mwifiex_cfg80211_init_p2p_client(priv))
906 case NL80211_IFTYPE_P2P_GO:
907 if (mwifiex_cfg80211_init_p2p_go(priv))
911 mwifiex_dbg(adapter, ERROR,
912 "%s: changing to %d not supported\n",
917 if (mwifiex_send_cmd(priv, HostCmd_CMD_SET_BSS_MODE,
918 HostCmd_ACT_GEN_SET, 0, NULL, true))
921 if (mwifiex_sta_init_cmd(priv, false, false))
924 switch (curr_iftype) {
925 case NL80211_IFTYPE_STATION:
926 case NL80211_IFTYPE_ADHOC:
927 adapter->curr_iface_comb.sta_intf--;
929 case NL80211_IFTYPE_AP:
930 adapter->curr_iface_comb.uap_intf--;
936 adapter->curr_iface_comb.p2p_intf++;
937 dev->ieee80211_ptr->iftype = type;
943 mwifiex_change_vif_to_sta_adhoc(struct net_device *dev,
944 enum nl80211_iftype curr_iftype,
945 enum nl80211_iftype type, u32 *flags,
946 struct vif_params *params)
948 struct mwifiex_private *priv;
949 struct mwifiex_adapter *adapter;
951 priv = mwifiex_netdev_get_priv(dev);
956 adapter = priv->adapter;
958 if ((curr_iftype != NL80211_IFTYPE_P2P_CLIENT &&
959 curr_iftype != NL80211_IFTYPE_P2P_GO) &&
960 (adapter->curr_iface_comb.sta_intf ==
961 adapter->iface_limit.sta_intf)) {
962 mwifiex_dbg(adapter, ERROR,
963 "cannot create multiple station/adhoc ifaces\n");
967 if (type == NL80211_IFTYPE_STATION)
968 mwifiex_dbg(adapter, INFO,
969 "%s: changing role to station\n", dev->name);
971 mwifiex_dbg(adapter, INFO,
972 "%s: changing role to adhoc\n", dev->name);
974 if (mwifiex_deinit_priv_params(priv))
976 if (mwifiex_init_new_priv_params(priv, dev, type))
978 if (mwifiex_send_cmd(priv, HostCmd_CMD_SET_BSS_MODE,
979 HostCmd_ACT_GEN_SET, 0, NULL, true))
981 if (mwifiex_sta_init_cmd(priv, false, false))
984 switch (curr_iftype) {
985 case NL80211_IFTYPE_P2P_CLIENT:
986 case NL80211_IFTYPE_P2P_GO:
987 adapter->curr_iface_comb.p2p_intf--;
989 case NL80211_IFTYPE_AP:
990 adapter->curr_iface_comb.uap_intf--;
996 adapter->curr_iface_comb.sta_intf++;
997 dev->ieee80211_ptr->iftype = type;
1002 mwifiex_change_vif_to_ap(struct net_device *dev,
1003 enum nl80211_iftype curr_iftype,
1004 enum nl80211_iftype type, u32 *flags,
1005 struct vif_params *params)
1007 struct mwifiex_private *priv;
1008 struct mwifiex_adapter *adapter;
1010 priv = mwifiex_netdev_get_priv(dev);
1015 adapter = priv->adapter;
1017 if (adapter->curr_iface_comb.uap_intf ==
1018 adapter->iface_limit.uap_intf) {
1019 mwifiex_dbg(adapter, ERROR,
1020 "cannot create multiple AP ifaces\n");
1024 mwifiex_dbg(adapter, INFO,
1025 "%s: changing role to AP\n", dev->name);
1027 if (mwifiex_deinit_priv_params(priv))
1029 if (mwifiex_init_new_priv_params(priv, dev, type))
1031 if (mwifiex_send_cmd(priv, HostCmd_CMD_SET_BSS_MODE,
1032 HostCmd_ACT_GEN_SET, 0, NULL, true))
1034 if (mwifiex_sta_init_cmd(priv, false, false))
1037 switch (curr_iftype) {
1038 case NL80211_IFTYPE_P2P_CLIENT:
1039 case NL80211_IFTYPE_P2P_GO:
1040 adapter->curr_iface_comb.p2p_intf--;
1042 case NL80211_IFTYPE_STATION:
1043 case NL80211_IFTYPE_ADHOC:
1044 adapter->curr_iface_comb.sta_intf--;
1050 adapter->curr_iface_comb.uap_intf++;
1051 dev->ieee80211_ptr->iftype = type;
1055 * CFG802.11 operation handler to change interface type.
1058 mwifiex_cfg80211_change_virtual_intf(struct wiphy *wiphy,
1059 struct net_device *dev,
1060 enum nl80211_iftype type, u32 *flags,
1061 struct vif_params *params)
1063 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
1064 enum nl80211_iftype curr_iftype = dev->ieee80211_ptr->iftype;
1066 switch (curr_iftype) {
1067 case NL80211_IFTYPE_ADHOC:
1069 case NL80211_IFTYPE_STATION:
1070 priv->bss_mode = type;
1071 priv->sec_info.authentication_mode =
1072 NL80211_AUTHTYPE_OPEN_SYSTEM;
1073 dev->ieee80211_ptr->iftype = type;
1074 mwifiex_deauthenticate(priv, NULL);
1075 return mwifiex_send_cmd(priv, HostCmd_CMD_SET_BSS_MODE,
1076 HostCmd_ACT_GEN_SET, 0, NULL,
1078 case NL80211_IFTYPE_P2P_CLIENT:
1079 case NL80211_IFTYPE_P2P_GO:
1080 return mwifiex_change_vif_to_p2p(dev, curr_iftype,
1081 type, flags, params);
1082 case NL80211_IFTYPE_AP:
1083 return mwifiex_change_vif_to_ap(dev, curr_iftype, type,
1085 case NL80211_IFTYPE_UNSPECIFIED:
1086 mwifiex_dbg(priv->adapter, INFO,
1087 "%s: kept type as IBSS\n", dev->name);
1088 case NL80211_IFTYPE_ADHOC: /* This shouldn't happen */
1091 mwifiex_dbg(priv->adapter, ERROR,
1092 "%s: changing to %d not supported\n",
1097 case NL80211_IFTYPE_STATION:
1099 case NL80211_IFTYPE_ADHOC:
1100 priv->bss_mode = type;
1101 priv->sec_info.authentication_mode =
1102 NL80211_AUTHTYPE_OPEN_SYSTEM;
1103 dev->ieee80211_ptr->iftype = type;
1104 mwifiex_deauthenticate(priv, NULL);
1105 return mwifiex_send_cmd(priv, HostCmd_CMD_SET_BSS_MODE,
1106 HostCmd_ACT_GEN_SET, 0, NULL,
1108 case NL80211_IFTYPE_P2P_CLIENT:
1109 case NL80211_IFTYPE_P2P_GO:
1110 return mwifiex_change_vif_to_p2p(dev, curr_iftype,
1111 type, flags, params);
1112 case NL80211_IFTYPE_AP:
1113 return mwifiex_change_vif_to_ap(dev, curr_iftype, type,
1115 case NL80211_IFTYPE_UNSPECIFIED:
1116 mwifiex_dbg(priv->adapter, INFO,
1117 "%s: kept type as STA\n", dev->name);
1118 case NL80211_IFTYPE_STATION: /* This shouldn't happen */
1121 mwifiex_dbg(priv->adapter, ERROR,
1122 "%s: changing to %d not supported\n",
1127 case NL80211_IFTYPE_AP:
1129 case NL80211_IFTYPE_ADHOC:
1130 case NL80211_IFTYPE_STATION:
1131 return mwifiex_change_vif_to_sta_adhoc(dev, curr_iftype,
1135 case NL80211_IFTYPE_P2P_CLIENT:
1136 case NL80211_IFTYPE_P2P_GO:
1137 return mwifiex_change_vif_to_p2p(dev, curr_iftype,
1138 type, flags, params);
1139 case NL80211_IFTYPE_UNSPECIFIED:
1140 mwifiex_dbg(priv->adapter, INFO,
1141 "%s: kept type as AP\n", dev->name);
1142 case NL80211_IFTYPE_AP: /* This shouldn't happen */
1145 mwifiex_dbg(priv->adapter, ERROR,
1146 "%s: changing to %d not supported\n",
1151 case NL80211_IFTYPE_P2P_CLIENT:
1152 case NL80211_IFTYPE_P2P_GO:
1154 case NL80211_IFTYPE_STATION:
1155 if (mwifiex_cfg80211_deinit_p2p(priv))
1157 priv->adapter->curr_iface_comb.p2p_intf--;
1158 priv->adapter->curr_iface_comb.sta_intf++;
1159 dev->ieee80211_ptr->iftype = type;
1161 case NL80211_IFTYPE_ADHOC:
1162 if (mwifiex_cfg80211_deinit_p2p(priv))
1164 return mwifiex_change_vif_to_sta_adhoc(dev, curr_iftype,
1168 case NL80211_IFTYPE_AP:
1169 if (mwifiex_cfg80211_deinit_p2p(priv))
1171 return mwifiex_change_vif_to_ap(dev, curr_iftype, type,
1173 case NL80211_IFTYPE_UNSPECIFIED:
1174 mwifiex_dbg(priv->adapter, INFO,
1175 "%s: kept type as P2P\n", dev->name);
1176 case NL80211_IFTYPE_P2P_CLIENT:
1177 case NL80211_IFTYPE_P2P_GO:
1180 mwifiex_dbg(priv->adapter, ERROR,
1181 "%s: changing to %d not supported\n",
1187 mwifiex_dbg(priv->adapter, ERROR,
1188 "%s: unknown iftype: %d\n",
1189 dev->name, dev->ieee80211_ptr->iftype);
1198 mwifiex_parse_htinfo(struct mwifiex_private *priv, u8 tx_htinfo,
1199 struct rate_info *rate)
1201 struct mwifiex_adapter *adapter = priv->adapter;
1203 if (adapter->is_hw_11ac_capable) {
1204 /* bit[1-0]: 00=LG 01=HT 10=VHT */
1205 if (tx_htinfo & BIT(0)) {
1207 rate->mcs = priv->tx_rate;
1208 rate->flags |= RATE_INFO_FLAGS_MCS;
1210 if (tx_htinfo & BIT(1)) {
1212 rate->mcs = priv->tx_rate & 0x0F;
1213 rate->flags |= RATE_INFO_FLAGS_VHT_MCS;
1216 if (tx_htinfo & (BIT(1) | BIT(0))) {
1218 switch (tx_htinfo & (BIT(3) | BIT(2))) {
1220 rate->bw = RATE_INFO_BW_20;
1223 rate->bw = RATE_INFO_BW_40;
1226 rate->bw = RATE_INFO_BW_80;
1228 case (BIT(3) | BIT(2)):
1229 rate->bw = RATE_INFO_BW_160;
1233 if (tx_htinfo & BIT(4))
1234 rate->flags |= RATE_INFO_FLAGS_SHORT_GI;
1236 if ((priv->tx_rate >> 4) == 1)
1243 * Bit 0 in tx_htinfo indicates that current Tx rate
1244 * is 11n rate. Valid MCS index values for us are 0 to 15.
1246 if ((tx_htinfo & BIT(0)) && (priv->tx_rate < 16)) {
1247 rate->mcs = priv->tx_rate;
1248 rate->flags |= RATE_INFO_FLAGS_MCS;
1249 rate->bw = RATE_INFO_BW_20;
1250 if (tx_htinfo & BIT(1))
1251 rate->bw = RATE_INFO_BW_40;
1252 if (tx_htinfo & BIT(2))
1253 rate->flags |= RATE_INFO_FLAGS_SHORT_GI;
1259 * This function dumps the station information on a buffer.
1261 * The following information are shown -
1262 * - Total bytes transmitted
1263 * - Total bytes received
1264 * - Total packets transmitted
1265 * - Total packets received
1266 * - Signal quality level
1267 * - Transmission rate
1270 mwifiex_dump_station_info(struct mwifiex_private *priv,
1271 struct mwifiex_sta_node *node,
1272 struct station_info *sinfo)
1276 sinfo->filled = BIT(NL80211_STA_INFO_RX_BYTES) | BIT(NL80211_STA_INFO_TX_BYTES) |
1277 BIT(NL80211_STA_INFO_RX_PACKETS) | BIT(NL80211_STA_INFO_TX_PACKETS) |
1278 BIT(NL80211_STA_INFO_TX_BITRATE) |
1279 BIT(NL80211_STA_INFO_SIGNAL) | BIT(NL80211_STA_INFO_SIGNAL_AVG);
1281 if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_UAP) {
1285 sinfo->filled |= BIT(NL80211_STA_INFO_INACTIVE_TIME) |
1286 BIT(NL80211_STA_INFO_TX_FAILED);
1287 sinfo->inactive_time =
1288 jiffies_to_msecs(jiffies - node->stats.last_rx);
1290 sinfo->signal = node->stats.rssi;
1291 sinfo->signal_avg = node->stats.rssi;
1292 sinfo->rx_bytes = node->stats.rx_bytes;
1293 sinfo->tx_bytes = node->stats.tx_bytes;
1294 sinfo->rx_packets = node->stats.rx_packets;
1295 sinfo->tx_packets = node->stats.tx_packets;
1296 sinfo->tx_failed = node->stats.tx_failed;
1298 mwifiex_parse_htinfo(priv, node->stats.last_tx_htinfo,
1300 sinfo->txrate.legacy = node->stats.last_tx_rate * 5;
1305 /* Get signal information from the firmware */
1306 if (mwifiex_send_cmd(priv, HostCmd_CMD_RSSI_INFO,
1307 HostCmd_ACT_GEN_GET, 0, NULL, true)) {
1308 mwifiex_dbg(priv->adapter, ERROR,
1309 "failed to get signal information\n");
1313 if (mwifiex_drv_get_data_rate(priv, &rate)) {
1314 mwifiex_dbg(priv->adapter, ERROR,
1315 "getting data rate error\n");
1319 /* Get DTIM period information from firmware */
1320 mwifiex_send_cmd(priv, HostCmd_CMD_802_11_SNMP_MIB,
1321 HostCmd_ACT_GEN_GET, DTIM_PERIOD_I,
1322 &priv->dtim_period, true);
1324 mwifiex_parse_htinfo(priv, priv->tx_htinfo, &sinfo->txrate);
1326 sinfo->signal_avg = priv->bcn_rssi_avg;
1327 sinfo->rx_bytes = priv->stats.rx_bytes;
1328 sinfo->tx_bytes = priv->stats.tx_bytes;
1329 sinfo->rx_packets = priv->stats.rx_packets;
1330 sinfo->tx_packets = priv->stats.tx_packets;
1331 sinfo->signal = priv->bcn_rssi_avg;
1332 /* bit rate is in 500 kb/s units. Convert it to 100kb/s units */
1333 sinfo->txrate.legacy = rate * 5;
1335 if (priv->bss_mode == NL80211_IFTYPE_STATION) {
1336 sinfo->filled |= BIT(NL80211_STA_INFO_BSS_PARAM);
1337 sinfo->bss_param.flags = 0;
1338 if (priv->curr_bss_params.bss_descriptor.cap_info_bitmap &
1339 WLAN_CAPABILITY_SHORT_PREAMBLE)
1340 sinfo->bss_param.flags |=
1341 BSS_PARAM_FLAGS_SHORT_PREAMBLE;
1342 if (priv->curr_bss_params.bss_descriptor.cap_info_bitmap &
1343 WLAN_CAPABILITY_SHORT_SLOT_TIME)
1344 sinfo->bss_param.flags |=
1345 BSS_PARAM_FLAGS_SHORT_SLOT_TIME;
1346 sinfo->bss_param.dtim_period = priv->dtim_period;
1347 sinfo->bss_param.beacon_interval =
1348 priv->curr_bss_params.bss_descriptor.beacon_period;
1355 * CFG802.11 operation handler to get station information.
1357 * This function only works in connected mode, and dumps the
1358 * requested station information, if available.
1361 mwifiex_cfg80211_get_station(struct wiphy *wiphy, struct net_device *dev,
1362 const u8 *mac, struct station_info *sinfo)
1364 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
1366 if (!priv->media_connected)
1368 if (memcmp(mac, priv->cfg_bssid, ETH_ALEN))
1371 return mwifiex_dump_station_info(priv, NULL, sinfo);
1375 * CFG802.11 operation handler to dump station information.
1378 mwifiex_cfg80211_dump_station(struct wiphy *wiphy, struct net_device *dev,
1379 int idx, u8 *mac, struct station_info *sinfo)
1381 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
1382 static struct mwifiex_sta_node *node;
1384 if ((GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA) &&
1385 priv->media_connected && idx == 0) {
1386 ether_addr_copy(mac, priv->cfg_bssid);
1387 return mwifiex_dump_station_info(priv, NULL, sinfo);
1388 } else if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_UAP) {
1389 mwifiex_send_cmd(priv, HOST_CMD_APCMD_STA_LIST,
1390 HostCmd_ACT_GEN_GET, 0, NULL, true);
1392 if (node && (&node->list == &priv->sta_list)) {
1397 node = list_prepare_entry(node, &priv->sta_list, list);
1398 list_for_each_entry_continue(node, &priv->sta_list, list) {
1399 ether_addr_copy(mac, node->mac_addr);
1400 return mwifiex_dump_station_info(priv, node, sinfo);
1408 mwifiex_cfg80211_dump_survey(struct wiphy *wiphy, struct net_device *dev,
1409 int idx, struct survey_info *survey)
1411 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
1412 struct mwifiex_chan_stats *pchan_stats = priv->adapter->chan_stats;
1413 enum ieee80211_band band;
1415 mwifiex_dbg(priv->adapter, DUMP, "dump_survey idx=%d\n", idx);
1417 memset(survey, 0, sizeof(struct survey_info));
1419 if ((GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA) &&
1420 priv->media_connected && idx == 0) {
1421 u8 curr_bss_band = priv->curr_bss_params.band;
1422 u32 chan = priv->curr_bss_params.bss_descriptor.channel;
1424 band = mwifiex_band_to_radio_type(curr_bss_band);
1425 survey->channel = ieee80211_get_channel(wiphy,
1426 ieee80211_channel_to_frequency(chan, band));
1428 if (priv->bcn_nf_last) {
1429 survey->filled = SURVEY_INFO_NOISE_DBM;
1430 survey->noise = priv->bcn_nf_last;
1435 if (idx >= priv->adapter->num_in_chan_stats)
1438 if (!pchan_stats[idx].cca_scan_dur)
1441 band = pchan_stats[idx].bandcfg;
1442 survey->channel = ieee80211_get_channel(wiphy,
1443 ieee80211_channel_to_frequency(pchan_stats[idx].chan_num, band));
1444 survey->filled = SURVEY_INFO_NOISE_DBM |
1446 SURVEY_INFO_TIME_BUSY;
1447 survey->noise = pchan_stats[idx].noise;
1448 survey->time = pchan_stats[idx].cca_scan_dur;
1449 survey->time_busy = pchan_stats[idx].cca_busy_dur;
1454 /* Supported rates to be advertised to the cfg80211 */
1455 static struct ieee80211_rate mwifiex_rates[] = {
1456 {.bitrate = 10, .hw_value = 2, },
1457 {.bitrate = 20, .hw_value = 4, },
1458 {.bitrate = 55, .hw_value = 11, },
1459 {.bitrate = 110, .hw_value = 22, },
1460 {.bitrate = 60, .hw_value = 12, },
1461 {.bitrate = 90, .hw_value = 18, },
1462 {.bitrate = 120, .hw_value = 24, },
1463 {.bitrate = 180, .hw_value = 36, },
1464 {.bitrate = 240, .hw_value = 48, },
1465 {.bitrate = 360, .hw_value = 72, },
1466 {.bitrate = 480, .hw_value = 96, },
1467 {.bitrate = 540, .hw_value = 108, },
1470 /* Channel definitions to be advertised to cfg80211 */
1471 static struct ieee80211_channel mwifiex_channels_2ghz[] = {
1472 {.center_freq = 2412, .hw_value = 1, },
1473 {.center_freq = 2417, .hw_value = 2, },
1474 {.center_freq = 2422, .hw_value = 3, },
1475 {.center_freq = 2427, .hw_value = 4, },
1476 {.center_freq = 2432, .hw_value = 5, },
1477 {.center_freq = 2437, .hw_value = 6, },
1478 {.center_freq = 2442, .hw_value = 7, },
1479 {.center_freq = 2447, .hw_value = 8, },
1480 {.center_freq = 2452, .hw_value = 9, },
1481 {.center_freq = 2457, .hw_value = 10, },
1482 {.center_freq = 2462, .hw_value = 11, },
1483 {.center_freq = 2467, .hw_value = 12, },
1484 {.center_freq = 2472, .hw_value = 13, },
1485 {.center_freq = 2484, .hw_value = 14, },
1488 static struct ieee80211_supported_band mwifiex_band_2ghz = {
1489 .channels = mwifiex_channels_2ghz,
1490 .n_channels = ARRAY_SIZE(mwifiex_channels_2ghz),
1491 .bitrates = mwifiex_rates,
1492 .n_bitrates = ARRAY_SIZE(mwifiex_rates),
1495 static struct ieee80211_channel mwifiex_channels_5ghz[] = {
1496 {.center_freq = 5040, .hw_value = 8, },
1497 {.center_freq = 5060, .hw_value = 12, },
1498 {.center_freq = 5080, .hw_value = 16, },
1499 {.center_freq = 5170, .hw_value = 34, },
1500 {.center_freq = 5190, .hw_value = 38, },
1501 {.center_freq = 5210, .hw_value = 42, },
1502 {.center_freq = 5230, .hw_value = 46, },
1503 {.center_freq = 5180, .hw_value = 36, },
1504 {.center_freq = 5200, .hw_value = 40, },
1505 {.center_freq = 5220, .hw_value = 44, },
1506 {.center_freq = 5240, .hw_value = 48, },
1507 {.center_freq = 5260, .hw_value = 52, },
1508 {.center_freq = 5280, .hw_value = 56, },
1509 {.center_freq = 5300, .hw_value = 60, },
1510 {.center_freq = 5320, .hw_value = 64, },
1511 {.center_freq = 5500, .hw_value = 100, },
1512 {.center_freq = 5520, .hw_value = 104, },
1513 {.center_freq = 5540, .hw_value = 108, },
1514 {.center_freq = 5560, .hw_value = 112, },
1515 {.center_freq = 5580, .hw_value = 116, },
1516 {.center_freq = 5600, .hw_value = 120, },
1517 {.center_freq = 5620, .hw_value = 124, },
1518 {.center_freq = 5640, .hw_value = 128, },
1519 {.center_freq = 5660, .hw_value = 132, },
1520 {.center_freq = 5680, .hw_value = 136, },
1521 {.center_freq = 5700, .hw_value = 140, },
1522 {.center_freq = 5745, .hw_value = 149, },
1523 {.center_freq = 5765, .hw_value = 153, },
1524 {.center_freq = 5785, .hw_value = 157, },
1525 {.center_freq = 5805, .hw_value = 161, },
1526 {.center_freq = 5825, .hw_value = 165, },
1529 static struct ieee80211_supported_band mwifiex_band_5ghz = {
1530 .channels = mwifiex_channels_5ghz,
1531 .n_channels = ARRAY_SIZE(mwifiex_channels_5ghz),
1532 .bitrates = mwifiex_rates + 4,
1533 .n_bitrates = ARRAY_SIZE(mwifiex_rates) - 4,
1537 /* Supported crypto cipher suits to be advertised to cfg80211 */
1538 static const u32 mwifiex_cipher_suites[] = {
1539 WLAN_CIPHER_SUITE_WEP40,
1540 WLAN_CIPHER_SUITE_WEP104,
1541 WLAN_CIPHER_SUITE_TKIP,
1542 WLAN_CIPHER_SUITE_CCMP,
1543 WLAN_CIPHER_SUITE_SMS4,
1544 WLAN_CIPHER_SUITE_AES_CMAC,
1547 /* Supported mgmt frame types to be advertised to cfg80211 */
1548 static const struct ieee80211_txrx_stypes
1549 mwifiex_mgmt_stypes[NUM_NL80211_IFTYPES] = {
1550 [NL80211_IFTYPE_STATION] = {
1551 .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
1552 BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
1553 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
1554 BIT(IEEE80211_STYPE_PROBE_REQ >> 4),
1556 [NL80211_IFTYPE_AP] = {
1557 .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
1558 BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
1559 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
1560 BIT(IEEE80211_STYPE_PROBE_REQ >> 4),
1562 [NL80211_IFTYPE_P2P_CLIENT] = {
1563 .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
1564 BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
1565 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
1566 BIT(IEEE80211_STYPE_PROBE_REQ >> 4),
1568 [NL80211_IFTYPE_P2P_GO] = {
1569 .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
1570 BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
1571 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
1572 BIT(IEEE80211_STYPE_PROBE_REQ >> 4),
1577 * CFG802.11 operation handler for setting bit rates.
1579 * Function configures data rates to firmware using bitrate mask
1580 * provided by cfg80211.
1582 static int mwifiex_cfg80211_set_bitrate_mask(struct wiphy *wiphy,
1583 struct net_device *dev,
1585 const struct cfg80211_bitrate_mask *mask)
1587 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
1588 u16 bitmap_rates[MAX_BITMAP_RATES_SIZE];
1589 enum ieee80211_band band;
1590 struct mwifiex_adapter *adapter = priv->adapter;
1592 if (!priv->media_connected) {
1593 mwifiex_dbg(adapter, ERROR,
1594 "Can not set Tx data rate in disconnected state\n");
1598 band = mwifiex_band_to_radio_type(priv->curr_bss_params.band);
1600 memset(bitmap_rates, 0, sizeof(bitmap_rates));
1602 /* Fill HR/DSSS rates. */
1603 if (band == IEEE80211_BAND_2GHZ)
1604 bitmap_rates[0] = mask->control[band].legacy & 0x000f;
1606 /* Fill OFDM rates */
1607 if (band == IEEE80211_BAND_2GHZ)
1608 bitmap_rates[1] = (mask->control[band].legacy & 0x0ff0) >> 4;
1610 bitmap_rates[1] = mask->control[band].legacy;
1612 /* Fill HT MCS rates */
1613 bitmap_rates[2] = mask->control[band].ht_mcs[0];
1614 if (adapter->hw_dev_mcs_support == HT_STREAM_2X2)
1615 bitmap_rates[2] |= mask->control[band].ht_mcs[1] << 8;
1617 /* Fill VHT MCS rates */
1618 if (adapter->fw_api_ver == MWIFIEX_FW_V15) {
1619 bitmap_rates[10] = mask->control[band].vht_mcs[0];
1620 if (adapter->hw_dev_mcs_support == HT_STREAM_2X2)
1621 bitmap_rates[11] = mask->control[band].vht_mcs[1];
1624 return mwifiex_send_cmd(priv, HostCmd_CMD_TX_RATE_CFG,
1625 HostCmd_ACT_GEN_SET, 0, bitmap_rates, true);
1629 * CFG802.11 operation handler for connection quality monitoring.
1631 * This function subscribes/unsubscribes HIGH_RSSI and LOW_RSSI
1634 static int mwifiex_cfg80211_set_cqm_rssi_config(struct wiphy *wiphy,
1635 struct net_device *dev,
1636 s32 rssi_thold, u32 rssi_hyst)
1638 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
1639 struct mwifiex_ds_misc_subsc_evt subsc_evt;
1641 priv->cqm_rssi_thold = rssi_thold;
1642 priv->cqm_rssi_hyst = rssi_hyst;
1644 memset(&subsc_evt, 0x00, sizeof(struct mwifiex_ds_misc_subsc_evt));
1645 subsc_evt.events = BITMASK_BCN_RSSI_LOW | BITMASK_BCN_RSSI_HIGH;
1647 /* Subscribe/unsubscribe low and high rssi events */
1648 if (rssi_thold && rssi_hyst) {
1649 subsc_evt.action = HostCmd_ACT_BITWISE_SET;
1650 subsc_evt.bcn_l_rssi_cfg.abs_value = abs(rssi_thold);
1651 subsc_evt.bcn_h_rssi_cfg.abs_value = abs(rssi_thold);
1652 subsc_evt.bcn_l_rssi_cfg.evt_freq = 1;
1653 subsc_evt.bcn_h_rssi_cfg.evt_freq = 1;
1654 return mwifiex_send_cmd(priv,
1655 HostCmd_CMD_802_11_SUBSCRIBE_EVENT,
1656 0, 0, &subsc_evt, true);
1658 subsc_evt.action = HostCmd_ACT_BITWISE_CLR;
1659 return mwifiex_send_cmd(priv,
1660 HostCmd_CMD_802_11_SUBSCRIBE_EVENT,
1661 0, 0, &subsc_evt, true);
1667 /* cfg80211 operation handler for change_beacon.
1668 * Function retrieves and sets modified management IEs to FW.
1670 static int mwifiex_cfg80211_change_beacon(struct wiphy *wiphy,
1671 struct net_device *dev,
1672 struct cfg80211_beacon_data *data)
1674 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
1676 if (GET_BSS_ROLE(priv) != MWIFIEX_BSS_ROLE_UAP) {
1677 mwifiex_dbg(priv->adapter, ERROR,
1678 "%s: bss_type mismatched\n", __func__);
1682 if (!priv->bss_started) {
1683 mwifiex_dbg(priv->adapter, ERROR,
1684 "%s: bss not started\n", __func__);
1688 if (mwifiex_set_mgmt_ies(priv, data)) {
1689 mwifiex_dbg(priv->adapter, ERROR,
1690 "%s: setting mgmt ies failed\n", __func__);
1697 /* cfg80211 operation handler for del_station.
1698 * Function deauthenticates station which value is provided in mac parameter.
1699 * If mac is NULL/broadcast, all stations in associated station list are
1700 * deauthenticated. If bss is not started or there are no stations in
1701 * associated stations list, no action is taken.
1704 mwifiex_cfg80211_del_station(struct wiphy *wiphy, struct net_device *dev,
1705 struct station_del_parameters *params)
1707 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
1708 struct mwifiex_sta_node *sta_node;
1709 u8 deauth_mac[ETH_ALEN];
1710 unsigned long flags;
1712 if (!priv->bss_started && priv->wdev.cac_started) {
1713 mwifiex_dbg(priv->adapter, INFO, "%s: abort CAC!\n", __func__);
1714 mwifiex_abort_cac(priv);
1717 if (list_empty(&priv->sta_list) || !priv->bss_started)
1720 if (!params->mac || is_broadcast_ether_addr(params->mac))
1723 mwifiex_dbg(priv->adapter, INFO, "%s: mac address %pM\n",
1724 __func__, params->mac);
1726 eth_zero_addr(deauth_mac);
1728 spin_lock_irqsave(&priv->sta_list_spinlock, flags);
1729 sta_node = mwifiex_get_sta_entry(priv, params->mac);
1731 ether_addr_copy(deauth_mac, params->mac);
1732 spin_unlock_irqrestore(&priv->sta_list_spinlock, flags);
1734 if (is_valid_ether_addr(deauth_mac)) {
1735 if (mwifiex_send_cmd(priv, HostCmd_CMD_UAP_STA_DEAUTH,
1736 HostCmd_ACT_GEN_SET, 0,
1745 mwifiex_cfg80211_set_antenna(struct wiphy *wiphy, u32 tx_ant, u32 rx_ant)
1747 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
1748 struct mwifiex_private *priv = mwifiex_get_priv(adapter,
1749 MWIFIEX_BSS_ROLE_ANY);
1750 struct mwifiex_ds_ant_cfg ant_cfg;
1752 if (!tx_ant || !rx_ant)
1755 if (adapter->hw_dev_mcs_support != HT_STREAM_2X2) {
1756 /* Not a MIMO chip. User should provide specific antenna number
1757 * for Tx/Rx path or enable all antennas for diversity
1759 if (tx_ant != rx_ant)
1762 if ((tx_ant & (tx_ant - 1)) &&
1763 (tx_ant != BIT(adapter->number_of_antenna) - 1))
1766 if ((tx_ant == BIT(adapter->number_of_antenna) - 1) &&
1767 (priv->adapter->number_of_antenna > 1)) {
1768 tx_ant = RF_ANTENNA_AUTO;
1769 rx_ant = RF_ANTENNA_AUTO;
1772 struct ieee80211_sta_ht_cap *ht_info;
1774 enum ieee80211_band band;
1776 if ((tx_ant == 0x1 && rx_ant == 0x1)) {
1777 adapter->user_dev_mcs_support = HT_STREAM_1X1;
1778 if (adapter->is_hw_11ac_capable)
1779 adapter->usr_dot_11ac_mcs_support =
1780 MWIFIEX_11AC_MCS_MAP_1X1;
1782 adapter->user_dev_mcs_support = HT_STREAM_2X2;
1783 if (adapter->is_hw_11ac_capable)
1784 adapter->usr_dot_11ac_mcs_support =
1785 MWIFIEX_11AC_MCS_MAP_2X2;
1788 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
1789 if (!adapter->wiphy->bands[band])
1792 ht_info = &adapter->wiphy->bands[band]->ht_cap;
1794 GET_RXMCSSUPP(adapter->user_dev_mcs_support);
1795 memset(&ht_info->mcs, 0, adapter->number_of_antenna);
1796 memset(&ht_info->mcs, 0xff, rx_mcs_supp);
1800 ant_cfg.tx_ant = tx_ant;
1801 ant_cfg.rx_ant = rx_ant;
1803 return mwifiex_send_cmd(priv, HostCmd_CMD_RF_ANTENNA,
1804 HostCmd_ACT_GEN_SET, 0, &ant_cfg, true);
1807 /* cfg80211 operation handler for stop ap.
1808 * Function stops BSS running at uAP interface.
1810 static int mwifiex_cfg80211_stop_ap(struct wiphy *wiphy, struct net_device *dev)
1812 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
1814 mwifiex_abort_cac(priv);
1816 if (mwifiex_del_mgmt_ies(priv))
1817 mwifiex_dbg(priv->adapter, ERROR,
1818 "Failed to delete mgmt IEs!\n");
1820 priv->ap_11n_enabled = 0;
1821 memset(&priv->bss_cfg, 0, sizeof(priv->bss_cfg));
1823 if (mwifiex_send_cmd(priv, HostCmd_CMD_UAP_BSS_STOP,
1824 HostCmd_ACT_GEN_SET, 0, NULL, true)) {
1825 mwifiex_dbg(priv->adapter, ERROR,
1826 "Failed to stop the BSS\n");
1830 if (mwifiex_send_cmd(priv, HOST_CMD_APCMD_SYS_RESET,
1831 HostCmd_ACT_GEN_SET, 0, NULL, true)) {
1832 mwifiex_dbg(priv->adapter, ERROR,
1833 "Failed to reset BSS\n");
1837 if (netif_carrier_ok(priv->netdev))
1838 netif_carrier_off(priv->netdev);
1839 mwifiex_stop_net_dev_queue(priv->netdev, priv->adapter);
1844 /* cfg80211 operation handler for start_ap.
1845 * Function sets beacon period, DTIM period, SSID and security into
1846 * AP config structure.
1847 * AP is configured with these settings and BSS is started.
1849 static int mwifiex_cfg80211_start_ap(struct wiphy *wiphy,
1850 struct net_device *dev,
1851 struct cfg80211_ap_settings *params)
1853 struct mwifiex_uap_bss_param *bss_cfg;
1854 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
1856 if (GET_BSS_ROLE(priv) != MWIFIEX_BSS_ROLE_UAP)
1859 bss_cfg = kzalloc(sizeof(struct mwifiex_uap_bss_param), GFP_KERNEL);
1863 mwifiex_set_sys_config_invalid_data(bss_cfg);
1865 if (params->beacon_interval)
1866 bss_cfg->beacon_period = params->beacon_interval;
1867 if (params->dtim_period)
1868 bss_cfg->dtim_period = params->dtim_period;
1870 if (params->ssid && params->ssid_len) {
1871 memcpy(bss_cfg->ssid.ssid, params->ssid, params->ssid_len);
1872 bss_cfg->ssid.ssid_len = params->ssid_len;
1874 if (params->inactivity_timeout > 0) {
1875 /* sta_ao_timer/ps_sta_ao_timer is in unit of 100ms */
1876 bss_cfg->sta_ao_timer = 10 * params->inactivity_timeout;
1877 bss_cfg->ps_sta_ao_timer = 10 * params->inactivity_timeout;
1880 switch (params->hidden_ssid) {
1881 case NL80211_HIDDEN_SSID_NOT_IN_USE:
1882 bss_cfg->bcast_ssid_ctl = 1;
1884 case NL80211_HIDDEN_SSID_ZERO_LEN:
1885 bss_cfg->bcast_ssid_ctl = 0;
1887 case NL80211_HIDDEN_SSID_ZERO_CONTENTS:
1888 /* firmware doesn't support this type of hidden SSID */
1894 mwifiex_uap_set_channel(priv, bss_cfg, params->chandef);
1895 mwifiex_set_uap_rates(bss_cfg, params);
1897 if (mwifiex_set_secure_params(priv, bss_cfg, params)) {
1899 mwifiex_dbg(priv->adapter, ERROR,
1900 "Failed to parse secuirty parameters!\n");
1904 mwifiex_set_ht_params(priv, bss_cfg, params);
1906 if (priv->adapter->is_hw_11ac_capable) {
1907 mwifiex_set_vht_params(priv, bss_cfg, params);
1908 mwifiex_set_vht_width(priv, params->chandef.width,
1909 priv->ap_11ac_enabled);
1912 if (priv->ap_11ac_enabled)
1913 mwifiex_set_11ac_ba_params(priv);
1915 mwifiex_set_ba_params(priv);
1917 mwifiex_set_wmm_params(priv, bss_cfg, params);
1919 if (mwifiex_is_11h_active(priv))
1920 mwifiex_set_tpc_params(priv, bss_cfg, params);
1922 if (mwifiex_is_11h_active(priv) &&
1923 !cfg80211_chandef_dfs_required(wiphy, ¶ms->chandef,
1925 mwifiex_dbg(priv->adapter, INFO,
1926 "Disable 11h extensions in FW\n");
1927 if (mwifiex_11h_activate(priv, false)) {
1928 mwifiex_dbg(priv->adapter, ERROR,
1929 "Failed to disable 11h extensions!!");
1932 priv->state_11h.is_11h_active = false;
1935 if (mwifiex_config_start_uap(priv, bss_cfg)) {
1936 mwifiex_dbg(priv->adapter, ERROR,
1937 "Failed to start AP\n");
1942 if (mwifiex_set_mgmt_ies(priv, ¶ms->beacon))
1945 if (!netif_carrier_ok(priv->netdev))
1946 netif_carrier_on(priv->netdev);
1947 mwifiex_wake_up_net_dev_queue(priv->netdev, priv->adapter);
1949 memcpy(&priv->bss_cfg, bss_cfg, sizeof(priv->bss_cfg));
1955 * CFG802.11 operation handler for disconnection request.
1957 * This function does not work when there is already a disconnection
1958 * procedure going on.
1961 mwifiex_cfg80211_disconnect(struct wiphy *wiphy, struct net_device *dev,
1964 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
1966 if (!mwifiex_stop_bg_scan(priv))
1967 cfg80211_sched_scan_stopped_rtnl(priv->wdev.wiphy);
1969 if (mwifiex_deauthenticate(priv, NULL))
1972 mwifiex_dbg(priv->adapter, MSG,
1973 "info: successfully disconnected from %pM:\t"
1974 "reason code %d\n", priv->cfg_bssid, reason_code);
1976 eth_zero_addr(priv->cfg_bssid);
1977 priv->hs2_enabled = false;
1983 * This function informs the CFG802.11 subsystem of a new IBSS.
1985 * The following information are sent to the CFG802.11 subsystem
1986 * to register the new IBSS. If we do not register the new IBSS,
1987 * a kernel panic will result.
1993 static int mwifiex_cfg80211_inform_ibss_bss(struct mwifiex_private *priv)
1995 struct ieee80211_channel *chan;
1996 struct mwifiex_bss_info bss_info;
1997 struct cfg80211_bss *bss;
1999 u8 ie_buf[IEEE80211_MAX_SSID_LEN + sizeof(struct ieee_types_header)];
2000 enum ieee80211_band band;
2002 if (mwifiex_get_bss_info(priv, &bss_info))
2005 ie_buf[0] = WLAN_EID_SSID;
2006 ie_buf[1] = bss_info.ssid.ssid_len;
2008 memcpy(&ie_buf[sizeof(struct ieee_types_header)],
2009 &bss_info.ssid.ssid, bss_info.ssid.ssid_len);
2010 ie_len = ie_buf[1] + sizeof(struct ieee_types_header);
2012 band = mwifiex_band_to_radio_type(priv->curr_bss_params.band);
2013 chan = __ieee80211_get_channel(priv->wdev.wiphy,
2014 ieee80211_channel_to_frequency(bss_info.bss_chan,
2017 bss = cfg80211_inform_bss(priv->wdev.wiphy, chan,
2018 CFG80211_BSS_FTYPE_UNKNOWN,
2019 bss_info.bssid, 0, WLAN_CAPABILITY_IBSS,
2020 0, ie_buf, ie_len, 0, GFP_KERNEL);
2022 cfg80211_put_bss(priv->wdev.wiphy, bss);
2023 ether_addr_copy(priv->cfg_bssid, bss_info.bssid);
2030 * This function connects with a BSS.
2032 * This function handles both Infra and Ad-Hoc modes. It also performs
2033 * validity checking on the provided parameters, disconnects from the
2034 * current BSS (if any), sets up the association/scan parameters,
2035 * including security settings, and performs specific SSID scan before
2036 * trying to connect.
2038 * For Infra mode, the function returns failure if the specified SSID
2039 * is not found in scan table. However, for Ad-Hoc mode, it can create
2040 * the IBSS if it does not exist. On successful completion in either case,
2041 * the function notifies the CFG802.11 subsystem of the new BSS connection.
2044 mwifiex_cfg80211_assoc(struct mwifiex_private *priv, size_t ssid_len,
2045 const u8 *ssid, const u8 *bssid, int mode,
2046 struct ieee80211_channel *channel,
2047 struct cfg80211_connect_params *sme, bool privacy)
2049 struct cfg80211_ssid req_ssid;
2050 int ret, auth_type = 0;
2051 struct cfg80211_bss *bss = NULL;
2052 u8 is_scanning_required = 0;
2054 memset(&req_ssid, 0, sizeof(struct cfg80211_ssid));
2056 req_ssid.ssid_len = ssid_len;
2057 if (ssid_len > IEEE80211_MAX_SSID_LEN) {
2058 mwifiex_dbg(priv->adapter, ERROR, "invalid SSID - aborting\n");
2062 memcpy(req_ssid.ssid, ssid, ssid_len);
2063 if (!req_ssid.ssid_len || req_ssid.ssid[0] < 0x20) {
2064 mwifiex_dbg(priv->adapter, ERROR, "invalid SSID - aborting\n");
2068 /* As this is new association, clear locally stored
2069 * keys and security related flags */
2070 priv->sec_info.wpa_enabled = false;
2071 priv->sec_info.wpa2_enabled = false;
2072 priv->wep_key_curr_index = 0;
2073 priv->sec_info.encryption_mode = 0;
2074 priv->sec_info.is_authtype_auto = 0;
2075 ret = mwifiex_set_encode(priv, NULL, NULL, 0, 0, NULL, 1);
2077 if (mode == NL80211_IFTYPE_ADHOC) {
2078 /* "privacy" is set only for ad-hoc mode */
2081 * Keep WLAN_CIPHER_SUITE_WEP104 for now so that
2082 * the firmware can find a matching network from the
2083 * scan. The cfg80211 does not give us the encryption
2084 * mode at this stage so just setting it to WEP here.
2086 priv->sec_info.encryption_mode =
2087 WLAN_CIPHER_SUITE_WEP104;
2088 priv->sec_info.authentication_mode =
2089 NL80211_AUTHTYPE_OPEN_SYSTEM;
2095 /* Now handle infra mode. "sme" is valid for infra mode only */
2096 if (sme->auth_type == NL80211_AUTHTYPE_AUTOMATIC) {
2097 auth_type = NL80211_AUTHTYPE_OPEN_SYSTEM;
2098 priv->sec_info.is_authtype_auto = 1;
2100 auth_type = sme->auth_type;
2103 if (sme->crypto.n_ciphers_pairwise) {
2104 priv->sec_info.encryption_mode =
2105 sme->crypto.ciphers_pairwise[0];
2106 priv->sec_info.authentication_mode = auth_type;
2109 if (sme->crypto.cipher_group) {
2110 priv->sec_info.encryption_mode = sme->crypto.cipher_group;
2111 priv->sec_info.authentication_mode = auth_type;
2114 ret = mwifiex_set_gen_ie(priv, sme->ie, sme->ie_len);
2117 if (mwifiex_is_alg_wep(priv->sec_info.encryption_mode)) {
2118 mwifiex_dbg(priv->adapter, INFO,
2119 "info: setting wep encryption\t"
2120 "with key len %d\n", sme->key_len);
2121 priv->wep_key_curr_index = sme->key_idx;
2122 ret = mwifiex_set_encode(priv, NULL, sme->key,
2123 sme->key_len, sme->key_idx,
2129 * Scan entries are valid for some time (15 sec). So we can save one
2130 * active scan time if we just try cfg80211_get_bss first. If it fails
2131 * then request scan and cfg80211_get_bss() again for final output.
2134 if (is_scanning_required) {
2135 /* Do specific SSID scanning */
2136 if (mwifiex_request_scan(priv, &req_ssid)) {
2137 mwifiex_dbg(priv->adapter, ERROR, "scan error\n");
2142 /* Find the BSS we want using available scan results */
2143 if (mode == NL80211_IFTYPE_ADHOC)
2144 bss = cfg80211_get_bss(priv->wdev.wiphy, channel,
2145 bssid, ssid, ssid_len,
2146 IEEE80211_BSS_TYPE_IBSS,
2147 IEEE80211_PRIVACY_ANY);
2149 bss = cfg80211_get_bss(priv->wdev.wiphy, channel,
2150 bssid, ssid, ssid_len,
2151 IEEE80211_BSS_TYPE_ESS,
2152 IEEE80211_PRIVACY_ANY);
2155 if (is_scanning_required) {
2156 mwifiex_dbg(priv->adapter, WARN,
2157 "assoc: requested bss not found in scan results\n");
2160 is_scanning_required = 1;
2162 mwifiex_dbg(priv->adapter, MSG,
2163 "info: trying to associate to '%s' bssid %pM\n",
2164 (char *)req_ssid.ssid, bss->bssid);
2165 memcpy(&priv->cfg_bssid, bss->bssid, ETH_ALEN);
2170 ret = mwifiex_bss_start(priv, bss, &req_ssid);
2174 if (mode == NL80211_IFTYPE_ADHOC) {
2175 /* Inform the BSS information to kernel, otherwise
2176 * kernel will give a panic after successful assoc */
2177 if (mwifiex_cfg80211_inform_ibss_bss(priv))
2185 * CFG802.11 operation handler for association request.
2187 * This function does not work when the current mode is set to Ad-Hoc, or
2188 * when there is already an association procedure going on. The given BSS
2189 * information is used to associate.
2192 mwifiex_cfg80211_connect(struct wiphy *wiphy, struct net_device *dev,
2193 struct cfg80211_connect_params *sme)
2195 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
2196 struct mwifiex_adapter *adapter = priv->adapter;
2199 if (GET_BSS_ROLE(priv) != MWIFIEX_BSS_ROLE_STA) {
2200 mwifiex_dbg(adapter, ERROR,
2201 "%s: reject infra assoc request in non-STA role\n",
2206 if (priv->wdev.current_bss) {
2207 mwifiex_dbg(adapter, ERROR,
2208 "%s: already connected\n", dev->name);
2212 if (adapter->surprise_removed || adapter->is_cmd_timedout) {
2213 mwifiex_dbg(adapter, ERROR,
2214 "%s: Ignore connection.\t"
2215 "Card removed or FW in bad state\n",
2220 mwifiex_dbg(adapter, INFO,
2221 "info: Trying to associate to %s and bssid %pM\n",
2222 (char *)sme->ssid, sme->bssid);
2224 if (!mwifiex_stop_bg_scan(priv))
2225 cfg80211_sched_scan_stopped_rtnl(priv->wdev.wiphy);
2227 ret = mwifiex_cfg80211_assoc(priv, sme->ssid_len, sme->ssid, sme->bssid,
2228 priv->bss_mode, sme->channel, sme, 0);
2230 cfg80211_connect_result(priv->netdev, priv->cfg_bssid, NULL, 0,
2231 NULL, 0, WLAN_STATUS_SUCCESS,
2233 mwifiex_dbg(priv->adapter, MSG,
2234 "info: associated to bssid %pM successfully\n",
2236 if (ISSUPP_TDLS_ENABLED(priv->adapter->fw_cap_info) &&
2237 priv->adapter->auto_tdls &&
2238 priv->bss_type == MWIFIEX_BSS_TYPE_STA)
2239 mwifiex_setup_auto_tdls_timer(priv);
2241 mwifiex_dbg(priv->adapter, ERROR,
2242 "info: association to bssid %pM failed\n",
2244 eth_zero_addr(priv->cfg_bssid);
2247 cfg80211_connect_result(priv->netdev, priv->cfg_bssid,
2248 NULL, 0, NULL, 0, ret,
2251 cfg80211_connect_result(priv->netdev, priv->cfg_bssid,
2253 WLAN_STATUS_UNSPECIFIED_FAILURE,
2261 * This function sets following parameters for ibss network.
2265 * - secondary channel offset
2267 static int mwifiex_set_ibss_params(struct mwifiex_private *priv,
2268 struct cfg80211_ibss_params *params)
2270 struct mwifiex_adapter *adapter = priv->adapter;
2272 u8 config_bands = 0;
2274 if (params->chandef.chan->band == IEEE80211_BAND_2GHZ) {
2275 if (!params->basic_rates) {
2276 config_bands = BAND_B | BAND_G;
2278 for (i = 0; i < mwifiex_band_2ghz.n_bitrates; i++) {
2280 * Rates below 6 Mbps in the table are CCK
2281 * rates; 802.11b and from 6 they are OFDM;
2284 if (mwifiex_rates[i].bitrate == 60) {
2290 if (params->basic_rates < index) {
2291 config_bands = BAND_B;
2293 config_bands = BAND_G;
2294 if (params->basic_rates % index)
2295 config_bands |= BAND_B;
2299 if (cfg80211_get_chandef_type(¶ms->chandef) !=
2301 config_bands |= BAND_G | BAND_GN;
2303 if (cfg80211_get_chandef_type(¶ms->chandef) ==
2305 config_bands = BAND_A;
2307 config_bands = BAND_AN | BAND_A;
2310 if (!((config_bands | adapter->fw_bands) & ~adapter->fw_bands)) {
2311 adapter->config_bands = config_bands;
2312 adapter->adhoc_start_band = config_bands;
2314 if ((config_bands & BAND_GN) || (config_bands & BAND_AN))
2315 adapter->adhoc_11n_enabled = true;
2317 adapter->adhoc_11n_enabled = false;
2320 adapter->sec_chan_offset =
2321 mwifiex_chan_type_to_sec_chan_offset(
2322 cfg80211_get_chandef_type(¶ms->chandef));
2323 priv->adhoc_channel = ieee80211_frequency_to_channel(
2324 params->chandef.chan->center_freq);
2326 mwifiex_dbg(adapter, INFO,
2327 "info: set ibss band %d, chan %d, chan offset %d\n",
2328 config_bands, priv->adhoc_channel,
2329 adapter->sec_chan_offset);
2335 * CFG802.11 operation handler to join an IBSS.
2337 * This function does not work in any mode other than Ad-Hoc, or if
2338 * a join operation is already in progress.
2341 mwifiex_cfg80211_join_ibss(struct wiphy *wiphy, struct net_device *dev,
2342 struct cfg80211_ibss_params *params)
2344 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
2347 if (priv->bss_mode != NL80211_IFTYPE_ADHOC) {
2348 mwifiex_dbg(priv->adapter, ERROR,
2349 "request to join ibss received\t"
2350 "when station is not in ibss mode\n");
2354 mwifiex_dbg(priv->adapter, MSG,
2355 "info: trying to join to %s and bssid %pM\n",
2356 (char *)params->ssid, params->bssid);
2358 mwifiex_set_ibss_params(priv, params);
2360 ret = mwifiex_cfg80211_assoc(priv, params->ssid_len, params->ssid,
2361 params->bssid, priv->bss_mode,
2362 params->chandef.chan, NULL,
2366 cfg80211_ibss_joined(priv->netdev, priv->cfg_bssid,
2367 params->chandef.chan, GFP_KERNEL);
2368 mwifiex_dbg(priv->adapter, MSG,
2369 "info: joined/created adhoc network with bssid\t"
2370 "%pM successfully\n", priv->cfg_bssid);
2372 mwifiex_dbg(priv->adapter, ERROR,
2373 "info: failed creating/joining adhoc network\n");
2380 * CFG802.11 operation handler to leave an IBSS.
2382 * This function does not work if a leave operation is
2383 * already in progress.
2386 mwifiex_cfg80211_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
2388 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
2390 mwifiex_dbg(priv->adapter, MSG, "info: disconnecting from essid %pM\n",
2392 if (mwifiex_deauthenticate(priv, NULL))
2395 eth_zero_addr(priv->cfg_bssid);
2401 * CFG802.11 operation handler for scan request.
2403 * This function issues a scan request to the firmware based upon
2404 * the user specified scan configuration. On successful completion,
2405 * it also informs the results.
2408 mwifiex_cfg80211_scan(struct wiphy *wiphy,
2409 struct cfg80211_scan_request *request)
2411 struct net_device *dev = request->wdev->netdev;
2412 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
2414 struct ieee80211_channel *chan;
2415 struct ieee_types_header *ie;
2416 struct mwifiex_user_scan_cfg *user_scan_cfg;
2418 mwifiex_dbg(priv->adapter, CMD,
2419 "info: received scan request on %s\n", dev->name);
2421 /* Block scan request if scan operation or scan cleanup when interface
2422 * is disabled is in process
2424 if (priv->scan_request || priv->scan_aborting) {
2425 mwifiex_dbg(priv->adapter, WARN,
2426 "cmd: Scan already in process..\n");
2430 if (!mwifiex_stop_bg_scan(priv))
2431 cfg80211_sched_scan_stopped_rtnl(priv->wdev.wiphy);
2433 user_scan_cfg = kzalloc(sizeof(*user_scan_cfg), GFP_KERNEL);
2437 priv->scan_request = request;
2439 user_scan_cfg->num_ssids = request->n_ssids;
2440 user_scan_cfg->ssid_list = request->ssids;
2442 if (request->ie && request->ie_len) {
2444 for (i = 0; i < MWIFIEX_MAX_VSIE_NUM; i++) {
2445 if (priv->vs_ie[i].mask != MWIFIEX_VSIE_MASK_CLEAR)
2447 priv->vs_ie[i].mask = MWIFIEX_VSIE_MASK_SCAN;
2448 ie = (struct ieee_types_header *)(request->ie + offset);
2449 memcpy(&priv->vs_ie[i].ie, ie, sizeof(*ie) + ie->len);
2450 offset += sizeof(*ie) + ie->len;
2452 if (offset >= request->ie_len)
2457 for (i = 0; i < min_t(u32, request->n_channels,
2458 MWIFIEX_USER_SCAN_CHAN_MAX); i++) {
2459 chan = request->channels[i];
2460 user_scan_cfg->chan_list[i].chan_number = chan->hw_value;
2461 user_scan_cfg->chan_list[i].radio_type = chan->band;
2463 if ((chan->flags & IEEE80211_CHAN_NO_IR) || !request->n_ssids)
2464 user_scan_cfg->chan_list[i].scan_type =
2465 MWIFIEX_SCAN_TYPE_PASSIVE;
2467 user_scan_cfg->chan_list[i].scan_type =
2468 MWIFIEX_SCAN_TYPE_ACTIVE;
2470 user_scan_cfg->chan_list[i].scan_time = 0;
2473 if (priv->adapter->scan_chan_gap_enabled &&
2474 mwifiex_is_any_intf_active(priv))
2475 user_scan_cfg->scan_chan_gap =
2476 priv->adapter->scan_chan_gap_time;
2478 ret = mwifiex_scan_networks(priv, user_scan_cfg);
2479 kfree(user_scan_cfg);
2481 mwifiex_dbg(priv->adapter, ERROR,
2482 "scan failed: %d\n", ret);
2483 priv->scan_aborting = false;
2484 priv->scan_request = NULL;
2488 if (request->ie && request->ie_len) {
2489 for (i = 0; i < MWIFIEX_MAX_VSIE_NUM; i++) {
2490 if (priv->vs_ie[i].mask == MWIFIEX_VSIE_MASK_SCAN) {
2491 priv->vs_ie[i].mask = MWIFIEX_VSIE_MASK_CLEAR;
2492 memset(&priv->vs_ie[i].ie, 0,
2493 MWIFIEX_MAX_VSIE_LEN);
2500 /* CFG802.11 operation handler for sched_scan_start.
2502 * This function issues a bgscan config request to the firmware based upon
2503 * the user specified sched_scan configuration. On successful completion,
2504 * firmware will generate BGSCAN_REPORT event, driver should issue bgscan
2505 * query command to get sched_scan results from firmware.
2508 mwifiex_cfg80211_sched_scan_start(struct wiphy *wiphy,
2509 struct net_device *dev,
2510 struct cfg80211_sched_scan_request *request)
2512 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
2514 struct ieee80211_channel *chan;
2515 struct mwifiex_bg_scan_cfg *bgscan_cfg;
2516 struct ieee_types_header *ie;
2518 if (!request || (!request->n_ssids && !request->n_match_sets)) {
2519 wiphy_err(wiphy, "%s : Invalid Sched_scan parameters",
2524 wiphy_info(wiphy, "sched_scan start : n_ssids=%d n_match_sets=%d ",
2525 request->n_ssids, request->n_match_sets);
2526 wiphy_info(wiphy, "n_channels=%d interval=%d ie_len=%d\n",
2527 request->n_channels, request->scan_plans->interval,
2528 (int)request->ie_len);
2530 bgscan_cfg = kzalloc(sizeof(*bgscan_cfg), GFP_KERNEL);
2534 if (priv->scan_request || priv->scan_aborting)
2535 bgscan_cfg->start_later = true;
2537 bgscan_cfg->num_ssids = request->n_match_sets;
2538 bgscan_cfg->ssid_list = request->match_sets;
2540 if (request->ie && request->ie_len) {
2542 for (i = 0; i < MWIFIEX_MAX_VSIE_NUM; i++) {
2543 if (priv->vs_ie[i].mask != MWIFIEX_VSIE_MASK_CLEAR)
2545 priv->vs_ie[i].mask = MWIFIEX_VSIE_MASK_BGSCAN;
2546 ie = (struct ieee_types_header *)(request->ie + offset);
2547 memcpy(&priv->vs_ie[i].ie, ie, sizeof(*ie) + ie->len);
2548 offset += sizeof(*ie) + ie->len;
2550 if (offset >= request->ie_len)
2555 for (i = 0; i < min_t(u32, request->n_channels,
2556 MWIFIEX_BG_SCAN_CHAN_MAX); i++) {
2557 chan = request->channels[i];
2558 bgscan_cfg->chan_list[i].chan_number = chan->hw_value;
2559 bgscan_cfg->chan_list[i].radio_type = chan->band;
2561 if ((chan->flags & IEEE80211_CHAN_NO_IR) || !request->n_ssids)
2562 bgscan_cfg->chan_list[i].scan_type =
2563 MWIFIEX_SCAN_TYPE_PASSIVE;
2565 bgscan_cfg->chan_list[i].scan_type =
2566 MWIFIEX_SCAN_TYPE_ACTIVE;
2568 bgscan_cfg->chan_list[i].scan_time = 0;
2571 bgscan_cfg->chan_per_scan = min_t(u32, request->n_channels,
2572 MWIFIEX_BG_SCAN_CHAN_MAX);
2574 /* Use at least 15 second for per scan cycle */
2575 bgscan_cfg->scan_interval = (request->scan_plans->interval >
2576 MWIFIEX_BGSCAN_INTERVAL) ?
2577 request->scan_plans->interval :
2578 MWIFIEX_BGSCAN_INTERVAL;
2580 bgscan_cfg->repeat_count = MWIFIEX_BGSCAN_REPEAT_COUNT;
2581 bgscan_cfg->report_condition = MWIFIEX_BGSCAN_SSID_MATCH |
2582 MWIFIEX_BGSCAN_WAIT_ALL_CHAN_DONE;
2583 bgscan_cfg->bss_type = MWIFIEX_BSS_MODE_INFRA;
2584 bgscan_cfg->action = MWIFIEX_BGSCAN_ACT_SET;
2585 bgscan_cfg->enable = true;
2586 if (request->min_rssi_thold != NL80211_SCAN_RSSI_THOLD_OFF) {
2587 bgscan_cfg->report_condition |= MWIFIEX_BGSCAN_SSID_RSSI_MATCH;
2588 bgscan_cfg->rssi_threshold = request->min_rssi_thold;
2591 if (mwifiex_send_cmd(priv, HostCmd_CMD_802_11_BG_SCAN_CONFIG,
2592 HostCmd_ACT_GEN_SET, 0, bgscan_cfg, true)) {
2597 priv->sched_scanning = true;
2603 /* CFG802.11 operation handler for sched_scan_stop.
2605 * This function issues a bgscan config command to disable
2606 * previous bgscan configuration in the firmware
2608 static int mwifiex_cfg80211_sched_scan_stop(struct wiphy *wiphy,
2609 struct net_device *dev)
2611 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
2613 wiphy_info(wiphy, "sched scan stop!");
2614 mwifiex_stop_bg_scan(priv);
2619 static void mwifiex_setup_vht_caps(struct ieee80211_sta_vht_cap *vht_info,
2620 struct mwifiex_private *priv)
2622 struct mwifiex_adapter *adapter = priv->adapter;
2624 vht_info->vht_supported = true;
2626 vht_info->cap = adapter->hw_dot_11ac_dev_cap;
2627 /* Update MCS support for VHT */
2628 vht_info->vht_mcs.rx_mcs_map = cpu_to_le16(
2629 adapter->hw_dot_11ac_mcs_support & 0xFFFF);
2630 vht_info->vht_mcs.rx_highest = 0;
2631 vht_info->vht_mcs.tx_mcs_map = cpu_to_le16(
2632 adapter->hw_dot_11ac_mcs_support >> 16);
2633 vht_info->vht_mcs.tx_highest = 0;
2637 * This function sets up the CFG802.11 specific HT capability fields
2638 * with default values.
2640 * The following default values are set -
2641 * - HT Supported = True
2642 * - Maximum AMPDU length factor = IEEE80211_HT_MAX_AMPDU_64K
2643 * - Minimum AMPDU spacing = IEEE80211_HT_MPDU_DENSITY_NONE
2644 * - HT Capabilities supported by firmware
2645 * - MCS information, Rx mask = 0xff
2646 * - MCD information, Tx parameters = IEEE80211_HT_MCS_TX_DEFINED (0x01)
2649 mwifiex_setup_ht_caps(struct ieee80211_sta_ht_cap *ht_info,
2650 struct mwifiex_private *priv)
2653 struct ieee80211_mcs_info mcs_set;
2654 u8 *mcs = (u8 *)&mcs_set;
2655 struct mwifiex_adapter *adapter = priv->adapter;
2657 ht_info->ht_supported = true;
2658 ht_info->ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
2659 ht_info->ampdu_density = IEEE80211_HT_MPDU_DENSITY_NONE;
2661 memset(&ht_info->mcs, 0, sizeof(ht_info->mcs));
2663 /* Fill HT capability information */
2664 if (ISSUPP_CHANWIDTH40(adapter->hw_dot_11n_dev_cap))
2665 ht_info->cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
2667 ht_info->cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
2669 if (ISSUPP_SHORTGI20(adapter->hw_dot_11n_dev_cap))
2670 ht_info->cap |= IEEE80211_HT_CAP_SGI_20;
2672 ht_info->cap &= ~IEEE80211_HT_CAP_SGI_20;
2674 if (ISSUPP_SHORTGI40(adapter->hw_dot_11n_dev_cap))
2675 ht_info->cap |= IEEE80211_HT_CAP_SGI_40;
2677 ht_info->cap &= ~IEEE80211_HT_CAP_SGI_40;
2679 if (adapter->user_dev_mcs_support == HT_STREAM_2X2)
2680 ht_info->cap |= 3 << IEEE80211_HT_CAP_RX_STBC_SHIFT;
2682 ht_info->cap |= 1 << IEEE80211_HT_CAP_RX_STBC_SHIFT;
2684 if (ISSUPP_TXSTBC(adapter->hw_dot_11n_dev_cap))
2685 ht_info->cap |= IEEE80211_HT_CAP_TX_STBC;
2687 ht_info->cap &= ~IEEE80211_HT_CAP_TX_STBC;
2689 if (ISSUPP_GREENFIELD(adapter->hw_dot_11n_dev_cap))
2690 ht_info->cap |= IEEE80211_HT_CAP_GRN_FLD;
2692 ht_info->cap &= ~IEEE80211_HT_CAP_GRN_FLD;
2694 if (ISENABLED_40MHZ_INTOLERANT(adapter->hw_dot_11n_dev_cap))
2695 ht_info->cap |= IEEE80211_HT_CAP_40MHZ_INTOLERANT;
2697 ht_info->cap &= ~IEEE80211_HT_CAP_40MHZ_INTOLERANT;
2699 if (ISSUPP_RXLDPC(adapter->hw_dot_11n_dev_cap))
2700 ht_info->cap |= IEEE80211_HT_CAP_LDPC_CODING;
2702 ht_info->cap &= ~IEEE80211_HT_CAP_LDPC_CODING;
2704 ht_info->cap &= ~IEEE80211_HT_CAP_MAX_AMSDU;
2705 ht_info->cap |= IEEE80211_HT_CAP_SM_PS;
2707 rx_mcs_supp = GET_RXMCSSUPP(adapter->user_dev_mcs_support);
2708 /* Set MCS for 1x1/2x2 */
2709 memset(mcs, 0xff, rx_mcs_supp);
2710 /* Clear all the other values */
2711 memset(&mcs[rx_mcs_supp], 0,
2712 sizeof(struct ieee80211_mcs_info) - rx_mcs_supp);
2713 if (priv->bss_mode == NL80211_IFTYPE_STATION ||
2714 ISSUPP_CHANWIDTH40(adapter->hw_dot_11n_dev_cap))
2715 /* Set MCS32 for infra mode or ad-hoc mode with 40MHz support */
2716 SETHT_MCS32(mcs_set.rx_mask);
2718 memcpy((u8 *) &ht_info->mcs, mcs, sizeof(struct ieee80211_mcs_info));
2720 ht_info->mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED;
2724 * create a new virtual interface with the given name and name assign type
2726 struct wireless_dev *mwifiex_add_virtual_intf(struct wiphy *wiphy,
2728 unsigned char name_assign_type,
2729 enum nl80211_iftype type,
2731 struct vif_params *params)
2733 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
2734 struct mwifiex_private *priv;
2735 struct net_device *dev;
2739 return ERR_PTR(-EFAULT);
2742 case NL80211_IFTYPE_UNSPECIFIED:
2743 case NL80211_IFTYPE_STATION:
2744 case NL80211_IFTYPE_ADHOC:
2745 if (adapter->curr_iface_comb.sta_intf ==
2746 adapter->iface_limit.sta_intf) {
2747 mwifiex_dbg(adapter, ERROR,
2748 "cannot create multiple sta/adhoc ifaces\n");
2749 return ERR_PTR(-EINVAL);
2752 priv = mwifiex_get_unused_priv_by_bss_type(
2753 adapter, MWIFIEX_BSS_TYPE_STA);
2755 mwifiex_dbg(adapter, ERROR,
2756 "could not get free private struct\n");
2757 return ERR_PTR(-EFAULT);
2760 priv->wdev.wiphy = wiphy;
2761 priv->wdev.iftype = NL80211_IFTYPE_STATION;
2763 if (type == NL80211_IFTYPE_UNSPECIFIED)
2764 priv->bss_mode = NL80211_IFTYPE_STATION;
2766 priv->bss_mode = type;
2768 priv->bss_type = MWIFIEX_BSS_TYPE_STA;
2769 priv->frame_type = MWIFIEX_DATA_FRAME_TYPE_ETH_II;
2770 priv->bss_priority = 0;
2771 priv->bss_role = MWIFIEX_BSS_ROLE_STA;
2774 case NL80211_IFTYPE_AP:
2775 if (adapter->curr_iface_comb.uap_intf ==
2776 adapter->iface_limit.uap_intf) {
2777 mwifiex_dbg(adapter, ERROR,
2778 "cannot create multiple AP ifaces\n");
2779 return ERR_PTR(-EINVAL);
2782 priv = mwifiex_get_unused_priv_by_bss_type(
2783 adapter, MWIFIEX_BSS_TYPE_UAP);
2785 mwifiex_dbg(adapter, ERROR,
2786 "could not get free private struct\n");
2787 return ERR_PTR(-EFAULT);
2790 priv->wdev.wiphy = wiphy;
2791 priv->wdev.iftype = NL80211_IFTYPE_AP;
2793 priv->bss_type = MWIFIEX_BSS_TYPE_UAP;
2794 priv->frame_type = MWIFIEX_DATA_FRAME_TYPE_ETH_II;
2795 priv->bss_priority = 0;
2796 priv->bss_role = MWIFIEX_BSS_ROLE_UAP;
2797 priv->bss_started = 0;
2798 priv->bss_mode = type;
2801 case NL80211_IFTYPE_P2P_CLIENT:
2802 if (adapter->curr_iface_comb.p2p_intf ==
2803 adapter->iface_limit.p2p_intf) {
2804 mwifiex_dbg(adapter, ERROR,
2805 "cannot create multiple P2P ifaces\n");
2806 return ERR_PTR(-EINVAL);
2809 priv = mwifiex_get_unused_priv_by_bss_type(
2810 adapter, MWIFIEX_BSS_TYPE_P2P);
2812 mwifiex_dbg(adapter, ERROR,
2813 "could not get free private struct\n");
2814 return ERR_PTR(-EFAULT);
2817 priv->wdev.wiphy = wiphy;
2818 /* At start-up, wpa_supplicant tries to change the interface
2819 * to NL80211_IFTYPE_STATION if it is not managed mode.
2821 priv->wdev.iftype = NL80211_IFTYPE_P2P_CLIENT;
2822 priv->bss_mode = NL80211_IFTYPE_P2P_CLIENT;
2824 /* Setting bss_type to P2P tells firmware that this interface
2825 * is receiving P2P peers found during find phase and doing
2826 * action frame handshake.
2828 priv->bss_type = MWIFIEX_BSS_TYPE_P2P;
2830 priv->frame_type = MWIFIEX_DATA_FRAME_TYPE_ETH_II;
2831 priv->bss_priority = MWIFIEX_BSS_ROLE_STA;
2832 priv->bss_role = MWIFIEX_BSS_ROLE_STA;
2833 priv->bss_started = 0;
2835 if (mwifiex_cfg80211_init_p2p_client(priv)) {
2836 memset(&priv->wdev, 0, sizeof(priv->wdev));
2837 priv->wdev.iftype = NL80211_IFTYPE_UNSPECIFIED;
2838 return ERR_PTR(-EFAULT);
2843 mwifiex_dbg(adapter, ERROR, "type not supported\n");
2844 return ERR_PTR(-EINVAL);
2847 dev = alloc_netdev_mqs(sizeof(struct mwifiex_private *), name,
2848 name_assign_type, ether_setup,
2849 IEEE80211_NUM_ACS, 1);
2851 mwifiex_dbg(adapter, ERROR,
2852 "no memory available for netdevice\n");
2853 memset(&priv->wdev, 0, sizeof(priv->wdev));
2854 priv->wdev.iftype = NL80211_IFTYPE_UNSPECIFIED;
2855 priv->bss_mode = NL80211_IFTYPE_UNSPECIFIED;
2856 return ERR_PTR(-ENOMEM);
2859 mwifiex_init_priv_params(priv, dev);
2862 mwifiex_setup_ht_caps(&wiphy->bands[IEEE80211_BAND_2GHZ]->ht_cap, priv);
2863 if (adapter->is_hw_11ac_capable)
2864 mwifiex_setup_vht_caps(
2865 &wiphy->bands[IEEE80211_BAND_2GHZ]->vht_cap, priv);
2867 if (adapter->config_bands & BAND_A)
2868 mwifiex_setup_ht_caps(
2869 &wiphy->bands[IEEE80211_BAND_5GHZ]->ht_cap, priv);
2871 if ((adapter->config_bands & BAND_A) && adapter->is_hw_11ac_capable)
2872 mwifiex_setup_vht_caps(
2873 &wiphy->bands[IEEE80211_BAND_5GHZ]->vht_cap, priv);
2875 dev_net_set(dev, wiphy_net(wiphy));
2876 dev->ieee80211_ptr = &priv->wdev;
2877 dev->ieee80211_ptr->iftype = priv->bss_mode;
2878 memcpy(dev->dev_addr, wiphy->perm_addr, ETH_ALEN);
2879 SET_NETDEV_DEV(dev, wiphy_dev(wiphy));
2881 dev->flags |= IFF_BROADCAST | IFF_MULTICAST;
2882 dev->watchdog_timeo = MWIFIEX_DEFAULT_WATCHDOG_TIMEOUT;
2883 dev->hard_header_len += MWIFIEX_MIN_DATA_HEADER_LEN;
2884 dev->ethtool_ops = &mwifiex_ethtool_ops;
2886 mdev_priv = netdev_priv(dev);
2887 *((unsigned long *) mdev_priv) = (unsigned long) priv;
2889 SET_NETDEV_DEV(dev, adapter->dev);
2891 /* Register network device */
2892 if (register_netdevice(dev)) {
2893 mwifiex_dbg(adapter, ERROR,
2894 "cannot register virtual network device\n");
2896 priv->bss_mode = NL80211_IFTYPE_UNSPECIFIED;
2897 priv->netdev = NULL;
2898 memset(&priv->wdev, 0, sizeof(priv->wdev));
2899 priv->wdev.iftype = NL80211_IFTYPE_UNSPECIFIED;
2900 return ERR_PTR(-EFAULT);
2903 priv->dfs_cac_workqueue = alloc_workqueue("MWIFIEX_DFS_CAC%s",
2906 WQ_UNBOUND, 1, name);
2907 if (!priv->dfs_cac_workqueue) {
2908 mwifiex_dbg(adapter, ERROR,
2909 "cannot register virtual network device\n");
2911 priv->bss_mode = NL80211_IFTYPE_UNSPECIFIED;
2912 priv->netdev = NULL;
2913 memset(&priv->wdev, 0, sizeof(priv->wdev));
2914 priv->wdev.iftype = NL80211_IFTYPE_UNSPECIFIED;
2915 return ERR_PTR(-ENOMEM);
2918 INIT_DELAYED_WORK(&priv->dfs_cac_work, mwifiex_dfs_cac_work_queue);
2920 priv->dfs_chan_sw_workqueue = alloc_workqueue("MWIFIEX_DFS_CHSW%s",
2921 WQ_HIGHPRI | WQ_UNBOUND |
2922 WQ_MEM_RECLAIM, 1, name);
2923 if (!priv->dfs_chan_sw_workqueue) {
2924 mwifiex_dbg(adapter, ERROR,
2925 "cannot register virtual network device\n");
2927 priv->bss_mode = NL80211_IFTYPE_UNSPECIFIED;
2928 priv->netdev = NULL;
2929 memset(&priv->wdev, 0, sizeof(priv->wdev));
2930 priv->wdev.iftype = NL80211_IFTYPE_UNSPECIFIED;
2931 return ERR_PTR(-ENOMEM);
2934 INIT_DELAYED_WORK(&priv->dfs_chan_sw_work,
2935 mwifiex_dfs_chan_sw_work_queue);
2937 sema_init(&priv->async_sem, 1);
2939 mwifiex_dbg(adapter, INFO,
2940 "info: %s: Marvell 802.11 Adapter\n", dev->name);
2942 #ifdef CONFIG_DEBUG_FS
2943 mwifiex_dev_debugfs_init(priv);
2947 case NL80211_IFTYPE_UNSPECIFIED:
2948 case NL80211_IFTYPE_STATION:
2949 case NL80211_IFTYPE_ADHOC:
2950 adapter->curr_iface_comb.sta_intf++;
2952 case NL80211_IFTYPE_AP:
2953 adapter->curr_iface_comb.uap_intf++;
2955 case NL80211_IFTYPE_P2P_CLIENT:
2956 adapter->curr_iface_comb.p2p_intf++;
2959 mwifiex_dbg(adapter, ERROR, "type not supported\n");
2960 return ERR_PTR(-EINVAL);
2965 EXPORT_SYMBOL_GPL(mwifiex_add_virtual_intf);
2968 * del_virtual_intf: remove the virtual interface determined by dev
2970 int mwifiex_del_virtual_intf(struct wiphy *wiphy, struct wireless_dev *wdev)
2972 struct mwifiex_private *priv = mwifiex_netdev_get_priv(wdev->netdev);
2973 struct mwifiex_adapter *adapter = priv->adapter;
2974 struct sk_buff *skb, *tmp;
2976 #ifdef CONFIG_DEBUG_FS
2977 mwifiex_dev_debugfs_remove(priv);
2980 if (priv->sched_scanning)
2981 priv->sched_scanning = false;
2983 mwifiex_stop_net_dev_queue(priv->netdev, adapter);
2985 skb_queue_walk_safe(&priv->bypass_txq, skb, tmp)
2986 mwifiex_write_data_complete(priv->adapter, skb, 0, -1);
2988 if (netif_carrier_ok(priv->netdev))
2989 netif_carrier_off(priv->netdev);
2991 if (wdev->netdev->reg_state == NETREG_REGISTERED)
2992 unregister_netdevice(wdev->netdev);
2994 if (priv->dfs_cac_workqueue) {
2995 flush_workqueue(priv->dfs_cac_workqueue);
2996 destroy_workqueue(priv->dfs_cac_workqueue);
2997 priv->dfs_cac_workqueue = NULL;
3000 if (priv->dfs_chan_sw_workqueue) {
3001 flush_workqueue(priv->dfs_chan_sw_workqueue);
3002 destroy_workqueue(priv->dfs_chan_sw_workqueue);
3003 priv->dfs_chan_sw_workqueue = NULL;
3005 /* Clear the priv in adapter */
3006 priv->netdev->ieee80211_ptr = NULL;
3007 priv->netdev = NULL;
3008 priv->wdev.iftype = NL80211_IFTYPE_UNSPECIFIED;
3010 priv->media_connected = false;
3012 switch (priv->bss_mode) {
3013 case NL80211_IFTYPE_UNSPECIFIED:
3014 case NL80211_IFTYPE_STATION:
3015 case NL80211_IFTYPE_ADHOC:
3016 adapter->curr_iface_comb.sta_intf--;
3018 case NL80211_IFTYPE_AP:
3019 adapter->curr_iface_comb.uap_intf--;
3021 case NL80211_IFTYPE_P2P_CLIENT:
3022 case NL80211_IFTYPE_P2P_GO:
3023 adapter->curr_iface_comb.p2p_intf--;
3026 mwifiex_dbg(adapter, ERROR,
3027 "del_virtual_intf: type not supported\n");
3031 priv->bss_mode = NL80211_IFTYPE_UNSPECIFIED;
3033 if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA ||
3034 GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_UAP)
3035 kfree(priv->hist_data);
3039 EXPORT_SYMBOL_GPL(mwifiex_del_virtual_intf);
3042 mwifiex_is_pattern_supported(struct cfg80211_pkt_pattern *pat, s8 *byte_seq,
3045 int j, k, valid_byte_cnt = 0;
3046 bool dont_care_byte = false;
3048 for (j = 0; j < DIV_ROUND_UP(pat->pattern_len, 8); j++) {
3049 for (k = 0; k < 8; k++) {
3050 if (pat->mask[j] & 1 << k) {
3051 memcpy(byte_seq + valid_byte_cnt,
3052 &pat->pattern[j * 8 + k], 1);
3058 dont_care_byte = true;
3061 /* wildcard bytes record as the offset
3062 * before the valid byte
3064 if (!valid_byte_cnt && !dont_care_byte)
3067 if (valid_byte_cnt > max_byte_seq)
3072 byte_seq[max_byte_seq] = valid_byte_cnt;
3078 static void mwifiex_set_auto_arp_mef_entry(struct mwifiex_private *priv,
3079 struct mwifiex_mef_entry *mef_entry)
3081 int i, filt_num = 0, num_ipv4 = 0;
3082 struct in_device *in_dev;
3083 struct in_ifaddr *ifa;
3084 __be32 ips[MWIFIEX_MAX_SUPPORTED_IPADDR];
3085 struct mwifiex_adapter *adapter = priv->adapter;
3087 mef_entry->mode = MEF_MODE_HOST_SLEEP;
3088 mef_entry->action = MEF_ACTION_AUTO_ARP;
3090 /* Enable ARP offload feature */
3091 memset(ips, 0, sizeof(ips));
3092 for (i = 0; i < MWIFIEX_MAX_BSS_NUM; i++) {
3093 if (adapter->priv[i]->netdev) {
3094 in_dev = __in_dev_get_rtnl(adapter->priv[i]->netdev);
3097 ifa = in_dev->ifa_list;
3098 if (!ifa || !ifa->ifa_local)
3100 ips[i] = ifa->ifa_local;
3105 for (i = 0; i < num_ipv4; i++) {
3108 mef_entry->filter[filt_num].repeat = 1;
3109 memcpy(mef_entry->filter[filt_num].byte_seq,
3110 (u8 *)&ips[i], sizeof(ips[i]));
3111 mef_entry->filter[filt_num].
3112 byte_seq[MWIFIEX_MEF_MAX_BYTESEQ] =
3114 mef_entry->filter[filt_num].offset = 46;
3115 mef_entry->filter[filt_num].filt_type = TYPE_EQ;
3117 mef_entry->filter[filt_num].filt_action =
3123 mef_entry->filter[filt_num].repeat = 1;
3124 mef_entry->filter[filt_num].byte_seq[0] = 0x08;
3125 mef_entry->filter[filt_num].byte_seq[1] = 0x06;
3126 mef_entry->filter[filt_num].byte_seq[MWIFIEX_MEF_MAX_BYTESEQ] = 2;
3127 mef_entry->filter[filt_num].offset = 20;
3128 mef_entry->filter[filt_num].filt_type = TYPE_EQ;
3129 mef_entry->filter[filt_num].filt_action = TYPE_AND;
3132 static int mwifiex_set_wowlan_mef_entry(struct mwifiex_private *priv,
3133 struct mwifiex_ds_mef_cfg *mef_cfg,
3134 struct mwifiex_mef_entry *mef_entry,
3135 struct cfg80211_wowlan *wowlan)
3137 int i, filt_num = 0, ret = 0;
3138 bool first_pat = true;
3139 u8 byte_seq[MWIFIEX_MEF_MAX_BYTESEQ + 1];
3140 const u8 ipv4_mc_mac[] = {0x33, 0x33};
3141 const u8 ipv6_mc_mac[] = {0x01, 0x00, 0x5e};
3143 mef_entry->mode = MEF_MODE_HOST_SLEEP;
3144 mef_entry->action = MEF_ACTION_ALLOW_AND_WAKEUP_HOST;
3146 for (i = 0; i < wowlan->n_patterns; i++) {
3147 memset(byte_seq, 0, sizeof(byte_seq));
3148 if (!mwifiex_is_pattern_supported(&wowlan->patterns[i],
3150 MWIFIEX_MEF_MAX_BYTESEQ)) {
3151 mwifiex_dbg(priv->adapter, ERROR,
3152 "Pattern not supported\n");
3156 if (!wowlan->patterns[i].pkt_offset) {
3157 if (!(byte_seq[0] & 0x01) &&
3158 (byte_seq[MWIFIEX_MEF_MAX_BYTESEQ] == 1)) {
3159 mef_cfg->criteria |= MWIFIEX_CRITERIA_UNICAST;
3161 } else if (is_broadcast_ether_addr(byte_seq)) {
3162 mef_cfg->criteria |= MWIFIEX_CRITERIA_BROADCAST;
3164 } else if ((!memcmp(byte_seq, ipv4_mc_mac, 2) &&
3165 (byte_seq[MWIFIEX_MEF_MAX_BYTESEQ] == 2)) ||
3166 (!memcmp(byte_seq, ipv6_mc_mac, 3) &&
3167 (byte_seq[MWIFIEX_MEF_MAX_BYTESEQ] == 3))) {
3168 mef_cfg->criteria |= MWIFIEX_CRITERIA_MULTICAST;
3172 mef_entry->filter[filt_num].repeat = 1;
3173 mef_entry->filter[filt_num].offset =
3174 wowlan->patterns[i].pkt_offset;
3175 memcpy(mef_entry->filter[filt_num].byte_seq, byte_seq,
3177 mef_entry->filter[filt_num].filt_type = TYPE_EQ;
3181 mwifiex_dbg(priv->adapter, INFO, "Wake on patterns\n");
3183 mef_entry->filter[filt_num].filt_action = TYPE_AND;
3189 if (wowlan->magic_pkt) {
3190 mef_cfg->criteria |= MWIFIEX_CRITERIA_UNICAST;
3191 mef_entry->filter[filt_num].repeat = 16;
3192 memcpy(mef_entry->filter[filt_num].byte_seq, priv->curr_addr,
3194 mef_entry->filter[filt_num].byte_seq[MWIFIEX_MEF_MAX_BYTESEQ] =
3196 mef_entry->filter[filt_num].offset = 28;
3197 mef_entry->filter[filt_num].filt_type = TYPE_EQ;
3199 mef_entry->filter[filt_num].filt_action = TYPE_OR;
3202 mef_entry->filter[filt_num].repeat = 16;
3203 memcpy(mef_entry->filter[filt_num].byte_seq, priv->curr_addr,
3205 mef_entry->filter[filt_num].byte_seq[MWIFIEX_MEF_MAX_BYTESEQ] =
3207 mef_entry->filter[filt_num].offset = 56;
3208 mef_entry->filter[filt_num].filt_type = TYPE_EQ;
3209 mef_entry->filter[filt_num].filt_action = TYPE_OR;
3210 mwifiex_dbg(priv->adapter, INFO, "Wake on magic packet\n");
3215 static int mwifiex_set_mef_filter(struct mwifiex_private *priv,
3216 struct cfg80211_wowlan *wowlan)
3218 int ret = 0, num_entries = 1;
3219 struct mwifiex_ds_mef_cfg mef_cfg;
3220 struct mwifiex_mef_entry *mef_entry;
3222 if (wowlan->n_patterns || wowlan->magic_pkt)
3225 mef_entry = kcalloc(num_entries, sizeof(*mef_entry), GFP_KERNEL);
3229 memset(&mef_cfg, 0, sizeof(mef_cfg));
3230 mef_cfg.criteria |= MWIFIEX_CRITERIA_BROADCAST |
3231 MWIFIEX_CRITERIA_UNICAST;
3232 mef_cfg.num_entries = num_entries;
3233 mef_cfg.mef_entry = mef_entry;
3235 mwifiex_set_auto_arp_mef_entry(priv, &mef_entry[0]);
3237 if (wowlan->n_patterns || wowlan->magic_pkt) {
3238 ret = mwifiex_set_wowlan_mef_entry(priv, &mef_cfg,
3239 &mef_entry[1], wowlan);
3244 if (!mef_cfg.criteria)
3245 mef_cfg.criteria = MWIFIEX_CRITERIA_BROADCAST |
3246 MWIFIEX_CRITERIA_UNICAST |
3247 MWIFIEX_CRITERIA_MULTICAST;
3249 ret = mwifiex_send_cmd(priv, HostCmd_CMD_MEF_CFG,
3250 HostCmd_ACT_GEN_SET, 0,
3258 static int mwifiex_cfg80211_suspend(struct wiphy *wiphy,
3259 struct cfg80211_wowlan *wowlan)
3261 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
3262 struct mwifiex_ds_hs_cfg hs_cfg;
3263 int i, ret = 0, retry_num = 10;
3264 struct mwifiex_private *priv;
3266 for (i = 0; i < adapter->priv_num; i++) {
3267 priv = adapter->priv[i];
3268 mwifiex_abort_cac(priv);
3271 mwifiex_cancel_all_pending_cmd(adapter);
3273 for (i = 0; i < adapter->priv_num; i++) {
3274 priv = adapter->priv[i];
3275 if (priv && priv->netdev)
3276 mwifiex_stop_net_dev_queue(priv->netdev, adapter);
3279 for (i = 0; i < retry_num; i++) {
3280 if (!mwifiex_wmm_lists_empty(adapter) ||
3281 !mwifiex_bypass_txlist_empty(adapter) ||
3282 !skb_queue_empty(&adapter->tx_data_q))
3283 usleep_range(10000, 15000);
3289 mwifiex_dbg(adapter, ERROR,
3290 "None of the WOWLAN triggers enabled\n");
3294 priv = mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_STA);
3296 if (!priv->media_connected && !wowlan->nd_config) {
3297 mwifiex_dbg(adapter, ERROR,
3298 "Can not configure WOWLAN in disconnected state\n");
3302 ret = mwifiex_set_mef_filter(priv, wowlan);
3304 mwifiex_dbg(adapter, ERROR, "Failed to set MEF filter\n");
3308 memset(&hs_cfg, 0, sizeof(hs_cfg));
3309 hs_cfg.conditions = le32_to_cpu(adapter->hs_cfg.conditions);
3311 if (wowlan->nd_config) {
3312 mwifiex_dbg(adapter, INFO, "Wake on net detect\n");
3313 hs_cfg.conditions |= HS_CFG_COND_MAC_EVENT;
3314 mwifiex_cfg80211_sched_scan_start(wiphy, priv->netdev,
3318 if (wowlan->disconnect) {
3319 hs_cfg.conditions |= HS_CFG_COND_MAC_EVENT;
3320 mwifiex_dbg(priv->adapter, INFO, "Wake on device disconnect\n");
3323 hs_cfg.is_invoke_hostcmd = false;
3324 hs_cfg.gpio = adapter->hs_cfg.gpio;
3325 hs_cfg.gap = adapter->hs_cfg.gap;
3326 ret = mwifiex_set_hs_params(priv, HostCmd_ACT_GEN_SET,
3327 MWIFIEX_SYNC_CMD, &hs_cfg);
3329 mwifiex_dbg(adapter, ERROR,
3330 "Failed to set HS params\n");
3337 static int mwifiex_cfg80211_resume(struct wiphy *wiphy)
3339 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
3340 struct mwifiex_private *priv;
3341 struct mwifiex_ds_wakeup_reason wakeup_reason;
3342 struct cfg80211_wowlan_wakeup wakeup_report;
3345 for (i = 0; i < adapter->priv_num; i++) {
3346 priv = adapter->priv[i];
3347 if (priv && priv->netdev)
3348 mwifiex_wake_up_net_dev_queue(priv->netdev, adapter);
3351 priv = mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_STA);
3352 mwifiex_get_wakeup_reason(priv, HostCmd_ACT_GEN_GET, MWIFIEX_SYNC_CMD,
3354 memset(&wakeup_report, 0, sizeof(struct cfg80211_wowlan_wakeup));
3356 wakeup_report.pattern_idx = -1;
3358 switch (wakeup_reason.hs_wakeup_reason) {
3359 case NO_HSWAKEUP_REASON:
3361 case BCAST_DATA_MATCHED:
3363 case MCAST_DATA_MATCHED:
3365 case UCAST_DATA_MATCHED:
3367 case MASKTABLE_EVENT_MATCHED:
3369 case NON_MASKABLE_EVENT_MATCHED:
3370 if (wiphy->wowlan_config->disconnect)
3371 wakeup_report.disconnect = true;
3372 if (wiphy->wowlan_config->nd_config)
3373 wakeup_report.net_detect = adapter->nd_info;
3375 case NON_MASKABLE_CONDITION_MATCHED:
3377 case MAGIC_PATTERN_MATCHED:
3378 if (wiphy->wowlan_config->magic_pkt)
3379 wakeup_report.magic_pkt = true;
3380 if (wiphy->wowlan_config->n_patterns)
3381 wakeup_report.pattern_idx = 1;
3383 case CONTROL_FRAME_MATCHED:
3385 case MANAGEMENT_FRAME_MATCHED:
3391 if ((wakeup_reason.hs_wakeup_reason > 0) &&
3392 (wakeup_reason.hs_wakeup_reason <= 7))
3393 cfg80211_report_wowlan_wakeup(&priv->wdev, &wakeup_report,
3396 if (adapter->nd_info) {
3397 for (i = 0 ; i < adapter->nd_info->n_matches ; i++)
3398 kfree(adapter->nd_info->matches[i]);
3399 kfree(adapter->nd_info);
3400 adapter->nd_info = NULL;
3406 static void mwifiex_cfg80211_set_wakeup(struct wiphy *wiphy,
3409 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
3411 device_set_wakeup_enable(adapter->dev, enabled);
3415 static int mwifiex_get_coalesce_pkt_type(u8 *byte_seq)
3417 const u8 ipv4_mc_mac[] = {0x33, 0x33};
3418 const u8 ipv6_mc_mac[] = {0x01, 0x00, 0x5e};
3419 const u8 bc_mac[] = {0xff, 0xff, 0xff, 0xff};
3421 if ((byte_seq[0] & 0x01) &&
3422 (byte_seq[MWIFIEX_COALESCE_MAX_BYTESEQ] == 1))
3423 return PACKET_TYPE_UNICAST;
3424 else if (!memcmp(byte_seq, bc_mac, 4))
3425 return PACKET_TYPE_BROADCAST;
3426 else if ((!memcmp(byte_seq, ipv4_mc_mac, 2) &&
3427 byte_seq[MWIFIEX_COALESCE_MAX_BYTESEQ] == 2) ||
3428 (!memcmp(byte_seq, ipv6_mc_mac, 3) &&
3429 byte_seq[MWIFIEX_COALESCE_MAX_BYTESEQ] == 3))
3430 return PACKET_TYPE_MULTICAST;
3436 mwifiex_fill_coalesce_rule_info(struct mwifiex_private *priv,
3437 struct cfg80211_coalesce_rules *crule,
3438 struct mwifiex_coalesce_rule *mrule)
3440 u8 byte_seq[MWIFIEX_COALESCE_MAX_BYTESEQ + 1];
3441 struct filt_field_param *param;
3444 mrule->max_coalescing_delay = crule->delay;
3446 param = mrule->params;
3448 for (i = 0; i < crule->n_patterns; i++) {
3449 memset(byte_seq, 0, sizeof(byte_seq));
3450 if (!mwifiex_is_pattern_supported(&crule->patterns[i],
3452 MWIFIEX_COALESCE_MAX_BYTESEQ)) {
3453 mwifiex_dbg(priv->adapter, ERROR,
3454 "Pattern not supported\n");
3458 if (!crule->patterns[i].pkt_offset) {
3461 pkt_type = mwifiex_get_coalesce_pkt_type(byte_seq);
3462 if (pkt_type && mrule->pkt_type) {
3463 mwifiex_dbg(priv->adapter, ERROR,
3464 "Multiple packet types not allowed\n");
3466 } else if (pkt_type) {
3467 mrule->pkt_type = pkt_type;
3472 if (crule->condition == NL80211_COALESCE_CONDITION_MATCH)
3473 param->operation = RECV_FILTER_MATCH_TYPE_EQ;
3475 param->operation = RECV_FILTER_MATCH_TYPE_NE;
3477 param->operand_len = byte_seq[MWIFIEX_COALESCE_MAX_BYTESEQ];
3478 memcpy(param->operand_byte_stream, byte_seq,
3479 param->operand_len);
3480 param->offset = crule->patterns[i].pkt_offset;
3483 mrule->num_of_fields++;
3486 if (!mrule->pkt_type) {
3487 mwifiex_dbg(priv->adapter, ERROR,
3488 "Packet type can not be determined\n");
3495 static int mwifiex_cfg80211_set_coalesce(struct wiphy *wiphy,
3496 struct cfg80211_coalesce *coalesce)
3498 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
3500 struct mwifiex_ds_coalesce_cfg coalesce_cfg;
3501 struct mwifiex_private *priv =
3502 mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_STA);
3504 memset(&coalesce_cfg, 0, sizeof(coalesce_cfg));
3506 mwifiex_dbg(adapter, WARN,
3507 "Disable coalesce and reset all previous rules\n");
3508 return mwifiex_send_cmd(priv, HostCmd_CMD_COALESCE_CFG,
3509 HostCmd_ACT_GEN_SET, 0,
3510 &coalesce_cfg, true);
3513 coalesce_cfg.num_of_rules = coalesce->n_rules;
3514 for (i = 0; i < coalesce->n_rules; i++) {
3515 ret = mwifiex_fill_coalesce_rule_info(priv, &coalesce->rules[i],
3516 &coalesce_cfg.rule[i]);
3518 mwifiex_dbg(adapter, ERROR,
3519 "Recheck the patterns provided for rule %d\n",
3525 return mwifiex_send_cmd(priv, HostCmd_CMD_COALESCE_CFG,
3526 HostCmd_ACT_GEN_SET, 0, &coalesce_cfg, true);
3529 /* cfg80211 ops handler for tdls_mgmt.
3530 * Function prepares TDLS action frame packets and forwards them to FW
3533 mwifiex_cfg80211_tdls_mgmt(struct wiphy *wiphy, struct net_device *dev,
3534 const u8 *peer, u8 action_code, u8 dialog_token,
3535 u16 status_code, u32 peer_capability,
3536 bool initiator, const u8 *extra_ies,
3537 size_t extra_ies_len)
3539 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
3542 if (!(wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS))
3545 /* make sure we are in station mode and connected */
3546 if (!(priv->bss_type == MWIFIEX_BSS_TYPE_STA && priv->media_connected))
3549 switch (action_code) {
3550 case WLAN_TDLS_SETUP_REQUEST:
3551 mwifiex_dbg(priv->adapter, MSG,
3552 "Send TDLS Setup Request to %pM status_code=%d\n",
3554 mwifiex_add_auto_tdls_peer(priv, peer);
3555 ret = mwifiex_send_tdls_data_frame(priv, peer, action_code,
3556 dialog_token, status_code,
3557 extra_ies, extra_ies_len);
3559 case WLAN_TDLS_SETUP_RESPONSE:
3560 mwifiex_add_auto_tdls_peer(priv, peer);
3561 mwifiex_dbg(priv->adapter, MSG,
3562 "Send TDLS Setup Response to %pM status_code=%d\n",
3564 ret = mwifiex_send_tdls_data_frame(priv, peer, action_code,
3565 dialog_token, status_code,
3566 extra_ies, extra_ies_len);
3568 case WLAN_TDLS_SETUP_CONFIRM:
3569 mwifiex_dbg(priv->adapter, MSG,
3570 "Send TDLS Confirm to %pM status_code=%d\n", peer,
3572 ret = mwifiex_send_tdls_data_frame(priv, peer, action_code,
3573 dialog_token, status_code,
3574 extra_ies, extra_ies_len);
3576 case WLAN_TDLS_TEARDOWN:
3577 mwifiex_dbg(priv->adapter, MSG,
3578 "Send TDLS Tear down to %pM\n", peer);
3579 ret = mwifiex_send_tdls_data_frame(priv, peer, action_code,
3580 dialog_token, status_code,
3581 extra_ies, extra_ies_len);
3583 case WLAN_TDLS_DISCOVERY_REQUEST:
3584 mwifiex_dbg(priv->adapter, MSG,
3585 "Send TDLS Discovery Request to %pM\n", peer);
3586 ret = mwifiex_send_tdls_data_frame(priv, peer, action_code,
3587 dialog_token, status_code,
3588 extra_ies, extra_ies_len);
3590 case WLAN_PUB_ACTION_TDLS_DISCOVER_RES:
3591 mwifiex_dbg(priv->adapter, MSG,
3592 "Send TDLS Discovery Response to %pM\n", peer);
3593 ret = mwifiex_send_tdls_action_frame(priv, peer, action_code,
3594 dialog_token, status_code,
3595 extra_ies, extra_ies_len);
3598 mwifiex_dbg(priv->adapter, ERROR,
3599 "Unknown TDLS mgmt/action frame %pM\n", peer);
3608 mwifiex_cfg80211_tdls_oper(struct wiphy *wiphy, struct net_device *dev,
3609 const u8 *peer, enum nl80211_tdls_operation action)
3611 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
3613 if (!(wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
3614 !(wiphy->flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP))
3617 /* make sure we are in station mode and connected */
3618 if (!(priv->bss_type == MWIFIEX_BSS_TYPE_STA && priv->media_connected))
3621 mwifiex_dbg(priv->adapter, MSG,
3622 "TDLS peer=%pM, oper=%d\n", peer, action);
3625 case NL80211_TDLS_ENABLE_LINK:
3626 action = MWIFIEX_TDLS_ENABLE_LINK;
3628 case NL80211_TDLS_DISABLE_LINK:
3629 action = MWIFIEX_TDLS_DISABLE_LINK;
3631 case NL80211_TDLS_TEARDOWN:
3632 /* shouldn't happen!*/
3633 mwifiex_dbg(priv->adapter, ERROR,
3634 "tdls_oper: teardown from driver not supported\n");
3636 case NL80211_TDLS_SETUP:
3637 /* shouldn't happen!*/
3638 mwifiex_dbg(priv->adapter, ERROR,
3639 "tdls_oper: setup from driver not supported\n");
3641 case NL80211_TDLS_DISCOVERY_REQ:
3642 /* shouldn't happen!*/
3643 mwifiex_dbg(priv->adapter, ERROR,
3644 "tdls_oper: discovery from driver not supported\n");
3647 mwifiex_dbg(priv->adapter, ERROR,
3648 "tdls_oper: operation not supported\n");
3652 return mwifiex_tdls_oper(priv, peer, action);
3656 mwifiex_cfg80211_tdls_chan_switch(struct wiphy *wiphy, struct net_device *dev,
3657 const u8 *addr, u8 oper_class,
3658 struct cfg80211_chan_def *chandef)
3660 struct mwifiex_sta_node *sta_ptr;
3661 unsigned long flags;
3663 u8 second_chan_offset, band;
3664 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
3666 spin_lock_irqsave(&priv->sta_list_spinlock, flags);
3667 sta_ptr = mwifiex_get_sta_entry(priv, addr);
3668 spin_unlock_irqrestore(&priv->sta_list_spinlock, flags);
3671 wiphy_err(wiphy, "%s: Invalid TDLS peer %pM\n",
3676 if (!(sta_ptr->tdls_cap.extcap.ext_capab[3] &
3677 WLAN_EXT_CAPA4_TDLS_CHAN_SWITCH)) {
3678 wiphy_err(wiphy, "%pM do not support tdls cs\n", addr);
3682 if (sta_ptr->tdls_status == TDLS_CHAN_SWITCHING ||
3683 sta_ptr->tdls_status == TDLS_IN_OFF_CHAN) {
3684 wiphy_err(wiphy, "channel switch is running, abort request\n");
3688 chan = chandef->chan->hw_value;
3689 second_chan_offset = mwifiex_get_sec_chan_offset(chan);
3690 band = chandef->chan->band;
3691 mwifiex_start_tdls_cs(priv, addr, chan, second_chan_offset, band);
3697 mwifiex_cfg80211_tdls_cancel_chan_switch(struct wiphy *wiphy,
3698 struct net_device *dev,
3701 struct mwifiex_sta_node *sta_ptr;
3702 unsigned long flags;
3703 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
3705 spin_lock_irqsave(&priv->sta_list_spinlock, flags);
3706 sta_ptr = mwifiex_get_sta_entry(priv, addr);
3707 spin_unlock_irqrestore(&priv->sta_list_spinlock, flags);
3710 wiphy_err(wiphy, "%s: Invalid TDLS peer %pM\n",
3712 } else if (!(sta_ptr->tdls_status == TDLS_CHAN_SWITCHING ||
3713 sta_ptr->tdls_status == TDLS_IN_BASE_CHAN ||
3714 sta_ptr->tdls_status == TDLS_IN_OFF_CHAN)) {
3715 wiphy_err(wiphy, "tdls chan switch not initialize by %pM\n",
3718 mwifiex_stop_tdls_cs(priv, addr);
3722 mwifiex_cfg80211_add_station(struct wiphy *wiphy, struct net_device *dev,
3723 const u8 *mac, struct station_parameters *params)
3725 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
3727 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
3730 /* make sure we are in station mode and connected */
3731 if ((priv->bss_type != MWIFIEX_BSS_TYPE_STA) || !priv->media_connected)
3734 return mwifiex_tdls_oper(priv, mac, MWIFIEX_TDLS_CREATE_LINK);
3738 mwifiex_cfg80211_channel_switch(struct wiphy *wiphy, struct net_device *dev,
3739 struct cfg80211_csa_settings *params)
3741 struct ieee_types_header *chsw_ie;
3742 struct ieee80211_channel_sw_ie *channel_sw;
3744 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
3746 if (priv->adapter->scan_processing) {
3747 mwifiex_dbg(priv->adapter, ERROR,
3748 "radar detection: scan in process...\n");
3752 if (priv->wdev.cac_started)
3755 if (cfg80211_chandef_identical(¶ms->chandef,
3756 &priv->dfs_chandef))
3759 chsw_ie = (void *)cfg80211_find_ie(WLAN_EID_CHANNEL_SWITCH,
3760 params->beacon_csa.tail,
3761 params->beacon_csa.tail_len);
3763 mwifiex_dbg(priv->adapter, ERROR,
3764 "Could not parse channel switch announcement IE\n");
3768 channel_sw = (void *)(chsw_ie + 1);
3769 if (channel_sw->mode) {
3770 if (netif_carrier_ok(priv->netdev))
3771 netif_carrier_off(priv->netdev);
3772 mwifiex_stop_net_dev_queue(priv->netdev, priv->adapter);
3775 if (mwifiex_del_mgmt_ies(priv))
3776 mwifiex_dbg(priv->adapter, ERROR,
3777 "Failed to delete mgmt IEs!\n");
3779 if (mwifiex_set_mgmt_ies(priv, ¶ms->beacon_csa)) {
3780 mwifiex_dbg(priv->adapter, ERROR,
3781 "%s: setting mgmt ies failed\n", __func__);
3785 memcpy(&priv->dfs_chandef, ¶ms->chandef, sizeof(priv->dfs_chandef));
3786 memcpy(&priv->beacon_after, ¶ms->beacon_after,
3787 sizeof(priv->beacon_after));
3789 chsw_msec = max(channel_sw->count * priv->bss_cfg.beacon_period, 100);
3790 queue_delayed_work(priv->dfs_chan_sw_workqueue, &priv->dfs_chan_sw_work,
3791 msecs_to_jiffies(chsw_msec));
3795 static int mwifiex_cfg80211_get_channel(struct wiphy *wiphy,
3796 struct wireless_dev *wdev,
3797 struct cfg80211_chan_def *chandef)
3799 struct mwifiex_private *priv = mwifiex_netdev_get_priv(wdev->netdev);
3800 struct mwifiex_bssdescriptor *curr_bss;
3801 struct ieee80211_channel *chan;
3802 u8 second_chan_offset;
3803 enum nl80211_channel_type chan_type;
3804 enum ieee80211_band band;
3808 if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_UAP &&
3809 cfg80211_chandef_valid(&priv->bss_chandef)) {
3810 *chandef = priv->bss_chandef;
3812 } else if (priv->media_connected) {
3813 curr_bss = &priv->curr_bss_params.bss_descriptor;
3814 band = mwifiex_band_to_radio_type(priv->curr_bss_params.band);
3815 freq = ieee80211_channel_to_frequency(curr_bss->channel, band);
3816 chan = ieee80211_get_channel(wiphy, freq);
3818 if (priv->ht_param_present) {
3819 second_chan_offset = priv->assoc_resp_ht_param &
3820 IEEE80211_HT_PARAM_CHA_SEC_OFFSET;
3821 chan_type = mwifiex_sec_chan_offset_to_chan_type
3822 (second_chan_offset);
3823 cfg80211_chandef_create(chandef, chan, chan_type);
3825 cfg80211_chandef_create(chandef, chan,
3826 NL80211_CHAN_NO_HT);
3835 mwifiex_cfg80211_start_radar_detection(struct wiphy *wiphy,
3836 struct net_device *dev,
3837 struct cfg80211_chan_def *chandef,
3840 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
3841 struct mwifiex_radar_params radar_params;
3843 if (priv->adapter->scan_processing) {
3844 mwifiex_dbg(priv->adapter, ERROR,
3845 "radar detection: scan already in process...\n");
3849 if (!mwifiex_is_11h_active(priv)) {
3850 mwifiex_dbg(priv->adapter, INFO,
3851 "Enable 11h extensions in FW\n");
3852 if (mwifiex_11h_activate(priv, true)) {
3853 mwifiex_dbg(priv->adapter, ERROR,
3854 "Failed to activate 11h extensions!!");
3857 priv->state_11h.is_11h_active = true;
3860 memset(&radar_params, 0, sizeof(struct mwifiex_radar_params));
3861 radar_params.chandef = chandef;
3862 radar_params.cac_time_ms = cac_time_ms;
3864 memcpy(&priv->dfs_chandef, chandef, sizeof(priv->dfs_chandef));
3866 if (mwifiex_send_cmd(priv, HostCmd_CMD_CHAN_REPORT_REQUEST,
3867 HostCmd_ACT_GEN_SET, 0, &radar_params, true))
3870 queue_delayed_work(priv->dfs_cac_workqueue, &priv->dfs_cac_work,
3871 msecs_to_jiffies(cac_time_ms));
3876 mwifiex_cfg80211_change_station(struct wiphy *wiphy, struct net_device *dev,
3878 struct station_parameters *params)
3881 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
3883 /* we support change_station handler only for TDLS peers*/
3884 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
3887 /* make sure we are in station mode and connected */
3888 if ((priv->bss_type != MWIFIEX_BSS_TYPE_STA) || !priv->media_connected)
3891 priv->sta_params = params;
3893 ret = mwifiex_tdls_oper(priv, mac, MWIFIEX_TDLS_CONFIG_LINK);
3894 priv->sta_params = NULL;
3899 /* station cfg80211 operations */
3900 static struct cfg80211_ops mwifiex_cfg80211_ops = {
3901 .add_virtual_intf = mwifiex_add_virtual_intf,
3902 .del_virtual_intf = mwifiex_del_virtual_intf,
3903 .change_virtual_intf = mwifiex_cfg80211_change_virtual_intf,
3904 .scan = mwifiex_cfg80211_scan,
3905 .connect = mwifiex_cfg80211_connect,
3906 .disconnect = mwifiex_cfg80211_disconnect,
3907 .get_station = mwifiex_cfg80211_get_station,
3908 .dump_station = mwifiex_cfg80211_dump_station,
3909 .dump_survey = mwifiex_cfg80211_dump_survey,
3910 .set_wiphy_params = mwifiex_cfg80211_set_wiphy_params,
3911 .join_ibss = mwifiex_cfg80211_join_ibss,
3912 .leave_ibss = mwifiex_cfg80211_leave_ibss,
3913 .add_key = mwifiex_cfg80211_add_key,
3914 .del_key = mwifiex_cfg80211_del_key,
3915 .mgmt_tx = mwifiex_cfg80211_mgmt_tx,
3916 .mgmt_frame_register = mwifiex_cfg80211_mgmt_frame_register,
3917 .remain_on_channel = mwifiex_cfg80211_remain_on_channel,
3918 .cancel_remain_on_channel = mwifiex_cfg80211_cancel_remain_on_channel,
3919 .set_default_key = mwifiex_cfg80211_set_default_key,
3920 .set_power_mgmt = mwifiex_cfg80211_set_power_mgmt,
3921 .set_tx_power = mwifiex_cfg80211_set_tx_power,
3922 .set_bitrate_mask = mwifiex_cfg80211_set_bitrate_mask,
3923 .start_ap = mwifiex_cfg80211_start_ap,
3924 .stop_ap = mwifiex_cfg80211_stop_ap,
3925 .change_beacon = mwifiex_cfg80211_change_beacon,
3926 .set_cqm_rssi_config = mwifiex_cfg80211_set_cqm_rssi_config,
3927 .set_antenna = mwifiex_cfg80211_set_antenna,
3928 .del_station = mwifiex_cfg80211_del_station,
3929 .sched_scan_start = mwifiex_cfg80211_sched_scan_start,
3930 .sched_scan_stop = mwifiex_cfg80211_sched_scan_stop,
3932 .suspend = mwifiex_cfg80211_suspend,
3933 .resume = mwifiex_cfg80211_resume,
3934 .set_wakeup = mwifiex_cfg80211_set_wakeup,
3936 .set_coalesce = mwifiex_cfg80211_set_coalesce,
3937 .tdls_mgmt = mwifiex_cfg80211_tdls_mgmt,
3938 .tdls_oper = mwifiex_cfg80211_tdls_oper,
3939 .tdls_channel_switch = mwifiex_cfg80211_tdls_chan_switch,
3940 .tdls_cancel_channel_switch = mwifiex_cfg80211_tdls_cancel_chan_switch,
3941 .add_station = mwifiex_cfg80211_add_station,
3942 .change_station = mwifiex_cfg80211_change_station,
3943 .get_channel = mwifiex_cfg80211_get_channel,
3944 .start_radar_detection = mwifiex_cfg80211_start_radar_detection,
3945 .channel_switch = mwifiex_cfg80211_channel_switch,
3949 static const struct wiphy_wowlan_support mwifiex_wowlan_support = {
3950 .flags = WIPHY_WOWLAN_MAGIC_PKT | WIPHY_WOWLAN_DISCONNECT |
3951 WIPHY_WOWLAN_NET_DETECT,
3952 .n_patterns = MWIFIEX_MEF_MAX_FILTERS,
3953 .pattern_min_len = 1,
3954 .pattern_max_len = MWIFIEX_MAX_PATTERN_LEN,
3955 .max_pkt_offset = MWIFIEX_MAX_OFFSET_LEN,
3956 .max_nd_match_sets = MWIFIEX_MAX_ND_MATCH_SETS,
3960 static bool mwifiex_is_valid_alpha2(const char *alpha2)
3962 if (!alpha2 || strlen(alpha2) != 2)
3965 if (isalpha(alpha2[0]) && isalpha(alpha2[1]))
3971 static const struct wiphy_coalesce_support mwifiex_coalesce_support = {
3972 .n_rules = MWIFIEX_COALESCE_MAX_RULES,
3973 .max_delay = MWIFIEX_MAX_COALESCING_DELAY,
3974 .n_patterns = MWIFIEX_COALESCE_MAX_FILTERS,
3975 .pattern_min_len = 1,
3976 .pattern_max_len = MWIFIEX_MAX_PATTERN_LEN,
3977 .max_pkt_offset = MWIFIEX_MAX_OFFSET_LEN,
3980 int mwifiex_init_channel_scan_gap(struct mwifiex_adapter *adapter)
3982 u32 n_channels_bg, n_channels_a = 0;
3984 n_channels_bg = mwifiex_band_2ghz.n_channels;
3986 if (adapter->config_bands & BAND_A)
3987 n_channels_a = mwifiex_band_5ghz.n_channels;
3989 adapter->num_in_chan_stats = max_t(u32, n_channels_bg, n_channels_a);
3990 adapter->chan_stats = vmalloc(sizeof(*adapter->chan_stats) *
3991 adapter->num_in_chan_stats);
3993 if (!adapter->chan_stats)
4000 * This function registers the device with CFG802.11 subsystem.
4002 * The function creates the wireless device/wiphy, populates it with
4003 * default parameters and handler function pointers, and finally
4004 * registers the device.
4007 int mwifiex_register_cfg80211(struct mwifiex_adapter *adapter)
4011 struct wiphy *wiphy;
4012 struct mwifiex_private *priv = adapter->priv[MWIFIEX_BSS_TYPE_STA];
4016 /* create a new wiphy for use with cfg80211 */
4017 wiphy = wiphy_new(&mwifiex_cfg80211_ops,
4018 sizeof(struct mwifiex_adapter *));
4020 mwifiex_dbg(adapter, ERROR,
4021 "%s: creating new wiphy\n", __func__);
4024 wiphy->max_scan_ssids = MWIFIEX_MAX_SSID_LIST_LENGTH;
4025 wiphy->max_scan_ie_len = MWIFIEX_MAX_VSIE_LEN;
4026 wiphy->mgmt_stypes = mwifiex_mgmt_stypes;
4027 wiphy->max_remain_on_channel_duration = 5000;
4028 wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
4029 BIT(NL80211_IFTYPE_ADHOC) |
4030 BIT(NL80211_IFTYPE_P2P_CLIENT) |
4031 BIT(NL80211_IFTYPE_P2P_GO) |
4032 BIT(NL80211_IFTYPE_AP);
4034 wiphy->bands[IEEE80211_BAND_2GHZ] = &mwifiex_band_2ghz;
4035 if (adapter->config_bands & BAND_A)
4036 wiphy->bands[IEEE80211_BAND_5GHZ] = &mwifiex_band_5ghz;
4038 wiphy->bands[IEEE80211_BAND_5GHZ] = NULL;
4040 if (adapter->drcs_enabled && ISSUPP_DRCS_ENABLED(adapter->fw_cap_info))
4041 wiphy->iface_combinations = &mwifiex_iface_comb_ap_sta_drcs;
4042 else if (adapter->is_hw_11ac_capable)
4043 wiphy->iface_combinations = &mwifiex_iface_comb_ap_sta_vht;
4045 wiphy->iface_combinations = &mwifiex_iface_comb_ap_sta;
4046 wiphy->n_iface_combinations = 1;
4048 /* Initialize cipher suits */
4049 wiphy->cipher_suites = mwifiex_cipher_suites;
4050 wiphy->n_cipher_suites = ARRAY_SIZE(mwifiex_cipher_suites);
4052 if (adapter->region_code)
4053 wiphy->regulatory_flags |= REGULATORY_DISABLE_BEACON_HINTS |
4054 REGULATORY_COUNTRY_IE_IGNORE;
4056 ether_addr_copy(wiphy->perm_addr, adapter->perm_addr);
4057 wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
4058 wiphy->flags |= WIPHY_FLAG_HAVE_AP_SME |
4059 WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD |
4060 WIPHY_FLAG_AP_UAPSD |
4061 WIPHY_FLAG_SUPPORTS_SCHED_SCAN |
4062 WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL |
4063 WIPHY_FLAG_HAS_CHANNEL_SWITCH |
4064 WIPHY_FLAG_PS_ON_BY_DEFAULT;
4066 if (ISSUPP_TDLS_ENABLED(adapter->fw_cap_info))
4067 wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS |
4068 WIPHY_FLAG_TDLS_EXTERNAL_SETUP;
4071 wiphy->wowlan = &mwifiex_wowlan_support;
4074 wiphy->coalesce = &mwifiex_coalesce_support;
4076 wiphy->probe_resp_offload = NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS |
4077 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2 |
4078 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P;
4080 wiphy->max_sched_scan_ssids = MWIFIEX_MAX_SSID_LIST_LENGTH;
4081 wiphy->max_sched_scan_ie_len = MWIFIEX_MAX_VSIE_LEN;
4082 wiphy->max_match_sets = MWIFIEX_MAX_SSID_LIST_LENGTH;
4084 wiphy->available_antennas_tx = BIT(adapter->number_of_antenna) - 1;
4085 wiphy->available_antennas_rx = BIT(adapter->number_of_antenna) - 1;
4087 wiphy->features |= NL80211_FEATURE_HT_IBSS |
4088 NL80211_FEATURE_INACTIVITY_TIMER |
4089 NL80211_FEATURE_NEED_OBSS_SCAN;
4091 if (ISSUPP_TDLS_ENABLED(adapter->fw_cap_info))
4092 wiphy->features |= NL80211_FEATURE_TDLS_CHANNEL_SWITCH;
4094 if (adapter->fw_api_ver == MWIFIEX_FW_V15)
4095 wiphy->features |= NL80211_FEATURE_SK_TX_STATUS;
4097 /* Reserve space for mwifiex specific private data for BSS */
4098 wiphy->bss_priv_size = sizeof(struct mwifiex_bss_priv);
4100 wiphy->reg_notifier = mwifiex_reg_notifier;
4102 /* Set struct mwifiex_adapter pointer in wiphy_priv */
4103 wdev_priv = wiphy_priv(wiphy);
4104 *(unsigned long *)wdev_priv = (unsigned long)adapter;
4106 set_wiphy_dev(wiphy, priv->adapter->dev);
4108 ret = wiphy_register(wiphy);
4110 mwifiex_dbg(adapter, ERROR,
4111 "%s: wiphy_register failed: %d\n", __func__, ret);
4116 if (reg_alpha2 && mwifiex_is_valid_alpha2(reg_alpha2)) {
4117 mwifiex_dbg(adapter, INFO,
4118 "driver hint alpha2: %2.2s\n", reg_alpha2);
4119 regulatory_hint(wiphy, reg_alpha2);
4121 if (adapter->region_code == 0x00) {
4122 mwifiex_dbg(adapter, WARN, "Ignore world regulatory domain\n");
4125 mwifiex_11d_code_2_region(adapter->region_code);
4127 regulatory_hint(wiphy, country_code))
4128 mwifiex_dbg(priv->adapter, ERROR, "regulatory_hint() failed\n");
4132 mwifiex_send_cmd(priv, HostCmd_CMD_802_11_SNMP_MIB,
4133 HostCmd_ACT_GEN_GET, FRAG_THRESH_I, &thr, true);
4134 wiphy->frag_threshold = thr;
4135 mwifiex_send_cmd(priv, HostCmd_CMD_802_11_SNMP_MIB,
4136 HostCmd_ACT_GEN_GET, RTS_THRESH_I, &thr, true);
4137 wiphy->rts_threshold = thr;
4138 mwifiex_send_cmd(priv, HostCmd_CMD_802_11_SNMP_MIB,
4139 HostCmd_ACT_GEN_GET, SHORT_RETRY_LIM_I, &retry, true);
4140 wiphy->retry_short = (u8) retry;
4141 mwifiex_send_cmd(priv, HostCmd_CMD_802_11_SNMP_MIB,
4142 HostCmd_ACT_GEN_GET, LONG_RETRY_LIM_I, &retry, true);
4143 wiphy->retry_long = (u8) retry;
4145 adapter->wiphy = wiphy;