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