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