blob: aa619186d9b65eef4b60f710e1b8aa4c212f32c1 [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
Amitkumar Karwarcc0ba0d52012-09-10 18:30:47 -070040static const struct ieee80211_regdomain mwifiex_world_regdom_custom = {
41 .n_reg_rules = 7,
42 .alpha2 = "99",
43 .reg_rules = {
44 /* Channel 1 - 11 */
45 REG_RULE(2412-10, 2462+10, 40, 3, 20, 0),
46 /* Channel 12 - 13 */
47 REG_RULE(2467-10, 2472+10, 20, 3, 20,
48 NL80211_RRF_PASSIVE_SCAN | NL80211_RRF_NO_IBSS),
49 /* Channel 14 */
50 REG_RULE(2484-10, 2484+10, 20, 3, 20,
51 NL80211_RRF_PASSIVE_SCAN | NL80211_RRF_NO_IBSS |
52 NL80211_RRF_NO_OFDM),
53 /* Channel 36 - 48 */
54 REG_RULE(5180-10, 5240+10, 40, 3, 20,
55 NL80211_RRF_PASSIVE_SCAN | NL80211_RRF_NO_IBSS),
56 /* Channel 149 - 165 */
57 REG_RULE(5745-10, 5825+10, 40, 3, 20,
58 NL80211_RRF_PASSIVE_SCAN | NL80211_RRF_NO_IBSS),
59 /* Channel 52 - 64 */
60 REG_RULE(5260-10, 5320+10, 40, 3, 30,
61 NL80211_RRF_PASSIVE_SCAN | NL80211_RRF_NO_IBSS |
62 NL80211_RRF_DFS),
63 /* Channel 100 - 140 */
64 REG_RULE(5500-10, 5700+10, 40, 3, 30,
65 NL80211_RRF_PASSIVE_SCAN | NL80211_RRF_NO_IBSS |
66 NL80211_RRF_DFS),
67 }
68};
69
Bing Zhao5e6e3a92011-03-21 18:00:50 -070070/*
71 * This function maps the nl802.11 channel type into driver channel type.
72 *
73 * The mapping is as follows -
Amitkumar Karwar21c3ba32011-12-20 23:47:21 -080074 * NL80211_CHAN_NO_HT -> IEEE80211_HT_PARAM_CHA_SEC_NONE
75 * NL80211_CHAN_HT20 -> IEEE80211_HT_PARAM_CHA_SEC_NONE
76 * NL80211_CHAN_HT40PLUS -> IEEE80211_HT_PARAM_CHA_SEC_ABOVE
77 * NL80211_CHAN_HT40MINUS -> IEEE80211_HT_PARAM_CHA_SEC_BELOW
78 * Others -> IEEE80211_HT_PARAM_CHA_SEC_NONE
Bing Zhao5e6e3a92011-03-21 18:00:50 -070079 */
Amitkumar Karwar21c3ba32011-12-20 23:47:21 -080080static u8
Amitkumar Karwar05910f42012-07-13 20:09:32 -070081mwifiex_chan_type_to_sec_chan_offset(enum nl80211_channel_type chan_type)
Bing Zhao5e6e3a92011-03-21 18:00:50 -070082{
Amitkumar Karwar05910f42012-07-13 20:09:32 -070083 switch (chan_type) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -070084 case NL80211_CHAN_NO_HT:
85 case NL80211_CHAN_HT20:
Amitkumar Karwar21c3ba32011-12-20 23:47:21 -080086 return IEEE80211_HT_PARAM_CHA_SEC_NONE;
Bing Zhao5e6e3a92011-03-21 18:00:50 -070087 case NL80211_CHAN_HT40PLUS:
Amitkumar Karwar21c3ba32011-12-20 23:47:21 -080088 return IEEE80211_HT_PARAM_CHA_SEC_ABOVE;
Bing Zhao5e6e3a92011-03-21 18:00:50 -070089 case NL80211_CHAN_HT40MINUS:
Amitkumar Karwar21c3ba32011-12-20 23:47:21 -080090 return IEEE80211_HT_PARAM_CHA_SEC_BELOW;
Bing Zhao5e6e3a92011-03-21 18:00:50 -070091 default:
Amitkumar Karwar21c3ba32011-12-20 23:47:21 -080092 return IEEE80211_HT_PARAM_CHA_SEC_NONE;
Bing Zhao5e6e3a92011-03-21 18:00:50 -070093 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -070094}
95
96/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -070097 * This function checks whether WEP is set.
98 */
99static int
100mwifiex_is_alg_wep(u32 cipher)
101{
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700102 switch (cipher) {
Yogesh Ashok Powar2be50b82011-04-01 18:36:47 -0700103 case WLAN_CIPHER_SUITE_WEP40:
104 case WLAN_CIPHER_SUITE_WEP104:
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700105 return 1;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700106 default:
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700107 break;
108 }
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700109
110 return 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700111}
112
113/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700114 * This function retrieves the private structure from kernel wiphy structure.
115 */
Avinash Patil67fdf392012-05-08 18:30:17 -0700116static void *mwifiex_cfg80211_get_adapter(struct wiphy *wiphy)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700117{
118 return (void *) (*(unsigned long *) wiphy_priv(wiphy));
119}
120
121/*
122 * CFG802.11 operation handler to delete a network key.
123 */
124static int
125mwifiex_cfg80211_del_key(struct wiphy *wiphy, struct net_device *netdev,
126 u8 key_index, bool pairwise, const u8 *mac_addr)
127{
Yogesh Ashok Powarf540f9f2012-01-11 20:06:12 -0800128 struct mwifiex_private *priv = mwifiex_netdev_get_priv(netdev);
Avinash Patil75edd2c2012-05-08 18:30:18 -0700129 const u8 bc_mac[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
130 const u8 *peer_mac = pairwise ? mac_addr : bc_mac;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700131
Ying Luo53b11232012-08-03 18:06:13 -0700132 if (mwifiex_set_encode(priv, NULL, NULL, 0, key_index, peer_mac, 1)) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700133 wiphy_err(wiphy, "deleting the crypto keys\n");
134 return -EFAULT;
135 }
136
137 wiphy_dbg(wiphy, "info: crypto keys deleted\n");
138 return 0;
139}
140
141/*
142 * CFG802.11 operation handler to set Tx power.
143 */
144static int
145mwifiex_cfg80211_set_tx_power(struct wiphy *wiphy,
146 enum nl80211_tx_power_setting type,
Luis R. Rodriguez742c29f2011-11-28 16:38:50 -0500147 int mbm)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700148{
Avinash Patil67fdf392012-05-08 18:30:17 -0700149 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
150 struct mwifiex_private *priv;
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700151 struct mwifiex_power_cfg power_cfg;
Luis R. Rodriguez742c29f2011-11-28 16:38:50 -0500152 int dbm = MBM_TO_DBM(mbm);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700153
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700154 if (type == NL80211_TX_POWER_FIXED) {
155 power_cfg.is_power_auto = 0;
156 power_cfg.power_level = dbm;
157 } else {
158 power_cfg.is_power_auto = 1;
159 }
160
Avinash Patil67fdf392012-05-08 18:30:17 -0700161 priv = mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY);
162
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700163 return mwifiex_set_tx_power(priv, &power_cfg);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700164}
165
166/*
167 * CFG802.11 operation handler to set Power Save option.
168 *
169 * The timeout value, if provided, is currently ignored.
170 */
171static int
172mwifiex_cfg80211_set_power_mgmt(struct wiphy *wiphy,
173 struct net_device *dev,
174 bool enabled, int timeout)
175{
Yogesh Ashok Powarf540f9f2012-01-11 20:06:12 -0800176 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700177 u32 ps_mode;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700178
179 if (timeout)
180 wiphy_dbg(wiphy,
Yogesh Ashok Powaraea07012012-03-13 19:22:35 -0700181 "info: ignore timeout value for IEEE Power Save\n");
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700182
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700183 ps_mode = enabled;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700184
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700185 return mwifiex_drv_set_power(priv, &ps_mode);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700186}
187
188/*
189 * CFG802.11 operation handler to set the default network key.
190 */
191static int
192mwifiex_cfg80211_set_default_key(struct wiphy *wiphy, struct net_device *netdev,
193 u8 key_index, bool unicast,
194 bool multicast)
195{
Yogesh Ashok Powarf540f9f2012-01-11 20:06:12 -0800196 struct mwifiex_private *priv = mwifiex_netdev_get_priv(netdev);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700197
Amitkumar Karwar2d3d0a82011-04-01 18:36:46 -0700198 /* Return if WEP key not configured */
Amitkumar Karwar5eb02e42012-02-24 21:36:04 -0800199 if (!priv->sec_info.wep_enabled)
Amitkumar Karwar2d3d0a82011-04-01 18:36:46 -0700200 return 0;
201
Avinash Patil96893532012-06-15 12:21:55 -0700202 if (priv->bss_type == MWIFIEX_BSS_TYPE_UAP) {
203 priv->wep_key_curr_index = key_index;
Ying Luo53b11232012-08-03 18:06:13 -0700204 } else if (mwifiex_set_encode(priv, NULL, NULL, 0, key_index,
205 NULL, 0)) {
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700206 wiphy_err(wiphy, "set default Tx key index\n");
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700207 return -EFAULT;
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700208 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700209
210 return 0;
211}
212
213/*
214 * CFG802.11 operation handler to add a network key.
215 */
216static int
217mwifiex_cfg80211_add_key(struct wiphy *wiphy, struct net_device *netdev,
218 u8 key_index, bool pairwise, const u8 *mac_addr,
219 struct key_params *params)
220{
Yogesh Ashok Powarf540f9f2012-01-11 20:06:12 -0800221 struct mwifiex_private *priv = mwifiex_netdev_get_priv(netdev);
Avinash Patil96893532012-06-15 12:21:55 -0700222 struct mwifiex_wep_key *wep_key;
Avinash Patil75edd2c2012-05-08 18:30:18 -0700223 const u8 bc_mac[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
224 const u8 *peer_mac = pairwise ? mac_addr : bc_mac;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700225
Avinash Patil96893532012-06-15 12:21:55 -0700226 if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_UAP &&
227 (params->cipher == WLAN_CIPHER_SUITE_WEP40 ||
228 params->cipher == WLAN_CIPHER_SUITE_WEP104)) {
229 if (params->key && params->key_len) {
230 wep_key = &priv->wep_key[key_index];
231 memset(wep_key, 0, sizeof(struct mwifiex_wep_key));
232 memcpy(wep_key->key_material, params->key,
233 params->key_len);
234 wep_key->key_index = key_index;
235 wep_key->key_length = params->key_len;
236 priv->sec_info.wep_enabled = 1;
237 }
238 return 0;
239 }
240
Ying Luo53b11232012-08-03 18:06:13 -0700241 if (mwifiex_set_encode(priv, params, params->key, params->key_len,
Avinash Patil75edd2c2012-05-08 18:30:18 -0700242 key_index, peer_mac, 0)) {
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700243 wiphy_err(wiphy, "crypto keys added\n");
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700244 return -EFAULT;
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700245 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700246
247 return 0;
248}
249
250/*
251 * This function sends domain information to the firmware.
252 *
253 * The following information are passed to the firmware -
254 * - Country codes
255 * - Sub bands (first channel, number of channels, maximum Tx power)
256 */
257static int mwifiex_send_domain_info_cmd_fw(struct wiphy *wiphy)
258{
259 u8 no_of_triplet = 0;
260 struct ieee80211_country_ie_triplet *t;
261 u8 no_of_parsed_chan = 0;
262 u8 first_chan = 0, next_chan = 0, max_pwr = 0;
263 u8 i, flag = 0;
264 enum ieee80211_band band;
265 struct ieee80211_supported_band *sband;
266 struct ieee80211_channel *ch;
Avinash Patil67fdf392012-05-08 18:30:17 -0700267 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
268 struct mwifiex_private *priv;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700269 struct mwifiex_802_11d_domain_reg *domain_info = &adapter->domain_reg;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700270
271 /* Set country code */
Avinash Patil67fdf392012-05-08 18:30:17 -0700272 domain_info->country_code[0] = adapter->country_code[0];
273 domain_info->country_code[1] = adapter->country_code[1];
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700274 domain_info->country_code[2] = ' ';
275
276 band = mwifiex_band_to_radio_type(adapter->config_bands);
277 if (!wiphy->bands[band]) {
278 wiphy_err(wiphy, "11D: setting domain info in FW\n");
279 return -1;
280 }
281
282 sband = wiphy->bands[band];
283
284 for (i = 0; i < sband->n_channels ; i++) {
285 ch = &sband->channels[i];
286 if (ch->flags & IEEE80211_CHAN_DISABLED)
287 continue;
288
289 if (!flag) {
290 flag = 1;
291 first_chan = (u32) ch->hw_value;
292 next_chan = first_chan;
Amitkumar Karwar34202e22012-06-27 19:57:59 -0700293 max_pwr = ch->max_reg_power;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700294 no_of_parsed_chan = 1;
295 continue;
296 }
297
298 if (ch->hw_value == next_chan + 1 &&
Amitkumar Karwar34202e22012-06-27 19:57:59 -0700299 ch->max_reg_power == max_pwr) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700300 next_chan++;
301 no_of_parsed_chan++;
302 } else {
303 t = &domain_info->triplet[no_of_triplet];
304 t->chans.first_channel = first_chan;
305 t->chans.num_channels = no_of_parsed_chan;
306 t->chans.max_power = max_pwr;
307 no_of_triplet++;
308 first_chan = (u32) ch->hw_value;
309 next_chan = first_chan;
Amitkumar Karwar34202e22012-06-27 19:57:59 -0700310 max_pwr = ch->max_reg_power;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700311 no_of_parsed_chan = 1;
312 }
313 }
314
315 if (flag) {
316 t = &domain_info->triplet[no_of_triplet];
317 t->chans.first_channel = first_chan;
318 t->chans.num_channels = no_of_parsed_chan;
319 t->chans.max_power = max_pwr;
320 no_of_triplet++;
321 }
322
323 domain_info->no_of_triplet = no_of_triplet;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700324
Avinash Patil67fdf392012-05-08 18:30:17 -0700325 priv = mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY);
326
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700327 if (mwifiex_send_cmd_async(priv, HostCmd_CMD_802_11D_DOMAIN_INFO,
Yogesh Ashok Powaraea07012012-03-13 19:22:35 -0700328 HostCmd_ACT_GEN_SET, 0, NULL)) {
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700329 wiphy_err(wiphy, "11D: setting domain info in FW\n");
330 return -1;
331 }
332
333 return 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700334}
335
336/*
337 * CFG802.11 regulatory domain callback function.
338 *
339 * This function is called when the regulatory domain is changed due to the
340 * following reasons -
341 * - Set by driver
342 * - Set by system core
343 * - Set by user
344 * - Set bt Country IE
345 */
346static int mwifiex_reg_notifier(struct wiphy *wiphy,
Yogesh Ashok Powaraea07012012-03-13 19:22:35 -0700347 struct regulatory_request *request)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700348{
Avinash Patil67fdf392012-05-08 18:30:17 -0700349 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700350
Avinash Patil67fdf392012-05-08 18:30:17 -0700351 wiphy_dbg(wiphy, "info: cfg80211 regulatory domain callback for %c%c\n",
352 request->alpha2[0], request->alpha2[1]);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700353
Avinash Patil67fdf392012-05-08 18:30:17 -0700354 memcpy(adapter->country_code, request->alpha2, sizeof(request->alpha2));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700355
356 switch (request->initiator) {
357 case NL80211_REGDOM_SET_BY_DRIVER:
358 case NL80211_REGDOM_SET_BY_CORE:
359 case NL80211_REGDOM_SET_BY_USER:
360 break;
361 /* Todo: apply driver specific changes in channel flags based
362 on the request initiator if necessary. */
363 case NL80211_REGDOM_SET_BY_COUNTRY_IE:
364 break;
365 }
366 mwifiex_send_domain_info_cmd_fw(wiphy);
367
368 return 0;
369}
370
371/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700372 * This function sets the fragmentation threshold.
373 *
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700374 * The fragmentation threshold value must lie between MWIFIEX_FRAG_MIN_VALUE
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700375 * and MWIFIEX_FRAG_MAX_VALUE.
376 */
377static int
378mwifiex_set_frag(struct mwifiex_private *priv, u32 frag_thr)
379{
Yogesh Ashok Powaraea07012012-03-13 19:22:35 -0700380 if (frag_thr < MWIFIEX_FRAG_MIN_VALUE ||
381 frag_thr > MWIFIEX_FRAG_MAX_VALUE)
Avinash Patil9b930ea2012-05-08 18:30:23 -0700382 frag_thr = MWIFIEX_FRAG_MAX_VALUE;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700383
Avinash Patil9b930ea2012-05-08 18:30:23 -0700384 return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_SNMP_MIB,
385 HostCmd_ACT_GEN_SET, FRAG_THRESH_I,
386 &frag_thr);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700387}
388
389/*
390 * This function sets the RTS threshold.
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700391
392 * The rts value must lie between MWIFIEX_RTS_MIN_VALUE
393 * and MWIFIEX_RTS_MAX_VALUE.
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700394 */
395static int
396mwifiex_set_rts(struct mwifiex_private *priv, u32 rts_thr)
397{
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700398 if (rts_thr < MWIFIEX_RTS_MIN_VALUE || rts_thr > MWIFIEX_RTS_MAX_VALUE)
399 rts_thr = MWIFIEX_RTS_MAX_VALUE;
400
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700401 return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_SNMP_MIB,
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700402 HostCmd_ACT_GEN_SET, RTS_THRESH_I,
403 &rts_thr);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700404}
405
406/*
407 * CFG802.11 operation handler to set wiphy parameters.
408 *
409 * This function can be used to set the RTS threshold and the
410 * Fragmentation threshold of the driver.
411 */
412static int
413mwifiex_cfg80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
414{
Avinash Patil67fdf392012-05-08 18:30:17 -0700415 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
Avinash Patil9b930ea2012-05-08 18:30:23 -0700416 struct mwifiex_private *priv;
417 struct mwifiex_uap_bss_param *bss_cfg;
418 int ret, bss_started, i;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700419
Avinash Patil9b930ea2012-05-08 18:30:23 -0700420 for (i = 0; i < adapter->priv_num; i++) {
421 priv = adapter->priv[i];
422
423 switch (priv->bss_role) {
424 case MWIFIEX_BSS_ROLE_UAP:
425 bss_cfg = kzalloc(sizeof(struct mwifiex_uap_bss_param),
426 GFP_KERNEL);
427 if (!bss_cfg)
428 return -ENOMEM;
429
430 mwifiex_set_sys_config_invalid_data(bss_cfg);
431
432 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
433 bss_cfg->rts_threshold = wiphy->rts_threshold;
434 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
435 bss_cfg->frag_threshold = wiphy->frag_threshold;
436 if (changed & WIPHY_PARAM_RETRY_LONG)
437 bss_cfg->retry_limit = wiphy->retry_long;
438
439 bss_started = priv->bss_started;
440
441 ret = mwifiex_send_cmd_sync(priv,
442 HostCmd_CMD_UAP_BSS_STOP,
443 HostCmd_ACT_GEN_SET, 0,
444 NULL);
445 if (ret) {
446 wiphy_err(wiphy, "Failed to stop the BSS\n");
447 kfree(bss_cfg);
448 return ret;
449 }
450
451 ret = mwifiex_send_cmd_async(priv,
452 HostCmd_CMD_UAP_SYS_CONFIG,
453 HostCmd_ACT_GEN_SET,
Avinash Patile76268d2012-05-08 18:30:27 -0700454 UAP_BSS_PARAMS_I, bss_cfg);
Avinash Patil9b930ea2012-05-08 18:30:23 -0700455
456 kfree(bss_cfg);
457
458 if (ret) {
459 wiphy_err(wiphy, "Failed to set bss config\n");
460 return ret;
461 }
462
463 if (!bss_started)
464 break;
465
466 ret = mwifiex_send_cmd_async(priv,
467 HostCmd_CMD_UAP_BSS_START,
468 HostCmd_ACT_GEN_SET, 0,
469 NULL);
470 if (ret) {
471 wiphy_err(wiphy, "Failed to start BSS\n");
472 return ret;
473 }
474
475 break;
476 case MWIFIEX_BSS_ROLE_STA:
477 if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
478 ret = mwifiex_set_rts(priv,
479 wiphy->rts_threshold);
480 if (ret)
481 return ret;
482 }
483 if (changed & WIPHY_PARAM_FRAG_THRESHOLD) {
484 ret = mwifiex_set_frag(priv,
485 wiphy->frag_threshold);
486 if (ret)
487 return ret;
488 }
489 break;
490 }
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700491 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700492
Avinash Patil9b930ea2012-05-08 18:30:23 -0700493 return 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700494}
495
496/*
497 * CFG802.11 operation handler to change interface type.
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700498 */
499static int
500mwifiex_cfg80211_change_virtual_intf(struct wiphy *wiphy,
501 struct net_device *dev,
502 enum nl80211_iftype type, u32 *flags,
503 struct vif_params *params)
504{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700505 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700506 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
Bing Zhaoeecd8252011-03-28 17:55:41 -0700507
Avinash Patil4f023412012-05-08 18:30:22 -0700508 switch (dev->ieee80211_ptr->iftype) {
Bing Zhaoeecd8252011-03-28 17:55:41 -0700509 case NL80211_IFTYPE_ADHOC:
Avinash Patil4f023412012-05-08 18:30:22 -0700510 switch (type) {
511 case NL80211_IFTYPE_STATION:
512 break;
513 case NL80211_IFTYPE_UNSPECIFIED:
514 wiphy_warn(wiphy, "%s: kept type as IBSS\n", dev->name);
515 case NL80211_IFTYPE_ADHOC: /* This shouldn't happen */
516 return 0;
517 case NL80211_IFTYPE_AP:
518 default:
519 wiphy_err(wiphy, "%s: changing to %d not supported\n",
520 dev->name, type);
521 return -EOPNOTSUPP;
522 }
Bing Zhaoeecd8252011-03-28 17:55:41 -0700523 break;
524 case NL80211_IFTYPE_STATION:
Avinash Patil4f023412012-05-08 18:30:22 -0700525 switch (type) {
526 case NL80211_IFTYPE_ADHOC:
527 break;
528 case NL80211_IFTYPE_UNSPECIFIED:
529 wiphy_warn(wiphy, "%s: kept type as STA\n", dev->name);
530 case NL80211_IFTYPE_STATION: /* This shouldn't happen */
531 return 0;
532 case NL80211_IFTYPE_AP:
533 default:
534 wiphy_err(wiphy, "%s: changing to %d not supported\n",
535 dev->name, type);
536 return -EOPNOTSUPP;
537 }
Bing Zhaoeecd8252011-03-28 17:55:41 -0700538 break;
Avinash Patil4f023412012-05-08 18:30:22 -0700539 case NL80211_IFTYPE_AP:
540 switch (type) {
541 case NL80211_IFTYPE_UNSPECIFIED:
542 wiphy_warn(wiphy, "%s: kept type as AP\n", dev->name);
543 case NL80211_IFTYPE_AP: /* This shouldn't happen */
544 return 0;
545 case NL80211_IFTYPE_ADHOC:
546 case NL80211_IFTYPE_STATION:
547 default:
548 wiphy_err(wiphy, "%s: changing to %d not supported\n",
549 dev->name, type);
550 return -EOPNOTSUPP;
551 }
552 break;
Bing Zhaoeecd8252011-03-28 17:55:41 -0700553 default:
Avinash Patil4f023412012-05-08 18:30:22 -0700554 wiphy_err(wiphy, "%s: unknown iftype: %d\n",
555 dev->name, dev->ieee80211_ptr->iftype);
556 return -EOPNOTSUPP;
Bing Zhaoeecd8252011-03-28 17:55:41 -0700557 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700558
Avinash Patil4f023412012-05-08 18:30:22 -0700559 dev->ieee80211_ptr->iftype = type;
560 priv->bss_mode = type;
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700561 mwifiex_deauthenticate(priv, NULL);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700562
Marc Yangf986b6d2011-03-28 17:55:42 -0700563 priv->sec_info.authentication_mode = NL80211_AUTHTYPE_OPEN_SYSTEM;
Bing Zhaoeecd8252011-03-28 17:55:41 -0700564
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700565 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_SET_BSS_MODE,
566 HostCmd_ACT_GEN_SET, 0, NULL);
Bing Zhaoeecd8252011-03-28 17:55:41 -0700567
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700568 return ret;
569}
570
571/*
572 * This function dumps the station information on a buffer.
573 *
574 * The following information are shown -
575 * - Total bytes transmitted
576 * - Total bytes received
577 * - Total packets transmitted
578 * - Total packets received
579 * - Signal quality level
580 * - Transmission rate
581 */
582static int
583mwifiex_dump_station_info(struct mwifiex_private *priv,
584 struct station_info *sinfo)
585{
Amitkumar Karwar006606c2012-07-13 20:09:31 -0700586 u32 rate;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700587
588 sinfo->filled = STATION_INFO_RX_BYTES | STATION_INFO_TX_BYTES |
Amitkumar Karwar7013d3e2012-03-15 20:51:50 -0700589 STATION_INFO_RX_PACKETS | STATION_INFO_TX_PACKETS |
590 STATION_INFO_TX_BITRATE |
591 STATION_INFO_SIGNAL | STATION_INFO_SIGNAL_AVG;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700592
593 /* Get signal information from the firmware */
Amitkumar Karwar958a4a82012-03-15 20:51:49 -0700594 if (mwifiex_send_cmd_sync(priv, HostCmd_CMD_RSSI_INFO,
595 HostCmd_ACT_GEN_GET, 0, NULL)) {
596 dev_err(priv->adapter->dev, "failed to get signal information\n");
597 return -EFAULT;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700598 }
599
600 if (mwifiex_drv_get_data_rate(priv, &rate)) {
601 dev_err(priv->adapter->dev, "getting data rate\n");
Amitkumar Karwar958a4a82012-03-15 20:51:49 -0700602 return -EFAULT;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700603 }
604
Amitkumar Karwarcaf60a62012-02-02 20:48:58 -0800605 /* Get DTIM period information from firmware */
606 mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_SNMP_MIB,
607 HostCmd_ACT_GEN_GET, DTIM_PERIOD_I,
608 &priv->dtim_period);
609
Amitkumar Karwar4ec6f9c2011-09-26 20:37:25 -0700610 /*
611 * Bit 0 in tx_htinfo indicates that current Tx rate is 11n rate. Valid
Amitkumar Karwarfe020122012-07-11 18:12:57 -0700612 * MCS index values for us are 0 to 15.
Amitkumar Karwar4ec6f9c2011-09-26 20:37:25 -0700613 */
Amitkumar Karwarfe020122012-07-11 18:12:57 -0700614 if ((priv->tx_htinfo & BIT(0)) && (priv->tx_rate < 16)) {
Amitkumar Karwar4ec6f9c2011-09-26 20:37:25 -0700615 sinfo->txrate.mcs = priv->tx_rate;
616 sinfo->txrate.flags |= RATE_INFO_FLAGS_MCS;
617 /* 40MHz rate */
618 if (priv->tx_htinfo & BIT(1))
619 sinfo->txrate.flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
620 /* SGI enabled */
621 if (priv->tx_htinfo & BIT(2))
622 sinfo->txrate.flags |= RATE_INFO_FLAGS_SHORT_GI;
623 }
624
Amitkumar Karwar7013d3e2012-03-15 20:51:50 -0700625 sinfo->signal_avg = priv->bcn_rssi_avg;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700626 sinfo->rx_bytes = priv->stats.rx_bytes;
627 sinfo->tx_bytes = priv->stats.tx_bytes;
628 sinfo->rx_packets = priv->stats.rx_packets;
629 sinfo->tx_packets = priv->stats.tx_packets;
Amitkumar Karwar958a4a82012-03-15 20:51:49 -0700630 sinfo->signal = priv->bcn_rssi_avg;
Amitkumar Karwar4ec6f9c2011-09-26 20:37:25 -0700631 /* bit rate is in 500 kb/s units. Convert it to 100kb/s units */
Amitkumar Karwar006606c2012-07-13 20:09:31 -0700632 sinfo->txrate.legacy = rate * 5;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700633
Amitkumar Karwarc4f3b972012-01-24 20:50:25 -0800634 if (priv->bss_mode == NL80211_IFTYPE_STATION) {
635 sinfo->filled |= STATION_INFO_BSS_PARAM;
636 sinfo->bss_param.flags = 0;
637 if (priv->curr_bss_params.bss_descriptor.cap_info_bitmap &
638 WLAN_CAPABILITY_SHORT_PREAMBLE)
639 sinfo->bss_param.flags |=
640 BSS_PARAM_FLAGS_SHORT_PREAMBLE;
641 if (priv->curr_bss_params.bss_descriptor.cap_info_bitmap &
642 WLAN_CAPABILITY_SHORT_SLOT_TIME)
643 sinfo->bss_param.flags |=
644 BSS_PARAM_FLAGS_SHORT_SLOT_TIME;
Amitkumar Karwarcaf60a62012-02-02 20:48:58 -0800645 sinfo->bss_param.dtim_period = priv->dtim_period;
Amitkumar Karwarc4f3b972012-01-24 20:50:25 -0800646 sinfo->bss_param.beacon_interval =
647 priv->curr_bss_params.bss_descriptor.beacon_period;
648 }
649
Amitkumar Karwar958a4a82012-03-15 20:51:49 -0700650 return 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700651}
652
653/*
654 * CFG802.11 operation handler to get station information.
655 *
656 * This function only works in connected mode, and dumps the
657 * requested station information, if available.
658 */
659static int
660mwifiex_cfg80211_get_station(struct wiphy *wiphy, struct net_device *dev,
661 u8 *mac, struct station_info *sinfo)
662{
663 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700664
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700665 if (!priv->media_connected)
666 return -ENOENT;
667 if (memcmp(mac, priv->cfg_bssid, ETH_ALEN))
668 return -ENOENT;
669
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700670 return mwifiex_dump_station_info(priv, sinfo);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700671}
672
Amitkumar Karwarf85aae62012-03-15 20:51:48 -0700673/*
674 * CFG802.11 operation handler to dump station information.
675 */
676static int
677mwifiex_cfg80211_dump_station(struct wiphy *wiphy, struct net_device *dev,
678 int idx, u8 *mac, struct station_info *sinfo)
679{
680 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
681
682 if (!priv->media_connected || idx)
683 return -ENOENT;
684
685 memcpy(mac, priv->cfg_bssid, ETH_ALEN);
686
687 return mwifiex_dump_station_info(priv, sinfo);
688}
689
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700690/* Supported rates to be advertised to the cfg80211 */
691
692static struct ieee80211_rate mwifiex_rates[] = {
693 {.bitrate = 10, .hw_value = 2, },
694 {.bitrate = 20, .hw_value = 4, },
695 {.bitrate = 55, .hw_value = 11, },
696 {.bitrate = 110, .hw_value = 22, },
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700697 {.bitrate = 60, .hw_value = 12, },
698 {.bitrate = 90, .hw_value = 18, },
699 {.bitrate = 120, .hw_value = 24, },
700 {.bitrate = 180, .hw_value = 36, },
701 {.bitrate = 240, .hw_value = 48, },
702 {.bitrate = 360, .hw_value = 72, },
703 {.bitrate = 480, .hw_value = 96, },
704 {.bitrate = 540, .hw_value = 108, },
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700705};
706
707/* Channel definitions to be advertised to cfg80211 */
708
709static struct ieee80211_channel mwifiex_channels_2ghz[] = {
710 {.center_freq = 2412, .hw_value = 1, },
711 {.center_freq = 2417, .hw_value = 2, },
712 {.center_freq = 2422, .hw_value = 3, },
713 {.center_freq = 2427, .hw_value = 4, },
714 {.center_freq = 2432, .hw_value = 5, },
715 {.center_freq = 2437, .hw_value = 6, },
716 {.center_freq = 2442, .hw_value = 7, },
717 {.center_freq = 2447, .hw_value = 8, },
718 {.center_freq = 2452, .hw_value = 9, },
719 {.center_freq = 2457, .hw_value = 10, },
720 {.center_freq = 2462, .hw_value = 11, },
721 {.center_freq = 2467, .hw_value = 12, },
722 {.center_freq = 2472, .hw_value = 13, },
723 {.center_freq = 2484, .hw_value = 14, },
724};
725
726static struct ieee80211_supported_band mwifiex_band_2ghz = {
727 .channels = mwifiex_channels_2ghz,
728 .n_channels = ARRAY_SIZE(mwifiex_channels_2ghz),
729 .bitrates = mwifiex_rates,
Amitkumar Karwar87638482012-03-07 19:36:07 -0800730 .n_bitrates = ARRAY_SIZE(mwifiex_rates),
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700731};
732
733static struct ieee80211_channel mwifiex_channels_5ghz[] = {
734 {.center_freq = 5040, .hw_value = 8, },
735 {.center_freq = 5060, .hw_value = 12, },
736 {.center_freq = 5080, .hw_value = 16, },
737 {.center_freq = 5170, .hw_value = 34, },
738 {.center_freq = 5190, .hw_value = 38, },
739 {.center_freq = 5210, .hw_value = 42, },
740 {.center_freq = 5230, .hw_value = 46, },
741 {.center_freq = 5180, .hw_value = 36, },
742 {.center_freq = 5200, .hw_value = 40, },
743 {.center_freq = 5220, .hw_value = 44, },
744 {.center_freq = 5240, .hw_value = 48, },
745 {.center_freq = 5260, .hw_value = 52, },
746 {.center_freq = 5280, .hw_value = 56, },
747 {.center_freq = 5300, .hw_value = 60, },
748 {.center_freq = 5320, .hw_value = 64, },
749 {.center_freq = 5500, .hw_value = 100, },
750 {.center_freq = 5520, .hw_value = 104, },
751 {.center_freq = 5540, .hw_value = 108, },
752 {.center_freq = 5560, .hw_value = 112, },
753 {.center_freq = 5580, .hw_value = 116, },
754 {.center_freq = 5600, .hw_value = 120, },
755 {.center_freq = 5620, .hw_value = 124, },
756 {.center_freq = 5640, .hw_value = 128, },
757 {.center_freq = 5660, .hw_value = 132, },
758 {.center_freq = 5680, .hw_value = 136, },
759 {.center_freq = 5700, .hw_value = 140, },
760 {.center_freq = 5745, .hw_value = 149, },
761 {.center_freq = 5765, .hw_value = 153, },
762 {.center_freq = 5785, .hw_value = 157, },
763 {.center_freq = 5805, .hw_value = 161, },
764 {.center_freq = 5825, .hw_value = 165, },
765};
766
767static struct ieee80211_supported_band mwifiex_band_5ghz = {
768 .channels = mwifiex_channels_5ghz,
769 .n_channels = ARRAY_SIZE(mwifiex_channels_5ghz),
Avinash Patileb416ad2012-02-27 22:04:11 -0800770 .bitrates = mwifiex_rates + 4,
771 .n_bitrates = ARRAY_SIZE(mwifiex_rates) - 4,
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700772};
773
774
775/* Supported crypto cipher suits to be advertised to cfg80211 */
776
777static const u32 mwifiex_cipher_suites[] = {
778 WLAN_CIPHER_SUITE_WEP40,
779 WLAN_CIPHER_SUITE_WEP104,
780 WLAN_CIPHER_SUITE_TKIP,
781 WLAN_CIPHER_SUITE_CCMP,
Ying Luo53b11232012-08-03 18:06:13 -0700782 WLAN_CIPHER_SUITE_AES_CMAC,
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700783};
784
785/*
Yogesh Ashok Powar5d82c532011-07-11 20:04:44 -0700786 * CFG802.11 operation handler for setting bit rates.
787 *
Amitkumar Karwar433c3992012-07-13 20:09:33 -0700788 * Function configures data rates to firmware using bitrate mask
789 * provided by cfg80211.
Yogesh Ashok Powar5d82c532011-07-11 20:04:44 -0700790 */
791static int mwifiex_cfg80211_set_bitrate_mask(struct wiphy *wiphy,
792 struct net_device *dev,
793 const u8 *peer,
794 const struct cfg80211_bitrate_mask *mask)
795{
Yogesh Ashok Powar5d82c532011-07-11 20:04:44 -0700796 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
Amitkumar Karwar433c3992012-07-13 20:09:33 -0700797 u16 bitmap_rates[MAX_BITMAP_RATES_SIZE];
798 enum ieee80211_band band;
Yogesh Ashok Powar5d82c532011-07-11 20:04:44 -0700799
Amitkumar Karwar433c3992012-07-13 20:09:33 -0700800 if (!priv->media_connected) {
801 dev_err(priv->adapter->dev,
802 "Can not set Tx data rate in disconnected state\n");
803 return -EINVAL;
Yogesh Ashok Powar5d82c532011-07-11 20:04:44 -0700804 }
805
Amitkumar Karwar433c3992012-07-13 20:09:33 -0700806 band = mwifiex_band_to_radio_type(priv->curr_bss_params.band);
Yogesh Ashok Powar5d82c532011-07-11 20:04:44 -0700807
Amitkumar Karwar433c3992012-07-13 20:09:33 -0700808 memset(bitmap_rates, 0, sizeof(bitmap_rates));
Yogesh Ashok Powar5d82c532011-07-11 20:04:44 -0700809
Amitkumar Karwar433c3992012-07-13 20:09:33 -0700810 /* Fill HR/DSSS rates. */
811 if (band == IEEE80211_BAND_2GHZ)
812 bitmap_rates[0] = mask->control[band].legacy & 0x000f;
Yogesh Ashok Powar5d82c532011-07-11 20:04:44 -0700813
Amitkumar Karwar433c3992012-07-13 20:09:33 -0700814 /* Fill OFDM rates */
815 if (band == IEEE80211_BAND_2GHZ)
816 bitmap_rates[1] = (mask->control[band].legacy & 0x0ff0) >> 4;
817 else
818 bitmap_rates[1] = mask->control[band].legacy;
819
820 /* Fill MCS rates */
821 bitmap_rates[2] = mask->control[band].mcs[0];
822 if (priv->adapter->hw_dev_mcs_support == HT_STREAM_2X2)
823 bitmap_rates[2] |= mask->control[band].mcs[1] << 8;
824
825 return mwifiex_send_cmd_sync(priv, HostCmd_CMD_TX_RATE_CFG,
826 HostCmd_ACT_GEN_SET, 0, bitmap_rates);
Yogesh Ashok Powar5d82c532011-07-11 20:04:44 -0700827}
828
829/*
Amitkumar Karwarfa444bf2012-03-15 20:51:51 -0700830 * CFG802.11 operation handler for connection quality monitoring.
831 *
832 * This function subscribes/unsubscribes HIGH_RSSI and LOW_RSSI
833 * events to FW.
834 */
835static int mwifiex_cfg80211_set_cqm_rssi_config(struct wiphy *wiphy,
836 struct net_device *dev,
837 s32 rssi_thold, u32 rssi_hyst)
838{
839 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
840 struct mwifiex_ds_misc_subsc_evt subsc_evt;
841
842 priv->cqm_rssi_thold = rssi_thold;
843 priv->cqm_rssi_hyst = rssi_hyst;
844
845 memset(&subsc_evt, 0x00, sizeof(struct mwifiex_ds_misc_subsc_evt));
846 subsc_evt.events = BITMASK_BCN_RSSI_LOW | BITMASK_BCN_RSSI_HIGH;
847
848 /* Subscribe/unsubscribe low and high rssi events */
849 if (rssi_thold && rssi_hyst) {
850 subsc_evt.action = HostCmd_ACT_BITWISE_SET;
851 subsc_evt.bcn_l_rssi_cfg.abs_value = abs(rssi_thold);
852 subsc_evt.bcn_h_rssi_cfg.abs_value = abs(rssi_thold);
853 subsc_evt.bcn_l_rssi_cfg.evt_freq = 1;
854 subsc_evt.bcn_h_rssi_cfg.evt_freq = 1;
855 return mwifiex_send_cmd_sync(priv,
856 HostCmd_CMD_802_11_SUBSCRIBE_EVENT,
857 0, 0, &subsc_evt);
858 } else {
859 subsc_evt.action = HostCmd_ACT_BITWISE_CLR;
860 return mwifiex_send_cmd_sync(priv,
861 HostCmd_CMD_802_11_SUBSCRIBE_EVENT,
862 0, 0, &subsc_evt);
863 }
864
865 return 0;
866}
867
Avinash Patil5370c832012-06-28 20:30:28 -0700868/* cfg80211 operation handler for change_beacon.
869 * Function retrieves and sets modified management IEs to FW.
870 */
871static int mwifiex_cfg80211_change_beacon(struct wiphy *wiphy,
872 struct net_device *dev,
873 struct cfg80211_beacon_data *data)
874{
875 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
876
877 if (priv->bss_type != MWIFIEX_BSS_TYPE_UAP) {
878 wiphy_err(wiphy, "%s: bss_type mismatched\n", __func__);
879 return -EINVAL;
880 }
881
882 if (!priv->bss_started) {
883 wiphy_err(wiphy, "%s: bss not started\n", __func__);
884 return -EINVAL;
885 }
886
887 if (mwifiex_set_mgmt_ies(priv, data)) {
888 wiphy_err(wiphy, "%s: setting mgmt ies failed\n", __func__);
889 return -EFAULT;
890 }
891
892 return 0;
893}
894
Amitkumar Karwar8a279d52012-07-02 19:32:33 -0700895static int
896mwifiex_cfg80211_set_antenna(struct wiphy *wiphy, u32 tx_ant, u32 rx_ant)
897{
898 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
899 struct mwifiex_private *priv = mwifiex_get_priv(adapter,
900 MWIFIEX_BSS_ROLE_ANY);
901 struct mwifiex_ds_ant_cfg ant_cfg;
902
903 if (!tx_ant || !rx_ant)
904 return -EOPNOTSUPP;
905
906 if (adapter->hw_dev_mcs_support != HT_STREAM_2X2) {
907 /* Not a MIMO chip. User should provide specific antenna number
908 * for Tx/Rx path or enable all antennas for diversity
909 */
910 if (tx_ant != rx_ant)
911 return -EOPNOTSUPP;
912
913 if ((tx_ant & (tx_ant - 1)) &&
914 (tx_ant != BIT(adapter->number_of_antenna) - 1))
915 return -EOPNOTSUPP;
916
917 if ((tx_ant == BIT(adapter->number_of_antenna) - 1) &&
918 (priv->adapter->number_of_antenna > 1)) {
919 tx_ant = RF_ANTENNA_AUTO;
920 rx_ant = RF_ANTENNA_AUTO;
921 }
922 }
923
924 ant_cfg.tx_ant = tx_ant;
925 ant_cfg.rx_ant = rx_ant;
926
927 return mwifiex_send_cmd_sync(priv, HostCmd_CMD_RF_ANTENNA,
928 HostCmd_ACT_GEN_SET, 0, &ant_cfg);
929}
930
Avinash Patil12190c52012-05-08 18:30:24 -0700931/* cfg80211 operation handler for stop ap.
932 * Function stops BSS running at uAP interface.
933 */
934static int mwifiex_cfg80211_stop_ap(struct wiphy *wiphy, struct net_device *dev)
935{
936 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
937
Avinash Patil40bbc212012-05-08 18:30:30 -0700938 if (mwifiex_del_mgmt_ies(priv))
939 wiphy_err(wiphy, "Failed to delete mgmt IEs!\n");
940
Avinash Patilc8258912012-08-03 18:06:05 -0700941 priv->ap_11n_enabled = 0;
942
Avinash Patil12190c52012-05-08 18:30:24 -0700943 if (mwifiex_send_cmd_sync(priv, HostCmd_CMD_UAP_BSS_STOP,
944 HostCmd_ACT_GEN_SET, 0, NULL)) {
945 wiphy_err(wiphy, "Failed to stop the BSS\n");
946 return -1;
947 }
948
949 return 0;
950}
951
952/* cfg80211 operation handler for start_ap.
953 * Function sets beacon period, DTIM period, SSID and security into
954 * AP config structure.
955 * AP is configured with these settings and BSS is started.
956 */
957static int mwifiex_cfg80211_start_ap(struct wiphy *wiphy,
958 struct net_device *dev,
959 struct cfg80211_ap_settings *params)
960{
961 struct mwifiex_uap_bss_param *bss_cfg;
962 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
Amitkumar Karwar05910f42012-07-13 20:09:32 -0700963 u8 config_bands = 0;
Avinash Patil12190c52012-05-08 18:30:24 -0700964
Avinash Patilf752dcd2012-05-08 18:30:26 -0700965 if (priv->bss_type != MWIFIEX_BSS_TYPE_UAP)
966 return -1;
Avinash Patiladb6ed02012-06-28 20:30:25 -0700967 if (mwifiex_set_mgmt_ies(priv, &params->beacon))
Avinash Patilf31acab2012-05-08 18:30:29 -0700968 return -1;
Avinash Patilf752dcd2012-05-08 18:30:26 -0700969
Avinash Patil12190c52012-05-08 18:30:24 -0700970 bss_cfg = kzalloc(sizeof(struct mwifiex_uap_bss_param), GFP_KERNEL);
971 if (!bss_cfg)
972 return -ENOMEM;
973
974 mwifiex_set_sys_config_invalid_data(bss_cfg);
975
976 if (params->beacon_interval)
977 bss_cfg->beacon_period = params->beacon_interval;
978 if (params->dtim_period)
979 bss_cfg->dtim_period = params->dtim_period;
980
981 if (params->ssid && params->ssid_len) {
982 memcpy(bss_cfg->ssid.ssid, params->ssid, params->ssid_len);
983 bss_cfg->ssid.ssid_len = params->ssid_len;
984 }
985
Avinash Patil7a1c9932012-05-29 15:39:05 -0700986 switch (params->hidden_ssid) {
987 case NL80211_HIDDEN_SSID_NOT_IN_USE:
988 bss_cfg->bcast_ssid_ctl = 1;
989 break;
990 case NL80211_HIDDEN_SSID_ZERO_LEN:
991 bss_cfg->bcast_ssid_ctl = 0;
992 break;
993 case NL80211_HIDDEN_SSID_ZERO_CONTENTS:
994 /* firmware doesn't support this type of hidden SSID */
995 default:
Bing Zhaob3190462012-07-03 15:53:13 -0700996 kfree(bss_cfg);
Avinash Patil7a1c9932012-05-29 15:39:05 -0700997 return -EINVAL;
998 }
999
Avinash Patil0abd79e2012-06-15 12:21:51 -07001000 bss_cfg->channel =
1001 (u8)ieee80211_frequency_to_channel(params->channel->center_freq);
Avinash Patil0abd79e2012-06-15 12:21:51 -07001002
Amitkumar Karwar05910f42012-07-13 20:09:32 -07001003 /* Set appropriate bands */
1004 if (params->channel->band == IEEE80211_BAND_2GHZ) {
Avinash Patila3c2c4f2012-08-27 20:32:53 -07001005 bss_cfg->band_cfg = BAND_CONFIG_BG;
1006
Amitkumar Karwar05910f42012-07-13 20:09:32 -07001007 if (params->channel_type == NL80211_CHAN_NO_HT)
1008 config_bands = BAND_B | BAND_G;
1009 else
1010 config_bands = BAND_B | BAND_G | BAND_GN;
1011 } else {
Avinash Patila3c2c4f2012-08-27 20:32:53 -07001012 bss_cfg->band_cfg = BAND_CONFIG_A;
1013
Amitkumar Karwar05910f42012-07-13 20:09:32 -07001014 if (params->channel_type == NL80211_CHAN_NO_HT)
1015 config_bands = BAND_A;
1016 else
1017 config_bands = BAND_AN | BAND_A;
Avinash Patil0abd79e2012-06-15 12:21:51 -07001018 }
1019
Amitkumar Karwar05910f42012-07-13 20:09:32 -07001020 if (!((config_bands | priv->adapter->fw_bands) &
1021 ~priv->adapter->fw_bands))
1022 priv->adapter->config_bands = config_bands;
1023
Avinash Patila3c2c4f2012-08-27 20:32:53 -07001024 mwifiex_set_uap_rates(bss_cfg, params);
Amitkumar Karwar05910f42012-07-13 20:09:32 -07001025 mwifiex_send_domain_info_cmd_fw(wiphy);
1026
Avinash Patilf752dcd2012-05-08 18:30:26 -07001027 if (mwifiex_set_secure_params(priv, bss_cfg, params)) {
1028 kfree(bss_cfg);
1029 wiphy_err(wiphy, "Failed to parse secuirty parameters!\n");
1030 return -1;
1031 }
1032
Avinash Patil22281252012-06-15 12:21:53 -07001033 mwifiex_set_ht_params(priv, bss_cfg, params);
1034
Avinash Patil12190c52012-05-08 18:30:24 -07001035 if (mwifiex_send_cmd_sync(priv, HostCmd_CMD_UAP_BSS_STOP,
1036 HostCmd_ACT_GEN_SET, 0, NULL)) {
1037 wiphy_err(wiphy, "Failed to stop the BSS\n");
1038 kfree(bss_cfg);
1039 return -1;
1040 }
1041
1042 if (mwifiex_send_cmd_async(priv, HostCmd_CMD_UAP_SYS_CONFIG,
Avinash Patile76268d2012-05-08 18:30:27 -07001043 HostCmd_ACT_GEN_SET,
1044 UAP_BSS_PARAMS_I, bss_cfg)) {
Avinash Patil12190c52012-05-08 18:30:24 -07001045 wiphy_err(wiphy, "Failed to set the SSID\n");
1046 kfree(bss_cfg);
1047 return -1;
1048 }
1049
1050 kfree(bss_cfg);
1051
1052 if (mwifiex_send_cmd_async(priv, HostCmd_CMD_UAP_BSS_START,
1053 HostCmd_ACT_GEN_SET, 0, NULL)) {
1054 wiphy_err(wiphy, "Failed to start the BSS\n");
1055 return -1;
1056 }
1057
Avinash Patil96893532012-06-15 12:21:55 -07001058 if (priv->sec_info.wep_enabled)
1059 priv->curr_pkt_filter |= HostCmd_ACT_MAC_WEP_ENABLE;
1060 else
1061 priv->curr_pkt_filter &= ~HostCmd_ACT_MAC_WEP_ENABLE;
1062
1063 if (mwifiex_send_cmd_sync(priv, HostCmd_CMD_MAC_CONTROL,
1064 HostCmd_ACT_GEN_SET, 0,
1065 &priv->curr_pkt_filter))
1066 return -1;
1067
Avinash Patil12190c52012-05-08 18:30:24 -07001068 return 0;
1069}
1070
Amitkumar Karwarfa444bf2012-03-15 20:51:51 -07001071/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001072 * CFG802.11 operation handler for disconnection request.
1073 *
1074 * This function does not work when there is already a disconnection
1075 * procedure going on.
1076 */
1077static int
1078mwifiex_cfg80211_disconnect(struct wiphy *wiphy, struct net_device *dev,
1079 u16 reason_code)
1080{
1081 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
1082
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001083 if (mwifiex_deauthenticate(priv, NULL))
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001084 return -EFAULT;
1085
1086 wiphy_dbg(wiphy, "info: successfully disconnected from %pM:"
1087 " reason code %d\n", priv->cfg_bssid, reason_code);
1088
Amitkumar Karwar38c9d662011-12-13 20:43:17 -08001089 memset(priv->cfg_bssid, 0, ETH_ALEN);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001090
1091 return 0;
1092}
1093
1094/*
1095 * This function informs the CFG802.11 subsystem of a new IBSS.
1096 *
1097 * The following information are sent to the CFG802.11 subsystem
1098 * to register the new IBSS. If we do not register the new IBSS,
1099 * a kernel panic will result.
1100 * - SSID
1101 * - SSID length
1102 * - BSSID
1103 * - Channel
1104 */
1105static int mwifiex_cfg80211_inform_ibss_bss(struct mwifiex_private *priv)
1106{
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001107 struct ieee80211_channel *chan;
1108 struct mwifiex_bss_info bss_info;
Amitkumar Karwaraa95a482011-11-07 21:41:12 -08001109 struct cfg80211_bss *bss;
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -07001110 int ie_len;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001111 u8 ie_buf[IEEE80211_MAX_SSID_LEN + sizeof(struct ieee_types_header)];
Amitkumar Karwar4ed5d522011-09-21 21:43:24 -07001112 enum ieee80211_band band;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001113
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001114 if (mwifiex_get_bss_info(priv, &bss_info))
1115 return -1;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001116
1117 ie_buf[0] = WLAN_EID_SSID;
1118 ie_buf[1] = bss_info.ssid.ssid_len;
1119
1120 memcpy(&ie_buf[sizeof(struct ieee_types_header)],
Yogesh Ashok Powaraea07012012-03-13 19:22:35 -07001121 &bss_info.ssid.ssid, bss_info.ssid.ssid_len);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001122 ie_len = ie_buf[1] + sizeof(struct ieee_types_header);
1123
Amitkumar Karwar4ed5d522011-09-21 21:43:24 -07001124 band = mwifiex_band_to_radio_type(priv->curr_bss_params.band);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001125 chan = __ieee80211_get_channel(priv->wdev->wiphy,
1126 ieee80211_channel_to_frequency(bss_info.bss_chan,
Amitkumar Karwar4ed5d522011-09-21 21:43:24 -07001127 band));
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001128
Amitkumar Karwaraa95a482011-11-07 21:41:12 -08001129 bss = cfg80211_inform_bss(priv->wdev->wiphy, chan,
Yogesh Ashok Powaraea07012012-03-13 19:22:35 -07001130 bss_info.bssid, 0, WLAN_CAPABILITY_IBSS,
1131 0, ie_buf, ie_len, 0, GFP_KERNEL);
Amitkumar Karwaraa95a482011-11-07 21:41:12 -08001132 cfg80211_put_bss(bss);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001133 memcpy(priv->cfg_bssid, bss_info.bssid, ETH_ALEN);
1134
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001135 return 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001136}
1137
1138/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001139 * This function connects with a BSS.
1140 *
1141 * This function handles both Infra and Ad-Hoc modes. It also performs
1142 * validity checking on the provided parameters, disconnects from the
1143 * current BSS (if any), sets up the association/scan parameters,
1144 * including security settings, and performs specific SSID scan before
1145 * trying to connect.
1146 *
1147 * For Infra mode, the function returns failure if the specified SSID
1148 * is not found in scan table. However, for Ad-Hoc mode, it can create
1149 * the IBSS if it does not exist. On successful completion in either case,
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001150 * the function notifies the CFG802.11 subsystem of the new BSS connection.
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001151 */
1152static int
1153mwifiex_cfg80211_assoc(struct mwifiex_private *priv, size_t ssid_len, u8 *ssid,
1154 u8 *bssid, int mode, struct ieee80211_channel *channel,
1155 struct cfg80211_connect_params *sme, bool privacy)
1156{
Amitkumar Karwarb9be5f32012-02-27 22:04:14 -08001157 struct cfg80211_ssid req_ssid;
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -07001158 int ret, auth_type = 0;
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001159 struct cfg80211_bss *bss = NULL;
Amitkumar Karwar05910f42012-07-13 20:09:32 -07001160 u8 is_scanning_required = 0, config_bands = 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001161
Amitkumar Karwarb9be5f32012-02-27 22:04:14 -08001162 memset(&req_ssid, 0, sizeof(struct cfg80211_ssid));
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001163
1164 req_ssid.ssid_len = ssid_len;
1165 if (ssid_len > IEEE80211_MAX_SSID_LEN) {
1166 dev_err(priv->adapter->dev, "invalid SSID - aborting\n");
1167 return -EINVAL;
1168 }
1169
1170 memcpy(req_ssid.ssid, ssid, ssid_len);
1171 if (!req_ssid.ssid_len || req_ssid.ssid[0] < 0x20) {
1172 dev_err(priv->adapter->dev, "invalid SSID - aborting\n");
1173 return -EINVAL;
1174 }
1175
1176 /* disconnect before try to associate */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001177 mwifiex_deauthenticate(priv, NULL);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001178
Amitkumar Karwar05910f42012-07-13 20:09:32 -07001179 if (channel) {
1180 if (mode == NL80211_IFTYPE_STATION) {
1181 if (channel->band == IEEE80211_BAND_2GHZ)
1182 config_bands = BAND_B | BAND_G | BAND_GN;
1183 else
1184 config_bands = BAND_A | BAND_AN;
1185
1186 if (!((config_bands | priv->adapter->fw_bands) &
1187 ~priv->adapter->fw_bands))
1188 priv->adapter->config_bands = config_bands;
1189 }
Amitkumar Karwar05910f42012-07-13 20:09:32 -07001190 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001191
Amitkumar Karwar6670f152012-02-09 18:32:22 -08001192 /* As this is new association, clear locally stored
1193 * keys and security related flags */
1194 priv->sec_info.wpa_enabled = false;
1195 priv->sec_info.wpa2_enabled = false;
1196 priv->wep_key_curr_index = 0;
Amitkumar Karwar00f157b2012-02-24 21:35:35 -08001197 priv->sec_info.encryption_mode = 0;
Amitkumar Karwara0f6d6c2012-02-24 21:36:05 -08001198 priv->sec_info.is_authtype_auto = 0;
Ying Luo53b11232012-08-03 18:06:13 -07001199 ret = mwifiex_set_encode(priv, NULL, NULL, 0, 0, NULL, 1);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001200
Bing Zhaoeecd8252011-03-28 17:55:41 -07001201 if (mode == NL80211_IFTYPE_ADHOC) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001202 /* "privacy" is set only for ad-hoc mode */
1203 if (privacy) {
1204 /*
Yogesh Ashok Powar2be50b82011-04-01 18:36:47 -07001205 * Keep WLAN_CIPHER_SUITE_WEP104 for now so that
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001206 * the firmware can find a matching network from the
1207 * scan. The cfg80211 does not give us the encryption
1208 * mode at this stage so just setting it to WEP here.
1209 */
Marc Yang203afec2011-03-24 20:49:39 -07001210 priv->sec_info.encryption_mode =
Yogesh Ashok Powar2be50b82011-04-01 18:36:47 -07001211 WLAN_CIPHER_SUITE_WEP104;
Marc Yang203afec2011-03-24 20:49:39 -07001212 priv->sec_info.authentication_mode =
Marc Yangf986b6d2011-03-28 17:55:42 -07001213 NL80211_AUTHTYPE_OPEN_SYSTEM;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001214 }
1215
1216 goto done;
1217 }
1218
1219 /* Now handle infra mode. "sme" is valid for infra mode only */
Amitkumar Karwara0f6d6c2012-02-24 21:36:05 -08001220 if (sme->auth_type == NL80211_AUTHTYPE_AUTOMATIC) {
Marc Yangf986b6d2011-03-28 17:55:42 -07001221 auth_type = NL80211_AUTHTYPE_OPEN_SYSTEM;
Amitkumar Karwara0f6d6c2012-02-24 21:36:05 -08001222 priv->sec_info.is_authtype_auto = 1;
1223 } else {
1224 auth_type = sme->auth_type;
1225 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001226
1227 if (sme->crypto.n_ciphers_pairwise) {
Yogesh Ashok Powar2be50b82011-04-01 18:36:47 -07001228 priv->sec_info.encryption_mode =
1229 sme->crypto.ciphers_pairwise[0];
Marc Yang203afec2011-03-24 20:49:39 -07001230 priv->sec_info.authentication_mode = auth_type;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001231 }
1232
1233 if (sme->crypto.cipher_group) {
Yogesh Ashok Powar2be50b82011-04-01 18:36:47 -07001234 priv->sec_info.encryption_mode = sme->crypto.cipher_group;
Marc Yang203afec2011-03-24 20:49:39 -07001235 priv->sec_info.authentication_mode = auth_type;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001236 }
1237 if (sme->ie)
1238 ret = mwifiex_set_gen_ie(priv, sme->ie, sme->ie_len);
1239
1240 if (sme->key) {
Amitkumar Karware6faada2011-07-07 17:33:19 -07001241 if (mwifiex_is_alg_wep(priv->sec_info.encryption_mode)) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001242 dev_dbg(priv->adapter->dev,
1243 "info: setting wep encryption"
1244 " with key len %d\n", sme->key_len);
Amitkumar Karwar6670f152012-02-09 18:32:22 -08001245 priv->wep_key_curr_index = sme->key_idx;
Ying Luo53b11232012-08-03 18:06:13 -07001246 ret = mwifiex_set_encode(priv, NULL, sme->key,
1247 sme->key_len, sme->key_idx,
1248 NULL, 0);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001249 }
1250 }
1251done:
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001252 /*
1253 * Scan entries are valid for some time (15 sec). So we can save one
1254 * active scan time if we just try cfg80211_get_bss first. If it fails
1255 * then request scan and cfg80211_get_bss() again for final output.
1256 */
1257 while (1) {
1258 if (is_scanning_required) {
1259 /* Do specific SSID scanning */
1260 if (mwifiex_request_scan(priv, &req_ssid)) {
1261 dev_err(priv->adapter->dev, "scan error\n");
1262 return -EFAULT;
1263 }
1264 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001265
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001266 /* Find the BSS we want using available scan results */
1267 if (mode == NL80211_IFTYPE_ADHOC)
1268 bss = cfg80211_get_bss(priv->wdev->wiphy, channel,
1269 bssid, ssid, ssid_len,
1270 WLAN_CAPABILITY_IBSS,
1271 WLAN_CAPABILITY_IBSS);
1272 else
1273 bss = cfg80211_get_bss(priv->wdev->wiphy, channel,
1274 bssid, ssid, ssid_len,
1275 WLAN_CAPABILITY_ESS,
1276 WLAN_CAPABILITY_ESS);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001277
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001278 if (!bss) {
1279 if (is_scanning_required) {
Yogesh Ashok Powaraea07012012-03-13 19:22:35 -07001280 dev_warn(priv->adapter->dev,
1281 "assoc: requested bss not found in scan results\n");
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001282 break;
1283 }
1284 is_scanning_required = 1;
1285 } else {
Yogesh Ashok Powaraea07012012-03-13 19:22:35 -07001286 dev_dbg(priv->adapter->dev,
1287 "info: trying to associate to '%s' bssid %pM\n",
1288 (char *) req_ssid.ssid, bss->bssid);
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001289 memcpy(&priv->cfg_bssid, bss->bssid, ETH_ALEN);
1290 break;
1291 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001292 }
1293
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001294 if (mwifiex_bss_start(priv, bss, &req_ssid))
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001295 return -EFAULT;
1296
Bing Zhaoeecd8252011-03-28 17:55:41 -07001297 if (mode == NL80211_IFTYPE_ADHOC) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001298 /* Inform the BSS information to kernel, otherwise
1299 * kernel will give a panic after successful assoc */
1300 if (mwifiex_cfg80211_inform_ibss_bss(priv))
1301 return -EFAULT;
1302 }
1303
1304 return ret;
1305}
1306
1307/*
1308 * CFG802.11 operation handler for association request.
1309 *
1310 * This function does not work when the current mode is set to Ad-Hoc, or
1311 * when there is already an association procedure going on. The given BSS
1312 * information is used to associate.
1313 */
1314static int
1315mwifiex_cfg80211_connect(struct wiphy *wiphy, struct net_device *dev,
1316 struct cfg80211_connect_params *sme)
1317{
1318 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
1319 int ret = 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001320
Bing Zhaoeecd8252011-03-28 17:55:41 -07001321 if (priv->bss_mode == NL80211_IFTYPE_ADHOC) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001322 wiphy_err(wiphy, "received infra assoc request "
1323 "when station is in ibss mode\n");
1324 goto done;
1325 }
1326
Avinash Patile5686342012-05-08 18:30:25 -07001327 if (priv->bss_mode == NL80211_IFTYPE_AP) {
1328 wiphy_err(wiphy, "skip association request for AP interface\n");
1329 goto done;
1330 }
1331
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001332 wiphy_dbg(wiphy, "info: Trying to associate to %s and bssid %pM\n",
Yogesh Ashok Powaraea07012012-03-13 19:22:35 -07001333 (char *) sme->ssid, sme->bssid);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001334
1335 ret = mwifiex_cfg80211_assoc(priv, sme->ssid_len, sme->ssid, sme->bssid,
Bing Zhaoeecd8252011-03-28 17:55:41 -07001336 priv->bss_mode, sme->channel, sme, 0);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001337done:
Amitkumar Karwar38c9d662011-12-13 20:43:17 -08001338 if (!ret) {
1339 cfg80211_connect_result(priv->netdev, priv->cfg_bssid, NULL, 0,
1340 NULL, 0, WLAN_STATUS_SUCCESS,
1341 GFP_KERNEL);
1342 dev_dbg(priv->adapter->dev,
1343 "info: associated to bssid %pM successfully\n",
1344 priv->cfg_bssid);
1345 } else {
1346 dev_dbg(priv->adapter->dev,
1347 "info: association to bssid %pM failed\n",
1348 priv->cfg_bssid);
1349 memset(priv->cfg_bssid, 0, ETH_ALEN);
1350 }
1351
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001352 return ret;
1353}
1354
1355/*
Amitkumar Karwar05910f42012-07-13 20:09:32 -07001356 * This function sets following parameters for ibss network.
1357 * - channel
1358 * - start band
1359 * - 11n flag
1360 * - secondary channel offset
1361 */
1362static int mwifiex_set_ibss_params(struct mwifiex_private *priv,
1363 struct cfg80211_ibss_params *params)
1364{
1365 struct wiphy *wiphy = priv->wdev->wiphy;
1366 struct mwifiex_adapter *adapter = priv->adapter;
1367 int index = 0, i;
1368 u8 config_bands = 0;
1369
1370 if (params->channel->band == IEEE80211_BAND_2GHZ) {
1371 if (!params->basic_rates) {
1372 config_bands = BAND_B | BAND_G;
1373 } else {
1374 for (i = 0; i < mwifiex_band_2ghz.n_bitrates; i++) {
1375 /*
1376 * Rates below 6 Mbps in the table are CCK
1377 * rates; 802.11b and from 6 they are OFDM;
1378 * 802.11G
1379 */
1380 if (mwifiex_rates[i].bitrate == 60) {
1381 index = 1 << i;
1382 break;
1383 }
1384 }
1385
1386 if (params->basic_rates < index) {
1387 config_bands = BAND_B;
1388 } else {
1389 config_bands = BAND_G;
1390 if (params->basic_rates % index)
1391 config_bands |= BAND_B;
1392 }
1393 }
1394
1395 if (params->channel_type != NL80211_CHAN_NO_HT)
1396 config_bands |= BAND_GN;
1397 } else {
1398 if (params->channel_type == NL80211_CHAN_NO_HT)
1399 config_bands = BAND_A;
1400 else
1401 config_bands = BAND_AN | BAND_A;
1402 }
1403
1404 if (!((config_bands | adapter->fw_bands) & ~adapter->fw_bands)) {
1405 adapter->config_bands = config_bands;
1406 adapter->adhoc_start_band = config_bands;
1407
1408 if ((config_bands & BAND_GN) || (config_bands & BAND_AN))
1409 adapter->adhoc_11n_enabled = true;
1410 else
1411 adapter->adhoc_11n_enabled = false;
1412 }
1413
1414 adapter->sec_chan_offset =
1415 mwifiex_chan_type_to_sec_chan_offset(params->channel_type);
1416 priv->adhoc_channel =
1417 ieee80211_frequency_to_channel(params->channel->center_freq);
1418
1419 wiphy_dbg(wiphy, "info: set ibss band %d, chan %d, chan offset %d\n",
1420 config_bands, priv->adhoc_channel, adapter->sec_chan_offset);
1421
1422 return 0;
1423}
1424
1425/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001426 * CFG802.11 operation handler to join an IBSS.
1427 *
1428 * This function does not work in any mode other than Ad-Hoc, or if
1429 * a join operation is already in progress.
1430 */
1431static int
1432mwifiex_cfg80211_join_ibss(struct wiphy *wiphy, struct net_device *dev,
1433 struct cfg80211_ibss_params *params)
1434{
Yogesh Ashok Powarf540f9f2012-01-11 20:06:12 -08001435 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001436 int ret = 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001437
Bing Zhaoeecd8252011-03-28 17:55:41 -07001438 if (priv->bss_mode != NL80211_IFTYPE_ADHOC) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001439 wiphy_err(wiphy, "request to join ibss received "
1440 "when station is not in ibss mode\n");
1441 goto done;
1442 }
1443
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001444 wiphy_dbg(wiphy, "info: trying to join to %s and bssid %pM\n",
Yogesh Ashok Powaraea07012012-03-13 19:22:35 -07001445 (char *) params->ssid, params->bssid);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001446
Amitkumar Karwar05910f42012-07-13 20:09:32 -07001447 mwifiex_set_ibss_params(priv, params);
1448
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001449 ret = mwifiex_cfg80211_assoc(priv, params->ssid_len, params->ssid,
Yogesh Ashok Powaraea07012012-03-13 19:22:35 -07001450 params->bssid, priv->bss_mode,
1451 params->channel, NULL, params->privacy);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001452done:
Amitkumar Karwar38c9d662011-12-13 20:43:17 -08001453 if (!ret) {
1454 cfg80211_ibss_joined(priv->netdev, priv->cfg_bssid, GFP_KERNEL);
1455 dev_dbg(priv->adapter->dev,
1456 "info: joined/created adhoc network with bssid"
1457 " %pM successfully\n", priv->cfg_bssid);
1458 } else {
1459 dev_dbg(priv->adapter->dev,
1460 "info: failed creating/joining adhoc network\n");
1461 }
1462
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001463 return ret;
1464}
1465
1466/*
1467 * CFG802.11 operation handler to leave an IBSS.
1468 *
1469 * This function does not work if a leave operation is
1470 * already in progress.
1471 */
1472static int
1473mwifiex_cfg80211_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
1474{
Yogesh Ashok Powarf540f9f2012-01-11 20:06:12 -08001475 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001476
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001477 wiphy_dbg(wiphy, "info: disconnecting from essid %pM\n",
Yogesh Ashok Powaraea07012012-03-13 19:22:35 -07001478 priv->cfg_bssid);
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001479 if (mwifiex_deauthenticate(priv, NULL))
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001480 return -EFAULT;
1481
Amitkumar Karwar38c9d662011-12-13 20:43:17 -08001482 memset(priv->cfg_bssid, 0, ETH_ALEN);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001483
1484 return 0;
1485}
1486
1487/*
1488 * CFG802.11 operation handler for scan request.
1489 *
1490 * This function issues a scan request to the firmware based upon
1491 * the user specified scan configuration. On successfull completion,
1492 * it also informs the results.
1493 */
1494static int
Johannes Bergfd014282012-06-18 19:17:03 +02001495mwifiex_cfg80211_scan(struct wiphy *wiphy,
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001496 struct cfg80211_scan_request *request)
1497{
Johannes Bergfd014282012-06-18 19:17:03 +02001498 struct net_device *dev = request->wdev->netdev;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001499 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
Amitkumar Karwar38c9d662011-12-13 20:43:17 -08001500 int i;
1501 struct ieee80211_channel *chan;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001502
1503 wiphy_dbg(wiphy, "info: received scan request on %s\n", dev->name);
1504
Amitkumar Karwarde093642012-09-20 20:23:18 -07001505 if (atomic_read(&priv->wmm.tx_pkts_queued) >=
1506 MWIFIEX_MIN_TX_PENDING_TO_CANCEL_SCAN) {
1507 dev_dbg(priv->adapter->dev, "scan rejected due to traffic\n");
1508 return -EBUSY;
1509 }
1510
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001511 priv->scan_request = request;
1512
Amitkumar Karwar38c9d662011-12-13 20:43:17 -08001513 priv->user_scan_cfg = kzalloc(sizeof(struct mwifiex_user_scan_cfg),
Yogesh Ashok Powaraea07012012-03-13 19:22:35 -07001514 GFP_KERNEL);
Amitkumar Karwar38c9d662011-12-13 20:43:17 -08001515 if (!priv->user_scan_cfg) {
1516 dev_err(priv->adapter->dev, "failed to alloc scan_req\n");
1517 return -ENOMEM;
1518 }
Amitkumar Karwarbe0b2812012-02-27 22:04:15 -08001519
1520 priv->user_scan_cfg->num_ssids = request->n_ssids;
1521 priv->user_scan_cfg->ssid_list = request->ssids;
1522
Avinash Patil13d7ba782012-04-09 20:06:56 -07001523 if (request->ie && request->ie_len) {
1524 for (i = 0; i < MWIFIEX_MAX_VSIE_NUM; i++) {
1525 if (priv->vs_ie[i].mask != MWIFIEX_VSIE_MASK_CLEAR)
1526 continue;
1527 priv->vs_ie[i].mask = MWIFIEX_VSIE_MASK_SCAN;
1528 memcpy(&priv->vs_ie[i].ie, request->ie,
1529 request->ie_len);
1530 break;
1531 }
1532 }
1533
Amitkumar Karwar38c9d662011-12-13 20:43:17 -08001534 for (i = 0; i < request->n_channels; i++) {
1535 chan = request->channels[i];
1536 priv->user_scan_cfg->chan_list[i].chan_number = chan->hw_value;
1537 priv->user_scan_cfg->chan_list[i].radio_type = chan->band;
1538
1539 if (chan->flags & IEEE80211_CHAN_PASSIVE_SCAN)
1540 priv->user_scan_cfg->chan_list[i].scan_type =
Yogesh Ashok Powaraea07012012-03-13 19:22:35 -07001541 MWIFIEX_SCAN_TYPE_PASSIVE;
Amitkumar Karwar38c9d662011-12-13 20:43:17 -08001542 else
1543 priv->user_scan_cfg->chan_list[i].scan_type =
Yogesh Ashok Powaraea07012012-03-13 19:22:35 -07001544 MWIFIEX_SCAN_TYPE_ACTIVE;
Amitkumar Karwar38c9d662011-12-13 20:43:17 -08001545
1546 priv->user_scan_cfg->chan_list[i].scan_time = 0;
1547 }
Amitkumar Karwar1a1fb972012-06-27 19:57:56 -07001548 if (mwifiex_scan_networks(priv, priv->user_scan_cfg))
Amitkumar Karwar38c9d662011-12-13 20:43:17 -08001549 return -EFAULT;
1550
Avinash Patil13d7ba782012-04-09 20:06:56 -07001551 if (request->ie && request->ie_len) {
1552 for (i = 0; i < MWIFIEX_MAX_VSIE_NUM; i++) {
1553 if (priv->vs_ie[i].mask == MWIFIEX_VSIE_MASK_SCAN) {
1554 priv->vs_ie[i].mask = MWIFIEX_VSIE_MASK_CLEAR;
1555 memset(&priv->vs_ie[i].ie, 0,
1556 MWIFIEX_MAX_VSIE_LEN);
1557 }
1558 }
1559 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001560 return 0;
1561}
1562
1563/*
1564 * This function sets up the CFG802.11 specific HT capability fields
1565 * with default values.
1566 *
1567 * The following default values are set -
1568 * - HT Supported = True
Amitkumar Karwara46b7b52011-04-27 19:13:12 -07001569 * - Maximum AMPDU length factor = IEEE80211_HT_MAX_AMPDU_64K
1570 * - Minimum AMPDU spacing = IEEE80211_HT_MPDU_DENSITY_NONE
1571 * - HT Capabilities supported by firmware
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001572 * - MCS information, Rx mask = 0xff
1573 * - MCD information, Tx parameters = IEEE80211_HT_MCS_TX_DEFINED (0x01)
1574 */
1575static void
1576mwifiex_setup_ht_caps(struct ieee80211_sta_ht_cap *ht_info,
1577 struct mwifiex_private *priv)
1578{
1579 int rx_mcs_supp;
1580 struct ieee80211_mcs_info mcs_set;
1581 u8 *mcs = (u8 *)&mcs_set;
1582 struct mwifiex_adapter *adapter = priv->adapter;
1583
1584 ht_info->ht_supported = true;
Amitkumar Karwara46b7b52011-04-27 19:13:12 -07001585 ht_info->ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
1586 ht_info->ampdu_density = IEEE80211_HT_MPDU_DENSITY_NONE;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001587
1588 memset(&ht_info->mcs, 0, sizeof(ht_info->mcs));
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001589
Amitkumar Karwara46b7b52011-04-27 19:13:12 -07001590 /* Fill HT capability information */
1591 if (ISSUPP_CHANWIDTH40(adapter->hw_dot_11n_dev_cap))
1592 ht_info->cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
1593 else
1594 ht_info->cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
1595
1596 if (ISSUPP_SHORTGI20(adapter->hw_dot_11n_dev_cap))
1597 ht_info->cap |= IEEE80211_HT_CAP_SGI_20;
1598 else
1599 ht_info->cap &= ~IEEE80211_HT_CAP_SGI_20;
1600
1601 if (ISSUPP_SHORTGI40(adapter->hw_dot_11n_dev_cap))
1602 ht_info->cap |= IEEE80211_HT_CAP_SGI_40;
1603 else
1604 ht_info->cap &= ~IEEE80211_HT_CAP_SGI_40;
1605
1606 if (ISSUPP_RXSTBC(adapter->hw_dot_11n_dev_cap))
1607 ht_info->cap |= 1 << IEEE80211_HT_CAP_RX_STBC_SHIFT;
1608 else
1609 ht_info->cap &= ~(3 << IEEE80211_HT_CAP_RX_STBC_SHIFT);
1610
1611 if (ISSUPP_TXSTBC(adapter->hw_dot_11n_dev_cap))
1612 ht_info->cap |= IEEE80211_HT_CAP_TX_STBC;
1613 else
1614 ht_info->cap &= ~IEEE80211_HT_CAP_TX_STBC;
1615
1616 ht_info->cap &= ~IEEE80211_HT_CAP_MAX_AMSDU;
1617 ht_info->cap |= IEEE80211_HT_CAP_SM_PS;
1618
1619 rx_mcs_supp = GET_RXMCSSUPP(adapter->hw_dev_mcs_support);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001620 /* Set MCS for 1x1 */
1621 memset(mcs, 0xff, rx_mcs_supp);
1622 /* Clear all the other values */
1623 memset(&mcs[rx_mcs_supp], 0,
Yogesh Ashok Powaraea07012012-03-13 19:22:35 -07001624 sizeof(struct ieee80211_mcs_info) - rx_mcs_supp);
Bing Zhaoeecd8252011-03-28 17:55:41 -07001625 if (priv->bss_mode == NL80211_IFTYPE_STATION ||
Yogesh Ashok Powaraea07012012-03-13 19:22:35 -07001626 ISSUPP_CHANWIDTH40(adapter->hw_dot_11n_dev_cap))
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001627 /* Set MCS32 for infra mode or ad-hoc mode with 40MHz support */
1628 SETHT_MCS32(mcs_set.rx_mask);
1629
1630 memcpy((u8 *) &ht_info->mcs, mcs, sizeof(struct ieee80211_mcs_info));
1631
1632 ht_info->mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED;
1633}
1634
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -07001635/*
1636 * create a new virtual interface with the given name
1637 */
Johannes Berg84efbb82012-06-16 00:00:26 +02001638struct wireless_dev *mwifiex_add_virtual_intf(struct wiphy *wiphy,
1639 char *name,
1640 enum nl80211_iftype type,
1641 u32 *flags,
1642 struct vif_params *params)
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -07001643{
Avinash Patil67fdf392012-05-08 18:30:17 -07001644 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
1645 struct mwifiex_private *priv;
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -07001646 struct net_device *dev;
1647 void *mdev_priv;
Avinash Patild6bffe82012-05-08 18:30:15 -07001648 struct wireless_dev *wdev;
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -07001649
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -07001650 if (!adapter)
Bing Zhao858faa52012-06-15 15:49:54 -07001651 return ERR_PTR(-EFAULT);
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -07001652
1653 switch (type) {
1654 case NL80211_IFTYPE_UNSPECIFIED:
1655 case NL80211_IFTYPE_STATION:
1656 case NL80211_IFTYPE_ADHOC:
Avinash Patild6bffe82012-05-08 18:30:15 -07001657 priv = adapter->priv[MWIFIEX_BSS_TYPE_STA];
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -07001658 if (priv->bss_mode) {
Avinash Patild6bffe82012-05-08 18:30:15 -07001659 wiphy_err(wiphy,
1660 "cannot create multiple sta/adhoc ifaces\n");
Bing Zhao858faa52012-06-15 15:49:54 -07001661 return ERR_PTR(-EINVAL);
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -07001662 }
1663
Avinash Patild6bffe82012-05-08 18:30:15 -07001664 wdev = kzalloc(sizeof(struct wireless_dev), GFP_KERNEL);
1665 if (!wdev)
Bing Zhao858faa52012-06-15 15:49:54 -07001666 return ERR_PTR(-ENOMEM);
Avinash Patild6bffe82012-05-08 18:30:15 -07001667
1668 wdev->wiphy = wiphy;
1669 priv->wdev = wdev;
1670 wdev->iftype = NL80211_IFTYPE_STATION;
1671
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -07001672 if (type == NL80211_IFTYPE_UNSPECIFIED)
1673 priv->bss_mode = NL80211_IFTYPE_STATION;
1674 else
1675 priv->bss_mode = type;
1676
1677 priv->bss_type = MWIFIEX_BSS_TYPE_STA;
1678 priv->frame_type = MWIFIEX_DATA_FRAME_TYPE_ETH_II;
Amitkumar Karwara458c0a2012-09-10 18:30:43 -07001679 priv->bss_priority = 0;
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -07001680 priv->bss_role = MWIFIEX_BSS_ROLE_STA;
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -07001681 priv->bss_num = 0;
1682
1683 break;
Avinash Patild6bffe82012-05-08 18:30:15 -07001684 case NL80211_IFTYPE_AP:
1685 priv = adapter->priv[MWIFIEX_BSS_TYPE_UAP];
1686
1687 if (priv->bss_mode) {
1688 wiphy_err(wiphy, "Can't create multiple AP interfaces");
Bing Zhao858faa52012-06-15 15:49:54 -07001689 return ERR_PTR(-EINVAL);
Avinash Patild6bffe82012-05-08 18:30:15 -07001690 }
1691
1692 wdev = kzalloc(sizeof(struct wireless_dev), GFP_KERNEL);
1693 if (!wdev)
Bing Zhao858faa52012-06-15 15:49:54 -07001694 return ERR_PTR(-ENOMEM);
Avinash Patild6bffe82012-05-08 18:30:15 -07001695
1696 priv->wdev = wdev;
1697 wdev->wiphy = wiphy;
1698 wdev->iftype = NL80211_IFTYPE_AP;
1699
1700 priv->bss_type = MWIFIEX_BSS_TYPE_UAP;
1701 priv->frame_type = MWIFIEX_DATA_FRAME_TYPE_ETH_II;
Amitkumar Karwara458c0a2012-09-10 18:30:43 -07001702 priv->bss_priority = 0;
Avinash Patild6bffe82012-05-08 18:30:15 -07001703 priv->bss_role = MWIFIEX_BSS_ROLE_UAP;
1704 priv->bss_started = 0;
1705 priv->bss_num = 0;
1706 priv->bss_mode = type;
1707
1708 break;
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -07001709 default:
1710 wiphy_err(wiphy, "type not supported\n");
Bing Zhao858faa52012-06-15 15:49:54 -07001711 return ERR_PTR(-EINVAL);
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -07001712 }
1713
1714 dev = alloc_netdev_mq(sizeof(struct mwifiex_private *), name,
1715 ether_setup, 1);
1716 if (!dev) {
1717 wiphy_err(wiphy, "no memory available for netdevice\n");
Bing Zhao858faa52012-06-15 15:49:54 -07001718 priv->bss_mode = NL80211_IFTYPE_UNSPECIFIED;
1719 return ERR_PTR(-ENOMEM);
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -07001720 }
1721
Avinash Patild6bffe82012-05-08 18:30:15 -07001722 mwifiex_init_priv_params(priv, dev);
1723 priv->netdev = dev;
1724
1725 mwifiex_setup_ht_caps(&wiphy->bands[IEEE80211_BAND_2GHZ]->ht_cap, priv);
1726
1727 if (adapter->config_bands & BAND_A)
1728 mwifiex_setup_ht_caps(
1729 &wiphy->bands[IEEE80211_BAND_5GHZ]->ht_cap, priv);
1730
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -07001731 dev_net_set(dev, wiphy_net(wiphy));
1732 dev->ieee80211_ptr = priv->wdev;
1733 dev->ieee80211_ptr->iftype = priv->bss_mode;
1734 memcpy(dev->dev_addr, wiphy->perm_addr, ETH_ALEN);
1735 memcpy(dev->perm_addr, wiphy->perm_addr, ETH_ALEN);
1736 SET_NETDEV_DEV(dev, wiphy_dev(wiphy));
1737
1738 dev->flags |= IFF_BROADCAST | IFF_MULTICAST;
1739 dev->watchdog_timeo = MWIFIEX_DEFAULT_WATCHDOG_TIMEOUT;
1740 dev->hard_header_len += MWIFIEX_MIN_DATA_HEADER_LEN;
1741
1742 mdev_priv = netdev_priv(dev);
1743 *((unsigned long *) mdev_priv) = (unsigned long) priv;
1744
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -07001745 SET_NETDEV_DEV(dev, adapter->dev);
1746
1747 /* Register network device */
1748 if (register_netdevice(dev)) {
1749 wiphy_err(wiphy, "cannot register virtual network device\n");
Bing Zhao858faa52012-06-15 15:49:54 -07001750 free_netdev(dev);
1751 priv->bss_mode = NL80211_IFTYPE_UNSPECIFIED;
1752 return ERR_PTR(-EFAULT);
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -07001753 }
1754
1755 sema_init(&priv->async_sem, 1);
1756 priv->scan_pending_on_block = false;
1757
1758 dev_dbg(adapter->dev, "info: %s: Marvell 802.11 Adapter\n", dev->name);
1759
1760#ifdef CONFIG_DEBUG_FS
1761 mwifiex_dev_debugfs_init(priv);
1762#endif
Johannes Berg84efbb82012-06-16 00:00:26 +02001763 return wdev;
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -07001764}
1765EXPORT_SYMBOL_GPL(mwifiex_add_virtual_intf);
1766
1767/*
1768 * del_virtual_intf: remove the virtual interface determined by dev
1769 */
Johannes Berg84efbb82012-06-16 00:00:26 +02001770int mwifiex_del_virtual_intf(struct wiphy *wiphy, struct wireless_dev *wdev)
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -07001771{
Johannes Berg84efbb82012-06-16 00:00:26 +02001772 struct mwifiex_private *priv = mwifiex_netdev_get_priv(wdev->netdev);
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -07001773
1774#ifdef CONFIG_DEBUG_FS
1775 mwifiex_dev_debugfs_remove(priv);
1776#endif
1777
1778 if (!netif_queue_stopped(priv->netdev))
1779 netif_stop_queue(priv->netdev);
1780
1781 if (netif_carrier_ok(priv->netdev))
1782 netif_carrier_off(priv->netdev);
1783
Johannes Berg84efbb82012-06-16 00:00:26 +02001784 if (wdev->netdev->reg_state == NETREG_REGISTERED)
1785 unregister_netdevice(wdev->netdev);
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -07001786
Johannes Berg84efbb82012-06-16 00:00:26 +02001787 if (wdev->netdev->reg_state == NETREG_UNREGISTERED)
1788 free_netdev(wdev->netdev);
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -07001789
1790 /* Clear the priv in adapter */
1791 priv->netdev = NULL;
1792
1793 priv->media_connected = false;
1794
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -07001795 priv->bss_mode = NL80211_IFTYPE_UNSPECIFIED;
1796
1797 return 0;
1798}
1799EXPORT_SYMBOL_GPL(mwifiex_del_virtual_intf);
1800
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001801/* station cfg80211 operations */
1802static struct cfg80211_ops mwifiex_cfg80211_ops = {
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -07001803 .add_virtual_intf = mwifiex_add_virtual_intf,
1804 .del_virtual_intf = mwifiex_del_virtual_intf,
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001805 .change_virtual_intf = mwifiex_cfg80211_change_virtual_intf,
1806 .scan = mwifiex_cfg80211_scan,
1807 .connect = mwifiex_cfg80211_connect,
1808 .disconnect = mwifiex_cfg80211_disconnect,
1809 .get_station = mwifiex_cfg80211_get_station,
Amitkumar Karwarf85aae62012-03-15 20:51:48 -07001810 .dump_station = mwifiex_cfg80211_dump_station,
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001811 .set_wiphy_params = mwifiex_cfg80211_set_wiphy_params,
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001812 .join_ibss = mwifiex_cfg80211_join_ibss,
1813 .leave_ibss = mwifiex_cfg80211_leave_ibss,
1814 .add_key = mwifiex_cfg80211_add_key,
1815 .del_key = mwifiex_cfg80211_del_key,
1816 .set_default_key = mwifiex_cfg80211_set_default_key,
1817 .set_power_mgmt = mwifiex_cfg80211_set_power_mgmt,
1818 .set_tx_power = mwifiex_cfg80211_set_tx_power,
Yogesh Ashok Powar5d82c532011-07-11 20:04:44 -07001819 .set_bitrate_mask = mwifiex_cfg80211_set_bitrate_mask,
Avinash Patil12190c52012-05-08 18:30:24 -07001820 .start_ap = mwifiex_cfg80211_start_ap,
1821 .stop_ap = mwifiex_cfg80211_stop_ap,
Avinash Patil5370c832012-06-28 20:30:28 -07001822 .change_beacon = mwifiex_cfg80211_change_beacon,
Amitkumar Karwarfa444bf2012-03-15 20:51:51 -07001823 .set_cqm_rssi_config = mwifiex_cfg80211_set_cqm_rssi_config,
Amitkumar Karwar8a279d52012-07-02 19:32:33 -07001824 .set_antenna = mwifiex_cfg80211_set_antenna,
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001825};
1826
1827/*
1828 * This function registers the device with CFG802.11 subsystem.
1829 *
1830 * The function creates the wireless device/wiphy, populates it with
1831 * default parameters and handler function pointers, and finally
1832 * registers the device.
1833 */
Avinash Patild6bffe82012-05-08 18:30:15 -07001834
1835int mwifiex_register_cfg80211(struct mwifiex_adapter *adapter)
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001836{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -07001837 int ret;
1838 void *wdev_priv;
Avinash Patild6bffe82012-05-08 18:30:15 -07001839 struct wiphy *wiphy;
1840 struct mwifiex_private *priv = adapter->priv[MWIFIEX_BSS_TYPE_STA];
Amitkumar Karwar9e04a7c2012-04-09 20:06:54 -07001841 u8 *country_code;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001842
Avinash Patild6bffe82012-05-08 18:30:15 -07001843 /* create a new wiphy for use with cfg80211 */
1844 wiphy = wiphy_new(&mwifiex_cfg80211_ops,
1845 sizeof(struct mwifiex_adapter *));
1846 if (!wiphy) {
1847 dev_err(adapter->dev, "%s: creating new wiphy\n", __func__);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001848 return -ENOMEM;
1849 }
Avinash Patild6bffe82012-05-08 18:30:15 -07001850 wiphy->max_scan_ssids = MWIFIEX_MAX_SSID_LIST_LENGTH;
1851 wiphy->max_scan_ie_len = MWIFIEX_MAX_VSIE_LEN;
1852 wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
1853 BIT(NL80211_IFTYPE_ADHOC) |
1854 BIT(NL80211_IFTYPE_AP);
Amitkumar Karwaradc89592011-04-27 19:13:11 -07001855
Avinash Patild6bffe82012-05-08 18:30:15 -07001856 wiphy->bands[IEEE80211_BAND_2GHZ] = &mwifiex_band_2ghz;
1857 if (adapter->config_bands & BAND_A)
1858 wiphy->bands[IEEE80211_BAND_5GHZ] = &mwifiex_band_5ghz;
1859 else
1860 wiphy->bands[IEEE80211_BAND_5GHZ] = NULL;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001861
Avinash Patilcd8440d2012-05-08 18:30:16 -07001862 wiphy->iface_combinations = &mwifiex_iface_comb_ap_sta;
1863 wiphy->n_iface_combinations = 1;
1864
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001865 /* Initialize cipher suits */
Avinash Patild6bffe82012-05-08 18:30:15 -07001866 wiphy->cipher_suites = mwifiex_cipher_suites;
1867 wiphy->n_cipher_suites = ARRAY_SIZE(mwifiex_cipher_suites);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001868
Avinash Patild6bffe82012-05-08 18:30:15 -07001869 memcpy(wiphy->perm_addr, priv->curr_addr, ETH_ALEN);
1870 wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
Avinash Patil2dd2bd62012-06-28 20:30:29 -07001871 wiphy->flags |= WIPHY_FLAG_HAVE_AP_SME |
Amitkumar Karwarcc0ba0d52012-09-10 18:30:47 -07001872 WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD |
1873 WIPHY_FLAG_CUSTOM_REGULATORY;
1874
1875 wiphy_apply_custom_regulatory(wiphy, &mwifiex_world_regdom_custom);
Avinash Patil2dd2bd62012-06-28 20:30:29 -07001876
1877 wiphy->probe_resp_offload = NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS |
1878 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001879
Amitkumar Karwar8a279d52012-07-02 19:32:33 -07001880 wiphy->available_antennas_tx = BIT(adapter->number_of_antenna) - 1;
1881 wiphy->available_antennas_rx = BIT(adapter->number_of_antenna) - 1;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001882
Amitkumar Karwar05910f42012-07-13 20:09:32 -07001883 wiphy->features = NL80211_FEATURE_HT_IBSS;
1884
Amitkumar Karwarb5abcf02012-04-16 21:36:52 -07001885 /* Reserve space for mwifiex specific private data for BSS */
Avinash Patild6bffe82012-05-08 18:30:15 -07001886 wiphy->bss_priv_size = sizeof(struct mwifiex_bss_priv);
Amitkumar Karwar5116f3c2011-09-21 21:43:23 -07001887
Avinash Patild6bffe82012-05-08 18:30:15 -07001888 wiphy->reg_notifier = mwifiex_reg_notifier;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001889
Avinash Patil67fdf392012-05-08 18:30:17 -07001890 /* Set struct mwifiex_adapter pointer in wiphy_priv */
Avinash Patild6bffe82012-05-08 18:30:15 -07001891 wdev_priv = wiphy_priv(wiphy);
Avinash Patil67fdf392012-05-08 18:30:17 -07001892 *(unsigned long *)wdev_priv = (unsigned long)adapter;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001893
Joe Perches2c208892012-06-04 12:44:17 +00001894 set_wiphy_dev(wiphy, priv->adapter->dev);
Yogesh Ashok Powara7b21162011-06-13 09:49:27 +05301895
Avinash Patild6bffe82012-05-08 18:30:15 -07001896 ret = wiphy_register(wiphy);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001897 if (ret < 0) {
Avinash Patild6bffe82012-05-08 18:30:15 -07001898 dev_err(adapter->dev,
1899 "%s: wiphy_register failed: %d\n", __func__, ret);
1900 wiphy_free(wiphy);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001901 return ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001902 }
Amitkumar Karwar9e04a7c2012-04-09 20:06:54 -07001903 country_code = mwifiex_11d_code_2_region(priv->adapter->region_code);
Bing Zhao77c8a142012-09-10 18:30:46 -07001904 if (country_code)
1905 dev_info(adapter->dev,
1906 "ignoring F/W country code %2.2s\n", country_code);
Amitkumar Karwar9e04a7c2012-04-09 20:06:54 -07001907
Avinash Patild6bffe82012-05-08 18:30:15 -07001908 adapter->wiphy = wiphy;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001909 return ret;
1910}