blob: b99ae2677d78982266105f73ba873df02a9d6723 [file] [log] [blame]
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001/*
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 */
33static int
34mwifiex_cfg80211_channel_type_to_mwifiex_channels(enum nl80211_channel_type
35 channel_type)
36{
Bing Zhao5e6e3a92011-03-21 18:00:50 -070037 switch (channel_type) {
38 case NL80211_CHAN_NO_HT:
39 case NL80211_CHAN_HT20:
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -070040 return NO_SEC_CHANNEL;
Bing Zhao5e6e3a92011-03-21 18:00:50 -070041 case NL80211_CHAN_HT40PLUS:
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -070042 return SEC_CHANNEL_ABOVE;
Bing Zhao5e6e3a92011-03-21 18:00:50 -070043 case NL80211_CHAN_HT40MINUS:
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -070044 return SEC_CHANNEL_BELOW;
Bing Zhao5e6e3a92011-03-21 18:00:50 -070045 default:
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -070046 return NO_SEC_CHANNEL;
Bing Zhao5e6e3a92011-03-21 18:00:50 -070047 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -070048}
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 */
59static enum nl80211_channel_type
60mwifiex_channels_to_cfg80211_channel_type(int channel_type)
61{
Bing Zhao5e6e3a92011-03-21 18:00:50 -070062 switch (channel_type) {
63 case NO_SEC_CHANNEL:
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -070064 return NL80211_CHAN_HT20;
Bing Zhao5e6e3a92011-03-21 18:00:50 -070065 case SEC_CHANNEL_ABOVE:
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -070066 return NL80211_CHAN_HT40PLUS;
Bing Zhao5e6e3a92011-03-21 18:00:50 -070067 case SEC_CHANNEL_BELOW:
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -070068 return NL80211_CHAN_HT40MINUS;
Bing Zhao5e6e3a92011-03-21 18:00:50 -070069 default:
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -070070 return NL80211_CHAN_HT20;
Bing Zhao5e6e3a92011-03-21 18:00:50 -070071 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -070072}
73
74/*
75 * This function checks whether WEP is set.
76 */
77static int
78mwifiex_is_alg_wep(u32 cipher)
79{
80 int alg = 0;
81
82 switch (cipher) {
Yogesh Ashok Powar2be50b82011-04-01 18:36:47 -070083 case WLAN_CIPHER_SUITE_WEP40:
84 case WLAN_CIPHER_SUITE_WEP104:
Bing Zhao5e6e3a92011-03-21 18:00:50 -070085 alg = 1;
86 break;
87 default:
88 alg = 0;
89 break;
90 }
91 return alg;
92}
93
94/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -070095 * This function retrieves the private structure from kernel wiphy structure.
96 */
97static 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 */
105static int
106mwifiex_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);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700110
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700111 if (mwifiex_set_encode(priv, NULL, 0, key_index, 1)) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700112 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 */
123static int
124mwifiex_cfg80211_set_tx_power(struct wiphy *wiphy,
125 enum nl80211_tx_power_setting type,
126 int dbm)
127{
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700128 struct mwifiex_private *priv = mwifiex_cfg80211_get_priv(wiphy);
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700129 struct mwifiex_power_cfg power_cfg;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700130
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700131 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
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700138 return mwifiex_set_tx_power(priv, &power_cfg);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700139}
140
141/*
142 * CFG802.11 operation handler to set Power Save option.
143 *
144 * The timeout value, if provided, is currently ignored.
145 */
146static int
147mwifiex_cfg80211_set_power_mgmt(struct wiphy *wiphy,
148 struct net_device *dev,
149 bool enabled, int timeout)
150{
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700151 struct mwifiex_private *priv = mwifiex_cfg80211_get_priv(wiphy);
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700152 u32 ps_mode;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700153
154 if (timeout)
155 wiphy_dbg(wiphy,
156 "info: ignoring the timeout value"
157 " for IEEE power save\n");
158
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700159 ps_mode = enabled;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700160
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700161 return mwifiex_drv_set_power(priv, &ps_mode);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700162}
163
164/*
165 * CFG802.11 operation handler to set the default network key.
166 */
167static int
168mwifiex_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);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700173
Amitkumar Karwar2d3d0a82011-04-01 18:36:46 -0700174 /* Return if WEP key not configured */
175 if (priv->sec_info.wep_status == MWIFIEX_802_11_WEP_DISABLED)
176 return 0;
177
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700178 if (mwifiex_set_encode(priv, NULL, 0, key_index, 0)) {
179 wiphy_err(wiphy, "set default Tx key index\n");
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700180 return -EFAULT;
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700181 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700182
183 return 0;
184}
185
186/*
187 * CFG802.11 operation handler to add a network key.
188 */
189static int
190mwifiex_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);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700195
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700196 if (mwifiex_set_encode(priv, params->key, params->key_len,
197 key_index, 0)) {
198 wiphy_err(wiphy, "crypto keys added\n");
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700199 return -EFAULT;
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700200 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700201
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 */
212static 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;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700225
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;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700279
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700280 if (mwifiex_send_cmd_async(priv, HostCmd_CMD_802_11D_DOMAIN_INFO,
281 HostCmd_ACT_GEN_SET, 0, NULL)) {
282 wiphy_err(wiphy, "11D: setting domain info in FW\n");
283 return -1;
284 }
285
286 return 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700287}
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 */
299static 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 */
330static int
331mwifiex_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;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700336 struct mwifiex_ds_band_cfg band_cfg;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700337 u32 config_bands = 0;
338 struct wiphy *wiphy = priv->wdev->wiphy;
339
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700340 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;
Bing Zhaoeecd8252011-03-28 17:55:41 -0700347 if (priv->bss_mode == NL80211_IFTYPE_STATION
348 || priv->bss_mode == NL80211_IFTYPE_UNSPECIFIED) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700349 band_cfg.config_bands = config_bands;
Bing Zhaoeecd8252011-03-28 17:55:41 -0700350 } else if (priv->bss_mode == NL80211_IFTYPE_ADHOC) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700351 band_cfg.config_bands = config_bands;
352 band_cfg.adhoc_start_band = config_bands;
353 }
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700354
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700355 band_cfg.sec_chan_offset =
356 mwifiex_cfg80211_channel_type_to_mwifiex_channels
357 (channel_type);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700358
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700359 if (mwifiex_set_radio_band_cfg(priv, &band_cfg))
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700360 return -EFAULT;
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700361
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700362 mwifiex_send_domain_info_cmd_fw(wiphy);
363 }
364
365 wiphy_dbg(wiphy, "info: setting band %d, channel offset %d and "
Bing Zhaoeecd8252011-03-28 17:55:41 -0700366 "mode %d\n", config_bands, band_cfg.sec_chan_offset,
367 priv->bss_mode);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700368 if (!chan)
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700369 return 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700370
371 memset(&cfp, 0, sizeof(cfp));
372 cfp.freq = chan->center_freq;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700373 cfp.channel = ieee80211_frequency_to_channel(chan->center_freq);
374
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700375 if (mwifiex_bss_set_channel(priv, &cfp))
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700376 return -EFAULT;
377
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700378 return mwifiex_drv_change_adhoc_chan(priv, cfp.channel);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700379}
380
381/*
382 * CFG802.11 operation handler to set channel.
383 *
384 * This function can only be used when station is not connected.
385 */
386static int
387mwifiex_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 *
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700405 * The fragmentation threshold value must lie between MWIFIEX_FRAG_MIN_VALUE
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700406 * and MWIFIEX_FRAG_MAX_VALUE.
407 */
408static int
409mwifiex_set_frag(struct mwifiex_private *priv, u32 frag_thr)
410{
411 int ret = 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700412
413 if (frag_thr < MWIFIEX_FRAG_MIN_VALUE
414 || frag_thr > MWIFIEX_FRAG_MAX_VALUE)
415 return -EINVAL;
416
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700417 /* 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);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700421
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700422 return ret;
423}
424
425/*
426 * This function sets the RTS threshold.
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700427
428 * The rts value must lie between MWIFIEX_RTS_MIN_VALUE
429 * and MWIFIEX_RTS_MAX_VALUE.
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700430 */
431static int
432mwifiex_set_rts(struct mwifiex_private *priv, u32 rts_thr)
433{
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700434 if (rts_thr < MWIFIEX_RTS_MIN_VALUE || rts_thr > MWIFIEX_RTS_MAX_VALUE)
435 rts_thr = MWIFIEX_RTS_MAX_VALUE;
436
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700437 return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_SNMP_MIB,
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700438 HostCmd_ACT_GEN_SET, RTS_THRESH_I,
439 &rts_thr);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700440}
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 */
448static int
449mwifiex_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
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700455 if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700456 ret = mwifiex_set_rts(priv, wiphy->rts_threshold);
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700457 if (ret)
458 return ret;
459 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700460
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.
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700469 */
470static int
471mwifiex_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);
Bing Zhaoeecd8252011-03-28 17:55:41 -0700478
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;
485
486 switch (type) {
487 case NL80211_IFTYPE_ADHOC:
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:
492 dev->ieee80211_ptr->iftype = NL80211_IFTYPE_STATION;
493 wiphy_dbg(wiphy, "info: setting interface type to managed\n");
494 break;
495 case NL80211_IFTYPE_UNSPECIFIED:
496 dev->ieee80211_ptr->iftype = NL80211_IFTYPE_STATION;
497 wiphy_dbg(wiphy, "info: setting interface type to auto\n");
498 return 0;
499 default:
500 wiphy_err(wiphy, "unknown interface type: %d\n", type);
501 return -EINVAL;
502 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700503
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700504 mwifiex_deauthenticate(priv, NULL);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700505
Marc Yangf986b6d2011-03-28 17:55:42 -0700506 priv->sec_info.authentication_mode = NL80211_AUTHTYPE_OPEN_SYSTEM;
Bing Zhaoeecd8252011-03-28 17:55:41 -0700507
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700508 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_SET_BSS_MODE,
509 HostCmd_ACT_GEN_SET, 0, NULL);
Bing Zhaoeecd8252011-03-28 17:55:41 -0700510
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700511 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 */
525static int
526mwifiex_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));
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700540 if (mwifiex_get_signal_info(priv, &signal)) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700541 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 */
566static int
567mwifiex_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);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700571
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
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700579 return mwifiex_dump_station_info(priv, sinfo);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700580}
581
582/* Supported rates to be advertised to the cfg80211 */
583
584static 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
603static 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
620static 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
627static 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
661static 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
671static 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 */
684static int
685mwifiex_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;
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700694 if (mwifiex_deauthenticate(priv, NULL))
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700695 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 */
716static int mwifiex_cfg80211_inform_ibss_bss(struct mwifiex_private *priv)
717{
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700718 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
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700723 if (mwifiex_get_bss_info(priv, &bss_info))
724 return -1;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700725
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
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700743 return 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700744}
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 */
765static 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;
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700772 u8 *ie, *ie_buf;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700773 u32 ie_len;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700774 u8 *beacon;
775 int beacon_size;
776 u8 element_id, element_len;
777
778 memset(&scan_resp, 0, sizeof(scan_resp));
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700779 scan_resp.scan_table = (u8 *) priv->adapter->scan_table;
780 scan_resp.num_in_scan_table = priv->adapter->num_in_scan_table;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700781
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;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700855 memcpy(&ie[sizeof(struct ieee_types_header)],
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700856 (u8 *) beacon
857 + sizeof(struct ieee_types_header),
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700858 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,
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700874 0, scan_table[i].cap_info_bitmap,
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700875 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 */
899static int
900mwifiex_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;
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700907 int auth_type = 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700908
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 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700925 mwifiex_deauthenticate(priv, NULL);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700926
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
Bing Zhaoeecd8252011-03-28 17:55:41 -0700934 if (mode == NL80211_IFTYPE_ADHOC) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700935 /* "privacy" is set only for ad-hoc mode */
936 if (privacy) {
937 /*
Yogesh Ashok Powar2be50b82011-04-01 18:36:47 -0700938 * Keep WLAN_CIPHER_SUITE_WEP104 for now so that
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700939 * 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 */
Marc Yang203afec2011-03-24 20:49:39 -0700943 priv->sec_info.encryption_mode =
Yogesh Ashok Powar2be50b82011-04-01 18:36:47 -0700944 WLAN_CIPHER_SUITE_WEP104;
Marc Yang203afec2011-03-24 20:49:39 -0700945 priv->sec_info.authentication_mode =
Marc Yangf986b6d2011-03-28 17:55:42 -0700946 NL80211_AUTHTYPE_OPEN_SYSTEM;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700947 }
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)
Marc Yangf986b6d2011-03-28 17:55:42 -0700955 auth_type = NL80211_AUTHTYPE_OPEN_SYSTEM;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700956 else if (sme->auth_type == NL80211_AUTHTYPE_SHARED_KEY)
Marc Yangf986b6d2011-03-28 17:55:42 -0700957 auth_type = NL80211_AUTHTYPE_SHARED_KEY;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700958
959 if (sme->crypto.n_ciphers_pairwise) {
Yogesh Ashok Powar2be50b82011-04-01 18:36:47 -0700960 priv->sec_info.encryption_mode =
961 sme->crypto.ciphers_pairwise[0];
Marc Yang203afec2011-03-24 20:49:39 -0700962 priv->sec_info.authentication_mode = auth_type;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700963 }
964
965 if (sme->crypto.cipher_group) {
Yogesh Ashok Powar2be50b82011-04-01 18:36:47 -0700966 priv->sec_info.encryption_mode = sme->crypto.cipher_group;
Marc Yang203afec2011-03-24 20:49:39 -0700967 priv->sec_info.authentication_mode = auth_type;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700968 }
969 if (sme->ie)
970 ret = mwifiex_set_gen_ie(priv, sme->ie, sme->ie_len);
971
972 if (sme->key) {
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700973 if (mwifiex_is_alg_wep(0) | mwifiex_is_alg_wep(0)) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700974 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 }
981done:
982 /* Do specific SSID scanning */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700983 if (mwifiex_request_scan(priv, &req_ssid)) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700984 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
Bing Zhaoeecd8252011-03-28 17:55:41 -0700991 if (mode != NL80211_IFTYPE_ADHOC) {
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700992 if (mwifiex_find_best_bss(priv, &ssid_bssid))
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700993 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
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001008 if (!netif_queue_stopped(priv->netdev))
1009 netif_stop_queue(priv->netdev);
1010
1011 if (mwifiex_bss_start(priv, &ssid_bssid))
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001012 return -EFAULT;
1013
Bing Zhaoeecd8252011-03-28 17:55:41 -07001014 if (mode == NL80211_IFTYPE_ADHOC) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001015 /* 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 */
1031static int
1032mwifiex_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;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001037
1038 if (priv->assoc_request)
1039 return -EBUSY;
1040
Bing Zhaoeecd8252011-03-28 17:55:41 -07001041 if (priv->bss_mode == NL80211_IFTYPE_ADHOC) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001042 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,
Bing Zhaoeecd8252011-03-28 17:55:41 -07001053 priv->bss_mode, sme->channel, sme, 0);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001054
1055done:
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 */
1067static int
1068mwifiex_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;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001073
1074 if (priv->ibss_join_request)
1075 return -EBUSY;
1076
Bing Zhaoeecd8252011-03-28 17:55:41 -07001077 if (priv->bss_mode != NL80211_IFTYPE_ADHOC) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001078 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,
Bing Zhaoeecd8252011-03-28 17:55:41 -07001089 params->bssid, priv->bss_mode,
1090 params->channel, NULL, params->privacy);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001091done:
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 */
1103static int
1104mwifiex_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);
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001115 if (mwifiex_deauthenticate(priv, NULL))
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001116 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 */
1130static int
1131mwifiex_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 */
1159static void
1160mwifiex_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);
Bing Zhaoeecd8252011-03-28 17:55:41 -07001181 if (priv->bss_mode == NL80211_IFTYPE_STATION ||
Marc Yang6d2bd912011-03-25 19:47:02 -07001182 ISSUPP_CHANWIDTH40(adapter->hw_dot_11n_dev_cap))
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001183 /* 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 */
1192static 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 */
1216int 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);
1238 wdev->wiphy->bands[IEEE80211_BAND_2GHZ] = &mwifiex_band_2ghz;
1239 wdev->wiphy->bands[IEEE80211_BAND_5GHZ] = &mwifiex_band_5ghz;
1240
1241 /* Initialize cipher suits */
1242 wdev->wiphy->cipher_suites = mwifiex_cipher_suites;
1243 wdev->wiphy->n_cipher_suites = ARRAY_SIZE(mwifiex_cipher_suites);
1244
1245 /* Initialize parameters for 2GHz band */
1246
1247 mwifiex_setup_ht_caps(&wdev->wiphy->bands[IEEE80211_BAND_2GHZ]->ht_cap,
1248 priv);
1249 mwifiex_setup_ht_caps(&wdev->wiphy->bands[IEEE80211_BAND_5GHZ]->ht_cap,
1250 priv);
1251
1252 memcpy(wdev->wiphy->perm_addr, mac, 6);
1253 wdev->wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
1254
1255 /* We are using custom domains */
1256 wdev->wiphy->flags |= WIPHY_FLAG_CUSTOM_REGULATORY;
1257
1258 wdev->wiphy->reg_notifier = mwifiex_reg_notifier;
1259
1260 /* Set struct mwifiex_private pointer in wiphy_priv */
1261 wdev_priv = wiphy_priv(wdev->wiphy);
1262
1263 *(unsigned long *) wdev_priv = (unsigned long) priv;
1264
1265 ret = wiphy_register(wdev->wiphy);
1266 if (ret < 0) {
1267 dev_err(priv->adapter->dev, "%s: registering cfg80211 device\n",
1268 __func__);
1269 wiphy_free(wdev->wiphy);
1270 return ret;
1271 } else {
1272 dev_dbg(priv->adapter->dev,
1273 "info: successfully registered wiphy device\n");
1274 }
1275
1276 dev_net_set(dev, wiphy_net(wdev->wiphy));
1277 dev->ieee80211_ptr = wdev;
1278 memcpy(dev->dev_addr, wdev->wiphy->perm_addr, 6);
1279 memcpy(dev->perm_addr, wdev->wiphy->perm_addr, 6);
1280 SET_NETDEV_DEV(dev, wiphy_dev(wdev->wiphy));
1281 priv->wdev = wdev;
1282
1283 dev->flags |= IFF_BROADCAST | IFF_MULTICAST;
1284 dev->watchdog_timeo = MWIFIEX_DEFAULT_WATCHDOG_TIMEOUT;
1285 dev->hard_header_len += MWIFIEX_MIN_DATA_HEADER_LEN;
1286
1287 return ret;
1288}
1289
1290/*
1291 * This function handles the result of different pending network operations.
1292 *
1293 * The following operations are handled and CFG802.11 subsystem is
1294 * notified accordingly -
1295 * - Scan request completion
1296 * - Association request completion
1297 * - IBSS join request completion
1298 * - Disconnect request completion
1299 */
1300void
1301mwifiex_cfg80211_results(struct work_struct *work)
1302{
1303 struct mwifiex_private *priv =
1304 container_of(work, struct mwifiex_private, cfg_workqueue);
1305 struct mwifiex_user_scan_cfg *scan_req;
1306 int ret = 0, i;
1307 struct ieee80211_channel *chan;
1308
1309 if (priv->scan_request) {
1310 scan_req = kzalloc(sizeof(struct mwifiex_user_scan_cfg),
1311 GFP_KERNEL);
1312 if (!scan_req) {
1313 dev_err(priv->adapter->dev, "failed to alloc "
1314 "scan_req\n");
1315 return;
1316 }
1317 for (i = 0; i < priv->scan_request->n_ssids; i++) {
1318 memcpy(scan_req->ssid_list[i].ssid,
1319 priv->scan_request->ssids[i].ssid,
1320 priv->scan_request->ssids[i].ssid_len);
1321 scan_req->ssid_list[i].max_len =
1322 priv->scan_request->ssids[i].ssid_len;
1323 }
1324 for (i = 0; i < priv->scan_request->n_channels; i++) {
1325 chan = priv->scan_request->channels[i];
1326 scan_req->chan_list[i].chan_number = chan->hw_value;
1327 scan_req->chan_list[i].radio_type = chan->band;
1328 if (chan->flags & IEEE80211_CHAN_DISABLED)
1329 scan_req->chan_list[i].scan_type =
1330 MWIFIEX_SCAN_TYPE_PASSIVE;
1331 else
1332 scan_req->chan_list[i].scan_type =
1333 MWIFIEX_SCAN_TYPE_ACTIVE;
1334 scan_req->chan_list[i].scan_time = 0;
1335 }
1336 if (mwifiex_set_user_scan_ioctl(priv, scan_req)) {
1337 ret = -EFAULT;
1338 goto done;
1339 }
1340 if (mwifiex_inform_bss_from_scan_result(priv, NULL))
1341 ret = -EFAULT;
1342done:
1343 priv->scan_result_status = ret;
1344 dev_dbg(priv->adapter->dev, "info: %s: sending scan results\n",
1345 __func__);
1346 cfg80211_scan_done(priv->scan_request,
1347 (priv->scan_result_status < 0));
1348 priv->scan_request = NULL;
1349 kfree(scan_req);
1350 }
1351
1352 if (priv->assoc_request) {
1353 if (!priv->assoc_result) {
1354 cfg80211_connect_result(priv->netdev, priv->cfg_bssid,
1355 NULL, 0, NULL, 0,
1356 WLAN_STATUS_SUCCESS,
1357 GFP_KERNEL);
1358 dev_dbg(priv->adapter->dev,
1359 "info: associated to bssid %pM successfully\n",
1360 priv->cfg_bssid);
1361 } else {
1362 dev_dbg(priv->adapter->dev,
1363 "info: association to bssid %pM failed\n",
1364 priv->cfg_bssid);
1365 memset(priv->cfg_bssid, 0, ETH_ALEN);
1366 }
1367 priv->assoc_request = 0;
1368 priv->assoc_result = 0;
1369 }
1370
1371 if (priv->ibss_join_request) {
1372 if (!priv->ibss_join_result) {
1373 cfg80211_ibss_joined(priv->netdev, priv->cfg_bssid,
1374 GFP_KERNEL);
1375 dev_dbg(priv->adapter->dev,
1376 "info: joined/created adhoc network with bssid"
1377 " %pM successfully\n", priv->cfg_bssid);
1378 } else {
1379 dev_dbg(priv->adapter->dev,
1380 "info: failed creating/joining adhoc network\n");
1381 }
1382 priv->ibss_join_request = 0;
1383 priv->ibss_join_result = 0;
1384 }
1385
1386 if (priv->disconnect) {
1387 memset(priv->cfg_bssid, 0, ETH_ALEN);
1388 priv->disconnect = 0;
1389 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001390}