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