2 * Marvell Wireless LAN device driver: CFG80211
4 * Copyright (C) 2011, 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.
23 static const struct ieee80211_iface_limit mwifiex_ap_sta_limits[] = {
25 .max = 1, .types = BIT(NL80211_IFTYPE_STATION),
28 .max = 1, .types = BIT(NL80211_IFTYPE_AP),
32 static const struct ieee80211_iface_combination mwifiex_iface_comb_ap_sta = {
33 .limits = mwifiex_ap_sta_limits,
34 .num_different_channels = 1,
35 .n_limits = ARRAY_SIZE(mwifiex_ap_sta_limits),
36 .max_interfaces = MWIFIEX_MAX_BSS_NUM,
37 .beacon_int_infra_match = true,
40 static const struct ieee80211_regdomain mwifiex_world_regdom_custom = {
45 REG_RULE(2412-10, 2462+10, 40, 3, 20, 0),
47 REG_RULE(2467-10, 2472+10, 20, 3, 20,
48 NL80211_RRF_PASSIVE_SCAN | NL80211_RRF_NO_IBSS),
50 REG_RULE(2484-10, 2484+10, 20, 3, 20,
51 NL80211_RRF_PASSIVE_SCAN | NL80211_RRF_NO_IBSS |
54 REG_RULE(5180-10, 5240+10, 40, 3, 20,
55 NL80211_RRF_PASSIVE_SCAN | NL80211_RRF_NO_IBSS),
56 /* Channel 149 - 165 */
57 REG_RULE(5745-10, 5825+10, 40, 3, 20,
58 NL80211_RRF_PASSIVE_SCAN | NL80211_RRF_NO_IBSS),
60 REG_RULE(5260-10, 5320+10, 40, 3, 30,
61 NL80211_RRF_PASSIVE_SCAN | NL80211_RRF_NO_IBSS |
63 /* Channel 100 - 140 */
64 REG_RULE(5500-10, 5700+10, 40, 3, 30,
65 NL80211_RRF_PASSIVE_SCAN | NL80211_RRF_NO_IBSS |
71 * This function maps the nl802.11 channel type into driver channel type.
73 * The mapping is as follows -
74 * NL80211_CHAN_NO_HT -> IEEE80211_HT_PARAM_CHA_SEC_NONE
75 * NL80211_CHAN_HT20 -> IEEE80211_HT_PARAM_CHA_SEC_NONE
76 * NL80211_CHAN_HT40PLUS -> IEEE80211_HT_PARAM_CHA_SEC_ABOVE
77 * NL80211_CHAN_HT40MINUS -> IEEE80211_HT_PARAM_CHA_SEC_BELOW
78 * Others -> IEEE80211_HT_PARAM_CHA_SEC_NONE
81 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;
97 * This function checks whether WEP is set.
100 mwifiex_is_alg_wep(u32 cipher)
103 case WLAN_CIPHER_SUITE_WEP40:
104 case WLAN_CIPHER_SUITE_WEP104:
114 * This function retrieves the private structure from kernel wiphy structure.
116 static void *mwifiex_cfg80211_get_adapter(struct wiphy *wiphy)
118 return (void *) (*(unsigned long *) wiphy_priv(wiphy));
122 * CFG802.11 operation handler to delete a network key.
125 mwifiex_cfg80211_del_key(struct wiphy *wiphy, struct net_device *netdev,
126 u8 key_index, bool pairwise, const u8 *mac_addr)
128 struct mwifiex_private *priv = mwifiex_netdev_get_priv(netdev);
129 const u8 bc_mac[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
130 const u8 *peer_mac = pairwise ? mac_addr : bc_mac;
132 if (mwifiex_set_encode(priv, NULL, NULL, 0, key_index, peer_mac, 1)) {
133 wiphy_err(wiphy, "deleting the crypto keys\n");
137 wiphy_dbg(wiphy, "info: crypto keys deleted\n");
142 * CFG802.11 operation handler to set Tx power.
145 mwifiex_cfg80211_set_tx_power(struct wiphy *wiphy,
146 enum nl80211_tx_power_setting type,
149 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
150 struct mwifiex_private *priv;
151 struct mwifiex_power_cfg power_cfg;
152 int dbm = MBM_TO_DBM(mbm);
154 if (type == NL80211_TX_POWER_FIXED) {
155 power_cfg.is_power_auto = 0;
156 power_cfg.power_level = dbm;
158 power_cfg.is_power_auto = 1;
161 priv = mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY);
163 return mwifiex_set_tx_power(priv, &power_cfg);
167 * CFG802.11 operation handler to set Power Save option.
169 * The timeout value, if provided, is currently ignored.
172 mwifiex_cfg80211_set_power_mgmt(struct wiphy *wiphy,
173 struct net_device *dev,
174 bool enabled, int timeout)
176 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
181 "info: ignore timeout value for IEEE Power Save\n");
185 return mwifiex_drv_set_power(priv, &ps_mode);
189 * CFG802.11 operation handler to set the default network key.
192 mwifiex_cfg80211_set_default_key(struct wiphy *wiphy, struct net_device *netdev,
193 u8 key_index, bool unicast,
196 struct mwifiex_private *priv = mwifiex_netdev_get_priv(netdev);
198 /* Return if WEP key not configured */
199 if (!priv->sec_info.wep_enabled)
202 if (priv->bss_type == MWIFIEX_BSS_TYPE_UAP) {
203 priv->wep_key_curr_index = key_index;
204 } else if (mwifiex_set_encode(priv, NULL, NULL, 0, key_index,
206 wiphy_err(wiphy, "set default Tx key index\n");
214 * CFG802.11 operation handler to add a network key.
217 mwifiex_cfg80211_add_key(struct wiphy *wiphy, struct net_device *netdev,
218 u8 key_index, bool pairwise, const u8 *mac_addr,
219 struct key_params *params)
221 struct mwifiex_private *priv = mwifiex_netdev_get_priv(netdev);
222 struct mwifiex_wep_key *wep_key;
223 const u8 bc_mac[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
224 const u8 *peer_mac = pairwise ? mac_addr : bc_mac;
226 if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_UAP &&
227 (params->cipher == WLAN_CIPHER_SUITE_WEP40 ||
228 params->cipher == WLAN_CIPHER_SUITE_WEP104)) {
229 if (params->key && params->key_len) {
230 wep_key = &priv->wep_key[key_index];
231 memset(wep_key, 0, sizeof(struct mwifiex_wep_key));
232 memcpy(wep_key->key_material, params->key,
234 wep_key->key_index = key_index;
235 wep_key->key_length = params->key_len;
236 priv->sec_info.wep_enabled = 1;
241 if (mwifiex_set_encode(priv, params, params->key, params->key_len,
242 key_index, peer_mac, 0)) {
243 wiphy_err(wiphy, "crypto keys added\n");
251 * This function sends domain information to the firmware.
253 * The following information are passed to the firmware -
255 * - Sub bands (first channel, number of channels, maximum Tx power)
257 static int mwifiex_send_domain_info_cmd_fw(struct wiphy *wiphy)
259 u8 no_of_triplet = 0;
260 struct ieee80211_country_ie_triplet *t;
261 u8 no_of_parsed_chan = 0;
262 u8 first_chan = 0, next_chan = 0, max_pwr = 0;
264 enum ieee80211_band band;
265 struct ieee80211_supported_band *sband;
266 struct ieee80211_channel *ch;
267 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
268 struct mwifiex_private *priv;
269 struct mwifiex_802_11d_domain_reg *domain_info = &adapter->domain_reg;
271 /* Set country code */
272 domain_info->country_code[0] = adapter->country_code[0];
273 domain_info->country_code[1] = adapter->country_code[1];
274 domain_info->country_code[2] = ' ';
276 band = mwifiex_band_to_radio_type(adapter->config_bands);
277 if (!wiphy->bands[band]) {
278 wiphy_err(wiphy, "11D: setting domain info in FW\n");
282 sband = wiphy->bands[band];
284 for (i = 0; i < sband->n_channels ; i++) {
285 ch = &sband->channels[i];
286 if (ch->flags & IEEE80211_CHAN_DISABLED)
291 first_chan = (u32) ch->hw_value;
292 next_chan = first_chan;
293 max_pwr = ch->max_reg_power;
294 no_of_parsed_chan = 1;
298 if (ch->hw_value == next_chan + 1 &&
299 ch->max_reg_power == max_pwr) {
303 t = &domain_info->triplet[no_of_triplet];
304 t->chans.first_channel = first_chan;
305 t->chans.num_channels = no_of_parsed_chan;
306 t->chans.max_power = max_pwr;
308 first_chan = (u32) ch->hw_value;
309 next_chan = first_chan;
310 max_pwr = ch->max_reg_power;
311 no_of_parsed_chan = 1;
316 t = &domain_info->triplet[no_of_triplet];
317 t->chans.first_channel = first_chan;
318 t->chans.num_channels = no_of_parsed_chan;
319 t->chans.max_power = max_pwr;
323 domain_info->no_of_triplet = no_of_triplet;
325 priv = mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY);
327 if (mwifiex_send_cmd_async(priv, HostCmd_CMD_802_11D_DOMAIN_INFO,
328 HostCmd_ACT_GEN_SET, 0, NULL)) {
329 wiphy_err(wiphy, "11D: setting domain info in FW\n");
337 * CFG802.11 regulatory domain callback function.
339 * This function is called when the regulatory domain is changed due to the
340 * following reasons -
342 * - Set by system core
344 * - Set bt Country IE
346 static int mwifiex_reg_notifier(struct wiphy *wiphy,
347 struct regulatory_request *request)
349 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
351 wiphy_dbg(wiphy, "info: cfg80211 regulatory domain callback for %c%c\n",
352 request->alpha2[0], request->alpha2[1]);
354 memcpy(adapter->country_code, request->alpha2, sizeof(request->alpha2));
356 switch (request->initiator) {
357 case NL80211_REGDOM_SET_BY_DRIVER:
358 case NL80211_REGDOM_SET_BY_CORE:
359 case NL80211_REGDOM_SET_BY_USER:
361 /* Todo: apply driver specific changes in channel flags based
362 on the request initiator if necessary. */
363 case NL80211_REGDOM_SET_BY_COUNTRY_IE:
366 mwifiex_send_domain_info_cmd_fw(wiphy);
372 * This function sets the fragmentation threshold.
374 * The fragmentation threshold value must lie between MWIFIEX_FRAG_MIN_VALUE
375 * and MWIFIEX_FRAG_MAX_VALUE.
378 mwifiex_set_frag(struct mwifiex_private *priv, u32 frag_thr)
380 if (frag_thr < MWIFIEX_FRAG_MIN_VALUE ||
381 frag_thr > MWIFIEX_FRAG_MAX_VALUE)
382 frag_thr = MWIFIEX_FRAG_MAX_VALUE;
384 return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_SNMP_MIB,
385 HostCmd_ACT_GEN_SET, FRAG_THRESH_I,
390 * This function sets the RTS threshold.
392 * The rts value must lie between MWIFIEX_RTS_MIN_VALUE
393 * and MWIFIEX_RTS_MAX_VALUE.
396 mwifiex_set_rts(struct mwifiex_private *priv, u32 rts_thr)
398 if (rts_thr < MWIFIEX_RTS_MIN_VALUE || rts_thr > MWIFIEX_RTS_MAX_VALUE)
399 rts_thr = MWIFIEX_RTS_MAX_VALUE;
401 return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_SNMP_MIB,
402 HostCmd_ACT_GEN_SET, RTS_THRESH_I,
407 * CFG802.11 operation handler to set wiphy parameters.
409 * This function can be used to set the RTS threshold and the
410 * Fragmentation threshold of the driver.
413 mwifiex_cfg80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
415 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
416 struct mwifiex_private *priv;
417 struct mwifiex_uap_bss_param *bss_cfg;
418 int ret, bss_started, i;
420 for (i = 0; i < adapter->priv_num; i++) {
421 priv = adapter->priv[i];
423 switch (priv->bss_role) {
424 case MWIFIEX_BSS_ROLE_UAP:
425 bss_cfg = kzalloc(sizeof(struct mwifiex_uap_bss_param),
430 mwifiex_set_sys_config_invalid_data(bss_cfg);
432 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
433 bss_cfg->rts_threshold = wiphy->rts_threshold;
434 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
435 bss_cfg->frag_threshold = wiphy->frag_threshold;
436 if (changed & WIPHY_PARAM_RETRY_LONG)
437 bss_cfg->retry_limit = wiphy->retry_long;
439 bss_started = priv->bss_started;
441 ret = mwifiex_send_cmd_sync(priv,
442 HostCmd_CMD_UAP_BSS_STOP,
443 HostCmd_ACT_GEN_SET, 0,
446 wiphy_err(wiphy, "Failed to stop the BSS\n");
451 ret = mwifiex_send_cmd_async(priv,
452 HostCmd_CMD_UAP_SYS_CONFIG,
454 UAP_BSS_PARAMS_I, bss_cfg);
459 wiphy_err(wiphy, "Failed to set bss config\n");
466 ret = mwifiex_send_cmd_async(priv,
467 HostCmd_CMD_UAP_BSS_START,
468 HostCmd_ACT_GEN_SET, 0,
471 wiphy_err(wiphy, "Failed to start BSS\n");
476 case MWIFIEX_BSS_ROLE_STA:
477 if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
478 ret = mwifiex_set_rts(priv,
479 wiphy->rts_threshold);
483 if (changed & WIPHY_PARAM_FRAG_THRESHOLD) {
484 ret = mwifiex_set_frag(priv,
485 wiphy->frag_threshold);
497 * CFG802.11 operation handler to change interface type.
500 mwifiex_cfg80211_change_virtual_intf(struct wiphy *wiphy,
501 struct net_device *dev,
502 enum nl80211_iftype type, u32 *flags,
503 struct vif_params *params)
506 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
508 switch (dev->ieee80211_ptr->iftype) {
509 case NL80211_IFTYPE_ADHOC:
511 case NL80211_IFTYPE_STATION:
513 case NL80211_IFTYPE_UNSPECIFIED:
514 wiphy_warn(wiphy, "%s: kept type as IBSS\n", dev->name);
515 case NL80211_IFTYPE_ADHOC: /* This shouldn't happen */
517 case NL80211_IFTYPE_AP:
519 wiphy_err(wiphy, "%s: changing to %d not supported\n",
524 case NL80211_IFTYPE_STATION:
526 case NL80211_IFTYPE_ADHOC:
528 case NL80211_IFTYPE_UNSPECIFIED:
529 wiphy_warn(wiphy, "%s: kept type as STA\n", dev->name);
530 case NL80211_IFTYPE_STATION: /* This shouldn't happen */
532 case NL80211_IFTYPE_AP:
534 wiphy_err(wiphy, "%s: changing to %d not supported\n",
539 case NL80211_IFTYPE_AP:
541 case NL80211_IFTYPE_UNSPECIFIED:
542 wiphy_warn(wiphy, "%s: kept type as AP\n", dev->name);
543 case NL80211_IFTYPE_AP: /* This shouldn't happen */
545 case NL80211_IFTYPE_ADHOC:
546 case NL80211_IFTYPE_STATION:
548 wiphy_err(wiphy, "%s: changing to %d not supported\n",
554 wiphy_err(wiphy, "%s: unknown iftype: %d\n",
555 dev->name, dev->ieee80211_ptr->iftype);
559 dev->ieee80211_ptr->iftype = type;
560 priv->bss_mode = type;
561 mwifiex_deauthenticate(priv, NULL);
563 priv->sec_info.authentication_mode = NL80211_AUTHTYPE_OPEN_SYSTEM;
565 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_SET_BSS_MODE,
566 HostCmd_ACT_GEN_SET, 0, NULL);
572 * This function dumps the station information on a buffer.
574 * The following information are shown -
575 * - Total bytes transmitted
576 * - Total bytes received
577 * - Total packets transmitted
578 * - Total packets received
579 * - Signal quality level
580 * - Transmission rate
583 mwifiex_dump_station_info(struct mwifiex_private *priv,
584 struct station_info *sinfo)
588 sinfo->filled = STATION_INFO_RX_BYTES | STATION_INFO_TX_BYTES |
589 STATION_INFO_RX_PACKETS | STATION_INFO_TX_PACKETS |
590 STATION_INFO_TX_BITRATE |
591 STATION_INFO_SIGNAL | STATION_INFO_SIGNAL_AVG;
593 /* Get signal information from the firmware */
594 if (mwifiex_send_cmd_sync(priv, HostCmd_CMD_RSSI_INFO,
595 HostCmd_ACT_GEN_GET, 0, NULL)) {
596 dev_err(priv->adapter->dev, "failed to get signal information\n");
600 if (mwifiex_drv_get_data_rate(priv, &rate)) {
601 dev_err(priv->adapter->dev, "getting data rate\n");
605 /* Get DTIM period information from firmware */
606 mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_SNMP_MIB,
607 HostCmd_ACT_GEN_GET, DTIM_PERIOD_I,
611 * Bit 0 in tx_htinfo indicates that current Tx rate is 11n rate. Valid
612 * MCS index values for us are 0 to 15.
614 if ((priv->tx_htinfo & BIT(0)) && (priv->tx_rate < 16)) {
615 sinfo->txrate.mcs = priv->tx_rate;
616 sinfo->txrate.flags |= RATE_INFO_FLAGS_MCS;
618 if (priv->tx_htinfo & BIT(1))
619 sinfo->txrate.flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
621 if (priv->tx_htinfo & BIT(2))
622 sinfo->txrate.flags |= RATE_INFO_FLAGS_SHORT_GI;
625 sinfo->signal_avg = priv->bcn_rssi_avg;
626 sinfo->rx_bytes = priv->stats.rx_bytes;
627 sinfo->tx_bytes = priv->stats.tx_bytes;
628 sinfo->rx_packets = priv->stats.rx_packets;
629 sinfo->tx_packets = priv->stats.tx_packets;
630 sinfo->signal = priv->bcn_rssi_avg;
631 /* bit rate is in 500 kb/s units. Convert it to 100kb/s units */
632 sinfo->txrate.legacy = rate * 5;
634 if (priv->bss_mode == NL80211_IFTYPE_STATION) {
635 sinfo->filled |= STATION_INFO_BSS_PARAM;
636 sinfo->bss_param.flags = 0;
637 if (priv->curr_bss_params.bss_descriptor.cap_info_bitmap &
638 WLAN_CAPABILITY_SHORT_PREAMBLE)
639 sinfo->bss_param.flags |=
640 BSS_PARAM_FLAGS_SHORT_PREAMBLE;
641 if (priv->curr_bss_params.bss_descriptor.cap_info_bitmap &
642 WLAN_CAPABILITY_SHORT_SLOT_TIME)
643 sinfo->bss_param.flags |=
644 BSS_PARAM_FLAGS_SHORT_SLOT_TIME;
645 sinfo->bss_param.dtim_period = priv->dtim_period;
646 sinfo->bss_param.beacon_interval =
647 priv->curr_bss_params.bss_descriptor.beacon_period;
654 * CFG802.11 operation handler to get station information.
656 * This function only works in connected mode, and dumps the
657 * requested station information, if available.
660 mwifiex_cfg80211_get_station(struct wiphy *wiphy, struct net_device *dev,
661 u8 *mac, struct station_info *sinfo)
663 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
665 if (!priv->media_connected)
667 if (memcmp(mac, priv->cfg_bssid, ETH_ALEN))
670 return mwifiex_dump_station_info(priv, sinfo);
674 * CFG802.11 operation handler to dump station information.
677 mwifiex_cfg80211_dump_station(struct wiphy *wiphy, struct net_device *dev,
678 int idx, u8 *mac, struct station_info *sinfo)
680 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
682 if (!priv->media_connected || idx)
685 memcpy(mac, priv->cfg_bssid, ETH_ALEN);
687 return mwifiex_dump_station_info(priv, sinfo);
690 /* Supported rates to be advertised to the cfg80211 */
692 static struct ieee80211_rate mwifiex_rates[] = {
693 {.bitrate = 10, .hw_value = 2, },
694 {.bitrate = 20, .hw_value = 4, },
695 {.bitrate = 55, .hw_value = 11, },
696 {.bitrate = 110, .hw_value = 22, },
697 {.bitrate = 60, .hw_value = 12, },
698 {.bitrate = 90, .hw_value = 18, },
699 {.bitrate = 120, .hw_value = 24, },
700 {.bitrate = 180, .hw_value = 36, },
701 {.bitrate = 240, .hw_value = 48, },
702 {.bitrate = 360, .hw_value = 72, },
703 {.bitrate = 480, .hw_value = 96, },
704 {.bitrate = 540, .hw_value = 108, },
707 /* Channel definitions to be advertised to cfg80211 */
709 static struct ieee80211_channel mwifiex_channels_2ghz[] = {
710 {.center_freq = 2412, .hw_value = 1, },
711 {.center_freq = 2417, .hw_value = 2, },
712 {.center_freq = 2422, .hw_value = 3, },
713 {.center_freq = 2427, .hw_value = 4, },
714 {.center_freq = 2432, .hw_value = 5, },
715 {.center_freq = 2437, .hw_value = 6, },
716 {.center_freq = 2442, .hw_value = 7, },
717 {.center_freq = 2447, .hw_value = 8, },
718 {.center_freq = 2452, .hw_value = 9, },
719 {.center_freq = 2457, .hw_value = 10, },
720 {.center_freq = 2462, .hw_value = 11, },
721 {.center_freq = 2467, .hw_value = 12, },
722 {.center_freq = 2472, .hw_value = 13, },
723 {.center_freq = 2484, .hw_value = 14, },
726 static struct ieee80211_supported_band mwifiex_band_2ghz = {
727 .channels = mwifiex_channels_2ghz,
728 .n_channels = ARRAY_SIZE(mwifiex_channels_2ghz),
729 .bitrates = mwifiex_rates,
730 .n_bitrates = ARRAY_SIZE(mwifiex_rates),
733 static struct ieee80211_channel mwifiex_channels_5ghz[] = {
734 {.center_freq = 5040, .hw_value = 8, },
735 {.center_freq = 5060, .hw_value = 12, },
736 {.center_freq = 5080, .hw_value = 16, },
737 {.center_freq = 5170, .hw_value = 34, },
738 {.center_freq = 5190, .hw_value = 38, },
739 {.center_freq = 5210, .hw_value = 42, },
740 {.center_freq = 5230, .hw_value = 46, },
741 {.center_freq = 5180, .hw_value = 36, },
742 {.center_freq = 5200, .hw_value = 40, },
743 {.center_freq = 5220, .hw_value = 44, },
744 {.center_freq = 5240, .hw_value = 48, },
745 {.center_freq = 5260, .hw_value = 52, },
746 {.center_freq = 5280, .hw_value = 56, },
747 {.center_freq = 5300, .hw_value = 60, },
748 {.center_freq = 5320, .hw_value = 64, },
749 {.center_freq = 5500, .hw_value = 100, },
750 {.center_freq = 5520, .hw_value = 104, },
751 {.center_freq = 5540, .hw_value = 108, },
752 {.center_freq = 5560, .hw_value = 112, },
753 {.center_freq = 5580, .hw_value = 116, },
754 {.center_freq = 5600, .hw_value = 120, },
755 {.center_freq = 5620, .hw_value = 124, },
756 {.center_freq = 5640, .hw_value = 128, },
757 {.center_freq = 5660, .hw_value = 132, },
758 {.center_freq = 5680, .hw_value = 136, },
759 {.center_freq = 5700, .hw_value = 140, },
760 {.center_freq = 5745, .hw_value = 149, },
761 {.center_freq = 5765, .hw_value = 153, },
762 {.center_freq = 5785, .hw_value = 157, },
763 {.center_freq = 5805, .hw_value = 161, },
764 {.center_freq = 5825, .hw_value = 165, },
767 static struct ieee80211_supported_band mwifiex_band_5ghz = {
768 .channels = mwifiex_channels_5ghz,
769 .n_channels = ARRAY_SIZE(mwifiex_channels_5ghz),
770 .bitrates = mwifiex_rates + 4,
771 .n_bitrates = ARRAY_SIZE(mwifiex_rates) - 4,
775 /* Supported crypto cipher suits to be advertised to cfg80211 */
777 static const u32 mwifiex_cipher_suites[] = {
778 WLAN_CIPHER_SUITE_WEP40,
779 WLAN_CIPHER_SUITE_WEP104,
780 WLAN_CIPHER_SUITE_TKIP,
781 WLAN_CIPHER_SUITE_CCMP,
782 WLAN_CIPHER_SUITE_AES_CMAC,
786 * CFG802.11 operation handler for setting bit rates.
788 * Function configures data rates to firmware using bitrate mask
789 * provided by cfg80211.
791 static int mwifiex_cfg80211_set_bitrate_mask(struct wiphy *wiphy,
792 struct net_device *dev,
794 const struct cfg80211_bitrate_mask *mask)
796 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
797 u16 bitmap_rates[MAX_BITMAP_RATES_SIZE];
798 enum ieee80211_band band;
800 if (!priv->media_connected) {
801 dev_err(priv->adapter->dev,
802 "Can not set Tx data rate in disconnected state\n");
806 band = mwifiex_band_to_radio_type(priv->curr_bss_params.band);
808 memset(bitmap_rates, 0, sizeof(bitmap_rates));
810 /* Fill HR/DSSS rates. */
811 if (band == IEEE80211_BAND_2GHZ)
812 bitmap_rates[0] = mask->control[band].legacy & 0x000f;
814 /* Fill OFDM rates */
815 if (band == IEEE80211_BAND_2GHZ)
816 bitmap_rates[1] = (mask->control[band].legacy & 0x0ff0) >> 4;
818 bitmap_rates[1] = mask->control[band].legacy;
821 bitmap_rates[2] = mask->control[band].mcs[0];
822 if (priv->adapter->hw_dev_mcs_support == HT_STREAM_2X2)
823 bitmap_rates[2] |= mask->control[band].mcs[1] << 8;
825 return mwifiex_send_cmd_sync(priv, HostCmd_CMD_TX_RATE_CFG,
826 HostCmd_ACT_GEN_SET, 0, bitmap_rates);
830 * CFG802.11 operation handler for connection quality monitoring.
832 * This function subscribes/unsubscribes HIGH_RSSI and LOW_RSSI
835 static int mwifiex_cfg80211_set_cqm_rssi_config(struct wiphy *wiphy,
836 struct net_device *dev,
837 s32 rssi_thold, u32 rssi_hyst)
839 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
840 struct mwifiex_ds_misc_subsc_evt subsc_evt;
842 priv->cqm_rssi_thold = rssi_thold;
843 priv->cqm_rssi_hyst = rssi_hyst;
845 memset(&subsc_evt, 0x00, sizeof(struct mwifiex_ds_misc_subsc_evt));
846 subsc_evt.events = BITMASK_BCN_RSSI_LOW | BITMASK_BCN_RSSI_HIGH;
848 /* Subscribe/unsubscribe low and high rssi events */
849 if (rssi_thold && rssi_hyst) {
850 subsc_evt.action = HostCmd_ACT_BITWISE_SET;
851 subsc_evt.bcn_l_rssi_cfg.abs_value = abs(rssi_thold);
852 subsc_evt.bcn_h_rssi_cfg.abs_value = abs(rssi_thold);
853 subsc_evt.bcn_l_rssi_cfg.evt_freq = 1;
854 subsc_evt.bcn_h_rssi_cfg.evt_freq = 1;
855 return mwifiex_send_cmd_sync(priv,
856 HostCmd_CMD_802_11_SUBSCRIBE_EVENT,
859 subsc_evt.action = HostCmd_ACT_BITWISE_CLR;
860 return mwifiex_send_cmd_sync(priv,
861 HostCmd_CMD_802_11_SUBSCRIBE_EVENT,
868 /* cfg80211 operation handler for change_beacon.
869 * Function retrieves and sets modified management IEs to FW.
871 static int mwifiex_cfg80211_change_beacon(struct wiphy *wiphy,
872 struct net_device *dev,
873 struct cfg80211_beacon_data *data)
875 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
877 if (priv->bss_type != MWIFIEX_BSS_TYPE_UAP) {
878 wiphy_err(wiphy, "%s: bss_type mismatched\n", __func__);
882 if (!priv->bss_started) {
883 wiphy_err(wiphy, "%s: bss not started\n", __func__);
887 if (mwifiex_set_mgmt_ies(priv, data)) {
888 wiphy_err(wiphy, "%s: setting mgmt ies failed\n", __func__);
896 mwifiex_cfg80211_set_antenna(struct wiphy *wiphy, u32 tx_ant, u32 rx_ant)
898 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
899 struct mwifiex_private *priv = mwifiex_get_priv(adapter,
900 MWIFIEX_BSS_ROLE_ANY);
901 struct mwifiex_ds_ant_cfg ant_cfg;
903 if (!tx_ant || !rx_ant)
906 if (adapter->hw_dev_mcs_support != HT_STREAM_2X2) {
907 /* Not a MIMO chip. User should provide specific antenna number
908 * for Tx/Rx path or enable all antennas for diversity
910 if (tx_ant != rx_ant)
913 if ((tx_ant & (tx_ant - 1)) &&
914 (tx_ant != BIT(adapter->number_of_antenna) - 1))
917 if ((tx_ant == BIT(adapter->number_of_antenna) - 1) &&
918 (priv->adapter->number_of_antenna > 1)) {
919 tx_ant = RF_ANTENNA_AUTO;
920 rx_ant = RF_ANTENNA_AUTO;
924 ant_cfg.tx_ant = tx_ant;
925 ant_cfg.rx_ant = rx_ant;
927 return mwifiex_send_cmd_sync(priv, HostCmd_CMD_RF_ANTENNA,
928 HostCmd_ACT_GEN_SET, 0, &ant_cfg);
931 /* cfg80211 operation handler for stop ap.
932 * Function stops BSS running at uAP interface.
934 static int mwifiex_cfg80211_stop_ap(struct wiphy *wiphy, struct net_device *dev)
936 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
938 if (mwifiex_del_mgmt_ies(priv))
939 wiphy_err(wiphy, "Failed to delete mgmt IEs!\n");
941 priv->ap_11n_enabled = 0;
943 if (mwifiex_send_cmd_sync(priv, HostCmd_CMD_UAP_BSS_STOP,
944 HostCmd_ACT_GEN_SET, 0, NULL)) {
945 wiphy_err(wiphy, "Failed to stop the BSS\n");
952 /* cfg80211 operation handler for start_ap.
953 * Function sets beacon period, DTIM period, SSID and security into
954 * AP config structure.
955 * AP is configured with these settings and BSS is started.
957 static int mwifiex_cfg80211_start_ap(struct wiphy *wiphy,
958 struct net_device *dev,
959 struct cfg80211_ap_settings *params)
961 struct mwifiex_uap_bss_param *bss_cfg;
962 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
965 if (priv->bss_type != MWIFIEX_BSS_TYPE_UAP)
967 if (mwifiex_set_mgmt_ies(priv, ¶ms->beacon))
970 bss_cfg = kzalloc(sizeof(struct mwifiex_uap_bss_param), GFP_KERNEL);
974 mwifiex_set_sys_config_invalid_data(bss_cfg);
976 if (params->beacon_interval)
977 bss_cfg->beacon_period = params->beacon_interval;
978 if (params->dtim_period)
979 bss_cfg->dtim_period = params->dtim_period;
981 if (params->ssid && params->ssid_len) {
982 memcpy(bss_cfg->ssid.ssid, params->ssid, params->ssid_len);
983 bss_cfg->ssid.ssid_len = params->ssid_len;
986 switch (params->hidden_ssid) {
987 case NL80211_HIDDEN_SSID_NOT_IN_USE:
988 bss_cfg->bcast_ssid_ctl = 1;
990 case NL80211_HIDDEN_SSID_ZERO_LEN:
991 bss_cfg->bcast_ssid_ctl = 0;
993 case NL80211_HIDDEN_SSID_ZERO_CONTENTS:
994 /* firmware doesn't support this type of hidden SSID */
1001 (u8)ieee80211_frequency_to_channel(params->channel->center_freq);
1003 /* Set appropriate bands */
1004 if (params->channel->band == IEEE80211_BAND_2GHZ) {
1005 bss_cfg->band_cfg = BAND_CONFIG_BG;
1007 if (params->channel_type == NL80211_CHAN_NO_HT)
1008 config_bands = BAND_B | BAND_G;
1010 config_bands = BAND_B | BAND_G | BAND_GN;
1012 bss_cfg->band_cfg = BAND_CONFIG_A;
1014 if (params->channel_type == NL80211_CHAN_NO_HT)
1015 config_bands = BAND_A;
1017 config_bands = BAND_AN | BAND_A;
1020 if (!((config_bands | priv->adapter->fw_bands) &
1021 ~priv->adapter->fw_bands))
1022 priv->adapter->config_bands = config_bands;
1024 mwifiex_set_uap_rates(bss_cfg, params);
1025 mwifiex_send_domain_info_cmd_fw(wiphy);
1027 if (mwifiex_set_secure_params(priv, bss_cfg, params)) {
1029 wiphy_err(wiphy, "Failed to parse secuirty parameters!\n");
1033 mwifiex_set_ht_params(priv, bss_cfg, params);
1035 if (mwifiex_send_cmd_sync(priv, HostCmd_CMD_UAP_BSS_STOP,
1036 HostCmd_ACT_GEN_SET, 0, NULL)) {
1037 wiphy_err(wiphy, "Failed to stop the BSS\n");
1042 if (mwifiex_send_cmd_async(priv, HostCmd_CMD_UAP_SYS_CONFIG,
1043 HostCmd_ACT_GEN_SET,
1044 UAP_BSS_PARAMS_I, bss_cfg)) {
1045 wiphy_err(wiphy, "Failed to set the SSID\n");
1052 if (mwifiex_send_cmd_async(priv, HostCmd_CMD_UAP_BSS_START,
1053 HostCmd_ACT_GEN_SET, 0, NULL)) {
1054 wiphy_err(wiphy, "Failed to start the BSS\n");
1058 if (priv->sec_info.wep_enabled)
1059 priv->curr_pkt_filter |= HostCmd_ACT_MAC_WEP_ENABLE;
1061 priv->curr_pkt_filter &= ~HostCmd_ACT_MAC_WEP_ENABLE;
1063 if (mwifiex_send_cmd_sync(priv, HostCmd_CMD_MAC_CONTROL,
1064 HostCmd_ACT_GEN_SET, 0,
1065 &priv->curr_pkt_filter))
1072 * CFG802.11 operation handler for disconnection request.
1074 * This function does not work when there is already a disconnection
1075 * procedure going on.
1078 mwifiex_cfg80211_disconnect(struct wiphy *wiphy, struct net_device *dev,
1081 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
1083 if (mwifiex_deauthenticate(priv, NULL))
1086 wiphy_dbg(wiphy, "info: successfully disconnected from %pM:"
1087 " reason code %d\n", priv->cfg_bssid, reason_code);
1089 memset(priv->cfg_bssid, 0, ETH_ALEN);
1095 * This function informs the CFG802.11 subsystem of a new IBSS.
1097 * The following information are sent to the CFG802.11 subsystem
1098 * to register the new IBSS. If we do not register the new IBSS,
1099 * a kernel panic will result.
1105 static int mwifiex_cfg80211_inform_ibss_bss(struct mwifiex_private *priv)
1107 struct ieee80211_channel *chan;
1108 struct mwifiex_bss_info bss_info;
1109 struct cfg80211_bss *bss;
1111 u8 ie_buf[IEEE80211_MAX_SSID_LEN + sizeof(struct ieee_types_header)];
1112 enum ieee80211_band band;
1114 if (mwifiex_get_bss_info(priv, &bss_info))
1117 ie_buf[0] = WLAN_EID_SSID;
1118 ie_buf[1] = bss_info.ssid.ssid_len;
1120 memcpy(&ie_buf[sizeof(struct ieee_types_header)],
1121 &bss_info.ssid.ssid, bss_info.ssid.ssid_len);
1122 ie_len = ie_buf[1] + sizeof(struct ieee_types_header);
1124 band = mwifiex_band_to_radio_type(priv->curr_bss_params.band);
1125 chan = __ieee80211_get_channel(priv->wdev->wiphy,
1126 ieee80211_channel_to_frequency(bss_info.bss_chan,
1129 bss = cfg80211_inform_bss(priv->wdev->wiphy, chan,
1130 bss_info.bssid, 0, WLAN_CAPABILITY_IBSS,
1131 0, ie_buf, ie_len, 0, GFP_KERNEL);
1132 cfg80211_put_bss(bss);
1133 memcpy(priv->cfg_bssid, bss_info.bssid, ETH_ALEN);
1139 * This function connects with a BSS.
1141 * This function handles both Infra and Ad-Hoc modes. It also performs
1142 * validity checking on the provided parameters, disconnects from the
1143 * current BSS (if any), sets up the association/scan parameters,
1144 * including security settings, and performs specific SSID scan before
1145 * trying to connect.
1147 * For Infra mode, the function returns failure if the specified SSID
1148 * is not found in scan table. However, for Ad-Hoc mode, it can create
1149 * the IBSS if it does not exist. On successful completion in either case,
1150 * the function notifies the CFG802.11 subsystem of the new BSS connection.
1153 mwifiex_cfg80211_assoc(struct mwifiex_private *priv, size_t ssid_len, u8 *ssid,
1154 u8 *bssid, int mode, struct ieee80211_channel *channel,
1155 struct cfg80211_connect_params *sme, bool privacy)
1157 struct cfg80211_ssid req_ssid;
1158 int ret, auth_type = 0;
1159 struct cfg80211_bss *bss = NULL;
1160 u8 is_scanning_required = 0, config_bands = 0;
1162 memset(&req_ssid, 0, sizeof(struct cfg80211_ssid));
1164 req_ssid.ssid_len = ssid_len;
1165 if (ssid_len > IEEE80211_MAX_SSID_LEN) {
1166 dev_err(priv->adapter->dev, "invalid SSID - aborting\n");
1170 memcpy(req_ssid.ssid, ssid, ssid_len);
1171 if (!req_ssid.ssid_len || req_ssid.ssid[0] < 0x20) {
1172 dev_err(priv->adapter->dev, "invalid SSID - aborting\n");
1176 /* disconnect before try to associate */
1177 mwifiex_deauthenticate(priv, NULL);
1180 if (mode == NL80211_IFTYPE_STATION) {
1181 if (channel->band == IEEE80211_BAND_2GHZ)
1182 config_bands = BAND_B | BAND_G | BAND_GN;
1184 config_bands = BAND_A | BAND_AN;
1186 if (!((config_bands | priv->adapter->fw_bands) &
1187 ~priv->adapter->fw_bands))
1188 priv->adapter->config_bands = config_bands;
1192 /* As this is new association, clear locally stored
1193 * keys and security related flags */
1194 priv->sec_info.wpa_enabled = false;
1195 priv->sec_info.wpa2_enabled = false;
1196 priv->wep_key_curr_index = 0;
1197 priv->sec_info.encryption_mode = 0;
1198 priv->sec_info.is_authtype_auto = 0;
1199 ret = mwifiex_set_encode(priv, NULL, NULL, 0, 0, NULL, 1);
1201 if (mode == NL80211_IFTYPE_ADHOC) {
1202 /* "privacy" is set only for ad-hoc mode */
1205 * Keep WLAN_CIPHER_SUITE_WEP104 for now so that
1206 * the firmware can find a matching network from the
1207 * scan. The cfg80211 does not give us the encryption
1208 * mode at this stage so just setting it to WEP here.
1210 priv->sec_info.encryption_mode =
1211 WLAN_CIPHER_SUITE_WEP104;
1212 priv->sec_info.authentication_mode =
1213 NL80211_AUTHTYPE_OPEN_SYSTEM;
1219 /* Now handle infra mode. "sme" is valid for infra mode only */
1220 if (sme->auth_type == NL80211_AUTHTYPE_AUTOMATIC) {
1221 auth_type = NL80211_AUTHTYPE_OPEN_SYSTEM;
1222 priv->sec_info.is_authtype_auto = 1;
1224 auth_type = sme->auth_type;
1227 if (sme->crypto.n_ciphers_pairwise) {
1228 priv->sec_info.encryption_mode =
1229 sme->crypto.ciphers_pairwise[0];
1230 priv->sec_info.authentication_mode = auth_type;
1233 if (sme->crypto.cipher_group) {
1234 priv->sec_info.encryption_mode = sme->crypto.cipher_group;
1235 priv->sec_info.authentication_mode = auth_type;
1238 ret = mwifiex_set_gen_ie(priv, sme->ie, sme->ie_len);
1241 if (mwifiex_is_alg_wep(priv->sec_info.encryption_mode)) {
1242 dev_dbg(priv->adapter->dev,
1243 "info: setting wep encryption"
1244 " with key len %d\n", sme->key_len);
1245 priv->wep_key_curr_index = sme->key_idx;
1246 ret = mwifiex_set_encode(priv, NULL, sme->key,
1247 sme->key_len, sme->key_idx,
1253 * Scan entries are valid for some time (15 sec). So we can save one
1254 * active scan time if we just try cfg80211_get_bss first. If it fails
1255 * then request scan and cfg80211_get_bss() again for final output.
1258 if (is_scanning_required) {
1259 /* Do specific SSID scanning */
1260 if (mwifiex_request_scan(priv, &req_ssid)) {
1261 dev_err(priv->adapter->dev, "scan error\n");
1266 /* Find the BSS we want using available scan results */
1267 if (mode == NL80211_IFTYPE_ADHOC)
1268 bss = cfg80211_get_bss(priv->wdev->wiphy, channel,
1269 bssid, ssid, ssid_len,
1270 WLAN_CAPABILITY_IBSS,
1271 WLAN_CAPABILITY_IBSS);
1273 bss = cfg80211_get_bss(priv->wdev->wiphy, channel,
1274 bssid, ssid, ssid_len,
1275 WLAN_CAPABILITY_ESS,
1276 WLAN_CAPABILITY_ESS);
1279 if (is_scanning_required) {
1280 dev_warn(priv->adapter->dev,
1281 "assoc: requested bss not found in scan results\n");
1284 is_scanning_required = 1;
1286 dev_dbg(priv->adapter->dev,
1287 "info: trying to associate to '%s' bssid %pM\n",
1288 (char *) req_ssid.ssid, bss->bssid);
1289 memcpy(&priv->cfg_bssid, bss->bssid, ETH_ALEN);
1294 if (mwifiex_bss_start(priv, bss, &req_ssid))
1297 if (mode == NL80211_IFTYPE_ADHOC) {
1298 /* Inform the BSS information to kernel, otherwise
1299 * kernel will give a panic after successful assoc */
1300 if (mwifiex_cfg80211_inform_ibss_bss(priv))
1308 * CFG802.11 operation handler for association request.
1310 * This function does not work when the current mode is set to Ad-Hoc, or
1311 * when there is already an association procedure going on. The given BSS
1312 * information is used to associate.
1315 mwifiex_cfg80211_connect(struct wiphy *wiphy, struct net_device *dev,
1316 struct cfg80211_connect_params *sme)
1318 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
1321 if (priv->bss_mode == NL80211_IFTYPE_ADHOC) {
1322 wiphy_err(wiphy, "received infra assoc request "
1323 "when station is in ibss mode\n");
1327 if (priv->bss_mode == NL80211_IFTYPE_AP) {
1328 wiphy_err(wiphy, "skip association request for AP interface\n");
1332 wiphy_dbg(wiphy, "info: Trying to associate to %s and bssid %pM\n",
1333 (char *) sme->ssid, sme->bssid);
1335 ret = mwifiex_cfg80211_assoc(priv, sme->ssid_len, sme->ssid, sme->bssid,
1336 priv->bss_mode, sme->channel, sme, 0);
1339 cfg80211_connect_result(priv->netdev, priv->cfg_bssid, NULL, 0,
1340 NULL, 0, WLAN_STATUS_SUCCESS,
1342 dev_dbg(priv->adapter->dev,
1343 "info: associated to bssid %pM successfully\n",
1346 dev_dbg(priv->adapter->dev,
1347 "info: association to bssid %pM failed\n",
1349 memset(priv->cfg_bssid, 0, ETH_ALEN);
1356 * This function sets following parameters for ibss network.
1360 * - secondary channel offset
1362 static int mwifiex_set_ibss_params(struct mwifiex_private *priv,
1363 struct cfg80211_ibss_params *params)
1365 struct wiphy *wiphy = priv->wdev->wiphy;
1366 struct mwifiex_adapter *adapter = priv->adapter;
1368 u8 config_bands = 0;
1370 if (params->channel->band == IEEE80211_BAND_2GHZ) {
1371 if (!params->basic_rates) {
1372 config_bands = BAND_B | BAND_G;
1374 for (i = 0; i < mwifiex_band_2ghz.n_bitrates; i++) {
1376 * Rates below 6 Mbps in the table are CCK
1377 * rates; 802.11b and from 6 they are OFDM;
1380 if (mwifiex_rates[i].bitrate == 60) {
1386 if (params->basic_rates < index) {
1387 config_bands = BAND_B;
1389 config_bands = BAND_G;
1390 if (params->basic_rates % index)
1391 config_bands |= BAND_B;
1395 if (params->channel_type != NL80211_CHAN_NO_HT)
1396 config_bands |= BAND_GN;
1398 if (params->channel_type == NL80211_CHAN_NO_HT)
1399 config_bands = BAND_A;
1401 config_bands = BAND_AN | BAND_A;
1404 if (!((config_bands | adapter->fw_bands) & ~adapter->fw_bands)) {
1405 adapter->config_bands = config_bands;
1406 adapter->adhoc_start_band = config_bands;
1408 if ((config_bands & BAND_GN) || (config_bands & BAND_AN))
1409 adapter->adhoc_11n_enabled = true;
1411 adapter->adhoc_11n_enabled = false;
1414 adapter->sec_chan_offset =
1415 mwifiex_chan_type_to_sec_chan_offset(params->channel_type);
1416 priv->adhoc_channel =
1417 ieee80211_frequency_to_channel(params->channel->center_freq);
1419 wiphy_dbg(wiphy, "info: set ibss band %d, chan %d, chan offset %d\n",
1420 config_bands, priv->adhoc_channel, adapter->sec_chan_offset);
1426 * CFG802.11 operation handler to join an IBSS.
1428 * This function does not work in any mode other than Ad-Hoc, or if
1429 * a join operation is already in progress.
1432 mwifiex_cfg80211_join_ibss(struct wiphy *wiphy, struct net_device *dev,
1433 struct cfg80211_ibss_params *params)
1435 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
1438 if (priv->bss_mode != NL80211_IFTYPE_ADHOC) {
1439 wiphy_err(wiphy, "request to join ibss received "
1440 "when station is not in ibss mode\n");
1444 wiphy_dbg(wiphy, "info: trying to join to %s and bssid %pM\n",
1445 (char *) params->ssid, params->bssid);
1447 mwifiex_set_ibss_params(priv, params);
1449 ret = mwifiex_cfg80211_assoc(priv, params->ssid_len, params->ssid,
1450 params->bssid, priv->bss_mode,
1451 params->channel, NULL, params->privacy);
1454 cfg80211_ibss_joined(priv->netdev, priv->cfg_bssid, GFP_KERNEL);
1455 dev_dbg(priv->adapter->dev,
1456 "info: joined/created adhoc network with bssid"
1457 " %pM successfully\n", priv->cfg_bssid);
1459 dev_dbg(priv->adapter->dev,
1460 "info: failed creating/joining adhoc network\n");
1467 * CFG802.11 operation handler to leave an IBSS.
1469 * This function does not work if a leave operation is
1470 * already in progress.
1473 mwifiex_cfg80211_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
1475 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
1477 wiphy_dbg(wiphy, "info: disconnecting from essid %pM\n",
1479 if (mwifiex_deauthenticate(priv, NULL))
1482 memset(priv->cfg_bssid, 0, ETH_ALEN);
1488 * CFG802.11 operation handler for scan request.
1490 * This function issues a scan request to the firmware based upon
1491 * the user specified scan configuration. On successfull completion,
1492 * it also informs the results.
1495 mwifiex_cfg80211_scan(struct wiphy *wiphy,
1496 struct cfg80211_scan_request *request)
1498 struct net_device *dev = request->wdev->netdev;
1499 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
1501 struct ieee80211_channel *chan;
1503 wiphy_dbg(wiphy, "info: received scan request on %s\n", dev->name);
1505 if (atomic_read(&priv->wmm.tx_pkts_queued) >=
1506 MWIFIEX_MIN_TX_PENDING_TO_CANCEL_SCAN) {
1507 dev_dbg(priv->adapter->dev, "scan rejected due to traffic\n");
1511 priv->scan_request = request;
1513 priv->user_scan_cfg = kzalloc(sizeof(struct mwifiex_user_scan_cfg),
1515 if (!priv->user_scan_cfg) {
1516 dev_err(priv->adapter->dev, "failed to alloc scan_req\n");
1520 priv->user_scan_cfg->num_ssids = request->n_ssids;
1521 priv->user_scan_cfg->ssid_list = request->ssids;
1523 if (request->ie && request->ie_len) {
1524 for (i = 0; i < MWIFIEX_MAX_VSIE_NUM; i++) {
1525 if (priv->vs_ie[i].mask != MWIFIEX_VSIE_MASK_CLEAR)
1527 priv->vs_ie[i].mask = MWIFIEX_VSIE_MASK_SCAN;
1528 memcpy(&priv->vs_ie[i].ie, request->ie,
1534 for (i = 0; i < request->n_channels; i++) {
1535 chan = request->channels[i];
1536 priv->user_scan_cfg->chan_list[i].chan_number = chan->hw_value;
1537 priv->user_scan_cfg->chan_list[i].radio_type = chan->band;
1539 if (chan->flags & IEEE80211_CHAN_PASSIVE_SCAN)
1540 priv->user_scan_cfg->chan_list[i].scan_type =
1541 MWIFIEX_SCAN_TYPE_PASSIVE;
1543 priv->user_scan_cfg->chan_list[i].scan_type =
1544 MWIFIEX_SCAN_TYPE_ACTIVE;
1546 priv->user_scan_cfg->chan_list[i].scan_time = 0;
1548 if (mwifiex_scan_networks(priv, priv->user_scan_cfg))
1551 if (request->ie && request->ie_len) {
1552 for (i = 0; i < MWIFIEX_MAX_VSIE_NUM; i++) {
1553 if (priv->vs_ie[i].mask == MWIFIEX_VSIE_MASK_SCAN) {
1554 priv->vs_ie[i].mask = MWIFIEX_VSIE_MASK_CLEAR;
1555 memset(&priv->vs_ie[i].ie, 0,
1556 MWIFIEX_MAX_VSIE_LEN);
1564 * This function sets up the CFG802.11 specific HT capability fields
1565 * with default values.
1567 * The following default values are set -
1568 * - HT Supported = True
1569 * - Maximum AMPDU length factor = IEEE80211_HT_MAX_AMPDU_64K
1570 * - Minimum AMPDU spacing = IEEE80211_HT_MPDU_DENSITY_NONE
1571 * - HT Capabilities supported by firmware
1572 * - MCS information, Rx mask = 0xff
1573 * - MCD information, Tx parameters = IEEE80211_HT_MCS_TX_DEFINED (0x01)
1576 mwifiex_setup_ht_caps(struct ieee80211_sta_ht_cap *ht_info,
1577 struct mwifiex_private *priv)
1580 struct ieee80211_mcs_info mcs_set;
1581 u8 *mcs = (u8 *)&mcs_set;
1582 struct mwifiex_adapter *adapter = priv->adapter;
1584 ht_info->ht_supported = true;
1585 ht_info->ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
1586 ht_info->ampdu_density = IEEE80211_HT_MPDU_DENSITY_NONE;
1588 memset(&ht_info->mcs, 0, sizeof(ht_info->mcs));
1590 /* Fill HT capability information */
1591 if (ISSUPP_CHANWIDTH40(adapter->hw_dot_11n_dev_cap))
1592 ht_info->cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
1594 ht_info->cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
1596 if (ISSUPP_SHORTGI20(adapter->hw_dot_11n_dev_cap))
1597 ht_info->cap |= IEEE80211_HT_CAP_SGI_20;
1599 ht_info->cap &= ~IEEE80211_HT_CAP_SGI_20;
1601 if (ISSUPP_SHORTGI40(adapter->hw_dot_11n_dev_cap))
1602 ht_info->cap |= IEEE80211_HT_CAP_SGI_40;
1604 ht_info->cap &= ~IEEE80211_HT_CAP_SGI_40;
1606 if (ISSUPP_RXSTBC(adapter->hw_dot_11n_dev_cap))
1607 ht_info->cap |= 1 << IEEE80211_HT_CAP_RX_STBC_SHIFT;
1609 ht_info->cap &= ~(3 << IEEE80211_HT_CAP_RX_STBC_SHIFT);
1611 if (ISSUPP_TXSTBC(adapter->hw_dot_11n_dev_cap))
1612 ht_info->cap |= IEEE80211_HT_CAP_TX_STBC;
1614 ht_info->cap &= ~IEEE80211_HT_CAP_TX_STBC;
1616 ht_info->cap &= ~IEEE80211_HT_CAP_MAX_AMSDU;
1617 ht_info->cap |= IEEE80211_HT_CAP_SM_PS;
1619 rx_mcs_supp = GET_RXMCSSUPP(adapter->hw_dev_mcs_support);
1620 /* Set MCS for 1x1 */
1621 memset(mcs, 0xff, rx_mcs_supp);
1622 /* Clear all the other values */
1623 memset(&mcs[rx_mcs_supp], 0,
1624 sizeof(struct ieee80211_mcs_info) - rx_mcs_supp);
1625 if (priv->bss_mode == NL80211_IFTYPE_STATION ||
1626 ISSUPP_CHANWIDTH40(adapter->hw_dot_11n_dev_cap))
1627 /* Set MCS32 for infra mode or ad-hoc mode with 40MHz support */
1628 SETHT_MCS32(mcs_set.rx_mask);
1630 memcpy((u8 *) &ht_info->mcs, mcs, sizeof(struct ieee80211_mcs_info));
1632 ht_info->mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED;
1636 * create a new virtual interface with the given name
1638 struct wireless_dev *mwifiex_add_virtual_intf(struct wiphy *wiphy,
1640 enum nl80211_iftype type,
1642 struct vif_params *params)
1644 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
1645 struct mwifiex_private *priv;
1646 struct net_device *dev;
1648 struct wireless_dev *wdev;
1651 return ERR_PTR(-EFAULT);
1654 case NL80211_IFTYPE_UNSPECIFIED:
1655 case NL80211_IFTYPE_STATION:
1656 case NL80211_IFTYPE_ADHOC:
1657 priv = adapter->priv[MWIFIEX_BSS_TYPE_STA];
1658 if (priv->bss_mode) {
1660 "cannot create multiple sta/adhoc ifaces\n");
1661 return ERR_PTR(-EINVAL);
1664 wdev = kzalloc(sizeof(struct wireless_dev), GFP_KERNEL);
1666 return ERR_PTR(-ENOMEM);
1668 wdev->wiphy = wiphy;
1670 wdev->iftype = NL80211_IFTYPE_STATION;
1672 if (type == NL80211_IFTYPE_UNSPECIFIED)
1673 priv->bss_mode = NL80211_IFTYPE_STATION;
1675 priv->bss_mode = type;
1677 priv->bss_type = MWIFIEX_BSS_TYPE_STA;
1678 priv->frame_type = MWIFIEX_DATA_FRAME_TYPE_ETH_II;
1679 priv->bss_priority = 0;
1680 priv->bss_role = MWIFIEX_BSS_ROLE_STA;
1684 case NL80211_IFTYPE_AP:
1685 priv = adapter->priv[MWIFIEX_BSS_TYPE_UAP];
1687 if (priv->bss_mode) {
1688 wiphy_err(wiphy, "Can't create multiple AP interfaces");
1689 return ERR_PTR(-EINVAL);
1692 wdev = kzalloc(sizeof(struct wireless_dev), GFP_KERNEL);
1694 return ERR_PTR(-ENOMEM);
1697 wdev->wiphy = wiphy;
1698 wdev->iftype = NL80211_IFTYPE_AP;
1700 priv->bss_type = MWIFIEX_BSS_TYPE_UAP;
1701 priv->frame_type = MWIFIEX_DATA_FRAME_TYPE_ETH_II;
1702 priv->bss_priority = 0;
1703 priv->bss_role = MWIFIEX_BSS_ROLE_UAP;
1704 priv->bss_started = 0;
1706 priv->bss_mode = type;
1710 wiphy_err(wiphy, "type not supported\n");
1711 return ERR_PTR(-EINVAL);
1714 dev = alloc_netdev_mq(sizeof(struct mwifiex_private *), name,
1717 wiphy_err(wiphy, "no memory available for netdevice\n");
1718 priv->bss_mode = NL80211_IFTYPE_UNSPECIFIED;
1719 return ERR_PTR(-ENOMEM);
1722 mwifiex_init_priv_params(priv, dev);
1725 mwifiex_setup_ht_caps(&wiphy->bands[IEEE80211_BAND_2GHZ]->ht_cap, priv);
1727 if (adapter->config_bands & BAND_A)
1728 mwifiex_setup_ht_caps(
1729 &wiphy->bands[IEEE80211_BAND_5GHZ]->ht_cap, priv);
1731 dev_net_set(dev, wiphy_net(wiphy));
1732 dev->ieee80211_ptr = priv->wdev;
1733 dev->ieee80211_ptr->iftype = priv->bss_mode;
1734 memcpy(dev->dev_addr, wiphy->perm_addr, ETH_ALEN);
1735 memcpy(dev->perm_addr, wiphy->perm_addr, ETH_ALEN);
1736 SET_NETDEV_DEV(dev, wiphy_dev(wiphy));
1738 dev->flags |= IFF_BROADCAST | IFF_MULTICAST;
1739 dev->watchdog_timeo = MWIFIEX_DEFAULT_WATCHDOG_TIMEOUT;
1740 dev->hard_header_len += MWIFIEX_MIN_DATA_HEADER_LEN;
1742 mdev_priv = netdev_priv(dev);
1743 *((unsigned long *) mdev_priv) = (unsigned long) priv;
1745 SET_NETDEV_DEV(dev, adapter->dev);
1747 /* Register network device */
1748 if (register_netdevice(dev)) {
1749 wiphy_err(wiphy, "cannot register virtual network device\n");
1751 priv->bss_mode = NL80211_IFTYPE_UNSPECIFIED;
1752 return ERR_PTR(-EFAULT);
1755 sema_init(&priv->async_sem, 1);
1756 priv->scan_pending_on_block = false;
1758 dev_dbg(adapter->dev, "info: %s: Marvell 802.11 Adapter\n", dev->name);
1760 #ifdef CONFIG_DEBUG_FS
1761 mwifiex_dev_debugfs_init(priv);
1765 EXPORT_SYMBOL_GPL(mwifiex_add_virtual_intf);
1768 * del_virtual_intf: remove the virtual interface determined by dev
1770 int mwifiex_del_virtual_intf(struct wiphy *wiphy, struct wireless_dev *wdev)
1772 struct mwifiex_private *priv = mwifiex_netdev_get_priv(wdev->netdev);
1774 #ifdef CONFIG_DEBUG_FS
1775 mwifiex_dev_debugfs_remove(priv);
1778 if (!netif_queue_stopped(priv->netdev))
1779 netif_stop_queue(priv->netdev);
1781 if (netif_carrier_ok(priv->netdev))
1782 netif_carrier_off(priv->netdev);
1784 if (wdev->netdev->reg_state == NETREG_REGISTERED)
1785 unregister_netdevice(wdev->netdev);
1787 if (wdev->netdev->reg_state == NETREG_UNREGISTERED)
1788 free_netdev(wdev->netdev);
1790 /* Clear the priv in adapter */
1791 priv->netdev = NULL;
1793 priv->media_connected = false;
1795 priv->bss_mode = NL80211_IFTYPE_UNSPECIFIED;
1799 EXPORT_SYMBOL_GPL(mwifiex_del_virtual_intf);
1801 /* station cfg80211 operations */
1802 static struct cfg80211_ops mwifiex_cfg80211_ops = {
1803 .add_virtual_intf = mwifiex_add_virtual_intf,
1804 .del_virtual_intf = mwifiex_del_virtual_intf,
1805 .change_virtual_intf = mwifiex_cfg80211_change_virtual_intf,
1806 .scan = mwifiex_cfg80211_scan,
1807 .connect = mwifiex_cfg80211_connect,
1808 .disconnect = mwifiex_cfg80211_disconnect,
1809 .get_station = mwifiex_cfg80211_get_station,
1810 .dump_station = mwifiex_cfg80211_dump_station,
1811 .set_wiphy_params = mwifiex_cfg80211_set_wiphy_params,
1812 .join_ibss = mwifiex_cfg80211_join_ibss,
1813 .leave_ibss = mwifiex_cfg80211_leave_ibss,
1814 .add_key = mwifiex_cfg80211_add_key,
1815 .del_key = mwifiex_cfg80211_del_key,
1816 .set_default_key = mwifiex_cfg80211_set_default_key,
1817 .set_power_mgmt = mwifiex_cfg80211_set_power_mgmt,
1818 .set_tx_power = mwifiex_cfg80211_set_tx_power,
1819 .set_bitrate_mask = mwifiex_cfg80211_set_bitrate_mask,
1820 .start_ap = mwifiex_cfg80211_start_ap,
1821 .stop_ap = mwifiex_cfg80211_stop_ap,
1822 .change_beacon = mwifiex_cfg80211_change_beacon,
1823 .set_cqm_rssi_config = mwifiex_cfg80211_set_cqm_rssi_config,
1824 .set_antenna = mwifiex_cfg80211_set_antenna,
1828 * This function registers the device with CFG802.11 subsystem.
1830 * The function creates the wireless device/wiphy, populates it with
1831 * default parameters and handler function pointers, and finally
1832 * registers the device.
1835 int mwifiex_register_cfg80211(struct mwifiex_adapter *adapter)
1839 struct wiphy *wiphy;
1840 struct mwifiex_private *priv = adapter->priv[MWIFIEX_BSS_TYPE_STA];
1843 /* create a new wiphy for use with cfg80211 */
1844 wiphy = wiphy_new(&mwifiex_cfg80211_ops,
1845 sizeof(struct mwifiex_adapter *));
1847 dev_err(adapter->dev, "%s: creating new wiphy\n", __func__);
1850 wiphy->max_scan_ssids = MWIFIEX_MAX_SSID_LIST_LENGTH;
1851 wiphy->max_scan_ie_len = MWIFIEX_MAX_VSIE_LEN;
1852 wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
1853 BIT(NL80211_IFTYPE_ADHOC) |
1854 BIT(NL80211_IFTYPE_AP);
1856 wiphy->bands[IEEE80211_BAND_2GHZ] = &mwifiex_band_2ghz;
1857 if (adapter->config_bands & BAND_A)
1858 wiphy->bands[IEEE80211_BAND_5GHZ] = &mwifiex_band_5ghz;
1860 wiphy->bands[IEEE80211_BAND_5GHZ] = NULL;
1862 wiphy->iface_combinations = &mwifiex_iface_comb_ap_sta;
1863 wiphy->n_iface_combinations = 1;
1865 /* Initialize cipher suits */
1866 wiphy->cipher_suites = mwifiex_cipher_suites;
1867 wiphy->n_cipher_suites = ARRAY_SIZE(mwifiex_cipher_suites);
1869 memcpy(wiphy->perm_addr, priv->curr_addr, ETH_ALEN);
1870 wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
1871 wiphy->flags |= WIPHY_FLAG_HAVE_AP_SME |
1872 WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD |
1873 WIPHY_FLAG_CUSTOM_REGULATORY;
1875 wiphy_apply_custom_regulatory(wiphy, &mwifiex_world_regdom_custom);
1877 wiphy->probe_resp_offload = NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS |
1878 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2;
1880 wiphy->available_antennas_tx = BIT(adapter->number_of_antenna) - 1;
1881 wiphy->available_antennas_rx = BIT(adapter->number_of_antenna) - 1;
1883 wiphy->features = NL80211_FEATURE_HT_IBSS;
1885 /* Reserve space for mwifiex specific private data for BSS */
1886 wiphy->bss_priv_size = sizeof(struct mwifiex_bss_priv);
1888 wiphy->reg_notifier = mwifiex_reg_notifier;
1890 /* Set struct mwifiex_adapter pointer in wiphy_priv */
1891 wdev_priv = wiphy_priv(wiphy);
1892 *(unsigned long *)wdev_priv = (unsigned long)adapter;
1894 set_wiphy_dev(wiphy, priv->adapter->dev);
1896 ret = wiphy_register(wiphy);
1898 dev_err(adapter->dev,
1899 "%s: wiphy_register failed: %d\n", __func__, ret);
1903 country_code = mwifiex_11d_code_2_region(priv->adapter->region_code);
1905 dev_info(adapter->dev,
1906 "ignoring F/W country code %2.2s\n", country_code);
1908 adapter->wiphy = wiphy;