Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2004-2011 Atheros Communications Inc. |
Vasanthakumar Thiagarajan | 1b2df40 | 2012-02-06 20:15:53 +0530 | [diff] [blame] | 3 | * Copyright (c) 2011-2012 Qualcomm Atheros, Inc. |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 4 | * |
| 5 | * Permission to use, copy, modify, and/or distribute this software for any |
| 6 | * purpose with or without fee is hereby granted, provided that the above |
| 7 | * copyright notice and this permission notice appear in all copies. |
| 8 | * |
| 9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
| 10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
| 11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
| 12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
| 14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
| 15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 16 | */ |
| 17 | |
Joe Perches | 516304b | 2012-03-18 17:30:52 -0700 | [diff] [blame^] | 18 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 19 | |
Paul Gortmaker | 6eb07ca | 2011-09-15 19:46:05 -0400 | [diff] [blame] | 20 | #include <linux/moduleparam.h> |
Raja Mani | c08631c | 2011-12-16 14:24:24 +0530 | [diff] [blame] | 21 | #include <linux/inetdevice.h> |
Kalle Valo | d6a434d | 2012-01-17 20:09:36 +0200 | [diff] [blame] | 22 | #include <linux/export.h> |
Paul Gortmaker | 6eb07ca | 2011-09-15 19:46:05 -0400 | [diff] [blame] | 23 | |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 24 | #include "core.h" |
| 25 | #include "cfg80211.h" |
| 26 | #include "debug.h" |
Kalle Valo | abcb344 | 2011-07-22 08:26:20 +0300 | [diff] [blame] | 27 | #include "hif-ops.h" |
Kalle Valo | 003353b0d | 2011-09-01 10:14:21 +0300 | [diff] [blame] | 28 | #include "testmode.h" |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 29 | |
| 30 | #define RATETAB_ENT(_rate, _rateid, _flags) { \ |
| 31 | .bitrate = (_rate), \ |
| 32 | .flags = (_flags), \ |
| 33 | .hw_value = (_rateid), \ |
| 34 | } |
| 35 | |
| 36 | #define CHAN2G(_channel, _freq, _flags) { \ |
| 37 | .band = IEEE80211_BAND_2GHZ, \ |
| 38 | .hw_value = (_channel), \ |
| 39 | .center_freq = (_freq), \ |
| 40 | .flags = (_flags), \ |
| 41 | .max_antenna_gain = 0, \ |
| 42 | .max_power = 30, \ |
| 43 | } |
| 44 | |
| 45 | #define CHAN5G(_channel, _flags) { \ |
| 46 | .band = IEEE80211_BAND_5GHZ, \ |
| 47 | .hw_value = (_channel), \ |
| 48 | .center_freq = 5000 + (5 * (_channel)), \ |
| 49 | .flags = (_flags), \ |
| 50 | .max_antenna_gain = 0, \ |
| 51 | .max_power = 30, \ |
| 52 | } |
| 53 | |
| 54 | static struct ieee80211_rate ath6kl_rates[] = { |
| 55 | RATETAB_ENT(10, 0x1, 0), |
| 56 | RATETAB_ENT(20, 0x2, 0), |
| 57 | RATETAB_ENT(55, 0x4, 0), |
| 58 | RATETAB_ENT(110, 0x8, 0), |
| 59 | RATETAB_ENT(60, 0x10, 0), |
| 60 | RATETAB_ENT(90, 0x20, 0), |
| 61 | RATETAB_ENT(120, 0x40, 0), |
| 62 | RATETAB_ENT(180, 0x80, 0), |
| 63 | RATETAB_ENT(240, 0x100, 0), |
| 64 | RATETAB_ENT(360, 0x200, 0), |
| 65 | RATETAB_ENT(480, 0x400, 0), |
| 66 | RATETAB_ENT(540, 0x800, 0), |
| 67 | }; |
| 68 | |
| 69 | #define ath6kl_a_rates (ath6kl_rates + 4) |
| 70 | #define ath6kl_a_rates_size 8 |
| 71 | #define ath6kl_g_rates (ath6kl_rates + 0) |
| 72 | #define ath6kl_g_rates_size 12 |
| 73 | |
Vasanthakumar Thiagarajan | faaf192 | 2012-02-27 11:44:19 +0530 | [diff] [blame] | 74 | #define ath6kl_g_htcap (IEEE80211_HT_CAP_SUP_WIDTH_20_40 | \ |
| 75 | IEEE80211_HT_CAP_SGI_20 | \ |
| 76 | IEEE80211_HT_CAP_SGI_40) |
| 77 | |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 78 | static struct ieee80211_channel ath6kl_2ghz_channels[] = { |
| 79 | CHAN2G(1, 2412, 0), |
| 80 | CHAN2G(2, 2417, 0), |
| 81 | CHAN2G(3, 2422, 0), |
| 82 | CHAN2G(4, 2427, 0), |
| 83 | CHAN2G(5, 2432, 0), |
| 84 | CHAN2G(6, 2437, 0), |
| 85 | CHAN2G(7, 2442, 0), |
| 86 | CHAN2G(8, 2447, 0), |
| 87 | CHAN2G(9, 2452, 0), |
| 88 | CHAN2G(10, 2457, 0), |
| 89 | CHAN2G(11, 2462, 0), |
| 90 | CHAN2G(12, 2467, 0), |
| 91 | CHAN2G(13, 2472, 0), |
| 92 | CHAN2G(14, 2484, 0), |
| 93 | }; |
| 94 | |
| 95 | static struct ieee80211_channel ath6kl_5ghz_a_channels[] = { |
| 96 | CHAN5G(34, 0), CHAN5G(36, 0), |
| 97 | CHAN5G(38, 0), CHAN5G(40, 0), |
| 98 | CHAN5G(42, 0), CHAN5G(44, 0), |
| 99 | CHAN5G(46, 0), CHAN5G(48, 0), |
| 100 | CHAN5G(52, 0), CHAN5G(56, 0), |
| 101 | CHAN5G(60, 0), CHAN5G(64, 0), |
| 102 | CHAN5G(100, 0), CHAN5G(104, 0), |
| 103 | CHAN5G(108, 0), CHAN5G(112, 0), |
| 104 | CHAN5G(116, 0), CHAN5G(120, 0), |
| 105 | CHAN5G(124, 0), CHAN5G(128, 0), |
| 106 | CHAN5G(132, 0), CHAN5G(136, 0), |
| 107 | CHAN5G(140, 0), CHAN5G(149, 0), |
| 108 | CHAN5G(153, 0), CHAN5G(157, 0), |
| 109 | CHAN5G(161, 0), CHAN5G(165, 0), |
| 110 | CHAN5G(184, 0), CHAN5G(188, 0), |
| 111 | CHAN5G(192, 0), CHAN5G(196, 0), |
| 112 | CHAN5G(200, 0), CHAN5G(204, 0), |
| 113 | CHAN5G(208, 0), CHAN5G(212, 0), |
| 114 | CHAN5G(216, 0), |
| 115 | }; |
| 116 | |
| 117 | static struct ieee80211_supported_band ath6kl_band_2ghz = { |
| 118 | .n_channels = ARRAY_SIZE(ath6kl_2ghz_channels), |
| 119 | .channels = ath6kl_2ghz_channels, |
| 120 | .n_bitrates = ath6kl_g_rates_size, |
| 121 | .bitrates = ath6kl_g_rates, |
Vasanthakumar Thiagarajan | faaf192 | 2012-02-27 11:44:19 +0530 | [diff] [blame] | 122 | .ht_cap.cap = ath6kl_g_htcap, |
| 123 | .ht_cap.ht_supported = true, |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 124 | }; |
| 125 | |
| 126 | static struct ieee80211_supported_band ath6kl_band_5ghz = { |
| 127 | .n_channels = ARRAY_SIZE(ath6kl_5ghz_a_channels), |
| 128 | .channels = ath6kl_5ghz_a_channels, |
| 129 | .n_bitrates = ath6kl_a_rates_size, |
| 130 | .bitrates = ath6kl_a_rates, |
Vasanthakumar Thiagarajan | faaf192 | 2012-02-27 11:44:19 +0530 | [diff] [blame] | 131 | .ht_cap.cap = ath6kl_g_htcap, |
| 132 | .ht_cap.ht_supported = true, |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 133 | }; |
| 134 | |
Jouni Malinen | 837cb97 | 2011-10-11 17:31:57 +0300 | [diff] [blame] | 135 | #define CCKM_KRK_CIPHER_SUITE 0x004096ff /* use for KRK */ |
| 136 | |
Kalle Valo | 10509f9 | 2011-12-13 14:52:07 +0200 | [diff] [blame] | 137 | /* returns true if scheduled scan was stopped */ |
| 138 | static bool __ath6kl_cfg80211_sscan_stop(struct ath6kl_vif *vif) |
| 139 | { |
| 140 | struct ath6kl *ar = vif->ar; |
| 141 | |
| 142 | if (ar->state != ATH6KL_STATE_SCHED_SCAN) |
| 143 | return false; |
| 144 | |
| 145 | del_timer_sync(&vif->sched_scan_timer); |
| 146 | |
| 147 | ath6kl_wmi_set_host_sleep_mode_cmd(ar->wmi, vif->fw_vif_idx, |
| 148 | ATH6KL_HOST_MODE_AWAKE); |
| 149 | |
| 150 | ar->state = ATH6KL_STATE_ON; |
| 151 | |
| 152 | return true; |
| 153 | } |
| 154 | |
| 155 | static void ath6kl_cfg80211_sscan_disable(struct ath6kl_vif *vif) |
| 156 | { |
| 157 | struct ath6kl *ar = vif->ar; |
| 158 | bool stopped; |
| 159 | |
| 160 | stopped = __ath6kl_cfg80211_sscan_stop(vif); |
| 161 | |
| 162 | if (!stopped) |
| 163 | return; |
| 164 | |
| 165 | cfg80211_sched_scan_stopped(ar->wiphy); |
| 166 | } |
| 167 | |
Vasanthakumar Thiagarajan | 240d279 | 2011-10-25 19:34:13 +0530 | [diff] [blame] | 168 | static int ath6kl_set_wpa_version(struct ath6kl_vif *vif, |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 169 | enum nl80211_wpa_versions wpa_version) |
| 170 | { |
| 171 | ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: %u\n", __func__, wpa_version); |
| 172 | |
| 173 | if (!wpa_version) { |
Vasanthakumar Thiagarajan | 3450334 | 2011-10-25 19:34:02 +0530 | [diff] [blame] | 174 | vif->auth_mode = NONE_AUTH; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 175 | } else if (wpa_version & NL80211_WPA_VERSION_2) { |
Vasanthakumar Thiagarajan | 3450334 | 2011-10-25 19:34:02 +0530 | [diff] [blame] | 176 | vif->auth_mode = WPA2_AUTH; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 177 | } else if (wpa_version & NL80211_WPA_VERSION_1) { |
Vasanthakumar Thiagarajan | 3450334 | 2011-10-25 19:34:02 +0530 | [diff] [blame] | 178 | vif->auth_mode = WPA_AUTH; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 179 | } else { |
| 180 | ath6kl_err("%s: %u not supported\n", __func__, wpa_version); |
| 181 | return -ENOTSUPP; |
| 182 | } |
| 183 | |
| 184 | return 0; |
| 185 | } |
| 186 | |
Vasanthakumar Thiagarajan | 240d279 | 2011-10-25 19:34:13 +0530 | [diff] [blame] | 187 | static int ath6kl_set_auth_type(struct ath6kl_vif *vif, |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 188 | enum nl80211_auth_type auth_type) |
| 189 | { |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 190 | ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: 0x%x\n", __func__, auth_type); |
| 191 | |
| 192 | switch (auth_type) { |
| 193 | case NL80211_AUTHTYPE_OPEN_SYSTEM: |
Vasanthakumar Thiagarajan | 3450334 | 2011-10-25 19:34:02 +0530 | [diff] [blame] | 194 | vif->dot11_auth_mode = OPEN_AUTH; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 195 | break; |
| 196 | case NL80211_AUTHTYPE_SHARED_KEY: |
Vasanthakumar Thiagarajan | 3450334 | 2011-10-25 19:34:02 +0530 | [diff] [blame] | 197 | vif->dot11_auth_mode = SHARED_AUTH; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 198 | break; |
| 199 | case NL80211_AUTHTYPE_NETWORK_EAP: |
Vasanthakumar Thiagarajan | 3450334 | 2011-10-25 19:34:02 +0530 | [diff] [blame] | 200 | vif->dot11_auth_mode = LEAP_AUTH; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 201 | break; |
| 202 | |
| 203 | case NL80211_AUTHTYPE_AUTOMATIC: |
Vasanthakumar Thiagarajan | 3450334 | 2011-10-25 19:34:02 +0530 | [diff] [blame] | 204 | vif->dot11_auth_mode = OPEN_AUTH | SHARED_AUTH; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 205 | break; |
| 206 | |
| 207 | default: |
Masanari Iida | 3c325fb | 2012-01-31 23:32:55 +0900 | [diff] [blame] | 208 | ath6kl_err("%s: 0x%x not supported\n", __func__, auth_type); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 209 | return -ENOTSUPP; |
| 210 | } |
| 211 | |
| 212 | return 0; |
| 213 | } |
| 214 | |
Vasanthakumar Thiagarajan | 240d279 | 2011-10-25 19:34:13 +0530 | [diff] [blame] | 215 | static int ath6kl_set_cipher(struct ath6kl_vif *vif, u32 cipher, bool ucast) |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 216 | { |
Vasanthakumar Thiagarajan | 3450334 | 2011-10-25 19:34:02 +0530 | [diff] [blame] | 217 | u8 *ar_cipher = ucast ? &vif->prwise_crypto : &vif->grp_crypto; |
| 218 | u8 *ar_cipher_len = ucast ? &vif->prwise_crypto_len : |
| 219 | &vif->grp_crypto_len; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 220 | |
| 221 | ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: cipher 0x%x, ucast %u\n", |
| 222 | __func__, cipher, ucast); |
| 223 | |
| 224 | switch (cipher) { |
| 225 | case 0: |
| 226 | /* our own hack to use value 0 as no crypto used */ |
| 227 | *ar_cipher = NONE_CRYPT; |
| 228 | *ar_cipher_len = 0; |
| 229 | break; |
| 230 | case WLAN_CIPHER_SUITE_WEP40: |
| 231 | *ar_cipher = WEP_CRYPT; |
| 232 | *ar_cipher_len = 5; |
| 233 | break; |
| 234 | case WLAN_CIPHER_SUITE_WEP104: |
| 235 | *ar_cipher = WEP_CRYPT; |
| 236 | *ar_cipher_len = 13; |
| 237 | break; |
| 238 | case WLAN_CIPHER_SUITE_TKIP: |
| 239 | *ar_cipher = TKIP_CRYPT; |
| 240 | *ar_cipher_len = 0; |
| 241 | break; |
| 242 | case WLAN_CIPHER_SUITE_CCMP: |
| 243 | *ar_cipher = AES_CRYPT; |
| 244 | *ar_cipher_len = 0; |
| 245 | break; |
Dai Shuibing | 5e07021 | 2011-11-03 11:39:37 +0200 | [diff] [blame] | 246 | case WLAN_CIPHER_SUITE_SMS4: |
| 247 | *ar_cipher = WAPI_CRYPT; |
| 248 | *ar_cipher_len = 0; |
| 249 | break; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 250 | default: |
| 251 | ath6kl_err("cipher 0x%x not supported\n", cipher); |
| 252 | return -ENOTSUPP; |
| 253 | } |
| 254 | |
| 255 | return 0; |
| 256 | } |
| 257 | |
Vasanthakumar Thiagarajan | 240d279 | 2011-10-25 19:34:13 +0530 | [diff] [blame] | 258 | static void ath6kl_set_key_mgmt(struct ath6kl_vif *vif, u32 key_mgmt) |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 259 | { |
| 260 | ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: 0x%x\n", __func__, key_mgmt); |
| 261 | |
| 262 | if (key_mgmt == WLAN_AKM_SUITE_PSK) { |
Vasanthakumar Thiagarajan | 3450334 | 2011-10-25 19:34:02 +0530 | [diff] [blame] | 263 | if (vif->auth_mode == WPA_AUTH) |
| 264 | vif->auth_mode = WPA_PSK_AUTH; |
| 265 | else if (vif->auth_mode == WPA2_AUTH) |
| 266 | vif->auth_mode = WPA2_PSK_AUTH; |
Jouni Malinen | 837cb97 | 2011-10-11 17:31:57 +0300 | [diff] [blame] | 267 | } else if (key_mgmt == 0x00409600) { |
Vasanthakumar Thiagarajan | 3450334 | 2011-10-25 19:34:02 +0530 | [diff] [blame] | 268 | if (vif->auth_mode == WPA_AUTH) |
| 269 | vif->auth_mode = WPA_AUTH_CCKM; |
| 270 | else if (vif->auth_mode == WPA2_AUTH) |
| 271 | vif->auth_mode = WPA2_AUTH_CCKM; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 272 | } else if (key_mgmt != WLAN_AKM_SUITE_8021X) { |
Vasanthakumar Thiagarajan | 3450334 | 2011-10-25 19:34:02 +0530 | [diff] [blame] | 273 | vif->auth_mode = NONE_AUTH; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 274 | } |
| 275 | } |
| 276 | |
Vasanthakumar Thiagarajan | 990bd91 | 2011-10-25 19:34:20 +0530 | [diff] [blame] | 277 | static bool ath6kl_cfg80211_ready(struct ath6kl_vif *vif) |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 278 | { |
Vasanthakumar Thiagarajan | 990bd91 | 2011-10-25 19:34:20 +0530 | [diff] [blame] | 279 | struct ath6kl *ar = vif->ar; |
Vasanthakumar Thiagarajan | 59c9844 | 2011-10-25 19:34:01 +0530 | [diff] [blame] | 280 | |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 281 | if (!test_bit(WMI_READY, &ar->flag)) { |
| 282 | ath6kl_err("wmi is not ready\n"); |
| 283 | return false; |
| 284 | } |
| 285 | |
Vasanthakumar Thiagarajan | 59c9844 | 2011-10-25 19:34:01 +0530 | [diff] [blame] | 286 | if (!test_bit(WLAN_ENABLED, &vif->flags)) { |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 287 | ath6kl_err("wlan disabled\n"); |
| 288 | return false; |
| 289 | } |
| 290 | |
| 291 | return true; |
| 292 | } |
| 293 | |
Kevin Fang | 6981ffd | 2011-10-07 08:51:19 +0800 | [diff] [blame] | 294 | static bool ath6kl_is_wpa_ie(const u8 *pos) |
| 295 | { |
| 296 | return pos[0] == WLAN_EID_WPA && pos[1] >= 4 && |
| 297 | pos[2] == 0x00 && pos[3] == 0x50 && |
| 298 | pos[4] == 0xf2 && pos[5] == 0x01; |
| 299 | } |
| 300 | |
| 301 | static bool ath6kl_is_rsn_ie(const u8 *pos) |
| 302 | { |
| 303 | return pos[0] == WLAN_EID_RSN; |
| 304 | } |
| 305 | |
Aarthi Thiruvengadam | 6354121 | 2011-10-25 11:25:52 -0700 | [diff] [blame] | 306 | static bool ath6kl_is_wps_ie(const u8 *pos) |
| 307 | { |
| 308 | return (pos[0] == WLAN_EID_VENDOR_SPECIFIC && |
| 309 | pos[1] >= 4 && |
| 310 | pos[2] == 0x00 && pos[3] == 0x50 && pos[4] == 0xf2 && |
| 311 | pos[5] == 0x04); |
| 312 | } |
| 313 | |
Vasanthakumar Thiagarajan | 334234b | 2011-10-25 19:34:12 +0530 | [diff] [blame] | 314 | static int ath6kl_set_assoc_req_ies(struct ath6kl_vif *vif, const u8 *ies, |
| 315 | size_t ies_len) |
Kevin Fang | 6981ffd | 2011-10-07 08:51:19 +0800 | [diff] [blame] | 316 | { |
Vasanthakumar Thiagarajan | 334234b | 2011-10-25 19:34:12 +0530 | [diff] [blame] | 317 | struct ath6kl *ar = vif->ar; |
Kevin Fang | 6981ffd | 2011-10-07 08:51:19 +0800 | [diff] [blame] | 318 | const u8 *pos; |
| 319 | u8 *buf = NULL; |
| 320 | size_t len = 0; |
| 321 | int ret; |
| 322 | |
| 323 | /* |
Aarthi Thiruvengadam | 6354121 | 2011-10-25 11:25:52 -0700 | [diff] [blame] | 324 | * Clear previously set flag |
| 325 | */ |
| 326 | |
| 327 | ar->connect_ctrl_flags &= ~CONNECT_WPS_FLAG; |
| 328 | |
| 329 | /* |
Kevin Fang | 6981ffd | 2011-10-07 08:51:19 +0800 | [diff] [blame] | 330 | * Filter out RSN/WPA IE(s) |
| 331 | */ |
| 332 | |
| 333 | if (ies && ies_len) { |
| 334 | buf = kmalloc(ies_len, GFP_KERNEL); |
| 335 | if (buf == NULL) |
| 336 | return -ENOMEM; |
| 337 | pos = ies; |
| 338 | |
| 339 | while (pos + 1 < ies + ies_len) { |
| 340 | if (pos + 2 + pos[1] > ies + ies_len) |
| 341 | break; |
| 342 | if (!(ath6kl_is_wpa_ie(pos) || ath6kl_is_rsn_ie(pos))) { |
| 343 | memcpy(buf + len, pos, 2 + pos[1]); |
| 344 | len += 2 + pos[1]; |
| 345 | } |
Aarthi Thiruvengadam | 6354121 | 2011-10-25 11:25:52 -0700 | [diff] [blame] | 346 | |
| 347 | if (ath6kl_is_wps_ie(pos)) |
| 348 | ar->connect_ctrl_flags |= CONNECT_WPS_FLAG; |
| 349 | |
Kevin Fang | 6981ffd | 2011-10-07 08:51:19 +0800 | [diff] [blame] | 350 | pos += 2 + pos[1]; |
| 351 | } |
| 352 | } |
| 353 | |
Vasanthakumar Thiagarajan | 334234b | 2011-10-25 19:34:12 +0530 | [diff] [blame] | 354 | ret = ath6kl_wmi_set_appie_cmd(ar->wmi, vif->fw_vif_idx, |
| 355 | WMI_FRAME_ASSOC_REQ, buf, len); |
Kevin Fang | 6981ffd | 2011-10-07 08:51:19 +0800 | [diff] [blame] | 356 | kfree(buf); |
| 357 | return ret; |
| 358 | } |
| 359 | |
Vasanthakumar Thiagarajan | 5505597 | 2011-10-25 19:34:23 +0530 | [diff] [blame] | 360 | static int ath6kl_nliftype_to_drv_iftype(enum nl80211_iftype type, u8 *nw_type) |
| 361 | { |
| 362 | switch (type) { |
| 363 | case NL80211_IFTYPE_STATION: |
| 364 | *nw_type = INFRA_NETWORK; |
| 365 | break; |
| 366 | case NL80211_IFTYPE_ADHOC: |
| 367 | *nw_type = ADHOC_NETWORK; |
| 368 | break; |
| 369 | case NL80211_IFTYPE_AP: |
| 370 | *nw_type = AP_NETWORK; |
| 371 | break; |
| 372 | case NL80211_IFTYPE_P2P_CLIENT: |
| 373 | *nw_type = INFRA_NETWORK; |
| 374 | break; |
| 375 | case NL80211_IFTYPE_P2P_GO: |
| 376 | *nw_type = AP_NETWORK; |
| 377 | break; |
| 378 | default: |
| 379 | ath6kl_err("invalid interface type %u\n", type); |
| 380 | return -ENOTSUPP; |
| 381 | } |
| 382 | |
| 383 | return 0; |
| 384 | } |
| 385 | |
| 386 | static bool ath6kl_is_valid_iftype(struct ath6kl *ar, enum nl80211_iftype type, |
| 387 | u8 *if_idx, u8 *nw_type) |
| 388 | { |
| 389 | int i; |
| 390 | |
| 391 | if (ath6kl_nliftype_to_drv_iftype(type, nw_type)) |
| 392 | return false; |
| 393 | |
| 394 | if (ar->ibss_if_active || ((type == NL80211_IFTYPE_ADHOC) && |
Kalle Valo | 96f1fad | 2012-03-07 20:03:57 +0200 | [diff] [blame] | 395 | ar->num_vif)) |
Vasanthakumar Thiagarajan | 5505597 | 2011-10-25 19:34:23 +0530 | [diff] [blame] | 396 | return false; |
| 397 | |
| 398 | if (type == NL80211_IFTYPE_STATION || |
| 399 | type == NL80211_IFTYPE_AP || type == NL80211_IFTYPE_ADHOC) { |
Kalle Valo | 71f96ee | 2011-11-14 19:31:30 +0200 | [diff] [blame] | 400 | for (i = 0; i < ar->vif_max; i++) { |
Vasanthakumar Thiagarajan | 5505597 | 2011-10-25 19:34:23 +0530 | [diff] [blame] | 401 | if ((ar->avail_idx_map >> i) & BIT(0)) { |
| 402 | *if_idx = i; |
| 403 | return true; |
| 404 | } |
| 405 | } |
| 406 | } |
| 407 | |
Vasanthakumar Thiagarajan | 3226f68a | 2011-10-25 19:34:24 +0530 | [diff] [blame] | 408 | if (type == NL80211_IFTYPE_P2P_CLIENT || |
| 409 | type == NL80211_IFTYPE_P2P_GO) { |
Kalle Valo | 71f96ee | 2011-11-14 19:31:30 +0200 | [diff] [blame] | 410 | for (i = ar->max_norm_iface; i < ar->vif_max; i++) { |
Vasanthakumar Thiagarajan | 3226f68a | 2011-10-25 19:34:24 +0530 | [diff] [blame] | 411 | if ((ar->avail_idx_map >> i) & BIT(0)) { |
| 412 | *if_idx = i; |
| 413 | return true; |
| 414 | } |
| 415 | } |
| 416 | } |
| 417 | |
Vasanthakumar Thiagarajan | 5505597 | 2011-10-25 19:34:23 +0530 | [diff] [blame] | 418 | return false; |
| 419 | } |
| 420 | |
Kalle Valo | 8c9bb05 | 2012-03-07 20:04:00 +0200 | [diff] [blame] | 421 | static bool ath6kl_is_tx_pending(struct ath6kl *ar) |
| 422 | { |
| 423 | return ar->tx_pending[ath6kl_wmi_get_control_ep(ar->wmi)] == 0; |
| 424 | } |
| 425 | |
| 426 | |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 427 | static int ath6kl_cfg80211_connect(struct wiphy *wiphy, struct net_device *dev, |
| 428 | struct cfg80211_connect_params *sme) |
| 429 | { |
| 430 | struct ath6kl *ar = ath6kl_priv(dev); |
Vasanthakumar Thiagarajan | 59c9844 | 2011-10-25 19:34:01 +0530 | [diff] [blame] | 431 | struct ath6kl_vif *vif = netdev_priv(dev); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 432 | int status; |
Aarthi Thiruvengadam | 3ca9d1f | 2011-12-13 13:32:12 -0800 | [diff] [blame] | 433 | u8 nw_subtype = (ar->p2p) ? SUBTYPE_P2PDEV : SUBTYPE_NONE; |
Raja Mani | ce0dc0c | 2012-02-20 19:08:08 +0530 | [diff] [blame] | 434 | u16 interval; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 435 | |
Kalle Valo | 10509f9 | 2011-12-13 14:52:07 +0200 | [diff] [blame] | 436 | ath6kl_cfg80211_sscan_disable(vif); |
| 437 | |
Vasanthakumar Thiagarajan | 14ee6f6 | 2011-10-25 19:34:09 +0530 | [diff] [blame] | 438 | vif->sme_state = SME_CONNECTING; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 439 | |
Vasanthakumar Thiagarajan | 990bd91 | 2011-10-25 19:34:20 +0530 | [diff] [blame] | 440 | if (!ath6kl_cfg80211_ready(vif)) |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 441 | return -EIO; |
| 442 | |
| 443 | if (test_bit(DESTROY_IN_PROGRESS, &ar->flag)) { |
| 444 | ath6kl_err("destroy in progress\n"); |
| 445 | return -EBUSY; |
| 446 | } |
| 447 | |
| 448 | if (test_bit(SKIP_SCAN, &ar->flag) && |
| 449 | ((sme->channel && sme->channel->center_freq == 0) || |
| 450 | (sme->bssid && is_zero_ether_addr(sme->bssid)))) { |
| 451 | ath6kl_err("SkipScan: channel or bssid invalid\n"); |
| 452 | return -EINVAL; |
| 453 | } |
| 454 | |
| 455 | if (down_interruptible(&ar->sem)) { |
| 456 | ath6kl_err("busy, couldn't get access\n"); |
| 457 | return -ERESTARTSYS; |
| 458 | } |
| 459 | |
| 460 | if (test_bit(DESTROY_IN_PROGRESS, &ar->flag)) { |
| 461 | ath6kl_err("busy, destroy in progress\n"); |
| 462 | up(&ar->sem); |
| 463 | return -EBUSY; |
| 464 | } |
| 465 | |
| 466 | if (ar->tx_pending[ath6kl_wmi_get_control_ep(ar->wmi)]) { |
| 467 | /* |
| 468 | * sleep until the command queue drains |
| 469 | */ |
| 470 | wait_event_interruptible_timeout(ar->event_wq, |
Kalle Valo | 8c9bb05 | 2012-03-07 20:04:00 +0200 | [diff] [blame] | 471 | ath6kl_is_tx_pending(ar), |
| 472 | WMI_TIMEOUT); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 473 | if (signal_pending(current)) { |
| 474 | ath6kl_err("cmd queue drain timeout\n"); |
| 475 | up(&ar->sem); |
| 476 | return -EINTR; |
| 477 | } |
| 478 | } |
| 479 | |
Jouni Malinen | 6e786cb | 2011-12-15 14:16:00 +0200 | [diff] [blame] | 480 | status = ath6kl_set_assoc_req_ies(vif, sme->ie, sme->ie_len); |
| 481 | if (status) { |
| 482 | up(&ar->sem); |
| 483 | return status; |
| 484 | } |
| 485 | |
| 486 | if (sme->ie == NULL || sme->ie_len == 0) |
Raja Mani | 542c519 | 2011-11-15 14:14:56 +0530 | [diff] [blame] | 487 | ar->connect_ctrl_flags &= ~CONNECT_WPS_FLAG; |
Kevin Fang | 6981ffd | 2011-10-07 08:51:19 +0800 | [diff] [blame] | 488 | |
Vasanthakumar Thiagarajan | 59c9844 | 2011-10-25 19:34:01 +0530 | [diff] [blame] | 489 | if (test_bit(CONNECTED, &vif->flags) && |
Vasanthakumar Thiagarajan | 3450334 | 2011-10-25 19:34:02 +0530 | [diff] [blame] | 490 | vif->ssid_len == sme->ssid_len && |
| 491 | !memcmp(vif->ssid, sme->ssid, vif->ssid_len)) { |
Vasanthakumar Thiagarajan | cf5333d | 2011-10-25 19:34:10 +0530 | [diff] [blame] | 492 | vif->reconnect_flag = true; |
Vasanthakumar Thiagarajan | 334234b | 2011-10-25 19:34:12 +0530 | [diff] [blame] | 493 | status = ath6kl_wmi_reconnect_cmd(ar->wmi, vif->fw_vif_idx, |
| 494 | vif->req_bssid, |
Vasanthakumar Thiagarajan | f74bac5 | 2011-10-25 19:34:05 +0530 | [diff] [blame] | 495 | vif->ch_hint); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 496 | |
| 497 | up(&ar->sem); |
| 498 | if (status) { |
| 499 | ath6kl_err("wmi_reconnect_cmd failed\n"); |
| 500 | return -EIO; |
| 501 | } |
| 502 | return 0; |
Vasanthakumar Thiagarajan | 3450334 | 2011-10-25 19:34:02 +0530 | [diff] [blame] | 503 | } else if (vif->ssid_len == sme->ssid_len && |
| 504 | !memcmp(vif->ssid, sme->ssid, vif->ssid_len)) { |
Vasanthakumar Thiagarajan | 240d279 | 2011-10-25 19:34:13 +0530 | [diff] [blame] | 505 | ath6kl_disconnect(vif); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 506 | } |
| 507 | |
Vasanthakumar Thiagarajan | 3450334 | 2011-10-25 19:34:02 +0530 | [diff] [blame] | 508 | memset(vif->ssid, 0, sizeof(vif->ssid)); |
| 509 | vif->ssid_len = sme->ssid_len; |
| 510 | memcpy(vif->ssid, sme->ssid, sme->ssid_len); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 511 | |
| 512 | if (sme->channel) |
Vasanthakumar Thiagarajan | f74bac5 | 2011-10-25 19:34:05 +0530 | [diff] [blame] | 513 | vif->ch_hint = sme->channel->center_freq; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 514 | |
Vasanthakumar Thiagarajan | 8c8b65e | 2011-10-25 19:34:04 +0530 | [diff] [blame] | 515 | memset(vif->req_bssid, 0, sizeof(vif->req_bssid)); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 516 | if (sme->bssid && !is_broadcast_ether_addr(sme->bssid)) |
Vasanthakumar Thiagarajan | 8c8b65e | 2011-10-25 19:34:04 +0530 | [diff] [blame] | 517 | memcpy(vif->req_bssid, sme->bssid, sizeof(vif->req_bssid)); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 518 | |
Vasanthakumar Thiagarajan | 240d279 | 2011-10-25 19:34:13 +0530 | [diff] [blame] | 519 | ath6kl_set_wpa_version(vif, sme->crypto.wpa_versions); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 520 | |
Vasanthakumar Thiagarajan | 240d279 | 2011-10-25 19:34:13 +0530 | [diff] [blame] | 521 | status = ath6kl_set_auth_type(vif, sme->auth_type); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 522 | if (status) { |
| 523 | up(&ar->sem); |
| 524 | return status; |
| 525 | } |
| 526 | |
| 527 | if (sme->crypto.n_ciphers_pairwise) |
Vasanthakumar Thiagarajan | 240d279 | 2011-10-25 19:34:13 +0530 | [diff] [blame] | 528 | ath6kl_set_cipher(vif, sme->crypto.ciphers_pairwise[0], true); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 529 | else |
Vasanthakumar Thiagarajan | 240d279 | 2011-10-25 19:34:13 +0530 | [diff] [blame] | 530 | ath6kl_set_cipher(vif, 0, true); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 531 | |
Vasanthakumar Thiagarajan | 240d279 | 2011-10-25 19:34:13 +0530 | [diff] [blame] | 532 | ath6kl_set_cipher(vif, sme->crypto.cipher_group, false); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 533 | |
| 534 | if (sme->crypto.n_akm_suites) |
Vasanthakumar Thiagarajan | 240d279 | 2011-10-25 19:34:13 +0530 | [diff] [blame] | 535 | ath6kl_set_key_mgmt(vif, sme->crypto.akm_suites[0]); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 536 | |
| 537 | if ((sme->key_len) && |
Vasanthakumar Thiagarajan | 3450334 | 2011-10-25 19:34:02 +0530 | [diff] [blame] | 538 | (vif->auth_mode == NONE_AUTH) && |
| 539 | (vif->prwise_crypto == WEP_CRYPT)) { |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 540 | struct ath6kl_key *key = NULL; |
| 541 | |
Vivek Natarajan | 792ecb3 | 2011-12-29 16:18:39 +0530 | [diff] [blame] | 542 | if (sme->key_idx > WMI_MAX_KEY_INDEX) { |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 543 | ath6kl_err("key index %d out of bounds\n", |
| 544 | sme->key_idx); |
| 545 | up(&ar->sem); |
| 546 | return -ENOENT; |
| 547 | } |
| 548 | |
Vasanthakumar Thiagarajan | 6f2a73f | 2011-10-25 19:34:06 +0530 | [diff] [blame] | 549 | key = &vif->keys[sme->key_idx]; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 550 | key->key_len = sme->key_len; |
| 551 | memcpy(key->key, sme->key, key->key_len); |
Vasanthakumar Thiagarajan | 3450334 | 2011-10-25 19:34:02 +0530 | [diff] [blame] | 552 | key->cipher = vif->prwise_crypto; |
| 553 | vif->def_txkey_index = sme->key_idx; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 554 | |
Vasanthakumar Thiagarajan | 334234b | 2011-10-25 19:34:12 +0530 | [diff] [blame] | 555 | ath6kl_wmi_addkey_cmd(ar->wmi, vif->fw_vif_idx, sme->key_idx, |
Vasanthakumar Thiagarajan | 3450334 | 2011-10-25 19:34:02 +0530 | [diff] [blame] | 556 | vif->prwise_crypto, |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 557 | GROUP_USAGE | TX_USAGE, |
| 558 | key->key_len, |
Jouni Malinen | f4bb9a6 | 2011-11-02 23:45:55 +0200 | [diff] [blame] | 559 | NULL, 0, |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 560 | key->key, KEY_OP_INIT_VAL, NULL, |
| 561 | NO_SYNC_WMIFLAG); |
| 562 | } |
| 563 | |
| 564 | if (!ar->usr_bss_filter) { |
Vasanthakumar Thiagarajan | 59c9844 | 2011-10-25 19:34:01 +0530 | [diff] [blame] | 565 | clear_bit(CLEAR_BSSFILTER_ON_BEACON, &vif->flags); |
Vasanthakumar Thiagarajan | 240d279 | 2011-10-25 19:34:13 +0530 | [diff] [blame] | 566 | if (ath6kl_wmi_bssfilter_cmd(ar->wmi, vif->fw_vif_idx, |
Kalle Valo | 96f1fad | 2012-03-07 20:03:57 +0200 | [diff] [blame] | 567 | ALL_BSS_FILTER, 0) != 0) { |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 568 | ath6kl_err("couldn't set bss filtering\n"); |
| 569 | up(&ar->sem); |
| 570 | return -EIO; |
| 571 | } |
| 572 | } |
| 573 | |
Vasanthakumar Thiagarajan | f5938f2 | 2011-10-25 19:34:03 +0530 | [diff] [blame] | 574 | vif->nw_type = vif->next_mode; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 575 | |
Aarthi Thiruvengadam | 3ca9d1f | 2011-12-13 13:32:12 -0800 | [diff] [blame] | 576 | if (vif->wdev.iftype == NL80211_IFTYPE_P2P_CLIENT) |
| 577 | nw_subtype = SUBTYPE_P2PCLIENT; |
| 578 | |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 579 | ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, |
| 580 | "%s: connect called with authmode %d dot11 auth %d" |
| 581 | " PW crypto %d PW crypto len %d GRP crypto %d" |
| 582 | " GRP crypto len %d channel hint %u\n", |
| 583 | __func__, |
Vasanthakumar Thiagarajan | 3450334 | 2011-10-25 19:34:02 +0530 | [diff] [blame] | 584 | vif->auth_mode, vif->dot11_auth_mode, vif->prwise_crypto, |
| 585 | vif->prwise_crypto_len, vif->grp_crypto, |
Vasanthakumar Thiagarajan | f74bac5 | 2011-10-25 19:34:05 +0530 | [diff] [blame] | 586 | vif->grp_crypto_len, vif->ch_hint); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 587 | |
Vasanthakumar Thiagarajan | cf5333d | 2011-10-25 19:34:10 +0530 | [diff] [blame] | 588 | vif->reconnect_flag = 0; |
Raja Mani | ce0dc0c | 2012-02-20 19:08:08 +0530 | [diff] [blame] | 589 | |
| 590 | if (vif->nw_type == INFRA_NETWORK) { |
Kalle Valo | b528387 | 2012-03-12 13:23:23 +0200 | [diff] [blame] | 591 | interval = max_t(u16, vif->listen_intvl_t, |
| 592 | ATH6KL_MAX_WOW_LISTEN_INTL); |
Raja Mani | ce0dc0c | 2012-02-20 19:08:08 +0530 | [diff] [blame] | 593 | status = ath6kl_wmi_listeninterval_cmd(ar->wmi, vif->fw_vif_idx, |
| 594 | interval, |
| 595 | 0); |
| 596 | if (status) { |
| 597 | ath6kl_err("couldn't set listen intervel\n"); |
| 598 | up(&ar->sem); |
| 599 | return status; |
| 600 | } |
| 601 | } |
| 602 | |
Vasanthakumar Thiagarajan | 334234b | 2011-10-25 19:34:12 +0530 | [diff] [blame] | 603 | status = ath6kl_wmi_connect_cmd(ar->wmi, vif->fw_vif_idx, vif->nw_type, |
Vasanthakumar Thiagarajan | 3450334 | 2011-10-25 19:34:02 +0530 | [diff] [blame] | 604 | vif->dot11_auth_mode, vif->auth_mode, |
| 605 | vif->prwise_crypto, |
| 606 | vif->prwise_crypto_len, |
| 607 | vif->grp_crypto, vif->grp_crypto_len, |
| 608 | vif->ssid_len, vif->ssid, |
Vasanthakumar Thiagarajan | f74bac5 | 2011-10-25 19:34:05 +0530 | [diff] [blame] | 609 | vif->req_bssid, vif->ch_hint, |
Aarthi Thiruvengadam | 3ca9d1f | 2011-12-13 13:32:12 -0800 | [diff] [blame] | 610 | ar->connect_ctrl_flags, nw_subtype); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 611 | |
| 612 | up(&ar->sem); |
| 613 | |
| 614 | if (status == -EINVAL) { |
Vasanthakumar Thiagarajan | 3450334 | 2011-10-25 19:34:02 +0530 | [diff] [blame] | 615 | memset(vif->ssid, 0, sizeof(vif->ssid)); |
| 616 | vif->ssid_len = 0; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 617 | ath6kl_err("invalid request\n"); |
| 618 | return -ENOENT; |
| 619 | } else if (status) { |
| 620 | ath6kl_err("ath6kl_wmi_connect_cmd failed\n"); |
| 621 | return -EIO; |
| 622 | } |
| 623 | |
| 624 | if ((!(ar->connect_ctrl_flags & CONNECT_DO_WPA_OFFLOAD)) && |
Kalle Valo | ddc3d77 | 2012-03-07 20:03:58 +0200 | [diff] [blame] | 625 | ((vif->auth_mode == WPA_PSK_AUTH) || |
| 626 | (vif->auth_mode == WPA2_PSK_AUTH))) { |
Vasanthakumar Thiagarajan | de3ad71 | 2011-10-25 19:34:08 +0530 | [diff] [blame] | 627 | mod_timer(&vif->disconnect_timer, |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 628 | jiffies + msecs_to_jiffies(DISCON_TIMER_INTVAL)); |
| 629 | } |
| 630 | |
| 631 | ar->connect_ctrl_flags &= ~CONNECT_DO_WPA_OFFLOAD; |
Vasanthakumar Thiagarajan | 59c9844 | 2011-10-25 19:34:01 +0530 | [diff] [blame] | 632 | set_bit(CONNECT_PEND, &vif->flags); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 633 | |
| 634 | return 0; |
| 635 | } |
| 636 | |
Vasanthakumar Thiagarajan | 5e13fd3 | 2011-12-13 17:19:57 +0530 | [diff] [blame] | 637 | static struct cfg80211_bss * |
| 638 | ath6kl_add_bss_if_needed(struct ath6kl_vif *vif, |
| 639 | enum network_type nw_type, |
| 640 | const u8 *bssid, |
| 641 | struct ieee80211_channel *chan, |
| 642 | const u8 *beacon_ie, |
| 643 | size_t beacon_ie_len) |
Jouni Malinen | 01cac47 | 2011-09-19 19:14:59 +0300 | [diff] [blame] | 644 | { |
Vasanthakumar Thiagarajan | 240d279 | 2011-10-25 19:34:13 +0530 | [diff] [blame] | 645 | struct ath6kl *ar = vif->ar; |
Jouni Malinen | 01cac47 | 2011-09-19 19:14:59 +0300 | [diff] [blame] | 646 | struct cfg80211_bss *bss; |
Raja Mani | 4eab6f4 | 2011-11-09 17:02:23 +0530 | [diff] [blame] | 647 | u16 cap_mask, cap_val; |
Jouni Malinen | 01cac47 | 2011-09-19 19:14:59 +0300 | [diff] [blame] | 648 | u8 *ie; |
| 649 | |
Raja Mani | 4eab6f4 | 2011-11-09 17:02:23 +0530 | [diff] [blame] | 650 | if (nw_type & ADHOC_NETWORK) { |
| 651 | cap_mask = WLAN_CAPABILITY_IBSS; |
| 652 | cap_val = WLAN_CAPABILITY_IBSS; |
| 653 | } else { |
| 654 | cap_mask = WLAN_CAPABILITY_ESS; |
| 655 | cap_val = WLAN_CAPABILITY_ESS; |
| 656 | } |
| 657 | |
Vasanthakumar Thiagarajan | be98e3a | 2011-10-25 19:33:57 +0530 | [diff] [blame] | 658 | bss = cfg80211_get_bss(ar->wiphy, chan, bssid, |
Raja Mani | 4eab6f4 | 2011-11-09 17:02:23 +0530 | [diff] [blame] | 659 | vif->ssid, vif->ssid_len, |
| 660 | cap_mask, cap_val); |
Jouni Malinen | 01cac47 | 2011-09-19 19:14:59 +0300 | [diff] [blame] | 661 | if (bss == NULL) { |
| 662 | /* |
| 663 | * Since cfg80211 may not yet know about the BSS, |
| 664 | * generate a partial entry until the first BSS info |
| 665 | * event becomes available. |
| 666 | * |
| 667 | * Prepend SSID element since it is not included in the Beacon |
| 668 | * IEs from the target. |
| 669 | */ |
Vasanthakumar Thiagarajan | 3450334 | 2011-10-25 19:34:02 +0530 | [diff] [blame] | 670 | ie = kmalloc(2 + vif->ssid_len + beacon_ie_len, GFP_KERNEL); |
Jouni Malinen | 01cac47 | 2011-09-19 19:14:59 +0300 | [diff] [blame] | 671 | if (ie == NULL) |
Vasanthakumar Thiagarajan | 5e13fd3 | 2011-12-13 17:19:57 +0530 | [diff] [blame] | 672 | return NULL; |
Jouni Malinen | 01cac47 | 2011-09-19 19:14:59 +0300 | [diff] [blame] | 673 | ie[0] = WLAN_EID_SSID; |
Vasanthakumar Thiagarajan | 3450334 | 2011-10-25 19:34:02 +0530 | [diff] [blame] | 674 | ie[1] = vif->ssid_len; |
| 675 | memcpy(ie + 2, vif->ssid, vif->ssid_len); |
| 676 | memcpy(ie + 2 + vif->ssid_len, beacon_ie, beacon_ie_len); |
Vasanthakumar Thiagarajan | be98e3a | 2011-10-25 19:33:57 +0530 | [diff] [blame] | 677 | bss = cfg80211_inform_bss(ar->wiphy, chan, |
Raja Mani | 4eab6f4 | 2011-11-09 17:02:23 +0530 | [diff] [blame] | 678 | bssid, 0, cap_val, 100, |
Vasanthakumar Thiagarajan | 3450334 | 2011-10-25 19:34:02 +0530 | [diff] [blame] | 679 | ie, 2 + vif->ssid_len + beacon_ie_len, |
Jouni Malinen | 01cac47 | 2011-09-19 19:14:59 +0300 | [diff] [blame] | 680 | 0, GFP_KERNEL); |
| 681 | if (bss) |
Raja Mani | 4eab6f4 | 2011-11-09 17:02:23 +0530 | [diff] [blame] | 682 | ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "added bss %pM to " |
| 683 | "cfg80211\n", bssid); |
Jouni Malinen | 01cac47 | 2011-09-19 19:14:59 +0300 | [diff] [blame] | 684 | kfree(ie); |
| 685 | } else |
Vasanthakumar Thiagarajan | 5e13fd3 | 2011-12-13 17:19:57 +0530 | [diff] [blame] | 686 | ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "cfg80211 already has a bss\n"); |
Jouni Malinen | 01cac47 | 2011-09-19 19:14:59 +0300 | [diff] [blame] | 687 | |
Vasanthakumar Thiagarajan | 5e13fd3 | 2011-12-13 17:19:57 +0530 | [diff] [blame] | 688 | return bss; |
Jouni Malinen | 01cac47 | 2011-09-19 19:14:59 +0300 | [diff] [blame] | 689 | } |
| 690 | |
Vasanthakumar Thiagarajan | 240d279 | 2011-10-25 19:34:13 +0530 | [diff] [blame] | 691 | void ath6kl_cfg80211_connect_event(struct ath6kl_vif *vif, u16 channel, |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 692 | u8 *bssid, u16 listen_intvl, |
| 693 | u16 beacon_intvl, |
| 694 | enum network_type nw_type, |
| 695 | u8 beacon_ie_len, u8 assoc_req_len, |
| 696 | u8 assoc_resp_len, u8 *assoc_info) |
| 697 | { |
Jouni Malinen | 01cac47 | 2011-09-19 19:14:59 +0300 | [diff] [blame] | 698 | struct ieee80211_channel *chan; |
Vasanthakumar Thiagarajan | 240d279 | 2011-10-25 19:34:13 +0530 | [diff] [blame] | 699 | struct ath6kl *ar = vif->ar; |
Vasanthakumar Thiagarajan | 5e13fd3 | 2011-12-13 17:19:57 +0530 | [diff] [blame] | 700 | struct cfg80211_bss *bss; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 701 | |
| 702 | /* capinfo + listen interval */ |
| 703 | u8 assoc_req_ie_offset = sizeof(u16) + sizeof(u16); |
| 704 | |
| 705 | /* capinfo + status code + associd */ |
| 706 | u8 assoc_resp_ie_offset = sizeof(u16) + sizeof(u16) + sizeof(u16); |
| 707 | |
| 708 | u8 *assoc_req_ie = assoc_info + beacon_ie_len + assoc_req_ie_offset; |
| 709 | u8 *assoc_resp_ie = assoc_info + beacon_ie_len + assoc_req_len + |
| 710 | assoc_resp_ie_offset; |
| 711 | |
| 712 | assoc_req_len -= assoc_req_ie_offset; |
| 713 | assoc_resp_len -= assoc_resp_ie_offset; |
| 714 | |
Jouni Malinen | 32c1087 | 2011-09-19 19:15:07 +0300 | [diff] [blame] | 715 | /* |
| 716 | * Store Beacon interval here; DTIM period will be available only once |
| 717 | * a Beacon frame from the AP is seen. |
| 718 | */ |
Vasanthakumar Thiagarajan | cf5333d | 2011-10-25 19:34:10 +0530 | [diff] [blame] | 719 | vif->assoc_bss_beacon_int = beacon_intvl; |
Vasanthakumar Thiagarajan | 59c9844 | 2011-10-25 19:34:01 +0530 | [diff] [blame] | 720 | clear_bit(DTIM_PERIOD_AVAIL, &vif->flags); |
Jouni Malinen | 32c1087 | 2011-09-19 19:15:07 +0300 | [diff] [blame] | 721 | |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 722 | if (nw_type & ADHOC_NETWORK) { |
Vasanthakumar Thiagarajan | 551959d | 2011-10-25 19:34:26 +0530 | [diff] [blame] | 723 | if (vif->wdev.iftype != NL80211_IFTYPE_ADHOC) { |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 724 | ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, |
| 725 | "%s: ath6k not in ibss mode\n", __func__); |
| 726 | return; |
| 727 | } |
| 728 | } |
| 729 | |
| 730 | if (nw_type & INFRA_NETWORK) { |
Vasanthakumar Thiagarajan | 551959d | 2011-10-25 19:34:26 +0530 | [diff] [blame] | 731 | if (vif->wdev.iftype != NL80211_IFTYPE_STATION && |
| 732 | vif->wdev.iftype != NL80211_IFTYPE_P2P_CLIENT) { |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 733 | ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, |
| 734 | "%s: ath6k not in station mode\n", __func__); |
| 735 | return; |
| 736 | } |
| 737 | } |
| 738 | |
Vasanthakumar Thiagarajan | be98e3a | 2011-10-25 19:33:57 +0530 | [diff] [blame] | 739 | chan = ieee80211_get_channel(ar->wiphy, (int) channel); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 740 | |
Vasanthakumar Thiagarajan | 5e13fd3 | 2011-12-13 17:19:57 +0530 | [diff] [blame] | 741 | bss = ath6kl_add_bss_if_needed(vif, nw_type, bssid, chan, |
| 742 | assoc_info, beacon_ie_len); |
| 743 | if (!bss) { |
Raja Mani | 4eab6f4 | 2011-11-09 17:02:23 +0530 | [diff] [blame] | 744 | ath6kl_err("could not add cfg80211 bss entry\n"); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 745 | return; |
| 746 | } |
| 747 | |
Raja Mani | 4eab6f4 | 2011-11-09 17:02:23 +0530 | [diff] [blame] | 748 | if (nw_type & ADHOC_NETWORK) { |
| 749 | ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "ad-hoc %s selected\n", |
| 750 | nw_type & ADHOC_CREATOR ? "creator" : "joiner"); |
| 751 | cfg80211_ibss_joined(vif->ndev, bssid, GFP_KERNEL); |
Vasanthakumar Thiagarajan | 5e13fd3 | 2011-12-13 17:19:57 +0530 | [diff] [blame] | 752 | cfg80211_put_bss(bss); |
Jouni Malinen | 01cac47 | 2011-09-19 19:14:59 +0300 | [diff] [blame] | 753 | return; |
| 754 | } |
| 755 | |
Vasanthakumar Thiagarajan | 14ee6f6 | 2011-10-25 19:34:09 +0530 | [diff] [blame] | 756 | if (vif->sme_state == SME_CONNECTING) { |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 757 | /* inform connect result to cfg80211 */ |
Vasanthakumar Thiagarajan | 14ee6f6 | 2011-10-25 19:34:09 +0530 | [diff] [blame] | 758 | vif->sme_state = SME_CONNECTED; |
Vasanthakumar Thiagarajan | 240d279 | 2011-10-25 19:34:13 +0530 | [diff] [blame] | 759 | cfg80211_connect_result(vif->ndev, bssid, |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 760 | assoc_req_ie, assoc_req_len, |
| 761 | assoc_resp_ie, assoc_resp_len, |
| 762 | WLAN_STATUS_SUCCESS, GFP_KERNEL); |
Vasanthakumar Thiagarajan | 5e13fd3 | 2011-12-13 17:19:57 +0530 | [diff] [blame] | 763 | cfg80211_put_bss(bss); |
Vasanthakumar Thiagarajan | 14ee6f6 | 2011-10-25 19:34:09 +0530 | [diff] [blame] | 764 | } else if (vif->sme_state == SME_CONNECTED) { |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 765 | /* inform roam event to cfg80211 */ |
Vasanthakumar Thiagarajan | 5e13fd3 | 2011-12-13 17:19:57 +0530 | [diff] [blame] | 766 | cfg80211_roamed_bss(vif->ndev, bss, assoc_req_ie, assoc_req_len, |
| 767 | assoc_resp_ie, assoc_resp_len, GFP_KERNEL); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 768 | } |
| 769 | } |
| 770 | |
| 771 | static int ath6kl_cfg80211_disconnect(struct wiphy *wiphy, |
| 772 | struct net_device *dev, u16 reason_code) |
| 773 | { |
Kalle Valo | d6d5c06 | 2011-11-25 13:17:37 +0200 | [diff] [blame] | 774 | struct ath6kl *ar = ath6kl_priv(dev); |
Vasanthakumar Thiagarajan | 3450334 | 2011-10-25 19:34:02 +0530 | [diff] [blame] | 775 | struct ath6kl_vif *vif = netdev_priv(dev); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 776 | |
| 777 | ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: reason=%u\n", __func__, |
| 778 | reason_code); |
| 779 | |
Kalle Valo | 10509f9 | 2011-12-13 14:52:07 +0200 | [diff] [blame] | 780 | ath6kl_cfg80211_sscan_disable(vif); |
| 781 | |
Vasanthakumar Thiagarajan | 990bd91 | 2011-10-25 19:34:20 +0530 | [diff] [blame] | 782 | if (!ath6kl_cfg80211_ready(vif)) |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 783 | return -EIO; |
| 784 | |
| 785 | if (test_bit(DESTROY_IN_PROGRESS, &ar->flag)) { |
| 786 | ath6kl_err("busy, destroy in progress\n"); |
| 787 | return -EBUSY; |
| 788 | } |
| 789 | |
| 790 | if (down_interruptible(&ar->sem)) { |
| 791 | ath6kl_err("busy, couldn't get access\n"); |
| 792 | return -ERESTARTSYS; |
| 793 | } |
| 794 | |
Vasanthakumar Thiagarajan | cf5333d | 2011-10-25 19:34:10 +0530 | [diff] [blame] | 795 | vif->reconnect_flag = 0; |
Vasanthakumar Thiagarajan | 240d279 | 2011-10-25 19:34:13 +0530 | [diff] [blame] | 796 | ath6kl_disconnect(vif); |
Vasanthakumar Thiagarajan | 3450334 | 2011-10-25 19:34:02 +0530 | [diff] [blame] | 797 | memset(vif->ssid, 0, sizeof(vif->ssid)); |
| 798 | vif->ssid_len = 0; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 799 | |
| 800 | if (!test_bit(SKIP_SCAN, &ar->flag)) |
Vasanthakumar Thiagarajan | 8c8b65e | 2011-10-25 19:34:04 +0530 | [diff] [blame] | 801 | memset(vif->req_bssid, 0, sizeof(vif->req_bssid)); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 802 | |
| 803 | up(&ar->sem); |
| 804 | |
Vasanthakumar Thiagarajan | 14ee6f6 | 2011-10-25 19:34:09 +0530 | [diff] [blame] | 805 | vif->sme_state = SME_DISCONNECTED; |
Vasanthakumar Thiagarajan | 170826d | 2011-09-10 15:26:35 +0530 | [diff] [blame] | 806 | |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 807 | return 0; |
| 808 | } |
| 809 | |
Vasanthakumar Thiagarajan | 240d279 | 2011-10-25 19:34:13 +0530 | [diff] [blame] | 810 | void ath6kl_cfg80211_disconnect_event(struct ath6kl_vif *vif, u8 reason, |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 811 | u8 *bssid, u8 assoc_resp_len, |
| 812 | u8 *assoc_info, u16 proto_reason) |
| 813 | { |
Vasanthakumar Thiagarajan | 240d279 | 2011-10-25 19:34:13 +0530 | [diff] [blame] | 814 | struct ath6kl *ar = vif->ar; |
Vasanthakumar Thiagarajan | 59c9844 | 2011-10-25 19:34:01 +0530 | [diff] [blame] | 815 | |
Vasanthakumar Thiagarajan | 14ee6f6 | 2011-10-25 19:34:09 +0530 | [diff] [blame] | 816 | if (vif->scan_req) { |
| 817 | cfg80211_scan_done(vif->scan_req, true); |
| 818 | vif->scan_req = NULL; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 819 | } |
| 820 | |
Vasanthakumar Thiagarajan | f5938f2 | 2011-10-25 19:34:03 +0530 | [diff] [blame] | 821 | if (vif->nw_type & ADHOC_NETWORK) { |
Vasanthakumar Thiagarajan | 551959d | 2011-10-25 19:34:26 +0530 | [diff] [blame] | 822 | if (vif->wdev.iftype != NL80211_IFTYPE_ADHOC) { |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 823 | ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, |
| 824 | "%s: ath6k not in ibss mode\n", __func__); |
| 825 | return; |
| 826 | } |
| 827 | memset(bssid, 0, ETH_ALEN); |
Vasanthakumar Thiagarajan | 240d279 | 2011-10-25 19:34:13 +0530 | [diff] [blame] | 828 | cfg80211_ibss_joined(vif->ndev, bssid, GFP_KERNEL); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 829 | return; |
| 830 | } |
| 831 | |
Vasanthakumar Thiagarajan | f5938f2 | 2011-10-25 19:34:03 +0530 | [diff] [blame] | 832 | if (vif->nw_type & INFRA_NETWORK) { |
Vasanthakumar Thiagarajan | 551959d | 2011-10-25 19:34:26 +0530 | [diff] [blame] | 833 | if (vif->wdev.iftype != NL80211_IFTYPE_STATION && |
| 834 | vif->wdev.iftype != NL80211_IFTYPE_P2P_CLIENT) { |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 835 | ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, |
| 836 | "%s: ath6k not in station mode\n", __func__); |
| 837 | return; |
| 838 | } |
| 839 | } |
| 840 | |
Vasanthakumar Thiagarajan | 1de547d | 2011-09-23 10:57:50 +0530 | [diff] [blame] | 841 | /* |
| 842 | * Send a disconnect command to target when a disconnect event is |
| 843 | * received with reason code other than 3 (DISCONNECT_CMD - disconnect |
| 844 | * request from host) to make the firmware stop trying to connect even |
| 845 | * after giving disconnect event. There will be one more disconnect |
| 846 | * event for this disconnect command with reason code DISCONNECT_CMD |
| 847 | * which will be notified to cfg80211. |
| 848 | */ |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 849 | |
Vasanthakumar Thiagarajan | 1de547d | 2011-09-23 10:57:50 +0530 | [diff] [blame] | 850 | if (reason != DISCONNECT_CMD) { |
Vasanthakumar Thiagarajan | 334234b | 2011-10-25 19:34:12 +0530 | [diff] [blame] | 851 | ath6kl_wmi_disconnect_cmd(ar->wmi, vif->fw_vif_idx); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 852 | return; |
| 853 | } |
| 854 | |
Vasanthakumar Thiagarajan | 59c9844 | 2011-10-25 19:34:01 +0530 | [diff] [blame] | 855 | clear_bit(CONNECT_PEND, &vif->flags); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 856 | |
Vasanthakumar Thiagarajan | 14ee6f6 | 2011-10-25 19:34:09 +0530 | [diff] [blame] | 857 | if (vif->sme_state == SME_CONNECTING) { |
Vasanthakumar Thiagarajan | 240d279 | 2011-10-25 19:34:13 +0530 | [diff] [blame] | 858 | cfg80211_connect_result(vif->ndev, |
Kalle Valo | 96f1fad | 2012-03-07 20:03:57 +0200 | [diff] [blame] | 859 | bssid, NULL, 0, |
| 860 | NULL, 0, |
| 861 | WLAN_STATUS_UNSPECIFIED_FAILURE, |
| 862 | GFP_KERNEL); |
Vasanthakumar Thiagarajan | 14ee6f6 | 2011-10-25 19:34:09 +0530 | [diff] [blame] | 863 | } else if (vif->sme_state == SME_CONNECTED) { |
Vasanthakumar Thiagarajan | 240d279 | 2011-10-25 19:34:13 +0530 | [diff] [blame] | 864 | cfg80211_disconnected(vif->ndev, reason, |
Kalle Valo | 96f1fad | 2012-03-07 20:03:57 +0200 | [diff] [blame] | 865 | NULL, 0, GFP_KERNEL); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 866 | } |
| 867 | |
Vasanthakumar Thiagarajan | 14ee6f6 | 2011-10-25 19:34:09 +0530 | [diff] [blame] | 868 | vif->sme_state = SME_DISCONNECTED; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 869 | } |
| 870 | |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 871 | static int ath6kl_cfg80211_scan(struct wiphy *wiphy, struct net_device *ndev, |
| 872 | struct cfg80211_scan_request *request) |
| 873 | { |
Kalle Valo | d6d5c06 | 2011-11-25 13:17:37 +0200 | [diff] [blame] | 874 | struct ath6kl *ar = ath6kl_priv(ndev); |
Vasanthakumar Thiagarajan | 59c9844 | 2011-10-25 19:34:01 +0530 | [diff] [blame] | 875 | struct ath6kl_vif *vif = netdev_priv(ndev); |
Edward Lu | 1276c9e | 2011-08-30 21:58:00 +0300 | [diff] [blame] | 876 | s8 n_channels = 0; |
| 877 | u16 *channels = NULL; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 878 | int ret = 0; |
Vasanthakumar Thiagarajan | f1f9217 | 2011-10-01 16:12:36 +0530 | [diff] [blame] | 879 | u32 force_fg_scan = 0; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 880 | |
Vasanthakumar Thiagarajan | 990bd91 | 2011-10-25 19:34:20 +0530 | [diff] [blame] | 881 | if (!ath6kl_cfg80211_ready(vif)) |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 882 | return -EIO; |
| 883 | |
Kalle Valo | 10509f9 | 2011-12-13 14:52:07 +0200 | [diff] [blame] | 884 | ath6kl_cfg80211_sscan_disable(vif); |
| 885 | |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 886 | if (!ar->usr_bss_filter) { |
Vasanthakumar Thiagarajan | 59c9844 | 2011-10-25 19:34:01 +0530 | [diff] [blame] | 887 | clear_bit(CLEAR_BSSFILTER_ON_BEACON, &vif->flags); |
Jouni Malinen | 1b1e6ee | 2011-08-30 21:58:10 +0300 | [diff] [blame] | 888 | ret = ath6kl_wmi_bssfilter_cmd( |
Vasanthakumar Thiagarajan | 240d279 | 2011-10-25 19:34:13 +0530 | [diff] [blame] | 889 | ar->wmi, vif->fw_vif_idx, |
Vasanthakumar Thiagarajan | 59c9844 | 2011-10-25 19:34:01 +0530 | [diff] [blame] | 890 | (test_bit(CONNECTED, &vif->flags) ? |
Jouni Malinen | 1b1e6ee | 2011-08-30 21:58:10 +0300 | [diff] [blame] | 891 | ALL_BUT_BSS_FILTER : ALL_BSS_FILTER), 0); |
| 892 | if (ret) { |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 893 | ath6kl_err("couldn't set bss filtering\n"); |
Jouni Malinen | 1b1e6ee | 2011-08-30 21:58:10 +0300 | [diff] [blame] | 894 | return ret; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 895 | } |
| 896 | } |
| 897 | |
| 898 | if (request->n_ssids && request->ssids[0].ssid_len) { |
| 899 | u8 i; |
| 900 | |
| 901 | if (request->n_ssids > (MAX_PROBED_SSID_INDEX - 1)) |
| 902 | request->n_ssids = MAX_PROBED_SSID_INDEX - 1; |
| 903 | |
| 904 | for (i = 0; i < request->n_ssids; i++) |
Vasanthakumar Thiagarajan | 334234b | 2011-10-25 19:34:12 +0530 | [diff] [blame] | 905 | ath6kl_wmi_probedssid_cmd(ar->wmi, vif->fw_vif_idx, |
| 906 | i + 1, SPECIFIC_SSID_FLAG, |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 907 | request->ssids[i].ssid_len, |
| 908 | request->ssids[i].ssid); |
| 909 | } |
| 910 | |
Aarthi Thiruvengadam | 080eec4 | 2012-02-28 09:17:04 -0800 | [diff] [blame] | 911 | /* this also clears IE in fw if it's not set */ |
| 912 | ret = ath6kl_wmi_set_appie_cmd(ar->wmi, vif->fw_vif_idx, |
| 913 | WMI_FRAME_PROBE_REQ, |
| 914 | request->ie, request->ie_len); |
| 915 | if (ret) { |
| 916 | ath6kl_err("failed to set Probe Request appie for " |
| 917 | "scan"); |
| 918 | return ret; |
Jouni Malinen | b84da8c | 2011-08-30 21:57:59 +0300 | [diff] [blame] | 919 | } |
| 920 | |
Jouni Malinen | 11869be | 2011-09-02 20:07:06 +0300 | [diff] [blame] | 921 | /* |
| 922 | * Scan only the requested channels if the request specifies a set of |
| 923 | * channels. If the list is longer than the target supports, do not |
| 924 | * configure the list and instead, scan all available channels. |
| 925 | */ |
| 926 | if (request->n_channels > 0 && |
| 927 | request->n_channels <= WMI_MAX_CHANNELS) { |
Edward Lu | 1276c9e | 2011-08-30 21:58:00 +0300 | [diff] [blame] | 928 | u8 i; |
| 929 | |
Jouni Malinen | 11869be | 2011-09-02 20:07:06 +0300 | [diff] [blame] | 930 | n_channels = request->n_channels; |
Edward Lu | 1276c9e | 2011-08-30 21:58:00 +0300 | [diff] [blame] | 931 | |
| 932 | channels = kzalloc(n_channels * sizeof(u16), GFP_KERNEL); |
| 933 | if (channels == NULL) { |
| 934 | ath6kl_warn("failed to set scan channels, " |
| 935 | "scan all channels"); |
| 936 | n_channels = 0; |
| 937 | } |
| 938 | |
| 939 | for (i = 0; i < n_channels; i++) |
| 940 | channels[i] = request->channels[i]->center_freq; |
| 941 | } |
| 942 | |
Vasanthakumar Thiagarajan | 59c9844 | 2011-10-25 19:34:01 +0530 | [diff] [blame] | 943 | if (test_bit(CONNECTED, &vif->flags)) |
Vasanthakumar Thiagarajan | f1f9217 | 2011-10-01 16:12:36 +0530 | [diff] [blame] | 944 | force_fg_scan = 1; |
| 945 | |
Aarthi Thiruvengadam | 3ca9d1f | 2011-12-13 13:32:12 -0800 | [diff] [blame] | 946 | if (test_bit(ATH6KL_FW_CAPABILITY_STA_P2PDEV_DUPLEX, |
Kalle Valo | 96f1fad | 2012-03-07 20:03:57 +0200 | [diff] [blame] | 947 | ar->fw_capabilities)) { |
Aarthi Thiruvengadam | 3ca9d1f | 2011-12-13 13:32:12 -0800 | [diff] [blame] | 948 | /* |
| 949 | * If capable of doing P2P mgmt operations using |
| 950 | * station interface, send additional information like |
| 951 | * supported rates to advertise and xmit rates for |
| 952 | * probe requests |
| 953 | */ |
| 954 | ret = ath6kl_wmi_beginscan_cmd(ar->wmi, vif->fw_vif_idx, |
| 955 | WMI_LONG_SCAN, force_fg_scan, |
Vasanthakumar Thiagarajan | 13423c3 | 2012-02-21 15:30:42 +0530 | [diff] [blame] | 956 | false, 0, |
| 957 | ATH6KL_FG_SCAN_INTERVAL, |
| 958 | n_channels, channels, |
| 959 | request->no_cck, |
Aarthi Thiruvengadam | 3ca9d1f | 2011-12-13 13:32:12 -0800 | [diff] [blame] | 960 | request->rates); |
| 961 | } else { |
| 962 | ret = ath6kl_wmi_startscan_cmd(ar->wmi, vif->fw_vif_idx, |
| 963 | WMI_LONG_SCAN, force_fg_scan, |
Vasanthakumar Thiagarajan | 13423c3 | 2012-02-21 15:30:42 +0530 | [diff] [blame] | 964 | false, 0, |
| 965 | ATH6KL_FG_SCAN_INTERVAL, |
| 966 | n_channels, channels); |
Aarthi Thiruvengadam | 3ca9d1f | 2011-12-13 13:32:12 -0800 | [diff] [blame] | 967 | } |
Jouni Malinen | 1b1e6ee | 2011-08-30 21:58:10 +0300 | [diff] [blame] | 968 | if (ret) |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 969 | ath6kl_err("wmi_startscan_cmd failed\n"); |
Jouni Malinen | 11869be | 2011-09-02 20:07:06 +0300 | [diff] [blame] | 970 | else |
Vasanthakumar Thiagarajan | 14ee6f6 | 2011-10-25 19:34:09 +0530 | [diff] [blame] | 971 | vif->scan_req = request; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 972 | |
Edward Lu | 1276c9e | 2011-08-30 21:58:00 +0300 | [diff] [blame] | 973 | kfree(channels); |
| 974 | |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 975 | return ret; |
| 976 | } |
| 977 | |
Kalle Valo | 1c17d31 | 2011-11-01 08:43:56 +0200 | [diff] [blame] | 978 | void ath6kl_cfg80211_scan_complete_event(struct ath6kl_vif *vif, bool aborted) |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 979 | { |
Vasanthakumar Thiagarajan | 240d279 | 2011-10-25 19:34:13 +0530 | [diff] [blame] | 980 | struct ath6kl *ar = vif->ar; |
Kalle Valo | 6fd1eac | 2011-07-21 10:22:50 +0300 | [diff] [blame] | 981 | int i; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 982 | |
Kalle Valo | 1c17d31 | 2011-11-01 08:43:56 +0200 | [diff] [blame] | 983 | ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: status%s\n", __func__, |
| 984 | aborted ? " aborted" : ""); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 985 | |
Vasanthakumar Thiagarajan | 14ee6f6 | 2011-10-25 19:34:09 +0530 | [diff] [blame] | 986 | if (!vif->scan_req) |
Kalle Valo | 6fd1eac | 2011-07-21 10:22:50 +0300 | [diff] [blame] | 987 | return; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 988 | |
Kalle Valo | 1c17d31 | 2011-11-01 08:43:56 +0200 | [diff] [blame] | 989 | if (aborted) |
Kalle Valo | 6fd1eac | 2011-07-21 10:22:50 +0300 | [diff] [blame] | 990 | goto out; |
Kalle Valo | 6fd1eac | 2011-07-21 10:22:50 +0300 | [diff] [blame] | 991 | |
Vasanthakumar Thiagarajan | 14ee6f6 | 2011-10-25 19:34:09 +0530 | [diff] [blame] | 992 | if (vif->scan_req->n_ssids && vif->scan_req->ssids[0].ssid_len) { |
| 993 | for (i = 0; i < vif->scan_req->n_ssids; i++) { |
Vasanthakumar Thiagarajan | 334234b | 2011-10-25 19:34:12 +0530 | [diff] [blame] | 994 | ath6kl_wmi_probedssid_cmd(ar->wmi, vif->fw_vif_idx, |
| 995 | i + 1, DISABLE_SSID_FLAG, |
Kalle Valo | 6fd1eac | 2011-07-21 10:22:50 +0300 | [diff] [blame] | 996 | 0, NULL); |
| 997 | } |
| 998 | } |
| 999 | |
| 1000 | out: |
Kalle Valo | cb93821 | 2011-10-27 18:47:46 +0300 | [diff] [blame] | 1001 | cfg80211_scan_done(vif->scan_req, aborted); |
Vasanthakumar Thiagarajan | 14ee6f6 | 2011-10-25 19:34:09 +0530 | [diff] [blame] | 1002 | vif->scan_req = NULL; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1003 | } |
| 1004 | |
| 1005 | static int ath6kl_cfg80211_add_key(struct wiphy *wiphy, struct net_device *ndev, |
| 1006 | u8 key_index, bool pairwise, |
| 1007 | const u8 *mac_addr, |
| 1008 | struct key_params *params) |
| 1009 | { |
Kalle Valo | d6d5c06 | 2011-11-25 13:17:37 +0200 | [diff] [blame] | 1010 | struct ath6kl *ar = ath6kl_priv(ndev); |
Vasanthakumar Thiagarajan | 59c9844 | 2011-10-25 19:34:01 +0530 | [diff] [blame] | 1011 | struct ath6kl_vif *vif = netdev_priv(ndev); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1012 | struct ath6kl_key *key = NULL; |
Sujith Manoharan | 4a8ce2f | 2012-01-10 09:53:38 +0530 | [diff] [blame] | 1013 | int seq_len; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1014 | u8 key_usage; |
| 1015 | u8 key_type; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1016 | |
Vasanthakumar Thiagarajan | 990bd91 | 2011-10-25 19:34:20 +0530 | [diff] [blame] | 1017 | if (!ath6kl_cfg80211_ready(vif)) |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1018 | return -EIO; |
| 1019 | |
Jouni Malinen | 837cb97 | 2011-10-11 17:31:57 +0300 | [diff] [blame] | 1020 | if (params->cipher == CCKM_KRK_CIPHER_SUITE) { |
| 1021 | if (params->key_len != WMI_KRK_LEN) |
| 1022 | return -EINVAL; |
Vasanthakumar Thiagarajan | 240d279 | 2011-10-25 19:34:13 +0530 | [diff] [blame] | 1023 | return ath6kl_wmi_add_krk_cmd(ar->wmi, vif->fw_vif_idx, |
| 1024 | params->key); |
Jouni Malinen | 837cb97 | 2011-10-11 17:31:57 +0300 | [diff] [blame] | 1025 | } |
| 1026 | |
Vivek Natarajan | 792ecb3 | 2011-12-29 16:18:39 +0530 | [diff] [blame] | 1027 | if (key_index > WMI_MAX_KEY_INDEX) { |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1028 | ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, |
| 1029 | "%s: key index %d out of bounds\n", __func__, |
| 1030 | key_index); |
| 1031 | return -ENOENT; |
| 1032 | } |
| 1033 | |
Vasanthakumar Thiagarajan | 6f2a73f | 2011-10-25 19:34:06 +0530 | [diff] [blame] | 1034 | key = &vif->keys[key_index]; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1035 | memset(key, 0, sizeof(struct ath6kl_key)); |
| 1036 | |
| 1037 | if (pairwise) |
| 1038 | key_usage = PAIRWISE_USAGE; |
| 1039 | else |
| 1040 | key_usage = GROUP_USAGE; |
| 1041 | |
Sujith Manoharan | 4a8ce2f | 2012-01-10 09:53:38 +0530 | [diff] [blame] | 1042 | seq_len = params->seq_len; |
| 1043 | if (params->cipher == WLAN_CIPHER_SUITE_SMS4 && |
| 1044 | seq_len > ATH6KL_KEY_SEQ_LEN) { |
| 1045 | /* Only first half of the WPI PN is configured */ |
| 1046 | seq_len = ATH6KL_KEY_SEQ_LEN; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1047 | } |
Sujith Manoharan | 4a8ce2f | 2012-01-10 09:53:38 +0530 | [diff] [blame] | 1048 | if (params->key_len > WLAN_MAX_KEY_LEN || |
| 1049 | seq_len > sizeof(key->seq)) |
| 1050 | return -EINVAL; |
| 1051 | |
| 1052 | key->key_len = params->key_len; |
| 1053 | memcpy(key->key, params->key, key->key_len); |
| 1054 | key->seq_len = seq_len; |
| 1055 | memcpy(key->seq, params->seq, key->seq_len); |
| 1056 | key->cipher = params->cipher; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1057 | |
| 1058 | switch (key->cipher) { |
| 1059 | case WLAN_CIPHER_SUITE_WEP40: |
| 1060 | case WLAN_CIPHER_SUITE_WEP104: |
| 1061 | key_type = WEP_CRYPT; |
| 1062 | break; |
| 1063 | |
| 1064 | case WLAN_CIPHER_SUITE_TKIP: |
| 1065 | key_type = TKIP_CRYPT; |
| 1066 | break; |
| 1067 | |
| 1068 | case WLAN_CIPHER_SUITE_CCMP: |
| 1069 | key_type = AES_CRYPT; |
| 1070 | break; |
Dai Shuibing | 5e07021 | 2011-11-03 11:39:37 +0200 | [diff] [blame] | 1071 | case WLAN_CIPHER_SUITE_SMS4: |
| 1072 | key_type = WAPI_CRYPT; |
| 1073 | break; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1074 | |
| 1075 | default: |
| 1076 | return -ENOTSUPP; |
| 1077 | } |
| 1078 | |
Kalle Valo | ddc3d77 | 2012-03-07 20:03:58 +0200 | [diff] [blame] | 1079 | if (((vif->auth_mode == WPA_PSK_AUTH) || |
| 1080 | (vif->auth_mode == WPA2_PSK_AUTH)) && |
| 1081 | (key_usage & GROUP_USAGE)) |
Vasanthakumar Thiagarajan | de3ad71 | 2011-10-25 19:34:08 +0530 | [diff] [blame] | 1082 | del_timer(&vif->disconnect_timer); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1083 | |
| 1084 | ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, |
| 1085 | "%s: index %d, key_len %d, key_type 0x%x, key_usage 0x%x, seq_len %d\n", |
| 1086 | __func__, key_index, key->key_len, key_type, |
| 1087 | key_usage, key->seq_len); |
| 1088 | |
Vasanthakumar Thiagarajan | f5938f2 | 2011-10-25 19:34:03 +0530 | [diff] [blame] | 1089 | if (vif->nw_type == AP_NETWORK && !pairwise && |
Jouni Malinen | 4703290 | 2011-12-08 16:50:30 +0200 | [diff] [blame] | 1090 | (key_type == TKIP_CRYPT || key_type == AES_CRYPT || |
Vasanthakumar Thiagarajan | cc4d623 | 2012-02-14 20:33:00 +0530 | [diff] [blame] | 1091 | key_type == WAPI_CRYPT)) { |
Jouni Malinen | 9a5b131 | 2011-08-30 21:57:52 +0300 | [diff] [blame] | 1092 | ar->ap_mode_bkey.valid = true; |
| 1093 | ar->ap_mode_bkey.key_index = key_index; |
| 1094 | ar->ap_mode_bkey.key_type = key_type; |
| 1095 | ar->ap_mode_bkey.key_len = key->key_len; |
| 1096 | memcpy(ar->ap_mode_bkey.key, key->key, key->key_len); |
Vasanthakumar Thiagarajan | 59c9844 | 2011-10-25 19:34:01 +0530 | [diff] [blame] | 1097 | if (!test_bit(CONNECTED, &vif->flags)) { |
Jouni Malinen | 9a5b131 | 2011-08-30 21:57:52 +0300 | [diff] [blame] | 1098 | ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "Delay initial group " |
| 1099 | "key configuration until AP mode has been " |
| 1100 | "started\n"); |
| 1101 | /* |
| 1102 | * The key will be set in ath6kl_connect_ap_mode() once |
| 1103 | * the connected event is received from the target. |
| 1104 | */ |
| 1105 | return 0; |
| 1106 | } |
| 1107 | } |
| 1108 | |
Vasanthakumar Thiagarajan | f5938f2 | 2011-10-25 19:34:03 +0530 | [diff] [blame] | 1109 | if (vif->next_mode == AP_NETWORK && key_type == WEP_CRYPT && |
Vasanthakumar Thiagarajan | 59c9844 | 2011-10-25 19:34:01 +0530 | [diff] [blame] | 1110 | !test_bit(CONNECTED, &vif->flags)) { |
Jouni Malinen | 151411e | 2011-09-15 15:10:16 +0300 | [diff] [blame] | 1111 | /* |
| 1112 | * Store the key locally so that it can be re-configured after |
| 1113 | * the AP mode has properly started |
| 1114 | * (ath6kl_install_statioc_wep_keys). |
| 1115 | */ |
| 1116 | ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "Delay WEP key configuration " |
| 1117 | "until AP mode has been started\n"); |
Vasanthakumar Thiagarajan | 6f2a73f | 2011-10-25 19:34:06 +0530 | [diff] [blame] | 1118 | vif->wep_key_list[key_index].key_len = key->key_len; |
| 1119 | memcpy(vif->wep_key_list[key_index].key, key->key, |
| 1120 | key->key_len); |
Jouni Malinen | 151411e | 2011-09-15 15:10:16 +0300 | [diff] [blame] | 1121 | return 0; |
| 1122 | } |
| 1123 | |
Vasanthakumar Thiagarajan | 7cefa44 | 2011-11-11 20:33:00 +0530 | [diff] [blame] | 1124 | return ath6kl_wmi_addkey_cmd(ar->wmi, vif->fw_vif_idx, key_index, |
Jouni Malinen | f3e61ec | 2011-11-02 23:46:47 +0200 | [diff] [blame] | 1125 | key_type, key_usage, key->key_len, |
| 1126 | key->seq, key->seq_len, key->key, |
| 1127 | KEY_OP_INIT_VAL, |
| 1128 | (u8 *) mac_addr, SYNC_BOTH_WMIFLAG); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1129 | } |
| 1130 | |
| 1131 | static int ath6kl_cfg80211_del_key(struct wiphy *wiphy, struct net_device *ndev, |
| 1132 | u8 key_index, bool pairwise, |
| 1133 | const u8 *mac_addr) |
| 1134 | { |
Kalle Valo | d6d5c06 | 2011-11-25 13:17:37 +0200 | [diff] [blame] | 1135 | struct ath6kl *ar = ath6kl_priv(ndev); |
Vasanthakumar Thiagarajan | 6f2a73f | 2011-10-25 19:34:06 +0530 | [diff] [blame] | 1136 | struct ath6kl_vif *vif = netdev_priv(ndev); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1137 | |
| 1138 | ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: index %d\n", __func__, key_index); |
| 1139 | |
Vasanthakumar Thiagarajan | 990bd91 | 2011-10-25 19:34:20 +0530 | [diff] [blame] | 1140 | if (!ath6kl_cfg80211_ready(vif)) |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1141 | return -EIO; |
| 1142 | |
Vivek Natarajan | 792ecb3 | 2011-12-29 16:18:39 +0530 | [diff] [blame] | 1143 | if (key_index > WMI_MAX_KEY_INDEX) { |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1144 | ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, |
| 1145 | "%s: key index %d out of bounds\n", __func__, |
| 1146 | key_index); |
| 1147 | return -ENOENT; |
| 1148 | } |
| 1149 | |
Vasanthakumar Thiagarajan | 6f2a73f | 2011-10-25 19:34:06 +0530 | [diff] [blame] | 1150 | if (!vif->keys[key_index].key_len) { |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1151 | ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, |
| 1152 | "%s: index %d is empty\n", __func__, key_index); |
| 1153 | return 0; |
| 1154 | } |
| 1155 | |
Vasanthakumar Thiagarajan | 6f2a73f | 2011-10-25 19:34:06 +0530 | [diff] [blame] | 1156 | vif->keys[key_index].key_len = 0; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1157 | |
Vasanthakumar Thiagarajan | 334234b | 2011-10-25 19:34:12 +0530 | [diff] [blame] | 1158 | return ath6kl_wmi_deletekey_cmd(ar->wmi, vif->fw_vif_idx, key_index); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1159 | } |
| 1160 | |
| 1161 | static int ath6kl_cfg80211_get_key(struct wiphy *wiphy, struct net_device *ndev, |
| 1162 | u8 key_index, bool pairwise, |
| 1163 | const u8 *mac_addr, void *cookie, |
| 1164 | void (*callback) (void *cookie, |
| 1165 | struct key_params *)) |
| 1166 | { |
Vasanthakumar Thiagarajan | 6f2a73f | 2011-10-25 19:34:06 +0530 | [diff] [blame] | 1167 | struct ath6kl_vif *vif = netdev_priv(ndev); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1168 | struct ath6kl_key *key = NULL; |
| 1169 | struct key_params params; |
| 1170 | |
| 1171 | ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: index %d\n", __func__, key_index); |
| 1172 | |
Vasanthakumar Thiagarajan | 990bd91 | 2011-10-25 19:34:20 +0530 | [diff] [blame] | 1173 | if (!ath6kl_cfg80211_ready(vif)) |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1174 | return -EIO; |
| 1175 | |
Vivek Natarajan | 792ecb3 | 2011-12-29 16:18:39 +0530 | [diff] [blame] | 1176 | if (key_index > WMI_MAX_KEY_INDEX) { |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1177 | ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, |
| 1178 | "%s: key index %d out of bounds\n", __func__, |
| 1179 | key_index); |
| 1180 | return -ENOENT; |
| 1181 | } |
| 1182 | |
Vasanthakumar Thiagarajan | 6f2a73f | 2011-10-25 19:34:06 +0530 | [diff] [blame] | 1183 | key = &vif->keys[key_index]; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1184 | memset(¶ms, 0, sizeof(params)); |
| 1185 | params.cipher = key->cipher; |
| 1186 | params.key_len = key->key_len; |
| 1187 | params.seq_len = key->seq_len; |
| 1188 | params.seq = key->seq; |
| 1189 | params.key = key->key; |
| 1190 | |
| 1191 | callback(cookie, ¶ms); |
| 1192 | |
| 1193 | return key->key_len ? 0 : -ENOENT; |
| 1194 | } |
| 1195 | |
| 1196 | static int ath6kl_cfg80211_set_default_key(struct wiphy *wiphy, |
| 1197 | struct net_device *ndev, |
| 1198 | u8 key_index, bool unicast, |
| 1199 | bool multicast) |
| 1200 | { |
Kalle Valo | d6d5c06 | 2011-11-25 13:17:37 +0200 | [diff] [blame] | 1201 | struct ath6kl *ar = ath6kl_priv(ndev); |
Vasanthakumar Thiagarajan | 59c9844 | 2011-10-25 19:34:01 +0530 | [diff] [blame] | 1202 | struct ath6kl_vif *vif = netdev_priv(ndev); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1203 | struct ath6kl_key *key = NULL; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1204 | u8 key_usage; |
Edward Lu | 229ed6b | 2011-08-30 21:58:07 +0300 | [diff] [blame] | 1205 | enum crypto_type key_type = NONE_CRYPT; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1206 | |
| 1207 | ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: index %d\n", __func__, key_index); |
| 1208 | |
Vasanthakumar Thiagarajan | 990bd91 | 2011-10-25 19:34:20 +0530 | [diff] [blame] | 1209 | if (!ath6kl_cfg80211_ready(vif)) |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1210 | return -EIO; |
| 1211 | |
Vivek Natarajan | 792ecb3 | 2011-12-29 16:18:39 +0530 | [diff] [blame] | 1212 | if (key_index > WMI_MAX_KEY_INDEX) { |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1213 | ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, |
| 1214 | "%s: key index %d out of bounds\n", |
| 1215 | __func__, key_index); |
| 1216 | return -ENOENT; |
| 1217 | } |
| 1218 | |
Vasanthakumar Thiagarajan | 6f2a73f | 2011-10-25 19:34:06 +0530 | [diff] [blame] | 1219 | if (!vif->keys[key_index].key_len) { |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1220 | ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: invalid key index %d\n", |
| 1221 | __func__, key_index); |
| 1222 | return -EINVAL; |
| 1223 | } |
| 1224 | |
Vasanthakumar Thiagarajan | 3450334 | 2011-10-25 19:34:02 +0530 | [diff] [blame] | 1225 | vif->def_txkey_index = key_index; |
Vasanthakumar Thiagarajan | 6f2a73f | 2011-10-25 19:34:06 +0530 | [diff] [blame] | 1226 | key = &vif->keys[vif->def_txkey_index]; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1227 | key_usage = GROUP_USAGE; |
Vasanthakumar Thiagarajan | 3450334 | 2011-10-25 19:34:02 +0530 | [diff] [blame] | 1228 | if (vif->prwise_crypto == WEP_CRYPT) |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1229 | key_usage |= TX_USAGE; |
Edward Lu | 229ed6b | 2011-08-30 21:58:07 +0300 | [diff] [blame] | 1230 | if (unicast) |
Vasanthakumar Thiagarajan | 3450334 | 2011-10-25 19:34:02 +0530 | [diff] [blame] | 1231 | key_type = vif->prwise_crypto; |
Edward Lu | 229ed6b | 2011-08-30 21:58:07 +0300 | [diff] [blame] | 1232 | if (multicast) |
Vasanthakumar Thiagarajan | 3450334 | 2011-10-25 19:34:02 +0530 | [diff] [blame] | 1233 | key_type = vif->grp_crypto; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1234 | |
Vasanthakumar Thiagarajan | f5938f2 | 2011-10-25 19:34:03 +0530 | [diff] [blame] | 1235 | if (vif->next_mode == AP_NETWORK && !test_bit(CONNECTED, &vif->flags)) |
Jouni Malinen | 9a5b131 | 2011-08-30 21:57:52 +0300 | [diff] [blame] | 1236 | return 0; /* Delay until AP mode has been started */ |
| 1237 | |
Jouni Malinen | f3e61ec | 2011-11-02 23:46:47 +0200 | [diff] [blame] | 1238 | return ath6kl_wmi_addkey_cmd(ar->wmi, vif->fw_vif_idx, |
| 1239 | vif->def_txkey_index, |
| 1240 | key_type, key_usage, |
| 1241 | key->key_len, key->seq, key->seq_len, |
| 1242 | key->key, |
| 1243 | KEY_OP_INIT_VAL, NULL, |
| 1244 | SYNC_BOTH_WMIFLAG); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1245 | } |
| 1246 | |
Vasanthakumar Thiagarajan | 240d279 | 2011-10-25 19:34:13 +0530 | [diff] [blame] | 1247 | void ath6kl_cfg80211_tkip_micerr_event(struct ath6kl_vif *vif, u8 keyid, |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1248 | bool ismcast) |
| 1249 | { |
| 1250 | ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, |
| 1251 | "%s: keyid %d, ismcast %d\n", __func__, keyid, ismcast); |
| 1252 | |
Vasanthakumar Thiagarajan | 240d279 | 2011-10-25 19:34:13 +0530 | [diff] [blame] | 1253 | cfg80211_michael_mic_failure(vif->ndev, vif->bssid, |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1254 | (ismcast ? NL80211_KEYTYPE_GROUP : |
| 1255 | NL80211_KEYTYPE_PAIRWISE), keyid, NULL, |
| 1256 | GFP_KERNEL); |
| 1257 | } |
| 1258 | |
| 1259 | static int ath6kl_cfg80211_set_wiphy_params(struct wiphy *wiphy, u32 changed) |
| 1260 | { |
| 1261 | struct ath6kl *ar = (struct ath6kl *)wiphy_priv(wiphy); |
Vasanthakumar Thiagarajan | 990bd91 | 2011-10-25 19:34:20 +0530 | [diff] [blame] | 1262 | struct ath6kl_vif *vif; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1263 | int ret; |
| 1264 | |
| 1265 | ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: changed 0x%x\n", __func__, |
| 1266 | changed); |
| 1267 | |
Vasanthakumar Thiagarajan | 990bd91 | 2011-10-25 19:34:20 +0530 | [diff] [blame] | 1268 | vif = ath6kl_vif_first(ar); |
| 1269 | if (!vif) |
| 1270 | return -EIO; |
| 1271 | |
| 1272 | if (!ath6kl_cfg80211_ready(vif)) |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1273 | return -EIO; |
| 1274 | |
| 1275 | if (changed & WIPHY_PARAM_RTS_THRESHOLD) { |
| 1276 | ret = ath6kl_wmi_set_rts_cmd(ar->wmi, wiphy->rts_threshold); |
| 1277 | if (ret != 0) { |
| 1278 | ath6kl_err("ath6kl_wmi_set_rts_cmd failed\n"); |
| 1279 | return -EIO; |
| 1280 | } |
| 1281 | } |
| 1282 | |
| 1283 | return 0; |
| 1284 | } |
| 1285 | |
| 1286 | /* |
| 1287 | * The type nl80211_tx_power_setting replaces the following |
| 1288 | * data type from 2.6.36 onwards |
| 1289 | */ |
| 1290 | static int ath6kl_cfg80211_set_txpower(struct wiphy *wiphy, |
| 1291 | enum nl80211_tx_power_setting type, |
Luis R. Rodriguez | b992a28 | 2011-11-23 11:08:14 -0500 | [diff] [blame] | 1292 | int mbm) |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1293 | { |
| 1294 | struct ath6kl *ar = (struct ath6kl *)wiphy_priv(wiphy); |
Vasanthakumar Thiagarajan | 990bd91 | 2011-10-25 19:34:20 +0530 | [diff] [blame] | 1295 | struct ath6kl_vif *vif; |
Luis R. Rodriguez | b992a28 | 2011-11-23 11:08:14 -0500 | [diff] [blame] | 1296 | int dbm = MBM_TO_DBM(mbm); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1297 | |
| 1298 | ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: type 0x%x, dbm %d\n", __func__, |
| 1299 | type, dbm); |
| 1300 | |
Vasanthakumar Thiagarajan | 990bd91 | 2011-10-25 19:34:20 +0530 | [diff] [blame] | 1301 | vif = ath6kl_vif_first(ar); |
| 1302 | if (!vif) |
| 1303 | return -EIO; |
| 1304 | |
| 1305 | if (!ath6kl_cfg80211_ready(vif)) |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1306 | return -EIO; |
| 1307 | |
| 1308 | switch (type) { |
| 1309 | case NL80211_TX_POWER_AUTOMATIC: |
| 1310 | return 0; |
| 1311 | case NL80211_TX_POWER_LIMITED: |
Kalle Valo | d0d670a | 2012-03-07 20:03:58 +0200 | [diff] [blame] | 1312 | ar->tx_pwr = dbm; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1313 | break; |
| 1314 | default: |
| 1315 | ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: type 0x%x not supported\n", |
| 1316 | __func__, type); |
| 1317 | return -EOPNOTSUPP; |
| 1318 | } |
| 1319 | |
Kalle Valo | d0d670a | 2012-03-07 20:03:58 +0200 | [diff] [blame] | 1320 | ath6kl_wmi_set_tx_pwr_cmd(ar->wmi, vif->fw_vif_idx, dbm); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1321 | |
| 1322 | return 0; |
| 1323 | } |
| 1324 | |
| 1325 | static int ath6kl_cfg80211_get_txpower(struct wiphy *wiphy, int *dbm) |
| 1326 | { |
| 1327 | struct ath6kl *ar = (struct ath6kl *)wiphy_priv(wiphy); |
Vasanthakumar Thiagarajan | 990bd91 | 2011-10-25 19:34:20 +0530 | [diff] [blame] | 1328 | struct ath6kl_vif *vif; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1329 | |
Vasanthakumar Thiagarajan | 990bd91 | 2011-10-25 19:34:20 +0530 | [diff] [blame] | 1330 | vif = ath6kl_vif_first(ar); |
| 1331 | if (!vif) |
| 1332 | return -EIO; |
| 1333 | |
| 1334 | if (!ath6kl_cfg80211_ready(vif)) |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1335 | return -EIO; |
| 1336 | |
Vasanthakumar Thiagarajan | 59c9844 | 2011-10-25 19:34:01 +0530 | [diff] [blame] | 1337 | if (test_bit(CONNECTED, &vif->flags)) { |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1338 | ar->tx_pwr = 0; |
| 1339 | |
Vasanthakumar Thiagarajan | 990bd91 | 2011-10-25 19:34:20 +0530 | [diff] [blame] | 1340 | if (ath6kl_wmi_get_tx_pwr_cmd(ar->wmi, vif->fw_vif_idx) != 0) { |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1341 | ath6kl_err("ath6kl_wmi_get_tx_pwr_cmd failed\n"); |
| 1342 | return -EIO; |
| 1343 | } |
| 1344 | |
| 1345 | wait_event_interruptible_timeout(ar->event_wq, ar->tx_pwr != 0, |
| 1346 | 5 * HZ); |
| 1347 | |
| 1348 | if (signal_pending(current)) { |
| 1349 | ath6kl_err("target did not respond\n"); |
| 1350 | return -EINTR; |
| 1351 | } |
| 1352 | } |
| 1353 | |
| 1354 | *dbm = ar->tx_pwr; |
| 1355 | return 0; |
| 1356 | } |
| 1357 | |
| 1358 | static int ath6kl_cfg80211_set_power_mgmt(struct wiphy *wiphy, |
| 1359 | struct net_device *dev, |
| 1360 | bool pmgmt, int timeout) |
| 1361 | { |
| 1362 | struct ath6kl *ar = ath6kl_priv(dev); |
| 1363 | struct wmi_power_mode_cmd mode; |
Vasanthakumar Thiagarajan | 334234b | 2011-10-25 19:34:12 +0530 | [diff] [blame] | 1364 | struct ath6kl_vif *vif = netdev_priv(dev); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1365 | |
| 1366 | ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: pmgmt %d, timeout %d\n", |
| 1367 | __func__, pmgmt, timeout); |
| 1368 | |
Vasanthakumar Thiagarajan | 990bd91 | 2011-10-25 19:34:20 +0530 | [diff] [blame] | 1369 | if (!ath6kl_cfg80211_ready(vif)) |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1370 | return -EIO; |
| 1371 | |
| 1372 | if (pmgmt) { |
| 1373 | ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: max perf\n", __func__); |
| 1374 | mode.pwr_mode = REC_POWER; |
| 1375 | } else { |
| 1376 | ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: rec power\n", __func__); |
| 1377 | mode.pwr_mode = MAX_PERF_POWER; |
| 1378 | } |
| 1379 | |
Vasanthakumar Thiagarajan | 334234b | 2011-10-25 19:34:12 +0530 | [diff] [blame] | 1380 | if (ath6kl_wmi_powermode_cmd(ar->wmi, vif->fw_vif_idx, |
Kalle Valo | 96f1fad | 2012-03-07 20:03:57 +0200 | [diff] [blame] | 1381 | mode.pwr_mode) != 0) { |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1382 | ath6kl_err("wmi_powermode_cmd failed\n"); |
| 1383 | return -EIO; |
| 1384 | } |
| 1385 | |
| 1386 | return 0; |
| 1387 | } |
| 1388 | |
Vasanthakumar Thiagarajan | 5505597 | 2011-10-25 19:34:23 +0530 | [diff] [blame] | 1389 | static struct net_device *ath6kl_cfg80211_add_iface(struct wiphy *wiphy, |
| 1390 | char *name, |
| 1391 | enum nl80211_iftype type, |
| 1392 | u32 *flags, |
| 1393 | struct vif_params *params) |
| 1394 | { |
| 1395 | struct ath6kl *ar = wiphy_priv(wiphy); |
| 1396 | struct net_device *ndev; |
| 1397 | u8 if_idx, nw_type; |
| 1398 | |
Kalle Valo | 71f96ee | 2011-11-14 19:31:30 +0200 | [diff] [blame] | 1399 | if (ar->num_vif == ar->vif_max) { |
Vasanthakumar Thiagarajan | 5505597 | 2011-10-25 19:34:23 +0530 | [diff] [blame] | 1400 | ath6kl_err("Reached maximum number of supported vif\n"); |
| 1401 | return ERR_PTR(-EINVAL); |
| 1402 | } |
| 1403 | |
| 1404 | if (!ath6kl_is_valid_iftype(ar, type, &if_idx, &nw_type)) { |
| 1405 | ath6kl_err("Not a supported interface type\n"); |
| 1406 | return ERR_PTR(-EINVAL); |
| 1407 | } |
| 1408 | |
| 1409 | ndev = ath6kl_interface_add(ar, name, type, if_idx, nw_type); |
| 1410 | if (!ndev) |
| 1411 | return ERR_PTR(-ENOMEM); |
| 1412 | |
| 1413 | ar->num_vif++; |
| 1414 | |
| 1415 | return ndev; |
| 1416 | } |
| 1417 | |
| 1418 | static int ath6kl_cfg80211_del_iface(struct wiphy *wiphy, |
| 1419 | struct net_device *ndev) |
| 1420 | { |
| 1421 | struct ath6kl *ar = wiphy_priv(wiphy); |
| 1422 | struct ath6kl_vif *vif = netdev_priv(ndev); |
| 1423 | |
Vasanthakumar Thiagarajan | 11f6e40 | 2011-11-01 16:38:50 +0530 | [diff] [blame] | 1424 | spin_lock_bh(&ar->list_lock); |
Vasanthakumar Thiagarajan | 5505597 | 2011-10-25 19:34:23 +0530 | [diff] [blame] | 1425 | list_del(&vif->list); |
Vasanthakumar Thiagarajan | 11f6e40 | 2011-11-01 16:38:50 +0530 | [diff] [blame] | 1426 | spin_unlock_bh(&ar->list_lock); |
Vasanthakumar Thiagarajan | 5505597 | 2011-10-25 19:34:23 +0530 | [diff] [blame] | 1427 | |
| 1428 | ath6kl_cleanup_vif(vif, test_bit(WMI_READY, &ar->flag)); |
| 1429 | |
Kalle Valo | c25889e | 2012-01-17 20:08:27 +0200 | [diff] [blame] | 1430 | ath6kl_cfg80211_vif_cleanup(vif); |
Vasanthakumar Thiagarajan | 5505597 | 2011-10-25 19:34:23 +0530 | [diff] [blame] | 1431 | |
| 1432 | return 0; |
| 1433 | } |
| 1434 | |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1435 | static int ath6kl_cfg80211_change_iface(struct wiphy *wiphy, |
| 1436 | struct net_device *ndev, |
| 1437 | enum nl80211_iftype type, u32 *flags, |
| 1438 | struct vif_params *params) |
| 1439 | { |
Vasanthakumar Thiagarajan | f5938f2 | 2011-10-25 19:34:03 +0530 | [diff] [blame] | 1440 | struct ath6kl_vif *vif = netdev_priv(ndev); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1441 | |
| 1442 | ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: type %u\n", __func__, type); |
| 1443 | |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1444 | switch (type) { |
| 1445 | case NL80211_IFTYPE_STATION: |
Vasanthakumar Thiagarajan | f5938f2 | 2011-10-25 19:34:03 +0530 | [diff] [blame] | 1446 | vif->next_mode = INFRA_NETWORK; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1447 | break; |
| 1448 | case NL80211_IFTYPE_ADHOC: |
Vasanthakumar Thiagarajan | f5938f2 | 2011-10-25 19:34:03 +0530 | [diff] [blame] | 1449 | vif->next_mode = ADHOC_NETWORK; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1450 | break; |
Jouni Malinen | 6e4604c | 2011-09-05 17:38:46 +0300 | [diff] [blame] | 1451 | case NL80211_IFTYPE_AP: |
Vasanthakumar Thiagarajan | f5938f2 | 2011-10-25 19:34:03 +0530 | [diff] [blame] | 1452 | vif->next_mode = AP_NETWORK; |
Jouni Malinen | 6e4604c | 2011-09-05 17:38:46 +0300 | [diff] [blame] | 1453 | break; |
Jouni Malinen | 6b5e5d2 | 2011-08-30 21:58:05 +0300 | [diff] [blame] | 1454 | case NL80211_IFTYPE_P2P_CLIENT: |
Vasanthakumar Thiagarajan | f5938f2 | 2011-10-25 19:34:03 +0530 | [diff] [blame] | 1455 | vif->next_mode = INFRA_NETWORK; |
Jouni Malinen | 6b5e5d2 | 2011-08-30 21:58:05 +0300 | [diff] [blame] | 1456 | break; |
| 1457 | case NL80211_IFTYPE_P2P_GO: |
Vasanthakumar Thiagarajan | f5938f2 | 2011-10-25 19:34:03 +0530 | [diff] [blame] | 1458 | vif->next_mode = AP_NETWORK; |
Jouni Malinen | 6b5e5d2 | 2011-08-30 21:58:05 +0300 | [diff] [blame] | 1459 | break; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1460 | default: |
| 1461 | ath6kl_err("invalid interface type %u\n", type); |
| 1462 | return -EOPNOTSUPP; |
| 1463 | } |
| 1464 | |
Vasanthakumar Thiagarajan | 551959d | 2011-10-25 19:34:26 +0530 | [diff] [blame] | 1465 | vif->wdev.iftype = type; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1466 | |
| 1467 | return 0; |
| 1468 | } |
| 1469 | |
| 1470 | static int ath6kl_cfg80211_join_ibss(struct wiphy *wiphy, |
| 1471 | struct net_device *dev, |
| 1472 | struct cfg80211_ibss_params *ibss_param) |
| 1473 | { |
| 1474 | struct ath6kl *ar = ath6kl_priv(dev); |
Vasanthakumar Thiagarajan | 59c9844 | 2011-10-25 19:34:01 +0530 | [diff] [blame] | 1475 | struct ath6kl_vif *vif = netdev_priv(dev); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1476 | int status; |
| 1477 | |
Vasanthakumar Thiagarajan | 990bd91 | 2011-10-25 19:34:20 +0530 | [diff] [blame] | 1478 | if (!ath6kl_cfg80211_ready(vif)) |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1479 | return -EIO; |
| 1480 | |
Vasanthakumar Thiagarajan | 3450334 | 2011-10-25 19:34:02 +0530 | [diff] [blame] | 1481 | vif->ssid_len = ibss_param->ssid_len; |
| 1482 | memcpy(vif->ssid, ibss_param->ssid, vif->ssid_len); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1483 | |
| 1484 | if (ibss_param->channel) |
Vasanthakumar Thiagarajan | f74bac5 | 2011-10-25 19:34:05 +0530 | [diff] [blame] | 1485 | vif->ch_hint = ibss_param->channel->center_freq; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1486 | |
| 1487 | if (ibss_param->channel_fixed) { |
| 1488 | /* |
| 1489 | * TODO: channel_fixed: The channel should be fixed, do not |
| 1490 | * search for IBSSs to join on other channels. Target |
| 1491 | * firmware does not support this feature, needs to be |
| 1492 | * updated. |
| 1493 | */ |
| 1494 | return -EOPNOTSUPP; |
| 1495 | } |
| 1496 | |
Vasanthakumar Thiagarajan | 8c8b65e | 2011-10-25 19:34:04 +0530 | [diff] [blame] | 1497 | memset(vif->req_bssid, 0, sizeof(vif->req_bssid)); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1498 | if (ibss_param->bssid && !is_broadcast_ether_addr(ibss_param->bssid)) |
Vasanthakumar Thiagarajan | 8c8b65e | 2011-10-25 19:34:04 +0530 | [diff] [blame] | 1499 | memcpy(vif->req_bssid, ibss_param->bssid, |
| 1500 | sizeof(vif->req_bssid)); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1501 | |
Vasanthakumar Thiagarajan | 240d279 | 2011-10-25 19:34:13 +0530 | [diff] [blame] | 1502 | ath6kl_set_wpa_version(vif, 0); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1503 | |
Vasanthakumar Thiagarajan | 240d279 | 2011-10-25 19:34:13 +0530 | [diff] [blame] | 1504 | status = ath6kl_set_auth_type(vif, NL80211_AUTHTYPE_OPEN_SYSTEM); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1505 | if (status) |
| 1506 | return status; |
| 1507 | |
| 1508 | if (ibss_param->privacy) { |
Vasanthakumar Thiagarajan | 240d279 | 2011-10-25 19:34:13 +0530 | [diff] [blame] | 1509 | ath6kl_set_cipher(vif, WLAN_CIPHER_SUITE_WEP40, true); |
| 1510 | ath6kl_set_cipher(vif, WLAN_CIPHER_SUITE_WEP40, false); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1511 | } else { |
Vasanthakumar Thiagarajan | 240d279 | 2011-10-25 19:34:13 +0530 | [diff] [blame] | 1512 | ath6kl_set_cipher(vif, 0, true); |
| 1513 | ath6kl_set_cipher(vif, 0, false); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1514 | } |
| 1515 | |
Vasanthakumar Thiagarajan | f5938f2 | 2011-10-25 19:34:03 +0530 | [diff] [blame] | 1516 | vif->nw_type = vif->next_mode; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1517 | |
| 1518 | ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, |
| 1519 | "%s: connect called with authmode %d dot11 auth %d" |
| 1520 | " PW crypto %d PW crypto len %d GRP crypto %d" |
| 1521 | " GRP crypto len %d channel hint %u\n", |
| 1522 | __func__, |
Vasanthakumar Thiagarajan | 3450334 | 2011-10-25 19:34:02 +0530 | [diff] [blame] | 1523 | vif->auth_mode, vif->dot11_auth_mode, vif->prwise_crypto, |
| 1524 | vif->prwise_crypto_len, vif->grp_crypto, |
Vasanthakumar Thiagarajan | f74bac5 | 2011-10-25 19:34:05 +0530 | [diff] [blame] | 1525 | vif->grp_crypto_len, vif->ch_hint); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1526 | |
Vasanthakumar Thiagarajan | 334234b | 2011-10-25 19:34:12 +0530 | [diff] [blame] | 1527 | status = ath6kl_wmi_connect_cmd(ar->wmi, vif->fw_vif_idx, vif->nw_type, |
Vasanthakumar Thiagarajan | 3450334 | 2011-10-25 19:34:02 +0530 | [diff] [blame] | 1528 | vif->dot11_auth_mode, vif->auth_mode, |
| 1529 | vif->prwise_crypto, |
| 1530 | vif->prwise_crypto_len, |
| 1531 | vif->grp_crypto, vif->grp_crypto_len, |
| 1532 | vif->ssid_len, vif->ssid, |
Vasanthakumar Thiagarajan | f74bac5 | 2011-10-25 19:34:05 +0530 | [diff] [blame] | 1533 | vif->req_bssid, vif->ch_hint, |
Aarthi Thiruvengadam | 3ca9d1f | 2011-12-13 13:32:12 -0800 | [diff] [blame] | 1534 | ar->connect_ctrl_flags, SUBTYPE_NONE); |
Vasanthakumar Thiagarajan | 59c9844 | 2011-10-25 19:34:01 +0530 | [diff] [blame] | 1535 | set_bit(CONNECT_PEND, &vif->flags); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1536 | |
| 1537 | return 0; |
| 1538 | } |
| 1539 | |
| 1540 | static int ath6kl_cfg80211_leave_ibss(struct wiphy *wiphy, |
| 1541 | struct net_device *dev) |
| 1542 | { |
Vasanthakumar Thiagarajan | 3450334 | 2011-10-25 19:34:02 +0530 | [diff] [blame] | 1543 | struct ath6kl_vif *vif = netdev_priv(dev); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1544 | |
Vasanthakumar Thiagarajan | 990bd91 | 2011-10-25 19:34:20 +0530 | [diff] [blame] | 1545 | if (!ath6kl_cfg80211_ready(vif)) |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1546 | return -EIO; |
| 1547 | |
Vasanthakumar Thiagarajan | 240d279 | 2011-10-25 19:34:13 +0530 | [diff] [blame] | 1548 | ath6kl_disconnect(vif); |
Vasanthakumar Thiagarajan | 3450334 | 2011-10-25 19:34:02 +0530 | [diff] [blame] | 1549 | memset(vif->ssid, 0, sizeof(vif->ssid)); |
| 1550 | vif->ssid_len = 0; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1551 | |
| 1552 | return 0; |
| 1553 | } |
| 1554 | |
| 1555 | static const u32 cipher_suites[] = { |
| 1556 | WLAN_CIPHER_SUITE_WEP40, |
| 1557 | WLAN_CIPHER_SUITE_WEP104, |
| 1558 | WLAN_CIPHER_SUITE_TKIP, |
| 1559 | WLAN_CIPHER_SUITE_CCMP, |
Jouni Malinen | 837cb97 | 2011-10-11 17:31:57 +0300 | [diff] [blame] | 1560 | CCKM_KRK_CIPHER_SUITE, |
Dai Shuibing | 5e07021 | 2011-11-03 11:39:37 +0200 | [diff] [blame] | 1561 | WLAN_CIPHER_SUITE_SMS4, |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1562 | }; |
| 1563 | |
| 1564 | static bool is_rate_legacy(s32 rate) |
| 1565 | { |
| 1566 | static const s32 legacy[] = { 1000, 2000, 5500, 11000, |
| 1567 | 6000, 9000, 12000, 18000, 24000, |
| 1568 | 36000, 48000, 54000 |
| 1569 | }; |
| 1570 | u8 i; |
| 1571 | |
| 1572 | for (i = 0; i < ARRAY_SIZE(legacy); i++) |
| 1573 | if (rate == legacy[i]) |
| 1574 | return true; |
| 1575 | |
| 1576 | return false; |
| 1577 | } |
| 1578 | |
| 1579 | static bool is_rate_ht20(s32 rate, u8 *mcs, bool *sgi) |
| 1580 | { |
| 1581 | static const s32 ht20[] = { 6500, 13000, 19500, 26000, 39000, |
| 1582 | 52000, 58500, 65000, 72200 |
| 1583 | }; |
| 1584 | u8 i; |
| 1585 | |
| 1586 | for (i = 0; i < ARRAY_SIZE(ht20); i++) { |
| 1587 | if (rate == ht20[i]) { |
| 1588 | if (i == ARRAY_SIZE(ht20) - 1) |
| 1589 | /* last rate uses sgi */ |
| 1590 | *sgi = true; |
| 1591 | else |
| 1592 | *sgi = false; |
| 1593 | |
| 1594 | *mcs = i; |
| 1595 | return true; |
| 1596 | } |
| 1597 | } |
| 1598 | return false; |
| 1599 | } |
| 1600 | |
| 1601 | static bool is_rate_ht40(s32 rate, u8 *mcs, bool *sgi) |
| 1602 | { |
| 1603 | static const s32 ht40[] = { 13500, 27000, 40500, 54000, |
| 1604 | 81000, 108000, 121500, 135000, |
| 1605 | 150000 |
| 1606 | }; |
| 1607 | u8 i; |
| 1608 | |
| 1609 | for (i = 0; i < ARRAY_SIZE(ht40); i++) { |
| 1610 | if (rate == ht40[i]) { |
| 1611 | if (i == ARRAY_SIZE(ht40) - 1) |
| 1612 | /* last rate uses sgi */ |
| 1613 | *sgi = true; |
| 1614 | else |
| 1615 | *sgi = false; |
| 1616 | |
| 1617 | *mcs = i; |
| 1618 | return true; |
| 1619 | } |
| 1620 | } |
| 1621 | |
| 1622 | return false; |
| 1623 | } |
| 1624 | |
| 1625 | static int ath6kl_get_station(struct wiphy *wiphy, struct net_device *dev, |
| 1626 | u8 *mac, struct station_info *sinfo) |
| 1627 | { |
| 1628 | struct ath6kl *ar = ath6kl_priv(dev); |
Vasanthakumar Thiagarajan | 59c9844 | 2011-10-25 19:34:01 +0530 | [diff] [blame] | 1629 | struct ath6kl_vif *vif = netdev_priv(dev); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1630 | long left; |
| 1631 | bool sgi; |
| 1632 | s32 rate; |
| 1633 | int ret; |
| 1634 | u8 mcs; |
| 1635 | |
Vasanthakumar Thiagarajan | 8c8b65e | 2011-10-25 19:34:04 +0530 | [diff] [blame] | 1636 | if (memcmp(mac, vif->bssid, ETH_ALEN) != 0) |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1637 | return -ENOENT; |
| 1638 | |
| 1639 | if (down_interruptible(&ar->sem)) |
| 1640 | return -EBUSY; |
| 1641 | |
Vasanthakumar Thiagarajan | b95907a | 2011-10-25 19:34:11 +0530 | [diff] [blame] | 1642 | set_bit(STATS_UPDATE_PEND, &vif->flags); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1643 | |
Vasanthakumar Thiagarajan | 334234b | 2011-10-25 19:34:12 +0530 | [diff] [blame] | 1644 | ret = ath6kl_wmi_get_stats_cmd(ar->wmi, vif->fw_vif_idx); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1645 | |
| 1646 | if (ret != 0) { |
| 1647 | up(&ar->sem); |
| 1648 | return -EIO; |
| 1649 | } |
| 1650 | |
| 1651 | left = wait_event_interruptible_timeout(ar->event_wq, |
| 1652 | !test_bit(STATS_UPDATE_PEND, |
Vasanthakumar Thiagarajan | b95907a | 2011-10-25 19:34:11 +0530 | [diff] [blame] | 1653 | &vif->flags), |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1654 | WMI_TIMEOUT); |
| 1655 | |
| 1656 | up(&ar->sem); |
| 1657 | |
| 1658 | if (left == 0) |
| 1659 | return -ETIMEDOUT; |
| 1660 | else if (left < 0) |
| 1661 | return left; |
| 1662 | |
Vasanthakumar Thiagarajan | b95907a | 2011-10-25 19:34:11 +0530 | [diff] [blame] | 1663 | if (vif->target_stats.rx_byte) { |
| 1664 | sinfo->rx_bytes = vif->target_stats.rx_byte; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1665 | sinfo->filled |= STATION_INFO_RX_BYTES; |
Vasanthakumar Thiagarajan | b95907a | 2011-10-25 19:34:11 +0530 | [diff] [blame] | 1666 | sinfo->rx_packets = vif->target_stats.rx_pkt; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1667 | sinfo->filled |= STATION_INFO_RX_PACKETS; |
| 1668 | } |
| 1669 | |
Vasanthakumar Thiagarajan | b95907a | 2011-10-25 19:34:11 +0530 | [diff] [blame] | 1670 | if (vif->target_stats.tx_byte) { |
| 1671 | sinfo->tx_bytes = vif->target_stats.tx_byte; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1672 | sinfo->filled |= STATION_INFO_TX_BYTES; |
Vasanthakumar Thiagarajan | b95907a | 2011-10-25 19:34:11 +0530 | [diff] [blame] | 1673 | sinfo->tx_packets = vif->target_stats.tx_pkt; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1674 | sinfo->filled |= STATION_INFO_TX_PACKETS; |
| 1675 | } |
| 1676 | |
Vasanthakumar Thiagarajan | b95907a | 2011-10-25 19:34:11 +0530 | [diff] [blame] | 1677 | sinfo->signal = vif->target_stats.cs_rssi; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1678 | sinfo->filled |= STATION_INFO_SIGNAL; |
| 1679 | |
Vasanthakumar Thiagarajan | b95907a | 2011-10-25 19:34:11 +0530 | [diff] [blame] | 1680 | rate = vif->target_stats.tx_ucast_rate; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1681 | |
| 1682 | if (is_rate_legacy(rate)) { |
| 1683 | sinfo->txrate.legacy = rate / 100; |
| 1684 | } else if (is_rate_ht20(rate, &mcs, &sgi)) { |
| 1685 | if (sgi) { |
| 1686 | sinfo->txrate.flags |= RATE_INFO_FLAGS_SHORT_GI; |
| 1687 | sinfo->txrate.mcs = mcs - 1; |
| 1688 | } else { |
| 1689 | sinfo->txrate.mcs = mcs; |
| 1690 | } |
| 1691 | |
| 1692 | sinfo->txrate.flags |= RATE_INFO_FLAGS_MCS; |
| 1693 | } else if (is_rate_ht40(rate, &mcs, &sgi)) { |
| 1694 | if (sgi) { |
| 1695 | sinfo->txrate.flags |= RATE_INFO_FLAGS_SHORT_GI; |
| 1696 | sinfo->txrate.mcs = mcs - 1; |
| 1697 | } else { |
| 1698 | sinfo->txrate.mcs = mcs; |
| 1699 | } |
| 1700 | |
| 1701 | sinfo->txrate.flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH; |
| 1702 | sinfo->txrate.flags |= RATE_INFO_FLAGS_MCS; |
| 1703 | } else { |
Kalle Valo | 9a73083 | 2011-09-27 23:33:28 +0300 | [diff] [blame] | 1704 | ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, |
| 1705 | "invalid rate from stats: %d\n", rate); |
| 1706 | ath6kl_debug_war(ar, ATH6KL_WAR_INVALID_RATE); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1707 | return 0; |
| 1708 | } |
| 1709 | |
| 1710 | sinfo->filled |= STATION_INFO_TX_BITRATE; |
| 1711 | |
Vasanthakumar Thiagarajan | 59c9844 | 2011-10-25 19:34:01 +0530 | [diff] [blame] | 1712 | if (test_bit(CONNECTED, &vif->flags) && |
| 1713 | test_bit(DTIM_PERIOD_AVAIL, &vif->flags) && |
Vasanthakumar Thiagarajan | f5938f2 | 2011-10-25 19:34:03 +0530 | [diff] [blame] | 1714 | vif->nw_type == INFRA_NETWORK) { |
Jouni Malinen | 32c1087 | 2011-09-19 19:15:07 +0300 | [diff] [blame] | 1715 | sinfo->filled |= STATION_INFO_BSS_PARAM; |
| 1716 | sinfo->bss_param.flags = 0; |
Vasanthakumar Thiagarajan | cf5333d | 2011-10-25 19:34:10 +0530 | [diff] [blame] | 1717 | sinfo->bss_param.dtim_period = vif->assoc_bss_dtim_period; |
| 1718 | sinfo->bss_param.beacon_interval = vif->assoc_bss_beacon_int; |
Jouni Malinen | 32c1087 | 2011-09-19 19:15:07 +0300 | [diff] [blame] | 1719 | } |
| 1720 | |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1721 | return 0; |
| 1722 | } |
| 1723 | |
| 1724 | static int ath6kl_set_pmksa(struct wiphy *wiphy, struct net_device *netdev, |
| 1725 | struct cfg80211_pmksa *pmksa) |
| 1726 | { |
| 1727 | struct ath6kl *ar = ath6kl_priv(netdev); |
Vasanthakumar Thiagarajan | 334234b | 2011-10-25 19:34:12 +0530 | [diff] [blame] | 1728 | struct ath6kl_vif *vif = netdev_priv(netdev); |
| 1729 | |
| 1730 | return ath6kl_wmi_setpmkid_cmd(ar->wmi, vif->fw_vif_idx, pmksa->bssid, |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1731 | pmksa->pmkid, true); |
| 1732 | } |
| 1733 | |
| 1734 | static int ath6kl_del_pmksa(struct wiphy *wiphy, struct net_device *netdev, |
| 1735 | struct cfg80211_pmksa *pmksa) |
| 1736 | { |
| 1737 | struct ath6kl *ar = ath6kl_priv(netdev); |
Vasanthakumar Thiagarajan | 334234b | 2011-10-25 19:34:12 +0530 | [diff] [blame] | 1738 | struct ath6kl_vif *vif = netdev_priv(netdev); |
| 1739 | |
| 1740 | return ath6kl_wmi_setpmkid_cmd(ar->wmi, vif->fw_vif_idx, pmksa->bssid, |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1741 | pmksa->pmkid, false); |
| 1742 | } |
| 1743 | |
| 1744 | static int ath6kl_flush_pmksa(struct wiphy *wiphy, struct net_device *netdev) |
| 1745 | { |
| 1746 | struct ath6kl *ar = ath6kl_priv(netdev); |
Vasanthakumar Thiagarajan | 59c9844 | 2011-10-25 19:34:01 +0530 | [diff] [blame] | 1747 | struct ath6kl_vif *vif = netdev_priv(netdev); |
| 1748 | |
| 1749 | if (test_bit(CONNECTED, &vif->flags)) |
Vasanthakumar Thiagarajan | 334234b | 2011-10-25 19:34:12 +0530 | [diff] [blame] | 1750 | return ath6kl_wmi_setpmkid_cmd(ar->wmi, vif->fw_vif_idx, |
| 1751 | vif->bssid, NULL, false); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1752 | return 0; |
| 1753 | } |
| 1754 | |
Raja Mani | d91e8ee | 2012-01-30 17:13:10 +0530 | [diff] [blame] | 1755 | static int ath6kl_wow_usr(struct ath6kl *ar, struct ath6kl_vif *vif, |
| 1756 | struct cfg80211_wowlan *wow, u32 *filter) |
Raja Mani | 6cb3c71 | 2011-11-07 22:52:45 +0200 | [diff] [blame] | 1757 | { |
Raja Mani | d91e8ee | 2012-01-30 17:13:10 +0530 | [diff] [blame] | 1758 | int ret, pos; |
| 1759 | u8 mask[WOW_MASK_SIZE]; |
Raja Mani | 6cb3c71 | 2011-11-07 22:52:45 +0200 | [diff] [blame] | 1760 | u16 i; |
Raja Mani | 6cb3c71 | 2011-11-07 22:52:45 +0200 | [diff] [blame] | 1761 | |
Raja Mani | d91e8ee | 2012-01-30 17:13:10 +0530 | [diff] [blame] | 1762 | /* Configure the patterns that we received from the user. */ |
Raja Mani | 6cb3c71 | 2011-11-07 22:52:45 +0200 | [diff] [blame] | 1763 | for (i = 0; i < wow->n_patterns; i++) { |
| 1764 | |
| 1765 | /* |
| 1766 | * Convert given nl80211 specific mask value to equivalent |
| 1767 | * driver specific mask value and send it to the chip along |
| 1768 | * with patterns. For example, If the mask value defined in |
| 1769 | * struct cfg80211_wowlan is 0xA (equivalent binary is 1010), |
| 1770 | * then equivalent driver specific mask value is |
| 1771 | * "0xFF 0x00 0xFF 0x00". |
| 1772 | */ |
| 1773 | memset(&mask, 0, sizeof(mask)); |
| 1774 | for (pos = 0; pos < wow->patterns[i].pattern_len; pos++) { |
| 1775 | if (wow->patterns[i].mask[pos / 8] & (0x1 << (pos % 8))) |
| 1776 | mask[pos] = 0xFF; |
| 1777 | } |
| 1778 | /* |
| 1779 | * Note: Pattern's offset is not passed as part of wowlan |
| 1780 | * parameter from CFG layer. So it's always passed as ZERO |
| 1781 | * to the firmware. It means, given WOW patterns are always |
| 1782 | * matched from the first byte of received pkt in the firmware. |
| 1783 | */ |
| 1784 | ret = ath6kl_wmi_add_wow_pattern_cmd(ar->wmi, |
Raja Mani | d91e8ee | 2012-01-30 17:13:10 +0530 | [diff] [blame] | 1785 | vif->fw_vif_idx, WOW_LIST_ID, |
| 1786 | wow->patterns[i].pattern_len, |
| 1787 | 0 /* pattern offset */, |
| 1788 | wow->patterns[i].pattern, mask); |
Raja Mani | 6cb3c71 | 2011-11-07 22:52:45 +0200 | [diff] [blame] | 1789 | if (ret) |
| 1790 | return ret; |
| 1791 | } |
| 1792 | |
Raja Mani | d91e8ee | 2012-01-30 17:13:10 +0530 | [diff] [blame] | 1793 | if (wow->disconnect) |
| 1794 | *filter |= WOW_FILTER_OPTION_NWK_DISASSOC; |
| 1795 | |
| 1796 | if (wow->magic_pkt) |
| 1797 | *filter |= WOW_FILTER_OPTION_MAGIC_PACKET; |
| 1798 | |
| 1799 | if (wow->gtk_rekey_failure) |
| 1800 | *filter |= WOW_FILTER_OPTION_GTK_ERROR; |
| 1801 | |
| 1802 | if (wow->eap_identity_req) |
| 1803 | *filter |= WOW_FILTER_OPTION_EAP_REQ; |
| 1804 | |
| 1805 | if (wow->four_way_handshake) |
| 1806 | *filter |= WOW_FILTER_OPTION_8021X_4WAYHS; |
| 1807 | |
| 1808 | return 0; |
| 1809 | } |
| 1810 | |
| 1811 | static int ath6kl_wow_ap(struct ath6kl *ar, struct ath6kl_vif *vif) |
| 1812 | { |
| 1813 | static const u8 unicst_pattern[] = { 0x00, 0x00, 0x00, |
| 1814 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 1815 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 1816 | 0x00, 0x08 }; |
| 1817 | static const u8 unicst_mask[] = { 0x01, 0x00, 0x00, |
| 1818 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 1819 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 1820 | 0x00, 0x7f }; |
| 1821 | u8 unicst_offset = 0; |
| 1822 | static const u8 arp_pattern[] = { 0x08, 0x06 }; |
| 1823 | static const u8 arp_mask[] = { 0xff, 0xff }; |
| 1824 | u8 arp_offset = 20; |
| 1825 | static const u8 discvr_pattern[] = { 0xe0, 0x00, 0x00, 0xf8 }; |
| 1826 | static const u8 discvr_mask[] = { 0xf0, 0x00, 0x00, 0xf8 }; |
| 1827 | u8 discvr_offset = 38; |
| 1828 | static const u8 dhcp_pattern[] = { 0xff, 0xff, 0xff, 0xff, |
| 1829 | 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 1830 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, |
| 1831 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 1832 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 1833 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x43 /* port 67 */ }; |
| 1834 | static const u8 dhcp_mask[] = { 0xff, 0xff, 0xff, 0xff, |
| 1835 | 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 1836 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, |
| 1837 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 1838 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 1839 | 0x00, 0x00, 0x00, 0x00, 0xff, 0xff /* port 67 */ }; |
| 1840 | u8 dhcp_offset = 0; |
| 1841 | int ret; |
| 1842 | |
| 1843 | /* Setup unicast IP, EAPOL-like and ARP pkt pattern */ |
| 1844 | ret = ath6kl_wmi_add_wow_pattern_cmd(ar->wmi, |
| 1845 | vif->fw_vif_idx, WOW_LIST_ID, |
| 1846 | sizeof(unicst_pattern), unicst_offset, |
| 1847 | unicst_pattern, unicst_mask); |
| 1848 | if (ret) { |
| 1849 | ath6kl_err("failed to add WOW unicast IP pattern\n"); |
| 1850 | return ret; |
| 1851 | } |
| 1852 | |
| 1853 | /* Setup all ARP pkt pattern */ |
| 1854 | ret = ath6kl_wmi_add_wow_pattern_cmd(ar->wmi, |
| 1855 | vif->fw_vif_idx, WOW_LIST_ID, |
| 1856 | sizeof(arp_pattern), arp_offset, |
| 1857 | arp_pattern, arp_mask); |
| 1858 | if (ret) { |
| 1859 | ath6kl_err("failed to add WOW ARP pattern\n"); |
| 1860 | return ret; |
| 1861 | } |
| 1862 | |
| 1863 | /* |
| 1864 | * Setup multicast pattern for mDNS 224.0.0.251, |
| 1865 | * SSDP 239.255.255.250 and LLMNR 224.0.0.252 |
| 1866 | */ |
| 1867 | ret = ath6kl_wmi_add_wow_pattern_cmd(ar->wmi, |
| 1868 | vif->fw_vif_idx, WOW_LIST_ID, |
| 1869 | sizeof(discvr_pattern), discvr_offset, |
| 1870 | discvr_pattern, discvr_mask); |
| 1871 | if (ret) { |
| 1872 | ath6kl_err("failed to add WOW mDNS/SSDP/LLMNR pattern\n"); |
| 1873 | return ret; |
| 1874 | } |
| 1875 | |
| 1876 | /* Setup all DHCP broadcast pkt pattern */ |
| 1877 | ret = ath6kl_wmi_add_wow_pattern_cmd(ar->wmi, |
| 1878 | vif->fw_vif_idx, WOW_LIST_ID, |
| 1879 | sizeof(dhcp_pattern), dhcp_offset, |
| 1880 | dhcp_pattern, dhcp_mask); |
| 1881 | if (ret) { |
| 1882 | ath6kl_err("failed to add WOW DHCP broadcast pattern\n"); |
| 1883 | return ret; |
| 1884 | } |
| 1885 | |
| 1886 | return 0; |
| 1887 | } |
| 1888 | |
| 1889 | static int ath6kl_wow_sta(struct ath6kl *ar, struct ath6kl_vif *vif) |
| 1890 | { |
| 1891 | struct net_device *ndev = vif->ndev; |
| 1892 | static const u8 discvr_pattern[] = { 0xe0, 0x00, 0x00, 0xf8 }; |
| 1893 | static const u8 discvr_mask[] = { 0xf0, 0x00, 0x00, 0xf8 }; |
| 1894 | u8 discvr_offset = 38; |
| 1895 | u8 mac_mask[ETH_ALEN]; |
| 1896 | int ret; |
| 1897 | |
| 1898 | /* Setup unicast pkt pattern */ |
| 1899 | memset(mac_mask, 0xff, ETH_ALEN); |
| 1900 | ret = ath6kl_wmi_add_wow_pattern_cmd(ar->wmi, |
| 1901 | vif->fw_vif_idx, WOW_LIST_ID, |
| 1902 | ETH_ALEN, 0, ndev->dev_addr, |
| 1903 | mac_mask); |
| 1904 | if (ret) { |
| 1905 | ath6kl_err("failed to add WOW unicast pattern\n"); |
| 1906 | return ret; |
| 1907 | } |
| 1908 | |
| 1909 | /* |
| 1910 | * Setup multicast pattern for mDNS 224.0.0.251, |
| 1911 | * SSDP 239.255.255.250 and LLMNR 224.0.0.252 |
| 1912 | */ |
| 1913 | if ((ndev->flags & IFF_ALLMULTI) || |
| 1914 | (ndev->flags & IFF_MULTICAST && netdev_mc_count(ndev) > 0)) { |
| 1915 | ret = ath6kl_wmi_add_wow_pattern_cmd(ar->wmi, |
| 1916 | vif->fw_vif_idx, WOW_LIST_ID, |
| 1917 | sizeof(discvr_pattern), discvr_offset, |
| 1918 | discvr_pattern, discvr_mask); |
| 1919 | if (ret) { |
| 1920 | ath6kl_err("failed to add WOW mDNS/SSDP/LLMNR " |
| 1921 | "pattern\n"); |
| 1922 | return ret; |
| 1923 | } |
| 1924 | } |
| 1925 | |
| 1926 | return 0; |
| 1927 | } |
| 1928 | |
| 1929 | static int ath6kl_wow_suspend(struct ath6kl *ar, struct cfg80211_wowlan *wow) |
| 1930 | { |
| 1931 | struct in_device *in_dev; |
| 1932 | struct in_ifaddr *ifa; |
| 1933 | struct ath6kl_vif *vif; |
| 1934 | int ret, left; |
| 1935 | u32 filter = 0; |
Raja Mani | ce0dc0c | 2012-02-20 19:08:08 +0530 | [diff] [blame] | 1936 | u16 i, bmiss_time; |
Raja Mani | d91e8ee | 2012-01-30 17:13:10 +0530 | [diff] [blame] | 1937 | u8 index = 0; |
| 1938 | __be32 ips[MAX_IP_ADDRS]; |
| 1939 | |
| 1940 | vif = ath6kl_vif_first(ar); |
| 1941 | if (!vif) |
| 1942 | return -EIO; |
| 1943 | |
| 1944 | if (!ath6kl_cfg80211_ready(vif)) |
| 1945 | return -EIO; |
| 1946 | |
| 1947 | if (!test_bit(CONNECTED, &vif->flags)) |
Raja Mani | 3c411a4 | 2012-01-30 17:13:12 +0530 | [diff] [blame] | 1948 | return -ENOTCONN; |
Raja Mani | d91e8ee | 2012-01-30 17:13:10 +0530 | [diff] [blame] | 1949 | |
| 1950 | if (wow && (wow->n_patterns > WOW_MAX_FILTERS_PER_LIST)) |
| 1951 | return -EINVAL; |
| 1952 | |
| 1953 | /* Clear existing WOW patterns */ |
| 1954 | for (i = 0; i < WOW_MAX_FILTERS_PER_LIST; i++) |
| 1955 | ath6kl_wmi_del_wow_pattern_cmd(ar->wmi, vif->fw_vif_idx, |
| 1956 | WOW_LIST_ID, i); |
| 1957 | |
| 1958 | /* |
| 1959 | * Skip the default WOW pattern configuration |
| 1960 | * if the driver receives any WOW patterns from |
| 1961 | * the user. |
| 1962 | */ |
| 1963 | if (wow) |
| 1964 | ret = ath6kl_wow_usr(ar, vif, wow, &filter); |
| 1965 | else if (vif->nw_type == AP_NETWORK) |
| 1966 | ret = ath6kl_wow_ap(ar, vif); |
| 1967 | else |
| 1968 | ret = ath6kl_wow_sta(ar, vif); |
| 1969 | |
| 1970 | if (ret) |
| 1971 | return ret; |
| 1972 | |
Raja Mani | 390a8c8 | 2012-03-07 11:35:04 +0530 | [diff] [blame] | 1973 | netif_stop_queue(vif->ndev); |
| 1974 | |
Raja Mani | ce0dc0c | 2012-02-20 19:08:08 +0530 | [diff] [blame] | 1975 | if (vif->nw_type != AP_NETWORK) { |
| 1976 | ret = ath6kl_wmi_listeninterval_cmd(ar->wmi, vif->fw_vif_idx, |
| 1977 | ATH6KL_MAX_WOW_LISTEN_INTL, |
| 1978 | 0); |
| 1979 | if (ret) |
| 1980 | return ret; |
| 1981 | |
| 1982 | /* Set listen interval x 15 times as bmiss time */ |
| 1983 | bmiss_time = ATH6KL_MAX_WOW_LISTEN_INTL * 15; |
| 1984 | if (bmiss_time > ATH6KL_MAX_BMISS_TIME) |
| 1985 | bmiss_time = ATH6KL_MAX_BMISS_TIME; |
| 1986 | |
| 1987 | ret = ath6kl_wmi_bmisstime_cmd(ar->wmi, vif->fw_vif_idx, |
| 1988 | bmiss_time, 0); |
| 1989 | if (ret) |
| 1990 | return ret; |
| 1991 | |
| 1992 | ret = ath6kl_wmi_scanparams_cmd(ar->wmi, vif->fw_vif_idx, |
| 1993 | 0xFFFF, 0, 0xFFFF, 0, 0, 0, |
| 1994 | 0, 0, 0, 0); |
| 1995 | if (ret) |
| 1996 | return ret; |
| 1997 | } |
| 1998 | |
Raja Mani | 390a8c8 | 2012-03-07 11:35:04 +0530 | [diff] [blame] | 1999 | ar->state = ATH6KL_STATE_SUSPENDING; |
| 2000 | |
Raja Mani | c08631c | 2011-12-16 14:24:24 +0530 | [diff] [blame] | 2001 | /* Setup own IP addr for ARP agent. */ |
| 2002 | in_dev = __in_dev_get_rtnl(vif->ndev); |
| 2003 | if (!in_dev) |
| 2004 | goto skip_arp; |
| 2005 | |
| 2006 | ifa = in_dev->ifa_list; |
| 2007 | memset(&ips, 0, sizeof(ips)); |
| 2008 | |
| 2009 | /* Configure IP addr only if IP address count < MAX_IP_ADDRS */ |
| 2010 | while (index < MAX_IP_ADDRS && ifa) { |
| 2011 | ips[index] = ifa->ifa_local; |
| 2012 | ifa = ifa->ifa_next; |
| 2013 | index++; |
| 2014 | } |
| 2015 | |
| 2016 | if (ifa) { |
| 2017 | ath6kl_err("total IP addr count is exceeding fw limit\n"); |
| 2018 | return -EINVAL; |
| 2019 | } |
| 2020 | |
| 2021 | ret = ath6kl_wmi_set_ip_cmd(ar->wmi, vif->fw_vif_idx, ips[0], ips[1]); |
| 2022 | if (ret) { |
| 2023 | ath6kl_err("fail to setup ip for arp agent\n"); |
| 2024 | return ret; |
| 2025 | } |
| 2026 | |
| 2027 | skip_arp: |
Raja Mani | 6cb3c71 | 2011-11-07 22:52:45 +0200 | [diff] [blame] | 2028 | ret = ath6kl_wmi_set_wow_mode_cmd(ar->wmi, vif->fw_vif_idx, |
| 2029 | ATH6KL_WOW_MODE_ENABLE, |
| 2030 | filter, |
| 2031 | WOW_HOST_REQ_DELAY); |
| 2032 | if (ret) |
| 2033 | return ret; |
| 2034 | |
Raja Mani | 081c7a8 | 2012-01-30 17:13:11 +0530 | [diff] [blame] | 2035 | clear_bit(HOST_SLEEP_MODE_CMD_PROCESSED, &vif->flags); |
| 2036 | |
Raja Mani | 6cb3c71 | 2011-11-07 22:52:45 +0200 | [diff] [blame] | 2037 | ret = ath6kl_wmi_set_host_sleep_mode_cmd(ar->wmi, vif->fw_vif_idx, |
| 2038 | ATH6KL_HOST_MODE_ASLEEP); |
| 2039 | if (ret) |
| 2040 | return ret; |
| 2041 | |
Raja Mani | 081c7a8 | 2012-01-30 17:13:11 +0530 | [diff] [blame] | 2042 | left = wait_event_interruptible_timeout(ar->event_wq, |
| 2043 | test_bit(HOST_SLEEP_MODE_CMD_PROCESSED, &vif->flags), |
| 2044 | WMI_TIMEOUT); |
| 2045 | if (left == 0) { |
| 2046 | ath6kl_warn("timeout, didn't get host sleep cmd " |
| 2047 | "processed event\n"); |
| 2048 | ret = -ETIMEDOUT; |
| 2049 | } else if (left < 0) { |
| 2050 | ath6kl_warn("error while waiting for host sleep cmd " |
| 2051 | "processed event %d\n", left); |
| 2052 | ret = left; |
| 2053 | } |
| 2054 | |
Raja Mani | 6cb3c71 | 2011-11-07 22:52:45 +0200 | [diff] [blame] | 2055 | if (ar->tx_pending[ar->ctrl_ep]) { |
| 2056 | left = wait_event_interruptible_timeout(ar->event_wq, |
| 2057 | ar->tx_pending[ar->ctrl_ep] == 0, WMI_TIMEOUT); |
| 2058 | if (left == 0) { |
| 2059 | ath6kl_warn("clear wmi ctrl data timeout\n"); |
| 2060 | ret = -ETIMEDOUT; |
| 2061 | } else if (left < 0) { |
| 2062 | ath6kl_warn("clear wmi ctrl data failed: %d\n", left); |
| 2063 | ret = left; |
| 2064 | } |
| 2065 | } |
| 2066 | |
| 2067 | return ret; |
| 2068 | } |
| 2069 | |
| 2070 | static int ath6kl_wow_resume(struct ath6kl *ar) |
| 2071 | { |
| 2072 | struct ath6kl_vif *vif; |
| 2073 | int ret; |
| 2074 | |
| 2075 | vif = ath6kl_vif_first(ar); |
| 2076 | if (!vif) |
| 2077 | return -EIO; |
| 2078 | |
Raja Mani | 390a8c8 | 2012-03-07 11:35:04 +0530 | [diff] [blame] | 2079 | ar->state = ATH6KL_STATE_RESUMING; |
| 2080 | |
Raja Mani | 6cb3c71 | 2011-11-07 22:52:45 +0200 | [diff] [blame] | 2081 | ret = ath6kl_wmi_set_host_sleep_mode_cmd(ar->wmi, vif->fw_vif_idx, |
| 2082 | ATH6KL_HOST_MODE_AWAKE); |
Raja Mani | 390a8c8 | 2012-03-07 11:35:04 +0530 | [diff] [blame] | 2083 | if (ret) { |
| 2084 | ath6kl_warn("Failed to configure host sleep mode for " |
| 2085 | "wow resume: %d\n", ret); |
| 2086 | ar->state = ATH6KL_STATE_WOW; |
| 2087 | return ret; |
| 2088 | } |
| 2089 | |
Raja Mani | ce0dc0c | 2012-02-20 19:08:08 +0530 | [diff] [blame] | 2090 | if (vif->nw_type != AP_NETWORK) { |
| 2091 | ret = ath6kl_wmi_scanparams_cmd(ar->wmi, vif->fw_vif_idx, |
| 2092 | 0, 0, 0, 0, 0, 0, 3, 0, 0, 0); |
| 2093 | if (ret) |
| 2094 | return ret; |
| 2095 | |
| 2096 | ret = ath6kl_wmi_listeninterval_cmd(ar->wmi, vif->fw_vif_idx, |
| 2097 | vif->listen_intvl_t, 0); |
| 2098 | if (ret) |
| 2099 | return ret; |
| 2100 | |
| 2101 | ret = ath6kl_wmi_bmisstime_cmd(ar->wmi, vif->fw_vif_idx, |
| 2102 | vif->bmiss_time_t, 0); |
| 2103 | if (ret) |
| 2104 | return ret; |
| 2105 | } |
| 2106 | |
Raja Mani | 390a8c8 | 2012-03-07 11:35:04 +0530 | [diff] [blame] | 2107 | ar->state = ATH6KL_STATE_ON; |
| 2108 | |
| 2109 | netif_wake_queue(vif->ndev); |
| 2110 | |
| 2111 | return 0; |
Raja Mani | 6cb3c71 | 2011-11-07 22:52:45 +0200 | [diff] [blame] | 2112 | } |
| 2113 | |
Kalle Valo | 52d81a6 | 2011-11-01 08:44:21 +0200 | [diff] [blame] | 2114 | int ath6kl_cfg80211_suspend(struct ath6kl *ar, |
Raja Mani | 0f60e9f | 2011-11-07 22:52:45 +0200 | [diff] [blame] | 2115 | enum ath6kl_cfg_suspend_mode mode, |
| 2116 | struct cfg80211_wowlan *wow) |
Kalle Valo | 52d81a6 | 2011-11-01 08:44:21 +0200 | [diff] [blame] | 2117 | { |
Raja Mani | 390a8c8 | 2012-03-07 11:35:04 +0530 | [diff] [blame] | 2118 | enum ath6kl_state prev_state; |
Kalle Valo | 52d81a6 | 2011-11-01 08:44:21 +0200 | [diff] [blame] | 2119 | int ret; |
| 2120 | |
Kalle Valo | 52d81a6 | 2011-11-01 08:44:21 +0200 | [diff] [blame] | 2121 | switch (mode) { |
Raja Mani | d7c44e0 | 2011-11-07 22:52:46 +0200 | [diff] [blame] | 2122 | case ATH6KL_CFG_SUSPEND_WOW: |
| 2123 | |
| 2124 | ath6kl_dbg(ATH6KL_DBG_SUSPEND, "wow mode suspend\n"); |
| 2125 | |
| 2126 | /* Flush all non control pkts in TX path */ |
| 2127 | ath6kl_tx_data_cleanup(ar); |
| 2128 | |
Raja Mani | 390a8c8 | 2012-03-07 11:35:04 +0530 | [diff] [blame] | 2129 | prev_state = ar->state; |
| 2130 | |
Raja Mani | d7c44e0 | 2011-11-07 22:52:46 +0200 | [diff] [blame] | 2131 | ret = ath6kl_wow_suspend(ar, wow); |
Raja Mani | 390a8c8 | 2012-03-07 11:35:04 +0530 | [diff] [blame] | 2132 | if (ret) { |
| 2133 | ar->state = prev_state; |
Raja Mani | d7c44e0 | 2011-11-07 22:52:46 +0200 | [diff] [blame] | 2134 | return ret; |
Raja Mani | 390a8c8 | 2012-03-07 11:35:04 +0530 | [diff] [blame] | 2135 | } |
Raja Mani | 1e9a905 | 2012-03-06 15:03:59 +0530 | [diff] [blame] | 2136 | |
Raja Mani | d7c44e0 | 2011-11-07 22:52:46 +0200 | [diff] [blame] | 2137 | ar->state = ATH6KL_STATE_WOW; |
| 2138 | break; |
| 2139 | |
Kalle Valo | 52d81a6 | 2011-11-01 08:44:21 +0200 | [diff] [blame] | 2140 | case ATH6KL_CFG_SUSPEND_DEEPSLEEP: |
Raja Mani | 524441e | 2011-11-07 22:52:46 +0200 | [diff] [blame] | 2141 | |
Kalle Valo | 7125f01 | 2011-12-13 14:51:37 +0200 | [diff] [blame] | 2142 | ath6kl_cfg80211_stop_all(ar); |
Raja Mani | 524441e | 2011-11-07 22:52:46 +0200 | [diff] [blame] | 2143 | |
Kalle Valo | 52d81a6 | 2011-11-01 08:44:21 +0200 | [diff] [blame] | 2144 | /* save the current power mode before enabling power save */ |
| 2145 | ar->wmi->saved_pwr_mode = ar->wmi->pwr_mode; |
| 2146 | |
| 2147 | ret = ath6kl_wmi_powermode_cmd(ar->wmi, 0, REC_POWER); |
| 2148 | if (ret) { |
| 2149 | ath6kl_warn("wmi powermode command failed during suspend: %d\n", |
| 2150 | ret); |
| 2151 | } |
| 2152 | |
Kalle Valo | 76a9fbe | 2011-11-01 08:44:28 +0200 | [diff] [blame] | 2153 | ar->state = ATH6KL_STATE_DEEPSLEEP; |
| 2154 | |
Kalle Valo | 52d81a6 | 2011-11-01 08:44:21 +0200 | [diff] [blame] | 2155 | break; |
Kalle Valo | b4b2a0b | 2011-11-01 08:44:44 +0200 | [diff] [blame] | 2156 | |
| 2157 | case ATH6KL_CFG_SUSPEND_CUTPOWER: |
Raja Mani | 524441e | 2011-11-07 22:52:46 +0200 | [diff] [blame] | 2158 | |
Kalle Valo | 7125f01 | 2011-12-13 14:51:37 +0200 | [diff] [blame] | 2159 | ath6kl_cfg80211_stop_all(ar); |
Raja Mani | 524441e | 2011-11-07 22:52:46 +0200 | [diff] [blame] | 2160 | |
Kalle Valo | b4b2a0b | 2011-11-01 08:44:44 +0200 | [diff] [blame] | 2161 | if (ar->state == ATH6KL_STATE_OFF) { |
| 2162 | ath6kl_dbg(ATH6KL_DBG_SUSPEND, |
| 2163 | "suspend hw off, no action for cutpower\n"); |
| 2164 | break; |
| 2165 | } |
| 2166 | |
| 2167 | ath6kl_dbg(ATH6KL_DBG_SUSPEND, "suspend cutting power\n"); |
| 2168 | |
| 2169 | ret = ath6kl_init_hw_stop(ar); |
| 2170 | if (ret) { |
| 2171 | ath6kl_warn("failed to stop hw during suspend: %d\n", |
| 2172 | ret); |
| 2173 | } |
| 2174 | |
| 2175 | ar->state = ATH6KL_STATE_CUTPOWER; |
| 2176 | |
| 2177 | break; |
| 2178 | |
Kalle Valo | 10509f9 | 2011-12-13 14:52:07 +0200 | [diff] [blame] | 2179 | case ATH6KL_CFG_SUSPEND_SCHED_SCAN: |
| 2180 | /* |
| 2181 | * Nothing needed for schedule scan, firmware is already in |
| 2182 | * wow mode and sleeping most of the time. |
| 2183 | */ |
| 2184 | break; |
| 2185 | |
Kalle Valo | b4b2a0b | 2011-11-01 08:44:44 +0200 | [diff] [blame] | 2186 | default: |
| 2187 | break; |
Kalle Valo | 52d81a6 | 2011-11-01 08:44:21 +0200 | [diff] [blame] | 2188 | } |
| 2189 | |
| 2190 | return 0; |
| 2191 | } |
Kalle Valo | d6a434d | 2012-01-17 20:09:36 +0200 | [diff] [blame] | 2192 | EXPORT_SYMBOL(ath6kl_cfg80211_suspend); |
Kalle Valo | 52d81a6 | 2011-11-01 08:44:21 +0200 | [diff] [blame] | 2193 | |
| 2194 | int ath6kl_cfg80211_resume(struct ath6kl *ar) |
| 2195 | { |
Kalle Valo | 76a9fbe | 2011-11-01 08:44:28 +0200 | [diff] [blame] | 2196 | int ret; |
| 2197 | |
| 2198 | switch (ar->state) { |
Raja Mani | d7c44e0 | 2011-11-07 22:52:46 +0200 | [diff] [blame] | 2199 | case ATH6KL_STATE_WOW: |
| 2200 | ath6kl_dbg(ATH6KL_DBG_SUSPEND, "wow mode resume\n"); |
| 2201 | |
| 2202 | ret = ath6kl_wow_resume(ar); |
| 2203 | if (ret) { |
| 2204 | ath6kl_warn("wow mode resume failed: %d\n", ret); |
| 2205 | return ret; |
| 2206 | } |
| 2207 | |
Raja Mani | d7c44e0 | 2011-11-07 22:52:46 +0200 | [diff] [blame] | 2208 | break; |
| 2209 | |
Kalle Valo | 76a9fbe | 2011-11-01 08:44:28 +0200 | [diff] [blame] | 2210 | case ATH6KL_STATE_DEEPSLEEP: |
| 2211 | if (ar->wmi->pwr_mode != ar->wmi->saved_pwr_mode) { |
| 2212 | ret = ath6kl_wmi_powermode_cmd(ar->wmi, 0, |
| 2213 | ar->wmi->saved_pwr_mode); |
| 2214 | if (ret) { |
| 2215 | ath6kl_warn("wmi powermode command failed during resume: %d\n", |
| 2216 | ret); |
| 2217 | } |
| 2218 | } |
| 2219 | |
| 2220 | ar->state = ATH6KL_STATE_ON; |
| 2221 | |
| 2222 | break; |
| 2223 | |
Kalle Valo | b4b2a0b | 2011-11-01 08:44:44 +0200 | [diff] [blame] | 2224 | case ATH6KL_STATE_CUTPOWER: |
| 2225 | ath6kl_dbg(ATH6KL_DBG_SUSPEND, "resume restoring power\n"); |
| 2226 | |
| 2227 | ret = ath6kl_init_hw_start(ar); |
| 2228 | if (ret) { |
| 2229 | ath6kl_warn("Failed to boot hw in resume: %d\n", ret); |
| 2230 | return ret; |
| 2231 | } |
Raja Mani | d7c44e0 | 2011-11-07 22:52:46 +0200 | [diff] [blame] | 2232 | break; |
Kalle Valo | b4b2a0b | 2011-11-01 08:44:44 +0200 | [diff] [blame] | 2233 | |
Kalle Valo | 10509f9 | 2011-12-13 14:52:07 +0200 | [diff] [blame] | 2234 | case ATH6KL_STATE_SCHED_SCAN: |
| 2235 | break; |
| 2236 | |
Kalle Valo | 76a9fbe | 2011-11-01 08:44:28 +0200 | [diff] [blame] | 2237 | default: |
| 2238 | break; |
Kalle Valo | 52d81a6 | 2011-11-01 08:44:21 +0200 | [diff] [blame] | 2239 | } |
| 2240 | |
| 2241 | return 0; |
| 2242 | } |
Kalle Valo | d6a434d | 2012-01-17 20:09:36 +0200 | [diff] [blame] | 2243 | EXPORT_SYMBOL(ath6kl_cfg80211_resume); |
Kalle Valo | 52d81a6 | 2011-11-01 08:44:21 +0200 | [diff] [blame] | 2244 | |
Kalle Valo | abcb344 | 2011-07-22 08:26:20 +0300 | [diff] [blame] | 2245 | #ifdef CONFIG_PM |
Kalle Valo | 52d81a6 | 2011-11-01 08:44:21 +0200 | [diff] [blame] | 2246 | |
| 2247 | /* hif layer decides what suspend mode to use */ |
| 2248 | static int __ath6kl_cfg80211_suspend(struct wiphy *wiphy, |
Kalle Valo | abcb344 | 2011-07-22 08:26:20 +0300 | [diff] [blame] | 2249 | struct cfg80211_wowlan *wow) |
| 2250 | { |
| 2251 | struct ath6kl *ar = wiphy_priv(wiphy); |
| 2252 | |
Raja Mani | 0f60e9f | 2011-11-07 22:52:45 +0200 | [diff] [blame] | 2253 | return ath6kl_hif_suspend(ar, wow); |
Kalle Valo | abcb344 | 2011-07-22 08:26:20 +0300 | [diff] [blame] | 2254 | } |
Chilam Ng | aa6cffc | 2011-10-05 10:12:52 +0300 | [diff] [blame] | 2255 | |
Kalle Valo | 52d81a6 | 2011-11-01 08:44:21 +0200 | [diff] [blame] | 2256 | static int __ath6kl_cfg80211_resume(struct wiphy *wiphy) |
Chilam Ng | aa6cffc | 2011-10-05 10:12:52 +0300 | [diff] [blame] | 2257 | { |
| 2258 | struct ath6kl *ar = wiphy_priv(wiphy); |
| 2259 | |
| 2260 | return ath6kl_hif_resume(ar); |
| 2261 | } |
Raja Mani | a918fb3 | 2011-11-07 22:52:46 +0200 | [diff] [blame] | 2262 | |
| 2263 | /* |
| 2264 | * FIXME: WOW suspend mode is selected if the host sdio controller supports |
| 2265 | * both sdio irq wake up and keep power. The target pulls sdio data line to |
| 2266 | * wake up the host when WOW pattern matches. This causes sdio irq handler |
| 2267 | * is being called in the host side which internally hits ath6kl's RX path. |
| 2268 | * |
| 2269 | * Since sdio interrupt is not disabled, RX path executes even before |
| 2270 | * the host executes the actual resume operation from PM module. |
| 2271 | * |
| 2272 | * In the current scenario, WOW resume should happen before start processing |
| 2273 | * any data from the target. So It's required to perform WOW resume in RX path. |
| 2274 | * Ideally we should perform WOW resume only in the actual platform |
| 2275 | * resume path. This area needs bit rework to avoid WOW resume in RX path. |
| 2276 | * |
| 2277 | * ath6kl_check_wow_status() is called from ath6kl_rx(). |
| 2278 | */ |
| 2279 | void ath6kl_check_wow_status(struct ath6kl *ar) |
| 2280 | { |
Raja Mani | 390a8c8 | 2012-03-07 11:35:04 +0530 | [diff] [blame] | 2281 | if (ar->state == ATH6KL_STATE_SUSPENDING) |
| 2282 | return; |
| 2283 | |
Raja Mani | a918fb3 | 2011-11-07 22:52:46 +0200 | [diff] [blame] | 2284 | if (ar->state == ATH6KL_STATE_WOW) |
| 2285 | ath6kl_cfg80211_resume(ar); |
| 2286 | } |
| 2287 | |
| 2288 | #else |
| 2289 | |
| 2290 | void ath6kl_check_wow_status(struct ath6kl *ar) |
| 2291 | { |
| 2292 | } |
Kalle Valo | abcb344 | 2011-07-22 08:26:20 +0300 | [diff] [blame] | 2293 | #endif |
| 2294 | |
Jouni Malinen | 6a7c9ba | 2011-08-30 21:57:50 +0300 | [diff] [blame] | 2295 | static int ath6kl_set_channel(struct wiphy *wiphy, struct net_device *dev, |
| 2296 | struct ieee80211_channel *chan, |
| 2297 | enum nl80211_channel_type channel_type) |
| 2298 | { |
Sujith Manoharan | e68f675 | 2011-12-22 12:15:27 +0530 | [diff] [blame] | 2299 | struct ath6kl_vif *vif; |
| 2300 | |
| 2301 | /* |
| 2302 | * 'dev' could be NULL if a channel change is required for the hardware |
| 2303 | * device itself, instead of a particular VIF. |
| 2304 | * |
| 2305 | * FIXME: To be handled properly when monitor mode is supported. |
| 2306 | */ |
| 2307 | if (!dev) |
| 2308 | return -EBUSY; |
| 2309 | |
| 2310 | vif = netdev_priv(dev); |
Jouni Malinen | 6a7c9ba | 2011-08-30 21:57:50 +0300 | [diff] [blame] | 2311 | |
Vasanthakumar Thiagarajan | 990bd91 | 2011-10-25 19:34:20 +0530 | [diff] [blame] | 2312 | if (!ath6kl_cfg80211_ready(vif)) |
Jouni Malinen | 6a7c9ba | 2011-08-30 21:57:50 +0300 | [diff] [blame] | 2313 | return -EIO; |
| 2314 | |
| 2315 | ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: center_freq=%u hw_value=%u\n", |
| 2316 | __func__, chan->center_freq, chan->hw_value); |
Vasanthakumar Thiagarajan | cf5333d | 2011-10-25 19:34:10 +0530 | [diff] [blame] | 2317 | vif->next_chan = chan->center_freq; |
Jouni Malinen | 6a7c9ba | 2011-08-30 21:57:50 +0300 | [diff] [blame] | 2318 | |
| 2319 | return 0; |
| 2320 | } |
| 2321 | |
Jouni Malinen | 8bdfbf4 | 2011-08-30 21:58:09 +0300 | [diff] [blame] | 2322 | static bool ath6kl_is_p2p_ie(const u8 *pos) |
| 2323 | { |
| 2324 | return pos[0] == WLAN_EID_VENDOR_SPECIFIC && pos[1] >= 4 && |
| 2325 | pos[2] == 0x50 && pos[3] == 0x6f && |
| 2326 | pos[4] == 0x9a && pos[5] == 0x09; |
| 2327 | } |
| 2328 | |
Vasanthakumar Thiagarajan | 334234b | 2011-10-25 19:34:12 +0530 | [diff] [blame] | 2329 | static int ath6kl_set_ap_probe_resp_ies(struct ath6kl_vif *vif, |
| 2330 | const u8 *ies, size_t ies_len) |
Jouni Malinen | 8bdfbf4 | 2011-08-30 21:58:09 +0300 | [diff] [blame] | 2331 | { |
Vasanthakumar Thiagarajan | 334234b | 2011-10-25 19:34:12 +0530 | [diff] [blame] | 2332 | struct ath6kl *ar = vif->ar; |
Jouni Malinen | 8bdfbf4 | 2011-08-30 21:58:09 +0300 | [diff] [blame] | 2333 | const u8 *pos; |
| 2334 | u8 *buf = NULL; |
| 2335 | size_t len = 0; |
| 2336 | int ret; |
| 2337 | |
| 2338 | /* |
| 2339 | * Filter out P2P IE(s) since they will be included depending on |
| 2340 | * the Probe Request frame in ath6kl_send_go_probe_resp(). |
| 2341 | */ |
| 2342 | |
| 2343 | if (ies && ies_len) { |
| 2344 | buf = kmalloc(ies_len, GFP_KERNEL); |
| 2345 | if (buf == NULL) |
| 2346 | return -ENOMEM; |
| 2347 | pos = ies; |
| 2348 | while (pos + 1 < ies + ies_len) { |
| 2349 | if (pos + 2 + pos[1] > ies + ies_len) |
| 2350 | break; |
| 2351 | if (!ath6kl_is_p2p_ie(pos)) { |
| 2352 | memcpy(buf + len, pos, 2 + pos[1]); |
| 2353 | len += 2 + pos[1]; |
| 2354 | } |
| 2355 | pos += 2 + pos[1]; |
| 2356 | } |
| 2357 | } |
| 2358 | |
Vasanthakumar Thiagarajan | 334234b | 2011-10-25 19:34:12 +0530 | [diff] [blame] | 2359 | ret = ath6kl_wmi_set_appie_cmd(ar->wmi, vif->fw_vif_idx, |
| 2360 | WMI_FRAME_PROBE_RESP, buf, len); |
Jouni Malinen | 8bdfbf4 | 2011-08-30 21:58:09 +0300 | [diff] [blame] | 2361 | kfree(buf); |
| 2362 | return ret; |
| 2363 | } |
| 2364 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2365 | static int ath6kl_set_ies(struct ath6kl_vif *vif, |
| 2366 | struct cfg80211_beacon_data *info) |
| 2367 | { |
| 2368 | struct ath6kl *ar = vif->ar; |
| 2369 | int res; |
| 2370 | |
Aarthi Thiruvengadam | 17a7b16 | 2012-03-08 12:25:02 -0800 | [diff] [blame] | 2371 | /* this also clears IE in fw if it's not set */ |
| 2372 | res = ath6kl_wmi_set_appie_cmd(ar->wmi, vif->fw_vif_idx, |
| 2373 | WMI_FRAME_BEACON, |
| 2374 | info->beacon_ies, |
| 2375 | info->beacon_ies_len); |
| 2376 | if (res) |
| 2377 | return res; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2378 | |
Aarthi Thiruvengadam | 17a7b16 | 2012-03-08 12:25:02 -0800 | [diff] [blame] | 2379 | /* this also clears IE in fw if it's not set */ |
| 2380 | res = ath6kl_set_ap_probe_resp_ies(vif, info->proberesp_ies, |
| 2381 | info->proberesp_ies_len); |
| 2382 | if (res) |
| 2383 | return res; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2384 | |
Aarthi Thiruvengadam | 17a7b16 | 2012-03-08 12:25:02 -0800 | [diff] [blame] | 2385 | /* this also clears IE in fw if it's not set */ |
| 2386 | res = ath6kl_wmi_set_appie_cmd(ar->wmi, vif->fw_vif_idx, |
| 2387 | WMI_FRAME_ASSOC_RESP, |
| 2388 | info->assocresp_ies, |
| 2389 | info->assocresp_ies_len); |
| 2390 | if (res) |
| 2391 | return res; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2392 | |
| 2393 | return 0; |
| 2394 | } |
| 2395 | |
| 2396 | static int ath6kl_start_ap(struct wiphy *wiphy, struct net_device *dev, |
| 2397 | struct cfg80211_ap_settings *info) |
Jouni Malinen | 6a7c9ba | 2011-08-30 21:57:50 +0300 | [diff] [blame] | 2398 | { |
| 2399 | struct ath6kl *ar = ath6kl_priv(dev); |
Vasanthakumar Thiagarajan | 3450334 | 2011-10-25 19:34:02 +0530 | [diff] [blame] | 2400 | struct ath6kl_vif *vif = netdev_priv(dev); |
Jouni Malinen | 6a7c9ba | 2011-08-30 21:57:50 +0300 | [diff] [blame] | 2401 | struct ieee80211_mgmt *mgmt; |
Thomas Pedersen | 67cd22e | 2012-02-28 15:08:46 -0800 | [diff] [blame] | 2402 | bool hidden = false; |
Jouni Malinen | 6a7c9ba | 2011-08-30 21:57:50 +0300 | [diff] [blame] | 2403 | u8 *ies; |
| 2404 | int ies_len; |
| 2405 | struct wmi_connect_cmd p; |
| 2406 | int res; |
Vasanthakumar Thiagarajan | be5abaa | 2011-11-11 20:33:01 +0530 | [diff] [blame] | 2407 | int i, ret; |
Jouni Malinen | 6a7c9ba | 2011-08-30 21:57:50 +0300 | [diff] [blame] | 2408 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2409 | ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s:\n", __func__); |
Jouni Malinen | 6a7c9ba | 2011-08-30 21:57:50 +0300 | [diff] [blame] | 2410 | |
Vasanthakumar Thiagarajan | 990bd91 | 2011-10-25 19:34:20 +0530 | [diff] [blame] | 2411 | if (!ath6kl_cfg80211_ready(vif)) |
Jouni Malinen | 6a7c9ba | 2011-08-30 21:57:50 +0300 | [diff] [blame] | 2412 | return -EIO; |
| 2413 | |
Vasanthakumar Thiagarajan | f5938f2 | 2011-10-25 19:34:03 +0530 | [diff] [blame] | 2414 | if (vif->next_mode != AP_NETWORK) |
Jouni Malinen | 6a7c9ba | 2011-08-30 21:57:50 +0300 | [diff] [blame] | 2415 | return -EOPNOTSUPP; |
| 2416 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2417 | res = ath6kl_set_ies(vif, &info->beacon); |
Jouni Malinen | 6a7c9ba | 2011-08-30 21:57:50 +0300 | [diff] [blame] | 2418 | |
Jouni Malinen | 9a5b131 | 2011-08-30 21:57:52 +0300 | [diff] [blame] | 2419 | ar->ap_mode_bkey.valid = false; |
| 2420 | |
Jouni Malinen | 6a7c9ba | 2011-08-30 21:57:50 +0300 | [diff] [blame] | 2421 | /* TODO: |
| 2422 | * info->interval |
| 2423 | * info->dtim_period |
| 2424 | */ |
| 2425 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2426 | if (info->beacon.head == NULL) |
Jouni Malinen | 6a7c9ba | 2011-08-30 21:57:50 +0300 | [diff] [blame] | 2427 | return -EINVAL; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2428 | mgmt = (struct ieee80211_mgmt *) info->beacon.head; |
Jouni Malinen | 6a7c9ba | 2011-08-30 21:57:50 +0300 | [diff] [blame] | 2429 | ies = mgmt->u.beacon.variable; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2430 | if (ies > info->beacon.head + info->beacon.head_len) |
Jouni Malinen | 6a7c9ba | 2011-08-30 21:57:50 +0300 | [diff] [blame] | 2431 | return -EINVAL; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2432 | ies_len = info->beacon.head + info->beacon.head_len - ies; |
Jouni Malinen | 6a7c9ba | 2011-08-30 21:57:50 +0300 | [diff] [blame] | 2433 | |
| 2434 | if (info->ssid == NULL) |
| 2435 | return -EINVAL; |
Vasanthakumar Thiagarajan | 3450334 | 2011-10-25 19:34:02 +0530 | [diff] [blame] | 2436 | memcpy(vif->ssid, info->ssid, info->ssid_len); |
| 2437 | vif->ssid_len = info->ssid_len; |
Jouni Malinen | 6a7c9ba | 2011-08-30 21:57:50 +0300 | [diff] [blame] | 2438 | if (info->hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE) |
Thomas Pedersen | 67cd22e | 2012-02-28 15:08:46 -0800 | [diff] [blame] | 2439 | hidden = true; |
| 2440 | |
| 2441 | res = ath6kl_wmi_ap_hidden_ssid(ar->wmi, vif->fw_vif_idx, hidden); |
| 2442 | if (res) |
| 2443 | return res; |
Jouni Malinen | 6a7c9ba | 2011-08-30 21:57:50 +0300 | [diff] [blame] | 2444 | |
Vasanthakumar Thiagarajan | be5abaa | 2011-11-11 20:33:01 +0530 | [diff] [blame] | 2445 | ret = ath6kl_set_auth_type(vif, info->auth_type); |
| 2446 | if (ret) |
| 2447 | return ret; |
Jouni Malinen | 6a7c9ba | 2011-08-30 21:57:50 +0300 | [diff] [blame] | 2448 | |
| 2449 | memset(&p, 0, sizeof(p)); |
| 2450 | |
| 2451 | for (i = 0; i < info->crypto.n_akm_suites; i++) { |
| 2452 | switch (info->crypto.akm_suites[i]) { |
| 2453 | case WLAN_AKM_SUITE_8021X: |
| 2454 | if (info->crypto.wpa_versions & NL80211_WPA_VERSION_1) |
| 2455 | p.auth_mode |= WPA_AUTH; |
| 2456 | if (info->crypto.wpa_versions & NL80211_WPA_VERSION_2) |
| 2457 | p.auth_mode |= WPA2_AUTH; |
| 2458 | break; |
| 2459 | case WLAN_AKM_SUITE_PSK: |
| 2460 | if (info->crypto.wpa_versions & NL80211_WPA_VERSION_1) |
| 2461 | p.auth_mode |= WPA_PSK_AUTH; |
| 2462 | if (info->crypto.wpa_versions & NL80211_WPA_VERSION_2) |
| 2463 | p.auth_mode |= WPA2_PSK_AUTH; |
| 2464 | break; |
| 2465 | } |
| 2466 | } |
| 2467 | if (p.auth_mode == 0) |
| 2468 | p.auth_mode = NONE_AUTH; |
Vasanthakumar Thiagarajan | 3450334 | 2011-10-25 19:34:02 +0530 | [diff] [blame] | 2469 | vif->auth_mode = p.auth_mode; |
Jouni Malinen | 6a7c9ba | 2011-08-30 21:57:50 +0300 | [diff] [blame] | 2470 | |
| 2471 | for (i = 0; i < info->crypto.n_ciphers_pairwise; i++) { |
| 2472 | switch (info->crypto.ciphers_pairwise[i]) { |
| 2473 | case WLAN_CIPHER_SUITE_WEP40: |
| 2474 | case WLAN_CIPHER_SUITE_WEP104: |
| 2475 | p.prwise_crypto_type |= WEP_CRYPT; |
| 2476 | break; |
| 2477 | case WLAN_CIPHER_SUITE_TKIP: |
| 2478 | p.prwise_crypto_type |= TKIP_CRYPT; |
| 2479 | break; |
| 2480 | case WLAN_CIPHER_SUITE_CCMP: |
| 2481 | p.prwise_crypto_type |= AES_CRYPT; |
| 2482 | break; |
Dai Shuibing | b8214df | 2011-11-03 11:39:38 +0200 | [diff] [blame] | 2483 | case WLAN_CIPHER_SUITE_SMS4: |
| 2484 | p.prwise_crypto_type |= WAPI_CRYPT; |
| 2485 | break; |
Jouni Malinen | 6a7c9ba | 2011-08-30 21:57:50 +0300 | [diff] [blame] | 2486 | } |
| 2487 | } |
Edward Lu | 229ed6b | 2011-08-30 21:58:07 +0300 | [diff] [blame] | 2488 | if (p.prwise_crypto_type == 0) { |
Jouni Malinen | 6a7c9ba | 2011-08-30 21:57:50 +0300 | [diff] [blame] | 2489 | p.prwise_crypto_type = NONE_CRYPT; |
Vasanthakumar Thiagarajan | 240d279 | 2011-10-25 19:34:13 +0530 | [diff] [blame] | 2490 | ath6kl_set_cipher(vif, 0, true); |
Edward Lu | 229ed6b | 2011-08-30 21:58:07 +0300 | [diff] [blame] | 2491 | } else if (info->crypto.n_ciphers_pairwise == 1) |
Vasanthakumar Thiagarajan | 240d279 | 2011-10-25 19:34:13 +0530 | [diff] [blame] | 2492 | ath6kl_set_cipher(vif, info->crypto.ciphers_pairwise[0], true); |
Jouni Malinen | 6a7c9ba | 2011-08-30 21:57:50 +0300 | [diff] [blame] | 2493 | |
| 2494 | switch (info->crypto.cipher_group) { |
| 2495 | case WLAN_CIPHER_SUITE_WEP40: |
| 2496 | case WLAN_CIPHER_SUITE_WEP104: |
| 2497 | p.grp_crypto_type = WEP_CRYPT; |
| 2498 | break; |
| 2499 | case WLAN_CIPHER_SUITE_TKIP: |
| 2500 | p.grp_crypto_type = TKIP_CRYPT; |
| 2501 | break; |
| 2502 | case WLAN_CIPHER_SUITE_CCMP: |
| 2503 | p.grp_crypto_type = AES_CRYPT; |
| 2504 | break; |
Dai Shuibing | b8214df | 2011-11-03 11:39:38 +0200 | [diff] [blame] | 2505 | case WLAN_CIPHER_SUITE_SMS4: |
| 2506 | p.grp_crypto_type = WAPI_CRYPT; |
| 2507 | break; |
Jouni Malinen | 6a7c9ba | 2011-08-30 21:57:50 +0300 | [diff] [blame] | 2508 | default: |
| 2509 | p.grp_crypto_type = NONE_CRYPT; |
| 2510 | break; |
| 2511 | } |
Vasanthakumar Thiagarajan | 240d279 | 2011-10-25 19:34:13 +0530 | [diff] [blame] | 2512 | ath6kl_set_cipher(vif, info->crypto.cipher_group, false); |
Jouni Malinen | 6a7c9ba | 2011-08-30 21:57:50 +0300 | [diff] [blame] | 2513 | |
| 2514 | p.nw_type = AP_NETWORK; |
Vasanthakumar Thiagarajan | f5938f2 | 2011-10-25 19:34:03 +0530 | [diff] [blame] | 2515 | vif->nw_type = vif->next_mode; |
Jouni Malinen | 6a7c9ba | 2011-08-30 21:57:50 +0300 | [diff] [blame] | 2516 | |
Vasanthakumar Thiagarajan | 3450334 | 2011-10-25 19:34:02 +0530 | [diff] [blame] | 2517 | p.ssid_len = vif->ssid_len; |
| 2518 | memcpy(p.ssid, vif->ssid, vif->ssid_len); |
| 2519 | p.dot11_auth_mode = vif->dot11_auth_mode; |
Vasanthakumar Thiagarajan | cf5333d | 2011-10-25 19:34:10 +0530 | [diff] [blame] | 2520 | p.ch = cpu_to_le16(vif->next_chan); |
Jouni Malinen | 6a7c9ba | 2011-08-30 21:57:50 +0300 | [diff] [blame] | 2521 | |
Thirumalai Pachamuthu | c1762a3 | 2012-01-12 18:21:39 +0530 | [diff] [blame] | 2522 | /* Enable uAPSD support by default */ |
| 2523 | res = ath6kl_wmi_ap_set_apsd(ar->wmi, vif->fw_vif_idx, true); |
| 2524 | if (res < 0) |
| 2525 | return res; |
| 2526 | |
Aarthi Thiruvengadam | 3ca9d1f | 2011-12-13 13:32:12 -0800 | [diff] [blame] | 2527 | if (vif->wdev.iftype == NL80211_IFTYPE_P2P_GO) { |
| 2528 | p.nw_subtype = SUBTYPE_P2PGO; |
| 2529 | } else { |
| 2530 | /* |
| 2531 | * Due to firmware limitation, it is not possible to |
| 2532 | * do P2P mgmt operations in AP mode |
| 2533 | */ |
| 2534 | p.nw_subtype = SUBTYPE_NONE; |
| 2535 | } |
| 2536 | |
Vasanthakumar Thiagarajan | 334234b | 2011-10-25 19:34:12 +0530 | [diff] [blame] | 2537 | res = ath6kl_wmi_ap_profile_commit(ar->wmi, vif->fw_vif_idx, &p); |
Jouni Malinen | 9a5b131 | 2011-08-30 21:57:52 +0300 | [diff] [blame] | 2538 | if (res < 0) |
| 2539 | return res; |
| 2540 | |
| 2541 | return 0; |
Jouni Malinen | 6a7c9ba | 2011-08-30 21:57:50 +0300 | [diff] [blame] | 2542 | } |
| 2543 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2544 | static int ath6kl_change_beacon(struct wiphy *wiphy, struct net_device *dev, |
| 2545 | struct cfg80211_beacon_data *beacon) |
Jouni Malinen | 6a7c9ba | 2011-08-30 21:57:50 +0300 | [diff] [blame] | 2546 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2547 | struct ath6kl_vif *vif = netdev_priv(dev); |
| 2548 | |
| 2549 | if (!ath6kl_cfg80211_ready(vif)) |
| 2550 | return -EIO; |
| 2551 | |
| 2552 | if (vif->next_mode != AP_NETWORK) |
| 2553 | return -EOPNOTSUPP; |
| 2554 | |
| 2555 | return ath6kl_set_ies(vif, beacon); |
Jouni Malinen | 6a7c9ba | 2011-08-30 21:57:50 +0300 | [diff] [blame] | 2556 | } |
| 2557 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2558 | static int ath6kl_stop_ap(struct wiphy *wiphy, struct net_device *dev) |
Jouni Malinen | 6a7c9ba | 2011-08-30 21:57:50 +0300 | [diff] [blame] | 2559 | { |
| 2560 | struct ath6kl *ar = ath6kl_priv(dev); |
Vasanthakumar Thiagarajan | 59c9844 | 2011-10-25 19:34:01 +0530 | [diff] [blame] | 2561 | struct ath6kl_vif *vif = netdev_priv(dev); |
Jouni Malinen | 6a7c9ba | 2011-08-30 21:57:50 +0300 | [diff] [blame] | 2562 | |
Vasanthakumar Thiagarajan | f5938f2 | 2011-10-25 19:34:03 +0530 | [diff] [blame] | 2563 | if (vif->nw_type != AP_NETWORK) |
Jouni Malinen | 6a7c9ba | 2011-08-30 21:57:50 +0300 | [diff] [blame] | 2564 | return -EOPNOTSUPP; |
Vasanthakumar Thiagarajan | 59c9844 | 2011-10-25 19:34:01 +0530 | [diff] [blame] | 2565 | if (!test_bit(CONNECTED, &vif->flags)) |
Jouni Malinen | 6a7c9ba | 2011-08-30 21:57:50 +0300 | [diff] [blame] | 2566 | return -ENOTCONN; |
| 2567 | |
Vasanthakumar Thiagarajan | 334234b | 2011-10-25 19:34:12 +0530 | [diff] [blame] | 2568 | ath6kl_wmi_disconnect_cmd(ar->wmi, vif->fw_vif_idx); |
Vasanthakumar Thiagarajan | 59c9844 | 2011-10-25 19:34:01 +0530 | [diff] [blame] | 2569 | clear_bit(CONNECTED, &vif->flags); |
Jouni Malinen | 6a7c9ba | 2011-08-30 21:57:50 +0300 | [diff] [blame] | 2570 | |
| 2571 | return 0; |
| 2572 | } |
| 2573 | |
Jouni Malinen | 33e5308 | 2011-12-27 11:02:56 +0200 | [diff] [blame] | 2574 | static const u8 bcast_addr[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; |
| 2575 | |
| 2576 | static int ath6kl_del_station(struct wiphy *wiphy, struct net_device *dev, |
| 2577 | u8 *mac) |
| 2578 | { |
| 2579 | struct ath6kl *ar = ath6kl_priv(dev); |
| 2580 | struct ath6kl_vif *vif = netdev_priv(dev); |
| 2581 | const u8 *addr = mac ? mac : bcast_addr; |
| 2582 | |
| 2583 | return ath6kl_wmi_ap_set_mlme(ar->wmi, vif->fw_vif_idx, WMI_AP_DEAUTH, |
| 2584 | addr, WLAN_REASON_PREV_AUTH_NOT_VALID); |
| 2585 | } |
| 2586 | |
Jouni Malinen | 2387513 | 2011-08-30 21:57:53 +0300 | [diff] [blame] | 2587 | static int ath6kl_change_station(struct wiphy *wiphy, struct net_device *dev, |
| 2588 | u8 *mac, struct station_parameters *params) |
| 2589 | { |
| 2590 | struct ath6kl *ar = ath6kl_priv(dev); |
Vasanthakumar Thiagarajan | f5938f2 | 2011-10-25 19:34:03 +0530 | [diff] [blame] | 2591 | struct ath6kl_vif *vif = netdev_priv(dev); |
Jouni Malinen | 2387513 | 2011-08-30 21:57:53 +0300 | [diff] [blame] | 2592 | |
Vasanthakumar Thiagarajan | f5938f2 | 2011-10-25 19:34:03 +0530 | [diff] [blame] | 2593 | if (vif->nw_type != AP_NETWORK) |
Jouni Malinen | 2387513 | 2011-08-30 21:57:53 +0300 | [diff] [blame] | 2594 | return -EOPNOTSUPP; |
| 2595 | |
| 2596 | /* Use this only for authorizing/unauthorizing a station */ |
| 2597 | if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED))) |
| 2598 | return -EOPNOTSUPP; |
| 2599 | |
| 2600 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED)) |
Vasanthakumar Thiagarajan | 334234b | 2011-10-25 19:34:12 +0530 | [diff] [blame] | 2601 | return ath6kl_wmi_ap_set_mlme(ar->wmi, vif->fw_vif_idx, |
| 2602 | WMI_AP_MLME_AUTHORIZE, mac, 0); |
| 2603 | return ath6kl_wmi_ap_set_mlme(ar->wmi, vif->fw_vif_idx, |
| 2604 | WMI_AP_MLME_UNAUTHORIZE, mac, 0); |
Jouni Malinen | 2387513 | 2011-08-30 21:57:53 +0300 | [diff] [blame] | 2605 | } |
| 2606 | |
Jouni Malinen | 63fa1e0 | 2011-08-30 21:57:55 +0300 | [diff] [blame] | 2607 | static int ath6kl_remain_on_channel(struct wiphy *wiphy, |
| 2608 | struct net_device *dev, |
| 2609 | struct ieee80211_channel *chan, |
| 2610 | enum nl80211_channel_type channel_type, |
| 2611 | unsigned int duration, |
| 2612 | u64 *cookie) |
| 2613 | { |
| 2614 | struct ath6kl *ar = ath6kl_priv(dev); |
Vasanthakumar Thiagarajan | 334234b | 2011-10-25 19:34:12 +0530 | [diff] [blame] | 2615 | struct ath6kl_vif *vif = netdev_priv(dev); |
Jouni Malinen | 1052261 | 2011-10-27 16:00:13 +0300 | [diff] [blame] | 2616 | u32 id; |
Jouni Malinen | 63fa1e0 | 2011-08-30 21:57:55 +0300 | [diff] [blame] | 2617 | |
| 2618 | /* TODO: if already pending or ongoing remain-on-channel, |
| 2619 | * return -EBUSY */ |
Jouni Malinen | 1052261 | 2011-10-27 16:00:13 +0300 | [diff] [blame] | 2620 | id = ++vif->last_roc_id; |
| 2621 | if (id == 0) { |
| 2622 | /* Do not use 0 as the cookie value */ |
| 2623 | id = ++vif->last_roc_id; |
| 2624 | } |
| 2625 | *cookie = id; |
Jouni Malinen | 63fa1e0 | 2011-08-30 21:57:55 +0300 | [diff] [blame] | 2626 | |
Vasanthakumar Thiagarajan | 334234b | 2011-10-25 19:34:12 +0530 | [diff] [blame] | 2627 | return ath6kl_wmi_remain_on_chnl_cmd(ar->wmi, vif->fw_vif_idx, |
| 2628 | chan->center_freq, duration); |
Jouni Malinen | 63fa1e0 | 2011-08-30 21:57:55 +0300 | [diff] [blame] | 2629 | } |
| 2630 | |
| 2631 | static int ath6kl_cancel_remain_on_channel(struct wiphy *wiphy, |
| 2632 | struct net_device *dev, |
| 2633 | u64 cookie) |
| 2634 | { |
| 2635 | struct ath6kl *ar = ath6kl_priv(dev); |
Vasanthakumar Thiagarajan | 334234b | 2011-10-25 19:34:12 +0530 | [diff] [blame] | 2636 | struct ath6kl_vif *vif = netdev_priv(dev); |
Jouni Malinen | 63fa1e0 | 2011-08-30 21:57:55 +0300 | [diff] [blame] | 2637 | |
Jouni Malinen | 1052261 | 2011-10-27 16:00:13 +0300 | [diff] [blame] | 2638 | if (cookie != vif->last_roc_id) |
Jouni Malinen | 63fa1e0 | 2011-08-30 21:57:55 +0300 | [diff] [blame] | 2639 | return -ENOENT; |
Jouni Malinen | 1052261 | 2011-10-27 16:00:13 +0300 | [diff] [blame] | 2640 | vif->last_cancel_roc_id = cookie; |
Jouni Malinen | 63fa1e0 | 2011-08-30 21:57:55 +0300 | [diff] [blame] | 2641 | |
Vasanthakumar Thiagarajan | 334234b | 2011-10-25 19:34:12 +0530 | [diff] [blame] | 2642 | return ath6kl_wmi_cancel_remain_on_chnl_cmd(ar->wmi, vif->fw_vif_idx); |
Jouni Malinen | 63fa1e0 | 2011-08-30 21:57:55 +0300 | [diff] [blame] | 2643 | } |
| 2644 | |
Vasanthakumar Thiagarajan | 334234b | 2011-10-25 19:34:12 +0530 | [diff] [blame] | 2645 | static int ath6kl_send_go_probe_resp(struct ath6kl_vif *vif, |
| 2646 | const u8 *buf, size_t len, |
| 2647 | unsigned int freq) |
Jouni Malinen | 8bdfbf4 | 2011-08-30 21:58:09 +0300 | [diff] [blame] | 2648 | { |
Vasanthakumar Thiagarajan | 334234b | 2011-10-25 19:34:12 +0530 | [diff] [blame] | 2649 | struct ath6kl *ar = vif->ar; |
Jouni Malinen | 8bdfbf4 | 2011-08-30 21:58:09 +0300 | [diff] [blame] | 2650 | const u8 *pos; |
| 2651 | u8 *p2p; |
| 2652 | int p2p_len; |
| 2653 | int ret; |
| 2654 | const struct ieee80211_mgmt *mgmt; |
| 2655 | |
| 2656 | mgmt = (const struct ieee80211_mgmt *) buf; |
| 2657 | |
| 2658 | /* Include P2P IE(s) from the frame generated in user space. */ |
| 2659 | |
| 2660 | p2p = kmalloc(len, GFP_KERNEL); |
| 2661 | if (p2p == NULL) |
| 2662 | return -ENOMEM; |
| 2663 | p2p_len = 0; |
| 2664 | |
| 2665 | pos = mgmt->u.probe_resp.variable; |
| 2666 | while (pos + 1 < buf + len) { |
| 2667 | if (pos + 2 + pos[1] > buf + len) |
| 2668 | break; |
| 2669 | if (ath6kl_is_p2p_ie(pos)) { |
| 2670 | memcpy(p2p + p2p_len, pos, 2 + pos[1]); |
| 2671 | p2p_len += 2 + pos[1]; |
| 2672 | } |
| 2673 | pos += 2 + pos[1]; |
| 2674 | } |
| 2675 | |
Vasanthakumar Thiagarajan | 334234b | 2011-10-25 19:34:12 +0530 | [diff] [blame] | 2676 | ret = ath6kl_wmi_send_probe_response_cmd(ar->wmi, vif->fw_vif_idx, freq, |
| 2677 | mgmt->da, p2p, p2p_len); |
Jouni Malinen | 8bdfbf4 | 2011-08-30 21:58:09 +0300 | [diff] [blame] | 2678 | kfree(p2p); |
| 2679 | return ret; |
| 2680 | } |
| 2681 | |
Naveen Gangadharan | d0ff738 | 2012-02-08 17:51:36 -0800 | [diff] [blame] | 2682 | static bool ath6kl_mgmt_powersave_ap(struct ath6kl_vif *vif, |
| 2683 | u32 id, |
| 2684 | u32 freq, |
| 2685 | u32 wait, |
| 2686 | const u8 *buf, |
| 2687 | size_t len, |
| 2688 | bool *more_data, |
| 2689 | bool no_cck) |
| 2690 | { |
| 2691 | struct ieee80211_mgmt *mgmt; |
| 2692 | struct ath6kl_sta *conn; |
| 2693 | bool is_psq_empty = false; |
| 2694 | struct ath6kl_mgmt_buff *mgmt_buf; |
| 2695 | size_t mgmt_buf_size; |
| 2696 | struct ath6kl *ar = vif->ar; |
| 2697 | |
| 2698 | mgmt = (struct ieee80211_mgmt *) buf; |
| 2699 | if (is_multicast_ether_addr(mgmt->da)) |
| 2700 | return false; |
| 2701 | |
| 2702 | conn = ath6kl_find_sta(vif, mgmt->da); |
| 2703 | if (!conn) |
| 2704 | return false; |
| 2705 | |
| 2706 | if (conn->sta_flags & STA_PS_SLEEP) { |
| 2707 | if (!(conn->sta_flags & STA_PS_POLLED)) { |
| 2708 | /* Queue the frames if the STA is sleeping */ |
| 2709 | mgmt_buf_size = len + sizeof(struct ath6kl_mgmt_buff); |
| 2710 | mgmt_buf = kmalloc(mgmt_buf_size, GFP_KERNEL); |
| 2711 | if (!mgmt_buf) |
| 2712 | return false; |
| 2713 | |
| 2714 | INIT_LIST_HEAD(&mgmt_buf->list); |
| 2715 | mgmt_buf->id = id; |
| 2716 | mgmt_buf->freq = freq; |
| 2717 | mgmt_buf->wait = wait; |
| 2718 | mgmt_buf->len = len; |
| 2719 | mgmt_buf->no_cck = no_cck; |
| 2720 | memcpy(mgmt_buf->buf, buf, len); |
| 2721 | spin_lock_bh(&conn->psq_lock); |
| 2722 | is_psq_empty = skb_queue_empty(&conn->psq) && |
| 2723 | (conn->mgmt_psq_len == 0); |
| 2724 | list_add_tail(&mgmt_buf->list, &conn->mgmt_psq); |
| 2725 | conn->mgmt_psq_len++; |
| 2726 | spin_unlock_bh(&conn->psq_lock); |
| 2727 | |
| 2728 | /* |
| 2729 | * If this is the first pkt getting queued |
| 2730 | * for this STA, update the PVB for this |
| 2731 | * STA. |
| 2732 | */ |
| 2733 | if (is_psq_empty) |
| 2734 | ath6kl_wmi_set_pvb_cmd(ar->wmi, vif->fw_vif_idx, |
| 2735 | conn->aid, 1); |
| 2736 | return true; |
| 2737 | } |
| 2738 | |
| 2739 | /* |
| 2740 | * This tx is because of a PsPoll. |
| 2741 | * Determine if MoreData bit has to be set. |
| 2742 | */ |
| 2743 | spin_lock_bh(&conn->psq_lock); |
| 2744 | if (!skb_queue_empty(&conn->psq) || (conn->mgmt_psq_len != 0)) |
| 2745 | *more_data = true; |
| 2746 | spin_unlock_bh(&conn->psq_lock); |
| 2747 | } |
| 2748 | |
| 2749 | return false; |
| 2750 | } |
| 2751 | |
Jouni Malinen | 8a6c8060 | 2011-08-30 21:57:56 +0300 | [diff] [blame] | 2752 | static int ath6kl_mgmt_tx(struct wiphy *wiphy, struct net_device *dev, |
| 2753 | struct ieee80211_channel *chan, bool offchan, |
| 2754 | enum nl80211_channel_type channel_type, |
| 2755 | bool channel_type_valid, unsigned int wait, |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 2756 | const u8 *buf, size_t len, bool no_cck, |
| 2757 | bool dont_wait_for_ack, u64 *cookie) |
Jouni Malinen | 8a6c8060 | 2011-08-30 21:57:56 +0300 | [diff] [blame] | 2758 | { |
| 2759 | struct ath6kl *ar = ath6kl_priv(dev); |
Vasanthakumar Thiagarajan | 59c9844 | 2011-10-25 19:34:01 +0530 | [diff] [blame] | 2760 | struct ath6kl_vif *vif = netdev_priv(dev); |
Jouni Malinen | 8a6c8060 | 2011-08-30 21:57:56 +0300 | [diff] [blame] | 2761 | u32 id; |
Jouni Malinen | 8bdfbf4 | 2011-08-30 21:58:09 +0300 | [diff] [blame] | 2762 | const struct ieee80211_mgmt *mgmt; |
Naveen Gangadharan | d0ff738 | 2012-02-08 17:51:36 -0800 | [diff] [blame] | 2763 | bool more_data, queued; |
Jouni Malinen | 8bdfbf4 | 2011-08-30 21:58:09 +0300 | [diff] [blame] | 2764 | |
| 2765 | mgmt = (const struct ieee80211_mgmt *) buf; |
| 2766 | if (buf + len >= mgmt->u.probe_resp.variable && |
Vasanthakumar Thiagarajan | f5938f2 | 2011-10-25 19:34:03 +0530 | [diff] [blame] | 2767 | vif->nw_type == AP_NETWORK && test_bit(CONNECTED, &vif->flags) && |
Jouni Malinen | 8bdfbf4 | 2011-08-30 21:58:09 +0300 | [diff] [blame] | 2768 | ieee80211_is_probe_resp(mgmt->frame_control)) { |
| 2769 | /* |
| 2770 | * Send Probe Response frame in AP mode using a separate WMI |
| 2771 | * command to allow the target to fill in the generic IEs. |
| 2772 | */ |
| 2773 | *cookie = 0; /* TX status not supported */ |
Vasanthakumar Thiagarajan | 334234b | 2011-10-25 19:34:12 +0530 | [diff] [blame] | 2774 | return ath6kl_send_go_probe_resp(vif, buf, len, |
Jouni Malinen | 8bdfbf4 | 2011-08-30 21:58:09 +0300 | [diff] [blame] | 2775 | chan->center_freq); |
| 2776 | } |
Jouni Malinen | 8a6c8060 | 2011-08-30 21:57:56 +0300 | [diff] [blame] | 2777 | |
Vasanthakumar Thiagarajan | cf5333d | 2011-10-25 19:34:10 +0530 | [diff] [blame] | 2778 | id = vif->send_action_id++; |
Jouni Malinen | 8a6c8060 | 2011-08-30 21:57:56 +0300 | [diff] [blame] | 2779 | if (id == 0) { |
| 2780 | /* |
| 2781 | * 0 is a reserved value in the WMI command and shall not be |
| 2782 | * used for the command. |
| 2783 | */ |
Vasanthakumar Thiagarajan | cf5333d | 2011-10-25 19:34:10 +0530 | [diff] [blame] | 2784 | id = vif->send_action_id++; |
Jouni Malinen | 8a6c8060 | 2011-08-30 21:57:56 +0300 | [diff] [blame] | 2785 | } |
| 2786 | |
| 2787 | *cookie = id; |
Aarthi Thiruvengadam | 3ca9d1f | 2011-12-13 13:32:12 -0800 | [diff] [blame] | 2788 | |
Naveen Gangadharan | d0ff738 | 2012-02-08 17:51:36 -0800 | [diff] [blame] | 2789 | /* AP mode Power saving processing */ |
| 2790 | if (vif->nw_type == AP_NETWORK) { |
| 2791 | queued = ath6kl_mgmt_powersave_ap(vif, |
| 2792 | id, chan->center_freq, |
| 2793 | wait, buf, |
| 2794 | len, &more_data, no_cck); |
| 2795 | if (queued) |
| 2796 | return 0; |
Aarthi Thiruvengadam | 3ca9d1f | 2011-12-13 13:32:12 -0800 | [diff] [blame] | 2797 | } |
Naveen Gangadharan | d0ff738 | 2012-02-08 17:51:36 -0800 | [diff] [blame] | 2798 | |
| 2799 | return ath6kl_wmi_send_mgmt_cmd(ar->wmi, vif->fw_vif_idx, id, |
| 2800 | chan->center_freq, wait, |
| 2801 | buf, len, no_cck); |
Jouni Malinen | 8a6c8060 | 2011-08-30 21:57:56 +0300 | [diff] [blame] | 2802 | } |
| 2803 | |
Jouni Malinen | ae32c30 | 2011-08-30 21:58:01 +0300 | [diff] [blame] | 2804 | static void ath6kl_mgmt_frame_register(struct wiphy *wiphy, |
| 2805 | struct net_device *dev, |
| 2806 | u16 frame_type, bool reg) |
| 2807 | { |
Vasanthakumar Thiagarajan | cf5333d | 2011-10-25 19:34:10 +0530 | [diff] [blame] | 2808 | struct ath6kl_vif *vif = netdev_priv(dev); |
Jouni Malinen | ae32c30 | 2011-08-30 21:58:01 +0300 | [diff] [blame] | 2809 | |
| 2810 | ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: frame_type=0x%x reg=%d\n", |
| 2811 | __func__, frame_type, reg); |
| 2812 | if (frame_type == IEEE80211_STYPE_PROBE_REQ) { |
| 2813 | /* |
| 2814 | * Note: This notification callback is not allowed to sleep, so |
| 2815 | * we cannot send WMI_PROBE_REQ_REPORT_CMD here. Instead, we |
| 2816 | * hardcode target to report Probe Request frames all the time. |
| 2817 | */ |
Vasanthakumar Thiagarajan | cf5333d | 2011-10-25 19:34:10 +0530 | [diff] [blame] | 2818 | vif->probe_req_report = reg; |
Jouni Malinen | ae32c30 | 2011-08-30 21:58:01 +0300 | [diff] [blame] | 2819 | } |
| 2820 | } |
| 2821 | |
Kalle Valo | 10509f9 | 2011-12-13 14:52:07 +0200 | [diff] [blame] | 2822 | static int ath6kl_cfg80211_sscan_start(struct wiphy *wiphy, |
| 2823 | struct net_device *dev, |
| 2824 | struct cfg80211_sched_scan_request *request) |
| 2825 | { |
| 2826 | struct ath6kl *ar = ath6kl_priv(dev); |
| 2827 | struct ath6kl_vif *vif = netdev_priv(dev); |
| 2828 | u16 interval; |
| 2829 | int ret; |
| 2830 | u8 i; |
| 2831 | |
| 2832 | if (ar->state != ATH6KL_STATE_ON) |
| 2833 | return -EIO; |
| 2834 | |
| 2835 | if (vif->sme_state != SME_DISCONNECTED) |
| 2836 | return -EBUSY; |
| 2837 | |
| 2838 | for (i = 0; i < ar->wiphy->max_sched_scan_ssids; i++) { |
| 2839 | ath6kl_wmi_probedssid_cmd(ar->wmi, vif->fw_vif_idx, |
| 2840 | i, DISABLE_SSID_FLAG, |
| 2841 | 0, NULL); |
| 2842 | } |
| 2843 | |
| 2844 | /* fw uses seconds, also make sure that it's >0 */ |
| 2845 | interval = max_t(u16, 1, request->interval / 1000); |
| 2846 | |
| 2847 | ath6kl_wmi_scanparams_cmd(ar->wmi, vif->fw_vif_idx, |
| 2848 | interval, interval, |
| 2849 | 10, 0, 0, 0, 3, 0, 0, 0); |
| 2850 | |
| 2851 | if (request->n_ssids && request->ssids[0].ssid_len) { |
| 2852 | for (i = 0; i < request->n_ssids; i++) { |
| 2853 | ath6kl_wmi_probedssid_cmd(ar->wmi, vif->fw_vif_idx, |
| 2854 | i, SPECIFIC_SSID_FLAG, |
| 2855 | request->ssids[i].ssid_len, |
| 2856 | request->ssids[i].ssid); |
| 2857 | } |
| 2858 | } |
| 2859 | |
| 2860 | ret = ath6kl_wmi_set_wow_mode_cmd(ar->wmi, vif->fw_vif_idx, |
| 2861 | ATH6KL_WOW_MODE_ENABLE, |
| 2862 | WOW_FILTER_SSID, |
| 2863 | WOW_HOST_REQ_DELAY); |
| 2864 | if (ret) { |
| 2865 | ath6kl_warn("Failed to enable wow with ssid filter: %d\n", ret); |
| 2866 | return ret; |
| 2867 | } |
| 2868 | |
| 2869 | /* this also clears IE in fw if it's not set */ |
| 2870 | ret = ath6kl_wmi_set_appie_cmd(ar->wmi, vif->fw_vif_idx, |
| 2871 | WMI_FRAME_PROBE_REQ, |
| 2872 | request->ie, request->ie_len); |
| 2873 | if (ret) { |
| 2874 | ath6kl_warn("Failed to set probe request IE for scheduled scan: %d", |
| 2875 | ret); |
| 2876 | return ret; |
| 2877 | } |
| 2878 | |
| 2879 | ret = ath6kl_wmi_set_host_sleep_mode_cmd(ar->wmi, vif->fw_vif_idx, |
| 2880 | ATH6KL_HOST_MODE_ASLEEP); |
| 2881 | if (ret) { |
| 2882 | ath6kl_warn("Failed to enable host sleep mode for sched scan: %d\n", |
| 2883 | ret); |
| 2884 | return ret; |
| 2885 | } |
| 2886 | |
| 2887 | ar->state = ATH6KL_STATE_SCHED_SCAN; |
| 2888 | |
| 2889 | return ret; |
| 2890 | } |
| 2891 | |
| 2892 | static int ath6kl_cfg80211_sscan_stop(struct wiphy *wiphy, |
| 2893 | struct net_device *dev) |
| 2894 | { |
| 2895 | struct ath6kl_vif *vif = netdev_priv(dev); |
| 2896 | bool stopped; |
| 2897 | |
| 2898 | stopped = __ath6kl_cfg80211_sscan_stop(vif); |
| 2899 | |
| 2900 | if (!stopped) |
| 2901 | return -EIO; |
| 2902 | |
| 2903 | return 0; |
| 2904 | } |
| 2905 | |
Jouni Malinen | f80574a | 2011-08-30 21:58:04 +0300 | [diff] [blame] | 2906 | static const struct ieee80211_txrx_stypes |
| 2907 | ath6kl_mgmt_stypes[NUM_NL80211_IFTYPES] = { |
| 2908 | [NL80211_IFTYPE_STATION] = { |
| 2909 | .tx = BIT(IEEE80211_STYPE_ACTION >> 4) | |
| 2910 | BIT(IEEE80211_STYPE_PROBE_RESP >> 4), |
| 2911 | .rx = BIT(IEEE80211_STYPE_ACTION >> 4) | |
| 2912 | BIT(IEEE80211_STYPE_PROBE_REQ >> 4) |
| 2913 | }, |
Jouni Malinen | ba1f6fe | 2011-12-27 11:03:53 +0200 | [diff] [blame] | 2914 | [NL80211_IFTYPE_AP] = { |
| 2915 | .tx = BIT(IEEE80211_STYPE_ACTION >> 4) | |
| 2916 | BIT(IEEE80211_STYPE_PROBE_RESP >> 4), |
| 2917 | .rx = BIT(IEEE80211_STYPE_ACTION >> 4) | |
| 2918 | BIT(IEEE80211_STYPE_PROBE_REQ >> 4) |
| 2919 | }, |
Jouni Malinen | f80574a | 2011-08-30 21:58:04 +0300 | [diff] [blame] | 2920 | [NL80211_IFTYPE_P2P_CLIENT] = { |
| 2921 | .tx = BIT(IEEE80211_STYPE_ACTION >> 4) | |
| 2922 | BIT(IEEE80211_STYPE_PROBE_RESP >> 4), |
| 2923 | .rx = BIT(IEEE80211_STYPE_ACTION >> 4) | |
| 2924 | BIT(IEEE80211_STYPE_PROBE_REQ >> 4) |
| 2925 | }, |
| 2926 | [NL80211_IFTYPE_P2P_GO] = { |
| 2927 | .tx = BIT(IEEE80211_STYPE_ACTION >> 4) | |
| 2928 | BIT(IEEE80211_STYPE_PROBE_RESP >> 4), |
| 2929 | .rx = BIT(IEEE80211_STYPE_ACTION >> 4) | |
| 2930 | BIT(IEEE80211_STYPE_PROBE_REQ >> 4) |
| 2931 | }, |
| 2932 | }; |
| 2933 | |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 2934 | static struct cfg80211_ops ath6kl_cfg80211_ops = { |
Vasanthakumar Thiagarajan | 5505597 | 2011-10-25 19:34:23 +0530 | [diff] [blame] | 2935 | .add_virtual_intf = ath6kl_cfg80211_add_iface, |
| 2936 | .del_virtual_intf = ath6kl_cfg80211_del_iface, |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 2937 | .change_virtual_intf = ath6kl_cfg80211_change_iface, |
| 2938 | .scan = ath6kl_cfg80211_scan, |
| 2939 | .connect = ath6kl_cfg80211_connect, |
| 2940 | .disconnect = ath6kl_cfg80211_disconnect, |
| 2941 | .add_key = ath6kl_cfg80211_add_key, |
| 2942 | .get_key = ath6kl_cfg80211_get_key, |
| 2943 | .del_key = ath6kl_cfg80211_del_key, |
| 2944 | .set_default_key = ath6kl_cfg80211_set_default_key, |
| 2945 | .set_wiphy_params = ath6kl_cfg80211_set_wiphy_params, |
| 2946 | .set_tx_power = ath6kl_cfg80211_set_txpower, |
| 2947 | .get_tx_power = ath6kl_cfg80211_get_txpower, |
| 2948 | .set_power_mgmt = ath6kl_cfg80211_set_power_mgmt, |
| 2949 | .join_ibss = ath6kl_cfg80211_join_ibss, |
| 2950 | .leave_ibss = ath6kl_cfg80211_leave_ibss, |
| 2951 | .get_station = ath6kl_get_station, |
| 2952 | .set_pmksa = ath6kl_set_pmksa, |
| 2953 | .del_pmksa = ath6kl_del_pmksa, |
| 2954 | .flush_pmksa = ath6kl_flush_pmksa, |
Kalle Valo | 003353b0d | 2011-09-01 10:14:21 +0300 | [diff] [blame] | 2955 | CFG80211_TESTMODE_CMD(ath6kl_tm_cmd) |
Kalle Valo | abcb344 | 2011-07-22 08:26:20 +0300 | [diff] [blame] | 2956 | #ifdef CONFIG_PM |
Kalle Valo | 52d81a6 | 2011-11-01 08:44:21 +0200 | [diff] [blame] | 2957 | .suspend = __ath6kl_cfg80211_suspend, |
| 2958 | .resume = __ath6kl_cfg80211_resume, |
Kalle Valo | abcb344 | 2011-07-22 08:26:20 +0300 | [diff] [blame] | 2959 | #endif |
Jouni Malinen | 6a7c9ba | 2011-08-30 21:57:50 +0300 | [diff] [blame] | 2960 | .set_channel = ath6kl_set_channel, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2961 | .start_ap = ath6kl_start_ap, |
| 2962 | .change_beacon = ath6kl_change_beacon, |
| 2963 | .stop_ap = ath6kl_stop_ap, |
Jouni Malinen | 33e5308 | 2011-12-27 11:02:56 +0200 | [diff] [blame] | 2964 | .del_station = ath6kl_del_station, |
Jouni Malinen | 2387513 | 2011-08-30 21:57:53 +0300 | [diff] [blame] | 2965 | .change_station = ath6kl_change_station, |
Jouni Malinen | 63fa1e0 | 2011-08-30 21:57:55 +0300 | [diff] [blame] | 2966 | .remain_on_channel = ath6kl_remain_on_channel, |
| 2967 | .cancel_remain_on_channel = ath6kl_cancel_remain_on_channel, |
Jouni Malinen | 8a6c8060 | 2011-08-30 21:57:56 +0300 | [diff] [blame] | 2968 | .mgmt_tx = ath6kl_mgmt_tx, |
Jouni Malinen | ae32c30 | 2011-08-30 21:58:01 +0300 | [diff] [blame] | 2969 | .mgmt_frame_register = ath6kl_mgmt_frame_register, |
Kalle Valo | 10509f9 | 2011-12-13 14:52:07 +0200 | [diff] [blame] | 2970 | .sched_scan_start = ath6kl_cfg80211_sscan_start, |
| 2971 | .sched_scan_stop = ath6kl_cfg80211_sscan_stop, |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 2972 | }; |
| 2973 | |
Kalle Valo | 7125f01 | 2011-12-13 14:51:37 +0200 | [diff] [blame] | 2974 | void ath6kl_cfg80211_stop(struct ath6kl_vif *vif) |
Kalle Valo | ec4b7f6 | 2011-11-01 08:44:04 +0200 | [diff] [blame] | 2975 | { |
Kalle Valo | 10509f9 | 2011-12-13 14:52:07 +0200 | [diff] [blame] | 2976 | ath6kl_cfg80211_sscan_disable(vif); |
| 2977 | |
Kalle Valo | ec4b7f6 | 2011-11-01 08:44:04 +0200 | [diff] [blame] | 2978 | switch (vif->sme_state) { |
Kalle Valo | c97a31b | 2011-12-13 14:51:10 +0200 | [diff] [blame] | 2979 | case SME_DISCONNECTED: |
| 2980 | break; |
Kalle Valo | ec4b7f6 | 2011-11-01 08:44:04 +0200 | [diff] [blame] | 2981 | case SME_CONNECTING: |
| 2982 | cfg80211_connect_result(vif->ndev, vif->bssid, NULL, 0, |
| 2983 | NULL, 0, |
| 2984 | WLAN_STATUS_UNSPECIFIED_FAILURE, |
| 2985 | GFP_KERNEL); |
| 2986 | break; |
| 2987 | case SME_CONNECTED: |
Kalle Valo | ec4b7f6 | 2011-11-01 08:44:04 +0200 | [diff] [blame] | 2988 | cfg80211_disconnected(vif->ndev, 0, NULL, 0, GFP_KERNEL); |
| 2989 | break; |
| 2990 | } |
| 2991 | |
| 2992 | if (test_bit(CONNECTED, &vif->flags) || |
| 2993 | test_bit(CONNECT_PEND, &vif->flags)) |
Kalle Valo | 7125f01 | 2011-12-13 14:51:37 +0200 | [diff] [blame] | 2994 | ath6kl_wmi_disconnect_cmd(vif->ar->wmi, vif->fw_vif_idx); |
Kalle Valo | ec4b7f6 | 2011-11-01 08:44:04 +0200 | [diff] [blame] | 2995 | |
| 2996 | vif->sme_state = SME_DISCONNECTED; |
Kalle Valo | 1f4052551 | 2011-11-01 08:44:13 +0200 | [diff] [blame] | 2997 | clear_bit(CONNECTED, &vif->flags); |
| 2998 | clear_bit(CONNECT_PEND, &vif->flags); |
Kalle Valo | ec4b7f6 | 2011-11-01 08:44:04 +0200 | [diff] [blame] | 2999 | |
| 3000 | /* disable scanning */ |
Kalle Valo | 7125f01 | 2011-12-13 14:51:37 +0200 | [diff] [blame] | 3001 | if (ath6kl_wmi_scanparams_cmd(vif->ar->wmi, vif->fw_vif_idx, 0xFFFF, |
| 3002 | 0, 0, 0, 0, 0, 0, 0, 0, 0) != 0) |
| 3003 | ath6kl_warn("failed to disable scan during stop\n"); |
Kalle Valo | ec4b7f6 | 2011-11-01 08:44:04 +0200 | [diff] [blame] | 3004 | |
| 3005 | ath6kl_cfg80211_scan_complete_event(vif, true); |
| 3006 | } |
| 3007 | |
Kalle Valo | 7125f01 | 2011-12-13 14:51:37 +0200 | [diff] [blame] | 3008 | void ath6kl_cfg80211_stop_all(struct ath6kl *ar) |
| 3009 | { |
| 3010 | struct ath6kl_vif *vif; |
| 3011 | |
| 3012 | vif = ath6kl_vif_first(ar); |
| 3013 | if (!vif) { |
| 3014 | /* save the current power mode before enabling power save */ |
| 3015 | ar->wmi->saved_pwr_mode = ar->wmi->pwr_mode; |
| 3016 | |
| 3017 | if (ath6kl_wmi_powermode_cmd(ar->wmi, 0, REC_POWER) != 0) |
| 3018 | ath6kl_warn("ath6kl_deep_sleep_enable: " |
| 3019 | "wmi_powermode_cmd failed\n"); |
| 3020 | return; |
| 3021 | } |
| 3022 | |
| 3023 | /* |
| 3024 | * FIXME: we should take ar->list_lock to protect changes in the |
| 3025 | * vif_list, but that's not trivial to do as ath6kl_cfg80211_stop() |
| 3026 | * sleeps. |
| 3027 | */ |
| 3028 | list_for_each_entry(vif, &ar->vif_list, list) |
| 3029 | ath6kl_cfg80211_stop(vif); |
| 3030 | } |
| 3031 | |
Kalle Valo | c25889e | 2012-01-17 20:08:27 +0200 | [diff] [blame] | 3032 | static int ath6kl_cfg80211_vif_init(struct ath6kl_vif *vif) |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 3033 | { |
Vasanthakumar Thiagarajan | 7baef81 | 2012-01-21 15:22:50 +0530 | [diff] [blame] | 3034 | vif->aggr_cntxt = aggr_init(vif); |
Vasanthakumar Thiagarajan | 2132c69 | 2011-10-25 19:34:07 +0530 | [diff] [blame] | 3035 | if (!vif->aggr_cntxt) { |
Vasanthakumar Thiagarajan | 8dafb70 | 2011-10-25 19:33:58 +0530 | [diff] [blame] | 3036 | ath6kl_err("failed to initialize aggr\n"); |
| 3037 | return -ENOMEM; |
| 3038 | } |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 3039 | |
Vasanthakumar Thiagarajan | de3ad71 | 2011-10-25 19:34:08 +0530 | [diff] [blame] | 3040 | setup_timer(&vif->disconnect_timer, disconnect_timer_handler, |
Vasanthakumar Thiagarajan | 108438b | 2011-10-25 19:34:00 +0530 | [diff] [blame] | 3041 | (unsigned long) vif->ndev); |
Kalle Valo | 10509f9 | 2011-12-13 14:52:07 +0200 | [diff] [blame] | 3042 | setup_timer(&vif->sched_scan_timer, ath6kl_wmi_sscan_timer, |
| 3043 | (unsigned long) vif); |
| 3044 | |
Vasanthakumar Thiagarajan | de3ad71 | 2011-10-25 19:34:08 +0530 | [diff] [blame] | 3045 | set_bit(WMM_ENABLED, &vif->flags); |
Vasanthakumar Thiagarajan | 478ac02 | 2011-10-25 19:34:19 +0530 | [diff] [blame] | 3046 | spin_lock_init(&vif->if_lock); |
Vasanthakumar Thiagarajan | 8dafb70 | 2011-10-25 19:33:58 +0530 | [diff] [blame] | 3047 | |
Vasanthakumar Thiagarajan | 80abaf9 | 2012-01-03 14:42:01 +0530 | [diff] [blame] | 3048 | INIT_LIST_HEAD(&vif->mc_filter); |
| 3049 | |
Vasanthakumar Thiagarajan | 8dafb70 | 2011-10-25 19:33:58 +0530 | [diff] [blame] | 3050 | return 0; |
| 3051 | } |
| 3052 | |
Kalle Valo | c25889e | 2012-01-17 20:08:27 +0200 | [diff] [blame] | 3053 | void ath6kl_cfg80211_vif_cleanup(struct ath6kl_vif *vif) |
Vasanthakumar Thiagarajan | 8dafb70 | 2011-10-25 19:33:58 +0530 | [diff] [blame] | 3054 | { |
Vasanthakumar Thiagarajan | 5505597 | 2011-10-25 19:34:23 +0530 | [diff] [blame] | 3055 | struct ath6kl *ar = vif->ar; |
Vasanthakumar Thiagarajan | 80abaf9 | 2012-01-03 14:42:01 +0530 | [diff] [blame] | 3056 | struct ath6kl_mc_filter *mc_filter, *tmp; |
Vasanthakumar Thiagarajan | 5505597 | 2011-10-25 19:34:23 +0530 | [diff] [blame] | 3057 | |
Vasanthakumar Thiagarajan | 2132c69 | 2011-10-25 19:34:07 +0530 | [diff] [blame] | 3058 | aggr_module_destroy(vif->aggr_cntxt); |
Vasanthakumar Thiagarajan | 108438b | 2011-10-25 19:34:00 +0530 | [diff] [blame] | 3059 | |
Vasanthakumar Thiagarajan | 5505597 | 2011-10-25 19:34:23 +0530 | [diff] [blame] | 3060 | ar->avail_idx_map |= BIT(vif->fw_vif_idx); |
| 3061 | |
| 3062 | if (vif->nw_type == ADHOC_NETWORK) |
| 3063 | ar->ibss_if_active = false; |
| 3064 | |
Vasanthakumar Thiagarajan | 80abaf9 | 2012-01-03 14:42:01 +0530 | [diff] [blame] | 3065 | list_for_each_entry_safe(mc_filter, tmp, &vif->mc_filter, list) { |
| 3066 | list_del(&mc_filter->list); |
| 3067 | kfree(mc_filter); |
| 3068 | } |
| 3069 | |
Vasanthakumar Thiagarajan | 2792972 | 2011-10-25 19:34:21 +0530 | [diff] [blame] | 3070 | unregister_netdevice(vif->ndev); |
Vasanthakumar Thiagarajan | 5505597 | 2011-10-25 19:34:23 +0530 | [diff] [blame] | 3071 | |
| 3072 | ar->num_vif--; |
Vasanthakumar Thiagarajan | 8dafb70 | 2011-10-25 19:33:58 +0530 | [diff] [blame] | 3073 | } |
| 3074 | |
| 3075 | struct net_device *ath6kl_interface_add(struct ath6kl *ar, char *name, |
Vasanthakumar Thiagarajan | 5505597 | 2011-10-25 19:34:23 +0530 | [diff] [blame] | 3076 | enum nl80211_iftype type, u8 fw_vif_idx, |
| 3077 | u8 nw_type) |
Vasanthakumar Thiagarajan | 8dafb70 | 2011-10-25 19:33:58 +0530 | [diff] [blame] | 3078 | { |
| 3079 | struct net_device *ndev; |
Vasanthakumar Thiagarajan | 108438b | 2011-10-25 19:34:00 +0530 | [diff] [blame] | 3080 | struct ath6kl_vif *vif; |
Vasanthakumar Thiagarajan | 8dafb70 | 2011-10-25 19:33:58 +0530 | [diff] [blame] | 3081 | |
Vasanthakumar Thiagarajan | 5505597 | 2011-10-25 19:34:23 +0530 | [diff] [blame] | 3082 | ndev = alloc_netdev(sizeof(*vif), name, ether_setup); |
Vasanthakumar Thiagarajan | 8dafb70 | 2011-10-25 19:33:58 +0530 | [diff] [blame] | 3083 | if (!ndev) |
| 3084 | return NULL; |
| 3085 | |
Vasanthakumar Thiagarajan | 108438b | 2011-10-25 19:34:00 +0530 | [diff] [blame] | 3086 | vif = netdev_priv(ndev); |
| 3087 | ndev->ieee80211_ptr = &vif->wdev; |
| 3088 | vif->wdev.wiphy = ar->wiphy; |
| 3089 | vif->ar = ar; |
Vasanthakumar Thiagarajan | 108438b | 2011-10-25 19:34:00 +0530 | [diff] [blame] | 3090 | vif->ndev = ndev; |
| 3091 | SET_NETDEV_DEV(ndev, wiphy_dev(vif->wdev.wiphy)); |
| 3092 | vif->wdev.netdev = ndev; |
| 3093 | vif->wdev.iftype = type; |
Vasanthakumar Thiagarajan | 334234b | 2011-10-25 19:34:12 +0530 | [diff] [blame] | 3094 | vif->fw_vif_idx = fw_vif_idx; |
Kalle Valo | d0d670a | 2012-03-07 20:03:58 +0200 | [diff] [blame] | 3095 | vif->nw_type = nw_type; |
| 3096 | vif->next_mode = nw_type; |
Raja Mani | 8f46fcc | 2012-02-20 19:08:07 +0530 | [diff] [blame] | 3097 | vif->listen_intvl_t = ATH6KL_DEFAULT_LISTEN_INTVAL; |
Raja Mani | ce0dc0c | 2012-02-20 19:08:08 +0530 | [diff] [blame] | 3098 | vif->bmiss_time_t = ATH6KL_DEFAULT_BMISS_TIME; |
Vasanthakumar Thiagarajan | 8dafb70 | 2011-10-25 19:33:58 +0530 | [diff] [blame] | 3099 | |
Vasanthakumar Thiagarajan | 5505597 | 2011-10-25 19:34:23 +0530 | [diff] [blame] | 3100 | memcpy(ndev->dev_addr, ar->mac_addr, ETH_ALEN); |
| 3101 | if (fw_vif_idx != 0) |
| 3102 | ndev->dev_addr[0] = (ndev->dev_addr[0] ^ (1 << fw_vif_idx)) | |
| 3103 | 0x2; |
| 3104 | |
Vasanthakumar Thiagarajan | 8dafb70 | 2011-10-25 19:33:58 +0530 | [diff] [blame] | 3105 | init_netdev(ndev); |
| 3106 | |
Vasanthakumar Thiagarajan | e29f25f | 2011-10-25 19:34:15 +0530 | [diff] [blame] | 3107 | ath6kl_init_control_info(vif); |
Vasanthakumar Thiagarajan | 8dafb70 | 2011-10-25 19:33:58 +0530 | [diff] [blame] | 3108 | |
Kalle Valo | c25889e | 2012-01-17 20:08:27 +0200 | [diff] [blame] | 3109 | if (ath6kl_cfg80211_vif_init(vif)) |
Vasanthakumar Thiagarajan | 8dafb70 | 2011-10-25 19:33:58 +0530 | [diff] [blame] | 3110 | goto err; |
| 3111 | |
Vasanthakumar Thiagarajan | 2792972 | 2011-10-25 19:34:21 +0530 | [diff] [blame] | 3112 | if (register_netdevice(ndev)) |
Vasanthakumar Thiagarajan | 8dafb70 | 2011-10-25 19:33:58 +0530 | [diff] [blame] | 3113 | goto err; |
| 3114 | |
Vasanthakumar Thiagarajan | 5505597 | 2011-10-25 19:34:23 +0530 | [diff] [blame] | 3115 | ar->avail_idx_map &= ~BIT(fw_vif_idx); |
Vasanthakumar Thiagarajan | 14ee6f6 | 2011-10-25 19:34:09 +0530 | [diff] [blame] | 3116 | vif->sme_state = SME_DISCONNECTED; |
Vasanthakumar Thiagarajan | 59c9844 | 2011-10-25 19:34:01 +0530 | [diff] [blame] | 3117 | set_bit(WLAN_ENABLED, &vif->flags); |
Vasanthakumar Thiagarajan | 8dafb70 | 2011-10-25 19:33:58 +0530 | [diff] [blame] | 3118 | ar->wlan_pwr_state = WLAN_POWER_STATE_ON; |
Vasanthakumar Thiagarajan | 59c9844 | 2011-10-25 19:34:01 +0530 | [diff] [blame] | 3119 | set_bit(NETDEV_REGISTERED, &vif->flags); |
Vasanthakumar Thiagarajan | 8dafb70 | 2011-10-25 19:33:58 +0530 | [diff] [blame] | 3120 | |
Vasanthakumar Thiagarajan | 5505597 | 2011-10-25 19:34:23 +0530 | [diff] [blame] | 3121 | if (type == NL80211_IFTYPE_ADHOC) |
| 3122 | ar->ibss_if_active = true; |
| 3123 | |
Vasanthakumar Thiagarajan | 11f6e40 | 2011-11-01 16:38:50 +0530 | [diff] [blame] | 3124 | spin_lock_bh(&ar->list_lock); |
Vasanthakumar Thiagarajan | 990bd91 | 2011-10-25 19:34:20 +0530 | [diff] [blame] | 3125 | list_add_tail(&vif->list, &ar->vif_list); |
Vasanthakumar Thiagarajan | 11f6e40 | 2011-11-01 16:38:50 +0530 | [diff] [blame] | 3126 | spin_unlock_bh(&ar->list_lock); |
Vasanthakumar Thiagarajan | 990bd91 | 2011-10-25 19:34:20 +0530 | [diff] [blame] | 3127 | |
Vasanthakumar Thiagarajan | 8dafb70 | 2011-10-25 19:33:58 +0530 | [diff] [blame] | 3128 | return ndev; |
| 3129 | |
| 3130 | err: |
Vasanthakumar Thiagarajan | 2792972 | 2011-10-25 19:34:21 +0530 | [diff] [blame] | 3131 | aggr_module_destroy(vif->aggr_cntxt); |
| 3132 | free_netdev(ndev); |
Vasanthakumar Thiagarajan | 8dafb70 | 2011-10-25 19:33:58 +0530 | [diff] [blame] | 3133 | return NULL; |
| 3134 | } |
| 3135 | |
Kalle Valo | 46d33a2 | 2012-01-17 20:08:40 +0200 | [diff] [blame] | 3136 | int ath6kl_cfg80211_init(struct ath6kl *ar) |
| 3137 | { |
| 3138 | struct wiphy *wiphy = ar->wiphy; |
| 3139 | int ret; |
| 3140 | |
| 3141 | wiphy->mgmt_stypes = ath6kl_mgmt_stypes; |
| 3142 | |
| 3143 | wiphy->max_remain_on_channel_duration = 5000; |
| 3144 | |
| 3145 | /* set device pointer for wiphy */ |
| 3146 | set_wiphy_dev(wiphy, ar->dev); |
| 3147 | |
| 3148 | wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) | |
| 3149 | BIT(NL80211_IFTYPE_ADHOC) | |
| 3150 | BIT(NL80211_IFTYPE_AP); |
| 3151 | if (ar->p2p) { |
| 3152 | wiphy->interface_modes |= BIT(NL80211_IFTYPE_P2P_GO) | |
| 3153 | BIT(NL80211_IFTYPE_P2P_CLIENT); |
| 3154 | } |
| 3155 | |
| 3156 | /* max num of ssids that can be probed during scanning */ |
| 3157 | wiphy->max_scan_ssids = MAX_PROBED_SSID_INDEX; |
| 3158 | wiphy->max_scan_ie_len = 1000; /* FIX: what is correct limit? */ |
| 3159 | wiphy->bands[IEEE80211_BAND_2GHZ] = &ath6kl_band_2ghz; |
| 3160 | wiphy->bands[IEEE80211_BAND_5GHZ] = &ath6kl_band_5ghz; |
| 3161 | wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM; |
| 3162 | |
| 3163 | wiphy->cipher_suites = cipher_suites; |
| 3164 | wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites); |
| 3165 | |
| 3166 | wiphy->wowlan.flags = WIPHY_WOWLAN_MAGIC_PKT | |
| 3167 | WIPHY_WOWLAN_DISCONNECT | |
| 3168 | WIPHY_WOWLAN_GTK_REKEY_FAILURE | |
| 3169 | WIPHY_WOWLAN_SUPPORTS_GTK_REKEY | |
| 3170 | WIPHY_WOWLAN_EAP_IDENTITY_REQ | |
| 3171 | WIPHY_WOWLAN_4WAY_HANDSHAKE; |
| 3172 | wiphy->wowlan.n_patterns = WOW_MAX_FILTERS_PER_LIST; |
| 3173 | wiphy->wowlan.pattern_min_len = 1; |
| 3174 | wiphy->wowlan.pattern_max_len = WOW_PATTERN_SIZE; |
| 3175 | |
| 3176 | wiphy->max_sched_scan_ssids = 10; |
| 3177 | |
Vasanthakumar Thiagarajan | f2afdac | 2012-02-28 20:20:19 +0530 | [diff] [blame] | 3178 | ar->wiphy->flags |= WIPHY_FLAG_SUPPORTS_FW_ROAM | |
| 3179 | WIPHY_FLAG_HAVE_AP_SME | |
| 3180 | WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL | |
| 3181 | WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD; |
| 3182 | |
| 3183 | if (test_bit(ATH6KL_FW_CAPABILITY_SCHED_SCAN, ar->fw_capabilities)) |
| 3184 | ar->wiphy->flags |= WIPHY_FLAG_SUPPORTS_SCHED_SCAN; |
| 3185 | |
| 3186 | ar->wiphy->probe_resp_offload = |
| 3187 | NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS | |
| 3188 | NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2 | |
| 3189 | NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P | |
| 3190 | NL80211_PROBE_RESP_OFFLOAD_SUPPORT_80211U; |
| 3191 | |
Kalle Valo | 46d33a2 | 2012-01-17 20:08:40 +0200 | [diff] [blame] | 3192 | ret = wiphy_register(wiphy); |
| 3193 | if (ret < 0) { |
| 3194 | ath6kl_err("couldn't register wiphy device\n"); |
| 3195 | return ret; |
| 3196 | } |
| 3197 | |
Vasanthakumar Thiagarajan | e5348a1 | 2012-02-25 14:43:17 +0530 | [diff] [blame] | 3198 | ar->wiphy_registered = true; |
| 3199 | |
Kalle Valo | 46d33a2 | 2012-01-17 20:08:40 +0200 | [diff] [blame] | 3200 | return 0; |
| 3201 | } |
| 3202 | |
| 3203 | void ath6kl_cfg80211_cleanup(struct ath6kl *ar) |
Vasanthakumar Thiagarajan | 8dafb70 | 2011-10-25 19:33:58 +0530 | [diff] [blame] | 3204 | { |
Vasanthakumar Thiagarajan | be98e3a | 2011-10-25 19:33:57 +0530 | [diff] [blame] | 3205 | wiphy_unregister(ar->wiphy); |
Vasanthakumar Thiagarajan | e5348a1 | 2012-02-25 14:43:17 +0530 | [diff] [blame] | 3206 | |
| 3207 | ar->wiphy_registered = false; |
Kalle Valo | 45eaa78 | 2012-01-17 20:09:05 +0200 | [diff] [blame] | 3208 | } |
Kalle Valo | 46d33a2 | 2012-01-17 20:08:40 +0200 | [diff] [blame] | 3209 | |
Kalle Valo | 45eaa78 | 2012-01-17 20:09:05 +0200 | [diff] [blame] | 3210 | struct ath6kl *ath6kl_cfg80211_create(void) |
| 3211 | { |
| 3212 | struct ath6kl *ar; |
| 3213 | struct wiphy *wiphy; |
| 3214 | |
| 3215 | /* create a new wiphy for use with cfg80211 */ |
| 3216 | wiphy = wiphy_new(&ath6kl_cfg80211_ops, sizeof(struct ath6kl)); |
| 3217 | |
| 3218 | if (!wiphy) { |
| 3219 | ath6kl_err("couldn't allocate wiphy device\n"); |
| 3220 | return NULL; |
| 3221 | } |
| 3222 | |
| 3223 | ar = wiphy_priv(wiphy); |
| 3224 | ar->wiphy = wiphy; |
| 3225 | |
| 3226 | return ar; |
| 3227 | } |
| 3228 | |
| 3229 | /* Note: ar variable must not be accessed after calling this! */ |
| 3230 | void ath6kl_cfg80211_destroy(struct ath6kl *ar) |
| 3231 | { |
Vasanthakumar Thiagarajan | 1d2a445 | 2012-01-21 15:22:53 +0530 | [diff] [blame] | 3232 | int i; |
| 3233 | |
| 3234 | for (i = 0; i < AP_MAX_NUM_STA; i++) |
| 3235 | kfree(ar->sta_list[i].aggr_conn); |
| 3236 | |
Vasanthakumar Thiagarajan | be98e3a | 2011-10-25 19:33:57 +0530 | [diff] [blame] | 3237 | wiphy_free(ar->wiphy); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 3238 | } |
Kalle Valo | 45eaa78 | 2012-01-17 20:09:05 +0200 | [diff] [blame] | 3239 | |