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_regdomain mwifiex_world_regdom_custom = {
28 REG_RULE(2412-10, 2462+10, 40, 3, 20, 0),
30 REG_RULE(2467-10, 2472+10, 20, 3, 20,
31 NL80211_RRF_PASSIVE_SCAN | NL80211_RRF_NO_IBSS),
33 REG_RULE(2484-10, 2484+10, 20, 3, 20,
34 NL80211_RRF_PASSIVE_SCAN | NL80211_RRF_NO_IBSS |
37 REG_RULE(5180-10, 5240+10, 40, 3, 20,
38 NL80211_RRF_PASSIVE_SCAN | NL80211_RRF_NO_IBSS),
39 /* Channel 149 - 165 */
40 REG_RULE(5745-10, 5825+10, 40, 3, 20,
41 NL80211_RRF_PASSIVE_SCAN | NL80211_RRF_NO_IBSS),
43 REG_RULE(5260-10, 5320+10, 40, 3, 30,
44 NL80211_RRF_PASSIVE_SCAN | NL80211_RRF_NO_IBSS |
46 /* Channel 100 - 140 */
47 REG_RULE(5500-10, 5700+10, 40, 3, 30,
48 NL80211_RRF_PASSIVE_SCAN | NL80211_RRF_NO_IBSS |
54 * This function maps the nl802.11 channel type into driver channel type.
56 * The mapping is as follows -
57 * NL80211_CHAN_NO_HT -> IEEE80211_HT_PARAM_CHA_SEC_NONE
58 * NL80211_CHAN_HT20 -> IEEE80211_HT_PARAM_CHA_SEC_NONE
59 * NL80211_CHAN_HT40PLUS -> IEEE80211_HT_PARAM_CHA_SEC_ABOVE
60 * NL80211_CHAN_HT40MINUS -> IEEE80211_HT_PARAM_CHA_SEC_BELOW
61 * Others -> IEEE80211_HT_PARAM_CHA_SEC_NONE
64 mwifiex_cfg80211_channel_type_to_sec_chan_offset(enum nl80211_channel_type
67 switch (channel_type) {
68 case NL80211_CHAN_NO_HT:
69 case NL80211_CHAN_HT20:
70 return IEEE80211_HT_PARAM_CHA_SEC_NONE;
71 case NL80211_CHAN_HT40PLUS:
72 return IEEE80211_HT_PARAM_CHA_SEC_ABOVE;
73 case NL80211_CHAN_HT40MINUS:
74 return IEEE80211_HT_PARAM_CHA_SEC_BELOW;
76 return IEEE80211_HT_PARAM_CHA_SEC_NONE;
81 * This function checks whether WEP is set.
84 mwifiex_is_alg_wep(u32 cipher)
87 case WLAN_CIPHER_SUITE_WEP40:
88 case WLAN_CIPHER_SUITE_WEP104:
98 * This function retrieves the private structure from kernel wiphy structure.
100 static void *mwifiex_cfg80211_get_priv(struct wiphy *wiphy)
102 return (void *) (*(unsigned long *) wiphy_priv(wiphy));
106 * CFG802.11 operation handler to delete a network key.
109 mwifiex_cfg80211_del_key(struct wiphy *wiphy, struct net_device *netdev,
110 u8 key_index, bool pairwise, const u8 *mac_addr)
112 struct mwifiex_private *priv = mwifiex_netdev_get_priv(netdev);
114 if (mwifiex_set_encode(priv, NULL, 0, key_index, 1)) {
115 wiphy_err(wiphy, "deleting the crypto keys\n");
119 wiphy_dbg(wiphy, "info: crypto keys deleted\n");
124 * This function forms an skb for management frame.
127 mwifiex_form_mgmt_frame(struct sk_buff *skb, const u8 *buf, size_t len)
129 u8 addr[ETH_ALEN] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
131 u32 tx_control = 0, pkt_type = PKT_TYPE_MGMT;
134 pkt_len = len + ETH_ALEN;
136 skb_reserve(skb, MWIFIEX_MIN_DATA_HEADER_LEN +
137 MWIFIEX_MGMT_FRAME_HEADER_SIZE + sizeof(pkt_len));
138 memcpy(skb_push(skb, sizeof(pkt_len)), &pkt_len, sizeof(pkt_len));
140 memcpy(skb_push(skb, sizeof(tx_control)),
141 &tx_control, sizeof(tx_control));
143 memcpy(skb_push(skb, sizeof(pkt_type)), &pkt_type, sizeof(pkt_type));
145 /* Add packet data and address4 */
146 memcpy(skb_put(skb, sizeof(struct ieee80211_hdr_3addr)), buf,
147 sizeof(struct ieee80211_hdr_3addr));
148 memcpy(skb_put(skb, ETH_ALEN), addr, ETH_ALEN);
149 memcpy(skb_put(skb, len - sizeof(struct ieee80211_hdr_3addr)),
150 buf + sizeof(struct ieee80211_hdr_3addr),
151 len - sizeof(struct ieee80211_hdr_3addr));
153 skb->priority = LOW_PRIO_TID;
154 do_gettimeofday(&tv);
155 skb->tstamp = timeval_to_ktime(tv);
161 * CFG802.11 operation handler to transmit a management frame.
164 mwifiex_cfg80211_mgmt_tx(struct wiphy *wiphy, struct net_device *dev,
165 struct ieee80211_channel *chan, bool offchan,
166 enum nl80211_channel_type channel_type,
167 bool channel_type_valid, unsigned int wait,
168 const u8 *buf, size_t len, bool no_cck,
169 bool dont_wait_for_ack, u64 *cookie)
173 const struct ieee80211_mgmt *mgmt;
174 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
177 wiphy_err(wiphy, "invalid buffer and length\n");
181 mgmt = (const struct ieee80211_mgmt *)buf;
182 if (GET_BSS_ROLE(priv) != MWIFIEX_BSS_ROLE_STA &&
183 ieee80211_is_probe_resp(mgmt->frame_control)) {
184 /* Since we support offload probe resp, we need to skip probe
185 * resp in AP or GO mode */
187 "info: skip to send probe resp in AP or GO mode\n");
191 pkt_len = len + ETH_ALEN;
192 skb = dev_alloc_skb(MWIFIEX_MIN_DATA_HEADER_LEN +
193 MWIFIEX_MGMT_FRAME_HEADER_SIZE +
194 pkt_len + sizeof(pkt_len));
197 wiphy_err(wiphy, "allocate skb failed for management frame\n");
201 mwifiex_form_mgmt_frame(skb, buf, len);
202 mwifiex_queue_tx_pkt(priv, skb);
204 *cookie = random32() | 1;
205 cfg80211_mgmt_tx_status(dev, *cookie, buf, len, true, GFP_ATOMIC);
207 wiphy_dbg(wiphy, "info: management frame transmitted\n");
212 * CFG802.11 operation handler to register a mgmt frame.
215 mwifiex_cfg80211_mgmt_frame_register(struct wiphy *wiphy,
216 struct net_device *dev,
217 u16 frame_type, bool reg)
219 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
222 priv->mgmt_frame_mask |= BIT(frame_type >> 4);
224 priv->mgmt_frame_mask &= ~BIT(frame_type >> 4);
226 mwifiex_send_cmd_async(priv, HostCmd_CMD_MGMT_FRAME_REG,
227 HostCmd_ACT_GEN_SET, 0, &priv->mgmt_frame_mask);
229 wiphy_dbg(wiphy, "info: mgmt frame registered\n");
233 * CFG802.11 operation handler to set Tx power.
236 mwifiex_cfg80211_set_tx_power(struct wiphy *wiphy,
237 enum nl80211_tx_power_setting type,
240 struct mwifiex_private *priv = mwifiex_cfg80211_get_priv(wiphy);
241 struct mwifiex_power_cfg power_cfg;
242 int dbm = MBM_TO_DBM(mbm);
244 if (type == NL80211_TX_POWER_FIXED) {
245 power_cfg.is_power_auto = 0;
246 power_cfg.power_level = dbm;
248 power_cfg.is_power_auto = 1;
251 return mwifiex_set_tx_power(priv, &power_cfg);
255 * CFG802.11 operation handler to set Power Save option.
257 * The timeout value, if provided, is currently ignored.
260 mwifiex_cfg80211_set_power_mgmt(struct wiphy *wiphy,
261 struct net_device *dev,
262 bool enabled, int timeout)
264 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
269 "info: ignore timeout value for IEEE Power Save\n");
273 return mwifiex_drv_set_power(priv, &ps_mode);
277 * CFG802.11 operation handler to set the default network key.
280 mwifiex_cfg80211_set_default_key(struct wiphy *wiphy, struct net_device *netdev,
281 u8 key_index, bool unicast,
284 struct mwifiex_private *priv = mwifiex_netdev_get_priv(netdev);
286 /* Return if WEP key not configured */
287 if (!priv->sec_info.wep_enabled)
290 if (mwifiex_set_encode(priv, NULL, 0, key_index, 0)) {
291 wiphy_err(wiphy, "set default Tx key index\n");
299 * CFG802.11 operation handler to add a network key.
302 mwifiex_cfg80211_add_key(struct wiphy *wiphy, struct net_device *netdev,
303 u8 key_index, bool pairwise, const u8 *mac_addr,
304 struct key_params *params)
306 struct mwifiex_private *priv = mwifiex_netdev_get_priv(netdev);
308 if (mwifiex_set_encode(priv, params->key, params->key_len,
310 wiphy_err(wiphy, "crypto keys added\n");
318 * This function sends domain information to the firmware.
320 * The following information are passed to the firmware -
322 * - Sub bands (first channel, number of channels, maximum Tx power)
324 static int mwifiex_send_domain_info_cmd_fw(struct wiphy *wiphy)
326 u8 no_of_triplet = 0;
327 struct ieee80211_country_ie_triplet *t;
328 u8 no_of_parsed_chan = 0;
329 u8 first_chan = 0, next_chan = 0, max_pwr = 0;
331 enum ieee80211_band band;
332 struct ieee80211_supported_band *sband;
333 struct ieee80211_channel *ch;
334 struct mwifiex_private *priv = mwifiex_cfg80211_get_priv(wiphy);
335 struct mwifiex_adapter *adapter = priv->adapter;
336 struct mwifiex_802_11d_domain_reg *domain_info = &adapter->domain_reg;
338 /* Set country code */
339 domain_info->country_code[0] = priv->country_code[0];
340 domain_info->country_code[1] = priv->country_code[1];
341 domain_info->country_code[2] = ' ';
343 band = mwifiex_band_to_radio_type(adapter->config_bands);
344 if (!wiphy->bands[band]) {
345 wiphy_err(wiphy, "11D: setting domain info in FW\n");
349 sband = wiphy->bands[band];
351 for (i = 0; i < sband->n_channels ; i++) {
352 ch = &sband->channels[i];
353 if (ch->flags & IEEE80211_CHAN_DISABLED)
358 first_chan = (u32) ch->hw_value;
359 next_chan = first_chan;
360 max_pwr = ch->max_power;
361 no_of_parsed_chan = 1;
365 if (ch->hw_value == next_chan + 1 &&
366 ch->max_power == max_pwr) {
370 t = &domain_info->triplet[no_of_triplet];
371 t->chans.first_channel = first_chan;
372 t->chans.num_channels = no_of_parsed_chan;
373 t->chans.max_power = max_pwr;
375 first_chan = (u32) ch->hw_value;
376 next_chan = first_chan;
377 max_pwr = ch->max_power;
378 no_of_parsed_chan = 1;
383 t = &domain_info->triplet[no_of_triplet];
384 t->chans.first_channel = first_chan;
385 t->chans.num_channels = no_of_parsed_chan;
386 t->chans.max_power = max_pwr;
390 domain_info->no_of_triplet = no_of_triplet;
392 if (mwifiex_send_cmd_async(priv, HostCmd_CMD_802_11D_DOMAIN_INFO,
393 HostCmd_ACT_GEN_SET, 0, NULL)) {
394 wiphy_err(wiphy, "11D: setting domain info in FW\n");
402 * CFG802.11 regulatory domain callback function.
404 * This function is called when the regulatory domain is changed due to the
405 * following reasons -
407 * - Set by system core
409 * - Set bt Country IE
411 static int mwifiex_reg_notifier(struct wiphy *wiphy,
412 struct regulatory_request *request)
414 struct mwifiex_private *priv = mwifiex_cfg80211_get_priv(wiphy);
416 wiphy_dbg(wiphy, "info: cfg80211 regulatory domain callback for domain"
417 " %c%c\n", request->alpha2[0], request->alpha2[1]);
419 memcpy(priv->country_code, request->alpha2, sizeof(request->alpha2));
421 switch (request->initiator) {
422 case NL80211_REGDOM_SET_BY_DRIVER:
423 case NL80211_REGDOM_SET_BY_CORE:
424 case NL80211_REGDOM_SET_BY_USER:
426 /* Todo: apply driver specific changes in channel flags based
427 on the request initiator if necessary. */
428 case NL80211_REGDOM_SET_BY_COUNTRY_IE:
431 mwifiex_send_domain_info_cmd_fw(wiphy);
437 * This function sets the RF channel.
439 * This function creates multiple IOCTL requests, populates them accordingly
440 * and issues them to set the band/channel and frequency.
443 mwifiex_set_rf_channel(struct mwifiex_private *priv,
444 struct ieee80211_channel *chan,
445 enum nl80211_channel_type channel_type)
447 struct mwifiex_chan_freq_power cfp;
448 u32 config_bands = 0;
449 struct wiphy *wiphy = priv->wdev->wiphy;
450 struct mwifiex_adapter *adapter = priv->adapter;
453 /* Set appropriate bands */
454 if (chan->band == IEEE80211_BAND_2GHZ) {
455 if (channel_type == NL80211_CHAN_NO_HT)
456 if (priv->adapter->config_bands == BAND_B ||
457 priv->adapter->config_bands == BAND_G)
459 priv->adapter->config_bands;
461 config_bands = BAND_B | BAND_G;
463 config_bands = BAND_B | BAND_G | BAND_GN;
465 if (channel_type == NL80211_CHAN_NO_HT)
466 config_bands = BAND_A;
468 config_bands = BAND_AN | BAND_A;
471 if (!((config_bands | adapter->fw_bands) &
472 ~adapter->fw_bands)) {
473 adapter->config_bands = config_bands;
474 if (priv->bss_mode == NL80211_IFTYPE_ADHOC) {
475 adapter->adhoc_start_band = config_bands;
476 if ((config_bands & BAND_GN) ||
477 (config_bands & BAND_AN))
478 adapter->adhoc_11n_enabled = true;
480 adapter->adhoc_11n_enabled = false;
483 adapter->sec_chan_offset =
484 mwifiex_cfg80211_channel_type_to_sec_chan_offset
486 adapter->channel_type = channel_type;
489 wiphy_dbg(wiphy, "info: setting band %d, chan offset %d, mode %d\n",
490 config_bands, adapter->sec_chan_offset, priv->bss_mode);
494 memset(&cfp, 0, sizeof(cfp));
495 cfp.freq = chan->center_freq;
496 cfp.channel = ieee80211_frequency_to_channel(chan->center_freq);
498 if (mwifiex_bss_set_channel(priv, &cfp))
501 return mwifiex_drv_change_adhoc_chan(priv, cfp.channel);
505 * CFG802.11 operation handler to set channel.
507 * This function can only be used when station is not connected.
510 mwifiex_cfg80211_set_channel(struct wiphy *wiphy, struct net_device *dev,
511 struct ieee80211_channel *chan,
512 enum nl80211_channel_type channel_type)
514 struct mwifiex_private *priv;
517 priv = mwifiex_netdev_get_priv(dev);
519 priv = mwifiex_cfg80211_get_priv(wiphy);
521 if (priv->media_connected) {
522 wiphy_err(wiphy, "This setting is valid only when station "
523 "is not connected\n");
527 return mwifiex_set_rf_channel(priv, chan, channel_type);
531 * This function sets the fragmentation threshold.
533 * The fragmentation threshold value must lie between MWIFIEX_FRAG_MIN_VALUE
534 * and MWIFIEX_FRAG_MAX_VALUE.
537 mwifiex_set_frag(struct mwifiex_private *priv, u32 frag_thr)
541 if (frag_thr < MWIFIEX_FRAG_MIN_VALUE ||
542 frag_thr > MWIFIEX_FRAG_MAX_VALUE)
545 /* Send request to firmware */
546 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_SNMP_MIB,
547 HostCmd_ACT_GEN_SET, FRAG_THRESH_I,
554 * This function sets the RTS threshold.
556 * The rts value must lie between MWIFIEX_RTS_MIN_VALUE
557 * and MWIFIEX_RTS_MAX_VALUE.
560 mwifiex_set_rts(struct mwifiex_private *priv, u32 rts_thr)
562 if (rts_thr < MWIFIEX_RTS_MIN_VALUE || rts_thr > MWIFIEX_RTS_MAX_VALUE)
563 rts_thr = MWIFIEX_RTS_MAX_VALUE;
565 return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_SNMP_MIB,
566 HostCmd_ACT_GEN_SET, RTS_THRESH_I,
571 * CFG802.11 operation handler to set wiphy parameters.
573 * This function can be used to set the RTS threshold and the
574 * Fragmentation threshold of the driver.
577 mwifiex_cfg80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
579 struct mwifiex_private *priv = mwifiex_cfg80211_get_priv(wiphy);
582 if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
583 ret = mwifiex_set_rts(priv, wiphy->rts_threshold);
588 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
589 ret = mwifiex_set_frag(priv, wiphy->frag_threshold);
595 * CFG802.11 operation handler to change interface type.
598 mwifiex_cfg80211_change_virtual_intf(struct wiphy *wiphy,
599 struct net_device *dev,
600 enum nl80211_iftype type, u32 *flags,
601 struct vif_params *params)
604 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
606 if (priv->bss_mode == type) {
607 wiphy_warn(wiphy, "already set to required type\n");
611 priv->bss_mode = type;
614 case NL80211_IFTYPE_ADHOC:
615 dev->ieee80211_ptr->iftype = NL80211_IFTYPE_ADHOC;
616 wiphy_dbg(wiphy, "info: setting interface type to adhoc\n");
618 case NL80211_IFTYPE_STATION:
619 dev->ieee80211_ptr->iftype = NL80211_IFTYPE_STATION;
620 wiphy_dbg(wiphy, "info: setting interface type to managed\n");
622 case NL80211_IFTYPE_UNSPECIFIED:
623 dev->ieee80211_ptr->iftype = NL80211_IFTYPE_STATION;
624 wiphy_dbg(wiphy, "info: setting interface type to auto\n");
627 wiphy_err(wiphy, "unknown interface type: %d\n", type);
631 mwifiex_deauthenticate(priv, NULL);
633 priv->sec_info.authentication_mode = NL80211_AUTHTYPE_OPEN_SYSTEM;
635 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_SET_BSS_MODE,
636 HostCmd_ACT_GEN_SET, 0, NULL);
642 * This function dumps the station information on a buffer.
644 * The following information are shown -
645 * - Total bytes transmitted
646 * - Total bytes received
647 * - Total packets transmitted
648 * - Total packets received
649 * - Signal quality level
650 * - Transmission rate
653 mwifiex_dump_station_info(struct mwifiex_private *priv,
654 struct station_info *sinfo)
656 struct mwifiex_rate_cfg rate;
658 sinfo->filled = STATION_INFO_RX_BYTES | STATION_INFO_TX_BYTES |
659 STATION_INFO_RX_PACKETS | STATION_INFO_TX_PACKETS |
660 STATION_INFO_TX_BITRATE |
661 STATION_INFO_SIGNAL | STATION_INFO_SIGNAL_AVG;
663 /* Get signal information from the firmware */
664 if (mwifiex_send_cmd_sync(priv, HostCmd_CMD_RSSI_INFO,
665 HostCmd_ACT_GEN_GET, 0, NULL)) {
666 dev_err(priv->adapter->dev, "failed to get signal information\n");
670 if (mwifiex_drv_get_data_rate(priv, &rate)) {
671 dev_err(priv->adapter->dev, "getting data rate\n");
675 /* Get DTIM period information from firmware */
676 mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_SNMP_MIB,
677 HostCmd_ACT_GEN_GET, DTIM_PERIOD_I,
681 * Bit 0 in tx_htinfo indicates that current Tx rate is 11n rate. Valid
682 * MCS index values for us are 0 to 15.
684 if ((priv->tx_htinfo & BIT(0)) && (priv->tx_rate < 16)) {
685 sinfo->txrate.mcs = priv->tx_rate;
686 sinfo->txrate.flags |= RATE_INFO_FLAGS_MCS;
688 if (priv->tx_htinfo & BIT(1))
689 sinfo->txrate.flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
691 if (priv->tx_htinfo & BIT(2))
692 sinfo->txrate.flags |= RATE_INFO_FLAGS_SHORT_GI;
695 sinfo->signal_avg = priv->bcn_rssi_avg;
696 sinfo->rx_bytes = priv->stats.rx_bytes;
697 sinfo->tx_bytes = priv->stats.tx_bytes;
698 sinfo->rx_packets = priv->stats.rx_packets;
699 sinfo->tx_packets = priv->stats.tx_packets;
700 sinfo->signal = priv->bcn_rssi_avg;
701 /* bit rate is in 500 kb/s units. Convert it to 100kb/s units */
702 sinfo->txrate.legacy = rate.rate * 5;
704 if (priv->bss_mode == NL80211_IFTYPE_STATION) {
705 sinfo->filled |= STATION_INFO_BSS_PARAM;
706 sinfo->bss_param.flags = 0;
707 if (priv->curr_bss_params.bss_descriptor.cap_info_bitmap &
708 WLAN_CAPABILITY_SHORT_PREAMBLE)
709 sinfo->bss_param.flags |=
710 BSS_PARAM_FLAGS_SHORT_PREAMBLE;
711 if (priv->curr_bss_params.bss_descriptor.cap_info_bitmap &
712 WLAN_CAPABILITY_SHORT_SLOT_TIME)
713 sinfo->bss_param.flags |=
714 BSS_PARAM_FLAGS_SHORT_SLOT_TIME;
715 sinfo->bss_param.dtim_period = priv->dtim_period;
716 sinfo->bss_param.beacon_interval =
717 priv->curr_bss_params.bss_descriptor.beacon_period;
724 * CFG802.11 operation handler to get station information.
726 * This function only works in connected mode, and dumps the
727 * requested station information, if available.
730 mwifiex_cfg80211_get_station(struct wiphy *wiphy, struct net_device *dev,
731 u8 *mac, struct station_info *sinfo)
733 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
735 if (!priv->media_connected)
737 if (memcmp(mac, priv->cfg_bssid, ETH_ALEN))
740 return mwifiex_dump_station_info(priv, sinfo);
744 * CFG802.11 operation handler to dump station information.
747 mwifiex_cfg80211_dump_station(struct wiphy *wiphy, struct net_device *dev,
748 int idx, u8 *mac, struct station_info *sinfo)
750 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
752 if (!priv->media_connected || idx)
755 memcpy(mac, priv->cfg_bssid, ETH_ALEN);
757 return mwifiex_dump_station_info(priv, sinfo);
760 /* Supported rates to be advertised to the cfg80211 */
762 static struct ieee80211_rate mwifiex_rates[] = {
763 {.bitrate = 10, .hw_value = 2, },
764 {.bitrate = 20, .hw_value = 4, },
765 {.bitrate = 55, .hw_value = 11, },
766 {.bitrate = 110, .hw_value = 22, },
767 {.bitrate = 60, .hw_value = 12, },
768 {.bitrate = 90, .hw_value = 18, },
769 {.bitrate = 120, .hw_value = 24, },
770 {.bitrate = 180, .hw_value = 36, },
771 {.bitrate = 240, .hw_value = 48, },
772 {.bitrate = 360, .hw_value = 72, },
773 {.bitrate = 480, .hw_value = 96, },
774 {.bitrate = 540, .hw_value = 108, },
777 /* Channel definitions to be advertised to cfg80211 */
779 static struct ieee80211_channel mwifiex_channels_2ghz[] = {
780 {.center_freq = 2412, .hw_value = 1, },
781 {.center_freq = 2417, .hw_value = 2, },
782 {.center_freq = 2422, .hw_value = 3, },
783 {.center_freq = 2427, .hw_value = 4, },
784 {.center_freq = 2432, .hw_value = 5, },
785 {.center_freq = 2437, .hw_value = 6, },
786 {.center_freq = 2442, .hw_value = 7, },
787 {.center_freq = 2447, .hw_value = 8, },
788 {.center_freq = 2452, .hw_value = 9, },
789 {.center_freq = 2457, .hw_value = 10, },
790 {.center_freq = 2462, .hw_value = 11, },
791 {.center_freq = 2467, .hw_value = 12, },
792 {.center_freq = 2472, .hw_value = 13, },
793 {.center_freq = 2484, .hw_value = 14, },
796 static struct ieee80211_supported_band mwifiex_band_2ghz = {
797 .channels = mwifiex_channels_2ghz,
798 .n_channels = ARRAY_SIZE(mwifiex_channels_2ghz),
799 .bitrates = mwifiex_rates,
800 .n_bitrates = ARRAY_SIZE(mwifiex_rates),
803 static struct ieee80211_channel mwifiex_channels_5ghz[] = {
804 {.center_freq = 5040, .hw_value = 8, },
805 {.center_freq = 5060, .hw_value = 12, },
806 {.center_freq = 5080, .hw_value = 16, },
807 {.center_freq = 5170, .hw_value = 34, },
808 {.center_freq = 5190, .hw_value = 38, },
809 {.center_freq = 5210, .hw_value = 42, },
810 {.center_freq = 5230, .hw_value = 46, },
811 {.center_freq = 5180, .hw_value = 36, },
812 {.center_freq = 5200, .hw_value = 40, },
813 {.center_freq = 5220, .hw_value = 44, },
814 {.center_freq = 5240, .hw_value = 48, },
815 {.center_freq = 5260, .hw_value = 52, },
816 {.center_freq = 5280, .hw_value = 56, },
817 {.center_freq = 5300, .hw_value = 60, },
818 {.center_freq = 5320, .hw_value = 64, },
819 {.center_freq = 5500, .hw_value = 100, },
820 {.center_freq = 5520, .hw_value = 104, },
821 {.center_freq = 5540, .hw_value = 108, },
822 {.center_freq = 5560, .hw_value = 112, },
823 {.center_freq = 5580, .hw_value = 116, },
824 {.center_freq = 5600, .hw_value = 120, },
825 {.center_freq = 5620, .hw_value = 124, },
826 {.center_freq = 5640, .hw_value = 128, },
827 {.center_freq = 5660, .hw_value = 132, },
828 {.center_freq = 5680, .hw_value = 136, },
829 {.center_freq = 5700, .hw_value = 140, },
830 {.center_freq = 5745, .hw_value = 149, },
831 {.center_freq = 5765, .hw_value = 153, },
832 {.center_freq = 5785, .hw_value = 157, },
833 {.center_freq = 5805, .hw_value = 161, },
834 {.center_freq = 5825, .hw_value = 165, },
837 static struct ieee80211_supported_band mwifiex_band_5ghz = {
838 .channels = mwifiex_channels_5ghz,
839 .n_channels = ARRAY_SIZE(mwifiex_channels_5ghz),
840 .bitrates = mwifiex_rates + 4,
841 .n_bitrates = ARRAY_SIZE(mwifiex_rates) - 4,
845 /* Supported crypto cipher suits to be advertised to cfg80211 */
847 static const u32 mwifiex_cipher_suites[] = {
848 WLAN_CIPHER_SUITE_WEP40,
849 WLAN_CIPHER_SUITE_WEP104,
850 WLAN_CIPHER_SUITE_TKIP,
851 WLAN_CIPHER_SUITE_CCMP,
854 /* Supported mgmt frame types to be advertised to cfg80211 */
855 static const struct ieee80211_txrx_stypes
856 mwifiex_mgmt_stypes[NUM_NL80211_IFTYPES] = {
857 [NL80211_IFTYPE_STATION] = {
858 .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
859 BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
860 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
861 BIT(IEEE80211_STYPE_PROBE_REQ >> 4),
863 [NL80211_IFTYPE_AP] = {
864 .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
865 BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
866 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
867 BIT(IEEE80211_STYPE_PROBE_REQ >> 4),
869 [NL80211_IFTYPE_P2P_CLIENT] = {
870 .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
871 BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
872 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
873 BIT(IEEE80211_STYPE_PROBE_REQ >> 4),
875 [NL80211_IFTYPE_P2P_GO] = {
876 .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
877 BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
878 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
879 BIT(IEEE80211_STYPE_PROBE_REQ >> 4),
884 * CFG802.11 operation handler for setting bit rates.
886 * Function selects legacy bang B/G/BG from corresponding bitrates selection.
887 * Currently only 2.4GHz band is supported.
889 static int mwifiex_cfg80211_set_bitrate_mask(struct wiphy *wiphy,
890 struct net_device *dev,
892 const struct cfg80211_bitrate_mask *mask)
894 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
895 int index = 0, mode = 0, i;
896 struct mwifiex_adapter *adapter = priv->adapter;
898 /* Currently only 2.4GHz is supported */
899 for (i = 0; i < mwifiex_band_2ghz.n_bitrates; i++) {
901 * Rates below 6 Mbps in the table are CCK rates; 802.11b
902 * and from 6 they are OFDM; 802.11G
904 if (mwifiex_rates[i].bitrate == 60) {
910 if (mask->control[IEEE80211_BAND_2GHZ].legacy < index) {
914 if (mask->control[IEEE80211_BAND_2GHZ].legacy % index)
918 if (!((mode | adapter->fw_bands) & ~adapter->fw_bands)) {
919 adapter->config_bands = mode;
920 if (priv->bss_mode == NL80211_IFTYPE_ADHOC) {
921 adapter->adhoc_start_band = mode;
922 adapter->adhoc_11n_enabled = false;
925 adapter->sec_chan_offset = IEEE80211_HT_PARAM_CHA_SEC_NONE;
926 adapter->channel_type = NL80211_CHAN_NO_HT;
928 wiphy_debug(wiphy, "info: device configured in 802.11%s%s mode\n",
929 (mode & BAND_B) ? "b" : "", (mode & BAND_G) ? "g" : "");
935 * CFG802.11 operation handler for connection quality monitoring.
937 * This function subscribes/unsubscribes HIGH_RSSI and LOW_RSSI
940 static int mwifiex_cfg80211_set_cqm_rssi_config(struct wiphy *wiphy,
941 struct net_device *dev,
942 s32 rssi_thold, u32 rssi_hyst)
944 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
945 struct mwifiex_ds_misc_subsc_evt subsc_evt;
947 priv->cqm_rssi_thold = rssi_thold;
948 priv->cqm_rssi_hyst = rssi_hyst;
950 memset(&subsc_evt, 0x00, sizeof(struct mwifiex_ds_misc_subsc_evt));
951 subsc_evt.events = BITMASK_BCN_RSSI_LOW | BITMASK_BCN_RSSI_HIGH;
953 /* Subscribe/unsubscribe low and high rssi events */
954 if (rssi_thold && rssi_hyst) {
955 subsc_evt.action = HostCmd_ACT_BITWISE_SET;
956 subsc_evt.bcn_l_rssi_cfg.abs_value = abs(rssi_thold);
957 subsc_evt.bcn_h_rssi_cfg.abs_value = abs(rssi_thold);
958 subsc_evt.bcn_l_rssi_cfg.evt_freq = 1;
959 subsc_evt.bcn_h_rssi_cfg.evt_freq = 1;
960 return mwifiex_send_cmd_sync(priv,
961 HostCmd_CMD_802_11_SUBSCRIBE_EVENT,
964 subsc_evt.action = HostCmd_ACT_BITWISE_CLR;
965 return mwifiex_send_cmd_sync(priv,
966 HostCmd_CMD_802_11_SUBSCRIBE_EVENT,
974 * CFG802.11 operation handler for disconnection request.
976 * This function does not work when there is already a disconnection
977 * procedure going on.
980 mwifiex_cfg80211_disconnect(struct wiphy *wiphy, struct net_device *dev,
983 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
985 if (mwifiex_deauthenticate(priv, NULL))
988 wiphy_dbg(wiphy, "info: successfully disconnected from %pM:"
989 " reason code %d\n", priv->cfg_bssid, reason_code);
991 memset(priv->cfg_bssid, 0, ETH_ALEN);
997 * This function informs the CFG802.11 subsystem of a new IBSS.
999 * The following information are sent to the CFG802.11 subsystem
1000 * to register the new IBSS. If we do not register the new IBSS,
1001 * a kernel panic will result.
1007 static int mwifiex_cfg80211_inform_ibss_bss(struct mwifiex_private *priv)
1009 struct ieee80211_channel *chan;
1010 struct mwifiex_bss_info bss_info;
1011 struct cfg80211_bss *bss;
1013 u8 ie_buf[IEEE80211_MAX_SSID_LEN + sizeof(struct ieee_types_header)];
1014 enum ieee80211_band band;
1016 if (mwifiex_get_bss_info(priv, &bss_info))
1019 ie_buf[0] = WLAN_EID_SSID;
1020 ie_buf[1] = bss_info.ssid.ssid_len;
1022 memcpy(&ie_buf[sizeof(struct ieee_types_header)],
1023 &bss_info.ssid.ssid, bss_info.ssid.ssid_len);
1024 ie_len = ie_buf[1] + sizeof(struct ieee_types_header);
1026 band = mwifiex_band_to_radio_type(priv->curr_bss_params.band);
1027 chan = __ieee80211_get_channel(priv->wdev->wiphy,
1028 ieee80211_channel_to_frequency(bss_info.bss_chan,
1031 bss = cfg80211_inform_bss(priv->wdev->wiphy, chan,
1032 bss_info.bssid, 0, WLAN_CAPABILITY_IBSS,
1033 0, ie_buf, ie_len, 0, GFP_KERNEL);
1034 cfg80211_put_bss(bss);
1035 memcpy(priv->cfg_bssid, bss_info.bssid, ETH_ALEN);
1041 * This function connects with a BSS.
1043 * This function handles both Infra and Ad-Hoc modes. It also performs
1044 * validity checking on the provided parameters, disconnects from the
1045 * current BSS (if any), sets up the association/scan parameters,
1046 * including security settings, and performs specific SSID scan before
1047 * trying to connect.
1049 * For Infra mode, the function returns failure if the specified SSID
1050 * is not found in scan table. However, for Ad-Hoc mode, it can create
1051 * the IBSS if it does not exist. On successful completion in either case,
1052 * the function notifies the CFG802.11 subsystem of the new BSS connection.
1055 mwifiex_cfg80211_assoc(struct mwifiex_private *priv, size_t ssid_len, u8 *ssid,
1056 u8 *bssid, int mode, struct ieee80211_channel *channel,
1057 struct cfg80211_connect_params *sme, bool privacy)
1059 struct cfg80211_ssid req_ssid;
1060 int ret, auth_type = 0;
1061 struct cfg80211_bss *bss = NULL;
1062 u8 is_scanning_required = 0;
1064 memset(&req_ssid, 0, sizeof(struct cfg80211_ssid));
1066 req_ssid.ssid_len = ssid_len;
1067 if (ssid_len > IEEE80211_MAX_SSID_LEN) {
1068 dev_err(priv->adapter->dev, "invalid SSID - aborting\n");
1072 memcpy(req_ssid.ssid, ssid, ssid_len);
1073 if (!req_ssid.ssid_len || req_ssid.ssid[0] < 0x20) {
1074 dev_err(priv->adapter->dev, "invalid SSID - aborting\n");
1078 /* disconnect before try to associate */
1079 mwifiex_deauthenticate(priv, NULL);
1082 ret = mwifiex_set_rf_channel(priv, channel,
1083 priv->adapter->channel_type);
1085 /* As this is new association, clear locally stored
1086 * keys and security related flags */
1087 priv->sec_info.wpa_enabled = false;
1088 priv->sec_info.wpa2_enabled = false;
1089 priv->wep_key_curr_index = 0;
1090 priv->sec_info.encryption_mode = 0;
1091 priv->sec_info.is_authtype_auto = 0;
1092 ret = mwifiex_set_encode(priv, NULL, 0, 0, 1);
1094 if (mode == NL80211_IFTYPE_ADHOC) {
1095 /* "privacy" is set only for ad-hoc mode */
1098 * Keep WLAN_CIPHER_SUITE_WEP104 for now so that
1099 * the firmware can find a matching network from the
1100 * scan. The cfg80211 does not give us the encryption
1101 * mode at this stage so just setting it to WEP here.
1103 priv->sec_info.encryption_mode =
1104 WLAN_CIPHER_SUITE_WEP104;
1105 priv->sec_info.authentication_mode =
1106 NL80211_AUTHTYPE_OPEN_SYSTEM;
1112 /* Now handle infra mode. "sme" is valid for infra mode only */
1113 if (sme->auth_type == NL80211_AUTHTYPE_AUTOMATIC) {
1114 auth_type = NL80211_AUTHTYPE_OPEN_SYSTEM;
1115 priv->sec_info.is_authtype_auto = 1;
1117 auth_type = sme->auth_type;
1120 if (sme->crypto.n_ciphers_pairwise) {
1121 priv->sec_info.encryption_mode =
1122 sme->crypto.ciphers_pairwise[0];
1123 priv->sec_info.authentication_mode = auth_type;
1126 if (sme->crypto.cipher_group) {
1127 priv->sec_info.encryption_mode = sme->crypto.cipher_group;
1128 priv->sec_info.authentication_mode = auth_type;
1131 ret = mwifiex_set_gen_ie(priv, sme->ie, sme->ie_len);
1134 if (mwifiex_is_alg_wep(priv->sec_info.encryption_mode)) {
1135 dev_dbg(priv->adapter->dev,
1136 "info: setting wep encryption"
1137 " with key len %d\n", sme->key_len);
1138 priv->wep_key_curr_index = sme->key_idx;
1139 ret = mwifiex_set_encode(priv, sme->key, sme->key_len,
1145 * Scan entries are valid for some time (15 sec). So we can save one
1146 * active scan time if we just try cfg80211_get_bss first. If it fails
1147 * then request scan and cfg80211_get_bss() again for final output.
1150 if (is_scanning_required) {
1151 /* Do specific SSID scanning */
1152 if (mwifiex_request_scan(priv, &req_ssid)) {
1153 dev_err(priv->adapter->dev, "scan error\n");
1158 /* Find the BSS we want using available scan results */
1159 if (mode == NL80211_IFTYPE_ADHOC)
1160 bss = cfg80211_get_bss(priv->wdev->wiphy, channel,
1161 bssid, ssid, ssid_len,
1162 WLAN_CAPABILITY_IBSS,
1163 WLAN_CAPABILITY_IBSS);
1165 bss = cfg80211_get_bss(priv->wdev->wiphy, channel,
1166 bssid, ssid, ssid_len,
1167 WLAN_CAPABILITY_ESS,
1168 WLAN_CAPABILITY_ESS);
1171 if (is_scanning_required) {
1172 dev_warn(priv->adapter->dev,
1173 "assoc: requested bss not found in scan results\n");
1176 is_scanning_required = 1;
1178 dev_dbg(priv->adapter->dev,
1179 "info: trying to associate to '%s' bssid %pM\n",
1180 (char *) req_ssid.ssid, bss->bssid);
1181 memcpy(&priv->cfg_bssid, bss->bssid, ETH_ALEN);
1186 ret = mwifiex_bss_start(priv, bss, &req_ssid);
1190 if (mode == NL80211_IFTYPE_ADHOC) {
1191 /* Inform the BSS information to kernel, otherwise
1192 * kernel will give a panic after successful assoc */
1193 if (mwifiex_cfg80211_inform_ibss_bss(priv))
1201 * CFG802.11 operation handler for association request.
1203 * This function does not work when the current mode is set to Ad-Hoc, or
1204 * when there is already an association procedure going on. The given BSS
1205 * information is used to associate.
1208 mwifiex_cfg80211_connect(struct wiphy *wiphy, struct net_device *dev,
1209 struct cfg80211_connect_params *sme)
1211 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
1214 if (priv->bss_mode == NL80211_IFTYPE_ADHOC) {
1215 wiphy_err(wiphy, "received infra assoc request "
1216 "when station is in ibss mode\n");
1220 wiphy_dbg(wiphy, "info: Trying to associate to %s and bssid %pM\n",
1221 (char *) sme->ssid, sme->bssid);
1223 ret = mwifiex_cfg80211_assoc(priv, sme->ssid_len, sme->ssid, sme->bssid,
1224 priv->bss_mode, sme->channel, sme, 0);
1227 cfg80211_connect_result(priv->netdev, priv->cfg_bssid, NULL, 0,
1228 NULL, 0, WLAN_STATUS_SUCCESS,
1230 dev_dbg(priv->adapter->dev,
1231 "info: associated to bssid %pM successfully\n",
1234 dev_dbg(priv->adapter->dev,
1235 "info: association to bssid %pM failed\n",
1237 memset(priv->cfg_bssid, 0, ETH_ALEN);
1240 cfg80211_connect_result(priv->netdev, priv->cfg_bssid,
1241 NULL, 0, NULL, 0, ret,
1244 cfg80211_connect_result(priv->netdev, priv->cfg_bssid,
1246 WLAN_STATUS_UNSPECIFIED_FAILURE,
1254 * CFG802.11 operation handler to join an IBSS.
1256 * This function does not work in any mode other than Ad-Hoc, or if
1257 * a join operation is already in progress.
1260 mwifiex_cfg80211_join_ibss(struct wiphy *wiphy, struct net_device *dev,
1261 struct cfg80211_ibss_params *params)
1263 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
1266 if (priv->bss_mode != NL80211_IFTYPE_ADHOC) {
1267 wiphy_err(wiphy, "request to join ibss received "
1268 "when station is not in ibss mode\n");
1272 wiphy_dbg(wiphy, "info: trying to join to %s and bssid %pM\n",
1273 (char *) params->ssid, params->bssid);
1275 ret = mwifiex_cfg80211_assoc(priv, params->ssid_len, params->ssid,
1276 params->bssid, priv->bss_mode,
1277 params->channel, NULL, params->privacy);
1280 cfg80211_ibss_joined(priv->netdev, priv->cfg_bssid, GFP_KERNEL);
1281 dev_dbg(priv->adapter->dev,
1282 "info: joined/created adhoc network with bssid"
1283 " %pM successfully\n", priv->cfg_bssid);
1285 dev_dbg(priv->adapter->dev,
1286 "info: failed creating/joining adhoc network\n");
1293 * CFG802.11 operation handler to leave an IBSS.
1295 * This function does not work if a leave operation is
1296 * already in progress.
1299 mwifiex_cfg80211_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
1301 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
1303 wiphy_dbg(wiphy, "info: disconnecting from essid %pM\n",
1305 if (mwifiex_deauthenticate(priv, NULL))
1308 memset(priv->cfg_bssid, 0, ETH_ALEN);
1314 * CFG802.11 operation handler for scan request.
1316 * This function issues a scan request to the firmware based upon
1317 * the user specified scan configuration. On successfull completion,
1318 * it also informs the results.
1321 mwifiex_cfg80211_scan(struct wiphy *wiphy, struct net_device *dev,
1322 struct cfg80211_scan_request *request)
1324 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
1326 struct ieee80211_channel *chan;
1328 wiphy_dbg(wiphy, "info: received scan request on %s\n", dev->name);
1330 if ((request->flags & CFG80211_SCAN_FLAG_TX_ABORT) &&
1331 atomic_read(&priv->wmm.tx_pkts_queued) >=
1332 MWIFIEX_MIN_TX_PENDING_TO_CANCEL_SCAN) {
1333 dev_dbg(priv->adapter->dev, "scan rejected due to traffic\n");
1337 if (priv->user_scan_cfg) {
1338 dev_err(priv->adapter->dev, "cmd: Scan already in process..\n");
1342 priv->user_scan_cfg = kzalloc(sizeof(struct mwifiex_user_scan_cfg),
1344 if (!priv->user_scan_cfg) {
1345 dev_err(priv->adapter->dev, "failed to alloc scan_req\n");
1349 priv->scan_request = request;
1351 priv->user_scan_cfg->num_ssids = request->n_ssids;
1352 priv->user_scan_cfg->ssid_list = request->ssids;
1354 if (request->ie && request->ie_len) {
1355 for (i = 0; i < MWIFIEX_MAX_VSIE_NUM; i++) {
1356 if (priv->vs_ie[i].mask != MWIFIEX_VSIE_MASK_CLEAR)
1358 priv->vs_ie[i].mask = MWIFIEX_VSIE_MASK_SCAN;
1359 memcpy(&priv->vs_ie[i].ie, request->ie,
1365 for (i = 0; i < request->n_channels; i++) {
1366 chan = request->channels[i];
1367 priv->user_scan_cfg->chan_list[i].chan_number = chan->hw_value;
1368 priv->user_scan_cfg->chan_list[i].radio_type = chan->band;
1370 if (chan->flags & IEEE80211_CHAN_PASSIVE_SCAN)
1371 priv->user_scan_cfg->chan_list[i].scan_type =
1372 MWIFIEX_SCAN_TYPE_PASSIVE;
1374 priv->user_scan_cfg->chan_list[i].scan_type =
1375 MWIFIEX_SCAN_TYPE_ACTIVE;
1377 priv->user_scan_cfg->chan_list[i].scan_time = 0;
1380 ret = mwifiex_scan_networks(priv, priv->user_scan_cfg);
1382 dev_err(priv->adapter->dev, "scan failed: %d\n", ret);
1383 priv->scan_request = NULL;
1384 kfree(priv->user_scan_cfg);
1385 priv->user_scan_cfg = NULL;
1389 if (request->ie && request->ie_len) {
1390 for (i = 0; i < MWIFIEX_MAX_VSIE_NUM; i++) {
1391 if (priv->vs_ie[i].mask == MWIFIEX_VSIE_MASK_SCAN) {
1392 priv->vs_ie[i].mask = MWIFIEX_VSIE_MASK_CLEAR;
1393 memset(&priv->vs_ie[i].ie, 0,
1394 MWIFIEX_MAX_VSIE_LEN);
1402 * This function sets up the CFG802.11 specific HT capability fields
1403 * with default values.
1405 * The following default values are set -
1406 * - HT Supported = True
1407 * - Maximum AMPDU length factor = IEEE80211_HT_MAX_AMPDU_64K
1408 * - Minimum AMPDU spacing = IEEE80211_HT_MPDU_DENSITY_NONE
1409 * - HT Capabilities supported by firmware
1410 * - MCS information, Rx mask = 0xff
1411 * - MCD information, Tx parameters = IEEE80211_HT_MCS_TX_DEFINED (0x01)
1414 mwifiex_setup_ht_caps(struct ieee80211_sta_ht_cap *ht_info,
1415 struct mwifiex_private *priv)
1418 struct ieee80211_mcs_info mcs_set;
1419 u8 *mcs = (u8 *)&mcs_set;
1420 struct mwifiex_adapter *adapter = priv->adapter;
1422 ht_info->ht_supported = true;
1423 ht_info->ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
1424 ht_info->ampdu_density = IEEE80211_HT_MPDU_DENSITY_NONE;
1426 memset(&ht_info->mcs, 0, sizeof(ht_info->mcs));
1428 /* Fill HT capability information */
1429 if (ISSUPP_CHANWIDTH40(adapter->hw_dot_11n_dev_cap))
1430 ht_info->cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
1432 ht_info->cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
1434 if (ISSUPP_SHORTGI20(adapter->hw_dot_11n_dev_cap))
1435 ht_info->cap |= IEEE80211_HT_CAP_SGI_20;
1437 ht_info->cap &= ~IEEE80211_HT_CAP_SGI_20;
1439 if (ISSUPP_SHORTGI40(adapter->hw_dot_11n_dev_cap))
1440 ht_info->cap |= IEEE80211_HT_CAP_SGI_40;
1442 ht_info->cap &= ~IEEE80211_HT_CAP_SGI_40;
1444 if (ISSUPP_RXSTBC(adapter->hw_dot_11n_dev_cap))
1445 ht_info->cap |= 1 << IEEE80211_HT_CAP_RX_STBC_SHIFT;
1447 ht_info->cap &= ~(3 << IEEE80211_HT_CAP_RX_STBC_SHIFT);
1449 if (ISSUPP_TXSTBC(adapter->hw_dot_11n_dev_cap))
1450 ht_info->cap |= IEEE80211_HT_CAP_TX_STBC;
1452 ht_info->cap &= ~IEEE80211_HT_CAP_TX_STBC;
1454 ht_info->cap &= ~IEEE80211_HT_CAP_MAX_AMSDU;
1455 ht_info->cap |= IEEE80211_HT_CAP_SM_PS;
1457 rx_mcs_supp = GET_RXMCSSUPP(adapter->hw_dev_mcs_support);
1458 /* Set MCS for 1x1 */
1459 memset(mcs, 0xff, rx_mcs_supp);
1460 /* Clear all the other values */
1461 memset(&mcs[rx_mcs_supp], 0,
1462 sizeof(struct ieee80211_mcs_info) - rx_mcs_supp);
1463 if (priv->bss_mode == NL80211_IFTYPE_STATION ||
1464 ISSUPP_CHANWIDTH40(adapter->hw_dot_11n_dev_cap))
1465 /* Set MCS32 for infra mode or ad-hoc mode with 40MHz support */
1466 SETHT_MCS32(mcs_set.rx_mask);
1468 memcpy((u8 *) &ht_info->mcs, mcs, sizeof(struct ieee80211_mcs_info));
1470 ht_info->mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED;
1474 * create a new virtual interface with the given name
1476 struct net_device *mwifiex_add_virtual_intf(struct wiphy *wiphy,
1478 enum nl80211_iftype type,
1480 struct vif_params *params)
1482 struct mwifiex_private *priv = mwifiex_cfg80211_get_priv(wiphy);
1483 struct mwifiex_adapter *adapter;
1484 struct net_device *dev;
1488 return ERR_PTR(-EFAULT);
1490 adapter = priv->adapter;
1492 return ERR_PTR(-EFAULT);
1495 case NL80211_IFTYPE_UNSPECIFIED:
1496 case NL80211_IFTYPE_STATION:
1497 case NL80211_IFTYPE_ADHOC:
1498 if (priv->bss_mode) {
1499 wiphy_err(wiphy, "cannot create multiple"
1500 " station/adhoc interfaces\n");
1501 return ERR_PTR(-EINVAL);
1504 if (type == NL80211_IFTYPE_UNSPECIFIED)
1505 priv->bss_mode = NL80211_IFTYPE_STATION;
1507 priv->bss_mode = type;
1509 priv->bss_type = MWIFIEX_BSS_TYPE_STA;
1510 priv->frame_type = MWIFIEX_DATA_FRAME_TYPE_ETH_II;
1511 priv->bss_priority = 0;
1512 priv->bss_role = MWIFIEX_BSS_ROLE_STA;
1517 wiphy_err(wiphy, "type not supported\n");
1518 return ERR_PTR(-EINVAL);
1521 dev = alloc_netdev_mq(sizeof(struct mwifiex_private *), name,
1524 wiphy_err(wiphy, "no memory available for netdevice\n");
1525 priv->bss_mode = NL80211_IFTYPE_UNSPECIFIED;
1526 return ERR_PTR(-ENOMEM);
1529 dev_net_set(dev, wiphy_net(wiphy));
1530 dev->ieee80211_ptr = priv->wdev;
1531 dev->ieee80211_ptr->iftype = priv->bss_mode;
1532 memcpy(dev->dev_addr, wiphy->perm_addr, ETH_ALEN);
1533 memcpy(dev->perm_addr, wiphy->perm_addr, ETH_ALEN);
1534 SET_NETDEV_DEV(dev, wiphy_dev(wiphy));
1536 dev->flags |= IFF_BROADCAST | IFF_MULTICAST;
1537 dev->watchdog_timeo = MWIFIEX_DEFAULT_WATCHDOG_TIMEOUT;
1538 dev->hard_header_len += MWIFIEX_MIN_DATA_HEADER_LEN;
1540 mdev_priv = netdev_priv(dev);
1541 *((unsigned long *) mdev_priv) = (unsigned long) priv;
1544 mwifiex_init_priv_params(priv, dev);
1546 SET_NETDEV_DEV(dev, adapter->dev);
1548 /* Register network device */
1549 if (register_netdevice(dev)) {
1550 wiphy_err(wiphy, "cannot register virtual network device\n");
1552 priv->bss_mode = NL80211_IFTYPE_UNSPECIFIED;
1553 return ERR_PTR(-EFAULT);
1556 sema_init(&priv->async_sem, 1);
1557 priv->scan_pending_on_block = false;
1559 dev_dbg(adapter->dev, "info: %s: Marvell 802.11 Adapter\n", dev->name);
1561 #ifdef CONFIG_DEBUG_FS
1562 mwifiex_dev_debugfs_init(priv);
1566 EXPORT_SYMBOL_GPL(mwifiex_add_virtual_intf);
1569 * del_virtual_intf: remove the virtual interface determined by dev
1571 int mwifiex_del_virtual_intf(struct wiphy *wiphy, struct net_device *dev)
1573 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
1575 #ifdef CONFIG_DEBUG_FS
1576 mwifiex_dev_debugfs_remove(priv);
1579 if (!netif_queue_stopped(priv->netdev))
1580 netif_stop_queue(priv->netdev);
1582 if (netif_carrier_ok(priv->netdev))
1583 netif_carrier_off(priv->netdev);
1585 if (dev->reg_state == NETREG_REGISTERED)
1586 unregister_netdevice(dev);
1588 if (dev->reg_state == NETREG_UNREGISTERED)
1591 /* Clear the priv in adapter */
1592 priv->netdev = NULL;
1594 priv->media_connected = false;
1596 priv->bss_mode = NL80211_IFTYPE_UNSPECIFIED;
1600 EXPORT_SYMBOL_GPL(mwifiex_del_virtual_intf);
1602 /* station cfg80211 operations */
1603 static struct cfg80211_ops mwifiex_cfg80211_ops = {
1604 .add_virtual_intf = mwifiex_add_virtual_intf,
1605 .del_virtual_intf = mwifiex_del_virtual_intf,
1606 .change_virtual_intf = mwifiex_cfg80211_change_virtual_intf,
1607 .scan = mwifiex_cfg80211_scan,
1608 .connect = mwifiex_cfg80211_connect,
1609 .disconnect = mwifiex_cfg80211_disconnect,
1610 .get_station = mwifiex_cfg80211_get_station,
1611 .dump_station = mwifiex_cfg80211_dump_station,
1612 .set_wiphy_params = mwifiex_cfg80211_set_wiphy_params,
1613 .set_channel = mwifiex_cfg80211_set_channel,
1614 .join_ibss = mwifiex_cfg80211_join_ibss,
1615 .leave_ibss = mwifiex_cfg80211_leave_ibss,
1616 .add_key = mwifiex_cfg80211_add_key,
1617 .del_key = mwifiex_cfg80211_del_key,
1618 .mgmt_tx = mwifiex_cfg80211_mgmt_tx,
1619 .mgmt_frame_register = mwifiex_cfg80211_mgmt_frame_register,
1620 .set_default_key = mwifiex_cfg80211_set_default_key,
1621 .set_power_mgmt = mwifiex_cfg80211_set_power_mgmt,
1622 .set_tx_power = mwifiex_cfg80211_set_tx_power,
1623 .set_bitrate_mask = mwifiex_cfg80211_set_bitrate_mask,
1624 .set_cqm_rssi_config = mwifiex_cfg80211_set_cqm_rssi_config,
1628 * This function registers the device with CFG802.11 subsystem.
1630 * The function creates the wireless device/wiphy, populates it with
1631 * default parameters and handler function pointers, and finally
1632 * registers the device.
1634 int mwifiex_register_cfg80211(struct mwifiex_private *priv)
1638 struct wireless_dev *wdev;
1639 struct ieee80211_sta_ht_cap *ht_info;
1642 wdev = kzalloc(sizeof(struct wireless_dev), GFP_KERNEL);
1644 dev_err(priv->adapter->dev, "%s: allocating wireless device\n",
1649 wiphy_new(&mwifiex_cfg80211_ops,
1650 sizeof(struct mwifiex_private *));
1655 wdev->iftype = NL80211_IFTYPE_STATION;
1656 wdev->wiphy->max_scan_ssids = 10;
1657 wdev->wiphy->max_scan_ie_len = MWIFIEX_MAX_VSIE_LEN;
1658 wdev->wiphy->mgmt_stypes = mwifiex_mgmt_stypes;
1659 wdev->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
1660 BIT(NL80211_IFTYPE_ADHOC);
1662 wdev->wiphy->bands[IEEE80211_BAND_2GHZ] = &mwifiex_band_2ghz;
1663 ht_info = &wdev->wiphy->bands[IEEE80211_BAND_2GHZ]->ht_cap;
1664 mwifiex_setup_ht_caps(ht_info, priv);
1666 if (priv->adapter->config_bands & BAND_A) {
1667 wdev->wiphy->bands[IEEE80211_BAND_5GHZ] = &mwifiex_band_5ghz;
1668 ht_info = &wdev->wiphy->bands[IEEE80211_BAND_5GHZ]->ht_cap;
1669 mwifiex_setup_ht_caps(ht_info, priv);
1671 wdev->wiphy->bands[IEEE80211_BAND_5GHZ] = NULL;
1674 /* Initialize cipher suits */
1675 wdev->wiphy->cipher_suites = mwifiex_cipher_suites;
1676 wdev->wiphy->n_cipher_suites = ARRAY_SIZE(mwifiex_cipher_suites);
1678 memcpy(wdev->wiphy->perm_addr, priv->curr_addr, ETH_ALEN);
1679 wdev->wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
1681 wdev->wiphy->flags |= WIPHY_FLAG_CUSTOM_REGULATORY;
1683 wdev->wiphy->probe_resp_offload =
1684 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS |
1685 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2 |
1686 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P;
1688 wiphy_apply_custom_regulatory(wdev->wiphy,
1689 &mwifiex_world_regdom_custom);
1691 /* Reserve space for mwifiex specific private data for BSS */
1692 wdev->wiphy->bss_priv_size = sizeof(struct mwifiex_bss_priv);
1694 wdev->wiphy->reg_notifier = mwifiex_reg_notifier;
1696 /* Set struct mwifiex_private pointer in wiphy_priv */
1697 wdev_priv = wiphy_priv(wdev->wiphy);
1699 *(unsigned long *) wdev_priv = (unsigned long) priv;
1701 set_wiphy_dev(wdev->wiphy, (struct device *) priv->adapter->dev);
1703 ret = wiphy_register(wdev->wiphy);
1705 dev_err(priv->adapter->dev, "%s: registering cfg80211 device\n",
1707 wiphy_free(wdev->wiphy);
1711 dev_dbg(priv->adapter->dev,
1712 "info: successfully registered wiphy device\n");
1715 country_code = mwifiex_11d_code_2_region(priv->adapter->region_code);
1717 dev_info(priv->adapter->dev,
1718 "ignoring F/W country code %2.2s\n", country_code);