blob: f7a06d2bc670d72f34e292149942294a73ad4b94 [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
Amitkumar Karwar05910f42012-07-13 20:09:32 -070051mwifiex_chan_type_to_sec_chan_offset(enum nl80211_channel_type chan_type)
Bing Zhao5e6e3a92011-03-21 18:00:50 -070052{
Amitkumar Karwar05910f42012-07-13 20:09:32 -070053 switch (chan_type) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -070054 case NL80211_CHAN_NO_HT:
55 case NL80211_CHAN_HT20:
Amitkumar Karwar21c3ba32011-12-20 23:47:21 -080056 return IEEE80211_HT_PARAM_CHA_SEC_NONE;
Bing Zhao5e6e3a92011-03-21 18:00:50 -070057 case NL80211_CHAN_HT40PLUS:
Amitkumar Karwar21c3ba32011-12-20 23:47:21 -080058 return IEEE80211_HT_PARAM_CHA_SEC_ABOVE;
Bing Zhao5e6e3a92011-03-21 18:00:50 -070059 case NL80211_CHAN_HT40MINUS:
Amitkumar Karwar21c3ba32011-12-20 23:47:21 -080060 return IEEE80211_HT_PARAM_CHA_SEC_BELOW;
Bing Zhao5e6e3a92011-03-21 18:00:50 -070061 default:
Amitkumar Karwar21c3ba32011-12-20 23:47:21 -080062 return IEEE80211_HT_PARAM_CHA_SEC_NONE;
Bing Zhao5e6e3a92011-03-21 18:00:50 -070063 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -070064}
65
66/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -070067 * This function checks whether WEP is set.
68 */
69static int
70mwifiex_is_alg_wep(u32 cipher)
71{
Bing Zhao5e6e3a92011-03-21 18:00:50 -070072 switch (cipher) {
Yogesh Ashok Powar2be50b82011-04-01 18:36:47 -070073 case WLAN_CIPHER_SUITE_WEP40:
74 case WLAN_CIPHER_SUITE_WEP104:
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -070075 return 1;
Bing Zhao5e6e3a92011-03-21 18:00:50 -070076 default:
Bing Zhao5e6e3a92011-03-21 18:00:50 -070077 break;
78 }
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -070079
80 return 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -070081}
82
83/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -070084 * This function retrieves the private structure from kernel wiphy structure.
85 */
Avinash Patil67fdf392012-05-08 18:30:17 -070086static void *mwifiex_cfg80211_get_adapter(struct wiphy *wiphy)
Bing Zhao5e6e3a92011-03-21 18:00:50 -070087{
88 return (void *) (*(unsigned long *) wiphy_priv(wiphy));
89}
90
91/*
92 * CFG802.11 operation handler to delete a network key.
93 */
94static int
95mwifiex_cfg80211_del_key(struct wiphy *wiphy, struct net_device *netdev,
96 u8 key_index, bool pairwise, const u8 *mac_addr)
97{
Yogesh Ashok Powarf540f9f2012-01-11 20:06:12 -080098 struct mwifiex_private *priv = mwifiex_netdev_get_priv(netdev);
Avinash Patil75edd2c2012-05-08 18:30:18 -070099 const u8 bc_mac[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
100 const u8 *peer_mac = pairwise ? mac_addr : bc_mac;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700101
Ying Luo53b11232012-08-03 18:06:13 -0700102 if (mwifiex_set_encode(priv, NULL, NULL, 0, key_index, peer_mac, 1)) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700103 wiphy_err(wiphy, "deleting the crypto keys\n");
104 return -EFAULT;
105 }
106
107 wiphy_dbg(wiphy, "info: crypto keys deleted\n");
108 return 0;
109}
110
111/*
112 * CFG802.11 operation handler to set Tx power.
113 */
114static int
115mwifiex_cfg80211_set_tx_power(struct wiphy *wiphy,
116 enum nl80211_tx_power_setting type,
Luis R. Rodriguez742c29f2011-11-28 16:38:50 -0500117 int mbm)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700118{
Avinash Patil67fdf392012-05-08 18:30:17 -0700119 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
120 struct mwifiex_private *priv;
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700121 struct mwifiex_power_cfg power_cfg;
Luis R. Rodriguez742c29f2011-11-28 16:38:50 -0500122 int dbm = MBM_TO_DBM(mbm);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700123
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700124 if (type == NL80211_TX_POWER_FIXED) {
125 power_cfg.is_power_auto = 0;
126 power_cfg.power_level = dbm;
127 } else {
128 power_cfg.is_power_auto = 1;
129 }
130
Avinash Patil67fdf392012-05-08 18:30:17 -0700131 priv = mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY);
132
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700133 return mwifiex_set_tx_power(priv, &power_cfg);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700134}
135
136/*
137 * CFG802.11 operation handler to set Power Save option.
138 *
139 * The timeout value, if provided, is currently ignored.
140 */
141static int
142mwifiex_cfg80211_set_power_mgmt(struct wiphy *wiphy,
143 struct net_device *dev,
144 bool enabled, int timeout)
145{
Yogesh Ashok Powarf540f9f2012-01-11 20:06:12 -0800146 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700147 u32 ps_mode;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700148
149 if (timeout)
150 wiphy_dbg(wiphy,
Yogesh Ashok Powaraea07012012-03-13 19:22:35 -0700151 "info: ignore timeout value for IEEE Power Save\n");
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700152
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700153 ps_mode = enabled;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700154
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700155 return mwifiex_drv_set_power(priv, &ps_mode);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700156}
157
158/*
159 * CFG802.11 operation handler to set the default network key.
160 */
161static int
162mwifiex_cfg80211_set_default_key(struct wiphy *wiphy, struct net_device *netdev,
163 u8 key_index, bool unicast,
164 bool multicast)
165{
Yogesh Ashok Powarf540f9f2012-01-11 20:06:12 -0800166 struct mwifiex_private *priv = mwifiex_netdev_get_priv(netdev);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700167
Amitkumar Karwar2d3d0a82011-04-01 18:36:46 -0700168 /* Return if WEP key not configured */
Amitkumar Karwar5eb02e42012-02-24 21:36:04 -0800169 if (!priv->sec_info.wep_enabled)
Amitkumar Karwar2d3d0a82011-04-01 18:36:46 -0700170 return 0;
171
Avinash Patil96893532012-06-15 12:21:55 -0700172 if (priv->bss_type == MWIFIEX_BSS_TYPE_UAP) {
173 priv->wep_key_curr_index = key_index;
Ying Luo53b11232012-08-03 18:06:13 -0700174 } else if (mwifiex_set_encode(priv, NULL, NULL, 0, key_index,
175 NULL, 0)) {
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700176 wiphy_err(wiphy, "set default Tx key index\n");
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700177 return -EFAULT;
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700178 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700179
180 return 0;
181}
182
183/*
184 * CFG802.11 operation handler to add a network key.
185 */
186static int
187mwifiex_cfg80211_add_key(struct wiphy *wiphy, struct net_device *netdev,
188 u8 key_index, bool pairwise, const u8 *mac_addr,
189 struct key_params *params)
190{
Yogesh Ashok Powarf540f9f2012-01-11 20:06:12 -0800191 struct mwifiex_private *priv = mwifiex_netdev_get_priv(netdev);
Avinash Patil96893532012-06-15 12:21:55 -0700192 struct mwifiex_wep_key *wep_key;
Avinash Patil75edd2c2012-05-08 18:30:18 -0700193 const u8 bc_mac[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
194 const u8 *peer_mac = pairwise ? mac_addr : bc_mac;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700195
Avinash Patil96893532012-06-15 12:21:55 -0700196 if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_UAP &&
197 (params->cipher == WLAN_CIPHER_SUITE_WEP40 ||
198 params->cipher == WLAN_CIPHER_SUITE_WEP104)) {
199 if (params->key && params->key_len) {
200 wep_key = &priv->wep_key[key_index];
201 memset(wep_key, 0, sizeof(struct mwifiex_wep_key));
202 memcpy(wep_key->key_material, params->key,
203 params->key_len);
204 wep_key->key_index = key_index;
205 wep_key->key_length = params->key_len;
206 priv->sec_info.wep_enabled = 1;
207 }
208 return 0;
209 }
210
Ying Luo53b11232012-08-03 18:06:13 -0700211 if (mwifiex_set_encode(priv, params, params->key, params->key_len,
Avinash Patil75edd2c2012-05-08 18:30:18 -0700212 key_index, peer_mac, 0)) {
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700213 wiphy_err(wiphy, "crypto keys added\n");
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700214 return -EFAULT;
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700215 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700216
217 return 0;
218}
219
220/*
221 * This function sends domain information to the firmware.
222 *
223 * The following information are passed to the firmware -
224 * - Country codes
225 * - Sub bands (first channel, number of channels, maximum Tx power)
226 */
227static int mwifiex_send_domain_info_cmd_fw(struct wiphy *wiphy)
228{
229 u8 no_of_triplet = 0;
230 struct ieee80211_country_ie_triplet *t;
231 u8 no_of_parsed_chan = 0;
232 u8 first_chan = 0, next_chan = 0, max_pwr = 0;
233 u8 i, flag = 0;
234 enum ieee80211_band band;
235 struct ieee80211_supported_band *sband;
236 struct ieee80211_channel *ch;
Avinash Patil67fdf392012-05-08 18:30:17 -0700237 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
238 struct mwifiex_private *priv;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700239 struct mwifiex_802_11d_domain_reg *domain_info = &adapter->domain_reg;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700240
241 /* Set country code */
Avinash Patil67fdf392012-05-08 18:30:17 -0700242 domain_info->country_code[0] = adapter->country_code[0];
243 domain_info->country_code[1] = adapter->country_code[1];
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700244 domain_info->country_code[2] = ' ';
245
246 band = mwifiex_band_to_radio_type(adapter->config_bands);
247 if (!wiphy->bands[band]) {
248 wiphy_err(wiphy, "11D: setting domain info in FW\n");
249 return -1;
250 }
251
252 sband = wiphy->bands[band];
253
254 for (i = 0; i < sband->n_channels ; i++) {
255 ch = &sband->channels[i];
256 if (ch->flags & IEEE80211_CHAN_DISABLED)
257 continue;
258
259 if (!flag) {
260 flag = 1;
261 first_chan = (u32) ch->hw_value;
262 next_chan = first_chan;
Amitkumar Karwar34202e22012-06-27 19:57:59 -0700263 max_pwr = ch->max_reg_power;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700264 no_of_parsed_chan = 1;
265 continue;
266 }
267
268 if (ch->hw_value == next_chan + 1 &&
Amitkumar Karwar34202e22012-06-27 19:57:59 -0700269 ch->max_reg_power == max_pwr) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700270 next_chan++;
271 no_of_parsed_chan++;
272 } else {
273 t = &domain_info->triplet[no_of_triplet];
274 t->chans.first_channel = first_chan;
275 t->chans.num_channels = no_of_parsed_chan;
276 t->chans.max_power = max_pwr;
277 no_of_triplet++;
278 first_chan = (u32) ch->hw_value;
279 next_chan = first_chan;
Amitkumar Karwar34202e22012-06-27 19:57:59 -0700280 max_pwr = ch->max_reg_power;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700281 no_of_parsed_chan = 1;
282 }
283 }
284
285 if (flag) {
286 t = &domain_info->triplet[no_of_triplet];
287 t->chans.first_channel = first_chan;
288 t->chans.num_channels = no_of_parsed_chan;
289 t->chans.max_power = max_pwr;
290 no_of_triplet++;
291 }
292
293 domain_info->no_of_triplet = no_of_triplet;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700294
Avinash Patil67fdf392012-05-08 18:30:17 -0700295 priv = mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY);
296
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700297 if (mwifiex_send_cmd_async(priv, HostCmd_CMD_802_11D_DOMAIN_INFO,
Yogesh Ashok Powaraea07012012-03-13 19:22:35 -0700298 HostCmd_ACT_GEN_SET, 0, NULL)) {
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700299 wiphy_err(wiphy, "11D: setting domain info in FW\n");
300 return -1;
301 }
302
303 return 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700304}
305
306/*
307 * CFG802.11 regulatory domain callback function.
308 *
309 * This function is called when the regulatory domain is changed due to the
310 * following reasons -
311 * - Set by driver
312 * - Set by system core
313 * - Set by user
314 * - Set bt Country IE
315 */
316static int mwifiex_reg_notifier(struct wiphy *wiphy,
Yogesh Ashok Powaraea07012012-03-13 19:22:35 -0700317 struct regulatory_request *request)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700318{
Avinash Patil67fdf392012-05-08 18:30:17 -0700319 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700320
Avinash Patil67fdf392012-05-08 18:30:17 -0700321 wiphy_dbg(wiphy, "info: cfg80211 regulatory domain callback for %c%c\n",
322 request->alpha2[0], request->alpha2[1]);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700323
Avinash Patil67fdf392012-05-08 18:30:17 -0700324 memcpy(adapter->country_code, request->alpha2, sizeof(request->alpha2));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700325
326 switch (request->initiator) {
327 case NL80211_REGDOM_SET_BY_DRIVER:
328 case NL80211_REGDOM_SET_BY_CORE:
329 case NL80211_REGDOM_SET_BY_USER:
330 break;
331 /* Todo: apply driver specific changes in channel flags based
332 on the request initiator if necessary. */
333 case NL80211_REGDOM_SET_BY_COUNTRY_IE:
334 break;
335 }
336 mwifiex_send_domain_info_cmd_fw(wiphy);
337
338 return 0;
339}
340
341/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700342 * This function sets the fragmentation threshold.
343 *
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700344 * The fragmentation threshold value must lie between MWIFIEX_FRAG_MIN_VALUE
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700345 * and MWIFIEX_FRAG_MAX_VALUE.
346 */
347static int
348mwifiex_set_frag(struct mwifiex_private *priv, u32 frag_thr)
349{
Yogesh Ashok Powaraea07012012-03-13 19:22:35 -0700350 if (frag_thr < MWIFIEX_FRAG_MIN_VALUE ||
351 frag_thr > MWIFIEX_FRAG_MAX_VALUE)
Avinash Patil9b930ea2012-05-08 18:30:23 -0700352 frag_thr = MWIFIEX_FRAG_MAX_VALUE;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700353
Avinash Patil9b930ea2012-05-08 18:30:23 -0700354 return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_SNMP_MIB,
355 HostCmd_ACT_GEN_SET, FRAG_THRESH_I,
356 &frag_thr);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700357}
358
359/*
360 * This function sets the RTS threshold.
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700361
362 * The rts value must lie between MWIFIEX_RTS_MIN_VALUE
363 * and MWIFIEX_RTS_MAX_VALUE.
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700364 */
365static int
366mwifiex_set_rts(struct mwifiex_private *priv, u32 rts_thr)
367{
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700368 if (rts_thr < MWIFIEX_RTS_MIN_VALUE || rts_thr > MWIFIEX_RTS_MAX_VALUE)
369 rts_thr = MWIFIEX_RTS_MAX_VALUE;
370
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700371 return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_SNMP_MIB,
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700372 HostCmd_ACT_GEN_SET, RTS_THRESH_I,
373 &rts_thr);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700374}
375
376/*
377 * CFG802.11 operation handler to set wiphy parameters.
378 *
379 * This function can be used to set the RTS threshold and the
380 * Fragmentation threshold of the driver.
381 */
382static int
383mwifiex_cfg80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
384{
Avinash Patil67fdf392012-05-08 18:30:17 -0700385 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
Avinash Patil9b930ea2012-05-08 18:30:23 -0700386 struct mwifiex_private *priv;
387 struct mwifiex_uap_bss_param *bss_cfg;
388 int ret, bss_started, i;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700389
Avinash Patil9b930ea2012-05-08 18:30:23 -0700390 for (i = 0; i < adapter->priv_num; i++) {
391 priv = adapter->priv[i];
392
393 switch (priv->bss_role) {
394 case MWIFIEX_BSS_ROLE_UAP:
395 bss_cfg = kzalloc(sizeof(struct mwifiex_uap_bss_param),
396 GFP_KERNEL);
397 if (!bss_cfg)
398 return -ENOMEM;
399
400 mwifiex_set_sys_config_invalid_data(bss_cfg);
401
402 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
403 bss_cfg->rts_threshold = wiphy->rts_threshold;
404 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
405 bss_cfg->frag_threshold = wiphy->frag_threshold;
406 if (changed & WIPHY_PARAM_RETRY_LONG)
407 bss_cfg->retry_limit = wiphy->retry_long;
408
409 bss_started = priv->bss_started;
410
411 ret = mwifiex_send_cmd_sync(priv,
412 HostCmd_CMD_UAP_BSS_STOP,
413 HostCmd_ACT_GEN_SET, 0,
414 NULL);
415 if (ret) {
416 wiphy_err(wiphy, "Failed to stop the BSS\n");
417 kfree(bss_cfg);
418 return ret;
419 }
420
421 ret = mwifiex_send_cmd_async(priv,
422 HostCmd_CMD_UAP_SYS_CONFIG,
423 HostCmd_ACT_GEN_SET,
Avinash Patile76268d2012-05-08 18:30:27 -0700424 UAP_BSS_PARAMS_I, bss_cfg);
Avinash Patil9b930ea2012-05-08 18:30:23 -0700425
426 kfree(bss_cfg);
427
428 if (ret) {
429 wiphy_err(wiphy, "Failed to set bss config\n");
430 return ret;
431 }
432
433 if (!bss_started)
434 break;
435
436 ret = mwifiex_send_cmd_async(priv,
437 HostCmd_CMD_UAP_BSS_START,
438 HostCmd_ACT_GEN_SET, 0,
439 NULL);
440 if (ret) {
441 wiphy_err(wiphy, "Failed to start BSS\n");
442 return ret;
443 }
444
445 break;
446 case MWIFIEX_BSS_ROLE_STA:
447 if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
448 ret = mwifiex_set_rts(priv,
449 wiphy->rts_threshold);
450 if (ret)
451 return ret;
452 }
453 if (changed & WIPHY_PARAM_FRAG_THRESHOLD) {
454 ret = mwifiex_set_frag(priv,
455 wiphy->frag_threshold);
456 if (ret)
457 return ret;
458 }
459 break;
460 }
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700461 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700462
Avinash Patil9b930ea2012-05-08 18:30:23 -0700463 return 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700464}
465
466/*
467 * CFG802.11 operation handler to change interface type.
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700468 */
469static int
470mwifiex_cfg80211_change_virtual_intf(struct wiphy *wiphy,
471 struct net_device *dev,
472 enum nl80211_iftype type, u32 *flags,
473 struct vif_params *params)
474{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700475 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700476 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
Bing Zhaoeecd8252011-03-28 17:55:41 -0700477
Avinash Patil4f023412012-05-08 18:30:22 -0700478 switch (dev->ieee80211_ptr->iftype) {
Bing Zhaoeecd8252011-03-28 17:55:41 -0700479 case NL80211_IFTYPE_ADHOC:
Avinash Patil4f023412012-05-08 18:30:22 -0700480 switch (type) {
481 case NL80211_IFTYPE_STATION:
482 break;
483 case NL80211_IFTYPE_UNSPECIFIED:
484 wiphy_warn(wiphy, "%s: kept type as IBSS\n", dev->name);
485 case NL80211_IFTYPE_ADHOC: /* This shouldn't happen */
486 return 0;
487 case NL80211_IFTYPE_AP:
488 default:
489 wiphy_err(wiphy, "%s: changing to %d not supported\n",
490 dev->name, type);
491 return -EOPNOTSUPP;
492 }
Bing Zhaoeecd8252011-03-28 17:55:41 -0700493 break;
494 case NL80211_IFTYPE_STATION:
Avinash Patil4f023412012-05-08 18:30:22 -0700495 switch (type) {
496 case NL80211_IFTYPE_ADHOC:
497 break;
498 case NL80211_IFTYPE_UNSPECIFIED:
499 wiphy_warn(wiphy, "%s: kept type as STA\n", dev->name);
500 case NL80211_IFTYPE_STATION: /* This shouldn't happen */
501 return 0;
502 case NL80211_IFTYPE_AP:
503 default:
504 wiphy_err(wiphy, "%s: changing to %d not supported\n",
505 dev->name, type);
506 return -EOPNOTSUPP;
507 }
Bing Zhaoeecd8252011-03-28 17:55:41 -0700508 break;
Avinash Patil4f023412012-05-08 18:30:22 -0700509 case NL80211_IFTYPE_AP:
510 switch (type) {
511 case NL80211_IFTYPE_UNSPECIFIED:
512 wiphy_warn(wiphy, "%s: kept type as AP\n", dev->name);
513 case NL80211_IFTYPE_AP: /* This shouldn't happen */
514 return 0;
515 case NL80211_IFTYPE_ADHOC:
516 case NL80211_IFTYPE_STATION:
517 default:
518 wiphy_err(wiphy, "%s: changing to %d not supported\n",
519 dev->name, type);
520 return -EOPNOTSUPP;
521 }
522 break;
Bing Zhaoeecd8252011-03-28 17:55:41 -0700523 default:
Avinash Patil4f023412012-05-08 18:30:22 -0700524 wiphy_err(wiphy, "%s: unknown iftype: %d\n",
525 dev->name, dev->ieee80211_ptr->iftype);
526 return -EOPNOTSUPP;
Bing Zhaoeecd8252011-03-28 17:55:41 -0700527 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700528
Avinash Patil4f023412012-05-08 18:30:22 -0700529 dev->ieee80211_ptr->iftype = type;
530 priv->bss_mode = type;
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700531 mwifiex_deauthenticate(priv, NULL);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700532
Marc Yangf986b6d2011-03-28 17:55:42 -0700533 priv->sec_info.authentication_mode = NL80211_AUTHTYPE_OPEN_SYSTEM;
Bing Zhaoeecd8252011-03-28 17:55:41 -0700534
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700535 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_SET_BSS_MODE,
536 HostCmd_ACT_GEN_SET, 0, NULL);
Bing Zhaoeecd8252011-03-28 17:55:41 -0700537
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700538 return ret;
539}
540
541/*
542 * This function dumps the station information on a buffer.
543 *
544 * The following information are shown -
545 * - Total bytes transmitted
546 * - Total bytes received
547 * - Total packets transmitted
548 * - Total packets received
549 * - Signal quality level
550 * - Transmission rate
551 */
552static int
553mwifiex_dump_station_info(struct mwifiex_private *priv,
554 struct station_info *sinfo)
555{
Amitkumar Karwar006606c2012-07-13 20:09:31 -0700556 u32 rate;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700557
558 sinfo->filled = STATION_INFO_RX_BYTES | STATION_INFO_TX_BYTES |
Amitkumar Karwar7013d3e2012-03-15 20:51:50 -0700559 STATION_INFO_RX_PACKETS | STATION_INFO_TX_PACKETS |
560 STATION_INFO_TX_BITRATE |
561 STATION_INFO_SIGNAL | STATION_INFO_SIGNAL_AVG;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700562
563 /* Get signal information from the firmware */
Amitkumar Karwar958a4a82012-03-15 20:51:49 -0700564 if (mwifiex_send_cmd_sync(priv, HostCmd_CMD_RSSI_INFO,
565 HostCmd_ACT_GEN_GET, 0, NULL)) {
566 dev_err(priv->adapter->dev, "failed to get signal information\n");
567 return -EFAULT;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700568 }
569
570 if (mwifiex_drv_get_data_rate(priv, &rate)) {
571 dev_err(priv->adapter->dev, "getting data rate\n");
Amitkumar Karwar958a4a82012-03-15 20:51:49 -0700572 return -EFAULT;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700573 }
574
Amitkumar Karwarcaf60a62012-02-02 20:48:58 -0800575 /* Get DTIM period information from firmware */
576 mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_SNMP_MIB,
577 HostCmd_ACT_GEN_GET, DTIM_PERIOD_I,
578 &priv->dtim_period);
579
Amitkumar Karwar4ec6f9c2011-09-26 20:37:25 -0700580 /*
581 * Bit 0 in tx_htinfo indicates that current Tx rate is 11n rate. Valid
Amitkumar Karwarfe020122012-07-11 18:12:57 -0700582 * MCS index values for us are 0 to 15.
Amitkumar Karwar4ec6f9c2011-09-26 20:37:25 -0700583 */
Amitkumar Karwarfe020122012-07-11 18:12:57 -0700584 if ((priv->tx_htinfo & BIT(0)) && (priv->tx_rate < 16)) {
Amitkumar Karwar4ec6f9c2011-09-26 20:37:25 -0700585 sinfo->txrate.mcs = priv->tx_rate;
586 sinfo->txrate.flags |= RATE_INFO_FLAGS_MCS;
587 /* 40MHz rate */
588 if (priv->tx_htinfo & BIT(1))
589 sinfo->txrate.flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
590 /* SGI enabled */
591 if (priv->tx_htinfo & BIT(2))
592 sinfo->txrate.flags |= RATE_INFO_FLAGS_SHORT_GI;
593 }
594
Amitkumar Karwar7013d3e2012-03-15 20:51:50 -0700595 sinfo->signal_avg = priv->bcn_rssi_avg;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700596 sinfo->rx_bytes = priv->stats.rx_bytes;
597 sinfo->tx_bytes = priv->stats.tx_bytes;
598 sinfo->rx_packets = priv->stats.rx_packets;
599 sinfo->tx_packets = priv->stats.tx_packets;
Amitkumar Karwar958a4a82012-03-15 20:51:49 -0700600 sinfo->signal = priv->bcn_rssi_avg;
Amitkumar Karwar4ec6f9c2011-09-26 20:37:25 -0700601 /* bit rate is in 500 kb/s units. Convert it to 100kb/s units */
Amitkumar Karwar006606c2012-07-13 20:09:31 -0700602 sinfo->txrate.legacy = rate * 5;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700603
Amitkumar Karwarc4f3b972012-01-24 20:50:25 -0800604 if (priv->bss_mode == NL80211_IFTYPE_STATION) {
605 sinfo->filled |= STATION_INFO_BSS_PARAM;
606 sinfo->bss_param.flags = 0;
607 if (priv->curr_bss_params.bss_descriptor.cap_info_bitmap &
608 WLAN_CAPABILITY_SHORT_PREAMBLE)
609 sinfo->bss_param.flags |=
610 BSS_PARAM_FLAGS_SHORT_PREAMBLE;
611 if (priv->curr_bss_params.bss_descriptor.cap_info_bitmap &
612 WLAN_CAPABILITY_SHORT_SLOT_TIME)
613 sinfo->bss_param.flags |=
614 BSS_PARAM_FLAGS_SHORT_SLOT_TIME;
Amitkumar Karwarcaf60a62012-02-02 20:48:58 -0800615 sinfo->bss_param.dtim_period = priv->dtim_period;
Amitkumar Karwarc4f3b972012-01-24 20:50:25 -0800616 sinfo->bss_param.beacon_interval =
617 priv->curr_bss_params.bss_descriptor.beacon_period;
618 }
619
Amitkumar Karwar958a4a82012-03-15 20:51:49 -0700620 return 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700621}
622
623/*
624 * CFG802.11 operation handler to get station information.
625 *
626 * This function only works in connected mode, and dumps the
627 * requested station information, if available.
628 */
629static int
630mwifiex_cfg80211_get_station(struct wiphy *wiphy, struct net_device *dev,
631 u8 *mac, struct station_info *sinfo)
632{
633 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700634
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700635 if (!priv->media_connected)
636 return -ENOENT;
637 if (memcmp(mac, priv->cfg_bssid, ETH_ALEN))
638 return -ENOENT;
639
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700640 return mwifiex_dump_station_info(priv, sinfo);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700641}
642
Amitkumar Karwarf85aae62012-03-15 20:51:48 -0700643/*
644 * CFG802.11 operation handler to dump station information.
645 */
646static int
647mwifiex_cfg80211_dump_station(struct wiphy *wiphy, struct net_device *dev,
648 int idx, u8 *mac, struct station_info *sinfo)
649{
650 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
651
652 if (!priv->media_connected || idx)
653 return -ENOENT;
654
655 memcpy(mac, priv->cfg_bssid, ETH_ALEN);
656
657 return mwifiex_dump_station_info(priv, sinfo);
658}
659
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700660/* Supported rates to be advertised to the cfg80211 */
661
662static struct ieee80211_rate mwifiex_rates[] = {
663 {.bitrate = 10, .hw_value = 2, },
664 {.bitrate = 20, .hw_value = 4, },
665 {.bitrate = 55, .hw_value = 11, },
666 {.bitrate = 110, .hw_value = 22, },
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700667 {.bitrate = 60, .hw_value = 12, },
668 {.bitrate = 90, .hw_value = 18, },
669 {.bitrate = 120, .hw_value = 24, },
670 {.bitrate = 180, .hw_value = 36, },
671 {.bitrate = 240, .hw_value = 48, },
672 {.bitrate = 360, .hw_value = 72, },
673 {.bitrate = 480, .hw_value = 96, },
674 {.bitrate = 540, .hw_value = 108, },
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700675};
676
677/* Channel definitions to be advertised to cfg80211 */
678
679static struct ieee80211_channel mwifiex_channels_2ghz[] = {
680 {.center_freq = 2412, .hw_value = 1, },
681 {.center_freq = 2417, .hw_value = 2, },
682 {.center_freq = 2422, .hw_value = 3, },
683 {.center_freq = 2427, .hw_value = 4, },
684 {.center_freq = 2432, .hw_value = 5, },
685 {.center_freq = 2437, .hw_value = 6, },
686 {.center_freq = 2442, .hw_value = 7, },
687 {.center_freq = 2447, .hw_value = 8, },
688 {.center_freq = 2452, .hw_value = 9, },
689 {.center_freq = 2457, .hw_value = 10, },
690 {.center_freq = 2462, .hw_value = 11, },
691 {.center_freq = 2467, .hw_value = 12, },
692 {.center_freq = 2472, .hw_value = 13, },
693 {.center_freq = 2484, .hw_value = 14, },
694};
695
696static struct ieee80211_supported_band mwifiex_band_2ghz = {
697 .channels = mwifiex_channels_2ghz,
698 .n_channels = ARRAY_SIZE(mwifiex_channels_2ghz),
699 .bitrates = mwifiex_rates,
Amitkumar Karwar87638482012-03-07 19:36:07 -0800700 .n_bitrates = ARRAY_SIZE(mwifiex_rates),
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700701};
702
703static struct ieee80211_channel mwifiex_channels_5ghz[] = {
704 {.center_freq = 5040, .hw_value = 8, },
705 {.center_freq = 5060, .hw_value = 12, },
706 {.center_freq = 5080, .hw_value = 16, },
707 {.center_freq = 5170, .hw_value = 34, },
708 {.center_freq = 5190, .hw_value = 38, },
709 {.center_freq = 5210, .hw_value = 42, },
710 {.center_freq = 5230, .hw_value = 46, },
711 {.center_freq = 5180, .hw_value = 36, },
712 {.center_freq = 5200, .hw_value = 40, },
713 {.center_freq = 5220, .hw_value = 44, },
714 {.center_freq = 5240, .hw_value = 48, },
715 {.center_freq = 5260, .hw_value = 52, },
716 {.center_freq = 5280, .hw_value = 56, },
717 {.center_freq = 5300, .hw_value = 60, },
718 {.center_freq = 5320, .hw_value = 64, },
719 {.center_freq = 5500, .hw_value = 100, },
720 {.center_freq = 5520, .hw_value = 104, },
721 {.center_freq = 5540, .hw_value = 108, },
722 {.center_freq = 5560, .hw_value = 112, },
723 {.center_freq = 5580, .hw_value = 116, },
724 {.center_freq = 5600, .hw_value = 120, },
725 {.center_freq = 5620, .hw_value = 124, },
726 {.center_freq = 5640, .hw_value = 128, },
727 {.center_freq = 5660, .hw_value = 132, },
728 {.center_freq = 5680, .hw_value = 136, },
729 {.center_freq = 5700, .hw_value = 140, },
730 {.center_freq = 5745, .hw_value = 149, },
731 {.center_freq = 5765, .hw_value = 153, },
732 {.center_freq = 5785, .hw_value = 157, },
733 {.center_freq = 5805, .hw_value = 161, },
734 {.center_freq = 5825, .hw_value = 165, },
735};
736
737static struct ieee80211_supported_band mwifiex_band_5ghz = {
738 .channels = mwifiex_channels_5ghz,
739 .n_channels = ARRAY_SIZE(mwifiex_channels_5ghz),
Avinash Patileb416ad2012-02-27 22:04:11 -0800740 .bitrates = mwifiex_rates + 4,
741 .n_bitrates = ARRAY_SIZE(mwifiex_rates) - 4,
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700742};
743
744
745/* Supported crypto cipher suits to be advertised to cfg80211 */
746
747static const u32 mwifiex_cipher_suites[] = {
748 WLAN_CIPHER_SUITE_WEP40,
749 WLAN_CIPHER_SUITE_WEP104,
750 WLAN_CIPHER_SUITE_TKIP,
751 WLAN_CIPHER_SUITE_CCMP,
Ying Luo53b11232012-08-03 18:06:13 -0700752 WLAN_CIPHER_SUITE_AES_CMAC,
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700753};
754
755/*
Yogesh Ashok Powar5d82c532011-07-11 20:04:44 -0700756 * CFG802.11 operation handler for setting bit rates.
757 *
Amitkumar Karwar433c3992012-07-13 20:09:33 -0700758 * Function configures data rates to firmware using bitrate mask
759 * provided by cfg80211.
Yogesh Ashok Powar5d82c532011-07-11 20:04:44 -0700760 */
761static int mwifiex_cfg80211_set_bitrate_mask(struct wiphy *wiphy,
762 struct net_device *dev,
763 const u8 *peer,
764 const struct cfg80211_bitrate_mask *mask)
765{
Yogesh Ashok Powar5d82c532011-07-11 20:04:44 -0700766 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
Amitkumar Karwar433c3992012-07-13 20:09:33 -0700767 u16 bitmap_rates[MAX_BITMAP_RATES_SIZE];
768 enum ieee80211_band band;
Yogesh Ashok Powar5d82c532011-07-11 20:04:44 -0700769
Amitkumar Karwar433c3992012-07-13 20:09:33 -0700770 if (!priv->media_connected) {
771 dev_err(priv->adapter->dev,
772 "Can not set Tx data rate in disconnected state\n");
773 return -EINVAL;
Yogesh Ashok Powar5d82c532011-07-11 20:04:44 -0700774 }
775
Amitkumar Karwar433c3992012-07-13 20:09:33 -0700776 band = mwifiex_band_to_radio_type(priv->curr_bss_params.band);
Yogesh Ashok Powar5d82c532011-07-11 20:04:44 -0700777
Amitkumar Karwar433c3992012-07-13 20:09:33 -0700778 memset(bitmap_rates, 0, sizeof(bitmap_rates));
Yogesh Ashok Powar5d82c532011-07-11 20:04:44 -0700779
Amitkumar Karwar433c3992012-07-13 20:09:33 -0700780 /* Fill HR/DSSS rates. */
781 if (band == IEEE80211_BAND_2GHZ)
782 bitmap_rates[0] = mask->control[band].legacy & 0x000f;
Yogesh Ashok Powar5d82c532011-07-11 20:04:44 -0700783
Amitkumar Karwar433c3992012-07-13 20:09:33 -0700784 /* Fill OFDM rates */
785 if (band == IEEE80211_BAND_2GHZ)
786 bitmap_rates[1] = (mask->control[band].legacy & 0x0ff0) >> 4;
787 else
788 bitmap_rates[1] = mask->control[band].legacy;
789
790 /* Fill MCS rates */
791 bitmap_rates[2] = mask->control[band].mcs[0];
792 if (priv->adapter->hw_dev_mcs_support == HT_STREAM_2X2)
793 bitmap_rates[2] |= mask->control[band].mcs[1] << 8;
794
795 return mwifiex_send_cmd_sync(priv, HostCmd_CMD_TX_RATE_CFG,
796 HostCmd_ACT_GEN_SET, 0, bitmap_rates);
Yogesh Ashok Powar5d82c532011-07-11 20:04:44 -0700797}
798
799/*
Amitkumar Karwarfa444bf2012-03-15 20:51:51 -0700800 * CFG802.11 operation handler for connection quality monitoring.
801 *
802 * This function subscribes/unsubscribes HIGH_RSSI and LOW_RSSI
803 * events to FW.
804 */
805static int mwifiex_cfg80211_set_cqm_rssi_config(struct wiphy *wiphy,
806 struct net_device *dev,
807 s32 rssi_thold, u32 rssi_hyst)
808{
809 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
810 struct mwifiex_ds_misc_subsc_evt subsc_evt;
811
812 priv->cqm_rssi_thold = rssi_thold;
813 priv->cqm_rssi_hyst = rssi_hyst;
814
815 memset(&subsc_evt, 0x00, sizeof(struct mwifiex_ds_misc_subsc_evt));
816 subsc_evt.events = BITMASK_BCN_RSSI_LOW | BITMASK_BCN_RSSI_HIGH;
817
818 /* Subscribe/unsubscribe low and high rssi events */
819 if (rssi_thold && rssi_hyst) {
820 subsc_evt.action = HostCmd_ACT_BITWISE_SET;
821 subsc_evt.bcn_l_rssi_cfg.abs_value = abs(rssi_thold);
822 subsc_evt.bcn_h_rssi_cfg.abs_value = abs(rssi_thold);
823 subsc_evt.bcn_l_rssi_cfg.evt_freq = 1;
824 subsc_evt.bcn_h_rssi_cfg.evt_freq = 1;
825 return mwifiex_send_cmd_sync(priv,
826 HostCmd_CMD_802_11_SUBSCRIBE_EVENT,
827 0, 0, &subsc_evt);
828 } else {
829 subsc_evt.action = HostCmd_ACT_BITWISE_CLR;
830 return mwifiex_send_cmd_sync(priv,
831 HostCmd_CMD_802_11_SUBSCRIBE_EVENT,
832 0, 0, &subsc_evt);
833 }
834
835 return 0;
836}
837
Avinash Patil5370c832012-06-28 20:30:28 -0700838/* cfg80211 operation handler for change_beacon.
839 * Function retrieves and sets modified management IEs to FW.
840 */
841static int mwifiex_cfg80211_change_beacon(struct wiphy *wiphy,
842 struct net_device *dev,
843 struct cfg80211_beacon_data *data)
844{
845 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
846
847 if (priv->bss_type != MWIFIEX_BSS_TYPE_UAP) {
848 wiphy_err(wiphy, "%s: bss_type mismatched\n", __func__);
849 return -EINVAL;
850 }
851
852 if (!priv->bss_started) {
853 wiphy_err(wiphy, "%s: bss not started\n", __func__);
854 return -EINVAL;
855 }
856
857 if (mwifiex_set_mgmt_ies(priv, data)) {
858 wiphy_err(wiphy, "%s: setting mgmt ies failed\n", __func__);
859 return -EFAULT;
860 }
861
862 return 0;
863}
864
Amitkumar Karwar8a279d52012-07-02 19:32:33 -0700865static int
866mwifiex_cfg80211_set_antenna(struct wiphy *wiphy, u32 tx_ant, u32 rx_ant)
867{
868 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
869 struct mwifiex_private *priv = mwifiex_get_priv(adapter,
870 MWIFIEX_BSS_ROLE_ANY);
871 struct mwifiex_ds_ant_cfg ant_cfg;
872
873 if (!tx_ant || !rx_ant)
874 return -EOPNOTSUPP;
875
876 if (adapter->hw_dev_mcs_support != HT_STREAM_2X2) {
877 /* Not a MIMO chip. User should provide specific antenna number
878 * for Tx/Rx path or enable all antennas for diversity
879 */
880 if (tx_ant != rx_ant)
881 return -EOPNOTSUPP;
882
883 if ((tx_ant & (tx_ant - 1)) &&
884 (tx_ant != BIT(adapter->number_of_antenna) - 1))
885 return -EOPNOTSUPP;
886
887 if ((tx_ant == BIT(adapter->number_of_antenna) - 1) &&
888 (priv->adapter->number_of_antenna > 1)) {
889 tx_ant = RF_ANTENNA_AUTO;
890 rx_ant = RF_ANTENNA_AUTO;
891 }
892 }
893
894 ant_cfg.tx_ant = tx_ant;
895 ant_cfg.rx_ant = rx_ant;
896
897 return mwifiex_send_cmd_sync(priv, HostCmd_CMD_RF_ANTENNA,
898 HostCmd_ACT_GEN_SET, 0, &ant_cfg);
899}
900
Avinash Patil12190c52012-05-08 18:30:24 -0700901/* cfg80211 operation handler for stop ap.
902 * Function stops BSS running at uAP interface.
903 */
904static int mwifiex_cfg80211_stop_ap(struct wiphy *wiphy, struct net_device *dev)
905{
906 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
907
Avinash Patil40bbc212012-05-08 18:30:30 -0700908 if (mwifiex_del_mgmt_ies(priv))
909 wiphy_err(wiphy, "Failed to delete mgmt IEs!\n");
910
Avinash Patilc8258912012-08-03 18:06:05 -0700911 priv->ap_11n_enabled = 0;
912
Avinash Patil12190c52012-05-08 18:30:24 -0700913 if (mwifiex_send_cmd_sync(priv, HostCmd_CMD_UAP_BSS_STOP,
914 HostCmd_ACT_GEN_SET, 0, NULL)) {
915 wiphy_err(wiphy, "Failed to stop the BSS\n");
916 return -1;
917 }
918
919 return 0;
920}
921
922/* cfg80211 operation handler for start_ap.
923 * Function sets beacon period, DTIM period, SSID and security into
924 * AP config structure.
925 * AP is configured with these settings and BSS is started.
926 */
927static int mwifiex_cfg80211_start_ap(struct wiphy *wiphy,
928 struct net_device *dev,
929 struct cfg80211_ap_settings *params)
930{
931 struct mwifiex_uap_bss_param *bss_cfg;
932 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
Amitkumar Karwar05910f42012-07-13 20:09:32 -0700933 u8 config_bands = 0;
Avinash Patil12190c52012-05-08 18:30:24 -0700934
Avinash Patilf752dcd2012-05-08 18:30:26 -0700935 if (priv->bss_type != MWIFIEX_BSS_TYPE_UAP)
936 return -1;
Avinash Patiladb6ed02012-06-28 20:30:25 -0700937 if (mwifiex_set_mgmt_ies(priv, &params->beacon))
Avinash Patilf31acab2012-05-08 18:30:29 -0700938 return -1;
Avinash Patilf752dcd2012-05-08 18:30:26 -0700939
Avinash Patil12190c52012-05-08 18:30:24 -0700940 bss_cfg = kzalloc(sizeof(struct mwifiex_uap_bss_param), GFP_KERNEL);
941 if (!bss_cfg)
942 return -ENOMEM;
943
944 mwifiex_set_sys_config_invalid_data(bss_cfg);
945
946 if (params->beacon_interval)
947 bss_cfg->beacon_period = params->beacon_interval;
948 if (params->dtim_period)
949 bss_cfg->dtim_period = params->dtim_period;
950
951 if (params->ssid && params->ssid_len) {
952 memcpy(bss_cfg->ssid.ssid, params->ssid, params->ssid_len);
953 bss_cfg->ssid.ssid_len = params->ssid_len;
954 }
955
Avinash Patil7a1c9932012-05-29 15:39:05 -0700956 switch (params->hidden_ssid) {
957 case NL80211_HIDDEN_SSID_NOT_IN_USE:
958 bss_cfg->bcast_ssid_ctl = 1;
959 break;
960 case NL80211_HIDDEN_SSID_ZERO_LEN:
961 bss_cfg->bcast_ssid_ctl = 0;
962 break;
963 case NL80211_HIDDEN_SSID_ZERO_CONTENTS:
964 /* firmware doesn't support this type of hidden SSID */
965 default:
Bing Zhaob3190462012-07-03 15:53:13 -0700966 kfree(bss_cfg);
Avinash Patil7a1c9932012-05-29 15:39:05 -0700967 return -EINVAL;
968 }
969
Avinash Patil0abd79e2012-06-15 12:21:51 -0700970 bss_cfg->channel =
971 (u8)ieee80211_frequency_to_channel(params->channel->center_freq);
Avinash Patil0abd79e2012-06-15 12:21:51 -0700972
Amitkumar Karwar05910f42012-07-13 20:09:32 -0700973 /* Set appropriate bands */
974 if (params->channel->band == IEEE80211_BAND_2GHZ) {
Avinash Patila3c2c4f2012-08-27 20:32:53 -0700975 bss_cfg->band_cfg = BAND_CONFIG_BG;
976
Amitkumar Karwar05910f42012-07-13 20:09:32 -0700977 if (params->channel_type == NL80211_CHAN_NO_HT)
978 config_bands = BAND_B | BAND_G;
979 else
980 config_bands = BAND_B | BAND_G | BAND_GN;
981 } else {
Avinash Patila3c2c4f2012-08-27 20:32:53 -0700982 bss_cfg->band_cfg = BAND_CONFIG_A;
983
Amitkumar Karwar05910f42012-07-13 20:09:32 -0700984 if (params->channel_type == NL80211_CHAN_NO_HT)
985 config_bands = BAND_A;
986 else
987 config_bands = BAND_AN | BAND_A;
Avinash Patil0abd79e2012-06-15 12:21:51 -0700988 }
989
Amitkumar Karwar05910f42012-07-13 20:09:32 -0700990 if (!((config_bands | priv->adapter->fw_bands) &
991 ~priv->adapter->fw_bands))
992 priv->adapter->config_bands = config_bands;
993
Avinash Patila3c2c4f2012-08-27 20:32:53 -0700994 mwifiex_set_uap_rates(bss_cfg, params);
Amitkumar Karwar05910f42012-07-13 20:09:32 -0700995 mwifiex_send_domain_info_cmd_fw(wiphy);
996
Avinash Patilf752dcd2012-05-08 18:30:26 -0700997 if (mwifiex_set_secure_params(priv, bss_cfg, params)) {
998 kfree(bss_cfg);
999 wiphy_err(wiphy, "Failed to parse secuirty parameters!\n");
1000 return -1;
1001 }
1002
Avinash Patil22281252012-06-15 12:21:53 -07001003 mwifiex_set_ht_params(priv, bss_cfg, params);
1004
Avinash Patil12190c52012-05-08 18:30:24 -07001005 if (mwifiex_send_cmd_sync(priv, HostCmd_CMD_UAP_BSS_STOP,
1006 HostCmd_ACT_GEN_SET, 0, NULL)) {
1007 wiphy_err(wiphy, "Failed to stop the BSS\n");
1008 kfree(bss_cfg);
1009 return -1;
1010 }
1011
1012 if (mwifiex_send_cmd_async(priv, HostCmd_CMD_UAP_SYS_CONFIG,
Avinash Patile76268d2012-05-08 18:30:27 -07001013 HostCmd_ACT_GEN_SET,
1014 UAP_BSS_PARAMS_I, bss_cfg)) {
Avinash Patil12190c52012-05-08 18:30:24 -07001015 wiphy_err(wiphy, "Failed to set the SSID\n");
1016 kfree(bss_cfg);
1017 return -1;
1018 }
1019
1020 kfree(bss_cfg);
1021
1022 if (mwifiex_send_cmd_async(priv, HostCmd_CMD_UAP_BSS_START,
1023 HostCmd_ACT_GEN_SET, 0, NULL)) {
1024 wiphy_err(wiphy, "Failed to start the BSS\n");
1025 return -1;
1026 }
1027
Avinash Patil96893532012-06-15 12:21:55 -07001028 if (priv->sec_info.wep_enabled)
1029 priv->curr_pkt_filter |= HostCmd_ACT_MAC_WEP_ENABLE;
1030 else
1031 priv->curr_pkt_filter &= ~HostCmd_ACT_MAC_WEP_ENABLE;
1032
1033 if (mwifiex_send_cmd_sync(priv, HostCmd_CMD_MAC_CONTROL,
1034 HostCmd_ACT_GEN_SET, 0,
1035 &priv->curr_pkt_filter))
1036 return -1;
1037
Avinash Patil12190c52012-05-08 18:30:24 -07001038 return 0;
1039}
1040
Amitkumar Karwarfa444bf2012-03-15 20:51:51 -07001041/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001042 * CFG802.11 operation handler for disconnection request.
1043 *
1044 * This function does not work when there is already a disconnection
1045 * procedure going on.
1046 */
1047static int
1048mwifiex_cfg80211_disconnect(struct wiphy *wiphy, struct net_device *dev,
1049 u16 reason_code)
1050{
1051 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
1052
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001053 if (mwifiex_deauthenticate(priv, NULL))
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001054 return -EFAULT;
1055
1056 wiphy_dbg(wiphy, "info: successfully disconnected from %pM:"
1057 " reason code %d\n", priv->cfg_bssid, reason_code);
1058
Amitkumar Karwar38c9d662011-12-13 20:43:17 -08001059 memset(priv->cfg_bssid, 0, ETH_ALEN);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001060
1061 return 0;
1062}
1063
1064/*
1065 * This function informs the CFG802.11 subsystem of a new IBSS.
1066 *
1067 * The following information are sent to the CFG802.11 subsystem
1068 * to register the new IBSS. If we do not register the new IBSS,
1069 * a kernel panic will result.
1070 * - SSID
1071 * - SSID length
1072 * - BSSID
1073 * - Channel
1074 */
1075static int mwifiex_cfg80211_inform_ibss_bss(struct mwifiex_private *priv)
1076{
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001077 struct ieee80211_channel *chan;
1078 struct mwifiex_bss_info bss_info;
Amitkumar Karwaraa95a482011-11-07 21:41:12 -08001079 struct cfg80211_bss *bss;
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -07001080 int ie_len;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001081 u8 ie_buf[IEEE80211_MAX_SSID_LEN + sizeof(struct ieee_types_header)];
Amitkumar Karwar4ed5d522011-09-21 21:43:24 -07001082 enum ieee80211_band band;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001083
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001084 if (mwifiex_get_bss_info(priv, &bss_info))
1085 return -1;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001086
1087 ie_buf[0] = WLAN_EID_SSID;
1088 ie_buf[1] = bss_info.ssid.ssid_len;
1089
1090 memcpy(&ie_buf[sizeof(struct ieee_types_header)],
Yogesh Ashok Powaraea07012012-03-13 19:22:35 -07001091 &bss_info.ssid.ssid, bss_info.ssid.ssid_len);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001092 ie_len = ie_buf[1] + sizeof(struct ieee_types_header);
1093
Amitkumar Karwar4ed5d522011-09-21 21:43:24 -07001094 band = mwifiex_band_to_radio_type(priv->curr_bss_params.band);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001095 chan = __ieee80211_get_channel(priv->wdev->wiphy,
1096 ieee80211_channel_to_frequency(bss_info.bss_chan,
Amitkumar Karwar4ed5d522011-09-21 21:43:24 -07001097 band));
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001098
Amitkumar Karwaraa95a482011-11-07 21:41:12 -08001099 bss = cfg80211_inform_bss(priv->wdev->wiphy, chan,
Yogesh Ashok Powaraea07012012-03-13 19:22:35 -07001100 bss_info.bssid, 0, WLAN_CAPABILITY_IBSS,
1101 0, ie_buf, ie_len, 0, GFP_KERNEL);
Amitkumar Karwaraa95a482011-11-07 21:41:12 -08001102 cfg80211_put_bss(bss);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001103 memcpy(priv->cfg_bssid, bss_info.bssid, ETH_ALEN);
1104
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001105 return 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001106}
1107
1108/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001109 * This function connects with a BSS.
1110 *
1111 * This function handles both Infra and Ad-Hoc modes. It also performs
1112 * validity checking on the provided parameters, disconnects from the
1113 * current BSS (if any), sets up the association/scan parameters,
1114 * including security settings, and performs specific SSID scan before
1115 * trying to connect.
1116 *
1117 * For Infra mode, the function returns failure if the specified SSID
1118 * is not found in scan table. However, for Ad-Hoc mode, it can create
1119 * the IBSS if it does not exist. On successful completion in either case,
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001120 * the function notifies the CFG802.11 subsystem of the new BSS connection.
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001121 */
1122static int
1123mwifiex_cfg80211_assoc(struct mwifiex_private *priv, size_t ssid_len, u8 *ssid,
1124 u8 *bssid, int mode, struct ieee80211_channel *channel,
1125 struct cfg80211_connect_params *sme, bool privacy)
1126{
Amitkumar Karwarb9be5f32012-02-27 22:04:14 -08001127 struct cfg80211_ssid req_ssid;
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -07001128 int ret, auth_type = 0;
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001129 struct cfg80211_bss *bss = NULL;
Amitkumar Karwar05910f42012-07-13 20:09:32 -07001130 u8 is_scanning_required = 0, config_bands = 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001131
Amitkumar Karwarb9be5f32012-02-27 22:04:14 -08001132 memset(&req_ssid, 0, sizeof(struct cfg80211_ssid));
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001133
1134 req_ssid.ssid_len = ssid_len;
1135 if (ssid_len > IEEE80211_MAX_SSID_LEN) {
1136 dev_err(priv->adapter->dev, "invalid SSID - aborting\n");
1137 return -EINVAL;
1138 }
1139
1140 memcpy(req_ssid.ssid, ssid, ssid_len);
1141 if (!req_ssid.ssid_len || req_ssid.ssid[0] < 0x20) {
1142 dev_err(priv->adapter->dev, "invalid SSID - aborting\n");
1143 return -EINVAL;
1144 }
1145
1146 /* disconnect before try to associate */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001147 mwifiex_deauthenticate(priv, NULL);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001148
Amitkumar Karwar05910f42012-07-13 20:09:32 -07001149 if (channel) {
1150 if (mode == NL80211_IFTYPE_STATION) {
1151 if (channel->band == IEEE80211_BAND_2GHZ)
1152 config_bands = BAND_B | BAND_G | BAND_GN;
1153 else
1154 config_bands = BAND_A | BAND_AN;
1155
1156 if (!((config_bands | priv->adapter->fw_bands) &
1157 ~priv->adapter->fw_bands))
1158 priv->adapter->config_bands = config_bands;
1159 }
1160 mwifiex_send_domain_info_cmd_fw(priv->wdev->wiphy);
1161 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001162
Amitkumar Karwar6670f152012-02-09 18:32:22 -08001163 /* As this is new association, clear locally stored
1164 * keys and security related flags */
1165 priv->sec_info.wpa_enabled = false;
1166 priv->sec_info.wpa2_enabled = false;
1167 priv->wep_key_curr_index = 0;
Amitkumar Karwar00f157b2012-02-24 21:35:35 -08001168 priv->sec_info.encryption_mode = 0;
Amitkumar Karwara0f6d6c2012-02-24 21:36:05 -08001169 priv->sec_info.is_authtype_auto = 0;
Ying Luo53b11232012-08-03 18:06:13 -07001170 ret = mwifiex_set_encode(priv, NULL, NULL, 0, 0, NULL, 1);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001171
Bing Zhaoeecd8252011-03-28 17:55:41 -07001172 if (mode == NL80211_IFTYPE_ADHOC) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001173 /* "privacy" is set only for ad-hoc mode */
1174 if (privacy) {
1175 /*
Yogesh Ashok Powar2be50b82011-04-01 18:36:47 -07001176 * Keep WLAN_CIPHER_SUITE_WEP104 for now so that
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001177 * the firmware can find a matching network from the
1178 * scan. The cfg80211 does not give us the encryption
1179 * mode at this stage so just setting it to WEP here.
1180 */
Marc Yang203afec2011-03-24 20:49:39 -07001181 priv->sec_info.encryption_mode =
Yogesh Ashok Powar2be50b82011-04-01 18:36:47 -07001182 WLAN_CIPHER_SUITE_WEP104;
Marc Yang203afec2011-03-24 20:49:39 -07001183 priv->sec_info.authentication_mode =
Marc Yangf986b6d2011-03-28 17:55:42 -07001184 NL80211_AUTHTYPE_OPEN_SYSTEM;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001185 }
1186
1187 goto done;
1188 }
1189
1190 /* Now handle infra mode. "sme" is valid for infra mode only */
Amitkumar Karwara0f6d6c2012-02-24 21:36:05 -08001191 if (sme->auth_type == NL80211_AUTHTYPE_AUTOMATIC) {
Marc Yangf986b6d2011-03-28 17:55:42 -07001192 auth_type = NL80211_AUTHTYPE_OPEN_SYSTEM;
Amitkumar Karwara0f6d6c2012-02-24 21:36:05 -08001193 priv->sec_info.is_authtype_auto = 1;
1194 } else {
1195 auth_type = sme->auth_type;
1196 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001197
1198 if (sme->crypto.n_ciphers_pairwise) {
Yogesh Ashok Powar2be50b82011-04-01 18:36:47 -07001199 priv->sec_info.encryption_mode =
1200 sme->crypto.ciphers_pairwise[0];
Marc Yang203afec2011-03-24 20:49:39 -07001201 priv->sec_info.authentication_mode = auth_type;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001202 }
1203
1204 if (sme->crypto.cipher_group) {
Yogesh Ashok Powar2be50b82011-04-01 18:36:47 -07001205 priv->sec_info.encryption_mode = sme->crypto.cipher_group;
Marc Yang203afec2011-03-24 20:49:39 -07001206 priv->sec_info.authentication_mode = auth_type;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001207 }
1208 if (sme->ie)
1209 ret = mwifiex_set_gen_ie(priv, sme->ie, sme->ie_len);
1210
1211 if (sme->key) {
Amitkumar Karware6faada2011-07-07 17:33:19 -07001212 if (mwifiex_is_alg_wep(priv->sec_info.encryption_mode)) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001213 dev_dbg(priv->adapter->dev,
1214 "info: setting wep encryption"
1215 " with key len %d\n", sme->key_len);
Amitkumar Karwar6670f152012-02-09 18:32:22 -08001216 priv->wep_key_curr_index = sme->key_idx;
Ying Luo53b11232012-08-03 18:06:13 -07001217 ret = mwifiex_set_encode(priv, NULL, sme->key,
1218 sme->key_len, sme->key_idx,
1219 NULL, 0);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001220 }
1221 }
1222done:
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001223 /*
1224 * Scan entries are valid for some time (15 sec). So we can save one
1225 * active scan time if we just try cfg80211_get_bss first. If it fails
1226 * then request scan and cfg80211_get_bss() again for final output.
1227 */
1228 while (1) {
1229 if (is_scanning_required) {
1230 /* Do specific SSID scanning */
1231 if (mwifiex_request_scan(priv, &req_ssid)) {
1232 dev_err(priv->adapter->dev, "scan error\n");
1233 return -EFAULT;
1234 }
1235 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001236
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001237 /* Find the BSS we want using available scan results */
1238 if (mode == NL80211_IFTYPE_ADHOC)
1239 bss = cfg80211_get_bss(priv->wdev->wiphy, channel,
1240 bssid, ssid, ssid_len,
1241 WLAN_CAPABILITY_IBSS,
1242 WLAN_CAPABILITY_IBSS);
1243 else
1244 bss = cfg80211_get_bss(priv->wdev->wiphy, channel,
1245 bssid, ssid, ssid_len,
1246 WLAN_CAPABILITY_ESS,
1247 WLAN_CAPABILITY_ESS);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001248
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001249 if (!bss) {
1250 if (is_scanning_required) {
Yogesh Ashok Powaraea07012012-03-13 19:22:35 -07001251 dev_warn(priv->adapter->dev,
1252 "assoc: requested bss not found in scan results\n");
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001253 break;
1254 }
1255 is_scanning_required = 1;
1256 } else {
Yogesh Ashok Powaraea07012012-03-13 19:22:35 -07001257 dev_dbg(priv->adapter->dev,
1258 "info: trying to associate to '%s' bssid %pM\n",
1259 (char *) req_ssid.ssid, bss->bssid);
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001260 memcpy(&priv->cfg_bssid, bss->bssid, ETH_ALEN);
1261 break;
1262 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001263 }
1264
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001265 if (mwifiex_bss_start(priv, bss, &req_ssid))
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001266 return -EFAULT;
1267
Bing Zhaoeecd8252011-03-28 17:55:41 -07001268 if (mode == NL80211_IFTYPE_ADHOC) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001269 /* Inform the BSS information to kernel, otherwise
1270 * kernel will give a panic after successful assoc */
1271 if (mwifiex_cfg80211_inform_ibss_bss(priv))
1272 return -EFAULT;
1273 }
1274
1275 return ret;
1276}
1277
1278/*
1279 * CFG802.11 operation handler for association request.
1280 *
1281 * This function does not work when the current mode is set to Ad-Hoc, or
1282 * when there is already an association procedure going on. The given BSS
1283 * information is used to associate.
1284 */
1285static int
1286mwifiex_cfg80211_connect(struct wiphy *wiphy, struct net_device *dev,
1287 struct cfg80211_connect_params *sme)
1288{
1289 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
1290 int ret = 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001291
Bing Zhaoeecd8252011-03-28 17:55:41 -07001292 if (priv->bss_mode == NL80211_IFTYPE_ADHOC) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001293 wiphy_err(wiphy, "received infra assoc request "
1294 "when station is in ibss mode\n");
1295 goto done;
1296 }
1297
Avinash Patile5686342012-05-08 18:30:25 -07001298 if (priv->bss_mode == NL80211_IFTYPE_AP) {
1299 wiphy_err(wiphy, "skip association request for AP interface\n");
1300 goto done;
1301 }
1302
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001303 wiphy_dbg(wiphy, "info: Trying to associate to %s and bssid %pM\n",
Yogesh Ashok Powaraea07012012-03-13 19:22:35 -07001304 (char *) sme->ssid, sme->bssid);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001305
1306 ret = mwifiex_cfg80211_assoc(priv, sme->ssid_len, sme->ssid, sme->bssid,
Bing Zhaoeecd8252011-03-28 17:55:41 -07001307 priv->bss_mode, sme->channel, sme, 0);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001308done:
Amitkumar Karwar38c9d662011-12-13 20:43:17 -08001309 if (!ret) {
1310 cfg80211_connect_result(priv->netdev, priv->cfg_bssid, NULL, 0,
1311 NULL, 0, WLAN_STATUS_SUCCESS,
1312 GFP_KERNEL);
1313 dev_dbg(priv->adapter->dev,
1314 "info: associated to bssid %pM successfully\n",
1315 priv->cfg_bssid);
1316 } else {
1317 dev_dbg(priv->adapter->dev,
1318 "info: association to bssid %pM failed\n",
1319 priv->cfg_bssid);
1320 memset(priv->cfg_bssid, 0, ETH_ALEN);
1321 }
1322
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001323 return ret;
1324}
1325
1326/*
Amitkumar Karwar05910f42012-07-13 20:09:32 -07001327 * This function sets following parameters for ibss network.
1328 * - channel
1329 * - start band
1330 * - 11n flag
1331 * - secondary channel offset
1332 */
1333static int mwifiex_set_ibss_params(struct mwifiex_private *priv,
1334 struct cfg80211_ibss_params *params)
1335{
1336 struct wiphy *wiphy = priv->wdev->wiphy;
1337 struct mwifiex_adapter *adapter = priv->adapter;
1338 int index = 0, i;
1339 u8 config_bands = 0;
1340
1341 if (params->channel->band == IEEE80211_BAND_2GHZ) {
1342 if (!params->basic_rates) {
1343 config_bands = BAND_B | BAND_G;
1344 } else {
1345 for (i = 0; i < mwifiex_band_2ghz.n_bitrates; i++) {
1346 /*
1347 * Rates below 6 Mbps in the table are CCK
1348 * rates; 802.11b and from 6 they are OFDM;
1349 * 802.11G
1350 */
1351 if (mwifiex_rates[i].bitrate == 60) {
1352 index = 1 << i;
1353 break;
1354 }
1355 }
1356
1357 if (params->basic_rates < index) {
1358 config_bands = BAND_B;
1359 } else {
1360 config_bands = BAND_G;
1361 if (params->basic_rates % index)
1362 config_bands |= BAND_B;
1363 }
1364 }
1365
1366 if (params->channel_type != NL80211_CHAN_NO_HT)
1367 config_bands |= BAND_GN;
1368 } else {
1369 if (params->channel_type == NL80211_CHAN_NO_HT)
1370 config_bands = BAND_A;
1371 else
1372 config_bands = BAND_AN | BAND_A;
1373 }
1374
1375 if (!((config_bands | adapter->fw_bands) & ~adapter->fw_bands)) {
1376 adapter->config_bands = config_bands;
1377 adapter->adhoc_start_band = config_bands;
1378
1379 if ((config_bands & BAND_GN) || (config_bands & BAND_AN))
1380 adapter->adhoc_11n_enabled = true;
1381 else
1382 adapter->adhoc_11n_enabled = false;
1383 }
1384
1385 adapter->sec_chan_offset =
1386 mwifiex_chan_type_to_sec_chan_offset(params->channel_type);
1387 priv->adhoc_channel =
1388 ieee80211_frequency_to_channel(params->channel->center_freq);
1389
1390 wiphy_dbg(wiphy, "info: set ibss band %d, chan %d, chan offset %d\n",
1391 config_bands, priv->adhoc_channel, adapter->sec_chan_offset);
1392
1393 return 0;
1394}
1395
1396/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001397 * CFG802.11 operation handler to join an IBSS.
1398 *
1399 * This function does not work in any mode other than Ad-Hoc, or if
1400 * a join operation is already in progress.
1401 */
1402static int
1403mwifiex_cfg80211_join_ibss(struct wiphy *wiphy, struct net_device *dev,
1404 struct cfg80211_ibss_params *params)
1405{
Yogesh Ashok Powarf540f9f2012-01-11 20:06:12 -08001406 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001407 int ret = 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001408
Bing Zhaoeecd8252011-03-28 17:55:41 -07001409 if (priv->bss_mode != NL80211_IFTYPE_ADHOC) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001410 wiphy_err(wiphy, "request to join ibss received "
1411 "when station is not in ibss mode\n");
1412 goto done;
1413 }
1414
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001415 wiphy_dbg(wiphy, "info: trying to join to %s and bssid %pM\n",
Yogesh Ashok Powaraea07012012-03-13 19:22:35 -07001416 (char *) params->ssid, params->bssid);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001417
Amitkumar Karwar05910f42012-07-13 20:09:32 -07001418 mwifiex_set_ibss_params(priv, params);
1419
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001420 ret = mwifiex_cfg80211_assoc(priv, params->ssid_len, params->ssid,
Yogesh Ashok Powaraea07012012-03-13 19:22:35 -07001421 params->bssid, priv->bss_mode,
1422 params->channel, NULL, params->privacy);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001423done:
Amitkumar Karwar38c9d662011-12-13 20:43:17 -08001424 if (!ret) {
1425 cfg80211_ibss_joined(priv->netdev, priv->cfg_bssid, GFP_KERNEL);
1426 dev_dbg(priv->adapter->dev,
1427 "info: joined/created adhoc network with bssid"
1428 " %pM successfully\n", priv->cfg_bssid);
1429 } else {
1430 dev_dbg(priv->adapter->dev,
1431 "info: failed creating/joining adhoc network\n");
1432 }
1433
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001434 return ret;
1435}
1436
1437/*
1438 * CFG802.11 operation handler to leave an IBSS.
1439 *
1440 * This function does not work if a leave operation is
1441 * already in progress.
1442 */
1443static int
1444mwifiex_cfg80211_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
1445{
Yogesh Ashok Powarf540f9f2012-01-11 20:06:12 -08001446 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001447
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001448 wiphy_dbg(wiphy, "info: disconnecting from essid %pM\n",
Yogesh Ashok Powaraea07012012-03-13 19:22:35 -07001449 priv->cfg_bssid);
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001450 if (mwifiex_deauthenticate(priv, NULL))
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001451 return -EFAULT;
1452
Amitkumar Karwar38c9d662011-12-13 20:43:17 -08001453 memset(priv->cfg_bssid, 0, ETH_ALEN);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001454
1455 return 0;
1456}
1457
1458/*
1459 * CFG802.11 operation handler for scan request.
1460 *
1461 * This function issues a scan request to the firmware based upon
1462 * the user specified scan configuration. On successfull completion,
1463 * it also informs the results.
1464 */
1465static int
Johannes Bergfd014282012-06-18 19:17:03 +02001466mwifiex_cfg80211_scan(struct wiphy *wiphy,
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001467 struct cfg80211_scan_request *request)
1468{
Johannes Bergfd014282012-06-18 19:17:03 +02001469 struct net_device *dev = request->wdev->netdev;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001470 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
Amitkumar Karwar38c9d662011-12-13 20:43:17 -08001471 int i;
1472 struct ieee80211_channel *chan;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001473
1474 wiphy_dbg(wiphy, "info: received scan request on %s\n", dev->name);
1475
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001476 priv->scan_request = request;
1477
Amitkumar Karwar38c9d662011-12-13 20:43:17 -08001478 priv->user_scan_cfg = kzalloc(sizeof(struct mwifiex_user_scan_cfg),
Yogesh Ashok Powaraea07012012-03-13 19:22:35 -07001479 GFP_KERNEL);
Amitkumar Karwar38c9d662011-12-13 20:43:17 -08001480 if (!priv->user_scan_cfg) {
1481 dev_err(priv->adapter->dev, "failed to alloc scan_req\n");
1482 return -ENOMEM;
1483 }
Amitkumar Karwarbe0b2812012-02-27 22:04:15 -08001484
1485 priv->user_scan_cfg->num_ssids = request->n_ssids;
1486 priv->user_scan_cfg->ssid_list = request->ssids;
1487
Avinash Patil13d7ba782012-04-09 20:06:56 -07001488 if (request->ie && request->ie_len) {
1489 for (i = 0; i < MWIFIEX_MAX_VSIE_NUM; i++) {
1490 if (priv->vs_ie[i].mask != MWIFIEX_VSIE_MASK_CLEAR)
1491 continue;
1492 priv->vs_ie[i].mask = MWIFIEX_VSIE_MASK_SCAN;
1493 memcpy(&priv->vs_ie[i].ie, request->ie,
1494 request->ie_len);
1495 break;
1496 }
1497 }
1498
Amitkumar Karwar38c9d662011-12-13 20:43:17 -08001499 for (i = 0; i < request->n_channels; i++) {
1500 chan = request->channels[i];
1501 priv->user_scan_cfg->chan_list[i].chan_number = chan->hw_value;
1502 priv->user_scan_cfg->chan_list[i].radio_type = chan->band;
1503
1504 if (chan->flags & IEEE80211_CHAN_PASSIVE_SCAN)
1505 priv->user_scan_cfg->chan_list[i].scan_type =
Yogesh Ashok Powaraea07012012-03-13 19:22:35 -07001506 MWIFIEX_SCAN_TYPE_PASSIVE;
Amitkumar Karwar38c9d662011-12-13 20:43:17 -08001507 else
1508 priv->user_scan_cfg->chan_list[i].scan_type =
Yogesh Ashok Powaraea07012012-03-13 19:22:35 -07001509 MWIFIEX_SCAN_TYPE_ACTIVE;
Amitkumar Karwar38c9d662011-12-13 20:43:17 -08001510
1511 priv->user_scan_cfg->chan_list[i].scan_time = 0;
1512 }
Amitkumar Karwar1a1fb972012-06-27 19:57:56 -07001513 if (mwifiex_scan_networks(priv, priv->user_scan_cfg))
Amitkumar Karwar38c9d662011-12-13 20:43:17 -08001514 return -EFAULT;
1515
Avinash Patil13d7ba782012-04-09 20:06:56 -07001516 if (request->ie && request->ie_len) {
1517 for (i = 0; i < MWIFIEX_MAX_VSIE_NUM; i++) {
1518 if (priv->vs_ie[i].mask == MWIFIEX_VSIE_MASK_SCAN) {
1519 priv->vs_ie[i].mask = MWIFIEX_VSIE_MASK_CLEAR;
1520 memset(&priv->vs_ie[i].ie, 0,
1521 MWIFIEX_MAX_VSIE_LEN);
1522 }
1523 }
1524 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001525 return 0;
1526}
1527
1528/*
1529 * This function sets up the CFG802.11 specific HT capability fields
1530 * with default values.
1531 *
1532 * The following default values are set -
1533 * - HT Supported = True
Amitkumar Karwara46b7b52011-04-27 19:13:12 -07001534 * - Maximum AMPDU length factor = IEEE80211_HT_MAX_AMPDU_64K
1535 * - Minimum AMPDU spacing = IEEE80211_HT_MPDU_DENSITY_NONE
1536 * - HT Capabilities supported by firmware
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001537 * - MCS information, Rx mask = 0xff
1538 * - MCD information, Tx parameters = IEEE80211_HT_MCS_TX_DEFINED (0x01)
1539 */
1540static void
1541mwifiex_setup_ht_caps(struct ieee80211_sta_ht_cap *ht_info,
1542 struct mwifiex_private *priv)
1543{
1544 int rx_mcs_supp;
1545 struct ieee80211_mcs_info mcs_set;
1546 u8 *mcs = (u8 *)&mcs_set;
1547 struct mwifiex_adapter *adapter = priv->adapter;
1548
1549 ht_info->ht_supported = true;
Amitkumar Karwara46b7b52011-04-27 19:13:12 -07001550 ht_info->ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
1551 ht_info->ampdu_density = IEEE80211_HT_MPDU_DENSITY_NONE;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001552
1553 memset(&ht_info->mcs, 0, sizeof(ht_info->mcs));
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001554
Amitkumar Karwara46b7b52011-04-27 19:13:12 -07001555 /* Fill HT capability information */
1556 if (ISSUPP_CHANWIDTH40(adapter->hw_dot_11n_dev_cap))
1557 ht_info->cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
1558 else
1559 ht_info->cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
1560
1561 if (ISSUPP_SHORTGI20(adapter->hw_dot_11n_dev_cap))
1562 ht_info->cap |= IEEE80211_HT_CAP_SGI_20;
1563 else
1564 ht_info->cap &= ~IEEE80211_HT_CAP_SGI_20;
1565
1566 if (ISSUPP_SHORTGI40(adapter->hw_dot_11n_dev_cap))
1567 ht_info->cap |= IEEE80211_HT_CAP_SGI_40;
1568 else
1569 ht_info->cap &= ~IEEE80211_HT_CAP_SGI_40;
1570
1571 if (ISSUPP_RXSTBC(adapter->hw_dot_11n_dev_cap))
1572 ht_info->cap |= 1 << IEEE80211_HT_CAP_RX_STBC_SHIFT;
1573 else
1574 ht_info->cap &= ~(3 << IEEE80211_HT_CAP_RX_STBC_SHIFT);
1575
1576 if (ISSUPP_TXSTBC(adapter->hw_dot_11n_dev_cap))
1577 ht_info->cap |= IEEE80211_HT_CAP_TX_STBC;
1578 else
1579 ht_info->cap &= ~IEEE80211_HT_CAP_TX_STBC;
1580
1581 ht_info->cap &= ~IEEE80211_HT_CAP_MAX_AMSDU;
1582 ht_info->cap |= IEEE80211_HT_CAP_SM_PS;
1583
1584 rx_mcs_supp = GET_RXMCSSUPP(adapter->hw_dev_mcs_support);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001585 /* Set MCS for 1x1 */
1586 memset(mcs, 0xff, rx_mcs_supp);
1587 /* Clear all the other values */
1588 memset(&mcs[rx_mcs_supp], 0,
Yogesh Ashok Powaraea07012012-03-13 19:22:35 -07001589 sizeof(struct ieee80211_mcs_info) - rx_mcs_supp);
Bing Zhaoeecd8252011-03-28 17:55:41 -07001590 if (priv->bss_mode == NL80211_IFTYPE_STATION ||
Yogesh Ashok Powaraea07012012-03-13 19:22:35 -07001591 ISSUPP_CHANWIDTH40(adapter->hw_dot_11n_dev_cap))
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001592 /* Set MCS32 for infra mode or ad-hoc mode with 40MHz support */
1593 SETHT_MCS32(mcs_set.rx_mask);
1594
1595 memcpy((u8 *) &ht_info->mcs, mcs, sizeof(struct ieee80211_mcs_info));
1596
1597 ht_info->mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED;
1598}
1599
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -07001600/*
1601 * create a new virtual interface with the given name
1602 */
Johannes Berg84efbb82012-06-16 00:00:26 +02001603struct wireless_dev *mwifiex_add_virtual_intf(struct wiphy *wiphy,
1604 char *name,
1605 enum nl80211_iftype type,
1606 u32 *flags,
1607 struct vif_params *params)
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -07001608{
Avinash Patil67fdf392012-05-08 18:30:17 -07001609 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
1610 struct mwifiex_private *priv;
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -07001611 struct net_device *dev;
1612 void *mdev_priv;
Avinash Patild6bffe82012-05-08 18:30:15 -07001613 struct wireless_dev *wdev;
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -07001614
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -07001615 if (!adapter)
Bing Zhao858faa52012-06-15 15:49:54 -07001616 return ERR_PTR(-EFAULT);
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -07001617
1618 switch (type) {
1619 case NL80211_IFTYPE_UNSPECIFIED:
1620 case NL80211_IFTYPE_STATION:
1621 case NL80211_IFTYPE_ADHOC:
Avinash Patild6bffe82012-05-08 18:30:15 -07001622 priv = adapter->priv[MWIFIEX_BSS_TYPE_STA];
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -07001623 if (priv->bss_mode) {
Avinash Patild6bffe82012-05-08 18:30:15 -07001624 wiphy_err(wiphy,
1625 "cannot create multiple sta/adhoc ifaces\n");
Bing Zhao858faa52012-06-15 15:49:54 -07001626 return ERR_PTR(-EINVAL);
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -07001627 }
1628
Avinash Patild6bffe82012-05-08 18:30:15 -07001629 wdev = kzalloc(sizeof(struct wireless_dev), GFP_KERNEL);
1630 if (!wdev)
Bing Zhao858faa52012-06-15 15:49:54 -07001631 return ERR_PTR(-ENOMEM);
Avinash Patild6bffe82012-05-08 18:30:15 -07001632
1633 wdev->wiphy = wiphy;
1634 priv->wdev = wdev;
1635 wdev->iftype = NL80211_IFTYPE_STATION;
1636
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -07001637 if (type == NL80211_IFTYPE_UNSPECIFIED)
1638 priv->bss_mode = NL80211_IFTYPE_STATION;
1639 else
1640 priv->bss_mode = type;
1641
1642 priv->bss_type = MWIFIEX_BSS_TYPE_STA;
1643 priv->frame_type = MWIFIEX_DATA_FRAME_TYPE_ETH_II;
Avinash Patild6bffe82012-05-08 18:30:15 -07001644 priv->bss_priority = MWIFIEX_BSS_ROLE_STA;
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -07001645 priv->bss_role = MWIFIEX_BSS_ROLE_STA;
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -07001646 priv->bss_num = 0;
1647
1648 break;
Avinash Patild6bffe82012-05-08 18:30:15 -07001649 case NL80211_IFTYPE_AP:
1650 priv = adapter->priv[MWIFIEX_BSS_TYPE_UAP];
1651
1652 if (priv->bss_mode) {
1653 wiphy_err(wiphy, "Can't create multiple AP interfaces");
Bing Zhao858faa52012-06-15 15:49:54 -07001654 return ERR_PTR(-EINVAL);
Avinash Patild6bffe82012-05-08 18:30:15 -07001655 }
1656
1657 wdev = kzalloc(sizeof(struct wireless_dev), GFP_KERNEL);
1658 if (!wdev)
Bing Zhao858faa52012-06-15 15:49:54 -07001659 return ERR_PTR(-ENOMEM);
Avinash Patild6bffe82012-05-08 18:30:15 -07001660
1661 priv->wdev = wdev;
1662 wdev->wiphy = wiphy;
1663 wdev->iftype = NL80211_IFTYPE_AP;
1664
1665 priv->bss_type = MWIFIEX_BSS_TYPE_UAP;
1666 priv->frame_type = MWIFIEX_DATA_FRAME_TYPE_ETH_II;
1667 priv->bss_priority = MWIFIEX_BSS_ROLE_UAP;
1668 priv->bss_role = MWIFIEX_BSS_ROLE_UAP;
1669 priv->bss_started = 0;
1670 priv->bss_num = 0;
1671 priv->bss_mode = type;
1672
1673 break;
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -07001674 default:
1675 wiphy_err(wiphy, "type not supported\n");
Bing Zhao858faa52012-06-15 15:49:54 -07001676 return ERR_PTR(-EINVAL);
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -07001677 }
1678
1679 dev = alloc_netdev_mq(sizeof(struct mwifiex_private *), name,
1680 ether_setup, 1);
1681 if (!dev) {
1682 wiphy_err(wiphy, "no memory available for netdevice\n");
Bing Zhao858faa52012-06-15 15:49:54 -07001683 priv->bss_mode = NL80211_IFTYPE_UNSPECIFIED;
1684 return ERR_PTR(-ENOMEM);
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -07001685 }
1686
Avinash Patild6bffe82012-05-08 18:30:15 -07001687 mwifiex_init_priv_params(priv, dev);
1688 priv->netdev = dev;
1689
1690 mwifiex_setup_ht_caps(&wiphy->bands[IEEE80211_BAND_2GHZ]->ht_cap, priv);
1691
1692 if (adapter->config_bands & BAND_A)
1693 mwifiex_setup_ht_caps(
1694 &wiphy->bands[IEEE80211_BAND_5GHZ]->ht_cap, priv);
1695
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -07001696 dev_net_set(dev, wiphy_net(wiphy));
1697 dev->ieee80211_ptr = priv->wdev;
1698 dev->ieee80211_ptr->iftype = priv->bss_mode;
1699 memcpy(dev->dev_addr, wiphy->perm_addr, ETH_ALEN);
1700 memcpy(dev->perm_addr, wiphy->perm_addr, ETH_ALEN);
1701 SET_NETDEV_DEV(dev, wiphy_dev(wiphy));
1702
1703 dev->flags |= IFF_BROADCAST | IFF_MULTICAST;
1704 dev->watchdog_timeo = MWIFIEX_DEFAULT_WATCHDOG_TIMEOUT;
1705 dev->hard_header_len += MWIFIEX_MIN_DATA_HEADER_LEN;
1706
1707 mdev_priv = netdev_priv(dev);
1708 *((unsigned long *) mdev_priv) = (unsigned long) priv;
1709
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -07001710 SET_NETDEV_DEV(dev, adapter->dev);
1711
1712 /* Register network device */
1713 if (register_netdevice(dev)) {
1714 wiphy_err(wiphy, "cannot register virtual network device\n");
Bing Zhao858faa52012-06-15 15:49:54 -07001715 free_netdev(dev);
1716 priv->bss_mode = NL80211_IFTYPE_UNSPECIFIED;
1717 return ERR_PTR(-EFAULT);
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -07001718 }
1719
1720 sema_init(&priv->async_sem, 1);
1721 priv->scan_pending_on_block = false;
1722
1723 dev_dbg(adapter->dev, "info: %s: Marvell 802.11 Adapter\n", dev->name);
1724
1725#ifdef CONFIG_DEBUG_FS
1726 mwifiex_dev_debugfs_init(priv);
1727#endif
Johannes Berg84efbb82012-06-16 00:00:26 +02001728 return wdev;
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -07001729}
1730EXPORT_SYMBOL_GPL(mwifiex_add_virtual_intf);
1731
1732/*
1733 * del_virtual_intf: remove the virtual interface determined by dev
1734 */
Johannes Berg84efbb82012-06-16 00:00:26 +02001735int mwifiex_del_virtual_intf(struct wiphy *wiphy, struct wireless_dev *wdev)
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -07001736{
Johannes Berg84efbb82012-06-16 00:00:26 +02001737 struct mwifiex_private *priv = mwifiex_netdev_get_priv(wdev->netdev);
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -07001738
1739#ifdef CONFIG_DEBUG_FS
1740 mwifiex_dev_debugfs_remove(priv);
1741#endif
1742
1743 if (!netif_queue_stopped(priv->netdev))
1744 netif_stop_queue(priv->netdev);
1745
1746 if (netif_carrier_ok(priv->netdev))
1747 netif_carrier_off(priv->netdev);
1748
Johannes Berg84efbb82012-06-16 00:00:26 +02001749 if (wdev->netdev->reg_state == NETREG_REGISTERED)
1750 unregister_netdevice(wdev->netdev);
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -07001751
Johannes Berg84efbb82012-06-16 00:00:26 +02001752 if (wdev->netdev->reg_state == NETREG_UNREGISTERED)
1753 free_netdev(wdev->netdev);
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -07001754
1755 /* Clear the priv in adapter */
1756 priv->netdev = NULL;
1757
1758 priv->media_connected = false;
1759
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -07001760 priv->bss_mode = NL80211_IFTYPE_UNSPECIFIED;
1761
1762 return 0;
1763}
1764EXPORT_SYMBOL_GPL(mwifiex_del_virtual_intf);
1765
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001766/* station cfg80211 operations */
1767static struct cfg80211_ops mwifiex_cfg80211_ops = {
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -07001768 .add_virtual_intf = mwifiex_add_virtual_intf,
1769 .del_virtual_intf = mwifiex_del_virtual_intf,
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001770 .change_virtual_intf = mwifiex_cfg80211_change_virtual_intf,
1771 .scan = mwifiex_cfg80211_scan,
1772 .connect = mwifiex_cfg80211_connect,
1773 .disconnect = mwifiex_cfg80211_disconnect,
1774 .get_station = mwifiex_cfg80211_get_station,
Amitkumar Karwarf85aae62012-03-15 20:51:48 -07001775 .dump_station = mwifiex_cfg80211_dump_station,
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001776 .set_wiphy_params = mwifiex_cfg80211_set_wiphy_params,
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001777 .join_ibss = mwifiex_cfg80211_join_ibss,
1778 .leave_ibss = mwifiex_cfg80211_leave_ibss,
1779 .add_key = mwifiex_cfg80211_add_key,
1780 .del_key = mwifiex_cfg80211_del_key,
1781 .set_default_key = mwifiex_cfg80211_set_default_key,
1782 .set_power_mgmt = mwifiex_cfg80211_set_power_mgmt,
1783 .set_tx_power = mwifiex_cfg80211_set_tx_power,
Yogesh Ashok Powar5d82c532011-07-11 20:04:44 -07001784 .set_bitrate_mask = mwifiex_cfg80211_set_bitrate_mask,
Avinash Patil12190c52012-05-08 18:30:24 -07001785 .start_ap = mwifiex_cfg80211_start_ap,
1786 .stop_ap = mwifiex_cfg80211_stop_ap,
Avinash Patil5370c832012-06-28 20:30:28 -07001787 .change_beacon = mwifiex_cfg80211_change_beacon,
Amitkumar Karwarfa444bf2012-03-15 20:51:51 -07001788 .set_cqm_rssi_config = mwifiex_cfg80211_set_cqm_rssi_config,
Amitkumar Karwar8a279d52012-07-02 19:32:33 -07001789 .set_antenna = mwifiex_cfg80211_set_antenna,
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001790};
1791
1792/*
1793 * This function registers the device with CFG802.11 subsystem.
1794 *
1795 * The function creates the wireless device/wiphy, populates it with
1796 * default parameters and handler function pointers, and finally
1797 * registers the device.
1798 */
Avinash Patild6bffe82012-05-08 18:30:15 -07001799
1800int mwifiex_register_cfg80211(struct mwifiex_adapter *adapter)
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001801{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -07001802 int ret;
1803 void *wdev_priv;
Avinash Patild6bffe82012-05-08 18:30:15 -07001804 struct wiphy *wiphy;
1805 struct mwifiex_private *priv = adapter->priv[MWIFIEX_BSS_TYPE_STA];
Amitkumar Karwar9e04a7c2012-04-09 20:06:54 -07001806 u8 *country_code;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001807
Avinash Patild6bffe82012-05-08 18:30:15 -07001808 /* create a new wiphy for use with cfg80211 */
1809 wiphy = wiphy_new(&mwifiex_cfg80211_ops,
1810 sizeof(struct mwifiex_adapter *));
1811 if (!wiphy) {
1812 dev_err(adapter->dev, "%s: creating new wiphy\n", __func__);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001813 return -ENOMEM;
1814 }
Avinash Patild6bffe82012-05-08 18:30:15 -07001815 wiphy->max_scan_ssids = MWIFIEX_MAX_SSID_LIST_LENGTH;
1816 wiphy->max_scan_ie_len = MWIFIEX_MAX_VSIE_LEN;
1817 wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
1818 BIT(NL80211_IFTYPE_ADHOC) |
1819 BIT(NL80211_IFTYPE_AP);
Amitkumar Karwaradc89592011-04-27 19:13:11 -07001820
Avinash Patild6bffe82012-05-08 18:30:15 -07001821 wiphy->bands[IEEE80211_BAND_2GHZ] = &mwifiex_band_2ghz;
1822 if (adapter->config_bands & BAND_A)
1823 wiphy->bands[IEEE80211_BAND_5GHZ] = &mwifiex_band_5ghz;
1824 else
1825 wiphy->bands[IEEE80211_BAND_5GHZ] = NULL;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001826
Avinash Patilcd8440d2012-05-08 18:30:16 -07001827 wiphy->iface_combinations = &mwifiex_iface_comb_ap_sta;
1828 wiphy->n_iface_combinations = 1;
1829
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001830 /* Initialize cipher suits */
Avinash Patild6bffe82012-05-08 18:30:15 -07001831 wiphy->cipher_suites = mwifiex_cipher_suites;
1832 wiphy->n_cipher_suites = ARRAY_SIZE(mwifiex_cipher_suites);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001833
Avinash Patild6bffe82012-05-08 18:30:15 -07001834 memcpy(wiphy->perm_addr, priv->curr_addr, ETH_ALEN);
1835 wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
Avinash Patil2dd2bd62012-06-28 20:30:29 -07001836 wiphy->flags |= WIPHY_FLAG_HAVE_AP_SME |
1837 WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD;
1838
1839 wiphy->probe_resp_offload = NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS |
1840 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001841
Amitkumar Karwar8a279d52012-07-02 19:32:33 -07001842 wiphy->available_antennas_tx = BIT(adapter->number_of_antenna) - 1;
1843 wiphy->available_antennas_rx = BIT(adapter->number_of_antenna) - 1;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001844
Amitkumar Karwar05910f42012-07-13 20:09:32 -07001845 wiphy->features = NL80211_FEATURE_HT_IBSS;
1846
Amitkumar Karwarb5abcf02012-04-16 21:36:52 -07001847 /* Reserve space for mwifiex specific private data for BSS */
Avinash Patild6bffe82012-05-08 18:30:15 -07001848 wiphy->bss_priv_size = sizeof(struct mwifiex_bss_priv);
Amitkumar Karwar5116f3c2011-09-21 21:43:23 -07001849
Avinash Patild6bffe82012-05-08 18:30:15 -07001850 wiphy->reg_notifier = mwifiex_reg_notifier;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001851
Avinash Patil67fdf392012-05-08 18:30:17 -07001852 /* Set struct mwifiex_adapter pointer in wiphy_priv */
Avinash Patild6bffe82012-05-08 18:30:15 -07001853 wdev_priv = wiphy_priv(wiphy);
Avinash Patil67fdf392012-05-08 18:30:17 -07001854 *(unsigned long *)wdev_priv = (unsigned long)adapter;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001855
Joe Perches2c208892012-06-04 12:44:17 +00001856 set_wiphy_dev(wiphy, priv->adapter->dev);
Yogesh Ashok Powara7b21162011-06-13 09:49:27 +05301857
Avinash Patild6bffe82012-05-08 18:30:15 -07001858 ret = wiphy_register(wiphy);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001859 if (ret < 0) {
Avinash Patild6bffe82012-05-08 18:30:15 -07001860 dev_err(adapter->dev,
1861 "%s: wiphy_register failed: %d\n", __func__, ret);
1862 wiphy_free(wiphy);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001863 return ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001864 }
Amitkumar Karwar9e04a7c2012-04-09 20:06:54 -07001865 country_code = mwifiex_11d_code_2_region(priv->adapter->region_code);
Avinash Patild6bffe82012-05-08 18:30:15 -07001866 if (country_code && regulatory_hint(wiphy, country_code))
1867 dev_err(adapter->dev, "regulatory_hint() failed\n");
Amitkumar Karwar9e04a7c2012-04-09 20:06:54 -07001868
Avinash Patild6bffe82012-05-08 18:30:15 -07001869 adapter->wiphy = wiphy;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001870 return ret;
1871}