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