blob: 453239389d26bc0373930d1d640fe5c459885e88 [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 */
87static void *mwifiex_cfg80211_get_priv(struct wiphy *wiphy)
88{
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{
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700118 struct mwifiex_private *priv = mwifiex_cfg80211_get_priv(wiphy);
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700119 struct mwifiex_power_cfg power_cfg;
Luis R. Rodriguez742c29f2011-11-28 16:38:50 -0500120 int dbm = MBM_TO_DBM(mbm);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700121
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700122 if (type == NL80211_TX_POWER_FIXED) {
123 power_cfg.is_power_auto = 0;
124 power_cfg.power_level = dbm;
125 } else {
126 power_cfg.is_power_auto = 1;
127 }
128
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700129 return mwifiex_set_tx_power(priv, &power_cfg);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700130}
131
132/*
133 * CFG802.11 operation handler to set Power Save option.
134 *
135 * The timeout value, if provided, is currently ignored.
136 */
137static int
138mwifiex_cfg80211_set_power_mgmt(struct wiphy *wiphy,
139 struct net_device *dev,
140 bool enabled, int timeout)
141{
Yogesh Ashok Powarf540f9f2012-01-11 20:06:12 -0800142 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700143 u32 ps_mode;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700144
145 if (timeout)
146 wiphy_dbg(wiphy,
Yogesh Ashok Powaraea07012012-03-13 19:22:35 -0700147 "info: ignore timeout value for IEEE Power Save\n");
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700148
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700149 ps_mode = enabled;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700150
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700151 return mwifiex_drv_set_power(priv, &ps_mode);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700152}
153
154/*
155 * CFG802.11 operation handler to set the default network key.
156 */
157static int
158mwifiex_cfg80211_set_default_key(struct wiphy *wiphy, struct net_device *netdev,
159 u8 key_index, bool unicast,
160 bool multicast)
161{
Yogesh Ashok Powarf540f9f2012-01-11 20:06:12 -0800162 struct mwifiex_private *priv = mwifiex_netdev_get_priv(netdev);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700163
Amitkumar Karwar2d3d0a82011-04-01 18:36:46 -0700164 /* Return if WEP key not configured */
Amitkumar Karwar5eb02e42012-02-24 21:36:04 -0800165 if (!priv->sec_info.wep_enabled)
Amitkumar Karwar2d3d0a82011-04-01 18:36:46 -0700166 return 0;
167
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700168 if (mwifiex_set_encode(priv, NULL, 0, key_index, 0)) {
169 wiphy_err(wiphy, "set default Tx key index\n");
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700170 return -EFAULT;
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700171 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700172
173 return 0;
174}
175
176/*
177 * CFG802.11 operation handler to add a network key.
178 */
179static int
180mwifiex_cfg80211_add_key(struct wiphy *wiphy, struct net_device *netdev,
181 u8 key_index, bool pairwise, const u8 *mac_addr,
182 struct key_params *params)
183{
Yogesh Ashok Powarf540f9f2012-01-11 20:06:12 -0800184 struct mwifiex_private *priv = mwifiex_netdev_get_priv(netdev);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700185
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700186 if (mwifiex_set_encode(priv, params->key, params->key_len,
Yogesh Ashok Powaraea07012012-03-13 19:22:35 -0700187 key_index, 0)) {
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700188 wiphy_err(wiphy, "crypto keys added\n");
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700189 return -EFAULT;
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700190 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700191
192 return 0;
193}
194
195/*
196 * This function sends domain information to the firmware.
197 *
198 * The following information are passed to the firmware -
199 * - Country codes
200 * - Sub bands (first channel, number of channels, maximum Tx power)
201 */
202static int mwifiex_send_domain_info_cmd_fw(struct wiphy *wiphy)
203{
204 u8 no_of_triplet = 0;
205 struct ieee80211_country_ie_triplet *t;
206 u8 no_of_parsed_chan = 0;
207 u8 first_chan = 0, next_chan = 0, max_pwr = 0;
208 u8 i, flag = 0;
209 enum ieee80211_band band;
210 struct ieee80211_supported_band *sband;
211 struct ieee80211_channel *ch;
212 struct mwifiex_private *priv = mwifiex_cfg80211_get_priv(wiphy);
213 struct mwifiex_adapter *adapter = priv->adapter;
214 struct mwifiex_802_11d_domain_reg *domain_info = &adapter->domain_reg;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700215
216 /* Set country code */
217 domain_info->country_code[0] = priv->country_code[0];
218 domain_info->country_code[1] = priv->country_code[1];
219 domain_info->country_code[2] = ' ';
220
221 band = mwifiex_band_to_radio_type(adapter->config_bands);
222 if (!wiphy->bands[band]) {
223 wiphy_err(wiphy, "11D: setting domain info in FW\n");
224 return -1;
225 }
226
227 sband = wiphy->bands[band];
228
229 for (i = 0; i < sband->n_channels ; i++) {
230 ch = &sband->channels[i];
231 if (ch->flags & IEEE80211_CHAN_DISABLED)
232 continue;
233
234 if (!flag) {
235 flag = 1;
236 first_chan = (u32) ch->hw_value;
237 next_chan = first_chan;
238 max_pwr = ch->max_power;
239 no_of_parsed_chan = 1;
240 continue;
241 }
242
243 if (ch->hw_value == next_chan + 1 &&
Yogesh Ashok Powaraea07012012-03-13 19:22:35 -0700244 ch->max_power == max_pwr) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700245 next_chan++;
246 no_of_parsed_chan++;
247 } else {
248 t = &domain_info->triplet[no_of_triplet];
249 t->chans.first_channel = first_chan;
250 t->chans.num_channels = no_of_parsed_chan;
251 t->chans.max_power = max_pwr;
252 no_of_triplet++;
253 first_chan = (u32) ch->hw_value;
254 next_chan = first_chan;
255 max_pwr = ch->max_power;
256 no_of_parsed_chan = 1;
257 }
258 }
259
260 if (flag) {
261 t = &domain_info->triplet[no_of_triplet];
262 t->chans.first_channel = first_chan;
263 t->chans.num_channels = no_of_parsed_chan;
264 t->chans.max_power = max_pwr;
265 no_of_triplet++;
266 }
267
268 domain_info->no_of_triplet = no_of_triplet;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700269
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700270 if (mwifiex_send_cmd_async(priv, HostCmd_CMD_802_11D_DOMAIN_INFO,
Yogesh Ashok Powaraea07012012-03-13 19:22:35 -0700271 HostCmd_ACT_GEN_SET, 0, NULL)) {
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700272 wiphy_err(wiphy, "11D: setting domain info in FW\n");
273 return -1;
274 }
275
276 return 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700277}
278
279/*
280 * CFG802.11 regulatory domain callback function.
281 *
282 * This function is called when the regulatory domain is changed due to the
283 * following reasons -
284 * - Set by driver
285 * - Set by system core
286 * - Set by user
287 * - Set bt Country IE
288 */
289static int mwifiex_reg_notifier(struct wiphy *wiphy,
Yogesh Ashok Powaraea07012012-03-13 19:22:35 -0700290 struct regulatory_request *request)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700291{
292 struct mwifiex_private *priv = mwifiex_cfg80211_get_priv(wiphy);
293
294 wiphy_dbg(wiphy, "info: cfg80211 regulatory domain callback for domain"
295 " %c%c\n", request->alpha2[0], request->alpha2[1]);
296
297 memcpy(priv->country_code, request->alpha2, sizeof(request->alpha2));
298
299 switch (request->initiator) {
300 case NL80211_REGDOM_SET_BY_DRIVER:
301 case NL80211_REGDOM_SET_BY_CORE:
302 case NL80211_REGDOM_SET_BY_USER:
303 break;
304 /* Todo: apply driver specific changes in channel flags based
305 on the request initiator if necessary. */
306 case NL80211_REGDOM_SET_BY_COUNTRY_IE:
307 break;
308 }
309 mwifiex_send_domain_info_cmd_fw(wiphy);
310
311 return 0;
312}
313
314/*
315 * This function sets the RF channel.
316 *
317 * This function creates multiple IOCTL requests, populates them accordingly
318 * and issues them to set the band/channel and frequency.
319 */
320static int
321mwifiex_set_rf_channel(struct mwifiex_private *priv,
322 struct ieee80211_channel *chan,
323 enum nl80211_channel_type channel_type)
324{
325 struct mwifiex_chan_freq_power cfp;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700326 u32 config_bands = 0;
327 struct wiphy *wiphy = priv->wdev->wiphy;
Amitkumar Karwar43906cd2011-12-20 23:47:20 -0800328 struct mwifiex_adapter *adapter = priv->adapter;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700329
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700330 if (chan) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700331 /* Set appropriate bands */
Amitkumar Karwar3aebee02011-12-20 23:47:22 -0800332 if (chan->band == IEEE80211_BAND_2GHZ) {
333 if (channel_type == NL80211_CHAN_NO_HT)
334 if (priv->adapter->config_bands == BAND_B ||
Yogesh Ashok Powaraea07012012-03-13 19:22:35 -0700335 priv->adapter->config_bands == BAND_G)
Amitkumar Karwar3aebee02011-12-20 23:47:22 -0800336 config_bands =
337 priv->adapter->config_bands;
338 else
339 config_bands = BAND_B | BAND_G;
340 else
341 config_bands = BAND_B | BAND_G | BAND_GN;
342 } else {
343 if (channel_type == NL80211_CHAN_NO_HT)
344 config_bands = BAND_A;
345 else
346 config_bands = BAND_AN | BAND_A;
347 }
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700348
Amitkumar Karwar43906cd2011-12-20 23:47:20 -0800349 if (!((config_bands | adapter->fw_bands) &
350 ~adapter->fw_bands)) {
351 adapter->config_bands = config_bands;
352 if (priv->bss_mode == NL80211_IFTYPE_ADHOC) {
353 adapter->adhoc_start_band = config_bands;
354 if ((config_bands & BAND_GN) ||
Yogesh Ashok Powaraea07012012-03-13 19:22:35 -0700355 (config_bands & BAND_AN))
Amitkumar Karwar43906cd2011-12-20 23:47:20 -0800356 adapter->adhoc_11n_enabled = true;
357 else
358 adapter->adhoc_11n_enabled = false;
359 }
360 }
Amitkumar Karwar21c3ba32011-12-20 23:47:21 -0800361 adapter->sec_chan_offset =
362 mwifiex_cfg80211_channel_type_to_sec_chan_offset
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700363 (channel_type);
Amitkumar Karwar3aebee02011-12-20 23:47:22 -0800364 adapter->channel_type = channel_type;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700365
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700366 mwifiex_send_domain_info_cmd_fw(wiphy);
367 }
368
Yogesh Ashok Powaraea07012012-03-13 19:22:35 -0700369 wiphy_dbg(wiphy, "info: setting band %d, chan offset %d, mode %d\n",
370 config_bands, adapter->sec_chan_offset, priv->bss_mode);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700371 if (!chan)
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700372 return 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700373
374 memset(&cfp, 0, sizeof(cfp));
375 cfp.freq = chan->center_freq;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700376 cfp.channel = ieee80211_frequency_to_channel(chan->center_freq);
377
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700378 if (mwifiex_bss_set_channel(priv, &cfp))
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700379 return -EFAULT;
380
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700381 return mwifiex_drv_change_adhoc_chan(priv, cfp.channel);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700382}
383
384/*
385 * CFG802.11 operation handler to set channel.
386 *
387 * This function can only be used when station is not connected.
388 */
389static int
390mwifiex_cfg80211_set_channel(struct wiphy *wiphy, struct net_device *dev,
391 struct ieee80211_channel *chan,
392 enum nl80211_channel_type channel_type)
393{
Amitkumar Karwar477778b2012-02-01 20:41:44 -0800394 struct mwifiex_private *priv;
395
396 if (dev)
397 priv = mwifiex_netdev_get_priv(dev);
398 else
399 priv = mwifiex_cfg80211_get_priv(wiphy);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700400
401 if (priv->media_connected) {
402 wiphy_err(wiphy, "This setting is valid only when station "
403 "is not connected\n");
404 return -EINVAL;
405 }
406
407 return mwifiex_set_rf_channel(priv, chan, channel_type);
408}
409
410/*
411 * This function sets the fragmentation threshold.
412 *
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700413 * The fragmentation threshold value must lie between MWIFIEX_FRAG_MIN_VALUE
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700414 * and MWIFIEX_FRAG_MAX_VALUE.
415 */
416static int
417mwifiex_set_frag(struct mwifiex_private *priv, u32 frag_thr)
418{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700419 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700420
Yogesh Ashok Powaraea07012012-03-13 19:22:35 -0700421 if (frag_thr < MWIFIEX_FRAG_MIN_VALUE ||
422 frag_thr > MWIFIEX_FRAG_MAX_VALUE)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700423 return -EINVAL;
424
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700425 /* Send request to firmware */
426 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_SNMP_MIB,
427 HostCmd_ACT_GEN_SET, FRAG_THRESH_I,
428 &frag_thr);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700429
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700430 return ret;
431}
432
433/*
434 * This function sets the RTS threshold.
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700435
436 * The rts value must lie between MWIFIEX_RTS_MIN_VALUE
437 * and MWIFIEX_RTS_MAX_VALUE.
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700438 */
439static int
440mwifiex_set_rts(struct mwifiex_private *priv, u32 rts_thr)
441{
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700442 if (rts_thr < MWIFIEX_RTS_MIN_VALUE || rts_thr > MWIFIEX_RTS_MAX_VALUE)
443 rts_thr = MWIFIEX_RTS_MAX_VALUE;
444
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700445 return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_SNMP_MIB,
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700446 HostCmd_ACT_GEN_SET, RTS_THRESH_I,
447 &rts_thr);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700448}
449
450/*
451 * CFG802.11 operation handler to set wiphy parameters.
452 *
453 * This function can be used to set the RTS threshold and the
454 * Fragmentation threshold of the driver.
455 */
456static int
457mwifiex_cfg80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
458{
459 struct mwifiex_private *priv = mwifiex_cfg80211_get_priv(wiphy);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700460 int ret = 0;
461
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700462 if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700463 ret = mwifiex_set_rts(priv, wiphy->rts_threshold);
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700464 if (ret)
465 return ret;
466 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700467
468 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
469 ret = mwifiex_set_frag(priv, wiphy->frag_threshold);
470
471 return ret;
472}
473
474/*
475 * CFG802.11 operation handler to change interface type.
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700476 */
477static int
478mwifiex_cfg80211_change_virtual_intf(struct wiphy *wiphy,
479 struct net_device *dev,
480 enum nl80211_iftype type, u32 *flags,
481 struct vif_params *params)
482{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700483 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700484 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
Bing Zhaoeecd8252011-03-28 17:55:41 -0700485
486 if (priv->bss_mode == type) {
487 wiphy_warn(wiphy, "already set to required type\n");
488 return 0;
489 }
490
491 priv->bss_mode = type;
492
493 switch (type) {
494 case NL80211_IFTYPE_ADHOC:
495 dev->ieee80211_ptr->iftype = NL80211_IFTYPE_ADHOC;
496 wiphy_dbg(wiphy, "info: setting interface type to adhoc\n");
497 break;
498 case NL80211_IFTYPE_STATION:
499 dev->ieee80211_ptr->iftype = NL80211_IFTYPE_STATION;
500 wiphy_dbg(wiphy, "info: setting interface type to managed\n");
501 break;
502 case NL80211_IFTYPE_UNSPECIFIED:
503 dev->ieee80211_ptr->iftype = NL80211_IFTYPE_STATION;
504 wiphy_dbg(wiphy, "info: setting interface type to auto\n");
505 return 0;
506 default:
507 wiphy_err(wiphy, "unknown interface type: %d\n", type);
508 return -EINVAL;
509 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700510
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700511 mwifiex_deauthenticate(priv, NULL);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700512
Marc Yangf986b6d2011-03-28 17:55:42 -0700513 priv->sec_info.authentication_mode = NL80211_AUTHTYPE_OPEN_SYSTEM;
Bing Zhaoeecd8252011-03-28 17:55:41 -0700514
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700515 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_SET_BSS_MODE,
516 HostCmd_ACT_GEN_SET, 0, NULL);
Bing Zhaoeecd8252011-03-28 17:55:41 -0700517
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700518 return ret;
519}
520
521/*
522 * This function dumps the station information on a buffer.
523 *
524 * The following information are shown -
525 * - Total bytes transmitted
526 * - Total bytes received
527 * - Total packets transmitted
528 * - Total packets received
529 * - Signal quality level
530 * - Transmission rate
531 */
532static int
533mwifiex_dump_station_info(struct mwifiex_private *priv,
534 struct station_info *sinfo)
535{
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700536 struct mwifiex_rate_cfg rate;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700537
538 sinfo->filled = STATION_INFO_RX_BYTES | STATION_INFO_TX_BYTES |
Amitkumar Karwar7013d3e2012-03-15 20:51:50 -0700539 STATION_INFO_RX_PACKETS | STATION_INFO_TX_PACKETS |
540 STATION_INFO_TX_BITRATE |
541 STATION_INFO_SIGNAL | STATION_INFO_SIGNAL_AVG;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700542
543 /* Get signal information from the firmware */
Amitkumar Karwar958a4a82012-03-15 20:51:49 -0700544 if (mwifiex_send_cmd_sync(priv, HostCmd_CMD_RSSI_INFO,
545 HostCmd_ACT_GEN_GET, 0, NULL)) {
546 dev_err(priv->adapter->dev, "failed to get signal information\n");
547 return -EFAULT;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700548 }
549
550 if (mwifiex_drv_get_data_rate(priv, &rate)) {
551 dev_err(priv->adapter->dev, "getting data rate\n");
Amitkumar Karwar958a4a82012-03-15 20:51:49 -0700552 return -EFAULT;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700553 }
554
Amitkumar Karwarcaf60a62012-02-02 20:48:58 -0800555 /* Get DTIM period information from firmware */
556 mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_SNMP_MIB,
557 HostCmd_ACT_GEN_GET, DTIM_PERIOD_I,
558 &priv->dtim_period);
559
Amitkumar Karwar4ec6f9c2011-09-26 20:37:25 -0700560 /*
561 * Bit 0 in tx_htinfo indicates that current Tx rate is 11n rate. Valid
562 * MCS index values for us are 0 to 7.
563 */
564 if ((priv->tx_htinfo & BIT(0)) && (priv->tx_rate < 8)) {
565 sinfo->txrate.mcs = priv->tx_rate;
566 sinfo->txrate.flags |= RATE_INFO_FLAGS_MCS;
567 /* 40MHz rate */
568 if (priv->tx_htinfo & BIT(1))
569 sinfo->txrate.flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
570 /* SGI enabled */
571 if (priv->tx_htinfo & BIT(2))
572 sinfo->txrate.flags |= RATE_INFO_FLAGS_SHORT_GI;
573 }
574
Amitkumar Karwar7013d3e2012-03-15 20:51:50 -0700575 sinfo->signal_avg = priv->bcn_rssi_avg;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700576 sinfo->rx_bytes = priv->stats.rx_bytes;
577 sinfo->tx_bytes = priv->stats.tx_bytes;
578 sinfo->rx_packets = priv->stats.rx_packets;
579 sinfo->tx_packets = priv->stats.tx_packets;
Amitkumar Karwar958a4a82012-03-15 20:51:49 -0700580 sinfo->signal = priv->bcn_rssi_avg;
Amitkumar Karwar4ec6f9c2011-09-26 20:37:25 -0700581 /* bit rate is in 500 kb/s units. Convert it to 100kb/s units */
582 sinfo->txrate.legacy = rate.rate * 5;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700583
Amitkumar Karwarc4f3b972012-01-24 20:50:25 -0800584 if (priv->bss_mode == NL80211_IFTYPE_STATION) {
585 sinfo->filled |= STATION_INFO_BSS_PARAM;
586 sinfo->bss_param.flags = 0;
587 if (priv->curr_bss_params.bss_descriptor.cap_info_bitmap &
588 WLAN_CAPABILITY_SHORT_PREAMBLE)
589 sinfo->bss_param.flags |=
590 BSS_PARAM_FLAGS_SHORT_PREAMBLE;
591 if (priv->curr_bss_params.bss_descriptor.cap_info_bitmap &
592 WLAN_CAPABILITY_SHORT_SLOT_TIME)
593 sinfo->bss_param.flags |=
594 BSS_PARAM_FLAGS_SHORT_SLOT_TIME;
Amitkumar Karwarcaf60a62012-02-02 20:48:58 -0800595 sinfo->bss_param.dtim_period = priv->dtim_period;
Amitkumar Karwarc4f3b972012-01-24 20:50:25 -0800596 sinfo->bss_param.beacon_interval =
597 priv->curr_bss_params.bss_descriptor.beacon_period;
598 }
599
Amitkumar Karwar958a4a82012-03-15 20:51:49 -0700600 return 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700601}
602
603/*
604 * CFG802.11 operation handler to get station information.
605 *
606 * This function only works in connected mode, and dumps the
607 * requested station information, if available.
608 */
609static int
610mwifiex_cfg80211_get_station(struct wiphy *wiphy, struct net_device *dev,
611 u8 *mac, struct station_info *sinfo)
612{
613 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700614
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700615 if (!priv->media_connected)
616 return -ENOENT;
617 if (memcmp(mac, priv->cfg_bssid, ETH_ALEN))
618 return -ENOENT;
619
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700620 return mwifiex_dump_station_info(priv, sinfo);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700621}
622
Amitkumar Karwarf85aae62012-03-15 20:51:48 -0700623/*
624 * CFG802.11 operation handler to dump station information.
625 */
626static int
627mwifiex_cfg80211_dump_station(struct wiphy *wiphy, struct net_device *dev,
628 int idx, u8 *mac, struct station_info *sinfo)
629{
630 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
631
632 if (!priv->media_connected || idx)
633 return -ENOENT;
634
635 memcpy(mac, priv->cfg_bssid, ETH_ALEN);
636
637 return mwifiex_dump_station_info(priv, sinfo);
638}
639
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700640/* Supported rates to be advertised to the cfg80211 */
641
642static struct ieee80211_rate mwifiex_rates[] = {
643 {.bitrate = 10, .hw_value = 2, },
644 {.bitrate = 20, .hw_value = 4, },
645 {.bitrate = 55, .hw_value = 11, },
646 {.bitrate = 110, .hw_value = 22, },
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700647 {.bitrate = 60, .hw_value = 12, },
648 {.bitrate = 90, .hw_value = 18, },
649 {.bitrate = 120, .hw_value = 24, },
650 {.bitrate = 180, .hw_value = 36, },
651 {.bitrate = 240, .hw_value = 48, },
652 {.bitrate = 360, .hw_value = 72, },
653 {.bitrate = 480, .hw_value = 96, },
654 {.bitrate = 540, .hw_value = 108, },
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700655};
656
657/* Channel definitions to be advertised to cfg80211 */
658
659static struct ieee80211_channel mwifiex_channels_2ghz[] = {
660 {.center_freq = 2412, .hw_value = 1, },
661 {.center_freq = 2417, .hw_value = 2, },
662 {.center_freq = 2422, .hw_value = 3, },
663 {.center_freq = 2427, .hw_value = 4, },
664 {.center_freq = 2432, .hw_value = 5, },
665 {.center_freq = 2437, .hw_value = 6, },
666 {.center_freq = 2442, .hw_value = 7, },
667 {.center_freq = 2447, .hw_value = 8, },
668 {.center_freq = 2452, .hw_value = 9, },
669 {.center_freq = 2457, .hw_value = 10, },
670 {.center_freq = 2462, .hw_value = 11, },
671 {.center_freq = 2467, .hw_value = 12, },
672 {.center_freq = 2472, .hw_value = 13, },
673 {.center_freq = 2484, .hw_value = 14, },
674};
675
676static struct ieee80211_supported_band mwifiex_band_2ghz = {
677 .channels = mwifiex_channels_2ghz,
678 .n_channels = ARRAY_SIZE(mwifiex_channels_2ghz),
679 .bitrates = mwifiex_rates,
Amitkumar Karwar87638482012-03-07 19:36:07 -0800680 .n_bitrates = ARRAY_SIZE(mwifiex_rates),
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700681};
682
683static struct ieee80211_channel mwifiex_channels_5ghz[] = {
684 {.center_freq = 5040, .hw_value = 8, },
685 {.center_freq = 5060, .hw_value = 12, },
686 {.center_freq = 5080, .hw_value = 16, },
687 {.center_freq = 5170, .hw_value = 34, },
688 {.center_freq = 5190, .hw_value = 38, },
689 {.center_freq = 5210, .hw_value = 42, },
690 {.center_freq = 5230, .hw_value = 46, },
691 {.center_freq = 5180, .hw_value = 36, },
692 {.center_freq = 5200, .hw_value = 40, },
693 {.center_freq = 5220, .hw_value = 44, },
694 {.center_freq = 5240, .hw_value = 48, },
695 {.center_freq = 5260, .hw_value = 52, },
696 {.center_freq = 5280, .hw_value = 56, },
697 {.center_freq = 5300, .hw_value = 60, },
698 {.center_freq = 5320, .hw_value = 64, },
699 {.center_freq = 5500, .hw_value = 100, },
700 {.center_freq = 5520, .hw_value = 104, },
701 {.center_freq = 5540, .hw_value = 108, },
702 {.center_freq = 5560, .hw_value = 112, },
703 {.center_freq = 5580, .hw_value = 116, },
704 {.center_freq = 5600, .hw_value = 120, },
705 {.center_freq = 5620, .hw_value = 124, },
706 {.center_freq = 5640, .hw_value = 128, },
707 {.center_freq = 5660, .hw_value = 132, },
708 {.center_freq = 5680, .hw_value = 136, },
709 {.center_freq = 5700, .hw_value = 140, },
710 {.center_freq = 5745, .hw_value = 149, },
711 {.center_freq = 5765, .hw_value = 153, },
712 {.center_freq = 5785, .hw_value = 157, },
713 {.center_freq = 5805, .hw_value = 161, },
714 {.center_freq = 5825, .hw_value = 165, },
715};
716
717static struct ieee80211_supported_band mwifiex_band_5ghz = {
718 .channels = mwifiex_channels_5ghz,
719 .n_channels = ARRAY_SIZE(mwifiex_channels_5ghz),
Avinash Patileb416ad2012-02-27 22:04:11 -0800720 .bitrates = mwifiex_rates + 4,
721 .n_bitrates = ARRAY_SIZE(mwifiex_rates) - 4,
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700722};
723
724
725/* Supported crypto cipher suits to be advertised to cfg80211 */
726
727static const u32 mwifiex_cipher_suites[] = {
728 WLAN_CIPHER_SUITE_WEP40,
729 WLAN_CIPHER_SUITE_WEP104,
730 WLAN_CIPHER_SUITE_TKIP,
731 WLAN_CIPHER_SUITE_CCMP,
732};
733
734/*
Yogesh Ashok Powar5d82c532011-07-11 20:04:44 -0700735 * CFG802.11 operation handler for setting bit rates.
736 *
737 * Function selects legacy bang B/G/BG from corresponding bitrates selection.
738 * Currently only 2.4GHz band is supported.
739 */
740static int mwifiex_cfg80211_set_bitrate_mask(struct wiphy *wiphy,
741 struct net_device *dev,
742 const u8 *peer,
743 const struct cfg80211_bitrate_mask *mask)
744{
Yogesh Ashok Powar5d82c532011-07-11 20:04:44 -0700745 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
746 int index = 0, mode = 0, i;
Amitkumar Karwar43906cd2011-12-20 23:47:20 -0800747 struct mwifiex_adapter *adapter = priv->adapter;
Yogesh Ashok Powar5d82c532011-07-11 20:04:44 -0700748
749 /* Currently only 2.4GHz is supported */
750 for (i = 0; i < mwifiex_band_2ghz.n_bitrates; i++) {
751 /*
752 * Rates below 6 Mbps in the table are CCK rates; 802.11b
753 * and from 6 they are OFDM; 802.11G
754 */
755 if (mwifiex_rates[i].bitrate == 60) {
756 index = 1 << i;
757 break;
758 }
759 }
760
761 if (mask->control[IEEE80211_BAND_2GHZ].legacy < index) {
762 mode = BAND_B;
763 } else {
764 mode = BAND_G;
765 if (mask->control[IEEE80211_BAND_2GHZ].legacy % index)
766 mode |= BAND_B;
767 }
768
Amitkumar Karwar43906cd2011-12-20 23:47:20 -0800769 if (!((mode | adapter->fw_bands) & ~adapter->fw_bands)) {
770 adapter->config_bands = mode;
771 if (priv->bss_mode == NL80211_IFTYPE_ADHOC) {
772 adapter->adhoc_start_band = mode;
773 adapter->adhoc_11n_enabled = false;
774 }
775 }
Amitkumar Karwar21c3ba32011-12-20 23:47:21 -0800776 adapter->sec_chan_offset = IEEE80211_HT_PARAM_CHA_SEC_NONE;
Amitkumar Karwar3aebee02011-12-20 23:47:22 -0800777 adapter->channel_type = NL80211_CHAN_NO_HT;
Yogesh Ashok Powar5d82c532011-07-11 20:04:44 -0700778
779 wiphy_debug(wiphy, "info: device configured in 802.11%s%s mode\n",
Yogesh Ashok Powaraea07012012-03-13 19:22:35 -0700780 (mode & BAND_B) ? "b" : "", (mode & BAND_G) ? "g" : "");
Yogesh Ashok Powar5d82c532011-07-11 20:04:44 -0700781
782 return 0;
783}
784
785/*
Amitkumar Karwarfa444bf2012-03-15 20:51:51 -0700786 * CFG802.11 operation handler for connection quality monitoring.
787 *
788 * This function subscribes/unsubscribes HIGH_RSSI and LOW_RSSI
789 * events to FW.
790 */
791static int mwifiex_cfg80211_set_cqm_rssi_config(struct wiphy *wiphy,
792 struct net_device *dev,
793 s32 rssi_thold, u32 rssi_hyst)
794{
795 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
796 struct mwifiex_ds_misc_subsc_evt subsc_evt;
797
798 priv->cqm_rssi_thold = rssi_thold;
799 priv->cqm_rssi_hyst = rssi_hyst;
800
801 memset(&subsc_evt, 0x00, sizeof(struct mwifiex_ds_misc_subsc_evt));
802 subsc_evt.events = BITMASK_BCN_RSSI_LOW | BITMASK_BCN_RSSI_HIGH;
803
804 /* Subscribe/unsubscribe low and high rssi events */
805 if (rssi_thold && rssi_hyst) {
806 subsc_evt.action = HostCmd_ACT_BITWISE_SET;
807 subsc_evt.bcn_l_rssi_cfg.abs_value = abs(rssi_thold);
808 subsc_evt.bcn_h_rssi_cfg.abs_value = abs(rssi_thold);
809 subsc_evt.bcn_l_rssi_cfg.evt_freq = 1;
810 subsc_evt.bcn_h_rssi_cfg.evt_freq = 1;
811 return mwifiex_send_cmd_sync(priv,
812 HostCmd_CMD_802_11_SUBSCRIBE_EVENT,
813 0, 0, &subsc_evt);
814 } else {
815 subsc_evt.action = HostCmd_ACT_BITWISE_CLR;
816 return mwifiex_send_cmd_sync(priv,
817 HostCmd_CMD_802_11_SUBSCRIBE_EVENT,
818 0, 0, &subsc_evt);
819 }
820
821 return 0;
822}
823
824/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700825 * CFG802.11 operation handler for disconnection request.
826 *
827 * This function does not work when there is already a disconnection
828 * procedure going on.
829 */
830static int
831mwifiex_cfg80211_disconnect(struct wiphy *wiphy, struct net_device *dev,
832 u16 reason_code)
833{
834 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
835
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700836 if (mwifiex_deauthenticate(priv, NULL))
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700837 return -EFAULT;
838
839 wiphy_dbg(wiphy, "info: successfully disconnected from %pM:"
840 " reason code %d\n", priv->cfg_bssid, reason_code);
841
Amitkumar Karwar38c9d662011-12-13 20:43:17 -0800842 memset(priv->cfg_bssid, 0, ETH_ALEN);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700843
844 return 0;
845}
846
847/*
848 * This function informs the CFG802.11 subsystem of a new IBSS.
849 *
850 * The following information are sent to the CFG802.11 subsystem
851 * to register the new IBSS. If we do not register the new IBSS,
852 * a kernel panic will result.
853 * - SSID
854 * - SSID length
855 * - BSSID
856 * - Channel
857 */
858static int mwifiex_cfg80211_inform_ibss_bss(struct mwifiex_private *priv)
859{
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700860 struct ieee80211_channel *chan;
861 struct mwifiex_bss_info bss_info;
Amitkumar Karwaraa95a482011-11-07 21:41:12 -0800862 struct cfg80211_bss *bss;
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700863 int ie_len;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700864 u8 ie_buf[IEEE80211_MAX_SSID_LEN + sizeof(struct ieee_types_header)];
Amitkumar Karwar4ed5d522011-09-21 21:43:24 -0700865 enum ieee80211_band band;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700866
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700867 if (mwifiex_get_bss_info(priv, &bss_info))
868 return -1;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700869
870 ie_buf[0] = WLAN_EID_SSID;
871 ie_buf[1] = bss_info.ssid.ssid_len;
872
873 memcpy(&ie_buf[sizeof(struct ieee_types_header)],
Yogesh Ashok Powaraea07012012-03-13 19:22:35 -0700874 &bss_info.ssid.ssid, bss_info.ssid.ssid_len);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700875 ie_len = ie_buf[1] + sizeof(struct ieee_types_header);
876
Amitkumar Karwar4ed5d522011-09-21 21:43:24 -0700877 band = mwifiex_band_to_radio_type(priv->curr_bss_params.band);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700878 chan = __ieee80211_get_channel(priv->wdev->wiphy,
879 ieee80211_channel_to_frequency(bss_info.bss_chan,
Amitkumar Karwar4ed5d522011-09-21 21:43:24 -0700880 band));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700881
Amitkumar Karwaraa95a482011-11-07 21:41:12 -0800882 bss = cfg80211_inform_bss(priv->wdev->wiphy, chan,
Yogesh Ashok Powaraea07012012-03-13 19:22:35 -0700883 bss_info.bssid, 0, WLAN_CAPABILITY_IBSS,
884 0, ie_buf, ie_len, 0, GFP_KERNEL);
Amitkumar Karwaraa95a482011-11-07 21:41:12 -0800885 cfg80211_put_bss(bss);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700886 memcpy(priv->cfg_bssid, bss_info.bssid, ETH_ALEN);
887
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700888 return 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700889}
890
891/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700892 * This function connects with a BSS.
893 *
894 * This function handles both Infra and Ad-Hoc modes. It also performs
895 * validity checking on the provided parameters, disconnects from the
896 * current BSS (if any), sets up the association/scan parameters,
897 * including security settings, and performs specific SSID scan before
898 * trying to connect.
899 *
900 * For Infra mode, the function returns failure if the specified SSID
901 * is not found in scan table. However, for Ad-Hoc mode, it can create
902 * the IBSS if it does not exist. On successful completion in either case,
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700903 * the function notifies the CFG802.11 subsystem of the new BSS connection.
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700904 */
905static int
906mwifiex_cfg80211_assoc(struct mwifiex_private *priv, size_t ssid_len, u8 *ssid,
907 u8 *bssid, int mode, struct ieee80211_channel *channel,
908 struct cfg80211_connect_params *sme, bool privacy)
909{
Amitkumar Karwarb9be5f32012-02-27 22:04:14 -0800910 struct cfg80211_ssid req_ssid;
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700911 int ret, auth_type = 0;
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700912 struct cfg80211_bss *bss = NULL;
913 u8 is_scanning_required = 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700914
Amitkumar Karwarb9be5f32012-02-27 22:04:14 -0800915 memset(&req_ssid, 0, sizeof(struct cfg80211_ssid));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700916
917 req_ssid.ssid_len = ssid_len;
918 if (ssid_len > IEEE80211_MAX_SSID_LEN) {
919 dev_err(priv->adapter->dev, "invalid SSID - aborting\n");
920 return -EINVAL;
921 }
922
923 memcpy(req_ssid.ssid, ssid, ssid_len);
924 if (!req_ssid.ssid_len || req_ssid.ssid[0] < 0x20) {
925 dev_err(priv->adapter->dev, "invalid SSID - aborting\n");
926 return -EINVAL;
927 }
928
929 /* disconnect before try to associate */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700930 mwifiex_deauthenticate(priv, NULL);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700931
932 if (channel)
933 ret = mwifiex_set_rf_channel(priv, channel,
Amitkumar Karwar3aebee02011-12-20 23:47:22 -0800934 priv->adapter->channel_type);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700935
Amitkumar Karwar6670f152012-02-09 18:32:22 -0800936 /* As this is new association, clear locally stored
937 * keys and security related flags */
938 priv->sec_info.wpa_enabled = false;
939 priv->sec_info.wpa2_enabled = false;
940 priv->wep_key_curr_index = 0;
Amitkumar Karwar00f157b2012-02-24 21:35:35 -0800941 priv->sec_info.encryption_mode = 0;
Amitkumar Karwara0f6d6c2012-02-24 21:36:05 -0800942 priv->sec_info.is_authtype_auto = 0;
Amitkumar Karwar6670f152012-02-09 18:32:22 -0800943 ret = mwifiex_set_encode(priv, NULL, 0, 0, 1);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700944
Bing Zhaoeecd8252011-03-28 17:55:41 -0700945 if (mode == NL80211_IFTYPE_ADHOC) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700946 /* "privacy" is set only for ad-hoc mode */
947 if (privacy) {
948 /*
Yogesh Ashok Powar2be50b82011-04-01 18:36:47 -0700949 * Keep WLAN_CIPHER_SUITE_WEP104 for now so that
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700950 * the firmware can find a matching network from the
951 * scan. The cfg80211 does not give us the encryption
952 * mode at this stage so just setting it to WEP here.
953 */
Marc Yang203afec2011-03-24 20:49:39 -0700954 priv->sec_info.encryption_mode =
Yogesh Ashok Powar2be50b82011-04-01 18:36:47 -0700955 WLAN_CIPHER_SUITE_WEP104;
Marc Yang203afec2011-03-24 20:49:39 -0700956 priv->sec_info.authentication_mode =
Marc Yangf986b6d2011-03-28 17:55:42 -0700957 NL80211_AUTHTYPE_OPEN_SYSTEM;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700958 }
959
960 goto done;
961 }
962
963 /* Now handle infra mode. "sme" is valid for infra mode only */
Amitkumar Karwara0f6d6c2012-02-24 21:36:05 -0800964 if (sme->auth_type == NL80211_AUTHTYPE_AUTOMATIC) {
Marc Yangf986b6d2011-03-28 17:55:42 -0700965 auth_type = NL80211_AUTHTYPE_OPEN_SYSTEM;
Amitkumar Karwara0f6d6c2012-02-24 21:36:05 -0800966 priv->sec_info.is_authtype_auto = 1;
967 } else {
968 auth_type = sme->auth_type;
969 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700970
971 if (sme->crypto.n_ciphers_pairwise) {
Yogesh Ashok Powar2be50b82011-04-01 18:36:47 -0700972 priv->sec_info.encryption_mode =
973 sme->crypto.ciphers_pairwise[0];
Marc Yang203afec2011-03-24 20:49:39 -0700974 priv->sec_info.authentication_mode = auth_type;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700975 }
976
977 if (sme->crypto.cipher_group) {
Yogesh Ashok Powar2be50b82011-04-01 18:36:47 -0700978 priv->sec_info.encryption_mode = sme->crypto.cipher_group;
Marc Yang203afec2011-03-24 20:49:39 -0700979 priv->sec_info.authentication_mode = auth_type;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700980 }
981 if (sme->ie)
982 ret = mwifiex_set_gen_ie(priv, sme->ie, sme->ie_len);
983
984 if (sme->key) {
Amitkumar Karware6faada2011-07-07 17:33:19 -0700985 if (mwifiex_is_alg_wep(priv->sec_info.encryption_mode)) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700986 dev_dbg(priv->adapter->dev,
987 "info: setting wep encryption"
988 " with key len %d\n", sme->key_len);
Amitkumar Karwar6670f152012-02-09 18:32:22 -0800989 priv->wep_key_curr_index = sme->key_idx;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700990 ret = mwifiex_set_encode(priv, sme->key, sme->key_len,
991 sme->key_idx, 0);
992 }
993 }
994done:
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700995 /*
996 * Scan entries are valid for some time (15 sec). So we can save one
997 * active scan time if we just try cfg80211_get_bss first. If it fails
998 * then request scan and cfg80211_get_bss() again for final output.
999 */
1000 while (1) {
1001 if (is_scanning_required) {
1002 /* Do specific SSID scanning */
1003 if (mwifiex_request_scan(priv, &req_ssid)) {
1004 dev_err(priv->adapter->dev, "scan error\n");
1005 return -EFAULT;
1006 }
1007 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001008
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001009 /* Find the BSS we want using available scan results */
1010 if (mode == NL80211_IFTYPE_ADHOC)
1011 bss = cfg80211_get_bss(priv->wdev->wiphy, channel,
1012 bssid, ssid, ssid_len,
1013 WLAN_CAPABILITY_IBSS,
1014 WLAN_CAPABILITY_IBSS);
1015 else
1016 bss = cfg80211_get_bss(priv->wdev->wiphy, channel,
1017 bssid, ssid, ssid_len,
1018 WLAN_CAPABILITY_ESS,
1019 WLAN_CAPABILITY_ESS);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001020
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001021 if (!bss) {
1022 if (is_scanning_required) {
Yogesh Ashok Powaraea07012012-03-13 19:22:35 -07001023 dev_warn(priv->adapter->dev,
1024 "assoc: requested bss not found in scan results\n");
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001025 break;
1026 }
1027 is_scanning_required = 1;
1028 } else {
Yogesh Ashok Powaraea07012012-03-13 19:22:35 -07001029 dev_dbg(priv->adapter->dev,
1030 "info: trying to associate to '%s' bssid %pM\n",
1031 (char *) req_ssid.ssid, bss->bssid);
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001032 memcpy(&priv->cfg_bssid, bss->bssid, ETH_ALEN);
1033 break;
1034 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001035 }
1036
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001037 if (mwifiex_bss_start(priv, bss, &req_ssid))
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001038 return -EFAULT;
1039
Bing Zhaoeecd8252011-03-28 17:55:41 -07001040 if (mode == NL80211_IFTYPE_ADHOC) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001041 /* Inform the BSS information to kernel, otherwise
1042 * kernel will give a panic after successful assoc */
1043 if (mwifiex_cfg80211_inform_ibss_bss(priv))
1044 return -EFAULT;
1045 }
1046
1047 return ret;
1048}
1049
1050/*
1051 * CFG802.11 operation handler for association request.
1052 *
1053 * This function does not work when the current mode is set to Ad-Hoc, or
1054 * when there is already an association procedure going on. The given BSS
1055 * information is used to associate.
1056 */
1057static int
1058mwifiex_cfg80211_connect(struct wiphy *wiphy, struct net_device *dev,
1059 struct cfg80211_connect_params *sme)
1060{
1061 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
1062 int ret = 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001063
Bing Zhaoeecd8252011-03-28 17:55:41 -07001064 if (priv->bss_mode == NL80211_IFTYPE_ADHOC) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001065 wiphy_err(wiphy, "received infra assoc request "
1066 "when station is in ibss mode\n");
1067 goto done;
1068 }
1069
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001070 wiphy_dbg(wiphy, "info: Trying to associate to %s and bssid %pM\n",
Yogesh Ashok Powaraea07012012-03-13 19:22:35 -07001071 (char *) sme->ssid, sme->bssid);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001072
1073 ret = mwifiex_cfg80211_assoc(priv, sme->ssid_len, sme->ssid, sme->bssid,
Bing Zhaoeecd8252011-03-28 17:55:41 -07001074 priv->bss_mode, sme->channel, sme, 0);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001075done:
Amitkumar Karwar38c9d662011-12-13 20:43:17 -08001076 if (!ret) {
1077 cfg80211_connect_result(priv->netdev, priv->cfg_bssid, NULL, 0,
1078 NULL, 0, WLAN_STATUS_SUCCESS,
1079 GFP_KERNEL);
1080 dev_dbg(priv->adapter->dev,
1081 "info: associated to bssid %pM successfully\n",
1082 priv->cfg_bssid);
1083 } else {
1084 dev_dbg(priv->adapter->dev,
1085 "info: association to bssid %pM failed\n",
1086 priv->cfg_bssid);
1087 memset(priv->cfg_bssid, 0, ETH_ALEN);
1088 }
1089
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001090 return ret;
1091}
1092
1093/*
1094 * CFG802.11 operation handler to join an IBSS.
1095 *
1096 * This function does not work in any mode other than Ad-Hoc, or if
1097 * a join operation is already in progress.
1098 */
1099static int
1100mwifiex_cfg80211_join_ibss(struct wiphy *wiphy, struct net_device *dev,
1101 struct cfg80211_ibss_params *params)
1102{
Yogesh Ashok Powarf540f9f2012-01-11 20:06:12 -08001103 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001104 int ret = 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001105
Bing Zhaoeecd8252011-03-28 17:55:41 -07001106 if (priv->bss_mode != NL80211_IFTYPE_ADHOC) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001107 wiphy_err(wiphy, "request to join ibss received "
1108 "when station is not in ibss mode\n");
1109 goto done;
1110 }
1111
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001112 wiphy_dbg(wiphy, "info: trying to join to %s and bssid %pM\n",
Yogesh Ashok Powaraea07012012-03-13 19:22:35 -07001113 (char *) params->ssid, params->bssid);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001114
1115 ret = mwifiex_cfg80211_assoc(priv, params->ssid_len, params->ssid,
Yogesh Ashok Powaraea07012012-03-13 19:22:35 -07001116 params->bssid, priv->bss_mode,
1117 params->channel, NULL, params->privacy);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001118done:
Amitkumar Karwar38c9d662011-12-13 20:43:17 -08001119 if (!ret) {
1120 cfg80211_ibss_joined(priv->netdev, priv->cfg_bssid, GFP_KERNEL);
1121 dev_dbg(priv->adapter->dev,
1122 "info: joined/created adhoc network with bssid"
1123 " %pM successfully\n", priv->cfg_bssid);
1124 } else {
1125 dev_dbg(priv->adapter->dev,
1126 "info: failed creating/joining adhoc network\n");
1127 }
1128
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001129 return ret;
1130}
1131
1132/*
1133 * CFG802.11 operation handler to leave an IBSS.
1134 *
1135 * This function does not work if a leave operation is
1136 * already in progress.
1137 */
1138static int
1139mwifiex_cfg80211_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
1140{
Yogesh Ashok Powarf540f9f2012-01-11 20:06:12 -08001141 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001142
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001143 wiphy_dbg(wiphy, "info: disconnecting from essid %pM\n",
Yogesh Ashok Powaraea07012012-03-13 19:22:35 -07001144 priv->cfg_bssid);
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001145 if (mwifiex_deauthenticate(priv, NULL))
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001146 return -EFAULT;
1147
Amitkumar Karwar38c9d662011-12-13 20:43:17 -08001148 memset(priv->cfg_bssid, 0, ETH_ALEN);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001149
1150 return 0;
1151}
1152
1153/*
1154 * CFG802.11 operation handler for scan request.
1155 *
1156 * This function issues a scan request to the firmware based upon
1157 * the user specified scan configuration. On successfull completion,
1158 * it also informs the results.
1159 */
1160static int
1161mwifiex_cfg80211_scan(struct wiphy *wiphy, struct net_device *dev,
1162 struct cfg80211_scan_request *request)
1163{
1164 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
Amitkumar Karwar38c9d662011-12-13 20:43:17 -08001165 int i;
1166 struct ieee80211_channel *chan;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001167
1168 wiphy_dbg(wiphy, "info: received scan request on %s\n", dev->name);
1169
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001170 priv->scan_request = request;
1171
Amitkumar Karwar38c9d662011-12-13 20:43:17 -08001172 priv->user_scan_cfg = kzalloc(sizeof(struct mwifiex_user_scan_cfg),
Yogesh Ashok Powaraea07012012-03-13 19:22:35 -07001173 GFP_KERNEL);
Amitkumar Karwar38c9d662011-12-13 20:43:17 -08001174 if (!priv->user_scan_cfg) {
1175 dev_err(priv->adapter->dev, "failed to alloc scan_req\n");
1176 return -ENOMEM;
1177 }
Amitkumar Karwarbe0b2812012-02-27 22:04:15 -08001178
1179 priv->user_scan_cfg->num_ssids = request->n_ssids;
1180 priv->user_scan_cfg->ssid_list = request->ssids;
1181
Avinash Patil13d7ba782012-04-09 20:06:56 -07001182 if (request->ie && request->ie_len) {
1183 for (i = 0; i < MWIFIEX_MAX_VSIE_NUM; i++) {
1184 if (priv->vs_ie[i].mask != MWIFIEX_VSIE_MASK_CLEAR)
1185 continue;
1186 priv->vs_ie[i].mask = MWIFIEX_VSIE_MASK_SCAN;
1187 memcpy(&priv->vs_ie[i].ie, request->ie,
1188 request->ie_len);
1189 break;
1190 }
1191 }
1192
Amitkumar Karwar38c9d662011-12-13 20:43:17 -08001193 for (i = 0; i < request->n_channels; i++) {
1194 chan = request->channels[i];
1195 priv->user_scan_cfg->chan_list[i].chan_number = chan->hw_value;
1196 priv->user_scan_cfg->chan_list[i].radio_type = chan->band;
1197
1198 if (chan->flags & IEEE80211_CHAN_PASSIVE_SCAN)
1199 priv->user_scan_cfg->chan_list[i].scan_type =
Yogesh Ashok Powaraea07012012-03-13 19:22:35 -07001200 MWIFIEX_SCAN_TYPE_PASSIVE;
Amitkumar Karwar38c9d662011-12-13 20:43:17 -08001201 else
1202 priv->user_scan_cfg->chan_list[i].scan_type =
Yogesh Ashok Powaraea07012012-03-13 19:22:35 -07001203 MWIFIEX_SCAN_TYPE_ACTIVE;
Amitkumar Karwar38c9d662011-12-13 20:43:17 -08001204
1205 priv->user_scan_cfg->chan_list[i].scan_time = 0;
1206 }
1207 if (mwifiex_set_user_scan_ioctl(priv, priv->user_scan_cfg))
1208 return -EFAULT;
1209
Avinash Patil13d7ba782012-04-09 20:06:56 -07001210 if (request->ie && request->ie_len) {
1211 for (i = 0; i < MWIFIEX_MAX_VSIE_NUM; i++) {
1212 if (priv->vs_ie[i].mask == MWIFIEX_VSIE_MASK_SCAN) {
1213 priv->vs_ie[i].mask = MWIFIEX_VSIE_MASK_CLEAR;
1214 memset(&priv->vs_ie[i].ie, 0,
1215 MWIFIEX_MAX_VSIE_LEN);
1216 }
1217 }
1218 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001219 return 0;
1220}
1221
1222/*
1223 * This function sets up the CFG802.11 specific HT capability fields
1224 * with default values.
1225 *
1226 * The following default values are set -
1227 * - HT Supported = True
Amitkumar Karwara46b7b52011-04-27 19:13:12 -07001228 * - Maximum AMPDU length factor = IEEE80211_HT_MAX_AMPDU_64K
1229 * - Minimum AMPDU spacing = IEEE80211_HT_MPDU_DENSITY_NONE
1230 * - HT Capabilities supported by firmware
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001231 * - MCS information, Rx mask = 0xff
1232 * - MCD information, Tx parameters = IEEE80211_HT_MCS_TX_DEFINED (0x01)
1233 */
1234static void
1235mwifiex_setup_ht_caps(struct ieee80211_sta_ht_cap *ht_info,
1236 struct mwifiex_private *priv)
1237{
1238 int rx_mcs_supp;
1239 struct ieee80211_mcs_info mcs_set;
1240 u8 *mcs = (u8 *)&mcs_set;
1241 struct mwifiex_adapter *adapter = priv->adapter;
1242
1243 ht_info->ht_supported = true;
Amitkumar Karwara46b7b52011-04-27 19:13:12 -07001244 ht_info->ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
1245 ht_info->ampdu_density = IEEE80211_HT_MPDU_DENSITY_NONE;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001246
1247 memset(&ht_info->mcs, 0, sizeof(ht_info->mcs));
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001248
Amitkumar Karwara46b7b52011-04-27 19:13:12 -07001249 /* Fill HT capability information */
1250 if (ISSUPP_CHANWIDTH40(adapter->hw_dot_11n_dev_cap))
1251 ht_info->cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
1252 else
1253 ht_info->cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
1254
1255 if (ISSUPP_SHORTGI20(adapter->hw_dot_11n_dev_cap))
1256 ht_info->cap |= IEEE80211_HT_CAP_SGI_20;
1257 else
1258 ht_info->cap &= ~IEEE80211_HT_CAP_SGI_20;
1259
1260 if (ISSUPP_SHORTGI40(adapter->hw_dot_11n_dev_cap))
1261 ht_info->cap |= IEEE80211_HT_CAP_SGI_40;
1262 else
1263 ht_info->cap &= ~IEEE80211_HT_CAP_SGI_40;
1264
1265 if (ISSUPP_RXSTBC(adapter->hw_dot_11n_dev_cap))
1266 ht_info->cap |= 1 << IEEE80211_HT_CAP_RX_STBC_SHIFT;
1267 else
1268 ht_info->cap &= ~(3 << IEEE80211_HT_CAP_RX_STBC_SHIFT);
1269
1270 if (ISSUPP_TXSTBC(adapter->hw_dot_11n_dev_cap))
1271 ht_info->cap |= IEEE80211_HT_CAP_TX_STBC;
1272 else
1273 ht_info->cap &= ~IEEE80211_HT_CAP_TX_STBC;
1274
1275 ht_info->cap &= ~IEEE80211_HT_CAP_MAX_AMSDU;
1276 ht_info->cap |= IEEE80211_HT_CAP_SM_PS;
1277
1278 rx_mcs_supp = GET_RXMCSSUPP(adapter->hw_dev_mcs_support);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001279 /* Set MCS for 1x1 */
1280 memset(mcs, 0xff, rx_mcs_supp);
1281 /* Clear all the other values */
1282 memset(&mcs[rx_mcs_supp], 0,
Yogesh Ashok Powaraea07012012-03-13 19:22:35 -07001283 sizeof(struct ieee80211_mcs_info) - rx_mcs_supp);
Bing Zhaoeecd8252011-03-28 17:55:41 -07001284 if (priv->bss_mode == NL80211_IFTYPE_STATION ||
Yogesh Ashok Powaraea07012012-03-13 19:22:35 -07001285 ISSUPP_CHANWIDTH40(adapter->hw_dot_11n_dev_cap))
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001286 /* Set MCS32 for infra mode or ad-hoc mode with 40MHz support */
1287 SETHT_MCS32(mcs_set.rx_mask);
1288
1289 memcpy((u8 *) &ht_info->mcs, mcs, sizeof(struct ieee80211_mcs_info));
1290
1291 ht_info->mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED;
1292}
1293
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -07001294/*
1295 * create a new virtual interface with the given name
1296 */
1297struct net_device *mwifiex_add_virtual_intf(struct wiphy *wiphy,
Yogesh Ashok Powaraea07012012-03-13 19:22:35 -07001298 char *name,
1299 enum nl80211_iftype type,
1300 u32 *flags,
1301 struct vif_params *params)
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -07001302{
1303 struct mwifiex_private *priv = mwifiex_cfg80211_get_priv(wiphy);
1304 struct mwifiex_adapter *adapter;
1305 struct net_device *dev;
1306 void *mdev_priv;
Avinash Patild6bffe82012-05-08 18:30:15 -07001307 struct wireless_dev *wdev;
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -07001308
1309 if (!priv)
1310 return NULL;
1311
1312 adapter = priv->adapter;
1313 if (!adapter)
1314 return NULL;
1315
1316 switch (type) {
1317 case NL80211_IFTYPE_UNSPECIFIED:
1318 case NL80211_IFTYPE_STATION:
1319 case NL80211_IFTYPE_ADHOC:
Avinash Patild6bffe82012-05-08 18:30:15 -07001320 priv = adapter->priv[MWIFIEX_BSS_TYPE_STA];
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -07001321 if (priv->bss_mode) {
Avinash Patild6bffe82012-05-08 18:30:15 -07001322 wiphy_err(wiphy,
1323 "cannot create multiple sta/adhoc ifaces\n");
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -07001324 return NULL;
1325 }
1326
Avinash Patild6bffe82012-05-08 18:30:15 -07001327 wdev = kzalloc(sizeof(struct wireless_dev), GFP_KERNEL);
1328 if (!wdev)
1329 return NULL;
1330
1331 wdev->wiphy = wiphy;
1332 priv->wdev = wdev;
1333 wdev->iftype = NL80211_IFTYPE_STATION;
1334
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -07001335 if (type == NL80211_IFTYPE_UNSPECIFIED)
1336 priv->bss_mode = NL80211_IFTYPE_STATION;
1337 else
1338 priv->bss_mode = type;
1339
1340 priv->bss_type = MWIFIEX_BSS_TYPE_STA;
1341 priv->frame_type = MWIFIEX_DATA_FRAME_TYPE_ETH_II;
Avinash Patild6bffe82012-05-08 18:30:15 -07001342 priv->bss_priority = MWIFIEX_BSS_ROLE_STA;
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -07001343 priv->bss_role = MWIFIEX_BSS_ROLE_STA;
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -07001344 priv->bss_num = 0;
1345
1346 break;
Avinash Patild6bffe82012-05-08 18:30:15 -07001347 case NL80211_IFTYPE_AP:
1348 priv = adapter->priv[MWIFIEX_BSS_TYPE_UAP];
1349
1350 if (priv->bss_mode) {
1351 wiphy_err(wiphy, "Can't create multiple AP interfaces");
1352 return NULL;
1353 }
1354
1355 wdev = kzalloc(sizeof(struct wireless_dev), GFP_KERNEL);
1356 if (!wdev)
1357 return NULL;
1358
1359 priv->wdev = wdev;
1360 wdev->wiphy = wiphy;
1361 wdev->iftype = NL80211_IFTYPE_AP;
1362
1363 priv->bss_type = MWIFIEX_BSS_TYPE_UAP;
1364 priv->frame_type = MWIFIEX_DATA_FRAME_TYPE_ETH_II;
1365 priv->bss_priority = MWIFIEX_BSS_ROLE_UAP;
1366 priv->bss_role = MWIFIEX_BSS_ROLE_UAP;
1367 priv->bss_started = 0;
1368 priv->bss_num = 0;
1369 priv->bss_mode = type;
1370
1371 break;
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -07001372 default:
1373 wiphy_err(wiphy, "type not supported\n");
1374 return NULL;
1375 }
1376
1377 dev = alloc_netdev_mq(sizeof(struct mwifiex_private *), name,
1378 ether_setup, 1);
1379 if (!dev) {
1380 wiphy_err(wiphy, "no memory available for netdevice\n");
1381 goto error;
1382 }
1383
Avinash Patild6bffe82012-05-08 18:30:15 -07001384 mwifiex_init_priv_params(priv, dev);
1385 priv->netdev = dev;
1386
1387 mwifiex_setup_ht_caps(&wiphy->bands[IEEE80211_BAND_2GHZ]->ht_cap, priv);
1388
1389 if (adapter->config_bands & BAND_A)
1390 mwifiex_setup_ht_caps(
1391 &wiphy->bands[IEEE80211_BAND_5GHZ]->ht_cap, priv);
1392
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -07001393 dev_net_set(dev, wiphy_net(wiphy));
1394 dev->ieee80211_ptr = priv->wdev;
1395 dev->ieee80211_ptr->iftype = priv->bss_mode;
1396 memcpy(dev->dev_addr, wiphy->perm_addr, ETH_ALEN);
1397 memcpy(dev->perm_addr, wiphy->perm_addr, ETH_ALEN);
1398 SET_NETDEV_DEV(dev, wiphy_dev(wiphy));
1399
1400 dev->flags |= IFF_BROADCAST | IFF_MULTICAST;
1401 dev->watchdog_timeo = MWIFIEX_DEFAULT_WATCHDOG_TIMEOUT;
1402 dev->hard_header_len += MWIFIEX_MIN_DATA_HEADER_LEN;
1403
1404 mdev_priv = netdev_priv(dev);
1405 *((unsigned long *) mdev_priv) = (unsigned long) priv;
1406
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -07001407 SET_NETDEV_DEV(dev, adapter->dev);
1408
1409 /* Register network device */
1410 if (register_netdevice(dev)) {
1411 wiphy_err(wiphy, "cannot register virtual network device\n");
1412 goto error;
1413 }
1414
1415 sema_init(&priv->async_sem, 1);
1416 priv->scan_pending_on_block = false;
1417
1418 dev_dbg(adapter->dev, "info: %s: Marvell 802.11 Adapter\n", dev->name);
1419
1420#ifdef CONFIG_DEBUG_FS
1421 mwifiex_dev_debugfs_init(priv);
1422#endif
1423 return dev;
1424error:
1425 if (dev && (dev->reg_state == NETREG_UNREGISTERED))
1426 free_netdev(dev);
1427 priv->bss_mode = NL80211_IFTYPE_UNSPECIFIED;
1428
1429 return NULL;
1430}
1431EXPORT_SYMBOL_GPL(mwifiex_add_virtual_intf);
1432
1433/*
1434 * del_virtual_intf: remove the virtual interface determined by dev
1435 */
1436int mwifiex_del_virtual_intf(struct wiphy *wiphy, struct net_device *dev)
1437{
Yogesh Ashok Powarf540f9f2012-01-11 20:06:12 -08001438 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -07001439
1440#ifdef CONFIG_DEBUG_FS
1441 mwifiex_dev_debugfs_remove(priv);
1442#endif
1443
1444 if (!netif_queue_stopped(priv->netdev))
1445 netif_stop_queue(priv->netdev);
1446
1447 if (netif_carrier_ok(priv->netdev))
1448 netif_carrier_off(priv->netdev);
1449
1450 if (dev->reg_state == NETREG_REGISTERED)
1451 unregister_netdevice(dev);
1452
1453 if (dev->reg_state == NETREG_UNREGISTERED)
1454 free_netdev(dev);
1455
1456 /* Clear the priv in adapter */
1457 priv->netdev = NULL;
1458
1459 priv->media_connected = false;
1460
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -07001461 priv->bss_mode = NL80211_IFTYPE_UNSPECIFIED;
1462
1463 return 0;
1464}
1465EXPORT_SYMBOL_GPL(mwifiex_del_virtual_intf);
1466
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001467/* station cfg80211 operations */
1468static struct cfg80211_ops mwifiex_cfg80211_ops = {
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -07001469 .add_virtual_intf = mwifiex_add_virtual_intf,
1470 .del_virtual_intf = mwifiex_del_virtual_intf,
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001471 .change_virtual_intf = mwifiex_cfg80211_change_virtual_intf,
1472 .scan = mwifiex_cfg80211_scan,
1473 .connect = mwifiex_cfg80211_connect,
1474 .disconnect = mwifiex_cfg80211_disconnect,
1475 .get_station = mwifiex_cfg80211_get_station,
Amitkumar Karwarf85aae62012-03-15 20:51:48 -07001476 .dump_station = mwifiex_cfg80211_dump_station,
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001477 .set_wiphy_params = mwifiex_cfg80211_set_wiphy_params,
1478 .set_channel = mwifiex_cfg80211_set_channel,
1479 .join_ibss = mwifiex_cfg80211_join_ibss,
1480 .leave_ibss = mwifiex_cfg80211_leave_ibss,
1481 .add_key = mwifiex_cfg80211_add_key,
1482 .del_key = mwifiex_cfg80211_del_key,
1483 .set_default_key = mwifiex_cfg80211_set_default_key,
1484 .set_power_mgmt = mwifiex_cfg80211_set_power_mgmt,
1485 .set_tx_power = mwifiex_cfg80211_set_tx_power,
Yogesh Ashok Powar5d82c532011-07-11 20:04:44 -07001486 .set_bitrate_mask = mwifiex_cfg80211_set_bitrate_mask,
Amitkumar Karwarfa444bf2012-03-15 20:51:51 -07001487 .set_cqm_rssi_config = mwifiex_cfg80211_set_cqm_rssi_config,
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001488};
1489
1490/*
1491 * This function registers the device with CFG802.11 subsystem.
1492 *
1493 * The function creates the wireless device/wiphy, populates it with
1494 * default parameters and handler function pointers, and finally
1495 * registers the device.
1496 */
Avinash Patild6bffe82012-05-08 18:30:15 -07001497
1498int mwifiex_register_cfg80211(struct mwifiex_adapter *adapter)
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001499{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -07001500 int ret;
1501 void *wdev_priv;
Avinash Patild6bffe82012-05-08 18:30:15 -07001502 struct wiphy *wiphy;
1503 struct mwifiex_private *priv = adapter->priv[MWIFIEX_BSS_TYPE_STA];
Amitkumar Karwar9e04a7c2012-04-09 20:06:54 -07001504 u8 *country_code;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001505
Avinash Patild6bffe82012-05-08 18:30:15 -07001506 /* create a new wiphy for use with cfg80211 */
1507 wiphy = wiphy_new(&mwifiex_cfg80211_ops,
1508 sizeof(struct mwifiex_adapter *));
1509 if (!wiphy) {
1510 dev_err(adapter->dev, "%s: creating new wiphy\n", __func__);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001511 return -ENOMEM;
1512 }
Avinash Patild6bffe82012-05-08 18:30:15 -07001513 wiphy->max_scan_ssids = MWIFIEX_MAX_SSID_LIST_LENGTH;
1514 wiphy->max_scan_ie_len = MWIFIEX_MAX_VSIE_LEN;
1515 wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
1516 BIT(NL80211_IFTYPE_ADHOC) |
1517 BIT(NL80211_IFTYPE_AP);
Amitkumar Karwaradc89592011-04-27 19:13:11 -07001518
Avinash Patild6bffe82012-05-08 18:30:15 -07001519 wiphy->bands[IEEE80211_BAND_2GHZ] = &mwifiex_band_2ghz;
1520 if (adapter->config_bands & BAND_A)
1521 wiphy->bands[IEEE80211_BAND_5GHZ] = &mwifiex_band_5ghz;
1522 else
1523 wiphy->bands[IEEE80211_BAND_5GHZ] = NULL;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001524
Avinash Patilcd8440d2012-05-08 18:30:16 -07001525 wiphy->iface_combinations = &mwifiex_iface_comb_ap_sta;
1526 wiphy->n_iface_combinations = 1;
1527
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001528 /* Initialize cipher suits */
Avinash Patild6bffe82012-05-08 18:30:15 -07001529 wiphy->cipher_suites = mwifiex_cipher_suites;
1530 wiphy->n_cipher_suites = ARRAY_SIZE(mwifiex_cipher_suites);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001531
Avinash Patild6bffe82012-05-08 18:30:15 -07001532 memcpy(wiphy->perm_addr, priv->curr_addr, ETH_ALEN);
1533 wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
1534 wiphy->flags |= WIPHY_FLAG_HAVE_AP_SME | WIPHY_FLAG_CUSTOM_REGULATORY;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001535
Amitkumar Karwarb5abcf02012-04-16 21:36:52 -07001536 /* Reserve space for mwifiex specific private data for BSS */
Avinash Patild6bffe82012-05-08 18:30:15 -07001537 wiphy->bss_priv_size = sizeof(struct mwifiex_bss_priv);
Amitkumar Karwar5116f3c2011-09-21 21:43:23 -07001538
Avinash Patild6bffe82012-05-08 18:30:15 -07001539 wiphy->reg_notifier = mwifiex_reg_notifier;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001540
1541 /* Set struct mwifiex_private pointer in wiphy_priv */
Avinash Patild6bffe82012-05-08 18:30:15 -07001542 wdev_priv = wiphy_priv(wiphy);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001543
1544 *(unsigned long *) wdev_priv = (unsigned long) priv;
1545
Avinash Patild6bffe82012-05-08 18:30:15 -07001546 set_wiphy_dev(wiphy, (struct device *)priv->adapter->dev);
Yogesh Ashok Powara7b21162011-06-13 09:49:27 +05301547
Avinash Patild6bffe82012-05-08 18:30:15 -07001548 ret = wiphy_register(wiphy);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001549 if (ret < 0) {
Avinash Patild6bffe82012-05-08 18:30:15 -07001550 dev_err(adapter->dev,
1551 "%s: wiphy_register failed: %d\n", __func__, ret);
1552 wiphy_free(wiphy);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001553 return ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001554 }
Amitkumar Karwar9e04a7c2012-04-09 20:06:54 -07001555 country_code = mwifiex_11d_code_2_region(priv->adapter->region_code);
Avinash Patild6bffe82012-05-08 18:30:15 -07001556 if (country_code && regulatory_hint(wiphy, country_code))
1557 dev_err(adapter->dev, "regulatory_hint() failed\n");
Amitkumar Karwar9e04a7c2012-04-09 20:06:54 -07001558
Avinash Patild6bffe82012-05-08 18:30:15 -07001559 adapter->wiphy = wiphy;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001560 return ret;
1561}