Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2010 Broadcom Corporation |
| 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 ANY |
| 11 | * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION |
| 13 | * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN |
| 14 | * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 15 | */ |
| 16 | |
| 17 | /* Toplevel file. Relies on dhd_linux.c to send commands to the dongle. */ |
| 18 | |
| 19 | #include <linux/kernel.h> |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 20 | #include <linux/etherdevice.h> |
Hante Meuleman | 68ca395 | 2014-02-25 20:30:26 +0100 | [diff] [blame] | 21 | #include <linux/module.h> |
Franky Lin | 1bacb04 | 2014-06-21 12:11:16 +0200 | [diff] [blame] | 22 | #include <linux/vmalloc.h> |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 23 | #include <net/cfg80211.h> |
Arend van Spriel | cbaa177 | 2012-08-30 19:43:02 +0200 | [diff] [blame] | 24 | #include <net/netlink.h> |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 25 | |
| 26 | #include <brcmu_utils.h> |
| 27 | #include <defs.h> |
| 28 | #include <brcmu_wifi.h> |
Hante Meuleman | 122d3d0 | 2014-10-28 14:56:18 +0100 | [diff] [blame] | 29 | #include "core.h" |
Hante Meuleman | a8e8ed3 | 2014-10-28 14:56:13 +0100 | [diff] [blame] | 30 | #include "debug.h" |
Arend van Spriel | 40c1c24 | 2013-04-05 10:57:44 +0200 | [diff] [blame] | 31 | #include "tracepoint.h" |
Hante Meuleman | 7a5c1f6 | 2013-02-08 15:53:44 +0100 | [diff] [blame] | 32 | #include "fwil_types.h" |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 33 | #include "p2p.h" |
Piotr Haber | 61730d4 | 2013-04-23 12:53:12 +0200 | [diff] [blame] | 34 | #include "btcoex.h" |
Arend Van Spriel | ac55136 | 2016-11-23 10:25:22 +0000 | [diff] [blame] | 35 | #include "pno.h" |
Hante Meuleman | bfe8197 | 2014-10-28 14:56:16 +0100 | [diff] [blame] | 36 | #include "cfg80211.h" |
Arend van Spriel | c08437b | 2014-07-12 08:49:39 +0200 | [diff] [blame] | 37 | #include "feature.h" |
Hante Meuleman | 81f5dcb | 2012-10-22 10:36:14 -0700 | [diff] [blame] | 38 | #include "fwil.h" |
Hante Meuleman | 8851cce | 2014-07-30 13:20:02 +0200 | [diff] [blame] | 39 | #include "proto.h" |
Franky Lin | 1bacb04 | 2014-06-21 12:11:16 +0200 | [diff] [blame] | 40 | #include "vendor.h" |
Hante Meuleman | d14f78b | 2014-10-28 14:56:14 +0100 | [diff] [blame] | 41 | #include "bus.h" |
Hante Meuleman | 6b89dcb | 2014-12-21 12:43:52 +0100 | [diff] [blame] | 42 | #include "common.h" |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 43 | |
Arend van Spriel | e580607 | 2012-09-19 22:21:08 +0200 | [diff] [blame] | 44 | #define BRCMF_SCAN_IE_LEN_MAX 2048 |
Arend van Spriel | e580607 | 2012-09-19 22:21:08 +0200 | [diff] [blame] | 45 | |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 46 | #define WPA_OUI "\x00\x50\xF2" /* WPA OUI */ |
| 47 | #define WPA_OUI_TYPE 1 |
| 48 | #define RSN_OUI "\x00\x0F\xAC" /* RSN OUI */ |
| 49 | #define WME_OUI_TYPE 2 |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 50 | #define WPS_OUI_TYPE 4 |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 51 | |
| 52 | #define VS_IE_FIXED_HDR_LEN 6 |
| 53 | #define WPA_IE_VERSION_LEN 2 |
| 54 | #define WPA_IE_MIN_OUI_LEN 4 |
| 55 | #define WPA_IE_SUITE_COUNT_LEN 2 |
| 56 | |
| 57 | #define WPA_CIPHER_NONE 0 /* None */ |
| 58 | #define WPA_CIPHER_WEP_40 1 /* WEP (40-bit) */ |
| 59 | #define WPA_CIPHER_TKIP 2 /* TKIP: default for WPA */ |
| 60 | #define WPA_CIPHER_AES_CCM 4 /* AES (CCM) */ |
| 61 | #define WPA_CIPHER_WEP_104 5 /* WEP (104-bit) */ |
| 62 | |
| 63 | #define RSN_AKM_NONE 0 /* None (IBSS) */ |
| 64 | #define RSN_AKM_UNSPECIFIED 1 /* Over 802.1x */ |
| 65 | #define RSN_AKM_PSK 2 /* Pre-shared Key */ |
Hante Meuleman | 240d61a | 2016-02-17 11:27:10 +0100 | [diff] [blame] | 66 | #define RSN_AKM_SHA256_1X 5 /* SHA256, 802.1X */ |
| 67 | #define RSN_AKM_SHA256_PSK 6 /* SHA256, Pre-shared Key */ |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 68 | #define RSN_CAP_LEN 2 /* Length of RSN capabilities */ |
Hante Meuleman | 240d61a | 2016-02-17 11:27:10 +0100 | [diff] [blame] | 69 | #define RSN_CAP_PTK_REPLAY_CNTR_MASK (BIT(2) | BIT(3)) |
| 70 | #define RSN_CAP_MFPR_MASK BIT(6) |
| 71 | #define RSN_CAP_MFPC_MASK BIT(7) |
| 72 | #define RSN_PMKID_COUNT_LEN 2 |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 73 | |
| 74 | #define VNDR_IE_CMD_LEN 4 /* length of the set command |
| 75 | * string :"add", "del" (+ NUL) |
| 76 | */ |
| 77 | #define VNDR_IE_COUNT_OFFSET 4 |
| 78 | #define VNDR_IE_PKTFLAG_OFFSET 8 |
| 79 | #define VNDR_IE_VSIE_OFFSET 12 |
| 80 | #define VNDR_IE_HDR_SIZE 12 |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 81 | #define VNDR_IE_PARSE_LIMIT 5 |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 82 | |
| 83 | #define DOT11_MGMT_HDR_LEN 24 /* d11 management header len */ |
| 84 | #define DOT11_BCN_PRB_FIXED_LEN 12 /* beacon/probe fixed length */ |
Hante Meuleman | 0401289 | 2012-09-27 14:17:49 +0200 | [diff] [blame] | 85 | |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 86 | #define BRCMF_SCAN_JOIN_ACTIVE_DWELL_TIME_MS 320 |
| 87 | #define BRCMF_SCAN_JOIN_PASSIVE_DWELL_TIME_MS 400 |
| 88 | #define BRCMF_SCAN_JOIN_PROBE_INTERVAL_MS 20 |
| 89 | |
Hante Meuleman | 1678ba8 | 2015-12-10 13:43:00 +0100 | [diff] [blame] | 90 | #define BRCMF_SCAN_CHANNEL_TIME 40 |
| 91 | #define BRCMF_SCAN_UNASSOC_TIME 40 |
| 92 | #define BRCMF_SCAN_PASSIVE_TIME 120 |
| 93 | |
Hante Meuleman | 3021ad9 | 2016-01-05 11:05:45 +0100 | [diff] [blame] | 94 | #define BRCMF_ND_INFO_TIMEOUT msecs_to_jiffies(2000) |
| 95 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 96 | #define BRCMF_ASSOC_PARAMS_FIXED_SIZE \ |
| 97 | (sizeof(struct brcmf_assoc_params_le) - sizeof(u16)) |
| 98 | |
Arend van Spriel | ce81e31 | 2012-10-22 13:55:37 -0700 | [diff] [blame] | 99 | static bool check_vif_up(struct brcmf_cfg80211_vif *vif) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 100 | { |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 101 | if (!test_bit(BRCMF_VIF_STATUS_READY, &vif->sme_state)) { |
Arend van Spriel | 647c9ae | 2012-12-05 15:26:01 +0100 | [diff] [blame] | 102 | brcmf_dbg(INFO, "device is not ready : status (%lu)\n", |
| 103 | vif->sme_state); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 104 | return false; |
| 105 | } |
| 106 | return true; |
| 107 | } |
| 108 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 109 | #define RATE_TO_BASE100KBPS(rate) (((rate) * 10) / 2) |
| 110 | #define RATETAB_ENT(_rateid, _flags) \ |
| 111 | { \ |
| 112 | .bitrate = RATE_TO_BASE100KBPS(_rateid), \ |
| 113 | .hw_value = (_rateid), \ |
| 114 | .flags = (_flags), \ |
| 115 | } |
| 116 | |
| 117 | static struct ieee80211_rate __wl_rates[] = { |
| 118 | RATETAB_ENT(BRCM_RATE_1M, 0), |
| 119 | RATETAB_ENT(BRCM_RATE_2M, IEEE80211_RATE_SHORT_PREAMBLE), |
| 120 | RATETAB_ENT(BRCM_RATE_5M5, IEEE80211_RATE_SHORT_PREAMBLE), |
| 121 | RATETAB_ENT(BRCM_RATE_11M, IEEE80211_RATE_SHORT_PREAMBLE), |
| 122 | RATETAB_ENT(BRCM_RATE_6M, 0), |
| 123 | RATETAB_ENT(BRCM_RATE_9M, 0), |
| 124 | RATETAB_ENT(BRCM_RATE_12M, 0), |
| 125 | RATETAB_ENT(BRCM_RATE_18M, 0), |
| 126 | RATETAB_ENT(BRCM_RATE_24M, 0), |
| 127 | RATETAB_ENT(BRCM_RATE_36M, 0), |
| 128 | RATETAB_ENT(BRCM_RATE_48M, 0), |
| 129 | RATETAB_ENT(BRCM_RATE_54M, 0), |
| 130 | }; |
| 131 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 132 | #define wl_g_rates (__wl_rates + 0) |
Arend van Spriel | 58de92d | 2015-04-14 20:10:24 +0200 | [diff] [blame] | 133 | #define wl_g_rates_size ARRAY_SIZE(__wl_rates) |
| 134 | #define wl_a_rates (__wl_rates + 4) |
| 135 | #define wl_a_rates_size (wl_g_rates_size - 4) |
| 136 | |
| 137 | #define CHAN2G(_channel, _freq) { \ |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 138 | .band = NL80211_BAND_2GHZ, \ |
Arend van Spriel | 58de92d | 2015-04-14 20:10:24 +0200 | [diff] [blame] | 139 | .center_freq = (_freq), \ |
| 140 | .hw_value = (_channel), \ |
| 141 | .flags = IEEE80211_CHAN_DISABLED, \ |
| 142 | .max_antenna_gain = 0, \ |
| 143 | .max_power = 30, \ |
| 144 | } |
| 145 | |
| 146 | #define CHAN5G(_channel) { \ |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 147 | .band = NL80211_BAND_5GHZ, \ |
Arend van Spriel | 58de92d | 2015-04-14 20:10:24 +0200 | [diff] [blame] | 148 | .center_freq = 5000 + (5 * (_channel)), \ |
| 149 | .hw_value = (_channel), \ |
| 150 | .flags = IEEE80211_CHAN_DISABLED, \ |
| 151 | .max_antenna_gain = 0, \ |
| 152 | .max_power = 30, \ |
| 153 | } |
| 154 | |
| 155 | static struct ieee80211_channel __wl_2ghz_channels[] = { |
| 156 | CHAN2G(1, 2412), CHAN2G(2, 2417), CHAN2G(3, 2422), CHAN2G(4, 2427), |
| 157 | CHAN2G(5, 2432), CHAN2G(6, 2437), CHAN2G(7, 2442), CHAN2G(8, 2447), |
| 158 | CHAN2G(9, 2452), CHAN2G(10, 2457), CHAN2G(11, 2462), CHAN2G(12, 2467), |
| 159 | CHAN2G(13, 2472), CHAN2G(14, 2484) |
| 160 | }; |
| 161 | |
| 162 | static struct ieee80211_channel __wl_5ghz_channels[] = { |
| 163 | CHAN5G(34), CHAN5G(36), CHAN5G(38), CHAN5G(40), CHAN5G(42), |
| 164 | CHAN5G(44), CHAN5G(46), CHAN5G(48), CHAN5G(52), CHAN5G(56), |
| 165 | CHAN5G(60), CHAN5G(64), CHAN5G(100), CHAN5G(104), CHAN5G(108), |
| 166 | CHAN5G(112), CHAN5G(116), CHAN5G(120), CHAN5G(124), CHAN5G(128), |
| 167 | CHAN5G(132), CHAN5G(136), CHAN5G(140), CHAN5G(144), CHAN5G(149), |
| 168 | CHAN5G(153), CHAN5G(157), CHAN5G(161), CHAN5G(165) |
| 169 | }; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 170 | |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 171 | /* Band templates duplicated per wiphy. The channel info |
Arend van Spriel | 58de92d | 2015-04-14 20:10:24 +0200 | [diff] [blame] | 172 | * above is added to the band during setup. |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 173 | */ |
| 174 | static const struct ieee80211_supported_band __wl_band_2ghz = { |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 175 | .band = NL80211_BAND_2GHZ, |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 176 | .bitrates = wl_g_rates, |
| 177 | .n_bitrates = wl_g_rates_size, |
| 178 | }; |
| 179 | |
Arend van Spriel | 58de92d | 2015-04-14 20:10:24 +0200 | [diff] [blame] | 180 | static const struct ieee80211_supported_band __wl_band_5ghz = { |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 181 | .band = NL80211_BAND_5GHZ, |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 182 | .bitrates = wl_a_rates, |
| 183 | .n_bitrates = wl_a_rates_size, |
| 184 | }; |
| 185 | |
Hante Meuleman | d48200b | 2013-04-03 12:40:29 +0200 | [diff] [blame] | 186 | /* This is to override regulatory domains defined in cfg80211 module (reg.c) |
| 187 | * By default world regulatory domain defined in reg.c puts the flags |
Luis R. Rodriguez | 8fe02e1 | 2013-10-21 19:22:25 +0200 | [diff] [blame] | 188 | * NL80211_RRF_NO_IR for 5GHz channels (for * 36..48 and 149..165). |
| 189 | * With respect to these flags, wpa_supplicant doesn't * start p2p |
| 190 | * operations on 5GHz channels. All the changes in world regulatory |
Hante Meuleman | d48200b | 2013-04-03 12:40:29 +0200 | [diff] [blame] | 191 | * domain are to be done here. |
| 192 | */ |
| 193 | static const struct ieee80211_regdomain brcmf_regdom = { |
| 194 | .n_reg_rules = 4, |
| 195 | .alpha2 = "99", |
| 196 | .reg_rules = { |
| 197 | /* IEEE 802.11b/g, channels 1..11 */ |
| 198 | REG_RULE(2412-10, 2472+10, 40, 6, 20, 0), |
| 199 | /* If any */ |
| 200 | /* IEEE 802.11 channel 14 - Only JP enables |
| 201 | * this and for 802.11b only |
| 202 | */ |
| 203 | REG_RULE(2484-10, 2484+10, 20, 6, 20, 0), |
| 204 | /* IEEE 802.11a, channel 36..64 */ |
Arend van Spriel | c555ecd | 2014-05-12 10:47:36 +0200 | [diff] [blame] | 205 | REG_RULE(5150-10, 5350+10, 80, 6, 20, 0), |
Hante Meuleman | d48200b | 2013-04-03 12:40:29 +0200 | [diff] [blame] | 206 | /* IEEE 802.11a, channel 100..165 */ |
Arend van Spriel | c555ecd | 2014-05-12 10:47:36 +0200 | [diff] [blame] | 207 | REG_RULE(5470-10, 5850+10, 80, 6, 20, 0), } |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 208 | }; |
| 209 | |
Hante Meuleman | 240d61a | 2016-02-17 11:27:10 +0100 | [diff] [blame] | 210 | /* Note: brcmf_cipher_suites is an array of int defining which cipher suites |
| 211 | * are supported. A pointer to this array and the number of entries is passed |
| 212 | * on to upper layers. AES_CMAC defines whether or not the driver supports MFP. |
| 213 | * So the cipher suite AES_CMAC has to be the last one in the array, and when |
| 214 | * device does not support MFP then the number of suites will be decreased by 1 |
| 215 | */ |
| 216 | static const u32 brcmf_cipher_suites[] = { |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 217 | WLAN_CIPHER_SUITE_WEP40, |
| 218 | WLAN_CIPHER_SUITE_WEP104, |
| 219 | WLAN_CIPHER_SUITE_TKIP, |
| 220 | WLAN_CIPHER_SUITE_CCMP, |
Hante Meuleman | 240d61a | 2016-02-17 11:27:10 +0100 | [diff] [blame] | 221 | /* Keep as last entry: */ |
| 222 | WLAN_CIPHER_SUITE_AES_CMAC |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 223 | }; |
| 224 | |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 225 | /* Vendor specific ie. id = 221, oui and type defines exact ie */ |
| 226 | struct brcmf_vs_tlv { |
| 227 | u8 id; |
| 228 | u8 len; |
| 229 | u8 oui[3]; |
| 230 | u8 oui_type; |
| 231 | }; |
| 232 | |
| 233 | struct parsed_vndr_ie_info { |
| 234 | u8 *ie_ptr; |
| 235 | u32 ie_len; /* total length including id & length field */ |
| 236 | struct brcmf_vs_tlv vndrie; |
| 237 | }; |
| 238 | |
| 239 | struct parsed_vndr_ies { |
| 240 | u32 count; |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 241 | struct parsed_vndr_ie_info ie_info[VNDR_IE_PARSE_LIMIT]; |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 242 | }; |
| 243 | |
Arend van Spriel | 7705ba6 | 2016-04-17 16:44:58 +0200 | [diff] [blame] | 244 | static u8 nl80211_band_to_fwil(enum nl80211_band band) |
| 245 | { |
| 246 | switch (band) { |
| 247 | case NL80211_BAND_2GHZ: |
| 248 | return WLC_BAND_2G; |
| 249 | case NL80211_BAND_5GHZ: |
| 250 | return WLC_BAND_5G; |
| 251 | default: |
| 252 | WARN_ON(1); |
| 253 | break; |
| 254 | } |
| 255 | return 0; |
| 256 | } |
| 257 | |
Arend van Spriel | 5a394eb | 2014-05-27 12:56:15 +0200 | [diff] [blame] | 258 | static u16 chandef_to_chanspec(struct brcmu_d11inf *d11inf, |
| 259 | struct cfg80211_chan_def *ch) |
Arend van Spriel | 600a897 | 2014-05-12 10:47:39 +0200 | [diff] [blame] | 260 | { |
| 261 | struct brcmu_chan ch_inf; |
| 262 | s32 primary_offset; |
| 263 | |
| 264 | brcmf_dbg(TRACE, "chandef: control %d center %d width %d\n", |
| 265 | ch->chan->center_freq, ch->center_freq1, ch->width); |
| 266 | ch_inf.chnum = ieee80211_frequency_to_channel(ch->center_freq1); |
Rafał Miłecki | 36e8072 | 2016-01-20 16:46:04 +0100 | [diff] [blame] | 267 | primary_offset = ch->chan->center_freq - ch->center_freq1; |
Arend van Spriel | 600a897 | 2014-05-12 10:47:39 +0200 | [diff] [blame] | 268 | switch (ch->width) { |
| 269 | case NL80211_CHAN_WIDTH_20: |
Arend van Spriel | 0cd75b1 | 2014-11-11 13:58:44 +0100 | [diff] [blame] | 270 | case NL80211_CHAN_WIDTH_20_NOHT: |
Arend van Spriel | 600a897 | 2014-05-12 10:47:39 +0200 | [diff] [blame] | 271 | ch_inf.bw = BRCMU_CHAN_BW_20; |
| 272 | WARN_ON(primary_offset != 0); |
| 273 | break; |
| 274 | case NL80211_CHAN_WIDTH_40: |
| 275 | ch_inf.bw = BRCMU_CHAN_BW_40; |
Rafał Miłecki | 36e8072 | 2016-01-20 16:46:04 +0100 | [diff] [blame] | 276 | if (primary_offset > 0) |
Arend van Spriel | 600a897 | 2014-05-12 10:47:39 +0200 | [diff] [blame] | 277 | ch_inf.sb = BRCMU_CHAN_SB_U; |
| 278 | else |
| 279 | ch_inf.sb = BRCMU_CHAN_SB_L; |
| 280 | break; |
| 281 | case NL80211_CHAN_WIDTH_80: |
| 282 | ch_inf.bw = BRCMU_CHAN_BW_80; |
Rafał Miłecki | 36e8072 | 2016-01-20 16:46:04 +0100 | [diff] [blame] | 283 | if (primary_offset == -30) |
| 284 | ch_inf.sb = BRCMU_CHAN_SB_LL; |
| 285 | else if (primary_offset == -10) |
| 286 | ch_inf.sb = BRCMU_CHAN_SB_LU; |
| 287 | else if (primary_offset == 10) |
| 288 | ch_inf.sb = BRCMU_CHAN_SB_UL; |
| 289 | else |
| 290 | ch_inf.sb = BRCMU_CHAN_SB_UU; |
Arend van Spriel | 600a897 | 2014-05-12 10:47:39 +0200 | [diff] [blame] | 291 | break; |
Arend van Spriel | 0cd75b1 | 2014-11-11 13:58:44 +0100 | [diff] [blame] | 292 | case NL80211_CHAN_WIDTH_80P80: |
| 293 | case NL80211_CHAN_WIDTH_160: |
| 294 | case NL80211_CHAN_WIDTH_5: |
| 295 | case NL80211_CHAN_WIDTH_10: |
Arend van Spriel | 600a897 | 2014-05-12 10:47:39 +0200 | [diff] [blame] | 296 | default: |
| 297 | WARN_ON_ONCE(1); |
| 298 | } |
| 299 | switch (ch->chan->band) { |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 300 | case NL80211_BAND_2GHZ: |
Arend van Spriel | 600a897 | 2014-05-12 10:47:39 +0200 | [diff] [blame] | 301 | ch_inf.band = BRCMU_CHAN_BAND_2G; |
| 302 | break; |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 303 | case NL80211_BAND_5GHZ: |
Arend van Spriel | 600a897 | 2014-05-12 10:47:39 +0200 | [diff] [blame] | 304 | ch_inf.band = BRCMU_CHAN_BAND_5G; |
| 305 | break; |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 306 | case NL80211_BAND_60GHZ: |
Arend van Spriel | 600a897 | 2014-05-12 10:47:39 +0200 | [diff] [blame] | 307 | default: |
| 308 | WARN_ON_ONCE(1); |
| 309 | } |
| 310 | d11inf->encchspec(&ch_inf); |
| 311 | |
| 312 | return ch_inf.chspec; |
| 313 | } |
| 314 | |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 315 | u16 channel_to_chanspec(struct brcmu_d11inf *d11inf, |
| 316 | struct ieee80211_channel *ch) |
Arend van Spriel | 6e18616 | 2012-10-22 10:36:22 -0700 | [diff] [blame] | 317 | { |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 318 | struct brcmu_chan ch_inf; |
Arend van Spriel | 6e18616 | 2012-10-22 10:36:22 -0700 | [diff] [blame] | 319 | |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 320 | ch_inf.chnum = ieee80211_frequency_to_channel(ch->center_freq); |
| 321 | ch_inf.bw = BRCMU_CHAN_BW_20; |
| 322 | d11inf->encchspec(&ch_inf); |
Arend van Spriel | 6e18616 | 2012-10-22 10:36:22 -0700 | [diff] [blame] | 323 | |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 324 | return ch_inf.chspec; |
Arend van Spriel | 6e18616 | 2012-10-22 10:36:22 -0700 | [diff] [blame] | 325 | } |
| 326 | |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 327 | /* Traverse a string of 1-byte tag/1-byte length/variable-length value |
| 328 | * triples, returning a pointer to the substring whose first element |
| 329 | * matches tag |
| 330 | */ |
Johannes Berg | 4b5800f | 2014-01-15 14:55:59 +0100 | [diff] [blame] | 331 | const struct brcmf_tlv * |
| 332 | brcmf_parse_tlvs(const void *buf, int buflen, uint key) |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 333 | { |
Johannes Berg | 4b5800f | 2014-01-15 14:55:59 +0100 | [diff] [blame] | 334 | const struct brcmf_tlv *elt = buf; |
| 335 | int totlen = buflen; |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 336 | |
| 337 | /* find tagged parameter */ |
| 338 | while (totlen >= TLV_HDR_LEN) { |
| 339 | int len = elt->len; |
| 340 | |
| 341 | /* validate remaining totlen */ |
| 342 | if ((elt->id == key) && (totlen >= (len + TLV_HDR_LEN))) |
| 343 | return elt; |
| 344 | |
| 345 | elt = (struct brcmf_tlv *)((u8 *)elt + (len + TLV_HDR_LEN)); |
| 346 | totlen -= (len + TLV_HDR_LEN); |
| 347 | } |
| 348 | |
| 349 | return NULL; |
| 350 | } |
| 351 | |
| 352 | /* Is any of the tlvs the expected entry? If |
| 353 | * not update the tlvs buffer pointer/length. |
| 354 | */ |
| 355 | static bool |
Johannes Berg | 4b5800f | 2014-01-15 14:55:59 +0100 | [diff] [blame] | 356 | brcmf_tlv_has_ie(const u8 *ie, const u8 **tlvs, u32 *tlvs_len, |
| 357 | const u8 *oui, u32 oui_len, u8 type) |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 358 | { |
| 359 | /* If the contents match the OUI and the type */ |
| 360 | if (ie[TLV_LEN_OFF] >= oui_len + 1 && |
| 361 | !memcmp(&ie[TLV_BODY_OFF], oui, oui_len) && |
| 362 | type == ie[TLV_BODY_OFF + oui_len]) { |
| 363 | return true; |
| 364 | } |
| 365 | |
| 366 | if (tlvs == NULL) |
| 367 | return false; |
| 368 | /* point to the next ie */ |
| 369 | ie += ie[TLV_LEN_OFF] + TLV_HDR_LEN; |
| 370 | /* calculate the length of the rest of the buffer */ |
| 371 | *tlvs_len -= (int)(ie - *tlvs); |
| 372 | /* update the pointer to the start of the buffer */ |
| 373 | *tlvs = ie; |
| 374 | |
| 375 | return false; |
| 376 | } |
| 377 | |
| 378 | static struct brcmf_vs_tlv * |
Johannes Berg | 4b5800f | 2014-01-15 14:55:59 +0100 | [diff] [blame] | 379 | brcmf_find_wpaie(const u8 *parse, u32 len) |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 380 | { |
Johannes Berg | 4b5800f | 2014-01-15 14:55:59 +0100 | [diff] [blame] | 381 | const struct brcmf_tlv *ie; |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 382 | |
| 383 | while ((ie = brcmf_parse_tlvs(parse, len, WLAN_EID_VENDOR_SPECIFIC))) { |
Johannes Berg | 4b5800f | 2014-01-15 14:55:59 +0100 | [diff] [blame] | 384 | if (brcmf_tlv_has_ie((const u8 *)ie, &parse, &len, |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 385 | WPA_OUI, TLV_OUI_LEN, WPA_OUI_TYPE)) |
| 386 | return (struct brcmf_vs_tlv *)ie; |
| 387 | } |
| 388 | return NULL; |
| 389 | } |
| 390 | |
| 391 | static struct brcmf_vs_tlv * |
Johannes Berg | 4b5800f | 2014-01-15 14:55:59 +0100 | [diff] [blame] | 392 | brcmf_find_wpsie(const u8 *parse, u32 len) |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 393 | { |
Johannes Berg | 4b5800f | 2014-01-15 14:55:59 +0100 | [diff] [blame] | 394 | const struct brcmf_tlv *ie; |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 395 | |
| 396 | while ((ie = brcmf_parse_tlvs(parse, len, WLAN_EID_VENDOR_SPECIFIC))) { |
| 397 | if (brcmf_tlv_has_ie((u8 *)ie, &parse, &len, |
| 398 | WPA_OUI, TLV_OUI_LEN, WPS_OUI_TYPE)) |
| 399 | return (struct brcmf_vs_tlv *)ie; |
| 400 | } |
| 401 | return NULL; |
| 402 | } |
| 403 | |
Arend van Spriel | 39504a2 | 2015-08-20 22:06:05 +0200 | [diff] [blame] | 404 | static int brcmf_vif_change_validate(struct brcmf_cfg80211_info *cfg, |
| 405 | struct brcmf_cfg80211_vif *vif, |
| 406 | enum nl80211_iftype new_type) |
| 407 | { |
Arend van Spriel | 39504a2 | 2015-08-20 22:06:05 +0200 | [diff] [blame] | 408 | struct brcmf_cfg80211_vif *pos; |
Arend van Spriel | 353c46a | 2015-12-10 13:43:06 +0100 | [diff] [blame] | 409 | bool check_combos = false; |
| 410 | int ret = 0; |
Purushottam Kushwaha | e227300 | 2016-10-12 18:25:35 +0530 | [diff] [blame] | 411 | struct iface_combination_params params = { |
| 412 | .num_different_channels = 1, |
| 413 | }; |
Arend van Spriel | 39504a2 | 2015-08-20 22:06:05 +0200 | [diff] [blame] | 414 | |
Arend van Spriel | 39504a2 | 2015-08-20 22:06:05 +0200 | [diff] [blame] | 415 | list_for_each_entry(pos, &cfg->vif_list, list) |
Arend van Spriel | 353c46a | 2015-12-10 13:43:06 +0100 | [diff] [blame] | 416 | if (pos == vif) { |
Purushottam Kushwaha | e227300 | 2016-10-12 18:25:35 +0530 | [diff] [blame] | 417 | params.iftype_num[new_type]++; |
Arend van Spriel | 353c46a | 2015-12-10 13:43:06 +0100 | [diff] [blame] | 418 | } else { |
| 419 | /* concurrent interfaces so need check combinations */ |
| 420 | check_combos = true; |
Purushottam Kushwaha | e227300 | 2016-10-12 18:25:35 +0530 | [diff] [blame] | 421 | params.iftype_num[pos->wdev.iftype]++; |
Arend van Spriel | 353c46a | 2015-12-10 13:43:06 +0100 | [diff] [blame] | 422 | } |
Arend van Spriel | 39504a2 | 2015-08-20 22:06:05 +0200 | [diff] [blame] | 423 | |
Arend van Spriel | 353c46a | 2015-12-10 13:43:06 +0100 | [diff] [blame] | 424 | if (check_combos) |
Purushottam Kushwaha | e227300 | 2016-10-12 18:25:35 +0530 | [diff] [blame] | 425 | ret = cfg80211_check_combinations(cfg->wiphy, ¶ms); |
Arend van Spriel | 353c46a | 2015-12-10 13:43:06 +0100 | [diff] [blame] | 426 | |
| 427 | return ret; |
Arend van Spriel | 39504a2 | 2015-08-20 22:06:05 +0200 | [diff] [blame] | 428 | } |
| 429 | |
| 430 | static int brcmf_vif_add_validate(struct brcmf_cfg80211_info *cfg, |
| 431 | enum nl80211_iftype new_type) |
| 432 | { |
Arend van Spriel | 39504a2 | 2015-08-20 22:06:05 +0200 | [diff] [blame] | 433 | struct brcmf_cfg80211_vif *pos; |
Purushottam Kushwaha | e227300 | 2016-10-12 18:25:35 +0530 | [diff] [blame] | 434 | struct iface_combination_params params = { |
| 435 | .num_different_channels = 1, |
| 436 | }; |
Arend van Spriel | 39504a2 | 2015-08-20 22:06:05 +0200 | [diff] [blame] | 437 | |
Arend van Spriel | 39504a2 | 2015-08-20 22:06:05 +0200 | [diff] [blame] | 438 | list_for_each_entry(pos, &cfg->vif_list, list) |
Purushottam Kushwaha | e227300 | 2016-10-12 18:25:35 +0530 | [diff] [blame] | 439 | params.iftype_num[pos->wdev.iftype]++; |
Arend van Spriel | 39504a2 | 2015-08-20 22:06:05 +0200 | [diff] [blame] | 440 | |
Purushottam Kushwaha | e227300 | 2016-10-12 18:25:35 +0530 | [diff] [blame] | 441 | params.iftype_num[new_type]++; |
| 442 | return cfg80211_check_combinations(cfg->wiphy, ¶ms); |
Arend van Spriel | 39504a2 | 2015-08-20 22:06:05 +0200 | [diff] [blame] | 443 | } |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 444 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 445 | static void convert_key_from_CPU(struct brcmf_wsec_key *key, |
| 446 | struct brcmf_wsec_key_le *key_le) |
| 447 | { |
| 448 | key_le->index = cpu_to_le32(key->index); |
| 449 | key_le->len = cpu_to_le32(key->len); |
| 450 | key_le->algo = cpu_to_le32(key->algo); |
| 451 | key_le->flags = cpu_to_le32(key->flags); |
| 452 | key_le->rxiv.hi = cpu_to_le32(key->rxiv.hi); |
| 453 | key_le->rxiv.lo = cpu_to_le16(key->rxiv.lo); |
| 454 | key_le->iv_initialized = cpu_to_le32(key->iv_initialized); |
| 455 | memcpy(key_le->data, key->data, sizeof(key->data)); |
| 456 | memcpy(key_le->ea, key->ea, sizeof(key->ea)); |
| 457 | } |
| 458 | |
Hante Meuleman | f09d0c0 | 2012-09-27 14:17:48 +0200 | [diff] [blame] | 459 | static int |
Hante Meuleman | 118eb30 | 2014-12-21 12:43:49 +0100 | [diff] [blame] | 460 | send_key_to_dongle(struct brcmf_if *ifp, struct brcmf_wsec_key *key) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 461 | { |
| 462 | int err; |
| 463 | struct brcmf_wsec_key_le key_le; |
| 464 | |
| 465 | convert_key_from_CPU(key, &key_le); |
Hante Meuleman | f09d0c0 | 2012-09-27 14:17:48 +0200 | [diff] [blame] | 466 | |
Hante Meuleman | 118eb30 | 2014-12-21 12:43:49 +0100 | [diff] [blame] | 467 | brcmf_netdev_wait_pend8021x(ifp); |
Hante Meuleman | 81f5dcb | 2012-10-22 10:36:14 -0700 | [diff] [blame] | 468 | |
Hante Meuleman | 118eb30 | 2014-12-21 12:43:49 +0100 | [diff] [blame] | 469 | err = brcmf_fil_bsscfg_data_set(ifp, "wsec_key", &key_le, |
Hante Meuleman | 81f5dcb | 2012-10-22 10:36:14 -0700 | [diff] [blame] | 470 | sizeof(key_le)); |
Hante Meuleman | f09d0c0 | 2012-09-27 14:17:48 +0200 | [diff] [blame] | 471 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 472 | if (err) |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 473 | brcmf_err("wsec_key error (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 474 | return err; |
| 475 | } |
| 476 | |
Hante Meuleman | b365745 | 2013-05-27 21:09:53 +0200 | [diff] [blame] | 477 | static s32 |
Franky Lin | 52f22fb | 2016-02-17 11:26:55 +0100 | [diff] [blame] | 478 | brcmf_configure_arp_nd_offload(struct brcmf_if *ifp, bool enable) |
Hante Meuleman | b365745 | 2013-05-27 21:09:53 +0200 | [diff] [blame] | 479 | { |
| 480 | s32 err; |
| 481 | u32 mode; |
| 482 | |
| 483 | if (enable) |
| 484 | mode = BRCMF_ARP_OL_AGENT | BRCMF_ARP_OL_PEER_AUTO_REPLY; |
| 485 | else |
| 486 | mode = 0; |
| 487 | |
| 488 | /* Try to set and enable ARP offload feature, this may fail, then it */ |
| 489 | /* is simply not supported and err 0 will be returned */ |
| 490 | err = brcmf_fil_iovar_int_set(ifp, "arp_ol", mode); |
| 491 | if (err) { |
| 492 | brcmf_dbg(TRACE, "failed to set ARP offload mode to 0x%x, err = %d\n", |
| 493 | mode, err); |
| 494 | err = 0; |
| 495 | } else { |
| 496 | err = brcmf_fil_iovar_int_set(ifp, "arpoe", enable); |
| 497 | if (err) { |
| 498 | brcmf_dbg(TRACE, "failed to configure (%d) ARP offload err = %d\n", |
| 499 | enable, err); |
| 500 | err = 0; |
| 501 | } else |
| 502 | brcmf_dbg(TRACE, "successfully configured (%d) ARP offload to 0x%x\n", |
| 503 | enable, mode); |
| 504 | } |
| 505 | |
Franky Lin | 52f22fb | 2016-02-17 11:26:55 +0100 | [diff] [blame] | 506 | err = brcmf_fil_iovar_int_set(ifp, "ndoe", enable); |
| 507 | if (err) { |
| 508 | brcmf_dbg(TRACE, "failed to configure (%d) ND offload err = %d\n", |
| 509 | enable, err); |
| 510 | err = 0; |
| 511 | } else |
| 512 | brcmf_dbg(TRACE, "successfully configured (%d) ND offload to 0x%x\n", |
| 513 | enable, mode); |
| 514 | |
Hante Meuleman | b365745 | 2013-05-27 21:09:53 +0200 | [diff] [blame] | 515 | return err; |
| 516 | } |
| 517 | |
Hante Meuleman | 8851cce | 2014-07-30 13:20:02 +0200 | [diff] [blame] | 518 | static void |
| 519 | brcmf_cfg80211_update_proto_addr_mode(struct wireless_dev *wdev) |
| 520 | { |
Arend van Spriel | 8f2b459 | 2014-09-11 22:51:32 +0200 | [diff] [blame] | 521 | struct brcmf_cfg80211_vif *vif; |
| 522 | struct brcmf_if *ifp; |
| 523 | |
| 524 | vif = container_of(wdev, struct brcmf_cfg80211_vif, wdev); |
| 525 | ifp = vif->ifp; |
Hante Meuleman | 8851cce | 2014-07-30 13:20:02 +0200 | [diff] [blame] | 526 | |
| 527 | if ((wdev->iftype == NL80211_IFTYPE_ADHOC) || |
| 528 | (wdev->iftype == NL80211_IFTYPE_AP) || |
| 529 | (wdev->iftype == NL80211_IFTYPE_P2P_GO)) |
| 530 | brcmf_proto_configure_addr_mode(ifp->drvr, ifp->ifidx, |
| 531 | ADDR_DIRECT); |
| 532 | else |
| 533 | brcmf_proto_configure_addr_mode(ifp->drvr, ifp->ifidx, |
| 534 | ADDR_INDIRECT); |
| 535 | } |
| 536 | |
Rafał Miłecki | d02fb8f | 2016-05-26 01:44:27 +0200 | [diff] [blame] | 537 | static int brcmf_get_first_free_bsscfgidx(struct brcmf_pub *drvr) |
| 538 | { |
| 539 | int bsscfgidx; |
| 540 | |
| 541 | for (bsscfgidx = 0; bsscfgidx < BRCMF_MAX_IFS; bsscfgidx++) { |
| 542 | /* bsscfgidx 1 is reserved for legacy P2P */ |
| 543 | if (bsscfgidx == 1) |
| 544 | continue; |
| 545 | if (!drvr->iflist[bsscfgidx]) |
| 546 | return bsscfgidx; |
| 547 | } |
| 548 | |
| 549 | return -ENOMEM; |
| 550 | } |
| 551 | |
Hante Meuleman | a44aa40 | 2014-12-03 21:05:33 +0100 | [diff] [blame] | 552 | static int brcmf_cfg80211_request_ap_if(struct brcmf_if *ifp) |
| 553 | { |
| 554 | struct brcmf_mbss_ssid_le mbss_ssid_le; |
| 555 | int bsscfgidx; |
| 556 | int err; |
| 557 | |
| 558 | memset(&mbss_ssid_le, 0, sizeof(mbss_ssid_le)); |
Rafał Miłecki | d02fb8f | 2016-05-26 01:44:27 +0200 | [diff] [blame] | 559 | bsscfgidx = brcmf_get_first_free_bsscfgidx(ifp->drvr); |
Hante Meuleman | a44aa40 | 2014-12-03 21:05:33 +0100 | [diff] [blame] | 560 | if (bsscfgidx < 0) |
| 561 | return bsscfgidx; |
| 562 | |
| 563 | mbss_ssid_le.bsscfgidx = cpu_to_le32(bsscfgidx); |
| 564 | mbss_ssid_le.SSID_len = cpu_to_le32(5); |
| 565 | sprintf(mbss_ssid_le.SSID, "ssid%d" , bsscfgidx); |
| 566 | |
| 567 | err = brcmf_fil_bsscfg_data_set(ifp, "bsscfg:ssid", &mbss_ssid_le, |
| 568 | sizeof(mbss_ssid_le)); |
| 569 | if (err < 0) |
| 570 | brcmf_err("setting ssid failed %d\n", err); |
| 571 | |
| 572 | return err; |
| 573 | } |
| 574 | |
| 575 | /** |
| 576 | * brcmf_ap_add_vif() - create a new AP virtual interface for multiple BSS |
| 577 | * |
| 578 | * @wiphy: wiphy device of new interface. |
| 579 | * @name: name of the new interface. |
| 580 | * @flags: not used. |
| 581 | * @params: contains mac address for AP device. |
| 582 | */ |
| 583 | static |
| 584 | struct wireless_dev *brcmf_ap_add_vif(struct wiphy *wiphy, const char *name, |
| 585 | u32 *flags, struct vif_params *params) |
| 586 | { |
| 587 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); |
| 588 | struct brcmf_if *ifp = netdev_priv(cfg_to_ndev(cfg)); |
| 589 | struct brcmf_cfg80211_vif *vif; |
| 590 | int err; |
| 591 | |
| 592 | if (brcmf_cfg80211_vif_event_armed(cfg)) |
| 593 | return ERR_PTR(-EBUSY); |
| 594 | |
| 595 | brcmf_dbg(INFO, "Adding vif \"%s\"\n", name); |
| 596 | |
Rafał Miłecki | 2607233 | 2016-06-06 23:03:55 +0200 | [diff] [blame] | 597 | vif = brcmf_alloc_vif(cfg, NL80211_IFTYPE_AP); |
Hante Meuleman | a44aa40 | 2014-12-03 21:05:33 +0100 | [diff] [blame] | 598 | if (IS_ERR(vif)) |
| 599 | return (struct wireless_dev *)vif; |
| 600 | |
| 601 | brcmf_cfg80211_arm_vif_event(cfg, vif); |
| 602 | |
| 603 | err = brcmf_cfg80211_request_ap_if(ifp); |
| 604 | if (err) { |
| 605 | brcmf_cfg80211_arm_vif_event(cfg, NULL); |
| 606 | goto fail; |
| 607 | } |
| 608 | |
| 609 | /* wait for firmware event */ |
Arend van Spriel | a9eb0c4 | 2016-02-17 11:26:50 +0100 | [diff] [blame] | 610 | err = brcmf_cfg80211_wait_vif_event(cfg, BRCMF_E_IF_ADD, |
| 611 | BRCMF_VIF_EVENT_TIMEOUT); |
Hante Meuleman | a44aa40 | 2014-12-03 21:05:33 +0100 | [diff] [blame] | 612 | brcmf_cfg80211_arm_vif_event(cfg, NULL); |
| 613 | if (!err) { |
| 614 | brcmf_err("timeout occurred\n"); |
| 615 | err = -EIO; |
| 616 | goto fail; |
| 617 | } |
| 618 | |
| 619 | /* interface created in firmware */ |
| 620 | ifp = vif->ifp; |
| 621 | if (!ifp) { |
| 622 | brcmf_err("no if pointer provided\n"); |
| 623 | err = -ENOENT; |
| 624 | goto fail; |
| 625 | } |
| 626 | |
| 627 | strncpy(ifp->ndev->name, name, sizeof(ifp->ndev->name) - 1); |
| 628 | err = brcmf_net_attach(ifp, true); |
| 629 | if (err) { |
| 630 | brcmf_err("Registering netdevice failed\n"); |
| 631 | goto fail; |
| 632 | } |
| 633 | |
| 634 | return &ifp->vif->wdev; |
| 635 | |
| 636 | fail: |
| 637 | brcmf_free_vif(vif); |
| 638 | return ERR_PTR(err); |
| 639 | } |
| 640 | |
Arend van Spriel | 967fe2c | 2014-03-15 17:18:21 +0100 | [diff] [blame] | 641 | static bool brcmf_is_apmode(struct brcmf_cfg80211_vif *vif) |
| 642 | { |
| 643 | enum nl80211_iftype iftype; |
| 644 | |
| 645 | iftype = vif->wdev.iftype; |
| 646 | return iftype == NL80211_IFTYPE_AP || iftype == NL80211_IFTYPE_P2P_GO; |
| 647 | } |
| 648 | |
| 649 | static bool brcmf_is_ibssmode(struct brcmf_cfg80211_vif *vif) |
| 650 | { |
| 651 | return vif->wdev.iftype == NL80211_IFTYPE_ADHOC; |
| 652 | } |
| 653 | |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 654 | static struct wireless_dev *brcmf_cfg80211_add_iface(struct wiphy *wiphy, |
| 655 | const char *name, |
Tom Gundersen | 6bab2e19 | 2015-03-18 11:13:39 +0100 | [diff] [blame] | 656 | unsigned char name_assign_type, |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 657 | enum nl80211_iftype type, |
| 658 | u32 *flags, |
| 659 | struct vif_params *params) |
| 660 | { |
Hante Meuleman | 8851cce | 2014-07-30 13:20:02 +0200 | [diff] [blame] | 661 | struct wireless_dev *wdev; |
Arend van Spriel | 39504a2 | 2015-08-20 22:06:05 +0200 | [diff] [blame] | 662 | int err; |
Hante Meuleman | 8851cce | 2014-07-30 13:20:02 +0200 | [diff] [blame] | 663 | |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 664 | brcmf_dbg(TRACE, "enter: %s type %d\n", name, type); |
Arend van Spriel | 39504a2 | 2015-08-20 22:06:05 +0200 | [diff] [blame] | 665 | err = brcmf_vif_add_validate(wiphy_to_cfg(wiphy), type); |
| 666 | if (err) { |
| 667 | brcmf_err("iface validation failed: err=%d\n", err); |
| 668 | return ERR_PTR(err); |
| 669 | } |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 670 | switch (type) { |
| 671 | case NL80211_IFTYPE_ADHOC: |
| 672 | case NL80211_IFTYPE_STATION: |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 673 | case NL80211_IFTYPE_AP_VLAN: |
| 674 | case NL80211_IFTYPE_WDS: |
| 675 | case NL80211_IFTYPE_MONITOR: |
| 676 | case NL80211_IFTYPE_MESH_POINT: |
| 677 | return ERR_PTR(-EOPNOTSUPP); |
Hante Meuleman | a44aa40 | 2014-12-03 21:05:33 +0100 | [diff] [blame] | 678 | case NL80211_IFTYPE_AP: |
| 679 | wdev = brcmf_ap_add_vif(wiphy, name, flags, params); |
Rafał Miłecki | 0cd33c2 | 2016-05-27 10:54:28 +0200 | [diff] [blame] | 680 | break; |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 681 | case NL80211_IFTYPE_P2P_CLIENT: |
| 682 | case NL80211_IFTYPE_P2P_GO: |
Arend van Spriel | 27f10e3 | 2013-04-05 10:57:50 +0200 | [diff] [blame] | 683 | case NL80211_IFTYPE_P2P_DEVICE: |
Tom Gundersen | 6bab2e19 | 2015-03-18 11:13:39 +0100 | [diff] [blame] | 684 | wdev = brcmf_p2p_add_vif(wiphy, name, name_assign_type, type, flags, params); |
Rafał Miłecki | 0cd33c2 | 2016-05-27 10:54:28 +0200 | [diff] [blame] | 685 | break; |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 686 | case NL80211_IFTYPE_UNSPECIFIED: |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 687 | default: |
| 688 | return ERR_PTR(-EINVAL); |
| 689 | } |
Rafał Miłecki | 0cd33c2 | 2016-05-27 10:54:28 +0200 | [diff] [blame] | 690 | |
| 691 | if (IS_ERR(wdev)) |
| 692 | brcmf_err("add iface %s type %d failed: err=%d\n", |
| 693 | name, type, (int)PTR_ERR(wdev)); |
| 694 | else |
| 695 | brcmf_cfg80211_update_proto_addr_mode(wdev); |
| 696 | |
| 697 | return wdev; |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 698 | } |
| 699 | |
Daniel Kim | 5e787f7 | 2014-06-21 12:11:18 +0200 | [diff] [blame] | 700 | static void brcmf_scan_config_mpc(struct brcmf_if *ifp, int mpc) |
| 701 | { |
Arend van Spriel | c08437b | 2014-07-12 08:49:39 +0200 | [diff] [blame] | 702 | if (brcmf_feat_is_quirk_enabled(ifp, BRCMF_FEAT_QUIRK_NEED_MPC)) |
Daniel Kim | 5e787f7 | 2014-06-21 12:11:18 +0200 | [diff] [blame] | 703 | brcmf_set_mpc(ifp, mpc); |
| 704 | } |
| 705 | |
Arend van Spriel | f96aa07 | 2013-04-05 10:57:48 +0200 | [diff] [blame] | 706 | void brcmf_set_mpc(struct brcmf_if *ifp, int mpc) |
Arend van Spriel | 5f4f9f1 | 2013-02-08 15:53:41 +0100 | [diff] [blame] | 707 | { |
Arend van Spriel | 5f4f9f1 | 2013-02-08 15:53:41 +0100 | [diff] [blame] | 708 | s32 err = 0; |
| 709 | |
| 710 | if (check_vif_up(ifp->vif)) { |
| 711 | err = brcmf_fil_iovar_int_set(ifp, "mpc", mpc); |
| 712 | if (err) { |
| 713 | brcmf_err("fail to set mpc\n"); |
| 714 | return; |
| 715 | } |
| 716 | brcmf_dbg(INFO, "MPC : %d\n", mpc); |
| 717 | } |
| 718 | } |
| 719 | |
Arend van Spriel | a0f472a | 2013-04-05 10:57:49 +0200 | [diff] [blame] | 720 | s32 brcmf_notify_escan_complete(struct brcmf_cfg80211_info *cfg, |
| 721 | struct brcmf_if *ifp, bool aborted, |
| 722 | bool fw_abort) |
Arend van Spriel | 5f4f9f1 | 2013-02-08 15:53:41 +0100 | [diff] [blame] | 723 | { |
| 724 | struct brcmf_scan_params_le params_le; |
| 725 | struct cfg80211_scan_request *scan_request; |
| 726 | s32 err = 0; |
| 727 | |
| 728 | brcmf_dbg(SCAN, "Enter\n"); |
| 729 | |
| 730 | /* clear scan request, because the FW abort can cause a second call */ |
| 731 | /* to this functon and might cause a double cfg80211_scan_done */ |
| 732 | scan_request = cfg->scan_request; |
| 733 | cfg->scan_request = NULL; |
| 734 | |
| 735 | if (timer_pending(&cfg->escan_timeout)) |
| 736 | del_timer_sync(&cfg->escan_timeout); |
| 737 | |
| 738 | if (fw_abort) { |
| 739 | /* Do a scan abort to stop the driver's scan engine */ |
| 740 | brcmf_dbg(SCAN, "ABORT scan in firmware\n"); |
| 741 | memset(¶ms_le, 0, sizeof(params_le)); |
Joe Perches | 93803b3 | 2015-03-02 19:54:49 -0800 | [diff] [blame] | 742 | eth_broadcast_addr(params_le.bssid); |
Arend van Spriel | 5f4f9f1 | 2013-02-08 15:53:41 +0100 | [diff] [blame] | 743 | params_le.bss_type = DOT11_BSSTYPE_ANY; |
| 744 | params_le.scan_type = 0; |
| 745 | params_le.channel_num = cpu_to_le32(1); |
| 746 | params_le.nprobes = cpu_to_le32(1); |
| 747 | params_le.active_time = cpu_to_le32(-1); |
| 748 | params_le.passive_time = cpu_to_le32(-1); |
| 749 | params_le.home_time = cpu_to_le32(-1); |
| 750 | /* Scan is aborted by setting channel_list[0] to -1 */ |
| 751 | params_le.channel_list[0] = cpu_to_le16(-1); |
| 752 | /* E-Scan (or anyother type) can be aborted by SCAN */ |
Arend van Spriel | f96aa07 | 2013-04-05 10:57:48 +0200 | [diff] [blame] | 753 | err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SCAN, |
Arend van Spriel | 5f4f9f1 | 2013-02-08 15:53:41 +0100 | [diff] [blame] | 754 | ¶ms_le, sizeof(params_le)); |
| 755 | if (err) |
| 756 | brcmf_err("Scan abort failed\n"); |
| 757 | } |
Arend van Spriel | 0f0fe99 | 2014-05-27 12:56:14 +0200 | [diff] [blame] | 758 | |
Daniel Kim | 5e787f7 | 2014-06-21 12:11:18 +0200 | [diff] [blame] | 759 | brcmf_scan_config_mpc(ifp, 1); |
Arend van Spriel | 0f0fe99 | 2014-05-27 12:56:14 +0200 | [diff] [blame] | 760 | |
Arend van Spriel | 5f4f9f1 | 2013-02-08 15:53:41 +0100 | [diff] [blame] | 761 | /* |
Arend Van Spriel | fa85b30 | 2016-11-23 10:25:25 +0000 | [diff] [blame] | 762 | * e-scan can be initiated internally |
Arend van Spriel | 5f4f9f1 | 2013-02-08 15:53:41 +0100 | [diff] [blame] | 763 | * which takes precedence. |
| 764 | */ |
Arend Van Spriel | fa85b30 | 2016-11-23 10:25:25 +0000 | [diff] [blame] | 765 | if (cfg->internal_escan) { |
Arend van Spriel | 5f4f9f1 | 2013-02-08 15:53:41 +0100 | [diff] [blame] | 766 | brcmf_dbg(SCAN, "scheduled scan completed\n"); |
Arend Van Spriel | fa85b30 | 2016-11-23 10:25:25 +0000 | [diff] [blame] | 767 | cfg->internal_escan = false; |
Arend van Spriel | 5f4f9f1 | 2013-02-08 15:53:41 +0100 | [diff] [blame] | 768 | if (!aborted) |
| 769 | cfg80211_sched_scan_results(cfg_to_wiphy(cfg)); |
Arend van Spriel | 5f4f9f1 | 2013-02-08 15:53:41 +0100 | [diff] [blame] | 770 | } else if (scan_request) { |
Avraham Stern | 1d76250 | 2016-07-05 17:10:13 +0300 | [diff] [blame] | 771 | struct cfg80211_scan_info info = { |
| 772 | .aborted = aborted, |
| 773 | }; |
| 774 | |
Arend van Spriel | 5f4f9f1 | 2013-02-08 15:53:41 +0100 | [diff] [blame] | 775 | brcmf_dbg(SCAN, "ESCAN Completed scan: %s\n", |
| 776 | aborted ? "Aborted" : "Done"); |
Avraham Stern | 1d76250 | 2016-07-05 17:10:13 +0300 | [diff] [blame] | 777 | cfg80211_scan_done(scan_request, &info); |
Arend van Spriel | 5f4f9f1 | 2013-02-08 15:53:41 +0100 | [diff] [blame] | 778 | } |
Hante Meuleman | 6eda4e2 | 2013-02-08 15:54:02 +0100 | [diff] [blame] | 779 | if (!test_and_clear_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status)) |
| 780 | brcmf_dbg(SCAN, "Scan complete, probably P2P scan\n"); |
Arend van Spriel | 5f4f9f1 | 2013-02-08 15:53:41 +0100 | [diff] [blame] | 781 | |
| 782 | return err; |
| 783 | } |
| 784 | |
Rafał Miłecki | dba8fbc | 2016-06-29 21:54:27 +0200 | [diff] [blame] | 785 | static int brcmf_cfg80211_del_ap_iface(struct wiphy *wiphy, |
| 786 | struct wireless_dev *wdev) |
| 787 | { |
| 788 | struct brcmf_cfg80211_info *cfg = wiphy_priv(wiphy); |
| 789 | struct net_device *ndev = wdev->netdev; |
| 790 | struct brcmf_if *ifp = netdev_priv(ndev); |
| 791 | int ret; |
| 792 | int err; |
| 793 | |
| 794 | brcmf_cfg80211_arm_vif_event(cfg, ifp->vif); |
| 795 | |
| 796 | err = brcmf_fil_bsscfg_data_set(ifp, "interface_remove", NULL, 0); |
| 797 | if (err) { |
| 798 | brcmf_err("interface_remove failed %d\n", err); |
| 799 | goto err_unarm; |
| 800 | } |
| 801 | |
| 802 | /* wait for firmware event */ |
| 803 | ret = brcmf_cfg80211_wait_vif_event(cfg, BRCMF_E_IF_DEL, |
| 804 | BRCMF_VIF_EVENT_TIMEOUT); |
| 805 | if (!ret) { |
| 806 | brcmf_err("timeout occurred\n"); |
| 807 | err = -EIO; |
| 808 | goto err_unarm; |
| 809 | } |
| 810 | |
| 811 | brcmf_remove_interface(ifp, true); |
| 812 | |
| 813 | err_unarm: |
| 814 | brcmf_cfg80211_arm_vif_event(cfg, NULL); |
| 815 | return err; |
| 816 | } |
| 817 | |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 818 | static |
| 819 | int brcmf_cfg80211_del_iface(struct wiphy *wiphy, struct wireless_dev *wdev) |
| 820 | { |
Arend van Spriel | 5f4f9f1 | 2013-02-08 15:53:41 +0100 | [diff] [blame] | 821 | struct brcmf_cfg80211_info *cfg = wiphy_priv(wiphy); |
| 822 | struct net_device *ndev = wdev->netdev; |
| 823 | |
Rafał Miłecki | dba8fbc | 2016-06-29 21:54:27 +0200 | [diff] [blame] | 824 | if (ndev && ndev == cfg_to_ndev(cfg)) |
| 825 | return -ENOTSUPP; |
| 826 | |
Arend van Spriel | 5f4f9f1 | 2013-02-08 15:53:41 +0100 | [diff] [blame] | 827 | /* vif event pending in firmware */ |
| 828 | if (brcmf_cfg80211_vif_event_armed(cfg)) |
| 829 | return -EBUSY; |
| 830 | |
| 831 | if (ndev) { |
| 832 | if (test_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status) && |
Arend van Spriel | a0f472a | 2013-04-05 10:57:49 +0200 | [diff] [blame] | 833 | cfg->escan_info.ifp == netdev_priv(ndev)) |
| 834 | brcmf_notify_escan_complete(cfg, netdev_priv(ndev), |
| 835 | true, true); |
Arend van Spriel | 5f4f9f1 | 2013-02-08 15:53:41 +0100 | [diff] [blame] | 836 | |
| 837 | brcmf_fil_iovar_int_set(netdev_priv(ndev), "mpc", 1); |
| 838 | } |
| 839 | |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 840 | switch (wdev->iftype) { |
| 841 | case NL80211_IFTYPE_ADHOC: |
| 842 | case NL80211_IFTYPE_STATION: |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 843 | case NL80211_IFTYPE_AP_VLAN: |
| 844 | case NL80211_IFTYPE_WDS: |
| 845 | case NL80211_IFTYPE_MONITOR: |
| 846 | case NL80211_IFTYPE_MESH_POINT: |
| 847 | return -EOPNOTSUPP; |
Rafał Miłecki | dba8fbc | 2016-06-29 21:54:27 +0200 | [diff] [blame] | 848 | case NL80211_IFTYPE_AP: |
| 849 | return brcmf_cfg80211_del_ap_iface(wiphy, wdev); |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 850 | case NL80211_IFTYPE_P2P_CLIENT: |
| 851 | case NL80211_IFTYPE_P2P_GO: |
Arend van Spriel | 27f10e3 | 2013-04-05 10:57:50 +0200 | [diff] [blame] | 852 | case NL80211_IFTYPE_P2P_DEVICE: |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 853 | return brcmf_p2p_del_vif(wiphy, wdev); |
| 854 | case NL80211_IFTYPE_UNSPECIFIED: |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 855 | default: |
| 856 | return -EINVAL; |
| 857 | } |
| 858 | return -EOPNOTSUPP; |
| 859 | } |
| 860 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 861 | static s32 |
| 862 | brcmf_cfg80211_change_iface(struct wiphy *wiphy, struct net_device *ndev, |
| 863 | enum nl80211_iftype type, u32 *flags, |
| 864 | struct vif_params *params) |
| 865 | { |
Hante Meuleman | 7a5c1f6 | 2013-02-08 15:53:44 +0100 | [diff] [blame] | 866 | struct brcmf_cfg80211_info *cfg = wiphy_priv(wiphy); |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 867 | struct brcmf_if *ifp = netdev_priv(ndev); |
Arend van Spriel | 128ce3b | 2012-11-28 21:44:12 +0100 | [diff] [blame] | 868 | struct brcmf_cfg80211_vif *vif = ifp->vif; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 869 | s32 infra = 0; |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 870 | s32 ap = 0; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 871 | s32 err = 0; |
| 872 | |
Hante Meuleman | 37a869e | 2015-10-29 20:33:17 +0100 | [diff] [blame] | 873 | brcmf_dbg(TRACE, "Enter, bsscfgidx=%d, type=%d\n", ifp->bsscfgidx, |
| 874 | type); |
Hante Meuleman | 178e9ef | 2015-09-18 22:08:11 +0200 | [diff] [blame] | 875 | |
| 876 | /* WAR: There are a number of p2p interface related problems which |
| 877 | * need to be handled initially (before doing the validate). |
| 878 | * wpa_supplicant tends to do iface changes on p2p device/client/go |
| 879 | * which are not always possible/allowed. However we need to return |
| 880 | * OK otherwise the wpa_supplicant wont start. The situation differs |
| 881 | * on configuration and setup (p2pon=1 module param). The first check |
| 882 | * is to see if the request is a change to station for p2p iface. |
| 883 | */ |
| 884 | if ((type == NL80211_IFTYPE_STATION) && |
| 885 | ((vif->wdev.iftype == NL80211_IFTYPE_P2P_CLIENT) || |
| 886 | (vif->wdev.iftype == NL80211_IFTYPE_P2P_GO) || |
| 887 | (vif->wdev.iftype == NL80211_IFTYPE_P2P_DEVICE))) { |
| 888 | brcmf_dbg(TRACE, "Ignoring cmd for p2p if\n"); |
| 889 | /* Now depending on whether module param p2pon=1 was used the |
| 890 | * response needs to be either 0 or EOPNOTSUPP. The reason is |
| 891 | * that if p2pon=1 is used, but a newer supplicant is used then |
| 892 | * we should return an error, as this combination wont work. |
| 893 | * In other situations 0 is returned and supplicant will start |
| 894 | * normally. It will give a trace in cfg80211, but it is the |
| 895 | * only way to get it working. Unfortunately this will result |
| 896 | * in situation where we wont support new supplicant in |
| 897 | * combination with module param p2pon=1, but that is the way |
| 898 | * it is. If the user tries this then unloading of driver might |
| 899 | * fail/lock. |
| 900 | */ |
| 901 | if (cfg->p2p.p2pdev_dynamically) |
| 902 | return -EOPNOTSUPP; |
| 903 | else |
| 904 | return 0; |
| 905 | } |
Arend van Spriel | 39504a2 | 2015-08-20 22:06:05 +0200 | [diff] [blame] | 906 | err = brcmf_vif_change_validate(wiphy_to_cfg(wiphy), vif, type); |
| 907 | if (err) { |
| 908 | brcmf_err("iface validation failed: err=%d\n", err); |
| 909 | return err; |
| 910 | } |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 911 | switch (type) { |
| 912 | case NL80211_IFTYPE_MONITOR: |
| 913 | case NL80211_IFTYPE_WDS: |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 914 | brcmf_err("type (%d) : currently we do not support this type\n", |
| 915 | type); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 916 | return -EOPNOTSUPP; |
| 917 | case NL80211_IFTYPE_ADHOC: |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 918 | infra = 0; |
| 919 | break; |
| 920 | case NL80211_IFTYPE_STATION: |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 921 | infra = 1; |
| 922 | break; |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 923 | case NL80211_IFTYPE_AP: |
Hante Meuleman | 7a5c1f6 | 2013-02-08 15:53:44 +0100 | [diff] [blame] | 924 | case NL80211_IFTYPE_P2P_GO: |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 925 | ap = 1; |
| 926 | break; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 927 | default: |
| 928 | err = -EINVAL; |
| 929 | goto done; |
| 930 | } |
| 931 | |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 932 | if (ap) { |
Hante Meuleman | 7a5c1f6 | 2013-02-08 15:53:44 +0100 | [diff] [blame] | 933 | if (type == NL80211_IFTYPE_P2P_GO) { |
| 934 | brcmf_dbg(INFO, "IF Type = P2P GO\n"); |
| 935 | err = brcmf_p2p_ifchange(cfg, BRCMF_FIL_P2P_IF_GO); |
| 936 | } |
| 937 | if (!err) { |
Hante Meuleman | 7a5c1f6 | 2013-02-08 15:53:44 +0100 | [diff] [blame] | 938 | brcmf_dbg(INFO, "IF Type = AP\n"); |
| 939 | } |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 940 | } else { |
Arend van Spriel | 128ce3b | 2012-11-28 21:44:12 +0100 | [diff] [blame] | 941 | err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_INFRA, infra); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 942 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 943 | brcmf_err("WLC_SET_INFRA error (%d)\n", err); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 944 | err = -EAGAIN; |
| 945 | goto done; |
| 946 | } |
Arend van Spriel | 967fe2c | 2014-03-15 17:18:21 +0100 | [diff] [blame] | 947 | brcmf_dbg(INFO, "IF Type = %s\n", brcmf_is_ibssmode(vif) ? |
Arend van Spriel | 647c9ae | 2012-12-05 15:26:01 +0100 | [diff] [blame] | 948 | "Adhoc" : "Infra"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 949 | } |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 950 | ndev->ieee80211_ptr->iftype = type; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 951 | |
Hante Meuleman | 8851cce | 2014-07-30 13:20:02 +0200 | [diff] [blame] | 952 | brcmf_cfg80211_update_proto_addr_mode(&vif->wdev); |
| 953 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 954 | done: |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 955 | brcmf_dbg(TRACE, "Exit\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 956 | |
| 957 | return err; |
| 958 | } |
| 959 | |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 960 | static void brcmf_escan_prep(struct brcmf_cfg80211_info *cfg, |
| 961 | struct brcmf_scan_params_le *params_le, |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 962 | struct cfg80211_scan_request *request) |
| 963 | { |
| 964 | u32 n_ssids; |
| 965 | u32 n_channels; |
| 966 | s32 i; |
| 967 | s32 offset; |
Arend van Spriel | 029591f | 2012-09-19 22:21:06 +0200 | [diff] [blame] | 968 | u16 chanspec; |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 969 | char *ptr; |
Arend van Spriel | 029591f | 2012-09-19 22:21:06 +0200 | [diff] [blame] | 970 | struct brcmf_ssid_le ssid_le; |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 971 | |
Joe Perches | 93803b3 | 2015-03-02 19:54:49 -0800 | [diff] [blame] | 972 | eth_broadcast_addr(params_le->bssid); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 973 | params_le->bss_type = DOT11_BSSTYPE_ANY; |
| 974 | params_le->scan_type = 0; |
| 975 | params_le->channel_num = 0; |
| 976 | params_le->nprobes = cpu_to_le32(-1); |
| 977 | params_le->active_time = cpu_to_le32(-1); |
| 978 | params_le->passive_time = cpu_to_le32(-1); |
| 979 | params_le->home_time = cpu_to_le32(-1); |
| 980 | memset(¶ms_le->ssid_le, 0, sizeof(params_le->ssid_le)); |
| 981 | |
| 982 | /* if request is null exit so it will be all channel broadcast scan */ |
| 983 | if (!request) |
| 984 | return; |
| 985 | |
| 986 | n_ssids = request->n_ssids; |
| 987 | n_channels = request->n_channels; |
| 988 | /* Copy channel array if applicable */ |
Arend van Spriel | 4e8a008 | 2012-12-05 15:26:03 +0100 | [diff] [blame] | 989 | brcmf_dbg(SCAN, "### List of channelspecs to scan ### %d\n", |
| 990 | n_channels); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 991 | if (n_channels > 0) { |
| 992 | for (i = 0; i < n_channels; i++) { |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 993 | chanspec = channel_to_chanspec(&cfg->d11inf, |
| 994 | request->channels[i]); |
Arend van Spriel | 4e8a008 | 2012-12-05 15:26:03 +0100 | [diff] [blame] | 995 | brcmf_dbg(SCAN, "Chan : %d, Channel spec: %x\n", |
| 996 | request->channels[i]->hw_value, chanspec); |
Arend van Spriel | 029591f | 2012-09-19 22:21:06 +0200 | [diff] [blame] | 997 | params_le->channel_list[i] = cpu_to_le16(chanspec); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 998 | } |
| 999 | } else { |
Arend van Spriel | 4e8a008 | 2012-12-05 15:26:03 +0100 | [diff] [blame] | 1000 | brcmf_dbg(SCAN, "Scanning all channels\n"); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1001 | } |
| 1002 | /* Copy ssid array if applicable */ |
Arend van Spriel | 4e8a008 | 2012-12-05 15:26:03 +0100 | [diff] [blame] | 1003 | brcmf_dbg(SCAN, "### List of SSIDs to scan ### %d\n", n_ssids); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1004 | if (n_ssids > 0) { |
| 1005 | offset = offsetof(struct brcmf_scan_params_le, channel_list) + |
| 1006 | n_channels * sizeof(u16); |
| 1007 | offset = roundup(offset, sizeof(u32)); |
| 1008 | ptr = (char *)params_le + offset; |
| 1009 | for (i = 0; i < n_ssids; i++) { |
Arend van Spriel | 029591f | 2012-09-19 22:21:06 +0200 | [diff] [blame] | 1010 | memset(&ssid_le, 0, sizeof(ssid_le)); |
| 1011 | ssid_le.SSID_len = |
| 1012 | cpu_to_le32(request->ssids[i].ssid_len); |
| 1013 | memcpy(ssid_le.SSID, request->ssids[i].ssid, |
| 1014 | request->ssids[i].ssid_len); |
| 1015 | if (!ssid_le.SSID_len) |
Arend van Spriel | 4e8a008 | 2012-12-05 15:26:03 +0100 | [diff] [blame] | 1016 | brcmf_dbg(SCAN, "%d: Broadcast scan\n", i); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1017 | else |
Arend van Spriel | 4e8a008 | 2012-12-05 15:26:03 +0100 | [diff] [blame] | 1018 | brcmf_dbg(SCAN, "%d: scan for %s size =%d\n", |
| 1019 | i, ssid_le.SSID, ssid_le.SSID_len); |
Arend van Spriel | 029591f | 2012-09-19 22:21:06 +0200 | [diff] [blame] | 1020 | memcpy(ptr, &ssid_le, sizeof(ssid_le)); |
| 1021 | ptr += sizeof(ssid_le); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1022 | } |
| 1023 | } else { |
Arend van Spriel | 4e8a008 | 2012-12-05 15:26:03 +0100 | [diff] [blame] | 1024 | brcmf_dbg(SCAN, "Broadcast scan %p\n", request->ssids); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1025 | if ((request->ssids) && request->ssids->ssid_len) { |
Arend van Spriel | 4e8a008 | 2012-12-05 15:26:03 +0100 | [diff] [blame] | 1026 | brcmf_dbg(SCAN, "SSID %s len=%d\n", |
| 1027 | params_le->ssid_le.SSID, |
| 1028 | request->ssids->ssid_len); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1029 | params_le->ssid_le.SSID_len = |
| 1030 | cpu_to_le32(request->ssids->ssid_len); |
| 1031 | memcpy(¶ms_le->ssid_le.SSID, request->ssids->ssid, |
| 1032 | request->ssids->ssid_len); |
| 1033 | } |
| 1034 | } |
| 1035 | /* Adding mask to channel numbers */ |
| 1036 | params_le->channel_num = |
| 1037 | cpu_to_le32((n_ssids << BRCMF_SCAN_PARAMS_NSSID_SHIFT) | |
| 1038 | (n_channels & BRCMF_SCAN_PARAMS_COUNT_MASK)); |
| 1039 | } |
| 1040 | |
| 1041 | static s32 |
Arend van Spriel | a0f472a | 2013-04-05 10:57:49 +0200 | [diff] [blame] | 1042 | brcmf_run_escan(struct brcmf_cfg80211_info *cfg, struct brcmf_if *ifp, |
Hante Meuleman | c495810 | 2015-11-25 11:32:41 +0100 | [diff] [blame] | 1043 | struct cfg80211_scan_request *request) |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1044 | { |
| 1045 | s32 params_size = BRCMF_SCAN_PARAMS_FIXED_SIZE + |
| 1046 | offsetof(struct brcmf_escan_params_le, params_le); |
| 1047 | struct brcmf_escan_params_le *params; |
| 1048 | s32 err = 0; |
| 1049 | |
Arend van Spriel | 4e8a008 | 2012-12-05 15:26:03 +0100 | [diff] [blame] | 1050 | brcmf_dbg(SCAN, "E-SCAN START\n"); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1051 | |
| 1052 | if (request != NULL) { |
| 1053 | /* Allocate space for populating ssids in struct */ |
| 1054 | params_size += sizeof(u32) * ((request->n_channels + 1) / 2); |
| 1055 | |
| 1056 | /* Allocate space for populating ssids in struct */ |
Hante Meuleman | e9a6ca8 | 2015-11-25 11:32:37 +0100 | [diff] [blame] | 1057 | params_size += sizeof(struct brcmf_ssid_le) * request->n_ssids; |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1058 | } |
| 1059 | |
| 1060 | params = kzalloc(params_size, GFP_KERNEL); |
| 1061 | if (!params) { |
| 1062 | err = -ENOMEM; |
| 1063 | goto exit; |
| 1064 | } |
| 1065 | BUG_ON(params_size + sizeof("escan") >= BRCMF_DCMD_MEDLEN); |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 1066 | brcmf_escan_prep(cfg, ¶ms->params_le, request); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1067 | params->version = cpu_to_le32(BRCMF_ESCAN_REQ_VERSION); |
Hante Meuleman | c495810 | 2015-11-25 11:32:41 +0100 | [diff] [blame] | 1068 | params->action = cpu_to_le16(WL_ESCAN_ACTION_START); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1069 | params->sync_id = cpu_to_le16(0x1234); |
| 1070 | |
Arend van Spriel | a0f472a | 2013-04-05 10:57:49 +0200 | [diff] [blame] | 1071 | err = brcmf_fil_iovar_data_set(ifp, "escan", params, params_size); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1072 | if (err) { |
| 1073 | if (err == -EBUSY) |
Arend van Spriel | 647c9ae | 2012-12-05 15:26:01 +0100 | [diff] [blame] | 1074 | brcmf_dbg(INFO, "system busy : escan canceled\n"); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1075 | else |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1076 | brcmf_err("error (%d)\n", err); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1077 | } |
| 1078 | |
| 1079 | kfree(params); |
| 1080 | exit: |
| 1081 | return err; |
| 1082 | } |
| 1083 | |
| 1084 | static s32 |
Arend Van Spriel | ab5981c | 2016-11-23 10:25:24 +0000 | [diff] [blame] | 1085 | brcmf_do_escan(struct brcmf_if *ifp, struct cfg80211_scan_request *request) |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1086 | { |
Arend Van Spriel | ab5981c | 2016-11-23 10:25:24 +0000 | [diff] [blame] | 1087 | struct brcmf_cfg80211_info *cfg = ifp->drvr->config; |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1088 | s32 err; |
Hante Meuleman | 81f5dcb | 2012-10-22 10:36:14 -0700 | [diff] [blame] | 1089 | u32 passive_scan; |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1090 | struct brcmf_scan_results *results; |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 1091 | struct escan_info *escan = &cfg->escan_info; |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1092 | |
Arend van Spriel | 4e8a008 | 2012-12-05 15:26:03 +0100 | [diff] [blame] | 1093 | brcmf_dbg(SCAN, "Enter\n"); |
Arend van Spriel | a0f472a | 2013-04-05 10:57:49 +0200 | [diff] [blame] | 1094 | escan->ifp = ifp; |
Arend Van Spriel | ab5981c | 2016-11-23 10:25:24 +0000 | [diff] [blame] | 1095 | escan->wiphy = cfg->wiphy; |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 1096 | escan->escan_state = WL_ESCAN_STATE_SCANNING; |
Hante Meuleman | 81f5dcb | 2012-10-22 10:36:14 -0700 | [diff] [blame] | 1097 | passive_scan = cfg->active_scan ? 0 : 1; |
Arend van Spriel | f96aa07 | 2013-04-05 10:57:48 +0200 | [diff] [blame] | 1098 | err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_PASSIVE_SCAN, |
Hante Meuleman | 81f5dcb | 2012-10-22 10:36:14 -0700 | [diff] [blame] | 1099 | passive_scan); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1100 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1101 | brcmf_err("error (%d)\n", err); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1102 | return err; |
| 1103 | } |
Daniel Kim | 5e787f7 | 2014-06-21 12:11:18 +0200 | [diff] [blame] | 1104 | brcmf_scan_config_mpc(ifp, 0); |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 1105 | results = (struct brcmf_scan_results *)cfg->escan_info.escan_buf; |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1106 | results->version = 0; |
| 1107 | results->count = 0; |
| 1108 | results->buflen = WL_ESCAN_RESULTS_FIXED_SIZE; |
| 1109 | |
Hante Meuleman | c495810 | 2015-11-25 11:32:41 +0100 | [diff] [blame] | 1110 | err = escan->run(cfg, ifp, request); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1111 | if (err) |
Daniel Kim | 5e787f7 | 2014-06-21 12:11:18 +0200 | [diff] [blame] | 1112 | brcmf_scan_config_mpc(ifp, 1); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1113 | return err; |
| 1114 | } |
| 1115 | |
| 1116 | static s32 |
Arend van Spriel | a0f472a | 2013-04-05 10:57:49 +0200 | [diff] [blame] | 1117 | brcmf_cfg80211_escan(struct wiphy *wiphy, struct brcmf_cfg80211_vif *vif, |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1118 | struct cfg80211_scan_request *request, |
| 1119 | struct cfg80211_ssid *this_ssid) |
| 1120 | { |
Arend van Spriel | a0f472a | 2013-04-05 10:57:49 +0200 | [diff] [blame] | 1121 | struct brcmf_if *ifp = vif->ifp; |
| 1122 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1123 | struct cfg80211_ssid *ssids; |
Hante Meuleman | 81f5dcb | 2012-10-22 10:36:14 -0700 | [diff] [blame] | 1124 | u32 passive_scan; |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1125 | bool escan_req; |
| 1126 | bool spec_scan; |
| 1127 | s32 err; |
Hante Meuleman | 675f5d8 | 2015-12-10 13:43:01 +0100 | [diff] [blame] | 1128 | struct brcmf_ssid_le ssid_le; |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1129 | u32 SSID_len; |
| 1130 | |
Arend van Spriel | 4e8a008 | 2012-12-05 15:26:03 +0100 | [diff] [blame] | 1131 | brcmf_dbg(SCAN, "START ESCAN\n"); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1132 | |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 1133 | if (test_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status)) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1134 | brcmf_err("Scanning already: status (%lu)\n", cfg->scan_status); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1135 | return -EAGAIN; |
| 1136 | } |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 1137 | if (test_bit(BRCMF_SCAN_STATUS_ABORT, &cfg->scan_status)) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1138 | brcmf_err("Scanning being aborted: status (%lu)\n", |
| 1139 | cfg->scan_status); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1140 | return -EAGAIN; |
| 1141 | } |
Arend van Spriel | 1687eee | 2013-04-23 12:53:11 +0200 | [diff] [blame] | 1142 | if (test_bit(BRCMF_SCAN_STATUS_SUPPRESS, &cfg->scan_status)) { |
| 1143 | brcmf_err("Scanning suppressed: status (%lu)\n", |
| 1144 | cfg->scan_status); |
| 1145 | return -EAGAIN; |
| 1146 | } |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 1147 | if (test_bit(BRCMF_VIF_STATUS_CONNECTING, &ifp->vif->sme_state)) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1148 | brcmf_err("Connecting: status (%lu)\n", ifp->vif->sme_state); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1149 | return -EAGAIN; |
| 1150 | } |
| 1151 | |
Hante Meuleman | 0f8ffe1 | 2013-02-08 15:53:42 +0100 | [diff] [blame] | 1152 | /* If scan req comes for p2p0, send it over primary I/F */ |
Arend van Spriel | a0f472a | 2013-04-05 10:57:49 +0200 | [diff] [blame] | 1153 | if (vif == cfg->p2p.bss_idx[P2PAPI_BSSCFG_DEVICE].vif) |
| 1154 | vif = cfg->p2p.bss_idx[P2PAPI_BSSCFG_PRIMARY].vif; |
Hante Meuleman | 0f8ffe1 | 2013-02-08 15:53:42 +0100 | [diff] [blame] | 1155 | |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1156 | escan_req = false; |
| 1157 | if (request) { |
| 1158 | /* scan bss */ |
| 1159 | ssids = request->ssids; |
| 1160 | escan_req = true; |
| 1161 | } else { |
| 1162 | /* scan in ibss */ |
| 1163 | /* we don't do escan in ibss */ |
| 1164 | ssids = this_ssid; |
| 1165 | } |
| 1166 | |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 1167 | cfg->scan_request = request; |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 1168 | set_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1169 | if (escan_req) { |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 1170 | cfg->escan_info.run = brcmf_run_escan; |
Arend van Spriel | a0f472a | 2013-04-05 10:57:49 +0200 | [diff] [blame] | 1171 | err = brcmf_p2p_scan_prep(wiphy, request, vif); |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 1172 | if (err) |
| 1173 | goto scan_out; |
| 1174 | |
Arend Van Spriel | ab5981c | 2016-11-23 10:25:24 +0000 | [diff] [blame] | 1175 | err = brcmf_do_escan(vif->ifp, request); |
Arend van Spriel | 2cb941c | 2012-11-05 16:22:10 -0800 | [diff] [blame] | 1176 | if (err) |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1177 | goto scan_out; |
| 1178 | } else { |
Arend van Spriel | 4e8a008 | 2012-12-05 15:26:03 +0100 | [diff] [blame] | 1179 | brcmf_dbg(SCAN, "ssid \"%s\", ssid_len (%d)\n", |
| 1180 | ssids->ssid, ssids->ssid_len); |
Hante Meuleman | 675f5d8 | 2015-12-10 13:43:01 +0100 | [diff] [blame] | 1181 | memset(&ssid_le, 0, sizeof(ssid_le)); |
| 1182 | SSID_len = min_t(u8, sizeof(ssid_le.SSID), ssids->ssid_len); |
| 1183 | ssid_le.SSID_len = cpu_to_le32(0); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1184 | spec_scan = false; |
| 1185 | if (SSID_len) { |
Hante Meuleman | 675f5d8 | 2015-12-10 13:43:01 +0100 | [diff] [blame] | 1186 | memcpy(ssid_le.SSID, ssids->ssid, SSID_len); |
| 1187 | ssid_le.SSID_len = cpu_to_le32(SSID_len); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1188 | spec_scan = true; |
| 1189 | } else |
Arend van Spriel | 4e8a008 | 2012-12-05 15:26:03 +0100 | [diff] [blame] | 1190 | brcmf_dbg(SCAN, "Broadcast scan\n"); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1191 | |
Hante Meuleman | 81f5dcb | 2012-10-22 10:36:14 -0700 | [diff] [blame] | 1192 | passive_scan = cfg->active_scan ? 0 : 1; |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 1193 | err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_PASSIVE_SCAN, |
Hante Meuleman | 81f5dcb | 2012-10-22 10:36:14 -0700 | [diff] [blame] | 1194 | passive_scan); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1195 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1196 | brcmf_err("WLC_SET_PASSIVE_SCAN error (%d)\n", err); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1197 | goto scan_out; |
| 1198 | } |
Daniel Kim | 5e787f7 | 2014-06-21 12:11:18 +0200 | [diff] [blame] | 1199 | brcmf_scan_config_mpc(ifp, 0); |
Hante Meuleman | 675f5d8 | 2015-12-10 13:43:01 +0100 | [diff] [blame] | 1200 | err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SCAN, &ssid_le, |
| 1201 | sizeof(ssid_le)); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1202 | if (err) { |
| 1203 | if (err == -EBUSY) |
Arend van Spriel | 647c9ae | 2012-12-05 15:26:01 +0100 | [diff] [blame] | 1204 | brcmf_dbg(INFO, "BUSY: scan for \"%s\" canceled\n", |
Hante Meuleman | 675f5d8 | 2015-12-10 13:43:01 +0100 | [diff] [blame] | 1205 | ssid_le.SSID); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1206 | else |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1207 | brcmf_err("WLC_SCAN error (%d)\n", err); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1208 | |
Daniel Kim | 5e787f7 | 2014-06-21 12:11:18 +0200 | [diff] [blame] | 1209 | brcmf_scan_config_mpc(ifp, 1); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1210 | goto scan_out; |
| 1211 | } |
| 1212 | } |
| 1213 | |
Hante Meuleman | 661fa95 | 2015-02-06 18:36:47 +0100 | [diff] [blame] | 1214 | /* Arm scan timeout timer */ |
| 1215 | mod_timer(&cfg->escan_timeout, jiffies + |
Hante Meuleman | d536733 | 2016-02-17 11:26:51 +0100 | [diff] [blame] | 1216 | BRCMF_ESCAN_TIMER_INTERVAL_MS * HZ / 1000); |
Hante Meuleman | 661fa95 | 2015-02-06 18:36:47 +0100 | [diff] [blame] | 1217 | |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1218 | return 0; |
| 1219 | |
| 1220 | scan_out: |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 1221 | clear_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status); |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 1222 | cfg->scan_request = NULL; |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1223 | return err; |
| 1224 | } |
| 1225 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1226 | static s32 |
Arend van Spriel | 0abb5f21 | 2012-10-22 13:55:32 -0700 | [diff] [blame] | 1227 | brcmf_cfg80211_scan(struct wiphy *wiphy, struct cfg80211_scan_request *request) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1228 | { |
Arend van Spriel | a0f472a | 2013-04-05 10:57:49 +0200 | [diff] [blame] | 1229 | struct brcmf_cfg80211_vif *vif; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1230 | s32 err = 0; |
| 1231 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 1232 | brcmf_dbg(TRACE, "Enter\n"); |
Arend van Spriel | a0f472a | 2013-04-05 10:57:49 +0200 | [diff] [blame] | 1233 | vif = container_of(request->wdev, struct brcmf_cfg80211_vif, wdev); |
| 1234 | if (!check_vif_up(vif)) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1235 | return -EIO; |
| 1236 | |
Arend van Spriel | a0f472a | 2013-04-05 10:57:49 +0200 | [diff] [blame] | 1237 | err = brcmf_cfg80211_escan(wiphy, vif, request, NULL); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1238 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1239 | if (err) |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1240 | brcmf_err("scan error (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1241 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 1242 | brcmf_dbg(TRACE, "Exit\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1243 | return err; |
| 1244 | } |
| 1245 | |
| 1246 | static s32 brcmf_set_rts(struct net_device *ndev, u32 rts_threshold) |
| 1247 | { |
| 1248 | s32 err = 0; |
| 1249 | |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 1250 | err = brcmf_fil_iovar_int_set(netdev_priv(ndev), "rtsthresh", |
| 1251 | rts_threshold); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1252 | if (err) |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1253 | brcmf_err("Error (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1254 | |
| 1255 | return err; |
| 1256 | } |
| 1257 | |
| 1258 | static s32 brcmf_set_frag(struct net_device *ndev, u32 frag_threshold) |
| 1259 | { |
| 1260 | s32 err = 0; |
| 1261 | |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 1262 | err = brcmf_fil_iovar_int_set(netdev_priv(ndev), "fragthresh", |
| 1263 | frag_threshold); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1264 | if (err) |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1265 | brcmf_err("Error (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1266 | |
| 1267 | return err; |
| 1268 | } |
| 1269 | |
| 1270 | static s32 brcmf_set_retry(struct net_device *ndev, u32 retry, bool l) |
| 1271 | { |
| 1272 | s32 err = 0; |
Hante Meuleman | b87e2c4 | 2012-11-14 18:46:23 -0800 | [diff] [blame] | 1273 | u32 cmd = (l ? BRCMF_C_SET_LRL : BRCMF_C_SET_SRL); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1274 | |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 1275 | err = brcmf_fil_cmd_int_set(netdev_priv(ndev), cmd, retry); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1276 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1277 | brcmf_err("cmd (%d) , error (%d)\n", cmd, err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1278 | return err; |
| 1279 | } |
| 1280 | return err; |
| 1281 | } |
| 1282 | |
| 1283 | static s32 brcmf_cfg80211_set_wiphy_params(struct wiphy *wiphy, u32 changed) |
| 1284 | { |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 1285 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); |
| 1286 | struct net_device *ndev = cfg_to_ndev(cfg); |
Arend van Spriel | 0abb5f21 | 2012-10-22 13:55:32 -0700 | [diff] [blame] | 1287 | struct brcmf_if *ifp = netdev_priv(ndev); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1288 | s32 err = 0; |
| 1289 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 1290 | brcmf_dbg(TRACE, "Enter\n"); |
Arend van Spriel | ce81e31 | 2012-10-22 13:55:37 -0700 | [diff] [blame] | 1291 | if (!check_vif_up(ifp->vif)) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1292 | return -EIO; |
| 1293 | |
| 1294 | if (changed & WIPHY_PARAM_RTS_THRESHOLD && |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 1295 | (cfg->conf->rts_threshold != wiphy->rts_threshold)) { |
| 1296 | cfg->conf->rts_threshold = wiphy->rts_threshold; |
| 1297 | err = brcmf_set_rts(ndev, cfg->conf->rts_threshold); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1298 | if (!err) |
| 1299 | goto done; |
| 1300 | } |
| 1301 | if (changed & WIPHY_PARAM_FRAG_THRESHOLD && |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 1302 | (cfg->conf->frag_threshold != wiphy->frag_threshold)) { |
| 1303 | cfg->conf->frag_threshold = wiphy->frag_threshold; |
| 1304 | err = brcmf_set_frag(ndev, cfg->conf->frag_threshold); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1305 | if (!err) |
| 1306 | goto done; |
| 1307 | } |
| 1308 | if (changed & WIPHY_PARAM_RETRY_LONG |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 1309 | && (cfg->conf->retry_long != wiphy->retry_long)) { |
| 1310 | cfg->conf->retry_long = wiphy->retry_long; |
| 1311 | err = brcmf_set_retry(ndev, cfg->conf->retry_long, true); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1312 | if (!err) |
| 1313 | goto done; |
| 1314 | } |
| 1315 | if (changed & WIPHY_PARAM_RETRY_SHORT |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 1316 | && (cfg->conf->retry_short != wiphy->retry_short)) { |
| 1317 | cfg->conf->retry_short = wiphy->retry_short; |
| 1318 | err = brcmf_set_retry(ndev, cfg->conf->retry_short, false); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1319 | if (!err) |
| 1320 | goto done; |
| 1321 | } |
| 1322 | |
| 1323 | done: |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 1324 | brcmf_dbg(TRACE, "Exit\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1325 | return err; |
| 1326 | } |
| 1327 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1328 | static void brcmf_init_prof(struct brcmf_cfg80211_profile *prof) |
| 1329 | { |
| 1330 | memset(prof, 0, sizeof(*prof)); |
| 1331 | } |
| 1332 | |
Arend van Spriel | 9b7a0dd | 2015-01-25 20:31:33 +0100 | [diff] [blame] | 1333 | static u16 brcmf_map_fw_linkdown_reason(const struct brcmf_event_msg *e) |
| 1334 | { |
| 1335 | u16 reason; |
| 1336 | |
| 1337 | switch (e->event_code) { |
| 1338 | case BRCMF_E_DEAUTH: |
| 1339 | case BRCMF_E_DEAUTH_IND: |
| 1340 | case BRCMF_E_DISASSOC_IND: |
| 1341 | reason = e->reason; |
| 1342 | break; |
| 1343 | case BRCMF_E_LINK: |
| 1344 | default: |
| 1345 | reason = 0; |
| 1346 | break; |
| 1347 | } |
| 1348 | return reason; |
| 1349 | } |
| 1350 | |
| 1351 | static void brcmf_link_down(struct brcmf_cfg80211_vif *vif, u16 reason) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1352 | { |
Piotr Haber | 61730d4 | 2013-04-23 12:53:12 +0200 | [diff] [blame] | 1353 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(vif->wdev.wiphy); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1354 | s32 err = 0; |
| 1355 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 1356 | brcmf_dbg(TRACE, "Enter\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1357 | |
Hante Meuleman | b0a7908 | 2015-12-10 13:43:07 +0100 | [diff] [blame] | 1358 | if (test_and_clear_bit(BRCMF_VIF_STATUS_CONNECTED, &vif->sme_state)) { |
Arend van Spriel | 647c9ae | 2012-12-05 15:26:01 +0100 | [diff] [blame] | 1359 | brcmf_dbg(INFO, "Call WLC_DISASSOC to stop excess roaming\n "); |
Arend van Spriel | 903e0ee | 2012-11-28 21:44:11 +0100 | [diff] [blame] | 1360 | err = brcmf_fil_cmd_data_set(vif->ifp, |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 1361 | BRCMF_C_DISASSOC, NULL, 0); |
Arend van Spriel | a538ae3 | 2013-07-25 23:01:34 +0200 | [diff] [blame] | 1362 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1363 | brcmf_err("WLC_DISASSOC failed (%d)\n", err); |
Arend van Spriel | a538ae3 | 2013-07-25 23:01:34 +0200 | [diff] [blame] | 1364 | } |
Hante Meuleman | b0a7908 | 2015-12-10 13:43:07 +0100 | [diff] [blame] | 1365 | if ((vif->wdev.iftype == NL80211_IFTYPE_STATION) || |
| 1366 | (vif->wdev.iftype == NL80211_IFTYPE_P2P_CLIENT)) |
| 1367 | cfg80211_disconnected(vif->wdev.netdev, reason, NULL, 0, |
| 1368 | true, GFP_KERNEL); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1369 | } |
Arend van Spriel | 903e0ee | 2012-11-28 21:44:11 +0100 | [diff] [blame] | 1370 | clear_bit(BRCMF_VIF_STATUS_CONNECTING, &vif->sme_state); |
Piotr Haber | 61730d4 | 2013-04-23 12:53:12 +0200 | [diff] [blame] | 1371 | clear_bit(BRCMF_SCAN_STATUS_SUPPRESS, &cfg->scan_status); |
| 1372 | brcmf_btcoex_set_mode(vif, BRCMF_BTCOEX_ENABLED, 0); |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 1373 | brcmf_dbg(TRACE, "Exit\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1374 | } |
| 1375 | |
| 1376 | static s32 |
| 1377 | brcmf_cfg80211_join_ibss(struct wiphy *wiphy, struct net_device *ndev, |
| 1378 | struct cfg80211_ibss_params *params) |
| 1379 | { |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 1380 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); |
Arend van Spriel | 0abb5f21 | 2012-10-22 13:55:32 -0700 | [diff] [blame] | 1381 | struct brcmf_if *ifp = netdev_priv(ndev); |
| 1382 | struct brcmf_cfg80211_profile *profile = &ifp->vif->profile; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1383 | struct brcmf_join_params join_params; |
| 1384 | size_t join_params_size = 0; |
| 1385 | s32 err = 0; |
| 1386 | s32 wsec = 0; |
| 1387 | s32 bcnprd; |
Hante Meuleman | 1701261 | 2013-02-06 18:40:44 +0100 | [diff] [blame] | 1388 | u16 chanspec; |
Hante Meuleman | e9a6ca8 | 2015-11-25 11:32:37 +0100 | [diff] [blame] | 1389 | u32 ssid_len; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1390 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 1391 | brcmf_dbg(TRACE, "Enter\n"); |
Arend van Spriel | ce81e31 | 2012-10-22 13:55:37 -0700 | [diff] [blame] | 1392 | if (!check_vif_up(ifp->vif)) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1393 | return -EIO; |
| 1394 | |
| 1395 | if (params->ssid) |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 1396 | brcmf_dbg(CONN, "SSID: %s\n", params->ssid); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1397 | else { |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 1398 | brcmf_dbg(CONN, "SSID: NULL, Not supported\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1399 | return -EOPNOTSUPP; |
| 1400 | } |
| 1401 | |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 1402 | set_bit(BRCMF_VIF_STATUS_CONNECTING, &ifp->vif->sme_state); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1403 | |
| 1404 | if (params->bssid) |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 1405 | brcmf_dbg(CONN, "BSSID: %pM\n", params->bssid); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1406 | else |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 1407 | brcmf_dbg(CONN, "No BSSID specified\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1408 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1409 | if (params->chandef.chan) |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 1410 | brcmf_dbg(CONN, "channel: %d\n", |
| 1411 | params->chandef.chan->center_freq); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1412 | else |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 1413 | brcmf_dbg(CONN, "no channel specified\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1414 | |
| 1415 | if (params->channel_fixed) |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 1416 | brcmf_dbg(CONN, "fixed channel required\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1417 | else |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 1418 | brcmf_dbg(CONN, "no fixed channel required\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1419 | |
| 1420 | if (params->ie && params->ie_len) |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 1421 | brcmf_dbg(CONN, "ie len: %d\n", params->ie_len); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1422 | else |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 1423 | brcmf_dbg(CONN, "no ie specified\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1424 | |
| 1425 | if (params->beacon_interval) |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 1426 | brcmf_dbg(CONN, "beacon interval: %d\n", |
| 1427 | params->beacon_interval); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1428 | else |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 1429 | brcmf_dbg(CONN, "no beacon interval specified\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1430 | |
| 1431 | if (params->basic_rates) |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 1432 | brcmf_dbg(CONN, "basic rates: %08X\n", params->basic_rates); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1433 | else |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 1434 | brcmf_dbg(CONN, "no basic rates specified\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1435 | |
| 1436 | if (params->privacy) |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 1437 | brcmf_dbg(CONN, "privacy required\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1438 | else |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 1439 | brcmf_dbg(CONN, "no privacy required\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1440 | |
| 1441 | /* Configure Privacy for starter */ |
| 1442 | if (params->privacy) |
| 1443 | wsec |= WEP_ENABLED; |
| 1444 | |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 1445 | err = brcmf_fil_iovar_int_set(ifp, "wsec", wsec); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1446 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1447 | brcmf_err("wsec failed (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1448 | goto done; |
| 1449 | } |
| 1450 | |
| 1451 | /* Configure Beacon Interval for starter */ |
| 1452 | if (params->beacon_interval) |
| 1453 | bcnprd = params->beacon_interval; |
| 1454 | else |
| 1455 | bcnprd = 100; |
| 1456 | |
Hante Meuleman | b87e2c4 | 2012-11-14 18:46:23 -0800 | [diff] [blame] | 1457 | err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_BCNPRD, bcnprd); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1458 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1459 | brcmf_err("WLC_SET_BCNPRD failed (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1460 | goto done; |
| 1461 | } |
| 1462 | |
| 1463 | /* Configure required join parameter */ |
| 1464 | memset(&join_params, 0, sizeof(struct brcmf_join_params)); |
| 1465 | |
| 1466 | /* SSID */ |
Hante Meuleman | e9a6ca8 | 2015-11-25 11:32:37 +0100 | [diff] [blame] | 1467 | ssid_len = min_t(u32, params->ssid_len, IEEE80211_MAX_SSID_LEN); |
| 1468 | memcpy(join_params.ssid_le.SSID, params->ssid, ssid_len); |
| 1469 | join_params.ssid_le.SSID_len = cpu_to_le32(ssid_len); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1470 | join_params_size = sizeof(join_params.ssid_le); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1471 | |
| 1472 | /* BSSID */ |
| 1473 | if (params->bssid) { |
| 1474 | memcpy(join_params.params_le.bssid, params->bssid, ETH_ALEN); |
Hante Meuleman | e9a6ca8 | 2015-11-25 11:32:37 +0100 | [diff] [blame] | 1475 | join_params_size += BRCMF_ASSOC_PARAMS_FIXED_SIZE; |
Arend van Spriel | 6c8c4f7 | 2012-09-27 14:17:57 +0200 | [diff] [blame] | 1476 | memcpy(profile->bssid, params->bssid, ETH_ALEN); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1477 | } else { |
Joe Perches | 93803b3 | 2015-03-02 19:54:49 -0800 | [diff] [blame] | 1478 | eth_broadcast_addr(join_params.params_le.bssid); |
| 1479 | eth_zero_addr(profile->bssid); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1480 | } |
| 1481 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1482 | /* Channel */ |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1483 | if (params->chandef.chan) { |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1484 | u32 target_channel; |
| 1485 | |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 1486 | cfg->channel = |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1487 | ieee80211_frequency_to_channel( |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1488 | params->chandef.chan->center_freq); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1489 | if (params->channel_fixed) { |
| 1490 | /* adding chanspec */ |
Arend van Spriel | 600a897 | 2014-05-12 10:47:39 +0200 | [diff] [blame] | 1491 | chanspec = chandef_to_chanspec(&cfg->d11inf, |
| 1492 | ¶ms->chandef); |
Hante Meuleman | 1701261 | 2013-02-06 18:40:44 +0100 | [diff] [blame] | 1493 | join_params.params_le.chanspec_list[0] = |
| 1494 | cpu_to_le16(chanspec); |
| 1495 | join_params.params_le.chanspec_num = cpu_to_le32(1); |
| 1496 | join_params_size += sizeof(join_params.params_le); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1497 | } |
| 1498 | |
| 1499 | /* set channel for starter */ |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 1500 | target_channel = cfg->channel; |
Hante Meuleman | b87e2c4 | 2012-11-14 18:46:23 -0800 | [diff] [blame] | 1501 | err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_CHANNEL, |
Hante Meuleman | 81f5dcb | 2012-10-22 10:36:14 -0700 | [diff] [blame] | 1502 | target_channel); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1503 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1504 | brcmf_err("WLC_SET_CHANNEL failed (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1505 | goto done; |
| 1506 | } |
| 1507 | } else |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 1508 | cfg->channel = 0; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1509 | |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 1510 | cfg->ibss_starter = false; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1511 | |
| 1512 | |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 1513 | err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SET_SSID, |
Hante Meuleman | 81f5dcb | 2012-10-22 10:36:14 -0700 | [diff] [blame] | 1514 | &join_params, join_params_size); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1515 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1516 | brcmf_err("WLC_SET_SSID failed (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1517 | goto done; |
| 1518 | } |
| 1519 | |
| 1520 | done: |
| 1521 | if (err) |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 1522 | clear_bit(BRCMF_VIF_STATUS_CONNECTING, &ifp->vif->sme_state); |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 1523 | brcmf_dbg(TRACE, "Exit\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1524 | return err; |
| 1525 | } |
| 1526 | |
| 1527 | static s32 |
| 1528 | brcmf_cfg80211_leave_ibss(struct wiphy *wiphy, struct net_device *ndev) |
| 1529 | { |
Arend van Spriel | 0abb5f21 | 2012-10-22 13:55:32 -0700 | [diff] [blame] | 1530 | struct brcmf_if *ifp = netdev_priv(ndev); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1531 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 1532 | brcmf_dbg(TRACE, "Enter\n"); |
Hante Meuleman | 6a98d64 | 2016-01-02 09:41:40 +0100 | [diff] [blame] | 1533 | if (!check_vif_up(ifp->vif)) { |
| 1534 | /* When driver is being unloaded, it can end up here. If an |
| 1535 | * error is returned then later on a debug trace in the wireless |
| 1536 | * core module will be printed. To avoid this 0 is returned. |
| 1537 | */ |
| 1538 | return 0; |
| 1539 | } |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1540 | |
Arend van Spriel | 9b7a0dd | 2015-01-25 20:31:33 +0100 | [diff] [blame] | 1541 | brcmf_link_down(ifp->vif, WLAN_REASON_DEAUTH_LEAVING); |
Hante Meuleman | 42e0ed0 | 2016-01-05 11:05:50 +0100 | [diff] [blame] | 1542 | brcmf_net_setcarrier(ifp, false); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1543 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 1544 | brcmf_dbg(TRACE, "Exit\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1545 | |
Peter Senna Tschudin | 12f3237 | 2014-05-31 10:14:06 -0300 | [diff] [blame] | 1546 | return 0; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1547 | } |
| 1548 | |
| 1549 | static s32 brcmf_set_wpa_version(struct net_device *ndev, |
| 1550 | struct cfg80211_connect_params *sme) |
| 1551 | { |
Arend van Spriel | 6ac4f4e | 2012-10-22 13:55:31 -0700 | [diff] [blame] | 1552 | struct brcmf_cfg80211_profile *profile = ndev_to_prof(ndev); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1553 | struct brcmf_cfg80211_security *sec; |
| 1554 | s32 val = 0; |
| 1555 | s32 err = 0; |
| 1556 | |
| 1557 | if (sme->crypto.wpa_versions & NL80211_WPA_VERSION_1) |
| 1558 | val = WPA_AUTH_PSK | WPA_AUTH_UNSPECIFIED; |
| 1559 | else if (sme->crypto.wpa_versions & NL80211_WPA_VERSION_2) |
| 1560 | val = WPA2_AUTH_PSK | WPA2_AUTH_UNSPECIFIED; |
| 1561 | else |
| 1562 | val = WPA_AUTH_DISABLED; |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 1563 | brcmf_dbg(CONN, "setting wpa_auth to 0x%0x\n", val); |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 1564 | err = brcmf_fil_bsscfg_int_set(netdev_priv(ndev), "wpa_auth", val); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1565 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1566 | brcmf_err("set wpa_auth failed (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1567 | return err; |
| 1568 | } |
Arend van Spriel | 06bb123 | 2012-09-27 14:17:56 +0200 | [diff] [blame] | 1569 | sec = &profile->sec; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1570 | sec->wpa_versions = sme->crypto.wpa_versions; |
| 1571 | return err; |
| 1572 | } |
| 1573 | |
| 1574 | static s32 brcmf_set_auth_type(struct net_device *ndev, |
| 1575 | struct cfg80211_connect_params *sme) |
| 1576 | { |
Arend van Spriel | 6ac4f4e | 2012-10-22 13:55:31 -0700 | [diff] [blame] | 1577 | struct brcmf_cfg80211_profile *profile = ndev_to_prof(ndev); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1578 | struct brcmf_cfg80211_security *sec; |
| 1579 | s32 val = 0; |
| 1580 | s32 err = 0; |
| 1581 | |
| 1582 | switch (sme->auth_type) { |
| 1583 | case NL80211_AUTHTYPE_OPEN_SYSTEM: |
| 1584 | val = 0; |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 1585 | brcmf_dbg(CONN, "open system\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1586 | break; |
| 1587 | case NL80211_AUTHTYPE_SHARED_KEY: |
| 1588 | val = 1; |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 1589 | brcmf_dbg(CONN, "shared key\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1590 | break; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1591 | default: |
| 1592 | val = 2; |
Hante Meuleman | 92c3136 | 2016-09-19 12:09:59 +0100 | [diff] [blame] | 1593 | brcmf_dbg(CONN, "automatic, auth type (%d)\n", sme->auth_type); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1594 | break; |
| 1595 | } |
| 1596 | |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 1597 | err = brcmf_fil_bsscfg_int_set(netdev_priv(ndev), "auth", val); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1598 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1599 | brcmf_err("set auth failed (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1600 | return err; |
| 1601 | } |
Arend van Spriel | 06bb123 | 2012-09-27 14:17:56 +0200 | [diff] [blame] | 1602 | sec = &profile->sec; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1603 | sec->auth_type = sme->auth_type; |
| 1604 | return err; |
| 1605 | } |
| 1606 | |
| 1607 | static s32 |
Daniel Kim | 87b7e9e | 2014-03-25 21:45:09 +0100 | [diff] [blame] | 1608 | brcmf_set_wsec_mode(struct net_device *ndev, |
Hante Meuleman | 240d61a | 2016-02-17 11:27:10 +0100 | [diff] [blame] | 1609 | struct cfg80211_connect_params *sme) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1610 | { |
Arend van Spriel | 6ac4f4e | 2012-10-22 13:55:31 -0700 | [diff] [blame] | 1611 | struct brcmf_cfg80211_profile *profile = ndev_to_prof(ndev); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1612 | struct brcmf_cfg80211_security *sec; |
| 1613 | s32 pval = 0; |
| 1614 | s32 gval = 0; |
Daniel Kim | 87b7e9e | 2014-03-25 21:45:09 +0100 | [diff] [blame] | 1615 | s32 wsec; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1616 | s32 err = 0; |
| 1617 | |
| 1618 | if (sme->crypto.n_ciphers_pairwise) { |
| 1619 | switch (sme->crypto.ciphers_pairwise[0]) { |
| 1620 | case WLAN_CIPHER_SUITE_WEP40: |
| 1621 | case WLAN_CIPHER_SUITE_WEP104: |
| 1622 | pval = WEP_ENABLED; |
| 1623 | break; |
| 1624 | case WLAN_CIPHER_SUITE_TKIP: |
| 1625 | pval = TKIP_ENABLED; |
| 1626 | break; |
| 1627 | case WLAN_CIPHER_SUITE_CCMP: |
| 1628 | pval = AES_ENABLED; |
| 1629 | break; |
| 1630 | case WLAN_CIPHER_SUITE_AES_CMAC: |
| 1631 | pval = AES_ENABLED; |
| 1632 | break; |
| 1633 | default: |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1634 | brcmf_err("invalid cipher pairwise (%d)\n", |
| 1635 | sme->crypto.ciphers_pairwise[0]); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1636 | return -EINVAL; |
| 1637 | } |
| 1638 | } |
| 1639 | if (sme->crypto.cipher_group) { |
| 1640 | switch (sme->crypto.cipher_group) { |
| 1641 | case WLAN_CIPHER_SUITE_WEP40: |
| 1642 | case WLAN_CIPHER_SUITE_WEP104: |
| 1643 | gval = WEP_ENABLED; |
| 1644 | break; |
| 1645 | case WLAN_CIPHER_SUITE_TKIP: |
| 1646 | gval = TKIP_ENABLED; |
| 1647 | break; |
| 1648 | case WLAN_CIPHER_SUITE_CCMP: |
| 1649 | gval = AES_ENABLED; |
| 1650 | break; |
| 1651 | case WLAN_CIPHER_SUITE_AES_CMAC: |
| 1652 | gval = AES_ENABLED; |
| 1653 | break; |
| 1654 | default: |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1655 | brcmf_err("invalid cipher group (%d)\n", |
| 1656 | sme->crypto.cipher_group); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1657 | return -EINVAL; |
| 1658 | } |
| 1659 | } |
| 1660 | |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 1661 | brcmf_dbg(CONN, "pval (%d) gval (%d)\n", pval, gval); |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 1662 | /* In case of privacy, but no security and WPS then simulate */ |
| 1663 | /* setting AES. WPS-2.0 allows no security */ |
| 1664 | if (brcmf_find_wpsie(sme->ie, sme->ie_len) && !pval && !gval && |
| 1665 | sme->privacy) |
| 1666 | pval = AES_ENABLED; |
Daniel Kim | 87b7e9e | 2014-03-25 21:45:09 +0100 | [diff] [blame] | 1667 | |
Hante Meuleman | 240d61a | 2016-02-17 11:27:10 +0100 | [diff] [blame] | 1668 | wsec = pval | gval; |
Daniel Kim | 87b7e9e | 2014-03-25 21:45:09 +0100 | [diff] [blame] | 1669 | err = brcmf_fil_bsscfg_int_set(netdev_priv(ndev), "wsec", wsec); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1670 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1671 | brcmf_err("error (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1672 | return err; |
| 1673 | } |
| 1674 | |
Arend van Spriel | 06bb123 | 2012-09-27 14:17:56 +0200 | [diff] [blame] | 1675 | sec = &profile->sec; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1676 | sec->cipher_pairwise = sme->crypto.ciphers_pairwise[0]; |
| 1677 | sec->cipher_group = sme->crypto.cipher_group; |
| 1678 | |
| 1679 | return err; |
| 1680 | } |
| 1681 | |
| 1682 | static s32 |
| 1683 | brcmf_set_key_mgmt(struct net_device *ndev, struct cfg80211_connect_params *sme) |
| 1684 | { |
Hante Meuleman | 240d61a | 2016-02-17 11:27:10 +0100 | [diff] [blame] | 1685 | struct brcmf_if *ifp = netdev_priv(ndev); |
| 1686 | s32 val; |
| 1687 | s32 err; |
| 1688 | const struct brcmf_tlv *rsn_ie; |
| 1689 | const u8 *ie; |
| 1690 | u32 ie_len; |
| 1691 | u32 offset; |
| 1692 | u16 rsn_cap; |
| 1693 | u32 mfp; |
| 1694 | u16 count; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1695 | |
Hante Meuleman | 240d61a | 2016-02-17 11:27:10 +0100 | [diff] [blame] | 1696 | if (!sme->crypto.n_akm_suites) |
| 1697 | return 0; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1698 | |
Hante Meuleman | 240d61a | 2016-02-17 11:27:10 +0100 | [diff] [blame] | 1699 | err = brcmf_fil_bsscfg_int_get(netdev_priv(ndev), "wpa_auth", &val); |
| 1700 | if (err) { |
| 1701 | brcmf_err("could not get wpa_auth (%d)\n", err); |
| 1702 | return err; |
| 1703 | } |
| 1704 | if (val & (WPA_AUTH_PSK | WPA_AUTH_UNSPECIFIED)) { |
| 1705 | switch (sme->crypto.akm_suites[0]) { |
| 1706 | case WLAN_AKM_SUITE_8021X: |
| 1707 | val = WPA_AUTH_UNSPECIFIED; |
| 1708 | break; |
| 1709 | case WLAN_AKM_SUITE_PSK: |
| 1710 | val = WPA_AUTH_PSK; |
| 1711 | break; |
| 1712 | default: |
| 1713 | brcmf_err("invalid cipher group (%d)\n", |
| 1714 | sme->crypto.cipher_group); |
| 1715 | return -EINVAL; |
| 1716 | } |
| 1717 | } else if (val & (WPA2_AUTH_PSK | WPA2_AUTH_UNSPECIFIED)) { |
| 1718 | switch (sme->crypto.akm_suites[0]) { |
| 1719 | case WLAN_AKM_SUITE_8021X: |
| 1720 | val = WPA2_AUTH_UNSPECIFIED; |
| 1721 | break; |
| 1722 | case WLAN_AKM_SUITE_8021X_SHA256: |
| 1723 | val = WPA2_AUTH_1X_SHA256; |
| 1724 | break; |
| 1725 | case WLAN_AKM_SUITE_PSK_SHA256: |
| 1726 | val = WPA2_AUTH_PSK_SHA256; |
| 1727 | break; |
| 1728 | case WLAN_AKM_SUITE_PSK: |
| 1729 | val = WPA2_AUTH_PSK; |
| 1730 | break; |
| 1731 | default: |
| 1732 | brcmf_err("invalid cipher group (%d)\n", |
| 1733 | sme->crypto.cipher_group); |
| 1734 | return -EINVAL; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1735 | } |
| 1736 | } |
Hante Meuleman | 240d61a | 2016-02-17 11:27:10 +0100 | [diff] [blame] | 1737 | |
| 1738 | if (!brcmf_feat_is_enabled(ifp, BRCMF_FEAT_MFP)) |
| 1739 | goto skip_mfp_config; |
| 1740 | /* The MFP mode (1 or 2) needs to be determined, parse IEs. The |
| 1741 | * IE will not be verified, just a quick search for MFP config |
| 1742 | */ |
| 1743 | rsn_ie = brcmf_parse_tlvs((const u8 *)sme->ie, sme->ie_len, |
| 1744 | WLAN_EID_RSN); |
| 1745 | if (!rsn_ie) |
| 1746 | goto skip_mfp_config; |
| 1747 | ie = (const u8 *)rsn_ie; |
| 1748 | ie_len = rsn_ie->len + TLV_HDR_LEN; |
| 1749 | /* Skip unicast suite */ |
| 1750 | offset = TLV_HDR_LEN + WPA_IE_VERSION_LEN + WPA_IE_MIN_OUI_LEN; |
| 1751 | if (offset + WPA_IE_SUITE_COUNT_LEN >= ie_len) |
| 1752 | goto skip_mfp_config; |
| 1753 | /* Skip multicast suite */ |
| 1754 | count = ie[offset] + (ie[offset + 1] << 8); |
| 1755 | offset += WPA_IE_SUITE_COUNT_LEN + (count * WPA_IE_MIN_OUI_LEN); |
| 1756 | if (offset + WPA_IE_SUITE_COUNT_LEN >= ie_len) |
| 1757 | goto skip_mfp_config; |
| 1758 | /* Skip auth key management suite(s) */ |
| 1759 | count = ie[offset] + (ie[offset + 1] << 8); |
| 1760 | offset += WPA_IE_SUITE_COUNT_LEN + (count * WPA_IE_MIN_OUI_LEN); |
| 1761 | if (offset + WPA_IE_SUITE_COUNT_LEN > ie_len) |
| 1762 | goto skip_mfp_config; |
| 1763 | /* Ready to read capabilities */ |
| 1764 | mfp = BRCMF_MFP_NONE; |
| 1765 | rsn_cap = ie[offset] + (ie[offset + 1] << 8); |
| 1766 | if (rsn_cap & RSN_CAP_MFPR_MASK) |
| 1767 | mfp = BRCMF_MFP_REQUIRED; |
| 1768 | else if (rsn_cap & RSN_CAP_MFPC_MASK) |
| 1769 | mfp = BRCMF_MFP_CAPABLE; |
| 1770 | brcmf_fil_bsscfg_int_set(netdev_priv(ndev), "mfp", mfp); |
| 1771 | |
| 1772 | skip_mfp_config: |
| 1773 | brcmf_dbg(CONN, "setting wpa_auth to %d\n", val); |
| 1774 | err = brcmf_fil_bsscfg_int_set(netdev_priv(ndev), "wpa_auth", val); |
| 1775 | if (err) { |
| 1776 | brcmf_err("could not set wpa_auth (%d)\n", err); |
| 1777 | return err; |
| 1778 | } |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1779 | |
| 1780 | return err; |
| 1781 | } |
| 1782 | |
| 1783 | static s32 |
Hante Meuleman | f09d0c0 | 2012-09-27 14:17:48 +0200 | [diff] [blame] | 1784 | brcmf_set_sharedkey(struct net_device *ndev, |
| 1785 | struct cfg80211_connect_params *sme) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1786 | { |
Arend van Spriel | 6ac4f4e | 2012-10-22 13:55:31 -0700 | [diff] [blame] | 1787 | struct brcmf_cfg80211_profile *profile = ndev_to_prof(ndev); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1788 | struct brcmf_cfg80211_security *sec; |
| 1789 | struct brcmf_wsec_key key; |
| 1790 | s32 val; |
| 1791 | s32 err = 0; |
| 1792 | |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 1793 | brcmf_dbg(CONN, "key len (%d)\n", sme->key_len); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1794 | |
Roland Vossen | a718e2f | 2011-10-12 20:51:24 +0200 | [diff] [blame] | 1795 | if (sme->key_len == 0) |
| 1796 | return 0; |
| 1797 | |
Arend van Spriel | 06bb123 | 2012-09-27 14:17:56 +0200 | [diff] [blame] | 1798 | sec = &profile->sec; |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 1799 | brcmf_dbg(CONN, "wpa_versions 0x%x cipher_pairwise 0x%x\n", |
| 1800 | sec->wpa_versions, sec->cipher_pairwise); |
Roland Vossen | a718e2f | 2011-10-12 20:51:24 +0200 | [diff] [blame] | 1801 | |
| 1802 | if (sec->wpa_versions & (NL80211_WPA_VERSION_1 | NL80211_WPA_VERSION_2)) |
| 1803 | return 0; |
| 1804 | |
Hante Meuleman | f09d0c0 | 2012-09-27 14:17:48 +0200 | [diff] [blame] | 1805 | if (!(sec->cipher_pairwise & |
| 1806 | (WLAN_CIPHER_SUITE_WEP40 | WLAN_CIPHER_SUITE_WEP104))) |
| 1807 | return 0; |
Roland Vossen | a718e2f | 2011-10-12 20:51:24 +0200 | [diff] [blame] | 1808 | |
Hante Meuleman | f09d0c0 | 2012-09-27 14:17:48 +0200 | [diff] [blame] | 1809 | memset(&key, 0, sizeof(key)); |
| 1810 | key.len = (u32) sme->key_len; |
| 1811 | key.index = (u32) sme->key_idx; |
| 1812 | if (key.len > sizeof(key.data)) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1813 | brcmf_err("Too long key length (%u)\n", key.len); |
Hante Meuleman | f09d0c0 | 2012-09-27 14:17:48 +0200 | [diff] [blame] | 1814 | return -EINVAL; |
| 1815 | } |
| 1816 | memcpy(key.data, sme->key, key.len); |
| 1817 | key.flags = BRCMF_PRIMARY_KEY; |
| 1818 | switch (sec->cipher_pairwise) { |
| 1819 | case WLAN_CIPHER_SUITE_WEP40: |
| 1820 | key.algo = CRYPTO_ALGO_WEP1; |
| 1821 | break; |
| 1822 | case WLAN_CIPHER_SUITE_WEP104: |
| 1823 | key.algo = CRYPTO_ALGO_WEP128; |
| 1824 | break; |
| 1825 | default: |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1826 | brcmf_err("Invalid algorithm (%d)\n", |
| 1827 | sme->crypto.ciphers_pairwise[0]); |
Hante Meuleman | f09d0c0 | 2012-09-27 14:17:48 +0200 | [diff] [blame] | 1828 | return -EINVAL; |
| 1829 | } |
| 1830 | /* Set the new key/index */ |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 1831 | brcmf_dbg(CONN, "key length (%d) key index (%d) algo (%d)\n", |
| 1832 | key.len, key.index, key.algo); |
| 1833 | brcmf_dbg(CONN, "key \"%s\"\n", key.data); |
Hante Meuleman | 118eb30 | 2014-12-21 12:43:49 +0100 | [diff] [blame] | 1834 | err = send_key_to_dongle(netdev_priv(ndev), &key); |
Hante Meuleman | f09d0c0 | 2012-09-27 14:17:48 +0200 | [diff] [blame] | 1835 | if (err) |
| 1836 | return err; |
| 1837 | |
| 1838 | if (sec->auth_type == NL80211_AUTHTYPE_SHARED_KEY) { |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 1839 | brcmf_dbg(CONN, "set auth_type to shared key\n"); |
Hante Meuleman | f09d0c0 | 2012-09-27 14:17:48 +0200 | [diff] [blame] | 1840 | val = WL_AUTH_SHARED_KEY; /* shared key */ |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 1841 | err = brcmf_fil_bsscfg_int_set(netdev_priv(ndev), "auth", val); |
Hante Meuleman | f09d0c0 | 2012-09-27 14:17:48 +0200 | [diff] [blame] | 1842 | if (err) |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1843 | brcmf_err("set auth failed (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1844 | } |
| 1845 | return err; |
| 1846 | } |
| 1847 | |
Arend van Spriel | cbb1ec9 | 2013-02-06 18:40:47 +0100 | [diff] [blame] | 1848 | static |
| 1849 | enum nl80211_auth_type brcmf_war_auth_type(struct brcmf_if *ifp, |
| 1850 | enum nl80211_auth_type type) |
| 1851 | { |
Arend van Spriel | c08437b | 2014-07-12 08:49:39 +0200 | [diff] [blame] | 1852 | if (type == NL80211_AUTHTYPE_AUTOMATIC && |
| 1853 | brcmf_feat_is_quirk_enabled(ifp, BRCMF_FEAT_QUIRK_AUTO_AUTH)) { |
| 1854 | brcmf_dbg(CONN, "WAR: use OPEN instead of AUTO\n"); |
| 1855 | type = NL80211_AUTHTYPE_OPEN_SYSTEM; |
Arend van Spriel | cbb1ec9 | 2013-02-06 18:40:47 +0100 | [diff] [blame] | 1856 | } |
| 1857 | return type; |
| 1858 | } |
| 1859 | |
Arend van Spriel | 7705ba6 | 2016-04-17 16:44:58 +0200 | [diff] [blame] | 1860 | static void brcmf_set_join_pref(struct brcmf_if *ifp, |
| 1861 | struct cfg80211_bss_selection *bss_select) |
| 1862 | { |
| 1863 | struct brcmf_join_pref_params join_pref_params[2]; |
| 1864 | enum nl80211_band band; |
| 1865 | int err, i = 0; |
| 1866 | |
| 1867 | join_pref_params[i].len = 2; |
| 1868 | join_pref_params[i].rssi_gain = 0; |
| 1869 | |
| 1870 | if (bss_select->behaviour != NL80211_BSS_SELECT_ATTR_BAND_PREF) |
| 1871 | brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_ASSOC_PREFER, WLC_BAND_AUTO); |
| 1872 | |
| 1873 | switch (bss_select->behaviour) { |
| 1874 | case __NL80211_BSS_SELECT_ATTR_INVALID: |
| 1875 | brcmf_c_set_joinpref_default(ifp); |
| 1876 | return; |
| 1877 | case NL80211_BSS_SELECT_ATTR_BAND_PREF: |
| 1878 | join_pref_params[i].type = BRCMF_JOIN_PREF_BAND; |
| 1879 | band = bss_select->param.band_pref; |
| 1880 | join_pref_params[i].band = nl80211_band_to_fwil(band); |
| 1881 | i++; |
| 1882 | break; |
| 1883 | case NL80211_BSS_SELECT_ATTR_RSSI_ADJUST: |
| 1884 | join_pref_params[i].type = BRCMF_JOIN_PREF_RSSI_DELTA; |
| 1885 | band = bss_select->param.adjust.band; |
| 1886 | join_pref_params[i].band = nl80211_band_to_fwil(band); |
| 1887 | join_pref_params[i].rssi_gain = bss_select->param.adjust.delta; |
| 1888 | i++; |
| 1889 | break; |
| 1890 | case NL80211_BSS_SELECT_ATTR_RSSI: |
| 1891 | default: |
| 1892 | break; |
| 1893 | } |
| 1894 | join_pref_params[i].type = BRCMF_JOIN_PREF_RSSI; |
| 1895 | join_pref_params[i].len = 2; |
| 1896 | join_pref_params[i].rssi_gain = 0; |
| 1897 | join_pref_params[i].band = 0; |
| 1898 | err = brcmf_fil_iovar_data_set(ifp, "join_pref", join_pref_params, |
| 1899 | sizeof(join_pref_params)); |
| 1900 | if (err) |
| 1901 | brcmf_err("Set join_pref error (%d)\n", err); |
| 1902 | } |
| 1903 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1904 | static s32 |
| 1905 | brcmf_cfg80211_connect(struct wiphy *wiphy, struct net_device *ndev, |
Arend van Spriel | cbb1ec9 | 2013-02-06 18:40:47 +0100 | [diff] [blame] | 1906 | struct cfg80211_connect_params *sme) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1907 | { |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 1908 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); |
Arend van Spriel | 0abb5f21 | 2012-10-22 13:55:32 -0700 | [diff] [blame] | 1909 | struct brcmf_if *ifp = netdev_priv(ndev); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1910 | struct ieee80211_channel *chan = sme->channel; |
| 1911 | struct brcmf_join_params join_params; |
| 1912 | size_t join_params_size; |
Johannes Berg | 4b5800f | 2014-01-15 14:55:59 +0100 | [diff] [blame] | 1913 | const struct brcmf_tlv *rsn_ie; |
| 1914 | const struct brcmf_vs_tlv *wpa_ie; |
| 1915 | const void *ie; |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 1916 | u32 ie_len; |
| 1917 | struct brcmf_ext_join_params_le *ext_join_params; |
Hante Meuleman | 1701261 | 2013-02-06 18:40:44 +0100 | [diff] [blame] | 1918 | u16 chanspec; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1919 | s32 err = 0; |
Hante Meuleman | e9a6ca8 | 2015-11-25 11:32:37 +0100 | [diff] [blame] | 1920 | u32 ssid_len; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1921 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 1922 | brcmf_dbg(TRACE, "Enter\n"); |
Arend van Spriel | ce81e31 | 2012-10-22 13:55:37 -0700 | [diff] [blame] | 1923 | if (!check_vif_up(ifp->vif)) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1924 | return -EIO; |
| 1925 | |
| 1926 | if (!sme->ssid) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1927 | brcmf_err("Invalid ssid\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1928 | return -EOPNOTSUPP; |
| 1929 | } |
| 1930 | |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 1931 | if (ifp->vif == cfg->p2p.bss_idx[P2PAPI_BSSCFG_PRIMARY].vif) { |
| 1932 | /* A normal (non P2P) connection request setup. */ |
| 1933 | ie = NULL; |
| 1934 | ie_len = 0; |
| 1935 | /* find the WPA_IE */ |
| 1936 | wpa_ie = brcmf_find_wpaie((u8 *)sme->ie, sme->ie_len); |
| 1937 | if (wpa_ie) { |
| 1938 | ie = wpa_ie; |
| 1939 | ie_len = wpa_ie->len + TLV_HDR_LEN; |
| 1940 | } else { |
| 1941 | /* find the RSN_IE */ |
Johannes Berg | 4b5800f | 2014-01-15 14:55:59 +0100 | [diff] [blame] | 1942 | rsn_ie = brcmf_parse_tlvs((const u8 *)sme->ie, |
| 1943 | sme->ie_len, |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 1944 | WLAN_EID_RSN); |
| 1945 | if (rsn_ie) { |
| 1946 | ie = rsn_ie; |
| 1947 | ie_len = rsn_ie->len + TLV_HDR_LEN; |
| 1948 | } |
| 1949 | } |
| 1950 | brcmf_fil_iovar_data_set(ifp, "wpaie", ie, ie_len); |
| 1951 | } |
| 1952 | |
| 1953 | err = brcmf_vif_set_mgmt_ie(ifp->vif, BRCMF_VNDR_IE_ASSOCREQ_FLAG, |
| 1954 | sme->ie, sme->ie_len); |
| 1955 | if (err) |
| 1956 | brcmf_err("Set Assoc REQ IE Failed\n"); |
| 1957 | else |
| 1958 | brcmf_dbg(TRACE, "Applied Vndr IEs for Assoc request\n"); |
| 1959 | |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 1960 | set_bit(BRCMF_VIF_STATUS_CONNECTING, &ifp->vif->sme_state); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1961 | |
| 1962 | if (chan) { |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 1963 | cfg->channel = |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1964 | ieee80211_frequency_to_channel(chan->center_freq); |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 1965 | chanspec = channel_to_chanspec(&cfg->d11inf, chan); |
Hante Meuleman | 1701261 | 2013-02-06 18:40:44 +0100 | [diff] [blame] | 1966 | brcmf_dbg(CONN, "channel=%d, center_req=%d, chanspec=0x%04x\n", |
| 1967 | cfg->channel, chan->center_freq, chanspec); |
| 1968 | } else { |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 1969 | cfg->channel = 0; |
Hante Meuleman | 1701261 | 2013-02-06 18:40:44 +0100 | [diff] [blame] | 1970 | chanspec = 0; |
| 1971 | } |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1972 | |
Arend van Spriel | 647c9ae | 2012-12-05 15:26:01 +0100 | [diff] [blame] | 1973 | brcmf_dbg(INFO, "ie (%p), ie_len (%zd)\n", sme->ie, sme->ie_len); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1974 | |
| 1975 | err = brcmf_set_wpa_version(ndev, sme); |
| 1976 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1977 | brcmf_err("wl_set_wpa_version failed (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1978 | goto done; |
| 1979 | } |
| 1980 | |
Arend van Spriel | cbb1ec9 | 2013-02-06 18:40:47 +0100 | [diff] [blame] | 1981 | sme->auth_type = brcmf_war_auth_type(ifp, sme->auth_type); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1982 | err = brcmf_set_auth_type(ndev, sme); |
| 1983 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1984 | brcmf_err("wl_set_auth_type failed (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1985 | goto done; |
| 1986 | } |
| 1987 | |
Hante Meuleman | 240d61a | 2016-02-17 11:27:10 +0100 | [diff] [blame] | 1988 | err = brcmf_set_wsec_mode(ndev, sme); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1989 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1990 | brcmf_err("wl_set_set_cipher failed (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1991 | goto done; |
| 1992 | } |
| 1993 | |
| 1994 | err = brcmf_set_key_mgmt(ndev, sme); |
| 1995 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1996 | brcmf_err("wl_set_key_mgmt failed (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1997 | goto done; |
| 1998 | } |
| 1999 | |
Hante Meuleman | f09d0c0 | 2012-09-27 14:17:48 +0200 | [diff] [blame] | 2000 | err = brcmf_set_sharedkey(ndev, sme); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2001 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 2002 | brcmf_err("brcmf_set_sharedkey failed (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2003 | goto done; |
| 2004 | } |
| 2005 | |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 2006 | /* Join with specific BSSID and cached SSID |
| 2007 | * If SSID is zero join based on BSSID only |
| 2008 | */ |
| 2009 | join_params_size = offsetof(struct brcmf_ext_join_params_le, assoc_le) + |
| 2010 | offsetof(struct brcmf_assoc_params_le, chanspec_list); |
| 2011 | if (cfg->channel) |
| 2012 | join_params_size += sizeof(u16); |
| 2013 | ext_join_params = kzalloc(join_params_size, GFP_KERNEL); |
| 2014 | if (ext_join_params == NULL) { |
| 2015 | err = -ENOMEM; |
| 2016 | goto done; |
| 2017 | } |
Hante Meuleman | e9a6ca8 | 2015-11-25 11:32:37 +0100 | [diff] [blame] | 2018 | ssid_len = min_t(u32, sme->ssid_len, IEEE80211_MAX_SSID_LEN); |
| 2019 | ext_join_params->ssid_le.SSID_len = cpu_to_le32(ssid_len); |
| 2020 | memcpy(&ext_join_params->ssid_le.SSID, sme->ssid, ssid_len); |
| 2021 | if (ssid_len < IEEE80211_MAX_SSID_LEN) |
| 2022 | brcmf_dbg(CONN, "SSID \"%s\", len (%d)\n", |
| 2023 | ext_join_params->ssid_le.SSID, ssid_len); |
Hante Meuleman | 63dd99e | 2014-03-15 17:18:19 +0100 | [diff] [blame] | 2024 | |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 2025 | /* Set up join scan parameters */ |
| 2026 | ext_join_params->scan_le.scan_type = -1; |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 2027 | ext_join_params->scan_le.home_time = cpu_to_le32(-1); |
| 2028 | |
| 2029 | if (sme->bssid) |
| 2030 | memcpy(&ext_join_params->assoc_le.bssid, sme->bssid, ETH_ALEN); |
| 2031 | else |
Joe Perches | 93803b3 | 2015-03-02 19:54:49 -0800 | [diff] [blame] | 2032 | eth_broadcast_addr(ext_join_params->assoc_le.bssid); |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 2033 | |
| 2034 | if (cfg->channel) { |
| 2035 | ext_join_params->assoc_le.chanspec_num = cpu_to_le32(1); |
| 2036 | |
| 2037 | ext_join_params->assoc_le.chanspec_list[0] = |
| 2038 | cpu_to_le16(chanspec); |
Hante Meuleman | 63dd99e | 2014-03-15 17:18:19 +0100 | [diff] [blame] | 2039 | /* Increase dwell time to receive probe response or detect |
| 2040 | * beacon from target AP at a noisy air only during connect |
| 2041 | * command. |
| 2042 | */ |
| 2043 | ext_join_params->scan_le.active_time = |
| 2044 | cpu_to_le32(BRCMF_SCAN_JOIN_ACTIVE_DWELL_TIME_MS); |
| 2045 | ext_join_params->scan_le.passive_time = |
| 2046 | cpu_to_le32(BRCMF_SCAN_JOIN_PASSIVE_DWELL_TIME_MS); |
| 2047 | /* To sync with presence period of VSDB GO send probe request |
| 2048 | * more frequently. Probe request will be stopped when it gets |
| 2049 | * probe response from target AP/GO. |
| 2050 | */ |
| 2051 | ext_join_params->scan_le.nprobes = |
| 2052 | cpu_to_le32(BRCMF_SCAN_JOIN_ACTIVE_DWELL_TIME_MS / |
| 2053 | BRCMF_SCAN_JOIN_PROBE_INTERVAL_MS); |
| 2054 | } else { |
| 2055 | ext_join_params->scan_le.active_time = cpu_to_le32(-1); |
| 2056 | ext_join_params->scan_le.passive_time = cpu_to_le32(-1); |
| 2057 | ext_join_params->scan_le.nprobes = cpu_to_le32(-1); |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 2058 | } |
| 2059 | |
Arend van Spriel | 7705ba6 | 2016-04-17 16:44:58 +0200 | [diff] [blame] | 2060 | brcmf_set_join_pref(ifp, &sme->bss_select); |
| 2061 | |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 2062 | err = brcmf_fil_bsscfg_data_set(ifp, "join", ext_join_params, |
| 2063 | join_params_size); |
| 2064 | kfree(ext_join_params); |
| 2065 | if (!err) |
| 2066 | /* This is it. join command worked, we are done */ |
| 2067 | goto done; |
| 2068 | |
| 2069 | /* join command failed, fallback to set ssid */ |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2070 | memset(&join_params, 0, sizeof(join_params)); |
| 2071 | join_params_size = sizeof(join_params.ssid_le); |
| 2072 | |
Hante Meuleman | e9a6ca8 | 2015-11-25 11:32:37 +0100 | [diff] [blame] | 2073 | memcpy(&join_params.ssid_le.SSID, sme->ssid, ssid_len); |
| 2074 | join_params.ssid_le.SSID_len = cpu_to_le32(ssid_len); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2075 | |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 2076 | if (sme->bssid) |
| 2077 | memcpy(join_params.params_le.bssid, sme->bssid, ETH_ALEN); |
| 2078 | else |
Joe Perches | 93803b3 | 2015-03-02 19:54:49 -0800 | [diff] [blame] | 2079 | eth_broadcast_addr(join_params.params_le.bssid); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2080 | |
Hante Meuleman | 1701261 | 2013-02-06 18:40:44 +0100 | [diff] [blame] | 2081 | if (cfg->channel) { |
| 2082 | join_params.params_le.chanspec_list[0] = cpu_to_le16(chanspec); |
| 2083 | join_params.params_le.chanspec_num = cpu_to_le32(1); |
| 2084 | join_params_size += sizeof(join_params.params_le); |
| 2085 | } |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 2086 | err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SET_SSID, |
Hante Meuleman | 81f5dcb | 2012-10-22 10:36:14 -0700 | [diff] [blame] | 2087 | &join_params, join_params_size); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2088 | if (err) |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 2089 | brcmf_err("BRCMF_C_SET_SSID failed (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2090 | |
| 2091 | done: |
| 2092 | if (err) |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 2093 | clear_bit(BRCMF_VIF_STATUS_CONNECTING, &ifp->vif->sme_state); |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 2094 | brcmf_dbg(TRACE, "Exit\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2095 | return err; |
| 2096 | } |
| 2097 | |
| 2098 | static s32 |
| 2099 | brcmf_cfg80211_disconnect(struct wiphy *wiphy, struct net_device *ndev, |
| 2100 | u16 reason_code) |
| 2101 | { |
Arend van Spriel | 0abb5f21 | 2012-10-22 13:55:32 -0700 | [diff] [blame] | 2102 | struct brcmf_if *ifp = netdev_priv(ndev); |
| 2103 | struct brcmf_cfg80211_profile *profile = &ifp->vif->profile; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2104 | struct brcmf_scb_val_le scbval; |
| 2105 | s32 err = 0; |
| 2106 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 2107 | brcmf_dbg(TRACE, "Enter. Reason code = %d\n", reason_code); |
Arend van Spriel | ce81e31 | 2012-10-22 13:55:37 -0700 | [diff] [blame] | 2108 | if (!check_vif_up(ifp->vif)) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2109 | return -EIO; |
| 2110 | |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 2111 | clear_bit(BRCMF_VIF_STATUS_CONNECTED, &ifp->vif->sme_state); |
Arend van Spriel | 4f3fff1 | 2014-11-20 22:27:02 +0100 | [diff] [blame] | 2112 | clear_bit(BRCMF_VIF_STATUS_CONNECTING, &ifp->vif->sme_state); |
Johannes Berg | 80279fb | 2015-05-22 16:22:20 +0200 | [diff] [blame] | 2113 | cfg80211_disconnected(ndev, reason_code, NULL, 0, true, GFP_KERNEL); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2114 | |
Arend van Spriel | 06bb123 | 2012-09-27 14:17:56 +0200 | [diff] [blame] | 2115 | memcpy(&scbval.ea, &profile->bssid, ETH_ALEN); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2116 | scbval.val = cpu_to_le32(reason_code); |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 2117 | err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_DISASSOC, |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 2118 | &scbval, sizeof(scbval)); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2119 | if (err) |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 2120 | brcmf_err("error (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2121 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 2122 | brcmf_dbg(TRACE, "Exit\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2123 | return err; |
| 2124 | } |
| 2125 | |
| 2126 | static s32 |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 2127 | brcmf_cfg80211_set_tx_power(struct wiphy *wiphy, struct wireless_dev *wdev, |
Luis R. Rodriguez | d3f3113 | 2011-11-28 16:38:48 -0500 | [diff] [blame] | 2128 | enum nl80211_tx_power_setting type, s32 mbm) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2129 | { |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 2130 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); |
Arend van Spriel | 0abb5f21 | 2012-10-22 13:55:32 -0700 | [diff] [blame] | 2131 | struct net_device *ndev = cfg_to_ndev(cfg); |
| 2132 | struct brcmf_if *ifp = netdev_priv(ndev); |
Hante Meuleman | 60dc35e | 2015-09-18 22:08:06 +0200 | [diff] [blame] | 2133 | s32 err; |
| 2134 | s32 disable; |
| 2135 | u32 qdbm = 127; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2136 | |
Hante Meuleman | 60dc35e | 2015-09-18 22:08:06 +0200 | [diff] [blame] | 2137 | brcmf_dbg(TRACE, "Enter %d %d\n", type, mbm); |
Arend van Spriel | ce81e31 | 2012-10-22 13:55:37 -0700 | [diff] [blame] | 2138 | if (!check_vif_up(ifp->vif)) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2139 | return -EIO; |
| 2140 | |
| 2141 | switch (type) { |
| 2142 | case NL80211_TX_POWER_AUTOMATIC: |
| 2143 | break; |
| 2144 | case NL80211_TX_POWER_LIMITED: |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2145 | case NL80211_TX_POWER_FIXED: |
Hante Meuleman | 60dc35e | 2015-09-18 22:08:06 +0200 | [diff] [blame] | 2146 | if (mbm < 0) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 2147 | brcmf_err("TX_POWER_FIXED - dbm is negative\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2148 | err = -EINVAL; |
| 2149 | goto done; |
| 2150 | } |
Hante Meuleman | 60dc35e | 2015-09-18 22:08:06 +0200 | [diff] [blame] | 2151 | qdbm = MBM_TO_DBM(4 * mbm); |
| 2152 | if (qdbm > 127) |
| 2153 | qdbm = 127; |
| 2154 | qdbm |= WL_TXPWR_OVERRIDE; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2155 | break; |
Hante Meuleman | 60dc35e | 2015-09-18 22:08:06 +0200 | [diff] [blame] | 2156 | default: |
| 2157 | brcmf_err("Unsupported type %d\n", type); |
| 2158 | err = -EINVAL; |
| 2159 | goto done; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2160 | } |
| 2161 | /* Make sure radio is off or on as far as software is concerned */ |
| 2162 | disable = WL_RADIO_SW_DISABLE << 16; |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 2163 | err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_RADIO, disable); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2164 | if (err) |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 2165 | brcmf_err("WLC_SET_RADIO error (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2166 | |
Hante Meuleman | 60dc35e | 2015-09-18 22:08:06 +0200 | [diff] [blame] | 2167 | err = brcmf_fil_iovar_int_set(ifp, "qtxpower", qdbm); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2168 | if (err) |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 2169 | brcmf_err("qtxpower error (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2170 | |
| 2171 | done: |
Hante Meuleman | 60dc35e | 2015-09-18 22:08:06 +0200 | [diff] [blame] | 2172 | brcmf_dbg(TRACE, "Exit %d (qdbm)\n", qdbm & ~WL_TXPWR_OVERRIDE); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2173 | return err; |
| 2174 | } |
| 2175 | |
Hante Meuleman | 60dc35e | 2015-09-18 22:08:06 +0200 | [diff] [blame] | 2176 | static s32 |
| 2177 | brcmf_cfg80211_get_tx_power(struct wiphy *wiphy, struct wireless_dev *wdev, |
| 2178 | s32 *dbm) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2179 | { |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 2180 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); |
Hante Meuleman | 60dc35e | 2015-09-18 22:08:06 +0200 | [diff] [blame] | 2181 | struct net_device *ndev = cfg_to_ndev(cfg); |
| 2182 | struct brcmf_if *ifp = netdev_priv(ndev); |
| 2183 | s32 qdbm = 0; |
| 2184 | s32 err; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2185 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 2186 | brcmf_dbg(TRACE, "Enter\n"); |
Arend van Spriel | ce81e31 | 2012-10-22 13:55:37 -0700 | [diff] [blame] | 2187 | if (!check_vif_up(ifp->vif)) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2188 | return -EIO; |
| 2189 | |
Hante Meuleman | 60dc35e | 2015-09-18 22:08:06 +0200 | [diff] [blame] | 2190 | err = brcmf_fil_iovar_int_get(ifp, "qtxpower", &qdbm); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2191 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 2192 | brcmf_err("error (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2193 | goto done; |
| 2194 | } |
Hante Meuleman | 60dc35e | 2015-09-18 22:08:06 +0200 | [diff] [blame] | 2195 | *dbm = (qdbm & ~WL_TXPWR_OVERRIDE) / 4; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2196 | |
| 2197 | done: |
Hante Meuleman | 60dc35e | 2015-09-18 22:08:06 +0200 | [diff] [blame] | 2198 | brcmf_dbg(TRACE, "Exit (0x%x %d)\n", qdbm, *dbm); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2199 | return err; |
| 2200 | } |
| 2201 | |
| 2202 | static s32 |
| 2203 | brcmf_cfg80211_config_default_key(struct wiphy *wiphy, struct net_device *ndev, |
Hante Meuleman | 60dc35e | 2015-09-18 22:08:06 +0200 | [diff] [blame] | 2204 | u8 key_idx, bool unicast, bool multicast) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2205 | { |
Arend van Spriel | 0abb5f21 | 2012-10-22 13:55:32 -0700 | [diff] [blame] | 2206 | struct brcmf_if *ifp = netdev_priv(ndev); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2207 | u32 index; |
| 2208 | u32 wsec; |
| 2209 | s32 err = 0; |
| 2210 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 2211 | brcmf_dbg(TRACE, "Enter\n"); |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 2212 | brcmf_dbg(CONN, "key index (%d)\n", key_idx); |
Arend van Spriel | ce81e31 | 2012-10-22 13:55:37 -0700 | [diff] [blame] | 2213 | if (!check_vif_up(ifp->vif)) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2214 | return -EIO; |
| 2215 | |
Arend van Spriel | 0abb5f21 | 2012-10-22 13:55:32 -0700 | [diff] [blame] | 2216 | err = brcmf_fil_bsscfg_int_get(ifp, "wsec", &wsec); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2217 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 2218 | brcmf_err("WLC_GET_WSEC error (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2219 | goto done; |
| 2220 | } |
| 2221 | |
| 2222 | if (wsec & WEP_ENABLED) { |
| 2223 | /* Just select a new current key */ |
| 2224 | index = key_idx; |
Arend van Spriel | 0abb5f21 | 2012-10-22 13:55:32 -0700 | [diff] [blame] | 2225 | err = brcmf_fil_cmd_int_set(ifp, |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 2226 | BRCMF_C_SET_KEY_PRIMARY, index); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2227 | if (err) |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 2228 | brcmf_err("error (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2229 | } |
| 2230 | done: |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 2231 | brcmf_dbg(TRACE, "Exit\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2232 | return err; |
| 2233 | } |
| 2234 | |
| 2235 | static s32 |
Hante Meuleman | 219e0f7 | 2016-02-17 11:27:09 +0100 | [diff] [blame] | 2236 | brcmf_cfg80211_del_key(struct wiphy *wiphy, struct net_device *ndev, |
| 2237 | u8 key_idx, bool pairwise, const u8 *mac_addr) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2238 | { |
Hante Meuleman | 992f606 | 2013-04-02 21:06:17 +0200 | [diff] [blame] | 2239 | struct brcmf_if *ifp = netdev_priv(ndev); |
Hante Meuleman | 240d61a | 2016-02-17 11:27:10 +0100 | [diff] [blame] | 2240 | struct brcmf_wsec_key *key; |
| 2241 | s32 err; |
Hante Meuleman | 219e0f7 | 2016-02-17 11:27:09 +0100 | [diff] [blame] | 2242 | |
| 2243 | brcmf_dbg(TRACE, "Enter\n"); |
Hante Meuleman | 240d61a | 2016-02-17 11:27:10 +0100 | [diff] [blame] | 2244 | brcmf_dbg(CONN, "key index (%d)\n", key_idx); |
| 2245 | |
Hante Meuleman | 219e0f7 | 2016-02-17 11:27:09 +0100 | [diff] [blame] | 2246 | if (!check_vif_up(ifp->vif)) |
| 2247 | return -EIO; |
| 2248 | |
| 2249 | if (key_idx >= BRCMF_MAX_DEFAULT_KEYS) { |
| 2250 | /* we ignore this key index in this case */ |
| 2251 | return -EINVAL; |
| 2252 | } |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2253 | |
Hante Meuleman | 240d61a | 2016-02-17 11:27:10 +0100 | [diff] [blame] | 2254 | key = &ifp->vif->profile.key[key_idx]; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2255 | |
Hante Meuleman | 240d61a | 2016-02-17 11:27:10 +0100 | [diff] [blame] | 2256 | if (key->algo == CRYPTO_ALGO_OFF) { |
| 2257 | brcmf_dbg(CONN, "Ignore clearing of (never configured) key\n"); |
| 2258 | return -EINVAL; |
| 2259 | } |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2260 | |
Hante Meuleman | 240d61a | 2016-02-17 11:27:10 +0100 | [diff] [blame] | 2261 | memset(key, 0, sizeof(*key)); |
| 2262 | key->index = (u32)key_idx; |
| 2263 | key->flags = BRCMF_PRIMARY_KEY; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2264 | |
Hante Meuleman | 240d61a | 2016-02-17 11:27:10 +0100 | [diff] [blame] | 2265 | /* Clear the key/index */ |
| 2266 | err = send_key_to_dongle(ifp, key); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2267 | |
Hante Meuleman | 219e0f7 | 2016-02-17 11:27:09 +0100 | [diff] [blame] | 2268 | brcmf_dbg(TRACE, "Exit\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2269 | return err; |
| 2270 | } |
| 2271 | |
| 2272 | static s32 |
| 2273 | brcmf_cfg80211_add_key(struct wiphy *wiphy, struct net_device *ndev, |
Hante Meuleman | 240d61a | 2016-02-17 11:27:10 +0100 | [diff] [blame] | 2274 | u8 key_idx, bool pairwise, const u8 *mac_addr, |
| 2275 | struct key_params *params) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2276 | { |
Arend van Spriel | 0abb5f21 | 2012-10-22 13:55:32 -0700 | [diff] [blame] | 2277 | struct brcmf_if *ifp = netdev_priv(ndev); |
Hante Meuleman | 118eb30 | 2014-12-21 12:43:49 +0100 | [diff] [blame] | 2278 | struct brcmf_wsec_key *key; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2279 | s32 val; |
| 2280 | s32 wsec; |
Hante Meuleman | 219e0f7 | 2016-02-17 11:27:09 +0100 | [diff] [blame] | 2281 | s32 err; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2282 | u8 keybuf[8]; |
Hante Meuleman | 219e0f7 | 2016-02-17 11:27:09 +0100 | [diff] [blame] | 2283 | bool ext_key; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2284 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 2285 | brcmf_dbg(TRACE, "Enter\n"); |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 2286 | brcmf_dbg(CONN, "key index (%d)\n", key_idx); |
Arend van Spriel | ce81e31 | 2012-10-22 13:55:37 -0700 | [diff] [blame] | 2287 | if (!check_vif_up(ifp->vif)) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2288 | return -EIO; |
| 2289 | |
Hante Meuleman | 118eb30 | 2014-12-21 12:43:49 +0100 | [diff] [blame] | 2290 | if (key_idx >= BRCMF_MAX_DEFAULT_KEYS) { |
| 2291 | /* we ignore this key index in this case */ |
| 2292 | brcmf_err("invalid key index (%d)\n", key_idx); |
| 2293 | return -EINVAL; |
| 2294 | } |
| 2295 | |
Hante Meuleman | 219e0f7 | 2016-02-17 11:27:09 +0100 | [diff] [blame] | 2296 | if (params->key_len == 0) |
| 2297 | return brcmf_cfg80211_del_key(wiphy, ndev, key_idx, pairwise, |
| 2298 | mac_addr); |
| 2299 | |
| 2300 | if (params->key_len > sizeof(key->data)) { |
| 2301 | brcmf_err("Too long key length (%u)\n", params->key_len); |
| 2302 | return -EINVAL; |
| 2303 | } |
| 2304 | |
| 2305 | ext_key = false; |
| 2306 | if (mac_addr && (params->cipher != WLAN_CIPHER_SUITE_WEP40) && |
| 2307 | (params->cipher != WLAN_CIPHER_SUITE_WEP104)) { |
| 2308 | brcmf_dbg(TRACE, "Ext key, mac %pM", mac_addr); |
| 2309 | ext_key = true; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2310 | } |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2311 | |
Hante Meuleman | 118eb30 | 2014-12-21 12:43:49 +0100 | [diff] [blame] | 2312 | key = &ifp->vif->profile.key[key_idx]; |
| 2313 | memset(key, 0, sizeof(*key)); |
Hante Meuleman | 219e0f7 | 2016-02-17 11:27:09 +0100 | [diff] [blame] | 2314 | if ((ext_key) && (!is_multicast_ether_addr(mac_addr))) |
| 2315 | memcpy((char *)&key->ea, (void *)mac_addr, ETH_ALEN); |
Hante Meuleman | 118eb30 | 2014-12-21 12:43:49 +0100 | [diff] [blame] | 2316 | key->len = params->key_len; |
| 2317 | key->index = key_idx; |
Hante Meuleman | 118eb30 | 2014-12-21 12:43:49 +0100 | [diff] [blame] | 2318 | memcpy(key->data, params->key, key->len); |
Hante Meuleman | 219e0f7 | 2016-02-17 11:27:09 +0100 | [diff] [blame] | 2319 | if (!ext_key) |
| 2320 | key->flags = BRCMF_PRIMARY_KEY; |
Hante Meuleman | 118eb30 | 2014-12-21 12:43:49 +0100 | [diff] [blame] | 2321 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2322 | switch (params->cipher) { |
| 2323 | case WLAN_CIPHER_SUITE_WEP40: |
Hante Meuleman | 118eb30 | 2014-12-21 12:43:49 +0100 | [diff] [blame] | 2324 | key->algo = CRYPTO_ALGO_WEP1; |
Hante Meuleman | f09d0c0 | 2012-09-27 14:17:48 +0200 | [diff] [blame] | 2325 | val = WEP_ENABLED; |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 2326 | brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_WEP40\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2327 | break; |
| 2328 | case WLAN_CIPHER_SUITE_WEP104: |
Hante Meuleman | 118eb30 | 2014-12-21 12:43:49 +0100 | [diff] [blame] | 2329 | key->algo = CRYPTO_ALGO_WEP128; |
Hante Meuleman | f09d0c0 | 2012-09-27 14:17:48 +0200 | [diff] [blame] | 2330 | val = WEP_ENABLED; |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 2331 | brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_WEP104\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2332 | break; |
| 2333 | case WLAN_CIPHER_SUITE_TKIP: |
Arend van Spriel | 967fe2c | 2014-03-15 17:18:21 +0100 | [diff] [blame] | 2334 | if (!brcmf_is_apmode(ifp->vif)) { |
Hante Meuleman | 992f606 | 2013-04-02 21:06:17 +0200 | [diff] [blame] | 2335 | brcmf_dbg(CONN, "Swapping RX/TX MIC key\n"); |
Hante Meuleman | 118eb30 | 2014-12-21 12:43:49 +0100 | [diff] [blame] | 2336 | memcpy(keybuf, &key->data[24], sizeof(keybuf)); |
| 2337 | memcpy(&key->data[24], &key->data[16], sizeof(keybuf)); |
| 2338 | memcpy(&key->data[16], keybuf, sizeof(keybuf)); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 2339 | } |
Hante Meuleman | 118eb30 | 2014-12-21 12:43:49 +0100 | [diff] [blame] | 2340 | key->algo = CRYPTO_ALGO_TKIP; |
Hante Meuleman | f09d0c0 | 2012-09-27 14:17:48 +0200 | [diff] [blame] | 2341 | val = TKIP_ENABLED; |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 2342 | brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_TKIP\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2343 | break; |
| 2344 | case WLAN_CIPHER_SUITE_AES_CMAC: |
Hante Meuleman | 118eb30 | 2014-12-21 12:43:49 +0100 | [diff] [blame] | 2345 | key->algo = CRYPTO_ALGO_AES_CCM; |
Hante Meuleman | f09d0c0 | 2012-09-27 14:17:48 +0200 | [diff] [blame] | 2346 | val = AES_ENABLED; |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 2347 | brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_AES_CMAC\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2348 | break; |
| 2349 | case WLAN_CIPHER_SUITE_CCMP: |
Hante Meuleman | 118eb30 | 2014-12-21 12:43:49 +0100 | [diff] [blame] | 2350 | key->algo = CRYPTO_ALGO_AES_CCM; |
Hante Meuleman | f09d0c0 | 2012-09-27 14:17:48 +0200 | [diff] [blame] | 2351 | val = AES_ENABLED; |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 2352 | brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_CCMP\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2353 | break; |
| 2354 | default: |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 2355 | brcmf_err("Invalid cipher (0x%x)\n", params->cipher); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2356 | err = -EINVAL; |
| 2357 | goto done; |
| 2358 | } |
| 2359 | |
Hante Meuleman | 118eb30 | 2014-12-21 12:43:49 +0100 | [diff] [blame] | 2360 | err = send_key_to_dongle(ifp, key); |
Hante Meuleman | 219e0f7 | 2016-02-17 11:27:09 +0100 | [diff] [blame] | 2361 | if (ext_key || err) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2362 | goto done; |
| 2363 | |
Arend van Spriel | 0abb5f21 | 2012-10-22 13:55:32 -0700 | [diff] [blame] | 2364 | err = brcmf_fil_bsscfg_int_get(ifp, "wsec", &wsec); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2365 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 2366 | brcmf_err("get wsec error (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2367 | goto done; |
| 2368 | } |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2369 | wsec |= val; |
Arend van Spriel | 0abb5f21 | 2012-10-22 13:55:32 -0700 | [diff] [blame] | 2370 | err = brcmf_fil_bsscfg_int_set(ifp, "wsec", wsec); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2371 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 2372 | brcmf_err("set wsec error (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2373 | goto done; |
| 2374 | } |
| 2375 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2376 | done: |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 2377 | brcmf_dbg(TRACE, "Exit\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2378 | return err; |
| 2379 | } |
| 2380 | |
| 2381 | static s32 |
Hante Meuleman | 240d61a | 2016-02-17 11:27:10 +0100 | [diff] [blame] | 2382 | brcmf_cfg80211_get_key(struct wiphy *wiphy, struct net_device *ndev, u8 key_idx, |
| 2383 | bool pairwise, const u8 *mac_addr, void *cookie, |
| 2384 | void (*callback)(void *cookie, |
| 2385 | struct key_params *params)) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2386 | { |
| 2387 | struct key_params params; |
Arend van Spriel | 0abb5f21 | 2012-10-22 13:55:32 -0700 | [diff] [blame] | 2388 | struct brcmf_if *ifp = netdev_priv(ndev); |
| 2389 | struct brcmf_cfg80211_profile *profile = &ifp->vif->profile; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2390 | struct brcmf_cfg80211_security *sec; |
| 2391 | s32 wsec; |
| 2392 | s32 err = 0; |
| 2393 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 2394 | brcmf_dbg(TRACE, "Enter\n"); |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 2395 | brcmf_dbg(CONN, "key index (%d)\n", key_idx); |
Arend van Spriel | ce81e31 | 2012-10-22 13:55:37 -0700 | [diff] [blame] | 2396 | if (!check_vif_up(ifp->vif)) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2397 | return -EIO; |
| 2398 | |
| 2399 | memset(¶ms, 0, sizeof(params)); |
| 2400 | |
Arend van Spriel | 0abb5f21 | 2012-10-22 13:55:32 -0700 | [diff] [blame] | 2401 | err = brcmf_fil_bsscfg_int_get(ifp, "wsec", &wsec); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2402 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 2403 | brcmf_err("WLC_GET_WSEC error (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2404 | /* Ignore this error, may happen during DISASSOC */ |
| 2405 | err = -EAGAIN; |
| 2406 | goto done; |
| 2407 | } |
Hante Meuleman | c5bf53a | 2013-04-02 21:06:19 +0200 | [diff] [blame] | 2408 | if (wsec & WEP_ENABLED) { |
Arend van Spriel | 06bb123 | 2012-09-27 14:17:56 +0200 | [diff] [blame] | 2409 | sec = &profile->sec; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2410 | if (sec->cipher_pairwise & WLAN_CIPHER_SUITE_WEP40) { |
| 2411 | params.cipher = WLAN_CIPHER_SUITE_WEP40; |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 2412 | brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_WEP40\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2413 | } else if (sec->cipher_pairwise & WLAN_CIPHER_SUITE_WEP104) { |
| 2414 | params.cipher = WLAN_CIPHER_SUITE_WEP104; |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 2415 | brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_WEP104\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2416 | } |
Hante Meuleman | c5bf53a | 2013-04-02 21:06:19 +0200 | [diff] [blame] | 2417 | } else if (wsec & TKIP_ENABLED) { |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2418 | params.cipher = WLAN_CIPHER_SUITE_TKIP; |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 2419 | brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_TKIP\n"); |
Hante Meuleman | c5bf53a | 2013-04-02 21:06:19 +0200 | [diff] [blame] | 2420 | } else if (wsec & AES_ENABLED) { |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2421 | params.cipher = WLAN_CIPHER_SUITE_AES_CMAC; |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 2422 | brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_AES_CMAC\n"); |
Hante Meuleman | c5bf53a | 2013-04-02 21:06:19 +0200 | [diff] [blame] | 2423 | } else { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 2424 | brcmf_err("Invalid algo (0x%x)\n", wsec); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2425 | err = -EINVAL; |
| 2426 | goto done; |
| 2427 | } |
| 2428 | callback(cookie, ¶ms); |
| 2429 | |
| 2430 | done: |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 2431 | brcmf_dbg(TRACE, "Exit\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2432 | return err; |
| 2433 | } |
| 2434 | |
| 2435 | static s32 |
| 2436 | brcmf_cfg80211_config_default_mgmt_key(struct wiphy *wiphy, |
Hante Meuleman | 240d61a | 2016-02-17 11:27:10 +0100 | [diff] [blame] | 2437 | struct net_device *ndev, u8 key_idx) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2438 | { |
Hante Meuleman | 240d61a | 2016-02-17 11:27:10 +0100 | [diff] [blame] | 2439 | struct brcmf_if *ifp = netdev_priv(ndev); |
| 2440 | |
| 2441 | brcmf_dbg(TRACE, "Enter key_idx %d\n", key_idx); |
| 2442 | |
| 2443 | if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_MFP)) |
| 2444 | return 0; |
| 2445 | |
Arend van Spriel | 647c9ae | 2012-12-05 15:26:01 +0100 | [diff] [blame] | 2446 | brcmf_dbg(INFO, "Not supported\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2447 | |
| 2448 | return -EOPNOTSUPP; |
| 2449 | } |
| 2450 | |
Hante Meuleman | 118eb30 | 2014-12-21 12:43:49 +0100 | [diff] [blame] | 2451 | static void |
| 2452 | brcmf_cfg80211_reconfigure_wep(struct brcmf_if *ifp) |
| 2453 | { |
| 2454 | s32 err; |
| 2455 | u8 key_idx; |
| 2456 | struct brcmf_wsec_key *key; |
| 2457 | s32 wsec; |
| 2458 | |
| 2459 | for (key_idx = 0; key_idx < BRCMF_MAX_DEFAULT_KEYS; key_idx++) { |
| 2460 | key = &ifp->vif->profile.key[key_idx]; |
| 2461 | if ((key->algo == CRYPTO_ALGO_WEP1) || |
| 2462 | (key->algo == CRYPTO_ALGO_WEP128)) |
| 2463 | break; |
| 2464 | } |
| 2465 | if (key_idx == BRCMF_MAX_DEFAULT_KEYS) |
| 2466 | return; |
| 2467 | |
| 2468 | err = send_key_to_dongle(ifp, key); |
| 2469 | if (err) { |
| 2470 | brcmf_err("Setting WEP key failed (%d)\n", err); |
| 2471 | return; |
| 2472 | } |
| 2473 | err = brcmf_fil_bsscfg_int_get(ifp, "wsec", &wsec); |
| 2474 | if (err) { |
| 2475 | brcmf_err("get wsec error (%d)\n", err); |
| 2476 | return; |
| 2477 | } |
| 2478 | wsec |= WEP_ENABLED; |
| 2479 | err = brcmf_fil_bsscfg_int_set(ifp, "wsec", wsec); |
| 2480 | if (err) |
| 2481 | brcmf_err("set wsec error (%d)\n", err); |
| 2482 | } |
| 2483 | |
Arend van Spriel | 1f0dc59 | 2015-06-11 00:12:19 +0200 | [diff] [blame] | 2484 | static void brcmf_convert_sta_flags(u32 fw_sta_flags, struct station_info *si) |
| 2485 | { |
| 2486 | struct nl80211_sta_flag_update *sfu; |
| 2487 | |
| 2488 | brcmf_dbg(TRACE, "flags %08x\n", fw_sta_flags); |
| 2489 | si->filled |= BIT(NL80211_STA_INFO_STA_FLAGS); |
| 2490 | sfu = &si->sta_flags; |
| 2491 | sfu->mask = BIT(NL80211_STA_FLAG_WME) | |
| 2492 | BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 2493 | BIT(NL80211_STA_FLAG_ASSOCIATED) | |
| 2494 | BIT(NL80211_STA_FLAG_AUTHORIZED); |
| 2495 | if (fw_sta_flags & BRCMF_STA_WME) |
| 2496 | sfu->set |= BIT(NL80211_STA_FLAG_WME); |
| 2497 | if (fw_sta_flags & BRCMF_STA_AUTHE) |
| 2498 | sfu->set |= BIT(NL80211_STA_FLAG_AUTHENTICATED); |
| 2499 | if (fw_sta_flags & BRCMF_STA_ASSOC) |
| 2500 | sfu->set |= BIT(NL80211_STA_FLAG_ASSOCIATED); |
| 2501 | if (fw_sta_flags & BRCMF_STA_AUTHO) |
| 2502 | sfu->set |= BIT(NL80211_STA_FLAG_AUTHORIZED); |
| 2503 | } |
| 2504 | |
| 2505 | static void brcmf_fill_bss_param(struct brcmf_if *ifp, struct station_info *si) |
| 2506 | { |
| 2507 | struct { |
| 2508 | __le32 len; |
| 2509 | struct brcmf_bss_info_le bss_le; |
| 2510 | } *buf; |
| 2511 | u16 capability; |
| 2512 | int err; |
| 2513 | |
| 2514 | buf = kzalloc(WL_BSS_INFO_MAX, GFP_KERNEL); |
| 2515 | if (!buf) |
| 2516 | return; |
| 2517 | |
| 2518 | buf->len = cpu_to_le32(WL_BSS_INFO_MAX); |
| 2519 | err = brcmf_fil_cmd_data_get(ifp, BRCMF_C_GET_BSS_INFO, buf, |
| 2520 | WL_BSS_INFO_MAX); |
| 2521 | if (err) { |
| 2522 | brcmf_err("Failed to get bss info (%d)\n", err); |
Rafał Miłecki | 23e9c12 | 2016-09-21 08:23:24 +0200 | [diff] [blame] | 2523 | goto out_kfree; |
Arend van Spriel | 1f0dc59 | 2015-06-11 00:12:19 +0200 | [diff] [blame] | 2524 | } |
| 2525 | si->filled |= BIT(NL80211_STA_INFO_BSS_PARAM); |
| 2526 | si->bss_param.beacon_interval = le16_to_cpu(buf->bss_le.beacon_period); |
| 2527 | si->bss_param.dtim_period = buf->bss_le.dtim_period; |
| 2528 | capability = le16_to_cpu(buf->bss_le.capability); |
| 2529 | if (capability & IEEE80211_HT_STBC_PARAM_DUAL_CTS_PROT) |
| 2530 | si->bss_param.flags |= BSS_PARAM_FLAGS_CTS_PROT; |
| 2531 | if (capability & WLAN_CAPABILITY_SHORT_PREAMBLE) |
| 2532 | si->bss_param.flags |= BSS_PARAM_FLAGS_SHORT_PREAMBLE; |
| 2533 | if (capability & WLAN_CAPABILITY_SHORT_SLOT_TIME) |
| 2534 | si->bss_param.flags |= BSS_PARAM_FLAGS_SHORT_SLOT_TIME; |
Rafał Miłecki | 23e9c12 | 2016-09-21 08:23:24 +0200 | [diff] [blame] | 2535 | |
| 2536 | out_kfree: |
| 2537 | kfree(buf); |
Arend van Spriel | 1f0dc59 | 2015-06-11 00:12:19 +0200 | [diff] [blame] | 2538 | } |
| 2539 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2540 | static s32 |
Hante Meuleman | 3f5893d | 2016-01-02 09:41:37 +0100 | [diff] [blame] | 2541 | brcmf_cfg80211_get_station_ibss(struct brcmf_if *ifp, |
| 2542 | struct station_info *sinfo) |
| 2543 | { |
| 2544 | struct brcmf_scb_val_le scbval; |
| 2545 | struct brcmf_pktcnt_le pktcnt; |
| 2546 | s32 err; |
| 2547 | u32 rate; |
| 2548 | u32 rssi; |
| 2549 | |
| 2550 | /* Get the current tx rate */ |
| 2551 | err = brcmf_fil_cmd_int_get(ifp, BRCMF_C_GET_RATE, &rate); |
| 2552 | if (err < 0) { |
| 2553 | brcmf_err("BRCMF_C_GET_RATE error (%d)\n", err); |
| 2554 | return err; |
| 2555 | } |
| 2556 | sinfo->filled |= BIT(NL80211_STA_INFO_TX_BITRATE); |
| 2557 | sinfo->txrate.legacy = rate * 5; |
| 2558 | |
| 2559 | memset(&scbval, 0, sizeof(scbval)); |
| 2560 | err = brcmf_fil_cmd_data_get(ifp, BRCMF_C_GET_RSSI, &scbval, |
| 2561 | sizeof(scbval)); |
| 2562 | if (err) { |
| 2563 | brcmf_err("BRCMF_C_GET_RSSI error (%d)\n", err); |
| 2564 | return err; |
| 2565 | } |
| 2566 | rssi = le32_to_cpu(scbval.val); |
| 2567 | sinfo->filled |= BIT(NL80211_STA_INFO_SIGNAL); |
| 2568 | sinfo->signal = rssi; |
| 2569 | |
| 2570 | err = brcmf_fil_cmd_data_get(ifp, BRCMF_C_GET_GET_PKTCNTS, &pktcnt, |
| 2571 | sizeof(pktcnt)); |
| 2572 | if (err) { |
| 2573 | brcmf_err("BRCMF_C_GET_GET_PKTCNTS error (%d)\n", err); |
| 2574 | return err; |
| 2575 | } |
| 2576 | sinfo->filled |= BIT(NL80211_STA_INFO_RX_PACKETS) | |
| 2577 | BIT(NL80211_STA_INFO_RX_DROP_MISC) | |
| 2578 | BIT(NL80211_STA_INFO_TX_PACKETS) | |
| 2579 | BIT(NL80211_STA_INFO_TX_FAILED); |
| 2580 | sinfo->rx_packets = le32_to_cpu(pktcnt.rx_good_pkt); |
| 2581 | sinfo->rx_dropped_misc = le32_to_cpu(pktcnt.rx_bad_pkt); |
| 2582 | sinfo->tx_packets = le32_to_cpu(pktcnt.tx_good_pkt); |
| 2583 | sinfo->tx_failed = le32_to_cpu(pktcnt.tx_bad_pkt); |
| 2584 | |
| 2585 | return 0; |
| 2586 | } |
| 2587 | |
| 2588 | static s32 |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2589 | brcmf_cfg80211_get_station(struct wiphy *wiphy, struct net_device *ndev, |
Johannes Berg | 3b3a016 | 2014-05-19 17:19:31 +0200 | [diff] [blame] | 2590 | const u8 *mac, struct station_info *sinfo) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2591 | { |
Arend van Spriel | 0abb5f21 | 2012-10-22 13:55:32 -0700 | [diff] [blame] | 2592 | struct brcmf_if *ifp = netdev_priv(ndev); |
Jaap Jan Meijer | 94abd77 | 2016-05-12 18:25:08 +0200 | [diff] [blame] | 2593 | struct brcmf_scb_val_le scb_val; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2594 | s32 err = 0; |
Hante Meuleman | 81f5dcb | 2012-10-22 10:36:14 -0700 | [diff] [blame] | 2595 | struct brcmf_sta_info_le sta_info_le; |
Arend van Spriel | 1f0dc59 | 2015-06-11 00:12:19 +0200 | [diff] [blame] | 2596 | u32 sta_flags; |
| 2597 | u32 is_tdls_peer; |
Hante Meuleman | cae355d | 2015-10-08 20:33:17 +0200 | [diff] [blame] | 2598 | s32 total_rssi; |
| 2599 | s32 count_rssi; |
Jaap Jan Meijer | 94abd77 | 2016-05-12 18:25:08 +0200 | [diff] [blame] | 2600 | int rssi; |
Hante Meuleman | cae355d | 2015-10-08 20:33:17 +0200 | [diff] [blame] | 2601 | u32 i; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2602 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 2603 | brcmf_dbg(TRACE, "Enter, MAC %pM\n", mac); |
Arend van Spriel | ce81e31 | 2012-10-22 13:55:37 -0700 | [diff] [blame] | 2604 | if (!check_vif_up(ifp->vif)) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2605 | return -EIO; |
| 2606 | |
Hante Meuleman | 3f5893d | 2016-01-02 09:41:37 +0100 | [diff] [blame] | 2607 | if (brcmf_is_ibssmode(ifp->vif)) |
| 2608 | return brcmf_cfg80211_get_station_ibss(ifp, sinfo); |
| 2609 | |
Arend van Spriel | 1f0dc59 | 2015-06-11 00:12:19 +0200 | [diff] [blame] | 2610 | memset(&sta_info_le, 0, sizeof(sta_info_le)); |
| 2611 | memcpy(&sta_info_le, mac, ETH_ALEN); |
| 2612 | err = brcmf_fil_iovar_data_get(ifp, "tdls_sta_info", |
| 2613 | &sta_info_le, |
| 2614 | sizeof(sta_info_le)); |
| 2615 | is_tdls_peer = !err; |
| 2616 | if (err) { |
Arend van Spriel | 0abb5f21 | 2012-10-22 13:55:32 -0700 | [diff] [blame] | 2617 | err = brcmf_fil_iovar_data_get(ifp, "sta_info", |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 2618 | &sta_info_le, |
Hante Meuleman | 81f5dcb | 2012-10-22 10:36:14 -0700 | [diff] [blame] | 2619 | sizeof(sta_info_le)); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 2620 | if (err < 0) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 2621 | brcmf_err("GET STA INFO failed, %d\n", err); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 2622 | goto done; |
Hante Meuleman | 7f6c562 | 2012-08-30 10:05:37 +0200 | [diff] [blame] | 2623 | } |
Arend van Spriel | 1f0dc59 | 2015-06-11 00:12:19 +0200 | [diff] [blame] | 2624 | } |
| 2625 | brcmf_dbg(TRACE, "version %d\n", le16_to_cpu(sta_info_le.ver)); |
| 2626 | sinfo->filled = BIT(NL80211_STA_INFO_INACTIVE_TIME); |
| 2627 | sinfo->inactive_time = le32_to_cpu(sta_info_le.idle) * 1000; |
| 2628 | sta_flags = le32_to_cpu(sta_info_le.flags); |
| 2629 | brcmf_convert_sta_flags(sta_flags, sinfo); |
| 2630 | sinfo->sta_flags.mask |= BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 2631 | if (is_tdls_peer) |
| 2632 | sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 2633 | else |
| 2634 | sinfo->sta_flags.set &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 2635 | if (sta_flags & BRCMF_STA_ASSOC) { |
| 2636 | sinfo->filled |= BIT(NL80211_STA_INFO_CONNECTED_TIME); |
| 2637 | sinfo->connected_time = le32_to_cpu(sta_info_le.in); |
| 2638 | brcmf_fill_bss_param(ifp, sinfo); |
| 2639 | } |
| 2640 | if (sta_flags & BRCMF_STA_SCBSTATS) { |
| 2641 | sinfo->filled |= BIT(NL80211_STA_INFO_TX_FAILED); |
| 2642 | sinfo->tx_failed = le32_to_cpu(sta_info_le.tx_failures); |
| 2643 | sinfo->filled |= BIT(NL80211_STA_INFO_TX_PACKETS); |
| 2644 | sinfo->tx_packets = le32_to_cpu(sta_info_le.tx_pkts); |
| 2645 | sinfo->tx_packets += le32_to_cpu(sta_info_le.tx_mcast_pkts); |
| 2646 | sinfo->filled |= BIT(NL80211_STA_INFO_RX_PACKETS); |
| 2647 | sinfo->rx_packets = le32_to_cpu(sta_info_le.rx_ucast_pkts); |
| 2648 | sinfo->rx_packets += le32_to_cpu(sta_info_le.rx_mcast_pkts); |
| 2649 | if (sinfo->tx_packets) { |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 2650 | sinfo->filled |= BIT(NL80211_STA_INFO_TX_BITRATE); |
Hante Meuleman | 124d517 | 2015-10-08 20:33:16 +0200 | [diff] [blame] | 2651 | sinfo->txrate.legacy = |
| 2652 | le32_to_cpu(sta_info_le.tx_rate) / 100; |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 2653 | } |
Arend van Spriel | 1f0dc59 | 2015-06-11 00:12:19 +0200 | [diff] [blame] | 2654 | if (sinfo->rx_packets) { |
| 2655 | sinfo->filled |= BIT(NL80211_STA_INFO_RX_BITRATE); |
Hante Meuleman | 124d517 | 2015-10-08 20:33:16 +0200 | [diff] [blame] | 2656 | sinfo->rxrate.legacy = |
| 2657 | le32_to_cpu(sta_info_le.rx_rate) / 100; |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 2658 | } |
Arend van Spriel | 1f0dc59 | 2015-06-11 00:12:19 +0200 | [diff] [blame] | 2659 | if (le16_to_cpu(sta_info_le.ver) >= 4) { |
| 2660 | sinfo->filled |= BIT(NL80211_STA_INFO_TX_BYTES); |
| 2661 | sinfo->tx_bytes = le64_to_cpu(sta_info_le.tx_tot_bytes); |
| 2662 | sinfo->filled |= BIT(NL80211_STA_INFO_RX_BYTES); |
| 2663 | sinfo->rx_bytes = le64_to_cpu(sta_info_le.rx_tot_bytes); |
| 2664 | } |
Hante Meuleman | cae355d | 2015-10-08 20:33:17 +0200 | [diff] [blame] | 2665 | total_rssi = 0; |
| 2666 | count_rssi = 0; |
| 2667 | for (i = 0; i < BRCMF_ANT_MAX; i++) { |
| 2668 | if (sta_info_le.rssi[i]) { |
| 2669 | sinfo->chain_signal_avg[count_rssi] = |
| 2670 | sta_info_le.rssi[i]; |
| 2671 | sinfo->chain_signal[count_rssi] = |
| 2672 | sta_info_le.rssi[i]; |
| 2673 | total_rssi += sta_info_le.rssi[i]; |
| 2674 | count_rssi++; |
| 2675 | } |
| 2676 | } |
| 2677 | if (count_rssi) { |
| 2678 | sinfo->filled |= BIT(NL80211_STA_INFO_CHAIN_SIGNAL); |
| 2679 | sinfo->chains = count_rssi; |
| 2680 | |
| 2681 | sinfo->filled |= BIT(NL80211_STA_INFO_SIGNAL); |
| 2682 | total_rssi /= count_rssi; |
| 2683 | sinfo->signal = total_rssi; |
Jaap Jan Meijer | 94abd77 | 2016-05-12 18:25:08 +0200 | [diff] [blame] | 2684 | } else if (test_bit(BRCMF_VIF_STATUS_CONNECTED, |
| 2685 | &ifp->vif->sme_state)) { |
| 2686 | memset(&scb_val, 0, sizeof(scb_val)); |
| 2687 | err = brcmf_fil_cmd_data_get(ifp, BRCMF_C_GET_RSSI, |
| 2688 | &scb_val, sizeof(scb_val)); |
| 2689 | if (err) { |
| 2690 | brcmf_err("Could not get rssi (%d)\n", err); |
| 2691 | goto done; |
| 2692 | } else { |
| 2693 | rssi = le32_to_cpu(scb_val.val); |
| 2694 | sinfo->filled |= BIT(NL80211_STA_INFO_SIGNAL); |
| 2695 | sinfo->signal = rssi; |
| 2696 | brcmf_dbg(CONN, "RSSI %d dBm\n", rssi); |
| 2697 | } |
Hante Meuleman | cae355d | 2015-10-08 20:33:17 +0200 | [diff] [blame] | 2698 | } |
Arend van Spriel | 1f0dc59 | 2015-06-11 00:12:19 +0200 | [diff] [blame] | 2699 | } |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2700 | done: |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 2701 | brcmf_dbg(TRACE, "Exit\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2702 | return err; |
| 2703 | } |
| 2704 | |
Hante Meuleman | bf2a7e0 | 2015-10-08 20:33:18 +0200 | [diff] [blame] | 2705 | static int |
| 2706 | brcmf_cfg80211_dump_station(struct wiphy *wiphy, struct net_device *ndev, |
| 2707 | int idx, u8 *mac, struct station_info *sinfo) |
| 2708 | { |
| 2709 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); |
| 2710 | struct brcmf_if *ifp = netdev_priv(ndev); |
| 2711 | s32 err; |
| 2712 | |
| 2713 | brcmf_dbg(TRACE, "Enter, idx %d\n", idx); |
| 2714 | |
| 2715 | if (idx == 0) { |
| 2716 | cfg->assoclist.count = cpu_to_le32(BRCMF_MAX_ASSOCLIST); |
| 2717 | err = brcmf_fil_cmd_data_get(ifp, BRCMF_C_GET_ASSOCLIST, |
| 2718 | &cfg->assoclist, |
| 2719 | sizeof(cfg->assoclist)); |
| 2720 | if (err) { |
| 2721 | brcmf_err("BRCMF_C_GET_ASSOCLIST unsupported, err=%d\n", |
| 2722 | err); |
| 2723 | cfg->assoclist.count = 0; |
| 2724 | return -EOPNOTSUPP; |
| 2725 | } |
| 2726 | } |
| 2727 | if (idx < le32_to_cpu(cfg->assoclist.count)) { |
| 2728 | memcpy(mac, cfg->assoclist.mac[idx], ETH_ALEN); |
| 2729 | return brcmf_cfg80211_get_station(wiphy, ndev, mac, sinfo); |
| 2730 | } |
| 2731 | return -ENOENT; |
| 2732 | } |
| 2733 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2734 | static s32 |
| 2735 | brcmf_cfg80211_set_power_mgmt(struct wiphy *wiphy, struct net_device *ndev, |
| 2736 | bool enabled, s32 timeout) |
| 2737 | { |
| 2738 | s32 pm; |
| 2739 | s32 err = 0; |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 2740 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 2741 | struct brcmf_if *ifp = netdev_priv(ndev); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2742 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 2743 | brcmf_dbg(TRACE, "Enter\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2744 | |
| 2745 | /* |
| 2746 | * Powersave enable/disable request is coming from the |
| 2747 | * cfg80211 even before the interface is up. In that |
| 2748 | * scenario, driver will be storing the power save |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 2749 | * preference in cfg struct to apply this to |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2750 | * FW later while initializing the dongle |
| 2751 | */ |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 2752 | cfg->pwr_save = enabled; |
Arend van Spriel | ce81e31 | 2012-10-22 13:55:37 -0700 | [diff] [blame] | 2753 | if (!check_vif_up(ifp->vif)) { |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2754 | |
Arend van Spriel | 647c9ae | 2012-12-05 15:26:01 +0100 | [diff] [blame] | 2755 | brcmf_dbg(INFO, "Device is not ready, storing the value in cfg_info struct\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2756 | goto done; |
| 2757 | } |
| 2758 | |
| 2759 | pm = enabled ? PM_FAST : PM_OFF; |
Hante Meuleman | 102fd0d | 2013-05-27 21:09:59 +0200 | [diff] [blame] | 2760 | /* Do not enable the power save after assoc if it is a p2p interface */ |
| 2761 | if (ifp->vif->wdev.iftype == NL80211_IFTYPE_P2P_CLIENT) { |
| 2762 | brcmf_dbg(INFO, "Do not enable power save for P2P clients\n"); |
| 2763 | pm = PM_OFF; |
| 2764 | } |
Arend van Spriel | 647c9ae | 2012-12-05 15:26:01 +0100 | [diff] [blame] | 2765 | brcmf_dbg(INFO, "power save %s\n", (pm ? "enabled" : "disabled")); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2766 | |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 2767 | err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_PM, pm); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2768 | if (err) { |
| 2769 | if (err == -ENODEV) |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 2770 | brcmf_err("net_device is not ready yet\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2771 | else |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 2772 | brcmf_err("error (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2773 | } |
| 2774 | done: |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 2775 | brcmf_dbg(TRACE, "Exit\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2776 | return err; |
| 2777 | } |
| 2778 | |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 2779 | static s32 brcmf_inform_single_bss(struct brcmf_cfg80211_info *cfg, |
Roland Vossen | d34bf64 | 2011-10-18 14:03:01 +0200 | [diff] [blame] | 2780 | struct brcmf_bss_info_le *bi) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2781 | { |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 2782 | struct wiphy *wiphy = cfg_to_wiphy(cfg); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2783 | struct ieee80211_channel *notify_channel; |
| 2784 | struct cfg80211_bss *bss; |
| 2785 | struct ieee80211_supported_band *band; |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 2786 | struct brcmu_chan ch; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2787 | u16 channel; |
| 2788 | u32 freq; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2789 | u16 notify_capability; |
| 2790 | u16 notify_interval; |
| 2791 | u8 *notify_ie; |
| 2792 | size_t notify_ielen; |
| 2793 | s32 notify_signal; |
| 2794 | |
| 2795 | if (le32_to_cpu(bi->length) > WL_BSS_INFO_MAX) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 2796 | brcmf_err("Bss info is larger than buffer. Discarding\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2797 | return 0; |
| 2798 | } |
| 2799 | |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 2800 | if (!bi->ctl_ch) { |
| 2801 | ch.chspec = le16_to_cpu(bi->chanspec); |
| 2802 | cfg->d11inf.decchspec(&ch); |
Rafał Miłecki | 4712d88 | 2016-05-20 13:38:57 +0200 | [diff] [blame] | 2803 | bi->ctl_ch = ch.control_ch_num; |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 2804 | } |
| 2805 | channel = bi->ctl_ch; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2806 | |
| 2807 | if (channel <= CH_MAX_2G_CHANNEL) |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 2808 | band = wiphy->bands[NL80211_BAND_2GHZ]; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2809 | else |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 2810 | band = wiphy->bands[NL80211_BAND_5GHZ]; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2811 | |
| 2812 | freq = ieee80211_channel_to_frequency(channel, band->band); |
| 2813 | notify_channel = ieee80211_get_channel(wiphy, freq); |
| 2814 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2815 | notify_capability = le16_to_cpu(bi->capability); |
| 2816 | notify_interval = le16_to_cpu(bi->beacon_period); |
| 2817 | notify_ie = (u8 *)bi + le16_to_cpu(bi->ie_offset); |
| 2818 | notify_ielen = le32_to_cpu(bi->ie_length); |
| 2819 | notify_signal = (s16)le16_to_cpu(bi->RSSI) * 100; |
| 2820 | |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 2821 | brcmf_dbg(CONN, "bssid: %pM\n", bi->BSSID); |
| 2822 | brcmf_dbg(CONN, "Channel: %d(%d)\n", channel, freq); |
| 2823 | brcmf_dbg(CONN, "Capability: %X\n", notify_capability); |
| 2824 | brcmf_dbg(CONN, "Beacon interval: %d\n", notify_interval); |
| 2825 | brcmf_dbg(CONN, "Signal: %d\n", notify_signal); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2826 | |
Johannes Berg | 5bc8c1f | 2014-08-12 21:01:28 +0200 | [diff] [blame] | 2827 | bss = cfg80211_inform_bss(wiphy, notify_channel, |
| 2828 | CFG80211_BSS_FTYPE_UNKNOWN, |
| 2829 | (const u8 *)bi->BSSID, |
| 2830 | 0, notify_capability, |
| 2831 | notify_interval, notify_ie, |
| 2832 | notify_ielen, notify_signal, |
| 2833 | GFP_KERNEL); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2834 | |
Franky Lin | e78946e | 2011-11-10 20:30:34 +0100 | [diff] [blame] | 2835 | if (!bss) |
| 2836 | return -ENOMEM; |
| 2837 | |
Johannes Berg | 5b112d3 | 2013-02-01 01:49:58 +0100 | [diff] [blame] | 2838 | cfg80211_put_bss(wiphy, bss); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2839 | |
Peter Senna Tschudin | 12f3237 | 2014-05-31 10:14:06 -0300 | [diff] [blame] | 2840 | return 0; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2841 | } |
| 2842 | |
Roland Vossen | 6f09be0 | 2011-10-18 14:03:02 +0200 | [diff] [blame] | 2843 | static struct brcmf_bss_info_le * |
| 2844 | next_bss_le(struct brcmf_scan_results *list, struct brcmf_bss_info_le *bss) |
| 2845 | { |
| 2846 | if (bss == NULL) |
| 2847 | return list->bss_info_le; |
| 2848 | return (struct brcmf_bss_info_le *)((unsigned long)bss + |
| 2849 | le32_to_cpu(bss->length)); |
| 2850 | } |
| 2851 | |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 2852 | static s32 brcmf_inform_bss(struct brcmf_cfg80211_info *cfg) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2853 | { |
| 2854 | struct brcmf_scan_results *bss_list; |
Roland Vossen | d34bf64 | 2011-10-18 14:03:01 +0200 | [diff] [blame] | 2855 | struct brcmf_bss_info_le *bi = NULL; /* must be initialized */ |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2856 | s32 err = 0; |
| 2857 | int i; |
| 2858 | |
Hante Meuleman | ef8596e | 2014-09-30 10:23:13 +0200 | [diff] [blame] | 2859 | bss_list = (struct brcmf_scan_results *)cfg->escan_info.escan_buf; |
Arend van Spriel | 0ecd816 | 2012-11-05 16:22:11 -0800 | [diff] [blame] | 2860 | if (bss_list->count != 0 && |
| 2861 | bss_list->version != BRCMF_BSS_INFO_VERSION) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 2862 | brcmf_err("Version %d != WL_BSS_INFO_VERSION\n", |
| 2863 | bss_list->version); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2864 | return -EOPNOTSUPP; |
| 2865 | } |
Arend van Spriel | 4e8a008 | 2012-12-05 15:26:03 +0100 | [diff] [blame] | 2866 | brcmf_dbg(SCAN, "scanned AP count (%d)\n", bss_list->count); |
Hante Meuleman | f0799895 | 2012-11-05 16:22:13 -0800 | [diff] [blame] | 2867 | for (i = 0; i < bss_list->count; i++) { |
Roland Vossen | 6f09be0 | 2011-10-18 14:03:02 +0200 | [diff] [blame] | 2868 | bi = next_bss_le(bss_list, bi); |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 2869 | err = brcmf_inform_single_bss(cfg, bi); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2870 | if (err) |
| 2871 | break; |
| 2872 | } |
| 2873 | return err; |
| 2874 | } |
| 2875 | |
Hante Meuleman | b0a7908 | 2015-12-10 13:43:07 +0100 | [diff] [blame] | 2876 | static s32 brcmf_inform_ibss(struct brcmf_cfg80211_info *cfg, |
| 2877 | struct net_device *ndev, const u8 *bssid) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2878 | { |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 2879 | struct wiphy *wiphy = cfg_to_wiphy(cfg); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2880 | struct ieee80211_channel *notify_channel; |
Roland Vossen | d34bf64 | 2011-10-18 14:03:01 +0200 | [diff] [blame] | 2881 | struct brcmf_bss_info_le *bi = NULL; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2882 | struct ieee80211_supported_band *band; |
Franky Lin | e78946e | 2011-11-10 20:30:34 +0100 | [diff] [blame] | 2883 | struct cfg80211_bss *bss; |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 2884 | struct brcmu_chan ch; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2885 | u8 *buf = NULL; |
| 2886 | s32 err = 0; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2887 | u32 freq; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2888 | u16 notify_capability; |
| 2889 | u16 notify_interval; |
| 2890 | u8 *notify_ie; |
| 2891 | size_t notify_ielen; |
| 2892 | s32 notify_signal; |
| 2893 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 2894 | brcmf_dbg(TRACE, "Enter\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2895 | |
| 2896 | buf = kzalloc(WL_BSS_INFO_MAX, GFP_KERNEL); |
| 2897 | if (buf == NULL) { |
| 2898 | err = -ENOMEM; |
| 2899 | goto CleanUp; |
| 2900 | } |
| 2901 | |
| 2902 | *(__le32 *)buf = cpu_to_le32(WL_BSS_INFO_MAX); |
| 2903 | |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 2904 | err = brcmf_fil_cmd_data_get(netdev_priv(ndev), BRCMF_C_GET_BSS_INFO, |
| 2905 | buf, WL_BSS_INFO_MAX); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2906 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 2907 | brcmf_err("WLC_GET_BSS_INFO failed: %d\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2908 | goto CleanUp; |
| 2909 | } |
| 2910 | |
Roland Vossen | d34bf64 | 2011-10-18 14:03:01 +0200 | [diff] [blame] | 2911 | bi = (struct brcmf_bss_info_le *)(buf + 4); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2912 | |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 2913 | ch.chspec = le16_to_cpu(bi->chanspec); |
| 2914 | cfg->d11inf.decchspec(&ch); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2915 | |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 2916 | if (ch.band == BRCMU_CHAN_BAND_2G) |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 2917 | band = wiphy->bands[NL80211_BAND_2GHZ]; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2918 | else |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 2919 | band = wiphy->bands[NL80211_BAND_5GHZ]; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2920 | |
Rafał Miłecki | 4712d88 | 2016-05-20 13:38:57 +0200 | [diff] [blame] | 2921 | freq = ieee80211_channel_to_frequency(ch.control_ch_num, band->band); |
Hante Meuleman | b0a7908 | 2015-12-10 13:43:07 +0100 | [diff] [blame] | 2922 | cfg->channel = freq; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2923 | notify_channel = ieee80211_get_channel(wiphy, freq); |
| 2924 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2925 | notify_capability = le16_to_cpu(bi->capability); |
| 2926 | notify_interval = le16_to_cpu(bi->beacon_period); |
| 2927 | notify_ie = (u8 *)bi + le16_to_cpu(bi->ie_offset); |
| 2928 | notify_ielen = le32_to_cpu(bi->ie_length); |
| 2929 | notify_signal = (s16)le16_to_cpu(bi->RSSI) * 100; |
| 2930 | |
Rafał Miłecki | 4712d88 | 2016-05-20 13:38:57 +0200 | [diff] [blame] | 2931 | brcmf_dbg(CONN, "channel: %d(%d)\n", ch.control_ch_num, freq); |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 2932 | brcmf_dbg(CONN, "capability: %X\n", notify_capability); |
| 2933 | brcmf_dbg(CONN, "beacon interval: %d\n", notify_interval); |
| 2934 | brcmf_dbg(CONN, "signal: %d\n", notify_signal); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2935 | |
Johannes Berg | 5bc8c1f | 2014-08-12 21:01:28 +0200 | [diff] [blame] | 2936 | bss = cfg80211_inform_bss(wiphy, notify_channel, |
| 2937 | CFG80211_BSS_FTYPE_UNKNOWN, bssid, 0, |
| 2938 | notify_capability, notify_interval, |
| 2939 | notify_ie, notify_ielen, notify_signal, |
| 2940 | GFP_KERNEL); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2941 | |
Franky Lin | e78946e | 2011-11-10 20:30:34 +0100 | [diff] [blame] | 2942 | if (!bss) { |
| 2943 | err = -ENOMEM; |
| 2944 | goto CleanUp; |
| 2945 | } |
| 2946 | |
Johannes Berg | 5b112d3 | 2013-02-01 01:49:58 +0100 | [diff] [blame] | 2947 | cfg80211_put_bss(wiphy, bss); |
Franky Lin | e78946e | 2011-11-10 20:30:34 +0100 | [diff] [blame] | 2948 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2949 | CleanUp: |
| 2950 | |
| 2951 | kfree(buf); |
| 2952 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 2953 | brcmf_dbg(TRACE, "Exit\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2954 | |
| 2955 | return err; |
| 2956 | } |
| 2957 | |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 2958 | static s32 brcmf_update_bss_info(struct brcmf_cfg80211_info *cfg, |
| 2959 | struct brcmf_if *ifp) |
Alwin Beukers | f8e4b41 | 2011-10-12 20:51:28 +0200 | [diff] [blame] | 2960 | { |
Roland Vossen | d34bf64 | 2011-10-18 14:03:01 +0200 | [diff] [blame] | 2961 | struct brcmf_bss_info_le *bi; |
Johannes Berg | 4b5800f | 2014-01-15 14:55:59 +0100 | [diff] [blame] | 2962 | const struct brcmf_tlv *tim; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2963 | u16 beacon_interval; |
| 2964 | u8 dtim_period; |
| 2965 | size_t ie_len; |
| 2966 | u8 *ie; |
| 2967 | s32 err = 0; |
| 2968 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 2969 | brcmf_dbg(TRACE, "Enter\n"); |
Arend van Spriel | 128ce3b | 2012-11-28 21:44:12 +0100 | [diff] [blame] | 2970 | if (brcmf_is_ibssmode(ifp->vif)) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2971 | return err; |
| 2972 | |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 2973 | *(__le32 *)cfg->extra_buf = cpu_to_le32(WL_EXTRA_BUF_MAX); |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 2974 | err = brcmf_fil_cmd_data_get(ifp, BRCMF_C_GET_BSS_INFO, |
Hante Meuleman | 81f5dcb | 2012-10-22 10:36:14 -0700 | [diff] [blame] | 2975 | cfg->extra_buf, WL_EXTRA_BUF_MAX); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2976 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 2977 | brcmf_err("Could not get bss info %d\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2978 | goto update_bss_info_out; |
| 2979 | } |
| 2980 | |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 2981 | bi = (struct brcmf_bss_info_le *)(cfg->extra_buf + 4); |
| 2982 | err = brcmf_inform_single_bss(cfg, bi); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2983 | if (err) |
| 2984 | goto update_bss_info_out; |
| 2985 | |
| 2986 | ie = ((u8 *)bi) + le16_to_cpu(bi->ie_offset); |
| 2987 | ie_len = le32_to_cpu(bi->ie_length); |
| 2988 | beacon_interval = le16_to_cpu(bi->beacon_period); |
| 2989 | |
Alwin Beukers | f8e4b41 | 2011-10-12 20:51:28 +0200 | [diff] [blame] | 2990 | tim = brcmf_parse_tlvs(ie, ie_len, WLAN_EID_TIM); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2991 | if (tim) |
| 2992 | dtim_period = tim->data[1]; |
| 2993 | else { |
| 2994 | /* |
| 2995 | * active scan was done so we could not get dtim |
| 2996 | * information out of probe response. |
| 2997 | * so we speficially query dtim information to dongle. |
| 2998 | */ |
| 2999 | u32 var; |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 3000 | err = brcmf_fil_iovar_int_get(ifp, "dtim_assoc", &var); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3001 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 3002 | brcmf_err("wl dtim_assoc failed (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3003 | goto update_bss_info_out; |
| 3004 | } |
| 3005 | dtim_period = (u8)var; |
| 3006 | } |
| 3007 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3008 | update_bss_info_out: |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 3009 | brcmf_dbg(TRACE, "Exit"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3010 | return err; |
| 3011 | } |
| 3012 | |
Hante Meuleman | 18e2f61 | 2013-02-08 15:53:49 +0100 | [diff] [blame] | 3013 | void brcmf_abort_scanning(struct brcmf_cfg80211_info *cfg) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3014 | { |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 3015 | struct escan_info *escan = &cfg->escan_info; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3016 | |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 3017 | set_bit(BRCMF_SCAN_STATUS_ABORT, &cfg->scan_status); |
Arend Van Spriel | fa85b30 | 2016-11-23 10:25:25 +0000 | [diff] [blame] | 3018 | if (cfg->internal_escan || cfg->scan_request) { |
Arend van Spriel | 108a4be | 2012-09-19 22:21:07 +0200 | [diff] [blame] | 3019 | escan->escan_state = WL_ESCAN_STATE_IDLE; |
Arend van Spriel | a0f472a | 2013-04-05 10:57:49 +0200 | [diff] [blame] | 3020 | brcmf_notify_escan_complete(cfg, escan->ifp, true, true); |
Arend van Spriel | 108a4be | 2012-09-19 22:21:07 +0200 | [diff] [blame] | 3021 | } |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 3022 | clear_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status); |
| 3023 | clear_bit(BRCMF_SCAN_STATUS_ABORT, &cfg->scan_status); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3024 | } |
| 3025 | |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 3026 | static void brcmf_cfg80211_escan_timeout_worker(struct work_struct *work) |
| 3027 | { |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 3028 | struct brcmf_cfg80211_info *cfg = |
| 3029 | container_of(work, struct brcmf_cfg80211_info, |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 3030 | escan_timeout_work); |
| 3031 | |
Hante Meuleman | ef8596e | 2014-09-30 10:23:13 +0200 | [diff] [blame] | 3032 | brcmf_inform_bss(cfg); |
Arend van Spriel | a0f472a | 2013-04-05 10:57:49 +0200 | [diff] [blame] | 3033 | brcmf_notify_escan_complete(cfg, cfg->escan_info.ifp, true, true); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 3034 | } |
| 3035 | |
| 3036 | static void brcmf_escan_timeout(unsigned long data) |
| 3037 | { |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 3038 | struct brcmf_cfg80211_info *cfg = |
| 3039 | (struct brcmf_cfg80211_info *)data; |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 3040 | |
Arend Van Spriel | fa85b30 | 2016-11-23 10:25:25 +0000 | [diff] [blame] | 3041 | if (cfg->internal_escan || cfg->scan_request) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 3042 | brcmf_err("timer expired\n"); |
Hante Meuleman | f0799895 | 2012-11-05 16:22:13 -0800 | [diff] [blame] | 3043 | schedule_work(&cfg->escan_timeout_work); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 3044 | } |
| 3045 | } |
| 3046 | |
| 3047 | static s32 |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 3048 | brcmf_compare_update_same_bss(struct brcmf_cfg80211_info *cfg, |
| 3049 | struct brcmf_bss_info_le *bss, |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 3050 | struct brcmf_bss_info_le *bss_info_le) |
| 3051 | { |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 3052 | struct brcmu_chan ch_bss, ch_bss_info_le; |
| 3053 | |
| 3054 | ch_bss.chspec = le16_to_cpu(bss->chanspec); |
| 3055 | cfg->d11inf.decchspec(&ch_bss); |
| 3056 | ch_bss_info_le.chspec = le16_to_cpu(bss_info_le->chanspec); |
| 3057 | cfg->d11inf.decchspec(&ch_bss_info_le); |
| 3058 | |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 3059 | if (!memcmp(&bss_info_le->BSSID, &bss->BSSID, ETH_ALEN) && |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 3060 | ch_bss.band == ch_bss_info_le.band && |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 3061 | bss_info_le->SSID_len == bss->SSID_len && |
| 3062 | !memcmp(bss_info_le->SSID, bss->SSID, bss_info_le->SSID_len)) { |
Arend van Spriel | 6f5838a | 2013-11-29 12:25:19 +0100 | [diff] [blame] | 3063 | if ((bss->flags & BRCMF_BSS_RSSI_ON_CHANNEL) == |
| 3064 | (bss_info_le->flags & BRCMF_BSS_RSSI_ON_CHANNEL)) { |
Arend van Spriel | 029591f | 2012-09-19 22:21:06 +0200 | [diff] [blame] | 3065 | s16 bss_rssi = le16_to_cpu(bss->RSSI); |
| 3066 | s16 bss_info_rssi = le16_to_cpu(bss_info_le->RSSI); |
| 3067 | |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 3068 | /* preserve max RSSI if the measurements are |
| 3069 | * both on-channel or both off-channel |
| 3070 | */ |
Arend van Spriel | 029591f | 2012-09-19 22:21:06 +0200 | [diff] [blame] | 3071 | if (bss_info_rssi > bss_rssi) |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 3072 | bss->RSSI = bss_info_le->RSSI; |
Arend van Spriel | 6f5838a | 2013-11-29 12:25:19 +0100 | [diff] [blame] | 3073 | } else if ((bss->flags & BRCMF_BSS_RSSI_ON_CHANNEL) && |
| 3074 | (bss_info_le->flags & BRCMF_BSS_RSSI_ON_CHANNEL) == 0) { |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 3075 | /* preserve the on-channel rssi measurement |
| 3076 | * if the new measurement is off channel |
| 3077 | */ |
| 3078 | bss->RSSI = bss_info_le->RSSI; |
Arend van Spriel | 6f5838a | 2013-11-29 12:25:19 +0100 | [diff] [blame] | 3079 | bss->flags |= BRCMF_BSS_RSSI_ON_CHANNEL; |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 3080 | } |
| 3081 | return 1; |
| 3082 | } |
| 3083 | return 0; |
| 3084 | } |
| 3085 | |
| 3086 | static s32 |
Arend van Spriel | 1993732 | 2012-11-05 16:22:32 -0800 | [diff] [blame] | 3087 | brcmf_cfg80211_escan_handler(struct brcmf_if *ifp, |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 3088 | const struct brcmf_event_msg *e, void *data) |
| 3089 | { |
Arend van Spriel | 1993732 | 2012-11-05 16:22:32 -0800 | [diff] [blame] | 3090 | struct brcmf_cfg80211_info *cfg = ifp->drvr->config; |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 3091 | s32 status; |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 3092 | struct brcmf_escan_result_le *escan_result_le; |
| 3093 | struct brcmf_bss_info_le *bss_info_le; |
| 3094 | struct brcmf_bss_info_le *bss = NULL; |
| 3095 | u32 bi_length; |
| 3096 | struct brcmf_scan_results *list; |
| 3097 | u32 i; |
Arend van Spriel | 97ed15c | 2012-09-13 21:12:06 +0200 | [diff] [blame] | 3098 | bool aborted; |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 3099 | |
Arend van Spriel | 5c36b99 | 2012-11-14 18:46:05 -0800 | [diff] [blame] | 3100 | status = e->status; |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 3101 | |
Arend van Spriel | a0f472a | 2013-04-05 10:57:49 +0200 | [diff] [blame] | 3102 | if (!test_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status)) { |
Hante Meuleman | 37a869e | 2015-10-29 20:33:17 +0100 | [diff] [blame] | 3103 | brcmf_err("scan not ready, bsscfgidx=%d\n", ifp->bsscfgidx); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 3104 | return -EPERM; |
| 3105 | } |
| 3106 | |
| 3107 | if (status == BRCMF_E_STATUS_PARTIAL) { |
Arend van Spriel | 4e8a008 | 2012-12-05 15:26:03 +0100 | [diff] [blame] | 3108 | brcmf_dbg(SCAN, "ESCAN Partial result\n"); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 3109 | escan_result_le = (struct brcmf_escan_result_le *) data; |
| 3110 | if (!escan_result_le) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 3111 | brcmf_err("Invalid escan result (NULL pointer)\n"); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 3112 | goto exit; |
| 3113 | } |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 3114 | if (le16_to_cpu(escan_result_le->bss_count) != 1) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 3115 | brcmf_err("Invalid bss_count %d: ignoring\n", |
| 3116 | escan_result_le->bss_count); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 3117 | goto exit; |
| 3118 | } |
| 3119 | bss_info_le = &escan_result_le->bss_info_le; |
| 3120 | |
Hante Meuleman | 6eda4e2 | 2013-02-08 15:54:02 +0100 | [diff] [blame] | 3121 | if (brcmf_p2p_scan_finding_common_channel(cfg, bss_info_le)) |
| 3122 | goto exit; |
| 3123 | |
Arend Van Spriel | fa85b30 | 2016-11-23 10:25:25 +0000 | [diff] [blame] | 3124 | if (!cfg->internal_escan && !cfg->scan_request) { |
Hante Meuleman | 6eda4e2 | 2013-02-08 15:54:02 +0100 | [diff] [blame] | 3125 | brcmf_dbg(SCAN, "result without cfg80211 request\n"); |
| 3126 | goto exit; |
| 3127 | } |
| 3128 | |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 3129 | bi_length = le32_to_cpu(bss_info_le->length); |
| 3130 | if (bi_length != (le32_to_cpu(escan_result_le->buflen) - |
| 3131 | WL_ESCAN_RESULTS_FIXED_SIZE)) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 3132 | brcmf_err("Invalid bss_info length %d: ignoring\n", |
| 3133 | bi_length); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 3134 | goto exit; |
| 3135 | } |
| 3136 | |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 3137 | if (!(cfg_to_wiphy(cfg)->interface_modes & |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 3138 | BIT(NL80211_IFTYPE_ADHOC))) { |
| 3139 | if (le16_to_cpu(bss_info_le->capability) & |
| 3140 | WLAN_CAPABILITY_IBSS) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 3141 | brcmf_err("Ignoring IBSS result\n"); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 3142 | goto exit; |
| 3143 | } |
| 3144 | } |
| 3145 | |
| 3146 | list = (struct brcmf_scan_results *) |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 3147 | cfg->escan_info.escan_buf; |
Hante Meuleman | d536733 | 2016-02-17 11:26:51 +0100 | [diff] [blame] | 3148 | if (bi_length > BRCMF_ESCAN_BUF_SIZE - list->buflen) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 3149 | brcmf_err("Buffer is too small: ignoring\n"); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 3150 | goto exit; |
| 3151 | } |
| 3152 | |
| 3153 | for (i = 0; i < list->count; i++) { |
| 3154 | bss = bss ? (struct brcmf_bss_info_le *) |
| 3155 | ((unsigned char *)bss + |
| 3156 | le32_to_cpu(bss->length)) : list->bss_info_le; |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 3157 | if (brcmf_compare_update_same_bss(cfg, bss, |
| 3158 | bss_info_le)) |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 3159 | goto exit; |
| 3160 | } |
Hante Meuleman | d536733 | 2016-02-17 11:26:51 +0100 | [diff] [blame] | 3161 | memcpy(&cfg->escan_info.escan_buf[list->buflen], bss_info_le, |
| 3162 | bi_length); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 3163 | list->version = le32_to_cpu(bss_info_le->version); |
| 3164 | list->buflen += bi_length; |
| 3165 | list->count++; |
| 3166 | } else { |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 3167 | cfg->escan_info.escan_state = WL_ESCAN_STATE_IDLE; |
Hante Meuleman | 6eda4e2 | 2013-02-08 15:54:02 +0100 | [diff] [blame] | 3168 | if (brcmf_p2p_scan_finding_common_channel(cfg, NULL)) |
| 3169 | goto exit; |
Arend Van Spriel | fa85b30 | 2016-11-23 10:25:25 +0000 | [diff] [blame] | 3170 | if (cfg->internal_escan || cfg->scan_request) { |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 3171 | brcmf_inform_bss(cfg); |
Arend van Spriel | 97ed15c | 2012-09-13 21:12:06 +0200 | [diff] [blame] | 3172 | aborted = status != BRCMF_E_STATUS_SUCCESS; |
Hante Meuleman | ef8596e | 2014-09-30 10:23:13 +0200 | [diff] [blame] | 3173 | brcmf_notify_escan_complete(cfg, ifp, aborted, false); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 3174 | } else |
Hante Meuleman | 6eda4e2 | 2013-02-08 15:54:02 +0100 | [diff] [blame] | 3175 | brcmf_dbg(SCAN, "Ignored scan complete result 0x%x\n", |
| 3176 | status); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 3177 | } |
| 3178 | exit: |
Peter Senna Tschudin | 12f3237 | 2014-05-31 10:14:06 -0300 | [diff] [blame] | 3179 | return 0; |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 3180 | } |
| 3181 | |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 3182 | static void brcmf_init_escan(struct brcmf_cfg80211_info *cfg) |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 3183 | { |
Arend van Spriel | 5c36b99 | 2012-11-14 18:46:05 -0800 | [diff] [blame] | 3184 | brcmf_fweh_register(cfg->pub, BRCMF_E_ESCAN_RESULT, |
| 3185 | brcmf_cfg80211_escan_handler); |
Hante Meuleman | f0799895 | 2012-11-05 16:22:13 -0800 | [diff] [blame] | 3186 | cfg->escan_info.escan_state = WL_ESCAN_STATE_IDLE; |
| 3187 | /* Init scan_timeout timer */ |
| 3188 | init_timer(&cfg->escan_timeout); |
| 3189 | cfg->escan_timeout.data = (unsigned long) cfg; |
| 3190 | cfg->escan_timeout.function = brcmf_escan_timeout; |
| 3191 | INIT_WORK(&cfg->escan_timeout_work, |
| 3192 | brcmf_cfg80211_escan_timeout_worker); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 3193 | } |
| 3194 | |
Arend Van Spriel | fa85b30 | 2016-11-23 10:25:25 +0000 | [diff] [blame] | 3195 | static struct cfg80211_scan_request * |
| 3196 | brcmf_alloc_internal_escan_request(struct wiphy *wiphy, u32 n_netinfo) { |
| 3197 | struct cfg80211_scan_request *req; |
| 3198 | size_t req_size; |
| 3199 | |
| 3200 | req_size = sizeof(*req) + |
| 3201 | n_netinfo * sizeof(req->channels[0]) + |
| 3202 | n_netinfo * sizeof(*req->ssids); |
| 3203 | |
| 3204 | req = kzalloc(req_size, GFP_KERNEL); |
| 3205 | if (req) { |
| 3206 | req->wiphy = wiphy; |
| 3207 | req->ssids = (void *)(&req->channels[0]) + |
| 3208 | n_netinfo * sizeof(req->channels[0]); |
| 3209 | } |
| 3210 | return req; |
| 3211 | } |
| 3212 | |
| 3213 | static int brcmf_internal_escan_add_info(struct cfg80211_scan_request *req, |
| 3214 | u8 *ssid, u8 ssid_len, u8 channel) |
| 3215 | { |
| 3216 | struct ieee80211_channel *chan; |
| 3217 | enum nl80211_band band; |
| 3218 | int freq; |
| 3219 | |
| 3220 | if (channel <= CH_MAX_2G_CHANNEL) |
| 3221 | band = NL80211_BAND_2GHZ; |
| 3222 | else |
| 3223 | band = NL80211_BAND_5GHZ; |
| 3224 | |
| 3225 | freq = ieee80211_channel_to_frequency(channel, band); |
| 3226 | if (!freq) |
| 3227 | return -EINVAL; |
| 3228 | |
| 3229 | chan = ieee80211_get_channel(req->wiphy, freq); |
| 3230 | if (!chan) |
| 3231 | return -EINVAL; |
| 3232 | |
| 3233 | req->channels[req->n_channels++] = chan; |
| 3234 | memcpy(req->ssids[req->n_ssids].ssid, ssid, ssid_len); |
| 3235 | req->ssids[req->n_ssids++].ssid_len = ssid_len; |
| 3236 | |
| 3237 | return 0; |
| 3238 | } |
| 3239 | |
| 3240 | static int brcmf_start_internal_escan(struct brcmf_if *ifp, |
| 3241 | struct cfg80211_scan_request *request) |
| 3242 | { |
| 3243 | struct brcmf_cfg80211_info *cfg = ifp->drvr->config; |
| 3244 | int err; |
| 3245 | |
| 3246 | if (test_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status)) { |
| 3247 | /* Abort any on-going scan */ |
| 3248 | brcmf_abort_scanning(cfg); |
| 3249 | } |
| 3250 | |
| 3251 | set_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status); |
| 3252 | cfg->escan_info.run = brcmf_run_escan; |
| 3253 | err = brcmf_do_escan(ifp, request); |
| 3254 | if (err) { |
| 3255 | clear_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status); |
| 3256 | return err; |
| 3257 | } |
| 3258 | cfg->internal_escan = true; |
| 3259 | return 0; |
| 3260 | } |
| 3261 | |
Arend Van Spriel | 53e3a80 | 2016-11-23 10:25:31 +0000 | [diff] [blame] | 3262 | static struct brcmf_pno_net_info_le * |
| 3263 | brcmf_get_netinfo_array(struct brcmf_pno_scanresults_le *pfn_v1) |
| 3264 | { |
| 3265 | struct brcmf_pno_scanresults_v2_le *pfn_v2; |
| 3266 | struct brcmf_pno_net_info_le *netinfo; |
| 3267 | |
| 3268 | switch (pfn_v1->version) { |
| 3269 | default: |
| 3270 | WARN_ON(1); |
| 3271 | /* fall-thru */ |
| 3272 | case cpu_to_le32(1): |
| 3273 | netinfo = (struct brcmf_pno_net_info_le *)(pfn_v1 + 1); |
| 3274 | break; |
| 3275 | case cpu_to_le32(2): |
| 3276 | pfn_v2 = (struct brcmf_pno_scanresults_v2_le *)pfn_v1; |
| 3277 | netinfo = (struct brcmf_pno_net_info_le *)(pfn_v2 + 1); |
| 3278 | break; |
| 3279 | } |
| 3280 | |
| 3281 | return netinfo; |
| 3282 | } |
| 3283 | |
Hante Meuleman | 5419f7f | 2016-01-05 11:05:46 +0100 | [diff] [blame] | 3284 | /* PFN result doesn't have all the info which are required by the supplicant |
| 3285 | * (For e.g IEs) Do a target Escan so that sched scan results are reported |
| 3286 | * via wl_inform_single_bss in the required format. Escan does require the |
| 3287 | * scan request in the form of cfg80211_scan_request. For timebeing, create |
| 3288 | * cfg80211_scan_request one out of the received PNO event. |
| 3289 | */ |
| 3290 | static s32 |
| 3291 | brcmf_notify_sched_scan_results(struct brcmf_if *ifp, |
| 3292 | const struct brcmf_event_msg *e, void *data) |
| 3293 | { |
| 3294 | struct brcmf_cfg80211_info *cfg = ifp->drvr->config; |
| 3295 | struct brcmf_pno_net_info_le *netinfo, *netinfo_start; |
| 3296 | struct cfg80211_scan_request *request = NULL; |
Hante Meuleman | 5419f7f | 2016-01-05 11:05:46 +0100 | [diff] [blame] | 3297 | struct wiphy *wiphy = cfg_to_wiphy(cfg); |
Arend Van Spriel | fa85b30 | 2016-11-23 10:25:25 +0000 | [diff] [blame] | 3298 | int i, err = 0; |
Hante Meuleman | 5419f7f | 2016-01-05 11:05:46 +0100 | [diff] [blame] | 3299 | struct brcmf_pno_scanresults_le *pfn_result; |
| 3300 | u32 result_count; |
| 3301 | u32 status; |
| 3302 | |
| 3303 | brcmf_dbg(SCAN, "Enter\n"); |
| 3304 | |
Hante Meuleman | 0aedbca | 2016-02-17 11:26:54 +0100 | [diff] [blame] | 3305 | if (e->datalen < (sizeof(*pfn_result) + sizeof(*netinfo))) { |
| 3306 | brcmf_dbg(SCAN, "Event data to small. Ignore\n"); |
| 3307 | return 0; |
| 3308 | } |
| 3309 | |
Hante Meuleman | 5419f7f | 2016-01-05 11:05:46 +0100 | [diff] [blame] | 3310 | if (e->event_code == BRCMF_E_PFN_NET_LOST) { |
| 3311 | brcmf_dbg(SCAN, "PFN NET LOST event. Do Nothing\n"); |
| 3312 | return 0; |
| 3313 | } |
| 3314 | |
| 3315 | pfn_result = (struct brcmf_pno_scanresults_le *)data; |
| 3316 | result_count = le32_to_cpu(pfn_result->count); |
| 3317 | status = le32_to_cpu(pfn_result->status); |
| 3318 | |
| 3319 | /* PFN event is limited to fit 512 bytes so we may get |
| 3320 | * multiple NET_FOUND events. For now place a warning here. |
| 3321 | */ |
| 3322 | WARN_ON(status != BRCMF_PNO_SCAN_COMPLETE); |
| 3323 | brcmf_dbg(SCAN, "PFN NET FOUND event. count: %d\n", result_count); |
Arend Van Spriel | fa85b30 | 2016-11-23 10:25:25 +0000 | [diff] [blame] | 3324 | if (!result_count) { |
Hante Meuleman | 5419f7f | 2016-01-05 11:05:46 +0100 | [diff] [blame] | 3325 | brcmf_err("FALSE PNO Event. (pfn_count == 0)\n"); |
| 3326 | goto out_err; |
| 3327 | } |
Arend Van Spriel | fa85b30 | 2016-11-23 10:25:25 +0000 | [diff] [blame] | 3328 | request = brcmf_alloc_internal_escan_request(wiphy, |
| 3329 | result_count); |
| 3330 | if (!request) { |
| 3331 | err = -ENOMEM; |
| 3332 | goto out_err; |
| 3333 | } |
Hante Meuleman | 5419f7f | 2016-01-05 11:05:46 +0100 | [diff] [blame] | 3334 | |
Arend Van Spriel | fa85b30 | 2016-11-23 10:25:25 +0000 | [diff] [blame] | 3335 | data += sizeof(struct brcmf_pno_scanresults_le); |
Arend Van Spriel | 53e3a80 | 2016-11-23 10:25:31 +0000 | [diff] [blame] | 3336 | netinfo_start = brcmf_get_netinfo_array(pfn_result); |
Arend Van Spriel | fa85b30 | 2016-11-23 10:25:25 +0000 | [diff] [blame] | 3337 | |
| 3338 | for (i = 0; i < result_count; i++) { |
| 3339 | netinfo = &netinfo_start[i]; |
| 3340 | if (!netinfo) { |
| 3341 | brcmf_err("Invalid netinfo ptr. index: %d\n", |
| 3342 | i); |
| 3343 | err = -EINVAL; |
| 3344 | goto out_err; |
| 3345 | } |
| 3346 | |
| 3347 | brcmf_dbg(SCAN, "SSID:%.32s Channel:%d\n", |
| 3348 | netinfo->SSID, netinfo->channel); |
| 3349 | err = brcmf_internal_escan_add_info(request, |
| 3350 | netinfo->SSID, |
| 3351 | netinfo->SSID_len, |
| 3352 | netinfo->channel); |
| 3353 | if (err) |
| 3354 | goto out_err; |
| 3355 | } |
| 3356 | |
| 3357 | err = brcmf_start_internal_escan(ifp, request); |
| 3358 | if (!err) |
| 3359 | goto free_req; |
Hante Meuleman | 5419f7f | 2016-01-05 11:05:46 +0100 | [diff] [blame] | 3360 | |
| 3361 | out_err: |
Hante Meuleman | 5419f7f | 2016-01-05 11:05:46 +0100 | [diff] [blame] | 3362 | cfg80211_sched_scan_stopped(wiphy); |
Arend Van Spriel | fa85b30 | 2016-11-23 10:25:25 +0000 | [diff] [blame] | 3363 | free_req: |
| 3364 | kfree(request); |
Hante Meuleman | 5419f7f | 2016-01-05 11:05:46 +0100 | [diff] [blame] | 3365 | return err; |
| 3366 | } |
| 3367 | |
| 3368 | static int |
| 3369 | brcmf_cfg80211_sched_scan_start(struct wiphy *wiphy, |
| 3370 | struct net_device *ndev, |
Arend Van Spriel | 3e2e86a | 2016-11-23 10:25:23 +0000 | [diff] [blame] | 3371 | struct cfg80211_sched_scan_request *req) |
Hante Meuleman | 5419f7f | 2016-01-05 11:05:46 +0100 | [diff] [blame] | 3372 | { |
| 3373 | struct brcmf_if *ifp = netdev_priv(ndev); |
| 3374 | struct brcmf_cfg80211_info *cfg = wiphy_priv(wiphy); |
Hante Meuleman | 5419f7f | 2016-01-05 11:05:46 +0100 | [diff] [blame] | 3375 | |
| 3376 | brcmf_dbg(SCAN, "Enter n_match_sets:%d n_ssids:%d\n", |
Arend Van Spriel | 3e2e86a | 2016-11-23 10:25:23 +0000 | [diff] [blame] | 3377 | req->n_match_sets, req->n_ssids); |
Arend Van Spriel | dfe5b0d | 2016-11-23 10:25:29 +0000 | [diff] [blame] | 3378 | |
Hante Meuleman | 5419f7f | 2016-01-05 11:05:46 +0100 | [diff] [blame] | 3379 | if (test_bit(BRCMF_SCAN_STATUS_SUPPRESS, &cfg->scan_status)) { |
| 3380 | brcmf_err("Scanning suppressed: status (%lu)\n", |
| 3381 | cfg->scan_status); |
| 3382 | return -EAGAIN; |
| 3383 | } |
| 3384 | |
Arend Van Spriel | 3e2e86a | 2016-11-23 10:25:23 +0000 | [diff] [blame] | 3385 | if (req->n_match_sets <= 0) { |
| 3386 | brcmf_dbg(SCAN, "invalid number of matchsets specified: %d\n", |
| 3387 | req->n_match_sets); |
Hante Meuleman | 5419f7f | 2016-01-05 11:05:46 +0100 | [diff] [blame] | 3388 | return -EINVAL; |
| 3389 | } |
| 3390 | |
Arend Van Spriel | 3e48611 | 2016-11-23 10:25:27 +0000 | [diff] [blame] | 3391 | return brcmf_pno_start_sched_scan(ifp, req); |
Hante Meuleman | 5419f7f | 2016-01-05 11:05:46 +0100 | [diff] [blame] | 3392 | } |
| 3393 | |
| 3394 | static int brcmf_cfg80211_sched_scan_stop(struct wiphy *wiphy, |
| 3395 | struct net_device *ndev) |
| 3396 | { |
| 3397 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); |
Arend Van Spriel | ac55136 | 2016-11-23 10:25:22 +0000 | [diff] [blame] | 3398 | struct brcmf_if *ifp = netdev_priv(ndev); |
Hante Meuleman | 5419f7f | 2016-01-05 11:05:46 +0100 | [diff] [blame] | 3399 | |
| 3400 | brcmf_dbg(SCAN, "enter\n"); |
Arend Van Spriel | ac55136 | 2016-11-23 10:25:22 +0000 | [diff] [blame] | 3401 | brcmf_pno_clean(ifp); |
Arend Van Spriel | fa85b30 | 2016-11-23 10:25:25 +0000 | [diff] [blame] | 3402 | if (cfg->internal_escan) |
Arend Van Spriel | ac55136 | 2016-11-23 10:25:22 +0000 | [diff] [blame] | 3403 | brcmf_notify_escan_complete(cfg, ifp, true, true); |
Hante Meuleman | 5419f7f | 2016-01-05 11:05:46 +0100 | [diff] [blame] | 3404 | return 0; |
| 3405 | } |
| 3406 | |
Alexandre Oliva | 5addc0d | 2012-01-16 14:00:12 -0500 | [diff] [blame] | 3407 | static __always_inline void brcmf_delay(u32 ms) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3408 | { |
| 3409 | if (ms < 1000 / HZ) { |
| 3410 | cond_resched(); |
| 3411 | mdelay(ms); |
| 3412 | } else { |
| 3413 | msleep(ms); |
| 3414 | } |
| 3415 | } |
| 3416 | |
Hante Meuleman | b9a82f8 | 2014-10-28 14:56:06 +0100 | [diff] [blame] | 3417 | static s32 brcmf_config_wowl_pattern(struct brcmf_if *ifp, u8 cmd[4], |
| 3418 | u8 *pattern, u32 patternsize, u8 *mask, |
| 3419 | u32 packet_offset) |
| 3420 | { |
| 3421 | struct brcmf_fil_wowl_pattern_le *filter; |
| 3422 | u32 masksize; |
| 3423 | u32 patternoffset; |
| 3424 | u8 *buf; |
| 3425 | u32 bufsize; |
| 3426 | s32 ret; |
| 3427 | |
| 3428 | masksize = (patternsize + 7) / 8; |
| 3429 | patternoffset = sizeof(*filter) - sizeof(filter->cmd) + masksize; |
| 3430 | |
| 3431 | bufsize = sizeof(*filter) + patternsize + masksize; |
| 3432 | buf = kzalloc(bufsize, GFP_KERNEL); |
| 3433 | if (!buf) |
| 3434 | return -ENOMEM; |
| 3435 | filter = (struct brcmf_fil_wowl_pattern_le *)buf; |
| 3436 | |
| 3437 | memcpy(filter->cmd, cmd, 4); |
| 3438 | filter->masksize = cpu_to_le32(masksize); |
| 3439 | filter->offset = cpu_to_le32(packet_offset); |
| 3440 | filter->patternoffset = cpu_to_le32(patternoffset); |
| 3441 | filter->patternsize = cpu_to_le32(patternsize); |
| 3442 | filter->type = cpu_to_le32(BRCMF_WOWL_PATTERN_TYPE_BITMAP); |
| 3443 | |
| 3444 | if ((mask) && (masksize)) |
| 3445 | memcpy(buf + sizeof(*filter), mask, masksize); |
| 3446 | if ((pattern) && (patternsize)) |
| 3447 | memcpy(buf + sizeof(*filter) + masksize, pattern, patternsize); |
| 3448 | |
| 3449 | ret = brcmf_fil_iovar_data_set(ifp, "wowl_pattern", buf, bufsize); |
| 3450 | |
| 3451 | kfree(buf); |
| 3452 | return ret; |
| 3453 | } |
| 3454 | |
Hante Meuleman | 3021ad9 | 2016-01-05 11:05:45 +0100 | [diff] [blame] | 3455 | static s32 |
| 3456 | brcmf_wowl_nd_results(struct brcmf_if *ifp, const struct brcmf_event_msg *e, |
| 3457 | void *data) |
| 3458 | { |
| 3459 | struct brcmf_cfg80211_info *cfg = ifp->drvr->config; |
| 3460 | struct brcmf_pno_scanresults_le *pfn_result; |
| 3461 | struct brcmf_pno_net_info_le *netinfo; |
| 3462 | |
| 3463 | brcmf_dbg(SCAN, "Enter\n"); |
| 3464 | |
Hante Meuleman | 0aedbca | 2016-02-17 11:26:54 +0100 | [diff] [blame] | 3465 | if (e->datalen < (sizeof(*pfn_result) + sizeof(*netinfo))) { |
| 3466 | brcmf_dbg(SCAN, "Event data to small. Ignore\n"); |
| 3467 | return 0; |
| 3468 | } |
| 3469 | |
Hante Meuleman | 3021ad9 | 2016-01-05 11:05:45 +0100 | [diff] [blame] | 3470 | pfn_result = (struct brcmf_pno_scanresults_le *)data; |
| 3471 | |
| 3472 | if (e->event_code == BRCMF_E_PFN_NET_LOST) { |
| 3473 | brcmf_dbg(SCAN, "PFN NET LOST event. Ignore\n"); |
| 3474 | return 0; |
| 3475 | } |
| 3476 | |
| 3477 | if (le32_to_cpu(pfn_result->count) < 1) { |
| 3478 | brcmf_err("Invalid result count, expected 1 (%d)\n", |
| 3479 | le32_to_cpu(pfn_result->count)); |
| 3480 | return -EINVAL; |
| 3481 | } |
| 3482 | |
| 3483 | data += sizeof(struct brcmf_pno_scanresults_le); |
| 3484 | netinfo = (struct brcmf_pno_net_info_le *)data; |
| 3485 | memcpy(cfg->wowl.nd->ssid.ssid, netinfo->SSID, netinfo->SSID_len); |
| 3486 | cfg->wowl.nd->ssid.ssid_len = netinfo->SSID_len; |
| 3487 | cfg->wowl.nd->n_channels = 1; |
| 3488 | cfg->wowl.nd->channels[0] = |
| 3489 | ieee80211_channel_to_frequency(netinfo->channel, |
| 3490 | netinfo->channel <= CH_MAX_2G_CHANNEL ? |
| 3491 | NL80211_BAND_2GHZ : NL80211_BAND_5GHZ); |
| 3492 | cfg->wowl.nd_info->n_matches = 1; |
| 3493 | cfg->wowl.nd_info->matches[0] = cfg->wowl.nd; |
| 3494 | |
| 3495 | /* Inform (the resume task) that the net detect information was recvd */ |
| 3496 | cfg->wowl.nd_data_completed = true; |
| 3497 | wake_up(&cfg->wowl.nd_data_wait); |
| 3498 | |
| 3499 | return 0; |
| 3500 | } |
| 3501 | |
Hante Meuleman | aeb6422 | 2015-10-29 20:33:19 +0100 | [diff] [blame] | 3502 | #ifdef CONFIG_PM |
| 3503 | |
| 3504 | static void brcmf_report_wowl_wakeind(struct wiphy *wiphy, struct brcmf_if *ifp) |
| 3505 | { |
Hante Meuleman | 3021ad9 | 2016-01-05 11:05:45 +0100 | [diff] [blame] | 3506 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); |
Hante Meuleman | aeb6422 | 2015-10-29 20:33:19 +0100 | [diff] [blame] | 3507 | struct brcmf_wowl_wakeind_le wake_ind_le; |
| 3508 | struct cfg80211_wowlan_wakeup wakeup_data; |
| 3509 | struct cfg80211_wowlan_wakeup *wakeup; |
| 3510 | u32 wakeind; |
| 3511 | s32 err; |
Hante Meuleman | 3021ad9 | 2016-01-05 11:05:45 +0100 | [diff] [blame] | 3512 | int timeout; |
Hante Meuleman | aeb6422 | 2015-10-29 20:33:19 +0100 | [diff] [blame] | 3513 | |
| 3514 | err = brcmf_fil_iovar_data_get(ifp, "wowl_wakeind", &wake_ind_le, |
| 3515 | sizeof(wake_ind_le)); |
Hante Meuleman | 3021ad9 | 2016-01-05 11:05:45 +0100 | [diff] [blame] | 3516 | if (err) { |
Hante Meuleman | aeb6422 | 2015-10-29 20:33:19 +0100 | [diff] [blame] | 3517 | brcmf_err("Get wowl_wakeind failed, err = %d\n", err); |
| 3518 | return; |
| 3519 | } |
| 3520 | |
| 3521 | wakeind = le32_to_cpu(wake_ind_le.ucode_wakeind); |
| 3522 | if (wakeind & (BRCMF_WOWL_MAGIC | BRCMF_WOWL_DIS | BRCMF_WOWL_BCN | |
Hante Meuleman | 3021ad9 | 2016-01-05 11:05:45 +0100 | [diff] [blame] | 3523 | BRCMF_WOWL_RETR | BRCMF_WOWL_NET | |
| 3524 | BRCMF_WOWL_PFN_FOUND)) { |
Hante Meuleman | aeb6422 | 2015-10-29 20:33:19 +0100 | [diff] [blame] | 3525 | wakeup = &wakeup_data; |
| 3526 | memset(&wakeup_data, 0, sizeof(wakeup_data)); |
| 3527 | wakeup_data.pattern_idx = -1; |
| 3528 | |
| 3529 | if (wakeind & BRCMF_WOWL_MAGIC) { |
| 3530 | brcmf_dbg(INFO, "WOWL Wake indicator: BRCMF_WOWL_MAGIC\n"); |
| 3531 | wakeup_data.magic_pkt = true; |
| 3532 | } |
| 3533 | if (wakeind & BRCMF_WOWL_DIS) { |
| 3534 | brcmf_dbg(INFO, "WOWL Wake indicator: BRCMF_WOWL_DIS\n"); |
| 3535 | wakeup_data.disconnect = true; |
| 3536 | } |
| 3537 | if (wakeind & BRCMF_WOWL_BCN) { |
| 3538 | brcmf_dbg(INFO, "WOWL Wake indicator: BRCMF_WOWL_BCN\n"); |
| 3539 | wakeup_data.disconnect = true; |
| 3540 | } |
| 3541 | if (wakeind & BRCMF_WOWL_RETR) { |
| 3542 | brcmf_dbg(INFO, "WOWL Wake indicator: BRCMF_WOWL_RETR\n"); |
| 3543 | wakeup_data.disconnect = true; |
| 3544 | } |
| 3545 | if (wakeind & BRCMF_WOWL_NET) { |
| 3546 | brcmf_dbg(INFO, "WOWL Wake indicator: BRCMF_WOWL_NET\n"); |
| 3547 | /* For now always map to pattern 0, no API to get |
| 3548 | * correct information available at the moment. |
| 3549 | */ |
| 3550 | wakeup_data.pattern_idx = 0; |
| 3551 | } |
Hante Meuleman | 3021ad9 | 2016-01-05 11:05:45 +0100 | [diff] [blame] | 3552 | if (wakeind & BRCMF_WOWL_PFN_FOUND) { |
| 3553 | brcmf_dbg(INFO, "WOWL Wake indicator: BRCMF_WOWL_PFN_FOUND\n"); |
| 3554 | timeout = wait_event_timeout(cfg->wowl.nd_data_wait, |
| 3555 | cfg->wowl.nd_data_completed, |
| 3556 | BRCMF_ND_INFO_TIMEOUT); |
| 3557 | if (!timeout) |
| 3558 | brcmf_err("No result for wowl net detect\n"); |
| 3559 | else |
| 3560 | wakeup_data.net_detect = cfg->wowl.nd_info; |
| 3561 | } |
Hante Meuleman | 5c22fb8 | 2016-02-17 11:27:03 +0100 | [diff] [blame] | 3562 | if (wakeind & BRCMF_WOWL_GTK_FAILURE) { |
| 3563 | brcmf_dbg(INFO, "WOWL Wake indicator: BRCMF_WOWL_GTK_FAILURE\n"); |
| 3564 | wakeup_data.gtk_rekey_failure = true; |
| 3565 | } |
Hante Meuleman | aeb6422 | 2015-10-29 20:33:19 +0100 | [diff] [blame] | 3566 | } else { |
| 3567 | wakeup = NULL; |
| 3568 | } |
| 3569 | cfg80211_report_wowlan_wakeup(&ifp->vif->wdev, wakeup, GFP_KERNEL); |
| 3570 | } |
| 3571 | |
| 3572 | #else |
| 3573 | |
| 3574 | static void brcmf_report_wowl_wakeind(struct wiphy *wiphy, struct brcmf_if *ifp) |
| 3575 | { |
| 3576 | } |
| 3577 | |
| 3578 | #endif /* CONFIG_PM */ |
| 3579 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3580 | static s32 brcmf_cfg80211_resume(struct wiphy *wiphy) |
| 3581 | { |
Hante Meuleman | 4eb3af7 | 2014-09-30 10:23:18 +0200 | [diff] [blame] | 3582 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); |
| 3583 | struct net_device *ndev = cfg_to_ndev(cfg); |
| 3584 | struct brcmf_if *ifp = netdev_priv(ndev); |
| 3585 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 3586 | brcmf_dbg(TRACE, "Enter\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3587 | |
Hante Meuleman | 3021ad9 | 2016-01-05 11:05:45 +0100 | [diff] [blame] | 3588 | if (cfg->wowl.active) { |
Hante Meuleman | aeb6422 | 2015-10-29 20:33:19 +0100 | [diff] [blame] | 3589 | brcmf_report_wowl_wakeind(wiphy, ifp); |
| 3590 | brcmf_fil_iovar_int_set(ifp, "wowl_clear", 0); |
| 3591 | brcmf_config_wowl_pattern(ifp, "clr", NULL, 0, NULL, 0); |
Hante Meuleman | 73ef9e6 | 2016-02-17 11:27:05 +0100 | [diff] [blame] | 3592 | if (!brcmf_feat_is_enabled(ifp, BRCMF_FEAT_WOWL_ARP_ND)) |
| 3593 | brcmf_configure_arp_nd_offload(ifp, true); |
Hante Meuleman | 4eb3af7 | 2014-09-30 10:23:18 +0200 | [diff] [blame] | 3594 | brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_PM, |
Hante Meuleman | 3021ad9 | 2016-01-05 11:05:45 +0100 | [diff] [blame] | 3595 | cfg->wowl.pre_pmmode); |
| 3596 | cfg->wowl.active = false; |
| 3597 | if (cfg->wowl.nd_enabled) { |
| 3598 | brcmf_cfg80211_sched_scan_stop(cfg->wiphy, ifp->ndev); |
| 3599 | brcmf_fweh_unregister(cfg->pub, BRCMF_E_PFN_NET_FOUND); |
| 3600 | brcmf_fweh_register(cfg->pub, BRCMF_E_PFN_NET_FOUND, |
| 3601 | brcmf_notify_sched_scan_results); |
| 3602 | cfg->wowl.nd_enabled = false; |
| 3603 | } |
Hante Meuleman | 4eb3af7 | 2014-09-30 10:23:18 +0200 | [diff] [blame] | 3604 | } |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3605 | return 0; |
| 3606 | } |
| 3607 | |
Hante Meuleman | 4eb3af7 | 2014-09-30 10:23:18 +0200 | [diff] [blame] | 3608 | static void brcmf_configure_wowl(struct brcmf_cfg80211_info *cfg, |
| 3609 | struct brcmf_if *ifp, |
| 3610 | struct cfg80211_wowlan *wowl) |
| 3611 | { |
| 3612 | u32 wowl_config; |
Hante Meuleman | a7ed782 | 2016-09-19 12:09:58 +0100 | [diff] [blame] | 3613 | struct brcmf_wowl_wakeind_le wowl_wakeind; |
Hante Meuleman | b9a82f8 | 2014-10-28 14:56:06 +0100 | [diff] [blame] | 3614 | u32 i; |
Hante Meuleman | 4eb3af7 | 2014-09-30 10:23:18 +0200 | [diff] [blame] | 3615 | |
| 3616 | brcmf_dbg(TRACE, "Suspend, wowl config.\n"); |
| 3617 | |
Hante Meuleman | 73ef9e6 | 2016-02-17 11:27:05 +0100 | [diff] [blame] | 3618 | if (!brcmf_feat_is_enabled(ifp, BRCMF_FEAT_WOWL_ARP_ND)) |
| 3619 | brcmf_configure_arp_nd_offload(ifp, false); |
Hante Meuleman | 3021ad9 | 2016-01-05 11:05:45 +0100 | [diff] [blame] | 3620 | brcmf_fil_cmd_int_get(ifp, BRCMF_C_GET_PM, &cfg->wowl.pre_pmmode); |
Hante Meuleman | 4eb3af7 | 2014-09-30 10:23:18 +0200 | [diff] [blame] | 3621 | brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_PM, PM_MAX); |
| 3622 | |
| 3623 | wowl_config = 0; |
| 3624 | if (wowl->disconnect) |
Hante Meuleman | b9a82f8 | 2014-10-28 14:56:06 +0100 | [diff] [blame] | 3625 | wowl_config = BRCMF_WOWL_DIS | BRCMF_WOWL_BCN | BRCMF_WOWL_RETR; |
Hante Meuleman | 4eb3af7 | 2014-09-30 10:23:18 +0200 | [diff] [blame] | 3626 | if (wowl->magic_pkt) |
Hante Meuleman | b9a82f8 | 2014-10-28 14:56:06 +0100 | [diff] [blame] | 3627 | wowl_config |= BRCMF_WOWL_MAGIC; |
| 3628 | if ((wowl->patterns) && (wowl->n_patterns)) { |
| 3629 | wowl_config |= BRCMF_WOWL_NET; |
| 3630 | for (i = 0; i < wowl->n_patterns; i++) { |
| 3631 | brcmf_config_wowl_pattern(ifp, "add", |
| 3632 | (u8 *)wowl->patterns[i].pattern, |
| 3633 | wowl->patterns[i].pattern_len, |
| 3634 | (u8 *)wowl->patterns[i].mask, |
| 3635 | wowl->patterns[i].pkt_offset); |
| 3636 | } |
| 3637 | } |
Hante Meuleman | 3021ad9 | 2016-01-05 11:05:45 +0100 | [diff] [blame] | 3638 | if (wowl->nd_config) { |
| 3639 | brcmf_cfg80211_sched_scan_start(cfg->wiphy, ifp->ndev, |
| 3640 | wowl->nd_config); |
| 3641 | wowl_config |= BRCMF_WOWL_PFN_FOUND; |
| 3642 | |
| 3643 | cfg->wowl.nd_data_completed = false; |
| 3644 | cfg->wowl.nd_enabled = true; |
| 3645 | /* Now reroute the event for PFN to the wowl function. */ |
| 3646 | brcmf_fweh_unregister(cfg->pub, BRCMF_E_PFN_NET_FOUND); |
| 3647 | brcmf_fweh_register(cfg->pub, BRCMF_E_PFN_NET_FOUND, |
| 3648 | brcmf_wowl_nd_results); |
| 3649 | } |
Hante Meuleman | 5c22fb8 | 2016-02-17 11:27:03 +0100 | [diff] [blame] | 3650 | if (wowl->gtk_rekey_failure) |
| 3651 | wowl_config |= BRCMF_WOWL_GTK_FAILURE; |
Hante Meuleman | 3021ad9 | 2016-01-05 11:05:45 +0100 | [diff] [blame] | 3652 | if (!test_bit(BRCMF_VIF_STATUS_CONNECTED, &ifp->vif->sme_state)) |
| 3653 | wowl_config |= BRCMF_WOWL_UNASSOC; |
| 3654 | |
Hante Meuleman | a7ed782 | 2016-09-19 12:09:58 +0100 | [diff] [blame] | 3655 | memcpy(&wowl_wakeind, "clear", 6); |
| 3656 | brcmf_fil_iovar_data_set(ifp, "wowl_wakeind", &wowl_wakeind, |
| 3657 | sizeof(wowl_wakeind)); |
Hante Meuleman | 4eb3af7 | 2014-09-30 10:23:18 +0200 | [diff] [blame] | 3658 | brcmf_fil_iovar_int_set(ifp, "wowl", wowl_config); |
| 3659 | brcmf_fil_iovar_int_set(ifp, "wowl_activate", 1); |
| 3660 | brcmf_bus_wowl_config(cfg->pub->bus_if, true); |
Hante Meuleman | 3021ad9 | 2016-01-05 11:05:45 +0100 | [diff] [blame] | 3661 | cfg->wowl.active = true; |
Hante Meuleman | 4eb3af7 | 2014-09-30 10:23:18 +0200 | [diff] [blame] | 3662 | } |
| 3663 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3664 | static s32 brcmf_cfg80211_suspend(struct wiphy *wiphy, |
Hante Meuleman | 4eb3af7 | 2014-09-30 10:23:18 +0200 | [diff] [blame] | 3665 | struct cfg80211_wowlan *wowl) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3666 | { |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 3667 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); |
| 3668 | struct net_device *ndev = cfg_to_ndev(cfg); |
Hante Meuleman | 4eb3af7 | 2014-09-30 10:23:18 +0200 | [diff] [blame] | 3669 | struct brcmf_if *ifp = netdev_priv(ndev); |
Arend van Spriel | 7d64107 | 2012-10-22 13:55:39 -0700 | [diff] [blame] | 3670 | struct brcmf_cfg80211_vif *vif; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3671 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 3672 | brcmf_dbg(TRACE, "Enter\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3673 | |
Hante Meuleman | 4eb3af7 | 2014-09-30 10:23:18 +0200 | [diff] [blame] | 3674 | /* if the primary net_device is not READY there is nothing |
Arend van Spriel | 7d64107 | 2012-10-22 13:55:39 -0700 | [diff] [blame] | 3675 | * we can do but pray resume goes smoothly. |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3676 | */ |
Hante Meuleman | 4eb3af7 | 2014-09-30 10:23:18 +0200 | [diff] [blame] | 3677 | if (!check_vif_up(ifp->vif)) |
Arend van Spriel | 7d64107 | 2012-10-22 13:55:39 -0700 | [diff] [blame] | 3678 | goto exit; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3679 | |
Hante Meuleman | 3021ad9 | 2016-01-05 11:05:45 +0100 | [diff] [blame] | 3680 | /* Stop scheduled scan */ |
| 3681 | if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_PNO)) |
| 3682 | brcmf_cfg80211_sched_scan_stop(wiphy, ndev); |
| 3683 | |
Arend van Spriel | 7d64107 | 2012-10-22 13:55:39 -0700 | [diff] [blame] | 3684 | /* end any scanning */ |
| 3685 | if (test_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status)) |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 3686 | brcmf_abort_scanning(cfg); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3687 | |
Hante Meuleman | 4eb3af7 | 2014-09-30 10:23:18 +0200 | [diff] [blame] | 3688 | if (wowl == NULL) { |
| 3689 | brcmf_bus_wowl_config(cfg->pub->bus_if, false); |
| 3690 | list_for_each_entry(vif, &cfg->vif_list, list) { |
| 3691 | if (!test_bit(BRCMF_VIF_STATUS_READY, &vif->sme_state)) |
| 3692 | continue; |
| 3693 | /* While going to suspend if associated with AP |
| 3694 | * disassociate from AP to save power while system is |
| 3695 | * in suspended state |
| 3696 | */ |
Arend van Spriel | 9b7a0dd | 2015-01-25 20:31:33 +0100 | [diff] [blame] | 3697 | brcmf_link_down(vif, WLAN_REASON_UNSPECIFIED); |
Hante Meuleman | 4eb3af7 | 2014-09-30 10:23:18 +0200 | [diff] [blame] | 3698 | /* Make sure WPA_Supplicant receives all the event |
| 3699 | * generated due to DISASSOC call to the fw to keep |
| 3700 | * the state fw and WPA_Supplicant state consistent |
| 3701 | */ |
| 3702 | brcmf_delay(500); |
| 3703 | } |
| 3704 | /* Configure MPC */ |
| 3705 | brcmf_set_mpc(ifp, 1); |
| 3706 | |
| 3707 | } else { |
| 3708 | /* Configure WOWL paramaters */ |
| 3709 | brcmf_configure_wowl(cfg, ifp, wowl); |
| 3710 | } |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3711 | |
Arend van Spriel | 7d64107 | 2012-10-22 13:55:39 -0700 | [diff] [blame] | 3712 | exit: |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 3713 | brcmf_dbg(TRACE, "Exit\n"); |
Arend van Spriel | 7d64107 | 2012-10-22 13:55:39 -0700 | [diff] [blame] | 3714 | /* clear any scanning activity */ |
| 3715 | cfg->scan_status = 0; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3716 | return 0; |
| 3717 | } |
| 3718 | |
| 3719 | static __used s32 |
Hante Meuleman | 6c404f3 | 2015-12-10 13:43:03 +0100 | [diff] [blame] | 3720 | brcmf_update_pmklist(struct brcmf_cfg80211_info *cfg, struct brcmf_if *ifp) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3721 | { |
Hante Meuleman | 6c404f3 | 2015-12-10 13:43:03 +0100 | [diff] [blame] | 3722 | struct brcmf_pmk_list_le *pmk_list; |
| 3723 | int i; |
| 3724 | u32 npmk; |
| 3725 | s32 err; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3726 | |
Hante Meuleman | 6c404f3 | 2015-12-10 13:43:03 +0100 | [diff] [blame] | 3727 | pmk_list = &cfg->pmk_list; |
| 3728 | npmk = le32_to_cpu(pmk_list->npmk); |
Arend van Spriel | 40c8e95 | 2011-10-12 20:51:20 +0200 | [diff] [blame] | 3729 | |
Hante Meuleman | 6c404f3 | 2015-12-10 13:43:03 +0100 | [diff] [blame] | 3730 | brcmf_dbg(CONN, "No of elements %d\n", npmk); |
| 3731 | for (i = 0; i < npmk; i++) |
| 3732 | brcmf_dbg(CONN, "PMK[%d]: %pM\n", i, &pmk_list->pmk[i].bssid); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3733 | |
Hante Meuleman | 6c404f3 | 2015-12-10 13:43:03 +0100 | [diff] [blame] | 3734 | err = brcmf_fil_iovar_data_set(ifp, "pmkid_info", pmk_list, |
| 3735 | sizeof(*pmk_list)); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3736 | |
| 3737 | return err; |
| 3738 | } |
| 3739 | |
| 3740 | static s32 |
| 3741 | brcmf_cfg80211_set_pmksa(struct wiphy *wiphy, struct net_device *ndev, |
| 3742 | struct cfg80211_pmksa *pmksa) |
| 3743 | { |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 3744 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); |
Arend van Spriel | 0abb5f21 | 2012-10-22 13:55:32 -0700 | [diff] [blame] | 3745 | struct brcmf_if *ifp = netdev_priv(ndev); |
Hante Meuleman | 6c404f3 | 2015-12-10 13:43:03 +0100 | [diff] [blame] | 3746 | struct brcmf_pmksa *pmk = &cfg->pmk_list.pmk[0]; |
| 3747 | s32 err; |
| 3748 | u32 npmk, i; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3749 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 3750 | brcmf_dbg(TRACE, "Enter\n"); |
Arend van Spriel | ce81e31 | 2012-10-22 13:55:37 -0700 | [diff] [blame] | 3751 | if (!check_vif_up(ifp->vif)) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3752 | return -EIO; |
| 3753 | |
Hante Meuleman | 6c404f3 | 2015-12-10 13:43:03 +0100 | [diff] [blame] | 3754 | npmk = le32_to_cpu(cfg->pmk_list.npmk); |
| 3755 | for (i = 0; i < npmk; i++) |
| 3756 | if (!memcmp(pmksa->bssid, pmk[i].bssid, ETH_ALEN)) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3757 | break; |
Hante Meuleman | 6c404f3 | 2015-12-10 13:43:03 +0100 | [diff] [blame] | 3758 | if (i < BRCMF_MAXPMKID) { |
| 3759 | memcpy(pmk[i].bssid, pmksa->bssid, ETH_ALEN); |
| 3760 | memcpy(pmk[i].pmkid, pmksa->pmkid, WLAN_PMKID_LEN); |
| 3761 | if (i == npmk) { |
| 3762 | npmk++; |
| 3763 | cfg->pmk_list.npmk = cpu_to_le32(npmk); |
Arend van Spriel | 40c8e95 | 2011-10-12 20:51:20 +0200 | [diff] [blame] | 3764 | } |
Hante Meuleman | 6c404f3 | 2015-12-10 13:43:03 +0100 | [diff] [blame] | 3765 | } else { |
| 3766 | brcmf_err("Too many PMKSA entries cached %d\n", npmk); |
| 3767 | return -EINVAL; |
| 3768 | } |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3769 | |
Hante Meuleman | 6c404f3 | 2015-12-10 13:43:03 +0100 | [diff] [blame] | 3770 | brcmf_dbg(CONN, "set_pmksa - PMK bssid: %pM =\n", pmk[npmk].bssid); |
| 3771 | for (i = 0; i < WLAN_PMKID_LEN; i += 4) |
| 3772 | brcmf_dbg(CONN, "%02x %02x %02x %02x\n", pmk[npmk].pmkid[i], |
| 3773 | pmk[npmk].pmkid[i + 1], pmk[npmk].pmkid[i + 2], |
| 3774 | pmk[npmk].pmkid[i + 3]); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3775 | |
Hante Meuleman | 6c404f3 | 2015-12-10 13:43:03 +0100 | [diff] [blame] | 3776 | err = brcmf_update_pmklist(cfg, ifp); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3777 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 3778 | brcmf_dbg(TRACE, "Exit\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3779 | return err; |
| 3780 | } |
| 3781 | |
| 3782 | static s32 |
| 3783 | brcmf_cfg80211_del_pmksa(struct wiphy *wiphy, struct net_device *ndev, |
Hante Meuleman | 6c404f3 | 2015-12-10 13:43:03 +0100 | [diff] [blame] | 3784 | struct cfg80211_pmksa *pmksa) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3785 | { |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 3786 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); |
Arend van Spriel | 0abb5f21 | 2012-10-22 13:55:32 -0700 | [diff] [blame] | 3787 | struct brcmf_if *ifp = netdev_priv(ndev); |
Hante Meuleman | 6c404f3 | 2015-12-10 13:43:03 +0100 | [diff] [blame] | 3788 | struct brcmf_pmksa *pmk = &cfg->pmk_list.pmk[0]; |
| 3789 | s32 err; |
| 3790 | u32 npmk, i; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3791 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 3792 | brcmf_dbg(TRACE, "Enter\n"); |
Arend van Spriel | ce81e31 | 2012-10-22 13:55:37 -0700 | [diff] [blame] | 3793 | if (!check_vif_up(ifp->vif)) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3794 | return -EIO; |
| 3795 | |
Nicolas Iooss | 7703773ef | 2016-08-23 11:37:17 +0200 | [diff] [blame] | 3796 | brcmf_dbg(CONN, "del_pmksa - PMK bssid = %pM\n", pmksa->bssid); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3797 | |
Hante Meuleman | 6c404f3 | 2015-12-10 13:43:03 +0100 | [diff] [blame] | 3798 | npmk = le32_to_cpu(cfg->pmk_list.npmk); |
| 3799 | for (i = 0; i < npmk; i++) |
Nicolas Iooss | 7703773ef | 2016-08-23 11:37:17 +0200 | [diff] [blame] | 3800 | if (!memcmp(pmksa->bssid, pmk[i].bssid, ETH_ALEN)) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3801 | break; |
| 3802 | |
Hante Meuleman | 6c404f3 | 2015-12-10 13:43:03 +0100 | [diff] [blame] | 3803 | if ((npmk > 0) && (i < npmk)) { |
| 3804 | for (; i < (npmk - 1); i++) { |
| 3805 | memcpy(&pmk[i].bssid, &pmk[i + 1].bssid, ETH_ALEN); |
| 3806 | memcpy(&pmk[i].pmkid, &pmk[i + 1].pmkid, |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3807 | WLAN_PMKID_LEN); |
| 3808 | } |
Hante Meuleman | 6c404f3 | 2015-12-10 13:43:03 +0100 | [diff] [blame] | 3809 | memset(&pmk[i], 0, sizeof(*pmk)); |
| 3810 | cfg->pmk_list.npmk = cpu_to_le32(npmk - 1); |
| 3811 | } else { |
| 3812 | brcmf_err("Cache entry not found\n"); |
| 3813 | return -EINVAL; |
| 3814 | } |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3815 | |
Hante Meuleman | 6c404f3 | 2015-12-10 13:43:03 +0100 | [diff] [blame] | 3816 | err = brcmf_update_pmklist(cfg, ifp); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3817 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 3818 | brcmf_dbg(TRACE, "Exit\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3819 | return err; |
| 3820 | |
| 3821 | } |
| 3822 | |
| 3823 | static s32 |
| 3824 | brcmf_cfg80211_flush_pmksa(struct wiphy *wiphy, struct net_device *ndev) |
| 3825 | { |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 3826 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); |
Arend van Spriel | 0abb5f21 | 2012-10-22 13:55:32 -0700 | [diff] [blame] | 3827 | struct brcmf_if *ifp = netdev_priv(ndev); |
Hante Meuleman | 6c404f3 | 2015-12-10 13:43:03 +0100 | [diff] [blame] | 3828 | s32 err; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3829 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 3830 | brcmf_dbg(TRACE, "Enter\n"); |
Arend van Spriel | ce81e31 | 2012-10-22 13:55:37 -0700 | [diff] [blame] | 3831 | if (!check_vif_up(ifp->vif)) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3832 | return -EIO; |
| 3833 | |
Hante Meuleman | 6c404f3 | 2015-12-10 13:43:03 +0100 | [diff] [blame] | 3834 | memset(&cfg->pmk_list, 0, sizeof(cfg->pmk_list)); |
| 3835 | err = brcmf_update_pmklist(cfg, ifp); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3836 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 3837 | brcmf_dbg(TRACE, "Exit\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3838 | return err; |
| 3839 | |
| 3840 | } |
| 3841 | |
Hante Meuleman | 1f17011 | 2013-02-06 18:40:38 +0100 | [diff] [blame] | 3842 | static s32 brcmf_configure_opensecurity(struct brcmf_if *ifp) |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3843 | { |
| 3844 | s32 err; |
| 3845 | |
| 3846 | /* set auth */ |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 3847 | err = brcmf_fil_bsscfg_int_set(ifp, "auth", 0); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3848 | if (err < 0) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 3849 | brcmf_err("auth error %d\n", err); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3850 | return err; |
| 3851 | } |
| 3852 | /* set wsec */ |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 3853 | err = brcmf_fil_bsscfg_int_set(ifp, "wsec", 0); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3854 | if (err < 0) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 3855 | brcmf_err("wsec error %d\n", err); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3856 | return err; |
| 3857 | } |
| 3858 | /* set upper-layer auth */ |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 3859 | err = brcmf_fil_bsscfg_int_set(ifp, "wpa_auth", WPA_AUTH_NONE); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3860 | if (err < 0) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 3861 | brcmf_err("wpa_auth error %d\n", err); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3862 | return err; |
| 3863 | } |
| 3864 | |
| 3865 | return 0; |
| 3866 | } |
| 3867 | |
| 3868 | static bool brcmf_valid_wpa_oui(u8 *oui, bool is_rsn_ie) |
| 3869 | { |
| 3870 | if (is_rsn_ie) |
| 3871 | return (memcmp(oui, RSN_OUI, TLV_OUI_LEN) == 0); |
| 3872 | |
| 3873 | return (memcmp(oui, WPA_OUI, TLV_OUI_LEN) == 0); |
| 3874 | } |
| 3875 | |
| 3876 | static s32 |
Hante Meuleman | a44aa40 | 2014-12-03 21:05:33 +0100 | [diff] [blame] | 3877 | brcmf_configure_wpaie(struct brcmf_if *ifp, |
Johannes Berg | 4b5800f | 2014-01-15 14:55:59 +0100 | [diff] [blame] | 3878 | const struct brcmf_vs_tlv *wpa_ie, |
| 3879 | bool is_rsn_ie) |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3880 | { |
| 3881 | u32 auth = 0; /* d11 open authentication */ |
| 3882 | u16 count; |
| 3883 | s32 err = 0; |
Hante Meuleman | 240d61a | 2016-02-17 11:27:10 +0100 | [diff] [blame] | 3884 | s32 len; |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3885 | u32 i; |
| 3886 | u32 wsec; |
| 3887 | u32 pval = 0; |
| 3888 | u32 gval = 0; |
| 3889 | u32 wpa_auth = 0; |
| 3890 | u32 offset; |
| 3891 | u8 *data; |
| 3892 | u16 rsn_cap; |
| 3893 | u32 wme_bss_disable; |
Hante Meuleman | 240d61a | 2016-02-17 11:27:10 +0100 | [diff] [blame] | 3894 | u32 mfp; |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3895 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 3896 | brcmf_dbg(TRACE, "Enter\n"); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3897 | if (wpa_ie == NULL) |
| 3898 | goto exit; |
| 3899 | |
| 3900 | len = wpa_ie->len + TLV_HDR_LEN; |
| 3901 | data = (u8 *)wpa_ie; |
Hante Meuleman | 619c5a9 | 2013-01-02 15:12:39 +0100 | [diff] [blame] | 3902 | offset = TLV_HDR_LEN; |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3903 | if (!is_rsn_ie) |
| 3904 | offset += VS_IE_FIXED_HDR_LEN; |
Hante Meuleman | 619c5a9 | 2013-01-02 15:12:39 +0100 | [diff] [blame] | 3905 | else |
| 3906 | offset += WPA_IE_VERSION_LEN; |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3907 | |
| 3908 | /* check for multicast cipher suite */ |
| 3909 | if (offset + WPA_IE_MIN_OUI_LEN > len) { |
| 3910 | err = -EINVAL; |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 3911 | brcmf_err("no multicast cipher suite\n"); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3912 | goto exit; |
| 3913 | } |
| 3914 | |
| 3915 | if (!brcmf_valid_wpa_oui(&data[offset], is_rsn_ie)) { |
| 3916 | err = -EINVAL; |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 3917 | brcmf_err("ivalid OUI\n"); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3918 | goto exit; |
| 3919 | } |
| 3920 | offset += TLV_OUI_LEN; |
| 3921 | |
| 3922 | /* pick up multicast cipher */ |
| 3923 | switch (data[offset]) { |
| 3924 | case WPA_CIPHER_NONE: |
| 3925 | gval = 0; |
| 3926 | break; |
| 3927 | case WPA_CIPHER_WEP_40: |
| 3928 | case WPA_CIPHER_WEP_104: |
| 3929 | gval = WEP_ENABLED; |
| 3930 | break; |
| 3931 | case WPA_CIPHER_TKIP: |
| 3932 | gval = TKIP_ENABLED; |
| 3933 | break; |
| 3934 | case WPA_CIPHER_AES_CCM: |
| 3935 | gval = AES_ENABLED; |
| 3936 | break; |
| 3937 | default: |
| 3938 | err = -EINVAL; |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 3939 | brcmf_err("Invalid multi cast cipher info\n"); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3940 | goto exit; |
| 3941 | } |
| 3942 | |
| 3943 | offset++; |
| 3944 | /* walk thru unicast cipher list and pick up what we recognize */ |
| 3945 | count = data[offset] + (data[offset + 1] << 8); |
| 3946 | offset += WPA_IE_SUITE_COUNT_LEN; |
| 3947 | /* Check for unicast suite(s) */ |
| 3948 | if (offset + (WPA_IE_MIN_OUI_LEN * count) > len) { |
| 3949 | err = -EINVAL; |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 3950 | brcmf_err("no unicast cipher suite\n"); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3951 | goto exit; |
| 3952 | } |
| 3953 | for (i = 0; i < count; i++) { |
| 3954 | if (!brcmf_valid_wpa_oui(&data[offset], is_rsn_ie)) { |
| 3955 | err = -EINVAL; |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 3956 | brcmf_err("ivalid OUI\n"); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3957 | goto exit; |
| 3958 | } |
| 3959 | offset += TLV_OUI_LEN; |
| 3960 | switch (data[offset]) { |
| 3961 | case WPA_CIPHER_NONE: |
| 3962 | break; |
| 3963 | case WPA_CIPHER_WEP_40: |
| 3964 | case WPA_CIPHER_WEP_104: |
| 3965 | pval |= WEP_ENABLED; |
| 3966 | break; |
| 3967 | case WPA_CIPHER_TKIP: |
| 3968 | pval |= TKIP_ENABLED; |
| 3969 | break; |
| 3970 | case WPA_CIPHER_AES_CCM: |
| 3971 | pval |= AES_ENABLED; |
| 3972 | break; |
| 3973 | default: |
Colin Ian King | ad334bb | 2016-12-23 00:43:22 +0000 | [diff] [blame^] | 3974 | brcmf_err("Invalid unicast security info\n"); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3975 | } |
| 3976 | offset++; |
| 3977 | } |
| 3978 | /* walk thru auth management suite list and pick up what we recognize */ |
| 3979 | count = data[offset] + (data[offset + 1] << 8); |
| 3980 | offset += WPA_IE_SUITE_COUNT_LEN; |
| 3981 | /* Check for auth key management suite(s) */ |
| 3982 | if (offset + (WPA_IE_MIN_OUI_LEN * count) > len) { |
| 3983 | err = -EINVAL; |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 3984 | brcmf_err("no auth key mgmt suite\n"); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3985 | goto exit; |
| 3986 | } |
| 3987 | for (i = 0; i < count; i++) { |
| 3988 | if (!brcmf_valid_wpa_oui(&data[offset], is_rsn_ie)) { |
| 3989 | err = -EINVAL; |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 3990 | brcmf_err("ivalid OUI\n"); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3991 | goto exit; |
| 3992 | } |
| 3993 | offset += TLV_OUI_LEN; |
| 3994 | switch (data[offset]) { |
| 3995 | case RSN_AKM_NONE: |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 3996 | brcmf_dbg(TRACE, "RSN_AKM_NONE\n"); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3997 | wpa_auth |= WPA_AUTH_NONE; |
| 3998 | break; |
| 3999 | case RSN_AKM_UNSPECIFIED: |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 4000 | brcmf_dbg(TRACE, "RSN_AKM_UNSPECIFIED\n"); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4001 | is_rsn_ie ? (wpa_auth |= WPA2_AUTH_UNSPECIFIED) : |
| 4002 | (wpa_auth |= WPA_AUTH_UNSPECIFIED); |
| 4003 | break; |
| 4004 | case RSN_AKM_PSK: |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 4005 | brcmf_dbg(TRACE, "RSN_AKM_PSK\n"); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4006 | is_rsn_ie ? (wpa_auth |= WPA2_AUTH_PSK) : |
| 4007 | (wpa_auth |= WPA_AUTH_PSK); |
| 4008 | break; |
Hante Meuleman | 240d61a | 2016-02-17 11:27:10 +0100 | [diff] [blame] | 4009 | case RSN_AKM_SHA256_PSK: |
| 4010 | brcmf_dbg(TRACE, "RSN_AKM_MFP_PSK\n"); |
| 4011 | wpa_auth |= WPA2_AUTH_PSK_SHA256; |
| 4012 | break; |
| 4013 | case RSN_AKM_SHA256_1X: |
| 4014 | brcmf_dbg(TRACE, "RSN_AKM_MFP_1X\n"); |
| 4015 | wpa_auth |= WPA2_AUTH_1X_SHA256; |
| 4016 | break; |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4017 | default: |
Colin Ian King | ad334bb | 2016-12-23 00:43:22 +0000 | [diff] [blame^] | 4018 | brcmf_err("Invalid key mgmt info\n"); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4019 | } |
| 4020 | offset++; |
| 4021 | } |
| 4022 | |
Hante Meuleman | 240d61a | 2016-02-17 11:27:10 +0100 | [diff] [blame] | 4023 | mfp = BRCMF_MFP_NONE; |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4024 | if (is_rsn_ie) { |
| 4025 | wme_bss_disable = 1; |
| 4026 | if ((offset + RSN_CAP_LEN) <= len) { |
| 4027 | rsn_cap = data[offset] + (data[offset + 1] << 8); |
| 4028 | if (rsn_cap & RSN_CAP_PTK_REPLAY_CNTR_MASK) |
| 4029 | wme_bss_disable = 0; |
Hante Meuleman | 240d61a | 2016-02-17 11:27:10 +0100 | [diff] [blame] | 4030 | if (rsn_cap & RSN_CAP_MFPR_MASK) { |
| 4031 | brcmf_dbg(TRACE, "MFP Required\n"); |
| 4032 | mfp = BRCMF_MFP_REQUIRED; |
| 4033 | /* Firmware only supports mfp required in |
| 4034 | * combination with WPA2_AUTH_PSK_SHA256 or |
| 4035 | * WPA2_AUTH_1X_SHA256. |
| 4036 | */ |
| 4037 | if (!(wpa_auth & (WPA2_AUTH_PSK_SHA256 | |
| 4038 | WPA2_AUTH_1X_SHA256))) { |
| 4039 | err = -EINVAL; |
| 4040 | goto exit; |
| 4041 | } |
| 4042 | /* Firmware has requirement that WPA2_AUTH_PSK/ |
| 4043 | * WPA2_AUTH_UNSPECIFIED be set, if SHA256 OUI |
| 4044 | * is to be included in the rsn ie. |
| 4045 | */ |
| 4046 | if (wpa_auth & WPA2_AUTH_PSK_SHA256) |
| 4047 | wpa_auth |= WPA2_AUTH_PSK; |
| 4048 | else if (wpa_auth & WPA2_AUTH_1X_SHA256) |
| 4049 | wpa_auth |= WPA2_AUTH_UNSPECIFIED; |
| 4050 | } else if (rsn_cap & RSN_CAP_MFPC_MASK) { |
| 4051 | brcmf_dbg(TRACE, "MFP Capable\n"); |
| 4052 | mfp = BRCMF_MFP_CAPABLE; |
| 4053 | } |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4054 | } |
Hante Meuleman | 240d61a | 2016-02-17 11:27:10 +0100 | [diff] [blame] | 4055 | offset += RSN_CAP_LEN; |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4056 | /* set wme_bss_disable to sync RSN Capabilities */ |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 4057 | err = brcmf_fil_bsscfg_int_set(ifp, "wme_bss_disable", |
Hante Meuleman | 81f5dcb | 2012-10-22 10:36:14 -0700 | [diff] [blame] | 4058 | wme_bss_disable); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4059 | if (err < 0) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 4060 | brcmf_err("wme_bss_disable error %d\n", err); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4061 | goto exit; |
| 4062 | } |
Hante Meuleman | 240d61a | 2016-02-17 11:27:10 +0100 | [diff] [blame] | 4063 | |
| 4064 | /* Skip PMKID cnt as it is know to be 0 for AP. */ |
| 4065 | offset += RSN_PMKID_COUNT_LEN; |
| 4066 | |
| 4067 | /* See if there is BIP wpa suite left for MFP */ |
| 4068 | if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_MFP) && |
| 4069 | ((offset + WPA_IE_MIN_OUI_LEN) <= len)) { |
| 4070 | err = brcmf_fil_bsscfg_data_set(ifp, "bip", |
| 4071 | &data[offset], |
| 4072 | WPA_IE_MIN_OUI_LEN); |
| 4073 | if (err < 0) { |
| 4074 | brcmf_err("bip error %d\n", err); |
| 4075 | goto exit; |
| 4076 | } |
| 4077 | } |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4078 | } |
| 4079 | /* FOR WPS , set SES_OW_ENABLED */ |
| 4080 | wsec = (pval | gval | SES_OW_ENABLED); |
| 4081 | |
| 4082 | /* set auth */ |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 4083 | err = brcmf_fil_bsscfg_int_set(ifp, "auth", auth); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4084 | if (err < 0) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 4085 | brcmf_err("auth error %d\n", err); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4086 | goto exit; |
| 4087 | } |
| 4088 | /* set wsec */ |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 4089 | err = brcmf_fil_bsscfg_int_set(ifp, "wsec", wsec); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4090 | if (err < 0) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 4091 | brcmf_err("wsec error %d\n", err); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4092 | goto exit; |
| 4093 | } |
Hante Meuleman | 240d61a | 2016-02-17 11:27:10 +0100 | [diff] [blame] | 4094 | /* Configure MFP, this needs to go after wsec otherwise the wsec command |
| 4095 | * will overwrite the values set by MFP |
| 4096 | */ |
| 4097 | if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_MFP)) { |
| 4098 | err = brcmf_fil_bsscfg_int_set(ifp, "mfp", mfp); |
| 4099 | if (err < 0) { |
| 4100 | brcmf_err("mfp error %d\n", err); |
| 4101 | goto exit; |
| 4102 | } |
| 4103 | } |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4104 | /* set upper-layer auth */ |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 4105 | err = brcmf_fil_bsscfg_int_set(ifp, "wpa_auth", wpa_auth); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4106 | if (err < 0) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 4107 | brcmf_err("wpa_auth error %d\n", err); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4108 | goto exit; |
| 4109 | } |
| 4110 | |
| 4111 | exit: |
| 4112 | return err; |
| 4113 | } |
| 4114 | |
| 4115 | static s32 |
Arend van Spriel | 3082b9b | 2012-11-05 16:22:12 -0800 | [diff] [blame] | 4116 | brcmf_parse_vndr_ies(const u8 *vndr_ie_buf, u32 vndr_ie_len, |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4117 | struct parsed_vndr_ies *vndr_ies) |
| 4118 | { |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4119 | struct brcmf_vs_tlv *vndrie; |
| 4120 | struct brcmf_tlv *ie; |
| 4121 | struct parsed_vndr_ie_info *parsed_info; |
| 4122 | s32 remaining_len; |
| 4123 | |
| 4124 | remaining_len = (s32)vndr_ie_len; |
| 4125 | memset(vndr_ies, 0, sizeof(*vndr_ies)); |
| 4126 | |
| 4127 | ie = (struct brcmf_tlv *)vndr_ie_buf; |
| 4128 | while (ie) { |
| 4129 | if (ie->id != WLAN_EID_VENDOR_SPECIFIC) |
| 4130 | goto next; |
| 4131 | vndrie = (struct brcmf_vs_tlv *)ie; |
| 4132 | /* len should be bigger than OUI length + one */ |
| 4133 | if (vndrie->len < (VS_IE_FIXED_HDR_LEN - TLV_HDR_LEN + 1)) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 4134 | brcmf_err("invalid vndr ie. length is too small %d\n", |
| 4135 | vndrie->len); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4136 | goto next; |
| 4137 | } |
| 4138 | /* if wpa or wme ie, do not add ie */ |
| 4139 | if (!memcmp(vndrie->oui, (u8 *)WPA_OUI, TLV_OUI_LEN) && |
| 4140 | ((vndrie->oui_type == WPA_OUI_TYPE) || |
| 4141 | (vndrie->oui_type == WME_OUI_TYPE))) { |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 4142 | brcmf_dbg(TRACE, "Found WPA/WME oui. Do not add it\n"); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4143 | goto next; |
| 4144 | } |
| 4145 | |
| 4146 | parsed_info = &vndr_ies->ie_info[vndr_ies->count]; |
| 4147 | |
| 4148 | /* save vndr ie information */ |
| 4149 | parsed_info->ie_ptr = (char *)vndrie; |
| 4150 | parsed_info->ie_len = vndrie->len + TLV_HDR_LEN; |
| 4151 | memcpy(&parsed_info->vndrie, vndrie, sizeof(*vndrie)); |
| 4152 | |
| 4153 | vndr_ies->count++; |
| 4154 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 4155 | brcmf_dbg(TRACE, "** OUI %02x %02x %02x, type 0x%02x\n", |
| 4156 | parsed_info->vndrie.oui[0], |
| 4157 | parsed_info->vndrie.oui[1], |
| 4158 | parsed_info->vndrie.oui[2], |
| 4159 | parsed_info->vndrie.oui_type); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4160 | |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 4161 | if (vndr_ies->count >= VNDR_IE_PARSE_LIMIT) |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4162 | break; |
| 4163 | next: |
Hante Meuleman | b41fc3d | 2012-11-28 21:44:13 +0100 | [diff] [blame] | 4164 | remaining_len -= (ie->len + TLV_HDR_LEN); |
| 4165 | if (remaining_len <= TLV_HDR_LEN) |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4166 | ie = NULL; |
| 4167 | else |
Hante Meuleman | b41fc3d | 2012-11-28 21:44:13 +0100 | [diff] [blame] | 4168 | ie = (struct brcmf_tlv *)(((u8 *)ie) + ie->len + |
| 4169 | TLV_HDR_LEN); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4170 | } |
Peter Senna Tschudin | 12f3237 | 2014-05-31 10:14:06 -0300 | [diff] [blame] | 4171 | return 0; |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4172 | } |
| 4173 | |
| 4174 | static u32 |
| 4175 | brcmf_vndr_ie(u8 *iebuf, s32 pktflag, u8 *ie_ptr, u32 ie_len, s8 *add_del_cmd) |
| 4176 | { |
| 4177 | |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4178 | strncpy(iebuf, add_del_cmd, VNDR_IE_CMD_LEN - 1); |
| 4179 | iebuf[VNDR_IE_CMD_LEN - 1] = '\0'; |
| 4180 | |
Vaishali Thakkar | 362126c | 2015-01-16 21:36:14 +0530 | [diff] [blame] | 4181 | put_unaligned_le32(1, &iebuf[VNDR_IE_COUNT_OFFSET]); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4182 | |
Vaishali Thakkar | 362126c | 2015-01-16 21:36:14 +0530 | [diff] [blame] | 4183 | put_unaligned_le32(pktflag, &iebuf[VNDR_IE_PKTFLAG_OFFSET]); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4184 | |
| 4185 | memcpy(&iebuf[VNDR_IE_VSIE_OFFSET], ie_ptr, ie_len); |
| 4186 | |
| 4187 | return ie_len + VNDR_IE_HDR_SIZE; |
| 4188 | } |
| 4189 | |
Arend van Spriel | 1332e26 | 2012-11-05 16:22:18 -0800 | [diff] [blame] | 4190 | s32 brcmf_vif_set_mgmt_ie(struct brcmf_cfg80211_vif *vif, s32 pktflag, |
| 4191 | const u8 *vndr_ie_buf, u32 vndr_ie_len) |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4192 | { |
Arend van Spriel | 1332e26 | 2012-11-05 16:22:18 -0800 | [diff] [blame] | 4193 | struct brcmf_if *ifp; |
| 4194 | struct vif_saved_ie *saved_ie; |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4195 | s32 err = 0; |
| 4196 | u8 *iovar_ie_buf; |
| 4197 | u8 *curr_ie_buf; |
| 4198 | u8 *mgmt_ie_buf = NULL; |
Dan Carpenter | 3e4f319 | 2012-10-10 11:13:12 -0700 | [diff] [blame] | 4199 | int mgmt_ie_buf_len; |
Dan Carpenter | 81118d1 | 2012-10-10 11:13:07 -0700 | [diff] [blame] | 4200 | u32 *mgmt_ie_len; |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4201 | u32 del_add_ie_buf_len = 0; |
| 4202 | u32 total_ie_buf_len = 0; |
| 4203 | u32 parsed_ie_buf_len = 0; |
| 4204 | struct parsed_vndr_ies old_vndr_ies; |
| 4205 | struct parsed_vndr_ies new_vndr_ies; |
| 4206 | struct parsed_vndr_ie_info *vndrie_info; |
| 4207 | s32 i; |
| 4208 | u8 *ptr; |
Dan Carpenter | 3e4f319 | 2012-10-10 11:13:12 -0700 | [diff] [blame] | 4209 | int remained_buf_len; |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4210 | |
Arend van Spriel | 1332e26 | 2012-11-05 16:22:18 -0800 | [diff] [blame] | 4211 | if (!vif) |
| 4212 | return -ENODEV; |
| 4213 | ifp = vif->ifp; |
| 4214 | saved_ie = &vif->saved_ie; |
| 4215 | |
Hante Meuleman | 37a869e | 2015-10-29 20:33:17 +0100 | [diff] [blame] | 4216 | brcmf_dbg(TRACE, "bsscfgidx %d, pktflag : 0x%02X\n", ifp->bsscfgidx, |
| 4217 | pktflag); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4218 | iovar_ie_buf = kzalloc(WL_EXTRA_BUF_MAX, GFP_KERNEL); |
| 4219 | if (!iovar_ie_buf) |
| 4220 | return -ENOMEM; |
| 4221 | curr_ie_buf = iovar_ie_buf; |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 4222 | switch (pktflag) { |
| 4223 | case BRCMF_VNDR_IE_PRBREQ_FLAG: |
| 4224 | mgmt_ie_buf = saved_ie->probe_req_ie; |
| 4225 | mgmt_ie_len = &saved_ie->probe_req_ie_len; |
| 4226 | mgmt_ie_buf_len = sizeof(saved_ie->probe_req_ie); |
| 4227 | break; |
| 4228 | case BRCMF_VNDR_IE_PRBRSP_FLAG: |
| 4229 | mgmt_ie_buf = saved_ie->probe_res_ie; |
| 4230 | mgmt_ie_len = &saved_ie->probe_res_ie_len; |
| 4231 | mgmt_ie_buf_len = sizeof(saved_ie->probe_res_ie); |
| 4232 | break; |
| 4233 | case BRCMF_VNDR_IE_BEACON_FLAG: |
| 4234 | mgmt_ie_buf = saved_ie->beacon_ie; |
| 4235 | mgmt_ie_len = &saved_ie->beacon_ie_len; |
| 4236 | mgmt_ie_buf_len = sizeof(saved_ie->beacon_ie); |
| 4237 | break; |
| 4238 | case BRCMF_VNDR_IE_ASSOCREQ_FLAG: |
| 4239 | mgmt_ie_buf = saved_ie->assoc_req_ie; |
| 4240 | mgmt_ie_len = &saved_ie->assoc_req_ie_len; |
| 4241 | mgmt_ie_buf_len = sizeof(saved_ie->assoc_req_ie); |
| 4242 | break; |
| 4243 | default: |
| 4244 | err = -EPERM; |
| 4245 | brcmf_err("not suitable type\n"); |
| 4246 | goto exit; |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4247 | } |
| 4248 | |
| 4249 | if (vndr_ie_len > mgmt_ie_buf_len) { |
| 4250 | err = -ENOMEM; |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 4251 | brcmf_err("extra IE size too big\n"); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4252 | goto exit; |
| 4253 | } |
| 4254 | |
| 4255 | /* parse and save new vndr_ie in curr_ie_buff before comparing it */ |
| 4256 | if (vndr_ie_buf && vndr_ie_len && curr_ie_buf) { |
| 4257 | ptr = curr_ie_buf; |
| 4258 | brcmf_parse_vndr_ies(vndr_ie_buf, vndr_ie_len, &new_vndr_ies); |
| 4259 | for (i = 0; i < new_vndr_ies.count; i++) { |
| 4260 | vndrie_info = &new_vndr_ies.ie_info[i]; |
| 4261 | memcpy(ptr + parsed_ie_buf_len, vndrie_info->ie_ptr, |
| 4262 | vndrie_info->ie_len); |
| 4263 | parsed_ie_buf_len += vndrie_info->ie_len; |
| 4264 | } |
| 4265 | } |
| 4266 | |
Hante Meuleman | b41fc3d | 2012-11-28 21:44:13 +0100 | [diff] [blame] | 4267 | if (mgmt_ie_buf && *mgmt_ie_len) { |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4268 | if (parsed_ie_buf_len && (parsed_ie_buf_len == *mgmt_ie_len) && |
| 4269 | (memcmp(mgmt_ie_buf, curr_ie_buf, |
| 4270 | parsed_ie_buf_len) == 0)) { |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 4271 | brcmf_dbg(TRACE, "Previous mgmt IE equals to current IE\n"); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4272 | goto exit; |
| 4273 | } |
| 4274 | |
| 4275 | /* parse old vndr_ie */ |
| 4276 | brcmf_parse_vndr_ies(mgmt_ie_buf, *mgmt_ie_len, &old_vndr_ies); |
| 4277 | |
| 4278 | /* make a command to delete old ie */ |
| 4279 | for (i = 0; i < old_vndr_ies.count; i++) { |
| 4280 | vndrie_info = &old_vndr_ies.ie_info[i]; |
| 4281 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 4282 | brcmf_dbg(TRACE, "DEL ID : %d, Len: %d , OUI:%02x:%02x:%02x\n", |
| 4283 | vndrie_info->vndrie.id, |
| 4284 | vndrie_info->vndrie.len, |
| 4285 | vndrie_info->vndrie.oui[0], |
| 4286 | vndrie_info->vndrie.oui[1], |
| 4287 | vndrie_info->vndrie.oui[2]); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4288 | |
| 4289 | del_add_ie_buf_len = brcmf_vndr_ie(curr_ie_buf, pktflag, |
| 4290 | vndrie_info->ie_ptr, |
| 4291 | vndrie_info->ie_len, |
| 4292 | "del"); |
| 4293 | curr_ie_buf += del_add_ie_buf_len; |
| 4294 | total_ie_buf_len += del_add_ie_buf_len; |
| 4295 | } |
| 4296 | } |
| 4297 | |
| 4298 | *mgmt_ie_len = 0; |
| 4299 | /* Add if there is any extra IE */ |
| 4300 | if (mgmt_ie_buf && parsed_ie_buf_len) { |
| 4301 | ptr = mgmt_ie_buf; |
| 4302 | |
| 4303 | remained_buf_len = mgmt_ie_buf_len; |
| 4304 | |
| 4305 | /* make a command to add new ie */ |
| 4306 | for (i = 0; i < new_vndr_ies.count; i++) { |
| 4307 | vndrie_info = &new_vndr_ies.ie_info[i]; |
| 4308 | |
Hante Meuleman | b41fc3d | 2012-11-28 21:44:13 +0100 | [diff] [blame] | 4309 | /* verify remained buf size before copy data */ |
| 4310 | if (remained_buf_len < (vndrie_info->vndrie.len + |
| 4311 | VNDR_IE_VSIE_OFFSET)) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 4312 | brcmf_err("no space in mgmt_ie_buf: len left %d", |
| 4313 | remained_buf_len); |
Hante Meuleman | b41fc3d | 2012-11-28 21:44:13 +0100 | [diff] [blame] | 4314 | break; |
| 4315 | } |
| 4316 | remained_buf_len -= (vndrie_info->ie_len + |
| 4317 | VNDR_IE_VSIE_OFFSET); |
| 4318 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 4319 | brcmf_dbg(TRACE, "ADDED ID : %d, Len: %d, OUI:%02x:%02x:%02x\n", |
| 4320 | vndrie_info->vndrie.id, |
| 4321 | vndrie_info->vndrie.len, |
| 4322 | vndrie_info->vndrie.oui[0], |
| 4323 | vndrie_info->vndrie.oui[1], |
| 4324 | vndrie_info->vndrie.oui[2]); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4325 | |
| 4326 | del_add_ie_buf_len = brcmf_vndr_ie(curr_ie_buf, pktflag, |
| 4327 | vndrie_info->ie_ptr, |
| 4328 | vndrie_info->ie_len, |
| 4329 | "add"); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4330 | |
| 4331 | /* save the parsed IE in wl struct */ |
| 4332 | memcpy(ptr + (*mgmt_ie_len), vndrie_info->ie_ptr, |
| 4333 | vndrie_info->ie_len); |
| 4334 | *mgmt_ie_len += vndrie_info->ie_len; |
| 4335 | |
| 4336 | curr_ie_buf += del_add_ie_buf_len; |
| 4337 | total_ie_buf_len += del_add_ie_buf_len; |
| 4338 | } |
| 4339 | } |
| 4340 | if (total_ie_buf_len) { |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 4341 | err = brcmf_fil_bsscfg_data_set(ifp, "vndr_ie", iovar_ie_buf, |
Hante Meuleman | 81f5dcb | 2012-10-22 10:36:14 -0700 | [diff] [blame] | 4342 | total_ie_buf_len); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4343 | if (err) |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 4344 | brcmf_err("vndr ie set error : %d\n", err); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4345 | } |
| 4346 | |
| 4347 | exit: |
| 4348 | kfree(iovar_ie_buf); |
| 4349 | return err; |
| 4350 | } |
| 4351 | |
Arend van Spriel | 5f4f9f1 | 2013-02-08 15:53:41 +0100 | [diff] [blame] | 4352 | s32 brcmf_vif_clear_mgmt_ies(struct brcmf_cfg80211_vif *vif) |
| 4353 | { |
| 4354 | s32 pktflags[] = { |
| 4355 | BRCMF_VNDR_IE_PRBREQ_FLAG, |
| 4356 | BRCMF_VNDR_IE_PRBRSP_FLAG, |
| 4357 | BRCMF_VNDR_IE_BEACON_FLAG |
| 4358 | }; |
| 4359 | int i; |
| 4360 | |
| 4361 | for (i = 0; i < ARRAY_SIZE(pktflags); i++) |
| 4362 | brcmf_vif_set_mgmt_ie(vif, pktflags[i], NULL, 0); |
| 4363 | |
| 4364 | memset(&vif->saved_ie, 0, sizeof(vif->saved_ie)); |
| 4365 | return 0; |
| 4366 | } |
| 4367 | |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4368 | static s32 |
Hante Meuleman | a0f0795 | 2013-02-08 15:53:47 +0100 | [diff] [blame] | 4369 | brcmf_config_ap_mgmt_ie(struct brcmf_cfg80211_vif *vif, |
| 4370 | struct cfg80211_beacon_data *beacon) |
| 4371 | { |
| 4372 | s32 err; |
| 4373 | |
| 4374 | /* Set Beacon IEs to FW */ |
| 4375 | err = brcmf_vif_set_mgmt_ie(vif, BRCMF_VNDR_IE_BEACON_FLAG, |
| 4376 | beacon->tail, beacon->tail_len); |
| 4377 | if (err) { |
| 4378 | brcmf_err("Set Beacon IE Failed\n"); |
| 4379 | return err; |
| 4380 | } |
| 4381 | brcmf_dbg(TRACE, "Applied Vndr IEs for Beacon\n"); |
| 4382 | |
| 4383 | /* Set Probe Response IEs to FW */ |
| 4384 | err = brcmf_vif_set_mgmt_ie(vif, BRCMF_VNDR_IE_PRBRSP_FLAG, |
| 4385 | beacon->proberesp_ies, |
| 4386 | beacon->proberesp_ies_len); |
| 4387 | if (err) |
| 4388 | brcmf_err("Set Probe Resp IE Failed\n"); |
| 4389 | else |
| 4390 | brcmf_dbg(TRACE, "Applied Vndr IEs for Probe Resp\n"); |
| 4391 | |
| 4392 | return err; |
| 4393 | } |
| 4394 | |
| 4395 | static s32 |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4396 | brcmf_cfg80211_start_ap(struct wiphy *wiphy, struct net_device *ndev, |
| 4397 | struct cfg80211_ap_settings *settings) |
| 4398 | { |
| 4399 | s32 ie_offset; |
Hante Meuleman | 1c9d30c | 2013-05-27 21:09:58 +0200 | [diff] [blame] | 4400 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 4401 | struct brcmf_if *ifp = netdev_priv(ndev); |
Johannes Berg | 4b5800f | 2014-01-15 14:55:59 +0100 | [diff] [blame] | 4402 | const struct brcmf_tlv *ssid_ie; |
Arend van Spriel | 9802776 | 2014-12-21 12:43:53 +0100 | [diff] [blame] | 4403 | const struct brcmf_tlv *country_ie; |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4404 | struct brcmf_ssid_le ssid_le; |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4405 | s32 err = -EPERM; |
Johannes Berg | 4b5800f | 2014-01-15 14:55:59 +0100 | [diff] [blame] | 4406 | const struct brcmf_tlv *rsn_ie; |
| 4407 | const struct brcmf_vs_tlv *wpa_ie; |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4408 | struct brcmf_join_params join_params; |
Hante Meuleman | a0f0795 | 2013-02-08 15:53:47 +0100 | [diff] [blame] | 4409 | enum nl80211_iftype dev_role; |
| 4410 | struct brcmf_fil_bss_enable_le bss_enable; |
Rafał Miłecki | 8707e08 | 2016-05-27 21:07:19 +0200 | [diff] [blame] | 4411 | u16 chanspec = chandef_to_chanspec(&cfg->d11inf, &settings->chandef); |
Hante Meuleman | a44aa40 | 2014-12-03 21:05:33 +0100 | [diff] [blame] | 4412 | bool mbss; |
Arend van Spriel | 9802776 | 2014-12-21 12:43:53 +0100 | [diff] [blame] | 4413 | int is_11d; |
Hante Meuleman | b3589df | 2016-09-19 12:09:51 +0100 | [diff] [blame] | 4414 | bool supports_11d; |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4415 | |
Arend van Spriel | 06c0158 | 2014-05-12 10:47:37 +0200 | [diff] [blame] | 4416 | brcmf_dbg(TRACE, "ctrlchn=%d, center=%d, bw=%d, beacon_interval=%d, dtim_period=%d,\n", |
| 4417 | settings->chandef.chan->hw_value, |
| 4418 | settings->chandef.center_freq1, settings->chandef.width, |
Arend van Spriel | a9a5687 | 2014-05-12 10:47:33 +0200 | [diff] [blame] | 4419 | settings->beacon_interval, settings->dtim_period); |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 4420 | brcmf_dbg(TRACE, "ssid=%s(%zu), auth_type=%d, inactivity_timeout=%d\n", |
| 4421 | settings->ssid, settings->ssid_len, settings->auth_type, |
| 4422 | settings->inactivity_timeout); |
Hante Meuleman | 426d0a5 | 2013-02-08 15:53:53 +0100 | [diff] [blame] | 4423 | dev_role = ifp->vif->wdev.iftype; |
Hante Meuleman | a44aa40 | 2014-12-03 21:05:33 +0100 | [diff] [blame] | 4424 | mbss = ifp->vif->mbss; |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4425 | |
Arend van Spriel | 9802776 | 2014-12-21 12:43:53 +0100 | [diff] [blame] | 4426 | /* store current 11d setting */ |
Hante Meuleman | b3589df | 2016-09-19 12:09:51 +0100 | [diff] [blame] | 4427 | if (brcmf_fil_cmd_int_get(ifp, BRCMF_C_GET_REGULATORY, |
| 4428 | &ifp->vif->is_11d)) { |
Arnd Bergmann | d3532ea | 2016-10-18 00:13:40 +0200 | [diff] [blame] | 4429 | is_11d = supports_11d = false; |
Hante Meuleman | b3589df | 2016-09-19 12:09:51 +0100 | [diff] [blame] | 4430 | } else { |
| 4431 | country_ie = brcmf_parse_tlvs((u8 *)settings->beacon.tail, |
| 4432 | settings->beacon.tail_len, |
| 4433 | WLAN_EID_COUNTRY); |
| 4434 | is_11d = country_ie ? 1 : 0; |
| 4435 | supports_11d = true; |
| 4436 | } |
Arend van Spriel | 9802776 | 2014-12-21 12:43:53 +0100 | [diff] [blame] | 4437 | |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4438 | memset(&ssid_le, 0, sizeof(ssid_le)); |
| 4439 | if (settings->ssid == NULL || settings->ssid_len == 0) { |
| 4440 | ie_offset = DOT11_MGMT_HDR_LEN + DOT11_BCN_PRB_FIXED_LEN; |
| 4441 | ssid_ie = brcmf_parse_tlvs( |
| 4442 | (u8 *)&settings->beacon.head[ie_offset], |
| 4443 | settings->beacon.head_len - ie_offset, |
| 4444 | WLAN_EID_SSID); |
Arend Van Spriel | ded8991 | 2016-09-05 10:45:47 +0100 | [diff] [blame] | 4445 | if (!ssid_ie || ssid_ie->len > IEEE80211_MAX_SSID_LEN) |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4446 | return -EINVAL; |
| 4447 | |
| 4448 | memcpy(ssid_le.SSID, ssid_ie->data, ssid_ie->len); |
| 4449 | ssid_le.SSID_len = cpu_to_le32(ssid_ie->len); |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 4450 | brcmf_dbg(TRACE, "SSID is (%s) in Head\n", ssid_le.SSID); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4451 | } else { |
| 4452 | memcpy(ssid_le.SSID, settings->ssid, settings->ssid_len); |
| 4453 | ssid_le.SSID_len = cpu_to_le32((u32)settings->ssid_len); |
| 4454 | } |
| 4455 | |
Hante Meuleman | a44aa40 | 2014-12-03 21:05:33 +0100 | [diff] [blame] | 4456 | if (!mbss) { |
| 4457 | brcmf_set_mpc(ifp, 0); |
Franky Lin | 52f22fb | 2016-02-17 11:26:55 +0100 | [diff] [blame] | 4458 | brcmf_configure_arp_nd_offload(ifp, false); |
Hante Meuleman | a44aa40 | 2014-12-03 21:05:33 +0100 | [diff] [blame] | 4459 | } |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4460 | |
| 4461 | /* find the RSN_IE */ |
| 4462 | rsn_ie = brcmf_parse_tlvs((u8 *)settings->beacon.tail, |
| 4463 | settings->beacon.tail_len, WLAN_EID_RSN); |
| 4464 | |
| 4465 | /* find the WPA_IE */ |
| 4466 | wpa_ie = brcmf_find_wpaie((u8 *)settings->beacon.tail, |
| 4467 | settings->beacon.tail_len); |
| 4468 | |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4469 | if ((wpa_ie != NULL || rsn_ie != NULL)) { |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 4470 | brcmf_dbg(TRACE, "WPA(2) IE is found\n"); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4471 | if (wpa_ie != NULL) { |
| 4472 | /* WPA IE */ |
Hante Meuleman | a44aa40 | 2014-12-03 21:05:33 +0100 | [diff] [blame] | 4473 | err = brcmf_configure_wpaie(ifp, wpa_ie, false); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4474 | if (err < 0) |
| 4475 | goto exit; |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4476 | } else { |
Hante Meuleman | a44aa40 | 2014-12-03 21:05:33 +0100 | [diff] [blame] | 4477 | struct brcmf_vs_tlv *tmp_ie; |
| 4478 | |
| 4479 | tmp_ie = (struct brcmf_vs_tlv *)rsn_ie; |
| 4480 | |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4481 | /* RSN IE */ |
Hante Meuleman | a44aa40 | 2014-12-03 21:05:33 +0100 | [diff] [blame] | 4482 | err = brcmf_configure_wpaie(ifp, tmp_ie, true); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4483 | if (err < 0) |
| 4484 | goto exit; |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4485 | } |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4486 | } else { |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 4487 | brcmf_dbg(TRACE, "No WPA(2) IEs found\n"); |
Hante Meuleman | 1f17011 | 2013-02-06 18:40:38 +0100 | [diff] [blame] | 4488 | brcmf_configure_opensecurity(ifp); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4489 | } |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4490 | |
Rafał Miłecki | 8707e08 | 2016-05-27 21:07:19 +0200 | [diff] [blame] | 4491 | /* Parameters shared by all radio interfaces */ |
Hante Meuleman | a44aa40 | 2014-12-03 21:05:33 +0100 | [diff] [blame] | 4492 | if (!mbss) { |
Hante Meuleman | b3589df | 2016-09-19 12:09:51 +0100 | [diff] [blame] | 4493 | if ((supports_11d) && (is_11d != ifp->vif->is_11d)) { |
Arend van Spriel | 9802776 | 2014-12-21 12:43:53 +0100 | [diff] [blame] | 4494 | err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_REGULATORY, |
| 4495 | is_11d); |
| 4496 | if (err < 0) { |
| 4497 | brcmf_err("Regulatory Set Error, %d\n", err); |
| 4498 | goto exit; |
| 4499 | } |
| 4500 | } |
Hante Meuleman | a44aa40 | 2014-12-03 21:05:33 +0100 | [diff] [blame] | 4501 | if (settings->beacon_interval) { |
| 4502 | err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_BCNPRD, |
| 4503 | settings->beacon_interval); |
| 4504 | if (err < 0) { |
| 4505 | brcmf_err("Beacon Interval Set Error, %d\n", |
| 4506 | err); |
| 4507 | goto exit; |
| 4508 | } |
| 4509 | } |
| 4510 | if (settings->dtim_period) { |
| 4511 | err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_DTIMPRD, |
| 4512 | settings->dtim_period); |
| 4513 | if (err < 0) { |
| 4514 | brcmf_err("DTIM Interval Set Error, %d\n", err); |
| 4515 | goto exit; |
| 4516 | } |
| 4517 | } |
| 4518 | |
Hante Meuleman | 8abffd8 | 2015-10-29 20:33:16 +0100 | [diff] [blame] | 4519 | if ((dev_role == NL80211_IFTYPE_AP) && |
| 4520 | ((ifp->ifidx == 0) || |
| 4521 | !brcmf_feat_is_enabled(ifp, BRCMF_FEAT_RSDB))) { |
Hante Meuleman | a44aa40 | 2014-12-03 21:05:33 +0100 | [diff] [blame] | 4522 | err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_DOWN, 1); |
| 4523 | if (err < 0) { |
| 4524 | brcmf_err("BRCMF_C_DOWN error %d\n", err); |
| 4525 | goto exit; |
| 4526 | } |
| 4527 | brcmf_fil_iovar_int_set(ifp, "apsta", 0); |
| 4528 | } |
| 4529 | |
| 4530 | err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_INFRA, 1); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4531 | if (err < 0) { |
Hante Meuleman | a44aa40 | 2014-12-03 21:05:33 +0100 | [diff] [blame] | 4532 | brcmf_err("SET INFRA error %d\n", err); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4533 | goto exit; |
| 4534 | } |
Hante Meuleman | b3589df | 2016-09-19 12:09:51 +0100 | [diff] [blame] | 4535 | } else if (WARN_ON(supports_11d && (is_11d != ifp->vif->is_11d))) { |
Arend van Spriel | 9802776 | 2014-12-21 12:43:53 +0100 | [diff] [blame] | 4536 | /* Multiple-BSS should use same 11d configuration */ |
| 4537 | err = -EINVAL; |
| 4538 | goto exit; |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4539 | } |
Rafał Miłecki | 8707e08 | 2016-05-27 21:07:19 +0200 | [diff] [blame] | 4540 | |
| 4541 | /* Interface specific setup */ |
Hante Meuleman | a0f0795 | 2013-02-08 15:53:47 +0100 | [diff] [blame] | 4542 | if (dev_role == NL80211_IFTYPE_AP) { |
Hante Meuleman | a44aa40 | 2014-12-03 21:05:33 +0100 | [diff] [blame] | 4543 | if ((brcmf_feat_is_enabled(ifp, BRCMF_FEAT_MBSS)) && (!mbss)) |
| 4544 | brcmf_fil_iovar_int_set(ifp, "mbss", 1); |
| 4545 | |
Hante Meuleman | a0f0795 | 2013-02-08 15:53:47 +0100 | [diff] [blame] | 4546 | err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_AP, 1); |
| 4547 | if (err < 0) { |
| 4548 | brcmf_err("setting AP mode failed %d\n", err); |
| 4549 | goto exit; |
| 4550 | } |
Rafał Miłecki | 8707e08 | 2016-05-27 21:07:19 +0200 | [diff] [blame] | 4551 | if (!mbss) { |
| 4552 | /* Firmware 10.x requires setting channel after enabling |
| 4553 | * AP and before bringing interface up. |
| 4554 | */ |
| 4555 | err = brcmf_fil_iovar_int_set(ifp, "chanspec", chanspec); |
| 4556 | if (err < 0) { |
| 4557 | brcmf_err("Set Channel failed: chspec=%d, %d\n", |
| 4558 | chanspec, err); |
| 4559 | goto exit; |
| 4560 | } |
| 4561 | } |
Hante Meuleman | a0f0795 | 2013-02-08 15:53:47 +0100 | [diff] [blame] | 4562 | err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_UP, 1); |
| 4563 | if (err < 0) { |
| 4564 | brcmf_err("BRCMF_C_UP error (%d)\n", err); |
| 4565 | goto exit; |
| 4566 | } |
Hante Meuleman | 118eb30 | 2014-12-21 12:43:49 +0100 | [diff] [blame] | 4567 | /* On DOWN the firmware removes the WEP keys, reconfigure |
| 4568 | * them if they were set. |
| 4569 | */ |
| 4570 | brcmf_cfg80211_reconfigure_wep(ifp); |
Hante Meuleman | a0f0795 | 2013-02-08 15:53:47 +0100 | [diff] [blame] | 4571 | |
| 4572 | memset(&join_params, 0, sizeof(join_params)); |
| 4573 | /* join parameters starts with ssid */ |
| 4574 | memcpy(&join_params.ssid_le, &ssid_le, sizeof(ssid_le)); |
| 4575 | /* create softap */ |
| 4576 | err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SET_SSID, |
| 4577 | &join_params, sizeof(join_params)); |
| 4578 | if (err < 0) { |
| 4579 | brcmf_err("SET SSID error (%d)\n", err); |
| 4580 | goto exit; |
| 4581 | } |
Rafał Miłecki | c940de1 | 2016-07-06 12:22:54 +0200 | [diff] [blame] | 4582 | |
| 4583 | if (settings->hidden_ssid) { |
| 4584 | err = brcmf_fil_iovar_int_set(ifp, "closednet", 1); |
| 4585 | if (err) { |
| 4586 | brcmf_err("closednet error (%d)\n", err); |
| 4587 | goto exit; |
| 4588 | } |
| 4589 | } |
| 4590 | |
Hante Meuleman | a0f0795 | 2013-02-08 15:53:47 +0100 | [diff] [blame] | 4591 | brcmf_dbg(TRACE, "AP mode configuration complete\n"); |
Rafał Miłecki | 8707e08 | 2016-05-27 21:07:19 +0200 | [diff] [blame] | 4592 | } else if (dev_role == NL80211_IFTYPE_P2P_GO) { |
| 4593 | err = brcmf_fil_iovar_int_set(ifp, "chanspec", chanspec); |
| 4594 | if (err < 0) { |
| 4595 | brcmf_err("Set Channel failed: chspec=%d, %d\n", |
| 4596 | chanspec, err); |
| 4597 | goto exit; |
| 4598 | } |
Hante Meuleman | a0f0795 | 2013-02-08 15:53:47 +0100 | [diff] [blame] | 4599 | err = brcmf_fil_bsscfg_data_set(ifp, "ssid", &ssid_le, |
| 4600 | sizeof(ssid_le)); |
| 4601 | if (err < 0) { |
| 4602 | brcmf_err("setting ssid failed %d\n", err); |
| 4603 | goto exit; |
| 4604 | } |
Hante Meuleman | 37a869e | 2015-10-29 20:33:17 +0100 | [diff] [blame] | 4605 | bss_enable.bsscfgidx = cpu_to_le32(ifp->bsscfgidx); |
Hante Meuleman | a0f0795 | 2013-02-08 15:53:47 +0100 | [diff] [blame] | 4606 | bss_enable.enable = cpu_to_le32(1); |
| 4607 | err = brcmf_fil_iovar_data_set(ifp, "bss", &bss_enable, |
| 4608 | sizeof(bss_enable)); |
| 4609 | if (err < 0) { |
| 4610 | brcmf_err("bss_enable config failed %d\n", err); |
| 4611 | goto exit; |
| 4612 | } |
| 4613 | |
| 4614 | brcmf_dbg(TRACE, "GO mode configuration complete\n"); |
Rafał Miłecki | 8707e08 | 2016-05-27 21:07:19 +0200 | [diff] [blame] | 4615 | } else { |
| 4616 | WARN_ON(1); |
Hante Meuleman | a0f0795 | 2013-02-08 15:53:47 +0100 | [diff] [blame] | 4617 | } |
Rafał Miłecki | 8707e08 | 2016-05-27 21:07:19 +0200 | [diff] [blame] | 4618 | |
Wright Feng | f25ba69 | 2016-11-18 09:59:52 +0800 | [diff] [blame] | 4619 | brcmf_config_ap_mgmt_ie(ifp->vif, &settings->beacon); |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 4620 | set_bit(BRCMF_VIF_STATUS_AP_CREATED, &ifp->vif->sme_state); |
Hante Meuleman | 92121e6 | 2015-10-08 20:33:21 +0200 | [diff] [blame] | 4621 | brcmf_net_setcarrier(ifp, true); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4622 | |
| 4623 | exit: |
Hante Meuleman | a44aa40 | 2014-12-03 21:05:33 +0100 | [diff] [blame] | 4624 | if ((err) && (!mbss)) { |
Arend van Spriel | f96aa07 | 2013-04-05 10:57:48 +0200 | [diff] [blame] | 4625 | brcmf_set_mpc(ifp, 1); |
Franky Lin | 52f22fb | 2016-02-17 11:26:55 +0100 | [diff] [blame] | 4626 | brcmf_configure_arp_nd_offload(ifp, true); |
Hante Meuleman | b365745 | 2013-05-27 21:09:53 +0200 | [diff] [blame] | 4627 | } |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4628 | return err; |
| 4629 | } |
| 4630 | |
| 4631 | static int brcmf_cfg80211_stop_ap(struct wiphy *wiphy, struct net_device *ndev) |
| 4632 | { |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 4633 | struct brcmf_if *ifp = netdev_priv(ndev); |
Hante Meuleman | 5c33a94 | 2013-04-02 21:06:18 +0200 | [diff] [blame] | 4634 | s32 err; |
Hante Meuleman | 426d0a5 | 2013-02-08 15:53:53 +0100 | [diff] [blame] | 4635 | struct brcmf_fil_bss_enable_le bss_enable; |
Hante Meuleman | 5c33a94 | 2013-04-02 21:06:18 +0200 | [diff] [blame] | 4636 | struct brcmf_join_params join_params; |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4637 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 4638 | brcmf_dbg(TRACE, "Enter\n"); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4639 | |
Hante Meuleman | 426d0a5 | 2013-02-08 15:53:53 +0100 | [diff] [blame] | 4640 | if (ifp->vif->wdev.iftype == NL80211_IFTYPE_AP) { |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4641 | /* Due to most likely deauths outstanding we sleep */ |
| 4642 | /* first to make sure they get processed by fw. */ |
| 4643 | msleep(400); |
Hante Meuleman | 5c33a94 | 2013-04-02 21:06:18 +0200 | [diff] [blame] | 4644 | |
Hante Meuleman | a44aa40 | 2014-12-03 21:05:33 +0100 | [diff] [blame] | 4645 | if (ifp->vif->mbss) { |
| 4646 | err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_DOWN, 1); |
| 4647 | return err; |
| 4648 | } |
| 4649 | |
Rafał Miłecki | c940de1 | 2016-07-06 12:22:54 +0200 | [diff] [blame] | 4650 | /* First BSS doesn't get a full reset */ |
| 4651 | if (ifp->bsscfgidx == 0) |
| 4652 | brcmf_fil_iovar_int_set(ifp, "closednet", 0); |
| 4653 | |
Hante Meuleman | 5c33a94 | 2013-04-02 21:06:18 +0200 | [diff] [blame] | 4654 | memset(&join_params, 0, sizeof(join_params)); |
| 4655 | err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SET_SSID, |
| 4656 | &join_params, sizeof(join_params)); |
| 4657 | if (err < 0) |
| 4658 | brcmf_err("SET SSID error (%d)\n", err); |
Hante Meuleman | a44aa40 | 2014-12-03 21:05:33 +0100 | [diff] [blame] | 4659 | err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_DOWN, 1); |
Hante Meuleman | 5c33a94 | 2013-04-02 21:06:18 +0200 | [diff] [blame] | 4660 | if (err < 0) |
Hante Meuleman | a44aa40 | 2014-12-03 21:05:33 +0100 | [diff] [blame] | 4661 | brcmf_err("BRCMF_C_DOWN error %d\n", err); |
Hante Meuleman | 5c33a94 | 2013-04-02 21:06:18 +0200 | [diff] [blame] | 4662 | err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_AP, 0); |
| 4663 | if (err < 0) |
| 4664 | brcmf_err("setting AP mode failed %d\n", err); |
| 4665 | err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_INFRA, 0); |
| 4666 | if (err < 0) |
| 4667 | brcmf_err("setting INFRA mode failed %d\n", err); |
Hante Meuleman | a44aa40 | 2014-12-03 21:05:33 +0100 | [diff] [blame] | 4668 | if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_MBSS)) |
| 4669 | brcmf_fil_iovar_int_set(ifp, "mbss", 0); |
Hante Meuleman | b3589df | 2016-09-19 12:09:51 +0100 | [diff] [blame] | 4670 | brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_REGULATORY, |
| 4671 | ifp->vif->is_11d); |
Hante Meuleman | a44aa40 | 2014-12-03 21:05:33 +0100 | [diff] [blame] | 4672 | /* Bring device back up so it can be used again */ |
| 4673 | err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_UP, 1); |
| 4674 | if (err < 0) |
| 4675 | brcmf_err("BRCMF_C_UP error %d\n", err); |
Wright Feng | f25ba69 | 2016-11-18 09:59:52 +0800 | [diff] [blame] | 4676 | |
| 4677 | brcmf_vif_clear_mgmt_ies(ifp->vif); |
Hante Meuleman | 426d0a5 | 2013-02-08 15:53:53 +0100 | [diff] [blame] | 4678 | } else { |
Hante Meuleman | 37a869e | 2015-10-29 20:33:17 +0100 | [diff] [blame] | 4679 | bss_enable.bsscfgidx = cpu_to_le32(ifp->bsscfgidx); |
Hante Meuleman | 426d0a5 | 2013-02-08 15:53:53 +0100 | [diff] [blame] | 4680 | bss_enable.enable = cpu_to_le32(0); |
| 4681 | err = brcmf_fil_iovar_data_set(ifp, "bss", &bss_enable, |
| 4682 | sizeof(bss_enable)); |
| 4683 | if (err < 0) |
| 4684 | brcmf_err("bss_enable config failed %d\n", err); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4685 | } |
Arend van Spriel | f96aa07 | 2013-04-05 10:57:48 +0200 | [diff] [blame] | 4686 | brcmf_set_mpc(ifp, 1); |
Franky Lin | 52f22fb | 2016-02-17 11:26:55 +0100 | [diff] [blame] | 4687 | brcmf_configure_arp_nd_offload(ifp, true); |
Hante Meuleman | 426d0a5 | 2013-02-08 15:53:53 +0100 | [diff] [blame] | 4688 | clear_bit(BRCMF_VIF_STATUS_AP_CREATED, &ifp->vif->sme_state); |
Hante Meuleman | 92121e6 | 2015-10-08 20:33:21 +0200 | [diff] [blame] | 4689 | brcmf_net_setcarrier(ifp, false); |
Hante Meuleman | 426d0a5 | 2013-02-08 15:53:53 +0100 | [diff] [blame] | 4690 | |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4691 | return err; |
| 4692 | } |
| 4693 | |
Hante Meuleman | a0f0795 | 2013-02-08 15:53:47 +0100 | [diff] [blame] | 4694 | static s32 |
| 4695 | brcmf_cfg80211_change_beacon(struct wiphy *wiphy, struct net_device *ndev, |
| 4696 | struct cfg80211_beacon_data *info) |
| 4697 | { |
Hante Meuleman | a0f0795 | 2013-02-08 15:53:47 +0100 | [diff] [blame] | 4698 | struct brcmf_if *ifp = netdev_priv(ndev); |
| 4699 | s32 err; |
| 4700 | |
| 4701 | brcmf_dbg(TRACE, "Enter\n"); |
| 4702 | |
Hante Meuleman | a0f0795 | 2013-02-08 15:53:47 +0100 | [diff] [blame] | 4703 | err = brcmf_config_ap_mgmt_ie(ifp->vif, info); |
| 4704 | |
| 4705 | return err; |
| 4706 | } |
| 4707 | |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4708 | static int |
| 4709 | brcmf_cfg80211_del_station(struct wiphy *wiphy, struct net_device *ndev, |
Jouni Malinen | 89c771e | 2014-10-10 20:52:40 +0300 | [diff] [blame] | 4710 | struct station_del_parameters *params) |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4711 | { |
Hante Meuleman | a0f0795 | 2013-02-08 15:53:47 +0100 | [diff] [blame] | 4712 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4713 | struct brcmf_scb_val_le scbval; |
Arend van Spriel | 0abb5f21 | 2012-10-22 13:55:32 -0700 | [diff] [blame] | 4714 | struct brcmf_if *ifp = netdev_priv(ndev); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4715 | s32 err; |
| 4716 | |
Jouni Malinen | 89c771e | 2014-10-10 20:52:40 +0300 | [diff] [blame] | 4717 | if (!params->mac) |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4718 | return -EFAULT; |
| 4719 | |
Jouni Malinen | 89c771e | 2014-10-10 20:52:40 +0300 | [diff] [blame] | 4720 | brcmf_dbg(TRACE, "Enter %pM\n", params->mac); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4721 | |
Hante Meuleman | a0f0795 | 2013-02-08 15:53:47 +0100 | [diff] [blame] | 4722 | if (ifp->vif == cfg->p2p.bss_idx[P2PAPI_BSSCFG_DEVICE].vif) |
| 4723 | ifp = cfg->p2p.bss_idx[P2PAPI_BSSCFG_PRIMARY].vif->ifp; |
Arend van Spriel | ce81e31 | 2012-10-22 13:55:37 -0700 | [diff] [blame] | 4724 | if (!check_vif_up(ifp->vif)) |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4725 | return -EIO; |
| 4726 | |
Jouni Malinen | 89c771e | 2014-10-10 20:52:40 +0300 | [diff] [blame] | 4727 | memcpy(&scbval.ea, params->mac, ETH_ALEN); |
Rafał Miłecki | ba8b6ae | 2015-02-08 11:51:47 +0100 | [diff] [blame] | 4728 | scbval.val = cpu_to_le32(params->reason_code); |
Arend van Spriel | 0abb5f21 | 2012-10-22 13:55:32 -0700 | [diff] [blame] | 4729 | err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SCB_DEAUTHENTICATE_FOR_REASON, |
Hante Meuleman | 81f5dcb | 2012-10-22 10:36:14 -0700 | [diff] [blame] | 4730 | &scbval, sizeof(scbval)); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4731 | if (err) |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 4732 | brcmf_err("SCB_DEAUTHENTICATE_FOR_REASON failed %d\n", err); |
Hante Meuleman | 7ab6acd | 2013-02-08 15:53:58 +0100 | [diff] [blame] | 4733 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 4734 | brcmf_dbg(TRACE, "Exit\n"); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4735 | return err; |
| 4736 | } |
| 4737 | |
Hante Meuleman | 6b89dcb | 2014-12-21 12:43:52 +0100 | [diff] [blame] | 4738 | static int |
| 4739 | brcmf_cfg80211_change_station(struct wiphy *wiphy, struct net_device *ndev, |
| 4740 | const u8 *mac, struct station_parameters *params) |
| 4741 | { |
| 4742 | struct brcmf_if *ifp = netdev_priv(ndev); |
| 4743 | s32 err; |
| 4744 | |
| 4745 | brcmf_dbg(TRACE, "Enter, MAC %pM, mask 0x%04x set 0x%04x\n", mac, |
| 4746 | params->sta_flags_mask, params->sta_flags_set); |
| 4747 | |
| 4748 | /* Ignore all 00 MAC */ |
| 4749 | if (is_zero_ether_addr(mac)) |
| 4750 | return 0; |
| 4751 | |
| 4752 | if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED))) |
| 4753 | return 0; |
| 4754 | |
| 4755 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED)) |
| 4756 | err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SET_SCB_AUTHORIZE, |
| 4757 | (void *)mac, ETH_ALEN); |
| 4758 | else |
| 4759 | err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SET_SCB_DEAUTHORIZE, |
| 4760 | (void *)mac, ETH_ALEN); |
| 4761 | if (err < 0) |
| 4762 | brcmf_err("Setting SCB (de-)authorize failed, %d\n", err); |
| 4763 | |
| 4764 | return err; |
| 4765 | } |
Hante Meuleman | 0de8aac | 2013-02-08 15:53:38 +0100 | [diff] [blame] | 4766 | |
| 4767 | static void |
| 4768 | brcmf_cfg80211_mgmt_frame_register(struct wiphy *wiphy, |
| 4769 | struct wireless_dev *wdev, |
| 4770 | u16 frame_type, bool reg) |
| 4771 | { |
Arend van Spriel | 7fa2e35 | 2013-04-05 10:57:47 +0200 | [diff] [blame] | 4772 | struct brcmf_cfg80211_vif *vif; |
Hante Meuleman | 0de8aac | 2013-02-08 15:53:38 +0100 | [diff] [blame] | 4773 | u16 mgmt_type; |
| 4774 | |
| 4775 | brcmf_dbg(TRACE, "Enter, frame_type %04x, reg=%d\n", frame_type, reg); |
| 4776 | |
| 4777 | mgmt_type = (frame_type & IEEE80211_FCTL_STYPE) >> 4; |
Arend van Spriel | 7fa2e35 | 2013-04-05 10:57:47 +0200 | [diff] [blame] | 4778 | vif = container_of(wdev, struct brcmf_cfg80211_vif, wdev); |
Hante Meuleman | 0de8aac | 2013-02-08 15:53:38 +0100 | [diff] [blame] | 4779 | if (reg) |
| 4780 | vif->mgmt_rx_reg |= BIT(mgmt_type); |
| 4781 | else |
Hante Meuleman | 318a64c | 2013-02-08 15:53:45 +0100 | [diff] [blame] | 4782 | vif->mgmt_rx_reg &= ~BIT(mgmt_type); |
Hante Meuleman | 0de8aac | 2013-02-08 15:53:38 +0100 | [diff] [blame] | 4783 | } |
| 4784 | |
| 4785 | |
| 4786 | static int |
| 4787 | brcmf_cfg80211_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev, |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 4788 | struct cfg80211_mgmt_tx_params *params, u64 *cookie) |
Hante Meuleman | 0de8aac | 2013-02-08 15:53:38 +0100 | [diff] [blame] | 4789 | { |
| 4790 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 4791 | struct ieee80211_channel *chan = params->chan; |
| 4792 | const u8 *buf = params->buf; |
| 4793 | size_t len = params->len; |
Hante Meuleman | 0de8aac | 2013-02-08 15:53:38 +0100 | [diff] [blame] | 4794 | const struct ieee80211_mgmt *mgmt; |
| 4795 | struct brcmf_cfg80211_vif *vif; |
| 4796 | s32 err = 0; |
| 4797 | s32 ie_offset; |
| 4798 | s32 ie_len; |
Hante Meuleman | 18e2f61 | 2013-02-08 15:53:49 +0100 | [diff] [blame] | 4799 | struct brcmf_fil_action_frame_le *action_frame; |
| 4800 | struct brcmf_fil_af_params_le *af_params; |
| 4801 | bool ack; |
| 4802 | s32 chan_nr; |
Antonio Quartulli | c2ff8ca | 2013-06-11 14:20:01 +0200 | [diff] [blame] | 4803 | u32 freq; |
Hante Meuleman | 0de8aac | 2013-02-08 15:53:38 +0100 | [diff] [blame] | 4804 | |
| 4805 | brcmf_dbg(TRACE, "Enter\n"); |
| 4806 | |
| 4807 | *cookie = 0; |
| 4808 | |
| 4809 | mgmt = (const struct ieee80211_mgmt *)buf; |
| 4810 | |
Hante Meuleman | a0f0795 | 2013-02-08 15:53:47 +0100 | [diff] [blame] | 4811 | if (!ieee80211_is_mgmt(mgmt->frame_control)) { |
| 4812 | brcmf_err("Driver only allows MGMT packet type\n"); |
| 4813 | return -EPERM; |
Hante Meuleman | 0de8aac | 2013-02-08 15:53:38 +0100 | [diff] [blame] | 4814 | } |
Hante Meuleman | a0f0795 | 2013-02-08 15:53:47 +0100 | [diff] [blame] | 4815 | |
Antonio Quartulli | c2ff8ca | 2013-06-11 14:20:01 +0200 | [diff] [blame] | 4816 | vif = container_of(wdev, struct brcmf_cfg80211_vif, wdev); |
| 4817 | |
Hante Meuleman | a0f0795 | 2013-02-08 15:53:47 +0100 | [diff] [blame] | 4818 | if (ieee80211_is_probe_resp(mgmt->frame_control)) { |
| 4819 | /* Right now the only reason to get a probe response */ |
| 4820 | /* is for p2p listen response or for p2p GO from */ |
| 4821 | /* wpa_supplicant. Unfortunately the probe is send */ |
| 4822 | /* on primary ndev, while dongle wants it on the p2p */ |
| 4823 | /* vif. Since this is only reason for a probe */ |
| 4824 | /* response to be sent, the vif is taken from cfg. */ |
| 4825 | /* If ever desired to send proberesp for non p2p */ |
| 4826 | /* response then data should be checked for */ |
| 4827 | /* "DIRECT-". Note in future supplicant will take */ |
| 4828 | /* dedicated p2p wdev to do this and then this 'hack'*/ |
| 4829 | /* is not needed anymore. */ |
| 4830 | ie_offset = DOT11_MGMT_HDR_LEN + |
| 4831 | DOT11_BCN_PRB_FIXED_LEN; |
| 4832 | ie_len = len - ie_offset; |
Hante Meuleman | a0f0795 | 2013-02-08 15:53:47 +0100 | [diff] [blame] | 4833 | if (vif == cfg->p2p.bss_idx[P2PAPI_BSSCFG_PRIMARY].vif) |
| 4834 | vif = cfg->p2p.bss_idx[P2PAPI_BSSCFG_DEVICE].vif; |
| 4835 | err = brcmf_vif_set_mgmt_ie(vif, |
| 4836 | BRCMF_VNDR_IE_PRBRSP_FLAG, |
| 4837 | &buf[ie_offset], |
| 4838 | ie_len); |
| 4839 | cfg80211_mgmt_tx_status(wdev, *cookie, buf, len, true, |
| 4840 | GFP_KERNEL); |
Hante Meuleman | 18e2f61 | 2013-02-08 15:53:49 +0100 | [diff] [blame] | 4841 | } else if (ieee80211_is_action(mgmt->frame_control)) { |
| 4842 | af_params = kzalloc(sizeof(*af_params), GFP_KERNEL); |
| 4843 | if (af_params == NULL) { |
| 4844 | brcmf_err("unable to allocate frame\n"); |
| 4845 | err = -ENOMEM; |
| 4846 | goto exit; |
| 4847 | } |
| 4848 | action_frame = &af_params->action_frame; |
| 4849 | /* Add the packet Id */ |
| 4850 | action_frame->packet_id = cpu_to_le32(*cookie); |
| 4851 | /* Add BSSID */ |
| 4852 | memcpy(&action_frame->da[0], &mgmt->da[0], ETH_ALEN); |
| 4853 | memcpy(&af_params->bssid[0], &mgmt->bssid[0], ETH_ALEN); |
| 4854 | /* Add the length exepted for 802.11 header */ |
| 4855 | action_frame->len = cpu_to_le16(len - DOT11_MGMT_HDR_LEN); |
Antonio Quartulli | c2ff8ca | 2013-06-11 14:20:01 +0200 | [diff] [blame] | 4856 | /* Add the channel. Use the one specified as parameter if any or |
| 4857 | * the current one (got from the firmware) otherwise |
| 4858 | */ |
| 4859 | if (chan) |
| 4860 | freq = chan->center_freq; |
| 4861 | else |
| 4862 | brcmf_fil_cmd_int_get(vif->ifp, BRCMF_C_GET_CHANNEL, |
| 4863 | &freq); |
| 4864 | chan_nr = ieee80211_frequency_to_channel(freq); |
Hante Meuleman | 18e2f61 | 2013-02-08 15:53:49 +0100 | [diff] [blame] | 4865 | af_params->channel = cpu_to_le32(chan_nr); |
| 4866 | |
| 4867 | memcpy(action_frame->data, &buf[DOT11_MGMT_HDR_LEN], |
| 4868 | le16_to_cpu(action_frame->len)); |
| 4869 | |
| 4870 | brcmf_dbg(TRACE, "Action frame, cookie=%lld, len=%d, freq=%d\n", |
Antonio Quartulli | 86a9c4a | 2013-06-19 13:35:31 +0200 | [diff] [blame] | 4871 | *cookie, le16_to_cpu(action_frame->len), freq); |
Hante Meuleman | 18e2f61 | 2013-02-08 15:53:49 +0100 | [diff] [blame] | 4872 | |
Arend van Spriel | 7fa2e35 | 2013-04-05 10:57:47 +0200 | [diff] [blame] | 4873 | ack = brcmf_p2p_send_action_frame(cfg, cfg_to_ndev(cfg), |
Hante Meuleman | 18e2f61 | 2013-02-08 15:53:49 +0100 | [diff] [blame] | 4874 | af_params); |
| 4875 | |
| 4876 | cfg80211_mgmt_tx_status(wdev, *cookie, buf, len, ack, |
| 4877 | GFP_KERNEL); |
| 4878 | kfree(af_params); |
Hante Meuleman | a0f0795 | 2013-02-08 15:53:47 +0100 | [diff] [blame] | 4879 | } else { |
| 4880 | brcmf_dbg(TRACE, "Unhandled, fc=%04x!!\n", mgmt->frame_control); |
| 4881 | brcmf_dbg_hex_dump(true, buf, len, "payload, len=%Zu\n", len); |
| 4882 | } |
| 4883 | |
Hante Meuleman | 18e2f61 | 2013-02-08 15:53:49 +0100 | [diff] [blame] | 4884 | exit: |
Hante Meuleman | 0de8aac | 2013-02-08 15:53:38 +0100 | [diff] [blame] | 4885 | return err; |
| 4886 | } |
| 4887 | |
| 4888 | |
| 4889 | static int |
| 4890 | brcmf_cfg80211_cancel_remain_on_channel(struct wiphy *wiphy, |
| 4891 | struct wireless_dev *wdev, |
| 4892 | u64 cookie) |
| 4893 | { |
| 4894 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); |
| 4895 | struct brcmf_cfg80211_vif *vif; |
| 4896 | int err = 0; |
| 4897 | |
| 4898 | brcmf_dbg(TRACE, "Enter p2p listen cancel\n"); |
| 4899 | |
| 4900 | vif = cfg->p2p.bss_idx[P2PAPI_BSSCFG_DEVICE].vif; |
| 4901 | if (vif == NULL) { |
| 4902 | brcmf_err("No p2p device available for probe response\n"); |
| 4903 | err = -ENODEV; |
| 4904 | goto exit; |
| 4905 | } |
| 4906 | brcmf_p2p_cancel_remain_on_channel(vif->ifp); |
| 4907 | exit: |
| 4908 | return err; |
| 4909 | } |
| 4910 | |
Rafał Miłecki | ee6e7aa | 2016-05-20 13:38:58 +0200 | [diff] [blame] | 4911 | static int brcmf_cfg80211_get_channel(struct wiphy *wiphy, |
| 4912 | struct wireless_dev *wdev, |
| 4913 | struct cfg80211_chan_def *chandef) |
| 4914 | { |
| 4915 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); |
| 4916 | struct net_device *ndev = wdev->netdev; |
| 4917 | struct brcmf_if *ifp; |
| 4918 | struct brcmu_chan ch; |
| 4919 | enum nl80211_band band = 0; |
| 4920 | enum nl80211_chan_width width = 0; |
| 4921 | u32 chanspec; |
| 4922 | int freq, err; |
| 4923 | |
| 4924 | if (!ndev) |
| 4925 | return -ENODEV; |
| 4926 | ifp = netdev_priv(ndev); |
| 4927 | |
| 4928 | err = brcmf_fil_iovar_int_get(ifp, "chanspec", &chanspec); |
| 4929 | if (err) { |
| 4930 | brcmf_err("chanspec failed (%d)\n", err); |
| 4931 | return err; |
| 4932 | } |
| 4933 | |
| 4934 | ch.chspec = chanspec; |
| 4935 | cfg->d11inf.decchspec(&ch); |
| 4936 | |
| 4937 | switch (ch.band) { |
| 4938 | case BRCMU_CHAN_BAND_2G: |
| 4939 | band = NL80211_BAND_2GHZ; |
| 4940 | break; |
| 4941 | case BRCMU_CHAN_BAND_5G: |
| 4942 | band = NL80211_BAND_5GHZ; |
| 4943 | break; |
| 4944 | } |
| 4945 | |
| 4946 | switch (ch.bw) { |
| 4947 | case BRCMU_CHAN_BW_80: |
| 4948 | width = NL80211_CHAN_WIDTH_80; |
| 4949 | break; |
| 4950 | case BRCMU_CHAN_BW_40: |
| 4951 | width = NL80211_CHAN_WIDTH_40; |
| 4952 | break; |
| 4953 | case BRCMU_CHAN_BW_20: |
| 4954 | width = NL80211_CHAN_WIDTH_20; |
| 4955 | break; |
| 4956 | case BRCMU_CHAN_BW_80P80: |
| 4957 | width = NL80211_CHAN_WIDTH_80P80; |
| 4958 | break; |
| 4959 | case BRCMU_CHAN_BW_160: |
| 4960 | width = NL80211_CHAN_WIDTH_160; |
| 4961 | break; |
| 4962 | } |
| 4963 | |
| 4964 | freq = ieee80211_channel_to_frequency(ch.control_ch_num, band); |
| 4965 | chandef->chan = ieee80211_get_channel(wiphy, freq); |
| 4966 | chandef->width = width; |
| 4967 | chandef->center_freq1 = ieee80211_channel_to_frequency(ch.chnum, band); |
| 4968 | chandef->center_freq2 = 0; |
| 4969 | |
| 4970 | return 0; |
| 4971 | } |
| 4972 | |
Piotr Haber | 61730d4 | 2013-04-23 12:53:12 +0200 | [diff] [blame] | 4973 | static int brcmf_cfg80211_crit_proto_start(struct wiphy *wiphy, |
| 4974 | struct wireless_dev *wdev, |
| 4975 | enum nl80211_crit_proto_id proto, |
| 4976 | u16 duration) |
| 4977 | { |
| 4978 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); |
| 4979 | struct brcmf_cfg80211_vif *vif; |
| 4980 | |
| 4981 | vif = container_of(wdev, struct brcmf_cfg80211_vif, wdev); |
| 4982 | |
| 4983 | /* only DHCP support for now */ |
| 4984 | if (proto != NL80211_CRIT_PROTO_DHCP) |
| 4985 | return -EINVAL; |
| 4986 | |
| 4987 | /* suppress and abort scanning */ |
| 4988 | set_bit(BRCMF_SCAN_STATUS_SUPPRESS, &cfg->scan_status); |
| 4989 | brcmf_abort_scanning(cfg); |
| 4990 | |
| 4991 | return brcmf_btcoex_set_mode(vif, BRCMF_BTCOEX_DISABLED, duration); |
| 4992 | } |
| 4993 | |
| 4994 | static void brcmf_cfg80211_crit_proto_stop(struct wiphy *wiphy, |
| 4995 | struct wireless_dev *wdev) |
| 4996 | { |
| 4997 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); |
| 4998 | struct brcmf_cfg80211_vif *vif; |
| 4999 | |
| 5000 | vif = container_of(wdev, struct brcmf_cfg80211_vif, wdev); |
| 5001 | |
| 5002 | brcmf_btcoex_set_mode(vif, BRCMF_BTCOEX_ENABLED, 0); |
| 5003 | clear_bit(BRCMF_SCAN_STATUS_SUPPRESS, &cfg->scan_status); |
| 5004 | } |
| 5005 | |
Hante Meuleman | 70b7d94 | 2014-07-30 13:20:07 +0200 | [diff] [blame] | 5006 | static s32 |
| 5007 | brcmf_notify_tdls_peer_event(struct brcmf_if *ifp, |
| 5008 | const struct brcmf_event_msg *e, void *data) |
| 5009 | { |
| 5010 | switch (e->reason) { |
| 5011 | case BRCMF_E_REASON_TDLS_PEER_DISCOVERED: |
| 5012 | brcmf_dbg(TRACE, "TDLS Peer Discovered\n"); |
| 5013 | break; |
| 5014 | case BRCMF_E_REASON_TDLS_PEER_CONNECTED: |
| 5015 | brcmf_dbg(TRACE, "TDLS Peer Connected\n"); |
| 5016 | brcmf_proto_add_tdls_peer(ifp->drvr, ifp->ifidx, (u8 *)e->addr); |
| 5017 | break; |
| 5018 | case BRCMF_E_REASON_TDLS_PEER_DISCONNECTED: |
| 5019 | brcmf_dbg(TRACE, "TDLS Peer Disconnected\n"); |
| 5020 | brcmf_proto_delete_peer(ifp->drvr, ifp->ifidx, (u8 *)e->addr); |
| 5021 | break; |
| 5022 | } |
| 5023 | |
| 5024 | return 0; |
| 5025 | } |
| 5026 | |
Arend van Spriel | 89c2f38 | 2013-08-10 12:27:25 +0200 | [diff] [blame] | 5027 | static int brcmf_convert_nl80211_tdls_oper(enum nl80211_tdls_operation oper) |
| 5028 | { |
| 5029 | int ret; |
| 5030 | |
| 5031 | switch (oper) { |
| 5032 | case NL80211_TDLS_DISCOVERY_REQ: |
| 5033 | ret = BRCMF_TDLS_MANUAL_EP_DISCOVERY; |
| 5034 | break; |
| 5035 | case NL80211_TDLS_SETUP: |
| 5036 | ret = BRCMF_TDLS_MANUAL_EP_CREATE; |
| 5037 | break; |
| 5038 | case NL80211_TDLS_TEARDOWN: |
| 5039 | ret = BRCMF_TDLS_MANUAL_EP_DELETE; |
| 5040 | break; |
| 5041 | default: |
| 5042 | brcmf_err("unsupported operation: %d\n", oper); |
| 5043 | ret = -EOPNOTSUPP; |
| 5044 | } |
| 5045 | return ret; |
| 5046 | } |
| 5047 | |
| 5048 | static int brcmf_cfg80211_tdls_oper(struct wiphy *wiphy, |
Johannes Berg | 3b3a016 | 2014-05-19 17:19:31 +0200 | [diff] [blame] | 5049 | struct net_device *ndev, const u8 *peer, |
Arend van Spriel | 89c2f38 | 2013-08-10 12:27:25 +0200 | [diff] [blame] | 5050 | enum nl80211_tdls_operation oper) |
| 5051 | { |
| 5052 | struct brcmf_if *ifp; |
| 5053 | struct brcmf_tdls_iovar_le info; |
| 5054 | int ret = 0; |
| 5055 | |
| 5056 | ret = brcmf_convert_nl80211_tdls_oper(oper); |
| 5057 | if (ret < 0) |
| 5058 | return ret; |
| 5059 | |
| 5060 | ifp = netdev_priv(ndev); |
| 5061 | memset(&info, 0, sizeof(info)); |
| 5062 | info.mode = (u8)ret; |
| 5063 | if (peer) |
| 5064 | memcpy(info.ea, peer, ETH_ALEN); |
| 5065 | |
| 5066 | ret = brcmf_fil_iovar_data_set(ifp, "tdls_endpoint", |
| 5067 | &info, sizeof(info)); |
| 5068 | if (ret < 0) |
| 5069 | brcmf_err("tdls_endpoint iovar failed: ret=%d\n", ret); |
| 5070 | |
| 5071 | return ret; |
| 5072 | } |
| 5073 | |
Hante Meuleman | 5c22fb8 | 2016-02-17 11:27:03 +0100 | [diff] [blame] | 5074 | #ifdef CONFIG_PM |
| 5075 | static int |
| 5076 | brcmf_cfg80211_set_rekey_data(struct wiphy *wiphy, struct net_device *ndev, |
| 5077 | struct cfg80211_gtk_rekey_data *gtk) |
| 5078 | { |
| 5079 | struct brcmf_if *ifp = netdev_priv(ndev); |
| 5080 | struct brcmf_gtk_keyinfo_le gtk_le; |
| 5081 | int ret; |
| 5082 | |
| 5083 | brcmf_dbg(TRACE, "Enter, bssidx=%d\n", ifp->bsscfgidx); |
| 5084 | |
| 5085 | memcpy(gtk_le.kck, gtk->kck, sizeof(gtk_le.kck)); |
| 5086 | memcpy(gtk_le.kek, gtk->kek, sizeof(gtk_le.kek)); |
| 5087 | memcpy(gtk_le.replay_counter, gtk->replay_ctr, |
| 5088 | sizeof(gtk_le.replay_counter)); |
| 5089 | |
| 5090 | ret = brcmf_fil_iovar_data_set(ifp, "gtk_key_info", >k_le, |
| 5091 | sizeof(gtk_le)); |
| 5092 | if (ret < 0) |
| 5093 | brcmf_err("gtk_key_info iovar failed: ret=%d\n", ret); |
| 5094 | |
| 5095 | return ret; |
| 5096 | } |
| 5097 | #endif |
| 5098 | |
| 5099 | static struct cfg80211_ops brcmf_cfg80211_ops = { |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 5100 | .add_virtual_intf = brcmf_cfg80211_add_iface, |
| 5101 | .del_virtual_intf = brcmf_cfg80211_del_iface, |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5102 | .change_virtual_intf = brcmf_cfg80211_change_iface, |
| 5103 | .scan = brcmf_cfg80211_scan, |
| 5104 | .set_wiphy_params = brcmf_cfg80211_set_wiphy_params, |
| 5105 | .join_ibss = brcmf_cfg80211_join_ibss, |
| 5106 | .leave_ibss = brcmf_cfg80211_leave_ibss, |
| 5107 | .get_station = brcmf_cfg80211_get_station, |
Hante Meuleman | bf2a7e0 | 2015-10-08 20:33:18 +0200 | [diff] [blame] | 5108 | .dump_station = brcmf_cfg80211_dump_station, |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5109 | .set_tx_power = brcmf_cfg80211_set_tx_power, |
| 5110 | .get_tx_power = brcmf_cfg80211_get_tx_power, |
| 5111 | .add_key = brcmf_cfg80211_add_key, |
| 5112 | .del_key = brcmf_cfg80211_del_key, |
| 5113 | .get_key = brcmf_cfg80211_get_key, |
| 5114 | .set_default_key = brcmf_cfg80211_config_default_key, |
| 5115 | .set_default_mgmt_key = brcmf_cfg80211_config_default_mgmt_key, |
| 5116 | .set_power_mgmt = brcmf_cfg80211_set_power_mgmt, |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5117 | .connect = brcmf_cfg80211_connect, |
| 5118 | .disconnect = brcmf_cfg80211_disconnect, |
| 5119 | .suspend = brcmf_cfg80211_suspend, |
| 5120 | .resume = brcmf_cfg80211_resume, |
| 5121 | .set_pmksa = brcmf_cfg80211_set_pmksa, |
| 5122 | .del_pmksa = brcmf_cfg80211_del_pmksa, |
Arend van Spriel | cbaa177 | 2012-08-30 19:43:02 +0200 | [diff] [blame] | 5123 | .flush_pmksa = brcmf_cfg80211_flush_pmksa, |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 5124 | .start_ap = brcmf_cfg80211_start_ap, |
| 5125 | .stop_ap = brcmf_cfg80211_stop_ap, |
Hante Meuleman | a0f0795 | 2013-02-08 15:53:47 +0100 | [diff] [blame] | 5126 | .change_beacon = brcmf_cfg80211_change_beacon, |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 5127 | .del_station = brcmf_cfg80211_del_station, |
Hante Meuleman | 6b89dcb | 2014-12-21 12:43:52 +0100 | [diff] [blame] | 5128 | .change_station = brcmf_cfg80211_change_station, |
Arend van Spriel | e580607 | 2012-09-19 22:21:08 +0200 | [diff] [blame] | 5129 | .sched_scan_start = brcmf_cfg80211_sched_scan_start, |
| 5130 | .sched_scan_stop = brcmf_cfg80211_sched_scan_stop, |
Hante Meuleman | 0de8aac | 2013-02-08 15:53:38 +0100 | [diff] [blame] | 5131 | .mgmt_frame_register = brcmf_cfg80211_mgmt_frame_register, |
| 5132 | .mgmt_tx = brcmf_cfg80211_mgmt_tx, |
| 5133 | .remain_on_channel = brcmf_p2p_remain_on_channel, |
| 5134 | .cancel_remain_on_channel = brcmf_cfg80211_cancel_remain_on_channel, |
Rafał Miłecki | ee6e7aa | 2016-05-20 13:38:58 +0200 | [diff] [blame] | 5135 | .get_channel = brcmf_cfg80211_get_channel, |
Arend van Spriel | 27f10e3 | 2013-04-05 10:57:50 +0200 | [diff] [blame] | 5136 | .start_p2p_device = brcmf_p2p_start_device, |
| 5137 | .stop_p2p_device = brcmf_p2p_stop_device, |
Piotr Haber | 61730d4 | 2013-04-23 12:53:12 +0200 | [diff] [blame] | 5138 | .crit_proto_start = brcmf_cfg80211_crit_proto_start, |
| 5139 | .crit_proto_stop = brcmf_cfg80211_crit_proto_stop, |
Arend van Spriel | 89c2f38 | 2013-08-10 12:27:25 +0200 | [diff] [blame] | 5140 | .tdls_oper = brcmf_cfg80211_tdls_oper, |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5141 | }; |
| 5142 | |
Arend van Spriel | 3eacf86 | 2012-10-22 13:55:30 -0700 | [diff] [blame] | 5143 | struct brcmf_cfg80211_vif *brcmf_alloc_vif(struct brcmf_cfg80211_info *cfg, |
Rafał Miłecki | 2607233 | 2016-06-06 23:03:55 +0200 | [diff] [blame] | 5144 | enum nl80211_iftype type) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5145 | { |
Hante Meuleman | a44aa40 | 2014-12-03 21:05:33 +0100 | [diff] [blame] | 5146 | struct brcmf_cfg80211_vif *vif_walk; |
Arend van Spriel | 3eacf86 | 2012-10-22 13:55:30 -0700 | [diff] [blame] | 5147 | struct brcmf_cfg80211_vif *vif; |
Hante Meuleman | a44aa40 | 2014-12-03 21:05:33 +0100 | [diff] [blame] | 5148 | bool mbss; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5149 | |
Arend van Spriel | 33a6b15 | 2013-02-08 15:53:39 +0100 | [diff] [blame] | 5150 | brcmf_dbg(TRACE, "allocating virtual interface (size=%zu)\n", |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 5151 | sizeof(*vif)); |
Arend van Spriel | 3eacf86 | 2012-10-22 13:55:30 -0700 | [diff] [blame] | 5152 | vif = kzalloc(sizeof(*vif), GFP_KERNEL); |
| 5153 | if (!vif) |
| 5154 | return ERR_PTR(-ENOMEM); |
| 5155 | |
| 5156 | vif->wdev.wiphy = cfg->wiphy; |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 5157 | vif->wdev.iftype = type; |
Arend van Spriel | 3eacf86 | 2012-10-22 13:55:30 -0700 | [diff] [blame] | 5158 | |
Arend van Spriel | 6ac4f4e | 2012-10-22 13:55:31 -0700 | [diff] [blame] | 5159 | brcmf_init_prof(&vif->profile); |
| 5160 | |
Hante Meuleman | a44aa40 | 2014-12-03 21:05:33 +0100 | [diff] [blame] | 5161 | if (type == NL80211_IFTYPE_AP) { |
| 5162 | mbss = false; |
| 5163 | list_for_each_entry(vif_walk, &cfg->vif_list, list) { |
| 5164 | if (vif_walk->wdev.iftype == NL80211_IFTYPE_AP) { |
| 5165 | mbss = true; |
| 5166 | break; |
| 5167 | } |
| 5168 | } |
| 5169 | vif->mbss = mbss; |
| 5170 | } |
| 5171 | |
Arend van Spriel | 3eacf86 | 2012-10-22 13:55:30 -0700 | [diff] [blame] | 5172 | list_add_tail(&vif->list, &cfg->vif_list); |
Arend van Spriel | 3eacf86 | 2012-10-22 13:55:30 -0700 | [diff] [blame] | 5173 | return vif; |
| 5174 | } |
| 5175 | |
Arend van Spriel | 427dec5 | 2014-01-06 12:40:47 +0100 | [diff] [blame] | 5176 | void brcmf_free_vif(struct brcmf_cfg80211_vif *vif) |
Arend van Spriel | 3eacf86 | 2012-10-22 13:55:30 -0700 | [diff] [blame] | 5177 | { |
Arend van Spriel | 3eacf86 | 2012-10-22 13:55:30 -0700 | [diff] [blame] | 5178 | list_del(&vif->list); |
Arend van Spriel | 3eacf86 | 2012-10-22 13:55:30 -0700 | [diff] [blame] | 5179 | kfree(vif); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5180 | } |
| 5181 | |
Arend van Spriel | 9df4d54 | 2014-01-06 12:40:49 +0100 | [diff] [blame] | 5182 | void brcmf_cfg80211_free_netdev(struct net_device *ndev) |
| 5183 | { |
| 5184 | struct brcmf_cfg80211_vif *vif; |
| 5185 | struct brcmf_if *ifp; |
| 5186 | |
| 5187 | ifp = netdev_priv(ndev); |
| 5188 | vif = ifp->vif; |
| 5189 | |
Arend van Spriel | 95ef123 | 2015-08-26 22:15:04 +0200 | [diff] [blame] | 5190 | if (vif) |
| 5191 | brcmf_free_vif(vif); |
Arend van Spriel | 9df4d54 | 2014-01-06 12:40:49 +0100 | [diff] [blame] | 5192 | free_netdev(ndev); |
| 5193 | } |
| 5194 | |
Arend van Spriel | 903e0ee | 2012-11-28 21:44:11 +0100 | [diff] [blame] | 5195 | static bool brcmf_is_linkup(const struct brcmf_event_msg *e) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5196 | { |
Arend van Spriel | 5c36b99 | 2012-11-14 18:46:05 -0800 | [diff] [blame] | 5197 | u32 event = e->event_code; |
| 5198 | u32 status = e->status; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5199 | |
| 5200 | if (event == BRCMF_E_SET_SSID && status == BRCMF_E_STATUS_SUCCESS) { |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 5201 | brcmf_dbg(CONN, "Processing set ssid\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5202 | return true; |
| 5203 | } |
| 5204 | |
| 5205 | return false; |
| 5206 | } |
| 5207 | |
Arend van Spriel | 903e0ee | 2012-11-28 21:44:11 +0100 | [diff] [blame] | 5208 | static bool brcmf_is_linkdown(const struct brcmf_event_msg *e) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5209 | { |
Arend van Spriel | 5c36b99 | 2012-11-14 18:46:05 -0800 | [diff] [blame] | 5210 | u32 event = e->event_code; |
| 5211 | u16 flags = e->flags; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5212 | |
Hante Meuleman | 68ca395 | 2014-02-25 20:30:26 +0100 | [diff] [blame] | 5213 | if ((event == BRCMF_E_DEAUTH) || (event == BRCMF_E_DEAUTH_IND) || |
| 5214 | (event == BRCMF_E_DISASSOC_IND) || |
| 5215 | ((event == BRCMF_E_LINK) && (!(flags & BRCMF_EVENT_MSG_LINK)))) { |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 5216 | brcmf_dbg(CONN, "Processing link down\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5217 | return true; |
| 5218 | } |
| 5219 | return false; |
| 5220 | } |
| 5221 | |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5222 | static bool brcmf_is_nonetwork(struct brcmf_cfg80211_info *cfg, |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5223 | const struct brcmf_event_msg *e) |
| 5224 | { |
Arend van Spriel | 5c36b99 | 2012-11-14 18:46:05 -0800 | [diff] [blame] | 5225 | u32 event = e->event_code; |
| 5226 | u32 status = e->status; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5227 | |
| 5228 | if (event == BRCMF_E_LINK && status == BRCMF_E_STATUS_NO_NETWORKS) { |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 5229 | brcmf_dbg(CONN, "Processing Link %s & no network found\n", |
| 5230 | e->flags & BRCMF_EVENT_MSG_LINK ? "up" : "down"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5231 | return true; |
| 5232 | } |
| 5233 | |
| 5234 | if (event == BRCMF_E_SET_SSID && status != BRCMF_E_STATUS_SUCCESS) { |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 5235 | brcmf_dbg(CONN, "Processing connecting & no network found\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5236 | return true; |
| 5237 | } |
| 5238 | |
| 5239 | return false; |
| 5240 | } |
| 5241 | |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5242 | static void brcmf_clear_assoc_ies(struct brcmf_cfg80211_info *cfg) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5243 | { |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5244 | struct brcmf_cfg80211_connect_info *conn_info = cfg_to_conn(cfg); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5245 | |
| 5246 | kfree(conn_info->req_ie); |
| 5247 | conn_info->req_ie = NULL; |
| 5248 | conn_info->req_ie_len = 0; |
| 5249 | kfree(conn_info->resp_ie); |
| 5250 | conn_info->resp_ie = NULL; |
| 5251 | conn_info->resp_ie_len = 0; |
| 5252 | } |
| 5253 | |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 5254 | static s32 brcmf_get_assoc_ies(struct brcmf_cfg80211_info *cfg, |
| 5255 | struct brcmf_if *ifp) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5256 | { |
Arend van Spriel | c4e382d | 2011-10-12 20:51:21 +0200 | [diff] [blame] | 5257 | struct brcmf_cfg80211_assoc_ielen_le *assoc_info; |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5258 | struct brcmf_cfg80211_connect_info *conn_info = cfg_to_conn(cfg); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5259 | u32 req_len; |
| 5260 | u32 resp_len; |
| 5261 | s32 err = 0; |
| 5262 | |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5263 | brcmf_clear_assoc_ies(cfg); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5264 | |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 5265 | err = brcmf_fil_iovar_data_get(ifp, "assoc_info", |
| 5266 | cfg->extra_buf, WL_ASSOC_INFO_MAX); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5267 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 5268 | brcmf_err("could not get assoc info (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5269 | return err; |
| 5270 | } |
Arend van Spriel | c4e382d | 2011-10-12 20:51:21 +0200 | [diff] [blame] | 5271 | assoc_info = |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5272 | (struct brcmf_cfg80211_assoc_ielen_le *)cfg->extra_buf; |
Arend van Spriel | c4e382d | 2011-10-12 20:51:21 +0200 | [diff] [blame] | 5273 | req_len = le32_to_cpu(assoc_info->req_len); |
| 5274 | resp_len = le32_to_cpu(assoc_info->resp_len); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5275 | if (req_len) { |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 5276 | err = brcmf_fil_iovar_data_get(ifp, "assoc_req_ies", |
Hante Meuleman | 81f5dcb | 2012-10-22 10:36:14 -0700 | [diff] [blame] | 5277 | cfg->extra_buf, |
| 5278 | WL_ASSOC_INFO_MAX); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5279 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 5280 | brcmf_err("could not get assoc req (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5281 | return err; |
| 5282 | } |
| 5283 | conn_info->req_ie_len = req_len; |
| 5284 | conn_info->req_ie = |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5285 | kmemdup(cfg->extra_buf, conn_info->req_ie_len, |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5286 | GFP_KERNEL); |
| 5287 | } else { |
| 5288 | conn_info->req_ie_len = 0; |
| 5289 | conn_info->req_ie = NULL; |
| 5290 | } |
| 5291 | if (resp_len) { |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 5292 | err = brcmf_fil_iovar_data_get(ifp, "assoc_resp_ies", |
Hante Meuleman | 81f5dcb | 2012-10-22 10:36:14 -0700 | [diff] [blame] | 5293 | cfg->extra_buf, |
| 5294 | WL_ASSOC_INFO_MAX); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5295 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 5296 | brcmf_err("could not get assoc resp (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5297 | return err; |
| 5298 | } |
| 5299 | conn_info->resp_ie_len = resp_len; |
| 5300 | conn_info->resp_ie = |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5301 | kmemdup(cfg->extra_buf, conn_info->resp_ie_len, |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5302 | GFP_KERNEL); |
| 5303 | } else { |
| 5304 | conn_info->resp_ie_len = 0; |
| 5305 | conn_info->resp_ie = NULL; |
| 5306 | } |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 5307 | brcmf_dbg(CONN, "req len (%d) resp len (%d)\n", |
| 5308 | conn_info->req_ie_len, conn_info->resp_ie_len); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5309 | |
| 5310 | return err; |
| 5311 | } |
| 5312 | |
| 5313 | static s32 |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5314 | brcmf_bss_roaming_done(struct brcmf_cfg80211_info *cfg, |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5315 | struct net_device *ndev, |
| 5316 | const struct brcmf_event_msg *e) |
| 5317 | { |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 5318 | struct brcmf_if *ifp = netdev_priv(ndev); |
| 5319 | struct brcmf_cfg80211_profile *profile = &ifp->vif->profile; |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5320 | struct brcmf_cfg80211_connect_info *conn_info = cfg_to_conn(cfg); |
| 5321 | struct wiphy *wiphy = cfg_to_wiphy(cfg); |
Franky Lin | a180b83 | 2012-10-10 11:13:09 -0700 | [diff] [blame] | 5322 | struct ieee80211_channel *notify_channel = NULL; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5323 | struct ieee80211_supported_band *band; |
Franky Lin | a180b83 | 2012-10-10 11:13:09 -0700 | [diff] [blame] | 5324 | struct brcmf_bss_info_le *bi; |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 5325 | struct brcmu_chan ch; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5326 | u32 freq; |
| 5327 | s32 err = 0; |
Franky Lin | a180b83 | 2012-10-10 11:13:09 -0700 | [diff] [blame] | 5328 | u8 *buf; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5329 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 5330 | brcmf_dbg(TRACE, "Enter\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5331 | |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 5332 | brcmf_get_assoc_ies(cfg, ifp); |
Arend van Spriel | 6c8c4f7 | 2012-09-27 14:17:57 +0200 | [diff] [blame] | 5333 | memcpy(profile->bssid, e->addr, ETH_ALEN); |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 5334 | brcmf_update_bss_info(cfg, ifp); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5335 | |
Franky Lin | a180b83 | 2012-10-10 11:13:09 -0700 | [diff] [blame] | 5336 | buf = kzalloc(WL_BSS_INFO_MAX, GFP_KERNEL); |
| 5337 | if (buf == NULL) { |
| 5338 | err = -ENOMEM; |
| 5339 | goto done; |
| 5340 | } |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5341 | |
Franky Lin | a180b83 | 2012-10-10 11:13:09 -0700 | [diff] [blame] | 5342 | /* data sent to dongle has to be little endian */ |
| 5343 | *(__le32 *)buf = cpu_to_le32(WL_BSS_INFO_MAX); |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 5344 | err = brcmf_fil_cmd_data_get(ifp, BRCMF_C_GET_BSS_INFO, |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 5345 | buf, WL_BSS_INFO_MAX); |
Franky Lin | a180b83 | 2012-10-10 11:13:09 -0700 | [diff] [blame] | 5346 | |
| 5347 | if (err) |
| 5348 | goto done; |
| 5349 | |
| 5350 | bi = (struct brcmf_bss_info_le *)(buf + 4); |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 5351 | ch.chspec = le16_to_cpu(bi->chanspec); |
| 5352 | cfg->d11inf.decchspec(&ch); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5353 | |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 5354 | if (ch.band == BRCMU_CHAN_BAND_2G) |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 5355 | band = wiphy->bands[NL80211_BAND_2GHZ]; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5356 | else |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 5357 | band = wiphy->bands[NL80211_BAND_5GHZ]; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5358 | |
Rafał Miłecki | 4712d88 | 2016-05-20 13:38:57 +0200 | [diff] [blame] | 5359 | freq = ieee80211_channel_to_frequency(ch.control_ch_num, band->band); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5360 | notify_channel = ieee80211_get_channel(wiphy, freq); |
| 5361 | |
Franky Lin | a180b83 | 2012-10-10 11:13:09 -0700 | [diff] [blame] | 5362 | done: |
| 5363 | kfree(buf); |
Arend van Spriel | 06bb123 | 2012-09-27 14:17:56 +0200 | [diff] [blame] | 5364 | cfg80211_roamed(ndev, notify_channel, (u8 *)profile->bssid, |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5365 | conn_info->req_ie, conn_info->req_ie_len, |
| 5366 | conn_info->resp_ie, conn_info->resp_ie_len, GFP_KERNEL); |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 5367 | brcmf_dbg(CONN, "Report roaming result\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5368 | |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 5369 | set_bit(BRCMF_VIF_STATUS_CONNECTED, &ifp->vif->sme_state); |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 5370 | brcmf_dbg(TRACE, "Exit\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5371 | return err; |
| 5372 | } |
| 5373 | |
| 5374 | static s32 |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5375 | brcmf_bss_connect_done(struct brcmf_cfg80211_info *cfg, |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5376 | struct net_device *ndev, const struct brcmf_event_msg *e, |
| 5377 | bool completed) |
| 5378 | { |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 5379 | struct brcmf_if *ifp = netdev_priv(ndev); |
| 5380 | struct brcmf_cfg80211_profile *profile = &ifp->vif->profile; |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5381 | struct brcmf_cfg80211_connect_info *conn_info = cfg_to_conn(cfg); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5382 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 5383 | brcmf_dbg(TRACE, "Enter\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5384 | |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 5385 | if (test_and_clear_bit(BRCMF_VIF_STATUS_CONNECTING, |
| 5386 | &ifp->vif->sme_state)) { |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5387 | if (completed) { |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 5388 | brcmf_get_assoc_ies(cfg, ifp); |
Arend van Spriel | 6c8c4f7 | 2012-09-27 14:17:57 +0200 | [diff] [blame] | 5389 | memcpy(profile->bssid, e->addr, ETH_ALEN); |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 5390 | brcmf_update_bss_info(cfg, ifp); |
| 5391 | set_bit(BRCMF_VIF_STATUS_CONNECTED, |
| 5392 | &ifp->vif->sme_state); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5393 | } |
| 5394 | cfg80211_connect_result(ndev, |
Arend van Spriel | 06bb123 | 2012-09-27 14:17:56 +0200 | [diff] [blame] | 5395 | (u8 *)profile->bssid, |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5396 | conn_info->req_ie, |
| 5397 | conn_info->req_ie_len, |
| 5398 | conn_info->resp_ie, |
| 5399 | conn_info->resp_ie_len, |
| 5400 | completed ? WLAN_STATUS_SUCCESS : |
| 5401 | WLAN_STATUS_AUTH_TIMEOUT, |
| 5402 | GFP_KERNEL); |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 5403 | brcmf_dbg(CONN, "Report connect result - connection %s\n", |
| 5404 | completed ? "succeeded" : "failed"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5405 | } |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 5406 | brcmf_dbg(TRACE, "Exit\n"); |
Peter Senna Tschudin | 12f3237 | 2014-05-31 10:14:06 -0300 | [diff] [blame] | 5407 | return 0; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5408 | } |
| 5409 | |
| 5410 | static s32 |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5411 | brcmf_notify_connect_status_ap(struct brcmf_cfg80211_info *cfg, |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 5412 | struct net_device *ndev, |
| 5413 | const struct brcmf_event_msg *e, void *data) |
| 5414 | { |
Hante Meuleman | 7ee2960 | 2013-02-06 18:40:43 +0100 | [diff] [blame] | 5415 | static int generation; |
Arend van Spriel | 5c36b99 | 2012-11-14 18:46:05 -0800 | [diff] [blame] | 5416 | u32 event = e->event_code; |
| 5417 | u32 reason = e->reason; |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 5418 | struct station_info sinfo; |
| 5419 | |
Rafał Miłecki | e1c122d | 2016-10-14 09:45:59 +0200 | [diff] [blame] | 5420 | brcmf_dbg(CONN, "event %s (%u), reason %d\n", |
| 5421 | brcmf_fweh_event_name(event), event, reason); |
Arend van Spriel | 5f4f9f1 | 2013-02-08 15:53:41 +0100 | [diff] [blame] | 5422 | if (event == BRCMF_E_LINK && reason == BRCMF_E_REASON_LINK_BSSCFG_DIS && |
| 5423 | ndev != cfg_to_ndev(cfg)) { |
| 5424 | brcmf_dbg(CONN, "AP mode link down\n"); |
| 5425 | complete(&cfg->vif_disabled); |
| 5426 | return 0; |
| 5427 | } |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 5428 | |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 5429 | if (((event == BRCMF_E_ASSOC_IND) || (event == BRCMF_E_REASSOC_IND)) && |
Hante Meuleman | 7ee2960 | 2013-02-06 18:40:43 +0100 | [diff] [blame] | 5430 | (reason == BRCMF_E_STATUS_SUCCESS)) { |
| 5431 | memset(&sinfo, 0, sizeof(sinfo)); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 5432 | if (!data) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 5433 | brcmf_err("No IEs present in ASSOC/REASSOC_IND"); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 5434 | return -EINVAL; |
| 5435 | } |
| 5436 | sinfo.assoc_req_ies = data; |
Hante Meuleman | 7ee2960 | 2013-02-06 18:40:43 +0100 | [diff] [blame] | 5437 | sinfo.assoc_req_ies_len = e->datalen; |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 5438 | generation++; |
| 5439 | sinfo.generation = generation; |
Hante Meuleman | 7ee2960 | 2013-02-06 18:40:43 +0100 | [diff] [blame] | 5440 | cfg80211_new_sta(ndev, e->addr, &sinfo, GFP_KERNEL); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 5441 | } else if ((event == BRCMF_E_DISASSOC_IND) || |
| 5442 | (event == BRCMF_E_DEAUTH_IND) || |
| 5443 | (event == BRCMF_E_DEAUTH)) { |
Hante Meuleman | 7ee2960 | 2013-02-06 18:40:43 +0100 | [diff] [blame] | 5444 | cfg80211_del_sta(ndev, e->addr, GFP_KERNEL); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 5445 | } |
Hante Meuleman | 7ee2960 | 2013-02-06 18:40:43 +0100 | [diff] [blame] | 5446 | return 0; |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 5447 | } |
| 5448 | |
| 5449 | static s32 |
Arend van Spriel | 1993732 | 2012-11-05 16:22:32 -0800 | [diff] [blame] | 5450 | brcmf_notify_connect_status(struct brcmf_if *ifp, |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5451 | const struct brcmf_event_msg *e, void *data) |
| 5452 | { |
Arend van Spriel | 1993732 | 2012-11-05 16:22:32 -0800 | [diff] [blame] | 5453 | struct brcmf_cfg80211_info *cfg = ifp->drvr->config; |
| 5454 | struct net_device *ndev = ifp->ndev; |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 5455 | struct brcmf_cfg80211_profile *profile = &ifp->vif->profile; |
Antonio Quartulli | fe94f3a | 2014-01-29 17:53:43 +0100 | [diff] [blame] | 5456 | struct ieee80211_channel *chan; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5457 | s32 err = 0; |
| 5458 | |
Hante Meuleman | 8851cce | 2014-07-30 13:20:02 +0200 | [diff] [blame] | 5459 | if ((e->event_code == BRCMF_E_DEAUTH) || |
| 5460 | (e->event_code == BRCMF_E_DEAUTH_IND) || |
| 5461 | (e->event_code == BRCMF_E_DISASSOC_IND) || |
| 5462 | ((e->event_code == BRCMF_E_LINK) && (!e->flags))) { |
| 5463 | brcmf_proto_delete_peer(ifp->drvr, ifp->ifidx, (u8 *)e->addr); |
| 5464 | } |
| 5465 | |
Arend van Spriel | 967fe2c | 2014-03-15 17:18:21 +0100 | [diff] [blame] | 5466 | if (brcmf_is_apmode(ifp->vif)) { |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5467 | err = brcmf_notify_connect_status_ap(cfg, ndev, e, data); |
Arend van Spriel | 903e0ee | 2012-11-28 21:44:11 +0100 | [diff] [blame] | 5468 | } else if (brcmf_is_linkup(e)) { |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 5469 | brcmf_dbg(CONN, "Linkup\n"); |
Arend van Spriel | 128ce3b | 2012-11-28 21:44:12 +0100 | [diff] [blame] | 5470 | if (brcmf_is_ibssmode(ifp->vif)) { |
Hante Meuleman | b0a7908 | 2015-12-10 13:43:07 +0100 | [diff] [blame] | 5471 | brcmf_inform_ibss(cfg, ndev, e->addr); |
Antonio Quartulli | fe94f3a | 2014-01-29 17:53:43 +0100 | [diff] [blame] | 5472 | chan = ieee80211_get_channel(cfg->wiphy, cfg->channel); |
Arend van Spriel | 6c8c4f7 | 2012-09-27 14:17:57 +0200 | [diff] [blame] | 5473 | memcpy(profile->bssid, e->addr, ETH_ALEN); |
Antonio Quartulli | fe94f3a | 2014-01-29 17:53:43 +0100 | [diff] [blame] | 5474 | cfg80211_ibss_joined(ndev, e->addr, chan, GFP_KERNEL); |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 5475 | clear_bit(BRCMF_VIF_STATUS_CONNECTING, |
| 5476 | &ifp->vif->sme_state); |
| 5477 | set_bit(BRCMF_VIF_STATUS_CONNECTED, |
| 5478 | &ifp->vif->sme_state); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5479 | } else |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5480 | brcmf_bss_connect_done(cfg, ndev, e, true); |
Hante Meuleman | 92121e6 | 2015-10-08 20:33:21 +0200 | [diff] [blame] | 5481 | brcmf_net_setcarrier(ifp, true); |
Arend van Spriel | 903e0ee | 2012-11-28 21:44:11 +0100 | [diff] [blame] | 5482 | } else if (brcmf_is_linkdown(e)) { |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 5483 | brcmf_dbg(CONN, "Linkdown\n"); |
Arend van Spriel | 128ce3b | 2012-11-28 21:44:12 +0100 | [diff] [blame] | 5484 | if (!brcmf_is_ibssmode(ifp->vif)) { |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5485 | brcmf_bss_connect_done(cfg, ndev, e, false); |
Hante Meuleman | 42e0ed0 | 2016-01-05 11:05:50 +0100 | [diff] [blame] | 5486 | brcmf_link_down(ifp->vif, |
| 5487 | brcmf_map_fw_linkdown_reason(e)); |
| 5488 | brcmf_init_prof(ndev_to_prof(ndev)); |
| 5489 | if (ndev != cfg_to_ndev(cfg)) |
| 5490 | complete(&cfg->vif_disabled); |
| 5491 | brcmf_net_setcarrier(ifp, false); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5492 | } |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5493 | } else if (brcmf_is_nonetwork(cfg, e)) { |
Arend van Spriel | 128ce3b | 2012-11-28 21:44:12 +0100 | [diff] [blame] | 5494 | if (brcmf_is_ibssmode(ifp->vif)) |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 5495 | clear_bit(BRCMF_VIF_STATUS_CONNECTING, |
| 5496 | &ifp->vif->sme_state); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5497 | else |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5498 | brcmf_bss_connect_done(cfg, ndev, e, false); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5499 | } |
| 5500 | |
| 5501 | return err; |
| 5502 | } |
| 5503 | |
| 5504 | static s32 |
Arend van Spriel | 1993732 | 2012-11-05 16:22:32 -0800 | [diff] [blame] | 5505 | brcmf_notify_roaming_status(struct brcmf_if *ifp, |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5506 | const struct brcmf_event_msg *e, void *data) |
| 5507 | { |
Arend van Spriel | 1993732 | 2012-11-05 16:22:32 -0800 | [diff] [blame] | 5508 | struct brcmf_cfg80211_info *cfg = ifp->drvr->config; |
Arend van Spriel | 5c36b99 | 2012-11-14 18:46:05 -0800 | [diff] [blame] | 5509 | u32 event = e->event_code; |
| 5510 | u32 status = e->status; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5511 | |
| 5512 | if (event == BRCMF_E_ROAM && status == BRCMF_E_STATUS_SUCCESS) { |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 5513 | if (test_bit(BRCMF_VIF_STATUS_CONNECTED, &ifp->vif->sme_state)) |
Arend van Spriel | 1993732 | 2012-11-05 16:22:32 -0800 | [diff] [blame] | 5514 | brcmf_bss_roaming_done(cfg, ifp->ndev, e); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5515 | else |
Arend van Spriel | 1993732 | 2012-11-05 16:22:32 -0800 | [diff] [blame] | 5516 | brcmf_bss_connect_done(cfg, ifp->ndev, e, true); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5517 | } |
| 5518 | |
Peter Senna Tschudin | 12f3237 | 2014-05-31 10:14:06 -0300 | [diff] [blame] | 5519 | return 0; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5520 | } |
| 5521 | |
| 5522 | static s32 |
Arend van Spriel | 1993732 | 2012-11-05 16:22:32 -0800 | [diff] [blame] | 5523 | brcmf_notify_mic_status(struct brcmf_if *ifp, |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5524 | const struct brcmf_event_msg *e, void *data) |
| 5525 | { |
Arend van Spriel | 5c36b99 | 2012-11-14 18:46:05 -0800 | [diff] [blame] | 5526 | u16 flags = e->flags; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5527 | enum nl80211_key_type key_type; |
| 5528 | |
| 5529 | if (flags & BRCMF_EVENT_MSG_GROUP) |
| 5530 | key_type = NL80211_KEYTYPE_GROUP; |
| 5531 | else |
| 5532 | key_type = NL80211_KEYTYPE_PAIRWISE; |
| 5533 | |
Arend van Spriel | 1993732 | 2012-11-05 16:22:32 -0800 | [diff] [blame] | 5534 | cfg80211_michael_mic_failure(ifp->ndev, (u8 *)&e->addr, key_type, -1, |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5535 | NULL, GFP_KERNEL); |
| 5536 | |
| 5537 | return 0; |
| 5538 | } |
| 5539 | |
Arend van Spriel | d3c0b63 | 2013-02-08 15:53:37 +0100 | [diff] [blame] | 5540 | static s32 brcmf_notify_vif_event(struct brcmf_if *ifp, |
| 5541 | const struct brcmf_event_msg *e, void *data) |
| 5542 | { |
| 5543 | struct brcmf_cfg80211_info *cfg = ifp->drvr->config; |
| 5544 | struct brcmf_if_event *ifevent = (struct brcmf_if_event *)data; |
| 5545 | struct brcmf_cfg80211_vif_event *event = &cfg->vif_event; |
| 5546 | struct brcmf_cfg80211_vif *vif; |
| 5547 | |
Hante Meuleman | 37a869e | 2015-10-29 20:33:17 +0100 | [diff] [blame] | 5548 | brcmf_dbg(TRACE, "Enter: action %u flags %u ifidx %u bsscfgidx %u\n", |
Arend van Spriel | d3c0b63 | 2013-02-08 15:53:37 +0100 | [diff] [blame] | 5549 | ifevent->action, ifevent->flags, ifevent->ifidx, |
Hante Meuleman | 37a869e | 2015-10-29 20:33:17 +0100 | [diff] [blame] | 5550 | ifevent->bsscfgidx); |
Arend van Spriel | d3c0b63 | 2013-02-08 15:53:37 +0100 | [diff] [blame] | 5551 | |
mhiramat@kernel.org | b64abcb | 2016-08-15 18:41:12 +0900 | [diff] [blame] | 5552 | spin_lock(&event->vif_event_lock); |
Arend van Spriel | d3c0b63 | 2013-02-08 15:53:37 +0100 | [diff] [blame] | 5553 | event->action = ifevent->action; |
| 5554 | vif = event->vif; |
| 5555 | |
| 5556 | switch (ifevent->action) { |
| 5557 | case BRCMF_E_IF_ADD: |
| 5558 | /* waiting process may have timed out */ |
Wei Yongjun | dc4a787 | 2013-02-22 21:32:20 +0800 | [diff] [blame] | 5559 | if (!cfg->vif_event.vif) { |
mhiramat@kernel.org | b64abcb | 2016-08-15 18:41:12 +0900 | [diff] [blame] | 5560 | spin_unlock(&event->vif_event_lock); |
Arend van Spriel | d3c0b63 | 2013-02-08 15:53:37 +0100 | [diff] [blame] | 5561 | return -EBADF; |
Wei Yongjun | dc4a787 | 2013-02-22 21:32:20 +0800 | [diff] [blame] | 5562 | } |
Arend van Spriel | d3c0b63 | 2013-02-08 15:53:37 +0100 | [diff] [blame] | 5563 | |
| 5564 | ifp->vif = vif; |
| 5565 | vif->ifp = ifp; |
Arend van Spriel | 01b8e7d | 2013-04-05 10:57:51 +0200 | [diff] [blame] | 5566 | if (ifp->ndev) { |
| 5567 | vif->wdev.netdev = ifp->ndev; |
| 5568 | ifp->ndev->ieee80211_ptr = &vif->wdev; |
| 5569 | SET_NETDEV_DEV(ifp->ndev, wiphy_dev(cfg->wiphy)); |
| 5570 | } |
mhiramat@kernel.org | b64abcb | 2016-08-15 18:41:12 +0900 | [diff] [blame] | 5571 | spin_unlock(&event->vif_event_lock); |
Arend van Spriel | d3c0b63 | 2013-02-08 15:53:37 +0100 | [diff] [blame] | 5572 | wake_up(&event->vif_wq); |
Hante Meuleman | 4b3a89d | 2013-02-08 15:54:01 +0100 | [diff] [blame] | 5573 | return 0; |
Arend van Spriel | d3c0b63 | 2013-02-08 15:53:37 +0100 | [diff] [blame] | 5574 | |
| 5575 | case BRCMF_E_IF_DEL: |
mhiramat@kernel.org | b64abcb | 2016-08-15 18:41:12 +0900 | [diff] [blame] | 5576 | spin_unlock(&event->vif_event_lock); |
Arend van Spriel | d3c0b63 | 2013-02-08 15:53:37 +0100 | [diff] [blame] | 5577 | /* event may not be upon user request */ |
| 5578 | if (brcmf_cfg80211_vif_event_armed(cfg)) |
| 5579 | wake_up(&event->vif_wq); |
| 5580 | return 0; |
| 5581 | |
Hante Meuleman | 7a5c1f6 | 2013-02-08 15:53:44 +0100 | [diff] [blame] | 5582 | case BRCMF_E_IF_CHANGE: |
mhiramat@kernel.org | b64abcb | 2016-08-15 18:41:12 +0900 | [diff] [blame] | 5583 | spin_unlock(&event->vif_event_lock); |
Hante Meuleman | 7a5c1f6 | 2013-02-08 15:53:44 +0100 | [diff] [blame] | 5584 | wake_up(&event->vif_wq); |
| 5585 | return 0; |
| 5586 | |
Arend van Spriel | d3c0b63 | 2013-02-08 15:53:37 +0100 | [diff] [blame] | 5587 | default: |
mhiramat@kernel.org | b64abcb | 2016-08-15 18:41:12 +0900 | [diff] [blame] | 5588 | spin_unlock(&event->vif_event_lock); |
Arend van Spriel | d3c0b63 | 2013-02-08 15:53:37 +0100 | [diff] [blame] | 5589 | break; |
| 5590 | } |
| 5591 | return -EINVAL; |
| 5592 | } |
| 5593 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5594 | static void brcmf_init_conf(struct brcmf_cfg80211_conf *conf) |
| 5595 | { |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5596 | conf->frag_threshold = (u32)-1; |
| 5597 | conf->rts_threshold = (u32)-1; |
| 5598 | conf->retry_short = (u32)-1; |
| 5599 | conf->retry_long = (u32)-1; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5600 | } |
| 5601 | |
Arend van Spriel | 5c36b99 | 2012-11-14 18:46:05 -0800 | [diff] [blame] | 5602 | static void brcmf_register_event_handlers(struct brcmf_cfg80211_info *cfg) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5603 | { |
Arend van Spriel | 5c36b99 | 2012-11-14 18:46:05 -0800 | [diff] [blame] | 5604 | brcmf_fweh_register(cfg->pub, BRCMF_E_LINK, |
| 5605 | brcmf_notify_connect_status); |
| 5606 | brcmf_fweh_register(cfg->pub, BRCMF_E_DEAUTH_IND, |
| 5607 | brcmf_notify_connect_status); |
| 5608 | brcmf_fweh_register(cfg->pub, BRCMF_E_DEAUTH, |
| 5609 | brcmf_notify_connect_status); |
| 5610 | brcmf_fweh_register(cfg->pub, BRCMF_E_DISASSOC_IND, |
| 5611 | brcmf_notify_connect_status); |
| 5612 | brcmf_fweh_register(cfg->pub, BRCMF_E_ASSOC_IND, |
| 5613 | brcmf_notify_connect_status); |
| 5614 | brcmf_fweh_register(cfg->pub, BRCMF_E_REASSOC_IND, |
| 5615 | brcmf_notify_connect_status); |
| 5616 | brcmf_fweh_register(cfg->pub, BRCMF_E_ROAM, |
| 5617 | brcmf_notify_roaming_status); |
| 5618 | brcmf_fweh_register(cfg->pub, BRCMF_E_MIC_ERROR, |
| 5619 | brcmf_notify_mic_status); |
| 5620 | brcmf_fweh_register(cfg->pub, BRCMF_E_SET_SSID, |
| 5621 | brcmf_notify_connect_status); |
| 5622 | brcmf_fweh_register(cfg->pub, BRCMF_E_PFN_NET_FOUND, |
| 5623 | brcmf_notify_sched_scan_results); |
Arend van Spriel | d3c0b63 | 2013-02-08 15:53:37 +0100 | [diff] [blame] | 5624 | brcmf_fweh_register(cfg->pub, BRCMF_E_IF, |
| 5625 | brcmf_notify_vif_event); |
Hante Meuleman | 0de8aac | 2013-02-08 15:53:38 +0100 | [diff] [blame] | 5626 | brcmf_fweh_register(cfg->pub, BRCMF_E_P2P_PROBEREQ_MSG, |
Hante Meuleman | 6eda4e2 | 2013-02-08 15:54:02 +0100 | [diff] [blame] | 5627 | brcmf_p2p_notify_rx_mgmt_p2p_probereq); |
Hante Meuleman | 0de8aac | 2013-02-08 15:53:38 +0100 | [diff] [blame] | 5628 | brcmf_fweh_register(cfg->pub, BRCMF_E_P2P_DISC_LISTEN_COMPLETE, |
| 5629 | brcmf_p2p_notify_listen_complete); |
Hante Meuleman | e6da340 | 2013-02-08 15:53:48 +0100 | [diff] [blame] | 5630 | brcmf_fweh_register(cfg->pub, BRCMF_E_ACTION_FRAME_RX, |
| 5631 | brcmf_p2p_notify_action_frame_rx); |
Hante Meuleman | 18e2f61 | 2013-02-08 15:53:49 +0100 | [diff] [blame] | 5632 | brcmf_fweh_register(cfg->pub, BRCMF_E_ACTION_FRAME_COMPLETE, |
| 5633 | brcmf_p2p_notify_action_tx_complete); |
Hante Meuleman | 6eda4e2 | 2013-02-08 15:54:02 +0100 | [diff] [blame] | 5634 | brcmf_fweh_register(cfg->pub, BRCMF_E_ACTION_FRAME_OFF_CHAN_COMPLETE, |
| 5635 | brcmf_p2p_notify_action_tx_complete); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5636 | } |
| 5637 | |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5638 | static void brcmf_deinit_priv_mem(struct brcmf_cfg80211_info *cfg) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5639 | { |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5640 | kfree(cfg->conf); |
| 5641 | cfg->conf = NULL; |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5642 | kfree(cfg->extra_buf); |
| 5643 | cfg->extra_buf = NULL; |
Hante Meuleman | 3021ad9 | 2016-01-05 11:05:45 +0100 | [diff] [blame] | 5644 | kfree(cfg->wowl.nd); |
| 5645 | cfg->wowl.nd = NULL; |
| 5646 | kfree(cfg->wowl.nd_info); |
| 5647 | cfg->wowl.nd_info = NULL; |
Hante Meuleman | d536733 | 2016-02-17 11:26:51 +0100 | [diff] [blame] | 5648 | kfree(cfg->escan_info.escan_buf); |
| 5649 | cfg->escan_info.escan_buf = NULL; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5650 | } |
| 5651 | |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5652 | static s32 brcmf_init_priv_mem(struct brcmf_cfg80211_info *cfg) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5653 | { |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5654 | cfg->conf = kzalloc(sizeof(*cfg->conf), GFP_KERNEL); |
| 5655 | if (!cfg->conf) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5656 | goto init_priv_mem_out; |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5657 | cfg->extra_buf = kzalloc(WL_EXTRA_BUF_MAX, GFP_KERNEL); |
| 5658 | if (!cfg->extra_buf) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5659 | goto init_priv_mem_out; |
Hante Meuleman | 3021ad9 | 2016-01-05 11:05:45 +0100 | [diff] [blame] | 5660 | cfg->wowl.nd = kzalloc(sizeof(*cfg->wowl.nd) + sizeof(u32), GFP_KERNEL); |
| 5661 | if (!cfg->wowl.nd) |
| 5662 | goto init_priv_mem_out; |
| 5663 | cfg->wowl.nd_info = kzalloc(sizeof(*cfg->wowl.nd_info) + |
| 5664 | sizeof(struct cfg80211_wowlan_nd_match *), |
| 5665 | GFP_KERNEL); |
| 5666 | if (!cfg->wowl.nd_info) |
| 5667 | goto init_priv_mem_out; |
Hante Meuleman | d536733 | 2016-02-17 11:26:51 +0100 | [diff] [blame] | 5668 | cfg->escan_info.escan_buf = kzalloc(BRCMF_ESCAN_BUF_SIZE, GFP_KERNEL); |
| 5669 | if (!cfg->escan_info.escan_buf) |
| 5670 | goto init_priv_mem_out; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5671 | |
| 5672 | return 0; |
| 5673 | |
| 5674 | init_priv_mem_out: |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5675 | brcmf_deinit_priv_mem(cfg); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5676 | |
| 5677 | return -ENOMEM; |
| 5678 | } |
| 5679 | |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5680 | static s32 wl_init_priv(struct brcmf_cfg80211_info *cfg) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5681 | { |
| 5682 | s32 err = 0; |
| 5683 | |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5684 | cfg->scan_request = NULL; |
| 5685 | cfg->pwr_save = true; |
Hante Meuleman | 68ca395 | 2014-02-25 20:30:26 +0100 | [diff] [blame] | 5686 | cfg->active_scan = true; /* we do active scan per default */ |
| 5687 | cfg->dongle_up = false; /* dongle is not up yet */ |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5688 | err = brcmf_init_priv_mem(cfg); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5689 | if (err) |
| 5690 | return err; |
Arend van Spriel | 5c36b99 | 2012-11-14 18:46:05 -0800 | [diff] [blame] | 5691 | brcmf_register_event_handlers(cfg); |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5692 | mutex_init(&cfg->usr_sync); |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5693 | brcmf_init_escan(cfg); |
| 5694 | brcmf_init_conf(cfg->conf); |
Arend van Spriel | 5f4f9f1 | 2013-02-08 15:53:41 +0100 | [diff] [blame] | 5695 | init_completion(&cfg->vif_disabled); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5696 | return err; |
| 5697 | } |
| 5698 | |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5699 | static void wl_deinit_priv(struct brcmf_cfg80211_info *cfg) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5700 | { |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5701 | cfg->dongle_up = false; /* dongle down */ |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5702 | brcmf_abort_scanning(cfg); |
| 5703 | brcmf_deinit_priv_mem(cfg); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5704 | } |
| 5705 | |
Arend van Spriel | d3c0b63 | 2013-02-08 15:53:37 +0100 | [diff] [blame] | 5706 | static void init_vif_event(struct brcmf_cfg80211_vif_event *event) |
| 5707 | { |
| 5708 | init_waitqueue_head(&event->vif_wq); |
mhiramat@kernel.org | b64abcb | 2016-08-15 18:41:12 +0900 | [diff] [blame] | 5709 | spin_lock_init(&event->vif_event_lock); |
Arend van Spriel | d3c0b63 | 2013-02-08 15:53:37 +0100 | [diff] [blame] | 5710 | } |
| 5711 | |
Hante Meuleman | 1119e23 | 2015-11-25 11:32:42 +0100 | [diff] [blame] | 5712 | static s32 brcmf_dongle_roam(struct brcmf_if *ifp) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5713 | { |
Hante Meuleman | 1119e23 | 2015-11-25 11:32:42 +0100 | [diff] [blame] | 5714 | s32 err; |
| 5715 | u32 bcn_timeout; |
Arend van Spriel | f588bc0 | 2011-10-12 20:51:22 +0200 | [diff] [blame] | 5716 | __le32 roamtrigger[2]; |
| 5717 | __le32 roam_delta[2]; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5718 | |
Hante Meuleman | 1119e23 | 2015-11-25 11:32:42 +0100 | [diff] [blame] | 5719 | /* Configure beacon timeout value based upon roaming setting */ |
Hante Meuleman | 7d34b05 | 2016-01-02 09:41:41 +0100 | [diff] [blame] | 5720 | if (ifp->drvr->settings->roamoff) |
Hante Meuleman | 1119e23 | 2015-11-25 11:32:42 +0100 | [diff] [blame] | 5721 | bcn_timeout = BRCMF_DEFAULT_BCN_TIMEOUT_ROAM_OFF; |
| 5722 | else |
| 5723 | bcn_timeout = BRCMF_DEFAULT_BCN_TIMEOUT_ROAM_ON; |
| 5724 | err = brcmf_fil_iovar_int_set(ifp, "bcn_timeout", bcn_timeout); |
| 5725 | if (err) { |
| 5726 | brcmf_err("bcn_timeout error (%d)\n", err); |
| 5727 | goto roam_setup_done; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5728 | } |
| 5729 | |
Hante Meuleman | 1119e23 | 2015-11-25 11:32:42 +0100 | [diff] [blame] | 5730 | /* Enable/Disable built-in roaming to allow supplicant to take care of |
| 5731 | * roaming. |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5732 | */ |
Hante Meuleman | 68ca395 | 2014-02-25 20:30:26 +0100 | [diff] [blame] | 5733 | brcmf_dbg(INFO, "Internal Roaming = %s\n", |
Hante Meuleman | 7d34b05 | 2016-01-02 09:41:41 +0100 | [diff] [blame] | 5734 | ifp->drvr->settings->roamoff ? "Off" : "On"); |
| 5735 | err = brcmf_fil_iovar_int_set(ifp, "roam_off", |
| 5736 | ifp->drvr->settings->roamoff); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5737 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 5738 | brcmf_err("roam_off error (%d)\n", err); |
Hante Meuleman | 1119e23 | 2015-11-25 11:32:42 +0100 | [diff] [blame] | 5739 | goto roam_setup_done; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5740 | } |
| 5741 | |
Arend van Spriel | f588bc0 | 2011-10-12 20:51:22 +0200 | [diff] [blame] | 5742 | roamtrigger[0] = cpu_to_le32(WL_ROAM_TRIGGER_LEVEL); |
| 5743 | roamtrigger[1] = cpu_to_le32(BRCM_BAND_ALL); |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 5744 | err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SET_ROAM_TRIGGER, |
Hante Meuleman | 81f5dcb | 2012-10-22 10:36:14 -0700 | [diff] [blame] | 5745 | (void *)roamtrigger, sizeof(roamtrigger)); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5746 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 5747 | brcmf_err("WLC_SET_ROAM_TRIGGER error (%d)\n", err); |
Hante Meuleman | 1119e23 | 2015-11-25 11:32:42 +0100 | [diff] [blame] | 5748 | goto roam_setup_done; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5749 | } |
| 5750 | |
Arend van Spriel | f588bc0 | 2011-10-12 20:51:22 +0200 | [diff] [blame] | 5751 | roam_delta[0] = cpu_to_le32(WL_ROAM_DELTA); |
| 5752 | roam_delta[1] = cpu_to_le32(BRCM_BAND_ALL); |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 5753 | err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SET_ROAM_DELTA, |
Hante Meuleman | 81f5dcb | 2012-10-22 10:36:14 -0700 | [diff] [blame] | 5754 | (void *)roam_delta, sizeof(roam_delta)); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5755 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 5756 | brcmf_err("WLC_SET_ROAM_DELTA error (%d)\n", err); |
Hante Meuleman | 1119e23 | 2015-11-25 11:32:42 +0100 | [diff] [blame] | 5757 | goto roam_setup_done; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5758 | } |
| 5759 | |
Hante Meuleman | 1119e23 | 2015-11-25 11:32:42 +0100 | [diff] [blame] | 5760 | roam_setup_done: |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5761 | return err; |
| 5762 | } |
| 5763 | |
| 5764 | static s32 |
Hante Meuleman | 1678ba8 | 2015-12-10 13:43:00 +0100 | [diff] [blame] | 5765 | brcmf_dongle_scantime(struct brcmf_if *ifp) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5766 | { |
| 5767 | s32 err = 0; |
| 5768 | |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 5769 | err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_SCAN_CHANNEL_TIME, |
Hante Meuleman | 1678ba8 | 2015-12-10 13:43:00 +0100 | [diff] [blame] | 5770 | BRCMF_SCAN_CHANNEL_TIME); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5771 | if (err) { |
Hante Meuleman | 1678ba8 | 2015-12-10 13:43:00 +0100 | [diff] [blame] | 5772 | brcmf_err("Scan assoc time error (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5773 | goto dongle_scantime_out; |
| 5774 | } |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 5775 | err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_SCAN_UNASSOC_TIME, |
Hante Meuleman | 1678ba8 | 2015-12-10 13:43:00 +0100 | [diff] [blame] | 5776 | BRCMF_SCAN_UNASSOC_TIME); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5777 | if (err) { |
Hante Meuleman | 1678ba8 | 2015-12-10 13:43:00 +0100 | [diff] [blame] | 5778 | brcmf_err("Scan unassoc time error (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5779 | goto dongle_scantime_out; |
| 5780 | } |
| 5781 | |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 5782 | err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_SCAN_PASSIVE_TIME, |
Hante Meuleman | 1678ba8 | 2015-12-10 13:43:00 +0100 | [diff] [blame] | 5783 | BRCMF_SCAN_PASSIVE_TIME); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5784 | if (err) { |
Hante Meuleman | 1678ba8 | 2015-12-10 13:43:00 +0100 | [diff] [blame] | 5785 | brcmf_err("Scan passive time error (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5786 | goto dongle_scantime_out; |
| 5787 | } |
| 5788 | |
| 5789 | dongle_scantime_out: |
| 5790 | return err; |
| 5791 | } |
| 5792 | |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 5793 | static void brcmf_update_bw40_channel_flag(struct ieee80211_channel *channel, |
| 5794 | struct brcmu_chan *ch) |
| 5795 | { |
| 5796 | u32 ht40_flag; |
| 5797 | |
| 5798 | ht40_flag = channel->flags & IEEE80211_CHAN_NO_HT40; |
| 5799 | if (ch->sb == BRCMU_CHAN_SB_U) { |
| 5800 | if (ht40_flag == IEEE80211_CHAN_NO_HT40) |
| 5801 | channel->flags &= ~IEEE80211_CHAN_NO_HT40; |
| 5802 | channel->flags |= IEEE80211_CHAN_NO_HT40PLUS; |
| 5803 | } else { |
| 5804 | /* It should be one of |
| 5805 | * IEEE80211_CHAN_NO_HT40 or |
| 5806 | * IEEE80211_CHAN_NO_HT40PLUS |
| 5807 | */ |
| 5808 | channel->flags &= ~IEEE80211_CHAN_NO_HT40; |
| 5809 | if (ht40_flag == IEEE80211_CHAN_NO_HT40) |
| 5810 | channel->flags |= IEEE80211_CHAN_NO_HT40MINUS; |
| 5811 | } |
| 5812 | } |
| 5813 | |
| 5814 | static int brcmf_construct_chaninfo(struct brcmf_cfg80211_info *cfg, |
| 5815 | u32 bw_cap[]) |
Hante Meuleman | d48200b | 2013-04-03 12:40:29 +0200 | [diff] [blame] | 5816 | { |
| 5817 | struct brcmf_if *ifp = netdev_priv(cfg_to_ndev(cfg)); |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 5818 | struct ieee80211_supported_band *band; |
| 5819 | struct ieee80211_channel *channel; |
| 5820 | struct wiphy *wiphy; |
Hante Meuleman | d48200b | 2013-04-03 12:40:29 +0200 | [diff] [blame] | 5821 | struct brcmf_chanspec_list *list; |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 5822 | struct brcmu_chan ch; |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 5823 | int err; |
Hante Meuleman | d48200b | 2013-04-03 12:40:29 +0200 | [diff] [blame] | 5824 | u8 *pbuf; |
| 5825 | u32 i, j; |
| 5826 | u32 total; |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 5827 | u32 chaninfo; |
Hante Meuleman | d48200b | 2013-04-03 12:40:29 +0200 | [diff] [blame] | 5828 | u32 index; |
Hante Meuleman | d48200b | 2013-04-03 12:40:29 +0200 | [diff] [blame] | 5829 | |
| 5830 | pbuf = kzalloc(BRCMF_DCMD_MEDLEN, GFP_KERNEL); |
| 5831 | |
| 5832 | if (pbuf == NULL) |
| 5833 | return -ENOMEM; |
| 5834 | |
| 5835 | list = (struct brcmf_chanspec_list *)pbuf; |
| 5836 | |
| 5837 | err = brcmf_fil_iovar_data_get(ifp, "chanspecs", pbuf, |
| 5838 | BRCMF_DCMD_MEDLEN); |
| 5839 | if (err) { |
| 5840 | brcmf_err("get chanspecs error (%d)\n", err); |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 5841 | goto fail_pbuf; |
Hante Meuleman | d48200b | 2013-04-03 12:40:29 +0200 | [diff] [blame] | 5842 | } |
| 5843 | |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 5844 | wiphy = cfg_to_wiphy(cfg); |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 5845 | band = wiphy->bands[NL80211_BAND_2GHZ]; |
Arend van Spriel | 58de92d | 2015-04-14 20:10:24 +0200 | [diff] [blame] | 5846 | if (band) |
| 5847 | for (i = 0; i < band->n_channels; i++) |
| 5848 | band->channels[i].flags = IEEE80211_CHAN_DISABLED; |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 5849 | band = wiphy->bands[NL80211_BAND_5GHZ]; |
Arend van Spriel | 58de92d | 2015-04-14 20:10:24 +0200 | [diff] [blame] | 5850 | if (band) |
| 5851 | for (i = 0; i < band->n_channels; i++) |
| 5852 | band->channels[i].flags = IEEE80211_CHAN_DISABLED; |
Hante Meuleman | d48200b | 2013-04-03 12:40:29 +0200 | [diff] [blame] | 5853 | |
| 5854 | total = le32_to_cpu(list->count); |
| 5855 | for (i = 0; i < total; i++) { |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 5856 | ch.chspec = (u16)le32_to_cpu(list->element[i]); |
| 5857 | cfg->d11inf.decchspec(&ch); |
Hante Meuleman | d48200b | 2013-04-03 12:40:29 +0200 | [diff] [blame] | 5858 | |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 5859 | if (ch.band == BRCMU_CHAN_BAND_2G) { |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 5860 | band = wiphy->bands[NL80211_BAND_2GHZ]; |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 5861 | } else if (ch.band == BRCMU_CHAN_BAND_5G) { |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 5862 | band = wiphy->bands[NL80211_BAND_5GHZ]; |
Hante Meuleman | d48200b | 2013-04-03 12:40:29 +0200 | [diff] [blame] | 5863 | } else { |
Arend van Spriel | 2375d97 | 2014-01-06 12:40:41 +0100 | [diff] [blame] | 5864 | brcmf_err("Invalid channel Spec. 0x%x.\n", ch.chspec); |
Hante Meuleman | d48200b | 2013-04-03 12:40:29 +0200 | [diff] [blame] | 5865 | continue; |
| 5866 | } |
Arend van Spriel | 58de92d | 2015-04-14 20:10:24 +0200 | [diff] [blame] | 5867 | if (!band) |
| 5868 | continue; |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 5869 | if (!(bw_cap[band->band] & WLC_BW_40MHZ_BIT) && |
Arend van Spriel | 2375d97 | 2014-01-06 12:40:41 +0100 | [diff] [blame] | 5870 | ch.bw == BRCMU_CHAN_BW_40) |
Hante Meuleman | d48200b | 2013-04-03 12:40:29 +0200 | [diff] [blame] | 5871 | continue; |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 5872 | if (!(bw_cap[band->band] & WLC_BW_80MHZ_BIT) && |
Arend van Spriel | ee942ec | 2014-05-12 10:47:38 +0200 | [diff] [blame] | 5873 | ch.bw == BRCMU_CHAN_BW_80) |
| 5874 | continue; |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 5875 | |
| 5876 | channel = band->channels; |
| 5877 | index = band->n_channels; |
| 5878 | for (j = 0; j < band->n_channels; j++) { |
Rafał Miłecki | 4712d88 | 2016-05-20 13:38:57 +0200 | [diff] [blame] | 5879 | if (channel[j].hw_value == ch.control_ch_num) { |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 5880 | index = j; |
Hante Meuleman | d48200b | 2013-04-03 12:40:29 +0200 | [diff] [blame] | 5881 | break; |
| 5882 | } |
| 5883 | } |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 5884 | channel[index].center_freq = |
Rafał Miłecki | 4712d88 | 2016-05-20 13:38:57 +0200 | [diff] [blame] | 5885 | ieee80211_channel_to_frequency(ch.control_ch_num, |
| 5886 | band->band); |
| 5887 | channel[index].hw_value = ch.control_ch_num; |
Hante Meuleman | d48200b | 2013-04-03 12:40:29 +0200 | [diff] [blame] | 5888 | |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 5889 | /* assuming the chanspecs order is HT20, |
| 5890 | * HT40 upper, HT40 lower, and VHT80. |
| 5891 | */ |
| 5892 | if (ch.bw == BRCMU_CHAN_BW_80) { |
| 5893 | channel[index].flags &= ~IEEE80211_CHAN_NO_80MHZ; |
| 5894 | } else if (ch.bw == BRCMU_CHAN_BW_40) { |
| 5895 | brcmf_update_bw40_channel_flag(&channel[index], &ch); |
| 5896 | } else { |
Arend van Spriel | 58de92d | 2015-04-14 20:10:24 +0200 | [diff] [blame] | 5897 | /* enable the channel and disable other bandwidths |
| 5898 | * for now as mentioned order assure they are enabled |
| 5899 | * for subsequent chanspecs. |
Arend van Spriel | ee942ec | 2014-05-12 10:47:38 +0200 | [diff] [blame] | 5900 | */ |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 5901 | channel[index].flags = IEEE80211_CHAN_NO_HT40 | |
| 5902 | IEEE80211_CHAN_NO_80MHZ; |
| 5903 | ch.bw = BRCMU_CHAN_BW_20; |
| 5904 | cfg->d11inf.encchspec(&ch); |
| 5905 | chaninfo = ch.chspec; |
| 5906 | err = brcmf_fil_bsscfg_int_get(ifp, "per_chan_info", |
| 5907 | &chaninfo); |
| 5908 | if (!err) { |
| 5909 | if (chaninfo & WL_CHAN_RADAR) |
| 5910 | channel[index].flags |= |
| 5911 | (IEEE80211_CHAN_RADAR | |
| 5912 | IEEE80211_CHAN_NO_IR); |
| 5913 | if (chaninfo & WL_CHAN_PASSIVE) |
| 5914 | channel[index].flags |= |
| 5915 | IEEE80211_CHAN_NO_IR; |
Hante Meuleman | d48200b | 2013-04-03 12:40:29 +0200 | [diff] [blame] | 5916 | } |
Hante Meuleman | d48200b | 2013-04-03 12:40:29 +0200 | [diff] [blame] | 5917 | } |
| 5918 | } |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 5919 | |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 5920 | fail_pbuf: |
Hante Meuleman | d48200b | 2013-04-03 12:40:29 +0200 | [diff] [blame] | 5921 | kfree(pbuf); |
| 5922 | return err; |
| 5923 | } |
| 5924 | |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 5925 | static int brcmf_enable_bw40_2g(struct brcmf_cfg80211_info *cfg) |
Arend van Spriel | aa70b4f | 2014-07-12 08:49:40 +0200 | [diff] [blame] | 5926 | { |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 5927 | struct brcmf_if *ifp = netdev_priv(cfg_to_ndev(cfg)); |
| 5928 | struct ieee80211_supported_band *band; |
Arend van Spriel | aa70b4f | 2014-07-12 08:49:40 +0200 | [diff] [blame] | 5929 | struct brcmf_fil_bwcap_le band_bwcap; |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 5930 | struct brcmf_chanspec_list *list; |
| 5931 | u8 *pbuf; |
Arend van Spriel | aa70b4f | 2014-07-12 08:49:40 +0200 | [diff] [blame] | 5932 | u32 val; |
| 5933 | int err; |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 5934 | struct brcmu_chan ch; |
| 5935 | u32 num_chan; |
| 5936 | int i, j; |
Arend van Spriel | aa70b4f | 2014-07-12 08:49:40 +0200 | [diff] [blame] | 5937 | |
| 5938 | /* verify support for bw_cap command */ |
| 5939 | val = WLC_BAND_5G; |
| 5940 | err = brcmf_fil_iovar_int_get(ifp, "bw_cap", &val); |
| 5941 | |
| 5942 | if (!err) { |
| 5943 | /* only set 2G bandwidth using bw_cap command */ |
| 5944 | band_bwcap.band = cpu_to_le32(WLC_BAND_2G); |
| 5945 | band_bwcap.bw_cap = cpu_to_le32(WLC_BW_CAP_40MHZ); |
| 5946 | err = brcmf_fil_iovar_data_set(ifp, "bw_cap", &band_bwcap, |
| 5947 | sizeof(band_bwcap)); |
| 5948 | } else { |
| 5949 | brcmf_dbg(INFO, "fallback to mimo_bw_cap\n"); |
| 5950 | val = WLC_N_BW_40ALL; |
| 5951 | err = brcmf_fil_iovar_int_set(ifp, "mimo_bw_cap", val); |
| 5952 | } |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 5953 | |
| 5954 | if (!err) { |
| 5955 | /* update channel info in 2G band */ |
| 5956 | pbuf = kzalloc(BRCMF_DCMD_MEDLEN, GFP_KERNEL); |
| 5957 | |
| 5958 | if (pbuf == NULL) |
| 5959 | return -ENOMEM; |
| 5960 | |
| 5961 | ch.band = BRCMU_CHAN_BAND_2G; |
| 5962 | ch.bw = BRCMU_CHAN_BW_40; |
Hante Meuleman | fac7d2a | 2014-09-11 22:51:30 +0200 | [diff] [blame] | 5963 | ch.sb = BRCMU_CHAN_SB_NONE; |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 5964 | ch.chnum = 0; |
| 5965 | cfg->d11inf.encchspec(&ch); |
| 5966 | |
| 5967 | /* pass encoded chanspec in query */ |
| 5968 | *(__le16 *)pbuf = cpu_to_le16(ch.chspec); |
| 5969 | |
| 5970 | err = brcmf_fil_iovar_data_get(ifp, "chanspecs", pbuf, |
| 5971 | BRCMF_DCMD_MEDLEN); |
| 5972 | if (err) { |
| 5973 | brcmf_err("get chanspecs error (%d)\n", err); |
| 5974 | kfree(pbuf); |
| 5975 | return err; |
| 5976 | } |
| 5977 | |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 5978 | band = cfg_to_wiphy(cfg)->bands[NL80211_BAND_2GHZ]; |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 5979 | list = (struct brcmf_chanspec_list *)pbuf; |
| 5980 | num_chan = le32_to_cpu(list->count); |
| 5981 | for (i = 0; i < num_chan; i++) { |
| 5982 | ch.chspec = (u16)le32_to_cpu(list->element[i]); |
| 5983 | cfg->d11inf.decchspec(&ch); |
| 5984 | if (WARN_ON(ch.band != BRCMU_CHAN_BAND_2G)) |
| 5985 | continue; |
| 5986 | if (WARN_ON(ch.bw != BRCMU_CHAN_BW_40)) |
| 5987 | continue; |
| 5988 | for (j = 0; j < band->n_channels; j++) { |
Rafał Miłecki | 4712d88 | 2016-05-20 13:38:57 +0200 | [diff] [blame] | 5989 | if (band->channels[j].hw_value == ch.control_ch_num) |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 5990 | break; |
| 5991 | } |
| 5992 | if (WARN_ON(j == band->n_channels)) |
| 5993 | continue; |
| 5994 | |
| 5995 | brcmf_update_bw40_channel_flag(&band->channels[j], &ch); |
| 5996 | } |
Hante Meuleman | fac7d2a | 2014-09-11 22:51:30 +0200 | [diff] [blame] | 5997 | kfree(pbuf); |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 5998 | } |
Arend van Spriel | aa70b4f | 2014-07-12 08:49:40 +0200 | [diff] [blame] | 5999 | return err; |
| 6000 | } |
| 6001 | |
Arend van Spriel | 2375d97 | 2014-01-06 12:40:41 +0100 | [diff] [blame] | 6002 | static void brcmf_get_bwcap(struct brcmf_if *ifp, u32 bw_cap[]) |
| 6003 | { |
| 6004 | u32 band, mimo_bwcap; |
| 6005 | int err; |
| 6006 | |
| 6007 | band = WLC_BAND_2G; |
| 6008 | err = brcmf_fil_iovar_int_get(ifp, "bw_cap", &band); |
| 6009 | if (!err) { |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 6010 | bw_cap[NL80211_BAND_2GHZ] = band; |
Arend van Spriel | 2375d97 | 2014-01-06 12:40:41 +0100 | [diff] [blame] | 6011 | band = WLC_BAND_5G; |
| 6012 | err = brcmf_fil_iovar_int_get(ifp, "bw_cap", &band); |
| 6013 | if (!err) { |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 6014 | bw_cap[NL80211_BAND_5GHZ] = band; |
Arend van Spriel | 2375d97 | 2014-01-06 12:40:41 +0100 | [diff] [blame] | 6015 | return; |
| 6016 | } |
| 6017 | WARN_ON(1); |
| 6018 | return; |
| 6019 | } |
| 6020 | brcmf_dbg(INFO, "fallback to mimo_bw_cap info\n"); |
| 6021 | mimo_bwcap = 0; |
| 6022 | err = brcmf_fil_iovar_int_get(ifp, "mimo_bw_cap", &mimo_bwcap); |
| 6023 | if (err) |
| 6024 | /* assume 20MHz if firmware does not give a clue */ |
| 6025 | mimo_bwcap = WLC_N_BW_20ALL; |
| 6026 | |
| 6027 | switch (mimo_bwcap) { |
| 6028 | case WLC_N_BW_40ALL: |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 6029 | bw_cap[NL80211_BAND_2GHZ] |= WLC_BW_40MHZ_BIT; |
Arend van Spriel | 2375d97 | 2014-01-06 12:40:41 +0100 | [diff] [blame] | 6030 | /* fall-thru */ |
| 6031 | case WLC_N_BW_20IN2G_40IN5G: |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 6032 | bw_cap[NL80211_BAND_5GHZ] |= WLC_BW_40MHZ_BIT; |
Arend van Spriel | 2375d97 | 2014-01-06 12:40:41 +0100 | [diff] [blame] | 6033 | /* fall-thru */ |
| 6034 | case WLC_N_BW_20ALL: |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 6035 | bw_cap[NL80211_BAND_2GHZ] |= WLC_BW_20MHZ_BIT; |
| 6036 | bw_cap[NL80211_BAND_5GHZ] |= WLC_BW_20MHZ_BIT; |
Arend van Spriel | 2375d97 | 2014-01-06 12:40:41 +0100 | [diff] [blame] | 6037 | break; |
| 6038 | default: |
| 6039 | brcmf_err("invalid mimo_bw_cap value\n"); |
| 6040 | } |
| 6041 | } |
Hante Meuleman | d48200b | 2013-04-03 12:40:29 +0200 | [diff] [blame] | 6042 | |
Arend van Spriel | 18d6c53 | 2014-05-12 10:47:35 +0200 | [diff] [blame] | 6043 | static void brcmf_update_ht_cap(struct ieee80211_supported_band *band, |
| 6044 | u32 bw_cap[2], u32 nchain) |
| 6045 | { |
| 6046 | band->ht_cap.ht_supported = true; |
| 6047 | if (bw_cap[band->band] & WLC_BW_40MHZ_BIT) { |
| 6048 | band->ht_cap.cap |= IEEE80211_HT_CAP_SGI_40; |
| 6049 | band->ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40; |
| 6050 | } |
| 6051 | band->ht_cap.cap |= IEEE80211_HT_CAP_SGI_20; |
| 6052 | band->ht_cap.cap |= IEEE80211_HT_CAP_DSSSCCK40; |
| 6053 | band->ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K; |
| 6054 | band->ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_16; |
| 6055 | memset(band->ht_cap.mcs.rx_mask, 0xff, nchain); |
| 6056 | band->ht_cap.mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED; |
| 6057 | } |
| 6058 | |
| 6059 | static __le16 brcmf_get_mcs_map(u32 nchain, enum ieee80211_vht_mcs_support supp) |
| 6060 | { |
| 6061 | u16 mcs_map; |
| 6062 | int i; |
| 6063 | |
| 6064 | for (i = 0, mcs_map = 0xFFFF; i < nchain; i++) |
| 6065 | mcs_map = (mcs_map << 2) | supp; |
| 6066 | |
| 6067 | return cpu_to_le16(mcs_map); |
| 6068 | } |
| 6069 | |
| 6070 | static void brcmf_update_vht_cap(struct ieee80211_supported_band *band, |
Hante Meuleman | 7bf65aa | 2015-11-25 11:32:43 +0100 | [diff] [blame] | 6071 | u32 bw_cap[2], u32 nchain, u32 txstreams, |
| 6072 | u32 txbf_bfe_cap, u32 txbf_bfr_cap) |
Arend van Spriel | 18d6c53 | 2014-05-12 10:47:35 +0200 | [diff] [blame] | 6073 | { |
| 6074 | __le16 mcs_map; |
| 6075 | |
| 6076 | /* not allowed in 2.4G band */ |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 6077 | if (band->band == NL80211_BAND_2GHZ) |
Arend van Spriel | 18d6c53 | 2014-05-12 10:47:35 +0200 | [diff] [blame] | 6078 | return; |
| 6079 | |
| 6080 | band->vht_cap.vht_supported = true; |
| 6081 | /* 80MHz is mandatory */ |
| 6082 | band->vht_cap.cap |= IEEE80211_VHT_CAP_SHORT_GI_80; |
| 6083 | if (bw_cap[band->band] & WLC_BW_160MHZ_BIT) { |
| 6084 | band->vht_cap.cap |= IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ; |
| 6085 | band->vht_cap.cap |= IEEE80211_VHT_CAP_SHORT_GI_160; |
| 6086 | } |
| 6087 | /* all support 256-QAM */ |
| 6088 | mcs_map = brcmf_get_mcs_map(nchain, IEEE80211_VHT_MCS_SUPPORT_0_9); |
| 6089 | band->vht_cap.vht_mcs.rx_mcs_map = mcs_map; |
| 6090 | band->vht_cap.vht_mcs.tx_mcs_map = mcs_map; |
Hante Meuleman | 7bf65aa | 2015-11-25 11:32:43 +0100 | [diff] [blame] | 6091 | |
| 6092 | /* Beamforming support information */ |
| 6093 | if (txbf_bfe_cap & BRCMF_TXBF_SU_BFE_CAP) |
| 6094 | band->vht_cap.cap |= IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE; |
| 6095 | if (txbf_bfe_cap & BRCMF_TXBF_MU_BFE_CAP) |
| 6096 | band->vht_cap.cap |= IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE; |
| 6097 | if (txbf_bfr_cap & BRCMF_TXBF_SU_BFR_CAP) |
| 6098 | band->vht_cap.cap |= IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE; |
| 6099 | if (txbf_bfr_cap & BRCMF_TXBF_MU_BFR_CAP) |
| 6100 | band->vht_cap.cap |= IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE; |
| 6101 | |
| 6102 | if ((txbf_bfe_cap || txbf_bfr_cap) && (txstreams > 1)) { |
| 6103 | band->vht_cap.cap |= |
| 6104 | (2 << IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT); |
| 6105 | band->vht_cap.cap |= ((txstreams - 1) << |
| 6106 | IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT); |
| 6107 | band->vht_cap.cap |= |
| 6108 | IEEE80211_VHT_CAP_VHT_LINK_ADAPTATION_VHT_MRQ_MFB; |
| 6109 | } |
Arend van Spriel | 18d6c53 | 2014-05-12 10:47:35 +0200 | [diff] [blame] | 6110 | } |
| 6111 | |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 6112 | static int brcmf_setup_wiphybands(struct wiphy *wiphy) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 6113 | { |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 6114 | struct brcmf_cfg80211_info *cfg = wiphy_priv(wiphy); |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 6115 | struct brcmf_if *ifp = netdev_priv(cfg_to_ndev(cfg)); |
Arend van Spriel | 18d6c53 | 2014-05-12 10:47:35 +0200 | [diff] [blame] | 6116 | u32 nmode = 0; |
| 6117 | u32 vhtmode = 0; |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 6118 | u32 bw_cap[2] = { WLC_BW_20MHZ_BIT, WLC_BW_20MHZ_BIT }; |
Daniel Kim | 4aca7a1 | 2014-02-25 20:30:36 +0100 | [diff] [blame] | 6119 | u32 rxchain; |
| 6120 | u32 nchain; |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 6121 | int err; |
Hante Meuleman | d48200b | 2013-04-03 12:40:29 +0200 | [diff] [blame] | 6122 | s32 i; |
Arend van Spriel | 2375d97 | 2014-01-06 12:40:41 +0100 | [diff] [blame] | 6123 | struct ieee80211_supported_band *band; |
Hante Meuleman | 7bf65aa | 2015-11-25 11:32:43 +0100 | [diff] [blame] | 6124 | u32 txstreams = 0; |
| 6125 | u32 txbf_bfe_cap = 0; |
| 6126 | u32 txbf_bfr_cap = 0; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 6127 | |
Arend van Spriel | 18d6c53 | 2014-05-12 10:47:35 +0200 | [diff] [blame] | 6128 | (void)brcmf_fil_iovar_int_get(ifp, "vhtmode", &vhtmode); |
Hante Meuleman | d48200b | 2013-04-03 12:40:29 +0200 | [diff] [blame] | 6129 | err = brcmf_fil_iovar_int_get(ifp, "nmode", &nmode); |
| 6130 | if (err) { |
| 6131 | brcmf_err("nmode error (%d)\n", err); |
| 6132 | } else { |
Arend van Spriel | 2375d97 | 2014-01-06 12:40:41 +0100 | [diff] [blame] | 6133 | brcmf_get_bwcap(ifp, bw_cap); |
Hante Meuleman | d48200b | 2013-04-03 12:40:29 +0200 | [diff] [blame] | 6134 | } |
Arend van Spriel | 18d6c53 | 2014-05-12 10:47:35 +0200 | [diff] [blame] | 6135 | brcmf_dbg(INFO, "nmode=%d, vhtmode=%d, bw_cap=(%d, %d)\n", |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 6136 | nmode, vhtmode, bw_cap[NL80211_BAND_2GHZ], |
| 6137 | bw_cap[NL80211_BAND_5GHZ]); |
Hante Meuleman | d48200b | 2013-04-03 12:40:29 +0200 | [diff] [blame] | 6138 | |
Daniel Kim | 4aca7a1 | 2014-02-25 20:30:36 +0100 | [diff] [blame] | 6139 | err = brcmf_fil_iovar_int_get(ifp, "rxchain", &rxchain); |
| 6140 | if (err) { |
| 6141 | brcmf_err("rxchain error (%d)\n", err); |
| 6142 | nchain = 1; |
| 6143 | } else { |
| 6144 | for (nchain = 0; rxchain; nchain++) |
| 6145 | rxchain = rxchain & (rxchain - 1); |
| 6146 | } |
| 6147 | brcmf_dbg(INFO, "nchain=%d\n", nchain); |
| 6148 | |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 6149 | err = brcmf_construct_chaninfo(cfg, bw_cap); |
Hante Meuleman | d48200b | 2013-04-03 12:40:29 +0200 | [diff] [blame] | 6150 | if (err) { |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 6151 | brcmf_err("brcmf_construct_chaninfo failed (%d)\n", err); |
Hante Meuleman | d48200b | 2013-04-03 12:40:29 +0200 | [diff] [blame] | 6152 | return err; |
| 6153 | } |
| 6154 | |
Hante Meuleman | 7bf65aa | 2015-11-25 11:32:43 +0100 | [diff] [blame] | 6155 | if (vhtmode) { |
| 6156 | (void)brcmf_fil_iovar_int_get(ifp, "txstreams", &txstreams); |
| 6157 | (void)brcmf_fil_iovar_int_get(ifp, "txbf_bfe_cap", |
| 6158 | &txbf_bfe_cap); |
| 6159 | (void)brcmf_fil_iovar_int_get(ifp, "txbf_bfr_cap", |
| 6160 | &txbf_bfr_cap); |
| 6161 | } |
| 6162 | |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 6163 | wiphy = cfg_to_wiphy(cfg); |
| 6164 | for (i = 0; i < ARRAY_SIZE(wiphy->bands); i++) { |
| 6165 | band = wiphy->bands[i]; |
| 6166 | if (band == NULL) |
Arend van Spriel | 2375d97 | 2014-01-06 12:40:41 +0100 | [diff] [blame] | 6167 | continue; |
Hante Meuleman | d48200b | 2013-04-03 12:40:29 +0200 | [diff] [blame] | 6168 | |
Arend van Spriel | 18d6c53 | 2014-05-12 10:47:35 +0200 | [diff] [blame] | 6169 | if (nmode) |
| 6170 | brcmf_update_ht_cap(band, bw_cap, nchain); |
| 6171 | if (vhtmode) |
Hante Meuleman | 7bf65aa | 2015-11-25 11:32:43 +0100 | [diff] [blame] | 6172 | brcmf_update_vht_cap(band, bw_cap, nchain, txstreams, |
| 6173 | txbf_bfe_cap, txbf_bfr_cap); |
Hante Meuleman | d48200b | 2013-04-03 12:40:29 +0200 | [diff] [blame] | 6174 | } |
| 6175 | |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 6176 | return 0; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 6177 | } |
| 6178 | |
Arend van Spriel | aa70b4f | 2014-07-12 08:49:40 +0200 | [diff] [blame] | 6179 | static const struct ieee80211_txrx_stypes |
| 6180 | brcmf_txrx_stypes[NUM_NL80211_IFTYPES] = { |
| 6181 | [NL80211_IFTYPE_STATION] = { |
| 6182 | .tx = 0xffff, |
| 6183 | .rx = BIT(IEEE80211_STYPE_ACTION >> 4) | |
| 6184 | BIT(IEEE80211_STYPE_PROBE_REQ >> 4) |
| 6185 | }, |
| 6186 | [NL80211_IFTYPE_P2P_CLIENT] = { |
| 6187 | .tx = 0xffff, |
| 6188 | .rx = BIT(IEEE80211_STYPE_ACTION >> 4) | |
| 6189 | BIT(IEEE80211_STYPE_PROBE_REQ >> 4) |
| 6190 | }, |
| 6191 | [NL80211_IFTYPE_P2P_GO] = { |
| 6192 | .tx = 0xffff, |
| 6193 | .rx = BIT(IEEE80211_STYPE_ASSOC_REQ >> 4) | |
| 6194 | BIT(IEEE80211_STYPE_REASSOC_REQ >> 4) | |
| 6195 | BIT(IEEE80211_STYPE_PROBE_REQ >> 4) | |
| 6196 | BIT(IEEE80211_STYPE_DISASSOC >> 4) | |
| 6197 | BIT(IEEE80211_STYPE_AUTH >> 4) | |
| 6198 | BIT(IEEE80211_STYPE_DEAUTH >> 4) | |
| 6199 | BIT(IEEE80211_STYPE_ACTION >> 4) |
| 6200 | }, |
| 6201 | [NL80211_IFTYPE_P2P_DEVICE] = { |
| 6202 | .tx = 0xffff, |
| 6203 | .rx = BIT(IEEE80211_STYPE_ACTION >> 4) | |
| 6204 | BIT(IEEE80211_STYPE_PROBE_REQ >> 4) |
| 6205 | } |
| 6206 | }; |
| 6207 | |
Arend van Spriel | 0882dda | 2015-08-20 22:06:03 +0200 | [diff] [blame] | 6208 | /** |
| 6209 | * brcmf_setup_ifmodes() - determine interface modes and combinations. |
| 6210 | * |
| 6211 | * @wiphy: wiphy object. |
| 6212 | * @ifp: interface object needed for feat module api. |
| 6213 | * |
| 6214 | * The interface modes and combinations are determined dynamically here |
| 6215 | * based on firmware functionality. |
| 6216 | * |
| 6217 | * no p2p and no mbss: |
| 6218 | * |
| 6219 | * #STA <= 1, #AP <= 1, channels = 1, 2 total |
| 6220 | * |
| 6221 | * no p2p and mbss: |
| 6222 | * |
| 6223 | * #STA <= 1, #AP <= 1, channels = 1, 2 total |
| 6224 | * #AP <= 4, matching BI, channels = 1, 4 total |
| 6225 | * |
| 6226 | * p2p, no mchan, and mbss: |
| 6227 | * |
| 6228 | * #STA <= 1, #P2P-DEV <= 1, #{P2P-CL, P2P-GO} <= 1, channels = 1, 3 total |
| 6229 | * #STA <= 1, #P2P-DEV <= 1, #AP <= 1, #P2P-CL <= 1, channels = 1, 4 total |
| 6230 | * #AP <= 4, matching BI, channels = 1, 4 total |
| 6231 | * |
| 6232 | * p2p, mchan, and mbss: |
| 6233 | * |
| 6234 | * #STA <= 1, #P2P-DEV <= 1, #{P2P-CL, P2P-GO} <= 1, channels = 2, 3 total |
| 6235 | * #STA <= 1, #P2P-DEV <= 1, #AP <= 1, #P2P-CL <= 1, channels = 1, 4 total |
| 6236 | * #AP <= 4, matching BI, channels = 1, 4 total |
| 6237 | */ |
Pontus Fuchs | 2e5f66f | 2015-06-11 00:12:18 +0200 | [diff] [blame] | 6238 | static int brcmf_setup_ifmodes(struct wiphy *wiphy, struct brcmf_if *ifp) |
| 6239 | { |
| 6240 | struct ieee80211_iface_combination *combo = NULL; |
Arend van Spriel | 0882dda | 2015-08-20 22:06:03 +0200 | [diff] [blame] | 6241 | struct ieee80211_iface_limit *c0_limits = NULL; |
| 6242 | struct ieee80211_iface_limit *p2p_limits = NULL; |
| 6243 | struct ieee80211_iface_limit *mbss_limits = NULL; |
| 6244 | bool mbss, p2p; |
| 6245 | int i, c, n_combos; |
Pontus Fuchs | 2e5f66f | 2015-06-11 00:12:18 +0200 | [diff] [blame] | 6246 | |
Arend van Spriel | 0882dda | 2015-08-20 22:06:03 +0200 | [diff] [blame] | 6247 | mbss = brcmf_feat_is_enabled(ifp, BRCMF_FEAT_MBSS); |
| 6248 | p2p = brcmf_feat_is_enabled(ifp, BRCMF_FEAT_P2P); |
| 6249 | |
| 6250 | n_combos = 1 + !!p2p + !!mbss; |
| 6251 | combo = kcalloc(n_combos, sizeof(*combo), GFP_KERNEL); |
Pontus Fuchs | 2e5f66f | 2015-06-11 00:12:18 +0200 | [diff] [blame] | 6252 | if (!combo) |
| 6253 | goto err; |
| 6254 | |
Pontus Fuchs | 2e5f66f | 2015-06-11 00:12:18 +0200 | [diff] [blame] | 6255 | wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) | |
| 6256 | BIT(NL80211_IFTYPE_ADHOC) | |
| 6257 | BIT(NL80211_IFTYPE_AP); |
| 6258 | |
Arend van Spriel | 0882dda | 2015-08-20 22:06:03 +0200 | [diff] [blame] | 6259 | c = 0; |
| 6260 | i = 0; |
Rafał Miłecki | f568ada | 2016-06-07 21:10:18 +0200 | [diff] [blame] | 6261 | c0_limits = kcalloc(p2p ? 3 : 2, sizeof(*c0_limits), GFP_KERNEL); |
| 6262 | if (!c0_limits) |
| 6263 | goto err; |
Arend van Spriel | 0882dda | 2015-08-20 22:06:03 +0200 | [diff] [blame] | 6264 | c0_limits[i].max = 1; |
| 6265 | c0_limits[i++].types = BIT(NL80211_IFTYPE_STATION); |
| 6266 | if (p2p) { |
| 6267 | if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_MCHAN)) |
| 6268 | combo[c].num_different_channels = 2; |
Pontus Fuchs | 2e5f66f | 2015-06-11 00:12:18 +0200 | [diff] [blame] | 6269 | wiphy->interface_modes |= BIT(NL80211_IFTYPE_P2P_CLIENT) | |
| 6270 | BIT(NL80211_IFTYPE_P2P_GO) | |
| 6271 | BIT(NL80211_IFTYPE_P2P_DEVICE); |
Arend van Spriel | 0882dda | 2015-08-20 22:06:03 +0200 | [diff] [blame] | 6272 | c0_limits[i].max = 1; |
| 6273 | c0_limits[i++].types = BIT(NL80211_IFTYPE_P2P_DEVICE); |
| 6274 | c0_limits[i].max = 1; |
| 6275 | c0_limits[i++].types = BIT(NL80211_IFTYPE_P2P_CLIENT) | |
| 6276 | BIT(NL80211_IFTYPE_P2P_GO); |
| 6277 | } else { |
| 6278 | c0_limits[i].max = 1; |
| 6279 | c0_limits[i++].types = BIT(NL80211_IFTYPE_AP); |
Pontus Fuchs | 2e5f66f | 2015-06-11 00:12:18 +0200 | [diff] [blame] | 6280 | } |
Rafał Miłecki | f568ada | 2016-06-07 21:10:18 +0200 | [diff] [blame] | 6281 | combo[c].num_different_channels = 1; |
Arend van Spriel | 0882dda | 2015-08-20 22:06:03 +0200 | [diff] [blame] | 6282 | combo[c].max_interfaces = i; |
| 6283 | combo[c].n_limits = i; |
| 6284 | combo[c].limits = c0_limits; |
Pontus Fuchs | 2e5f66f | 2015-06-11 00:12:18 +0200 | [diff] [blame] | 6285 | |
Arend van Spriel | 0882dda | 2015-08-20 22:06:03 +0200 | [diff] [blame] | 6286 | if (p2p) { |
| 6287 | c++; |
| 6288 | i = 0; |
Rafał Miłecki | f568ada | 2016-06-07 21:10:18 +0200 | [diff] [blame] | 6289 | p2p_limits = kcalloc(4, sizeof(*p2p_limits), GFP_KERNEL); |
| 6290 | if (!p2p_limits) |
| 6291 | goto err; |
Arend van Spriel | 0882dda | 2015-08-20 22:06:03 +0200 | [diff] [blame] | 6292 | p2p_limits[i].max = 1; |
| 6293 | p2p_limits[i++].types = BIT(NL80211_IFTYPE_STATION); |
| 6294 | p2p_limits[i].max = 1; |
| 6295 | p2p_limits[i++].types = BIT(NL80211_IFTYPE_AP); |
| 6296 | p2p_limits[i].max = 1; |
| 6297 | p2p_limits[i++].types = BIT(NL80211_IFTYPE_P2P_CLIENT); |
| 6298 | p2p_limits[i].max = 1; |
| 6299 | p2p_limits[i++].types = BIT(NL80211_IFTYPE_P2P_DEVICE); |
Rafał Miłecki | f568ada | 2016-06-07 21:10:18 +0200 | [diff] [blame] | 6300 | combo[c].num_different_channels = 1; |
Arend van Spriel | 0882dda | 2015-08-20 22:06:03 +0200 | [diff] [blame] | 6301 | combo[c].max_interfaces = i; |
| 6302 | combo[c].n_limits = i; |
| 6303 | combo[c].limits = p2p_limits; |
| 6304 | } |
| 6305 | |
| 6306 | if (mbss) { |
| 6307 | c++; |
Rafał Miłecki | f568ada | 2016-06-07 21:10:18 +0200 | [diff] [blame] | 6308 | i = 0; |
| 6309 | mbss_limits = kcalloc(1, sizeof(*mbss_limits), GFP_KERNEL); |
| 6310 | if (!mbss_limits) |
| 6311 | goto err; |
| 6312 | mbss_limits[i].max = 4; |
| 6313 | mbss_limits[i++].types = BIT(NL80211_IFTYPE_AP); |
Arend van Spriel | 0882dda | 2015-08-20 22:06:03 +0200 | [diff] [blame] | 6314 | combo[c].beacon_int_infra_match = true; |
| 6315 | combo[c].num_different_channels = 1; |
Arend van Spriel | 0882dda | 2015-08-20 22:06:03 +0200 | [diff] [blame] | 6316 | combo[c].max_interfaces = 4; |
Rafał Miłecki | f568ada | 2016-06-07 21:10:18 +0200 | [diff] [blame] | 6317 | combo[c].n_limits = i; |
Arend van Spriel | 0882dda | 2015-08-20 22:06:03 +0200 | [diff] [blame] | 6318 | combo[c].limits = mbss_limits; |
| 6319 | } |
Rafał Miłecki | f568ada | 2016-06-07 21:10:18 +0200 | [diff] [blame] | 6320 | |
Arend van Spriel | 0882dda | 2015-08-20 22:06:03 +0200 | [diff] [blame] | 6321 | wiphy->n_iface_combinations = n_combos; |
Pontus Fuchs | 2e5f66f | 2015-06-11 00:12:18 +0200 | [diff] [blame] | 6322 | wiphy->iface_combinations = combo; |
Pontus Fuchs | 2e5f66f | 2015-06-11 00:12:18 +0200 | [diff] [blame] | 6323 | return 0; |
| 6324 | |
| 6325 | err: |
Arend van Spriel | 0882dda | 2015-08-20 22:06:03 +0200 | [diff] [blame] | 6326 | kfree(c0_limits); |
| 6327 | kfree(p2p_limits); |
| 6328 | kfree(mbss_limits); |
Pontus Fuchs | 2e5f66f | 2015-06-11 00:12:18 +0200 | [diff] [blame] | 6329 | kfree(combo); |
| 6330 | return -ENOMEM; |
| 6331 | } |
| 6332 | |
Arend van Spriel | aa70b4f | 2014-07-12 08:49:40 +0200 | [diff] [blame] | 6333 | static void brcmf_wiphy_pno_params(struct wiphy *wiphy) |
| 6334 | { |
| 6335 | /* scheduled scan settings */ |
| 6336 | wiphy->max_sched_scan_ssids = BRCMF_PNO_MAX_PFN_COUNT; |
| 6337 | wiphy->max_match_sets = BRCMF_PNO_MAX_PFN_COUNT; |
| 6338 | wiphy->max_sched_scan_ie_len = BRCMF_SCAN_IE_LEN_MAX; |
Arend Van Spriel | c6989fd | 2016-11-23 10:25:30 +0000 | [diff] [blame] | 6339 | wiphy->max_sched_scan_plan_interval = BRCMF_PNO_SCHED_SCAN_MAX_PERIOD; |
Arend van Spriel | aa70b4f | 2014-07-12 08:49:40 +0200 | [diff] [blame] | 6340 | wiphy->flags |= WIPHY_FLAG_SUPPORTS_SCHED_SCAN; |
| 6341 | } |
| 6342 | |
Hante Meuleman | 4eb3af7 | 2014-09-30 10:23:18 +0200 | [diff] [blame] | 6343 | #ifdef CONFIG_PM |
Hante Meuleman | 3021ad9 | 2016-01-05 11:05:45 +0100 | [diff] [blame] | 6344 | static struct wiphy_wowlan_support brcmf_wowlan_support = { |
Hante Meuleman | 4eb3af7 | 2014-09-30 10:23:18 +0200 | [diff] [blame] | 6345 | .flags = WIPHY_WOWLAN_MAGIC_PKT | WIPHY_WOWLAN_DISCONNECT, |
Hante Meuleman | b9a82f8 | 2014-10-28 14:56:06 +0100 | [diff] [blame] | 6346 | .n_patterns = BRCMF_WOWL_MAXPATTERNS, |
| 6347 | .pattern_max_len = BRCMF_WOWL_MAXPATTERNSIZE, |
| 6348 | .pattern_min_len = 1, |
| 6349 | .max_pkt_offset = 1500, |
Hante Meuleman | 4eb3af7 | 2014-09-30 10:23:18 +0200 | [diff] [blame] | 6350 | }; |
| 6351 | #endif |
| 6352 | |
Hante Meuleman | 3021ad9 | 2016-01-05 11:05:45 +0100 | [diff] [blame] | 6353 | static void brcmf_wiphy_wowl_params(struct wiphy *wiphy, struct brcmf_if *ifp) |
Hante Meuleman | 4eb3af7 | 2014-09-30 10:23:18 +0200 | [diff] [blame] | 6354 | { |
| 6355 | #ifdef CONFIG_PM |
Hante Meuleman | 3021ad9 | 2016-01-05 11:05:45 +0100 | [diff] [blame] | 6356 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); |
Hante Meuleman | 3021ad9 | 2016-01-05 11:05:45 +0100 | [diff] [blame] | 6357 | |
| 6358 | if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_PNO)) { |
Hante Meuleman | 5c22fb8 | 2016-02-17 11:27:03 +0100 | [diff] [blame] | 6359 | if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_WOWL_ND)) { |
| 6360 | brcmf_wowlan_support.flags |= WIPHY_WOWLAN_NET_DETECT; |
| 6361 | init_waitqueue_head(&cfg->wowl.nd_data_wait); |
Hante Meuleman | 3021ad9 | 2016-01-05 11:05:45 +0100 | [diff] [blame] | 6362 | } |
| 6363 | } |
Hante Meuleman | 5c22fb8 | 2016-02-17 11:27:03 +0100 | [diff] [blame] | 6364 | if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_WOWL_GTK)) { |
| 6365 | brcmf_wowlan_support.flags |= WIPHY_WOWLAN_SUPPORTS_GTK_REKEY; |
| 6366 | brcmf_wowlan_support.flags |= WIPHY_WOWLAN_GTK_REKEY_FAILURE; |
| 6367 | } |
| 6368 | |
Hante Meuleman | 4eb3af7 | 2014-09-30 10:23:18 +0200 | [diff] [blame] | 6369 | wiphy->wowlan = &brcmf_wowlan_support; |
| 6370 | #endif |
| 6371 | } |
| 6372 | |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 6373 | static int brcmf_setup_wiphy(struct wiphy *wiphy, struct brcmf_if *ifp) |
Arend van Spriel | aa70b4f | 2014-07-12 08:49:40 +0200 | [diff] [blame] | 6374 | { |
Rafa? Mi?ecki | e3faa86 | 2015-07-09 17:07:08 +0200 | [diff] [blame] | 6375 | struct brcmf_pub *drvr = ifp->drvr; |
Rafał Miłecki | 50f32e2 | 2015-08-20 00:16:42 +0200 | [diff] [blame] | 6376 | const struct ieee80211_iface_combination *combo; |
Arend van Spriel | 58de92d | 2015-04-14 20:10:24 +0200 | [diff] [blame] | 6377 | struct ieee80211_supported_band *band; |
Rafał Miłecki | 50f32e2 | 2015-08-20 00:16:42 +0200 | [diff] [blame] | 6378 | u16 max_interfaces = 0; |
Arend van Spriel | 58de92d | 2015-04-14 20:10:24 +0200 | [diff] [blame] | 6379 | __le32 bandlist[3]; |
| 6380 | u32 n_bands; |
| 6381 | int err, i; |
| 6382 | |
Arend van Spriel | aa70b4f | 2014-07-12 08:49:40 +0200 | [diff] [blame] | 6383 | wiphy->max_scan_ssids = WL_NUM_SCAN_MAX; |
| 6384 | wiphy->max_scan_ie_len = BRCMF_SCAN_IE_LEN_MAX; |
Hante Meuleman | 6c404f3 | 2015-12-10 13:43:03 +0100 | [diff] [blame] | 6385 | wiphy->max_num_pmkids = BRCMF_MAXPMKID; |
Pontus Fuchs | 2e5f66f | 2015-06-11 00:12:18 +0200 | [diff] [blame] | 6386 | |
| 6387 | err = brcmf_setup_ifmodes(wiphy, ifp); |
| 6388 | if (err) |
| 6389 | return err; |
| 6390 | |
Rafał Miłecki | 50f32e2 | 2015-08-20 00:16:42 +0200 | [diff] [blame] | 6391 | for (i = 0, combo = wiphy->iface_combinations; |
| 6392 | i < wiphy->n_iface_combinations; i++, combo++) { |
| 6393 | max_interfaces = max(max_interfaces, combo->max_interfaces); |
| 6394 | } |
| 6395 | |
| 6396 | for (i = 0; i < max_interfaces && i < ARRAY_SIZE(drvr->addresses); |
| 6397 | i++) { |
Rafa? Mi?ecki | e3faa86 | 2015-07-09 17:07:08 +0200 | [diff] [blame] | 6398 | u8 *addr = drvr->addresses[i].addr; |
| 6399 | |
| 6400 | memcpy(addr, drvr->mac, ETH_ALEN); |
| 6401 | if (i) { |
| 6402 | addr[0] |= BIT(1); |
| 6403 | addr[ETH_ALEN - 1] ^= i; |
| 6404 | } |
| 6405 | } |
| 6406 | wiphy->addresses = drvr->addresses; |
| 6407 | wiphy->n_addresses = i; |
| 6408 | |
Arend van Spriel | aa70b4f | 2014-07-12 08:49:40 +0200 | [diff] [blame] | 6409 | wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM; |
Hante Meuleman | 240d61a | 2016-02-17 11:27:10 +0100 | [diff] [blame] | 6410 | wiphy->cipher_suites = brcmf_cipher_suites; |
| 6411 | wiphy->n_cipher_suites = ARRAY_SIZE(brcmf_cipher_suites); |
| 6412 | if (!brcmf_feat_is_enabled(ifp, BRCMF_FEAT_MFP)) |
| 6413 | wiphy->n_cipher_suites--; |
Arend van Spriel | 7705ba6 | 2016-04-17 16:44:58 +0200 | [diff] [blame] | 6414 | wiphy->bss_select_support = BIT(NL80211_BSS_SELECT_ATTR_RSSI) | |
| 6415 | BIT(NL80211_BSS_SELECT_ATTR_BAND_PREF) | |
| 6416 | BIT(NL80211_BSS_SELECT_ATTR_RSSI_ADJUST); |
| 6417 | |
Arend van Spriel | aa70b4f | 2014-07-12 08:49:40 +0200 | [diff] [blame] | 6418 | wiphy->flags |= WIPHY_FLAG_PS_ON_BY_DEFAULT | |
| 6419 | WIPHY_FLAG_OFFCHAN_TX | |
Hante Meuleman | a7b82d4 | 2015-12-10 13:43:04 +0100 | [diff] [blame] | 6420 | WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL; |
| 6421 | if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_TDLS)) |
| 6422 | wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS; |
Hante Meuleman | 7d34b05 | 2016-01-02 09:41:41 +0100 | [diff] [blame] | 6423 | if (!ifp->drvr->settings->roamoff) |
Arend van Spriel | aa70b4f | 2014-07-12 08:49:40 +0200 | [diff] [blame] | 6424 | wiphy->flags |= WIPHY_FLAG_SUPPORTS_FW_ROAM; |
| 6425 | wiphy->mgmt_stypes = brcmf_txrx_stypes; |
| 6426 | wiphy->max_remain_on_channel_duration = 5000; |
Arend van Spriel | 7a7a87d | 2015-04-14 20:10:27 +0200 | [diff] [blame] | 6427 | if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_PNO)) |
| 6428 | brcmf_wiphy_pno_params(wiphy); |
Arend van Spriel | aa70b4f | 2014-07-12 08:49:40 +0200 | [diff] [blame] | 6429 | |
| 6430 | /* vendor commands/events support */ |
| 6431 | wiphy->vendor_commands = brcmf_vendor_cmds; |
| 6432 | wiphy->n_vendor_commands = BRCMF_VNDR_CMDS_LAST - 1; |
| 6433 | |
Hante Meuleman | 4eb3af7 | 2014-09-30 10:23:18 +0200 | [diff] [blame] | 6434 | if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_WOWL)) |
Hante Meuleman | 3021ad9 | 2016-01-05 11:05:45 +0100 | [diff] [blame] | 6435 | brcmf_wiphy_wowl_params(wiphy, ifp); |
Arend van Spriel | 58de92d | 2015-04-14 20:10:24 +0200 | [diff] [blame] | 6436 | err = brcmf_fil_cmd_data_get(ifp, BRCMF_C_GET_BANDLIST, &bandlist, |
| 6437 | sizeof(bandlist)); |
| 6438 | if (err) { |
| 6439 | brcmf_err("could not obtain band info: err=%d\n", err); |
| 6440 | return err; |
| 6441 | } |
| 6442 | /* first entry in bandlist is number of bands */ |
| 6443 | n_bands = le32_to_cpu(bandlist[0]); |
| 6444 | for (i = 1; i <= n_bands && i < ARRAY_SIZE(bandlist); i++) { |
| 6445 | if (bandlist[i] == cpu_to_le32(WLC_BAND_2G)) { |
| 6446 | band = kmemdup(&__wl_band_2ghz, sizeof(__wl_band_2ghz), |
| 6447 | GFP_KERNEL); |
| 6448 | if (!band) |
| 6449 | return -ENOMEM; |
| 6450 | |
| 6451 | band->channels = kmemdup(&__wl_2ghz_channels, |
| 6452 | sizeof(__wl_2ghz_channels), |
| 6453 | GFP_KERNEL); |
| 6454 | if (!band->channels) { |
| 6455 | kfree(band); |
| 6456 | return -ENOMEM; |
| 6457 | } |
| 6458 | |
| 6459 | band->n_channels = ARRAY_SIZE(__wl_2ghz_channels); |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 6460 | wiphy->bands[NL80211_BAND_2GHZ] = band; |
Arend van Spriel | 58de92d | 2015-04-14 20:10:24 +0200 | [diff] [blame] | 6461 | } |
| 6462 | if (bandlist[i] == cpu_to_le32(WLC_BAND_5G)) { |
| 6463 | band = kmemdup(&__wl_band_5ghz, sizeof(__wl_band_5ghz), |
| 6464 | GFP_KERNEL); |
| 6465 | if (!band) |
| 6466 | return -ENOMEM; |
| 6467 | |
| 6468 | band->channels = kmemdup(&__wl_5ghz_channels, |
| 6469 | sizeof(__wl_5ghz_channels), |
| 6470 | GFP_KERNEL); |
| 6471 | if (!band->channels) { |
| 6472 | kfree(band); |
| 6473 | return -ENOMEM; |
| 6474 | } |
| 6475 | |
| 6476 | band->n_channels = ARRAY_SIZE(__wl_5ghz_channels); |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 6477 | wiphy->bands[NL80211_BAND_5GHZ] = band; |
Arend van Spriel | 58de92d | 2015-04-14 20:10:24 +0200 | [diff] [blame] | 6478 | } |
| 6479 | } |
| 6480 | err = brcmf_setup_wiphybands(wiphy); |
| 6481 | return err; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 6482 | } |
| 6483 | |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 6484 | static s32 brcmf_config_dongle(struct brcmf_cfg80211_info *cfg) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 6485 | { |
| 6486 | struct net_device *ndev; |
| 6487 | struct wireless_dev *wdev; |
Hante Meuleman | 40a2329 | 2013-01-02 15:22:51 +0100 | [diff] [blame] | 6488 | struct brcmf_if *ifp; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 6489 | s32 power_mode; |
| 6490 | s32 err = 0; |
| 6491 | |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 6492 | if (cfg->dongle_up) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 6493 | return err; |
| 6494 | |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 6495 | ndev = cfg_to_ndev(cfg); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 6496 | wdev = ndev->ieee80211_ptr; |
Hante Meuleman | 40a2329 | 2013-01-02 15:22:51 +0100 | [diff] [blame] | 6497 | ifp = netdev_priv(ndev); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 6498 | |
Hante Meuleman | 40a2329 | 2013-01-02 15:22:51 +0100 | [diff] [blame] | 6499 | /* make sure RF is ready for work */ |
| 6500 | brcmf_fil_cmd_int_set(ifp, BRCMF_C_UP, 0); |
| 6501 | |
Hante Meuleman | 1678ba8 | 2015-12-10 13:43:00 +0100 | [diff] [blame] | 6502 | brcmf_dongle_scantime(ifp); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 6503 | |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 6504 | power_mode = cfg->pwr_save ? PM_FAST : PM_OFF; |
Hante Meuleman | 40a2329 | 2013-01-02 15:22:51 +0100 | [diff] [blame] | 6505 | err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_PM, power_mode); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 6506 | if (err) |
| 6507 | goto default_conf_out; |
Arend van Spriel | 647c9ae | 2012-12-05 15:26:01 +0100 | [diff] [blame] | 6508 | brcmf_dbg(INFO, "power save set to %s\n", |
| 6509 | (power_mode ? "enabled" : "disabled")); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 6510 | |
Hante Meuleman | 1119e23 | 2015-11-25 11:32:42 +0100 | [diff] [blame] | 6511 | err = brcmf_dongle_roam(ifp); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 6512 | if (err) |
| 6513 | goto default_conf_out; |
Franky Lin | 5dd161f | 2012-10-10 11:13:10 -0700 | [diff] [blame] | 6514 | err = brcmf_cfg80211_change_iface(wdev->wiphy, ndev, wdev->iftype, |
| 6515 | NULL, NULL); |
Hante Meuleman | 40a2329 | 2013-01-02 15:22:51 +0100 | [diff] [blame] | 6516 | if (err) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 6517 | goto default_conf_out; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 6518 | |
Franky Lin | 52f22fb | 2016-02-17 11:26:55 +0100 | [diff] [blame] | 6519 | brcmf_configure_arp_nd_offload(ifp, true); |
Hante Meuleman | b365745 | 2013-05-27 21:09:53 +0200 | [diff] [blame] | 6520 | |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 6521 | cfg->dongle_up = true; |
Hante Meuleman | 40a2329 | 2013-01-02 15:22:51 +0100 | [diff] [blame] | 6522 | default_conf_out: |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 6523 | |
| 6524 | return err; |
| 6525 | |
| 6526 | } |
| 6527 | |
Arend van Spriel | bdf5ff5 | 2012-11-14 18:46:09 -0800 | [diff] [blame] | 6528 | static s32 __brcmf_cfg80211_up(struct brcmf_if *ifp) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 6529 | { |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 6530 | set_bit(BRCMF_VIF_STATUS_READY, &ifp->vif->sme_state); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 6531 | |
Arend van Spriel | bdf5ff5 | 2012-11-14 18:46:09 -0800 | [diff] [blame] | 6532 | return brcmf_config_dongle(ifp->drvr->config); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 6533 | } |
| 6534 | |
Arend van Spriel | bdf5ff5 | 2012-11-14 18:46:09 -0800 | [diff] [blame] | 6535 | static s32 __brcmf_cfg80211_down(struct brcmf_if *ifp) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 6536 | { |
Arend van Spriel | bdf5ff5 | 2012-11-14 18:46:09 -0800 | [diff] [blame] | 6537 | struct brcmf_cfg80211_info *cfg = ifp->drvr->config; |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 6538 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 6539 | /* |
| 6540 | * While going down, if associated with AP disassociate |
| 6541 | * from AP to save power |
| 6542 | */ |
Arend van Spriel | 903e0ee | 2012-11-28 21:44:11 +0100 | [diff] [blame] | 6543 | if (check_vif_up(ifp->vif)) { |
Arend van Spriel | 9b7a0dd | 2015-01-25 20:31:33 +0100 | [diff] [blame] | 6544 | brcmf_link_down(ifp->vif, WLAN_REASON_UNSPECIFIED); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 6545 | |
| 6546 | /* Make sure WPA_Supplicant receives all the event |
| 6547 | generated due to DISASSOC call to the fw to keep |
| 6548 | the state fw and WPA_Supplicant state consistent |
| 6549 | */ |
| 6550 | brcmf_delay(500); |
| 6551 | } |
| 6552 | |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 6553 | brcmf_abort_scanning(cfg); |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 6554 | clear_bit(BRCMF_VIF_STATUS_READY, &ifp->vif->sme_state); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 6555 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 6556 | return 0; |
| 6557 | } |
| 6558 | |
Arend van Spriel | bdf5ff5 | 2012-11-14 18:46:09 -0800 | [diff] [blame] | 6559 | s32 brcmf_cfg80211_up(struct net_device *ndev) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 6560 | { |
Arend van Spriel | bdf5ff5 | 2012-11-14 18:46:09 -0800 | [diff] [blame] | 6561 | struct brcmf_if *ifp = netdev_priv(ndev); |
| 6562 | struct brcmf_cfg80211_info *cfg = ifp->drvr->config; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 6563 | s32 err = 0; |
| 6564 | |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 6565 | mutex_lock(&cfg->usr_sync); |
Arend van Spriel | bdf5ff5 | 2012-11-14 18:46:09 -0800 | [diff] [blame] | 6566 | err = __brcmf_cfg80211_up(ifp); |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 6567 | mutex_unlock(&cfg->usr_sync); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 6568 | |
| 6569 | return err; |
| 6570 | } |
| 6571 | |
Arend van Spriel | bdf5ff5 | 2012-11-14 18:46:09 -0800 | [diff] [blame] | 6572 | s32 brcmf_cfg80211_down(struct net_device *ndev) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 6573 | { |
Arend van Spriel | bdf5ff5 | 2012-11-14 18:46:09 -0800 | [diff] [blame] | 6574 | struct brcmf_if *ifp = netdev_priv(ndev); |
| 6575 | struct brcmf_cfg80211_info *cfg = ifp->drvr->config; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 6576 | s32 err = 0; |
| 6577 | |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 6578 | mutex_lock(&cfg->usr_sync); |
Arend van Spriel | bdf5ff5 | 2012-11-14 18:46:09 -0800 | [diff] [blame] | 6579 | err = __brcmf_cfg80211_down(ifp); |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 6580 | mutex_unlock(&cfg->usr_sync); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 6581 | |
| 6582 | return err; |
| 6583 | } |
| 6584 | |
Arend van Spriel | a7965fb | 2013-04-11 17:08:37 +0200 | [diff] [blame] | 6585 | enum nl80211_iftype brcmf_cfg80211_get_iftype(struct brcmf_if *ifp) |
| 6586 | { |
| 6587 | struct wireless_dev *wdev = &ifp->vif->wdev; |
| 6588 | |
| 6589 | return wdev->iftype; |
| 6590 | } |
| 6591 | |
Hante Meuleman | bfe8197 | 2014-10-28 14:56:16 +0100 | [diff] [blame] | 6592 | bool brcmf_get_vif_state_any(struct brcmf_cfg80211_info *cfg, |
| 6593 | unsigned long state) |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 6594 | { |
| 6595 | struct brcmf_cfg80211_vif *vif; |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 6596 | |
| 6597 | list_for_each_entry(vif, &cfg->vif_list, list) { |
| 6598 | if (test_bit(state, &vif->sme_state)) |
Rasmus Villemoes | e843bb1 | 2014-06-22 20:50:40 +0200 | [diff] [blame] | 6599 | return true; |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 6600 | } |
Rasmus Villemoes | e843bb1 | 2014-06-22 20:50:40 +0200 | [diff] [blame] | 6601 | return false; |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 6602 | } |
Arend van Spriel | d3c0b63 | 2013-02-08 15:53:37 +0100 | [diff] [blame] | 6603 | |
| 6604 | static inline bool vif_event_equals(struct brcmf_cfg80211_vif_event *event, |
| 6605 | u8 action) |
| 6606 | { |
| 6607 | u8 evt_action; |
| 6608 | |
mhiramat@kernel.org | b64abcb | 2016-08-15 18:41:12 +0900 | [diff] [blame] | 6609 | spin_lock(&event->vif_event_lock); |
Arend van Spriel | d3c0b63 | 2013-02-08 15:53:37 +0100 | [diff] [blame] | 6610 | evt_action = event->action; |
mhiramat@kernel.org | b64abcb | 2016-08-15 18:41:12 +0900 | [diff] [blame] | 6611 | spin_unlock(&event->vif_event_lock); |
Arend van Spriel | d3c0b63 | 2013-02-08 15:53:37 +0100 | [diff] [blame] | 6612 | return evt_action == action; |
| 6613 | } |
| 6614 | |
| 6615 | void brcmf_cfg80211_arm_vif_event(struct brcmf_cfg80211_info *cfg, |
| 6616 | struct brcmf_cfg80211_vif *vif) |
| 6617 | { |
| 6618 | struct brcmf_cfg80211_vif_event *event = &cfg->vif_event; |
| 6619 | |
mhiramat@kernel.org | b64abcb | 2016-08-15 18:41:12 +0900 | [diff] [blame] | 6620 | spin_lock(&event->vif_event_lock); |
Arend van Spriel | d3c0b63 | 2013-02-08 15:53:37 +0100 | [diff] [blame] | 6621 | event->vif = vif; |
| 6622 | event->action = 0; |
mhiramat@kernel.org | b64abcb | 2016-08-15 18:41:12 +0900 | [diff] [blame] | 6623 | spin_unlock(&event->vif_event_lock); |
Arend van Spriel | d3c0b63 | 2013-02-08 15:53:37 +0100 | [diff] [blame] | 6624 | } |
| 6625 | |
| 6626 | bool brcmf_cfg80211_vif_event_armed(struct brcmf_cfg80211_info *cfg) |
| 6627 | { |
| 6628 | struct brcmf_cfg80211_vif_event *event = &cfg->vif_event; |
| 6629 | bool armed; |
| 6630 | |
mhiramat@kernel.org | b64abcb | 2016-08-15 18:41:12 +0900 | [diff] [blame] | 6631 | spin_lock(&event->vif_event_lock); |
Arend van Spriel | d3c0b63 | 2013-02-08 15:53:37 +0100 | [diff] [blame] | 6632 | armed = event->vif != NULL; |
mhiramat@kernel.org | b64abcb | 2016-08-15 18:41:12 +0900 | [diff] [blame] | 6633 | spin_unlock(&event->vif_event_lock); |
Arend van Spriel | d3c0b63 | 2013-02-08 15:53:37 +0100 | [diff] [blame] | 6634 | |
| 6635 | return armed; |
| 6636 | } |
Arend van Spriel | a9eb0c4 | 2016-02-17 11:26:50 +0100 | [diff] [blame] | 6637 | |
| 6638 | int brcmf_cfg80211_wait_vif_event(struct brcmf_cfg80211_info *cfg, |
| 6639 | u8 action, ulong timeout) |
Arend van Spriel | d3c0b63 | 2013-02-08 15:53:37 +0100 | [diff] [blame] | 6640 | { |
| 6641 | struct brcmf_cfg80211_vif_event *event = &cfg->vif_event; |
| 6642 | |
| 6643 | return wait_event_timeout(event->vif_wq, |
| 6644 | vif_event_equals(event, action), timeout); |
| 6645 | } |
| 6646 | |
Hante Meuleman | 73345fd | 2016-02-17 11:26:53 +0100 | [diff] [blame] | 6647 | static s32 brcmf_translate_country_code(struct brcmf_pub *drvr, char alpha2[2], |
| 6648 | struct brcmf_fil_country_le *ccreq) |
| 6649 | { |
Hante Meuleman | 4d79289 | 2016-02-17 11:27:07 +0100 | [diff] [blame] | 6650 | struct brcmfmac_pd_cc *country_codes; |
| 6651 | struct brcmfmac_pd_cc_entry *cc; |
Hante Meuleman | 73345fd | 2016-02-17 11:26:53 +0100 | [diff] [blame] | 6652 | s32 found_index; |
| 6653 | int i; |
| 6654 | |
| 6655 | country_codes = drvr->settings->country_codes; |
| 6656 | if (!country_codes) { |
| 6657 | brcmf_dbg(TRACE, "No country codes configured for device\n"); |
| 6658 | return -EINVAL; |
| 6659 | } |
| 6660 | |
| 6661 | if ((alpha2[0] == ccreq->country_abbrev[0]) && |
| 6662 | (alpha2[1] == ccreq->country_abbrev[1])) { |
| 6663 | brcmf_dbg(TRACE, "Country code already set\n"); |
| 6664 | return -EAGAIN; |
| 6665 | } |
| 6666 | |
| 6667 | found_index = -1; |
| 6668 | for (i = 0; i < country_codes->table_size; i++) { |
| 6669 | cc = &country_codes->table[i]; |
| 6670 | if ((cc->iso3166[0] == '\0') && (found_index == -1)) |
| 6671 | found_index = i; |
| 6672 | if ((cc->iso3166[0] == alpha2[0]) && |
| 6673 | (cc->iso3166[1] == alpha2[1])) { |
| 6674 | found_index = i; |
| 6675 | break; |
| 6676 | } |
| 6677 | } |
| 6678 | if (found_index == -1) { |
| 6679 | brcmf_dbg(TRACE, "No country code match found\n"); |
| 6680 | return -EINVAL; |
| 6681 | } |
| 6682 | memset(ccreq, 0, sizeof(*ccreq)); |
| 6683 | ccreq->rev = cpu_to_le32(country_codes->table[found_index].rev); |
| 6684 | memcpy(ccreq->ccode, country_codes->table[found_index].cc, |
| 6685 | BRCMF_COUNTRY_BUF_SZ); |
| 6686 | ccreq->country_abbrev[0] = alpha2[0]; |
| 6687 | ccreq->country_abbrev[1] = alpha2[1]; |
| 6688 | ccreq->country_abbrev[2] = 0; |
| 6689 | |
| 6690 | return 0; |
| 6691 | } |
| 6692 | |
Arend van Spriel | 63db1a4 | 2014-12-21 12:43:51 +0100 | [diff] [blame] | 6693 | static void brcmf_cfg80211_reg_notifier(struct wiphy *wiphy, |
| 6694 | struct regulatory_request *req) |
| 6695 | { |
| 6696 | struct brcmf_cfg80211_info *cfg = wiphy_priv(wiphy); |
| 6697 | struct brcmf_if *ifp = netdev_priv(cfg_to_ndev(cfg)); |
| 6698 | struct brcmf_fil_country_le ccreq; |
Hante Meuleman | 73345fd | 2016-02-17 11:26:53 +0100 | [diff] [blame] | 6699 | s32 err; |
Arend van Spriel | 63db1a4 | 2014-12-21 12:43:51 +0100 | [diff] [blame] | 6700 | int i; |
| 6701 | |
Arend van Spriel | 63db1a4 | 2014-12-21 12:43:51 +0100 | [diff] [blame] | 6702 | /* ignore non-ISO3166 country codes */ |
| 6703 | for (i = 0; i < sizeof(req->alpha2); i++) |
| 6704 | if (req->alpha2[i] < 'A' || req->alpha2[i] > 'Z') { |
Hante Meuleman | 73345fd | 2016-02-17 11:26:53 +0100 | [diff] [blame] | 6705 | brcmf_err("not a ISO3166 code (0x%02x 0x%02x)\n", |
| 6706 | req->alpha2[0], req->alpha2[1]); |
Arend van Spriel | 63db1a4 | 2014-12-21 12:43:51 +0100 | [diff] [blame] | 6707 | return; |
| 6708 | } |
Hante Meuleman | 73345fd | 2016-02-17 11:26:53 +0100 | [diff] [blame] | 6709 | |
| 6710 | brcmf_dbg(TRACE, "Enter: initiator=%d, alpha=%c%c\n", req->initiator, |
| 6711 | req->alpha2[0], req->alpha2[1]); |
| 6712 | |
| 6713 | err = brcmf_fil_iovar_data_get(ifp, "country", &ccreq, sizeof(ccreq)); |
| 6714 | if (err) { |
| 6715 | brcmf_err("Country code iovar returned err = %d\n", err); |
| 6716 | return; |
| 6717 | } |
| 6718 | |
| 6719 | err = brcmf_translate_country_code(ifp->drvr, req->alpha2, &ccreq); |
| 6720 | if (err) |
| 6721 | return; |
| 6722 | |
| 6723 | err = brcmf_fil_iovar_data_set(ifp, "country", &ccreq, sizeof(ccreq)); |
| 6724 | if (err) { |
| 6725 | brcmf_err("Firmware rejected country setting\n"); |
Arend van Spriel | 8afe0ec | 2015-04-14 20:10:25 +0200 | [diff] [blame] | 6726 | return; |
| 6727 | } |
| 6728 | brcmf_setup_wiphybands(wiphy); |
Arend van Spriel | 63db1a4 | 2014-12-21 12:43:51 +0100 | [diff] [blame] | 6729 | } |
| 6730 | |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 6731 | static void brcmf_free_wiphy(struct wiphy *wiphy) |
| 6732 | { |
Arend van Spriel | 0882dda | 2015-08-20 22:06:03 +0200 | [diff] [blame] | 6733 | int i; |
| 6734 | |
Arend van Spriel | 58de92d | 2015-04-14 20:10:24 +0200 | [diff] [blame] | 6735 | if (!wiphy) |
| 6736 | return; |
| 6737 | |
Arend van Spriel | 0882dda | 2015-08-20 22:06:03 +0200 | [diff] [blame] | 6738 | if (wiphy->iface_combinations) { |
| 6739 | for (i = 0; i < wiphy->n_iface_combinations; i++) |
| 6740 | kfree(wiphy->iface_combinations[i].limits); |
| 6741 | } |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 6742 | kfree(wiphy->iface_combinations); |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 6743 | if (wiphy->bands[NL80211_BAND_2GHZ]) { |
| 6744 | kfree(wiphy->bands[NL80211_BAND_2GHZ]->channels); |
| 6745 | kfree(wiphy->bands[NL80211_BAND_2GHZ]); |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 6746 | } |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 6747 | if (wiphy->bands[NL80211_BAND_5GHZ]) { |
| 6748 | kfree(wiphy->bands[NL80211_BAND_5GHZ]->channels); |
| 6749 | kfree(wiphy->bands[NL80211_BAND_5GHZ]); |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 6750 | } |
| 6751 | wiphy_free(wiphy); |
| 6752 | } |
| 6753 | |
Arend van Spriel | ccfd1e8 | 2014-07-12 08:49:38 +0200 | [diff] [blame] | 6754 | struct brcmf_cfg80211_info *brcmf_cfg80211_attach(struct brcmf_pub *drvr, |
Hante Meuleman | ae7c03f | 2015-09-18 22:08:08 +0200 | [diff] [blame] | 6755 | struct device *busdev, |
| 6756 | bool p2pdev_forced) |
Arend van Spriel | ccfd1e8 | 2014-07-12 08:49:38 +0200 | [diff] [blame] | 6757 | { |
Arend van Spriel | 46f3b6e | 2015-08-26 22:14:58 +0200 | [diff] [blame] | 6758 | struct net_device *ndev = brcmf_get_ifp(drvr, 0)->ndev; |
Arend van Spriel | ccfd1e8 | 2014-07-12 08:49:38 +0200 | [diff] [blame] | 6759 | struct brcmf_cfg80211_info *cfg; |
| 6760 | struct wiphy *wiphy; |
Hante Meuleman | 5c22fb8 | 2016-02-17 11:27:03 +0100 | [diff] [blame] | 6761 | struct cfg80211_ops *ops; |
Arend van Spriel | ccfd1e8 | 2014-07-12 08:49:38 +0200 | [diff] [blame] | 6762 | struct brcmf_cfg80211_vif *vif; |
| 6763 | struct brcmf_if *ifp; |
| 6764 | s32 err = 0; |
| 6765 | s32 io_type; |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 6766 | u16 *cap = NULL; |
Arend van Spriel | ccfd1e8 | 2014-07-12 08:49:38 +0200 | [diff] [blame] | 6767 | |
| 6768 | if (!ndev) { |
| 6769 | brcmf_err("ndev is invalid\n"); |
| 6770 | return NULL; |
| 6771 | } |
| 6772 | |
Muhammad Falak R Wani | d464fd8 | 2016-05-19 19:29:03 +0530 | [diff] [blame] | 6773 | ops = kmemdup(&brcmf_cfg80211_ops, sizeof(*ops), GFP_KERNEL); |
Hante Meuleman | 5c22fb8 | 2016-02-17 11:27:03 +0100 | [diff] [blame] | 6774 | if (!ops) |
| 6775 | return NULL; |
| 6776 | |
Arend van Spriel | ccfd1e8 | 2014-07-12 08:49:38 +0200 | [diff] [blame] | 6777 | ifp = netdev_priv(ndev); |
Hante Meuleman | 5c22fb8 | 2016-02-17 11:27:03 +0100 | [diff] [blame] | 6778 | #ifdef CONFIG_PM |
| 6779 | if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_WOWL_GTK)) |
| 6780 | ops->set_rekey_data = brcmf_cfg80211_set_rekey_data; |
| 6781 | #endif |
| 6782 | wiphy = wiphy_new(ops, sizeof(struct brcmf_cfg80211_info)); |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 6783 | if (!wiphy) { |
| 6784 | brcmf_err("Could not allocate wiphy device\n"); |
Arend van Spriel | ccfd1e8 | 2014-07-12 08:49:38 +0200 | [diff] [blame] | 6785 | return NULL; |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 6786 | } |
Rafał Miłecki | 6896f4f | 2015-05-31 02:52:26 +0200 | [diff] [blame] | 6787 | memcpy(wiphy->perm_addr, drvr->mac, ETH_ALEN); |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 6788 | set_wiphy_dev(wiphy, busdev); |
Arend van Spriel | ccfd1e8 | 2014-07-12 08:49:38 +0200 | [diff] [blame] | 6789 | |
| 6790 | cfg = wiphy_priv(wiphy); |
| 6791 | cfg->wiphy = wiphy; |
Hante Meuleman | 5c22fb8 | 2016-02-17 11:27:03 +0100 | [diff] [blame] | 6792 | cfg->ops = ops; |
Arend van Spriel | ccfd1e8 | 2014-07-12 08:49:38 +0200 | [diff] [blame] | 6793 | cfg->pub = drvr; |
| 6794 | init_vif_event(&cfg->vif_event); |
| 6795 | INIT_LIST_HEAD(&cfg->vif_list); |
| 6796 | |
Rafał Miłecki | 2607233 | 2016-06-06 23:03:55 +0200 | [diff] [blame] | 6797 | vif = brcmf_alloc_vif(cfg, NL80211_IFTYPE_STATION); |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 6798 | if (IS_ERR(vif)) |
| 6799 | goto wiphy_out; |
Arend van Spriel | ccfd1e8 | 2014-07-12 08:49:38 +0200 | [diff] [blame] | 6800 | |
| 6801 | vif->ifp = ifp; |
| 6802 | vif->wdev.netdev = ndev; |
| 6803 | ndev->ieee80211_ptr = &vif->wdev; |
| 6804 | SET_NETDEV_DEV(ndev, wiphy_dev(cfg->wiphy)); |
| 6805 | |
| 6806 | err = wl_init_priv(cfg); |
| 6807 | if (err) { |
| 6808 | brcmf_err("Failed to init iwm_priv (%d)\n", err); |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 6809 | brcmf_free_vif(vif); |
| 6810 | goto wiphy_out; |
Arend van Spriel | ccfd1e8 | 2014-07-12 08:49:38 +0200 | [diff] [blame] | 6811 | } |
| 6812 | ifp->vif = vif; |
| 6813 | |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 6814 | /* determine d11 io type before wiphy setup */ |
| 6815 | err = brcmf_fil_cmd_int_get(ifp, BRCMF_C_GET_VERSION, &io_type); |
Arend van Spriel | ccfd1e8 | 2014-07-12 08:49:38 +0200 | [diff] [blame] | 6816 | if (err) { |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 6817 | brcmf_err("Failed to get D11 version (%d)\n", err); |
| 6818 | goto priv_out; |
Arend van Spriel | ccfd1e8 | 2014-07-12 08:49:38 +0200 | [diff] [blame] | 6819 | } |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 6820 | cfg->d11inf.io_type = (u8)io_type; |
| 6821 | brcmu_d11_attach(&cfg->d11inf); |
| 6822 | |
| 6823 | err = brcmf_setup_wiphy(wiphy, ifp); |
| 6824 | if (err < 0) |
| 6825 | goto priv_out; |
| 6826 | |
| 6827 | brcmf_dbg(INFO, "Registering custom regulatory\n"); |
Arend van Spriel | 63db1a4 | 2014-12-21 12:43:51 +0100 | [diff] [blame] | 6828 | wiphy->reg_notifier = brcmf_cfg80211_reg_notifier; |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 6829 | wiphy->regulatory_flags |= REGULATORY_CUSTOM_REG; |
| 6830 | wiphy_apply_custom_regulatory(wiphy, &brcmf_regdom); |
| 6831 | |
| 6832 | /* firmware defaults to 40MHz disabled in 2G band. We signal |
| 6833 | * cfg80211 here that we do and have it decide we can enable |
| 6834 | * it. But first check if device does support 2G operation. |
| 6835 | */ |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 6836 | if (wiphy->bands[NL80211_BAND_2GHZ]) { |
| 6837 | cap = &wiphy->bands[NL80211_BAND_2GHZ]->ht_cap.cap; |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 6838 | *cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40; |
| 6839 | } |
| 6840 | err = wiphy_register(wiphy); |
| 6841 | if (err < 0) { |
| 6842 | brcmf_err("Could not register wiphy device (%d)\n", err); |
| 6843 | goto priv_out; |
Arend van Spriel | ccfd1e8 | 2014-07-12 08:49:38 +0200 | [diff] [blame] | 6844 | } |
| 6845 | |
| 6846 | /* If cfg80211 didn't disable 40MHz HT CAP in wiphy_register(), |
| 6847 | * setup 40MHz in 2GHz band and enable OBSS scanning. |
| 6848 | */ |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 6849 | if (cap && (*cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40)) { |
| 6850 | err = brcmf_enable_bw40_2g(cfg); |
Arend van Spriel | ccfd1e8 | 2014-07-12 08:49:38 +0200 | [diff] [blame] | 6851 | if (!err) |
| 6852 | err = brcmf_fil_iovar_int_set(ifp, "obss_coex", |
| 6853 | BRCMF_OBSS_COEX_AUTO); |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 6854 | else |
| 6855 | *cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40; |
Arend van Spriel | ccfd1e8 | 2014-07-12 08:49:38 +0200 | [diff] [blame] | 6856 | } |
Hante Meuleman | 2b76acd | 2015-10-08 20:33:15 +0200 | [diff] [blame] | 6857 | /* p2p might require that "if-events" get processed by fweh. So |
| 6858 | * activate the already registered event handlers now and activate |
| 6859 | * the rest when initialization has completed. drvr->config needs to |
| 6860 | * be assigned before activating events. |
| 6861 | */ |
| 6862 | drvr->config = cfg; |
| 6863 | err = brcmf_fweh_activate_events(ifp); |
| 6864 | if (err) { |
| 6865 | brcmf_err("FWEH activation failed (%d)\n", err); |
| 6866 | goto wiphy_unreg_out; |
| 6867 | } |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 6868 | |
Hante Meuleman | ae7c03f | 2015-09-18 22:08:08 +0200 | [diff] [blame] | 6869 | err = brcmf_p2p_attach(cfg, p2pdev_forced); |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 6870 | if (err) { |
| 6871 | brcmf_err("P2P initilisation failed (%d)\n", err); |
| 6872 | goto wiphy_unreg_out; |
| 6873 | } |
| 6874 | err = brcmf_btcoex_attach(cfg); |
| 6875 | if (err) { |
| 6876 | brcmf_err("BT-coex initialisation failed (%d)\n", err); |
| 6877 | brcmf_p2p_detach(&cfg->p2p); |
| 6878 | goto wiphy_unreg_out; |
| 6879 | } |
Arend van Spriel | ccfd1e8 | 2014-07-12 08:49:38 +0200 | [diff] [blame] | 6880 | |
Hante Meuleman | a7b82d4 | 2015-12-10 13:43:04 +0100 | [diff] [blame] | 6881 | if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_TDLS)) { |
| 6882 | err = brcmf_fil_iovar_int_set(ifp, "tdls_enable", 1); |
| 6883 | if (err) { |
| 6884 | brcmf_dbg(INFO, "TDLS not enabled (%d)\n", err); |
| 6885 | wiphy->flags &= ~WIPHY_FLAG_SUPPORTS_TDLS; |
| 6886 | } else { |
| 6887 | brcmf_fweh_register(cfg->pub, BRCMF_E_TDLS_PEER_EVENT, |
| 6888 | brcmf_notify_tdls_peer_event); |
| 6889 | } |
Arend van Spriel | ccfd1e8 | 2014-07-12 08:49:38 +0200 | [diff] [blame] | 6890 | } |
| 6891 | |
Hante Meuleman | 2b76acd | 2015-10-08 20:33:15 +0200 | [diff] [blame] | 6892 | /* (re-) activate FWEH event handling */ |
| 6893 | err = brcmf_fweh_activate_events(ifp); |
| 6894 | if (err) { |
| 6895 | brcmf_err("FWEH activation failed (%d)\n", err); |
| 6896 | goto wiphy_unreg_out; |
| 6897 | } |
| 6898 | |
Hante Meuleman | 48ed16e | 2016-01-02 09:41:38 +0100 | [diff] [blame] | 6899 | /* Fill in some of the advertised nl80211 supported features */ |
| 6900 | if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_SCAN_RANDOM_MAC)) { |
| 6901 | wiphy->features |= NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR; |
| 6902 | #ifdef CONFIG_PM |
Franky Lin | 6ea0915 | 2016-02-17 11:26:52 +0100 | [diff] [blame] | 6903 | if (wiphy->wowlan && |
| 6904 | wiphy->wowlan->flags & WIPHY_WOWLAN_NET_DETECT) |
Hante Meuleman | 48ed16e | 2016-01-02 09:41:38 +0100 | [diff] [blame] | 6905 | wiphy->features |= NL80211_FEATURE_ND_RANDOM_MAC_ADDR; |
| 6906 | #endif |
| 6907 | } |
| 6908 | |
Arend van Spriel | ccfd1e8 | 2014-07-12 08:49:38 +0200 | [diff] [blame] | 6909 | return cfg; |
| 6910 | |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 6911 | wiphy_unreg_out: |
| 6912 | wiphy_unregister(cfg->wiphy); |
| 6913 | priv_out: |
Arend van Spriel | ccfd1e8 | 2014-07-12 08:49:38 +0200 | [diff] [blame] | 6914 | wl_deinit_priv(cfg); |
Arend van Spriel | ccfd1e8 | 2014-07-12 08:49:38 +0200 | [diff] [blame] | 6915 | brcmf_free_vif(vif); |
Hante Meuleman | 2b5d348 | 2015-09-18 22:08:04 +0200 | [diff] [blame] | 6916 | ifp->vif = NULL; |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 6917 | wiphy_out: |
| 6918 | brcmf_free_wiphy(wiphy); |
Hante Meuleman | 5c22fb8 | 2016-02-17 11:27:03 +0100 | [diff] [blame] | 6919 | kfree(ops); |
Arend van Spriel | ccfd1e8 | 2014-07-12 08:49:38 +0200 | [diff] [blame] | 6920 | return NULL; |
| 6921 | } |
| 6922 | |
| 6923 | void brcmf_cfg80211_detach(struct brcmf_cfg80211_info *cfg) |
| 6924 | { |
| 6925 | if (!cfg) |
| 6926 | return; |
| 6927 | |
Arend van Spriel | ccfd1e8 | 2014-07-12 08:49:38 +0200 | [diff] [blame] | 6928 | brcmf_btcoex_detach(cfg); |
Arend van Spriel | f7a4087 | 2015-06-11 00:12:23 +0200 | [diff] [blame] | 6929 | wiphy_unregister(cfg->wiphy); |
Hante Meuleman | 5c22fb8 | 2016-02-17 11:27:03 +0100 | [diff] [blame] | 6930 | kfree(cfg->ops); |
Arend van Spriel | ccfd1e8 | 2014-07-12 08:49:38 +0200 | [diff] [blame] | 6931 | wl_deinit_priv(cfg); |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 6932 | brcmf_free_wiphy(cfg->wiphy); |
Arend van Spriel | ccfd1e8 | 2014-07-12 08:49:38 +0200 | [diff] [blame] | 6933 | } |