blob: 2969f74faa420823a01e0c385144552d9df03297 [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
Avinash Patil75edd2c2012-05-08 18:30:18 -0700102 if (mwifiex_set_encode(priv, 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;
174 } else if (mwifiex_set_encode(priv, NULL, 0, key_index, NULL, 0)) {
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700175 wiphy_err(wiphy, "set default Tx key index\n");
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700176 return -EFAULT;
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700177 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700178
179 return 0;
180}
181
182/*
183 * CFG802.11 operation handler to add a network key.
184 */
185static int
186mwifiex_cfg80211_add_key(struct wiphy *wiphy, struct net_device *netdev,
187 u8 key_index, bool pairwise, const u8 *mac_addr,
188 struct key_params *params)
189{
Yogesh Ashok Powarf540f9f2012-01-11 20:06:12 -0800190 struct mwifiex_private *priv = mwifiex_netdev_get_priv(netdev);
Avinash Patil96893532012-06-15 12:21:55 -0700191 struct mwifiex_wep_key *wep_key;
Avinash Patil75edd2c2012-05-08 18:30:18 -0700192 const u8 bc_mac[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
193 const u8 *peer_mac = pairwise ? mac_addr : bc_mac;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700194
Avinash Patil96893532012-06-15 12:21:55 -0700195 if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_UAP &&
196 (params->cipher == WLAN_CIPHER_SUITE_WEP40 ||
197 params->cipher == WLAN_CIPHER_SUITE_WEP104)) {
198 if (params->key && params->key_len) {
199 wep_key = &priv->wep_key[key_index];
200 memset(wep_key, 0, sizeof(struct mwifiex_wep_key));
201 memcpy(wep_key->key_material, params->key,
202 params->key_len);
203 wep_key->key_index = key_index;
204 wep_key->key_length = params->key_len;
205 priv->sec_info.wep_enabled = 1;
206 }
207 return 0;
208 }
209
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700210 if (mwifiex_set_encode(priv, params->key, params->key_len,
Avinash Patil75edd2c2012-05-08 18:30:18 -0700211 key_index, peer_mac, 0)) {
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700212 wiphy_err(wiphy, "crypto keys added\n");
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700213 return -EFAULT;
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700214 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700215
216 return 0;
217}
218
219/*
220 * This function sends domain information to the firmware.
221 *
222 * The following information are passed to the firmware -
223 * - Country codes
224 * - Sub bands (first channel, number of channels, maximum Tx power)
225 */
226static int mwifiex_send_domain_info_cmd_fw(struct wiphy *wiphy)
227{
228 u8 no_of_triplet = 0;
229 struct ieee80211_country_ie_triplet *t;
230 u8 no_of_parsed_chan = 0;
231 u8 first_chan = 0, next_chan = 0, max_pwr = 0;
232 u8 i, flag = 0;
233 enum ieee80211_band band;
234 struct ieee80211_supported_band *sband;
235 struct ieee80211_channel *ch;
Avinash Patil67fdf392012-05-08 18:30:17 -0700236 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
237 struct mwifiex_private *priv;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700238 struct mwifiex_802_11d_domain_reg *domain_info = &adapter->domain_reg;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700239
240 /* Set country code */
Avinash Patil67fdf392012-05-08 18:30:17 -0700241 domain_info->country_code[0] = adapter->country_code[0];
242 domain_info->country_code[1] = adapter->country_code[1];
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700243 domain_info->country_code[2] = ' ';
244
245 band = mwifiex_band_to_radio_type(adapter->config_bands);
246 if (!wiphy->bands[band]) {
247 wiphy_err(wiphy, "11D: setting domain info in FW\n");
248 return -1;
249 }
250
251 sband = wiphy->bands[band];
252
253 for (i = 0; i < sband->n_channels ; i++) {
254 ch = &sband->channels[i];
255 if (ch->flags & IEEE80211_CHAN_DISABLED)
256 continue;
257
258 if (!flag) {
259 flag = 1;
260 first_chan = (u32) ch->hw_value;
261 next_chan = first_chan;
Amitkumar Karwar34202e22012-06-27 19:57:59 -0700262 max_pwr = ch->max_reg_power;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700263 no_of_parsed_chan = 1;
264 continue;
265 }
266
267 if (ch->hw_value == next_chan + 1 &&
Amitkumar Karwar34202e22012-06-27 19:57:59 -0700268 ch->max_reg_power == max_pwr) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700269 next_chan++;
270 no_of_parsed_chan++;
271 } else {
272 t = &domain_info->triplet[no_of_triplet];
273 t->chans.first_channel = first_chan;
274 t->chans.num_channels = no_of_parsed_chan;
275 t->chans.max_power = max_pwr;
276 no_of_triplet++;
277 first_chan = (u32) ch->hw_value;
278 next_chan = first_chan;
Amitkumar Karwar34202e22012-06-27 19:57:59 -0700279 max_pwr = ch->max_reg_power;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700280 no_of_parsed_chan = 1;
281 }
282 }
283
284 if (flag) {
285 t = &domain_info->triplet[no_of_triplet];
286 t->chans.first_channel = first_chan;
287 t->chans.num_channels = no_of_parsed_chan;
288 t->chans.max_power = max_pwr;
289 no_of_triplet++;
290 }
291
292 domain_info->no_of_triplet = no_of_triplet;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700293
Avinash Patil67fdf392012-05-08 18:30:17 -0700294 priv = mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY);
295
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700296 if (mwifiex_send_cmd_async(priv, HostCmd_CMD_802_11D_DOMAIN_INFO,
Yogesh Ashok Powaraea07012012-03-13 19:22:35 -0700297 HostCmd_ACT_GEN_SET, 0, NULL)) {
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700298 wiphy_err(wiphy, "11D: setting domain info in FW\n");
299 return -1;
300 }
301
302 return 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700303}
304
305/*
306 * CFG802.11 regulatory domain callback function.
307 *
308 * This function is called when the regulatory domain is changed due to the
309 * following reasons -
310 * - Set by driver
311 * - Set by system core
312 * - Set by user
313 * - Set bt Country IE
314 */
315static int mwifiex_reg_notifier(struct wiphy *wiphy,
Yogesh Ashok Powaraea07012012-03-13 19:22:35 -0700316 struct regulatory_request *request)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700317{
Avinash Patil67fdf392012-05-08 18:30:17 -0700318 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700319
Avinash Patil67fdf392012-05-08 18:30:17 -0700320 wiphy_dbg(wiphy, "info: cfg80211 regulatory domain callback for %c%c\n",
321 request->alpha2[0], request->alpha2[1]);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700322
Avinash Patil67fdf392012-05-08 18:30:17 -0700323 memcpy(adapter->country_code, request->alpha2, sizeof(request->alpha2));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700324
325 switch (request->initiator) {
326 case NL80211_REGDOM_SET_BY_DRIVER:
327 case NL80211_REGDOM_SET_BY_CORE:
328 case NL80211_REGDOM_SET_BY_USER:
329 break;
330 /* Todo: apply driver specific changes in channel flags based
331 on the request initiator if necessary. */
332 case NL80211_REGDOM_SET_BY_COUNTRY_IE:
333 break;
334 }
335 mwifiex_send_domain_info_cmd_fw(wiphy);
336
337 return 0;
338}
339
340/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700341 * This function sets the fragmentation threshold.
342 *
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700343 * The fragmentation threshold value must lie between MWIFIEX_FRAG_MIN_VALUE
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700344 * and MWIFIEX_FRAG_MAX_VALUE.
345 */
346static int
347mwifiex_set_frag(struct mwifiex_private *priv, u32 frag_thr)
348{
Yogesh Ashok Powaraea07012012-03-13 19:22:35 -0700349 if (frag_thr < MWIFIEX_FRAG_MIN_VALUE ||
350 frag_thr > MWIFIEX_FRAG_MAX_VALUE)
Avinash Patil9b930ea2012-05-08 18:30:23 -0700351 frag_thr = MWIFIEX_FRAG_MAX_VALUE;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700352
Avinash Patil9b930ea2012-05-08 18:30:23 -0700353 return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_SNMP_MIB,
354 HostCmd_ACT_GEN_SET, FRAG_THRESH_I,
355 &frag_thr);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700356}
357
358/*
359 * This function sets the RTS threshold.
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700360
361 * The rts value must lie between MWIFIEX_RTS_MIN_VALUE
362 * and MWIFIEX_RTS_MAX_VALUE.
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700363 */
364static int
365mwifiex_set_rts(struct mwifiex_private *priv, u32 rts_thr)
366{
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700367 if (rts_thr < MWIFIEX_RTS_MIN_VALUE || rts_thr > MWIFIEX_RTS_MAX_VALUE)
368 rts_thr = MWIFIEX_RTS_MAX_VALUE;
369
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700370 return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_SNMP_MIB,
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700371 HostCmd_ACT_GEN_SET, RTS_THRESH_I,
372 &rts_thr);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700373}
374
375/*
376 * CFG802.11 operation handler to set wiphy parameters.
377 *
378 * This function can be used to set the RTS threshold and the
379 * Fragmentation threshold of the driver.
380 */
381static int
382mwifiex_cfg80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
383{
Avinash Patil67fdf392012-05-08 18:30:17 -0700384 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
Avinash Patil9b930ea2012-05-08 18:30:23 -0700385 struct mwifiex_private *priv;
386 struct mwifiex_uap_bss_param *bss_cfg;
387 int ret, bss_started, i;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700388
Avinash Patil9b930ea2012-05-08 18:30:23 -0700389 for (i = 0; i < adapter->priv_num; i++) {
390 priv = adapter->priv[i];
391
392 switch (priv->bss_role) {
393 case MWIFIEX_BSS_ROLE_UAP:
394 bss_cfg = kzalloc(sizeof(struct mwifiex_uap_bss_param),
395 GFP_KERNEL);
396 if (!bss_cfg)
397 return -ENOMEM;
398
399 mwifiex_set_sys_config_invalid_data(bss_cfg);
400
401 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
402 bss_cfg->rts_threshold = wiphy->rts_threshold;
403 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
404 bss_cfg->frag_threshold = wiphy->frag_threshold;
405 if (changed & WIPHY_PARAM_RETRY_LONG)
406 bss_cfg->retry_limit = wiphy->retry_long;
407
408 bss_started = priv->bss_started;
409
410 ret = mwifiex_send_cmd_sync(priv,
411 HostCmd_CMD_UAP_BSS_STOP,
412 HostCmd_ACT_GEN_SET, 0,
413 NULL);
414 if (ret) {
415 wiphy_err(wiphy, "Failed to stop the BSS\n");
416 kfree(bss_cfg);
417 return ret;
418 }
419
420 ret = mwifiex_send_cmd_async(priv,
421 HostCmd_CMD_UAP_SYS_CONFIG,
422 HostCmd_ACT_GEN_SET,
Avinash Patile76268d2012-05-08 18:30:27 -0700423 UAP_BSS_PARAMS_I, bss_cfg);
Avinash Patil9b930ea2012-05-08 18:30:23 -0700424
425 kfree(bss_cfg);
426
427 if (ret) {
428 wiphy_err(wiphy, "Failed to set bss config\n");
429 return ret;
430 }
431
432 if (!bss_started)
433 break;
434
435 ret = mwifiex_send_cmd_async(priv,
436 HostCmd_CMD_UAP_BSS_START,
437 HostCmd_ACT_GEN_SET, 0,
438 NULL);
439 if (ret) {
440 wiphy_err(wiphy, "Failed to start BSS\n");
441 return ret;
442 }
443
444 break;
445 case MWIFIEX_BSS_ROLE_STA:
446 if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
447 ret = mwifiex_set_rts(priv,
448 wiphy->rts_threshold);
449 if (ret)
450 return ret;
451 }
452 if (changed & WIPHY_PARAM_FRAG_THRESHOLD) {
453 ret = mwifiex_set_frag(priv,
454 wiphy->frag_threshold);
455 if (ret)
456 return ret;
457 }
458 break;
459 }
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700460 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700461
Avinash Patil9b930ea2012-05-08 18:30:23 -0700462 return 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700463}
464
465/*
466 * CFG802.11 operation handler to change interface type.
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700467 */
468static int
469mwifiex_cfg80211_change_virtual_intf(struct wiphy *wiphy,
470 struct net_device *dev,
471 enum nl80211_iftype type, u32 *flags,
472 struct vif_params *params)
473{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700474 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700475 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
Bing Zhaoeecd8252011-03-28 17:55:41 -0700476
Avinash Patil4f023412012-05-08 18:30:22 -0700477 switch (dev->ieee80211_ptr->iftype) {
Bing Zhaoeecd8252011-03-28 17:55:41 -0700478 case NL80211_IFTYPE_ADHOC:
Avinash Patil4f023412012-05-08 18:30:22 -0700479 switch (type) {
480 case NL80211_IFTYPE_STATION:
481 break;
482 case NL80211_IFTYPE_UNSPECIFIED:
483 wiphy_warn(wiphy, "%s: kept type as IBSS\n", dev->name);
484 case NL80211_IFTYPE_ADHOC: /* This shouldn't happen */
485 return 0;
486 case NL80211_IFTYPE_AP:
487 default:
488 wiphy_err(wiphy, "%s: changing to %d not supported\n",
489 dev->name, type);
490 return -EOPNOTSUPP;
491 }
Bing Zhaoeecd8252011-03-28 17:55:41 -0700492 break;
493 case NL80211_IFTYPE_STATION:
Avinash Patil4f023412012-05-08 18:30:22 -0700494 switch (type) {
495 case NL80211_IFTYPE_ADHOC:
496 break;
497 case NL80211_IFTYPE_UNSPECIFIED:
498 wiphy_warn(wiphy, "%s: kept type as STA\n", dev->name);
499 case NL80211_IFTYPE_STATION: /* This shouldn't happen */
500 return 0;
501 case NL80211_IFTYPE_AP:
502 default:
503 wiphy_err(wiphy, "%s: changing to %d not supported\n",
504 dev->name, type);
505 return -EOPNOTSUPP;
506 }
Bing Zhaoeecd8252011-03-28 17:55:41 -0700507 break;
Avinash Patil4f023412012-05-08 18:30:22 -0700508 case NL80211_IFTYPE_AP:
509 switch (type) {
510 case NL80211_IFTYPE_UNSPECIFIED:
511 wiphy_warn(wiphy, "%s: kept type as AP\n", dev->name);
512 case NL80211_IFTYPE_AP: /* This shouldn't happen */
513 return 0;
514 case NL80211_IFTYPE_ADHOC:
515 case NL80211_IFTYPE_STATION:
516 default:
517 wiphy_err(wiphy, "%s: changing to %d not supported\n",
518 dev->name, type);
519 return -EOPNOTSUPP;
520 }
521 break;
Bing Zhaoeecd8252011-03-28 17:55:41 -0700522 default:
Avinash Patil4f023412012-05-08 18:30:22 -0700523 wiphy_err(wiphy, "%s: unknown iftype: %d\n",
524 dev->name, dev->ieee80211_ptr->iftype);
525 return -EOPNOTSUPP;
Bing Zhaoeecd8252011-03-28 17:55:41 -0700526 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700527
Avinash Patil4f023412012-05-08 18:30:22 -0700528 dev->ieee80211_ptr->iftype = type;
529 priv->bss_mode = type;
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700530 mwifiex_deauthenticate(priv, NULL);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700531
Marc Yangf986b6d2011-03-28 17:55:42 -0700532 priv->sec_info.authentication_mode = NL80211_AUTHTYPE_OPEN_SYSTEM;
Bing Zhaoeecd8252011-03-28 17:55:41 -0700533
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700534 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_SET_BSS_MODE,
535 HostCmd_ACT_GEN_SET, 0, NULL);
Bing Zhaoeecd8252011-03-28 17:55:41 -0700536
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700537 return ret;
538}
539
540/*
541 * This function dumps the station information on a buffer.
542 *
543 * The following information are shown -
544 * - Total bytes transmitted
545 * - Total bytes received
546 * - Total packets transmitted
547 * - Total packets received
548 * - Signal quality level
549 * - Transmission rate
550 */
551static int
552mwifiex_dump_station_info(struct mwifiex_private *priv,
553 struct station_info *sinfo)
554{
Amitkumar Karwar006606c2012-07-13 20:09:31 -0700555 u32 rate;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700556
557 sinfo->filled = STATION_INFO_RX_BYTES | STATION_INFO_TX_BYTES |
Amitkumar Karwar7013d3e2012-03-15 20:51:50 -0700558 STATION_INFO_RX_PACKETS | STATION_INFO_TX_PACKETS |
559 STATION_INFO_TX_BITRATE |
560 STATION_INFO_SIGNAL | STATION_INFO_SIGNAL_AVG;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700561
562 /* Get signal information from the firmware */
Amitkumar Karwar958a4a82012-03-15 20:51:49 -0700563 if (mwifiex_send_cmd_sync(priv, HostCmd_CMD_RSSI_INFO,
564 HostCmd_ACT_GEN_GET, 0, NULL)) {
565 dev_err(priv->adapter->dev, "failed to get signal information\n");
566 return -EFAULT;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700567 }
568
569 if (mwifiex_drv_get_data_rate(priv, &rate)) {
570 dev_err(priv->adapter->dev, "getting data rate\n");
Amitkumar Karwar958a4a82012-03-15 20:51:49 -0700571 return -EFAULT;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700572 }
573
Amitkumar Karwarcaf60a62012-02-02 20:48:58 -0800574 /* Get DTIM period information from firmware */
575 mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_SNMP_MIB,
576 HostCmd_ACT_GEN_GET, DTIM_PERIOD_I,
577 &priv->dtim_period);
578
Amitkumar Karwar4ec6f9c2011-09-26 20:37:25 -0700579 /*
580 * Bit 0 in tx_htinfo indicates that current Tx rate is 11n rate. Valid
581 * MCS index values for us are 0 to 7.
582 */
583 if ((priv->tx_htinfo & BIT(0)) && (priv->tx_rate < 8)) {
584 sinfo->txrate.mcs = priv->tx_rate;
585 sinfo->txrate.flags |= RATE_INFO_FLAGS_MCS;
586 /* 40MHz rate */
587 if (priv->tx_htinfo & BIT(1))
588 sinfo->txrate.flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
589 /* SGI enabled */
590 if (priv->tx_htinfo & BIT(2))
591 sinfo->txrate.flags |= RATE_INFO_FLAGS_SHORT_GI;
592 }
593
Amitkumar Karwar7013d3e2012-03-15 20:51:50 -0700594 sinfo->signal_avg = priv->bcn_rssi_avg;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700595 sinfo->rx_bytes = priv->stats.rx_bytes;
596 sinfo->tx_bytes = priv->stats.tx_bytes;
597 sinfo->rx_packets = priv->stats.rx_packets;
598 sinfo->tx_packets = priv->stats.tx_packets;
Amitkumar Karwar958a4a82012-03-15 20:51:49 -0700599 sinfo->signal = priv->bcn_rssi_avg;
Amitkumar Karwar4ec6f9c2011-09-26 20:37:25 -0700600 /* bit rate is in 500 kb/s units. Convert it to 100kb/s units */
Amitkumar Karwar006606c2012-07-13 20:09:31 -0700601 sinfo->txrate.legacy = rate * 5;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700602
Amitkumar Karwarc4f3b972012-01-24 20:50:25 -0800603 if (priv->bss_mode == NL80211_IFTYPE_STATION) {
604 sinfo->filled |= STATION_INFO_BSS_PARAM;
605 sinfo->bss_param.flags = 0;
606 if (priv->curr_bss_params.bss_descriptor.cap_info_bitmap &
607 WLAN_CAPABILITY_SHORT_PREAMBLE)
608 sinfo->bss_param.flags |=
609 BSS_PARAM_FLAGS_SHORT_PREAMBLE;
610 if (priv->curr_bss_params.bss_descriptor.cap_info_bitmap &
611 WLAN_CAPABILITY_SHORT_SLOT_TIME)
612 sinfo->bss_param.flags |=
613 BSS_PARAM_FLAGS_SHORT_SLOT_TIME;
Amitkumar Karwarcaf60a62012-02-02 20:48:58 -0800614 sinfo->bss_param.dtim_period = priv->dtim_period;
Amitkumar Karwarc4f3b972012-01-24 20:50:25 -0800615 sinfo->bss_param.beacon_interval =
616 priv->curr_bss_params.bss_descriptor.beacon_period;
617 }
618
Amitkumar Karwar958a4a82012-03-15 20:51:49 -0700619 return 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700620}
621
622/*
623 * CFG802.11 operation handler to get station information.
624 *
625 * This function only works in connected mode, and dumps the
626 * requested station information, if available.
627 */
628static int
629mwifiex_cfg80211_get_station(struct wiphy *wiphy, struct net_device *dev,
630 u8 *mac, struct station_info *sinfo)
631{
632 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700633
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700634 if (!priv->media_connected)
635 return -ENOENT;
636 if (memcmp(mac, priv->cfg_bssid, ETH_ALEN))
637 return -ENOENT;
638
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700639 return mwifiex_dump_station_info(priv, sinfo);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700640}
641
Amitkumar Karwarf85aae62012-03-15 20:51:48 -0700642/*
643 * CFG802.11 operation handler to dump station information.
644 */
645static int
646mwifiex_cfg80211_dump_station(struct wiphy *wiphy, struct net_device *dev,
647 int idx, u8 *mac, struct station_info *sinfo)
648{
649 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
650
651 if (!priv->media_connected || idx)
652 return -ENOENT;
653
654 memcpy(mac, priv->cfg_bssid, ETH_ALEN);
655
656 return mwifiex_dump_station_info(priv, sinfo);
657}
658
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700659/* Supported rates to be advertised to the cfg80211 */
660
661static struct ieee80211_rate mwifiex_rates[] = {
662 {.bitrate = 10, .hw_value = 2, },
663 {.bitrate = 20, .hw_value = 4, },
664 {.bitrate = 55, .hw_value = 11, },
665 {.bitrate = 110, .hw_value = 22, },
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700666 {.bitrate = 60, .hw_value = 12, },
667 {.bitrate = 90, .hw_value = 18, },
668 {.bitrate = 120, .hw_value = 24, },
669 {.bitrate = 180, .hw_value = 36, },
670 {.bitrate = 240, .hw_value = 48, },
671 {.bitrate = 360, .hw_value = 72, },
672 {.bitrate = 480, .hw_value = 96, },
673 {.bitrate = 540, .hw_value = 108, },
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700674};
675
676/* Channel definitions to be advertised to cfg80211 */
677
678static struct ieee80211_channel mwifiex_channels_2ghz[] = {
679 {.center_freq = 2412, .hw_value = 1, },
680 {.center_freq = 2417, .hw_value = 2, },
681 {.center_freq = 2422, .hw_value = 3, },
682 {.center_freq = 2427, .hw_value = 4, },
683 {.center_freq = 2432, .hw_value = 5, },
684 {.center_freq = 2437, .hw_value = 6, },
685 {.center_freq = 2442, .hw_value = 7, },
686 {.center_freq = 2447, .hw_value = 8, },
687 {.center_freq = 2452, .hw_value = 9, },
688 {.center_freq = 2457, .hw_value = 10, },
689 {.center_freq = 2462, .hw_value = 11, },
690 {.center_freq = 2467, .hw_value = 12, },
691 {.center_freq = 2472, .hw_value = 13, },
692 {.center_freq = 2484, .hw_value = 14, },
693};
694
695static struct ieee80211_supported_band mwifiex_band_2ghz = {
696 .channels = mwifiex_channels_2ghz,
697 .n_channels = ARRAY_SIZE(mwifiex_channels_2ghz),
698 .bitrates = mwifiex_rates,
Amitkumar Karwar87638482012-03-07 19:36:07 -0800699 .n_bitrates = ARRAY_SIZE(mwifiex_rates),
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700700};
701
702static struct ieee80211_channel mwifiex_channels_5ghz[] = {
703 {.center_freq = 5040, .hw_value = 8, },
704 {.center_freq = 5060, .hw_value = 12, },
705 {.center_freq = 5080, .hw_value = 16, },
706 {.center_freq = 5170, .hw_value = 34, },
707 {.center_freq = 5190, .hw_value = 38, },
708 {.center_freq = 5210, .hw_value = 42, },
709 {.center_freq = 5230, .hw_value = 46, },
710 {.center_freq = 5180, .hw_value = 36, },
711 {.center_freq = 5200, .hw_value = 40, },
712 {.center_freq = 5220, .hw_value = 44, },
713 {.center_freq = 5240, .hw_value = 48, },
714 {.center_freq = 5260, .hw_value = 52, },
715 {.center_freq = 5280, .hw_value = 56, },
716 {.center_freq = 5300, .hw_value = 60, },
717 {.center_freq = 5320, .hw_value = 64, },
718 {.center_freq = 5500, .hw_value = 100, },
719 {.center_freq = 5520, .hw_value = 104, },
720 {.center_freq = 5540, .hw_value = 108, },
721 {.center_freq = 5560, .hw_value = 112, },
722 {.center_freq = 5580, .hw_value = 116, },
723 {.center_freq = 5600, .hw_value = 120, },
724 {.center_freq = 5620, .hw_value = 124, },
725 {.center_freq = 5640, .hw_value = 128, },
726 {.center_freq = 5660, .hw_value = 132, },
727 {.center_freq = 5680, .hw_value = 136, },
728 {.center_freq = 5700, .hw_value = 140, },
729 {.center_freq = 5745, .hw_value = 149, },
730 {.center_freq = 5765, .hw_value = 153, },
731 {.center_freq = 5785, .hw_value = 157, },
732 {.center_freq = 5805, .hw_value = 161, },
733 {.center_freq = 5825, .hw_value = 165, },
734};
735
736static struct ieee80211_supported_band mwifiex_band_5ghz = {
737 .channels = mwifiex_channels_5ghz,
738 .n_channels = ARRAY_SIZE(mwifiex_channels_5ghz),
Avinash Patileb416ad2012-02-27 22:04:11 -0800739 .bitrates = mwifiex_rates + 4,
740 .n_bitrates = ARRAY_SIZE(mwifiex_rates) - 4,
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700741};
742
743
744/* Supported crypto cipher suits to be advertised to cfg80211 */
745
746static const u32 mwifiex_cipher_suites[] = {
747 WLAN_CIPHER_SUITE_WEP40,
748 WLAN_CIPHER_SUITE_WEP104,
749 WLAN_CIPHER_SUITE_TKIP,
750 WLAN_CIPHER_SUITE_CCMP,
751};
752
753/*
Yogesh Ashok Powar5d82c532011-07-11 20:04:44 -0700754 * CFG802.11 operation handler for setting bit rates.
755 *
Amitkumar Karwar433c3992012-07-13 20:09:33 -0700756 * Function configures data rates to firmware using bitrate mask
757 * provided by cfg80211.
Yogesh Ashok Powar5d82c532011-07-11 20:04:44 -0700758 */
759static int mwifiex_cfg80211_set_bitrate_mask(struct wiphy *wiphy,
760 struct net_device *dev,
761 const u8 *peer,
762 const struct cfg80211_bitrate_mask *mask)
763{
Yogesh Ashok Powar5d82c532011-07-11 20:04:44 -0700764 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
Amitkumar Karwar433c3992012-07-13 20:09:33 -0700765 u16 bitmap_rates[MAX_BITMAP_RATES_SIZE];
766 enum ieee80211_band band;
Yogesh Ashok Powar5d82c532011-07-11 20:04:44 -0700767
Amitkumar Karwar433c3992012-07-13 20:09:33 -0700768 if (!priv->media_connected) {
769 dev_err(priv->adapter->dev,
770 "Can not set Tx data rate in disconnected state\n");
771 return -EINVAL;
Yogesh Ashok Powar5d82c532011-07-11 20:04:44 -0700772 }
773
Amitkumar Karwar433c3992012-07-13 20:09:33 -0700774 band = mwifiex_band_to_radio_type(priv->curr_bss_params.band);
Yogesh Ashok Powar5d82c532011-07-11 20:04:44 -0700775
Amitkumar Karwar433c3992012-07-13 20:09:33 -0700776 memset(bitmap_rates, 0, sizeof(bitmap_rates));
Yogesh Ashok Powar5d82c532011-07-11 20:04:44 -0700777
Amitkumar Karwar433c3992012-07-13 20:09:33 -0700778 /* Fill HR/DSSS rates. */
779 if (band == IEEE80211_BAND_2GHZ)
780 bitmap_rates[0] = mask->control[band].legacy & 0x000f;
Yogesh Ashok Powar5d82c532011-07-11 20:04:44 -0700781
Amitkumar Karwar433c3992012-07-13 20:09:33 -0700782 /* Fill OFDM rates */
783 if (band == IEEE80211_BAND_2GHZ)
784 bitmap_rates[1] = (mask->control[band].legacy & 0x0ff0) >> 4;
785 else
786 bitmap_rates[1] = mask->control[band].legacy;
787
788 /* Fill MCS rates */
789 bitmap_rates[2] = mask->control[band].mcs[0];
790 if (priv->adapter->hw_dev_mcs_support == HT_STREAM_2X2)
791 bitmap_rates[2] |= mask->control[band].mcs[1] << 8;
792
793 return mwifiex_send_cmd_sync(priv, HostCmd_CMD_TX_RATE_CFG,
794 HostCmd_ACT_GEN_SET, 0, bitmap_rates);
Yogesh Ashok Powar5d82c532011-07-11 20:04:44 -0700795}
796
797/*
Amitkumar Karwarfa444bf2012-03-15 20:51:51 -0700798 * CFG802.11 operation handler for connection quality monitoring.
799 *
800 * This function subscribes/unsubscribes HIGH_RSSI and LOW_RSSI
801 * events to FW.
802 */
803static int mwifiex_cfg80211_set_cqm_rssi_config(struct wiphy *wiphy,
804 struct net_device *dev,
805 s32 rssi_thold, u32 rssi_hyst)
806{
807 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
808 struct mwifiex_ds_misc_subsc_evt subsc_evt;
809
810 priv->cqm_rssi_thold = rssi_thold;
811 priv->cqm_rssi_hyst = rssi_hyst;
812
813 memset(&subsc_evt, 0x00, sizeof(struct mwifiex_ds_misc_subsc_evt));
814 subsc_evt.events = BITMASK_BCN_RSSI_LOW | BITMASK_BCN_RSSI_HIGH;
815
816 /* Subscribe/unsubscribe low and high rssi events */
817 if (rssi_thold && rssi_hyst) {
818 subsc_evt.action = HostCmd_ACT_BITWISE_SET;
819 subsc_evt.bcn_l_rssi_cfg.abs_value = abs(rssi_thold);
820 subsc_evt.bcn_h_rssi_cfg.abs_value = abs(rssi_thold);
821 subsc_evt.bcn_l_rssi_cfg.evt_freq = 1;
822 subsc_evt.bcn_h_rssi_cfg.evt_freq = 1;
823 return mwifiex_send_cmd_sync(priv,
824 HostCmd_CMD_802_11_SUBSCRIBE_EVENT,
825 0, 0, &subsc_evt);
826 } else {
827 subsc_evt.action = HostCmd_ACT_BITWISE_CLR;
828 return mwifiex_send_cmd_sync(priv,
829 HostCmd_CMD_802_11_SUBSCRIBE_EVENT,
830 0, 0, &subsc_evt);
831 }
832
833 return 0;
834}
835
Avinash Patil5370c832012-06-28 20:30:28 -0700836/* cfg80211 operation handler for change_beacon.
837 * Function retrieves and sets modified management IEs to FW.
838 */
839static int mwifiex_cfg80211_change_beacon(struct wiphy *wiphy,
840 struct net_device *dev,
841 struct cfg80211_beacon_data *data)
842{
843 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
844
845 if (priv->bss_type != MWIFIEX_BSS_TYPE_UAP) {
846 wiphy_err(wiphy, "%s: bss_type mismatched\n", __func__);
847 return -EINVAL;
848 }
849
850 if (!priv->bss_started) {
851 wiphy_err(wiphy, "%s: bss not started\n", __func__);
852 return -EINVAL;
853 }
854
855 if (mwifiex_set_mgmt_ies(priv, data)) {
856 wiphy_err(wiphy, "%s: setting mgmt ies failed\n", __func__);
857 return -EFAULT;
858 }
859
860 return 0;
861}
862
Amitkumar Karwar8a279d52012-07-02 19:32:33 -0700863static int
864mwifiex_cfg80211_set_antenna(struct wiphy *wiphy, u32 tx_ant, u32 rx_ant)
865{
866 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
867 struct mwifiex_private *priv = mwifiex_get_priv(adapter,
868 MWIFIEX_BSS_ROLE_ANY);
869 struct mwifiex_ds_ant_cfg ant_cfg;
870
871 if (!tx_ant || !rx_ant)
872 return -EOPNOTSUPP;
873
874 if (adapter->hw_dev_mcs_support != HT_STREAM_2X2) {
875 /* Not a MIMO chip. User should provide specific antenna number
876 * for Tx/Rx path or enable all antennas for diversity
877 */
878 if (tx_ant != rx_ant)
879 return -EOPNOTSUPP;
880
881 if ((tx_ant & (tx_ant - 1)) &&
882 (tx_ant != BIT(adapter->number_of_antenna) - 1))
883 return -EOPNOTSUPP;
884
885 if ((tx_ant == BIT(adapter->number_of_antenna) - 1) &&
886 (priv->adapter->number_of_antenna > 1)) {
887 tx_ant = RF_ANTENNA_AUTO;
888 rx_ant = RF_ANTENNA_AUTO;
889 }
890 }
891
892 ant_cfg.tx_ant = tx_ant;
893 ant_cfg.rx_ant = rx_ant;
894
895 return mwifiex_send_cmd_sync(priv, HostCmd_CMD_RF_ANTENNA,
896 HostCmd_ACT_GEN_SET, 0, &ant_cfg);
897}
898
Avinash Patil12190c52012-05-08 18:30:24 -0700899/* cfg80211 operation handler for stop ap.
900 * Function stops BSS running at uAP interface.
901 */
902static int mwifiex_cfg80211_stop_ap(struct wiphy *wiphy, struct net_device *dev)
903{
904 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
905
Avinash Patil40bbc212012-05-08 18:30:30 -0700906 if (mwifiex_del_mgmt_ies(priv))
907 wiphy_err(wiphy, "Failed to delete mgmt IEs!\n");
908
Avinash Patil12190c52012-05-08 18:30:24 -0700909 if (mwifiex_send_cmd_sync(priv, HostCmd_CMD_UAP_BSS_STOP,
910 HostCmd_ACT_GEN_SET, 0, NULL)) {
911 wiphy_err(wiphy, "Failed to stop the BSS\n");
912 return -1;
913 }
914
915 return 0;
916}
917
918/* cfg80211 operation handler for start_ap.
919 * Function sets beacon period, DTIM period, SSID and security into
920 * AP config structure.
921 * AP is configured with these settings and BSS is started.
922 */
923static int mwifiex_cfg80211_start_ap(struct wiphy *wiphy,
924 struct net_device *dev,
925 struct cfg80211_ap_settings *params)
926{
927 struct mwifiex_uap_bss_param *bss_cfg;
928 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
Amitkumar Karwar05910f42012-07-13 20:09:32 -0700929 u8 config_bands = 0;
Avinash Patil12190c52012-05-08 18:30:24 -0700930
Avinash Patilf752dcd2012-05-08 18:30:26 -0700931 if (priv->bss_type != MWIFIEX_BSS_TYPE_UAP)
932 return -1;
Avinash Patiladb6ed02012-06-28 20:30:25 -0700933 if (mwifiex_set_mgmt_ies(priv, &params->beacon))
Avinash Patilf31acab2012-05-08 18:30:29 -0700934 return -1;
Avinash Patilf752dcd2012-05-08 18:30:26 -0700935
Avinash Patil12190c52012-05-08 18:30:24 -0700936 bss_cfg = kzalloc(sizeof(struct mwifiex_uap_bss_param), GFP_KERNEL);
937 if (!bss_cfg)
938 return -ENOMEM;
939
940 mwifiex_set_sys_config_invalid_data(bss_cfg);
941
942 if (params->beacon_interval)
943 bss_cfg->beacon_period = params->beacon_interval;
944 if (params->dtim_period)
945 bss_cfg->dtim_period = params->dtim_period;
946
947 if (params->ssid && params->ssid_len) {
948 memcpy(bss_cfg->ssid.ssid, params->ssid, params->ssid_len);
949 bss_cfg->ssid.ssid_len = params->ssid_len;
950 }
951
Avinash Patil605b73a2012-05-16 21:24:55 -0700952 switch (params->hidden_ssid) {
953 case NL80211_HIDDEN_SSID_NOT_IN_USE:
954 bss_cfg->bcast_ssid_ctl = 1;
955 break;
956 case NL80211_HIDDEN_SSID_ZERO_LEN:
957 bss_cfg->bcast_ssid_ctl = 0;
958 break;
959 case NL80211_HIDDEN_SSID_ZERO_CONTENTS:
960 /* firmware doesn't support this type of hidden SSID */
961 default:
Bing Zhaob3190462012-07-03 15:53:13 -0700962 kfree(bss_cfg);
Avinash Patil605b73a2012-05-16 21:24:55 -0700963 return -EINVAL;
964 }
965
Avinash Patil0abd79e2012-06-15 12:21:51 -0700966 bss_cfg->channel =
967 (u8)ieee80211_frequency_to_channel(params->channel->center_freq);
968 bss_cfg->band_cfg = BAND_CONFIG_MANUAL;
969
Amitkumar Karwar05910f42012-07-13 20:09:32 -0700970 /* Set appropriate bands */
971 if (params->channel->band == IEEE80211_BAND_2GHZ) {
972 if (params->channel_type == NL80211_CHAN_NO_HT)
973 config_bands = BAND_B | BAND_G;
974 else
975 config_bands = BAND_B | BAND_G | BAND_GN;
976 } else {
977 if (params->channel_type == NL80211_CHAN_NO_HT)
978 config_bands = BAND_A;
979 else
980 config_bands = BAND_AN | BAND_A;
Avinash Patil0abd79e2012-06-15 12:21:51 -0700981 }
982
Amitkumar Karwar05910f42012-07-13 20:09:32 -0700983 if (!((config_bands | priv->adapter->fw_bands) &
984 ~priv->adapter->fw_bands))
985 priv->adapter->config_bands = config_bands;
986
987 mwifiex_send_domain_info_cmd_fw(wiphy);
988
Avinash Patilf752dcd2012-05-08 18:30:26 -0700989 if (mwifiex_set_secure_params(priv, bss_cfg, params)) {
990 kfree(bss_cfg);
991 wiphy_err(wiphy, "Failed to parse secuirty parameters!\n");
992 return -1;
993 }
994
Avinash Patil22281252012-06-15 12:21:53 -0700995 mwifiex_set_ht_params(priv, bss_cfg, params);
996
Avinash Patil12190c52012-05-08 18:30:24 -0700997 if (mwifiex_send_cmd_sync(priv, HostCmd_CMD_UAP_BSS_STOP,
998 HostCmd_ACT_GEN_SET, 0, NULL)) {
999 wiphy_err(wiphy, "Failed to stop the BSS\n");
1000 kfree(bss_cfg);
1001 return -1;
1002 }
1003
1004 if (mwifiex_send_cmd_async(priv, HostCmd_CMD_UAP_SYS_CONFIG,
Avinash Patile76268d2012-05-08 18:30:27 -07001005 HostCmd_ACT_GEN_SET,
1006 UAP_BSS_PARAMS_I, bss_cfg)) {
Avinash Patil12190c52012-05-08 18:30:24 -07001007 wiphy_err(wiphy, "Failed to set the SSID\n");
1008 kfree(bss_cfg);
1009 return -1;
1010 }
1011
1012 kfree(bss_cfg);
1013
1014 if (mwifiex_send_cmd_async(priv, HostCmd_CMD_UAP_BSS_START,
1015 HostCmd_ACT_GEN_SET, 0, NULL)) {
1016 wiphy_err(wiphy, "Failed to start the BSS\n");
1017 return -1;
1018 }
1019
Avinash Patil96893532012-06-15 12:21:55 -07001020 if (priv->sec_info.wep_enabled)
1021 priv->curr_pkt_filter |= HostCmd_ACT_MAC_WEP_ENABLE;
1022 else
1023 priv->curr_pkt_filter &= ~HostCmd_ACT_MAC_WEP_ENABLE;
1024
1025 if (mwifiex_send_cmd_sync(priv, HostCmd_CMD_MAC_CONTROL,
1026 HostCmd_ACT_GEN_SET, 0,
1027 &priv->curr_pkt_filter))
1028 return -1;
1029
Avinash Patil12190c52012-05-08 18:30:24 -07001030 return 0;
1031}
1032
Amitkumar Karwarfa444bf2012-03-15 20:51:51 -07001033/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001034 * CFG802.11 operation handler for disconnection request.
1035 *
1036 * This function does not work when there is already a disconnection
1037 * procedure going on.
1038 */
1039static int
1040mwifiex_cfg80211_disconnect(struct wiphy *wiphy, struct net_device *dev,
1041 u16 reason_code)
1042{
1043 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
1044
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001045 if (mwifiex_deauthenticate(priv, NULL))
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001046 return -EFAULT;
1047
1048 wiphy_dbg(wiphy, "info: successfully disconnected from %pM:"
1049 " reason code %d\n", priv->cfg_bssid, reason_code);
1050
Amitkumar Karwar38c9d662011-12-13 20:43:17 -08001051 memset(priv->cfg_bssid, 0, ETH_ALEN);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001052
1053 return 0;
1054}
1055
1056/*
1057 * This function informs the CFG802.11 subsystem of a new IBSS.
1058 *
1059 * The following information are sent to the CFG802.11 subsystem
1060 * to register the new IBSS. If we do not register the new IBSS,
1061 * a kernel panic will result.
1062 * - SSID
1063 * - SSID length
1064 * - BSSID
1065 * - Channel
1066 */
1067static int mwifiex_cfg80211_inform_ibss_bss(struct mwifiex_private *priv)
1068{
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001069 struct ieee80211_channel *chan;
1070 struct mwifiex_bss_info bss_info;
Amitkumar Karwaraa95a482011-11-07 21:41:12 -08001071 struct cfg80211_bss *bss;
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -07001072 int ie_len;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001073 u8 ie_buf[IEEE80211_MAX_SSID_LEN + sizeof(struct ieee_types_header)];
Amitkumar Karwar4ed5d522011-09-21 21:43:24 -07001074 enum ieee80211_band band;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001075
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001076 if (mwifiex_get_bss_info(priv, &bss_info))
1077 return -1;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001078
1079 ie_buf[0] = WLAN_EID_SSID;
1080 ie_buf[1] = bss_info.ssid.ssid_len;
1081
1082 memcpy(&ie_buf[sizeof(struct ieee_types_header)],
Yogesh Ashok Powaraea07012012-03-13 19:22:35 -07001083 &bss_info.ssid.ssid, bss_info.ssid.ssid_len);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001084 ie_len = ie_buf[1] + sizeof(struct ieee_types_header);
1085
Amitkumar Karwar4ed5d522011-09-21 21:43:24 -07001086 band = mwifiex_band_to_radio_type(priv->curr_bss_params.band);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001087 chan = __ieee80211_get_channel(priv->wdev->wiphy,
1088 ieee80211_channel_to_frequency(bss_info.bss_chan,
Amitkumar Karwar4ed5d522011-09-21 21:43:24 -07001089 band));
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001090
Amitkumar Karwaraa95a482011-11-07 21:41:12 -08001091 bss = cfg80211_inform_bss(priv->wdev->wiphy, chan,
Yogesh Ashok Powaraea07012012-03-13 19:22:35 -07001092 bss_info.bssid, 0, WLAN_CAPABILITY_IBSS,
1093 0, ie_buf, ie_len, 0, GFP_KERNEL);
Amitkumar Karwaraa95a482011-11-07 21:41:12 -08001094 cfg80211_put_bss(bss);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001095 memcpy(priv->cfg_bssid, bss_info.bssid, ETH_ALEN);
1096
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001097 return 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001098}
1099
1100/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001101 * This function connects with a BSS.
1102 *
1103 * This function handles both Infra and Ad-Hoc modes. It also performs
1104 * validity checking on the provided parameters, disconnects from the
1105 * current BSS (if any), sets up the association/scan parameters,
1106 * including security settings, and performs specific SSID scan before
1107 * trying to connect.
1108 *
1109 * For Infra mode, the function returns failure if the specified SSID
1110 * is not found in scan table. However, for Ad-Hoc mode, it can create
1111 * the IBSS if it does not exist. On successful completion in either case,
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001112 * the function notifies the CFG802.11 subsystem of the new BSS connection.
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001113 */
1114static int
1115mwifiex_cfg80211_assoc(struct mwifiex_private *priv, size_t ssid_len, u8 *ssid,
1116 u8 *bssid, int mode, struct ieee80211_channel *channel,
1117 struct cfg80211_connect_params *sme, bool privacy)
1118{
Amitkumar Karwarb9be5f32012-02-27 22:04:14 -08001119 struct cfg80211_ssid req_ssid;
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -07001120 int ret, auth_type = 0;
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001121 struct cfg80211_bss *bss = NULL;
Amitkumar Karwar05910f42012-07-13 20:09:32 -07001122 u8 is_scanning_required = 0, config_bands = 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001123
Amitkumar Karwarb9be5f32012-02-27 22:04:14 -08001124 memset(&req_ssid, 0, sizeof(struct cfg80211_ssid));
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001125
1126 req_ssid.ssid_len = ssid_len;
1127 if (ssid_len > IEEE80211_MAX_SSID_LEN) {
1128 dev_err(priv->adapter->dev, "invalid SSID - aborting\n");
1129 return -EINVAL;
1130 }
1131
1132 memcpy(req_ssid.ssid, ssid, ssid_len);
1133 if (!req_ssid.ssid_len || req_ssid.ssid[0] < 0x20) {
1134 dev_err(priv->adapter->dev, "invalid SSID - aborting\n");
1135 return -EINVAL;
1136 }
1137
1138 /* disconnect before try to associate */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001139 mwifiex_deauthenticate(priv, NULL);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001140
Amitkumar Karwar05910f42012-07-13 20:09:32 -07001141 if (channel) {
1142 if (mode == NL80211_IFTYPE_STATION) {
1143 if (channel->band == IEEE80211_BAND_2GHZ)
1144 config_bands = BAND_B | BAND_G | BAND_GN;
1145 else
1146 config_bands = BAND_A | BAND_AN;
1147
1148 if (!((config_bands | priv->adapter->fw_bands) &
1149 ~priv->adapter->fw_bands))
1150 priv->adapter->config_bands = config_bands;
1151 }
1152 mwifiex_send_domain_info_cmd_fw(priv->wdev->wiphy);
1153 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001154
Amitkumar Karwar6670f152012-02-09 18:32:22 -08001155 /* As this is new association, clear locally stored
1156 * keys and security related flags */
1157 priv->sec_info.wpa_enabled = false;
1158 priv->sec_info.wpa2_enabled = false;
1159 priv->wep_key_curr_index = 0;
Amitkumar Karwar00f157b2012-02-24 21:35:35 -08001160 priv->sec_info.encryption_mode = 0;
Amitkumar Karwara0f6d6c2012-02-24 21:36:05 -08001161 priv->sec_info.is_authtype_auto = 0;
Avinash Patil75edd2c2012-05-08 18:30:18 -07001162 ret = mwifiex_set_encode(priv, NULL, 0, 0, NULL, 1);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001163
Bing Zhaoeecd8252011-03-28 17:55:41 -07001164 if (mode == NL80211_IFTYPE_ADHOC) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001165 /* "privacy" is set only for ad-hoc mode */
1166 if (privacy) {
1167 /*
Yogesh Ashok Powar2be50b82011-04-01 18:36:47 -07001168 * Keep WLAN_CIPHER_SUITE_WEP104 for now so that
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001169 * the firmware can find a matching network from the
1170 * scan. The cfg80211 does not give us the encryption
1171 * mode at this stage so just setting it to WEP here.
1172 */
Marc Yang203afec2011-03-24 20:49:39 -07001173 priv->sec_info.encryption_mode =
Yogesh Ashok Powar2be50b82011-04-01 18:36:47 -07001174 WLAN_CIPHER_SUITE_WEP104;
Marc Yang203afec2011-03-24 20:49:39 -07001175 priv->sec_info.authentication_mode =
Marc Yangf986b6d2011-03-28 17:55:42 -07001176 NL80211_AUTHTYPE_OPEN_SYSTEM;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001177 }
1178
1179 goto done;
1180 }
1181
1182 /* Now handle infra mode. "sme" is valid for infra mode only */
Amitkumar Karwara0f6d6c2012-02-24 21:36:05 -08001183 if (sme->auth_type == NL80211_AUTHTYPE_AUTOMATIC) {
Marc Yangf986b6d2011-03-28 17:55:42 -07001184 auth_type = NL80211_AUTHTYPE_OPEN_SYSTEM;
Amitkumar Karwara0f6d6c2012-02-24 21:36:05 -08001185 priv->sec_info.is_authtype_auto = 1;
1186 } else {
1187 auth_type = sme->auth_type;
1188 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001189
1190 if (sme->crypto.n_ciphers_pairwise) {
Yogesh Ashok Powar2be50b82011-04-01 18:36:47 -07001191 priv->sec_info.encryption_mode =
1192 sme->crypto.ciphers_pairwise[0];
Marc Yang203afec2011-03-24 20:49:39 -07001193 priv->sec_info.authentication_mode = auth_type;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001194 }
1195
1196 if (sme->crypto.cipher_group) {
Yogesh Ashok Powar2be50b82011-04-01 18:36:47 -07001197 priv->sec_info.encryption_mode = sme->crypto.cipher_group;
Marc Yang203afec2011-03-24 20:49:39 -07001198 priv->sec_info.authentication_mode = auth_type;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001199 }
1200 if (sme->ie)
1201 ret = mwifiex_set_gen_ie(priv, sme->ie, sme->ie_len);
1202
1203 if (sme->key) {
Amitkumar Karware6faada2011-07-07 17:33:19 -07001204 if (mwifiex_is_alg_wep(priv->sec_info.encryption_mode)) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001205 dev_dbg(priv->adapter->dev,
1206 "info: setting wep encryption"
1207 " with key len %d\n", sme->key_len);
Amitkumar Karwar6670f152012-02-09 18:32:22 -08001208 priv->wep_key_curr_index = sme->key_idx;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001209 ret = mwifiex_set_encode(priv, sme->key, sme->key_len,
Avinash Patil75edd2c2012-05-08 18:30:18 -07001210 sme->key_idx, NULL, 0);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001211 }
1212 }
1213done:
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001214 /*
1215 * Scan entries are valid for some time (15 sec). So we can save one
1216 * active scan time if we just try cfg80211_get_bss first. If it fails
1217 * then request scan and cfg80211_get_bss() again for final output.
1218 */
1219 while (1) {
1220 if (is_scanning_required) {
1221 /* Do specific SSID scanning */
1222 if (mwifiex_request_scan(priv, &req_ssid)) {
1223 dev_err(priv->adapter->dev, "scan error\n");
1224 return -EFAULT;
1225 }
1226 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001227
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001228 /* Find the BSS we want using available scan results */
1229 if (mode == NL80211_IFTYPE_ADHOC)
1230 bss = cfg80211_get_bss(priv->wdev->wiphy, channel,
1231 bssid, ssid, ssid_len,
1232 WLAN_CAPABILITY_IBSS,
1233 WLAN_CAPABILITY_IBSS);
1234 else
1235 bss = cfg80211_get_bss(priv->wdev->wiphy, channel,
1236 bssid, ssid, ssid_len,
1237 WLAN_CAPABILITY_ESS,
1238 WLAN_CAPABILITY_ESS);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001239
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001240 if (!bss) {
1241 if (is_scanning_required) {
Yogesh Ashok Powaraea07012012-03-13 19:22:35 -07001242 dev_warn(priv->adapter->dev,
1243 "assoc: requested bss not found in scan results\n");
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001244 break;
1245 }
1246 is_scanning_required = 1;
1247 } else {
Yogesh Ashok Powaraea07012012-03-13 19:22:35 -07001248 dev_dbg(priv->adapter->dev,
1249 "info: trying to associate to '%s' bssid %pM\n",
1250 (char *) req_ssid.ssid, bss->bssid);
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001251 memcpy(&priv->cfg_bssid, bss->bssid, ETH_ALEN);
1252 break;
1253 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001254 }
1255
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001256 if (mwifiex_bss_start(priv, bss, &req_ssid))
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001257 return -EFAULT;
1258
Bing Zhaoeecd8252011-03-28 17:55:41 -07001259 if (mode == NL80211_IFTYPE_ADHOC) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001260 /* Inform the BSS information to kernel, otherwise
1261 * kernel will give a panic after successful assoc */
1262 if (mwifiex_cfg80211_inform_ibss_bss(priv))
1263 return -EFAULT;
1264 }
1265
1266 return ret;
1267}
1268
1269/*
1270 * CFG802.11 operation handler for association request.
1271 *
1272 * This function does not work when the current mode is set to Ad-Hoc, or
1273 * when there is already an association procedure going on. The given BSS
1274 * information is used to associate.
1275 */
1276static int
1277mwifiex_cfg80211_connect(struct wiphy *wiphy, struct net_device *dev,
1278 struct cfg80211_connect_params *sme)
1279{
1280 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
1281 int ret = 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001282
Bing Zhaoeecd8252011-03-28 17:55:41 -07001283 if (priv->bss_mode == NL80211_IFTYPE_ADHOC) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001284 wiphy_err(wiphy, "received infra assoc request "
1285 "when station is in ibss mode\n");
1286 goto done;
1287 }
1288
Avinash Patile5686342012-05-08 18:30:25 -07001289 if (priv->bss_mode == NL80211_IFTYPE_AP) {
1290 wiphy_err(wiphy, "skip association request for AP interface\n");
1291 goto done;
1292 }
1293
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001294 wiphy_dbg(wiphy, "info: Trying to associate to %s and bssid %pM\n",
Yogesh Ashok Powaraea07012012-03-13 19:22:35 -07001295 (char *) sme->ssid, sme->bssid);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001296
1297 ret = mwifiex_cfg80211_assoc(priv, sme->ssid_len, sme->ssid, sme->bssid,
Bing Zhaoeecd8252011-03-28 17:55:41 -07001298 priv->bss_mode, sme->channel, sme, 0);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001299done:
Amitkumar Karwar38c9d662011-12-13 20:43:17 -08001300 if (!ret) {
1301 cfg80211_connect_result(priv->netdev, priv->cfg_bssid, NULL, 0,
1302 NULL, 0, WLAN_STATUS_SUCCESS,
1303 GFP_KERNEL);
1304 dev_dbg(priv->adapter->dev,
1305 "info: associated to bssid %pM successfully\n",
1306 priv->cfg_bssid);
1307 } else {
1308 dev_dbg(priv->adapter->dev,
1309 "info: association to bssid %pM failed\n",
1310 priv->cfg_bssid);
1311 memset(priv->cfg_bssid, 0, ETH_ALEN);
1312 }
1313
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001314 return ret;
1315}
1316
1317/*
Amitkumar Karwar05910f42012-07-13 20:09:32 -07001318 * This function sets following parameters for ibss network.
1319 * - channel
1320 * - start band
1321 * - 11n flag
1322 * - secondary channel offset
1323 */
1324static int mwifiex_set_ibss_params(struct mwifiex_private *priv,
1325 struct cfg80211_ibss_params *params)
1326{
1327 struct wiphy *wiphy = priv->wdev->wiphy;
1328 struct mwifiex_adapter *adapter = priv->adapter;
1329 int index = 0, i;
1330 u8 config_bands = 0;
1331
1332 if (params->channel->band == IEEE80211_BAND_2GHZ) {
1333 if (!params->basic_rates) {
1334 config_bands = BAND_B | BAND_G;
1335 } else {
1336 for (i = 0; i < mwifiex_band_2ghz.n_bitrates; i++) {
1337 /*
1338 * Rates below 6 Mbps in the table are CCK
1339 * rates; 802.11b and from 6 they are OFDM;
1340 * 802.11G
1341 */
1342 if (mwifiex_rates[i].bitrate == 60) {
1343 index = 1 << i;
1344 break;
1345 }
1346 }
1347
1348 if (params->basic_rates < index) {
1349 config_bands = BAND_B;
1350 } else {
1351 config_bands = BAND_G;
1352 if (params->basic_rates % index)
1353 config_bands |= BAND_B;
1354 }
1355 }
1356
1357 if (params->channel_type != NL80211_CHAN_NO_HT)
1358 config_bands |= BAND_GN;
1359 } else {
1360 if (params->channel_type == NL80211_CHAN_NO_HT)
1361 config_bands = BAND_A;
1362 else
1363 config_bands = BAND_AN | BAND_A;
1364 }
1365
1366 if (!((config_bands | adapter->fw_bands) & ~adapter->fw_bands)) {
1367 adapter->config_bands = config_bands;
1368 adapter->adhoc_start_band = config_bands;
1369
1370 if ((config_bands & BAND_GN) || (config_bands & BAND_AN))
1371 adapter->adhoc_11n_enabled = true;
1372 else
1373 adapter->adhoc_11n_enabled = false;
1374 }
1375
1376 adapter->sec_chan_offset =
1377 mwifiex_chan_type_to_sec_chan_offset(params->channel_type);
1378 priv->adhoc_channel =
1379 ieee80211_frequency_to_channel(params->channel->center_freq);
1380
1381 wiphy_dbg(wiphy, "info: set ibss band %d, chan %d, chan offset %d\n",
1382 config_bands, priv->adhoc_channel, adapter->sec_chan_offset);
1383
1384 return 0;
1385}
1386
1387/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001388 * CFG802.11 operation handler to join an IBSS.
1389 *
1390 * This function does not work in any mode other than Ad-Hoc, or if
1391 * a join operation is already in progress.
1392 */
1393static int
1394mwifiex_cfg80211_join_ibss(struct wiphy *wiphy, struct net_device *dev,
1395 struct cfg80211_ibss_params *params)
1396{
Yogesh Ashok Powarf540f9f2012-01-11 20:06:12 -08001397 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001398 int ret = 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001399
Bing Zhaoeecd8252011-03-28 17:55:41 -07001400 if (priv->bss_mode != NL80211_IFTYPE_ADHOC) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001401 wiphy_err(wiphy, "request to join ibss received "
1402 "when station is not in ibss mode\n");
1403 goto done;
1404 }
1405
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001406 wiphy_dbg(wiphy, "info: trying to join to %s and bssid %pM\n",
Yogesh Ashok Powaraea07012012-03-13 19:22:35 -07001407 (char *) params->ssid, params->bssid);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001408
Amitkumar Karwar05910f42012-07-13 20:09:32 -07001409 mwifiex_set_ibss_params(priv, params);
1410
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001411 ret = mwifiex_cfg80211_assoc(priv, params->ssid_len, params->ssid,
Yogesh Ashok Powaraea07012012-03-13 19:22:35 -07001412 params->bssid, priv->bss_mode,
1413 params->channel, NULL, params->privacy);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001414done:
Amitkumar Karwar38c9d662011-12-13 20:43:17 -08001415 if (!ret) {
1416 cfg80211_ibss_joined(priv->netdev, priv->cfg_bssid, GFP_KERNEL);
1417 dev_dbg(priv->adapter->dev,
1418 "info: joined/created adhoc network with bssid"
1419 " %pM successfully\n", priv->cfg_bssid);
1420 } else {
1421 dev_dbg(priv->adapter->dev,
1422 "info: failed creating/joining adhoc network\n");
1423 }
1424
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001425 return ret;
1426}
1427
1428/*
1429 * CFG802.11 operation handler to leave an IBSS.
1430 *
1431 * This function does not work if a leave operation is
1432 * already in progress.
1433 */
1434static int
1435mwifiex_cfg80211_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
1436{
Yogesh Ashok Powarf540f9f2012-01-11 20:06:12 -08001437 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001438
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001439 wiphy_dbg(wiphy, "info: disconnecting from essid %pM\n",
Yogesh Ashok Powaraea07012012-03-13 19:22:35 -07001440 priv->cfg_bssid);
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001441 if (mwifiex_deauthenticate(priv, NULL))
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001442 return -EFAULT;
1443
Amitkumar Karwar38c9d662011-12-13 20:43:17 -08001444 memset(priv->cfg_bssid, 0, ETH_ALEN);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001445
1446 return 0;
1447}
1448
1449/*
1450 * CFG802.11 operation handler for scan request.
1451 *
1452 * This function issues a scan request to the firmware based upon
1453 * the user specified scan configuration. On successfull completion,
1454 * it also informs the results.
1455 */
1456static int
Johannes Bergfd014282012-06-18 19:17:03 +02001457mwifiex_cfg80211_scan(struct wiphy *wiphy,
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001458 struct cfg80211_scan_request *request)
1459{
Johannes Bergfd014282012-06-18 19:17:03 +02001460 struct net_device *dev = request->wdev->netdev;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001461 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
Amitkumar Karwar38c9d662011-12-13 20:43:17 -08001462 int i;
1463 struct ieee80211_channel *chan;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001464
1465 wiphy_dbg(wiphy, "info: received scan request on %s\n", dev->name);
1466
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001467 priv->scan_request = request;
1468
Amitkumar Karwar38c9d662011-12-13 20:43:17 -08001469 priv->user_scan_cfg = kzalloc(sizeof(struct mwifiex_user_scan_cfg),
Yogesh Ashok Powaraea07012012-03-13 19:22:35 -07001470 GFP_KERNEL);
Amitkumar Karwar38c9d662011-12-13 20:43:17 -08001471 if (!priv->user_scan_cfg) {
1472 dev_err(priv->adapter->dev, "failed to alloc scan_req\n");
1473 return -ENOMEM;
1474 }
Amitkumar Karwarbe0b2812012-02-27 22:04:15 -08001475
1476 priv->user_scan_cfg->num_ssids = request->n_ssids;
1477 priv->user_scan_cfg->ssid_list = request->ssids;
1478
Avinash Patil13d7ba782012-04-09 20:06:56 -07001479 if (request->ie && request->ie_len) {
1480 for (i = 0; i < MWIFIEX_MAX_VSIE_NUM; i++) {
1481 if (priv->vs_ie[i].mask != MWIFIEX_VSIE_MASK_CLEAR)
1482 continue;
1483 priv->vs_ie[i].mask = MWIFIEX_VSIE_MASK_SCAN;
1484 memcpy(&priv->vs_ie[i].ie, request->ie,
1485 request->ie_len);
1486 break;
1487 }
1488 }
1489
Amitkumar Karwar38c9d662011-12-13 20:43:17 -08001490 for (i = 0; i < request->n_channels; i++) {
1491 chan = request->channels[i];
1492 priv->user_scan_cfg->chan_list[i].chan_number = chan->hw_value;
1493 priv->user_scan_cfg->chan_list[i].radio_type = chan->band;
1494
1495 if (chan->flags & IEEE80211_CHAN_PASSIVE_SCAN)
1496 priv->user_scan_cfg->chan_list[i].scan_type =
Yogesh Ashok Powaraea07012012-03-13 19:22:35 -07001497 MWIFIEX_SCAN_TYPE_PASSIVE;
Amitkumar Karwar38c9d662011-12-13 20:43:17 -08001498 else
1499 priv->user_scan_cfg->chan_list[i].scan_type =
Yogesh Ashok Powaraea07012012-03-13 19:22:35 -07001500 MWIFIEX_SCAN_TYPE_ACTIVE;
Amitkumar Karwar38c9d662011-12-13 20:43:17 -08001501
1502 priv->user_scan_cfg->chan_list[i].scan_time = 0;
1503 }
Amitkumar Karwar1a1fb972012-06-27 19:57:56 -07001504 if (mwifiex_scan_networks(priv, priv->user_scan_cfg))
Amitkumar Karwar38c9d662011-12-13 20:43:17 -08001505 return -EFAULT;
1506
Avinash Patil13d7ba782012-04-09 20:06:56 -07001507 if (request->ie && request->ie_len) {
1508 for (i = 0; i < MWIFIEX_MAX_VSIE_NUM; i++) {
1509 if (priv->vs_ie[i].mask == MWIFIEX_VSIE_MASK_SCAN) {
1510 priv->vs_ie[i].mask = MWIFIEX_VSIE_MASK_CLEAR;
1511 memset(&priv->vs_ie[i].ie, 0,
1512 MWIFIEX_MAX_VSIE_LEN);
1513 }
1514 }
1515 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001516 return 0;
1517}
1518
1519/*
1520 * This function sets up the CFG802.11 specific HT capability fields
1521 * with default values.
1522 *
1523 * The following default values are set -
1524 * - HT Supported = True
Amitkumar Karwara46b7b52011-04-27 19:13:12 -07001525 * - Maximum AMPDU length factor = IEEE80211_HT_MAX_AMPDU_64K
1526 * - Minimum AMPDU spacing = IEEE80211_HT_MPDU_DENSITY_NONE
1527 * - HT Capabilities supported by firmware
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001528 * - MCS information, Rx mask = 0xff
1529 * - MCD information, Tx parameters = IEEE80211_HT_MCS_TX_DEFINED (0x01)
1530 */
1531static void
1532mwifiex_setup_ht_caps(struct ieee80211_sta_ht_cap *ht_info,
1533 struct mwifiex_private *priv)
1534{
1535 int rx_mcs_supp;
1536 struct ieee80211_mcs_info mcs_set;
1537 u8 *mcs = (u8 *)&mcs_set;
1538 struct mwifiex_adapter *adapter = priv->adapter;
1539
1540 ht_info->ht_supported = true;
Amitkumar Karwara46b7b52011-04-27 19:13:12 -07001541 ht_info->ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
1542 ht_info->ampdu_density = IEEE80211_HT_MPDU_DENSITY_NONE;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001543
1544 memset(&ht_info->mcs, 0, sizeof(ht_info->mcs));
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001545
Amitkumar Karwara46b7b52011-04-27 19:13:12 -07001546 /* Fill HT capability information */
1547 if (ISSUPP_CHANWIDTH40(adapter->hw_dot_11n_dev_cap))
1548 ht_info->cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
1549 else
1550 ht_info->cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
1551
1552 if (ISSUPP_SHORTGI20(adapter->hw_dot_11n_dev_cap))
1553 ht_info->cap |= IEEE80211_HT_CAP_SGI_20;
1554 else
1555 ht_info->cap &= ~IEEE80211_HT_CAP_SGI_20;
1556
1557 if (ISSUPP_SHORTGI40(adapter->hw_dot_11n_dev_cap))
1558 ht_info->cap |= IEEE80211_HT_CAP_SGI_40;
1559 else
1560 ht_info->cap &= ~IEEE80211_HT_CAP_SGI_40;
1561
1562 if (ISSUPP_RXSTBC(adapter->hw_dot_11n_dev_cap))
1563 ht_info->cap |= 1 << IEEE80211_HT_CAP_RX_STBC_SHIFT;
1564 else
1565 ht_info->cap &= ~(3 << IEEE80211_HT_CAP_RX_STBC_SHIFT);
1566
1567 if (ISSUPP_TXSTBC(adapter->hw_dot_11n_dev_cap))
1568 ht_info->cap |= IEEE80211_HT_CAP_TX_STBC;
1569 else
1570 ht_info->cap &= ~IEEE80211_HT_CAP_TX_STBC;
1571
1572 ht_info->cap &= ~IEEE80211_HT_CAP_MAX_AMSDU;
1573 ht_info->cap |= IEEE80211_HT_CAP_SM_PS;
1574
1575 rx_mcs_supp = GET_RXMCSSUPP(adapter->hw_dev_mcs_support);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001576 /* Set MCS for 1x1 */
1577 memset(mcs, 0xff, rx_mcs_supp);
1578 /* Clear all the other values */
1579 memset(&mcs[rx_mcs_supp], 0,
Yogesh Ashok Powaraea07012012-03-13 19:22:35 -07001580 sizeof(struct ieee80211_mcs_info) - rx_mcs_supp);
Bing Zhaoeecd8252011-03-28 17:55:41 -07001581 if (priv->bss_mode == NL80211_IFTYPE_STATION ||
Yogesh Ashok Powaraea07012012-03-13 19:22:35 -07001582 ISSUPP_CHANWIDTH40(adapter->hw_dot_11n_dev_cap))
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001583 /* Set MCS32 for infra mode or ad-hoc mode with 40MHz support */
1584 SETHT_MCS32(mcs_set.rx_mask);
1585
1586 memcpy((u8 *) &ht_info->mcs, mcs, sizeof(struct ieee80211_mcs_info));
1587
1588 ht_info->mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED;
1589}
1590
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -07001591/*
1592 * create a new virtual interface with the given name
1593 */
Johannes Berg84efbb82012-06-16 00:00:26 +02001594struct wireless_dev *mwifiex_add_virtual_intf(struct wiphy *wiphy,
1595 char *name,
1596 enum nl80211_iftype type,
1597 u32 *flags,
1598 struct vif_params *params)
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -07001599{
Avinash Patil67fdf392012-05-08 18:30:17 -07001600 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
1601 struct mwifiex_private *priv;
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -07001602 struct net_device *dev;
1603 void *mdev_priv;
Avinash Patild6bffe82012-05-08 18:30:15 -07001604 struct wireless_dev *wdev;
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -07001605
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -07001606 if (!adapter)
Bing Zhao858faa52012-06-15 15:49:54 -07001607 return ERR_PTR(-EFAULT);
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -07001608
1609 switch (type) {
1610 case NL80211_IFTYPE_UNSPECIFIED:
1611 case NL80211_IFTYPE_STATION:
1612 case NL80211_IFTYPE_ADHOC:
Avinash Patild6bffe82012-05-08 18:30:15 -07001613 priv = adapter->priv[MWIFIEX_BSS_TYPE_STA];
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -07001614 if (priv->bss_mode) {
Avinash Patild6bffe82012-05-08 18:30:15 -07001615 wiphy_err(wiphy,
1616 "cannot create multiple sta/adhoc ifaces\n");
Bing Zhao858faa52012-06-15 15:49:54 -07001617 return ERR_PTR(-EINVAL);
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -07001618 }
1619
Avinash Patild6bffe82012-05-08 18:30:15 -07001620 wdev = kzalloc(sizeof(struct wireless_dev), GFP_KERNEL);
1621 if (!wdev)
Bing Zhao858faa52012-06-15 15:49:54 -07001622 return ERR_PTR(-ENOMEM);
Avinash Patild6bffe82012-05-08 18:30:15 -07001623
1624 wdev->wiphy = wiphy;
1625 priv->wdev = wdev;
1626 wdev->iftype = NL80211_IFTYPE_STATION;
1627
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -07001628 if (type == NL80211_IFTYPE_UNSPECIFIED)
1629 priv->bss_mode = NL80211_IFTYPE_STATION;
1630 else
1631 priv->bss_mode = type;
1632
1633 priv->bss_type = MWIFIEX_BSS_TYPE_STA;
1634 priv->frame_type = MWIFIEX_DATA_FRAME_TYPE_ETH_II;
Avinash Patild6bffe82012-05-08 18:30:15 -07001635 priv->bss_priority = MWIFIEX_BSS_ROLE_STA;
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -07001636 priv->bss_role = MWIFIEX_BSS_ROLE_STA;
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -07001637 priv->bss_num = 0;
1638
1639 break;
Avinash Patild6bffe82012-05-08 18:30:15 -07001640 case NL80211_IFTYPE_AP:
1641 priv = adapter->priv[MWIFIEX_BSS_TYPE_UAP];
1642
1643 if (priv->bss_mode) {
1644 wiphy_err(wiphy, "Can't create multiple AP interfaces");
Bing Zhao858faa52012-06-15 15:49:54 -07001645 return ERR_PTR(-EINVAL);
Avinash Patild6bffe82012-05-08 18:30:15 -07001646 }
1647
1648 wdev = kzalloc(sizeof(struct wireless_dev), GFP_KERNEL);
1649 if (!wdev)
Bing Zhao858faa52012-06-15 15:49:54 -07001650 return ERR_PTR(-ENOMEM);
Avinash Patild6bffe82012-05-08 18:30:15 -07001651
1652 priv->wdev = wdev;
1653 wdev->wiphy = wiphy;
1654 wdev->iftype = NL80211_IFTYPE_AP;
1655
1656 priv->bss_type = MWIFIEX_BSS_TYPE_UAP;
1657 priv->frame_type = MWIFIEX_DATA_FRAME_TYPE_ETH_II;
1658 priv->bss_priority = MWIFIEX_BSS_ROLE_UAP;
1659 priv->bss_role = MWIFIEX_BSS_ROLE_UAP;
1660 priv->bss_started = 0;
1661 priv->bss_num = 0;
1662 priv->bss_mode = type;
1663
1664 break;
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -07001665 default:
1666 wiphy_err(wiphy, "type not supported\n");
Bing Zhao858faa52012-06-15 15:49:54 -07001667 return ERR_PTR(-EINVAL);
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -07001668 }
1669
1670 dev = alloc_netdev_mq(sizeof(struct mwifiex_private *), name,
1671 ether_setup, 1);
1672 if (!dev) {
1673 wiphy_err(wiphy, "no memory available for netdevice\n");
Bing Zhao858faa52012-06-15 15:49:54 -07001674 priv->bss_mode = NL80211_IFTYPE_UNSPECIFIED;
1675 return ERR_PTR(-ENOMEM);
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -07001676 }
1677
Avinash Patild6bffe82012-05-08 18:30:15 -07001678 mwifiex_init_priv_params(priv, dev);
1679 priv->netdev = dev;
1680
1681 mwifiex_setup_ht_caps(&wiphy->bands[IEEE80211_BAND_2GHZ]->ht_cap, priv);
1682
1683 if (adapter->config_bands & BAND_A)
1684 mwifiex_setup_ht_caps(
1685 &wiphy->bands[IEEE80211_BAND_5GHZ]->ht_cap, priv);
1686
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -07001687 dev_net_set(dev, wiphy_net(wiphy));
1688 dev->ieee80211_ptr = priv->wdev;
1689 dev->ieee80211_ptr->iftype = priv->bss_mode;
1690 memcpy(dev->dev_addr, wiphy->perm_addr, ETH_ALEN);
1691 memcpy(dev->perm_addr, wiphy->perm_addr, ETH_ALEN);
1692 SET_NETDEV_DEV(dev, wiphy_dev(wiphy));
1693
1694 dev->flags |= IFF_BROADCAST | IFF_MULTICAST;
1695 dev->watchdog_timeo = MWIFIEX_DEFAULT_WATCHDOG_TIMEOUT;
1696 dev->hard_header_len += MWIFIEX_MIN_DATA_HEADER_LEN;
1697
1698 mdev_priv = netdev_priv(dev);
1699 *((unsigned long *) mdev_priv) = (unsigned long) priv;
1700
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -07001701 SET_NETDEV_DEV(dev, adapter->dev);
1702
1703 /* Register network device */
1704 if (register_netdevice(dev)) {
1705 wiphy_err(wiphy, "cannot register virtual network device\n");
Bing Zhao858faa52012-06-15 15:49:54 -07001706 free_netdev(dev);
1707 priv->bss_mode = NL80211_IFTYPE_UNSPECIFIED;
1708 return ERR_PTR(-EFAULT);
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -07001709 }
1710
1711 sema_init(&priv->async_sem, 1);
1712 priv->scan_pending_on_block = false;
1713
1714 dev_dbg(adapter->dev, "info: %s: Marvell 802.11 Adapter\n", dev->name);
1715
1716#ifdef CONFIG_DEBUG_FS
1717 mwifiex_dev_debugfs_init(priv);
1718#endif
Johannes Berg84efbb82012-06-16 00:00:26 +02001719 return wdev;
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -07001720}
1721EXPORT_SYMBOL_GPL(mwifiex_add_virtual_intf);
1722
1723/*
1724 * del_virtual_intf: remove the virtual interface determined by dev
1725 */
Johannes Berg84efbb82012-06-16 00:00:26 +02001726int mwifiex_del_virtual_intf(struct wiphy *wiphy, struct wireless_dev *wdev)
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -07001727{
Johannes Berg84efbb82012-06-16 00:00:26 +02001728 struct mwifiex_private *priv = mwifiex_netdev_get_priv(wdev->netdev);
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -07001729
1730#ifdef CONFIG_DEBUG_FS
1731 mwifiex_dev_debugfs_remove(priv);
1732#endif
1733
1734 if (!netif_queue_stopped(priv->netdev))
1735 netif_stop_queue(priv->netdev);
1736
1737 if (netif_carrier_ok(priv->netdev))
1738 netif_carrier_off(priv->netdev);
1739
Johannes Berg84efbb82012-06-16 00:00:26 +02001740 if (wdev->netdev->reg_state == NETREG_REGISTERED)
1741 unregister_netdevice(wdev->netdev);
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -07001742
Johannes Berg84efbb82012-06-16 00:00:26 +02001743 if (wdev->netdev->reg_state == NETREG_UNREGISTERED)
1744 free_netdev(wdev->netdev);
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -07001745
1746 /* Clear the priv in adapter */
1747 priv->netdev = NULL;
1748
1749 priv->media_connected = false;
1750
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -07001751 priv->bss_mode = NL80211_IFTYPE_UNSPECIFIED;
1752
1753 return 0;
1754}
1755EXPORT_SYMBOL_GPL(mwifiex_del_virtual_intf);
1756
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001757/* station cfg80211 operations */
1758static struct cfg80211_ops mwifiex_cfg80211_ops = {
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -07001759 .add_virtual_intf = mwifiex_add_virtual_intf,
1760 .del_virtual_intf = mwifiex_del_virtual_intf,
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001761 .change_virtual_intf = mwifiex_cfg80211_change_virtual_intf,
1762 .scan = mwifiex_cfg80211_scan,
1763 .connect = mwifiex_cfg80211_connect,
1764 .disconnect = mwifiex_cfg80211_disconnect,
1765 .get_station = mwifiex_cfg80211_get_station,
Amitkumar Karwarf85aae62012-03-15 20:51:48 -07001766 .dump_station = mwifiex_cfg80211_dump_station,
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001767 .set_wiphy_params = mwifiex_cfg80211_set_wiphy_params,
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001768 .join_ibss = mwifiex_cfg80211_join_ibss,
1769 .leave_ibss = mwifiex_cfg80211_leave_ibss,
1770 .add_key = mwifiex_cfg80211_add_key,
1771 .del_key = mwifiex_cfg80211_del_key,
1772 .set_default_key = mwifiex_cfg80211_set_default_key,
1773 .set_power_mgmt = mwifiex_cfg80211_set_power_mgmt,
1774 .set_tx_power = mwifiex_cfg80211_set_tx_power,
Yogesh Ashok Powar5d82c532011-07-11 20:04:44 -07001775 .set_bitrate_mask = mwifiex_cfg80211_set_bitrate_mask,
Avinash Patil12190c52012-05-08 18:30:24 -07001776 .start_ap = mwifiex_cfg80211_start_ap,
1777 .stop_ap = mwifiex_cfg80211_stop_ap,
Avinash Patil5370c832012-06-28 20:30:28 -07001778 .change_beacon = mwifiex_cfg80211_change_beacon,
Amitkumar Karwarfa444bf2012-03-15 20:51:51 -07001779 .set_cqm_rssi_config = mwifiex_cfg80211_set_cqm_rssi_config,
Amitkumar Karwar8a279d52012-07-02 19:32:33 -07001780 .set_antenna = mwifiex_cfg80211_set_antenna,
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001781};
1782
1783/*
1784 * This function registers the device with CFG802.11 subsystem.
1785 *
1786 * The function creates the wireless device/wiphy, populates it with
1787 * default parameters and handler function pointers, and finally
1788 * registers the device.
1789 */
Avinash Patild6bffe82012-05-08 18:30:15 -07001790
1791int mwifiex_register_cfg80211(struct mwifiex_adapter *adapter)
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001792{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -07001793 int ret;
1794 void *wdev_priv;
Avinash Patild6bffe82012-05-08 18:30:15 -07001795 struct wiphy *wiphy;
1796 struct mwifiex_private *priv = adapter->priv[MWIFIEX_BSS_TYPE_STA];
Amitkumar Karwar9e04a7c2012-04-09 20:06:54 -07001797 u8 *country_code;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001798
Avinash Patild6bffe82012-05-08 18:30:15 -07001799 /* create a new wiphy for use with cfg80211 */
1800 wiphy = wiphy_new(&mwifiex_cfg80211_ops,
1801 sizeof(struct mwifiex_adapter *));
1802 if (!wiphy) {
1803 dev_err(adapter->dev, "%s: creating new wiphy\n", __func__);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001804 return -ENOMEM;
1805 }
Avinash Patild6bffe82012-05-08 18:30:15 -07001806 wiphy->max_scan_ssids = MWIFIEX_MAX_SSID_LIST_LENGTH;
1807 wiphy->max_scan_ie_len = MWIFIEX_MAX_VSIE_LEN;
1808 wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
1809 BIT(NL80211_IFTYPE_ADHOC) |
1810 BIT(NL80211_IFTYPE_AP);
Amitkumar Karwaradc89592011-04-27 19:13:11 -07001811
Avinash Patild6bffe82012-05-08 18:30:15 -07001812 wiphy->bands[IEEE80211_BAND_2GHZ] = &mwifiex_band_2ghz;
1813 if (adapter->config_bands & BAND_A)
1814 wiphy->bands[IEEE80211_BAND_5GHZ] = &mwifiex_band_5ghz;
1815 else
1816 wiphy->bands[IEEE80211_BAND_5GHZ] = NULL;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001817
Avinash Patilcd8440d2012-05-08 18:30:16 -07001818 wiphy->iface_combinations = &mwifiex_iface_comb_ap_sta;
1819 wiphy->n_iface_combinations = 1;
1820
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001821 /* Initialize cipher suits */
Avinash Patild6bffe82012-05-08 18:30:15 -07001822 wiphy->cipher_suites = mwifiex_cipher_suites;
1823 wiphy->n_cipher_suites = ARRAY_SIZE(mwifiex_cipher_suites);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001824
Avinash Patild6bffe82012-05-08 18:30:15 -07001825 memcpy(wiphy->perm_addr, priv->curr_addr, ETH_ALEN);
1826 wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
Avinash Patil2dd2bd62012-06-28 20:30:29 -07001827 wiphy->flags |= WIPHY_FLAG_HAVE_AP_SME |
1828 WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD;
1829
1830 wiphy->probe_resp_offload = NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS |
1831 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001832
Amitkumar Karwar8a279d52012-07-02 19:32:33 -07001833 wiphy->available_antennas_tx = BIT(adapter->number_of_antenna) - 1;
1834 wiphy->available_antennas_rx = BIT(adapter->number_of_antenna) - 1;
1835
Amitkumar Karwar05910f42012-07-13 20:09:32 -07001836 wiphy->features = NL80211_FEATURE_HT_IBSS;
1837
Amitkumar Karwarb5abcf02012-04-16 21:36:52 -07001838 /* Reserve space for mwifiex specific private data for BSS */
Avinash Patild6bffe82012-05-08 18:30:15 -07001839 wiphy->bss_priv_size = sizeof(struct mwifiex_bss_priv);
Amitkumar Karwar5116f3c2011-09-21 21:43:23 -07001840
Avinash Patild6bffe82012-05-08 18:30:15 -07001841 wiphy->reg_notifier = mwifiex_reg_notifier;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001842
Avinash Patil67fdf392012-05-08 18:30:17 -07001843 /* Set struct mwifiex_adapter pointer in wiphy_priv */
Avinash Patild6bffe82012-05-08 18:30:15 -07001844 wdev_priv = wiphy_priv(wiphy);
Avinash Patil67fdf392012-05-08 18:30:17 -07001845 *(unsigned long *)wdev_priv = (unsigned long)adapter;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001846
Avinash Patild6bffe82012-05-08 18:30:15 -07001847 set_wiphy_dev(wiphy, (struct device *)priv->adapter->dev);
Yogesh Ashok Powara7b21162011-06-13 09:49:27 +05301848
Avinash Patild6bffe82012-05-08 18:30:15 -07001849 ret = wiphy_register(wiphy);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001850 if (ret < 0) {
Avinash Patild6bffe82012-05-08 18:30:15 -07001851 dev_err(adapter->dev,
1852 "%s: wiphy_register failed: %d\n", __func__, ret);
1853 wiphy_free(wiphy);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001854 return ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001855 }
Amitkumar Karwar9e04a7c2012-04-09 20:06:54 -07001856 country_code = mwifiex_11d_code_2_region(priv->adapter->region_code);
Avinash Patild6bffe82012-05-08 18:30:15 -07001857 if (country_code && regulatory_hint(wiphy, country_code))
1858 dev_err(adapter->dev, "regulatory_hint() failed\n");
Amitkumar Karwar9e04a7c2012-04-09 20:06:54 -07001859
Avinash Patild6bffe82012-05-08 18:30:15 -07001860 adapter->wiphy = wiphy;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001861 return ret;
1862}