blob: ff627e1f8378c822db43ba53f2fdf6c60f123d27 [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
Avinash Patilcd8440d2012-05-08 18:30:16 -070023static const struct ieee80211_iface_limit mwifiex_ap_sta_limits[] = {
24 {
25 .max = 1, .types = BIT(NL80211_IFTYPE_STATION),
26 },
27 {
28 .max = 1, .types = BIT(NL80211_IFTYPE_AP),
29 },
30};
31
32static const struct ieee80211_iface_combination mwifiex_iface_comb_ap_sta = {
33 .limits = mwifiex_ap_sta_limits,
34 .num_different_channels = 1,
35 .n_limits = ARRAY_SIZE(mwifiex_ap_sta_limits),
36 .max_interfaces = MWIFIEX_MAX_BSS_NUM,
37 .beacon_int_infra_match = true,
38};
39
Bing Zhao5e6e3a92011-03-21 18:00:50 -070040/*
41 * This function maps the nl802.11 channel type into driver channel type.
42 *
43 * The mapping is as follows -
Amitkumar Karwar21c3ba32011-12-20 23:47:21 -080044 * NL80211_CHAN_NO_HT -> IEEE80211_HT_PARAM_CHA_SEC_NONE
45 * NL80211_CHAN_HT20 -> IEEE80211_HT_PARAM_CHA_SEC_NONE
46 * NL80211_CHAN_HT40PLUS -> IEEE80211_HT_PARAM_CHA_SEC_ABOVE
47 * NL80211_CHAN_HT40MINUS -> IEEE80211_HT_PARAM_CHA_SEC_BELOW
48 * Others -> IEEE80211_HT_PARAM_CHA_SEC_NONE
Bing Zhao5e6e3a92011-03-21 18:00:50 -070049 */
Amitkumar Karwar21c3ba32011-12-20 23:47:21 -080050static u8
51mwifiex_cfg80211_channel_type_to_sec_chan_offset(enum nl80211_channel_type
52 channel_type)
Bing Zhao5e6e3a92011-03-21 18:00:50 -070053{
Bing Zhao5e6e3a92011-03-21 18:00:50 -070054 switch (channel_type) {
55 case NL80211_CHAN_NO_HT:
56 case NL80211_CHAN_HT20:
Amitkumar Karwar21c3ba32011-12-20 23:47:21 -080057 return IEEE80211_HT_PARAM_CHA_SEC_NONE;
Bing Zhao5e6e3a92011-03-21 18:00:50 -070058 case NL80211_CHAN_HT40PLUS:
Amitkumar Karwar21c3ba32011-12-20 23:47:21 -080059 return IEEE80211_HT_PARAM_CHA_SEC_ABOVE;
Bing Zhao5e6e3a92011-03-21 18:00:50 -070060 case NL80211_CHAN_HT40MINUS:
Amitkumar Karwar21c3ba32011-12-20 23:47:21 -080061 return IEEE80211_HT_PARAM_CHA_SEC_BELOW;
Bing Zhao5e6e3a92011-03-21 18:00:50 -070062 default:
Amitkumar Karwar21c3ba32011-12-20 23:47:21 -080063 return IEEE80211_HT_PARAM_CHA_SEC_NONE;
Bing Zhao5e6e3a92011-03-21 18:00:50 -070064 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -070065}
66
67/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -070068 * This function checks whether WEP is set.
69 */
70static int
71mwifiex_is_alg_wep(u32 cipher)
72{
Bing Zhao5e6e3a92011-03-21 18:00:50 -070073 switch (cipher) {
Yogesh Ashok Powar2be50b82011-04-01 18:36:47 -070074 case WLAN_CIPHER_SUITE_WEP40:
75 case WLAN_CIPHER_SUITE_WEP104:
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -070076 return 1;
Bing Zhao5e6e3a92011-03-21 18:00:50 -070077 default:
Bing Zhao5e6e3a92011-03-21 18:00:50 -070078 break;
79 }
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -070080
81 return 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -070082}
83
84/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -070085 * This function retrieves the private structure from kernel wiphy structure.
86 */
Avinash Patil67fdf392012-05-08 18:30:17 -070087static void *mwifiex_cfg80211_get_adapter(struct wiphy *wiphy)
Bing Zhao5e6e3a92011-03-21 18:00:50 -070088{
89 return (void *) (*(unsigned long *) wiphy_priv(wiphy));
90}
91
92/*
93 * CFG802.11 operation handler to delete a network key.
94 */
95static int
96mwifiex_cfg80211_del_key(struct wiphy *wiphy, struct net_device *netdev,
97 u8 key_index, bool pairwise, const u8 *mac_addr)
98{
Yogesh Ashok Powarf540f9f2012-01-11 20:06:12 -080099 struct mwifiex_private *priv = mwifiex_netdev_get_priv(netdev);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700100
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700101 if (mwifiex_set_encode(priv, NULL, 0, key_index, 1)) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700102 wiphy_err(wiphy, "deleting the crypto keys\n");
103 return -EFAULT;
104 }
105
106 wiphy_dbg(wiphy, "info: crypto keys deleted\n");
107 return 0;
108}
109
110/*
111 * CFG802.11 operation handler to set Tx power.
112 */
113static int
114mwifiex_cfg80211_set_tx_power(struct wiphy *wiphy,
115 enum nl80211_tx_power_setting type,
Luis R. Rodriguez742c29f2011-11-28 16:38:50 -0500116 int mbm)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700117{
Avinash Patil67fdf392012-05-08 18:30:17 -0700118 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
119 struct mwifiex_private *priv;
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700120 struct mwifiex_power_cfg power_cfg;
Luis R. Rodriguez742c29f2011-11-28 16:38:50 -0500121 int dbm = MBM_TO_DBM(mbm);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700122
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700123 if (type == NL80211_TX_POWER_FIXED) {
124 power_cfg.is_power_auto = 0;
125 power_cfg.power_level = dbm;
126 } else {
127 power_cfg.is_power_auto = 1;
128 }
129
Avinash Patil67fdf392012-05-08 18:30:17 -0700130 priv = mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY);
131
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700132 return mwifiex_set_tx_power(priv, &power_cfg);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700133}
134
135/*
136 * CFG802.11 operation handler to set Power Save option.
137 *
138 * The timeout value, if provided, is currently ignored.
139 */
140static int
141mwifiex_cfg80211_set_power_mgmt(struct wiphy *wiphy,
142 struct net_device *dev,
143 bool enabled, int timeout)
144{
Yogesh Ashok Powarf540f9f2012-01-11 20:06:12 -0800145 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700146 u32 ps_mode;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700147
148 if (timeout)
149 wiphy_dbg(wiphy,
Yogesh Ashok Powaraea07012012-03-13 19:22:35 -0700150 "info: ignore timeout value for IEEE Power Save\n");
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700151
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700152 ps_mode = enabled;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700153
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700154 return mwifiex_drv_set_power(priv, &ps_mode);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700155}
156
157/*
158 * CFG802.11 operation handler to set the default network key.
159 */
160static int
161mwifiex_cfg80211_set_default_key(struct wiphy *wiphy, struct net_device *netdev,
162 u8 key_index, bool unicast,
163 bool multicast)
164{
Yogesh Ashok Powarf540f9f2012-01-11 20:06:12 -0800165 struct mwifiex_private *priv = mwifiex_netdev_get_priv(netdev);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700166
Amitkumar Karwar2d3d0a82011-04-01 18:36:46 -0700167 /* Return if WEP key not configured */
Amitkumar Karwar5eb02e42012-02-24 21:36:04 -0800168 if (!priv->sec_info.wep_enabled)
Amitkumar Karwar2d3d0a82011-04-01 18:36:46 -0700169 return 0;
170
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700171 if (mwifiex_set_encode(priv, NULL, 0, key_index, 0)) {
172 wiphy_err(wiphy, "set default Tx key index\n");
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700173 return -EFAULT;
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700174 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700175
176 return 0;
177}
178
179/*
180 * CFG802.11 operation handler to add a network key.
181 */
182static int
183mwifiex_cfg80211_add_key(struct wiphy *wiphy, struct net_device *netdev,
184 u8 key_index, bool pairwise, const u8 *mac_addr,
185 struct key_params *params)
186{
Yogesh Ashok Powarf540f9f2012-01-11 20:06:12 -0800187 struct mwifiex_private *priv = mwifiex_netdev_get_priv(netdev);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700188
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700189 if (mwifiex_set_encode(priv, params->key, params->key_len,
Yogesh Ashok Powaraea07012012-03-13 19:22:35 -0700190 key_index, 0)) {
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700191 wiphy_err(wiphy, "crypto keys added\n");
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700192 return -EFAULT;
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700193 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700194
195 return 0;
196}
197
198/*
199 * This function sends domain information to the firmware.
200 *
201 * The following information are passed to the firmware -
202 * - Country codes
203 * - Sub bands (first channel, number of channels, maximum Tx power)
204 */
205static int mwifiex_send_domain_info_cmd_fw(struct wiphy *wiphy)
206{
207 u8 no_of_triplet = 0;
208 struct ieee80211_country_ie_triplet *t;
209 u8 no_of_parsed_chan = 0;
210 u8 first_chan = 0, next_chan = 0, max_pwr = 0;
211 u8 i, flag = 0;
212 enum ieee80211_band band;
213 struct ieee80211_supported_band *sband;
214 struct ieee80211_channel *ch;
Avinash Patil67fdf392012-05-08 18:30:17 -0700215 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
216 struct mwifiex_private *priv;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700217 struct mwifiex_802_11d_domain_reg *domain_info = &adapter->domain_reg;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700218
219 /* Set country code */
Avinash Patil67fdf392012-05-08 18:30:17 -0700220 domain_info->country_code[0] = adapter->country_code[0];
221 domain_info->country_code[1] = adapter->country_code[1];
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700222 domain_info->country_code[2] = ' ';
223
224 band = mwifiex_band_to_radio_type(adapter->config_bands);
225 if (!wiphy->bands[band]) {
226 wiphy_err(wiphy, "11D: setting domain info in FW\n");
227 return -1;
228 }
229
230 sband = wiphy->bands[band];
231
232 for (i = 0; i < sband->n_channels ; i++) {
233 ch = &sband->channels[i];
234 if (ch->flags & IEEE80211_CHAN_DISABLED)
235 continue;
236
237 if (!flag) {
238 flag = 1;
239 first_chan = (u32) ch->hw_value;
240 next_chan = first_chan;
241 max_pwr = ch->max_power;
242 no_of_parsed_chan = 1;
243 continue;
244 }
245
246 if (ch->hw_value == next_chan + 1 &&
Yogesh Ashok Powaraea07012012-03-13 19:22:35 -0700247 ch->max_power == max_pwr) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700248 next_chan++;
249 no_of_parsed_chan++;
250 } else {
251 t = &domain_info->triplet[no_of_triplet];
252 t->chans.first_channel = first_chan;
253 t->chans.num_channels = no_of_parsed_chan;
254 t->chans.max_power = max_pwr;
255 no_of_triplet++;
256 first_chan = (u32) ch->hw_value;
257 next_chan = first_chan;
258 max_pwr = ch->max_power;
259 no_of_parsed_chan = 1;
260 }
261 }
262
263 if (flag) {
264 t = &domain_info->triplet[no_of_triplet];
265 t->chans.first_channel = first_chan;
266 t->chans.num_channels = no_of_parsed_chan;
267 t->chans.max_power = max_pwr;
268 no_of_triplet++;
269 }
270
271 domain_info->no_of_triplet = no_of_triplet;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700272
Avinash Patil67fdf392012-05-08 18:30:17 -0700273 priv = mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY);
274
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700275 if (mwifiex_send_cmd_async(priv, HostCmd_CMD_802_11D_DOMAIN_INFO,
Yogesh Ashok Powaraea07012012-03-13 19:22:35 -0700276 HostCmd_ACT_GEN_SET, 0, NULL)) {
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700277 wiphy_err(wiphy, "11D: setting domain info in FW\n");
278 return -1;
279 }
280
281 return 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700282}
283
284/*
285 * CFG802.11 regulatory domain callback function.
286 *
287 * This function is called when the regulatory domain is changed due to the
288 * following reasons -
289 * - Set by driver
290 * - Set by system core
291 * - Set by user
292 * - Set bt Country IE
293 */
294static int mwifiex_reg_notifier(struct wiphy *wiphy,
Yogesh Ashok Powaraea07012012-03-13 19:22:35 -0700295 struct regulatory_request *request)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700296{
Avinash Patil67fdf392012-05-08 18:30:17 -0700297 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700298
Avinash Patil67fdf392012-05-08 18:30:17 -0700299 wiphy_dbg(wiphy, "info: cfg80211 regulatory domain callback for %c%c\n",
300 request->alpha2[0], request->alpha2[1]);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700301
Avinash Patil67fdf392012-05-08 18:30:17 -0700302 memcpy(adapter->country_code, request->alpha2, sizeof(request->alpha2));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700303
304 switch (request->initiator) {
305 case NL80211_REGDOM_SET_BY_DRIVER:
306 case NL80211_REGDOM_SET_BY_CORE:
307 case NL80211_REGDOM_SET_BY_USER:
308 break;
309 /* Todo: apply driver specific changes in channel flags based
310 on the request initiator if necessary. */
311 case NL80211_REGDOM_SET_BY_COUNTRY_IE:
312 break;
313 }
314 mwifiex_send_domain_info_cmd_fw(wiphy);
315
316 return 0;
317}
318
319/*
320 * This function sets the RF channel.
321 *
322 * This function creates multiple IOCTL requests, populates them accordingly
323 * and issues them to set the band/channel and frequency.
324 */
325static int
326mwifiex_set_rf_channel(struct mwifiex_private *priv,
327 struct ieee80211_channel *chan,
328 enum nl80211_channel_type channel_type)
329{
330 struct mwifiex_chan_freq_power cfp;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700331 u32 config_bands = 0;
332 struct wiphy *wiphy = priv->wdev->wiphy;
Amitkumar Karwar43906cd2011-12-20 23:47:20 -0800333 struct mwifiex_adapter *adapter = priv->adapter;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700334
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700335 if (chan) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700336 /* Set appropriate bands */
Amitkumar Karwar3aebee02011-12-20 23:47:22 -0800337 if (chan->band == IEEE80211_BAND_2GHZ) {
338 if (channel_type == NL80211_CHAN_NO_HT)
339 if (priv->adapter->config_bands == BAND_B ||
Yogesh Ashok Powaraea07012012-03-13 19:22:35 -0700340 priv->adapter->config_bands == BAND_G)
Amitkumar Karwar3aebee02011-12-20 23:47:22 -0800341 config_bands =
342 priv->adapter->config_bands;
343 else
344 config_bands = BAND_B | BAND_G;
345 else
346 config_bands = BAND_B | BAND_G | BAND_GN;
347 } else {
348 if (channel_type == NL80211_CHAN_NO_HT)
349 config_bands = BAND_A;
350 else
351 config_bands = BAND_AN | BAND_A;
352 }
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700353
Amitkumar Karwar43906cd2011-12-20 23:47:20 -0800354 if (!((config_bands | adapter->fw_bands) &
355 ~adapter->fw_bands)) {
356 adapter->config_bands = config_bands;
357 if (priv->bss_mode == NL80211_IFTYPE_ADHOC) {
358 adapter->adhoc_start_band = config_bands;
359 if ((config_bands & BAND_GN) ||
Yogesh Ashok Powaraea07012012-03-13 19:22:35 -0700360 (config_bands & BAND_AN))
Amitkumar Karwar43906cd2011-12-20 23:47:20 -0800361 adapter->adhoc_11n_enabled = true;
362 else
363 adapter->adhoc_11n_enabled = false;
364 }
365 }
Amitkumar Karwar21c3ba32011-12-20 23:47:21 -0800366 adapter->sec_chan_offset =
367 mwifiex_cfg80211_channel_type_to_sec_chan_offset
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700368 (channel_type);
Amitkumar Karwar3aebee02011-12-20 23:47:22 -0800369 adapter->channel_type = channel_type;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700370
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700371 mwifiex_send_domain_info_cmd_fw(wiphy);
372 }
373
Yogesh Ashok Powaraea07012012-03-13 19:22:35 -0700374 wiphy_dbg(wiphy, "info: setting band %d, chan offset %d, mode %d\n",
375 config_bands, adapter->sec_chan_offset, priv->bss_mode);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700376 if (!chan)
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700377 return 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700378
379 memset(&cfp, 0, sizeof(cfp));
380 cfp.freq = chan->center_freq;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700381 cfp.channel = ieee80211_frequency_to_channel(chan->center_freq);
382
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700383 if (mwifiex_bss_set_channel(priv, &cfp))
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700384 return -EFAULT;
385
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700386 return mwifiex_drv_change_adhoc_chan(priv, cfp.channel);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700387}
388
389/*
390 * CFG802.11 operation handler to set channel.
391 *
392 * This function can only be used when station is not connected.
393 */
394static int
395mwifiex_cfg80211_set_channel(struct wiphy *wiphy, struct net_device *dev,
396 struct ieee80211_channel *chan,
397 enum nl80211_channel_type channel_type)
398{
Amitkumar Karwar477778b2012-02-01 20:41:44 -0800399 struct mwifiex_private *priv;
Avinash Patil67fdf392012-05-08 18:30:17 -0700400 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
Amitkumar Karwar477778b2012-02-01 20:41:44 -0800401
402 if (dev)
403 priv = mwifiex_netdev_get_priv(dev);
404 else
Avinash Patil67fdf392012-05-08 18:30:17 -0700405 priv = mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_STA);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700406
407 if (priv->media_connected) {
Avinash Patil67fdf392012-05-08 18:30:17 -0700408 wiphy_err(wiphy, "This is invalid in connected state\n");
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700409 return -EINVAL;
410 }
411
412 return mwifiex_set_rf_channel(priv, chan, channel_type);
413}
414
415/*
416 * This function sets the fragmentation threshold.
417 *
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700418 * The fragmentation threshold value must lie between MWIFIEX_FRAG_MIN_VALUE
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700419 * and MWIFIEX_FRAG_MAX_VALUE.
420 */
421static int
422mwifiex_set_frag(struct mwifiex_private *priv, u32 frag_thr)
423{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700424 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700425
Yogesh Ashok Powaraea07012012-03-13 19:22:35 -0700426 if (frag_thr < MWIFIEX_FRAG_MIN_VALUE ||
427 frag_thr > MWIFIEX_FRAG_MAX_VALUE)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700428 return -EINVAL;
429
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700430 /* Send request to firmware */
431 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_SNMP_MIB,
432 HostCmd_ACT_GEN_SET, FRAG_THRESH_I,
433 &frag_thr);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700434
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700435 return ret;
436}
437
438/*
439 * This function sets the RTS threshold.
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700440
441 * The rts value must lie between MWIFIEX_RTS_MIN_VALUE
442 * and MWIFIEX_RTS_MAX_VALUE.
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700443 */
444static int
445mwifiex_set_rts(struct mwifiex_private *priv, u32 rts_thr)
446{
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700447 if (rts_thr < MWIFIEX_RTS_MIN_VALUE || rts_thr > MWIFIEX_RTS_MAX_VALUE)
448 rts_thr = MWIFIEX_RTS_MAX_VALUE;
449
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700450 return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_SNMP_MIB,
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700451 HostCmd_ACT_GEN_SET, RTS_THRESH_I,
452 &rts_thr);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700453}
454
455/*
456 * CFG802.11 operation handler to set wiphy parameters.
457 *
458 * This function can be used to set the RTS threshold and the
459 * Fragmentation threshold of the driver.
460 */
461static int
462mwifiex_cfg80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
463{
Avinash Patil67fdf392012-05-08 18:30:17 -0700464 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
465 struct mwifiex_private *priv = mwifiex_get_priv(adapter,
466 MWIFIEX_BSS_ROLE_STA);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700467 int ret = 0;
468
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700469 if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700470 ret = mwifiex_set_rts(priv, wiphy->rts_threshold);
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700471 if (ret)
472 return ret;
473 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700474
475 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
476 ret = mwifiex_set_frag(priv, wiphy->frag_threshold);
477
478 return ret;
479}
480
481/*
482 * CFG802.11 operation handler to change interface type.
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700483 */
484static int
485mwifiex_cfg80211_change_virtual_intf(struct wiphy *wiphy,
486 struct net_device *dev,
487 enum nl80211_iftype type, u32 *flags,
488 struct vif_params *params)
489{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700490 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700491 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
Bing Zhaoeecd8252011-03-28 17:55:41 -0700492
493 if (priv->bss_mode == type) {
494 wiphy_warn(wiphy, "already set to required type\n");
495 return 0;
496 }
497
498 priv->bss_mode = type;
499
500 switch (type) {
501 case NL80211_IFTYPE_ADHOC:
502 dev->ieee80211_ptr->iftype = NL80211_IFTYPE_ADHOC;
503 wiphy_dbg(wiphy, "info: setting interface type to adhoc\n");
504 break;
505 case NL80211_IFTYPE_STATION:
506 dev->ieee80211_ptr->iftype = NL80211_IFTYPE_STATION;
507 wiphy_dbg(wiphy, "info: setting interface type to managed\n");
508 break;
509 case NL80211_IFTYPE_UNSPECIFIED:
510 dev->ieee80211_ptr->iftype = NL80211_IFTYPE_STATION;
511 wiphy_dbg(wiphy, "info: setting interface type to auto\n");
512 return 0;
513 default:
514 wiphy_err(wiphy, "unknown interface type: %d\n", type);
515 return -EINVAL;
516 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700517
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700518 mwifiex_deauthenticate(priv, NULL);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700519
Marc Yangf986b6d2011-03-28 17:55:42 -0700520 priv->sec_info.authentication_mode = NL80211_AUTHTYPE_OPEN_SYSTEM;
Bing Zhaoeecd8252011-03-28 17:55:41 -0700521
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700522 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_SET_BSS_MODE,
523 HostCmd_ACT_GEN_SET, 0, NULL);
Bing Zhaoeecd8252011-03-28 17:55:41 -0700524
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700525 return ret;
526}
527
528/*
529 * This function dumps the station information on a buffer.
530 *
531 * The following information are shown -
532 * - Total bytes transmitted
533 * - Total bytes received
534 * - Total packets transmitted
535 * - Total packets received
536 * - Signal quality level
537 * - Transmission rate
538 */
539static int
540mwifiex_dump_station_info(struct mwifiex_private *priv,
541 struct station_info *sinfo)
542{
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700543 struct mwifiex_rate_cfg rate;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700544
545 sinfo->filled = STATION_INFO_RX_BYTES | STATION_INFO_TX_BYTES |
Amitkumar Karwar7013d3e2012-03-15 20:51:50 -0700546 STATION_INFO_RX_PACKETS | STATION_INFO_TX_PACKETS |
547 STATION_INFO_TX_BITRATE |
548 STATION_INFO_SIGNAL | STATION_INFO_SIGNAL_AVG;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700549
550 /* Get signal information from the firmware */
Amitkumar Karwar958a4a82012-03-15 20:51:49 -0700551 if (mwifiex_send_cmd_sync(priv, HostCmd_CMD_RSSI_INFO,
552 HostCmd_ACT_GEN_GET, 0, NULL)) {
553 dev_err(priv->adapter->dev, "failed to get signal information\n");
554 return -EFAULT;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700555 }
556
557 if (mwifiex_drv_get_data_rate(priv, &rate)) {
558 dev_err(priv->adapter->dev, "getting data rate\n");
Amitkumar Karwar958a4a82012-03-15 20:51:49 -0700559 return -EFAULT;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700560 }
561
Amitkumar Karwarcaf60a62012-02-02 20:48:58 -0800562 /* Get DTIM period information from firmware */
563 mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_SNMP_MIB,
564 HostCmd_ACT_GEN_GET, DTIM_PERIOD_I,
565 &priv->dtim_period);
566
Amitkumar Karwar4ec6f9c2011-09-26 20:37:25 -0700567 /*
568 * Bit 0 in tx_htinfo indicates that current Tx rate is 11n rate. Valid
569 * MCS index values for us are 0 to 7.
570 */
571 if ((priv->tx_htinfo & BIT(0)) && (priv->tx_rate < 8)) {
572 sinfo->txrate.mcs = priv->tx_rate;
573 sinfo->txrate.flags |= RATE_INFO_FLAGS_MCS;
574 /* 40MHz rate */
575 if (priv->tx_htinfo & BIT(1))
576 sinfo->txrate.flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
577 /* SGI enabled */
578 if (priv->tx_htinfo & BIT(2))
579 sinfo->txrate.flags |= RATE_INFO_FLAGS_SHORT_GI;
580 }
581
Amitkumar Karwar7013d3e2012-03-15 20:51:50 -0700582 sinfo->signal_avg = priv->bcn_rssi_avg;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700583 sinfo->rx_bytes = priv->stats.rx_bytes;
584 sinfo->tx_bytes = priv->stats.tx_bytes;
585 sinfo->rx_packets = priv->stats.rx_packets;
586 sinfo->tx_packets = priv->stats.tx_packets;
Amitkumar Karwar958a4a82012-03-15 20:51:49 -0700587 sinfo->signal = priv->bcn_rssi_avg;
Amitkumar Karwar4ec6f9c2011-09-26 20:37:25 -0700588 /* bit rate is in 500 kb/s units. Convert it to 100kb/s units */
589 sinfo->txrate.legacy = rate.rate * 5;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700590
Amitkumar Karwarc4f3b972012-01-24 20:50:25 -0800591 if (priv->bss_mode == NL80211_IFTYPE_STATION) {
592 sinfo->filled |= STATION_INFO_BSS_PARAM;
593 sinfo->bss_param.flags = 0;
594 if (priv->curr_bss_params.bss_descriptor.cap_info_bitmap &
595 WLAN_CAPABILITY_SHORT_PREAMBLE)
596 sinfo->bss_param.flags |=
597 BSS_PARAM_FLAGS_SHORT_PREAMBLE;
598 if (priv->curr_bss_params.bss_descriptor.cap_info_bitmap &
599 WLAN_CAPABILITY_SHORT_SLOT_TIME)
600 sinfo->bss_param.flags |=
601 BSS_PARAM_FLAGS_SHORT_SLOT_TIME;
Amitkumar Karwarcaf60a62012-02-02 20:48:58 -0800602 sinfo->bss_param.dtim_period = priv->dtim_period;
Amitkumar Karwarc4f3b972012-01-24 20:50:25 -0800603 sinfo->bss_param.beacon_interval =
604 priv->curr_bss_params.bss_descriptor.beacon_period;
605 }
606
Amitkumar Karwar958a4a82012-03-15 20:51:49 -0700607 return 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700608}
609
610/*
611 * CFG802.11 operation handler to get station information.
612 *
613 * This function only works in connected mode, and dumps the
614 * requested station information, if available.
615 */
616static int
617mwifiex_cfg80211_get_station(struct wiphy *wiphy, struct net_device *dev,
618 u8 *mac, struct station_info *sinfo)
619{
620 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700621
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700622 if (!priv->media_connected)
623 return -ENOENT;
624 if (memcmp(mac, priv->cfg_bssid, ETH_ALEN))
625 return -ENOENT;
626
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700627 return mwifiex_dump_station_info(priv, sinfo);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700628}
629
Amitkumar Karwarf85aae62012-03-15 20:51:48 -0700630/*
631 * CFG802.11 operation handler to dump station information.
632 */
633static int
634mwifiex_cfg80211_dump_station(struct wiphy *wiphy, struct net_device *dev,
635 int idx, u8 *mac, struct station_info *sinfo)
636{
637 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
638
639 if (!priv->media_connected || idx)
640 return -ENOENT;
641
642 memcpy(mac, priv->cfg_bssid, ETH_ALEN);
643
644 return mwifiex_dump_station_info(priv, sinfo);
645}
646
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700647/* Supported rates to be advertised to the cfg80211 */
648
649static struct ieee80211_rate mwifiex_rates[] = {
650 {.bitrate = 10, .hw_value = 2, },
651 {.bitrate = 20, .hw_value = 4, },
652 {.bitrate = 55, .hw_value = 11, },
653 {.bitrate = 110, .hw_value = 22, },
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700654 {.bitrate = 60, .hw_value = 12, },
655 {.bitrate = 90, .hw_value = 18, },
656 {.bitrate = 120, .hw_value = 24, },
657 {.bitrate = 180, .hw_value = 36, },
658 {.bitrate = 240, .hw_value = 48, },
659 {.bitrate = 360, .hw_value = 72, },
660 {.bitrate = 480, .hw_value = 96, },
661 {.bitrate = 540, .hw_value = 108, },
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700662};
663
664/* Channel definitions to be advertised to cfg80211 */
665
666static struct ieee80211_channel mwifiex_channels_2ghz[] = {
667 {.center_freq = 2412, .hw_value = 1, },
668 {.center_freq = 2417, .hw_value = 2, },
669 {.center_freq = 2422, .hw_value = 3, },
670 {.center_freq = 2427, .hw_value = 4, },
671 {.center_freq = 2432, .hw_value = 5, },
672 {.center_freq = 2437, .hw_value = 6, },
673 {.center_freq = 2442, .hw_value = 7, },
674 {.center_freq = 2447, .hw_value = 8, },
675 {.center_freq = 2452, .hw_value = 9, },
676 {.center_freq = 2457, .hw_value = 10, },
677 {.center_freq = 2462, .hw_value = 11, },
678 {.center_freq = 2467, .hw_value = 12, },
679 {.center_freq = 2472, .hw_value = 13, },
680 {.center_freq = 2484, .hw_value = 14, },
681};
682
683static struct ieee80211_supported_band mwifiex_band_2ghz = {
684 .channels = mwifiex_channels_2ghz,
685 .n_channels = ARRAY_SIZE(mwifiex_channels_2ghz),
686 .bitrates = mwifiex_rates,
Amitkumar Karwar87638482012-03-07 19:36:07 -0800687 .n_bitrates = ARRAY_SIZE(mwifiex_rates),
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700688};
689
690static struct ieee80211_channel mwifiex_channels_5ghz[] = {
691 {.center_freq = 5040, .hw_value = 8, },
692 {.center_freq = 5060, .hw_value = 12, },
693 {.center_freq = 5080, .hw_value = 16, },
694 {.center_freq = 5170, .hw_value = 34, },
695 {.center_freq = 5190, .hw_value = 38, },
696 {.center_freq = 5210, .hw_value = 42, },
697 {.center_freq = 5230, .hw_value = 46, },
698 {.center_freq = 5180, .hw_value = 36, },
699 {.center_freq = 5200, .hw_value = 40, },
700 {.center_freq = 5220, .hw_value = 44, },
701 {.center_freq = 5240, .hw_value = 48, },
702 {.center_freq = 5260, .hw_value = 52, },
703 {.center_freq = 5280, .hw_value = 56, },
704 {.center_freq = 5300, .hw_value = 60, },
705 {.center_freq = 5320, .hw_value = 64, },
706 {.center_freq = 5500, .hw_value = 100, },
707 {.center_freq = 5520, .hw_value = 104, },
708 {.center_freq = 5540, .hw_value = 108, },
709 {.center_freq = 5560, .hw_value = 112, },
710 {.center_freq = 5580, .hw_value = 116, },
711 {.center_freq = 5600, .hw_value = 120, },
712 {.center_freq = 5620, .hw_value = 124, },
713 {.center_freq = 5640, .hw_value = 128, },
714 {.center_freq = 5660, .hw_value = 132, },
715 {.center_freq = 5680, .hw_value = 136, },
716 {.center_freq = 5700, .hw_value = 140, },
717 {.center_freq = 5745, .hw_value = 149, },
718 {.center_freq = 5765, .hw_value = 153, },
719 {.center_freq = 5785, .hw_value = 157, },
720 {.center_freq = 5805, .hw_value = 161, },
721 {.center_freq = 5825, .hw_value = 165, },
722};
723
724static struct ieee80211_supported_band mwifiex_band_5ghz = {
725 .channels = mwifiex_channels_5ghz,
726 .n_channels = ARRAY_SIZE(mwifiex_channels_5ghz),
Avinash Patileb416ad2012-02-27 22:04:11 -0800727 .bitrates = mwifiex_rates + 4,
728 .n_bitrates = ARRAY_SIZE(mwifiex_rates) - 4,
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700729};
730
731
732/* Supported crypto cipher suits to be advertised to cfg80211 */
733
734static const u32 mwifiex_cipher_suites[] = {
735 WLAN_CIPHER_SUITE_WEP40,
736 WLAN_CIPHER_SUITE_WEP104,
737 WLAN_CIPHER_SUITE_TKIP,
738 WLAN_CIPHER_SUITE_CCMP,
739};
740
741/*
Yogesh Ashok Powar5d82c532011-07-11 20:04:44 -0700742 * CFG802.11 operation handler for setting bit rates.
743 *
744 * Function selects legacy bang B/G/BG from corresponding bitrates selection.
745 * Currently only 2.4GHz band is supported.
746 */
747static int mwifiex_cfg80211_set_bitrate_mask(struct wiphy *wiphy,
748 struct net_device *dev,
749 const u8 *peer,
750 const struct cfg80211_bitrate_mask *mask)
751{
Yogesh Ashok Powar5d82c532011-07-11 20:04:44 -0700752 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
753 int index = 0, mode = 0, i;
Amitkumar Karwar43906cd2011-12-20 23:47:20 -0800754 struct mwifiex_adapter *adapter = priv->adapter;
Yogesh Ashok Powar5d82c532011-07-11 20:04:44 -0700755
756 /* Currently only 2.4GHz is supported */
757 for (i = 0; i < mwifiex_band_2ghz.n_bitrates; i++) {
758 /*
759 * Rates below 6 Mbps in the table are CCK rates; 802.11b
760 * and from 6 they are OFDM; 802.11G
761 */
762 if (mwifiex_rates[i].bitrate == 60) {
763 index = 1 << i;
764 break;
765 }
766 }
767
768 if (mask->control[IEEE80211_BAND_2GHZ].legacy < index) {
769 mode = BAND_B;
770 } else {
771 mode = BAND_G;
772 if (mask->control[IEEE80211_BAND_2GHZ].legacy % index)
773 mode |= BAND_B;
774 }
775
Amitkumar Karwar43906cd2011-12-20 23:47:20 -0800776 if (!((mode | adapter->fw_bands) & ~adapter->fw_bands)) {
777 adapter->config_bands = mode;
778 if (priv->bss_mode == NL80211_IFTYPE_ADHOC) {
779 adapter->adhoc_start_band = mode;
780 adapter->adhoc_11n_enabled = false;
781 }
782 }
Amitkumar Karwar21c3ba32011-12-20 23:47:21 -0800783 adapter->sec_chan_offset = IEEE80211_HT_PARAM_CHA_SEC_NONE;
Amitkumar Karwar3aebee02011-12-20 23:47:22 -0800784 adapter->channel_type = NL80211_CHAN_NO_HT;
Yogesh Ashok Powar5d82c532011-07-11 20:04:44 -0700785
786 wiphy_debug(wiphy, "info: device configured in 802.11%s%s mode\n",
Yogesh Ashok Powaraea07012012-03-13 19:22:35 -0700787 (mode & BAND_B) ? "b" : "", (mode & BAND_G) ? "g" : "");
Yogesh Ashok Powar5d82c532011-07-11 20:04:44 -0700788
789 return 0;
790}
791
792/*
Amitkumar Karwarfa444bf2012-03-15 20:51:51 -0700793 * CFG802.11 operation handler for connection quality monitoring.
794 *
795 * This function subscribes/unsubscribes HIGH_RSSI and LOW_RSSI
796 * events to FW.
797 */
798static int mwifiex_cfg80211_set_cqm_rssi_config(struct wiphy *wiphy,
799 struct net_device *dev,
800 s32 rssi_thold, u32 rssi_hyst)
801{
802 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
803 struct mwifiex_ds_misc_subsc_evt subsc_evt;
804
805 priv->cqm_rssi_thold = rssi_thold;
806 priv->cqm_rssi_hyst = rssi_hyst;
807
808 memset(&subsc_evt, 0x00, sizeof(struct mwifiex_ds_misc_subsc_evt));
809 subsc_evt.events = BITMASK_BCN_RSSI_LOW | BITMASK_BCN_RSSI_HIGH;
810
811 /* Subscribe/unsubscribe low and high rssi events */
812 if (rssi_thold && rssi_hyst) {
813 subsc_evt.action = HostCmd_ACT_BITWISE_SET;
814 subsc_evt.bcn_l_rssi_cfg.abs_value = abs(rssi_thold);
815 subsc_evt.bcn_h_rssi_cfg.abs_value = abs(rssi_thold);
816 subsc_evt.bcn_l_rssi_cfg.evt_freq = 1;
817 subsc_evt.bcn_h_rssi_cfg.evt_freq = 1;
818 return mwifiex_send_cmd_sync(priv,
819 HostCmd_CMD_802_11_SUBSCRIBE_EVENT,
820 0, 0, &subsc_evt);
821 } else {
822 subsc_evt.action = HostCmd_ACT_BITWISE_CLR;
823 return mwifiex_send_cmd_sync(priv,
824 HostCmd_CMD_802_11_SUBSCRIBE_EVENT,
825 0, 0, &subsc_evt);
826 }
827
828 return 0;
829}
830
831/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700832 * CFG802.11 operation handler for disconnection request.
833 *
834 * This function does not work when there is already a disconnection
835 * procedure going on.
836 */
837static int
838mwifiex_cfg80211_disconnect(struct wiphy *wiphy, struct net_device *dev,
839 u16 reason_code)
840{
841 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
842
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700843 if (mwifiex_deauthenticate(priv, NULL))
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700844 return -EFAULT;
845
846 wiphy_dbg(wiphy, "info: successfully disconnected from %pM:"
847 " reason code %d\n", priv->cfg_bssid, reason_code);
848
Amitkumar Karwar38c9d662011-12-13 20:43:17 -0800849 memset(priv->cfg_bssid, 0, ETH_ALEN);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700850
851 return 0;
852}
853
854/*
855 * This function informs the CFG802.11 subsystem of a new IBSS.
856 *
857 * The following information are sent to the CFG802.11 subsystem
858 * to register the new IBSS. If we do not register the new IBSS,
859 * a kernel panic will result.
860 * - SSID
861 * - SSID length
862 * - BSSID
863 * - Channel
864 */
865static int mwifiex_cfg80211_inform_ibss_bss(struct mwifiex_private *priv)
866{
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700867 struct ieee80211_channel *chan;
868 struct mwifiex_bss_info bss_info;
Amitkumar Karwaraa95a482011-11-07 21:41:12 -0800869 struct cfg80211_bss *bss;
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700870 int ie_len;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700871 u8 ie_buf[IEEE80211_MAX_SSID_LEN + sizeof(struct ieee_types_header)];
Amitkumar Karwar4ed5d522011-09-21 21:43:24 -0700872 enum ieee80211_band band;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700873
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700874 if (mwifiex_get_bss_info(priv, &bss_info))
875 return -1;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700876
877 ie_buf[0] = WLAN_EID_SSID;
878 ie_buf[1] = bss_info.ssid.ssid_len;
879
880 memcpy(&ie_buf[sizeof(struct ieee_types_header)],
Yogesh Ashok Powaraea07012012-03-13 19:22:35 -0700881 &bss_info.ssid.ssid, bss_info.ssid.ssid_len);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700882 ie_len = ie_buf[1] + sizeof(struct ieee_types_header);
883
Amitkumar Karwar4ed5d522011-09-21 21:43:24 -0700884 band = mwifiex_band_to_radio_type(priv->curr_bss_params.band);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700885 chan = __ieee80211_get_channel(priv->wdev->wiphy,
886 ieee80211_channel_to_frequency(bss_info.bss_chan,
Amitkumar Karwar4ed5d522011-09-21 21:43:24 -0700887 band));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700888
Amitkumar Karwaraa95a482011-11-07 21:41:12 -0800889 bss = cfg80211_inform_bss(priv->wdev->wiphy, chan,
Yogesh Ashok Powaraea07012012-03-13 19:22:35 -0700890 bss_info.bssid, 0, WLAN_CAPABILITY_IBSS,
891 0, ie_buf, ie_len, 0, GFP_KERNEL);
Amitkumar Karwaraa95a482011-11-07 21:41:12 -0800892 cfg80211_put_bss(bss);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700893 memcpy(priv->cfg_bssid, bss_info.bssid, ETH_ALEN);
894
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700895 return 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700896}
897
898/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700899 * This function connects with a BSS.
900 *
901 * This function handles both Infra and Ad-Hoc modes. It also performs
902 * validity checking on the provided parameters, disconnects from the
903 * current BSS (if any), sets up the association/scan parameters,
904 * including security settings, and performs specific SSID scan before
905 * trying to connect.
906 *
907 * For Infra mode, the function returns failure if the specified SSID
908 * is not found in scan table. However, for Ad-Hoc mode, it can create
909 * the IBSS if it does not exist. On successful completion in either case,
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700910 * the function notifies the CFG802.11 subsystem of the new BSS connection.
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700911 */
912static int
913mwifiex_cfg80211_assoc(struct mwifiex_private *priv, size_t ssid_len, u8 *ssid,
914 u8 *bssid, int mode, struct ieee80211_channel *channel,
915 struct cfg80211_connect_params *sme, bool privacy)
916{
Amitkumar Karwarb9be5f32012-02-27 22:04:14 -0800917 struct cfg80211_ssid req_ssid;
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700918 int ret, auth_type = 0;
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700919 struct cfg80211_bss *bss = NULL;
920 u8 is_scanning_required = 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700921
Amitkumar Karwarb9be5f32012-02-27 22:04:14 -0800922 memset(&req_ssid, 0, sizeof(struct cfg80211_ssid));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700923
924 req_ssid.ssid_len = ssid_len;
925 if (ssid_len > IEEE80211_MAX_SSID_LEN) {
926 dev_err(priv->adapter->dev, "invalid SSID - aborting\n");
927 return -EINVAL;
928 }
929
930 memcpy(req_ssid.ssid, ssid, ssid_len);
931 if (!req_ssid.ssid_len || req_ssid.ssid[0] < 0x20) {
932 dev_err(priv->adapter->dev, "invalid SSID - aborting\n");
933 return -EINVAL;
934 }
935
936 /* disconnect before try to associate */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700937 mwifiex_deauthenticate(priv, NULL);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700938
939 if (channel)
940 ret = mwifiex_set_rf_channel(priv, channel,
Amitkumar Karwar3aebee02011-12-20 23:47:22 -0800941 priv->adapter->channel_type);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700942
Amitkumar Karwar6670f152012-02-09 18:32:22 -0800943 /* As this is new association, clear locally stored
944 * keys and security related flags */
945 priv->sec_info.wpa_enabled = false;
946 priv->sec_info.wpa2_enabled = false;
947 priv->wep_key_curr_index = 0;
Amitkumar Karwar00f157b2012-02-24 21:35:35 -0800948 priv->sec_info.encryption_mode = 0;
Amitkumar Karwara0f6d6c2012-02-24 21:36:05 -0800949 priv->sec_info.is_authtype_auto = 0;
Amitkumar Karwar6670f152012-02-09 18:32:22 -0800950 ret = mwifiex_set_encode(priv, NULL, 0, 0, 1);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700951
Bing Zhaoeecd8252011-03-28 17:55:41 -0700952 if (mode == NL80211_IFTYPE_ADHOC) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700953 /* "privacy" is set only for ad-hoc mode */
954 if (privacy) {
955 /*
Yogesh Ashok Powar2be50b82011-04-01 18:36:47 -0700956 * Keep WLAN_CIPHER_SUITE_WEP104 for now so that
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700957 * the firmware can find a matching network from the
958 * scan. The cfg80211 does not give us the encryption
959 * mode at this stage so just setting it to WEP here.
960 */
Marc Yang203afec2011-03-24 20:49:39 -0700961 priv->sec_info.encryption_mode =
Yogesh Ashok Powar2be50b82011-04-01 18:36:47 -0700962 WLAN_CIPHER_SUITE_WEP104;
Marc Yang203afec2011-03-24 20:49:39 -0700963 priv->sec_info.authentication_mode =
Marc Yangf986b6d2011-03-28 17:55:42 -0700964 NL80211_AUTHTYPE_OPEN_SYSTEM;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700965 }
966
967 goto done;
968 }
969
970 /* Now handle infra mode. "sme" is valid for infra mode only */
Amitkumar Karwara0f6d6c2012-02-24 21:36:05 -0800971 if (sme->auth_type == NL80211_AUTHTYPE_AUTOMATIC) {
Marc Yangf986b6d2011-03-28 17:55:42 -0700972 auth_type = NL80211_AUTHTYPE_OPEN_SYSTEM;
Amitkumar Karwara0f6d6c2012-02-24 21:36:05 -0800973 priv->sec_info.is_authtype_auto = 1;
974 } else {
975 auth_type = sme->auth_type;
976 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700977
978 if (sme->crypto.n_ciphers_pairwise) {
Yogesh Ashok Powar2be50b82011-04-01 18:36:47 -0700979 priv->sec_info.encryption_mode =
980 sme->crypto.ciphers_pairwise[0];
Marc Yang203afec2011-03-24 20:49:39 -0700981 priv->sec_info.authentication_mode = auth_type;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700982 }
983
984 if (sme->crypto.cipher_group) {
Yogesh Ashok Powar2be50b82011-04-01 18:36:47 -0700985 priv->sec_info.encryption_mode = sme->crypto.cipher_group;
Marc Yang203afec2011-03-24 20:49:39 -0700986 priv->sec_info.authentication_mode = auth_type;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700987 }
988 if (sme->ie)
989 ret = mwifiex_set_gen_ie(priv, sme->ie, sme->ie_len);
990
991 if (sme->key) {
Amitkumar Karware6faada2011-07-07 17:33:19 -0700992 if (mwifiex_is_alg_wep(priv->sec_info.encryption_mode)) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700993 dev_dbg(priv->adapter->dev,
994 "info: setting wep encryption"
995 " with key len %d\n", sme->key_len);
Amitkumar Karwar6670f152012-02-09 18:32:22 -0800996 priv->wep_key_curr_index = sme->key_idx;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700997 ret = mwifiex_set_encode(priv, sme->key, sme->key_len,
998 sme->key_idx, 0);
999 }
1000 }
1001done:
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001002 /*
1003 * Scan entries are valid for some time (15 sec). So we can save one
1004 * active scan time if we just try cfg80211_get_bss first. If it fails
1005 * then request scan and cfg80211_get_bss() again for final output.
1006 */
1007 while (1) {
1008 if (is_scanning_required) {
1009 /* Do specific SSID scanning */
1010 if (mwifiex_request_scan(priv, &req_ssid)) {
1011 dev_err(priv->adapter->dev, "scan error\n");
1012 return -EFAULT;
1013 }
1014 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001015
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001016 /* Find the BSS we want using available scan results */
1017 if (mode == NL80211_IFTYPE_ADHOC)
1018 bss = cfg80211_get_bss(priv->wdev->wiphy, channel,
1019 bssid, ssid, ssid_len,
1020 WLAN_CAPABILITY_IBSS,
1021 WLAN_CAPABILITY_IBSS);
1022 else
1023 bss = cfg80211_get_bss(priv->wdev->wiphy, channel,
1024 bssid, ssid, ssid_len,
1025 WLAN_CAPABILITY_ESS,
1026 WLAN_CAPABILITY_ESS);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001027
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001028 if (!bss) {
1029 if (is_scanning_required) {
Yogesh Ashok Powaraea07012012-03-13 19:22:35 -07001030 dev_warn(priv->adapter->dev,
1031 "assoc: requested bss not found in scan results\n");
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001032 break;
1033 }
1034 is_scanning_required = 1;
1035 } else {
Yogesh Ashok Powaraea07012012-03-13 19:22:35 -07001036 dev_dbg(priv->adapter->dev,
1037 "info: trying to associate to '%s' bssid %pM\n",
1038 (char *) req_ssid.ssid, bss->bssid);
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001039 memcpy(&priv->cfg_bssid, bss->bssid, ETH_ALEN);
1040 break;
1041 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001042 }
1043
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001044 if (mwifiex_bss_start(priv, bss, &req_ssid))
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001045 return -EFAULT;
1046
Bing Zhaoeecd8252011-03-28 17:55:41 -07001047 if (mode == NL80211_IFTYPE_ADHOC) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001048 /* Inform the BSS information to kernel, otherwise
1049 * kernel will give a panic after successful assoc */
1050 if (mwifiex_cfg80211_inform_ibss_bss(priv))
1051 return -EFAULT;
1052 }
1053
1054 return ret;
1055}
1056
1057/*
1058 * CFG802.11 operation handler for association request.
1059 *
1060 * This function does not work when the current mode is set to Ad-Hoc, or
1061 * when there is already an association procedure going on. The given BSS
1062 * information is used to associate.
1063 */
1064static int
1065mwifiex_cfg80211_connect(struct wiphy *wiphy, struct net_device *dev,
1066 struct cfg80211_connect_params *sme)
1067{
1068 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
1069 int ret = 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001070
Bing Zhaoeecd8252011-03-28 17:55:41 -07001071 if (priv->bss_mode == NL80211_IFTYPE_ADHOC) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001072 wiphy_err(wiphy, "received infra assoc request "
1073 "when station is in ibss mode\n");
1074 goto done;
1075 }
1076
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001077 wiphy_dbg(wiphy, "info: Trying to associate to %s and bssid %pM\n",
Yogesh Ashok Powaraea07012012-03-13 19:22:35 -07001078 (char *) sme->ssid, sme->bssid);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001079
1080 ret = mwifiex_cfg80211_assoc(priv, sme->ssid_len, sme->ssid, sme->bssid,
Bing Zhaoeecd8252011-03-28 17:55:41 -07001081 priv->bss_mode, sme->channel, sme, 0);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001082done:
Amitkumar Karwar38c9d662011-12-13 20:43:17 -08001083 if (!ret) {
1084 cfg80211_connect_result(priv->netdev, priv->cfg_bssid, NULL, 0,
1085 NULL, 0, WLAN_STATUS_SUCCESS,
1086 GFP_KERNEL);
1087 dev_dbg(priv->adapter->dev,
1088 "info: associated to bssid %pM successfully\n",
1089 priv->cfg_bssid);
1090 } else {
1091 dev_dbg(priv->adapter->dev,
1092 "info: association to bssid %pM failed\n",
1093 priv->cfg_bssid);
1094 memset(priv->cfg_bssid, 0, ETH_ALEN);
1095 }
1096
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001097 return ret;
1098}
1099
1100/*
1101 * CFG802.11 operation handler to join an IBSS.
1102 *
1103 * This function does not work in any mode other than Ad-Hoc, or if
1104 * a join operation is already in progress.
1105 */
1106static int
1107mwifiex_cfg80211_join_ibss(struct wiphy *wiphy, struct net_device *dev,
1108 struct cfg80211_ibss_params *params)
1109{
Yogesh Ashok Powarf540f9f2012-01-11 20:06:12 -08001110 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001111 int ret = 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001112
Bing Zhaoeecd8252011-03-28 17:55:41 -07001113 if (priv->bss_mode != NL80211_IFTYPE_ADHOC) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001114 wiphy_err(wiphy, "request to join ibss received "
1115 "when station is not in ibss mode\n");
1116 goto done;
1117 }
1118
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001119 wiphy_dbg(wiphy, "info: trying to join to %s and bssid %pM\n",
Yogesh Ashok Powaraea07012012-03-13 19:22:35 -07001120 (char *) params->ssid, params->bssid);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001121
1122 ret = mwifiex_cfg80211_assoc(priv, params->ssid_len, params->ssid,
Yogesh Ashok Powaraea07012012-03-13 19:22:35 -07001123 params->bssid, priv->bss_mode,
1124 params->channel, NULL, params->privacy);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001125done:
Amitkumar Karwar38c9d662011-12-13 20:43:17 -08001126 if (!ret) {
1127 cfg80211_ibss_joined(priv->netdev, priv->cfg_bssid, GFP_KERNEL);
1128 dev_dbg(priv->adapter->dev,
1129 "info: joined/created adhoc network with bssid"
1130 " %pM successfully\n", priv->cfg_bssid);
1131 } else {
1132 dev_dbg(priv->adapter->dev,
1133 "info: failed creating/joining adhoc network\n");
1134 }
1135
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001136 return ret;
1137}
1138
1139/*
1140 * CFG802.11 operation handler to leave an IBSS.
1141 *
1142 * This function does not work if a leave operation is
1143 * already in progress.
1144 */
1145static int
1146mwifiex_cfg80211_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
1147{
Yogesh Ashok Powarf540f9f2012-01-11 20:06:12 -08001148 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001149
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001150 wiphy_dbg(wiphy, "info: disconnecting from essid %pM\n",
Yogesh Ashok Powaraea07012012-03-13 19:22:35 -07001151 priv->cfg_bssid);
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001152 if (mwifiex_deauthenticate(priv, NULL))
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001153 return -EFAULT;
1154
Amitkumar Karwar38c9d662011-12-13 20:43:17 -08001155 memset(priv->cfg_bssid, 0, ETH_ALEN);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001156
1157 return 0;
1158}
1159
1160/*
1161 * CFG802.11 operation handler for scan request.
1162 *
1163 * This function issues a scan request to the firmware based upon
1164 * the user specified scan configuration. On successfull completion,
1165 * it also informs the results.
1166 */
1167static int
1168mwifiex_cfg80211_scan(struct wiphy *wiphy, struct net_device *dev,
1169 struct cfg80211_scan_request *request)
1170{
1171 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
Amitkumar Karwar38c9d662011-12-13 20:43:17 -08001172 int i;
1173 struct ieee80211_channel *chan;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001174
1175 wiphy_dbg(wiphy, "info: received scan request on %s\n", dev->name);
1176
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001177 priv->scan_request = request;
1178
Amitkumar Karwar38c9d662011-12-13 20:43:17 -08001179 priv->user_scan_cfg = kzalloc(sizeof(struct mwifiex_user_scan_cfg),
Yogesh Ashok Powaraea07012012-03-13 19:22:35 -07001180 GFP_KERNEL);
Amitkumar Karwar38c9d662011-12-13 20:43:17 -08001181 if (!priv->user_scan_cfg) {
1182 dev_err(priv->adapter->dev, "failed to alloc scan_req\n");
1183 return -ENOMEM;
1184 }
Amitkumar Karwarbe0b2812012-02-27 22:04:15 -08001185
1186 priv->user_scan_cfg->num_ssids = request->n_ssids;
1187 priv->user_scan_cfg->ssid_list = request->ssids;
1188
Avinash Patil13d7ba782012-04-09 20:06:56 -07001189 if (request->ie && request->ie_len) {
1190 for (i = 0; i < MWIFIEX_MAX_VSIE_NUM; i++) {
1191 if (priv->vs_ie[i].mask != MWIFIEX_VSIE_MASK_CLEAR)
1192 continue;
1193 priv->vs_ie[i].mask = MWIFIEX_VSIE_MASK_SCAN;
1194 memcpy(&priv->vs_ie[i].ie, request->ie,
1195 request->ie_len);
1196 break;
1197 }
1198 }
1199
Amitkumar Karwar38c9d662011-12-13 20:43:17 -08001200 for (i = 0; i < request->n_channels; i++) {
1201 chan = request->channels[i];
1202 priv->user_scan_cfg->chan_list[i].chan_number = chan->hw_value;
1203 priv->user_scan_cfg->chan_list[i].radio_type = chan->band;
1204
1205 if (chan->flags & IEEE80211_CHAN_PASSIVE_SCAN)
1206 priv->user_scan_cfg->chan_list[i].scan_type =
Yogesh Ashok Powaraea07012012-03-13 19:22:35 -07001207 MWIFIEX_SCAN_TYPE_PASSIVE;
Amitkumar Karwar38c9d662011-12-13 20:43:17 -08001208 else
1209 priv->user_scan_cfg->chan_list[i].scan_type =
Yogesh Ashok Powaraea07012012-03-13 19:22:35 -07001210 MWIFIEX_SCAN_TYPE_ACTIVE;
Amitkumar Karwar38c9d662011-12-13 20:43:17 -08001211
1212 priv->user_scan_cfg->chan_list[i].scan_time = 0;
1213 }
1214 if (mwifiex_set_user_scan_ioctl(priv, priv->user_scan_cfg))
1215 return -EFAULT;
1216
Avinash Patil13d7ba782012-04-09 20:06:56 -07001217 if (request->ie && request->ie_len) {
1218 for (i = 0; i < MWIFIEX_MAX_VSIE_NUM; i++) {
1219 if (priv->vs_ie[i].mask == MWIFIEX_VSIE_MASK_SCAN) {
1220 priv->vs_ie[i].mask = MWIFIEX_VSIE_MASK_CLEAR;
1221 memset(&priv->vs_ie[i].ie, 0,
1222 MWIFIEX_MAX_VSIE_LEN);
1223 }
1224 }
1225 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001226 return 0;
1227}
1228
1229/*
1230 * This function sets up the CFG802.11 specific HT capability fields
1231 * with default values.
1232 *
1233 * The following default values are set -
1234 * - HT Supported = True
Amitkumar Karwara46b7b52011-04-27 19:13:12 -07001235 * - Maximum AMPDU length factor = IEEE80211_HT_MAX_AMPDU_64K
1236 * - Minimum AMPDU spacing = IEEE80211_HT_MPDU_DENSITY_NONE
1237 * - HT Capabilities supported by firmware
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001238 * - MCS information, Rx mask = 0xff
1239 * - MCD information, Tx parameters = IEEE80211_HT_MCS_TX_DEFINED (0x01)
1240 */
1241static void
1242mwifiex_setup_ht_caps(struct ieee80211_sta_ht_cap *ht_info,
1243 struct mwifiex_private *priv)
1244{
1245 int rx_mcs_supp;
1246 struct ieee80211_mcs_info mcs_set;
1247 u8 *mcs = (u8 *)&mcs_set;
1248 struct mwifiex_adapter *adapter = priv->adapter;
1249
1250 ht_info->ht_supported = true;
Amitkumar Karwara46b7b52011-04-27 19:13:12 -07001251 ht_info->ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
1252 ht_info->ampdu_density = IEEE80211_HT_MPDU_DENSITY_NONE;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001253
1254 memset(&ht_info->mcs, 0, sizeof(ht_info->mcs));
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001255
Amitkumar Karwara46b7b52011-04-27 19:13:12 -07001256 /* Fill HT capability information */
1257 if (ISSUPP_CHANWIDTH40(adapter->hw_dot_11n_dev_cap))
1258 ht_info->cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
1259 else
1260 ht_info->cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
1261
1262 if (ISSUPP_SHORTGI20(adapter->hw_dot_11n_dev_cap))
1263 ht_info->cap |= IEEE80211_HT_CAP_SGI_20;
1264 else
1265 ht_info->cap &= ~IEEE80211_HT_CAP_SGI_20;
1266
1267 if (ISSUPP_SHORTGI40(adapter->hw_dot_11n_dev_cap))
1268 ht_info->cap |= IEEE80211_HT_CAP_SGI_40;
1269 else
1270 ht_info->cap &= ~IEEE80211_HT_CAP_SGI_40;
1271
1272 if (ISSUPP_RXSTBC(adapter->hw_dot_11n_dev_cap))
1273 ht_info->cap |= 1 << IEEE80211_HT_CAP_RX_STBC_SHIFT;
1274 else
1275 ht_info->cap &= ~(3 << IEEE80211_HT_CAP_RX_STBC_SHIFT);
1276
1277 if (ISSUPP_TXSTBC(adapter->hw_dot_11n_dev_cap))
1278 ht_info->cap |= IEEE80211_HT_CAP_TX_STBC;
1279 else
1280 ht_info->cap &= ~IEEE80211_HT_CAP_TX_STBC;
1281
1282 ht_info->cap &= ~IEEE80211_HT_CAP_MAX_AMSDU;
1283 ht_info->cap |= IEEE80211_HT_CAP_SM_PS;
1284
1285 rx_mcs_supp = GET_RXMCSSUPP(adapter->hw_dev_mcs_support);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001286 /* Set MCS for 1x1 */
1287 memset(mcs, 0xff, rx_mcs_supp);
1288 /* Clear all the other values */
1289 memset(&mcs[rx_mcs_supp], 0,
Yogesh Ashok Powaraea07012012-03-13 19:22:35 -07001290 sizeof(struct ieee80211_mcs_info) - rx_mcs_supp);
Bing Zhaoeecd8252011-03-28 17:55:41 -07001291 if (priv->bss_mode == NL80211_IFTYPE_STATION ||
Yogesh Ashok Powaraea07012012-03-13 19:22:35 -07001292 ISSUPP_CHANWIDTH40(adapter->hw_dot_11n_dev_cap))
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001293 /* Set MCS32 for infra mode or ad-hoc mode with 40MHz support */
1294 SETHT_MCS32(mcs_set.rx_mask);
1295
1296 memcpy((u8 *) &ht_info->mcs, mcs, sizeof(struct ieee80211_mcs_info));
1297
1298 ht_info->mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED;
1299}
1300
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -07001301/*
1302 * create a new virtual interface with the given name
1303 */
1304struct net_device *mwifiex_add_virtual_intf(struct wiphy *wiphy,
Yogesh Ashok Powaraea07012012-03-13 19:22:35 -07001305 char *name,
1306 enum nl80211_iftype type,
1307 u32 *flags,
1308 struct vif_params *params)
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -07001309{
Avinash Patil67fdf392012-05-08 18:30:17 -07001310 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
1311 struct mwifiex_private *priv;
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -07001312 struct net_device *dev;
1313 void *mdev_priv;
Avinash Patild6bffe82012-05-08 18:30:15 -07001314 struct wireless_dev *wdev;
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -07001315
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -07001316 if (!adapter)
1317 return NULL;
1318
1319 switch (type) {
1320 case NL80211_IFTYPE_UNSPECIFIED:
1321 case NL80211_IFTYPE_STATION:
1322 case NL80211_IFTYPE_ADHOC:
Avinash Patild6bffe82012-05-08 18:30:15 -07001323 priv = adapter->priv[MWIFIEX_BSS_TYPE_STA];
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -07001324 if (priv->bss_mode) {
Avinash Patild6bffe82012-05-08 18:30:15 -07001325 wiphy_err(wiphy,
1326 "cannot create multiple sta/adhoc ifaces\n");
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -07001327 return NULL;
1328 }
1329
Avinash Patild6bffe82012-05-08 18:30:15 -07001330 wdev = kzalloc(sizeof(struct wireless_dev), GFP_KERNEL);
1331 if (!wdev)
1332 return NULL;
1333
1334 wdev->wiphy = wiphy;
1335 priv->wdev = wdev;
1336 wdev->iftype = NL80211_IFTYPE_STATION;
1337
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -07001338 if (type == NL80211_IFTYPE_UNSPECIFIED)
1339 priv->bss_mode = NL80211_IFTYPE_STATION;
1340 else
1341 priv->bss_mode = type;
1342
1343 priv->bss_type = MWIFIEX_BSS_TYPE_STA;
1344 priv->frame_type = MWIFIEX_DATA_FRAME_TYPE_ETH_II;
Avinash Patild6bffe82012-05-08 18:30:15 -07001345 priv->bss_priority = MWIFIEX_BSS_ROLE_STA;
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -07001346 priv->bss_role = MWIFIEX_BSS_ROLE_STA;
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -07001347 priv->bss_num = 0;
1348
1349 break;
Avinash Patild6bffe82012-05-08 18:30:15 -07001350 case NL80211_IFTYPE_AP:
1351 priv = adapter->priv[MWIFIEX_BSS_TYPE_UAP];
1352
1353 if (priv->bss_mode) {
1354 wiphy_err(wiphy, "Can't create multiple AP interfaces");
1355 return NULL;
1356 }
1357
1358 wdev = kzalloc(sizeof(struct wireless_dev), GFP_KERNEL);
1359 if (!wdev)
1360 return NULL;
1361
1362 priv->wdev = wdev;
1363 wdev->wiphy = wiphy;
1364 wdev->iftype = NL80211_IFTYPE_AP;
1365
1366 priv->bss_type = MWIFIEX_BSS_TYPE_UAP;
1367 priv->frame_type = MWIFIEX_DATA_FRAME_TYPE_ETH_II;
1368 priv->bss_priority = MWIFIEX_BSS_ROLE_UAP;
1369 priv->bss_role = MWIFIEX_BSS_ROLE_UAP;
1370 priv->bss_started = 0;
1371 priv->bss_num = 0;
1372 priv->bss_mode = type;
1373
1374 break;
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -07001375 default:
1376 wiphy_err(wiphy, "type not supported\n");
1377 return NULL;
1378 }
1379
1380 dev = alloc_netdev_mq(sizeof(struct mwifiex_private *), name,
1381 ether_setup, 1);
1382 if (!dev) {
1383 wiphy_err(wiphy, "no memory available for netdevice\n");
1384 goto error;
1385 }
1386
Avinash Patild6bffe82012-05-08 18:30:15 -07001387 mwifiex_init_priv_params(priv, dev);
1388 priv->netdev = dev;
1389
1390 mwifiex_setup_ht_caps(&wiphy->bands[IEEE80211_BAND_2GHZ]->ht_cap, priv);
1391
1392 if (adapter->config_bands & BAND_A)
1393 mwifiex_setup_ht_caps(
1394 &wiphy->bands[IEEE80211_BAND_5GHZ]->ht_cap, priv);
1395
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -07001396 dev_net_set(dev, wiphy_net(wiphy));
1397 dev->ieee80211_ptr = priv->wdev;
1398 dev->ieee80211_ptr->iftype = priv->bss_mode;
1399 memcpy(dev->dev_addr, wiphy->perm_addr, ETH_ALEN);
1400 memcpy(dev->perm_addr, wiphy->perm_addr, ETH_ALEN);
1401 SET_NETDEV_DEV(dev, wiphy_dev(wiphy));
1402
1403 dev->flags |= IFF_BROADCAST | IFF_MULTICAST;
1404 dev->watchdog_timeo = MWIFIEX_DEFAULT_WATCHDOG_TIMEOUT;
1405 dev->hard_header_len += MWIFIEX_MIN_DATA_HEADER_LEN;
1406
1407 mdev_priv = netdev_priv(dev);
1408 *((unsigned long *) mdev_priv) = (unsigned long) priv;
1409
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -07001410 SET_NETDEV_DEV(dev, adapter->dev);
1411
1412 /* Register network device */
1413 if (register_netdevice(dev)) {
1414 wiphy_err(wiphy, "cannot register virtual network device\n");
1415 goto error;
1416 }
1417
1418 sema_init(&priv->async_sem, 1);
1419 priv->scan_pending_on_block = false;
1420
1421 dev_dbg(adapter->dev, "info: %s: Marvell 802.11 Adapter\n", dev->name);
1422
1423#ifdef CONFIG_DEBUG_FS
1424 mwifiex_dev_debugfs_init(priv);
1425#endif
1426 return dev;
1427error:
1428 if (dev && (dev->reg_state == NETREG_UNREGISTERED))
1429 free_netdev(dev);
1430 priv->bss_mode = NL80211_IFTYPE_UNSPECIFIED;
1431
1432 return NULL;
1433}
1434EXPORT_SYMBOL_GPL(mwifiex_add_virtual_intf);
1435
1436/*
1437 * del_virtual_intf: remove the virtual interface determined by dev
1438 */
1439int mwifiex_del_virtual_intf(struct wiphy *wiphy, struct net_device *dev)
1440{
Yogesh Ashok Powarf540f9f2012-01-11 20:06:12 -08001441 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -07001442
1443#ifdef CONFIG_DEBUG_FS
1444 mwifiex_dev_debugfs_remove(priv);
1445#endif
1446
1447 if (!netif_queue_stopped(priv->netdev))
1448 netif_stop_queue(priv->netdev);
1449
1450 if (netif_carrier_ok(priv->netdev))
1451 netif_carrier_off(priv->netdev);
1452
1453 if (dev->reg_state == NETREG_REGISTERED)
1454 unregister_netdevice(dev);
1455
1456 if (dev->reg_state == NETREG_UNREGISTERED)
1457 free_netdev(dev);
1458
1459 /* Clear the priv in adapter */
1460 priv->netdev = NULL;
1461
1462 priv->media_connected = false;
1463
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -07001464 priv->bss_mode = NL80211_IFTYPE_UNSPECIFIED;
1465
1466 return 0;
1467}
1468EXPORT_SYMBOL_GPL(mwifiex_del_virtual_intf);
1469
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001470/* station cfg80211 operations */
1471static struct cfg80211_ops mwifiex_cfg80211_ops = {
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -07001472 .add_virtual_intf = mwifiex_add_virtual_intf,
1473 .del_virtual_intf = mwifiex_del_virtual_intf,
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001474 .change_virtual_intf = mwifiex_cfg80211_change_virtual_intf,
1475 .scan = mwifiex_cfg80211_scan,
1476 .connect = mwifiex_cfg80211_connect,
1477 .disconnect = mwifiex_cfg80211_disconnect,
1478 .get_station = mwifiex_cfg80211_get_station,
Amitkumar Karwarf85aae62012-03-15 20:51:48 -07001479 .dump_station = mwifiex_cfg80211_dump_station,
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001480 .set_wiphy_params = mwifiex_cfg80211_set_wiphy_params,
1481 .set_channel = mwifiex_cfg80211_set_channel,
1482 .join_ibss = mwifiex_cfg80211_join_ibss,
1483 .leave_ibss = mwifiex_cfg80211_leave_ibss,
1484 .add_key = mwifiex_cfg80211_add_key,
1485 .del_key = mwifiex_cfg80211_del_key,
1486 .set_default_key = mwifiex_cfg80211_set_default_key,
1487 .set_power_mgmt = mwifiex_cfg80211_set_power_mgmt,
1488 .set_tx_power = mwifiex_cfg80211_set_tx_power,
Yogesh Ashok Powar5d82c532011-07-11 20:04:44 -07001489 .set_bitrate_mask = mwifiex_cfg80211_set_bitrate_mask,
Amitkumar Karwarfa444bf2012-03-15 20:51:51 -07001490 .set_cqm_rssi_config = mwifiex_cfg80211_set_cqm_rssi_config,
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001491};
1492
1493/*
1494 * This function registers the device with CFG802.11 subsystem.
1495 *
1496 * The function creates the wireless device/wiphy, populates it with
1497 * default parameters and handler function pointers, and finally
1498 * registers the device.
1499 */
Avinash Patild6bffe82012-05-08 18:30:15 -07001500
1501int mwifiex_register_cfg80211(struct mwifiex_adapter *adapter)
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001502{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -07001503 int ret;
1504 void *wdev_priv;
Avinash Patild6bffe82012-05-08 18:30:15 -07001505 struct wiphy *wiphy;
1506 struct mwifiex_private *priv = adapter->priv[MWIFIEX_BSS_TYPE_STA];
Amitkumar Karwar9e04a7c2012-04-09 20:06:54 -07001507 u8 *country_code;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001508
Avinash Patild6bffe82012-05-08 18:30:15 -07001509 /* create a new wiphy for use with cfg80211 */
1510 wiphy = wiphy_new(&mwifiex_cfg80211_ops,
1511 sizeof(struct mwifiex_adapter *));
1512 if (!wiphy) {
1513 dev_err(adapter->dev, "%s: creating new wiphy\n", __func__);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001514 return -ENOMEM;
1515 }
Avinash Patild6bffe82012-05-08 18:30:15 -07001516 wiphy->max_scan_ssids = MWIFIEX_MAX_SSID_LIST_LENGTH;
1517 wiphy->max_scan_ie_len = MWIFIEX_MAX_VSIE_LEN;
1518 wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
1519 BIT(NL80211_IFTYPE_ADHOC) |
1520 BIT(NL80211_IFTYPE_AP);
Amitkumar Karwaradc89592011-04-27 19:13:11 -07001521
Avinash Patild6bffe82012-05-08 18:30:15 -07001522 wiphy->bands[IEEE80211_BAND_2GHZ] = &mwifiex_band_2ghz;
1523 if (adapter->config_bands & BAND_A)
1524 wiphy->bands[IEEE80211_BAND_5GHZ] = &mwifiex_band_5ghz;
1525 else
1526 wiphy->bands[IEEE80211_BAND_5GHZ] = NULL;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001527
Avinash Patilcd8440d2012-05-08 18:30:16 -07001528 wiphy->iface_combinations = &mwifiex_iface_comb_ap_sta;
1529 wiphy->n_iface_combinations = 1;
1530
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001531 /* Initialize cipher suits */
Avinash Patild6bffe82012-05-08 18:30:15 -07001532 wiphy->cipher_suites = mwifiex_cipher_suites;
1533 wiphy->n_cipher_suites = ARRAY_SIZE(mwifiex_cipher_suites);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001534
Avinash Patild6bffe82012-05-08 18:30:15 -07001535 memcpy(wiphy->perm_addr, priv->curr_addr, ETH_ALEN);
1536 wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
1537 wiphy->flags |= WIPHY_FLAG_HAVE_AP_SME | WIPHY_FLAG_CUSTOM_REGULATORY;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001538
Amitkumar Karwarb5abcf02012-04-16 21:36:52 -07001539 /* Reserve space for mwifiex specific private data for BSS */
Avinash Patild6bffe82012-05-08 18:30:15 -07001540 wiphy->bss_priv_size = sizeof(struct mwifiex_bss_priv);
Amitkumar Karwar5116f3c2011-09-21 21:43:23 -07001541
Avinash Patild6bffe82012-05-08 18:30:15 -07001542 wiphy->reg_notifier = mwifiex_reg_notifier;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001543
Avinash Patil67fdf392012-05-08 18:30:17 -07001544 /* Set struct mwifiex_adapter pointer in wiphy_priv */
Avinash Patild6bffe82012-05-08 18:30:15 -07001545 wdev_priv = wiphy_priv(wiphy);
Avinash Patil67fdf392012-05-08 18:30:17 -07001546 *(unsigned long *)wdev_priv = (unsigned long)adapter;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001547
Avinash Patild6bffe82012-05-08 18:30:15 -07001548 set_wiphy_dev(wiphy, (struct device *)priv->adapter->dev);
Yogesh Ashok Powara7b21162011-06-13 09:49:27 +05301549
Avinash Patild6bffe82012-05-08 18:30:15 -07001550 ret = wiphy_register(wiphy);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001551 if (ret < 0) {
Avinash Patild6bffe82012-05-08 18:30:15 -07001552 dev_err(adapter->dev,
1553 "%s: wiphy_register failed: %d\n", __func__, ret);
1554 wiphy_free(wiphy);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001555 return ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001556 }
Amitkumar Karwar9e04a7c2012-04-09 20:06:54 -07001557 country_code = mwifiex_11d_code_2_region(priv->adapter->region_code);
Avinash Patild6bffe82012-05-08 18:30:15 -07001558 if (country_code && regulatory_hint(wiphy, country_code))
1559 dev_err(adapter->dev, "regulatory_hint() failed\n");
Amitkumar Karwar9e04a7c2012-04-09 20:06:54 -07001560
Avinash Patild6bffe82012-05-08 18:30:15 -07001561 adapter->wiphy = wiphy;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001562 return ret;
1563}