2 * Marvell Wireless LAN device driver: CFG80211
4 * Copyright (C) 2011-2014, Marvell International Ltd.
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.
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.
23 static char *reg_alpha2
;
24 module_param(reg_alpha2
, charp
, 0);
26 static const struct ieee80211_iface_limit mwifiex_ap_sta_limits
[] = {
28 .max
= 2, .types
= BIT(NL80211_IFTYPE_STATION
) |
29 BIT(NL80211_IFTYPE_P2P_GO
) |
30 BIT(NL80211_IFTYPE_P2P_CLIENT
),
33 .max
= 1, .types
= BIT(NL80211_IFTYPE_AP
),
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,
46 * This function maps the nl802.11 channel type into driver channel type.
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
55 u8
mwifiex_chan_type_to_sec_chan_offset(enum nl80211_channel_type 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
;
66 return IEEE80211_HT_PARAM_CHA_SEC_NONE
;
71 * This function checks whether WEP is set.
74 mwifiex_is_alg_wep(u32 cipher
)
77 case WLAN_CIPHER_SUITE_WEP40
:
78 case WLAN_CIPHER_SUITE_WEP104
:
88 * This function retrieves the private structure from kernel wiphy structure.
90 static void *mwifiex_cfg80211_get_adapter(struct wiphy
*wiphy
)
92 return (void *) (*(unsigned long *) wiphy_priv(wiphy
));
96 * CFG802.11 operation handler to delete a network key.
99 mwifiex_cfg80211_del_key(struct wiphy
*wiphy
, struct net_device
*netdev
,
100 u8 key_index
, bool pairwise
, const u8
*mac_addr
)
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
;
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");
111 mwifiex_dbg(priv
->adapter
, INFO
, "info: crypto keys deleted\n");
116 * This function forms an skb for management frame.
119 mwifiex_form_mgmt_frame(struct sk_buff
*skb
, const u8
*buf
, size_t len
)
121 u8 addr
[ETH_ALEN
] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
123 u32 tx_control
= 0, pkt_type
= PKT_TYPE_MGMT
;
125 pkt_len
= len
+ ETH_ALEN
;
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
));
131 memcpy(skb_push(skb
, sizeof(tx_control
)),
132 &tx_control
, sizeof(tx_control
));
134 memcpy(skb_push(skb
, sizeof(pkt_type
)), &pkt_type
, sizeof(pkt_type
));
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
));
144 skb
->priority
= LOW_PRIO_TID
;
145 __net_timestamp(skb
);
151 * CFG802.11 operation handler to transmit a management frame.
154 mwifiex_cfg80211_mgmt_tx(struct wiphy
*wiphy
, struct wireless_dev
*wdev
,
155 struct cfg80211_mgmt_tx_params
*params
, u64
*cookie
)
157 const u8
*buf
= params
->buf
;
158 size_t len
= params
->len
;
161 const struct ieee80211_mgmt
*mgmt
;
162 struct mwifiex_txinfo
*tx_info
;
163 struct mwifiex_private
*priv
= mwifiex_netdev_get_priv(wdev
->netdev
);
166 mwifiex_dbg(priv
->adapter
, ERROR
, "invalid buffer and length\n");
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");
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
));
186 mwifiex_dbg(priv
->adapter
, ERROR
,
187 "allocate skb failed for management frame\n");
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
;
197 mwifiex_form_mgmt_frame(skb
, buf
, len
);
198 *cookie
= prandom_u32() | 1;
200 if (ieee80211_is_action(mgmt
->frame_control
))
201 skb
= mwifiex_clone_skb_for_tx_status(priv
,
203 MWIFIEX_BUF_FLAG_ACTION_TX_STATUS
, cookie
);
205 cfg80211_mgmt_tx_status(wdev
, *cookie
, buf
, len
, true,
208 mwifiex_queue_tx_pkt(priv
, skb
);
210 mwifiex_dbg(priv
->adapter
, INFO
, "info: management frame transmitted\n");
215 * CFG802.11 operation handler to register a mgmt frame.
218 mwifiex_cfg80211_mgmt_frame_register(struct wiphy
*wiphy
,
219 struct wireless_dev
*wdev
,
220 u16 frame_type
, bool reg
)
222 struct mwifiex_private
*priv
= mwifiex_netdev_get_priv(wdev
->netdev
);
226 mask
= priv
->mgmt_frame_mask
| BIT(frame_type
>> 4);
228 mask
= priv
->mgmt_frame_mask
& ~BIT(frame_type
>> 4);
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");
240 * CFG802.11 operation handler to remain on channel.
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
)
248 struct mwifiex_private
*priv
= mwifiex_netdev_get_priv(wdev
->netdev
);
251 if (!chan
|| !cookie
) {
252 mwifiex_dbg(priv
->adapter
, ERROR
, "Invalid parameter for ROC\n");
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
);
263 ret
= mwifiex_remain_on_chan_cfg(priv
, HostCmd_ACT_GEN_SET
, chan
,
267 *cookie
= prandom_u32() | 1;
268 priv
->roc_cfg
.cookie
= *cookie
;
269 priv
->roc_cfg
.chan
= *chan
;
271 cfg80211_ready_on_channel(wdev
, *cookie
, chan
,
272 duration
, GFP_ATOMIC
);
274 mwifiex_dbg(priv
->adapter
, INFO
,
275 "info: ROC, cookie = 0x%llx\n", *cookie
);
282 * CFG802.11 operation handler to cancel remain on channel.
285 mwifiex_cfg80211_cancel_remain_on_channel(struct wiphy
*wiphy
,
286 struct wireless_dev
*wdev
, u64 cookie
)
288 struct mwifiex_private
*priv
= mwifiex_netdev_get_priv(wdev
->netdev
);
291 if (cookie
!= priv
->roc_cfg
.cookie
)
294 ret
= mwifiex_remain_on_chan_cfg(priv
, HostCmd_ACT_GEN_REMOVE
,
295 &priv
->roc_cfg
.chan
, 0);
298 cfg80211_remain_on_channel_expired(wdev
, cookie
,
302 memset(&priv
->roc_cfg
, 0, sizeof(struct mwifiex_roc_cfg
));
304 mwifiex_dbg(priv
->adapter
, INFO
,
305 "info: cancel ROC, cookie = 0x%llx\n", cookie
);
312 * CFG802.11 operation handler to set Tx power.
315 mwifiex_cfg80211_set_tx_power(struct wiphy
*wiphy
,
316 struct wireless_dev
*wdev
,
317 enum nl80211_tx_power_setting type
,
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
);
325 if (type
== NL80211_TX_POWER_FIXED
) {
326 power_cfg
.is_power_auto
= 0;
327 power_cfg
.power_level
= dbm
;
329 power_cfg
.is_power_auto
= 1;
332 priv
= mwifiex_get_priv(adapter
, MWIFIEX_BSS_ROLE_ANY
);
334 return mwifiex_set_tx_power(priv
, &power_cfg
);
338 * CFG802.11 operation handler to set Power Save option.
340 * The timeout value, if provided, is currently ignored.
343 mwifiex_cfg80211_set_power_mgmt(struct wiphy
*wiphy
,
344 struct net_device
*dev
,
345 bool enabled
, int timeout
)
347 struct mwifiex_private
*priv
= mwifiex_netdev_get_priv(dev
);
351 mwifiex_dbg(priv
->adapter
, INFO
,
352 "info: ignore timeout value for IEEE Power Save\n");
356 return mwifiex_drv_set_power(priv
, &ps_mode
);
360 * CFG802.11 operation handler to set the default network key.
363 mwifiex_cfg80211_set_default_key(struct wiphy
*wiphy
, struct net_device
*netdev
,
364 u8 key_index
, bool unicast
,
367 struct mwifiex_private
*priv
= mwifiex_netdev_get_priv(netdev
);
369 /* Return if WEP key not configured */
370 if (!priv
->sec_info
.wep_enabled
)
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
,
377 mwifiex_dbg(priv
->adapter
, ERROR
, "set default Tx key index\n");
385 * CFG802.11 operation handler to add a network key.
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
)
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
;
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
,
405 wep_key
->key_index
= key_index
;
406 wep_key
->key_length
= params
->key_len
;
407 priv
->sec_info
.wep_enabled
= 1;
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");
422 * This function sends domain information to the firmware.
424 * The following information are passed to the firmware -
426 * - Sub bands (first channel, number of channels, maximum Tx power)
428 static int mwifiex_send_domain_info_cmd_fw(struct wiphy
*wiphy
)
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;
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
;
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] = ' ';
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");
454 sband
= wiphy
->bands
[band
];
456 for (i
= 0; i
< sband
->n_channels
; i
++) {
457 ch
= &sband
->channels
[i
];
458 if (ch
->flags
& IEEE80211_CHAN_DISABLED
)
463 first_chan
= (u32
) ch
->hw_value
;
464 next_chan
= first_chan
;
465 max_pwr
= ch
->max_power
;
466 no_of_parsed_chan
= 1;
470 if (ch
->hw_value
== next_chan
+ 1 &&
471 ch
->max_power
== max_pwr
) {
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
;
480 first_chan
= (u32
) ch
->hw_value
;
481 next_chan
= first_chan
;
482 max_pwr
= ch
->max_power
;
483 no_of_parsed_chan
= 1;
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
;
495 domain_info
->no_of_triplet
= no_of_triplet
;
497 priv
= mwifiex_get_priv(adapter
, MWIFIEX_BSS_ROLE_ANY
);
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");
510 * CFG802.11 regulatory domain callback function.
512 * This function is called when the regulatory domain is changed due to the
513 * following reasons -
515 * - Set by system core
517 * - Set bt Country IE
519 static void mwifiex_reg_notifier(struct wiphy
*wiphy
,
520 struct regulatory_request
*request
)
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]);
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
:
536 mwifiex_dbg(adapter
, ERROR
,
537 "unknown regdom initiator: %d\n",
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
);
554 * This function sets the fragmentation threshold.
556 * The fragmentation threshold value must lie between MWIFIEX_FRAG_MIN_VALUE
557 * and MWIFIEX_FRAG_MAX_VALUE.
560 mwifiex_set_frag(struct mwifiex_private
*priv
, u32 frag_thr
)
562 if (frag_thr
< MWIFIEX_FRAG_MIN_VALUE
||
563 frag_thr
> MWIFIEX_FRAG_MAX_VALUE
)
564 frag_thr
= MWIFIEX_FRAG_MAX_VALUE
;
566 return mwifiex_send_cmd(priv
, HostCmd_CMD_802_11_SNMP_MIB
,
567 HostCmd_ACT_GEN_SET
, FRAG_THRESH_I
,
572 * This function sets the RTS threshold.
574 * The rts value must lie between MWIFIEX_RTS_MIN_VALUE
575 * and MWIFIEX_RTS_MAX_VALUE.
578 mwifiex_set_rts(struct mwifiex_private
*priv
, u32 rts_thr
)
580 if (rts_thr
< MWIFIEX_RTS_MIN_VALUE
|| rts_thr
> MWIFIEX_RTS_MAX_VALUE
)
581 rts_thr
= MWIFIEX_RTS_MAX_VALUE
;
583 return mwifiex_send_cmd(priv
, HostCmd_CMD_802_11_SNMP_MIB
,
584 HostCmd_ACT_GEN_SET
, RTS_THRESH_I
,
589 * CFG802.11 operation handler to set wiphy parameters.
591 * This function can be used to set the RTS threshold and the
592 * Fragmentation threshold of the driver.
595 mwifiex_cfg80211_set_wiphy_params(struct wiphy
*wiphy
, u32 changed
)
597 struct mwifiex_adapter
*adapter
= mwifiex_cfg80211_get_adapter(wiphy
);
598 struct mwifiex_private
*priv
;
599 struct mwifiex_uap_bss_param
*bss_cfg
;
602 priv
= mwifiex_get_priv(adapter
, MWIFIEX_BSS_ROLE_ANY
);
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");
612 bss_cfg
= kzalloc(sizeof(*bss_cfg
), GFP_KERNEL
);
616 mwifiex_set_sys_config_invalid_data(bss_cfg
);
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
;
625 ret
= mwifiex_send_cmd(priv
, HostCmd_CMD_UAP_SYS_CONFIG
,
627 UAP_BSS_PARAMS_I
, bss_cfg
,
632 mwifiex_dbg(adapter
, ERROR
,
633 "Failed to set wiphy phy params\n");
638 case MWIFIEX_BSS_ROLE_STA
:
639 if (priv
->media_connected
) {
640 mwifiex_dbg(adapter
, ERROR
,
641 "cannot change wiphy params when connected");
644 if (changed
& WIPHY_PARAM_RTS_THRESHOLD
) {
645 ret
= mwifiex_set_rts(priv
,
646 wiphy
->rts_threshold
);
650 if (changed
& WIPHY_PARAM_FRAG_THRESHOLD
) {
651 ret
= mwifiex_set_frag(priv
,
652 wiphy
->frag_threshold
);
663 mwifiex_cfg80211_deinit_p2p(struct mwifiex_private
*priv
)
665 u16 mode
= P2P_MODE_DISABLE
;
667 if (mwifiex_send_cmd(priv
, HostCmd_CMD_P2P_MODE_CFG
,
668 HostCmd_ACT_GEN_SET
, 0, &mode
, true))
675 * This function initializes the functionalities for P2P client.
676 * The P2P client initialization sequence is:
677 * disable -> device -> client
680 mwifiex_cfg80211_init_p2p_client(struct mwifiex_private
*priv
)
684 if (mwifiex_cfg80211_deinit_p2p(priv
))
687 mode
= P2P_MODE_DEVICE
;
688 if (mwifiex_send_cmd(priv
, HostCmd_CMD_P2P_MODE_CFG
,
689 HostCmd_ACT_GEN_SET
, 0, &mode
, true))
692 mode
= P2P_MODE_CLIENT
;
693 if (mwifiex_send_cmd(priv
, HostCmd_CMD_P2P_MODE_CFG
,
694 HostCmd_ACT_GEN_SET
, 0, &mode
, true))
701 * This function initializes the functionalities for P2P GO.
702 * The P2P GO initialization sequence is:
703 * disable -> device -> GO
706 mwifiex_cfg80211_init_p2p_go(struct mwifiex_private
*priv
)
710 if (mwifiex_cfg80211_deinit_p2p(priv
))
713 mode
= P2P_MODE_DEVICE
;
714 if (mwifiex_send_cmd(priv
, HostCmd_CMD_P2P_MODE_CFG
,
715 HostCmd_ACT_GEN_SET
, 0, &mode
, true))
719 if (mwifiex_send_cmd(priv
, HostCmd_CMD_P2P_MODE_CFG
,
720 HostCmd_ACT_GEN_SET
, 0, &mode
, true))
726 static int mwifiex_deinit_priv_params(struct mwifiex_private
*priv
)
728 struct mwifiex_adapter
*adapter
= priv
->adapter
;
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");
740 mwifiex_deauthenticate(priv
, NULL
);
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
);
748 spin_unlock_irqrestore(&adapter
->main_proc_lock
, flags
);
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
);
757 spin_unlock_irqrestore(&adapter
->rx_proc_lock
, flags
);
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
;
769 mwifiex_init_new_priv_params(struct mwifiex_private
*priv
,
770 struct net_device
*dev
,
771 enum nl80211_iftype type
)
773 struct mwifiex_adapter
*adapter
= priv
->adapter
;
776 mwifiex_init_priv(priv
);
778 priv
->bss_mode
= type
;
779 priv
->wdev
.iftype
= type
;
781 mwifiex_init_priv_params(priv
, priv
->netdev
);
782 priv
->bss_started
= 0;
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
;
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
;
795 case NL80211_IFTYPE_AP
:
796 priv
->bss_type
= MWIFIEX_BSS_TYPE_UAP
;
797 priv
->bss_role
= MWIFIEX_BSS_ROLE_UAP
;
800 mwifiex_dbg(adapter
, ERROR
,
801 "%s: changing to %d not supported\n",
806 spin_lock_irqsave(&adapter
->main_proc_lock
, flags
);
807 adapter
->main_locked
= false;
808 spin_unlock_irqrestore(&adapter
->main_proc_lock
, flags
);
810 spin_lock_irqsave(&adapter
->rx_proc_lock
, flags
);
811 adapter
->rx_locked
= false;
812 spin_unlock_irqrestore(&adapter
->rx_proc_lock
, flags
);
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
)
823 struct mwifiex_private
*priv
;
824 struct mwifiex_adapter
*adapter
;
826 priv
= mwifiex_netdev_get_priv(dev
);
831 adapter
= priv
->adapter
;
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");
840 mwifiex_dbg(adapter
, INFO
,
841 "%s: changing role to p2p\n", dev
->name
);
843 if (mwifiex_deinit_priv_params(priv
))
845 if (mwifiex_init_new_priv_params(priv
, dev
, type
))
849 case NL80211_IFTYPE_P2P_CLIENT
:
850 if (mwifiex_cfg80211_init_p2p_client(priv
))
853 case NL80211_IFTYPE_P2P_GO
:
854 if (mwifiex_cfg80211_init_p2p_go(priv
))
858 mwifiex_dbg(adapter
, ERROR
,
859 "%s: changing to %d not supported\n",
864 if (mwifiex_send_cmd(priv
, HostCmd_CMD_SET_BSS_MODE
,
865 HostCmd_ACT_GEN_SET
, 0, NULL
, true))
868 if (mwifiex_sta_init_cmd(priv
, false, false))
871 switch (curr_iftype
) {
872 case NL80211_IFTYPE_STATION
:
873 case NL80211_IFTYPE_ADHOC
:
874 adapter
->curr_iface_comb
.sta_intf
--;
876 case NL80211_IFTYPE_AP
:
877 adapter
->curr_iface_comb
.uap_intf
--;
883 adapter
->curr_iface_comb
.p2p_intf
++;
884 dev
->ieee80211_ptr
->iftype
= type
;
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
)
895 struct mwifiex_private
*priv
;
896 struct mwifiex_adapter
*adapter
;
898 priv
= mwifiex_netdev_get_priv(dev
);
903 adapter
= priv
->adapter
;
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");
914 if (type
== NL80211_IFTYPE_STATION
)
915 mwifiex_dbg(adapter
, INFO
,
916 "%s: changing role to station\n", dev
->name
);
918 mwifiex_dbg(adapter
, INFO
,
919 "%s: changing role to adhoc\n", dev
->name
);
921 if (mwifiex_deinit_priv_params(priv
))
923 if (mwifiex_init_new_priv_params(priv
, dev
, type
))
925 if (mwifiex_send_cmd(priv
, HostCmd_CMD_SET_BSS_MODE
,
926 HostCmd_ACT_GEN_SET
, 0, NULL
, true))
928 if (mwifiex_sta_init_cmd(priv
, false, false))
931 switch (curr_iftype
) {
932 case NL80211_IFTYPE_P2P_CLIENT
:
933 case NL80211_IFTYPE_P2P_GO
:
934 adapter
->curr_iface_comb
.p2p_intf
--;
936 case NL80211_IFTYPE_AP
:
937 adapter
->curr_iface_comb
.uap_intf
--;
943 adapter
->curr_iface_comb
.sta_intf
++;
944 dev
->ieee80211_ptr
->iftype
= type
;
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
)
954 struct mwifiex_private
*priv
;
955 struct mwifiex_adapter
*adapter
;
957 priv
= mwifiex_netdev_get_priv(dev
);
962 adapter
= priv
->adapter
;
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");
971 mwifiex_dbg(adapter
, INFO
,
972 "%s: changing role to AP\n", dev
->name
);
974 if (mwifiex_deinit_priv_params(priv
))
976 if (mwifiex_init_new_priv_params(priv
, dev
, type
))
978 if (mwifiex_send_cmd(priv
, HostCmd_CMD_SET_BSS_MODE
,
979 HostCmd_ACT_GEN_SET
, 0, NULL
, true))
981 if (mwifiex_sta_init_cmd(priv
, false, false))
984 switch (curr_iftype
) {
985 case NL80211_IFTYPE_P2P_CLIENT
:
986 case NL80211_IFTYPE_P2P_GO
:
987 adapter
->curr_iface_comb
.p2p_intf
--;
989 case NL80211_IFTYPE_STATION
:
990 case NL80211_IFTYPE_ADHOC
:
991 adapter
->curr_iface_comb
.sta_intf
--;
997 adapter
->curr_iface_comb
.uap_intf
++;
998 dev
->ieee80211_ptr
->iftype
= type
;
1002 * CFG802.11 operation handler to change interface type.
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
)
1010 struct mwifiex_private
*priv
= mwifiex_netdev_get_priv(dev
);
1011 enum nl80211_iftype curr_iftype
= dev
->ieee80211_ptr
->iftype
;
1013 switch (curr_iftype
) {
1014 case NL80211_IFTYPE_ADHOC
:
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
,
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
,
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 */
1038 mwifiex_dbg(priv
->adapter
, ERROR
,
1039 "%s: changing to %d not supported\n",
1044 case NL80211_IFTYPE_STATION
:
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
,
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
,
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 */
1068 mwifiex_dbg(priv
->adapter
, ERROR
,
1069 "%s: changing to %d not supported\n",
1074 case NL80211_IFTYPE_AP
:
1076 case NL80211_IFTYPE_ADHOC
:
1077 case NL80211_IFTYPE_STATION
:
1078 return mwifiex_change_vif_to_sta_adhoc(dev
, curr_iftype
,
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 */
1092 mwifiex_dbg(priv
->adapter
, ERROR
,
1093 "%s: changing to %d not supported\n",
1098 case NL80211_IFTYPE_P2P_CLIENT
:
1099 case NL80211_IFTYPE_P2P_GO
:
1101 case NL80211_IFTYPE_STATION
:
1102 if (mwifiex_cfg80211_init_p2p_client(priv
))
1104 dev
->ieee80211_ptr
->iftype
= type
;
1106 case NL80211_IFTYPE_ADHOC
:
1107 if (mwifiex_cfg80211_deinit_p2p(priv
))
1109 return mwifiex_change_vif_to_sta_adhoc(dev
, curr_iftype
,
1113 case NL80211_IFTYPE_AP
:
1114 if (mwifiex_cfg80211_deinit_p2p(priv
))
1116 return mwifiex_change_vif_to_ap(dev
, curr_iftype
, type
,
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
:
1125 mwifiex_dbg(priv
->adapter
, ERROR
,
1126 "%s: changing to %d not supported\n",
1132 mwifiex_dbg(priv
->adapter
, ERROR
,
1133 "%s: unknown iftype: %d\n",
1134 dev
->name
, dev
->ieee80211_ptr
->iftype
);
1143 mwifiex_parse_htinfo(struct mwifiex_private
*priv
, u8 tx_htinfo
,
1144 struct rate_info
*rate
)
1146 struct mwifiex_adapter
*adapter
= priv
->adapter
;
1148 if (adapter
->is_hw_11ac_capable
) {
1149 /* bit[1-0]: 00=LG 01=HT 10=VHT */
1150 if (tx_htinfo
& BIT(0)) {
1152 rate
->mcs
= priv
->tx_rate
;
1153 rate
->flags
|= RATE_INFO_FLAGS_MCS
;
1155 if (tx_htinfo
& BIT(1)) {
1157 rate
->mcs
= priv
->tx_rate
& 0x0F;
1158 rate
->flags
|= RATE_INFO_FLAGS_VHT_MCS
;
1161 if (tx_htinfo
& (BIT(1) | BIT(0))) {
1163 switch (tx_htinfo
& (BIT(3) | BIT(2))) {
1165 rate
->bw
= RATE_INFO_BW_20
;
1168 rate
->bw
= RATE_INFO_BW_40
;
1171 rate
->bw
= RATE_INFO_BW_80
;
1173 case (BIT(3) | BIT(2)):
1174 rate
->bw
= RATE_INFO_BW_160
;
1178 if (tx_htinfo
& BIT(4))
1179 rate
->flags
|= RATE_INFO_FLAGS_SHORT_GI
;
1181 if ((priv
->tx_rate
>> 4) == 1)
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.
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
;
1204 * This function dumps the station information on a buffer.
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
1215 mwifiex_dump_station_info(struct mwifiex_private
*priv
,
1216 struct station_info
*sinfo
)
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
);
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");
1233 if (mwifiex_drv_get_data_rate(priv
, &rate
)) {
1234 mwifiex_dbg(priv
->adapter
, ERROR
,
1235 "getting data rate error\n");
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);
1244 mwifiex_parse_htinfo(priv
, priv
->tx_htinfo
, &sinfo
->txrate
);
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;
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
;
1275 * CFG802.11 operation handler to get station information.
1277 * This function only works in connected mode, and dumps the
1278 * requested station information, if available.
1281 mwifiex_cfg80211_get_station(struct wiphy
*wiphy
, struct net_device
*dev
,
1282 const u8
*mac
, struct station_info
*sinfo
)
1284 struct mwifiex_private
*priv
= mwifiex_netdev_get_priv(dev
);
1286 if (!priv
->media_connected
)
1288 if (memcmp(mac
, priv
->cfg_bssid
, ETH_ALEN
))
1291 return mwifiex_dump_station_info(priv
, sinfo
);
1295 * CFG802.11 operation handler to dump station information.
1298 mwifiex_cfg80211_dump_station(struct wiphy
*wiphy
, struct net_device
*dev
,
1299 int idx
, u8
*mac
, struct station_info
*sinfo
)
1301 struct mwifiex_private
*priv
= mwifiex_netdev_get_priv(dev
);
1303 if (!priv
->media_connected
|| idx
)
1306 memcpy(mac
, priv
->cfg_bssid
, ETH_ALEN
);
1308 return mwifiex_dump_station_info(priv
, sinfo
);
1312 mwifiex_cfg80211_dump_survey(struct wiphy
*wiphy
, struct net_device
*dev
,
1313 int idx
, struct survey_info
*survey
)
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
;
1319 mwifiex_dbg(priv
->adapter
, DUMP
, "dump_survey idx=%d\n", idx
);
1321 memset(survey
, 0, sizeof(struct survey_info
));
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
;
1328 band
= mwifiex_band_to_radio_type(curr_bss_band
);
1329 survey
->channel
= ieee80211_get_channel(wiphy
,
1330 ieee80211_channel_to_frequency(chan
, band
));
1332 if (priv
->bcn_nf_last
) {
1333 survey
->filled
= SURVEY_INFO_NOISE_DBM
;
1334 survey
->noise
= priv
->bcn_nf_last
;
1339 if (idx
>= priv
->adapter
->num_in_chan_stats
)
1342 if (!pchan_stats
[idx
].cca_scan_dur
)
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
|
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
;
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, },
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, },
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
),
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, },
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,
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
,
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),
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),
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),
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),
1480 * CFG802.11 operation handler for setting bit rates.
1482 * Function configures data rates to firmware using bitrate mask
1483 * provided by cfg80211.
1485 static int mwifiex_cfg80211_set_bitrate_mask(struct wiphy
*wiphy
,
1486 struct net_device
*dev
,
1488 const struct cfg80211_bitrate_mask
*mask
)
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
;
1495 if (!priv
->media_connected
) {
1496 mwifiex_dbg(adapter
, ERROR
,
1497 "Can not set Tx data rate in disconnected state\n");
1501 band
= mwifiex_band_to_radio_type(priv
->curr_bss_params
.band
);
1503 memset(bitmap_rates
, 0, sizeof(bitmap_rates
));
1505 /* Fill HR/DSSS rates. */
1506 if (band
== IEEE80211_BAND_2GHZ
)
1507 bitmap_rates
[0] = mask
->control
[band
].legacy
& 0x000f;
1509 /* Fill OFDM rates */
1510 if (band
== IEEE80211_BAND_2GHZ
)
1511 bitmap_rates
[1] = (mask
->control
[band
].legacy
& 0x0ff0) >> 4;
1513 bitmap_rates
[1] = mask
->control
[band
].legacy
;
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;
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];
1527 return mwifiex_send_cmd(priv
, HostCmd_CMD_TX_RATE_CFG
,
1528 HostCmd_ACT_GEN_SET
, 0, bitmap_rates
, true);
1532 * CFG802.11 operation handler for connection quality monitoring.
1534 * This function subscribes/unsubscribes HIGH_RSSI and LOW_RSSI
1537 static int mwifiex_cfg80211_set_cqm_rssi_config(struct wiphy
*wiphy
,
1538 struct net_device
*dev
,
1539 s32 rssi_thold
, u32 rssi_hyst
)
1541 struct mwifiex_private
*priv
= mwifiex_netdev_get_priv(dev
);
1542 struct mwifiex_ds_misc_subsc_evt subsc_evt
;
1544 priv
->cqm_rssi_thold
= rssi_thold
;
1545 priv
->cqm_rssi_hyst
= rssi_hyst
;
1547 memset(&subsc_evt
, 0x00, sizeof(struct mwifiex_ds_misc_subsc_evt
));
1548 subsc_evt
.events
= BITMASK_BCN_RSSI_LOW
| BITMASK_BCN_RSSI_HIGH
;
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);
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);
1570 /* cfg80211 operation handler for change_beacon.
1571 * Function retrieves and sets modified management IEs to FW.
1573 static int mwifiex_cfg80211_change_beacon(struct wiphy
*wiphy
,
1574 struct net_device
*dev
,
1575 struct cfg80211_beacon_data
*data
)
1577 struct mwifiex_private
*priv
= mwifiex_netdev_get_priv(dev
);
1579 if (GET_BSS_ROLE(priv
) != MWIFIEX_BSS_ROLE_UAP
) {
1580 mwifiex_dbg(priv
->adapter
, ERROR
,
1581 "%s: bss_type mismatched\n", __func__
);
1585 if (!priv
->bss_started
) {
1586 mwifiex_dbg(priv
->adapter
, ERROR
,
1587 "%s: bss not started\n", __func__
);
1591 if (mwifiex_set_mgmt_ies(priv
, data
)) {
1592 mwifiex_dbg(priv
->adapter
, ERROR
,
1593 "%s: setting mgmt ies failed\n", __func__
);
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.
1607 mwifiex_cfg80211_del_station(struct wiphy
*wiphy
, struct net_device
*dev
,
1608 struct station_del_parameters
*params
)
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
;
1615 if (list_empty(&priv
->sta_list
) || !priv
->bss_started
)
1618 if (!params
->mac
|| is_broadcast_ether_addr(params
->mac
))
1621 mwifiex_dbg(priv
->adapter
, INFO
, "%s: mac address %pM\n",
1622 __func__
, params
->mac
);
1624 eth_zero_addr(deauth_mac
);
1626 spin_lock_irqsave(&priv
->sta_list_spinlock
, flags
);
1627 sta_node
= mwifiex_get_sta_entry(priv
, params
->mac
);
1629 ether_addr_copy(deauth_mac
, params
->mac
);
1630 spin_unlock_irqrestore(&priv
->sta_list_spinlock
, flags
);
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,
1643 mwifiex_cfg80211_set_antenna(struct wiphy
*wiphy
, u32 tx_ant
, u32 rx_ant
)
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
;
1650 if (!tx_ant
|| !rx_ant
)
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
1657 if (tx_ant
!= rx_ant
)
1660 if ((tx_ant
& (tx_ant
- 1)) &&
1661 (tx_ant
!= BIT(adapter
->number_of_antenna
) - 1))
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
;
1670 struct ieee80211_sta_ht_cap
*ht_info
;
1672 enum ieee80211_band band
;
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
;
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
;
1686 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
1687 if (!adapter
->wiphy
->bands
[band
])
1690 ht_info
= &adapter
->wiphy
->bands
[band
]->ht_cap
;
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
);
1698 ant_cfg
.tx_ant
= tx_ant
;
1699 ant_cfg
.rx_ant
= rx_ant
;
1701 return mwifiex_send_cmd(priv
, HostCmd_CMD_RF_ANTENNA
,
1702 HostCmd_ACT_GEN_SET
, 0, &ant_cfg
, true);
1705 /* cfg80211 operation handler for stop ap.
1706 * Function stops BSS running at uAP interface.
1708 static int mwifiex_cfg80211_stop_ap(struct wiphy
*wiphy
, struct net_device
*dev
)
1710 struct mwifiex_private
*priv
= mwifiex_netdev_get_priv(dev
);
1712 mwifiex_abort_cac(priv
);
1714 if (mwifiex_del_mgmt_ies(priv
))
1715 mwifiex_dbg(priv
->adapter
, ERROR
,
1716 "Failed to delete mgmt IEs!\n");
1718 priv
->ap_11n_enabled
= 0;
1719 memset(&priv
->bss_cfg
, 0, sizeof(priv
->bss_cfg
));
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");
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.
1736 static int mwifiex_cfg80211_start_ap(struct wiphy
*wiphy
,
1737 struct net_device
*dev
,
1738 struct cfg80211_ap_settings
*params
)
1740 struct mwifiex_uap_bss_param
*bss_cfg
;
1741 struct mwifiex_private
*priv
= mwifiex_netdev_get_priv(dev
);
1743 if (GET_BSS_ROLE(priv
) != MWIFIEX_BSS_ROLE_UAP
)
1746 bss_cfg
= kzalloc(sizeof(struct mwifiex_uap_bss_param
), GFP_KERNEL
);
1750 mwifiex_set_sys_config_invalid_data(bss_cfg
);
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
;
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
;
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
;
1767 switch (params
->hidden_ssid
) {
1768 case NL80211_HIDDEN_SSID_NOT_IN_USE
:
1769 bss_cfg
->bcast_ssid_ctl
= 1;
1771 case NL80211_HIDDEN_SSID_ZERO_LEN
:
1772 bss_cfg
->bcast_ssid_ctl
= 0;
1774 case NL80211_HIDDEN_SSID_ZERO_CONTENTS
:
1775 /* firmware doesn't support this type of hidden SSID */
1781 mwifiex_uap_set_channel(bss_cfg
, params
->chandef
);
1782 mwifiex_set_uap_rates(bss_cfg
, params
);
1784 if (mwifiex_set_secure_params(priv
, bss_cfg
, params
)) {
1786 mwifiex_dbg(priv
->adapter
, ERROR
,
1787 "Failed to parse secuirty parameters!\n");
1791 mwifiex_set_ht_params(priv
, bss_cfg
, params
);
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
);
1799 if (priv
->ap_11ac_enabled
)
1800 mwifiex_set_11ac_ba_params(priv
);
1802 mwifiex_set_ba_params(priv
);
1804 mwifiex_set_wmm_params(priv
, bss_cfg
, params
);
1806 if (mwifiex_is_11h_active(priv
) &&
1807 !cfg80211_chandef_dfs_required(wiphy
, ¶ms
->chandef
,
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!!");
1816 priv
->state_11h
.is_11h_active
= true;
1819 if (mwifiex_config_start_uap(priv
, bss_cfg
)) {
1820 mwifiex_dbg(priv
->adapter
, ERROR
,
1821 "Failed to start AP\n");
1826 if (mwifiex_set_mgmt_ies(priv
, ¶ms
->beacon
))
1829 memcpy(&priv
->bss_cfg
, bss_cfg
, sizeof(priv
->bss_cfg
));
1835 * CFG802.11 operation handler for disconnection request.
1837 * This function does not work when there is already a disconnection
1838 * procedure going on.
1841 mwifiex_cfg80211_disconnect(struct wiphy
*wiphy
, struct net_device
*dev
,
1844 struct mwifiex_private
*priv
= mwifiex_netdev_get_priv(dev
);
1846 if (mwifiex_deauthenticate(priv
, NULL
))
1849 mwifiex_dbg(priv
->adapter
, MSG
,
1850 "info: successfully disconnected from %pM:\t"
1851 "reason code %d\n", priv
->cfg_bssid
, reason_code
);
1853 eth_zero_addr(priv
->cfg_bssid
);
1854 priv
->hs2_enabled
= false;
1860 * This function informs the CFG802.11 subsystem of a new IBSS.
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.
1870 static int mwifiex_cfg80211_inform_ibss_bss(struct mwifiex_private
*priv
)
1872 struct ieee80211_channel
*chan
;
1873 struct mwifiex_bss_info bss_info
;
1874 struct cfg80211_bss
*bss
;
1876 u8 ie_buf
[IEEE80211_MAX_SSID_LEN
+ sizeof(struct ieee_types_header
)];
1877 enum ieee80211_band band
;
1879 if (mwifiex_get_bss_info(priv
, &bss_info
))
1882 ie_buf
[0] = WLAN_EID_SSID
;
1883 ie_buf
[1] = bss_info
.ssid
.ssid_len
;
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
);
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
,
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
);
1905 * This function connects with a BSS.
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.
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.
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
)
1924 struct cfg80211_ssid req_ssid
;
1925 int ret
, auth_type
= 0;
1926 struct cfg80211_bss
*bss
= NULL
;
1927 u8 is_scanning_required
= 0;
1929 memset(&req_ssid
, 0, sizeof(struct cfg80211_ssid
));
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");
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");
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);
1952 if (mode
== NL80211_IFTYPE_ADHOC
) {
1953 /* "privacy" is set only for ad-hoc mode */
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.
1961 priv
->sec_info
.encryption_mode
=
1962 WLAN_CIPHER_SUITE_WEP104
;
1963 priv
->sec_info
.authentication_mode
=
1964 NL80211_AUTHTYPE_OPEN_SYSTEM
;
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;
1975 auth_type
= sme
->auth_type
;
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
;
1984 if (sme
->crypto
.cipher_group
) {
1985 priv
->sec_info
.encryption_mode
= sme
->crypto
.cipher_group
;
1986 priv
->sec_info
.authentication_mode
= auth_type
;
1989 ret
= mwifiex_set_gen_ie(priv
, sme
->ie
, sme
->ie_len
);
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
,
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.
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");
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
);
2024 bss
= cfg80211_get_bss(priv
->wdev
.wiphy
, channel
,
2025 bssid
, ssid
, ssid_len
,
2026 IEEE80211_BSS_TYPE_ESS
,
2027 IEEE80211_PRIVACY_ANY
);
2030 if (is_scanning_required
) {
2031 mwifiex_dbg(priv
->adapter
, WARN
,
2032 "assoc: requested bss not found in scan results\n");
2035 is_scanning_required
= 1;
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
);
2045 ret
= mwifiex_bss_start(priv
, bss
, &req_ssid
);
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
))
2060 * CFG802.11 operation handler for association request.
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.
2067 mwifiex_cfg80211_connect(struct wiphy
*wiphy
, struct net_device
*dev
,
2068 struct cfg80211_connect_params
*sme
)
2070 struct mwifiex_private
*priv
= mwifiex_netdev_get_priv(dev
);
2071 struct mwifiex_adapter
*adapter
= priv
->adapter
;
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",
2081 if (priv
->wdev
.current_bss
) {
2082 mwifiex_dbg(adapter
, ERROR
,
2083 "%s: already connected\n", dev
->name
);
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",
2095 mwifiex_dbg(adapter
, INFO
,
2096 "info: Trying to associate to %s and bssid %pM\n",
2097 (char *)sme
->ssid
, sme
->bssid
);
2099 ret
= mwifiex_cfg80211_assoc(priv
, sme
->ssid_len
, sme
->ssid
, sme
->bssid
,
2100 priv
->bss_mode
, sme
->channel
, sme
, 0);
2102 cfg80211_connect_result(priv
->netdev
, priv
->cfg_bssid
, NULL
, 0,
2103 NULL
, 0, WLAN_STATUS_SUCCESS
,
2105 mwifiex_dbg(priv
->adapter
, MSG
,
2106 "info: associated to bssid %pM successfully\n",
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
);
2113 mwifiex_dbg(priv
->adapter
, ERROR
,
2114 "info: association to bssid %pM failed\n",
2116 eth_zero_addr(priv
->cfg_bssid
);
2119 cfg80211_connect_result(priv
->netdev
, priv
->cfg_bssid
,
2120 NULL
, 0, NULL
, 0, ret
,
2123 cfg80211_connect_result(priv
->netdev
, priv
->cfg_bssid
,
2125 WLAN_STATUS_UNSPECIFIED_FAILURE
,
2133 * This function sets following parameters for ibss network.
2137 * - secondary channel offset
2139 static int mwifiex_set_ibss_params(struct mwifiex_private
*priv
,
2140 struct cfg80211_ibss_params
*params
)
2142 struct mwifiex_adapter
*adapter
= priv
->adapter
;
2144 u8 config_bands
= 0;
2146 if (params
->chandef
.chan
->band
== IEEE80211_BAND_2GHZ
) {
2147 if (!params
->basic_rates
) {
2148 config_bands
= BAND_B
| BAND_G
;
2150 for (i
= 0; i
< mwifiex_band_2ghz
.n_bitrates
; i
++) {
2152 * Rates below 6 Mbps in the table are CCK
2153 * rates; 802.11b and from 6 they are OFDM;
2156 if (mwifiex_rates
[i
].bitrate
== 60) {
2162 if (params
->basic_rates
< index
) {
2163 config_bands
= BAND_B
;
2165 config_bands
= BAND_G
;
2166 if (params
->basic_rates
% index
)
2167 config_bands
|= BAND_B
;
2171 if (cfg80211_get_chandef_type(¶ms
->chandef
) !=
2173 config_bands
|= BAND_G
| BAND_GN
;
2175 if (cfg80211_get_chandef_type(¶ms
->chandef
) ==
2177 config_bands
= BAND_A
;
2179 config_bands
= BAND_AN
| BAND_A
;
2182 if (!((config_bands
| adapter
->fw_bands
) & ~adapter
->fw_bands
)) {
2183 adapter
->config_bands
= config_bands
;
2184 adapter
->adhoc_start_band
= config_bands
;
2186 if ((config_bands
& BAND_GN
) || (config_bands
& BAND_AN
))
2187 adapter
->adhoc_11n_enabled
= true;
2189 adapter
->adhoc_11n_enabled
= false;
2192 adapter
->sec_chan_offset
=
2193 mwifiex_chan_type_to_sec_chan_offset(
2194 cfg80211_get_chandef_type(¶ms
->chandef
));
2195 priv
->adhoc_channel
= ieee80211_frequency_to_channel(
2196 params
->chandef
.chan
->center_freq
);
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
);
2207 * CFG802.11 operation handler to join an IBSS.
2209 * This function does not work in any mode other than Ad-Hoc, or if
2210 * a join operation is already in progress.
2213 mwifiex_cfg80211_join_ibss(struct wiphy
*wiphy
, struct net_device
*dev
,
2214 struct cfg80211_ibss_params
*params
)
2216 struct mwifiex_private
*priv
= mwifiex_netdev_get_priv(dev
);
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");
2226 mwifiex_dbg(priv
->adapter
, MSG
,
2227 "info: trying to join to %s and bssid %pM\n",
2228 (char *)params
->ssid
, params
->bssid
);
2230 mwifiex_set_ibss_params(priv
, params
);
2232 ret
= mwifiex_cfg80211_assoc(priv
, params
->ssid_len
, params
->ssid
,
2233 params
->bssid
, priv
->bss_mode
,
2234 params
->chandef
.chan
, NULL
,
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
);
2244 mwifiex_dbg(priv
->adapter
, ERROR
,
2245 "info: failed creating/joining adhoc network\n");
2252 * CFG802.11 operation handler to leave an IBSS.
2254 * This function does not work if a leave operation is
2255 * already in progress.
2258 mwifiex_cfg80211_leave_ibss(struct wiphy
*wiphy
, struct net_device
*dev
)
2260 struct mwifiex_private
*priv
= mwifiex_netdev_get_priv(dev
);
2262 mwifiex_dbg(priv
->adapter
, MSG
, "info: disconnecting from essid %pM\n",
2264 if (mwifiex_deauthenticate(priv
, NULL
))
2267 eth_zero_addr(priv
->cfg_bssid
);
2273 * CFG802.11 operation handler for scan request.
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.
2280 mwifiex_cfg80211_scan(struct wiphy
*wiphy
,
2281 struct cfg80211_scan_request
*request
)
2283 struct net_device
*dev
= request
->wdev
->netdev
;
2284 struct mwifiex_private
*priv
= mwifiex_netdev_get_priv(dev
);
2286 struct ieee80211_channel
*chan
;
2287 struct ieee_types_header
*ie
;
2288 struct mwifiex_user_scan_cfg
*user_scan_cfg
;
2290 mwifiex_dbg(priv
->adapter
, CMD
,
2291 "info: received scan request on %s\n", dev
->name
);
2293 /* Block scan request if scan operation or scan cleanup when interface
2294 * is disabled is in process
2296 if (priv
->scan_request
|| priv
->scan_aborting
) {
2297 mwifiex_dbg(priv
->adapter
, WARN
,
2298 "cmd: Scan already in process..\n");
2302 user_scan_cfg
= kzalloc(sizeof(*user_scan_cfg
), GFP_KERNEL
);
2306 priv
->scan_request
= request
;
2308 user_scan_cfg
->num_ssids
= request
->n_ssids
;
2309 user_scan_cfg
->ssid_list
= request
->ssids
;
2311 if (request
->ie
&& request
->ie_len
) {
2313 for (i
= 0; i
< MWIFIEX_MAX_VSIE_NUM
; i
++) {
2314 if (priv
->vs_ie
[i
].mask
!= MWIFIEX_VSIE_MASK_CLEAR
)
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
;
2321 if (offset
>= request
->ie_len
)
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
;
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
;
2336 user_scan_cfg
->chan_list
[i
].scan_type
=
2337 MWIFIEX_SCAN_TYPE_ACTIVE
;
2339 user_scan_cfg
->chan_list
[i
].scan_time
= 0;
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
;
2347 ret
= mwifiex_scan_networks(priv
, user_scan_cfg
);
2348 kfree(user_scan_cfg
);
2350 mwifiex_dbg(priv
->adapter
, ERROR
,
2351 "scan failed: %d\n", ret
);
2352 priv
->scan_aborting
= false;
2353 priv
->scan_request
= NULL
;
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
);
2369 static void mwifiex_setup_vht_caps(struct ieee80211_sta_vht_cap
*vht_info
,
2370 struct mwifiex_private
*priv
)
2372 struct mwifiex_adapter
*adapter
= priv
->adapter
;
2374 vht_info
->vht_supported
= true;
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;
2387 * This function sets up the CFG802.11 specific HT capability fields
2388 * with default values.
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)
2399 mwifiex_setup_ht_caps(struct ieee80211_sta_ht_cap
*ht_info
,
2400 struct mwifiex_private
*priv
)
2403 struct ieee80211_mcs_info mcs_set
;
2404 u8
*mcs
= (u8
*)&mcs_set
;
2405 struct mwifiex_adapter
*adapter
= priv
->adapter
;
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
;
2411 memset(&ht_info
->mcs
, 0, sizeof(ht_info
->mcs
));
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
;
2417 ht_info
->cap
&= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40
;
2419 if (ISSUPP_SHORTGI20(adapter
->hw_dot_11n_dev_cap
))
2420 ht_info
->cap
|= IEEE80211_HT_CAP_SGI_20
;
2422 ht_info
->cap
&= ~IEEE80211_HT_CAP_SGI_20
;
2424 if (ISSUPP_SHORTGI40(adapter
->hw_dot_11n_dev_cap
))
2425 ht_info
->cap
|= IEEE80211_HT_CAP_SGI_40
;
2427 ht_info
->cap
&= ~IEEE80211_HT_CAP_SGI_40
;
2429 if (adapter
->user_dev_mcs_support
== HT_STREAM_2X2
)
2430 ht_info
->cap
|= 3 << IEEE80211_HT_CAP_RX_STBC_SHIFT
;
2432 ht_info
->cap
|= 1 << IEEE80211_HT_CAP_RX_STBC_SHIFT
;
2434 if (ISSUPP_TXSTBC(adapter
->hw_dot_11n_dev_cap
))
2435 ht_info
->cap
|= IEEE80211_HT_CAP_TX_STBC
;
2437 ht_info
->cap
&= ~IEEE80211_HT_CAP_TX_STBC
;
2439 if (ISSUPP_GREENFIELD(adapter
->hw_dot_11n_dev_cap
))
2440 ht_info
->cap
|= IEEE80211_HT_CAP_GRN_FLD
;
2442 ht_info
->cap
&= ~IEEE80211_HT_CAP_GRN_FLD
;
2444 if (ISENABLED_40MHZ_INTOLERANT(adapter
->hw_dot_11n_dev_cap
))
2445 ht_info
->cap
|= IEEE80211_HT_CAP_40MHZ_INTOLERANT
;
2447 ht_info
->cap
&= ~IEEE80211_HT_CAP_40MHZ_INTOLERANT
;
2449 if (ISSUPP_RXLDPC(adapter
->hw_dot_11n_dev_cap
))
2450 ht_info
->cap
|= IEEE80211_HT_CAP_LDPC_CODING
;
2452 ht_info
->cap
&= ~IEEE80211_HT_CAP_LDPC_CODING
;
2454 ht_info
->cap
&= ~IEEE80211_HT_CAP_MAX_AMSDU
;
2455 ht_info
->cap
|= IEEE80211_HT_CAP_SM_PS
;
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
);
2468 memcpy((u8
*) &ht_info
->mcs
, mcs
, sizeof(struct ieee80211_mcs_info
));
2470 ht_info
->mcs
.tx_params
= IEEE80211_HT_MCS_TX_DEFINED
;
2474 * create a new virtual interface with the given name and name assign type
2476 struct wireless_dev
*mwifiex_add_virtual_intf(struct wiphy
*wiphy
,
2478 unsigned char name_assign_type
,
2479 enum nl80211_iftype type
,
2481 struct vif_params
*params
)
2483 struct mwifiex_adapter
*adapter
= mwifiex_cfg80211_get_adapter(wiphy
);
2484 struct mwifiex_private
*priv
;
2485 struct net_device
*dev
;
2489 return ERR_PTR(-EFAULT
);
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
);
2502 priv
= mwifiex_get_unused_priv(adapter
);
2504 mwifiex_dbg(adapter
, ERROR
,
2505 "could not get free private struct\n");
2506 return ERR_PTR(-EFAULT
);
2509 priv
->wdev
.wiphy
= wiphy
;
2510 priv
->wdev
.iftype
= NL80211_IFTYPE_STATION
;
2512 if (type
== NL80211_IFTYPE_UNSPECIFIED
)
2513 priv
->bss_mode
= NL80211_IFTYPE_STATION
;
2515 priv
->bss_mode
= type
;
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
;
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
);
2532 priv
= mwifiex_get_unused_priv(adapter
);
2534 mwifiex_dbg(adapter
, ERROR
,
2535 "could not get free private struct\n");
2536 return ERR_PTR(-EFAULT
);
2539 priv
->wdev
.wiphy
= wiphy
;
2540 priv
->wdev
.iftype
= NL80211_IFTYPE_AP
;
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
;
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
);
2559 priv
= mwifiex_get_unused_priv(adapter
);
2561 mwifiex_dbg(adapter
, ERROR
,
2562 "could not get free private struct\n");
2563 return ERR_PTR(-EFAULT
);
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.
2570 priv
->wdev
.iftype
= NL80211_IFTYPE_P2P_CLIENT
;
2571 priv
->bss_mode
= NL80211_IFTYPE_P2P_CLIENT
;
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.
2577 priv
->bss_type
= MWIFIEX_BSS_TYPE_P2P
;
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
;
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
);
2593 mwifiex_dbg(adapter
, ERROR
, "type not supported\n");
2594 return ERR_PTR(-EINVAL
);
2597 dev
= alloc_netdev_mqs(sizeof(struct mwifiex_private
*), name
,
2598 name_assign_type
, ether_setup
,
2599 IEEE80211_NUM_ACS
, 1);
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
);
2609 mwifiex_init_priv_params(priv
, dev
);
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
);
2617 if (adapter
->config_bands
& BAND_A
)
2618 mwifiex_setup_ht_caps(
2619 &wiphy
->bands
[IEEE80211_BAND_5GHZ
]->ht_cap
, priv
);
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
);
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
));
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
;
2636 mdev_priv
= netdev_priv(dev
);
2637 *((unsigned long *) mdev_priv
) = (unsigned long) priv
;
2639 SET_NETDEV_DEV(dev
, adapter
->dev
);
2641 /* Register network device */
2642 if (register_netdevice(dev
)) {
2643 mwifiex_dbg(adapter
, ERROR
,
2644 "cannot register virtual network device\n");
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
);
2653 priv
->dfs_cac_workqueue
= alloc_workqueue("MWIFIEX_DFS_CAC%s",
2656 WQ_UNBOUND
, 1, name
);
2657 if (!priv
->dfs_cac_workqueue
) {
2658 mwifiex_dbg(adapter
, ERROR
,
2659 "cannot register virtual network device\n");
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
);
2668 INIT_DELAYED_WORK(&priv
->dfs_cac_work
, mwifiex_dfs_cac_work_queue
);
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");
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
);
2684 INIT_DELAYED_WORK(&priv
->dfs_chan_sw_work
,
2685 mwifiex_dfs_chan_sw_work_queue
);
2687 sema_init(&priv
->async_sem
, 1);
2689 mwifiex_dbg(adapter
, INFO
,
2690 "info: %s: Marvell 802.11 Adapter\n", dev
->name
);
2692 #ifdef CONFIG_DEBUG_FS
2693 mwifiex_dev_debugfs_init(priv
);
2697 case NL80211_IFTYPE_UNSPECIFIED
:
2698 case NL80211_IFTYPE_STATION
:
2699 case NL80211_IFTYPE_ADHOC
:
2700 adapter
->curr_iface_comb
.sta_intf
++;
2702 case NL80211_IFTYPE_AP
:
2703 adapter
->curr_iface_comb
.uap_intf
++;
2705 case NL80211_IFTYPE_P2P_CLIENT
:
2706 adapter
->curr_iface_comb
.p2p_intf
++;
2709 mwifiex_dbg(adapter
, ERROR
, "type not supported\n");
2710 return ERR_PTR(-EINVAL
);
2715 EXPORT_SYMBOL_GPL(mwifiex_add_virtual_intf
);
2718 * del_virtual_intf: remove the virtual interface determined by dev
2720 int mwifiex_del_virtual_intf(struct wiphy
*wiphy
, struct wireless_dev
*wdev
)
2722 struct mwifiex_private
*priv
= mwifiex_netdev_get_priv(wdev
->netdev
);
2723 struct mwifiex_adapter
*adapter
= priv
->adapter
;
2725 #ifdef CONFIG_DEBUG_FS
2726 mwifiex_dev_debugfs_remove(priv
);
2729 mwifiex_stop_net_dev_queue(priv
->netdev
, adapter
);
2731 if (netif_carrier_ok(priv
->netdev
))
2732 netif_carrier_off(priv
->netdev
);
2734 if (wdev
->netdev
->reg_state
== NETREG_REGISTERED
)
2735 unregister_netdevice(wdev
->netdev
);
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
;
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
;
2748 /* Clear the priv in adapter */
2749 priv
->netdev
->ieee80211_ptr
= NULL
;
2750 priv
->netdev
= NULL
;
2751 priv
->wdev
.iftype
= NL80211_IFTYPE_UNSPECIFIED
;
2753 priv
->media_connected
= false;
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
++;
2761 case NL80211_IFTYPE_AP
:
2762 adapter
->curr_iface_comb
.uap_intf
++;
2764 case NL80211_IFTYPE_P2P_CLIENT
:
2765 case NL80211_IFTYPE_P2P_GO
:
2766 adapter
->curr_iface_comb
.p2p_intf
++;
2769 mwifiex_dbg(adapter
, ERROR
,
2770 "del_virtual_intf: type not supported\n");
2774 priv
->bss_mode
= NL80211_IFTYPE_UNSPECIFIED
;
2776 if (GET_BSS_ROLE(priv
) == MWIFIEX_BSS_ROLE_STA
||
2777 GET_BSS_ROLE(priv
) == MWIFIEX_BSS_ROLE_UAP
)
2778 kfree(priv
->hist_data
);
2782 EXPORT_SYMBOL_GPL(mwifiex_del_virtual_intf
);
2785 mwifiex_is_pattern_supported(struct cfg80211_pkt_pattern
*pat
, s8
*byte_seq
,
2788 int j
, k
, valid_byte_cnt
= 0;
2789 bool dont_care_byte
= false;
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);
2801 dont_care_byte
= true;
2804 if (valid_byte_cnt
> max_byte_seq
)
2809 byte_seq
[max_byte_seq
] = valid_byte_cnt
;
2815 static void mwifiex_set_auto_arp_mef_entry(struct mwifiex_private
*priv
,
2816 struct mwifiex_mef_entry
*mef_entry
)
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
;
2824 mef_entry
->mode
= MEF_MODE_HOST_SLEEP
;
2825 mef_entry
->action
= MEF_ACTION_AUTO_ARP
;
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
);
2834 ifa
= in_dev
->ifa_list
;
2835 if (!ifa
|| !ifa
->ifa_local
)
2837 ips
[i
] = ifa
->ifa_local
;
2842 for (i
= 0; i
< num_ipv4
; i
++) {
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
] =
2851 mef_entry
->filter
[filt_num
].offset
= 46;
2852 mef_entry
->filter
[filt_num
].filt_type
= TYPE_EQ
;
2854 mef_entry
->filter
[filt_num
].filt_action
=
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
;
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
)
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};
2880 mef_entry
->mode
= MEF_MODE_HOST_SLEEP
;
2881 mef_entry
->action
= MEF_ACTION_ALLOW_AND_WAKEUP_HOST
;
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
],
2887 MWIFIEX_MEF_MAX_BYTESEQ
)) {
2888 mwifiex_dbg(priv
->adapter
, ERROR
,
2889 "Pattern not supported\n");
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
;
2899 } else if (is_broadcast_ether_addr(byte_seq
)) {
2900 mef_cfg
->criteria
|= MWIFIEX_CRITERIA_BROADCAST
;
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
;
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
,
2915 mef_entry
->filter
[filt_num
].filt_type
= TYPE_EQ
;
2920 mef_entry
->filter
[filt_num
].filt_action
= TYPE_AND
;
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
,
2930 mef_entry
->filter
[filt_num
].byte_seq
[MWIFIEX_MEF_MAX_BYTESEQ
] =
2932 mef_entry
->filter
[filt_num
].offset
= 28;
2933 mef_entry
->filter
[filt_num
].filt_type
= TYPE_EQ
;
2935 mef_entry
->filter
[filt_num
].filt_action
= TYPE_OR
;
2938 mef_entry
->filter
[filt_num
].repeat
= 16;
2939 memcpy(mef_entry
->filter
[filt_num
].byte_seq
, priv
->curr_addr
,
2941 mef_entry
->filter
[filt_num
].byte_seq
[MWIFIEX_MEF_MAX_BYTESEQ
] =
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
;
2950 static int mwifiex_set_mef_filter(struct mwifiex_private
*priv
,
2951 struct cfg80211_wowlan
*wowlan
)
2953 int ret
= 0, num_entries
= 1;
2954 struct mwifiex_ds_mef_cfg mef_cfg
;
2955 struct mwifiex_mef_entry
*mef_entry
;
2957 if (wowlan
->n_patterns
|| wowlan
->magic_pkt
)
2960 mef_entry
= kcalloc(num_entries
, sizeof(*mef_entry
), GFP_KERNEL
);
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
;
2970 mwifiex_set_auto_arp_mef_entry(priv
, &mef_entry
[0]);
2972 if (wowlan
->n_patterns
|| wowlan
->magic_pkt
)
2973 ret
= mwifiex_set_wowlan_mef_entry(priv
, &mef_cfg
,
2974 &mef_entry
[1], wowlan
);
2976 if (!mef_cfg
.criteria
)
2977 mef_cfg
.criteria
= MWIFIEX_CRITERIA_BROADCAST
|
2978 MWIFIEX_CRITERIA_UNICAST
|
2979 MWIFIEX_CRITERIA_MULTICAST
;
2981 ret
= mwifiex_send_cmd(priv
, HostCmd_CMD_MEF_CFG
,
2982 HostCmd_ACT_GEN_SET
, 0,
2988 static int mwifiex_cfg80211_suspend(struct wiphy
*wiphy
,
2989 struct cfg80211_wowlan
*wowlan
)
2991 struct mwifiex_adapter
*adapter
= mwifiex_cfg80211_get_adapter(wiphy
);
2992 struct mwifiex_ds_hs_cfg hs_cfg
;
2994 struct mwifiex_private
*priv
;
2996 for (i
= 0; i
< adapter
->priv_num
; i
++) {
2997 priv
= adapter
->priv
[i
];
2998 mwifiex_abort_cac(priv
);
3001 mwifiex_cancel_all_pending_cmd(adapter
);
3004 mwifiex_dbg(adapter
, ERROR
,
3005 "None of the WOWLAN triggers enabled\n");
3009 priv
= mwifiex_get_priv(adapter
, MWIFIEX_BSS_ROLE_STA
);
3011 if (!priv
->media_connected
) {
3012 mwifiex_dbg(adapter
, ERROR
,
3013 "Can not configure WOWLAN in disconnected state\n");
3017 ret
= mwifiex_set_mef_filter(priv
, wowlan
);
3019 mwifiex_dbg(adapter
, ERROR
, "Failed to set MEF filter\n");
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
);
3032 mwifiex_dbg(adapter
, ERROR
,
3033 "Failed to set HS params\n");
3041 static int mwifiex_cfg80211_resume(struct wiphy
*wiphy
)
3046 static void mwifiex_cfg80211_set_wakeup(struct wiphy
*wiphy
,
3049 struct mwifiex_adapter
*adapter
= mwifiex_cfg80211_get_adapter(wiphy
);
3051 device_set_wakeup_enable(adapter
->dev
, enabled
);
3055 static int mwifiex_get_coalesce_pkt_type(u8
*byte_seq
)
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};
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
;
3076 mwifiex_fill_coalesce_rule_info(struct mwifiex_private
*priv
,
3077 struct cfg80211_coalesce_rules
*crule
,
3078 struct mwifiex_coalesce_rule
*mrule
)
3080 u8 byte_seq
[MWIFIEX_COALESCE_MAX_BYTESEQ
+ 1];
3081 struct filt_field_param
*param
;
3084 mrule
->max_coalescing_delay
= crule
->delay
;
3086 param
= mrule
->params
;
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
],
3092 MWIFIEX_COALESCE_MAX_BYTESEQ
)) {
3093 mwifiex_dbg(priv
->adapter
, ERROR
,
3094 "Pattern not supported\n");
3098 if (!crule
->patterns
[i
].pkt_offset
) {
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");
3106 } else if (pkt_type
) {
3107 mrule
->pkt_type
= pkt_type
;
3112 if (crule
->condition
== NL80211_COALESCE_CONDITION_MATCH
)
3113 param
->operation
= RECV_FILTER_MATCH_TYPE_EQ
;
3115 param
->operation
= RECV_FILTER_MATCH_TYPE_NE
;
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
;
3123 mrule
->num_of_fields
++;
3126 if (!mrule
->pkt_type
) {
3127 mwifiex_dbg(priv
->adapter
, ERROR
,
3128 "Packet type can not be determined\n");
3135 static int mwifiex_cfg80211_set_coalesce(struct wiphy
*wiphy
,
3136 struct cfg80211_coalesce
*coalesce
)
3138 struct mwifiex_adapter
*adapter
= mwifiex_cfg80211_get_adapter(wiphy
);
3140 struct mwifiex_ds_coalesce_cfg coalesce_cfg
;
3141 struct mwifiex_private
*priv
=
3142 mwifiex_get_priv(adapter
, MWIFIEX_BSS_ROLE_STA
);
3144 memset(&coalesce_cfg
, 0, sizeof(coalesce_cfg
));
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);
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
]);
3158 mwifiex_dbg(adapter
, ERROR
,
3159 "Recheck the patterns provided for rule %d\n",
3165 return mwifiex_send_cmd(priv
, HostCmd_CMD_COALESCE_CFG
,
3166 HostCmd_ACT_GEN_SET
, 0, &coalesce_cfg
, true);
3169 /* cfg80211 ops handler for tdls_mgmt.
3170 * Function prepares TDLS action frame packets and forwards them to FW
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
)
3179 struct mwifiex_private
*priv
= mwifiex_netdev_get_priv(dev
);
3182 if (!(wiphy
->flags
& WIPHY_FLAG_SUPPORTS_TDLS
))
3185 /* make sure we are in station mode and connected */
3186 if (!(priv
->bss_type
== MWIFIEX_BSS_TYPE_STA
&& priv
->media_connected
))
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",
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
);
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",
3204 ret
= mwifiex_send_tdls_data_frame(priv
, peer
, action_code
,
3205 dialog_token
, status_code
,
3206 extra_ies
, extra_ies_len
);
3208 case WLAN_TDLS_SETUP_CONFIRM
:
3209 mwifiex_dbg(priv
->adapter
, MSG
,
3210 "Send TDLS Confirm to %pM status_code=%d\n", peer
,
3212 ret
= mwifiex_send_tdls_data_frame(priv
, peer
, action_code
,
3213 dialog_token
, status_code
,
3214 extra_ies
, extra_ies_len
);
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
);
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
);
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
);
3238 mwifiex_dbg(priv
->adapter
, ERROR
,
3239 "Unknown TDLS mgmt/action frame %pM\n", peer
);
3248 mwifiex_cfg80211_tdls_oper(struct wiphy
*wiphy
, struct net_device
*dev
,
3249 const u8
*peer
, enum nl80211_tdls_operation action
)
3251 struct mwifiex_private
*priv
= mwifiex_netdev_get_priv(dev
);
3253 if (!(wiphy
->flags
& WIPHY_FLAG_SUPPORTS_TDLS
) ||
3254 !(wiphy
->flags
& WIPHY_FLAG_TDLS_EXTERNAL_SETUP
))
3257 /* make sure we are in station mode and connected */
3258 if (!(priv
->bss_type
== MWIFIEX_BSS_TYPE_STA
&& priv
->media_connected
))
3261 mwifiex_dbg(priv
->adapter
, MSG
,
3262 "TDLS peer=%pM, oper=%d\n", peer
, action
);
3265 case NL80211_TDLS_ENABLE_LINK
:
3266 action
= MWIFIEX_TDLS_ENABLE_LINK
;
3268 case NL80211_TDLS_DISABLE_LINK
:
3269 action
= MWIFIEX_TDLS_DISABLE_LINK
;
3271 case NL80211_TDLS_TEARDOWN
:
3272 /* shouldn't happen!*/
3273 mwifiex_dbg(priv
->adapter
, ERROR
,
3274 "tdls_oper: teardown from driver not supported\n");
3276 case NL80211_TDLS_SETUP
:
3277 /* shouldn't happen!*/
3278 mwifiex_dbg(priv
->adapter
, ERROR
,
3279 "tdls_oper: setup from driver not supported\n");
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");
3287 mwifiex_dbg(priv
->adapter
, ERROR
,
3288 "tdls_oper: operation not supported\n");
3292 return mwifiex_tdls_oper(priv
, peer
, action
);
3296 mwifiex_cfg80211_add_station(struct wiphy
*wiphy
, struct net_device
*dev
,
3297 const u8
*mac
, struct station_parameters
*params
)
3299 struct mwifiex_private
*priv
= mwifiex_netdev_get_priv(dev
);
3301 if (!(params
->sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
)))
3304 /* make sure we are in station mode and connected */
3305 if ((priv
->bss_type
!= MWIFIEX_BSS_TYPE_STA
) || !priv
->media_connected
)
3308 return mwifiex_tdls_oper(priv
, mac
, MWIFIEX_TDLS_CREATE_LINK
);
3312 mwifiex_cfg80211_channel_switch(struct wiphy
*wiphy
, struct net_device
*dev
,
3313 struct cfg80211_csa_settings
*params
)
3315 struct ieee_types_header
*chsw_ie
;
3316 struct ieee80211_channel_sw_ie
*channel_sw
;
3318 struct mwifiex_private
*priv
= mwifiex_netdev_get_priv(dev
);
3320 if (priv
->adapter
->scan_processing
) {
3321 mwifiex_dbg(priv
->adapter
, ERROR
,
3322 "radar detection: scan in process...\n");
3326 if (priv
->wdev
.cac_started
)
3329 if (cfg80211_chandef_identical(¶ms
->chandef
,
3330 &priv
->dfs_chandef
))
3333 chsw_ie
= (void *)cfg80211_find_ie(WLAN_EID_CHANNEL_SWITCH
,
3334 params
->beacon_csa
.tail
,
3335 params
->beacon_csa
.tail_len
);
3337 mwifiex_dbg(priv
->adapter
, ERROR
,
3338 "Could not parse channel switch announcement IE\n");
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
);
3349 if (mwifiex_del_mgmt_ies(priv
))
3350 mwifiex_dbg(priv
->adapter
, ERROR
,
3351 "Failed to delete mgmt IEs!\n");
3353 if (mwifiex_set_mgmt_ies(priv
, ¶ms
->beacon_csa
)) {
3354 mwifiex_dbg(priv
->adapter
, ERROR
,
3355 "%s: setting mgmt ies failed\n", __func__
);
3359 memcpy(&priv
->dfs_chandef
, ¶ms
->chandef
, sizeof(priv
->dfs_chandef
));
3360 memcpy(&priv
->beacon_after
, ¶ms
->beacon_after
,
3361 sizeof(priv
->beacon_after
));
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
));
3370 mwifiex_cfg80211_start_radar_detection(struct wiphy
*wiphy
,
3371 struct net_device
*dev
,
3372 struct cfg80211_chan_def
*chandef
,
3375 struct mwifiex_private
*priv
= mwifiex_netdev_get_priv(dev
);
3376 struct mwifiex_radar_params radar_params
;
3378 if (priv
->adapter
->scan_processing
) {
3379 mwifiex_dbg(priv
->adapter
, ERROR
,
3380 "radar detection: scan already in process...\n");
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!!");
3392 priv
->state_11h
.is_11h_active
= true;
3395 memset(&radar_params
, 0, sizeof(struct mwifiex_radar_params
));
3396 radar_params
.chandef
= chandef
;
3397 radar_params
.cac_time_ms
= cac_time_ms
;
3399 memcpy(&priv
->dfs_chandef
, chandef
, sizeof(priv
->dfs_chandef
));
3401 if (mwifiex_send_cmd(priv
, HostCmd_CMD_CHAN_REPORT_REQUEST
,
3402 HostCmd_ACT_GEN_SET
, 0, &radar_params
, true))
3405 queue_delayed_work(priv
->dfs_cac_workqueue
, &priv
->dfs_cac_work
,
3406 msecs_to_jiffies(cac_time_ms
));
3411 mwifiex_cfg80211_change_station(struct wiphy
*wiphy
, struct net_device
*dev
,
3413 struct station_parameters
*params
)
3416 struct mwifiex_private
*priv
= mwifiex_netdev_get_priv(dev
);
3418 /* we support change_station handler only for TDLS peers*/
3419 if (!(params
->sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
)))
3422 /* make sure we are in station mode and connected */
3423 if ((priv
->bss_type
!= MWIFIEX_BSS_TYPE_STA
) || !priv
->media_connected
)
3426 priv
->sta_params
= params
;
3428 ret
= mwifiex_tdls_oper(priv
, mac
, MWIFIEX_TDLS_CONFIG_LINK
);
3429 priv
->sta_params
= NULL
;
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
,
3465 .suspend
= mwifiex_cfg80211_suspend
,
3466 .resume
= mwifiex_cfg80211_resume
,
3467 .set_wakeup
= mwifiex_cfg80211_set_wakeup
,
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
,
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
,
3488 static bool mwifiex_is_valid_alpha2(const char *alpha2
)
3490 if (!alpha2
|| strlen(alpha2
) != 2)
3493 if (isalpha(alpha2
[0]) && isalpha(alpha2
[1]))
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
,
3508 int mwifiex_init_channel_scan_gap(struct mwifiex_adapter
*adapter
)
3510 u32 n_channels_bg
, n_channels_a
= 0;
3512 n_channels_bg
= mwifiex_band_2ghz
.n_channels
;
3514 if (adapter
->config_bands
& BAND_A
)
3515 n_channels_a
= mwifiex_band_5ghz
.n_channels
;
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
);
3521 if (!adapter
->chan_stats
)
3528 * This function registers the device with CFG802.11 subsystem.
3530 * The function creates the wireless device/wiphy, populates it with
3531 * default parameters and handler function pointers, and finally
3532 * registers the device.
3535 int mwifiex_register_cfg80211(struct mwifiex_adapter
*adapter
)
3539 struct wiphy
*wiphy
;
3540 struct mwifiex_private
*priv
= adapter
->priv
[MWIFIEX_BSS_TYPE_STA
];
3544 /* create a new wiphy for use with cfg80211 */
3545 wiphy
= wiphy_new(&mwifiex_cfg80211_ops
,
3546 sizeof(struct mwifiex_adapter
*));
3548 mwifiex_dbg(adapter
, ERROR
,
3549 "%s: creating new wiphy\n", __func__
);
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
);
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
;
3566 wiphy
->bands
[IEEE80211_BAND_5GHZ
] = NULL
;
3568 wiphy
->iface_combinations
= &mwifiex_iface_comb_ap_sta
;
3569 wiphy
->n_iface_combinations
= 1;
3571 /* Initialize cipher suits */
3572 wiphy
->cipher_suites
= mwifiex_cipher_suites
;
3573 wiphy
->n_cipher_suites
= ARRAY_SIZE(mwifiex_cipher_suites
);
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
;
3583 if (ISSUPP_TDLS_ENABLED(adapter
->fw_cap_info
))
3584 wiphy
->flags
|= WIPHY_FLAG_SUPPORTS_TDLS
|
3585 WIPHY_FLAG_TDLS_EXTERNAL_SETUP
;
3588 wiphy
->wowlan
= &mwifiex_wowlan_support
;
3591 wiphy
->coalesce
= &mwifiex_coalesce_support
;
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
;
3597 wiphy
->available_antennas_tx
= BIT(adapter
->number_of_antenna
) - 1;
3598 wiphy
->available_antennas_rx
= BIT(adapter
->number_of_antenna
) - 1;
3600 wiphy
->features
|= NL80211_FEATURE_HT_IBSS
|
3601 NL80211_FEATURE_INACTIVITY_TIMER
|
3602 NL80211_FEATURE_NEED_OBSS_SCAN
;
3604 if (adapter
->fw_api_ver
== MWIFIEX_FW_V15
)
3605 wiphy
->features
|= NL80211_FEATURE_SK_TX_STATUS
;
3607 /* Reserve space for mwifiex specific private data for BSS */
3608 wiphy
->bss_priv_size
= sizeof(struct mwifiex_bss_priv
);
3610 wiphy
->reg_notifier
= mwifiex_reg_notifier
;
3612 /* Set struct mwifiex_adapter pointer in wiphy_priv */
3613 wdev_priv
= wiphy_priv(wiphy
);
3614 *(unsigned long *)wdev_priv
= (unsigned long)adapter
;
3616 set_wiphy_dev(wiphy
, priv
->adapter
->dev
);
3618 ret
= wiphy_register(wiphy
);
3620 mwifiex_dbg(adapter
, ERROR
,
3621 "%s: wiphy_register failed: %d\n", __func__
, ret
);
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
);
3631 country_code
= mwifiex_11d_code_2_region(adapter
->region_code
);
3633 mwifiex_dbg(adapter
, WARN
,
3634 "ignoring F/W country code %2.2s\n",
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
;
3651 adapter
->wiphy
= wiphy
;