UPSTREAM mwifiex: fix memory leak issue when driver unload
[cascardo/linux.git] / drivers / net / wireless / mwifiex / cfg80211.c
1 /*
2  * Marvell Wireless LAN device driver: CFG80211
3  *
4  * Copyright (C) 2011, Marvell International Ltd.
5  *
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.
13  *
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.
18  */
19
20 #include "cfg80211.h"
21 #include "main.h"
22
23 static const struct ieee80211_regdomain mwifiex_world_regdom_custom = {
24         .n_reg_rules = 7,
25         .alpha2 =  "99",
26         .reg_rules = {
27                 /* Channel 1 - 11 */
28                 REG_RULE(2412-10, 2462+10, 40, 3, 20, 0),
29                 /* Channel 12 - 13 */
30                 REG_RULE(2467-10, 2472+10, 20, 3, 20,
31                          NL80211_RRF_PASSIVE_SCAN | NL80211_RRF_NO_IBSS),
32                 /* Channel 14 */
33                 REG_RULE(2484-10, 2484+10, 20, 3, 20,
34                          NL80211_RRF_PASSIVE_SCAN | NL80211_RRF_NO_IBSS |
35                          NL80211_RRF_NO_OFDM),
36                 /* Channel 36 - 48 */
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),
42                 /* Channel 52 - 64 */
43                 REG_RULE(5260-10, 5320+10, 40, 3, 30,
44                          NL80211_RRF_PASSIVE_SCAN | NL80211_RRF_NO_IBSS |
45                          NL80211_RRF_DFS),
46                 /* Channel 100 - 140 */
47                 REG_RULE(5500-10, 5700+10, 40, 3, 30,
48                          NL80211_RRF_PASSIVE_SCAN | NL80211_RRF_NO_IBSS |
49                          NL80211_RRF_DFS),
50         }
51 };
52
53 /*
54  * This function maps the nl802.11 channel type into driver channel type.
55  *
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
62  */
63 static u8
64 mwifiex_cfg80211_channel_type_to_sec_chan_offset(enum nl80211_channel_type
65                                                  channel_type)
66 {
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;
75         default:
76                 return IEEE80211_HT_PARAM_CHA_SEC_NONE;
77         }
78 }
79
80 /*
81  * This function checks whether WEP is set.
82  */
83 static int
84 mwifiex_is_alg_wep(u32 cipher)
85 {
86         switch (cipher) {
87         case WLAN_CIPHER_SUITE_WEP40:
88         case WLAN_CIPHER_SUITE_WEP104:
89                 return 1;
90         default:
91                 break;
92         }
93
94         return 0;
95 }
96
97 /*
98  * This function retrieves the private structure from kernel wiphy structure.
99  */
100 static void *mwifiex_cfg80211_get_priv(struct wiphy *wiphy)
101 {
102         return (void *) (*(unsigned long *) wiphy_priv(wiphy));
103 }
104
105 /*
106  * CFG802.11 operation handler to delete a network key.
107  */
108 static int
109 mwifiex_cfg80211_del_key(struct wiphy *wiphy, struct net_device *netdev,
110                          u8 key_index, bool pairwise, const u8 *mac_addr)
111 {
112         struct mwifiex_private *priv = mwifiex_netdev_get_priv(netdev);
113
114         if (mwifiex_set_encode(priv, NULL, 0, key_index, 1)) {
115                 wiphy_err(wiphy, "deleting the crypto keys\n");
116                 return -EFAULT;
117         }
118
119         wiphy_dbg(wiphy, "info: crypto keys deleted\n");
120         return 0;
121 }
122
123 /*
124  * This function forms an skb for management frame.
125  */
126 static int
127 mwifiex_form_mgmt_frame(struct sk_buff *skb, const u8 *buf, size_t len)
128 {
129         u8 addr[ETH_ALEN] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
130         u16 pkt_len;
131         u32 tx_control = 0, pkt_type = PKT_TYPE_MGMT;
132         struct timeval tv;
133
134         pkt_len = len + ETH_ALEN;
135
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));
139
140         memcpy(skb_push(skb, sizeof(tx_control)),
141                &tx_control, sizeof(tx_control));
142
143         memcpy(skb_push(skb, sizeof(pkt_type)), &pkt_type, sizeof(pkt_type));
144
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));
152
153         skb->priority = LOW_PRIO_TID;
154         do_gettimeofday(&tv);
155         skb->tstamp = timeval_to_ktime(tv);
156
157         return 0;
158 }
159
160 /*
161  * CFG802.11 operation handler to transmit a management frame.
162  */
163 static int
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)
170 {
171         struct sk_buff *skb;
172         u16 pkt_len;
173         const struct ieee80211_mgmt *mgmt;
174         struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
175
176         if (!buf || !len) {
177                 wiphy_err(wiphy, "invalid buffer and length\n");
178                 return -EFAULT;
179         }
180
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 */
186                 wiphy_dbg(wiphy,
187                           "info: skip to send probe resp in AP or GO mode\n");
188                 return 0;
189         }
190
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));
195
196         if (!skb) {
197                 wiphy_err(wiphy, "allocate skb failed for management frame\n");
198                 return -ENOMEM;
199         }
200
201         mwifiex_form_mgmt_frame(skb, buf, len);
202         mwifiex_queue_tx_pkt(priv, skb);
203
204         *cookie = random32() | 1;
205         cfg80211_mgmt_tx_status(dev, *cookie, buf, len, true, GFP_ATOMIC);
206
207         wiphy_dbg(wiphy, "info: management frame transmitted\n");
208         return 0;
209 }
210
211 /*
212  * CFG802.11 operation handler to register a mgmt frame.
213  */
214 static void
215 mwifiex_cfg80211_mgmt_frame_register(struct wiphy *wiphy,
216                                      struct net_device *dev,
217                                      u16 frame_type, bool reg)
218 {
219         struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
220
221         if (reg)
222                 priv->mgmt_frame_mask |= BIT(frame_type >> 4);
223         else
224                 priv->mgmt_frame_mask &= ~BIT(frame_type >> 4);
225
226         mwifiex_send_cmd_async(priv, HostCmd_CMD_MGMT_FRAME_REG,
227                                HostCmd_ACT_GEN_SET, 0, &priv->mgmt_frame_mask);
228
229         wiphy_dbg(wiphy, "info: mgmt frame registered\n");
230 }
231
232 /*
233  * CFG802.11 operation handler to set Tx power.
234  */
235 static int
236 mwifiex_cfg80211_set_tx_power(struct wiphy *wiphy,
237                               enum nl80211_tx_power_setting type,
238                               int mbm)
239 {
240         struct mwifiex_private *priv = mwifiex_cfg80211_get_priv(wiphy);
241         struct mwifiex_power_cfg power_cfg;
242         int dbm = MBM_TO_DBM(mbm);
243
244         if (type == NL80211_TX_POWER_FIXED) {
245                 power_cfg.is_power_auto = 0;
246                 power_cfg.power_level = dbm;
247         } else {
248                 power_cfg.is_power_auto = 1;
249         }
250
251         return mwifiex_set_tx_power(priv, &power_cfg);
252 }
253
254 /*
255  * CFG802.11 operation handler to set Power Save option.
256  *
257  * The timeout value, if provided, is currently ignored.
258  */
259 static int
260 mwifiex_cfg80211_set_power_mgmt(struct wiphy *wiphy,
261                                 struct net_device *dev,
262                                 bool enabled, int timeout)
263 {
264         struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
265         u32 ps_mode;
266
267         if (timeout)
268                 wiphy_dbg(wiphy,
269                           "info: ignore timeout value for IEEE Power Save\n");
270
271         ps_mode = enabled;
272
273         return mwifiex_drv_set_power(priv, &ps_mode);
274 }
275
276 /*
277  * CFG802.11 operation handler to set the default network key.
278  */
279 static int
280 mwifiex_cfg80211_set_default_key(struct wiphy *wiphy, struct net_device *netdev,
281                                  u8 key_index, bool unicast,
282                                  bool multicast)
283 {
284         struct mwifiex_private *priv = mwifiex_netdev_get_priv(netdev);
285
286         /* Return if WEP key not configured */
287         if (!priv->sec_info.wep_enabled)
288                 return 0;
289
290         if (mwifiex_set_encode(priv, NULL, 0, key_index, 0)) {
291                 wiphy_err(wiphy, "set default Tx key index\n");
292                 return -EFAULT;
293         }
294
295         return 0;
296 }
297
298 /*
299  * CFG802.11 operation handler to add a network key.
300  */
301 static int
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)
305 {
306         struct mwifiex_private *priv = mwifiex_netdev_get_priv(netdev);
307
308         if (mwifiex_set_encode(priv, params->key, params->key_len,
309                                key_index, 0)) {
310                 wiphy_err(wiphy, "crypto keys added\n");
311                 return -EFAULT;
312         }
313
314         return 0;
315 }
316
317 /*
318  * This function sends domain information to the firmware.
319  *
320  * The following information are passed to the firmware -
321  *      - Country codes
322  *      - Sub bands (first channel, number of channels, maximum Tx power)
323  */
324 static int mwifiex_send_domain_info_cmd_fw(struct wiphy *wiphy)
325 {
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;
330         u8 i, flag = 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;
337
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] = ' ';
342
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");
346                 return -1;
347         }
348
349         sband = wiphy->bands[band];
350
351         for (i = 0; i < sband->n_channels ; i++) {
352                 ch = &sband->channels[i];
353                 if (ch->flags & IEEE80211_CHAN_DISABLED)
354                         continue;
355
356                 if (!flag) {
357                         flag = 1;
358                         first_chan = (u32) ch->hw_value;
359                         next_chan = first_chan;
360                         max_pwr = ch->max_power;
361                         no_of_parsed_chan = 1;
362                         continue;
363                 }
364
365                 if (ch->hw_value == next_chan + 1 &&
366                     ch->max_power == max_pwr) {
367                         next_chan++;
368                         no_of_parsed_chan++;
369                 } else {
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;
374                         no_of_triplet++;
375                         first_chan = (u32) ch->hw_value;
376                         next_chan = first_chan;
377                         max_pwr = ch->max_power;
378                         no_of_parsed_chan = 1;
379                 }
380         }
381
382         if (flag) {
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;
387                 no_of_triplet++;
388         }
389
390         domain_info->no_of_triplet = no_of_triplet;
391
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");
395                 return -1;
396         }
397
398         return 0;
399 }
400
401 /*
402  * CFG802.11 regulatory domain callback function.
403  *
404  * This function is called when the regulatory domain is changed due to the
405  * following reasons -
406  *      - Set by driver
407  *      - Set by system core
408  *      - Set by user
409  *      - Set bt Country IE
410  */
411 static int mwifiex_reg_notifier(struct wiphy *wiphy,
412                                 struct regulatory_request *request)
413 {
414         struct mwifiex_private *priv = mwifiex_cfg80211_get_priv(wiphy);
415
416         wiphy_dbg(wiphy, "info: cfg80211 regulatory domain callback for domain"
417                         " %c%c\n", request->alpha2[0], request->alpha2[1]);
418
419         memcpy(priv->country_code, request->alpha2, sizeof(request->alpha2));
420
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:
425                 break;
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:
429                 break;
430         }
431         mwifiex_send_domain_info_cmd_fw(wiphy);
432
433         return 0;
434 }
435
436 /*
437  * This function sets the RF channel.
438  *
439  * This function creates multiple IOCTL requests, populates them accordingly
440  * and issues them to set the band/channel and frequency.
441  */
442 static int
443 mwifiex_set_rf_channel(struct mwifiex_private *priv,
444                        struct ieee80211_channel *chan,
445                        enum nl80211_channel_type channel_type)
446 {
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;
451
452         if (chan) {
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)
458                                         config_bands =
459                                                 priv->adapter->config_bands;
460                                 else
461                                         config_bands = BAND_B | BAND_G;
462                         else
463                                 config_bands = BAND_B | BAND_G | BAND_GN;
464                 } else {
465                         if (channel_type == NL80211_CHAN_NO_HT)
466                                 config_bands = BAND_A;
467                         else
468                                 config_bands = BAND_AN | BAND_A;
469                 }
470
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;
479                                 else
480                                         adapter->adhoc_11n_enabled = false;
481                         }
482                 }
483                 adapter->sec_chan_offset =
484                         mwifiex_cfg80211_channel_type_to_sec_chan_offset
485                         (channel_type);
486                 adapter->channel_type = channel_type;
487         }
488
489         wiphy_dbg(wiphy, "info: setting band %d, chan offset %d, mode %d\n",
490                   config_bands, adapter->sec_chan_offset, priv->bss_mode);
491         if (!chan)
492                 return 0;
493
494         memset(&cfp, 0, sizeof(cfp));
495         cfp.freq = chan->center_freq;
496         cfp.channel = ieee80211_frequency_to_channel(chan->center_freq);
497
498         if (mwifiex_bss_set_channel(priv, &cfp))
499                 return -EFAULT;
500
501         return mwifiex_drv_change_adhoc_chan(priv, cfp.channel);
502 }
503
504 /*
505  * CFG802.11 operation handler to set channel.
506  *
507  * This function can only be used when station is not connected.
508  */
509 static int
510 mwifiex_cfg80211_set_channel(struct wiphy *wiphy, struct net_device *dev,
511                              struct ieee80211_channel *chan,
512                              enum nl80211_channel_type channel_type)
513 {
514         struct mwifiex_private *priv;
515
516         if (dev)
517                 priv = mwifiex_netdev_get_priv(dev);
518         else
519                 priv = mwifiex_cfg80211_get_priv(wiphy);
520
521         if (priv->media_connected) {
522                 wiphy_err(wiphy, "This setting is valid only when station "
523                                 "is not connected\n");
524                 return -EINVAL;
525         }
526
527         return mwifiex_set_rf_channel(priv, chan, channel_type);
528 }
529
530 static int
531 mwifiex_cfg80211_set_antenna(struct wiphy *wiphy, u32 tx_ant, u32 rx_ant)
532 {
533         struct mwifiex_private *priv = mwifiex_cfg80211_get_priv(wiphy);
534         struct mwifiex_adapter *adapter = priv->adapter;
535         struct mwifiex_ds_ant_cfg ant_cfg;
536
537         if (!tx_ant || !rx_ant)
538                 return -EOPNOTSUPP;
539
540         if (adapter->hw_dev_mcs_support != HT_STREAM_2X2) {
541                 /* Not a MIMO chip. User should provide specific antenna number
542                  * for Tx/Rx path or enable all antennas for diversity
543                  */
544                 if (tx_ant != rx_ant)
545                         return -EOPNOTSUPP;
546
547                 if ((tx_ant & (tx_ant - 1)) &&
548                     (tx_ant != BIT(adapter->number_of_antenna) - 1))
549                         return -EOPNOTSUPP;
550
551                 if ((tx_ant == BIT(adapter->number_of_antenna) - 1) &&
552                     (priv->adapter->number_of_antenna > 1)) {
553                         tx_ant = RF_ANTENNA_AUTO;
554                         rx_ant = RF_ANTENNA_AUTO;
555                 }
556         }
557
558         ant_cfg.tx_ant = tx_ant;
559         ant_cfg.rx_ant = rx_ant;
560
561         return mwifiex_send_cmd_sync(priv, HostCmd_CMD_RF_ANTENNA,
562                                      HostCmd_ACT_GEN_SET, 0, &ant_cfg);
563 }
564
565 /*
566  * This function sets the fragmentation threshold.
567  *
568  * The fragmentation threshold value must lie between MWIFIEX_FRAG_MIN_VALUE
569  * and MWIFIEX_FRAG_MAX_VALUE.
570  */
571 static int
572 mwifiex_set_frag(struct mwifiex_private *priv, u32 frag_thr)
573 {
574         int ret;
575
576         if (frag_thr < MWIFIEX_FRAG_MIN_VALUE ||
577             frag_thr > MWIFIEX_FRAG_MAX_VALUE)
578                 return -EINVAL;
579
580         /* Send request to firmware */
581         ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_SNMP_MIB,
582                                     HostCmd_ACT_GEN_SET, FRAG_THRESH_I,
583                                     &frag_thr);
584
585         return ret;
586 }
587
588 /*
589  * This function sets the RTS threshold.
590
591  * The rts value must lie between MWIFIEX_RTS_MIN_VALUE
592  * and MWIFIEX_RTS_MAX_VALUE.
593  */
594 static int
595 mwifiex_set_rts(struct mwifiex_private *priv, u32 rts_thr)
596 {
597         if (rts_thr < MWIFIEX_RTS_MIN_VALUE || rts_thr > MWIFIEX_RTS_MAX_VALUE)
598                 rts_thr = MWIFIEX_RTS_MAX_VALUE;
599
600         return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_SNMP_MIB,
601                                     HostCmd_ACT_GEN_SET, RTS_THRESH_I,
602                                     &rts_thr);
603 }
604
605 /*
606  * CFG802.11 operation handler to set wiphy parameters.
607  *
608  * This function can be used to set the RTS threshold and the
609  * Fragmentation threshold of the driver.
610  */
611 static int
612 mwifiex_cfg80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
613 {
614         struct mwifiex_private *priv = mwifiex_cfg80211_get_priv(wiphy);
615         int ret = 0;
616
617         if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
618                 ret = mwifiex_set_rts(priv, wiphy->rts_threshold);
619                 if (ret)
620                         return ret;
621         }
622
623         if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
624                 ret = mwifiex_set_frag(priv, wiphy->frag_threshold);
625
626         return ret;
627 }
628
629 /*
630  * CFG802.11 operation handler to change interface type.
631  */
632 static int
633 mwifiex_cfg80211_change_virtual_intf(struct wiphy *wiphy,
634                                      struct net_device *dev,
635                                      enum nl80211_iftype type, u32 *flags,
636                                      struct vif_params *params)
637 {
638         int ret;
639         struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
640
641         if (priv->bss_mode == type) {
642                 wiphy_warn(wiphy, "already set to required type\n");
643                 return 0;
644         }
645
646         priv->bss_mode = type;
647
648         switch (type) {
649         case NL80211_IFTYPE_ADHOC:
650                 dev->ieee80211_ptr->iftype = NL80211_IFTYPE_ADHOC;
651                 wiphy_dbg(wiphy, "info: setting interface type to adhoc\n");
652                 break;
653         case NL80211_IFTYPE_STATION:
654                 dev->ieee80211_ptr->iftype = NL80211_IFTYPE_STATION;
655                 wiphy_dbg(wiphy, "info: setting interface type to managed\n");
656                 break;
657         case NL80211_IFTYPE_UNSPECIFIED:
658                 dev->ieee80211_ptr->iftype = NL80211_IFTYPE_STATION;
659                 wiphy_dbg(wiphy, "info: setting interface type to auto\n");
660                 return 0;
661         default:
662                 wiphy_err(wiphy, "unknown interface type: %d\n", type);
663                 return -EINVAL;
664         }
665
666         mwifiex_deauthenticate(priv, NULL);
667
668         priv->sec_info.authentication_mode = NL80211_AUTHTYPE_OPEN_SYSTEM;
669
670         ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_SET_BSS_MODE,
671                                     HostCmd_ACT_GEN_SET, 0, NULL);
672
673         return ret;
674 }
675
676 /*
677  * This function dumps the station information on a buffer.
678  *
679  * The following information are shown -
680  *      - Total bytes transmitted
681  *      - Total bytes received
682  *      - Total packets transmitted
683  *      - Total packets received
684  *      - Signal quality level
685  *      - Transmission rate
686  */
687 static int
688 mwifiex_dump_station_info(struct mwifiex_private *priv,
689                           struct station_info *sinfo)
690 {
691         struct mwifiex_rate_cfg rate;
692
693         sinfo->filled = STATION_INFO_RX_BYTES | STATION_INFO_TX_BYTES |
694                         STATION_INFO_RX_PACKETS | STATION_INFO_TX_PACKETS |
695                         STATION_INFO_TX_BITRATE |
696                         STATION_INFO_SIGNAL | STATION_INFO_SIGNAL_AVG;
697
698         /* Get signal information from the firmware */
699         if (mwifiex_send_cmd_sync(priv, HostCmd_CMD_RSSI_INFO,
700                                   HostCmd_ACT_GEN_GET, 0, NULL)) {
701                 dev_err(priv->adapter->dev, "failed to get signal information\n");
702                 return -EFAULT;
703         }
704
705         if (mwifiex_drv_get_data_rate(priv, &rate)) {
706                 dev_err(priv->adapter->dev, "getting data rate\n");
707                 return -EFAULT;
708         }
709
710         /* Get DTIM period information from firmware */
711         mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_SNMP_MIB,
712                               HostCmd_ACT_GEN_GET, DTIM_PERIOD_I,
713                               &priv->dtim_period);
714
715         /*
716          * Bit 0 in tx_htinfo indicates that current Tx rate is 11n rate. Valid
717          * MCS index values for us are 0 to 15.
718          */
719         if ((priv->tx_htinfo & BIT(0)) && (priv->tx_rate < 16)) {
720                 sinfo->txrate.mcs = priv->tx_rate;
721                 sinfo->txrate.flags |= RATE_INFO_FLAGS_MCS;
722                 /* 40MHz rate */
723                 if (priv->tx_htinfo & BIT(1))
724                         sinfo->txrate.flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
725                 /* SGI enabled */
726                 if (priv->tx_htinfo & BIT(2))
727                         sinfo->txrate.flags |= RATE_INFO_FLAGS_SHORT_GI;
728         }
729
730         sinfo->signal_avg = priv->bcn_rssi_avg;
731         sinfo->rx_bytes = priv->stats.rx_bytes;
732         sinfo->tx_bytes = priv->stats.tx_bytes;
733         sinfo->rx_packets = priv->stats.rx_packets;
734         sinfo->tx_packets = priv->stats.tx_packets;
735         sinfo->signal = priv->bcn_rssi_avg;
736         /* bit rate is in 500 kb/s units. Convert it to 100kb/s units */
737         sinfo->txrate.legacy = rate.rate * 5;
738
739         if (priv->bss_mode == NL80211_IFTYPE_STATION) {
740                 sinfo->filled |= STATION_INFO_BSS_PARAM;
741                 sinfo->bss_param.flags = 0;
742                 if (priv->curr_bss_params.bss_descriptor.cap_info_bitmap &
743                                                 WLAN_CAPABILITY_SHORT_PREAMBLE)
744                         sinfo->bss_param.flags |=
745                                         BSS_PARAM_FLAGS_SHORT_PREAMBLE;
746                 if (priv->curr_bss_params.bss_descriptor.cap_info_bitmap &
747                                                 WLAN_CAPABILITY_SHORT_SLOT_TIME)
748                         sinfo->bss_param.flags |=
749                                         BSS_PARAM_FLAGS_SHORT_SLOT_TIME;
750                 sinfo->bss_param.dtim_period = priv->dtim_period;
751                 sinfo->bss_param.beacon_interval =
752                         priv->curr_bss_params.bss_descriptor.beacon_period;
753         }
754
755         return 0;
756 }
757
758 /*
759  * CFG802.11 operation handler to get station information.
760  *
761  * This function only works in connected mode, and dumps the
762  * requested station information, if available.
763  */
764 static int
765 mwifiex_cfg80211_get_station(struct wiphy *wiphy, struct net_device *dev,
766                              u8 *mac, struct station_info *sinfo)
767 {
768         struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
769
770         if (!priv->media_connected)
771                 return -ENOENT;
772         if (memcmp(mac, priv->cfg_bssid, ETH_ALEN))
773                 return -ENOENT;
774
775         return mwifiex_dump_station_info(priv, sinfo);
776 }
777
778 /*
779  * CFG802.11 operation handler to dump station information.
780  */
781 static int
782 mwifiex_cfg80211_dump_station(struct wiphy *wiphy, struct net_device *dev,
783                               int idx, u8 *mac, struct station_info *sinfo)
784 {
785         struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
786
787         if (!priv->media_connected || idx)
788                 return -ENOENT;
789
790         memcpy(mac, priv->cfg_bssid, ETH_ALEN);
791
792         return mwifiex_dump_station_info(priv, sinfo);
793 }
794
795 /* Supported rates to be advertised to the cfg80211 */
796
797 static struct ieee80211_rate mwifiex_rates[] = {
798         {.bitrate = 10, .hw_value = 2, },
799         {.bitrate = 20, .hw_value = 4, },
800         {.bitrate = 55, .hw_value = 11, },
801         {.bitrate = 110, .hw_value = 22, },
802         {.bitrate = 60, .hw_value = 12, },
803         {.bitrate = 90, .hw_value = 18, },
804         {.bitrate = 120, .hw_value = 24, },
805         {.bitrate = 180, .hw_value = 36, },
806         {.bitrate = 240, .hw_value = 48, },
807         {.bitrate = 360, .hw_value = 72, },
808         {.bitrate = 480, .hw_value = 96, },
809         {.bitrate = 540, .hw_value = 108, },
810 };
811
812 /* Channel definitions to be advertised to cfg80211 */
813
814 static struct ieee80211_channel mwifiex_channels_2ghz[] = {
815         {.center_freq = 2412, .hw_value = 1, },
816         {.center_freq = 2417, .hw_value = 2, },
817         {.center_freq = 2422, .hw_value = 3, },
818         {.center_freq = 2427, .hw_value = 4, },
819         {.center_freq = 2432, .hw_value = 5, },
820         {.center_freq = 2437, .hw_value = 6, },
821         {.center_freq = 2442, .hw_value = 7, },
822         {.center_freq = 2447, .hw_value = 8, },
823         {.center_freq = 2452, .hw_value = 9, },
824         {.center_freq = 2457, .hw_value = 10, },
825         {.center_freq = 2462, .hw_value = 11, },
826         {.center_freq = 2467, .hw_value = 12, },
827         {.center_freq = 2472, .hw_value = 13, },
828         {.center_freq = 2484, .hw_value = 14, },
829 };
830
831 static struct ieee80211_supported_band mwifiex_band_2ghz = {
832         .channels = mwifiex_channels_2ghz,
833         .n_channels = ARRAY_SIZE(mwifiex_channels_2ghz),
834         .bitrates = mwifiex_rates,
835         .n_bitrates = ARRAY_SIZE(mwifiex_rates),
836 };
837
838 static struct ieee80211_channel mwifiex_channels_5ghz[] = {
839         {.center_freq = 5040, .hw_value = 8, },
840         {.center_freq = 5060, .hw_value = 12, },
841         {.center_freq = 5080, .hw_value = 16, },
842         {.center_freq = 5170, .hw_value = 34, },
843         {.center_freq = 5190, .hw_value = 38, },
844         {.center_freq = 5210, .hw_value = 42, },
845         {.center_freq = 5230, .hw_value = 46, },
846         {.center_freq = 5180, .hw_value = 36, },
847         {.center_freq = 5200, .hw_value = 40, },
848         {.center_freq = 5220, .hw_value = 44, },
849         {.center_freq = 5240, .hw_value = 48, },
850         {.center_freq = 5260, .hw_value = 52, },
851         {.center_freq = 5280, .hw_value = 56, },
852         {.center_freq = 5300, .hw_value = 60, },
853         {.center_freq = 5320, .hw_value = 64, },
854         {.center_freq = 5500, .hw_value = 100, },
855         {.center_freq = 5520, .hw_value = 104, },
856         {.center_freq = 5540, .hw_value = 108, },
857         {.center_freq = 5560, .hw_value = 112, },
858         {.center_freq = 5580, .hw_value = 116, },
859         {.center_freq = 5600, .hw_value = 120, },
860         {.center_freq = 5620, .hw_value = 124, },
861         {.center_freq = 5640, .hw_value = 128, },
862         {.center_freq = 5660, .hw_value = 132, },
863         {.center_freq = 5680, .hw_value = 136, },
864         {.center_freq = 5700, .hw_value = 140, },
865         {.center_freq = 5745, .hw_value = 149, },
866         {.center_freq = 5765, .hw_value = 153, },
867         {.center_freq = 5785, .hw_value = 157, },
868         {.center_freq = 5805, .hw_value = 161, },
869         {.center_freq = 5825, .hw_value = 165, },
870 };
871
872 static struct ieee80211_supported_band mwifiex_band_5ghz = {
873         .channels = mwifiex_channels_5ghz,
874         .n_channels = ARRAY_SIZE(mwifiex_channels_5ghz),
875         .bitrates = mwifiex_rates + 4,
876         .n_bitrates = ARRAY_SIZE(mwifiex_rates) - 4,
877 };
878
879
880 /* Supported crypto cipher suits to be advertised to cfg80211 */
881
882 static const u32 mwifiex_cipher_suites[] = {
883         WLAN_CIPHER_SUITE_WEP40,
884         WLAN_CIPHER_SUITE_WEP104,
885         WLAN_CIPHER_SUITE_TKIP,
886         WLAN_CIPHER_SUITE_CCMP,
887 };
888
889 /* Supported mgmt frame types to be advertised to cfg80211 */
890 static const struct ieee80211_txrx_stypes
891 mwifiex_mgmt_stypes[NUM_NL80211_IFTYPES] = {
892         [NL80211_IFTYPE_STATION] = {
893                 .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
894                       BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
895                 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
896                       BIT(IEEE80211_STYPE_PROBE_REQ >> 4),
897         },
898         [NL80211_IFTYPE_AP] = {
899                 .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
900                       BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
901                 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
902                       BIT(IEEE80211_STYPE_PROBE_REQ >> 4),
903         },
904         [NL80211_IFTYPE_P2P_CLIENT] = {
905                 .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
906                       BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
907                 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
908                       BIT(IEEE80211_STYPE_PROBE_REQ >> 4),
909         },
910         [NL80211_IFTYPE_P2P_GO] = {
911                 .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
912                       BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
913                 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
914                       BIT(IEEE80211_STYPE_PROBE_REQ >> 4),
915         },
916 };
917
918 /*
919  * CFG802.11 operation handler for setting bit rates.
920  *
921  * Function configures data rates to firmware using bitrate mask
922  * provided by cfg80211.
923  */
924 static int mwifiex_cfg80211_set_bitrate_mask(struct wiphy *wiphy,
925                                 struct net_device *dev,
926                                 const u8 *peer,
927                                 const struct cfg80211_bitrate_mask *mask)
928 {
929         struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
930         u16 bitmap_rates[MAX_BITMAP_RATES_SIZE];
931         enum ieee80211_band band;
932
933         if (!priv->media_connected) {
934                 dev_err(priv->adapter->dev,
935                         "Can not set Tx data rate in disconnected state\n");
936                 return -EINVAL;
937         }
938
939         band = mwifiex_band_to_radio_type(priv->curr_bss_params.band);
940
941         memset(bitmap_rates, 0, sizeof(bitmap_rates));
942
943         /* Fill HR/DSSS rates. */
944         if (band == IEEE80211_BAND_2GHZ)
945                 bitmap_rates[0] = mask->control[band].legacy & 0x000f;
946
947         /* Fill OFDM rates */
948         if (band == IEEE80211_BAND_2GHZ)
949                 bitmap_rates[1] = (mask->control[band].legacy & 0x0ff0) >> 4;
950         else
951                 bitmap_rates[1] = mask->control[band].legacy;
952
953         /* Fill MCS rates */
954         bitmap_rates[2] = mask->control[band].mcs[0];
955         if (priv->adapter->hw_dev_mcs_support == HT_STREAM_2X2)
956                 bitmap_rates[2] |= mask->control[band].mcs[1] << 8;
957
958         return mwifiex_send_cmd_sync(priv, HostCmd_CMD_TX_RATE_CFG,
959                                      HostCmd_ACT_GEN_SET, 0, bitmap_rates);
960 }
961
962 /*
963  * CFG802.11 operation handler for connection quality monitoring.
964  *
965  * This function subscribes/unsubscribes HIGH_RSSI and LOW_RSSI
966  * events to FW.
967  */
968 static int mwifiex_cfg80211_set_cqm_rssi_config(struct wiphy *wiphy,
969                                                 struct net_device *dev,
970                                                 s32 rssi_thold, u32 rssi_hyst)
971 {
972         struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
973         struct mwifiex_ds_misc_subsc_evt subsc_evt;
974
975         priv->cqm_rssi_thold = rssi_thold;
976         priv->cqm_rssi_hyst = rssi_hyst;
977
978         memset(&subsc_evt, 0x00, sizeof(struct mwifiex_ds_misc_subsc_evt));
979         subsc_evt.events = BITMASK_BCN_RSSI_LOW | BITMASK_BCN_RSSI_HIGH;
980
981         /* Subscribe/unsubscribe low and high rssi events */
982         if (rssi_thold && rssi_hyst) {
983                 subsc_evt.action = HostCmd_ACT_BITWISE_SET;
984                 subsc_evt.bcn_l_rssi_cfg.abs_value = abs(rssi_thold);
985                 subsc_evt.bcn_h_rssi_cfg.abs_value = abs(rssi_thold);
986                 subsc_evt.bcn_l_rssi_cfg.evt_freq = 1;
987                 subsc_evt.bcn_h_rssi_cfg.evt_freq = 1;
988                 return mwifiex_send_cmd_sync(priv,
989                                              HostCmd_CMD_802_11_SUBSCRIBE_EVENT,
990                                              0, 0, &subsc_evt);
991         } else {
992                 subsc_evt.action = HostCmd_ACT_BITWISE_CLR;
993                 return mwifiex_send_cmd_sync(priv,
994                                              HostCmd_CMD_802_11_SUBSCRIBE_EVENT,
995                                              0, 0, &subsc_evt);
996         }
997
998         return 0;
999 }
1000
1001 /*
1002  * CFG802.11 operation handler for disconnection request.
1003  *
1004  * This function does not work when there is already a disconnection
1005  * procedure going on.
1006  */
1007 static int
1008 mwifiex_cfg80211_disconnect(struct wiphy *wiphy, struct net_device *dev,
1009                             u16 reason_code)
1010 {
1011         struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
1012
1013         if (mwifiex_deauthenticate(priv, NULL))
1014                 return -EFAULT;
1015
1016         wiphy_dbg(wiphy, "info: successfully disconnected from %pM:"
1017                 " reason code %d\n", priv->cfg_bssid, reason_code);
1018
1019         memset(priv->cfg_bssid, 0, ETH_ALEN);
1020
1021         return 0;
1022 }
1023
1024 /*
1025  * This function informs the CFG802.11 subsystem of a new IBSS.
1026  *
1027  * The following information are sent to the CFG802.11 subsystem
1028  * to register the new IBSS. If we do not register the new IBSS,
1029  * a kernel panic will result.
1030  *      - SSID
1031  *      - SSID length
1032  *      - BSSID
1033  *      - Channel
1034  */
1035 static int mwifiex_cfg80211_inform_ibss_bss(struct mwifiex_private *priv)
1036 {
1037         struct ieee80211_channel *chan;
1038         struct mwifiex_bss_info bss_info;
1039         struct cfg80211_bss *bss;
1040         int ie_len;
1041         u8 ie_buf[IEEE80211_MAX_SSID_LEN + sizeof(struct ieee_types_header)];
1042         enum ieee80211_band band;
1043
1044         if (mwifiex_get_bss_info(priv, &bss_info))
1045                 return -1;
1046
1047         ie_buf[0] = WLAN_EID_SSID;
1048         ie_buf[1] = bss_info.ssid.ssid_len;
1049
1050         memcpy(&ie_buf[sizeof(struct ieee_types_header)],
1051                &bss_info.ssid.ssid, bss_info.ssid.ssid_len);
1052         ie_len = ie_buf[1] + sizeof(struct ieee_types_header);
1053
1054         band = mwifiex_band_to_radio_type(priv->curr_bss_params.band);
1055         chan = __ieee80211_get_channel(priv->wdev->wiphy,
1056                         ieee80211_channel_to_frequency(bss_info.bss_chan,
1057                                                        band));
1058
1059         bss = cfg80211_inform_bss(priv->wdev->wiphy, chan,
1060                                   bss_info.bssid, 0, WLAN_CAPABILITY_IBSS,
1061                                   0, ie_buf, ie_len, 0, GFP_KERNEL);
1062         cfg80211_put_bss(bss);
1063         memcpy(priv->cfg_bssid, bss_info.bssid, ETH_ALEN);
1064
1065         return 0;
1066 }
1067
1068 /*
1069  * This function connects with a BSS.
1070  *
1071  * This function handles both Infra and Ad-Hoc modes. It also performs
1072  * validity checking on the provided parameters, disconnects from the
1073  * current BSS (if any), sets up the association/scan parameters,
1074  * including security settings, and performs specific SSID scan before
1075  * trying to connect.
1076  *
1077  * For Infra mode, the function returns failure if the specified SSID
1078  * is not found in scan table. However, for Ad-Hoc mode, it can create
1079  * the IBSS if it does not exist. On successful completion in either case,
1080  * the function notifies the CFG802.11 subsystem of the new BSS connection.
1081  */
1082 static int
1083 mwifiex_cfg80211_assoc(struct mwifiex_private *priv, size_t ssid_len, u8 *ssid,
1084                        u8 *bssid, int mode, struct ieee80211_channel *channel,
1085                        struct cfg80211_connect_params *sme, bool privacy)
1086 {
1087         struct cfg80211_ssid req_ssid;
1088         int ret, auth_type = 0;
1089         struct cfg80211_bss *bss = NULL;
1090         u8 is_scanning_required = 0;
1091
1092         memset(&req_ssid, 0, sizeof(struct cfg80211_ssid));
1093
1094         req_ssid.ssid_len = ssid_len;
1095         if (ssid_len > IEEE80211_MAX_SSID_LEN) {
1096                 dev_err(priv->adapter->dev, "invalid SSID - aborting\n");
1097                 return -EINVAL;
1098         }
1099
1100         memcpy(req_ssid.ssid, ssid, ssid_len);
1101         if (!req_ssid.ssid_len || req_ssid.ssid[0] < 0x20) {
1102                 dev_err(priv->adapter->dev, "invalid SSID - aborting\n");
1103                 return -EINVAL;
1104         }
1105
1106         /* disconnect before try to associate */
1107         mwifiex_deauthenticate(priv, NULL);
1108
1109         if (channel)
1110                 ret = mwifiex_set_rf_channel(priv, channel,
1111                                                 priv->adapter->channel_type);
1112
1113         /* As this is new association, clear locally stored
1114          * keys and security related flags */
1115         priv->sec_info.wpa_enabled = false;
1116         priv->sec_info.wpa2_enabled = false;
1117         priv->wep_key_curr_index = 0;
1118         priv->sec_info.encryption_mode = 0;
1119         priv->sec_info.is_authtype_auto = 0;
1120         ret = mwifiex_set_encode(priv, NULL, 0, 0, 1);
1121
1122         if (mode == NL80211_IFTYPE_ADHOC) {
1123                 /* "privacy" is set only for ad-hoc mode */
1124                 if (privacy) {
1125                         /*
1126                          * Keep WLAN_CIPHER_SUITE_WEP104 for now so that
1127                          * the firmware can find a matching network from the
1128                          * scan. The cfg80211 does not give us the encryption
1129                          * mode at this stage so just setting it to WEP here.
1130                          */
1131                         priv->sec_info.encryption_mode =
1132                                         WLAN_CIPHER_SUITE_WEP104;
1133                         priv->sec_info.authentication_mode =
1134                                         NL80211_AUTHTYPE_OPEN_SYSTEM;
1135                 }
1136
1137                 goto done;
1138         }
1139
1140         /* Now handle infra mode. "sme" is valid for infra mode only */
1141         if (sme->auth_type == NL80211_AUTHTYPE_AUTOMATIC) {
1142                 auth_type = NL80211_AUTHTYPE_OPEN_SYSTEM;
1143                 priv->sec_info.is_authtype_auto = 1;
1144         } else {
1145                 auth_type = sme->auth_type;
1146         }
1147
1148         if (sme->crypto.n_ciphers_pairwise) {
1149                 priv->sec_info.encryption_mode =
1150                                                 sme->crypto.ciphers_pairwise[0];
1151                 priv->sec_info.authentication_mode = auth_type;
1152         }
1153
1154         if (sme->crypto.cipher_group) {
1155                 priv->sec_info.encryption_mode = sme->crypto.cipher_group;
1156                 priv->sec_info.authentication_mode = auth_type;
1157         }
1158         if (sme->ie)
1159                 ret = mwifiex_set_gen_ie(priv, sme->ie, sme->ie_len);
1160
1161         if (sme->key) {
1162                 if (mwifiex_is_alg_wep(priv->sec_info.encryption_mode)) {
1163                         dev_dbg(priv->adapter->dev,
1164                                 "info: setting wep encryption"
1165                                 " with key len %d\n", sme->key_len);
1166                         priv->wep_key_curr_index = sme->key_idx;
1167                         ret = mwifiex_set_encode(priv, sme->key, sme->key_len,
1168                                                         sme->key_idx, 0);
1169                 }
1170         }
1171 done:
1172         /*
1173          * Scan entries are valid for some time (15 sec). So we can save one
1174          * active scan time if we just try cfg80211_get_bss first. If it fails
1175          * then request scan and cfg80211_get_bss() again for final output.
1176          */
1177         while (1) {
1178                 if (is_scanning_required) {
1179                         /* Do specific SSID scanning */
1180                         if (mwifiex_request_scan(priv, &req_ssid)) {
1181                                 dev_err(priv->adapter->dev, "scan error\n");
1182                                 return -EFAULT;
1183                         }
1184                 }
1185
1186                 /* Find the BSS we want using available scan results */
1187                 if (mode == NL80211_IFTYPE_ADHOC)
1188                         bss = cfg80211_get_bss(priv->wdev->wiphy, channel,
1189                                                bssid, ssid, ssid_len,
1190                                                WLAN_CAPABILITY_IBSS,
1191                                                WLAN_CAPABILITY_IBSS);
1192                 else
1193                         bss = cfg80211_get_bss(priv->wdev->wiphy, channel,
1194                                                bssid, ssid, ssid_len,
1195                                                WLAN_CAPABILITY_ESS,
1196                                                WLAN_CAPABILITY_ESS);
1197
1198                 if (!bss) {
1199                         if (is_scanning_required) {
1200                                 dev_warn(priv->adapter->dev,
1201                                          "assoc: requested bss not found in scan results\n");
1202                                 break;
1203                         }
1204                         is_scanning_required = 1;
1205                 } else {
1206                         dev_dbg(priv->adapter->dev,
1207                                 "info: trying to associate to '%s' bssid %pM\n",
1208                                 (char *) req_ssid.ssid, bss->bssid);
1209                         memcpy(&priv->cfg_bssid, bss->bssid, ETH_ALEN);
1210                         break;
1211                 }
1212         }
1213
1214         ret = mwifiex_bss_start(priv, bss, &req_ssid);
1215         if (ret)
1216                 return ret;
1217
1218         if (mode == NL80211_IFTYPE_ADHOC) {
1219                 /* Inform the BSS information to kernel, otherwise
1220                  * kernel will give a panic after successful assoc */
1221                 if (mwifiex_cfg80211_inform_ibss_bss(priv))
1222                         return -EFAULT;
1223         }
1224
1225         return ret;
1226 }
1227
1228 /*
1229  * CFG802.11 operation handler for association request.
1230  *
1231  * This function does not work when the current mode is set to Ad-Hoc, or
1232  * when there is already an association procedure going on. The given BSS
1233  * information is used to associate.
1234  */
1235 static int
1236 mwifiex_cfg80211_connect(struct wiphy *wiphy, struct net_device *dev,
1237                          struct cfg80211_connect_params *sme)
1238 {
1239         struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
1240         int ret = 0;
1241
1242         if (priv->bss_mode == NL80211_IFTYPE_ADHOC) {
1243                 wiphy_err(wiphy, "received infra assoc request "
1244                                 "when station is in ibss mode\n");
1245                 goto done;
1246         }
1247
1248         wiphy_dbg(wiphy, "info: Trying to associate to %s and bssid %pM\n",
1249                   (char *) sme->ssid, sme->bssid);
1250
1251         ret = mwifiex_cfg80211_assoc(priv, sme->ssid_len, sme->ssid, sme->bssid,
1252                                      priv->bss_mode, sme->channel, sme, 0);
1253 done:
1254         if (!ret) {
1255                 cfg80211_connect_result(priv->netdev, priv->cfg_bssid, NULL, 0,
1256                                         NULL, 0, WLAN_STATUS_SUCCESS,
1257                                         GFP_KERNEL);
1258                 dev_dbg(priv->adapter->dev,
1259                         "info: associated to bssid %pM successfully\n",
1260                         priv->cfg_bssid);
1261         } else {
1262                 dev_dbg(priv->adapter->dev,
1263                         "info: association to bssid %pM failed\n",
1264                         priv->cfg_bssid);
1265                 memset(priv->cfg_bssid, 0, ETH_ALEN);
1266
1267                 if (ret > 0)
1268                         cfg80211_connect_result(priv->netdev, priv->cfg_bssid,
1269                                                 NULL, 0, NULL, 0, ret,
1270                                                 GFP_KERNEL);
1271                 else
1272                         cfg80211_connect_result(priv->netdev, priv->cfg_bssid,
1273                                                 NULL, 0, NULL, 0,
1274                                                 WLAN_STATUS_UNSPECIFIED_FAILURE,
1275                                                 GFP_KERNEL);
1276         }
1277
1278         return 0;
1279 }
1280
1281 /*
1282  * CFG802.11 operation handler to join an IBSS.
1283  *
1284  * This function does not work in any mode other than Ad-Hoc, or if
1285  * a join operation is already in progress.
1286  */
1287 static int
1288 mwifiex_cfg80211_join_ibss(struct wiphy *wiphy, struct net_device *dev,
1289                            struct cfg80211_ibss_params *params)
1290 {
1291         struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
1292         int ret = 0;
1293
1294         if (priv->bss_mode != NL80211_IFTYPE_ADHOC) {
1295                 wiphy_err(wiphy, "request to join ibss received "
1296                                 "when station is not in ibss mode\n");
1297                 goto done;
1298         }
1299
1300         wiphy_dbg(wiphy, "info: trying to join to %s and bssid %pM\n",
1301                   (char *) params->ssid, params->bssid);
1302
1303         ret = mwifiex_cfg80211_assoc(priv, params->ssid_len, params->ssid,
1304                                      params->bssid, priv->bss_mode,
1305                                      params->channel, NULL, params->privacy);
1306 done:
1307         if (!ret) {
1308                 cfg80211_ibss_joined(priv->netdev, priv->cfg_bssid, GFP_KERNEL);
1309                 dev_dbg(priv->adapter->dev,
1310                         "info: joined/created adhoc network with bssid"
1311                         " %pM successfully\n", priv->cfg_bssid);
1312         } else {
1313                 dev_dbg(priv->adapter->dev,
1314                         "info: failed creating/joining adhoc network\n");
1315         }
1316
1317         return ret;
1318 }
1319
1320 /*
1321  * CFG802.11 operation handler to leave an IBSS.
1322  *
1323  * This function does not work if a leave operation is
1324  * already in progress.
1325  */
1326 static int
1327 mwifiex_cfg80211_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
1328 {
1329         struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
1330
1331         wiphy_dbg(wiphy, "info: disconnecting from essid %pM\n",
1332                   priv->cfg_bssid);
1333         if (mwifiex_deauthenticate(priv, NULL))
1334                 return -EFAULT;
1335
1336         memset(priv->cfg_bssid, 0, ETH_ALEN);
1337
1338         return 0;
1339 }
1340
1341 /*
1342  * CFG802.11 operation handler for scan request.
1343  *
1344  * This function issues a scan request to the firmware based upon
1345  * the user specified scan configuration. On successfull completion,
1346  * it also informs the results.
1347  */
1348 static int
1349 mwifiex_cfg80211_scan(struct wiphy *wiphy, struct net_device *dev,
1350                       struct cfg80211_scan_request *request)
1351 {
1352         struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
1353         int i, ret;
1354         struct ieee80211_channel *chan;
1355
1356         wiphy_dbg(wiphy, "info: received scan request on %s\n", dev->name);
1357
1358         if ((request->flags & CFG80211_SCAN_FLAG_TX_ABORT) &&
1359             atomic_read(&priv->wmm.tx_pkts_queued) >=
1360             MWIFIEX_MIN_TX_PENDING_TO_CANCEL_SCAN) {
1361                 dev_dbg(priv->adapter->dev, "scan rejected due to traffic\n");
1362                 return -EBUSY;
1363         }
1364
1365         if (priv->user_scan_cfg) {
1366                 dev_err(priv->adapter->dev, "cmd: Scan already in process..\n");
1367                 return -EBUSY;
1368         }
1369
1370         priv->user_scan_cfg = kzalloc(sizeof(struct mwifiex_user_scan_cfg),
1371                                       GFP_KERNEL);
1372         if (!priv->user_scan_cfg) {
1373                 dev_err(priv->adapter->dev, "failed to alloc scan_req\n");
1374                 return -ENOMEM;
1375         }
1376
1377         priv->scan_request = request;
1378
1379         priv->user_scan_cfg->num_ssids = request->n_ssids;
1380         priv->user_scan_cfg->ssid_list = request->ssids;
1381
1382         if (request->ie && request->ie_len) {
1383                 for (i = 0; i < MWIFIEX_MAX_VSIE_NUM; i++) {
1384                         if (priv->vs_ie[i].mask != MWIFIEX_VSIE_MASK_CLEAR)
1385                                 continue;
1386                         priv->vs_ie[i].mask = MWIFIEX_VSIE_MASK_SCAN;
1387                         memcpy(&priv->vs_ie[i].ie, request->ie,
1388                                request->ie_len);
1389                         break;
1390                 }
1391         }
1392
1393         for (i = 0; i < request->n_channels; i++) {
1394                 chan = request->channels[i];
1395                 priv->user_scan_cfg->chan_list[i].chan_number = chan->hw_value;
1396                 priv->user_scan_cfg->chan_list[i].radio_type = chan->band;
1397
1398                 if (chan->flags & IEEE80211_CHAN_PASSIVE_SCAN)
1399                         priv->user_scan_cfg->chan_list[i].scan_type =
1400                                                 MWIFIEX_SCAN_TYPE_PASSIVE;
1401                 else
1402                         priv->user_scan_cfg->chan_list[i].scan_type =
1403                                                 MWIFIEX_SCAN_TYPE_ACTIVE;
1404
1405                 priv->user_scan_cfg->chan_list[i].scan_time = 0;
1406         }
1407
1408         ret = mwifiex_scan_networks(priv, priv->user_scan_cfg);
1409         if (ret) {
1410                 dev_err(priv->adapter->dev, "scan failed: %d\n", ret);
1411                 priv->scan_request = NULL;
1412                 kfree(priv->user_scan_cfg);
1413                 priv->user_scan_cfg = NULL;
1414                 return ret;
1415         }
1416
1417         if (request->ie && request->ie_len) {
1418                 for (i = 0; i < MWIFIEX_MAX_VSIE_NUM; i++) {
1419                         if (priv->vs_ie[i].mask == MWIFIEX_VSIE_MASK_SCAN) {
1420                                 priv->vs_ie[i].mask = MWIFIEX_VSIE_MASK_CLEAR;
1421                                 memset(&priv->vs_ie[i].ie, 0,
1422                                        MWIFIEX_MAX_VSIE_LEN);
1423                         }
1424                 }
1425         }
1426         return 0;
1427 }
1428
1429 /*
1430  * This function sets up the CFG802.11 specific HT capability fields
1431  * with default values.
1432  *
1433  * The following default values are set -
1434  *      - HT Supported = True
1435  *      - Maximum AMPDU length factor = IEEE80211_HT_MAX_AMPDU_64K
1436  *      - Minimum AMPDU spacing = IEEE80211_HT_MPDU_DENSITY_NONE
1437  *      - HT Capabilities supported by firmware
1438  *      - MCS information, Rx mask = 0xff
1439  *      - MCD information, Tx parameters = IEEE80211_HT_MCS_TX_DEFINED (0x01)
1440  */
1441 static void
1442 mwifiex_setup_ht_caps(struct ieee80211_sta_ht_cap *ht_info,
1443                       struct mwifiex_private *priv)
1444 {
1445         int rx_mcs_supp;
1446         struct ieee80211_mcs_info mcs_set;
1447         u8 *mcs = (u8 *)&mcs_set;
1448         struct mwifiex_adapter *adapter = priv->adapter;
1449
1450         ht_info->ht_supported = true;
1451         ht_info->ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
1452         ht_info->ampdu_density = IEEE80211_HT_MPDU_DENSITY_NONE;
1453
1454         memset(&ht_info->mcs, 0, sizeof(ht_info->mcs));
1455
1456         /* Fill HT capability information */
1457         if (ISSUPP_CHANWIDTH40(adapter->hw_dot_11n_dev_cap))
1458                 ht_info->cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
1459         else
1460                 ht_info->cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
1461
1462         if (ISSUPP_SHORTGI20(adapter->hw_dot_11n_dev_cap))
1463                 ht_info->cap |= IEEE80211_HT_CAP_SGI_20;
1464         else
1465                 ht_info->cap &= ~IEEE80211_HT_CAP_SGI_20;
1466
1467         if (ISSUPP_SHORTGI40(adapter->hw_dot_11n_dev_cap))
1468                 ht_info->cap |= IEEE80211_HT_CAP_SGI_40;
1469         else
1470                 ht_info->cap &= ~IEEE80211_HT_CAP_SGI_40;
1471
1472         if (ISSUPP_RXSTBC(adapter->hw_dot_11n_dev_cap))
1473                 ht_info->cap |= 1 << IEEE80211_HT_CAP_RX_STBC_SHIFT;
1474         else
1475                 ht_info->cap &= ~(3 << IEEE80211_HT_CAP_RX_STBC_SHIFT);
1476
1477         if (ISSUPP_TXSTBC(adapter->hw_dot_11n_dev_cap))
1478                 ht_info->cap |= IEEE80211_HT_CAP_TX_STBC;
1479         else
1480                 ht_info->cap &= ~IEEE80211_HT_CAP_TX_STBC;
1481
1482         ht_info->cap &= ~IEEE80211_HT_CAP_MAX_AMSDU;
1483         ht_info->cap |= IEEE80211_HT_CAP_SM_PS;
1484
1485         rx_mcs_supp = GET_RXMCSSUPP(adapter->hw_dev_mcs_support);
1486         /* Set MCS for 1x1 */
1487         memset(mcs, 0xff, rx_mcs_supp);
1488         /* Clear all the other values */
1489         memset(&mcs[rx_mcs_supp], 0,
1490                sizeof(struct ieee80211_mcs_info) - rx_mcs_supp);
1491         if (priv->bss_mode == NL80211_IFTYPE_STATION ||
1492             ISSUPP_CHANWIDTH40(adapter->hw_dot_11n_dev_cap))
1493                 /* Set MCS32 for infra mode or ad-hoc mode with 40MHz support */
1494                 SETHT_MCS32(mcs_set.rx_mask);
1495
1496         memcpy((u8 *) &ht_info->mcs, mcs, sizeof(struct ieee80211_mcs_info));
1497
1498         ht_info->mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED;
1499 }
1500
1501 /*
1502  *  create a new virtual interface with the given name
1503  */
1504 struct net_device *mwifiex_add_virtual_intf(struct wiphy *wiphy,
1505                                             char *name,
1506                                             enum nl80211_iftype type,
1507                                             u32 *flags,
1508                                             struct vif_params *params)
1509 {
1510         struct mwifiex_private *priv = mwifiex_cfg80211_get_priv(wiphy);
1511         struct mwifiex_adapter *adapter;
1512         struct net_device *dev;
1513         void *mdev_priv;
1514
1515         if (!priv)
1516                 return ERR_PTR(-EFAULT);
1517
1518         adapter = priv->adapter;
1519         if (!adapter)
1520                 return ERR_PTR(-EFAULT);
1521
1522         switch (type) {
1523         case NL80211_IFTYPE_UNSPECIFIED:
1524         case NL80211_IFTYPE_STATION:
1525         case NL80211_IFTYPE_ADHOC:
1526                 if (priv->bss_mode) {
1527                         wiphy_err(wiphy, "cannot create multiple"
1528                                         " station/adhoc interfaces\n");
1529                         return ERR_PTR(-EINVAL);
1530                 }
1531
1532                 if (type == NL80211_IFTYPE_UNSPECIFIED)
1533                         priv->bss_mode = NL80211_IFTYPE_STATION;
1534                 else
1535                         priv->bss_mode = type;
1536
1537                 priv->bss_type = MWIFIEX_BSS_TYPE_STA;
1538                 priv->frame_type = MWIFIEX_DATA_FRAME_TYPE_ETH_II;
1539                 priv->bss_priority = 0;
1540                 priv->bss_role = MWIFIEX_BSS_ROLE_STA;
1541                 priv->bss_num = 0;
1542
1543                 break;
1544         default:
1545                 wiphy_err(wiphy, "type not supported\n");
1546                 return ERR_PTR(-EINVAL);
1547         }
1548
1549         dev = alloc_netdev_mqs(sizeof(struct mwifiex_private *), name,
1550                                ether_setup, IEEE80211_NUM_ACS, 1);
1551         if (!dev) {
1552                 wiphy_err(wiphy, "no memory available for netdevice\n");
1553                 priv->bss_mode = NL80211_IFTYPE_UNSPECIFIED;
1554                 return ERR_PTR(-ENOMEM);
1555         }
1556
1557         dev_net_set(dev, wiphy_net(wiphy));
1558         dev->ieee80211_ptr = priv->wdev;
1559         dev->ieee80211_ptr->iftype = priv->bss_mode;
1560         memcpy(dev->dev_addr, wiphy->perm_addr, ETH_ALEN);
1561         memcpy(dev->perm_addr, wiphy->perm_addr, ETH_ALEN);
1562         SET_NETDEV_DEV(dev, wiphy_dev(wiphy));
1563
1564         dev->flags |= IFF_BROADCAST | IFF_MULTICAST;
1565         dev->watchdog_timeo = MWIFIEX_DEFAULT_WATCHDOG_TIMEOUT;
1566         dev->hard_header_len += MWIFIEX_MIN_DATA_HEADER_LEN;
1567
1568         mdev_priv = netdev_priv(dev);
1569         *((unsigned long *) mdev_priv) = (unsigned long) priv;
1570
1571         priv->netdev = dev;
1572         mwifiex_init_priv_params(priv, dev);
1573
1574         SET_NETDEV_DEV(dev, adapter->dev);
1575
1576         /* Register network device */
1577         if (register_netdevice(dev)) {
1578                 wiphy_err(wiphy, "cannot register virtual network device\n");
1579                 free_netdev(dev);
1580                 priv->bss_mode = NL80211_IFTYPE_UNSPECIFIED;
1581                 return ERR_PTR(-EFAULT);
1582         }
1583
1584         sema_init(&priv->async_sem, 1);
1585
1586         dev_dbg(adapter->dev, "info: %s: Marvell 802.11 Adapter\n", dev->name);
1587
1588 #ifdef CONFIG_DEBUG_FS
1589         mwifiex_dev_debugfs_init(priv);
1590 #endif
1591         return dev;
1592 }
1593 EXPORT_SYMBOL_GPL(mwifiex_add_virtual_intf);
1594
1595 /*
1596  * del_virtual_intf: remove the virtual interface determined by dev
1597  */
1598 int mwifiex_del_virtual_intf(struct wiphy *wiphy, struct net_device *dev)
1599 {
1600         struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
1601
1602 #ifdef CONFIG_DEBUG_FS
1603         mwifiex_dev_debugfs_remove(priv);
1604 #endif
1605
1606         mwifiex_stop_net_dev_queue(priv->netdev, priv->adapter);
1607
1608         if (netif_carrier_ok(priv->netdev))
1609                 netif_carrier_off(priv->netdev);
1610
1611         if (dev->reg_state == NETREG_REGISTERED)
1612                 unregister_netdevice(dev);
1613
1614         /* Clear the priv in adapter */
1615         priv->netdev = NULL;
1616
1617         priv->media_connected = false;
1618
1619         priv->bss_mode = NL80211_IFTYPE_UNSPECIFIED;
1620
1621         return 0;
1622 }
1623 EXPORT_SYMBOL_GPL(mwifiex_del_virtual_intf);
1624
1625 /* station cfg80211 operations */
1626 static struct cfg80211_ops mwifiex_cfg80211_ops = {
1627         .add_virtual_intf = mwifiex_add_virtual_intf,
1628         .del_virtual_intf = mwifiex_del_virtual_intf,
1629         .change_virtual_intf = mwifiex_cfg80211_change_virtual_intf,
1630         .scan = mwifiex_cfg80211_scan,
1631         .connect = mwifiex_cfg80211_connect,
1632         .disconnect = mwifiex_cfg80211_disconnect,
1633         .get_station = mwifiex_cfg80211_get_station,
1634         .dump_station = mwifiex_cfg80211_dump_station,
1635         .set_wiphy_params = mwifiex_cfg80211_set_wiphy_params,
1636         .set_channel = mwifiex_cfg80211_set_channel,
1637         .join_ibss = mwifiex_cfg80211_join_ibss,
1638         .leave_ibss = mwifiex_cfg80211_leave_ibss,
1639         .add_key = mwifiex_cfg80211_add_key,
1640         .del_key = mwifiex_cfg80211_del_key,
1641         .mgmt_tx = mwifiex_cfg80211_mgmt_tx,
1642         .mgmt_frame_register = mwifiex_cfg80211_mgmt_frame_register,
1643         .set_default_key = mwifiex_cfg80211_set_default_key,
1644         .set_power_mgmt = mwifiex_cfg80211_set_power_mgmt,
1645         .set_tx_power = mwifiex_cfg80211_set_tx_power,
1646         .set_bitrate_mask = mwifiex_cfg80211_set_bitrate_mask,
1647         .set_cqm_rssi_config = mwifiex_cfg80211_set_cqm_rssi_config,
1648         .set_antenna = mwifiex_cfg80211_set_antenna,
1649 };
1650
1651 /*
1652  * This function registers the device with CFG802.11 subsystem.
1653  *
1654  * The function creates the wireless device/wiphy, populates it with
1655  * default parameters and handler function pointers, and finally
1656  * registers the device.
1657  */
1658 int mwifiex_register_cfg80211(struct mwifiex_private *priv)
1659 {
1660         int ret;
1661         void *wdev_priv;
1662         struct wireless_dev *wdev;
1663         struct ieee80211_sta_ht_cap *ht_info;
1664         u8 *country_code;
1665
1666         wdev = kzalloc(sizeof(struct wireless_dev), GFP_KERNEL);
1667         if (!wdev) {
1668                 dev_err(priv->adapter->dev, "%s: allocating wireless device\n",
1669                         __func__);
1670                 return -ENOMEM;
1671         }
1672         wdev->wiphy =
1673                 wiphy_new(&mwifiex_cfg80211_ops,
1674                           sizeof(struct mwifiex_private *));
1675         if (!wdev->wiphy) {
1676                 kfree(wdev);
1677                 return -ENOMEM;
1678         }
1679         wdev->iftype = NL80211_IFTYPE_STATION;
1680         wdev->wiphy->max_scan_ssids = 10;
1681         wdev->wiphy->max_scan_ie_len = MWIFIEX_MAX_VSIE_LEN;
1682         wdev->wiphy->mgmt_stypes = mwifiex_mgmt_stypes;
1683         wdev->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
1684                                        BIT(NL80211_IFTYPE_ADHOC);
1685
1686         wdev->wiphy->bands[IEEE80211_BAND_2GHZ] = &mwifiex_band_2ghz;
1687         ht_info = &wdev->wiphy->bands[IEEE80211_BAND_2GHZ]->ht_cap;
1688         mwifiex_setup_ht_caps(ht_info, priv);
1689
1690         if (priv->adapter->config_bands & BAND_A) {
1691                 wdev->wiphy->bands[IEEE80211_BAND_5GHZ] = &mwifiex_band_5ghz;
1692                 ht_info = &wdev->wiphy->bands[IEEE80211_BAND_5GHZ]->ht_cap;
1693                 mwifiex_setup_ht_caps(ht_info, priv);
1694         } else {
1695                 wdev->wiphy->bands[IEEE80211_BAND_5GHZ] = NULL;
1696         }
1697
1698         /* Initialize cipher suits */
1699         wdev->wiphy->cipher_suites = mwifiex_cipher_suites;
1700         wdev->wiphy->n_cipher_suites = ARRAY_SIZE(mwifiex_cipher_suites);
1701
1702         memcpy(wdev->wiphy->perm_addr, priv->curr_addr, ETH_ALEN);
1703         wdev->wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
1704
1705         wdev->wiphy->flags |= WIPHY_FLAG_CUSTOM_REGULATORY;
1706
1707         wdev->wiphy->probe_resp_offload =
1708                                     NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS |
1709                                     NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2 |
1710                                     NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P;
1711
1712         wiphy_apply_custom_regulatory(wdev->wiphy,
1713                                       &mwifiex_world_regdom_custom);
1714
1715         wdev->wiphy->available_antennas_tx =
1716                 BIT(priv->adapter->number_of_antenna) - 1;
1717         wdev->wiphy->available_antennas_rx =
1718                 BIT(priv->adapter->number_of_antenna) - 1;
1719
1720         /* Reserve space for mwifiex specific private data for BSS */
1721         wdev->wiphy->bss_priv_size = sizeof(struct mwifiex_bss_priv);
1722
1723         wdev->wiphy->reg_notifier = mwifiex_reg_notifier;
1724
1725         /* Set struct mwifiex_private pointer in wiphy_priv */
1726         wdev_priv = wiphy_priv(wdev->wiphy);
1727
1728         *(unsigned long *) wdev_priv = (unsigned long) priv;
1729
1730         set_wiphy_dev(wdev->wiphy, (struct device *) priv->adapter->dev);
1731
1732         ret = wiphy_register(wdev->wiphy);
1733         if (ret < 0) {
1734                 dev_err(priv->adapter->dev, "%s: registering cfg80211 device\n",
1735                         __func__);
1736                 wiphy_free(wdev->wiphy);
1737                 kfree(wdev);
1738                 return ret;
1739         } else {
1740                 dev_dbg(priv->adapter->dev,
1741                         "info: successfully registered wiphy device\n");
1742         }
1743
1744         country_code = mwifiex_11d_code_2_region(priv->adapter->region_code);
1745         if (country_code)
1746                 dev_info(priv->adapter->dev,
1747                          "ignoring F/W country code %2.2s\n", country_code);
1748
1749         priv->wdev = wdev;
1750
1751         return ret;
1752 }