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