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