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