mwifiex: discard deauth and disassoc event during WPS session
[deliverable/linux.git] / drivers / net / wireless / mwifiex / cfg80211.c
CommitLineData
5e6e3a92
BZ
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
3c68ef5b
AP
23static char *reg_alpha2;
24module_param(reg_alpha2, charp, 0);
25
cd8440da
AP
26static const struct ieee80211_iface_limit mwifiex_ap_sta_limits[] = {
27 {
197f4a2e 28 .max = 2, .types = BIT(NL80211_IFTYPE_STATION),
cd8440da
AP
29 },
30 {
31 .max = 1, .types = BIT(NL80211_IFTYPE_AP),
32 },
33};
34
35static const struct ieee80211_iface_combination mwifiex_iface_comb_ap_sta = {
36 .limits = mwifiex_ap_sta_limits,
37 .num_different_channels = 1,
38 .n_limits = ARRAY_SIZE(mwifiex_ap_sta_limits),
39 .max_interfaces = MWIFIEX_MAX_BSS_NUM,
40 .beacon_int_infra_match = true,
41};
42
cc0ba0d5
AK
43static const struct ieee80211_regdomain mwifiex_world_regdom_custom = {
44 .n_reg_rules = 7,
45 .alpha2 = "99",
46 .reg_rules = {
47 /* Channel 1 - 11 */
48 REG_RULE(2412-10, 2462+10, 40, 3, 20, 0),
49 /* Channel 12 - 13 */
50 REG_RULE(2467-10, 2472+10, 20, 3, 20,
51 NL80211_RRF_PASSIVE_SCAN | NL80211_RRF_NO_IBSS),
52 /* Channel 14 */
53 REG_RULE(2484-10, 2484+10, 20, 3, 20,
54 NL80211_RRF_PASSIVE_SCAN | NL80211_RRF_NO_IBSS |
55 NL80211_RRF_NO_OFDM),
56 /* Channel 36 - 48 */
57 REG_RULE(5180-10, 5240+10, 40, 3, 20,
58 NL80211_RRF_PASSIVE_SCAN | NL80211_RRF_NO_IBSS),
59 /* Channel 149 - 165 */
60 REG_RULE(5745-10, 5825+10, 40, 3, 20,
61 NL80211_RRF_PASSIVE_SCAN | NL80211_RRF_NO_IBSS),
62 /* Channel 52 - 64 */
63 REG_RULE(5260-10, 5320+10, 40, 3, 30,
64 NL80211_RRF_PASSIVE_SCAN | NL80211_RRF_NO_IBSS |
65 NL80211_RRF_DFS),
66 /* Channel 100 - 140 */
67 REG_RULE(5500-10, 5700+10, 40, 3, 30,
68 NL80211_RRF_PASSIVE_SCAN | NL80211_RRF_NO_IBSS |
69 NL80211_RRF_DFS),
70 }
71};
72
5e6e3a92
BZ
73/*
74 * This function maps the nl802.11 channel type into driver channel type.
75 *
76 * The mapping is as follows -
21c3ba34
AK
77 * NL80211_CHAN_NO_HT -> IEEE80211_HT_PARAM_CHA_SEC_NONE
78 * NL80211_CHAN_HT20 -> IEEE80211_HT_PARAM_CHA_SEC_NONE
79 * NL80211_CHAN_HT40PLUS -> IEEE80211_HT_PARAM_CHA_SEC_ABOVE
80 * NL80211_CHAN_HT40MINUS -> IEEE80211_HT_PARAM_CHA_SEC_BELOW
81 * Others -> IEEE80211_HT_PARAM_CHA_SEC_NONE
5e6e3a92 82 */
7feb4c48 83u8 mwifiex_chan_type_to_sec_chan_offset(enum nl80211_channel_type chan_type)
5e6e3a92 84{
05910f4a 85 switch (chan_type) {
5e6e3a92
BZ
86 case NL80211_CHAN_NO_HT:
87 case NL80211_CHAN_HT20:
21c3ba34 88 return IEEE80211_HT_PARAM_CHA_SEC_NONE;
5e6e3a92 89 case NL80211_CHAN_HT40PLUS:
21c3ba34 90 return IEEE80211_HT_PARAM_CHA_SEC_ABOVE;
5e6e3a92 91 case NL80211_CHAN_HT40MINUS:
21c3ba34 92 return IEEE80211_HT_PARAM_CHA_SEC_BELOW;
5e6e3a92 93 default:
21c3ba34 94 return IEEE80211_HT_PARAM_CHA_SEC_NONE;
5e6e3a92 95 }
5e6e3a92
BZ
96}
97
5e6e3a92
BZ
98/*
99 * This function checks whether WEP is set.
100 */
101static int
102mwifiex_is_alg_wep(u32 cipher)
103{
5e6e3a92 104 switch (cipher) {
2be50b8d
YAP
105 case WLAN_CIPHER_SUITE_WEP40:
106 case WLAN_CIPHER_SUITE_WEP104:
270e58e8 107 return 1;
5e6e3a92 108 default:
5e6e3a92
BZ
109 break;
110 }
270e58e8
YAP
111
112 return 0;
5e6e3a92
BZ
113}
114
5e6e3a92
BZ
115/*
116 * This function retrieves the private structure from kernel wiphy structure.
117 */
67fdf39e 118static void *mwifiex_cfg80211_get_adapter(struct wiphy *wiphy)
5e6e3a92
BZ
119{
120 return (void *) (*(unsigned long *) wiphy_priv(wiphy));
121}
122
123/*
124 * CFG802.11 operation handler to delete a network key.
125 */
126static int
127mwifiex_cfg80211_del_key(struct wiphy *wiphy, struct net_device *netdev,
128 u8 key_index, bool pairwise, const u8 *mac_addr)
129{
f540f9f3 130 struct mwifiex_private *priv = mwifiex_netdev_get_priv(netdev);
75edd2c6
AP
131 const u8 bc_mac[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
132 const u8 *peer_mac = pairwise ? mac_addr : bc_mac;
5e6e3a92 133
53b11231 134 if (mwifiex_set_encode(priv, NULL, NULL, 0, key_index, peer_mac, 1)) {
5e6e3a92
BZ
135 wiphy_err(wiphy, "deleting the crypto keys\n");
136 return -EFAULT;
137 }
138
139 wiphy_dbg(wiphy, "info: crypto keys deleted\n");
140 return 0;
141}
142
e39faa73
SP
143/*
144 * This function forms an skb for management frame.
145 */
146static int
147mwifiex_form_mgmt_frame(struct sk_buff *skb, const u8 *buf, size_t len)
148{
149 u8 addr[ETH_ALEN] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
150 u16 pkt_len;
151 u32 tx_control = 0, pkt_type = PKT_TYPE_MGMT;
152 struct timeval tv;
153
154 pkt_len = len + ETH_ALEN;
155
156 skb_reserve(skb, MWIFIEX_MIN_DATA_HEADER_LEN +
157 MWIFIEX_MGMT_FRAME_HEADER_SIZE + sizeof(pkt_len));
158 memcpy(skb_push(skb, sizeof(pkt_len)), &pkt_len, sizeof(pkt_len));
159
160 memcpy(skb_push(skb, sizeof(tx_control)),
161 &tx_control, sizeof(tx_control));
162
163 memcpy(skb_push(skb, sizeof(pkt_type)), &pkt_type, sizeof(pkt_type));
164
165 /* Add packet data and address4 */
166 memcpy(skb_put(skb, sizeof(struct ieee80211_hdr_3addr)), buf,
167 sizeof(struct ieee80211_hdr_3addr));
168 memcpy(skb_put(skb, ETH_ALEN), addr, ETH_ALEN);
169 memcpy(skb_put(skb, len - sizeof(struct ieee80211_hdr_3addr)),
170 buf + sizeof(struct ieee80211_hdr_3addr),
171 len - sizeof(struct ieee80211_hdr_3addr));
172
173 skb->priority = LOW_PRIO_TID;
174 do_gettimeofday(&tv);
175 skb->tstamp = timeval_to_ktime(tv);
176
177 return 0;
178}
179
180/*
181 * CFG802.11 operation handler to transmit a management frame.
182 */
183static int
184mwifiex_cfg80211_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev,
185 struct ieee80211_channel *chan, bool offchan,
42d97a59
JB
186 unsigned int wait, const u8 *buf, size_t len,
187 bool no_cck, bool dont_wait_for_ack, u64 *cookie)
e39faa73
SP
188{
189 struct sk_buff *skb;
190 u16 pkt_len;
191 const struct ieee80211_mgmt *mgmt;
231d83e2 192 struct mwifiex_txinfo *tx_info;
e39faa73
SP
193 struct mwifiex_private *priv = mwifiex_netdev_get_priv(wdev->netdev);
194
195 if (!buf || !len) {
196 wiphy_err(wiphy, "invalid buffer and length\n");
197 return -EFAULT;
198 }
199
200 mgmt = (const struct ieee80211_mgmt *)buf;
201 if (GET_BSS_ROLE(priv) != MWIFIEX_BSS_ROLE_STA &&
202 ieee80211_is_probe_resp(mgmt->frame_control)) {
203 /* Since we support offload probe resp, we need to skip probe
204 * resp in AP or GO mode */
205 wiphy_dbg(wiphy,
206 "info: skip to send probe resp in AP or GO mode\n");
207 return 0;
208 }
209
210 pkt_len = len + ETH_ALEN;
211 skb = dev_alloc_skb(MWIFIEX_MIN_DATA_HEADER_LEN +
212 MWIFIEX_MGMT_FRAME_HEADER_SIZE +
213 pkt_len + sizeof(pkt_len));
214
215 if (!skb) {
216 wiphy_err(wiphy, "allocate skb failed for management frame\n");
217 return -ENOMEM;
218 }
219
231d83e2
HY
220 tx_info = MWIFIEX_SKB_TXCB(skb);
221 tx_info->bss_num = priv->bss_num;
222 tx_info->bss_type = priv->bss_type;
223
e39faa73
SP
224 mwifiex_form_mgmt_frame(skb, buf, len);
225 mwifiex_queue_tx_pkt(priv, skb);
226
e00adf39 227 *cookie = prandom_u32() | 1;
e39faa73
SP
228 cfg80211_mgmt_tx_status(wdev, *cookie, buf, len, true, GFP_ATOMIC);
229
230 wiphy_dbg(wiphy, "info: management frame transmitted\n");
231 return 0;
232}
233
3cec6870
SP
234/*
235 * CFG802.11 operation handler to register a mgmt frame.
236 */
237static void
238mwifiex_cfg80211_mgmt_frame_register(struct wiphy *wiphy,
239 struct wireless_dev *wdev,
240 u16 frame_type, bool reg)
241{
242 struct mwifiex_private *priv = mwifiex_netdev_get_priv(wdev->netdev);
243
244 if (reg)
245 priv->mgmt_frame_mask |= BIT(frame_type >> 4);
246 else
247 priv->mgmt_frame_mask &= ~BIT(frame_type >> 4);
248
249 mwifiex_send_cmd_async(priv, HostCmd_CMD_MGMT_FRAME_REG,
250 HostCmd_ACT_GEN_SET, 0, &priv->mgmt_frame_mask);
251
252 wiphy_dbg(wiphy, "info: mgmt frame registered\n");
253}
254
7feb4c48
SP
255/*
256 * CFG802.11 operation handler to remain on channel.
257 */
258static int
259mwifiex_cfg80211_remain_on_channel(struct wiphy *wiphy,
260 struct wireless_dev *wdev,
261 struct ieee80211_channel *chan,
7feb4c48
SP
262 unsigned int duration, u64 *cookie)
263{
264 struct mwifiex_private *priv = mwifiex_netdev_get_priv(wdev->netdev);
265 int ret;
266
267 if (!chan || !cookie) {
268 wiphy_err(wiphy, "Invalid parameter for ROC\n");
269 return -EINVAL;
270 }
271
272 if (priv->roc_cfg.cookie) {
273 wiphy_dbg(wiphy, "info: ongoing ROC, cookie = 0x%llu\n",
274 priv->roc_cfg.cookie);
275 return -EBUSY;
276 }
277
278 ret = mwifiex_remain_on_chan_cfg(priv, HostCmd_ACT_GEN_SET, chan,
42d97a59 279 duration);
7feb4c48
SP
280
281 if (!ret) {
e00adf39 282 *cookie = prandom_u32() | 1;
7feb4c48
SP
283 priv->roc_cfg.cookie = *cookie;
284 priv->roc_cfg.chan = *chan;
7feb4c48 285
42d97a59 286 cfg80211_ready_on_channel(wdev, *cookie, chan,
7feb4c48
SP
287 duration, GFP_ATOMIC);
288
289 wiphy_dbg(wiphy, "info: ROC, cookie = 0x%llx\n", *cookie);
290 }
291
292 return ret;
293}
294
295/*
296 * CFG802.11 operation handler to cancel remain on channel.
297 */
298static int
299mwifiex_cfg80211_cancel_remain_on_channel(struct wiphy *wiphy,
300 struct wireless_dev *wdev, u64 cookie)
301{
302 struct mwifiex_private *priv = mwifiex_netdev_get_priv(wdev->netdev);
303 int ret;
304
305 if (cookie != priv->roc_cfg.cookie)
306 return -ENOENT;
307
308 ret = mwifiex_remain_on_chan_cfg(priv, HostCmd_ACT_GEN_REMOVE,
42d97a59 309 &priv->roc_cfg.chan, 0);
7feb4c48
SP
310
311 if (!ret) {
312 cfg80211_remain_on_channel_expired(wdev, cookie,
313 &priv->roc_cfg.chan,
7feb4c48
SP
314 GFP_ATOMIC);
315
316 memset(&priv->roc_cfg, 0, sizeof(struct mwifiex_roc_cfg));
317
318 wiphy_dbg(wiphy, "info: cancel ROC, cookie = 0x%llx\n", cookie);
319 }
320
321 return ret;
322}
323
5e6e3a92
BZ
324/*
325 * CFG802.11 operation handler to set Tx power.
326 */
327static int
328mwifiex_cfg80211_set_tx_power(struct wiphy *wiphy,
c8442118 329 struct wireless_dev *wdev,
5e6e3a92 330 enum nl80211_tx_power_setting type,
742c29fd 331 int mbm)
5e6e3a92 332{
67fdf39e
AP
333 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
334 struct mwifiex_private *priv;
600f5d90 335 struct mwifiex_power_cfg power_cfg;
742c29fd 336 int dbm = MBM_TO_DBM(mbm);
5e6e3a92 337
600f5d90
AK
338 if (type == NL80211_TX_POWER_FIXED) {
339 power_cfg.is_power_auto = 0;
340 power_cfg.power_level = dbm;
341 } else {
342 power_cfg.is_power_auto = 1;
343 }
344
67fdf39e
AP
345 priv = mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY);
346
636c4598 347 return mwifiex_set_tx_power(priv, &power_cfg);
5e6e3a92
BZ
348}
349
350/*
351 * CFG802.11 operation handler to set Power Save option.
352 *
353 * The timeout value, if provided, is currently ignored.
354 */
355static int
356mwifiex_cfg80211_set_power_mgmt(struct wiphy *wiphy,
357 struct net_device *dev,
358 bool enabled, int timeout)
359{
f540f9f3 360 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
600f5d90 361 u32 ps_mode;
5e6e3a92
BZ
362
363 if (timeout)
364 wiphy_dbg(wiphy,
aea0701e 365 "info: ignore timeout value for IEEE Power Save\n");
5e6e3a92 366
600f5d90 367 ps_mode = enabled;
5e6e3a92 368
636c4598 369 return mwifiex_drv_set_power(priv, &ps_mode);
5e6e3a92
BZ
370}
371
372/*
373 * CFG802.11 operation handler to set the default network key.
374 */
375static int
376mwifiex_cfg80211_set_default_key(struct wiphy *wiphy, struct net_device *netdev,
377 u8 key_index, bool unicast,
378 bool multicast)
379{
f540f9f3 380 struct mwifiex_private *priv = mwifiex_netdev_get_priv(netdev);
5e6e3a92 381
2d3d0a88 382 /* Return if WEP key not configured */
5eb02e44 383 if (!priv->sec_info.wep_enabled)
2d3d0a88
AK
384 return 0;
385
96893538
AP
386 if (priv->bss_type == MWIFIEX_BSS_TYPE_UAP) {
387 priv->wep_key_curr_index = key_index;
53b11231
YL
388 } else if (mwifiex_set_encode(priv, NULL, NULL, 0, key_index,
389 NULL, 0)) {
636c4598 390 wiphy_err(wiphy, "set default Tx key index\n");
5e6e3a92 391 return -EFAULT;
636c4598 392 }
5e6e3a92
BZ
393
394 return 0;
395}
396
397/*
398 * CFG802.11 operation handler to add a network key.
399 */
400static int
401mwifiex_cfg80211_add_key(struct wiphy *wiphy, struct net_device *netdev,
402 u8 key_index, bool pairwise, const u8 *mac_addr,
403 struct key_params *params)
404{
f540f9f3 405 struct mwifiex_private *priv = mwifiex_netdev_get_priv(netdev);
96893538 406 struct mwifiex_wep_key *wep_key;
75edd2c6
AP
407 const u8 bc_mac[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
408 const u8 *peer_mac = pairwise ? mac_addr : bc_mac;
5e6e3a92 409
96893538
AP
410 if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_UAP &&
411 (params->cipher == WLAN_CIPHER_SUITE_WEP40 ||
412 params->cipher == WLAN_CIPHER_SUITE_WEP104)) {
413 if (params->key && params->key_len) {
414 wep_key = &priv->wep_key[key_index];
415 memset(wep_key, 0, sizeof(struct mwifiex_wep_key));
416 memcpy(wep_key->key_material, params->key,
417 params->key_len);
418 wep_key->key_index = key_index;
419 wep_key->key_length = params->key_len;
420 priv->sec_info.wep_enabled = 1;
421 }
422 return 0;
423 }
424
53b11231 425 if (mwifiex_set_encode(priv, params, params->key, params->key_len,
75edd2c6 426 key_index, peer_mac, 0)) {
636c4598 427 wiphy_err(wiphy, "crypto keys added\n");
5e6e3a92 428 return -EFAULT;
636c4598 429 }
5e6e3a92
BZ
430
431 return 0;
432}
433
434/*
435 * This function sends domain information to the firmware.
436 *
437 * The following information are passed to the firmware -
438 * - Country codes
439 * - Sub bands (first channel, number of channels, maximum Tx power)
440 */
441static int mwifiex_send_domain_info_cmd_fw(struct wiphy *wiphy)
442{
443 u8 no_of_triplet = 0;
444 struct ieee80211_country_ie_triplet *t;
445 u8 no_of_parsed_chan = 0;
446 u8 first_chan = 0, next_chan = 0, max_pwr = 0;
447 u8 i, flag = 0;
448 enum ieee80211_band band;
449 struct ieee80211_supported_band *sband;
450 struct ieee80211_channel *ch;
67fdf39e
AP
451 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
452 struct mwifiex_private *priv;
5e6e3a92 453 struct mwifiex_802_11d_domain_reg *domain_info = &adapter->domain_reg;
5e6e3a92
BZ
454
455 /* Set country code */
67fdf39e
AP
456 domain_info->country_code[0] = adapter->country_code[0];
457 domain_info->country_code[1] = adapter->country_code[1];
5e6e3a92
BZ
458 domain_info->country_code[2] = ' ';
459
460 band = mwifiex_band_to_radio_type(adapter->config_bands);
461 if (!wiphy->bands[band]) {
462 wiphy_err(wiphy, "11D: setting domain info in FW\n");
463 return -1;
464 }
465
466 sband = wiphy->bands[band];
467
468 for (i = 0; i < sband->n_channels ; i++) {
469 ch = &sband->channels[i];
470 if (ch->flags & IEEE80211_CHAN_DISABLED)
471 continue;
472
473 if (!flag) {
474 flag = 1;
475 first_chan = (u32) ch->hw_value;
476 next_chan = first_chan;
22db2497 477 max_pwr = ch->max_power;
5e6e3a92
BZ
478 no_of_parsed_chan = 1;
479 continue;
480 }
481
482 if (ch->hw_value == next_chan + 1 &&
22db2497 483 ch->max_power == max_pwr) {
5e6e3a92
BZ
484 next_chan++;
485 no_of_parsed_chan++;
486 } else {
487 t = &domain_info->triplet[no_of_triplet];
488 t->chans.first_channel = first_chan;
489 t->chans.num_channels = no_of_parsed_chan;
490 t->chans.max_power = max_pwr;
491 no_of_triplet++;
492 first_chan = (u32) ch->hw_value;
493 next_chan = first_chan;
22db2497 494 max_pwr = ch->max_power;
5e6e3a92
BZ
495 no_of_parsed_chan = 1;
496 }
497 }
498
499 if (flag) {
500 t = &domain_info->triplet[no_of_triplet];
501 t->chans.first_channel = first_chan;
502 t->chans.num_channels = no_of_parsed_chan;
503 t->chans.max_power = max_pwr;
504 no_of_triplet++;
505 }
506
507 domain_info->no_of_triplet = no_of_triplet;
636c4598 508
67fdf39e
AP
509 priv = mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY);
510
636c4598 511 if (mwifiex_send_cmd_async(priv, HostCmd_CMD_802_11D_DOMAIN_INFO,
aea0701e 512 HostCmd_ACT_GEN_SET, 0, NULL)) {
5e6e3a92 513 wiphy_err(wiphy, "11D: setting domain info in FW\n");
636c4598
YAP
514 return -1;
515 }
5e6e3a92 516
636c4598 517 return 0;
5e6e3a92
BZ
518}
519
520/*
521 * CFG802.11 regulatory domain callback function.
522 *
523 * This function is called when the regulatory domain is changed due to the
524 * following reasons -
525 * - Set by driver
526 * - Set by system core
527 * - Set by user
528 * - Set bt Country IE
529 */
0c0280bd
LR
530static void mwifiex_reg_notifier(struct wiphy *wiphy,
531 struct regulatory_request *request)
5e6e3a92 532{
67fdf39e 533 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
5e6e3a92 534
67fdf39e
AP
535 wiphy_dbg(wiphy, "info: cfg80211 regulatory domain callback for %c%c\n",
536 request->alpha2[0], request->alpha2[1]);
5e6e3a92 537
67fdf39e 538 memcpy(adapter->country_code, request->alpha2, sizeof(request->alpha2));
5e6e3a92
BZ
539
540 switch (request->initiator) {
541 case NL80211_REGDOM_SET_BY_DRIVER:
542 case NL80211_REGDOM_SET_BY_CORE:
543 case NL80211_REGDOM_SET_BY_USER:
544 break;
545 /* Todo: apply driver specific changes in channel flags based
546 on the request initiator if necessary. */
547 case NL80211_REGDOM_SET_BY_COUNTRY_IE:
548 break;
549 }
550 mwifiex_send_domain_info_cmd_fw(wiphy);
5e6e3a92
BZ
551}
552
5e6e3a92
BZ
553/*
554 * This function sets the fragmentation threshold.
555 *
600f5d90 556 * The fragmentation threshold value must lie between MWIFIEX_FRAG_MIN_VALUE
5e6e3a92
BZ
557 * and MWIFIEX_FRAG_MAX_VALUE.
558 */
559static int
560mwifiex_set_frag(struct mwifiex_private *priv, u32 frag_thr)
561{
aea0701e
YAP
562 if (frag_thr < MWIFIEX_FRAG_MIN_VALUE ||
563 frag_thr > MWIFIEX_FRAG_MAX_VALUE)
9b930eae 564 frag_thr = MWIFIEX_FRAG_MAX_VALUE;
5e6e3a92 565
9b930eae
AP
566 return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_SNMP_MIB,
567 HostCmd_ACT_GEN_SET, FRAG_THRESH_I,
568 &frag_thr);
5e6e3a92
BZ
569}
570
571/*
572 * This function sets the RTS threshold.
600f5d90
AK
573
574 * The rts value must lie between MWIFIEX_RTS_MIN_VALUE
575 * and MWIFIEX_RTS_MAX_VALUE.
5e6e3a92
BZ
576 */
577static int
578mwifiex_set_rts(struct mwifiex_private *priv, u32 rts_thr)
579{
5e6e3a92
BZ
580 if (rts_thr < MWIFIEX_RTS_MIN_VALUE || rts_thr > MWIFIEX_RTS_MAX_VALUE)
581 rts_thr = MWIFIEX_RTS_MAX_VALUE;
582
636c4598 583 return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_SNMP_MIB,
600f5d90
AK
584 HostCmd_ACT_GEN_SET, RTS_THRESH_I,
585 &rts_thr);
5e6e3a92
BZ
586}
587
588/*
589 * CFG802.11 operation handler to set wiphy parameters.
590 *
591 * This function can be used to set the RTS threshold and the
592 * Fragmentation threshold of the driver.
593 */
594static int
595mwifiex_cfg80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
596{
67fdf39e 597 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
9b930eae
AP
598 struct mwifiex_private *priv;
599 struct mwifiex_uap_bss_param *bss_cfg;
600 int ret, bss_started, i;
601
602 for (i = 0; i < adapter->priv_num; i++) {
603 priv = adapter->priv[i];
604
605 switch (priv->bss_role) {
606 case MWIFIEX_BSS_ROLE_UAP:
607 bss_cfg = kzalloc(sizeof(struct mwifiex_uap_bss_param),
608 GFP_KERNEL);
609 if (!bss_cfg)
610 return -ENOMEM;
611
612 mwifiex_set_sys_config_invalid_data(bss_cfg);
613
614 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
615 bss_cfg->rts_threshold = wiphy->rts_threshold;
616 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
617 bss_cfg->frag_threshold = wiphy->frag_threshold;
618 if (changed & WIPHY_PARAM_RETRY_LONG)
619 bss_cfg->retry_limit = wiphy->retry_long;
620
621 bss_started = priv->bss_started;
622
623 ret = mwifiex_send_cmd_sync(priv,
624 HostCmd_CMD_UAP_BSS_STOP,
625 HostCmd_ACT_GEN_SET, 0,
626 NULL);
627 if (ret) {
628 wiphy_err(wiphy, "Failed to stop the BSS\n");
629 kfree(bss_cfg);
630 return ret;
631 }
632
633 ret = mwifiex_send_cmd_async(priv,
634 HostCmd_CMD_UAP_SYS_CONFIG,
635 HostCmd_ACT_GEN_SET,
e76268da 636 UAP_BSS_PARAMS_I, bss_cfg);
5e6e3a92 637
9b930eae
AP
638 kfree(bss_cfg);
639
640 if (ret) {
641 wiphy_err(wiphy, "Failed to set bss config\n");
642 return ret;
643 }
5e6e3a92 644
9b930eae
AP
645 if (!bss_started)
646 break;
647
648 ret = mwifiex_send_cmd_async(priv,
649 HostCmd_CMD_UAP_BSS_START,
650 HostCmd_ACT_GEN_SET, 0,
651 NULL);
652 if (ret) {
653 wiphy_err(wiphy, "Failed to start BSS\n");
654 return ret;
655 }
656
657 break;
658 case MWIFIEX_BSS_ROLE_STA:
659 if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
660 ret = mwifiex_set_rts(priv,
661 wiphy->rts_threshold);
662 if (ret)
663 return ret;
664 }
665 if (changed & WIPHY_PARAM_FRAG_THRESHOLD) {
666 ret = mwifiex_set_frag(priv,
667 wiphy->frag_threshold);
668 if (ret)
669 return ret;
670 }
671 break;
672 }
673 }
674
675 return 0;
5e6e3a92
BZ
676}
677
e1a2b7a3
SP
678static int
679mwifiex_cfg80211_deinit_p2p(struct mwifiex_private *priv)
680{
681 u16 mode = P2P_MODE_DISABLE;
682
9197ab9e
SP
683 if (GET_BSS_ROLE(priv) != MWIFIEX_BSS_ROLE_STA)
684 mwifiex_set_bss_role(priv, MWIFIEX_BSS_ROLE_STA);
685
e1a2b7a3
SP
686 if (mwifiex_send_cmd_sync(priv, HostCmd_CMD_P2P_MODE_CFG,
687 HostCmd_ACT_GEN_SET, 0, &mode))
688 return -1;
689
690 return 0;
691}
692
693/*
694 * This function initializes the functionalities for P2P client.
695 * The P2P client initialization sequence is:
696 * disable -> device -> client
697 */
698static int
699mwifiex_cfg80211_init_p2p_client(struct mwifiex_private *priv)
700{
701 u16 mode;
702
703 if (mwifiex_cfg80211_deinit_p2p(priv))
704 return -1;
705
706 mode = P2P_MODE_DEVICE;
707 if (mwifiex_send_cmd_sync(priv, HostCmd_CMD_P2P_MODE_CFG,
708 HostCmd_ACT_GEN_SET, 0, &mode))
709 return -1;
710
711 mode = P2P_MODE_CLIENT;
712 if (mwifiex_send_cmd_sync(priv, HostCmd_CMD_P2P_MODE_CFG,
713 HostCmd_ACT_GEN_SET, 0, &mode))
714 return -1;
715
716 return 0;
717}
718
9197ab9e
SP
719/*
720 * This function initializes the functionalities for P2P GO.
721 * The P2P GO initialization sequence is:
722 * disable -> device -> GO
723 */
724static int
725mwifiex_cfg80211_init_p2p_go(struct mwifiex_private *priv)
726{
727 u16 mode;
728
729 if (mwifiex_cfg80211_deinit_p2p(priv))
730 return -1;
731
732 mode = P2P_MODE_DEVICE;
733 if (mwifiex_send_cmd_sync(priv, HostCmd_CMD_P2P_MODE_CFG,
734 HostCmd_ACT_GEN_SET, 0, &mode))
735 return -1;
736
737 mode = P2P_MODE_GO;
738 if (mwifiex_send_cmd_sync(priv, HostCmd_CMD_P2P_MODE_CFG,
739 HostCmd_ACT_GEN_SET, 0, &mode))
740 return -1;
741
742 if (GET_BSS_ROLE(priv) != MWIFIEX_BSS_ROLE_UAP)
743 mwifiex_set_bss_role(priv, MWIFIEX_BSS_ROLE_UAP);
744
745 return 0;
746}
747
5e6e3a92
BZ
748/*
749 * CFG802.11 operation handler to change interface type.
5e6e3a92
BZ
750 */
751static int
752mwifiex_cfg80211_change_virtual_intf(struct wiphy *wiphy,
753 struct net_device *dev,
754 enum nl80211_iftype type, u32 *flags,
755 struct vif_params *params)
756{
270e58e8 757 int ret;
5e6e3a92 758 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
5e6e3a92 759
4f02341a 760 switch (dev->ieee80211_ptr->iftype) {
5e6e3a92 761 case NL80211_IFTYPE_ADHOC:
4f02341a
AP
762 switch (type) {
763 case NL80211_IFTYPE_STATION:
764 break;
765 case NL80211_IFTYPE_UNSPECIFIED:
766 wiphy_warn(wiphy, "%s: kept type as IBSS\n", dev->name);
767 case NL80211_IFTYPE_ADHOC: /* This shouldn't happen */
768 return 0;
769 case NL80211_IFTYPE_AP:
770 default:
771 wiphy_err(wiphy, "%s: changing to %d not supported\n",
772 dev->name, type);
773 return -EOPNOTSUPP;
774 }
5e6e3a92
BZ
775 break;
776 case NL80211_IFTYPE_STATION:
4f02341a
AP
777 switch (type) {
778 case NL80211_IFTYPE_ADHOC:
779 break;
e1a2b7a3
SP
780 case NL80211_IFTYPE_P2P_CLIENT:
781 if (mwifiex_cfg80211_init_p2p_client(priv))
782 return -EFAULT;
783 dev->ieee80211_ptr->iftype = type;
784 return 0;
9197ab9e
SP
785 case NL80211_IFTYPE_P2P_GO:
786 if (mwifiex_cfg80211_init_p2p_go(priv))
787 return -EFAULT;
788 dev->ieee80211_ptr->iftype = type;
789 return 0;
4f02341a
AP
790 case NL80211_IFTYPE_UNSPECIFIED:
791 wiphy_warn(wiphy, "%s: kept type as STA\n", dev->name);
792 case NL80211_IFTYPE_STATION: /* This shouldn't happen */
793 return 0;
794 case NL80211_IFTYPE_AP:
795 default:
796 wiphy_err(wiphy, "%s: changing to %d not supported\n",
797 dev->name, type);
798 return -EOPNOTSUPP;
799 }
800 break;
801 case NL80211_IFTYPE_AP:
802 switch (type) {
803 case NL80211_IFTYPE_UNSPECIFIED:
804 wiphy_warn(wiphy, "%s: kept type as AP\n", dev->name);
805 case NL80211_IFTYPE_AP: /* This shouldn't happen */
806 return 0;
807 case NL80211_IFTYPE_ADHOC:
808 case NL80211_IFTYPE_STATION:
809 default:
810 wiphy_err(wiphy, "%s: changing to %d not supported\n",
811 dev->name, type);
812 return -EOPNOTSUPP;
813 }
5e6e3a92 814 break;
e1a2b7a3 815 case NL80211_IFTYPE_P2P_CLIENT:
9197ab9e 816 case NL80211_IFTYPE_P2P_GO:
e1a2b7a3
SP
817 switch (type) {
818 case NL80211_IFTYPE_STATION:
819 if (mwifiex_cfg80211_deinit_p2p(priv))
820 return -EFAULT;
821 dev->ieee80211_ptr->iftype = type;
822 return 0;
823 default:
824 return -EOPNOTSUPP;
825 }
826 break;
5e6e3a92 827 default:
4f02341a
AP
828 wiphy_err(wiphy, "%s: unknown iftype: %d\n",
829 dev->name, dev->ieee80211_ptr->iftype);
830 return -EOPNOTSUPP;
5e6e3a92 831 }
5e6e3a92 832
4f02341a
AP
833 dev->ieee80211_ptr->iftype = type;
834 priv->bss_mode = type;
600f5d90 835 mwifiex_deauthenticate(priv, NULL);
eecd8250 836
f986b6d5 837 priv->sec_info.authentication_mode = NL80211_AUTHTYPE_OPEN_SYSTEM;
eecd8250 838
600f5d90
AK
839 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_SET_BSS_MODE,
840 HostCmd_ACT_GEN_SET, 0, NULL);
eecd8250 841
5e6e3a92
BZ
842 return ret;
843}
844
a5f39056
YAP
845static void
846mwifiex_parse_htinfo(struct mwifiex_private *priv, u8 tx_htinfo,
847 struct rate_info *rate)
848{
849 struct mwifiex_adapter *adapter = priv->adapter;
850
851 if (adapter->is_hw_11ac_capable) {
852 /* bit[1-0]: 00=LG 01=HT 10=VHT */
853 if (tx_htinfo & BIT(0)) {
854 /* HT */
855 rate->mcs = priv->tx_rate;
856 rate->flags |= RATE_INFO_FLAGS_MCS;
857 }
858 if (tx_htinfo & BIT(1)) {
859 /* VHT */
860 rate->mcs = priv->tx_rate & 0x0F;
861 rate->flags |= RATE_INFO_FLAGS_VHT_MCS;
862 }
863
864 if (tx_htinfo & (BIT(1) | BIT(0))) {
865 /* HT or VHT */
866 switch (tx_htinfo & (BIT(3) | BIT(2))) {
867 case 0:
868 /* This will be 20MHz */
869 break;
870 case (BIT(2)):
871 rate->flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
872 break;
873 case (BIT(3)):
874 rate->flags |= RATE_INFO_FLAGS_80_MHZ_WIDTH;
875 break;
876 case (BIT(3) | BIT(2)):
877 rate->flags |= RATE_INFO_FLAGS_160_MHZ_WIDTH;
878 break;
879 }
880
881 if (tx_htinfo & BIT(4))
882 rate->flags |= RATE_INFO_FLAGS_SHORT_GI;
883
884 if ((priv->tx_rate >> 4) == 1)
885 rate->nss = 2;
886 else
887 rate->nss = 1;
888 }
889 } else {
890 /*
891 * Bit 0 in tx_htinfo indicates that current Tx rate
892 * is 11n rate. Valid MCS index values for us are 0 to 15.
893 */
894 if ((tx_htinfo & BIT(0)) && (priv->tx_rate < 16)) {
895 rate->mcs = priv->tx_rate;
896 rate->flags |= RATE_INFO_FLAGS_MCS;
897 if (tx_htinfo & BIT(1))
898 rate->flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
899 if (tx_htinfo & BIT(2))
900 rate->flags |= RATE_INFO_FLAGS_SHORT_GI;
901 }
902 }
903}
904
5e6e3a92
BZ
905/*
906 * This function dumps the station information on a buffer.
907 *
908 * The following information are shown -
909 * - Total bytes transmitted
910 * - Total bytes received
911 * - Total packets transmitted
912 * - Total packets received
913 * - Signal quality level
914 * - Transmission rate
915 */
916static int
917mwifiex_dump_station_info(struct mwifiex_private *priv,
918 struct station_info *sinfo)
919{
006606c0 920 u32 rate;
5e6e3a92
BZ
921
922 sinfo->filled = STATION_INFO_RX_BYTES | STATION_INFO_TX_BYTES |
7013d3e2
AK
923 STATION_INFO_RX_PACKETS | STATION_INFO_TX_PACKETS |
924 STATION_INFO_TX_BITRATE |
925 STATION_INFO_SIGNAL | STATION_INFO_SIGNAL_AVG;
5e6e3a92
BZ
926
927 /* Get signal information from the firmware */
958a4a86
AK
928 if (mwifiex_send_cmd_sync(priv, HostCmd_CMD_RSSI_INFO,
929 HostCmd_ACT_GEN_GET, 0, NULL)) {
930 dev_err(priv->adapter->dev, "failed to get signal information\n");
931 return -EFAULT;
5e6e3a92
BZ
932 }
933
934 if (mwifiex_drv_get_data_rate(priv, &rate)) {
935 dev_err(priv->adapter->dev, "getting data rate\n");
958a4a86 936 return -EFAULT;
5e6e3a92
BZ
937 }
938
caf60a6c
AK
939 /* Get DTIM period information from firmware */
940 mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_SNMP_MIB,
941 HostCmd_ACT_GEN_GET, DTIM_PERIOD_I,
942 &priv->dtim_period);
943
a5f39056 944 mwifiex_parse_htinfo(priv, priv->tx_htinfo, &sinfo->txrate);
4ec6f9c0 945
7013d3e2 946 sinfo->signal_avg = priv->bcn_rssi_avg;
5e6e3a92
BZ
947 sinfo->rx_bytes = priv->stats.rx_bytes;
948 sinfo->tx_bytes = priv->stats.tx_bytes;
949 sinfo->rx_packets = priv->stats.rx_packets;
950 sinfo->tx_packets = priv->stats.tx_packets;
958a4a86 951 sinfo->signal = priv->bcn_rssi_avg;
4ec6f9c0 952 /* bit rate is in 500 kb/s units. Convert it to 100kb/s units */
006606c0 953 sinfo->txrate.legacy = rate * 5;
5e6e3a92 954
c4f3b972
AK
955 if (priv->bss_mode == NL80211_IFTYPE_STATION) {
956 sinfo->filled |= STATION_INFO_BSS_PARAM;
957 sinfo->bss_param.flags = 0;
958 if (priv->curr_bss_params.bss_descriptor.cap_info_bitmap &
959 WLAN_CAPABILITY_SHORT_PREAMBLE)
960 sinfo->bss_param.flags |=
961 BSS_PARAM_FLAGS_SHORT_PREAMBLE;
962 if (priv->curr_bss_params.bss_descriptor.cap_info_bitmap &
963 WLAN_CAPABILITY_SHORT_SLOT_TIME)
964 sinfo->bss_param.flags |=
965 BSS_PARAM_FLAGS_SHORT_SLOT_TIME;
caf60a6c 966 sinfo->bss_param.dtim_period = priv->dtim_period;
c4f3b972
AK
967 sinfo->bss_param.beacon_interval =
968 priv->curr_bss_params.bss_descriptor.beacon_period;
969 }
970
958a4a86 971 return 0;
5e6e3a92
BZ
972}
973
974/*
975 * CFG802.11 operation handler to get station information.
976 *
977 * This function only works in connected mode, and dumps the
978 * requested station information, if available.
979 */
980static int
981mwifiex_cfg80211_get_station(struct wiphy *wiphy, struct net_device *dev,
982 u8 *mac, struct station_info *sinfo)
983{
984 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
5e6e3a92 985
5e6e3a92
BZ
986 if (!priv->media_connected)
987 return -ENOENT;
988 if (memcmp(mac, priv->cfg_bssid, ETH_ALEN))
989 return -ENOENT;
990
636c4598 991 return mwifiex_dump_station_info(priv, sinfo);
5e6e3a92
BZ
992}
993
f85aae6b
AK
994/*
995 * CFG802.11 operation handler to dump station information.
996 */
997static int
998mwifiex_cfg80211_dump_station(struct wiphy *wiphy, struct net_device *dev,
999 int idx, u8 *mac, struct station_info *sinfo)
1000{
1001 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
1002
1003 if (!priv->media_connected || idx)
1004 return -ENOENT;
1005
1006 memcpy(mac, priv->cfg_bssid, ETH_ALEN);
1007
1008 return mwifiex_dump_station_info(priv, sinfo);
1009}
1010
5e6e3a92 1011/* Supported rates to be advertised to the cfg80211 */
5e6e3a92
BZ
1012static struct ieee80211_rate mwifiex_rates[] = {
1013 {.bitrate = 10, .hw_value = 2, },
1014 {.bitrate = 20, .hw_value = 4, },
1015 {.bitrate = 55, .hw_value = 11, },
1016 {.bitrate = 110, .hw_value = 22, },
5e6e3a92
BZ
1017 {.bitrate = 60, .hw_value = 12, },
1018 {.bitrate = 90, .hw_value = 18, },
1019 {.bitrate = 120, .hw_value = 24, },
1020 {.bitrate = 180, .hw_value = 36, },
1021 {.bitrate = 240, .hw_value = 48, },
1022 {.bitrate = 360, .hw_value = 72, },
1023 {.bitrate = 480, .hw_value = 96, },
1024 {.bitrate = 540, .hw_value = 108, },
5e6e3a92
BZ
1025};
1026
1027/* Channel definitions to be advertised to cfg80211 */
5e6e3a92
BZ
1028static struct ieee80211_channel mwifiex_channels_2ghz[] = {
1029 {.center_freq = 2412, .hw_value = 1, },
1030 {.center_freq = 2417, .hw_value = 2, },
1031 {.center_freq = 2422, .hw_value = 3, },
1032 {.center_freq = 2427, .hw_value = 4, },
1033 {.center_freq = 2432, .hw_value = 5, },
1034 {.center_freq = 2437, .hw_value = 6, },
1035 {.center_freq = 2442, .hw_value = 7, },
1036 {.center_freq = 2447, .hw_value = 8, },
1037 {.center_freq = 2452, .hw_value = 9, },
1038 {.center_freq = 2457, .hw_value = 10, },
1039 {.center_freq = 2462, .hw_value = 11, },
1040 {.center_freq = 2467, .hw_value = 12, },
1041 {.center_freq = 2472, .hw_value = 13, },
1042 {.center_freq = 2484, .hw_value = 14, },
1043};
1044
1045static struct ieee80211_supported_band mwifiex_band_2ghz = {
1046 .channels = mwifiex_channels_2ghz,
1047 .n_channels = ARRAY_SIZE(mwifiex_channels_2ghz),
1048 .bitrates = mwifiex_rates,
8763848e 1049 .n_bitrates = ARRAY_SIZE(mwifiex_rates),
5e6e3a92
BZ
1050};
1051
1052static struct ieee80211_channel mwifiex_channels_5ghz[] = {
1053 {.center_freq = 5040, .hw_value = 8, },
1054 {.center_freq = 5060, .hw_value = 12, },
1055 {.center_freq = 5080, .hw_value = 16, },
1056 {.center_freq = 5170, .hw_value = 34, },
1057 {.center_freq = 5190, .hw_value = 38, },
1058 {.center_freq = 5210, .hw_value = 42, },
1059 {.center_freq = 5230, .hw_value = 46, },
1060 {.center_freq = 5180, .hw_value = 36, },
1061 {.center_freq = 5200, .hw_value = 40, },
1062 {.center_freq = 5220, .hw_value = 44, },
1063 {.center_freq = 5240, .hw_value = 48, },
1064 {.center_freq = 5260, .hw_value = 52, },
1065 {.center_freq = 5280, .hw_value = 56, },
1066 {.center_freq = 5300, .hw_value = 60, },
1067 {.center_freq = 5320, .hw_value = 64, },
1068 {.center_freq = 5500, .hw_value = 100, },
1069 {.center_freq = 5520, .hw_value = 104, },
1070 {.center_freq = 5540, .hw_value = 108, },
1071 {.center_freq = 5560, .hw_value = 112, },
1072 {.center_freq = 5580, .hw_value = 116, },
1073 {.center_freq = 5600, .hw_value = 120, },
1074 {.center_freq = 5620, .hw_value = 124, },
1075 {.center_freq = 5640, .hw_value = 128, },
1076 {.center_freq = 5660, .hw_value = 132, },
1077 {.center_freq = 5680, .hw_value = 136, },
1078 {.center_freq = 5700, .hw_value = 140, },
1079 {.center_freq = 5745, .hw_value = 149, },
1080 {.center_freq = 5765, .hw_value = 153, },
1081 {.center_freq = 5785, .hw_value = 157, },
1082 {.center_freq = 5805, .hw_value = 161, },
1083 {.center_freq = 5825, .hw_value = 165, },
1084};
1085
1086static struct ieee80211_supported_band mwifiex_band_5ghz = {
1087 .channels = mwifiex_channels_5ghz,
1088 .n_channels = ARRAY_SIZE(mwifiex_channels_5ghz),
eb416ad3
AP
1089 .bitrates = mwifiex_rates + 4,
1090 .n_bitrates = ARRAY_SIZE(mwifiex_rates) - 4,
5e6e3a92
BZ
1091};
1092
1093
1094/* Supported crypto cipher suits to be advertised to cfg80211 */
5e6e3a92
BZ
1095static const u32 mwifiex_cipher_suites[] = {
1096 WLAN_CIPHER_SUITE_WEP40,
1097 WLAN_CIPHER_SUITE_WEP104,
1098 WLAN_CIPHER_SUITE_TKIP,
1099 WLAN_CIPHER_SUITE_CCMP,
53b11231 1100 WLAN_CIPHER_SUITE_AES_CMAC,
5e6e3a92
BZ
1101};
1102
83719be8
SP
1103/* Supported mgmt frame types to be advertised to cfg80211 */
1104static const struct ieee80211_txrx_stypes
1105mwifiex_mgmt_stypes[NUM_NL80211_IFTYPES] = {
1106 [NL80211_IFTYPE_STATION] = {
1107 .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
1108 BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
1109 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
1110 BIT(IEEE80211_STYPE_PROBE_REQ >> 4),
1111 },
1112 [NL80211_IFTYPE_AP] = {
1113 .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
1114 BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
1115 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
1116 BIT(IEEE80211_STYPE_PROBE_REQ >> 4),
1117 },
1118 [NL80211_IFTYPE_P2P_CLIENT] = {
1119 .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
1120 BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
1121 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
1122 BIT(IEEE80211_STYPE_PROBE_REQ >> 4),
1123 },
1124 [NL80211_IFTYPE_P2P_GO] = {
1125 .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
1126 BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
1127 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
1128 BIT(IEEE80211_STYPE_PROBE_REQ >> 4),
1129 },
1130};
1131
5d82c53a
YAP
1132/*
1133 * CFG802.11 operation handler for setting bit rates.
1134 *
433c3990
AK
1135 * Function configures data rates to firmware using bitrate mask
1136 * provided by cfg80211.
5d82c53a
YAP
1137 */
1138static int mwifiex_cfg80211_set_bitrate_mask(struct wiphy *wiphy,
1139 struct net_device *dev,
1140 const u8 *peer,
1141 const struct cfg80211_bitrate_mask *mask)
1142{
5d82c53a 1143 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
433c3990
AK
1144 u16 bitmap_rates[MAX_BITMAP_RATES_SIZE];
1145 enum ieee80211_band band;
5d82c53a 1146
433c3990
AK
1147 if (!priv->media_connected) {
1148 dev_err(priv->adapter->dev,
1149 "Can not set Tx data rate in disconnected state\n");
1150 return -EINVAL;
5d82c53a
YAP
1151 }
1152
433c3990 1153 band = mwifiex_band_to_radio_type(priv->curr_bss_params.band);
5d82c53a 1154
433c3990 1155 memset(bitmap_rates, 0, sizeof(bitmap_rates));
5d82c53a 1156
433c3990
AK
1157 /* Fill HR/DSSS rates. */
1158 if (band == IEEE80211_BAND_2GHZ)
1159 bitmap_rates[0] = mask->control[band].legacy & 0x000f;
5d82c53a 1160
433c3990
AK
1161 /* Fill OFDM rates */
1162 if (band == IEEE80211_BAND_2GHZ)
1163 bitmap_rates[1] = (mask->control[band].legacy & 0x0ff0) >> 4;
1164 else
1165 bitmap_rates[1] = mask->control[band].legacy;
1166
1167 /* Fill MCS rates */
1168 bitmap_rates[2] = mask->control[band].mcs[0];
1169 if (priv->adapter->hw_dev_mcs_support == HT_STREAM_2X2)
1170 bitmap_rates[2] |= mask->control[band].mcs[1] << 8;
1171
1172 return mwifiex_send_cmd_sync(priv, HostCmd_CMD_TX_RATE_CFG,
1173 HostCmd_ACT_GEN_SET, 0, bitmap_rates);
5d82c53a
YAP
1174}
1175
fa444bf8
AK
1176/*
1177 * CFG802.11 operation handler for connection quality monitoring.
1178 *
1179 * This function subscribes/unsubscribes HIGH_RSSI and LOW_RSSI
1180 * events to FW.
1181 */
1182static int mwifiex_cfg80211_set_cqm_rssi_config(struct wiphy *wiphy,
1183 struct net_device *dev,
1184 s32 rssi_thold, u32 rssi_hyst)
1185{
1186 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
1187 struct mwifiex_ds_misc_subsc_evt subsc_evt;
1188
1189 priv->cqm_rssi_thold = rssi_thold;
1190 priv->cqm_rssi_hyst = rssi_hyst;
1191
1192 memset(&subsc_evt, 0x00, sizeof(struct mwifiex_ds_misc_subsc_evt));
1193 subsc_evt.events = BITMASK_BCN_RSSI_LOW | BITMASK_BCN_RSSI_HIGH;
1194
1195 /* Subscribe/unsubscribe low and high rssi events */
1196 if (rssi_thold && rssi_hyst) {
1197 subsc_evt.action = HostCmd_ACT_BITWISE_SET;
1198 subsc_evt.bcn_l_rssi_cfg.abs_value = abs(rssi_thold);
1199 subsc_evt.bcn_h_rssi_cfg.abs_value = abs(rssi_thold);
1200 subsc_evt.bcn_l_rssi_cfg.evt_freq = 1;
1201 subsc_evt.bcn_h_rssi_cfg.evt_freq = 1;
1202 return mwifiex_send_cmd_sync(priv,
1203 HostCmd_CMD_802_11_SUBSCRIBE_EVENT,
1204 0, 0, &subsc_evt);
1205 } else {
1206 subsc_evt.action = HostCmd_ACT_BITWISE_CLR;
1207 return mwifiex_send_cmd_sync(priv,
1208 HostCmd_CMD_802_11_SUBSCRIBE_EVENT,
1209 0, 0, &subsc_evt);
1210 }
1211
1212 return 0;
1213}
1214
5370c836
AP
1215/* cfg80211 operation handler for change_beacon.
1216 * Function retrieves and sets modified management IEs to FW.
1217 */
1218static int mwifiex_cfg80211_change_beacon(struct wiphy *wiphy,
1219 struct net_device *dev,
1220 struct cfg80211_beacon_data *data)
1221{
1222 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
1223
9197ab9e 1224 if (GET_BSS_ROLE(priv) != MWIFIEX_BSS_ROLE_UAP) {
5370c836
AP
1225 wiphy_err(wiphy, "%s: bss_type mismatched\n", __func__);
1226 return -EINVAL;
1227 }
1228
1229 if (!priv->bss_started) {
1230 wiphy_err(wiphy, "%s: bss not started\n", __func__);
1231 return -EINVAL;
1232 }
1233
1234 if (mwifiex_set_mgmt_ies(priv, data)) {
1235 wiphy_err(wiphy, "%s: setting mgmt ies failed\n", __func__);
1236 return -EFAULT;
1237 }
1238
1239 return 0;
1240}
1241
0f9e9b8b
AP
1242/* cfg80211 operation handler for del_station.
1243 * Function deauthenticates station which value is provided in mac parameter.
1244 * If mac is NULL/broadcast, all stations in associated station list are
1245 * deauthenticated. If bss is not started or there are no stations in
1246 * associated stations list, no action is taken.
1247 */
1248static int
1249mwifiex_cfg80211_del_station(struct wiphy *wiphy, struct net_device *dev,
1250 u8 *mac)
1251{
1252 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
1253 struct mwifiex_sta_node *sta_node;
1254 unsigned long flags;
1255
1256 if (list_empty(&priv->sta_list) || !priv->bss_started)
1257 return 0;
1258
1259 if (!mac || is_broadcast_ether_addr(mac)) {
1260 wiphy_dbg(wiphy, "%s: NULL/broadcast mac address\n", __func__);
1261 list_for_each_entry(sta_node, &priv->sta_list, list) {
1262 if (mwifiex_send_cmd_sync(priv,
1263 HostCmd_CMD_UAP_STA_DEAUTH,
1264 HostCmd_ACT_GEN_SET, 0,
1265 sta_node->mac_addr))
1266 return -1;
1267 mwifiex_uap_del_sta_data(priv, sta_node);
1268 }
1269 } else {
1270 wiphy_dbg(wiphy, "%s: mac address %pM\n", __func__, mac);
1271 spin_lock_irqsave(&priv->sta_list_spinlock, flags);
1272 sta_node = mwifiex_get_sta_entry(priv, mac);
1273 spin_unlock_irqrestore(&priv->sta_list_spinlock, flags);
1274 if (sta_node) {
1275 if (mwifiex_send_cmd_sync(priv,
1276 HostCmd_CMD_UAP_STA_DEAUTH,
1277 HostCmd_ACT_GEN_SET, 0,
1278 sta_node->mac_addr))
1279 return -1;
1280 mwifiex_uap_del_sta_data(priv, sta_node);
1281 }
1282 }
1283
1284 return 0;
1285}
1286
8a279d5b
AK
1287static int
1288mwifiex_cfg80211_set_antenna(struct wiphy *wiphy, u32 tx_ant, u32 rx_ant)
1289{
1290 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
1291 struct mwifiex_private *priv = mwifiex_get_priv(adapter,
1292 MWIFIEX_BSS_ROLE_ANY);
1293 struct mwifiex_ds_ant_cfg ant_cfg;
1294
1295 if (!tx_ant || !rx_ant)
1296 return -EOPNOTSUPP;
1297
1298 if (adapter->hw_dev_mcs_support != HT_STREAM_2X2) {
1299 /* Not a MIMO chip. User should provide specific antenna number
1300 * for Tx/Rx path or enable all antennas for diversity
1301 */
1302 if (tx_ant != rx_ant)
1303 return -EOPNOTSUPP;
1304
1305 if ((tx_ant & (tx_ant - 1)) &&
1306 (tx_ant != BIT(adapter->number_of_antenna) - 1))
1307 return -EOPNOTSUPP;
1308
1309 if ((tx_ant == BIT(adapter->number_of_antenna) - 1) &&
1310 (priv->adapter->number_of_antenna > 1)) {
1311 tx_ant = RF_ANTENNA_AUTO;
1312 rx_ant = RF_ANTENNA_AUTO;
1313 }
1314 }
1315
1316 ant_cfg.tx_ant = tx_ant;
1317 ant_cfg.rx_ant = rx_ant;
1318
1319 return mwifiex_send_cmd_sync(priv, HostCmd_CMD_RF_ANTENNA,
1320 HostCmd_ACT_GEN_SET, 0, &ant_cfg);
1321}
1322
12190c5d
AP
1323/* cfg80211 operation handler for stop ap.
1324 * Function stops BSS running at uAP interface.
1325 */
1326static int mwifiex_cfg80211_stop_ap(struct wiphy *wiphy, struct net_device *dev)
1327{
1328 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
1329
40bbc21a
AP
1330 if (mwifiex_del_mgmt_ies(priv))
1331 wiphy_err(wiphy, "Failed to delete mgmt IEs!\n");
1332
c8258913
AP
1333 priv->ap_11n_enabled = 0;
1334
12190c5d
AP
1335 if (mwifiex_send_cmd_sync(priv, HostCmd_CMD_UAP_BSS_STOP,
1336 HostCmd_ACT_GEN_SET, 0, NULL)) {
1337 wiphy_err(wiphy, "Failed to stop the BSS\n");
1338 return -1;
1339 }
1340
1341 return 0;
1342}
1343
1344/* cfg80211 operation handler for start_ap.
1345 * Function sets beacon period, DTIM period, SSID and security into
1346 * AP config structure.
1347 * AP is configured with these settings and BSS is started.
1348 */
1349static int mwifiex_cfg80211_start_ap(struct wiphy *wiphy,
1350 struct net_device *dev,
1351 struct cfg80211_ap_settings *params)
1352{
1353 struct mwifiex_uap_bss_param *bss_cfg;
1354 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
05910f4a 1355 u8 config_bands = 0;
12190c5d 1356
9197ab9e 1357 if (GET_BSS_ROLE(priv) != MWIFIEX_BSS_ROLE_UAP)
f752dcd5 1358 return -1;
adb6ed0c 1359 if (mwifiex_set_mgmt_ies(priv, &params->beacon))
f31acabe 1360 return -1;
f752dcd5 1361
12190c5d
AP
1362 bss_cfg = kzalloc(sizeof(struct mwifiex_uap_bss_param), GFP_KERNEL);
1363 if (!bss_cfg)
1364 return -ENOMEM;
1365
1366 mwifiex_set_sys_config_invalid_data(bss_cfg);
1367
1368 if (params->beacon_interval)
1369 bss_cfg->beacon_period = params->beacon_interval;
1370 if (params->dtim_period)
1371 bss_cfg->dtim_period = params->dtim_period;
1372
1373 if (params->ssid && params->ssid_len) {
1374 memcpy(bss_cfg->ssid.ssid, params->ssid, params->ssid_len);
1375 bss_cfg->ssid.ssid_len = params->ssid_len;
1376 }
1377
7a1c9934
AP
1378 switch (params->hidden_ssid) {
1379 case NL80211_HIDDEN_SSID_NOT_IN_USE:
1380 bss_cfg->bcast_ssid_ctl = 1;
1381 break;
1382 case NL80211_HIDDEN_SSID_ZERO_LEN:
1383 bss_cfg->bcast_ssid_ctl = 0;
1384 break;
1385 case NL80211_HIDDEN_SSID_ZERO_CONTENTS:
1386 /* firmware doesn't support this type of hidden SSID */
1387 default:
b3190466 1388 kfree(bss_cfg);
7a1c9934
AP
1389 return -EINVAL;
1390 }
1391
683b6d3b
JB
1392 bss_cfg->channel = ieee80211_frequency_to_channel(
1393 params->chandef.chan->center_freq);
0abd79e5 1394
05910f4a 1395 /* Set appropriate bands */
683b6d3b 1396 if (params->chandef.chan->band == IEEE80211_BAND_2GHZ) {
a3c2c4f6 1397 bss_cfg->band_cfg = BAND_CONFIG_BG;
a5f39056 1398 config_bands = BAND_B | BAND_G;
a3c2c4f6 1399
a5f39056
YAP
1400 if (params->chandef.width > NL80211_CHAN_WIDTH_20_NOHT)
1401 config_bands |= BAND_GN;
1402
1403 if (params->chandef.width > NL80211_CHAN_WIDTH_40)
1404 config_bands |= BAND_GAC;
05910f4a 1405 } else {
a3c2c4f6 1406 bss_cfg->band_cfg = BAND_CONFIG_A;
a5f39056 1407 config_bands = BAND_A;
a3c2c4f6 1408
a5f39056
YAP
1409 if (params->chandef.width > NL80211_CHAN_WIDTH_20_NOHT)
1410 config_bands |= BAND_AN;
1411
1412 if (params->chandef.width > NL80211_CHAN_WIDTH_40)
1413 config_bands |= BAND_AAC;
0abd79e5
AP
1414 }
1415
05910f4a
AK
1416 if (!((config_bands | priv->adapter->fw_bands) &
1417 ~priv->adapter->fw_bands))
1418 priv->adapter->config_bands = config_bands;
1419
a3c2c4f6 1420 mwifiex_set_uap_rates(bss_cfg, params);
05910f4a
AK
1421 mwifiex_send_domain_info_cmd_fw(wiphy);
1422
f752dcd5
AP
1423 if (mwifiex_set_secure_params(priv, bss_cfg, params)) {
1424 kfree(bss_cfg);
1425 wiphy_err(wiphy, "Failed to parse secuirty parameters!\n");
1426 return -1;
1427 }
1428
22281256 1429 mwifiex_set_ht_params(priv, bss_cfg, params);
83c78da9
YAP
1430
1431 if (priv->adapter->is_hw_11ac_capable) {
1432 mwifiex_set_vht_params(priv, bss_cfg, params);
1433 mwifiex_set_vht_width(priv, params->chandef.width,
1434 priv->ap_11ac_enabled);
1435 }
1436
2b6254da
AP
1437 if (priv->ap_11ac_enabled)
1438 mwifiex_set_11ac_ba_params(priv);
1439 else
1440 mwifiex_set_ba_params(priv);
1441
54428c57 1442 mwifiex_set_wmm_params(priv, bss_cfg, params);
22281256 1443
8b4509f6
KG
1444 if (params->inactivity_timeout > 0) {
1445 /* sta_ao_timer/ps_sta_ao_timer is in unit of 100ms */
1446 bss_cfg->sta_ao_timer = 10 * params->inactivity_timeout;
1447 bss_cfg->ps_sta_ao_timer = 10 * params->inactivity_timeout;
1448 }
1449
12190c5d
AP
1450 if (mwifiex_send_cmd_sync(priv, HostCmd_CMD_UAP_BSS_STOP,
1451 HostCmd_ACT_GEN_SET, 0, NULL)) {
1452 wiphy_err(wiphy, "Failed to stop the BSS\n");
1453 kfree(bss_cfg);
1454 return -1;
1455 }
1456
1457 if (mwifiex_send_cmd_async(priv, HostCmd_CMD_UAP_SYS_CONFIG,
e76268da
AP
1458 HostCmd_ACT_GEN_SET,
1459 UAP_BSS_PARAMS_I, bss_cfg)) {
12190c5d
AP
1460 wiphy_err(wiphy, "Failed to set the SSID\n");
1461 kfree(bss_cfg);
1462 return -1;
1463 }
1464
1465 kfree(bss_cfg);
1466
1467 if (mwifiex_send_cmd_async(priv, HostCmd_CMD_UAP_BSS_START,
1468 HostCmd_ACT_GEN_SET, 0, NULL)) {
1469 wiphy_err(wiphy, "Failed to start the BSS\n");
1470 return -1;
1471 }
1472
96893538
AP
1473 if (priv->sec_info.wep_enabled)
1474 priv->curr_pkt_filter |= HostCmd_ACT_MAC_WEP_ENABLE;
1475 else
1476 priv->curr_pkt_filter &= ~HostCmd_ACT_MAC_WEP_ENABLE;
1477
1478 if (mwifiex_send_cmd_sync(priv, HostCmd_CMD_MAC_CONTROL,
1479 HostCmd_ACT_GEN_SET, 0,
1480 &priv->curr_pkt_filter))
1481 return -1;
1482
12190c5d
AP
1483 return 0;
1484}
1485
5e6e3a92
BZ
1486/*
1487 * CFG802.11 operation handler for disconnection request.
1488 *
1489 * This function does not work when there is already a disconnection
1490 * procedure going on.
1491 */
1492static int
1493mwifiex_cfg80211_disconnect(struct wiphy *wiphy, struct net_device *dev,
1494 u16 reason_code)
1495{
1496 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
1497
600f5d90 1498 if (mwifiex_deauthenticate(priv, NULL))
5e6e3a92
BZ
1499 return -EFAULT;
1500
1501 wiphy_dbg(wiphy, "info: successfully disconnected from %pM:"
1502 " reason code %d\n", priv->cfg_bssid, reason_code);
1503
38c9d664 1504 memset(priv->cfg_bssid, 0, ETH_ALEN);
5e6e3a92
BZ
1505
1506 return 0;
1507}
1508
1509/*
1510 * This function informs the CFG802.11 subsystem of a new IBSS.
1511 *
1512 * The following information are sent to the CFG802.11 subsystem
1513 * to register the new IBSS. If we do not register the new IBSS,
1514 * a kernel panic will result.
1515 * - SSID
1516 * - SSID length
1517 * - BSSID
1518 * - Channel
1519 */
1520static int mwifiex_cfg80211_inform_ibss_bss(struct mwifiex_private *priv)
1521{
5e6e3a92
BZ
1522 struct ieee80211_channel *chan;
1523 struct mwifiex_bss_info bss_info;
aa95a48d 1524 struct cfg80211_bss *bss;
270e58e8 1525 int ie_len;
5e6e3a92 1526 u8 ie_buf[IEEE80211_MAX_SSID_LEN + sizeof(struct ieee_types_header)];
4ed5d521 1527 enum ieee80211_band band;
5e6e3a92 1528
636c4598
YAP
1529 if (mwifiex_get_bss_info(priv, &bss_info))
1530 return -1;
5e6e3a92
BZ
1531
1532 ie_buf[0] = WLAN_EID_SSID;
1533 ie_buf[1] = bss_info.ssid.ssid_len;
1534
1535 memcpy(&ie_buf[sizeof(struct ieee_types_header)],
aea0701e 1536 &bss_info.ssid.ssid, bss_info.ssid.ssid_len);
5e6e3a92
BZ
1537 ie_len = ie_buf[1] + sizeof(struct ieee_types_header);
1538
4ed5d521 1539 band = mwifiex_band_to_radio_type(priv->curr_bss_params.band);
5e6e3a92
BZ
1540 chan = __ieee80211_get_channel(priv->wdev->wiphy,
1541 ieee80211_channel_to_frequency(bss_info.bss_chan,
4ed5d521 1542 band));
5e6e3a92 1543
aa95a48d 1544 bss = cfg80211_inform_bss(priv->wdev->wiphy, chan,
aea0701e
YAP
1545 bss_info.bssid, 0, WLAN_CAPABILITY_IBSS,
1546 0, ie_buf, ie_len, 0, GFP_KERNEL);
5b112d3d 1547 cfg80211_put_bss(priv->wdev->wiphy, bss);
5e6e3a92
BZ
1548 memcpy(priv->cfg_bssid, bss_info.bssid, ETH_ALEN);
1549
636c4598 1550 return 0;
5e6e3a92
BZ
1551}
1552
5e6e3a92
BZ
1553/*
1554 * This function connects with a BSS.
1555 *
1556 * This function handles both Infra and Ad-Hoc modes. It also performs
1557 * validity checking on the provided parameters, disconnects from the
1558 * current BSS (if any), sets up the association/scan parameters,
1559 * including security settings, and performs specific SSID scan before
1560 * trying to connect.
1561 *
1562 * For Infra mode, the function returns failure if the specified SSID
1563 * is not found in scan table. However, for Ad-Hoc mode, it can create
1564 * the IBSS if it does not exist. On successful completion in either case,
7c6fa2a8 1565 * the function notifies the CFG802.11 subsystem of the new BSS connection.
5e6e3a92
BZ
1566 */
1567static int
1568mwifiex_cfg80211_assoc(struct mwifiex_private *priv, size_t ssid_len, u8 *ssid,
1569 u8 *bssid, int mode, struct ieee80211_channel *channel,
1570 struct cfg80211_connect_params *sme, bool privacy)
1571{
b9be5f39 1572 struct cfg80211_ssid req_ssid;
270e58e8 1573 int ret, auth_type = 0;
7c6fa2a8 1574 struct cfg80211_bss *bss = NULL;
d7b9c520 1575 u8 is_scanning_required = 0;
5e6e3a92 1576
b9be5f39 1577 memset(&req_ssid, 0, sizeof(struct cfg80211_ssid));
5e6e3a92
BZ
1578
1579 req_ssid.ssid_len = ssid_len;
1580 if (ssid_len > IEEE80211_MAX_SSID_LEN) {
1581 dev_err(priv->adapter->dev, "invalid SSID - aborting\n");
1582 return -EINVAL;
1583 }
1584
1585 memcpy(req_ssid.ssid, ssid, ssid_len);
1586 if (!req_ssid.ssid_len || req_ssid.ssid[0] < 0x20) {
1587 dev_err(priv->adapter->dev, "invalid SSID - aborting\n");
1588 return -EINVAL;
1589 }
1590
1591 /* disconnect before try to associate */
600f5d90 1592 mwifiex_deauthenticate(priv, NULL);
5e6e3a92 1593
6670f15b
AK
1594 /* As this is new association, clear locally stored
1595 * keys and security related flags */
1596 priv->sec_info.wpa_enabled = false;
1597 priv->sec_info.wpa2_enabled = false;
1598 priv->wep_key_curr_index = 0;
00f157b4 1599 priv->sec_info.encryption_mode = 0;
a0f6d6ca 1600 priv->sec_info.is_authtype_auto = 0;
53b11231 1601 ret = mwifiex_set_encode(priv, NULL, NULL, 0, 0, NULL, 1);
5e6e3a92 1602
eecd8250 1603 if (mode == NL80211_IFTYPE_ADHOC) {
5e6e3a92
BZ
1604 /* "privacy" is set only for ad-hoc mode */
1605 if (privacy) {
1606 /*
2be50b8d 1607 * Keep WLAN_CIPHER_SUITE_WEP104 for now so that
5e6e3a92
BZ
1608 * the firmware can find a matching network from the
1609 * scan. The cfg80211 does not give us the encryption
1610 * mode at this stage so just setting it to WEP here.
1611 */
203afeca 1612 priv->sec_info.encryption_mode =
2be50b8d 1613 WLAN_CIPHER_SUITE_WEP104;
203afeca 1614 priv->sec_info.authentication_mode =
f986b6d5 1615 NL80211_AUTHTYPE_OPEN_SYSTEM;
5e6e3a92
BZ
1616 }
1617
1618 goto done;
1619 }
1620
1621 /* Now handle infra mode. "sme" is valid for infra mode only */
a0f6d6ca 1622 if (sme->auth_type == NL80211_AUTHTYPE_AUTOMATIC) {
f986b6d5 1623 auth_type = NL80211_AUTHTYPE_OPEN_SYSTEM;
a0f6d6ca
AK
1624 priv->sec_info.is_authtype_auto = 1;
1625 } else {
1626 auth_type = sme->auth_type;
1627 }
5e6e3a92
BZ
1628
1629 if (sme->crypto.n_ciphers_pairwise) {
2be50b8d
YAP
1630 priv->sec_info.encryption_mode =
1631 sme->crypto.ciphers_pairwise[0];
203afeca 1632 priv->sec_info.authentication_mode = auth_type;
5e6e3a92
BZ
1633 }
1634
1635 if (sme->crypto.cipher_group) {
2be50b8d 1636 priv->sec_info.encryption_mode = sme->crypto.cipher_group;
203afeca 1637 priv->sec_info.authentication_mode = auth_type;
5e6e3a92
BZ
1638 }
1639 if (sme->ie)
1640 ret = mwifiex_set_gen_ie(priv, sme->ie, sme->ie_len);
1641
1642 if (sme->key) {
e6faada5 1643 if (mwifiex_is_alg_wep(priv->sec_info.encryption_mode)) {
5e6e3a92
BZ
1644 dev_dbg(priv->adapter->dev,
1645 "info: setting wep encryption"
1646 " with key len %d\n", sme->key_len);
6670f15b 1647 priv->wep_key_curr_index = sme->key_idx;
53b11231
YL
1648 ret = mwifiex_set_encode(priv, NULL, sme->key,
1649 sme->key_len, sme->key_idx,
1650 NULL, 0);
5e6e3a92
BZ
1651 }
1652 }
1653done:
7c6fa2a8
AK
1654 /*
1655 * Scan entries are valid for some time (15 sec). So we can save one
1656 * active scan time if we just try cfg80211_get_bss first. If it fails
1657 * then request scan and cfg80211_get_bss() again for final output.
1658 */
1659 while (1) {
1660 if (is_scanning_required) {
1661 /* Do specific SSID scanning */
1662 if (mwifiex_request_scan(priv, &req_ssid)) {
1663 dev_err(priv->adapter->dev, "scan error\n");
1664 return -EFAULT;
1665 }
1666 }
5e6e3a92 1667
7c6fa2a8
AK
1668 /* Find the BSS we want using available scan results */
1669 if (mode == NL80211_IFTYPE_ADHOC)
1670 bss = cfg80211_get_bss(priv->wdev->wiphy, channel,
1671 bssid, ssid, ssid_len,
1672 WLAN_CAPABILITY_IBSS,
1673 WLAN_CAPABILITY_IBSS);
1674 else
1675 bss = cfg80211_get_bss(priv->wdev->wiphy, channel,
1676 bssid, ssid, ssid_len,
1677 WLAN_CAPABILITY_ESS,
1678 WLAN_CAPABILITY_ESS);
1679
1680 if (!bss) {
1681 if (is_scanning_required) {
aea0701e
YAP
1682 dev_warn(priv->adapter->dev,
1683 "assoc: requested bss not found in scan results\n");
7c6fa2a8
AK
1684 break;
1685 }
1686 is_scanning_required = 1;
1687 } else {
aea0701e
YAP
1688 dev_dbg(priv->adapter->dev,
1689 "info: trying to associate to '%s' bssid %pM\n",
1690 (char *) req_ssid.ssid, bss->bssid);
7c6fa2a8
AK
1691 memcpy(&priv->cfg_bssid, bss->bssid, ETH_ALEN);
1692 break;
1693 }
5e6e3a92
BZ
1694 }
1695
06975884
AK
1696 ret = mwifiex_bss_start(priv, bss, &req_ssid);
1697 if (ret)
1698 return ret;
5e6e3a92 1699
eecd8250 1700 if (mode == NL80211_IFTYPE_ADHOC) {
5e6e3a92
BZ
1701 /* Inform the BSS information to kernel, otherwise
1702 * kernel will give a panic after successful assoc */
1703 if (mwifiex_cfg80211_inform_ibss_bss(priv))
1704 return -EFAULT;
1705 }
1706
1707 return ret;
1708}
1709
1710/*
1711 * CFG802.11 operation handler for association request.
1712 *
1713 * This function does not work when the current mode is set to Ad-Hoc, or
1714 * when there is already an association procedure going on. The given BSS
1715 * information is used to associate.
1716 */
1717static int
1718mwifiex_cfg80211_connect(struct wiphy *wiphy, struct net_device *dev,
1719 struct cfg80211_connect_params *sme)
1720{
1721 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
8bc77a4d 1722 int ret;
5e6e3a92 1723
8bc77a4d
BZ
1724 if (priv->bss_mode != NL80211_IFTYPE_STATION) {
1725 wiphy_err(wiphy,
1726 "%s: reject infra assoc request in non-STA mode\n",
1727 dev->name);
1728 return -EINVAL;
e568634a
AP
1729 }
1730
5e6e3a92 1731 wiphy_dbg(wiphy, "info: Trying to associate to %s and bssid %pM\n",
aea0701e 1732 (char *) sme->ssid, sme->bssid);
5e6e3a92
BZ
1733
1734 ret = mwifiex_cfg80211_assoc(priv, sme->ssid_len, sme->ssid, sme->bssid,
eecd8250 1735 priv->bss_mode, sme->channel, sme, 0);
38c9d664
AK
1736 if (!ret) {
1737 cfg80211_connect_result(priv->netdev, priv->cfg_bssid, NULL, 0,
1738 NULL, 0, WLAN_STATUS_SUCCESS,
1739 GFP_KERNEL);
1740 dev_dbg(priv->adapter->dev,
1741 "info: associated to bssid %pM successfully\n",
1742 priv->cfg_bssid);
1743 } else {
1744 dev_dbg(priv->adapter->dev,
1745 "info: association to bssid %pM failed\n",
1746 priv->cfg_bssid);
1747 memset(priv->cfg_bssid, 0, ETH_ALEN);
06975884
AK
1748
1749 if (ret > 0)
1750 cfg80211_connect_result(priv->netdev, priv->cfg_bssid,
1751 NULL, 0, NULL, 0, ret,
1752 GFP_KERNEL);
1753 else
1754 cfg80211_connect_result(priv->netdev, priv->cfg_bssid,
1755 NULL, 0, NULL, 0,
1756 WLAN_STATUS_UNSPECIFIED_FAILURE,
1757 GFP_KERNEL);
38c9d664
AK
1758 }
1759
06975884 1760 return 0;
5e6e3a92
BZ
1761}
1762
05910f4a
AK
1763/*
1764 * This function sets following parameters for ibss network.
1765 * - channel
1766 * - start band
1767 * - 11n flag
1768 * - secondary channel offset
1769 */
1770static int mwifiex_set_ibss_params(struct mwifiex_private *priv,
1771 struct cfg80211_ibss_params *params)
1772{
1773 struct wiphy *wiphy = priv->wdev->wiphy;
1774 struct mwifiex_adapter *adapter = priv->adapter;
1775 int index = 0, i;
1776 u8 config_bands = 0;
1777
683b6d3b 1778 if (params->chandef.chan->band == IEEE80211_BAND_2GHZ) {
05910f4a
AK
1779 if (!params->basic_rates) {
1780 config_bands = BAND_B | BAND_G;
1781 } else {
1782 for (i = 0; i < mwifiex_band_2ghz.n_bitrates; i++) {
1783 /*
1784 * Rates below 6 Mbps in the table are CCK
1785 * rates; 802.11b and from 6 they are OFDM;
1786 * 802.11G
1787 */
1788 if (mwifiex_rates[i].bitrate == 60) {
1789 index = 1 << i;
1790 break;
1791 }
1792 }
1793
1794 if (params->basic_rates < index) {
1795 config_bands = BAND_B;
1796 } else {
1797 config_bands = BAND_G;
1798 if (params->basic_rates % index)
1799 config_bands |= BAND_B;
1800 }
1801 }
1802
683b6d3b
JB
1803 if (cfg80211_get_chandef_type(&params->chandef) !=
1804 NL80211_CHAN_NO_HT)
3b86acb8 1805 config_bands |= BAND_G | BAND_GN;
05910f4a 1806 } else {
c3ff0b2d 1807 if (cfg80211_get_chandef_type(&params->chandef) ==
683b6d3b 1808 NL80211_CHAN_NO_HT)
05910f4a
AK
1809 config_bands = BAND_A;
1810 else
1811 config_bands = BAND_AN | BAND_A;
1812 }
1813
1814 if (!((config_bands | adapter->fw_bands) & ~adapter->fw_bands)) {
1815 adapter->config_bands = config_bands;
1816 adapter->adhoc_start_band = config_bands;
1817
1818 if ((config_bands & BAND_GN) || (config_bands & BAND_AN))
1819 adapter->adhoc_11n_enabled = true;
1820 else
1821 adapter->adhoc_11n_enabled = false;
1822 }
1823
1824 adapter->sec_chan_offset =
683b6d3b
JB
1825 mwifiex_chan_type_to_sec_chan_offset(
1826 cfg80211_get_chandef_type(&params->chandef));
1827 priv->adhoc_channel = ieee80211_frequency_to_channel(
1828 params->chandef.chan->center_freq);
05910f4a
AK
1829
1830 wiphy_dbg(wiphy, "info: set ibss band %d, chan %d, chan offset %d\n",
1831 config_bands, priv->adhoc_channel, adapter->sec_chan_offset);
1832
1833 return 0;
1834}
1835
5e6e3a92
BZ
1836/*
1837 * CFG802.11 operation handler to join an IBSS.
1838 *
1839 * This function does not work in any mode other than Ad-Hoc, or if
1840 * a join operation is already in progress.
1841 */
1842static int
1843mwifiex_cfg80211_join_ibss(struct wiphy *wiphy, struct net_device *dev,
1844 struct cfg80211_ibss_params *params)
1845{
f540f9f3 1846 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
5e6e3a92 1847 int ret = 0;
5e6e3a92 1848
eecd8250 1849 if (priv->bss_mode != NL80211_IFTYPE_ADHOC) {
5e6e3a92
BZ
1850 wiphy_err(wiphy, "request to join ibss received "
1851 "when station is not in ibss mode\n");
1852 goto done;
1853 }
1854
5e6e3a92 1855 wiphy_dbg(wiphy, "info: trying to join to %s and bssid %pM\n",
aea0701e 1856 (char *) params->ssid, params->bssid);
5e6e3a92 1857
05910f4a
AK
1858 mwifiex_set_ibss_params(priv, params);
1859
5e6e3a92 1860 ret = mwifiex_cfg80211_assoc(priv, params->ssid_len, params->ssid,
aea0701e 1861 params->bssid, priv->bss_mode,
683b6d3b
JB
1862 params->chandef.chan, NULL,
1863 params->privacy);
5e6e3a92 1864done:
38c9d664
AK
1865 if (!ret) {
1866 cfg80211_ibss_joined(priv->netdev, priv->cfg_bssid, GFP_KERNEL);
1867 dev_dbg(priv->adapter->dev,
1868 "info: joined/created adhoc network with bssid"
1869 " %pM successfully\n", priv->cfg_bssid);
1870 } else {
1871 dev_dbg(priv->adapter->dev,
1872 "info: failed creating/joining adhoc network\n");
1873 }
1874
5e6e3a92
BZ
1875 return ret;
1876}
1877
1878/*
1879 * CFG802.11 operation handler to leave an IBSS.
1880 *
1881 * This function does not work if a leave operation is
1882 * already in progress.
1883 */
1884static int
1885mwifiex_cfg80211_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
1886{
f540f9f3 1887 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
5e6e3a92 1888
5e6e3a92 1889 wiphy_dbg(wiphy, "info: disconnecting from essid %pM\n",
aea0701e 1890 priv->cfg_bssid);
600f5d90 1891 if (mwifiex_deauthenticate(priv, NULL))
5e6e3a92
BZ
1892 return -EFAULT;
1893
38c9d664 1894 memset(priv->cfg_bssid, 0, ETH_ALEN);
5e6e3a92
BZ
1895
1896 return 0;
1897}
1898
1899/*
1900 * CFG802.11 operation handler for scan request.
1901 *
1902 * This function issues a scan request to the firmware based upon
1903 * the user specified scan configuration. On successfull completion,
1904 * it also informs the results.
1905 */
1906static int
fd014284 1907mwifiex_cfg80211_scan(struct wiphy *wiphy,
5e6e3a92
BZ
1908 struct cfg80211_scan_request *request)
1909{
fd014284 1910 struct net_device *dev = request->wdev->netdev;
5e6e3a92 1911 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
c2476335 1912 int i, offset, ret;
38c9d664 1913 struct ieee80211_channel *chan;
ea021f56 1914 struct ieee_types_header *ie;
75ab753d 1915 struct mwifiex_user_scan_cfg *user_scan_cfg;
5e6e3a92
BZ
1916
1917 wiphy_dbg(wiphy, "info: received scan request on %s\n", dev->name);
1918
e45a8419
AK
1919 if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
1920 atomic_read(&priv->wmm.tx_pkts_queued) >=
de09364e
AK
1921 MWIFIEX_MIN_TX_PENDING_TO_CANCEL_SCAN) {
1922 dev_dbg(priv->adapter->dev, "scan rejected due to traffic\n");
1923 return -EBUSY;
1924 }
1925
75ab753d
AK
1926 /* Block scan request if scan operation or scan cleanup when interface
1927 * is disabled is in process
1928 */
1929 if (priv->scan_request || priv->scan_aborting) {
f162cac8
AK
1930 dev_err(priv->adapter->dev, "cmd: Scan already in process..\n");
1931 return -EBUSY;
1932 }
1933
75ab753d
AK
1934 user_scan_cfg = kzalloc(sizeof(*user_scan_cfg), GFP_KERNEL);
1935 if (!user_scan_cfg)
38c9d664 1936 return -ENOMEM;
be0b281e 1937
6fcf2b10
BZ
1938 priv->scan_request = request;
1939
75ab753d
AK
1940 user_scan_cfg->num_ssids = request->n_ssids;
1941 user_scan_cfg->ssid_list = request->ssids;
be0b281e 1942
13d7ba78 1943 if (request->ie && request->ie_len) {
ea021f56 1944 offset = 0;
13d7ba78
AP
1945 for (i = 0; i < MWIFIEX_MAX_VSIE_NUM; i++) {
1946 if (priv->vs_ie[i].mask != MWIFIEX_VSIE_MASK_CLEAR)
1947 continue;
1948 priv->vs_ie[i].mask = MWIFIEX_VSIE_MASK_SCAN;
ea021f56
SP
1949 ie = (struct ieee_types_header *)(request->ie + offset);
1950 memcpy(&priv->vs_ie[i].ie, ie, sizeof(*ie) + ie->len);
1951 offset += sizeof(*ie) + ie->len;
1952
1953 if (offset >= request->ie_len)
1954 break;
13d7ba78
AP
1955 }
1956 }
1957
901ceba4
SP
1958 for (i = 0; i < min_t(u32, request->n_channels,
1959 MWIFIEX_USER_SCAN_CHAN_MAX); i++) {
38c9d664 1960 chan = request->channels[i];
75ab753d
AK
1961 user_scan_cfg->chan_list[i].chan_number = chan->hw_value;
1962 user_scan_cfg->chan_list[i].radio_type = chan->band;
38c9d664
AK
1963
1964 if (chan->flags & IEEE80211_CHAN_PASSIVE_SCAN)
75ab753d 1965 user_scan_cfg->chan_list[i].scan_type =
aea0701e 1966 MWIFIEX_SCAN_TYPE_PASSIVE;
38c9d664 1967 else
75ab753d 1968 user_scan_cfg->chan_list[i].scan_type =
aea0701e 1969 MWIFIEX_SCAN_TYPE_ACTIVE;
38c9d664 1970
75ab753d 1971 user_scan_cfg->chan_list[i].scan_time = 0;
38c9d664 1972 }
c2476335 1973
75ab753d
AK
1974 ret = mwifiex_scan_networks(priv, user_scan_cfg);
1975 kfree(user_scan_cfg);
c2476335
BZ
1976 if (ret) {
1977 dev_err(priv->adapter->dev, "scan failed: %d\n", ret);
75ab753d 1978 priv->scan_aborting = false;
6fcf2b10 1979 priv->scan_request = NULL;
c2476335
BZ
1980 return ret;
1981 }
38c9d664 1982
13d7ba78
AP
1983 if (request->ie && request->ie_len) {
1984 for (i = 0; i < MWIFIEX_MAX_VSIE_NUM; i++) {
1985 if (priv->vs_ie[i].mask == MWIFIEX_VSIE_MASK_SCAN) {
1986 priv->vs_ie[i].mask = MWIFIEX_VSIE_MASK_CLEAR;
1987 memset(&priv->vs_ie[i].ie, 0,
1988 MWIFIEX_MAX_VSIE_LEN);
1989 }
1990 }
1991 }
5e6e3a92
BZ
1992 return 0;
1993}
1994
a5f39056
YAP
1995static void mwifiex_setup_vht_caps(struct ieee80211_sta_vht_cap *vht_info,
1996 struct mwifiex_private *priv)
1997{
1998 struct mwifiex_adapter *adapter = priv->adapter;
a5f39056
YAP
1999
2000 vht_info->vht_supported = true;
2001
43283feb 2002 vht_info->cap = adapter->hw_dot_11ac_dev_cap;
a5f39056
YAP
2003 /* Update MCS support for VHT */
2004 vht_info->vht_mcs.rx_mcs_map = cpu_to_le16(
2005 adapter->hw_dot_11ac_mcs_support & 0xFFFF);
2006 vht_info->vht_mcs.rx_highest = 0;
2007 vht_info->vht_mcs.tx_mcs_map = cpu_to_le16(
2008 adapter->hw_dot_11ac_mcs_support >> 16);
2009 vht_info->vht_mcs.tx_highest = 0;
2010}
2011
5e6e3a92
BZ
2012/*
2013 * This function sets up the CFG802.11 specific HT capability fields
2014 * with default values.
2015 *
2016 * The following default values are set -
2017 * - HT Supported = True
a46b7b5c
AK
2018 * - Maximum AMPDU length factor = IEEE80211_HT_MAX_AMPDU_64K
2019 * - Minimum AMPDU spacing = IEEE80211_HT_MPDU_DENSITY_NONE
2020 * - HT Capabilities supported by firmware
5e6e3a92
BZ
2021 * - MCS information, Rx mask = 0xff
2022 * - MCD information, Tx parameters = IEEE80211_HT_MCS_TX_DEFINED (0x01)
2023 */
2024static void
2025mwifiex_setup_ht_caps(struct ieee80211_sta_ht_cap *ht_info,
2026 struct mwifiex_private *priv)
2027{
2028 int rx_mcs_supp;
2029 struct ieee80211_mcs_info mcs_set;
2030 u8 *mcs = (u8 *)&mcs_set;
2031 struct mwifiex_adapter *adapter = priv->adapter;
2032
2033 ht_info->ht_supported = true;
a46b7b5c
AK
2034 ht_info->ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
2035 ht_info->ampdu_density = IEEE80211_HT_MPDU_DENSITY_NONE;
5e6e3a92
BZ
2036
2037 memset(&ht_info->mcs, 0, sizeof(ht_info->mcs));
5e6e3a92 2038
a46b7b5c
AK
2039 /* Fill HT capability information */
2040 if (ISSUPP_CHANWIDTH40(adapter->hw_dot_11n_dev_cap))
2041 ht_info->cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
2042 else
2043 ht_info->cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
2044
2045 if (ISSUPP_SHORTGI20(adapter->hw_dot_11n_dev_cap))
2046 ht_info->cap |= IEEE80211_HT_CAP_SGI_20;
2047 else
2048 ht_info->cap &= ~IEEE80211_HT_CAP_SGI_20;
2049
2050 if (ISSUPP_SHORTGI40(adapter->hw_dot_11n_dev_cap))
2051 ht_info->cap |= IEEE80211_HT_CAP_SGI_40;
2052 else
2053 ht_info->cap &= ~IEEE80211_HT_CAP_SGI_40;
2054
2055 if (ISSUPP_RXSTBC(adapter->hw_dot_11n_dev_cap))
2056 ht_info->cap |= 1 << IEEE80211_HT_CAP_RX_STBC_SHIFT;
2057 else
2058 ht_info->cap &= ~(3 << IEEE80211_HT_CAP_RX_STBC_SHIFT);
2059
2060 if (ISSUPP_TXSTBC(adapter->hw_dot_11n_dev_cap))
2061 ht_info->cap |= IEEE80211_HT_CAP_TX_STBC;
2062 else
2063 ht_info->cap &= ~IEEE80211_HT_CAP_TX_STBC;
2064
dd0d83c2
AP
2065 if (ISSUPP_GREENFIELD(adapter->hw_dot_11n_dev_cap))
2066 ht_info->cap |= IEEE80211_HT_CAP_GRN_FLD;
2067 else
2068 ht_info->cap &= ~IEEE80211_HT_CAP_GRN_FLD;
2069
2070 if (ISENABLED_40MHZ_INTOLERANT(adapter->hw_dot_11n_dev_cap))
2071 ht_info->cap |= IEEE80211_HT_CAP_40MHZ_INTOLERANT;
2072 else
2073 ht_info->cap &= ~IEEE80211_HT_CAP_40MHZ_INTOLERANT;
2074
2075 if (ISSUPP_RXLDPC(adapter->hw_dot_11n_dev_cap))
2076 ht_info->cap |= IEEE80211_HT_CAP_LDPC_CODING;
2077 else
2078 ht_info->cap &= ~IEEE80211_HT_CAP_LDPC_CODING;
2079
a46b7b5c
AK
2080 ht_info->cap &= ~IEEE80211_HT_CAP_MAX_AMSDU;
2081 ht_info->cap |= IEEE80211_HT_CAP_SM_PS;
2082
2083 rx_mcs_supp = GET_RXMCSSUPP(adapter->hw_dev_mcs_support);
5e6e3a92
BZ
2084 /* Set MCS for 1x1 */
2085 memset(mcs, 0xff, rx_mcs_supp);
2086 /* Clear all the other values */
2087 memset(&mcs[rx_mcs_supp], 0,
aea0701e 2088 sizeof(struct ieee80211_mcs_info) - rx_mcs_supp);
eecd8250 2089 if (priv->bss_mode == NL80211_IFTYPE_STATION ||
aea0701e 2090 ISSUPP_CHANWIDTH40(adapter->hw_dot_11n_dev_cap))
5e6e3a92
BZ
2091 /* Set MCS32 for infra mode or ad-hoc mode with 40MHz support */
2092 SETHT_MCS32(mcs_set.rx_mask);
2093
2094 memcpy((u8 *) &ht_info->mcs, mcs, sizeof(struct ieee80211_mcs_info));
2095
2096 ht_info->mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED;
2097}
2098
93a1df48
YAP
2099/*
2100 * create a new virtual interface with the given name
2101 */
84efbb84 2102struct wireless_dev *mwifiex_add_virtual_intf(struct wiphy *wiphy,
552bff0c 2103 const char *name,
84efbb84
JB
2104 enum nl80211_iftype type,
2105 u32 *flags,
2106 struct vif_params *params)
93a1df48 2107{
67fdf39e
AP
2108 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
2109 struct mwifiex_private *priv;
93a1df48
YAP
2110 struct net_device *dev;
2111 void *mdev_priv;
d6bffe8b 2112 struct wireless_dev *wdev;
93a1df48 2113
93a1df48 2114 if (!adapter)
858faa57 2115 return ERR_PTR(-EFAULT);
93a1df48
YAP
2116
2117 switch (type) {
2118 case NL80211_IFTYPE_UNSPECIFIED:
2119 case NL80211_IFTYPE_STATION:
2120 case NL80211_IFTYPE_ADHOC:
d6bffe8b 2121 priv = adapter->priv[MWIFIEX_BSS_TYPE_STA];
93a1df48 2122 if (priv->bss_mode) {
d6bffe8b
AP
2123 wiphy_err(wiphy,
2124 "cannot create multiple sta/adhoc ifaces\n");
858faa57 2125 return ERR_PTR(-EINVAL);
93a1df48
YAP
2126 }
2127
d6bffe8b
AP
2128 wdev = kzalloc(sizeof(struct wireless_dev), GFP_KERNEL);
2129 if (!wdev)
858faa57 2130 return ERR_PTR(-ENOMEM);
d6bffe8b
AP
2131
2132 wdev->wiphy = wiphy;
2133 priv->wdev = wdev;
2134 wdev->iftype = NL80211_IFTYPE_STATION;
2135
93a1df48
YAP
2136 if (type == NL80211_IFTYPE_UNSPECIFIED)
2137 priv->bss_mode = NL80211_IFTYPE_STATION;
2138 else
2139 priv->bss_mode = type;
2140
2141 priv->bss_type = MWIFIEX_BSS_TYPE_STA;
2142 priv->frame_type = MWIFIEX_DATA_FRAME_TYPE_ETH_II;
a458c0ae 2143 priv->bss_priority = 0;
93a1df48 2144 priv->bss_role = MWIFIEX_BSS_ROLE_STA;
93a1df48
YAP
2145 priv->bss_num = 0;
2146
d6bffe8b
AP
2147 break;
2148 case NL80211_IFTYPE_AP:
2149 priv = adapter->priv[MWIFIEX_BSS_TYPE_UAP];
2150
2151 if (priv->bss_mode) {
2152 wiphy_err(wiphy, "Can't create multiple AP interfaces");
858faa57 2153 return ERR_PTR(-EINVAL);
d6bffe8b
AP
2154 }
2155
2156 wdev = kzalloc(sizeof(struct wireless_dev), GFP_KERNEL);
2157 if (!wdev)
858faa57 2158 return ERR_PTR(-ENOMEM);
d6bffe8b
AP
2159
2160 priv->wdev = wdev;
2161 wdev->wiphy = wiphy;
2162 wdev->iftype = NL80211_IFTYPE_AP;
2163
2164 priv->bss_type = MWIFIEX_BSS_TYPE_UAP;
2165 priv->frame_type = MWIFIEX_DATA_FRAME_TYPE_ETH_II;
a458c0ae 2166 priv->bss_priority = 0;
d6bffe8b
AP
2167 priv->bss_role = MWIFIEX_BSS_ROLE_UAP;
2168 priv->bss_started = 0;
2169 priv->bss_num = 0;
2170 priv->bss_mode = type;
2171
197f4a2e
SP
2172 break;
2173 case NL80211_IFTYPE_P2P_CLIENT:
2174 priv = adapter->priv[MWIFIEX_BSS_TYPE_P2P];
2175
2176 if (priv->bss_mode) {
2177 wiphy_err(wiphy, "Can't create multiple P2P ifaces");
2178 return ERR_PTR(-EINVAL);
2179 }
2180
2181 wdev = kzalloc(sizeof(struct wireless_dev), GFP_KERNEL);
2182 if (!wdev)
2183 return ERR_PTR(-ENOMEM);
2184
2185 priv->wdev = wdev;
2186 wdev->wiphy = wiphy;
2187
2188 /* At start-up, wpa_supplicant tries to change the interface
2189 * to NL80211_IFTYPE_STATION if it is not managed mode.
197f4a2e 2190 */
5586d3e2
PS
2191 wdev->iftype = NL80211_IFTYPE_P2P_CLIENT;
2192 priv->bss_mode = NL80211_IFTYPE_P2P_CLIENT;
197f4a2e
SP
2193
2194 /* Setting bss_type to P2P tells firmware that this interface
2195 * is receiving P2P peers found during find phase and doing
2196 * action frame handshake.
2197 */
2198 priv->bss_type = MWIFIEX_BSS_TYPE_P2P;
2199
2200 priv->frame_type = MWIFIEX_DATA_FRAME_TYPE_ETH_II;
2201 priv->bss_priority = MWIFIEX_BSS_ROLE_STA;
2202 priv->bss_role = MWIFIEX_BSS_ROLE_STA;
2203 priv->bss_started = 0;
2204 priv->bss_num = 0;
2205
66aa1ae2
BZ
2206 if (mwifiex_cfg80211_init_p2p_client(priv))
2207 return ERR_PTR(-EFAULT);
2208
93a1df48
YAP
2209 break;
2210 default:
2211 wiphy_err(wiphy, "type not supported\n");
858faa57 2212 return ERR_PTR(-EINVAL);
93a1df48
YAP
2213 }
2214
47411a06
AP
2215 dev = alloc_netdev_mqs(sizeof(struct mwifiex_private *), name,
2216 ether_setup, IEEE80211_NUM_ACS, 1);
93a1df48
YAP
2217 if (!dev) {
2218 wiphy_err(wiphy, "no memory available for netdevice\n");
858faa57
BZ
2219 priv->bss_mode = NL80211_IFTYPE_UNSPECIFIED;
2220 return ERR_PTR(-ENOMEM);
93a1df48
YAP
2221 }
2222
d6bffe8b
AP
2223 mwifiex_init_priv_params(priv, dev);
2224 priv->netdev = dev;
2225
2226 mwifiex_setup_ht_caps(&wiphy->bands[IEEE80211_BAND_2GHZ]->ht_cap, priv);
a5f39056
YAP
2227 if (adapter->is_hw_11ac_capable)
2228 mwifiex_setup_vht_caps(
2229 &wiphy->bands[IEEE80211_BAND_2GHZ]->vht_cap, priv);
d6bffe8b
AP
2230
2231 if (adapter->config_bands & BAND_A)
2232 mwifiex_setup_ht_caps(
2233 &wiphy->bands[IEEE80211_BAND_5GHZ]->ht_cap, priv);
2234
a5f39056
YAP
2235 if ((adapter->config_bands & BAND_A) && adapter->is_hw_11ac_capable)
2236 mwifiex_setup_vht_caps(
2237 &wiphy->bands[IEEE80211_BAND_5GHZ]->vht_cap, priv);
2238
93a1df48
YAP
2239 dev_net_set(dev, wiphy_net(wiphy));
2240 dev->ieee80211_ptr = priv->wdev;
2241 dev->ieee80211_ptr->iftype = priv->bss_mode;
2242 memcpy(dev->dev_addr, wiphy->perm_addr, ETH_ALEN);
93a1df48
YAP
2243 SET_NETDEV_DEV(dev, wiphy_dev(wiphy));
2244
2245 dev->flags |= IFF_BROADCAST | IFF_MULTICAST;
2246 dev->watchdog_timeo = MWIFIEX_DEFAULT_WATCHDOG_TIMEOUT;
2247 dev->hard_header_len += MWIFIEX_MIN_DATA_HEADER_LEN;
0d7f53e3 2248 dev->ethtool_ops = &mwifiex_ethtool_ops;
93a1df48
YAP
2249
2250 mdev_priv = netdev_priv(dev);
2251 *((unsigned long *) mdev_priv) = (unsigned long) priv;
2252
93a1df48
YAP
2253 SET_NETDEV_DEV(dev, adapter->dev);
2254
2255 /* Register network device */
2256 if (register_netdevice(dev)) {
2257 wiphy_err(wiphy, "cannot register virtual network device\n");
858faa57
BZ
2258 free_netdev(dev);
2259 priv->bss_mode = NL80211_IFTYPE_UNSPECIFIED;
2260 return ERR_PTR(-EFAULT);
93a1df48
YAP
2261 }
2262
2263 sema_init(&priv->async_sem, 1);
93a1df48
YAP
2264
2265 dev_dbg(adapter->dev, "info: %s: Marvell 802.11 Adapter\n", dev->name);
2266
2267#ifdef CONFIG_DEBUG_FS
2268 mwifiex_dev_debugfs_init(priv);
2269#endif
84efbb84 2270 return wdev;
93a1df48
YAP
2271}
2272EXPORT_SYMBOL_GPL(mwifiex_add_virtual_intf);
2273
2274/*
2275 * del_virtual_intf: remove the virtual interface determined by dev
2276 */
84efbb84 2277int mwifiex_del_virtual_intf(struct wiphy *wiphy, struct wireless_dev *wdev)
93a1df48 2278{
84efbb84 2279 struct mwifiex_private *priv = mwifiex_netdev_get_priv(wdev->netdev);
93a1df48
YAP
2280
2281#ifdef CONFIG_DEBUG_FS
2282 mwifiex_dev_debugfs_remove(priv);
2283#endif
2284
47411a06 2285 mwifiex_stop_net_dev_queue(priv->netdev, priv->adapter);
93a1df48
YAP
2286
2287 if (netif_carrier_ok(priv->netdev))
2288 netif_carrier_off(priv->netdev);
2289
84efbb84
JB
2290 if (wdev->netdev->reg_state == NETREG_REGISTERED)
2291 unregister_netdevice(wdev->netdev);
93a1df48 2292
93a1df48
YAP
2293 /* Clear the priv in adapter */
2294 priv->netdev = NULL;
2295
2296 priv->media_connected = false;
2297
93a1df48
YAP
2298 priv->bss_mode = NL80211_IFTYPE_UNSPECIFIED;
2299
2300 return 0;
2301}
2302EXPORT_SYMBOL_GPL(mwifiex_del_virtual_intf);
2303
7da060c1
AK
2304#ifdef CONFIG_PM
2305static bool
2306mwifiex_is_pattern_supported(struct cfg80211_wowlan_trig_pkt_pattern *pat,
2307 s8 *byte_seq)
2308{
2309 int j, k, valid_byte_cnt = 0;
2310 bool dont_care_byte = false;
2311
2312 for (j = 0; j < DIV_ROUND_UP(pat->pattern_len, 8); j++) {
2313 for (k = 0; k < 8; k++) {
2314 if (pat->mask[j] & 1 << k) {
2315 memcpy(byte_seq + valid_byte_cnt,
2316 &pat->pattern[j * 8 + k], 1);
2317 valid_byte_cnt++;
2318 if (dont_care_byte)
2319 return false;
2320 } else {
2321 if (valid_byte_cnt)
2322 dont_care_byte = true;
2323 }
2324
2325 if (valid_byte_cnt > MAX_BYTESEQ)
2326 return false;
2327 }
2328 }
2329
2330 byte_seq[MAX_BYTESEQ] = valid_byte_cnt;
2331
2332 return true;
2333}
2334
2335static int mwifiex_cfg80211_suspend(struct wiphy *wiphy,
2336 struct cfg80211_wowlan *wowlan)
2337{
2338 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
2339 struct mwifiex_ds_mef_cfg mef_cfg;
2340 struct mwifiex_mef_entry *mef_entry;
2341 int i, filt_num = 0, ret;
2342 bool first_pat = true;
2343 u8 byte_seq[MAX_BYTESEQ + 1];
2344 const u8 ipv4_mc_mac[] = {0x33, 0x33};
2345 const u8 ipv6_mc_mac[] = {0x01, 0x00, 0x5e};
2346 struct mwifiex_private *priv =
2347 mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_STA);
2348
2349 if (!wowlan) {
2350 dev_warn(adapter->dev, "None of the WOWLAN triggers enabled\n");
2351 return 0;
2352 }
2353
2354 if (!priv->media_connected) {
2355 dev_warn(adapter->dev,
2356 "Can not configure WOWLAN in disconnected state\n");
2357 return 0;
2358 }
2359
c678fb2a
BZ
2360 mef_entry = kzalloc(sizeof(*mef_entry), GFP_KERNEL);
2361 if (!mef_entry)
2362 return -ENOMEM;
2363
7da060c1
AK
2364 memset(&mef_cfg, 0, sizeof(mef_cfg));
2365 mef_cfg.num_entries = 1;
7da060c1
AK
2366 mef_cfg.mef_entry = mef_entry;
2367 mef_entry->mode = MEF_MODE_HOST_SLEEP;
2368 mef_entry->action = MEF_ACTION_ALLOW_AND_WAKEUP_HOST;
2369
2370 for (i = 0; i < wowlan->n_patterns; i++) {
2371 memset(byte_seq, 0, sizeof(byte_seq));
2372 if (!mwifiex_is_pattern_supported(&wowlan->patterns[i],
2373 byte_seq)) {
2374 wiphy_err(wiphy, "Pattern not supported\n");
2375 kfree(mef_entry);
2376 return -EOPNOTSUPP;
2377 }
2378
2379 if (!wowlan->patterns[i].pkt_offset) {
2380 if (!(byte_seq[0] & 0x01) &&
2381 (byte_seq[MAX_BYTESEQ] == 1)) {
2382 mef_cfg.criteria |= MWIFIEX_CRITERIA_UNICAST;
2383 continue;
2384 } else if (is_broadcast_ether_addr(byte_seq)) {
2385 mef_cfg.criteria |= MWIFIEX_CRITERIA_BROADCAST;
2386 continue;
2387 } else if ((!memcmp(byte_seq, ipv4_mc_mac, 2) &&
2388 (byte_seq[MAX_BYTESEQ] == 2)) ||
2389 (!memcmp(byte_seq, ipv6_mc_mac, 3) &&
2390 (byte_seq[MAX_BYTESEQ] == 3))) {
2391 mef_cfg.criteria |= MWIFIEX_CRITERIA_MULTICAST;
2392 continue;
2393 }
2394 }
2395
2396 mef_entry->filter[filt_num].repeat = 1;
2397 mef_entry->filter[filt_num].offset =
2398 wowlan->patterns[i].pkt_offset;
2399 memcpy(mef_entry->filter[filt_num].byte_seq, byte_seq,
2400 sizeof(byte_seq));
2401 mef_entry->filter[filt_num].filt_type = TYPE_EQ;
2402
2403 if (first_pat)
2404 first_pat = false;
2405 else
2406 mef_entry->filter[filt_num].filt_action = TYPE_AND;
2407
2408 filt_num++;
2409 }
2410
2411 if (wowlan->magic_pkt) {
2412 mef_cfg.criteria |= MWIFIEX_CRITERIA_UNICAST;
2413 mef_entry->filter[filt_num].repeat = 16;
2414 memcpy(mef_entry->filter[filt_num].byte_seq, priv->curr_addr,
2415 ETH_ALEN);
2416 mef_entry->filter[filt_num].byte_seq[MAX_BYTESEQ] = ETH_ALEN;
2417 mef_entry->filter[filt_num].offset = 14;
2418 mef_entry->filter[filt_num].filt_type = TYPE_EQ;
2419 if (filt_num)
2420 mef_entry->filter[filt_num].filt_action = TYPE_OR;
2421 }
2422
2423 if (!mef_cfg.criteria)
2424 mef_cfg.criteria = MWIFIEX_CRITERIA_BROADCAST |
2425 MWIFIEX_CRITERIA_UNICAST |
2426 MWIFIEX_CRITERIA_MULTICAST;
2427
2428 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_MEF_CFG,
2429 HostCmd_ACT_GEN_SET, 0,
2430 &mef_cfg);
2431
2432 kfree(mef_entry);
2433 return ret;
2434}
2435
2436static int mwifiex_cfg80211_resume(struct wiphy *wiphy)
2437{
2438 return 0;
2439}
2440
2441static void mwifiex_cfg80211_set_wakeup(struct wiphy *wiphy,
2442 bool enabled)
2443{
2444 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
2445
2446 device_set_wakeup_enable(adapter->dev, enabled);
2447}
2448#endif
2449
5e6e3a92
BZ
2450/* station cfg80211 operations */
2451static struct cfg80211_ops mwifiex_cfg80211_ops = {
93a1df48
YAP
2452 .add_virtual_intf = mwifiex_add_virtual_intf,
2453 .del_virtual_intf = mwifiex_del_virtual_intf,
5e6e3a92
BZ
2454 .change_virtual_intf = mwifiex_cfg80211_change_virtual_intf,
2455 .scan = mwifiex_cfg80211_scan,
2456 .connect = mwifiex_cfg80211_connect,
2457 .disconnect = mwifiex_cfg80211_disconnect,
2458 .get_station = mwifiex_cfg80211_get_station,
f85aae6b 2459 .dump_station = mwifiex_cfg80211_dump_station,
5e6e3a92 2460 .set_wiphy_params = mwifiex_cfg80211_set_wiphy_params,
5e6e3a92
BZ
2461 .join_ibss = mwifiex_cfg80211_join_ibss,
2462 .leave_ibss = mwifiex_cfg80211_leave_ibss,
2463 .add_key = mwifiex_cfg80211_add_key,
2464 .del_key = mwifiex_cfg80211_del_key,
e39faa73 2465 .mgmt_tx = mwifiex_cfg80211_mgmt_tx,
3cec6870 2466 .mgmt_frame_register = mwifiex_cfg80211_mgmt_frame_register,
7feb4c48
SP
2467 .remain_on_channel = mwifiex_cfg80211_remain_on_channel,
2468 .cancel_remain_on_channel = mwifiex_cfg80211_cancel_remain_on_channel,
5e6e3a92
BZ
2469 .set_default_key = mwifiex_cfg80211_set_default_key,
2470 .set_power_mgmt = mwifiex_cfg80211_set_power_mgmt,
2471 .set_tx_power = mwifiex_cfg80211_set_tx_power,
5d82c53a 2472 .set_bitrate_mask = mwifiex_cfg80211_set_bitrate_mask,
12190c5d
AP
2473 .start_ap = mwifiex_cfg80211_start_ap,
2474 .stop_ap = mwifiex_cfg80211_stop_ap,
5370c836 2475 .change_beacon = mwifiex_cfg80211_change_beacon,
fa444bf8 2476 .set_cqm_rssi_config = mwifiex_cfg80211_set_cqm_rssi_config,
8a279d5b 2477 .set_antenna = mwifiex_cfg80211_set_antenna,
0f9e9b8b 2478 .del_station = mwifiex_cfg80211_del_station,
7da060c1
AK
2479#ifdef CONFIG_PM
2480 .suspend = mwifiex_cfg80211_suspend,
2481 .resume = mwifiex_cfg80211_resume,
2482 .set_wakeup = mwifiex_cfg80211_set_wakeup,
2483#endif
5e6e3a92
BZ
2484};
2485
964dc9e2
JB
2486#ifdef CONFIG_PM
2487static const struct wiphy_wowlan_support mwifiex_wowlan_support = {
2488 .flags = WIPHY_WOWLAN_MAGIC_PKT,
2489 .n_patterns = MWIFIEX_MAX_FILTERS,
2490 .pattern_min_len = 1,
2491 .pattern_max_len = MWIFIEX_MAX_PATTERN_LEN,
2492 .max_pkt_offset = MWIFIEX_MAX_OFFSET_LEN,
2493};
2494#endif
2495
3c68ef5b
AP
2496static bool mwifiex_is_valid_alpha2(const char *alpha2)
2497{
2498 if (!alpha2 || strlen(alpha2) != 2)
2499 return false;
2500
2501 if (isalpha(alpha2[0]) && isalpha(alpha2[1]))
2502 return true;
2503
2504 return false;
2505}
2506
5e6e3a92
BZ
2507/*
2508 * This function registers the device with CFG802.11 subsystem.
2509 *
2510 * The function creates the wireless device/wiphy, populates it with
2511 * default parameters and handler function pointers, and finally
2512 * registers the device.
2513 */
d6bffe8b
AP
2514
2515int mwifiex_register_cfg80211(struct mwifiex_adapter *adapter)
5e6e3a92 2516{
270e58e8
YAP
2517 int ret;
2518 void *wdev_priv;
d6bffe8b
AP
2519 struct wiphy *wiphy;
2520 struct mwifiex_private *priv = adapter->priv[MWIFIEX_BSS_TYPE_STA];
9e04a7c6 2521 u8 *country_code;
5e6e3a92 2522
d6bffe8b
AP
2523 /* create a new wiphy for use with cfg80211 */
2524 wiphy = wiphy_new(&mwifiex_cfg80211_ops,
2525 sizeof(struct mwifiex_adapter *));
2526 if (!wiphy) {
2527 dev_err(adapter->dev, "%s: creating new wiphy\n", __func__);
5e6e3a92
BZ
2528 return -ENOMEM;
2529 }
d6bffe8b
AP
2530 wiphy->max_scan_ssids = MWIFIEX_MAX_SSID_LIST_LENGTH;
2531 wiphy->max_scan_ie_len = MWIFIEX_MAX_VSIE_LEN;
83719be8 2532 wiphy->mgmt_stypes = mwifiex_mgmt_stypes;
7feb4c48 2533 wiphy->max_remain_on_channel_duration = 5000;
d6bffe8b
AP
2534 wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
2535 BIT(NL80211_IFTYPE_ADHOC) |
197f4a2e
SP
2536 BIT(NL80211_IFTYPE_P2P_CLIENT) |
2537 BIT(NL80211_IFTYPE_P2P_GO) |
d6bffe8b
AP
2538 BIT(NL80211_IFTYPE_AP);
2539
2540 wiphy->bands[IEEE80211_BAND_2GHZ] = &mwifiex_band_2ghz;
2541 if (adapter->config_bands & BAND_A)
2542 wiphy->bands[IEEE80211_BAND_5GHZ] = &mwifiex_band_5ghz;
2543 else
2544 wiphy->bands[IEEE80211_BAND_5GHZ] = NULL;
5e6e3a92 2545
cd8440da
AP
2546 wiphy->iface_combinations = &mwifiex_iface_comb_ap_sta;
2547 wiphy->n_iface_combinations = 1;
2548
5e6e3a92 2549 /* Initialize cipher suits */
d6bffe8b
AP
2550 wiphy->cipher_suites = mwifiex_cipher_suites;
2551 wiphy->n_cipher_suites = ARRAY_SIZE(mwifiex_cipher_suites);
5e6e3a92 2552
d6bffe8b
AP
2553 memcpy(wiphy->perm_addr, priv->curr_addr, ETH_ALEN);
2554 wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
2dd2bd6b 2555 wiphy->flags |= WIPHY_FLAG_HAVE_AP_SME |
cc0ba0d5 2556 WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD |
54428c57 2557 WIPHY_FLAG_AP_UAPSD |
7feb4c48 2558 WIPHY_FLAG_CUSTOM_REGULATORY |
3c68ef5b 2559 WIPHY_FLAG_STRICT_REGULATORY |
7feb4c48 2560 WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
cc0ba0d5
AK
2561
2562 wiphy_apply_custom_regulatory(wiphy, &mwifiex_world_regdom_custom);
2dd2bd6b 2563
7da060c1 2564#ifdef CONFIG_PM
964dc9e2 2565 wiphy->wowlan = &mwifiex_wowlan_support;
7da060c1
AK
2566#endif
2567
2dd2bd6b 2568 wiphy->probe_resp_offload = NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS |
e39faa73
SP
2569 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2 |
2570 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P;
5e6e3a92 2571
8a279d5b
AK
2572 wiphy->available_antennas_tx = BIT(adapter->number_of_antenna) - 1;
2573 wiphy->available_antennas_rx = BIT(adapter->number_of_antenna) - 1;
5e6e3a92 2574
b292219f 2575 wiphy->features |= NL80211_FEATURE_HT_IBSS |
e45a8419
AK
2576 NL80211_FEATURE_INACTIVITY_TIMER |
2577 NL80211_FEATURE_LOW_PRIORITY_SCAN;
05910f4a 2578
b5abcf02 2579 /* Reserve space for mwifiex specific private data for BSS */
d6bffe8b 2580 wiphy->bss_priv_size = sizeof(struct mwifiex_bss_priv);
5116f3ce 2581
d6bffe8b 2582 wiphy->reg_notifier = mwifiex_reg_notifier;
5e6e3a92 2583
67fdf39e 2584 /* Set struct mwifiex_adapter pointer in wiphy_priv */
d6bffe8b 2585 wdev_priv = wiphy_priv(wiphy);
67fdf39e 2586 *(unsigned long *)wdev_priv = (unsigned long)adapter;
5e6e3a92 2587
2c208890 2588 set_wiphy_dev(wiphy, priv->adapter->dev);
a7b21165 2589
d6bffe8b 2590 ret = wiphy_register(wiphy);
5e6e3a92 2591 if (ret < 0) {
d6bffe8b
AP
2592 dev_err(adapter->dev,
2593 "%s: wiphy_register failed: %d\n", __func__, ret);
2594 wiphy_free(wiphy);
5e6e3a92 2595 return ret;
5e6e3a92 2596 }
3c68ef5b
AP
2597
2598 if (reg_alpha2 && mwifiex_is_valid_alpha2(reg_alpha2)) {
2599 wiphy_info(wiphy, "driver hint alpha2: %2.2s\n", reg_alpha2);
2600 regulatory_hint(wiphy, reg_alpha2);
2601 } else {
2602 country_code = mwifiex_11d_code_2_region(adapter->region_code);
2603 if (country_code)
2604 wiphy_info(wiphy, "ignoring F/W country code %2.2s\n",
2605 country_code);
2606 }
5e6e3a92 2607
d6bffe8b 2608 adapter->wiphy = wiphy;
5e6e3a92
BZ
2609 return ret;
2610}
This page took 0.557126 seconds and 5 git commands to generate.