blob: 11942e5e33cf5745e8c32dfa4e9f559a18209890 [file] [log] [blame]
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001/*
2 * Marvell Wireless LAN device driver: CFG80211
3 *
4 * Copyright (C) 2011, Marvell International Ltd.
5 *
6 * This software file (the "File") is distributed by Marvell International
7 * Ltd. under the terms of the GNU General Public License Version 2, June 1991
8 * (the "License"). You may use, redistribute and/or modify this File in
9 * accordance with the terms and conditions of the License, a copy of which
10 * is available by writing to the Free Software Foundation, Inc.,
11 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA or on the
12 * worldwide web at http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
13 *
14 * THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE
16 * ARE EXPRESSLY DISCLAIMED. The License provides additional details about
17 * this warranty disclaimer.
18 */
19
20#include "cfg80211.h"
21#include "main.h"
22
Avinash Patilcd8440d2012-05-08 18:30:16 -070023static const struct ieee80211_iface_limit mwifiex_ap_sta_limits[] = {
24 {
25 .max = 1, .types = BIT(NL80211_IFTYPE_STATION),
26 },
27 {
28 .max = 1, .types = BIT(NL80211_IFTYPE_AP),
29 },
30};
31
32static const struct ieee80211_iface_combination mwifiex_iface_comb_ap_sta = {
33 .limits = mwifiex_ap_sta_limits,
34 .num_different_channels = 1,
35 .n_limits = ARRAY_SIZE(mwifiex_ap_sta_limits),
36 .max_interfaces = MWIFIEX_MAX_BSS_NUM,
37 .beacon_int_infra_match = true,
38};
39
Amitkumar Karwarcc0ba0d2012-09-10 18:30:47 -070040static const struct ieee80211_regdomain mwifiex_world_regdom_custom = {
41 .n_reg_rules = 7,
42 .alpha2 = "99",
43 .reg_rules = {
44 /* Channel 1 - 11 */
45 REG_RULE(2412-10, 2462+10, 40, 3, 20, 0),
46 /* Channel 12 - 13 */
47 REG_RULE(2467-10, 2472+10, 20, 3, 20,
48 NL80211_RRF_PASSIVE_SCAN | NL80211_RRF_NO_IBSS),
49 /* Channel 14 */
50 REG_RULE(2484-10, 2484+10, 20, 3, 20,
51 NL80211_RRF_PASSIVE_SCAN | NL80211_RRF_NO_IBSS |
52 NL80211_RRF_NO_OFDM),
53 /* Channel 36 - 48 */
54 REG_RULE(5180-10, 5240+10, 40, 3, 20,
55 NL80211_RRF_PASSIVE_SCAN | NL80211_RRF_NO_IBSS),
56 /* Channel 149 - 165 */
57 REG_RULE(5745-10, 5825+10, 40, 3, 20,
58 NL80211_RRF_PASSIVE_SCAN | NL80211_RRF_NO_IBSS),
59 /* Channel 52 - 64 */
60 REG_RULE(5260-10, 5320+10, 40, 3, 30,
61 NL80211_RRF_PASSIVE_SCAN | NL80211_RRF_NO_IBSS |
62 NL80211_RRF_DFS),
63 /* Channel 100 - 140 */
64 REG_RULE(5500-10, 5700+10, 40, 3, 30,
65 NL80211_RRF_PASSIVE_SCAN | NL80211_RRF_NO_IBSS |
66 NL80211_RRF_DFS),
67 }
68};
69
Bing Zhao5e6e3a92011-03-21 18:00:50 -070070/*
71 * This function maps the nl802.11 channel type into driver channel type.
72 *
73 * The mapping is as follows -
Amitkumar Karwar21c3ba32011-12-20 23:47:21 -080074 * NL80211_CHAN_NO_HT -> IEEE80211_HT_PARAM_CHA_SEC_NONE
75 * NL80211_CHAN_HT20 -> IEEE80211_HT_PARAM_CHA_SEC_NONE
76 * NL80211_CHAN_HT40PLUS -> IEEE80211_HT_PARAM_CHA_SEC_ABOVE
77 * NL80211_CHAN_HT40MINUS -> IEEE80211_HT_PARAM_CHA_SEC_BELOW
78 * Others -> IEEE80211_HT_PARAM_CHA_SEC_NONE
Bing Zhao5e6e3a92011-03-21 18:00:50 -070079 */
Amitkumar Karwar21c3ba32011-12-20 23:47:21 -080080static u8
Amitkumar Karwar05910f42012-07-13 20:09:32 -070081mwifiex_chan_type_to_sec_chan_offset(enum nl80211_channel_type chan_type)
Bing Zhao5e6e3a92011-03-21 18:00:50 -070082{
Amitkumar Karwar05910f42012-07-13 20:09:32 -070083 switch (chan_type) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -070084 case NL80211_CHAN_NO_HT:
85 case NL80211_CHAN_HT20:
Amitkumar Karwar21c3ba32011-12-20 23:47:21 -080086 return IEEE80211_HT_PARAM_CHA_SEC_NONE;
Bing Zhao5e6e3a92011-03-21 18:00:50 -070087 case NL80211_CHAN_HT40PLUS:
Amitkumar Karwar21c3ba32011-12-20 23:47:21 -080088 return IEEE80211_HT_PARAM_CHA_SEC_ABOVE;
Bing Zhao5e6e3a92011-03-21 18:00:50 -070089 case NL80211_CHAN_HT40MINUS:
Amitkumar Karwar21c3ba32011-12-20 23:47:21 -080090 return IEEE80211_HT_PARAM_CHA_SEC_BELOW;
Bing Zhao5e6e3a92011-03-21 18:00:50 -070091 default:
Amitkumar Karwar21c3ba32011-12-20 23:47:21 -080092 return IEEE80211_HT_PARAM_CHA_SEC_NONE;
Bing Zhao5e6e3a92011-03-21 18:00:50 -070093 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -070094}
95
96/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -070097 * This function checks whether WEP is set.
98 */
99static int
100mwifiex_is_alg_wep(u32 cipher)
101{
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700102 switch (cipher) {
Yogesh Ashok Powar2be50b82011-04-01 18:36:47 -0700103 case WLAN_CIPHER_SUITE_WEP40:
104 case WLAN_CIPHER_SUITE_WEP104:
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700105 return 1;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700106 default:
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700107 break;
108 }
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700109
110 return 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700111}
112
113/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700114 * This function retrieves the private structure from kernel wiphy structure.
115 */
Avinash Patil67fdf392012-05-08 18:30:17 -0700116static void *mwifiex_cfg80211_get_adapter(struct wiphy *wiphy)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700117{
118 return (void *) (*(unsigned long *) wiphy_priv(wiphy));
119}
120
121/*
122 * CFG802.11 operation handler to delete a network key.
123 */
124static int
125mwifiex_cfg80211_del_key(struct wiphy *wiphy, struct net_device *netdev,
126 u8 key_index, bool pairwise, const u8 *mac_addr)
127{
Yogesh Ashok Powarf540f9f2012-01-11 20:06:12 -0800128 struct mwifiex_private *priv = mwifiex_netdev_get_priv(netdev);
Avinash Patil75edd2c2012-05-08 18:30:18 -0700129 const u8 bc_mac[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
130 const u8 *peer_mac = pairwise ? mac_addr : bc_mac;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700131
Ying Luo53b11232012-08-03 18:06:13 -0700132 if (mwifiex_set_encode(priv, NULL, NULL, 0, key_index, peer_mac, 1)) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700133 wiphy_err(wiphy, "deleting the crypto keys\n");
134 return -EFAULT;
135 }
136
137 wiphy_dbg(wiphy, "info: crypto keys deleted\n");
138 return 0;
139}
140
141/*
Stone Piaoe39faa72012-09-25 20:23:32 -0700142 * This function forms an skb for management frame.
143 */
144static int
145mwifiex_form_mgmt_frame(struct sk_buff *skb, const u8 *buf, size_t len)
146{
147 u8 addr[ETH_ALEN] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
148 u16 pkt_len;
149 u32 tx_control = 0, pkt_type = PKT_TYPE_MGMT;
150 struct timeval tv;
151
152 pkt_len = len + ETH_ALEN;
153
154 skb_reserve(skb, MWIFIEX_MIN_DATA_HEADER_LEN +
155 MWIFIEX_MGMT_FRAME_HEADER_SIZE + sizeof(pkt_len));
156 memcpy(skb_push(skb, sizeof(pkt_len)), &pkt_len, sizeof(pkt_len));
157
158 memcpy(skb_push(skb, sizeof(tx_control)),
159 &tx_control, sizeof(tx_control));
160
161 memcpy(skb_push(skb, sizeof(pkt_type)), &pkt_type, sizeof(pkt_type));
162
163 /* Add packet data and address4 */
164 memcpy(skb_put(skb, sizeof(struct ieee80211_hdr_3addr)), buf,
165 sizeof(struct ieee80211_hdr_3addr));
166 memcpy(skb_put(skb, ETH_ALEN), addr, ETH_ALEN);
167 memcpy(skb_put(skb, len - sizeof(struct ieee80211_hdr_3addr)),
168 buf + sizeof(struct ieee80211_hdr_3addr),
169 len - sizeof(struct ieee80211_hdr_3addr));
170
171 skb->priority = LOW_PRIO_TID;
172 do_gettimeofday(&tv);
173 skb->tstamp = timeval_to_ktime(tv);
174
175 return 0;
176}
177
178/*
179 * CFG802.11 operation handler to transmit a management frame.
180 */
181static int
182mwifiex_cfg80211_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev,
183 struct ieee80211_channel *chan, bool offchan,
184 enum nl80211_channel_type channel_type,
185 bool channel_type_valid, unsigned int wait,
186 const u8 *buf, size_t len, bool no_cck,
187 bool dont_wait_for_ack, u64 *cookie)
188{
189 struct sk_buff *skb;
190 u16 pkt_len;
191 const struct ieee80211_mgmt *mgmt;
192 struct mwifiex_private *priv = mwifiex_netdev_get_priv(wdev->netdev);
193
194 if (!buf || !len) {
195 wiphy_err(wiphy, "invalid buffer and length\n");
196 return -EFAULT;
197 }
198
199 mgmt = (const struct ieee80211_mgmt *)buf;
200 if (GET_BSS_ROLE(priv) != MWIFIEX_BSS_ROLE_STA &&
201 ieee80211_is_probe_resp(mgmt->frame_control)) {
202 /* Since we support offload probe resp, we need to skip probe
203 * resp in AP or GO mode */
204 wiphy_dbg(wiphy,
205 "info: skip to send probe resp in AP or GO mode\n");
206 return 0;
207 }
208
209 pkt_len = len + ETH_ALEN;
210 skb = dev_alloc_skb(MWIFIEX_MIN_DATA_HEADER_LEN +
211 MWIFIEX_MGMT_FRAME_HEADER_SIZE +
212 pkt_len + sizeof(pkt_len));
213
214 if (!skb) {
215 wiphy_err(wiphy, "allocate skb failed for management frame\n");
216 return -ENOMEM;
217 }
218
219 mwifiex_form_mgmt_frame(skb, buf, len);
220 mwifiex_queue_tx_pkt(priv, skb);
221
222 *cookie = random32() | 1;
223 cfg80211_mgmt_tx_status(wdev, *cookie, buf, len, true, GFP_ATOMIC);
224
225 wiphy_dbg(wiphy, "info: management frame transmitted\n");
226 return 0;
227}
228
229/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700230 * CFG802.11 operation handler to set Tx power.
231 */
232static int
233mwifiex_cfg80211_set_tx_power(struct wiphy *wiphy,
234 enum nl80211_tx_power_setting type,
Luis R. Rodriguez742c29f2011-11-28 16:38:50 -0500235 int mbm)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700236{
Avinash Patil67fdf392012-05-08 18:30:17 -0700237 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
238 struct mwifiex_private *priv;
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700239 struct mwifiex_power_cfg power_cfg;
Luis R. Rodriguez742c29f2011-11-28 16:38:50 -0500240 int dbm = MBM_TO_DBM(mbm);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700241
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700242 if (type == NL80211_TX_POWER_FIXED) {
243 power_cfg.is_power_auto = 0;
244 power_cfg.power_level = dbm;
245 } else {
246 power_cfg.is_power_auto = 1;
247 }
248
Avinash Patil67fdf392012-05-08 18:30:17 -0700249 priv = mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY);
250
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700251 return mwifiex_set_tx_power(priv, &power_cfg);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700252}
253
254/*
255 * CFG802.11 operation handler to set Power Save option.
256 *
257 * The timeout value, if provided, is currently ignored.
258 */
259static int
260mwifiex_cfg80211_set_power_mgmt(struct wiphy *wiphy,
261 struct net_device *dev,
262 bool enabled, int timeout)
263{
Yogesh Ashok Powarf540f9f2012-01-11 20:06:12 -0800264 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700265 u32 ps_mode;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700266
267 if (timeout)
268 wiphy_dbg(wiphy,
Yogesh Ashok Powaraea07012012-03-13 19:22:35 -0700269 "info: ignore timeout value for IEEE Power Save\n");
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700270
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700271 ps_mode = enabled;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700272
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700273 return mwifiex_drv_set_power(priv, &ps_mode);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700274}
275
276/*
277 * CFG802.11 operation handler to set the default network key.
278 */
279static int
280mwifiex_cfg80211_set_default_key(struct wiphy *wiphy, struct net_device *netdev,
281 u8 key_index, bool unicast,
282 bool multicast)
283{
Yogesh Ashok Powarf540f9f2012-01-11 20:06:12 -0800284 struct mwifiex_private *priv = mwifiex_netdev_get_priv(netdev);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700285
Amitkumar Karwar2d3d0a82011-04-01 18:36:46 -0700286 /* Return if WEP key not configured */
Amitkumar Karwar5eb02e42012-02-24 21:36:04 -0800287 if (!priv->sec_info.wep_enabled)
Amitkumar Karwar2d3d0a82011-04-01 18:36:46 -0700288 return 0;
289
Avinash Patil96893532012-06-15 12:21:55 -0700290 if (priv->bss_type == MWIFIEX_BSS_TYPE_UAP) {
291 priv->wep_key_curr_index = key_index;
Ying Luo53b11232012-08-03 18:06:13 -0700292 } else if (mwifiex_set_encode(priv, NULL, NULL, 0, key_index,
293 NULL, 0)) {
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700294 wiphy_err(wiphy, "set default Tx key index\n");
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700295 return -EFAULT;
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700296 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700297
298 return 0;
299}
300
301/*
302 * CFG802.11 operation handler to add a network key.
303 */
304static int
305mwifiex_cfg80211_add_key(struct wiphy *wiphy, struct net_device *netdev,
306 u8 key_index, bool pairwise, const u8 *mac_addr,
307 struct key_params *params)
308{
Yogesh Ashok Powarf540f9f2012-01-11 20:06:12 -0800309 struct mwifiex_private *priv = mwifiex_netdev_get_priv(netdev);
Avinash Patil96893532012-06-15 12:21:55 -0700310 struct mwifiex_wep_key *wep_key;
Avinash Patil75edd2c2012-05-08 18:30:18 -0700311 const u8 bc_mac[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
312 const u8 *peer_mac = pairwise ? mac_addr : bc_mac;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700313
Avinash Patil96893532012-06-15 12:21:55 -0700314 if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_UAP &&
315 (params->cipher == WLAN_CIPHER_SUITE_WEP40 ||
316 params->cipher == WLAN_CIPHER_SUITE_WEP104)) {
317 if (params->key && params->key_len) {
318 wep_key = &priv->wep_key[key_index];
319 memset(wep_key, 0, sizeof(struct mwifiex_wep_key));
320 memcpy(wep_key->key_material, params->key,
321 params->key_len);
322 wep_key->key_index = key_index;
323 wep_key->key_length = params->key_len;
324 priv->sec_info.wep_enabled = 1;
325 }
326 return 0;
327 }
328
Ying Luo53b11232012-08-03 18:06:13 -0700329 if (mwifiex_set_encode(priv, params, params->key, params->key_len,
Avinash Patil75edd2c2012-05-08 18:30:18 -0700330 key_index, peer_mac, 0)) {
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700331 wiphy_err(wiphy, "crypto keys added\n");
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700332 return -EFAULT;
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700333 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700334
335 return 0;
336}
337
338/*
339 * This function sends domain information to the firmware.
340 *
341 * The following information are passed to the firmware -
342 * - Country codes
343 * - Sub bands (first channel, number of channels, maximum Tx power)
344 */
345static int mwifiex_send_domain_info_cmd_fw(struct wiphy *wiphy)
346{
347 u8 no_of_triplet = 0;
348 struct ieee80211_country_ie_triplet *t;
349 u8 no_of_parsed_chan = 0;
350 u8 first_chan = 0, next_chan = 0, max_pwr = 0;
351 u8 i, flag = 0;
352 enum ieee80211_band band;
353 struct ieee80211_supported_band *sband;
354 struct ieee80211_channel *ch;
Avinash Patil67fdf392012-05-08 18:30:17 -0700355 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
356 struct mwifiex_private *priv;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700357 struct mwifiex_802_11d_domain_reg *domain_info = &adapter->domain_reg;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700358
359 /* Set country code */
Avinash Patil67fdf392012-05-08 18:30:17 -0700360 domain_info->country_code[0] = adapter->country_code[0];
361 domain_info->country_code[1] = adapter->country_code[1];
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700362 domain_info->country_code[2] = ' ';
363
364 band = mwifiex_band_to_radio_type(adapter->config_bands);
365 if (!wiphy->bands[band]) {
366 wiphy_err(wiphy, "11D: setting domain info in FW\n");
367 return -1;
368 }
369
370 sband = wiphy->bands[band];
371
372 for (i = 0; i < sband->n_channels ; i++) {
373 ch = &sband->channels[i];
374 if (ch->flags & IEEE80211_CHAN_DISABLED)
375 continue;
376
377 if (!flag) {
378 flag = 1;
379 first_chan = (u32) ch->hw_value;
380 next_chan = first_chan;
Amitkumar Karwar34202e22012-06-27 19:57:59 -0700381 max_pwr = ch->max_reg_power;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700382 no_of_parsed_chan = 1;
383 continue;
384 }
385
386 if (ch->hw_value == next_chan + 1 &&
Amitkumar Karwar34202e22012-06-27 19:57:59 -0700387 ch->max_reg_power == max_pwr) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700388 next_chan++;
389 no_of_parsed_chan++;
390 } else {
391 t = &domain_info->triplet[no_of_triplet];
392 t->chans.first_channel = first_chan;
393 t->chans.num_channels = no_of_parsed_chan;
394 t->chans.max_power = max_pwr;
395 no_of_triplet++;
396 first_chan = (u32) ch->hw_value;
397 next_chan = first_chan;
Amitkumar Karwar34202e22012-06-27 19:57:59 -0700398 max_pwr = ch->max_reg_power;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700399 no_of_parsed_chan = 1;
400 }
401 }
402
403 if (flag) {
404 t = &domain_info->triplet[no_of_triplet];
405 t->chans.first_channel = first_chan;
406 t->chans.num_channels = no_of_parsed_chan;
407 t->chans.max_power = max_pwr;
408 no_of_triplet++;
409 }
410
411 domain_info->no_of_triplet = no_of_triplet;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700412
Avinash Patil67fdf392012-05-08 18:30:17 -0700413 priv = mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY);
414
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700415 if (mwifiex_send_cmd_async(priv, HostCmd_CMD_802_11D_DOMAIN_INFO,
Yogesh Ashok Powaraea07012012-03-13 19:22:35 -0700416 HostCmd_ACT_GEN_SET, 0, NULL)) {
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700417 wiphy_err(wiphy, "11D: setting domain info in FW\n");
418 return -1;
419 }
420
421 return 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700422}
423
424/*
425 * CFG802.11 regulatory domain callback function.
426 *
427 * This function is called when the regulatory domain is changed due to the
428 * following reasons -
429 * - Set by driver
430 * - Set by system core
431 * - Set by user
432 * - Set bt Country IE
433 */
434static int mwifiex_reg_notifier(struct wiphy *wiphy,
Yogesh Ashok Powaraea07012012-03-13 19:22:35 -0700435 struct regulatory_request *request)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700436{
Avinash Patil67fdf392012-05-08 18:30:17 -0700437 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700438
Avinash Patil67fdf392012-05-08 18:30:17 -0700439 wiphy_dbg(wiphy, "info: cfg80211 regulatory domain callback for %c%c\n",
440 request->alpha2[0], request->alpha2[1]);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700441
Avinash Patil67fdf392012-05-08 18:30:17 -0700442 memcpy(adapter->country_code, request->alpha2, sizeof(request->alpha2));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700443
444 switch (request->initiator) {
445 case NL80211_REGDOM_SET_BY_DRIVER:
446 case NL80211_REGDOM_SET_BY_CORE:
447 case NL80211_REGDOM_SET_BY_USER:
448 break;
449 /* Todo: apply driver specific changes in channel flags based
450 on the request initiator if necessary. */
451 case NL80211_REGDOM_SET_BY_COUNTRY_IE:
452 break;
453 }
454 mwifiex_send_domain_info_cmd_fw(wiphy);
455
456 return 0;
457}
458
459/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700460 * This function sets the fragmentation threshold.
461 *
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700462 * The fragmentation threshold value must lie between MWIFIEX_FRAG_MIN_VALUE
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700463 * and MWIFIEX_FRAG_MAX_VALUE.
464 */
465static int
466mwifiex_set_frag(struct mwifiex_private *priv, u32 frag_thr)
467{
Yogesh Ashok Powaraea07012012-03-13 19:22:35 -0700468 if (frag_thr < MWIFIEX_FRAG_MIN_VALUE ||
469 frag_thr > MWIFIEX_FRAG_MAX_VALUE)
Avinash Patil9b930ea2012-05-08 18:30:23 -0700470 frag_thr = MWIFIEX_FRAG_MAX_VALUE;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700471
Avinash Patil9b930ea2012-05-08 18:30:23 -0700472 return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_SNMP_MIB,
473 HostCmd_ACT_GEN_SET, FRAG_THRESH_I,
474 &frag_thr);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700475}
476
477/*
478 * This function sets the RTS threshold.
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700479
480 * The rts value must lie between MWIFIEX_RTS_MIN_VALUE
481 * and MWIFIEX_RTS_MAX_VALUE.
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700482 */
483static int
484mwifiex_set_rts(struct mwifiex_private *priv, u32 rts_thr)
485{
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700486 if (rts_thr < MWIFIEX_RTS_MIN_VALUE || rts_thr > MWIFIEX_RTS_MAX_VALUE)
487 rts_thr = MWIFIEX_RTS_MAX_VALUE;
488
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700489 return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_SNMP_MIB,
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700490 HostCmd_ACT_GEN_SET, RTS_THRESH_I,
491 &rts_thr);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700492}
493
494/*
495 * CFG802.11 operation handler to set wiphy parameters.
496 *
497 * This function can be used to set the RTS threshold and the
498 * Fragmentation threshold of the driver.
499 */
500static int
501mwifiex_cfg80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
502{
Avinash Patil67fdf392012-05-08 18:30:17 -0700503 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
Avinash Patil9b930ea2012-05-08 18:30:23 -0700504 struct mwifiex_private *priv;
505 struct mwifiex_uap_bss_param *bss_cfg;
506 int ret, bss_started, i;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700507
Avinash Patil9b930ea2012-05-08 18:30:23 -0700508 for (i = 0; i < adapter->priv_num; i++) {
509 priv = adapter->priv[i];
510
511 switch (priv->bss_role) {
512 case MWIFIEX_BSS_ROLE_UAP:
513 bss_cfg = kzalloc(sizeof(struct mwifiex_uap_bss_param),
514 GFP_KERNEL);
515 if (!bss_cfg)
516 return -ENOMEM;
517
518 mwifiex_set_sys_config_invalid_data(bss_cfg);
519
520 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
521 bss_cfg->rts_threshold = wiphy->rts_threshold;
522 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
523 bss_cfg->frag_threshold = wiphy->frag_threshold;
524 if (changed & WIPHY_PARAM_RETRY_LONG)
525 bss_cfg->retry_limit = wiphy->retry_long;
526
527 bss_started = priv->bss_started;
528
529 ret = mwifiex_send_cmd_sync(priv,
530 HostCmd_CMD_UAP_BSS_STOP,
531 HostCmd_ACT_GEN_SET, 0,
532 NULL);
533 if (ret) {
534 wiphy_err(wiphy, "Failed to stop the BSS\n");
535 kfree(bss_cfg);
536 return ret;
537 }
538
539 ret = mwifiex_send_cmd_async(priv,
540 HostCmd_CMD_UAP_SYS_CONFIG,
541 HostCmd_ACT_GEN_SET,
Avinash Patile76268d2012-05-08 18:30:27 -0700542 UAP_BSS_PARAMS_I, bss_cfg);
Avinash Patil9b930ea2012-05-08 18:30:23 -0700543
544 kfree(bss_cfg);
545
546 if (ret) {
547 wiphy_err(wiphy, "Failed to set bss config\n");
548 return ret;
549 }
550
551 if (!bss_started)
552 break;
553
554 ret = mwifiex_send_cmd_async(priv,
555 HostCmd_CMD_UAP_BSS_START,
556 HostCmd_ACT_GEN_SET, 0,
557 NULL);
558 if (ret) {
559 wiphy_err(wiphy, "Failed to start BSS\n");
560 return ret;
561 }
562
563 break;
564 case MWIFIEX_BSS_ROLE_STA:
565 if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
566 ret = mwifiex_set_rts(priv,
567 wiphy->rts_threshold);
568 if (ret)
569 return ret;
570 }
571 if (changed & WIPHY_PARAM_FRAG_THRESHOLD) {
572 ret = mwifiex_set_frag(priv,
573 wiphy->frag_threshold);
574 if (ret)
575 return ret;
576 }
577 break;
578 }
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700579 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700580
Avinash Patil9b930ea2012-05-08 18:30:23 -0700581 return 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700582}
583
584/*
585 * CFG802.11 operation handler to change interface type.
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700586 */
587static int
588mwifiex_cfg80211_change_virtual_intf(struct wiphy *wiphy,
589 struct net_device *dev,
590 enum nl80211_iftype type, u32 *flags,
591 struct vif_params *params)
592{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700593 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700594 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
Bing Zhaoeecd8252011-03-28 17:55:41 -0700595
Avinash Patil4f023412012-05-08 18:30:22 -0700596 switch (dev->ieee80211_ptr->iftype) {
Bing Zhaoeecd8252011-03-28 17:55:41 -0700597 case NL80211_IFTYPE_ADHOC:
Avinash Patil4f023412012-05-08 18:30:22 -0700598 switch (type) {
599 case NL80211_IFTYPE_STATION:
600 break;
601 case NL80211_IFTYPE_UNSPECIFIED:
602 wiphy_warn(wiphy, "%s: kept type as IBSS\n", dev->name);
603 case NL80211_IFTYPE_ADHOC: /* This shouldn't happen */
604 return 0;
605 case NL80211_IFTYPE_AP:
606 default:
607 wiphy_err(wiphy, "%s: changing to %d not supported\n",
608 dev->name, type);
609 return -EOPNOTSUPP;
610 }
Bing Zhaoeecd8252011-03-28 17:55:41 -0700611 break;
612 case NL80211_IFTYPE_STATION:
Avinash Patil4f023412012-05-08 18:30:22 -0700613 switch (type) {
614 case NL80211_IFTYPE_ADHOC:
615 break;
616 case NL80211_IFTYPE_UNSPECIFIED:
617 wiphy_warn(wiphy, "%s: kept type as STA\n", dev->name);
618 case NL80211_IFTYPE_STATION: /* This shouldn't happen */
619 return 0;
620 case NL80211_IFTYPE_AP:
621 default:
622 wiphy_err(wiphy, "%s: changing to %d not supported\n",
623 dev->name, type);
624 return -EOPNOTSUPP;
625 }
Bing Zhaoeecd8252011-03-28 17:55:41 -0700626 break;
Avinash Patil4f023412012-05-08 18:30:22 -0700627 case NL80211_IFTYPE_AP:
628 switch (type) {
629 case NL80211_IFTYPE_UNSPECIFIED:
630 wiphy_warn(wiphy, "%s: kept type as AP\n", dev->name);
631 case NL80211_IFTYPE_AP: /* This shouldn't happen */
632 return 0;
633 case NL80211_IFTYPE_ADHOC:
634 case NL80211_IFTYPE_STATION:
635 default:
636 wiphy_err(wiphy, "%s: changing to %d not supported\n",
637 dev->name, type);
638 return -EOPNOTSUPP;
639 }
640 break;
Bing Zhaoeecd8252011-03-28 17:55:41 -0700641 default:
Avinash Patil4f023412012-05-08 18:30:22 -0700642 wiphy_err(wiphy, "%s: unknown iftype: %d\n",
643 dev->name, dev->ieee80211_ptr->iftype);
644 return -EOPNOTSUPP;
Bing Zhaoeecd8252011-03-28 17:55:41 -0700645 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700646
Avinash Patil4f023412012-05-08 18:30:22 -0700647 dev->ieee80211_ptr->iftype = type;
648 priv->bss_mode = type;
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700649 mwifiex_deauthenticate(priv, NULL);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700650
Marc Yangf986b6d2011-03-28 17:55:42 -0700651 priv->sec_info.authentication_mode = NL80211_AUTHTYPE_OPEN_SYSTEM;
Bing Zhaoeecd8252011-03-28 17:55:41 -0700652
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700653 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_SET_BSS_MODE,
654 HostCmd_ACT_GEN_SET, 0, NULL);
Bing Zhaoeecd8252011-03-28 17:55:41 -0700655
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700656 return ret;
657}
658
659/*
660 * This function dumps the station information on a buffer.
661 *
662 * The following information are shown -
663 * - Total bytes transmitted
664 * - Total bytes received
665 * - Total packets transmitted
666 * - Total packets received
667 * - Signal quality level
668 * - Transmission rate
669 */
670static int
671mwifiex_dump_station_info(struct mwifiex_private *priv,
672 struct station_info *sinfo)
673{
Amitkumar Karwar006606c2012-07-13 20:09:31 -0700674 u32 rate;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700675
676 sinfo->filled = STATION_INFO_RX_BYTES | STATION_INFO_TX_BYTES |
Amitkumar Karwar7013d3e2012-03-15 20:51:50 -0700677 STATION_INFO_RX_PACKETS | STATION_INFO_TX_PACKETS |
678 STATION_INFO_TX_BITRATE |
679 STATION_INFO_SIGNAL | STATION_INFO_SIGNAL_AVG;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700680
681 /* Get signal information from the firmware */
Amitkumar Karwar958a4a82012-03-15 20:51:49 -0700682 if (mwifiex_send_cmd_sync(priv, HostCmd_CMD_RSSI_INFO,
683 HostCmd_ACT_GEN_GET, 0, NULL)) {
684 dev_err(priv->adapter->dev, "failed to get signal information\n");
685 return -EFAULT;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700686 }
687
688 if (mwifiex_drv_get_data_rate(priv, &rate)) {
689 dev_err(priv->adapter->dev, "getting data rate\n");
Amitkumar Karwar958a4a82012-03-15 20:51:49 -0700690 return -EFAULT;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700691 }
692
Amitkumar Karwarcaf60a62012-02-02 20:48:58 -0800693 /* Get DTIM period information from firmware */
694 mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_SNMP_MIB,
695 HostCmd_ACT_GEN_GET, DTIM_PERIOD_I,
696 &priv->dtim_period);
697
Amitkumar Karwar4ec6f9c2011-09-26 20:37:25 -0700698 /*
699 * Bit 0 in tx_htinfo indicates that current Tx rate is 11n rate. Valid
Amitkumar Karwarfe020122012-07-11 18:12:57 -0700700 * MCS index values for us are 0 to 15.
Amitkumar Karwar4ec6f9c2011-09-26 20:37:25 -0700701 */
Amitkumar Karwarfe020122012-07-11 18:12:57 -0700702 if ((priv->tx_htinfo & BIT(0)) && (priv->tx_rate < 16)) {
Amitkumar Karwar4ec6f9c2011-09-26 20:37:25 -0700703 sinfo->txrate.mcs = priv->tx_rate;
704 sinfo->txrate.flags |= RATE_INFO_FLAGS_MCS;
705 /* 40MHz rate */
706 if (priv->tx_htinfo & BIT(1))
707 sinfo->txrate.flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
708 /* SGI enabled */
709 if (priv->tx_htinfo & BIT(2))
710 sinfo->txrate.flags |= RATE_INFO_FLAGS_SHORT_GI;
711 }
712
Amitkumar Karwar7013d3e2012-03-15 20:51:50 -0700713 sinfo->signal_avg = priv->bcn_rssi_avg;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700714 sinfo->rx_bytes = priv->stats.rx_bytes;
715 sinfo->tx_bytes = priv->stats.tx_bytes;
716 sinfo->rx_packets = priv->stats.rx_packets;
717 sinfo->tx_packets = priv->stats.tx_packets;
Amitkumar Karwar958a4a82012-03-15 20:51:49 -0700718 sinfo->signal = priv->bcn_rssi_avg;
Amitkumar Karwar4ec6f9c2011-09-26 20:37:25 -0700719 /* bit rate is in 500 kb/s units. Convert it to 100kb/s units */
Amitkumar Karwar006606c2012-07-13 20:09:31 -0700720 sinfo->txrate.legacy = rate * 5;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700721
Amitkumar Karwarc4f3b972012-01-24 20:50:25 -0800722 if (priv->bss_mode == NL80211_IFTYPE_STATION) {
723 sinfo->filled |= STATION_INFO_BSS_PARAM;
724 sinfo->bss_param.flags = 0;
725 if (priv->curr_bss_params.bss_descriptor.cap_info_bitmap &
726 WLAN_CAPABILITY_SHORT_PREAMBLE)
727 sinfo->bss_param.flags |=
728 BSS_PARAM_FLAGS_SHORT_PREAMBLE;
729 if (priv->curr_bss_params.bss_descriptor.cap_info_bitmap &
730 WLAN_CAPABILITY_SHORT_SLOT_TIME)
731 sinfo->bss_param.flags |=
732 BSS_PARAM_FLAGS_SHORT_SLOT_TIME;
Amitkumar Karwarcaf60a62012-02-02 20:48:58 -0800733 sinfo->bss_param.dtim_period = priv->dtim_period;
Amitkumar Karwarc4f3b972012-01-24 20:50:25 -0800734 sinfo->bss_param.beacon_interval =
735 priv->curr_bss_params.bss_descriptor.beacon_period;
736 }
737
Amitkumar Karwar958a4a82012-03-15 20:51:49 -0700738 return 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700739}
740
741/*
742 * CFG802.11 operation handler to get station information.
743 *
744 * This function only works in connected mode, and dumps the
745 * requested station information, if available.
746 */
747static int
748mwifiex_cfg80211_get_station(struct wiphy *wiphy, struct net_device *dev,
749 u8 *mac, struct station_info *sinfo)
750{
751 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700752
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700753 if (!priv->media_connected)
754 return -ENOENT;
755 if (memcmp(mac, priv->cfg_bssid, ETH_ALEN))
756 return -ENOENT;
757
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700758 return mwifiex_dump_station_info(priv, sinfo);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700759}
760
Amitkumar Karwarf85aae62012-03-15 20:51:48 -0700761/*
762 * CFG802.11 operation handler to dump station information.
763 */
764static int
765mwifiex_cfg80211_dump_station(struct wiphy *wiphy, struct net_device *dev,
766 int idx, u8 *mac, struct station_info *sinfo)
767{
768 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
769
770 if (!priv->media_connected || idx)
771 return -ENOENT;
772
773 memcpy(mac, priv->cfg_bssid, ETH_ALEN);
774
775 return mwifiex_dump_station_info(priv, sinfo);
776}
777
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700778/* Supported rates to be advertised to the cfg80211 */
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700779static struct ieee80211_rate mwifiex_rates[] = {
780 {.bitrate = 10, .hw_value = 2, },
781 {.bitrate = 20, .hw_value = 4, },
782 {.bitrate = 55, .hw_value = 11, },
783 {.bitrate = 110, .hw_value = 22, },
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700784 {.bitrate = 60, .hw_value = 12, },
785 {.bitrate = 90, .hw_value = 18, },
786 {.bitrate = 120, .hw_value = 24, },
787 {.bitrate = 180, .hw_value = 36, },
788 {.bitrate = 240, .hw_value = 48, },
789 {.bitrate = 360, .hw_value = 72, },
790 {.bitrate = 480, .hw_value = 96, },
791 {.bitrate = 540, .hw_value = 108, },
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700792};
793
794/* Channel definitions to be advertised to cfg80211 */
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700795static struct ieee80211_channel mwifiex_channels_2ghz[] = {
796 {.center_freq = 2412, .hw_value = 1, },
797 {.center_freq = 2417, .hw_value = 2, },
798 {.center_freq = 2422, .hw_value = 3, },
799 {.center_freq = 2427, .hw_value = 4, },
800 {.center_freq = 2432, .hw_value = 5, },
801 {.center_freq = 2437, .hw_value = 6, },
802 {.center_freq = 2442, .hw_value = 7, },
803 {.center_freq = 2447, .hw_value = 8, },
804 {.center_freq = 2452, .hw_value = 9, },
805 {.center_freq = 2457, .hw_value = 10, },
806 {.center_freq = 2462, .hw_value = 11, },
807 {.center_freq = 2467, .hw_value = 12, },
808 {.center_freq = 2472, .hw_value = 13, },
809 {.center_freq = 2484, .hw_value = 14, },
810};
811
812static struct ieee80211_supported_band mwifiex_band_2ghz = {
813 .channels = mwifiex_channels_2ghz,
814 .n_channels = ARRAY_SIZE(mwifiex_channels_2ghz),
815 .bitrates = mwifiex_rates,
Amitkumar Karwar87638482012-03-07 19:36:07 -0800816 .n_bitrates = ARRAY_SIZE(mwifiex_rates),
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700817};
818
819static struct ieee80211_channel mwifiex_channels_5ghz[] = {
820 {.center_freq = 5040, .hw_value = 8, },
821 {.center_freq = 5060, .hw_value = 12, },
822 {.center_freq = 5080, .hw_value = 16, },
823 {.center_freq = 5170, .hw_value = 34, },
824 {.center_freq = 5190, .hw_value = 38, },
825 {.center_freq = 5210, .hw_value = 42, },
826 {.center_freq = 5230, .hw_value = 46, },
827 {.center_freq = 5180, .hw_value = 36, },
828 {.center_freq = 5200, .hw_value = 40, },
829 {.center_freq = 5220, .hw_value = 44, },
830 {.center_freq = 5240, .hw_value = 48, },
831 {.center_freq = 5260, .hw_value = 52, },
832 {.center_freq = 5280, .hw_value = 56, },
833 {.center_freq = 5300, .hw_value = 60, },
834 {.center_freq = 5320, .hw_value = 64, },
835 {.center_freq = 5500, .hw_value = 100, },
836 {.center_freq = 5520, .hw_value = 104, },
837 {.center_freq = 5540, .hw_value = 108, },
838 {.center_freq = 5560, .hw_value = 112, },
839 {.center_freq = 5580, .hw_value = 116, },
840 {.center_freq = 5600, .hw_value = 120, },
841 {.center_freq = 5620, .hw_value = 124, },
842 {.center_freq = 5640, .hw_value = 128, },
843 {.center_freq = 5660, .hw_value = 132, },
844 {.center_freq = 5680, .hw_value = 136, },
845 {.center_freq = 5700, .hw_value = 140, },
846 {.center_freq = 5745, .hw_value = 149, },
847 {.center_freq = 5765, .hw_value = 153, },
848 {.center_freq = 5785, .hw_value = 157, },
849 {.center_freq = 5805, .hw_value = 161, },
850 {.center_freq = 5825, .hw_value = 165, },
851};
852
853static struct ieee80211_supported_band mwifiex_band_5ghz = {
854 .channels = mwifiex_channels_5ghz,
855 .n_channels = ARRAY_SIZE(mwifiex_channels_5ghz),
Avinash Patileb416ad2012-02-27 22:04:11 -0800856 .bitrates = mwifiex_rates + 4,
857 .n_bitrates = ARRAY_SIZE(mwifiex_rates) - 4,
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700858};
859
860
861/* Supported crypto cipher suits to be advertised to cfg80211 */
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700862static const u32 mwifiex_cipher_suites[] = {
863 WLAN_CIPHER_SUITE_WEP40,
864 WLAN_CIPHER_SUITE_WEP104,
865 WLAN_CIPHER_SUITE_TKIP,
866 WLAN_CIPHER_SUITE_CCMP,
Ying Luo53b11232012-08-03 18:06:13 -0700867 WLAN_CIPHER_SUITE_AES_CMAC,
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700868};
869
870/*
Yogesh Ashok Powar5d82c532011-07-11 20:04:44 -0700871 * CFG802.11 operation handler for setting bit rates.
872 *
Amitkumar Karwar433c3992012-07-13 20:09:33 -0700873 * Function configures data rates to firmware using bitrate mask
874 * provided by cfg80211.
Yogesh Ashok Powar5d82c532011-07-11 20:04:44 -0700875 */
876static int mwifiex_cfg80211_set_bitrate_mask(struct wiphy *wiphy,
877 struct net_device *dev,
878 const u8 *peer,
879 const struct cfg80211_bitrate_mask *mask)
880{
Yogesh Ashok Powar5d82c532011-07-11 20:04:44 -0700881 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
Amitkumar Karwar433c3992012-07-13 20:09:33 -0700882 u16 bitmap_rates[MAX_BITMAP_RATES_SIZE];
883 enum ieee80211_band band;
Yogesh Ashok Powar5d82c532011-07-11 20:04:44 -0700884
Amitkumar Karwar433c3992012-07-13 20:09:33 -0700885 if (!priv->media_connected) {
886 dev_err(priv->adapter->dev,
887 "Can not set Tx data rate in disconnected state\n");
888 return -EINVAL;
Yogesh Ashok Powar5d82c532011-07-11 20:04:44 -0700889 }
890
Amitkumar Karwar433c3992012-07-13 20:09:33 -0700891 band = mwifiex_band_to_radio_type(priv->curr_bss_params.band);
Yogesh Ashok Powar5d82c532011-07-11 20:04:44 -0700892
Amitkumar Karwar433c3992012-07-13 20:09:33 -0700893 memset(bitmap_rates, 0, sizeof(bitmap_rates));
Yogesh Ashok Powar5d82c532011-07-11 20:04:44 -0700894
Amitkumar Karwar433c3992012-07-13 20:09:33 -0700895 /* Fill HR/DSSS rates. */
896 if (band == IEEE80211_BAND_2GHZ)
897 bitmap_rates[0] = mask->control[band].legacy & 0x000f;
Yogesh Ashok Powar5d82c532011-07-11 20:04:44 -0700898
Amitkumar Karwar433c3992012-07-13 20:09:33 -0700899 /* Fill OFDM rates */
900 if (band == IEEE80211_BAND_2GHZ)
901 bitmap_rates[1] = (mask->control[band].legacy & 0x0ff0) >> 4;
902 else
903 bitmap_rates[1] = mask->control[band].legacy;
904
905 /* Fill MCS rates */
906 bitmap_rates[2] = mask->control[band].mcs[0];
907 if (priv->adapter->hw_dev_mcs_support == HT_STREAM_2X2)
908 bitmap_rates[2] |= mask->control[band].mcs[1] << 8;
909
910 return mwifiex_send_cmd_sync(priv, HostCmd_CMD_TX_RATE_CFG,
911 HostCmd_ACT_GEN_SET, 0, bitmap_rates);
Yogesh Ashok Powar5d82c532011-07-11 20:04:44 -0700912}
913
914/*
Amitkumar Karwarfa444bf2012-03-15 20:51:51 -0700915 * CFG802.11 operation handler for connection quality monitoring.
916 *
917 * This function subscribes/unsubscribes HIGH_RSSI and LOW_RSSI
918 * events to FW.
919 */
920static int mwifiex_cfg80211_set_cqm_rssi_config(struct wiphy *wiphy,
921 struct net_device *dev,
922 s32 rssi_thold, u32 rssi_hyst)
923{
924 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
925 struct mwifiex_ds_misc_subsc_evt subsc_evt;
926
927 priv->cqm_rssi_thold = rssi_thold;
928 priv->cqm_rssi_hyst = rssi_hyst;
929
930 memset(&subsc_evt, 0x00, sizeof(struct mwifiex_ds_misc_subsc_evt));
931 subsc_evt.events = BITMASK_BCN_RSSI_LOW | BITMASK_BCN_RSSI_HIGH;
932
933 /* Subscribe/unsubscribe low and high rssi events */
934 if (rssi_thold && rssi_hyst) {
935 subsc_evt.action = HostCmd_ACT_BITWISE_SET;
936 subsc_evt.bcn_l_rssi_cfg.abs_value = abs(rssi_thold);
937 subsc_evt.bcn_h_rssi_cfg.abs_value = abs(rssi_thold);
938 subsc_evt.bcn_l_rssi_cfg.evt_freq = 1;
939 subsc_evt.bcn_h_rssi_cfg.evt_freq = 1;
940 return mwifiex_send_cmd_sync(priv,
941 HostCmd_CMD_802_11_SUBSCRIBE_EVENT,
942 0, 0, &subsc_evt);
943 } else {
944 subsc_evt.action = HostCmd_ACT_BITWISE_CLR;
945 return mwifiex_send_cmd_sync(priv,
946 HostCmd_CMD_802_11_SUBSCRIBE_EVENT,
947 0, 0, &subsc_evt);
948 }
949
950 return 0;
951}
952
Avinash Patil5370c832012-06-28 20:30:28 -0700953/* cfg80211 operation handler for change_beacon.
954 * Function retrieves and sets modified management IEs to FW.
955 */
956static int mwifiex_cfg80211_change_beacon(struct wiphy *wiphy,
957 struct net_device *dev,
958 struct cfg80211_beacon_data *data)
959{
960 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
961
962 if (priv->bss_type != MWIFIEX_BSS_TYPE_UAP) {
963 wiphy_err(wiphy, "%s: bss_type mismatched\n", __func__);
964 return -EINVAL;
965 }
966
967 if (!priv->bss_started) {
968 wiphy_err(wiphy, "%s: bss not started\n", __func__);
969 return -EINVAL;
970 }
971
972 if (mwifiex_set_mgmt_ies(priv, data)) {
973 wiphy_err(wiphy, "%s: setting mgmt ies failed\n", __func__);
974 return -EFAULT;
975 }
976
977 return 0;
978}
979
Amitkumar Karwar8a279d52012-07-02 19:32:33 -0700980static int
981mwifiex_cfg80211_set_antenna(struct wiphy *wiphy, u32 tx_ant, u32 rx_ant)
982{
983 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
984 struct mwifiex_private *priv = mwifiex_get_priv(adapter,
985 MWIFIEX_BSS_ROLE_ANY);
986 struct mwifiex_ds_ant_cfg ant_cfg;
987
988 if (!tx_ant || !rx_ant)
989 return -EOPNOTSUPP;
990
991 if (adapter->hw_dev_mcs_support != HT_STREAM_2X2) {
992 /* Not a MIMO chip. User should provide specific antenna number
993 * for Tx/Rx path or enable all antennas for diversity
994 */
995 if (tx_ant != rx_ant)
996 return -EOPNOTSUPP;
997
998 if ((tx_ant & (tx_ant - 1)) &&
999 (tx_ant != BIT(adapter->number_of_antenna) - 1))
1000 return -EOPNOTSUPP;
1001
1002 if ((tx_ant == BIT(adapter->number_of_antenna) - 1) &&
1003 (priv->adapter->number_of_antenna > 1)) {
1004 tx_ant = RF_ANTENNA_AUTO;
1005 rx_ant = RF_ANTENNA_AUTO;
1006 }
1007 }
1008
1009 ant_cfg.tx_ant = tx_ant;
1010 ant_cfg.rx_ant = rx_ant;
1011
1012 return mwifiex_send_cmd_sync(priv, HostCmd_CMD_RF_ANTENNA,
1013 HostCmd_ACT_GEN_SET, 0, &ant_cfg);
1014}
1015
Avinash Patil12190c52012-05-08 18:30:24 -07001016/* cfg80211 operation handler for stop ap.
1017 * Function stops BSS running at uAP interface.
1018 */
1019static int mwifiex_cfg80211_stop_ap(struct wiphy *wiphy, struct net_device *dev)
1020{
1021 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
1022
Avinash Patil40bbc212012-05-08 18:30:30 -07001023 if (mwifiex_del_mgmt_ies(priv))
1024 wiphy_err(wiphy, "Failed to delete mgmt IEs!\n");
1025
Avinash Patilc8258912012-08-03 18:06:05 -07001026 priv->ap_11n_enabled = 0;
1027
Avinash Patil12190c52012-05-08 18:30:24 -07001028 if (mwifiex_send_cmd_sync(priv, HostCmd_CMD_UAP_BSS_STOP,
1029 HostCmd_ACT_GEN_SET, 0, NULL)) {
1030 wiphy_err(wiphy, "Failed to stop the BSS\n");
1031 return -1;
1032 }
1033
1034 return 0;
1035}
1036
1037/* cfg80211 operation handler for start_ap.
1038 * Function sets beacon period, DTIM period, SSID and security into
1039 * AP config structure.
1040 * AP is configured with these settings and BSS is started.
1041 */
1042static int mwifiex_cfg80211_start_ap(struct wiphy *wiphy,
1043 struct net_device *dev,
1044 struct cfg80211_ap_settings *params)
1045{
1046 struct mwifiex_uap_bss_param *bss_cfg;
1047 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
Amitkumar Karwar05910f42012-07-13 20:09:32 -07001048 u8 config_bands = 0;
Avinash Patil12190c52012-05-08 18:30:24 -07001049
Avinash Patilf752dcd2012-05-08 18:30:26 -07001050 if (priv->bss_type != MWIFIEX_BSS_TYPE_UAP)
1051 return -1;
Avinash Patiladb6ed02012-06-28 20:30:25 -07001052 if (mwifiex_set_mgmt_ies(priv, &params->beacon))
Avinash Patilf31acab2012-05-08 18:30:29 -07001053 return -1;
Avinash Patilf752dcd2012-05-08 18:30:26 -07001054
Avinash Patil12190c52012-05-08 18:30:24 -07001055 bss_cfg = kzalloc(sizeof(struct mwifiex_uap_bss_param), GFP_KERNEL);
1056 if (!bss_cfg)
1057 return -ENOMEM;
1058
1059 mwifiex_set_sys_config_invalid_data(bss_cfg);
1060
1061 if (params->beacon_interval)
1062 bss_cfg->beacon_period = params->beacon_interval;
1063 if (params->dtim_period)
1064 bss_cfg->dtim_period = params->dtim_period;
1065
1066 if (params->ssid && params->ssid_len) {
1067 memcpy(bss_cfg->ssid.ssid, params->ssid, params->ssid_len);
1068 bss_cfg->ssid.ssid_len = params->ssid_len;
1069 }
1070
Avinash Patil7a1c9932012-05-29 15:39:05 -07001071 switch (params->hidden_ssid) {
1072 case NL80211_HIDDEN_SSID_NOT_IN_USE:
1073 bss_cfg->bcast_ssid_ctl = 1;
1074 break;
1075 case NL80211_HIDDEN_SSID_ZERO_LEN:
1076 bss_cfg->bcast_ssid_ctl = 0;
1077 break;
1078 case NL80211_HIDDEN_SSID_ZERO_CONTENTS:
1079 /* firmware doesn't support this type of hidden SSID */
1080 default:
Bing Zhaob3190462012-07-03 15:53:13 -07001081 kfree(bss_cfg);
Avinash Patil7a1c9932012-05-29 15:39:05 -07001082 return -EINVAL;
1083 }
1084
Avinash Patil0abd79e2012-06-15 12:21:51 -07001085 bss_cfg->channel =
1086 (u8)ieee80211_frequency_to_channel(params->channel->center_freq);
Avinash Patil0abd79e2012-06-15 12:21:51 -07001087
Amitkumar Karwar05910f42012-07-13 20:09:32 -07001088 /* Set appropriate bands */
1089 if (params->channel->band == IEEE80211_BAND_2GHZ) {
Avinash Patila3c2c4f2012-08-27 20:32:53 -07001090 bss_cfg->band_cfg = BAND_CONFIG_BG;
1091
Amitkumar Karwar05910f42012-07-13 20:09:32 -07001092 if (params->channel_type == NL80211_CHAN_NO_HT)
1093 config_bands = BAND_B | BAND_G;
1094 else
1095 config_bands = BAND_B | BAND_G | BAND_GN;
1096 } else {
Avinash Patila3c2c4f2012-08-27 20:32:53 -07001097 bss_cfg->band_cfg = BAND_CONFIG_A;
1098
Amitkumar Karwar05910f42012-07-13 20:09:32 -07001099 if (params->channel_type == NL80211_CHAN_NO_HT)
1100 config_bands = BAND_A;
1101 else
1102 config_bands = BAND_AN | BAND_A;
Avinash Patil0abd79e2012-06-15 12:21:51 -07001103 }
1104
Amitkumar Karwar05910f42012-07-13 20:09:32 -07001105 if (!((config_bands | priv->adapter->fw_bands) &
1106 ~priv->adapter->fw_bands))
1107 priv->adapter->config_bands = config_bands;
1108
Avinash Patila3c2c4f2012-08-27 20:32:53 -07001109 mwifiex_set_uap_rates(bss_cfg, params);
Amitkumar Karwar05910f42012-07-13 20:09:32 -07001110 mwifiex_send_domain_info_cmd_fw(wiphy);
1111
Avinash Patilf752dcd2012-05-08 18:30:26 -07001112 if (mwifiex_set_secure_params(priv, bss_cfg, params)) {
1113 kfree(bss_cfg);
1114 wiphy_err(wiphy, "Failed to parse secuirty parameters!\n");
1115 return -1;
1116 }
1117
Avinash Patil22281252012-06-15 12:21:53 -07001118 mwifiex_set_ht_params(priv, bss_cfg, params);
1119
Avinash Patil12190c52012-05-08 18:30:24 -07001120 if (mwifiex_send_cmd_sync(priv, HostCmd_CMD_UAP_BSS_STOP,
1121 HostCmd_ACT_GEN_SET, 0, NULL)) {
1122 wiphy_err(wiphy, "Failed to stop the BSS\n");
1123 kfree(bss_cfg);
1124 return -1;
1125 }
1126
1127 if (mwifiex_send_cmd_async(priv, HostCmd_CMD_UAP_SYS_CONFIG,
Avinash Patile76268d2012-05-08 18:30:27 -07001128 HostCmd_ACT_GEN_SET,
1129 UAP_BSS_PARAMS_I, bss_cfg)) {
Avinash Patil12190c52012-05-08 18:30:24 -07001130 wiphy_err(wiphy, "Failed to set the SSID\n");
1131 kfree(bss_cfg);
1132 return -1;
1133 }
1134
1135 kfree(bss_cfg);
1136
1137 if (mwifiex_send_cmd_async(priv, HostCmd_CMD_UAP_BSS_START,
1138 HostCmd_ACT_GEN_SET, 0, NULL)) {
1139 wiphy_err(wiphy, "Failed to start the BSS\n");
1140 return -1;
1141 }
1142
Avinash Patil96893532012-06-15 12:21:55 -07001143 if (priv->sec_info.wep_enabled)
1144 priv->curr_pkt_filter |= HostCmd_ACT_MAC_WEP_ENABLE;
1145 else
1146 priv->curr_pkt_filter &= ~HostCmd_ACT_MAC_WEP_ENABLE;
1147
1148 if (mwifiex_send_cmd_sync(priv, HostCmd_CMD_MAC_CONTROL,
1149 HostCmd_ACT_GEN_SET, 0,
1150 &priv->curr_pkt_filter))
1151 return -1;
1152
Avinash Patil12190c52012-05-08 18:30:24 -07001153 return 0;
1154}
1155
Amitkumar Karwarfa444bf2012-03-15 20:51:51 -07001156/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001157 * CFG802.11 operation handler for disconnection request.
1158 *
1159 * This function does not work when there is already a disconnection
1160 * procedure going on.
1161 */
1162static int
1163mwifiex_cfg80211_disconnect(struct wiphy *wiphy, struct net_device *dev,
1164 u16 reason_code)
1165{
1166 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
1167
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001168 if (mwifiex_deauthenticate(priv, NULL))
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001169 return -EFAULT;
1170
1171 wiphy_dbg(wiphy, "info: successfully disconnected from %pM:"
1172 " reason code %d\n", priv->cfg_bssid, reason_code);
1173
Amitkumar Karwar38c9d662011-12-13 20:43:17 -08001174 memset(priv->cfg_bssid, 0, ETH_ALEN);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001175
1176 return 0;
1177}
1178
1179/*
1180 * This function informs the CFG802.11 subsystem of a new IBSS.
1181 *
1182 * The following information are sent to the CFG802.11 subsystem
1183 * to register the new IBSS. If we do not register the new IBSS,
1184 * a kernel panic will result.
1185 * - SSID
1186 * - SSID length
1187 * - BSSID
1188 * - Channel
1189 */
1190static int mwifiex_cfg80211_inform_ibss_bss(struct mwifiex_private *priv)
1191{
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001192 struct ieee80211_channel *chan;
1193 struct mwifiex_bss_info bss_info;
Amitkumar Karwaraa95a482011-11-07 21:41:12 -08001194 struct cfg80211_bss *bss;
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -07001195 int ie_len;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001196 u8 ie_buf[IEEE80211_MAX_SSID_LEN + sizeof(struct ieee_types_header)];
Amitkumar Karwar4ed5d522011-09-21 21:43:24 -07001197 enum ieee80211_band band;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001198
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001199 if (mwifiex_get_bss_info(priv, &bss_info))
1200 return -1;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001201
1202 ie_buf[0] = WLAN_EID_SSID;
1203 ie_buf[1] = bss_info.ssid.ssid_len;
1204
1205 memcpy(&ie_buf[sizeof(struct ieee_types_header)],
Yogesh Ashok Powaraea07012012-03-13 19:22:35 -07001206 &bss_info.ssid.ssid, bss_info.ssid.ssid_len);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001207 ie_len = ie_buf[1] + sizeof(struct ieee_types_header);
1208
Amitkumar Karwar4ed5d522011-09-21 21:43:24 -07001209 band = mwifiex_band_to_radio_type(priv->curr_bss_params.band);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001210 chan = __ieee80211_get_channel(priv->wdev->wiphy,
1211 ieee80211_channel_to_frequency(bss_info.bss_chan,
Amitkumar Karwar4ed5d522011-09-21 21:43:24 -07001212 band));
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001213
Amitkumar Karwaraa95a482011-11-07 21:41:12 -08001214 bss = cfg80211_inform_bss(priv->wdev->wiphy, chan,
Yogesh Ashok Powaraea07012012-03-13 19:22:35 -07001215 bss_info.bssid, 0, WLAN_CAPABILITY_IBSS,
1216 0, ie_buf, ie_len, 0, GFP_KERNEL);
Amitkumar Karwaraa95a482011-11-07 21:41:12 -08001217 cfg80211_put_bss(bss);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001218 memcpy(priv->cfg_bssid, bss_info.bssid, ETH_ALEN);
1219
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001220 return 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001221}
1222
1223/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001224 * This function connects with a BSS.
1225 *
1226 * This function handles both Infra and Ad-Hoc modes. It also performs
1227 * validity checking on the provided parameters, disconnects from the
1228 * current BSS (if any), sets up the association/scan parameters,
1229 * including security settings, and performs specific SSID scan before
1230 * trying to connect.
1231 *
1232 * For Infra mode, the function returns failure if the specified SSID
1233 * is not found in scan table. However, for Ad-Hoc mode, it can create
1234 * the IBSS if it does not exist. On successful completion in either case,
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001235 * the function notifies the CFG802.11 subsystem of the new BSS connection.
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001236 */
1237static int
1238mwifiex_cfg80211_assoc(struct mwifiex_private *priv, size_t ssid_len, u8 *ssid,
1239 u8 *bssid, int mode, struct ieee80211_channel *channel,
1240 struct cfg80211_connect_params *sme, bool privacy)
1241{
Amitkumar Karwarb9be5f32012-02-27 22:04:14 -08001242 struct cfg80211_ssid req_ssid;
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -07001243 int ret, auth_type = 0;
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001244 struct cfg80211_bss *bss = NULL;
Amitkumar Karwar05910f42012-07-13 20:09:32 -07001245 u8 is_scanning_required = 0, config_bands = 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001246
Amitkumar Karwarb9be5f32012-02-27 22:04:14 -08001247 memset(&req_ssid, 0, sizeof(struct cfg80211_ssid));
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001248
1249 req_ssid.ssid_len = ssid_len;
1250 if (ssid_len > IEEE80211_MAX_SSID_LEN) {
1251 dev_err(priv->adapter->dev, "invalid SSID - aborting\n");
1252 return -EINVAL;
1253 }
1254
1255 memcpy(req_ssid.ssid, ssid, ssid_len);
1256 if (!req_ssid.ssid_len || req_ssid.ssid[0] < 0x20) {
1257 dev_err(priv->adapter->dev, "invalid SSID - aborting\n");
1258 return -EINVAL;
1259 }
1260
1261 /* disconnect before try to associate */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001262 mwifiex_deauthenticate(priv, NULL);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001263
Amitkumar Karwar05910f42012-07-13 20:09:32 -07001264 if (channel) {
1265 if (mode == NL80211_IFTYPE_STATION) {
1266 if (channel->band == IEEE80211_BAND_2GHZ)
1267 config_bands = BAND_B | BAND_G | BAND_GN;
1268 else
1269 config_bands = BAND_A | BAND_AN;
1270
1271 if (!((config_bands | priv->adapter->fw_bands) &
1272 ~priv->adapter->fw_bands))
1273 priv->adapter->config_bands = config_bands;
1274 }
Amitkumar Karwar05910f42012-07-13 20:09:32 -07001275 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001276
Amitkumar Karwar6670f152012-02-09 18:32:22 -08001277 /* As this is new association, clear locally stored
1278 * keys and security related flags */
1279 priv->sec_info.wpa_enabled = false;
1280 priv->sec_info.wpa2_enabled = false;
1281 priv->wep_key_curr_index = 0;
Amitkumar Karwar00f157b2012-02-24 21:35:35 -08001282 priv->sec_info.encryption_mode = 0;
Amitkumar Karwara0f6d6c2012-02-24 21:36:05 -08001283 priv->sec_info.is_authtype_auto = 0;
Ying Luo53b11232012-08-03 18:06:13 -07001284 ret = mwifiex_set_encode(priv, NULL, NULL, 0, 0, NULL, 1);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001285
Bing Zhaoeecd8252011-03-28 17:55:41 -07001286 if (mode == NL80211_IFTYPE_ADHOC) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001287 /* "privacy" is set only for ad-hoc mode */
1288 if (privacy) {
1289 /*
Yogesh Ashok Powar2be50b82011-04-01 18:36:47 -07001290 * Keep WLAN_CIPHER_SUITE_WEP104 for now so that
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001291 * the firmware can find a matching network from the
1292 * scan. The cfg80211 does not give us the encryption
1293 * mode at this stage so just setting it to WEP here.
1294 */
Marc Yang203afec2011-03-24 20:49:39 -07001295 priv->sec_info.encryption_mode =
Yogesh Ashok Powar2be50b82011-04-01 18:36:47 -07001296 WLAN_CIPHER_SUITE_WEP104;
Marc Yang203afec2011-03-24 20:49:39 -07001297 priv->sec_info.authentication_mode =
Marc Yangf986b6d2011-03-28 17:55:42 -07001298 NL80211_AUTHTYPE_OPEN_SYSTEM;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001299 }
1300
1301 goto done;
1302 }
1303
1304 /* Now handle infra mode. "sme" is valid for infra mode only */
Amitkumar Karwara0f6d6c2012-02-24 21:36:05 -08001305 if (sme->auth_type == NL80211_AUTHTYPE_AUTOMATIC) {
Marc Yangf986b6d2011-03-28 17:55:42 -07001306 auth_type = NL80211_AUTHTYPE_OPEN_SYSTEM;
Amitkumar Karwara0f6d6c2012-02-24 21:36:05 -08001307 priv->sec_info.is_authtype_auto = 1;
1308 } else {
1309 auth_type = sme->auth_type;
1310 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001311
1312 if (sme->crypto.n_ciphers_pairwise) {
Yogesh Ashok Powar2be50b82011-04-01 18:36:47 -07001313 priv->sec_info.encryption_mode =
1314 sme->crypto.ciphers_pairwise[0];
Marc Yang203afec2011-03-24 20:49:39 -07001315 priv->sec_info.authentication_mode = auth_type;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001316 }
1317
1318 if (sme->crypto.cipher_group) {
Yogesh Ashok Powar2be50b82011-04-01 18:36:47 -07001319 priv->sec_info.encryption_mode = sme->crypto.cipher_group;
Marc Yang203afec2011-03-24 20:49:39 -07001320 priv->sec_info.authentication_mode = auth_type;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001321 }
1322 if (sme->ie)
1323 ret = mwifiex_set_gen_ie(priv, sme->ie, sme->ie_len);
1324
1325 if (sme->key) {
Amitkumar Karware6faada2011-07-07 17:33:19 -07001326 if (mwifiex_is_alg_wep(priv->sec_info.encryption_mode)) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001327 dev_dbg(priv->adapter->dev,
1328 "info: setting wep encryption"
1329 " with key len %d\n", sme->key_len);
Amitkumar Karwar6670f152012-02-09 18:32:22 -08001330 priv->wep_key_curr_index = sme->key_idx;
Ying Luo53b11232012-08-03 18:06:13 -07001331 ret = mwifiex_set_encode(priv, NULL, sme->key,
1332 sme->key_len, sme->key_idx,
1333 NULL, 0);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001334 }
1335 }
1336done:
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001337 /*
1338 * Scan entries are valid for some time (15 sec). So we can save one
1339 * active scan time if we just try cfg80211_get_bss first. If it fails
1340 * then request scan and cfg80211_get_bss() again for final output.
1341 */
1342 while (1) {
1343 if (is_scanning_required) {
1344 /* Do specific SSID scanning */
1345 if (mwifiex_request_scan(priv, &req_ssid)) {
1346 dev_err(priv->adapter->dev, "scan error\n");
1347 return -EFAULT;
1348 }
1349 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001350
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001351 /* Find the BSS we want using available scan results */
1352 if (mode == NL80211_IFTYPE_ADHOC)
1353 bss = cfg80211_get_bss(priv->wdev->wiphy, channel,
1354 bssid, ssid, ssid_len,
1355 WLAN_CAPABILITY_IBSS,
1356 WLAN_CAPABILITY_IBSS);
1357 else
1358 bss = cfg80211_get_bss(priv->wdev->wiphy, channel,
1359 bssid, ssid, ssid_len,
1360 WLAN_CAPABILITY_ESS,
1361 WLAN_CAPABILITY_ESS);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001362
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001363 if (!bss) {
1364 if (is_scanning_required) {
Yogesh Ashok Powaraea07012012-03-13 19:22:35 -07001365 dev_warn(priv->adapter->dev,
1366 "assoc: requested bss not found in scan results\n");
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001367 break;
1368 }
1369 is_scanning_required = 1;
1370 } else {
Yogesh Ashok Powaraea07012012-03-13 19:22:35 -07001371 dev_dbg(priv->adapter->dev,
1372 "info: trying to associate to '%s' bssid %pM\n",
1373 (char *) req_ssid.ssid, bss->bssid);
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001374 memcpy(&priv->cfg_bssid, bss->bssid, ETH_ALEN);
1375 break;
1376 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001377 }
1378
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001379 if (mwifiex_bss_start(priv, bss, &req_ssid))
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001380 return -EFAULT;
1381
Bing Zhaoeecd8252011-03-28 17:55:41 -07001382 if (mode == NL80211_IFTYPE_ADHOC) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001383 /* Inform the BSS information to kernel, otherwise
1384 * kernel will give a panic after successful assoc */
1385 if (mwifiex_cfg80211_inform_ibss_bss(priv))
1386 return -EFAULT;
1387 }
1388
1389 return ret;
1390}
1391
1392/*
1393 * CFG802.11 operation handler for association request.
1394 *
1395 * This function does not work when the current mode is set to Ad-Hoc, or
1396 * when there is already an association procedure going on. The given BSS
1397 * information is used to associate.
1398 */
1399static int
1400mwifiex_cfg80211_connect(struct wiphy *wiphy, struct net_device *dev,
1401 struct cfg80211_connect_params *sme)
1402{
1403 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
1404 int ret = 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001405
Bing Zhaoeecd8252011-03-28 17:55:41 -07001406 if (priv->bss_mode == NL80211_IFTYPE_ADHOC) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001407 wiphy_err(wiphy, "received infra assoc request "
1408 "when station is in ibss mode\n");
1409 goto done;
1410 }
1411
Avinash Patile5686342012-05-08 18:30:25 -07001412 if (priv->bss_mode == NL80211_IFTYPE_AP) {
1413 wiphy_err(wiphy, "skip association request for AP interface\n");
1414 goto done;
1415 }
1416
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001417 wiphy_dbg(wiphy, "info: Trying to associate to %s and bssid %pM\n",
Yogesh Ashok Powaraea07012012-03-13 19:22:35 -07001418 (char *) sme->ssid, sme->bssid);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001419
1420 ret = mwifiex_cfg80211_assoc(priv, sme->ssid_len, sme->ssid, sme->bssid,
Bing Zhaoeecd8252011-03-28 17:55:41 -07001421 priv->bss_mode, sme->channel, sme, 0);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001422done:
Amitkumar Karwar38c9d662011-12-13 20:43:17 -08001423 if (!ret) {
1424 cfg80211_connect_result(priv->netdev, priv->cfg_bssid, NULL, 0,
1425 NULL, 0, WLAN_STATUS_SUCCESS,
1426 GFP_KERNEL);
1427 dev_dbg(priv->adapter->dev,
1428 "info: associated to bssid %pM successfully\n",
1429 priv->cfg_bssid);
1430 } else {
1431 dev_dbg(priv->adapter->dev,
1432 "info: association to bssid %pM failed\n",
1433 priv->cfg_bssid);
1434 memset(priv->cfg_bssid, 0, ETH_ALEN);
1435 }
1436
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001437 return ret;
1438}
1439
1440/*
Amitkumar Karwar05910f42012-07-13 20:09:32 -07001441 * This function sets following parameters for ibss network.
1442 * - channel
1443 * - start band
1444 * - 11n flag
1445 * - secondary channel offset
1446 */
1447static int mwifiex_set_ibss_params(struct mwifiex_private *priv,
1448 struct cfg80211_ibss_params *params)
1449{
1450 struct wiphy *wiphy = priv->wdev->wiphy;
1451 struct mwifiex_adapter *adapter = priv->adapter;
1452 int index = 0, i;
1453 u8 config_bands = 0;
1454
1455 if (params->channel->band == IEEE80211_BAND_2GHZ) {
1456 if (!params->basic_rates) {
1457 config_bands = BAND_B | BAND_G;
1458 } else {
1459 for (i = 0; i < mwifiex_band_2ghz.n_bitrates; i++) {
1460 /*
1461 * Rates below 6 Mbps in the table are CCK
1462 * rates; 802.11b and from 6 they are OFDM;
1463 * 802.11G
1464 */
1465 if (mwifiex_rates[i].bitrate == 60) {
1466 index = 1 << i;
1467 break;
1468 }
1469 }
1470
1471 if (params->basic_rates < index) {
1472 config_bands = BAND_B;
1473 } else {
1474 config_bands = BAND_G;
1475 if (params->basic_rates % index)
1476 config_bands |= BAND_B;
1477 }
1478 }
1479
1480 if (params->channel_type != NL80211_CHAN_NO_HT)
1481 config_bands |= BAND_GN;
1482 } else {
1483 if (params->channel_type == NL80211_CHAN_NO_HT)
1484 config_bands = BAND_A;
1485 else
1486 config_bands = BAND_AN | BAND_A;
1487 }
1488
1489 if (!((config_bands | adapter->fw_bands) & ~adapter->fw_bands)) {
1490 adapter->config_bands = config_bands;
1491 adapter->adhoc_start_band = config_bands;
1492
1493 if ((config_bands & BAND_GN) || (config_bands & BAND_AN))
1494 adapter->adhoc_11n_enabled = true;
1495 else
1496 adapter->adhoc_11n_enabled = false;
1497 }
1498
1499 adapter->sec_chan_offset =
1500 mwifiex_chan_type_to_sec_chan_offset(params->channel_type);
1501 priv->adhoc_channel =
1502 ieee80211_frequency_to_channel(params->channel->center_freq);
1503
1504 wiphy_dbg(wiphy, "info: set ibss band %d, chan %d, chan offset %d\n",
1505 config_bands, priv->adhoc_channel, adapter->sec_chan_offset);
1506
1507 return 0;
1508}
1509
1510/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001511 * CFG802.11 operation handler to join an IBSS.
1512 *
1513 * This function does not work in any mode other than Ad-Hoc, or if
1514 * a join operation is already in progress.
1515 */
1516static int
1517mwifiex_cfg80211_join_ibss(struct wiphy *wiphy, struct net_device *dev,
1518 struct cfg80211_ibss_params *params)
1519{
Yogesh Ashok Powarf540f9f2012-01-11 20:06:12 -08001520 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001521 int ret = 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001522
Bing Zhaoeecd8252011-03-28 17:55:41 -07001523 if (priv->bss_mode != NL80211_IFTYPE_ADHOC) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001524 wiphy_err(wiphy, "request to join ibss received "
1525 "when station is not in ibss mode\n");
1526 goto done;
1527 }
1528
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001529 wiphy_dbg(wiphy, "info: trying to join to %s and bssid %pM\n",
Yogesh Ashok Powaraea07012012-03-13 19:22:35 -07001530 (char *) params->ssid, params->bssid);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001531
Amitkumar Karwar05910f42012-07-13 20:09:32 -07001532 mwifiex_set_ibss_params(priv, params);
1533
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001534 ret = mwifiex_cfg80211_assoc(priv, params->ssid_len, params->ssid,
Yogesh Ashok Powaraea07012012-03-13 19:22:35 -07001535 params->bssid, priv->bss_mode,
1536 params->channel, NULL, params->privacy);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001537done:
Amitkumar Karwar38c9d662011-12-13 20:43:17 -08001538 if (!ret) {
1539 cfg80211_ibss_joined(priv->netdev, priv->cfg_bssid, GFP_KERNEL);
1540 dev_dbg(priv->adapter->dev,
1541 "info: joined/created adhoc network with bssid"
1542 " %pM successfully\n", priv->cfg_bssid);
1543 } else {
1544 dev_dbg(priv->adapter->dev,
1545 "info: failed creating/joining adhoc network\n");
1546 }
1547
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001548 return ret;
1549}
1550
1551/*
1552 * CFG802.11 operation handler to leave an IBSS.
1553 *
1554 * This function does not work if a leave operation is
1555 * already in progress.
1556 */
1557static int
1558mwifiex_cfg80211_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
1559{
Yogesh Ashok Powarf540f9f2012-01-11 20:06:12 -08001560 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001561
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001562 wiphy_dbg(wiphy, "info: disconnecting from essid %pM\n",
Yogesh Ashok Powaraea07012012-03-13 19:22:35 -07001563 priv->cfg_bssid);
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001564 if (mwifiex_deauthenticate(priv, NULL))
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001565 return -EFAULT;
1566
Amitkumar Karwar38c9d662011-12-13 20:43:17 -08001567 memset(priv->cfg_bssid, 0, ETH_ALEN);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001568
1569 return 0;
1570}
1571
1572/*
1573 * CFG802.11 operation handler for scan request.
1574 *
1575 * This function issues a scan request to the firmware based upon
1576 * the user specified scan configuration. On successfull completion,
1577 * it also informs the results.
1578 */
1579static int
Johannes Bergfd014282012-06-18 19:17:03 +02001580mwifiex_cfg80211_scan(struct wiphy *wiphy,
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001581 struct cfg80211_scan_request *request)
1582{
Johannes Bergfd014282012-06-18 19:17:03 +02001583 struct net_device *dev = request->wdev->netdev;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001584 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
Amitkumar Karwar38c9d662011-12-13 20:43:17 -08001585 int i;
1586 struct ieee80211_channel *chan;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001587
1588 wiphy_dbg(wiphy, "info: received scan request on %s\n", dev->name);
1589
Amitkumar Karwarde093642012-09-20 20:23:18 -07001590 if (atomic_read(&priv->wmm.tx_pkts_queued) >=
1591 MWIFIEX_MIN_TX_PENDING_TO_CANCEL_SCAN) {
1592 dev_dbg(priv->adapter->dev, "scan rejected due to traffic\n");
1593 return -EBUSY;
1594 }
1595
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001596 priv->scan_request = request;
1597
Amitkumar Karwar38c9d662011-12-13 20:43:17 -08001598 priv->user_scan_cfg = kzalloc(sizeof(struct mwifiex_user_scan_cfg),
Yogesh Ashok Powaraea07012012-03-13 19:22:35 -07001599 GFP_KERNEL);
Amitkumar Karwar38c9d662011-12-13 20:43:17 -08001600 if (!priv->user_scan_cfg) {
1601 dev_err(priv->adapter->dev, "failed to alloc scan_req\n");
1602 return -ENOMEM;
1603 }
Amitkumar Karwarbe0b2812012-02-27 22:04:15 -08001604
1605 priv->user_scan_cfg->num_ssids = request->n_ssids;
1606 priv->user_scan_cfg->ssid_list = request->ssids;
1607
Avinash Patil13d7ba72012-04-09 20:06:56 -07001608 if (request->ie && request->ie_len) {
1609 for (i = 0; i < MWIFIEX_MAX_VSIE_NUM; i++) {
1610 if (priv->vs_ie[i].mask != MWIFIEX_VSIE_MASK_CLEAR)
1611 continue;
1612 priv->vs_ie[i].mask = MWIFIEX_VSIE_MASK_SCAN;
1613 memcpy(&priv->vs_ie[i].ie, request->ie,
1614 request->ie_len);
1615 break;
1616 }
1617 }
1618
Amitkumar Karwar38c9d662011-12-13 20:43:17 -08001619 for (i = 0; i < request->n_channels; i++) {
1620 chan = request->channels[i];
1621 priv->user_scan_cfg->chan_list[i].chan_number = chan->hw_value;
1622 priv->user_scan_cfg->chan_list[i].radio_type = chan->band;
1623
1624 if (chan->flags & IEEE80211_CHAN_PASSIVE_SCAN)
1625 priv->user_scan_cfg->chan_list[i].scan_type =
Yogesh Ashok Powaraea07012012-03-13 19:22:35 -07001626 MWIFIEX_SCAN_TYPE_PASSIVE;
Amitkumar Karwar38c9d662011-12-13 20:43:17 -08001627 else
1628 priv->user_scan_cfg->chan_list[i].scan_type =
Yogesh Ashok Powaraea07012012-03-13 19:22:35 -07001629 MWIFIEX_SCAN_TYPE_ACTIVE;
Amitkumar Karwar38c9d662011-12-13 20:43:17 -08001630
1631 priv->user_scan_cfg->chan_list[i].scan_time = 0;
1632 }
Amitkumar Karwar1a1fb972012-06-27 19:57:56 -07001633 if (mwifiex_scan_networks(priv, priv->user_scan_cfg))
Amitkumar Karwar38c9d662011-12-13 20:43:17 -08001634 return -EFAULT;
1635
Avinash Patil13d7ba72012-04-09 20:06:56 -07001636 if (request->ie && request->ie_len) {
1637 for (i = 0; i < MWIFIEX_MAX_VSIE_NUM; i++) {
1638 if (priv->vs_ie[i].mask == MWIFIEX_VSIE_MASK_SCAN) {
1639 priv->vs_ie[i].mask = MWIFIEX_VSIE_MASK_CLEAR;
1640 memset(&priv->vs_ie[i].ie, 0,
1641 MWIFIEX_MAX_VSIE_LEN);
1642 }
1643 }
1644 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001645 return 0;
1646}
1647
1648/*
1649 * This function sets up the CFG802.11 specific HT capability fields
1650 * with default values.
1651 *
1652 * The following default values are set -
1653 * - HT Supported = True
Amitkumar Karwara46b7b52011-04-27 19:13:12 -07001654 * - Maximum AMPDU length factor = IEEE80211_HT_MAX_AMPDU_64K
1655 * - Minimum AMPDU spacing = IEEE80211_HT_MPDU_DENSITY_NONE
1656 * - HT Capabilities supported by firmware
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001657 * - MCS information, Rx mask = 0xff
1658 * - MCD information, Tx parameters = IEEE80211_HT_MCS_TX_DEFINED (0x01)
1659 */
1660static void
1661mwifiex_setup_ht_caps(struct ieee80211_sta_ht_cap *ht_info,
1662 struct mwifiex_private *priv)
1663{
1664 int rx_mcs_supp;
1665 struct ieee80211_mcs_info mcs_set;
1666 u8 *mcs = (u8 *)&mcs_set;
1667 struct mwifiex_adapter *adapter = priv->adapter;
1668
1669 ht_info->ht_supported = true;
Amitkumar Karwara46b7b52011-04-27 19:13:12 -07001670 ht_info->ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
1671 ht_info->ampdu_density = IEEE80211_HT_MPDU_DENSITY_NONE;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001672
1673 memset(&ht_info->mcs, 0, sizeof(ht_info->mcs));
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001674
Amitkumar Karwara46b7b52011-04-27 19:13:12 -07001675 /* Fill HT capability information */
1676 if (ISSUPP_CHANWIDTH40(adapter->hw_dot_11n_dev_cap))
1677 ht_info->cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
1678 else
1679 ht_info->cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
1680
1681 if (ISSUPP_SHORTGI20(adapter->hw_dot_11n_dev_cap))
1682 ht_info->cap |= IEEE80211_HT_CAP_SGI_20;
1683 else
1684 ht_info->cap &= ~IEEE80211_HT_CAP_SGI_20;
1685
1686 if (ISSUPP_SHORTGI40(adapter->hw_dot_11n_dev_cap))
1687 ht_info->cap |= IEEE80211_HT_CAP_SGI_40;
1688 else
1689 ht_info->cap &= ~IEEE80211_HT_CAP_SGI_40;
1690
1691 if (ISSUPP_RXSTBC(adapter->hw_dot_11n_dev_cap))
1692 ht_info->cap |= 1 << IEEE80211_HT_CAP_RX_STBC_SHIFT;
1693 else
1694 ht_info->cap &= ~(3 << IEEE80211_HT_CAP_RX_STBC_SHIFT);
1695
1696 if (ISSUPP_TXSTBC(adapter->hw_dot_11n_dev_cap))
1697 ht_info->cap |= IEEE80211_HT_CAP_TX_STBC;
1698 else
1699 ht_info->cap &= ~IEEE80211_HT_CAP_TX_STBC;
1700
1701 ht_info->cap &= ~IEEE80211_HT_CAP_MAX_AMSDU;
1702 ht_info->cap |= IEEE80211_HT_CAP_SM_PS;
1703
1704 rx_mcs_supp = GET_RXMCSSUPP(adapter->hw_dev_mcs_support);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001705 /* Set MCS for 1x1 */
1706 memset(mcs, 0xff, rx_mcs_supp);
1707 /* Clear all the other values */
1708 memset(&mcs[rx_mcs_supp], 0,
Yogesh Ashok Powaraea07012012-03-13 19:22:35 -07001709 sizeof(struct ieee80211_mcs_info) - rx_mcs_supp);
Bing Zhaoeecd8252011-03-28 17:55:41 -07001710 if (priv->bss_mode == NL80211_IFTYPE_STATION ||
Yogesh Ashok Powaraea07012012-03-13 19:22:35 -07001711 ISSUPP_CHANWIDTH40(adapter->hw_dot_11n_dev_cap))
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001712 /* Set MCS32 for infra mode or ad-hoc mode with 40MHz support */
1713 SETHT_MCS32(mcs_set.rx_mask);
1714
1715 memcpy((u8 *) &ht_info->mcs, mcs, sizeof(struct ieee80211_mcs_info));
1716
1717 ht_info->mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED;
1718}
1719
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -07001720/*
1721 * create a new virtual interface with the given name
1722 */
Johannes Berg84efbb82012-06-16 00:00:26 +02001723struct wireless_dev *mwifiex_add_virtual_intf(struct wiphy *wiphy,
Johannes Berg552bff02012-09-19 09:26:06 +02001724 const char *name,
Johannes Berg84efbb82012-06-16 00:00:26 +02001725 enum nl80211_iftype type,
1726 u32 *flags,
1727 struct vif_params *params)
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -07001728{
Avinash Patil67fdf392012-05-08 18:30:17 -07001729 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
1730 struct mwifiex_private *priv;
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -07001731 struct net_device *dev;
1732 void *mdev_priv;
Avinash Patild6bffe82012-05-08 18:30:15 -07001733 struct wireless_dev *wdev;
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -07001734
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -07001735 if (!adapter)
Bing Zhao858faa52012-06-15 15:49:54 -07001736 return ERR_PTR(-EFAULT);
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -07001737
1738 switch (type) {
1739 case NL80211_IFTYPE_UNSPECIFIED:
1740 case NL80211_IFTYPE_STATION:
1741 case NL80211_IFTYPE_ADHOC:
Avinash Patild6bffe82012-05-08 18:30:15 -07001742 priv = adapter->priv[MWIFIEX_BSS_TYPE_STA];
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -07001743 if (priv->bss_mode) {
Avinash Patild6bffe82012-05-08 18:30:15 -07001744 wiphy_err(wiphy,
1745 "cannot create multiple sta/adhoc ifaces\n");
Bing Zhao858faa52012-06-15 15:49:54 -07001746 return ERR_PTR(-EINVAL);
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -07001747 }
1748
Avinash Patild6bffe82012-05-08 18:30:15 -07001749 wdev = kzalloc(sizeof(struct wireless_dev), GFP_KERNEL);
1750 if (!wdev)
Bing Zhao858faa52012-06-15 15:49:54 -07001751 return ERR_PTR(-ENOMEM);
Avinash Patild6bffe82012-05-08 18:30:15 -07001752
1753 wdev->wiphy = wiphy;
1754 priv->wdev = wdev;
1755 wdev->iftype = NL80211_IFTYPE_STATION;
1756
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -07001757 if (type == NL80211_IFTYPE_UNSPECIFIED)
1758 priv->bss_mode = NL80211_IFTYPE_STATION;
1759 else
1760 priv->bss_mode = type;
1761
1762 priv->bss_type = MWIFIEX_BSS_TYPE_STA;
1763 priv->frame_type = MWIFIEX_DATA_FRAME_TYPE_ETH_II;
Amitkumar Karwara458c0a2012-09-10 18:30:43 -07001764 priv->bss_priority = 0;
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -07001765 priv->bss_role = MWIFIEX_BSS_ROLE_STA;
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -07001766 priv->bss_num = 0;
1767
1768 break;
Avinash Patild6bffe82012-05-08 18:30:15 -07001769 case NL80211_IFTYPE_AP:
1770 priv = adapter->priv[MWIFIEX_BSS_TYPE_UAP];
1771
1772 if (priv->bss_mode) {
1773 wiphy_err(wiphy, "Can't create multiple AP interfaces");
Bing Zhao858faa52012-06-15 15:49:54 -07001774 return ERR_PTR(-EINVAL);
Avinash Patild6bffe82012-05-08 18:30:15 -07001775 }
1776
1777 wdev = kzalloc(sizeof(struct wireless_dev), GFP_KERNEL);
1778 if (!wdev)
Bing Zhao858faa52012-06-15 15:49:54 -07001779 return ERR_PTR(-ENOMEM);
Avinash Patild6bffe82012-05-08 18:30:15 -07001780
1781 priv->wdev = wdev;
1782 wdev->wiphy = wiphy;
1783 wdev->iftype = NL80211_IFTYPE_AP;
1784
1785 priv->bss_type = MWIFIEX_BSS_TYPE_UAP;
1786 priv->frame_type = MWIFIEX_DATA_FRAME_TYPE_ETH_II;
Amitkumar Karwara458c0a2012-09-10 18:30:43 -07001787 priv->bss_priority = 0;
Avinash Patild6bffe82012-05-08 18:30:15 -07001788 priv->bss_role = MWIFIEX_BSS_ROLE_UAP;
1789 priv->bss_started = 0;
1790 priv->bss_num = 0;
1791 priv->bss_mode = type;
1792
1793 break;
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -07001794 default:
1795 wiphy_err(wiphy, "type not supported\n");
Bing Zhao858faa52012-06-15 15:49:54 -07001796 return ERR_PTR(-EINVAL);
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -07001797 }
1798
1799 dev = alloc_netdev_mq(sizeof(struct mwifiex_private *), name,
1800 ether_setup, 1);
1801 if (!dev) {
1802 wiphy_err(wiphy, "no memory available for netdevice\n");
Bing Zhao858faa52012-06-15 15:49:54 -07001803 priv->bss_mode = NL80211_IFTYPE_UNSPECIFIED;
1804 return ERR_PTR(-ENOMEM);
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -07001805 }
1806
Avinash Patild6bffe82012-05-08 18:30:15 -07001807 mwifiex_init_priv_params(priv, dev);
1808 priv->netdev = dev;
1809
1810 mwifiex_setup_ht_caps(&wiphy->bands[IEEE80211_BAND_2GHZ]->ht_cap, priv);
1811
1812 if (adapter->config_bands & BAND_A)
1813 mwifiex_setup_ht_caps(
1814 &wiphy->bands[IEEE80211_BAND_5GHZ]->ht_cap, priv);
1815
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -07001816 dev_net_set(dev, wiphy_net(wiphy));
1817 dev->ieee80211_ptr = priv->wdev;
1818 dev->ieee80211_ptr->iftype = priv->bss_mode;
1819 memcpy(dev->dev_addr, wiphy->perm_addr, ETH_ALEN);
1820 memcpy(dev->perm_addr, wiphy->perm_addr, ETH_ALEN);
1821 SET_NETDEV_DEV(dev, wiphy_dev(wiphy));
1822
1823 dev->flags |= IFF_BROADCAST | IFF_MULTICAST;
1824 dev->watchdog_timeo = MWIFIEX_DEFAULT_WATCHDOG_TIMEOUT;
1825 dev->hard_header_len += MWIFIEX_MIN_DATA_HEADER_LEN;
1826
1827 mdev_priv = netdev_priv(dev);
1828 *((unsigned long *) mdev_priv) = (unsigned long) priv;
1829
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -07001830 SET_NETDEV_DEV(dev, adapter->dev);
1831
1832 /* Register network device */
1833 if (register_netdevice(dev)) {
1834 wiphy_err(wiphy, "cannot register virtual network device\n");
Bing Zhao858faa52012-06-15 15:49:54 -07001835 free_netdev(dev);
1836 priv->bss_mode = NL80211_IFTYPE_UNSPECIFIED;
1837 return ERR_PTR(-EFAULT);
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -07001838 }
1839
1840 sema_init(&priv->async_sem, 1);
1841 priv->scan_pending_on_block = false;
1842
1843 dev_dbg(adapter->dev, "info: %s: Marvell 802.11 Adapter\n", dev->name);
1844
1845#ifdef CONFIG_DEBUG_FS
1846 mwifiex_dev_debugfs_init(priv);
1847#endif
Johannes Berg84efbb82012-06-16 00:00:26 +02001848 return wdev;
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -07001849}
1850EXPORT_SYMBOL_GPL(mwifiex_add_virtual_intf);
1851
1852/*
1853 * del_virtual_intf: remove the virtual interface determined by dev
1854 */
Johannes Berg84efbb82012-06-16 00:00:26 +02001855int mwifiex_del_virtual_intf(struct wiphy *wiphy, struct wireless_dev *wdev)
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -07001856{
Johannes Berg84efbb82012-06-16 00:00:26 +02001857 struct mwifiex_private *priv = mwifiex_netdev_get_priv(wdev->netdev);
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -07001858
1859#ifdef CONFIG_DEBUG_FS
1860 mwifiex_dev_debugfs_remove(priv);
1861#endif
1862
1863 if (!netif_queue_stopped(priv->netdev))
1864 netif_stop_queue(priv->netdev);
1865
1866 if (netif_carrier_ok(priv->netdev))
1867 netif_carrier_off(priv->netdev);
1868
Johannes Berg84efbb82012-06-16 00:00:26 +02001869 if (wdev->netdev->reg_state == NETREG_REGISTERED)
1870 unregister_netdevice(wdev->netdev);
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -07001871
Johannes Berg84efbb82012-06-16 00:00:26 +02001872 if (wdev->netdev->reg_state == NETREG_UNREGISTERED)
1873 free_netdev(wdev->netdev);
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -07001874
1875 /* Clear the priv in adapter */
1876 priv->netdev = NULL;
1877
1878 priv->media_connected = false;
1879
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -07001880 priv->bss_mode = NL80211_IFTYPE_UNSPECIFIED;
1881
1882 return 0;
1883}
1884EXPORT_SYMBOL_GPL(mwifiex_del_virtual_intf);
1885
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001886/* station cfg80211 operations */
1887static struct cfg80211_ops mwifiex_cfg80211_ops = {
Yogesh Ashok Powar93a1df42011-09-26 20:37:26 -07001888 .add_virtual_intf = mwifiex_add_virtual_intf,
1889 .del_virtual_intf = mwifiex_del_virtual_intf,
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001890 .change_virtual_intf = mwifiex_cfg80211_change_virtual_intf,
1891 .scan = mwifiex_cfg80211_scan,
1892 .connect = mwifiex_cfg80211_connect,
1893 .disconnect = mwifiex_cfg80211_disconnect,
1894 .get_station = mwifiex_cfg80211_get_station,
Amitkumar Karwarf85aae62012-03-15 20:51:48 -07001895 .dump_station = mwifiex_cfg80211_dump_station,
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001896 .set_wiphy_params = mwifiex_cfg80211_set_wiphy_params,
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001897 .join_ibss = mwifiex_cfg80211_join_ibss,
1898 .leave_ibss = mwifiex_cfg80211_leave_ibss,
1899 .add_key = mwifiex_cfg80211_add_key,
1900 .del_key = mwifiex_cfg80211_del_key,
Stone Piaoe39faa72012-09-25 20:23:32 -07001901 .mgmt_tx = mwifiex_cfg80211_mgmt_tx,
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001902 .set_default_key = mwifiex_cfg80211_set_default_key,
1903 .set_power_mgmt = mwifiex_cfg80211_set_power_mgmt,
1904 .set_tx_power = mwifiex_cfg80211_set_tx_power,
Yogesh Ashok Powar5d82c532011-07-11 20:04:44 -07001905 .set_bitrate_mask = mwifiex_cfg80211_set_bitrate_mask,
Avinash Patil12190c52012-05-08 18:30:24 -07001906 .start_ap = mwifiex_cfg80211_start_ap,
1907 .stop_ap = mwifiex_cfg80211_stop_ap,
Avinash Patil5370c832012-06-28 20:30:28 -07001908 .change_beacon = mwifiex_cfg80211_change_beacon,
Amitkumar Karwarfa444bf2012-03-15 20:51:51 -07001909 .set_cqm_rssi_config = mwifiex_cfg80211_set_cqm_rssi_config,
Amitkumar Karwar8a279d52012-07-02 19:32:33 -07001910 .set_antenna = mwifiex_cfg80211_set_antenna,
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001911};
1912
1913/*
1914 * This function registers the device with CFG802.11 subsystem.
1915 *
1916 * The function creates the wireless device/wiphy, populates it with
1917 * default parameters and handler function pointers, and finally
1918 * registers the device.
1919 */
Avinash Patild6bffe82012-05-08 18:30:15 -07001920
1921int mwifiex_register_cfg80211(struct mwifiex_adapter *adapter)
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001922{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -07001923 int ret;
1924 void *wdev_priv;
Avinash Patild6bffe82012-05-08 18:30:15 -07001925 struct wiphy *wiphy;
1926 struct mwifiex_private *priv = adapter->priv[MWIFIEX_BSS_TYPE_STA];
Amitkumar Karwar9e04a7c2012-04-09 20:06:54 -07001927 u8 *country_code;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001928
Avinash Patild6bffe82012-05-08 18:30:15 -07001929 /* create a new wiphy for use with cfg80211 */
1930 wiphy = wiphy_new(&mwifiex_cfg80211_ops,
1931 sizeof(struct mwifiex_adapter *));
1932 if (!wiphy) {
1933 dev_err(adapter->dev, "%s: creating new wiphy\n", __func__);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001934 return -ENOMEM;
1935 }
Avinash Patild6bffe82012-05-08 18:30:15 -07001936 wiphy->max_scan_ssids = MWIFIEX_MAX_SSID_LIST_LENGTH;
1937 wiphy->max_scan_ie_len = MWIFIEX_MAX_VSIE_LEN;
1938 wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
1939 BIT(NL80211_IFTYPE_ADHOC) |
1940 BIT(NL80211_IFTYPE_AP);
Amitkumar Karwaradc89592011-04-27 19:13:11 -07001941
Avinash Patild6bffe82012-05-08 18:30:15 -07001942 wiphy->bands[IEEE80211_BAND_2GHZ] = &mwifiex_band_2ghz;
1943 if (adapter->config_bands & BAND_A)
1944 wiphy->bands[IEEE80211_BAND_5GHZ] = &mwifiex_band_5ghz;
1945 else
1946 wiphy->bands[IEEE80211_BAND_5GHZ] = NULL;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001947
Avinash Patilcd8440d2012-05-08 18:30:16 -07001948 wiphy->iface_combinations = &mwifiex_iface_comb_ap_sta;
1949 wiphy->n_iface_combinations = 1;
1950
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001951 /* Initialize cipher suits */
Avinash Patild6bffe82012-05-08 18:30:15 -07001952 wiphy->cipher_suites = mwifiex_cipher_suites;
1953 wiphy->n_cipher_suites = ARRAY_SIZE(mwifiex_cipher_suites);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001954
Avinash Patild6bffe82012-05-08 18:30:15 -07001955 memcpy(wiphy->perm_addr, priv->curr_addr, ETH_ALEN);
1956 wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
Avinash Patil2dd2bd62012-06-28 20:30:29 -07001957 wiphy->flags |= WIPHY_FLAG_HAVE_AP_SME |
Amitkumar Karwarcc0ba0d2012-09-10 18:30:47 -07001958 WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD |
1959 WIPHY_FLAG_CUSTOM_REGULATORY;
1960
1961 wiphy_apply_custom_regulatory(wiphy, &mwifiex_world_regdom_custom);
Avinash Patil2dd2bd62012-06-28 20:30:29 -07001962
1963 wiphy->probe_resp_offload = NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS |
Stone Piaoe39faa72012-09-25 20:23:32 -07001964 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2 |
1965 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001966
Amitkumar Karwar8a279d52012-07-02 19:32:33 -07001967 wiphy->available_antennas_tx = BIT(adapter->number_of_antenna) - 1;
1968 wiphy->available_antennas_rx = BIT(adapter->number_of_antenna) - 1;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001969
Amitkumar Karwar05910f42012-07-13 20:09:32 -07001970 wiphy->features = NL80211_FEATURE_HT_IBSS;
1971
Amitkumar Karwarb5abcf02012-04-16 21:36:52 -07001972 /* Reserve space for mwifiex specific private data for BSS */
Avinash Patild6bffe82012-05-08 18:30:15 -07001973 wiphy->bss_priv_size = sizeof(struct mwifiex_bss_priv);
Amitkumar Karwar5116f3c2011-09-21 21:43:23 -07001974
Avinash Patild6bffe82012-05-08 18:30:15 -07001975 wiphy->reg_notifier = mwifiex_reg_notifier;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001976
Avinash Patil67fdf392012-05-08 18:30:17 -07001977 /* Set struct mwifiex_adapter pointer in wiphy_priv */
Avinash Patild6bffe82012-05-08 18:30:15 -07001978 wdev_priv = wiphy_priv(wiphy);
Avinash Patil67fdf392012-05-08 18:30:17 -07001979 *(unsigned long *)wdev_priv = (unsigned long)adapter;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001980
Joe Perches2c208892012-06-04 12:44:17 +00001981 set_wiphy_dev(wiphy, priv->adapter->dev);
Yogesh Ashok Powara7b21162011-06-13 09:49:27 +05301982
Avinash Patild6bffe82012-05-08 18:30:15 -07001983 ret = wiphy_register(wiphy);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001984 if (ret < 0) {
Avinash Patild6bffe82012-05-08 18:30:15 -07001985 dev_err(adapter->dev,
1986 "%s: wiphy_register failed: %d\n", __func__, ret);
1987 wiphy_free(wiphy);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001988 return ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001989 }
Amitkumar Karwar9e04a7c2012-04-09 20:06:54 -07001990 country_code = mwifiex_11d_code_2_region(priv->adapter->region_code);
Bing Zhao77c8a142012-09-10 18:30:46 -07001991 if (country_code)
1992 dev_info(adapter->dev,
1993 "ignoring F/W country code %2.2s\n", country_code);
Amitkumar Karwar9e04a7c2012-04-09 20:06:54 -07001994
Avinash Patild6bffe82012-05-08 18:30:15 -07001995 adapter->wiphy = wiphy;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001996 return ret;
1997}