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), \ |
Arend van Spriel | 58de92d | 2015-04-14 20:10:24 +0200 | [diff] [blame] | 141 | .max_antenna_gain = 0, \ |
| 142 | .max_power = 30, \ |
| 143 | } |
| 144 | |
| 145 | #define CHAN5G(_channel) { \ |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 146 | .band = NL80211_BAND_5GHZ, \ |
Arend van Spriel | 58de92d | 2015-04-14 20:10:24 +0200 | [diff] [blame] | 147 | .center_freq = 5000 + (5 * (_channel)), \ |
| 148 | .hw_value = (_channel), \ |
Arend van Spriel | 58de92d | 2015-04-14 20:10:24 +0200 | [diff] [blame] | 149 | .max_antenna_gain = 0, \ |
| 150 | .max_power = 30, \ |
| 151 | } |
| 152 | |
| 153 | static struct ieee80211_channel __wl_2ghz_channels[] = { |
| 154 | CHAN2G(1, 2412), CHAN2G(2, 2417), CHAN2G(3, 2422), CHAN2G(4, 2427), |
| 155 | CHAN2G(5, 2432), CHAN2G(6, 2437), CHAN2G(7, 2442), CHAN2G(8, 2447), |
| 156 | CHAN2G(9, 2452), CHAN2G(10, 2457), CHAN2G(11, 2462), CHAN2G(12, 2467), |
| 157 | CHAN2G(13, 2472), CHAN2G(14, 2484) |
| 158 | }; |
| 159 | |
| 160 | static struct ieee80211_channel __wl_5ghz_channels[] = { |
| 161 | CHAN5G(34), CHAN5G(36), CHAN5G(38), CHAN5G(40), CHAN5G(42), |
| 162 | CHAN5G(44), CHAN5G(46), CHAN5G(48), CHAN5G(52), CHAN5G(56), |
| 163 | CHAN5G(60), CHAN5G(64), CHAN5G(100), CHAN5G(104), CHAN5G(108), |
| 164 | CHAN5G(112), CHAN5G(116), CHAN5G(120), CHAN5G(124), CHAN5G(128), |
| 165 | CHAN5G(132), CHAN5G(136), CHAN5G(140), CHAN5G(144), CHAN5G(149), |
| 166 | CHAN5G(153), CHAN5G(157), CHAN5G(161), CHAN5G(165) |
| 167 | }; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 168 | |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 169 | /* Band templates duplicated per wiphy. The channel info |
Arend van Spriel | 58de92d | 2015-04-14 20:10:24 +0200 | [diff] [blame] | 170 | * above is added to the band during setup. |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 171 | */ |
| 172 | static const struct ieee80211_supported_band __wl_band_2ghz = { |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 173 | .band = NL80211_BAND_2GHZ, |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 174 | .bitrates = wl_g_rates, |
| 175 | .n_bitrates = wl_g_rates_size, |
| 176 | }; |
| 177 | |
Arend van Spriel | 58de92d | 2015-04-14 20:10:24 +0200 | [diff] [blame] | 178 | static const struct ieee80211_supported_band __wl_band_5ghz = { |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 179 | .band = NL80211_BAND_5GHZ, |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 180 | .bitrates = wl_a_rates, |
| 181 | .n_bitrates = wl_a_rates_size, |
| 182 | }; |
| 183 | |
Hante Meuleman | d48200b | 2013-04-03 12:40:29 +0200 | [diff] [blame] | 184 | /* This is to override regulatory domains defined in cfg80211 module (reg.c) |
| 185 | * 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] | 186 | * NL80211_RRF_NO_IR for 5GHz channels (for * 36..48 and 149..165). |
| 187 | * With respect to these flags, wpa_supplicant doesn't * start p2p |
| 188 | * operations on 5GHz channels. All the changes in world regulatory |
Hante Meuleman | d48200b | 2013-04-03 12:40:29 +0200 | [diff] [blame] | 189 | * domain are to be done here. |
| 190 | */ |
| 191 | static const struct ieee80211_regdomain brcmf_regdom = { |
| 192 | .n_reg_rules = 4, |
| 193 | .alpha2 = "99", |
| 194 | .reg_rules = { |
| 195 | /* IEEE 802.11b/g, channels 1..11 */ |
| 196 | REG_RULE(2412-10, 2472+10, 40, 6, 20, 0), |
| 197 | /* If any */ |
| 198 | /* IEEE 802.11 channel 14 - Only JP enables |
| 199 | * this and for 802.11b only |
| 200 | */ |
| 201 | REG_RULE(2484-10, 2484+10, 20, 6, 20, 0), |
| 202 | /* IEEE 802.11a, channel 36..64 */ |
Arend van Spriel | c555ecd | 2014-05-12 10:47:36 +0200 | [diff] [blame] | 203 | REG_RULE(5150-10, 5350+10, 80, 6, 20, 0), |
Hante Meuleman | d48200b | 2013-04-03 12:40:29 +0200 | [diff] [blame] | 204 | /* IEEE 802.11a, channel 100..165 */ |
Arend van Spriel | c555ecd | 2014-05-12 10:47:36 +0200 | [diff] [blame] | 205 | REG_RULE(5470-10, 5850+10, 80, 6, 20, 0), } |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 206 | }; |
| 207 | |
Hante Meuleman | 240d61a | 2016-02-17 11:27:10 +0100 | [diff] [blame] | 208 | /* Note: brcmf_cipher_suites is an array of int defining which cipher suites |
| 209 | * are supported. A pointer to this array and the number of entries is passed |
| 210 | * on to upper layers. AES_CMAC defines whether or not the driver supports MFP. |
| 211 | * So the cipher suite AES_CMAC has to be the last one in the array, and when |
| 212 | * device does not support MFP then the number of suites will be decreased by 1 |
| 213 | */ |
| 214 | static const u32 brcmf_cipher_suites[] = { |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 215 | WLAN_CIPHER_SUITE_WEP40, |
| 216 | WLAN_CIPHER_SUITE_WEP104, |
| 217 | WLAN_CIPHER_SUITE_TKIP, |
| 218 | WLAN_CIPHER_SUITE_CCMP, |
Hante Meuleman | 240d61a | 2016-02-17 11:27:10 +0100 | [diff] [blame] | 219 | /* Keep as last entry: */ |
| 220 | WLAN_CIPHER_SUITE_AES_CMAC |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 221 | }; |
| 222 | |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 223 | /* Vendor specific ie. id = 221, oui and type defines exact ie */ |
| 224 | struct brcmf_vs_tlv { |
| 225 | u8 id; |
| 226 | u8 len; |
| 227 | u8 oui[3]; |
| 228 | u8 oui_type; |
| 229 | }; |
| 230 | |
| 231 | struct parsed_vndr_ie_info { |
| 232 | u8 *ie_ptr; |
| 233 | u32 ie_len; /* total length including id & length field */ |
| 234 | struct brcmf_vs_tlv vndrie; |
| 235 | }; |
| 236 | |
| 237 | struct parsed_vndr_ies { |
| 238 | u32 count; |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 239 | struct parsed_vndr_ie_info ie_info[VNDR_IE_PARSE_LIMIT]; |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 240 | }; |
| 241 | |
Arend van Spriel | 7705ba6 | 2016-04-17 16:44:58 +0200 | [diff] [blame] | 242 | static u8 nl80211_band_to_fwil(enum nl80211_band band) |
| 243 | { |
| 244 | switch (band) { |
| 245 | case NL80211_BAND_2GHZ: |
| 246 | return WLC_BAND_2G; |
| 247 | case NL80211_BAND_5GHZ: |
| 248 | return WLC_BAND_5G; |
| 249 | default: |
| 250 | WARN_ON(1); |
| 251 | break; |
| 252 | } |
| 253 | return 0; |
| 254 | } |
| 255 | |
Arend van Spriel | 5a394eb | 2014-05-27 12:56:15 +0200 | [diff] [blame] | 256 | static u16 chandef_to_chanspec(struct brcmu_d11inf *d11inf, |
| 257 | struct cfg80211_chan_def *ch) |
Arend van Spriel | 600a897 | 2014-05-12 10:47:39 +0200 | [diff] [blame] | 258 | { |
| 259 | struct brcmu_chan ch_inf; |
| 260 | s32 primary_offset; |
| 261 | |
| 262 | brcmf_dbg(TRACE, "chandef: control %d center %d width %d\n", |
| 263 | ch->chan->center_freq, ch->center_freq1, ch->width); |
| 264 | ch_inf.chnum = ieee80211_frequency_to_channel(ch->center_freq1); |
Rafał Miłecki | 36e8072 | 2016-01-20 16:46:04 +0100 | [diff] [blame] | 265 | primary_offset = ch->chan->center_freq - ch->center_freq1; |
Arend van Spriel | 600a897 | 2014-05-12 10:47:39 +0200 | [diff] [blame] | 266 | switch (ch->width) { |
| 267 | case NL80211_CHAN_WIDTH_20: |
Arend van Spriel | 0cd75b1 | 2014-11-11 13:58:44 +0100 | [diff] [blame] | 268 | case NL80211_CHAN_WIDTH_20_NOHT: |
Arend van Spriel | 600a897 | 2014-05-12 10:47:39 +0200 | [diff] [blame] | 269 | ch_inf.bw = BRCMU_CHAN_BW_20; |
| 270 | WARN_ON(primary_offset != 0); |
| 271 | break; |
| 272 | case NL80211_CHAN_WIDTH_40: |
| 273 | ch_inf.bw = BRCMU_CHAN_BW_40; |
Rafał Miłecki | 36e8072 | 2016-01-20 16:46:04 +0100 | [diff] [blame] | 274 | if (primary_offset > 0) |
Arend van Spriel | 600a897 | 2014-05-12 10:47:39 +0200 | [diff] [blame] | 275 | ch_inf.sb = BRCMU_CHAN_SB_U; |
| 276 | else |
| 277 | ch_inf.sb = BRCMU_CHAN_SB_L; |
| 278 | break; |
| 279 | case NL80211_CHAN_WIDTH_80: |
| 280 | ch_inf.bw = BRCMU_CHAN_BW_80; |
Rafał Miłecki | 36e8072 | 2016-01-20 16:46:04 +0100 | [diff] [blame] | 281 | if (primary_offset == -30) |
| 282 | ch_inf.sb = BRCMU_CHAN_SB_LL; |
| 283 | else if (primary_offset == -10) |
| 284 | ch_inf.sb = BRCMU_CHAN_SB_LU; |
| 285 | else if (primary_offset == 10) |
| 286 | ch_inf.sb = BRCMU_CHAN_SB_UL; |
| 287 | else |
| 288 | ch_inf.sb = BRCMU_CHAN_SB_UU; |
Arend van Spriel | 600a897 | 2014-05-12 10:47:39 +0200 | [diff] [blame] | 289 | break; |
Arend van Spriel | 0cd75b1 | 2014-11-11 13:58:44 +0100 | [diff] [blame] | 290 | case NL80211_CHAN_WIDTH_80P80: |
| 291 | case NL80211_CHAN_WIDTH_160: |
| 292 | case NL80211_CHAN_WIDTH_5: |
| 293 | case NL80211_CHAN_WIDTH_10: |
Arend van Spriel | 600a897 | 2014-05-12 10:47:39 +0200 | [diff] [blame] | 294 | default: |
| 295 | WARN_ON_ONCE(1); |
| 296 | } |
| 297 | switch (ch->chan->band) { |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 298 | case NL80211_BAND_2GHZ: |
Arend van Spriel | 600a897 | 2014-05-12 10:47:39 +0200 | [diff] [blame] | 299 | ch_inf.band = BRCMU_CHAN_BAND_2G; |
| 300 | break; |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 301 | case NL80211_BAND_5GHZ: |
Arend van Spriel | 600a897 | 2014-05-12 10:47:39 +0200 | [diff] [blame] | 302 | ch_inf.band = BRCMU_CHAN_BAND_5G; |
| 303 | break; |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 304 | case NL80211_BAND_60GHZ: |
Arend van Spriel | 600a897 | 2014-05-12 10:47:39 +0200 | [diff] [blame] | 305 | default: |
| 306 | WARN_ON_ONCE(1); |
| 307 | } |
| 308 | d11inf->encchspec(&ch_inf); |
| 309 | |
| 310 | return ch_inf.chspec; |
| 311 | } |
| 312 | |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 313 | u16 channel_to_chanspec(struct brcmu_d11inf *d11inf, |
| 314 | struct ieee80211_channel *ch) |
Arend van Spriel | 6e18616 | 2012-10-22 10:36:22 -0700 | [diff] [blame] | 315 | { |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 316 | struct brcmu_chan ch_inf; |
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 | ch_inf.chnum = ieee80211_frequency_to_channel(ch->center_freq); |
| 319 | ch_inf.bw = BRCMU_CHAN_BW_20; |
| 320 | d11inf->encchspec(&ch_inf); |
Arend van Spriel | 6e18616 | 2012-10-22 10:36:22 -0700 | [diff] [blame] | 321 | |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 322 | return ch_inf.chspec; |
Arend van Spriel | 6e18616 | 2012-10-22 10:36:22 -0700 | [diff] [blame] | 323 | } |
| 324 | |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 325 | /* Traverse a string of 1-byte tag/1-byte length/variable-length value |
| 326 | * triples, returning a pointer to the substring whose first element |
| 327 | * matches tag |
| 328 | */ |
Rafał Miłecki | c8d8707 | 2017-01-18 11:48:51 +0100 | [diff] [blame] | 329 | static const struct brcmf_tlv * |
Johannes Berg | 4b5800f | 2014-01-15 14:55:59 +0100 | [diff] [blame] | 330 | brcmf_parse_tlvs(const void *buf, int buflen, uint key) |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 331 | { |
Johannes Berg | 4b5800f | 2014-01-15 14:55:59 +0100 | [diff] [blame] | 332 | const struct brcmf_tlv *elt = buf; |
| 333 | int totlen = buflen; |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 334 | |
| 335 | /* find tagged parameter */ |
| 336 | while (totlen >= TLV_HDR_LEN) { |
| 337 | int len = elt->len; |
| 338 | |
| 339 | /* validate remaining totlen */ |
| 340 | if ((elt->id == key) && (totlen >= (len + TLV_HDR_LEN))) |
| 341 | return elt; |
| 342 | |
| 343 | elt = (struct brcmf_tlv *)((u8 *)elt + (len + TLV_HDR_LEN)); |
| 344 | totlen -= (len + TLV_HDR_LEN); |
| 345 | } |
| 346 | |
| 347 | return NULL; |
| 348 | } |
| 349 | |
| 350 | /* Is any of the tlvs the expected entry? If |
| 351 | * not update the tlvs buffer pointer/length. |
| 352 | */ |
| 353 | static bool |
Johannes Berg | 4b5800f | 2014-01-15 14:55:59 +0100 | [diff] [blame] | 354 | brcmf_tlv_has_ie(const u8 *ie, const u8 **tlvs, u32 *tlvs_len, |
| 355 | const u8 *oui, u32 oui_len, u8 type) |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 356 | { |
| 357 | /* If the contents match the OUI and the type */ |
| 358 | if (ie[TLV_LEN_OFF] >= oui_len + 1 && |
| 359 | !memcmp(&ie[TLV_BODY_OFF], oui, oui_len) && |
| 360 | type == ie[TLV_BODY_OFF + oui_len]) { |
| 361 | return true; |
| 362 | } |
| 363 | |
| 364 | if (tlvs == NULL) |
| 365 | return false; |
| 366 | /* point to the next ie */ |
| 367 | ie += ie[TLV_LEN_OFF] + TLV_HDR_LEN; |
| 368 | /* calculate the length of the rest of the buffer */ |
| 369 | *tlvs_len -= (int)(ie - *tlvs); |
| 370 | /* update the pointer to the start of the buffer */ |
| 371 | *tlvs = ie; |
| 372 | |
| 373 | return false; |
| 374 | } |
| 375 | |
| 376 | static struct brcmf_vs_tlv * |
Johannes Berg | 4b5800f | 2014-01-15 14:55:59 +0100 | [diff] [blame] | 377 | brcmf_find_wpaie(const u8 *parse, u32 len) |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 378 | { |
Johannes Berg | 4b5800f | 2014-01-15 14:55:59 +0100 | [diff] [blame] | 379 | const struct brcmf_tlv *ie; |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 380 | |
| 381 | while ((ie = brcmf_parse_tlvs(parse, len, WLAN_EID_VENDOR_SPECIFIC))) { |
Johannes Berg | 4b5800f | 2014-01-15 14:55:59 +0100 | [diff] [blame] | 382 | if (brcmf_tlv_has_ie((const u8 *)ie, &parse, &len, |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 383 | WPA_OUI, TLV_OUI_LEN, WPA_OUI_TYPE)) |
| 384 | return (struct brcmf_vs_tlv *)ie; |
| 385 | } |
| 386 | return NULL; |
| 387 | } |
| 388 | |
| 389 | static struct brcmf_vs_tlv * |
Johannes Berg | 4b5800f | 2014-01-15 14:55:59 +0100 | [diff] [blame] | 390 | brcmf_find_wpsie(const u8 *parse, u32 len) |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 391 | { |
Johannes Berg | 4b5800f | 2014-01-15 14:55:59 +0100 | [diff] [blame] | 392 | const struct brcmf_tlv *ie; |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 393 | |
| 394 | while ((ie = brcmf_parse_tlvs(parse, len, WLAN_EID_VENDOR_SPECIFIC))) { |
| 395 | if (brcmf_tlv_has_ie((u8 *)ie, &parse, &len, |
| 396 | WPA_OUI, TLV_OUI_LEN, WPS_OUI_TYPE)) |
| 397 | return (struct brcmf_vs_tlv *)ie; |
| 398 | } |
| 399 | return NULL; |
| 400 | } |
| 401 | |
Arend van Spriel | 39504a2 | 2015-08-20 22:06:05 +0200 | [diff] [blame] | 402 | static int brcmf_vif_change_validate(struct brcmf_cfg80211_info *cfg, |
| 403 | struct brcmf_cfg80211_vif *vif, |
| 404 | enum nl80211_iftype new_type) |
| 405 | { |
Arend van Spriel | 39504a2 | 2015-08-20 22:06:05 +0200 | [diff] [blame] | 406 | struct brcmf_cfg80211_vif *pos; |
Arend van Spriel | 353c46a | 2015-12-10 13:43:06 +0100 | [diff] [blame] | 407 | bool check_combos = false; |
| 408 | int ret = 0; |
Purushottam Kushwaha | e227300 | 2016-10-12 18:25:35 +0530 | [diff] [blame] | 409 | struct iface_combination_params params = { |
| 410 | .num_different_channels = 1, |
| 411 | }; |
Arend van Spriel | 39504a2 | 2015-08-20 22:06:05 +0200 | [diff] [blame] | 412 | |
Arend van Spriel | 39504a2 | 2015-08-20 22:06:05 +0200 | [diff] [blame] | 413 | list_for_each_entry(pos, &cfg->vif_list, list) |
Arend van Spriel | 353c46a | 2015-12-10 13:43:06 +0100 | [diff] [blame] | 414 | if (pos == vif) { |
Purushottam Kushwaha | e227300 | 2016-10-12 18:25:35 +0530 | [diff] [blame] | 415 | params.iftype_num[new_type]++; |
Arend van Spriel | 353c46a | 2015-12-10 13:43:06 +0100 | [diff] [blame] | 416 | } else { |
| 417 | /* concurrent interfaces so need check combinations */ |
| 418 | check_combos = true; |
Purushottam Kushwaha | e227300 | 2016-10-12 18:25:35 +0530 | [diff] [blame] | 419 | params.iftype_num[pos->wdev.iftype]++; |
Arend van Spriel | 353c46a | 2015-12-10 13:43:06 +0100 | [diff] [blame] | 420 | } |
Arend van Spriel | 39504a2 | 2015-08-20 22:06:05 +0200 | [diff] [blame] | 421 | |
Arend van Spriel | 353c46a | 2015-12-10 13:43:06 +0100 | [diff] [blame] | 422 | if (check_combos) |
Purushottam Kushwaha | e227300 | 2016-10-12 18:25:35 +0530 | [diff] [blame] | 423 | ret = cfg80211_check_combinations(cfg->wiphy, ¶ms); |
Arend van Spriel | 353c46a | 2015-12-10 13:43:06 +0100 | [diff] [blame] | 424 | |
| 425 | return ret; |
Arend van Spriel | 39504a2 | 2015-08-20 22:06:05 +0200 | [diff] [blame] | 426 | } |
| 427 | |
| 428 | static int brcmf_vif_add_validate(struct brcmf_cfg80211_info *cfg, |
| 429 | enum nl80211_iftype new_type) |
| 430 | { |
Arend van Spriel | 39504a2 | 2015-08-20 22:06:05 +0200 | [diff] [blame] | 431 | struct brcmf_cfg80211_vif *pos; |
Purushottam Kushwaha | e227300 | 2016-10-12 18:25:35 +0530 | [diff] [blame] | 432 | struct iface_combination_params params = { |
| 433 | .num_different_channels = 1, |
| 434 | }; |
Arend van Spriel | 39504a2 | 2015-08-20 22:06:05 +0200 | [diff] [blame] | 435 | |
Arend van Spriel | 39504a2 | 2015-08-20 22:06:05 +0200 | [diff] [blame] | 436 | list_for_each_entry(pos, &cfg->vif_list, list) |
Purushottam Kushwaha | e227300 | 2016-10-12 18:25:35 +0530 | [diff] [blame] | 437 | params.iftype_num[pos->wdev.iftype]++; |
Arend van Spriel | 39504a2 | 2015-08-20 22:06:05 +0200 | [diff] [blame] | 438 | |
Purushottam Kushwaha | e227300 | 2016-10-12 18:25:35 +0530 | [diff] [blame] | 439 | params.iftype_num[new_type]++; |
| 440 | return cfg80211_check_combinations(cfg->wiphy, ¶ms); |
Arend van Spriel | 39504a2 | 2015-08-20 22:06:05 +0200 | [diff] [blame] | 441 | } |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 442 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 443 | static void convert_key_from_CPU(struct brcmf_wsec_key *key, |
| 444 | struct brcmf_wsec_key_le *key_le) |
| 445 | { |
| 446 | key_le->index = cpu_to_le32(key->index); |
| 447 | key_le->len = cpu_to_le32(key->len); |
| 448 | key_le->algo = cpu_to_le32(key->algo); |
| 449 | key_le->flags = cpu_to_le32(key->flags); |
| 450 | key_le->rxiv.hi = cpu_to_le32(key->rxiv.hi); |
| 451 | key_le->rxiv.lo = cpu_to_le16(key->rxiv.lo); |
| 452 | key_le->iv_initialized = cpu_to_le32(key->iv_initialized); |
| 453 | memcpy(key_le->data, key->data, sizeof(key->data)); |
| 454 | memcpy(key_le->ea, key->ea, sizeof(key->ea)); |
| 455 | } |
| 456 | |
Hante Meuleman | f09d0c0 | 2012-09-27 14:17:48 +0200 | [diff] [blame] | 457 | static int |
Hante Meuleman | 118eb30 | 2014-12-21 12:43:49 +0100 | [diff] [blame] | 458 | 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] | 459 | { |
| 460 | int err; |
| 461 | struct brcmf_wsec_key_le key_le; |
| 462 | |
| 463 | convert_key_from_CPU(key, &key_le); |
Hante Meuleman | f09d0c0 | 2012-09-27 14:17:48 +0200 | [diff] [blame] | 464 | |
Hante Meuleman | 118eb30 | 2014-12-21 12:43:49 +0100 | [diff] [blame] | 465 | brcmf_netdev_wait_pend8021x(ifp); |
Hante Meuleman | 81f5dcb | 2012-10-22 10:36:14 -0700 | [diff] [blame] | 466 | |
Hante Meuleman | 118eb30 | 2014-12-21 12:43:49 +0100 | [diff] [blame] | 467 | err = brcmf_fil_bsscfg_data_set(ifp, "wsec_key", &key_le, |
Hante Meuleman | 81f5dcb | 2012-10-22 10:36:14 -0700 | [diff] [blame] | 468 | sizeof(key_le)); |
Hante Meuleman | f09d0c0 | 2012-09-27 14:17:48 +0200 | [diff] [blame] | 469 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 470 | if (err) |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 471 | brcmf_err("wsec_key error (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 472 | return err; |
| 473 | } |
| 474 | |
Hante Meuleman | b365745 | 2013-05-27 21:09:53 +0200 | [diff] [blame] | 475 | static s32 |
Franky Lin | 52f22fb | 2016-02-17 11:26:55 +0100 | [diff] [blame] | 476 | brcmf_configure_arp_nd_offload(struct brcmf_if *ifp, bool enable) |
Hante Meuleman | b365745 | 2013-05-27 21:09:53 +0200 | [diff] [blame] | 477 | { |
| 478 | s32 err; |
| 479 | u32 mode; |
| 480 | |
| 481 | if (enable) |
| 482 | mode = BRCMF_ARP_OL_AGENT | BRCMF_ARP_OL_PEER_AUTO_REPLY; |
| 483 | else |
| 484 | mode = 0; |
| 485 | |
| 486 | /* Try to set and enable ARP offload feature, this may fail, then it */ |
| 487 | /* is simply not supported and err 0 will be returned */ |
| 488 | err = brcmf_fil_iovar_int_set(ifp, "arp_ol", mode); |
| 489 | if (err) { |
| 490 | brcmf_dbg(TRACE, "failed to set ARP offload mode to 0x%x, err = %d\n", |
| 491 | mode, err); |
| 492 | err = 0; |
| 493 | } else { |
| 494 | err = brcmf_fil_iovar_int_set(ifp, "arpoe", enable); |
| 495 | if (err) { |
| 496 | brcmf_dbg(TRACE, "failed to configure (%d) ARP offload err = %d\n", |
| 497 | enable, err); |
| 498 | err = 0; |
| 499 | } else |
| 500 | brcmf_dbg(TRACE, "successfully configured (%d) ARP offload to 0x%x\n", |
| 501 | enable, mode); |
| 502 | } |
| 503 | |
Franky Lin | 52f22fb | 2016-02-17 11:26:55 +0100 | [diff] [blame] | 504 | err = brcmf_fil_iovar_int_set(ifp, "ndoe", enable); |
| 505 | if (err) { |
| 506 | brcmf_dbg(TRACE, "failed to configure (%d) ND offload err = %d\n", |
| 507 | enable, err); |
| 508 | err = 0; |
| 509 | } else |
| 510 | brcmf_dbg(TRACE, "successfully configured (%d) ND offload to 0x%x\n", |
| 511 | enable, mode); |
| 512 | |
Hante Meuleman | b365745 | 2013-05-27 21:09:53 +0200 | [diff] [blame] | 513 | return err; |
| 514 | } |
| 515 | |
Hante Meuleman | 8851cce | 2014-07-30 13:20:02 +0200 | [diff] [blame] | 516 | static void |
| 517 | brcmf_cfg80211_update_proto_addr_mode(struct wireless_dev *wdev) |
| 518 | { |
Arend van Spriel | 8f2b459 | 2014-09-11 22:51:32 +0200 | [diff] [blame] | 519 | struct brcmf_cfg80211_vif *vif; |
| 520 | struct brcmf_if *ifp; |
| 521 | |
| 522 | vif = container_of(wdev, struct brcmf_cfg80211_vif, wdev); |
| 523 | ifp = vif->ifp; |
Hante Meuleman | 8851cce | 2014-07-30 13:20:02 +0200 | [diff] [blame] | 524 | |
| 525 | if ((wdev->iftype == NL80211_IFTYPE_ADHOC) || |
| 526 | (wdev->iftype == NL80211_IFTYPE_AP) || |
| 527 | (wdev->iftype == NL80211_IFTYPE_P2P_GO)) |
| 528 | brcmf_proto_configure_addr_mode(ifp->drvr, ifp->ifidx, |
| 529 | ADDR_DIRECT); |
| 530 | else |
| 531 | brcmf_proto_configure_addr_mode(ifp->drvr, ifp->ifidx, |
| 532 | ADDR_INDIRECT); |
| 533 | } |
| 534 | |
Rafał Miłecki | d02fb8f | 2016-05-26 01:44:27 +0200 | [diff] [blame] | 535 | static int brcmf_get_first_free_bsscfgidx(struct brcmf_pub *drvr) |
| 536 | { |
| 537 | int bsscfgidx; |
| 538 | |
| 539 | for (bsscfgidx = 0; bsscfgidx < BRCMF_MAX_IFS; bsscfgidx++) { |
| 540 | /* bsscfgidx 1 is reserved for legacy P2P */ |
| 541 | if (bsscfgidx == 1) |
| 542 | continue; |
| 543 | if (!drvr->iflist[bsscfgidx]) |
| 544 | return bsscfgidx; |
| 545 | } |
| 546 | |
| 547 | return -ENOMEM; |
| 548 | } |
| 549 | |
Hante Meuleman | a44aa40 | 2014-12-03 21:05:33 +0100 | [diff] [blame] | 550 | static int brcmf_cfg80211_request_ap_if(struct brcmf_if *ifp) |
| 551 | { |
| 552 | struct brcmf_mbss_ssid_le mbss_ssid_le; |
| 553 | int bsscfgidx; |
| 554 | int err; |
| 555 | |
| 556 | memset(&mbss_ssid_le, 0, sizeof(mbss_ssid_le)); |
Rafał Miłecki | d02fb8f | 2016-05-26 01:44:27 +0200 | [diff] [blame] | 557 | bsscfgidx = brcmf_get_first_free_bsscfgidx(ifp->drvr); |
Hante Meuleman | a44aa40 | 2014-12-03 21:05:33 +0100 | [diff] [blame] | 558 | if (bsscfgidx < 0) |
| 559 | return bsscfgidx; |
| 560 | |
| 561 | mbss_ssid_le.bsscfgidx = cpu_to_le32(bsscfgidx); |
| 562 | mbss_ssid_le.SSID_len = cpu_to_le32(5); |
| 563 | sprintf(mbss_ssid_le.SSID, "ssid%d" , bsscfgidx); |
| 564 | |
| 565 | err = brcmf_fil_bsscfg_data_set(ifp, "bsscfg:ssid", &mbss_ssid_le, |
| 566 | sizeof(mbss_ssid_le)); |
| 567 | if (err < 0) |
| 568 | brcmf_err("setting ssid failed %d\n", err); |
| 569 | |
| 570 | return err; |
| 571 | } |
| 572 | |
| 573 | /** |
| 574 | * brcmf_ap_add_vif() - create a new AP virtual interface for multiple BSS |
| 575 | * |
| 576 | * @wiphy: wiphy device of new interface. |
| 577 | * @name: name of the new interface. |
Hante Meuleman | a44aa40 | 2014-12-03 21:05:33 +0100 | [diff] [blame] | 578 | * @params: contains mac address for AP device. |
| 579 | */ |
| 580 | static |
| 581 | struct wireless_dev *brcmf_ap_add_vif(struct wiphy *wiphy, const char *name, |
Johannes Berg | 818a986 | 2017-04-12 11:23:28 +0200 | [diff] [blame^] | 582 | struct vif_params *params) |
Hante Meuleman | a44aa40 | 2014-12-03 21:05:33 +0100 | [diff] [blame] | 583 | { |
| 584 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); |
| 585 | struct brcmf_if *ifp = netdev_priv(cfg_to_ndev(cfg)); |
| 586 | struct brcmf_cfg80211_vif *vif; |
| 587 | int err; |
| 588 | |
| 589 | if (brcmf_cfg80211_vif_event_armed(cfg)) |
| 590 | return ERR_PTR(-EBUSY); |
| 591 | |
| 592 | brcmf_dbg(INFO, "Adding vif \"%s\"\n", name); |
| 593 | |
Rafał Miłecki | 2607233 | 2016-06-06 23:03:55 +0200 | [diff] [blame] | 594 | vif = brcmf_alloc_vif(cfg, NL80211_IFTYPE_AP); |
Hante Meuleman | a44aa40 | 2014-12-03 21:05:33 +0100 | [diff] [blame] | 595 | if (IS_ERR(vif)) |
| 596 | return (struct wireless_dev *)vif; |
| 597 | |
| 598 | brcmf_cfg80211_arm_vif_event(cfg, vif); |
| 599 | |
| 600 | err = brcmf_cfg80211_request_ap_if(ifp); |
| 601 | if (err) { |
| 602 | brcmf_cfg80211_arm_vif_event(cfg, NULL); |
| 603 | goto fail; |
| 604 | } |
| 605 | |
| 606 | /* wait for firmware event */ |
Arend van Spriel | a9eb0c4 | 2016-02-17 11:26:50 +0100 | [diff] [blame] | 607 | err = brcmf_cfg80211_wait_vif_event(cfg, BRCMF_E_IF_ADD, |
| 608 | BRCMF_VIF_EVENT_TIMEOUT); |
Hante Meuleman | a44aa40 | 2014-12-03 21:05:33 +0100 | [diff] [blame] | 609 | brcmf_cfg80211_arm_vif_event(cfg, NULL); |
| 610 | if (!err) { |
| 611 | brcmf_err("timeout occurred\n"); |
| 612 | err = -EIO; |
| 613 | goto fail; |
| 614 | } |
| 615 | |
| 616 | /* interface created in firmware */ |
| 617 | ifp = vif->ifp; |
| 618 | if (!ifp) { |
| 619 | brcmf_err("no if pointer provided\n"); |
| 620 | err = -ENOENT; |
| 621 | goto fail; |
| 622 | } |
| 623 | |
| 624 | strncpy(ifp->ndev->name, name, sizeof(ifp->ndev->name) - 1); |
| 625 | err = brcmf_net_attach(ifp, true); |
| 626 | if (err) { |
| 627 | brcmf_err("Registering netdevice failed\n"); |
| 628 | goto fail; |
| 629 | } |
| 630 | |
| 631 | return &ifp->vif->wdev; |
| 632 | |
| 633 | fail: |
| 634 | brcmf_free_vif(vif); |
| 635 | return ERR_PTR(err); |
| 636 | } |
| 637 | |
Arend van Spriel | 967fe2c | 2014-03-15 17:18:21 +0100 | [diff] [blame] | 638 | static bool brcmf_is_apmode(struct brcmf_cfg80211_vif *vif) |
| 639 | { |
| 640 | enum nl80211_iftype iftype; |
| 641 | |
| 642 | iftype = vif->wdev.iftype; |
| 643 | return iftype == NL80211_IFTYPE_AP || iftype == NL80211_IFTYPE_P2P_GO; |
| 644 | } |
| 645 | |
| 646 | static bool brcmf_is_ibssmode(struct brcmf_cfg80211_vif *vif) |
| 647 | { |
| 648 | return vif->wdev.iftype == NL80211_IFTYPE_ADHOC; |
| 649 | } |
| 650 | |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 651 | static struct wireless_dev *brcmf_cfg80211_add_iface(struct wiphy *wiphy, |
| 652 | const char *name, |
Tom Gundersen | 6bab2e19 | 2015-03-18 11:13:39 +0100 | [diff] [blame] | 653 | unsigned char name_assign_type, |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 654 | enum nl80211_iftype type, |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 655 | struct vif_params *params) |
| 656 | { |
Hante Meuleman | 8851cce | 2014-07-30 13:20:02 +0200 | [diff] [blame] | 657 | struct wireless_dev *wdev; |
Arend van Spriel | 39504a2 | 2015-08-20 22:06:05 +0200 | [diff] [blame] | 658 | int err; |
Hante Meuleman | 8851cce | 2014-07-30 13:20:02 +0200 | [diff] [blame] | 659 | |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 660 | brcmf_dbg(TRACE, "enter: %s type %d\n", name, type); |
Arend van Spriel | 39504a2 | 2015-08-20 22:06:05 +0200 | [diff] [blame] | 661 | err = brcmf_vif_add_validate(wiphy_to_cfg(wiphy), type); |
| 662 | if (err) { |
| 663 | brcmf_err("iface validation failed: err=%d\n", err); |
| 664 | return ERR_PTR(err); |
| 665 | } |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 666 | switch (type) { |
| 667 | case NL80211_IFTYPE_ADHOC: |
| 668 | case NL80211_IFTYPE_STATION: |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 669 | case NL80211_IFTYPE_AP_VLAN: |
| 670 | case NL80211_IFTYPE_WDS: |
| 671 | case NL80211_IFTYPE_MONITOR: |
| 672 | case NL80211_IFTYPE_MESH_POINT: |
| 673 | return ERR_PTR(-EOPNOTSUPP); |
Hante Meuleman | a44aa40 | 2014-12-03 21:05:33 +0100 | [diff] [blame] | 674 | case NL80211_IFTYPE_AP: |
Johannes Berg | 818a986 | 2017-04-12 11:23:28 +0200 | [diff] [blame^] | 675 | wdev = brcmf_ap_add_vif(wiphy, name, params); |
Rafał Miłecki | 0cd33c2 | 2016-05-27 10:54:28 +0200 | [diff] [blame] | 676 | break; |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 677 | case NL80211_IFTYPE_P2P_CLIENT: |
| 678 | case NL80211_IFTYPE_P2P_GO: |
Arend van Spriel | 27f10e3 | 2013-04-05 10:57:50 +0200 | [diff] [blame] | 679 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 818a986 | 2017-04-12 11:23:28 +0200 | [diff] [blame^] | 680 | wdev = brcmf_p2p_add_vif(wiphy, name, name_assign_type, type, params); |
Rafał Miłecki | 0cd33c2 | 2016-05-27 10:54:28 +0200 | [diff] [blame] | 681 | break; |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 682 | case NL80211_IFTYPE_UNSPECIFIED: |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 683 | default: |
| 684 | return ERR_PTR(-EINVAL); |
| 685 | } |
Rafał Miłecki | 0cd33c2 | 2016-05-27 10:54:28 +0200 | [diff] [blame] | 686 | |
| 687 | if (IS_ERR(wdev)) |
| 688 | brcmf_err("add iface %s type %d failed: err=%d\n", |
| 689 | name, type, (int)PTR_ERR(wdev)); |
| 690 | else |
| 691 | brcmf_cfg80211_update_proto_addr_mode(wdev); |
| 692 | |
| 693 | return wdev; |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 694 | } |
| 695 | |
Daniel Kim | 5e787f7 | 2014-06-21 12:11:18 +0200 | [diff] [blame] | 696 | static void brcmf_scan_config_mpc(struct brcmf_if *ifp, int mpc) |
| 697 | { |
Arend van Spriel | c08437b | 2014-07-12 08:49:39 +0200 | [diff] [blame] | 698 | if (brcmf_feat_is_quirk_enabled(ifp, BRCMF_FEAT_QUIRK_NEED_MPC)) |
Daniel Kim | 5e787f7 | 2014-06-21 12:11:18 +0200 | [diff] [blame] | 699 | brcmf_set_mpc(ifp, mpc); |
| 700 | } |
| 701 | |
Arend van Spriel | f96aa07 | 2013-04-05 10:57:48 +0200 | [diff] [blame] | 702 | void brcmf_set_mpc(struct brcmf_if *ifp, int mpc) |
Arend van Spriel | 5f4f9f1 | 2013-02-08 15:53:41 +0100 | [diff] [blame] | 703 | { |
Arend van Spriel | 5f4f9f1 | 2013-02-08 15:53:41 +0100 | [diff] [blame] | 704 | s32 err = 0; |
| 705 | |
| 706 | if (check_vif_up(ifp->vif)) { |
| 707 | err = brcmf_fil_iovar_int_set(ifp, "mpc", mpc); |
| 708 | if (err) { |
| 709 | brcmf_err("fail to set mpc\n"); |
| 710 | return; |
| 711 | } |
| 712 | brcmf_dbg(INFO, "MPC : %d\n", mpc); |
| 713 | } |
| 714 | } |
| 715 | |
Arend van Spriel | a0f472a | 2013-04-05 10:57:49 +0200 | [diff] [blame] | 716 | s32 brcmf_notify_escan_complete(struct brcmf_cfg80211_info *cfg, |
| 717 | struct brcmf_if *ifp, bool aborted, |
| 718 | bool fw_abort) |
Arend van Spriel | 5f4f9f1 | 2013-02-08 15:53:41 +0100 | [diff] [blame] | 719 | { |
| 720 | struct brcmf_scan_params_le params_le; |
| 721 | struct cfg80211_scan_request *scan_request; |
| 722 | s32 err = 0; |
| 723 | |
| 724 | brcmf_dbg(SCAN, "Enter\n"); |
| 725 | |
| 726 | /* clear scan request, because the FW abort can cause a second call */ |
| 727 | /* to this functon and might cause a double cfg80211_scan_done */ |
| 728 | scan_request = cfg->scan_request; |
| 729 | cfg->scan_request = NULL; |
| 730 | |
| 731 | if (timer_pending(&cfg->escan_timeout)) |
| 732 | del_timer_sync(&cfg->escan_timeout); |
| 733 | |
| 734 | if (fw_abort) { |
| 735 | /* Do a scan abort to stop the driver's scan engine */ |
| 736 | brcmf_dbg(SCAN, "ABORT scan in firmware\n"); |
| 737 | memset(¶ms_le, 0, sizeof(params_le)); |
Joe Perches | 93803b3 | 2015-03-02 19:54:49 -0800 | [diff] [blame] | 738 | eth_broadcast_addr(params_le.bssid); |
Arend van Spriel | 5f4f9f1 | 2013-02-08 15:53:41 +0100 | [diff] [blame] | 739 | params_le.bss_type = DOT11_BSSTYPE_ANY; |
| 740 | params_le.scan_type = 0; |
| 741 | params_le.channel_num = cpu_to_le32(1); |
| 742 | params_le.nprobes = cpu_to_le32(1); |
| 743 | params_le.active_time = cpu_to_le32(-1); |
| 744 | params_le.passive_time = cpu_to_le32(-1); |
| 745 | params_le.home_time = cpu_to_le32(-1); |
| 746 | /* Scan is aborted by setting channel_list[0] to -1 */ |
| 747 | params_le.channel_list[0] = cpu_to_le16(-1); |
| 748 | /* E-Scan (or anyother type) can be aborted by SCAN */ |
Arend van Spriel | f96aa07 | 2013-04-05 10:57:48 +0200 | [diff] [blame] | 749 | err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SCAN, |
Arend van Spriel | 5f4f9f1 | 2013-02-08 15:53:41 +0100 | [diff] [blame] | 750 | ¶ms_le, sizeof(params_le)); |
| 751 | if (err) |
| 752 | brcmf_err("Scan abort failed\n"); |
| 753 | } |
Arend van Spriel | 0f0fe99 | 2014-05-27 12:56:14 +0200 | [diff] [blame] | 754 | |
Daniel Kim | 5e787f7 | 2014-06-21 12:11:18 +0200 | [diff] [blame] | 755 | brcmf_scan_config_mpc(ifp, 1); |
Arend van Spriel | 0f0fe99 | 2014-05-27 12:56:14 +0200 | [diff] [blame] | 756 | |
Arend van Spriel | 5f4f9f1 | 2013-02-08 15:53:41 +0100 | [diff] [blame] | 757 | /* |
Arend Van Spriel | fa85b30 | 2016-11-23 10:25:25 +0000 | [diff] [blame] | 758 | * e-scan can be initiated internally |
Arend van Spriel | 5f4f9f1 | 2013-02-08 15:53:41 +0100 | [diff] [blame] | 759 | * which takes precedence. |
| 760 | */ |
Arend Van Spriel | fa85b30 | 2016-11-23 10:25:25 +0000 | [diff] [blame] | 761 | if (cfg->internal_escan) { |
Arend van Spriel | 5f4f9f1 | 2013-02-08 15:53:41 +0100 | [diff] [blame] | 762 | brcmf_dbg(SCAN, "scheduled scan completed\n"); |
Arend Van Spriel | fa85b30 | 2016-11-23 10:25:25 +0000 | [diff] [blame] | 763 | cfg->internal_escan = false; |
Arend van Spriel | 5f4f9f1 | 2013-02-08 15:53:41 +0100 | [diff] [blame] | 764 | if (!aborted) |
| 765 | cfg80211_sched_scan_results(cfg_to_wiphy(cfg)); |
Arend van Spriel | 5f4f9f1 | 2013-02-08 15:53:41 +0100 | [diff] [blame] | 766 | } else if (scan_request) { |
Avraham Stern | 1d76250 | 2016-07-05 17:10:13 +0300 | [diff] [blame] | 767 | struct cfg80211_scan_info info = { |
| 768 | .aborted = aborted, |
| 769 | }; |
| 770 | |
Arend van Spriel | 5f4f9f1 | 2013-02-08 15:53:41 +0100 | [diff] [blame] | 771 | brcmf_dbg(SCAN, "ESCAN Completed scan: %s\n", |
| 772 | aborted ? "Aborted" : "Done"); |
Avraham Stern | 1d76250 | 2016-07-05 17:10:13 +0300 | [diff] [blame] | 773 | cfg80211_scan_done(scan_request, &info); |
Arend van Spriel | 5f4f9f1 | 2013-02-08 15:53:41 +0100 | [diff] [blame] | 774 | } |
Hante Meuleman | 6eda4e2 | 2013-02-08 15:54:02 +0100 | [diff] [blame] | 775 | if (!test_and_clear_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status)) |
| 776 | brcmf_dbg(SCAN, "Scan complete, probably P2P scan\n"); |
Arend van Spriel | 5f4f9f1 | 2013-02-08 15:53:41 +0100 | [diff] [blame] | 777 | |
| 778 | return err; |
| 779 | } |
| 780 | |
Rafał Miłecki | dba8fbc | 2016-06-29 21:54:27 +0200 | [diff] [blame] | 781 | static int brcmf_cfg80211_del_ap_iface(struct wiphy *wiphy, |
| 782 | struct wireless_dev *wdev) |
| 783 | { |
| 784 | struct brcmf_cfg80211_info *cfg = wiphy_priv(wiphy); |
| 785 | struct net_device *ndev = wdev->netdev; |
| 786 | struct brcmf_if *ifp = netdev_priv(ndev); |
| 787 | int ret; |
| 788 | int err; |
| 789 | |
| 790 | brcmf_cfg80211_arm_vif_event(cfg, ifp->vif); |
| 791 | |
| 792 | err = brcmf_fil_bsscfg_data_set(ifp, "interface_remove", NULL, 0); |
| 793 | if (err) { |
| 794 | brcmf_err("interface_remove failed %d\n", err); |
| 795 | goto err_unarm; |
| 796 | } |
| 797 | |
| 798 | /* wait for firmware event */ |
| 799 | ret = brcmf_cfg80211_wait_vif_event(cfg, BRCMF_E_IF_DEL, |
| 800 | BRCMF_VIF_EVENT_TIMEOUT); |
| 801 | if (!ret) { |
| 802 | brcmf_err("timeout occurred\n"); |
| 803 | err = -EIO; |
| 804 | goto err_unarm; |
| 805 | } |
| 806 | |
| 807 | brcmf_remove_interface(ifp, true); |
| 808 | |
| 809 | err_unarm: |
| 810 | brcmf_cfg80211_arm_vif_event(cfg, NULL); |
| 811 | return err; |
| 812 | } |
| 813 | |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 814 | static |
| 815 | int brcmf_cfg80211_del_iface(struct wiphy *wiphy, struct wireless_dev *wdev) |
| 816 | { |
Arend van Spriel | 5f4f9f1 | 2013-02-08 15:53:41 +0100 | [diff] [blame] | 817 | struct brcmf_cfg80211_info *cfg = wiphy_priv(wiphy); |
| 818 | struct net_device *ndev = wdev->netdev; |
| 819 | |
Rafał Miłecki | dba8fbc | 2016-06-29 21:54:27 +0200 | [diff] [blame] | 820 | if (ndev && ndev == cfg_to_ndev(cfg)) |
| 821 | return -ENOTSUPP; |
| 822 | |
Arend van Spriel | 5f4f9f1 | 2013-02-08 15:53:41 +0100 | [diff] [blame] | 823 | /* vif event pending in firmware */ |
| 824 | if (brcmf_cfg80211_vif_event_armed(cfg)) |
| 825 | return -EBUSY; |
| 826 | |
| 827 | if (ndev) { |
| 828 | if (test_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status) && |
Arend van Spriel | a0f472a | 2013-04-05 10:57:49 +0200 | [diff] [blame] | 829 | cfg->escan_info.ifp == netdev_priv(ndev)) |
| 830 | brcmf_notify_escan_complete(cfg, netdev_priv(ndev), |
| 831 | true, true); |
Arend van Spriel | 5f4f9f1 | 2013-02-08 15:53:41 +0100 | [diff] [blame] | 832 | |
| 833 | brcmf_fil_iovar_int_set(netdev_priv(ndev), "mpc", 1); |
| 834 | } |
| 835 | |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 836 | switch (wdev->iftype) { |
| 837 | case NL80211_IFTYPE_ADHOC: |
| 838 | case NL80211_IFTYPE_STATION: |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 839 | case NL80211_IFTYPE_AP_VLAN: |
| 840 | case NL80211_IFTYPE_WDS: |
| 841 | case NL80211_IFTYPE_MONITOR: |
| 842 | case NL80211_IFTYPE_MESH_POINT: |
| 843 | return -EOPNOTSUPP; |
Rafał Miłecki | dba8fbc | 2016-06-29 21:54:27 +0200 | [diff] [blame] | 844 | case NL80211_IFTYPE_AP: |
| 845 | return brcmf_cfg80211_del_ap_iface(wiphy, wdev); |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 846 | case NL80211_IFTYPE_P2P_CLIENT: |
| 847 | case NL80211_IFTYPE_P2P_GO: |
Arend van Spriel | 27f10e3 | 2013-04-05 10:57:50 +0200 | [diff] [blame] | 848 | case NL80211_IFTYPE_P2P_DEVICE: |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 849 | return brcmf_p2p_del_vif(wiphy, wdev); |
| 850 | case NL80211_IFTYPE_UNSPECIFIED: |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 851 | default: |
| 852 | return -EINVAL; |
| 853 | } |
| 854 | return -EOPNOTSUPP; |
| 855 | } |
| 856 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 857 | static s32 |
| 858 | brcmf_cfg80211_change_iface(struct wiphy *wiphy, struct net_device *ndev, |
Johannes Berg | 818a986 | 2017-04-12 11:23:28 +0200 | [diff] [blame^] | 859 | enum nl80211_iftype type, |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 860 | struct vif_params *params) |
| 861 | { |
Hante Meuleman | 7a5c1f6 | 2013-02-08 15:53:44 +0100 | [diff] [blame] | 862 | struct brcmf_cfg80211_info *cfg = wiphy_priv(wiphy); |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 863 | struct brcmf_if *ifp = netdev_priv(ndev); |
Arend van Spriel | 128ce3b | 2012-11-28 21:44:12 +0100 | [diff] [blame] | 864 | struct brcmf_cfg80211_vif *vif = ifp->vif; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 865 | s32 infra = 0; |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 866 | s32 ap = 0; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 867 | s32 err = 0; |
| 868 | |
Hante Meuleman | 37a869e | 2015-10-29 20:33:17 +0100 | [diff] [blame] | 869 | brcmf_dbg(TRACE, "Enter, bsscfgidx=%d, type=%d\n", ifp->bsscfgidx, |
| 870 | type); |
Hante Meuleman | 178e9ef | 2015-09-18 22:08:11 +0200 | [diff] [blame] | 871 | |
| 872 | /* WAR: There are a number of p2p interface related problems which |
| 873 | * need to be handled initially (before doing the validate). |
| 874 | * wpa_supplicant tends to do iface changes on p2p device/client/go |
| 875 | * which are not always possible/allowed. However we need to return |
| 876 | * OK otherwise the wpa_supplicant wont start. The situation differs |
| 877 | * on configuration and setup (p2pon=1 module param). The first check |
| 878 | * is to see if the request is a change to station for p2p iface. |
| 879 | */ |
| 880 | if ((type == NL80211_IFTYPE_STATION) && |
| 881 | ((vif->wdev.iftype == NL80211_IFTYPE_P2P_CLIENT) || |
| 882 | (vif->wdev.iftype == NL80211_IFTYPE_P2P_GO) || |
| 883 | (vif->wdev.iftype == NL80211_IFTYPE_P2P_DEVICE))) { |
| 884 | brcmf_dbg(TRACE, "Ignoring cmd for p2p if\n"); |
| 885 | /* Now depending on whether module param p2pon=1 was used the |
| 886 | * response needs to be either 0 or EOPNOTSUPP. The reason is |
| 887 | * that if p2pon=1 is used, but a newer supplicant is used then |
| 888 | * we should return an error, as this combination wont work. |
| 889 | * In other situations 0 is returned and supplicant will start |
| 890 | * normally. It will give a trace in cfg80211, but it is the |
| 891 | * only way to get it working. Unfortunately this will result |
| 892 | * in situation where we wont support new supplicant in |
| 893 | * combination with module param p2pon=1, but that is the way |
| 894 | * it is. If the user tries this then unloading of driver might |
| 895 | * fail/lock. |
| 896 | */ |
| 897 | if (cfg->p2p.p2pdev_dynamically) |
| 898 | return -EOPNOTSUPP; |
| 899 | else |
| 900 | return 0; |
| 901 | } |
Arend van Spriel | 39504a2 | 2015-08-20 22:06:05 +0200 | [diff] [blame] | 902 | err = brcmf_vif_change_validate(wiphy_to_cfg(wiphy), vif, type); |
| 903 | if (err) { |
| 904 | brcmf_err("iface validation failed: err=%d\n", err); |
| 905 | return err; |
| 906 | } |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 907 | switch (type) { |
| 908 | case NL80211_IFTYPE_MONITOR: |
| 909 | case NL80211_IFTYPE_WDS: |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 910 | brcmf_err("type (%d) : currently we do not support this type\n", |
| 911 | type); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 912 | return -EOPNOTSUPP; |
| 913 | case NL80211_IFTYPE_ADHOC: |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 914 | infra = 0; |
| 915 | break; |
| 916 | case NL80211_IFTYPE_STATION: |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 917 | infra = 1; |
| 918 | break; |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 919 | case NL80211_IFTYPE_AP: |
Hante Meuleman | 7a5c1f6 | 2013-02-08 15:53:44 +0100 | [diff] [blame] | 920 | case NL80211_IFTYPE_P2P_GO: |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 921 | ap = 1; |
| 922 | break; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 923 | default: |
| 924 | err = -EINVAL; |
| 925 | goto done; |
| 926 | } |
| 927 | |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 928 | if (ap) { |
Hante Meuleman | 7a5c1f6 | 2013-02-08 15:53:44 +0100 | [diff] [blame] | 929 | if (type == NL80211_IFTYPE_P2P_GO) { |
| 930 | brcmf_dbg(INFO, "IF Type = P2P GO\n"); |
| 931 | err = brcmf_p2p_ifchange(cfg, BRCMF_FIL_P2P_IF_GO); |
| 932 | } |
| 933 | if (!err) { |
Hante Meuleman | 7a5c1f6 | 2013-02-08 15:53:44 +0100 | [diff] [blame] | 934 | brcmf_dbg(INFO, "IF Type = AP\n"); |
| 935 | } |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 936 | } else { |
Arend van Spriel | 128ce3b | 2012-11-28 21:44:12 +0100 | [diff] [blame] | 937 | err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_INFRA, infra); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 938 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 939 | brcmf_err("WLC_SET_INFRA error (%d)\n", err); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 940 | err = -EAGAIN; |
| 941 | goto done; |
| 942 | } |
Arend van Spriel | 967fe2c | 2014-03-15 17:18:21 +0100 | [diff] [blame] | 943 | brcmf_dbg(INFO, "IF Type = %s\n", brcmf_is_ibssmode(vif) ? |
Arend van Spriel | 647c9ae | 2012-12-05 15:26:01 +0100 | [diff] [blame] | 944 | "Adhoc" : "Infra"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 945 | } |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 946 | ndev->ieee80211_ptr->iftype = type; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 947 | |
Hante Meuleman | 8851cce | 2014-07-30 13:20:02 +0200 | [diff] [blame] | 948 | brcmf_cfg80211_update_proto_addr_mode(&vif->wdev); |
| 949 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 950 | done: |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 951 | brcmf_dbg(TRACE, "Exit\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 952 | |
| 953 | return err; |
| 954 | } |
| 955 | |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 956 | static void brcmf_escan_prep(struct brcmf_cfg80211_info *cfg, |
| 957 | struct brcmf_scan_params_le *params_le, |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 958 | struct cfg80211_scan_request *request) |
| 959 | { |
| 960 | u32 n_ssids; |
| 961 | u32 n_channels; |
| 962 | s32 i; |
| 963 | s32 offset; |
Arend van Spriel | 029591f | 2012-09-19 22:21:06 +0200 | [diff] [blame] | 964 | u16 chanspec; |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 965 | char *ptr; |
Arend van Spriel | 029591f | 2012-09-19 22:21:06 +0200 | [diff] [blame] | 966 | struct brcmf_ssid_le ssid_le; |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 967 | |
Joe Perches | 93803b3 | 2015-03-02 19:54:49 -0800 | [diff] [blame] | 968 | eth_broadcast_addr(params_le->bssid); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 969 | params_le->bss_type = DOT11_BSSTYPE_ANY; |
| 970 | params_le->scan_type = 0; |
| 971 | params_le->channel_num = 0; |
| 972 | params_le->nprobes = cpu_to_le32(-1); |
| 973 | params_le->active_time = cpu_to_le32(-1); |
| 974 | params_le->passive_time = cpu_to_le32(-1); |
| 975 | params_le->home_time = cpu_to_le32(-1); |
| 976 | memset(¶ms_le->ssid_le, 0, sizeof(params_le->ssid_le)); |
| 977 | |
| 978 | /* if request is null exit so it will be all channel broadcast scan */ |
| 979 | if (!request) |
| 980 | return; |
| 981 | |
| 982 | n_ssids = request->n_ssids; |
| 983 | n_channels = request->n_channels; |
| 984 | /* Copy channel array if applicable */ |
Arend van Spriel | 4e8a008 | 2012-12-05 15:26:03 +0100 | [diff] [blame] | 985 | brcmf_dbg(SCAN, "### List of channelspecs to scan ### %d\n", |
| 986 | n_channels); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 987 | if (n_channels > 0) { |
| 988 | for (i = 0; i < n_channels; i++) { |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 989 | chanspec = channel_to_chanspec(&cfg->d11inf, |
| 990 | request->channels[i]); |
Arend van Spriel | 4e8a008 | 2012-12-05 15:26:03 +0100 | [diff] [blame] | 991 | brcmf_dbg(SCAN, "Chan : %d, Channel spec: %x\n", |
| 992 | request->channels[i]->hw_value, chanspec); |
Arend van Spriel | 029591f | 2012-09-19 22:21:06 +0200 | [diff] [blame] | 993 | params_le->channel_list[i] = cpu_to_le16(chanspec); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 994 | } |
| 995 | } else { |
Arend van Spriel | 4e8a008 | 2012-12-05 15:26:03 +0100 | [diff] [blame] | 996 | brcmf_dbg(SCAN, "Scanning all channels\n"); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 997 | } |
| 998 | /* Copy ssid array if applicable */ |
Arend van Spriel | 4e8a008 | 2012-12-05 15:26:03 +0100 | [diff] [blame] | 999 | brcmf_dbg(SCAN, "### List of SSIDs to scan ### %d\n", n_ssids); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1000 | if (n_ssids > 0) { |
| 1001 | offset = offsetof(struct brcmf_scan_params_le, channel_list) + |
| 1002 | n_channels * sizeof(u16); |
| 1003 | offset = roundup(offset, sizeof(u32)); |
| 1004 | ptr = (char *)params_le + offset; |
| 1005 | for (i = 0; i < n_ssids; i++) { |
Arend van Spriel | 029591f | 2012-09-19 22:21:06 +0200 | [diff] [blame] | 1006 | memset(&ssid_le, 0, sizeof(ssid_le)); |
| 1007 | ssid_le.SSID_len = |
| 1008 | cpu_to_le32(request->ssids[i].ssid_len); |
| 1009 | memcpy(ssid_le.SSID, request->ssids[i].ssid, |
| 1010 | request->ssids[i].ssid_len); |
| 1011 | if (!ssid_le.SSID_len) |
Arend van Spriel | 4e8a008 | 2012-12-05 15:26:03 +0100 | [diff] [blame] | 1012 | brcmf_dbg(SCAN, "%d: Broadcast scan\n", i); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1013 | else |
Arend van Spriel | 4e8a008 | 2012-12-05 15:26:03 +0100 | [diff] [blame] | 1014 | brcmf_dbg(SCAN, "%d: scan for %s size =%d\n", |
| 1015 | i, ssid_le.SSID, ssid_le.SSID_len); |
Arend van Spriel | 029591f | 2012-09-19 22:21:06 +0200 | [diff] [blame] | 1016 | memcpy(ptr, &ssid_le, sizeof(ssid_le)); |
| 1017 | ptr += sizeof(ssid_le); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1018 | } |
| 1019 | } else { |
Arend van Spriel | 4e8a008 | 2012-12-05 15:26:03 +0100 | [diff] [blame] | 1020 | brcmf_dbg(SCAN, "Broadcast scan %p\n", request->ssids); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1021 | if ((request->ssids) && request->ssids->ssid_len) { |
Arend van Spriel | 4e8a008 | 2012-12-05 15:26:03 +0100 | [diff] [blame] | 1022 | brcmf_dbg(SCAN, "SSID %s len=%d\n", |
| 1023 | params_le->ssid_le.SSID, |
| 1024 | request->ssids->ssid_len); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1025 | params_le->ssid_le.SSID_len = |
| 1026 | cpu_to_le32(request->ssids->ssid_len); |
| 1027 | memcpy(¶ms_le->ssid_le.SSID, request->ssids->ssid, |
| 1028 | request->ssids->ssid_len); |
| 1029 | } |
| 1030 | } |
| 1031 | /* Adding mask to channel numbers */ |
| 1032 | params_le->channel_num = |
| 1033 | cpu_to_le32((n_ssids << BRCMF_SCAN_PARAMS_NSSID_SHIFT) | |
| 1034 | (n_channels & BRCMF_SCAN_PARAMS_COUNT_MASK)); |
| 1035 | } |
| 1036 | |
| 1037 | static s32 |
Arend van Spriel | a0f472a | 2013-04-05 10:57:49 +0200 | [diff] [blame] | 1038 | brcmf_run_escan(struct brcmf_cfg80211_info *cfg, struct brcmf_if *ifp, |
Hante Meuleman | c495810 | 2015-11-25 11:32:41 +0100 | [diff] [blame] | 1039 | struct cfg80211_scan_request *request) |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1040 | { |
| 1041 | s32 params_size = BRCMF_SCAN_PARAMS_FIXED_SIZE + |
| 1042 | offsetof(struct brcmf_escan_params_le, params_le); |
| 1043 | struct brcmf_escan_params_le *params; |
| 1044 | s32 err = 0; |
| 1045 | |
Arend van Spriel | 4e8a008 | 2012-12-05 15:26:03 +0100 | [diff] [blame] | 1046 | brcmf_dbg(SCAN, "E-SCAN START\n"); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1047 | |
| 1048 | if (request != NULL) { |
| 1049 | /* Allocate space for populating ssids in struct */ |
| 1050 | params_size += sizeof(u32) * ((request->n_channels + 1) / 2); |
| 1051 | |
| 1052 | /* Allocate space for populating ssids in struct */ |
Hante Meuleman | e9a6ca8 | 2015-11-25 11:32:37 +0100 | [diff] [blame] | 1053 | params_size += sizeof(struct brcmf_ssid_le) * request->n_ssids; |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1054 | } |
| 1055 | |
| 1056 | params = kzalloc(params_size, GFP_KERNEL); |
| 1057 | if (!params) { |
| 1058 | err = -ENOMEM; |
| 1059 | goto exit; |
| 1060 | } |
| 1061 | BUG_ON(params_size + sizeof("escan") >= BRCMF_DCMD_MEDLEN); |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 1062 | brcmf_escan_prep(cfg, ¶ms->params_le, request); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1063 | params->version = cpu_to_le32(BRCMF_ESCAN_REQ_VERSION); |
Hante Meuleman | c495810 | 2015-11-25 11:32:41 +0100 | [diff] [blame] | 1064 | params->action = cpu_to_le16(WL_ESCAN_ACTION_START); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1065 | params->sync_id = cpu_to_le16(0x1234); |
| 1066 | |
Arend van Spriel | a0f472a | 2013-04-05 10:57:49 +0200 | [diff] [blame] | 1067 | err = brcmf_fil_iovar_data_set(ifp, "escan", params, params_size); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1068 | if (err) { |
| 1069 | if (err == -EBUSY) |
Arend van Spriel | 647c9ae | 2012-12-05 15:26:01 +0100 | [diff] [blame] | 1070 | brcmf_dbg(INFO, "system busy : escan canceled\n"); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1071 | else |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1072 | brcmf_err("error (%d)\n", err); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1073 | } |
| 1074 | |
| 1075 | kfree(params); |
| 1076 | exit: |
| 1077 | return err; |
| 1078 | } |
| 1079 | |
| 1080 | static s32 |
Arend Van Spriel | ab5981c | 2016-11-23 10:25:24 +0000 | [diff] [blame] | 1081 | brcmf_do_escan(struct brcmf_if *ifp, struct cfg80211_scan_request *request) |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1082 | { |
Arend Van Spriel | ab5981c | 2016-11-23 10:25:24 +0000 | [diff] [blame] | 1083 | struct brcmf_cfg80211_info *cfg = ifp->drvr->config; |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1084 | s32 err; |
Hante Meuleman | 81f5dcb | 2012-10-22 10:36:14 -0700 | [diff] [blame] | 1085 | u32 passive_scan; |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1086 | struct brcmf_scan_results *results; |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 1087 | struct escan_info *escan = &cfg->escan_info; |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1088 | |
Arend van Spriel | 4e8a008 | 2012-12-05 15:26:03 +0100 | [diff] [blame] | 1089 | brcmf_dbg(SCAN, "Enter\n"); |
Arend van Spriel | a0f472a | 2013-04-05 10:57:49 +0200 | [diff] [blame] | 1090 | escan->ifp = ifp; |
Arend Van Spriel | ab5981c | 2016-11-23 10:25:24 +0000 | [diff] [blame] | 1091 | escan->wiphy = cfg->wiphy; |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 1092 | escan->escan_state = WL_ESCAN_STATE_SCANNING; |
Hante Meuleman | 81f5dcb | 2012-10-22 10:36:14 -0700 | [diff] [blame] | 1093 | passive_scan = cfg->active_scan ? 0 : 1; |
Arend van Spriel | f96aa07 | 2013-04-05 10:57:48 +0200 | [diff] [blame] | 1094 | err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_PASSIVE_SCAN, |
Hante Meuleman | 81f5dcb | 2012-10-22 10:36:14 -0700 | [diff] [blame] | 1095 | passive_scan); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1096 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1097 | brcmf_err("error (%d)\n", err); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1098 | return err; |
| 1099 | } |
Daniel Kim | 5e787f7 | 2014-06-21 12:11:18 +0200 | [diff] [blame] | 1100 | brcmf_scan_config_mpc(ifp, 0); |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 1101 | results = (struct brcmf_scan_results *)cfg->escan_info.escan_buf; |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1102 | results->version = 0; |
| 1103 | results->count = 0; |
| 1104 | results->buflen = WL_ESCAN_RESULTS_FIXED_SIZE; |
| 1105 | |
Hante Meuleman | c495810 | 2015-11-25 11:32:41 +0100 | [diff] [blame] | 1106 | err = escan->run(cfg, ifp, request); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1107 | if (err) |
Daniel Kim | 5e787f7 | 2014-06-21 12:11:18 +0200 | [diff] [blame] | 1108 | brcmf_scan_config_mpc(ifp, 1); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1109 | return err; |
| 1110 | } |
| 1111 | |
| 1112 | static s32 |
Arend van Spriel | a0f472a | 2013-04-05 10:57:49 +0200 | [diff] [blame] | 1113 | brcmf_cfg80211_escan(struct wiphy *wiphy, struct brcmf_cfg80211_vif *vif, |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1114 | struct cfg80211_scan_request *request, |
| 1115 | struct cfg80211_ssid *this_ssid) |
| 1116 | { |
Arend van Spriel | a0f472a | 2013-04-05 10:57:49 +0200 | [diff] [blame] | 1117 | struct brcmf_if *ifp = vif->ifp; |
| 1118 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1119 | struct cfg80211_ssid *ssids; |
Hante Meuleman | 81f5dcb | 2012-10-22 10:36:14 -0700 | [diff] [blame] | 1120 | u32 passive_scan; |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1121 | bool escan_req; |
| 1122 | bool spec_scan; |
| 1123 | s32 err; |
Hante Meuleman | 675f5d8 | 2015-12-10 13:43:01 +0100 | [diff] [blame] | 1124 | struct brcmf_ssid_le ssid_le; |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1125 | u32 SSID_len; |
| 1126 | |
Arend van Spriel | 4e8a008 | 2012-12-05 15:26:03 +0100 | [diff] [blame] | 1127 | brcmf_dbg(SCAN, "START ESCAN\n"); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1128 | |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 1129 | if (test_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status)) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1130 | brcmf_err("Scanning already: status (%lu)\n", cfg->scan_status); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1131 | return -EAGAIN; |
| 1132 | } |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 1133 | if (test_bit(BRCMF_SCAN_STATUS_ABORT, &cfg->scan_status)) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1134 | brcmf_err("Scanning being aborted: status (%lu)\n", |
| 1135 | cfg->scan_status); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1136 | return -EAGAIN; |
| 1137 | } |
Arend van Spriel | 1687eee | 2013-04-23 12:53:11 +0200 | [diff] [blame] | 1138 | if (test_bit(BRCMF_SCAN_STATUS_SUPPRESS, &cfg->scan_status)) { |
| 1139 | brcmf_err("Scanning suppressed: status (%lu)\n", |
| 1140 | cfg->scan_status); |
| 1141 | return -EAGAIN; |
| 1142 | } |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 1143 | if (test_bit(BRCMF_VIF_STATUS_CONNECTING, &ifp->vif->sme_state)) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1144 | brcmf_err("Connecting: status (%lu)\n", ifp->vif->sme_state); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1145 | return -EAGAIN; |
| 1146 | } |
| 1147 | |
Hante Meuleman | 0f8ffe1 | 2013-02-08 15:53:42 +0100 | [diff] [blame] | 1148 | /* 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] | 1149 | if (vif == cfg->p2p.bss_idx[P2PAPI_BSSCFG_DEVICE].vif) |
| 1150 | vif = cfg->p2p.bss_idx[P2PAPI_BSSCFG_PRIMARY].vif; |
Hante Meuleman | 0f8ffe1 | 2013-02-08 15:53:42 +0100 | [diff] [blame] | 1151 | |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1152 | escan_req = false; |
| 1153 | if (request) { |
| 1154 | /* scan bss */ |
| 1155 | ssids = request->ssids; |
| 1156 | escan_req = true; |
| 1157 | } else { |
| 1158 | /* scan in ibss */ |
| 1159 | /* we don't do escan in ibss */ |
| 1160 | ssids = this_ssid; |
| 1161 | } |
| 1162 | |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 1163 | cfg->scan_request = request; |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 1164 | set_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1165 | if (escan_req) { |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 1166 | cfg->escan_info.run = brcmf_run_escan; |
Arend van Spriel | a0f472a | 2013-04-05 10:57:49 +0200 | [diff] [blame] | 1167 | err = brcmf_p2p_scan_prep(wiphy, request, vif); |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 1168 | if (err) |
| 1169 | goto scan_out; |
| 1170 | |
Arend Van Spriel | ab5981c | 2016-11-23 10:25:24 +0000 | [diff] [blame] | 1171 | err = brcmf_do_escan(vif->ifp, request); |
Arend van Spriel | 2cb941c | 2012-11-05 16:22:10 -0800 | [diff] [blame] | 1172 | if (err) |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1173 | goto scan_out; |
| 1174 | } else { |
Arend van Spriel | 4e8a008 | 2012-12-05 15:26:03 +0100 | [diff] [blame] | 1175 | brcmf_dbg(SCAN, "ssid \"%s\", ssid_len (%d)\n", |
| 1176 | ssids->ssid, ssids->ssid_len); |
Hante Meuleman | 675f5d8 | 2015-12-10 13:43:01 +0100 | [diff] [blame] | 1177 | memset(&ssid_le, 0, sizeof(ssid_le)); |
| 1178 | SSID_len = min_t(u8, sizeof(ssid_le.SSID), ssids->ssid_len); |
| 1179 | ssid_le.SSID_len = cpu_to_le32(0); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1180 | spec_scan = false; |
| 1181 | if (SSID_len) { |
Hante Meuleman | 675f5d8 | 2015-12-10 13:43:01 +0100 | [diff] [blame] | 1182 | memcpy(ssid_le.SSID, ssids->ssid, SSID_len); |
| 1183 | ssid_le.SSID_len = cpu_to_le32(SSID_len); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1184 | spec_scan = true; |
| 1185 | } else |
Arend van Spriel | 4e8a008 | 2012-12-05 15:26:03 +0100 | [diff] [blame] | 1186 | brcmf_dbg(SCAN, "Broadcast scan\n"); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1187 | |
Hante Meuleman | 81f5dcb | 2012-10-22 10:36:14 -0700 | [diff] [blame] | 1188 | passive_scan = cfg->active_scan ? 0 : 1; |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 1189 | err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_PASSIVE_SCAN, |
Hante Meuleman | 81f5dcb | 2012-10-22 10:36:14 -0700 | [diff] [blame] | 1190 | passive_scan); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1191 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1192 | brcmf_err("WLC_SET_PASSIVE_SCAN error (%d)\n", err); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1193 | goto scan_out; |
| 1194 | } |
Daniel Kim | 5e787f7 | 2014-06-21 12:11:18 +0200 | [diff] [blame] | 1195 | brcmf_scan_config_mpc(ifp, 0); |
Hante Meuleman | 675f5d8 | 2015-12-10 13:43:01 +0100 | [diff] [blame] | 1196 | err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SCAN, &ssid_le, |
| 1197 | sizeof(ssid_le)); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1198 | if (err) { |
| 1199 | if (err == -EBUSY) |
Arend van Spriel | 647c9ae | 2012-12-05 15:26:01 +0100 | [diff] [blame] | 1200 | brcmf_dbg(INFO, "BUSY: scan for \"%s\" canceled\n", |
Hante Meuleman | 675f5d8 | 2015-12-10 13:43:01 +0100 | [diff] [blame] | 1201 | ssid_le.SSID); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1202 | else |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1203 | brcmf_err("WLC_SCAN error (%d)\n", err); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1204 | |
Daniel Kim | 5e787f7 | 2014-06-21 12:11:18 +0200 | [diff] [blame] | 1205 | brcmf_scan_config_mpc(ifp, 1); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1206 | goto scan_out; |
| 1207 | } |
| 1208 | } |
| 1209 | |
Hante Meuleman | 661fa95 | 2015-02-06 18:36:47 +0100 | [diff] [blame] | 1210 | /* Arm scan timeout timer */ |
| 1211 | mod_timer(&cfg->escan_timeout, jiffies + |
Hante Meuleman | d536733 | 2016-02-17 11:26:51 +0100 | [diff] [blame] | 1212 | BRCMF_ESCAN_TIMER_INTERVAL_MS * HZ / 1000); |
Hante Meuleman | 661fa95 | 2015-02-06 18:36:47 +0100 | [diff] [blame] | 1213 | |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1214 | return 0; |
| 1215 | |
| 1216 | scan_out: |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 1217 | clear_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status); |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 1218 | cfg->scan_request = NULL; |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1219 | return err; |
| 1220 | } |
| 1221 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1222 | static s32 |
Arend van Spriel | 0abb5f21 | 2012-10-22 13:55:32 -0700 | [diff] [blame] | 1223 | brcmf_cfg80211_scan(struct wiphy *wiphy, struct cfg80211_scan_request *request) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1224 | { |
Arend van Spriel | a0f472a | 2013-04-05 10:57:49 +0200 | [diff] [blame] | 1225 | struct brcmf_cfg80211_vif *vif; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1226 | s32 err = 0; |
| 1227 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 1228 | brcmf_dbg(TRACE, "Enter\n"); |
Arend van Spriel | a0f472a | 2013-04-05 10:57:49 +0200 | [diff] [blame] | 1229 | vif = container_of(request->wdev, struct brcmf_cfg80211_vif, wdev); |
| 1230 | if (!check_vif_up(vif)) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1231 | return -EIO; |
| 1232 | |
Arend van Spriel | a0f472a | 2013-04-05 10:57:49 +0200 | [diff] [blame] | 1233 | err = brcmf_cfg80211_escan(wiphy, vif, request, NULL); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1234 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1235 | if (err) |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1236 | brcmf_err("scan error (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1237 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 1238 | brcmf_dbg(TRACE, "Exit\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1239 | return err; |
| 1240 | } |
| 1241 | |
| 1242 | static s32 brcmf_set_rts(struct net_device *ndev, u32 rts_threshold) |
| 1243 | { |
| 1244 | s32 err = 0; |
| 1245 | |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 1246 | err = brcmf_fil_iovar_int_set(netdev_priv(ndev), "rtsthresh", |
| 1247 | rts_threshold); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1248 | if (err) |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1249 | brcmf_err("Error (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1250 | |
| 1251 | return err; |
| 1252 | } |
| 1253 | |
| 1254 | static s32 brcmf_set_frag(struct net_device *ndev, u32 frag_threshold) |
| 1255 | { |
| 1256 | s32 err = 0; |
| 1257 | |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 1258 | err = brcmf_fil_iovar_int_set(netdev_priv(ndev), "fragthresh", |
| 1259 | frag_threshold); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1260 | if (err) |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1261 | brcmf_err("Error (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1262 | |
| 1263 | return err; |
| 1264 | } |
| 1265 | |
| 1266 | static s32 brcmf_set_retry(struct net_device *ndev, u32 retry, bool l) |
| 1267 | { |
| 1268 | s32 err = 0; |
Hante Meuleman | b87e2c4 | 2012-11-14 18:46:23 -0800 | [diff] [blame] | 1269 | u32 cmd = (l ? BRCMF_C_SET_LRL : BRCMF_C_SET_SRL); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1270 | |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 1271 | err = brcmf_fil_cmd_int_set(netdev_priv(ndev), cmd, retry); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1272 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1273 | brcmf_err("cmd (%d) , error (%d)\n", cmd, err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1274 | return err; |
| 1275 | } |
| 1276 | return err; |
| 1277 | } |
| 1278 | |
| 1279 | static s32 brcmf_cfg80211_set_wiphy_params(struct wiphy *wiphy, u32 changed) |
| 1280 | { |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 1281 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); |
| 1282 | struct net_device *ndev = cfg_to_ndev(cfg); |
Arend van Spriel | 0abb5f21 | 2012-10-22 13:55:32 -0700 | [diff] [blame] | 1283 | struct brcmf_if *ifp = netdev_priv(ndev); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1284 | s32 err = 0; |
| 1285 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 1286 | brcmf_dbg(TRACE, "Enter\n"); |
Arend van Spriel | ce81e31 | 2012-10-22 13:55:37 -0700 | [diff] [blame] | 1287 | if (!check_vif_up(ifp->vif)) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1288 | return -EIO; |
| 1289 | |
| 1290 | if (changed & WIPHY_PARAM_RTS_THRESHOLD && |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 1291 | (cfg->conf->rts_threshold != wiphy->rts_threshold)) { |
| 1292 | cfg->conf->rts_threshold = wiphy->rts_threshold; |
| 1293 | err = brcmf_set_rts(ndev, cfg->conf->rts_threshold); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1294 | if (!err) |
| 1295 | goto done; |
| 1296 | } |
| 1297 | if (changed & WIPHY_PARAM_FRAG_THRESHOLD && |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 1298 | (cfg->conf->frag_threshold != wiphy->frag_threshold)) { |
| 1299 | cfg->conf->frag_threshold = wiphy->frag_threshold; |
| 1300 | err = brcmf_set_frag(ndev, cfg->conf->frag_threshold); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1301 | if (!err) |
| 1302 | goto done; |
| 1303 | } |
| 1304 | if (changed & WIPHY_PARAM_RETRY_LONG |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 1305 | && (cfg->conf->retry_long != wiphy->retry_long)) { |
| 1306 | cfg->conf->retry_long = wiphy->retry_long; |
| 1307 | err = brcmf_set_retry(ndev, cfg->conf->retry_long, true); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1308 | if (!err) |
| 1309 | goto done; |
| 1310 | } |
| 1311 | if (changed & WIPHY_PARAM_RETRY_SHORT |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 1312 | && (cfg->conf->retry_short != wiphy->retry_short)) { |
| 1313 | cfg->conf->retry_short = wiphy->retry_short; |
| 1314 | err = brcmf_set_retry(ndev, cfg->conf->retry_short, false); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1315 | if (!err) |
| 1316 | goto done; |
| 1317 | } |
| 1318 | |
| 1319 | done: |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 1320 | brcmf_dbg(TRACE, "Exit\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1321 | return err; |
| 1322 | } |
| 1323 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1324 | static void brcmf_init_prof(struct brcmf_cfg80211_profile *prof) |
| 1325 | { |
| 1326 | memset(prof, 0, sizeof(*prof)); |
| 1327 | } |
| 1328 | |
Arend van Spriel | 9b7a0dd | 2015-01-25 20:31:33 +0100 | [diff] [blame] | 1329 | static u16 brcmf_map_fw_linkdown_reason(const struct brcmf_event_msg *e) |
| 1330 | { |
| 1331 | u16 reason; |
| 1332 | |
| 1333 | switch (e->event_code) { |
| 1334 | case BRCMF_E_DEAUTH: |
| 1335 | case BRCMF_E_DEAUTH_IND: |
| 1336 | case BRCMF_E_DISASSOC_IND: |
| 1337 | reason = e->reason; |
| 1338 | break; |
| 1339 | case BRCMF_E_LINK: |
| 1340 | default: |
| 1341 | reason = 0; |
| 1342 | break; |
| 1343 | } |
| 1344 | return reason; |
| 1345 | } |
| 1346 | |
| 1347 | 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] | 1348 | { |
Piotr Haber | 61730d4 | 2013-04-23 12:53:12 +0200 | [diff] [blame] | 1349 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(vif->wdev.wiphy); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1350 | s32 err = 0; |
| 1351 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 1352 | brcmf_dbg(TRACE, "Enter\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1353 | |
Hante Meuleman | b0a7908 | 2015-12-10 13:43:07 +0100 | [diff] [blame] | 1354 | 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] | 1355 | brcmf_dbg(INFO, "Call WLC_DISASSOC to stop excess roaming\n "); |
Arend van Spriel | 903e0ee | 2012-11-28 21:44:11 +0100 | [diff] [blame] | 1356 | err = brcmf_fil_cmd_data_set(vif->ifp, |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 1357 | BRCMF_C_DISASSOC, NULL, 0); |
Arend van Spriel | a538ae3 | 2013-07-25 23:01:34 +0200 | [diff] [blame] | 1358 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1359 | brcmf_err("WLC_DISASSOC failed (%d)\n", err); |
Arend van Spriel | a538ae3 | 2013-07-25 23:01:34 +0200 | [diff] [blame] | 1360 | } |
Hante Meuleman | b0a7908 | 2015-12-10 13:43:07 +0100 | [diff] [blame] | 1361 | if ((vif->wdev.iftype == NL80211_IFTYPE_STATION) || |
| 1362 | (vif->wdev.iftype == NL80211_IFTYPE_P2P_CLIENT)) |
| 1363 | cfg80211_disconnected(vif->wdev.netdev, reason, NULL, 0, |
| 1364 | true, GFP_KERNEL); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1365 | } |
Arend van Spriel | 903e0ee | 2012-11-28 21:44:11 +0100 | [diff] [blame] | 1366 | clear_bit(BRCMF_VIF_STATUS_CONNECTING, &vif->sme_state); |
Piotr Haber | 61730d4 | 2013-04-23 12:53:12 +0200 | [diff] [blame] | 1367 | clear_bit(BRCMF_SCAN_STATUS_SUPPRESS, &cfg->scan_status); |
| 1368 | brcmf_btcoex_set_mode(vif, BRCMF_BTCOEX_ENABLED, 0); |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 1369 | brcmf_dbg(TRACE, "Exit\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1370 | } |
| 1371 | |
| 1372 | static s32 |
| 1373 | brcmf_cfg80211_join_ibss(struct wiphy *wiphy, struct net_device *ndev, |
| 1374 | struct cfg80211_ibss_params *params) |
| 1375 | { |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 1376 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); |
Arend van Spriel | 0abb5f21 | 2012-10-22 13:55:32 -0700 | [diff] [blame] | 1377 | struct brcmf_if *ifp = netdev_priv(ndev); |
| 1378 | struct brcmf_cfg80211_profile *profile = &ifp->vif->profile; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1379 | struct brcmf_join_params join_params; |
| 1380 | size_t join_params_size = 0; |
| 1381 | s32 err = 0; |
| 1382 | s32 wsec = 0; |
| 1383 | s32 bcnprd; |
Hante Meuleman | 1701261 | 2013-02-06 18:40:44 +0100 | [diff] [blame] | 1384 | u16 chanspec; |
Hante Meuleman | e9a6ca8 | 2015-11-25 11:32:37 +0100 | [diff] [blame] | 1385 | u32 ssid_len; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1386 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 1387 | brcmf_dbg(TRACE, "Enter\n"); |
Arend van Spriel | ce81e31 | 2012-10-22 13:55:37 -0700 | [diff] [blame] | 1388 | if (!check_vif_up(ifp->vif)) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1389 | return -EIO; |
| 1390 | |
| 1391 | if (params->ssid) |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 1392 | brcmf_dbg(CONN, "SSID: %s\n", params->ssid); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1393 | else { |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 1394 | brcmf_dbg(CONN, "SSID: NULL, Not supported\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1395 | return -EOPNOTSUPP; |
| 1396 | } |
| 1397 | |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 1398 | set_bit(BRCMF_VIF_STATUS_CONNECTING, &ifp->vif->sme_state); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1399 | |
| 1400 | if (params->bssid) |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 1401 | brcmf_dbg(CONN, "BSSID: %pM\n", params->bssid); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1402 | else |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 1403 | brcmf_dbg(CONN, "No BSSID specified\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1404 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1405 | if (params->chandef.chan) |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 1406 | brcmf_dbg(CONN, "channel: %d\n", |
| 1407 | params->chandef.chan->center_freq); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1408 | else |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 1409 | brcmf_dbg(CONN, "no channel specified\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1410 | |
| 1411 | if (params->channel_fixed) |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 1412 | brcmf_dbg(CONN, "fixed channel required\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1413 | else |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 1414 | brcmf_dbg(CONN, "no fixed channel required\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1415 | |
| 1416 | if (params->ie && params->ie_len) |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 1417 | brcmf_dbg(CONN, "ie len: %d\n", params->ie_len); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1418 | else |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 1419 | brcmf_dbg(CONN, "no ie specified\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1420 | |
| 1421 | if (params->beacon_interval) |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 1422 | brcmf_dbg(CONN, "beacon interval: %d\n", |
| 1423 | params->beacon_interval); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1424 | else |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 1425 | brcmf_dbg(CONN, "no beacon interval specified\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1426 | |
| 1427 | if (params->basic_rates) |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 1428 | brcmf_dbg(CONN, "basic rates: %08X\n", params->basic_rates); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1429 | else |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 1430 | brcmf_dbg(CONN, "no basic rates specified\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1431 | |
| 1432 | if (params->privacy) |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 1433 | brcmf_dbg(CONN, "privacy required\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1434 | else |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 1435 | brcmf_dbg(CONN, "no privacy required\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1436 | |
| 1437 | /* Configure Privacy for starter */ |
| 1438 | if (params->privacy) |
| 1439 | wsec |= WEP_ENABLED; |
| 1440 | |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 1441 | err = brcmf_fil_iovar_int_set(ifp, "wsec", wsec); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1442 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1443 | brcmf_err("wsec failed (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1444 | goto done; |
| 1445 | } |
| 1446 | |
| 1447 | /* Configure Beacon Interval for starter */ |
| 1448 | if (params->beacon_interval) |
| 1449 | bcnprd = params->beacon_interval; |
| 1450 | else |
| 1451 | bcnprd = 100; |
| 1452 | |
Hante Meuleman | b87e2c4 | 2012-11-14 18:46:23 -0800 | [diff] [blame] | 1453 | 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] | 1454 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1455 | brcmf_err("WLC_SET_BCNPRD failed (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1456 | goto done; |
| 1457 | } |
| 1458 | |
| 1459 | /* Configure required join parameter */ |
| 1460 | memset(&join_params, 0, sizeof(struct brcmf_join_params)); |
| 1461 | |
| 1462 | /* SSID */ |
Hante Meuleman | e9a6ca8 | 2015-11-25 11:32:37 +0100 | [diff] [blame] | 1463 | ssid_len = min_t(u32, params->ssid_len, IEEE80211_MAX_SSID_LEN); |
| 1464 | memcpy(join_params.ssid_le.SSID, params->ssid, ssid_len); |
| 1465 | join_params.ssid_le.SSID_len = cpu_to_le32(ssid_len); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1466 | join_params_size = sizeof(join_params.ssid_le); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1467 | |
| 1468 | /* BSSID */ |
| 1469 | if (params->bssid) { |
| 1470 | memcpy(join_params.params_le.bssid, params->bssid, ETH_ALEN); |
Hante Meuleman | e9a6ca8 | 2015-11-25 11:32:37 +0100 | [diff] [blame] | 1471 | join_params_size += BRCMF_ASSOC_PARAMS_FIXED_SIZE; |
Arend van Spriel | 6c8c4f7 | 2012-09-27 14:17:57 +0200 | [diff] [blame] | 1472 | memcpy(profile->bssid, params->bssid, ETH_ALEN); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1473 | } else { |
Joe Perches | 93803b3 | 2015-03-02 19:54:49 -0800 | [diff] [blame] | 1474 | eth_broadcast_addr(join_params.params_le.bssid); |
| 1475 | eth_zero_addr(profile->bssid); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1476 | } |
| 1477 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1478 | /* Channel */ |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1479 | if (params->chandef.chan) { |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1480 | u32 target_channel; |
| 1481 | |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 1482 | cfg->channel = |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1483 | ieee80211_frequency_to_channel( |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1484 | params->chandef.chan->center_freq); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1485 | if (params->channel_fixed) { |
| 1486 | /* adding chanspec */ |
Arend van Spriel | 600a897 | 2014-05-12 10:47:39 +0200 | [diff] [blame] | 1487 | chanspec = chandef_to_chanspec(&cfg->d11inf, |
| 1488 | ¶ms->chandef); |
Hante Meuleman | 1701261 | 2013-02-06 18:40:44 +0100 | [diff] [blame] | 1489 | join_params.params_le.chanspec_list[0] = |
| 1490 | cpu_to_le16(chanspec); |
| 1491 | join_params.params_le.chanspec_num = cpu_to_le32(1); |
| 1492 | join_params_size += sizeof(join_params.params_le); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1493 | } |
| 1494 | |
| 1495 | /* set channel for starter */ |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 1496 | target_channel = cfg->channel; |
Hante Meuleman | b87e2c4 | 2012-11-14 18:46:23 -0800 | [diff] [blame] | 1497 | err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_CHANNEL, |
Hante Meuleman | 81f5dcb | 2012-10-22 10:36:14 -0700 | [diff] [blame] | 1498 | target_channel); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1499 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1500 | brcmf_err("WLC_SET_CHANNEL failed (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1501 | goto done; |
| 1502 | } |
| 1503 | } else |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 1504 | cfg->channel = 0; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1505 | |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 1506 | cfg->ibss_starter = false; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1507 | |
| 1508 | |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 1509 | err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SET_SSID, |
Hante Meuleman | 81f5dcb | 2012-10-22 10:36:14 -0700 | [diff] [blame] | 1510 | &join_params, join_params_size); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1511 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1512 | brcmf_err("WLC_SET_SSID failed (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1513 | goto done; |
| 1514 | } |
| 1515 | |
| 1516 | done: |
| 1517 | if (err) |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 1518 | clear_bit(BRCMF_VIF_STATUS_CONNECTING, &ifp->vif->sme_state); |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 1519 | brcmf_dbg(TRACE, "Exit\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1520 | return err; |
| 1521 | } |
| 1522 | |
| 1523 | static s32 |
| 1524 | brcmf_cfg80211_leave_ibss(struct wiphy *wiphy, struct net_device *ndev) |
| 1525 | { |
Arend van Spriel | 0abb5f21 | 2012-10-22 13:55:32 -0700 | [diff] [blame] | 1526 | struct brcmf_if *ifp = netdev_priv(ndev); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1527 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 1528 | brcmf_dbg(TRACE, "Enter\n"); |
Hante Meuleman | 6a98d64 | 2016-01-02 09:41:40 +0100 | [diff] [blame] | 1529 | if (!check_vif_up(ifp->vif)) { |
| 1530 | /* When driver is being unloaded, it can end up here. If an |
| 1531 | * error is returned then later on a debug trace in the wireless |
| 1532 | * core module will be printed. To avoid this 0 is returned. |
| 1533 | */ |
| 1534 | return 0; |
| 1535 | } |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1536 | |
Arend van Spriel | 9b7a0dd | 2015-01-25 20:31:33 +0100 | [diff] [blame] | 1537 | brcmf_link_down(ifp->vif, WLAN_REASON_DEAUTH_LEAVING); |
Hante Meuleman | 42e0ed0 | 2016-01-05 11:05:50 +0100 | [diff] [blame] | 1538 | brcmf_net_setcarrier(ifp, false); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1539 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 1540 | brcmf_dbg(TRACE, "Exit\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1541 | |
Peter Senna Tschudin | 12f3237 | 2014-05-31 10:14:06 -0300 | [diff] [blame] | 1542 | return 0; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1543 | } |
| 1544 | |
| 1545 | static s32 brcmf_set_wpa_version(struct net_device *ndev, |
| 1546 | struct cfg80211_connect_params *sme) |
| 1547 | { |
Arend van Spriel | 6ac4f4e | 2012-10-22 13:55:31 -0700 | [diff] [blame] | 1548 | struct brcmf_cfg80211_profile *profile = ndev_to_prof(ndev); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1549 | struct brcmf_cfg80211_security *sec; |
| 1550 | s32 val = 0; |
| 1551 | s32 err = 0; |
| 1552 | |
| 1553 | if (sme->crypto.wpa_versions & NL80211_WPA_VERSION_1) |
| 1554 | val = WPA_AUTH_PSK | WPA_AUTH_UNSPECIFIED; |
| 1555 | else if (sme->crypto.wpa_versions & NL80211_WPA_VERSION_2) |
| 1556 | val = WPA2_AUTH_PSK | WPA2_AUTH_UNSPECIFIED; |
| 1557 | else |
| 1558 | val = WPA_AUTH_DISABLED; |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 1559 | brcmf_dbg(CONN, "setting wpa_auth to 0x%0x\n", val); |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 1560 | 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] | 1561 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1562 | brcmf_err("set wpa_auth failed (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1563 | return err; |
| 1564 | } |
Arend van Spriel | 06bb123 | 2012-09-27 14:17:56 +0200 | [diff] [blame] | 1565 | sec = &profile->sec; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1566 | sec->wpa_versions = sme->crypto.wpa_versions; |
| 1567 | return err; |
| 1568 | } |
| 1569 | |
| 1570 | static s32 brcmf_set_auth_type(struct net_device *ndev, |
| 1571 | struct cfg80211_connect_params *sme) |
| 1572 | { |
Arend van Spriel | 6ac4f4e | 2012-10-22 13:55:31 -0700 | [diff] [blame] | 1573 | struct brcmf_cfg80211_profile *profile = ndev_to_prof(ndev); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1574 | struct brcmf_cfg80211_security *sec; |
| 1575 | s32 val = 0; |
| 1576 | s32 err = 0; |
| 1577 | |
| 1578 | switch (sme->auth_type) { |
| 1579 | case NL80211_AUTHTYPE_OPEN_SYSTEM: |
| 1580 | val = 0; |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 1581 | brcmf_dbg(CONN, "open system\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1582 | break; |
| 1583 | case NL80211_AUTHTYPE_SHARED_KEY: |
| 1584 | val = 1; |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 1585 | brcmf_dbg(CONN, "shared key\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1586 | break; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1587 | default: |
| 1588 | val = 2; |
Hante Meuleman | 92c3136 | 2016-09-19 12:09:59 +0100 | [diff] [blame] | 1589 | brcmf_dbg(CONN, "automatic, auth type (%d)\n", sme->auth_type); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1590 | break; |
| 1591 | } |
| 1592 | |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 1593 | err = brcmf_fil_bsscfg_int_set(netdev_priv(ndev), "auth", val); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1594 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1595 | brcmf_err("set auth failed (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1596 | return err; |
| 1597 | } |
Arend van Spriel | 06bb123 | 2012-09-27 14:17:56 +0200 | [diff] [blame] | 1598 | sec = &profile->sec; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1599 | sec->auth_type = sme->auth_type; |
| 1600 | return err; |
| 1601 | } |
| 1602 | |
| 1603 | static s32 |
Daniel Kim | 87b7e9e | 2014-03-25 21:45:09 +0100 | [diff] [blame] | 1604 | brcmf_set_wsec_mode(struct net_device *ndev, |
Hante Meuleman | 240d61a | 2016-02-17 11:27:10 +0100 | [diff] [blame] | 1605 | struct cfg80211_connect_params *sme) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1606 | { |
Arend van Spriel | 6ac4f4e | 2012-10-22 13:55:31 -0700 | [diff] [blame] | 1607 | struct brcmf_cfg80211_profile *profile = ndev_to_prof(ndev); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1608 | struct brcmf_cfg80211_security *sec; |
| 1609 | s32 pval = 0; |
| 1610 | s32 gval = 0; |
Daniel Kim | 87b7e9e | 2014-03-25 21:45:09 +0100 | [diff] [blame] | 1611 | s32 wsec; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1612 | s32 err = 0; |
| 1613 | |
| 1614 | if (sme->crypto.n_ciphers_pairwise) { |
| 1615 | switch (sme->crypto.ciphers_pairwise[0]) { |
| 1616 | case WLAN_CIPHER_SUITE_WEP40: |
| 1617 | case WLAN_CIPHER_SUITE_WEP104: |
| 1618 | pval = WEP_ENABLED; |
| 1619 | break; |
| 1620 | case WLAN_CIPHER_SUITE_TKIP: |
| 1621 | pval = TKIP_ENABLED; |
| 1622 | break; |
| 1623 | case WLAN_CIPHER_SUITE_CCMP: |
| 1624 | pval = AES_ENABLED; |
| 1625 | break; |
| 1626 | case WLAN_CIPHER_SUITE_AES_CMAC: |
| 1627 | pval = AES_ENABLED; |
| 1628 | break; |
| 1629 | default: |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1630 | brcmf_err("invalid cipher pairwise (%d)\n", |
| 1631 | sme->crypto.ciphers_pairwise[0]); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1632 | return -EINVAL; |
| 1633 | } |
| 1634 | } |
| 1635 | if (sme->crypto.cipher_group) { |
| 1636 | switch (sme->crypto.cipher_group) { |
| 1637 | case WLAN_CIPHER_SUITE_WEP40: |
| 1638 | case WLAN_CIPHER_SUITE_WEP104: |
| 1639 | gval = WEP_ENABLED; |
| 1640 | break; |
| 1641 | case WLAN_CIPHER_SUITE_TKIP: |
| 1642 | gval = TKIP_ENABLED; |
| 1643 | break; |
| 1644 | case WLAN_CIPHER_SUITE_CCMP: |
| 1645 | gval = AES_ENABLED; |
| 1646 | break; |
| 1647 | case WLAN_CIPHER_SUITE_AES_CMAC: |
| 1648 | gval = AES_ENABLED; |
| 1649 | break; |
| 1650 | default: |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1651 | brcmf_err("invalid cipher group (%d)\n", |
| 1652 | sme->crypto.cipher_group); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1653 | return -EINVAL; |
| 1654 | } |
| 1655 | } |
| 1656 | |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 1657 | brcmf_dbg(CONN, "pval (%d) gval (%d)\n", pval, gval); |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 1658 | /* In case of privacy, but no security and WPS then simulate */ |
| 1659 | /* setting AES. WPS-2.0 allows no security */ |
| 1660 | if (brcmf_find_wpsie(sme->ie, sme->ie_len) && !pval && !gval && |
| 1661 | sme->privacy) |
| 1662 | pval = AES_ENABLED; |
Daniel Kim | 87b7e9e | 2014-03-25 21:45:09 +0100 | [diff] [blame] | 1663 | |
Hante Meuleman | 240d61a | 2016-02-17 11:27:10 +0100 | [diff] [blame] | 1664 | wsec = pval | gval; |
Daniel Kim | 87b7e9e | 2014-03-25 21:45:09 +0100 | [diff] [blame] | 1665 | err = brcmf_fil_bsscfg_int_set(netdev_priv(ndev), "wsec", wsec); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1666 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1667 | brcmf_err("error (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1668 | return err; |
| 1669 | } |
| 1670 | |
Arend van Spriel | 06bb123 | 2012-09-27 14:17:56 +0200 | [diff] [blame] | 1671 | sec = &profile->sec; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1672 | sec->cipher_pairwise = sme->crypto.ciphers_pairwise[0]; |
| 1673 | sec->cipher_group = sme->crypto.cipher_group; |
| 1674 | |
| 1675 | return err; |
| 1676 | } |
| 1677 | |
| 1678 | static s32 |
| 1679 | brcmf_set_key_mgmt(struct net_device *ndev, struct cfg80211_connect_params *sme) |
| 1680 | { |
Hante Meuleman | 240d61a | 2016-02-17 11:27:10 +0100 | [diff] [blame] | 1681 | struct brcmf_if *ifp = netdev_priv(ndev); |
| 1682 | s32 val; |
| 1683 | s32 err; |
| 1684 | const struct brcmf_tlv *rsn_ie; |
| 1685 | const u8 *ie; |
| 1686 | u32 ie_len; |
| 1687 | u32 offset; |
| 1688 | u16 rsn_cap; |
| 1689 | u32 mfp; |
| 1690 | u16 count; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1691 | |
Hante Meuleman | 240d61a | 2016-02-17 11:27:10 +0100 | [diff] [blame] | 1692 | if (!sme->crypto.n_akm_suites) |
| 1693 | return 0; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1694 | |
Hante Meuleman | 240d61a | 2016-02-17 11:27:10 +0100 | [diff] [blame] | 1695 | err = brcmf_fil_bsscfg_int_get(netdev_priv(ndev), "wpa_auth", &val); |
| 1696 | if (err) { |
| 1697 | brcmf_err("could not get wpa_auth (%d)\n", err); |
| 1698 | return err; |
| 1699 | } |
| 1700 | if (val & (WPA_AUTH_PSK | WPA_AUTH_UNSPECIFIED)) { |
| 1701 | switch (sme->crypto.akm_suites[0]) { |
| 1702 | case WLAN_AKM_SUITE_8021X: |
| 1703 | val = WPA_AUTH_UNSPECIFIED; |
| 1704 | break; |
| 1705 | case WLAN_AKM_SUITE_PSK: |
| 1706 | val = WPA_AUTH_PSK; |
| 1707 | break; |
| 1708 | default: |
| 1709 | brcmf_err("invalid cipher group (%d)\n", |
| 1710 | sme->crypto.cipher_group); |
| 1711 | return -EINVAL; |
| 1712 | } |
| 1713 | } else if (val & (WPA2_AUTH_PSK | WPA2_AUTH_UNSPECIFIED)) { |
| 1714 | switch (sme->crypto.akm_suites[0]) { |
| 1715 | case WLAN_AKM_SUITE_8021X: |
| 1716 | val = WPA2_AUTH_UNSPECIFIED; |
| 1717 | break; |
| 1718 | case WLAN_AKM_SUITE_8021X_SHA256: |
| 1719 | val = WPA2_AUTH_1X_SHA256; |
| 1720 | break; |
| 1721 | case WLAN_AKM_SUITE_PSK_SHA256: |
| 1722 | val = WPA2_AUTH_PSK_SHA256; |
| 1723 | break; |
| 1724 | case WLAN_AKM_SUITE_PSK: |
| 1725 | val = WPA2_AUTH_PSK; |
| 1726 | break; |
| 1727 | default: |
| 1728 | brcmf_err("invalid cipher group (%d)\n", |
| 1729 | sme->crypto.cipher_group); |
| 1730 | return -EINVAL; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1731 | } |
| 1732 | } |
Hante Meuleman | 240d61a | 2016-02-17 11:27:10 +0100 | [diff] [blame] | 1733 | |
| 1734 | if (!brcmf_feat_is_enabled(ifp, BRCMF_FEAT_MFP)) |
| 1735 | goto skip_mfp_config; |
| 1736 | /* The MFP mode (1 or 2) needs to be determined, parse IEs. The |
| 1737 | * IE will not be verified, just a quick search for MFP config |
| 1738 | */ |
| 1739 | rsn_ie = brcmf_parse_tlvs((const u8 *)sme->ie, sme->ie_len, |
| 1740 | WLAN_EID_RSN); |
| 1741 | if (!rsn_ie) |
| 1742 | goto skip_mfp_config; |
| 1743 | ie = (const u8 *)rsn_ie; |
| 1744 | ie_len = rsn_ie->len + TLV_HDR_LEN; |
| 1745 | /* Skip unicast suite */ |
| 1746 | offset = TLV_HDR_LEN + WPA_IE_VERSION_LEN + WPA_IE_MIN_OUI_LEN; |
| 1747 | if (offset + WPA_IE_SUITE_COUNT_LEN >= ie_len) |
| 1748 | goto skip_mfp_config; |
| 1749 | /* Skip multicast suite */ |
| 1750 | count = ie[offset] + (ie[offset + 1] << 8); |
| 1751 | offset += WPA_IE_SUITE_COUNT_LEN + (count * WPA_IE_MIN_OUI_LEN); |
| 1752 | if (offset + WPA_IE_SUITE_COUNT_LEN >= ie_len) |
| 1753 | goto skip_mfp_config; |
| 1754 | /* Skip auth key management suite(s) */ |
| 1755 | count = ie[offset] + (ie[offset + 1] << 8); |
| 1756 | offset += WPA_IE_SUITE_COUNT_LEN + (count * WPA_IE_MIN_OUI_LEN); |
| 1757 | if (offset + WPA_IE_SUITE_COUNT_LEN > ie_len) |
| 1758 | goto skip_mfp_config; |
| 1759 | /* Ready to read capabilities */ |
| 1760 | mfp = BRCMF_MFP_NONE; |
| 1761 | rsn_cap = ie[offset] + (ie[offset + 1] << 8); |
| 1762 | if (rsn_cap & RSN_CAP_MFPR_MASK) |
| 1763 | mfp = BRCMF_MFP_REQUIRED; |
| 1764 | else if (rsn_cap & RSN_CAP_MFPC_MASK) |
| 1765 | mfp = BRCMF_MFP_CAPABLE; |
| 1766 | brcmf_fil_bsscfg_int_set(netdev_priv(ndev), "mfp", mfp); |
| 1767 | |
| 1768 | skip_mfp_config: |
| 1769 | brcmf_dbg(CONN, "setting wpa_auth to %d\n", val); |
| 1770 | err = brcmf_fil_bsscfg_int_set(netdev_priv(ndev), "wpa_auth", val); |
| 1771 | if (err) { |
| 1772 | brcmf_err("could not set wpa_auth (%d)\n", err); |
| 1773 | return err; |
| 1774 | } |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1775 | |
| 1776 | return err; |
| 1777 | } |
| 1778 | |
| 1779 | static s32 |
Hante Meuleman | f09d0c0 | 2012-09-27 14:17:48 +0200 | [diff] [blame] | 1780 | brcmf_set_sharedkey(struct net_device *ndev, |
| 1781 | struct cfg80211_connect_params *sme) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1782 | { |
Arend van Spriel | 6ac4f4e | 2012-10-22 13:55:31 -0700 | [diff] [blame] | 1783 | struct brcmf_cfg80211_profile *profile = ndev_to_prof(ndev); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1784 | struct brcmf_cfg80211_security *sec; |
| 1785 | struct brcmf_wsec_key key; |
| 1786 | s32 val; |
| 1787 | s32 err = 0; |
| 1788 | |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 1789 | brcmf_dbg(CONN, "key len (%d)\n", sme->key_len); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1790 | |
Roland Vossen | a718e2f | 2011-10-12 20:51:24 +0200 | [diff] [blame] | 1791 | if (sme->key_len == 0) |
| 1792 | return 0; |
| 1793 | |
Arend van Spriel | 06bb123 | 2012-09-27 14:17:56 +0200 | [diff] [blame] | 1794 | sec = &profile->sec; |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 1795 | brcmf_dbg(CONN, "wpa_versions 0x%x cipher_pairwise 0x%x\n", |
| 1796 | sec->wpa_versions, sec->cipher_pairwise); |
Roland Vossen | a718e2f | 2011-10-12 20:51:24 +0200 | [diff] [blame] | 1797 | |
| 1798 | if (sec->wpa_versions & (NL80211_WPA_VERSION_1 | NL80211_WPA_VERSION_2)) |
| 1799 | return 0; |
| 1800 | |
Hante Meuleman | f09d0c0 | 2012-09-27 14:17:48 +0200 | [diff] [blame] | 1801 | if (!(sec->cipher_pairwise & |
| 1802 | (WLAN_CIPHER_SUITE_WEP40 | WLAN_CIPHER_SUITE_WEP104))) |
| 1803 | return 0; |
Roland Vossen | a718e2f | 2011-10-12 20:51:24 +0200 | [diff] [blame] | 1804 | |
Hante Meuleman | f09d0c0 | 2012-09-27 14:17:48 +0200 | [diff] [blame] | 1805 | memset(&key, 0, sizeof(key)); |
| 1806 | key.len = (u32) sme->key_len; |
| 1807 | key.index = (u32) sme->key_idx; |
| 1808 | if (key.len > sizeof(key.data)) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1809 | brcmf_err("Too long key length (%u)\n", key.len); |
Hante Meuleman | f09d0c0 | 2012-09-27 14:17:48 +0200 | [diff] [blame] | 1810 | return -EINVAL; |
| 1811 | } |
| 1812 | memcpy(key.data, sme->key, key.len); |
| 1813 | key.flags = BRCMF_PRIMARY_KEY; |
| 1814 | switch (sec->cipher_pairwise) { |
| 1815 | case WLAN_CIPHER_SUITE_WEP40: |
| 1816 | key.algo = CRYPTO_ALGO_WEP1; |
| 1817 | break; |
| 1818 | case WLAN_CIPHER_SUITE_WEP104: |
| 1819 | key.algo = CRYPTO_ALGO_WEP128; |
| 1820 | break; |
| 1821 | default: |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1822 | brcmf_err("Invalid algorithm (%d)\n", |
| 1823 | sme->crypto.ciphers_pairwise[0]); |
Hante Meuleman | f09d0c0 | 2012-09-27 14:17:48 +0200 | [diff] [blame] | 1824 | return -EINVAL; |
| 1825 | } |
| 1826 | /* Set the new key/index */ |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 1827 | brcmf_dbg(CONN, "key length (%d) key index (%d) algo (%d)\n", |
| 1828 | key.len, key.index, key.algo); |
| 1829 | brcmf_dbg(CONN, "key \"%s\"\n", key.data); |
Hante Meuleman | 118eb30 | 2014-12-21 12:43:49 +0100 | [diff] [blame] | 1830 | err = send_key_to_dongle(netdev_priv(ndev), &key); |
Hante Meuleman | f09d0c0 | 2012-09-27 14:17:48 +0200 | [diff] [blame] | 1831 | if (err) |
| 1832 | return err; |
| 1833 | |
| 1834 | if (sec->auth_type == NL80211_AUTHTYPE_SHARED_KEY) { |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 1835 | brcmf_dbg(CONN, "set auth_type to shared key\n"); |
Hante Meuleman | f09d0c0 | 2012-09-27 14:17:48 +0200 | [diff] [blame] | 1836 | val = WL_AUTH_SHARED_KEY; /* shared key */ |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 1837 | err = brcmf_fil_bsscfg_int_set(netdev_priv(ndev), "auth", val); |
Hante Meuleman | f09d0c0 | 2012-09-27 14:17:48 +0200 | [diff] [blame] | 1838 | if (err) |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1839 | brcmf_err("set auth failed (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1840 | } |
| 1841 | return err; |
| 1842 | } |
| 1843 | |
Arend van Spriel | cbb1ec9 | 2013-02-06 18:40:47 +0100 | [diff] [blame] | 1844 | static |
| 1845 | enum nl80211_auth_type brcmf_war_auth_type(struct brcmf_if *ifp, |
| 1846 | enum nl80211_auth_type type) |
| 1847 | { |
Arend van Spriel | c08437b | 2014-07-12 08:49:39 +0200 | [diff] [blame] | 1848 | if (type == NL80211_AUTHTYPE_AUTOMATIC && |
| 1849 | brcmf_feat_is_quirk_enabled(ifp, BRCMF_FEAT_QUIRK_AUTO_AUTH)) { |
| 1850 | brcmf_dbg(CONN, "WAR: use OPEN instead of AUTO\n"); |
| 1851 | type = NL80211_AUTHTYPE_OPEN_SYSTEM; |
Arend van Spriel | cbb1ec9 | 2013-02-06 18:40:47 +0100 | [diff] [blame] | 1852 | } |
| 1853 | return type; |
| 1854 | } |
| 1855 | |
Arend van Spriel | 7705ba6 | 2016-04-17 16:44:58 +0200 | [diff] [blame] | 1856 | static void brcmf_set_join_pref(struct brcmf_if *ifp, |
| 1857 | struct cfg80211_bss_selection *bss_select) |
| 1858 | { |
| 1859 | struct brcmf_join_pref_params join_pref_params[2]; |
| 1860 | enum nl80211_band band; |
| 1861 | int err, i = 0; |
| 1862 | |
| 1863 | join_pref_params[i].len = 2; |
| 1864 | join_pref_params[i].rssi_gain = 0; |
| 1865 | |
| 1866 | if (bss_select->behaviour != NL80211_BSS_SELECT_ATTR_BAND_PREF) |
| 1867 | brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_ASSOC_PREFER, WLC_BAND_AUTO); |
| 1868 | |
| 1869 | switch (bss_select->behaviour) { |
| 1870 | case __NL80211_BSS_SELECT_ATTR_INVALID: |
| 1871 | brcmf_c_set_joinpref_default(ifp); |
| 1872 | return; |
| 1873 | case NL80211_BSS_SELECT_ATTR_BAND_PREF: |
| 1874 | join_pref_params[i].type = BRCMF_JOIN_PREF_BAND; |
| 1875 | band = bss_select->param.band_pref; |
| 1876 | join_pref_params[i].band = nl80211_band_to_fwil(band); |
| 1877 | i++; |
| 1878 | break; |
| 1879 | case NL80211_BSS_SELECT_ATTR_RSSI_ADJUST: |
| 1880 | join_pref_params[i].type = BRCMF_JOIN_PREF_RSSI_DELTA; |
| 1881 | band = bss_select->param.adjust.band; |
| 1882 | join_pref_params[i].band = nl80211_band_to_fwil(band); |
| 1883 | join_pref_params[i].rssi_gain = bss_select->param.adjust.delta; |
| 1884 | i++; |
| 1885 | break; |
| 1886 | case NL80211_BSS_SELECT_ATTR_RSSI: |
| 1887 | default: |
| 1888 | break; |
| 1889 | } |
| 1890 | join_pref_params[i].type = BRCMF_JOIN_PREF_RSSI; |
| 1891 | join_pref_params[i].len = 2; |
| 1892 | join_pref_params[i].rssi_gain = 0; |
| 1893 | join_pref_params[i].band = 0; |
| 1894 | err = brcmf_fil_iovar_data_set(ifp, "join_pref", join_pref_params, |
| 1895 | sizeof(join_pref_params)); |
| 1896 | if (err) |
| 1897 | brcmf_err("Set join_pref error (%d)\n", err); |
| 1898 | } |
| 1899 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1900 | static s32 |
| 1901 | brcmf_cfg80211_connect(struct wiphy *wiphy, struct net_device *ndev, |
Arend van Spriel | cbb1ec9 | 2013-02-06 18:40:47 +0100 | [diff] [blame] | 1902 | struct cfg80211_connect_params *sme) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1903 | { |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 1904 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); |
Arend van Spriel | 0abb5f21 | 2012-10-22 13:55:32 -0700 | [diff] [blame] | 1905 | struct brcmf_if *ifp = netdev_priv(ndev); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1906 | struct ieee80211_channel *chan = sme->channel; |
| 1907 | struct brcmf_join_params join_params; |
| 1908 | size_t join_params_size; |
Johannes Berg | 4b5800f | 2014-01-15 14:55:59 +0100 | [diff] [blame] | 1909 | const struct brcmf_tlv *rsn_ie; |
| 1910 | const struct brcmf_vs_tlv *wpa_ie; |
| 1911 | const void *ie; |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 1912 | u32 ie_len; |
| 1913 | struct brcmf_ext_join_params_le *ext_join_params; |
Hante Meuleman | 1701261 | 2013-02-06 18:40:44 +0100 | [diff] [blame] | 1914 | u16 chanspec; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1915 | s32 err = 0; |
Hante Meuleman | e9a6ca8 | 2015-11-25 11:32:37 +0100 | [diff] [blame] | 1916 | u32 ssid_len; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1917 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 1918 | brcmf_dbg(TRACE, "Enter\n"); |
Arend van Spriel | ce81e31 | 2012-10-22 13:55:37 -0700 | [diff] [blame] | 1919 | if (!check_vif_up(ifp->vif)) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1920 | return -EIO; |
| 1921 | |
| 1922 | if (!sme->ssid) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1923 | brcmf_err("Invalid ssid\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1924 | return -EOPNOTSUPP; |
| 1925 | } |
| 1926 | |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 1927 | if (ifp->vif == cfg->p2p.bss_idx[P2PAPI_BSSCFG_PRIMARY].vif) { |
| 1928 | /* A normal (non P2P) connection request setup. */ |
| 1929 | ie = NULL; |
| 1930 | ie_len = 0; |
| 1931 | /* find the WPA_IE */ |
| 1932 | wpa_ie = brcmf_find_wpaie((u8 *)sme->ie, sme->ie_len); |
| 1933 | if (wpa_ie) { |
| 1934 | ie = wpa_ie; |
| 1935 | ie_len = wpa_ie->len + TLV_HDR_LEN; |
| 1936 | } else { |
| 1937 | /* find the RSN_IE */ |
Johannes Berg | 4b5800f | 2014-01-15 14:55:59 +0100 | [diff] [blame] | 1938 | rsn_ie = brcmf_parse_tlvs((const u8 *)sme->ie, |
| 1939 | sme->ie_len, |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 1940 | WLAN_EID_RSN); |
| 1941 | if (rsn_ie) { |
| 1942 | ie = rsn_ie; |
| 1943 | ie_len = rsn_ie->len + TLV_HDR_LEN; |
| 1944 | } |
| 1945 | } |
| 1946 | brcmf_fil_iovar_data_set(ifp, "wpaie", ie, ie_len); |
| 1947 | } |
| 1948 | |
| 1949 | err = brcmf_vif_set_mgmt_ie(ifp->vif, BRCMF_VNDR_IE_ASSOCREQ_FLAG, |
| 1950 | sme->ie, sme->ie_len); |
| 1951 | if (err) |
| 1952 | brcmf_err("Set Assoc REQ IE Failed\n"); |
| 1953 | else |
| 1954 | brcmf_dbg(TRACE, "Applied Vndr IEs for Assoc request\n"); |
| 1955 | |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 1956 | set_bit(BRCMF_VIF_STATUS_CONNECTING, &ifp->vif->sme_state); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1957 | |
| 1958 | if (chan) { |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 1959 | cfg->channel = |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1960 | ieee80211_frequency_to_channel(chan->center_freq); |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 1961 | chanspec = channel_to_chanspec(&cfg->d11inf, chan); |
Hante Meuleman | 1701261 | 2013-02-06 18:40:44 +0100 | [diff] [blame] | 1962 | brcmf_dbg(CONN, "channel=%d, center_req=%d, chanspec=0x%04x\n", |
| 1963 | cfg->channel, chan->center_freq, chanspec); |
| 1964 | } else { |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 1965 | cfg->channel = 0; |
Hante Meuleman | 1701261 | 2013-02-06 18:40:44 +0100 | [diff] [blame] | 1966 | chanspec = 0; |
| 1967 | } |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1968 | |
Arend van Spriel | 647c9ae | 2012-12-05 15:26:01 +0100 | [diff] [blame] | 1969 | 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] | 1970 | |
| 1971 | err = brcmf_set_wpa_version(ndev, sme); |
| 1972 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1973 | brcmf_err("wl_set_wpa_version failed (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1974 | goto done; |
| 1975 | } |
| 1976 | |
Arend van Spriel | cbb1ec9 | 2013-02-06 18:40:47 +0100 | [diff] [blame] | 1977 | sme->auth_type = brcmf_war_auth_type(ifp, sme->auth_type); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1978 | err = brcmf_set_auth_type(ndev, sme); |
| 1979 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1980 | brcmf_err("wl_set_auth_type failed (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1981 | goto done; |
| 1982 | } |
| 1983 | |
Hante Meuleman | 240d61a | 2016-02-17 11:27:10 +0100 | [diff] [blame] | 1984 | err = brcmf_set_wsec_mode(ndev, sme); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1985 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1986 | brcmf_err("wl_set_set_cipher failed (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1987 | goto done; |
| 1988 | } |
| 1989 | |
| 1990 | err = brcmf_set_key_mgmt(ndev, sme); |
| 1991 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1992 | brcmf_err("wl_set_key_mgmt failed (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1993 | goto done; |
| 1994 | } |
| 1995 | |
Hante Meuleman | f09d0c0 | 2012-09-27 14:17:48 +0200 | [diff] [blame] | 1996 | err = brcmf_set_sharedkey(ndev, sme); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1997 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1998 | brcmf_err("brcmf_set_sharedkey failed (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1999 | goto done; |
| 2000 | } |
| 2001 | |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 2002 | /* Join with specific BSSID and cached SSID |
| 2003 | * If SSID is zero join based on BSSID only |
| 2004 | */ |
| 2005 | join_params_size = offsetof(struct brcmf_ext_join_params_le, assoc_le) + |
| 2006 | offsetof(struct brcmf_assoc_params_le, chanspec_list); |
| 2007 | if (cfg->channel) |
| 2008 | join_params_size += sizeof(u16); |
| 2009 | ext_join_params = kzalloc(join_params_size, GFP_KERNEL); |
| 2010 | if (ext_join_params == NULL) { |
| 2011 | err = -ENOMEM; |
| 2012 | goto done; |
| 2013 | } |
Hante Meuleman | e9a6ca8 | 2015-11-25 11:32:37 +0100 | [diff] [blame] | 2014 | ssid_len = min_t(u32, sme->ssid_len, IEEE80211_MAX_SSID_LEN); |
| 2015 | ext_join_params->ssid_le.SSID_len = cpu_to_le32(ssid_len); |
| 2016 | memcpy(&ext_join_params->ssid_le.SSID, sme->ssid, ssid_len); |
| 2017 | if (ssid_len < IEEE80211_MAX_SSID_LEN) |
| 2018 | brcmf_dbg(CONN, "SSID \"%s\", len (%d)\n", |
| 2019 | ext_join_params->ssid_le.SSID, ssid_len); |
Hante Meuleman | 63dd99e | 2014-03-15 17:18:19 +0100 | [diff] [blame] | 2020 | |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 2021 | /* Set up join scan parameters */ |
| 2022 | ext_join_params->scan_le.scan_type = -1; |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 2023 | ext_join_params->scan_le.home_time = cpu_to_le32(-1); |
| 2024 | |
| 2025 | if (sme->bssid) |
| 2026 | memcpy(&ext_join_params->assoc_le.bssid, sme->bssid, ETH_ALEN); |
| 2027 | else |
Joe Perches | 93803b3 | 2015-03-02 19:54:49 -0800 | [diff] [blame] | 2028 | eth_broadcast_addr(ext_join_params->assoc_le.bssid); |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 2029 | |
| 2030 | if (cfg->channel) { |
| 2031 | ext_join_params->assoc_le.chanspec_num = cpu_to_le32(1); |
| 2032 | |
| 2033 | ext_join_params->assoc_le.chanspec_list[0] = |
| 2034 | cpu_to_le16(chanspec); |
Hante Meuleman | 63dd99e | 2014-03-15 17:18:19 +0100 | [diff] [blame] | 2035 | /* Increase dwell time to receive probe response or detect |
| 2036 | * beacon from target AP at a noisy air only during connect |
| 2037 | * command. |
| 2038 | */ |
| 2039 | ext_join_params->scan_le.active_time = |
| 2040 | cpu_to_le32(BRCMF_SCAN_JOIN_ACTIVE_DWELL_TIME_MS); |
| 2041 | ext_join_params->scan_le.passive_time = |
| 2042 | cpu_to_le32(BRCMF_SCAN_JOIN_PASSIVE_DWELL_TIME_MS); |
| 2043 | /* To sync with presence period of VSDB GO send probe request |
| 2044 | * more frequently. Probe request will be stopped when it gets |
| 2045 | * probe response from target AP/GO. |
| 2046 | */ |
| 2047 | ext_join_params->scan_le.nprobes = |
| 2048 | cpu_to_le32(BRCMF_SCAN_JOIN_ACTIVE_DWELL_TIME_MS / |
| 2049 | BRCMF_SCAN_JOIN_PROBE_INTERVAL_MS); |
| 2050 | } else { |
| 2051 | ext_join_params->scan_le.active_time = cpu_to_le32(-1); |
| 2052 | ext_join_params->scan_le.passive_time = cpu_to_le32(-1); |
| 2053 | ext_join_params->scan_le.nprobes = cpu_to_le32(-1); |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 2054 | } |
| 2055 | |
Arend van Spriel | 7705ba6 | 2016-04-17 16:44:58 +0200 | [diff] [blame] | 2056 | brcmf_set_join_pref(ifp, &sme->bss_select); |
| 2057 | |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 2058 | err = brcmf_fil_bsscfg_data_set(ifp, "join", ext_join_params, |
| 2059 | join_params_size); |
| 2060 | kfree(ext_join_params); |
| 2061 | if (!err) |
| 2062 | /* This is it. join command worked, we are done */ |
| 2063 | goto done; |
| 2064 | |
| 2065 | /* join command failed, fallback to set ssid */ |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2066 | memset(&join_params, 0, sizeof(join_params)); |
| 2067 | join_params_size = sizeof(join_params.ssid_le); |
| 2068 | |
Hante Meuleman | e9a6ca8 | 2015-11-25 11:32:37 +0100 | [diff] [blame] | 2069 | memcpy(&join_params.ssid_le.SSID, sme->ssid, ssid_len); |
| 2070 | join_params.ssid_le.SSID_len = cpu_to_le32(ssid_len); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2071 | |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 2072 | if (sme->bssid) |
| 2073 | memcpy(join_params.params_le.bssid, sme->bssid, ETH_ALEN); |
| 2074 | else |
Joe Perches | 93803b3 | 2015-03-02 19:54:49 -0800 | [diff] [blame] | 2075 | eth_broadcast_addr(join_params.params_le.bssid); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2076 | |
Hante Meuleman | 1701261 | 2013-02-06 18:40:44 +0100 | [diff] [blame] | 2077 | if (cfg->channel) { |
| 2078 | join_params.params_le.chanspec_list[0] = cpu_to_le16(chanspec); |
| 2079 | join_params.params_le.chanspec_num = cpu_to_le32(1); |
| 2080 | join_params_size += sizeof(join_params.params_le); |
| 2081 | } |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 2082 | err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SET_SSID, |
Hante Meuleman | 81f5dcb | 2012-10-22 10:36:14 -0700 | [diff] [blame] | 2083 | &join_params, join_params_size); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2084 | if (err) |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 2085 | brcmf_err("BRCMF_C_SET_SSID failed (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2086 | |
| 2087 | done: |
| 2088 | if (err) |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 2089 | clear_bit(BRCMF_VIF_STATUS_CONNECTING, &ifp->vif->sme_state); |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 2090 | brcmf_dbg(TRACE, "Exit\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2091 | return err; |
| 2092 | } |
| 2093 | |
| 2094 | static s32 |
| 2095 | brcmf_cfg80211_disconnect(struct wiphy *wiphy, struct net_device *ndev, |
| 2096 | u16 reason_code) |
| 2097 | { |
Arend van Spriel | 0abb5f21 | 2012-10-22 13:55:32 -0700 | [diff] [blame] | 2098 | struct brcmf_if *ifp = netdev_priv(ndev); |
| 2099 | struct brcmf_cfg80211_profile *profile = &ifp->vif->profile; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2100 | struct brcmf_scb_val_le scbval; |
| 2101 | s32 err = 0; |
| 2102 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 2103 | brcmf_dbg(TRACE, "Enter. Reason code = %d\n", reason_code); |
Arend van Spriel | ce81e31 | 2012-10-22 13:55:37 -0700 | [diff] [blame] | 2104 | if (!check_vif_up(ifp->vif)) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2105 | return -EIO; |
| 2106 | |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 2107 | clear_bit(BRCMF_VIF_STATUS_CONNECTED, &ifp->vif->sme_state); |
Arend van Spriel | 4f3fff1 | 2014-11-20 22:27:02 +0100 | [diff] [blame] | 2108 | clear_bit(BRCMF_VIF_STATUS_CONNECTING, &ifp->vif->sme_state); |
Johannes Berg | 80279fb | 2015-05-22 16:22:20 +0200 | [diff] [blame] | 2109 | cfg80211_disconnected(ndev, reason_code, NULL, 0, true, GFP_KERNEL); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2110 | |
Arend van Spriel | 06bb123 | 2012-09-27 14:17:56 +0200 | [diff] [blame] | 2111 | memcpy(&scbval.ea, &profile->bssid, ETH_ALEN); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2112 | scbval.val = cpu_to_le32(reason_code); |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 2113 | err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_DISASSOC, |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 2114 | &scbval, sizeof(scbval)); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2115 | if (err) |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 2116 | brcmf_err("error (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2117 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 2118 | brcmf_dbg(TRACE, "Exit\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2119 | return err; |
| 2120 | } |
| 2121 | |
| 2122 | static s32 |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 2123 | 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] | 2124 | enum nl80211_tx_power_setting type, s32 mbm) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2125 | { |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 2126 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); |
Arend van Spriel | 0abb5f21 | 2012-10-22 13:55:32 -0700 | [diff] [blame] | 2127 | struct net_device *ndev = cfg_to_ndev(cfg); |
| 2128 | struct brcmf_if *ifp = netdev_priv(ndev); |
Hante Meuleman | 60dc35e | 2015-09-18 22:08:06 +0200 | [diff] [blame] | 2129 | s32 err; |
| 2130 | s32 disable; |
| 2131 | u32 qdbm = 127; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2132 | |
Hante Meuleman | 60dc35e | 2015-09-18 22:08:06 +0200 | [diff] [blame] | 2133 | brcmf_dbg(TRACE, "Enter %d %d\n", type, mbm); |
Arend van Spriel | ce81e31 | 2012-10-22 13:55:37 -0700 | [diff] [blame] | 2134 | if (!check_vif_up(ifp->vif)) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2135 | return -EIO; |
| 2136 | |
| 2137 | switch (type) { |
| 2138 | case NL80211_TX_POWER_AUTOMATIC: |
| 2139 | break; |
| 2140 | case NL80211_TX_POWER_LIMITED: |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2141 | case NL80211_TX_POWER_FIXED: |
Hante Meuleman | 60dc35e | 2015-09-18 22:08:06 +0200 | [diff] [blame] | 2142 | if (mbm < 0) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 2143 | brcmf_err("TX_POWER_FIXED - dbm is negative\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2144 | err = -EINVAL; |
| 2145 | goto done; |
| 2146 | } |
Hante Meuleman | 60dc35e | 2015-09-18 22:08:06 +0200 | [diff] [blame] | 2147 | qdbm = MBM_TO_DBM(4 * mbm); |
| 2148 | if (qdbm > 127) |
| 2149 | qdbm = 127; |
| 2150 | qdbm |= WL_TXPWR_OVERRIDE; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2151 | break; |
Hante Meuleman | 60dc35e | 2015-09-18 22:08:06 +0200 | [diff] [blame] | 2152 | default: |
| 2153 | brcmf_err("Unsupported type %d\n", type); |
| 2154 | err = -EINVAL; |
| 2155 | goto done; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2156 | } |
| 2157 | /* Make sure radio is off or on as far as software is concerned */ |
| 2158 | disable = WL_RADIO_SW_DISABLE << 16; |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 2159 | 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] | 2160 | if (err) |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 2161 | brcmf_err("WLC_SET_RADIO error (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2162 | |
Hante Meuleman | 60dc35e | 2015-09-18 22:08:06 +0200 | [diff] [blame] | 2163 | err = brcmf_fil_iovar_int_set(ifp, "qtxpower", qdbm); |
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("qtxpower error (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2166 | |
| 2167 | done: |
Hante Meuleman | 60dc35e | 2015-09-18 22:08:06 +0200 | [diff] [blame] | 2168 | brcmf_dbg(TRACE, "Exit %d (qdbm)\n", qdbm & ~WL_TXPWR_OVERRIDE); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2169 | return err; |
| 2170 | } |
| 2171 | |
Hante Meuleman | 60dc35e | 2015-09-18 22:08:06 +0200 | [diff] [blame] | 2172 | static s32 |
| 2173 | brcmf_cfg80211_get_tx_power(struct wiphy *wiphy, struct wireless_dev *wdev, |
| 2174 | s32 *dbm) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2175 | { |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 2176 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); |
Hante Meuleman | 60dc35e | 2015-09-18 22:08:06 +0200 | [diff] [blame] | 2177 | struct net_device *ndev = cfg_to_ndev(cfg); |
| 2178 | struct brcmf_if *ifp = netdev_priv(ndev); |
| 2179 | s32 qdbm = 0; |
| 2180 | s32 err; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2181 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 2182 | brcmf_dbg(TRACE, "Enter\n"); |
Arend van Spriel | ce81e31 | 2012-10-22 13:55:37 -0700 | [diff] [blame] | 2183 | if (!check_vif_up(ifp->vif)) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2184 | return -EIO; |
| 2185 | |
Hante Meuleman | 60dc35e | 2015-09-18 22:08:06 +0200 | [diff] [blame] | 2186 | err = brcmf_fil_iovar_int_get(ifp, "qtxpower", &qdbm); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2187 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 2188 | brcmf_err("error (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2189 | goto done; |
| 2190 | } |
Hante Meuleman | 60dc35e | 2015-09-18 22:08:06 +0200 | [diff] [blame] | 2191 | *dbm = (qdbm & ~WL_TXPWR_OVERRIDE) / 4; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2192 | |
| 2193 | done: |
Hante Meuleman | 60dc35e | 2015-09-18 22:08:06 +0200 | [diff] [blame] | 2194 | brcmf_dbg(TRACE, "Exit (0x%x %d)\n", qdbm, *dbm); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2195 | return err; |
| 2196 | } |
| 2197 | |
| 2198 | static s32 |
| 2199 | brcmf_cfg80211_config_default_key(struct wiphy *wiphy, struct net_device *ndev, |
Hante Meuleman | 60dc35e | 2015-09-18 22:08:06 +0200 | [diff] [blame] | 2200 | u8 key_idx, bool unicast, bool multicast) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2201 | { |
Arend van Spriel | 0abb5f21 | 2012-10-22 13:55:32 -0700 | [diff] [blame] | 2202 | struct brcmf_if *ifp = netdev_priv(ndev); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2203 | u32 index; |
| 2204 | u32 wsec; |
| 2205 | s32 err = 0; |
| 2206 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 2207 | brcmf_dbg(TRACE, "Enter\n"); |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 2208 | brcmf_dbg(CONN, "key index (%d)\n", key_idx); |
Arend van Spriel | ce81e31 | 2012-10-22 13:55:37 -0700 | [diff] [blame] | 2209 | if (!check_vif_up(ifp->vif)) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2210 | return -EIO; |
| 2211 | |
Arend van Spriel | 0abb5f21 | 2012-10-22 13:55:32 -0700 | [diff] [blame] | 2212 | err = brcmf_fil_bsscfg_int_get(ifp, "wsec", &wsec); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2213 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 2214 | brcmf_err("WLC_GET_WSEC error (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2215 | goto done; |
| 2216 | } |
| 2217 | |
| 2218 | if (wsec & WEP_ENABLED) { |
| 2219 | /* Just select a new current key */ |
| 2220 | index = key_idx; |
Arend van Spriel | 0abb5f21 | 2012-10-22 13:55:32 -0700 | [diff] [blame] | 2221 | err = brcmf_fil_cmd_int_set(ifp, |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 2222 | BRCMF_C_SET_KEY_PRIMARY, index); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2223 | if (err) |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 2224 | brcmf_err("error (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2225 | } |
| 2226 | done: |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 2227 | brcmf_dbg(TRACE, "Exit\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2228 | return err; |
| 2229 | } |
| 2230 | |
| 2231 | static s32 |
Hante Meuleman | 219e0f7 | 2016-02-17 11:27:09 +0100 | [diff] [blame] | 2232 | brcmf_cfg80211_del_key(struct wiphy *wiphy, struct net_device *ndev, |
| 2233 | u8 key_idx, bool pairwise, const u8 *mac_addr) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2234 | { |
Hante Meuleman | 992f606 | 2013-04-02 21:06:17 +0200 | [diff] [blame] | 2235 | struct brcmf_if *ifp = netdev_priv(ndev); |
Hante Meuleman | 240d61a | 2016-02-17 11:27:10 +0100 | [diff] [blame] | 2236 | struct brcmf_wsec_key *key; |
| 2237 | s32 err; |
Hante Meuleman | 219e0f7 | 2016-02-17 11:27:09 +0100 | [diff] [blame] | 2238 | |
| 2239 | brcmf_dbg(TRACE, "Enter\n"); |
Hante Meuleman | 240d61a | 2016-02-17 11:27:10 +0100 | [diff] [blame] | 2240 | brcmf_dbg(CONN, "key index (%d)\n", key_idx); |
| 2241 | |
Hante Meuleman | 219e0f7 | 2016-02-17 11:27:09 +0100 | [diff] [blame] | 2242 | if (!check_vif_up(ifp->vif)) |
| 2243 | return -EIO; |
| 2244 | |
| 2245 | if (key_idx >= BRCMF_MAX_DEFAULT_KEYS) { |
| 2246 | /* we ignore this key index in this case */ |
| 2247 | return -EINVAL; |
| 2248 | } |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2249 | |
Hante Meuleman | 240d61a | 2016-02-17 11:27:10 +0100 | [diff] [blame] | 2250 | key = &ifp->vif->profile.key[key_idx]; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2251 | |
Hante Meuleman | 240d61a | 2016-02-17 11:27:10 +0100 | [diff] [blame] | 2252 | if (key->algo == CRYPTO_ALGO_OFF) { |
| 2253 | brcmf_dbg(CONN, "Ignore clearing of (never configured) key\n"); |
| 2254 | return -EINVAL; |
| 2255 | } |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2256 | |
Hante Meuleman | 240d61a | 2016-02-17 11:27:10 +0100 | [diff] [blame] | 2257 | memset(key, 0, sizeof(*key)); |
| 2258 | key->index = (u32)key_idx; |
| 2259 | key->flags = BRCMF_PRIMARY_KEY; |
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 | /* Clear the key/index */ |
| 2262 | err = send_key_to_dongle(ifp, key); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2263 | |
Hante Meuleman | 219e0f7 | 2016-02-17 11:27:09 +0100 | [diff] [blame] | 2264 | brcmf_dbg(TRACE, "Exit\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2265 | return err; |
| 2266 | } |
| 2267 | |
| 2268 | static s32 |
| 2269 | brcmf_cfg80211_add_key(struct wiphy *wiphy, struct net_device *ndev, |
Hante Meuleman | 240d61a | 2016-02-17 11:27:10 +0100 | [diff] [blame] | 2270 | u8 key_idx, bool pairwise, const u8 *mac_addr, |
| 2271 | struct key_params *params) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2272 | { |
Arend van Spriel | 0abb5f21 | 2012-10-22 13:55:32 -0700 | [diff] [blame] | 2273 | struct brcmf_if *ifp = netdev_priv(ndev); |
Hante Meuleman | 118eb30 | 2014-12-21 12:43:49 +0100 | [diff] [blame] | 2274 | struct brcmf_wsec_key *key; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2275 | s32 val; |
| 2276 | s32 wsec; |
Hante Meuleman | 219e0f7 | 2016-02-17 11:27:09 +0100 | [diff] [blame] | 2277 | s32 err; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2278 | u8 keybuf[8]; |
Hante Meuleman | 219e0f7 | 2016-02-17 11:27:09 +0100 | [diff] [blame] | 2279 | bool ext_key; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2280 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 2281 | brcmf_dbg(TRACE, "Enter\n"); |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 2282 | brcmf_dbg(CONN, "key index (%d)\n", key_idx); |
Arend van Spriel | ce81e31 | 2012-10-22 13:55:37 -0700 | [diff] [blame] | 2283 | if (!check_vif_up(ifp->vif)) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2284 | return -EIO; |
| 2285 | |
Hante Meuleman | 118eb30 | 2014-12-21 12:43:49 +0100 | [diff] [blame] | 2286 | if (key_idx >= BRCMF_MAX_DEFAULT_KEYS) { |
| 2287 | /* we ignore this key index in this case */ |
| 2288 | brcmf_err("invalid key index (%d)\n", key_idx); |
| 2289 | return -EINVAL; |
| 2290 | } |
| 2291 | |
Hante Meuleman | 219e0f7 | 2016-02-17 11:27:09 +0100 | [diff] [blame] | 2292 | if (params->key_len == 0) |
| 2293 | return brcmf_cfg80211_del_key(wiphy, ndev, key_idx, pairwise, |
| 2294 | mac_addr); |
| 2295 | |
| 2296 | if (params->key_len > sizeof(key->data)) { |
| 2297 | brcmf_err("Too long key length (%u)\n", params->key_len); |
| 2298 | return -EINVAL; |
| 2299 | } |
| 2300 | |
| 2301 | ext_key = false; |
| 2302 | if (mac_addr && (params->cipher != WLAN_CIPHER_SUITE_WEP40) && |
| 2303 | (params->cipher != WLAN_CIPHER_SUITE_WEP104)) { |
| 2304 | brcmf_dbg(TRACE, "Ext key, mac %pM", mac_addr); |
| 2305 | ext_key = true; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2306 | } |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2307 | |
Hante Meuleman | 118eb30 | 2014-12-21 12:43:49 +0100 | [diff] [blame] | 2308 | key = &ifp->vif->profile.key[key_idx]; |
| 2309 | memset(key, 0, sizeof(*key)); |
Hante Meuleman | 219e0f7 | 2016-02-17 11:27:09 +0100 | [diff] [blame] | 2310 | if ((ext_key) && (!is_multicast_ether_addr(mac_addr))) |
| 2311 | memcpy((char *)&key->ea, (void *)mac_addr, ETH_ALEN); |
Hante Meuleman | 118eb30 | 2014-12-21 12:43:49 +0100 | [diff] [blame] | 2312 | key->len = params->key_len; |
| 2313 | key->index = key_idx; |
Hante Meuleman | 118eb30 | 2014-12-21 12:43:49 +0100 | [diff] [blame] | 2314 | memcpy(key->data, params->key, key->len); |
Hante Meuleman | 219e0f7 | 2016-02-17 11:27:09 +0100 | [diff] [blame] | 2315 | if (!ext_key) |
| 2316 | key->flags = BRCMF_PRIMARY_KEY; |
Hante Meuleman | 118eb30 | 2014-12-21 12:43:49 +0100 | [diff] [blame] | 2317 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2318 | switch (params->cipher) { |
| 2319 | case WLAN_CIPHER_SUITE_WEP40: |
Hante Meuleman | 118eb30 | 2014-12-21 12:43:49 +0100 | [diff] [blame] | 2320 | key->algo = CRYPTO_ALGO_WEP1; |
Hante Meuleman | f09d0c0 | 2012-09-27 14:17:48 +0200 | [diff] [blame] | 2321 | val = WEP_ENABLED; |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 2322 | brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_WEP40\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2323 | break; |
| 2324 | case WLAN_CIPHER_SUITE_WEP104: |
Hante Meuleman | 118eb30 | 2014-12-21 12:43:49 +0100 | [diff] [blame] | 2325 | key->algo = CRYPTO_ALGO_WEP128; |
Hante Meuleman | f09d0c0 | 2012-09-27 14:17:48 +0200 | [diff] [blame] | 2326 | val = WEP_ENABLED; |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 2327 | brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_WEP104\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2328 | break; |
| 2329 | case WLAN_CIPHER_SUITE_TKIP: |
Arend van Spriel | 967fe2c | 2014-03-15 17:18:21 +0100 | [diff] [blame] | 2330 | if (!brcmf_is_apmode(ifp->vif)) { |
Hante Meuleman | 992f606 | 2013-04-02 21:06:17 +0200 | [diff] [blame] | 2331 | brcmf_dbg(CONN, "Swapping RX/TX MIC key\n"); |
Hante Meuleman | 118eb30 | 2014-12-21 12:43:49 +0100 | [diff] [blame] | 2332 | memcpy(keybuf, &key->data[24], sizeof(keybuf)); |
| 2333 | memcpy(&key->data[24], &key->data[16], sizeof(keybuf)); |
| 2334 | memcpy(&key->data[16], keybuf, sizeof(keybuf)); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 2335 | } |
Hante Meuleman | 118eb30 | 2014-12-21 12:43:49 +0100 | [diff] [blame] | 2336 | key->algo = CRYPTO_ALGO_TKIP; |
Hante Meuleman | f09d0c0 | 2012-09-27 14:17:48 +0200 | [diff] [blame] | 2337 | val = TKIP_ENABLED; |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 2338 | brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_TKIP\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2339 | break; |
| 2340 | case WLAN_CIPHER_SUITE_AES_CMAC: |
Hante Meuleman | 118eb30 | 2014-12-21 12:43:49 +0100 | [diff] [blame] | 2341 | key->algo = CRYPTO_ALGO_AES_CCM; |
Hante Meuleman | f09d0c0 | 2012-09-27 14:17:48 +0200 | [diff] [blame] | 2342 | val = AES_ENABLED; |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 2343 | brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_AES_CMAC\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2344 | break; |
| 2345 | case WLAN_CIPHER_SUITE_CCMP: |
Hante Meuleman | 118eb30 | 2014-12-21 12:43:49 +0100 | [diff] [blame] | 2346 | key->algo = CRYPTO_ALGO_AES_CCM; |
Hante Meuleman | f09d0c0 | 2012-09-27 14:17:48 +0200 | [diff] [blame] | 2347 | val = AES_ENABLED; |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 2348 | brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_CCMP\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2349 | break; |
| 2350 | default: |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 2351 | brcmf_err("Invalid cipher (0x%x)\n", params->cipher); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2352 | err = -EINVAL; |
| 2353 | goto done; |
| 2354 | } |
| 2355 | |
Hante Meuleman | 118eb30 | 2014-12-21 12:43:49 +0100 | [diff] [blame] | 2356 | err = send_key_to_dongle(ifp, key); |
Hante Meuleman | 219e0f7 | 2016-02-17 11:27:09 +0100 | [diff] [blame] | 2357 | if (ext_key || err) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2358 | goto done; |
| 2359 | |
Arend van Spriel | 0abb5f21 | 2012-10-22 13:55:32 -0700 | [diff] [blame] | 2360 | err = brcmf_fil_bsscfg_int_get(ifp, "wsec", &wsec); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2361 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 2362 | brcmf_err("get wsec error (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2363 | goto done; |
| 2364 | } |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2365 | wsec |= val; |
Arend van Spriel | 0abb5f21 | 2012-10-22 13:55:32 -0700 | [diff] [blame] | 2366 | err = brcmf_fil_bsscfg_int_set(ifp, "wsec", wsec); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2367 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 2368 | brcmf_err("set wsec error (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2369 | goto done; |
| 2370 | } |
| 2371 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2372 | done: |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 2373 | brcmf_dbg(TRACE, "Exit\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2374 | return err; |
| 2375 | } |
| 2376 | |
| 2377 | static s32 |
Hante Meuleman | 240d61a | 2016-02-17 11:27:10 +0100 | [diff] [blame] | 2378 | brcmf_cfg80211_get_key(struct wiphy *wiphy, struct net_device *ndev, u8 key_idx, |
| 2379 | bool pairwise, const u8 *mac_addr, void *cookie, |
| 2380 | void (*callback)(void *cookie, |
| 2381 | struct key_params *params)) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2382 | { |
| 2383 | struct key_params params; |
Arend van Spriel | 0abb5f21 | 2012-10-22 13:55:32 -0700 | [diff] [blame] | 2384 | struct brcmf_if *ifp = netdev_priv(ndev); |
| 2385 | struct brcmf_cfg80211_profile *profile = &ifp->vif->profile; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2386 | struct brcmf_cfg80211_security *sec; |
| 2387 | s32 wsec; |
| 2388 | s32 err = 0; |
| 2389 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 2390 | brcmf_dbg(TRACE, "Enter\n"); |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 2391 | brcmf_dbg(CONN, "key index (%d)\n", key_idx); |
Arend van Spriel | ce81e31 | 2012-10-22 13:55:37 -0700 | [diff] [blame] | 2392 | if (!check_vif_up(ifp->vif)) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2393 | return -EIO; |
| 2394 | |
| 2395 | memset(¶ms, 0, sizeof(params)); |
| 2396 | |
Arend van Spriel | 0abb5f21 | 2012-10-22 13:55:32 -0700 | [diff] [blame] | 2397 | err = brcmf_fil_bsscfg_int_get(ifp, "wsec", &wsec); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2398 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 2399 | brcmf_err("WLC_GET_WSEC error (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2400 | /* Ignore this error, may happen during DISASSOC */ |
| 2401 | err = -EAGAIN; |
| 2402 | goto done; |
| 2403 | } |
Hante Meuleman | c5bf53a | 2013-04-02 21:06:19 +0200 | [diff] [blame] | 2404 | if (wsec & WEP_ENABLED) { |
Arend van Spriel | 06bb123 | 2012-09-27 14:17:56 +0200 | [diff] [blame] | 2405 | sec = &profile->sec; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2406 | if (sec->cipher_pairwise & WLAN_CIPHER_SUITE_WEP40) { |
| 2407 | params.cipher = WLAN_CIPHER_SUITE_WEP40; |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 2408 | brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_WEP40\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2409 | } else if (sec->cipher_pairwise & WLAN_CIPHER_SUITE_WEP104) { |
| 2410 | params.cipher = WLAN_CIPHER_SUITE_WEP104; |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 2411 | brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_WEP104\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2412 | } |
Hante Meuleman | c5bf53a | 2013-04-02 21:06:19 +0200 | [diff] [blame] | 2413 | } else if (wsec & TKIP_ENABLED) { |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2414 | params.cipher = WLAN_CIPHER_SUITE_TKIP; |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 2415 | brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_TKIP\n"); |
Hante Meuleman | c5bf53a | 2013-04-02 21:06:19 +0200 | [diff] [blame] | 2416 | } else if (wsec & AES_ENABLED) { |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2417 | params.cipher = WLAN_CIPHER_SUITE_AES_CMAC; |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 2418 | brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_AES_CMAC\n"); |
Hante Meuleman | c5bf53a | 2013-04-02 21:06:19 +0200 | [diff] [blame] | 2419 | } else { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 2420 | brcmf_err("Invalid algo (0x%x)\n", wsec); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2421 | err = -EINVAL; |
| 2422 | goto done; |
| 2423 | } |
| 2424 | callback(cookie, ¶ms); |
| 2425 | |
| 2426 | done: |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 2427 | brcmf_dbg(TRACE, "Exit\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2428 | return err; |
| 2429 | } |
| 2430 | |
| 2431 | static s32 |
| 2432 | brcmf_cfg80211_config_default_mgmt_key(struct wiphy *wiphy, |
Hante Meuleman | 240d61a | 2016-02-17 11:27:10 +0100 | [diff] [blame] | 2433 | struct net_device *ndev, u8 key_idx) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2434 | { |
Hante Meuleman | 240d61a | 2016-02-17 11:27:10 +0100 | [diff] [blame] | 2435 | struct brcmf_if *ifp = netdev_priv(ndev); |
| 2436 | |
| 2437 | brcmf_dbg(TRACE, "Enter key_idx %d\n", key_idx); |
| 2438 | |
| 2439 | if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_MFP)) |
| 2440 | return 0; |
| 2441 | |
Arend van Spriel | 647c9ae | 2012-12-05 15:26:01 +0100 | [diff] [blame] | 2442 | brcmf_dbg(INFO, "Not supported\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2443 | |
| 2444 | return -EOPNOTSUPP; |
| 2445 | } |
| 2446 | |
Hante Meuleman | 118eb30 | 2014-12-21 12:43:49 +0100 | [diff] [blame] | 2447 | static void |
| 2448 | brcmf_cfg80211_reconfigure_wep(struct brcmf_if *ifp) |
| 2449 | { |
| 2450 | s32 err; |
| 2451 | u8 key_idx; |
| 2452 | struct brcmf_wsec_key *key; |
| 2453 | s32 wsec; |
| 2454 | |
| 2455 | for (key_idx = 0; key_idx < BRCMF_MAX_DEFAULT_KEYS; key_idx++) { |
| 2456 | key = &ifp->vif->profile.key[key_idx]; |
| 2457 | if ((key->algo == CRYPTO_ALGO_WEP1) || |
| 2458 | (key->algo == CRYPTO_ALGO_WEP128)) |
| 2459 | break; |
| 2460 | } |
| 2461 | if (key_idx == BRCMF_MAX_DEFAULT_KEYS) |
| 2462 | return; |
| 2463 | |
| 2464 | err = send_key_to_dongle(ifp, key); |
| 2465 | if (err) { |
| 2466 | brcmf_err("Setting WEP key failed (%d)\n", err); |
| 2467 | return; |
| 2468 | } |
| 2469 | err = brcmf_fil_bsscfg_int_get(ifp, "wsec", &wsec); |
| 2470 | if (err) { |
| 2471 | brcmf_err("get wsec error (%d)\n", err); |
| 2472 | return; |
| 2473 | } |
| 2474 | wsec |= WEP_ENABLED; |
| 2475 | err = brcmf_fil_bsscfg_int_set(ifp, "wsec", wsec); |
| 2476 | if (err) |
| 2477 | brcmf_err("set wsec error (%d)\n", err); |
| 2478 | } |
| 2479 | |
Arend van Spriel | 1f0dc59 | 2015-06-11 00:12:19 +0200 | [diff] [blame] | 2480 | static void brcmf_convert_sta_flags(u32 fw_sta_flags, struct station_info *si) |
| 2481 | { |
| 2482 | struct nl80211_sta_flag_update *sfu; |
| 2483 | |
| 2484 | brcmf_dbg(TRACE, "flags %08x\n", fw_sta_flags); |
| 2485 | si->filled |= BIT(NL80211_STA_INFO_STA_FLAGS); |
| 2486 | sfu = &si->sta_flags; |
| 2487 | sfu->mask = BIT(NL80211_STA_FLAG_WME) | |
| 2488 | BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 2489 | BIT(NL80211_STA_FLAG_ASSOCIATED) | |
| 2490 | BIT(NL80211_STA_FLAG_AUTHORIZED); |
| 2491 | if (fw_sta_flags & BRCMF_STA_WME) |
| 2492 | sfu->set |= BIT(NL80211_STA_FLAG_WME); |
| 2493 | if (fw_sta_flags & BRCMF_STA_AUTHE) |
| 2494 | sfu->set |= BIT(NL80211_STA_FLAG_AUTHENTICATED); |
| 2495 | if (fw_sta_flags & BRCMF_STA_ASSOC) |
| 2496 | sfu->set |= BIT(NL80211_STA_FLAG_ASSOCIATED); |
| 2497 | if (fw_sta_flags & BRCMF_STA_AUTHO) |
| 2498 | sfu->set |= BIT(NL80211_STA_FLAG_AUTHORIZED); |
| 2499 | } |
| 2500 | |
| 2501 | static void brcmf_fill_bss_param(struct brcmf_if *ifp, struct station_info *si) |
| 2502 | { |
| 2503 | struct { |
| 2504 | __le32 len; |
| 2505 | struct brcmf_bss_info_le bss_le; |
| 2506 | } *buf; |
| 2507 | u16 capability; |
| 2508 | int err; |
| 2509 | |
| 2510 | buf = kzalloc(WL_BSS_INFO_MAX, GFP_KERNEL); |
| 2511 | if (!buf) |
| 2512 | return; |
| 2513 | |
| 2514 | buf->len = cpu_to_le32(WL_BSS_INFO_MAX); |
| 2515 | err = brcmf_fil_cmd_data_get(ifp, BRCMF_C_GET_BSS_INFO, buf, |
| 2516 | WL_BSS_INFO_MAX); |
| 2517 | if (err) { |
| 2518 | brcmf_err("Failed to get bss info (%d)\n", err); |
Rafał Miłecki | 23e9c12 | 2016-09-21 08:23:24 +0200 | [diff] [blame] | 2519 | goto out_kfree; |
Arend van Spriel | 1f0dc59 | 2015-06-11 00:12:19 +0200 | [diff] [blame] | 2520 | } |
| 2521 | si->filled |= BIT(NL80211_STA_INFO_BSS_PARAM); |
| 2522 | si->bss_param.beacon_interval = le16_to_cpu(buf->bss_le.beacon_period); |
| 2523 | si->bss_param.dtim_period = buf->bss_le.dtim_period; |
| 2524 | capability = le16_to_cpu(buf->bss_le.capability); |
| 2525 | if (capability & IEEE80211_HT_STBC_PARAM_DUAL_CTS_PROT) |
| 2526 | si->bss_param.flags |= BSS_PARAM_FLAGS_CTS_PROT; |
| 2527 | if (capability & WLAN_CAPABILITY_SHORT_PREAMBLE) |
| 2528 | si->bss_param.flags |= BSS_PARAM_FLAGS_SHORT_PREAMBLE; |
| 2529 | if (capability & WLAN_CAPABILITY_SHORT_SLOT_TIME) |
| 2530 | si->bss_param.flags |= BSS_PARAM_FLAGS_SHORT_SLOT_TIME; |
Rafał Miłecki | 23e9c12 | 2016-09-21 08:23:24 +0200 | [diff] [blame] | 2531 | |
| 2532 | out_kfree: |
| 2533 | kfree(buf); |
Arend van Spriel | 1f0dc59 | 2015-06-11 00:12:19 +0200 | [diff] [blame] | 2534 | } |
| 2535 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2536 | static s32 |
Hante Meuleman | 3f5893d | 2016-01-02 09:41:37 +0100 | [diff] [blame] | 2537 | brcmf_cfg80211_get_station_ibss(struct brcmf_if *ifp, |
| 2538 | struct station_info *sinfo) |
| 2539 | { |
| 2540 | struct brcmf_scb_val_le scbval; |
| 2541 | struct brcmf_pktcnt_le pktcnt; |
| 2542 | s32 err; |
| 2543 | u32 rate; |
| 2544 | u32 rssi; |
| 2545 | |
| 2546 | /* Get the current tx rate */ |
| 2547 | err = brcmf_fil_cmd_int_get(ifp, BRCMF_C_GET_RATE, &rate); |
| 2548 | if (err < 0) { |
| 2549 | brcmf_err("BRCMF_C_GET_RATE error (%d)\n", err); |
| 2550 | return err; |
| 2551 | } |
| 2552 | sinfo->filled |= BIT(NL80211_STA_INFO_TX_BITRATE); |
| 2553 | sinfo->txrate.legacy = rate * 5; |
| 2554 | |
| 2555 | memset(&scbval, 0, sizeof(scbval)); |
| 2556 | err = brcmf_fil_cmd_data_get(ifp, BRCMF_C_GET_RSSI, &scbval, |
| 2557 | sizeof(scbval)); |
| 2558 | if (err) { |
| 2559 | brcmf_err("BRCMF_C_GET_RSSI error (%d)\n", err); |
| 2560 | return err; |
| 2561 | } |
| 2562 | rssi = le32_to_cpu(scbval.val); |
| 2563 | sinfo->filled |= BIT(NL80211_STA_INFO_SIGNAL); |
| 2564 | sinfo->signal = rssi; |
| 2565 | |
| 2566 | err = brcmf_fil_cmd_data_get(ifp, BRCMF_C_GET_GET_PKTCNTS, &pktcnt, |
| 2567 | sizeof(pktcnt)); |
| 2568 | if (err) { |
| 2569 | brcmf_err("BRCMF_C_GET_GET_PKTCNTS error (%d)\n", err); |
| 2570 | return err; |
| 2571 | } |
| 2572 | sinfo->filled |= BIT(NL80211_STA_INFO_RX_PACKETS) | |
| 2573 | BIT(NL80211_STA_INFO_RX_DROP_MISC) | |
| 2574 | BIT(NL80211_STA_INFO_TX_PACKETS) | |
| 2575 | BIT(NL80211_STA_INFO_TX_FAILED); |
| 2576 | sinfo->rx_packets = le32_to_cpu(pktcnt.rx_good_pkt); |
| 2577 | sinfo->rx_dropped_misc = le32_to_cpu(pktcnt.rx_bad_pkt); |
| 2578 | sinfo->tx_packets = le32_to_cpu(pktcnt.tx_good_pkt); |
| 2579 | sinfo->tx_failed = le32_to_cpu(pktcnt.tx_bad_pkt); |
| 2580 | |
| 2581 | return 0; |
| 2582 | } |
| 2583 | |
| 2584 | static s32 |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2585 | brcmf_cfg80211_get_station(struct wiphy *wiphy, struct net_device *ndev, |
Johannes Berg | 3b3a016 | 2014-05-19 17:19:31 +0200 | [diff] [blame] | 2586 | const u8 *mac, struct station_info *sinfo) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2587 | { |
Arend van Spriel | 0abb5f21 | 2012-10-22 13:55:32 -0700 | [diff] [blame] | 2588 | struct brcmf_if *ifp = netdev_priv(ndev); |
Jaap Jan Meijer | 94abd77 | 2016-05-12 18:25:08 +0200 | [diff] [blame] | 2589 | struct brcmf_scb_val_le scb_val; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2590 | s32 err = 0; |
Hante Meuleman | 81f5dcb | 2012-10-22 10:36:14 -0700 | [diff] [blame] | 2591 | struct brcmf_sta_info_le sta_info_le; |
Arend van Spriel | 1f0dc59 | 2015-06-11 00:12:19 +0200 | [diff] [blame] | 2592 | u32 sta_flags; |
| 2593 | u32 is_tdls_peer; |
Hante Meuleman | cae355d | 2015-10-08 20:33:17 +0200 | [diff] [blame] | 2594 | s32 total_rssi; |
| 2595 | s32 count_rssi; |
Jaap Jan Meijer | 94abd77 | 2016-05-12 18:25:08 +0200 | [diff] [blame] | 2596 | int rssi; |
Hante Meuleman | cae355d | 2015-10-08 20:33:17 +0200 | [diff] [blame] | 2597 | u32 i; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2598 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 2599 | brcmf_dbg(TRACE, "Enter, MAC %pM\n", mac); |
Arend van Spriel | ce81e31 | 2012-10-22 13:55:37 -0700 | [diff] [blame] | 2600 | if (!check_vif_up(ifp->vif)) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2601 | return -EIO; |
| 2602 | |
Hante Meuleman | 3f5893d | 2016-01-02 09:41:37 +0100 | [diff] [blame] | 2603 | if (brcmf_is_ibssmode(ifp->vif)) |
| 2604 | return brcmf_cfg80211_get_station_ibss(ifp, sinfo); |
| 2605 | |
Arend van Spriel | 1f0dc59 | 2015-06-11 00:12:19 +0200 | [diff] [blame] | 2606 | memset(&sta_info_le, 0, sizeof(sta_info_le)); |
| 2607 | memcpy(&sta_info_le, mac, ETH_ALEN); |
| 2608 | err = brcmf_fil_iovar_data_get(ifp, "tdls_sta_info", |
| 2609 | &sta_info_le, |
| 2610 | sizeof(sta_info_le)); |
| 2611 | is_tdls_peer = !err; |
| 2612 | if (err) { |
Arend van Spriel | 0abb5f21 | 2012-10-22 13:55:32 -0700 | [diff] [blame] | 2613 | err = brcmf_fil_iovar_data_get(ifp, "sta_info", |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 2614 | &sta_info_le, |
Hante Meuleman | 81f5dcb | 2012-10-22 10:36:14 -0700 | [diff] [blame] | 2615 | sizeof(sta_info_le)); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 2616 | if (err < 0) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 2617 | brcmf_err("GET STA INFO failed, %d\n", err); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 2618 | goto done; |
Hante Meuleman | 7f6c562 | 2012-08-30 10:05:37 +0200 | [diff] [blame] | 2619 | } |
Arend van Spriel | 1f0dc59 | 2015-06-11 00:12:19 +0200 | [diff] [blame] | 2620 | } |
| 2621 | brcmf_dbg(TRACE, "version %d\n", le16_to_cpu(sta_info_le.ver)); |
| 2622 | sinfo->filled = BIT(NL80211_STA_INFO_INACTIVE_TIME); |
| 2623 | sinfo->inactive_time = le32_to_cpu(sta_info_le.idle) * 1000; |
| 2624 | sta_flags = le32_to_cpu(sta_info_le.flags); |
| 2625 | brcmf_convert_sta_flags(sta_flags, sinfo); |
| 2626 | sinfo->sta_flags.mask |= BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 2627 | if (is_tdls_peer) |
| 2628 | sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 2629 | else |
| 2630 | sinfo->sta_flags.set &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 2631 | if (sta_flags & BRCMF_STA_ASSOC) { |
| 2632 | sinfo->filled |= BIT(NL80211_STA_INFO_CONNECTED_TIME); |
| 2633 | sinfo->connected_time = le32_to_cpu(sta_info_le.in); |
| 2634 | brcmf_fill_bss_param(ifp, sinfo); |
| 2635 | } |
| 2636 | if (sta_flags & BRCMF_STA_SCBSTATS) { |
| 2637 | sinfo->filled |= BIT(NL80211_STA_INFO_TX_FAILED); |
| 2638 | sinfo->tx_failed = le32_to_cpu(sta_info_le.tx_failures); |
| 2639 | sinfo->filled |= BIT(NL80211_STA_INFO_TX_PACKETS); |
| 2640 | sinfo->tx_packets = le32_to_cpu(sta_info_le.tx_pkts); |
| 2641 | sinfo->tx_packets += le32_to_cpu(sta_info_le.tx_mcast_pkts); |
| 2642 | sinfo->filled |= BIT(NL80211_STA_INFO_RX_PACKETS); |
| 2643 | sinfo->rx_packets = le32_to_cpu(sta_info_le.rx_ucast_pkts); |
| 2644 | sinfo->rx_packets += le32_to_cpu(sta_info_le.rx_mcast_pkts); |
| 2645 | if (sinfo->tx_packets) { |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 2646 | sinfo->filled |= BIT(NL80211_STA_INFO_TX_BITRATE); |
Hante Meuleman | 124d517 | 2015-10-08 20:33:16 +0200 | [diff] [blame] | 2647 | sinfo->txrate.legacy = |
| 2648 | le32_to_cpu(sta_info_le.tx_rate) / 100; |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 2649 | } |
Arend van Spriel | 1f0dc59 | 2015-06-11 00:12:19 +0200 | [diff] [blame] | 2650 | if (sinfo->rx_packets) { |
| 2651 | sinfo->filled |= BIT(NL80211_STA_INFO_RX_BITRATE); |
Hante Meuleman | 124d517 | 2015-10-08 20:33:16 +0200 | [diff] [blame] | 2652 | sinfo->rxrate.legacy = |
| 2653 | le32_to_cpu(sta_info_le.rx_rate) / 100; |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 2654 | } |
Arend van Spriel | 1f0dc59 | 2015-06-11 00:12:19 +0200 | [diff] [blame] | 2655 | if (le16_to_cpu(sta_info_le.ver) >= 4) { |
| 2656 | sinfo->filled |= BIT(NL80211_STA_INFO_TX_BYTES); |
| 2657 | sinfo->tx_bytes = le64_to_cpu(sta_info_le.tx_tot_bytes); |
| 2658 | sinfo->filled |= BIT(NL80211_STA_INFO_RX_BYTES); |
| 2659 | sinfo->rx_bytes = le64_to_cpu(sta_info_le.rx_tot_bytes); |
| 2660 | } |
Hante Meuleman | cae355d | 2015-10-08 20:33:17 +0200 | [diff] [blame] | 2661 | total_rssi = 0; |
| 2662 | count_rssi = 0; |
| 2663 | for (i = 0; i < BRCMF_ANT_MAX; i++) { |
| 2664 | if (sta_info_le.rssi[i]) { |
| 2665 | sinfo->chain_signal_avg[count_rssi] = |
| 2666 | sta_info_le.rssi[i]; |
| 2667 | sinfo->chain_signal[count_rssi] = |
| 2668 | sta_info_le.rssi[i]; |
| 2669 | total_rssi += sta_info_le.rssi[i]; |
| 2670 | count_rssi++; |
| 2671 | } |
| 2672 | } |
| 2673 | if (count_rssi) { |
| 2674 | sinfo->filled |= BIT(NL80211_STA_INFO_CHAIN_SIGNAL); |
| 2675 | sinfo->chains = count_rssi; |
| 2676 | |
| 2677 | sinfo->filled |= BIT(NL80211_STA_INFO_SIGNAL); |
| 2678 | total_rssi /= count_rssi; |
| 2679 | sinfo->signal = total_rssi; |
Jaap Jan Meijer | 94abd77 | 2016-05-12 18:25:08 +0200 | [diff] [blame] | 2680 | } else if (test_bit(BRCMF_VIF_STATUS_CONNECTED, |
| 2681 | &ifp->vif->sme_state)) { |
| 2682 | memset(&scb_val, 0, sizeof(scb_val)); |
| 2683 | err = brcmf_fil_cmd_data_get(ifp, BRCMF_C_GET_RSSI, |
| 2684 | &scb_val, sizeof(scb_val)); |
| 2685 | if (err) { |
| 2686 | brcmf_err("Could not get rssi (%d)\n", err); |
| 2687 | goto done; |
| 2688 | } else { |
| 2689 | rssi = le32_to_cpu(scb_val.val); |
| 2690 | sinfo->filled |= BIT(NL80211_STA_INFO_SIGNAL); |
| 2691 | sinfo->signal = rssi; |
| 2692 | brcmf_dbg(CONN, "RSSI %d dBm\n", rssi); |
| 2693 | } |
Hante Meuleman | cae355d | 2015-10-08 20:33:17 +0200 | [diff] [blame] | 2694 | } |
Arend van Spriel | 1f0dc59 | 2015-06-11 00:12:19 +0200 | [diff] [blame] | 2695 | } |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2696 | done: |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 2697 | brcmf_dbg(TRACE, "Exit\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2698 | return err; |
| 2699 | } |
| 2700 | |
Hante Meuleman | bf2a7e0 | 2015-10-08 20:33:18 +0200 | [diff] [blame] | 2701 | static int |
| 2702 | brcmf_cfg80211_dump_station(struct wiphy *wiphy, struct net_device *ndev, |
| 2703 | int idx, u8 *mac, struct station_info *sinfo) |
| 2704 | { |
| 2705 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); |
| 2706 | struct brcmf_if *ifp = netdev_priv(ndev); |
| 2707 | s32 err; |
| 2708 | |
| 2709 | brcmf_dbg(TRACE, "Enter, idx %d\n", idx); |
| 2710 | |
| 2711 | if (idx == 0) { |
| 2712 | cfg->assoclist.count = cpu_to_le32(BRCMF_MAX_ASSOCLIST); |
| 2713 | err = brcmf_fil_cmd_data_get(ifp, BRCMF_C_GET_ASSOCLIST, |
| 2714 | &cfg->assoclist, |
| 2715 | sizeof(cfg->assoclist)); |
| 2716 | if (err) { |
| 2717 | brcmf_err("BRCMF_C_GET_ASSOCLIST unsupported, err=%d\n", |
| 2718 | err); |
| 2719 | cfg->assoclist.count = 0; |
| 2720 | return -EOPNOTSUPP; |
| 2721 | } |
| 2722 | } |
| 2723 | if (idx < le32_to_cpu(cfg->assoclist.count)) { |
| 2724 | memcpy(mac, cfg->assoclist.mac[idx], ETH_ALEN); |
| 2725 | return brcmf_cfg80211_get_station(wiphy, ndev, mac, sinfo); |
| 2726 | } |
| 2727 | return -ENOENT; |
| 2728 | } |
| 2729 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2730 | static s32 |
| 2731 | brcmf_cfg80211_set_power_mgmt(struct wiphy *wiphy, struct net_device *ndev, |
| 2732 | bool enabled, s32 timeout) |
| 2733 | { |
| 2734 | s32 pm; |
| 2735 | s32 err = 0; |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 2736 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 2737 | struct brcmf_if *ifp = netdev_priv(ndev); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2738 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 2739 | brcmf_dbg(TRACE, "Enter\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2740 | |
| 2741 | /* |
| 2742 | * Powersave enable/disable request is coming from the |
| 2743 | * cfg80211 even before the interface is up. In that |
| 2744 | * scenario, driver will be storing the power save |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 2745 | * preference in cfg struct to apply this to |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2746 | * FW later while initializing the dongle |
| 2747 | */ |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 2748 | cfg->pwr_save = enabled; |
Arend van Spriel | ce81e31 | 2012-10-22 13:55:37 -0700 | [diff] [blame] | 2749 | if (!check_vif_up(ifp->vif)) { |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2750 | |
Arend van Spriel | 647c9ae | 2012-12-05 15:26:01 +0100 | [diff] [blame] | 2751 | 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] | 2752 | goto done; |
| 2753 | } |
| 2754 | |
| 2755 | pm = enabled ? PM_FAST : PM_OFF; |
Hante Meuleman | 102fd0d | 2013-05-27 21:09:59 +0200 | [diff] [blame] | 2756 | /* Do not enable the power save after assoc if it is a p2p interface */ |
| 2757 | if (ifp->vif->wdev.iftype == NL80211_IFTYPE_P2P_CLIENT) { |
| 2758 | brcmf_dbg(INFO, "Do not enable power save for P2P clients\n"); |
| 2759 | pm = PM_OFF; |
| 2760 | } |
Arend van Spriel | 647c9ae | 2012-12-05 15:26:01 +0100 | [diff] [blame] | 2761 | brcmf_dbg(INFO, "power save %s\n", (pm ? "enabled" : "disabled")); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2762 | |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 2763 | 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] | 2764 | if (err) { |
| 2765 | if (err == -ENODEV) |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 2766 | brcmf_err("net_device is not ready yet\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2767 | else |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 2768 | brcmf_err("error (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2769 | } |
| 2770 | done: |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 2771 | brcmf_dbg(TRACE, "Exit\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2772 | return err; |
| 2773 | } |
| 2774 | |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 2775 | static s32 brcmf_inform_single_bss(struct brcmf_cfg80211_info *cfg, |
Roland Vossen | d34bf64 | 2011-10-18 14:03:01 +0200 | [diff] [blame] | 2776 | struct brcmf_bss_info_le *bi) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2777 | { |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 2778 | struct wiphy *wiphy = cfg_to_wiphy(cfg); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2779 | struct ieee80211_channel *notify_channel; |
| 2780 | struct cfg80211_bss *bss; |
| 2781 | struct ieee80211_supported_band *band; |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 2782 | struct brcmu_chan ch; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2783 | u16 channel; |
| 2784 | u32 freq; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2785 | u16 notify_capability; |
| 2786 | u16 notify_interval; |
| 2787 | u8 *notify_ie; |
| 2788 | size_t notify_ielen; |
| 2789 | s32 notify_signal; |
| 2790 | |
| 2791 | if (le32_to_cpu(bi->length) > WL_BSS_INFO_MAX) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 2792 | brcmf_err("Bss info is larger than buffer. Discarding\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2793 | return 0; |
| 2794 | } |
| 2795 | |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 2796 | if (!bi->ctl_ch) { |
| 2797 | ch.chspec = le16_to_cpu(bi->chanspec); |
| 2798 | cfg->d11inf.decchspec(&ch); |
Rafał Miłecki | 4712d88 | 2016-05-20 13:38:57 +0200 | [diff] [blame] | 2799 | bi->ctl_ch = ch.control_ch_num; |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 2800 | } |
| 2801 | channel = bi->ctl_ch; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2802 | |
| 2803 | if (channel <= CH_MAX_2G_CHANNEL) |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 2804 | band = wiphy->bands[NL80211_BAND_2GHZ]; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2805 | else |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 2806 | band = wiphy->bands[NL80211_BAND_5GHZ]; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2807 | |
| 2808 | freq = ieee80211_channel_to_frequency(channel, band->band); |
| 2809 | notify_channel = ieee80211_get_channel(wiphy, freq); |
| 2810 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2811 | notify_capability = le16_to_cpu(bi->capability); |
| 2812 | notify_interval = le16_to_cpu(bi->beacon_period); |
| 2813 | notify_ie = (u8 *)bi + le16_to_cpu(bi->ie_offset); |
| 2814 | notify_ielen = le32_to_cpu(bi->ie_length); |
| 2815 | notify_signal = (s16)le16_to_cpu(bi->RSSI) * 100; |
| 2816 | |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 2817 | brcmf_dbg(CONN, "bssid: %pM\n", bi->BSSID); |
| 2818 | brcmf_dbg(CONN, "Channel: %d(%d)\n", channel, freq); |
| 2819 | brcmf_dbg(CONN, "Capability: %X\n", notify_capability); |
| 2820 | brcmf_dbg(CONN, "Beacon interval: %d\n", notify_interval); |
| 2821 | brcmf_dbg(CONN, "Signal: %d\n", notify_signal); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2822 | |
Johannes Berg | 5bc8c1f | 2014-08-12 21:01:28 +0200 | [diff] [blame] | 2823 | bss = cfg80211_inform_bss(wiphy, notify_channel, |
| 2824 | CFG80211_BSS_FTYPE_UNKNOWN, |
| 2825 | (const u8 *)bi->BSSID, |
| 2826 | 0, notify_capability, |
| 2827 | notify_interval, notify_ie, |
| 2828 | notify_ielen, notify_signal, |
| 2829 | GFP_KERNEL); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2830 | |
Franky Lin | e78946e | 2011-11-10 20:30:34 +0100 | [diff] [blame] | 2831 | if (!bss) |
| 2832 | return -ENOMEM; |
| 2833 | |
Johannes Berg | 5b112d3 | 2013-02-01 01:49:58 +0100 | [diff] [blame] | 2834 | cfg80211_put_bss(wiphy, bss); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2835 | |
Peter Senna Tschudin | 12f3237 | 2014-05-31 10:14:06 -0300 | [diff] [blame] | 2836 | return 0; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2837 | } |
| 2838 | |
Roland Vossen | 6f09be0 | 2011-10-18 14:03:02 +0200 | [diff] [blame] | 2839 | static struct brcmf_bss_info_le * |
| 2840 | next_bss_le(struct brcmf_scan_results *list, struct brcmf_bss_info_le *bss) |
| 2841 | { |
| 2842 | if (bss == NULL) |
| 2843 | return list->bss_info_le; |
| 2844 | return (struct brcmf_bss_info_le *)((unsigned long)bss + |
| 2845 | le32_to_cpu(bss->length)); |
| 2846 | } |
| 2847 | |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 2848 | static s32 brcmf_inform_bss(struct brcmf_cfg80211_info *cfg) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2849 | { |
| 2850 | struct brcmf_scan_results *bss_list; |
Roland Vossen | d34bf64 | 2011-10-18 14:03:01 +0200 | [diff] [blame] | 2851 | struct brcmf_bss_info_le *bi = NULL; /* must be initialized */ |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2852 | s32 err = 0; |
| 2853 | int i; |
| 2854 | |
Hante Meuleman | ef8596e | 2014-09-30 10:23:13 +0200 | [diff] [blame] | 2855 | bss_list = (struct brcmf_scan_results *)cfg->escan_info.escan_buf; |
Arend van Spriel | 0ecd816 | 2012-11-05 16:22:11 -0800 | [diff] [blame] | 2856 | if (bss_list->count != 0 && |
| 2857 | bss_list->version != BRCMF_BSS_INFO_VERSION) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 2858 | brcmf_err("Version %d != WL_BSS_INFO_VERSION\n", |
| 2859 | bss_list->version); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2860 | return -EOPNOTSUPP; |
| 2861 | } |
Arend van Spriel | 4e8a008 | 2012-12-05 15:26:03 +0100 | [diff] [blame] | 2862 | brcmf_dbg(SCAN, "scanned AP count (%d)\n", bss_list->count); |
Hante Meuleman | f0799895 | 2012-11-05 16:22:13 -0800 | [diff] [blame] | 2863 | for (i = 0; i < bss_list->count; i++) { |
Roland Vossen | 6f09be0 | 2011-10-18 14:03:02 +0200 | [diff] [blame] | 2864 | bi = next_bss_le(bss_list, bi); |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 2865 | err = brcmf_inform_single_bss(cfg, bi); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2866 | if (err) |
| 2867 | break; |
| 2868 | } |
| 2869 | return err; |
| 2870 | } |
| 2871 | |
Hante Meuleman | b0a7908 | 2015-12-10 13:43:07 +0100 | [diff] [blame] | 2872 | static s32 brcmf_inform_ibss(struct brcmf_cfg80211_info *cfg, |
| 2873 | struct net_device *ndev, const u8 *bssid) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2874 | { |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 2875 | struct wiphy *wiphy = cfg_to_wiphy(cfg); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2876 | struct ieee80211_channel *notify_channel; |
Roland Vossen | d34bf64 | 2011-10-18 14:03:01 +0200 | [diff] [blame] | 2877 | struct brcmf_bss_info_le *bi = NULL; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2878 | struct ieee80211_supported_band *band; |
Franky Lin | e78946e | 2011-11-10 20:30:34 +0100 | [diff] [blame] | 2879 | struct cfg80211_bss *bss; |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 2880 | struct brcmu_chan ch; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2881 | u8 *buf = NULL; |
| 2882 | s32 err = 0; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2883 | u32 freq; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2884 | u16 notify_capability; |
| 2885 | u16 notify_interval; |
| 2886 | u8 *notify_ie; |
| 2887 | size_t notify_ielen; |
| 2888 | s32 notify_signal; |
| 2889 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 2890 | brcmf_dbg(TRACE, "Enter\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2891 | |
| 2892 | buf = kzalloc(WL_BSS_INFO_MAX, GFP_KERNEL); |
| 2893 | if (buf == NULL) { |
| 2894 | err = -ENOMEM; |
| 2895 | goto CleanUp; |
| 2896 | } |
| 2897 | |
| 2898 | *(__le32 *)buf = cpu_to_le32(WL_BSS_INFO_MAX); |
| 2899 | |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 2900 | err = brcmf_fil_cmd_data_get(netdev_priv(ndev), BRCMF_C_GET_BSS_INFO, |
| 2901 | buf, WL_BSS_INFO_MAX); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2902 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 2903 | brcmf_err("WLC_GET_BSS_INFO failed: %d\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2904 | goto CleanUp; |
| 2905 | } |
| 2906 | |
Roland Vossen | d34bf64 | 2011-10-18 14:03:01 +0200 | [diff] [blame] | 2907 | bi = (struct brcmf_bss_info_le *)(buf + 4); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2908 | |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 2909 | ch.chspec = le16_to_cpu(bi->chanspec); |
| 2910 | cfg->d11inf.decchspec(&ch); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2911 | |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 2912 | if (ch.band == BRCMU_CHAN_BAND_2G) |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 2913 | band = wiphy->bands[NL80211_BAND_2GHZ]; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2914 | else |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 2915 | band = wiphy->bands[NL80211_BAND_5GHZ]; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2916 | |
Rafał Miłecki | 4712d88 | 2016-05-20 13:38:57 +0200 | [diff] [blame] | 2917 | freq = ieee80211_channel_to_frequency(ch.control_ch_num, band->band); |
Hante Meuleman | b0a7908 | 2015-12-10 13:43:07 +0100 | [diff] [blame] | 2918 | cfg->channel = freq; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2919 | notify_channel = ieee80211_get_channel(wiphy, freq); |
| 2920 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2921 | notify_capability = le16_to_cpu(bi->capability); |
| 2922 | notify_interval = le16_to_cpu(bi->beacon_period); |
| 2923 | notify_ie = (u8 *)bi + le16_to_cpu(bi->ie_offset); |
| 2924 | notify_ielen = le32_to_cpu(bi->ie_length); |
| 2925 | notify_signal = (s16)le16_to_cpu(bi->RSSI) * 100; |
| 2926 | |
Rafał Miłecki | 4712d88 | 2016-05-20 13:38:57 +0200 | [diff] [blame] | 2927 | 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] | 2928 | brcmf_dbg(CONN, "capability: %X\n", notify_capability); |
| 2929 | brcmf_dbg(CONN, "beacon interval: %d\n", notify_interval); |
| 2930 | brcmf_dbg(CONN, "signal: %d\n", notify_signal); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2931 | |
Johannes Berg | 5bc8c1f | 2014-08-12 21:01:28 +0200 | [diff] [blame] | 2932 | bss = cfg80211_inform_bss(wiphy, notify_channel, |
| 2933 | CFG80211_BSS_FTYPE_UNKNOWN, bssid, 0, |
| 2934 | notify_capability, notify_interval, |
| 2935 | notify_ie, notify_ielen, notify_signal, |
| 2936 | GFP_KERNEL); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2937 | |
Franky Lin | e78946e | 2011-11-10 20:30:34 +0100 | [diff] [blame] | 2938 | if (!bss) { |
| 2939 | err = -ENOMEM; |
| 2940 | goto CleanUp; |
| 2941 | } |
| 2942 | |
Johannes Berg | 5b112d3 | 2013-02-01 01:49:58 +0100 | [diff] [blame] | 2943 | cfg80211_put_bss(wiphy, bss); |
Franky Lin | e78946e | 2011-11-10 20:30:34 +0100 | [diff] [blame] | 2944 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2945 | CleanUp: |
| 2946 | |
| 2947 | kfree(buf); |
| 2948 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 2949 | brcmf_dbg(TRACE, "Exit\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2950 | |
| 2951 | return err; |
| 2952 | } |
| 2953 | |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 2954 | static s32 brcmf_update_bss_info(struct brcmf_cfg80211_info *cfg, |
| 2955 | struct brcmf_if *ifp) |
Alwin Beukers | f8e4b41 | 2011-10-12 20:51:28 +0200 | [diff] [blame] | 2956 | { |
Roland Vossen | d34bf64 | 2011-10-18 14:03:01 +0200 | [diff] [blame] | 2957 | struct brcmf_bss_info_le *bi; |
Johannes Berg | 4b5800f | 2014-01-15 14:55:59 +0100 | [diff] [blame] | 2958 | const struct brcmf_tlv *tim; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2959 | u16 beacon_interval; |
| 2960 | u8 dtim_period; |
| 2961 | size_t ie_len; |
| 2962 | u8 *ie; |
| 2963 | s32 err = 0; |
| 2964 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 2965 | brcmf_dbg(TRACE, "Enter\n"); |
Arend van Spriel | 128ce3b | 2012-11-28 21:44:12 +0100 | [diff] [blame] | 2966 | if (brcmf_is_ibssmode(ifp->vif)) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2967 | return err; |
| 2968 | |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 2969 | *(__le32 *)cfg->extra_buf = cpu_to_le32(WL_EXTRA_BUF_MAX); |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 2970 | err = brcmf_fil_cmd_data_get(ifp, BRCMF_C_GET_BSS_INFO, |
Hante Meuleman | 81f5dcb | 2012-10-22 10:36:14 -0700 | [diff] [blame] | 2971 | cfg->extra_buf, WL_EXTRA_BUF_MAX); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2972 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 2973 | brcmf_err("Could not get bss info %d\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2974 | goto update_bss_info_out; |
| 2975 | } |
| 2976 | |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 2977 | bi = (struct brcmf_bss_info_le *)(cfg->extra_buf + 4); |
| 2978 | err = brcmf_inform_single_bss(cfg, bi); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2979 | if (err) |
| 2980 | goto update_bss_info_out; |
| 2981 | |
| 2982 | ie = ((u8 *)bi) + le16_to_cpu(bi->ie_offset); |
| 2983 | ie_len = le32_to_cpu(bi->ie_length); |
| 2984 | beacon_interval = le16_to_cpu(bi->beacon_period); |
| 2985 | |
Alwin Beukers | f8e4b41 | 2011-10-12 20:51:28 +0200 | [diff] [blame] | 2986 | tim = brcmf_parse_tlvs(ie, ie_len, WLAN_EID_TIM); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2987 | if (tim) |
| 2988 | dtim_period = tim->data[1]; |
| 2989 | else { |
| 2990 | /* |
| 2991 | * active scan was done so we could not get dtim |
| 2992 | * information out of probe response. |
| 2993 | * so we speficially query dtim information to dongle. |
| 2994 | */ |
| 2995 | u32 var; |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 2996 | err = brcmf_fil_iovar_int_get(ifp, "dtim_assoc", &var); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2997 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 2998 | brcmf_err("wl dtim_assoc failed (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2999 | goto update_bss_info_out; |
| 3000 | } |
| 3001 | dtim_period = (u8)var; |
| 3002 | } |
| 3003 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3004 | update_bss_info_out: |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 3005 | brcmf_dbg(TRACE, "Exit"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3006 | return err; |
| 3007 | } |
| 3008 | |
Hante Meuleman | 18e2f61 | 2013-02-08 15:53:49 +0100 | [diff] [blame] | 3009 | void brcmf_abort_scanning(struct brcmf_cfg80211_info *cfg) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3010 | { |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 3011 | struct escan_info *escan = &cfg->escan_info; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3012 | |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 3013 | set_bit(BRCMF_SCAN_STATUS_ABORT, &cfg->scan_status); |
Arend Van Spriel | fa85b30 | 2016-11-23 10:25:25 +0000 | [diff] [blame] | 3014 | if (cfg->internal_escan || cfg->scan_request) { |
Arend van Spriel | 108a4be | 2012-09-19 22:21:07 +0200 | [diff] [blame] | 3015 | escan->escan_state = WL_ESCAN_STATE_IDLE; |
Arend van Spriel | a0f472a | 2013-04-05 10:57:49 +0200 | [diff] [blame] | 3016 | brcmf_notify_escan_complete(cfg, escan->ifp, true, true); |
Arend van Spriel | 108a4be | 2012-09-19 22:21:07 +0200 | [diff] [blame] | 3017 | } |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 3018 | clear_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status); |
| 3019 | clear_bit(BRCMF_SCAN_STATUS_ABORT, &cfg->scan_status); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3020 | } |
| 3021 | |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 3022 | static void brcmf_cfg80211_escan_timeout_worker(struct work_struct *work) |
| 3023 | { |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 3024 | struct brcmf_cfg80211_info *cfg = |
| 3025 | container_of(work, struct brcmf_cfg80211_info, |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 3026 | escan_timeout_work); |
| 3027 | |
Hante Meuleman | ef8596e | 2014-09-30 10:23:13 +0200 | [diff] [blame] | 3028 | brcmf_inform_bss(cfg); |
Arend van Spriel | a0f472a | 2013-04-05 10:57:49 +0200 | [diff] [blame] | 3029 | brcmf_notify_escan_complete(cfg, cfg->escan_info.ifp, true, true); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 3030 | } |
| 3031 | |
| 3032 | static void brcmf_escan_timeout(unsigned long data) |
| 3033 | { |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 3034 | struct brcmf_cfg80211_info *cfg = |
| 3035 | (struct brcmf_cfg80211_info *)data; |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 3036 | |
Arend Van Spriel | fa85b30 | 2016-11-23 10:25:25 +0000 | [diff] [blame] | 3037 | if (cfg->internal_escan || cfg->scan_request) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 3038 | brcmf_err("timer expired\n"); |
Hante Meuleman | f0799895 | 2012-11-05 16:22:13 -0800 | [diff] [blame] | 3039 | schedule_work(&cfg->escan_timeout_work); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 3040 | } |
| 3041 | } |
| 3042 | |
| 3043 | static s32 |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 3044 | brcmf_compare_update_same_bss(struct brcmf_cfg80211_info *cfg, |
| 3045 | struct brcmf_bss_info_le *bss, |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 3046 | struct brcmf_bss_info_le *bss_info_le) |
| 3047 | { |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 3048 | struct brcmu_chan ch_bss, ch_bss_info_le; |
| 3049 | |
| 3050 | ch_bss.chspec = le16_to_cpu(bss->chanspec); |
| 3051 | cfg->d11inf.decchspec(&ch_bss); |
| 3052 | ch_bss_info_le.chspec = le16_to_cpu(bss_info_le->chanspec); |
| 3053 | cfg->d11inf.decchspec(&ch_bss_info_le); |
| 3054 | |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 3055 | if (!memcmp(&bss_info_le->BSSID, &bss->BSSID, ETH_ALEN) && |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 3056 | ch_bss.band == ch_bss_info_le.band && |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 3057 | bss_info_le->SSID_len == bss->SSID_len && |
| 3058 | !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] | 3059 | if ((bss->flags & BRCMF_BSS_RSSI_ON_CHANNEL) == |
| 3060 | (bss_info_le->flags & BRCMF_BSS_RSSI_ON_CHANNEL)) { |
Arend van Spriel | 029591f | 2012-09-19 22:21:06 +0200 | [diff] [blame] | 3061 | s16 bss_rssi = le16_to_cpu(bss->RSSI); |
| 3062 | s16 bss_info_rssi = le16_to_cpu(bss_info_le->RSSI); |
| 3063 | |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 3064 | /* preserve max RSSI if the measurements are |
| 3065 | * both on-channel or both off-channel |
| 3066 | */ |
Arend van Spriel | 029591f | 2012-09-19 22:21:06 +0200 | [diff] [blame] | 3067 | if (bss_info_rssi > bss_rssi) |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 3068 | bss->RSSI = bss_info_le->RSSI; |
Arend van Spriel | 6f5838a | 2013-11-29 12:25:19 +0100 | [diff] [blame] | 3069 | } else if ((bss->flags & BRCMF_BSS_RSSI_ON_CHANNEL) && |
| 3070 | (bss_info_le->flags & BRCMF_BSS_RSSI_ON_CHANNEL) == 0) { |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 3071 | /* preserve the on-channel rssi measurement |
| 3072 | * if the new measurement is off channel |
| 3073 | */ |
| 3074 | bss->RSSI = bss_info_le->RSSI; |
Arend van Spriel | 6f5838a | 2013-11-29 12:25:19 +0100 | [diff] [blame] | 3075 | bss->flags |= BRCMF_BSS_RSSI_ON_CHANNEL; |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 3076 | } |
| 3077 | return 1; |
| 3078 | } |
| 3079 | return 0; |
| 3080 | } |
| 3081 | |
| 3082 | static s32 |
Arend van Spriel | 1993732 | 2012-11-05 16:22:32 -0800 | [diff] [blame] | 3083 | brcmf_cfg80211_escan_handler(struct brcmf_if *ifp, |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 3084 | const struct brcmf_event_msg *e, void *data) |
| 3085 | { |
Arend van Spriel | 1993732 | 2012-11-05 16:22:32 -0800 | [diff] [blame] | 3086 | struct brcmf_cfg80211_info *cfg = ifp->drvr->config; |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 3087 | s32 status; |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 3088 | struct brcmf_escan_result_le *escan_result_le; |
| 3089 | struct brcmf_bss_info_le *bss_info_le; |
| 3090 | struct brcmf_bss_info_le *bss = NULL; |
| 3091 | u32 bi_length; |
| 3092 | struct brcmf_scan_results *list; |
| 3093 | u32 i; |
Arend van Spriel | 97ed15c | 2012-09-13 21:12:06 +0200 | [diff] [blame] | 3094 | bool aborted; |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 3095 | |
Arend van Spriel | 5c36b99 | 2012-11-14 18:46:05 -0800 | [diff] [blame] | 3096 | status = e->status; |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 3097 | |
Arend van Spriel | a0f472a | 2013-04-05 10:57:49 +0200 | [diff] [blame] | 3098 | if (!test_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status)) { |
Hante Meuleman | 37a869e | 2015-10-29 20:33:17 +0100 | [diff] [blame] | 3099 | brcmf_err("scan not ready, bsscfgidx=%d\n", ifp->bsscfgidx); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 3100 | return -EPERM; |
| 3101 | } |
| 3102 | |
| 3103 | if (status == BRCMF_E_STATUS_PARTIAL) { |
Arend van Spriel | 4e8a008 | 2012-12-05 15:26:03 +0100 | [diff] [blame] | 3104 | brcmf_dbg(SCAN, "ESCAN Partial result\n"); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 3105 | escan_result_le = (struct brcmf_escan_result_le *) data; |
| 3106 | if (!escan_result_le) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 3107 | brcmf_err("Invalid escan result (NULL pointer)\n"); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 3108 | goto exit; |
| 3109 | } |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 3110 | if (le16_to_cpu(escan_result_le->bss_count) != 1) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 3111 | brcmf_err("Invalid bss_count %d: ignoring\n", |
| 3112 | escan_result_le->bss_count); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 3113 | goto exit; |
| 3114 | } |
| 3115 | bss_info_le = &escan_result_le->bss_info_le; |
| 3116 | |
Hante Meuleman | 6eda4e2 | 2013-02-08 15:54:02 +0100 | [diff] [blame] | 3117 | if (brcmf_p2p_scan_finding_common_channel(cfg, bss_info_le)) |
| 3118 | goto exit; |
| 3119 | |
Arend Van Spriel | fa85b30 | 2016-11-23 10:25:25 +0000 | [diff] [blame] | 3120 | if (!cfg->internal_escan && !cfg->scan_request) { |
Hante Meuleman | 6eda4e2 | 2013-02-08 15:54:02 +0100 | [diff] [blame] | 3121 | brcmf_dbg(SCAN, "result without cfg80211 request\n"); |
| 3122 | goto exit; |
| 3123 | } |
| 3124 | |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 3125 | bi_length = le32_to_cpu(bss_info_le->length); |
| 3126 | if (bi_length != (le32_to_cpu(escan_result_le->buflen) - |
| 3127 | WL_ESCAN_RESULTS_FIXED_SIZE)) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 3128 | brcmf_err("Invalid bss_info length %d: ignoring\n", |
| 3129 | bi_length); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 3130 | goto exit; |
| 3131 | } |
| 3132 | |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 3133 | if (!(cfg_to_wiphy(cfg)->interface_modes & |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 3134 | BIT(NL80211_IFTYPE_ADHOC))) { |
| 3135 | if (le16_to_cpu(bss_info_le->capability) & |
| 3136 | WLAN_CAPABILITY_IBSS) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 3137 | brcmf_err("Ignoring IBSS result\n"); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 3138 | goto exit; |
| 3139 | } |
| 3140 | } |
| 3141 | |
| 3142 | list = (struct brcmf_scan_results *) |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 3143 | cfg->escan_info.escan_buf; |
Hante Meuleman | d536733 | 2016-02-17 11:26:51 +0100 | [diff] [blame] | 3144 | if (bi_length > BRCMF_ESCAN_BUF_SIZE - list->buflen) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 3145 | brcmf_err("Buffer is too small: ignoring\n"); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 3146 | goto exit; |
| 3147 | } |
| 3148 | |
| 3149 | for (i = 0; i < list->count; i++) { |
| 3150 | bss = bss ? (struct brcmf_bss_info_le *) |
| 3151 | ((unsigned char *)bss + |
| 3152 | le32_to_cpu(bss->length)) : list->bss_info_le; |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 3153 | if (brcmf_compare_update_same_bss(cfg, bss, |
| 3154 | bss_info_le)) |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 3155 | goto exit; |
| 3156 | } |
Hante Meuleman | d536733 | 2016-02-17 11:26:51 +0100 | [diff] [blame] | 3157 | memcpy(&cfg->escan_info.escan_buf[list->buflen], bss_info_le, |
| 3158 | bi_length); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 3159 | list->version = le32_to_cpu(bss_info_le->version); |
| 3160 | list->buflen += bi_length; |
| 3161 | list->count++; |
| 3162 | } else { |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 3163 | cfg->escan_info.escan_state = WL_ESCAN_STATE_IDLE; |
Hante Meuleman | 6eda4e2 | 2013-02-08 15:54:02 +0100 | [diff] [blame] | 3164 | if (brcmf_p2p_scan_finding_common_channel(cfg, NULL)) |
| 3165 | goto exit; |
Arend Van Spriel | fa85b30 | 2016-11-23 10:25:25 +0000 | [diff] [blame] | 3166 | if (cfg->internal_escan || cfg->scan_request) { |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 3167 | brcmf_inform_bss(cfg); |
Arend van Spriel | 97ed15c | 2012-09-13 21:12:06 +0200 | [diff] [blame] | 3168 | aborted = status != BRCMF_E_STATUS_SUCCESS; |
Hante Meuleman | ef8596e | 2014-09-30 10:23:13 +0200 | [diff] [blame] | 3169 | brcmf_notify_escan_complete(cfg, ifp, aborted, false); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 3170 | } else |
Hante Meuleman | 6eda4e2 | 2013-02-08 15:54:02 +0100 | [diff] [blame] | 3171 | brcmf_dbg(SCAN, "Ignored scan complete result 0x%x\n", |
| 3172 | status); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 3173 | } |
| 3174 | exit: |
Peter Senna Tschudin | 12f3237 | 2014-05-31 10:14:06 -0300 | [diff] [blame] | 3175 | return 0; |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 3176 | } |
| 3177 | |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 3178 | static void brcmf_init_escan(struct brcmf_cfg80211_info *cfg) |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 3179 | { |
Arend van Spriel | 5c36b99 | 2012-11-14 18:46:05 -0800 | [diff] [blame] | 3180 | brcmf_fweh_register(cfg->pub, BRCMF_E_ESCAN_RESULT, |
| 3181 | brcmf_cfg80211_escan_handler); |
Hante Meuleman | f0799895 | 2012-11-05 16:22:13 -0800 | [diff] [blame] | 3182 | cfg->escan_info.escan_state = WL_ESCAN_STATE_IDLE; |
| 3183 | /* Init scan_timeout timer */ |
| 3184 | init_timer(&cfg->escan_timeout); |
| 3185 | cfg->escan_timeout.data = (unsigned long) cfg; |
| 3186 | cfg->escan_timeout.function = brcmf_escan_timeout; |
| 3187 | INIT_WORK(&cfg->escan_timeout_work, |
| 3188 | brcmf_cfg80211_escan_timeout_worker); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 3189 | } |
| 3190 | |
Arend Van Spriel | fa85b30 | 2016-11-23 10:25:25 +0000 | [diff] [blame] | 3191 | static struct cfg80211_scan_request * |
| 3192 | brcmf_alloc_internal_escan_request(struct wiphy *wiphy, u32 n_netinfo) { |
| 3193 | struct cfg80211_scan_request *req; |
| 3194 | size_t req_size; |
| 3195 | |
| 3196 | req_size = sizeof(*req) + |
| 3197 | n_netinfo * sizeof(req->channels[0]) + |
| 3198 | n_netinfo * sizeof(*req->ssids); |
| 3199 | |
| 3200 | req = kzalloc(req_size, GFP_KERNEL); |
| 3201 | if (req) { |
| 3202 | req->wiphy = wiphy; |
| 3203 | req->ssids = (void *)(&req->channels[0]) + |
| 3204 | n_netinfo * sizeof(req->channels[0]); |
| 3205 | } |
| 3206 | return req; |
| 3207 | } |
| 3208 | |
| 3209 | static int brcmf_internal_escan_add_info(struct cfg80211_scan_request *req, |
| 3210 | u8 *ssid, u8 ssid_len, u8 channel) |
| 3211 | { |
| 3212 | struct ieee80211_channel *chan; |
| 3213 | enum nl80211_band band; |
| 3214 | int freq; |
| 3215 | |
| 3216 | if (channel <= CH_MAX_2G_CHANNEL) |
| 3217 | band = NL80211_BAND_2GHZ; |
| 3218 | else |
| 3219 | band = NL80211_BAND_5GHZ; |
| 3220 | |
| 3221 | freq = ieee80211_channel_to_frequency(channel, band); |
| 3222 | if (!freq) |
| 3223 | return -EINVAL; |
| 3224 | |
| 3225 | chan = ieee80211_get_channel(req->wiphy, freq); |
| 3226 | if (!chan) |
| 3227 | return -EINVAL; |
| 3228 | |
| 3229 | req->channels[req->n_channels++] = chan; |
| 3230 | memcpy(req->ssids[req->n_ssids].ssid, ssid, ssid_len); |
| 3231 | req->ssids[req->n_ssids++].ssid_len = ssid_len; |
| 3232 | |
| 3233 | return 0; |
| 3234 | } |
| 3235 | |
| 3236 | static int brcmf_start_internal_escan(struct brcmf_if *ifp, |
| 3237 | struct cfg80211_scan_request *request) |
| 3238 | { |
| 3239 | struct brcmf_cfg80211_info *cfg = ifp->drvr->config; |
| 3240 | int err; |
| 3241 | |
| 3242 | if (test_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status)) { |
| 3243 | /* Abort any on-going scan */ |
| 3244 | brcmf_abort_scanning(cfg); |
| 3245 | } |
| 3246 | |
| 3247 | set_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status); |
| 3248 | cfg->escan_info.run = brcmf_run_escan; |
| 3249 | err = brcmf_do_escan(ifp, request); |
| 3250 | if (err) { |
| 3251 | clear_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status); |
| 3252 | return err; |
| 3253 | } |
| 3254 | cfg->internal_escan = true; |
| 3255 | return 0; |
| 3256 | } |
| 3257 | |
Arend Van Spriel | 53e3a80 | 2016-11-23 10:25:31 +0000 | [diff] [blame] | 3258 | static struct brcmf_pno_net_info_le * |
| 3259 | brcmf_get_netinfo_array(struct brcmf_pno_scanresults_le *pfn_v1) |
| 3260 | { |
| 3261 | struct brcmf_pno_scanresults_v2_le *pfn_v2; |
| 3262 | struct brcmf_pno_net_info_le *netinfo; |
| 3263 | |
| 3264 | switch (pfn_v1->version) { |
| 3265 | default: |
| 3266 | WARN_ON(1); |
| 3267 | /* fall-thru */ |
| 3268 | case cpu_to_le32(1): |
| 3269 | netinfo = (struct brcmf_pno_net_info_le *)(pfn_v1 + 1); |
| 3270 | break; |
| 3271 | case cpu_to_le32(2): |
| 3272 | pfn_v2 = (struct brcmf_pno_scanresults_v2_le *)pfn_v1; |
| 3273 | netinfo = (struct brcmf_pno_net_info_le *)(pfn_v2 + 1); |
| 3274 | break; |
| 3275 | } |
| 3276 | |
| 3277 | return netinfo; |
| 3278 | } |
| 3279 | |
Hante Meuleman | 5419f7f | 2016-01-05 11:05:46 +0100 | [diff] [blame] | 3280 | /* PFN result doesn't have all the info which are required by the supplicant |
| 3281 | * (For e.g IEs) Do a target Escan so that sched scan results are reported |
| 3282 | * via wl_inform_single_bss in the required format. Escan does require the |
| 3283 | * scan request in the form of cfg80211_scan_request. For timebeing, create |
| 3284 | * cfg80211_scan_request one out of the received PNO event. |
| 3285 | */ |
| 3286 | static s32 |
| 3287 | brcmf_notify_sched_scan_results(struct brcmf_if *ifp, |
| 3288 | const struct brcmf_event_msg *e, void *data) |
| 3289 | { |
| 3290 | struct brcmf_cfg80211_info *cfg = ifp->drvr->config; |
| 3291 | struct brcmf_pno_net_info_le *netinfo, *netinfo_start; |
| 3292 | struct cfg80211_scan_request *request = NULL; |
Hante Meuleman | 5419f7f | 2016-01-05 11:05:46 +0100 | [diff] [blame] | 3293 | struct wiphy *wiphy = cfg_to_wiphy(cfg); |
Arend Van Spriel | fa85b30 | 2016-11-23 10:25:25 +0000 | [diff] [blame] | 3294 | int i, err = 0; |
Hante Meuleman | 5419f7f | 2016-01-05 11:05:46 +0100 | [diff] [blame] | 3295 | struct brcmf_pno_scanresults_le *pfn_result; |
| 3296 | u32 result_count; |
| 3297 | u32 status; |
| 3298 | |
| 3299 | brcmf_dbg(SCAN, "Enter\n"); |
| 3300 | |
Hante Meuleman | 0aedbca | 2016-02-17 11:26:54 +0100 | [diff] [blame] | 3301 | if (e->datalen < (sizeof(*pfn_result) + sizeof(*netinfo))) { |
| 3302 | brcmf_dbg(SCAN, "Event data to small. Ignore\n"); |
| 3303 | return 0; |
| 3304 | } |
| 3305 | |
Hante Meuleman | 5419f7f | 2016-01-05 11:05:46 +0100 | [diff] [blame] | 3306 | if (e->event_code == BRCMF_E_PFN_NET_LOST) { |
| 3307 | brcmf_dbg(SCAN, "PFN NET LOST event. Do Nothing\n"); |
| 3308 | return 0; |
| 3309 | } |
| 3310 | |
| 3311 | pfn_result = (struct brcmf_pno_scanresults_le *)data; |
| 3312 | result_count = le32_to_cpu(pfn_result->count); |
| 3313 | status = le32_to_cpu(pfn_result->status); |
| 3314 | |
| 3315 | /* PFN event is limited to fit 512 bytes so we may get |
| 3316 | * multiple NET_FOUND events. For now place a warning here. |
| 3317 | */ |
| 3318 | WARN_ON(status != BRCMF_PNO_SCAN_COMPLETE); |
| 3319 | 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] | 3320 | if (!result_count) { |
Hante Meuleman | 5419f7f | 2016-01-05 11:05:46 +0100 | [diff] [blame] | 3321 | brcmf_err("FALSE PNO Event. (pfn_count == 0)\n"); |
| 3322 | goto out_err; |
| 3323 | } |
Arend Van Spriel | fa85b30 | 2016-11-23 10:25:25 +0000 | [diff] [blame] | 3324 | request = brcmf_alloc_internal_escan_request(wiphy, |
| 3325 | result_count); |
| 3326 | if (!request) { |
| 3327 | err = -ENOMEM; |
| 3328 | goto out_err; |
| 3329 | } |
Hante Meuleman | 5419f7f | 2016-01-05 11:05:46 +0100 | [diff] [blame] | 3330 | |
Arend Van Spriel | 53e3a80 | 2016-11-23 10:25:31 +0000 | [diff] [blame] | 3331 | netinfo_start = brcmf_get_netinfo_array(pfn_result); |
Arend Van Spriel | fa85b30 | 2016-11-23 10:25:25 +0000 | [diff] [blame] | 3332 | |
| 3333 | for (i = 0; i < result_count; i++) { |
| 3334 | netinfo = &netinfo_start[i]; |
| 3335 | if (!netinfo) { |
| 3336 | brcmf_err("Invalid netinfo ptr. index: %d\n", |
| 3337 | i); |
| 3338 | err = -EINVAL; |
| 3339 | goto out_err; |
| 3340 | } |
| 3341 | |
| 3342 | brcmf_dbg(SCAN, "SSID:%.32s Channel:%d\n", |
| 3343 | netinfo->SSID, netinfo->channel); |
| 3344 | err = brcmf_internal_escan_add_info(request, |
| 3345 | netinfo->SSID, |
| 3346 | netinfo->SSID_len, |
| 3347 | netinfo->channel); |
| 3348 | if (err) |
| 3349 | goto out_err; |
| 3350 | } |
| 3351 | |
| 3352 | err = brcmf_start_internal_escan(ifp, request); |
| 3353 | if (!err) |
| 3354 | goto free_req; |
Hante Meuleman | 5419f7f | 2016-01-05 11:05:46 +0100 | [diff] [blame] | 3355 | |
| 3356 | out_err: |
Hante Meuleman | 5419f7f | 2016-01-05 11:05:46 +0100 | [diff] [blame] | 3357 | cfg80211_sched_scan_stopped(wiphy); |
Arend Van Spriel | fa85b30 | 2016-11-23 10:25:25 +0000 | [diff] [blame] | 3358 | free_req: |
| 3359 | kfree(request); |
Hante Meuleman | 5419f7f | 2016-01-05 11:05:46 +0100 | [diff] [blame] | 3360 | return err; |
| 3361 | } |
| 3362 | |
| 3363 | static int |
| 3364 | brcmf_cfg80211_sched_scan_start(struct wiphy *wiphy, |
| 3365 | struct net_device *ndev, |
Arend Van Spriel | 3e2e86a | 2016-11-23 10:25:23 +0000 | [diff] [blame] | 3366 | struct cfg80211_sched_scan_request *req) |
Hante Meuleman | 5419f7f | 2016-01-05 11:05:46 +0100 | [diff] [blame] | 3367 | { |
| 3368 | struct brcmf_if *ifp = netdev_priv(ndev); |
| 3369 | struct brcmf_cfg80211_info *cfg = wiphy_priv(wiphy); |
Hante Meuleman | 5419f7f | 2016-01-05 11:05:46 +0100 | [diff] [blame] | 3370 | |
| 3371 | 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] | 3372 | req->n_match_sets, req->n_ssids); |
Arend Van Spriel | dfe5b0d | 2016-11-23 10:25:29 +0000 | [diff] [blame] | 3373 | |
Hante Meuleman | 5419f7f | 2016-01-05 11:05:46 +0100 | [diff] [blame] | 3374 | if (test_bit(BRCMF_SCAN_STATUS_SUPPRESS, &cfg->scan_status)) { |
| 3375 | brcmf_err("Scanning suppressed: status (%lu)\n", |
| 3376 | cfg->scan_status); |
| 3377 | return -EAGAIN; |
| 3378 | } |
| 3379 | |
Arend Van Spriel | 3e2e86a | 2016-11-23 10:25:23 +0000 | [diff] [blame] | 3380 | if (req->n_match_sets <= 0) { |
| 3381 | brcmf_dbg(SCAN, "invalid number of matchsets specified: %d\n", |
| 3382 | req->n_match_sets); |
Hante Meuleman | 5419f7f | 2016-01-05 11:05:46 +0100 | [diff] [blame] | 3383 | return -EINVAL; |
| 3384 | } |
| 3385 | |
Arend Van Spriel | 3e48611 | 2016-11-23 10:25:27 +0000 | [diff] [blame] | 3386 | return brcmf_pno_start_sched_scan(ifp, req); |
Hante Meuleman | 5419f7f | 2016-01-05 11:05:46 +0100 | [diff] [blame] | 3387 | } |
| 3388 | |
| 3389 | static int brcmf_cfg80211_sched_scan_stop(struct wiphy *wiphy, |
| 3390 | struct net_device *ndev) |
| 3391 | { |
| 3392 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); |
Arend Van Spriel | ac55136 | 2016-11-23 10:25:22 +0000 | [diff] [blame] | 3393 | struct brcmf_if *ifp = netdev_priv(ndev); |
Hante Meuleman | 5419f7f | 2016-01-05 11:05:46 +0100 | [diff] [blame] | 3394 | |
| 3395 | brcmf_dbg(SCAN, "enter\n"); |
Arend Van Spriel | ac55136 | 2016-11-23 10:25:22 +0000 | [diff] [blame] | 3396 | brcmf_pno_clean(ifp); |
Arend Van Spriel | fa85b30 | 2016-11-23 10:25:25 +0000 | [diff] [blame] | 3397 | if (cfg->internal_escan) |
Arend Van Spriel | ac55136 | 2016-11-23 10:25:22 +0000 | [diff] [blame] | 3398 | brcmf_notify_escan_complete(cfg, ifp, true, true); |
Hante Meuleman | 5419f7f | 2016-01-05 11:05:46 +0100 | [diff] [blame] | 3399 | return 0; |
| 3400 | } |
| 3401 | |
Alexandre Oliva | 5addc0d | 2012-01-16 14:00:12 -0500 | [diff] [blame] | 3402 | static __always_inline void brcmf_delay(u32 ms) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3403 | { |
| 3404 | if (ms < 1000 / HZ) { |
| 3405 | cond_resched(); |
| 3406 | mdelay(ms); |
| 3407 | } else { |
| 3408 | msleep(ms); |
| 3409 | } |
| 3410 | } |
| 3411 | |
Hante Meuleman | b9a82f8 | 2014-10-28 14:56:06 +0100 | [diff] [blame] | 3412 | static s32 brcmf_config_wowl_pattern(struct brcmf_if *ifp, u8 cmd[4], |
| 3413 | u8 *pattern, u32 patternsize, u8 *mask, |
| 3414 | u32 packet_offset) |
| 3415 | { |
| 3416 | struct brcmf_fil_wowl_pattern_le *filter; |
| 3417 | u32 masksize; |
| 3418 | u32 patternoffset; |
| 3419 | u8 *buf; |
| 3420 | u32 bufsize; |
| 3421 | s32 ret; |
| 3422 | |
| 3423 | masksize = (patternsize + 7) / 8; |
| 3424 | patternoffset = sizeof(*filter) - sizeof(filter->cmd) + masksize; |
| 3425 | |
| 3426 | bufsize = sizeof(*filter) + patternsize + masksize; |
| 3427 | buf = kzalloc(bufsize, GFP_KERNEL); |
| 3428 | if (!buf) |
| 3429 | return -ENOMEM; |
| 3430 | filter = (struct brcmf_fil_wowl_pattern_le *)buf; |
| 3431 | |
| 3432 | memcpy(filter->cmd, cmd, 4); |
| 3433 | filter->masksize = cpu_to_le32(masksize); |
| 3434 | filter->offset = cpu_to_le32(packet_offset); |
| 3435 | filter->patternoffset = cpu_to_le32(patternoffset); |
| 3436 | filter->patternsize = cpu_to_le32(patternsize); |
| 3437 | filter->type = cpu_to_le32(BRCMF_WOWL_PATTERN_TYPE_BITMAP); |
| 3438 | |
| 3439 | if ((mask) && (masksize)) |
| 3440 | memcpy(buf + sizeof(*filter), mask, masksize); |
| 3441 | if ((pattern) && (patternsize)) |
| 3442 | memcpy(buf + sizeof(*filter) + masksize, pattern, patternsize); |
| 3443 | |
| 3444 | ret = brcmf_fil_iovar_data_set(ifp, "wowl_pattern", buf, bufsize); |
| 3445 | |
| 3446 | kfree(buf); |
| 3447 | return ret; |
| 3448 | } |
| 3449 | |
Hante Meuleman | 3021ad9 | 2016-01-05 11:05:45 +0100 | [diff] [blame] | 3450 | static s32 |
| 3451 | brcmf_wowl_nd_results(struct brcmf_if *ifp, const struct brcmf_event_msg *e, |
| 3452 | void *data) |
| 3453 | { |
| 3454 | struct brcmf_cfg80211_info *cfg = ifp->drvr->config; |
| 3455 | struct brcmf_pno_scanresults_le *pfn_result; |
| 3456 | struct brcmf_pno_net_info_le *netinfo; |
| 3457 | |
| 3458 | brcmf_dbg(SCAN, "Enter\n"); |
| 3459 | |
Hante Meuleman | 0aedbca | 2016-02-17 11:26:54 +0100 | [diff] [blame] | 3460 | if (e->datalen < (sizeof(*pfn_result) + sizeof(*netinfo))) { |
| 3461 | brcmf_dbg(SCAN, "Event data to small. Ignore\n"); |
| 3462 | return 0; |
| 3463 | } |
| 3464 | |
Hante Meuleman | 3021ad9 | 2016-01-05 11:05:45 +0100 | [diff] [blame] | 3465 | pfn_result = (struct brcmf_pno_scanresults_le *)data; |
| 3466 | |
| 3467 | if (e->event_code == BRCMF_E_PFN_NET_LOST) { |
| 3468 | brcmf_dbg(SCAN, "PFN NET LOST event. Ignore\n"); |
| 3469 | return 0; |
| 3470 | } |
| 3471 | |
| 3472 | if (le32_to_cpu(pfn_result->count) < 1) { |
| 3473 | brcmf_err("Invalid result count, expected 1 (%d)\n", |
| 3474 | le32_to_cpu(pfn_result->count)); |
| 3475 | return -EINVAL; |
| 3476 | } |
| 3477 | |
Arend Van Spriel | d29afe9 | 2017-01-27 12:27:46 +0000 | [diff] [blame] | 3478 | netinfo = brcmf_get_netinfo_array(pfn_result); |
Hante Meuleman | 3021ad9 | 2016-01-05 11:05:45 +0100 | [diff] [blame] | 3479 | memcpy(cfg->wowl.nd->ssid.ssid, netinfo->SSID, netinfo->SSID_len); |
| 3480 | cfg->wowl.nd->ssid.ssid_len = netinfo->SSID_len; |
| 3481 | cfg->wowl.nd->n_channels = 1; |
| 3482 | cfg->wowl.nd->channels[0] = |
| 3483 | ieee80211_channel_to_frequency(netinfo->channel, |
| 3484 | netinfo->channel <= CH_MAX_2G_CHANNEL ? |
| 3485 | NL80211_BAND_2GHZ : NL80211_BAND_5GHZ); |
| 3486 | cfg->wowl.nd_info->n_matches = 1; |
| 3487 | cfg->wowl.nd_info->matches[0] = cfg->wowl.nd; |
| 3488 | |
| 3489 | /* Inform (the resume task) that the net detect information was recvd */ |
| 3490 | cfg->wowl.nd_data_completed = true; |
| 3491 | wake_up(&cfg->wowl.nd_data_wait); |
| 3492 | |
| 3493 | return 0; |
| 3494 | } |
| 3495 | |
Hante Meuleman | aeb6422 | 2015-10-29 20:33:19 +0100 | [diff] [blame] | 3496 | #ifdef CONFIG_PM |
| 3497 | |
| 3498 | static void brcmf_report_wowl_wakeind(struct wiphy *wiphy, struct brcmf_if *ifp) |
| 3499 | { |
Hante Meuleman | 3021ad9 | 2016-01-05 11:05:45 +0100 | [diff] [blame] | 3500 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); |
Hante Meuleman | aeb6422 | 2015-10-29 20:33:19 +0100 | [diff] [blame] | 3501 | struct brcmf_wowl_wakeind_le wake_ind_le; |
| 3502 | struct cfg80211_wowlan_wakeup wakeup_data; |
| 3503 | struct cfg80211_wowlan_wakeup *wakeup; |
| 3504 | u32 wakeind; |
| 3505 | s32 err; |
Hante Meuleman | 3021ad9 | 2016-01-05 11:05:45 +0100 | [diff] [blame] | 3506 | int timeout; |
Hante Meuleman | aeb6422 | 2015-10-29 20:33:19 +0100 | [diff] [blame] | 3507 | |
| 3508 | err = brcmf_fil_iovar_data_get(ifp, "wowl_wakeind", &wake_ind_le, |
| 3509 | sizeof(wake_ind_le)); |
Hante Meuleman | 3021ad9 | 2016-01-05 11:05:45 +0100 | [diff] [blame] | 3510 | if (err) { |
Hante Meuleman | aeb6422 | 2015-10-29 20:33:19 +0100 | [diff] [blame] | 3511 | brcmf_err("Get wowl_wakeind failed, err = %d\n", err); |
| 3512 | return; |
| 3513 | } |
| 3514 | |
| 3515 | wakeind = le32_to_cpu(wake_ind_le.ucode_wakeind); |
| 3516 | if (wakeind & (BRCMF_WOWL_MAGIC | BRCMF_WOWL_DIS | BRCMF_WOWL_BCN | |
Hante Meuleman | 3021ad9 | 2016-01-05 11:05:45 +0100 | [diff] [blame] | 3517 | BRCMF_WOWL_RETR | BRCMF_WOWL_NET | |
| 3518 | BRCMF_WOWL_PFN_FOUND)) { |
Hante Meuleman | aeb6422 | 2015-10-29 20:33:19 +0100 | [diff] [blame] | 3519 | wakeup = &wakeup_data; |
| 3520 | memset(&wakeup_data, 0, sizeof(wakeup_data)); |
| 3521 | wakeup_data.pattern_idx = -1; |
| 3522 | |
| 3523 | if (wakeind & BRCMF_WOWL_MAGIC) { |
| 3524 | brcmf_dbg(INFO, "WOWL Wake indicator: BRCMF_WOWL_MAGIC\n"); |
| 3525 | wakeup_data.magic_pkt = true; |
| 3526 | } |
| 3527 | if (wakeind & BRCMF_WOWL_DIS) { |
| 3528 | brcmf_dbg(INFO, "WOWL Wake indicator: BRCMF_WOWL_DIS\n"); |
| 3529 | wakeup_data.disconnect = true; |
| 3530 | } |
| 3531 | if (wakeind & BRCMF_WOWL_BCN) { |
| 3532 | brcmf_dbg(INFO, "WOWL Wake indicator: BRCMF_WOWL_BCN\n"); |
| 3533 | wakeup_data.disconnect = true; |
| 3534 | } |
| 3535 | if (wakeind & BRCMF_WOWL_RETR) { |
| 3536 | brcmf_dbg(INFO, "WOWL Wake indicator: BRCMF_WOWL_RETR\n"); |
| 3537 | wakeup_data.disconnect = true; |
| 3538 | } |
| 3539 | if (wakeind & BRCMF_WOWL_NET) { |
| 3540 | brcmf_dbg(INFO, "WOWL Wake indicator: BRCMF_WOWL_NET\n"); |
| 3541 | /* For now always map to pattern 0, no API to get |
| 3542 | * correct information available at the moment. |
| 3543 | */ |
| 3544 | wakeup_data.pattern_idx = 0; |
| 3545 | } |
Hante Meuleman | 3021ad9 | 2016-01-05 11:05:45 +0100 | [diff] [blame] | 3546 | if (wakeind & BRCMF_WOWL_PFN_FOUND) { |
| 3547 | brcmf_dbg(INFO, "WOWL Wake indicator: BRCMF_WOWL_PFN_FOUND\n"); |
| 3548 | timeout = wait_event_timeout(cfg->wowl.nd_data_wait, |
| 3549 | cfg->wowl.nd_data_completed, |
| 3550 | BRCMF_ND_INFO_TIMEOUT); |
| 3551 | if (!timeout) |
| 3552 | brcmf_err("No result for wowl net detect\n"); |
| 3553 | else |
| 3554 | wakeup_data.net_detect = cfg->wowl.nd_info; |
| 3555 | } |
Hante Meuleman | 5c22fb8 | 2016-02-17 11:27:03 +0100 | [diff] [blame] | 3556 | if (wakeind & BRCMF_WOWL_GTK_FAILURE) { |
| 3557 | brcmf_dbg(INFO, "WOWL Wake indicator: BRCMF_WOWL_GTK_FAILURE\n"); |
| 3558 | wakeup_data.gtk_rekey_failure = true; |
| 3559 | } |
Hante Meuleman | aeb6422 | 2015-10-29 20:33:19 +0100 | [diff] [blame] | 3560 | } else { |
| 3561 | wakeup = NULL; |
| 3562 | } |
| 3563 | cfg80211_report_wowlan_wakeup(&ifp->vif->wdev, wakeup, GFP_KERNEL); |
| 3564 | } |
| 3565 | |
| 3566 | #else |
| 3567 | |
| 3568 | static void brcmf_report_wowl_wakeind(struct wiphy *wiphy, struct brcmf_if *ifp) |
| 3569 | { |
| 3570 | } |
| 3571 | |
| 3572 | #endif /* CONFIG_PM */ |
| 3573 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3574 | static s32 brcmf_cfg80211_resume(struct wiphy *wiphy) |
| 3575 | { |
Hante Meuleman | 4eb3af7 | 2014-09-30 10:23:18 +0200 | [diff] [blame] | 3576 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); |
| 3577 | struct net_device *ndev = cfg_to_ndev(cfg); |
| 3578 | struct brcmf_if *ifp = netdev_priv(ndev); |
| 3579 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 3580 | brcmf_dbg(TRACE, "Enter\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3581 | |
Hante Meuleman | 3021ad9 | 2016-01-05 11:05:45 +0100 | [diff] [blame] | 3582 | if (cfg->wowl.active) { |
Hante Meuleman | aeb6422 | 2015-10-29 20:33:19 +0100 | [diff] [blame] | 3583 | brcmf_report_wowl_wakeind(wiphy, ifp); |
| 3584 | brcmf_fil_iovar_int_set(ifp, "wowl_clear", 0); |
| 3585 | brcmf_config_wowl_pattern(ifp, "clr", NULL, 0, NULL, 0); |
Hante Meuleman | 73ef9e6 | 2016-02-17 11:27:05 +0100 | [diff] [blame] | 3586 | if (!brcmf_feat_is_enabled(ifp, BRCMF_FEAT_WOWL_ARP_ND)) |
| 3587 | brcmf_configure_arp_nd_offload(ifp, true); |
Hante Meuleman | 4eb3af7 | 2014-09-30 10:23:18 +0200 | [diff] [blame] | 3588 | brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_PM, |
Hante Meuleman | 3021ad9 | 2016-01-05 11:05:45 +0100 | [diff] [blame] | 3589 | cfg->wowl.pre_pmmode); |
| 3590 | cfg->wowl.active = false; |
| 3591 | if (cfg->wowl.nd_enabled) { |
| 3592 | brcmf_cfg80211_sched_scan_stop(cfg->wiphy, ifp->ndev); |
| 3593 | brcmf_fweh_unregister(cfg->pub, BRCMF_E_PFN_NET_FOUND); |
| 3594 | brcmf_fweh_register(cfg->pub, BRCMF_E_PFN_NET_FOUND, |
| 3595 | brcmf_notify_sched_scan_results); |
| 3596 | cfg->wowl.nd_enabled = false; |
| 3597 | } |
Hante Meuleman | 4eb3af7 | 2014-09-30 10:23:18 +0200 | [diff] [blame] | 3598 | } |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3599 | return 0; |
| 3600 | } |
| 3601 | |
Hante Meuleman | 4eb3af7 | 2014-09-30 10:23:18 +0200 | [diff] [blame] | 3602 | static void brcmf_configure_wowl(struct brcmf_cfg80211_info *cfg, |
| 3603 | struct brcmf_if *ifp, |
| 3604 | struct cfg80211_wowlan *wowl) |
| 3605 | { |
| 3606 | u32 wowl_config; |
Hante Meuleman | a7ed782 | 2016-09-19 12:09:58 +0100 | [diff] [blame] | 3607 | struct brcmf_wowl_wakeind_le wowl_wakeind; |
Hante Meuleman | b9a82f8 | 2014-10-28 14:56:06 +0100 | [diff] [blame] | 3608 | u32 i; |
Hante Meuleman | 4eb3af7 | 2014-09-30 10:23:18 +0200 | [diff] [blame] | 3609 | |
| 3610 | brcmf_dbg(TRACE, "Suspend, wowl config.\n"); |
| 3611 | |
Hante Meuleman | 73ef9e6 | 2016-02-17 11:27:05 +0100 | [diff] [blame] | 3612 | if (!brcmf_feat_is_enabled(ifp, BRCMF_FEAT_WOWL_ARP_ND)) |
| 3613 | brcmf_configure_arp_nd_offload(ifp, false); |
Hante Meuleman | 3021ad9 | 2016-01-05 11:05:45 +0100 | [diff] [blame] | 3614 | 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] | 3615 | brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_PM, PM_MAX); |
| 3616 | |
| 3617 | wowl_config = 0; |
| 3618 | if (wowl->disconnect) |
Hante Meuleman | b9a82f8 | 2014-10-28 14:56:06 +0100 | [diff] [blame] | 3619 | wowl_config = BRCMF_WOWL_DIS | BRCMF_WOWL_BCN | BRCMF_WOWL_RETR; |
Hante Meuleman | 4eb3af7 | 2014-09-30 10:23:18 +0200 | [diff] [blame] | 3620 | if (wowl->magic_pkt) |
Hante Meuleman | b9a82f8 | 2014-10-28 14:56:06 +0100 | [diff] [blame] | 3621 | wowl_config |= BRCMF_WOWL_MAGIC; |
| 3622 | if ((wowl->patterns) && (wowl->n_patterns)) { |
| 3623 | wowl_config |= BRCMF_WOWL_NET; |
| 3624 | for (i = 0; i < wowl->n_patterns; i++) { |
| 3625 | brcmf_config_wowl_pattern(ifp, "add", |
| 3626 | (u8 *)wowl->patterns[i].pattern, |
| 3627 | wowl->patterns[i].pattern_len, |
| 3628 | (u8 *)wowl->patterns[i].mask, |
| 3629 | wowl->patterns[i].pkt_offset); |
| 3630 | } |
| 3631 | } |
Hante Meuleman | 3021ad9 | 2016-01-05 11:05:45 +0100 | [diff] [blame] | 3632 | if (wowl->nd_config) { |
| 3633 | brcmf_cfg80211_sched_scan_start(cfg->wiphy, ifp->ndev, |
| 3634 | wowl->nd_config); |
| 3635 | wowl_config |= BRCMF_WOWL_PFN_FOUND; |
| 3636 | |
| 3637 | cfg->wowl.nd_data_completed = false; |
| 3638 | cfg->wowl.nd_enabled = true; |
| 3639 | /* Now reroute the event for PFN to the wowl function. */ |
| 3640 | brcmf_fweh_unregister(cfg->pub, BRCMF_E_PFN_NET_FOUND); |
| 3641 | brcmf_fweh_register(cfg->pub, BRCMF_E_PFN_NET_FOUND, |
| 3642 | brcmf_wowl_nd_results); |
| 3643 | } |
Hante Meuleman | 5c22fb8 | 2016-02-17 11:27:03 +0100 | [diff] [blame] | 3644 | if (wowl->gtk_rekey_failure) |
| 3645 | wowl_config |= BRCMF_WOWL_GTK_FAILURE; |
Hante Meuleman | 3021ad9 | 2016-01-05 11:05:45 +0100 | [diff] [blame] | 3646 | if (!test_bit(BRCMF_VIF_STATUS_CONNECTED, &ifp->vif->sme_state)) |
| 3647 | wowl_config |= BRCMF_WOWL_UNASSOC; |
| 3648 | |
Hante Meuleman | a7ed782 | 2016-09-19 12:09:58 +0100 | [diff] [blame] | 3649 | memcpy(&wowl_wakeind, "clear", 6); |
| 3650 | brcmf_fil_iovar_data_set(ifp, "wowl_wakeind", &wowl_wakeind, |
| 3651 | sizeof(wowl_wakeind)); |
Hante Meuleman | 4eb3af7 | 2014-09-30 10:23:18 +0200 | [diff] [blame] | 3652 | brcmf_fil_iovar_int_set(ifp, "wowl", wowl_config); |
| 3653 | brcmf_fil_iovar_int_set(ifp, "wowl_activate", 1); |
| 3654 | brcmf_bus_wowl_config(cfg->pub->bus_if, true); |
Hante Meuleman | 3021ad9 | 2016-01-05 11:05:45 +0100 | [diff] [blame] | 3655 | cfg->wowl.active = true; |
Hante Meuleman | 4eb3af7 | 2014-09-30 10:23:18 +0200 | [diff] [blame] | 3656 | } |
| 3657 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3658 | static s32 brcmf_cfg80211_suspend(struct wiphy *wiphy, |
Hante Meuleman | 4eb3af7 | 2014-09-30 10:23:18 +0200 | [diff] [blame] | 3659 | struct cfg80211_wowlan *wowl) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3660 | { |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 3661 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); |
| 3662 | struct net_device *ndev = cfg_to_ndev(cfg); |
Hante Meuleman | 4eb3af7 | 2014-09-30 10:23:18 +0200 | [diff] [blame] | 3663 | struct brcmf_if *ifp = netdev_priv(ndev); |
Arend van Spriel | 7d64107 | 2012-10-22 13:55:39 -0700 | [diff] [blame] | 3664 | struct brcmf_cfg80211_vif *vif; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3665 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 3666 | brcmf_dbg(TRACE, "Enter\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3667 | |
Hante Meuleman | 4eb3af7 | 2014-09-30 10:23:18 +0200 | [diff] [blame] | 3668 | /* if the primary net_device is not READY there is nothing |
Arend van Spriel | 7d64107 | 2012-10-22 13:55:39 -0700 | [diff] [blame] | 3669 | * we can do but pray resume goes smoothly. |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3670 | */ |
Hante Meuleman | 4eb3af7 | 2014-09-30 10:23:18 +0200 | [diff] [blame] | 3671 | if (!check_vif_up(ifp->vif)) |
Arend van Spriel | 7d64107 | 2012-10-22 13:55:39 -0700 | [diff] [blame] | 3672 | goto exit; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3673 | |
Hante Meuleman | 3021ad9 | 2016-01-05 11:05:45 +0100 | [diff] [blame] | 3674 | /* Stop scheduled scan */ |
| 3675 | if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_PNO)) |
| 3676 | brcmf_cfg80211_sched_scan_stop(wiphy, ndev); |
| 3677 | |
Arend van Spriel | 7d64107 | 2012-10-22 13:55:39 -0700 | [diff] [blame] | 3678 | /* end any scanning */ |
| 3679 | if (test_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status)) |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 3680 | brcmf_abort_scanning(cfg); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3681 | |
Hante Meuleman | 4eb3af7 | 2014-09-30 10:23:18 +0200 | [diff] [blame] | 3682 | if (wowl == NULL) { |
| 3683 | brcmf_bus_wowl_config(cfg->pub->bus_if, false); |
| 3684 | list_for_each_entry(vif, &cfg->vif_list, list) { |
| 3685 | if (!test_bit(BRCMF_VIF_STATUS_READY, &vif->sme_state)) |
| 3686 | continue; |
| 3687 | /* While going to suspend if associated with AP |
| 3688 | * disassociate from AP to save power while system is |
| 3689 | * in suspended state |
| 3690 | */ |
Arend van Spriel | 9b7a0dd | 2015-01-25 20:31:33 +0100 | [diff] [blame] | 3691 | brcmf_link_down(vif, WLAN_REASON_UNSPECIFIED); |
Hante Meuleman | 4eb3af7 | 2014-09-30 10:23:18 +0200 | [diff] [blame] | 3692 | /* Make sure WPA_Supplicant receives all the event |
| 3693 | * generated due to DISASSOC call to the fw to keep |
| 3694 | * the state fw and WPA_Supplicant state consistent |
| 3695 | */ |
| 3696 | brcmf_delay(500); |
| 3697 | } |
| 3698 | /* Configure MPC */ |
| 3699 | brcmf_set_mpc(ifp, 1); |
| 3700 | |
| 3701 | } else { |
| 3702 | /* Configure WOWL paramaters */ |
| 3703 | brcmf_configure_wowl(cfg, ifp, wowl); |
| 3704 | } |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3705 | |
Arend van Spriel | 7d64107 | 2012-10-22 13:55:39 -0700 | [diff] [blame] | 3706 | exit: |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 3707 | brcmf_dbg(TRACE, "Exit\n"); |
Arend van Spriel | 7d64107 | 2012-10-22 13:55:39 -0700 | [diff] [blame] | 3708 | /* clear any scanning activity */ |
| 3709 | cfg->scan_status = 0; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3710 | return 0; |
| 3711 | } |
| 3712 | |
| 3713 | static __used s32 |
Hante Meuleman | 6c404f3 | 2015-12-10 13:43:03 +0100 | [diff] [blame] | 3714 | 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] | 3715 | { |
Hante Meuleman | 6c404f3 | 2015-12-10 13:43:03 +0100 | [diff] [blame] | 3716 | struct brcmf_pmk_list_le *pmk_list; |
| 3717 | int i; |
| 3718 | u32 npmk; |
| 3719 | s32 err; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3720 | |
Hante Meuleman | 6c404f3 | 2015-12-10 13:43:03 +0100 | [diff] [blame] | 3721 | pmk_list = &cfg->pmk_list; |
| 3722 | npmk = le32_to_cpu(pmk_list->npmk); |
Arend van Spriel | 40c8e95 | 2011-10-12 20:51:20 +0200 | [diff] [blame] | 3723 | |
Hante Meuleman | 6c404f3 | 2015-12-10 13:43:03 +0100 | [diff] [blame] | 3724 | brcmf_dbg(CONN, "No of elements %d\n", npmk); |
| 3725 | for (i = 0; i < npmk; i++) |
| 3726 | 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] | 3727 | |
Hante Meuleman | 6c404f3 | 2015-12-10 13:43:03 +0100 | [diff] [blame] | 3728 | err = brcmf_fil_iovar_data_set(ifp, "pmkid_info", pmk_list, |
| 3729 | sizeof(*pmk_list)); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3730 | |
| 3731 | return err; |
| 3732 | } |
| 3733 | |
| 3734 | static s32 |
| 3735 | brcmf_cfg80211_set_pmksa(struct wiphy *wiphy, struct net_device *ndev, |
| 3736 | struct cfg80211_pmksa *pmksa) |
| 3737 | { |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 3738 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); |
Arend van Spriel | 0abb5f21 | 2012-10-22 13:55:32 -0700 | [diff] [blame] | 3739 | struct brcmf_if *ifp = netdev_priv(ndev); |
Hante Meuleman | 6c404f3 | 2015-12-10 13:43:03 +0100 | [diff] [blame] | 3740 | struct brcmf_pmksa *pmk = &cfg->pmk_list.pmk[0]; |
| 3741 | s32 err; |
| 3742 | u32 npmk, i; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3743 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 3744 | brcmf_dbg(TRACE, "Enter\n"); |
Arend van Spriel | ce81e31 | 2012-10-22 13:55:37 -0700 | [diff] [blame] | 3745 | if (!check_vif_up(ifp->vif)) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3746 | return -EIO; |
| 3747 | |
Hante Meuleman | 6c404f3 | 2015-12-10 13:43:03 +0100 | [diff] [blame] | 3748 | npmk = le32_to_cpu(cfg->pmk_list.npmk); |
| 3749 | for (i = 0; i < npmk; i++) |
| 3750 | if (!memcmp(pmksa->bssid, pmk[i].bssid, ETH_ALEN)) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3751 | break; |
Hante Meuleman | 6c404f3 | 2015-12-10 13:43:03 +0100 | [diff] [blame] | 3752 | if (i < BRCMF_MAXPMKID) { |
| 3753 | memcpy(pmk[i].bssid, pmksa->bssid, ETH_ALEN); |
| 3754 | memcpy(pmk[i].pmkid, pmksa->pmkid, WLAN_PMKID_LEN); |
| 3755 | if (i == npmk) { |
| 3756 | npmk++; |
| 3757 | cfg->pmk_list.npmk = cpu_to_le32(npmk); |
Arend van Spriel | 40c8e95 | 2011-10-12 20:51:20 +0200 | [diff] [blame] | 3758 | } |
Hante Meuleman | 6c404f3 | 2015-12-10 13:43:03 +0100 | [diff] [blame] | 3759 | } else { |
| 3760 | brcmf_err("Too many PMKSA entries cached %d\n", npmk); |
| 3761 | return -EINVAL; |
| 3762 | } |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3763 | |
Hante Meuleman | 6c404f3 | 2015-12-10 13:43:03 +0100 | [diff] [blame] | 3764 | brcmf_dbg(CONN, "set_pmksa - PMK bssid: %pM =\n", pmk[npmk].bssid); |
| 3765 | for (i = 0; i < WLAN_PMKID_LEN; i += 4) |
| 3766 | brcmf_dbg(CONN, "%02x %02x %02x %02x\n", pmk[npmk].pmkid[i], |
| 3767 | pmk[npmk].pmkid[i + 1], pmk[npmk].pmkid[i + 2], |
| 3768 | pmk[npmk].pmkid[i + 3]); |
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 | err = brcmf_update_pmklist(cfg, ifp); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3771 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 3772 | brcmf_dbg(TRACE, "Exit\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3773 | return err; |
| 3774 | } |
| 3775 | |
| 3776 | static s32 |
| 3777 | brcmf_cfg80211_del_pmksa(struct wiphy *wiphy, struct net_device *ndev, |
Hante Meuleman | 6c404f3 | 2015-12-10 13:43:03 +0100 | [diff] [blame] | 3778 | struct cfg80211_pmksa *pmksa) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3779 | { |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 3780 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); |
Arend van Spriel | 0abb5f21 | 2012-10-22 13:55:32 -0700 | [diff] [blame] | 3781 | struct brcmf_if *ifp = netdev_priv(ndev); |
Hante Meuleman | 6c404f3 | 2015-12-10 13:43:03 +0100 | [diff] [blame] | 3782 | struct brcmf_pmksa *pmk = &cfg->pmk_list.pmk[0]; |
| 3783 | s32 err; |
| 3784 | u32 npmk, i; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3785 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 3786 | brcmf_dbg(TRACE, "Enter\n"); |
Arend van Spriel | ce81e31 | 2012-10-22 13:55:37 -0700 | [diff] [blame] | 3787 | if (!check_vif_up(ifp->vif)) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3788 | return -EIO; |
| 3789 | |
Nicolas Iooss | 7703773ef | 2016-08-23 11:37:17 +0200 | [diff] [blame] | 3790 | brcmf_dbg(CONN, "del_pmksa - PMK bssid = %pM\n", pmksa->bssid); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3791 | |
Hante Meuleman | 6c404f3 | 2015-12-10 13:43:03 +0100 | [diff] [blame] | 3792 | npmk = le32_to_cpu(cfg->pmk_list.npmk); |
| 3793 | for (i = 0; i < npmk; i++) |
Nicolas Iooss | 7703773ef | 2016-08-23 11:37:17 +0200 | [diff] [blame] | 3794 | if (!memcmp(pmksa->bssid, pmk[i].bssid, ETH_ALEN)) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3795 | break; |
| 3796 | |
Hante Meuleman | 6c404f3 | 2015-12-10 13:43:03 +0100 | [diff] [blame] | 3797 | if ((npmk > 0) && (i < npmk)) { |
| 3798 | for (; i < (npmk - 1); i++) { |
| 3799 | memcpy(&pmk[i].bssid, &pmk[i + 1].bssid, ETH_ALEN); |
| 3800 | memcpy(&pmk[i].pmkid, &pmk[i + 1].pmkid, |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3801 | WLAN_PMKID_LEN); |
| 3802 | } |
Hante Meuleman | 6c404f3 | 2015-12-10 13:43:03 +0100 | [diff] [blame] | 3803 | memset(&pmk[i], 0, sizeof(*pmk)); |
| 3804 | cfg->pmk_list.npmk = cpu_to_le32(npmk - 1); |
| 3805 | } else { |
| 3806 | brcmf_err("Cache entry not found\n"); |
| 3807 | return -EINVAL; |
| 3808 | } |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3809 | |
Hante Meuleman | 6c404f3 | 2015-12-10 13:43:03 +0100 | [diff] [blame] | 3810 | err = brcmf_update_pmklist(cfg, ifp); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3811 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 3812 | brcmf_dbg(TRACE, "Exit\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3813 | return err; |
| 3814 | |
| 3815 | } |
| 3816 | |
| 3817 | static s32 |
| 3818 | brcmf_cfg80211_flush_pmksa(struct wiphy *wiphy, struct net_device *ndev) |
| 3819 | { |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 3820 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); |
Arend van Spriel | 0abb5f21 | 2012-10-22 13:55:32 -0700 | [diff] [blame] | 3821 | struct brcmf_if *ifp = netdev_priv(ndev); |
Hante Meuleman | 6c404f3 | 2015-12-10 13:43:03 +0100 | [diff] [blame] | 3822 | s32 err; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3823 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 3824 | brcmf_dbg(TRACE, "Enter\n"); |
Arend van Spriel | ce81e31 | 2012-10-22 13:55:37 -0700 | [diff] [blame] | 3825 | if (!check_vif_up(ifp->vif)) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3826 | return -EIO; |
| 3827 | |
Hante Meuleman | 6c404f3 | 2015-12-10 13:43:03 +0100 | [diff] [blame] | 3828 | memset(&cfg->pmk_list, 0, sizeof(cfg->pmk_list)); |
| 3829 | err = brcmf_update_pmklist(cfg, ifp); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3830 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 3831 | brcmf_dbg(TRACE, "Exit\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3832 | return err; |
| 3833 | |
| 3834 | } |
| 3835 | |
Hante Meuleman | 1f17011 | 2013-02-06 18:40:38 +0100 | [diff] [blame] | 3836 | static s32 brcmf_configure_opensecurity(struct brcmf_if *ifp) |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3837 | { |
| 3838 | s32 err; |
| 3839 | |
| 3840 | /* set auth */ |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 3841 | err = brcmf_fil_bsscfg_int_set(ifp, "auth", 0); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3842 | if (err < 0) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 3843 | brcmf_err("auth error %d\n", err); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3844 | return err; |
| 3845 | } |
| 3846 | /* set wsec */ |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 3847 | err = brcmf_fil_bsscfg_int_set(ifp, "wsec", 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("wsec error %d\n", err); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3850 | return err; |
| 3851 | } |
| 3852 | /* set upper-layer auth */ |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 3853 | err = brcmf_fil_bsscfg_int_set(ifp, "wpa_auth", WPA_AUTH_NONE); |
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("wpa_auth error %d\n", err); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3856 | return err; |
| 3857 | } |
| 3858 | |
| 3859 | return 0; |
| 3860 | } |
| 3861 | |
| 3862 | static bool brcmf_valid_wpa_oui(u8 *oui, bool is_rsn_ie) |
| 3863 | { |
| 3864 | if (is_rsn_ie) |
| 3865 | return (memcmp(oui, RSN_OUI, TLV_OUI_LEN) == 0); |
| 3866 | |
| 3867 | return (memcmp(oui, WPA_OUI, TLV_OUI_LEN) == 0); |
| 3868 | } |
| 3869 | |
| 3870 | static s32 |
Hante Meuleman | a44aa40 | 2014-12-03 21:05:33 +0100 | [diff] [blame] | 3871 | brcmf_configure_wpaie(struct brcmf_if *ifp, |
Johannes Berg | 4b5800f | 2014-01-15 14:55:59 +0100 | [diff] [blame] | 3872 | const struct brcmf_vs_tlv *wpa_ie, |
| 3873 | bool is_rsn_ie) |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3874 | { |
| 3875 | u32 auth = 0; /* d11 open authentication */ |
| 3876 | u16 count; |
| 3877 | s32 err = 0; |
Hante Meuleman | 240d61a | 2016-02-17 11:27:10 +0100 | [diff] [blame] | 3878 | s32 len; |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3879 | u32 i; |
| 3880 | u32 wsec; |
| 3881 | u32 pval = 0; |
| 3882 | u32 gval = 0; |
| 3883 | u32 wpa_auth = 0; |
| 3884 | u32 offset; |
| 3885 | u8 *data; |
| 3886 | u16 rsn_cap; |
| 3887 | u32 wme_bss_disable; |
Hante Meuleman | 240d61a | 2016-02-17 11:27:10 +0100 | [diff] [blame] | 3888 | u32 mfp; |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3889 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 3890 | brcmf_dbg(TRACE, "Enter\n"); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3891 | if (wpa_ie == NULL) |
| 3892 | goto exit; |
| 3893 | |
| 3894 | len = wpa_ie->len + TLV_HDR_LEN; |
| 3895 | data = (u8 *)wpa_ie; |
Hante Meuleman | 619c5a9 | 2013-01-02 15:12:39 +0100 | [diff] [blame] | 3896 | offset = TLV_HDR_LEN; |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3897 | if (!is_rsn_ie) |
| 3898 | offset += VS_IE_FIXED_HDR_LEN; |
Hante Meuleman | 619c5a9 | 2013-01-02 15:12:39 +0100 | [diff] [blame] | 3899 | else |
| 3900 | offset += WPA_IE_VERSION_LEN; |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3901 | |
| 3902 | /* check for multicast cipher suite */ |
| 3903 | if (offset + WPA_IE_MIN_OUI_LEN > len) { |
| 3904 | err = -EINVAL; |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 3905 | brcmf_err("no multicast cipher suite\n"); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3906 | goto exit; |
| 3907 | } |
| 3908 | |
| 3909 | if (!brcmf_valid_wpa_oui(&data[offset], is_rsn_ie)) { |
| 3910 | err = -EINVAL; |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 3911 | brcmf_err("ivalid OUI\n"); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3912 | goto exit; |
| 3913 | } |
| 3914 | offset += TLV_OUI_LEN; |
| 3915 | |
| 3916 | /* pick up multicast cipher */ |
| 3917 | switch (data[offset]) { |
| 3918 | case WPA_CIPHER_NONE: |
| 3919 | gval = 0; |
| 3920 | break; |
| 3921 | case WPA_CIPHER_WEP_40: |
| 3922 | case WPA_CIPHER_WEP_104: |
| 3923 | gval = WEP_ENABLED; |
| 3924 | break; |
| 3925 | case WPA_CIPHER_TKIP: |
| 3926 | gval = TKIP_ENABLED; |
| 3927 | break; |
| 3928 | case WPA_CIPHER_AES_CCM: |
| 3929 | gval = AES_ENABLED; |
| 3930 | break; |
| 3931 | default: |
| 3932 | err = -EINVAL; |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 3933 | brcmf_err("Invalid multi cast cipher info\n"); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3934 | goto exit; |
| 3935 | } |
| 3936 | |
| 3937 | offset++; |
| 3938 | /* walk thru unicast cipher list and pick up what we recognize */ |
| 3939 | count = data[offset] + (data[offset + 1] << 8); |
| 3940 | offset += WPA_IE_SUITE_COUNT_LEN; |
| 3941 | /* Check for unicast suite(s) */ |
| 3942 | if (offset + (WPA_IE_MIN_OUI_LEN * count) > len) { |
| 3943 | err = -EINVAL; |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 3944 | brcmf_err("no unicast cipher suite\n"); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3945 | goto exit; |
| 3946 | } |
| 3947 | for (i = 0; i < count; i++) { |
| 3948 | if (!brcmf_valid_wpa_oui(&data[offset], is_rsn_ie)) { |
| 3949 | err = -EINVAL; |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 3950 | brcmf_err("ivalid OUI\n"); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3951 | goto exit; |
| 3952 | } |
| 3953 | offset += TLV_OUI_LEN; |
| 3954 | switch (data[offset]) { |
| 3955 | case WPA_CIPHER_NONE: |
| 3956 | break; |
| 3957 | case WPA_CIPHER_WEP_40: |
| 3958 | case WPA_CIPHER_WEP_104: |
| 3959 | pval |= WEP_ENABLED; |
| 3960 | break; |
| 3961 | case WPA_CIPHER_TKIP: |
| 3962 | pval |= TKIP_ENABLED; |
| 3963 | break; |
| 3964 | case WPA_CIPHER_AES_CCM: |
| 3965 | pval |= AES_ENABLED; |
| 3966 | break; |
| 3967 | default: |
Colin Ian King | ad334bb | 2016-12-23 00:43:22 +0000 | [diff] [blame] | 3968 | brcmf_err("Invalid unicast security info\n"); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3969 | } |
| 3970 | offset++; |
| 3971 | } |
| 3972 | /* walk thru auth management suite list and pick up what we recognize */ |
| 3973 | count = data[offset] + (data[offset + 1] << 8); |
| 3974 | offset += WPA_IE_SUITE_COUNT_LEN; |
| 3975 | /* Check for auth key management suite(s) */ |
| 3976 | if (offset + (WPA_IE_MIN_OUI_LEN * count) > len) { |
| 3977 | err = -EINVAL; |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 3978 | brcmf_err("no auth key mgmt suite\n"); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3979 | goto exit; |
| 3980 | } |
| 3981 | for (i = 0; i < count; i++) { |
| 3982 | if (!brcmf_valid_wpa_oui(&data[offset], is_rsn_ie)) { |
| 3983 | err = -EINVAL; |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 3984 | brcmf_err("ivalid OUI\n"); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3985 | goto exit; |
| 3986 | } |
| 3987 | offset += TLV_OUI_LEN; |
| 3988 | switch (data[offset]) { |
| 3989 | case RSN_AKM_NONE: |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 3990 | brcmf_dbg(TRACE, "RSN_AKM_NONE\n"); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3991 | wpa_auth |= WPA_AUTH_NONE; |
| 3992 | break; |
| 3993 | case RSN_AKM_UNSPECIFIED: |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 3994 | brcmf_dbg(TRACE, "RSN_AKM_UNSPECIFIED\n"); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3995 | is_rsn_ie ? (wpa_auth |= WPA2_AUTH_UNSPECIFIED) : |
| 3996 | (wpa_auth |= WPA_AUTH_UNSPECIFIED); |
| 3997 | break; |
| 3998 | case RSN_AKM_PSK: |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 3999 | brcmf_dbg(TRACE, "RSN_AKM_PSK\n"); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4000 | is_rsn_ie ? (wpa_auth |= WPA2_AUTH_PSK) : |
| 4001 | (wpa_auth |= WPA_AUTH_PSK); |
| 4002 | break; |
Hante Meuleman | 240d61a | 2016-02-17 11:27:10 +0100 | [diff] [blame] | 4003 | case RSN_AKM_SHA256_PSK: |
| 4004 | brcmf_dbg(TRACE, "RSN_AKM_MFP_PSK\n"); |
| 4005 | wpa_auth |= WPA2_AUTH_PSK_SHA256; |
| 4006 | break; |
| 4007 | case RSN_AKM_SHA256_1X: |
| 4008 | brcmf_dbg(TRACE, "RSN_AKM_MFP_1X\n"); |
| 4009 | wpa_auth |= WPA2_AUTH_1X_SHA256; |
| 4010 | break; |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4011 | default: |
Colin Ian King | ad334bb | 2016-12-23 00:43:22 +0000 | [diff] [blame] | 4012 | brcmf_err("Invalid key mgmt info\n"); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4013 | } |
| 4014 | offset++; |
| 4015 | } |
| 4016 | |
Hante Meuleman | 240d61a | 2016-02-17 11:27:10 +0100 | [diff] [blame] | 4017 | mfp = BRCMF_MFP_NONE; |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4018 | if (is_rsn_ie) { |
| 4019 | wme_bss_disable = 1; |
| 4020 | if ((offset + RSN_CAP_LEN) <= len) { |
| 4021 | rsn_cap = data[offset] + (data[offset + 1] << 8); |
| 4022 | if (rsn_cap & RSN_CAP_PTK_REPLAY_CNTR_MASK) |
| 4023 | wme_bss_disable = 0; |
Hante Meuleman | 240d61a | 2016-02-17 11:27:10 +0100 | [diff] [blame] | 4024 | if (rsn_cap & RSN_CAP_MFPR_MASK) { |
| 4025 | brcmf_dbg(TRACE, "MFP Required\n"); |
| 4026 | mfp = BRCMF_MFP_REQUIRED; |
| 4027 | /* Firmware only supports mfp required in |
| 4028 | * combination with WPA2_AUTH_PSK_SHA256 or |
| 4029 | * WPA2_AUTH_1X_SHA256. |
| 4030 | */ |
| 4031 | if (!(wpa_auth & (WPA2_AUTH_PSK_SHA256 | |
| 4032 | WPA2_AUTH_1X_SHA256))) { |
| 4033 | err = -EINVAL; |
| 4034 | goto exit; |
| 4035 | } |
| 4036 | /* Firmware has requirement that WPA2_AUTH_PSK/ |
| 4037 | * WPA2_AUTH_UNSPECIFIED be set, if SHA256 OUI |
| 4038 | * is to be included in the rsn ie. |
| 4039 | */ |
| 4040 | if (wpa_auth & WPA2_AUTH_PSK_SHA256) |
| 4041 | wpa_auth |= WPA2_AUTH_PSK; |
| 4042 | else if (wpa_auth & WPA2_AUTH_1X_SHA256) |
| 4043 | wpa_auth |= WPA2_AUTH_UNSPECIFIED; |
| 4044 | } else if (rsn_cap & RSN_CAP_MFPC_MASK) { |
| 4045 | brcmf_dbg(TRACE, "MFP Capable\n"); |
| 4046 | mfp = BRCMF_MFP_CAPABLE; |
| 4047 | } |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4048 | } |
Hante Meuleman | 240d61a | 2016-02-17 11:27:10 +0100 | [diff] [blame] | 4049 | offset += RSN_CAP_LEN; |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4050 | /* set wme_bss_disable to sync RSN Capabilities */ |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 4051 | err = brcmf_fil_bsscfg_int_set(ifp, "wme_bss_disable", |
Hante Meuleman | 81f5dcb | 2012-10-22 10:36:14 -0700 | [diff] [blame] | 4052 | wme_bss_disable); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4053 | if (err < 0) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 4054 | brcmf_err("wme_bss_disable error %d\n", err); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4055 | goto exit; |
| 4056 | } |
Hante Meuleman | 240d61a | 2016-02-17 11:27:10 +0100 | [diff] [blame] | 4057 | |
| 4058 | /* Skip PMKID cnt as it is know to be 0 for AP. */ |
| 4059 | offset += RSN_PMKID_COUNT_LEN; |
| 4060 | |
| 4061 | /* See if there is BIP wpa suite left for MFP */ |
| 4062 | if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_MFP) && |
| 4063 | ((offset + WPA_IE_MIN_OUI_LEN) <= len)) { |
| 4064 | err = brcmf_fil_bsscfg_data_set(ifp, "bip", |
| 4065 | &data[offset], |
| 4066 | WPA_IE_MIN_OUI_LEN); |
| 4067 | if (err < 0) { |
| 4068 | brcmf_err("bip error %d\n", err); |
| 4069 | goto exit; |
| 4070 | } |
| 4071 | } |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4072 | } |
| 4073 | /* FOR WPS , set SES_OW_ENABLED */ |
| 4074 | wsec = (pval | gval | SES_OW_ENABLED); |
| 4075 | |
| 4076 | /* set auth */ |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 4077 | err = brcmf_fil_bsscfg_int_set(ifp, "auth", auth); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4078 | if (err < 0) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 4079 | brcmf_err("auth error %d\n", err); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4080 | goto exit; |
| 4081 | } |
| 4082 | /* set wsec */ |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 4083 | err = brcmf_fil_bsscfg_int_set(ifp, "wsec", wsec); |
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("wsec error %d\n", err); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4086 | goto exit; |
| 4087 | } |
Hante Meuleman | 240d61a | 2016-02-17 11:27:10 +0100 | [diff] [blame] | 4088 | /* Configure MFP, this needs to go after wsec otherwise the wsec command |
| 4089 | * will overwrite the values set by MFP |
| 4090 | */ |
| 4091 | if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_MFP)) { |
| 4092 | err = brcmf_fil_bsscfg_int_set(ifp, "mfp", mfp); |
| 4093 | if (err < 0) { |
| 4094 | brcmf_err("mfp error %d\n", err); |
| 4095 | goto exit; |
| 4096 | } |
| 4097 | } |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4098 | /* set upper-layer auth */ |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 4099 | err = brcmf_fil_bsscfg_int_set(ifp, "wpa_auth", wpa_auth); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4100 | if (err < 0) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 4101 | brcmf_err("wpa_auth error %d\n", err); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4102 | goto exit; |
| 4103 | } |
| 4104 | |
| 4105 | exit: |
| 4106 | return err; |
| 4107 | } |
| 4108 | |
| 4109 | static s32 |
Arend van Spriel | 3082b9b | 2012-11-05 16:22:12 -0800 | [diff] [blame] | 4110 | 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] | 4111 | struct parsed_vndr_ies *vndr_ies) |
| 4112 | { |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4113 | struct brcmf_vs_tlv *vndrie; |
| 4114 | struct brcmf_tlv *ie; |
| 4115 | struct parsed_vndr_ie_info *parsed_info; |
| 4116 | s32 remaining_len; |
| 4117 | |
| 4118 | remaining_len = (s32)vndr_ie_len; |
| 4119 | memset(vndr_ies, 0, sizeof(*vndr_ies)); |
| 4120 | |
| 4121 | ie = (struct brcmf_tlv *)vndr_ie_buf; |
| 4122 | while (ie) { |
| 4123 | if (ie->id != WLAN_EID_VENDOR_SPECIFIC) |
| 4124 | goto next; |
| 4125 | vndrie = (struct brcmf_vs_tlv *)ie; |
| 4126 | /* len should be bigger than OUI length + one */ |
| 4127 | 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] | 4128 | brcmf_err("invalid vndr ie. length is too small %d\n", |
| 4129 | vndrie->len); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4130 | goto next; |
| 4131 | } |
| 4132 | /* if wpa or wme ie, do not add ie */ |
| 4133 | if (!memcmp(vndrie->oui, (u8 *)WPA_OUI, TLV_OUI_LEN) && |
| 4134 | ((vndrie->oui_type == WPA_OUI_TYPE) || |
| 4135 | (vndrie->oui_type == WME_OUI_TYPE))) { |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 4136 | brcmf_dbg(TRACE, "Found WPA/WME oui. Do not add it\n"); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4137 | goto next; |
| 4138 | } |
| 4139 | |
| 4140 | parsed_info = &vndr_ies->ie_info[vndr_ies->count]; |
| 4141 | |
| 4142 | /* save vndr ie information */ |
| 4143 | parsed_info->ie_ptr = (char *)vndrie; |
| 4144 | parsed_info->ie_len = vndrie->len + TLV_HDR_LEN; |
| 4145 | memcpy(&parsed_info->vndrie, vndrie, sizeof(*vndrie)); |
| 4146 | |
| 4147 | vndr_ies->count++; |
| 4148 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 4149 | brcmf_dbg(TRACE, "** OUI %02x %02x %02x, type 0x%02x\n", |
| 4150 | parsed_info->vndrie.oui[0], |
| 4151 | parsed_info->vndrie.oui[1], |
| 4152 | parsed_info->vndrie.oui[2], |
| 4153 | parsed_info->vndrie.oui_type); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4154 | |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 4155 | if (vndr_ies->count >= VNDR_IE_PARSE_LIMIT) |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4156 | break; |
| 4157 | next: |
Hante Meuleman | b41fc3d | 2012-11-28 21:44:13 +0100 | [diff] [blame] | 4158 | remaining_len -= (ie->len + TLV_HDR_LEN); |
| 4159 | if (remaining_len <= TLV_HDR_LEN) |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4160 | ie = NULL; |
| 4161 | else |
Hante Meuleman | b41fc3d | 2012-11-28 21:44:13 +0100 | [diff] [blame] | 4162 | ie = (struct brcmf_tlv *)(((u8 *)ie) + ie->len + |
| 4163 | TLV_HDR_LEN); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4164 | } |
Peter Senna Tschudin | 12f3237 | 2014-05-31 10:14:06 -0300 | [diff] [blame] | 4165 | return 0; |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4166 | } |
| 4167 | |
| 4168 | static u32 |
| 4169 | brcmf_vndr_ie(u8 *iebuf, s32 pktflag, u8 *ie_ptr, u32 ie_len, s8 *add_del_cmd) |
| 4170 | { |
| 4171 | |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4172 | strncpy(iebuf, add_del_cmd, VNDR_IE_CMD_LEN - 1); |
| 4173 | iebuf[VNDR_IE_CMD_LEN - 1] = '\0'; |
| 4174 | |
Vaishali Thakkar | 362126c | 2015-01-16 21:36:14 +0530 | [diff] [blame] | 4175 | put_unaligned_le32(1, &iebuf[VNDR_IE_COUNT_OFFSET]); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4176 | |
Vaishali Thakkar | 362126c | 2015-01-16 21:36:14 +0530 | [diff] [blame] | 4177 | put_unaligned_le32(pktflag, &iebuf[VNDR_IE_PKTFLAG_OFFSET]); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4178 | |
| 4179 | memcpy(&iebuf[VNDR_IE_VSIE_OFFSET], ie_ptr, ie_len); |
| 4180 | |
| 4181 | return ie_len + VNDR_IE_HDR_SIZE; |
| 4182 | } |
| 4183 | |
Arend van Spriel | 1332e26 | 2012-11-05 16:22:18 -0800 | [diff] [blame] | 4184 | s32 brcmf_vif_set_mgmt_ie(struct brcmf_cfg80211_vif *vif, s32 pktflag, |
| 4185 | const u8 *vndr_ie_buf, u32 vndr_ie_len) |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4186 | { |
Arend van Spriel | 1332e26 | 2012-11-05 16:22:18 -0800 | [diff] [blame] | 4187 | struct brcmf_if *ifp; |
| 4188 | struct vif_saved_ie *saved_ie; |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4189 | s32 err = 0; |
| 4190 | u8 *iovar_ie_buf; |
| 4191 | u8 *curr_ie_buf; |
| 4192 | u8 *mgmt_ie_buf = NULL; |
Dan Carpenter | 3e4f319 | 2012-10-10 11:13:12 -0700 | [diff] [blame] | 4193 | int mgmt_ie_buf_len; |
Dan Carpenter | 81118d1 | 2012-10-10 11:13:07 -0700 | [diff] [blame] | 4194 | u32 *mgmt_ie_len; |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4195 | u32 del_add_ie_buf_len = 0; |
| 4196 | u32 total_ie_buf_len = 0; |
| 4197 | u32 parsed_ie_buf_len = 0; |
| 4198 | struct parsed_vndr_ies old_vndr_ies; |
| 4199 | struct parsed_vndr_ies new_vndr_ies; |
| 4200 | struct parsed_vndr_ie_info *vndrie_info; |
| 4201 | s32 i; |
| 4202 | u8 *ptr; |
Dan Carpenter | 3e4f319 | 2012-10-10 11:13:12 -0700 | [diff] [blame] | 4203 | int remained_buf_len; |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4204 | |
Arend van Spriel | 1332e26 | 2012-11-05 16:22:18 -0800 | [diff] [blame] | 4205 | if (!vif) |
| 4206 | return -ENODEV; |
| 4207 | ifp = vif->ifp; |
| 4208 | saved_ie = &vif->saved_ie; |
| 4209 | |
Hante Meuleman | 37a869e | 2015-10-29 20:33:17 +0100 | [diff] [blame] | 4210 | brcmf_dbg(TRACE, "bsscfgidx %d, pktflag : 0x%02X\n", ifp->bsscfgidx, |
| 4211 | pktflag); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4212 | iovar_ie_buf = kzalloc(WL_EXTRA_BUF_MAX, GFP_KERNEL); |
| 4213 | if (!iovar_ie_buf) |
| 4214 | return -ENOMEM; |
| 4215 | curr_ie_buf = iovar_ie_buf; |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 4216 | switch (pktflag) { |
| 4217 | case BRCMF_VNDR_IE_PRBREQ_FLAG: |
| 4218 | mgmt_ie_buf = saved_ie->probe_req_ie; |
| 4219 | mgmt_ie_len = &saved_ie->probe_req_ie_len; |
| 4220 | mgmt_ie_buf_len = sizeof(saved_ie->probe_req_ie); |
| 4221 | break; |
| 4222 | case BRCMF_VNDR_IE_PRBRSP_FLAG: |
| 4223 | mgmt_ie_buf = saved_ie->probe_res_ie; |
| 4224 | mgmt_ie_len = &saved_ie->probe_res_ie_len; |
| 4225 | mgmt_ie_buf_len = sizeof(saved_ie->probe_res_ie); |
| 4226 | break; |
| 4227 | case BRCMF_VNDR_IE_BEACON_FLAG: |
| 4228 | mgmt_ie_buf = saved_ie->beacon_ie; |
| 4229 | mgmt_ie_len = &saved_ie->beacon_ie_len; |
| 4230 | mgmt_ie_buf_len = sizeof(saved_ie->beacon_ie); |
| 4231 | break; |
| 4232 | case BRCMF_VNDR_IE_ASSOCREQ_FLAG: |
| 4233 | mgmt_ie_buf = saved_ie->assoc_req_ie; |
| 4234 | mgmt_ie_len = &saved_ie->assoc_req_ie_len; |
| 4235 | mgmt_ie_buf_len = sizeof(saved_ie->assoc_req_ie); |
| 4236 | break; |
| 4237 | default: |
| 4238 | err = -EPERM; |
| 4239 | brcmf_err("not suitable type\n"); |
| 4240 | goto exit; |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4241 | } |
| 4242 | |
| 4243 | if (vndr_ie_len > mgmt_ie_buf_len) { |
| 4244 | err = -ENOMEM; |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 4245 | brcmf_err("extra IE size too big\n"); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4246 | goto exit; |
| 4247 | } |
| 4248 | |
| 4249 | /* parse and save new vndr_ie in curr_ie_buff before comparing it */ |
| 4250 | if (vndr_ie_buf && vndr_ie_len && curr_ie_buf) { |
| 4251 | ptr = curr_ie_buf; |
| 4252 | brcmf_parse_vndr_ies(vndr_ie_buf, vndr_ie_len, &new_vndr_ies); |
| 4253 | for (i = 0; i < new_vndr_ies.count; i++) { |
| 4254 | vndrie_info = &new_vndr_ies.ie_info[i]; |
| 4255 | memcpy(ptr + parsed_ie_buf_len, vndrie_info->ie_ptr, |
| 4256 | vndrie_info->ie_len); |
| 4257 | parsed_ie_buf_len += vndrie_info->ie_len; |
| 4258 | } |
| 4259 | } |
| 4260 | |
Hante Meuleman | b41fc3d | 2012-11-28 21:44:13 +0100 | [diff] [blame] | 4261 | if (mgmt_ie_buf && *mgmt_ie_len) { |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4262 | if (parsed_ie_buf_len && (parsed_ie_buf_len == *mgmt_ie_len) && |
| 4263 | (memcmp(mgmt_ie_buf, curr_ie_buf, |
| 4264 | parsed_ie_buf_len) == 0)) { |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 4265 | brcmf_dbg(TRACE, "Previous mgmt IE equals to current IE\n"); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4266 | goto exit; |
| 4267 | } |
| 4268 | |
| 4269 | /* parse old vndr_ie */ |
| 4270 | brcmf_parse_vndr_ies(mgmt_ie_buf, *mgmt_ie_len, &old_vndr_ies); |
| 4271 | |
| 4272 | /* make a command to delete old ie */ |
| 4273 | for (i = 0; i < old_vndr_ies.count; i++) { |
| 4274 | vndrie_info = &old_vndr_ies.ie_info[i]; |
| 4275 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 4276 | brcmf_dbg(TRACE, "DEL ID : %d, Len: %d , OUI:%02x:%02x:%02x\n", |
| 4277 | vndrie_info->vndrie.id, |
| 4278 | vndrie_info->vndrie.len, |
| 4279 | vndrie_info->vndrie.oui[0], |
| 4280 | vndrie_info->vndrie.oui[1], |
| 4281 | vndrie_info->vndrie.oui[2]); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4282 | |
| 4283 | del_add_ie_buf_len = brcmf_vndr_ie(curr_ie_buf, pktflag, |
| 4284 | vndrie_info->ie_ptr, |
| 4285 | vndrie_info->ie_len, |
| 4286 | "del"); |
| 4287 | curr_ie_buf += del_add_ie_buf_len; |
| 4288 | total_ie_buf_len += del_add_ie_buf_len; |
| 4289 | } |
| 4290 | } |
| 4291 | |
| 4292 | *mgmt_ie_len = 0; |
| 4293 | /* Add if there is any extra IE */ |
| 4294 | if (mgmt_ie_buf && parsed_ie_buf_len) { |
| 4295 | ptr = mgmt_ie_buf; |
| 4296 | |
| 4297 | remained_buf_len = mgmt_ie_buf_len; |
| 4298 | |
| 4299 | /* make a command to add new ie */ |
| 4300 | for (i = 0; i < new_vndr_ies.count; i++) { |
| 4301 | vndrie_info = &new_vndr_ies.ie_info[i]; |
| 4302 | |
Hante Meuleman | b41fc3d | 2012-11-28 21:44:13 +0100 | [diff] [blame] | 4303 | /* verify remained buf size before copy data */ |
| 4304 | if (remained_buf_len < (vndrie_info->vndrie.len + |
| 4305 | VNDR_IE_VSIE_OFFSET)) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 4306 | brcmf_err("no space in mgmt_ie_buf: len left %d", |
| 4307 | remained_buf_len); |
Hante Meuleman | b41fc3d | 2012-11-28 21:44:13 +0100 | [diff] [blame] | 4308 | break; |
| 4309 | } |
| 4310 | remained_buf_len -= (vndrie_info->ie_len + |
| 4311 | VNDR_IE_VSIE_OFFSET); |
| 4312 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 4313 | brcmf_dbg(TRACE, "ADDED ID : %d, Len: %d, OUI:%02x:%02x:%02x\n", |
| 4314 | vndrie_info->vndrie.id, |
| 4315 | vndrie_info->vndrie.len, |
| 4316 | vndrie_info->vndrie.oui[0], |
| 4317 | vndrie_info->vndrie.oui[1], |
| 4318 | vndrie_info->vndrie.oui[2]); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4319 | |
| 4320 | del_add_ie_buf_len = brcmf_vndr_ie(curr_ie_buf, pktflag, |
| 4321 | vndrie_info->ie_ptr, |
| 4322 | vndrie_info->ie_len, |
| 4323 | "add"); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4324 | |
| 4325 | /* save the parsed IE in wl struct */ |
| 4326 | memcpy(ptr + (*mgmt_ie_len), vndrie_info->ie_ptr, |
| 4327 | vndrie_info->ie_len); |
| 4328 | *mgmt_ie_len += vndrie_info->ie_len; |
| 4329 | |
| 4330 | curr_ie_buf += del_add_ie_buf_len; |
| 4331 | total_ie_buf_len += del_add_ie_buf_len; |
| 4332 | } |
| 4333 | } |
| 4334 | if (total_ie_buf_len) { |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 4335 | err = brcmf_fil_bsscfg_data_set(ifp, "vndr_ie", iovar_ie_buf, |
Hante Meuleman | 81f5dcb | 2012-10-22 10:36:14 -0700 | [diff] [blame] | 4336 | total_ie_buf_len); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4337 | if (err) |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 4338 | brcmf_err("vndr ie set error : %d\n", err); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4339 | } |
| 4340 | |
| 4341 | exit: |
| 4342 | kfree(iovar_ie_buf); |
| 4343 | return err; |
| 4344 | } |
| 4345 | |
Arend van Spriel | 5f4f9f1 | 2013-02-08 15:53:41 +0100 | [diff] [blame] | 4346 | s32 brcmf_vif_clear_mgmt_ies(struct brcmf_cfg80211_vif *vif) |
| 4347 | { |
| 4348 | s32 pktflags[] = { |
| 4349 | BRCMF_VNDR_IE_PRBREQ_FLAG, |
| 4350 | BRCMF_VNDR_IE_PRBRSP_FLAG, |
| 4351 | BRCMF_VNDR_IE_BEACON_FLAG |
| 4352 | }; |
| 4353 | int i; |
| 4354 | |
| 4355 | for (i = 0; i < ARRAY_SIZE(pktflags); i++) |
| 4356 | brcmf_vif_set_mgmt_ie(vif, pktflags[i], NULL, 0); |
| 4357 | |
| 4358 | memset(&vif->saved_ie, 0, sizeof(vif->saved_ie)); |
| 4359 | return 0; |
| 4360 | } |
| 4361 | |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4362 | static s32 |
Hante Meuleman | a0f0795 | 2013-02-08 15:53:47 +0100 | [diff] [blame] | 4363 | brcmf_config_ap_mgmt_ie(struct brcmf_cfg80211_vif *vif, |
| 4364 | struct cfg80211_beacon_data *beacon) |
| 4365 | { |
| 4366 | s32 err; |
| 4367 | |
| 4368 | /* Set Beacon IEs to FW */ |
| 4369 | err = brcmf_vif_set_mgmt_ie(vif, BRCMF_VNDR_IE_BEACON_FLAG, |
| 4370 | beacon->tail, beacon->tail_len); |
| 4371 | if (err) { |
| 4372 | brcmf_err("Set Beacon IE Failed\n"); |
| 4373 | return err; |
| 4374 | } |
| 4375 | brcmf_dbg(TRACE, "Applied Vndr IEs for Beacon\n"); |
| 4376 | |
| 4377 | /* Set Probe Response IEs to FW */ |
| 4378 | err = brcmf_vif_set_mgmt_ie(vif, BRCMF_VNDR_IE_PRBRSP_FLAG, |
| 4379 | beacon->proberesp_ies, |
| 4380 | beacon->proberesp_ies_len); |
| 4381 | if (err) |
| 4382 | brcmf_err("Set Probe Resp IE Failed\n"); |
| 4383 | else |
| 4384 | brcmf_dbg(TRACE, "Applied Vndr IEs for Probe Resp\n"); |
| 4385 | |
| 4386 | return err; |
| 4387 | } |
| 4388 | |
| 4389 | static s32 |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4390 | brcmf_cfg80211_start_ap(struct wiphy *wiphy, struct net_device *ndev, |
| 4391 | struct cfg80211_ap_settings *settings) |
| 4392 | { |
| 4393 | s32 ie_offset; |
Hante Meuleman | 1c9d30c | 2013-05-27 21:09:58 +0200 | [diff] [blame] | 4394 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 4395 | struct brcmf_if *ifp = netdev_priv(ndev); |
Johannes Berg | 4b5800f | 2014-01-15 14:55:59 +0100 | [diff] [blame] | 4396 | const struct brcmf_tlv *ssid_ie; |
Arend van Spriel | 9802776 | 2014-12-21 12:43:53 +0100 | [diff] [blame] | 4397 | const struct brcmf_tlv *country_ie; |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4398 | struct brcmf_ssid_le ssid_le; |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4399 | s32 err = -EPERM; |
Johannes Berg | 4b5800f | 2014-01-15 14:55:59 +0100 | [diff] [blame] | 4400 | const struct brcmf_tlv *rsn_ie; |
| 4401 | const struct brcmf_vs_tlv *wpa_ie; |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4402 | struct brcmf_join_params join_params; |
Hante Meuleman | a0f0795 | 2013-02-08 15:53:47 +0100 | [diff] [blame] | 4403 | enum nl80211_iftype dev_role; |
| 4404 | struct brcmf_fil_bss_enable_le bss_enable; |
Rafał Miłecki | 8707e08 | 2016-05-27 21:07:19 +0200 | [diff] [blame] | 4405 | u16 chanspec = chandef_to_chanspec(&cfg->d11inf, &settings->chandef); |
Hante Meuleman | a44aa40 | 2014-12-03 21:05:33 +0100 | [diff] [blame] | 4406 | bool mbss; |
Arend van Spriel | 9802776 | 2014-12-21 12:43:53 +0100 | [diff] [blame] | 4407 | int is_11d; |
Hante Meuleman | b3589df | 2016-09-19 12:09:51 +0100 | [diff] [blame] | 4408 | bool supports_11d; |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4409 | |
Arend van Spriel | 06c0158 | 2014-05-12 10:47:37 +0200 | [diff] [blame] | 4410 | brcmf_dbg(TRACE, "ctrlchn=%d, center=%d, bw=%d, beacon_interval=%d, dtim_period=%d,\n", |
| 4411 | settings->chandef.chan->hw_value, |
| 4412 | settings->chandef.center_freq1, settings->chandef.width, |
Arend van Spriel | a9a5687 | 2014-05-12 10:47:33 +0200 | [diff] [blame] | 4413 | settings->beacon_interval, settings->dtim_period); |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 4414 | brcmf_dbg(TRACE, "ssid=%s(%zu), auth_type=%d, inactivity_timeout=%d\n", |
| 4415 | settings->ssid, settings->ssid_len, settings->auth_type, |
| 4416 | settings->inactivity_timeout); |
Hante Meuleman | 426d0a5 | 2013-02-08 15:53:53 +0100 | [diff] [blame] | 4417 | dev_role = ifp->vif->wdev.iftype; |
Hante Meuleman | a44aa40 | 2014-12-03 21:05:33 +0100 | [diff] [blame] | 4418 | mbss = ifp->vif->mbss; |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4419 | |
Arend van Spriel | 9802776 | 2014-12-21 12:43:53 +0100 | [diff] [blame] | 4420 | /* store current 11d setting */ |
Hante Meuleman | b3589df | 2016-09-19 12:09:51 +0100 | [diff] [blame] | 4421 | if (brcmf_fil_cmd_int_get(ifp, BRCMF_C_GET_REGULATORY, |
| 4422 | &ifp->vif->is_11d)) { |
Arnd Bergmann | d3532ea | 2016-10-18 00:13:40 +0200 | [diff] [blame] | 4423 | is_11d = supports_11d = false; |
Hante Meuleman | b3589df | 2016-09-19 12:09:51 +0100 | [diff] [blame] | 4424 | } else { |
| 4425 | country_ie = brcmf_parse_tlvs((u8 *)settings->beacon.tail, |
| 4426 | settings->beacon.tail_len, |
| 4427 | WLAN_EID_COUNTRY); |
| 4428 | is_11d = country_ie ? 1 : 0; |
| 4429 | supports_11d = true; |
| 4430 | } |
Arend van Spriel | 9802776 | 2014-12-21 12:43:53 +0100 | [diff] [blame] | 4431 | |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4432 | memset(&ssid_le, 0, sizeof(ssid_le)); |
| 4433 | if (settings->ssid == NULL || settings->ssid_len == 0) { |
| 4434 | ie_offset = DOT11_MGMT_HDR_LEN + DOT11_BCN_PRB_FIXED_LEN; |
| 4435 | ssid_ie = brcmf_parse_tlvs( |
| 4436 | (u8 *)&settings->beacon.head[ie_offset], |
| 4437 | settings->beacon.head_len - ie_offset, |
| 4438 | WLAN_EID_SSID); |
Arend Van Spriel | ded8991 | 2016-09-05 10:45:47 +0100 | [diff] [blame] | 4439 | if (!ssid_ie || ssid_ie->len > IEEE80211_MAX_SSID_LEN) |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4440 | return -EINVAL; |
| 4441 | |
| 4442 | memcpy(ssid_le.SSID, ssid_ie->data, ssid_ie->len); |
| 4443 | ssid_le.SSID_len = cpu_to_le32(ssid_ie->len); |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 4444 | brcmf_dbg(TRACE, "SSID is (%s) in Head\n", ssid_le.SSID); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4445 | } else { |
| 4446 | memcpy(ssid_le.SSID, settings->ssid, settings->ssid_len); |
| 4447 | ssid_le.SSID_len = cpu_to_le32((u32)settings->ssid_len); |
| 4448 | } |
| 4449 | |
Hante Meuleman | a44aa40 | 2014-12-03 21:05:33 +0100 | [diff] [blame] | 4450 | if (!mbss) { |
| 4451 | brcmf_set_mpc(ifp, 0); |
Franky Lin | 52f22fb | 2016-02-17 11:26:55 +0100 | [diff] [blame] | 4452 | brcmf_configure_arp_nd_offload(ifp, false); |
Hante Meuleman | a44aa40 | 2014-12-03 21:05:33 +0100 | [diff] [blame] | 4453 | } |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4454 | |
| 4455 | /* find the RSN_IE */ |
| 4456 | rsn_ie = brcmf_parse_tlvs((u8 *)settings->beacon.tail, |
| 4457 | settings->beacon.tail_len, WLAN_EID_RSN); |
| 4458 | |
| 4459 | /* find the WPA_IE */ |
| 4460 | wpa_ie = brcmf_find_wpaie((u8 *)settings->beacon.tail, |
| 4461 | settings->beacon.tail_len); |
| 4462 | |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4463 | if ((wpa_ie != NULL || rsn_ie != NULL)) { |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 4464 | brcmf_dbg(TRACE, "WPA(2) IE is found\n"); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4465 | if (wpa_ie != NULL) { |
| 4466 | /* WPA IE */ |
Hante Meuleman | a44aa40 | 2014-12-03 21:05:33 +0100 | [diff] [blame] | 4467 | err = brcmf_configure_wpaie(ifp, wpa_ie, false); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4468 | if (err < 0) |
| 4469 | goto exit; |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4470 | } else { |
Hante Meuleman | a44aa40 | 2014-12-03 21:05:33 +0100 | [diff] [blame] | 4471 | struct brcmf_vs_tlv *tmp_ie; |
| 4472 | |
| 4473 | tmp_ie = (struct brcmf_vs_tlv *)rsn_ie; |
| 4474 | |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4475 | /* RSN IE */ |
Hante Meuleman | a44aa40 | 2014-12-03 21:05:33 +0100 | [diff] [blame] | 4476 | err = brcmf_configure_wpaie(ifp, tmp_ie, true); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4477 | if (err < 0) |
| 4478 | goto exit; |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4479 | } |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4480 | } else { |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 4481 | brcmf_dbg(TRACE, "No WPA(2) IEs found\n"); |
Hante Meuleman | 1f17011 | 2013-02-06 18:40:38 +0100 | [diff] [blame] | 4482 | brcmf_configure_opensecurity(ifp); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4483 | } |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4484 | |
Rafał Miłecki | 8707e08 | 2016-05-27 21:07:19 +0200 | [diff] [blame] | 4485 | /* Parameters shared by all radio interfaces */ |
Hante Meuleman | a44aa40 | 2014-12-03 21:05:33 +0100 | [diff] [blame] | 4486 | if (!mbss) { |
Hante Meuleman | b3589df | 2016-09-19 12:09:51 +0100 | [diff] [blame] | 4487 | if ((supports_11d) && (is_11d != ifp->vif->is_11d)) { |
Arend van Spriel | 9802776 | 2014-12-21 12:43:53 +0100 | [diff] [blame] | 4488 | err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_REGULATORY, |
| 4489 | is_11d); |
| 4490 | if (err < 0) { |
| 4491 | brcmf_err("Regulatory Set Error, %d\n", err); |
| 4492 | goto exit; |
| 4493 | } |
| 4494 | } |
Hante Meuleman | a44aa40 | 2014-12-03 21:05:33 +0100 | [diff] [blame] | 4495 | if (settings->beacon_interval) { |
| 4496 | err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_BCNPRD, |
| 4497 | settings->beacon_interval); |
| 4498 | if (err < 0) { |
| 4499 | brcmf_err("Beacon Interval Set Error, %d\n", |
| 4500 | err); |
| 4501 | goto exit; |
| 4502 | } |
| 4503 | } |
| 4504 | if (settings->dtim_period) { |
| 4505 | err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_DTIMPRD, |
| 4506 | settings->dtim_period); |
| 4507 | if (err < 0) { |
| 4508 | brcmf_err("DTIM Interval Set Error, %d\n", err); |
| 4509 | goto exit; |
| 4510 | } |
| 4511 | } |
| 4512 | |
Hante Meuleman | 8abffd8 | 2015-10-29 20:33:16 +0100 | [diff] [blame] | 4513 | if ((dev_role == NL80211_IFTYPE_AP) && |
| 4514 | ((ifp->ifidx == 0) || |
| 4515 | !brcmf_feat_is_enabled(ifp, BRCMF_FEAT_RSDB))) { |
Hante Meuleman | a44aa40 | 2014-12-03 21:05:33 +0100 | [diff] [blame] | 4516 | err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_DOWN, 1); |
| 4517 | if (err < 0) { |
| 4518 | brcmf_err("BRCMF_C_DOWN error %d\n", err); |
| 4519 | goto exit; |
| 4520 | } |
| 4521 | brcmf_fil_iovar_int_set(ifp, "apsta", 0); |
| 4522 | } |
| 4523 | |
| 4524 | err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_INFRA, 1); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4525 | if (err < 0) { |
Hante Meuleman | a44aa40 | 2014-12-03 21:05:33 +0100 | [diff] [blame] | 4526 | brcmf_err("SET INFRA error %d\n", err); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4527 | goto exit; |
| 4528 | } |
Hante Meuleman | b3589df | 2016-09-19 12:09:51 +0100 | [diff] [blame] | 4529 | } 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] | 4530 | /* Multiple-BSS should use same 11d configuration */ |
| 4531 | err = -EINVAL; |
| 4532 | goto exit; |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4533 | } |
Rafał Miłecki | 8707e08 | 2016-05-27 21:07:19 +0200 | [diff] [blame] | 4534 | |
| 4535 | /* Interface specific setup */ |
Hante Meuleman | a0f0795 | 2013-02-08 15:53:47 +0100 | [diff] [blame] | 4536 | if (dev_role == NL80211_IFTYPE_AP) { |
Hante Meuleman | a44aa40 | 2014-12-03 21:05:33 +0100 | [diff] [blame] | 4537 | if ((brcmf_feat_is_enabled(ifp, BRCMF_FEAT_MBSS)) && (!mbss)) |
| 4538 | brcmf_fil_iovar_int_set(ifp, "mbss", 1); |
| 4539 | |
Hante Meuleman | a0f0795 | 2013-02-08 15:53:47 +0100 | [diff] [blame] | 4540 | err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_AP, 1); |
| 4541 | if (err < 0) { |
| 4542 | brcmf_err("setting AP mode failed %d\n", err); |
| 4543 | goto exit; |
| 4544 | } |
Rafał Miłecki | 8707e08 | 2016-05-27 21:07:19 +0200 | [diff] [blame] | 4545 | if (!mbss) { |
| 4546 | /* Firmware 10.x requires setting channel after enabling |
| 4547 | * AP and before bringing interface up. |
| 4548 | */ |
| 4549 | err = brcmf_fil_iovar_int_set(ifp, "chanspec", chanspec); |
| 4550 | if (err < 0) { |
| 4551 | brcmf_err("Set Channel failed: chspec=%d, %d\n", |
| 4552 | chanspec, err); |
| 4553 | goto exit; |
| 4554 | } |
| 4555 | } |
Hante Meuleman | a0f0795 | 2013-02-08 15:53:47 +0100 | [diff] [blame] | 4556 | err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_UP, 1); |
| 4557 | if (err < 0) { |
| 4558 | brcmf_err("BRCMF_C_UP error (%d)\n", err); |
| 4559 | goto exit; |
| 4560 | } |
Hante Meuleman | 118eb30 | 2014-12-21 12:43:49 +0100 | [diff] [blame] | 4561 | /* On DOWN the firmware removes the WEP keys, reconfigure |
| 4562 | * them if they were set. |
| 4563 | */ |
| 4564 | brcmf_cfg80211_reconfigure_wep(ifp); |
Hante Meuleman | a0f0795 | 2013-02-08 15:53:47 +0100 | [diff] [blame] | 4565 | |
| 4566 | memset(&join_params, 0, sizeof(join_params)); |
| 4567 | /* join parameters starts with ssid */ |
| 4568 | memcpy(&join_params.ssid_le, &ssid_le, sizeof(ssid_le)); |
| 4569 | /* create softap */ |
| 4570 | err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SET_SSID, |
| 4571 | &join_params, sizeof(join_params)); |
| 4572 | if (err < 0) { |
| 4573 | brcmf_err("SET SSID error (%d)\n", err); |
| 4574 | goto exit; |
| 4575 | } |
Rafał Miłecki | c940de1 | 2016-07-06 12:22:54 +0200 | [diff] [blame] | 4576 | |
| 4577 | if (settings->hidden_ssid) { |
| 4578 | err = brcmf_fil_iovar_int_set(ifp, "closednet", 1); |
| 4579 | if (err) { |
| 4580 | brcmf_err("closednet error (%d)\n", err); |
| 4581 | goto exit; |
| 4582 | } |
| 4583 | } |
| 4584 | |
Hante Meuleman | a0f0795 | 2013-02-08 15:53:47 +0100 | [diff] [blame] | 4585 | brcmf_dbg(TRACE, "AP mode configuration complete\n"); |
Rafał Miłecki | 8707e08 | 2016-05-27 21:07:19 +0200 | [diff] [blame] | 4586 | } else if (dev_role == NL80211_IFTYPE_P2P_GO) { |
| 4587 | err = brcmf_fil_iovar_int_set(ifp, "chanspec", chanspec); |
| 4588 | if (err < 0) { |
| 4589 | brcmf_err("Set Channel failed: chspec=%d, %d\n", |
| 4590 | chanspec, err); |
| 4591 | goto exit; |
| 4592 | } |
Hante Meuleman | a0f0795 | 2013-02-08 15:53:47 +0100 | [diff] [blame] | 4593 | err = brcmf_fil_bsscfg_data_set(ifp, "ssid", &ssid_le, |
| 4594 | sizeof(ssid_le)); |
| 4595 | if (err < 0) { |
| 4596 | brcmf_err("setting ssid failed %d\n", err); |
| 4597 | goto exit; |
| 4598 | } |
Hante Meuleman | 37a869e | 2015-10-29 20:33:17 +0100 | [diff] [blame] | 4599 | bss_enable.bsscfgidx = cpu_to_le32(ifp->bsscfgidx); |
Hante Meuleman | a0f0795 | 2013-02-08 15:53:47 +0100 | [diff] [blame] | 4600 | bss_enable.enable = cpu_to_le32(1); |
| 4601 | err = brcmf_fil_iovar_data_set(ifp, "bss", &bss_enable, |
| 4602 | sizeof(bss_enable)); |
| 4603 | if (err < 0) { |
| 4604 | brcmf_err("bss_enable config failed %d\n", err); |
| 4605 | goto exit; |
| 4606 | } |
| 4607 | |
| 4608 | brcmf_dbg(TRACE, "GO mode configuration complete\n"); |
Rafał Miłecki | 8707e08 | 2016-05-27 21:07:19 +0200 | [diff] [blame] | 4609 | } else { |
| 4610 | WARN_ON(1); |
Hante Meuleman | a0f0795 | 2013-02-08 15:53:47 +0100 | [diff] [blame] | 4611 | } |
Rafał Miłecki | 8707e08 | 2016-05-27 21:07:19 +0200 | [diff] [blame] | 4612 | |
Wright Feng | f25ba69 | 2016-11-18 09:59:52 +0800 | [diff] [blame] | 4613 | brcmf_config_ap_mgmt_ie(ifp->vif, &settings->beacon); |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 4614 | set_bit(BRCMF_VIF_STATUS_AP_CREATED, &ifp->vif->sme_state); |
Hante Meuleman | 92121e6 | 2015-10-08 20:33:21 +0200 | [diff] [blame] | 4615 | brcmf_net_setcarrier(ifp, true); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4616 | |
| 4617 | exit: |
Hante Meuleman | a44aa40 | 2014-12-03 21:05:33 +0100 | [diff] [blame] | 4618 | if ((err) && (!mbss)) { |
Arend van Spriel | f96aa07 | 2013-04-05 10:57:48 +0200 | [diff] [blame] | 4619 | brcmf_set_mpc(ifp, 1); |
Franky Lin | 52f22fb | 2016-02-17 11:26:55 +0100 | [diff] [blame] | 4620 | brcmf_configure_arp_nd_offload(ifp, true); |
Hante Meuleman | b365745 | 2013-05-27 21:09:53 +0200 | [diff] [blame] | 4621 | } |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4622 | return err; |
| 4623 | } |
| 4624 | |
| 4625 | static int brcmf_cfg80211_stop_ap(struct wiphy *wiphy, struct net_device *ndev) |
| 4626 | { |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 4627 | struct brcmf_if *ifp = netdev_priv(ndev); |
Hante Meuleman | 5c33a94 | 2013-04-02 21:06:18 +0200 | [diff] [blame] | 4628 | s32 err; |
Hante Meuleman | 426d0a5 | 2013-02-08 15:53:53 +0100 | [diff] [blame] | 4629 | struct brcmf_fil_bss_enable_le bss_enable; |
Hante Meuleman | 5c33a94 | 2013-04-02 21:06:18 +0200 | [diff] [blame] | 4630 | struct brcmf_join_params join_params; |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4631 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 4632 | brcmf_dbg(TRACE, "Enter\n"); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4633 | |
Hante Meuleman | 426d0a5 | 2013-02-08 15:53:53 +0100 | [diff] [blame] | 4634 | if (ifp->vif->wdev.iftype == NL80211_IFTYPE_AP) { |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4635 | /* Due to most likely deauths outstanding we sleep */ |
| 4636 | /* first to make sure they get processed by fw. */ |
| 4637 | msleep(400); |
Hante Meuleman | 5c33a94 | 2013-04-02 21:06:18 +0200 | [diff] [blame] | 4638 | |
Hante Meuleman | a44aa40 | 2014-12-03 21:05:33 +0100 | [diff] [blame] | 4639 | if (ifp->vif->mbss) { |
| 4640 | err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_DOWN, 1); |
| 4641 | return err; |
| 4642 | } |
| 4643 | |
Rafał Miłecki | c940de1 | 2016-07-06 12:22:54 +0200 | [diff] [blame] | 4644 | /* First BSS doesn't get a full reset */ |
| 4645 | if (ifp->bsscfgidx == 0) |
| 4646 | brcmf_fil_iovar_int_set(ifp, "closednet", 0); |
| 4647 | |
Hante Meuleman | 5c33a94 | 2013-04-02 21:06:18 +0200 | [diff] [blame] | 4648 | memset(&join_params, 0, sizeof(join_params)); |
| 4649 | err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SET_SSID, |
| 4650 | &join_params, sizeof(join_params)); |
| 4651 | if (err < 0) |
| 4652 | brcmf_err("SET SSID error (%d)\n", err); |
Hante Meuleman | a44aa40 | 2014-12-03 21:05:33 +0100 | [diff] [blame] | 4653 | err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_DOWN, 1); |
Hante Meuleman | 5c33a94 | 2013-04-02 21:06:18 +0200 | [diff] [blame] | 4654 | if (err < 0) |
Hante Meuleman | a44aa40 | 2014-12-03 21:05:33 +0100 | [diff] [blame] | 4655 | brcmf_err("BRCMF_C_DOWN error %d\n", err); |
Hante Meuleman | 5c33a94 | 2013-04-02 21:06:18 +0200 | [diff] [blame] | 4656 | err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_AP, 0); |
| 4657 | if (err < 0) |
| 4658 | brcmf_err("setting AP mode failed %d\n", err); |
| 4659 | err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_INFRA, 0); |
| 4660 | if (err < 0) |
| 4661 | brcmf_err("setting INFRA mode failed %d\n", err); |
Hante Meuleman | a44aa40 | 2014-12-03 21:05:33 +0100 | [diff] [blame] | 4662 | if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_MBSS)) |
| 4663 | brcmf_fil_iovar_int_set(ifp, "mbss", 0); |
Hante Meuleman | b3589df | 2016-09-19 12:09:51 +0100 | [diff] [blame] | 4664 | brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_REGULATORY, |
| 4665 | ifp->vif->is_11d); |
Hante Meuleman | a44aa40 | 2014-12-03 21:05:33 +0100 | [diff] [blame] | 4666 | /* Bring device back up so it can be used again */ |
| 4667 | err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_UP, 1); |
| 4668 | if (err < 0) |
| 4669 | brcmf_err("BRCMF_C_UP error %d\n", err); |
Wright Feng | f25ba69 | 2016-11-18 09:59:52 +0800 | [diff] [blame] | 4670 | |
| 4671 | brcmf_vif_clear_mgmt_ies(ifp->vif); |
Hante Meuleman | 426d0a5 | 2013-02-08 15:53:53 +0100 | [diff] [blame] | 4672 | } else { |
Hante Meuleman | 37a869e | 2015-10-29 20:33:17 +0100 | [diff] [blame] | 4673 | bss_enable.bsscfgidx = cpu_to_le32(ifp->bsscfgidx); |
Hante Meuleman | 426d0a5 | 2013-02-08 15:53:53 +0100 | [diff] [blame] | 4674 | bss_enable.enable = cpu_to_le32(0); |
| 4675 | err = brcmf_fil_iovar_data_set(ifp, "bss", &bss_enable, |
| 4676 | sizeof(bss_enable)); |
| 4677 | if (err < 0) |
| 4678 | brcmf_err("bss_enable config failed %d\n", err); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4679 | } |
Arend van Spriel | f96aa07 | 2013-04-05 10:57:48 +0200 | [diff] [blame] | 4680 | brcmf_set_mpc(ifp, 1); |
Franky Lin | 52f22fb | 2016-02-17 11:26:55 +0100 | [diff] [blame] | 4681 | brcmf_configure_arp_nd_offload(ifp, true); |
Hante Meuleman | 426d0a5 | 2013-02-08 15:53:53 +0100 | [diff] [blame] | 4682 | clear_bit(BRCMF_VIF_STATUS_AP_CREATED, &ifp->vif->sme_state); |
Hante Meuleman | 92121e6 | 2015-10-08 20:33:21 +0200 | [diff] [blame] | 4683 | brcmf_net_setcarrier(ifp, false); |
Hante Meuleman | 426d0a5 | 2013-02-08 15:53:53 +0100 | [diff] [blame] | 4684 | |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4685 | return err; |
| 4686 | } |
| 4687 | |
Hante Meuleman | a0f0795 | 2013-02-08 15:53:47 +0100 | [diff] [blame] | 4688 | static s32 |
| 4689 | brcmf_cfg80211_change_beacon(struct wiphy *wiphy, struct net_device *ndev, |
| 4690 | struct cfg80211_beacon_data *info) |
| 4691 | { |
Hante Meuleman | a0f0795 | 2013-02-08 15:53:47 +0100 | [diff] [blame] | 4692 | struct brcmf_if *ifp = netdev_priv(ndev); |
| 4693 | s32 err; |
| 4694 | |
| 4695 | brcmf_dbg(TRACE, "Enter\n"); |
| 4696 | |
Hante Meuleman | a0f0795 | 2013-02-08 15:53:47 +0100 | [diff] [blame] | 4697 | err = brcmf_config_ap_mgmt_ie(ifp->vif, info); |
| 4698 | |
| 4699 | return err; |
| 4700 | } |
| 4701 | |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4702 | static int |
| 4703 | brcmf_cfg80211_del_station(struct wiphy *wiphy, struct net_device *ndev, |
Jouni Malinen | 89c771e | 2014-10-10 20:52:40 +0300 | [diff] [blame] | 4704 | struct station_del_parameters *params) |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4705 | { |
Hante Meuleman | a0f0795 | 2013-02-08 15:53:47 +0100 | [diff] [blame] | 4706 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4707 | struct brcmf_scb_val_le scbval; |
Arend van Spriel | 0abb5f21 | 2012-10-22 13:55:32 -0700 | [diff] [blame] | 4708 | struct brcmf_if *ifp = netdev_priv(ndev); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4709 | s32 err; |
| 4710 | |
Jouni Malinen | 89c771e | 2014-10-10 20:52:40 +0300 | [diff] [blame] | 4711 | if (!params->mac) |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4712 | return -EFAULT; |
| 4713 | |
Jouni Malinen | 89c771e | 2014-10-10 20:52:40 +0300 | [diff] [blame] | 4714 | brcmf_dbg(TRACE, "Enter %pM\n", params->mac); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4715 | |
Hante Meuleman | a0f0795 | 2013-02-08 15:53:47 +0100 | [diff] [blame] | 4716 | if (ifp->vif == cfg->p2p.bss_idx[P2PAPI_BSSCFG_DEVICE].vif) |
| 4717 | ifp = cfg->p2p.bss_idx[P2PAPI_BSSCFG_PRIMARY].vif->ifp; |
Arend van Spriel | ce81e31 | 2012-10-22 13:55:37 -0700 | [diff] [blame] | 4718 | if (!check_vif_up(ifp->vif)) |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4719 | return -EIO; |
| 4720 | |
Jouni Malinen | 89c771e | 2014-10-10 20:52:40 +0300 | [diff] [blame] | 4721 | memcpy(&scbval.ea, params->mac, ETH_ALEN); |
Rafał Miłecki | ba8b6ae | 2015-02-08 11:51:47 +0100 | [diff] [blame] | 4722 | scbval.val = cpu_to_le32(params->reason_code); |
Arend van Spriel | 0abb5f21 | 2012-10-22 13:55:32 -0700 | [diff] [blame] | 4723 | 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] | 4724 | &scbval, sizeof(scbval)); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4725 | if (err) |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 4726 | brcmf_err("SCB_DEAUTHENTICATE_FOR_REASON failed %d\n", err); |
Hante Meuleman | 7ab6acd | 2013-02-08 15:53:58 +0100 | [diff] [blame] | 4727 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 4728 | brcmf_dbg(TRACE, "Exit\n"); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4729 | return err; |
| 4730 | } |
| 4731 | |
Hante Meuleman | 6b89dcb | 2014-12-21 12:43:52 +0100 | [diff] [blame] | 4732 | static int |
| 4733 | brcmf_cfg80211_change_station(struct wiphy *wiphy, struct net_device *ndev, |
| 4734 | const u8 *mac, struct station_parameters *params) |
| 4735 | { |
| 4736 | struct brcmf_if *ifp = netdev_priv(ndev); |
| 4737 | s32 err; |
| 4738 | |
| 4739 | brcmf_dbg(TRACE, "Enter, MAC %pM, mask 0x%04x set 0x%04x\n", mac, |
| 4740 | params->sta_flags_mask, params->sta_flags_set); |
| 4741 | |
| 4742 | /* Ignore all 00 MAC */ |
| 4743 | if (is_zero_ether_addr(mac)) |
| 4744 | return 0; |
| 4745 | |
| 4746 | if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED))) |
| 4747 | return 0; |
| 4748 | |
| 4749 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED)) |
| 4750 | err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SET_SCB_AUTHORIZE, |
| 4751 | (void *)mac, ETH_ALEN); |
| 4752 | else |
| 4753 | err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SET_SCB_DEAUTHORIZE, |
| 4754 | (void *)mac, ETH_ALEN); |
| 4755 | if (err < 0) |
| 4756 | brcmf_err("Setting SCB (de-)authorize failed, %d\n", err); |
| 4757 | |
| 4758 | return err; |
| 4759 | } |
Hante Meuleman | 0de8aac | 2013-02-08 15:53:38 +0100 | [diff] [blame] | 4760 | |
| 4761 | static void |
| 4762 | brcmf_cfg80211_mgmt_frame_register(struct wiphy *wiphy, |
| 4763 | struct wireless_dev *wdev, |
| 4764 | u16 frame_type, bool reg) |
| 4765 | { |
Arend van Spriel | 7fa2e35 | 2013-04-05 10:57:47 +0200 | [diff] [blame] | 4766 | struct brcmf_cfg80211_vif *vif; |
Hante Meuleman | 0de8aac | 2013-02-08 15:53:38 +0100 | [diff] [blame] | 4767 | u16 mgmt_type; |
| 4768 | |
| 4769 | brcmf_dbg(TRACE, "Enter, frame_type %04x, reg=%d\n", frame_type, reg); |
| 4770 | |
| 4771 | mgmt_type = (frame_type & IEEE80211_FCTL_STYPE) >> 4; |
Arend van Spriel | 7fa2e35 | 2013-04-05 10:57:47 +0200 | [diff] [blame] | 4772 | vif = container_of(wdev, struct brcmf_cfg80211_vif, wdev); |
Hante Meuleman | 0de8aac | 2013-02-08 15:53:38 +0100 | [diff] [blame] | 4773 | if (reg) |
| 4774 | vif->mgmt_rx_reg |= BIT(mgmt_type); |
| 4775 | else |
Hante Meuleman | 318a64c | 2013-02-08 15:53:45 +0100 | [diff] [blame] | 4776 | vif->mgmt_rx_reg &= ~BIT(mgmt_type); |
Hante Meuleman | 0de8aac | 2013-02-08 15:53:38 +0100 | [diff] [blame] | 4777 | } |
| 4778 | |
| 4779 | |
| 4780 | static int |
| 4781 | brcmf_cfg80211_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev, |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 4782 | struct cfg80211_mgmt_tx_params *params, u64 *cookie) |
Hante Meuleman | 0de8aac | 2013-02-08 15:53:38 +0100 | [diff] [blame] | 4783 | { |
| 4784 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 4785 | struct ieee80211_channel *chan = params->chan; |
| 4786 | const u8 *buf = params->buf; |
| 4787 | size_t len = params->len; |
Hante Meuleman | 0de8aac | 2013-02-08 15:53:38 +0100 | [diff] [blame] | 4788 | const struct ieee80211_mgmt *mgmt; |
| 4789 | struct brcmf_cfg80211_vif *vif; |
| 4790 | s32 err = 0; |
| 4791 | s32 ie_offset; |
| 4792 | s32 ie_len; |
Hante Meuleman | 18e2f61 | 2013-02-08 15:53:49 +0100 | [diff] [blame] | 4793 | struct brcmf_fil_action_frame_le *action_frame; |
| 4794 | struct brcmf_fil_af_params_le *af_params; |
| 4795 | bool ack; |
| 4796 | s32 chan_nr; |
Antonio Quartulli | c2ff8ca | 2013-06-11 14:20:01 +0200 | [diff] [blame] | 4797 | u32 freq; |
Hante Meuleman | 0de8aac | 2013-02-08 15:53:38 +0100 | [diff] [blame] | 4798 | |
| 4799 | brcmf_dbg(TRACE, "Enter\n"); |
| 4800 | |
| 4801 | *cookie = 0; |
| 4802 | |
| 4803 | mgmt = (const struct ieee80211_mgmt *)buf; |
| 4804 | |
Hante Meuleman | a0f0795 | 2013-02-08 15:53:47 +0100 | [diff] [blame] | 4805 | if (!ieee80211_is_mgmt(mgmt->frame_control)) { |
| 4806 | brcmf_err("Driver only allows MGMT packet type\n"); |
| 4807 | return -EPERM; |
Hante Meuleman | 0de8aac | 2013-02-08 15:53:38 +0100 | [diff] [blame] | 4808 | } |
Hante Meuleman | a0f0795 | 2013-02-08 15:53:47 +0100 | [diff] [blame] | 4809 | |
Antonio Quartulli | c2ff8ca | 2013-06-11 14:20:01 +0200 | [diff] [blame] | 4810 | vif = container_of(wdev, struct brcmf_cfg80211_vif, wdev); |
| 4811 | |
Hante Meuleman | a0f0795 | 2013-02-08 15:53:47 +0100 | [diff] [blame] | 4812 | if (ieee80211_is_probe_resp(mgmt->frame_control)) { |
| 4813 | /* Right now the only reason to get a probe response */ |
| 4814 | /* is for p2p listen response or for p2p GO from */ |
| 4815 | /* wpa_supplicant. Unfortunately the probe is send */ |
| 4816 | /* on primary ndev, while dongle wants it on the p2p */ |
| 4817 | /* vif. Since this is only reason for a probe */ |
| 4818 | /* response to be sent, the vif is taken from cfg. */ |
| 4819 | /* If ever desired to send proberesp for non p2p */ |
| 4820 | /* response then data should be checked for */ |
| 4821 | /* "DIRECT-". Note in future supplicant will take */ |
| 4822 | /* dedicated p2p wdev to do this and then this 'hack'*/ |
| 4823 | /* is not needed anymore. */ |
| 4824 | ie_offset = DOT11_MGMT_HDR_LEN + |
| 4825 | DOT11_BCN_PRB_FIXED_LEN; |
| 4826 | ie_len = len - ie_offset; |
Hante Meuleman | a0f0795 | 2013-02-08 15:53:47 +0100 | [diff] [blame] | 4827 | if (vif == cfg->p2p.bss_idx[P2PAPI_BSSCFG_PRIMARY].vif) |
| 4828 | vif = cfg->p2p.bss_idx[P2PAPI_BSSCFG_DEVICE].vif; |
| 4829 | err = brcmf_vif_set_mgmt_ie(vif, |
| 4830 | BRCMF_VNDR_IE_PRBRSP_FLAG, |
| 4831 | &buf[ie_offset], |
| 4832 | ie_len); |
| 4833 | cfg80211_mgmt_tx_status(wdev, *cookie, buf, len, true, |
| 4834 | GFP_KERNEL); |
Hante Meuleman | 18e2f61 | 2013-02-08 15:53:49 +0100 | [diff] [blame] | 4835 | } else if (ieee80211_is_action(mgmt->frame_control)) { |
| 4836 | af_params = kzalloc(sizeof(*af_params), GFP_KERNEL); |
| 4837 | if (af_params == NULL) { |
| 4838 | brcmf_err("unable to allocate frame\n"); |
| 4839 | err = -ENOMEM; |
| 4840 | goto exit; |
| 4841 | } |
| 4842 | action_frame = &af_params->action_frame; |
| 4843 | /* Add the packet Id */ |
| 4844 | action_frame->packet_id = cpu_to_le32(*cookie); |
| 4845 | /* Add BSSID */ |
| 4846 | memcpy(&action_frame->da[0], &mgmt->da[0], ETH_ALEN); |
| 4847 | memcpy(&af_params->bssid[0], &mgmt->bssid[0], ETH_ALEN); |
| 4848 | /* Add the length exepted for 802.11 header */ |
| 4849 | action_frame->len = cpu_to_le16(len - DOT11_MGMT_HDR_LEN); |
Antonio Quartulli | c2ff8ca | 2013-06-11 14:20:01 +0200 | [diff] [blame] | 4850 | /* Add the channel. Use the one specified as parameter if any or |
| 4851 | * the current one (got from the firmware) otherwise |
| 4852 | */ |
| 4853 | if (chan) |
| 4854 | freq = chan->center_freq; |
| 4855 | else |
| 4856 | brcmf_fil_cmd_int_get(vif->ifp, BRCMF_C_GET_CHANNEL, |
| 4857 | &freq); |
| 4858 | chan_nr = ieee80211_frequency_to_channel(freq); |
Hante Meuleman | 18e2f61 | 2013-02-08 15:53:49 +0100 | [diff] [blame] | 4859 | af_params->channel = cpu_to_le32(chan_nr); |
| 4860 | |
| 4861 | memcpy(action_frame->data, &buf[DOT11_MGMT_HDR_LEN], |
| 4862 | le16_to_cpu(action_frame->len)); |
| 4863 | |
| 4864 | brcmf_dbg(TRACE, "Action frame, cookie=%lld, len=%d, freq=%d\n", |
Antonio Quartulli | 86a9c4a | 2013-06-19 13:35:31 +0200 | [diff] [blame] | 4865 | *cookie, le16_to_cpu(action_frame->len), freq); |
Hante Meuleman | 18e2f61 | 2013-02-08 15:53:49 +0100 | [diff] [blame] | 4866 | |
Arend van Spriel | 7fa2e35 | 2013-04-05 10:57:47 +0200 | [diff] [blame] | 4867 | ack = brcmf_p2p_send_action_frame(cfg, cfg_to_ndev(cfg), |
Hante Meuleman | 18e2f61 | 2013-02-08 15:53:49 +0100 | [diff] [blame] | 4868 | af_params); |
| 4869 | |
| 4870 | cfg80211_mgmt_tx_status(wdev, *cookie, buf, len, ack, |
| 4871 | GFP_KERNEL); |
| 4872 | kfree(af_params); |
Hante Meuleman | a0f0795 | 2013-02-08 15:53:47 +0100 | [diff] [blame] | 4873 | } else { |
| 4874 | brcmf_dbg(TRACE, "Unhandled, fc=%04x!!\n", mgmt->frame_control); |
Alexey Dobriyan | 5b5e092 | 2017-02-27 14:30:02 -0800 | [diff] [blame] | 4875 | brcmf_dbg_hex_dump(true, buf, len, "payload, len=%zu\n", len); |
Hante Meuleman | a0f0795 | 2013-02-08 15:53:47 +0100 | [diff] [blame] | 4876 | } |
| 4877 | |
Hante Meuleman | 18e2f61 | 2013-02-08 15:53:49 +0100 | [diff] [blame] | 4878 | exit: |
Hante Meuleman | 0de8aac | 2013-02-08 15:53:38 +0100 | [diff] [blame] | 4879 | return err; |
| 4880 | } |
| 4881 | |
| 4882 | |
| 4883 | static int |
| 4884 | brcmf_cfg80211_cancel_remain_on_channel(struct wiphy *wiphy, |
| 4885 | struct wireless_dev *wdev, |
| 4886 | u64 cookie) |
| 4887 | { |
| 4888 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); |
| 4889 | struct brcmf_cfg80211_vif *vif; |
| 4890 | int err = 0; |
| 4891 | |
| 4892 | brcmf_dbg(TRACE, "Enter p2p listen cancel\n"); |
| 4893 | |
| 4894 | vif = cfg->p2p.bss_idx[P2PAPI_BSSCFG_DEVICE].vif; |
| 4895 | if (vif == NULL) { |
| 4896 | brcmf_err("No p2p device available for probe response\n"); |
| 4897 | err = -ENODEV; |
| 4898 | goto exit; |
| 4899 | } |
| 4900 | brcmf_p2p_cancel_remain_on_channel(vif->ifp); |
| 4901 | exit: |
| 4902 | return err; |
| 4903 | } |
| 4904 | |
Rafał Miłecki | ee6e7aa | 2016-05-20 13:38:58 +0200 | [diff] [blame] | 4905 | static int brcmf_cfg80211_get_channel(struct wiphy *wiphy, |
| 4906 | struct wireless_dev *wdev, |
| 4907 | struct cfg80211_chan_def *chandef) |
| 4908 | { |
| 4909 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); |
| 4910 | struct net_device *ndev = wdev->netdev; |
| 4911 | struct brcmf_if *ifp; |
| 4912 | struct brcmu_chan ch; |
| 4913 | enum nl80211_band band = 0; |
| 4914 | enum nl80211_chan_width width = 0; |
| 4915 | u32 chanspec; |
| 4916 | int freq, err; |
| 4917 | |
| 4918 | if (!ndev) |
| 4919 | return -ENODEV; |
| 4920 | ifp = netdev_priv(ndev); |
| 4921 | |
| 4922 | err = brcmf_fil_iovar_int_get(ifp, "chanspec", &chanspec); |
| 4923 | if (err) { |
| 4924 | brcmf_err("chanspec failed (%d)\n", err); |
| 4925 | return err; |
| 4926 | } |
| 4927 | |
| 4928 | ch.chspec = chanspec; |
| 4929 | cfg->d11inf.decchspec(&ch); |
| 4930 | |
| 4931 | switch (ch.band) { |
| 4932 | case BRCMU_CHAN_BAND_2G: |
| 4933 | band = NL80211_BAND_2GHZ; |
| 4934 | break; |
| 4935 | case BRCMU_CHAN_BAND_5G: |
| 4936 | band = NL80211_BAND_5GHZ; |
| 4937 | break; |
| 4938 | } |
| 4939 | |
| 4940 | switch (ch.bw) { |
| 4941 | case BRCMU_CHAN_BW_80: |
| 4942 | width = NL80211_CHAN_WIDTH_80; |
| 4943 | break; |
| 4944 | case BRCMU_CHAN_BW_40: |
| 4945 | width = NL80211_CHAN_WIDTH_40; |
| 4946 | break; |
| 4947 | case BRCMU_CHAN_BW_20: |
| 4948 | width = NL80211_CHAN_WIDTH_20; |
| 4949 | break; |
| 4950 | case BRCMU_CHAN_BW_80P80: |
| 4951 | width = NL80211_CHAN_WIDTH_80P80; |
| 4952 | break; |
| 4953 | case BRCMU_CHAN_BW_160: |
| 4954 | width = NL80211_CHAN_WIDTH_160; |
| 4955 | break; |
| 4956 | } |
| 4957 | |
| 4958 | freq = ieee80211_channel_to_frequency(ch.control_ch_num, band); |
| 4959 | chandef->chan = ieee80211_get_channel(wiphy, freq); |
| 4960 | chandef->width = width; |
| 4961 | chandef->center_freq1 = ieee80211_channel_to_frequency(ch.chnum, band); |
| 4962 | chandef->center_freq2 = 0; |
| 4963 | |
| 4964 | return 0; |
| 4965 | } |
| 4966 | |
Piotr Haber | 61730d4 | 2013-04-23 12:53:12 +0200 | [diff] [blame] | 4967 | static int brcmf_cfg80211_crit_proto_start(struct wiphy *wiphy, |
| 4968 | struct wireless_dev *wdev, |
| 4969 | enum nl80211_crit_proto_id proto, |
| 4970 | u16 duration) |
| 4971 | { |
| 4972 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); |
| 4973 | struct brcmf_cfg80211_vif *vif; |
| 4974 | |
| 4975 | vif = container_of(wdev, struct brcmf_cfg80211_vif, wdev); |
| 4976 | |
| 4977 | /* only DHCP support for now */ |
| 4978 | if (proto != NL80211_CRIT_PROTO_DHCP) |
| 4979 | return -EINVAL; |
| 4980 | |
| 4981 | /* suppress and abort scanning */ |
| 4982 | set_bit(BRCMF_SCAN_STATUS_SUPPRESS, &cfg->scan_status); |
| 4983 | brcmf_abort_scanning(cfg); |
| 4984 | |
| 4985 | return brcmf_btcoex_set_mode(vif, BRCMF_BTCOEX_DISABLED, duration); |
| 4986 | } |
| 4987 | |
| 4988 | static void brcmf_cfg80211_crit_proto_stop(struct wiphy *wiphy, |
| 4989 | struct wireless_dev *wdev) |
| 4990 | { |
| 4991 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); |
| 4992 | struct brcmf_cfg80211_vif *vif; |
| 4993 | |
| 4994 | vif = container_of(wdev, struct brcmf_cfg80211_vif, wdev); |
| 4995 | |
| 4996 | brcmf_btcoex_set_mode(vif, BRCMF_BTCOEX_ENABLED, 0); |
| 4997 | clear_bit(BRCMF_SCAN_STATUS_SUPPRESS, &cfg->scan_status); |
| 4998 | } |
| 4999 | |
Hante Meuleman | 70b7d94 | 2014-07-30 13:20:07 +0200 | [diff] [blame] | 5000 | static s32 |
| 5001 | brcmf_notify_tdls_peer_event(struct brcmf_if *ifp, |
| 5002 | const struct brcmf_event_msg *e, void *data) |
| 5003 | { |
| 5004 | switch (e->reason) { |
| 5005 | case BRCMF_E_REASON_TDLS_PEER_DISCOVERED: |
| 5006 | brcmf_dbg(TRACE, "TDLS Peer Discovered\n"); |
| 5007 | break; |
| 5008 | case BRCMF_E_REASON_TDLS_PEER_CONNECTED: |
| 5009 | brcmf_dbg(TRACE, "TDLS Peer Connected\n"); |
| 5010 | brcmf_proto_add_tdls_peer(ifp->drvr, ifp->ifidx, (u8 *)e->addr); |
| 5011 | break; |
| 5012 | case BRCMF_E_REASON_TDLS_PEER_DISCONNECTED: |
| 5013 | brcmf_dbg(TRACE, "TDLS Peer Disconnected\n"); |
| 5014 | brcmf_proto_delete_peer(ifp->drvr, ifp->ifidx, (u8 *)e->addr); |
| 5015 | break; |
| 5016 | } |
| 5017 | |
| 5018 | return 0; |
| 5019 | } |
| 5020 | |
Arend van Spriel | 89c2f38 | 2013-08-10 12:27:25 +0200 | [diff] [blame] | 5021 | static int brcmf_convert_nl80211_tdls_oper(enum nl80211_tdls_operation oper) |
| 5022 | { |
| 5023 | int ret; |
| 5024 | |
| 5025 | switch (oper) { |
| 5026 | case NL80211_TDLS_DISCOVERY_REQ: |
| 5027 | ret = BRCMF_TDLS_MANUAL_EP_DISCOVERY; |
| 5028 | break; |
| 5029 | case NL80211_TDLS_SETUP: |
| 5030 | ret = BRCMF_TDLS_MANUAL_EP_CREATE; |
| 5031 | break; |
| 5032 | case NL80211_TDLS_TEARDOWN: |
| 5033 | ret = BRCMF_TDLS_MANUAL_EP_DELETE; |
| 5034 | break; |
| 5035 | default: |
| 5036 | brcmf_err("unsupported operation: %d\n", oper); |
| 5037 | ret = -EOPNOTSUPP; |
| 5038 | } |
| 5039 | return ret; |
| 5040 | } |
| 5041 | |
| 5042 | static int brcmf_cfg80211_tdls_oper(struct wiphy *wiphy, |
Johannes Berg | 3b3a016 | 2014-05-19 17:19:31 +0200 | [diff] [blame] | 5043 | struct net_device *ndev, const u8 *peer, |
Arend van Spriel | 89c2f38 | 2013-08-10 12:27:25 +0200 | [diff] [blame] | 5044 | enum nl80211_tdls_operation oper) |
| 5045 | { |
| 5046 | struct brcmf_if *ifp; |
| 5047 | struct brcmf_tdls_iovar_le info; |
| 5048 | int ret = 0; |
| 5049 | |
| 5050 | ret = brcmf_convert_nl80211_tdls_oper(oper); |
| 5051 | if (ret < 0) |
| 5052 | return ret; |
| 5053 | |
| 5054 | ifp = netdev_priv(ndev); |
| 5055 | memset(&info, 0, sizeof(info)); |
| 5056 | info.mode = (u8)ret; |
| 5057 | if (peer) |
| 5058 | memcpy(info.ea, peer, ETH_ALEN); |
| 5059 | |
| 5060 | ret = brcmf_fil_iovar_data_set(ifp, "tdls_endpoint", |
| 5061 | &info, sizeof(info)); |
| 5062 | if (ret < 0) |
| 5063 | brcmf_err("tdls_endpoint iovar failed: ret=%d\n", ret); |
| 5064 | |
| 5065 | return ret; |
| 5066 | } |
| 5067 | |
Arend Van Spriel | 2a2a5d1 | 2017-01-27 12:27:48 +0000 | [diff] [blame] | 5068 | static int |
| 5069 | brcmf_cfg80211_update_conn_params(struct wiphy *wiphy, |
| 5070 | struct net_device *ndev, |
| 5071 | struct cfg80211_connect_params *sme, |
| 5072 | u32 changed) |
| 5073 | { |
| 5074 | struct brcmf_if *ifp; |
| 5075 | int err; |
| 5076 | |
| 5077 | if (!(changed & UPDATE_ASSOC_IES)) |
| 5078 | return 0; |
| 5079 | |
| 5080 | ifp = netdev_priv(ndev); |
| 5081 | err = brcmf_vif_set_mgmt_ie(ifp->vif, BRCMF_VNDR_IE_ASSOCREQ_FLAG, |
| 5082 | sme->ie, sme->ie_len); |
| 5083 | if (err) |
| 5084 | brcmf_err("Set Assoc REQ IE Failed\n"); |
| 5085 | else |
| 5086 | brcmf_dbg(TRACE, "Applied Vndr IEs for Assoc request\n"); |
| 5087 | |
| 5088 | return err; |
| 5089 | } |
| 5090 | |
Hante Meuleman | 5c22fb8 | 2016-02-17 11:27:03 +0100 | [diff] [blame] | 5091 | #ifdef CONFIG_PM |
| 5092 | static int |
| 5093 | brcmf_cfg80211_set_rekey_data(struct wiphy *wiphy, struct net_device *ndev, |
| 5094 | struct cfg80211_gtk_rekey_data *gtk) |
| 5095 | { |
| 5096 | struct brcmf_if *ifp = netdev_priv(ndev); |
| 5097 | struct brcmf_gtk_keyinfo_le gtk_le; |
| 5098 | int ret; |
| 5099 | |
| 5100 | brcmf_dbg(TRACE, "Enter, bssidx=%d\n", ifp->bsscfgidx); |
| 5101 | |
| 5102 | memcpy(gtk_le.kck, gtk->kck, sizeof(gtk_le.kck)); |
| 5103 | memcpy(gtk_le.kek, gtk->kek, sizeof(gtk_le.kek)); |
| 5104 | memcpy(gtk_le.replay_counter, gtk->replay_ctr, |
| 5105 | sizeof(gtk_le.replay_counter)); |
| 5106 | |
| 5107 | ret = brcmf_fil_iovar_data_set(ifp, "gtk_key_info", >k_le, |
| 5108 | sizeof(gtk_le)); |
| 5109 | if (ret < 0) |
| 5110 | brcmf_err("gtk_key_info iovar failed: ret=%d\n", ret); |
| 5111 | |
| 5112 | return ret; |
| 5113 | } |
| 5114 | #endif |
| 5115 | |
| 5116 | static struct cfg80211_ops brcmf_cfg80211_ops = { |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 5117 | .add_virtual_intf = brcmf_cfg80211_add_iface, |
| 5118 | .del_virtual_intf = brcmf_cfg80211_del_iface, |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5119 | .change_virtual_intf = brcmf_cfg80211_change_iface, |
| 5120 | .scan = brcmf_cfg80211_scan, |
| 5121 | .set_wiphy_params = brcmf_cfg80211_set_wiphy_params, |
| 5122 | .join_ibss = brcmf_cfg80211_join_ibss, |
| 5123 | .leave_ibss = brcmf_cfg80211_leave_ibss, |
| 5124 | .get_station = brcmf_cfg80211_get_station, |
Hante Meuleman | bf2a7e0 | 2015-10-08 20:33:18 +0200 | [diff] [blame] | 5125 | .dump_station = brcmf_cfg80211_dump_station, |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5126 | .set_tx_power = brcmf_cfg80211_set_tx_power, |
| 5127 | .get_tx_power = brcmf_cfg80211_get_tx_power, |
| 5128 | .add_key = brcmf_cfg80211_add_key, |
| 5129 | .del_key = brcmf_cfg80211_del_key, |
| 5130 | .get_key = brcmf_cfg80211_get_key, |
| 5131 | .set_default_key = brcmf_cfg80211_config_default_key, |
| 5132 | .set_default_mgmt_key = brcmf_cfg80211_config_default_mgmt_key, |
| 5133 | .set_power_mgmt = brcmf_cfg80211_set_power_mgmt, |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5134 | .connect = brcmf_cfg80211_connect, |
| 5135 | .disconnect = brcmf_cfg80211_disconnect, |
| 5136 | .suspend = brcmf_cfg80211_suspend, |
| 5137 | .resume = brcmf_cfg80211_resume, |
| 5138 | .set_pmksa = brcmf_cfg80211_set_pmksa, |
| 5139 | .del_pmksa = brcmf_cfg80211_del_pmksa, |
Arend van Spriel | cbaa177 | 2012-08-30 19:43:02 +0200 | [diff] [blame] | 5140 | .flush_pmksa = brcmf_cfg80211_flush_pmksa, |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 5141 | .start_ap = brcmf_cfg80211_start_ap, |
| 5142 | .stop_ap = brcmf_cfg80211_stop_ap, |
Hante Meuleman | a0f0795 | 2013-02-08 15:53:47 +0100 | [diff] [blame] | 5143 | .change_beacon = brcmf_cfg80211_change_beacon, |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 5144 | .del_station = brcmf_cfg80211_del_station, |
Hante Meuleman | 6b89dcb | 2014-12-21 12:43:52 +0100 | [diff] [blame] | 5145 | .change_station = brcmf_cfg80211_change_station, |
Arend van Spriel | e580607 | 2012-09-19 22:21:08 +0200 | [diff] [blame] | 5146 | .sched_scan_start = brcmf_cfg80211_sched_scan_start, |
| 5147 | .sched_scan_stop = brcmf_cfg80211_sched_scan_stop, |
Hante Meuleman | 0de8aac | 2013-02-08 15:53:38 +0100 | [diff] [blame] | 5148 | .mgmt_frame_register = brcmf_cfg80211_mgmt_frame_register, |
| 5149 | .mgmt_tx = brcmf_cfg80211_mgmt_tx, |
| 5150 | .remain_on_channel = brcmf_p2p_remain_on_channel, |
| 5151 | .cancel_remain_on_channel = brcmf_cfg80211_cancel_remain_on_channel, |
Rafał Miłecki | ee6e7aa | 2016-05-20 13:38:58 +0200 | [diff] [blame] | 5152 | .get_channel = brcmf_cfg80211_get_channel, |
Arend van Spriel | 27f10e3 | 2013-04-05 10:57:50 +0200 | [diff] [blame] | 5153 | .start_p2p_device = brcmf_p2p_start_device, |
| 5154 | .stop_p2p_device = brcmf_p2p_stop_device, |
Piotr Haber | 61730d4 | 2013-04-23 12:53:12 +0200 | [diff] [blame] | 5155 | .crit_proto_start = brcmf_cfg80211_crit_proto_start, |
| 5156 | .crit_proto_stop = brcmf_cfg80211_crit_proto_stop, |
Arend van Spriel | 89c2f38 | 2013-08-10 12:27:25 +0200 | [diff] [blame] | 5157 | .tdls_oper = brcmf_cfg80211_tdls_oper, |
Arend Van Spriel | 2a2a5d1 | 2017-01-27 12:27:48 +0000 | [diff] [blame] | 5158 | .update_connect_params = brcmf_cfg80211_update_conn_params, |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5159 | }; |
| 5160 | |
Arend van Spriel | 3eacf86 | 2012-10-22 13:55:30 -0700 | [diff] [blame] | 5161 | 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] | 5162 | enum nl80211_iftype type) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5163 | { |
Hante Meuleman | a44aa40 | 2014-12-03 21:05:33 +0100 | [diff] [blame] | 5164 | struct brcmf_cfg80211_vif *vif_walk; |
Arend van Spriel | 3eacf86 | 2012-10-22 13:55:30 -0700 | [diff] [blame] | 5165 | struct brcmf_cfg80211_vif *vif; |
Hante Meuleman | a44aa40 | 2014-12-03 21:05:33 +0100 | [diff] [blame] | 5166 | bool mbss; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5167 | |
Arend van Spriel | 33a6b15 | 2013-02-08 15:53:39 +0100 | [diff] [blame] | 5168 | brcmf_dbg(TRACE, "allocating virtual interface (size=%zu)\n", |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 5169 | sizeof(*vif)); |
Arend van Spriel | 3eacf86 | 2012-10-22 13:55:30 -0700 | [diff] [blame] | 5170 | vif = kzalloc(sizeof(*vif), GFP_KERNEL); |
| 5171 | if (!vif) |
| 5172 | return ERR_PTR(-ENOMEM); |
| 5173 | |
| 5174 | vif->wdev.wiphy = cfg->wiphy; |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 5175 | vif->wdev.iftype = type; |
Arend van Spriel | 3eacf86 | 2012-10-22 13:55:30 -0700 | [diff] [blame] | 5176 | |
Arend van Spriel | 6ac4f4e | 2012-10-22 13:55:31 -0700 | [diff] [blame] | 5177 | brcmf_init_prof(&vif->profile); |
| 5178 | |
Hante Meuleman | a44aa40 | 2014-12-03 21:05:33 +0100 | [diff] [blame] | 5179 | if (type == NL80211_IFTYPE_AP) { |
| 5180 | mbss = false; |
| 5181 | list_for_each_entry(vif_walk, &cfg->vif_list, list) { |
| 5182 | if (vif_walk->wdev.iftype == NL80211_IFTYPE_AP) { |
| 5183 | mbss = true; |
| 5184 | break; |
| 5185 | } |
| 5186 | } |
| 5187 | vif->mbss = mbss; |
| 5188 | } |
| 5189 | |
Arend van Spriel | 3eacf86 | 2012-10-22 13:55:30 -0700 | [diff] [blame] | 5190 | list_add_tail(&vif->list, &cfg->vif_list); |
Arend van Spriel | 3eacf86 | 2012-10-22 13:55:30 -0700 | [diff] [blame] | 5191 | return vif; |
| 5192 | } |
| 5193 | |
Arend van Spriel | 427dec5 | 2014-01-06 12:40:47 +0100 | [diff] [blame] | 5194 | void brcmf_free_vif(struct brcmf_cfg80211_vif *vif) |
Arend van Spriel | 3eacf86 | 2012-10-22 13:55:30 -0700 | [diff] [blame] | 5195 | { |
Arend van Spriel | 3eacf86 | 2012-10-22 13:55:30 -0700 | [diff] [blame] | 5196 | list_del(&vif->list); |
Arend van Spriel | 3eacf86 | 2012-10-22 13:55:30 -0700 | [diff] [blame] | 5197 | kfree(vif); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5198 | } |
| 5199 | |
Arend van Spriel | 9df4d54 | 2014-01-06 12:40:49 +0100 | [diff] [blame] | 5200 | void brcmf_cfg80211_free_netdev(struct net_device *ndev) |
| 5201 | { |
| 5202 | struct brcmf_cfg80211_vif *vif; |
| 5203 | struct brcmf_if *ifp; |
| 5204 | |
| 5205 | ifp = netdev_priv(ndev); |
| 5206 | vif = ifp->vif; |
| 5207 | |
Arend van Spriel | 95ef123 | 2015-08-26 22:15:04 +0200 | [diff] [blame] | 5208 | if (vif) |
| 5209 | brcmf_free_vif(vif); |
Arend van Spriel | 9df4d54 | 2014-01-06 12:40:49 +0100 | [diff] [blame] | 5210 | free_netdev(ndev); |
| 5211 | } |
| 5212 | |
Arend van Spriel | 903e0ee | 2012-11-28 21:44:11 +0100 | [diff] [blame] | 5213 | static bool brcmf_is_linkup(const struct brcmf_event_msg *e) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5214 | { |
Arend van Spriel | 5c36b99 | 2012-11-14 18:46:05 -0800 | [diff] [blame] | 5215 | u32 event = e->event_code; |
| 5216 | u32 status = e->status; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5217 | |
| 5218 | if (event == BRCMF_E_SET_SSID && status == BRCMF_E_STATUS_SUCCESS) { |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 5219 | brcmf_dbg(CONN, "Processing set ssid\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5220 | return true; |
| 5221 | } |
| 5222 | |
| 5223 | return false; |
| 5224 | } |
| 5225 | |
Arend van Spriel | 903e0ee | 2012-11-28 21:44:11 +0100 | [diff] [blame] | 5226 | static bool brcmf_is_linkdown(const struct brcmf_event_msg *e) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5227 | { |
Arend van Spriel | 5c36b99 | 2012-11-14 18:46:05 -0800 | [diff] [blame] | 5228 | u32 event = e->event_code; |
| 5229 | u16 flags = e->flags; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5230 | |
Hante Meuleman | 68ca395 | 2014-02-25 20:30:26 +0100 | [diff] [blame] | 5231 | if ((event == BRCMF_E_DEAUTH) || (event == BRCMF_E_DEAUTH_IND) || |
| 5232 | (event == BRCMF_E_DISASSOC_IND) || |
| 5233 | ((event == BRCMF_E_LINK) && (!(flags & BRCMF_EVENT_MSG_LINK)))) { |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 5234 | brcmf_dbg(CONN, "Processing link down\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5235 | return true; |
| 5236 | } |
| 5237 | return false; |
| 5238 | } |
| 5239 | |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5240 | static bool brcmf_is_nonetwork(struct brcmf_cfg80211_info *cfg, |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5241 | const struct brcmf_event_msg *e) |
| 5242 | { |
Arend van Spriel | 5c36b99 | 2012-11-14 18:46:05 -0800 | [diff] [blame] | 5243 | u32 event = e->event_code; |
| 5244 | u32 status = e->status; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5245 | |
| 5246 | if (event == BRCMF_E_LINK && status == BRCMF_E_STATUS_NO_NETWORKS) { |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 5247 | brcmf_dbg(CONN, "Processing Link %s & no network found\n", |
| 5248 | e->flags & BRCMF_EVENT_MSG_LINK ? "up" : "down"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5249 | return true; |
| 5250 | } |
| 5251 | |
| 5252 | if (event == BRCMF_E_SET_SSID && status != BRCMF_E_STATUS_SUCCESS) { |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 5253 | brcmf_dbg(CONN, "Processing connecting & no network found\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5254 | return true; |
| 5255 | } |
| 5256 | |
| 5257 | return false; |
| 5258 | } |
| 5259 | |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5260 | static void brcmf_clear_assoc_ies(struct brcmf_cfg80211_info *cfg) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5261 | { |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5262 | struct brcmf_cfg80211_connect_info *conn_info = cfg_to_conn(cfg); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5263 | |
| 5264 | kfree(conn_info->req_ie); |
| 5265 | conn_info->req_ie = NULL; |
| 5266 | conn_info->req_ie_len = 0; |
| 5267 | kfree(conn_info->resp_ie); |
| 5268 | conn_info->resp_ie = NULL; |
| 5269 | conn_info->resp_ie_len = 0; |
| 5270 | } |
| 5271 | |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 5272 | static s32 brcmf_get_assoc_ies(struct brcmf_cfg80211_info *cfg, |
| 5273 | struct brcmf_if *ifp) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5274 | { |
Arend van Spriel | c4e382d | 2011-10-12 20:51:21 +0200 | [diff] [blame] | 5275 | struct brcmf_cfg80211_assoc_ielen_le *assoc_info; |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5276 | struct brcmf_cfg80211_connect_info *conn_info = cfg_to_conn(cfg); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5277 | u32 req_len; |
| 5278 | u32 resp_len; |
| 5279 | s32 err = 0; |
| 5280 | |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5281 | brcmf_clear_assoc_ies(cfg); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5282 | |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 5283 | err = brcmf_fil_iovar_data_get(ifp, "assoc_info", |
| 5284 | cfg->extra_buf, WL_ASSOC_INFO_MAX); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5285 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 5286 | brcmf_err("could not get assoc info (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5287 | return err; |
| 5288 | } |
Arend van Spriel | c4e382d | 2011-10-12 20:51:21 +0200 | [diff] [blame] | 5289 | assoc_info = |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5290 | (struct brcmf_cfg80211_assoc_ielen_le *)cfg->extra_buf; |
Arend van Spriel | c4e382d | 2011-10-12 20:51:21 +0200 | [diff] [blame] | 5291 | req_len = le32_to_cpu(assoc_info->req_len); |
| 5292 | resp_len = le32_to_cpu(assoc_info->resp_len); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5293 | if (req_len) { |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 5294 | err = brcmf_fil_iovar_data_get(ifp, "assoc_req_ies", |
Hante Meuleman | 81f5dcb | 2012-10-22 10:36:14 -0700 | [diff] [blame] | 5295 | cfg->extra_buf, |
| 5296 | WL_ASSOC_INFO_MAX); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5297 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 5298 | brcmf_err("could not get assoc req (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5299 | return err; |
| 5300 | } |
| 5301 | conn_info->req_ie_len = req_len; |
| 5302 | conn_info->req_ie = |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5303 | kmemdup(cfg->extra_buf, conn_info->req_ie_len, |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5304 | GFP_KERNEL); |
| 5305 | } else { |
| 5306 | conn_info->req_ie_len = 0; |
| 5307 | conn_info->req_ie = NULL; |
| 5308 | } |
| 5309 | if (resp_len) { |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 5310 | err = brcmf_fil_iovar_data_get(ifp, "assoc_resp_ies", |
Hante Meuleman | 81f5dcb | 2012-10-22 10:36:14 -0700 | [diff] [blame] | 5311 | cfg->extra_buf, |
| 5312 | WL_ASSOC_INFO_MAX); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5313 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 5314 | brcmf_err("could not get assoc resp (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5315 | return err; |
| 5316 | } |
| 5317 | conn_info->resp_ie_len = resp_len; |
| 5318 | conn_info->resp_ie = |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5319 | kmemdup(cfg->extra_buf, conn_info->resp_ie_len, |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5320 | GFP_KERNEL); |
| 5321 | } else { |
| 5322 | conn_info->resp_ie_len = 0; |
| 5323 | conn_info->resp_ie = NULL; |
| 5324 | } |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 5325 | brcmf_dbg(CONN, "req len (%d) resp len (%d)\n", |
| 5326 | conn_info->req_ie_len, conn_info->resp_ie_len); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5327 | |
| 5328 | return err; |
| 5329 | } |
| 5330 | |
| 5331 | static s32 |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5332 | brcmf_bss_roaming_done(struct brcmf_cfg80211_info *cfg, |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5333 | struct net_device *ndev, |
| 5334 | const struct brcmf_event_msg *e) |
| 5335 | { |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 5336 | struct brcmf_if *ifp = netdev_priv(ndev); |
| 5337 | struct brcmf_cfg80211_profile *profile = &ifp->vif->profile; |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5338 | struct brcmf_cfg80211_connect_info *conn_info = cfg_to_conn(cfg); |
| 5339 | struct wiphy *wiphy = cfg_to_wiphy(cfg); |
Franky Lin | a180b83 | 2012-10-10 11:13:09 -0700 | [diff] [blame] | 5340 | struct ieee80211_channel *notify_channel = NULL; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5341 | struct ieee80211_supported_band *band; |
Franky Lin | a180b83 | 2012-10-10 11:13:09 -0700 | [diff] [blame] | 5342 | struct brcmf_bss_info_le *bi; |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 5343 | struct brcmu_chan ch; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5344 | u32 freq; |
| 5345 | s32 err = 0; |
Franky Lin | a180b83 | 2012-10-10 11:13:09 -0700 | [diff] [blame] | 5346 | u8 *buf; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5347 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 5348 | brcmf_dbg(TRACE, "Enter\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5349 | |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 5350 | brcmf_get_assoc_ies(cfg, ifp); |
Arend van Spriel | 6c8c4f7 | 2012-09-27 14:17:57 +0200 | [diff] [blame] | 5351 | memcpy(profile->bssid, e->addr, ETH_ALEN); |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 5352 | brcmf_update_bss_info(cfg, ifp); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5353 | |
Franky Lin | a180b83 | 2012-10-10 11:13:09 -0700 | [diff] [blame] | 5354 | buf = kzalloc(WL_BSS_INFO_MAX, GFP_KERNEL); |
| 5355 | if (buf == NULL) { |
| 5356 | err = -ENOMEM; |
| 5357 | goto done; |
| 5358 | } |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5359 | |
Franky Lin | a180b83 | 2012-10-10 11:13:09 -0700 | [diff] [blame] | 5360 | /* data sent to dongle has to be little endian */ |
| 5361 | *(__le32 *)buf = cpu_to_le32(WL_BSS_INFO_MAX); |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 5362 | 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] | 5363 | buf, WL_BSS_INFO_MAX); |
Franky Lin | a180b83 | 2012-10-10 11:13:09 -0700 | [diff] [blame] | 5364 | |
| 5365 | if (err) |
| 5366 | goto done; |
| 5367 | |
| 5368 | bi = (struct brcmf_bss_info_le *)(buf + 4); |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 5369 | ch.chspec = le16_to_cpu(bi->chanspec); |
| 5370 | cfg->d11inf.decchspec(&ch); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5371 | |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 5372 | if (ch.band == BRCMU_CHAN_BAND_2G) |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 5373 | band = wiphy->bands[NL80211_BAND_2GHZ]; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5374 | else |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 5375 | band = wiphy->bands[NL80211_BAND_5GHZ]; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5376 | |
Rafał Miłecki | 4712d88 | 2016-05-20 13:38:57 +0200 | [diff] [blame] | 5377 | freq = ieee80211_channel_to_frequency(ch.control_ch_num, band->band); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5378 | notify_channel = ieee80211_get_channel(wiphy, freq); |
| 5379 | |
Franky Lin | a180b83 | 2012-10-10 11:13:09 -0700 | [diff] [blame] | 5380 | done: |
| 5381 | kfree(buf); |
Arend van Spriel | 06bb123 | 2012-09-27 14:17:56 +0200 | [diff] [blame] | 5382 | cfg80211_roamed(ndev, notify_channel, (u8 *)profile->bssid, |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5383 | conn_info->req_ie, conn_info->req_ie_len, |
| 5384 | conn_info->resp_ie, conn_info->resp_ie_len, GFP_KERNEL); |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 5385 | brcmf_dbg(CONN, "Report roaming result\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5386 | |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 5387 | set_bit(BRCMF_VIF_STATUS_CONNECTED, &ifp->vif->sme_state); |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 5388 | brcmf_dbg(TRACE, "Exit\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5389 | return err; |
| 5390 | } |
| 5391 | |
| 5392 | static s32 |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5393 | brcmf_bss_connect_done(struct brcmf_cfg80211_info *cfg, |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5394 | struct net_device *ndev, const struct brcmf_event_msg *e, |
| 5395 | bool completed) |
| 5396 | { |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 5397 | struct brcmf_if *ifp = netdev_priv(ndev); |
| 5398 | struct brcmf_cfg80211_profile *profile = &ifp->vif->profile; |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5399 | struct brcmf_cfg80211_connect_info *conn_info = cfg_to_conn(cfg); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5400 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 5401 | brcmf_dbg(TRACE, "Enter\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5402 | |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 5403 | if (test_and_clear_bit(BRCMF_VIF_STATUS_CONNECTING, |
| 5404 | &ifp->vif->sme_state)) { |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5405 | if (completed) { |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 5406 | brcmf_get_assoc_ies(cfg, ifp); |
Arend van Spriel | 6c8c4f7 | 2012-09-27 14:17:57 +0200 | [diff] [blame] | 5407 | memcpy(profile->bssid, e->addr, ETH_ALEN); |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 5408 | brcmf_update_bss_info(cfg, ifp); |
| 5409 | set_bit(BRCMF_VIF_STATUS_CONNECTED, |
| 5410 | &ifp->vif->sme_state); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5411 | } |
| 5412 | cfg80211_connect_result(ndev, |
Arend van Spriel | 06bb123 | 2012-09-27 14:17:56 +0200 | [diff] [blame] | 5413 | (u8 *)profile->bssid, |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5414 | conn_info->req_ie, |
| 5415 | conn_info->req_ie_len, |
| 5416 | conn_info->resp_ie, |
| 5417 | conn_info->resp_ie_len, |
| 5418 | completed ? WLAN_STATUS_SUCCESS : |
| 5419 | WLAN_STATUS_AUTH_TIMEOUT, |
| 5420 | GFP_KERNEL); |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 5421 | brcmf_dbg(CONN, "Report connect result - connection %s\n", |
| 5422 | completed ? "succeeded" : "failed"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5423 | } |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 5424 | brcmf_dbg(TRACE, "Exit\n"); |
Peter Senna Tschudin | 12f3237 | 2014-05-31 10:14:06 -0300 | [diff] [blame] | 5425 | return 0; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5426 | } |
| 5427 | |
| 5428 | static s32 |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5429 | brcmf_notify_connect_status_ap(struct brcmf_cfg80211_info *cfg, |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 5430 | struct net_device *ndev, |
| 5431 | const struct brcmf_event_msg *e, void *data) |
| 5432 | { |
Hante Meuleman | 7ee2960 | 2013-02-06 18:40:43 +0100 | [diff] [blame] | 5433 | static int generation; |
Arend van Spriel | 5c36b99 | 2012-11-14 18:46:05 -0800 | [diff] [blame] | 5434 | u32 event = e->event_code; |
| 5435 | u32 reason = e->reason; |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 5436 | struct station_info sinfo; |
| 5437 | |
Rafał Miłecki | e1c122d | 2016-10-14 09:45:59 +0200 | [diff] [blame] | 5438 | brcmf_dbg(CONN, "event %s (%u), reason %d\n", |
| 5439 | brcmf_fweh_event_name(event), event, reason); |
Arend van Spriel | 5f4f9f1 | 2013-02-08 15:53:41 +0100 | [diff] [blame] | 5440 | if (event == BRCMF_E_LINK && reason == BRCMF_E_REASON_LINK_BSSCFG_DIS && |
| 5441 | ndev != cfg_to_ndev(cfg)) { |
| 5442 | brcmf_dbg(CONN, "AP mode link down\n"); |
| 5443 | complete(&cfg->vif_disabled); |
| 5444 | return 0; |
| 5445 | } |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 5446 | |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 5447 | if (((event == BRCMF_E_ASSOC_IND) || (event == BRCMF_E_REASSOC_IND)) && |
Hante Meuleman | 7ee2960 | 2013-02-06 18:40:43 +0100 | [diff] [blame] | 5448 | (reason == BRCMF_E_STATUS_SUCCESS)) { |
| 5449 | memset(&sinfo, 0, sizeof(sinfo)); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 5450 | if (!data) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 5451 | brcmf_err("No IEs present in ASSOC/REASSOC_IND"); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 5452 | return -EINVAL; |
| 5453 | } |
| 5454 | sinfo.assoc_req_ies = data; |
Hante Meuleman | 7ee2960 | 2013-02-06 18:40:43 +0100 | [diff] [blame] | 5455 | sinfo.assoc_req_ies_len = e->datalen; |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 5456 | generation++; |
| 5457 | sinfo.generation = generation; |
Hante Meuleman | 7ee2960 | 2013-02-06 18:40:43 +0100 | [diff] [blame] | 5458 | cfg80211_new_sta(ndev, e->addr, &sinfo, GFP_KERNEL); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 5459 | } else if ((event == BRCMF_E_DISASSOC_IND) || |
| 5460 | (event == BRCMF_E_DEAUTH_IND) || |
| 5461 | (event == BRCMF_E_DEAUTH)) { |
Hante Meuleman | 7ee2960 | 2013-02-06 18:40:43 +0100 | [diff] [blame] | 5462 | cfg80211_del_sta(ndev, e->addr, GFP_KERNEL); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 5463 | } |
Hante Meuleman | 7ee2960 | 2013-02-06 18:40:43 +0100 | [diff] [blame] | 5464 | return 0; |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 5465 | } |
| 5466 | |
| 5467 | static s32 |
Arend van Spriel | 1993732 | 2012-11-05 16:22:32 -0800 | [diff] [blame] | 5468 | brcmf_notify_connect_status(struct brcmf_if *ifp, |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5469 | const struct brcmf_event_msg *e, void *data) |
| 5470 | { |
Arend van Spriel | 1993732 | 2012-11-05 16:22:32 -0800 | [diff] [blame] | 5471 | struct brcmf_cfg80211_info *cfg = ifp->drvr->config; |
| 5472 | struct net_device *ndev = ifp->ndev; |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 5473 | struct brcmf_cfg80211_profile *profile = &ifp->vif->profile; |
Antonio Quartulli | fe94f3a | 2014-01-29 17:53:43 +0100 | [diff] [blame] | 5474 | struct ieee80211_channel *chan; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5475 | s32 err = 0; |
| 5476 | |
Hante Meuleman | 8851cce | 2014-07-30 13:20:02 +0200 | [diff] [blame] | 5477 | if ((e->event_code == BRCMF_E_DEAUTH) || |
| 5478 | (e->event_code == BRCMF_E_DEAUTH_IND) || |
| 5479 | (e->event_code == BRCMF_E_DISASSOC_IND) || |
| 5480 | ((e->event_code == BRCMF_E_LINK) && (!e->flags))) { |
| 5481 | brcmf_proto_delete_peer(ifp->drvr, ifp->ifidx, (u8 *)e->addr); |
| 5482 | } |
| 5483 | |
Arend van Spriel | 967fe2c | 2014-03-15 17:18:21 +0100 | [diff] [blame] | 5484 | if (brcmf_is_apmode(ifp->vif)) { |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5485 | err = brcmf_notify_connect_status_ap(cfg, ndev, e, data); |
Arend van Spriel | 903e0ee | 2012-11-28 21:44:11 +0100 | [diff] [blame] | 5486 | } else if (brcmf_is_linkup(e)) { |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 5487 | brcmf_dbg(CONN, "Linkup\n"); |
Arend van Spriel | 128ce3b | 2012-11-28 21:44:12 +0100 | [diff] [blame] | 5488 | if (brcmf_is_ibssmode(ifp->vif)) { |
Hante Meuleman | b0a7908 | 2015-12-10 13:43:07 +0100 | [diff] [blame] | 5489 | brcmf_inform_ibss(cfg, ndev, e->addr); |
Antonio Quartulli | fe94f3a | 2014-01-29 17:53:43 +0100 | [diff] [blame] | 5490 | chan = ieee80211_get_channel(cfg->wiphy, cfg->channel); |
Arend van Spriel | 6c8c4f7 | 2012-09-27 14:17:57 +0200 | [diff] [blame] | 5491 | memcpy(profile->bssid, e->addr, ETH_ALEN); |
Antonio Quartulli | fe94f3a | 2014-01-29 17:53:43 +0100 | [diff] [blame] | 5492 | cfg80211_ibss_joined(ndev, e->addr, chan, GFP_KERNEL); |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 5493 | clear_bit(BRCMF_VIF_STATUS_CONNECTING, |
| 5494 | &ifp->vif->sme_state); |
| 5495 | set_bit(BRCMF_VIF_STATUS_CONNECTED, |
| 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, true); |
Hante Meuleman | 92121e6 | 2015-10-08 20:33:21 +0200 | [diff] [blame] | 5499 | brcmf_net_setcarrier(ifp, true); |
Arend van Spriel | 903e0ee | 2012-11-28 21:44:11 +0100 | [diff] [blame] | 5500 | } else if (brcmf_is_linkdown(e)) { |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 5501 | brcmf_dbg(CONN, "Linkdown\n"); |
Arend van Spriel | 128ce3b | 2012-11-28 21:44:12 +0100 | [diff] [blame] | 5502 | if (!brcmf_is_ibssmode(ifp->vif)) { |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5503 | brcmf_bss_connect_done(cfg, ndev, e, false); |
Hante Meuleman | 42e0ed0 | 2016-01-05 11:05:50 +0100 | [diff] [blame] | 5504 | brcmf_link_down(ifp->vif, |
| 5505 | brcmf_map_fw_linkdown_reason(e)); |
| 5506 | brcmf_init_prof(ndev_to_prof(ndev)); |
| 5507 | if (ndev != cfg_to_ndev(cfg)) |
| 5508 | complete(&cfg->vif_disabled); |
| 5509 | brcmf_net_setcarrier(ifp, false); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5510 | } |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5511 | } else if (brcmf_is_nonetwork(cfg, e)) { |
Arend van Spriel | 128ce3b | 2012-11-28 21:44:12 +0100 | [diff] [blame] | 5512 | if (brcmf_is_ibssmode(ifp->vif)) |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 5513 | clear_bit(BRCMF_VIF_STATUS_CONNECTING, |
| 5514 | &ifp->vif->sme_state); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5515 | else |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5516 | brcmf_bss_connect_done(cfg, ndev, e, false); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5517 | } |
| 5518 | |
| 5519 | return err; |
| 5520 | } |
| 5521 | |
| 5522 | static s32 |
Arend van Spriel | 1993732 | 2012-11-05 16:22:32 -0800 | [diff] [blame] | 5523 | brcmf_notify_roaming_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 | 1993732 | 2012-11-05 16:22:32 -0800 | [diff] [blame] | 5526 | struct brcmf_cfg80211_info *cfg = ifp->drvr->config; |
Arend van Spriel | 5c36b99 | 2012-11-14 18:46:05 -0800 | [diff] [blame] | 5527 | u32 event = e->event_code; |
| 5528 | u32 status = e->status; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5529 | |
| 5530 | if (event == BRCMF_E_ROAM && status == BRCMF_E_STATUS_SUCCESS) { |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 5531 | if (test_bit(BRCMF_VIF_STATUS_CONNECTED, &ifp->vif->sme_state)) |
Arend van Spriel | 1993732 | 2012-11-05 16:22:32 -0800 | [diff] [blame] | 5532 | brcmf_bss_roaming_done(cfg, ifp->ndev, e); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5533 | else |
Arend van Spriel | 1993732 | 2012-11-05 16:22:32 -0800 | [diff] [blame] | 5534 | brcmf_bss_connect_done(cfg, ifp->ndev, e, true); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5535 | } |
| 5536 | |
Peter Senna Tschudin | 12f3237 | 2014-05-31 10:14:06 -0300 | [diff] [blame] | 5537 | return 0; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5538 | } |
| 5539 | |
| 5540 | static s32 |
Arend van Spriel | 1993732 | 2012-11-05 16:22:32 -0800 | [diff] [blame] | 5541 | brcmf_notify_mic_status(struct brcmf_if *ifp, |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5542 | const struct brcmf_event_msg *e, void *data) |
| 5543 | { |
Arend van Spriel | 5c36b99 | 2012-11-14 18:46:05 -0800 | [diff] [blame] | 5544 | u16 flags = e->flags; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5545 | enum nl80211_key_type key_type; |
| 5546 | |
| 5547 | if (flags & BRCMF_EVENT_MSG_GROUP) |
| 5548 | key_type = NL80211_KEYTYPE_GROUP; |
| 5549 | else |
| 5550 | key_type = NL80211_KEYTYPE_PAIRWISE; |
| 5551 | |
Arend van Spriel | 1993732 | 2012-11-05 16:22:32 -0800 | [diff] [blame] | 5552 | 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] | 5553 | NULL, GFP_KERNEL); |
| 5554 | |
| 5555 | return 0; |
| 5556 | } |
| 5557 | |
Arend van Spriel | d3c0b63 | 2013-02-08 15:53:37 +0100 | [diff] [blame] | 5558 | static s32 brcmf_notify_vif_event(struct brcmf_if *ifp, |
| 5559 | const struct brcmf_event_msg *e, void *data) |
| 5560 | { |
| 5561 | struct brcmf_cfg80211_info *cfg = ifp->drvr->config; |
| 5562 | struct brcmf_if_event *ifevent = (struct brcmf_if_event *)data; |
| 5563 | struct brcmf_cfg80211_vif_event *event = &cfg->vif_event; |
| 5564 | struct brcmf_cfg80211_vif *vif; |
| 5565 | |
Hante Meuleman | 37a869e | 2015-10-29 20:33:17 +0100 | [diff] [blame] | 5566 | 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] | 5567 | ifevent->action, ifevent->flags, ifevent->ifidx, |
Hante Meuleman | 37a869e | 2015-10-29 20:33:17 +0100 | [diff] [blame] | 5568 | ifevent->bsscfgidx); |
Arend van Spriel | d3c0b63 | 2013-02-08 15:53:37 +0100 | [diff] [blame] | 5569 | |
mhiramat@kernel.org | b64abcb | 2016-08-15 18:41:12 +0900 | [diff] [blame] | 5570 | spin_lock(&event->vif_event_lock); |
Arend van Spriel | d3c0b63 | 2013-02-08 15:53:37 +0100 | [diff] [blame] | 5571 | event->action = ifevent->action; |
| 5572 | vif = event->vif; |
| 5573 | |
| 5574 | switch (ifevent->action) { |
| 5575 | case BRCMF_E_IF_ADD: |
| 5576 | /* waiting process may have timed out */ |
Wei Yongjun | dc4a787 | 2013-02-22 21:32:20 +0800 | [diff] [blame] | 5577 | if (!cfg->vif_event.vif) { |
mhiramat@kernel.org | b64abcb | 2016-08-15 18:41:12 +0900 | [diff] [blame] | 5578 | spin_unlock(&event->vif_event_lock); |
Arend van Spriel | d3c0b63 | 2013-02-08 15:53:37 +0100 | [diff] [blame] | 5579 | return -EBADF; |
Wei Yongjun | dc4a787 | 2013-02-22 21:32:20 +0800 | [diff] [blame] | 5580 | } |
Arend van Spriel | d3c0b63 | 2013-02-08 15:53:37 +0100 | [diff] [blame] | 5581 | |
| 5582 | ifp->vif = vif; |
| 5583 | vif->ifp = ifp; |
Arend van Spriel | 01b8e7d | 2013-04-05 10:57:51 +0200 | [diff] [blame] | 5584 | if (ifp->ndev) { |
| 5585 | vif->wdev.netdev = ifp->ndev; |
| 5586 | ifp->ndev->ieee80211_ptr = &vif->wdev; |
| 5587 | SET_NETDEV_DEV(ifp->ndev, wiphy_dev(cfg->wiphy)); |
| 5588 | } |
mhiramat@kernel.org | b64abcb | 2016-08-15 18:41:12 +0900 | [diff] [blame] | 5589 | spin_unlock(&event->vif_event_lock); |
Arend van Spriel | d3c0b63 | 2013-02-08 15:53:37 +0100 | [diff] [blame] | 5590 | wake_up(&event->vif_wq); |
Hante Meuleman | 4b3a89d | 2013-02-08 15:54:01 +0100 | [diff] [blame] | 5591 | return 0; |
Arend van Spriel | d3c0b63 | 2013-02-08 15:53:37 +0100 | [diff] [blame] | 5592 | |
| 5593 | case BRCMF_E_IF_DEL: |
mhiramat@kernel.org | b64abcb | 2016-08-15 18:41:12 +0900 | [diff] [blame] | 5594 | spin_unlock(&event->vif_event_lock); |
Arend van Spriel | d3c0b63 | 2013-02-08 15:53:37 +0100 | [diff] [blame] | 5595 | /* event may not be upon user request */ |
| 5596 | if (brcmf_cfg80211_vif_event_armed(cfg)) |
| 5597 | wake_up(&event->vif_wq); |
| 5598 | return 0; |
| 5599 | |
Hante Meuleman | 7a5c1f6 | 2013-02-08 15:53:44 +0100 | [diff] [blame] | 5600 | case BRCMF_E_IF_CHANGE: |
mhiramat@kernel.org | b64abcb | 2016-08-15 18:41:12 +0900 | [diff] [blame] | 5601 | spin_unlock(&event->vif_event_lock); |
Hante Meuleman | 7a5c1f6 | 2013-02-08 15:53:44 +0100 | [diff] [blame] | 5602 | wake_up(&event->vif_wq); |
| 5603 | return 0; |
| 5604 | |
Arend van Spriel | d3c0b63 | 2013-02-08 15:53:37 +0100 | [diff] [blame] | 5605 | default: |
mhiramat@kernel.org | b64abcb | 2016-08-15 18:41:12 +0900 | [diff] [blame] | 5606 | spin_unlock(&event->vif_event_lock); |
Arend van Spriel | d3c0b63 | 2013-02-08 15:53:37 +0100 | [diff] [blame] | 5607 | break; |
| 5608 | } |
| 5609 | return -EINVAL; |
| 5610 | } |
| 5611 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5612 | static void brcmf_init_conf(struct brcmf_cfg80211_conf *conf) |
| 5613 | { |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5614 | conf->frag_threshold = (u32)-1; |
| 5615 | conf->rts_threshold = (u32)-1; |
| 5616 | conf->retry_short = (u32)-1; |
| 5617 | conf->retry_long = (u32)-1; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5618 | } |
| 5619 | |
Arend van Spriel | 5c36b99 | 2012-11-14 18:46:05 -0800 | [diff] [blame] | 5620 | static void brcmf_register_event_handlers(struct brcmf_cfg80211_info *cfg) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5621 | { |
Arend van Spriel | 5c36b99 | 2012-11-14 18:46:05 -0800 | [diff] [blame] | 5622 | brcmf_fweh_register(cfg->pub, BRCMF_E_LINK, |
| 5623 | brcmf_notify_connect_status); |
| 5624 | brcmf_fweh_register(cfg->pub, BRCMF_E_DEAUTH_IND, |
| 5625 | brcmf_notify_connect_status); |
| 5626 | brcmf_fweh_register(cfg->pub, BRCMF_E_DEAUTH, |
| 5627 | brcmf_notify_connect_status); |
| 5628 | brcmf_fweh_register(cfg->pub, BRCMF_E_DISASSOC_IND, |
| 5629 | brcmf_notify_connect_status); |
| 5630 | brcmf_fweh_register(cfg->pub, BRCMF_E_ASSOC_IND, |
| 5631 | brcmf_notify_connect_status); |
| 5632 | brcmf_fweh_register(cfg->pub, BRCMF_E_REASSOC_IND, |
| 5633 | brcmf_notify_connect_status); |
| 5634 | brcmf_fweh_register(cfg->pub, BRCMF_E_ROAM, |
| 5635 | brcmf_notify_roaming_status); |
| 5636 | brcmf_fweh_register(cfg->pub, BRCMF_E_MIC_ERROR, |
| 5637 | brcmf_notify_mic_status); |
| 5638 | brcmf_fweh_register(cfg->pub, BRCMF_E_SET_SSID, |
| 5639 | brcmf_notify_connect_status); |
| 5640 | brcmf_fweh_register(cfg->pub, BRCMF_E_PFN_NET_FOUND, |
| 5641 | brcmf_notify_sched_scan_results); |
Arend van Spriel | d3c0b63 | 2013-02-08 15:53:37 +0100 | [diff] [blame] | 5642 | brcmf_fweh_register(cfg->pub, BRCMF_E_IF, |
| 5643 | brcmf_notify_vif_event); |
Hante Meuleman | 0de8aac | 2013-02-08 15:53:38 +0100 | [diff] [blame] | 5644 | brcmf_fweh_register(cfg->pub, BRCMF_E_P2P_PROBEREQ_MSG, |
Hante Meuleman | 6eda4e2 | 2013-02-08 15:54:02 +0100 | [diff] [blame] | 5645 | brcmf_p2p_notify_rx_mgmt_p2p_probereq); |
Hante Meuleman | 0de8aac | 2013-02-08 15:53:38 +0100 | [diff] [blame] | 5646 | brcmf_fweh_register(cfg->pub, BRCMF_E_P2P_DISC_LISTEN_COMPLETE, |
| 5647 | brcmf_p2p_notify_listen_complete); |
Hante Meuleman | e6da340 | 2013-02-08 15:53:48 +0100 | [diff] [blame] | 5648 | brcmf_fweh_register(cfg->pub, BRCMF_E_ACTION_FRAME_RX, |
| 5649 | brcmf_p2p_notify_action_frame_rx); |
Hante Meuleman | 18e2f61 | 2013-02-08 15:53:49 +0100 | [diff] [blame] | 5650 | brcmf_fweh_register(cfg->pub, BRCMF_E_ACTION_FRAME_COMPLETE, |
| 5651 | brcmf_p2p_notify_action_tx_complete); |
Hante Meuleman | 6eda4e2 | 2013-02-08 15:54:02 +0100 | [diff] [blame] | 5652 | brcmf_fweh_register(cfg->pub, BRCMF_E_ACTION_FRAME_OFF_CHAN_COMPLETE, |
| 5653 | brcmf_p2p_notify_action_tx_complete); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5654 | } |
| 5655 | |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5656 | static void brcmf_deinit_priv_mem(struct brcmf_cfg80211_info *cfg) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5657 | { |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5658 | kfree(cfg->conf); |
| 5659 | cfg->conf = NULL; |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5660 | kfree(cfg->extra_buf); |
| 5661 | cfg->extra_buf = NULL; |
Hante Meuleman | 3021ad9 | 2016-01-05 11:05:45 +0100 | [diff] [blame] | 5662 | kfree(cfg->wowl.nd); |
| 5663 | cfg->wowl.nd = NULL; |
| 5664 | kfree(cfg->wowl.nd_info); |
| 5665 | cfg->wowl.nd_info = NULL; |
Hante Meuleman | d536733 | 2016-02-17 11:26:51 +0100 | [diff] [blame] | 5666 | kfree(cfg->escan_info.escan_buf); |
| 5667 | cfg->escan_info.escan_buf = NULL; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5668 | } |
| 5669 | |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5670 | static s32 brcmf_init_priv_mem(struct brcmf_cfg80211_info *cfg) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5671 | { |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5672 | cfg->conf = kzalloc(sizeof(*cfg->conf), GFP_KERNEL); |
| 5673 | if (!cfg->conf) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5674 | goto init_priv_mem_out; |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5675 | cfg->extra_buf = kzalloc(WL_EXTRA_BUF_MAX, GFP_KERNEL); |
| 5676 | if (!cfg->extra_buf) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5677 | goto init_priv_mem_out; |
Hante Meuleman | 3021ad9 | 2016-01-05 11:05:45 +0100 | [diff] [blame] | 5678 | cfg->wowl.nd = kzalloc(sizeof(*cfg->wowl.nd) + sizeof(u32), GFP_KERNEL); |
| 5679 | if (!cfg->wowl.nd) |
| 5680 | goto init_priv_mem_out; |
| 5681 | cfg->wowl.nd_info = kzalloc(sizeof(*cfg->wowl.nd_info) + |
| 5682 | sizeof(struct cfg80211_wowlan_nd_match *), |
| 5683 | GFP_KERNEL); |
| 5684 | if (!cfg->wowl.nd_info) |
| 5685 | goto init_priv_mem_out; |
Hante Meuleman | d536733 | 2016-02-17 11:26:51 +0100 | [diff] [blame] | 5686 | cfg->escan_info.escan_buf = kzalloc(BRCMF_ESCAN_BUF_SIZE, GFP_KERNEL); |
| 5687 | if (!cfg->escan_info.escan_buf) |
| 5688 | goto init_priv_mem_out; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5689 | |
| 5690 | return 0; |
| 5691 | |
| 5692 | init_priv_mem_out: |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5693 | brcmf_deinit_priv_mem(cfg); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5694 | |
| 5695 | return -ENOMEM; |
| 5696 | } |
| 5697 | |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5698 | static s32 wl_init_priv(struct brcmf_cfg80211_info *cfg) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5699 | { |
| 5700 | s32 err = 0; |
| 5701 | |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5702 | cfg->scan_request = NULL; |
| 5703 | cfg->pwr_save = true; |
Hante Meuleman | 68ca395 | 2014-02-25 20:30:26 +0100 | [diff] [blame] | 5704 | cfg->active_scan = true; /* we do active scan per default */ |
| 5705 | cfg->dongle_up = false; /* dongle is not up yet */ |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5706 | err = brcmf_init_priv_mem(cfg); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5707 | if (err) |
| 5708 | return err; |
Arend van Spriel | 5c36b99 | 2012-11-14 18:46:05 -0800 | [diff] [blame] | 5709 | brcmf_register_event_handlers(cfg); |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5710 | mutex_init(&cfg->usr_sync); |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5711 | brcmf_init_escan(cfg); |
| 5712 | brcmf_init_conf(cfg->conf); |
Arend van Spriel | 5f4f9f1 | 2013-02-08 15:53:41 +0100 | [diff] [blame] | 5713 | init_completion(&cfg->vif_disabled); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5714 | return err; |
| 5715 | } |
| 5716 | |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5717 | static void wl_deinit_priv(struct brcmf_cfg80211_info *cfg) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5718 | { |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5719 | cfg->dongle_up = false; /* dongle down */ |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5720 | brcmf_abort_scanning(cfg); |
| 5721 | brcmf_deinit_priv_mem(cfg); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5722 | } |
| 5723 | |
Arend van Spriel | d3c0b63 | 2013-02-08 15:53:37 +0100 | [diff] [blame] | 5724 | static void init_vif_event(struct brcmf_cfg80211_vif_event *event) |
| 5725 | { |
| 5726 | init_waitqueue_head(&event->vif_wq); |
mhiramat@kernel.org | b64abcb | 2016-08-15 18:41:12 +0900 | [diff] [blame] | 5727 | spin_lock_init(&event->vif_event_lock); |
Arend van Spriel | d3c0b63 | 2013-02-08 15:53:37 +0100 | [diff] [blame] | 5728 | } |
| 5729 | |
Hante Meuleman | 1119e23 | 2015-11-25 11:32:42 +0100 | [diff] [blame] | 5730 | static s32 brcmf_dongle_roam(struct brcmf_if *ifp) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5731 | { |
Hante Meuleman | 1119e23 | 2015-11-25 11:32:42 +0100 | [diff] [blame] | 5732 | s32 err; |
| 5733 | u32 bcn_timeout; |
Arend van Spriel | f588bc0 | 2011-10-12 20:51:22 +0200 | [diff] [blame] | 5734 | __le32 roamtrigger[2]; |
| 5735 | __le32 roam_delta[2]; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5736 | |
Hante Meuleman | 1119e23 | 2015-11-25 11:32:42 +0100 | [diff] [blame] | 5737 | /* Configure beacon timeout value based upon roaming setting */ |
Hante Meuleman | 7d34b05 | 2016-01-02 09:41:41 +0100 | [diff] [blame] | 5738 | if (ifp->drvr->settings->roamoff) |
Hante Meuleman | 1119e23 | 2015-11-25 11:32:42 +0100 | [diff] [blame] | 5739 | bcn_timeout = BRCMF_DEFAULT_BCN_TIMEOUT_ROAM_OFF; |
| 5740 | else |
| 5741 | bcn_timeout = BRCMF_DEFAULT_BCN_TIMEOUT_ROAM_ON; |
| 5742 | err = brcmf_fil_iovar_int_set(ifp, "bcn_timeout", bcn_timeout); |
| 5743 | if (err) { |
| 5744 | brcmf_err("bcn_timeout error (%d)\n", err); |
| 5745 | goto roam_setup_done; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5746 | } |
| 5747 | |
Hante Meuleman | 1119e23 | 2015-11-25 11:32:42 +0100 | [diff] [blame] | 5748 | /* Enable/Disable built-in roaming to allow supplicant to take care of |
| 5749 | * roaming. |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5750 | */ |
Hante Meuleman | 68ca395 | 2014-02-25 20:30:26 +0100 | [diff] [blame] | 5751 | brcmf_dbg(INFO, "Internal Roaming = %s\n", |
Hante Meuleman | 7d34b05 | 2016-01-02 09:41:41 +0100 | [diff] [blame] | 5752 | ifp->drvr->settings->roamoff ? "Off" : "On"); |
| 5753 | err = brcmf_fil_iovar_int_set(ifp, "roam_off", |
| 5754 | ifp->drvr->settings->roamoff); |
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("roam_off 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 | |
Arend van Spriel | f588bc0 | 2011-10-12 20:51:22 +0200 | [diff] [blame] | 5760 | roamtrigger[0] = cpu_to_le32(WL_ROAM_TRIGGER_LEVEL); |
| 5761 | roamtrigger[1] = cpu_to_le32(BRCM_BAND_ALL); |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 5762 | err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SET_ROAM_TRIGGER, |
Hante Meuleman | 81f5dcb | 2012-10-22 10:36:14 -0700 | [diff] [blame] | 5763 | (void *)roamtrigger, sizeof(roamtrigger)); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5764 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 5765 | brcmf_err("WLC_SET_ROAM_TRIGGER error (%d)\n", err); |
Hante Meuleman | 1119e23 | 2015-11-25 11:32:42 +0100 | [diff] [blame] | 5766 | goto roam_setup_done; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5767 | } |
| 5768 | |
Arend van Spriel | f588bc0 | 2011-10-12 20:51:22 +0200 | [diff] [blame] | 5769 | roam_delta[0] = cpu_to_le32(WL_ROAM_DELTA); |
| 5770 | roam_delta[1] = cpu_to_le32(BRCM_BAND_ALL); |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 5771 | err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SET_ROAM_DELTA, |
Hante Meuleman | 81f5dcb | 2012-10-22 10:36:14 -0700 | [diff] [blame] | 5772 | (void *)roam_delta, sizeof(roam_delta)); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5773 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 5774 | brcmf_err("WLC_SET_ROAM_DELTA error (%d)\n", err); |
Hante Meuleman | 1119e23 | 2015-11-25 11:32:42 +0100 | [diff] [blame] | 5775 | goto roam_setup_done; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5776 | } |
| 5777 | |
Hante Meuleman | 1119e23 | 2015-11-25 11:32:42 +0100 | [diff] [blame] | 5778 | roam_setup_done: |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5779 | return err; |
| 5780 | } |
| 5781 | |
| 5782 | static s32 |
Hante Meuleman | 1678ba8 | 2015-12-10 13:43:00 +0100 | [diff] [blame] | 5783 | brcmf_dongle_scantime(struct brcmf_if *ifp) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5784 | { |
| 5785 | s32 err = 0; |
| 5786 | |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 5787 | 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] | 5788 | BRCMF_SCAN_CHANNEL_TIME); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5789 | if (err) { |
Hante Meuleman | 1678ba8 | 2015-12-10 13:43:00 +0100 | [diff] [blame] | 5790 | brcmf_err("Scan assoc time error (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5791 | goto dongle_scantime_out; |
| 5792 | } |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 5793 | 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] | 5794 | BRCMF_SCAN_UNASSOC_TIME); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5795 | if (err) { |
Hante Meuleman | 1678ba8 | 2015-12-10 13:43:00 +0100 | [diff] [blame] | 5796 | brcmf_err("Scan unassoc time error (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5797 | goto dongle_scantime_out; |
| 5798 | } |
| 5799 | |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 5800 | 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] | 5801 | BRCMF_SCAN_PASSIVE_TIME); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5802 | if (err) { |
Hante Meuleman | 1678ba8 | 2015-12-10 13:43:00 +0100 | [diff] [blame] | 5803 | brcmf_err("Scan passive time error (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5804 | goto dongle_scantime_out; |
| 5805 | } |
| 5806 | |
| 5807 | dongle_scantime_out: |
| 5808 | return err; |
| 5809 | } |
| 5810 | |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 5811 | static void brcmf_update_bw40_channel_flag(struct ieee80211_channel *channel, |
| 5812 | struct brcmu_chan *ch) |
| 5813 | { |
| 5814 | u32 ht40_flag; |
| 5815 | |
| 5816 | ht40_flag = channel->flags & IEEE80211_CHAN_NO_HT40; |
| 5817 | if (ch->sb == BRCMU_CHAN_SB_U) { |
| 5818 | if (ht40_flag == IEEE80211_CHAN_NO_HT40) |
| 5819 | channel->flags &= ~IEEE80211_CHAN_NO_HT40; |
| 5820 | channel->flags |= IEEE80211_CHAN_NO_HT40PLUS; |
| 5821 | } else { |
| 5822 | /* It should be one of |
| 5823 | * IEEE80211_CHAN_NO_HT40 or |
| 5824 | * IEEE80211_CHAN_NO_HT40PLUS |
| 5825 | */ |
| 5826 | channel->flags &= ~IEEE80211_CHAN_NO_HT40; |
| 5827 | if (ht40_flag == IEEE80211_CHAN_NO_HT40) |
| 5828 | channel->flags |= IEEE80211_CHAN_NO_HT40MINUS; |
| 5829 | } |
| 5830 | } |
| 5831 | |
| 5832 | static int brcmf_construct_chaninfo(struct brcmf_cfg80211_info *cfg, |
| 5833 | u32 bw_cap[]) |
Hante Meuleman | d48200b | 2013-04-03 12:40:29 +0200 | [diff] [blame] | 5834 | { |
| 5835 | struct brcmf_if *ifp = netdev_priv(cfg_to_ndev(cfg)); |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 5836 | struct ieee80211_supported_band *band; |
| 5837 | struct ieee80211_channel *channel; |
| 5838 | struct wiphy *wiphy; |
Hante Meuleman | d48200b | 2013-04-03 12:40:29 +0200 | [diff] [blame] | 5839 | struct brcmf_chanspec_list *list; |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 5840 | struct brcmu_chan ch; |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 5841 | int err; |
Hante Meuleman | d48200b | 2013-04-03 12:40:29 +0200 | [diff] [blame] | 5842 | u8 *pbuf; |
| 5843 | u32 i, j; |
| 5844 | u32 total; |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 5845 | u32 chaninfo; |
Hante Meuleman | d48200b | 2013-04-03 12:40:29 +0200 | [diff] [blame] | 5846 | |
| 5847 | pbuf = kzalloc(BRCMF_DCMD_MEDLEN, GFP_KERNEL); |
| 5848 | |
| 5849 | if (pbuf == NULL) |
| 5850 | return -ENOMEM; |
| 5851 | |
| 5852 | list = (struct brcmf_chanspec_list *)pbuf; |
| 5853 | |
| 5854 | err = brcmf_fil_iovar_data_get(ifp, "chanspecs", pbuf, |
| 5855 | BRCMF_DCMD_MEDLEN); |
| 5856 | if (err) { |
| 5857 | brcmf_err("get chanspecs error (%d)\n", err); |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 5858 | goto fail_pbuf; |
Hante Meuleman | d48200b | 2013-04-03 12:40:29 +0200 | [diff] [blame] | 5859 | } |
| 5860 | |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 5861 | wiphy = cfg_to_wiphy(cfg); |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 5862 | band = wiphy->bands[NL80211_BAND_2GHZ]; |
Arend van Spriel | 58de92d | 2015-04-14 20:10:24 +0200 | [diff] [blame] | 5863 | if (band) |
| 5864 | for (i = 0; i < band->n_channels; i++) |
| 5865 | band->channels[i].flags = IEEE80211_CHAN_DISABLED; |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 5866 | band = wiphy->bands[NL80211_BAND_5GHZ]; |
Arend van Spriel | 58de92d | 2015-04-14 20:10:24 +0200 | [diff] [blame] | 5867 | if (band) |
| 5868 | for (i = 0; i < band->n_channels; i++) |
| 5869 | band->channels[i].flags = IEEE80211_CHAN_DISABLED; |
Hante Meuleman | d48200b | 2013-04-03 12:40:29 +0200 | [diff] [blame] | 5870 | |
| 5871 | total = le32_to_cpu(list->count); |
| 5872 | for (i = 0; i < total; i++) { |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 5873 | ch.chspec = (u16)le32_to_cpu(list->element[i]); |
| 5874 | cfg->d11inf.decchspec(&ch); |
Hante Meuleman | d48200b | 2013-04-03 12:40:29 +0200 | [diff] [blame] | 5875 | |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 5876 | if (ch.band == BRCMU_CHAN_BAND_2G) { |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 5877 | band = wiphy->bands[NL80211_BAND_2GHZ]; |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 5878 | } else if (ch.band == BRCMU_CHAN_BAND_5G) { |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 5879 | band = wiphy->bands[NL80211_BAND_5GHZ]; |
Hante Meuleman | d48200b | 2013-04-03 12:40:29 +0200 | [diff] [blame] | 5880 | } else { |
Arend van Spriel | 2375d97 | 2014-01-06 12:40:41 +0100 | [diff] [blame] | 5881 | brcmf_err("Invalid channel Spec. 0x%x.\n", ch.chspec); |
Hante Meuleman | d48200b | 2013-04-03 12:40:29 +0200 | [diff] [blame] | 5882 | continue; |
| 5883 | } |
Arend van Spriel | 58de92d | 2015-04-14 20:10:24 +0200 | [diff] [blame] | 5884 | if (!band) |
| 5885 | continue; |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 5886 | if (!(bw_cap[band->band] & WLC_BW_40MHZ_BIT) && |
Arend van Spriel | 2375d97 | 2014-01-06 12:40:41 +0100 | [diff] [blame] | 5887 | ch.bw == BRCMU_CHAN_BW_40) |
Hante Meuleman | d48200b | 2013-04-03 12:40:29 +0200 | [diff] [blame] | 5888 | continue; |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 5889 | if (!(bw_cap[band->band] & WLC_BW_80MHZ_BIT) && |
Arend van Spriel | ee942ec | 2014-05-12 10:47:38 +0200 | [diff] [blame] | 5890 | ch.bw == BRCMU_CHAN_BW_80) |
| 5891 | continue; |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 5892 | |
Rafał Miłecki | 77c0d0c | 2017-01-04 12:09:41 +0100 | [diff] [blame] | 5893 | channel = NULL; |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 5894 | for (j = 0; j < band->n_channels; j++) { |
Rafał Miłecki | 77c0d0c | 2017-01-04 12:09:41 +0100 | [diff] [blame] | 5895 | if (band->channels[j].hw_value == ch.control_ch_num) { |
| 5896 | channel = &band->channels[j]; |
Hante Meuleman | d48200b | 2013-04-03 12:40:29 +0200 | [diff] [blame] | 5897 | break; |
| 5898 | } |
| 5899 | } |
Rafał Miłecki | 77c0d0c | 2017-01-04 12:09:41 +0100 | [diff] [blame] | 5900 | if (!channel) { |
| 5901 | /* It seems firmware supports some channel we never |
| 5902 | * considered. Something new in IEEE standard? |
| 5903 | */ |
| 5904 | brcmf_err("Ignoring unexpected firmware channel %d\n", |
| 5905 | ch.control_ch_num); |
| 5906 | continue; |
| 5907 | } |
Hante Meuleman | d48200b | 2013-04-03 12:40:29 +0200 | [diff] [blame] | 5908 | |
Rafał Miłecki | 0f83ff6 | 2017-01-17 23:35:50 +0100 | [diff] [blame] | 5909 | if (channel->orig_flags & IEEE80211_CHAN_DISABLED) |
| 5910 | continue; |
| 5911 | |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 5912 | /* assuming the chanspecs order is HT20, |
| 5913 | * HT40 upper, HT40 lower, and VHT80. |
| 5914 | */ |
| 5915 | if (ch.bw == BRCMU_CHAN_BW_80) { |
Rafał Miłecki | 77c0d0c | 2017-01-04 12:09:41 +0100 | [diff] [blame] | 5916 | channel->flags &= ~IEEE80211_CHAN_NO_80MHZ; |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 5917 | } else if (ch.bw == BRCMU_CHAN_BW_40) { |
Rafał Miłecki | 77c0d0c | 2017-01-04 12:09:41 +0100 | [diff] [blame] | 5918 | brcmf_update_bw40_channel_flag(channel, &ch); |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 5919 | } else { |
Arend van Spriel | 58de92d | 2015-04-14 20:10:24 +0200 | [diff] [blame] | 5920 | /* enable the channel and disable other bandwidths |
| 5921 | * for now as mentioned order assure they are enabled |
| 5922 | * for subsequent chanspecs. |
Arend van Spriel | ee942ec | 2014-05-12 10:47:38 +0200 | [diff] [blame] | 5923 | */ |
Rafał Miłecki | 77c0d0c | 2017-01-04 12:09:41 +0100 | [diff] [blame] | 5924 | channel->flags = IEEE80211_CHAN_NO_HT40 | |
| 5925 | IEEE80211_CHAN_NO_80MHZ; |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 5926 | ch.bw = BRCMU_CHAN_BW_20; |
| 5927 | cfg->d11inf.encchspec(&ch); |
| 5928 | chaninfo = ch.chspec; |
| 5929 | err = brcmf_fil_bsscfg_int_get(ifp, "per_chan_info", |
| 5930 | &chaninfo); |
| 5931 | if (!err) { |
| 5932 | if (chaninfo & WL_CHAN_RADAR) |
Rafał Miłecki | 77c0d0c | 2017-01-04 12:09:41 +0100 | [diff] [blame] | 5933 | channel->flags |= |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 5934 | (IEEE80211_CHAN_RADAR | |
| 5935 | IEEE80211_CHAN_NO_IR); |
| 5936 | if (chaninfo & WL_CHAN_PASSIVE) |
Rafał Miłecki | 77c0d0c | 2017-01-04 12:09:41 +0100 | [diff] [blame] | 5937 | channel->flags |= |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 5938 | IEEE80211_CHAN_NO_IR; |
Hante Meuleman | d48200b | 2013-04-03 12:40:29 +0200 | [diff] [blame] | 5939 | } |
Hante Meuleman | d48200b | 2013-04-03 12:40:29 +0200 | [diff] [blame] | 5940 | } |
| 5941 | } |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 5942 | |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 5943 | fail_pbuf: |
Hante Meuleman | d48200b | 2013-04-03 12:40:29 +0200 | [diff] [blame] | 5944 | kfree(pbuf); |
| 5945 | return err; |
| 5946 | } |
| 5947 | |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 5948 | static int brcmf_enable_bw40_2g(struct brcmf_cfg80211_info *cfg) |
Arend van Spriel | aa70b4f | 2014-07-12 08:49:40 +0200 | [diff] [blame] | 5949 | { |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 5950 | struct brcmf_if *ifp = netdev_priv(cfg_to_ndev(cfg)); |
| 5951 | struct ieee80211_supported_band *band; |
Arend van Spriel | aa70b4f | 2014-07-12 08:49:40 +0200 | [diff] [blame] | 5952 | struct brcmf_fil_bwcap_le band_bwcap; |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 5953 | struct brcmf_chanspec_list *list; |
| 5954 | u8 *pbuf; |
Arend van Spriel | aa70b4f | 2014-07-12 08:49:40 +0200 | [diff] [blame] | 5955 | u32 val; |
| 5956 | int err; |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 5957 | struct brcmu_chan ch; |
| 5958 | u32 num_chan; |
| 5959 | int i, j; |
Arend van Spriel | aa70b4f | 2014-07-12 08:49:40 +0200 | [diff] [blame] | 5960 | |
| 5961 | /* verify support for bw_cap command */ |
| 5962 | val = WLC_BAND_5G; |
| 5963 | err = brcmf_fil_iovar_int_get(ifp, "bw_cap", &val); |
| 5964 | |
| 5965 | if (!err) { |
| 5966 | /* only set 2G bandwidth using bw_cap command */ |
| 5967 | band_bwcap.band = cpu_to_le32(WLC_BAND_2G); |
| 5968 | band_bwcap.bw_cap = cpu_to_le32(WLC_BW_CAP_40MHZ); |
| 5969 | err = brcmf_fil_iovar_data_set(ifp, "bw_cap", &band_bwcap, |
| 5970 | sizeof(band_bwcap)); |
| 5971 | } else { |
| 5972 | brcmf_dbg(INFO, "fallback to mimo_bw_cap\n"); |
| 5973 | val = WLC_N_BW_40ALL; |
| 5974 | err = brcmf_fil_iovar_int_set(ifp, "mimo_bw_cap", val); |
| 5975 | } |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 5976 | |
| 5977 | if (!err) { |
| 5978 | /* update channel info in 2G band */ |
| 5979 | pbuf = kzalloc(BRCMF_DCMD_MEDLEN, GFP_KERNEL); |
| 5980 | |
| 5981 | if (pbuf == NULL) |
| 5982 | return -ENOMEM; |
| 5983 | |
| 5984 | ch.band = BRCMU_CHAN_BAND_2G; |
| 5985 | ch.bw = BRCMU_CHAN_BW_40; |
Hante Meuleman | fac7d2a | 2014-09-11 22:51:30 +0200 | [diff] [blame] | 5986 | ch.sb = BRCMU_CHAN_SB_NONE; |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 5987 | ch.chnum = 0; |
| 5988 | cfg->d11inf.encchspec(&ch); |
| 5989 | |
| 5990 | /* pass encoded chanspec in query */ |
| 5991 | *(__le16 *)pbuf = cpu_to_le16(ch.chspec); |
| 5992 | |
| 5993 | err = brcmf_fil_iovar_data_get(ifp, "chanspecs", pbuf, |
| 5994 | BRCMF_DCMD_MEDLEN); |
| 5995 | if (err) { |
| 5996 | brcmf_err("get chanspecs error (%d)\n", err); |
| 5997 | kfree(pbuf); |
| 5998 | return err; |
| 5999 | } |
| 6000 | |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 6001 | band = cfg_to_wiphy(cfg)->bands[NL80211_BAND_2GHZ]; |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 6002 | list = (struct brcmf_chanspec_list *)pbuf; |
| 6003 | num_chan = le32_to_cpu(list->count); |
| 6004 | for (i = 0; i < num_chan; i++) { |
| 6005 | ch.chspec = (u16)le32_to_cpu(list->element[i]); |
| 6006 | cfg->d11inf.decchspec(&ch); |
| 6007 | if (WARN_ON(ch.band != BRCMU_CHAN_BAND_2G)) |
| 6008 | continue; |
| 6009 | if (WARN_ON(ch.bw != BRCMU_CHAN_BW_40)) |
| 6010 | continue; |
| 6011 | for (j = 0; j < band->n_channels; j++) { |
Rafał Miłecki | 4712d88 | 2016-05-20 13:38:57 +0200 | [diff] [blame] | 6012 | if (band->channels[j].hw_value == ch.control_ch_num) |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 6013 | break; |
| 6014 | } |
| 6015 | if (WARN_ON(j == band->n_channels)) |
| 6016 | continue; |
| 6017 | |
| 6018 | brcmf_update_bw40_channel_flag(&band->channels[j], &ch); |
| 6019 | } |
Hante Meuleman | fac7d2a | 2014-09-11 22:51:30 +0200 | [diff] [blame] | 6020 | kfree(pbuf); |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 6021 | } |
Arend van Spriel | aa70b4f | 2014-07-12 08:49:40 +0200 | [diff] [blame] | 6022 | return err; |
| 6023 | } |
| 6024 | |
Arend van Spriel | 2375d97 | 2014-01-06 12:40:41 +0100 | [diff] [blame] | 6025 | static void brcmf_get_bwcap(struct brcmf_if *ifp, u32 bw_cap[]) |
| 6026 | { |
| 6027 | u32 band, mimo_bwcap; |
| 6028 | int err; |
| 6029 | |
| 6030 | band = WLC_BAND_2G; |
| 6031 | err = brcmf_fil_iovar_int_get(ifp, "bw_cap", &band); |
| 6032 | if (!err) { |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 6033 | bw_cap[NL80211_BAND_2GHZ] = band; |
Arend van Spriel | 2375d97 | 2014-01-06 12:40:41 +0100 | [diff] [blame] | 6034 | band = WLC_BAND_5G; |
| 6035 | err = brcmf_fil_iovar_int_get(ifp, "bw_cap", &band); |
| 6036 | if (!err) { |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 6037 | bw_cap[NL80211_BAND_5GHZ] = band; |
Arend van Spriel | 2375d97 | 2014-01-06 12:40:41 +0100 | [diff] [blame] | 6038 | return; |
| 6039 | } |
| 6040 | WARN_ON(1); |
| 6041 | return; |
| 6042 | } |
| 6043 | brcmf_dbg(INFO, "fallback to mimo_bw_cap info\n"); |
| 6044 | mimo_bwcap = 0; |
| 6045 | err = brcmf_fil_iovar_int_get(ifp, "mimo_bw_cap", &mimo_bwcap); |
| 6046 | if (err) |
| 6047 | /* assume 20MHz if firmware does not give a clue */ |
| 6048 | mimo_bwcap = WLC_N_BW_20ALL; |
| 6049 | |
| 6050 | switch (mimo_bwcap) { |
| 6051 | case WLC_N_BW_40ALL: |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 6052 | bw_cap[NL80211_BAND_2GHZ] |= WLC_BW_40MHZ_BIT; |
Arend van Spriel | 2375d97 | 2014-01-06 12:40:41 +0100 | [diff] [blame] | 6053 | /* fall-thru */ |
| 6054 | case WLC_N_BW_20IN2G_40IN5G: |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 6055 | bw_cap[NL80211_BAND_5GHZ] |= WLC_BW_40MHZ_BIT; |
Arend van Spriel | 2375d97 | 2014-01-06 12:40:41 +0100 | [diff] [blame] | 6056 | /* fall-thru */ |
| 6057 | case WLC_N_BW_20ALL: |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 6058 | bw_cap[NL80211_BAND_2GHZ] |= WLC_BW_20MHZ_BIT; |
| 6059 | bw_cap[NL80211_BAND_5GHZ] |= WLC_BW_20MHZ_BIT; |
Arend van Spriel | 2375d97 | 2014-01-06 12:40:41 +0100 | [diff] [blame] | 6060 | break; |
| 6061 | default: |
| 6062 | brcmf_err("invalid mimo_bw_cap value\n"); |
| 6063 | } |
| 6064 | } |
Hante Meuleman | d48200b | 2013-04-03 12:40:29 +0200 | [diff] [blame] | 6065 | |
Arend van Spriel | 18d6c53 | 2014-05-12 10:47:35 +0200 | [diff] [blame] | 6066 | static void brcmf_update_ht_cap(struct ieee80211_supported_band *band, |
| 6067 | u32 bw_cap[2], u32 nchain) |
| 6068 | { |
| 6069 | band->ht_cap.ht_supported = true; |
| 6070 | if (bw_cap[band->band] & WLC_BW_40MHZ_BIT) { |
| 6071 | band->ht_cap.cap |= IEEE80211_HT_CAP_SGI_40; |
| 6072 | band->ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40; |
| 6073 | } |
| 6074 | band->ht_cap.cap |= IEEE80211_HT_CAP_SGI_20; |
| 6075 | band->ht_cap.cap |= IEEE80211_HT_CAP_DSSSCCK40; |
| 6076 | band->ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K; |
| 6077 | band->ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_16; |
| 6078 | memset(band->ht_cap.mcs.rx_mask, 0xff, nchain); |
| 6079 | band->ht_cap.mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED; |
| 6080 | } |
| 6081 | |
| 6082 | static __le16 brcmf_get_mcs_map(u32 nchain, enum ieee80211_vht_mcs_support supp) |
| 6083 | { |
| 6084 | u16 mcs_map; |
| 6085 | int i; |
| 6086 | |
| 6087 | for (i = 0, mcs_map = 0xFFFF; i < nchain; i++) |
| 6088 | mcs_map = (mcs_map << 2) | supp; |
| 6089 | |
| 6090 | return cpu_to_le16(mcs_map); |
| 6091 | } |
| 6092 | |
| 6093 | static void brcmf_update_vht_cap(struct ieee80211_supported_band *band, |
Hante Meuleman | 7bf65aa | 2015-11-25 11:32:43 +0100 | [diff] [blame] | 6094 | u32 bw_cap[2], u32 nchain, u32 txstreams, |
| 6095 | u32 txbf_bfe_cap, u32 txbf_bfr_cap) |
Arend van Spriel | 18d6c53 | 2014-05-12 10:47:35 +0200 | [diff] [blame] | 6096 | { |
| 6097 | __le16 mcs_map; |
| 6098 | |
| 6099 | /* not allowed in 2.4G band */ |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 6100 | if (band->band == NL80211_BAND_2GHZ) |
Arend van Spriel | 18d6c53 | 2014-05-12 10:47:35 +0200 | [diff] [blame] | 6101 | return; |
| 6102 | |
| 6103 | band->vht_cap.vht_supported = true; |
| 6104 | /* 80MHz is mandatory */ |
| 6105 | band->vht_cap.cap |= IEEE80211_VHT_CAP_SHORT_GI_80; |
| 6106 | if (bw_cap[band->band] & WLC_BW_160MHZ_BIT) { |
| 6107 | band->vht_cap.cap |= IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ; |
| 6108 | band->vht_cap.cap |= IEEE80211_VHT_CAP_SHORT_GI_160; |
| 6109 | } |
| 6110 | /* all support 256-QAM */ |
| 6111 | mcs_map = brcmf_get_mcs_map(nchain, IEEE80211_VHT_MCS_SUPPORT_0_9); |
| 6112 | band->vht_cap.vht_mcs.rx_mcs_map = mcs_map; |
| 6113 | band->vht_cap.vht_mcs.tx_mcs_map = mcs_map; |
Hante Meuleman | 7bf65aa | 2015-11-25 11:32:43 +0100 | [diff] [blame] | 6114 | |
| 6115 | /* Beamforming support information */ |
| 6116 | if (txbf_bfe_cap & BRCMF_TXBF_SU_BFE_CAP) |
| 6117 | band->vht_cap.cap |= IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE; |
| 6118 | if (txbf_bfe_cap & BRCMF_TXBF_MU_BFE_CAP) |
| 6119 | band->vht_cap.cap |= IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE; |
| 6120 | if (txbf_bfr_cap & BRCMF_TXBF_SU_BFR_CAP) |
| 6121 | band->vht_cap.cap |= IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE; |
| 6122 | if (txbf_bfr_cap & BRCMF_TXBF_MU_BFR_CAP) |
| 6123 | band->vht_cap.cap |= IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE; |
| 6124 | |
| 6125 | if ((txbf_bfe_cap || txbf_bfr_cap) && (txstreams > 1)) { |
| 6126 | band->vht_cap.cap |= |
| 6127 | (2 << IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT); |
| 6128 | band->vht_cap.cap |= ((txstreams - 1) << |
| 6129 | IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT); |
| 6130 | band->vht_cap.cap |= |
| 6131 | IEEE80211_VHT_CAP_VHT_LINK_ADAPTATION_VHT_MRQ_MFB; |
| 6132 | } |
Arend van Spriel | 18d6c53 | 2014-05-12 10:47:35 +0200 | [diff] [blame] | 6133 | } |
| 6134 | |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 6135 | static int brcmf_setup_wiphybands(struct wiphy *wiphy) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 6136 | { |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 6137 | struct brcmf_cfg80211_info *cfg = wiphy_priv(wiphy); |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 6138 | struct brcmf_if *ifp = netdev_priv(cfg_to_ndev(cfg)); |
Arend van Spriel | 18d6c53 | 2014-05-12 10:47:35 +0200 | [diff] [blame] | 6139 | u32 nmode = 0; |
| 6140 | u32 vhtmode = 0; |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 6141 | u32 bw_cap[2] = { WLC_BW_20MHZ_BIT, WLC_BW_20MHZ_BIT }; |
Daniel Kim | 4aca7a1 | 2014-02-25 20:30:36 +0100 | [diff] [blame] | 6142 | u32 rxchain; |
| 6143 | u32 nchain; |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 6144 | int err; |
Hante Meuleman | d48200b | 2013-04-03 12:40:29 +0200 | [diff] [blame] | 6145 | s32 i; |
Arend van Spriel | 2375d97 | 2014-01-06 12:40:41 +0100 | [diff] [blame] | 6146 | struct ieee80211_supported_band *band; |
Hante Meuleman | 7bf65aa | 2015-11-25 11:32:43 +0100 | [diff] [blame] | 6147 | u32 txstreams = 0; |
| 6148 | u32 txbf_bfe_cap = 0; |
| 6149 | u32 txbf_bfr_cap = 0; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 6150 | |
Arend van Spriel | 18d6c53 | 2014-05-12 10:47:35 +0200 | [diff] [blame] | 6151 | (void)brcmf_fil_iovar_int_get(ifp, "vhtmode", &vhtmode); |
Hante Meuleman | d48200b | 2013-04-03 12:40:29 +0200 | [diff] [blame] | 6152 | err = brcmf_fil_iovar_int_get(ifp, "nmode", &nmode); |
| 6153 | if (err) { |
| 6154 | brcmf_err("nmode error (%d)\n", err); |
| 6155 | } else { |
Arend van Spriel | 2375d97 | 2014-01-06 12:40:41 +0100 | [diff] [blame] | 6156 | brcmf_get_bwcap(ifp, bw_cap); |
Hante Meuleman | d48200b | 2013-04-03 12:40:29 +0200 | [diff] [blame] | 6157 | } |
Arend van Spriel | 18d6c53 | 2014-05-12 10:47:35 +0200 | [diff] [blame] | 6158 | brcmf_dbg(INFO, "nmode=%d, vhtmode=%d, bw_cap=(%d, %d)\n", |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 6159 | nmode, vhtmode, bw_cap[NL80211_BAND_2GHZ], |
| 6160 | bw_cap[NL80211_BAND_5GHZ]); |
Hante Meuleman | d48200b | 2013-04-03 12:40:29 +0200 | [diff] [blame] | 6161 | |
Daniel Kim | 4aca7a1 | 2014-02-25 20:30:36 +0100 | [diff] [blame] | 6162 | err = brcmf_fil_iovar_int_get(ifp, "rxchain", &rxchain); |
| 6163 | if (err) { |
| 6164 | brcmf_err("rxchain error (%d)\n", err); |
| 6165 | nchain = 1; |
| 6166 | } else { |
| 6167 | for (nchain = 0; rxchain; nchain++) |
| 6168 | rxchain = rxchain & (rxchain - 1); |
| 6169 | } |
| 6170 | brcmf_dbg(INFO, "nchain=%d\n", nchain); |
| 6171 | |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 6172 | err = brcmf_construct_chaninfo(cfg, bw_cap); |
Hante Meuleman | d48200b | 2013-04-03 12:40:29 +0200 | [diff] [blame] | 6173 | if (err) { |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 6174 | brcmf_err("brcmf_construct_chaninfo failed (%d)\n", err); |
Hante Meuleman | d48200b | 2013-04-03 12:40:29 +0200 | [diff] [blame] | 6175 | return err; |
| 6176 | } |
| 6177 | |
Hante Meuleman | 7bf65aa | 2015-11-25 11:32:43 +0100 | [diff] [blame] | 6178 | if (vhtmode) { |
| 6179 | (void)brcmf_fil_iovar_int_get(ifp, "txstreams", &txstreams); |
| 6180 | (void)brcmf_fil_iovar_int_get(ifp, "txbf_bfe_cap", |
| 6181 | &txbf_bfe_cap); |
| 6182 | (void)brcmf_fil_iovar_int_get(ifp, "txbf_bfr_cap", |
| 6183 | &txbf_bfr_cap); |
| 6184 | } |
| 6185 | |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 6186 | wiphy = cfg_to_wiphy(cfg); |
| 6187 | for (i = 0; i < ARRAY_SIZE(wiphy->bands); i++) { |
| 6188 | band = wiphy->bands[i]; |
| 6189 | if (band == NULL) |
Arend van Spriel | 2375d97 | 2014-01-06 12:40:41 +0100 | [diff] [blame] | 6190 | continue; |
Hante Meuleman | d48200b | 2013-04-03 12:40:29 +0200 | [diff] [blame] | 6191 | |
Arend van Spriel | 18d6c53 | 2014-05-12 10:47:35 +0200 | [diff] [blame] | 6192 | if (nmode) |
| 6193 | brcmf_update_ht_cap(band, bw_cap, nchain); |
| 6194 | if (vhtmode) |
Hante Meuleman | 7bf65aa | 2015-11-25 11:32:43 +0100 | [diff] [blame] | 6195 | brcmf_update_vht_cap(band, bw_cap, nchain, txstreams, |
| 6196 | txbf_bfe_cap, txbf_bfr_cap); |
Hante Meuleman | d48200b | 2013-04-03 12:40:29 +0200 | [diff] [blame] | 6197 | } |
| 6198 | |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 6199 | return 0; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 6200 | } |
| 6201 | |
Arend van Spriel | aa70b4f | 2014-07-12 08:49:40 +0200 | [diff] [blame] | 6202 | static const struct ieee80211_txrx_stypes |
| 6203 | brcmf_txrx_stypes[NUM_NL80211_IFTYPES] = { |
| 6204 | [NL80211_IFTYPE_STATION] = { |
| 6205 | .tx = 0xffff, |
| 6206 | .rx = BIT(IEEE80211_STYPE_ACTION >> 4) | |
| 6207 | BIT(IEEE80211_STYPE_PROBE_REQ >> 4) |
| 6208 | }, |
| 6209 | [NL80211_IFTYPE_P2P_CLIENT] = { |
| 6210 | .tx = 0xffff, |
| 6211 | .rx = BIT(IEEE80211_STYPE_ACTION >> 4) | |
| 6212 | BIT(IEEE80211_STYPE_PROBE_REQ >> 4) |
| 6213 | }, |
| 6214 | [NL80211_IFTYPE_P2P_GO] = { |
| 6215 | .tx = 0xffff, |
| 6216 | .rx = BIT(IEEE80211_STYPE_ASSOC_REQ >> 4) | |
| 6217 | BIT(IEEE80211_STYPE_REASSOC_REQ >> 4) | |
| 6218 | BIT(IEEE80211_STYPE_PROBE_REQ >> 4) | |
| 6219 | BIT(IEEE80211_STYPE_DISASSOC >> 4) | |
| 6220 | BIT(IEEE80211_STYPE_AUTH >> 4) | |
| 6221 | BIT(IEEE80211_STYPE_DEAUTH >> 4) | |
| 6222 | BIT(IEEE80211_STYPE_ACTION >> 4) |
| 6223 | }, |
| 6224 | [NL80211_IFTYPE_P2P_DEVICE] = { |
| 6225 | .tx = 0xffff, |
| 6226 | .rx = BIT(IEEE80211_STYPE_ACTION >> 4) | |
| 6227 | BIT(IEEE80211_STYPE_PROBE_REQ >> 4) |
| 6228 | } |
| 6229 | }; |
| 6230 | |
Arend van Spriel | 0882dda | 2015-08-20 22:06:03 +0200 | [diff] [blame] | 6231 | /** |
| 6232 | * brcmf_setup_ifmodes() - determine interface modes and combinations. |
| 6233 | * |
| 6234 | * @wiphy: wiphy object. |
| 6235 | * @ifp: interface object needed for feat module api. |
| 6236 | * |
| 6237 | * The interface modes and combinations are determined dynamically here |
| 6238 | * based on firmware functionality. |
| 6239 | * |
| 6240 | * no p2p and no mbss: |
| 6241 | * |
| 6242 | * #STA <= 1, #AP <= 1, channels = 1, 2 total |
| 6243 | * |
| 6244 | * no p2p and mbss: |
| 6245 | * |
| 6246 | * #STA <= 1, #AP <= 1, channels = 1, 2 total |
| 6247 | * #AP <= 4, matching BI, channels = 1, 4 total |
| 6248 | * |
| 6249 | * p2p, no mchan, and mbss: |
| 6250 | * |
| 6251 | * #STA <= 1, #P2P-DEV <= 1, #{P2P-CL, P2P-GO} <= 1, channels = 1, 3 total |
| 6252 | * #STA <= 1, #P2P-DEV <= 1, #AP <= 1, #P2P-CL <= 1, channels = 1, 4 total |
| 6253 | * #AP <= 4, matching BI, channels = 1, 4 total |
| 6254 | * |
| 6255 | * p2p, mchan, and mbss: |
| 6256 | * |
| 6257 | * #STA <= 1, #P2P-DEV <= 1, #{P2P-CL, P2P-GO} <= 1, channels = 2, 3 total |
| 6258 | * #STA <= 1, #P2P-DEV <= 1, #AP <= 1, #P2P-CL <= 1, channels = 1, 4 total |
| 6259 | * #AP <= 4, matching BI, channels = 1, 4 total |
| 6260 | */ |
Pontus Fuchs | 2e5f66f | 2015-06-11 00:12:18 +0200 | [diff] [blame] | 6261 | static int brcmf_setup_ifmodes(struct wiphy *wiphy, struct brcmf_if *ifp) |
| 6262 | { |
| 6263 | struct ieee80211_iface_combination *combo = NULL; |
Arend van Spriel | 0882dda | 2015-08-20 22:06:03 +0200 | [diff] [blame] | 6264 | struct ieee80211_iface_limit *c0_limits = NULL; |
| 6265 | struct ieee80211_iface_limit *p2p_limits = NULL; |
| 6266 | struct ieee80211_iface_limit *mbss_limits = NULL; |
| 6267 | bool mbss, p2p; |
| 6268 | int i, c, n_combos; |
Pontus Fuchs | 2e5f66f | 2015-06-11 00:12:18 +0200 | [diff] [blame] | 6269 | |
Arend van Spriel | 0882dda | 2015-08-20 22:06:03 +0200 | [diff] [blame] | 6270 | mbss = brcmf_feat_is_enabled(ifp, BRCMF_FEAT_MBSS); |
| 6271 | p2p = brcmf_feat_is_enabled(ifp, BRCMF_FEAT_P2P); |
| 6272 | |
| 6273 | n_combos = 1 + !!p2p + !!mbss; |
| 6274 | combo = kcalloc(n_combos, sizeof(*combo), GFP_KERNEL); |
Pontus Fuchs | 2e5f66f | 2015-06-11 00:12:18 +0200 | [diff] [blame] | 6275 | if (!combo) |
| 6276 | goto err; |
| 6277 | |
Pontus Fuchs | 2e5f66f | 2015-06-11 00:12:18 +0200 | [diff] [blame] | 6278 | wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) | |
| 6279 | BIT(NL80211_IFTYPE_ADHOC) | |
| 6280 | BIT(NL80211_IFTYPE_AP); |
| 6281 | |
Arend van Spriel | 0882dda | 2015-08-20 22:06:03 +0200 | [diff] [blame] | 6282 | c = 0; |
| 6283 | i = 0; |
Rafał Miłecki | f568ada | 2016-06-07 21:10:18 +0200 | [diff] [blame] | 6284 | c0_limits = kcalloc(p2p ? 3 : 2, sizeof(*c0_limits), GFP_KERNEL); |
| 6285 | if (!c0_limits) |
| 6286 | goto err; |
Arend van Spriel | 0882dda | 2015-08-20 22:06:03 +0200 | [diff] [blame] | 6287 | c0_limits[i].max = 1; |
| 6288 | c0_limits[i++].types = BIT(NL80211_IFTYPE_STATION); |
| 6289 | if (p2p) { |
| 6290 | if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_MCHAN)) |
| 6291 | combo[c].num_different_channels = 2; |
Pontus Fuchs | 2e5f66f | 2015-06-11 00:12:18 +0200 | [diff] [blame] | 6292 | wiphy->interface_modes |= BIT(NL80211_IFTYPE_P2P_CLIENT) | |
| 6293 | BIT(NL80211_IFTYPE_P2P_GO) | |
| 6294 | BIT(NL80211_IFTYPE_P2P_DEVICE); |
Arend van Spriel | 0882dda | 2015-08-20 22:06:03 +0200 | [diff] [blame] | 6295 | c0_limits[i].max = 1; |
| 6296 | c0_limits[i++].types = BIT(NL80211_IFTYPE_P2P_DEVICE); |
| 6297 | c0_limits[i].max = 1; |
| 6298 | c0_limits[i++].types = BIT(NL80211_IFTYPE_P2P_CLIENT) | |
| 6299 | BIT(NL80211_IFTYPE_P2P_GO); |
| 6300 | } else { |
| 6301 | c0_limits[i].max = 1; |
| 6302 | c0_limits[i++].types = BIT(NL80211_IFTYPE_AP); |
Pontus Fuchs | 2e5f66f | 2015-06-11 00:12:18 +0200 | [diff] [blame] | 6303 | } |
Rafał Miłecki | f568ada | 2016-06-07 21:10:18 +0200 | [diff] [blame] | 6304 | combo[c].num_different_channels = 1; |
Arend van Spriel | 0882dda | 2015-08-20 22:06:03 +0200 | [diff] [blame] | 6305 | combo[c].max_interfaces = i; |
| 6306 | combo[c].n_limits = i; |
| 6307 | combo[c].limits = c0_limits; |
Pontus Fuchs | 2e5f66f | 2015-06-11 00:12:18 +0200 | [diff] [blame] | 6308 | |
Arend van Spriel | 0882dda | 2015-08-20 22:06:03 +0200 | [diff] [blame] | 6309 | if (p2p) { |
| 6310 | c++; |
| 6311 | i = 0; |
Rafał Miłecki | f568ada | 2016-06-07 21:10:18 +0200 | [diff] [blame] | 6312 | p2p_limits = kcalloc(4, sizeof(*p2p_limits), GFP_KERNEL); |
| 6313 | if (!p2p_limits) |
| 6314 | goto err; |
Arend van Spriel | 0882dda | 2015-08-20 22:06:03 +0200 | [diff] [blame] | 6315 | p2p_limits[i].max = 1; |
| 6316 | p2p_limits[i++].types = BIT(NL80211_IFTYPE_STATION); |
| 6317 | p2p_limits[i].max = 1; |
| 6318 | p2p_limits[i++].types = BIT(NL80211_IFTYPE_AP); |
| 6319 | p2p_limits[i].max = 1; |
| 6320 | p2p_limits[i++].types = BIT(NL80211_IFTYPE_P2P_CLIENT); |
| 6321 | p2p_limits[i].max = 1; |
| 6322 | p2p_limits[i++].types = BIT(NL80211_IFTYPE_P2P_DEVICE); |
Rafał Miłecki | f568ada | 2016-06-07 21:10:18 +0200 | [diff] [blame] | 6323 | combo[c].num_different_channels = 1; |
Arend van Spriel | 0882dda | 2015-08-20 22:06:03 +0200 | [diff] [blame] | 6324 | combo[c].max_interfaces = i; |
| 6325 | combo[c].n_limits = i; |
| 6326 | combo[c].limits = p2p_limits; |
| 6327 | } |
| 6328 | |
| 6329 | if (mbss) { |
| 6330 | c++; |
Rafał Miłecki | f568ada | 2016-06-07 21:10:18 +0200 | [diff] [blame] | 6331 | i = 0; |
| 6332 | mbss_limits = kcalloc(1, sizeof(*mbss_limits), GFP_KERNEL); |
| 6333 | if (!mbss_limits) |
| 6334 | goto err; |
| 6335 | mbss_limits[i].max = 4; |
| 6336 | mbss_limits[i++].types = BIT(NL80211_IFTYPE_AP); |
Arend van Spriel | 0882dda | 2015-08-20 22:06:03 +0200 | [diff] [blame] | 6337 | combo[c].beacon_int_infra_match = true; |
| 6338 | combo[c].num_different_channels = 1; |
Arend van Spriel | 0882dda | 2015-08-20 22:06:03 +0200 | [diff] [blame] | 6339 | combo[c].max_interfaces = 4; |
Rafał Miłecki | f568ada | 2016-06-07 21:10:18 +0200 | [diff] [blame] | 6340 | combo[c].n_limits = i; |
Arend van Spriel | 0882dda | 2015-08-20 22:06:03 +0200 | [diff] [blame] | 6341 | combo[c].limits = mbss_limits; |
| 6342 | } |
Rafał Miłecki | f568ada | 2016-06-07 21:10:18 +0200 | [diff] [blame] | 6343 | |
Arend van Spriel | 0882dda | 2015-08-20 22:06:03 +0200 | [diff] [blame] | 6344 | wiphy->n_iface_combinations = n_combos; |
Pontus Fuchs | 2e5f66f | 2015-06-11 00:12:18 +0200 | [diff] [blame] | 6345 | wiphy->iface_combinations = combo; |
Pontus Fuchs | 2e5f66f | 2015-06-11 00:12:18 +0200 | [diff] [blame] | 6346 | return 0; |
| 6347 | |
| 6348 | err: |
Arend van Spriel | 0882dda | 2015-08-20 22:06:03 +0200 | [diff] [blame] | 6349 | kfree(c0_limits); |
| 6350 | kfree(p2p_limits); |
| 6351 | kfree(mbss_limits); |
Pontus Fuchs | 2e5f66f | 2015-06-11 00:12:18 +0200 | [diff] [blame] | 6352 | kfree(combo); |
| 6353 | return -ENOMEM; |
| 6354 | } |
| 6355 | |
Arend van Spriel | aa70b4f | 2014-07-12 08:49:40 +0200 | [diff] [blame] | 6356 | static void brcmf_wiphy_pno_params(struct wiphy *wiphy) |
| 6357 | { |
| 6358 | /* scheduled scan settings */ |
| 6359 | wiphy->max_sched_scan_ssids = BRCMF_PNO_MAX_PFN_COUNT; |
| 6360 | wiphy->max_match_sets = BRCMF_PNO_MAX_PFN_COUNT; |
| 6361 | wiphy->max_sched_scan_ie_len = BRCMF_SCAN_IE_LEN_MAX; |
Arend Van Spriel | c6989fd | 2016-11-23 10:25:30 +0000 | [diff] [blame] | 6362 | 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] | 6363 | wiphy->flags |= WIPHY_FLAG_SUPPORTS_SCHED_SCAN; |
| 6364 | } |
| 6365 | |
Hante Meuleman | 4eb3af7 | 2014-09-30 10:23:18 +0200 | [diff] [blame] | 6366 | #ifdef CONFIG_PM |
Arend Van Spriel | 0b57010 | 2017-01-27 12:27:47 +0000 | [diff] [blame] | 6367 | static const struct wiphy_wowlan_support brcmf_wowlan_support = { |
Hante Meuleman | 4eb3af7 | 2014-09-30 10:23:18 +0200 | [diff] [blame] | 6368 | .flags = WIPHY_WOWLAN_MAGIC_PKT | WIPHY_WOWLAN_DISCONNECT, |
Hante Meuleman | b9a82f8 | 2014-10-28 14:56:06 +0100 | [diff] [blame] | 6369 | .n_patterns = BRCMF_WOWL_MAXPATTERNS, |
| 6370 | .pattern_max_len = BRCMF_WOWL_MAXPATTERNSIZE, |
| 6371 | .pattern_min_len = 1, |
| 6372 | .max_pkt_offset = 1500, |
Hante Meuleman | 4eb3af7 | 2014-09-30 10:23:18 +0200 | [diff] [blame] | 6373 | }; |
| 6374 | #endif |
| 6375 | |
Hante Meuleman | 3021ad9 | 2016-01-05 11:05:45 +0100 | [diff] [blame] | 6376 | 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] | 6377 | { |
| 6378 | #ifdef CONFIG_PM |
Hante Meuleman | 3021ad9 | 2016-01-05 11:05:45 +0100 | [diff] [blame] | 6379 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); |
Arend Van Spriel | 0b57010 | 2017-01-27 12:27:47 +0000 | [diff] [blame] | 6380 | struct wiphy_wowlan_support *wowl; |
| 6381 | |
| 6382 | wowl = kmemdup(&brcmf_wowlan_support, sizeof(brcmf_wowlan_support), |
| 6383 | GFP_KERNEL); |
| 6384 | if (!wowl) { |
| 6385 | brcmf_err("only support basic wowlan features\n"); |
| 6386 | wiphy->wowlan = &brcmf_wowlan_support; |
| 6387 | return; |
| 6388 | } |
Hante Meuleman | 3021ad9 | 2016-01-05 11:05:45 +0100 | [diff] [blame] | 6389 | |
| 6390 | if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_PNO)) { |
Hante Meuleman | 5c22fb8 | 2016-02-17 11:27:03 +0100 | [diff] [blame] | 6391 | if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_WOWL_ND)) { |
Arend Van Spriel | 0b57010 | 2017-01-27 12:27:47 +0000 | [diff] [blame] | 6392 | wowl->flags |= WIPHY_WOWLAN_NET_DETECT; |
| 6393 | wowl->max_nd_match_sets = BRCMF_PNO_MAX_PFN_COUNT; |
Hante Meuleman | 5c22fb8 | 2016-02-17 11:27:03 +0100 | [diff] [blame] | 6394 | init_waitqueue_head(&cfg->wowl.nd_data_wait); |
Hante Meuleman | 3021ad9 | 2016-01-05 11:05:45 +0100 | [diff] [blame] | 6395 | } |
| 6396 | } |
Hante Meuleman | 5c22fb8 | 2016-02-17 11:27:03 +0100 | [diff] [blame] | 6397 | if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_WOWL_GTK)) { |
Arend Van Spriel | 0b57010 | 2017-01-27 12:27:47 +0000 | [diff] [blame] | 6398 | wowl->flags |= WIPHY_WOWLAN_SUPPORTS_GTK_REKEY; |
| 6399 | wowl->flags |= WIPHY_WOWLAN_GTK_REKEY_FAILURE; |
Hante Meuleman | 5c22fb8 | 2016-02-17 11:27:03 +0100 | [diff] [blame] | 6400 | } |
| 6401 | |
Arend Van Spriel | 0b57010 | 2017-01-27 12:27:47 +0000 | [diff] [blame] | 6402 | wiphy->wowlan = wowl; |
Hante Meuleman | 4eb3af7 | 2014-09-30 10:23:18 +0200 | [diff] [blame] | 6403 | #endif |
| 6404 | } |
| 6405 | |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 6406 | 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] | 6407 | { |
Rafa? Mi?ecki | e3faa86 | 2015-07-09 17:07:08 +0200 | [diff] [blame] | 6408 | struct brcmf_pub *drvr = ifp->drvr; |
Rafał Miłecki | 50f32e2 | 2015-08-20 00:16:42 +0200 | [diff] [blame] | 6409 | const struct ieee80211_iface_combination *combo; |
Arend van Spriel | 58de92d | 2015-04-14 20:10:24 +0200 | [diff] [blame] | 6410 | struct ieee80211_supported_band *band; |
Rafał Miłecki | 50f32e2 | 2015-08-20 00:16:42 +0200 | [diff] [blame] | 6411 | u16 max_interfaces = 0; |
Arend van Spriel | 58de92d | 2015-04-14 20:10:24 +0200 | [diff] [blame] | 6412 | __le32 bandlist[3]; |
| 6413 | u32 n_bands; |
| 6414 | int err, i; |
| 6415 | |
Arend van Spriel | aa70b4f | 2014-07-12 08:49:40 +0200 | [diff] [blame] | 6416 | wiphy->max_scan_ssids = WL_NUM_SCAN_MAX; |
| 6417 | wiphy->max_scan_ie_len = BRCMF_SCAN_IE_LEN_MAX; |
Hante Meuleman | 6c404f3 | 2015-12-10 13:43:03 +0100 | [diff] [blame] | 6418 | wiphy->max_num_pmkids = BRCMF_MAXPMKID; |
Pontus Fuchs | 2e5f66f | 2015-06-11 00:12:18 +0200 | [diff] [blame] | 6419 | |
| 6420 | err = brcmf_setup_ifmodes(wiphy, ifp); |
| 6421 | if (err) |
| 6422 | return err; |
| 6423 | |
Rafał Miłecki | 50f32e2 | 2015-08-20 00:16:42 +0200 | [diff] [blame] | 6424 | for (i = 0, combo = wiphy->iface_combinations; |
| 6425 | i < wiphy->n_iface_combinations; i++, combo++) { |
| 6426 | max_interfaces = max(max_interfaces, combo->max_interfaces); |
| 6427 | } |
| 6428 | |
| 6429 | for (i = 0; i < max_interfaces && i < ARRAY_SIZE(drvr->addresses); |
| 6430 | i++) { |
Rafa? Mi?ecki | e3faa86 | 2015-07-09 17:07:08 +0200 | [diff] [blame] | 6431 | u8 *addr = drvr->addresses[i].addr; |
| 6432 | |
| 6433 | memcpy(addr, drvr->mac, ETH_ALEN); |
| 6434 | if (i) { |
| 6435 | addr[0] |= BIT(1); |
| 6436 | addr[ETH_ALEN - 1] ^= i; |
| 6437 | } |
| 6438 | } |
| 6439 | wiphy->addresses = drvr->addresses; |
| 6440 | wiphy->n_addresses = i; |
| 6441 | |
Arend van Spriel | aa70b4f | 2014-07-12 08:49:40 +0200 | [diff] [blame] | 6442 | wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM; |
Hante Meuleman | 240d61a | 2016-02-17 11:27:10 +0100 | [diff] [blame] | 6443 | wiphy->cipher_suites = brcmf_cipher_suites; |
| 6444 | wiphy->n_cipher_suites = ARRAY_SIZE(brcmf_cipher_suites); |
| 6445 | if (!brcmf_feat_is_enabled(ifp, BRCMF_FEAT_MFP)) |
| 6446 | wiphy->n_cipher_suites--; |
Arend van Spriel | 7705ba6 | 2016-04-17 16:44:58 +0200 | [diff] [blame] | 6447 | wiphy->bss_select_support = BIT(NL80211_BSS_SELECT_ATTR_RSSI) | |
| 6448 | BIT(NL80211_BSS_SELECT_ATTR_BAND_PREF) | |
| 6449 | BIT(NL80211_BSS_SELECT_ATTR_RSSI_ADJUST); |
| 6450 | |
Arend van Spriel | aa70b4f | 2014-07-12 08:49:40 +0200 | [diff] [blame] | 6451 | wiphy->flags |= WIPHY_FLAG_PS_ON_BY_DEFAULT | |
| 6452 | WIPHY_FLAG_OFFCHAN_TX | |
Hante Meuleman | a7b82d4 | 2015-12-10 13:43:04 +0100 | [diff] [blame] | 6453 | WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL; |
| 6454 | if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_TDLS)) |
| 6455 | wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS; |
Hante Meuleman | 7d34b05 | 2016-01-02 09:41:41 +0100 | [diff] [blame] | 6456 | if (!ifp->drvr->settings->roamoff) |
Arend van Spriel | aa70b4f | 2014-07-12 08:49:40 +0200 | [diff] [blame] | 6457 | wiphy->flags |= WIPHY_FLAG_SUPPORTS_FW_ROAM; |
| 6458 | wiphy->mgmt_stypes = brcmf_txrx_stypes; |
| 6459 | wiphy->max_remain_on_channel_duration = 5000; |
Arend van Spriel | 7a7a87d | 2015-04-14 20:10:27 +0200 | [diff] [blame] | 6460 | if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_PNO)) |
| 6461 | brcmf_wiphy_pno_params(wiphy); |
Arend van Spriel | aa70b4f | 2014-07-12 08:49:40 +0200 | [diff] [blame] | 6462 | |
| 6463 | /* vendor commands/events support */ |
| 6464 | wiphy->vendor_commands = brcmf_vendor_cmds; |
| 6465 | wiphy->n_vendor_commands = BRCMF_VNDR_CMDS_LAST - 1; |
| 6466 | |
Hante Meuleman | 4eb3af7 | 2014-09-30 10:23:18 +0200 | [diff] [blame] | 6467 | if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_WOWL)) |
Hante Meuleman | 3021ad9 | 2016-01-05 11:05:45 +0100 | [diff] [blame] | 6468 | brcmf_wiphy_wowl_params(wiphy, ifp); |
Arend van Spriel | 58de92d | 2015-04-14 20:10:24 +0200 | [diff] [blame] | 6469 | err = brcmf_fil_cmd_data_get(ifp, BRCMF_C_GET_BANDLIST, &bandlist, |
| 6470 | sizeof(bandlist)); |
| 6471 | if (err) { |
| 6472 | brcmf_err("could not obtain band info: err=%d\n", err); |
| 6473 | return err; |
| 6474 | } |
| 6475 | /* first entry in bandlist is number of bands */ |
| 6476 | n_bands = le32_to_cpu(bandlist[0]); |
| 6477 | for (i = 1; i <= n_bands && i < ARRAY_SIZE(bandlist); i++) { |
| 6478 | if (bandlist[i] == cpu_to_le32(WLC_BAND_2G)) { |
| 6479 | band = kmemdup(&__wl_band_2ghz, sizeof(__wl_band_2ghz), |
| 6480 | GFP_KERNEL); |
| 6481 | if (!band) |
| 6482 | return -ENOMEM; |
| 6483 | |
| 6484 | band->channels = kmemdup(&__wl_2ghz_channels, |
| 6485 | sizeof(__wl_2ghz_channels), |
| 6486 | GFP_KERNEL); |
| 6487 | if (!band->channels) { |
| 6488 | kfree(band); |
| 6489 | return -ENOMEM; |
| 6490 | } |
| 6491 | |
| 6492 | band->n_channels = ARRAY_SIZE(__wl_2ghz_channels); |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 6493 | wiphy->bands[NL80211_BAND_2GHZ] = band; |
Arend van Spriel | 58de92d | 2015-04-14 20:10:24 +0200 | [diff] [blame] | 6494 | } |
| 6495 | if (bandlist[i] == cpu_to_le32(WLC_BAND_5G)) { |
| 6496 | band = kmemdup(&__wl_band_5ghz, sizeof(__wl_band_5ghz), |
| 6497 | GFP_KERNEL); |
| 6498 | if (!band) |
| 6499 | return -ENOMEM; |
| 6500 | |
| 6501 | band->channels = kmemdup(&__wl_5ghz_channels, |
| 6502 | sizeof(__wl_5ghz_channels), |
| 6503 | GFP_KERNEL); |
| 6504 | if (!band->channels) { |
| 6505 | kfree(band); |
| 6506 | return -ENOMEM; |
| 6507 | } |
| 6508 | |
| 6509 | band->n_channels = ARRAY_SIZE(__wl_5ghz_channels); |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 6510 | wiphy->bands[NL80211_BAND_5GHZ] = band; |
Arend van Spriel | 58de92d | 2015-04-14 20:10:24 +0200 | [diff] [blame] | 6511 | } |
| 6512 | } |
Rafał Miłecki | 0f83ff6 | 2017-01-17 23:35:50 +0100 | [diff] [blame] | 6513 | |
| 6514 | wiphy_read_of_freq_limits(wiphy); |
| 6515 | |
Rafał Miłecki | ab99063 | 2017-01-07 21:36:05 +0100 | [diff] [blame] | 6516 | return 0; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 6517 | } |
| 6518 | |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 6519 | static s32 brcmf_config_dongle(struct brcmf_cfg80211_info *cfg) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 6520 | { |
| 6521 | struct net_device *ndev; |
| 6522 | struct wireless_dev *wdev; |
Hante Meuleman | 40a2329 | 2013-01-02 15:22:51 +0100 | [diff] [blame] | 6523 | struct brcmf_if *ifp; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 6524 | s32 power_mode; |
| 6525 | s32 err = 0; |
| 6526 | |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 6527 | if (cfg->dongle_up) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 6528 | return err; |
| 6529 | |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 6530 | ndev = cfg_to_ndev(cfg); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 6531 | wdev = ndev->ieee80211_ptr; |
Hante Meuleman | 40a2329 | 2013-01-02 15:22:51 +0100 | [diff] [blame] | 6532 | ifp = netdev_priv(ndev); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 6533 | |
Hante Meuleman | 40a2329 | 2013-01-02 15:22:51 +0100 | [diff] [blame] | 6534 | /* make sure RF is ready for work */ |
| 6535 | brcmf_fil_cmd_int_set(ifp, BRCMF_C_UP, 0); |
| 6536 | |
Hante Meuleman | 1678ba8 | 2015-12-10 13:43:00 +0100 | [diff] [blame] | 6537 | brcmf_dongle_scantime(ifp); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 6538 | |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 6539 | power_mode = cfg->pwr_save ? PM_FAST : PM_OFF; |
Hante Meuleman | 40a2329 | 2013-01-02 15:22:51 +0100 | [diff] [blame] | 6540 | 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] | 6541 | if (err) |
| 6542 | goto default_conf_out; |
Arend van Spriel | 647c9ae | 2012-12-05 15:26:01 +0100 | [diff] [blame] | 6543 | brcmf_dbg(INFO, "power save set to %s\n", |
| 6544 | (power_mode ? "enabled" : "disabled")); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 6545 | |
Hante Meuleman | 1119e23 | 2015-11-25 11:32:42 +0100 | [diff] [blame] | 6546 | err = brcmf_dongle_roam(ifp); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 6547 | if (err) |
| 6548 | goto default_conf_out; |
Franky Lin | 5dd161f | 2012-10-10 11:13:10 -0700 | [diff] [blame] | 6549 | err = brcmf_cfg80211_change_iface(wdev->wiphy, ndev, wdev->iftype, |
Johannes Berg | 818a986 | 2017-04-12 11:23:28 +0200 | [diff] [blame^] | 6550 | NULL); |
Hante Meuleman | 40a2329 | 2013-01-02 15:22:51 +0100 | [diff] [blame] | 6551 | if (err) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 6552 | goto default_conf_out; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 6553 | |
Franky Lin | 52f22fb | 2016-02-17 11:26:55 +0100 | [diff] [blame] | 6554 | brcmf_configure_arp_nd_offload(ifp, true); |
Hante Meuleman | b365745 | 2013-05-27 21:09:53 +0200 | [diff] [blame] | 6555 | |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 6556 | cfg->dongle_up = true; |
Hante Meuleman | 40a2329 | 2013-01-02 15:22:51 +0100 | [diff] [blame] | 6557 | default_conf_out: |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 6558 | |
| 6559 | return err; |
| 6560 | |
| 6561 | } |
| 6562 | |
Arend van Spriel | bdf5ff5 | 2012-11-14 18:46:09 -0800 | [diff] [blame] | 6563 | static s32 __brcmf_cfg80211_up(struct brcmf_if *ifp) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 6564 | { |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 6565 | set_bit(BRCMF_VIF_STATUS_READY, &ifp->vif->sme_state); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 6566 | |
Arend van Spriel | bdf5ff5 | 2012-11-14 18:46:09 -0800 | [diff] [blame] | 6567 | return brcmf_config_dongle(ifp->drvr->config); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 6568 | } |
| 6569 | |
Arend van Spriel | bdf5ff5 | 2012-11-14 18:46:09 -0800 | [diff] [blame] | 6570 | static s32 __brcmf_cfg80211_down(struct brcmf_if *ifp) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 6571 | { |
Arend van Spriel | bdf5ff5 | 2012-11-14 18:46:09 -0800 | [diff] [blame] | 6572 | struct brcmf_cfg80211_info *cfg = ifp->drvr->config; |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 6573 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 6574 | /* |
| 6575 | * While going down, if associated with AP disassociate |
| 6576 | * from AP to save power |
| 6577 | */ |
Arend van Spriel | 903e0ee | 2012-11-28 21:44:11 +0100 | [diff] [blame] | 6578 | if (check_vif_up(ifp->vif)) { |
Arend van Spriel | 9b7a0dd | 2015-01-25 20:31:33 +0100 | [diff] [blame] | 6579 | brcmf_link_down(ifp->vif, WLAN_REASON_UNSPECIFIED); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 6580 | |
| 6581 | /* Make sure WPA_Supplicant receives all the event |
| 6582 | generated due to DISASSOC call to the fw to keep |
| 6583 | the state fw and WPA_Supplicant state consistent |
| 6584 | */ |
| 6585 | brcmf_delay(500); |
| 6586 | } |
| 6587 | |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 6588 | brcmf_abort_scanning(cfg); |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 6589 | clear_bit(BRCMF_VIF_STATUS_READY, &ifp->vif->sme_state); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 6590 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 6591 | return 0; |
| 6592 | } |
| 6593 | |
Arend van Spriel | bdf5ff5 | 2012-11-14 18:46:09 -0800 | [diff] [blame] | 6594 | s32 brcmf_cfg80211_up(struct net_device *ndev) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 6595 | { |
Arend van Spriel | bdf5ff5 | 2012-11-14 18:46:09 -0800 | [diff] [blame] | 6596 | struct brcmf_if *ifp = netdev_priv(ndev); |
| 6597 | struct brcmf_cfg80211_info *cfg = ifp->drvr->config; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 6598 | s32 err = 0; |
| 6599 | |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 6600 | mutex_lock(&cfg->usr_sync); |
Arend van Spriel | bdf5ff5 | 2012-11-14 18:46:09 -0800 | [diff] [blame] | 6601 | err = __brcmf_cfg80211_up(ifp); |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 6602 | mutex_unlock(&cfg->usr_sync); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 6603 | |
| 6604 | return err; |
| 6605 | } |
| 6606 | |
Arend van Spriel | bdf5ff5 | 2012-11-14 18:46:09 -0800 | [diff] [blame] | 6607 | s32 brcmf_cfg80211_down(struct net_device *ndev) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 6608 | { |
Arend van Spriel | bdf5ff5 | 2012-11-14 18:46:09 -0800 | [diff] [blame] | 6609 | struct brcmf_if *ifp = netdev_priv(ndev); |
| 6610 | struct brcmf_cfg80211_info *cfg = ifp->drvr->config; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 6611 | s32 err = 0; |
| 6612 | |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 6613 | mutex_lock(&cfg->usr_sync); |
Arend van Spriel | bdf5ff5 | 2012-11-14 18:46:09 -0800 | [diff] [blame] | 6614 | err = __brcmf_cfg80211_down(ifp); |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 6615 | mutex_unlock(&cfg->usr_sync); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 6616 | |
| 6617 | return err; |
| 6618 | } |
| 6619 | |
Arend van Spriel | a7965fb | 2013-04-11 17:08:37 +0200 | [diff] [blame] | 6620 | enum nl80211_iftype brcmf_cfg80211_get_iftype(struct brcmf_if *ifp) |
| 6621 | { |
| 6622 | struct wireless_dev *wdev = &ifp->vif->wdev; |
| 6623 | |
| 6624 | return wdev->iftype; |
| 6625 | } |
| 6626 | |
Hante Meuleman | bfe8197 | 2014-10-28 14:56:16 +0100 | [diff] [blame] | 6627 | bool brcmf_get_vif_state_any(struct brcmf_cfg80211_info *cfg, |
| 6628 | unsigned long state) |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 6629 | { |
| 6630 | struct brcmf_cfg80211_vif *vif; |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 6631 | |
| 6632 | list_for_each_entry(vif, &cfg->vif_list, list) { |
| 6633 | if (test_bit(state, &vif->sme_state)) |
Rasmus Villemoes | e843bb1 | 2014-06-22 20:50:40 +0200 | [diff] [blame] | 6634 | return true; |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 6635 | } |
Rasmus Villemoes | e843bb1 | 2014-06-22 20:50:40 +0200 | [diff] [blame] | 6636 | return false; |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 6637 | } |
Arend van Spriel | d3c0b63 | 2013-02-08 15:53:37 +0100 | [diff] [blame] | 6638 | |
| 6639 | static inline bool vif_event_equals(struct brcmf_cfg80211_vif_event *event, |
| 6640 | u8 action) |
| 6641 | { |
| 6642 | u8 evt_action; |
| 6643 | |
mhiramat@kernel.org | b64abcb | 2016-08-15 18:41:12 +0900 | [diff] [blame] | 6644 | spin_lock(&event->vif_event_lock); |
Arend van Spriel | d3c0b63 | 2013-02-08 15:53:37 +0100 | [diff] [blame] | 6645 | evt_action = event->action; |
mhiramat@kernel.org | b64abcb | 2016-08-15 18:41:12 +0900 | [diff] [blame] | 6646 | spin_unlock(&event->vif_event_lock); |
Arend van Spriel | d3c0b63 | 2013-02-08 15:53:37 +0100 | [diff] [blame] | 6647 | return evt_action == action; |
| 6648 | } |
| 6649 | |
| 6650 | void brcmf_cfg80211_arm_vif_event(struct brcmf_cfg80211_info *cfg, |
| 6651 | struct brcmf_cfg80211_vif *vif) |
| 6652 | { |
| 6653 | struct brcmf_cfg80211_vif_event *event = &cfg->vif_event; |
| 6654 | |
mhiramat@kernel.org | b64abcb | 2016-08-15 18:41:12 +0900 | [diff] [blame] | 6655 | spin_lock(&event->vif_event_lock); |
Arend van Spriel | d3c0b63 | 2013-02-08 15:53:37 +0100 | [diff] [blame] | 6656 | event->vif = vif; |
| 6657 | event->action = 0; |
mhiramat@kernel.org | b64abcb | 2016-08-15 18:41:12 +0900 | [diff] [blame] | 6658 | spin_unlock(&event->vif_event_lock); |
Arend van Spriel | d3c0b63 | 2013-02-08 15:53:37 +0100 | [diff] [blame] | 6659 | } |
| 6660 | |
| 6661 | bool brcmf_cfg80211_vif_event_armed(struct brcmf_cfg80211_info *cfg) |
| 6662 | { |
| 6663 | struct brcmf_cfg80211_vif_event *event = &cfg->vif_event; |
| 6664 | bool armed; |
| 6665 | |
mhiramat@kernel.org | b64abcb | 2016-08-15 18:41:12 +0900 | [diff] [blame] | 6666 | spin_lock(&event->vif_event_lock); |
Arend van Spriel | d3c0b63 | 2013-02-08 15:53:37 +0100 | [diff] [blame] | 6667 | armed = event->vif != NULL; |
mhiramat@kernel.org | b64abcb | 2016-08-15 18:41:12 +0900 | [diff] [blame] | 6668 | spin_unlock(&event->vif_event_lock); |
Arend van Spriel | d3c0b63 | 2013-02-08 15:53:37 +0100 | [diff] [blame] | 6669 | |
| 6670 | return armed; |
| 6671 | } |
Arend van Spriel | a9eb0c4 | 2016-02-17 11:26:50 +0100 | [diff] [blame] | 6672 | |
| 6673 | int brcmf_cfg80211_wait_vif_event(struct brcmf_cfg80211_info *cfg, |
| 6674 | u8 action, ulong timeout) |
Arend van Spriel | d3c0b63 | 2013-02-08 15:53:37 +0100 | [diff] [blame] | 6675 | { |
| 6676 | struct brcmf_cfg80211_vif_event *event = &cfg->vif_event; |
| 6677 | |
| 6678 | return wait_event_timeout(event->vif_wq, |
| 6679 | vif_event_equals(event, action), timeout); |
| 6680 | } |
| 6681 | |
Hante Meuleman | 73345fd | 2016-02-17 11:26:53 +0100 | [diff] [blame] | 6682 | static s32 brcmf_translate_country_code(struct brcmf_pub *drvr, char alpha2[2], |
| 6683 | struct brcmf_fil_country_le *ccreq) |
| 6684 | { |
Hante Meuleman | 4d79289 | 2016-02-17 11:27:07 +0100 | [diff] [blame] | 6685 | struct brcmfmac_pd_cc *country_codes; |
| 6686 | struct brcmfmac_pd_cc_entry *cc; |
Hante Meuleman | 73345fd | 2016-02-17 11:26:53 +0100 | [diff] [blame] | 6687 | s32 found_index; |
| 6688 | int i; |
| 6689 | |
| 6690 | country_codes = drvr->settings->country_codes; |
| 6691 | if (!country_codes) { |
| 6692 | brcmf_dbg(TRACE, "No country codes configured for device\n"); |
| 6693 | return -EINVAL; |
| 6694 | } |
| 6695 | |
| 6696 | if ((alpha2[0] == ccreq->country_abbrev[0]) && |
| 6697 | (alpha2[1] == ccreq->country_abbrev[1])) { |
| 6698 | brcmf_dbg(TRACE, "Country code already set\n"); |
| 6699 | return -EAGAIN; |
| 6700 | } |
| 6701 | |
| 6702 | found_index = -1; |
| 6703 | for (i = 0; i < country_codes->table_size; i++) { |
| 6704 | cc = &country_codes->table[i]; |
| 6705 | if ((cc->iso3166[0] == '\0') && (found_index == -1)) |
| 6706 | found_index = i; |
| 6707 | if ((cc->iso3166[0] == alpha2[0]) && |
| 6708 | (cc->iso3166[1] == alpha2[1])) { |
| 6709 | found_index = i; |
| 6710 | break; |
| 6711 | } |
| 6712 | } |
| 6713 | if (found_index == -1) { |
| 6714 | brcmf_dbg(TRACE, "No country code match found\n"); |
| 6715 | return -EINVAL; |
| 6716 | } |
| 6717 | memset(ccreq, 0, sizeof(*ccreq)); |
| 6718 | ccreq->rev = cpu_to_le32(country_codes->table[found_index].rev); |
| 6719 | memcpy(ccreq->ccode, country_codes->table[found_index].cc, |
| 6720 | BRCMF_COUNTRY_BUF_SZ); |
| 6721 | ccreq->country_abbrev[0] = alpha2[0]; |
| 6722 | ccreq->country_abbrev[1] = alpha2[1]; |
| 6723 | ccreq->country_abbrev[2] = 0; |
| 6724 | |
| 6725 | return 0; |
| 6726 | } |
| 6727 | |
Arend van Spriel | 63db1a4 | 2014-12-21 12:43:51 +0100 | [diff] [blame] | 6728 | static void brcmf_cfg80211_reg_notifier(struct wiphy *wiphy, |
| 6729 | struct regulatory_request *req) |
| 6730 | { |
| 6731 | struct brcmf_cfg80211_info *cfg = wiphy_priv(wiphy); |
| 6732 | struct brcmf_if *ifp = netdev_priv(cfg_to_ndev(cfg)); |
| 6733 | struct brcmf_fil_country_le ccreq; |
Hante Meuleman | 73345fd | 2016-02-17 11:26:53 +0100 | [diff] [blame] | 6734 | s32 err; |
Arend van Spriel | 63db1a4 | 2014-12-21 12:43:51 +0100 | [diff] [blame] | 6735 | int i; |
| 6736 | |
Arend van Spriel | 63db1a4 | 2014-12-21 12:43:51 +0100 | [diff] [blame] | 6737 | /* ignore non-ISO3166 country codes */ |
| 6738 | for (i = 0; i < sizeof(req->alpha2); i++) |
| 6739 | if (req->alpha2[i] < 'A' || req->alpha2[i] > 'Z') { |
Hante Meuleman | 73345fd | 2016-02-17 11:26:53 +0100 | [diff] [blame] | 6740 | brcmf_err("not a ISO3166 code (0x%02x 0x%02x)\n", |
| 6741 | req->alpha2[0], req->alpha2[1]); |
Arend van Spriel | 63db1a4 | 2014-12-21 12:43:51 +0100 | [diff] [blame] | 6742 | return; |
| 6743 | } |
Hante Meuleman | 73345fd | 2016-02-17 11:26:53 +0100 | [diff] [blame] | 6744 | |
| 6745 | brcmf_dbg(TRACE, "Enter: initiator=%d, alpha=%c%c\n", req->initiator, |
| 6746 | req->alpha2[0], req->alpha2[1]); |
| 6747 | |
| 6748 | err = brcmf_fil_iovar_data_get(ifp, "country", &ccreq, sizeof(ccreq)); |
| 6749 | if (err) { |
| 6750 | brcmf_err("Country code iovar returned err = %d\n", err); |
| 6751 | return; |
| 6752 | } |
| 6753 | |
| 6754 | err = brcmf_translate_country_code(ifp->drvr, req->alpha2, &ccreq); |
| 6755 | if (err) |
| 6756 | return; |
| 6757 | |
| 6758 | err = brcmf_fil_iovar_data_set(ifp, "country", &ccreq, sizeof(ccreq)); |
| 6759 | if (err) { |
| 6760 | brcmf_err("Firmware rejected country setting\n"); |
Arend van Spriel | 8afe0ec | 2015-04-14 20:10:25 +0200 | [diff] [blame] | 6761 | return; |
| 6762 | } |
| 6763 | brcmf_setup_wiphybands(wiphy); |
Arend van Spriel | 63db1a4 | 2014-12-21 12:43:51 +0100 | [diff] [blame] | 6764 | } |
| 6765 | |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 6766 | static void brcmf_free_wiphy(struct wiphy *wiphy) |
| 6767 | { |
Arend van Spriel | 0882dda | 2015-08-20 22:06:03 +0200 | [diff] [blame] | 6768 | int i; |
| 6769 | |
Arend van Spriel | 58de92d | 2015-04-14 20:10:24 +0200 | [diff] [blame] | 6770 | if (!wiphy) |
| 6771 | return; |
| 6772 | |
Arend van Spriel | 0882dda | 2015-08-20 22:06:03 +0200 | [diff] [blame] | 6773 | if (wiphy->iface_combinations) { |
| 6774 | for (i = 0; i < wiphy->n_iface_combinations; i++) |
| 6775 | kfree(wiphy->iface_combinations[i].limits); |
| 6776 | } |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 6777 | kfree(wiphy->iface_combinations); |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 6778 | if (wiphy->bands[NL80211_BAND_2GHZ]) { |
| 6779 | kfree(wiphy->bands[NL80211_BAND_2GHZ]->channels); |
| 6780 | kfree(wiphy->bands[NL80211_BAND_2GHZ]); |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 6781 | } |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 6782 | if (wiphy->bands[NL80211_BAND_5GHZ]) { |
| 6783 | kfree(wiphy->bands[NL80211_BAND_5GHZ]->channels); |
| 6784 | kfree(wiphy->bands[NL80211_BAND_5GHZ]); |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 6785 | } |
Arend Van Spriel | 0b57010 | 2017-01-27 12:27:47 +0000 | [diff] [blame] | 6786 | #if IS_ENABLED(CONFIG_PM) |
| 6787 | if (wiphy->wowlan != &brcmf_wowlan_support) |
| 6788 | kfree(wiphy->wowlan); |
| 6789 | #endif |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 6790 | wiphy_free(wiphy); |
| 6791 | } |
| 6792 | |
Arend van Spriel | ccfd1e8 | 2014-07-12 08:49:38 +0200 | [diff] [blame] | 6793 | struct brcmf_cfg80211_info *brcmf_cfg80211_attach(struct brcmf_pub *drvr, |
Hante Meuleman | ae7c03f | 2015-09-18 22:08:08 +0200 | [diff] [blame] | 6794 | struct device *busdev, |
| 6795 | bool p2pdev_forced) |
Arend van Spriel | ccfd1e8 | 2014-07-12 08:49:38 +0200 | [diff] [blame] | 6796 | { |
Arend van Spriel | 46f3b6e | 2015-08-26 22:14:58 +0200 | [diff] [blame] | 6797 | struct net_device *ndev = brcmf_get_ifp(drvr, 0)->ndev; |
Arend van Spriel | ccfd1e8 | 2014-07-12 08:49:38 +0200 | [diff] [blame] | 6798 | struct brcmf_cfg80211_info *cfg; |
| 6799 | struct wiphy *wiphy; |
Hante Meuleman | 5c22fb8 | 2016-02-17 11:27:03 +0100 | [diff] [blame] | 6800 | struct cfg80211_ops *ops; |
Arend van Spriel | ccfd1e8 | 2014-07-12 08:49:38 +0200 | [diff] [blame] | 6801 | struct brcmf_cfg80211_vif *vif; |
| 6802 | struct brcmf_if *ifp; |
| 6803 | s32 err = 0; |
| 6804 | s32 io_type; |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 6805 | u16 *cap = NULL; |
Arend van Spriel | ccfd1e8 | 2014-07-12 08:49:38 +0200 | [diff] [blame] | 6806 | |
| 6807 | if (!ndev) { |
| 6808 | brcmf_err("ndev is invalid\n"); |
| 6809 | return NULL; |
| 6810 | } |
| 6811 | |
Muhammad Falak R Wani | d464fd8 | 2016-05-19 19:29:03 +0530 | [diff] [blame] | 6812 | ops = kmemdup(&brcmf_cfg80211_ops, sizeof(*ops), GFP_KERNEL); |
Hante Meuleman | 5c22fb8 | 2016-02-17 11:27:03 +0100 | [diff] [blame] | 6813 | if (!ops) |
| 6814 | return NULL; |
| 6815 | |
Arend van Spriel | ccfd1e8 | 2014-07-12 08:49:38 +0200 | [diff] [blame] | 6816 | ifp = netdev_priv(ndev); |
Hante Meuleman | 5c22fb8 | 2016-02-17 11:27:03 +0100 | [diff] [blame] | 6817 | #ifdef CONFIG_PM |
| 6818 | if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_WOWL_GTK)) |
| 6819 | ops->set_rekey_data = brcmf_cfg80211_set_rekey_data; |
| 6820 | #endif |
| 6821 | wiphy = wiphy_new(ops, sizeof(struct brcmf_cfg80211_info)); |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 6822 | if (!wiphy) { |
| 6823 | brcmf_err("Could not allocate wiphy device\n"); |
Arend van Spriel | ccfd1e8 | 2014-07-12 08:49:38 +0200 | [diff] [blame] | 6824 | return NULL; |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 6825 | } |
Rafał Miłecki | 6896f4f | 2015-05-31 02:52:26 +0200 | [diff] [blame] | 6826 | memcpy(wiphy->perm_addr, drvr->mac, ETH_ALEN); |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 6827 | set_wiphy_dev(wiphy, busdev); |
Arend van Spriel | ccfd1e8 | 2014-07-12 08:49:38 +0200 | [diff] [blame] | 6828 | |
| 6829 | cfg = wiphy_priv(wiphy); |
| 6830 | cfg->wiphy = wiphy; |
Hante Meuleman | 5c22fb8 | 2016-02-17 11:27:03 +0100 | [diff] [blame] | 6831 | cfg->ops = ops; |
Arend van Spriel | ccfd1e8 | 2014-07-12 08:49:38 +0200 | [diff] [blame] | 6832 | cfg->pub = drvr; |
| 6833 | init_vif_event(&cfg->vif_event); |
| 6834 | INIT_LIST_HEAD(&cfg->vif_list); |
| 6835 | |
Rafał Miłecki | 2607233 | 2016-06-06 23:03:55 +0200 | [diff] [blame] | 6836 | vif = brcmf_alloc_vif(cfg, NL80211_IFTYPE_STATION); |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 6837 | if (IS_ERR(vif)) |
| 6838 | goto wiphy_out; |
Arend van Spriel | ccfd1e8 | 2014-07-12 08:49:38 +0200 | [diff] [blame] | 6839 | |
| 6840 | vif->ifp = ifp; |
| 6841 | vif->wdev.netdev = ndev; |
| 6842 | ndev->ieee80211_ptr = &vif->wdev; |
| 6843 | SET_NETDEV_DEV(ndev, wiphy_dev(cfg->wiphy)); |
| 6844 | |
| 6845 | err = wl_init_priv(cfg); |
| 6846 | if (err) { |
| 6847 | brcmf_err("Failed to init iwm_priv (%d)\n", err); |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 6848 | brcmf_free_vif(vif); |
| 6849 | goto wiphy_out; |
Arend van Spriel | ccfd1e8 | 2014-07-12 08:49:38 +0200 | [diff] [blame] | 6850 | } |
| 6851 | ifp->vif = vif; |
| 6852 | |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 6853 | /* determine d11 io type before wiphy setup */ |
| 6854 | 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] | 6855 | if (err) { |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 6856 | brcmf_err("Failed to get D11 version (%d)\n", err); |
| 6857 | goto priv_out; |
Arend van Spriel | ccfd1e8 | 2014-07-12 08:49:38 +0200 | [diff] [blame] | 6858 | } |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 6859 | cfg->d11inf.io_type = (u8)io_type; |
| 6860 | brcmu_d11_attach(&cfg->d11inf); |
| 6861 | |
| 6862 | err = brcmf_setup_wiphy(wiphy, ifp); |
| 6863 | if (err < 0) |
| 6864 | goto priv_out; |
| 6865 | |
| 6866 | brcmf_dbg(INFO, "Registering custom regulatory\n"); |
Arend van Spriel | 63db1a4 | 2014-12-21 12:43:51 +0100 | [diff] [blame] | 6867 | wiphy->reg_notifier = brcmf_cfg80211_reg_notifier; |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 6868 | wiphy->regulatory_flags |= REGULATORY_CUSTOM_REG; |
| 6869 | wiphy_apply_custom_regulatory(wiphy, &brcmf_regdom); |
| 6870 | |
| 6871 | /* firmware defaults to 40MHz disabled in 2G band. We signal |
| 6872 | * cfg80211 here that we do and have it decide we can enable |
| 6873 | * it. But first check if device does support 2G operation. |
| 6874 | */ |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 6875 | if (wiphy->bands[NL80211_BAND_2GHZ]) { |
| 6876 | cap = &wiphy->bands[NL80211_BAND_2GHZ]->ht_cap.cap; |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 6877 | *cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40; |
| 6878 | } |
| 6879 | err = wiphy_register(wiphy); |
| 6880 | if (err < 0) { |
| 6881 | brcmf_err("Could not register wiphy device (%d)\n", err); |
| 6882 | goto priv_out; |
Arend van Spriel | ccfd1e8 | 2014-07-12 08:49:38 +0200 | [diff] [blame] | 6883 | } |
| 6884 | |
Rafał Miłecki | ab99063 | 2017-01-07 21:36:05 +0100 | [diff] [blame] | 6885 | err = brcmf_setup_wiphybands(wiphy); |
| 6886 | if (err) { |
| 6887 | brcmf_err("Setting wiphy bands failed (%d)\n", err); |
| 6888 | goto wiphy_unreg_out; |
| 6889 | } |
| 6890 | |
Arend van Spriel | ccfd1e8 | 2014-07-12 08:49:38 +0200 | [diff] [blame] | 6891 | /* If cfg80211 didn't disable 40MHz HT CAP in wiphy_register(), |
| 6892 | * setup 40MHz in 2GHz band and enable OBSS scanning. |
| 6893 | */ |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 6894 | if (cap && (*cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40)) { |
| 6895 | err = brcmf_enable_bw40_2g(cfg); |
Arend van Spriel | ccfd1e8 | 2014-07-12 08:49:38 +0200 | [diff] [blame] | 6896 | if (!err) |
| 6897 | err = brcmf_fil_iovar_int_set(ifp, "obss_coex", |
| 6898 | BRCMF_OBSS_COEX_AUTO); |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 6899 | else |
| 6900 | *cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40; |
Arend van Spriel | ccfd1e8 | 2014-07-12 08:49:38 +0200 | [diff] [blame] | 6901 | } |
Hante Meuleman | 2b76acd | 2015-10-08 20:33:15 +0200 | [diff] [blame] | 6902 | /* p2p might require that "if-events" get processed by fweh. So |
| 6903 | * activate the already registered event handlers now and activate |
| 6904 | * the rest when initialization has completed. drvr->config needs to |
| 6905 | * be assigned before activating events. |
| 6906 | */ |
| 6907 | drvr->config = cfg; |
| 6908 | err = brcmf_fweh_activate_events(ifp); |
| 6909 | if (err) { |
| 6910 | brcmf_err("FWEH activation failed (%d)\n", err); |
| 6911 | goto wiphy_unreg_out; |
| 6912 | } |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 6913 | |
Hante Meuleman | ae7c03f | 2015-09-18 22:08:08 +0200 | [diff] [blame] | 6914 | err = brcmf_p2p_attach(cfg, p2pdev_forced); |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 6915 | if (err) { |
Arend Van Spriel | cb853da | 2016-12-09 11:34:13 +0000 | [diff] [blame] | 6916 | brcmf_err("P2P initialisation failed (%d)\n", err); |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 6917 | goto wiphy_unreg_out; |
| 6918 | } |
| 6919 | err = brcmf_btcoex_attach(cfg); |
| 6920 | if (err) { |
| 6921 | brcmf_err("BT-coex initialisation failed (%d)\n", err); |
| 6922 | brcmf_p2p_detach(&cfg->p2p); |
| 6923 | goto wiphy_unreg_out; |
| 6924 | } |
Arend van Spriel | ccfd1e8 | 2014-07-12 08:49:38 +0200 | [diff] [blame] | 6925 | |
Hante Meuleman | a7b82d4 | 2015-12-10 13:43:04 +0100 | [diff] [blame] | 6926 | if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_TDLS)) { |
| 6927 | err = brcmf_fil_iovar_int_set(ifp, "tdls_enable", 1); |
| 6928 | if (err) { |
| 6929 | brcmf_dbg(INFO, "TDLS not enabled (%d)\n", err); |
| 6930 | wiphy->flags &= ~WIPHY_FLAG_SUPPORTS_TDLS; |
| 6931 | } else { |
| 6932 | brcmf_fweh_register(cfg->pub, BRCMF_E_TDLS_PEER_EVENT, |
| 6933 | brcmf_notify_tdls_peer_event); |
| 6934 | } |
Arend van Spriel | ccfd1e8 | 2014-07-12 08:49:38 +0200 | [diff] [blame] | 6935 | } |
| 6936 | |
Hante Meuleman | 2b76acd | 2015-10-08 20:33:15 +0200 | [diff] [blame] | 6937 | /* (re-) activate FWEH event handling */ |
| 6938 | err = brcmf_fweh_activate_events(ifp); |
| 6939 | if (err) { |
| 6940 | brcmf_err("FWEH activation failed (%d)\n", err); |
Arend Van Spriel | cb853da | 2016-12-09 11:34:13 +0000 | [diff] [blame] | 6941 | goto detach; |
Hante Meuleman | 2b76acd | 2015-10-08 20:33:15 +0200 | [diff] [blame] | 6942 | } |
| 6943 | |
Hante Meuleman | 48ed16e | 2016-01-02 09:41:38 +0100 | [diff] [blame] | 6944 | /* Fill in some of the advertised nl80211 supported features */ |
| 6945 | if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_SCAN_RANDOM_MAC)) { |
| 6946 | wiphy->features |= NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR; |
| 6947 | #ifdef CONFIG_PM |
Franky Lin | 6ea0915 | 2016-02-17 11:26:52 +0100 | [diff] [blame] | 6948 | if (wiphy->wowlan && |
| 6949 | wiphy->wowlan->flags & WIPHY_WOWLAN_NET_DETECT) |
Hante Meuleman | 48ed16e | 2016-01-02 09:41:38 +0100 | [diff] [blame] | 6950 | wiphy->features |= NL80211_FEATURE_ND_RANDOM_MAC_ADDR; |
| 6951 | #endif |
| 6952 | } |
| 6953 | |
Arend van Spriel | ccfd1e8 | 2014-07-12 08:49:38 +0200 | [diff] [blame] | 6954 | return cfg; |
| 6955 | |
Arend Van Spriel | cb853da | 2016-12-09 11:34:13 +0000 | [diff] [blame] | 6956 | detach: |
| 6957 | brcmf_btcoex_detach(cfg); |
| 6958 | brcmf_p2p_detach(&cfg->p2p); |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 6959 | wiphy_unreg_out: |
| 6960 | wiphy_unregister(cfg->wiphy); |
| 6961 | priv_out: |
Arend van Spriel | ccfd1e8 | 2014-07-12 08:49:38 +0200 | [diff] [blame] | 6962 | wl_deinit_priv(cfg); |
Arend van Spriel | ccfd1e8 | 2014-07-12 08:49:38 +0200 | [diff] [blame] | 6963 | brcmf_free_vif(vif); |
Hante Meuleman | 2b5d348 | 2015-09-18 22:08:04 +0200 | [diff] [blame] | 6964 | ifp->vif = NULL; |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 6965 | wiphy_out: |
| 6966 | brcmf_free_wiphy(wiphy); |
Hante Meuleman | 5c22fb8 | 2016-02-17 11:27:03 +0100 | [diff] [blame] | 6967 | kfree(ops); |
Arend van Spriel | ccfd1e8 | 2014-07-12 08:49:38 +0200 | [diff] [blame] | 6968 | return NULL; |
| 6969 | } |
| 6970 | |
| 6971 | void brcmf_cfg80211_detach(struct brcmf_cfg80211_info *cfg) |
| 6972 | { |
| 6973 | if (!cfg) |
| 6974 | return; |
| 6975 | |
Arend van Spriel | ccfd1e8 | 2014-07-12 08:49:38 +0200 | [diff] [blame] | 6976 | brcmf_btcoex_detach(cfg); |
Arend van Spriel | f7a4087 | 2015-06-11 00:12:23 +0200 | [diff] [blame] | 6977 | wiphy_unregister(cfg->wiphy); |
Hante Meuleman | 5c22fb8 | 2016-02-17 11:27:03 +0100 | [diff] [blame] | 6978 | kfree(cfg->ops); |
Arend van Spriel | ccfd1e8 | 2014-07-12 08:49:38 +0200 | [diff] [blame] | 6979 | wl_deinit_priv(cfg); |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 6980 | brcmf_free_wiphy(cfg->wiphy); |
Arend van Spriel | ccfd1e8 | 2014-07-12 08:49:38 +0200 | [diff] [blame] | 6981 | } |