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);
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 rcu_read_lock();
1543 sta_node = nxpwifi_get_sta_entry(priv, params->mac);
1544 if (sta_node)
1545 ether_addr_copy(deauth_mac, params->mac);
1546 rcu_read_unlock();
1547
1548 if (is_valid_ether_addr(deauth_mac)) {
1549 ret = nxpwifi_uap_sta_deauth(priv, deauth_mac);
1550 nxpwifi_del_sta_entry(priv, deauth_mac);
1551 }
1552 return ret;
1553 }
1554
1555 static int
nxpwifi_cfg80211_set_antenna(struct wiphy * wiphy,int radio_idx,u32 tx_ant,u32 rx_ant)1556 nxpwifi_cfg80211_set_antenna(struct wiphy *wiphy, int radio_idx, u32 tx_ant, u32 rx_ant)
1557 {
1558 struct nxpwifi_adapter *adapter = nxpwifi_cfg80211_get_adapter(wiphy);
1559 struct nxpwifi_private *priv = nxpwifi_get_priv(adapter,
1560 NXPWIFI_BSS_ROLE_ANY);
1561 struct nxpwifi_ds_ant_cfg ant_cfg;
1562
1563 if (!tx_ant || !rx_ant)
1564 return -EOPNOTSUPP;
1565
1566 if (adapter->hw_dev_mcs_support != HT_STREAM_2X2) {
1567 /*
1568 * Not a MIMO chip. User should provide specific antenna number
1569 * for Tx/Rx path or enable all antennas for diversity
1570 */
1571 if (tx_ant != rx_ant)
1572 return -EOPNOTSUPP;
1573
1574 if ((tx_ant & (tx_ant - 1)) &&
1575 (tx_ant != BIT(adapter->number_of_antenna) - 1))
1576 return -EOPNOTSUPP;
1577
1578 if ((tx_ant == BIT(adapter->number_of_antenna) - 1) &&
1579 priv->adapter->number_of_antenna > 1) {
1580 tx_ant = RF_ANTENNA_AUTO;
1581 rx_ant = RF_ANTENNA_AUTO;
1582 }
1583 } else {
1584 struct ieee80211_sta_ht_cap *ht_info;
1585 int rx_mcs_supp;
1586 enum nl80211_band band;
1587
1588 if ((tx_ant == 0x1 && rx_ant == 0x1)) {
1589 adapter->user_dev_mcs_support = HT_STREAM_1X1;
1590 if (adapter->is_hw_11ac_capable)
1591 adapter->usr_dot_11ac_mcs_support =
1592 NXPWIFI_11AC_MCS_MAP_1X1;
1593 } else {
1594 adapter->user_dev_mcs_support = HT_STREAM_2X2;
1595 if (adapter->is_hw_11ac_capable)
1596 adapter->usr_dot_11ac_mcs_support =
1597 NXPWIFI_11AC_MCS_MAP_2X2;
1598 }
1599
1600 for (band = 0; band < NUM_NL80211_BANDS; band++) {
1601 if (!adapter->wiphy->bands[band])
1602 continue;
1603
1604 ht_info = &adapter->wiphy->bands[band]->ht_cap;
1605 rx_mcs_supp =
1606 GET_RXMCSSUPP(adapter->user_dev_mcs_support);
1607 memset(&ht_info->mcs, 0, adapter->number_of_antenna);
1608 memset(&ht_info->mcs, 0xff, rx_mcs_supp);
1609 }
1610 }
1611
1612 ant_cfg.tx_ant = tx_ant;
1613 ant_cfg.rx_ant = rx_ant;
1614
1615 return nxpwifi_set_rf_antenna(priv, &ant_cfg);
1616 }
1617
1618 static int
nxpwifi_cfg80211_get_antenna(struct wiphy * wiphy,int radio_idx,u32 * tx_ant,u32 * rx_ant)1619 nxpwifi_cfg80211_get_antenna(struct wiphy *wiphy, int radio_idx, u32 *tx_ant, u32 *rx_ant)
1620 {
1621 struct nxpwifi_adapter *adapter = nxpwifi_cfg80211_get_adapter(wiphy);
1622 struct nxpwifi_private *priv = nxpwifi_get_priv(adapter,
1623 NXPWIFI_BSS_ROLE_ANY);
1624 int ret;
1625
1626 ret = nxpwifi_get_rf_antenna(priv, tx_ant, rx_ant);
1627
1628 return ret;
1629 }
1630
1631 /*
1632 * cfg80211 op: stop AP.
1633 * Stops the BSS running on the uAP interface.
1634 */
nxpwifi_cfg80211_stop_ap(struct wiphy * wiphy,struct net_device * dev,unsigned int link_id)1635 static int nxpwifi_cfg80211_stop_ap(struct wiphy *wiphy, struct net_device *dev,
1636 unsigned int link_id)
1637 {
1638 struct nxpwifi_private *priv = nxpwifi_netdev_get_priv(dev);
1639 int ret;
1640
1641 nxpwifi_abort_cac(priv);
1642
1643 if (nxpwifi_del_mgmt_ies(priv))
1644 nxpwifi_dbg(priv->adapter, ERROR,
1645 "Failed to delete mgmt IEs!\n");
1646
1647 priv->ap_11n_enabled = 0;
1648 memset(&priv->bss_cfg, 0, sizeof(priv->bss_cfg));
1649
1650 ret = nxpwifi_ap_stop_bss(priv);
1651 if (ret) {
1652 nxpwifi_dbg(priv->adapter, ERROR,
1653 "Failed to stop the BSS\n");
1654 goto done;
1655 }
1656
1657 ret = nxpwifi_ap_sys_reset(priv);
1658 if (ret) {
1659 nxpwifi_dbg(priv->adapter, ERROR,
1660 "Failed to reset BSS\n");
1661 goto done;
1662 }
1663
1664 netif_carrier_off(priv->netdev);
1665 nxpwifi_stop_net_dev_queue(priv->netdev, priv->adapter);
1666
1667 if (atomic_dec_and_test(&priv->adapter->uap_count)) {
1668 priv->adapter->chandef_valid = false;
1669 memset(&priv->adapter->chandef, 0, sizeof(priv->adapter->chandef));
1670 }
1671
1672 done:
1673 return ret;
1674 }
1675
1676 /*
1677 * cfg80211 op: start AP.
1678 * Applies beacon/DTIM/SSID/security settings to the uAP configuration and
1679 * starts the BSS.
1680 */
nxpwifi_cfg80211_start_ap(struct wiphy * wiphy,struct net_device * dev,struct cfg80211_ap_settings * params)1681 static int nxpwifi_cfg80211_start_ap(struct wiphy *wiphy,
1682 struct net_device *dev,
1683 struct cfg80211_ap_settings *params)
1684 {
1685 struct nxpwifi_uap_bss_param *bss_cfg;
1686 struct nxpwifi_private *priv = nxpwifi_netdev_get_priv(dev);
1687 struct nxpwifi_adapter *adapter = priv->adapter;
1688 struct cfg80211_chan_def use_chandef;
1689 bool is_first_uap = false;
1690 int ret;
1691
1692 /*
1693 * Adapter is the HW channel owner (single PHY).
1694 * All UAP interfaces on the same adapter must share
1695 * the same RF channel.
1696 */
1697 use_chandef = params->chandef;
1698
1699 if (adapter->chandef_valid) {
1700 if (!cfg80211_chandef_identical(&adapter->chandef,
1701 ¶ms->chandef)) {
1702 nxpwifi_dbg(adapter, INFO,
1703 "UAP already running on channel %d, ignore requested channel %d\n",
1704 adapter->chandef.chan->hw_value,
1705 params->chandef.chan->hw_value);
1706 }
1707 use_chandef = adapter->chandef;
1708 } else {
1709 is_first_uap = true;
1710 }
1711
1712 if (GET_BSS_ROLE(priv) != NXPWIFI_BSS_ROLE_UAP)
1713 return -EINVAL;
1714
1715 if (!nxpwifi_is_channel_setting_allowable(priv, params->chandef.chan))
1716 return -EOPNOTSUPP;
1717
1718 bss_cfg = kzalloc_obj(*bss_cfg);
1719 if (!bss_cfg)
1720 return -ENOMEM;
1721
1722 nxpwifi_set_sys_config_invalid_data(bss_cfg);
1723
1724 memcpy(bss_cfg->mac_addr, priv->curr_addr, ETH_ALEN);
1725
1726 if (params->beacon_interval)
1727 bss_cfg->beacon_period = params->beacon_interval;
1728 if (params->dtim_period)
1729 bss_cfg->dtim_period = params->dtim_period;
1730
1731 if (params->ssid && params->ssid_len) {
1732 memcpy(bss_cfg->ssid.ssid, params->ssid, params->ssid_len);
1733 bss_cfg->ssid.ssid_len = params->ssid_len;
1734 }
1735 if (params->inactivity_timeout > 0) {
1736 /* sta_ao_timer/ps_sta_ao_timer is in unit of 100ms */
1737 bss_cfg->sta_ao_timer = 10 * params->inactivity_timeout;
1738 bss_cfg->ps_sta_ao_timer = 10 * params->inactivity_timeout;
1739 }
1740
1741 /* Default: SSID is visible */
1742 bss_cfg->bcast_ssid_ctl = NXPWIFI_BCAST_SSID_VISIBLE;
1743
1744 switch (params->hidden_ssid) {
1745 case NL80211_HIDDEN_SSID_NOT_IN_USE:
1746 bss_cfg->bcast_ssid_ctl = NXPWIFI_BCAST_SSID_VISIBLE;
1747 break;
1748 case NL80211_HIDDEN_SSID_ZERO_LEN:
1749 bss_cfg->bcast_ssid_ctl = NXPWIFI_BCAST_SSID_HIDE_LEN_ZERO;
1750 break;
1751 case NL80211_HIDDEN_SSID_ZERO_CONTENTS:
1752 bss_cfg->bcast_ssid_ctl = NXPWIFI_BCAST_SSID_HIDE_LEN_RETAIN;
1753 break;
1754 }
1755
1756 nxpwifi_uap_set_channel(priv, bss_cfg, use_chandef);
1757 nxpwifi_set_uap_rates(bss_cfg, params);
1758
1759 ret = nxpwifi_set_secure_params(priv, bss_cfg, params);
1760 if (ret) {
1761 nxpwifi_dbg(adapter, ERROR,
1762 "Failed to parse security parameters!\n");
1763 goto done;
1764 }
1765
1766 nxpwifi_set_ht_params(priv, bss_cfg, params);
1767
1768 if (adapter->is_hw_11ac_capable) {
1769 nxpwifi_set_vht_params(priv, bss_cfg, params);
1770 nxpwifi_set_vht_width(priv, use_chandef.width,
1771 priv->ap_11ac_enabled);
1772 }
1773
1774 if (priv->ap_11ac_enabled)
1775 nxpwifi_set_11ac_ba_params(priv);
1776 else
1777 nxpwifi_set_ba_params(priv);
1778
1779 if (adapter->is_hw_11ax_capable) {
1780 priv->ap_11ax_enabled =
1781 nxpwifi_check_11ax_capability(priv, bss_cfg, params);
1782 if (priv->ap_11ax_enabled)
1783 nxpwifi_set_11ax_status(priv, bss_cfg, params);
1784 }
1785
1786 nxpwifi_set_wmm_params(priv, bss_cfg, params);
1787
1788 if (nxpwifi_is_11h_active(priv))
1789 nxpwifi_set_tpc_params(priv, bss_cfg, params);
1790
1791 if (nxpwifi_is_11h_active(priv) &&
1792 !cfg80211_chandef_dfs_required(wiphy, ¶ms->chandef,
1793 priv->bss_mode)) {
1794 nxpwifi_dbg(priv->adapter, INFO,
1795 "Disable 11h extensions in FW\n");
1796 ret = nxpwifi_11h_activate(priv, false);
1797 if (ret) {
1798 nxpwifi_dbg(priv->adapter, ERROR,
1799 "Failed to disable 11h extensions!!");
1800 goto done;
1801 }
1802 priv->state_11h.is_11h_active = false;
1803 }
1804
1805 nxpwifi_config_uap_11d(priv, ¶ms->beacon);
1806
1807 ret = nxpwifi_set_mgmt_ies(priv, ¶ms->beacon);
1808 if (ret)
1809 goto done;
1810
1811 ret = nxpwifi_config_start_uap(priv, bss_cfg);
1812 if (ret) {
1813 nxpwifi_dbg(priv->adapter, ERROR,
1814 "Failed to start AP\n");
1815 goto done;
1816 }
1817
1818 /* First UAP records adapter-level HW channel */
1819 if (is_first_uap) {
1820 adapter->chandef = use_chandef;
1821 adapter->chandef_valid = true;
1822 }
1823 atomic_inc(&adapter->uap_count);
1824 netif_carrier_on(priv->netdev);
1825 nxpwifi_wake_up_net_dev_queue(priv->netdev, priv->adapter);
1826
1827 memcpy(&priv->bss_cfg, bss_cfg, sizeof(priv->bss_cfg));
1828
1829 done:
1830 kfree(bss_cfg);
1831 return ret;
1832 }
1833
1834 /*
1835 * cfg80211 op: handle scan request.
1836 * Issues a firmware scan using the requested parameters and reports the
1837 * results.
1838 */
1839 static int
nxpwifi_cfg80211_scan(struct wiphy * wiphy,struct cfg80211_scan_request * request)1840 nxpwifi_cfg80211_scan(struct wiphy *wiphy,
1841 struct cfg80211_scan_request *request)
1842 {
1843 struct net_device *dev = request->wdev->netdev;
1844 struct nxpwifi_private *priv = nxpwifi_netdev_get_priv(dev);
1845 int i, offset, ret;
1846 struct ieee80211_channel *chan;
1847 struct element *ie;
1848 struct nxpwifi_user_scan_cfg *user_scan_cfg;
1849 u8 mac_addr[ETH_ALEN];
1850
1851 nxpwifi_dbg(priv->adapter, CMD,
1852 "info: received scan request on %s\n", dev->name);
1853
1854 /*
1855 * Block scan requests during active scanning or scan cleanup.
1856 * Prevents new scans when the interface is disabled or teardown is in
1857 * progress.
1858 */
1859 if (priv->scan_request || priv->scan_aborting) {
1860 nxpwifi_dbg(priv->adapter, WARN,
1861 "cmd: Scan already in process..\n");
1862 return -EBUSY;
1863 }
1864
1865 if (!priv->wdev.connected && priv->scan_block)
1866 priv->scan_block = false;
1867
1868 if (!nxpwifi_stop_bg_scan(priv))
1869 cfg80211_sched_scan_stopped_locked(priv->wdev.wiphy, 0);
1870
1871 user_scan_cfg = kzalloc_obj(*user_scan_cfg);
1872 if (!user_scan_cfg)
1873 return -ENOMEM;
1874
1875 priv->scan_request = request;
1876
1877 if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) {
1878 get_random_mask_addr(mac_addr, request->mac_addr,
1879 request->mac_addr_mask);
1880 ether_addr_copy(request->mac_addr, mac_addr);
1881 ether_addr_copy(user_scan_cfg->random_mac, mac_addr);
1882 }
1883
1884 user_scan_cfg->num_ssids = request->n_ssids;
1885 user_scan_cfg->ssid_list = request->ssids;
1886
1887 if (request->ie && request->ie_len) {
1888 offset = 0;
1889 for (i = 0; i < NXPWIFI_MAX_VSIE_NUM; i++) {
1890 if (priv->vs_ie[i].mask != NXPWIFI_VSIE_MASK_CLEAR)
1891 continue;
1892 priv->vs_ie[i].mask = NXPWIFI_VSIE_MASK_SCAN;
1893 ie = (struct element *)(request->ie + offset);
1894 memcpy(&priv->vs_ie[i].ie, ie,
1895 sizeof(*ie) + ie->datalen);
1896 offset += sizeof(*ie) + ie->datalen;
1897
1898 if (offset >= request->ie_len)
1899 break;
1900 }
1901 }
1902
1903 for (i = 0; i < min_t(u32, request->n_channels,
1904 NXPWIFI_USER_SCAN_CHAN_MAX); i++) {
1905 chan = request->channels[i];
1906 user_scan_cfg->chan_list[i].chan_number = chan->hw_value;
1907 user_scan_cfg->chan_list[i].radio_type = chan->band;
1908
1909 if ((chan->flags & IEEE80211_CHAN_NO_IR) || !request->n_ssids)
1910 user_scan_cfg->chan_list[i].scan_type =
1911 NXPWIFI_SCAN_TYPE_PASSIVE;
1912 else
1913 user_scan_cfg->chan_list[i].scan_type =
1914 NXPWIFI_SCAN_TYPE_ACTIVE;
1915
1916 user_scan_cfg->chan_list[i].scan_time = 0;
1917 }
1918
1919 if (priv->adapter->scan_chan_gap_enabled &&
1920 nxpwifi_is_any_intf_active(priv))
1921 user_scan_cfg->scan_chan_gap =
1922 priv->adapter->scan_chan_gap_time;
1923
1924 ret = nxpwifi_scan_networks(priv, user_scan_cfg);
1925 kfree(user_scan_cfg);
1926 if (ret) {
1927 nxpwifi_dbg(priv->adapter, ERROR,
1928 "scan failed: %d\n", ret);
1929 priv->scan_aborting = false;
1930 priv->scan_request = NULL;
1931 return ret;
1932 }
1933
1934 if (request->ie && request->ie_len) {
1935 for (i = 0; i < NXPWIFI_MAX_VSIE_NUM; i++) {
1936 if (priv->vs_ie[i].mask == NXPWIFI_VSIE_MASK_SCAN) {
1937 priv->vs_ie[i].mask = NXPWIFI_VSIE_MASK_CLEAR;
1938 memset(&priv->vs_ie[i].ie, 0,
1939 NXPWIFI_MAX_VSIE_LEN);
1940 }
1941 }
1942 }
1943 return 0;
1944 }
1945
1946 /*
1947 * cfg80211 sched_scan_start handler.
1948 *
1949 * Send a bgscan configuration request to the firmware based on the
1950 * scheduled scan parameters. On success, the firmware later issues a
1951 * BGSCAN_REPORT event, after which the driver should query the firmware
1952 * for scan results.
1953 */
1954 static int
nxpwifi_cfg80211_sched_scan_start(struct wiphy * wiphy,struct net_device * dev,struct cfg80211_sched_scan_request * request)1955 nxpwifi_cfg80211_sched_scan_start(struct wiphy *wiphy,
1956 struct net_device *dev,
1957 struct cfg80211_sched_scan_request *request)
1958 {
1959 struct nxpwifi_private *priv = nxpwifi_netdev_get_priv(dev);
1960 int i, offset;
1961 struct ieee80211_channel *chan;
1962 struct nxpwifi_bg_scan_cfg *bgscan_cfg;
1963 struct element *ie;
1964 int ret;
1965
1966 if (!request || (!request->n_ssids && !request->n_match_sets)) {
1967 wiphy_err(wiphy, "%s : Invalid Sched_scan parameters",
1968 __func__);
1969 return -EINVAL;
1970 }
1971
1972 wiphy_info(wiphy, "sched_scan start : n_ssids=%d n_match_sets=%d ",
1973 request->n_ssids, request->n_match_sets);
1974 wiphy_info(wiphy, "n_channels=%d interval=%d ie_len=%d\n",
1975 request->n_channels, request->scan_plans->interval,
1976 (int)request->ie_len);
1977
1978 bgscan_cfg = kzalloc_obj(*bgscan_cfg);
1979 if (!bgscan_cfg)
1980 return -ENOMEM;
1981
1982 if (priv->scan_request || priv->scan_aborting)
1983 bgscan_cfg->start_later = true;
1984
1985 bgscan_cfg->num_ssids = request->n_match_sets;
1986 bgscan_cfg->ssid_list = request->match_sets;
1987
1988 if (request->ie && request->ie_len) {
1989 offset = 0;
1990 for (i = 0; i < NXPWIFI_MAX_VSIE_NUM; i++) {
1991 if (priv->vs_ie[i].mask != NXPWIFI_VSIE_MASK_CLEAR)
1992 continue;
1993 priv->vs_ie[i].mask = NXPWIFI_VSIE_MASK_BGSCAN;
1994 ie = (struct element *)(request->ie + offset);
1995 memcpy(&priv->vs_ie[i].ie, ie,
1996 sizeof(*ie) + ie->datalen);
1997 offset += sizeof(*ie) + ie->datalen;
1998
1999 if (offset >= request->ie_len)
2000 break;
2001 }
2002 }
2003
2004 for (i = 0; i < min_t(u32, request->n_channels,
2005 NXPWIFI_BG_SCAN_CHAN_MAX); i++) {
2006 chan = request->channels[i];
2007 bgscan_cfg->chan_list[i].chan_number = chan->hw_value;
2008 bgscan_cfg->chan_list[i].radio_type = chan->band;
2009
2010 if ((chan->flags & IEEE80211_CHAN_NO_IR) || !request->n_ssids)
2011 bgscan_cfg->chan_list[i].scan_type =
2012 NXPWIFI_SCAN_TYPE_PASSIVE;
2013 else
2014 bgscan_cfg->chan_list[i].scan_type =
2015 NXPWIFI_SCAN_TYPE_ACTIVE;
2016
2017 bgscan_cfg->chan_list[i].scan_time = 0;
2018 }
2019
2020 bgscan_cfg->chan_per_scan = min_t(u32, request->n_channels,
2021 NXPWIFI_BG_SCAN_CHAN_MAX);
2022
2023 /* Minimum scan cycle duration: 15 seconds */
2024 bgscan_cfg->scan_interval = (request->scan_plans->interval >
2025 NXPWIFI_BGSCAN_INTERVAL) ?
2026 request->scan_plans->interval :
2027 NXPWIFI_BGSCAN_INTERVAL;
2028
2029 bgscan_cfg->repeat_count = NXPWIFI_BGSCAN_REPEAT_COUNT;
2030 bgscan_cfg->report_condition = NXPWIFI_BGSCAN_SSID_MATCH |
2031 NXPWIFI_BGSCAN_WAIT_ALL_CHAN_DONE;
2032 bgscan_cfg->bss_type = NXPWIFI_BSS_MODE_INFRA;
2033 bgscan_cfg->action = NXPWIFI_BGSCAN_ACT_SET;
2034 bgscan_cfg->enable = true;
2035 if (request->min_rssi_thold != NL80211_SCAN_RSSI_THOLD_OFF) {
2036 bgscan_cfg->report_condition |= NXPWIFI_BGSCAN_SSID_RSSI_MATCH;
2037 bgscan_cfg->rssi_threshold = request->min_rssi_thold;
2038 }
2039
2040 ret = nxpwifi_bg_scan_config(priv, bgscan_cfg);
2041
2042 if (!ret)
2043 priv->sched_scanning = true;
2044
2045 kfree(bgscan_cfg);
2046 return ret;
2047 }
2048
2049 /*
2050 * cfg80211 sched_scan_stop handler.
2051 *
2052 * Send a bgscan configuration command to disable the previous
2053 * background scan settings in the firmware.
2054 */
nxpwifi_cfg80211_sched_scan_stop(struct wiphy * wiphy,struct net_device * dev,u64 reqid)2055 static int nxpwifi_cfg80211_sched_scan_stop(struct wiphy *wiphy,
2056 struct net_device *dev, u64 reqid)
2057 {
2058 struct nxpwifi_private *priv = nxpwifi_netdev_get_priv(dev);
2059
2060 wiphy_info(wiphy, "sched scan stop!");
2061 return nxpwifi_stop_bg_scan(priv);
2062 }
2063
2064 /*
2065 * Set default cfg80211 HT capabilities.
2066 */
2067 static void
nxpwifi_setup_ht_caps(struct nxpwifi_private * priv,struct ieee80211_sta_ht_cap * ht_info)2068 nxpwifi_setup_ht_caps(struct nxpwifi_private *priv,
2069 struct ieee80211_sta_ht_cap *ht_info)
2070 {
2071 int rx_mcs_supp;
2072 struct ieee80211_mcs_info mcs_set;
2073 u8 *mcs = (u8 *)&mcs_set;
2074 struct nxpwifi_adapter *adapter = priv->adapter;
2075
2076 ht_info->ht_supported = true;
2077 ht_info->ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
2078 ht_info->ampdu_density = IEEE80211_HT_MPDU_DENSITY_NONE;
2079
2080 memset(&ht_info->mcs, 0, sizeof(ht_info->mcs));
2081
2082 /* Fill HT capability information */
2083 if (ISSUPP_CHANWIDTH40(adapter->hw_dot_11n_dev_cap))
2084 ht_info->cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
2085 else
2086 ht_info->cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
2087
2088 if (ISSUPP_SHORTGI20(adapter->hw_dot_11n_dev_cap))
2089 ht_info->cap |= IEEE80211_HT_CAP_SGI_20;
2090 else
2091 ht_info->cap &= ~IEEE80211_HT_CAP_SGI_20;
2092
2093 if (ISSUPP_SHORTGI40(adapter->hw_dot_11n_dev_cap))
2094 ht_info->cap |= IEEE80211_HT_CAP_SGI_40;
2095 else
2096 ht_info->cap &= ~IEEE80211_HT_CAP_SGI_40;
2097
2098 if (adapter->user_dev_mcs_support == HT_STREAM_2X2)
2099 ht_info->cap |= 2 << IEEE80211_HT_CAP_RX_STBC_SHIFT;
2100 else
2101 ht_info->cap |= 1 << IEEE80211_HT_CAP_RX_STBC_SHIFT;
2102
2103 if (ISSUPP_TXSTBC(adapter->hw_dot_11n_dev_cap))
2104 ht_info->cap |= IEEE80211_HT_CAP_TX_STBC;
2105 else
2106 ht_info->cap &= ~IEEE80211_HT_CAP_TX_STBC;
2107
2108 if (ISSUPP_GREENFIELD(adapter->hw_dot_11n_dev_cap))
2109 ht_info->cap |= IEEE80211_HT_CAP_GRN_FLD;
2110 else
2111 ht_info->cap &= ~IEEE80211_HT_CAP_GRN_FLD;
2112
2113 if (ISENABLED_40MHZ_INTOLERANT(adapter->hw_dot_11n_dev_cap))
2114 ht_info->cap |= IEEE80211_HT_CAP_40MHZ_INTOLERANT;
2115 else
2116 ht_info->cap &= ~IEEE80211_HT_CAP_40MHZ_INTOLERANT;
2117
2118 if (ISSUPP_RXLDPC(adapter->hw_dot_11n_dev_cap))
2119 ht_info->cap |= IEEE80211_HT_CAP_LDPC_CODING;
2120 else
2121 ht_info->cap &= ~IEEE80211_HT_CAP_LDPC_CODING;
2122
2123 ht_info->cap &= ~IEEE80211_HT_CAP_MAX_AMSDU;
2124 ht_info->cap |= IEEE80211_HT_CAP_SM_PS;
2125
2126 rx_mcs_supp = GET_RXMCSSUPP(adapter->user_dev_mcs_support);
2127 /* Set MCS for 1x1/2x2 */
2128 memset(mcs, 0xff, rx_mcs_supp);
2129 /* Clear all the other values */
2130 memset(&mcs[rx_mcs_supp], 0,
2131 sizeof(struct ieee80211_mcs_info) - rx_mcs_supp);
2132 if (priv->bss_mode == NL80211_IFTYPE_STATION ||
2133 ISSUPP_CHANWIDTH40(adapter->hw_dot_11n_dev_cap))
2134 /* Set MCS32 for infra mode or ad-hoc mode with 40MHz support */
2135 SETHT_MCS32(mcs_set.rx_mask);
2136
2137 memcpy((u8 *)&ht_info->mcs, mcs, sizeof(struct ieee80211_mcs_info));
2138
2139 ht_info->mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED;
2140 }
2141
2142 static void
nxpwifi_setup_vht_caps(struct nxpwifi_private * priv,struct ieee80211_sta_vht_cap * vht_info)2143 nxpwifi_setup_vht_caps(struct nxpwifi_private *priv,
2144 struct ieee80211_sta_vht_cap *vht_info)
2145 {
2146 struct nxpwifi_adapter *adapter = priv->adapter;
2147
2148 vht_info->vht_supported = true;
2149
2150 vht_info->cap = adapter->hw_dot_11ac_dev_cap;
2151 /* Update MCS support for VHT */
2152 vht_info->vht_mcs.rx_mcs_map =
2153 cpu_to_le16(adapter->hw_dot_11ac_mcs_support & 0xFFFF);
2154 vht_info->vht_mcs.rx_highest = 0;
2155 vht_info->vht_mcs.tx_mcs_map =
2156 cpu_to_le16(adapter->hw_dot_11ac_mcs_support >> 16);
2157 vht_info->vht_mcs.tx_highest = 0;
2158 }
2159
2160 /*
2161 * 5 GHz HE capability masks for UAP mode.
2162 *
2163 * MAC: TWT requester/respondor, broadcast TWT, OMI control.
2164 *
2165 * PHY: 40/80 MHz width, puncturing, LDPC, NDP 4xLTF, STBC,
2166 * Doppler, DCM, SU BF/BFe, STS, sounding dims, extended
2167 * range, PPE present, 4xLTF 0.8us GI, Rx 1024-QAM.
2168 */
2169 #define UAP_HE_MAC_CAP0_MASK (IEEE80211_HE_MAC_CAP0_TWT_REQ | \
2170 IEEE80211_HE_MAC_CAP0_TWT_RES)
2171
2172 #define UAP_HE_MAC_CAP1_MASK 0
2173 #define UAP_HE_MAC_CAP2_MASK IEEE80211_HE_MAC_CAP2_BCAST_TWT
2174 #define UAP_HE_MAC_CAP3_MASK IEEE80211_HE_MAC_CAP3_OMI_CONTROL
2175 #define UAP_HE_MAC_CAP4_MASK 0
2176 #define UAP_HE_MAC_CAP5_MASK 0
2177
2178 #define UAP_HE_PHY_CAP0_MASK IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_40MHZ_80MHZ_IN_5G
2179 #define UAP_HE_PHY_CAP1_MASK (IEEE80211_HE_PHY_CAP1_LDPC_CODING_IN_PAYLOAD | \
2180 IEEE80211_HE_PHY_CAP1_PREAMBLE_PUNC_RX_80MHZ_ONLY_SECOND_20MHZ | \
2181 IEEE80211_HE_PHY_CAP1_PREAMBLE_PUNC_RX_80MHZ_ONLY_SECOND_40MHZ)
2182 #define UAP_HE_PHY_CAP2_MASK (IEEE80211_HE_PHY_CAP2_NDP_4x_LTF_AND_3_2US | \
2183 IEEE80211_HE_PHY_CAP2_STBC_TX_UNDER_80MHZ | \
2184 IEEE80211_HE_PHY_CAP2_STBC_RX_UNDER_80MHZ | \
2185 IEEE80211_HE_PHY_CAP2_DOPPLER_TX | \
2186 IEEE80211_HE_PHY_CAP2_DOPPLER_RX)
2187 #define UAP_HE_PHY_CAP3_MASK (IEEE80211_HE_PHY_CAP3_DCM_MAX_CONST_TX_BPSK | \
2188 IEEE80211_HE_PHY_CAP3_DCM_MAX_TX_NSS_1 | \
2189 IEEE80211_HE_PHY_CAP3_DCM_MAX_CONST_RX_BPSK | \
2190 IEEE80211_HE_PHY_CAP3_DCM_MAX_RX_NSS_1 | \
2191 IEEE80211_HE_PHY_CAP3_SU_BEAMFORMER)
2192 #define UAP_HE_PHY_CAP4_MASK (IEEE80211_HE_PHY_CAP4_SU_BEAMFORMEE | \
2193 IEEE80211_HE_PHY_CAP4_BEAMFORMEE_MAX_STS_UNDER_80MHZ_8)
2194 #define UAP_HE_PHY_CAP5_MASK IEEE80211_HE_PHY_CAP5_BEAMFORMEE_NUM_SND_DIM_UNDER_80MHZ_2
2195 #define UAP_HE_PHY_CAP6_MASK (IEEE80211_HE_PHY_CAP6_PARTIAL_BW_EXT_RANGE | \
2196 IEEE80211_HE_PHY_CAP6_PPE_THRESHOLD_PRESENT)
2197 #define UAP_HE_PHY_CAP7_MASK (IEEE80211_HE_PHY_CAP7_HE_SU_MU_PPDU_4XLTF_AND_08_US_GI | \
2198 IEEE80211_HE_PHY_CAP7_MAX_NC_1)
2199 #define UAP_HE_PHY_CAP8_MASK 0
2200 #define UAP_HE_PHY_CAP9_MASK IEEE80211_HE_PHY_CAP9_RX_1024_QAM_LESS_THAN_242_TONE_RU
2201 #define UAP_HE_PHY_CAP10_MASK 0
2202
2203 /*
2204 * 2.4 GHz HE capability masks for UAP mode.
2205 *
2206 * MAC: HTC HE, OMI control (no UL OFDMA).
2207 * PHY: 40 MHz, LDPC, NDP 4xLTF, STBC, Doppler, DCM,
2208 * SU BF/BFe, STS/sounding dims, extended range,
2209 * PPE present, 4xLTF 0.8us GI, Rx 1024-QAM.
2210 */
2211 #define UAP_HE_2G_MAC_CAP0_MASK 0x00
2212 #define UAP_HE_2G_MAC_CAP1_MASK 0x00
2213 #define UAP_HE_2G_MAC_CAP2_MASK 0x00
2214 #define UAP_HE_2G_MAC_CAP3_MASK IEEE80211_HE_MAC_CAP3_OMI_CONTROL
2215 #define UAP_HE_2G_MAC_CAP4_MASK 0x00
2216 #define UAP_HE_2G_MAC_CAP5_MASK 0x00
2217
2218 #define UAP_HE_2G_PHY_CAP0_MASK IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_40MHZ_IN_2G
2219 #define UAP_HE_2G_PHY_CAP1_MASK IEEE80211_HE_PHY_CAP1_LDPC_CODING_IN_PAYLOAD
2220 #define UAP_HE_2G_PHY_CAP2_MASK (IEEE80211_HE_PHY_CAP2_NDP_4x_LTF_AND_3_2US | \
2221 IEEE80211_HE_PHY_CAP2_STBC_TX_UNDER_80MHZ | \
2222 IEEE80211_HE_PHY_CAP2_STBC_RX_UNDER_80MHZ | \
2223 IEEE80211_HE_PHY_CAP2_DOPPLER_TX | \
2224 IEEE80211_HE_PHY_CAP2_DOPPLER_RX)
2225 #define UAP_HE_2G_PHY_CAP3_MASK (IEEE80211_HE_PHY_CAP3_DCM_MAX_CONST_TX_BPSK | \
2226 IEEE80211_HE_PHY_CAP3_DCM_MAX_TX_NSS_1 | \
2227 IEEE80211_HE_PHY_CAP3_DCM_MAX_CONST_RX_BPSK | \
2228 IEEE80211_HE_PHY_CAP3_DCM_MAX_RX_NSS_1 | \
2229 IEEE80211_HE_PHY_CAP3_SU_BEAMFORMER)
2230 #define UAP_HE_2G_PHY_CAP4_MASK (IEEE80211_HE_PHY_CAP4_SU_BEAMFORMEE | \
2231 IEEE80211_HE_PHY_CAP4_BEAMFORMEE_MAX_STS_UNDER_80MHZ_8)
2232 #define UAP_HE_2G_PHY_CAP5_MASK IEEE80211_HE_PHY_CAP5_BEAMFORMEE_NUM_SND_DIM_UNDER_80MHZ_2
2233 #define UAP_HE_2G_PHY_CAP6_MASK (IEEE80211_HE_PHY_CAP6_PARTIAL_BW_EXT_RANGE | \
2234 IEEE80211_HE_PHY_CAP6_PPE_THRESHOLD_PRESENT)
2235 #define UAP_HE_2G_PHY_CAP7_MASK (IEEE80211_HE_PHY_CAP7_HE_SU_MU_PPDU_4XLTF_AND_08_US_GI | \
2236 IEEE80211_HE_PHY_CAP7_MAX_NC_1)
2237 #define UAP_HE_2G_PHY_CAP8_MASK 0x00
2238 #define UAP_HE_2G_PHY_CAP9_MASK IEEE80211_HE_PHY_CAP9_RX_1024_QAM_LESS_THAN_242_TONE_RU
2239 #define UAP_HE_2G_PHY_CAP10_MASK 0x00
2240 #define HE_CAP_FIX_SIZE 22
2241
2242 static void
nxpwifi_update_11ax_ie(u8 band,struct nxpwifi_11ax_he_cap_cfg * he_cap_cfg)2243 nxpwifi_update_11ax_ie(u8 band,
2244 struct nxpwifi_11ax_he_cap_cfg *he_cap_cfg)
2245 {
2246 if (band == BAND_A) {
2247 he_cap_cfg->cap_elem.mac_cap_info[0] &= UAP_HE_MAC_CAP0_MASK;
2248 he_cap_cfg->cap_elem.mac_cap_info[1] &= UAP_HE_MAC_CAP1_MASK;
2249 he_cap_cfg->cap_elem.mac_cap_info[2] &= UAP_HE_MAC_CAP2_MASK;
2250 he_cap_cfg->cap_elem.mac_cap_info[3] &= UAP_HE_MAC_CAP3_MASK;
2251 he_cap_cfg->cap_elem.mac_cap_info[4] &= UAP_HE_MAC_CAP4_MASK;
2252 he_cap_cfg->cap_elem.mac_cap_info[5] &= UAP_HE_MAC_CAP5_MASK;
2253 he_cap_cfg->cap_elem.phy_cap_info[0] &= UAP_HE_PHY_CAP0_MASK;
2254 he_cap_cfg->cap_elem.phy_cap_info[1] &= UAP_HE_PHY_CAP1_MASK;
2255 he_cap_cfg->cap_elem.phy_cap_info[2] &= UAP_HE_PHY_CAP2_MASK;
2256 he_cap_cfg->cap_elem.phy_cap_info[3] &= UAP_HE_PHY_CAP3_MASK;
2257 he_cap_cfg->cap_elem.phy_cap_info[4] &= UAP_HE_PHY_CAP4_MASK;
2258 he_cap_cfg->cap_elem.phy_cap_info[5] &= UAP_HE_PHY_CAP5_MASK;
2259 he_cap_cfg->cap_elem.phy_cap_info[6] &= UAP_HE_PHY_CAP6_MASK;
2260 he_cap_cfg->cap_elem.phy_cap_info[7] &= UAP_HE_PHY_CAP7_MASK;
2261 he_cap_cfg->cap_elem.phy_cap_info[8] &= UAP_HE_PHY_CAP8_MASK;
2262 he_cap_cfg->cap_elem.phy_cap_info[9] &= UAP_HE_PHY_CAP9_MASK;
2263 he_cap_cfg->cap_elem.phy_cap_info[10] &= UAP_HE_PHY_CAP10_MASK;
2264 } else {
2265 he_cap_cfg->cap_elem.mac_cap_info[0] &= UAP_HE_2G_MAC_CAP0_MASK;
2266 he_cap_cfg->cap_elem.mac_cap_info[1] &= UAP_HE_2G_MAC_CAP1_MASK;
2267 he_cap_cfg->cap_elem.mac_cap_info[2] &= UAP_HE_2G_MAC_CAP2_MASK;
2268 he_cap_cfg->cap_elem.mac_cap_info[3] &= UAP_HE_2G_MAC_CAP3_MASK;
2269 he_cap_cfg->cap_elem.mac_cap_info[4] &= UAP_HE_2G_MAC_CAP4_MASK;
2270 he_cap_cfg->cap_elem.mac_cap_info[5] &= UAP_HE_2G_MAC_CAP5_MASK;
2271 he_cap_cfg->cap_elem.phy_cap_info[0] &= UAP_HE_2G_PHY_CAP0_MASK;
2272 he_cap_cfg->cap_elem.phy_cap_info[1] &= UAP_HE_2G_PHY_CAP1_MASK;
2273 he_cap_cfg->cap_elem.phy_cap_info[2] &= UAP_HE_2G_PHY_CAP2_MASK;
2274 he_cap_cfg->cap_elem.phy_cap_info[3] &= UAP_HE_2G_PHY_CAP3_MASK;
2275 he_cap_cfg->cap_elem.phy_cap_info[4] &= UAP_HE_2G_PHY_CAP4_MASK;
2276 he_cap_cfg->cap_elem.phy_cap_info[5] &= UAP_HE_2G_PHY_CAP5_MASK;
2277 he_cap_cfg->cap_elem.phy_cap_info[6] &= UAP_HE_2G_PHY_CAP6_MASK;
2278 he_cap_cfg->cap_elem.phy_cap_info[7] &= UAP_HE_2G_PHY_CAP7_MASK;
2279 he_cap_cfg->cap_elem.phy_cap_info[8] &= UAP_HE_2G_PHY_CAP8_MASK;
2280 he_cap_cfg->cap_elem.phy_cap_info[9] &= UAP_HE_2G_PHY_CAP9_MASK;
2281 he_cap_cfg->cap_elem.phy_cap_info[10] &= UAP_HE_2G_PHY_CAP10_MASK;
2282 }
2283 }
2284
2285 static void
nxpwifi_setup_he_caps(struct nxpwifi_private * priv,struct ieee80211_supported_band * band)2286 nxpwifi_setup_he_caps(struct nxpwifi_private *priv,
2287 struct ieee80211_supported_band *band)
2288 {
2289 struct nxpwifi_adapter *adapter = priv->adapter;
2290 struct ieee80211_sband_iftype_data *iftype_data;
2291 struct nxpwifi_11ax_he_cap_cfg he_cap_cfg;
2292 u8 hw_he_cap_len;
2293 u8 extra_mcs_size;
2294 int ppe_threshold_len;
2295
2296 if (band->band == NL80211_BAND_5GHZ) {
2297 hw_he_cap_len = adapter->hw_he_cap_len;
2298 memcpy(&he_cap_cfg, adapter->hw_he_cap, hw_he_cap_len);
2299 nxpwifi_update_11ax_ie(BAND_A, &he_cap_cfg);
2300 } else {
2301 hw_he_cap_len = adapter->hw_2g_he_cap_len;
2302 memcpy(&he_cap_cfg, adapter->hw_2g_he_cap, hw_he_cap_len);
2303 nxpwifi_update_11ax_ie(BAND_G, &he_cap_cfg);
2304 }
2305
2306 if (!hw_he_cap_len)
2307 return;
2308
2309 iftype_data = kmalloc_obj(*iftype_data);
2310 if (!iftype_data)
2311 return;
2312 memset(iftype_data, 0, sizeof(*iftype_data));
2313
2314 iftype_data->types_mask =
2315 BIT(NL80211_IFTYPE_STATION) | BIT(NL80211_IFTYPE_AP);
2316 iftype_data->he_cap.has_he = true;
2317
2318 memcpy(iftype_data->he_cap.he_cap_elem.mac_cap_info,
2319 he_cap_cfg.cap_elem.mac_cap_info,
2320 sizeof(he_cap_cfg.cap_elem.mac_cap_info));
2321 memcpy(iftype_data->he_cap.he_cap_elem.phy_cap_info,
2322 he_cap_cfg.cap_elem.phy_cap_info,
2323 sizeof(he_cap_cfg.cap_elem.phy_cap_info));
2324 memset(&iftype_data->he_cap.he_mcs_nss_supp,
2325 0xff,
2326 sizeof(iftype_data->he_cap.he_mcs_nss_supp));
2327 memcpy(&iftype_data->he_cap.he_mcs_nss_supp,
2328 he_cap_cfg.he_txrx_mcs_support,
2329 sizeof(he_cap_cfg.he_txrx_mcs_support));
2330
2331 extra_mcs_size = 0;
2332 /* Add 160 MHz MCS/NSS if supported */
2333 if (he_cap_cfg.cap_elem.phy_cap_info[0] & BIT(3))
2334 extra_mcs_size += 4;
2335 /* Add 80+80 MHz MCS/NSS if supported */
2336 if (he_cap_cfg.cap_elem.phy_cap_info[0] & BIT(4))
2337 extra_mcs_size += 4;
2338 if (extra_mcs_size)
2339 memcpy((u8 *)&iftype_data->he_cap.he_mcs_nss_supp.rx_mcs_160,
2340 he_cap_cfg.val, extra_mcs_size);
2341
2342 /* Parse PPE thresholds when present */
2343 ppe_threshold_len = he_cap_cfg.len - HE_CAP_FIX_SIZE - extra_mcs_size;
2344 if (he_cap_cfg.cap_elem.phy_cap_info[6] & BIT(7) && ppe_threshold_len) {
2345 memcpy(iftype_data->he_cap.ppe_thres,
2346 &he_cap_cfg.val[extra_mcs_size],
2347 ppe_threshold_len);
2348 } else {
2349 iftype_data->he_cap.he_cap_elem.phy_cap_info[6] &= BIT(7);
2350 }
2351
2352 _ieee80211_set_sband_iftype_data(band, iftype_data, 1);
2353 }
2354
2355 /* 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)2356 struct wireless_dev *nxpwifi_add_virtual_intf(struct wiphy *wiphy,
2357 const char *name,
2358 unsigned char name_assign_type,
2359 enum nl80211_iftype type,
2360 struct vif_params *params)
2361 {
2362 struct nxpwifi_adapter *adapter = nxpwifi_cfg80211_get_adapter(wiphy);
2363 struct nxpwifi_private *priv;
2364 struct net_device *dev;
2365 void *mdev_priv;
2366 int ret;
2367
2368 if (!adapter)
2369 return ERR_PTR(-EFAULT);
2370
2371 switch (type) {
2372 case NL80211_IFTYPE_UNSPECIFIED:
2373 case NL80211_IFTYPE_STATION:
2374 if (adapter->curr_iface_comb.sta_intf ==
2375 adapter->iface_limit.sta_intf) {
2376 nxpwifi_dbg(adapter, ERROR,
2377 "cannot create multiple sta ifaces\n");
2378 return ERR_PTR(-EINVAL);
2379 }
2380
2381 priv = nxpwifi_get_unused_priv_by_bss_type
2382 (adapter, NXPWIFI_BSS_TYPE_STA);
2383 if (!priv) {
2384 nxpwifi_dbg(adapter, ERROR,
2385 "could not get free private struct\n");
2386 return ERR_PTR(-EFAULT);
2387 }
2388
2389 priv->wdev.wiphy = wiphy;
2390 priv->wdev.iftype = NL80211_IFTYPE_STATION;
2391
2392 if (type == NL80211_IFTYPE_UNSPECIFIED)
2393 priv->bss_mode = NL80211_IFTYPE_STATION;
2394 else
2395 priv->bss_mode = type;
2396
2397 priv->bss_type = NXPWIFI_BSS_TYPE_STA;
2398 priv->frame_type = NXPWIFI_DATA_FRAME_TYPE_ETH_II;
2399 priv->bss_priority = 0;
2400 priv->bss_role = NXPWIFI_BSS_ROLE_STA;
2401
2402 break;
2403 case NL80211_IFTYPE_AP:
2404 if (adapter->curr_iface_comb.uap_intf ==
2405 adapter->iface_limit.uap_intf) {
2406 nxpwifi_dbg(adapter, ERROR,
2407 "cannot create multiple AP ifaces\n");
2408 return ERR_PTR(-EINVAL);
2409 }
2410
2411 priv = nxpwifi_get_unused_priv_by_bss_type
2412 (adapter, NXPWIFI_BSS_TYPE_UAP);
2413 if (!priv) {
2414 nxpwifi_dbg(adapter, ERROR,
2415 "could not get free private struct\n");
2416 return ERR_PTR(-EFAULT);
2417 }
2418
2419 priv->wdev.wiphy = wiphy;
2420 priv->wdev.iftype = NL80211_IFTYPE_AP;
2421
2422 priv->bss_type = NXPWIFI_BSS_TYPE_UAP;
2423 priv->frame_type = NXPWIFI_DATA_FRAME_TYPE_ETH_II;
2424 priv->bss_priority = 0;
2425 priv->bss_role = NXPWIFI_BSS_ROLE_UAP;
2426 priv->bss_started = 0;
2427 priv->bss_mode = type;
2428
2429 break;
2430 case NL80211_IFTYPE_MONITOR:
2431 priv = nxpwifi_get_unused_priv_by_bss_type
2432 (adapter, NXPWIFI_BSS_TYPE_UAP);
2433 if (!priv) {
2434 nxpwifi_dbg(adapter, ERROR,
2435 "could not get free private struct\n");
2436 return ERR_PTR(-EFAULT);
2437 }
2438 priv->wdev.wiphy = wiphy;
2439 priv->wdev.iftype = NL80211_IFTYPE_MONITOR;
2440
2441 priv->bss_type = NXPWIFI_BSS_TYPE_UAP;
2442 priv->frame_type = NXPWIFI_DATA_FRAME_TYPE_ETH_II;
2443 priv->bss_priority = 0;
2444 priv->bss_started = 0;
2445 priv->bss_mode = type;
2446
2447 break;
2448 default:
2449 nxpwifi_dbg(adapter, ERROR, "type not supported\n");
2450 return ERR_PTR(-EINVAL);
2451 }
2452
2453 dev = alloc_netdev_mqs(sizeof(struct nxpwifi_private *), name,
2454 name_assign_type, ether_setup,
2455 IEEE80211_NUM_ACS, 1);
2456 if (!dev) {
2457 nxpwifi_dbg(adapter, ERROR,
2458 "no memory available for netdevice\n");
2459 ret = -ENOMEM;
2460 goto err_alloc_netdev;
2461 }
2462
2463 nxpwifi_init_priv_params(priv, dev);
2464
2465 priv->netdev = dev;
2466
2467 nxpwifi_set_mac_address(priv, dev, false, NULL);
2468
2469 if (type != NL80211_IFTYPE_MONITOR) {
2470 ret = nxpwifi_set_bss_mode(priv);
2471
2472 if (ret) {
2473 nxpwifi_dbg(adapter, ERROR,
2474 "%s: err_set_bss_mode\n", __func__);
2475 goto err_set_bss_mode;
2476 }
2477 }
2478
2479 ret = nxpwifi_sta_init_cmd(priv, false, false);
2480 if (ret)
2481 goto err_sta_init;
2482
2483 dev_net_set(dev, wiphy_net(wiphy));
2484 dev->ieee80211_ptr = &priv->wdev;
2485 dev->ieee80211_ptr->iftype = priv->bss_mode;
2486 SET_NETDEV_DEV(dev, wiphy_dev(wiphy));
2487
2488 dev->flags |= IFF_BROADCAST | IFF_MULTICAST;
2489 dev->watchdog_timeo = NXPWIFI_DEFAULT_WATCHDOG_TIMEOUT;
2490 dev->needed_headroom = NXPWIFI_MIN_DATA_HEADER_LEN;
2491 dev->ethtool_ops = &nxpwifi_ethtool_ops;
2492
2493 mdev_priv = netdev_priv(dev);
2494 *((unsigned long *)mdev_priv) = (unsigned long)priv;
2495
2496 if (type == NL80211_IFTYPE_MONITOR)
2497 dev->type = ARPHRD_IEEE80211_RADIOTAP;
2498
2499 SET_NETDEV_DEV(dev, adapter->dev);
2500
2501 wiphy_work_init(&priv->reset_conn_state_work, nxpwifi_reset_conn_state_work);
2502
2503 wiphy_delayed_work_init(&priv->dfs_cac_work, nxpwifi_dfs_cac_work);
2504
2505 wiphy_delayed_work_init(&priv->dfs_chan_sw_work, nxpwifi_dfs_chan_sw_work);
2506
2507 /* Register network device */
2508 if (cfg80211_register_netdevice(dev)) {
2509 nxpwifi_dbg(adapter, ERROR, "cannot register network device\n");
2510 ret = -EFAULT;
2511 goto err_reg_netdev;
2512 }
2513
2514 nxpwifi_dbg(adapter, INFO,
2515 "info: %s: NXP 802.11 Adapter\n", dev->name);
2516
2517 #ifdef CONFIG_DEBUG_FS
2518 nxpwifi_dev_debugfs_init(priv);
2519 #endif
2520
2521 update_vif_type_counter(adapter, type, 1);
2522
2523 return &priv->wdev;
2524
2525 err_reg_netdev:
2526 free_netdev(dev);
2527 priv->netdev = NULL;
2528 err_sta_init:
2529 err_set_bss_mode:
2530 err_alloc_netdev:
2531 memset(&priv->wdev, 0, sizeof(priv->wdev));
2532 priv->wdev.iftype = NL80211_IFTYPE_UNSPECIFIED;
2533 priv->bss_mode = NL80211_IFTYPE_UNSPECIFIED;
2534 return ERR_PTR(ret);
2535 }
2536 EXPORT_SYMBOL_GPL(nxpwifi_add_virtual_intf);
2537
2538 /* del_virtual_intf: remove the virtual interface determined by dev */
nxpwifi_del_virtual_intf(struct wiphy * wiphy,struct wireless_dev * wdev)2539 int nxpwifi_del_virtual_intf(struct wiphy *wiphy, struct wireless_dev *wdev)
2540 {
2541 struct nxpwifi_private *priv = nxpwifi_netdev_get_priv(wdev->netdev);
2542 struct nxpwifi_adapter *adapter = priv->adapter;
2543 struct sk_buff *skb, *tmp;
2544
2545 #ifdef CONFIG_DEBUG_FS
2546 nxpwifi_dev_debugfs_remove(priv);
2547 #endif
2548 if (priv->bss_mode == NL80211_IFTYPE_MONITOR) {
2549 struct nxpwifi_802_11_net_monitor netmon_cfg;
2550
2551 memset(&netmon_cfg, 0, sizeof(struct nxpwifi_802_11_net_monitor));
2552 nxpwifi_config_monitor_mode(priv, &netmon_cfg);
2553 }
2554
2555 if (priv->sched_scanning)
2556 priv->sched_scanning = false;
2557
2558 nxpwifi_stop_net_dev_queue(priv->netdev, adapter);
2559
2560 skb_queue_walk_safe(&priv->bypass_txq, skb, tmp) {
2561 skb_unlink(skb, &priv->bypass_txq);
2562 nxpwifi_write_data_complete(priv->adapter, skb, 0, -1);
2563 }
2564
2565 netif_carrier_off(priv->netdev);
2566
2567 if (wdev->netdev->reg_state == NETREG_REGISTERED)
2568 cfg80211_unregister_netdevice(wdev->netdev);
2569
2570 /* Clear the priv in adapter */
2571 priv->netdev = NULL;
2572
2573 update_vif_type_counter(adapter, priv->bss_mode, -1);
2574
2575 priv->bss_mode = NL80211_IFTYPE_UNSPECIFIED;
2576
2577 if (GET_BSS_ROLE(priv) == NXPWIFI_BSS_ROLE_STA ||
2578 GET_BSS_ROLE(priv) == NXPWIFI_BSS_ROLE_UAP)
2579 kfree(priv->hist_data);
2580
2581 return 0;
2582 }
2583 EXPORT_SYMBOL_GPL(nxpwifi_del_virtual_intf);
2584
2585 static bool
nxpwifi_is_pattern_supported(struct cfg80211_pkt_pattern * pat,s8 * byte_seq,u8 max_byte_seq)2586 nxpwifi_is_pattern_supported(struct cfg80211_pkt_pattern *pat, s8 *byte_seq,
2587 u8 max_byte_seq)
2588 {
2589 int j, k, valid_byte_cnt = 0;
2590 bool dont_care_byte = false;
2591
2592 for (j = 0; j < DIV_ROUND_UP(pat->pattern_len, 8); j++) {
2593 for (k = 0; k < 8; k++) {
2594 if (pat->mask[j] & 1 << k) {
2595 memcpy(byte_seq + valid_byte_cnt,
2596 &pat->pattern[j * 8 + k], 1);
2597 valid_byte_cnt++;
2598 if (dont_care_byte)
2599 return false;
2600 } else {
2601 if (valid_byte_cnt)
2602 dont_care_byte = true;
2603 }
2604
2605 /* wildcard bytes record as the offset before the valid byte */
2606 if (!valid_byte_cnt && !dont_care_byte)
2607 pat->pkt_offset++;
2608
2609 if (valid_byte_cnt > max_byte_seq)
2610 return false;
2611 }
2612 }
2613
2614 byte_seq[max_byte_seq] = valid_byte_cnt;
2615
2616 return true;
2617 }
2618
2619 #ifdef CONFIG_PM
nxpwifi_set_auto_arp_mef_entry(struct nxpwifi_private * priv,struct nxpwifi_mef_entry * mef_entry)2620 static void nxpwifi_set_auto_arp_mef_entry(struct nxpwifi_private *priv,
2621 struct nxpwifi_mef_entry *mef_entry)
2622 {
2623 int i, filt_num = 0, num_ipv4 = 0;
2624 struct in_device *in_dev;
2625 struct in_ifaddr *ifa;
2626 __be32 ips[NXPWIFI_MAX_SUPPORTED_IPADDR];
2627 struct nxpwifi_adapter *adapter = priv->adapter;
2628
2629 mef_entry->mode = MEF_MODE_HOST_SLEEP;
2630 mef_entry->action = MEF_ACTION_AUTO_ARP;
2631
2632 /* Enable ARP offload feature */
2633 memset(ips, 0, sizeof(ips));
2634 for (i = 0; i < adapter->priv_num; i++) {
2635 if (adapter->priv[i]->netdev) {
2636 in_dev = __in_dev_get_rtnl(adapter->priv[i]->netdev);
2637 if (!in_dev)
2638 continue;
2639 ifa = rtnl_dereference(in_dev->ifa_list);
2640 if (!ifa || !ifa->ifa_local)
2641 continue;
2642 ips[i] = ifa->ifa_local;
2643 num_ipv4++;
2644 }
2645 }
2646
2647 for (i = 0; i < num_ipv4; i++) {
2648 if (!ips[i])
2649 continue;
2650 mef_entry->filter[filt_num].repeat = 1;
2651 memcpy(mef_entry->filter[filt_num].byte_seq,
2652 (u8 *)&ips[i], sizeof(ips[i]));
2653 mef_entry->filter[filt_num].byte_seq[NXPWIFI_MEF_MAX_BYTESEQ] =
2654 sizeof(ips[i]);
2655 mef_entry->filter[filt_num].offset = 46;
2656 mef_entry->filter[filt_num].filt_type = TYPE_EQ;
2657 if (filt_num) {
2658 mef_entry->filter[filt_num].filt_action =
2659 TYPE_OR;
2660 }
2661 filt_num++;
2662 }
2663
2664 mef_entry->filter[filt_num].repeat = 1;
2665 mef_entry->filter[filt_num].byte_seq[0] = 0x08;
2666 mef_entry->filter[filt_num].byte_seq[1] = 0x06;
2667 mef_entry->filter[filt_num].byte_seq[NXPWIFI_MEF_MAX_BYTESEQ] = 2;
2668 mef_entry->filter[filt_num].offset = 20;
2669 mef_entry->filter[filt_num].filt_type = TYPE_EQ;
2670 mef_entry->filter[filt_num].filt_action = TYPE_AND;
2671 }
2672
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)2673 static int nxpwifi_set_wowlan_mef_entry(struct nxpwifi_private *priv,
2674 struct nxpwifi_ds_mef_cfg *mef_cfg,
2675 struct nxpwifi_mef_entry *mef_entry,
2676 struct cfg80211_wowlan *wowlan)
2677 {
2678 int i, filt_num = 0, ret = 0;
2679 bool first_pat = true;
2680 u8 byte_seq[NXPWIFI_MEF_MAX_BYTESEQ + 1];
2681
2682 mef_entry->mode = MEF_MODE_HOST_SLEEP;
2683 mef_entry->action = MEF_ACTION_ALLOW_AND_WAKEUP_HOST;
2684
2685 for (i = 0; i < wowlan->n_patterns; i++) {
2686 memset(byte_seq, 0, sizeof(byte_seq));
2687 if (!nxpwifi_is_pattern_supported
2688 (&wowlan->patterns[i], byte_seq,
2689 NXPWIFI_MEF_MAX_BYTESEQ)) {
2690 nxpwifi_dbg(priv->adapter, ERROR,
2691 "Pattern not supported\n");
2692 return -EOPNOTSUPP;
2693 }
2694
2695 if (!wowlan->patterns[i].pkt_offset) {
2696 if (is_unicast_ether_addr(byte_seq) &&
2697 byte_seq[NXPWIFI_MEF_MAX_BYTESEQ] == 1) {
2698 mef_cfg->criteria |= NXPWIFI_CRITERIA_UNICAST;
2699 continue;
2700 } else if (is_broadcast_ether_addr(byte_seq)) {
2701 mef_cfg->criteria |= NXPWIFI_CRITERIA_BROADCAST;
2702 continue;
2703 } else if ((!memcmp(byte_seq, "\x33\x33", 2) &&
2704 (byte_seq[NXPWIFI_MEF_MAX_BYTESEQ] == 2)) ||
2705 (!memcmp(byte_seq, "\x01\x00\x5e", 3) &&
2706 (byte_seq[NXPWIFI_MEF_MAX_BYTESEQ] == 3))) {
2707 mef_cfg->criteria |= NXPWIFI_CRITERIA_MULTICAST;
2708 continue;
2709 }
2710 }
2711 mef_entry->filter[filt_num].repeat = 1;
2712 mef_entry->filter[filt_num].offset =
2713 wowlan->patterns[i].pkt_offset;
2714 memcpy(mef_entry->filter[filt_num].byte_seq, byte_seq,
2715 sizeof(byte_seq));
2716 mef_entry->filter[filt_num].filt_type = TYPE_EQ;
2717
2718 if (first_pat) {
2719 first_pat = false;
2720 nxpwifi_dbg(priv->adapter, INFO, "Wake on patterns\n");
2721 } else {
2722 mef_entry->filter[filt_num].filt_action = TYPE_AND;
2723 }
2724
2725 filt_num++;
2726 }
2727
2728 if (wowlan->magic_pkt) {
2729 mef_cfg->criteria |= NXPWIFI_CRITERIA_UNICAST;
2730 mef_entry->filter[filt_num].repeat = 16;
2731 memcpy(mef_entry->filter[filt_num].byte_seq, priv->curr_addr,
2732 ETH_ALEN);
2733 mef_entry->filter[filt_num].byte_seq[NXPWIFI_MEF_MAX_BYTESEQ] =
2734 ETH_ALEN;
2735 mef_entry->filter[filt_num].offset = 28;
2736 mef_entry->filter[filt_num].filt_type = TYPE_EQ;
2737 if (filt_num)
2738 mef_entry->filter[filt_num].filt_action = TYPE_OR;
2739
2740 filt_num++;
2741 mef_entry->filter[filt_num].repeat = 16;
2742 memcpy(mef_entry->filter[filt_num].byte_seq, priv->curr_addr,
2743 ETH_ALEN);
2744 mef_entry->filter[filt_num].byte_seq[NXPWIFI_MEF_MAX_BYTESEQ] =
2745 ETH_ALEN;
2746 mef_entry->filter[filt_num].offset = 56;
2747 mef_entry->filter[filt_num].filt_type = TYPE_EQ;
2748 mef_entry->filter[filt_num].filt_action = TYPE_OR;
2749 nxpwifi_dbg(priv->adapter, INFO, "Wake on magic packet\n");
2750 }
2751 return ret;
2752 }
2753
nxpwifi_set_mef_filter(struct nxpwifi_private * priv,struct cfg80211_wowlan * wowlan)2754 static int nxpwifi_set_mef_filter(struct nxpwifi_private *priv,
2755 struct cfg80211_wowlan *wowlan)
2756 {
2757 int ret = 0, num_entries = 1;
2758 struct nxpwifi_ds_mef_cfg mef_cfg;
2759 struct nxpwifi_mef_entry *mef_entry;
2760
2761 if (wowlan->n_patterns || wowlan->magic_pkt)
2762 num_entries++;
2763
2764 mef_entry = kzalloc_objs(*mef_entry, num_entries);
2765 if (!mef_entry)
2766 return -ENOMEM;
2767
2768 memset(&mef_cfg, 0, sizeof(mef_cfg));
2769 mef_cfg.criteria |= NXPWIFI_CRITERIA_BROADCAST |
2770 NXPWIFI_CRITERIA_UNICAST;
2771 mef_cfg.num_entries = num_entries;
2772 mef_cfg.mef_entry = mef_entry;
2773
2774 nxpwifi_set_auto_arp_mef_entry(priv, &mef_entry[0]);
2775
2776 if (wowlan->n_patterns || wowlan->magic_pkt) {
2777 ret = nxpwifi_set_wowlan_mef_entry(priv, &mef_cfg,
2778 &mef_entry[1], wowlan);
2779 if (ret)
2780 goto done;
2781 }
2782
2783 if (!mef_cfg.criteria)
2784 mef_cfg.criteria = NXPWIFI_CRITERIA_BROADCAST |
2785 NXPWIFI_CRITERIA_UNICAST |
2786 NXPWIFI_CRITERIA_MULTICAST;
2787
2788 ret = nxpwifi_mef_cfg(priv, &mef_cfg);
2789
2790 done:
2791 kfree(mef_entry);
2792 return ret;
2793 }
2794
nxpwifi_cfg80211_suspend(struct wiphy * wiphy,struct cfg80211_wowlan * wowlan)2795 static int nxpwifi_cfg80211_suspend(struct wiphy *wiphy,
2796 struct cfg80211_wowlan *wowlan)
2797 {
2798 struct nxpwifi_adapter *adapter = nxpwifi_cfg80211_get_adapter(wiphy);
2799 struct nxpwifi_ds_hs_cfg hs_cfg;
2800 int i, ret = 0, retry_num = 10;
2801 struct nxpwifi_private *priv;
2802 struct nxpwifi_private *sta_priv =
2803 nxpwifi_get_priv(adapter, NXPWIFI_BSS_ROLE_STA);
2804
2805 adapter->wowlan_enabled = false;
2806
2807 sta_priv->scan_aborting = true;
2808 for (i = 0; i < adapter->priv_num; i++) {
2809 priv = adapter->priv[i];
2810 nxpwifi_abort_cac(priv);
2811 }
2812
2813 nxpwifi_cancel_all_pending_cmd(adapter);
2814
2815 for (i = 0; i < adapter->priv_num; i++) {
2816 priv = adapter->priv[i];
2817 if (priv->netdev)
2818 netif_device_detach(priv->netdev);
2819 }
2820
2821 for (i = 0; i < retry_num; i++) {
2822 if (!nxpwifi_wmm_lists_empty(adapter) ||
2823 !nxpwifi_bypass_txlist_empty(adapter) ||
2824 !skb_queue_empty(&adapter->tx_data_q))
2825 usleep_range(10000, 15000);
2826 else
2827 break;
2828 }
2829
2830 if (!wowlan) {
2831 nxpwifi_dbg(adapter, INFO,
2832 "None of the WOWLAN triggers enabled\n");
2833 ret = 0;
2834 goto done;
2835 }
2836
2837 if (!sta_priv->media_connected && !wowlan->nd_config) {
2838 nxpwifi_dbg(adapter, ERROR,
2839 "Can not configure WOWLAN in disconnected state\n");
2840 ret = 0;
2841 goto done;
2842 }
2843
2844 ret = nxpwifi_set_mef_filter(sta_priv, wowlan);
2845 if (ret) {
2846 nxpwifi_dbg(adapter, ERROR, "Failed to set MEF filter\n");
2847 goto done;
2848 }
2849
2850 memset(&hs_cfg, 0, sizeof(hs_cfg));
2851 hs_cfg.conditions = le32_to_cpu(adapter->hs_cfg.conditions);
2852
2853 if (wowlan->nd_config) {
2854 nxpwifi_dbg(adapter, INFO, "Wake on net detect\n");
2855 hs_cfg.conditions |= HS_CFG_COND_MAC_EVENT;
2856 nxpwifi_cfg80211_sched_scan_start(wiphy, sta_priv->netdev,
2857 wowlan->nd_config);
2858 }
2859
2860 if (wowlan->disconnect) {
2861 hs_cfg.conditions |= HS_CFG_COND_MAC_EVENT;
2862 nxpwifi_dbg(sta_priv->adapter, INFO, "Wake on device disconnect\n");
2863 }
2864
2865 hs_cfg.is_invoke_hostcmd = false;
2866 hs_cfg.gpio = adapter->hs_cfg.gpio;
2867 hs_cfg.gap = adapter->hs_cfg.gap;
2868 ret = nxpwifi_set_hs_params(sta_priv, HOST_ACT_GEN_SET,
2869 NXPWIFI_SYNC_CMD, &hs_cfg);
2870 if (ret)
2871 nxpwifi_dbg(adapter, ERROR, "Failed to set HS params\n");
2872
2873 adapter->wowlan_enabled = true;
2874
2875 done:
2876 sta_priv->scan_aborting = false;
2877 return ret;
2878 }
2879
nxpwifi_cfg80211_resume(struct wiphy * wiphy)2880 static int nxpwifi_cfg80211_resume(struct wiphy *wiphy)
2881 {
2882 struct nxpwifi_adapter *adapter = nxpwifi_cfg80211_get_adapter(wiphy);
2883 struct nxpwifi_private *priv;
2884 struct nxpwifi_ds_wakeup_reason wakeup_reason;
2885 struct cfg80211_wowlan_wakeup wakeup_report;
2886 int i;
2887 bool report_wakeup_reason = true;
2888
2889 for (i = 0; i < adapter->priv_num; i++) {
2890 priv = adapter->priv[i];
2891 if (priv->netdev)
2892 netif_device_attach(priv->netdev);
2893 }
2894
2895 if (!wiphy->wowlan_config)
2896 goto done;
2897
2898 priv = nxpwifi_get_priv(adapter, NXPWIFI_BSS_ROLE_STA);
2899 nxpwifi_get_wakeup_reason(priv, HOST_ACT_GEN_GET, NXPWIFI_SYNC_CMD,
2900 &wakeup_reason);
2901 memset(&wakeup_report, 0, sizeof(struct cfg80211_wowlan_wakeup));
2902
2903 wakeup_report.pattern_idx = -1;
2904
2905 switch (wakeup_reason.hs_wakeup_reason) {
2906 case NO_HSWAKEUP_REASON:
2907 break;
2908 case BCAST_DATA_MATCHED:
2909 break;
2910 case MCAST_DATA_MATCHED:
2911 break;
2912 case UCAST_DATA_MATCHED:
2913 break;
2914 case MASKTABLE_EVENT_MATCHED:
2915 break;
2916 case NON_MASKABLE_EVENT_MATCHED:
2917 if (wiphy->wowlan_config->disconnect)
2918 wakeup_report.disconnect = true;
2919 if (wiphy->wowlan_config->nd_config)
2920 wakeup_report.net_detect = adapter->nd_info;
2921 break;
2922 case NON_MASKABLE_CONDITION_MATCHED:
2923 break;
2924 case MAGIC_PATTERN_MATCHED:
2925 if (wiphy->wowlan_config->magic_pkt)
2926 wakeup_report.magic_pkt = true;
2927 if (wiphy->wowlan_config->n_patterns)
2928 wakeup_report.pattern_idx = 1;
2929 break;
2930 case GTK_REKEY_FAILURE:
2931 if (wiphy->wowlan_config->gtk_rekey_failure)
2932 wakeup_report.gtk_rekey_failure = true;
2933 break;
2934 default:
2935 report_wakeup_reason = false;
2936 break;
2937 }
2938
2939 if (report_wakeup_reason)
2940 cfg80211_report_wowlan_wakeup(&priv->wdev, &wakeup_report,
2941 GFP_KERNEL);
2942
2943 done:
2944 if (adapter->nd_info) {
2945 for (i = 0 ; i < adapter->nd_info->n_matches ; i++)
2946 kfree(adapter->nd_info->matches[i]);
2947 kfree(adapter->nd_info);
2948 adapter->nd_info = NULL;
2949 }
2950
2951 return 0;
2952 }
2953
nxpwifi_cfg80211_set_wakeup(struct wiphy * wiphy,bool enabled)2954 static void nxpwifi_cfg80211_set_wakeup(struct wiphy *wiphy,
2955 bool enabled)
2956 {
2957 struct nxpwifi_adapter *adapter = nxpwifi_cfg80211_get_adapter(wiphy);
2958
2959 device_set_wakeup_enable(adapter->dev, enabled);
2960 }
2961 #endif
2962
nxpwifi_get_coalesce_pkt_type(u8 * byte_seq)2963 static int nxpwifi_get_coalesce_pkt_type(u8 *byte_seq)
2964 {
2965 if ((byte_seq[0] & 0x01) &&
2966 byte_seq[NXPWIFI_COALESCE_MAX_BYTESEQ] == 1)
2967 return PACKET_TYPE_UNICAST;
2968 else if (is_broadcast_ether_addr(byte_seq))
2969 return PACKET_TYPE_BROADCAST;
2970 else if ((!memcmp(byte_seq, "\x33\x33", 2) &&
2971 byte_seq[NXPWIFI_COALESCE_MAX_BYTESEQ] == 2) ||
2972 (!memcmp(byte_seq, "\x01\x00\x5e", 3) &&
2973 byte_seq[NXPWIFI_COALESCE_MAX_BYTESEQ] == 3))
2974 return PACKET_TYPE_MULTICAST;
2975
2976 return 0;
2977 }
2978
2979 static int
nxpwifi_fill_coalesce_rule_info(struct nxpwifi_private * priv,struct cfg80211_coalesce_rules * crule,struct nxpwifi_coalesce_rule * mrule)2980 nxpwifi_fill_coalesce_rule_info(struct nxpwifi_private *priv,
2981 struct cfg80211_coalesce_rules *crule,
2982 struct nxpwifi_coalesce_rule *mrule)
2983 {
2984 u8 byte_seq[NXPWIFI_COALESCE_MAX_BYTESEQ + 1];
2985 struct filt_field_param *param;
2986 int i;
2987
2988 mrule->max_coalescing_delay = crule->delay;
2989
2990 param = mrule->params;
2991
2992 for (i = 0; i < crule->n_patterns; i++) {
2993 memset(byte_seq, 0, sizeof(byte_seq));
2994 if (!nxpwifi_is_pattern_supported(&crule->patterns[i],
2995 byte_seq,
2996 NXPWIFI_COALESCE_MAX_BYTESEQ)) {
2997 nxpwifi_dbg(priv->adapter, ERROR,
2998 "Pattern not supported\n");
2999 return -EOPNOTSUPP;
3000 }
3001
3002 if (!crule->patterns[i].pkt_offset) {
3003 u8 pkt_type;
3004
3005 pkt_type = nxpwifi_get_coalesce_pkt_type(byte_seq);
3006 if (pkt_type && mrule->pkt_type) {
3007 nxpwifi_dbg(priv->adapter, ERROR,
3008 "Multiple packet types not allowed\n");
3009 return -EOPNOTSUPP;
3010 } else if (pkt_type) {
3011 mrule->pkt_type = pkt_type;
3012 continue;
3013 }
3014 }
3015
3016 if (crule->condition == NL80211_COALESCE_CONDITION_MATCH)
3017 param->operation = RECV_FILTER_MATCH_TYPE_EQ;
3018 else
3019 param->operation = RECV_FILTER_MATCH_TYPE_NE;
3020
3021 param->operand_len = byte_seq[NXPWIFI_COALESCE_MAX_BYTESEQ];
3022 memcpy(param->operand_byte_stream, byte_seq,
3023 param->operand_len);
3024 param->offset = crule->patterns[i].pkt_offset;
3025 param++;
3026
3027 mrule->num_of_fields++;
3028 }
3029
3030 if (!mrule->pkt_type) {
3031 nxpwifi_dbg(priv->adapter, ERROR,
3032 "Packet type can not be determined\n");
3033 return -EOPNOTSUPP;
3034 }
3035
3036 return 0;
3037 }
3038
nxpwifi_cfg80211_set_coalesce(struct wiphy * wiphy,struct cfg80211_coalesce * coalesce)3039 static int nxpwifi_cfg80211_set_coalesce(struct wiphy *wiphy,
3040 struct cfg80211_coalesce *coalesce)
3041 {
3042 struct nxpwifi_adapter *adapter = nxpwifi_cfg80211_get_adapter(wiphy);
3043 int i, ret;
3044 struct nxpwifi_ds_coalesce_cfg coalesce_cfg;
3045 struct nxpwifi_private *priv =
3046 nxpwifi_get_priv(adapter, NXPWIFI_BSS_ROLE_STA);
3047
3048 memset(&coalesce_cfg, 0, sizeof(coalesce_cfg));
3049
3050 if (!coalesce)
3051 return nxpwifi_coalesce_cfg(priv, &coalesce_cfg);
3052
3053 coalesce_cfg.num_of_rules = coalesce->n_rules;
3054 for (i = 0; i < coalesce->n_rules; i++) {
3055 ret = nxpwifi_fill_coalesce_rule_info(priv, &coalesce->rules[i],
3056 &coalesce_cfg.rule[i]);
3057 if (ret) {
3058 nxpwifi_dbg(adapter, ERROR,
3059 "Recheck the patterns provided for rule %d\n",
3060 i + 1);
3061 return ret;
3062 }
3063 }
3064
3065 return nxpwifi_coalesce_cfg(priv, &coalesce_cfg);
3066 }
3067
3068 static int
nxpwifi_cfg80211_uap_add_station(struct nxpwifi_private * priv,const u8 * mac,struct station_parameters * params)3069 nxpwifi_cfg80211_uap_add_station(struct nxpwifi_private *priv, const u8 *mac,
3070 struct station_parameters *params)
3071 {
3072 struct nxpwifi_sta_info add_sta;
3073 int ret;
3074
3075 memcpy(add_sta.peer_mac, mac, ETH_ALEN);
3076 add_sta.params = params;
3077
3078 ret = nxpwifi_add_new_station(priv, &add_sta);
3079
3080 return ret;
3081 }
3082
3083 static int
nxpwifi_cfg80211_add_station(struct wiphy * wiphy,struct wireless_dev * wdev,const u8 * mac,struct station_parameters * params)3084 nxpwifi_cfg80211_add_station(struct wiphy *wiphy, struct wireless_dev *wdev,
3085 const u8 *mac, struct station_parameters *params)
3086 {
3087 struct nxpwifi_private *priv = nxpwifi_netdev_get_priv(wdev->netdev);
3088 int ret = -EOPNOTSUPP;
3089
3090 if (GET_BSS_ROLE(priv) == NXPWIFI_BSS_ROLE_UAP)
3091 ret = nxpwifi_cfg80211_uap_add_station(priv, mac, params);
3092
3093 return ret;
3094 }
3095
3096 static int
nxpwifi_cfg80211_channel_switch(struct wiphy * wiphy,struct net_device * dev,struct cfg80211_csa_settings * params)3097 nxpwifi_cfg80211_channel_switch(struct wiphy *wiphy, struct net_device *dev,
3098 struct cfg80211_csa_settings *params)
3099 {
3100 struct nxpwifi_private *priv = nxpwifi_netdev_get_priv(dev);
3101 int chsw_msec;
3102 int ret;
3103
3104 if (priv->adapter->scan_processing) {
3105 nxpwifi_dbg(priv->adapter, ERROR,
3106 "radar detection: scan in process...\n");
3107 return -EBUSY;
3108 }
3109
3110 if (priv->wdev.links[0].cac_started)
3111 return -EBUSY;
3112
3113 if (cfg80211_chandef_identical(¶ms->chandef,
3114 &priv->dfs_chandef))
3115 return -EINVAL;
3116
3117 if (params->block_tx) {
3118 netif_carrier_off(priv->netdev);
3119 nxpwifi_stop_net_dev_queue(priv->netdev, priv->adapter);
3120 priv->uap_stop_tx = true;
3121 }
3122
3123 ret = nxpwifi_del_mgmt_ies(priv);
3124 if (ret)
3125 nxpwifi_dbg(priv->adapter, ERROR,
3126 "Failed to delete mgmt IEs!\n");
3127
3128 ret = nxpwifi_set_mgmt_ies(priv, ¶ms->beacon_csa);
3129 if (ret) {
3130 nxpwifi_dbg(priv->adapter, ERROR,
3131 "%s: setting mgmt ies failed\n", __func__);
3132 goto done;
3133 }
3134
3135 memcpy(&priv->dfs_chandef, ¶ms->chandef, sizeof(priv->dfs_chandef));
3136 memcpy(&priv->ap_update_info.beacon, ¶ms->beacon_after,
3137 sizeof(priv->ap_update_info.beacon));
3138
3139 chsw_msec = max(params->count * priv->bss_cfg.beacon_period, 100);
3140
3141 nxpwifi_queue_delayed_wiphy_work(priv->adapter,
3142 &priv->dfs_chan_sw_work,
3143 msecs_to_jiffies(chsw_msec));
3144
3145 done:
3146 return ret;
3147 }
3148
nxpwifi_cfg80211_get_channel(struct wiphy * wiphy,struct wireless_dev * wdev,unsigned int link_id,struct cfg80211_chan_def * chandef)3149 static int nxpwifi_cfg80211_get_channel(struct wiphy *wiphy,
3150 struct wireless_dev *wdev,
3151 unsigned int link_id,
3152 struct cfg80211_chan_def *chandef)
3153 {
3154 struct nxpwifi_private *priv = nxpwifi_netdev_get_priv(wdev->netdev);
3155 struct nxpwifi_bssdescriptor *curr_bss;
3156 struct ieee80211_channel *chan;
3157 enum nl80211_channel_type chan_type;
3158 enum nl80211_band band;
3159 int freq;
3160 int ret = -ENODATA;
3161
3162 if (GET_BSS_ROLE(priv) == NXPWIFI_BSS_ROLE_UAP &&
3163 cfg80211_chandef_valid(&priv->bss_chandef)) {
3164 *chandef = priv->bss_chandef;
3165 ret = 0;
3166 } else if (priv->media_connected) {
3167 curr_bss = &priv->curr_bss_params.bss_descriptor;
3168 band = nxpwifi_band_to_radio_type(priv->curr_bss_params.band);
3169 freq = ieee80211_channel_to_frequency(curr_bss->channel, band);
3170 chan = ieee80211_get_channel(wiphy, freq);
3171
3172 if (priv->ht_param_present) {
3173 chan_type = nxpwifi_get_chan_type(priv);
3174 cfg80211_chandef_create(chandef, chan, chan_type);
3175 } else {
3176 cfg80211_chandef_create(chandef, chan,
3177 NL80211_CHAN_NO_HT);
3178 }
3179 ret = 0;
3180 }
3181
3182 return ret;
3183 }
3184
3185 #ifdef CONFIG_NL80211_TESTMODE
3186
3187 enum nxpwifi_tm_attr {
3188 __NXPWIFI_TM_ATTR_INVALID = 0,
3189 NXPWIFI_TM_ATTR_CMD = 1,
3190 NXPWIFI_TM_ATTR_DATA = 2,
3191
3192 /* keep last */
3193 __NXPWIFI_TM_ATTR_AFTER_LAST,
3194 NXPWIFI_TM_ATTR_MAX = __NXPWIFI_TM_ATTR_AFTER_LAST - 1,
3195 };
3196
3197 static const struct nla_policy nxpwifi_tm_policy[NXPWIFI_TM_ATTR_MAX + 1] = {
3198 [NXPWIFI_TM_ATTR_CMD] = { .type = NLA_U32 },
3199 [NXPWIFI_TM_ATTR_DATA] = { .type = NLA_BINARY,
3200 .len = NXPWIFI_SIZE_OF_CMD_BUFFER },
3201 };
3202
3203 enum nxpwifi_tm_command {
3204 NXPWIFI_TM_CMD_HOSTCMD = 0,
3205 };
3206
nxpwifi_tm_cmd(struct wiphy * wiphy,struct wireless_dev * wdev,void * data,int len)3207 static int nxpwifi_tm_cmd(struct wiphy *wiphy, struct wireless_dev *wdev,
3208 void *data, int len)
3209 {
3210 struct nxpwifi_private *priv = nxpwifi_netdev_get_priv(wdev->netdev);
3211 struct nxpwifi_ds_misc_cmd *hostcmd;
3212 struct nlattr *tb[NXPWIFI_TM_ATTR_MAX + 1];
3213 struct sk_buff *skb;
3214 int err;
3215
3216 if (!priv)
3217 return -EINVAL;
3218
3219 err = nla_parse_deprecated(tb, NXPWIFI_TM_ATTR_MAX, data, len,
3220 nxpwifi_tm_policy, NULL);
3221 if (err)
3222 return err;
3223
3224 if (!tb[NXPWIFI_TM_ATTR_CMD])
3225 return -EINVAL;
3226
3227 switch (nla_get_u32(tb[NXPWIFI_TM_ATTR_CMD])) {
3228 case NXPWIFI_TM_CMD_HOSTCMD:
3229 if (!tb[NXPWIFI_TM_ATTR_DATA])
3230 return -EINVAL;
3231
3232 hostcmd = kzalloc_obj(*hostcmd);
3233 if (!hostcmd)
3234 return -ENOMEM;
3235
3236 hostcmd->len = nla_len(tb[NXPWIFI_TM_ATTR_DATA]);
3237 memcpy(hostcmd->cmd, nla_data(tb[NXPWIFI_TM_ATTR_DATA]),
3238 hostcmd->len);
3239
3240 if (nxpwifi_hostcmd(priv, hostcmd)) {
3241 nxpwifi_dbg(priv->adapter, ERROR, "Failed to process hostcmd\n");
3242 kfree(hostcmd);
3243 return -EFAULT;
3244 }
3245
3246 /* process hostcmd response*/
3247 skb = cfg80211_testmode_alloc_reply_skb(wiphy, hostcmd->len);
3248 if (!skb) {
3249 kfree(hostcmd);
3250 return -ENOMEM;
3251 }
3252 err = nla_put(skb, NXPWIFI_TM_ATTR_DATA,
3253 hostcmd->len, hostcmd->cmd);
3254 if (err) {
3255 kfree(hostcmd);
3256 kfree_skb(skb);
3257 return -EMSGSIZE;
3258 }
3259
3260 err = cfg80211_testmode_reply(skb);
3261 kfree(hostcmd);
3262 return err;
3263 default:
3264 return -EOPNOTSUPP;
3265 }
3266 }
3267 #endif
3268
3269 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)3270 nxpwifi_cfg80211_start_radar_detection(struct wiphy *wiphy,
3271 struct net_device *dev,
3272 struct cfg80211_chan_def *chandef,
3273 u32 cac_time_ms, int link_id)
3274 {
3275 struct nxpwifi_private *priv = nxpwifi_netdev_get_priv(dev);
3276 struct nxpwifi_radar_params radar_params;
3277 int ret;
3278
3279 if (priv->adapter->scan_processing) {
3280 nxpwifi_dbg(priv->adapter, ERROR,
3281 "radar detection: scan already in process...\n");
3282 return -EBUSY;
3283 }
3284
3285 if (!nxpwifi_is_11h_active(priv)) {
3286 nxpwifi_dbg(priv->adapter, INFO,
3287 "Enable 11h extensions in FW\n");
3288 if (nxpwifi_11h_activate(priv, true)) {
3289 nxpwifi_dbg(priv->adapter, ERROR,
3290 "Failed to activate 11h extensions!!");
3291 return -EPERM;
3292 }
3293 priv->state_11h.is_11h_active = true;
3294 }
3295
3296 memset(&radar_params, 0, sizeof(struct nxpwifi_radar_params));
3297 radar_params.chandef = chandef;
3298 radar_params.cac_time_ms = cac_time_ms;
3299
3300 memcpy(&priv->dfs_chandef, chandef, sizeof(priv->dfs_chandef));
3301
3302 ret = nxpwifi_chan_report_request(priv, &radar_params);
3303 if (!ret)
3304 nxpwifi_queue_delayed_wiphy_work(priv->adapter,
3305 &priv->dfs_cac_work,
3306 msecs_to_jiffies(cac_time_ms));
3307
3308 return ret;
3309 }
3310
3311 static int
nxpwifi_cfg80211_change_station(struct wiphy * wiphy,struct wireless_dev * wdev,const u8 * mac,struct station_parameters * params)3312 nxpwifi_cfg80211_change_station(struct wiphy *wiphy, struct wireless_dev *wdev,
3313 const u8 *mac,
3314 struct station_parameters *params)
3315 {
3316 return 0;
3317 }
3318
3319 static int
nxpwifi_cfg80211_authenticate(struct wiphy * wiphy,struct net_device * dev,struct cfg80211_auth_request * req)3320 nxpwifi_cfg80211_authenticate(struct wiphy *wiphy,
3321 struct net_device *dev,
3322 struct cfg80211_auth_request *req)
3323 {
3324 struct nxpwifi_private *priv = nxpwifi_netdev_get_priv(dev);
3325 struct nxpwifi_adapter *adapter = priv->adapter;
3326 struct sk_buff *skb;
3327 u16 pkt_len, auth_alg;
3328 size_t frame_len;
3329 int ret;
3330 struct ieee80211_mgmt *mgmt;
3331 struct nxpwifi_txinfo *tx_info;
3332 u8 trans = 1, status_code = 0;
3333 u8 *varptr = NULL;
3334
3335 if (GET_BSS_ROLE(priv) == NXPWIFI_BSS_ROLE_UAP) {
3336 nxpwifi_dbg(adapter, ERROR, "Interface role is AP\n");
3337 return -EINVAL;
3338 }
3339
3340 if (priv->wdev.iftype != NL80211_IFTYPE_STATION) {
3341 nxpwifi_dbg(adapter, ERROR,
3342 "Interface type is not correct (type %d)\n",
3343 priv->wdev.iftype);
3344 return -EINVAL;
3345 }
3346
3347 if (!nxpwifi_is_channel_setting_allowable(priv, req->bss->channel))
3348 return -EOPNOTSUPP;
3349
3350 if (priv->auth_alg != WLAN_AUTH_SAE &&
3351 (priv->auth_flag & HOST_MLME_AUTH_PENDING)) {
3352 nxpwifi_dbg(adapter, ERROR, "Pending auth on going\n");
3353 return -EBUSY;
3354 }
3355
3356 if (!priv->host_mlme_reg) {
3357 priv->host_mlme_reg = true;
3358 priv->mgmt_frame_mask |= HOST_MLME_MGMT_MASK;
3359 nxpwifi_mgmt_frame_reg(priv, priv->mgmt_frame_mask);
3360 }
3361
3362 switch (req->auth_type) {
3363 case NL80211_AUTHTYPE_OPEN_SYSTEM:
3364 auth_alg = WLAN_AUTH_OPEN;
3365 break;
3366 case NL80211_AUTHTYPE_SHARED_KEY:
3367 auth_alg = WLAN_AUTH_SHARED_KEY;
3368 break;
3369 case NL80211_AUTHTYPE_FT:
3370 auth_alg = WLAN_AUTH_FT;
3371 break;
3372 case NL80211_AUTHTYPE_NETWORK_EAP:
3373 auth_alg = WLAN_AUTH_LEAP;
3374 break;
3375 case NL80211_AUTHTYPE_SAE:
3376 auth_alg = WLAN_AUTH_SAE;
3377 break;
3378 default:
3379 nxpwifi_dbg(adapter, ERROR,
3380 "unsupported auth type=%d\n", req->auth_type);
3381 return -EOPNOTSUPP;
3382 }
3383
3384 if (!(priv->auth_flag & HOST_MLME_AUTH_PENDING)) {
3385 ret = nxpwifi_remain_on_chan_cfg(priv, HOST_ACT_GEN_SET,
3386 req->bss->channel,
3387 AUTH_TX_DEFAULT_WAIT_TIME);
3388
3389 if (!ret) {
3390 priv->roc_cfg.cookie =
3391 nxpwifi_roc_cookie(adapter);
3392 priv->roc_cfg.chan = *req->bss->channel;
3393 } else {
3394 return -EPERM;
3395 }
3396 }
3397
3398 priv->sec_info.authentication_mode = auth_alg;
3399
3400 nxpwifi_cancel_scan(adapter);
3401
3402 frame_len = req->ie_len + req->auth_data_len +
3403 sizeof(struct ieee80211_hdr_3addr) + NXPWIFI_AUTH_BODY_LEN;
3404
3405 if (req->auth_data_len >= 4)
3406 frame_len -= 4;
3407
3408 /* nxpwifi_form_mgmt_frame() inserts address4, so the frame handed to
3409 * the firmware is ETH_ALEN longer than the one built here.
3410 */
3411 if (frame_len > U16_MAX - ETH_ALEN) {
3412 nxpwifi_dbg(adapter, ERROR,
3413 "auth frame too long: %zu bytes\n", frame_len);
3414 return -EINVAL;
3415 }
3416 pkt_len = frame_len + ETH_ALEN;
3417
3418 mgmt = kzalloc(frame_len, GFP_KERNEL);
3419 if (!mgmt)
3420 return -ENOMEM;
3421
3422 skb = dev_alloc_skb(NXPWIFI_MIN_DATA_HEADER_LEN +
3423 NXPWIFI_MGMT_FRAME_HEADER_SIZE +
3424 pkt_len + sizeof(pkt_len));
3425 if (!skb) {
3426 nxpwifi_dbg(adapter, ERROR,
3427 "allocate skb failed for management frame\n");
3428 kfree(mgmt);
3429 return -ENOMEM;
3430 }
3431
3432 tx_info = NXPWIFI_SKB_TXCB(skb);
3433 memset(tx_info, 0, sizeof(*tx_info));
3434 tx_info->bss_num = priv->bss_num;
3435 tx_info->bss_type = priv->bss_type;
3436 tx_info->pkt_len = pkt_len;
3437
3438 memcpy(mgmt->da, req->bss->bssid, ETH_ALEN);
3439 memcpy(mgmt->sa, priv->curr_addr, ETH_ALEN);
3440 memcpy(mgmt->bssid, req->bss->bssid, ETH_ALEN);
3441 mgmt->frame_control =
3442 cpu_to_le16(IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_AUTH);
3443
3444 if (req->auth_data_len >= 4) {
3445 if (req->auth_type == NL80211_AUTHTYPE_SAE) {
3446 __le16 *pos = (__le16 *)req->auth_data;
3447
3448 trans = le16_to_cpu(pos[0]);
3449 status_code = le16_to_cpu(pos[1]);
3450 }
3451 memcpy((u8 *)(&mgmt->u.auth.variable), req->auth_data + 4,
3452 req->auth_data_len - 4);
3453 varptr = (u8 *)&mgmt->u.auth.variable +
3454 (req->auth_data_len - 4);
3455 }
3456
3457 mgmt->u.auth.auth_alg = cpu_to_le16(auth_alg);
3458 mgmt->u.auth.auth_transaction = cpu_to_le16(trans);
3459 mgmt->u.auth.status_code = cpu_to_le16(status_code);
3460
3461 if (req->ie && req->ie_len) {
3462 if (!varptr)
3463 varptr = (u8 *)&mgmt->u.auth.variable;
3464 memcpy((u8 *)varptr, req->ie, req->ie_len);
3465 }
3466
3467 nxpwifi_form_mgmt_frame(skb, (const u8 *)mgmt, frame_len);
3468 kfree(mgmt);
3469 priv->auth_flag = HOST_MLME_AUTH_PENDING;
3470 priv->auth_alg = auth_alg;
3471 skb->priority = WMM_HIGHEST_PRIORITY;
3472 __net_timestamp(skb);
3473
3474 nxpwifi_dbg(adapter, MSG,
3475 "auth: send authentication to %pM\n", req->bss->bssid);
3476
3477 nxpwifi_queue_tx_pkt(priv, skb);
3478
3479 return 0;
3480 }
3481
3482 static int
nxpwifi_cfg80211_associate(struct wiphy * wiphy,struct net_device * dev,struct cfg80211_assoc_request * req)3483 nxpwifi_cfg80211_associate(struct wiphy *wiphy, struct net_device *dev,
3484 struct cfg80211_assoc_request *req)
3485 {
3486 struct nxpwifi_private *priv = nxpwifi_netdev_get_priv(dev);
3487 struct nxpwifi_adapter *adapter = priv->adapter;
3488 int ret;
3489 struct cfg80211_ssid req_ssid;
3490 const u8 *ssid_ie;
3491
3492 if (GET_BSS_ROLE(priv) != NXPWIFI_BSS_ROLE_STA) {
3493 nxpwifi_dbg(adapter, ERROR,
3494 "%s: reject infra assoc request in non-STA role\n",
3495 dev->name);
3496 return -EINVAL;
3497 }
3498
3499 if (test_bit(NXPWIFI_SURPRISE_REMOVED, &adapter->work_flags) ||
3500 test_bit(NXPWIFI_IS_CMD_TIMEDOUT, &adapter->work_flags)) {
3501 nxpwifi_dbg(adapter, ERROR,
3502 "%s: Ignore association.\t"
3503 "Card removed or FW in bad state\n",
3504 dev->name);
3505 return -EPERM;
3506 }
3507
3508 if (priv->auth_alg == WLAN_AUTH_SAE)
3509 priv->auth_flag = HOST_MLME_AUTH_DONE;
3510
3511 if (priv->auth_flag && !(priv->auth_flag & HOST_MLME_AUTH_DONE))
3512 return -EBUSY;
3513
3514 if (priv->roc_cfg.cookie) {
3515 ret = nxpwifi_remain_on_chan_cfg(priv, HOST_ACT_GEN_REMOVE,
3516 &priv->roc_cfg.chan, 0);
3517 if (!ret)
3518 memset(&priv->roc_cfg, 0,
3519 sizeof(struct nxpwifi_roc_cfg));
3520 else
3521 return ret;
3522 }
3523
3524 if (!nxpwifi_stop_bg_scan(priv))
3525 cfg80211_sched_scan_stopped_locked(priv->wdev.wiphy, 0);
3526
3527 memset(&req_ssid, 0, sizeof(struct cfg80211_ssid));
3528 rcu_read_lock();
3529 ssid_ie = ieee80211_bss_get_ie(req->bss, WLAN_EID_SSID);
3530
3531 if (!ssid_ie)
3532 goto ssid_err;
3533
3534 req_ssid.ssid_len = ssid_ie[1];
3535 if (req_ssid.ssid_len > IEEE80211_MAX_SSID_LEN) {
3536 nxpwifi_dbg(adapter, ERROR, "invalid SSID - aborting\n");
3537 goto ssid_err;
3538 }
3539
3540 memcpy(req_ssid.ssid, ssid_ie + 2, req_ssid.ssid_len);
3541 if (!req_ssid.ssid_len || req_ssid.ssid[0] < 0x20) {
3542 nxpwifi_dbg(adapter, ERROR, "invalid SSID - aborting\n");
3543 goto ssid_err;
3544 }
3545 rcu_read_unlock();
3546
3547 /*
3548 * As this is new association, clear locally stored
3549 * keys and security related flags
3550 */
3551 priv->sec_info.wpa_enabled = false;
3552 priv->sec_info.wpa2_enabled = false;
3553 priv->wep_key_curr_index = 0;
3554 priv->sec_info.encryption_mode = 0;
3555 priv->sec_info.is_authtype_auto = 0;
3556 ret = nxpwifi_set_encode(priv, NULL, NULL, 0, 0, NULL, 1);
3557
3558 if (req->crypto.n_ciphers_pairwise)
3559 priv->sec_info.encryption_mode =
3560 req->crypto.ciphers_pairwise[0];
3561
3562 if (req->crypto.cipher_group)
3563 priv->sec_info.encryption_mode = req->crypto.cipher_group;
3564
3565 if (req->ie)
3566 ret = nxpwifi_set_gen_ie(priv, req->ie, req->ie_len);
3567
3568 memcpy(priv->cfg_bssid, req->bss->bssid, ETH_ALEN);
3569
3570 nxpwifi_dbg(adapter, MSG,
3571 "assoc: send association to %pM\n", req->bss->bssid);
3572
3573 cfg80211_ref_bss(adapter->wiphy, req->bss);
3574
3575 ret = nxpwifi_bss_start(priv, req->bss, &req_ssid);
3576
3577 if (ret) {
3578 priv->auth_flag = 0;
3579 priv->auth_alg = WLAN_AUTH_NONE;
3580 eth_zero_addr(priv->cfg_bssid);
3581 }
3582
3583 if (ret >= 0) {
3584 if (priv->assoc_rsp_size) {
3585 priv->req_bss = req->bss;
3586 adapter->assoc_resp_received = true;
3587 nxpwifi_queue_wiphy_work(adapter,
3588 &adapter->host_mlme_work);
3589 }
3590 ret = 0;
3591 }
3592
3593 cfg80211_put_bss(priv->adapter->wiphy, req->bss);
3594
3595 return ret;
3596
3597 ssid_err:
3598
3599 rcu_read_unlock();
3600 return -EINVAL;
3601 }
3602
3603 static int
nxpwifi_cfg80211_disconnect(struct wiphy * wiphy,struct net_device * dev,u16 reason_code)3604 nxpwifi_cfg80211_disconnect(struct wiphy *wiphy, struct net_device *dev,
3605 u16 reason_code)
3606 {
3607 struct nxpwifi_private *priv = nxpwifi_netdev_get_priv(dev);
3608 int ret;
3609
3610 if (!nxpwifi_stop_bg_scan(priv))
3611 cfg80211_sched_scan_stopped_locked(priv->wdev.wiphy, 0);
3612
3613 ret = nxpwifi_deauthenticate(priv, NULL);
3614 if (!ret) {
3615 eth_zero_addr(priv->cfg_bssid);
3616 priv->hs2_enabled = false;
3617 }
3618
3619 return ret;
3620 }
3621
3622 static int
nxpwifi_cfg80211_deauthenticate(struct wiphy * wiphy,struct net_device * dev,struct cfg80211_deauth_request * req)3623 nxpwifi_cfg80211_deauthenticate(struct wiphy *wiphy,
3624 struct net_device *dev,
3625 struct cfg80211_deauth_request *req)
3626 {
3627 return nxpwifi_cfg80211_disconnect(wiphy, dev, req->reason_code);
3628 }
3629
3630 static int
nxpwifi_cfg80211_disassociate(struct wiphy * wiphy,struct net_device * dev,struct cfg80211_disassoc_request * req)3631 nxpwifi_cfg80211_disassociate(struct wiphy *wiphy,
3632 struct net_device *dev,
3633 struct cfg80211_disassoc_request *req)
3634 {
3635 return nxpwifi_cfg80211_disconnect(wiphy, dev, req->reason_code);
3636 }
3637
3638 static int
nxpwifi_cfg80211_probe_peer(struct wiphy * wiphy,struct net_device * dev,const u8 * peer,u64 cookie)3639 nxpwifi_cfg80211_probe_peer(struct wiphy *wiphy,
3640 struct net_device *dev, const u8 *peer,
3641 u64 cookie)
3642 {
3643 /*
3644 * hostapd looks for NL80211_CMD_PROBE_CLIENT support; otherwise,
3645 * it requires monitor-mode support (which mwifiex doesn't support).
3646 * Provide fake probe_peer support to work around this.
3647 */
3648 return -EOPNOTSUPP;
3649 }
3650
3651 /* station cfg80211 operations */
3652 static const struct cfg80211_ops nxpwifi_cfg80211_ops = {
3653 .add_virtual_intf = nxpwifi_add_virtual_intf,
3654 .del_virtual_intf = nxpwifi_del_virtual_intf,
3655 .change_virtual_intf = nxpwifi_cfg80211_change_virtual_intf,
3656 .scan = nxpwifi_cfg80211_scan,
3657 .auth = nxpwifi_cfg80211_authenticate,
3658 .assoc = nxpwifi_cfg80211_associate,
3659 .deauth = nxpwifi_cfg80211_deauthenticate,
3660 .disassoc = nxpwifi_cfg80211_disassociate,
3661 .probe_peer = nxpwifi_cfg80211_probe_peer,
3662 .get_station = nxpwifi_cfg80211_get_station,
3663 .dump_station = nxpwifi_cfg80211_dump_station,
3664 .dump_survey = nxpwifi_cfg80211_dump_survey,
3665 .set_wiphy_params = nxpwifi_cfg80211_set_wiphy_params,
3666 .add_key = nxpwifi_cfg80211_add_key,
3667 .del_key = nxpwifi_cfg80211_del_key,
3668 .set_default_mgmt_key = nxpwifi_cfg80211_set_default_mgmt_key,
3669 .mgmt_tx = nxpwifi_cfg80211_mgmt_tx,
3670 .update_mgmt_frame_registrations =
3671 nxpwifi_cfg80211_update_mgmt_frame_registrations,
3672 .remain_on_channel = nxpwifi_cfg80211_remain_on_channel,
3673 .cancel_remain_on_channel = nxpwifi_cfg80211_cancel_remain_on_channel,
3674 .set_default_key = nxpwifi_cfg80211_set_default_key,
3675 .set_power_mgmt = nxpwifi_cfg80211_set_power_mgmt,
3676 .set_tx_power = nxpwifi_cfg80211_set_tx_power,
3677 .get_tx_power = nxpwifi_cfg80211_get_tx_power,
3678 .set_bitrate_mask = nxpwifi_cfg80211_set_bitrate_mask,
3679 .start_ap = nxpwifi_cfg80211_start_ap,
3680 .stop_ap = nxpwifi_cfg80211_stop_ap,
3681 .change_beacon = nxpwifi_cfg80211_change_beacon,
3682 .set_cqm_rssi_config = nxpwifi_cfg80211_set_cqm_rssi_config,
3683 .set_antenna = nxpwifi_cfg80211_set_antenna,
3684 .get_antenna = nxpwifi_cfg80211_get_antenna,
3685 .del_station = nxpwifi_cfg80211_del_station,
3686 .sched_scan_start = nxpwifi_cfg80211_sched_scan_start,
3687 .sched_scan_stop = nxpwifi_cfg80211_sched_scan_stop,
3688 .change_station = nxpwifi_cfg80211_change_station,
3689 #ifdef CONFIG_PM
3690 .suspend = nxpwifi_cfg80211_suspend,
3691 .resume = nxpwifi_cfg80211_resume,
3692 .set_wakeup = nxpwifi_cfg80211_set_wakeup,
3693 #endif
3694 .set_coalesce = nxpwifi_cfg80211_set_coalesce,
3695 .add_station = nxpwifi_cfg80211_add_station,
3696 CFG80211_TESTMODE_CMD(nxpwifi_tm_cmd)
3697 .get_channel = nxpwifi_cfg80211_get_channel,
3698 .start_radar_detection = nxpwifi_cfg80211_start_radar_detection,
3699 .channel_switch = nxpwifi_cfg80211_channel_switch,
3700 };
3701
3702 #ifdef CONFIG_PM
3703 static const struct wiphy_wowlan_support nxpwifi_wowlan_support = {
3704 .flags = WIPHY_WOWLAN_MAGIC_PKT | WIPHY_WOWLAN_DISCONNECT |
3705 WIPHY_WOWLAN_NET_DETECT | WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
3706 WIPHY_WOWLAN_GTK_REKEY_FAILURE,
3707 .n_patterns = NXPWIFI_MEF_MAX_FILTERS,
3708 .pattern_min_len = 1,
3709 .pattern_max_len = NXPWIFI_MAX_PATTERN_LEN,
3710 .max_pkt_offset = NXPWIFI_MAX_OFFSET_LEN,
3711 .max_nd_match_sets = NXPWIFI_MAX_ND_MATCH_SETS,
3712 };
3713
3714 static const struct wiphy_wowlan_support nxpwifi_wowlan_support_no_gtk = {
3715 .flags = WIPHY_WOWLAN_MAGIC_PKT | WIPHY_WOWLAN_DISCONNECT |
3716 WIPHY_WOWLAN_NET_DETECT,
3717 .n_patterns = NXPWIFI_MEF_MAX_FILTERS,
3718 .pattern_min_len = 1,
3719 .pattern_max_len = NXPWIFI_MAX_PATTERN_LEN,
3720 .max_pkt_offset = NXPWIFI_MAX_OFFSET_LEN,
3721 .max_nd_match_sets = NXPWIFI_MAX_ND_MATCH_SETS,
3722 };
3723 #endif
3724
3725 static const struct wiphy_coalesce_support nxpwifi_coalesce_support = {
3726 .n_rules = NXPWIFI_COALESCE_MAX_RULES,
3727 .max_delay = NXPWIFI_MAX_COALESCING_DELAY,
3728 .n_patterns = NXPWIFI_COALESCE_MAX_FILTERS,
3729 .pattern_min_len = 1,
3730 .pattern_max_len = NXPWIFI_MAX_PATTERN_LEN,
3731 .max_pkt_offset = NXPWIFI_MAX_OFFSET_LEN,
3732 };
3733
nxpwifi_init_channel_scan_gap(struct nxpwifi_adapter * adapter)3734 int nxpwifi_init_channel_scan_gap(struct nxpwifi_adapter *adapter)
3735 {
3736 u32 n_channels_bg, n_channels_a = 0;
3737
3738 n_channels_bg = nxpwifi_band_2ghz.n_channels;
3739
3740 if (adapter->fw_bands & BAND_A)
3741 n_channels_a = nxpwifi_band_5ghz.n_channels;
3742
3743 /*
3744 * allocate twice the number total channels, since the driver issues an
3745 * additional active scan request for hidden SSIDs on passive channels.
3746 */
3747 adapter->num_in_chan_stats = 2 * (n_channels_bg + n_channels_a);
3748 adapter->chan_stats = kcalloc(adapter->num_in_chan_stats,
3749 sizeof(*adapter->chan_stats),
3750 GFP_KERNEL);
3751
3752 if (!adapter->chan_stats)
3753 return -ENOMEM;
3754
3755 return 0;
3756 }
3757
3758 /*
3759 * Register the device with cfg80211.
3760 *
3761 * Create and initialize the wiphy, fill in defaults and handlers,
3762 * then register it with the cfg80211 subsystem.
3763 */
nxpwifi_register_cfg80211(struct nxpwifi_adapter * adapter)3764 int nxpwifi_register_cfg80211(struct nxpwifi_adapter *adapter)
3765 {
3766 int ret;
3767 void *wdev_priv;
3768 struct wiphy *wiphy;
3769 struct nxpwifi_private *priv = adapter->priv[NXPWIFI_BSS_TYPE_STA];
3770 struct ieee80211_sta_ht_cap *ht_cap;
3771 struct ieee80211_sta_vht_cap *vht_cap;
3772 u8 *country_code;
3773 u32 thr, retry;
3774
3775 /* create a new wiphy for use with cfg80211 */
3776 wiphy = wiphy_new(&nxpwifi_cfg80211_ops,
3777 sizeof(struct nxpwifi_adapter *));
3778 if (!wiphy) {
3779 nxpwifi_dbg(adapter, ERROR,
3780 "%s: creating new wiphy\n", __func__);
3781 return -ENOMEM;
3782 }
3783
3784 wiphy->max_scan_ssids = NXPWIFI_MAX_SSID_LIST_LENGTH;
3785 wiphy->max_scan_ie_len = NXPWIFI_MAX_VSIE_LEN;
3786
3787 wiphy->mgmt_stypes = nxpwifi_mgmt_stypes;
3788 wiphy->max_remain_on_channel_duration = 5000;
3789 wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
3790 BIT(NL80211_IFTYPE_AP) |
3791 BIT(NL80211_IFTYPE_MONITOR);
3792
3793 wiphy->max_num_akm_suites = CFG80211_MAX_NUM_AKM_SUITES;
3794
3795 wiphy->bands[NL80211_BAND_2GHZ] =
3796 devm_kmemdup(adapter->dev, &nxpwifi_band_2ghz,
3797 sizeof(nxpwifi_band_2ghz), GFP_KERNEL);
3798 if (!wiphy->bands[NL80211_BAND_2GHZ]) {
3799 ret = -ENOMEM;
3800 goto err;
3801 }
3802
3803 if (adapter->fw_bands & BAND_A) {
3804 wiphy->bands[NL80211_BAND_5GHZ] =
3805 devm_kmemdup(adapter->dev, &nxpwifi_band_5ghz,
3806 sizeof(nxpwifi_band_5ghz), GFP_KERNEL);
3807 if (!wiphy->bands[NL80211_BAND_5GHZ]) {
3808 ret = -ENOMEM;
3809 goto err;
3810 }
3811 } else {
3812 wiphy->bands[NL80211_BAND_5GHZ] = NULL;
3813 }
3814
3815 ht_cap = &wiphy->bands[NL80211_BAND_2GHZ]->ht_cap;
3816 nxpwifi_setup_ht_caps(priv, ht_cap);
3817
3818 if (adapter->is_hw_11ac_capable) {
3819 vht_cap = &wiphy->bands[NL80211_BAND_2GHZ]->vht_cap;
3820 nxpwifi_setup_vht_caps(priv, vht_cap);
3821 }
3822
3823 if (adapter->is_hw_11ax_capable)
3824 nxpwifi_setup_he_caps(priv, wiphy->bands[NL80211_BAND_2GHZ]);
3825
3826 if (adapter->fw_bands & BAND_A) {
3827 ht_cap = &wiphy->bands[NL80211_BAND_5GHZ]->ht_cap;
3828 nxpwifi_setup_ht_caps(priv, ht_cap);
3829
3830 if (adapter->is_hw_11ac_capable) {
3831 vht_cap = &wiphy->bands[NL80211_BAND_5GHZ]->vht_cap;
3832 nxpwifi_setup_vht_caps(priv, vht_cap);
3833 }
3834
3835 if (adapter->is_hw_11ax_capable)
3836 nxpwifi_setup_he_caps(priv, wiphy->bands[NL80211_BAND_5GHZ]);
3837 }
3838
3839 if (adapter->is_hw_11ac_capable)
3840 wiphy->iface_combinations = &nxpwifi_iface_comb_ap_sta_vht;
3841 else
3842 wiphy->iface_combinations = &nxpwifi_iface_comb_ap_sta;
3843 wiphy->n_iface_combinations = 1;
3844
3845 wiphy->max_ap_assoc_sta = adapter->max_sta_conn;
3846
3847 /* Initialize cipher suits */
3848 wiphy->cipher_suites = nxpwifi_cipher_suites;
3849 wiphy->n_cipher_suites = ARRAY_SIZE(nxpwifi_cipher_suites);
3850
3851 if (adapter->regd) {
3852 wiphy->regulatory_flags |= REGULATORY_CUSTOM_REG |
3853 REGULATORY_DISABLE_BEACON_HINTS |
3854 REGULATORY_COUNTRY_IE_IGNORE;
3855 wiphy_apply_custom_regulatory(wiphy, adapter->regd);
3856 }
3857
3858 ether_addr_copy(wiphy->perm_addr, adapter->perm_addr);
3859 wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
3860 wiphy->flags |= WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD |
3861 WIPHY_FLAG_AP_UAPSD |
3862 WIPHY_FLAG_REPORTS_OBSS |
3863 WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL |
3864 WIPHY_FLAG_HAS_CHANNEL_SWITCH |
3865 WIPHY_FLAG_NETNS_OK |
3866 WIPHY_FLAG_PS_ON_BY_DEFAULT;
3867 wiphy->max_num_csa_counters = NXPWIFI_MAX_CSA_COUNTERS;
3868
3869 #ifdef CONFIG_PM
3870 if (ISSUPP_FIRMWARE_SUPPLICANT(priv->adapter->fw_cap_info))
3871 wiphy->wowlan = &nxpwifi_wowlan_support;
3872 else
3873 wiphy->wowlan = &nxpwifi_wowlan_support_no_gtk;
3874 #endif
3875
3876 wiphy->coalesce = &nxpwifi_coalesce_support;
3877
3878 wiphy->probe_resp_offload = NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS |
3879 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2;
3880
3881 wiphy->max_sched_scan_reqs = 1;
3882 wiphy->max_sched_scan_ssids = NXPWIFI_MAX_SSID_LIST_LENGTH;
3883 wiphy->max_sched_scan_ie_len = NXPWIFI_MAX_VSIE_LEN;
3884 wiphy->max_match_sets = NXPWIFI_MAX_SSID_LIST_LENGTH;
3885
3886 wiphy->available_antennas_tx = BIT(adapter->number_of_antenna) - 1;
3887 wiphy->available_antennas_rx = BIT(adapter->number_of_antenna) - 1;
3888
3889 wiphy->features |= NL80211_FEATURE_SAE |
3890 NL80211_FEATURE_INACTIVITY_TIMER |
3891 NL80211_FEATURE_LOW_PRIORITY_SCAN |
3892 NL80211_FEATURE_NEED_OBSS_SCAN;
3893
3894 if (ISSUPP_RANDOM_MAC(adapter->fw_cap_info))
3895 wiphy->features |= NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR |
3896 NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR |
3897 NL80211_FEATURE_ND_RANDOM_MAC_ADDR;
3898
3899 if (adapter->fw_api_ver == NXPWIFI_FW_V15)
3900 wiphy->features |= NL80211_FEATURE_SK_TX_STATUS;
3901
3902 /* Reserve space for nxpwifi specific private data for BSS */
3903 wiphy->bss_priv_size = sizeof(struct nxpwifi_bss_priv);
3904
3905 wiphy->reg_notifier = nxpwifi_reg_notifier;
3906
3907 /* Set struct nxpwifi_adapter pointer in wiphy_priv */
3908 wdev_priv = wiphy_priv(wiphy);
3909 *(unsigned long *)wdev_priv = (unsigned long)adapter;
3910
3911 set_wiphy_dev(wiphy, priv->adapter->dev);
3912
3913 ret = wiphy_register(wiphy);
3914 if (ret < 0) {
3915 nxpwifi_dbg(adapter, ERROR,
3916 "%s: wiphy_register failed: %d\n", __func__, ret);
3917 goto err;
3918 }
3919
3920 if (!adapter->regd) {
3921 if (adapter->region_code == 0x00) {
3922 nxpwifi_dbg(adapter, WARN,
3923 "Ignore world regulatory domain\n");
3924 } else {
3925 wiphy->regulatory_flags |=
3926 REGULATORY_DISABLE_BEACON_HINTS |
3927 REGULATORY_COUNTRY_IE_IGNORE;
3928 country_code =
3929 nxpwifi_11d_code_2_region(adapter->region_code);
3930 if (country_code &&
3931 regulatory_hint(wiphy, country_code))
3932 nxpwifi_dbg(priv->adapter, ERROR,
3933 "regulatory_hint() failed\n");
3934 }
3935 }
3936
3937 nxpwifi_get_802_11_snmp_mib(priv, FRAG_THRESH_I, &thr);
3938 wiphy->frag_threshold = thr;
3939 nxpwifi_get_802_11_snmp_mib(priv, RTS_THRESH_I, &thr);
3940 wiphy->rts_threshold = thr;
3941 nxpwifi_get_802_11_snmp_mib(priv, SHORT_RETRY_LIM_I, &retry);
3942 wiphy->retry_short = (u8)retry;
3943 nxpwifi_get_802_11_snmp_mib(priv, LONG_RETRY_LIM_I, &retry);
3944 wiphy->retry_long = (u8)retry;
3945
3946 adapter->wiphy = wiphy;
3947 return ret;
3948
3949 err:
3950 wiphy_free(wiphy);
3951 return ret;
3952 }
3953