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