1 /*
2 * NXP Wireless LAN device driver: CFG80211
3 *
4 * Copyright 2011-2020 NXP
5 *
6 * This software file (the "File") is distributed by NXP
7 * 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 #include "11n.h"
23 #include "wmm.h"
24
25 static char *reg_alpha2;
26 module_param(reg_alpha2, charp, 0);
27
28 static const struct ieee80211_iface_limit mwifiex_ap_sta_limits[] = {
29 {
30 .max = MWIFIEX_MAX_BSS_NUM,
31 .types = BIT(NL80211_IFTYPE_STATION) |
32 BIT(NL80211_IFTYPE_P2P_GO) |
33 BIT(NL80211_IFTYPE_P2P_CLIENT) |
34 BIT(NL80211_IFTYPE_AP),
35 },
36 };
37
38 static const struct ieee80211_iface_combination
39 mwifiex_iface_comb_ap_sta = {
40 .limits = mwifiex_ap_sta_limits,
41 .num_different_channels = 1,
42 .n_limits = ARRAY_SIZE(mwifiex_ap_sta_limits),
43 .max_interfaces = MWIFIEX_MAX_BSS_NUM,
44 .beacon_int_infra_match = true,
45 .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
46 BIT(NL80211_CHAN_WIDTH_20) |
47 BIT(NL80211_CHAN_WIDTH_40),
48 };
49
50 static const struct ieee80211_iface_combination
51 mwifiex_iface_comb_ap_sta_vht = {
52 .limits = mwifiex_ap_sta_limits,
53 .num_different_channels = 1,
54 .n_limits = ARRAY_SIZE(mwifiex_ap_sta_limits),
55 .max_interfaces = MWIFIEX_MAX_BSS_NUM,
56 .beacon_int_infra_match = true,
57 .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
58 BIT(NL80211_CHAN_WIDTH_20) |
59 BIT(NL80211_CHAN_WIDTH_40) |
60 BIT(NL80211_CHAN_WIDTH_80),
61 };
62
63 static const struct
64 ieee80211_iface_combination mwifiex_iface_comb_ap_sta_drcs = {
65 .limits = mwifiex_ap_sta_limits,
66 .num_different_channels = 2,
67 .n_limits = ARRAY_SIZE(mwifiex_ap_sta_limits),
68 .max_interfaces = MWIFIEX_MAX_BSS_NUM,
69 .beacon_int_infra_match = true,
70 };
71
72 /*
73 * This function maps the nl802.11 channel type into driver channel type.
74 *
75 * The mapping is as follows -
76 * NL80211_CHAN_NO_HT -> IEEE80211_HT_PARAM_CHA_SEC_NONE
77 * NL80211_CHAN_HT20 -> IEEE80211_HT_PARAM_CHA_SEC_NONE
78 * NL80211_CHAN_HT40PLUS -> IEEE80211_HT_PARAM_CHA_SEC_ABOVE
79 * NL80211_CHAN_HT40MINUS -> IEEE80211_HT_PARAM_CHA_SEC_BELOW
80 * Others -> IEEE80211_HT_PARAM_CHA_SEC_NONE
81 */
mwifiex_chan_type_to_sec_chan_offset(enum nl80211_channel_type chan_type)82 u8 mwifiex_chan_type_to_sec_chan_offset(enum nl80211_channel_type chan_type)
83 {
84 switch (chan_type) {
85 case NL80211_CHAN_NO_HT:
86 case NL80211_CHAN_HT20:
87 return IEEE80211_HT_PARAM_CHA_SEC_NONE;
88 case NL80211_CHAN_HT40PLUS:
89 return IEEE80211_HT_PARAM_CHA_SEC_ABOVE;
90 case NL80211_CHAN_HT40MINUS:
91 return IEEE80211_HT_PARAM_CHA_SEC_BELOW;
92 default:
93 return IEEE80211_HT_PARAM_CHA_SEC_NONE;
94 }
95 }
96
97 /* This function maps IEEE HT secondary channel type to NL80211 channel type
98 */
mwifiex_get_chan_type(struct mwifiex_private * priv)99 u8 mwifiex_get_chan_type(struct mwifiex_private *priv)
100 {
101 struct mwifiex_channel_band channel_band;
102 int ret;
103
104 ret = mwifiex_get_chan_info(priv, &channel_band);
105
106 if (!ret) {
107 switch (channel_band.band_config.chan_width) {
108 case CHAN_BW_20MHZ:
109 if (IS_11N_ENABLED(priv))
110 return NL80211_CHAN_HT20;
111 else
112 return NL80211_CHAN_NO_HT;
113 case CHAN_BW_40MHZ:
114 if (channel_band.band_config.chan2_offset ==
115 SEC_CHAN_ABOVE)
116 return NL80211_CHAN_HT40PLUS;
117 else
118 return NL80211_CHAN_HT40MINUS;
119 default:
120 return NL80211_CHAN_HT20;
121 }
122 }
123
124 return NL80211_CHAN_HT20;
125 }
126
127 /*
128 * This function checks whether WEP is set.
129 */
130 static int
mwifiex_is_alg_wep(u32 cipher)131 mwifiex_is_alg_wep(u32 cipher)
132 {
133 switch (cipher) {
134 case WLAN_CIPHER_SUITE_WEP40:
135 case WLAN_CIPHER_SUITE_WEP104:
136 return 1;
137 default:
138 break;
139 }
140
141 return 0;
142 }
143
144 /*
145 * This function retrieves the private structure from kernel wiphy structure.
146 */
mwifiex_cfg80211_get_adapter(struct wiphy * wiphy)147 static void *mwifiex_cfg80211_get_adapter(struct wiphy *wiphy)
148 {
149 return (void *) (*(unsigned long *) wiphy_priv(wiphy));
150 }
151
152 /*
153 * CFG802.11 operation handler to delete a network key.
154 */
155 static int
mwifiex_cfg80211_del_key(struct wiphy * wiphy,struct net_device * netdev,u8 key_index,bool pairwise,const u8 * mac_addr)156 mwifiex_cfg80211_del_key(struct wiphy *wiphy, struct net_device *netdev,
157 u8 key_index, bool pairwise, const u8 *mac_addr)
158 {
159 struct mwifiex_private *priv = mwifiex_netdev_get_priv(netdev);
160 static const u8 bc_mac[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
161 const u8 *peer_mac = pairwise ? mac_addr : bc_mac;
162
163 if (mwifiex_set_encode(priv, NULL, NULL, 0, key_index, peer_mac, 1)) {
164 mwifiex_dbg(priv->adapter, ERROR, "deleting the crypto keys\n");
165 return -EFAULT;
166 }
167
168 mwifiex_dbg(priv->adapter, INFO, "info: crypto keys deleted\n");
169 return 0;
170 }
171
172 /*
173 * This function forms an skb for management frame.
174 */
175 static int
mwifiex_form_mgmt_frame(struct sk_buff * skb,const u8 * buf,size_t len)176 mwifiex_form_mgmt_frame(struct sk_buff *skb, const u8 *buf, size_t len)
177 {
178 u8 addr[ETH_ALEN] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
179 u16 pkt_len;
180 u32 tx_control = 0, pkt_type = PKT_TYPE_MGMT;
181
182 pkt_len = len + ETH_ALEN;
183
184 skb_reserve(skb, MWIFIEX_MIN_DATA_HEADER_LEN +
185 MWIFIEX_MGMT_FRAME_HEADER_SIZE + sizeof(pkt_len));
186 memcpy(skb_push(skb, sizeof(pkt_len)), &pkt_len, sizeof(pkt_len));
187
188 memcpy(skb_push(skb, sizeof(tx_control)),
189 &tx_control, sizeof(tx_control));
190
191 memcpy(skb_push(skb, sizeof(pkt_type)), &pkt_type, sizeof(pkt_type));
192
193 /* Add packet data and address4 */
194 skb_put_data(skb, buf, sizeof(struct ieee80211_hdr_3addr));
195 skb_put_data(skb, addr, ETH_ALEN);
196 skb_put_data(skb, buf + sizeof(struct ieee80211_hdr_3addr),
197 len - sizeof(struct ieee80211_hdr_3addr));
198
199 skb->priority = LOW_PRIO_TID;
200 __net_timestamp(skb);
201
202 return 0;
203 }
204
205 /*
206 * CFG802.11 operation handler to transmit a management frame.
207 */
208 static int
mwifiex_cfg80211_mgmt_tx(struct wiphy * wiphy,struct wireless_dev * wdev,struct cfg80211_mgmt_tx_params * params,u64 * cookie)209 mwifiex_cfg80211_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev,
210 struct cfg80211_mgmt_tx_params *params, u64 *cookie)
211 {
212 const u8 *buf = params->buf;
213 size_t len = params->len;
214 struct sk_buff *skb;
215 u16 pkt_len;
216 const struct ieee80211_mgmt *mgmt;
217 struct mwifiex_txinfo *tx_info;
218 struct mwifiex_private *priv = mwifiex_netdev_get_priv(wdev->netdev);
219
220 if (!buf || !len) {
221 mwifiex_dbg(priv->adapter, ERROR, "invalid buffer and length\n");
222 return -EFAULT;
223 }
224
225 mgmt = (const struct ieee80211_mgmt *)buf;
226 if (GET_BSS_ROLE(priv) != MWIFIEX_BSS_ROLE_STA &&
227 ieee80211_is_probe_resp(mgmt->frame_control)) {
228 /* Since we support offload probe resp, we need to skip probe
229 * resp in AP or GO mode */
230 mwifiex_dbg(priv->adapter, INFO,
231 "info: skip to send probe resp in AP or GO mode\n");
232 return 0;
233 }
234
235 pkt_len = len + ETH_ALEN;
236 skb = dev_alloc_skb(MWIFIEX_MIN_DATA_HEADER_LEN +
237 MWIFIEX_MGMT_FRAME_HEADER_SIZE +
238 pkt_len + sizeof(pkt_len));
239
240 if (!skb) {
241 mwifiex_dbg(priv->adapter, ERROR,
242 "allocate skb failed for management frame\n");
243 return -ENOMEM;
244 }
245
246 tx_info = MWIFIEX_SKB_TXCB(skb);
247 memset(tx_info, 0, sizeof(*tx_info));
248 tx_info->bss_num = priv->bss_num;
249 tx_info->bss_type = priv->bss_type;
250 tx_info->pkt_len = pkt_len;
251
252 mwifiex_form_mgmt_frame(skb, buf, len);
253 *cookie = prandom_u32() | 1;
254
255 if (ieee80211_is_action(mgmt->frame_control))
256 skb = mwifiex_clone_skb_for_tx_status(priv,
257 skb,
258 MWIFIEX_BUF_FLAG_ACTION_TX_STATUS, cookie);
259 else
260 cfg80211_mgmt_tx_status(wdev, *cookie, buf, len, true,
261 GFP_ATOMIC);
262
263 mwifiex_queue_tx_pkt(priv, skb);
264
265 mwifiex_dbg(priv->adapter, INFO, "info: management frame transmitted\n");
266 return 0;
267 }
268
269 /*
270 * CFG802.11 operation handler to register a mgmt frame.
271 */
272 static void
mwifiex_cfg80211_update_mgmt_frame_registrations(struct wiphy * wiphy,struct wireless_dev * wdev,struct mgmt_frame_regs * upd)273 mwifiex_cfg80211_update_mgmt_frame_registrations(struct wiphy *wiphy,
274 struct wireless_dev *wdev,
275 struct mgmt_frame_regs *upd)
276 {
277 struct mwifiex_private *priv = mwifiex_netdev_get_priv(wdev->netdev);
278 u32 mask = upd->interface_stypes;
279
280 if (mask != priv->mgmt_frame_mask) {
281 priv->mgmt_frame_mask = mask;
282 mwifiex_send_cmd(priv, HostCmd_CMD_MGMT_FRAME_REG,
283 HostCmd_ACT_GEN_SET, 0,
284 &priv->mgmt_frame_mask, false);
285 mwifiex_dbg(priv->adapter, INFO, "info: mgmt frame registered\n");
286 }
287 }
288
289 /*
290 * CFG802.11 operation handler to remain on channel.
291 */
292 static int
mwifiex_cfg80211_remain_on_channel(struct wiphy * wiphy,struct wireless_dev * wdev,struct ieee80211_channel * chan,unsigned int duration,u64 * cookie)293 mwifiex_cfg80211_remain_on_channel(struct wiphy *wiphy,
294 struct wireless_dev *wdev,
295 struct ieee80211_channel *chan,
296 unsigned int duration, u64 *cookie)
297 {
298 struct mwifiex_private *priv = mwifiex_netdev_get_priv(wdev->netdev);
299 int ret;
300
301 if (!chan || !cookie) {
302 mwifiex_dbg(priv->adapter, ERROR, "Invalid parameter for ROC\n");
303 return -EINVAL;
304 }
305
306 if (priv->roc_cfg.cookie) {
307 mwifiex_dbg(priv->adapter, INFO,
308 "info: ongoing ROC, cookie = 0x%llx\n",
309 priv->roc_cfg.cookie);
310 return -EBUSY;
311 }
312
313 ret = mwifiex_remain_on_chan_cfg(priv, HostCmd_ACT_GEN_SET, chan,
314 duration);
315
316 if (!ret) {
317 *cookie = prandom_u32() | 1;
318 priv->roc_cfg.cookie = *cookie;
319 priv->roc_cfg.chan = *chan;
320
321 cfg80211_ready_on_channel(wdev, *cookie, chan,
322 duration, GFP_ATOMIC);
323
324 mwifiex_dbg(priv->adapter, INFO,
325 "info: ROC, cookie = 0x%llx\n", *cookie);
326 }
327
328 return ret;
329 }
330
331 /*
332 * CFG802.11 operation handler to cancel remain on channel.
333 */
334 static int
mwifiex_cfg80211_cancel_remain_on_channel(struct wiphy * wiphy,struct wireless_dev * wdev,u64 cookie)335 mwifiex_cfg80211_cancel_remain_on_channel(struct wiphy *wiphy,
336 struct wireless_dev *wdev, u64 cookie)
337 {
338 struct mwifiex_private *priv = mwifiex_netdev_get_priv(wdev->netdev);
339 int ret;
340
341 if (cookie != priv->roc_cfg.cookie)
342 return -ENOENT;
343
344 ret = mwifiex_remain_on_chan_cfg(priv, HostCmd_ACT_GEN_REMOVE,
345 &priv->roc_cfg.chan, 0);
346
347 if (!ret) {
348 cfg80211_remain_on_channel_expired(wdev, cookie,
349 &priv->roc_cfg.chan,
350 GFP_ATOMIC);
351
352 memset(&priv->roc_cfg, 0, sizeof(struct mwifiex_roc_cfg));
353
354 mwifiex_dbg(priv->adapter, INFO,
355 "info: cancel ROC, cookie = 0x%llx\n", cookie);
356 }
357
358 return ret;
359 }
360
361 /*
362 * CFG802.11 operation handler to set Tx power.
363 */
364 static int
mwifiex_cfg80211_set_tx_power(struct wiphy * wiphy,struct wireless_dev * wdev,enum nl80211_tx_power_setting type,int mbm)365 mwifiex_cfg80211_set_tx_power(struct wiphy *wiphy,
366 struct wireless_dev *wdev,
367 enum nl80211_tx_power_setting type,
368 int mbm)
369 {
370 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
371 struct mwifiex_private *priv;
372 struct mwifiex_power_cfg power_cfg;
373 int dbm = MBM_TO_DBM(mbm);
374
375 switch (type) {
376 case NL80211_TX_POWER_FIXED:
377 power_cfg.is_power_auto = 0;
378 power_cfg.is_power_fixed = 1;
379 power_cfg.power_level = dbm;
380 break;
381 case NL80211_TX_POWER_LIMITED:
382 power_cfg.is_power_auto = 0;
383 power_cfg.is_power_fixed = 0;
384 power_cfg.power_level = dbm;
385 break;
386 case NL80211_TX_POWER_AUTOMATIC:
387 power_cfg.is_power_auto = 1;
388 break;
389 }
390
391 priv = mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY);
392
393 return mwifiex_set_tx_power(priv, &power_cfg);
394 }
395
396 /*
397 * CFG802.11 operation handler to get Tx power.
398 */
399 static int
mwifiex_cfg80211_get_tx_power(struct wiphy * wiphy,struct wireless_dev * wdev,int * dbm)400 mwifiex_cfg80211_get_tx_power(struct wiphy *wiphy,
401 struct wireless_dev *wdev,
402 int *dbm)
403 {
404 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
405 struct mwifiex_private *priv = mwifiex_get_priv(adapter,
406 MWIFIEX_BSS_ROLE_ANY);
407 int ret = mwifiex_send_cmd(priv, HostCmd_CMD_RF_TX_PWR,
408 HostCmd_ACT_GEN_GET, 0, NULL, true);
409
410 if (ret < 0)
411 return ret;
412
413 /* tx_power_level is set in HostCmd_CMD_RF_TX_PWR command handler */
414 *dbm = priv->tx_power_level;
415
416 return 0;
417 }
418
419 /*
420 * CFG802.11 operation handler to set Power Save option.
421 *
422 * The timeout value, if provided, is currently ignored.
423 */
424 static int
mwifiex_cfg80211_set_power_mgmt(struct wiphy * wiphy,struct net_device * dev,bool enabled,int timeout)425 mwifiex_cfg80211_set_power_mgmt(struct wiphy *wiphy,
426 struct net_device *dev,
427 bool enabled, int timeout)
428 {
429 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
430 u32 ps_mode;
431
432 if (timeout)
433 mwifiex_dbg(priv->adapter, INFO,
434 "info: ignore timeout value for IEEE Power Save\n");
435
436 ps_mode = enabled;
437
438 return mwifiex_drv_set_power(priv, &ps_mode);
439 }
440
441 /*
442 * CFG802.11 operation handler to set the default network key.
443 */
444 static int
mwifiex_cfg80211_set_default_key(struct wiphy * wiphy,struct net_device * netdev,u8 key_index,bool unicast,bool multicast)445 mwifiex_cfg80211_set_default_key(struct wiphy *wiphy, struct net_device *netdev,
446 u8 key_index, bool unicast,
447 bool multicast)
448 {
449 struct mwifiex_private *priv = mwifiex_netdev_get_priv(netdev);
450
451 /* Return if WEP key not configured */
452 if (!priv->sec_info.wep_enabled)
453 return 0;
454
455 if (priv->bss_type == MWIFIEX_BSS_TYPE_UAP) {
456 priv->wep_key_curr_index = key_index;
457 } else if (mwifiex_set_encode(priv, NULL, NULL, 0, key_index,
458 NULL, 0)) {
459 mwifiex_dbg(priv->adapter, ERROR, "set default Tx key index\n");
460 return -EFAULT;
461 }
462
463 return 0;
464 }
465
466 /*
467 * CFG802.11 operation handler to add a network key.
468 */
469 static int
mwifiex_cfg80211_add_key(struct wiphy * wiphy,struct net_device * netdev,u8 key_index,bool pairwise,const u8 * mac_addr,struct key_params * params)470 mwifiex_cfg80211_add_key(struct wiphy *wiphy, struct net_device *netdev,
471 u8 key_index, bool pairwise, const u8 *mac_addr,
472 struct key_params *params)
473 {
474 struct mwifiex_private *priv = mwifiex_netdev_get_priv(netdev);
475 struct mwifiex_wep_key *wep_key;
476 static const u8 bc_mac[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
477 const u8 *peer_mac = pairwise ? mac_addr : bc_mac;
478
479 if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_UAP &&
480 (params->cipher == WLAN_CIPHER_SUITE_WEP40 ||
481 params->cipher == WLAN_CIPHER_SUITE_WEP104)) {
482 if (params->key && params->key_len) {
483 wep_key = &priv->wep_key[key_index];
484 memset(wep_key, 0, sizeof(struct mwifiex_wep_key));
485 memcpy(wep_key->key_material, params->key,
486 params->key_len);
487 wep_key->key_index = key_index;
488 wep_key->key_length = params->key_len;
489 priv->sec_info.wep_enabled = 1;
490 }
491 return 0;
492 }
493
494 if (mwifiex_set_encode(priv, params, params->key, params->key_len,
495 key_index, peer_mac, 0)) {
496 mwifiex_dbg(priv->adapter, ERROR, "crypto keys added\n");
497 return -EFAULT;
498 }
499
500 return 0;
501 }
502
503 /*
504 * CFG802.11 operation handler to set default mgmt key.
505 */
506 static int
mwifiex_cfg80211_set_default_mgmt_key(struct wiphy * wiphy,struct net_device * netdev,u8 key_index)507 mwifiex_cfg80211_set_default_mgmt_key(struct wiphy *wiphy,
508 struct net_device *netdev,
509 u8 key_index)
510 {
511 struct mwifiex_private *priv = mwifiex_netdev_get_priv(netdev);
512 struct mwifiex_ds_encrypt_key encrypt_key;
513
514 wiphy_dbg(wiphy, "set default mgmt key, key index=%d\n", key_index);
515
516 memset(&encrypt_key, 0, sizeof(struct mwifiex_ds_encrypt_key));
517 encrypt_key.key_len = WLAN_KEY_LEN_CCMP;
518 encrypt_key.key_index = key_index;
519 encrypt_key.is_igtk_def_key = true;
520 eth_broadcast_addr(encrypt_key.mac_addr);
521
522 return mwifiex_send_cmd(priv, HostCmd_CMD_802_11_KEY_MATERIAL,
523 HostCmd_ACT_GEN_SET, true, &encrypt_key, true);
524 }
525
526 /*
527 * This function sends domain information to the firmware.
528 *
529 * The following information are passed to the firmware -
530 * - Country codes
531 * - Sub bands (first channel, number of channels, maximum Tx power)
532 */
mwifiex_send_domain_info_cmd_fw(struct wiphy * wiphy)533 int mwifiex_send_domain_info_cmd_fw(struct wiphy *wiphy)
534 {
535 u8 no_of_triplet = 0;
536 struct ieee80211_country_ie_triplet *t;
537 u8 no_of_parsed_chan = 0;
538 u8 first_chan = 0, next_chan = 0, max_pwr = 0;
539 u8 i, flag = 0;
540 enum nl80211_band band;
541 struct ieee80211_supported_band *sband;
542 struct ieee80211_channel *ch;
543 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
544 struct mwifiex_private *priv;
545 struct mwifiex_802_11d_domain_reg *domain_info = &adapter->domain_reg;
546
547 /* Set country code */
548 domain_info->country_code[0] = adapter->country_code[0];
549 domain_info->country_code[1] = adapter->country_code[1];
550 domain_info->country_code[2] = ' ';
551
552 band = mwifiex_band_to_radio_type(adapter->config_bands);
553 if (!wiphy->bands[band]) {
554 mwifiex_dbg(adapter, ERROR,
555 "11D: setting domain info in FW\n");
556 return -1;
557 }
558
559 sband = wiphy->bands[band];
560
561 for (i = 0; i < sband->n_channels ; i++) {
562 ch = &sband->channels[i];
563 if (ch->flags & IEEE80211_CHAN_DISABLED)
564 continue;
565
566 if (!flag) {
567 flag = 1;
568 first_chan = (u32) ch->hw_value;
569 next_chan = first_chan;
570 max_pwr = ch->max_power;
571 no_of_parsed_chan = 1;
572 continue;
573 }
574
575 if (ch->hw_value == next_chan + 1 &&
576 ch->max_power == max_pwr) {
577 next_chan++;
578 no_of_parsed_chan++;
579 } else {
580 t = &domain_info->triplet[no_of_triplet];
581 t->chans.first_channel = first_chan;
582 t->chans.num_channels = no_of_parsed_chan;
583 t->chans.max_power = max_pwr;
584 no_of_triplet++;
585 first_chan = (u32) ch->hw_value;
586 next_chan = first_chan;
587 max_pwr = ch->max_power;
588 no_of_parsed_chan = 1;
589 }
590 }
591
592 if (flag) {
593 t = &domain_info->triplet[no_of_triplet];
594 t->chans.first_channel = first_chan;
595 t->chans.num_channels = no_of_parsed_chan;
596 t->chans.max_power = max_pwr;
597 no_of_triplet++;
598 }
599
600 domain_info->no_of_triplet = no_of_triplet;
601
602 priv = mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY);
603
604 if (mwifiex_send_cmd(priv, HostCmd_CMD_802_11D_DOMAIN_INFO,
605 HostCmd_ACT_GEN_SET, 0, NULL, false)) {
606 mwifiex_dbg(adapter, INFO,
607 "11D: setting domain info in FW\n");
608 return -1;
609 }
610
611 return 0;
612 }
613
mwifiex_reg_apply_radar_flags(struct wiphy * wiphy)614 static void mwifiex_reg_apply_radar_flags(struct wiphy *wiphy)
615 {
616 struct ieee80211_supported_band *sband;
617 struct ieee80211_channel *chan;
618 unsigned int i;
619
620 if (!wiphy->bands[NL80211_BAND_5GHZ])
621 return;
622 sband = wiphy->bands[NL80211_BAND_5GHZ];
623
624 for (i = 0; i < sband->n_channels; i++) {
625 chan = &sband->channels[i];
626 if ((!(chan->flags & IEEE80211_CHAN_DISABLED)) &&
627 (chan->flags & IEEE80211_CHAN_RADAR))
628 chan->flags |= IEEE80211_CHAN_NO_IR;
629 }
630 }
631
632 /*
633 * CFG802.11 regulatory domain callback function.
634 *
635 * This function is called when the regulatory domain is changed due to the
636 * following reasons -
637 * - Set by driver
638 * - Set by system core
639 * - Set by user
640 * - Set bt Country IE
641 */
mwifiex_reg_notifier(struct wiphy * wiphy,struct regulatory_request * request)642 static void mwifiex_reg_notifier(struct wiphy *wiphy,
643 struct regulatory_request *request)
644 {
645 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
646 struct mwifiex_private *priv = mwifiex_get_priv(adapter,
647 MWIFIEX_BSS_ROLE_ANY);
648 mwifiex_dbg(adapter, INFO,
649 "info: cfg80211 regulatory domain callback for %c%c\n",
650 request->alpha2[0], request->alpha2[1]);
651 mwifiex_reg_apply_radar_flags(wiphy);
652
653 switch (request->initiator) {
654 case NL80211_REGDOM_SET_BY_DRIVER:
655 case NL80211_REGDOM_SET_BY_CORE:
656 case NL80211_REGDOM_SET_BY_USER:
657 case NL80211_REGDOM_SET_BY_COUNTRY_IE:
658 break;
659 default:
660 mwifiex_dbg(adapter, ERROR,
661 "unknown regdom initiator: %d\n",
662 request->initiator);
663 return;
664 }
665
666 /* Don't send world or same regdom info to firmware */
667 if (strncmp(request->alpha2, "00", 2) &&
668 strncmp(request->alpha2, adapter->country_code,
669 sizeof(request->alpha2))) {
670 memcpy(adapter->country_code, request->alpha2,
671 sizeof(request->alpha2));
672 mwifiex_send_domain_info_cmd_fw(wiphy);
673 mwifiex_dnld_txpwr_table(priv);
674 }
675 }
676
677 /*
678 * This function sets the fragmentation threshold.
679 *
680 * The fragmentation threshold value must lie between MWIFIEX_FRAG_MIN_VALUE
681 * and MWIFIEX_FRAG_MAX_VALUE.
682 */
683 static int
mwifiex_set_frag(struct mwifiex_private * priv,u32 frag_thr)684 mwifiex_set_frag(struct mwifiex_private *priv, u32 frag_thr)
685 {
686 if (frag_thr < MWIFIEX_FRAG_MIN_VALUE ||
687 frag_thr > MWIFIEX_FRAG_MAX_VALUE)
688 frag_thr = MWIFIEX_FRAG_MAX_VALUE;
689
690 return mwifiex_send_cmd(priv, HostCmd_CMD_802_11_SNMP_MIB,
691 HostCmd_ACT_GEN_SET, FRAG_THRESH_I,
692 &frag_thr, true);
693 }
694
695 /*
696 * This function sets the RTS threshold.
697
698 * The rts value must lie between MWIFIEX_RTS_MIN_VALUE
699 * and MWIFIEX_RTS_MAX_VALUE.
700 */
701 static int
mwifiex_set_rts(struct mwifiex_private * priv,u32 rts_thr)702 mwifiex_set_rts(struct mwifiex_private *priv, u32 rts_thr)
703 {
704 if (rts_thr < MWIFIEX_RTS_MIN_VALUE || rts_thr > MWIFIEX_RTS_MAX_VALUE)
705 rts_thr = MWIFIEX_RTS_MAX_VALUE;
706
707 return mwifiex_send_cmd(priv, HostCmd_CMD_802_11_SNMP_MIB,
708 HostCmd_ACT_GEN_SET, RTS_THRESH_I,
709 &rts_thr, true);
710 }
711
712 /*
713 * CFG802.11 operation handler to set wiphy parameters.
714 *
715 * This function can be used to set the RTS threshold and the
716 * Fragmentation threshold of the driver.
717 */
718 static int
mwifiex_cfg80211_set_wiphy_params(struct wiphy * wiphy,u32 changed)719 mwifiex_cfg80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
720 {
721 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
722 struct mwifiex_private *priv;
723 struct mwifiex_uap_bss_param *bss_cfg;
724 int ret;
725
726 priv = mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY);
727
728 switch (priv->bss_role) {
729 case MWIFIEX_BSS_ROLE_UAP:
730 if (priv->bss_started) {
731 mwifiex_dbg(adapter, ERROR,
732 "cannot change wiphy params when bss started");
733 return -EINVAL;
734 }
735
736 bss_cfg = kzalloc(sizeof(*bss_cfg), GFP_KERNEL);
737 if (!bss_cfg)
738 return -ENOMEM;
739
740 mwifiex_set_sys_config_invalid_data(bss_cfg);
741
742 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
743 bss_cfg->rts_threshold = wiphy->rts_threshold;
744 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
745 bss_cfg->frag_threshold = wiphy->frag_threshold;
746 if (changed & WIPHY_PARAM_RETRY_LONG)
747 bss_cfg->retry_limit = wiphy->retry_long;
748
749 ret = mwifiex_send_cmd(priv, HostCmd_CMD_UAP_SYS_CONFIG,
750 HostCmd_ACT_GEN_SET,
751 UAP_BSS_PARAMS_I, bss_cfg,
752 false);
753
754 kfree(bss_cfg);
755 if (ret) {
756 mwifiex_dbg(adapter, ERROR,
757 "Failed to set wiphy phy params\n");
758 return ret;
759 }
760 break;
761
762 case MWIFIEX_BSS_ROLE_STA:
763 if (priv->media_connected) {
764 mwifiex_dbg(adapter, ERROR,
765 "cannot change wiphy params when connected");
766 return -EINVAL;
767 }
768 if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
769 ret = mwifiex_set_rts(priv,
770 wiphy->rts_threshold);
771 if (ret)
772 return ret;
773 }
774 if (changed & WIPHY_PARAM_FRAG_THRESHOLD) {
775 ret = mwifiex_set_frag(priv,
776 wiphy->frag_threshold);
777 if (ret)
778 return ret;
779 }
780 break;
781 }
782
783 return 0;
784 }
785
786 static int
mwifiex_cfg80211_deinit_p2p(struct mwifiex_private * priv)787 mwifiex_cfg80211_deinit_p2p(struct mwifiex_private *priv)
788 {
789 u16 mode = P2P_MODE_DISABLE;
790
791 if (mwifiex_send_cmd(priv, HostCmd_CMD_P2P_MODE_CFG,
792 HostCmd_ACT_GEN_SET, 0, &mode, true))
793 return -1;
794
795 return 0;
796 }
797
798 /*
799 * This function initializes the functionalities for P2P client.
800 * The P2P client initialization sequence is:
801 * disable -> device -> client
802 */
803 static int
mwifiex_cfg80211_init_p2p_client(struct mwifiex_private * priv)804 mwifiex_cfg80211_init_p2p_client(struct mwifiex_private *priv)
805 {
806 u16 mode;
807
808 if (mwifiex_cfg80211_deinit_p2p(priv))
809 return -1;
810
811 mode = P2P_MODE_DEVICE;
812 if (mwifiex_send_cmd(priv, HostCmd_CMD_P2P_MODE_CFG,
813 HostCmd_ACT_GEN_SET, 0, &mode, true))
814 return -1;
815
816 mode = P2P_MODE_CLIENT;
817 if (mwifiex_send_cmd(priv, HostCmd_CMD_P2P_MODE_CFG,
818 HostCmd_ACT_GEN_SET, 0, &mode, true))
819 return -1;
820
821 return 0;
822 }
823
824 /*
825 * This function initializes the functionalities for P2P GO.
826 * The P2P GO initialization sequence is:
827 * disable -> device -> GO
828 */
829 static int
mwifiex_cfg80211_init_p2p_go(struct mwifiex_private * priv)830 mwifiex_cfg80211_init_p2p_go(struct mwifiex_private *priv)
831 {
832 u16 mode;
833
834 if (mwifiex_cfg80211_deinit_p2p(priv))
835 return -1;
836
837 mode = P2P_MODE_DEVICE;
838 if (mwifiex_send_cmd(priv, HostCmd_CMD_P2P_MODE_CFG,
839 HostCmd_ACT_GEN_SET, 0, &mode, true))
840 return -1;
841
842 mode = P2P_MODE_GO;
843 if (mwifiex_send_cmd(priv, HostCmd_CMD_P2P_MODE_CFG,
844 HostCmd_ACT_GEN_SET, 0, &mode, true))
845 return -1;
846
847 return 0;
848 }
849
mwifiex_deinit_priv_params(struct mwifiex_private * priv)850 static int mwifiex_deinit_priv_params(struct mwifiex_private *priv)
851 {
852 struct mwifiex_adapter *adapter = priv->adapter;
853 unsigned long flags;
854
855 priv->mgmt_frame_mask = 0;
856 if (mwifiex_send_cmd(priv, HostCmd_CMD_MGMT_FRAME_REG,
857 HostCmd_ACT_GEN_SET, 0,
858 &priv->mgmt_frame_mask, false)) {
859 mwifiex_dbg(adapter, ERROR,
860 "could not unregister mgmt frame rx\n");
861 return -1;
862 }
863
864 mwifiex_deauthenticate(priv, NULL);
865
866 spin_lock_irqsave(&adapter->main_proc_lock, flags);
867 adapter->main_locked = true;
868 if (adapter->mwifiex_processing) {
869 spin_unlock_irqrestore(&adapter->main_proc_lock, flags);
870 flush_workqueue(adapter->workqueue);
871 } else {
872 spin_unlock_irqrestore(&adapter->main_proc_lock, flags);
873 }
874
875 spin_lock_bh(&adapter->rx_proc_lock);
876 adapter->rx_locked = true;
877 if (adapter->rx_processing) {
878 spin_unlock_bh(&adapter->rx_proc_lock);
879 flush_workqueue(adapter->rx_workqueue);
880 } else {
881 spin_unlock_bh(&adapter->rx_proc_lock);
882 }
883
884 mwifiex_free_priv(priv);
885 priv->wdev.iftype = NL80211_IFTYPE_UNSPECIFIED;
886 priv->bss_mode = NL80211_IFTYPE_UNSPECIFIED;
887 priv->sec_info.authentication_mode = NL80211_AUTHTYPE_OPEN_SYSTEM;
888
889 return 0;
890 }
891
892 static int
mwifiex_init_new_priv_params(struct mwifiex_private * priv,struct net_device * dev,enum nl80211_iftype type)893 mwifiex_init_new_priv_params(struct mwifiex_private *priv,
894 struct net_device *dev,
895 enum nl80211_iftype type)
896 {
897 struct mwifiex_adapter *adapter = priv->adapter;
898 unsigned long flags;
899
900 mwifiex_init_priv(priv);
901
902 priv->bss_mode = type;
903 priv->wdev.iftype = type;
904
905 mwifiex_init_priv_params(priv, priv->netdev);
906 priv->bss_started = 0;
907
908 switch (type) {
909 case NL80211_IFTYPE_STATION:
910 case NL80211_IFTYPE_ADHOC:
911 priv->bss_role = MWIFIEX_BSS_ROLE_STA;
912 priv->bss_type = MWIFIEX_BSS_TYPE_STA;
913 break;
914 case NL80211_IFTYPE_P2P_CLIENT:
915 priv->bss_role = MWIFIEX_BSS_ROLE_STA;
916 priv->bss_type = MWIFIEX_BSS_TYPE_P2P;
917 break;
918 case NL80211_IFTYPE_P2P_GO:
919 priv->bss_role = MWIFIEX_BSS_ROLE_UAP;
920 priv->bss_type = MWIFIEX_BSS_TYPE_P2P;
921 break;
922 case NL80211_IFTYPE_AP:
923 priv->bss_role = MWIFIEX_BSS_ROLE_UAP;
924 priv->bss_type = MWIFIEX_BSS_TYPE_UAP;
925 break;
926 default:
927 mwifiex_dbg(adapter, ERROR,
928 "%s: changing to %d not supported\n",
929 dev->name, type);
930 return -EOPNOTSUPP;
931 }
932
933 spin_lock_irqsave(&adapter->main_proc_lock, flags);
934 adapter->main_locked = false;
935 spin_unlock_irqrestore(&adapter->main_proc_lock, flags);
936
937 spin_lock_bh(&adapter->rx_proc_lock);
938 adapter->rx_locked = false;
939 spin_unlock_bh(&adapter->rx_proc_lock);
940
941 mwifiex_set_mac_address(priv, dev, false, NULL);
942
943 return 0;
944 }
945
946 static int
mwifiex_change_vif_to_p2p(struct net_device * dev,enum nl80211_iftype curr_iftype,enum nl80211_iftype type,struct vif_params * params)947 mwifiex_change_vif_to_p2p(struct net_device *dev,
948 enum nl80211_iftype curr_iftype,
949 enum nl80211_iftype type,
950 struct vif_params *params)
951 {
952 struct mwifiex_private *priv;
953 struct mwifiex_adapter *adapter;
954
955 priv = mwifiex_netdev_get_priv(dev);
956
957 if (!priv)
958 return -1;
959
960 adapter = priv->adapter;
961
962 if (adapter->curr_iface_comb.p2p_intf ==
963 adapter->iface_limit.p2p_intf) {
964 mwifiex_dbg(adapter, ERROR,
965 "cannot create multiple P2P ifaces\n");
966 return -1;
967 }
968
969 mwifiex_dbg(adapter, INFO,
970 "%s: changing role to p2p\n", dev->name);
971
972 if (mwifiex_deinit_priv_params(priv))
973 return -1;
974 if (mwifiex_init_new_priv_params(priv, dev, type))
975 return -1;
976
977 switch (type) {
978 case NL80211_IFTYPE_P2P_CLIENT:
979 if (mwifiex_cfg80211_init_p2p_client(priv))
980 return -EFAULT;
981 break;
982 case NL80211_IFTYPE_P2P_GO:
983 if (mwifiex_cfg80211_init_p2p_go(priv))
984 return -EFAULT;
985 break;
986 default:
987 mwifiex_dbg(adapter, ERROR,
988 "%s: changing to %d not supported\n",
989 dev->name, type);
990 return -EOPNOTSUPP;
991 }
992
993 if (mwifiex_send_cmd(priv, HostCmd_CMD_SET_BSS_MODE,
994 HostCmd_ACT_GEN_SET, 0, NULL, true))
995 return -1;
996
997 if (mwifiex_sta_init_cmd(priv, false, false))
998 return -1;
999
1000 switch (curr_iftype) {
1001 case NL80211_IFTYPE_STATION:
1002 case NL80211_IFTYPE_ADHOC:
1003 adapter->curr_iface_comb.sta_intf--;
1004 break;
1005 case NL80211_IFTYPE_AP:
1006 adapter->curr_iface_comb.uap_intf--;
1007 break;
1008 default:
1009 break;
1010 }
1011
1012 adapter->curr_iface_comb.p2p_intf++;
1013 dev->ieee80211_ptr->iftype = type;
1014
1015 return 0;
1016 }
1017
1018 static int
mwifiex_change_vif_to_sta_adhoc(struct net_device * dev,enum nl80211_iftype curr_iftype,enum nl80211_iftype type,struct vif_params * params)1019 mwifiex_change_vif_to_sta_adhoc(struct net_device *dev,
1020 enum nl80211_iftype curr_iftype,
1021 enum nl80211_iftype type,
1022 struct vif_params *params)
1023 {
1024 struct mwifiex_private *priv;
1025 struct mwifiex_adapter *adapter;
1026
1027 priv = mwifiex_netdev_get_priv(dev);
1028
1029 if (!priv)
1030 return -1;
1031
1032 adapter = priv->adapter;
1033
1034 if ((curr_iftype != NL80211_IFTYPE_P2P_CLIENT &&
1035 curr_iftype != NL80211_IFTYPE_P2P_GO) &&
1036 (adapter->curr_iface_comb.sta_intf ==
1037 adapter->iface_limit.sta_intf)) {
1038 mwifiex_dbg(adapter, ERROR,
1039 "cannot create multiple station/adhoc ifaces\n");
1040 return -1;
1041 }
1042
1043 if (type == NL80211_IFTYPE_STATION)
1044 mwifiex_dbg(adapter, INFO,
1045 "%s: changing role to station\n", dev->name);
1046 else
1047 mwifiex_dbg(adapter, INFO,
1048 "%s: changing role to adhoc\n", dev->name);
1049
1050 if (mwifiex_deinit_priv_params(priv))
1051 return -1;
1052 if (mwifiex_init_new_priv_params(priv, dev, type))
1053 return -1;
1054 if (mwifiex_send_cmd(priv, HostCmd_CMD_SET_BSS_MODE,
1055 HostCmd_ACT_GEN_SET, 0, NULL, true))
1056 return -1;
1057 if (mwifiex_sta_init_cmd(priv, false, false))
1058 return -1;
1059
1060 switch (curr_iftype) {
1061 case NL80211_IFTYPE_P2P_CLIENT:
1062 case NL80211_IFTYPE_P2P_GO:
1063 adapter->curr_iface_comb.p2p_intf--;
1064 break;
1065 case NL80211_IFTYPE_AP:
1066 adapter->curr_iface_comb.uap_intf--;
1067 break;
1068 default:
1069 break;
1070 }
1071
1072 adapter->curr_iface_comb.sta_intf++;
1073 dev->ieee80211_ptr->iftype = type;
1074 return 0;
1075 }
1076
1077 static int
mwifiex_change_vif_to_ap(struct net_device * dev,enum nl80211_iftype curr_iftype,enum nl80211_iftype type,struct vif_params * params)1078 mwifiex_change_vif_to_ap(struct net_device *dev,
1079 enum nl80211_iftype curr_iftype,
1080 enum nl80211_iftype type,
1081 struct vif_params *params)
1082 {
1083 struct mwifiex_private *priv;
1084 struct mwifiex_adapter *adapter;
1085
1086 priv = mwifiex_netdev_get_priv(dev);
1087
1088 if (!priv)
1089 return -1;
1090
1091 adapter = priv->adapter;
1092
1093 if (adapter->curr_iface_comb.uap_intf ==
1094 adapter->iface_limit.uap_intf) {
1095 mwifiex_dbg(adapter, ERROR,
1096 "cannot create multiple AP ifaces\n");
1097 return -1;
1098 }
1099
1100 mwifiex_dbg(adapter, INFO,
1101 "%s: changing role to AP\n", dev->name);
1102
1103 if (mwifiex_deinit_priv_params(priv))
1104 return -1;
1105 if (mwifiex_init_new_priv_params(priv, dev, type))
1106 return -1;
1107 if (mwifiex_send_cmd(priv, HostCmd_CMD_SET_BSS_MODE,
1108 HostCmd_ACT_GEN_SET, 0, NULL, true))
1109 return -1;
1110 if (mwifiex_sta_init_cmd(priv, false, false))
1111 return -1;
1112
1113 switch (curr_iftype) {
1114 case NL80211_IFTYPE_P2P_CLIENT:
1115 case NL80211_IFTYPE_P2P_GO:
1116 adapter->curr_iface_comb.p2p_intf--;
1117 break;
1118 case NL80211_IFTYPE_STATION:
1119 case NL80211_IFTYPE_ADHOC:
1120 adapter->curr_iface_comb.sta_intf--;
1121 break;
1122 default:
1123 break;
1124 }
1125
1126 adapter->curr_iface_comb.uap_intf++;
1127 dev->ieee80211_ptr->iftype = type;
1128 return 0;
1129 }
1130 /*
1131 * CFG802.11 operation handler to change interface type.
1132 */
1133 static int
mwifiex_cfg80211_change_virtual_intf(struct wiphy * wiphy,struct net_device * dev,enum nl80211_iftype type,struct vif_params * params)1134 mwifiex_cfg80211_change_virtual_intf(struct wiphy *wiphy,
1135 struct net_device *dev,
1136 enum nl80211_iftype type,
1137 struct vif_params *params)
1138 {
1139 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
1140 enum nl80211_iftype curr_iftype = dev->ieee80211_ptr->iftype;
1141
1142 if (priv->scan_request) {
1143 mwifiex_dbg(priv->adapter, ERROR,
1144 "change virtual interface: scan in process\n");
1145 return -EBUSY;
1146 }
1147
1148 switch (curr_iftype) {
1149 case NL80211_IFTYPE_ADHOC:
1150 switch (type) {
1151 case NL80211_IFTYPE_STATION:
1152 priv->bss_mode = type;
1153 priv->sec_info.authentication_mode =
1154 NL80211_AUTHTYPE_OPEN_SYSTEM;
1155 dev->ieee80211_ptr->iftype = type;
1156 mwifiex_deauthenticate(priv, NULL);
1157 return mwifiex_send_cmd(priv, HostCmd_CMD_SET_BSS_MODE,
1158 HostCmd_ACT_GEN_SET, 0, NULL,
1159 true);
1160 case NL80211_IFTYPE_P2P_CLIENT:
1161 case NL80211_IFTYPE_P2P_GO:
1162 return mwifiex_change_vif_to_p2p(dev, curr_iftype,
1163 type, params);
1164 case NL80211_IFTYPE_AP:
1165 return mwifiex_change_vif_to_ap(dev, curr_iftype, type,
1166 params);
1167 case NL80211_IFTYPE_UNSPECIFIED:
1168 mwifiex_dbg(priv->adapter, INFO,
1169 "%s: kept type as IBSS\n", dev->name);
1170 fallthrough;
1171 case NL80211_IFTYPE_ADHOC: /* This shouldn't happen */
1172 return 0;
1173 default:
1174 mwifiex_dbg(priv->adapter, ERROR,
1175 "%s: changing to %d not supported\n",
1176 dev->name, type);
1177 return -EOPNOTSUPP;
1178 }
1179 break;
1180 case NL80211_IFTYPE_STATION:
1181 switch (type) {
1182 case NL80211_IFTYPE_ADHOC:
1183 priv->bss_mode = type;
1184 priv->sec_info.authentication_mode =
1185 NL80211_AUTHTYPE_OPEN_SYSTEM;
1186 dev->ieee80211_ptr->iftype = type;
1187 mwifiex_deauthenticate(priv, NULL);
1188 return mwifiex_send_cmd(priv, HostCmd_CMD_SET_BSS_MODE,
1189 HostCmd_ACT_GEN_SET, 0, NULL,
1190 true);
1191 case NL80211_IFTYPE_P2P_CLIENT:
1192 case NL80211_IFTYPE_P2P_GO:
1193 return mwifiex_change_vif_to_p2p(dev, curr_iftype,
1194 type, params);
1195 case NL80211_IFTYPE_AP:
1196 return mwifiex_change_vif_to_ap(dev, curr_iftype, type,
1197 params);
1198 case NL80211_IFTYPE_UNSPECIFIED:
1199 mwifiex_dbg(priv->adapter, INFO,
1200 "%s: kept type as STA\n", dev->name);
1201 fallthrough;
1202 case NL80211_IFTYPE_STATION: /* This shouldn't happen */
1203 return 0;
1204 default:
1205 mwifiex_dbg(priv->adapter, ERROR,
1206 "%s: changing to %d not supported\n",
1207 dev->name, type);
1208 return -EOPNOTSUPP;
1209 }
1210 break;
1211 case NL80211_IFTYPE_AP:
1212 switch (type) {
1213 case NL80211_IFTYPE_ADHOC:
1214 return mwifiex_change_vif_to_sta_adhoc(dev, curr_iftype,
1215 type, params);
1216 break;
1217 case NL80211_IFTYPE_P2P_CLIENT:
1218 case NL80211_IFTYPE_P2P_GO:
1219 return mwifiex_change_vif_to_p2p(dev, curr_iftype,
1220 type, params);
1221 case NL80211_IFTYPE_UNSPECIFIED:
1222 mwifiex_dbg(priv->adapter, INFO,
1223 "%s: kept type as AP\n", dev->name);
1224 fallthrough;
1225 case NL80211_IFTYPE_AP: /* This shouldn't happen */
1226 return 0;
1227 default:
1228 mwifiex_dbg(priv->adapter, ERROR,
1229 "%s: changing to %d not supported\n",
1230 dev->name, type);
1231 return -EOPNOTSUPP;
1232 }
1233 break;
1234 case NL80211_IFTYPE_P2P_CLIENT:
1235 case NL80211_IFTYPE_P2P_GO:
1236 if (mwifiex_cfg80211_deinit_p2p(priv))
1237 return -EFAULT;
1238
1239 switch (type) {
1240 case NL80211_IFTYPE_ADHOC:
1241 case NL80211_IFTYPE_STATION:
1242 return mwifiex_change_vif_to_sta_adhoc(dev, curr_iftype,
1243 type, params);
1244 case NL80211_IFTYPE_AP:
1245 return mwifiex_change_vif_to_ap(dev, curr_iftype, type,
1246 params);
1247 case NL80211_IFTYPE_UNSPECIFIED:
1248 mwifiex_dbg(priv->adapter, INFO,
1249 "%s: kept type as P2P\n", dev->name);
1250 fallthrough;
1251 case NL80211_IFTYPE_P2P_CLIENT:
1252 case NL80211_IFTYPE_P2P_GO:
1253 return 0;
1254 default:
1255 mwifiex_dbg(priv->adapter, ERROR,
1256 "%s: changing to %d not supported\n",
1257 dev->name, type);
1258 return -EOPNOTSUPP;
1259 }
1260 break;
1261 default:
1262 mwifiex_dbg(priv->adapter, ERROR,
1263 "%s: unknown iftype: %d\n",
1264 dev->name, dev->ieee80211_ptr->iftype);
1265 return -EOPNOTSUPP;
1266 }
1267
1268
1269 return 0;
1270 }
1271
1272 static void
mwifiex_parse_htinfo(struct mwifiex_private * priv,u8 rateinfo,u8 htinfo,struct rate_info * rate)1273 mwifiex_parse_htinfo(struct mwifiex_private *priv, u8 rateinfo, u8 htinfo,
1274 struct rate_info *rate)
1275 {
1276 struct mwifiex_adapter *adapter = priv->adapter;
1277
1278 if (adapter->is_hw_11ac_capable) {
1279 /* bit[1-0]: 00=LG 01=HT 10=VHT */
1280 if (htinfo & BIT(0)) {
1281 /* HT */
1282 rate->mcs = rateinfo;
1283 rate->flags |= RATE_INFO_FLAGS_MCS;
1284 }
1285 if (htinfo & BIT(1)) {
1286 /* VHT */
1287 rate->mcs = rateinfo & 0x0F;
1288 rate->flags |= RATE_INFO_FLAGS_VHT_MCS;
1289 }
1290
1291 if (htinfo & (BIT(1) | BIT(0))) {
1292 /* HT or VHT */
1293 switch (htinfo & (BIT(3) | BIT(2))) {
1294 case 0:
1295 rate->bw = RATE_INFO_BW_20;
1296 break;
1297 case (BIT(2)):
1298 rate->bw = RATE_INFO_BW_40;
1299 break;
1300 case (BIT(3)):
1301 rate->bw = RATE_INFO_BW_80;
1302 break;
1303 case (BIT(3) | BIT(2)):
1304 rate->bw = RATE_INFO_BW_160;
1305 break;
1306 }
1307
1308 if (htinfo & BIT(4))
1309 rate->flags |= RATE_INFO_FLAGS_SHORT_GI;
1310
1311 if ((rateinfo >> 4) == 1)
1312 rate->nss = 2;
1313 else
1314 rate->nss = 1;
1315 }
1316 } else {
1317 /*
1318 * Bit 0 in htinfo indicates that current rate is 11n. Valid
1319 * MCS index values for us are 0 to 15.
1320 */
1321 if ((htinfo & BIT(0)) && (rateinfo < 16)) {
1322 rate->mcs = rateinfo;
1323 rate->flags |= RATE_INFO_FLAGS_MCS;
1324 rate->bw = RATE_INFO_BW_20;
1325 if (htinfo & BIT(1))
1326 rate->bw = RATE_INFO_BW_40;
1327 if (htinfo & BIT(2))
1328 rate->flags |= RATE_INFO_FLAGS_SHORT_GI;
1329 }
1330 }
1331
1332 /* Decode legacy rates for non-HT. */
1333 if (!(htinfo & (BIT(0) | BIT(1)))) {
1334 /* Bitrates in multiples of 100kb/s. */
1335 static const int legacy_rates[] = {
1336 [0] = 10,
1337 [1] = 20,
1338 [2] = 55,
1339 [3] = 110,
1340 [4] = 60, /* MWIFIEX_RATE_INDEX_OFDM0 */
1341 [5] = 60,
1342 [6] = 90,
1343 [7] = 120,
1344 [8] = 180,
1345 [9] = 240,
1346 [10] = 360,
1347 [11] = 480,
1348 [12] = 540,
1349 };
1350 if (rateinfo < ARRAY_SIZE(legacy_rates))
1351 rate->legacy = legacy_rates[rateinfo];
1352 }
1353 }
1354
1355 /*
1356 * This function dumps the station information on a buffer.
1357 *
1358 * The following information are shown -
1359 * - Total bytes transmitted
1360 * - Total bytes received
1361 * - Total packets transmitted
1362 * - Total packets received
1363 * - Signal quality level
1364 * - Transmission rate
1365 */
1366 static int
mwifiex_dump_station_info(struct mwifiex_private * priv,struct mwifiex_sta_node * node,struct station_info * sinfo)1367 mwifiex_dump_station_info(struct mwifiex_private *priv,
1368 struct mwifiex_sta_node *node,
1369 struct station_info *sinfo)
1370 {
1371 u32 rate;
1372
1373 sinfo->filled = BIT_ULL(NL80211_STA_INFO_RX_BYTES) | BIT_ULL(NL80211_STA_INFO_TX_BYTES) |
1374 BIT_ULL(NL80211_STA_INFO_RX_PACKETS) | BIT_ULL(NL80211_STA_INFO_TX_PACKETS) |
1375 BIT_ULL(NL80211_STA_INFO_TX_BITRATE) |
1376 BIT_ULL(NL80211_STA_INFO_SIGNAL) | BIT_ULL(NL80211_STA_INFO_SIGNAL_AVG);
1377
1378 if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_UAP) {
1379 if (!node)
1380 return -ENOENT;
1381
1382 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_INACTIVE_TIME) |
1383 BIT_ULL(NL80211_STA_INFO_TX_FAILED);
1384 sinfo->inactive_time =
1385 jiffies_to_msecs(jiffies - node->stats.last_rx);
1386
1387 sinfo->signal = node->stats.rssi;
1388 sinfo->signal_avg = node->stats.rssi;
1389 sinfo->rx_bytes = node->stats.rx_bytes;
1390 sinfo->tx_bytes = node->stats.tx_bytes;
1391 sinfo->rx_packets = node->stats.rx_packets;
1392 sinfo->tx_packets = node->stats.tx_packets;
1393 sinfo->tx_failed = node->stats.tx_failed;
1394
1395 mwifiex_parse_htinfo(priv, priv->tx_rate,
1396 node->stats.last_tx_htinfo,
1397 &sinfo->txrate);
1398 sinfo->txrate.legacy = node->stats.last_tx_rate * 5;
1399
1400 return 0;
1401 }
1402
1403 /* Get signal information from the firmware */
1404 if (mwifiex_send_cmd(priv, HostCmd_CMD_RSSI_INFO,
1405 HostCmd_ACT_GEN_GET, 0, NULL, true)) {
1406 mwifiex_dbg(priv->adapter, ERROR,
1407 "failed to get signal information\n");
1408 return -EFAULT;
1409 }
1410
1411 if (mwifiex_drv_get_data_rate(priv, &rate)) {
1412 mwifiex_dbg(priv->adapter, ERROR,
1413 "getting data rate error\n");
1414 return -EFAULT;
1415 }
1416
1417 /* Get DTIM period information from firmware */
1418 mwifiex_send_cmd(priv, HostCmd_CMD_802_11_SNMP_MIB,
1419 HostCmd_ACT_GEN_GET, DTIM_PERIOD_I,
1420 &priv->dtim_period, true);
1421
1422 mwifiex_parse_htinfo(priv, priv->tx_rate, priv->tx_htinfo,
1423 &sinfo->txrate);
1424
1425 sinfo->signal_avg = priv->bcn_rssi_avg;
1426 sinfo->rx_bytes = priv->stats.rx_bytes;
1427 sinfo->tx_bytes = priv->stats.tx_bytes;
1428 sinfo->rx_packets = priv->stats.rx_packets;
1429 sinfo->tx_packets = priv->stats.tx_packets;
1430 sinfo->signal = priv->bcn_rssi_avg;
1431 /* bit rate is in 500 kb/s units. Convert it to 100kb/s units */
1432 sinfo->txrate.legacy = rate * 5;
1433
1434 sinfo->filled |= BIT(NL80211_STA_INFO_RX_BITRATE);
1435 mwifiex_parse_htinfo(priv, priv->rxpd_rate, priv->rxpd_htinfo,
1436 &sinfo->rxrate);
1437
1438 if (priv->bss_mode == NL80211_IFTYPE_STATION) {
1439 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_BSS_PARAM);
1440 sinfo->bss_param.flags = 0;
1441 if (priv->curr_bss_params.bss_descriptor.cap_info_bitmap &
1442 WLAN_CAPABILITY_SHORT_PREAMBLE)
1443 sinfo->bss_param.flags |=
1444 BSS_PARAM_FLAGS_SHORT_PREAMBLE;
1445 if (priv->curr_bss_params.bss_descriptor.cap_info_bitmap &
1446 WLAN_CAPABILITY_SHORT_SLOT_TIME)
1447 sinfo->bss_param.flags |=
1448 BSS_PARAM_FLAGS_SHORT_SLOT_TIME;
1449 sinfo->bss_param.dtim_period = priv->dtim_period;
1450 sinfo->bss_param.beacon_interval =
1451 priv->curr_bss_params.bss_descriptor.beacon_period;
1452 }
1453
1454 return 0;
1455 }
1456
1457 /*
1458 * CFG802.11 operation handler to get station information.
1459 *
1460 * This function only works in connected mode, and dumps the
1461 * requested station information, if available.
1462 */
1463 static int
mwifiex_cfg80211_get_station(struct wiphy * wiphy,struct net_device * dev,const u8 * mac,struct station_info * sinfo)1464 mwifiex_cfg80211_get_station(struct wiphy *wiphy, struct net_device *dev,
1465 const u8 *mac, struct station_info *sinfo)
1466 {
1467 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
1468
1469 if (!priv->media_connected)
1470 return -ENOENT;
1471 if (memcmp(mac, priv->cfg_bssid, ETH_ALEN))
1472 return -ENOENT;
1473
1474 return mwifiex_dump_station_info(priv, NULL, sinfo);
1475 }
1476
1477 /*
1478 * CFG802.11 operation handler to dump station information.
1479 */
1480 static int
mwifiex_cfg80211_dump_station(struct wiphy * wiphy,struct net_device * dev,int idx,u8 * mac,struct station_info * sinfo)1481 mwifiex_cfg80211_dump_station(struct wiphy *wiphy, struct net_device *dev,
1482 int idx, u8 *mac, struct station_info *sinfo)
1483 {
1484 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
1485 struct mwifiex_sta_node *node;
1486 int i;
1487
1488 if ((GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA) &&
1489 priv->media_connected && idx == 0) {
1490 ether_addr_copy(mac, priv->cfg_bssid);
1491 return mwifiex_dump_station_info(priv, NULL, sinfo);
1492 } else if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_UAP) {
1493 mwifiex_send_cmd(priv, HOST_CMD_APCMD_STA_LIST,
1494 HostCmd_ACT_GEN_GET, 0, NULL, true);
1495
1496 i = 0;
1497 list_for_each_entry(node, &priv->sta_list, list) {
1498 if (i++ != idx)
1499 continue;
1500 ether_addr_copy(mac, node->mac_addr);
1501 return mwifiex_dump_station_info(priv, node, sinfo);
1502 }
1503 }
1504
1505 return -ENOENT;
1506 }
1507
1508 static int
mwifiex_cfg80211_dump_survey(struct wiphy * wiphy,struct net_device * dev,int idx,struct survey_info * survey)1509 mwifiex_cfg80211_dump_survey(struct wiphy *wiphy, struct net_device *dev,
1510 int idx, struct survey_info *survey)
1511 {
1512 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
1513 struct mwifiex_chan_stats *pchan_stats = priv->adapter->chan_stats;
1514 enum nl80211_band band;
1515
1516 mwifiex_dbg(priv->adapter, DUMP, "dump_survey idx=%d\n", idx);
1517
1518 memset(survey, 0, sizeof(struct survey_info));
1519
1520 if ((GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA) &&
1521 priv->media_connected && idx == 0) {
1522 u8 curr_bss_band = priv->curr_bss_params.band;
1523 u32 chan = priv->curr_bss_params.bss_descriptor.channel;
1524
1525 band = mwifiex_band_to_radio_type(curr_bss_band);
1526 survey->channel = ieee80211_get_channel(wiphy,
1527 ieee80211_channel_to_frequency(chan, band));
1528
1529 if (priv->bcn_nf_last) {
1530 survey->filled = SURVEY_INFO_NOISE_DBM;
1531 survey->noise = priv->bcn_nf_last;
1532 }
1533 return 0;
1534 }
1535
1536 if (idx >= priv->adapter->num_in_chan_stats)
1537 return -ENOENT;
1538
1539 if (!pchan_stats[idx].cca_scan_dur)
1540 return 0;
1541
1542 band = pchan_stats[idx].bandcfg;
1543 survey->channel = ieee80211_get_channel(wiphy,
1544 ieee80211_channel_to_frequency(pchan_stats[idx].chan_num, band));
1545 survey->filled = SURVEY_INFO_NOISE_DBM |
1546 SURVEY_INFO_TIME |
1547 SURVEY_INFO_TIME_BUSY;
1548 survey->noise = pchan_stats[idx].noise;
1549 survey->time = pchan_stats[idx].cca_scan_dur;
1550 survey->time_busy = pchan_stats[idx].cca_busy_dur;
1551
1552 return 0;
1553 }
1554
1555 /* Supported rates to be advertised to the cfg80211 */
1556 static struct ieee80211_rate mwifiex_rates[] = {
1557 {.bitrate = 10, .hw_value = 2, },
1558 {.bitrate = 20, .hw_value = 4, },
1559 {.bitrate = 55, .hw_value = 11, },
1560 {.bitrate = 110, .hw_value = 22, },
1561 {.bitrate = 60, .hw_value = 12, },
1562 {.bitrate = 90, .hw_value = 18, },
1563 {.bitrate = 120, .hw_value = 24, },
1564 {.bitrate = 180, .hw_value = 36, },
1565 {.bitrate = 240, .hw_value = 48, },
1566 {.bitrate = 360, .hw_value = 72, },
1567 {.bitrate = 480, .hw_value = 96, },
1568 {.bitrate = 540, .hw_value = 108, },
1569 };
1570
1571 /* Channel definitions to be advertised to cfg80211 */
1572 static struct ieee80211_channel mwifiex_channels_2ghz[] = {
1573 {.center_freq = 2412, .hw_value = 1, },
1574 {.center_freq = 2417, .hw_value = 2, },
1575 {.center_freq = 2422, .hw_value = 3, },
1576 {.center_freq = 2427, .hw_value = 4, },
1577 {.center_freq = 2432, .hw_value = 5, },
1578 {.center_freq = 2437, .hw_value = 6, },
1579 {.center_freq = 2442, .hw_value = 7, },
1580 {.center_freq = 2447, .hw_value = 8, },
1581 {.center_freq = 2452, .hw_value = 9, },
1582 {.center_freq = 2457, .hw_value = 10, },
1583 {.center_freq = 2462, .hw_value = 11, },
1584 {.center_freq = 2467, .hw_value = 12, },
1585 {.center_freq = 2472, .hw_value = 13, },
1586 {.center_freq = 2484, .hw_value = 14, },
1587 };
1588
1589 static struct ieee80211_supported_band mwifiex_band_2ghz = {
1590 .channels = mwifiex_channels_2ghz,
1591 .n_channels = ARRAY_SIZE(mwifiex_channels_2ghz),
1592 .bitrates = mwifiex_rates,
1593 .n_bitrates = ARRAY_SIZE(mwifiex_rates),
1594 };
1595
1596 static struct ieee80211_channel mwifiex_channels_5ghz[] = {
1597 {.center_freq = 5040, .hw_value = 8, },
1598 {.center_freq = 5060, .hw_value = 12, },
1599 {.center_freq = 5080, .hw_value = 16, },
1600 {.center_freq = 5170, .hw_value = 34, },
1601 {.center_freq = 5190, .hw_value = 38, },
1602 {.center_freq = 5210, .hw_value = 42, },
1603 {.center_freq = 5230, .hw_value = 46, },
1604 {.center_freq = 5180, .hw_value = 36, },
1605 {.center_freq = 5200, .hw_value = 40, },
1606 {.center_freq = 5220, .hw_value = 44, },
1607 {.center_freq = 5240, .hw_value = 48, },
1608 {.center_freq = 5260, .hw_value = 52, },
1609 {.center_freq = 5280, .hw_value = 56, },
1610 {.center_freq = 5300, .hw_value = 60, },
1611 {.center_freq = 5320, .hw_value = 64, },
1612 {.center_freq = 5500, .hw_value = 100, },
1613 {.center_freq = 5520, .hw_value = 104, },
1614 {.center_freq = 5540, .hw_value = 108, },
1615 {.center_freq = 5560, .hw_value = 112, },
1616 {.center_freq = 5580, .hw_value = 116, },
1617 {.center_freq = 5600, .hw_value = 120, },
1618 {.center_freq = 5620, .hw_value = 124, },
1619 {.center_freq = 5640, .hw_value = 128, },
1620 {.center_freq = 5660, .hw_value = 132, },
1621 {.center_freq = 5680, .hw_value = 136, },
1622 {.center_freq = 5700, .hw_value = 140, },
1623 {.center_freq = 5745, .hw_value = 149, },
1624 {.center_freq = 5765, .hw_value = 153, },
1625 {.center_freq = 5785, .hw_value = 157, },
1626 {.center_freq = 5805, .hw_value = 161, },
1627 {.center_freq = 5825, .hw_value = 165, },
1628 };
1629
1630 static struct ieee80211_supported_band mwifiex_band_5ghz = {
1631 .channels = mwifiex_channels_5ghz,
1632 .n_channels = ARRAY_SIZE(mwifiex_channels_5ghz),
1633 .bitrates = mwifiex_rates + 4,
1634 .n_bitrates = ARRAY_SIZE(mwifiex_rates) - 4,
1635 };
1636
1637
1638 /* Supported crypto cipher suits to be advertised to cfg80211 */
1639 static const u32 mwifiex_cipher_suites[] = {
1640 WLAN_CIPHER_SUITE_WEP40,
1641 WLAN_CIPHER_SUITE_WEP104,
1642 WLAN_CIPHER_SUITE_TKIP,
1643 WLAN_CIPHER_SUITE_CCMP,
1644 WLAN_CIPHER_SUITE_SMS4,
1645 WLAN_CIPHER_SUITE_AES_CMAC,
1646 };
1647
1648 /* Supported mgmt frame types to be advertised to cfg80211 */
1649 static const struct ieee80211_txrx_stypes
1650 mwifiex_mgmt_stypes[NUM_NL80211_IFTYPES] = {
1651 [NL80211_IFTYPE_STATION] = {
1652 .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
1653 BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
1654 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
1655 BIT(IEEE80211_STYPE_PROBE_REQ >> 4),
1656 },
1657 [NL80211_IFTYPE_AP] = {
1658 .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
1659 BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
1660 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
1661 BIT(IEEE80211_STYPE_PROBE_REQ >> 4),
1662 },
1663 [NL80211_IFTYPE_P2P_CLIENT] = {
1664 .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
1665 BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
1666 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
1667 BIT(IEEE80211_STYPE_PROBE_REQ >> 4),
1668 },
1669 [NL80211_IFTYPE_P2P_GO] = {
1670 .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
1671 BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
1672 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
1673 BIT(IEEE80211_STYPE_PROBE_REQ >> 4),
1674 },
1675 };
1676
1677 /*
1678 * CFG802.11 operation handler for setting bit rates.
1679 *
1680 * Function configures data rates to firmware using bitrate mask
1681 * provided by cfg80211.
1682 */
mwifiex_cfg80211_set_bitrate_mask(struct wiphy * wiphy,struct net_device * dev,const u8 * peer,const struct cfg80211_bitrate_mask * mask)1683 static int mwifiex_cfg80211_set_bitrate_mask(struct wiphy *wiphy,
1684 struct net_device *dev,
1685 const u8 *peer,
1686 const struct cfg80211_bitrate_mask *mask)
1687 {
1688 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
1689 u16 bitmap_rates[MAX_BITMAP_RATES_SIZE];
1690 enum nl80211_band band;
1691 struct mwifiex_adapter *adapter = priv->adapter;
1692
1693 if (!priv->media_connected) {
1694 mwifiex_dbg(adapter, ERROR,
1695 "Can not set Tx data rate in disconnected state\n");
1696 return -EINVAL;
1697 }
1698
1699 band = mwifiex_band_to_radio_type(priv->curr_bss_params.band);
1700
1701 memset(bitmap_rates, 0, sizeof(bitmap_rates));
1702
1703 /* Fill HR/DSSS rates. */
1704 if (band == NL80211_BAND_2GHZ)
1705 bitmap_rates[0] = mask->control[band].legacy & 0x000f;
1706
1707 /* Fill OFDM rates */
1708 if (band == NL80211_BAND_2GHZ)
1709 bitmap_rates[1] = (mask->control[band].legacy & 0x0ff0) >> 4;
1710 else
1711 bitmap_rates[1] = mask->control[band].legacy;
1712
1713 /* Fill HT MCS rates */
1714 bitmap_rates[2] = mask->control[band].ht_mcs[0];
1715 if (adapter->hw_dev_mcs_support == HT_STREAM_2X2)
1716 bitmap_rates[2] |= mask->control[band].ht_mcs[1] << 8;
1717
1718 /* Fill VHT MCS rates */
1719 if (adapter->fw_api_ver == MWIFIEX_FW_V15) {
1720 bitmap_rates[10] = mask->control[band].vht_mcs[0];
1721 if (adapter->hw_dev_mcs_support == HT_STREAM_2X2)
1722 bitmap_rates[11] = mask->control[band].vht_mcs[1];
1723 }
1724
1725 return mwifiex_send_cmd(priv, HostCmd_CMD_TX_RATE_CFG,
1726 HostCmd_ACT_GEN_SET, 0, bitmap_rates, true);
1727 }
1728
1729 /*
1730 * CFG802.11 operation handler for connection quality monitoring.
1731 *
1732 * This function subscribes/unsubscribes HIGH_RSSI and LOW_RSSI
1733 * events to FW.
1734 */
mwifiex_cfg80211_set_cqm_rssi_config(struct wiphy * wiphy,struct net_device * dev,s32 rssi_thold,u32 rssi_hyst)1735 static int mwifiex_cfg80211_set_cqm_rssi_config(struct wiphy *wiphy,
1736 struct net_device *dev,
1737 s32 rssi_thold, u32 rssi_hyst)
1738 {
1739 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
1740 struct mwifiex_ds_misc_subsc_evt subsc_evt;
1741
1742 priv->cqm_rssi_thold = rssi_thold;
1743 priv->cqm_rssi_hyst = rssi_hyst;
1744
1745 memset(&subsc_evt, 0x00, sizeof(struct mwifiex_ds_misc_subsc_evt));
1746 subsc_evt.events = BITMASK_BCN_RSSI_LOW | BITMASK_BCN_RSSI_HIGH;
1747
1748 /* Subscribe/unsubscribe low and high rssi events */
1749 if (rssi_thold && rssi_hyst) {
1750 subsc_evt.action = HostCmd_ACT_BITWISE_SET;
1751 subsc_evt.bcn_l_rssi_cfg.abs_value = abs(rssi_thold);
1752 subsc_evt.bcn_h_rssi_cfg.abs_value = abs(rssi_thold);
1753 subsc_evt.bcn_l_rssi_cfg.evt_freq = 1;
1754 subsc_evt.bcn_h_rssi_cfg.evt_freq = 1;
1755 return mwifiex_send_cmd(priv,
1756 HostCmd_CMD_802_11_SUBSCRIBE_EVENT,
1757 0, 0, &subsc_evt, true);
1758 } else {
1759 subsc_evt.action = HostCmd_ACT_BITWISE_CLR;
1760 return mwifiex_send_cmd(priv,
1761 HostCmd_CMD_802_11_SUBSCRIBE_EVENT,
1762 0, 0, &subsc_evt, true);
1763 }
1764
1765 return 0;
1766 }
1767
1768 /* cfg80211 operation handler for change_beacon.
1769 * Function retrieves and sets modified management IEs to FW.
1770 */
mwifiex_cfg80211_change_beacon(struct wiphy * wiphy,struct net_device * dev,struct cfg80211_beacon_data * data)1771 static int mwifiex_cfg80211_change_beacon(struct wiphy *wiphy,
1772 struct net_device *dev,
1773 struct cfg80211_beacon_data *data)
1774 {
1775 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
1776 struct mwifiex_adapter *adapter = priv->adapter;
1777
1778 mwifiex_cancel_scan(adapter);
1779
1780 if (GET_BSS_ROLE(priv) != MWIFIEX_BSS_ROLE_UAP) {
1781 mwifiex_dbg(priv->adapter, ERROR,
1782 "%s: bss_type mismatched\n", __func__);
1783 return -EINVAL;
1784 }
1785
1786 if (!priv->bss_started) {
1787 mwifiex_dbg(priv->adapter, ERROR,
1788 "%s: bss not started\n", __func__);
1789 return -EINVAL;
1790 }
1791
1792 if (mwifiex_set_mgmt_ies(priv, data)) {
1793 mwifiex_dbg(priv->adapter, ERROR,
1794 "%s: setting mgmt ies failed\n", __func__);
1795 return -EFAULT;
1796 }
1797
1798 return 0;
1799 }
1800
1801 /* cfg80211 operation handler for del_station.
1802 * Function deauthenticates station which value is provided in mac parameter.
1803 * If mac is NULL/broadcast, all stations in associated station list are
1804 * deauthenticated. If bss is not started or there are no stations in
1805 * associated stations list, no action is taken.
1806 */
1807 static int
mwifiex_cfg80211_del_station(struct wiphy * wiphy,struct net_device * dev,struct station_del_parameters * params)1808 mwifiex_cfg80211_del_station(struct wiphy *wiphy, struct net_device *dev,
1809 struct station_del_parameters *params)
1810 {
1811 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
1812 struct mwifiex_sta_node *sta_node;
1813 u8 deauth_mac[ETH_ALEN];
1814
1815 if (!priv->bss_started && priv->wdev.cac_started) {
1816 mwifiex_dbg(priv->adapter, INFO, "%s: abort CAC!\n", __func__);
1817 mwifiex_abort_cac(priv);
1818 }
1819
1820 if (list_empty(&priv->sta_list) || !priv->bss_started)
1821 return 0;
1822
1823 if (!params->mac || is_broadcast_ether_addr(params->mac))
1824 return 0;
1825
1826 mwifiex_dbg(priv->adapter, INFO, "%s: mac address %pM\n",
1827 __func__, params->mac);
1828
1829 eth_zero_addr(deauth_mac);
1830
1831 spin_lock_bh(&priv->sta_list_spinlock);
1832 sta_node = mwifiex_get_sta_entry(priv, params->mac);
1833 if (sta_node)
1834 ether_addr_copy(deauth_mac, params->mac);
1835 spin_unlock_bh(&priv->sta_list_spinlock);
1836
1837 if (is_valid_ether_addr(deauth_mac)) {
1838 if (mwifiex_send_cmd(priv, HostCmd_CMD_UAP_STA_DEAUTH,
1839 HostCmd_ACT_GEN_SET, 0,
1840 deauth_mac, true))
1841 return -1;
1842 }
1843
1844 return 0;
1845 }
1846
1847 static int
mwifiex_cfg80211_set_antenna(struct wiphy * wiphy,u32 tx_ant,u32 rx_ant)1848 mwifiex_cfg80211_set_antenna(struct wiphy *wiphy, u32 tx_ant, u32 rx_ant)
1849 {
1850 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
1851 struct mwifiex_private *priv = mwifiex_get_priv(adapter,
1852 MWIFIEX_BSS_ROLE_ANY);
1853 struct mwifiex_ds_ant_cfg ant_cfg;
1854
1855 if (!tx_ant || !rx_ant)
1856 return -EOPNOTSUPP;
1857
1858 if (adapter->hw_dev_mcs_support != HT_STREAM_2X2) {
1859 /* Not a MIMO chip. User should provide specific antenna number
1860 * for Tx/Rx path or enable all antennas for diversity
1861 */
1862 if (tx_ant != rx_ant)
1863 return -EOPNOTSUPP;
1864
1865 if ((tx_ant & (tx_ant - 1)) &&
1866 (tx_ant != BIT(adapter->number_of_antenna) - 1))
1867 return -EOPNOTSUPP;
1868
1869 if ((tx_ant == BIT(adapter->number_of_antenna) - 1) &&
1870 (priv->adapter->number_of_antenna > 1)) {
1871 tx_ant = RF_ANTENNA_AUTO;
1872 rx_ant = RF_ANTENNA_AUTO;
1873 }
1874 } else {
1875 struct ieee80211_sta_ht_cap *ht_info;
1876 int rx_mcs_supp;
1877 enum nl80211_band band;
1878
1879 if ((tx_ant == 0x1 && rx_ant == 0x1)) {
1880 adapter->user_dev_mcs_support = HT_STREAM_1X1;
1881 if (adapter->is_hw_11ac_capable)
1882 adapter->usr_dot_11ac_mcs_support =
1883 MWIFIEX_11AC_MCS_MAP_1X1;
1884 } else {
1885 adapter->user_dev_mcs_support = HT_STREAM_2X2;
1886 if (adapter->is_hw_11ac_capable)
1887 adapter->usr_dot_11ac_mcs_support =
1888 MWIFIEX_11AC_MCS_MAP_2X2;
1889 }
1890
1891 for (band = 0; band < NUM_NL80211_BANDS; band++) {
1892 if (!adapter->wiphy->bands[band])
1893 continue;
1894
1895 ht_info = &adapter->wiphy->bands[band]->ht_cap;
1896 rx_mcs_supp =
1897 GET_RXMCSSUPP(adapter->user_dev_mcs_support);
1898 memset(&ht_info->mcs, 0, adapter->number_of_antenna);
1899 memset(&ht_info->mcs, 0xff, rx_mcs_supp);
1900 }
1901 }
1902
1903 ant_cfg.tx_ant = tx_ant;
1904 ant_cfg.rx_ant = rx_ant;
1905
1906 return mwifiex_send_cmd(priv, HostCmd_CMD_RF_ANTENNA,
1907 HostCmd_ACT_GEN_SET, 0, &ant_cfg, true);
1908 }
1909
1910 static int
mwifiex_cfg80211_get_antenna(struct wiphy * wiphy,u32 * tx_ant,u32 * rx_ant)1911 mwifiex_cfg80211_get_antenna(struct wiphy *wiphy, u32 *tx_ant, u32 *rx_ant)
1912 {
1913 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
1914 struct mwifiex_private *priv = mwifiex_get_priv(adapter,
1915 MWIFIEX_BSS_ROLE_ANY);
1916 mwifiex_send_cmd(priv, HostCmd_CMD_RF_ANTENNA,
1917 HostCmd_ACT_GEN_GET, 0, NULL, true);
1918
1919 *tx_ant = priv->tx_ant;
1920 *rx_ant = priv->rx_ant;
1921
1922 return 0;
1923 }
1924
1925 /* cfg80211 operation handler for stop ap.
1926 * Function stops BSS running at uAP interface.
1927 */
mwifiex_cfg80211_stop_ap(struct wiphy * wiphy,struct net_device * dev)1928 static int mwifiex_cfg80211_stop_ap(struct wiphy *wiphy, struct net_device *dev)
1929 {
1930 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
1931
1932 mwifiex_abort_cac(priv);
1933
1934 if (mwifiex_del_mgmt_ies(priv))
1935 mwifiex_dbg(priv->adapter, ERROR,
1936 "Failed to delete mgmt IEs!\n");
1937
1938 priv->ap_11n_enabled = 0;
1939 memset(&priv->bss_cfg, 0, sizeof(priv->bss_cfg));
1940
1941 if (mwifiex_send_cmd(priv, HostCmd_CMD_UAP_BSS_STOP,
1942 HostCmd_ACT_GEN_SET, 0, NULL, true)) {
1943 mwifiex_dbg(priv->adapter, ERROR,
1944 "Failed to stop the BSS\n");
1945 return -1;
1946 }
1947
1948 if (mwifiex_send_cmd(priv, HOST_CMD_APCMD_SYS_RESET,
1949 HostCmd_ACT_GEN_SET, 0, NULL, true)) {
1950 mwifiex_dbg(priv->adapter, ERROR,
1951 "Failed to reset BSS\n");
1952 return -1;
1953 }
1954
1955 if (netif_carrier_ok(priv->netdev))
1956 netif_carrier_off(priv->netdev);
1957 mwifiex_stop_net_dev_queue(priv->netdev, priv->adapter);
1958
1959 return 0;
1960 }
1961
1962 /* cfg80211 operation handler for start_ap.
1963 * Function sets beacon period, DTIM period, SSID and security into
1964 * AP config structure.
1965 * AP is configured with these settings and BSS is started.
1966 */
mwifiex_cfg80211_start_ap(struct wiphy * wiphy,struct net_device * dev,struct cfg80211_ap_settings * params)1967 static int mwifiex_cfg80211_start_ap(struct wiphy *wiphy,
1968 struct net_device *dev,
1969 struct cfg80211_ap_settings *params)
1970 {
1971 struct mwifiex_uap_bss_param *bss_cfg;
1972 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
1973
1974 if (GET_BSS_ROLE(priv) != MWIFIEX_BSS_ROLE_UAP)
1975 return -1;
1976
1977 bss_cfg = kzalloc(sizeof(struct mwifiex_uap_bss_param), GFP_KERNEL);
1978 if (!bss_cfg)
1979 return -ENOMEM;
1980
1981 mwifiex_set_sys_config_invalid_data(bss_cfg);
1982
1983 if (params->beacon_interval)
1984 bss_cfg->beacon_period = params->beacon_interval;
1985 if (params->dtim_period)
1986 bss_cfg->dtim_period = params->dtim_period;
1987
1988 if (params->ssid && params->ssid_len) {
1989 memcpy(bss_cfg->ssid.ssid, params->ssid, params->ssid_len);
1990 bss_cfg->ssid.ssid_len = params->ssid_len;
1991 }
1992 if (params->inactivity_timeout > 0) {
1993 /* sta_ao_timer/ps_sta_ao_timer is in unit of 100ms */
1994 bss_cfg->sta_ao_timer = 10 * params->inactivity_timeout;
1995 bss_cfg->ps_sta_ao_timer = 10 * params->inactivity_timeout;
1996 }
1997
1998 switch (params->hidden_ssid) {
1999 case NL80211_HIDDEN_SSID_NOT_IN_USE:
2000 bss_cfg->bcast_ssid_ctl = 1;
2001 break;
2002 case NL80211_HIDDEN_SSID_ZERO_LEN:
2003 bss_cfg->bcast_ssid_ctl = 0;
2004 break;
2005 case NL80211_HIDDEN_SSID_ZERO_CONTENTS:
2006 bss_cfg->bcast_ssid_ctl = 2;
2007 break;
2008 default:
2009 kfree(bss_cfg);
2010 return -EINVAL;
2011 }
2012
2013 mwifiex_uap_set_channel(priv, bss_cfg, params->chandef);
2014 mwifiex_set_uap_rates(bss_cfg, params);
2015
2016 if (mwifiex_set_secure_params(priv, bss_cfg, params)) {
2017 mwifiex_dbg(priv->adapter, ERROR,
2018 "Failed to parse security parameters!\n");
2019 goto out;
2020 }
2021
2022 mwifiex_set_ht_params(priv, bss_cfg, params);
2023
2024 if (priv->adapter->is_hw_11ac_capable) {
2025 mwifiex_set_vht_params(priv, bss_cfg, params);
2026 mwifiex_set_vht_width(priv, params->chandef.width,
2027 priv->ap_11ac_enabled);
2028 }
2029
2030 if (priv->ap_11ac_enabled)
2031 mwifiex_set_11ac_ba_params(priv);
2032 else
2033 mwifiex_set_ba_params(priv);
2034
2035 mwifiex_set_wmm_params(priv, bss_cfg, params);
2036
2037 if (mwifiex_is_11h_active(priv))
2038 mwifiex_set_tpc_params(priv, bss_cfg, params);
2039
2040 if (mwifiex_is_11h_active(priv) &&
2041 !cfg80211_chandef_dfs_required(wiphy, ¶ms->chandef,
2042 priv->bss_mode)) {
2043 mwifiex_dbg(priv->adapter, INFO,
2044 "Disable 11h extensions in FW\n");
2045 if (mwifiex_11h_activate(priv, false)) {
2046 mwifiex_dbg(priv->adapter, ERROR,
2047 "Failed to disable 11h extensions!!");
2048 goto out;
2049 }
2050 priv->state_11h.is_11h_active = false;
2051 }
2052
2053 mwifiex_config_uap_11d(priv, ¶ms->beacon);
2054
2055 if (mwifiex_config_start_uap(priv, bss_cfg)) {
2056 mwifiex_dbg(priv->adapter, ERROR,
2057 "Failed to start AP\n");
2058 goto out;
2059 }
2060
2061 if (mwifiex_set_mgmt_ies(priv, ¶ms->beacon))
2062 goto out;
2063
2064 if (!netif_carrier_ok(priv->netdev))
2065 netif_carrier_on(priv->netdev);
2066 mwifiex_wake_up_net_dev_queue(priv->netdev, priv->adapter);
2067
2068 memcpy(&priv->bss_cfg, bss_cfg, sizeof(priv->bss_cfg));
2069 kfree(bss_cfg);
2070 return 0;
2071
2072 out:
2073 kfree(bss_cfg);
2074 return -1;
2075 }
2076
2077 /*
2078 * CFG802.11 operation handler for disconnection request.
2079 *
2080 * This function does not work when there is already a disconnection
2081 * procedure going on.
2082 */
2083 static int
mwifiex_cfg80211_disconnect(struct wiphy * wiphy,struct net_device * dev,u16 reason_code)2084 mwifiex_cfg80211_disconnect(struct wiphy *wiphy, struct net_device *dev,
2085 u16 reason_code)
2086 {
2087 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
2088
2089 if (!mwifiex_stop_bg_scan(priv))
2090 cfg80211_sched_scan_stopped_rtnl(priv->wdev.wiphy, 0);
2091
2092 if (mwifiex_deauthenticate(priv, NULL))
2093 return -EFAULT;
2094
2095 eth_zero_addr(priv->cfg_bssid);
2096 priv->hs2_enabled = false;
2097
2098 return 0;
2099 }
2100
2101 /*
2102 * This function informs the CFG802.11 subsystem of a new IBSS.
2103 *
2104 * The following information are sent to the CFG802.11 subsystem
2105 * to register the new IBSS. If we do not register the new IBSS,
2106 * a kernel panic will result.
2107 * - SSID
2108 * - SSID length
2109 * - BSSID
2110 * - Channel
2111 */
mwifiex_cfg80211_inform_ibss_bss(struct mwifiex_private * priv)2112 static int mwifiex_cfg80211_inform_ibss_bss(struct mwifiex_private *priv)
2113 {
2114 struct ieee80211_channel *chan;
2115 struct mwifiex_bss_info bss_info;
2116 struct cfg80211_bss *bss;
2117 int ie_len;
2118 u8 ie_buf[IEEE80211_MAX_SSID_LEN + sizeof(struct ieee_types_header)];
2119 enum nl80211_band band;
2120
2121 if (mwifiex_get_bss_info(priv, &bss_info))
2122 return -1;
2123
2124 ie_buf[0] = WLAN_EID_SSID;
2125 ie_buf[1] = bss_info.ssid.ssid_len;
2126
2127 memcpy(&ie_buf[sizeof(struct ieee_types_header)],
2128 &bss_info.ssid.ssid, bss_info.ssid.ssid_len);
2129 ie_len = ie_buf[1] + sizeof(struct ieee_types_header);
2130
2131 band = mwifiex_band_to_radio_type(priv->curr_bss_params.band);
2132 chan = ieee80211_get_channel(priv->wdev.wiphy,
2133 ieee80211_channel_to_frequency(bss_info.bss_chan,
2134 band));
2135
2136 bss = cfg80211_inform_bss(priv->wdev.wiphy, chan,
2137 CFG80211_BSS_FTYPE_UNKNOWN,
2138 bss_info.bssid, 0, WLAN_CAPABILITY_IBSS,
2139 0, ie_buf, ie_len, 0, GFP_KERNEL);
2140 if (bss) {
2141 cfg80211_put_bss(priv->wdev.wiphy, bss);
2142 ether_addr_copy(priv->cfg_bssid, bss_info.bssid);
2143 }
2144
2145 return 0;
2146 }
2147
2148 /*
2149 * This function connects with a BSS.
2150 *
2151 * This function handles both Infra and Ad-Hoc modes. It also performs
2152 * validity checking on the provided parameters, disconnects from the
2153 * current BSS (if any), sets up the association/scan parameters,
2154 * including security settings, and performs specific SSID scan before
2155 * trying to connect.
2156 *
2157 * For Infra mode, the function returns failure if the specified SSID
2158 * is not found in scan table. However, for Ad-Hoc mode, it can create
2159 * the IBSS if it does not exist. On successful completion in either case,
2160 * the function notifies the CFG802.11 subsystem of the new BSS connection.
2161 */
2162 static int
mwifiex_cfg80211_assoc(struct mwifiex_private * priv,size_t ssid_len,const u8 * ssid,const u8 * bssid,int mode,struct ieee80211_channel * channel,struct cfg80211_connect_params * sme,bool privacy)2163 mwifiex_cfg80211_assoc(struct mwifiex_private *priv, size_t ssid_len,
2164 const u8 *ssid, const u8 *bssid, int mode,
2165 struct ieee80211_channel *channel,
2166 struct cfg80211_connect_params *sme, bool privacy)
2167 {
2168 struct cfg80211_ssid req_ssid;
2169 int ret, auth_type = 0;
2170 struct cfg80211_bss *bss = NULL;
2171 u8 is_scanning_required = 0;
2172
2173 memset(&req_ssid, 0, sizeof(struct cfg80211_ssid));
2174
2175 req_ssid.ssid_len = ssid_len;
2176 if (ssid_len > IEEE80211_MAX_SSID_LEN) {
2177 mwifiex_dbg(priv->adapter, ERROR, "invalid SSID - aborting\n");
2178 return -EINVAL;
2179 }
2180
2181 memcpy(req_ssid.ssid, ssid, ssid_len);
2182 if (!req_ssid.ssid_len || req_ssid.ssid[0] < 0x20) {
2183 mwifiex_dbg(priv->adapter, ERROR, "invalid SSID - aborting\n");
2184 return -EINVAL;
2185 }
2186
2187 /* As this is new association, clear locally stored
2188 * keys and security related flags */
2189 priv->sec_info.wpa_enabled = false;
2190 priv->sec_info.wpa2_enabled = false;
2191 priv->wep_key_curr_index = 0;
2192 priv->sec_info.encryption_mode = 0;
2193 priv->sec_info.is_authtype_auto = 0;
2194 ret = mwifiex_set_encode(priv, NULL, NULL, 0, 0, NULL, 1);
2195
2196 if (mode == NL80211_IFTYPE_ADHOC) {
2197 u16 enable = true;
2198
2199 /* set ibss coalescing_status */
2200 ret = mwifiex_send_cmd(
2201 priv,
2202 HostCmd_CMD_802_11_IBSS_COALESCING_STATUS,
2203 HostCmd_ACT_GEN_SET, 0, &enable, true);
2204 if (ret)
2205 return ret;
2206
2207 /* "privacy" is set only for ad-hoc mode */
2208 if (privacy) {
2209 /*
2210 * Keep WLAN_CIPHER_SUITE_WEP104 for now so that
2211 * the firmware can find a matching network from the
2212 * scan. The cfg80211 does not give us the encryption
2213 * mode at this stage so just setting it to WEP here.
2214 */
2215 priv->sec_info.encryption_mode =
2216 WLAN_CIPHER_SUITE_WEP104;
2217 priv->sec_info.authentication_mode =
2218 NL80211_AUTHTYPE_OPEN_SYSTEM;
2219 }
2220
2221 goto done;
2222 }
2223
2224 /* Now handle infra mode. "sme" is valid for infra mode only */
2225 if (sme->auth_type == NL80211_AUTHTYPE_AUTOMATIC) {
2226 auth_type = NL80211_AUTHTYPE_OPEN_SYSTEM;
2227 priv->sec_info.is_authtype_auto = 1;
2228 } else {
2229 auth_type = sme->auth_type;
2230 }
2231
2232 if (sme->crypto.n_ciphers_pairwise) {
2233 priv->sec_info.encryption_mode =
2234 sme->crypto.ciphers_pairwise[0];
2235 priv->sec_info.authentication_mode = auth_type;
2236 }
2237
2238 if (sme->crypto.cipher_group) {
2239 priv->sec_info.encryption_mode = sme->crypto.cipher_group;
2240 priv->sec_info.authentication_mode = auth_type;
2241 }
2242 if (sme->ie)
2243 ret = mwifiex_set_gen_ie(priv, sme->ie, sme->ie_len);
2244
2245 if (sme->key) {
2246 if (mwifiex_is_alg_wep(priv->sec_info.encryption_mode)) {
2247 mwifiex_dbg(priv->adapter, INFO,
2248 "info: setting wep encryption\t"
2249 "with key len %d\n", sme->key_len);
2250 priv->wep_key_curr_index = sme->key_idx;
2251 ret = mwifiex_set_encode(priv, NULL, sme->key,
2252 sme->key_len, sme->key_idx,
2253 NULL, 0);
2254 }
2255 }
2256 done:
2257 /*
2258 * Scan entries are valid for some time (15 sec). So we can save one
2259 * active scan time if we just try cfg80211_get_bss first. If it fails
2260 * then request scan and cfg80211_get_bss() again for final output.
2261 */
2262 while (1) {
2263 if (is_scanning_required) {
2264 /* Do specific SSID scanning */
2265 if (mwifiex_request_scan(priv, &req_ssid)) {
2266 mwifiex_dbg(priv->adapter, ERROR, "scan error\n");
2267 return -EFAULT;
2268 }
2269 }
2270
2271 /* Find the BSS we want using available scan results */
2272 if (mode == NL80211_IFTYPE_ADHOC)
2273 bss = cfg80211_get_bss(priv->wdev.wiphy, channel,
2274 bssid, ssid, ssid_len,
2275 IEEE80211_BSS_TYPE_IBSS,
2276 IEEE80211_PRIVACY_ANY);
2277 else
2278 bss = cfg80211_get_bss(priv->wdev.wiphy, channel,
2279 bssid, ssid, ssid_len,
2280 IEEE80211_BSS_TYPE_ESS,
2281 IEEE80211_PRIVACY_ANY);
2282
2283 if (!bss) {
2284 if (is_scanning_required) {
2285 mwifiex_dbg(priv->adapter, MSG,
2286 "assoc: requested bss not found in scan results\n");
2287 break;
2288 }
2289 is_scanning_required = 1;
2290 } else {
2291 mwifiex_dbg(priv->adapter, MSG,
2292 "info: trying to associate to '%.*s' bssid %pM\n",
2293 req_ssid.ssid_len, (char *)req_ssid.ssid,
2294 bss->bssid);
2295 memcpy(&priv->cfg_bssid, bss->bssid, ETH_ALEN);
2296 break;
2297 }
2298 }
2299
2300 ret = mwifiex_bss_start(priv, bss, &req_ssid);
2301 if (ret)
2302 return ret;
2303
2304 if (mode == NL80211_IFTYPE_ADHOC) {
2305 /* Inform the BSS information to kernel, otherwise
2306 * kernel will give a panic after successful assoc */
2307 if (mwifiex_cfg80211_inform_ibss_bss(priv))
2308 return -EFAULT;
2309 }
2310
2311 return ret;
2312 }
2313
2314 /*
2315 * CFG802.11 operation handler for association request.
2316 *
2317 * This function does not work when the current mode is set to Ad-Hoc, or
2318 * when there is already an association procedure going on. The given BSS
2319 * information is used to associate.
2320 */
2321 static int
mwifiex_cfg80211_connect(struct wiphy * wiphy,struct net_device * dev,struct cfg80211_connect_params * sme)2322 mwifiex_cfg80211_connect(struct wiphy *wiphy, struct net_device *dev,
2323 struct cfg80211_connect_params *sme)
2324 {
2325 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
2326 struct mwifiex_adapter *adapter = priv->adapter;
2327 int ret;
2328
2329 if (GET_BSS_ROLE(priv) != MWIFIEX_BSS_ROLE_STA) {
2330 mwifiex_dbg(adapter, ERROR,
2331 "%s: reject infra assoc request in non-STA role\n",
2332 dev->name);
2333 return -EINVAL;
2334 }
2335
2336 if (priv->wdev.current_bss) {
2337 mwifiex_dbg(adapter, ERROR,
2338 "%s: already connected\n", dev->name);
2339 return -EALREADY;
2340 }
2341
2342 if (priv->scan_block)
2343 priv->scan_block = false;
2344
2345 if (test_bit(MWIFIEX_SURPRISE_REMOVED, &adapter->work_flags) ||
2346 test_bit(MWIFIEX_IS_CMD_TIMEDOUT, &adapter->work_flags)) {
2347 mwifiex_dbg(adapter, ERROR,
2348 "%s: Ignore connection.\t"
2349 "Card removed or FW in bad state\n",
2350 dev->name);
2351 return -EFAULT;
2352 }
2353
2354 mwifiex_dbg(adapter, INFO,
2355 "info: Trying to associate to %.*s and bssid %pM\n",
2356 (int)sme->ssid_len, (char *)sme->ssid, sme->bssid);
2357
2358 if (!mwifiex_stop_bg_scan(priv))
2359 cfg80211_sched_scan_stopped_rtnl(priv->wdev.wiphy, 0);
2360
2361 ret = mwifiex_cfg80211_assoc(priv, sme->ssid_len, sme->ssid, sme->bssid,
2362 priv->bss_mode, sme->channel, sme, 0);
2363 if (!ret) {
2364 cfg80211_connect_result(priv->netdev, priv->cfg_bssid, NULL, 0,
2365 NULL, 0, WLAN_STATUS_SUCCESS,
2366 GFP_KERNEL);
2367 mwifiex_dbg(priv->adapter, MSG,
2368 "info: associated to bssid %pM successfully\n",
2369 priv->cfg_bssid);
2370 if (ISSUPP_TDLS_ENABLED(priv->adapter->fw_cap_info) &&
2371 priv->adapter->auto_tdls &&
2372 priv->bss_type == MWIFIEX_BSS_TYPE_STA)
2373 mwifiex_setup_auto_tdls_timer(priv);
2374 } else {
2375 mwifiex_dbg(priv->adapter, ERROR,
2376 "info: association to bssid %pM failed\n",
2377 priv->cfg_bssid);
2378 eth_zero_addr(priv->cfg_bssid);
2379
2380 if (ret > 0)
2381 cfg80211_connect_result(priv->netdev, priv->cfg_bssid,
2382 NULL, 0, NULL, 0, ret,
2383 GFP_KERNEL);
2384 else
2385 cfg80211_connect_result(priv->netdev, priv->cfg_bssid,
2386 NULL, 0, NULL, 0,
2387 WLAN_STATUS_UNSPECIFIED_FAILURE,
2388 GFP_KERNEL);
2389 }
2390
2391 return 0;
2392 }
2393
2394 /*
2395 * This function sets following parameters for ibss network.
2396 * - channel
2397 * - start band
2398 * - 11n flag
2399 * - secondary channel offset
2400 */
mwifiex_set_ibss_params(struct mwifiex_private * priv,struct cfg80211_ibss_params * params)2401 static int mwifiex_set_ibss_params(struct mwifiex_private *priv,
2402 struct cfg80211_ibss_params *params)
2403 {
2404 struct mwifiex_adapter *adapter = priv->adapter;
2405 int index = 0, i;
2406 u8 config_bands = 0;
2407
2408 if (params->chandef.chan->band == NL80211_BAND_2GHZ) {
2409 if (!params->basic_rates) {
2410 config_bands = BAND_B | BAND_G;
2411 } else {
2412 for (i = 0; i < mwifiex_band_2ghz.n_bitrates; i++) {
2413 /*
2414 * Rates below 6 Mbps in the table are CCK
2415 * rates; 802.11b and from 6 they are OFDM;
2416 * 802.11G
2417 */
2418 if (mwifiex_rates[i].bitrate == 60) {
2419 index = 1 << i;
2420 break;
2421 }
2422 }
2423
2424 if (params->basic_rates < index) {
2425 config_bands = BAND_B;
2426 } else {
2427 config_bands = BAND_G;
2428 if (params->basic_rates % index)
2429 config_bands |= BAND_B;
2430 }
2431 }
2432
2433 if (cfg80211_get_chandef_type(¶ms->chandef) !=
2434 NL80211_CHAN_NO_HT)
2435 config_bands |= BAND_G | BAND_GN;
2436 } else {
2437 if (cfg80211_get_chandef_type(¶ms->chandef) ==
2438 NL80211_CHAN_NO_HT)
2439 config_bands = BAND_A;
2440 else
2441 config_bands = BAND_AN | BAND_A;
2442 }
2443
2444 if (!((config_bands | adapter->fw_bands) & ~adapter->fw_bands)) {
2445 adapter->config_bands = config_bands;
2446 adapter->adhoc_start_band = config_bands;
2447
2448 if ((config_bands & BAND_GN) || (config_bands & BAND_AN))
2449 adapter->adhoc_11n_enabled = true;
2450 else
2451 adapter->adhoc_11n_enabled = false;
2452 }
2453
2454 adapter->sec_chan_offset =
2455 mwifiex_chan_type_to_sec_chan_offset(
2456 cfg80211_get_chandef_type(¶ms->chandef));
2457 priv->adhoc_channel = ieee80211_frequency_to_channel(
2458 params->chandef.chan->center_freq);
2459
2460 mwifiex_dbg(adapter, INFO,
2461 "info: set ibss band %d, chan %d, chan offset %d\n",
2462 config_bands, priv->adhoc_channel,
2463 adapter->sec_chan_offset);
2464
2465 return 0;
2466 }
2467
2468 /*
2469 * CFG802.11 operation handler to join an IBSS.
2470 *
2471 * This function does not work in any mode other than Ad-Hoc, or if
2472 * a join operation is already in progress.
2473 */
2474 static int
mwifiex_cfg80211_join_ibss(struct wiphy * wiphy,struct net_device * dev,struct cfg80211_ibss_params * params)2475 mwifiex_cfg80211_join_ibss(struct wiphy *wiphy, struct net_device *dev,
2476 struct cfg80211_ibss_params *params)
2477 {
2478 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
2479 int ret = 0;
2480
2481 if (priv->bss_mode != NL80211_IFTYPE_ADHOC) {
2482 mwifiex_dbg(priv->adapter, ERROR,
2483 "request to join ibss received\t"
2484 "when station is not in ibss mode\n");
2485 goto done;
2486 }
2487
2488 mwifiex_dbg(priv->adapter, MSG,
2489 "info: trying to join to %.*s and bssid %pM\n",
2490 params->ssid_len, (char *)params->ssid, params->bssid);
2491
2492 mwifiex_set_ibss_params(priv, params);
2493
2494 ret = mwifiex_cfg80211_assoc(priv, params->ssid_len, params->ssid,
2495 params->bssid, priv->bss_mode,
2496 params->chandef.chan, NULL,
2497 params->privacy);
2498 done:
2499 if (!ret) {
2500 cfg80211_ibss_joined(priv->netdev, priv->cfg_bssid,
2501 params->chandef.chan, GFP_KERNEL);
2502 mwifiex_dbg(priv->adapter, MSG,
2503 "info: joined/created adhoc network with bssid\t"
2504 "%pM successfully\n", priv->cfg_bssid);
2505 } else {
2506 mwifiex_dbg(priv->adapter, ERROR,
2507 "info: failed creating/joining adhoc network\n");
2508 }
2509
2510 return ret;
2511 }
2512
2513 /*
2514 * CFG802.11 operation handler to leave an IBSS.
2515 *
2516 * This function does not work if a leave operation is
2517 * already in progress.
2518 */
2519 static int
mwifiex_cfg80211_leave_ibss(struct wiphy * wiphy,struct net_device * dev)2520 mwifiex_cfg80211_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
2521 {
2522 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
2523
2524 mwifiex_dbg(priv->adapter, MSG, "info: disconnecting from essid %pM\n",
2525 priv->cfg_bssid);
2526 if (mwifiex_deauthenticate(priv, NULL))
2527 return -EFAULT;
2528
2529 eth_zero_addr(priv->cfg_bssid);
2530
2531 return 0;
2532 }
2533
2534 /*
2535 * CFG802.11 operation handler for scan request.
2536 *
2537 * This function issues a scan request to the firmware based upon
2538 * the user specified scan configuration. On successful completion,
2539 * it also informs the results.
2540 */
2541 static int
mwifiex_cfg80211_scan(struct wiphy * wiphy,struct cfg80211_scan_request * request)2542 mwifiex_cfg80211_scan(struct wiphy *wiphy,
2543 struct cfg80211_scan_request *request)
2544 {
2545 struct net_device *dev = request->wdev->netdev;
2546 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
2547 int i, offset, ret;
2548 struct ieee80211_channel *chan;
2549 struct ieee_types_header *ie;
2550 struct mwifiex_user_scan_cfg *user_scan_cfg;
2551 u8 mac_addr[ETH_ALEN];
2552
2553 mwifiex_dbg(priv->adapter, CMD,
2554 "info: received scan request on %s\n", dev->name);
2555
2556 /* Block scan request if scan operation or scan cleanup when interface
2557 * is disabled is in process
2558 */
2559 if (priv->scan_request || priv->scan_aborting) {
2560 mwifiex_dbg(priv->adapter, WARN,
2561 "cmd: Scan already in process..\n");
2562 return -EBUSY;
2563 }
2564
2565 if (!priv->wdev.current_bss && priv->scan_block)
2566 priv->scan_block = false;
2567
2568 if (!mwifiex_stop_bg_scan(priv))
2569 cfg80211_sched_scan_stopped_rtnl(priv->wdev.wiphy, 0);
2570
2571 user_scan_cfg = kzalloc(sizeof(*user_scan_cfg), GFP_KERNEL);
2572 if (!user_scan_cfg)
2573 return -ENOMEM;
2574
2575 priv->scan_request = request;
2576
2577 if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) {
2578 get_random_mask_addr(mac_addr, request->mac_addr,
2579 request->mac_addr_mask);
2580 ether_addr_copy(request->mac_addr, mac_addr);
2581 ether_addr_copy(user_scan_cfg->random_mac, mac_addr);
2582 }
2583
2584 user_scan_cfg->num_ssids = request->n_ssids;
2585 user_scan_cfg->ssid_list = request->ssids;
2586
2587 if (request->ie && request->ie_len) {
2588 offset = 0;
2589 for (i = 0; i < MWIFIEX_MAX_VSIE_NUM; i++) {
2590 if (priv->vs_ie[i].mask != MWIFIEX_VSIE_MASK_CLEAR)
2591 continue;
2592 priv->vs_ie[i].mask = MWIFIEX_VSIE_MASK_SCAN;
2593 ie = (struct ieee_types_header *)(request->ie + offset);
2594 memcpy(&priv->vs_ie[i].ie, ie, sizeof(*ie) + ie->len);
2595 offset += sizeof(*ie) + ie->len;
2596
2597 if (offset >= request->ie_len)
2598 break;
2599 }
2600 }
2601
2602 for (i = 0; i < min_t(u32, request->n_channels,
2603 MWIFIEX_USER_SCAN_CHAN_MAX); i++) {
2604 chan = request->channels[i];
2605 user_scan_cfg->chan_list[i].chan_number = chan->hw_value;
2606 user_scan_cfg->chan_list[i].radio_type = chan->band;
2607
2608 if ((chan->flags & IEEE80211_CHAN_NO_IR) || !request->n_ssids)
2609 user_scan_cfg->chan_list[i].scan_type =
2610 MWIFIEX_SCAN_TYPE_PASSIVE;
2611 else
2612 user_scan_cfg->chan_list[i].scan_type =
2613 MWIFIEX_SCAN_TYPE_ACTIVE;
2614
2615 user_scan_cfg->chan_list[i].scan_time = 0;
2616 }
2617
2618 if (priv->adapter->scan_chan_gap_enabled &&
2619 mwifiex_is_any_intf_active(priv))
2620 user_scan_cfg->scan_chan_gap =
2621 priv->adapter->scan_chan_gap_time;
2622
2623 ret = mwifiex_scan_networks(priv, user_scan_cfg);
2624 kfree(user_scan_cfg);
2625 if (ret) {
2626 mwifiex_dbg(priv->adapter, ERROR,
2627 "scan failed: %d\n", ret);
2628 priv->scan_aborting = false;
2629 priv->scan_request = NULL;
2630 return ret;
2631 }
2632
2633 if (request->ie && request->ie_len) {
2634 for (i = 0; i < MWIFIEX_MAX_VSIE_NUM; i++) {
2635 if (priv->vs_ie[i].mask == MWIFIEX_VSIE_MASK_SCAN) {
2636 priv->vs_ie[i].mask = MWIFIEX_VSIE_MASK_CLEAR;
2637 memset(&priv->vs_ie[i].ie, 0,
2638 MWIFIEX_MAX_VSIE_LEN);
2639 }
2640 }
2641 }
2642 return 0;
2643 }
2644
2645 /* CFG802.11 operation handler for sched_scan_start.
2646 *
2647 * This function issues a bgscan config request to the firmware based upon
2648 * the user specified sched_scan configuration. On successful completion,
2649 * firmware will generate BGSCAN_REPORT event, driver should issue bgscan
2650 * query command to get sched_scan results from firmware.
2651 */
2652 static int
mwifiex_cfg80211_sched_scan_start(struct wiphy * wiphy,struct net_device * dev,struct cfg80211_sched_scan_request * request)2653 mwifiex_cfg80211_sched_scan_start(struct wiphy *wiphy,
2654 struct net_device *dev,
2655 struct cfg80211_sched_scan_request *request)
2656 {
2657 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
2658 int i, offset;
2659 struct ieee80211_channel *chan;
2660 struct mwifiex_bg_scan_cfg *bgscan_cfg;
2661 struct ieee_types_header *ie;
2662
2663 if (!request || (!request->n_ssids && !request->n_match_sets)) {
2664 wiphy_err(wiphy, "%s : Invalid Sched_scan parameters",
2665 __func__);
2666 return -EINVAL;
2667 }
2668
2669 wiphy_info(wiphy, "sched_scan start : n_ssids=%d n_match_sets=%d ",
2670 request->n_ssids, request->n_match_sets);
2671 wiphy_info(wiphy, "n_channels=%d interval=%d ie_len=%d\n",
2672 request->n_channels, request->scan_plans->interval,
2673 (int)request->ie_len);
2674
2675 bgscan_cfg = kzalloc(sizeof(*bgscan_cfg), GFP_KERNEL);
2676 if (!bgscan_cfg)
2677 return -ENOMEM;
2678
2679 if (priv->scan_request || priv->scan_aborting)
2680 bgscan_cfg->start_later = true;
2681
2682 bgscan_cfg->num_ssids = request->n_match_sets;
2683 bgscan_cfg->ssid_list = request->match_sets;
2684
2685 if (request->ie && request->ie_len) {
2686 offset = 0;
2687 for (i = 0; i < MWIFIEX_MAX_VSIE_NUM; i++) {
2688 if (priv->vs_ie[i].mask != MWIFIEX_VSIE_MASK_CLEAR)
2689 continue;
2690 priv->vs_ie[i].mask = MWIFIEX_VSIE_MASK_BGSCAN;
2691 ie = (struct ieee_types_header *)(request->ie + offset);
2692 memcpy(&priv->vs_ie[i].ie, ie, sizeof(*ie) + ie->len);
2693 offset += sizeof(*ie) + ie->len;
2694
2695 if (offset >= request->ie_len)
2696 break;
2697 }
2698 }
2699
2700 for (i = 0; i < min_t(u32, request->n_channels,
2701 MWIFIEX_BG_SCAN_CHAN_MAX); i++) {
2702 chan = request->channels[i];
2703 bgscan_cfg->chan_list[i].chan_number = chan->hw_value;
2704 bgscan_cfg->chan_list[i].radio_type = chan->band;
2705
2706 if ((chan->flags & IEEE80211_CHAN_NO_IR) || !request->n_ssids)
2707 bgscan_cfg->chan_list[i].scan_type =
2708 MWIFIEX_SCAN_TYPE_PASSIVE;
2709 else
2710 bgscan_cfg->chan_list[i].scan_type =
2711 MWIFIEX_SCAN_TYPE_ACTIVE;
2712
2713 bgscan_cfg->chan_list[i].scan_time = 0;
2714 }
2715
2716 bgscan_cfg->chan_per_scan = min_t(u32, request->n_channels,
2717 MWIFIEX_BG_SCAN_CHAN_MAX);
2718
2719 /* Use at least 15 second for per scan cycle */
2720 bgscan_cfg->scan_interval = (request->scan_plans->interval >
2721 MWIFIEX_BGSCAN_INTERVAL) ?
2722 request->scan_plans->interval :
2723 MWIFIEX_BGSCAN_INTERVAL;
2724
2725 bgscan_cfg->repeat_count = MWIFIEX_BGSCAN_REPEAT_COUNT;
2726 bgscan_cfg->report_condition = MWIFIEX_BGSCAN_SSID_MATCH |
2727 MWIFIEX_BGSCAN_WAIT_ALL_CHAN_DONE;
2728 bgscan_cfg->bss_type = MWIFIEX_BSS_MODE_INFRA;
2729 bgscan_cfg->action = MWIFIEX_BGSCAN_ACT_SET;
2730 bgscan_cfg->enable = true;
2731 if (request->min_rssi_thold != NL80211_SCAN_RSSI_THOLD_OFF) {
2732 bgscan_cfg->report_condition |= MWIFIEX_BGSCAN_SSID_RSSI_MATCH;
2733 bgscan_cfg->rssi_threshold = request->min_rssi_thold;
2734 }
2735
2736 if (mwifiex_send_cmd(priv, HostCmd_CMD_802_11_BG_SCAN_CONFIG,
2737 HostCmd_ACT_GEN_SET, 0, bgscan_cfg, true)) {
2738 kfree(bgscan_cfg);
2739 return -EFAULT;
2740 }
2741
2742 priv->sched_scanning = true;
2743
2744 kfree(bgscan_cfg);
2745 return 0;
2746 }
2747
2748 /* CFG802.11 operation handler for sched_scan_stop.
2749 *
2750 * This function issues a bgscan config command to disable
2751 * previous bgscan configuration in the firmware
2752 */
mwifiex_cfg80211_sched_scan_stop(struct wiphy * wiphy,struct net_device * dev,u64 reqid)2753 static int mwifiex_cfg80211_sched_scan_stop(struct wiphy *wiphy,
2754 struct net_device *dev, u64 reqid)
2755 {
2756 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
2757
2758 wiphy_info(wiphy, "sched scan stop!");
2759 mwifiex_stop_bg_scan(priv);
2760
2761 return 0;
2762 }
2763
mwifiex_setup_vht_caps(struct ieee80211_sta_vht_cap * vht_info,struct mwifiex_private * priv)2764 static void mwifiex_setup_vht_caps(struct ieee80211_sta_vht_cap *vht_info,
2765 struct mwifiex_private *priv)
2766 {
2767 struct mwifiex_adapter *adapter = priv->adapter;
2768
2769 vht_info->vht_supported = true;
2770
2771 vht_info->cap = adapter->hw_dot_11ac_dev_cap;
2772 /* Update MCS support for VHT */
2773 vht_info->vht_mcs.rx_mcs_map = cpu_to_le16(
2774 adapter->hw_dot_11ac_mcs_support & 0xFFFF);
2775 vht_info->vht_mcs.rx_highest = 0;
2776 vht_info->vht_mcs.tx_mcs_map = cpu_to_le16(
2777 adapter->hw_dot_11ac_mcs_support >> 16);
2778 vht_info->vht_mcs.tx_highest = 0;
2779 }
2780
2781 /*
2782 * This function sets up the CFG802.11 specific HT capability fields
2783 * with default values.
2784 *
2785 * The following default values are set -
2786 * - HT Supported = True
2787 * - Maximum AMPDU length factor = IEEE80211_HT_MAX_AMPDU_64K
2788 * - Minimum AMPDU spacing = IEEE80211_HT_MPDU_DENSITY_NONE
2789 * - HT Capabilities supported by firmware
2790 * - MCS information, Rx mask = 0xff
2791 * - MCD information, Tx parameters = IEEE80211_HT_MCS_TX_DEFINED (0x01)
2792 */
2793 static void
mwifiex_setup_ht_caps(struct ieee80211_sta_ht_cap * ht_info,struct mwifiex_private * priv)2794 mwifiex_setup_ht_caps(struct ieee80211_sta_ht_cap *ht_info,
2795 struct mwifiex_private *priv)
2796 {
2797 int rx_mcs_supp;
2798 struct ieee80211_mcs_info mcs_set;
2799 u8 *mcs = (u8 *)&mcs_set;
2800 struct mwifiex_adapter *adapter = priv->adapter;
2801
2802 ht_info->ht_supported = true;
2803 ht_info->ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
2804 ht_info->ampdu_density = IEEE80211_HT_MPDU_DENSITY_NONE;
2805
2806 memset(&ht_info->mcs, 0, sizeof(ht_info->mcs));
2807
2808 /* Fill HT capability information */
2809 if (ISSUPP_CHANWIDTH40(adapter->hw_dot_11n_dev_cap))
2810 ht_info->cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
2811 else
2812 ht_info->cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
2813
2814 if (ISSUPP_SHORTGI20(adapter->hw_dot_11n_dev_cap))
2815 ht_info->cap |= IEEE80211_HT_CAP_SGI_20;
2816 else
2817 ht_info->cap &= ~IEEE80211_HT_CAP_SGI_20;
2818
2819 if (ISSUPP_SHORTGI40(adapter->hw_dot_11n_dev_cap))
2820 ht_info->cap |= IEEE80211_HT_CAP_SGI_40;
2821 else
2822 ht_info->cap &= ~IEEE80211_HT_CAP_SGI_40;
2823
2824 if (adapter->user_dev_mcs_support == HT_STREAM_2X2)
2825 ht_info->cap |= 2 << IEEE80211_HT_CAP_RX_STBC_SHIFT;
2826 else
2827 ht_info->cap |= 1 << IEEE80211_HT_CAP_RX_STBC_SHIFT;
2828
2829 if (ISSUPP_TXSTBC(adapter->hw_dot_11n_dev_cap))
2830 ht_info->cap |= IEEE80211_HT_CAP_TX_STBC;
2831 else
2832 ht_info->cap &= ~IEEE80211_HT_CAP_TX_STBC;
2833
2834 if (ISSUPP_GREENFIELD(adapter->hw_dot_11n_dev_cap))
2835 ht_info->cap |= IEEE80211_HT_CAP_GRN_FLD;
2836 else
2837 ht_info->cap &= ~IEEE80211_HT_CAP_GRN_FLD;
2838
2839 if (ISENABLED_40MHZ_INTOLERANT(adapter->hw_dot_11n_dev_cap))
2840 ht_info->cap |= IEEE80211_HT_CAP_40MHZ_INTOLERANT;
2841 else
2842 ht_info->cap &= ~IEEE80211_HT_CAP_40MHZ_INTOLERANT;
2843
2844 if (ISSUPP_RXLDPC(adapter->hw_dot_11n_dev_cap))
2845 ht_info->cap |= IEEE80211_HT_CAP_LDPC_CODING;
2846 else
2847 ht_info->cap &= ~IEEE80211_HT_CAP_LDPC_CODING;
2848
2849 ht_info->cap &= ~IEEE80211_HT_CAP_MAX_AMSDU;
2850 ht_info->cap |= IEEE80211_HT_CAP_SM_PS;
2851
2852 rx_mcs_supp = GET_RXMCSSUPP(adapter->user_dev_mcs_support);
2853 /* Set MCS for 1x1/2x2 */
2854 memset(mcs, 0xff, rx_mcs_supp);
2855 /* Clear all the other values */
2856 memset(&mcs[rx_mcs_supp], 0,
2857 sizeof(struct ieee80211_mcs_info) - rx_mcs_supp);
2858 if (priv->bss_mode == NL80211_IFTYPE_STATION ||
2859 ISSUPP_CHANWIDTH40(adapter->hw_dot_11n_dev_cap))
2860 /* Set MCS32 for infra mode or ad-hoc mode with 40MHz support */
2861 SETHT_MCS32(mcs_set.rx_mask);
2862
2863 memcpy((u8 *) &ht_info->mcs, mcs, sizeof(struct ieee80211_mcs_info));
2864
2865 ht_info->mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED;
2866 }
2867
2868 /*
2869 * create a new virtual interface with the given name and name assign type
2870 */
mwifiex_add_virtual_intf(struct wiphy * wiphy,const char * name,unsigned char name_assign_type,enum nl80211_iftype type,struct vif_params * params)2871 struct wireless_dev *mwifiex_add_virtual_intf(struct wiphy *wiphy,
2872 const char *name,
2873 unsigned char name_assign_type,
2874 enum nl80211_iftype type,
2875 struct vif_params *params)
2876 {
2877 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
2878 struct mwifiex_private *priv;
2879 struct net_device *dev;
2880 void *mdev_priv;
2881 int ret;
2882
2883 if (!adapter)
2884 return ERR_PTR(-EFAULT);
2885
2886 switch (type) {
2887 case NL80211_IFTYPE_UNSPECIFIED:
2888 case NL80211_IFTYPE_STATION:
2889 case NL80211_IFTYPE_ADHOC:
2890 if (adapter->curr_iface_comb.sta_intf ==
2891 adapter->iface_limit.sta_intf) {
2892 mwifiex_dbg(adapter, ERROR,
2893 "cannot create multiple sta/adhoc ifaces\n");
2894 return ERR_PTR(-EINVAL);
2895 }
2896
2897 priv = mwifiex_get_unused_priv_by_bss_type(
2898 adapter, MWIFIEX_BSS_TYPE_STA);
2899 if (!priv) {
2900 mwifiex_dbg(adapter, ERROR,
2901 "could not get free private struct\n");
2902 return ERR_PTR(-EFAULT);
2903 }
2904
2905 priv->wdev.wiphy = wiphy;
2906 priv->wdev.iftype = NL80211_IFTYPE_STATION;
2907
2908 if (type == NL80211_IFTYPE_UNSPECIFIED)
2909 priv->bss_mode = NL80211_IFTYPE_STATION;
2910 else
2911 priv->bss_mode = type;
2912
2913 priv->bss_type = MWIFIEX_BSS_TYPE_STA;
2914 priv->frame_type = MWIFIEX_DATA_FRAME_TYPE_ETH_II;
2915 priv->bss_priority = 0;
2916 priv->bss_role = MWIFIEX_BSS_ROLE_STA;
2917
2918 break;
2919 case NL80211_IFTYPE_AP:
2920 if (adapter->curr_iface_comb.uap_intf ==
2921 adapter->iface_limit.uap_intf) {
2922 mwifiex_dbg(adapter, ERROR,
2923 "cannot create multiple AP ifaces\n");
2924 return ERR_PTR(-EINVAL);
2925 }
2926
2927 priv = mwifiex_get_unused_priv_by_bss_type(
2928 adapter, MWIFIEX_BSS_TYPE_UAP);
2929 if (!priv) {
2930 mwifiex_dbg(adapter, ERROR,
2931 "could not get free private struct\n");
2932 return ERR_PTR(-EFAULT);
2933 }
2934
2935 priv->wdev.wiphy = wiphy;
2936 priv->wdev.iftype = NL80211_IFTYPE_AP;
2937
2938 priv->bss_type = MWIFIEX_BSS_TYPE_UAP;
2939 priv->frame_type = MWIFIEX_DATA_FRAME_TYPE_ETH_II;
2940 priv->bss_priority = 0;
2941 priv->bss_role = MWIFIEX_BSS_ROLE_UAP;
2942 priv->bss_started = 0;
2943 priv->bss_mode = type;
2944
2945 break;
2946 case NL80211_IFTYPE_P2P_CLIENT:
2947 if (adapter->curr_iface_comb.p2p_intf ==
2948 adapter->iface_limit.p2p_intf) {
2949 mwifiex_dbg(adapter, ERROR,
2950 "cannot create multiple P2P ifaces\n");
2951 return ERR_PTR(-EINVAL);
2952 }
2953
2954 priv = mwifiex_get_unused_priv_by_bss_type(
2955 adapter, MWIFIEX_BSS_TYPE_P2P);
2956 if (!priv) {
2957 mwifiex_dbg(adapter, ERROR,
2958 "could not get free private struct\n");
2959 return ERR_PTR(-EFAULT);
2960 }
2961
2962 priv->wdev.wiphy = wiphy;
2963 /* At start-up, wpa_supplicant tries to change the interface
2964 * to NL80211_IFTYPE_STATION if it is not managed mode.
2965 */
2966 priv->wdev.iftype = NL80211_IFTYPE_P2P_CLIENT;
2967 priv->bss_mode = NL80211_IFTYPE_P2P_CLIENT;
2968
2969 /* Setting bss_type to P2P tells firmware that this interface
2970 * is receiving P2P peers found during find phase and doing
2971 * action frame handshake.
2972 */
2973 priv->bss_type = MWIFIEX_BSS_TYPE_P2P;
2974
2975 priv->frame_type = MWIFIEX_DATA_FRAME_TYPE_ETH_II;
2976 priv->bss_priority = MWIFIEX_BSS_ROLE_STA;
2977 priv->bss_role = MWIFIEX_BSS_ROLE_STA;
2978 priv->bss_started = 0;
2979
2980 if (mwifiex_cfg80211_init_p2p_client(priv)) {
2981 memset(&priv->wdev, 0, sizeof(priv->wdev));
2982 priv->wdev.iftype = NL80211_IFTYPE_UNSPECIFIED;
2983 return ERR_PTR(-EFAULT);
2984 }
2985
2986 break;
2987 default:
2988 mwifiex_dbg(adapter, ERROR, "type not supported\n");
2989 return ERR_PTR(-EINVAL);
2990 }
2991
2992 dev = alloc_netdev_mqs(sizeof(struct mwifiex_private *), name,
2993 name_assign_type, ether_setup,
2994 IEEE80211_NUM_ACS, 1);
2995 if (!dev) {
2996 mwifiex_dbg(adapter, ERROR,
2997 "no memory available for netdevice\n");
2998 ret = -ENOMEM;
2999 goto err_alloc_netdev;
3000 }
3001
3002 mwifiex_init_priv_params(priv, dev);
3003
3004 priv->netdev = dev;
3005
3006 if (!adapter->mfg_mode) {
3007 mwifiex_set_mac_address(priv, dev, false, NULL);
3008
3009 ret = mwifiex_send_cmd(priv, HostCmd_CMD_SET_BSS_MODE,
3010 HostCmd_ACT_GEN_SET, 0, NULL, true);
3011 if (ret)
3012 goto err_set_bss_mode;
3013
3014 ret = mwifiex_sta_init_cmd(priv, false, false);
3015 if (ret)
3016 goto err_sta_init;
3017 }
3018
3019 mwifiex_setup_ht_caps(&wiphy->bands[NL80211_BAND_2GHZ]->ht_cap, priv);
3020 if (adapter->is_hw_11ac_capable)
3021 mwifiex_setup_vht_caps(
3022 &wiphy->bands[NL80211_BAND_2GHZ]->vht_cap, priv);
3023
3024 if (adapter->config_bands & BAND_A)
3025 mwifiex_setup_ht_caps(
3026 &wiphy->bands[NL80211_BAND_5GHZ]->ht_cap, priv);
3027
3028 if ((adapter->config_bands & BAND_A) && adapter->is_hw_11ac_capable)
3029 mwifiex_setup_vht_caps(
3030 &wiphy->bands[NL80211_BAND_5GHZ]->vht_cap, priv);
3031
3032 dev_net_set(dev, wiphy_net(wiphy));
3033 dev->ieee80211_ptr = &priv->wdev;
3034 dev->ieee80211_ptr->iftype = priv->bss_mode;
3035 SET_NETDEV_DEV(dev, wiphy_dev(wiphy));
3036
3037 dev->flags |= IFF_BROADCAST | IFF_MULTICAST;
3038 dev->watchdog_timeo = MWIFIEX_DEFAULT_WATCHDOG_TIMEOUT;
3039 dev->needed_headroom = MWIFIEX_MIN_DATA_HEADER_LEN;
3040 dev->ethtool_ops = &mwifiex_ethtool_ops;
3041
3042 mdev_priv = netdev_priv(dev);
3043 *((unsigned long *) mdev_priv) = (unsigned long) priv;
3044
3045 SET_NETDEV_DEV(dev, adapter->dev);
3046
3047 priv->dfs_cac_workqueue = alloc_workqueue("MWIFIEX_DFS_CAC%s",
3048 WQ_HIGHPRI |
3049 WQ_MEM_RECLAIM |
3050 WQ_UNBOUND, 1, name);
3051 if (!priv->dfs_cac_workqueue) {
3052 mwifiex_dbg(adapter, ERROR, "cannot alloc DFS CAC queue\n");
3053 ret = -ENOMEM;
3054 goto err_alloc_cac;
3055 }
3056
3057 INIT_DELAYED_WORK(&priv->dfs_cac_work, mwifiex_dfs_cac_work_queue);
3058
3059 priv->dfs_chan_sw_workqueue = alloc_workqueue("MWIFIEX_DFS_CHSW%s",
3060 WQ_HIGHPRI | WQ_UNBOUND |
3061 WQ_MEM_RECLAIM, 1, name);
3062 if (!priv->dfs_chan_sw_workqueue) {
3063 mwifiex_dbg(adapter, ERROR, "cannot alloc DFS channel sw queue\n");
3064 ret = -ENOMEM;
3065 goto err_alloc_chsw;
3066 }
3067
3068 INIT_DELAYED_WORK(&priv->dfs_chan_sw_work,
3069 mwifiex_dfs_chan_sw_work_queue);
3070
3071 mutex_init(&priv->async_mutex);
3072
3073 /* Register network device */
3074 if (register_netdevice(dev)) {
3075 mwifiex_dbg(adapter, ERROR, "cannot register network device\n");
3076 ret = -EFAULT;
3077 goto err_reg_netdev;
3078 }
3079
3080 mwifiex_dbg(adapter, INFO,
3081 "info: %s: Marvell 802.11 Adapter\n", dev->name);
3082
3083 #ifdef CONFIG_DEBUG_FS
3084 mwifiex_dev_debugfs_init(priv);
3085 #endif
3086
3087 switch (type) {
3088 case NL80211_IFTYPE_UNSPECIFIED:
3089 case NL80211_IFTYPE_STATION:
3090 case NL80211_IFTYPE_ADHOC:
3091 adapter->curr_iface_comb.sta_intf++;
3092 break;
3093 case NL80211_IFTYPE_AP:
3094 adapter->curr_iface_comb.uap_intf++;
3095 break;
3096 case NL80211_IFTYPE_P2P_CLIENT:
3097 adapter->curr_iface_comb.p2p_intf++;
3098 break;
3099 default:
3100 /* This should be dead code; checked above */
3101 mwifiex_dbg(adapter, ERROR, "type not supported\n");
3102 return ERR_PTR(-EINVAL);
3103 }
3104
3105 return &priv->wdev;
3106
3107 err_reg_netdev:
3108 destroy_workqueue(priv->dfs_chan_sw_workqueue);
3109 priv->dfs_chan_sw_workqueue = NULL;
3110 err_alloc_chsw:
3111 destroy_workqueue(priv->dfs_cac_workqueue);
3112 priv->dfs_cac_workqueue = NULL;
3113 err_alloc_cac:
3114 free_netdev(dev);
3115 priv->netdev = NULL;
3116 err_sta_init:
3117 err_set_bss_mode:
3118 err_alloc_netdev:
3119 memset(&priv->wdev, 0, sizeof(priv->wdev));
3120 priv->wdev.iftype = NL80211_IFTYPE_UNSPECIFIED;
3121 priv->bss_mode = NL80211_IFTYPE_UNSPECIFIED;
3122 return ERR_PTR(ret);
3123 }
3124 EXPORT_SYMBOL_GPL(mwifiex_add_virtual_intf);
3125
3126 /*
3127 * del_virtual_intf: remove the virtual interface determined by dev
3128 */
mwifiex_del_virtual_intf(struct wiphy * wiphy,struct wireless_dev * wdev)3129 int mwifiex_del_virtual_intf(struct wiphy *wiphy, struct wireless_dev *wdev)
3130 {
3131 struct mwifiex_private *priv = mwifiex_netdev_get_priv(wdev->netdev);
3132 struct mwifiex_adapter *adapter = priv->adapter;
3133 struct sk_buff *skb, *tmp;
3134
3135 #ifdef CONFIG_DEBUG_FS
3136 mwifiex_dev_debugfs_remove(priv);
3137 #endif
3138
3139 if (priv->sched_scanning)
3140 priv->sched_scanning = false;
3141
3142 mwifiex_stop_net_dev_queue(priv->netdev, adapter);
3143
3144 skb_queue_walk_safe(&priv->bypass_txq, skb, tmp) {
3145 skb_unlink(skb, &priv->bypass_txq);
3146 mwifiex_write_data_complete(priv->adapter, skb, 0, -1);
3147 }
3148
3149 if (netif_carrier_ok(priv->netdev))
3150 netif_carrier_off(priv->netdev);
3151
3152 if (wdev->netdev->reg_state == NETREG_REGISTERED)
3153 unregister_netdevice(wdev->netdev);
3154
3155 if (priv->dfs_cac_workqueue) {
3156 flush_workqueue(priv->dfs_cac_workqueue);
3157 destroy_workqueue(priv->dfs_cac_workqueue);
3158 priv->dfs_cac_workqueue = NULL;
3159 }
3160
3161 if (priv->dfs_chan_sw_workqueue) {
3162 flush_workqueue(priv->dfs_chan_sw_workqueue);
3163 destroy_workqueue(priv->dfs_chan_sw_workqueue);
3164 priv->dfs_chan_sw_workqueue = NULL;
3165 }
3166 /* Clear the priv in adapter */
3167 priv->netdev = NULL;
3168
3169 switch (priv->bss_mode) {
3170 case NL80211_IFTYPE_UNSPECIFIED:
3171 case NL80211_IFTYPE_STATION:
3172 case NL80211_IFTYPE_ADHOC:
3173 adapter->curr_iface_comb.sta_intf--;
3174 break;
3175 case NL80211_IFTYPE_AP:
3176 adapter->curr_iface_comb.uap_intf--;
3177 break;
3178 case NL80211_IFTYPE_P2P_CLIENT:
3179 case NL80211_IFTYPE_P2P_GO:
3180 adapter->curr_iface_comb.p2p_intf--;
3181 break;
3182 default:
3183 mwifiex_dbg(adapter, ERROR,
3184 "del_virtual_intf: type not supported\n");
3185 break;
3186 }
3187
3188 priv->bss_mode = NL80211_IFTYPE_UNSPECIFIED;
3189
3190 if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA ||
3191 GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_UAP)
3192 kfree(priv->hist_data);
3193
3194 return 0;
3195 }
3196 EXPORT_SYMBOL_GPL(mwifiex_del_virtual_intf);
3197
3198 static bool
mwifiex_is_pattern_supported(struct cfg80211_pkt_pattern * pat,s8 * byte_seq,u8 max_byte_seq)3199 mwifiex_is_pattern_supported(struct cfg80211_pkt_pattern *pat, s8 *byte_seq,
3200 u8 max_byte_seq)
3201 {
3202 int j, k, valid_byte_cnt = 0;
3203 bool dont_care_byte = false;
3204
3205 for (j = 0; j < DIV_ROUND_UP(pat->pattern_len, 8); j++) {
3206 for (k = 0; k < 8; k++) {
3207 if (pat->mask[j] & 1 << k) {
3208 memcpy(byte_seq + valid_byte_cnt,
3209 &pat->pattern[j * 8 + k], 1);
3210 valid_byte_cnt++;
3211 if (dont_care_byte)
3212 return false;
3213 } else {
3214 if (valid_byte_cnt)
3215 dont_care_byte = true;
3216 }
3217
3218 /* wildcard bytes record as the offset
3219 * before the valid byte
3220 */
3221 if (!valid_byte_cnt && !dont_care_byte)
3222 pat->pkt_offset++;
3223
3224 if (valid_byte_cnt > max_byte_seq)
3225 return false;
3226 }
3227 }
3228
3229 byte_seq[max_byte_seq] = valid_byte_cnt;
3230
3231 return true;
3232 }
3233
3234 #ifdef CONFIG_PM
mwifiex_set_auto_arp_mef_entry(struct mwifiex_private * priv,struct mwifiex_mef_entry * mef_entry)3235 static void mwifiex_set_auto_arp_mef_entry(struct mwifiex_private *priv,
3236 struct mwifiex_mef_entry *mef_entry)
3237 {
3238 int i, filt_num = 0, num_ipv4 = 0;
3239 struct in_device *in_dev;
3240 struct in_ifaddr *ifa;
3241 __be32 ips[MWIFIEX_MAX_SUPPORTED_IPADDR];
3242 struct mwifiex_adapter *adapter = priv->adapter;
3243
3244 mef_entry->mode = MEF_MODE_HOST_SLEEP;
3245 mef_entry->action = MEF_ACTION_AUTO_ARP;
3246
3247 /* Enable ARP offload feature */
3248 memset(ips, 0, sizeof(ips));
3249 for (i = 0; i < MWIFIEX_MAX_BSS_NUM; i++) {
3250 if (adapter->priv[i]->netdev) {
3251 in_dev = __in_dev_get_rtnl(adapter->priv[i]->netdev);
3252 if (!in_dev)
3253 continue;
3254 ifa = rtnl_dereference(in_dev->ifa_list);
3255 if (!ifa || !ifa->ifa_local)
3256 continue;
3257 ips[i] = ifa->ifa_local;
3258 num_ipv4++;
3259 }
3260 }
3261
3262 for (i = 0; i < num_ipv4; i++) {
3263 if (!ips[i])
3264 continue;
3265 mef_entry->filter[filt_num].repeat = 1;
3266 memcpy(mef_entry->filter[filt_num].byte_seq,
3267 (u8 *)&ips[i], sizeof(ips[i]));
3268 mef_entry->filter[filt_num].
3269 byte_seq[MWIFIEX_MEF_MAX_BYTESEQ] =
3270 sizeof(ips[i]);
3271 mef_entry->filter[filt_num].offset = 46;
3272 mef_entry->filter[filt_num].filt_type = TYPE_EQ;
3273 if (filt_num) {
3274 mef_entry->filter[filt_num].filt_action =
3275 TYPE_OR;
3276 }
3277 filt_num++;
3278 }
3279
3280 mef_entry->filter[filt_num].repeat = 1;
3281 mef_entry->filter[filt_num].byte_seq[0] = 0x08;
3282 mef_entry->filter[filt_num].byte_seq[1] = 0x06;
3283 mef_entry->filter[filt_num].byte_seq[MWIFIEX_MEF_MAX_BYTESEQ] = 2;
3284 mef_entry->filter[filt_num].offset = 20;
3285 mef_entry->filter[filt_num].filt_type = TYPE_EQ;
3286 mef_entry->filter[filt_num].filt_action = TYPE_AND;
3287 }
3288
mwifiex_set_wowlan_mef_entry(struct mwifiex_private * priv,struct mwifiex_ds_mef_cfg * mef_cfg,struct mwifiex_mef_entry * mef_entry,struct cfg80211_wowlan * wowlan)3289 static int mwifiex_set_wowlan_mef_entry(struct mwifiex_private *priv,
3290 struct mwifiex_ds_mef_cfg *mef_cfg,
3291 struct mwifiex_mef_entry *mef_entry,
3292 struct cfg80211_wowlan *wowlan)
3293 {
3294 int i, filt_num = 0, ret = 0;
3295 bool first_pat = true;
3296 u8 byte_seq[MWIFIEX_MEF_MAX_BYTESEQ + 1];
3297 static const u8 ipv4_mc_mac[] = {0x33, 0x33};
3298 static const u8 ipv6_mc_mac[] = {0x01, 0x00, 0x5e};
3299
3300 mef_entry->mode = MEF_MODE_HOST_SLEEP;
3301 mef_entry->action = MEF_ACTION_ALLOW_AND_WAKEUP_HOST;
3302
3303 for (i = 0; i < wowlan->n_patterns; i++) {
3304 memset(byte_seq, 0, sizeof(byte_seq));
3305 if (!mwifiex_is_pattern_supported(&wowlan->patterns[i],
3306 byte_seq,
3307 MWIFIEX_MEF_MAX_BYTESEQ)) {
3308 mwifiex_dbg(priv->adapter, ERROR,
3309 "Pattern not supported\n");
3310 return -EOPNOTSUPP;
3311 }
3312
3313 if (!wowlan->patterns[i].pkt_offset) {
3314 if (!(byte_seq[0] & 0x01) &&
3315 (byte_seq[MWIFIEX_MEF_MAX_BYTESEQ] == 1)) {
3316 mef_cfg->criteria |= MWIFIEX_CRITERIA_UNICAST;
3317 continue;
3318 } else if (is_broadcast_ether_addr(byte_seq)) {
3319 mef_cfg->criteria |= MWIFIEX_CRITERIA_BROADCAST;
3320 continue;
3321 } else if ((!memcmp(byte_seq, ipv4_mc_mac, 2) &&
3322 (byte_seq[MWIFIEX_MEF_MAX_BYTESEQ] == 2)) ||
3323 (!memcmp(byte_seq, ipv6_mc_mac, 3) &&
3324 (byte_seq[MWIFIEX_MEF_MAX_BYTESEQ] == 3))) {
3325 mef_cfg->criteria |= MWIFIEX_CRITERIA_MULTICAST;
3326 continue;
3327 }
3328 }
3329 mef_entry->filter[filt_num].repeat = 1;
3330 mef_entry->filter[filt_num].offset =
3331 wowlan->patterns[i].pkt_offset;
3332 memcpy(mef_entry->filter[filt_num].byte_seq, byte_seq,
3333 sizeof(byte_seq));
3334 mef_entry->filter[filt_num].filt_type = TYPE_EQ;
3335
3336 if (first_pat) {
3337 first_pat = false;
3338 mwifiex_dbg(priv->adapter, INFO, "Wake on patterns\n");
3339 } else {
3340 mef_entry->filter[filt_num].filt_action = TYPE_AND;
3341 }
3342
3343 filt_num++;
3344 }
3345
3346 if (wowlan->magic_pkt) {
3347 mef_cfg->criteria |= MWIFIEX_CRITERIA_UNICAST;
3348 mef_entry->filter[filt_num].repeat = 16;
3349 memcpy(mef_entry->filter[filt_num].byte_seq, priv->curr_addr,
3350 ETH_ALEN);
3351 mef_entry->filter[filt_num].byte_seq[MWIFIEX_MEF_MAX_BYTESEQ] =
3352 ETH_ALEN;
3353 mef_entry->filter[filt_num].offset = 28;
3354 mef_entry->filter[filt_num].filt_type = TYPE_EQ;
3355 if (filt_num)
3356 mef_entry->filter[filt_num].filt_action = TYPE_OR;
3357
3358 filt_num++;
3359 mef_entry->filter[filt_num].repeat = 16;
3360 memcpy(mef_entry->filter[filt_num].byte_seq, priv->curr_addr,
3361 ETH_ALEN);
3362 mef_entry->filter[filt_num].byte_seq[MWIFIEX_MEF_MAX_BYTESEQ] =
3363 ETH_ALEN;
3364 mef_entry->filter[filt_num].offset = 56;
3365 mef_entry->filter[filt_num].filt_type = TYPE_EQ;
3366 mef_entry->filter[filt_num].filt_action = TYPE_OR;
3367 mwifiex_dbg(priv->adapter, INFO, "Wake on magic packet\n");
3368 }
3369 return ret;
3370 }
3371
mwifiex_set_mef_filter(struct mwifiex_private * priv,struct cfg80211_wowlan * wowlan)3372 static int mwifiex_set_mef_filter(struct mwifiex_private *priv,
3373 struct cfg80211_wowlan *wowlan)
3374 {
3375 int ret = 0, num_entries = 1;
3376 struct mwifiex_ds_mef_cfg mef_cfg;
3377 struct mwifiex_mef_entry *mef_entry;
3378
3379 if (wowlan->n_patterns || wowlan->magic_pkt)
3380 num_entries++;
3381
3382 mef_entry = kcalloc(num_entries, sizeof(*mef_entry), GFP_KERNEL);
3383 if (!mef_entry)
3384 return -ENOMEM;
3385
3386 memset(&mef_cfg, 0, sizeof(mef_cfg));
3387 mef_cfg.criteria |= MWIFIEX_CRITERIA_BROADCAST |
3388 MWIFIEX_CRITERIA_UNICAST;
3389 mef_cfg.num_entries = num_entries;
3390 mef_cfg.mef_entry = mef_entry;
3391
3392 mwifiex_set_auto_arp_mef_entry(priv, &mef_entry[0]);
3393
3394 if (wowlan->n_patterns || wowlan->magic_pkt) {
3395 ret = mwifiex_set_wowlan_mef_entry(priv, &mef_cfg,
3396 &mef_entry[1], wowlan);
3397 if (ret)
3398 goto err;
3399 }
3400
3401 if (!mef_cfg.criteria)
3402 mef_cfg.criteria = MWIFIEX_CRITERIA_BROADCAST |
3403 MWIFIEX_CRITERIA_UNICAST |
3404 MWIFIEX_CRITERIA_MULTICAST;
3405
3406 ret = mwifiex_send_cmd(priv, HostCmd_CMD_MEF_CFG,
3407 HostCmd_ACT_GEN_SET, 0,
3408 &mef_cfg, true);
3409
3410 err:
3411 kfree(mef_entry);
3412 return ret;
3413 }
3414
mwifiex_cfg80211_suspend(struct wiphy * wiphy,struct cfg80211_wowlan * wowlan)3415 static int mwifiex_cfg80211_suspend(struct wiphy *wiphy,
3416 struct cfg80211_wowlan *wowlan)
3417 {
3418 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
3419 struct mwifiex_ds_hs_cfg hs_cfg;
3420 int i, ret = 0, retry_num = 10;
3421 struct mwifiex_private *priv;
3422 struct mwifiex_private *sta_priv =
3423 mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_STA);
3424
3425 sta_priv->scan_aborting = true;
3426 for (i = 0; i < adapter->priv_num; i++) {
3427 priv = adapter->priv[i];
3428 mwifiex_abort_cac(priv);
3429 }
3430
3431 mwifiex_cancel_all_pending_cmd(adapter);
3432
3433 for (i = 0; i < adapter->priv_num; i++) {
3434 priv = adapter->priv[i];
3435 if (priv && priv->netdev)
3436 netif_device_detach(priv->netdev);
3437 }
3438
3439 for (i = 0; i < retry_num; i++) {
3440 if (!mwifiex_wmm_lists_empty(adapter) ||
3441 !mwifiex_bypass_txlist_empty(adapter) ||
3442 !skb_queue_empty(&adapter->tx_data_q))
3443 usleep_range(10000, 15000);
3444 else
3445 break;
3446 }
3447
3448 if (!wowlan) {
3449 mwifiex_dbg(adapter, ERROR,
3450 "None of the WOWLAN triggers enabled\n");
3451 ret = 0;
3452 goto done;
3453 }
3454
3455 if (!sta_priv->media_connected && !wowlan->nd_config) {
3456 mwifiex_dbg(adapter, ERROR,
3457 "Can not configure WOWLAN in disconnected state\n");
3458 ret = 0;
3459 goto done;
3460 }
3461
3462 ret = mwifiex_set_mef_filter(sta_priv, wowlan);
3463 if (ret) {
3464 mwifiex_dbg(adapter, ERROR, "Failed to set MEF filter\n");
3465 goto done;
3466 }
3467
3468 memset(&hs_cfg, 0, sizeof(hs_cfg));
3469 hs_cfg.conditions = le32_to_cpu(adapter->hs_cfg.conditions);
3470
3471 if (wowlan->nd_config) {
3472 mwifiex_dbg(adapter, INFO, "Wake on net detect\n");
3473 hs_cfg.conditions |= HS_CFG_COND_MAC_EVENT;
3474 mwifiex_cfg80211_sched_scan_start(wiphy, sta_priv->netdev,
3475 wowlan->nd_config);
3476 }
3477
3478 if (wowlan->disconnect) {
3479 hs_cfg.conditions |= HS_CFG_COND_MAC_EVENT;
3480 mwifiex_dbg(sta_priv->adapter, INFO, "Wake on device disconnect\n");
3481 }
3482
3483 hs_cfg.is_invoke_hostcmd = false;
3484 hs_cfg.gpio = adapter->hs_cfg.gpio;
3485 hs_cfg.gap = adapter->hs_cfg.gap;
3486 ret = mwifiex_set_hs_params(sta_priv, HostCmd_ACT_GEN_SET,
3487 MWIFIEX_SYNC_CMD, &hs_cfg);
3488 if (ret)
3489 mwifiex_dbg(adapter, ERROR, "Failed to set HS params\n");
3490
3491 done:
3492 sta_priv->scan_aborting = false;
3493 return ret;
3494 }
3495
mwifiex_cfg80211_resume(struct wiphy * wiphy)3496 static int mwifiex_cfg80211_resume(struct wiphy *wiphy)
3497 {
3498 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
3499 struct mwifiex_private *priv;
3500 struct mwifiex_ds_wakeup_reason wakeup_reason;
3501 struct cfg80211_wowlan_wakeup wakeup_report;
3502 int i;
3503 bool report_wakeup_reason = true;
3504
3505 for (i = 0; i < adapter->priv_num; i++) {
3506 priv = adapter->priv[i];
3507 if (priv && priv->netdev)
3508 netif_device_attach(priv->netdev);
3509 }
3510
3511 if (!wiphy->wowlan_config)
3512 goto done;
3513
3514 priv = mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_STA);
3515 mwifiex_get_wakeup_reason(priv, HostCmd_ACT_GEN_GET, MWIFIEX_SYNC_CMD,
3516 &wakeup_reason);
3517 memset(&wakeup_report, 0, sizeof(struct cfg80211_wowlan_wakeup));
3518
3519 wakeup_report.pattern_idx = -1;
3520
3521 switch (wakeup_reason.hs_wakeup_reason) {
3522 case NO_HSWAKEUP_REASON:
3523 break;
3524 case BCAST_DATA_MATCHED:
3525 break;
3526 case MCAST_DATA_MATCHED:
3527 break;
3528 case UCAST_DATA_MATCHED:
3529 break;
3530 case MASKTABLE_EVENT_MATCHED:
3531 break;
3532 case NON_MASKABLE_EVENT_MATCHED:
3533 if (wiphy->wowlan_config->disconnect)
3534 wakeup_report.disconnect = true;
3535 if (wiphy->wowlan_config->nd_config)
3536 wakeup_report.net_detect = adapter->nd_info;
3537 break;
3538 case NON_MASKABLE_CONDITION_MATCHED:
3539 break;
3540 case MAGIC_PATTERN_MATCHED:
3541 if (wiphy->wowlan_config->magic_pkt)
3542 wakeup_report.magic_pkt = true;
3543 if (wiphy->wowlan_config->n_patterns)
3544 wakeup_report.pattern_idx = 1;
3545 break;
3546 case GTK_REKEY_FAILURE:
3547 if (wiphy->wowlan_config->gtk_rekey_failure)
3548 wakeup_report.gtk_rekey_failure = true;
3549 break;
3550 default:
3551 report_wakeup_reason = false;
3552 break;
3553 }
3554
3555 if (report_wakeup_reason)
3556 cfg80211_report_wowlan_wakeup(&priv->wdev, &wakeup_report,
3557 GFP_KERNEL);
3558
3559 done:
3560 if (adapter->nd_info) {
3561 for (i = 0 ; i < adapter->nd_info->n_matches ; i++)
3562 kfree(adapter->nd_info->matches[i]);
3563 kfree(adapter->nd_info);
3564 adapter->nd_info = NULL;
3565 }
3566
3567 return 0;
3568 }
3569
mwifiex_cfg80211_set_wakeup(struct wiphy * wiphy,bool enabled)3570 static void mwifiex_cfg80211_set_wakeup(struct wiphy *wiphy,
3571 bool enabled)
3572 {
3573 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
3574
3575 device_set_wakeup_enable(adapter->dev, enabled);
3576 }
3577
mwifiex_set_rekey_data(struct wiphy * wiphy,struct net_device * dev,struct cfg80211_gtk_rekey_data * data)3578 static int mwifiex_set_rekey_data(struct wiphy *wiphy, struct net_device *dev,
3579 struct cfg80211_gtk_rekey_data *data)
3580 {
3581 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
3582
3583 if (!ISSUPP_FIRMWARE_SUPPLICANT(priv->adapter->fw_cap_info))
3584 return -EOPNOTSUPP;
3585
3586 return mwifiex_send_cmd(priv, HostCmd_CMD_GTK_REKEY_OFFLOAD_CFG,
3587 HostCmd_ACT_GEN_SET, 0, data, true);
3588 }
3589
3590 #endif
3591
mwifiex_get_coalesce_pkt_type(u8 * byte_seq)3592 static int mwifiex_get_coalesce_pkt_type(u8 *byte_seq)
3593 {
3594 static const u8 ipv4_mc_mac[] = {0x33, 0x33};
3595 static const u8 ipv6_mc_mac[] = {0x01, 0x00, 0x5e};
3596 static const u8 bc_mac[] = {0xff, 0xff, 0xff, 0xff};
3597
3598 if ((byte_seq[0] & 0x01) &&
3599 (byte_seq[MWIFIEX_COALESCE_MAX_BYTESEQ] == 1))
3600 return PACKET_TYPE_UNICAST;
3601 else if (!memcmp(byte_seq, bc_mac, 4))
3602 return PACKET_TYPE_BROADCAST;
3603 else if ((!memcmp(byte_seq, ipv4_mc_mac, 2) &&
3604 byte_seq[MWIFIEX_COALESCE_MAX_BYTESEQ] == 2) ||
3605 (!memcmp(byte_seq, ipv6_mc_mac, 3) &&
3606 byte_seq[MWIFIEX_COALESCE_MAX_BYTESEQ] == 3))
3607 return PACKET_TYPE_MULTICAST;
3608
3609 return 0;
3610 }
3611
3612 static int
mwifiex_fill_coalesce_rule_info(struct mwifiex_private * priv,struct cfg80211_coalesce_rules * crule,struct mwifiex_coalesce_rule * mrule)3613 mwifiex_fill_coalesce_rule_info(struct mwifiex_private *priv,
3614 struct cfg80211_coalesce_rules *crule,
3615 struct mwifiex_coalesce_rule *mrule)
3616 {
3617 u8 byte_seq[MWIFIEX_COALESCE_MAX_BYTESEQ + 1];
3618 struct filt_field_param *param;
3619 int i;
3620
3621 mrule->max_coalescing_delay = crule->delay;
3622
3623 param = mrule->params;
3624
3625 for (i = 0; i < crule->n_patterns; i++) {
3626 memset(byte_seq, 0, sizeof(byte_seq));
3627 if (!mwifiex_is_pattern_supported(&crule->patterns[i],
3628 byte_seq,
3629 MWIFIEX_COALESCE_MAX_BYTESEQ)) {
3630 mwifiex_dbg(priv->adapter, ERROR,
3631 "Pattern not supported\n");
3632 return -EOPNOTSUPP;
3633 }
3634
3635 if (!crule->patterns[i].pkt_offset) {
3636 u8 pkt_type;
3637
3638 pkt_type = mwifiex_get_coalesce_pkt_type(byte_seq);
3639 if (pkt_type && mrule->pkt_type) {
3640 mwifiex_dbg(priv->adapter, ERROR,
3641 "Multiple packet types not allowed\n");
3642 return -EOPNOTSUPP;
3643 } else if (pkt_type) {
3644 mrule->pkt_type = pkt_type;
3645 continue;
3646 }
3647 }
3648
3649 if (crule->condition == NL80211_COALESCE_CONDITION_MATCH)
3650 param->operation = RECV_FILTER_MATCH_TYPE_EQ;
3651 else
3652 param->operation = RECV_FILTER_MATCH_TYPE_NE;
3653
3654 param->operand_len = byte_seq[MWIFIEX_COALESCE_MAX_BYTESEQ];
3655 memcpy(param->operand_byte_stream, byte_seq,
3656 param->operand_len);
3657 param->offset = crule->patterns[i].pkt_offset;
3658 param++;
3659
3660 mrule->num_of_fields++;
3661 }
3662
3663 if (!mrule->pkt_type) {
3664 mwifiex_dbg(priv->adapter, ERROR,
3665 "Packet type can not be determined\n");
3666 return -EOPNOTSUPP;
3667 }
3668
3669 return 0;
3670 }
3671
mwifiex_cfg80211_set_coalesce(struct wiphy * wiphy,struct cfg80211_coalesce * coalesce)3672 static int mwifiex_cfg80211_set_coalesce(struct wiphy *wiphy,
3673 struct cfg80211_coalesce *coalesce)
3674 {
3675 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
3676 int i, ret;
3677 struct mwifiex_ds_coalesce_cfg coalesce_cfg;
3678 struct mwifiex_private *priv =
3679 mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_STA);
3680
3681 memset(&coalesce_cfg, 0, sizeof(coalesce_cfg));
3682 if (!coalesce) {
3683 mwifiex_dbg(adapter, WARN,
3684 "Disable coalesce and reset all previous rules\n");
3685 return mwifiex_send_cmd(priv, HostCmd_CMD_COALESCE_CFG,
3686 HostCmd_ACT_GEN_SET, 0,
3687 &coalesce_cfg, true);
3688 }
3689
3690 coalesce_cfg.num_of_rules = coalesce->n_rules;
3691 for (i = 0; i < coalesce->n_rules; i++) {
3692 ret = mwifiex_fill_coalesce_rule_info(priv, &coalesce->rules[i],
3693 &coalesce_cfg.rule[i]);
3694 if (ret) {
3695 mwifiex_dbg(adapter, ERROR,
3696 "Recheck the patterns provided for rule %d\n",
3697 i + 1);
3698 return ret;
3699 }
3700 }
3701
3702 return mwifiex_send_cmd(priv, HostCmd_CMD_COALESCE_CFG,
3703 HostCmd_ACT_GEN_SET, 0, &coalesce_cfg, true);
3704 }
3705
3706 /* cfg80211 ops handler for tdls_mgmt.
3707 * Function prepares TDLS action frame packets and forwards them to FW
3708 */
3709 static int
mwifiex_cfg80211_tdls_mgmt(struct wiphy * wiphy,struct net_device * dev,const u8 * peer,u8 action_code,u8 dialog_token,u16 status_code,u32 peer_capability,bool initiator,const u8 * extra_ies,size_t extra_ies_len)3710 mwifiex_cfg80211_tdls_mgmt(struct wiphy *wiphy, struct net_device *dev,
3711 const u8 *peer, u8 action_code, u8 dialog_token,
3712 u16 status_code, u32 peer_capability,
3713 bool initiator, const u8 *extra_ies,
3714 size_t extra_ies_len)
3715 {
3716 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
3717 int ret;
3718
3719 if (!(wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS))
3720 return -EOPNOTSUPP;
3721
3722 /* make sure we are in station mode and connected */
3723 if (!(priv->bss_type == MWIFIEX_BSS_TYPE_STA && priv->media_connected))
3724 return -EOPNOTSUPP;
3725
3726 switch (action_code) {
3727 case WLAN_TDLS_SETUP_REQUEST:
3728 mwifiex_dbg(priv->adapter, MSG,
3729 "Send TDLS Setup Request to %pM status_code=%d\n",
3730 peer, status_code);
3731 mwifiex_add_auto_tdls_peer(priv, peer);
3732 ret = mwifiex_send_tdls_data_frame(priv, peer, action_code,
3733 dialog_token, status_code,
3734 extra_ies, extra_ies_len);
3735 break;
3736 case WLAN_TDLS_SETUP_RESPONSE:
3737 mwifiex_add_auto_tdls_peer(priv, peer);
3738 mwifiex_dbg(priv->adapter, MSG,
3739 "Send TDLS Setup Response to %pM status_code=%d\n",
3740 peer, status_code);
3741 ret = mwifiex_send_tdls_data_frame(priv, peer, action_code,
3742 dialog_token, status_code,
3743 extra_ies, extra_ies_len);
3744 break;
3745 case WLAN_TDLS_SETUP_CONFIRM:
3746 mwifiex_dbg(priv->adapter, MSG,
3747 "Send TDLS Confirm to %pM status_code=%d\n", peer,
3748 status_code);
3749 ret = mwifiex_send_tdls_data_frame(priv, peer, action_code,
3750 dialog_token, status_code,
3751 extra_ies, extra_ies_len);
3752 break;
3753 case WLAN_TDLS_TEARDOWN:
3754 mwifiex_dbg(priv->adapter, MSG,
3755 "Send TDLS Tear down to %pM\n", peer);
3756 ret = mwifiex_send_tdls_data_frame(priv, peer, action_code,
3757 dialog_token, status_code,
3758 extra_ies, extra_ies_len);
3759 break;
3760 case WLAN_TDLS_DISCOVERY_REQUEST:
3761 mwifiex_dbg(priv->adapter, MSG,
3762 "Send TDLS Discovery Request to %pM\n", peer);
3763 ret = mwifiex_send_tdls_data_frame(priv, peer, action_code,
3764 dialog_token, status_code,
3765 extra_ies, extra_ies_len);
3766 break;
3767 case WLAN_PUB_ACTION_TDLS_DISCOVER_RES:
3768 mwifiex_dbg(priv->adapter, MSG,
3769 "Send TDLS Discovery Response to %pM\n", peer);
3770 ret = mwifiex_send_tdls_action_frame(priv, peer, action_code,
3771 dialog_token, status_code,
3772 extra_ies, extra_ies_len);
3773 break;
3774 default:
3775 mwifiex_dbg(priv->adapter, ERROR,
3776 "Unknown TDLS mgmt/action frame %pM\n", peer);
3777 ret = -EINVAL;
3778 break;
3779 }
3780
3781 return ret;
3782 }
3783
3784 static int
mwifiex_cfg80211_tdls_oper(struct wiphy * wiphy,struct net_device * dev,const u8 * peer,enum nl80211_tdls_operation action)3785 mwifiex_cfg80211_tdls_oper(struct wiphy *wiphy, struct net_device *dev,
3786 const u8 *peer, enum nl80211_tdls_operation action)
3787 {
3788 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
3789
3790 if (!(wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
3791 !(wiphy->flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP))
3792 return -EOPNOTSUPP;
3793
3794 /* make sure we are in station mode and connected */
3795 if (!(priv->bss_type == MWIFIEX_BSS_TYPE_STA && priv->media_connected))
3796 return -EOPNOTSUPP;
3797
3798 mwifiex_dbg(priv->adapter, MSG,
3799 "TDLS peer=%pM, oper=%d\n", peer, action);
3800
3801 switch (action) {
3802 case NL80211_TDLS_ENABLE_LINK:
3803 action = MWIFIEX_TDLS_ENABLE_LINK;
3804 break;
3805 case NL80211_TDLS_DISABLE_LINK:
3806 action = MWIFIEX_TDLS_DISABLE_LINK;
3807 break;
3808 case NL80211_TDLS_TEARDOWN:
3809 /* shouldn't happen!*/
3810 mwifiex_dbg(priv->adapter, ERROR,
3811 "tdls_oper: teardown from driver not supported\n");
3812 return -EINVAL;
3813 case NL80211_TDLS_SETUP:
3814 /* shouldn't happen!*/
3815 mwifiex_dbg(priv->adapter, ERROR,
3816 "tdls_oper: setup from driver not supported\n");
3817 return -EINVAL;
3818 case NL80211_TDLS_DISCOVERY_REQ:
3819 /* shouldn't happen!*/
3820 mwifiex_dbg(priv->adapter, ERROR,
3821 "tdls_oper: discovery from driver not supported\n");
3822 return -EINVAL;
3823 default:
3824 mwifiex_dbg(priv->adapter, ERROR,
3825 "tdls_oper: operation not supported\n");
3826 return -EOPNOTSUPP;
3827 }
3828
3829 return mwifiex_tdls_oper(priv, peer, action);
3830 }
3831
3832 static int
mwifiex_cfg80211_tdls_chan_switch(struct wiphy * wiphy,struct net_device * dev,const u8 * addr,u8 oper_class,struct cfg80211_chan_def * chandef)3833 mwifiex_cfg80211_tdls_chan_switch(struct wiphy *wiphy, struct net_device *dev,
3834 const u8 *addr, u8 oper_class,
3835 struct cfg80211_chan_def *chandef)
3836 {
3837 struct mwifiex_sta_node *sta_ptr;
3838 u16 chan;
3839 u8 second_chan_offset, band;
3840 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
3841
3842 spin_lock_bh(&priv->sta_list_spinlock);
3843 sta_ptr = mwifiex_get_sta_entry(priv, addr);
3844 if (!sta_ptr) {
3845 spin_unlock_bh(&priv->sta_list_spinlock);
3846 wiphy_err(wiphy, "%s: Invalid TDLS peer %pM\n",
3847 __func__, addr);
3848 return -ENOENT;
3849 }
3850
3851 if (!(sta_ptr->tdls_cap.extcap.ext_capab[3] &
3852 WLAN_EXT_CAPA4_TDLS_CHAN_SWITCH)) {
3853 spin_unlock_bh(&priv->sta_list_spinlock);
3854 wiphy_err(wiphy, "%pM do not support tdls cs\n", addr);
3855 return -ENOENT;
3856 }
3857
3858 if (sta_ptr->tdls_status == TDLS_CHAN_SWITCHING ||
3859 sta_ptr->tdls_status == TDLS_IN_OFF_CHAN) {
3860 spin_unlock_bh(&priv->sta_list_spinlock);
3861 wiphy_err(wiphy, "channel switch is running, abort request\n");
3862 return -EALREADY;
3863 }
3864 spin_unlock_bh(&priv->sta_list_spinlock);
3865
3866 chan = chandef->chan->hw_value;
3867 second_chan_offset = mwifiex_get_sec_chan_offset(chan);
3868 band = chandef->chan->band;
3869 mwifiex_start_tdls_cs(priv, addr, chan, second_chan_offset, band);
3870
3871 return 0;
3872 }
3873
3874 static void
mwifiex_cfg80211_tdls_cancel_chan_switch(struct wiphy * wiphy,struct net_device * dev,const u8 * addr)3875 mwifiex_cfg80211_tdls_cancel_chan_switch(struct wiphy *wiphy,
3876 struct net_device *dev,
3877 const u8 *addr)
3878 {
3879 struct mwifiex_sta_node *sta_ptr;
3880 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
3881
3882 spin_lock_bh(&priv->sta_list_spinlock);
3883 sta_ptr = mwifiex_get_sta_entry(priv, addr);
3884 if (!sta_ptr) {
3885 spin_unlock_bh(&priv->sta_list_spinlock);
3886 wiphy_err(wiphy, "%s: Invalid TDLS peer %pM\n",
3887 __func__, addr);
3888 } else if (!(sta_ptr->tdls_status == TDLS_CHAN_SWITCHING ||
3889 sta_ptr->tdls_status == TDLS_IN_BASE_CHAN ||
3890 sta_ptr->tdls_status == TDLS_IN_OFF_CHAN)) {
3891 spin_unlock_bh(&priv->sta_list_spinlock);
3892 wiphy_err(wiphy, "tdls chan switch not initialize by %pM\n",
3893 addr);
3894 } else {
3895 spin_unlock_bh(&priv->sta_list_spinlock);
3896 mwifiex_stop_tdls_cs(priv, addr);
3897 }
3898 }
3899
3900 static int
mwifiex_cfg80211_add_station(struct wiphy * wiphy,struct net_device * dev,const u8 * mac,struct station_parameters * params)3901 mwifiex_cfg80211_add_station(struct wiphy *wiphy, struct net_device *dev,
3902 const u8 *mac, struct station_parameters *params)
3903 {
3904 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
3905
3906 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
3907 return -EOPNOTSUPP;
3908
3909 /* make sure we are in station mode and connected */
3910 if ((priv->bss_type != MWIFIEX_BSS_TYPE_STA) || !priv->media_connected)
3911 return -EOPNOTSUPP;
3912
3913 return mwifiex_tdls_oper(priv, mac, MWIFIEX_TDLS_CREATE_LINK);
3914 }
3915
3916 static int
mwifiex_cfg80211_channel_switch(struct wiphy * wiphy,struct net_device * dev,struct cfg80211_csa_settings * params)3917 mwifiex_cfg80211_channel_switch(struct wiphy *wiphy, struct net_device *dev,
3918 struct cfg80211_csa_settings *params)
3919 {
3920 struct ieee_types_header *chsw_ie;
3921 struct ieee80211_channel_sw_ie *channel_sw;
3922 int chsw_msec;
3923 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
3924
3925 if (priv->adapter->scan_processing) {
3926 mwifiex_dbg(priv->adapter, ERROR,
3927 "radar detection: scan in process...\n");
3928 return -EBUSY;
3929 }
3930
3931 if (priv->wdev.cac_started)
3932 return -EBUSY;
3933
3934 if (cfg80211_chandef_identical(¶ms->chandef,
3935 &priv->dfs_chandef))
3936 return -EINVAL;
3937
3938 chsw_ie = (void *)cfg80211_find_ie(WLAN_EID_CHANNEL_SWITCH,
3939 params->beacon_csa.tail,
3940 params->beacon_csa.tail_len);
3941 if (!chsw_ie) {
3942 mwifiex_dbg(priv->adapter, ERROR,
3943 "Could not parse channel switch announcement IE\n");
3944 return -EINVAL;
3945 }
3946
3947 channel_sw = (void *)(chsw_ie + 1);
3948 if (channel_sw->mode) {
3949 if (netif_carrier_ok(priv->netdev))
3950 netif_carrier_off(priv->netdev);
3951 mwifiex_stop_net_dev_queue(priv->netdev, priv->adapter);
3952 }
3953
3954 if (mwifiex_del_mgmt_ies(priv))
3955 mwifiex_dbg(priv->adapter, ERROR,
3956 "Failed to delete mgmt IEs!\n");
3957
3958 if (mwifiex_set_mgmt_ies(priv, ¶ms->beacon_csa)) {
3959 mwifiex_dbg(priv->adapter, ERROR,
3960 "%s: setting mgmt ies failed\n", __func__);
3961 return -EFAULT;
3962 }
3963
3964 memcpy(&priv->dfs_chandef, ¶ms->chandef, sizeof(priv->dfs_chandef));
3965 memcpy(&priv->beacon_after, ¶ms->beacon_after,
3966 sizeof(priv->beacon_after));
3967
3968 chsw_msec = max(channel_sw->count * priv->bss_cfg.beacon_period, 100);
3969 queue_delayed_work(priv->dfs_chan_sw_workqueue, &priv->dfs_chan_sw_work,
3970 msecs_to_jiffies(chsw_msec));
3971 return 0;
3972 }
3973
mwifiex_cfg80211_get_channel(struct wiphy * wiphy,struct wireless_dev * wdev,struct cfg80211_chan_def * chandef)3974 static int mwifiex_cfg80211_get_channel(struct wiphy *wiphy,
3975 struct wireless_dev *wdev,
3976 struct cfg80211_chan_def *chandef)
3977 {
3978 struct mwifiex_private *priv = mwifiex_netdev_get_priv(wdev->netdev);
3979 struct mwifiex_bssdescriptor *curr_bss;
3980 struct ieee80211_channel *chan;
3981 enum nl80211_channel_type chan_type;
3982 enum nl80211_band band;
3983 int freq;
3984 int ret = -ENODATA;
3985
3986 if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_UAP &&
3987 cfg80211_chandef_valid(&priv->bss_chandef)) {
3988 *chandef = priv->bss_chandef;
3989 ret = 0;
3990 } else if (priv->media_connected) {
3991 curr_bss = &priv->curr_bss_params.bss_descriptor;
3992 band = mwifiex_band_to_radio_type(priv->curr_bss_params.band);
3993 freq = ieee80211_channel_to_frequency(curr_bss->channel, band);
3994 chan = ieee80211_get_channel(wiphy, freq);
3995
3996 if (priv->ht_param_present) {
3997 chan_type = mwifiex_get_chan_type(priv);
3998 cfg80211_chandef_create(chandef, chan, chan_type);
3999 } else {
4000 cfg80211_chandef_create(chandef, chan,
4001 NL80211_CHAN_NO_HT);
4002 }
4003 ret = 0;
4004 }
4005
4006 return ret;
4007 }
4008
4009 #ifdef CONFIG_NL80211_TESTMODE
4010
4011 enum mwifiex_tm_attr {
4012 __MWIFIEX_TM_ATTR_INVALID = 0,
4013 MWIFIEX_TM_ATTR_CMD = 1,
4014 MWIFIEX_TM_ATTR_DATA = 2,
4015
4016 /* keep last */
4017 __MWIFIEX_TM_ATTR_AFTER_LAST,
4018 MWIFIEX_TM_ATTR_MAX = __MWIFIEX_TM_ATTR_AFTER_LAST - 1,
4019 };
4020
4021 static const struct nla_policy mwifiex_tm_policy[MWIFIEX_TM_ATTR_MAX + 1] = {
4022 [MWIFIEX_TM_ATTR_CMD] = { .type = NLA_U32 },
4023 [MWIFIEX_TM_ATTR_DATA] = { .type = NLA_BINARY,
4024 .len = MWIFIEX_SIZE_OF_CMD_BUFFER },
4025 };
4026
4027 enum mwifiex_tm_command {
4028 MWIFIEX_TM_CMD_HOSTCMD = 0,
4029 };
4030
mwifiex_tm_cmd(struct wiphy * wiphy,struct wireless_dev * wdev,void * data,int len)4031 static int mwifiex_tm_cmd(struct wiphy *wiphy, struct wireless_dev *wdev,
4032 void *data, int len)
4033 {
4034 struct mwifiex_private *priv = mwifiex_netdev_get_priv(wdev->netdev);
4035 struct mwifiex_ds_misc_cmd *hostcmd;
4036 struct nlattr *tb[MWIFIEX_TM_ATTR_MAX + 1];
4037 struct sk_buff *skb;
4038 int err;
4039
4040 if (!priv)
4041 return -EINVAL;
4042
4043 err = nla_parse_deprecated(tb, MWIFIEX_TM_ATTR_MAX, data, len,
4044 mwifiex_tm_policy, NULL);
4045 if (err)
4046 return err;
4047
4048 if (!tb[MWIFIEX_TM_ATTR_CMD])
4049 return -EINVAL;
4050
4051 switch (nla_get_u32(tb[MWIFIEX_TM_ATTR_CMD])) {
4052 case MWIFIEX_TM_CMD_HOSTCMD:
4053 if (!tb[MWIFIEX_TM_ATTR_DATA])
4054 return -EINVAL;
4055
4056 hostcmd = kzalloc(sizeof(*hostcmd), GFP_KERNEL);
4057 if (!hostcmd)
4058 return -ENOMEM;
4059
4060 hostcmd->len = nla_len(tb[MWIFIEX_TM_ATTR_DATA]);
4061 memcpy(hostcmd->cmd, nla_data(tb[MWIFIEX_TM_ATTR_DATA]),
4062 hostcmd->len);
4063
4064 if (mwifiex_send_cmd(priv, 0, 0, 0, hostcmd, true)) {
4065 dev_err(priv->adapter->dev, "Failed to process hostcmd\n");
4066 kfree(hostcmd);
4067 return -EFAULT;
4068 }
4069
4070 /* process hostcmd response*/
4071 skb = cfg80211_testmode_alloc_reply_skb(wiphy, hostcmd->len);
4072 if (!skb) {
4073 kfree(hostcmd);
4074 return -ENOMEM;
4075 }
4076 err = nla_put(skb, MWIFIEX_TM_ATTR_DATA,
4077 hostcmd->len, hostcmd->cmd);
4078 if (err) {
4079 kfree(hostcmd);
4080 kfree_skb(skb);
4081 return -EMSGSIZE;
4082 }
4083
4084 err = cfg80211_testmode_reply(skb);
4085 kfree(hostcmd);
4086 return err;
4087 default:
4088 return -EOPNOTSUPP;
4089 }
4090 }
4091 #endif
4092
4093 static int
mwifiex_cfg80211_start_radar_detection(struct wiphy * wiphy,struct net_device * dev,struct cfg80211_chan_def * chandef,u32 cac_time_ms)4094 mwifiex_cfg80211_start_radar_detection(struct wiphy *wiphy,
4095 struct net_device *dev,
4096 struct cfg80211_chan_def *chandef,
4097 u32 cac_time_ms)
4098 {
4099 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
4100 struct mwifiex_radar_params radar_params;
4101
4102 if (priv->adapter->scan_processing) {
4103 mwifiex_dbg(priv->adapter, ERROR,
4104 "radar detection: scan already in process...\n");
4105 return -EBUSY;
4106 }
4107
4108 if (!mwifiex_is_11h_active(priv)) {
4109 mwifiex_dbg(priv->adapter, INFO,
4110 "Enable 11h extensions in FW\n");
4111 if (mwifiex_11h_activate(priv, true)) {
4112 mwifiex_dbg(priv->adapter, ERROR,
4113 "Failed to activate 11h extensions!!");
4114 return -1;
4115 }
4116 priv->state_11h.is_11h_active = true;
4117 }
4118
4119 memset(&radar_params, 0, sizeof(struct mwifiex_radar_params));
4120 radar_params.chandef = chandef;
4121 radar_params.cac_time_ms = cac_time_ms;
4122
4123 memcpy(&priv->dfs_chandef, chandef, sizeof(priv->dfs_chandef));
4124
4125 if (mwifiex_send_cmd(priv, HostCmd_CMD_CHAN_REPORT_REQUEST,
4126 HostCmd_ACT_GEN_SET, 0, &radar_params, true))
4127 return -1;
4128
4129 queue_delayed_work(priv->dfs_cac_workqueue, &priv->dfs_cac_work,
4130 msecs_to_jiffies(cac_time_ms));
4131 return 0;
4132 }
4133
4134 static int
mwifiex_cfg80211_change_station(struct wiphy * wiphy,struct net_device * dev,const u8 * mac,struct station_parameters * params)4135 mwifiex_cfg80211_change_station(struct wiphy *wiphy, struct net_device *dev,
4136 const u8 *mac,
4137 struct station_parameters *params)
4138 {
4139 int ret;
4140 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
4141
4142 /* we support change_station handler only for TDLS peers*/
4143 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
4144 return -EOPNOTSUPP;
4145
4146 /* make sure we are in station mode and connected */
4147 if ((priv->bss_type != MWIFIEX_BSS_TYPE_STA) || !priv->media_connected)
4148 return -EOPNOTSUPP;
4149
4150 priv->sta_params = params;
4151
4152 ret = mwifiex_tdls_oper(priv, mac, MWIFIEX_TDLS_CONFIG_LINK);
4153 priv->sta_params = NULL;
4154
4155 return ret;
4156 }
4157
4158 /* station cfg80211 operations */
4159 static struct cfg80211_ops mwifiex_cfg80211_ops = {
4160 .add_virtual_intf = mwifiex_add_virtual_intf,
4161 .del_virtual_intf = mwifiex_del_virtual_intf,
4162 .change_virtual_intf = mwifiex_cfg80211_change_virtual_intf,
4163 .scan = mwifiex_cfg80211_scan,
4164 .connect = mwifiex_cfg80211_connect,
4165 .disconnect = mwifiex_cfg80211_disconnect,
4166 .get_station = mwifiex_cfg80211_get_station,
4167 .dump_station = mwifiex_cfg80211_dump_station,
4168 .dump_survey = mwifiex_cfg80211_dump_survey,
4169 .set_wiphy_params = mwifiex_cfg80211_set_wiphy_params,
4170 .join_ibss = mwifiex_cfg80211_join_ibss,
4171 .leave_ibss = mwifiex_cfg80211_leave_ibss,
4172 .add_key = mwifiex_cfg80211_add_key,
4173 .del_key = mwifiex_cfg80211_del_key,
4174 .set_default_mgmt_key = mwifiex_cfg80211_set_default_mgmt_key,
4175 .mgmt_tx = mwifiex_cfg80211_mgmt_tx,
4176 .update_mgmt_frame_registrations =
4177 mwifiex_cfg80211_update_mgmt_frame_registrations,
4178 .remain_on_channel = mwifiex_cfg80211_remain_on_channel,
4179 .cancel_remain_on_channel = mwifiex_cfg80211_cancel_remain_on_channel,
4180 .set_default_key = mwifiex_cfg80211_set_default_key,
4181 .set_power_mgmt = mwifiex_cfg80211_set_power_mgmt,
4182 .set_tx_power = mwifiex_cfg80211_set_tx_power,
4183 .get_tx_power = mwifiex_cfg80211_get_tx_power,
4184 .set_bitrate_mask = mwifiex_cfg80211_set_bitrate_mask,
4185 .start_ap = mwifiex_cfg80211_start_ap,
4186 .stop_ap = mwifiex_cfg80211_stop_ap,
4187 .change_beacon = mwifiex_cfg80211_change_beacon,
4188 .set_cqm_rssi_config = mwifiex_cfg80211_set_cqm_rssi_config,
4189 .set_antenna = mwifiex_cfg80211_set_antenna,
4190 .get_antenna = mwifiex_cfg80211_get_antenna,
4191 .del_station = mwifiex_cfg80211_del_station,
4192 .sched_scan_start = mwifiex_cfg80211_sched_scan_start,
4193 .sched_scan_stop = mwifiex_cfg80211_sched_scan_stop,
4194 #ifdef CONFIG_PM
4195 .suspend = mwifiex_cfg80211_suspend,
4196 .resume = mwifiex_cfg80211_resume,
4197 .set_wakeup = mwifiex_cfg80211_set_wakeup,
4198 .set_rekey_data = mwifiex_set_rekey_data,
4199 #endif
4200 .set_coalesce = mwifiex_cfg80211_set_coalesce,
4201 .tdls_mgmt = mwifiex_cfg80211_tdls_mgmt,
4202 .tdls_oper = mwifiex_cfg80211_tdls_oper,
4203 .tdls_channel_switch = mwifiex_cfg80211_tdls_chan_switch,
4204 .tdls_cancel_channel_switch = mwifiex_cfg80211_tdls_cancel_chan_switch,
4205 .add_station = mwifiex_cfg80211_add_station,
4206 .change_station = mwifiex_cfg80211_change_station,
4207 CFG80211_TESTMODE_CMD(mwifiex_tm_cmd)
4208 .get_channel = mwifiex_cfg80211_get_channel,
4209 .start_radar_detection = mwifiex_cfg80211_start_radar_detection,
4210 .channel_switch = mwifiex_cfg80211_channel_switch,
4211 };
4212
4213 #ifdef CONFIG_PM
4214 static const struct wiphy_wowlan_support mwifiex_wowlan_support = {
4215 .flags = WIPHY_WOWLAN_MAGIC_PKT | WIPHY_WOWLAN_DISCONNECT |
4216 WIPHY_WOWLAN_NET_DETECT | WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
4217 WIPHY_WOWLAN_GTK_REKEY_FAILURE,
4218 .n_patterns = MWIFIEX_MEF_MAX_FILTERS,
4219 .pattern_min_len = 1,
4220 .pattern_max_len = MWIFIEX_MAX_PATTERN_LEN,
4221 .max_pkt_offset = MWIFIEX_MAX_OFFSET_LEN,
4222 .max_nd_match_sets = MWIFIEX_MAX_ND_MATCH_SETS,
4223 };
4224
4225 static const struct wiphy_wowlan_support mwifiex_wowlan_support_no_gtk = {
4226 .flags = WIPHY_WOWLAN_MAGIC_PKT | WIPHY_WOWLAN_DISCONNECT |
4227 WIPHY_WOWLAN_NET_DETECT,
4228 .n_patterns = MWIFIEX_MEF_MAX_FILTERS,
4229 .pattern_min_len = 1,
4230 .pattern_max_len = MWIFIEX_MAX_PATTERN_LEN,
4231 .max_pkt_offset = MWIFIEX_MAX_OFFSET_LEN,
4232 .max_nd_match_sets = MWIFIEX_MAX_ND_MATCH_SETS,
4233 };
4234 #endif
4235
mwifiex_is_valid_alpha2(const char * alpha2)4236 static bool mwifiex_is_valid_alpha2(const char *alpha2)
4237 {
4238 if (!alpha2 || strlen(alpha2) != 2)
4239 return false;
4240
4241 if (isalpha(alpha2[0]) && isalpha(alpha2[1]))
4242 return true;
4243
4244 return false;
4245 }
4246
4247 static const struct wiphy_coalesce_support mwifiex_coalesce_support = {
4248 .n_rules = MWIFIEX_COALESCE_MAX_RULES,
4249 .max_delay = MWIFIEX_MAX_COALESCING_DELAY,
4250 .n_patterns = MWIFIEX_COALESCE_MAX_FILTERS,
4251 .pattern_min_len = 1,
4252 .pattern_max_len = MWIFIEX_MAX_PATTERN_LEN,
4253 .max_pkt_offset = MWIFIEX_MAX_OFFSET_LEN,
4254 };
4255
mwifiex_init_channel_scan_gap(struct mwifiex_adapter * adapter)4256 int mwifiex_init_channel_scan_gap(struct mwifiex_adapter *adapter)
4257 {
4258 u32 n_channels_bg, n_channels_a = 0;
4259
4260 n_channels_bg = mwifiex_band_2ghz.n_channels;
4261
4262 if (adapter->config_bands & BAND_A)
4263 n_channels_a = mwifiex_band_5ghz.n_channels;
4264
4265 /* allocate twice the number total channels, since the driver issues an
4266 * additional active scan request for hidden SSIDs on passive channels.
4267 */
4268 adapter->num_in_chan_stats = 2 * (n_channels_bg + n_channels_a);
4269 adapter->chan_stats = vmalloc(array_size(sizeof(*adapter->chan_stats),
4270 adapter->num_in_chan_stats));
4271
4272 if (!adapter->chan_stats)
4273 return -ENOMEM;
4274
4275 return 0;
4276 }
4277
4278 /*
4279 * This function registers the device with CFG802.11 subsystem.
4280 *
4281 * The function creates the wireless device/wiphy, populates it with
4282 * default parameters and handler function pointers, and finally
4283 * registers the device.
4284 */
4285
mwifiex_register_cfg80211(struct mwifiex_adapter * adapter)4286 int mwifiex_register_cfg80211(struct mwifiex_adapter *adapter)
4287 {
4288 int ret;
4289 void *wdev_priv;
4290 struct wiphy *wiphy;
4291 struct mwifiex_private *priv = adapter->priv[MWIFIEX_BSS_TYPE_STA];
4292 u8 *country_code;
4293 u32 thr, retry;
4294
4295 /* create a new wiphy for use with cfg80211 */
4296 wiphy = wiphy_new(&mwifiex_cfg80211_ops,
4297 sizeof(struct mwifiex_adapter *));
4298 if (!wiphy) {
4299 mwifiex_dbg(adapter, ERROR,
4300 "%s: creating new wiphy\n", __func__);
4301 return -ENOMEM;
4302 }
4303 wiphy->max_scan_ssids = MWIFIEX_MAX_SSID_LIST_LENGTH;
4304 wiphy->max_scan_ie_len = MWIFIEX_MAX_VSIE_LEN;
4305 wiphy->mgmt_stypes = mwifiex_mgmt_stypes;
4306 wiphy->max_remain_on_channel_duration = 5000;
4307 wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
4308 BIT(NL80211_IFTYPE_P2P_CLIENT) |
4309 BIT(NL80211_IFTYPE_P2P_GO) |
4310 BIT(NL80211_IFTYPE_AP);
4311
4312 if (ISSUPP_ADHOC_ENABLED(adapter->fw_cap_info))
4313 wiphy->interface_modes |= BIT(NL80211_IFTYPE_ADHOC);
4314
4315 wiphy->bands[NL80211_BAND_2GHZ] = &mwifiex_band_2ghz;
4316 if (adapter->config_bands & BAND_A)
4317 wiphy->bands[NL80211_BAND_5GHZ] = &mwifiex_band_5ghz;
4318 else
4319 wiphy->bands[NL80211_BAND_5GHZ] = NULL;
4320
4321 if (adapter->drcs_enabled && ISSUPP_DRCS_ENABLED(adapter->fw_cap_info))
4322 wiphy->iface_combinations = &mwifiex_iface_comb_ap_sta_drcs;
4323 else if (adapter->is_hw_11ac_capable)
4324 wiphy->iface_combinations = &mwifiex_iface_comb_ap_sta_vht;
4325 else
4326 wiphy->iface_combinations = &mwifiex_iface_comb_ap_sta;
4327 wiphy->n_iface_combinations = 1;
4328
4329 if (adapter->max_sta_conn > adapter->max_p2p_conn)
4330 wiphy->max_ap_assoc_sta = adapter->max_sta_conn;
4331 else
4332 wiphy->max_ap_assoc_sta = adapter->max_p2p_conn;
4333
4334 /* Initialize cipher suits */
4335 wiphy->cipher_suites = mwifiex_cipher_suites;
4336 wiphy->n_cipher_suites = ARRAY_SIZE(mwifiex_cipher_suites);
4337
4338 if (adapter->regd) {
4339 wiphy->regulatory_flags |= REGULATORY_CUSTOM_REG |
4340 REGULATORY_DISABLE_BEACON_HINTS |
4341 REGULATORY_COUNTRY_IE_IGNORE;
4342 wiphy_apply_custom_regulatory(wiphy, adapter->regd);
4343 }
4344
4345 ether_addr_copy(wiphy->perm_addr, adapter->perm_addr);
4346 wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
4347 wiphy->flags |= WIPHY_FLAG_HAVE_AP_SME |
4348 WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD |
4349 WIPHY_FLAG_AP_UAPSD |
4350 WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL |
4351 WIPHY_FLAG_HAS_CHANNEL_SWITCH |
4352 WIPHY_FLAG_PS_ON_BY_DEFAULT;
4353
4354 if (ISSUPP_TDLS_ENABLED(adapter->fw_cap_info))
4355 wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS |
4356 WIPHY_FLAG_TDLS_EXTERNAL_SETUP;
4357
4358 #ifdef CONFIG_PM
4359 if (ISSUPP_FIRMWARE_SUPPLICANT(priv->adapter->fw_cap_info))
4360 wiphy->wowlan = &mwifiex_wowlan_support;
4361 else
4362 wiphy->wowlan = &mwifiex_wowlan_support_no_gtk;
4363 #endif
4364
4365 wiphy->coalesce = &mwifiex_coalesce_support;
4366
4367 wiphy->probe_resp_offload = NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS |
4368 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2 |
4369 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P;
4370
4371 wiphy->max_sched_scan_reqs = 1;
4372 wiphy->max_sched_scan_ssids = MWIFIEX_MAX_SSID_LIST_LENGTH;
4373 wiphy->max_sched_scan_ie_len = MWIFIEX_MAX_VSIE_LEN;
4374 wiphy->max_match_sets = MWIFIEX_MAX_SSID_LIST_LENGTH;
4375
4376 wiphy->available_antennas_tx = BIT(adapter->number_of_antenna) - 1;
4377 wiphy->available_antennas_rx = BIT(adapter->number_of_antenna) - 1;
4378
4379 wiphy->features |= NL80211_FEATURE_INACTIVITY_TIMER |
4380 NL80211_FEATURE_LOW_PRIORITY_SCAN |
4381 NL80211_FEATURE_NEED_OBSS_SCAN;
4382
4383 if (ISSUPP_ADHOC_ENABLED(adapter->fw_cap_info))
4384 wiphy->features |= NL80211_FEATURE_HT_IBSS;
4385
4386 if (ISSUPP_RANDOM_MAC(adapter->fw_cap_info))
4387 wiphy->features |= NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR |
4388 NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR |
4389 NL80211_FEATURE_ND_RANDOM_MAC_ADDR;
4390
4391 if (ISSUPP_TDLS_ENABLED(adapter->fw_cap_info))
4392 wiphy->features |= NL80211_FEATURE_TDLS_CHANNEL_SWITCH;
4393
4394 if (adapter->fw_api_ver == MWIFIEX_FW_V15)
4395 wiphy->features |= NL80211_FEATURE_SK_TX_STATUS;
4396
4397 /* Reserve space for mwifiex specific private data for BSS */
4398 wiphy->bss_priv_size = sizeof(struct mwifiex_bss_priv);
4399
4400 wiphy->reg_notifier = mwifiex_reg_notifier;
4401
4402 /* Set struct mwifiex_adapter pointer in wiphy_priv */
4403 wdev_priv = wiphy_priv(wiphy);
4404 *(unsigned long *)wdev_priv = (unsigned long)adapter;
4405
4406 set_wiphy_dev(wiphy, priv->adapter->dev);
4407
4408 ret = wiphy_register(wiphy);
4409 if (ret < 0) {
4410 mwifiex_dbg(adapter, ERROR,
4411 "%s: wiphy_register failed: %d\n", __func__, ret);
4412 wiphy_free(wiphy);
4413 return ret;
4414 }
4415
4416 if (!adapter->regd) {
4417 if (reg_alpha2 && mwifiex_is_valid_alpha2(reg_alpha2)) {
4418 mwifiex_dbg(adapter, INFO,
4419 "driver hint alpha2: %2.2s\n", reg_alpha2);
4420 regulatory_hint(wiphy, reg_alpha2);
4421 } else {
4422 if (adapter->region_code == 0x00) {
4423 mwifiex_dbg(adapter, WARN,
4424 "Ignore world regulatory domain\n");
4425 } else {
4426 wiphy->regulatory_flags |=
4427 REGULATORY_DISABLE_BEACON_HINTS |
4428 REGULATORY_COUNTRY_IE_IGNORE;
4429 country_code =
4430 mwifiex_11d_code_2_region(
4431 adapter->region_code);
4432 if (country_code &&
4433 regulatory_hint(wiphy, country_code))
4434 mwifiex_dbg(priv->adapter, ERROR,
4435 "regulatory_hint() failed\n");
4436 }
4437 }
4438 }
4439
4440 mwifiex_send_cmd(priv, HostCmd_CMD_802_11_SNMP_MIB,
4441 HostCmd_ACT_GEN_GET, FRAG_THRESH_I, &thr, true);
4442 wiphy->frag_threshold = thr;
4443 mwifiex_send_cmd(priv, HostCmd_CMD_802_11_SNMP_MIB,
4444 HostCmd_ACT_GEN_GET, RTS_THRESH_I, &thr, true);
4445 wiphy->rts_threshold = thr;
4446 mwifiex_send_cmd(priv, HostCmd_CMD_802_11_SNMP_MIB,
4447 HostCmd_ACT_GEN_GET, SHORT_RETRY_LIM_I, &retry, true);
4448 wiphy->retry_short = (u8) retry;
4449 mwifiex_send_cmd(priv, HostCmd_CMD_802_11_SNMP_MIB,
4450 HostCmd_ACT_GEN_GET, LONG_RETRY_LIM_I, &retry, true);
4451 wiphy->retry_long = (u8) retry;
4452
4453 adapter->wiphy = wiphy;
4454 return ret;
4455 }
4456