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 net_device * netdev,int link_id,u8 key_index,bool pairwise,const u8 * mac_addr)144 mwifiex_cfg80211_del_key(struct wiphy *wiphy, struct net_device *netdev,
145 int link_id, u8 key_index, bool pairwise,
146 const u8 *mac_addr)
147 {
148 struct mwifiex_private *priv = mwifiex_netdev_get_priv(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 *cookie = get_random_u32() | 1;
263
264 if (ieee80211_is_action(mgmt->frame_control))
265 skb = mwifiex_clone_skb_for_tx_status(priv,
266 skb,
267 MWIFIEX_BUF_FLAG_ACTION_TX_STATUS, cookie);
268 else
269 cfg80211_mgmt_tx_status(wdev, *cookie, buf, len, true,
270 GFP_ATOMIC);
271
272 mwifiex_queue_tx_pkt(priv, skb);
273
274 mwifiex_dbg(priv->adapter, INFO, "info: management frame transmitted\n");
275 return 0;
276 }
277
278 /*
279 * CFG802.11 operation handler to register a mgmt frame.
280 */
281 static void
mwifiex_cfg80211_update_mgmt_frame_registrations(struct wiphy * wiphy,struct wireless_dev * wdev,struct mgmt_frame_regs * upd)282 mwifiex_cfg80211_update_mgmt_frame_registrations(struct wiphy *wiphy,
283 struct wireless_dev *wdev,
284 struct mgmt_frame_regs *upd)
285 {
286 struct mwifiex_private *priv = mwifiex_netdev_get_priv(wdev->netdev);
287 u32 mask = upd->interface_stypes;
288
289 if (mask != priv->mgmt_frame_mask) {
290 priv->mgmt_frame_mask = mask;
291 if (priv->host_mlme_reg)
292 priv->mgmt_frame_mask |= HOST_MLME_MGMT_MASK;
293 mwifiex_send_cmd(priv, HostCmd_CMD_MGMT_FRAME_REG,
294 HostCmd_ACT_GEN_SET, 0,
295 &priv->mgmt_frame_mask, false);
296 mwifiex_dbg(priv->adapter, INFO, "info: mgmt frame registered\n");
297 }
298 }
299
300 /*
301 * CFG802.11 operation handler to remain on channel.
302 */
303 static int
mwifiex_cfg80211_remain_on_channel(struct wiphy * wiphy,struct wireless_dev * wdev,struct ieee80211_channel * chan,unsigned int duration,u64 * cookie)304 mwifiex_cfg80211_remain_on_channel(struct wiphy *wiphy,
305 struct wireless_dev *wdev,
306 struct ieee80211_channel *chan,
307 unsigned int duration, u64 *cookie)
308 {
309 struct mwifiex_private *priv = mwifiex_netdev_get_priv(wdev->netdev);
310 int ret;
311
312 if (!chan || !cookie) {
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 *cookie = get_random_u32() | 1;
329 priv->roc_cfg.cookie = *cookie;
330 priv->roc_cfg.chan = *chan;
331
332 cfg80211_ready_on_channel(wdev, *cookie, chan,
333 duration, GFP_ATOMIC);
334
335 mwifiex_dbg(priv->adapter, INFO,
336 "info: ROC, cookie = 0x%llx\n", *cookie);
337 }
338
339 return ret;
340 }
341
342 /*
343 * CFG802.11 operation handler to cancel remain on channel.
344 */
345 static int
mwifiex_cfg80211_cancel_remain_on_channel(struct wiphy * wiphy,struct wireless_dev * wdev,u64 cookie)346 mwifiex_cfg80211_cancel_remain_on_channel(struct wiphy *wiphy,
347 struct wireless_dev *wdev, u64 cookie)
348 {
349 struct mwifiex_private *priv = mwifiex_netdev_get_priv(wdev->netdev);
350 int ret;
351
352 if (cookie != priv->roc_cfg.cookie)
353 return -ENOENT;
354
355 ret = mwifiex_remain_on_chan_cfg(priv, HostCmd_ACT_GEN_REMOVE,
356 &priv->roc_cfg.chan, 0);
357
358 if (!ret) {
359 cfg80211_remain_on_channel_expired(wdev, cookie,
360 &priv->roc_cfg.chan,
361 GFP_ATOMIC);
362
363 memset(&priv->roc_cfg, 0, sizeof(struct mwifiex_roc_cfg));
364
365 mwifiex_dbg(priv->adapter, INFO,
366 "info: cancel ROC, cookie = 0x%llx\n", cookie);
367 }
368
369 return ret;
370 }
371
372 /*
373 * CFG802.11 operation handler to set Tx power.
374 */
375 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)376 mwifiex_cfg80211_set_tx_power(struct wiphy *wiphy,
377 struct wireless_dev *wdev,
378 int radio_idx,
379 enum nl80211_tx_power_setting type,
380 int mbm)
381 {
382 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
383 struct mwifiex_private *priv;
384 struct mwifiex_power_cfg power_cfg;
385 int dbm = MBM_TO_DBM(mbm);
386
387 switch (type) {
388 case NL80211_TX_POWER_FIXED:
389 power_cfg.is_power_auto = 0;
390 power_cfg.is_power_fixed = 1;
391 power_cfg.power_level = dbm;
392 break;
393 case NL80211_TX_POWER_LIMITED:
394 power_cfg.is_power_auto = 0;
395 power_cfg.is_power_fixed = 0;
396 power_cfg.power_level = dbm;
397 break;
398 case NL80211_TX_POWER_AUTOMATIC:
399 power_cfg.is_power_auto = 1;
400 break;
401 }
402
403 priv = mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY);
404
405 return mwifiex_set_tx_power(priv, &power_cfg);
406 }
407
408 /*
409 * CFG802.11 operation handler to get Tx power.
410 */
411 static int
mwifiex_cfg80211_get_tx_power(struct wiphy * wiphy,struct wireless_dev * wdev,int radio_idx,unsigned int link_id,int * dbm)412 mwifiex_cfg80211_get_tx_power(struct wiphy *wiphy,
413 struct wireless_dev *wdev,
414 int radio_idx,
415 unsigned int link_id, int *dbm)
416 {
417 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
418 struct mwifiex_private *priv = mwifiex_get_priv(adapter,
419 MWIFIEX_BSS_ROLE_ANY);
420 int ret = mwifiex_send_cmd(priv, HostCmd_CMD_RF_TX_PWR,
421 HostCmd_ACT_GEN_GET, 0, NULL, true);
422
423 if (ret < 0)
424 return ret;
425
426 /* tx_power_level is set in HostCmd_CMD_RF_TX_PWR command handler */
427 *dbm = priv->tx_power_level;
428
429 return 0;
430 }
431
432 /*
433 * CFG802.11 operation handler to set Power Save option.
434 *
435 * The timeout value, if provided, is currently ignored.
436 */
437 static int
mwifiex_cfg80211_set_power_mgmt(struct wiphy * wiphy,struct net_device * dev,bool enabled,int timeout)438 mwifiex_cfg80211_set_power_mgmt(struct wiphy *wiphy,
439 struct net_device *dev,
440 bool enabled, int timeout)
441 {
442 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
443 u32 ps_mode;
444
445 if (timeout)
446 mwifiex_dbg(priv->adapter, INFO,
447 "info: ignore timeout value for IEEE Power Save\n");
448
449 ps_mode = enabled;
450
451 return mwifiex_drv_set_power(priv, &ps_mode);
452 }
453
454 /*
455 * CFG802.11 operation handler to set the default network key.
456 */
457 static int
mwifiex_cfg80211_set_default_key(struct wiphy * wiphy,struct net_device * netdev,int link_id,u8 key_index,bool unicast,bool multicast)458 mwifiex_cfg80211_set_default_key(struct wiphy *wiphy, struct net_device *netdev,
459 int link_id, u8 key_index, bool unicast,
460 bool multicast)
461 {
462 struct mwifiex_private *priv = mwifiex_netdev_get_priv(netdev);
463
464 /* Return if WEP key not configured */
465 if (!priv->sec_info.wep_enabled)
466 return 0;
467
468 if (priv->bss_type == MWIFIEX_BSS_TYPE_UAP) {
469 priv->wep_key_curr_index = key_index;
470 } else if (mwifiex_set_encode(priv, NULL, NULL, 0, key_index,
471 NULL, 0)) {
472 mwifiex_dbg(priv->adapter, ERROR, "set default Tx key index\n");
473 return -EFAULT;
474 }
475
476 return 0;
477 }
478
479 /*
480 * CFG802.11 operation handler to add a network key.
481 */
482 static int
mwifiex_cfg80211_add_key(struct wiphy * wiphy,struct net_device * netdev,int link_id,u8 key_index,bool pairwise,const u8 * mac_addr,struct key_params * params)483 mwifiex_cfg80211_add_key(struct wiphy *wiphy, struct net_device *netdev,
484 int link_id, u8 key_index, bool pairwise,
485 const u8 *mac_addr, struct key_params *params)
486 {
487 struct mwifiex_private *priv = mwifiex_netdev_get_priv(netdev);
488 struct mwifiex_wep_key *wep_key;
489 static const u8 bc_mac[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
490 const u8 *peer_mac = pairwise ? mac_addr : bc_mac;
491
492 if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_UAP &&
493 (params->cipher == WLAN_CIPHER_SUITE_WEP40 ||
494 params->cipher == WLAN_CIPHER_SUITE_WEP104)) {
495 if (params->key && params->key_len) {
496 wep_key = &priv->wep_key[key_index];
497 memset(wep_key, 0, sizeof(struct mwifiex_wep_key));
498 memcpy(wep_key->key_material, params->key,
499 params->key_len);
500 wep_key->key_index = key_index;
501 wep_key->key_length = params->key_len;
502 priv->sec_info.wep_enabled = 1;
503 }
504 return 0;
505 }
506
507 if (mwifiex_set_encode(priv, params, params->key, params->key_len,
508 key_index, peer_mac, 0)) {
509 mwifiex_dbg(priv->adapter, ERROR, "crypto keys added\n");
510 return -EFAULT;
511 }
512
513 return 0;
514 }
515
516 /*
517 * CFG802.11 operation handler to set default mgmt key.
518 */
519 static int
mwifiex_cfg80211_set_default_mgmt_key(struct wiphy * wiphy,struct net_device * netdev,int link_id,u8 key_index)520 mwifiex_cfg80211_set_default_mgmt_key(struct wiphy *wiphy,
521 struct net_device *netdev,
522 int link_id,
523 u8 key_index)
524 {
525 struct mwifiex_private *priv = mwifiex_netdev_get_priv(netdev);
526 struct mwifiex_ds_encrypt_key encrypt_key;
527
528 wiphy_dbg(wiphy, "set default mgmt key, key index=%d\n", key_index);
529
530 if (priv->adapter->host_mlme_enabled)
531 return 0;
532
533 memset(&encrypt_key, 0, sizeof(struct mwifiex_ds_encrypt_key));
534 encrypt_key.key_len = WLAN_KEY_LEN_CCMP;
535 encrypt_key.key_index = key_index;
536 encrypt_key.is_igtk_def_key = true;
537 eth_broadcast_addr(encrypt_key.mac_addr);
538
539 if (mwifiex_send_cmd(priv, HostCmd_CMD_802_11_KEY_MATERIAL,
540 HostCmd_ACT_GEN_SET, true, &encrypt_key, true)) {
541 mwifiex_dbg(priv->adapter, ERROR,
542 "Sending KEY_MATERIAL command failed\n");
543 return -1;
544 }
545
546 return 0;
547 }
548
549 /*
550 * This function sends domain information to the firmware.
551 *
552 * The following information are passed to the firmware -
553 * - Country codes
554 * - Sub bands (first channel, number of channels, maximum Tx power)
555 */
mwifiex_send_domain_info_cmd_fw(struct wiphy * wiphy)556 int mwifiex_send_domain_info_cmd_fw(struct wiphy *wiphy)
557 {
558 u8 no_of_triplet = 0;
559 struct ieee80211_country_ie_triplet *t;
560 u8 no_of_parsed_chan = 0;
561 u8 first_chan = 0, next_chan = 0, max_pwr = 0;
562 u8 i, flag = 0;
563 enum nl80211_band band;
564 struct ieee80211_supported_band *sband;
565 struct ieee80211_channel *ch;
566 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
567 struct mwifiex_private *priv;
568 struct mwifiex_802_11d_domain_reg *domain_info = &adapter->domain_reg;
569
570 /* Set country code */
571 domain_info->country_code[0] = adapter->country_code[0];
572 domain_info->country_code[1] = adapter->country_code[1];
573 domain_info->country_code[2] = ' ';
574
575 band = mwifiex_band_to_radio_type(adapter->config_bands);
576 if (!wiphy->bands[band]) {
577 mwifiex_dbg(adapter, ERROR,
578 "11D: setting domain info in FW\n");
579 return -1;
580 }
581
582 sband = wiphy->bands[band];
583
584 for (i = 0; i < sband->n_channels ; i++) {
585 ch = &sband->channels[i];
586 if (ch->flags & IEEE80211_CHAN_DISABLED)
587 continue;
588
589 if (!flag) {
590 flag = 1;
591 first_chan = (u32) ch->hw_value;
592 next_chan = first_chan;
593 max_pwr = ch->max_power;
594 no_of_parsed_chan = 1;
595 continue;
596 }
597
598 if (ch->hw_value == next_chan + 1 &&
599 ch->max_power == max_pwr) {
600 next_chan++;
601 no_of_parsed_chan++;
602 } else {
603 t = &domain_info->triplet[no_of_triplet];
604 t->chans.first_channel = first_chan;
605 t->chans.num_channels = no_of_parsed_chan;
606 t->chans.max_power = max_pwr;
607 no_of_triplet++;
608 first_chan = (u32) ch->hw_value;
609 next_chan = first_chan;
610 max_pwr = ch->max_power;
611 no_of_parsed_chan = 1;
612 }
613 }
614
615 if (flag) {
616 t = &domain_info->triplet[no_of_triplet];
617 t->chans.first_channel = first_chan;
618 t->chans.num_channels = no_of_parsed_chan;
619 t->chans.max_power = max_pwr;
620 no_of_triplet++;
621 }
622
623 domain_info->no_of_triplet = no_of_triplet;
624
625 priv = mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY);
626
627 if (mwifiex_send_cmd(priv, HostCmd_CMD_802_11D_DOMAIN_INFO,
628 HostCmd_ACT_GEN_SET, 0, NULL, false)) {
629 mwifiex_dbg(adapter, INFO,
630 "11D: setting domain info in FW\n");
631 return -1;
632 }
633
634 return 0;
635 }
636
mwifiex_reg_apply_radar_flags(struct wiphy * wiphy)637 static void mwifiex_reg_apply_radar_flags(struct wiphy *wiphy)
638 {
639 struct ieee80211_supported_band *sband;
640 struct ieee80211_channel *chan;
641 unsigned int i;
642
643 if (!wiphy->bands[NL80211_BAND_5GHZ])
644 return;
645 sband = wiphy->bands[NL80211_BAND_5GHZ];
646
647 for (i = 0; i < sband->n_channels; i++) {
648 chan = &sband->channels[i];
649 if ((!(chan->flags & IEEE80211_CHAN_DISABLED)) &&
650 (chan->flags & IEEE80211_CHAN_RADAR))
651 chan->flags |= IEEE80211_CHAN_NO_IR;
652 }
653 }
654
655 /*
656 * CFG802.11 regulatory domain callback function.
657 *
658 * This function is called when the regulatory domain is changed due to the
659 * following reasons -
660 * - Set by driver
661 * - Set by system core
662 * - Set by user
663 * - Set bt Country IE
664 */
mwifiex_reg_notifier(struct wiphy * wiphy,struct regulatory_request * request)665 static void mwifiex_reg_notifier(struct wiphy *wiphy,
666 struct regulatory_request *request)
667 {
668 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
669 struct mwifiex_private *priv = mwifiex_get_priv(adapter,
670 MWIFIEX_BSS_ROLE_ANY);
671 mwifiex_dbg(adapter, INFO,
672 "info: cfg80211 regulatory domain callback for %c%c\n",
673 request->alpha2[0], request->alpha2[1]);
674 mwifiex_reg_apply_radar_flags(wiphy);
675
676 switch (request->initiator) {
677 case NL80211_REGDOM_SET_BY_DRIVER:
678 case NL80211_REGDOM_SET_BY_CORE:
679 case NL80211_REGDOM_SET_BY_USER:
680 case NL80211_REGDOM_SET_BY_COUNTRY_IE:
681 break;
682 default:
683 mwifiex_dbg(adapter, ERROR,
684 "unknown regdom initiator: %d\n",
685 request->initiator);
686 return;
687 }
688
689 /* Don't send same regdom info to firmware */
690 if (strncmp(request->alpha2, adapter->country_code,
691 sizeof(request->alpha2)) != 0) {
692 memcpy(adapter->country_code, request->alpha2,
693 sizeof(request->alpha2));
694 mwifiex_send_domain_info_cmd_fw(wiphy);
695 mwifiex_dnld_txpwr_table(priv);
696 }
697 }
698
699 /*
700 * This function sets the fragmentation threshold.
701 *
702 * The fragmentation threshold value must lie between MWIFIEX_FRAG_MIN_VALUE
703 * and MWIFIEX_FRAG_MAX_VALUE.
704 */
705 static int
mwifiex_set_frag(struct mwifiex_private * priv,u32 frag_thr)706 mwifiex_set_frag(struct mwifiex_private *priv, u32 frag_thr)
707 {
708 if (frag_thr < MWIFIEX_FRAG_MIN_VALUE ||
709 frag_thr > MWIFIEX_FRAG_MAX_VALUE)
710 frag_thr = MWIFIEX_FRAG_MAX_VALUE;
711
712 return mwifiex_send_cmd(priv, HostCmd_CMD_802_11_SNMP_MIB,
713 HostCmd_ACT_GEN_SET, FRAG_THRESH_I,
714 &frag_thr, true);
715 }
716
717 /*
718 * This function sets the RTS threshold.
719
720 * The rts value must lie between MWIFIEX_RTS_MIN_VALUE
721 * and MWIFIEX_RTS_MAX_VALUE.
722 */
723 static int
mwifiex_set_rts(struct mwifiex_private * priv,u32 rts_thr)724 mwifiex_set_rts(struct mwifiex_private *priv, u32 rts_thr)
725 {
726 if (rts_thr < MWIFIEX_RTS_MIN_VALUE || rts_thr > MWIFIEX_RTS_MAX_VALUE)
727 rts_thr = MWIFIEX_RTS_MAX_VALUE;
728
729 return mwifiex_send_cmd(priv, HostCmd_CMD_802_11_SNMP_MIB,
730 HostCmd_ACT_GEN_SET, RTS_THRESH_I,
731 &rts_thr, true);
732 }
733
734 /*
735 * CFG802.11 operation handler to set wiphy parameters.
736 *
737 * This function can be used to set the RTS threshold and the
738 * Fragmentation threshold of the driver.
739 */
740 static int
mwifiex_cfg80211_set_wiphy_params(struct wiphy * wiphy,int radio_idx,u32 changed)741 mwifiex_cfg80211_set_wiphy_params(struct wiphy *wiphy, int radio_idx,
742 u32 changed)
743 {
744 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
745 struct mwifiex_private *priv;
746 struct mwifiex_uap_bss_param *bss_cfg;
747 int ret;
748
749 priv = mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY);
750
751 switch (priv->bss_role) {
752 case MWIFIEX_BSS_ROLE_UAP:
753 if (priv->bss_started) {
754 mwifiex_dbg(adapter, ERROR,
755 "cannot change wiphy params when bss started");
756 return -EINVAL;
757 }
758
759 bss_cfg = kzalloc_obj(*bss_cfg);
760 if (!bss_cfg)
761 return -ENOMEM;
762
763 mwifiex_set_sys_config_invalid_data(bss_cfg);
764
765 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
766 bss_cfg->rts_threshold = wiphy->rts_threshold;
767 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
768 bss_cfg->frag_threshold = wiphy->frag_threshold;
769 if (changed & WIPHY_PARAM_RETRY_LONG)
770 bss_cfg->retry_limit = wiphy->retry_long;
771
772 ret = mwifiex_send_cmd(priv, HostCmd_CMD_UAP_SYS_CONFIG,
773 HostCmd_ACT_GEN_SET,
774 UAP_BSS_PARAMS_I, bss_cfg,
775 false);
776
777 kfree(bss_cfg);
778 if (ret) {
779 mwifiex_dbg(adapter, ERROR,
780 "Failed to set wiphy phy params\n");
781 return ret;
782 }
783 break;
784
785 case MWIFIEX_BSS_ROLE_STA:
786 if (priv->media_connected) {
787 mwifiex_dbg(adapter, ERROR,
788 "cannot change wiphy params when connected");
789 return -EINVAL;
790 }
791 if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
792 ret = mwifiex_set_rts(priv,
793 wiphy->rts_threshold);
794 if (ret)
795 return ret;
796 }
797 if (changed & WIPHY_PARAM_FRAG_THRESHOLD) {
798 ret = mwifiex_set_frag(priv,
799 wiphy->frag_threshold);
800 if (ret)
801 return ret;
802 }
803 break;
804 }
805
806 return 0;
807 }
808
809 static int
mwifiex_cfg80211_deinit_p2p(struct mwifiex_private * priv)810 mwifiex_cfg80211_deinit_p2p(struct mwifiex_private *priv)
811 {
812 u16 mode = P2P_MODE_DISABLE;
813
814 if (mwifiex_send_cmd(priv, HostCmd_CMD_P2P_MODE_CFG,
815 HostCmd_ACT_GEN_SET, 0, &mode, true))
816 return -1;
817
818 return 0;
819 }
820
821 /*
822 * This function initializes the functionalities for P2P client.
823 * The P2P client initialization sequence is:
824 * disable -> device -> client
825 */
826 static int
mwifiex_cfg80211_init_p2p_client(struct mwifiex_private * priv)827 mwifiex_cfg80211_init_p2p_client(struct mwifiex_private *priv)
828 {
829 u16 mode;
830
831 if (mwifiex_cfg80211_deinit_p2p(priv))
832 return -1;
833
834 mode = P2P_MODE_DEVICE;
835 if (mwifiex_send_cmd(priv, HostCmd_CMD_P2P_MODE_CFG,
836 HostCmd_ACT_GEN_SET, 0, &mode, true))
837 return -1;
838
839 mode = P2P_MODE_CLIENT;
840 if (mwifiex_send_cmd(priv, HostCmd_CMD_P2P_MODE_CFG,
841 HostCmd_ACT_GEN_SET, 0, &mode, true))
842 return -1;
843
844 return 0;
845 }
846
847 /*
848 * This function initializes the functionalities for P2P GO.
849 * The P2P GO initialization sequence is:
850 * disable -> device -> GO
851 */
852 static int
mwifiex_cfg80211_init_p2p_go(struct mwifiex_private * priv)853 mwifiex_cfg80211_init_p2p_go(struct mwifiex_private *priv)
854 {
855 u16 mode;
856
857 if (mwifiex_cfg80211_deinit_p2p(priv))
858 return -1;
859
860 mode = P2P_MODE_DEVICE;
861 if (mwifiex_send_cmd(priv, HostCmd_CMD_P2P_MODE_CFG,
862 HostCmd_ACT_GEN_SET, 0, &mode, true))
863 return -1;
864
865 mode = P2P_MODE_GO;
866 if (mwifiex_send_cmd(priv, HostCmd_CMD_P2P_MODE_CFG,
867 HostCmd_ACT_GEN_SET, 0, &mode, true))
868 return -1;
869
870 return 0;
871 }
872
mwifiex_deinit_priv_params(struct mwifiex_private * priv)873 static int mwifiex_deinit_priv_params(struct mwifiex_private *priv)
874 {
875 struct mwifiex_adapter *adapter = priv->adapter;
876 unsigned long flags;
877
878 priv->host_mlme_reg = false;
879 priv->mgmt_frame_mask = 0;
880 if (mwifiex_send_cmd(priv, HostCmd_CMD_MGMT_FRAME_REG,
881 HostCmd_ACT_GEN_SET, 0,
882 &priv->mgmt_frame_mask, false)) {
883 mwifiex_dbg(adapter, ERROR,
884 "could not unregister mgmt frame rx\n");
885 return -1;
886 }
887
888 mwifiex_deauthenticate(priv, NULL);
889
890 spin_lock_irqsave(&adapter->main_proc_lock, flags);
891 adapter->main_locked = true;
892 if (adapter->mwifiex_processing) {
893 spin_unlock_irqrestore(&adapter->main_proc_lock, flags);
894 flush_workqueue(adapter->workqueue);
895 } else {
896 spin_unlock_irqrestore(&adapter->main_proc_lock, flags);
897 }
898
899 spin_lock_bh(&adapter->rx_proc_lock);
900 adapter->rx_locked = true;
901 if (adapter->rx_processing) {
902 spin_unlock_bh(&adapter->rx_proc_lock);
903 flush_workqueue(adapter->rx_workqueue);
904 } else {
905 spin_unlock_bh(&adapter->rx_proc_lock);
906 }
907
908 mwifiex_free_priv(priv);
909 priv->wdev.iftype = NL80211_IFTYPE_UNSPECIFIED;
910 priv->bss_mode = NL80211_IFTYPE_UNSPECIFIED;
911 priv->sec_info.authentication_mode = NL80211_AUTHTYPE_OPEN_SYSTEM;
912
913 return 0;
914 }
915
916 static int
mwifiex_init_new_priv_params(struct mwifiex_private * priv,struct net_device * dev,enum nl80211_iftype type)917 mwifiex_init_new_priv_params(struct mwifiex_private *priv,
918 struct net_device *dev,
919 enum nl80211_iftype type)
920 {
921 struct mwifiex_adapter *adapter = priv->adapter;
922 unsigned long flags;
923
924 mwifiex_init_priv(priv);
925
926 priv->bss_mode = type;
927 priv->wdev.iftype = type;
928
929 mwifiex_init_priv_params(priv, priv->netdev);
930 priv->bss_started = 0;
931
932 switch (type) {
933 case NL80211_IFTYPE_STATION:
934 case NL80211_IFTYPE_ADHOC:
935 priv->bss_role = MWIFIEX_BSS_ROLE_STA;
936 priv->bss_type = MWIFIEX_BSS_TYPE_STA;
937 break;
938 case NL80211_IFTYPE_P2P_CLIENT:
939 priv->bss_role = MWIFIEX_BSS_ROLE_STA;
940 priv->bss_type = MWIFIEX_BSS_TYPE_P2P;
941 break;
942 case NL80211_IFTYPE_P2P_GO:
943 priv->bss_role = MWIFIEX_BSS_ROLE_UAP;
944 priv->bss_type = MWIFIEX_BSS_TYPE_P2P;
945 break;
946 case NL80211_IFTYPE_AP:
947 priv->bss_role = MWIFIEX_BSS_ROLE_UAP;
948 priv->bss_type = MWIFIEX_BSS_TYPE_UAP;
949 break;
950 default:
951 mwifiex_dbg(adapter, ERROR,
952 "%s: changing to %d not supported\n",
953 dev->name, type);
954 return -EOPNOTSUPP;
955 }
956
957 priv->bss_num = mwifiex_get_unused_bss_num(adapter, priv->bss_type);
958
959 spin_lock_irqsave(&adapter->main_proc_lock, flags);
960 adapter->main_locked = false;
961 spin_unlock_irqrestore(&adapter->main_proc_lock, flags);
962
963 spin_lock_bh(&adapter->rx_proc_lock);
964 adapter->rx_locked = false;
965 spin_unlock_bh(&adapter->rx_proc_lock);
966
967 mwifiex_set_mac_address(priv, dev, false, NULL);
968
969 return 0;
970 }
971
972 static bool
is_vif_type_change_allowed(struct mwifiex_adapter * adapter,enum nl80211_iftype old_iftype,enum nl80211_iftype new_iftype)973 is_vif_type_change_allowed(struct mwifiex_adapter *adapter,
974 enum nl80211_iftype old_iftype,
975 enum nl80211_iftype new_iftype)
976 {
977 switch (old_iftype) {
978 case NL80211_IFTYPE_ADHOC:
979 switch (new_iftype) {
980 case NL80211_IFTYPE_STATION:
981 return true;
982 case NL80211_IFTYPE_P2P_CLIENT:
983 case NL80211_IFTYPE_P2P_GO:
984 return adapter->curr_iface_comb.p2p_intf !=
985 adapter->iface_limit.p2p_intf;
986 case NL80211_IFTYPE_AP:
987 return adapter->curr_iface_comb.uap_intf !=
988 adapter->iface_limit.uap_intf;
989 default:
990 return false;
991 }
992
993 case NL80211_IFTYPE_STATION:
994 switch (new_iftype) {
995 case NL80211_IFTYPE_ADHOC:
996 return true;
997 case NL80211_IFTYPE_P2P_CLIENT:
998 case NL80211_IFTYPE_P2P_GO:
999 return adapter->curr_iface_comb.p2p_intf !=
1000 adapter->iface_limit.p2p_intf;
1001 case NL80211_IFTYPE_AP:
1002 return adapter->curr_iface_comb.uap_intf !=
1003 adapter->iface_limit.uap_intf;
1004 default:
1005 return false;
1006 }
1007
1008 case NL80211_IFTYPE_AP:
1009 switch (new_iftype) {
1010 case NL80211_IFTYPE_ADHOC:
1011 case NL80211_IFTYPE_STATION:
1012 return adapter->curr_iface_comb.sta_intf !=
1013 adapter->iface_limit.sta_intf;
1014 case NL80211_IFTYPE_P2P_CLIENT:
1015 case NL80211_IFTYPE_P2P_GO:
1016 return adapter->curr_iface_comb.p2p_intf !=
1017 adapter->iface_limit.p2p_intf;
1018 default:
1019 return false;
1020 }
1021
1022 case NL80211_IFTYPE_P2P_CLIENT:
1023 switch (new_iftype) {
1024 case NL80211_IFTYPE_ADHOC:
1025 case NL80211_IFTYPE_STATION:
1026 return true;
1027 case NL80211_IFTYPE_P2P_GO:
1028 return true;
1029 case NL80211_IFTYPE_AP:
1030 return adapter->curr_iface_comb.uap_intf !=
1031 adapter->iface_limit.uap_intf;
1032 default:
1033 return false;
1034 }
1035
1036 case NL80211_IFTYPE_P2P_GO:
1037 switch (new_iftype) {
1038 case NL80211_IFTYPE_ADHOC:
1039 case NL80211_IFTYPE_STATION:
1040 return true;
1041 case NL80211_IFTYPE_P2P_CLIENT:
1042 return true;
1043 case NL80211_IFTYPE_AP:
1044 return adapter->curr_iface_comb.uap_intf !=
1045 adapter->iface_limit.uap_intf;
1046 default:
1047 return false;
1048 }
1049
1050 default:
1051 break;
1052 }
1053
1054 return false;
1055 }
1056
1057 static void
update_vif_type_counter(struct mwifiex_adapter * adapter,enum nl80211_iftype iftype,int change)1058 update_vif_type_counter(struct mwifiex_adapter *adapter,
1059 enum nl80211_iftype iftype,
1060 int change)
1061 {
1062 switch (iftype) {
1063 case NL80211_IFTYPE_UNSPECIFIED:
1064 case NL80211_IFTYPE_ADHOC:
1065 case NL80211_IFTYPE_STATION:
1066 adapter->curr_iface_comb.sta_intf += change;
1067 break;
1068 case NL80211_IFTYPE_AP:
1069 adapter->curr_iface_comb.uap_intf += change;
1070 break;
1071 case NL80211_IFTYPE_P2P_CLIENT:
1072 case NL80211_IFTYPE_P2P_GO:
1073 adapter->curr_iface_comb.p2p_intf += change;
1074 break;
1075 default:
1076 mwifiex_dbg(adapter, ERROR,
1077 "%s: Unsupported iftype passed: %d\n",
1078 __func__, iftype);
1079 break;
1080 }
1081 }
1082
1083 static int
mwifiex_change_vif_to_p2p(struct net_device * dev,enum nl80211_iftype curr_iftype,enum nl80211_iftype type,struct vif_params * params)1084 mwifiex_change_vif_to_p2p(struct net_device *dev,
1085 enum nl80211_iftype curr_iftype,
1086 enum nl80211_iftype type,
1087 struct vif_params *params)
1088 {
1089 struct mwifiex_private *priv;
1090 struct mwifiex_adapter *adapter;
1091
1092 priv = mwifiex_netdev_get_priv(dev);
1093
1094 if (!priv)
1095 return -1;
1096
1097 adapter = priv->adapter;
1098
1099 mwifiex_dbg(adapter, INFO,
1100 "%s: changing role to p2p\n", dev->name);
1101
1102 if (mwifiex_deinit_priv_params(priv))
1103 return -1;
1104 if (mwifiex_init_new_priv_params(priv, dev, type))
1105 return -1;
1106
1107 update_vif_type_counter(adapter, curr_iftype, -1);
1108 update_vif_type_counter(adapter, type, +1);
1109 dev->ieee80211_ptr->iftype = type;
1110
1111 switch (type) {
1112 case NL80211_IFTYPE_P2P_CLIENT:
1113 if (mwifiex_cfg80211_init_p2p_client(priv))
1114 return -EFAULT;
1115 break;
1116 case NL80211_IFTYPE_P2P_GO:
1117 if (mwifiex_cfg80211_init_p2p_go(priv))
1118 return -EFAULT;
1119 break;
1120 default:
1121 mwifiex_dbg(adapter, ERROR,
1122 "%s: changing to %d not supported\n",
1123 dev->name, type);
1124 return -EOPNOTSUPP;
1125 }
1126
1127 if (mwifiex_send_cmd(priv, HostCmd_CMD_SET_BSS_MODE,
1128 HostCmd_ACT_GEN_SET, 0, NULL, true))
1129 return -1;
1130
1131 if (mwifiex_sta_init_cmd(priv, false))
1132 return -1;
1133
1134 return 0;
1135 }
1136
1137 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)1138 mwifiex_change_vif_to_sta_adhoc(struct net_device *dev,
1139 enum nl80211_iftype curr_iftype,
1140 enum nl80211_iftype type,
1141 struct vif_params *params)
1142 {
1143 struct mwifiex_private *priv;
1144 struct mwifiex_adapter *adapter;
1145
1146 priv = mwifiex_netdev_get_priv(dev);
1147
1148 if (!priv)
1149 return -1;
1150
1151 adapter = priv->adapter;
1152
1153 if (type == NL80211_IFTYPE_STATION)
1154 mwifiex_dbg(adapter, INFO,
1155 "%s: changing role to station\n", dev->name);
1156 else
1157 mwifiex_dbg(adapter, INFO,
1158 "%s: changing role to adhoc\n", dev->name);
1159
1160 if (mwifiex_deinit_priv_params(priv))
1161 return -1;
1162 if (mwifiex_init_new_priv_params(priv, dev, type))
1163 return -1;
1164
1165 update_vif_type_counter(adapter, curr_iftype, -1);
1166 update_vif_type_counter(adapter, type, +1);
1167 dev->ieee80211_ptr->iftype = type;
1168
1169 if (mwifiex_send_cmd(priv, HostCmd_CMD_SET_BSS_MODE,
1170 HostCmd_ACT_GEN_SET, 0, NULL, true))
1171 return -1;
1172 if (mwifiex_sta_init_cmd(priv, false))
1173 return -1;
1174
1175 return 0;
1176 }
1177
1178 static int
mwifiex_change_vif_to_ap(struct net_device * dev,enum nl80211_iftype curr_iftype,enum nl80211_iftype type,struct vif_params * params)1179 mwifiex_change_vif_to_ap(struct net_device *dev,
1180 enum nl80211_iftype curr_iftype,
1181 enum nl80211_iftype type,
1182 struct vif_params *params)
1183 {
1184 struct mwifiex_private *priv;
1185 struct mwifiex_adapter *adapter;
1186
1187 priv = mwifiex_netdev_get_priv(dev);
1188
1189 if (!priv)
1190 return -1;
1191
1192 adapter = priv->adapter;
1193
1194 mwifiex_dbg(adapter, INFO,
1195 "%s: changing role to AP\n", dev->name);
1196
1197 if (mwifiex_deinit_priv_params(priv))
1198 return -1;
1199 if (mwifiex_init_new_priv_params(priv, dev, type))
1200 return -1;
1201
1202 update_vif_type_counter(adapter, curr_iftype, -1);
1203 update_vif_type_counter(adapter, type, +1);
1204 dev->ieee80211_ptr->iftype = type;
1205
1206 if (mwifiex_send_cmd(priv, HostCmd_CMD_SET_BSS_MODE,
1207 HostCmd_ACT_GEN_SET, 0, NULL, true))
1208 return -1;
1209 if (mwifiex_sta_init_cmd(priv, false))
1210 return -1;
1211
1212 return 0;
1213 }
1214 /*
1215 * CFG802.11 operation handler to change interface type.
1216 */
1217 static int
mwifiex_cfg80211_change_virtual_intf(struct wiphy * wiphy,struct net_device * dev,enum nl80211_iftype type,struct vif_params * params)1218 mwifiex_cfg80211_change_virtual_intf(struct wiphy *wiphy,
1219 struct net_device *dev,
1220 enum nl80211_iftype type,
1221 struct vif_params *params)
1222 {
1223 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
1224 enum nl80211_iftype curr_iftype = dev->ieee80211_ptr->iftype;
1225
1226 if (priv->scan_request) {
1227 mwifiex_dbg(priv->adapter, ERROR,
1228 "change virtual interface: scan in process\n");
1229 return -EBUSY;
1230 }
1231
1232 if (type == NL80211_IFTYPE_UNSPECIFIED) {
1233 mwifiex_dbg(priv->adapter, INFO,
1234 "%s: no new type specified, keeping old type %d\n",
1235 dev->name, curr_iftype);
1236 return 0;
1237 }
1238
1239 if (curr_iftype == type) {
1240 mwifiex_dbg(priv->adapter, INFO,
1241 "%s: interface already is of type %d\n",
1242 dev->name, curr_iftype);
1243 return 0;
1244 }
1245
1246 if (!is_vif_type_change_allowed(priv->adapter, curr_iftype, type)) {
1247 mwifiex_dbg(priv->adapter, ERROR,
1248 "%s: change from type %d to %d is not allowed\n",
1249 dev->name, curr_iftype, type);
1250 return -EOPNOTSUPP;
1251 }
1252
1253 switch (curr_iftype) {
1254 case NL80211_IFTYPE_ADHOC:
1255 switch (type) {
1256 case NL80211_IFTYPE_STATION:
1257 priv->bss_mode = type;
1258 priv->sec_info.authentication_mode =
1259 NL80211_AUTHTYPE_OPEN_SYSTEM;
1260 dev->ieee80211_ptr->iftype = type;
1261 mwifiex_deauthenticate(priv, NULL);
1262 return mwifiex_send_cmd(priv, HostCmd_CMD_SET_BSS_MODE,
1263 HostCmd_ACT_GEN_SET, 0, NULL,
1264 true);
1265 case NL80211_IFTYPE_P2P_CLIENT:
1266 case NL80211_IFTYPE_P2P_GO:
1267 return mwifiex_change_vif_to_p2p(dev, curr_iftype,
1268 type, params);
1269 case NL80211_IFTYPE_AP:
1270 return mwifiex_change_vif_to_ap(dev, curr_iftype, type,
1271 params);
1272 default:
1273 goto errnotsupp;
1274 }
1275
1276 case NL80211_IFTYPE_STATION:
1277 switch (type) {
1278 case NL80211_IFTYPE_ADHOC:
1279 priv->bss_mode = type;
1280 priv->sec_info.authentication_mode =
1281 NL80211_AUTHTYPE_OPEN_SYSTEM;
1282 dev->ieee80211_ptr->iftype = type;
1283 mwifiex_deauthenticate(priv, NULL);
1284 return mwifiex_send_cmd(priv, HostCmd_CMD_SET_BSS_MODE,
1285 HostCmd_ACT_GEN_SET, 0, NULL,
1286 true);
1287 case NL80211_IFTYPE_P2P_CLIENT:
1288 case NL80211_IFTYPE_P2P_GO:
1289 return mwifiex_change_vif_to_p2p(dev, curr_iftype,
1290 type, params);
1291 case NL80211_IFTYPE_AP:
1292 return mwifiex_change_vif_to_ap(dev, curr_iftype, type,
1293 params);
1294 default:
1295 goto errnotsupp;
1296 }
1297
1298 case NL80211_IFTYPE_AP:
1299 switch (type) {
1300 case NL80211_IFTYPE_ADHOC:
1301 case NL80211_IFTYPE_STATION:
1302 return mwifiex_change_vif_to_sta_adhoc(dev, curr_iftype,
1303 type, params);
1304 break;
1305 case NL80211_IFTYPE_P2P_CLIENT:
1306 case NL80211_IFTYPE_P2P_GO:
1307 return mwifiex_change_vif_to_p2p(dev, curr_iftype,
1308 type, params);
1309 default:
1310 goto errnotsupp;
1311 }
1312
1313 case NL80211_IFTYPE_P2P_CLIENT:
1314 if (mwifiex_cfg80211_deinit_p2p(priv))
1315 return -EFAULT;
1316
1317 switch (type) {
1318 case NL80211_IFTYPE_ADHOC:
1319 case NL80211_IFTYPE_STATION:
1320 return mwifiex_change_vif_to_sta_adhoc(dev, curr_iftype,
1321 type, params);
1322 case NL80211_IFTYPE_P2P_GO:
1323 return mwifiex_change_vif_to_p2p(dev, curr_iftype,
1324 type, params);
1325 case NL80211_IFTYPE_AP:
1326 return mwifiex_change_vif_to_ap(dev, curr_iftype, type,
1327 params);
1328 default:
1329 goto errnotsupp;
1330 }
1331
1332 case NL80211_IFTYPE_P2P_GO:
1333 if (mwifiex_cfg80211_deinit_p2p(priv))
1334 return -EFAULT;
1335
1336 switch (type) {
1337 case NL80211_IFTYPE_ADHOC:
1338 case NL80211_IFTYPE_STATION:
1339 return mwifiex_change_vif_to_sta_adhoc(dev, curr_iftype,
1340 type, params);
1341 case NL80211_IFTYPE_P2P_CLIENT:
1342 return mwifiex_change_vif_to_p2p(dev, curr_iftype,
1343 type, params);
1344 case NL80211_IFTYPE_AP:
1345 return mwifiex_change_vif_to_ap(dev, curr_iftype, type,
1346 params);
1347 default:
1348 goto errnotsupp;
1349 }
1350
1351 default:
1352 goto errnotsupp;
1353 }
1354
1355
1356 return 0;
1357
1358 errnotsupp:
1359 mwifiex_dbg(priv->adapter, ERROR,
1360 "unsupported interface type transition: %d to %d\n",
1361 curr_iftype, type);
1362 return -EOPNOTSUPP;
1363 }
1364
1365 static void
mwifiex_parse_htinfo(struct mwifiex_private * priv,u8 rateinfo,u8 htinfo,struct rate_info * rate)1366 mwifiex_parse_htinfo(struct mwifiex_private *priv, u8 rateinfo, u8 htinfo,
1367 struct rate_info *rate)
1368 {
1369 struct mwifiex_adapter *adapter = priv->adapter;
1370
1371 if (adapter->is_hw_11ac_capable) {
1372 /* bit[1-0]: 00=LG 01=HT 10=VHT */
1373 if (htinfo & BIT(0)) {
1374 /* HT */
1375 rate->mcs = rateinfo;
1376 rate->flags |= RATE_INFO_FLAGS_MCS;
1377 }
1378 if (htinfo & BIT(1)) {
1379 /* VHT */
1380 rate->mcs = rateinfo & 0x0F;
1381 rate->flags |= RATE_INFO_FLAGS_VHT_MCS;
1382 }
1383
1384 if (htinfo & (BIT(1) | BIT(0))) {
1385 /* HT or VHT */
1386 switch (htinfo & (BIT(3) | BIT(2))) {
1387 case 0:
1388 rate->bw = RATE_INFO_BW_20;
1389 break;
1390 case (BIT(2)):
1391 rate->bw = RATE_INFO_BW_40;
1392 break;
1393 case (BIT(3)):
1394 rate->bw = RATE_INFO_BW_80;
1395 break;
1396 case (BIT(3) | BIT(2)):
1397 rate->bw = RATE_INFO_BW_160;
1398 break;
1399 }
1400
1401 if (htinfo & BIT(4))
1402 rate->flags |= RATE_INFO_FLAGS_SHORT_GI;
1403
1404 if ((rateinfo >> 4) == 1)
1405 rate->nss = 2;
1406 else
1407 rate->nss = 1;
1408 }
1409 } else {
1410 /*
1411 * Bit 0 in htinfo indicates that current rate is 11n. Valid
1412 * MCS index values for us are 0 to 15.
1413 */
1414 if ((htinfo & BIT(0)) && (rateinfo < 16)) {
1415 rate->mcs = rateinfo;
1416 rate->flags |= RATE_INFO_FLAGS_MCS;
1417 rate->bw = RATE_INFO_BW_20;
1418 if (htinfo & BIT(1))
1419 rate->bw = RATE_INFO_BW_40;
1420 if (htinfo & BIT(2))
1421 rate->flags |= RATE_INFO_FLAGS_SHORT_GI;
1422 }
1423 }
1424
1425 /* Decode legacy rates for non-HT. */
1426 if (!(htinfo & (BIT(0) | BIT(1)))) {
1427 /* Bitrates in multiples of 100kb/s. */
1428 static const int legacy_rates[] = {
1429 [0] = 10,
1430 [1] = 20,
1431 [2] = 55,
1432 [3] = 110,
1433 [4] = 60, /* MWIFIEX_RATE_INDEX_OFDM0 */
1434 [5] = 60,
1435 [6] = 90,
1436 [7] = 120,
1437 [8] = 180,
1438 [9] = 240,
1439 [10] = 360,
1440 [11] = 480,
1441 [12] = 540,
1442 };
1443 if (rateinfo < ARRAY_SIZE(legacy_rates))
1444 rate->legacy = legacy_rates[rateinfo];
1445 }
1446 }
1447
1448 /*
1449 * This function dumps the station information on a buffer.
1450 *
1451 * The following information are shown -
1452 * - Total bytes transmitted
1453 * - Total bytes received
1454 * - Total packets transmitted
1455 * - Total packets received
1456 * - Signal quality level
1457 * - Transmission rate
1458 */
1459 static int
mwifiex_dump_station_info(struct mwifiex_private * priv,struct mwifiex_sta_node * node,struct station_info * sinfo)1460 mwifiex_dump_station_info(struct mwifiex_private *priv,
1461 struct mwifiex_sta_node *node,
1462 struct station_info *sinfo)
1463 {
1464 u32 rate;
1465
1466 sinfo->filled = BIT_ULL(NL80211_STA_INFO_RX_BYTES) | BIT_ULL(NL80211_STA_INFO_TX_BYTES) |
1467 BIT_ULL(NL80211_STA_INFO_RX_PACKETS) | BIT_ULL(NL80211_STA_INFO_TX_PACKETS) |
1468 BIT_ULL(NL80211_STA_INFO_TX_BITRATE) |
1469 BIT_ULL(NL80211_STA_INFO_SIGNAL) | BIT_ULL(NL80211_STA_INFO_SIGNAL_AVG);
1470
1471 if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_UAP) {
1472 if (!node)
1473 return -ENOENT;
1474
1475 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_INACTIVE_TIME) |
1476 BIT_ULL(NL80211_STA_INFO_TX_FAILED);
1477 sinfo->inactive_time =
1478 jiffies_to_msecs(jiffies - node->stats.last_rx);
1479
1480 sinfo->signal = node->stats.rssi;
1481 sinfo->signal_avg = node->stats.rssi;
1482 sinfo->rx_bytes = node->stats.rx_bytes;
1483 sinfo->tx_bytes = node->stats.tx_bytes;
1484 sinfo->rx_packets = node->stats.rx_packets;
1485 sinfo->tx_packets = node->stats.tx_packets;
1486 sinfo->tx_failed = node->stats.tx_failed;
1487
1488 mwifiex_parse_htinfo(priv, priv->tx_rate,
1489 node->stats.last_tx_htinfo,
1490 &sinfo->txrate);
1491 sinfo->txrate.legacy = node->stats.last_tx_rate * 5;
1492
1493 return 0;
1494 }
1495
1496 /* Get signal information from the firmware */
1497 if (mwifiex_send_cmd(priv, HostCmd_CMD_RSSI_INFO,
1498 HostCmd_ACT_GEN_GET, 0, NULL, true)) {
1499 mwifiex_dbg(priv->adapter, ERROR,
1500 "failed to get signal information\n");
1501 return -EFAULT;
1502 }
1503
1504 if (mwifiex_drv_get_data_rate(priv, &rate)) {
1505 mwifiex_dbg(priv->adapter, ERROR,
1506 "getting data rate error\n");
1507 return -EFAULT;
1508 }
1509
1510 /* Get DTIM period information from firmware */
1511 mwifiex_send_cmd(priv, HostCmd_CMD_802_11_SNMP_MIB,
1512 HostCmd_ACT_GEN_GET, DTIM_PERIOD_I,
1513 &priv->dtim_period, true);
1514
1515 mwifiex_parse_htinfo(priv, priv->tx_rate, priv->tx_htinfo,
1516 &sinfo->txrate);
1517
1518 sinfo->signal_avg = priv->bcn_rssi_avg;
1519 sinfo->rx_bytes = priv->stats.rx_bytes;
1520 sinfo->tx_bytes = priv->stats.tx_bytes;
1521 sinfo->rx_packets = priv->stats.rx_packets;
1522 sinfo->tx_packets = priv->stats.tx_packets;
1523 sinfo->signal = priv->bcn_rssi_avg;
1524 /* bit rate is in 500 kb/s units. Convert it to 100kb/s units */
1525 sinfo->txrate.legacy = rate * 5;
1526
1527 sinfo->filled |= BIT(NL80211_STA_INFO_RX_BITRATE);
1528 mwifiex_parse_htinfo(priv, priv->rxpd_rate, priv->rxpd_htinfo,
1529 &sinfo->rxrate);
1530
1531 if (priv->bss_mode == NL80211_IFTYPE_STATION) {
1532 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_BSS_PARAM);
1533 sinfo->bss_param.flags = 0;
1534 if (priv->curr_bss_params.bss_descriptor.cap_info_bitmap &
1535 WLAN_CAPABILITY_SHORT_PREAMBLE)
1536 sinfo->bss_param.flags |=
1537 BSS_PARAM_FLAGS_SHORT_PREAMBLE;
1538 if (priv->curr_bss_params.bss_descriptor.cap_info_bitmap &
1539 WLAN_CAPABILITY_SHORT_SLOT_TIME)
1540 sinfo->bss_param.flags |=
1541 BSS_PARAM_FLAGS_SHORT_SLOT_TIME;
1542 sinfo->bss_param.dtim_period = priv->dtim_period;
1543 sinfo->bss_param.beacon_interval =
1544 priv->curr_bss_params.bss_descriptor.beacon_period;
1545 }
1546
1547 return 0;
1548 }
1549
1550 /*
1551 * CFG802.11 operation handler to get station information.
1552 *
1553 * This function only works in connected mode, and dumps the
1554 * requested station information, if available.
1555 */
1556 static int
mwifiex_cfg80211_get_station(struct wiphy * wiphy,struct net_device * dev,const u8 * mac,struct station_info * sinfo)1557 mwifiex_cfg80211_get_station(struct wiphy *wiphy, struct net_device *dev,
1558 const u8 *mac, struct station_info *sinfo)
1559 {
1560 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
1561
1562 if (!priv->media_connected)
1563 return -ENOENT;
1564 if (memcmp(mac, priv->cfg_bssid, ETH_ALEN))
1565 return -ENOENT;
1566
1567 return mwifiex_dump_station_info(priv, NULL, sinfo);
1568 }
1569
1570 /*
1571 * CFG802.11 operation handler to dump station information.
1572 */
1573 static int
mwifiex_cfg80211_dump_station(struct wiphy * wiphy,struct net_device * dev,int idx,u8 * mac,struct station_info * sinfo)1574 mwifiex_cfg80211_dump_station(struct wiphy *wiphy, struct net_device *dev,
1575 int idx, u8 *mac, struct station_info *sinfo)
1576 {
1577 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
1578 struct mwifiex_sta_node *node;
1579 int i;
1580
1581 if ((GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA) &&
1582 priv->media_connected && idx == 0) {
1583 ether_addr_copy(mac, priv->cfg_bssid);
1584 return mwifiex_dump_station_info(priv, NULL, sinfo);
1585 } else if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_UAP) {
1586 mwifiex_send_cmd(priv, HOST_CMD_APCMD_STA_LIST,
1587 HostCmd_ACT_GEN_GET, 0, NULL, true);
1588
1589 i = 0;
1590 list_for_each_entry(node, &priv->sta_list, list) {
1591 if (i++ != idx)
1592 continue;
1593 ether_addr_copy(mac, node->mac_addr);
1594 return mwifiex_dump_station_info(priv, node, sinfo);
1595 }
1596 }
1597
1598 return -ENOENT;
1599 }
1600
1601 static int
mwifiex_cfg80211_dump_survey(struct wiphy * wiphy,struct net_device * dev,int idx,struct survey_info * survey)1602 mwifiex_cfg80211_dump_survey(struct wiphy *wiphy, struct net_device *dev,
1603 int idx, struct survey_info *survey)
1604 {
1605 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
1606 struct mwifiex_chan_stats *pchan_stats = priv->adapter->chan_stats;
1607 enum nl80211_band band;
1608
1609 mwifiex_dbg(priv->adapter, DUMP, "dump_survey idx=%d\n", idx);
1610
1611 memset(survey, 0, sizeof(struct survey_info));
1612
1613 if ((GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA) &&
1614 priv->media_connected && idx == 0) {
1615 u8 curr_bss_band = priv->curr_bss_params.band;
1616 u32 chan = priv->curr_bss_params.bss_descriptor.channel;
1617
1618 band = mwifiex_band_to_radio_type(curr_bss_band);
1619 survey->channel = ieee80211_get_channel(wiphy,
1620 ieee80211_channel_to_frequency(chan, band));
1621
1622 if (priv->bcn_nf_last) {
1623 survey->filled = SURVEY_INFO_NOISE_DBM;
1624 survey->noise = priv->bcn_nf_last;
1625 }
1626 return 0;
1627 }
1628
1629 if (idx >= priv->adapter->num_in_chan_stats)
1630 return -ENOENT;
1631
1632 if (!pchan_stats[idx].cca_scan_dur)
1633 return 0;
1634
1635 band = pchan_stats[idx].bandcfg;
1636 survey->channel = ieee80211_get_channel(wiphy,
1637 ieee80211_channel_to_frequency(pchan_stats[idx].chan_num, band));
1638 survey->filled = SURVEY_INFO_NOISE_DBM |
1639 SURVEY_INFO_TIME |
1640 SURVEY_INFO_TIME_BUSY;
1641 survey->noise = pchan_stats[idx].noise;
1642 survey->time = pchan_stats[idx].cca_scan_dur;
1643 survey->time_busy = pchan_stats[idx].cca_busy_dur;
1644
1645 return 0;
1646 }
1647
1648 /* Supported rates to be advertised to the cfg80211 */
1649 static struct ieee80211_rate mwifiex_rates[] = {
1650 {.bitrate = 10, .hw_value = 2, },
1651 {.bitrate = 20, .hw_value = 4, },
1652 {.bitrate = 55, .hw_value = 11, },
1653 {.bitrate = 110, .hw_value = 22, },
1654 {.bitrate = 60, .hw_value = 12, },
1655 {.bitrate = 90, .hw_value = 18, },
1656 {.bitrate = 120, .hw_value = 24, },
1657 {.bitrate = 180, .hw_value = 36, },
1658 {.bitrate = 240, .hw_value = 48, },
1659 {.bitrate = 360, .hw_value = 72, },
1660 {.bitrate = 480, .hw_value = 96, },
1661 {.bitrate = 540, .hw_value = 108, },
1662 };
1663
1664 /* Channel definitions to be advertised to cfg80211 */
1665 static struct ieee80211_channel mwifiex_channels_2ghz[] = {
1666 {.center_freq = 2412, .hw_value = 1, },
1667 {.center_freq = 2417, .hw_value = 2, },
1668 {.center_freq = 2422, .hw_value = 3, },
1669 {.center_freq = 2427, .hw_value = 4, },
1670 {.center_freq = 2432, .hw_value = 5, },
1671 {.center_freq = 2437, .hw_value = 6, },
1672 {.center_freq = 2442, .hw_value = 7, },
1673 {.center_freq = 2447, .hw_value = 8, },
1674 {.center_freq = 2452, .hw_value = 9, },
1675 {.center_freq = 2457, .hw_value = 10, },
1676 {.center_freq = 2462, .hw_value = 11, },
1677 {.center_freq = 2467, .hw_value = 12, },
1678 {.center_freq = 2472, .hw_value = 13, },
1679 {.center_freq = 2484, .hw_value = 14, },
1680 };
1681
1682 static struct ieee80211_supported_band mwifiex_band_2ghz = {
1683 .channels = mwifiex_channels_2ghz,
1684 .n_channels = ARRAY_SIZE(mwifiex_channels_2ghz),
1685 .bitrates = mwifiex_rates,
1686 .n_bitrates = ARRAY_SIZE(mwifiex_rates),
1687 };
1688
1689 static struct ieee80211_channel mwifiex_channels_5ghz[] = {
1690 {.center_freq = 5040, .hw_value = 8, },
1691 {.center_freq = 5060, .hw_value = 12, },
1692 {.center_freq = 5080, .hw_value = 16, },
1693 {.center_freq = 5170, .hw_value = 34, },
1694 {.center_freq = 5190, .hw_value = 38, },
1695 {.center_freq = 5210, .hw_value = 42, },
1696 {.center_freq = 5230, .hw_value = 46, },
1697 {.center_freq = 5180, .hw_value = 36, },
1698 {.center_freq = 5200, .hw_value = 40, },
1699 {.center_freq = 5220, .hw_value = 44, },
1700 {.center_freq = 5240, .hw_value = 48, },
1701 {.center_freq = 5260, .hw_value = 52, },
1702 {.center_freq = 5280, .hw_value = 56, },
1703 {.center_freq = 5300, .hw_value = 60, },
1704 {.center_freq = 5320, .hw_value = 64, },
1705 {.center_freq = 5500, .hw_value = 100, },
1706 {.center_freq = 5520, .hw_value = 104, },
1707 {.center_freq = 5540, .hw_value = 108, },
1708 {.center_freq = 5560, .hw_value = 112, },
1709 {.center_freq = 5580, .hw_value = 116, },
1710 {.center_freq = 5600, .hw_value = 120, },
1711 {.center_freq = 5620, .hw_value = 124, },
1712 {.center_freq = 5640, .hw_value = 128, },
1713 {.center_freq = 5660, .hw_value = 132, },
1714 {.center_freq = 5680, .hw_value = 136, },
1715 {.center_freq = 5700, .hw_value = 140, },
1716 {.center_freq = 5745, .hw_value = 149, },
1717 {.center_freq = 5765, .hw_value = 153, },
1718 {.center_freq = 5785, .hw_value = 157, },
1719 {.center_freq = 5805, .hw_value = 161, },
1720 {.center_freq = 5825, .hw_value = 165, },
1721 };
1722
1723 static struct ieee80211_supported_band mwifiex_band_5ghz = {
1724 .channels = mwifiex_channels_5ghz,
1725 .n_channels = ARRAY_SIZE(mwifiex_channels_5ghz),
1726 .bitrates = mwifiex_rates + 4,
1727 .n_bitrates = ARRAY_SIZE(mwifiex_rates) - 4,
1728 };
1729
1730
1731 /* Supported crypto cipher suits to be advertised to cfg80211 */
1732 static const u32 mwifiex_cipher_suites[] = {
1733 WLAN_CIPHER_SUITE_WEP40,
1734 WLAN_CIPHER_SUITE_WEP104,
1735 WLAN_CIPHER_SUITE_TKIP,
1736 WLAN_CIPHER_SUITE_CCMP,
1737 WLAN_CIPHER_SUITE_SMS4,
1738 WLAN_CIPHER_SUITE_AES_CMAC,
1739 };
1740
1741 /* Supported mgmt frame types to be advertised to cfg80211 */
1742 static const struct ieee80211_txrx_stypes
1743 mwifiex_mgmt_stypes[NUM_NL80211_IFTYPES] = {
1744 [NL80211_IFTYPE_STATION] = {
1745 .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
1746 BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
1747 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
1748 BIT(IEEE80211_STYPE_PROBE_REQ >> 4),
1749 },
1750 [NL80211_IFTYPE_AP] = {
1751 .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
1752 BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
1753 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
1754 BIT(IEEE80211_STYPE_PROBE_REQ >> 4),
1755 },
1756 [NL80211_IFTYPE_P2P_CLIENT] = {
1757 .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
1758 BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
1759 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
1760 BIT(IEEE80211_STYPE_PROBE_REQ >> 4),
1761 },
1762 [NL80211_IFTYPE_P2P_GO] = {
1763 .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
1764 BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
1765 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
1766 BIT(IEEE80211_STYPE_PROBE_REQ >> 4),
1767 },
1768 };
1769
1770 /*
1771 * CFG802.11 operation handler for setting bit rates.
1772 *
1773 * Function configures data rates to firmware using bitrate mask
1774 * provided by cfg80211.
1775 */
1776 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)1777 mwifiex_cfg80211_set_bitrate_mask(struct wiphy *wiphy,
1778 struct net_device *dev,
1779 unsigned int link_id,
1780 const u8 *peer,
1781 const struct cfg80211_bitrate_mask *mask)
1782 {
1783 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
1784 u16 bitmap_rates[MAX_BITMAP_RATES_SIZE];
1785 enum nl80211_band band;
1786 struct mwifiex_adapter *adapter = priv->adapter;
1787
1788 if (!priv->media_connected) {
1789 mwifiex_dbg(adapter, ERROR,
1790 "Can not set Tx data rate in disconnected state\n");
1791 return -EINVAL;
1792 }
1793
1794 band = mwifiex_band_to_radio_type(priv->curr_bss_params.band);
1795
1796 memset(bitmap_rates, 0, sizeof(bitmap_rates));
1797
1798 /* Fill HR/DSSS rates. */
1799 if (band == NL80211_BAND_2GHZ)
1800 bitmap_rates[0] = mask->control[band].legacy & 0x000f;
1801
1802 /* Fill OFDM rates */
1803 if (band == NL80211_BAND_2GHZ)
1804 bitmap_rates[1] = (mask->control[band].legacy & 0x0ff0) >> 4;
1805 else
1806 bitmap_rates[1] = mask->control[band].legacy;
1807
1808 /* Fill HT MCS rates */
1809 bitmap_rates[2] = mask->control[band].ht_mcs[0];
1810 if (adapter->hw_dev_mcs_support == HT_STREAM_2X2)
1811 bitmap_rates[2] |= mask->control[band].ht_mcs[1] << 8;
1812
1813 /* Fill VHT MCS rates */
1814 if (adapter->fw_api_ver == MWIFIEX_FW_V15) {
1815 bitmap_rates[10] = mask->control[band].vht_mcs[0];
1816 if (adapter->hw_dev_mcs_support == HT_STREAM_2X2)
1817 bitmap_rates[11] = mask->control[band].vht_mcs[1];
1818 }
1819
1820 return mwifiex_send_cmd(priv, HostCmd_CMD_TX_RATE_CFG,
1821 HostCmd_ACT_GEN_SET, 0, bitmap_rates, true);
1822 }
1823
1824 /*
1825 * CFG802.11 operation handler for connection quality monitoring.
1826 *
1827 * This function subscribes/unsubscribes HIGH_RSSI and LOW_RSSI
1828 * events to FW.
1829 */
mwifiex_cfg80211_set_cqm_rssi_config(struct wiphy * wiphy,struct net_device * dev,s32 rssi_thold,u32 rssi_hyst)1830 static int mwifiex_cfg80211_set_cqm_rssi_config(struct wiphy *wiphy,
1831 struct net_device *dev,
1832 s32 rssi_thold, u32 rssi_hyst)
1833 {
1834 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
1835 struct mwifiex_ds_misc_subsc_evt subsc_evt;
1836
1837 priv->cqm_rssi_thold = rssi_thold;
1838 priv->cqm_rssi_hyst = rssi_hyst;
1839
1840 memset(&subsc_evt, 0x00, sizeof(struct mwifiex_ds_misc_subsc_evt));
1841 subsc_evt.events = BITMASK_BCN_RSSI_LOW | BITMASK_BCN_RSSI_HIGH;
1842
1843 /* Subscribe/unsubscribe low and high rssi events */
1844 if (rssi_thold && rssi_hyst) {
1845 subsc_evt.action = HostCmd_ACT_BITWISE_SET;
1846 subsc_evt.bcn_l_rssi_cfg.abs_value = abs(rssi_thold);
1847 subsc_evt.bcn_h_rssi_cfg.abs_value = abs(rssi_thold);
1848 subsc_evt.bcn_l_rssi_cfg.evt_freq = 1;
1849 subsc_evt.bcn_h_rssi_cfg.evt_freq = 1;
1850 return mwifiex_send_cmd(priv,
1851 HostCmd_CMD_802_11_SUBSCRIBE_EVENT,
1852 0, 0, &subsc_evt, true);
1853 } else {
1854 subsc_evt.action = HostCmd_ACT_BITWISE_CLR;
1855 return mwifiex_send_cmd(priv,
1856 HostCmd_CMD_802_11_SUBSCRIBE_EVENT,
1857 0, 0, &subsc_evt, true);
1858 }
1859
1860 return 0;
1861 }
1862
1863 /* cfg80211 operation handler for change_beacon.
1864 * Function retrieves and sets modified management IEs to FW.
1865 */
mwifiex_cfg80211_change_beacon(struct wiphy * wiphy,struct net_device * dev,struct cfg80211_ap_update * params)1866 static int mwifiex_cfg80211_change_beacon(struct wiphy *wiphy,
1867 struct net_device *dev,
1868 struct cfg80211_ap_update *params)
1869 {
1870 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
1871 struct mwifiex_adapter *adapter = priv->adapter;
1872 struct cfg80211_beacon_data *data = ¶ms->beacon;
1873
1874 mwifiex_cancel_scan(adapter);
1875
1876 if (GET_BSS_ROLE(priv) != MWIFIEX_BSS_ROLE_UAP) {
1877 mwifiex_dbg(priv->adapter, ERROR,
1878 "%s: bss_type mismatched\n", __func__);
1879 return -EINVAL;
1880 }
1881
1882 if (!priv->bss_started) {
1883 mwifiex_dbg(priv->adapter, ERROR,
1884 "%s: bss not started\n", __func__);
1885 return -EINVAL;
1886 }
1887
1888 if (mwifiex_set_mgmt_ies(priv, data)) {
1889 mwifiex_dbg(priv->adapter, ERROR,
1890 "%s: setting mgmt ies failed\n", __func__);
1891 return -EFAULT;
1892 }
1893
1894 return 0;
1895 }
1896
1897 /* cfg80211 operation handler for del_station.
1898 * Function deauthenticates station which value is provided in mac parameter.
1899 * If mac is NULL/broadcast, all stations in associated station list are
1900 * deauthenticated. If bss is not started or there are no stations in
1901 * associated stations list, no action is taken.
1902 */
1903 static int
mwifiex_cfg80211_del_station(struct wiphy * wiphy,struct net_device * dev,struct station_del_parameters * params)1904 mwifiex_cfg80211_del_station(struct wiphy *wiphy, struct net_device *dev,
1905 struct station_del_parameters *params)
1906 {
1907 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
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, mac, sinfo, GFP_KERNEL);
3997 kfree(sinfo);
3998 }
3999
4000 return ret;
4001 }
4002
4003 static int
mwifiex_cfg80211_add_station(struct wiphy * wiphy,struct net_device * dev,const u8 * mac,struct station_parameters * params)4004 mwifiex_cfg80211_add_station(struct wiphy *wiphy, struct net_device *dev,
4005 const u8 *mac, struct station_parameters *params)
4006 {
4007 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
4008
4009 if (priv->adapter->host_mlme_enabled &&
4010 (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_UAP))
4011 return mwifiex_cfg80211_uap_add_station(priv, mac, params);
4012
4013 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
4014 return -EOPNOTSUPP;
4015
4016 /* make sure we are in station mode and connected */
4017 if ((priv->bss_type != MWIFIEX_BSS_TYPE_STA) || !priv->media_connected)
4018 return -EOPNOTSUPP;
4019
4020 return mwifiex_tdls_oper(priv, mac, MWIFIEX_TDLS_CREATE_LINK);
4021 }
4022
4023 static int
mwifiex_cfg80211_channel_switch(struct wiphy * wiphy,struct net_device * dev,struct cfg80211_csa_settings * params)4024 mwifiex_cfg80211_channel_switch(struct wiphy *wiphy, struct net_device *dev,
4025 struct cfg80211_csa_settings *params)
4026 {
4027 struct ieee_types_header *chsw_ie;
4028 struct ieee80211_channel_sw_ie *channel_sw;
4029 int chsw_msec;
4030 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
4031
4032 if (priv->adapter->scan_processing) {
4033 mwifiex_dbg(priv->adapter, ERROR,
4034 "radar detection: scan in process...\n");
4035 return -EBUSY;
4036 }
4037
4038 if (priv->wdev.links[0].cac_started)
4039 return -EBUSY;
4040
4041 if (cfg80211_chandef_identical(¶ms->chandef,
4042 &priv->dfs_chandef))
4043 return -EINVAL;
4044
4045 chsw_ie = (void *)cfg80211_find_ie(WLAN_EID_CHANNEL_SWITCH,
4046 params->beacon_csa.tail,
4047 params->beacon_csa.tail_len);
4048 if (!chsw_ie) {
4049 mwifiex_dbg(priv->adapter, ERROR,
4050 "Could not parse channel switch announcement IE\n");
4051 return -EINVAL;
4052 }
4053
4054 channel_sw = (void *)(chsw_ie + 1);
4055 if (channel_sw->mode) {
4056 if (netif_carrier_ok(priv->netdev))
4057 netif_carrier_off(priv->netdev);
4058 mwifiex_stop_net_dev_queue(priv->netdev, priv->adapter);
4059 }
4060
4061 if (mwifiex_del_mgmt_ies(priv))
4062 mwifiex_dbg(priv->adapter, ERROR,
4063 "Failed to delete mgmt IEs!\n");
4064
4065 if (mwifiex_set_mgmt_ies(priv, ¶ms->beacon_csa)) {
4066 mwifiex_dbg(priv->adapter, ERROR,
4067 "%s: setting mgmt ies failed\n", __func__);
4068 return -EFAULT;
4069 }
4070
4071 memcpy(&priv->dfs_chandef, ¶ms->chandef, sizeof(priv->dfs_chandef));
4072 memcpy(&priv->beacon_after, ¶ms->beacon_after,
4073 sizeof(priv->beacon_after));
4074
4075 chsw_msec = max(channel_sw->count * priv->bss_cfg.beacon_period, 100);
4076 queue_delayed_work(priv->dfs_chan_sw_workqueue, &priv->dfs_chan_sw_work,
4077 msecs_to_jiffies(chsw_msec));
4078 return 0;
4079 }
4080
mwifiex_cfg80211_get_channel(struct wiphy * wiphy,struct wireless_dev * wdev,unsigned int link_id,struct cfg80211_chan_def * chandef)4081 static int mwifiex_cfg80211_get_channel(struct wiphy *wiphy,
4082 struct wireless_dev *wdev,
4083 unsigned int link_id,
4084 struct cfg80211_chan_def *chandef)
4085 {
4086 struct mwifiex_private *priv = mwifiex_netdev_get_priv(wdev->netdev);
4087 struct mwifiex_bssdescriptor *curr_bss;
4088 struct ieee80211_channel *chan;
4089 enum nl80211_channel_type chan_type;
4090 enum nl80211_band band;
4091 int freq;
4092 int ret = -ENODATA;
4093
4094 if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_UAP &&
4095 cfg80211_chandef_valid(&priv->bss_chandef)) {
4096 *chandef = priv->bss_chandef;
4097 ret = 0;
4098 } else if (priv->media_connected) {
4099 curr_bss = &priv->curr_bss_params.bss_descriptor;
4100 band = mwifiex_band_to_radio_type(priv->curr_bss_params.band);
4101 freq = ieee80211_channel_to_frequency(curr_bss->channel, band);
4102 chan = ieee80211_get_channel(wiphy, freq);
4103
4104 if (priv->ht_param_present) {
4105 chan_type = mwifiex_get_chan_type(priv);
4106 cfg80211_chandef_create(chandef, chan, chan_type);
4107 } else {
4108 cfg80211_chandef_create(chandef, chan,
4109 NL80211_CHAN_NO_HT);
4110 }
4111 ret = 0;
4112 }
4113
4114 return ret;
4115 }
4116
4117 #ifdef CONFIG_NL80211_TESTMODE
4118
4119 enum mwifiex_tm_attr {
4120 __MWIFIEX_TM_ATTR_INVALID = 0,
4121 MWIFIEX_TM_ATTR_CMD = 1,
4122 MWIFIEX_TM_ATTR_DATA = 2,
4123
4124 /* keep last */
4125 __MWIFIEX_TM_ATTR_AFTER_LAST,
4126 MWIFIEX_TM_ATTR_MAX = __MWIFIEX_TM_ATTR_AFTER_LAST - 1,
4127 };
4128
4129 static const struct nla_policy mwifiex_tm_policy[MWIFIEX_TM_ATTR_MAX + 1] = {
4130 [MWIFIEX_TM_ATTR_CMD] = { .type = NLA_U32 },
4131 [MWIFIEX_TM_ATTR_DATA] = { .type = NLA_BINARY,
4132 .len = MWIFIEX_SIZE_OF_CMD_BUFFER },
4133 };
4134
4135 enum mwifiex_tm_command {
4136 MWIFIEX_TM_CMD_HOSTCMD = 0,
4137 };
4138
mwifiex_tm_cmd(struct wiphy * wiphy,struct wireless_dev * wdev,void * data,int len)4139 static int mwifiex_tm_cmd(struct wiphy *wiphy, struct wireless_dev *wdev,
4140 void *data, int len)
4141 {
4142 struct mwifiex_private *priv = mwifiex_netdev_get_priv(wdev->netdev);
4143 struct mwifiex_ds_misc_cmd *hostcmd;
4144 struct nlattr *tb[MWIFIEX_TM_ATTR_MAX + 1];
4145 struct sk_buff *skb;
4146 int err;
4147
4148 if (!priv)
4149 return -EINVAL;
4150
4151 err = nla_parse_deprecated(tb, MWIFIEX_TM_ATTR_MAX, data, len,
4152 mwifiex_tm_policy, NULL);
4153 if (err)
4154 return err;
4155
4156 if (!tb[MWIFIEX_TM_ATTR_CMD])
4157 return -EINVAL;
4158
4159 switch (nla_get_u32(tb[MWIFIEX_TM_ATTR_CMD])) {
4160 case MWIFIEX_TM_CMD_HOSTCMD:
4161 if (!tb[MWIFIEX_TM_ATTR_DATA])
4162 return -EINVAL;
4163
4164 hostcmd = kzalloc_obj(*hostcmd);
4165 if (!hostcmd)
4166 return -ENOMEM;
4167
4168 hostcmd->len = nla_len(tb[MWIFIEX_TM_ATTR_DATA]);
4169 memcpy(hostcmd->cmd, nla_data(tb[MWIFIEX_TM_ATTR_DATA]),
4170 hostcmd->len);
4171
4172 if (mwifiex_send_cmd(priv, 0, 0, 0, hostcmd, true)) {
4173 dev_err(priv->adapter->dev, "Failed to process hostcmd\n");
4174 kfree(hostcmd);
4175 return -EFAULT;
4176 }
4177
4178 /* process hostcmd response*/
4179 skb = cfg80211_testmode_alloc_reply_skb(wiphy, hostcmd->len);
4180 if (!skb) {
4181 kfree(hostcmd);
4182 return -ENOMEM;
4183 }
4184 err = nla_put(skb, MWIFIEX_TM_ATTR_DATA,
4185 hostcmd->len, hostcmd->cmd);
4186 if (err) {
4187 kfree(hostcmd);
4188 kfree_skb(skb);
4189 return -EMSGSIZE;
4190 }
4191
4192 err = cfg80211_testmode_reply(skb);
4193 kfree(hostcmd);
4194 return err;
4195 default:
4196 return -EOPNOTSUPP;
4197 }
4198 }
4199 #endif
4200
4201 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)4202 mwifiex_cfg80211_start_radar_detection(struct wiphy *wiphy,
4203 struct net_device *dev,
4204 struct cfg80211_chan_def *chandef,
4205 u32 cac_time_ms, int link_id)
4206 {
4207 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
4208 struct mwifiex_radar_params radar_params;
4209
4210 if (priv->adapter->scan_processing) {
4211 mwifiex_dbg(priv->adapter, ERROR,
4212 "radar detection: scan already in process...\n");
4213 return -EBUSY;
4214 }
4215
4216 if (!mwifiex_is_11h_active(priv)) {
4217 mwifiex_dbg(priv->adapter, INFO,
4218 "Enable 11h extensions in FW\n");
4219 if (mwifiex_11h_activate(priv, true)) {
4220 mwifiex_dbg(priv->adapter, ERROR,
4221 "Failed to activate 11h extensions!!");
4222 return -1;
4223 }
4224 priv->state_11h.is_11h_active = true;
4225 }
4226
4227 memset(&radar_params, 0, sizeof(struct mwifiex_radar_params));
4228 radar_params.chandef = chandef;
4229 radar_params.cac_time_ms = cac_time_ms;
4230
4231 memcpy(&priv->dfs_chandef, chandef, sizeof(priv->dfs_chandef));
4232
4233 if (mwifiex_send_cmd(priv, HostCmd_CMD_CHAN_REPORT_REQUEST,
4234 HostCmd_ACT_GEN_SET, 0, &radar_params, true))
4235 return -1;
4236
4237 queue_delayed_work(priv->dfs_cac_workqueue, &priv->dfs_cac_work,
4238 msecs_to_jiffies(cac_time_ms));
4239 return 0;
4240 }
4241
4242 static int
mwifiex_cfg80211_change_station(struct wiphy * wiphy,struct net_device * dev,const u8 * mac,struct station_parameters * params)4243 mwifiex_cfg80211_change_station(struct wiphy *wiphy, struct net_device *dev,
4244 const u8 *mac,
4245 struct station_parameters *params)
4246 {
4247 int ret;
4248 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
4249
4250 if (priv->adapter->host_mlme_enabled &&
4251 (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_UAP))
4252 return 0;
4253
4254 /* we support change_station handler only for TDLS peers*/
4255 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
4256 return -EOPNOTSUPP;
4257
4258 /* make sure we are in station mode and connected */
4259 if ((priv->bss_type != MWIFIEX_BSS_TYPE_STA) || !priv->media_connected)
4260 return -EOPNOTSUPP;
4261
4262 priv->sta_params = params;
4263
4264 ret = mwifiex_tdls_oper(priv, mac, MWIFIEX_TDLS_CONFIG_LINK);
4265 priv->sta_params = NULL;
4266
4267 return ret;
4268 }
4269
4270 static int
mwifiex_cfg80211_authenticate(struct wiphy * wiphy,struct net_device * dev,struct cfg80211_auth_request * req)4271 mwifiex_cfg80211_authenticate(struct wiphy *wiphy,
4272 struct net_device *dev,
4273 struct cfg80211_auth_request *req)
4274 {
4275 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
4276 struct mwifiex_adapter *adapter = priv->adapter;
4277 struct sk_buff *skb;
4278 u16 pkt_len, auth_alg;
4279 int ret;
4280 struct mwifiex_ieee80211_mgmt *mgmt;
4281 struct mwifiex_txinfo *tx_info;
4282 u32 tx_control = 0, pkt_type = PKT_TYPE_MGMT;
4283 u8 trans = 1, status_code = 0;
4284 u8 *varptr = NULL;
4285
4286 if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_UAP) {
4287 mwifiex_dbg(priv->adapter, ERROR, "Interface role is AP\n");
4288 return -EFAULT;
4289 }
4290
4291 if (priv->wdev.iftype != NL80211_IFTYPE_STATION) {
4292 mwifiex_dbg(priv->adapter, ERROR,
4293 "Interface type is not correct (type %d)\n",
4294 priv->wdev.iftype);
4295 return -EINVAL;
4296 }
4297
4298 if (priv->auth_alg != WLAN_AUTH_SAE &&
4299 (priv->auth_flag & HOST_MLME_AUTH_PENDING)) {
4300 mwifiex_dbg(priv->adapter, ERROR, "Pending auth on going\n");
4301 return -EBUSY;
4302 }
4303
4304 if (!priv->host_mlme_reg) {
4305 priv->host_mlme_reg = true;
4306 priv->mgmt_frame_mask |= HOST_MLME_MGMT_MASK;
4307 mwifiex_send_cmd(priv, HostCmd_CMD_MGMT_FRAME_REG,
4308 HostCmd_ACT_GEN_SET, 0,
4309 &priv->mgmt_frame_mask, false);
4310 }
4311
4312 switch (req->auth_type) {
4313 case NL80211_AUTHTYPE_OPEN_SYSTEM:
4314 auth_alg = WLAN_AUTH_OPEN;
4315 break;
4316 case NL80211_AUTHTYPE_SHARED_KEY:
4317 auth_alg = WLAN_AUTH_SHARED_KEY;
4318 break;
4319 case NL80211_AUTHTYPE_FT:
4320 auth_alg = WLAN_AUTH_FT;
4321 break;
4322 case NL80211_AUTHTYPE_NETWORK_EAP:
4323 auth_alg = WLAN_AUTH_LEAP;
4324 break;
4325 case NL80211_AUTHTYPE_SAE:
4326 auth_alg = WLAN_AUTH_SAE;
4327 break;
4328 default:
4329 mwifiex_dbg(priv->adapter, ERROR,
4330 "unsupported auth type=%d\n", req->auth_type);
4331 return -EOPNOTSUPP;
4332 }
4333
4334 if (!priv->auth_flag) {
4335 ret = mwifiex_remain_on_chan_cfg(priv, HostCmd_ACT_GEN_SET,
4336 req->bss->channel,
4337 AUTH_TX_DEFAULT_WAIT_TIME);
4338
4339 if (!ret) {
4340 priv->roc_cfg.cookie = get_random_u32() | 1;
4341 priv->roc_cfg.chan = *req->bss->channel;
4342 } else {
4343 return -EFAULT;
4344 }
4345 }
4346
4347 priv->sec_info.authentication_mode = auth_alg;
4348
4349 mwifiex_cancel_scan(adapter);
4350
4351 pkt_len = (u16)req->ie_len + req->auth_data_len +
4352 MWIFIEX_MGMT_HEADER_LEN + MWIFIEX_AUTH_BODY_LEN;
4353 if (req->auth_data_len >= 4)
4354 pkt_len -= 4;
4355
4356 skb = dev_alloc_skb(MWIFIEX_MIN_DATA_HEADER_LEN +
4357 MWIFIEX_MGMT_FRAME_HEADER_SIZE +
4358 pkt_len + sizeof(pkt_len));
4359 if (!skb) {
4360 mwifiex_dbg(priv->adapter, ERROR,
4361 "allocate skb failed for management frame\n");
4362 return -ENOMEM;
4363 }
4364
4365 tx_info = MWIFIEX_SKB_TXCB(skb);
4366 memset(tx_info, 0, sizeof(*tx_info));
4367 tx_info->bss_num = priv->bss_num;
4368 tx_info->bss_type = priv->bss_type;
4369 tx_info->pkt_len = pkt_len;
4370
4371 skb_reserve(skb, MWIFIEX_MIN_DATA_HEADER_LEN +
4372 MWIFIEX_MGMT_FRAME_HEADER_SIZE + sizeof(pkt_len));
4373 memcpy(skb_push(skb, sizeof(pkt_len)), &pkt_len, sizeof(pkt_len));
4374 memcpy(skb_push(skb, sizeof(tx_control)),
4375 &tx_control, sizeof(tx_control));
4376 memcpy(skb_push(skb, sizeof(pkt_type)), &pkt_type, sizeof(pkt_type));
4377
4378 mgmt = (struct mwifiex_ieee80211_mgmt *)skb_put(skb, pkt_len);
4379 memset(mgmt, 0, pkt_len);
4380 mgmt->frame_control =
4381 cpu_to_le16(IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_AUTH);
4382 memcpy(mgmt->da, req->bss->bssid, ETH_ALEN);
4383 memcpy(mgmt->sa, priv->curr_addr, ETH_ALEN);
4384 memcpy(mgmt->bssid, req->bss->bssid, ETH_ALEN);
4385 eth_broadcast_addr(mgmt->addr4);
4386
4387 if (req->auth_data_len >= 4) {
4388 if (req->auth_type == NL80211_AUTHTYPE_SAE) {
4389 __le16 *pos = (__le16 *)req->auth_data;
4390
4391 trans = le16_to_cpu(pos[0]);
4392 status_code = le16_to_cpu(pos[1]);
4393 }
4394 memcpy((u8 *)(&mgmt->auth.variable), req->auth_data + 4,
4395 req->auth_data_len - 4);
4396 varptr = (u8 *)&mgmt->auth.variable +
4397 (req->auth_data_len - 4);
4398 }
4399
4400 mgmt->auth.auth_alg = cpu_to_le16(auth_alg);
4401 mgmt->auth.auth_transaction = cpu_to_le16(trans);
4402 mgmt->auth.status_code = cpu_to_le16(status_code);
4403
4404 if (req->ie && req->ie_len) {
4405 if (!varptr)
4406 varptr = (u8 *)&mgmt->auth.variable;
4407 memcpy((u8 *)varptr, req->ie, req->ie_len);
4408 }
4409
4410 priv->auth_flag = HOST_MLME_AUTH_PENDING;
4411 priv->auth_alg = auth_alg;
4412
4413 skb->priority = WMM_HIGHEST_PRIORITY;
4414 __net_timestamp(skb);
4415
4416 mwifiex_dbg(priv->adapter, MSG,
4417 "auth: send authentication to %pM\n", req->bss->bssid);
4418
4419 mwifiex_queue_tx_pkt(priv, skb);
4420
4421 return 0;
4422 }
4423
4424 static int
mwifiex_cfg80211_associate(struct wiphy * wiphy,struct net_device * dev,struct cfg80211_assoc_request * req)4425 mwifiex_cfg80211_associate(struct wiphy *wiphy, struct net_device *dev,
4426 struct cfg80211_assoc_request *req)
4427 {
4428 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
4429 struct mwifiex_adapter *adapter = priv->adapter;
4430 int ret;
4431 struct cfg80211_ssid req_ssid;
4432 const u8 *ssid_ie;
4433
4434 if (GET_BSS_ROLE(priv) != MWIFIEX_BSS_ROLE_STA) {
4435 mwifiex_dbg(adapter, ERROR,
4436 "%s: reject infra assoc request in non-STA role\n",
4437 dev->name);
4438 return -EINVAL;
4439 }
4440
4441 if (test_bit(MWIFIEX_SURPRISE_REMOVED, &adapter->work_flags) ||
4442 test_bit(MWIFIEX_IS_CMD_TIMEDOUT, &adapter->work_flags)) {
4443 mwifiex_dbg(adapter, ERROR,
4444 "%s: Ignore association.\t"
4445 "Card removed or FW in bad state\n",
4446 dev->name);
4447 return -EFAULT;
4448 }
4449
4450 if (priv->auth_alg == WLAN_AUTH_SAE)
4451 priv->auth_flag = HOST_MLME_AUTH_DONE;
4452
4453 if (priv->auth_flag && !(priv->auth_flag & HOST_MLME_AUTH_DONE))
4454 return -EBUSY;
4455
4456 if (priv->roc_cfg.cookie) {
4457 ret = mwifiex_remain_on_chan_cfg(priv, HostCmd_ACT_GEN_REMOVE,
4458 &priv->roc_cfg.chan, 0);
4459 if (!ret)
4460 memset(&priv->roc_cfg, 0,
4461 sizeof(struct mwifiex_roc_cfg));
4462 else
4463 return -EFAULT;
4464 }
4465
4466 if (!mwifiex_stop_bg_scan(priv))
4467 cfg80211_sched_scan_stopped_locked(priv->wdev.wiphy, 0);
4468
4469 memset(&req_ssid, 0, sizeof(struct cfg80211_ssid));
4470 rcu_read_lock();
4471 ssid_ie = ieee80211_bss_get_ie(req->bss, WLAN_EID_SSID);
4472
4473 if (!ssid_ie)
4474 goto ssid_err;
4475
4476 req_ssid.ssid_len = ssid_ie[1];
4477 if (req_ssid.ssid_len > IEEE80211_MAX_SSID_LEN) {
4478 mwifiex_dbg(adapter, ERROR, "invalid SSID - aborting\n");
4479 goto ssid_err;
4480 }
4481
4482 memcpy(req_ssid.ssid, ssid_ie + 2, req_ssid.ssid_len);
4483 if (!req_ssid.ssid_len || req_ssid.ssid[0] < 0x20) {
4484 mwifiex_dbg(adapter, ERROR, "invalid SSID - aborting\n");
4485 goto ssid_err;
4486 }
4487 rcu_read_unlock();
4488
4489 /* As this is new association, clear locally stored
4490 * keys and security related flags
4491 */
4492 priv->sec_info.wpa_enabled = false;
4493 priv->sec_info.wpa2_enabled = false;
4494 priv->wep_key_curr_index = 0;
4495 priv->sec_info.encryption_mode = 0;
4496 priv->sec_info.is_authtype_auto = 0;
4497 if (mwifiex_set_encode(priv, NULL, NULL, 0, 0, NULL, 1)) {
4498 mwifiex_dbg(priv->adapter, ERROR, "deleting the crypto keys\n");
4499 return -EFAULT;
4500 }
4501
4502 if (req->crypto.n_ciphers_pairwise)
4503 priv->sec_info.encryption_mode =
4504 req->crypto.ciphers_pairwise[0];
4505
4506 if (req->crypto.cipher_group)
4507 priv->sec_info.encryption_mode = req->crypto.cipher_group;
4508
4509 if (req->ie)
4510 mwifiex_set_gen_ie(priv, req->ie, req->ie_len);
4511
4512 memcpy(priv->cfg_bssid, req->bss->bssid, ETH_ALEN);
4513
4514 mwifiex_dbg(adapter, MSG,
4515 "assoc: send association to %pM\n", req->bss->bssid);
4516
4517 cfg80211_ref_bss(adapter->wiphy, req->bss);
4518 ret = mwifiex_bss_start(priv, req->bss, &req_ssid);
4519 if (ret) {
4520 priv->auth_flag = 0;
4521 priv->auth_alg = WLAN_AUTH_NONE;
4522 eth_zero_addr(priv->cfg_bssid);
4523 }
4524
4525 if (priv->assoc_rsp_size) {
4526 priv->req_bss = req->bss;
4527 adapter->assoc_resp_received = true;
4528 queue_work(adapter->host_mlme_workqueue,
4529 &adapter->host_mlme_work);
4530 }
4531
4532 cfg80211_put_bss(priv->adapter->wiphy, req->bss);
4533
4534 return 0;
4535
4536 ssid_err:
4537 rcu_read_unlock();
4538 return -EFAULT;
4539 }
4540
4541 static int
mwifiex_cfg80211_deauthenticate(struct wiphy * wiphy,struct net_device * dev,struct cfg80211_deauth_request * req)4542 mwifiex_cfg80211_deauthenticate(struct wiphy *wiphy,
4543 struct net_device *dev,
4544 struct cfg80211_deauth_request *req)
4545 {
4546 return mwifiex_cfg80211_disconnect(wiphy, dev, req->reason_code);
4547 }
4548
4549 static int
mwifiex_cfg80211_disassociate(struct wiphy * wiphy,struct net_device * dev,struct cfg80211_disassoc_request * req)4550 mwifiex_cfg80211_disassociate(struct wiphy *wiphy,
4551 struct net_device *dev,
4552 struct cfg80211_disassoc_request *req)
4553 {
4554 return mwifiex_cfg80211_disconnect(wiphy, dev, req->reason_code);
4555 }
4556
4557 static int
mwifiex_cfg80211_probe_client(struct wiphy * wiphy,struct net_device * dev,const u8 * peer,u64 * cookie)4558 mwifiex_cfg80211_probe_client(struct wiphy *wiphy,
4559 struct net_device *dev, const u8 *peer,
4560 u64 *cookie)
4561 {
4562 /* hostapd looks for NL80211_CMD_PROBE_CLIENT support; otherwise,
4563 * it requires monitor-mode support (which mwifiex doesn't support).
4564 * Provide fake probe_client support to work around this.
4565 */
4566 return -EOPNOTSUPP;
4567 }
4568
4569 /* station cfg80211 operations */
4570 static const struct cfg80211_ops mwifiex_cfg80211_ops = {
4571 .add_virtual_intf = mwifiex_add_virtual_intf,
4572 .del_virtual_intf = mwifiex_del_virtual_intf,
4573 .change_virtual_intf = mwifiex_cfg80211_change_virtual_intf,
4574 .scan = mwifiex_cfg80211_scan,
4575 .connect = mwifiex_cfg80211_connect,
4576 .disconnect = mwifiex_cfg80211_disconnect,
4577 .get_station = mwifiex_cfg80211_get_station,
4578 .dump_station = mwifiex_cfg80211_dump_station,
4579 .dump_survey = mwifiex_cfg80211_dump_survey,
4580 .set_wiphy_params = mwifiex_cfg80211_set_wiphy_params,
4581 .join_ibss = mwifiex_cfg80211_join_ibss,
4582 .leave_ibss = mwifiex_cfg80211_leave_ibss,
4583 .add_key = mwifiex_cfg80211_add_key,
4584 .del_key = mwifiex_cfg80211_del_key,
4585 .set_default_mgmt_key = mwifiex_cfg80211_set_default_mgmt_key,
4586 .mgmt_tx = mwifiex_cfg80211_mgmt_tx,
4587 .update_mgmt_frame_registrations =
4588 mwifiex_cfg80211_update_mgmt_frame_registrations,
4589 .remain_on_channel = mwifiex_cfg80211_remain_on_channel,
4590 .cancel_remain_on_channel = mwifiex_cfg80211_cancel_remain_on_channel,
4591 .set_default_key = mwifiex_cfg80211_set_default_key,
4592 .set_power_mgmt = mwifiex_cfg80211_set_power_mgmt,
4593 .set_tx_power = mwifiex_cfg80211_set_tx_power,
4594 .get_tx_power = mwifiex_cfg80211_get_tx_power,
4595 .set_bitrate_mask = mwifiex_cfg80211_set_bitrate_mask,
4596 .start_ap = mwifiex_cfg80211_start_ap,
4597 .stop_ap = mwifiex_cfg80211_stop_ap,
4598 .change_beacon = mwifiex_cfg80211_change_beacon,
4599 .set_cqm_rssi_config = mwifiex_cfg80211_set_cqm_rssi_config,
4600 .set_antenna = mwifiex_cfg80211_set_antenna,
4601 .get_antenna = mwifiex_cfg80211_get_antenna,
4602 .del_station = mwifiex_cfg80211_del_station,
4603 .sched_scan_start = mwifiex_cfg80211_sched_scan_start,
4604 .sched_scan_stop = mwifiex_cfg80211_sched_scan_stop,
4605 #ifdef CONFIG_PM
4606 .suspend = mwifiex_cfg80211_suspend,
4607 .resume = mwifiex_cfg80211_resume,
4608 .set_wakeup = mwifiex_cfg80211_set_wakeup,
4609 .set_rekey_data = mwifiex_set_rekey_data,
4610 #endif
4611 .set_coalesce = mwifiex_cfg80211_set_coalesce,
4612 .tdls_mgmt = mwifiex_cfg80211_tdls_mgmt,
4613 .tdls_oper = mwifiex_cfg80211_tdls_oper,
4614 .tdls_channel_switch = mwifiex_cfg80211_tdls_chan_switch,
4615 .tdls_cancel_channel_switch = mwifiex_cfg80211_tdls_cancel_chan_switch,
4616 .add_station = mwifiex_cfg80211_add_station,
4617 .change_station = mwifiex_cfg80211_change_station,
4618 CFG80211_TESTMODE_CMD(mwifiex_tm_cmd)
4619 .get_channel = mwifiex_cfg80211_get_channel,
4620 .start_radar_detection = mwifiex_cfg80211_start_radar_detection,
4621 .channel_switch = mwifiex_cfg80211_channel_switch,
4622 };
4623
4624 #ifdef CONFIG_PM
4625 static const struct wiphy_wowlan_support mwifiex_wowlan_support = {
4626 .flags = WIPHY_WOWLAN_MAGIC_PKT | WIPHY_WOWLAN_DISCONNECT |
4627 WIPHY_WOWLAN_NET_DETECT | WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
4628 WIPHY_WOWLAN_GTK_REKEY_FAILURE,
4629 .n_patterns = MWIFIEX_MEF_MAX_FILTERS,
4630 .pattern_min_len = 1,
4631 .pattern_max_len = MWIFIEX_MAX_PATTERN_LEN,
4632 .max_pkt_offset = MWIFIEX_MAX_OFFSET_LEN,
4633 .max_nd_match_sets = MWIFIEX_MAX_ND_MATCH_SETS,
4634 };
4635
4636 static const struct wiphy_wowlan_support mwifiex_wowlan_support_no_gtk = {
4637 .flags = WIPHY_WOWLAN_MAGIC_PKT | WIPHY_WOWLAN_DISCONNECT |
4638 WIPHY_WOWLAN_NET_DETECT,
4639 .n_patterns = MWIFIEX_MEF_MAX_FILTERS,
4640 .pattern_min_len = 1,
4641 .pattern_max_len = MWIFIEX_MAX_PATTERN_LEN,
4642 .max_pkt_offset = MWIFIEX_MAX_OFFSET_LEN,
4643 .max_nd_match_sets = MWIFIEX_MAX_ND_MATCH_SETS,
4644 };
4645 #endif
4646
mwifiex_is_valid_alpha2(const char * alpha2)4647 static bool mwifiex_is_valid_alpha2(const char *alpha2)
4648 {
4649 if (!alpha2 || strlen(alpha2) != 2)
4650 return false;
4651
4652 if (isalpha(alpha2[0]) && isalpha(alpha2[1]))
4653 return true;
4654
4655 return false;
4656 }
4657
4658 static const struct wiphy_coalesce_support mwifiex_coalesce_support = {
4659 .n_rules = MWIFIEX_COALESCE_MAX_RULES,
4660 .max_delay = MWIFIEX_MAX_COALESCING_DELAY,
4661 .n_patterns = MWIFIEX_COALESCE_MAX_FILTERS,
4662 .pattern_min_len = 1,
4663 .pattern_max_len = MWIFIEX_MAX_PATTERN_LEN,
4664 .max_pkt_offset = MWIFIEX_MAX_OFFSET_LEN,
4665 };
4666
mwifiex_init_channel_scan_gap(struct mwifiex_adapter * adapter)4667 int mwifiex_init_channel_scan_gap(struct mwifiex_adapter *adapter)
4668 {
4669 u32 n_channels_bg, n_channels_a = 0;
4670
4671 n_channels_bg = mwifiex_band_2ghz.n_channels;
4672
4673 if (adapter->config_bands & BAND_A)
4674 n_channels_a = mwifiex_band_5ghz.n_channels;
4675
4676 /* allocate twice the number total channels, since the driver issues an
4677 * additional active scan request for hidden SSIDs on passive channels.
4678 */
4679 adapter->num_in_chan_stats = 2 * (n_channels_bg + n_channels_a);
4680 adapter->chan_stats = kzalloc_objs(*adapter->chan_stats,
4681 adapter->num_in_chan_stats);
4682
4683 if (!adapter->chan_stats)
4684 return -ENOMEM;
4685
4686 return 0;
4687 }
4688
4689 /*
4690 * This function registers the device with CFG802.11 subsystem.
4691 *
4692 * The function creates the wireless device/wiphy, populates it with
4693 * default parameters and handler function pointers, and finally
4694 * registers the device.
4695 */
4696
mwifiex_register_cfg80211(struct mwifiex_adapter * adapter)4697 int mwifiex_register_cfg80211(struct mwifiex_adapter *adapter)
4698 {
4699 int ret;
4700 void *wdev_priv;
4701 struct wiphy *wiphy;
4702 struct mwifiex_private *priv = adapter->priv[MWIFIEX_BSS_TYPE_STA];
4703 const u8 *country_code;
4704 u32 thr, retry;
4705 struct cfg80211_ops *ops;
4706
4707 ops = devm_kmemdup(adapter->dev, &mwifiex_cfg80211_ops,
4708 sizeof(mwifiex_cfg80211_ops), GFP_KERNEL);
4709 if (!ops)
4710 return -ENOMEM;
4711
4712 /* create a new wiphy for use with cfg80211 */
4713 wiphy = wiphy_new(ops, sizeof(struct mwifiex_adapter *));
4714 if (!wiphy) {
4715 mwifiex_dbg(adapter, ERROR,
4716 "%s: creating new wiphy\n", __func__);
4717 return -ENOMEM;
4718 }
4719 if (adapter->host_mlme_enabled) {
4720 ops->auth = mwifiex_cfg80211_authenticate;
4721 ops->assoc = mwifiex_cfg80211_associate;
4722 ops->deauth = mwifiex_cfg80211_deauthenticate;
4723 ops->disassoc = mwifiex_cfg80211_disassociate;
4724 ops->disconnect = NULL;
4725 ops->connect = NULL;
4726 ops->probe_client = mwifiex_cfg80211_probe_client;
4727 }
4728 wiphy->max_scan_ssids = MWIFIEX_MAX_SSID_LIST_LENGTH;
4729 wiphy->max_scan_ie_len = MWIFIEX_MAX_VSIE_LEN;
4730 if (adapter->host_mlme_enabled) {
4731 memcpy(adapter->mwifiex_mgmt_stypes,
4732 mwifiex_mgmt_stypes,
4733 NUM_NL80211_IFTYPES *
4734 sizeof(struct ieee80211_txrx_stypes));
4735
4736 adapter->mwifiex_mgmt_stypes[NL80211_IFTYPE_AP].tx = 0xffff;
4737 adapter->mwifiex_mgmt_stypes[NL80211_IFTYPE_AP].rx =
4738 BIT(IEEE80211_STYPE_ASSOC_REQ >> 4) |
4739 BIT(IEEE80211_STYPE_REASSOC_REQ >> 4) |
4740 BIT(IEEE80211_STYPE_PROBE_REQ >> 4) |
4741 BIT(IEEE80211_STYPE_DISASSOC >> 4) |
4742 BIT(IEEE80211_STYPE_AUTH >> 4) |
4743 BIT(IEEE80211_STYPE_DEAUTH >> 4) |
4744 BIT(IEEE80211_STYPE_ACTION >> 4);
4745 wiphy->mgmt_stypes = adapter->mwifiex_mgmt_stypes;
4746 } else {
4747 wiphy->mgmt_stypes = mwifiex_mgmt_stypes;
4748 }
4749 wiphy->max_remain_on_channel_duration = 5000;
4750 wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
4751 BIT(NL80211_IFTYPE_P2P_CLIENT) |
4752 BIT(NL80211_IFTYPE_P2P_GO) |
4753 BIT(NL80211_IFTYPE_AP);
4754
4755 wiphy->max_num_akm_suites = CFG80211_MAX_NUM_AKM_SUITES;
4756
4757 if (ISSUPP_ADHOC_ENABLED(adapter->fw_cap_info))
4758 wiphy->interface_modes |= BIT(NL80211_IFTYPE_ADHOC);
4759
4760 wiphy->bands[NL80211_BAND_2GHZ] = devm_kmemdup(adapter->dev,
4761 &mwifiex_band_2ghz,
4762 sizeof(mwifiex_band_2ghz),
4763 GFP_KERNEL);
4764 if (!wiphy->bands[NL80211_BAND_2GHZ]) {
4765 ret = -ENOMEM;
4766 goto err;
4767 }
4768
4769 if (adapter->config_bands & BAND_A) {
4770 wiphy->bands[NL80211_BAND_5GHZ] = devm_kmemdup(adapter->dev,
4771 &mwifiex_band_5ghz,
4772 sizeof(mwifiex_band_5ghz),
4773 GFP_KERNEL);
4774 if (!wiphy->bands[NL80211_BAND_5GHZ]) {
4775 ret = -ENOMEM;
4776 goto err;
4777 }
4778 } else {
4779 wiphy->bands[NL80211_BAND_5GHZ] = NULL;
4780 }
4781
4782 if (adapter->drcs_enabled && ISSUPP_DRCS_ENABLED(adapter->fw_cap_info))
4783 wiphy->iface_combinations = &mwifiex_iface_comb_ap_sta_drcs;
4784 else if (adapter->is_hw_11ac_capable)
4785 wiphy->iface_combinations = &mwifiex_iface_comb_ap_sta_vht;
4786 else
4787 wiphy->iface_combinations = &mwifiex_iface_comb_ap_sta;
4788 wiphy->n_iface_combinations = 1;
4789
4790 wiphy->max_ap_assoc_sta = max_t(typeof(wiphy->max_ap_assoc_sta),
4791 adapter->max_sta_conn,
4792 adapter->max_p2p_conn);
4793
4794 /* Initialize cipher suits */
4795 wiphy->cipher_suites = mwifiex_cipher_suites;
4796 wiphy->n_cipher_suites = ARRAY_SIZE(mwifiex_cipher_suites);
4797
4798 if (adapter->regd) {
4799 wiphy->regulatory_flags |= REGULATORY_CUSTOM_REG |
4800 REGULATORY_DISABLE_BEACON_HINTS |
4801 REGULATORY_COUNTRY_IE_IGNORE;
4802 wiphy_apply_custom_regulatory(wiphy, adapter->regd);
4803 }
4804
4805 ether_addr_copy(wiphy->perm_addr, adapter->perm_addr);
4806 wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
4807 wiphy->flags |= WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD |
4808 WIPHY_FLAG_AP_UAPSD |
4809 WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL |
4810 WIPHY_FLAG_HAS_CHANNEL_SWITCH |
4811 WIPHY_FLAG_NETNS_OK |
4812 WIPHY_FLAG_PS_ON_BY_DEFAULT;
4813
4814 if (adapter->host_mlme_enabled)
4815 wiphy->flags |= WIPHY_FLAG_REPORTS_OBSS;
4816 else
4817 wiphy->flags |= WIPHY_FLAG_HAVE_AP_SME;
4818
4819 if (ISSUPP_TDLS_ENABLED(adapter->fw_cap_info))
4820 wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS |
4821 WIPHY_FLAG_TDLS_EXTERNAL_SETUP;
4822
4823 #ifdef CONFIG_PM
4824 if (ISSUPP_FIRMWARE_SUPPLICANT(priv->adapter->fw_cap_info))
4825 wiphy->wowlan = &mwifiex_wowlan_support;
4826 else
4827 wiphy->wowlan = &mwifiex_wowlan_support_no_gtk;
4828 #endif
4829
4830 wiphy->coalesce = &mwifiex_coalesce_support;
4831
4832 wiphy->probe_resp_offload = NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS |
4833 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2 |
4834 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P;
4835
4836 wiphy->max_sched_scan_reqs = 1;
4837 wiphy->max_sched_scan_ssids = MWIFIEX_MAX_SSID_LIST_LENGTH;
4838 wiphy->max_sched_scan_ie_len = MWIFIEX_MAX_VSIE_LEN;
4839 wiphy->max_match_sets = MWIFIEX_MAX_SSID_LIST_LENGTH;
4840
4841 wiphy->available_antennas_tx = BIT(adapter->number_of_antenna) - 1;
4842 wiphy->available_antennas_rx = BIT(adapter->number_of_antenna) - 1;
4843
4844 wiphy->features |= NL80211_FEATURE_INACTIVITY_TIMER |
4845 NL80211_FEATURE_LOW_PRIORITY_SCAN |
4846 NL80211_FEATURE_NEED_OBSS_SCAN;
4847
4848 if (adapter->host_mlme_enabled)
4849 wiphy->features |= NL80211_FEATURE_SAE;
4850
4851 if (ISSUPP_ADHOC_ENABLED(adapter->fw_cap_info))
4852 wiphy->features |= NL80211_FEATURE_HT_IBSS;
4853
4854 if (ISSUPP_RANDOM_MAC(adapter->fw_cap_info))
4855 wiphy->features |= NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR |
4856 NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR |
4857 NL80211_FEATURE_ND_RANDOM_MAC_ADDR;
4858
4859 if (ISSUPP_TDLS_ENABLED(adapter->fw_cap_info))
4860 wiphy->features |= NL80211_FEATURE_TDLS_CHANNEL_SWITCH;
4861
4862 if (adapter->fw_api_ver == MWIFIEX_FW_V15)
4863 wiphy->features |= NL80211_FEATURE_SK_TX_STATUS;
4864
4865 /* Reserve space for mwifiex specific private data for BSS */
4866 wiphy->bss_priv_size = sizeof(struct mwifiex_bss_priv);
4867
4868 wiphy->reg_notifier = mwifiex_reg_notifier;
4869
4870 /* Set struct mwifiex_adapter pointer in wiphy_priv */
4871 wdev_priv = wiphy_priv(wiphy);
4872 *(unsigned long *)wdev_priv = (unsigned long)adapter;
4873
4874 set_wiphy_dev(wiphy, priv->adapter->dev);
4875
4876 ret = wiphy_register(wiphy);
4877 if (ret < 0) {
4878 mwifiex_dbg(adapter, ERROR,
4879 "%s: wiphy_register failed: %d\n", __func__, ret);
4880 goto err;
4881 }
4882
4883 if (!adapter->regd) {
4884 if (reg_alpha2 && mwifiex_is_valid_alpha2(reg_alpha2)) {
4885 mwifiex_dbg(adapter, INFO,
4886 "driver hint alpha2: %2.2s\n", reg_alpha2);
4887 regulatory_hint(wiphy, reg_alpha2);
4888 } else {
4889 if (adapter->region_code == 0x00) {
4890 mwifiex_dbg(adapter, WARN,
4891 "Ignore world regulatory domain\n");
4892 } else {
4893 wiphy->regulatory_flags |=
4894 REGULATORY_DISABLE_BEACON_HINTS |
4895 REGULATORY_COUNTRY_IE_IGNORE;
4896 country_code =
4897 mwifiex_11d_code_2_region(
4898 adapter->region_code);
4899 if (country_code &&
4900 regulatory_hint(wiphy, country_code))
4901 mwifiex_dbg(priv->adapter, ERROR,
4902 "regulatory_hint() failed\n");
4903 }
4904 }
4905 }
4906
4907 mwifiex_send_cmd(priv, HostCmd_CMD_802_11_SNMP_MIB,
4908 HostCmd_ACT_GEN_GET, FRAG_THRESH_I, &thr, true);
4909 wiphy->frag_threshold = thr;
4910 mwifiex_send_cmd(priv, HostCmd_CMD_802_11_SNMP_MIB,
4911 HostCmd_ACT_GEN_GET, RTS_THRESH_I, &thr, true);
4912 wiphy->rts_threshold = thr;
4913 mwifiex_send_cmd(priv, HostCmd_CMD_802_11_SNMP_MIB,
4914 HostCmd_ACT_GEN_GET, SHORT_RETRY_LIM_I, &retry, true);
4915 wiphy->retry_short = (u8) retry;
4916 mwifiex_send_cmd(priv, HostCmd_CMD_802_11_SNMP_MIB,
4917 HostCmd_ACT_GEN_GET, LONG_RETRY_LIM_I, &retry, true);
4918 wiphy->retry_long = (u8) retry;
4919
4920 adapter->wiphy = wiphy;
4921 return ret;
4922
4923 err:
4924 wiphy_free(wiphy);
4925
4926 return ret;
4927 }
4928