1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * nxpwifi: cfg80211 support
4 *
5 * Copyright 2011-2024 NXP
6 */
7
8 #include "cfg80211.h"
9 #include "main.h"
10 #include "cmdevt.h"
11 #include "11n.h"
12 #include "wmm.h"
13
14 static const struct ieee80211_iface_limit nxpwifi_ap_sta_limits[] = {
15 {
16 .max = NXPWIFI_MAX_BSS_NUM,
17 .types = BIT(NL80211_IFTYPE_STATION) |
18 BIT(NL80211_IFTYPE_AP) |
19 BIT(NL80211_IFTYPE_MONITOR),
20 },
21 };
22
23 static const struct ieee80211_iface_combination
24 nxpwifi_iface_comb_ap_sta = {
25 .limits = nxpwifi_ap_sta_limits,
26 .num_different_channels = 1,
27 .n_limits = ARRAY_SIZE(nxpwifi_ap_sta_limits),
28 .max_interfaces = NXPWIFI_MAX_BSS_NUM,
29 .beacon_int_infra_match = true,
30 .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
31 BIT(NL80211_CHAN_WIDTH_20) |
32 BIT(NL80211_CHAN_WIDTH_40),
33 };
34
35 static const struct ieee80211_iface_combination
36 nxpwifi_iface_comb_ap_sta_vht = {
37 .limits = nxpwifi_ap_sta_limits,
38 .num_different_channels = 1,
39 .n_limits = ARRAY_SIZE(nxpwifi_ap_sta_limits),
40 .max_interfaces = NXPWIFI_MAX_BSS_NUM,
41 .beacon_int_infra_match = true,
42 .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
43 BIT(NL80211_CHAN_WIDTH_20) |
44 BIT(NL80211_CHAN_WIDTH_40) |
45 BIT(NL80211_CHAN_WIDTH_80),
46 };
47
48 /* Map nl80211 channel types to secondary channel offsets */
nxpwifi_chan_type_to_sec_chan_offset(enum nl80211_channel_type chan_type)49 u8 nxpwifi_chan_type_to_sec_chan_offset(enum nl80211_channel_type chan_type)
50 {
51 switch (chan_type) {
52 case NL80211_CHAN_NO_HT:
53 case NL80211_CHAN_HT20:
54 return IEEE80211_HT_PARAM_CHA_SEC_NONE;
55 case NL80211_CHAN_HT40PLUS:
56 return IEEE80211_HT_PARAM_CHA_SEC_ABOVE;
57 case NL80211_CHAN_HT40MINUS:
58 return IEEE80211_HT_PARAM_CHA_SEC_BELOW;
59 default:
60 return IEEE80211_HT_PARAM_CHA_SEC_NONE;
61 }
62 }
63
64 /* Map IEEE HT secondary‑channel type to nl80211 channel type */
nxpwifi_get_chan_type(struct nxpwifi_private * priv)65 u8 nxpwifi_get_chan_type(struct nxpwifi_private *priv)
66 {
67 struct nxpwifi_channel_band channel_band;
68 int ret;
69
70 ret = nxpwifi_get_chan_info(priv, &channel_band);
71
72 if (!ret) {
73 switch (channel_band.band_config.chan_width) {
74 case CHAN_BW_20MHZ:
75 if (IS_11N_ENABLED(priv))
76 return NL80211_CHAN_HT20;
77 else
78 return NL80211_CHAN_NO_HT;
79 case CHAN_BW_40MHZ:
80 if (channel_band.band_config.chan2_offset ==
81 IEEE80211_HT_PARAM_CHA_SEC_ABOVE)
82 return NL80211_CHAN_HT40PLUS;
83 else
84 return NL80211_CHAN_HT40MINUS;
85 default:
86 return NL80211_CHAN_HT20;
87 }
88 }
89
90 return NL80211_CHAN_HT20;
91 }
92
93 /* Retrieve the driver private data from the wiphy */
nxpwifi_cfg80211_get_adapter(struct wiphy * wiphy)94 static void *nxpwifi_cfg80211_get_adapter(struct wiphy *wiphy)
95 {
96 return (void *)(*(unsigned long *)wiphy_priv(wiphy));
97 }
98
99 /* cfg80211 operation handler to delete a network key. */
100 static int
nxpwifi_cfg80211_del_key(struct wiphy * wiphy,struct wireless_dev * wdev,int link_id,u8 key_index,bool pairwise,const u8 * mac_addr)101 nxpwifi_cfg80211_del_key(struct wiphy *wiphy, struct wireless_dev *wdev,
102 int link_id, u8 key_index, bool pairwise,
103 const u8 *mac_addr)
104 {
105 struct nxpwifi_private *priv = nxpwifi_netdev_get_priv(wdev->netdev);
106 static const u8 bc_mac[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
107 const u8 *peer_mac = pairwise ? mac_addr : bc_mac;
108 int ret;
109
110 ret = nxpwifi_set_encode(priv, NULL, NULL, 0, key_index, peer_mac, 1);
111 if (ret)
112 nxpwifi_dbg(priv->adapter, ERROR,
113 "crypto keys deleted failed %d\n", ret);
114 else
115 nxpwifi_dbg(priv->adapter, INFO, "info: crypto keys deleted\n");
116
117 return ret;
118 }
119
120 /* Build an skb containing a management frame */
121 static void
nxpwifi_form_mgmt_frame(struct sk_buff * skb,const u8 * buf,size_t len)122 nxpwifi_form_mgmt_frame(struct sk_buff *skb, const u8 *buf, size_t len)
123 {
124 u8 addr[ETH_ALEN];
125 u16 pkt_len;
126 u32 tx_control = 0, pkt_type = PKT_TYPE_MGMT;
127
128 eth_broadcast_addr(addr);
129 pkt_len = len + ETH_ALEN;
130
131 skb_reserve(skb, NXPWIFI_MIN_DATA_HEADER_LEN +
132 NXPWIFI_MGMT_FRAME_HEADER_SIZE + sizeof(pkt_len));
133 memcpy(skb_push(skb, sizeof(pkt_len)), &pkt_len, sizeof(pkt_len));
134
135 memcpy(skb_push(skb, sizeof(tx_control)),
136 &tx_control, sizeof(tx_control));
137
138 memcpy(skb_push(skb, sizeof(pkt_type)), &pkt_type, sizeof(pkt_type));
139
140 /* Add packet data and address4 */
141 skb_put_data(skb, buf, sizeof(struct ieee80211_hdr_3addr));
142 skb_put_data(skb, addr, ETH_ALEN);
143 skb_put_data(skb, buf + sizeof(struct ieee80211_hdr_3addr),
144 len - sizeof(struct ieee80211_hdr_3addr));
145
146 skb->priority = TC_PRIO_BESTEFFORT;
147 __net_timestamp(skb);
148 }
149
150 /* cfg80211 operation handler to transmit a management frame. */
151 static int
nxpwifi_cfg80211_mgmt_tx(struct wiphy * wiphy,struct wireless_dev * wdev,struct cfg80211_mgmt_tx_params * params,u64 cookie)152 nxpwifi_cfg80211_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev,
153 struct cfg80211_mgmt_tx_params *params, u64 cookie)
154 {
155 const u8 *buf = params->buf;
156 size_t len = params->len;
157 struct sk_buff *skb;
158 u16 pkt_len;
159 const struct ieee80211_mgmt *mgmt;
160 struct nxpwifi_txinfo *tx_info;
161 struct nxpwifi_private *priv = nxpwifi_netdev_get_priv(wdev->netdev);
162
163 if (!buf || !len) {
164 nxpwifi_dbg(priv->adapter, ERROR, "invalid buffer and length\n");
165 return -EINVAL;
166 }
167
168 mgmt = (const struct ieee80211_mgmt *)buf;
169 if (GET_BSS_ROLE(priv) != NXPWIFI_BSS_ROLE_STA &&
170 ieee80211_is_probe_resp(mgmt->frame_control)) {
171 /* Offloaded probe responses; skip TX in AP/GO mode */
172 nxpwifi_dbg(priv->adapter, INFO,
173 "info: skip to send probe resp in AP or GO mode\n");
174 return 0;
175 }
176
177 if (GET_BSS_ROLE(priv) == NXPWIFI_BSS_ROLE_UAP) {
178 if (ieee80211_is_auth(mgmt->frame_control))
179 nxpwifi_dbg(priv->adapter, MSG,
180 "auth: send auth to %pM\n", mgmt->da);
181 if (ieee80211_is_deauth(mgmt->frame_control))
182 nxpwifi_dbg(priv->adapter, MSG,
183 "auth: send deauth to %pM\n", mgmt->da);
184 if (ieee80211_is_disassoc(mgmt->frame_control))
185 nxpwifi_dbg(priv->adapter, MSG,
186 "assoc: send disassoc to %pM\n", mgmt->da);
187 if (ieee80211_is_assoc_resp(mgmt->frame_control))
188 nxpwifi_dbg(priv->adapter, MSG,
189 "assoc: send assoc resp to %pM\n",
190 mgmt->da);
191 if (ieee80211_is_reassoc_resp(mgmt->frame_control))
192 nxpwifi_dbg(priv->adapter, MSG,
193 "assoc: send reassoc resp to %pM\n",
194 mgmt->da);
195 }
196
197 pkt_len = len + ETH_ALEN;
198 skb = dev_alloc_skb(NXPWIFI_MIN_DATA_HEADER_LEN +
199 NXPWIFI_MGMT_FRAME_HEADER_SIZE +
200 pkt_len + sizeof(pkt_len));
201
202 if (!skb) {
203 nxpwifi_dbg(priv->adapter, ERROR,
204 "allocate skb failed for management frame\n");
205 return -ENOMEM;
206 }
207
208 tx_info = NXPWIFI_SKB_TXCB(skb);
209 memset(tx_info, 0, sizeof(*tx_info));
210 tx_info->bss_num = priv->bss_num;
211 tx_info->bss_type = priv->bss_type;
212 tx_info->pkt_len = pkt_len;
213
214 nxpwifi_form_mgmt_frame(skb, buf, len);
215
216 if (ieee80211_is_action(mgmt->frame_control))
217 skb = nxpwifi_clone_skb_for_tx_status(priv,
218 skb,
219 NXPWIFI_BUF_FLAG_ACTION_TX_STATUS, &cookie);
220 else
221 cfg80211_mgmt_tx_status(wdev, cookie, buf, len, true,
222 GFP_ATOMIC);
223
224 nxpwifi_queue_tx_pkt(priv, skb);
225
226 nxpwifi_dbg(priv->adapter, INFO, "info: management frame transmitted\n");
227 return 0;
228 }
229
230 /* cfg80211 operation handler to register a mgmt frame. */
231 static void
nxpwifi_cfg80211_update_mgmt_frame_registrations(struct wiphy * wiphy,struct wireless_dev * wdev,struct mgmt_frame_regs * upd)232 nxpwifi_cfg80211_update_mgmt_frame_registrations(struct wiphy *wiphy,
233 struct wireless_dev *wdev,
234 struct mgmt_frame_regs *upd)
235 {
236 struct nxpwifi_private *priv = nxpwifi_netdev_get_priv(wdev->netdev);
237 u32 mask = upd->interface_stypes;
238
239 if (mask != priv->mgmt_frame_mask) {
240 priv->mgmt_frame_mask = mask;
241 if (priv->host_mlme_reg &&
242 GET_BSS_ROLE(priv) != NXPWIFI_BSS_ROLE_UAP)
243 priv->mgmt_frame_mask |= HOST_MLME_MGMT_MASK;
244
245 nxpwifi_mgmt_frame_reg(priv, priv->mgmt_frame_mask);
246
247 nxpwifi_dbg(priv->adapter, INFO, "info: mgmt frame registered\n");
248 }
249 }
250
251 /* cfg80211 operation handler to remain on channel. */
252 static int
nxpwifi_cfg80211_remain_on_channel(struct wiphy * wiphy,struct wireless_dev * wdev,struct ieee80211_channel * chan,unsigned int duration,u64 cookie,const u8 * rx_addr)253 nxpwifi_cfg80211_remain_on_channel(struct wiphy *wiphy,
254 struct wireless_dev *wdev,
255 struct ieee80211_channel *chan,
256 unsigned int duration, u64 cookie,
257 const u8 *rx_addr)
258 {
259 struct nxpwifi_private *priv = nxpwifi_netdev_get_priv(wdev->netdev);
260 struct nxpwifi_adapter *adapter = priv->adapter;
261 int ret;
262
263 if (!chan) {
264 nxpwifi_dbg(adapter, ERROR, "Invalid parameter for ROC\n");
265 return -EINVAL;
266 }
267
268 if (priv->roc_cfg.cookie) {
269 nxpwifi_dbg(adapter, INFO,
270 "info: ongoing ROC, cookie = 0x%llx\n",
271 priv->roc_cfg.cookie);
272 return -EBUSY;
273 }
274
275 ret = nxpwifi_remain_on_chan_cfg(priv, HOST_ACT_GEN_SET, chan,
276 duration);
277
278 if (!ret) {
279 priv->roc_cfg.cookie = cookie;
280 priv->roc_cfg.chan = *chan;
281
282 cfg80211_ready_on_channel(wdev, cookie, chan,
283 duration, GFP_ATOMIC);
284
285 nxpwifi_dbg(adapter, INFO,
286 "info: ROC, cookie = 0x%llx\n", cookie);
287 }
288
289 return ret;
290 }
291
292 /* cfg80211 operation handler to cancel remain on channel. */
293 static int
nxpwifi_cfg80211_cancel_remain_on_channel(struct wiphy * wiphy,struct wireless_dev * wdev,u64 cookie)294 nxpwifi_cfg80211_cancel_remain_on_channel(struct wiphy *wiphy,
295 struct wireless_dev *wdev, u64 cookie)
296 {
297 struct nxpwifi_private *priv = nxpwifi_netdev_get_priv(wdev->netdev);
298 int ret;
299
300 if (cookie != priv->roc_cfg.cookie)
301 return -ENOENT;
302
303 ret = nxpwifi_remain_on_chan_cfg(priv, HOST_ACT_GEN_REMOVE,
304 &priv->roc_cfg.chan, 0);
305
306 if (!ret) {
307 cfg80211_remain_on_channel_expired(wdev, cookie,
308 &priv->roc_cfg.chan,
309 GFP_ATOMIC);
310
311 memset(&priv->roc_cfg, 0, sizeof(struct nxpwifi_roc_cfg));
312
313 nxpwifi_dbg(priv->adapter, INFO,
314 "info: cancel ROC, cookie = 0x%llx\n", cookie);
315 }
316
317 return ret;
318 }
319
320 /* cfg80211 operation handler to set Tx power. */
321 static int
nxpwifi_cfg80211_set_tx_power(struct wiphy * wiphy,struct wireless_dev * wdev,int radio_idx,enum nl80211_tx_power_setting type,int mbm)322 nxpwifi_cfg80211_set_tx_power(struct wiphy *wiphy,
323 struct wireless_dev *wdev,
324 int radio_idx,
325 enum nl80211_tx_power_setting type,
326 int mbm)
327 {
328 struct nxpwifi_adapter *adapter = nxpwifi_cfg80211_get_adapter(wiphy);
329 struct nxpwifi_private *priv;
330 struct nxpwifi_power_cfg power_cfg;
331 int dbm = MBM_TO_DBM(mbm);
332
333 switch (type) {
334 case NL80211_TX_POWER_FIXED:
335 power_cfg.is_power_auto = 0;
336 power_cfg.is_power_fixed = 1;
337 power_cfg.power_level = dbm;
338 break;
339 case NL80211_TX_POWER_LIMITED:
340 power_cfg.is_power_auto = 0;
341 power_cfg.is_power_fixed = 0;
342 power_cfg.power_level = dbm;
343 break;
344 case NL80211_TX_POWER_AUTOMATIC:
345 power_cfg.is_power_auto = 1;
346 break;
347 }
348
349 priv = nxpwifi_get_priv(adapter, NXPWIFI_BSS_ROLE_ANY);
350
351 return nxpwifi_set_tx_power(priv, &power_cfg);
352 }
353
354 /* cfg80211 operation handler to get Tx power. */
355 static int
nxpwifi_cfg80211_get_tx_power(struct wiphy * wiphy,struct wireless_dev * wdev,int radio_idx,unsigned int link_id,int * dbm)356 nxpwifi_cfg80211_get_tx_power(struct wiphy *wiphy,
357 struct wireless_dev *wdev,
358 int radio_idx,
359 unsigned int link_id,
360 int *dbm)
361 {
362 struct nxpwifi_adapter *adapter = nxpwifi_cfg80211_get_adapter(wiphy);
363 struct nxpwifi_private *priv = nxpwifi_get_priv(adapter, NXPWIFI_BSS_ROLE_ANY);
364 int ret = nxpwifi_get_tx_pwr(priv);
365
366 if (ret < 0)
367 return ret;
368
369 *dbm = priv->tx_power_level;
370
371 return 0;
372 }
373
374 /*
375 * cfg80211 handler for setting IEEE 802.11 Power Save mode.
376 *
377 * The 'timeout' parameter is not supported and is ignored.
378 */
379 static int
nxpwifi_cfg80211_set_power_mgmt(struct wiphy * wiphy,struct net_device * dev,bool enabled,int timeout)380 nxpwifi_cfg80211_set_power_mgmt(struct wiphy *wiphy,
381 struct net_device *dev,
382 bool enabled, int timeout)
383 {
384 struct nxpwifi_private *priv = nxpwifi_netdev_get_priv(dev);
385 u32 ps_mode;
386
387 if (timeout)
388 nxpwifi_dbg(priv->adapter, INFO,
389 "info: ignore timeout value for IEEE Power Save\n");
390
391 ps_mode = enabled;
392
393 return nxpwifi_drv_set_power(priv, &ps_mode);
394 }
395
396 /*
397 * cfg80211 handler for setting the default WEP key.
398 *
399 * Ignored if WEP is not enabled.
400 */
401 static int
nxpwifi_cfg80211_set_default_key(struct wiphy * wiphy,struct net_device * netdev,int link_id,u8 key_index,bool unicast,bool multicast)402 nxpwifi_cfg80211_set_default_key(struct wiphy *wiphy, struct net_device *netdev,
403 int link_id, u8 key_index, bool unicast,
404 bool multicast)
405 {
406 struct nxpwifi_private *priv = nxpwifi_netdev_get_priv(netdev);
407 int ret = 0;
408
409 /* Return if WEP key not configured */
410 if (!priv->sec_info.wep_enabled)
411 return 0;
412
413 if (priv->bss_type == NXPWIFI_BSS_TYPE_UAP) {
414 priv->wep_key_curr_index = key_index;
415 } else {
416 ret = nxpwifi_set_encode(priv, NULL, NULL, 0, key_index,
417 NULL, 0);
418 if (ret)
419 nxpwifi_dbg(priv->adapter, ERROR,
420 "failed to set default Tx key index\n");
421 }
422
423 return ret;
424 }
425
426 /* cfg80211 handler for adding an 802.11 encryption key. */
427 static int
nxpwifi_cfg80211_add_key(struct wiphy * wiphy,struct wireless_dev * wdev,int link_id,u8 key_index,bool pairwise,const u8 * mac_addr,struct key_params * params)428 nxpwifi_cfg80211_add_key(struct wiphy *wiphy, struct wireless_dev *wdev,
429 int link_id, u8 key_index, bool pairwise,
430 const u8 *mac_addr, struct key_params *params)
431 {
432 struct nxpwifi_private *priv = nxpwifi_netdev_get_priv(wdev->netdev);
433 struct nxpwifi_wep_key *wep_key;
434 u8 bc_mac[ETH_ALEN];
435 const u8 *peer_mac;
436 int ret;
437
438 eth_broadcast_addr(bc_mac);
439 peer_mac = pairwise ? mac_addr : bc_mac;
440
441 if (GET_BSS_ROLE(priv) == NXPWIFI_BSS_ROLE_UAP &&
442 (params->cipher == WLAN_CIPHER_SUITE_WEP40 ||
443 params->cipher == WLAN_CIPHER_SUITE_WEP104)) {
444 if (params->key && params->key_len) {
445 wep_key = &priv->wep_key[key_index];
446 memset(wep_key, 0, sizeof(struct nxpwifi_wep_key));
447 memcpy(wep_key->key_material, params->key,
448 params->key_len);
449 wep_key->key_index = key_index;
450 wep_key->key_length = params->key_len;
451 priv->sec_info.wep_enabled = 1;
452 }
453 return 0;
454 }
455
456 ret = nxpwifi_set_encode(priv, params, params->key, params->key_len,
457 key_index, peer_mac, 0);
458 if (ret)
459 nxpwifi_dbg(priv->adapter, ERROR,
460 "failed to add crypto keys\n");
461
462 return ret;
463 }
464
465 /* cfg80211 handler for setting the default management key. */
466 static int
nxpwifi_cfg80211_set_default_mgmt_key(struct wiphy * wiphy,struct wireless_dev * wdev,int link_id,u8 key_index)467 nxpwifi_cfg80211_set_default_mgmt_key(struct wiphy *wiphy,
468 struct wireless_dev *wdev,
469 int link_id,
470 u8 key_index)
471 {
472 return 0;
473 }
474
475 /*
476 * Sends regulatory domain information to the firmware.
477 *
478 * Includes:
479 * - Country code
480 * - Sub-band definitions (first channel, channel count, max TX power)
481 */
nxpwifi_send_domain_info_cmd_fw(struct wiphy * wiphy,enum nl80211_band band)482 int nxpwifi_send_domain_info_cmd_fw(struct wiphy *wiphy, enum nl80211_band band)
483 {
484 u8 no_of_triplet = 0;
485 struct ieee80211_country_ie_triplet *t;
486 u8 no_of_parsed_chan = 0;
487 u8 first_chan = 0, next_chan = 0, max_pwr = 0;
488 u8 i, flag = 0;
489 struct ieee80211_supported_band *sband;
490 struct ieee80211_channel *ch;
491 struct nxpwifi_adapter *adapter = nxpwifi_cfg80211_get_adapter(wiphy);
492 struct nxpwifi_private *priv;
493 struct nxpwifi_802_11d_domain_reg *domain_info = &adapter->domain_reg;
494 int ret;
495
496 domain_info->dfs_region = adapter->dfs_region;
497
498 /* Set country code */
499 domain_info->country_code[0] = adapter->country_code[0];
500 domain_info->country_code[1] = adapter->country_code[1];
501 domain_info->country_code[2] = ' ';
502
503 if (!wiphy->bands[band]) {
504 nxpwifi_dbg(adapter, ERROR,
505 "11D: setting domain info in FW\n");
506 return -EINVAL;
507 }
508
509 sband = wiphy->bands[band];
510
511 for (i = 0; i < sband->n_channels ; i++) {
512 ch = &sband->channels[i];
513 if (ch->flags & IEEE80211_CHAN_DISABLED)
514 continue;
515
516 if (!flag) {
517 flag = 1;
518 first_chan = (u32)ch->hw_value;
519 next_chan = first_chan;
520 max_pwr = ch->max_power;
521 no_of_parsed_chan = 1;
522 continue;
523 }
524
525 if (ch->hw_value == next_chan + 1 &&
526 ch->max_power == max_pwr) {
527 next_chan++;
528 no_of_parsed_chan++;
529 } else {
530 t = &domain_info->triplet[no_of_triplet];
531 t->chans.first_channel = first_chan;
532 t->chans.num_channels = no_of_parsed_chan;
533 t->chans.max_power = max_pwr;
534 no_of_triplet++;
535 first_chan = (u32)ch->hw_value;
536 next_chan = first_chan;
537 max_pwr = ch->max_power;
538 no_of_parsed_chan = 1;
539 }
540 }
541
542 if (flag) {
543 t = &domain_info->triplet[no_of_triplet];
544 t->chans.first_channel = first_chan;
545 t->chans.num_channels = no_of_parsed_chan;
546 t->chans.max_power = max_pwr;
547 no_of_triplet++;
548 }
549
550 domain_info->no_of_triplet = no_of_triplet;
551
552 priv = nxpwifi_get_priv(adapter, NXPWIFI_BSS_ROLE_ANY);
553
554 ret = nxpwifi_apply_regdomain(priv);
555
556 if (ret)
557 nxpwifi_dbg(adapter, INFO,
558 "11D: failed to set domain info in FW\n");
559
560 return ret;
561 }
562
nxpwifi_reg_apply_radar_flags(struct wiphy * wiphy)563 static void nxpwifi_reg_apply_radar_flags(struct wiphy *wiphy)
564 {
565 struct ieee80211_supported_band *sband;
566 struct ieee80211_channel *chan;
567 unsigned int i;
568
569 if (!wiphy->bands[NL80211_BAND_5GHZ])
570 return;
571 sband = wiphy->bands[NL80211_BAND_5GHZ];
572
573 for (i = 0; i < sband->n_channels; i++) {
574 chan = &sband->channels[i];
575 if ((!(chan->flags & IEEE80211_CHAN_DISABLED)) &&
576 (chan->flags & IEEE80211_CHAN_RADAR))
577 chan->flags |= IEEE80211_CHAN_NO_IR;
578 }
579 }
580
581 /*
582 * cfg80211 regulatory domain change callback.
583 *
584 * Invoked when the regulatory domain is updated by:
585 * - the driver
586 * - the system core
587 * - the user
588 * - a received Country IE
589 */
nxpwifi_reg_notifier(struct wiphy * wiphy,struct regulatory_request * request)590 static void nxpwifi_reg_notifier(struct wiphy *wiphy,
591 struct regulatory_request *request)
592 {
593 struct nxpwifi_adapter *adapter = nxpwifi_cfg80211_get_adapter(wiphy);
594
595 nxpwifi_dbg(adapter, INFO,
596 "info: cfg80211 regulatory domain callback for %c%c\n",
597 request->alpha2[0], request->alpha2[1]);
598 nxpwifi_reg_apply_radar_flags(wiphy);
599
600 switch (request->initiator) {
601 case NL80211_REGDOM_SET_BY_DRIVER:
602 case NL80211_REGDOM_SET_BY_CORE:
603 case NL80211_REGDOM_SET_BY_USER:
604 case NL80211_REGDOM_SET_BY_COUNTRY_IE:
605 break;
606 default:
607 nxpwifi_dbg(adapter, ERROR,
608 "unknown regdom initiator: %d\n",
609 request->initiator);
610 return;
611 }
612
613 /* Skip world/unchanged regulatory domains. */
614 if (strncmp(request->alpha2, "00", 2) &&
615 strncmp(request->alpha2, adapter->country_code,
616 sizeof(request->alpha2))) {
617 memcpy(adapter->country_code, request->alpha2,
618 sizeof(request->alpha2));
619 adapter->dfs_region = request->dfs_region;
620 nxpwifi_send_domain_info_cmd_fw(wiphy, NL80211_BAND_2GHZ);
621 if (adapter->fw_bands & BAND_A)
622 nxpwifi_send_domain_info_cmd_fw(wiphy,
623 NL80211_BAND_5GHZ);
624 }
625 }
626
627 /*
628 * cfg80211 op: set wiphy parameters.
629 * Updates RTS/fragmentation thresholds and retry limits based on 'changed'
630 * flags.
631 */
632 static int
nxpwifi_cfg80211_set_wiphy_params(struct wiphy * wiphy,int radio_idx,u32 changed)633 nxpwifi_cfg80211_set_wiphy_params(struct wiphy *wiphy, int radio_idx, u32 changed)
634 {
635 struct nxpwifi_adapter *adapter = nxpwifi_cfg80211_get_adapter(wiphy);
636 struct nxpwifi_private *priv;
637 struct nxpwifi_uap_bss_param *bss_cfg;
638 int ret = 0;
639
640 priv = nxpwifi_get_priv(adapter, NXPWIFI_BSS_ROLE_ANY);
641
642 switch (priv->bss_role) {
643 case NXPWIFI_BSS_ROLE_UAP:
644 bss_cfg = kzalloc_obj(*bss_cfg, GFP_KERNEL);
645 if (!bss_cfg) {
646 ret = -ENOMEM;
647 break;
648 }
649
650 nxpwifi_set_sys_config_invalid_data(bss_cfg);
651
652 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
653 bss_cfg->rts_threshold = wiphy->rts_threshold;
654 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
655 bss_cfg->frag_threshold = wiphy->frag_threshold;
656 if (changed & WIPHY_PARAM_RETRY_LONG)
657 bss_cfg->retry_limit = wiphy->retry_long;
658
659 ret = nxpwifi_set_uap_sys_cfg(priv, bss_cfg);
660
661 kfree(bss_cfg);
662 if (ret)
663 nxpwifi_dbg(adapter, ERROR,
664 "Failed to set wiphy phy params\n");
665 break;
666
667 case NXPWIFI_BSS_ROLE_STA:
668 if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
669 ret = nxpwifi_set_rts(priv,
670 wiphy->rts_threshold);
671 if (ret)
672 break;
673 }
674 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
675 ret = nxpwifi_set_frag(priv,
676 wiphy->frag_threshold);
677 break;
678 }
679
680 return ret;
681 }
682
nxpwifi_deinit_priv_params(struct nxpwifi_private * priv)683 static int nxpwifi_deinit_priv_params(struct nxpwifi_private *priv)
684 {
685 struct nxpwifi_adapter *adapter = priv->adapter;
686 int ret = 0;
687
688 if (priv->mgmt_frame_mask) {
689 priv->mgmt_frame_mask = 0;
690 ret = nxpwifi_mgmt_frame_reg(priv, priv->mgmt_frame_mask);
691
692 if (ret) {
693 nxpwifi_dbg(adapter, ERROR,
694 "could not unregister mgmt frame rx\n");
695 return ret;
696 }
697 priv->host_mlme_reg = false;
698
699 }
700
701 nxpwifi_deauthenticate(priv, NULL);
702
703 atomic_set(&adapter->iface_changing, 1);
704 flush_workqueue(adapter->workqueue);
705 flush_workqueue(adapter->rx_workqueue);
706 nxpwifi_free_priv(priv);
707 priv->wdev.iftype = NL80211_IFTYPE_UNSPECIFIED;
708 priv->bss_mode = NL80211_IFTYPE_UNSPECIFIED;
709 priv->sec_info.authentication_mode = NL80211_AUTHTYPE_OPEN_SYSTEM;
710
711 return ret;
712 }
713
714 static int
nxpwifi_init_new_priv_params(struct nxpwifi_private * priv,struct net_device * dev,enum nl80211_iftype type)715 nxpwifi_init_new_priv_params(struct nxpwifi_private *priv,
716 struct net_device *dev,
717 enum nl80211_iftype type)
718 {
719 struct nxpwifi_adapter *adapter = priv->adapter;
720 int ret;
721
722 nxpwifi_init_priv(priv);
723
724 priv->bss_mode = type;
725 priv->wdev.iftype = type;
726
727 nxpwifi_init_priv_params(priv, priv->netdev);
728 priv->bss_started = 0;
729
730 switch (type) {
731 case NL80211_IFTYPE_STATION:
732 priv->bss_role = NXPWIFI_BSS_ROLE_STA;
733 break;
734 case NL80211_IFTYPE_AP:
735 priv->bss_role = NXPWIFI_BSS_ROLE_UAP;
736 break;
737 default:
738 nxpwifi_dbg(adapter, ERROR,
739 "%s: changing to %d not supported\n",
740 dev->name, type);
741 return -EOPNOTSUPP;
742 }
743
744 ret = nxpwifi_get_unused_bss_num(adapter, priv->bss_type,
745 &priv->bss_num);
746
747 if (ret) {
748 nxpwifi_dbg(adapter, ERROR,
749 "%s: no unused bss_num for type %d\n",
750 dev->name, priv->bss_type);
751 return ret;
752 }
753
754 flush_workqueue(adapter->workqueue);
755 atomic_set(&adapter->iface_changing, 0);
756
757 nxpwifi_set_mac_address(priv, dev, false, NULL);
758
759 return 0;
760 }
761
762 static bool
is_vif_type_change_allowed(struct nxpwifi_adapter * adapter,enum nl80211_iftype old_iftype,enum nl80211_iftype new_iftype)763 is_vif_type_change_allowed(struct nxpwifi_adapter *adapter,
764 enum nl80211_iftype old_iftype,
765 enum nl80211_iftype new_iftype)
766 {
767 switch (old_iftype) {
768 case NL80211_IFTYPE_STATION:
769 switch (new_iftype) {
770 case NL80211_IFTYPE_AP:
771 return adapter->curr_iface_comb.uap_intf !=
772 adapter->iface_limit.uap_intf;
773 default:
774 return false;
775 }
776
777 case NL80211_IFTYPE_AP:
778 switch (new_iftype) {
779 case NL80211_IFTYPE_STATION:
780 return adapter->curr_iface_comb.sta_intf !=
781 adapter->iface_limit.sta_intf;
782 default:
783 return false;
784 }
785
786 default:
787 break;
788 }
789
790 return false;
791 }
792
793 static void
update_vif_type_counter(struct nxpwifi_adapter * adapter,enum nl80211_iftype iftype,int change)794 update_vif_type_counter(struct nxpwifi_adapter *adapter,
795 enum nl80211_iftype iftype,
796 int change)
797 {
798 switch (iftype) {
799 case NL80211_IFTYPE_UNSPECIFIED:
800 case NL80211_IFTYPE_STATION:
801 adapter->curr_iface_comb.sta_intf += change;
802 break;
803 case NL80211_IFTYPE_AP:
804 adapter->curr_iface_comb.uap_intf += change;
805 break;
806 case NL80211_IFTYPE_MONITOR:
807 break;
808 default:
809 nxpwifi_dbg(adapter, ERROR,
810 "%s: Unsupported iftype passed: %d\n",
811 __func__, iftype);
812 break;
813 }
814 }
815
816 static int
nxpwifi_change_vif_to_sta(struct net_device * dev,enum nl80211_iftype curr_iftype,enum nl80211_iftype type,struct vif_params * params)817 nxpwifi_change_vif_to_sta(struct net_device *dev,
818 enum nl80211_iftype curr_iftype,
819 enum nl80211_iftype type,
820 struct vif_params *params)
821 {
822 struct nxpwifi_private *priv;
823 struct nxpwifi_adapter *adapter;
824 int ret;
825
826 priv = nxpwifi_netdev_get_priv(dev);
827
828 if (!priv)
829 return -EINVAL;
830
831 adapter = priv->adapter;
832
833 nxpwifi_dbg(adapter, INFO,
834 "%s: changing role to station\n", dev->name);
835
836 ret = nxpwifi_deinit_priv_params(priv);
837 if (ret)
838 goto done;
839 ret = nxpwifi_init_new_priv_params(priv, dev, type);
840 if (ret)
841 goto done;
842
843 update_vif_type_counter(adapter, curr_iftype, -1);
844 update_vif_type_counter(adapter, type, 1);
845 dev->ieee80211_ptr->iftype = type;
846
847 if (nxpwifi_set_bss_mode(priv))
848 return -1;
849
850 if (ret)
851 goto done;
852
853 ret = nxpwifi_sta_init_cmd(priv, false, false);
854
855 done:
856 return ret;
857 }
858
859 static int
nxpwifi_change_vif_to_ap(struct net_device * dev,enum nl80211_iftype curr_iftype,enum nl80211_iftype type,struct vif_params * params)860 nxpwifi_change_vif_to_ap(struct net_device *dev,
861 enum nl80211_iftype curr_iftype,
862 enum nl80211_iftype type,
863 struct vif_params *params)
864 {
865 struct nxpwifi_private *priv;
866 struct nxpwifi_adapter *adapter;
867 int ret;
868
869 priv = nxpwifi_netdev_get_priv(dev);
870
871 if (!priv)
872 return -EINVAL;
873
874 adapter = priv->adapter;
875
876 nxpwifi_dbg(adapter, INFO,
877 "%s: changing role to AP\n", dev->name);
878
879 ret = nxpwifi_deinit_priv_params(priv);
880 if (ret)
881 goto done;
882
883 ret = nxpwifi_init_new_priv_params(priv, dev, type);
884 if (ret)
885 goto done;
886
887 update_vif_type_counter(adapter, curr_iftype, -1);
888 update_vif_type_counter(adapter, type, 1);
889 dev->ieee80211_ptr->iftype = type;
890
891 if (nxpwifi_set_bss_mode(priv))
892 return -1;
893
894 if (ret)
895 goto done;
896
897 ret = nxpwifi_sta_init_cmd(priv, false, false);
898
899 done:
900 return ret;
901 }
902
903 /* cfg80211 operation handler to change interface type. */
904 static int
nxpwifi_cfg80211_change_virtual_intf(struct wiphy * wiphy,struct net_device * dev,enum nl80211_iftype type,struct vif_params * params)905 nxpwifi_cfg80211_change_virtual_intf(struct wiphy *wiphy,
906 struct net_device *dev,
907 enum nl80211_iftype type,
908 struct vif_params *params)
909 {
910 struct nxpwifi_private *priv = nxpwifi_netdev_get_priv(dev);
911 enum nl80211_iftype curr_iftype = dev->ieee80211_ptr->iftype;
912
913 if (priv->scan_request) {
914 nxpwifi_dbg(priv->adapter, ERROR,
915 "change virtual interface: scan in process\n");
916 return -EBUSY;
917 }
918
919 if (type == NL80211_IFTYPE_UNSPECIFIED) {
920 nxpwifi_dbg(priv->adapter, INFO,
921 "%s: no new type specified, keeping old type %d\n",
922 dev->name, curr_iftype);
923 return 0;
924 }
925
926 if (curr_iftype == type) {
927 nxpwifi_dbg(priv->adapter, INFO,
928 "%s: interface already is of type %d\n",
929 dev->name, curr_iftype);
930 return 0;
931 }
932
933 if (!is_vif_type_change_allowed(priv->adapter, curr_iftype, type)) {
934 nxpwifi_dbg(priv->adapter, ERROR,
935 "%s: change from type %d to %d is not allowed\n",
936 dev->name, curr_iftype, type);
937 return -EOPNOTSUPP;
938 }
939
940 switch (curr_iftype) {
941 case NL80211_IFTYPE_STATION:
942 switch (type) {
943 case NL80211_IFTYPE_AP:
944 return nxpwifi_change_vif_to_ap(dev, curr_iftype, type,
945 params);
946 default:
947 goto errnotsupp;
948 }
949
950 case NL80211_IFTYPE_AP:
951 switch (type) {
952 case NL80211_IFTYPE_STATION:
953 return nxpwifi_change_vif_to_sta(dev, curr_iftype,
954 type, params);
955 default:
956 goto errnotsupp;
957 }
958
959 default:
960 goto errnotsupp;
961 }
962
963 errnotsupp:
964 nxpwifi_dbg(priv->adapter, ERROR,
965 "unsupported interface type transition: %d to %d\n",
966 curr_iftype, type);
967 return -EOPNOTSUPP;
968 }
969
970 #define RATE_FORMAT_LG 0
971 #define RATE_FORMAT_HT 1
972 #define RATE_FORMAT_VHT 2
973 #define RATE_FORMAT_HE 3
974
975 static void
nxpwifi_parse_htinfo(struct nxpwifi_private * priv,u8 rateinfo,u8 htinfo,struct rate_info * rate)976 nxpwifi_parse_htinfo(struct nxpwifi_private *priv, u8 rateinfo, u8 htinfo,
977 struct rate_info *rate)
978 {
979 struct nxpwifi_adapter *adapter = priv->adapter;
980 u8 rate_format;
981 u8 he_dcm;
982 u8 stbc;
983 u8 gi;
984 u8 bw;
985 /* Bitrates in multiples of 100kb/s. */
986 static const int legacy_rates[] = {
987 [0] = 10,
988 [1] = 20,
989 [2] = 55,
990 [3] = 110,
991 [4] = 60, /* NXPWIFI_RATE_INDEX_OFDM0 */
992 [5] = 60,
993 [6] = 90,
994 [7] = 120,
995 [8] = 180,
996 [9] = 240,
997 [10] = 360,
998 [11] = 480,
999 [12] = 540,
1000 };
1001
1002 rate_format = htinfo & 0x3;
1003
1004 switch (rate_format) {
1005 case RATE_FORMAT_LG:
1006 if (rateinfo < ARRAY_SIZE(legacy_rates))
1007 rate->legacy = legacy_rates[rateinfo];
1008 break;
1009 case RATE_FORMAT_HT:
1010 rate->mcs = rateinfo;
1011 rate->flags |= RATE_INFO_FLAGS_MCS;
1012 break;
1013 case RATE_FORMAT_VHT:
1014 rate->mcs = rateinfo & 0xF;
1015 rate->flags |= RATE_INFO_FLAGS_VHT_MCS;
1016 break;
1017 case RATE_FORMAT_HE:
1018 rate->mcs = rateinfo & 0xF;
1019 rate->flags |= RATE_INFO_FLAGS_HE_MCS;
1020 he_dcm = 0; /* ToDo: ext_rate_info */
1021 gi = (htinfo & BIT(4)) >> 4 |
1022 (htinfo & BIT(7)) >> 6;
1023 stbc = (htinfo & BIT(5)) >> 5;
1024 if (gi > 3) {
1025 nxpwifi_dbg(adapter, ERROR, "Invalid gi value\n");
1026 break;
1027 }
1028 if (gi == 3 && stbc && he_dcm) {
1029 gi = 0;
1030 stbc = 0;
1031 he_dcm = 0;
1032 }
1033 if (gi > 0)
1034 gi -= 1;
1035 rate->he_gi = gi;
1036 rate->he_dcm = he_dcm;
1037 break;
1038 }
1039
1040 bw = (htinfo & 0xC) >> 2;
1041
1042 switch (bw) {
1043 case 0:
1044 rate->bw = RATE_INFO_BW_20;
1045 break;
1046 case 1:
1047 rate->bw = RATE_INFO_BW_40;
1048 break;
1049 case 2:
1050 rate->bw = RATE_INFO_BW_80;
1051 break;
1052 case 3:
1053 rate->bw = RATE_INFO_BW_160;
1054 break;
1055 }
1056
1057 if (rate_format != RATE_FORMAT_HE && (htinfo & BIT(4)))
1058 rate->flags |= RATE_INFO_FLAGS_SHORT_GI;
1059
1060 if ((rateinfo >> 4) == 1)
1061 rate->nss = 2;
1062 else
1063 rate->nss = 1;
1064 }
1065
1066 /*
1067 * Dump station statistics into station_info.
1068 * Includes bytes/packets counters, signal level, and TX/RX rates.
1069 */
1070 static int
nxpwifi_dump_station_info(struct nxpwifi_private * priv,struct nxpwifi_sta_node * node,struct station_info * sinfo)1071 nxpwifi_dump_station_info(struct nxpwifi_private *priv,
1072 struct nxpwifi_sta_node *node,
1073 struct station_info *sinfo)
1074 {
1075 u32 rate;
1076 int ret;
1077
1078 sinfo->filled = BIT_ULL(NL80211_STA_INFO_RX_BYTES) |
1079 BIT_ULL(NL80211_STA_INFO_TX_BYTES) |
1080 BIT_ULL(NL80211_STA_INFO_RX_PACKETS) |
1081 BIT_ULL(NL80211_STA_INFO_TX_PACKETS) |
1082 BIT_ULL(NL80211_STA_INFO_TX_BITRATE) |
1083 BIT_ULL(NL80211_STA_INFO_SIGNAL) |
1084 BIT_ULL(NL80211_STA_INFO_SIGNAL_AVG);
1085
1086 if (GET_BSS_ROLE(priv) == NXPWIFI_BSS_ROLE_UAP) {
1087 if (!node)
1088 return -ENOENT;
1089
1090 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_INACTIVE_TIME) |
1091 BIT_ULL(NL80211_STA_INFO_TX_FAILED);
1092 sinfo->inactive_time =
1093 jiffies_to_msecs(jiffies - node->stats.last_rx);
1094
1095 sinfo->signal = node->stats.rssi;
1096 sinfo->signal_avg = node->stats.rssi;
1097 sinfo->rx_bytes = node->stats.rx_bytes;
1098 sinfo->tx_bytes = node->stats.tx_bytes;
1099 sinfo->rx_packets = node->stats.rx_packets;
1100 sinfo->tx_packets = node->stats.tx_packets;
1101 sinfo->tx_failed = node->stats.tx_failed;
1102
1103 nxpwifi_parse_htinfo(priv, priv->tx_rate,
1104 node->stats.last_tx_htinfo,
1105 &sinfo->txrate);
1106 sinfo->txrate.legacy = node->stats.last_tx_rate * 5;
1107
1108 return 0;
1109 }
1110
1111 /* Get signal information from the firmware */
1112 ret = nxpwifi_get_rssi_info(priv);
1113 if (ret) {
1114 nxpwifi_dbg(priv->adapter, ERROR,
1115 "failed to get signal information\n");
1116 goto done;
1117 }
1118
1119 ret = nxpwifi_drv_get_data_rate(priv, &rate);
1120 if (ret) {
1121 nxpwifi_dbg(priv->adapter, ERROR,
1122 "getting data rate error\n");
1123 goto done;
1124 }
1125
1126 /* Retrieve DTIM period value from firmware. */
1127 nxpwifi_get_802_11_snmp_mib(priv, DTIM_PERIOD_I, &priv->dtim_period);
1128
1129 nxpwifi_parse_htinfo(priv, priv->tx_rate, priv->tx_htinfo,
1130 &sinfo->txrate);
1131
1132 sinfo->signal_avg = priv->bcn_rssi_avg;
1133 sinfo->rx_bytes = priv->stats.rx_bytes;
1134 sinfo->tx_bytes = priv->stats.tx_bytes;
1135 sinfo->rx_packets = priv->stats.rx_packets;
1136 sinfo->tx_packets = priv->stats.tx_packets;
1137 sinfo->signal = priv->bcn_rssi_avg;
1138 /* Convert bitrate from 500 kb/s units to 100 kb/s units. */
1139 sinfo->txrate.legacy = rate * 5;
1140
1141 sinfo->filled |= BIT(NL80211_STA_INFO_RX_BITRATE);
1142 nxpwifi_parse_htinfo(priv, priv->rxpd_rate, priv->rxpd_htinfo,
1143 &sinfo->rxrate);
1144
1145 if (priv->bss_mode == NL80211_IFTYPE_STATION) {
1146 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_BSS_PARAM);
1147 sinfo->bss_param.flags = 0;
1148 if (priv->curr_bss_params.bss_descriptor.cap_info_bitmap &
1149 WLAN_CAPABILITY_SHORT_PREAMBLE)
1150 sinfo->bss_param.flags |=
1151 BSS_PARAM_FLAGS_SHORT_PREAMBLE;
1152 if (priv->curr_bss_params.bss_descriptor.cap_info_bitmap &
1153 WLAN_CAPABILITY_SHORT_SLOT_TIME)
1154 sinfo->bss_param.flags |=
1155 BSS_PARAM_FLAGS_SHORT_SLOT_TIME;
1156 sinfo->bss_param.dtim_period = priv->dtim_period;
1157 sinfo->bss_param.beacon_interval =
1158 priv->curr_bss_params.bss_descriptor.beacon_period;
1159 }
1160
1161 done:
1162 return ret;
1163 }
1164
1165 /*
1166 * cfg80211 op: get station information.
1167 * Works only when connected and fills station_info with current stats.
1168 */
1169 static int
nxpwifi_cfg80211_get_station(struct wiphy * wiphy,struct wireless_dev * wdev,const u8 * mac,struct station_info * sinfo)1170 nxpwifi_cfg80211_get_station(struct wiphy *wiphy, struct wireless_dev *wdev,
1171 const u8 *mac, struct station_info *sinfo)
1172 {
1173 struct nxpwifi_private *priv = nxpwifi_netdev_get_priv(wdev->netdev);
1174 struct nxpwifi_sta_node *node;
1175
1176 if (GET_BSS_ROLE(priv) == NXPWIFI_BSS_ROLE_STA) {
1177 if (!priv->media_connected ||
1178 memcmp(mac, priv->cfg_bssid, ETH_ALEN))
1179 return -ENOENT;
1180 node = NULL;
1181 } else {
1182 rcu_read_lock();
1183 node = nxpwifi_get_sta_entry(priv, mac);
1184 rcu_read_unlock();
1185 }
1186
1187 return nxpwifi_dump_station_info(priv, node, sinfo);
1188 }
1189
1190 /* cfg80211 operation handler to dump station information. */
1191 static int
nxpwifi_cfg80211_dump_station(struct wiphy * wiphy,struct wireless_dev * wdev,int idx,u8 * mac,struct station_info * sinfo)1192 nxpwifi_cfg80211_dump_station(struct wiphy *wiphy, struct wireless_dev *wdev,
1193 int idx, u8 *mac, struct station_info *sinfo)
1194 {
1195 struct nxpwifi_private *priv = nxpwifi_netdev_get_priv(wdev->netdev);
1196 struct nxpwifi_sta_node *node;
1197 struct nxpwifi_sta_node *found = NULL;
1198 int i;
1199
1200 if ((GET_BSS_ROLE(priv) == NXPWIFI_BSS_ROLE_STA) &&
1201 priv->media_connected && idx == 0) {
1202 ether_addr_copy(mac, priv->cfg_bssid);
1203 return nxpwifi_dump_station_info(priv, NULL, sinfo);
1204 } else if (GET_BSS_ROLE(priv) == NXPWIFI_BSS_ROLE_UAP) {
1205 nxpwifi_ap_get_sta_list(priv);
1206
1207 i = 0;
1208 rcu_read_lock();
1209 list_for_each_entry_rcu(node, &priv->sta_list, list) {
1210 if (i++ != idx)
1211 continue;
1212 found = node;
1213 break;
1214 }
1215 rcu_read_unlock();
1216
1217 if (found) {
1218 ether_addr_copy(mac, node->mac_addr);
1219 return nxpwifi_dump_station_info(priv, node, sinfo);
1220 }
1221 }
1222
1223 return -ENOENT;
1224 }
1225
1226 static int
nxpwifi_cfg80211_dump_survey(struct wiphy * wiphy,struct net_device * dev,int idx,struct survey_info * survey)1227 nxpwifi_cfg80211_dump_survey(struct wiphy *wiphy, struct net_device *dev,
1228 int idx, struct survey_info *survey)
1229 {
1230 struct nxpwifi_private *priv = nxpwifi_netdev_get_priv(dev);
1231 struct nxpwifi_chan_stats *pchan_stats = priv->adapter->chan_stats;
1232 enum nl80211_band band;
1233 u8 chan_num;
1234
1235 nxpwifi_dbg(priv->adapter, DUMP, "dump_survey idx=%d\n", idx);
1236
1237 memset(survey, 0, sizeof(struct survey_info));
1238
1239 if ((GET_BSS_ROLE(priv) == NXPWIFI_BSS_ROLE_STA) &&
1240 priv->media_connected && idx == 0) {
1241 u8 curr_bss_band = priv->curr_bss_params.band;
1242 u32 chan = priv->curr_bss_params.bss_descriptor.channel;
1243
1244 band = nxpwifi_band_to_radio_type(curr_bss_band);
1245 survey->channel = ieee80211_get_channel
1246 (wiphy,
1247 ieee80211_channel_to_frequency(chan, band));
1248
1249 if (priv->bcn_nf_last) {
1250 survey->filled = SURVEY_INFO_NOISE_DBM;
1251 survey->noise = priv->bcn_nf_last;
1252 }
1253 return 0;
1254 }
1255
1256 if (idx >= priv->adapter->num_in_chan_stats)
1257 return -ENOENT;
1258
1259 if (!pchan_stats[idx].cca_scan_dur)
1260 return 0;
1261
1262 band = pchan_stats[idx].bandcfg;
1263 chan_num = pchan_stats[idx].chan_num;
1264 survey->channel = ieee80211_get_channel
1265 (wiphy,
1266 ieee80211_channel_to_frequency(chan_num, band));
1267 survey->filled = SURVEY_INFO_NOISE_DBM |
1268 SURVEY_INFO_TIME |
1269 SURVEY_INFO_TIME_BUSY;
1270 survey->noise = pchan_stats[idx].noise;
1271 survey->time = pchan_stats[idx].cca_scan_dur;
1272 survey->time_busy = pchan_stats[idx].cca_busy_dur;
1273
1274 return 0;
1275 }
1276
1277 /* Supported rates to be advertised to the cfg80211 */
1278 static struct ieee80211_rate nxpwifi_rates[] = {
1279 {.bitrate = 10, .hw_value = 2, },
1280 {.bitrate = 20, .hw_value = 4, },
1281 {.bitrate = 55, .hw_value = 11, },
1282 {.bitrate = 110, .hw_value = 22, },
1283 {.bitrate = 60, .hw_value = 12, },
1284 {.bitrate = 90, .hw_value = 18, },
1285 {.bitrate = 120, .hw_value = 24, },
1286 {.bitrate = 180, .hw_value = 36, },
1287 {.bitrate = 240, .hw_value = 48, },
1288 {.bitrate = 360, .hw_value = 72, },
1289 {.bitrate = 480, .hw_value = 96, },
1290 {.bitrate = 540, .hw_value = 108, },
1291 };
1292
1293 /* Channel definitions to be advertised to cfg80211 */
1294 static struct ieee80211_channel nxpwifi_channels_2ghz[] = {
1295 {.center_freq = 2412, .hw_value = 1, },
1296 {.center_freq = 2417, .hw_value = 2, },
1297 {.center_freq = 2422, .hw_value = 3, },
1298 {.center_freq = 2427, .hw_value = 4, },
1299 {.center_freq = 2432, .hw_value = 5, },
1300 {.center_freq = 2437, .hw_value = 6, },
1301 {.center_freq = 2442, .hw_value = 7, },
1302 {.center_freq = 2447, .hw_value = 8, },
1303 {.center_freq = 2452, .hw_value = 9, },
1304 {.center_freq = 2457, .hw_value = 10, },
1305 {.center_freq = 2462, .hw_value = 11, },
1306 {.center_freq = 2467, .hw_value = 12, },
1307 {.center_freq = 2472, .hw_value = 13, },
1308 {.center_freq = 2484, .hw_value = 14, },
1309 };
1310
1311 static struct ieee80211_supported_band nxpwifi_band_2ghz = {
1312 .band = NL80211_BAND_2GHZ,
1313 .channels = nxpwifi_channels_2ghz,
1314 .n_channels = ARRAY_SIZE(nxpwifi_channels_2ghz),
1315 .bitrates = nxpwifi_rates,
1316 .n_bitrates = ARRAY_SIZE(nxpwifi_rates),
1317 };
1318
1319 static struct ieee80211_channel nxpwifi_channels_5ghz[] = {
1320 {.center_freq = 5040, .hw_value = 8, },
1321 {.center_freq = 5060, .hw_value = 12, },
1322 {.center_freq = 5080, .hw_value = 16, },
1323 {.center_freq = 5170, .hw_value = 34, },
1324 {.center_freq = 5190, .hw_value = 38, },
1325 {.center_freq = 5210, .hw_value = 42, },
1326 {.center_freq = 5230, .hw_value = 46, },
1327 {.center_freq = 5180, .hw_value = 36, },
1328 {.center_freq = 5200, .hw_value = 40, },
1329 {.center_freq = 5220, .hw_value = 44, },
1330 {.center_freq = 5240, .hw_value = 48, },
1331 {.center_freq = 5260, .hw_value = 52, },
1332 {.center_freq = 5280, .hw_value = 56, },
1333 {.center_freq = 5300, .hw_value = 60, },
1334 {.center_freq = 5320, .hw_value = 64, },
1335 {.center_freq = 5500, .hw_value = 100, },
1336 {.center_freq = 5520, .hw_value = 104, },
1337 {.center_freq = 5540, .hw_value = 108, },
1338 {.center_freq = 5560, .hw_value = 112, },
1339 {.center_freq = 5580, .hw_value = 116, },
1340 {.center_freq = 5600, .hw_value = 120, },
1341 {.center_freq = 5620, .hw_value = 124, },
1342 {.center_freq = 5640, .hw_value = 128, },
1343 {.center_freq = 5660, .hw_value = 132, },
1344 {.center_freq = 5680, .hw_value = 136, },
1345 {.center_freq = 5700, .hw_value = 140, },
1346 {.center_freq = 5745, .hw_value = 149, },
1347 {.center_freq = 5765, .hw_value = 153, },
1348 {.center_freq = 5785, .hw_value = 157, },
1349 {.center_freq = 5805, .hw_value = 161, },
1350 {.center_freq = 5825, .hw_value = 165, },
1351 };
1352
1353 static struct ieee80211_supported_band nxpwifi_band_5ghz = {
1354 .band = NL80211_BAND_5GHZ,
1355 .channels = nxpwifi_channels_5ghz,
1356 .n_channels = ARRAY_SIZE(nxpwifi_channels_5ghz),
1357 .bitrates = nxpwifi_rates + 4,
1358 .n_bitrates = ARRAY_SIZE(nxpwifi_rates) - 4,
1359 };
1360
1361 /* Supported crypto cipher suits to be advertised to cfg80211 */
1362 static const u32 nxpwifi_cipher_suites[] = {
1363 WLAN_CIPHER_SUITE_WEP40,
1364 WLAN_CIPHER_SUITE_WEP104,
1365 WLAN_CIPHER_SUITE_TKIP,
1366 WLAN_CIPHER_SUITE_CCMP,
1367 WLAN_CIPHER_SUITE_SMS4,
1368 WLAN_CIPHER_SUITE_AES_CMAC,
1369 WLAN_CIPHER_SUITE_GCMP_256,
1370 WLAN_CIPHER_SUITE_CCMP_256,
1371 WLAN_CIPHER_SUITE_BIP_GMAC_256,
1372 WLAN_CIPHER_SUITE_BIP_CMAC_256,
1373 };
1374
1375 /* Supported mgmt frame types to be advertised to cfg80211 */
1376 static const struct ieee80211_txrx_stypes
1377 nxpwifi_mgmt_stypes[NUM_NL80211_IFTYPES] = {
1378 [NL80211_IFTYPE_STATION] = {
1379 .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
1380 BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
1381 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
1382 BIT(IEEE80211_STYPE_PROBE_REQ >> 4),
1383 },
1384 [NL80211_IFTYPE_AP] = {
1385 .tx = 0xffff,
1386 .rx = BIT(IEEE80211_STYPE_ASSOC_REQ >> 4) |
1387 BIT(IEEE80211_STYPE_REASSOC_REQ >> 4) |
1388 BIT(IEEE80211_STYPE_PROBE_REQ >> 4) |
1389 BIT(IEEE80211_STYPE_DISASSOC >> 4) |
1390 BIT(IEEE80211_STYPE_AUTH >> 4) |
1391 BIT(IEEE80211_STYPE_DEAUTH >> 4) |
1392 BIT(IEEE80211_STYPE_ACTION >> 4),
1393 },
1394 };
1395
1396 /*
1397 * cfg80211 op: set bitrate mask.
1398 * Converts cfg80211 bitrate selections into firmware bitmap format.
1399 */
1400 static int
nxpwifi_cfg80211_set_bitrate_mask(struct wiphy * wiphy,struct net_device * dev,unsigned int link_id,const u8 * peer,const struct cfg80211_bitrate_mask * mask)1401 nxpwifi_cfg80211_set_bitrate_mask(struct wiphy *wiphy,
1402 struct net_device *dev,
1403 unsigned int link_id,
1404 const u8 *peer,
1405 const struct cfg80211_bitrate_mask *mask)
1406 {
1407 struct nxpwifi_private *priv = nxpwifi_netdev_get_priv(dev);
1408 u16 bitmap_rates[MAX_BITMAP_RATES_SIZE];
1409 enum nl80211_band band;
1410 struct nxpwifi_adapter *adapter = priv->adapter;
1411
1412 if (!priv->media_connected) {
1413 nxpwifi_dbg(adapter, ERROR,
1414 "Can not set Tx data rate in disconnected state\n");
1415 return -EINVAL;
1416 }
1417
1418 band = nxpwifi_band_to_radio_type(priv->curr_bss_params.band);
1419
1420 memset(bitmap_rates, 0, sizeof(bitmap_rates));
1421
1422 /* Fill HR/DSSS legacy rates (2.4 GHz only). */
1423 if (band == NL80211_BAND_2GHZ)
1424 bitmap_rates[0] = mask->control[band].legacy & 0x000f;
1425
1426 /* Fill OFDM legacy rates. */
1427 if (band == NL80211_BAND_2GHZ)
1428 bitmap_rates[1] = (mask->control[band].legacy & 0x0ff0) >> 4;
1429 else
1430 bitmap_rates[1] = mask->control[band].legacy;
1431
1432 /* Fill HT MCS bitmap (1x1 or 2x2 depending on hardware). */
1433 bitmap_rates[2] = mask->control[band].ht_mcs[0];
1434 if (adapter->hw_dev_mcs_support == HT_STREAM_2X2)
1435 bitmap_rates[2] |= mask->control[band].ht_mcs[1] << 8;
1436
1437 /* Fill VHT MCS bitmap if supported by firmware. */
1438 if (adapter->fw_api_ver == NXPWIFI_FW_V15) {
1439 bitmap_rates[10] = mask->control[band].vht_mcs[0];
1440 if (adapter->hw_dev_mcs_support == HT_STREAM_2X2)
1441 bitmap_rates[11] = mask->control[band].vht_mcs[1];
1442 }
1443
1444 return nxpwifi_set_tx_rate(priv, bitmap_rates);
1445 }
1446
1447 /*
1448 * cfg80211 op: configure connection-quality monitoring.
1449 * Subscribes or unsubscribes HIGH_RSSI and LOW_RSSI events to firmware.
1450 */
nxpwifi_cfg80211_set_cqm_rssi_config(struct wiphy * wiphy,struct net_device * dev,s32 rssi_thold,u32 rssi_hyst)1451 static int nxpwifi_cfg80211_set_cqm_rssi_config(struct wiphy *wiphy,
1452 struct net_device *dev,
1453 s32 rssi_thold, u32 rssi_hyst)
1454 {
1455 struct nxpwifi_private *priv = nxpwifi_netdev_get_priv(dev);
1456 struct nxpwifi_ds_misc_subsc_evt subsc_evt;
1457 int ret = 0;
1458
1459 priv->cqm_rssi_thold = rssi_thold;
1460 priv->cqm_rssi_hyst = rssi_hyst;
1461
1462 memset(&subsc_evt, 0x00, sizeof(struct nxpwifi_ds_misc_subsc_evt));
1463 subsc_evt.events = BITMASK_BCN_RSSI_LOW | BITMASK_BCN_RSSI_HIGH;
1464
1465 /* Subscribe/unsubscribe low and high rssi events */
1466 if (rssi_thold && rssi_hyst) {
1467 subsc_evt.action = HOST_ACT_BITWISE_SET;
1468 subsc_evt.bcn_l_rssi_cfg.abs_value = abs(rssi_thold);
1469 subsc_evt.bcn_h_rssi_cfg.abs_value = abs(rssi_thold);
1470 subsc_evt.bcn_l_rssi_cfg.evt_freq = 1;
1471 subsc_evt.bcn_h_rssi_cfg.evt_freq = 1;
1472 ret = nxpwifi_802_11_subscribe_event(priv, &subsc_evt);
1473 } else {
1474 subsc_evt.action = HOST_ACT_BITWISE_CLR;
1475 ret = nxpwifi_802_11_subscribe_event(priv, &subsc_evt);
1476 }
1477
1478 return ret;
1479 }
1480
1481 /*
1482 * cfg80211 operation handler for change_beacon.
1483 * Function retrieves and sets modified management IEs to FW.
1484 */
nxpwifi_cfg80211_change_beacon(struct wiphy * wiphy,struct net_device * dev,struct cfg80211_ap_update * params)1485 int nxpwifi_cfg80211_change_beacon(struct wiphy *wiphy,
1486 struct net_device *dev,
1487 struct cfg80211_ap_update *params)
1488 {
1489 struct nxpwifi_private *priv = nxpwifi_netdev_get_priv(dev);
1490 struct nxpwifi_adapter *adapter = priv->adapter;
1491 struct cfg80211_beacon_data *data = ¶ms->beacon;
1492 int ret;
1493
1494 nxpwifi_cancel_scan(adapter);
1495
1496 if (GET_BSS_ROLE(priv) != NXPWIFI_BSS_ROLE_UAP) {
1497 nxpwifi_dbg(priv->adapter, ERROR,
1498 "%s: bss_type mismatched\n", __func__);
1499 return -EINVAL;
1500 }
1501
1502 ret = nxpwifi_set_mgmt_ies(priv, data);
1503 if (ret)
1504 nxpwifi_dbg(priv->adapter, ERROR,
1505 "%s: setting mgmt ies failed\n", __func__);
1506
1507 return ret;
1508 }
1509
1510 /*
1511 * cfg80211 operation handler for del_station.
1512 * Function deauthenticates station which value is provided in mac parameter.
1513 * If mac is NULL/broadcast, all stations in associated station list are
1514 * deauthenticated. If bss is not started or there are no stations in
1515 * associated stations list, no action is taken.
1516 */
1517 static int
nxpwifi_cfg80211_del_station(struct wiphy * wiphy,struct wireless_dev * wdev,struct station_del_parameters * params)1518 nxpwifi_cfg80211_del_station(struct wiphy *wiphy, struct wireless_dev *wdev,
1519 struct station_del_parameters *params)
1520 {
1521 struct nxpwifi_private *priv = nxpwifi_netdev_get_priv(wdev->netdev);
1522 struct nxpwifi_sta_node *sta_node;
1523 u8 deauth_mac[ETH_ALEN];
1524 int ret = 0;
1525
1526 if (!priv->bss_started && priv->wdev.links[0].cac_started) {
1527 nxpwifi_dbg(priv->adapter, INFO, "%s: abort CAC!\n", __func__);
1528 nxpwifi_abort_cac(priv);
1529 }
1530
1531 if (list_empty(&priv->sta_list) || !priv->bss_started)
1532 return 0;
1533
1534 if (!params->mac || is_broadcast_ether_addr(params->mac))
1535 return 0;
1536
1537 nxpwifi_dbg(priv->adapter, INFO, "%s: mac address %pM\n",
1538 __func__, params->mac);
1539
1540 eth_zero_addr(deauth_mac);
1541
1542 sta_node = nxpwifi_get_sta_entry(priv, params->mac);
1543 if (sta_node)
1544 ether_addr_copy(deauth_mac, params->mac);
1545
1546 if (is_valid_ether_addr(deauth_mac)) {
1547 ret = nxpwifi_uap_sta_deauth(priv, deauth_mac);
1548 nxpwifi_del_sta_entry(priv, deauth_mac);
1549 }
1550 return ret;
1551 }
1552
1553 static int
nxpwifi_cfg80211_set_antenna(struct wiphy * wiphy,int radio_idx,u32 tx_ant,u32 rx_ant)1554 nxpwifi_cfg80211_set_antenna(struct wiphy *wiphy, int radio_idx, u32 tx_ant, u32 rx_ant)
1555 {
1556 struct nxpwifi_adapter *adapter = nxpwifi_cfg80211_get_adapter(wiphy);
1557 struct nxpwifi_private *priv = nxpwifi_get_priv(adapter,
1558 NXPWIFI_BSS_ROLE_ANY);
1559 struct nxpwifi_ds_ant_cfg ant_cfg;
1560
1561 if (!tx_ant || !rx_ant)
1562 return -EOPNOTSUPP;
1563
1564 if (adapter->hw_dev_mcs_support != HT_STREAM_2X2) {
1565 /*
1566 * Not a MIMO chip. User should provide specific antenna number
1567 * for Tx/Rx path or enable all antennas for diversity
1568 */
1569 if (tx_ant != rx_ant)
1570 return -EOPNOTSUPP;
1571
1572 if ((tx_ant & (tx_ant - 1)) &&
1573 (tx_ant != BIT(adapter->number_of_antenna) - 1))
1574 return -EOPNOTSUPP;
1575
1576 if ((tx_ant == BIT(adapter->number_of_antenna) - 1) &&
1577 priv->adapter->number_of_antenna > 1) {
1578 tx_ant = RF_ANTENNA_AUTO;
1579 rx_ant = RF_ANTENNA_AUTO;
1580 }
1581 } else {
1582 struct ieee80211_sta_ht_cap *ht_info;
1583 int rx_mcs_supp;
1584 enum nl80211_band band;
1585
1586 if ((tx_ant == 0x1 && rx_ant == 0x1)) {
1587 adapter->user_dev_mcs_support = HT_STREAM_1X1;
1588 if (adapter->is_hw_11ac_capable)
1589 adapter->usr_dot_11ac_mcs_support =
1590 NXPWIFI_11AC_MCS_MAP_1X1;
1591 } else {
1592 adapter->user_dev_mcs_support = HT_STREAM_2X2;
1593 if (adapter->is_hw_11ac_capable)
1594 adapter->usr_dot_11ac_mcs_support =
1595 NXPWIFI_11AC_MCS_MAP_2X2;
1596 }
1597
1598 for (band = 0; band < NUM_NL80211_BANDS; band++) {
1599 if (!adapter->wiphy->bands[band])
1600 continue;
1601
1602 ht_info = &adapter->wiphy->bands[band]->ht_cap;
1603 rx_mcs_supp =
1604 GET_RXMCSSUPP(adapter->user_dev_mcs_support);
1605 memset(&ht_info->mcs, 0, adapter->number_of_antenna);
1606 memset(&ht_info->mcs, 0xff, rx_mcs_supp);
1607 }
1608 }
1609
1610 ant_cfg.tx_ant = tx_ant;
1611 ant_cfg.rx_ant = rx_ant;
1612
1613 return nxpwifi_set_rf_antenna(priv, &ant_cfg);
1614 }
1615
1616 static int
nxpwifi_cfg80211_get_antenna(struct wiphy * wiphy,int radio_idx,u32 * tx_ant,u32 * rx_ant)1617 nxpwifi_cfg80211_get_antenna(struct wiphy *wiphy, int radio_idx, u32 *tx_ant, u32 *rx_ant)
1618 {
1619 struct nxpwifi_adapter *adapter = nxpwifi_cfg80211_get_adapter(wiphy);
1620 struct nxpwifi_private *priv = nxpwifi_get_priv(adapter,
1621 NXPWIFI_BSS_ROLE_ANY);
1622 int ret;
1623
1624 ret = nxpwifi_get_rf_antenna(priv, tx_ant, rx_ant);
1625
1626 return ret;
1627 }
1628
1629 /*
1630 * cfg80211 op: stop AP.
1631 * Stops the BSS running on the uAP interface.
1632 */
nxpwifi_cfg80211_stop_ap(struct wiphy * wiphy,struct net_device * dev,unsigned int link_id)1633 static int nxpwifi_cfg80211_stop_ap(struct wiphy *wiphy, struct net_device *dev,
1634 unsigned int link_id)
1635 {
1636 struct nxpwifi_private *priv = nxpwifi_netdev_get_priv(dev);
1637 int ret;
1638
1639 nxpwifi_abort_cac(priv);
1640
1641 if (nxpwifi_del_mgmt_ies(priv))
1642 nxpwifi_dbg(priv->adapter, ERROR,
1643 "Failed to delete mgmt IEs!\n");
1644
1645 priv->ap_11n_enabled = 0;
1646 memset(&priv->bss_cfg, 0, sizeof(priv->bss_cfg));
1647
1648 ret = nxpwifi_ap_stop_bss(priv);
1649 if (ret) {
1650 nxpwifi_dbg(priv->adapter, ERROR,
1651 "Failed to stop the BSS\n");
1652 goto done;
1653 }
1654
1655 ret = nxpwifi_ap_sys_reset(priv);
1656 if (ret) {
1657 nxpwifi_dbg(priv->adapter, ERROR,
1658 "Failed to reset BSS\n");
1659 goto done;
1660 }
1661
1662 netif_carrier_off(priv->netdev);
1663 nxpwifi_stop_net_dev_queue(priv->netdev, priv->adapter);
1664
1665 if (atomic_dec_and_test(&priv->adapter->uap_count)) {
1666 priv->adapter->chandef_valid = false;
1667 memset(&priv->adapter->chandef, 0, sizeof(priv->adapter->chandef));
1668 }
1669
1670 done:
1671 return ret;
1672 }
1673
1674 /*
1675 * cfg80211 op: start AP.
1676 * Applies beacon/DTIM/SSID/security settings to the uAP configuration and
1677 * starts the BSS.
1678 */
nxpwifi_cfg80211_start_ap(struct wiphy * wiphy,struct net_device * dev,struct cfg80211_ap_settings * params)1679 static int nxpwifi_cfg80211_start_ap(struct wiphy *wiphy,
1680 struct net_device *dev,
1681 struct cfg80211_ap_settings *params)
1682 {
1683 struct nxpwifi_uap_bss_param *bss_cfg;
1684 struct nxpwifi_private *priv = nxpwifi_netdev_get_priv(dev);
1685 struct nxpwifi_adapter *adapter = priv->adapter;
1686 struct cfg80211_chan_def use_chandef;
1687 bool is_first_uap = false;
1688 int ret;
1689
1690 /*
1691 * Adapter is the HW channel owner (single PHY).
1692 * All UAP interfaces on the same adapter must share
1693 * the same RF channel.
1694 */
1695 use_chandef = params->chandef;
1696
1697 if (adapter->chandef_valid) {
1698 if (!cfg80211_chandef_identical(&adapter->chandef,
1699 ¶ms->chandef)) {
1700 nxpwifi_dbg(adapter, INFO,
1701 "UAP already running on channel %d, ignore requested channel %d\n",
1702 adapter->chandef.chan->hw_value,
1703 params->chandef.chan->hw_value);
1704 }
1705 use_chandef = adapter->chandef;
1706 } else {
1707 is_first_uap = true;
1708 }
1709
1710 if (GET_BSS_ROLE(priv) != NXPWIFI_BSS_ROLE_UAP)
1711 return -EINVAL;
1712
1713 if (!nxpwifi_is_channel_setting_allowable(priv, params->chandef.chan))
1714 return -EOPNOTSUPP;
1715
1716 bss_cfg = kzalloc_obj(*bss_cfg, GFP_KERNEL);
1717 if (!bss_cfg)
1718 return -ENOMEM;
1719
1720 nxpwifi_set_sys_config_invalid_data(bss_cfg);
1721
1722 memcpy(bss_cfg->mac_addr, priv->curr_addr, ETH_ALEN);
1723
1724 if (params->beacon_interval)
1725 bss_cfg->beacon_period = params->beacon_interval;
1726 if (params->dtim_period)
1727 bss_cfg->dtim_period = params->dtim_period;
1728
1729 if (params->ssid && params->ssid_len) {
1730 memcpy(bss_cfg->ssid.ssid, params->ssid, params->ssid_len);
1731 bss_cfg->ssid.ssid_len = params->ssid_len;
1732 }
1733 if (params->inactivity_timeout > 0) {
1734 /* sta_ao_timer/ps_sta_ao_timer is in unit of 100ms */
1735 bss_cfg->sta_ao_timer = 10 * params->inactivity_timeout;
1736 bss_cfg->ps_sta_ao_timer = 10 * params->inactivity_timeout;
1737 }
1738
1739 /* Default: SSID is visible */
1740 bss_cfg->bcast_ssid_ctl = NXPWIFI_BCAST_SSID_VISIBLE;
1741
1742 switch (params->hidden_ssid) {
1743 case NL80211_HIDDEN_SSID_NOT_IN_USE:
1744 bss_cfg->bcast_ssid_ctl = NXPWIFI_BCAST_SSID_VISIBLE;
1745 break;
1746 case NL80211_HIDDEN_SSID_ZERO_LEN:
1747 bss_cfg->bcast_ssid_ctl = NXPWIFI_BCAST_SSID_HIDE_LEN_ZERO;
1748 break;
1749 case NL80211_HIDDEN_SSID_ZERO_CONTENTS:
1750 bss_cfg->bcast_ssid_ctl = NXPWIFI_BCAST_SSID_HIDE_LEN_RETAIN;
1751 break;
1752 }
1753
1754 nxpwifi_uap_set_channel(priv, bss_cfg, use_chandef);
1755 nxpwifi_set_uap_rates(bss_cfg, params);
1756
1757 ret = nxpwifi_set_secure_params(priv, bss_cfg, params);
1758 if (ret) {
1759 nxpwifi_dbg(adapter, ERROR,
1760 "Failed to parse security parameters!\n");
1761 goto done;
1762 }
1763
1764 nxpwifi_set_ht_params(priv, bss_cfg, params);
1765
1766 if (adapter->is_hw_11ac_capable) {
1767 nxpwifi_set_vht_params(priv, bss_cfg, params);
1768 nxpwifi_set_vht_width(priv, use_chandef.width,
1769 priv->ap_11ac_enabled);
1770 }
1771
1772 if (priv->ap_11ac_enabled)
1773 nxpwifi_set_11ac_ba_params(priv);
1774 else
1775 nxpwifi_set_ba_params(priv);
1776
1777 if (adapter->is_hw_11ax_capable) {
1778 priv->ap_11ax_enabled =
1779 nxpwifi_check_11ax_capability(priv, bss_cfg, params);
1780 if (priv->ap_11ax_enabled)
1781 nxpwifi_set_11ax_status(priv, bss_cfg, params);
1782 }
1783
1784 nxpwifi_set_wmm_params(priv, bss_cfg, params);
1785
1786 if (nxpwifi_is_11h_active(priv))
1787 nxpwifi_set_tpc_params(priv, bss_cfg, params);
1788
1789 if (nxpwifi_is_11h_active(priv) &&
1790 !cfg80211_chandef_dfs_required(wiphy, ¶ms->chandef,
1791 priv->bss_mode)) {
1792 nxpwifi_dbg(priv->adapter, INFO,
1793 "Disable 11h extensions in FW\n");
1794 ret = nxpwifi_11h_activate(priv, false);
1795 if (ret) {
1796 nxpwifi_dbg(priv->adapter, ERROR,
1797 "Failed to disable 11h extensions!!");
1798 goto done;
1799 }
1800 priv->state_11h.is_11h_active = false;
1801 }
1802
1803 nxpwifi_config_uap_11d(priv, ¶ms->beacon);
1804
1805 ret = nxpwifi_set_mgmt_ies(priv, ¶ms->beacon);
1806 if (ret)
1807 goto done;
1808
1809 ret = nxpwifi_config_start_uap(priv, bss_cfg);
1810 if (ret) {
1811 nxpwifi_dbg(priv->adapter, ERROR,
1812 "Failed to start AP\n");
1813 goto done;
1814 }
1815
1816 /* First UAP records adapter-level HW channel */
1817 if (is_first_uap) {
1818 adapter->chandef = use_chandef;
1819 adapter->chandef_valid = true;
1820 }
1821 atomic_inc(&adapter->uap_count);
1822 netif_carrier_on(priv->netdev);
1823 nxpwifi_wake_up_net_dev_queue(priv->netdev, priv->adapter);
1824
1825 memcpy(&priv->bss_cfg, bss_cfg, sizeof(priv->bss_cfg));
1826
1827 done:
1828 kfree(bss_cfg);
1829 return ret;
1830 }
1831
1832 /*
1833 * cfg80211 op: handle scan request.
1834 * Issues a firmware scan using the requested parameters and reports the
1835 * results.
1836 */
1837 static int
nxpwifi_cfg80211_scan(struct wiphy * wiphy,struct cfg80211_scan_request * request)1838 nxpwifi_cfg80211_scan(struct wiphy *wiphy,
1839 struct cfg80211_scan_request *request)
1840 {
1841 struct net_device *dev = request->wdev->netdev;
1842 struct nxpwifi_private *priv = nxpwifi_netdev_get_priv(dev);
1843 int i, offset, ret;
1844 struct ieee80211_channel *chan;
1845 struct element *ie;
1846 struct nxpwifi_user_scan_cfg *user_scan_cfg;
1847 u8 mac_addr[ETH_ALEN];
1848
1849 nxpwifi_dbg(priv->adapter, CMD,
1850 "info: received scan request on %s\n", dev->name);
1851
1852 /*
1853 * Block scan requests during active scanning or scan cleanup.
1854 * Prevents new scans when the interface is disabled or teardown is in
1855 * progress.
1856 */
1857 if (priv->scan_request || priv->scan_aborting) {
1858 nxpwifi_dbg(priv->adapter, WARN,
1859 "cmd: Scan already in process..\n");
1860 return -EBUSY;
1861 }
1862
1863 if (!priv->wdev.connected && priv->scan_block)
1864 priv->scan_block = false;
1865
1866 if (!nxpwifi_stop_bg_scan(priv))
1867 cfg80211_sched_scan_stopped_locked(priv->wdev.wiphy, 0);
1868
1869 user_scan_cfg = kzalloc_obj(*user_scan_cfg, GFP_KERNEL);
1870 if (!user_scan_cfg)
1871 return -ENOMEM;
1872
1873 priv->scan_request = request;
1874
1875 if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) {
1876 get_random_mask_addr(mac_addr, request->mac_addr,
1877 request->mac_addr_mask);
1878 ether_addr_copy(request->mac_addr, mac_addr);
1879 ether_addr_copy(user_scan_cfg->random_mac, mac_addr);
1880 }
1881
1882 user_scan_cfg->num_ssids = request->n_ssids;
1883 user_scan_cfg->ssid_list = request->ssids;
1884
1885 if (request->ie && request->ie_len) {
1886 offset = 0;
1887 for (i = 0; i < NXPWIFI_MAX_VSIE_NUM; i++) {
1888 if (priv->vs_ie[i].mask != NXPWIFI_VSIE_MASK_CLEAR)
1889 continue;
1890 priv->vs_ie[i].mask = NXPWIFI_VSIE_MASK_SCAN;
1891 ie = (struct element *)(request->ie + offset);
1892 memcpy(&priv->vs_ie[i].ie, ie,
1893 sizeof(*ie) + ie->datalen);
1894 offset += sizeof(*ie) + ie->datalen;
1895
1896 if (offset >= request->ie_len)
1897 break;
1898 }
1899 }
1900
1901 for (i = 0; i < min_t(u32, request->n_channels,
1902 NXPWIFI_USER_SCAN_CHAN_MAX); i++) {
1903 chan = request->channels[i];
1904 user_scan_cfg->chan_list[i].chan_number = chan->hw_value;
1905 user_scan_cfg->chan_list[i].radio_type = chan->band;
1906
1907 if ((chan->flags & IEEE80211_CHAN_NO_IR) || !request->n_ssids)
1908 user_scan_cfg->chan_list[i].scan_type =
1909 NXPWIFI_SCAN_TYPE_PASSIVE;
1910 else
1911 user_scan_cfg->chan_list[i].scan_type =
1912 NXPWIFI_SCAN_TYPE_ACTIVE;
1913
1914 user_scan_cfg->chan_list[i].scan_time = 0;
1915 }
1916
1917 if (priv->adapter->scan_chan_gap_enabled &&
1918 nxpwifi_is_any_intf_active(priv))
1919 user_scan_cfg->scan_chan_gap =
1920 priv->adapter->scan_chan_gap_time;
1921
1922 ret = nxpwifi_scan_networks(priv, user_scan_cfg);
1923 kfree(user_scan_cfg);
1924 if (ret) {
1925 nxpwifi_dbg(priv->adapter, ERROR,
1926 "scan failed: %d\n", ret);
1927 priv->scan_aborting = false;
1928 priv->scan_request = NULL;
1929 return ret;
1930 }
1931
1932 if (request->ie && request->ie_len) {
1933 for (i = 0; i < NXPWIFI_MAX_VSIE_NUM; i++) {
1934 if (priv->vs_ie[i].mask == NXPWIFI_VSIE_MASK_SCAN) {
1935 priv->vs_ie[i].mask = NXPWIFI_VSIE_MASK_CLEAR;
1936 memset(&priv->vs_ie[i].ie, 0,
1937 NXPWIFI_MAX_VSIE_LEN);
1938 }
1939 }
1940 }
1941 return 0;
1942 }
1943
1944 /*
1945 * cfg80211 sched_scan_start handler.
1946 *
1947 * Send a bgscan configuration request to the firmware based on the
1948 * scheduled scan parameters. On success, the firmware later issues a
1949 * BGSCAN_REPORT event, after which the driver should query the firmware
1950 * for scan results.
1951 */
1952 static int
nxpwifi_cfg80211_sched_scan_start(struct wiphy * wiphy,struct net_device * dev,struct cfg80211_sched_scan_request * request)1953 nxpwifi_cfg80211_sched_scan_start(struct wiphy *wiphy,
1954 struct net_device *dev,
1955 struct cfg80211_sched_scan_request *request)
1956 {
1957 struct nxpwifi_private *priv = nxpwifi_netdev_get_priv(dev);
1958 int i, offset;
1959 struct ieee80211_channel *chan;
1960 struct nxpwifi_bg_scan_cfg *bgscan_cfg;
1961 struct element *ie;
1962 int ret;
1963
1964 if (!request || (!request->n_ssids && !request->n_match_sets)) {
1965 wiphy_err(wiphy, "%s : Invalid Sched_scan parameters",
1966 __func__);
1967 return -EINVAL;
1968 }
1969
1970 wiphy_info(wiphy, "sched_scan start : n_ssids=%d n_match_sets=%d ",
1971 request->n_ssids, request->n_match_sets);
1972 wiphy_info(wiphy, "n_channels=%d interval=%d ie_len=%d\n",
1973 request->n_channels, request->scan_plans->interval,
1974 (int)request->ie_len);
1975
1976 bgscan_cfg = kzalloc_obj(*bgscan_cfg, GFP_KERNEL);
1977 if (!bgscan_cfg)
1978 return -ENOMEM;
1979
1980 if (priv->scan_request || priv->scan_aborting)
1981 bgscan_cfg->start_later = true;
1982
1983 bgscan_cfg->num_ssids = request->n_match_sets;
1984 bgscan_cfg->ssid_list = request->match_sets;
1985
1986 if (request->ie && request->ie_len) {
1987 offset = 0;
1988 for (i = 0; i < NXPWIFI_MAX_VSIE_NUM; i++) {
1989 if (priv->vs_ie[i].mask != NXPWIFI_VSIE_MASK_CLEAR)
1990 continue;
1991 priv->vs_ie[i].mask = NXPWIFI_VSIE_MASK_BGSCAN;
1992 ie = (struct element *)(request->ie + offset);
1993 memcpy(&priv->vs_ie[i].ie, ie,
1994 sizeof(*ie) + ie->datalen);
1995 offset += sizeof(*ie) + ie->datalen;
1996
1997 if (offset >= request->ie_len)
1998 break;
1999 }
2000 }
2001
2002 for (i = 0; i < min_t(u32, request->n_channels,
2003 NXPWIFI_BG_SCAN_CHAN_MAX); i++) {
2004 chan = request->channels[i];
2005 bgscan_cfg->chan_list[i].chan_number = chan->hw_value;
2006 bgscan_cfg->chan_list[i].radio_type = chan->band;
2007
2008 if ((chan->flags & IEEE80211_CHAN_NO_IR) || !request->n_ssids)
2009 bgscan_cfg->chan_list[i].scan_type =
2010 NXPWIFI_SCAN_TYPE_PASSIVE;
2011 else
2012 bgscan_cfg->chan_list[i].scan_type =
2013 NXPWIFI_SCAN_TYPE_ACTIVE;
2014
2015 bgscan_cfg->chan_list[i].scan_time = 0;
2016 }
2017
2018 bgscan_cfg->chan_per_scan = min_t(u32, request->n_channels,
2019 NXPWIFI_BG_SCAN_CHAN_MAX);
2020
2021 /* Minimum scan cycle duration: 15 seconds */
2022 bgscan_cfg->scan_interval = (request->scan_plans->interval >
2023 NXPWIFI_BGSCAN_INTERVAL) ?
2024 request->scan_plans->interval :
2025 NXPWIFI_BGSCAN_INTERVAL;
2026
2027 bgscan_cfg->repeat_count = NXPWIFI_BGSCAN_REPEAT_COUNT;
2028 bgscan_cfg->report_condition = NXPWIFI_BGSCAN_SSID_MATCH |
2029 NXPWIFI_BGSCAN_WAIT_ALL_CHAN_DONE;
2030 bgscan_cfg->bss_type = NXPWIFI_BSS_MODE_INFRA;
2031 bgscan_cfg->action = NXPWIFI_BGSCAN_ACT_SET;
2032 bgscan_cfg->enable = true;
2033 if (request->min_rssi_thold != NL80211_SCAN_RSSI_THOLD_OFF) {
2034 bgscan_cfg->report_condition |= NXPWIFI_BGSCAN_SSID_RSSI_MATCH;
2035 bgscan_cfg->rssi_threshold = request->min_rssi_thold;
2036 }
2037
2038 ret = nxpwifi_bg_scan_config(priv, bgscan_cfg);
2039
2040 if (!ret)
2041 priv->sched_scanning = true;
2042
2043 kfree(bgscan_cfg);
2044 return ret;
2045 }
2046
2047 /*
2048 * cfg80211 sched_scan_stop handler.
2049 *
2050 * Send a bgscan configuration command to disable the previous
2051 * background scan settings in the firmware.
2052 */
nxpwifi_cfg80211_sched_scan_stop(struct wiphy * wiphy,struct net_device * dev,u64 reqid)2053 static int nxpwifi_cfg80211_sched_scan_stop(struct wiphy *wiphy,
2054 struct net_device *dev, u64 reqid)
2055 {
2056 struct nxpwifi_private *priv = nxpwifi_netdev_get_priv(dev);
2057
2058 wiphy_info(wiphy, "sched scan stop!");
2059 return nxpwifi_stop_bg_scan(priv);
2060 }
2061
2062 /*
2063 * Set default cfg80211 HT capabilities.
2064 */
2065 static void
nxpwifi_setup_ht_caps(struct nxpwifi_private * priv,struct ieee80211_sta_ht_cap * ht_info)2066 nxpwifi_setup_ht_caps(struct nxpwifi_private *priv,
2067 struct ieee80211_sta_ht_cap *ht_info)
2068 {
2069 int rx_mcs_supp;
2070 struct ieee80211_mcs_info mcs_set;
2071 u8 *mcs = (u8 *)&mcs_set;
2072 struct nxpwifi_adapter *adapter = priv->adapter;
2073
2074 ht_info->ht_supported = true;
2075 ht_info->ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
2076 ht_info->ampdu_density = IEEE80211_HT_MPDU_DENSITY_NONE;
2077
2078 memset(&ht_info->mcs, 0, sizeof(ht_info->mcs));
2079
2080 /* Fill HT capability information */
2081 if (ISSUPP_CHANWIDTH40(adapter->hw_dot_11n_dev_cap))
2082 ht_info->cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
2083 else
2084 ht_info->cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
2085
2086 if (ISSUPP_SHORTGI20(adapter->hw_dot_11n_dev_cap))
2087 ht_info->cap |= IEEE80211_HT_CAP_SGI_20;
2088 else
2089 ht_info->cap &= ~IEEE80211_HT_CAP_SGI_20;
2090
2091 if (ISSUPP_SHORTGI40(adapter->hw_dot_11n_dev_cap))
2092 ht_info->cap |= IEEE80211_HT_CAP_SGI_40;
2093 else
2094 ht_info->cap &= ~IEEE80211_HT_CAP_SGI_40;
2095
2096 if (adapter->user_dev_mcs_support == HT_STREAM_2X2)
2097 ht_info->cap |= 2 << IEEE80211_HT_CAP_RX_STBC_SHIFT;
2098 else
2099 ht_info->cap |= 1 << IEEE80211_HT_CAP_RX_STBC_SHIFT;
2100
2101 if (ISSUPP_TXSTBC(adapter->hw_dot_11n_dev_cap))
2102 ht_info->cap |= IEEE80211_HT_CAP_TX_STBC;
2103 else
2104 ht_info->cap &= ~IEEE80211_HT_CAP_TX_STBC;
2105
2106 if (ISSUPP_GREENFIELD(adapter->hw_dot_11n_dev_cap))
2107 ht_info->cap |= IEEE80211_HT_CAP_GRN_FLD;
2108 else
2109 ht_info->cap &= ~IEEE80211_HT_CAP_GRN_FLD;
2110
2111 if (ISENABLED_40MHZ_INTOLERANT(adapter->hw_dot_11n_dev_cap))
2112 ht_info->cap |= IEEE80211_HT_CAP_40MHZ_INTOLERANT;
2113 else
2114 ht_info->cap &= ~IEEE80211_HT_CAP_40MHZ_INTOLERANT;
2115
2116 if (ISSUPP_RXLDPC(adapter->hw_dot_11n_dev_cap))
2117 ht_info->cap |= IEEE80211_HT_CAP_LDPC_CODING;
2118 else
2119 ht_info->cap &= ~IEEE80211_HT_CAP_LDPC_CODING;
2120
2121 ht_info->cap &= ~IEEE80211_HT_CAP_MAX_AMSDU;
2122 ht_info->cap |= IEEE80211_HT_CAP_SM_PS;
2123
2124 rx_mcs_supp = GET_RXMCSSUPP(adapter->user_dev_mcs_support);
2125 /* Set MCS for 1x1/2x2 */
2126 memset(mcs, 0xff, rx_mcs_supp);
2127 /* Clear all the other values */
2128 memset(&mcs[rx_mcs_supp], 0,
2129 sizeof(struct ieee80211_mcs_info) - rx_mcs_supp);
2130 if (priv->bss_mode == NL80211_IFTYPE_STATION ||
2131 ISSUPP_CHANWIDTH40(adapter->hw_dot_11n_dev_cap))
2132 /* Set MCS32 for infra mode or ad-hoc mode with 40MHz support */
2133 SETHT_MCS32(mcs_set.rx_mask);
2134
2135 memcpy((u8 *)&ht_info->mcs, mcs, sizeof(struct ieee80211_mcs_info));
2136
2137 ht_info->mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED;
2138 }
2139
2140 static void
nxpwifi_setup_vht_caps(struct nxpwifi_private * priv,struct ieee80211_sta_vht_cap * vht_info)2141 nxpwifi_setup_vht_caps(struct nxpwifi_private *priv,
2142 struct ieee80211_sta_vht_cap *vht_info)
2143 {
2144 struct nxpwifi_adapter *adapter = priv->adapter;
2145
2146 vht_info->vht_supported = true;
2147
2148 vht_info->cap = adapter->hw_dot_11ac_dev_cap;
2149 /* Update MCS support for VHT */
2150 vht_info->vht_mcs.rx_mcs_map =
2151 cpu_to_le16(adapter->hw_dot_11ac_mcs_support & 0xFFFF);
2152 vht_info->vht_mcs.rx_highest = 0;
2153 vht_info->vht_mcs.tx_mcs_map =
2154 cpu_to_le16(adapter->hw_dot_11ac_mcs_support >> 16);
2155 vht_info->vht_mcs.tx_highest = 0;
2156 }
2157
2158 /*
2159 * 5 GHz HE capability masks for UAP mode.
2160 *
2161 * MAC: TWT requester/respondor, broadcast TWT, OMI control.
2162 *
2163 * PHY: 40/80 MHz width, puncturing, LDPC, NDP 4xLTF, STBC,
2164 * Doppler, DCM, SU BF/BFe, STS, sounding dims, extended
2165 * range, PPE present, 4xLTF 0.8us GI, Rx 1024-QAM.
2166 */
2167 #define UAP_HE_MAC_CAP0_MASK (IEEE80211_HE_MAC_CAP0_TWT_REQ | \
2168 IEEE80211_HE_MAC_CAP0_TWT_RES)
2169
2170 #define UAP_HE_MAC_CAP1_MASK 0
2171 #define UAP_HE_MAC_CAP2_MASK IEEE80211_HE_MAC_CAP2_BCAST_TWT
2172 #define UAP_HE_MAC_CAP3_MASK IEEE80211_HE_MAC_CAP3_OMI_CONTROL
2173 #define UAP_HE_MAC_CAP4_MASK 0
2174 #define UAP_HE_MAC_CAP5_MASK 0
2175
2176 #define UAP_HE_PHY_CAP0_MASK IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_40MHZ_80MHZ_IN_5G
2177 #define UAP_HE_PHY_CAP1_MASK (IEEE80211_HE_PHY_CAP1_LDPC_CODING_IN_PAYLOAD | \
2178 IEEE80211_HE_PHY_CAP1_PREAMBLE_PUNC_RX_80MHZ_ONLY_SECOND_20MHZ | \
2179 IEEE80211_HE_PHY_CAP1_PREAMBLE_PUNC_RX_80MHZ_ONLY_SECOND_40MHZ)
2180 #define UAP_HE_PHY_CAP2_MASK (IEEE80211_HE_PHY_CAP2_NDP_4x_LTF_AND_3_2US | \
2181 IEEE80211_HE_PHY_CAP2_STBC_TX_UNDER_80MHZ | \
2182 IEEE80211_HE_PHY_CAP2_STBC_RX_UNDER_80MHZ | \
2183 IEEE80211_HE_PHY_CAP2_DOPPLER_TX | \
2184 IEEE80211_HE_PHY_CAP2_DOPPLER_RX)
2185 #define UAP_HE_PHY_CAP3_MASK (IEEE80211_HE_PHY_CAP3_DCM_MAX_CONST_TX_BPSK | \
2186 IEEE80211_HE_PHY_CAP3_DCM_MAX_TX_NSS_1 | \
2187 IEEE80211_HE_PHY_CAP3_DCM_MAX_CONST_RX_BPSK | \
2188 IEEE80211_HE_PHY_CAP3_DCM_MAX_RX_NSS_1 | \
2189 IEEE80211_HE_PHY_CAP3_SU_BEAMFORMER)
2190 #define UAP_HE_PHY_CAP4_MASK (IEEE80211_HE_PHY_CAP4_SU_BEAMFORMEE | \
2191 IEEE80211_HE_PHY_CAP4_BEAMFORMEE_MAX_STS_UNDER_80MHZ_8)
2192 #define UAP_HE_PHY_CAP5_MASK IEEE80211_HE_PHY_CAP5_BEAMFORMEE_NUM_SND_DIM_UNDER_80MHZ_2
2193 #define UAP_HE_PHY_CAP6_MASK (IEEE80211_HE_PHY_CAP6_PARTIAL_BW_EXT_RANGE | \
2194 IEEE80211_HE_PHY_CAP6_PPE_THRESHOLD_PRESENT)
2195 #define UAP_HE_PHY_CAP7_MASK (IEEE80211_HE_PHY_CAP7_HE_SU_MU_PPDU_4XLTF_AND_08_US_GI | \
2196 IEEE80211_HE_PHY_CAP7_MAX_NC_1)
2197 #define UAP_HE_PHY_CAP8_MASK 0
2198 #define UAP_HE_PHY_CAP9_MASK IEEE80211_HE_PHY_CAP9_RX_1024_QAM_LESS_THAN_242_TONE_RU
2199 #define UAP_HE_PHY_CAP10_MASK 0
2200
2201 /*
2202 * 2.4 GHz HE capability masks for UAP mode.
2203 *
2204 * MAC: HTC HE, OMI control (no UL OFDMA).
2205 * PHY: 40 MHz, LDPC, NDP 4xLTF, STBC, Doppler, DCM,
2206 * SU BF/BFe, STS/sounding dims, extended range,
2207 * PPE present, 4xLTF 0.8us GI, Rx 1024-QAM.
2208 */
2209 #define UAP_HE_2G_MAC_CAP0_MASK 0x00
2210 #define UAP_HE_2G_MAC_CAP1_MASK 0x00
2211 #define UAP_HE_2G_MAC_CAP2_MASK 0x00
2212 #define UAP_HE_2G_MAC_CAP3_MASK IEEE80211_HE_MAC_CAP3_OMI_CONTROL
2213 #define UAP_HE_2G_MAC_CAP4_MASK 0x00
2214 #define UAP_HE_2G_MAC_CAP5_MASK 0x00
2215
2216 #define UAP_HE_2G_PHY_CAP0_MASK IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_40MHZ_IN_2G
2217 #define UAP_HE_2G_PHY_CAP1_MASK IEEE80211_HE_PHY_CAP1_LDPC_CODING_IN_PAYLOAD
2218 #define UAP_HE_2G_PHY_CAP2_MASK (IEEE80211_HE_PHY_CAP2_NDP_4x_LTF_AND_3_2US | \
2219 IEEE80211_HE_PHY_CAP2_STBC_TX_UNDER_80MHZ | \
2220 IEEE80211_HE_PHY_CAP2_STBC_RX_UNDER_80MHZ | \
2221 IEEE80211_HE_PHY_CAP2_DOPPLER_TX | \
2222 IEEE80211_HE_PHY_CAP2_DOPPLER_RX)
2223 #define UAP_HE_2G_PHY_CAP3_MASK (IEEE80211_HE_PHY_CAP3_DCM_MAX_CONST_TX_BPSK | \
2224 IEEE80211_HE_PHY_CAP3_DCM_MAX_TX_NSS_1 | \
2225 IEEE80211_HE_PHY_CAP3_DCM_MAX_CONST_RX_BPSK | \
2226 IEEE80211_HE_PHY_CAP3_DCM_MAX_RX_NSS_1 | \
2227 IEEE80211_HE_PHY_CAP3_SU_BEAMFORMER)
2228 #define UAP_HE_2G_PHY_CAP4_MASK (IEEE80211_HE_PHY_CAP4_SU_BEAMFORMEE | \
2229 IEEE80211_HE_PHY_CAP4_BEAMFORMEE_MAX_STS_UNDER_80MHZ_8)
2230 #define UAP_HE_2G_PHY_CAP5_MASK IEEE80211_HE_PHY_CAP5_BEAMFORMEE_NUM_SND_DIM_UNDER_80MHZ_2
2231 #define UAP_HE_2G_PHY_CAP6_MASK (IEEE80211_HE_PHY_CAP6_PARTIAL_BW_EXT_RANGE | \
2232 IEEE80211_HE_PHY_CAP6_PPE_THRESHOLD_PRESENT)
2233 #define UAP_HE_2G_PHY_CAP7_MASK (IEEE80211_HE_PHY_CAP7_HE_SU_MU_PPDU_4XLTF_AND_08_US_GI | \
2234 IEEE80211_HE_PHY_CAP7_MAX_NC_1)
2235 #define UAP_HE_2G_PHY_CAP8_MASK 0x00
2236 #define UAP_HE_2G_PHY_CAP9_MASK IEEE80211_HE_PHY_CAP9_RX_1024_QAM_LESS_THAN_242_TONE_RU
2237 #define UAP_HE_2G_PHY_CAP10_MASK 0x00
2238 #define HE_CAP_FIX_SIZE 22
2239
2240 static void
nxpwifi_update_11ax_ie(u8 band,struct nxpwifi_11ax_he_cap_cfg * he_cap_cfg)2241 nxpwifi_update_11ax_ie(u8 band,
2242 struct nxpwifi_11ax_he_cap_cfg *he_cap_cfg)
2243 {
2244 if (band == BAND_A) {
2245 he_cap_cfg->cap_elem.mac_cap_info[0] &= UAP_HE_MAC_CAP0_MASK;
2246 he_cap_cfg->cap_elem.mac_cap_info[1] &= UAP_HE_MAC_CAP1_MASK;
2247 he_cap_cfg->cap_elem.mac_cap_info[2] &= UAP_HE_MAC_CAP2_MASK;
2248 he_cap_cfg->cap_elem.mac_cap_info[3] &= UAP_HE_MAC_CAP3_MASK;
2249 he_cap_cfg->cap_elem.mac_cap_info[4] &= UAP_HE_MAC_CAP4_MASK;
2250 he_cap_cfg->cap_elem.mac_cap_info[5] &= UAP_HE_MAC_CAP5_MASK;
2251 he_cap_cfg->cap_elem.phy_cap_info[0] &= UAP_HE_PHY_CAP0_MASK;
2252 he_cap_cfg->cap_elem.phy_cap_info[1] &= UAP_HE_PHY_CAP1_MASK;
2253 he_cap_cfg->cap_elem.phy_cap_info[2] &= UAP_HE_PHY_CAP2_MASK;
2254 he_cap_cfg->cap_elem.phy_cap_info[3] &= UAP_HE_PHY_CAP3_MASK;
2255 he_cap_cfg->cap_elem.phy_cap_info[4] &= UAP_HE_PHY_CAP4_MASK;
2256 he_cap_cfg->cap_elem.phy_cap_info[5] &= UAP_HE_PHY_CAP5_MASK;
2257 he_cap_cfg->cap_elem.phy_cap_info[6] &= UAP_HE_PHY_CAP6_MASK;
2258 he_cap_cfg->cap_elem.phy_cap_info[7] &= UAP_HE_PHY_CAP7_MASK;
2259 he_cap_cfg->cap_elem.phy_cap_info[8] &= UAP_HE_PHY_CAP8_MASK;
2260 he_cap_cfg->cap_elem.phy_cap_info[9] &= UAP_HE_PHY_CAP9_MASK;
2261 he_cap_cfg->cap_elem.phy_cap_info[10] &= UAP_HE_PHY_CAP10_MASK;
2262 } else {
2263 he_cap_cfg->cap_elem.mac_cap_info[0] &= UAP_HE_2G_MAC_CAP0_MASK;
2264 he_cap_cfg->cap_elem.mac_cap_info[1] &= UAP_HE_2G_MAC_CAP1_MASK;
2265 he_cap_cfg->cap_elem.mac_cap_info[2] &= UAP_HE_2G_MAC_CAP2_MASK;
2266 he_cap_cfg->cap_elem.mac_cap_info[3] &= UAP_HE_2G_MAC_CAP3_MASK;
2267 he_cap_cfg->cap_elem.mac_cap_info[4] &= UAP_HE_2G_MAC_CAP4_MASK;
2268 he_cap_cfg->cap_elem.mac_cap_info[5] &= UAP_HE_2G_MAC_CAP5_MASK;
2269 he_cap_cfg->cap_elem.phy_cap_info[0] &= UAP_HE_2G_PHY_CAP0_MASK;
2270 he_cap_cfg->cap_elem.phy_cap_info[1] &= UAP_HE_2G_PHY_CAP1_MASK;
2271 he_cap_cfg->cap_elem.phy_cap_info[2] &= UAP_HE_2G_PHY_CAP2_MASK;
2272 he_cap_cfg->cap_elem.phy_cap_info[3] &= UAP_HE_2G_PHY_CAP3_MASK;
2273 he_cap_cfg->cap_elem.phy_cap_info[4] &= UAP_HE_2G_PHY_CAP4_MASK;
2274 he_cap_cfg->cap_elem.phy_cap_info[5] &= UAP_HE_2G_PHY_CAP5_MASK;
2275 he_cap_cfg->cap_elem.phy_cap_info[6] &= UAP_HE_2G_PHY_CAP6_MASK;
2276 he_cap_cfg->cap_elem.phy_cap_info[7] &= UAP_HE_2G_PHY_CAP7_MASK;
2277 he_cap_cfg->cap_elem.phy_cap_info[8] &= UAP_HE_2G_PHY_CAP8_MASK;
2278 he_cap_cfg->cap_elem.phy_cap_info[9] &= UAP_HE_2G_PHY_CAP9_MASK;
2279 he_cap_cfg->cap_elem.phy_cap_info[10] &= UAP_HE_2G_PHY_CAP10_MASK;
2280 }
2281 }
2282
2283 static void
nxpwifi_setup_he_caps(struct nxpwifi_private * priv,struct ieee80211_supported_band * band)2284 nxpwifi_setup_he_caps(struct nxpwifi_private *priv,
2285 struct ieee80211_supported_band *band)
2286 {
2287 struct nxpwifi_adapter *adapter = priv->adapter;
2288 struct ieee80211_sband_iftype_data *iftype_data;
2289 struct nxpwifi_11ax_he_cap_cfg he_cap_cfg;
2290 u8 hw_he_cap_len;
2291 u8 extra_mcs_size;
2292 int ppe_threshold_len;
2293
2294 if (band->band == NL80211_BAND_5GHZ) {
2295 hw_he_cap_len = adapter->hw_he_cap_len;
2296 memcpy(&he_cap_cfg, adapter->hw_he_cap, hw_he_cap_len);
2297 nxpwifi_update_11ax_ie(BAND_A, &he_cap_cfg);
2298 } else {
2299 hw_he_cap_len = adapter->hw_2g_he_cap_len;
2300 memcpy(&he_cap_cfg, adapter->hw_2g_he_cap, hw_he_cap_len);
2301 nxpwifi_update_11ax_ie(BAND_G, &he_cap_cfg);
2302 }
2303
2304 if (!hw_he_cap_len)
2305 return;
2306
2307 iftype_data = kmalloc_obj(*iftype_data, GFP_KERNEL);
2308 if (!iftype_data)
2309 return;
2310 memset(iftype_data, 0, sizeof(*iftype_data));
2311
2312 iftype_data->types_mask =
2313 BIT(NL80211_IFTYPE_STATION) | BIT(NL80211_IFTYPE_AP);
2314 iftype_data->he_cap.has_he = true;
2315
2316 memcpy(iftype_data->he_cap.he_cap_elem.mac_cap_info,
2317 he_cap_cfg.cap_elem.mac_cap_info,
2318 sizeof(he_cap_cfg.cap_elem.mac_cap_info));
2319 memcpy(iftype_data->he_cap.he_cap_elem.phy_cap_info,
2320 he_cap_cfg.cap_elem.phy_cap_info,
2321 sizeof(he_cap_cfg.cap_elem.phy_cap_info));
2322 memset(&iftype_data->he_cap.he_mcs_nss_supp,
2323 0xff,
2324 sizeof(iftype_data->he_cap.he_mcs_nss_supp));
2325 memcpy(&iftype_data->he_cap.he_mcs_nss_supp,
2326 he_cap_cfg.he_txrx_mcs_support,
2327 sizeof(he_cap_cfg.he_txrx_mcs_support));
2328
2329 extra_mcs_size = 0;
2330 /* Add 160 MHz MCS/NSS if supported */
2331 if (he_cap_cfg.cap_elem.phy_cap_info[0] & BIT(3))
2332 extra_mcs_size += 4;
2333 /* Add 80+80 MHz MCS/NSS if supported */
2334 if (he_cap_cfg.cap_elem.phy_cap_info[0] & BIT(4))
2335 extra_mcs_size += 4;
2336 if (extra_mcs_size)
2337 memcpy((u8 *)&iftype_data->he_cap.he_mcs_nss_supp.rx_mcs_160,
2338 he_cap_cfg.val, extra_mcs_size);
2339
2340 /* Parse PPE thresholds when present */
2341 ppe_threshold_len = he_cap_cfg.len - HE_CAP_FIX_SIZE - extra_mcs_size;
2342 if (he_cap_cfg.cap_elem.phy_cap_info[6] & BIT(7) && ppe_threshold_len) {
2343 memcpy(iftype_data->he_cap.ppe_thres,
2344 &he_cap_cfg.val[extra_mcs_size],
2345 ppe_threshold_len);
2346 } else {
2347 iftype_data->he_cap.he_cap_elem.phy_cap_info[6] &= BIT(7);
2348 }
2349
2350 _ieee80211_set_sband_iftype_data(band, iftype_data, 1);
2351 }
2352
2353 /* create a new virtual interface with the given name and name assign type */
nxpwifi_add_virtual_intf(struct wiphy * wiphy,const char * name,unsigned char name_assign_type,enum nl80211_iftype type,struct vif_params * params)2354 struct wireless_dev *nxpwifi_add_virtual_intf(struct wiphy *wiphy,
2355 const char *name,
2356 unsigned char name_assign_type,
2357 enum nl80211_iftype type,
2358 struct vif_params *params)
2359 {
2360 struct nxpwifi_adapter *adapter = nxpwifi_cfg80211_get_adapter(wiphy);
2361 struct nxpwifi_private *priv;
2362 struct net_device *dev;
2363 void *mdev_priv;
2364 int ret;
2365
2366 if (!adapter)
2367 return ERR_PTR(-EFAULT);
2368
2369 switch (type) {
2370 case NL80211_IFTYPE_UNSPECIFIED:
2371 case NL80211_IFTYPE_STATION:
2372 if (adapter->curr_iface_comb.sta_intf ==
2373 adapter->iface_limit.sta_intf) {
2374 nxpwifi_dbg(adapter, ERROR,
2375 "cannot create multiple sta ifaces\n");
2376 return ERR_PTR(-EINVAL);
2377 }
2378
2379 priv = nxpwifi_get_unused_priv_by_bss_type
2380 (adapter, NXPWIFI_BSS_TYPE_STA);
2381 if (!priv) {
2382 nxpwifi_dbg(adapter, ERROR,
2383 "could not get free private struct\n");
2384 return ERR_PTR(-EFAULT);
2385 }
2386
2387 priv->wdev.wiphy = wiphy;
2388 priv->wdev.iftype = NL80211_IFTYPE_STATION;
2389
2390 if (type == NL80211_IFTYPE_UNSPECIFIED)
2391 priv->bss_mode = NL80211_IFTYPE_STATION;
2392 else
2393 priv->bss_mode = type;
2394
2395 priv->bss_type = NXPWIFI_BSS_TYPE_STA;
2396 priv->frame_type = NXPWIFI_DATA_FRAME_TYPE_ETH_II;
2397 priv->bss_priority = 0;
2398 priv->bss_role = NXPWIFI_BSS_ROLE_STA;
2399
2400 break;
2401 case NL80211_IFTYPE_AP:
2402 if (adapter->curr_iface_comb.uap_intf ==
2403 adapter->iface_limit.uap_intf) {
2404 nxpwifi_dbg(adapter, ERROR,
2405 "cannot create multiple AP ifaces\n");
2406 return ERR_PTR(-EINVAL);
2407 }
2408
2409 priv = nxpwifi_get_unused_priv_by_bss_type
2410 (adapter, NXPWIFI_BSS_TYPE_UAP);
2411 if (!priv) {
2412 nxpwifi_dbg(adapter, ERROR,
2413 "could not get free private struct\n");
2414 return ERR_PTR(-EFAULT);
2415 }
2416
2417 priv->wdev.wiphy = wiphy;
2418 priv->wdev.iftype = NL80211_IFTYPE_AP;
2419
2420 priv->bss_type = NXPWIFI_BSS_TYPE_UAP;
2421 priv->frame_type = NXPWIFI_DATA_FRAME_TYPE_ETH_II;
2422 priv->bss_priority = 0;
2423 priv->bss_role = NXPWIFI_BSS_ROLE_UAP;
2424 priv->bss_started = 0;
2425 priv->bss_mode = type;
2426
2427 break;
2428 case NL80211_IFTYPE_MONITOR:
2429 priv = nxpwifi_get_unused_priv_by_bss_type
2430 (adapter, NXPWIFI_BSS_TYPE_UAP);
2431 if (!priv) {
2432 nxpwifi_dbg(adapter, ERROR,
2433 "could not get free private struct\n");
2434 return ERR_PTR(-EFAULT);
2435 }
2436 priv->wdev.wiphy = wiphy;
2437 priv->wdev.iftype = NL80211_IFTYPE_MONITOR;
2438
2439 priv->bss_type = NXPWIFI_BSS_TYPE_UAP;
2440 priv->frame_type = NXPWIFI_DATA_FRAME_TYPE_ETH_II;
2441 priv->bss_priority = 0;
2442 priv->bss_started = 0;
2443 priv->bss_mode = type;
2444
2445 break;
2446 default:
2447 nxpwifi_dbg(adapter, ERROR, "type not supported\n");
2448 return ERR_PTR(-EINVAL);
2449 }
2450
2451 dev = alloc_netdev_mqs(sizeof(struct nxpwifi_private *), name,
2452 name_assign_type, ether_setup,
2453 IEEE80211_NUM_ACS, 1);
2454 if (!dev) {
2455 nxpwifi_dbg(adapter, ERROR,
2456 "no memory available for netdevice\n");
2457 ret = -ENOMEM;
2458 goto err_alloc_netdev;
2459 }
2460
2461 nxpwifi_init_priv_params(priv, dev);
2462
2463 priv->netdev = dev;
2464
2465 nxpwifi_set_mac_address(priv, dev, false, NULL);
2466
2467 if (type != NL80211_IFTYPE_MONITOR) {
2468 ret = nxpwifi_set_bss_mode(priv);
2469
2470 if (ret) {
2471 nxpwifi_dbg(adapter, ERROR,
2472 "%s: err_set_bss_mode\n", __func__);
2473 goto err_set_bss_mode;
2474 }
2475 }
2476
2477 ret = nxpwifi_sta_init_cmd(priv, false, false);
2478 if (ret)
2479 goto err_sta_init;
2480
2481 dev_net_set(dev, wiphy_net(wiphy));
2482 dev->ieee80211_ptr = &priv->wdev;
2483 dev->ieee80211_ptr->iftype = priv->bss_mode;
2484 SET_NETDEV_DEV(dev, wiphy_dev(wiphy));
2485
2486 dev->flags |= IFF_BROADCAST | IFF_MULTICAST;
2487 dev->watchdog_timeo = NXPWIFI_DEFAULT_WATCHDOG_TIMEOUT;
2488 dev->needed_headroom = NXPWIFI_MIN_DATA_HEADER_LEN;
2489 dev->ethtool_ops = &nxpwifi_ethtool_ops;
2490
2491 mdev_priv = netdev_priv(dev);
2492 *((unsigned long *)mdev_priv) = (unsigned long)priv;
2493
2494 if (type == NL80211_IFTYPE_MONITOR)
2495 dev->type = ARPHRD_IEEE80211_RADIOTAP;
2496
2497 SET_NETDEV_DEV(dev, adapter->dev);
2498
2499 wiphy_work_init(&priv->reset_conn_state_work, nxpwifi_reset_conn_state_work);
2500
2501 wiphy_delayed_work_init(&priv->dfs_cac_work, nxpwifi_dfs_cac_work);
2502
2503 wiphy_delayed_work_init(&priv->dfs_chan_sw_work, nxpwifi_dfs_chan_sw_work);
2504
2505 /* Register network device */
2506 if (cfg80211_register_netdevice(dev)) {
2507 nxpwifi_dbg(adapter, ERROR, "cannot register network device\n");
2508 ret = -EFAULT;
2509 goto err_reg_netdev;
2510 }
2511
2512 nxpwifi_dbg(adapter, INFO,
2513 "info: %s: NXP 802.11 Adapter\n", dev->name);
2514
2515 #ifdef CONFIG_DEBUG_FS
2516 nxpwifi_dev_debugfs_init(priv);
2517 #endif
2518
2519 update_vif_type_counter(adapter, type, 1);
2520
2521 return &priv->wdev;
2522
2523 err_reg_netdev:
2524 free_netdev(dev);
2525 priv->netdev = NULL;
2526 err_sta_init:
2527 err_set_bss_mode:
2528 err_alloc_netdev:
2529 memset(&priv->wdev, 0, sizeof(priv->wdev));
2530 priv->wdev.iftype = NL80211_IFTYPE_UNSPECIFIED;
2531 priv->bss_mode = NL80211_IFTYPE_UNSPECIFIED;
2532 return ERR_PTR(ret);
2533 }
2534 EXPORT_SYMBOL_GPL(nxpwifi_add_virtual_intf);
2535
2536 /* del_virtual_intf: remove the virtual interface determined by dev */
nxpwifi_del_virtual_intf(struct wiphy * wiphy,struct wireless_dev * wdev)2537 int nxpwifi_del_virtual_intf(struct wiphy *wiphy, struct wireless_dev *wdev)
2538 {
2539 struct nxpwifi_private *priv = nxpwifi_netdev_get_priv(wdev->netdev);
2540 struct nxpwifi_adapter *adapter = priv->adapter;
2541 struct sk_buff *skb, *tmp;
2542
2543 #ifdef CONFIG_DEBUG_FS
2544 nxpwifi_dev_debugfs_remove(priv);
2545 #endif
2546 if (priv->bss_mode == NL80211_IFTYPE_MONITOR) {
2547 struct nxpwifi_802_11_net_monitor netmon_cfg;
2548
2549 memset(&netmon_cfg, 0, sizeof(struct nxpwifi_802_11_net_monitor));
2550 nxpwifi_config_monitor_mode(priv, &netmon_cfg);
2551 }
2552
2553 if (priv->sched_scanning)
2554 priv->sched_scanning = false;
2555
2556 nxpwifi_stop_net_dev_queue(priv->netdev, adapter);
2557
2558 skb_queue_walk_safe(&priv->bypass_txq, skb, tmp) {
2559 skb_unlink(skb, &priv->bypass_txq);
2560 nxpwifi_write_data_complete(priv->adapter, skb, 0, -1);
2561 }
2562
2563 netif_carrier_off(priv->netdev);
2564
2565 if (wdev->netdev->reg_state == NETREG_REGISTERED)
2566 cfg80211_unregister_netdevice(wdev->netdev);
2567
2568 /* Clear the priv in adapter */
2569 priv->netdev = NULL;
2570
2571 update_vif_type_counter(adapter, priv->bss_mode, -1);
2572
2573 priv->bss_mode = NL80211_IFTYPE_UNSPECIFIED;
2574
2575 if (GET_BSS_ROLE(priv) == NXPWIFI_BSS_ROLE_STA ||
2576 GET_BSS_ROLE(priv) == NXPWIFI_BSS_ROLE_UAP)
2577 kfree(priv->hist_data);
2578
2579 return 0;
2580 }
2581 EXPORT_SYMBOL_GPL(nxpwifi_del_virtual_intf);
2582
2583 static bool
nxpwifi_is_pattern_supported(struct cfg80211_pkt_pattern * pat,s8 * byte_seq,u8 max_byte_seq)2584 nxpwifi_is_pattern_supported(struct cfg80211_pkt_pattern *pat, s8 *byte_seq,
2585 u8 max_byte_seq)
2586 {
2587 int j, k, valid_byte_cnt = 0;
2588 bool dont_care_byte = false;
2589
2590 for (j = 0; j < DIV_ROUND_UP(pat->pattern_len, 8); j++) {
2591 for (k = 0; k < 8; k++) {
2592 if (pat->mask[j] & 1 << k) {
2593 memcpy(byte_seq + valid_byte_cnt,
2594 &pat->pattern[j * 8 + k], 1);
2595 valid_byte_cnt++;
2596 if (dont_care_byte)
2597 return false;
2598 } else {
2599 if (valid_byte_cnt)
2600 dont_care_byte = true;
2601 }
2602
2603 /* wildcard bytes record as the offset before the valid byte */
2604 if (!valid_byte_cnt && !dont_care_byte)
2605 pat->pkt_offset++;
2606
2607 if (valid_byte_cnt > max_byte_seq)
2608 return false;
2609 }
2610 }
2611
2612 byte_seq[max_byte_seq] = valid_byte_cnt;
2613
2614 return true;
2615 }
2616
2617 #ifdef CONFIG_PM
nxpwifi_set_auto_arp_mef_entry(struct nxpwifi_private * priv,struct nxpwifi_mef_entry * mef_entry)2618 static void nxpwifi_set_auto_arp_mef_entry(struct nxpwifi_private *priv,
2619 struct nxpwifi_mef_entry *mef_entry)
2620 {
2621 int i, filt_num = 0, num_ipv4 = 0;
2622 struct in_device *in_dev;
2623 struct in_ifaddr *ifa;
2624 __be32 ips[NXPWIFI_MAX_SUPPORTED_IPADDR];
2625 struct nxpwifi_adapter *adapter = priv->adapter;
2626
2627 mef_entry->mode = MEF_MODE_HOST_SLEEP;
2628 mef_entry->action = MEF_ACTION_AUTO_ARP;
2629
2630 /* Enable ARP offload feature */
2631 memset(ips, 0, sizeof(ips));
2632 for (i = 0; i < adapter->priv_num; i++) {
2633 if (adapter->priv[i]->netdev) {
2634 in_dev = __in_dev_get_rtnl(adapter->priv[i]->netdev);
2635 if (!in_dev)
2636 continue;
2637 ifa = rtnl_dereference(in_dev->ifa_list);
2638 if (!ifa || !ifa->ifa_local)
2639 continue;
2640 ips[i] = ifa->ifa_local;
2641 num_ipv4++;
2642 }
2643 }
2644
2645 for (i = 0; i < num_ipv4; i++) {
2646 if (!ips[i])
2647 continue;
2648 mef_entry->filter[filt_num].repeat = 1;
2649 memcpy(mef_entry->filter[filt_num].byte_seq,
2650 (u8 *)&ips[i], sizeof(ips[i]));
2651 mef_entry->filter[filt_num].byte_seq[NXPWIFI_MEF_MAX_BYTESEQ] =
2652 sizeof(ips[i]);
2653 mef_entry->filter[filt_num].offset = 46;
2654 mef_entry->filter[filt_num].filt_type = TYPE_EQ;
2655 if (filt_num) {
2656 mef_entry->filter[filt_num].filt_action =
2657 TYPE_OR;
2658 }
2659 filt_num++;
2660 }
2661
2662 mef_entry->filter[filt_num].repeat = 1;
2663 mef_entry->filter[filt_num].byte_seq[0] = 0x08;
2664 mef_entry->filter[filt_num].byte_seq[1] = 0x06;
2665 mef_entry->filter[filt_num].byte_seq[NXPWIFI_MEF_MAX_BYTESEQ] = 2;
2666 mef_entry->filter[filt_num].offset = 20;
2667 mef_entry->filter[filt_num].filt_type = TYPE_EQ;
2668 mef_entry->filter[filt_num].filt_action = TYPE_AND;
2669 }
2670
nxpwifi_set_wowlan_mef_entry(struct nxpwifi_private * priv,struct nxpwifi_ds_mef_cfg * mef_cfg,struct nxpwifi_mef_entry * mef_entry,struct cfg80211_wowlan * wowlan)2671 static int nxpwifi_set_wowlan_mef_entry(struct nxpwifi_private *priv,
2672 struct nxpwifi_ds_mef_cfg *mef_cfg,
2673 struct nxpwifi_mef_entry *mef_entry,
2674 struct cfg80211_wowlan *wowlan)
2675 {
2676 int i, filt_num = 0, ret = 0;
2677 bool first_pat = true;
2678 u8 byte_seq[NXPWIFI_MEF_MAX_BYTESEQ + 1];
2679
2680 mef_entry->mode = MEF_MODE_HOST_SLEEP;
2681 mef_entry->action = MEF_ACTION_ALLOW_AND_WAKEUP_HOST;
2682
2683 for (i = 0; i < wowlan->n_patterns; i++) {
2684 memset(byte_seq, 0, sizeof(byte_seq));
2685 if (!nxpwifi_is_pattern_supported
2686 (&wowlan->patterns[i], byte_seq,
2687 NXPWIFI_MEF_MAX_BYTESEQ)) {
2688 nxpwifi_dbg(priv->adapter, ERROR,
2689 "Pattern not supported\n");
2690 return -EOPNOTSUPP;
2691 }
2692
2693 if (!wowlan->patterns[i].pkt_offset) {
2694 if (is_unicast_ether_addr(byte_seq) &&
2695 byte_seq[NXPWIFI_MEF_MAX_BYTESEQ] == 1) {
2696 mef_cfg->criteria |= NXPWIFI_CRITERIA_UNICAST;
2697 continue;
2698 } else if (is_broadcast_ether_addr(byte_seq)) {
2699 mef_cfg->criteria |= NXPWIFI_CRITERIA_BROADCAST;
2700 continue;
2701 } else if ((!memcmp(byte_seq, "\x33\x33", 2) &&
2702 (byte_seq[NXPWIFI_MEF_MAX_BYTESEQ] == 2)) ||
2703 (!memcmp(byte_seq, "\x01\x00\x5e", 3) &&
2704 (byte_seq[NXPWIFI_MEF_MAX_BYTESEQ] == 3))) {
2705 mef_cfg->criteria |= NXPWIFI_CRITERIA_MULTICAST;
2706 continue;
2707 }
2708 }
2709 mef_entry->filter[filt_num].repeat = 1;
2710 mef_entry->filter[filt_num].offset =
2711 wowlan->patterns[i].pkt_offset;
2712 memcpy(mef_entry->filter[filt_num].byte_seq, byte_seq,
2713 sizeof(byte_seq));
2714 mef_entry->filter[filt_num].filt_type = TYPE_EQ;
2715
2716 if (first_pat) {
2717 first_pat = false;
2718 nxpwifi_dbg(priv->adapter, INFO, "Wake on patterns\n");
2719 } else {
2720 mef_entry->filter[filt_num].filt_action = TYPE_AND;
2721 }
2722
2723 filt_num++;
2724 }
2725
2726 if (wowlan->magic_pkt) {
2727 mef_cfg->criteria |= NXPWIFI_CRITERIA_UNICAST;
2728 mef_entry->filter[filt_num].repeat = 16;
2729 memcpy(mef_entry->filter[filt_num].byte_seq, priv->curr_addr,
2730 ETH_ALEN);
2731 mef_entry->filter[filt_num].byte_seq[NXPWIFI_MEF_MAX_BYTESEQ] =
2732 ETH_ALEN;
2733 mef_entry->filter[filt_num].offset = 28;
2734 mef_entry->filter[filt_num].filt_type = TYPE_EQ;
2735 if (filt_num)
2736 mef_entry->filter[filt_num].filt_action = TYPE_OR;
2737
2738 filt_num++;
2739 mef_entry->filter[filt_num].repeat = 16;
2740 memcpy(mef_entry->filter[filt_num].byte_seq, priv->curr_addr,
2741 ETH_ALEN);
2742 mef_entry->filter[filt_num].byte_seq[NXPWIFI_MEF_MAX_BYTESEQ] =
2743 ETH_ALEN;
2744 mef_entry->filter[filt_num].offset = 56;
2745 mef_entry->filter[filt_num].filt_type = TYPE_EQ;
2746 mef_entry->filter[filt_num].filt_action = TYPE_OR;
2747 nxpwifi_dbg(priv->adapter, INFO, "Wake on magic packet\n");
2748 }
2749 return ret;
2750 }
2751
nxpwifi_set_mef_filter(struct nxpwifi_private * priv,struct cfg80211_wowlan * wowlan)2752 static int nxpwifi_set_mef_filter(struct nxpwifi_private *priv,
2753 struct cfg80211_wowlan *wowlan)
2754 {
2755 int ret = 0, num_entries = 1;
2756 struct nxpwifi_ds_mef_cfg mef_cfg;
2757 struct nxpwifi_mef_entry *mef_entry;
2758
2759 if (wowlan->n_patterns || wowlan->magic_pkt)
2760 num_entries++;
2761
2762 mef_entry = kzalloc_objs(*mef_entry, num_entries, GFP_KERNEL);
2763 if (!mef_entry)
2764 return -ENOMEM;
2765
2766 memset(&mef_cfg, 0, sizeof(mef_cfg));
2767 mef_cfg.criteria |= NXPWIFI_CRITERIA_BROADCAST |
2768 NXPWIFI_CRITERIA_UNICAST;
2769 mef_cfg.num_entries = num_entries;
2770 mef_cfg.mef_entry = mef_entry;
2771
2772 nxpwifi_set_auto_arp_mef_entry(priv, &mef_entry[0]);
2773
2774 if (wowlan->n_patterns || wowlan->magic_pkt) {
2775 ret = nxpwifi_set_wowlan_mef_entry(priv, &mef_cfg,
2776 &mef_entry[1], wowlan);
2777 if (ret)
2778 goto done;
2779 }
2780
2781 if (!mef_cfg.criteria)
2782 mef_cfg.criteria = NXPWIFI_CRITERIA_BROADCAST |
2783 NXPWIFI_CRITERIA_UNICAST |
2784 NXPWIFI_CRITERIA_MULTICAST;
2785
2786 ret = nxpwifi_mef_cfg(priv, &mef_cfg);
2787
2788 done:
2789 kfree(mef_entry);
2790 return ret;
2791 }
2792
nxpwifi_cfg80211_suspend(struct wiphy * wiphy,struct cfg80211_wowlan * wowlan)2793 static int nxpwifi_cfg80211_suspend(struct wiphy *wiphy,
2794 struct cfg80211_wowlan *wowlan)
2795 {
2796 struct nxpwifi_adapter *adapter = nxpwifi_cfg80211_get_adapter(wiphy);
2797 struct nxpwifi_ds_hs_cfg hs_cfg;
2798 int i, ret = 0, retry_num = 10;
2799 struct nxpwifi_private *priv;
2800 struct nxpwifi_private *sta_priv =
2801 nxpwifi_get_priv(adapter, NXPWIFI_BSS_ROLE_STA);
2802
2803 adapter->wowlan_enabled = false;
2804
2805 sta_priv->scan_aborting = true;
2806 for (i = 0; i < adapter->priv_num; i++) {
2807 priv = adapter->priv[i];
2808 nxpwifi_abort_cac(priv);
2809 }
2810
2811 nxpwifi_cancel_all_pending_cmd(adapter);
2812
2813 for (i = 0; i < adapter->priv_num; i++) {
2814 priv = adapter->priv[i];
2815 if (priv->netdev)
2816 netif_device_detach(priv->netdev);
2817 }
2818
2819 for (i = 0; i < retry_num; i++) {
2820 if (!nxpwifi_wmm_lists_empty(adapter) ||
2821 !nxpwifi_bypass_txlist_empty(adapter) ||
2822 !skb_queue_empty(&adapter->tx_data_q))
2823 usleep_range(10000, 15000);
2824 else
2825 break;
2826 }
2827
2828 if (!wowlan) {
2829 nxpwifi_dbg(adapter, INFO,
2830 "None of the WOWLAN triggers enabled\n");
2831 ret = 0;
2832 goto done;
2833 }
2834
2835 if (!sta_priv->media_connected && !wowlan->nd_config) {
2836 nxpwifi_dbg(adapter, ERROR,
2837 "Can not configure WOWLAN in disconnected state\n");
2838 ret = 0;
2839 goto done;
2840 }
2841
2842 ret = nxpwifi_set_mef_filter(sta_priv, wowlan);
2843 if (ret) {
2844 nxpwifi_dbg(adapter, ERROR, "Failed to set MEF filter\n");
2845 goto done;
2846 }
2847
2848 memset(&hs_cfg, 0, sizeof(hs_cfg));
2849 hs_cfg.conditions = le32_to_cpu(adapter->hs_cfg.conditions);
2850
2851 if (wowlan->nd_config) {
2852 nxpwifi_dbg(adapter, INFO, "Wake on net detect\n");
2853 hs_cfg.conditions |= HS_CFG_COND_MAC_EVENT;
2854 nxpwifi_cfg80211_sched_scan_start(wiphy, sta_priv->netdev,
2855 wowlan->nd_config);
2856 }
2857
2858 if (wowlan->disconnect) {
2859 hs_cfg.conditions |= HS_CFG_COND_MAC_EVENT;
2860 nxpwifi_dbg(sta_priv->adapter, INFO, "Wake on device disconnect\n");
2861 }
2862
2863 hs_cfg.is_invoke_hostcmd = false;
2864 hs_cfg.gpio = adapter->hs_cfg.gpio;
2865 hs_cfg.gap = adapter->hs_cfg.gap;
2866 ret = nxpwifi_set_hs_params(sta_priv, HOST_ACT_GEN_SET,
2867 NXPWIFI_SYNC_CMD, &hs_cfg);
2868 if (ret)
2869 nxpwifi_dbg(adapter, ERROR, "Failed to set HS params\n");
2870
2871 adapter->wowlan_enabled = true;
2872
2873 done:
2874 sta_priv->scan_aborting = false;
2875 return ret;
2876 }
2877
nxpwifi_cfg80211_resume(struct wiphy * wiphy)2878 static int nxpwifi_cfg80211_resume(struct wiphy *wiphy)
2879 {
2880 struct nxpwifi_adapter *adapter = nxpwifi_cfg80211_get_adapter(wiphy);
2881 struct nxpwifi_private *priv;
2882 struct nxpwifi_ds_wakeup_reason wakeup_reason;
2883 struct cfg80211_wowlan_wakeup wakeup_report;
2884 int i;
2885 bool report_wakeup_reason = true;
2886
2887 for (i = 0; i < adapter->priv_num; i++) {
2888 priv = adapter->priv[i];
2889 if (priv->netdev)
2890 netif_device_attach(priv->netdev);
2891 }
2892
2893 if (!wiphy->wowlan_config)
2894 goto done;
2895
2896 priv = nxpwifi_get_priv(adapter, NXPWIFI_BSS_ROLE_STA);
2897 nxpwifi_get_wakeup_reason(priv, HOST_ACT_GEN_GET, NXPWIFI_SYNC_CMD,
2898 &wakeup_reason);
2899 memset(&wakeup_report, 0, sizeof(struct cfg80211_wowlan_wakeup));
2900
2901 wakeup_report.pattern_idx = -1;
2902
2903 switch (wakeup_reason.hs_wakeup_reason) {
2904 case NO_HSWAKEUP_REASON:
2905 break;
2906 case BCAST_DATA_MATCHED:
2907 break;
2908 case MCAST_DATA_MATCHED:
2909 break;
2910 case UCAST_DATA_MATCHED:
2911 break;
2912 case MASKTABLE_EVENT_MATCHED:
2913 break;
2914 case NON_MASKABLE_EVENT_MATCHED:
2915 if (wiphy->wowlan_config->disconnect)
2916 wakeup_report.disconnect = true;
2917 if (wiphy->wowlan_config->nd_config)
2918 wakeup_report.net_detect = adapter->nd_info;
2919 break;
2920 case NON_MASKABLE_CONDITION_MATCHED:
2921 break;
2922 case MAGIC_PATTERN_MATCHED:
2923 if (wiphy->wowlan_config->magic_pkt)
2924 wakeup_report.magic_pkt = true;
2925 if (wiphy->wowlan_config->n_patterns)
2926 wakeup_report.pattern_idx = 1;
2927 break;
2928 case GTK_REKEY_FAILURE:
2929 if (wiphy->wowlan_config->gtk_rekey_failure)
2930 wakeup_report.gtk_rekey_failure = true;
2931 break;
2932 default:
2933 report_wakeup_reason = false;
2934 break;
2935 }
2936
2937 if (report_wakeup_reason)
2938 cfg80211_report_wowlan_wakeup(&priv->wdev, &wakeup_report,
2939 GFP_KERNEL);
2940
2941 done:
2942 if (adapter->nd_info) {
2943 for (i = 0 ; i < adapter->nd_info->n_matches ; i++)
2944 kfree(adapter->nd_info->matches[i]);
2945 kfree(adapter->nd_info);
2946 adapter->nd_info = NULL;
2947 }
2948
2949 return 0;
2950 }
2951
nxpwifi_cfg80211_set_wakeup(struct wiphy * wiphy,bool enabled)2952 static void nxpwifi_cfg80211_set_wakeup(struct wiphy *wiphy,
2953 bool enabled)
2954 {
2955 struct nxpwifi_adapter *adapter = nxpwifi_cfg80211_get_adapter(wiphy);
2956
2957 device_set_wakeup_enable(adapter->dev, enabled);
2958 }
2959 #endif
2960
nxpwifi_get_coalesce_pkt_type(u8 * byte_seq)2961 static int nxpwifi_get_coalesce_pkt_type(u8 *byte_seq)
2962 {
2963 if ((byte_seq[0] & 0x01) &&
2964 byte_seq[NXPWIFI_COALESCE_MAX_BYTESEQ] == 1)
2965 return PACKET_TYPE_UNICAST;
2966 else if (is_broadcast_ether_addr(byte_seq))
2967 return PACKET_TYPE_BROADCAST;
2968 else if ((!memcmp(byte_seq, "\x33\x33", 2) &&
2969 byte_seq[NXPWIFI_COALESCE_MAX_BYTESEQ] == 2) ||
2970 (!memcmp(byte_seq, "\x01\x00\x5e", 3) &&
2971 byte_seq[NXPWIFI_COALESCE_MAX_BYTESEQ] == 3))
2972 return PACKET_TYPE_MULTICAST;
2973
2974 return 0;
2975 }
2976
2977 static int
nxpwifi_fill_coalesce_rule_info(struct nxpwifi_private * priv,struct cfg80211_coalesce_rules * crule,struct nxpwifi_coalesce_rule * mrule)2978 nxpwifi_fill_coalesce_rule_info(struct nxpwifi_private *priv,
2979 struct cfg80211_coalesce_rules *crule,
2980 struct nxpwifi_coalesce_rule *mrule)
2981 {
2982 u8 byte_seq[NXPWIFI_COALESCE_MAX_BYTESEQ + 1];
2983 struct filt_field_param *param;
2984 int i;
2985
2986 mrule->max_coalescing_delay = crule->delay;
2987
2988 param = mrule->params;
2989
2990 for (i = 0; i < crule->n_patterns; i++) {
2991 memset(byte_seq, 0, sizeof(byte_seq));
2992 if (!nxpwifi_is_pattern_supported(&crule->patterns[i],
2993 byte_seq,
2994 NXPWIFI_COALESCE_MAX_BYTESEQ)) {
2995 nxpwifi_dbg(priv->adapter, ERROR,
2996 "Pattern not supported\n");
2997 return -EOPNOTSUPP;
2998 }
2999
3000 if (!crule->patterns[i].pkt_offset) {
3001 u8 pkt_type;
3002
3003 pkt_type = nxpwifi_get_coalesce_pkt_type(byte_seq);
3004 if (pkt_type && mrule->pkt_type) {
3005 nxpwifi_dbg(priv->adapter, ERROR,
3006 "Multiple packet types not allowed\n");
3007 return -EOPNOTSUPP;
3008 } else if (pkt_type) {
3009 mrule->pkt_type = pkt_type;
3010 continue;
3011 }
3012 }
3013
3014 if (crule->condition == NL80211_COALESCE_CONDITION_MATCH)
3015 param->operation = RECV_FILTER_MATCH_TYPE_EQ;
3016 else
3017 param->operation = RECV_FILTER_MATCH_TYPE_NE;
3018
3019 param->operand_len = byte_seq[NXPWIFI_COALESCE_MAX_BYTESEQ];
3020 memcpy(param->operand_byte_stream, byte_seq,
3021 param->operand_len);
3022 param->offset = crule->patterns[i].pkt_offset;
3023 param++;
3024
3025 mrule->num_of_fields++;
3026 }
3027
3028 if (!mrule->pkt_type) {
3029 nxpwifi_dbg(priv->adapter, ERROR,
3030 "Packet type can not be determined\n");
3031 return -EOPNOTSUPP;
3032 }
3033
3034 return 0;
3035 }
3036
nxpwifi_cfg80211_set_coalesce(struct wiphy * wiphy,struct cfg80211_coalesce * coalesce)3037 static int nxpwifi_cfg80211_set_coalesce(struct wiphy *wiphy,
3038 struct cfg80211_coalesce *coalesce)
3039 {
3040 struct nxpwifi_adapter *adapter = nxpwifi_cfg80211_get_adapter(wiphy);
3041 int i, ret;
3042 struct nxpwifi_ds_coalesce_cfg coalesce_cfg;
3043 struct nxpwifi_private *priv =
3044 nxpwifi_get_priv(adapter, NXPWIFI_BSS_ROLE_STA);
3045
3046 memset(&coalesce_cfg, 0, sizeof(coalesce_cfg));
3047
3048 if (!coalesce)
3049 return nxpwifi_coalesce_cfg(priv, &coalesce_cfg);
3050
3051 coalesce_cfg.num_of_rules = coalesce->n_rules;
3052 for (i = 0; i < coalesce->n_rules; i++) {
3053 ret = nxpwifi_fill_coalesce_rule_info(priv, &coalesce->rules[i],
3054 &coalesce_cfg.rule[i]);
3055 if (ret) {
3056 nxpwifi_dbg(adapter, ERROR,
3057 "Recheck the patterns provided for rule %d\n",
3058 i + 1);
3059 return ret;
3060 }
3061 }
3062
3063 return nxpwifi_coalesce_cfg(priv, &coalesce_cfg);
3064 }
3065
3066 static int
nxpwifi_cfg80211_uap_add_station(struct nxpwifi_private * priv,const u8 * mac,struct station_parameters * params)3067 nxpwifi_cfg80211_uap_add_station(struct nxpwifi_private *priv, const u8 *mac,
3068 struct station_parameters *params)
3069 {
3070 struct nxpwifi_sta_info add_sta;
3071 int ret;
3072
3073 memcpy(add_sta.peer_mac, mac, ETH_ALEN);
3074 add_sta.params = params;
3075
3076 ret = nxpwifi_add_new_station(priv, &add_sta);
3077
3078 return ret;
3079 }
3080
3081 static int
nxpwifi_cfg80211_add_station(struct wiphy * wiphy,struct wireless_dev * wdev,const u8 * mac,struct station_parameters * params)3082 nxpwifi_cfg80211_add_station(struct wiphy *wiphy, struct wireless_dev *wdev,
3083 const u8 *mac, struct station_parameters *params)
3084 {
3085 struct nxpwifi_private *priv = nxpwifi_netdev_get_priv(wdev->netdev);
3086 int ret = -EOPNOTSUPP;
3087
3088 if (GET_BSS_ROLE(priv) == NXPWIFI_BSS_ROLE_UAP)
3089 ret = nxpwifi_cfg80211_uap_add_station(priv, mac, params);
3090
3091 return ret;
3092 }
3093
3094 static int
nxpwifi_cfg80211_channel_switch(struct wiphy * wiphy,struct net_device * dev,struct cfg80211_csa_settings * params)3095 nxpwifi_cfg80211_channel_switch(struct wiphy *wiphy, struct net_device *dev,
3096 struct cfg80211_csa_settings *params)
3097 {
3098 struct nxpwifi_private *priv = nxpwifi_netdev_get_priv(dev);
3099 int chsw_msec;
3100 int ret;
3101
3102 if (priv->adapter->scan_processing) {
3103 nxpwifi_dbg(priv->adapter, ERROR,
3104 "radar detection: scan in process...\n");
3105 return -EBUSY;
3106 }
3107
3108 if (priv->wdev.links[0].cac_started)
3109 return -EBUSY;
3110
3111 if (cfg80211_chandef_identical(¶ms->chandef,
3112 &priv->dfs_chandef))
3113 return -EINVAL;
3114
3115 if (params->block_tx) {
3116 netif_carrier_off(priv->netdev);
3117 nxpwifi_stop_net_dev_queue(priv->netdev, priv->adapter);
3118 priv->uap_stop_tx = true;
3119 }
3120
3121 ret = nxpwifi_del_mgmt_ies(priv);
3122 if (ret)
3123 nxpwifi_dbg(priv->adapter, ERROR,
3124 "Failed to delete mgmt IEs!\n");
3125
3126 ret = nxpwifi_set_mgmt_ies(priv, ¶ms->beacon_csa);
3127 if (ret) {
3128 nxpwifi_dbg(priv->adapter, ERROR,
3129 "%s: setting mgmt ies failed\n", __func__);
3130 goto done;
3131 }
3132
3133 memcpy(&priv->dfs_chandef, ¶ms->chandef, sizeof(priv->dfs_chandef));
3134 memcpy(&priv->ap_update_info.beacon, ¶ms->beacon_after,
3135 sizeof(priv->ap_update_info.beacon));
3136
3137 chsw_msec = max(params->count * priv->bss_cfg.beacon_period, 100);
3138
3139 nxpwifi_queue_delayed_wiphy_work(priv->adapter,
3140 &priv->dfs_chan_sw_work,
3141 msecs_to_jiffies(chsw_msec));
3142
3143 done:
3144 return ret;
3145 }
3146
nxpwifi_cfg80211_get_channel(struct wiphy * wiphy,struct wireless_dev * wdev,unsigned int link_id,struct cfg80211_chan_def * chandef)3147 static int nxpwifi_cfg80211_get_channel(struct wiphy *wiphy,
3148 struct wireless_dev *wdev,
3149 unsigned int link_id,
3150 struct cfg80211_chan_def *chandef)
3151 {
3152 struct nxpwifi_private *priv = nxpwifi_netdev_get_priv(wdev->netdev);
3153 struct nxpwifi_bssdescriptor *curr_bss;
3154 struct ieee80211_channel *chan;
3155 enum nl80211_channel_type chan_type;
3156 enum nl80211_band band;
3157 int freq;
3158 int ret = -ENODATA;
3159
3160 if (GET_BSS_ROLE(priv) == NXPWIFI_BSS_ROLE_UAP &&
3161 cfg80211_chandef_valid(&priv->bss_chandef)) {
3162 *chandef = priv->bss_chandef;
3163 ret = 0;
3164 } else if (priv->media_connected) {
3165 curr_bss = &priv->curr_bss_params.bss_descriptor;
3166 band = nxpwifi_band_to_radio_type(priv->curr_bss_params.band);
3167 freq = ieee80211_channel_to_frequency(curr_bss->channel, band);
3168 chan = ieee80211_get_channel(wiphy, freq);
3169
3170 if (priv->ht_param_present) {
3171 chan_type = nxpwifi_get_chan_type(priv);
3172 cfg80211_chandef_create(chandef, chan, chan_type);
3173 } else {
3174 cfg80211_chandef_create(chandef, chan,
3175 NL80211_CHAN_NO_HT);
3176 }
3177 ret = 0;
3178 }
3179
3180 return ret;
3181 }
3182
3183 #ifdef CONFIG_NL80211_TESTMODE
3184
3185 enum nxpwifi_tm_attr {
3186 __NXPWIFI_TM_ATTR_INVALID = 0,
3187 NXPWIFI_TM_ATTR_CMD = 1,
3188 NXPWIFI_TM_ATTR_DATA = 2,
3189
3190 /* keep last */
3191 __NXPWIFI_TM_ATTR_AFTER_LAST,
3192 NXPWIFI_TM_ATTR_MAX = __NXPWIFI_TM_ATTR_AFTER_LAST - 1,
3193 };
3194
3195 static const struct nla_policy nxpwifi_tm_policy[NXPWIFI_TM_ATTR_MAX + 1] = {
3196 [NXPWIFI_TM_ATTR_CMD] = { .type = NLA_U32 },
3197 [NXPWIFI_TM_ATTR_DATA] = { .type = NLA_BINARY,
3198 .len = NXPWIFI_SIZE_OF_CMD_BUFFER },
3199 };
3200
3201 enum nxpwifi_tm_command {
3202 NXPWIFI_TM_CMD_HOSTCMD = 0,
3203 };
3204
nxpwifi_tm_cmd(struct wiphy * wiphy,struct wireless_dev * wdev,void * data,int len)3205 static int nxpwifi_tm_cmd(struct wiphy *wiphy, struct wireless_dev *wdev,
3206 void *data, int len)
3207 {
3208 struct nxpwifi_private *priv = nxpwifi_netdev_get_priv(wdev->netdev);
3209 struct nxpwifi_ds_misc_cmd *hostcmd;
3210 struct nlattr *tb[NXPWIFI_TM_ATTR_MAX + 1];
3211 struct sk_buff *skb;
3212 int err;
3213
3214 if (!priv)
3215 return -EINVAL;
3216
3217 err = nla_parse_deprecated(tb, NXPWIFI_TM_ATTR_MAX, data, len,
3218 nxpwifi_tm_policy, NULL);
3219 if (err)
3220 return err;
3221
3222 if (!tb[NXPWIFI_TM_ATTR_CMD])
3223 return -EINVAL;
3224
3225 switch (nla_get_u32(tb[NXPWIFI_TM_ATTR_CMD])) {
3226 case NXPWIFI_TM_CMD_HOSTCMD:
3227 if (!tb[NXPWIFI_TM_ATTR_DATA])
3228 return -EINVAL;
3229
3230 hostcmd = kzalloc_obj(*hostcmd, GFP_KERNEL);
3231 if (!hostcmd)
3232 return -ENOMEM;
3233
3234 hostcmd->len = nla_len(tb[NXPWIFI_TM_ATTR_DATA]);
3235 memcpy(hostcmd->cmd, nla_data(tb[NXPWIFI_TM_ATTR_DATA]),
3236 hostcmd->len);
3237
3238 if (nxpwifi_hostcmd(priv, hostcmd)) {
3239 nxpwifi_dbg(priv->adapter, ERROR, "Failed to process hostcmd\n");
3240 kfree(hostcmd);
3241 return -EFAULT;
3242 }
3243
3244 /* process hostcmd response*/
3245 skb = cfg80211_testmode_alloc_reply_skb(wiphy, hostcmd->len);
3246 if (!skb) {
3247 kfree(hostcmd);
3248 return -ENOMEM;
3249 }
3250 err = nla_put(skb, NXPWIFI_TM_ATTR_DATA,
3251 hostcmd->len, hostcmd->cmd);
3252 if (err) {
3253 kfree(hostcmd);
3254 kfree_skb(skb);
3255 return -EMSGSIZE;
3256 }
3257
3258 err = cfg80211_testmode_reply(skb);
3259 kfree(hostcmd);
3260 return err;
3261 default:
3262 return -EOPNOTSUPP;
3263 }
3264 }
3265 #endif
3266
3267 static int
nxpwifi_cfg80211_start_radar_detection(struct wiphy * wiphy,struct net_device * dev,struct cfg80211_chan_def * chandef,u32 cac_time_ms,int link_id)3268 nxpwifi_cfg80211_start_radar_detection(struct wiphy *wiphy,
3269 struct net_device *dev,
3270 struct cfg80211_chan_def *chandef,
3271 u32 cac_time_ms, int link_id)
3272 {
3273 struct nxpwifi_private *priv = nxpwifi_netdev_get_priv(dev);
3274 struct nxpwifi_radar_params radar_params;
3275 int ret;
3276
3277 if (priv->adapter->scan_processing) {
3278 nxpwifi_dbg(priv->adapter, ERROR,
3279 "radar detection: scan already in process...\n");
3280 return -EBUSY;
3281 }
3282
3283 if (!nxpwifi_is_11h_active(priv)) {
3284 nxpwifi_dbg(priv->adapter, INFO,
3285 "Enable 11h extensions in FW\n");
3286 if (nxpwifi_11h_activate(priv, true)) {
3287 nxpwifi_dbg(priv->adapter, ERROR,
3288 "Failed to activate 11h extensions!!");
3289 return -EPERM;
3290 }
3291 priv->state_11h.is_11h_active = true;
3292 }
3293
3294 memset(&radar_params, 0, sizeof(struct nxpwifi_radar_params));
3295 radar_params.chandef = chandef;
3296 radar_params.cac_time_ms = cac_time_ms;
3297
3298 memcpy(&priv->dfs_chandef, chandef, sizeof(priv->dfs_chandef));
3299
3300 ret = nxpwifi_chan_report_request(priv, &radar_params);
3301 if (!ret)
3302 nxpwifi_queue_delayed_wiphy_work(priv->adapter,
3303 &priv->dfs_cac_work,
3304 msecs_to_jiffies(cac_time_ms));
3305
3306 return ret;
3307 }
3308
3309 static int
nxpwifi_cfg80211_change_station(struct wiphy * wiphy,struct wireless_dev * wdev,const u8 * mac,struct station_parameters * params)3310 nxpwifi_cfg80211_change_station(struct wiphy *wiphy, struct wireless_dev *wdev,
3311 const u8 *mac,
3312 struct station_parameters *params)
3313 {
3314 return 0;
3315 }
3316
3317 static int
nxpwifi_cfg80211_authenticate(struct wiphy * wiphy,struct net_device * dev,struct cfg80211_auth_request * req)3318 nxpwifi_cfg80211_authenticate(struct wiphy *wiphy,
3319 struct net_device *dev,
3320 struct cfg80211_auth_request *req)
3321 {
3322 struct nxpwifi_private *priv = nxpwifi_netdev_get_priv(dev);
3323 struct nxpwifi_adapter *adapter = priv->adapter;
3324 struct sk_buff *skb;
3325 u16 pkt_len, auth_alg;
3326 int ret;
3327 struct ieee80211_mgmt *mgmt;
3328 struct nxpwifi_txinfo *tx_info;
3329 u8 trans = 1, status_code = 0;
3330 u8 *varptr = NULL;
3331
3332 if (GET_BSS_ROLE(priv) == NXPWIFI_BSS_ROLE_UAP) {
3333 nxpwifi_dbg(adapter, ERROR, "Interface role is AP\n");
3334 return -EINVAL;
3335 }
3336
3337 if (priv->wdev.iftype != NL80211_IFTYPE_STATION) {
3338 nxpwifi_dbg(adapter, ERROR,
3339 "Interface type is not correct (type %d)\n",
3340 priv->wdev.iftype);
3341 return -EINVAL;
3342 }
3343
3344 if (!nxpwifi_is_channel_setting_allowable(priv, req->bss->channel))
3345 return -EOPNOTSUPP;
3346
3347 if (priv->auth_alg != WLAN_AUTH_SAE &&
3348 (priv->auth_flag & HOST_MLME_AUTH_PENDING)) {
3349 nxpwifi_dbg(adapter, ERROR, "Pending auth on going\n");
3350 return -EBUSY;
3351 }
3352
3353 if (!priv->host_mlme_reg) {
3354 priv->host_mlme_reg = true;
3355 priv->mgmt_frame_mask |= HOST_MLME_MGMT_MASK;
3356 nxpwifi_mgmt_frame_reg(priv, priv->mgmt_frame_mask);
3357 }
3358
3359 switch (req->auth_type) {
3360 case NL80211_AUTHTYPE_OPEN_SYSTEM:
3361 auth_alg = WLAN_AUTH_OPEN;
3362 break;
3363 case NL80211_AUTHTYPE_SHARED_KEY:
3364 auth_alg = WLAN_AUTH_SHARED_KEY;
3365 break;
3366 case NL80211_AUTHTYPE_FT:
3367 auth_alg = WLAN_AUTH_FT;
3368 break;
3369 case NL80211_AUTHTYPE_NETWORK_EAP:
3370 auth_alg = WLAN_AUTH_LEAP;
3371 break;
3372 case NL80211_AUTHTYPE_SAE:
3373 auth_alg = WLAN_AUTH_SAE;
3374 break;
3375 default:
3376 nxpwifi_dbg(adapter, ERROR,
3377 "unsupported auth type=%d\n", req->auth_type);
3378 return -EOPNOTSUPP;
3379 }
3380
3381 if (!(priv->auth_flag & HOST_MLME_AUTH_PENDING)) {
3382 ret = nxpwifi_remain_on_chan_cfg(priv, HOST_ACT_GEN_SET,
3383 req->bss->channel,
3384 AUTH_TX_DEFAULT_WAIT_TIME);
3385
3386 if (!ret) {
3387 priv->roc_cfg.cookie =
3388 nxpwifi_roc_cookie(adapter);
3389 priv->roc_cfg.chan = *req->bss->channel;
3390 } else {
3391 return -EPERM;
3392 }
3393 }
3394
3395 priv->sec_info.authentication_mode = auth_alg;
3396
3397 nxpwifi_cancel_scan(adapter);
3398
3399 pkt_len = (u16)req->ie_len + req->auth_data_len +
3400 NXPWIFI_MGMT_HEADER_LEN + NXPWIFI_AUTH_BODY_LEN;
3401
3402 if (req->auth_data_len >= 4)
3403 pkt_len -= 4;
3404
3405 mgmt = kzalloc(pkt_len, GFP_KERNEL);
3406
3407 skb = dev_alloc_skb(NXPWIFI_MIN_DATA_HEADER_LEN +
3408 NXPWIFI_MGMT_FRAME_HEADER_SIZE +
3409 pkt_len + sizeof(pkt_len));
3410 if (!skb) {
3411 nxpwifi_dbg(adapter, ERROR,
3412 "allocate skb failed for management frame\n");
3413 return -ENOMEM;
3414 }
3415
3416 tx_info = NXPWIFI_SKB_TXCB(skb);
3417 memset(tx_info, 0, sizeof(*tx_info));
3418 tx_info->bss_num = priv->bss_num;
3419 tx_info->bss_type = priv->bss_type;
3420 tx_info->pkt_len = pkt_len;
3421
3422 memcpy(mgmt->da, req->bss->bssid, ETH_ALEN);
3423 memcpy(mgmt->sa, priv->curr_addr, ETH_ALEN);
3424 memcpy(mgmt->bssid, req->bss->bssid, ETH_ALEN);
3425 mgmt->frame_control =
3426 cpu_to_le16(IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_AUTH);
3427
3428 if (req->auth_data_len >= 4) {
3429 if (req->auth_type == NL80211_AUTHTYPE_SAE) {
3430 __le16 *pos = (__le16 *)req->auth_data;
3431
3432 trans = le16_to_cpu(pos[0]);
3433 status_code = le16_to_cpu(pos[1]);
3434 }
3435 memcpy((u8 *)(&mgmt->u.auth.variable), req->auth_data + 4,
3436 req->auth_data_len - 4);
3437 varptr = (u8 *)&mgmt->u.auth.variable +
3438 (req->auth_data_len - 4);
3439 }
3440
3441 mgmt->u.auth.auth_alg = cpu_to_le16(auth_alg);
3442 mgmt->u.auth.auth_transaction = cpu_to_le16(trans);
3443 mgmt->u.auth.status_code = cpu_to_le16(status_code);
3444
3445 if (req->ie && req->ie_len) {
3446 if (!varptr)
3447 varptr = (u8 *)&mgmt->u.auth.variable;
3448 memcpy((u8 *)varptr, req->ie, req->ie_len);
3449 }
3450
3451 nxpwifi_form_mgmt_frame(skb, (const u8 *)mgmt, pkt_len);
3452 kfree(mgmt);
3453 priv->auth_flag = HOST_MLME_AUTH_PENDING;
3454 priv->auth_alg = auth_alg;
3455 skb->priority = WMM_HIGHEST_PRIORITY;
3456 __net_timestamp(skb);
3457
3458 nxpwifi_dbg(adapter, MSG,
3459 "auth: send authentication to %pM\n", req->bss->bssid);
3460
3461 nxpwifi_queue_tx_pkt(priv, skb);
3462
3463 return 0;
3464 }
3465
3466 static int
nxpwifi_cfg80211_associate(struct wiphy * wiphy,struct net_device * dev,struct cfg80211_assoc_request * req)3467 nxpwifi_cfg80211_associate(struct wiphy *wiphy, struct net_device *dev,
3468 struct cfg80211_assoc_request *req)
3469 {
3470 struct nxpwifi_private *priv = nxpwifi_netdev_get_priv(dev);
3471 struct nxpwifi_adapter *adapter = priv->adapter;
3472 int ret;
3473 struct cfg80211_ssid req_ssid;
3474 const u8 *ssid_ie;
3475
3476 if (GET_BSS_ROLE(priv) != NXPWIFI_BSS_ROLE_STA) {
3477 nxpwifi_dbg(adapter, ERROR,
3478 "%s: reject infra assoc request in non-STA role\n",
3479 dev->name);
3480 return -EINVAL;
3481 }
3482
3483 if (test_bit(NXPWIFI_SURPRISE_REMOVED, &adapter->work_flags) ||
3484 test_bit(NXPWIFI_IS_CMD_TIMEDOUT, &adapter->work_flags)) {
3485 nxpwifi_dbg(adapter, ERROR,
3486 "%s: Ignore association.\t"
3487 "Card removed or FW in bad state\n",
3488 dev->name);
3489 return -EPERM;
3490 }
3491
3492 if (priv->auth_alg == WLAN_AUTH_SAE)
3493 priv->auth_flag = HOST_MLME_AUTH_DONE;
3494
3495 if (priv->auth_flag && !(priv->auth_flag & HOST_MLME_AUTH_DONE))
3496 return -EBUSY;
3497
3498 if (priv->roc_cfg.cookie) {
3499 ret = nxpwifi_remain_on_chan_cfg(priv, HOST_ACT_GEN_REMOVE,
3500 &priv->roc_cfg.chan, 0);
3501 if (!ret)
3502 memset(&priv->roc_cfg, 0,
3503 sizeof(struct nxpwifi_roc_cfg));
3504 else
3505 return ret;
3506 }
3507
3508 if (!nxpwifi_stop_bg_scan(priv))
3509 cfg80211_sched_scan_stopped_locked(priv->wdev.wiphy, 0);
3510
3511 memset(&req_ssid, 0, sizeof(struct cfg80211_ssid));
3512 rcu_read_lock();
3513 ssid_ie = ieee80211_bss_get_ie(req->bss, WLAN_EID_SSID);
3514
3515 if (!ssid_ie)
3516 goto ssid_err;
3517
3518 req_ssid.ssid_len = ssid_ie[1];
3519 if (req_ssid.ssid_len > IEEE80211_MAX_SSID_LEN) {
3520 nxpwifi_dbg(adapter, ERROR, "invalid SSID - aborting\n");
3521 goto ssid_err;
3522 }
3523
3524 memcpy(req_ssid.ssid, ssid_ie + 2, req_ssid.ssid_len);
3525 if (!req_ssid.ssid_len || req_ssid.ssid[0] < 0x20) {
3526 nxpwifi_dbg(adapter, ERROR, "invalid SSID - aborting\n");
3527 goto ssid_err;
3528 }
3529 rcu_read_unlock();
3530
3531 /*
3532 * As this is new association, clear locally stored
3533 * keys and security related flags
3534 */
3535 priv->sec_info.wpa_enabled = false;
3536 priv->sec_info.wpa2_enabled = false;
3537 priv->wep_key_curr_index = 0;
3538 priv->sec_info.encryption_mode = 0;
3539 priv->sec_info.is_authtype_auto = 0;
3540 ret = nxpwifi_set_encode(priv, NULL, NULL, 0, 0, NULL, 1);
3541
3542 if (req->crypto.n_ciphers_pairwise)
3543 priv->sec_info.encryption_mode =
3544 req->crypto.ciphers_pairwise[0];
3545
3546 if (req->crypto.cipher_group)
3547 priv->sec_info.encryption_mode = req->crypto.cipher_group;
3548
3549 if (req->ie)
3550 ret = nxpwifi_set_gen_ie(priv, req->ie, req->ie_len);
3551
3552 memcpy(priv->cfg_bssid, req->bss->bssid, ETH_ALEN);
3553
3554 nxpwifi_dbg(adapter, MSG,
3555 "assoc: send association to %pM\n", req->bss->bssid);
3556
3557 cfg80211_ref_bss(adapter->wiphy, req->bss);
3558
3559 ret = nxpwifi_bss_start(priv, req->bss, &req_ssid);
3560
3561 if (ret) {
3562 priv->auth_flag = 0;
3563 priv->auth_alg = WLAN_AUTH_NONE;
3564 eth_zero_addr(priv->cfg_bssid);
3565 }
3566
3567 if (ret >= 0) {
3568 if (priv->assoc_rsp_size) {
3569 priv->req_bss = req->bss;
3570 adapter->assoc_resp_received = true;
3571 nxpwifi_queue_wiphy_work(adapter,
3572 &adapter->host_mlme_work);
3573 }
3574 ret = 0;
3575 }
3576
3577 cfg80211_put_bss(priv->adapter->wiphy, req->bss);
3578
3579 return ret;
3580
3581 ssid_err:
3582
3583 rcu_read_unlock();
3584 return -EINVAL;
3585 }
3586
3587 static int
nxpwifi_cfg80211_disconnect(struct wiphy * wiphy,struct net_device * dev,u16 reason_code)3588 nxpwifi_cfg80211_disconnect(struct wiphy *wiphy, struct net_device *dev,
3589 u16 reason_code)
3590 {
3591 struct nxpwifi_private *priv = nxpwifi_netdev_get_priv(dev);
3592 int ret;
3593
3594 if (!nxpwifi_stop_bg_scan(priv))
3595 cfg80211_sched_scan_stopped_locked(priv->wdev.wiphy, 0);
3596
3597 ret = nxpwifi_deauthenticate(priv, NULL);
3598 if (!ret) {
3599 eth_zero_addr(priv->cfg_bssid);
3600 priv->hs2_enabled = false;
3601 }
3602
3603 return ret;
3604 }
3605
3606 static int
nxpwifi_cfg80211_deauthenticate(struct wiphy * wiphy,struct net_device * dev,struct cfg80211_deauth_request * req)3607 nxpwifi_cfg80211_deauthenticate(struct wiphy *wiphy,
3608 struct net_device *dev,
3609 struct cfg80211_deauth_request *req)
3610 {
3611 return nxpwifi_cfg80211_disconnect(wiphy, dev, req->reason_code);
3612 }
3613
3614 static int
nxpwifi_cfg80211_disassociate(struct wiphy * wiphy,struct net_device * dev,struct cfg80211_disassoc_request * req)3615 nxpwifi_cfg80211_disassociate(struct wiphy *wiphy,
3616 struct net_device *dev,
3617 struct cfg80211_disassoc_request *req)
3618 {
3619 return nxpwifi_cfg80211_disconnect(wiphy, dev, req->reason_code);
3620 }
3621
3622 static int
nxpwifi_cfg80211_probe_peer(struct wiphy * wiphy,struct net_device * dev,const u8 * peer,u64 cookie)3623 nxpwifi_cfg80211_probe_peer(struct wiphy *wiphy,
3624 struct net_device *dev, const u8 *peer,
3625 u64 cookie)
3626 {
3627 /*
3628 * hostapd looks for NL80211_CMD_PROBE_CLIENT support; otherwise,
3629 * it requires monitor-mode support (which mwifiex doesn't support).
3630 * Provide fake probe_peer support to work around this.
3631 */
3632 return -EOPNOTSUPP;
3633 }
3634
3635 /* station cfg80211 operations */
3636 static const struct cfg80211_ops nxpwifi_cfg80211_ops = {
3637 .add_virtual_intf = nxpwifi_add_virtual_intf,
3638 .del_virtual_intf = nxpwifi_del_virtual_intf,
3639 .change_virtual_intf = nxpwifi_cfg80211_change_virtual_intf,
3640 .scan = nxpwifi_cfg80211_scan,
3641 .auth = nxpwifi_cfg80211_authenticate,
3642 .assoc = nxpwifi_cfg80211_associate,
3643 .deauth = nxpwifi_cfg80211_deauthenticate,
3644 .disassoc = nxpwifi_cfg80211_disassociate,
3645 .probe_peer = nxpwifi_cfg80211_probe_peer,
3646 .get_station = nxpwifi_cfg80211_get_station,
3647 .dump_station = nxpwifi_cfg80211_dump_station,
3648 .dump_survey = nxpwifi_cfg80211_dump_survey,
3649 .set_wiphy_params = nxpwifi_cfg80211_set_wiphy_params,
3650 .add_key = nxpwifi_cfg80211_add_key,
3651 .del_key = nxpwifi_cfg80211_del_key,
3652 .set_default_mgmt_key = nxpwifi_cfg80211_set_default_mgmt_key,
3653 .mgmt_tx = nxpwifi_cfg80211_mgmt_tx,
3654 .update_mgmt_frame_registrations =
3655 nxpwifi_cfg80211_update_mgmt_frame_registrations,
3656 .remain_on_channel = nxpwifi_cfg80211_remain_on_channel,
3657 .cancel_remain_on_channel = nxpwifi_cfg80211_cancel_remain_on_channel,
3658 .set_default_key = nxpwifi_cfg80211_set_default_key,
3659 .set_power_mgmt = nxpwifi_cfg80211_set_power_mgmt,
3660 .set_tx_power = nxpwifi_cfg80211_set_tx_power,
3661 .get_tx_power = nxpwifi_cfg80211_get_tx_power,
3662 .set_bitrate_mask = nxpwifi_cfg80211_set_bitrate_mask,
3663 .start_ap = nxpwifi_cfg80211_start_ap,
3664 .stop_ap = nxpwifi_cfg80211_stop_ap,
3665 .change_beacon = nxpwifi_cfg80211_change_beacon,
3666 .set_cqm_rssi_config = nxpwifi_cfg80211_set_cqm_rssi_config,
3667 .set_antenna = nxpwifi_cfg80211_set_antenna,
3668 .get_antenna = nxpwifi_cfg80211_get_antenna,
3669 .del_station = nxpwifi_cfg80211_del_station,
3670 .sched_scan_start = nxpwifi_cfg80211_sched_scan_start,
3671 .sched_scan_stop = nxpwifi_cfg80211_sched_scan_stop,
3672 .change_station = nxpwifi_cfg80211_change_station,
3673 #ifdef CONFIG_PM
3674 .suspend = nxpwifi_cfg80211_suspend,
3675 .resume = nxpwifi_cfg80211_resume,
3676 .set_wakeup = nxpwifi_cfg80211_set_wakeup,
3677 #endif
3678 .set_coalesce = nxpwifi_cfg80211_set_coalesce,
3679 .add_station = nxpwifi_cfg80211_add_station,
3680 CFG80211_TESTMODE_CMD(nxpwifi_tm_cmd)
3681 .get_channel = nxpwifi_cfg80211_get_channel,
3682 .start_radar_detection = nxpwifi_cfg80211_start_radar_detection,
3683 .channel_switch = nxpwifi_cfg80211_channel_switch,
3684 };
3685
3686 #ifdef CONFIG_PM
3687 static const struct wiphy_wowlan_support nxpwifi_wowlan_support = {
3688 .flags = WIPHY_WOWLAN_MAGIC_PKT | WIPHY_WOWLAN_DISCONNECT |
3689 WIPHY_WOWLAN_NET_DETECT | WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
3690 WIPHY_WOWLAN_GTK_REKEY_FAILURE,
3691 .n_patterns = NXPWIFI_MEF_MAX_FILTERS,
3692 .pattern_min_len = 1,
3693 .pattern_max_len = NXPWIFI_MAX_PATTERN_LEN,
3694 .max_pkt_offset = NXPWIFI_MAX_OFFSET_LEN,
3695 .max_nd_match_sets = NXPWIFI_MAX_ND_MATCH_SETS,
3696 };
3697
3698 static const struct wiphy_wowlan_support nxpwifi_wowlan_support_no_gtk = {
3699 .flags = WIPHY_WOWLAN_MAGIC_PKT | WIPHY_WOWLAN_DISCONNECT |
3700 WIPHY_WOWLAN_NET_DETECT,
3701 .n_patterns = NXPWIFI_MEF_MAX_FILTERS,
3702 .pattern_min_len = 1,
3703 .pattern_max_len = NXPWIFI_MAX_PATTERN_LEN,
3704 .max_pkt_offset = NXPWIFI_MAX_OFFSET_LEN,
3705 .max_nd_match_sets = NXPWIFI_MAX_ND_MATCH_SETS,
3706 };
3707 #endif
3708
3709 static const struct wiphy_coalesce_support nxpwifi_coalesce_support = {
3710 .n_rules = NXPWIFI_COALESCE_MAX_RULES,
3711 .max_delay = NXPWIFI_MAX_COALESCING_DELAY,
3712 .n_patterns = NXPWIFI_COALESCE_MAX_FILTERS,
3713 .pattern_min_len = 1,
3714 .pattern_max_len = NXPWIFI_MAX_PATTERN_LEN,
3715 .max_pkt_offset = NXPWIFI_MAX_OFFSET_LEN,
3716 };
3717
nxpwifi_init_channel_scan_gap(struct nxpwifi_adapter * adapter)3718 int nxpwifi_init_channel_scan_gap(struct nxpwifi_adapter *adapter)
3719 {
3720 u32 n_channels_bg, n_channels_a = 0;
3721
3722 n_channels_bg = nxpwifi_band_2ghz.n_channels;
3723
3724 if (adapter->fw_bands & BAND_A)
3725 n_channels_a = nxpwifi_band_5ghz.n_channels;
3726
3727 /*
3728 * allocate twice the number total channels, since the driver issues an
3729 * additional active scan request for hidden SSIDs on passive channels.
3730 */
3731 adapter->num_in_chan_stats = 2 * (n_channels_bg + n_channels_a);
3732 adapter->chan_stats = vmalloc(array_size(sizeof(*adapter->chan_stats),
3733 adapter->num_in_chan_stats));
3734
3735 if (!adapter->chan_stats)
3736 return -ENOMEM;
3737
3738 return 0;
3739 }
3740
3741 /*
3742 * Register the device with cfg80211.
3743 *
3744 * Create and initialize the wiphy, fill in defaults and handlers,
3745 * then register it with the cfg80211 subsystem.
3746 */
nxpwifi_register_cfg80211(struct nxpwifi_adapter * adapter)3747 int nxpwifi_register_cfg80211(struct nxpwifi_adapter *adapter)
3748 {
3749 int ret;
3750 void *wdev_priv;
3751 struct wiphy *wiphy;
3752 struct nxpwifi_private *priv = adapter->priv[NXPWIFI_BSS_TYPE_STA];
3753 struct ieee80211_sta_ht_cap *ht_cap;
3754 struct ieee80211_sta_vht_cap *vht_cap;
3755 u8 *country_code;
3756 u32 thr, retry;
3757
3758 /* create a new wiphy for use with cfg80211 */
3759 wiphy = wiphy_new(&nxpwifi_cfg80211_ops,
3760 sizeof(struct nxpwifi_adapter *));
3761 if (!wiphy) {
3762 nxpwifi_dbg(adapter, ERROR,
3763 "%s: creating new wiphy\n", __func__);
3764 return -ENOMEM;
3765 }
3766
3767 wiphy->max_scan_ssids = NXPWIFI_MAX_SSID_LIST_LENGTH;
3768 wiphy->max_scan_ie_len = NXPWIFI_MAX_VSIE_LEN;
3769
3770 wiphy->mgmt_stypes = nxpwifi_mgmt_stypes;
3771 wiphy->max_remain_on_channel_duration = 5000;
3772 wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
3773 BIT(NL80211_IFTYPE_AP) |
3774 BIT(NL80211_IFTYPE_MONITOR);
3775
3776 wiphy->max_num_akm_suites = CFG80211_MAX_NUM_AKM_SUITES;
3777
3778 wiphy->bands[NL80211_BAND_2GHZ] =
3779 devm_kmemdup(adapter->dev, &nxpwifi_band_2ghz,
3780 sizeof(nxpwifi_band_2ghz), GFP_KERNEL);
3781 if (!wiphy->bands[NL80211_BAND_2GHZ]) {
3782 ret = -ENOMEM;
3783 goto err;
3784 }
3785
3786 if (adapter->fw_bands & BAND_A) {
3787 wiphy->bands[NL80211_BAND_5GHZ] =
3788 devm_kmemdup(adapter->dev, &nxpwifi_band_5ghz,
3789 sizeof(nxpwifi_band_5ghz), GFP_KERNEL);
3790 if (!wiphy->bands[NL80211_BAND_5GHZ]) {
3791 ret = -ENOMEM;
3792 goto err;
3793 }
3794 } else {
3795 wiphy->bands[NL80211_BAND_5GHZ] = NULL;
3796 }
3797
3798 ht_cap = &wiphy->bands[NL80211_BAND_2GHZ]->ht_cap;
3799 nxpwifi_setup_ht_caps(priv, ht_cap);
3800
3801 if (adapter->is_hw_11ac_capable) {
3802 vht_cap = &wiphy->bands[NL80211_BAND_2GHZ]->vht_cap;
3803 nxpwifi_setup_vht_caps(priv, vht_cap);
3804 }
3805
3806 if (adapter->is_hw_11ax_capable)
3807 nxpwifi_setup_he_caps(priv, wiphy->bands[NL80211_BAND_2GHZ]);
3808
3809 if (adapter->fw_bands & BAND_A) {
3810 ht_cap = &wiphy->bands[NL80211_BAND_5GHZ]->ht_cap;
3811 nxpwifi_setup_ht_caps(priv, ht_cap);
3812
3813 if (adapter->is_hw_11ac_capable) {
3814 vht_cap = &wiphy->bands[NL80211_BAND_5GHZ]->vht_cap;
3815 nxpwifi_setup_vht_caps(priv, vht_cap);
3816 }
3817
3818 if (adapter->is_hw_11ax_capable)
3819 nxpwifi_setup_he_caps(priv, wiphy->bands[NL80211_BAND_5GHZ]);
3820 }
3821
3822 if (adapter->is_hw_11ac_capable)
3823 wiphy->iface_combinations = &nxpwifi_iface_comb_ap_sta_vht;
3824 else
3825 wiphy->iface_combinations = &nxpwifi_iface_comb_ap_sta;
3826 wiphy->n_iface_combinations = 1;
3827
3828 wiphy->max_ap_assoc_sta = adapter->max_sta_conn;
3829
3830 /* Initialize cipher suits */
3831 wiphy->cipher_suites = nxpwifi_cipher_suites;
3832 wiphy->n_cipher_suites = ARRAY_SIZE(nxpwifi_cipher_suites);
3833
3834 if (adapter->regd) {
3835 wiphy->regulatory_flags |= REGULATORY_CUSTOM_REG |
3836 REGULATORY_DISABLE_BEACON_HINTS |
3837 REGULATORY_COUNTRY_IE_IGNORE;
3838 wiphy_apply_custom_regulatory(wiphy, adapter->regd);
3839 }
3840
3841 ether_addr_copy(wiphy->perm_addr, adapter->perm_addr);
3842 wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
3843 wiphy->flags |= WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD |
3844 WIPHY_FLAG_AP_UAPSD |
3845 WIPHY_FLAG_REPORTS_OBSS |
3846 WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL |
3847 WIPHY_FLAG_HAS_CHANNEL_SWITCH |
3848 WIPHY_FLAG_NETNS_OK |
3849 WIPHY_FLAG_PS_ON_BY_DEFAULT;
3850 wiphy->max_num_csa_counters = NXPWIFI_MAX_CSA_COUNTERS;
3851
3852 #ifdef CONFIG_PM
3853 if (ISSUPP_FIRMWARE_SUPPLICANT(priv->adapter->fw_cap_info))
3854 wiphy->wowlan = &nxpwifi_wowlan_support;
3855 else
3856 wiphy->wowlan = &nxpwifi_wowlan_support_no_gtk;
3857 #endif
3858
3859 wiphy->coalesce = &nxpwifi_coalesce_support;
3860
3861 wiphy->probe_resp_offload = NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS |
3862 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2;
3863
3864 wiphy->max_sched_scan_reqs = 1;
3865 wiphy->max_sched_scan_ssids = NXPWIFI_MAX_SSID_LIST_LENGTH;
3866 wiphy->max_sched_scan_ie_len = NXPWIFI_MAX_VSIE_LEN;
3867 wiphy->max_match_sets = NXPWIFI_MAX_SSID_LIST_LENGTH;
3868
3869 wiphy->available_antennas_tx = BIT(adapter->number_of_antenna) - 1;
3870 wiphy->available_antennas_rx = BIT(adapter->number_of_antenna) - 1;
3871
3872 wiphy->features |= NL80211_FEATURE_SAE |
3873 NL80211_FEATURE_INACTIVITY_TIMER |
3874 NL80211_FEATURE_LOW_PRIORITY_SCAN |
3875 NL80211_FEATURE_NEED_OBSS_SCAN;
3876
3877 if (ISSUPP_RANDOM_MAC(adapter->fw_cap_info))
3878 wiphy->features |= NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR |
3879 NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR |
3880 NL80211_FEATURE_ND_RANDOM_MAC_ADDR;
3881
3882 if (adapter->fw_api_ver == NXPWIFI_FW_V15)
3883 wiphy->features |= NL80211_FEATURE_SK_TX_STATUS;
3884
3885 /* Reserve space for nxpwifi specific private data for BSS */
3886 wiphy->bss_priv_size = sizeof(struct nxpwifi_bss_priv);
3887
3888 wiphy->reg_notifier = nxpwifi_reg_notifier;
3889
3890 /* Set struct nxpwifi_adapter pointer in wiphy_priv */
3891 wdev_priv = wiphy_priv(wiphy);
3892 *(unsigned long *)wdev_priv = (unsigned long)adapter;
3893
3894 set_wiphy_dev(wiphy, priv->adapter->dev);
3895
3896 ret = wiphy_register(wiphy);
3897 if (ret < 0) {
3898 nxpwifi_dbg(adapter, ERROR,
3899 "%s: wiphy_register failed: %d\n", __func__, ret);
3900 goto err;
3901 }
3902
3903 if (!adapter->regd) {
3904 if (adapter->region_code == 0x00) {
3905 nxpwifi_dbg(adapter, WARN,
3906 "Ignore world regulatory domain\n");
3907 } else {
3908 wiphy->regulatory_flags |=
3909 REGULATORY_DISABLE_BEACON_HINTS |
3910 REGULATORY_COUNTRY_IE_IGNORE;
3911 country_code =
3912 nxpwifi_11d_code_2_region(adapter->region_code);
3913 if (country_code &&
3914 regulatory_hint(wiphy, country_code))
3915 nxpwifi_dbg(priv->adapter, ERROR,
3916 "regulatory_hint() failed\n");
3917 }
3918 }
3919
3920 nxpwifi_get_802_11_snmp_mib(priv, FRAG_THRESH_I, &thr);
3921 wiphy->frag_threshold = thr;
3922 nxpwifi_get_802_11_snmp_mib(priv, RTS_THRESH_I, &thr);
3923 wiphy->rts_threshold = thr;
3924 nxpwifi_get_802_11_snmp_mib(priv, SHORT_RETRY_LIM_I, &retry);
3925 wiphy->retry_short = (u8)retry;
3926 nxpwifi_get_802_11_snmp_mib(priv, LONG_RETRY_LIM_I, &retry);
3927 wiphy->retry_long = (u8)retry;
3928
3929 adapter->wiphy = wiphy;
3930 return ret;
3931
3932 err:
3933 wiphy_free(wiphy);
3934 return ret;
3935 }
3936