]>
Commit | Line | Data |
---|---|---|
5e6e3a92 BZ |
1 | /* |
2 | * Marvell Wireless LAN device driver: CFG80211 | |
3 | * | |
4 | * Copyright (C) 2011, Marvell International Ltd. | |
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" | |
22 | ||
23 | /* | |
24 | * This function maps the nl802.11 channel type into driver channel type. | |
25 | * | |
26 | * The mapping is as follows - | |
27 | * NL80211_CHAN_NO_HT -> NO_SEC_CHANNEL | |
28 | * NL80211_CHAN_HT20 -> NO_SEC_CHANNEL | |
29 | * NL80211_CHAN_HT40PLUS -> SEC_CHANNEL_ABOVE | |
30 | * NL80211_CHAN_HT40MINUS -> SEC_CHANNEL_BELOW | |
31 | * Others -> NO_SEC_CHANNEL | |
32 | */ | |
33 | static int | |
34 | mwifiex_cfg80211_channel_type_to_mwifiex_channels(enum nl80211_channel_type | |
35 | channel_type) | |
36 | { | |
5e6e3a92 BZ |
37 | switch (channel_type) { |
38 | case NL80211_CHAN_NO_HT: | |
39 | case NL80211_CHAN_HT20: | |
636c4598 | 40 | return NO_SEC_CHANNEL; |
5e6e3a92 | 41 | case NL80211_CHAN_HT40PLUS: |
636c4598 | 42 | return SEC_CHANNEL_ABOVE; |
5e6e3a92 | 43 | case NL80211_CHAN_HT40MINUS: |
636c4598 | 44 | return SEC_CHANNEL_BELOW; |
5e6e3a92 | 45 | default: |
636c4598 | 46 | return NO_SEC_CHANNEL; |
5e6e3a92 | 47 | } |
5e6e3a92 BZ |
48 | } |
49 | ||
50 | /* | |
51 | * This function maps the driver channel type into nl802.11 channel type. | |
52 | * | |
53 | * The mapping is as follows - | |
54 | * NO_SEC_CHANNEL -> NL80211_CHAN_HT20 | |
55 | * SEC_CHANNEL_ABOVE -> NL80211_CHAN_HT40PLUS | |
56 | * SEC_CHANNEL_BELOW -> NL80211_CHAN_HT40MINUS | |
57 | * Others -> NL80211_CHAN_HT20 | |
58 | */ | |
59 | static enum nl80211_channel_type | |
60 | mwifiex_channels_to_cfg80211_channel_type(int channel_type) | |
61 | { | |
5e6e3a92 BZ |
62 | switch (channel_type) { |
63 | case NO_SEC_CHANNEL: | |
636c4598 | 64 | return NL80211_CHAN_HT20; |
5e6e3a92 | 65 | case SEC_CHANNEL_ABOVE: |
636c4598 | 66 | return NL80211_CHAN_HT40PLUS; |
5e6e3a92 | 67 | case SEC_CHANNEL_BELOW: |
636c4598 | 68 | return NL80211_CHAN_HT40MINUS; |
5e6e3a92 | 69 | default: |
636c4598 | 70 | return NL80211_CHAN_HT20; |
5e6e3a92 | 71 | } |
5e6e3a92 BZ |
72 | } |
73 | ||
74 | /* | |
75 | * This function checks whether WEP is set. | |
76 | */ | |
77 | static int | |
78 | mwifiex_is_alg_wep(u32 cipher) | |
79 | { | |
80 | int alg = 0; | |
81 | ||
82 | switch (cipher) { | |
2be50b8d YAP |
83 | case WLAN_CIPHER_SUITE_WEP40: |
84 | case WLAN_CIPHER_SUITE_WEP104: | |
5e6e3a92 BZ |
85 | alg = 1; |
86 | break; | |
87 | default: | |
88 | alg = 0; | |
89 | break; | |
90 | } | |
91 | return alg; | |
92 | } | |
93 | ||
5e6e3a92 BZ |
94 | /* |
95 | * This function retrieves the private structure from kernel wiphy structure. | |
96 | */ | |
97 | static void *mwifiex_cfg80211_get_priv(struct wiphy *wiphy) | |
98 | { | |
99 | return (void *) (*(unsigned long *) wiphy_priv(wiphy)); | |
100 | } | |
101 | ||
102 | /* | |
103 | * CFG802.11 operation handler to delete a network key. | |
104 | */ | |
105 | static int | |
106 | mwifiex_cfg80211_del_key(struct wiphy *wiphy, struct net_device *netdev, | |
107 | u8 key_index, bool pairwise, const u8 *mac_addr) | |
108 | { | |
109 | struct mwifiex_private *priv = mwifiex_cfg80211_get_priv(wiphy); | |
5e6e3a92 | 110 | |
636c4598 | 111 | if (mwifiex_set_encode(priv, NULL, 0, key_index, 1)) { |
5e6e3a92 BZ |
112 | wiphy_err(wiphy, "deleting the crypto keys\n"); |
113 | return -EFAULT; | |
114 | } | |
115 | ||
116 | wiphy_dbg(wiphy, "info: crypto keys deleted\n"); | |
117 | return 0; | |
118 | } | |
119 | ||
120 | /* | |
121 | * CFG802.11 operation handler to set Tx power. | |
122 | */ | |
123 | static int | |
124 | mwifiex_cfg80211_set_tx_power(struct wiphy *wiphy, | |
125 | enum nl80211_tx_power_setting type, | |
126 | int dbm) | |
127 | { | |
5e6e3a92 | 128 | struct mwifiex_private *priv = mwifiex_cfg80211_get_priv(wiphy); |
600f5d90 | 129 | struct mwifiex_power_cfg power_cfg; |
5e6e3a92 | 130 | |
600f5d90 AK |
131 | if (type == NL80211_TX_POWER_FIXED) { |
132 | power_cfg.is_power_auto = 0; | |
133 | power_cfg.power_level = dbm; | |
134 | } else { | |
135 | power_cfg.is_power_auto = 1; | |
136 | } | |
137 | ||
636c4598 | 138 | return mwifiex_set_tx_power(priv, &power_cfg); |
5e6e3a92 BZ |
139 | } |
140 | ||
141 | /* | |
142 | * CFG802.11 operation handler to set Power Save option. | |
143 | * | |
144 | * The timeout value, if provided, is currently ignored. | |
145 | */ | |
146 | static int | |
147 | mwifiex_cfg80211_set_power_mgmt(struct wiphy *wiphy, | |
148 | struct net_device *dev, | |
149 | bool enabled, int timeout) | |
150 | { | |
5e6e3a92 | 151 | struct mwifiex_private *priv = mwifiex_cfg80211_get_priv(wiphy); |
600f5d90 | 152 | u32 ps_mode; |
5e6e3a92 BZ |
153 | |
154 | if (timeout) | |
155 | wiphy_dbg(wiphy, | |
156 | "info: ignoring the timeout value" | |
157 | " for IEEE power save\n"); | |
158 | ||
600f5d90 | 159 | ps_mode = enabled; |
5e6e3a92 | 160 | |
636c4598 | 161 | return mwifiex_drv_set_power(priv, &ps_mode); |
5e6e3a92 BZ |
162 | } |
163 | ||
164 | /* | |
165 | * CFG802.11 operation handler to set the default network key. | |
166 | */ | |
167 | static int | |
168 | mwifiex_cfg80211_set_default_key(struct wiphy *wiphy, struct net_device *netdev, | |
169 | u8 key_index, bool unicast, | |
170 | bool multicast) | |
171 | { | |
172 | struct mwifiex_private *priv = mwifiex_cfg80211_get_priv(wiphy); | |
5e6e3a92 | 173 | |
2d3d0a88 AK |
174 | /* Return if WEP key not configured */ |
175 | if (priv->sec_info.wep_status == MWIFIEX_802_11_WEP_DISABLED) | |
176 | return 0; | |
177 | ||
636c4598 YAP |
178 | if (mwifiex_set_encode(priv, NULL, 0, key_index, 0)) { |
179 | wiphy_err(wiphy, "set default Tx key index\n"); | |
5e6e3a92 | 180 | return -EFAULT; |
636c4598 | 181 | } |
5e6e3a92 BZ |
182 | |
183 | return 0; | |
184 | } | |
185 | ||
186 | /* | |
187 | * CFG802.11 operation handler to add a network key. | |
188 | */ | |
189 | static int | |
190 | mwifiex_cfg80211_add_key(struct wiphy *wiphy, struct net_device *netdev, | |
191 | u8 key_index, bool pairwise, const u8 *mac_addr, | |
192 | struct key_params *params) | |
193 | { | |
194 | struct mwifiex_private *priv = mwifiex_cfg80211_get_priv(wiphy); | |
5e6e3a92 | 195 | |
636c4598 YAP |
196 | if (mwifiex_set_encode(priv, params->key, params->key_len, |
197 | key_index, 0)) { | |
198 | wiphy_err(wiphy, "crypto keys added\n"); | |
5e6e3a92 | 199 | return -EFAULT; |
636c4598 | 200 | } |
5e6e3a92 BZ |
201 | |
202 | return 0; | |
203 | } | |
204 | ||
205 | /* | |
206 | * This function sends domain information to the firmware. | |
207 | * | |
208 | * The following information are passed to the firmware - | |
209 | * - Country codes | |
210 | * - Sub bands (first channel, number of channels, maximum Tx power) | |
211 | */ | |
212 | static int mwifiex_send_domain_info_cmd_fw(struct wiphy *wiphy) | |
213 | { | |
214 | u8 no_of_triplet = 0; | |
215 | struct ieee80211_country_ie_triplet *t; | |
216 | u8 no_of_parsed_chan = 0; | |
217 | u8 first_chan = 0, next_chan = 0, max_pwr = 0; | |
218 | u8 i, flag = 0; | |
219 | enum ieee80211_band band; | |
220 | struct ieee80211_supported_band *sband; | |
221 | struct ieee80211_channel *ch; | |
222 | struct mwifiex_private *priv = mwifiex_cfg80211_get_priv(wiphy); | |
223 | struct mwifiex_adapter *adapter = priv->adapter; | |
224 | struct mwifiex_802_11d_domain_reg *domain_info = &adapter->domain_reg; | |
5e6e3a92 BZ |
225 | |
226 | /* Set country code */ | |
227 | domain_info->country_code[0] = priv->country_code[0]; | |
228 | domain_info->country_code[1] = priv->country_code[1]; | |
229 | domain_info->country_code[2] = ' '; | |
230 | ||
231 | band = mwifiex_band_to_radio_type(adapter->config_bands); | |
232 | if (!wiphy->bands[band]) { | |
233 | wiphy_err(wiphy, "11D: setting domain info in FW\n"); | |
234 | return -1; | |
235 | } | |
236 | ||
237 | sband = wiphy->bands[band]; | |
238 | ||
239 | for (i = 0; i < sband->n_channels ; i++) { | |
240 | ch = &sband->channels[i]; | |
241 | if (ch->flags & IEEE80211_CHAN_DISABLED) | |
242 | continue; | |
243 | ||
244 | if (!flag) { | |
245 | flag = 1; | |
246 | first_chan = (u32) ch->hw_value; | |
247 | next_chan = first_chan; | |
248 | max_pwr = ch->max_power; | |
249 | no_of_parsed_chan = 1; | |
250 | continue; | |
251 | } | |
252 | ||
253 | if (ch->hw_value == next_chan + 1 && | |
254 | ch->max_power == max_pwr) { | |
255 | next_chan++; | |
256 | no_of_parsed_chan++; | |
257 | } else { | |
258 | t = &domain_info->triplet[no_of_triplet]; | |
259 | t->chans.first_channel = first_chan; | |
260 | t->chans.num_channels = no_of_parsed_chan; | |
261 | t->chans.max_power = max_pwr; | |
262 | no_of_triplet++; | |
263 | first_chan = (u32) ch->hw_value; | |
264 | next_chan = first_chan; | |
265 | max_pwr = ch->max_power; | |
266 | no_of_parsed_chan = 1; | |
267 | } | |
268 | } | |
269 | ||
270 | if (flag) { | |
271 | t = &domain_info->triplet[no_of_triplet]; | |
272 | t->chans.first_channel = first_chan; | |
273 | t->chans.num_channels = no_of_parsed_chan; | |
274 | t->chans.max_power = max_pwr; | |
275 | no_of_triplet++; | |
276 | } | |
277 | ||
278 | domain_info->no_of_triplet = no_of_triplet; | |
636c4598 YAP |
279 | |
280 | if (mwifiex_send_cmd_async(priv, HostCmd_CMD_802_11D_DOMAIN_INFO, | |
281 | HostCmd_ACT_GEN_SET, 0, NULL)) { | |
5e6e3a92 | 282 | wiphy_err(wiphy, "11D: setting domain info in FW\n"); |
636c4598 YAP |
283 | return -1; |
284 | } | |
5e6e3a92 | 285 | |
636c4598 | 286 | return 0; |
5e6e3a92 BZ |
287 | } |
288 | ||
289 | /* | |
290 | * CFG802.11 regulatory domain callback function. | |
291 | * | |
292 | * This function is called when the regulatory domain is changed due to the | |
293 | * following reasons - | |
294 | * - Set by driver | |
295 | * - Set by system core | |
296 | * - Set by user | |
297 | * - Set bt Country IE | |
298 | */ | |
299 | static int mwifiex_reg_notifier(struct wiphy *wiphy, | |
300 | struct regulatory_request *request) | |
301 | { | |
302 | struct mwifiex_private *priv = mwifiex_cfg80211_get_priv(wiphy); | |
303 | ||
304 | wiphy_dbg(wiphy, "info: cfg80211 regulatory domain callback for domain" | |
305 | " %c%c\n", request->alpha2[0], request->alpha2[1]); | |
306 | ||
307 | memcpy(priv->country_code, request->alpha2, sizeof(request->alpha2)); | |
308 | ||
309 | switch (request->initiator) { | |
310 | case NL80211_REGDOM_SET_BY_DRIVER: | |
311 | case NL80211_REGDOM_SET_BY_CORE: | |
312 | case NL80211_REGDOM_SET_BY_USER: | |
313 | break; | |
314 | /* Todo: apply driver specific changes in channel flags based | |
315 | on the request initiator if necessary. */ | |
316 | case NL80211_REGDOM_SET_BY_COUNTRY_IE: | |
317 | break; | |
318 | } | |
319 | mwifiex_send_domain_info_cmd_fw(wiphy); | |
320 | ||
321 | return 0; | |
322 | } | |
323 | ||
324 | /* | |
325 | * This function sets the RF channel. | |
326 | * | |
327 | * This function creates multiple IOCTL requests, populates them accordingly | |
328 | * and issues them to set the band/channel and frequency. | |
329 | */ | |
330 | static int | |
331 | mwifiex_set_rf_channel(struct mwifiex_private *priv, | |
332 | struct ieee80211_channel *chan, | |
333 | enum nl80211_channel_type channel_type) | |
334 | { | |
335 | struct mwifiex_chan_freq_power cfp; | |
5e6e3a92 | 336 | struct mwifiex_ds_band_cfg band_cfg; |
5e6e3a92 BZ |
337 | u32 config_bands = 0; |
338 | struct wiphy *wiphy = priv->wdev->wiphy; | |
339 | ||
5e6e3a92 BZ |
340 | if (chan) { |
341 | memset(&band_cfg, 0, sizeof(band_cfg)); | |
342 | /* Set appropriate bands */ | |
343 | if (chan->band == IEEE80211_BAND_2GHZ) | |
344 | config_bands = BAND_B | BAND_G | BAND_GN; | |
345 | else | |
346 | config_bands = BAND_AN | BAND_A; | |
eecd8250 BZ |
347 | if (priv->bss_mode == NL80211_IFTYPE_STATION |
348 | || priv->bss_mode == NL80211_IFTYPE_UNSPECIFIED) { | |
5e6e3a92 | 349 | band_cfg.config_bands = config_bands; |
eecd8250 | 350 | } else if (priv->bss_mode == NL80211_IFTYPE_ADHOC) { |
5e6e3a92 BZ |
351 | band_cfg.config_bands = config_bands; |
352 | band_cfg.adhoc_start_band = config_bands; | |
353 | } | |
636c4598 | 354 | |
5e6e3a92 BZ |
355 | band_cfg.sec_chan_offset = |
356 | mwifiex_cfg80211_channel_type_to_mwifiex_channels | |
357 | (channel_type); | |
5e6e3a92 | 358 | |
636c4598 | 359 | if (mwifiex_set_radio_band_cfg(priv, &band_cfg)) |
5e6e3a92 | 360 | return -EFAULT; |
636c4598 | 361 | |
5e6e3a92 BZ |
362 | mwifiex_send_domain_info_cmd_fw(wiphy); |
363 | } | |
364 | ||
365 | wiphy_dbg(wiphy, "info: setting band %d, channel offset %d and " | |
eecd8250 BZ |
366 | "mode %d\n", config_bands, band_cfg.sec_chan_offset, |
367 | priv->bss_mode); | |
5e6e3a92 | 368 | if (!chan) |
636c4598 | 369 | return 0; |
5e6e3a92 BZ |
370 | |
371 | memset(&cfp, 0, sizeof(cfp)); | |
372 | cfp.freq = chan->center_freq; | |
5e6e3a92 BZ |
373 | cfp.channel = ieee80211_frequency_to_channel(chan->center_freq); |
374 | ||
636c4598 | 375 | if (mwifiex_bss_set_channel(priv, &cfp)) |
5e6e3a92 BZ |
376 | return -EFAULT; |
377 | ||
636c4598 | 378 | return mwifiex_drv_change_adhoc_chan(priv, cfp.channel); |
5e6e3a92 BZ |
379 | } |
380 | ||
381 | /* | |
382 | * CFG802.11 operation handler to set channel. | |
383 | * | |
384 | * This function can only be used when station is not connected. | |
385 | */ | |
386 | static int | |
387 | mwifiex_cfg80211_set_channel(struct wiphy *wiphy, struct net_device *dev, | |
388 | struct ieee80211_channel *chan, | |
389 | enum nl80211_channel_type channel_type) | |
390 | { | |
391 | struct mwifiex_private *priv = mwifiex_cfg80211_get_priv(wiphy); | |
392 | ||
393 | if (priv->media_connected) { | |
394 | wiphy_err(wiphy, "This setting is valid only when station " | |
395 | "is not connected\n"); | |
396 | return -EINVAL; | |
397 | } | |
398 | ||
399 | return mwifiex_set_rf_channel(priv, chan, channel_type); | |
400 | } | |
401 | ||
402 | /* | |
403 | * This function sets the fragmentation threshold. | |
404 | * | |
600f5d90 | 405 | * The fragmentation threshold value must lie between MWIFIEX_FRAG_MIN_VALUE |
5e6e3a92 BZ |
406 | * and MWIFIEX_FRAG_MAX_VALUE. |
407 | */ | |
408 | static int | |
409 | mwifiex_set_frag(struct mwifiex_private *priv, u32 frag_thr) | |
410 | { | |
411 | int ret = 0; | |
5e6e3a92 BZ |
412 | |
413 | if (frag_thr < MWIFIEX_FRAG_MIN_VALUE | |
414 | || frag_thr > MWIFIEX_FRAG_MAX_VALUE) | |
415 | return -EINVAL; | |
416 | ||
600f5d90 AK |
417 | /* Send request to firmware */ |
418 | ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_SNMP_MIB, | |
419 | HostCmd_ACT_GEN_SET, FRAG_THRESH_I, | |
420 | &frag_thr); | |
5e6e3a92 | 421 | |
5e6e3a92 BZ |
422 | return ret; |
423 | } | |
424 | ||
425 | /* | |
426 | * This function sets the RTS threshold. | |
600f5d90 AK |
427 | |
428 | * The rts value must lie between MWIFIEX_RTS_MIN_VALUE | |
429 | * and MWIFIEX_RTS_MAX_VALUE. | |
5e6e3a92 BZ |
430 | */ |
431 | static int | |
432 | mwifiex_set_rts(struct mwifiex_private *priv, u32 rts_thr) | |
433 | { | |
5e6e3a92 BZ |
434 | if (rts_thr < MWIFIEX_RTS_MIN_VALUE || rts_thr > MWIFIEX_RTS_MAX_VALUE) |
435 | rts_thr = MWIFIEX_RTS_MAX_VALUE; | |
436 | ||
636c4598 | 437 | return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_SNMP_MIB, |
600f5d90 AK |
438 | HostCmd_ACT_GEN_SET, RTS_THRESH_I, |
439 | &rts_thr); | |
5e6e3a92 BZ |
440 | } |
441 | ||
442 | /* | |
443 | * CFG802.11 operation handler to set wiphy parameters. | |
444 | * | |
445 | * This function can be used to set the RTS threshold and the | |
446 | * Fragmentation threshold of the driver. | |
447 | */ | |
448 | static int | |
449 | mwifiex_cfg80211_set_wiphy_params(struct wiphy *wiphy, u32 changed) | |
450 | { | |
451 | struct mwifiex_private *priv = mwifiex_cfg80211_get_priv(wiphy); | |
452 | ||
453 | int ret = 0; | |
454 | ||
636c4598 | 455 | if (changed & WIPHY_PARAM_RTS_THRESHOLD) { |
5e6e3a92 | 456 | ret = mwifiex_set_rts(priv, wiphy->rts_threshold); |
636c4598 YAP |
457 | if (ret) |
458 | return ret; | |
459 | } | |
5e6e3a92 BZ |
460 | |
461 | if (changed & WIPHY_PARAM_FRAG_THRESHOLD) | |
462 | ret = mwifiex_set_frag(priv, wiphy->frag_threshold); | |
463 | ||
464 | return ret; | |
465 | } | |
466 | ||
467 | /* | |
468 | * CFG802.11 operation handler to change interface type. | |
5e6e3a92 BZ |
469 | */ |
470 | static int | |
471 | mwifiex_cfg80211_change_virtual_intf(struct wiphy *wiphy, | |
472 | struct net_device *dev, | |
473 | enum nl80211_iftype type, u32 *flags, | |
474 | struct vif_params *params) | |
475 | { | |
476 | int ret = 0; | |
477 | struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev); | |
5e6e3a92 | 478 | |
eecd8250 BZ |
479 | if (priv->bss_mode == type) { |
480 | wiphy_warn(wiphy, "already set to required type\n"); | |
481 | return 0; | |
482 | } | |
483 | ||
484 | priv->bss_mode = type; | |
5e6e3a92 BZ |
485 | |
486 | switch (type) { | |
487 | case NL80211_IFTYPE_ADHOC: | |
5e6e3a92 BZ |
488 | dev->ieee80211_ptr->iftype = NL80211_IFTYPE_ADHOC; |
489 | wiphy_dbg(wiphy, "info: setting interface type to adhoc\n"); | |
490 | break; | |
491 | case NL80211_IFTYPE_STATION: | |
5e6e3a92 | 492 | dev->ieee80211_ptr->iftype = NL80211_IFTYPE_STATION; |
eecd8250 | 493 | wiphy_dbg(wiphy, "info: setting interface type to managed\n"); |
5e6e3a92 BZ |
494 | break; |
495 | case NL80211_IFTYPE_UNSPECIFIED: | |
5e6e3a92 BZ |
496 | dev->ieee80211_ptr->iftype = NL80211_IFTYPE_STATION; |
497 | wiphy_dbg(wiphy, "info: setting interface type to auto\n"); | |
eecd8250 | 498 | return 0; |
5e6e3a92 | 499 | default: |
eecd8250 BZ |
500 | wiphy_err(wiphy, "unknown interface type: %d\n", type); |
501 | return -EINVAL; | |
5e6e3a92 | 502 | } |
5e6e3a92 | 503 | |
600f5d90 | 504 | mwifiex_deauthenticate(priv, NULL); |
eecd8250 | 505 | |
f986b6d5 | 506 | priv->sec_info.authentication_mode = NL80211_AUTHTYPE_OPEN_SYSTEM; |
eecd8250 | 507 | |
600f5d90 AK |
508 | ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_SET_BSS_MODE, |
509 | HostCmd_ACT_GEN_SET, 0, NULL); | |
eecd8250 | 510 | |
5e6e3a92 BZ |
511 | return ret; |
512 | } | |
513 | ||
514 | /* | |
515 | * This function dumps the station information on a buffer. | |
516 | * | |
517 | * The following information are shown - | |
518 | * - Total bytes transmitted | |
519 | * - Total bytes received | |
520 | * - Total packets transmitted | |
521 | * - Total packets received | |
522 | * - Signal quality level | |
523 | * - Transmission rate | |
524 | */ | |
525 | static int | |
526 | mwifiex_dump_station_info(struct mwifiex_private *priv, | |
527 | struct station_info *sinfo) | |
528 | { | |
529 | struct mwifiex_ds_get_signal signal; | |
530 | struct mwifiex_rate_cfg rate; | |
531 | int ret = 0; | |
532 | ||
533 | sinfo->filled = STATION_INFO_RX_BYTES | STATION_INFO_TX_BYTES | | |
534 | STATION_INFO_RX_PACKETS | | |
535 | STATION_INFO_TX_PACKETS | |
536 | | STATION_INFO_SIGNAL | STATION_INFO_TX_BITRATE; | |
537 | ||
538 | /* Get signal information from the firmware */ | |
539 | memset(&signal, 0, sizeof(struct mwifiex_ds_get_signal)); | |
600f5d90 | 540 | if (mwifiex_get_signal_info(priv, &signal)) { |
5e6e3a92 BZ |
541 | dev_err(priv->adapter->dev, "getting signal information\n"); |
542 | ret = -EFAULT; | |
543 | } | |
544 | ||
545 | if (mwifiex_drv_get_data_rate(priv, &rate)) { | |
546 | dev_err(priv->adapter->dev, "getting data rate\n"); | |
547 | ret = -EFAULT; | |
548 | } | |
549 | ||
550 | sinfo->rx_bytes = priv->stats.rx_bytes; | |
551 | sinfo->tx_bytes = priv->stats.tx_bytes; | |
552 | sinfo->rx_packets = priv->stats.rx_packets; | |
553 | sinfo->tx_packets = priv->stats.tx_packets; | |
554 | sinfo->signal = priv->w_stats.qual.level; | |
555 | sinfo->txrate.legacy = rate.rate; | |
556 | ||
557 | return ret; | |
558 | } | |
559 | ||
560 | /* | |
561 | * CFG802.11 operation handler to get station information. | |
562 | * | |
563 | * This function only works in connected mode, and dumps the | |
564 | * requested station information, if available. | |
565 | */ | |
566 | static int | |
567 | mwifiex_cfg80211_get_station(struct wiphy *wiphy, struct net_device *dev, | |
568 | u8 *mac, struct station_info *sinfo) | |
569 | { | |
570 | struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev); | |
5e6e3a92 BZ |
571 | |
572 | mwifiex_dump_station_info(priv, sinfo); | |
573 | ||
574 | if (!priv->media_connected) | |
575 | return -ENOENT; | |
576 | if (memcmp(mac, priv->cfg_bssid, ETH_ALEN)) | |
577 | return -ENOENT; | |
578 | ||
636c4598 | 579 | return mwifiex_dump_station_info(priv, sinfo); |
5e6e3a92 BZ |
580 | } |
581 | ||
582 | /* Supported rates to be advertised to the cfg80211 */ | |
583 | ||
584 | static struct ieee80211_rate mwifiex_rates[] = { | |
585 | {.bitrate = 10, .hw_value = 2, }, | |
586 | {.bitrate = 20, .hw_value = 4, }, | |
587 | {.bitrate = 55, .hw_value = 11, }, | |
588 | {.bitrate = 110, .hw_value = 22, }, | |
589 | {.bitrate = 220, .hw_value = 44, }, | |
590 | {.bitrate = 60, .hw_value = 12, }, | |
591 | {.bitrate = 90, .hw_value = 18, }, | |
592 | {.bitrate = 120, .hw_value = 24, }, | |
593 | {.bitrate = 180, .hw_value = 36, }, | |
594 | {.bitrate = 240, .hw_value = 48, }, | |
595 | {.bitrate = 360, .hw_value = 72, }, | |
596 | {.bitrate = 480, .hw_value = 96, }, | |
597 | {.bitrate = 540, .hw_value = 108, }, | |
598 | {.bitrate = 720, .hw_value = 144, }, | |
599 | }; | |
600 | ||
601 | /* Channel definitions to be advertised to cfg80211 */ | |
602 | ||
603 | static struct ieee80211_channel mwifiex_channels_2ghz[] = { | |
604 | {.center_freq = 2412, .hw_value = 1, }, | |
605 | {.center_freq = 2417, .hw_value = 2, }, | |
606 | {.center_freq = 2422, .hw_value = 3, }, | |
607 | {.center_freq = 2427, .hw_value = 4, }, | |
608 | {.center_freq = 2432, .hw_value = 5, }, | |
609 | {.center_freq = 2437, .hw_value = 6, }, | |
610 | {.center_freq = 2442, .hw_value = 7, }, | |
611 | {.center_freq = 2447, .hw_value = 8, }, | |
612 | {.center_freq = 2452, .hw_value = 9, }, | |
613 | {.center_freq = 2457, .hw_value = 10, }, | |
614 | {.center_freq = 2462, .hw_value = 11, }, | |
615 | {.center_freq = 2467, .hw_value = 12, }, | |
616 | {.center_freq = 2472, .hw_value = 13, }, | |
617 | {.center_freq = 2484, .hw_value = 14, }, | |
618 | }; | |
619 | ||
620 | static struct ieee80211_supported_band mwifiex_band_2ghz = { | |
621 | .channels = mwifiex_channels_2ghz, | |
622 | .n_channels = ARRAY_SIZE(mwifiex_channels_2ghz), | |
623 | .bitrates = mwifiex_rates, | |
624 | .n_bitrates = 14, | |
625 | }; | |
626 | ||
627 | static struct ieee80211_channel mwifiex_channels_5ghz[] = { | |
628 | {.center_freq = 5040, .hw_value = 8, }, | |
629 | {.center_freq = 5060, .hw_value = 12, }, | |
630 | {.center_freq = 5080, .hw_value = 16, }, | |
631 | {.center_freq = 5170, .hw_value = 34, }, | |
632 | {.center_freq = 5190, .hw_value = 38, }, | |
633 | {.center_freq = 5210, .hw_value = 42, }, | |
634 | {.center_freq = 5230, .hw_value = 46, }, | |
635 | {.center_freq = 5180, .hw_value = 36, }, | |
636 | {.center_freq = 5200, .hw_value = 40, }, | |
637 | {.center_freq = 5220, .hw_value = 44, }, | |
638 | {.center_freq = 5240, .hw_value = 48, }, | |
639 | {.center_freq = 5260, .hw_value = 52, }, | |
640 | {.center_freq = 5280, .hw_value = 56, }, | |
641 | {.center_freq = 5300, .hw_value = 60, }, | |
642 | {.center_freq = 5320, .hw_value = 64, }, | |
643 | {.center_freq = 5500, .hw_value = 100, }, | |
644 | {.center_freq = 5520, .hw_value = 104, }, | |
645 | {.center_freq = 5540, .hw_value = 108, }, | |
646 | {.center_freq = 5560, .hw_value = 112, }, | |
647 | {.center_freq = 5580, .hw_value = 116, }, | |
648 | {.center_freq = 5600, .hw_value = 120, }, | |
649 | {.center_freq = 5620, .hw_value = 124, }, | |
650 | {.center_freq = 5640, .hw_value = 128, }, | |
651 | {.center_freq = 5660, .hw_value = 132, }, | |
652 | {.center_freq = 5680, .hw_value = 136, }, | |
653 | {.center_freq = 5700, .hw_value = 140, }, | |
654 | {.center_freq = 5745, .hw_value = 149, }, | |
655 | {.center_freq = 5765, .hw_value = 153, }, | |
656 | {.center_freq = 5785, .hw_value = 157, }, | |
657 | {.center_freq = 5805, .hw_value = 161, }, | |
658 | {.center_freq = 5825, .hw_value = 165, }, | |
659 | }; | |
660 | ||
661 | static struct ieee80211_supported_band mwifiex_band_5ghz = { | |
662 | .channels = mwifiex_channels_5ghz, | |
663 | .n_channels = ARRAY_SIZE(mwifiex_channels_5ghz), | |
664 | .bitrates = mwifiex_rates - 4, | |
665 | .n_bitrates = ARRAY_SIZE(mwifiex_rates) + 4, | |
666 | }; | |
667 | ||
668 | ||
669 | /* Supported crypto cipher suits to be advertised to cfg80211 */ | |
670 | ||
671 | static const u32 mwifiex_cipher_suites[] = { | |
672 | WLAN_CIPHER_SUITE_WEP40, | |
673 | WLAN_CIPHER_SUITE_WEP104, | |
674 | WLAN_CIPHER_SUITE_TKIP, | |
675 | WLAN_CIPHER_SUITE_CCMP, | |
676 | }; | |
677 | ||
678 | /* | |
679 | * CFG802.11 operation handler for disconnection request. | |
680 | * | |
681 | * This function does not work when there is already a disconnection | |
682 | * procedure going on. | |
683 | */ | |
684 | static int | |
685 | mwifiex_cfg80211_disconnect(struct wiphy *wiphy, struct net_device *dev, | |
686 | u16 reason_code) | |
687 | { | |
688 | struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev); | |
689 | ||
690 | if (priv->disconnect) | |
691 | return -EBUSY; | |
692 | ||
693 | priv->disconnect = 1; | |
600f5d90 | 694 | if (mwifiex_deauthenticate(priv, NULL)) |
5e6e3a92 BZ |
695 | return -EFAULT; |
696 | ||
697 | wiphy_dbg(wiphy, "info: successfully disconnected from %pM:" | |
698 | " reason code %d\n", priv->cfg_bssid, reason_code); | |
699 | ||
700 | queue_work(priv->workqueue, &priv->cfg_workqueue); | |
701 | ||
702 | return 0; | |
703 | } | |
704 | ||
705 | /* | |
706 | * This function informs the CFG802.11 subsystem of a new IBSS. | |
707 | * | |
708 | * The following information are sent to the CFG802.11 subsystem | |
709 | * to register the new IBSS. If we do not register the new IBSS, | |
710 | * a kernel panic will result. | |
711 | * - SSID | |
712 | * - SSID length | |
713 | * - BSSID | |
714 | * - Channel | |
715 | */ | |
716 | static int mwifiex_cfg80211_inform_ibss_bss(struct mwifiex_private *priv) | |
717 | { | |
5e6e3a92 BZ |
718 | struct ieee80211_channel *chan; |
719 | struct mwifiex_bss_info bss_info; | |
720 | int ie_len = 0; | |
721 | u8 ie_buf[IEEE80211_MAX_SSID_LEN + sizeof(struct ieee_types_header)]; | |
722 | ||
636c4598 YAP |
723 | if (mwifiex_get_bss_info(priv, &bss_info)) |
724 | return -1; | |
5e6e3a92 BZ |
725 | |
726 | ie_buf[0] = WLAN_EID_SSID; | |
727 | ie_buf[1] = bss_info.ssid.ssid_len; | |
728 | ||
729 | memcpy(&ie_buf[sizeof(struct ieee_types_header)], | |
730 | &bss_info.ssid.ssid, | |
731 | bss_info.ssid.ssid_len); | |
732 | ie_len = ie_buf[1] + sizeof(struct ieee_types_header); | |
733 | ||
734 | chan = __ieee80211_get_channel(priv->wdev->wiphy, | |
735 | ieee80211_channel_to_frequency(bss_info.bss_chan, | |
736 | priv->curr_bss_params.band)); | |
737 | ||
738 | cfg80211_inform_bss(priv->wdev->wiphy, chan, | |
739 | bss_info.bssid, 0, WLAN_CAPABILITY_IBSS, | |
740 | 0, ie_buf, ie_len, 0, GFP_KERNEL); | |
741 | memcpy(priv->cfg_bssid, bss_info.bssid, ETH_ALEN); | |
742 | ||
636c4598 | 743 | return 0; |
5e6e3a92 BZ |
744 | } |
745 | ||
746 | /* | |
747 | * This function informs the CFG802.11 subsystem of a new BSS connection. | |
748 | * | |
749 | * The following information are sent to the CFG802.11 subsystem | |
750 | * to register the new BSS connection. If we do not register the new BSS, | |
751 | * a kernel panic will result. | |
752 | * - MAC address | |
753 | * - Capabilities | |
754 | * - Beacon period | |
755 | * - RSSI value | |
756 | * - Channel | |
757 | * - Supported rates IE | |
758 | * - Extended capabilities IE | |
759 | * - DS parameter set IE | |
760 | * - HT Capability IE | |
761 | * - Vendor Specific IE (221) | |
762 | * - WPA IE | |
763 | * - RSN IE | |
764 | */ | |
765 | static int mwifiex_inform_bss_from_scan_result(struct mwifiex_private *priv, | |
766 | struct mwifiex_802_11_ssid *ssid) | |
767 | { | |
768 | struct mwifiex_scan_resp scan_resp; | |
769 | struct mwifiex_bssdescriptor *scan_table; | |
770 | int i, j; | |
771 | struct ieee80211_channel *chan; | |
636c4598 | 772 | u8 *ie, *ie_buf; |
5e6e3a92 | 773 | u32 ie_len; |
5e6e3a92 BZ |
774 | u8 *beacon; |
775 | int beacon_size; | |
776 | u8 element_id, element_len; | |
777 | ||
778 | memset(&scan_resp, 0, sizeof(scan_resp)); | |
600f5d90 AK |
779 | scan_resp.scan_table = (u8 *) priv->adapter->scan_table; |
780 | scan_resp.num_in_scan_table = priv->adapter->num_in_scan_table; | |
5e6e3a92 BZ |
781 | |
782 | #define MAX_IE_BUF 2048 | |
783 | ie_buf = kzalloc(MAX_IE_BUF, GFP_KERNEL); | |
784 | if (!ie_buf) { | |
785 | dev_err(priv->adapter->dev, "%s: failed to alloc ie_buf\n", | |
786 | __func__); | |
787 | return -ENOMEM; | |
788 | } | |
789 | ||
790 | scan_table = (struct mwifiex_bssdescriptor *) scan_resp.scan_table; | |
791 | for (i = 0; i < scan_resp.num_in_scan_table; i++) { | |
792 | if (ssid) { | |
793 | /* Inform specific BSS only */ | |
794 | if (memcmp(ssid->ssid, scan_table[i].ssid.ssid, | |
795 | ssid->ssid_len)) | |
796 | continue; | |
797 | } | |
798 | memset(ie_buf, 0, MAX_IE_BUF); | |
799 | ie_buf[0] = WLAN_EID_SSID; | |
800 | ie_buf[1] = scan_table[i].ssid.ssid_len; | |
801 | memcpy(&ie_buf[sizeof(struct ieee_types_header)], | |
802 | scan_table[i].ssid.ssid, ie_buf[1]); | |
803 | ||
804 | ie = ie_buf + ie_buf[1] + sizeof(struct ieee_types_header); | |
805 | ie_len = ie_buf[1] + sizeof(struct ieee_types_header); | |
806 | ||
807 | ie[0] = WLAN_EID_SUPP_RATES; | |
808 | ||
809 | for (j = 0; j < sizeof(scan_table[i].supported_rates); j++) { | |
810 | if (!scan_table[i].supported_rates[j]) | |
811 | break; | |
812 | else | |
813 | ie[j + sizeof(struct ieee_types_header)] = | |
814 | scan_table[i].supported_rates[j]; | |
815 | } | |
816 | ||
817 | ie[1] = j; | |
818 | ie_len += ie[1] + sizeof(struct ieee_types_header); | |
819 | ||
820 | beacon = scan_table[i].beacon_buf; | |
821 | beacon_size = scan_table[i].beacon_buf_size; | |
822 | ||
823 | /* Skip time stamp, beacon interval and capability */ | |
824 | ||
825 | if (beacon) { | |
826 | beacon += sizeof(scan_table[i].beacon_period) | |
827 | + sizeof(scan_table[i].time_stamp) + | |
828 | +sizeof(scan_table[i].cap_info_bitmap); | |
829 | ||
830 | beacon_size -= sizeof(scan_table[i].beacon_period) | |
831 | + sizeof(scan_table[i].time_stamp) | |
832 | + sizeof(scan_table[i].cap_info_bitmap); | |
833 | } | |
834 | ||
835 | while (beacon_size >= sizeof(struct ieee_types_header)) { | |
836 | ie = ie_buf + ie_len; | |
837 | element_id = *beacon; | |
838 | element_len = *(beacon + 1); | |
839 | if (beacon_size < (int) element_len + | |
840 | sizeof(struct ieee_types_header)) { | |
841 | dev_err(priv->adapter->dev, "%s: in processing" | |
842 | " IE, bytes left < IE length\n", | |
843 | __func__); | |
844 | break; | |
845 | } | |
846 | switch (element_id) { | |
847 | case WLAN_EID_EXT_CAPABILITY: | |
848 | case WLAN_EID_DS_PARAMS: | |
849 | case WLAN_EID_HT_CAPABILITY: | |
850 | case WLAN_EID_VENDOR_SPECIFIC: | |
851 | case WLAN_EID_RSN: | |
852 | case WLAN_EID_BSS_AC_ACCESS_DELAY: | |
853 | ie[0] = element_id; | |
854 | ie[1] = element_len; | |
5e6e3a92 | 855 | memcpy(&ie[sizeof(struct ieee_types_header)], |
636c4598 YAP |
856 | (u8 *) beacon |
857 | + sizeof(struct ieee_types_header), | |
5e6e3a92 BZ |
858 | element_len); |
859 | ie_len += ie[1] + | |
860 | sizeof(struct ieee_types_header); | |
861 | break; | |
862 | default: | |
863 | break; | |
864 | } | |
865 | beacon += element_len + | |
866 | sizeof(struct ieee_types_header); | |
867 | beacon_size -= element_len + | |
868 | sizeof(struct ieee_types_header); | |
869 | } | |
870 | chan = ieee80211_get_channel(priv->wdev->wiphy, | |
871 | scan_table[i].freq); | |
872 | cfg80211_inform_bss(priv->wdev->wiphy, chan, | |
873 | scan_table[i].mac_address, | |
636c4598 | 874 | 0, scan_table[i].cap_info_bitmap, |
5e6e3a92 BZ |
875 | scan_table[i].beacon_period, |
876 | ie_buf, ie_len, | |
877 | scan_table[i].rssi, GFP_KERNEL); | |
878 | } | |
879 | ||
880 | kfree(ie_buf); | |
881 | return 0; | |
882 | } | |
883 | ||
884 | /* | |
885 | * This function connects with a BSS. | |
886 | * | |
887 | * This function handles both Infra and Ad-Hoc modes. It also performs | |
888 | * validity checking on the provided parameters, disconnects from the | |
889 | * current BSS (if any), sets up the association/scan parameters, | |
890 | * including security settings, and performs specific SSID scan before | |
891 | * trying to connect. | |
892 | * | |
893 | * For Infra mode, the function returns failure if the specified SSID | |
894 | * is not found in scan table. However, for Ad-Hoc mode, it can create | |
895 | * the IBSS if it does not exist. On successful completion in either case, | |
896 | * the function notifies the CFG802.11 subsystem of the new BSS connection, | |
897 | * otherwise the kernel will panic. | |
898 | */ | |
899 | static int | |
900 | mwifiex_cfg80211_assoc(struct mwifiex_private *priv, size_t ssid_len, u8 *ssid, | |
901 | u8 *bssid, int mode, struct ieee80211_channel *channel, | |
902 | struct cfg80211_connect_params *sme, bool privacy) | |
903 | { | |
904 | struct mwifiex_802_11_ssid req_ssid; | |
905 | struct mwifiex_ssid_bssid ssid_bssid; | |
906 | int ret = 0; | |
636c4598 | 907 | int auth_type = 0; |
5e6e3a92 BZ |
908 | |
909 | memset(&req_ssid, 0, sizeof(struct mwifiex_802_11_ssid)); | |
910 | memset(&ssid_bssid, 0, sizeof(struct mwifiex_ssid_bssid)); | |
911 | ||
912 | req_ssid.ssid_len = ssid_len; | |
913 | if (ssid_len > IEEE80211_MAX_SSID_LEN) { | |
914 | dev_err(priv->adapter->dev, "invalid SSID - aborting\n"); | |
915 | return -EINVAL; | |
916 | } | |
917 | ||
918 | memcpy(req_ssid.ssid, ssid, ssid_len); | |
919 | if (!req_ssid.ssid_len || req_ssid.ssid[0] < 0x20) { | |
920 | dev_err(priv->adapter->dev, "invalid SSID - aborting\n"); | |
921 | return -EINVAL; | |
922 | } | |
923 | ||
924 | /* disconnect before try to associate */ | |
600f5d90 | 925 | mwifiex_deauthenticate(priv, NULL); |
5e6e3a92 BZ |
926 | |
927 | if (channel) | |
928 | ret = mwifiex_set_rf_channel(priv, channel, | |
929 | mwifiex_channels_to_cfg80211_channel_type | |
930 | (priv->adapter->chan_offset)); | |
931 | ||
932 | ret = mwifiex_set_encode(priv, NULL, 0, 0, 1); /* Disable keys */ | |
933 | ||
eecd8250 | 934 | if (mode == NL80211_IFTYPE_ADHOC) { |
5e6e3a92 BZ |
935 | /* "privacy" is set only for ad-hoc mode */ |
936 | if (privacy) { | |
937 | /* | |
2be50b8d | 938 | * Keep WLAN_CIPHER_SUITE_WEP104 for now so that |
5e6e3a92 BZ |
939 | * the firmware can find a matching network from the |
940 | * scan. The cfg80211 does not give us the encryption | |
941 | * mode at this stage so just setting it to WEP here. | |
942 | */ | |
203afeca | 943 | priv->sec_info.encryption_mode = |
2be50b8d | 944 | WLAN_CIPHER_SUITE_WEP104; |
203afeca | 945 | priv->sec_info.authentication_mode = |
f986b6d5 | 946 | NL80211_AUTHTYPE_OPEN_SYSTEM; |
5e6e3a92 BZ |
947 | } |
948 | ||
949 | goto done; | |
950 | } | |
951 | ||
952 | /* Now handle infra mode. "sme" is valid for infra mode only */ | |
953 | if (sme->auth_type == NL80211_AUTHTYPE_AUTOMATIC | |
954 | || sme->auth_type == NL80211_AUTHTYPE_OPEN_SYSTEM) | |
f986b6d5 | 955 | auth_type = NL80211_AUTHTYPE_OPEN_SYSTEM; |
5e6e3a92 | 956 | else if (sme->auth_type == NL80211_AUTHTYPE_SHARED_KEY) |
f986b6d5 | 957 | auth_type = NL80211_AUTHTYPE_SHARED_KEY; |
5e6e3a92 BZ |
958 | |
959 | if (sme->crypto.n_ciphers_pairwise) { | |
2be50b8d YAP |
960 | priv->sec_info.encryption_mode = |
961 | sme->crypto.ciphers_pairwise[0]; | |
203afeca | 962 | priv->sec_info.authentication_mode = auth_type; |
5e6e3a92 BZ |
963 | } |
964 | ||
965 | if (sme->crypto.cipher_group) { | |
2be50b8d | 966 | priv->sec_info.encryption_mode = sme->crypto.cipher_group; |
203afeca | 967 | priv->sec_info.authentication_mode = auth_type; |
5e6e3a92 BZ |
968 | } |
969 | if (sme->ie) | |
970 | ret = mwifiex_set_gen_ie(priv, sme->ie, sme->ie_len); | |
971 | ||
972 | if (sme->key) { | |
636c4598 | 973 | if (mwifiex_is_alg_wep(0) | mwifiex_is_alg_wep(0)) { |
5e6e3a92 BZ |
974 | dev_dbg(priv->adapter->dev, |
975 | "info: setting wep encryption" | |
976 | " with key len %d\n", sme->key_len); | |
977 | ret = mwifiex_set_encode(priv, sme->key, sme->key_len, | |
978 | sme->key_idx, 0); | |
979 | } | |
980 | } | |
981 | done: | |
982 | /* Do specific SSID scanning */ | |
600f5d90 | 983 | if (mwifiex_request_scan(priv, &req_ssid)) { |
5e6e3a92 BZ |
984 | dev_err(priv->adapter->dev, "scan error\n"); |
985 | return -EFAULT; | |
986 | } | |
987 | ||
988 | ||
989 | memcpy(&ssid_bssid.ssid, &req_ssid, sizeof(struct mwifiex_802_11_ssid)); | |
990 | ||
eecd8250 | 991 | if (mode != NL80211_IFTYPE_ADHOC) { |
600f5d90 | 992 | if (mwifiex_find_best_bss(priv, &ssid_bssid)) |
5e6e3a92 BZ |
993 | return -EFAULT; |
994 | /* Inform the BSS information to kernel, otherwise | |
995 | * kernel will give a panic after successful assoc */ | |
996 | if (mwifiex_inform_bss_from_scan_result(priv, &req_ssid)) | |
997 | return -EFAULT; | |
998 | } | |
999 | ||
1000 | dev_dbg(priv->adapter->dev, "info: trying to associate to %s and bssid %pM\n", | |
1001 | (char *) req_ssid.ssid, ssid_bssid.bssid); | |
1002 | ||
1003 | memcpy(&priv->cfg_bssid, ssid_bssid.bssid, 6); | |
1004 | ||
1005 | /* Connect to BSS by ESSID */ | |
1006 | memset(&ssid_bssid.bssid, 0, ETH_ALEN); | |
1007 | ||
600f5d90 AK |
1008 | if (!netif_queue_stopped(priv->netdev)) |
1009 | netif_stop_queue(priv->netdev); | |
1010 | ||
1011 | if (mwifiex_bss_start(priv, &ssid_bssid)) | |
5e6e3a92 BZ |
1012 | return -EFAULT; |
1013 | ||
eecd8250 | 1014 | if (mode == NL80211_IFTYPE_ADHOC) { |
5e6e3a92 BZ |
1015 | /* Inform the BSS information to kernel, otherwise |
1016 | * kernel will give a panic after successful assoc */ | |
1017 | if (mwifiex_cfg80211_inform_ibss_bss(priv)) | |
1018 | return -EFAULT; | |
1019 | } | |
1020 | ||
1021 | return ret; | |
1022 | } | |
1023 | ||
1024 | /* | |
1025 | * CFG802.11 operation handler for association request. | |
1026 | * | |
1027 | * This function does not work when the current mode is set to Ad-Hoc, or | |
1028 | * when there is already an association procedure going on. The given BSS | |
1029 | * information is used to associate. | |
1030 | */ | |
1031 | static int | |
1032 | mwifiex_cfg80211_connect(struct wiphy *wiphy, struct net_device *dev, | |
1033 | struct cfg80211_connect_params *sme) | |
1034 | { | |
1035 | struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev); | |
1036 | int ret = 0; | |
5e6e3a92 BZ |
1037 | |
1038 | if (priv->assoc_request) | |
1039 | return -EBUSY; | |
1040 | ||
eecd8250 | 1041 | if (priv->bss_mode == NL80211_IFTYPE_ADHOC) { |
5e6e3a92 BZ |
1042 | wiphy_err(wiphy, "received infra assoc request " |
1043 | "when station is in ibss mode\n"); | |
1044 | goto done; | |
1045 | } | |
1046 | ||
1047 | priv->assoc_request = 1; | |
1048 | ||
1049 | wiphy_dbg(wiphy, "info: Trying to associate to %s and bssid %pM\n", | |
1050 | (char *) sme->ssid, sme->bssid); | |
1051 | ||
1052 | ret = mwifiex_cfg80211_assoc(priv, sme->ssid_len, sme->ssid, sme->bssid, | |
eecd8250 | 1053 | priv->bss_mode, sme->channel, sme, 0); |
5e6e3a92 BZ |
1054 | |
1055 | done: | |
1056 | priv->assoc_result = ret; | |
1057 | queue_work(priv->workqueue, &priv->cfg_workqueue); | |
1058 | return ret; | |
1059 | } | |
1060 | ||
1061 | /* | |
1062 | * CFG802.11 operation handler to join an IBSS. | |
1063 | * | |
1064 | * This function does not work in any mode other than Ad-Hoc, or if | |
1065 | * a join operation is already in progress. | |
1066 | */ | |
1067 | static int | |
1068 | mwifiex_cfg80211_join_ibss(struct wiphy *wiphy, struct net_device *dev, | |
1069 | struct cfg80211_ibss_params *params) | |
1070 | { | |
1071 | struct mwifiex_private *priv = mwifiex_cfg80211_get_priv(wiphy); | |
1072 | int ret = 0; | |
5e6e3a92 BZ |
1073 | |
1074 | if (priv->ibss_join_request) | |
1075 | return -EBUSY; | |
1076 | ||
eecd8250 | 1077 | if (priv->bss_mode != NL80211_IFTYPE_ADHOC) { |
5e6e3a92 BZ |
1078 | wiphy_err(wiphy, "request to join ibss received " |
1079 | "when station is not in ibss mode\n"); | |
1080 | goto done; | |
1081 | } | |
1082 | ||
1083 | priv->ibss_join_request = 1; | |
1084 | ||
1085 | wiphy_dbg(wiphy, "info: trying to join to %s and bssid %pM\n", | |
1086 | (char *) params->ssid, params->bssid); | |
1087 | ||
1088 | ret = mwifiex_cfg80211_assoc(priv, params->ssid_len, params->ssid, | |
eecd8250 BZ |
1089 | params->bssid, priv->bss_mode, |
1090 | params->channel, NULL, params->privacy); | |
5e6e3a92 BZ |
1091 | done: |
1092 | priv->ibss_join_result = ret; | |
1093 | queue_work(priv->workqueue, &priv->cfg_workqueue); | |
1094 | return ret; | |
1095 | } | |
1096 | ||
1097 | /* | |
1098 | * CFG802.11 operation handler to leave an IBSS. | |
1099 | * | |
1100 | * This function does not work if a leave operation is | |
1101 | * already in progress. | |
1102 | */ | |
1103 | static int | |
1104 | mwifiex_cfg80211_leave_ibss(struct wiphy *wiphy, struct net_device *dev) | |
1105 | { | |
1106 | struct mwifiex_private *priv = mwifiex_cfg80211_get_priv(wiphy); | |
1107 | ||
1108 | if (priv->disconnect) | |
1109 | return -EBUSY; | |
1110 | ||
1111 | priv->disconnect = 1; | |
1112 | ||
1113 | wiphy_dbg(wiphy, "info: disconnecting from essid %pM\n", | |
1114 | priv->cfg_bssid); | |
600f5d90 | 1115 | if (mwifiex_deauthenticate(priv, NULL)) |
5e6e3a92 BZ |
1116 | return -EFAULT; |
1117 | ||
1118 | queue_work(priv->workqueue, &priv->cfg_workqueue); | |
1119 | ||
1120 | return 0; | |
1121 | } | |
1122 | ||
1123 | /* | |
1124 | * CFG802.11 operation handler for scan request. | |
1125 | * | |
1126 | * This function issues a scan request to the firmware based upon | |
1127 | * the user specified scan configuration. On successfull completion, | |
1128 | * it also informs the results. | |
1129 | */ | |
1130 | static int | |
1131 | mwifiex_cfg80211_scan(struct wiphy *wiphy, struct net_device *dev, | |
1132 | struct cfg80211_scan_request *request) | |
1133 | { | |
1134 | struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev); | |
1135 | ||
1136 | wiphy_dbg(wiphy, "info: received scan request on %s\n", dev->name); | |
1137 | ||
1138 | if (priv->scan_request && priv->scan_request != request) | |
1139 | return -EBUSY; | |
1140 | ||
1141 | priv->scan_request = request; | |
1142 | ||
1143 | queue_work(priv->workqueue, &priv->cfg_workqueue); | |
1144 | return 0; | |
1145 | } | |
1146 | ||
1147 | /* | |
1148 | * This function sets up the CFG802.11 specific HT capability fields | |
1149 | * with default values. | |
1150 | * | |
1151 | * The following default values are set - | |
1152 | * - HT Supported = True | |
1153 | * - Maximum AMPDU length factor = 0x3 | |
1154 | * - Minimum AMPDU spacing = 0x6 | |
1155 | * - HT Capabilities map = IEEE80211_HT_CAP_SUP_WIDTH_20_40 (0x0002) | |
1156 | * - MCS information, Rx mask = 0xff | |
1157 | * - MCD information, Tx parameters = IEEE80211_HT_MCS_TX_DEFINED (0x01) | |
1158 | */ | |
1159 | static void | |
1160 | mwifiex_setup_ht_caps(struct ieee80211_sta_ht_cap *ht_info, | |
1161 | struct mwifiex_private *priv) | |
1162 | { | |
1163 | int rx_mcs_supp; | |
1164 | struct ieee80211_mcs_info mcs_set; | |
1165 | u8 *mcs = (u8 *)&mcs_set; | |
1166 | struct mwifiex_adapter *adapter = priv->adapter; | |
1167 | ||
1168 | ht_info->ht_supported = true; | |
1169 | ht_info->ampdu_factor = 0x3; | |
1170 | ht_info->ampdu_density = 0x6; | |
1171 | ||
1172 | memset(&ht_info->mcs, 0, sizeof(ht_info->mcs)); | |
1173 | ht_info->cap = IEEE80211_HT_CAP_SUP_WIDTH_20_40; | |
1174 | ||
1175 | rx_mcs_supp = GET_RXMCSSUPP(priv->adapter->hw_dev_mcs_support); | |
1176 | /* Set MCS for 1x1 */ | |
1177 | memset(mcs, 0xff, rx_mcs_supp); | |
1178 | /* Clear all the other values */ | |
1179 | memset(&mcs[rx_mcs_supp], 0, | |
1180 | sizeof(struct ieee80211_mcs_info) - rx_mcs_supp); | |
eecd8250 | 1181 | if (priv->bss_mode == NL80211_IFTYPE_STATION || |
6d2bd916 | 1182 | ISSUPP_CHANWIDTH40(adapter->hw_dot_11n_dev_cap)) |
5e6e3a92 BZ |
1183 | /* Set MCS32 for infra mode or ad-hoc mode with 40MHz support */ |
1184 | SETHT_MCS32(mcs_set.rx_mask); | |
1185 | ||
1186 | memcpy((u8 *) &ht_info->mcs, mcs, sizeof(struct ieee80211_mcs_info)); | |
1187 | ||
1188 | ht_info->mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED; | |
1189 | } | |
1190 | ||
1191 | /* station cfg80211 operations */ | |
1192 | static struct cfg80211_ops mwifiex_cfg80211_ops = { | |
1193 | .change_virtual_intf = mwifiex_cfg80211_change_virtual_intf, | |
1194 | .scan = mwifiex_cfg80211_scan, | |
1195 | .connect = mwifiex_cfg80211_connect, | |
1196 | .disconnect = mwifiex_cfg80211_disconnect, | |
1197 | .get_station = mwifiex_cfg80211_get_station, | |
1198 | .set_wiphy_params = mwifiex_cfg80211_set_wiphy_params, | |
1199 | .set_channel = mwifiex_cfg80211_set_channel, | |
1200 | .join_ibss = mwifiex_cfg80211_join_ibss, | |
1201 | .leave_ibss = mwifiex_cfg80211_leave_ibss, | |
1202 | .add_key = mwifiex_cfg80211_add_key, | |
1203 | .del_key = mwifiex_cfg80211_del_key, | |
1204 | .set_default_key = mwifiex_cfg80211_set_default_key, | |
1205 | .set_power_mgmt = mwifiex_cfg80211_set_power_mgmt, | |
1206 | .set_tx_power = mwifiex_cfg80211_set_tx_power, | |
1207 | }; | |
1208 | ||
1209 | /* | |
1210 | * This function registers the device with CFG802.11 subsystem. | |
1211 | * | |
1212 | * The function creates the wireless device/wiphy, populates it with | |
1213 | * default parameters and handler function pointers, and finally | |
1214 | * registers the device. | |
1215 | */ | |
1216 | int mwifiex_register_cfg80211(struct net_device *dev, u8 *mac, | |
1217 | struct mwifiex_private *priv) | |
1218 | { | |
1219 | int ret = 0; | |
1220 | void *wdev_priv = NULL; | |
1221 | struct wireless_dev *wdev; | |
1222 | ||
1223 | wdev = kzalloc(sizeof(struct wireless_dev), GFP_KERNEL); | |
1224 | if (!wdev) { | |
1225 | dev_err(priv->adapter->dev, "%s: allocating wireless device\n", | |
1226 | __func__); | |
1227 | return -ENOMEM; | |
1228 | } | |
1229 | wdev->wiphy = | |
1230 | wiphy_new(&mwifiex_cfg80211_ops, | |
1231 | sizeof(struct mwifiex_private *)); | |
1232 | if (!wdev->wiphy) | |
1233 | return -ENOMEM; | |
1234 | wdev->iftype = NL80211_IFTYPE_STATION; | |
1235 | wdev->wiphy->max_scan_ssids = 10; | |
1236 | wdev->wiphy->interface_modes = | |
1237 | BIT(NL80211_IFTYPE_STATION) | BIT(NL80211_IFTYPE_ADHOC); | |
adc89595 | 1238 | |
5e6e3a92 | 1239 | wdev->wiphy->bands[IEEE80211_BAND_2GHZ] = &mwifiex_band_2ghz; |
adc89595 AK |
1240 | mwifiex_setup_ht_caps( |
1241 | &wdev->wiphy->bands[IEEE80211_BAND_2GHZ]->ht_cap, priv); | |
1242 | ||
1243 | if (priv->adapter->config_bands & BAND_A) { | |
1244 | wdev->wiphy->bands[IEEE80211_BAND_5GHZ] = &mwifiex_band_5ghz; | |
1245 | mwifiex_setup_ht_caps( | |
1246 | &wdev->wiphy->bands[IEEE80211_BAND_5GHZ]->ht_cap, priv); | |
1247 | } else { | |
1248 | wdev->wiphy->bands[IEEE80211_BAND_5GHZ] = NULL; | |
1249 | } | |
5e6e3a92 BZ |
1250 | |
1251 | /* Initialize cipher suits */ | |
1252 | wdev->wiphy->cipher_suites = mwifiex_cipher_suites; | |
1253 | wdev->wiphy->n_cipher_suites = ARRAY_SIZE(mwifiex_cipher_suites); | |
1254 | ||
5e6e3a92 BZ |
1255 | memcpy(wdev->wiphy->perm_addr, mac, 6); |
1256 | wdev->wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM; | |
1257 | ||
1258 | /* We are using custom domains */ | |
1259 | wdev->wiphy->flags |= WIPHY_FLAG_CUSTOM_REGULATORY; | |
1260 | ||
1261 | wdev->wiphy->reg_notifier = mwifiex_reg_notifier; | |
1262 | ||
1263 | /* Set struct mwifiex_private pointer in wiphy_priv */ | |
1264 | wdev_priv = wiphy_priv(wdev->wiphy); | |
1265 | ||
1266 | *(unsigned long *) wdev_priv = (unsigned long) priv; | |
1267 | ||
1268 | ret = wiphy_register(wdev->wiphy); | |
1269 | if (ret < 0) { | |
1270 | dev_err(priv->adapter->dev, "%s: registering cfg80211 device\n", | |
1271 | __func__); | |
1272 | wiphy_free(wdev->wiphy); | |
1273 | return ret; | |
1274 | } else { | |
1275 | dev_dbg(priv->adapter->dev, | |
1276 | "info: successfully registered wiphy device\n"); | |
1277 | } | |
1278 | ||
1279 | dev_net_set(dev, wiphy_net(wdev->wiphy)); | |
1280 | dev->ieee80211_ptr = wdev; | |
1281 | memcpy(dev->dev_addr, wdev->wiphy->perm_addr, 6); | |
1282 | memcpy(dev->perm_addr, wdev->wiphy->perm_addr, 6); | |
1283 | SET_NETDEV_DEV(dev, wiphy_dev(wdev->wiphy)); | |
1284 | priv->wdev = wdev; | |
1285 | ||
1286 | dev->flags |= IFF_BROADCAST | IFF_MULTICAST; | |
1287 | dev->watchdog_timeo = MWIFIEX_DEFAULT_WATCHDOG_TIMEOUT; | |
1288 | dev->hard_header_len += MWIFIEX_MIN_DATA_HEADER_LEN; | |
1289 | ||
1290 | return ret; | |
1291 | } | |
1292 | ||
1293 | /* | |
1294 | * This function handles the result of different pending network operations. | |
1295 | * | |
1296 | * The following operations are handled and CFG802.11 subsystem is | |
1297 | * notified accordingly - | |
1298 | * - Scan request completion | |
1299 | * - Association request completion | |
1300 | * - IBSS join request completion | |
1301 | * - Disconnect request completion | |
1302 | */ | |
1303 | void | |
1304 | mwifiex_cfg80211_results(struct work_struct *work) | |
1305 | { | |
1306 | struct mwifiex_private *priv = | |
1307 | container_of(work, struct mwifiex_private, cfg_workqueue); | |
1308 | struct mwifiex_user_scan_cfg *scan_req; | |
1309 | int ret = 0, i; | |
1310 | struct ieee80211_channel *chan; | |
1311 | ||
1312 | if (priv->scan_request) { | |
1313 | scan_req = kzalloc(sizeof(struct mwifiex_user_scan_cfg), | |
1314 | GFP_KERNEL); | |
1315 | if (!scan_req) { | |
1316 | dev_err(priv->adapter->dev, "failed to alloc " | |
1317 | "scan_req\n"); | |
1318 | return; | |
1319 | } | |
1320 | for (i = 0; i < priv->scan_request->n_ssids; i++) { | |
1321 | memcpy(scan_req->ssid_list[i].ssid, | |
1322 | priv->scan_request->ssids[i].ssid, | |
1323 | priv->scan_request->ssids[i].ssid_len); | |
1324 | scan_req->ssid_list[i].max_len = | |
1325 | priv->scan_request->ssids[i].ssid_len; | |
1326 | } | |
1327 | for (i = 0; i < priv->scan_request->n_channels; i++) { | |
1328 | chan = priv->scan_request->channels[i]; | |
1329 | scan_req->chan_list[i].chan_number = chan->hw_value; | |
1330 | scan_req->chan_list[i].radio_type = chan->band; | |
1331 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
1332 | scan_req->chan_list[i].scan_type = | |
1333 | MWIFIEX_SCAN_TYPE_PASSIVE; | |
1334 | else | |
1335 | scan_req->chan_list[i].scan_type = | |
1336 | MWIFIEX_SCAN_TYPE_ACTIVE; | |
1337 | scan_req->chan_list[i].scan_time = 0; | |
1338 | } | |
1339 | if (mwifiex_set_user_scan_ioctl(priv, scan_req)) { | |
1340 | ret = -EFAULT; | |
1341 | goto done; | |
1342 | } | |
1343 | if (mwifiex_inform_bss_from_scan_result(priv, NULL)) | |
1344 | ret = -EFAULT; | |
1345 | done: | |
1346 | priv->scan_result_status = ret; | |
1347 | dev_dbg(priv->adapter->dev, "info: %s: sending scan results\n", | |
1348 | __func__); | |
1349 | cfg80211_scan_done(priv->scan_request, | |
1350 | (priv->scan_result_status < 0)); | |
1351 | priv->scan_request = NULL; | |
1352 | kfree(scan_req); | |
1353 | } | |
1354 | ||
1355 | if (priv->assoc_request) { | |
1356 | if (!priv->assoc_result) { | |
1357 | cfg80211_connect_result(priv->netdev, priv->cfg_bssid, | |
1358 | NULL, 0, NULL, 0, | |
1359 | WLAN_STATUS_SUCCESS, | |
1360 | GFP_KERNEL); | |
1361 | dev_dbg(priv->adapter->dev, | |
1362 | "info: associated to bssid %pM successfully\n", | |
1363 | priv->cfg_bssid); | |
1364 | } else { | |
1365 | dev_dbg(priv->adapter->dev, | |
1366 | "info: association to bssid %pM failed\n", | |
1367 | priv->cfg_bssid); | |
1368 | memset(priv->cfg_bssid, 0, ETH_ALEN); | |
1369 | } | |
1370 | priv->assoc_request = 0; | |
1371 | priv->assoc_result = 0; | |
1372 | } | |
1373 | ||
1374 | if (priv->ibss_join_request) { | |
1375 | if (!priv->ibss_join_result) { | |
1376 | cfg80211_ibss_joined(priv->netdev, priv->cfg_bssid, | |
1377 | GFP_KERNEL); | |
1378 | dev_dbg(priv->adapter->dev, | |
1379 | "info: joined/created adhoc network with bssid" | |
1380 | " %pM successfully\n", priv->cfg_bssid); | |
1381 | } else { | |
1382 | dev_dbg(priv->adapter->dev, | |
1383 | "info: failed creating/joining adhoc network\n"); | |
1384 | } | |
1385 | priv->ibss_join_request = 0; | |
1386 | priv->ibss_join_result = 0; | |
1387 | } | |
1388 | ||
1389 | if (priv->disconnect) { | |
1390 | memset(priv->cfg_bssid, 0, ETH_ALEN); | |
1391 | priv->disconnect = 0; | |
1392 | } | |
5e6e3a92 | 1393 | } |