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