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