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" |
Hante Meuleman | bfe8197 | 2014-10-28 14:56:16 +0100 | [diff] [blame] | 35 | #include "cfg80211.h" |
Arend van Spriel | c08437b | 2014-07-12 08:49:39 +0200 | [diff] [blame] | 36 | #include "feature.h" |
Hante Meuleman | 81f5dcb | 2012-10-22 10:36:14 -0700 | [diff] [blame] | 37 | #include "fwil.h" |
Hante Meuleman | 8851cce | 2014-07-30 13:20:02 +0200 | [diff] [blame] | 38 | #include "proto.h" |
Franky Lin | 1bacb04 | 2014-06-21 12:11:16 +0200 | [diff] [blame] | 39 | #include "vendor.h" |
Hante Meuleman | d14f78b | 2014-10-28 14:56:14 +0100 | [diff] [blame] | 40 | #include "bus.h" |
Hante Meuleman | 6b89dcb | 2014-12-21 12:43:52 +0100 | [diff] [blame] | 41 | #include "common.h" |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 42 | |
Arend van Spriel | e580607 | 2012-09-19 22:21:08 +0200 | [diff] [blame] | 43 | #define BRCMF_SCAN_IE_LEN_MAX 2048 |
| 44 | #define BRCMF_PNO_VERSION 2 |
| 45 | #define BRCMF_PNO_TIME 30 |
| 46 | #define BRCMF_PNO_REPEAT 4 |
| 47 | #define BRCMF_PNO_FREQ_EXPO_MAX 3 |
| 48 | #define BRCMF_PNO_MAX_PFN_COUNT 16 |
| 49 | #define BRCMF_PNO_ENABLE_ADAPTSCAN_BIT 6 |
| 50 | #define BRCMF_PNO_HIDDEN_BIT 2 |
| 51 | #define BRCMF_PNO_WPA_AUTH_ANY 0xFFFFFFFF |
| 52 | #define BRCMF_PNO_SCAN_COMPLETE 1 |
| 53 | #define BRCMF_PNO_SCAN_INCOMPLETE 0 |
| 54 | |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 55 | #define WPA_OUI "\x00\x50\xF2" /* WPA OUI */ |
| 56 | #define WPA_OUI_TYPE 1 |
| 57 | #define RSN_OUI "\x00\x0F\xAC" /* RSN OUI */ |
| 58 | #define WME_OUI_TYPE 2 |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 59 | #define WPS_OUI_TYPE 4 |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 60 | |
| 61 | #define VS_IE_FIXED_HDR_LEN 6 |
| 62 | #define WPA_IE_VERSION_LEN 2 |
| 63 | #define WPA_IE_MIN_OUI_LEN 4 |
| 64 | #define WPA_IE_SUITE_COUNT_LEN 2 |
| 65 | |
| 66 | #define WPA_CIPHER_NONE 0 /* None */ |
| 67 | #define WPA_CIPHER_WEP_40 1 /* WEP (40-bit) */ |
| 68 | #define WPA_CIPHER_TKIP 2 /* TKIP: default for WPA */ |
| 69 | #define WPA_CIPHER_AES_CCM 4 /* AES (CCM) */ |
| 70 | #define WPA_CIPHER_WEP_104 5 /* WEP (104-bit) */ |
| 71 | |
| 72 | #define RSN_AKM_NONE 0 /* None (IBSS) */ |
| 73 | #define RSN_AKM_UNSPECIFIED 1 /* Over 802.1x */ |
| 74 | #define RSN_AKM_PSK 2 /* Pre-shared Key */ |
Hante Meuleman | 240d61a | 2016-02-17 11:27:10 +0100 | [diff] [blame] | 75 | #define RSN_AKM_SHA256_1X 5 /* SHA256, 802.1X */ |
| 76 | #define RSN_AKM_SHA256_PSK 6 /* SHA256, Pre-shared Key */ |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 77 | #define RSN_CAP_LEN 2 /* Length of RSN capabilities */ |
Hante Meuleman | 240d61a | 2016-02-17 11:27:10 +0100 | [diff] [blame] | 78 | #define RSN_CAP_PTK_REPLAY_CNTR_MASK (BIT(2) | BIT(3)) |
| 79 | #define RSN_CAP_MFPR_MASK BIT(6) |
| 80 | #define RSN_CAP_MFPC_MASK BIT(7) |
| 81 | #define RSN_PMKID_COUNT_LEN 2 |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 82 | |
| 83 | #define VNDR_IE_CMD_LEN 4 /* length of the set command |
| 84 | * string :"add", "del" (+ NUL) |
| 85 | */ |
| 86 | #define VNDR_IE_COUNT_OFFSET 4 |
| 87 | #define VNDR_IE_PKTFLAG_OFFSET 8 |
| 88 | #define VNDR_IE_VSIE_OFFSET 12 |
| 89 | #define VNDR_IE_HDR_SIZE 12 |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 90 | #define VNDR_IE_PARSE_LIMIT 5 |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 91 | |
| 92 | #define DOT11_MGMT_HDR_LEN 24 /* d11 management header len */ |
| 93 | #define DOT11_BCN_PRB_FIXED_LEN 12 /* beacon/probe fixed length */ |
Hante Meuleman | 0401289 | 2012-09-27 14:17:49 +0200 | [diff] [blame] | 94 | |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 95 | #define BRCMF_SCAN_JOIN_ACTIVE_DWELL_TIME_MS 320 |
| 96 | #define BRCMF_SCAN_JOIN_PASSIVE_DWELL_TIME_MS 400 |
| 97 | #define BRCMF_SCAN_JOIN_PROBE_INTERVAL_MS 20 |
| 98 | |
Hante Meuleman | 1678ba8 | 2015-12-10 13:43:00 +0100 | [diff] [blame] | 99 | #define BRCMF_SCAN_CHANNEL_TIME 40 |
| 100 | #define BRCMF_SCAN_UNASSOC_TIME 40 |
| 101 | #define BRCMF_SCAN_PASSIVE_TIME 120 |
| 102 | |
Hante Meuleman | 3021ad9 | 2016-01-05 11:05:45 +0100 | [diff] [blame] | 103 | #define BRCMF_ND_INFO_TIMEOUT msecs_to_jiffies(2000) |
| 104 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 105 | #define BRCMF_ASSOC_PARAMS_FIXED_SIZE \ |
| 106 | (sizeof(struct brcmf_assoc_params_le) - sizeof(u16)) |
| 107 | |
Arend van Spriel | ce81e31 | 2012-10-22 13:55:37 -0700 | [diff] [blame] | 108 | static bool check_vif_up(struct brcmf_cfg80211_vif *vif) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 109 | { |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 110 | if (!test_bit(BRCMF_VIF_STATUS_READY, &vif->sme_state)) { |
Arend van Spriel | 647c9ae | 2012-12-05 15:26:01 +0100 | [diff] [blame] | 111 | brcmf_dbg(INFO, "device is not ready : status (%lu)\n", |
| 112 | vif->sme_state); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 113 | return false; |
| 114 | } |
| 115 | return true; |
| 116 | } |
| 117 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 118 | #define RATE_TO_BASE100KBPS(rate) (((rate) * 10) / 2) |
| 119 | #define RATETAB_ENT(_rateid, _flags) \ |
| 120 | { \ |
| 121 | .bitrate = RATE_TO_BASE100KBPS(_rateid), \ |
| 122 | .hw_value = (_rateid), \ |
| 123 | .flags = (_flags), \ |
| 124 | } |
| 125 | |
| 126 | static struct ieee80211_rate __wl_rates[] = { |
| 127 | RATETAB_ENT(BRCM_RATE_1M, 0), |
| 128 | RATETAB_ENT(BRCM_RATE_2M, IEEE80211_RATE_SHORT_PREAMBLE), |
| 129 | RATETAB_ENT(BRCM_RATE_5M5, IEEE80211_RATE_SHORT_PREAMBLE), |
| 130 | RATETAB_ENT(BRCM_RATE_11M, IEEE80211_RATE_SHORT_PREAMBLE), |
| 131 | RATETAB_ENT(BRCM_RATE_6M, 0), |
| 132 | RATETAB_ENT(BRCM_RATE_9M, 0), |
| 133 | RATETAB_ENT(BRCM_RATE_12M, 0), |
| 134 | RATETAB_ENT(BRCM_RATE_18M, 0), |
| 135 | RATETAB_ENT(BRCM_RATE_24M, 0), |
| 136 | RATETAB_ENT(BRCM_RATE_36M, 0), |
| 137 | RATETAB_ENT(BRCM_RATE_48M, 0), |
| 138 | RATETAB_ENT(BRCM_RATE_54M, 0), |
| 139 | }; |
| 140 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 141 | #define wl_g_rates (__wl_rates + 0) |
Arend van Spriel | 58de92d | 2015-04-14 20:10:24 +0200 | [diff] [blame] | 142 | #define wl_g_rates_size ARRAY_SIZE(__wl_rates) |
| 143 | #define wl_a_rates (__wl_rates + 4) |
| 144 | #define wl_a_rates_size (wl_g_rates_size - 4) |
| 145 | |
| 146 | #define CHAN2G(_channel, _freq) { \ |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 147 | .band = NL80211_BAND_2GHZ, \ |
Arend van Spriel | 58de92d | 2015-04-14 20:10:24 +0200 | [diff] [blame] | 148 | .center_freq = (_freq), \ |
| 149 | .hw_value = (_channel), \ |
| 150 | .flags = IEEE80211_CHAN_DISABLED, \ |
| 151 | .max_antenna_gain = 0, \ |
| 152 | .max_power = 30, \ |
| 153 | } |
| 154 | |
| 155 | #define CHAN5G(_channel) { \ |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 156 | .band = NL80211_BAND_5GHZ, \ |
Arend van Spriel | 58de92d | 2015-04-14 20:10:24 +0200 | [diff] [blame] | 157 | .center_freq = 5000 + (5 * (_channel)), \ |
| 158 | .hw_value = (_channel), \ |
| 159 | .flags = IEEE80211_CHAN_DISABLED, \ |
| 160 | .max_antenna_gain = 0, \ |
| 161 | .max_power = 30, \ |
| 162 | } |
| 163 | |
| 164 | static struct ieee80211_channel __wl_2ghz_channels[] = { |
| 165 | CHAN2G(1, 2412), CHAN2G(2, 2417), CHAN2G(3, 2422), CHAN2G(4, 2427), |
| 166 | CHAN2G(5, 2432), CHAN2G(6, 2437), CHAN2G(7, 2442), CHAN2G(8, 2447), |
| 167 | CHAN2G(9, 2452), CHAN2G(10, 2457), CHAN2G(11, 2462), CHAN2G(12, 2467), |
| 168 | CHAN2G(13, 2472), CHAN2G(14, 2484) |
| 169 | }; |
| 170 | |
| 171 | static struct ieee80211_channel __wl_5ghz_channels[] = { |
| 172 | CHAN5G(34), CHAN5G(36), CHAN5G(38), CHAN5G(40), CHAN5G(42), |
| 173 | CHAN5G(44), CHAN5G(46), CHAN5G(48), CHAN5G(52), CHAN5G(56), |
| 174 | CHAN5G(60), CHAN5G(64), CHAN5G(100), CHAN5G(104), CHAN5G(108), |
| 175 | CHAN5G(112), CHAN5G(116), CHAN5G(120), CHAN5G(124), CHAN5G(128), |
| 176 | CHAN5G(132), CHAN5G(136), CHAN5G(140), CHAN5G(144), CHAN5G(149), |
| 177 | CHAN5G(153), CHAN5G(157), CHAN5G(161), CHAN5G(165) |
| 178 | }; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 179 | |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 180 | /* Band templates duplicated per wiphy. The channel info |
Arend van Spriel | 58de92d | 2015-04-14 20:10:24 +0200 | [diff] [blame] | 181 | * above is added to the band during setup. |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 182 | */ |
| 183 | static const struct ieee80211_supported_band __wl_band_2ghz = { |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 184 | .band = NL80211_BAND_2GHZ, |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 185 | .bitrates = wl_g_rates, |
| 186 | .n_bitrates = wl_g_rates_size, |
| 187 | }; |
| 188 | |
Arend van Spriel | 58de92d | 2015-04-14 20:10:24 +0200 | [diff] [blame] | 189 | static const struct ieee80211_supported_band __wl_band_5ghz = { |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 190 | .band = NL80211_BAND_5GHZ, |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 191 | .bitrates = wl_a_rates, |
| 192 | .n_bitrates = wl_a_rates_size, |
| 193 | }; |
| 194 | |
Hante Meuleman | d48200b | 2013-04-03 12:40:29 +0200 | [diff] [blame] | 195 | /* This is to override regulatory domains defined in cfg80211 module (reg.c) |
| 196 | * 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] | 197 | * NL80211_RRF_NO_IR for 5GHz channels (for * 36..48 and 149..165). |
| 198 | * With respect to these flags, wpa_supplicant doesn't * start p2p |
| 199 | * operations on 5GHz channels. All the changes in world regulatory |
Hante Meuleman | d48200b | 2013-04-03 12:40:29 +0200 | [diff] [blame] | 200 | * domain are to be done here. |
| 201 | */ |
| 202 | static const struct ieee80211_regdomain brcmf_regdom = { |
| 203 | .n_reg_rules = 4, |
| 204 | .alpha2 = "99", |
| 205 | .reg_rules = { |
| 206 | /* IEEE 802.11b/g, channels 1..11 */ |
| 207 | REG_RULE(2412-10, 2472+10, 40, 6, 20, 0), |
| 208 | /* If any */ |
| 209 | /* IEEE 802.11 channel 14 - Only JP enables |
| 210 | * this and for 802.11b only |
| 211 | */ |
| 212 | REG_RULE(2484-10, 2484+10, 20, 6, 20, 0), |
| 213 | /* IEEE 802.11a, channel 36..64 */ |
Arend van Spriel | c555ecd | 2014-05-12 10:47:36 +0200 | [diff] [blame] | 214 | REG_RULE(5150-10, 5350+10, 80, 6, 20, 0), |
Hante Meuleman | d48200b | 2013-04-03 12:40:29 +0200 | [diff] [blame] | 215 | /* IEEE 802.11a, channel 100..165 */ |
Arend van Spriel | c555ecd | 2014-05-12 10:47:36 +0200 | [diff] [blame] | 216 | REG_RULE(5470-10, 5850+10, 80, 6, 20, 0), } |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 217 | }; |
| 218 | |
Hante Meuleman | 240d61a | 2016-02-17 11:27:10 +0100 | [diff] [blame] | 219 | /* Note: brcmf_cipher_suites is an array of int defining which cipher suites |
| 220 | * are supported. A pointer to this array and the number of entries is passed |
| 221 | * on to upper layers. AES_CMAC defines whether or not the driver supports MFP. |
| 222 | * So the cipher suite AES_CMAC has to be the last one in the array, and when |
| 223 | * device does not support MFP then the number of suites will be decreased by 1 |
| 224 | */ |
| 225 | static const u32 brcmf_cipher_suites[] = { |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 226 | WLAN_CIPHER_SUITE_WEP40, |
| 227 | WLAN_CIPHER_SUITE_WEP104, |
| 228 | WLAN_CIPHER_SUITE_TKIP, |
| 229 | WLAN_CIPHER_SUITE_CCMP, |
Hante Meuleman | 240d61a | 2016-02-17 11:27:10 +0100 | [diff] [blame] | 230 | /* Keep as last entry: */ |
| 231 | WLAN_CIPHER_SUITE_AES_CMAC |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 232 | }; |
| 233 | |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 234 | /* Vendor specific ie. id = 221, oui and type defines exact ie */ |
| 235 | struct brcmf_vs_tlv { |
| 236 | u8 id; |
| 237 | u8 len; |
| 238 | u8 oui[3]; |
| 239 | u8 oui_type; |
| 240 | }; |
| 241 | |
| 242 | struct parsed_vndr_ie_info { |
| 243 | u8 *ie_ptr; |
| 244 | u32 ie_len; /* total length including id & length field */ |
| 245 | struct brcmf_vs_tlv vndrie; |
| 246 | }; |
| 247 | |
| 248 | struct parsed_vndr_ies { |
| 249 | u32 count; |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 250 | struct parsed_vndr_ie_info ie_info[VNDR_IE_PARSE_LIMIT]; |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 251 | }; |
| 252 | |
Arend van Spriel | 7705ba6 | 2016-04-17 16:44:58 +0200 | [diff] [blame] | 253 | static u8 nl80211_band_to_fwil(enum nl80211_band band) |
| 254 | { |
| 255 | switch (band) { |
| 256 | case NL80211_BAND_2GHZ: |
| 257 | return WLC_BAND_2G; |
| 258 | case NL80211_BAND_5GHZ: |
| 259 | return WLC_BAND_5G; |
| 260 | default: |
| 261 | WARN_ON(1); |
| 262 | break; |
| 263 | } |
| 264 | return 0; |
| 265 | } |
| 266 | |
Arend van Spriel | 5a394eb | 2014-05-27 12:56:15 +0200 | [diff] [blame] | 267 | static u16 chandef_to_chanspec(struct brcmu_d11inf *d11inf, |
| 268 | struct cfg80211_chan_def *ch) |
Arend van Spriel | 600a897 | 2014-05-12 10:47:39 +0200 | [diff] [blame] | 269 | { |
| 270 | struct brcmu_chan ch_inf; |
| 271 | s32 primary_offset; |
| 272 | |
| 273 | brcmf_dbg(TRACE, "chandef: control %d center %d width %d\n", |
| 274 | ch->chan->center_freq, ch->center_freq1, ch->width); |
| 275 | ch_inf.chnum = ieee80211_frequency_to_channel(ch->center_freq1); |
Rafał Miłecki | 36e8072 | 2016-01-20 16:46:04 +0100 | [diff] [blame] | 276 | primary_offset = ch->chan->center_freq - ch->center_freq1; |
Arend van Spriel | 600a897 | 2014-05-12 10:47:39 +0200 | [diff] [blame] | 277 | switch (ch->width) { |
| 278 | case NL80211_CHAN_WIDTH_20: |
Arend van Spriel | 0cd75b1 | 2014-11-11 13:58:44 +0100 | [diff] [blame] | 279 | case NL80211_CHAN_WIDTH_20_NOHT: |
Arend van Spriel | 600a897 | 2014-05-12 10:47:39 +0200 | [diff] [blame] | 280 | ch_inf.bw = BRCMU_CHAN_BW_20; |
| 281 | WARN_ON(primary_offset != 0); |
| 282 | break; |
| 283 | case NL80211_CHAN_WIDTH_40: |
| 284 | ch_inf.bw = BRCMU_CHAN_BW_40; |
Rafał Miłecki | 36e8072 | 2016-01-20 16:46:04 +0100 | [diff] [blame] | 285 | if (primary_offset > 0) |
Arend van Spriel | 600a897 | 2014-05-12 10:47:39 +0200 | [diff] [blame] | 286 | ch_inf.sb = BRCMU_CHAN_SB_U; |
| 287 | else |
| 288 | ch_inf.sb = BRCMU_CHAN_SB_L; |
| 289 | break; |
| 290 | case NL80211_CHAN_WIDTH_80: |
| 291 | ch_inf.bw = BRCMU_CHAN_BW_80; |
Rafał Miłecki | 36e8072 | 2016-01-20 16:46:04 +0100 | [diff] [blame] | 292 | if (primary_offset == -30) |
| 293 | ch_inf.sb = BRCMU_CHAN_SB_LL; |
| 294 | else if (primary_offset == -10) |
| 295 | ch_inf.sb = BRCMU_CHAN_SB_LU; |
| 296 | else if (primary_offset == 10) |
| 297 | ch_inf.sb = BRCMU_CHAN_SB_UL; |
| 298 | else |
| 299 | ch_inf.sb = BRCMU_CHAN_SB_UU; |
Arend van Spriel | 600a897 | 2014-05-12 10:47:39 +0200 | [diff] [blame] | 300 | break; |
Arend van Spriel | 0cd75b1 | 2014-11-11 13:58:44 +0100 | [diff] [blame] | 301 | case NL80211_CHAN_WIDTH_80P80: |
| 302 | case NL80211_CHAN_WIDTH_160: |
| 303 | case NL80211_CHAN_WIDTH_5: |
| 304 | case NL80211_CHAN_WIDTH_10: |
Arend van Spriel | 600a897 | 2014-05-12 10:47:39 +0200 | [diff] [blame] | 305 | default: |
| 306 | WARN_ON_ONCE(1); |
| 307 | } |
| 308 | switch (ch->chan->band) { |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 309 | case NL80211_BAND_2GHZ: |
Arend van Spriel | 600a897 | 2014-05-12 10:47:39 +0200 | [diff] [blame] | 310 | ch_inf.band = BRCMU_CHAN_BAND_2G; |
| 311 | break; |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 312 | case NL80211_BAND_5GHZ: |
Arend van Spriel | 600a897 | 2014-05-12 10:47:39 +0200 | [diff] [blame] | 313 | ch_inf.band = BRCMU_CHAN_BAND_5G; |
| 314 | break; |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 315 | case NL80211_BAND_60GHZ: |
Arend van Spriel | 600a897 | 2014-05-12 10:47:39 +0200 | [diff] [blame] | 316 | default: |
| 317 | WARN_ON_ONCE(1); |
| 318 | } |
| 319 | d11inf->encchspec(&ch_inf); |
| 320 | |
| 321 | return ch_inf.chspec; |
| 322 | } |
| 323 | |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 324 | u16 channel_to_chanspec(struct brcmu_d11inf *d11inf, |
| 325 | struct ieee80211_channel *ch) |
Arend van Spriel | 6e18616 | 2012-10-22 10:36:22 -0700 | [diff] [blame] | 326 | { |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 327 | struct brcmu_chan ch_inf; |
Arend van Spriel | 6e18616 | 2012-10-22 10:36:22 -0700 | [diff] [blame] | 328 | |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 329 | ch_inf.chnum = ieee80211_frequency_to_channel(ch->center_freq); |
| 330 | ch_inf.bw = BRCMU_CHAN_BW_20; |
| 331 | d11inf->encchspec(&ch_inf); |
Arend van Spriel | 6e18616 | 2012-10-22 10:36:22 -0700 | [diff] [blame] | 332 | |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 333 | return ch_inf.chspec; |
Arend van Spriel | 6e18616 | 2012-10-22 10:36:22 -0700 | [diff] [blame] | 334 | } |
| 335 | |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 336 | /* Traverse a string of 1-byte tag/1-byte length/variable-length value |
| 337 | * triples, returning a pointer to the substring whose first element |
| 338 | * matches tag |
| 339 | */ |
Johannes Berg | 4b5800f | 2014-01-15 14:55:59 +0100 | [diff] [blame] | 340 | const struct brcmf_tlv * |
| 341 | brcmf_parse_tlvs(const void *buf, int buflen, uint key) |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 342 | { |
Johannes Berg | 4b5800f | 2014-01-15 14:55:59 +0100 | [diff] [blame] | 343 | const struct brcmf_tlv *elt = buf; |
| 344 | int totlen = buflen; |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 345 | |
| 346 | /* find tagged parameter */ |
| 347 | while (totlen >= TLV_HDR_LEN) { |
| 348 | int len = elt->len; |
| 349 | |
| 350 | /* validate remaining totlen */ |
| 351 | if ((elt->id == key) && (totlen >= (len + TLV_HDR_LEN))) |
| 352 | return elt; |
| 353 | |
| 354 | elt = (struct brcmf_tlv *)((u8 *)elt + (len + TLV_HDR_LEN)); |
| 355 | totlen -= (len + TLV_HDR_LEN); |
| 356 | } |
| 357 | |
| 358 | return NULL; |
| 359 | } |
| 360 | |
| 361 | /* Is any of the tlvs the expected entry? If |
| 362 | * not update the tlvs buffer pointer/length. |
| 363 | */ |
| 364 | static bool |
Johannes Berg | 4b5800f | 2014-01-15 14:55:59 +0100 | [diff] [blame] | 365 | brcmf_tlv_has_ie(const u8 *ie, const u8 **tlvs, u32 *tlvs_len, |
| 366 | const u8 *oui, u32 oui_len, u8 type) |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 367 | { |
| 368 | /* If the contents match the OUI and the type */ |
| 369 | if (ie[TLV_LEN_OFF] >= oui_len + 1 && |
| 370 | !memcmp(&ie[TLV_BODY_OFF], oui, oui_len) && |
| 371 | type == ie[TLV_BODY_OFF + oui_len]) { |
| 372 | return true; |
| 373 | } |
| 374 | |
| 375 | if (tlvs == NULL) |
| 376 | return false; |
| 377 | /* point to the next ie */ |
| 378 | ie += ie[TLV_LEN_OFF] + TLV_HDR_LEN; |
| 379 | /* calculate the length of the rest of the buffer */ |
| 380 | *tlvs_len -= (int)(ie - *tlvs); |
| 381 | /* update the pointer to the start of the buffer */ |
| 382 | *tlvs = ie; |
| 383 | |
| 384 | return false; |
| 385 | } |
| 386 | |
| 387 | static struct brcmf_vs_tlv * |
Johannes Berg | 4b5800f | 2014-01-15 14:55:59 +0100 | [diff] [blame] | 388 | brcmf_find_wpaie(const u8 *parse, u32 len) |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 389 | { |
Johannes Berg | 4b5800f | 2014-01-15 14:55:59 +0100 | [diff] [blame] | 390 | const struct brcmf_tlv *ie; |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 391 | |
| 392 | while ((ie = brcmf_parse_tlvs(parse, len, WLAN_EID_VENDOR_SPECIFIC))) { |
Johannes Berg | 4b5800f | 2014-01-15 14:55:59 +0100 | [diff] [blame] | 393 | if (brcmf_tlv_has_ie((const u8 *)ie, &parse, &len, |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 394 | WPA_OUI, TLV_OUI_LEN, WPA_OUI_TYPE)) |
| 395 | return (struct brcmf_vs_tlv *)ie; |
| 396 | } |
| 397 | return NULL; |
| 398 | } |
| 399 | |
| 400 | static struct brcmf_vs_tlv * |
Johannes Berg | 4b5800f | 2014-01-15 14:55:59 +0100 | [diff] [blame] | 401 | brcmf_find_wpsie(const u8 *parse, u32 len) |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 402 | { |
Johannes Berg | 4b5800f | 2014-01-15 14:55:59 +0100 | [diff] [blame] | 403 | const struct brcmf_tlv *ie; |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 404 | |
| 405 | while ((ie = brcmf_parse_tlvs(parse, len, WLAN_EID_VENDOR_SPECIFIC))) { |
| 406 | if (brcmf_tlv_has_ie((u8 *)ie, &parse, &len, |
| 407 | WPA_OUI, TLV_OUI_LEN, WPS_OUI_TYPE)) |
| 408 | return (struct brcmf_vs_tlv *)ie; |
| 409 | } |
| 410 | return NULL; |
| 411 | } |
| 412 | |
Arend van Spriel | 39504a2 | 2015-08-20 22:06:05 +0200 | [diff] [blame] | 413 | static int brcmf_vif_change_validate(struct brcmf_cfg80211_info *cfg, |
| 414 | struct brcmf_cfg80211_vif *vif, |
| 415 | enum nl80211_iftype new_type) |
| 416 | { |
| 417 | int iftype_num[NUM_NL80211_IFTYPES]; |
| 418 | struct brcmf_cfg80211_vif *pos; |
Arend van Spriel | 353c46a | 2015-12-10 13:43:06 +0100 | [diff] [blame] | 419 | bool check_combos = false; |
| 420 | int ret = 0; |
Arend van Spriel | 39504a2 | 2015-08-20 22:06:05 +0200 | [diff] [blame] | 421 | |
| 422 | memset(&iftype_num[0], 0, sizeof(iftype_num)); |
| 423 | list_for_each_entry(pos, &cfg->vif_list, list) |
Arend van Spriel | 353c46a | 2015-12-10 13:43:06 +0100 | [diff] [blame] | 424 | if (pos == vif) { |
Arend van Spriel | 39504a2 | 2015-08-20 22:06:05 +0200 | [diff] [blame] | 425 | iftype_num[new_type]++; |
Arend van Spriel | 353c46a | 2015-12-10 13:43:06 +0100 | [diff] [blame] | 426 | } else { |
| 427 | /* concurrent interfaces so need check combinations */ |
| 428 | check_combos = true; |
Arend van Spriel | 39504a2 | 2015-08-20 22:06:05 +0200 | [diff] [blame] | 429 | iftype_num[pos->wdev.iftype]++; |
Arend van Spriel | 353c46a | 2015-12-10 13:43:06 +0100 | [diff] [blame] | 430 | } |
Arend van Spriel | 39504a2 | 2015-08-20 22:06:05 +0200 | [diff] [blame] | 431 | |
Arend van Spriel | 353c46a | 2015-12-10 13:43:06 +0100 | [diff] [blame] | 432 | if (check_combos) |
| 433 | ret = cfg80211_check_combinations(cfg->wiphy, 1, 0, iftype_num); |
| 434 | |
| 435 | return ret; |
Arend van Spriel | 39504a2 | 2015-08-20 22:06:05 +0200 | [diff] [blame] | 436 | } |
| 437 | |
| 438 | static int brcmf_vif_add_validate(struct brcmf_cfg80211_info *cfg, |
| 439 | enum nl80211_iftype new_type) |
| 440 | { |
| 441 | int iftype_num[NUM_NL80211_IFTYPES]; |
| 442 | struct brcmf_cfg80211_vif *pos; |
| 443 | |
| 444 | memset(&iftype_num[0], 0, sizeof(iftype_num)); |
| 445 | list_for_each_entry(pos, &cfg->vif_list, list) |
| 446 | iftype_num[pos->wdev.iftype]++; |
| 447 | |
| 448 | iftype_num[new_type]++; |
| 449 | return cfg80211_check_combinations(cfg->wiphy, 1, 0, iftype_num); |
| 450 | } |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 451 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 452 | static void convert_key_from_CPU(struct brcmf_wsec_key *key, |
| 453 | struct brcmf_wsec_key_le *key_le) |
| 454 | { |
| 455 | key_le->index = cpu_to_le32(key->index); |
| 456 | key_le->len = cpu_to_le32(key->len); |
| 457 | key_le->algo = cpu_to_le32(key->algo); |
| 458 | key_le->flags = cpu_to_le32(key->flags); |
| 459 | key_le->rxiv.hi = cpu_to_le32(key->rxiv.hi); |
| 460 | key_le->rxiv.lo = cpu_to_le16(key->rxiv.lo); |
| 461 | key_le->iv_initialized = cpu_to_le32(key->iv_initialized); |
| 462 | memcpy(key_le->data, key->data, sizeof(key->data)); |
| 463 | memcpy(key_le->ea, key->ea, sizeof(key->ea)); |
| 464 | } |
| 465 | |
Hante Meuleman | f09d0c0 | 2012-09-27 14:17:48 +0200 | [diff] [blame] | 466 | static int |
Hante Meuleman | 118eb30 | 2014-12-21 12:43:49 +0100 | [diff] [blame] | 467 | 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] | 468 | { |
| 469 | int err; |
| 470 | struct brcmf_wsec_key_le key_le; |
| 471 | |
| 472 | convert_key_from_CPU(key, &key_le); |
Hante Meuleman | f09d0c0 | 2012-09-27 14:17:48 +0200 | [diff] [blame] | 473 | |
Hante Meuleman | 118eb30 | 2014-12-21 12:43:49 +0100 | [diff] [blame] | 474 | brcmf_netdev_wait_pend8021x(ifp); |
Hante Meuleman | 81f5dcb | 2012-10-22 10:36:14 -0700 | [diff] [blame] | 475 | |
Hante Meuleman | 118eb30 | 2014-12-21 12:43:49 +0100 | [diff] [blame] | 476 | err = brcmf_fil_bsscfg_data_set(ifp, "wsec_key", &key_le, |
Hante Meuleman | 81f5dcb | 2012-10-22 10:36:14 -0700 | [diff] [blame] | 477 | sizeof(key_le)); |
Hante Meuleman | f09d0c0 | 2012-09-27 14:17:48 +0200 | [diff] [blame] | 478 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 479 | if (err) |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 480 | brcmf_err("wsec_key error (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 481 | return err; |
| 482 | } |
| 483 | |
Hante Meuleman | b365745 | 2013-05-27 21:09:53 +0200 | [diff] [blame] | 484 | static s32 |
Franky Lin | 52f22fb | 2016-02-17 11:26:55 +0100 | [diff] [blame] | 485 | brcmf_configure_arp_nd_offload(struct brcmf_if *ifp, bool enable) |
Hante Meuleman | b365745 | 2013-05-27 21:09:53 +0200 | [diff] [blame] | 486 | { |
| 487 | s32 err; |
| 488 | u32 mode; |
| 489 | |
| 490 | if (enable) |
| 491 | mode = BRCMF_ARP_OL_AGENT | BRCMF_ARP_OL_PEER_AUTO_REPLY; |
| 492 | else |
| 493 | mode = 0; |
| 494 | |
| 495 | /* Try to set and enable ARP offload feature, this may fail, then it */ |
| 496 | /* is simply not supported and err 0 will be returned */ |
| 497 | err = brcmf_fil_iovar_int_set(ifp, "arp_ol", mode); |
| 498 | if (err) { |
| 499 | brcmf_dbg(TRACE, "failed to set ARP offload mode to 0x%x, err = %d\n", |
| 500 | mode, err); |
| 501 | err = 0; |
| 502 | } else { |
| 503 | err = brcmf_fil_iovar_int_set(ifp, "arpoe", enable); |
| 504 | if (err) { |
| 505 | brcmf_dbg(TRACE, "failed to configure (%d) ARP offload err = %d\n", |
| 506 | enable, err); |
| 507 | err = 0; |
| 508 | } else |
| 509 | brcmf_dbg(TRACE, "successfully configured (%d) ARP offload to 0x%x\n", |
| 510 | enable, mode); |
| 511 | } |
| 512 | |
Franky Lin | 52f22fb | 2016-02-17 11:26:55 +0100 | [diff] [blame] | 513 | err = brcmf_fil_iovar_int_set(ifp, "ndoe", enable); |
| 514 | if (err) { |
| 515 | brcmf_dbg(TRACE, "failed to configure (%d) ND offload err = %d\n", |
| 516 | enable, err); |
| 517 | err = 0; |
| 518 | } else |
| 519 | brcmf_dbg(TRACE, "successfully configured (%d) ND offload to 0x%x\n", |
| 520 | enable, mode); |
| 521 | |
Hante Meuleman | b365745 | 2013-05-27 21:09:53 +0200 | [diff] [blame] | 522 | return err; |
| 523 | } |
| 524 | |
Hante Meuleman | 8851cce | 2014-07-30 13:20:02 +0200 | [diff] [blame] | 525 | static void |
| 526 | brcmf_cfg80211_update_proto_addr_mode(struct wireless_dev *wdev) |
| 527 | { |
Arend van Spriel | 8f2b459 | 2014-09-11 22:51:32 +0200 | [diff] [blame] | 528 | struct brcmf_cfg80211_vif *vif; |
| 529 | struct brcmf_if *ifp; |
| 530 | |
| 531 | vif = container_of(wdev, struct brcmf_cfg80211_vif, wdev); |
| 532 | ifp = vif->ifp; |
Hante Meuleman | 8851cce | 2014-07-30 13:20:02 +0200 | [diff] [blame] | 533 | |
| 534 | if ((wdev->iftype == NL80211_IFTYPE_ADHOC) || |
| 535 | (wdev->iftype == NL80211_IFTYPE_AP) || |
| 536 | (wdev->iftype == NL80211_IFTYPE_P2P_GO)) |
| 537 | brcmf_proto_configure_addr_mode(ifp->drvr, ifp->ifidx, |
| 538 | ADDR_DIRECT); |
| 539 | else |
| 540 | brcmf_proto_configure_addr_mode(ifp->drvr, ifp->ifidx, |
| 541 | ADDR_INDIRECT); |
| 542 | } |
| 543 | |
Rafał Miłecki | d02fb8f | 2016-05-26 01:44:27 +0200 | [diff] [blame] | 544 | static int brcmf_get_first_free_bsscfgidx(struct brcmf_pub *drvr) |
| 545 | { |
| 546 | int bsscfgidx; |
| 547 | |
| 548 | for (bsscfgidx = 0; bsscfgidx < BRCMF_MAX_IFS; bsscfgidx++) { |
| 549 | /* bsscfgidx 1 is reserved for legacy P2P */ |
| 550 | if (bsscfgidx == 1) |
| 551 | continue; |
| 552 | if (!drvr->iflist[bsscfgidx]) |
| 553 | return bsscfgidx; |
| 554 | } |
| 555 | |
| 556 | return -ENOMEM; |
| 557 | } |
| 558 | |
Hante Meuleman | a44aa40 | 2014-12-03 21:05:33 +0100 | [diff] [blame] | 559 | static int brcmf_cfg80211_request_ap_if(struct brcmf_if *ifp) |
| 560 | { |
| 561 | struct brcmf_mbss_ssid_le mbss_ssid_le; |
| 562 | int bsscfgidx; |
| 563 | int err; |
| 564 | |
| 565 | memset(&mbss_ssid_le, 0, sizeof(mbss_ssid_le)); |
Rafał Miłecki | d02fb8f | 2016-05-26 01:44:27 +0200 | [diff] [blame] | 566 | bsscfgidx = brcmf_get_first_free_bsscfgidx(ifp->drvr); |
Hante Meuleman | a44aa40 | 2014-12-03 21:05:33 +0100 | [diff] [blame] | 567 | if (bsscfgidx < 0) |
| 568 | return bsscfgidx; |
| 569 | |
| 570 | mbss_ssid_le.bsscfgidx = cpu_to_le32(bsscfgidx); |
| 571 | mbss_ssid_le.SSID_len = cpu_to_le32(5); |
| 572 | sprintf(mbss_ssid_le.SSID, "ssid%d" , bsscfgidx); |
| 573 | |
| 574 | err = brcmf_fil_bsscfg_data_set(ifp, "bsscfg:ssid", &mbss_ssid_le, |
| 575 | sizeof(mbss_ssid_le)); |
| 576 | if (err < 0) |
| 577 | brcmf_err("setting ssid failed %d\n", err); |
| 578 | |
| 579 | return err; |
| 580 | } |
| 581 | |
| 582 | /** |
| 583 | * brcmf_ap_add_vif() - create a new AP virtual interface for multiple BSS |
| 584 | * |
| 585 | * @wiphy: wiphy device of new interface. |
| 586 | * @name: name of the new interface. |
| 587 | * @flags: not used. |
| 588 | * @params: contains mac address for AP device. |
| 589 | */ |
| 590 | static |
| 591 | struct wireless_dev *brcmf_ap_add_vif(struct wiphy *wiphy, const char *name, |
| 592 | u32 *flags, struct vif_params *params) |
| 593 | { |
| 594 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); |
| 595 | struct brcmf_if *ifp = netdev_priv(cfg_to_ndev(cfg)); |
| 596 | struct brcmf_cfg80211_vif *vif; |
| 597 | int err; |
| 598 | |
| 599 | if (brcmf_cfg80211_vif_event_armed(cfg)) |
| 600 | return ERR_PTR(-EBUSY); |
| 601 | |
| 602 | brcmf_dbg(INFO, "Adding vif \"%s\"\n", name); |
| 603 | |
| 604 | vif = brcmf_alloc_vif(cfg, NL80211_IFTYPE_AP, false); |
| 605 | if (IS_ERR(vif)) |
| 606 | return (struct wireless_dev *)vif; |
| 607 | |
| 608 | brcmf_cfg80211_arm_vif_event(cfg, vif); |
| 609 | |
| 610 | err = brcmf_cfg80211_request_ap_if(ifp); |
| 611 | if (err) { |
| 612 | brcmf_cfg80211_arm_vif_event(cfg, NULL); |
| 613 | goto fail; |
| 614 | } |
| 615 | |
| 616 | /* wait for firmware event */ |
Arend van Spriel | a9eb0c4 | 2016-02-17 11:26:50 +0100 | [diff] [blame] | 617 | err = brcmf_cfg80211_wait_vif_event(cfg, BRCMF_E_IF_ADD, |
| 618 | BRCMF_VIF_EVENT_TIMEOUT); |
Hante Meuleman | a44aa40 | 2014-12-03 21:05:33 +0100 | [diff] [blame] | 619 | brcmf_cfg80211_arm_vif_event(cfg, NULL); |
| 620 | if (!err) { |
| 621 | brcmf_err("timeout occurred\n"); |
| 622 | err = -EIO; |
| 623 | goto fail; |
| 624 | } |
| 625 | |
| 626 | /* interface created in firmware */ |
| 627 | ifp = vif->ifp; |
| 628 | if (!ifp) { |
| 629 | brcmf_err("no if pointer provided\n"); |
| 630 | err = -ENOENT; |
| 631 | goto fail; |
| 632 | } |
| 633 | |
| 634 | strncpy(ifp->ndev->name, name, sizeof(ifp->ndev->name) - 1); |
| 635 | err = brcmf_net_attach(ifp, true); |
| 636 | if (err) { |
| 637 | brcmf_err("Registering netdevice failed\n"); |
| 638 | goto fail; |
| 639 | } |
| 640 | |
| 641 | return &ifp->vif->wdev; |
| 642 | |
| 643 | fail: |
| 644 | brcmf_free_vif(vif); |
| 645 | return ERR_PTR(err); |
| 646 | } |
| 647 | |
Arend van Spriel | 967fe2c | 2014-03-15 17:18:21 +0100 | [diff] [blame] | 648 | static bool brcmf_is_apmode(struct brcmf_cfg80211_vif *vif) |
| 649 | { |
| 650 | enum nl80211_iftype iftype; |
| 651 | |
| 652 | iftype = vif->wdev.iftype; |
| 653 | return iftype == NL80211_IFTYPE_AP || iftype == NL80211_IFTYPE_P2P_GO; |
| 654 | } |
| 655 | |
| 656 | static bool brcmf_is_ibssmode(struct brcmf_cfg80211_vif *vif) |
| 657 | { |
| 658 | return vif->wdev.iftype == NL80211_IFTYPE_ADHOC; |
| 659 | } |
| 660 | |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 661 | static struct wireless_dev *brcmf_cfg80211_add_iface(struct wiphy *wiphy, |
| 662 | const char *name, |
Tom Gundersen | 6bab2e19 | 2015-03-18 11:13:39 +0100 | [diff] [blame] | 663 | unsigned char name_assign_type, |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 664 | enum nl80211_iftype type, |
| 665 | u32 *flags, |
| 666 | struct vif_params *params) |
| 667 | { |
Hante Meuleman | 8851cce | 2014-07-30 13:20:02 +0200 | [diff] [blame] | 668 | struct wireless_dev *wdev; |
Arend van Spriel | 39504a2 | 2015-08-20 22:06:05 +0200 | [diff] [blame] | 669 | int err; |
Hante Meuleman | 8851cce | 2014-07-30 13:20:02 +0200 | [diff] [blame] | 670 | |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 671 | brcmf_dbg(TRACE, "enter: %s type %d\n", name, type); |
Arend van Spriel | 39504a2 | 2015-08-20 22:06:05 +0200 | [diff] [blame] | 672 | err = brcmf_vif_add_validate(wiphy_to_cfg(wiphy), type); |
| 673 | if (err) { |
| 674 | brcmf_err("iface validation failed: err=%d\n", err); |
| 675 | return ERR_PTR(err); |
| 676 | } |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 677 | switch (type) { |
| 678 | case NL80211_IFTYPE_ADHOC: |
| 679 | case NL80211_IFTYPE_STATION: |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 680 | case NL80211_IFTYPE_AP_VLAN: |
| 681 | case NL80211_IFTYPE_WDS: |
| 682 | case NL80211_IFTYPE_MONITOR: |
| 683 | case NL80211_IFTYPE_MESH_POINT: |
| 684 | return ERR_PTR(-EOPNOTSUPP); |
Hante Meuleman | a44aa40 | 2014-12-03 21:05:33 +0100 | [diff] [blame] | 685 | case NL80211_IFTYPE_AP: |
| 686 | wdev = brcmf_ap_add_vif(wiphy, name, flags, params); |
| 687 | if (!IS_ERR(wdev)) |
| 688 | brcmf_cfg80211_update_proto_addr_mode(wdev); |
| 689 | return wdev; |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 690 | case NL80211_IFTYPE_P2P_CLIENT: |
| 691 | case NL80211_IFTYPE_P2P_GO: |
Arend van Spriel | 27f10e3 | 2013-04-05 10:57:50 +0200 | [diff] [blame] | 692 | case NL80211_IFTYPE_P2P_DEVICE: |
Tom Gundersen | 6bab2e19 | 2015-03-18 11:13:39 +0100 | [diff] [blame] | 693 | wdev = brcmf_p2p_add_vif(wiphy, name, name_assign_type, type, flags, params); |
Hante Meuleman | 8851cce | 2014-07-30 13:20:02 +0200 | [diff] [blame] | 694 | if (!IS_ERR(wdev)) |
| 695 | brcmf_cfg80211_update_proto_addr_mode(wdev); |
| 696 | return wdev; |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 697 | case NL80211_IFTYPE_UNSPECIFIED: |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 698 | default: |
| 699 | return ERR_PTR(-EINVAL); |
| 700 | } |
| 701 | } |
| 702 | |
Daniel Kim | 5e787f7 | 2014-06-21 12:11:18 +0200 | [diff] [blame] | 703 | static void brcmf_scan_config_mpc(struct brcmf_if *ifp, int mpc) |
| 704 | { |
Arend van Spriel | c08437b | 2014-07-12 08:49:39 +0200 | [diff] [blame] | 705 | if (brcmf_feat_is_quirk_enabled(ifp, BRCMF_FEAT_QUIRK_NEED_MPC)) |
Daniel Kim | 5e787f7 | 2014-06-21 12:11:18 +0200 | [diff] [blame] | 706 | brcmf_set_mpc(ifp, mpc); |
| 707 | } |
| 708 | |
Arend van Spriel | f96aa07 | 2013-04-05 10:57:48 +0200 | [diff] [blame] | 709 | void brcmf_set_mpc(struct brcmf_if *ifp, int mpc) |
Arend van Spriel | 5f4f9f1 | 2013-02-08 15:53:41 +0100 | [diff] [blame] | 710 | { |
Arend van Spriel | 5f4f9f1 | 2013-02-08 15:53:41 +0100 | [diff] [blame] | 711 | s32 err = 0; |
| 712 | |
| 713 | if (check_vif_up(ifp->vif)) { |
| 714 | err = brcmf_fil_iovar_int_set(ifp, "mpc", mpc); |
| 715 | if (err) { |
| 716 | brcmf_err("fail to set mpc\n"); |
| 717 | return; |
| 718 | } |
| 719 | brcmf_dbg(INFO, "MPC : %d\n", mpc); |
| 720 | } |
| 721 | } |
| 722 | |
Arend van Spriel | a0f472a | 2013-04-05 10:57:49 +0200 | [diff] [blame] | 723 | s32 brcmf_notify_escan_complete(struct brcmf_cfg80211_info *cfg, |
| 724 | struct brcmf_if *ifp, bool aborted, |
| 725 | bool fw_abort) |
Arend van Spriel | 5f4f9f1 | 2013-02-08 15:53:41 +0100 | [diff] [blame] | 726 | { |
| 727 | struct brcmf_scan_params_le params_le; |
| 728 | struct cfg80211_scan_request *scan_request; |
| 729 | s32 err = 0; |
| 730 | |
| 731 | brcmf_dbg(SCAN, "Enter\n"); |
| 732 | |
| 733 | /* clear scan request, because the FW abort can cause a second call */ |
| 734 | /* to this functon and might cause a double cfg80211_scan_done */ |
| 735 | scan_request = cfg->scan_request; |
| 736 | cfg->scan_request = NULL; |
| 737 | |
| 738 | if (timer_pending(&cfg->escan_timeout)) |
| 739 | del_timer_sync(&cfg->escan_timeout); |
| 740 | |
| 741 | if (fw_abort) { |
| 742 | /* Do a scan abort to stop the driver's scan engine */ |
| 743 | brcmf_dbg(SCAN, "ABORT scan in firmware\n"); |
| 744 | memset(¶ms_le, 0, sizeof(params_le)); |
Joe Perches | 93803b3 | 2015-03-02 19:54:49 -0800 | [diff] [blame] | 745 | eth_broadcast_addr(params_le.bssid); |
Arend van Spriel | 5f4f9f1 | 2013-02-08 15:53:41 +0100 | [diff] [blame] | 746 | params_le.bss_type = DOT11_BSSTYPE_ANY; |
| 747 | params_le.scan_type = 0; |
| 748 | params_le.channel_num = cpu_to_le32(1); |
| 749 | params_le.nprobes = cpu_to_le32(1); |
| 750 | params_le.active_time = cpu_to_le32(-1); |
| 751 | params_le.passive_time = cpu_to_le32(-1); |
| 752 | params_le.home_time = cpu_to_le32(-1); |
| 753 | /* Scan is aborted by setting channel_list[0] to -1 */ |
| 754 | params_le.channel_list[0] = cpu_to_le16(-1); |
| 755 | /* E-Scan (or anyother type) can be aborted by SCAN */ |
Arend van Spriel | f96aa07 | 2013-04-05 10:57:48 +0200 | [diff] [blame] | 756 | err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SCAN, |
Arend van Spriel | 5f4f9f1 | 2013-02-08 15:53:41 +0100 | [diff] [blame] | 757 | ¶ms_le, sizeof(params_le)); |
| 758 | if (err) |
| 759 | brcmf_err("Scan abort failed\n"); |
| 760 | } |
Arend van Spriel | 0f0fe99 | 2014-05-27 12:56:14 +0200 | [diff] [blame] | 761 | |
Daniel Kim | 5e787f7 | 2014-06-21 12:11:18 +0200 | [diff] [blame] | 762 | brcmf_scan_config_mpc(ifp, 1); |
Arend van Spriel | 0f0fe99 | 2014-05-27 12:56:14 +0200 | [diff] [blame] | 763 | |
Arend van Spriel | 5f4f9f1 | 2013-02-08 15:53:41 +0100 | [diff] [blame] | 764 | /* |
| 765 | * e-scan can be initiated by scheduled scan |
| 766 | * which takes precedence. |
| 767 | */ |
| 768 | if (cfg->sched_escan) { |
| 769 | brcmf_dbg(SCAN, "scheduled scan completed\n"); |
| 770 | cfg->sched_escan = false; |
| 771 | if (!aborted) |
| 772 | cfg80211_sched_scan_results(cfg_to_wiphy(cfg)); |
Arend van Spriel | 5f4f9f1 | 2013-02-08 15:53:41 +0100 | [diff] [blame] | 773 | } else if (scan_request) { |
| 774 | brcmf_dbg(SCAN, "ESCAN Completed scan: %s\n", |
| 775 | aborted ? "Aborted" : "Done"); |
| 776 | cfg80211_scan_done(scan_request, aborted); |
Arend van Spriel | 5f4f9f1 | 2013-02-08 15:53:41 +0100 | [diff] [blame] | 777 | } |
Hante Meuleman | 6eda4e2 | 2013-02-08 15:54:02 +0100 | [diff] [blame] | 778 | if (!test_and_clear_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status)) |
| 779 | brcmf_dbg(SCAN, "Scan complete, probably P2P scan\n"); |
Arend van Spriel | 5f4f9f1 | 2013-02-08 15:53:41 +0100 | [diff] [blame] | 780 | |
| 781 | return err; |
| 782 | } |
| 783 | |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 784 | static |
| 785 | int brcmf_cfg80211_del_iface(struct wiphy *wiphy, struct wireless_dev *wdev) |
| 786 | { |
Arend van Spriel | 5f4f9f1 | 2013-02-08 15:53:41 +0100 | [diff] [blame] | 787 | struct brcmf_cfg80211_info *cfg = wiphy_priv(wiphy); |
| 788 | struct net_device *ndev = wdev->netdev; |
| 789 | |
| 790 | /* vif event pending in firmware */ |
| 791 | if (brcmf_cfg80211_vif_event_armed(cfg)) |
| 792 | return -EBUSY; |
| 793 | |
| 794 | if (ndev) { |
| 795 | if (test_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status) && |
Arend van Spriel | a0f472a | 2013-04-05 10:57:49 +0200 | [diff] [blame] | 796 | cfg->escan_info.ifp == netdev_priv(ndev)) |
| 797 | brcmf_notify_escan_complete(cfg, netdev_priv(ndev), |
| 798 | true, true); |
Arend van Spriel | 5f4f9f1 | 2013-02-08 15:53:41 +0100 | [diff] [blame] | 799 | |
| 800 | brcmf_fil_iovar_int_set(netdev_priv(ndev), "mpc", 1); |
| 801 | } |
| 802 | |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 803 | switch (wdev->iftype) { |
| 804 | case NL80211_IFTYPE_ADHOC: |
| 805 | case NL80211_IFTYPE_STATION: |
| 806 | case NL80211_IFTYPE_AP: |
| 807 | case NL80211_IFTYPE_AP_VLAN: |
| 808 | case NL80211_IFTYPE_WDS: |
| 809 | case NL80211_IFTYPE_MONITOR: |
| 810 | case NL80211_IFTYPE_MESH_POINT: |
| 811 | return -EOPNOTSUPP; |
| 812 | case NL80211_IFTYPE_P2P_CLIENT: |
| 813 | case NL80211_IFTYPE_P2P_GO: |
Arend van Spriel | 27f10e3 | 2013-04-05 10:57:50 +0200 | [diff] [blame] | 814 | case NL80211_IFTYPE_P2P_DEVICE: |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 815 | return brcmf_p2p_del_vif(wiphy, wdev); |
| 816 | case NL80211_IFTYPE_UNSPECIFIED: |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 817 | default: |
| 818 | return -EINVAL; |
| 819 | } |
| 820 | return -EOPNOTSUPP; |
| 821 | } |
| 822 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 823 | static s32 |
| 824 | brcmf_cfg80211_change_iface(struct wiphy *wiphy, struct net_device *ndev, |
| 825 | enum nl80211_iftype type, u32 *flags, |
| 826 | struct vif_params *params) |
| 827 | { |
Hante Meuleman | 7a5c1f6 | 2013-02-08 15:53:44 +0100 | [diff] [blame] | 828 | struct brcmf_cfg80211_info *cfg = wiphy_priv(wiphy); |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 829 | struct brcmf_if *ifp = netdev_priv(ndev); |
Arend van Spriel | 128ce3b | 2012-11-28 21:44:12 +0100 | [diff] [blame] | 830 | struct brcmf_cfg80211_vif *vif = ifp->vif; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 831 | s32 infra = 0; |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 832 | s32 ap = 0; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 833 | s32 err = 0; |
| 834 | |
Hante Meuleman | 37a869e | 2015-10-29 20:33:17 +0100 | [diff] [blame] | 835 | brcmf_dbg(TRACE, "Enter, bsscfgidx=%d, type=%d\n", ifp->bsscfgidx, |
| 836 | type); |
Hante Meuleman | 178e9ef | 2015-09-18 22:08:11 +0200 | [diff] [blame] | 837 | |
| 838 | /* WAR: There are a number of p2p interface related problems which |
| 839 | * need to be handled initially (before doing the validate). |
| 840 | * wpa_supplicant tends to do iface changes on p2p device/client/go |
| 841 | * which are not always possible/allowed. However we need to return |
| 842 | * OK otherwise the wpa_supplicant wont start. The situation differs |
| 843 | * on configuration and setup (p2pon=1 module param). The first check |
| 844 | * is to see if the request is a change to station for p2p iface. |
| 845 | */ |
| 846 | if ((type == NL80211_IFTYPE_STATION) && |
| 847 | ((vif->wdev.iftype == NL80211_IFTYPE_P2P_CLIENT) || |
| 848 | (vif->wdev.iftype == NL80211_IFTYPE_P2P_GO) || |
| 849 | (vif->wdev.iftype == NL80211_IFTYPE_P2P_DEVICE))) { |
| 850 | brcmf_dbg(TRACE, "Ignoring cmd for p2p if\n"); |
| 851 | /* Now depending on whether module param p2pon=1 was used the |
| 852 | * response needs to be either 0 or EOPNOTSUPP. The reason is |
| 853 | * that if p2pon=1 is used, but a newer supplicant is used then |
| 854 | * we should return an error, as this combination wont work. |
| 855 | * In other situations 0 is returned and supplicant will start |
| 856 | * normally. It will give a trace in cfg80211, but it is the |
| 857 | * only way to get it working. Unfortunately this will result |
| 858 | * in situation where we wont support new supplicant in |
| 859 | * combination with module param p2pon=1, but that is the way |
| 860 | * it is. If the user tries this then unloading of driver might |
| 861 | * fail/lock. |
| 862 | */ |
| 863 | if (cfg->p2p.p2pdev_dynamically) |
| 864 | return -EOPNOTSUPP; |
| 865 | else |
| 866 | return 0; |
| 867 | } |
Arend van Spriel | 39504a2 | 2015-08-20 22:06:05 +0200 | [diff] [blame] | 868 | err = brcmf_vif_change_validate(wiphy_to_cfg(wiphy), vif, type); |
| 869 | if (err) { |
| 870 | brcmf_err("iface validation failed: err=%d\n", err); |
| 871 | return err; |
| 872 | } |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 873 | switch (type) { |
| 874 | case NL80211_IFTYPE_MONITOR: |
| 875 | case NL80211_IFTYPE_WDS: |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 876 | brcmf_err("type (%d) : currently we do not support this type\n", |
| 877 | type); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 878 | return -EOPNOTSUPP; |
| 879 | case NL80211_IFTYPE_ADHOC: |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 880 | infra = 0; |
| 881 | break; |
| 882 | case NL80211_IFTYPE_STATION: |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 883 | infra = 1; |
| 884 | break; |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 885 | case NL80211_IFTYPE_AP: |
Hante Meuleman | 7a5c1f6 | 2013-02-08 15:53:44 +0100 | [diff] [blame] | 886 | case NL80211_IFTYPE_P2P_GO: |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 887 | ap = 1; |
| 888 | break; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 889 | default: |
| 890 | err = -EINVAL; |
| 891 | goto done; |
| 892 | } |
| 893 | |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 894 | if (ap) { |
Hante Meuleman | 7a5c1f6 | 2013-02-08 15:53:44 +0100 | [diff] [blame] | 895 | if (type == NL80211_IFTYPE_P2P_GO) { |
| 896 | brcmf_dbg(INFO, "IF Type = P2P GO\n"); |
| 897 | err = brcmf_p2p_ifchange(cfg, BRCMF_FIL_P2P_IF_GO); |
| 898 | } |
| 899 | if (!err) { |
Hante Meuleman | 7a5c1f6 | 2013-02-08 15:53:44 +0100 | [diff] [blame] | 900 | brcmf_dbg(INFO, "IF Type = AP\n"); |
| 901 | } |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 902 | } else { |
Arend van Spriel | 128ce3b | 2012-11-28 21:44:12 +0100 | [diff] [blame] | 903 | err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_INFRA, infra); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 904 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 905 | brcmf_err("WLC_SET_INFRA error (%d)\n", err); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 906 | err = -EAGAIN; |
| 907 | goto done; |
| 908 | } |
Arend van Spriel | 967fe2c | 2014-03-15 17:18:21 +0100 | [diff] [blame] | 909 | brcmf_dbg(INFO, "IF Type = %s\n", brcmf_is_ibssmode(vif) ? |
Arend van Spriel | 647c9ae | 2012-12-05 15:26:01 +0100 | [diff] [blame] | 910 | "Adhoc" : "Infra"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 911 | } |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 912 | ndev->ieee80211_ptr->iftype = type; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 913 | |
Hante Meuleman | 8851cce | 2014-07-30 13:20:02 +0200 | [diff] [blame] | 914 | brcmf_cfg80211_update_proto_addr_mode(&vif->wdev); |
| 915 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 916 | done: |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 917 | brcmf_dbg(TRACE, "Exit\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 918 | |
| 919 | return err; |
| 920 | } |
| 921 | |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 922 | static void brcmf_escan_prep(struct brcmf_cfg80211_info *cfg, |
| 923 | struct brcmf_scan_params_le *params_le, |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 924 | struct cfg80211_scan_request *request) |
| 925 | { |
| 926 | u32 n_ssids; |
| 927 | u32 n_channels; |
| 928 | s32 i; |
| 929 | s32 offset; |
Arend van Spriel | 029591f | 2012-09-19 22:21:06 +0200 | [diff] [blame] | 930 | u16 chanspec; |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 931 | char *ptr; |
Arend van Spriel | 029591f | 2012-09-19 22:21:06 +0200 | [diff] [blame] | 932 | struct brcmf_ssid_le ssid_le; |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 933 | |
Joe Perches | 93803b3 | 2015-03-02 19:54:49 -0800 | [diff] [blame] | 934 | eth_broadcast_addr(params_le->bssid); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 935 | params_le->bss_type = DOT11_BSSTYPE_ANY; |
| 936 | params_le->scan_type = 0; |
| 937 | params_le->channel_num = 0; |
| 938 | params_le->nprobes = cpu_to_le32(-1); |
| 939 | params_le->active_time = cpu_to_le32(-1); |
| 940 | params_le->passive_time = cpu_to_le32(-1); |
| 941 | params_le->home_time = cpu_to_le32(-1); |
| 942 | memset(¶ms_le->ssid_le, 0, sizeof(params_le->ssid_le)); |
| 943 | |
| 944 | /* if request is null exit so it will be all channel broadcast scan */ |
| 945 | if (!request) |
| 946 | return; |
| 947 | |
| 948 | n_ssids = request->n_ssids; |
| 949 | n_channels = request->n_channels; |
| 950 | /* Copy channel array if applicable */ |
Arend van Spriel | 4e8a008 | 2012-12-05 15:26:03 +0100 | [diff] [blame] | 951 | brcmf_dbg(SCAN, "### List of channelspecs to scan ### %d\n", |
| 952 | n_channels); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 953 | if (n_channels > 0) { |
| 954 | for (i = 0; i < n_channels; i++) { |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 955 | chanspec = channel_to_chanspec(&cfg->d11inf, |
| 956 | request->channels[i]); |
Arend van Spriel | 4e8a008 | 2012-12-05 15:26:03 +0100 | [diff] [blame] | 957 | brcmf_dbg(SCAN, "Chan : %d, Channel spec: %x\n", |
| 958 | request->channels[i]->hw_value, chanspec); |
Arend van Spriel | 029591f | 2012-09-19 22:21:06 +0200 | [diff] [blame] | 959 | params_le->channel_list[i] = cpu_to_le16(chanspec); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 960 | } |
| 961 | } else { |
Arend van Spriel | 4e8a008 | 2012-12-05 15:26:03 +0100 | [diff] [blame] | 962 | brcmf_dbg(SCAN, "Scanning all channels\n"); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 963 | } |
| 964 | /* Copy ssid array if applicable */ |
Arend van Spriel | 4e8a008 | 2012-12-05 15:26:03 +0100 | [diff] [blame] | 965 | brcmf_dbg(SCAN, "### List of SSIDs to scan ### %d\n", n_ssids); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 966 | if (n_ssids > 0) { |
| 967 | offset = offsetof(struct brcmf_scan_params_le, channel_list) + |
| 968 | n_channels * sizeof(u16); |
| 969 | offset = roundup(offset, sizeof(u32)); |
| 970 | ptr = (char *)params_le + offset; |
| 971 | for (i = 0; i < n_ssids; i++) { |
Arend van Spriel | 029591f | 2012-09-19 22:21:06 +0200 | [diff] [blame] | 972 | memset(&ssid_le, 0, sizeof(ssid_le)); |
| 973 | ssid_le.SSID_len = |
| 974 | cpu_to_le32(request->ssids[i].ssid_len); |
| 975 | memcpy(ssid_le.SSID, request->ssids[i].ssid, |
| 976 | request->ssids[i].ssid_len); |
| 977 | if (!ssid_le.SSID_len) |
Arend van Spriel | 4e8a008 | 2012-12-05 15:26:03 +0100 | [diff] [blame] | 978 | brcmf_dbg(SCAN, "%d: Broadcast scan\n", i); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 979 | else |
Arend van Spriel | 4e8a008 | 2012-12-05 15:26:03 +0100 | [diff] [blame] | 980 | brcmf_dbg(SCAN, "%d: scan for %s size =%d\n", |
| 981 | i, ssid_le.SSID, ssid_le.SSID_len); |
Arend van Spriel | 029591f | 2012-09-19 22:21:06 +0200 | [diff] [blame] | 982 | memcpy(ptr, &ssid_le, sizeof(ssid_le)); |
| 983 | ptr += sizeof(ssid_le); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 984 | } |
| 985 | } else { |
Arend van Spriel | 4e8a008 | 2012-12-05 15:26:03 +0100 | [diff] [blame] | 986 | brcmf_dbg(SCAN, "Broadcast scan %p\n", request->ssids); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 987 | if ((request->ssids) && request->ssids->ssid_len) { |
Arend van Spriel | 4e8a008 | 2012-12-05 15:26:03 +0100 | [diff] [blame] | 988 | brcmf_dbg(SCAN, "SSID %s len=%d\n", |
| 989 | params_le->ssid_le.SSID, |
| 990 | request->ssids->ssid_len); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 991 | params_le->ssid_le.SSID_len = |
| 992 | cpu_to_le32(request->ssids->ssid_len); |
| 993 | memcpy(¶ms_le->ssid_le.SSID, request->ssids->ssid, |
| 994 | request->ssids->ssid_len); |
| 995 | } |
| 996 | } |
| 997 | /* Adding mask to channel numbers */ |
| 998 | params_le->channel_num = |
| 999 | cpu_to_le32((n_ssids << BRCMF_SCAN_PARAMS_NSSID_SHIFT) | |
| 1000 | (n_channels & BRCMF_SCAN_PARAMS_COUNT_MASK)); |
| 1001 | } |
| 1002 | |
| 1003 | static s32 |
Arend van Spriel | a0f472a | 2013-04-05 10:57:49 +0200 | [diff] [blame] | 1004 | brcmf_run_escan(struct brcmf_cfg80211_info *cfg, struct brcmf_if *ifp, |
Hante Meuleman | c495810 | 2015-11-25 11:32:41 +0100 | [diff] [blame] | 1005 | struct cfg80211_scan_request *request) |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1006 | { |
| 1007 | s32 params_size = BRCMF_SCAN_PARAMS_FIXED_SIZE + |
| 1008 | offsetof(struct brcmf_escan_params_le, params_le); |
| 1009 | struct brcmf_escan_params_le *params; |
| 1010 | s32 err = 0; |
| 1011 | |
Arend van Spriel | 4e8a008 | 2012-12-05 15:26:03 +0100 | [diff] [blame] | 1012 | brcmf_dbg(SCAN, "E-SCAN START\n"); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1013 | |
| 1014 | if (request != NULL) { |
| 1015 | /* Allocate space for populating ssids in struct */ |
| 1016 | params_size += sizeof(u32) * ((request->n_channels + 1) / 2); |
| 1017 | |
| 1018 | /* Allocate space for populating ssids in struct */ |
Hante Meuleman | e9a6ca8 | 2015-11-25 11:32:37 +0100 | [diff] [blame] | 1019 | params_size += sizeof(struct brcmf_ssid_le) * request->n_ssids; |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1020 | } |
| 1021 | |
| 1022 | params = kzalloc(params_size, GFP_KERNEL); |
| 1023 | if (!params) { |
| 1024 | err = -ENOMEM; |
| 1025 | goto exit; |
| 1026 | } |
| 1027 | BUG_ON(params_size + sizeof("escan") >= BRCMF_DCMD_MEDLEN); |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 1028 | brcmf_escan_prep(cfg, ¶ms->params_le, request); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1029 | params->version = cpu_to_le32(BRCMF_ESCAN_REQ_VERSION); |
Hante Meuleman | c495810 | 2015-11-25 11:32:41 +0100 | [diff] [blame] | 1030 | params->action = cpu_to_le16(WL_ESCAN_ACTION_START); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1031 | params->sync_id = cpu_to_le16(0x1234); |
| 1032 | |
Arend van Spriel | a0f472a | 2013-04-05 10:57:49 +0200 | [diff] [blame] | 1033 | err = brcmf_fil_iovar_data_set(ifp, "escan", params, params_size); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1034 | if (err) { |
| 1035 | if (err == -EBUSY) |
Arend van Spriel | 647c9ae | 2012-12-05 15:26:01 +0100 | [diff] [blame] | 1036 | brcmf_dbg(INFO, "system busy : escan canceled\n"); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1037 | else |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1038 | brcmf_err("error (%d)\n", err); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1039 | } |
| 1040 | |
| 1041 | kfree(params); |
| 1042 | exit: |
| 1043 | return err; |
| 1044 | } |
| 1045 | |
| 1046 | static s32 |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 1047 | brcmf_do_escan(struct brcmf_cfg80211_info *cfg, struct wiphy *wiphy, |
Arend van Spriel | a0f472a | 2013-04-05 10:57:49 +0200 | [diff] [blame] | 1048 | struct brcmf_if *ifp, struct cfg80211_scan_request *request) |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1049 | { |
| 1050 | s32 err; |
Hante Meuleman | 81f5dcb | 2012-10-22 10:36:14 -0700 | [diff] [blame] | 1051 | u32 passive_scan; |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1052 | struct brcmf_scan_results *results; |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 1053 | struct escan_info *escan = &cfg->escan_info; |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1054 | |
Arend van Spriel | 4e8a008 | 2012-12-05 15:26:03 +0100 | [diff] [blame] | 1055 | brcmf_dbg(SCAN, "Enter\n"); |
Arend van Spriel | a0f472a | 2013-04-05 10:57:49 +0200 | [diff] [blame] | 1056 | escan->ifp = ifp; |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 1057 | escan->wiphy = wiphy; |
| 1058 | escan->escan_state = WL_ESCAN_STATE_SCANNING; |
Hante Meuleman | 81f5dcb | 2012-10-22 10:36:14 -0700 | [diff] [blame] | 1059 | passive_scan = cfg->active_scan ? 0 : 1; |
Arend van Spriel | f96aa07 | 2013-04-05 10:57:48 +0200 | [diff] [blame] | 1060 | err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_PASSIVE_SCAN, |
Hante Meuleman | 81f5dcb | 2012-10-22 10:36:14 -0700 | [diff] [blame] | 1061 | passive_scan); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1062 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1063 | brcmf_err("error (%d)\n", err); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1064 | return err; |
| 1065 | } |
Daniel Kim | 5e787f7 | 2014-06-21 12:11:18 +0200 | [diff] [blame] | 1066 | brcmf_scan_config_mpc(ifp, 0); |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 1067 | results = (struct brcmf_scan_results *)cfg->escan_info.escan_buf; |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1068 | results->version = 0; |
| 1069 | results->count = 0; |
| 1070 | results->buflen = WL_ESCAN_RESULTS_FIXED_SIZE; |
| 1071 | |
Hante Meuleman | c495810 | 2015-11-25 11:32:41 +0100 | [diff] [blame] | 1072 | err = escan->run(cfg, ifp, request); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1073 | if (err) |
Daniel Kim | 5e787f7 | 2014-06-21 12:11:18 +0200 | [diff] [blame] | 1074 | brcmf_scan_config_mpc(ifp, 1); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1075 | return err; |
| 1076 | } |
| 1077 | |
| 1078 | static s32 |
Arend van Spriel | a0f472a | 2013-04-05 10:57:49 +0200 | [diff] [blame] | 1079 | brcmf_cfg80211_escan(struct wiphy *wiphy, struct brcmf_cfg80211_vif *vif, |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1080 | struct cfg80211_scan_request *request, |
| 1081 | struct cfg80211_ssid *this_ssid) |
| 1082 | { |
Arend van Spriel | a0f472a | 2013-04-05 10:57:49 +0200 | [diff] [blame] | 1083 | struct brcmf_if *ifp = vif->ifp; |
| 1084 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1085 | struct cfg80211_ssid *ssids; |
Hante Meuleman | 81f5dcb | 2012-10-22 10:36:14 -0700 | [diff] [blame] | 1086 | u32 passive_scan; |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1087 | bool escan_req; |
| 1088 | bool spec_scan; |
| 1089 | s32 err; |
Hante Meuleman | 675f5d8 | 2015-12-10 13:43:01 +0100 | [diff] [blame] | 1090 | struct brcmf_ssid_le ssid_le; |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1091 | u32 SSID_len; |
| 1092 | |
Arend van Spriel | 4e8a008 | 2012-12-05 15:26:03 +0100 | [diff] [blame] | 1093 | brcmf_dbg(SCAN, "START ESCAN\n"); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1094 | |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 1095 | if (test_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status)) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1096 | brcmf_err("Scanning already: status (%lu)\n", cfg->scan_status); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1097 | return -EAGAIN; |
| 1098 | } |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 1099 | if (test_bit(BRCMF_SCAN_STATUS_ABORT, &cfg->scan_status)) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1100 | brcmf_err("Scanning being aborted: status (%lu)\n", |
| 1101 | cfg->scan_status); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1102 | return -EAGAIN; |
| 1103 | } |
Arend van Spriel | 1687eee | 2013-04-23 12:53:11 +0200 | [diff] [blame] | 1104 | if (test_bit(BRCMF_SCAN_STATUS_SUPPRESS, &cfg->scan_status)) { |
| 1105 | brcmf_err("Scanning suppressed: status (%lu)\n", |
| 1106 | cfg->scan_status); |
| 1107 | return -EAGAIN; |
| 1108 | } |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 1109 | if (test_bit(BRCMF_VIF_STATUS_CONNECTING, &ifp->vif->sme_state)) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1110 | brcmf_err("Connecting: status (%lu)\n", ifp->vif->sme_state); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1111 | return -EAGAIN; |
| 1112 | } |
| 1113 | |
Hante Meuleman | 0f8ffe1 | 2013-02-08 15:53:42 +0100 | [diff] [blame] | 1114 | /* 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] | 1115 | if (vif == cfg->p2p.bss_idx[P2PAPI_BSSCFG_DEVICE].vif) |
| 1116 | vif = cfg->p2p.bss_idx[P2PAPI_BSSCFG_PRIMARY].vif; |
Hante Meuleman | 0f8ffe1 | 2013-02-08 15:53:42 +0100 | [diff] [blame] | 1117 | |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1118 | escan_req = false; |
| 1119 | if (request) { |
| 1120 | /* scan bss */ |
| 1121 | ssids = request->ssids; |
| 1122 | escan_req = true; |
| 1123 | } else { |
| 1124 | /* scan in ibss */ |
| 1125 | /* we don't do escan in ibss */ |
| 1126 | ssids = this_ssid; |
| 1127 | } |
| 1128 | |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 1129 | cfg->scan_request = request; |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 1130 | set_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1131 | if (escan_req) { |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 1132 | cfg->escan_info.run = brcmf_run_escan; |
Arend van Spriel | a0f472a | 2013-04-05 10:57:49 +0200 | [diff] [blame] | 1133 | err = brcmf_p2p_scan_prep(wiphy, request, vif); |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 1134 | if (err) |
| 1135 | goto scan_out; |
| 1136 | |
Arend van Spriel | a0f472a | 2013-04-05 10:57:49 +0200 | [diff] [blame] | 1137 | err = brcmf_do_escan(cfg, wiphy, vif->ifp, request); |
Arend van Spriel | 2cb941c | 2012-11-05 16:22:10 -0800 | [diff] [blame] | 1138 | if (err) |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1139 | goto scan_out; |
| 1140 | } else { |
Arend van Spriel | 4e8a008 | 2012-12-05 15:26:03 +0100 | [diff] [blame] | 1141 | brcmf_dbg(SCAN, "ssid \"%s\", ssid_len (%d)\n", |
| 1142 | ssids->ssid, ssids->ssid_len); |
Hante Meuleman | 675f5d8 | 2015-12-10 13:43:01 +0100 | [diff] [blame] | 1143 | memset(&ssid_le, 0, sizeof(ssid_le)); |
| 1144 | SSID_len = min_t(u8, sizeof(ssid_le.SSID), ssids->ssid_len); |
| 1145 | ssid_le.SSID_len = cpu_to_le32(0); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1146 | spec_scan = false; |
| 1147 | if (SSID_len) { |
Hante Meuleman | 675f5d8 | 2015-12-10 13:43:01 +0100 | [diff] [blame] | 1148 | memcpy(ssid_le.SSID, ssids->ssid, SSID_len); |
| 1149 | ssid_le.SSID_len = cpu_to_le32(SSID_len); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1150 | spec_scan = true; |
| 1151 | } else |
Arend van Spriel | 4e8a008 | 2012-12-05 15:26:03 +0100 | [diff] [blame] | 1152 | brcmf_dbg(SCAN, "Broadcast scan\n"); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1153 | |
Hante Meuleman | 81f5dcb | 2012-10-22 10:36:14 -0700 | [diff] [blame] | 1154 | passive_scan = cfg->active_scan ? 0 : 1; |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 1155 | err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_PASSIVE_SCAN, |
Hante Meuleman | 81f5dcb | 2012-10-22 10:36:14 -0700 | [diff] [blame] | 1156 | passive_scan); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1157 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1158 | brcmf_err("WLC_SET_PASSIVE_SCAN error (%d)\n", err); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1159 | goto scan_out; |
| 1160 | } |
Daniel Kim | 5e787f7 | 2014-06-21 12:11:18 +0200 | [diff] [blame] | 1161 | brcmf_scan_config_mpc(ifp, 0); |
Hante Meuleman | 675f5d8 | 2015-12-10 13:43:01 +0100 | [diff] [blame] | 1162 | err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SCAN, &ssid_le, |
| 1163 | sizeof(ssid_le)); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1164 | if (err) { |
| 1165 | if (err == -EBUSY) |
Arend van Spriel | 647c9ae | 2012-12-05 15:26:01 +0100 | [diff] [blame] | 1166 | brcmf_dbg(INFO, "BUSY: scan for \"%s\" canceled\n", |
Hante Meuleman | 675f5d8 | 2015-12-10 13:43:01 +0100 | [diff] [blame] | 1167 | ssid_le.SSID); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1168 | else |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1169 | brcmf_err("WLC_SCAN error (%d)\n", err); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1170 | |
Daniel Kim | 5e787f7 | 2014-06-21 12:11:18 +0200 | [diff] [blame] | 1171 | brcmf_scan_config_mpc(ifp, 1); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1172 | goto scan_out; |
| 1173 | } |
| 1174 | } |
| 1175 | |
Hante Meuleman | 661fa95 | 2015-02-06 18:36:47 +0100 | [diff] [blame] | 1176 | /* Arm scan timeout timer */ |
| 1177 | mod_timer(&cfg->escan_timeout, jiffies + |
Hante Meuleman | d536733 | 2016-02-17 11:26:51 +0100 | [diff] [blame] | 1178 | BRCMF_ESCAN_TIMER_INTERVAL_MS * HZ / 1000); |
Hante Meuleman | 661fa95 | 2015-02-06 18:36:47 +0100 | [diff] [blame] | 1179 | |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1180 | return 0; |
| 1181 | |
| 1182 | scan_out: |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 1183 | clear_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status); |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 1184 | cfg->scan_request = NULL; |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1185 | return err; |
| 1186 | } |
| 1187 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1188 | static s32 |
Arend van Spriel | 0abb5f21 | 2012-10-22 13:55:32 -0700 | [diff] [blame] | 1189 | brcmf_cfg80211_scan(struct wiphy *wiphy, struct cfg80211_scan_request *request) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1190 | { |
Arend van Spriel | a0f472a | 2013-04-05 10:57:49 +0200 | [diff] [blame] | 1191 | struct brcmf_cfg80211_vif *vif; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1192 | s32 err = 0; |
| 1193 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 1194 | brcmf_dbg(TRACE, "Enter\n"); |
Arend van Spriel | a0f472a | 2013-04-05 10:57:49 +0200 | [diff] [blame] | 1195 | vif = container_of(request->wdev, struct brcmf_cfg80211_vif, wdev); |
| 1196 | if (!check_vif_up(vif)) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1197 | return -EIO; |
| 1198 | |
Arend van Spriel | a0f472a | 2013-04-05 10:57:49 +0200 | [diff] [blame] | 1199 | err = brcmf_cfg80211_escan(wiphy, vif, request, NULL); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1200 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1201 | if (err) |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1202 | brcmf_err("scan error (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1203 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 1204 | brcmf_dbg(TRACE, "Exit\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1205 | return err; |
| 1206 | } |
| 1207 | |
| 1208 | static s32 brcmf_set_rts(struct net_device *ndev, u32 rts_threshold) |
| 1209 | { |
| 1210 | s32 err = 0; |
| 1211 | |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 1212 | err = brcmf_fil_iovar_int_set(netdev_priv(ndev), "rtsthresh", |
| 1213 | rts_threshold); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1214 | if (err) |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1215 | brcmf_err("Error (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1216 | |
| 1217 | return err; |
| 1218 | } |
| 1219 | |
| 1220 | static s32 brcmf_set_frag(struct net_device *ndev, u32 frag_threshold) |
| 1221 | { |
| 1222 | s32 err = 0; |
| 1223 | |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 1224 | err = brcmf_fil_iovar_int_set(netdev_priv(ndev), "fragthresh", |
| 1225 | frag_threshold); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1226 | if (err) |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1227 | brcmf_err("Error (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1228 | |
| 1229 | return err; |
| 1230 | } |
| 1231 | |
| 1232 | static s32 brcmf_set_retry(struct net_device *ndev, u32 retry, bool l) |
| 1233 | { |
| 1234 | s32 err = 0; |
Hante Meuleman | b87e2c4 | 2012-11-14 18:46:23 -0800 | [diff] [blame] | 1235 | u32 cmd = (l ? BRCMF_C_SET_LRL : BRCMF_C_SET_SRL); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1236 | |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 1237 | err = brcmf_fil_cmd_int_set(netdev_priv(ndev), cmd, retry); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1238 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1239 | brcmf_err("cmd (%d) , error (%d)\n", cmd, err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1240 | return err; |
| 1241 | } |
| 1242 | return err; |
| 1243 | } |
| 1244 | |
| 1245 | static s32 brcmf_cfg80211_set_wiphy_params(struct wiphy *wiphy, u32 changed) |
| 1246 | { |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 1247 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); |
| 1248 | struct net_device *ndev = cfg_to_ndev(cfg); |
Arend van Spriel | 0abb5f21 | 2012-10-22 13:55:32 -0700 | [diff] [blame] | 1249 | struct brcmf_if *ifp = netdev_priv(ndev); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1250 | s32 err = 0; |
| 1251 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 1252 | brcmf_dbg(TRACE, "Enter\n"); |
Arend van Spriel | ce81e31 | 2012-10-22 13:55:37 -0700 | [diff] [blame] | 1253 | if (!check_vif_up(ifp->vif)) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1254 | return -EIO; |
| 1255 | |
| 1256 | if (changed & WIPHY_PARAM_RTS_THRESHOLD && |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 1257 | (cfg->conf->rts_threshold != wiphy->rts_threshold)) { |
| 1258 | cfg->conf->rts_threshold = wiphy->rts_threshold; |
| 1259 | err = brcmf_set_rts(ndev, cfg->conf->rts_threshold); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1260 | if (!err) |
| 1261 | goto done; |
| 1262 | } |
| 1263 | if (changed & WIPHY_PARAM_FRAG_THRESHOLD && |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 1264 | (cfg->conf->frag_threshold != wiphy->frag_threshold)) { |
| 1265 | cfg->conf->frag_threshold = wiphy->frag_threshold; |
| 1266 | err = brcmf_set_frag(ndev, cfg->conf->frag_threshold); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1267 | if (!err) |
| 1268 | goto done; |
| 1269 | } |
| 1270 | if (changed & WIPHY_PARAM_RETRY_LONG |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 1271 | && (cfg->conf->retry_long != wiphy->retry_long)) { |
| 1272 | cfg->conf->retry_long = wiphy->retry_long; |
| 1273 | err = brcmf_set_retry(ndev, cfg->conf->retry_long, true); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1274 | if (!err) |
| 1275 | goto done; |
| 1276 | } |
| 1277 | if (changed & WIPHY_PARAM_RETRY_SHORT |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 1278 | && (cfg->conf->retry_short != wiphy->retry_short)) { |
| 1279 | cfg->conf->retry_short = wiphy->retry_short; |
| 1280 | err = brcmf_set_retry(ndev, cfg->conf->retry_short, false); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1281 | if (!err) |
| 1282 | goto done; |
| 1283 | } |
| 1284 | |
| 1285 | done: |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 1286 | brcmf_dbg(TRACE, "Exit\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1287 | return err; |
| 1288 | } |
| 1289 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1290 | static void brcmf_init_prof(struct brcmf_cfg80211_profile *prof) |
| 1291 | { |
| 1292 | memset(prof, 0, sizeof(*prof)); |
| 1293 | } |
| 1294 | |
Arend van Spriel | 9b7a0dd | 2015-01-25 20:31:33 +0100 | [diff] [blame] | 1295 | static u16 brcmf_map_fw_linkdown_reason(const struct brcmf_event_msg *e) |
| 1296 | { |
| 1297 | u16 reason; |
| 1298 | |
| 1299 | switch (e->event_code) { |
| 1300 | case BRCMF_E_DEAUTH: |
| 1301 | case BRCMF_E_DEAUTH_IND: |
| 1302 | case BRCMF_E_DISASSOC_IND: |
| 1303 | reason = e->reason; |
| 1304 | break; |
| 1305 | case BRCMF_E_LINK: |
| 1306 | default: |
| 1307 | reason = 0; |
| 1308 | break; |
| 1309 | } |
| 1310 | return reason; |
| 1311 | } |
| 1312 | |
| 1313 | 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] | 1314 | { |
Piotr Haber | 61730d4 | 2013-04-23 12:53:12 +0200 | [diff] [blame] | 1315 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(vif->wdev.wiphy); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1316 | s32 err = 0; |
| 1317 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 1318 | brcmf_dbg(TRACE, "Enter\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1319 | |
Hante Meuleman | b0a7908 | 2015-12-10 13:43:07 +0100 | [diff] [blame] | 1320 | 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] | 1321 | brcmf_dbg(INFO, "Call WLC_DISASSOC to stop excess roaming\n "); |
Arend van Spriel | 903e0ee | 2012-11-28 21:44:11 +0100 | [diff] [blame] | 1322 | err = brcmf_fil_cmd_data_set(vif->ifp, |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 1323 | BRCMF_C_DISASSOC, NULL, 0); |
Arend van Spriel | a538ae3 | 2013-07-25 23:01:34 +0200 | [diff] [blame] | 1324 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1325 | brcmf_err("WLC_DISASSOC failed (%d)\n", err); |
Arend van Spriel | a538ae3 | 2013-07-25 23:01:34 +0200 | [diff] [blame] | 1326 | } |
Hante Meuleman | b0a7908 | 2015-12-10 13:43:07 +0100 | [diff] [blame] | 1327 | if ((vif->wdev.iftype == NL80211_IFTYPE_STATION) || |
| 1328 | (vif->wdev.iftype == NL80211_IFTYPE_P2P_CLIENT)) |
| 1329 | cfg80211_disconnected(vif->wdev.netdev, reason, NULL, 0, |
| 1330 | true, GFP_KERNEL); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1331 | } |
Arend van Spriel | 903e0ee | 2012-11-28 21:44:11 +0100 | [diff] [blame] | 1332 | clear_bit(BRCMF_VIF_STATUS_CONNECTING, &vif->sme_state); |
Piotr Haber | 61730d4 | 2013-04-23 12:53:12 +0200 | [diff] [blame] | 1333 | clear_bit(BRCMF_SCAN_STATUS_SUPPRESS, &cfg->scan_status); |
| 1334 | brcmf_btcoex_set_mode(vif, BRCMF_BTCOEX_ENABLED, 0); |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 1335 | brcmf_dbg(TRACE, "Exit\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1336 | } |
| 1337 | |
| 1338 | static s32 |
| 1339 | brcmf_cfg80211_join_ibss(struct wiphy *wiphy, struct net_device *ndev, |
| 1340 | struct cfg80211_ibss_params *params) |
| 1341 | { |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 1342 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); |
Arend van Spriel | 0abb5f21 | 2012-10-22 13:55:32 -0700 | [diff] [blame] | 1343 | struct brcmf_if *ifp = netdev_priv(ndev); |
| 1344 | struct brcmf_cfg80211_profile *profile = &ifp->vif->profile; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1345 | struct brcmf_join_params join_params; |
| 1346 | size_t join_params_size = 0; |
| 1347 | s32 err = 0; |
| 1348 | s32 wsec = 0; |
| 1349 | s32 bcnprd; |
Hante Meuleman | 1701261 | 2013-02-06 18:40:44 +0100 | [diff] [blame] | 1350 | u16 chanspec; |
Hante Meuleman | e9a6ca8 | 2015-11-25 11:32:37 +0100 | [diff] [blame] | 1351 | u32 ssid_len; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1352 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 1353 | brcmf_dbg(TRACE, "Enter\n"); |
Arend van Spriel | ce81e31 | 2012-10-22 13:55:37 -0700 | [diff] [blame] | 1354 | if (!check_vif_up(ifp->vif)) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1355 | return -EIO; |
| 1356 | |
| 1357 | if (params->ssid) |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 1358 | brcmf_dbg(CONN, "SSID: %s\n", params->ssid); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1359 | else { |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 1360 | brcmf_dbg(CONN, "SSID: NULL, Not supported\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1361 | return -EOPNOTSUPP; |
| 1362 | } |
| 1363 | |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 1364 | set_bit(BRCMF_VIF_STATUS_CONNECTING, &ifp->vif->sme_state); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1365 | |
| 1366 | if (params->bssid) |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 1367 | brcmf_dbg(CONN, "BSSID: %pM\n", params->bssid); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1368 | else |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 1369 | brcmf_dbg(CONN, "No BSSID specified\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1370 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1371 | if (params->chandef.chan) |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 1372 | brcmf_dbg(CONN, "channel: %d\n", |
| 1373 | params->chandef.chan->center_freq); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1374 | else |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 1375 | brcmf_dbg(CONN, "no channel specified\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1376 | |
| 1377 | if (params->channel_fixed) |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 1378 | brcmf_dbg(CONN, "fixed channel required\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1379 | else |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 1380 | brcmf_dbg(CONN, "no fixed channel required\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1381 | |
| 1382 | if (params->ie && params->ie_len) |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 1383 | brcmf_dbg(CONN, "ie len: %d\n", params->ie_len); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1384 | else |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 1385 | brcmf_dbg(CONN, "no ie specified\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1386 | |
| 1387 | if (params->beacon_interval) |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 1388 | brcmf_dbg(CONN, "beacon interval: %d\n", |
| 1389 | params->beacon_interval); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1390 | else |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 1391 | brcmf_dbg(CONN, "no beacon interval specified\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1392 | |
| 1393 | if (params->basic_rates) |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 1394 | brcmf_dbg(CONN, "basic rates: %08X\n", params->basic_rates); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1395 | else |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 1396 | brcmf_dbg(CONN, "no basic rates specified\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1397 | |
| 1398 | if (params->privacy) |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 1399 | brcmf_dbg(CONN, "privacy required\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1400 | else |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 1401 | brcmf_dbg(CONN, "no privacy required\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1402 | |
| 1403 | /* Configure Privacy for starter */ |
| 1404 | if (params->privacy) |
| 1405 | wsec |= WEP_ENABLED; |
| 1406 | |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 1407 | err = brcmf_fil_iovar_int_set(ifp, "wsec", wsec); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1408 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1409 | brcmf_err("wsec failed (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1410 | goto done; |
| 1411 | } |
| 1412 | |
| 1413 | /* Configure Beacon Interval for starter */ |
| 1414 | if (params->beacon_interval) |
| 1415 | bcnprd = params->beacon_interval; |
| 1416 | else |
| 1417 | bcnprd = 100; |
| 1418 | |
Hante Meuleman | b87e2c4 | 2012-11-14 18:46:23 -0800 | [diff] [blame] | 1419 | 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] | 1420 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1421 | brcmf_err("WLC_SET_BCNPRD failed (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1422 | goto done; |
| 1423 | } |
| 1424 | |
| 1425 | /* Configure required join parameter */ |
| 1426 | memset(&join_params, 0, sizeof(struct brcmf_join_params)); |
| 1427 | |
| 1428 | /* SSID */ |
Hante Meuleman | e9a6ca8 | 2015-11-25 11:32:37 +0100 | [diff] [blame] | 1429 | ssid_len = min_t(u32, params->ssid_len, IEEE80211_MAX_SSID_LEN); |
| 1430 | memcpy(join_params.ssid_le.SSID, params->ssid, ssid_len); |
| 1431 | join_params.ssid_le.SSID_len = cpu_to_le32(ssid_len); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1432 | join_params_size = sizeof(join_params.ssid_le); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1433 | |
| 1434 | /* BSSID */ |
| 1435 | if (params->bssid) { |
| 1436 | memcpy(join_params.params_le.bssid, params->bssid, ETH_ALEN); |
Hante Meuleman | e9a6ca8 | 2015-11-25 11:32:37 +0100 | [diff] [blame] | 1437 | join_params_size += BRCMF_ASSOC_PARAMS_FIXED_SIZE; |
Arend van Spriel | 6c8c4f7 | 2012-09-27 14:17:57 +0200 | [diff] [blame] | 1438 | memcpy(profile->bssid, params->bssid, ETH_ALEN); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1439 | } else { |
Joe Perches | 93803b3 | 2015-03-02 19:54:49 -0800 | [diff] [blame] | 1440 | eth_broadcast_addr(join_params.params_le.bssid); |
| 1441 | eth_zero_addr(profile->bssid); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1442 | } |
| 1443 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1444 | /* Channel */ |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1445 | if (params->chandef.chan) { |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1446 | u32 target_channel; |
| 1447 | |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 1448 | cfg->channel = |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1449 | ieee80211_frequency_to_channel( |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1450 | params->chandef.chan->center_freq); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1451 | if (params->channel_fixed) { |
| 1452 | /* adding chanspec */ |
Arend van Spriel | 600a897 | 2014-05-12 10:47:39 +0200 | [diff] [blame] | 1453 | chanspec = chandef_to_chanspec(&cfg->d11inf, |
| 1454 | ¶ms->chandef); |
Hante Meuleman | 1701261 | 2013-02-06 18:40:44 +0100 | [diff] [blame] | 1455 | join_params.params_le.chanspec_list[0] = |
| 1456 | cpu_to_le16(chanspec); |
| 1457 | join_params.params_le.chanspec_num = cpu_to_le32(1); |
| 1458 | join_params_size += sizeof(join_params.params_le); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1459 | } |
| 1460 | |
| 1461 | /* set channel for starter */ |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 1462 | target_channel = cfg->channel; |
Hante Meuleman | b87e2c4 | 2012-11-14 18:46:23 -0800 | [diff] [blame] | 1463 | err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_CHANNEL, |
Hante Meuleman | 81f5dcb | 2012-10-22 10:36:14 -0700 | [diff] [blame] | 1464 | target_channel); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1465 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1466 | brcmf_err("WLC_SET_CHANNEL failed (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1467 | goto done; |
| 1468 | } |
| 1469 | } else |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 1470 | cfg->channel = 0; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1471 | |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 1472 | cfg->ibss_starter = false; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1473 | |
| 1474 | |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 1475 | err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SET_SSID, |
Hante Meuleman | 81f5dcb | 2012-10-22 10:36:14 -0700 | [diff] [blame] | 1476 | &join_params, join_params_size); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1477 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1478 | brcmf_err("WLC_SET_SSID failed (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1479 | goto done; |
| 1480 | } |
| 1481 | |
| 1482 | done: |
| 1483 | if (err) |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 1484 | clear_bit(BRCMF_VIF_STATUS_CONNECTING, &ifp->vif->sme_state); |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 1485 | brcmf_dbg(TRACE, "Exit\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1486 | return err; |
| 1487 | } |
| 1488 | |
| 1489 | static s32 |
| 1490 | brcmf_cfg80211_leave_ibss(struct wiphy *wiphy, struct net_device *ndev) |
| 1491 | { |
Arend van Spriel | 0abb5f21 | 2012-10-22 13:55:32 -0700 | [diff] [blame] | 1492 | struct brcmf_if *ifp = netdev_priv(ndev); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1493 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 1494 | brcmf_dbg(TRACE, "Enter\n"); |
Hante Meuleman | 6a98d64 | 2016-01-02 09:41:40 +0100 | [diff] [blame] | 1495 | if (!check_vif_up(ifp->vif)) { |
| 1496 | /* When driver is being unloaded, it can end up here. If an |
| 1497 | * error is returned then later on a debug trace in the wireless |
| 1498 | * core module will be printed. To avoid this 0 is returned. |
| 1499 | */ |
| 1500 | return 0; |
| 1501 | } |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1502 | |
Arend van Spriel | 9b7a0dd | 2015-01-25 20:31:33 +0100 | [diff] [blame] | 1503 | brcmf_link_down(ifp->vif, WLAN_REASON_DEAUTH_LEAVING); |
Hante Meuleman | 42e0ed0 | 2016-01-05 11:05:50 +0100 | [diff] [blame] | 1504 | brcmf_net_setcarrier(ifp, false); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1505 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 1506 | brcmf_dbg(TRACE, "Exit\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1507 | |
Peter Senna Tschudin | 12f3237 | 2014-05-31 10:14:06 -0300 | [diff] [blame] | 1508 | return 0; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1509 | } |
| 1510 | |
| 1511 | static s32 brcmf_set_wpa_version(struct net_device *ndev, |
| 1512 | struct cfg80211_connect_params *sme) |
| 1513 | { |
Arend van Spriel | 6ac4f4e | 2012-10-22 13:55:31 -0700 | [diff] [blame] | 1514 | struct brcmf_cfg80211_profile *profile = ndev_to_prof(ndev); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1515 | struct brcmf_cfg80211_security *sec; |
| 1516 | s32 val = 0; |
| 1517 | s32 err = 0; |
| 1518 | |
| 1519 | if (sme->crypto.wpa_versions & NL80211_WPA_VERSION_1) |
| 1520 | val = WPA_AUTH_PSK | WPA_AUTH_UNSPECIFIED; |
| 1521 | else if (sme->crypto.wpa_versions & NL80211_WPA_VERSION_2) |
| 1522 | val = WPA2_AUTH_PSK | WPA2_AUTH_UNSPECIFIED; |
| 1523 | else |
| 1524 | val = WPA_AUTH_DISABLED; |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 1525 | brcmf_dbg(CONN, "setting wpa_auth to 0x%0x\n", val); |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 1526 | 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] | 1527 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1528 | brcmf_err("set wpa_auth failed (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1529 | return err; |
| 1530 | } |
Arend van Spriel | 06bb123 | 2012-09-27 14:17:56 +0200 | [diff] [blame] | 1531 | sec = &profile->sec; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1532 | sec->wpa_versions = sme->crypto.wpa_versions; |
| 1533 | return err; |
| 1534 | } |
| 1535 | |
| 1536 | static s32 brcmf_set_auth_type(struct net_device *ndev, |
| 1537 | struct cfg80211_connect_params *sme) |
| 1538 | { |
Arend van Spriel | 6ac4f4e | 2012-10-22 13:55:31 -0700 | [diff] [blame] | 1539 | struct brcmf_cfg80211_profile *profile = ndev_to_prof(ndev); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1540 | struct brcmf_cfg80211_security *sec; |
| 1541 | s32 val = 0; |
| 1542 | s32 err = 0; |
| 1543 | |
| 1544 | switch (sme->auth_type) { |
| 1545 | case NL80211_AUTHTYPE_OPEN_SYSTEM: |
| 1546 | val = 0; |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 1547 | brcmf_dbg(CONN, "open system\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1548 | break; |
| 1549 | case NL80211_AUTHTYPE_SHARED_KEY: |
| 1550 | val = 1; |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 1551 | brcmf_dbg(CONN, "shared key\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1552 | break; |
| 1553 | case NL80211_AUTHTYPE_AUTOMATIC: |
| 1554 | val = 2; |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 1555 | brcmf_dbg(CONN, "automatic\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1556 | break; |
| 1557 | case NL80211_AUTHTYPE_NETWORK_EAP: |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 1558 | brcmf_dbg(CONN, "network eap\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1559 | default: |
| 1560 | val = 2; |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1561 | brcmf_err("invalid auth type (%d)\n", sme->auth_type); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1562 | break; |
| 1563 | } |
| 1564 | |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 1565 | err = brcmf_fil_bsscfg_int_set(netdev_priv(ndev), "auth", val); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1566 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1567 | brcmf_err("set auth failed (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1568 | return err; |
| 1569 | } |
Arend van Spriel | 06bb123 | 2012-09-27 14:17:56 +0200 | [diff] [blame] | 1570 | sec = &profile->sec; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1571 | sec->auth_type = sme->auth_type; |
| 1572 | return err; |
| 1573 | } |
| 1574 | |
| 1575 | static s32 |
Daniel Kim | 87b7e9e | 2014-03-25 21:45:09 +0100 | [diff] [blame] | 1576 | brcmf_set_wsec_mode(struct net_device *ndev, |
Hante Meuleman | 240d61a | 2016-02-17 11:27:10 +0100 | [diff] [blame] | 1577 | struct cfg80211_connect_params *sme) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1578 | { |
Arend van Spriel | 6ac4f4e | 2012-10-22 13:55:31 -0700 | [diff] [blame] | 1579 | struct brcmf_cfg80211_profile *profile = ndev_to_prof(ndev); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1580 | struct brcmf_cfg80211_security *sec; |
| 1581 | s32 pval = 0; |
| 1582 | s32 gval = 0; |
Daniel Kim | 87b7e9e | 2014-03-25 21:45:09 +0100 | [diff] [blame] | 1583 | s32 wsec; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1584 | s32 err = 0; |
| 1585 | |
| 1586 | if (sme->crypto.n_ciphers_pairwise) { |
| 1587 | switch (sme->crypto.ciphers_pairwise[0]) { |
| 1588 | case WLAN_CIPHER_SUITE_WEP40: |
| 1589 | case WLAN_CIPHER_SUITE_WEP104: |
| 1590 | pval = WEP_ENABLED; |
| 1591 | break; |
| 1592 | case WLAN_CIPHER_SUITE_TKIP: |
| 1593 | pval = TKIP_ENABLED; |
| 1594 | break; |
| 1595 | case WLAN_CIPHER_SUITE_CCMP: |
| 1596 | pval = AES_ENABLED; |
| 1597 | break; |
| 1598 | case WLAN_CIPHER_SUITE_AES_CMAC: |
| 1599 | pval = AES_ENABLED; |
| 1600 | break; |
| 1601 | default: |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1602 | brcmf_err("invalid cipher pairwise (%d)\n", |
| 1603 | sme->crypto.ciphers_pairwise[0]); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1604 | return -EINVAL; |
| 1605 | } |
| 1606 | } |
| 1607 | if (sme->crypto.cipher_group) { |
| 1608 | switch (sme->crypto.cipher_group) { |
| 1609 | case WLAN_CIPHER_SUITE_WEP40: |
| 1610 | case WLAN_CIPHER_SUITE_WEP104: |
| 1611 | gval = WEP_ENABLED; |
| 1612 | break; |
| 1613 | case WLAN_CIPHER_SUITE_TKIP: |
| 1614 | gval = TKIP_ENABLED; |
| 1615 | break; |
| 1616 | case WLAN_CIPHER_SUITE_CCMP: |
| 1617 | gval = AES_ENABLED; |
| 1618 | break; |
| 1619 | case WLAN_CIPHER_SUITE_AES_CMAC: |
| 1620 | gval = AES_ENABLED; |
| 1621 | break; |
| 1622 | default: |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1623 | brcmf_err("invalid cipher group (%d)\n", |
| 1624 | sme->crypto.cipher_group); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1625 | return -EINVAL; |
| 1626 | } |
| 1627 | } |
| 1628 | |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 1629 | brcmf_dbg(CONN, "pval (%d) gval (%d)\n", pval, gval); |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 1630 | /* In case of privacy, but no security and WPS then simulate */ |
| 1631 | /* setting AES. WPS-2.0 allows no security */ |
| 1632 | if (brcmf_find_wpsie(sme->ie, sme->ie_len) && !pval && !gval && |
| 1633 | sme->privacy) |
| 1634 | pval = AES_ENABLED; |
Daniel Kim | 87b7e9e | 2014-03-25 21:45:09 +0100 | [diff] [blame] | 1635 | |
Hante Meuleman | 240d61a | 2016-02-17 11:27:10 +0100 | [diff] [blame] | 1636 | wsec = pval | gval; |
Daniel Kim | 87b7e9e | 2014-03-25 21:45:09 +0100 | [diff] [blame] | 1637 | err = brcmf_fil_bsscfg_int_set(netdev_priv(ndev), "wsec", wsec); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1638 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1639 | brcmf_err("error (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1640 | return err; |
| 1641 | } |
| 1642 | |
Arend van Spriel | 06bb123 | 2012-09-27 14:17:56 +0200 | [diff] [blame] | 1643 | sec = &profile->sec; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1644 | sec->cipher_pairwise = sme->crypto.ciphers_pairwise[0]; |
| 1645 | sec->cipher_group = sme->crypto.cipher_group; |
| 1646 | |
| 1647 | return err; |
| 1648 | } |
| 1649 | |
| 1650 | static s32 |
| 1651 | brcmf_set_key_mgmt(struct net_device *ndev, struct cfg80211_connect_params *sme) |
| 1652 | { |
Hante Meuleman | 240d61a | 2016-02-17 11:27:10 +0100 | [diff] [blame] | 1653 | struct brcmf_if *ifp = netdev_priv(ndev); |
| 1654 | s32 val; |
| 1655 | s32 err; |
| 1656 | const struct brcmf_tlv *rsn_ie; |
| 1657 | const u8 *ie; |
| 1658 | u32 ie_len; |
| 1659 | u32 offset; |
| 1660 | u16 rsn_cap; |
| 1661 | u32 mfp; |
| 1662 | u16 count; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1663 | |
Hante Meuleman | 240d61a | 2016-02-17 11:27:10 +0100 | [diff] [blame] | 1664 | if (!sme->crypto.n_akm_suites) |
| 1665 | return 0; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1666 | |
Hante Meuleman | 240d61a | 2016-02-17 11:27:10 +0100 | [diff] [blame] | 1667 | err = brcmf_fil_bsscfg_int_get(netdev_priv(ndev), "wpa_auth", &val); |
| 1668 | if (err) { |
| 1669 | brcmf_err("could not get wpa_auth (%d)\n", err); |
| 1670 | return err; |
| 1671 | } |
| 1672 | if (val & (WPA_AUTH_PSK | WPA_AUTH_UNSPECIFIED)) { |
| 1673 | switch (sme->crypto.akm_suites[0]) { |
| 1674 | case WLAN_AKM_SUITE_8021X: |
| 1675 | val = WPA_AUTH_UNSPECIFIED; |
| 1676 | break; |
| 1677 | case WLAN_AKM_SUITE_PSK: |
| 1678 | val = WPA_AUTH_PSK; |
| 1679 | break; |
| 1680 | default: |
| 1681 | brcmf_err("invalid cipher group (%d)\n", |
| 1682 | sme->crypto.cipher_group); |
| 1683 | return -EINVAL; |
| 1684 | } |
| 1685 | } else if (val & (WPA2_AUTH_PSK | WPA2_AUTH_UNSPECIFIED)) { |
| 1686 | switch (sme->crypto.akm_suites[0]) { |
| 1687 | case WLAN_AKM_SUITE_8021X: |
| 1688 | val = WPA2_AUTH_UNSPECIFIED; |
| 1689 | break; |
| 1690 | case WLAN_AKM_SUITE_8021X_SHA256: |
| 1691 | val = WPA2_AUTH_1X_SHA256; |
| 1692 | break; |
| 1693 | case WLAN_AKM_SUITE_PSK_SHA256: |
| 1694 | val = WPA2_AUTH_PSK_SHA256; |
| 1695 | break; |
| 1696 | case WLAN_AKM_SUITE_PSK: |
| 1697 | val = WPA2_AUTH_PSK; |
| 1698 | break; |
| 1699 | default: |
| 1700 | brcmf_err("invalid cipher group (%d)\n", |
| 1701 | sme->crypto.cipher_group); |
| 1702 | return -EINVAL; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1703 | } |
| 1704 | } |
Hante Meuleman | 240d61a | 2016-02-17 11:27:10 +0100 | [diff] [blame] | 1705 | |
| 1706 | if (!brcmf_feat_is_enabled(ifp, BRCMF_FEAT_MFP)) |
| 1707 | goto skip_mfp_config; |
| 1708 | /* The MFP mode (1 or 2) needs to be determined, parse IEs. The |
| 1709 | * IE will not be verified, just a quick search for MFP config |
| 1710 | */ |
| 1711 | rsn_ie = brcmf_parse_tlvs((const u8 *)sme->ie, sme->ie_len, |
| 1712 | WLAN_EID_RSN); |
| 1713 | if (!rsn_ie) |
| 1714 | goto skip_mfp_config; |
| 1715 | ie = (const u8 *)rsn_ie; |
| 1716 | ie_len = rsn_ie->len + TLV_HDR_LEN; |
| 1717 | /* Skip unicast suite */ |
| 1718 | offset = TLV_HDR_LEN + WPA_IE_VERSION_LEN + WPA_IE_MIN_OUI_LEN; |
| 1719 | if (offset + WPA_IE_SUITE_COUNT_LEN >= ie_len) |
| 1720 | goto skip_mfp_config; |
| 1721 | /* Skip multicast suite */ |
| 1722 | count = ie[offset] + (ie[offset + 1] << 8); |
| 1723 | offset += WPA_IE_SUITE_COUNT_LEN + (count * WPA_IE_MIN_OUI_LEN); |
| 1724 | if (offset + WPA_IE_SUITE_COUNT_LEN >= ie_len) |
| 1725 | goto skip_mfp_config; |
| 1726 | /* Skip auth key management suite(s) */ |
| 1727 | count = ie[offset] + (ie[offset + 1] << 8); |
| 1728 | offset += WPA_IE_SUITE_COUNT_LEN + (count * WPA_IE_MIN_OUI_LEN); |
| 1729 | if (offset + WPA_IE_SUITE_COUNT_LEN > ie_len) |
| 1730 | goto skip_mfp_config; |
| 1731 | /* Ready to read capabilities */ |
| 1732 | mfp = BRCMF_MFP_NONE; |
| 1733 | rsn_cap = ie[offset] + (ie[offset + 1] << 8); |
| 1734 | if (rsn_cap & RSN_CAP_MFPR_MASK) |
| 1735 | mfp = BRCMF_MFP_REQUIRED; |
| 1736 | else if (rsn_cap & RSN_CAP_MFPC_MASK) |
| 1737 | mfp = BRCMF_MFP_CAPABLE; |
| 1738 | brcmf_fil_bsscfg_int_set(netdev_priv(ndev), "mfp", mfp); |
| 1739 | |
| 1740 | skip_mfp_config: |
| 1741 | brcmf_dbg(CONN, "setting wpa_auth to %d\n", val); |
| 1742 | err = brcmf_fil_bsscfg_int_set(netdev_priv(ndev), "wpa_auth", val); |
| 1743 | if (err) { |
| 1744 | brcmf_err("could not set wpa_auth (%d)\n", err); |
| 1745 | return err; |
| 1746 | } |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1747 | |
| 1748 | return err; |
| 1749 | } |
| 1750 | |
| 1751 | static s32 |
Hante Meuleman | f09d0c0 | 2012-09-27 14:17:48 +0200 | [diff] [blame] | 1752 | brcmf_set_sharedkey(struct net_device *ndev, |
| 1753 | struct cfg80211_connect_params *sme) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1754 | { |
Arend van Spriel | 6ac4f4e | 2012-10-22 13:55:31 -0700 | [diff] [blame] | 1755 | struct brcmf_cfg80211_profile *profile = ndev_to_prof(ndev); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1756 | struct brcmf_cfg80211_security *sec; |
| 1757 | struct brcmf_wsec_key key; |
| 1758 | s32 val; |
| 1759 | s32 err = 0; |
| 1760 | |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 1761 | brcmf_dbg(CONN, "key len (%d)\n", sme->key_len); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1762 | |
Roland Vossen | a718e2f | 2011-10-12 20:51:24 +0200 | [diff] [blame] | 1763 | if (sme->key_len == 0) |
| 1764 | return 0; |
| 1765 | |
Arend van Spriel | 06bb123 | 2012-09-27 14:17:56 +0200 | [diff] [blame] | 1766 | sec = &profile->sec; |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 1767 | brcmf_dbg(CONN, "wpa_versions 0x%x cipher_pairwise 0x%x\n", |
| 1768 | sec->wpa_versions, sec->cipher_pairwise); |
Roland Vossen | a718e2f | 2011-10-12 20:51:24 +0200 | [diff] [blame] | 1769 | |
| 1770 | if (sec->wpa_versions & (NL80211_WPA_VERSION_1 | NL80211_WPA_VERSION_2)) |
| 1771 | return 0; |
| 1772 | |
Hante Meuleman | f09d0c0 | 2012-09-27 14:17:48 +0200 | [diff] [blame] | 1773 | if (!(sec->cipher_pairwise & |
| 1774 | (WLAN_CIPHER_SUITE_WEP40 | WLAN_CIPHER_SUITE_WEP104))) |
| 1775 | return 0; |
Roland Vossen | a718e2f | 2011-10-12 20:51:24 +0200 | [diff] [blame] | 1776 | |
Hante Meuleman | f09d0c0 | 2012-09-27 14:17:48 +0200 | [diff] [blame] | 1777 | memset(&key, 0, sizeof(key)); |
| 1778 | key.len = (u32) sme->key_len; |
| 1779 | key.index = (u32) sme->key_idx; |
| 1780 | if (key.len > sizeof(key.data)) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1781 | brcmf_err("Too long key length (%u)\n", key.len); |
Hante Meuleman | f09d0c0 | 2012-09-27 14:17:48 +0200 | [diff] [blame] | 1782 | return -EINVAL; |
| 1783 | } |
| 1784 | memcpy(key.data, sme->key, key.len); |
| 1785 | key.flags = BRCMF_PRIMARY_KEY; |
| 1786 | switch (sec->cipher_pairwise) { |
| 1787 | case WLAN_CIPHER_SUITE_WEP40: |
| 1788 | key.algo = CRYPTO_ALGO_WEP1; |
| 1789 | break; |
| 1790 | case WLAN_CIPHER_SUITE_WEP104: |
| 1791 | key.algo = CRYPTO_ALGO_WEP128; |
| 1792 | break; |
| 1793 | default: |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1794 | brcmf_err("Invalid algorithm (%d)\n", |
| 1795 | sme->crypto.ciphers_pairwise[0]); |
Hante Meuleman | f09d0c0 | 2012-09-27 14:17:48 +0200 | [diff] [blame] | 1796 | return -EINVAL; |
| 1797 | } |
| 1798 | /* Set the new key/index */ |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 1799 | brcmf_dbg(CONN, "key length (%d) key index (%d) algo (%d)\n", |
| 1800 | key.len, key.index, key.algo); |
| 1801 | brcmf_dbg(CONN, "key \"%s\"\n", key.data); |
Hante Meuleman | 118eb30 | 2014-12-21 12:43:49 +0100 | [diff] [blame] | 1802 | err = send_key_to_dongle(netdev_priv(ndev), &key); |
Hante Meuleman | f09d0c0 | 2012-09-27 14:17:48 +0200 | [diff] [blame] | 1803 | if (err) |
| 1804 | return err; |
| 1805 | |
| 1806 | if (sec->auth_type == NL80211_AUTHTYPE_SHARED_KEY) { |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 1807 | brcmf_dbg(CONN, "set auth_type to shared key\n"); |
Hante Meuleman | f09d0c0 | 2012-09-27 14:17:48 +0200 | [diff] [blame] | 1808 | val = WL_AUTH_SHARED_KEY; /* shared key */ |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 1809 | err = brcmf_fil_bsscfg_int_set(netdev_priv(ndev), "auth", val); |
Hante Meuleman | f09d0c0 | 2012-09-27 14:17:48 +0200 | [diff] [blame] | 1810 | if (err) |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1811 | brcmf_err("set auth failed (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1812 | } |
| 1813 | return err; |
| 1814 | } |
| 1815 | |
Arend van Spriel | cbb1ec9 | 2013-02-06 18:40:47 +0100 | [diff] [blame] | 1816 | static |
| 1817 | enum nl80211_auth_type brcmf_war_auth_type(struct brcmf_if *ifp, |
| 1818 | enum nl80211_auth_type type) |
| 1819 | { |
Arend van Spriel | c08437b | 2014-07-12 08:49:39 +0200 | [diff] [blame] | 1820 | if (type == NL80211_AUTHTYPE_AUTOMATIC && |
| 1821 | brcmf_feat_is_quirk_enabled(ifp, BRCMF_FEAT_QUIRK_AUTO_AUTH)) { |
| 1822 | brcmf_dbg(CONN, "WAR: use OPEN instead of AUTO\n"); |
| 1823 | type = NL80211_AUTHTYPE_OPEN_SYSTEM; |
Arend van Spriel | cbb1ec9 | 2013-02-06 18:40:47 +0100 | [diff] [blame] | 1824 | } |
| 1825 | return type; |
| 1826 | } |
| 1827 | |
Arend van Spriel | 7705ba6 | 2016-04-17 16:44:58 +0200 | [diff] [blame] | 1828 | static void brcmf_set_join_pref(struct brcmf_if *ifp, |
| 1829 | struct cfg80211_bss_selection *bss_select) |
| 1830 | { |
| 1831 | struct brcmf_join_pref_params join_pref_params[2]; |
| 1832 | enum nl80211_band band; |
| 1833 | int err, i = 0; |
| 1834 | |
| 1835 | join_pref_params[i].len = 2; |
| 1836 | join_pref_params[i].rssi_gain = 0; |
| 1837 | |
| 1838 | if (bss_select->behaviour != NL80211_BSS_SELECT_ATTR_BAND_PREF) |
| 1839 | brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_ASSOC_PREFER, WLC_BAND_AUTO); |
| 1840 | |
| 1841 | switch (bss_select->behaviour) { |
| 1842 | case __NL80211_BSS_SELECT_ATTR_INVALID: |
| 1843 | brcmf_c_set_joinpref_default(ifp); |
| 1844 | return; |
| 1845 | case NL80211_BSS_SELECT_ATTR_BAND_PREF: |
| 1846 | join_pref_params[i].type = BRCMF_JOIN_PREF_BAND; |
| 1847 | band = bss_select->param.band_pref; |
| 1848 | join_pref_params[i].band = nl80211_band_to_fwil(band); |
| 1849 | i++; |
| 1850 | break; |
| 1851 | case NL80211_BSS_SELECT_ATTR_RSSI_ADJUST: |
| 1852 | join_pref_params[i].type = BRCMF_JOIN_PREF_RSSI_DELTA; |
| 1853 | band = bss_select->param.adjust.band; |
| 1854 | join_pref_params[i].band = nl80211_band_to_fwil(band); |
| 1855 | join_pref_params[i].rssi_gain = bss_select->param.adjust.delta; |
| 1856 | i++; |
| 1857 | break; |
| 1858 | case NL80211_BSS_SELECT_ATTR_RSSI: |
| 1859 | default: |
| 1860 | break; |
| 1861 | } |
| 1862 | join_pref_params[i].type = BRCMF_JOIN_PREF_RSSI; |
| 1863 | join_pref_params[i].len = 2; |
| 1864 | join_pref_params[i].rssi_gain = 0; |
| 1865 | join_pref_params[i].band = 0; |
| 1866 | err = brcmf_fil_iovar_data_set(ifp, "join_pref", join_pref_params, |
| 1867 | sizeof(join_pref_params)); |
| 1868 | if (err) |
| 1869 | brcmf_err("Set join_pref error (%d)\n", err); |
| 1870 | } |
| 1871 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1872 | static s32 |
| 1873 | brcmf_cfg80211_connect(struct wiphy *wiphy, struct net_device *ndev, |
Arend van Spriel | cbb1ec9 | 2013-02-06 18:40:47 +0100 | [diff] [blame] | 1874 | struct cfg80211_connect_params *sme) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1875 | { |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 1876 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); |
Arend van Spriel | 0abb5f21 | 2012-10-22 13:55:32 -0700 | [diff] [blame] | 1877 | struct brcmf_if *ifp = netdev_priv(ndev); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1878 | struct ieee80211_channel *chan = sme->channel; |
| 1879 | struct brcmf_join_params join_params; |
| 1880 | size_t join_params_size; |
Johannes Berg | 4b5800f | 2014-01-15 14:55:59 +0100 | [diff] [blame] | 1881 | const struct brcmf_tlv *rsn_ie; |
| 1882 | const struct brcmf_vs_tlv *wpa_ie; |
| 1883 | const void *ie; |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 1884 | u32 ie_len; |
| 1885 | struct brcmf_ext_join_params_le *ext_join_params; |
Hante Meuleman | 1701261 | 2013-02-06 18:40:44 +0100 | [diff] [blame] | 1886 | u16 chanspec; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1887 | s32 err = 0; |
Hante Meuleman | e9a6ca8 | 2015-11-25 11:32:37 +0100 | [diff] [blame] | 1888 | u32 ssid_len; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1889 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 1890 | brcmf_dbg(TRACE, "Enter\n"); |
Arend van Spriel | ce81e31 | 2012-10-22 13:55:37 -0700 | [diff] [blame] | 1891 | if (!check_vif_up(ifp->vif)) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1892 | return -EIO; |
| 1893 | |
| 1894 | if (!sme->ssid) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1895 | brcmf_err("Invalid ssid\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1896 | return -EOPNOTSUPP; |
| 1897 | } |
| 1898 | |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 1899 | if (ifp->vif == cfg->p2p.bss_idx[P2PAPI_BSSCFG_PRIMARY].vif) { |
| 1900 | /* A normal (non P2P) connection request setup. */ |
| 1901 | ie = NULL; |
| 1902 | ie_len = 0; |
| 1903 | /* find the WPA_IE */ |
| 1904 | wpa_ie = brcmf_find_wpaie((u8 *)sme->ie, sme->ie_len); |
| 1905 | if (wpa_ie) { |
| 1906 | ie = wpa_ie; |
| 1907 | ie_len = wpa_ie->len + TLV_HDR_LEN; |
| 1908 | } else { |
| 1909 | /* find the RSN_IE */ |
Johannes Berg | 4b5800f | 2014-01-15 14:55:59 +0100 | [diff] [blame] | 1910 | rsn_ie = brcmf_parse_tlvs((const u8 *)sme->ie, |
| 1911 | sme->ie_len, |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 1912 | WLAN_EID_RSN); |
| 1913 | if (rsn_ie) { |
| 1914 | ie = rsn_ie; |
| 1915 | ie_len = rsn_ie->len + TLV_HDR_LEN; |
| 1916 | } |
| 1917 | } |
| 1918 | brcmf_fil_iovar_data_set(ifp, "wpaie", ie, ie_len); |
| 1919 | } |
| 1920 | |
| 1921 | err = brcmf_vif_set_mgmt_ie(ifp->vif, BRCMF_VNDR_IE_ASSOCREQ_FLAG, |
| 1922 | sme->ie, sme->ie_len); |
| 1923 | if (err) |
| 1924 | brcmf_err("Set Assoc REQ IE Failed\n"); |
| 1925 | else |
| 1926 | brcmf_dbg(TRACE, "Applied Vndr IEs for Assoc request\n"); |
| 1927 | |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 1928 | set_bit(BRCMF_VIF_STATUS_CONNECTING, &ifp->vif->sme_state); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1929 | |
| 1930 | if (chan) { |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 1931 | cfg->channel = |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1932 | ieee80211_frequency_to_channel(chan->center_freq); |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 1933 | chanspec = channel_to_chanspec(&cfg->d11inf, chan); |
Hante Meuleman | 1701261 | 2013-02-06 18:40:44 +0100 | [diff] [blame] | 1934 | brcmf_dbg(CONN, "channel=%d, center_req=%d, chanspec=0x%04x\n", |
| 1935 | cfg->channel, chan->center_freq, chanspec); |
| 1936 | } else { |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 1937 | cfg->channel = 0; |
Hante Meuleman | 1701261 | 2013-02-06 18:40:44 +0100 | [diff] [blame] | 1938 | chanspec = 0; |
| 1939 | } |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1940 | |
Arend van Spriel | 647c9ae | 2012-12-05 15:26:01 +0100 | [diff] [blame] | 1941 | 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] | 1942 | |
| 1943 | err = brcmf_set_wpa_version(ndev, sme); |
| 1944 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1945 | brcmf_err("wl_set_wpa_version failed (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1946 | goto done; |
| 1947 | } |
| 1948 | |
Arend van Spriel | cbb1ec9 | 2013-02-06 18:40:47 +0100 | [diff] [blame] | 1949 | sme->auth_type = brcmf_war_auth_type(ifp, sme->auth_type); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1950 | err = brcmf_set_auth_type(ndev, sme); |
| 1951 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1952 | brcmf_err("wl_set_auth_type failed (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1953 | goto done; |
| 1954 | } |
| 1955 | |
Hante Meuleman | 240d61a | 2016-02-17 11:27:10 +0100 | [diff] [blame] | 1956 | err = brcmf_set_wsec_mode(ndev, sme); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1957 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1958 | brcmf_err("wl_set_set_cipher failed (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1959 | goto done; |
| 1960 | } |
| 1961 | |
| 1962 | err = brcmf_set_key_mgmt(ndev, sme); |
| 1963 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1964 | brcmf_err("wl_set_key_mgmt failed (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1965 | goto done; |
| 1966 | } |
| 1967 | |
Hante Meuleman | f09d0c0 | 2012-09-27 14:17:48 +0200 | [diff] [blame] | 1968 | err = brcmf_set_sharedkey(ndev, sme); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1969 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1970 | brcmf_err("brcmf_set_sharedkey failed (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1971 | goto done; |
| 1972 | } |
| 1973 | |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 1974 | /* Join with specific BSSID and cached SSID |
| 1975 | * If SSID is zero join based on BSSID only |
| 1976 | */ |
| 1977 | join_params_size = offsetof(struct brcmf_ext_join_params_le, assoc_le) + |
| 1978 | offsetof(struct brcmf_assoc_params_le, chanspec_list); |
| 1979 | if (cfg->channel) |
| 1980 | join_params_size += sizeof(u16); |
| 1981 | ext_join_params = kzalloc(join_params_size, GFP_KERNEL); |
| 1982 | if (ext_join_params == NULL) { |
| 1983 | err = -ENOMEM; |
| 1984 | goto done; |
| 1985 | } |
Hante Meuleman | e9a6ca8 | 2015-11-25 11:32:37 +0100 | [diff] [blame] | 1986 | ssid_len = min_t(u32, sme->ssid_len, IEEE80211_MAX_SSID_LEN); |
| 1987 | ext_join_params->ssid_le.SSID_len = cpu_to_le32(ssid_len); |
| 1988 | memcpy(&ext_join_params->ssid_le.SSID, sme->ssid, ssid_len); |
| 1989 | if (ssid_len < IEEE80211_MAX_SSID_LEN) |
| 1990 | brcmf_dbg(CONN, "SSID \"%s\", len (%d)\n", |
| 1991 | ext_join_params->ssid_le.SSID, ssid_len); |
Hante Meuleman | 63dd99e | 2014-03-15 17:18:19 +0100 | [diff] [blame] | 1992 | |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 1993 | /* Set up join scan parameters */ |
| 1994 | ext_join_params->scan_le.scan_type = -1; |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 1995 | ext_join_params->scan_le.home_time = cpu_to_le32(-1); |
| 1996 | |
| 1997 | if (sme->bssid) |
| 1998 | memcpy(&ext_join_params->assoc_le.bssid, sme->bssid, ETH_ALEN); |
| 1999 | else |
Joe Perches | 93803b3 | 2015-03-02 19:54:49 -0800 | [diff] [blame] | 2000 | eth_broadcast_addr(ext_join_params->assoc_le.bssid); |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 2001 | |
| 2002 | if (cfg->channel) { |
| 2003 | ext_join_params->assoc_le.chanspec_num = cpu_to_le32(1); |
| 2004 | |
| 2005 | ext_join_params->assoc_le.chanspec_list[0] = |
| 2006 | cpu_to_le16(chanspec); |
Hante Meuleman | 63dd99e | 2014-03-15 17:18:19 +0100 | [diff] [blame] | 2007 | /* Increase dwell time to receive probe response or detect |
| 2008 | * beacon from target AP at a noisy air only during connect |
| 2009 | * command. |
| 2010 | */ |
| 2011 | ext_join_params->scan_le.active_time = |
| 2012 | cpu_to_le32(BRCMF_SCAN_JOIN_ACTIVE_DWELL_TIME_MS); |
| 2013 | ext_join_params->scan_le.passive_time = |
| 2014 | cpu_to_le32(BRCMF_SCAN_JOIN_PASSIVE_DWELL_TIME_MS); |
| 2015 | /* To sync with presence period of VSDB GO send probe request |
| 2016 | * more frequently. Probe request will be stopped when it gets |
| 2017 | * probe response from target AP/GO. |
| 2018 | */ |
| 2019 | ext_join_params->scan_le.nprobes = |
| 2020 | cpu_to_le32(BRCMF_SCAN_JOIN_ACTIVE_DWELL_TIME_MS / |
| 2021 | BRCMF_SCAN_JOIN_PROBE_INTERVAL_MS); |
| 2022 | } else { |
| 2023 | ext_join_params->scan_le.active_time = cpu_to_le32(-1); |
| 2024 | ext_join_params->scan_le.passive_time = cpu_to_le32(-1); |
| 2025 | ext_join_params->scan_le.nprobes = cpu_to_le32(-1); |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 2026 | } |
| 2027 | |
Arend van Spriel | 7705ba6 | 2016-04-17 16:44:58 +0200 | [diff] [blame] | 2028 | brcmf_set_join_pref(ifp, &sme->bss_select); |
| 2029 | |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 2030 | err = brcmf_fil_bsscfg_data_set(ifp, "join", ext_join_params, |
| 2031 | join_params_size); |
| 2032 | kfree(ext_join_params); |
| 2033 | if (!err) |
| 2034 | /* This is it. join command worked, we are done */ |
| 2035 | goto done; |
| 2036 | |
| 2037 | /* join command failed, fallback to set ssid */ |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2038 | memset(&join_params, 0, sizeof(join_params)); |
| 2039 | join_params_size = sizeof(join_params.ssid_le); |
| 2040 | |
Hante Meuleman | e9a6ca8 | 2015-11-25 11:32:37 +0100 | [diff] [blame] | 2041 | memcpy(&join_params.ssid_le.SSID, sme->ssid, ssid_len); |
| 2042 | join_params.ssid_le.SSID_len = cpu_to_le32(ssid_len); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2043 | |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 2044 | if (sme->bssid) |
| 2045 | memcpy(join_params.params_le.bssid, sme->bssid, ETH_ALEN); |
| 2046 | else |
Joe Perches | 93803b3 | 2015-03-02 19:54:49 -0800 | [diff] [blame] | 2047 | eth_broadcast_addr(join_params.params_le.bssid); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2048 | |
Hante Meuleman | 1701261 | 2013-02-06 18:40:44 +0100 | [diff] [blame] | 2049 | if (cfg->channel) { |
| 2050 | join_params.params_le.chanspec_list[0] = cpu_to_le16(chanspec); |
| 2051 | join_params.params_le.chanspec_num = cpu_to_le32(1); |
| 2052 | join_params_size += sizeof(join_params.params_le); |
| 2053 | } |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 2054 | err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SET_SSID, |
Hante Meuleman | 81f5dcb | 2012-10-22 10:36:14 -0700 | [diff] [blame] | 2055 | &join_params, join_params_size); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2056 | if (err) |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 2057 | brcmf_err("BRCMF_C_SET_SSID failed (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2058 | |
| 2059 | done: |
| 2060 | if (err) |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 2061 | clear_bit(BRCMF_VIF_STATUS_CONNECTING, &ifp->vif->sme_state); |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 2062 | brcmf_dbg(TRACE, "Exit\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2063 | return err; |
| 2064 | } |
| 2065 | |
| 2066 | static s32 |
| 2067 | brcmf_cfg80211_disconnect(struct wiphy *wiphy, struct net_device *ndev, |
| 2068 | u16 reason_code) |
| 2069 | { |
Arend van Spriel | 0abb5f21 | 2012-10-22 13:55:32 -0700 | [diff] [blame] | 2070 | struct brcmf_if *ifp = netdev_priv(ndev); |
| 2071 | struct brcmf_cfg80211_profile *profile = &ifp->vif->profile; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2072 | struct brcmf_scb_val_le scbval; |
| 2073 | s32 err = 0; |
| 2074 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 2075 | brcmf_dbg(TRACE, "Enter. Reason code = %d\n", reason_code); |
Arend van Spriel | ce81e31 | 2012-10-22 13:55:37 -0700 | [diff] [blame] | 2076 | if (!check_vif_up(ifp->vif)) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2077 | return -EIO; |
| 2078 | |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 2079 | clear_bit(BRCMF_VIF_STATUS_CONNECTED, &ifp->vif->sme_state); |
Arend van Spriel | 4f3fff1 | 2014-11-20 22:27:02 +0100 | [diff] [blame] | 2080 | clear_bit(BRCMF_VIF_STATUS_CONNECTING, &ifp->vif->sme_state); |
Johannes Berg | 80279fb | 2015-05-22 16:22:20 +0200 | [diff] [blame] | 2081 | cfg80211_disconnected(ndev, reason_code, NULL, 0, true, GFP_KERNEL); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2082 | |
Arend van Spriel | 06bb123 | 2012-09-27 14:17:56 +0200 | [diff] [blame] | 2083 | memcpy(&scbval.ea, &profile->bssid, ETH_ALEN); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2084 | scbval.val = cpu_to_le32(reason_code); |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 2085 | err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_DISASSOC, |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 2086 | &scbval, sizeof(scbval)); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2087 | if (err) |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 2088 | brcmf_err("error (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2089 | |
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 |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 2095 | 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] | 2096 | enum nl80211_tx_power_setting type, s32 mbm) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2097 | { |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 2098 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); |
Arend van Spriel | 0abb5f21 | 2012-10-22 13:55:32 -0700 | [diff] [blame] | 2099 | struct net_device *ndev = cfg_to_ndev(cfg); |
| 2100 | struct brcmf_if *ifp = netdev_priv(ndev); |
Hante Meuleman | 60dc35e | 2015-09-18 22:08:06 +0200 | [diff] [blame] | 2101 | s32 err; |
| 2102 | s32 disable; |
| 2103 | u32 qdbm = 127; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2104 | |
Hante Meuleman | 60dc35e | 2015-09-18 22:08:06 +0200 | [diff] [blame] | 2105 | brcmf_dbg(TRACE, "Enter %d %d\n", type, mbm); |
Arend van Spriel | ce81e31 | 2012-10-22 13:55:37 -0700 | [diff] [blame] | 2106 | if (!check_vif_up(ifp->vif)) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2107 | return -EIO; |
| 2108 | |
| 2109 | switch (type) { |
| 2110 | case NL80211_TX_POWER_AUTOMATIC: |
| 2111 | break; |
| 2112 | case NL80211_TX_POWER_LIMITED: |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2113 | case NL80211_TX_POWER_FIXED: |
Hante Meuleman | 60dc35e | 2015-09-18 22:08:06 +0200 | [diff] [blame] | 2114 | if (mbm < 0) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 2115 | brcmf_err("TX_POWER_FIXED - dbm is negative\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2116 | err = -EINVAL; |
| 2117 | goto done; |
| 2118 | } |
Hante Meuleman | 60dc35e | 2015-09-18 22:08:06 +0200 | [diff] [blame] | 2119 | qdbm = MBM_TO_DBM(4 * mbm); |
| 2120 | if (qdbm > 127) |
| 2121 | qdbm = 127; |
| 2122 | qdbm |= WL_TXPWR_OVERRIDE; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2123 | break; |
Hante Meuleman | 60dc35e | 2015-09-18 22:08:06 +0200 | [diff] [blame] | 2124 | default: |
| 2125 | brcmf_err("Unsupported type %d\n", type); |
| 2126 | err = -EINVAL; |
| 2127 | goto done; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2128 | } |
| 2129 | /* Make sure radio is off or on as far as software is concerned */ |
| 2130 | disable = WL_RADIO_SW_DISABLE << 16; |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 2131 | 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] | 2132 | if (err) |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 2133 | brcmf_err("WLC_SET_RADIO error (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2134 | |
Hante Meuleman | 60dc35e | 2015-09-18 22:08:06 +0200 | [diff] [blame] | 2135 | err = brcmf_fil_iovar_int_set(ifp, "qtxpower", qdbm); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2136 | if (err) |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 2137 | brcmf_err("qtxpower error (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2138 | |
| 2139 | done: |
Hante Meuleman | 60dc35e | 2015-09-18 22:08:06 +0200 | [diff] [blame] | 2140 | brcmf_dbg(TRACE, "Exit %d (qdbm)\n", qdbm & ~WL_TXPWR_OVERRIDE); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2141 | return err; |
| 2142 | } |
| 2143 | |
Hante Meuleman | 60dc35e | 2015-09-18 22:08:06 +0200 | [diff] [blame] | 2144 | static s32 |
| 2145 | brcmf_cfg80211_get_tx_power(struct wiphy *wiphy, struct wireless_dev *wdev, |
| 2146 | s32 *dbm) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2147 | { |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 2148 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); |
Hante Meuleman | 60dc35e | 2015-09-18 22:08:06 +0200 | [diff] [blame] | 2149 | struct net_device *ndev = cfg_to_ndev(cfg); |
| 2150 | struct brcmf_if *ifp = netdev_priv(ndev); |
| 2151 | s32 qdbm = 0; |
| 2152 | s32 err; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2153 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 2154 | brcmf_dbg(TRACE, "Enter\n"); |
Arend van Spriel | ce81e31 | 2012-10-22 13:55:37 -0700 | [diff] [blame] | 2155 | if (!check_vif_up(ifp->vif)) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2156 | return -EIO; |
| 2157 | |
Hante Meuleman | 60dc35e | 2015-09-18 22:08:06 +0200 | [diff] [blame] | 2158 | err = brcmf_fil_iovar_int_get(ifp, "qtxpower", &qdbm); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2159 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 2160 | brcmf_err("error (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2161 | goto done; |
| 2162 | } |
Hante Meuleman | 60dc35e | 2015-09-18 22:08:06 +0200 | [diff] [blame] | 2163 | *dbm = (qdbm & ~WL_TXPWR_OVERRIDE) / 4; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2164 | |
| 2165 | done: |
Hante Meuleman | 60dc35e | 2015-09-18 22:08:06 +0200 | [diff] [blame] | 2166 | brcmf_dbg(TRACE, "Exit (0x%x %d)\n", qdbm, *dbm); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2167 | return err; |
| 2168 | } |
| 2169 | |
| 2170 | static s32 |
| 2171 | brcmf_cfg80211_config_default_key(struct wiphy *wiphy, struct net_device *ndev, |
Hante Meuleman | 60dc35e | 2015-09-18 22:08:06 +0200 | [diff] [blame] | 2172 | u8 key_idx, bool unicast, bool multicast) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2173 | { |
Arend van Spriel | 0abb5f21 | 2012-10-22 13:55:32 -0700 | [diff] [blame] | 2174 | struct brcmf_if *ifp = netdev_priv(ndev); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2175 | u32 index; |
| 2176 | u32 wsec; |
| 2177 | s32 err = 0; |
| 2178 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 2179 | brcmf_dbg(TRACE, "Enter\n"); |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 2180 | brcmf_dbg(CONN, "key index (%d)\n", key_idx); |
Arend van Spriel | ce81e31 | 2012-10-22 13:55:37 -0700 | [diff] [blame] | 2181 | if (!check_vif_up(ifp->vif)) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2182 | return -EIO; |
| 2183 | |
Arend van Spriel | 0abb5f21 | 2012-10-22 13:55:32 -0700 | [diff] [blame] | 2184 | err = brcmf_fil_bsscfg_int_get(ifp, "wsec", &wsec); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2185 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 2186 | brcmf_err("WLC_GET_WSEC error (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2187 | goto done; |
| 2188 | } |
| 2189 | |
| 2190 | if (wsec & WEP_ENABLED) { |
| 2191 | /* Just select a new current key */ |
| 2192 | index = key_idx; |
Arend van Spriel | 0abb5f21 | 2012-10-22 13:55:32 -0700 | [diff] [blame] | 2193 | err = brcmf_fil_cmd_int_set(ifp, |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 2194 | BRCMF_C_SET_KEY_PRIMARY, index); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2195 | if (err) |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 2196 | brcmf_err("error (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2197 | } |
| 2198 | done: |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 2199 | brcmf_dbg(TRACE, "Exit\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2200 | return err; |
| 2201 | } |
| 2202 | |
| 2203 | static s32 |
Hante Meuleman | 219e0f7 | 2016-02-17 11:27:09 +0100 | [diff] [blame] | 2204 | brcmf_cfg80211_del_key(struct wiphy *wiphy, struct net_device *ndev, |
| 2205 | u8 key_idx, bool pairwise, const u8 *mac_addr) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2206 | { |
Hante Meuleman | 992f606 | 2013-04-02 21:06:17 +0200 | [diff] [blame] | 2207 | struct brcmf_if *ifp = netdev_priv(ndev); |
Hante Meuleman | 240d61a | 2016-02-17 11:27:10 +0100 | [diff] [blame] | 2208 | struct brcmf_wsec_key *key; |
| 2209 | s32 err; |
Hante Meuleman | 219e0f7 | 2016-02-17 11:27:09 +0100 | [diff] [blame] | 2210 | |
| 2211 | brcmf_dbg(TRACE, "Enter\n"); |
Hante Meuleman | 240d61a | 2016-02-17 11:27:10 +0100 | [diff] [blame] | 2212 | brcmf_dbg(CONN, "key index (%d)\n", key_idx); |
| 2213 | |
Hante Meuleman | 219e0f7 | 2016-02-17 11:27:09 +0100 | [diff] [blame] | 2214 | if (!check_vif_up(ifp->vif)) |
| 2215 | return -EIO; |
| 2216 | |
| 2217 | if (key_idx >= BRCMF_MAX_DEFAULT_KEYS) { |
| 2218 | /* we ignore this key index in this case */ |
| 2219 | return -EINVAL; |
| 2220 | } |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2221 | |
Hante Meuleman | 240d61a | 2016-02-17 11:27:10 +0100 | [diff] [blame] | 2222 | key = &ifp->vif->profile.key[key_idx]; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2223 | |
Hante Meuleman | 240d61a | 2016-02-17 11:27:10 +0100 | [diff] [blame] | 2224 | if (key->algo == CRYPTO_ALGO_OFF) { |
| 2225 | brcmf_dbg(CONN, "Ignore clearing of (never configured) key\n"); |
| 2226 | return -EINVAL; |
| 2227 | } |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2228 | |
Hante Meuleman | 240d61a | 2016-02-17 11:27:10 +0100 | [diff] [blame] | 2229 | memset(key, 0, sizeof(*key)); |
| 2230 | key->index = (u32)key_idx; |
| 2231 | key->flags = BRCMF_PRIMARY_KEY; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2232 | |
Hante Meuleman | 240d61a | 2016-02-17 11:27:10 +0100 | [diff] [blame] | 2233 | /* Clear the key/index */ |
| 2234 | err = send_key_to_dongle(ifp, key); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2235 | |
Hante Meuleman | 219e0f7 | 2016-02-17 11:27:09 +0100 | [diff] [blame] | 2236 | brcmf_dbg(TRACE, "Exit\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2237 | return err; |
| 2238 | } |
| 2239 | |
| 2240 | static s32 |
| 2241 | brcmf_cfg80211_add_key(struct wiphy *wiphy, struct net_device *ndev, |
Hante Meuleman | 240d61a | 2016-02-17 11:27:10 +0100 | [diff] [blame] | 2242 | u8 key_idx, bool pairwise, const u8 *mac_addr, |
| 2243 | struct key_params *params) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2244 | { |
Arend van Spriel | 0abb5f21 | 2012-10-22 13:55:32 -0700 | [diff] [blame] | 2245 | struct brcmf_if *ifp = netdev_priv(ndev); |
Hante Meuleman | 118eb30 | 2014-12-21 12:43:49 +0100 | [diff] [blame] | 2246 | struct brcmf_wsec_key *key; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2247 | s32 val; |
| 2248 | s32 wsec; |
Hante Meuleman | 219e0f7 | 2016-02-17 11:27:09 +0100 | [diff] [blame] | 2249 | s32 err; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2250 | u8 keybuf[8]; |
Hante Meuleman | 219e0f7 | 2016-02-17 11:27:09 +0100 | [diff] [blame] | 2251 | bool ext_key; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2252 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 2253 | brcmf_dbg(TRACE, "Enter\n"); |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 2254 | brcmf_dbg(CONN, "key index (%d)\n", key_idx); |
Arend van Spriel | ce81e31 | 2012-10-22 13:55:37 -0700 | [diff] [blame] | 2255 | if (!check_vif_up(ifp->vif)) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2256 | return -EIO; |
| 2257 | |
Hante Meuleman | 118eb30 | 2014-12-21 12:43:49 +0100 | [diff] [blame] | 2258 | if (key_idx >= BRCMF_MAX_DEFAULT_KEYS) { |
| 2259 | /* we ignore this key index in this case */ |
| 2260 | brcmf_err("invalid key index (%d)\n", key_idx); |
| 2261 | return -EINVAL; |
| 2262 | } |
| 2263 | |
Hante Meuleman | 219e0f7 | 2016-02-17 11:27:09 +0100 | [diff] [blame] | 2264 | if (params->key_len == 0) |
| 2265 | return brcmf_cfg80211_del_key(wiphy, ndev, key_idx, pairwise, |
| 2266 | mac_addr); |
| 2267 | |
| 2268 | if (params->key_len > sizeof(key->data)) { |
| 2269 | brcmf_err("Too long key length (%u)\n", params->key_len); |
| 2270 | return -EINVAL; |
| 2271 | } |
| 2272 | |
| 2273 | ext_key = false; |
| 2274 | if (mac_addr && (params->cipher != WLAN_CIPHER_SUITE_WEP40) && |
| 2275 | (params->cipher != WLAN_CIPHER_SUITE_WEP104)) { |
| 2276 | brcmf_dbg(TRACE, "Ext key, mac %pM", mac_addr); |
| 2277 | ext_key = true; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2278 | } |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2279 | |
Hante Meuleman | 118eb30 | 2014-12-21 12:43:49 +0100 | [diff] [blame] | 2280 | key = &ifp->vif->profile.key[key_idx]; |
| 2281 | memset(key, 0, sizeof(*key)); |
Hante Meuleman | 219e0f7 | 2016-02-17 11:27:09 +0100 | [diff] [blame] | 2282 | if ((ext_key) && (!is_multicast_ether_addr(mac_addr))) |
| 2283 | memcpy((char *)&key->ea, (void *)mac_addr, ETH_ALEN); |
Hante Meuleman | 118eb30 | 2014-12-21 12:43:49 +0100 | [diff] [blame] | 2284 | key->len = params->key_len; |
| 2285 | key->index = key_idx; |
Hante Meuleman | 118eb30 | 2014-12-21 12:43:49 +0100 | [diff] [blame] | 2286 | memcpy(key->data, params->key, key->len); |
Hante Meuleman | 219e0f7 | 2016-02-17 11:27:09 +0100 | [diff] [blame] | 2287 | if (!ext_key) |
| 2288 | key->flags = BRCMF_PRIMARY_KEY; |
Hante Meuleman | 118eb30 | 2014-12-21 12:43:49 +0100 | [diff] [blame] | 2289 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2290 | switch (params->cipher) { |
| 2291 | case WLAN_CIPHER_SUITE_WEP40: |
Hante Meuleman | 118eb30 | 2014-12-21 12:43:49 +0100 | [diff] [blame] | 2292 | key->algo = CRYPTO_ALGO_WEP1; |
Hante Meuleman | f09d0c0 | 2012-09-27 14:17:48 +0200 | [diff] [blame] | 2293 | val = WEP_ENABLED; |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 2294 | brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_WEP40\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2295 | break; |
| 2296 | case WLAN_CIPHER_SUITE_WEP104: |
Hante Meuleman | 118eb30 | 2014-12-21 12:43:49 +0100 | [diff] [blame] | 2297 | key->algo = CRYPTO_ALGO_WEP128; |
Hante Meuleman | f09d0c0 | 2012-09-27 14:17:48 +0200 | [diff] [blame] | 2298 | val = WEP_ENABLED; |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 2299 | brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_WEP104\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2300 | break; |
| 2301 | case WLAN_CIPHER_SUITE_TKIP: |
Arend van Spriel | 967fe2c | 2014-03-15 17:18:21 +0100 | [diff] [blame] | 2302 | if (!brcmf_is_apmode(ifp->vif)) { |
Hante Meuleman | 992f606 | 2013-04-02 21:06:17 +0200 | [diff] [blame] | 2303 | brcmf_dbg(CONN, "Swapping RX/TX MIC key\n"); |
Hante Meuleman | 118eb30 | 2014-12-21 12:43:49 +0100 | [diff] [blame] | 2304 | memcpy(keybuf, &key->data[24], sizeof(keybuf)); |
| 2305 | memcpy(&key->data[24], &key->data[16], sizeof(keybuf)); |
| 2306 | memcpy(&key->data[16], keybuf, sizeof(keybuf)); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 2307 | } |
Hante Meuleman | 118eb30 | 2014-12-21 12:43:49 +0100 | [diff] [blame] | 2308 | key->algo = CRYPTO_ALGO_TKIP; |
Hante Meuleman | f09d0c0 | 2012-09-27 14:17:48 +0200 | [diff] [blame] | 2309 | val = TKIP_ENABLED; |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 2310 | brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_TKIP\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2311 | break; |
| 2312 | case WLAN_CIPHER_SUITE_AES_CMAC: |
Hante Meuleman | 118eb30 | 2014-12-21 12:43:49 +0100 | [diff] [blame] | 2313 | key->algo = CRYPTO_ALGO_AES_CCM; |
Hante Meuleman | f09d0c0 | 2012-09-27 14:17:48 +0200 | [diff] [blame] | 2314 | val = AES_ENABLED; |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 2315 | brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_AES_CMAC\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2316 | break; |
| 2317 | case WLAN_CIPHER_SUITE_CCMP: |
Hante Meuleman | 118eb30 | 2014-12-21 12:43:49 +0100 | [diff] [blame] | 2318 | key->algo = CRYPTO_ALGO_AES_CCM; |
Hante Meuleman | f09d0c0 | 2012-09-27 14:17:48 +0200 | [diff] [blame] | 2319 | val = AES_ENABLED; |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 2320 | brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_CCMP\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2321 | break; |
| 2322 | default: |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 2323 | brcmf_err("Invalid cipher (0x%x)\n", params->cipher); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2324 | err = -EINVAL; |
| 2325 | goto done; |
| 2326 | } |
| 2327 | |
Hante Meuleman | 118eb30 | 2014-12-21 12:43:49 +0100 | [diff] [blame] | 2328 | err = send_key_to_dongle(ifp, key); |
Hante Meuleman | 219e0f7 | 2016-02-17 11:27:09 +0100 | [diff] [blame] | 2329 | if (ext_key || err) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2330 | goto done; |
| 2331 | |
Arend van Spriel | 0abb5f21 | 2012-10-22 13:55:32 -0700 | [diff] [blame] | 2332 | err = brcmf_fil_bsscfg_int_get(ifp, "wsec", &wsec); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2333 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 2334 | brcmf_err("get wsec error (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2335 | goto done; |
| 2336 | } |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2337 | wsec |= val; |
Arend van Spriel | 0abb5f21 | 2012-10-22 13:55:32 -0700 | [diff] [blame] | 2338 | err = brcmf_fil_bsscfg_int_set(ifp, "wsec", wsec); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2339 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 2340 | brcmf_err("set wsec error (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2341 | goto done; |
| 2342 | } |
| 2343 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2344 | done: |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 2345 | brcmf_dbg(TRACE, "Exit\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2346 | return err; |
| 2347 | } |
| 2348 | |
| 2349 | static s32 |
Hante Meuleman | 240d61a | 2016-02-17 11:27:10 +0100 | [diff] [blame] | 2350 | brcmf_cfg80211_get_key(struct wiphy *wiphy, struct net_device *ndev, u8 key_idx, |
| 2351 | bool pairwise, const u8 *mac_addr, void *cookie, |
| 2352 | void (*callback)(void *cookie, |
| 2353 | struct key_params *params)) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2354 | { |
| 2355 | struct key_params params; |
Arend van Spriel | 0abb5f21 | 2012-10-22 13:55:32 -0700 | [diff] [blame] | 2356 | struct brcmf_if *ifp = netdev_priv(ndev); |
| 2357 | struct brcmf_cfg80211_profile *profile = &ifp->vif->profile; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2358 | struct brcmf_cfg80211_security *sec; |
| 2359 | s32 wsec; |
| 2360 | s32 err = 0; |
| 2361 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 2362 | brcmf_dbg(TRACE, "Enter\n"); |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 2363 | brcmf_dbg(CONN, "key index (%d)\n", key_idx); |
Arend van Spriel | ce81e31 | 2012-10-22 13:55:37 -0700 | [diff] [blame] | 2364 | if (!check_vif_up(ifp->vif)) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2365 | return -EIO; |
| 2366 | |
| 2367 | memset(¶ms, 0, sizeof(params)); |
| 2368 | |
Arend van Spriel | 0abb5f21 | 2012-10-22 13:55:32 -0700 | [diff] [blame] | 2369 | err = brcmf_fil_bsscfg_int_get(ifp, "wsec", &wsec); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2370 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 2371 | brcmf_err("WLC_GET_WSEC error (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2372 | /* Ignore this error, may happen during DISASSOC */ |
| 2373 | err = -EAGAIN; |
| 2374 | goto done; |
| 2375 | } |
Hante Meuleman | c5bf53a | 2013-04-02 21:06:19 +0200 | [diff] [blame] | 2376 | if (wsec & WEP_ENABLED) { |
Arend van Spriel | 06bb123 | 2012-09-27 14:17:56 +0200 | [diff] [blame] | 2377 | sec = &profile->sec; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2378 | if (sec->cipher_pairwise & WLAN_CIPHER_SUITE_WEP40) { |
| 2379 | params.cipher = WLAN_CIPHER_SUITE_WEP40; |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 2380 | brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_WEP40\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2381 | } else if (sec->cipher_pairwise & WLAN_CIPHER_SUITE_WEP104) { |
| 2382 | params.cipher = WLAN_CIPHER_SUITE_WEP104; |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 2383 | brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_WEP104\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2384 | } |
Hante Meuleman | c5bf53a | 2013-04-02 21:06:19 +0200 | [diff] [blame] | 2385 | } else if (wsec & TKIP_ENABLED) { |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2386 | params.cipher = WLAN_CIPHER_SUITE_TKIP; |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 2387 | brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_TKIP\n"); |
Hante Meuleman | c5bf53a | 2013-04-02 21:06:19 +0200 | [diff] [blame] | 2388 | } else if (wsec & AES_ENABLED) { |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2389 | params.cipher = WLAN_CIPHER_SUITE_AES_CMAC; |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 2390 | brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_AES_CMAC\n"); |
Hante Meuleman | c5bf53a | 2013-04-02 21:06:19 +0200 | [diff] [blame] | 2391 | } else { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 2392 | brcmf_err("Invalid algo (0x%x)\n", wsec); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2393 | err = -EINVAL; |
| 2394 | goto done; |
| 2395 | } |
| 2396 | callback(cookie, ¶ms); |
| 2397 | |
| 2398 | done: |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 2399 | brcmf_dbg(TRACE, "Exit\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2400 | return err; |
| 2401 | } |
| 2402 | |
| 2403 | static s32 |
| 2404 | brcmf_cfg80211_config_default_mgmt_key(struct wiphy *wiphy, |
Hante Meuleman | 240d61a | 2016-02-17 11:27:10 +0100 | [diff] [blame] | 2405 | struct net_device *ndev, u8 key_idx) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2406 | { |
Hante Meuleman | 240d61a | 2016-02-17 11:27:10 +0100 | [diff] [blame] | 2407 | struct brcmf_if *ifp = netdev_priv(ndev); |
| 2408 | |
| 2409 | brcmf_dbg(TRACE, "Enter key_idx %d\n", key_idx); |
| 2410 | |
| 2411 | if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_MFP)) |
| 2412 | return 0; |
| 2413 | |
Arend van Spriel | 647c9ae | 2012-12-05 15:26:01 +0100 | [diff] [blame] | 2414 | brcmf_dbg(INFO, "Not supported\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2415 | |
| 2416 | return -EOPNOTSUPP; |
| 2417 | } |
| 2418 | |
Hante Meuleman | 118eb30 | 2014-12-21 12:43:49 +0100 | [diff] [blame] | 2419 | static void |
| 2420 | brcmf_cfg80211_reconfigure_wep(struct brcmf_if *ifp) |
| 2421 | { |
| 2422 | s32 err; |
| 2423 | u8 key_idx; |
| 2424 | struct brcmf_wsec_key *key; |
| 2425 | s32 wsec; |
| 2426 | |
| 2427 | for (key_idx = 0; key_idx < BRCMF_MAX_DEFAULT_KEYS; key_idx++) { |
| 2428 | key = &ifp->vif->profile.key[key_idx]; |
| 2429 | if ((key->algo == CRYPTO_ALGO_WEP1) || |
| 2430 | (key->algo == CRYPTO_ALGO_WEP128)) |
| 2431 | break; |
| 2432 | } |
| 2433 | if (key_idx == BRCMF_MAX_DEFAULT_KEYS) |
| 2434 | return; |
| 2435 | |
| 2436 | err = send_key_to_dongle(ifp, key); |
| 2437 | if (err) { |
| 2438 | brcmf_err("Setting WEP key failed (%d)\n", err); |
| 2439 | return; |
| 2440 | } |
| 2441 | err = brcmf_fil_bsscfg_int_get(ifp, "wsec", &wsec); |
| 2442 | if (err) { |
| 2443 | brcmf_err("get wsec error (%d)\n", err); |
| 2444 | return; |
| 2445 | } |
| 2446 | wsec |= WEP_ENABLED; |
| 2447 | err = brcmf_fil_bsscfg_int_set(ifp, "wsec", wsec); |
| 2448 | if (err) |
| 2449 | brcmf_err("set wsec error (%d)\n", err); |
| 2450 | } |
| 2451 | |
Arend van Spriel | 1f0dc59 | 2015-06-11 00:12:19 +0200 | [diff] [blame] | 2452 | static void brcmf_convert_sta_flags(u32 fw_sta_flags, struct station_info *si) |
| 2453 | { |
| 2454 | struct nl80211_sta_flag_update *sfu; |
| 2455 | |
| 2456 | brcmf_dbg(TRACE, "flags %08x\n", fw_sta_flags); |
| 2457 | si->filled |= BIT(NL80211_STA_INFO_STA_FLAGS); |
| 2458 | sfu = &si->sta_flags; |
| 2459 | sfu->mask = BIT(NL80211_STA_FLAG_WME) | |
| 2460 | BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 2461 | BIT(NL80211_STA_FLAG_ASSOCIATED) | |
| 2462 | BIT(NL80211_STA_FLAG_AUTHORIZED); |
| 2463 | if (fw_sta_flags & BRCMF_STA_WME) |
| 2464 | sfu->set |= BIT(NL80211_STA_FLAG_WME); |
| 2465 | if (fw_sta_flags & BRCMF_STA_AUTHE) |
| 2466 | sfu->set |= BIT(NL80211_STA_FLAG_AUTHENTICATED); |
| 2467 | if (fw_sta_flags & BRCMF_STA_ASSOC) |
| 2468 | sfu->set |= BIT(NL80211_STA_FLAG_ASSOCIATED); |
| 2469 | if (fw_sta_flags & BRCMF_STA_AUTHO) |
| 2470 | sfu->set |= BIT(NL80211_STA_FLAG_AUTHORIZED); |
| 2471 | } |
| 2472 | |
| 2473 | static void brcmf_fill_bss_param(struct brcmf_if *ifp, struct station_info *si) |
| 2474 | { |
| 2475 | struct { |
| 2476 | __le32 len; |
| 2477 | struct brcmf_bss_info_le bss_le; |
| 2478 | } *buf; |
| 2479 | u16 capability; |
| 2480 | int err; |
| 2481 | |
| 2482 | buf = kzalloc(WL_BSS_INFO_MAX, GFP_KERNEL); |
| 2483 | if (!buf) |
| 2484 | return; |
| 2485 | |
| 2486 | buf->len = cpu_to_le32(WL_BSS_INFO_MAX); |
| 2487 | err = brcmf_fil_cmd_data_get(ifp, BRCMF_C_GET_BSS_INFO, buf, |
| 2488 | WL_BSS_INFO_MAX); |
| 2489 | if (err) { |
| 2490 | brcmf_err("Failed to get bss info (%d)\n", err); |
| 2491 | return; |
| 2492 | } |
| 2493 | si->filled |= BIT(NL80211_STA_INFO_BSS_PARAM); |
| 2494 | si->bss_param.beacon_interval = le16_to_cpu(buf->bss_le.beacon_period); |
| 2495 | si->bss_param.dtim_period = buf->bss_le.dtim_period; |
| 2496 | capability = le16_to_cpu(buf->bss_le.capability); |
| 2497 | if (capability & IEEE80211_HT_STBC_PARAM_DUAL_CTS_PROT) |
| 2498 | si->bss_param.flags |= BSS_PARAM_FLAGS_CTS_PROT; |
| 2499 | if (capability & WLAN_CAPABILITY_SHORT_PREAMBLE) |
| 2500 | si->bss_param.flags |= BSS_PARAM_FLAGS_SHORT_PREAMBLE; |
| 2501 | if (capability & WLAN_CAPABILITY_SHORT_SLOT_TIME) |
| 2502 | si->bss_param.flags |= BSS_PARAM_FLAGS_SHORT_SLOT_TIME; |
| 2503 | } |
| 2504 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2505 | static s32 |
Hante Meuleman | 3f5893d | 2016-01-02 09:41:37 +0100 | [diff] [blame] | 2506 | brcmf_cfg80211_get_station_ibss(struct brcmf_if *ifp, |
| 2507 | struct station_info *sinfo) |
| 2508 | { |
| 2509 | struct brcmf_scb_val_le scbval; |
| 2510 | struct brcmf_pktcnt_le pktcnt; |
| 2511 | s32 err; |
| 2512 | u32 rate; |
| 2513 | u32 rssi; |
| 2514 | |
| 2515 | /* Get the current tx rate */ |
| 2516 | err = brcmf_fil_cmd_int_get(ifp, BRCMF_C_GET_RATE, &rate); |
| 2517 | if (err < 0) { |
| 2518 | brcmf_err("BRCMF_C_GET_RATE error (%d)\n", err); |
| 2519 | return err; |
| 2520 | } |
| 2521 | sinfo->filled |= BIT(NL80211_STA_INFO_TX_BITRATE); |
| 2522 | sinfo->txrate.legacy = rate * 5; |
| 2523 | |
| 2524 | memset(&scbval, 0, sizeof(scbval)); |
| 2525 | err = brcmf_fil_cmd_data_get(ifp, BRCMF_C_GET_RSSI, &scbval, |
| 2526 | sizeof(scbval)); |
| 2527 | if (err) { |
| 2528 | brcmf_err("BRCMF_C_GET_RSSI error (%d)\n", err); |
| 2529 | return err; |
| 2530 | } |
| 2531 | rssi = le32_to_cpu(scbval.val); |
| 2532 | sinfo->filled |= BIT(NL80211_STA_INFO_SIGNAL); |
| 2533 | sinfo->signal = rssi; |
| 2534 | |
| 2535 | err = brcmf_fil_cmd_data_get(ifp, BRCMF_C_GET_GET_PKTCNTS, &pktcnt, |
| 2536 | sizeof(pktcnt)); |
| 2537 | if (err) { |
| 2538 | brcmf_err("BRCMF_C_GET_GET_PKTCNTS error (%d)\n", err); |
| 2539 | return err; |
| 2540 | } |
| 2541 | sinfo->filled |= BIT(NL80211_STA_INFO_RX_PACKETS) | |
| 2542 | BIT(NL80211_STA_INFO_RX_DROP_MISC) | |
| 2543 | BIT(NL80211_STA_INFO_TX_PACKETS) | |
| 2544 | BIT(NL80211_STA_INFO_TX_FAILED); |
| 2545 | sinfo->rx_packets = le32_to_cpu(pktcnt.rx_good_pkt); |
| 2546 | sinfo->rx_dropped_misc = le32_to_cpu(pktcnt.rx_bad_pkt); |
| 2547 | sinfo->tx_packets = le32_to_cpu(pktcnt.tx_good_pkt); |
| 2548 | sinfo->tx_failed = le32_to_cpu(pktcnt.tx_bad_pkt); |
| 2549 | |
| 2550 | return 0; |
| 2551 | } |
| 2552 | |
| 2553 | static s32 |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2554 | brcmf_cfg80211_get_station(struct wiphy *wiphy, struct net_device *ndev, |
Johannes Berg | 3b3a016 | 2014-05-19 17:19:31 +0200 | [diff] [blame] | 2555 | const u8 *mac, struct station_info *sinfo) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2556 | { |
Arend van Spriel | 0abb5f21 | 2012-10-22 13:55:32 -0700 | [diff] [blame] | 2557 | struct brcmf_if *ifp = netdev_priv(ndev); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2558 | s32 err = 0; |
Hante Meuleman | 81f5dcb | 2012-10-22 10:36:14 -0700 | [diff] [blame] | 2559 | struct brcmf_sta_info_le sta_info_le; |
Arend van Spriel | 1f0dc59 | 2015-06-11 00:12:19 +0200 | [diff] [blame] | 2560 | u32 sta_flags; |
| 2561 | u32 is_tdls_peer; |
Hante Meuleman | cae355d | 2015-10-08 20:33:17 +0200 | [diff] [blame] | 2562 | s32 total_rssi; |
| 2563 | s32 count_rssi; |
| 2564 | u32 i; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2565 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 2566 | brcmf_dbg(TRACE, "Enter, MAC %pM\n", mac); |
Arend van Spriel | ce81e31 | 2012-10-22 13:55:37 -0700 | [diff] [blame] | 2567 | if (!check_vif_up(ifp->vif)) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2568 | return -EIO; |
| 2569 | |
Hante Meuleman | 3f5893d | 2016-01-02 09:41:37 +0100 | [diff] [blame] | 2570 | if (brcmf_is_ibssmode(ifp->vif)) |
| 2571 | return brcmf_cfg80211_get_station_ibss(ifp, sinfo); |
| 2572 | |
Arend van Spriel | 1f0dc59 | 2015-06-11 00:12:19 +0200 | [diff] [blame] | 2573 | memset(&sta_info_le, 0, sizeof(sta_info_le)); |
| 2574 | memcpy(&sta_info_le, mac, ETH_ALEN); |
| 2575 | err = brcmf_fil_iovar_data_get(ifp, "tdls_sta_info", |
| 2576 | &sta_info_le, |
| 2577 | sizeof(sta_info_le)); |
| 2578 | is_tdls_peer = !err; |
| 2579 | if (err) { |
Arend van Spriel | 0abb5f21 | 2012-10-22 13:55:32 -0700 | [diff] [blame] | 2580 | err = brcmf_fil_iovar_data_get(ifp, "sta_info", |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 2581 | &sta_info_le, |
Hante Meuleman | 81f5dcb | 2012-10-22 10:36:14 -0700 | [diff] [blame] | 2582 | sizeof(sta_info_le)); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 2583 | if (err < 0) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 2584 | brcmf_err("GET STA INFO failed, %d\n", err); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 2585 | goto done; |
Hante Meuleman | 7f6c562 | 2012-08-30 10:05:37 +0200 | [diff] [blame] | 2586 | } |
Arend van Spriel | 1f0dc59 | 2015-06-11 00:12:19 +0200 | [diff] [blame] | 2587 | } |
| 2588 | brcmf_dbg(TRACE, "version %d\n", le16_to_cpu(sta_info_le.ver)); |
| 2589 | sinfo->filled = BIT(NL80211_STA_INFO_INACTIVE_TIME); |
| 2590 | sinfo->inactive_time = le32_to_cpu(sta_info_le.idle) * 1000; |
| 2591 | sta_flags = le32_to_cpu(sta_info_le.flags); |
| 2592 | brcmf_convert_sta_flags(sta_flags, sinfo); |
| 2593 | sinfo->sta_flags.mask |= BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 2594 | if (is_tdls_peer) |
| 2595 | sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 2596 | else |
| 2597 | sinfo->sta_flags.set &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 2598 | if (sta_flags & BRCMF_STA_ASSOC) { |
| 2599 | sinfo->filled |= BIT(NL80211_STA_INFO_CONNECTED_TIME); |
| 2600 | sinfo->connected_time = le32_to_cpu(sta_info_le.in); |
| 2601 | brcmf_fill_bss_param(ifp, sinfo); |
| 2602 | } |
| 2603 | if (sta_flags & BRCMF_STA_SCBSTATS) { |
| 2604 | sinfo->filled |= BIT(NL80211_STA_INFO_TX_FAILED); |
| 2605 | sinfo->tx_failed = le32_to_cpu(sta_info_le.tx_failures); |
| 2606 | sinfo->filled |= BIT(NL80211_STA_INFO_TX_PACKETS); |
| 2607 | sinfo->tx_packets = le32_to_cpu(sta_info_le.tx_pkts); |
| 2608 | sinfo->tx_packets += le32_to_cpu(sta_info_le.tx_mcast_pkts); |
| 2609 | sinfo->filled |= BIT(NL80211_STA_INFO_RX_PACKETS); |
| 2610 | sinfo->rx_packets = le32_to_cpu(sta_info_le.rx_ucast_pkts); |
| 2611 | sinfo->rx_packets += le32_to_cpu(sta_info_le.rx_mcast_pkts); |
| 2612 | if (sinfo->tx_packets) { |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 2613 | sinfo->filled |= BIT(NL80211_STA_INFO_TX_BITRATE); |
Hante Meuleman | 124d517 | 2015-10-08 20:33:16 +0200 | [diff] [blame] | 2614 | sinfo->txrate.legacy = |
| 2615 | le32_to_cpu(sta_info_le.tx_rate) / 100; |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 2616 | } |
Arend van Spriel | 1f0dc59 | 2015-06-11 00:12:19 +0200 | [diff] [blame] | 2617 | if (sinfo->rx_packets) { |
| 2618 | sinfo->filled |= BIT(NL80211_STA_INFO_RX_BITRATE); |
Hante Meuleman | 124d517 | 2015-10-08 20:33:16 +0200 | [diff] [blame] | 2619 | sinfo->rxrate.legacy = |
| 2620 | le32_to_cpu(sta_info_le.rx_rate) / 100; |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 2621 | } |
Arend van Spriel | 1f0dc59 | 2015-06-11 00:12:19 +0200 | [diff] [blame] | 2622 | if (le16_to_cpu(sta_info_le.ver) >= 4) { |
| 2623 | sinfo->filled |= BIT(NL80211_STA_INFO_TX_BYTES); |
| 2624 | sinfo->tx_bytes = le64_to_cpu(sta_info_le.tx_tot_bytes); |
| 2625 | sinfo->filled |= BIT(NL80211_STA_INFO_RX_BYTES); |
| 2626 | sinfo->rx_bytes = le64_to_cpu(sta_info_le.rx_tot_bytes); |
| 2627 | } |
Hante Meuleman | cae355d | 2015-10-08 20:33:17 +0200 | [diff] [blame] | 2628 | total_rssi = 0; |
| 2629 | count_rssi = 0; |
| 2630 | for (i = 0; i < BRCMF_ANT_MAX; i++) { |
| 2631 | if (sta_info_le.rssi[i]) { |
| 2632 | sinfo->chain_signal_avg[count_rssi] = |
| 2633 | sta_info_le.rssi[i]; |
| 2634 | sinfo->chain_signal[count_rssi] = |
| 2635 | sta_info_le.rssi[i]; |
| 2636 | total_rssi += sta_info_le.rssi[i]; |
| 2637 | count_rssi++; |
| 2638 | } |
| 2639 | } |
| 2640 | if (count_rssi) { |
| 2641 | sinfo->filled |= BIT(NL80211_STA_INFO_CHAIN_SIGNAL); |
| 2642 | sinfo->chains = count_rssi; |
| 2643 | |
| 2644 | sinfo->filled |= BIT(NL80211_STA_INFO_SIGNAL); |
| 2645 | total_rssi /= count_rssi; |
| 2646 | sinfo->signal = total_rssi; |
| 2647 | } |
Arend van Spriel | 1f0dc59 | 2015-06-11 00:12:19 +0200 | [diff] [blame] | 2648 | } |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2649 | done: |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 2650 | brcmf_dbg(TRACE, "Exit\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2651 | return err; |
| 2652 | } |
| 2653 | |
Hante Meuleman | bf2a7e0 | 2015-10-08 20:33:18 +0200 | [diff] [blame] | 2654 | static int |
| 2655 | brcmf_cfg80211_dump_station(struct wiphy *wiphy, struct net_device *ndev, |
| 2656 | int idx, u8 *mac, struct station_info *sinfo) |
| 2657 | { |
| 2658 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); |
| 2659 | struct brcmf_if *ifp = netdev_priv(ndev); |
| 2660 | s32 err; |
| 2661 | |
| 2662 | brcmf_dbg(TRACE, "Enter, idx %d\n", idx); |
| 2663 | |
| 2664 | if (idx == 0) { |
| 2665 | cfg->assoclist.count = cpu_to_le32(BRCMF_MAX_ASSOCLIST); |
| 2666 | err = brcmf_fil_cmd_data_get(ifp, BRCMF_C_GET_ASSOCLIST, |
| 2667 | &cfg->assoclist, |
| 2668 | sizeof(cfg->assoclist)); |
| 2669 | if (err) { |
| 2670 | brcmf_err("BRCMF_C_GET_ASSOCLIST unsupported, err=%d\n", |
| 2671 | err); |
| 2672 | cfg->assoclist.count = 0; |
| 2673 | return -EOPNOTSUPP; |
| 2674 | } |
| 2675 | } |
| 2676 | if (idx < le32_to_cpu(cfg->assoclist.count)) { |
| 2677 | memcpy(mac, cfg->assoclist.mac[idx], ETH_ALEN); |
| 2678 | return brcmf_cfg80211_get_station(wiphy, ndev, mac, sinfo); |
| 2679 | } |
| 2680 | return -ENOENT; |
| 2681 | } |
| 2682 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2683 | static s32 |
| 2684 | brcmf_cfg80211_set_power_mgmt(struct wiphy *wiphy, struct net_device *ndev, |
| 2685 | bool enabled, s32 timeout) |
| 2686 | { |
| 2687 | s32 pm; |
| 2688 | s32 err = 0; |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 2689 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 2690 | struct brcmf_if *ifp = netdev_priv(ndev); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2691 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 2692 | brcmf_dbg(TRACE, "Enter\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2693 | |
| 2694 | /* |
| 2695 | * Powersave enable/disable request is coming from the |
| 2696 | * cfg80211 even before the interface is up. In that |
| 2697 | * scenario, driver will be storing the power save |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 2698 | * preference in cfg struct to apply this to |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2699 | * FW later while initializing the dongle |
| 2700 | */ |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 2701 | cfg->pwr_save = enabled; |
Arend van Spriel | ce81e31 | 2012-10-22 13:55:37 -0700 | [diff] [blame] | 2702 | if (!check_vif_up(ifp->vif)) { |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2703 | |
Arend van Spriel | 647c9ae | 2012-12-05 15:26:01 +0100 | [diff] [blame] | 2704 | 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] | 2705 | goto done; |
| 2706 | } |
| 2707 | |
| 2708 | pm = enabled ? PM_FAST : PM_OFF; |
Hante Meuleman | 102fd0d | 2013-05-27 21:09:59 +0200 | [diff] [blame] | 2709 | /* Do not enable the power save after assoc if it is a p2p interface */ |
| 2710 | if (ifp->vif->wdev.iftype == NL80211_IFTYPE_P2P_CLIENT) { |
| 2711 | brcmf_dbg(INFO, "Do not enable power save for P2P clients\n"); |
| 2712 | pm = PM_OFF; |
| 2713 | } |
Arend van Spriel | 647c9ae | 2012-12-05 15:26:01 +0100 | [diff] [blame] | 2714 | brcmf_dbg(INFO, "power save %s\n", (pm ? "enabled" : "disabled")); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2715 | |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 2716 | 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] | 2717 | if (err) { |
| 2718 | if (err == -ENODEV) |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 2719 | brcmf_err("net_device is not ready yet\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2720 | else |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 2721 | brcmf_err("error (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2722 | } |
| 2723 | done: |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 2724 | brcmf_dbg(TRACE, "Exit\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2725 | return err; |
| 2726 | } |
| 2727 | |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 2728 | static s32 brcmf_inform_single_bss(struct brcmf_cfg80211_info *cfg, |
Roland Vossen | d34bf64 | 2011-10-18 14:03:01 +0200 | [diff] [blame] | 2729 | struct brcmf_bss_info_le *bi) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2730 | { |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 2731 | struct wiphy *wiphy = cfg_to_wiphy(cfg); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2732 | struct ieee80211_channel *notify_channel; |
| 2733 | struct cfg80211_bss *bss; |
| 2734 | struct ieee80211_supported_band *band; |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 2735 | struct brcmu_chan ch; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2736 | u16 channel; |
| 2737 | u32 freq; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2738 | u16 notify_capability; |
| 2739 | u16 notify_interval; |
| 2740 | u8 *notify_ie; |
| 2741 | size_t notify_ielen; |
| 2742 | s32 notify_signal; |
| 2743 | |
| 2744 | if (le32_to_cpu(bi->length) > WL_BSS_INFO_MAX) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 2745 | brcmf_err("Bss info is larger than buffer. Discarding\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2746 | return 0; |
| 2747 | } |
| 2748 | |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 2749 | if (!bi->ctl_ch) { |
| 2750 | ch.chspec = le16_to_cpu(bi->chanspec); |
| 2751 | cfg->d11inf.decchspec(&ch); |
| 2752 | bi->ctl_ch = ch.chnum; |
| 2753 | } |
| 2754 | channel = bi->ctl_ch; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2755 | |
| 2756 | if (channel <= CH_MAX_2G_CHANNEL) |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 2757 | band = wiphy->bands[NL80211_BAND_2GHZ]; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2758 | else |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 2759 | band = wiphy->bands[NL80211_BAND_5GHZ]; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2760 | |
| 2761 | freq = ieee80211_channel_to_frequency(channel, band->band); |
| 2762 | notify_channel = ieee80211_get_channel(wiphy, freq); |
| 2763 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2764 | notify_capability = le16_to_cpu(bi->capability); |
| 2765 | notify_interval = le16_to_cpu(bi->beacon_period); |
| 2766 | notify_ie = (u8 *)bi + le16_to_cpu(bi->ie_offset); |
| 2767 | notify_ielen = le32_to_cpu(bi->ie_length); |
| 2768 | notify_signal = (s16)le16_to_cpu(bi->RSSI) * 100; |
| 2769 | |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 2770 | brcmf_dbg(CONN, "bssid: %pM\n", bi->BSSID); |
| 2771 | brcmf_dbg(CONN, "Channel: %d(%d)\n", channel, freq); |
| 2772 | brcmf_dbg(CONN, "Capability: %X\n", notify_capability); |
| 2773 | brcmf_dbg(CONN, "Beacon interval: %d\n", notify_interval); |
| 2774 | brcmf_dbg(CONN, "Signal: %d\n", notify_signal); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2775 | |
Johannes Berg | 5bc8c1f | 2014-08-12 21:01:28 +0200 | [diff] [blame] | 2776 | bss = cfg80211_inform_bss(wiphy, notify_channel, |
| 2777 | CFG80211_BSS_FTYPE_UNKNOWN, |
| 2778 | (const u8 *)bi->BSSID, |
| 2779 | 0, notify_capability, |
| 2780 | notify_interval, notify_ie, |
| 2781 | notify_ielen, notify_signal, |
| 2782 | GFP_KERNEL); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2783 | |
Franky Lin | e78946e | 2011-11-10 20:30:34 +0100 | [diff] [blame] | 2784 | if (!bss) |
| 2785 | return -ENOMEM; |
| 2786 | |
Johannes Berg | 5b112d3 | 2013-02-01 01:49:58 +0100 | [diff] [blame] | 2787 | cfg80211_put_bss(wiphy, bss); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2788 | |
Peter Senna Tschudin | 12f3237 | 2014-05-31 10:14:06 -0300 | [diff] [blame] | 2789 | return 0; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2790 | } |
| 2791 | |
Roland Vossen | 6f09be0 | 2011-10-18 14:03:02 +0200 | [diff] [blame] | 2792 | static struct brcmf_bss_info_le * |
| 2793 | next_bss_le(struct brcmf_scan_results *list, struct brcmf_bss_info_le *bss) |
| 2794 | { |
| 2795 | if (bss == NULL) |
| 2796 | return list->bss_info_le; |
| 2797 | return (struct brcmf_bss_info_le *)((unsigned long)bss + |
| 2798 | le32_to_cpu(bss->length)); |
| 2799 | } |
| 2800 | |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 2801 | static s32 brcmf_inform_bss(struct brcmf_cfg80211_info *cfg) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2802 | { |
| 2803 | struct brcmf_scan_results *bss_list; |
Roland Vossen | d34bf64 | 2011-10-18 14:03:01 +0200 | [diff] [blame] | 2804 | struct brcmf_bss_info_le *bi = NULL; /* must be initialized */ |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2805 | s32 err = 0; |
| 2806 | int i; |
| 2807 | |
Hante Meuleman | ef8596e | 2014-09-30 10:23:13 +0200 | [diff] [blame] | 2808 | bss_list = (struct brcmf_scan_results *)cfg->escan_info.escan_buf; |
Arend van Spriel | 0ecd816 | 2012-11-05 16:22:11 -0800 | [diff] [blame] | 2809 | if (bss_list->count != 0 && |
| 2810 | bss_list->version != BRCMF_BSS_INFO_VERSION) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 2811 | brcmf_err("Version %d != WL_BSS_INFO_VERSION\n", |
| 2812 | bss_list->version); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2813 | return -EOPNOTSUPP; |
| 2814 | } |
Arend van Spriel | 4e8a008 | 2012-12-05 15:26:03 +0100 | [diff] [blame] | 2815 | brcmf_dbg(SCAN, "scanned AP count (%d)\n", bss_list->count); |
Hante Meuleman | f0799895 | 2012-11-05 16:22:13 -0800 | [diff] [blame] | 2816 | for (i = 0; i < bss_list->count; i++) { |
Roland Vossen | 6f09be0 | 2011-10-18 14:03:02 +0200 | [diff] [blame] | 2817 | bi = next_bss_le(bss_list, bi); |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 2818 | err = brcmf_inform_single_bss(cfg, bi); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2819 | if (err) |
| 2820 | break; |
| 2821 | } |
| 2822 | return err; |
| 2823 | } |
| 2824 | |
Hante Meuleman | b0a7908 | 2015-12-10 13:43:07 +0100 | [diff] [blame] | 2825 | static s32 brcmf_inform_ibss(struct brcmf_cfg80211_info *cfg, |
| 2826 | struct net_device *ndev, const u8 *bssid) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2827 | { |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 2828 | struct wiphy *wiphy = cfg_to_wiphy(cfg); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2829 | struct ieee80211_channel *notify_channel; |
Roland Vossen | d34bf64 | 2011-10-18 14:03:01 +0200 | [diff] [blame] | 2830 | struct brcmf_bss_info_le *bi = NULL; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2831 | struct ieee80211_supported_band *band; |
Franky Lin | e78946e | 2011-11-10 20:30:34 +0100 | [diff] [blame] | 2832 | struct cfg80211_bss *bss; |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 2833 | struct brcmu_chan ch; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2834 | u8 *buf = NULL; |
| 2835 | s32 err = 0; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2836 | u32 freq; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2837 | u16 notify_capability; |
| 2838 | u16 notify_interval; |
| 2839 | u8 *notify_ie; |
| 2840 | size_t notify_ielen; |
| 2841 | s32 notify_signal; |
| 2842 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 2843 | brcmf_dbg(TRACE, "Enter\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2844 | |
| 2845 | buf = kzalloc(WL_BSS_INFO_MAX, GFP_KERNEL); |
| 2846 | if (buf == NULL) { |
| 2847 | err = -ENOMEM; |
| 2848 | goto CleanUp; |
| 2849 | } |
| 2850 | |
| 2851 | *(__le32 *)buf = cpu_to_le32(WL_BSS_INFO_MAX); |
| 2852 | |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 2853 | err = brcmf_fil_cmd_data_get(netdev_priv(ndev), BRCMF_C_GET_BSS_INFO, |
| 2854 | buf, WL_BSS_INFO_MAX); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2855 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 2856 | brcmf_err("WLC_GET_BSS_INFO failed: %d\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2857 | goto CleanUp; |
| 2858 | } |
| 2859 | |
Roland Vossen | d34bf64 | 2011-10-18 14:03:01 +0200 | [diff] [blame] | 2860 | bi = (struct brcmf_bss_info_le *)(buf + 4); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2861 | |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 2862 | ch.chspec = le16_to_cpu(bi->chanspec); |
| 2863 | cfg->d11inf.decchspec(&ch); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2864 | |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 2865 | if (ch.band == BRCMU_CHAN_BAND_2G) |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 2866 | band = wiphy->bands[NL80211_BAND_2GHZ]; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2867 | else |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 2868 | band = wiphy->bands[NL80211_BAND_5GHZ]; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2869 | |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 2870 | freq = ieee80211_channel_to_frequency(ch.chnum, band->band); |
Hante Meuleman | b0a7908 | 2015-12-10 13:43:07 +0100 | [diff] [blame] | 2871 | cfg->channel = freq; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2872 | notify_channel = ieee80211_get_channel(wiphy, freq); |
| 2873 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2874 | notify_capability = le16_to_cpu(bi->capability); |
| 2875 | notify_interval = le16_to_cpu(bi->beacon_period); |
| 2876 | notify_ie = (u8 *)bi + le16_to_cpu(bi->ie_offset); |
| 2877 | notify_ielen = le32_to_cpu(bi->ie_length); |
| 2878 | notify_signal = (s16)le16_to_cpu(bi->RSSI) * 100; |
| 2879 | |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 2880 | brcmf_dbg(CONN, "channel: %d(%d)\n", ch.chnum, freq); |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 2881 | brcmf_dbg(CONN, "capability: %X\n", notify_capability); |
| 2882 | brcmf_dbg(CONN, "beacon interval: %d\n", notify_interval); |
| 2883 | brcmf_dbg(CONN, "signal: %d\n", notify_signal); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2884 | |
Johannes Berg | 5bc8c1f | 2014-08-12 21:01:28 +0200 | [diff] [blame] | 2885 | bss = cfg80211_inform_bss(wiphy, notify_channel, |
| 2886 | CFG80211_BSS_FTYPE_UNKNOWN, bssid, 0, |
| 2887 | notify_capability, notify_interval, |
| 2888 | notify_ie, notify_ielen, notify_signal, |
| 2889 | GFP_KERNEL); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2890 | |
Franky Lin | e78946e | 2011-11-10 20:30:34 +0100 | [diff] [blame] | 2891 | if (!bss) { |
| 2892 | err = -ENOMEM; |
| 2893 | goto CleanUp; |
| 2894 | } |
| 2895 | |
Johannes Berg | 5b112d3 | 2013-02-01 01:49:58 +0100 | [diff] [blame] | 2896 | cfg80211_put_bss(wiphy, bss); |
Franky Lin | e78946e | 2011-11-10 20:30:34 +0100 | [diff] [blame] | 2897 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2898 | CleanUp: |
| 2899 | |
| 2900 | kfree(buf); |
| 2901 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 2902 | brcmf_dbg(TRACE, "Exit\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2903 | |
| 2904 | return err; |
| 2905 | } |
| 2906 | |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 2907 | static s32 brcmf_update_bss_info(struct brcmf_cfg80211_info *cfg, |
| 2908 | struct brcmf_if *ifp) |
Alwin Beukers | f8e4b41 | 2011-10-12 20:51:28 +0200 | [diff] [blame] | 2909 | { |
Roland Vossen | d34bf64 | 2011-10-18 14:03:01 +0200 | [diff] [blame] | 2910 | struct brcmf_bss_info_le *bi; |
Johannes Berg | 4b5800f | 2014-01-15 14:55:59 +0100 | [diff] [blame] | 2911 | const struct brcmf_tlv *tim; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2912 | u16 beacon_interval; |
| 2913 | u8 dtim_period; |
| 2914 | size_t ie_len; |
| 2915 | u8 *ie; |
| 2916 | s32 err = 0; |
| 2917 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 2918 | brcmf_dbg(TRACE, "Enter\n"); |
Arend van Spriel | 128ce3b | 2012-11-28 21:44:12 +0100 | [diff] [blame] | 2919 | if (brcmf_is_ibssmode(ifp->vif)) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2920 | return err; |
| 2921 | |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 2922 | *(__le32 *)cfg->extra_buf = cpu_to_le32(WL_EXTRA_BUF_MAX); |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 2923 | err = brcmf_fil_cmd_data_get(ifp, BRCMF_C_GET_BSS_INFO, |
Hante Meuleman | 81f5dcb | 2012-10-22 10:36:14 -0700 | [diff] [blame] | 2924 | cfg->extra_buf, WL_EXTRA_BUF_MAX); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2925 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 2926 | brcmf_err("Could not get bss info %d\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2927 | goto update_bss_info_out; |
| 2928 | } |
| 2929 | |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 2930 | bi = (struct brcmf_bss_info_le *)(cfg->extra_buf + 4); |
| 2931 | err = brcmf_inform_single_bss(cfg, bi); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2932 | if (err) |
| 2933 | goto update_bss_info_out; |
| 2934 | |
| 2935 | ie = ((u8 *)bi) + le16_to_cpu(bi->ie_offset); |
| 2936 | ie_len = le32_to_cpu(bi->ie_length); |
| 2937 | beacon_interval = le16_to_cpu(bi->beacon_period); |
| 2938 | |
Alwin Beukers | f8e4b41 | 2011-10-12 20:51:28 +0200 | [diff] [blame] | 2939 | tim = brcmf_parse_tlvs(ie, ie_len, WLAN_EID_TIM); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2940 | if (tim) |
| 2941 | dtim_period = tim->data[1]; |
| 2942 | else { |
| 2943 | /* |
| 2944 | * active scan was done so we could not get dtim |
| 2945 | * information out of probe response. |
| 2946 | * so we speficially query dtim information to dongle. |
| 2947 | */ |
| 2948 | u32 var; |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 2949 | err = brcmf_fil_iovar_int_get(ifp, "dtim_assoc", &var); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2950 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 2951 | brcmf_err("wl dtim_assoc failed (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2952 | goto update_bss_info_out; |
| 2953 | } |
| 2954 | dtim_period = (u8)var; |
| 2955 | } |
| 2956 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2957 | update_bss_info_out: |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 2958 | brcmf_dbg(TRACE, "Exit"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2959 | return err; |
| 2960 | } |
| 2961 | |
Hante Meuleman | 18e2f61 | 2013-02-08 15:53:49 +0100 | [diff] [blame] | 2962 | void brcmf_abort_scanning(struct brcmf_cfg80211_info *cfg) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2963 | { |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 2964 | struct escan_info *escan = &cfg->escan_info; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2965 | |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 2966 | set_bit(BRCMF_SCAN_STATUS_ABORT, &cfg->scan_status); |
Hante Meuleman | f0799895 | 2012-11-05 16:22:13 -0800 | [diff] [blame] | 2967 | if (cfg->scan_request) { |
Arend van Spriel | 108a4be | 2012-09-19 22:21:07 +0200 | [diff] [blame] | 2968 | escan->escan_state = WL_ESCAN_STATE_IDLE; |
Arend van Spriel | a0f472a | 2013-04-05 10:57:49 +0200 | [diff] [blame] | 2969 | brcmf_notify_escan_complete(cfg, escan->ifp, true, true); |
Arend van Spriel | 108a4be | 2012-09-19 22:21:07 +0200 | [diff] [blame] | 2970 | } |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 2971 | clear_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status); |
| 2972 | clear_bit(BRCMF_SCAN_STATUS_ABORT, &cfg->scan_status); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2973 | } |
| 2974 | |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 2975 | static void brcmf_cfg80211_escan_timeout_worker(struct work_struct *work) |
| 2976 | { |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 2977 | struct brcmf_cfg80211_info *cfg = |
| 2978 | container_of(work, struct brcmf_cfg80211_info, |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 2979 | escan_timeout_work); |
| 2980 | |
Hante Meuleman | ef8596e | 2014-09-30 10:23:13 +0200 | [diff] [blame] | 2981 | brcmf_inform_bss(cfg); |
Arend van Spriel | a0f472a | 2013-04-05 10:57:49 +0200 | [diff] [blame] | 2982 | brcmf_notify_escan_complete(cfg, cfg->escan_info.ifp, true, true); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 2983 | } |
| 2984 | |
| 2985 | static void brcmf_escan_timeout(unsigned long data) |
| 2986 | { |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 2987 | struct brcmf_cfg80211_info *cfg = |
| 2988 | (struct brcmf_cfg80211_info *)data; |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 2989 | |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 2990 | if (cfg->scan_request) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 2991 | brcmf_err("timer expired\n"); |
Hante Meuleman | f0799895 | 2012-11-05 16:22:13 -0800 | [diff] [blame] | 2992 | schedule_work(&cfg->escan_timeout_work); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 2993 | } |
| 2994 | } |
| 2995 | |
| 2996 | static s32 |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 2997 | brcmf_compare_update_same_bss(struct brcmf_cfg80211_info *cfg, |
| 2998 | struct brcmf_bss_info_le *bss, |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 2999 | struct brcmf_bss_info_le *bss_info_le) |
| 3000 | { |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 3001 | struct brcmu_chan ch_bss, ch_bss_info_le; |
| 3002 | |
| 3003 | ch_bss.chspec = le16_to_cpu(bss->chanspec); |
| 3004 | cfg->d11inf.decchspec(&ch_bss); |
| 3005 | ch_bss_info_le.chspec = le16_to_cpu(bss_info_le->chanspec); |
| 3006 | cfg->d11inf.decchspec(&ch_bss_info_le); |
| 3007 | |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 3008 | if (!memcmp(&bss_info_le->BSSID, &bss->BSSID, ETH_ALEN) && |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 3009 | ch_bss.band == ch_bss_info_le.band && |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 3010 | bss_info_le->SSID_len == bss->SSID_len && |
| 3011 | !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] | 3012 | if ((bss->flags & BRCMF_BSS_RSSI_ON_CHANNEL) == |
| 3013 | (bss_info_le->flags & BRCMF_BSS_RSSI_ON_CHANNEL)) { |
Arend van Spriel | 029591f | 2012-09-19 22:21:06 +0200 | [diff] [blame] | 3014 | s16 bss_rssi = le16_to_cpu(bss->RSSI); |
| 3015 | s16 bss_info_rssi = le16_to_cpu(bss_info_le->RSSI); |
| 3016 | |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 3017 | /* preserve max RSSI if the measurements are |
| 3018 | * both on-channel or both off-channel |
| 3019 | */ |
Arend van Spriel | 029591f | 2012-09-19 22:21:06 +0200 | [diff] [blame] | 3020 | if (bss_info_rssi > bss_rssi) |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 3021 | bss->RSSI = bss_info_le->RSSI; |
Arend van Spriel | 6f5838a | 2013-11-29 12:25:19 +0100 | [diff] [blame] | 3022 | } else if ((bss->flags & BRCMF_BSS_RSSI_ON_CHANNEL) && |
| 3023 | (bss_info_le->flags & BRCMF_BSS_RSSI_ON_CHANNEL) == 0) { |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 3024 | /* preserve the on-channel rssi measurement |
| 3025 | * if the new measurement is off channel |
| 3026 | */ |
| 3027 | bss->RSSI = bss_info_le->RSSI; |
Arend van Spriel | 6f5838a | 2013-11-29 12:25:19 +0100 | [diff] [blame] | 3028 | bss->flags |= BRCMF_BSS_RSSI_ON_CHANNEL; |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 3029 | } |
| 3030 | return 1; |
| 3031 | } |
| 3032 | return 0; |
| 3033 | } |
| 3034 | |
| 3035 | static s32 |
Arend van Spriel | 1993732 | 2012-11-05 16:22:32 -0800 | [diff] [blame] | 3036 | brcmf_cfg80211_escan_handler(struct brcmf_if *ifp, |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 3037 | const struct brcmf_event_msg *e, void *data) |
| 3038 | { |
Arend van Spriel | 1993732 | 2012-11-05 16:22:32 -0800 | [diff] [blame] | 3039 | struct brcmf_cfg80211_info *cfg = ifp->drvr->config; |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 3040 | s32 status; |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 3041 | struct brcmf_escan_result_le *escan_result_le; |
| 3042 | struct brcmf_bss_info_le *bss_info_le; |
| 3043 | struct brcmf_bss_info_le *bss = NULL; |
| 3044 | u32 bi_length; |
| 3045 | struct brcmf_scan_results *list; |
| 3046 | u32 i; |
Arend van Spriel | 97ed15c | 2012-09-13 21:12:06 +0200 | [diff] [blame] | 3047 | bool aborted; |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 3048 | |
Arend van Spriel | 5c36b99 | 2012-11-14 18:46:05 -0800 | [diff] [blame] | 3049 | status = e->status; |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 3050 | |
Arend van Spriel | a0f472a | 2013-04-05 10:57:49 +0200 | [diff] [blame] | 3051 | if (!test_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status)) { |
Hante Meuleman | 37a869e | 2015-10-29 20:33:17 +0100 | [diff] [blame] | 3052 | brcmf_err("scan not ready, bsscfgidx=%d\n", ifp->bsscfgidx); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 3053 | return -EPERM; |
| 3054 | } |
| 3055 | |
| 3056 | if (status == BRCMF_E_STATUS_PARTIAL) { |
Arend van Spriel | 4e8a008 | 2012-12-05 15:26:03 +0100 | [diff] [blame] | 3057 | brcmf_dbg(SCAN, "ESCAN Partial result\n"); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 3058 | escan_result_le = (struct brcmf_escan_result_le *) data; |
| 3059 | if (!escan_result_le) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 3060 | brcmf_err("Invalid escan result (NULL pointer)\n"); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 3061 | goto exit; |
| 3062 | } |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 3063 | if (le16_to_cpu(escan_result_le->bss_count) != 1) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 3064 | brcmf_err("Invalid bss_count %d: ignoring\n", |
| 3065 | escan_result_le->bss_count); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 3066 | goto exit; |
| 3067 | } |
| 3068 | bss_info_le = &escan_result_le->bss_info_le; |
| 3069 | |
Hante Meuleman | 6eda4e2 | 2013-02-08 15:54:02 +0100 | [diff] [blame] | 3070 | if (brcmf_p2p_scan_finding_common_channel(cfg, bss_info_le)) |
| 3071 | goto exit; |
| 3072 | |
| 3073 | if (!cfg->scan_request) { |
| 3074 | brcmf_dbg(SCAN, "result without cfg80211 request\n"); |
| 3075 | goto exit; |
| 3076 | } |
| 3077 | |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 3078 | bi_length = le32_to_cpu(bss_info_le->length); |
| 3079 | if (bi_length != (le32_to_cpu(escan_result_le->buflen) - |
| 3080 | WL_ESCAN_RESULTS_FIXED_SIZE)) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 3081 | brcmf_err("Invalid bss_info length %d: ignoring\n", |
| 3082 | bi_length); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 3083 | goto exit; |
| 3084 | } |
| 3085 | |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 3086 | if (!(cfg_to_wiphy(cfg)->interface_modes & |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 3087 | BIT(NL80211_IFTYPE_ADHOC))) { |
| 3088 | if (le16_to_cpu(bss_info_le->capability) & |
| 3089 | WLAN_CAPABILITY_IBSS) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 3090 | brcmf_err("Ignoring IBSS result\n"); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 3091 | goto exit; |
| 3092 | } |
| 3093 | } |
| 3094 | |
| 3095 | list = (struct brcmf_scan_results *) |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 3096 | cfg->escan_info.escan_buf; |
Hante Meuleman | d536733 | 2016-02-17 11:26:51 +0100 | [diff] [blame] | 3097 | if (bi_length > BRCMF_ESCAN_BUF_SIZE - list->buflen) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 3098 | brcmf_err("Buffer is too small: ignoring\n"); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 3099 | goto exit; |
| 3100 | } |
| 3101 | |
| 3102 | for (i = 0; i < list->count; i++) { |
| 3103 | bss = bss ? (struct brcmf_bss_info_le *) |
| 3104 | ((unsigned char *)bss + |
| 3105 | le32_to_cpu(bss->length)) : list->bss_info_le; |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 3106 | if (brcmf_compare_update_same_bss(cfg, bss, |
| 3107 | bss_info_le)) |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 3108 | goto exit; |
| 3109 | } |
Hante Meuleman | d536733 | 2016-02-17 11:26:51 +0100 | [diff] [blame] | 3110 | memcpy(&cfg->escan_info.escan_buf[list->buflen], bss_info_le, |
| 3111 | bi_length); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 3112 | list->version = le32_to_cpu(bss_info_le->version); |
| 3113 | list->buflen += bi_length; |
| 3114 | list->count++; |
| 3115 | } else { |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 3116 | cfg->escan_info.escan_state = WL_ESCAN_STATE_IDLE; |
Hante Meuleman | 6eda4e2 | 2013-02-08 15:54:02 +0100 | [diff] [blame] | 3117 | if (brcmf_p2p_scan_finding_common_channel(cfg, NULL)) |
| 3118 | goto exit; |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 3119 | if (cfg->scan_request) { |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 3120 | brcmf_inform_bss(cfg); |
Arend van Spriel | 97ed15c | 2012-09-13 21:12:06 +0200 | [diff] [blame] | 3121 | aborted = status != BRCMF_E_STATUS_SUCCESS; |
Hante Meuleman | ef8596e | 2014-09-30 10:23:13 +0200 | [diff] [blame] | 3122 | brcmf_notify_escan_complete(cfg, ifp, aborted, false); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 3123 | } else |
Hante Meuleman | 6eda4e2 | 2013-02-08 15:54:02 +0100 | [diff] [blame] | 3124 | brcmf_dbg(SCAN, "Ignored scan complete result 0x%x\n", |
| 3125 | status); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 3126 | } |
| 3127 | exit: |
Peter Senna Tschudin | 12f3237 | 2014-05-31 10:14:06 -0300 | [diff] [blame] | 3128 | return 0; |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 3129 | } |
| 3130 | |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 3131 | static void brcmf_init_escan(struct brcmf_cfg80211_info *cfg) |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 3132 | { |
Arend van Spriel | 5c36b99 | 2012-11-14 18:46:05 -0800 | [diff] [blame] | 3133 | brcmf_fweh_register(cfg->pub, BRCMF_E_ESCAN_RESULT, |
| 3134 | brcmf_cfg80211_escan_handler); |
Hante Meuleman | f0799895 | 2012-11-05 16:22:13 -0800 | [diff] [blame] | 3135 | cfg->escan_info.escan_state = WL_ESCAN_STATE_IDLE; |
| 3136 | /* Init scan_timeout timer */ |
| 3137 | init_timer(&cfg->escan_timeout); |
| 3138 | cfg->escan_timeout.data = (unsigned long) cfg; |
| 3139 | cfg->escan_timeout.function = brcmf_escan_timeout; |
| 3140 | INIT_WORK(&cfg->escan_timeout_work, |
| 3141 | brcmf_cfg80211_escan_timeout_worker); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 3142 | } |
| 3143 | |
Hante Meuleman | 5419f7f | 2016-01-05 11:05:46 +0100 | [diff] [blame] | 3144 | /* PFN result doesn't have all the info which are required by the supplicant |
| 3145 | * (For e.g IEs) Do a target Escan so that sched scan results are reported |
| 3146 | * via wl_inform_single_bss in the required format. Escan does require the |
| 3147 | * scan request in the form of cfg80211_scan_request. For timebeing, create |
| 3148 | * cfg80211_scan_request one out of the received PNO event. |
| 3149 | */ |
| 3150 | static s32 |
| 3151 | brcmf_notify_sched_scan_results(struct brcmf_if *ifp, |
| 3152 | const struct brcmf_event_msg *e, void *data) |
| 3153 | { |
| 3154 | struct brcmf_cfg80211_info *cfg = ifp->drvr->config; |
| 3155 | struct brcmf_pno_net_info_le *netinfo, *netinfo_start; |
| 3156 | struct cfg80211_scan_request *request = NULL; |
| 3157 | struct cfg80211_ssid *ssid = NULL; |
| 3158 | struct ieee80211_channel *channel = NULL; |
| 3159 | struct wiphy *wiphy = cfg_to_wiphy(cfg); |
| 3160 | int err = 0; |
| 3161 | int channel_req = 0; |
| 3162 | int band = 0; |
| 3163 | struct brcmf_pno_scanresults_le *pfn_result; |
| 3164 | u32 result_count; |
| 3165 | u32 status; |
| 3166 | |
| 3167 | brcmf_dbg(SCAN, "Enter\n"); |
| 3168 | |
Hante Meuleman | 0aedbca | 2016-02-17 11:26:54 +0100 | [diff] [blame] | 3169 | if (e->datalen < (sizeof(*pfn_result) + sizeof(*netinfo))) { |
| 3170 | brcmf_dbg(SCAN, "Event data to small. Ignore\n"); |
| 3171 | return 0; |
| 3172 | } |
| 3173 | |
Hante Meuleman | 5419f7f | 2016-01-05 11:05:46 +0100 | [diff] [blame] | 3174 | if (e->event_code == BRCMF_E_PFN_NET_LOST) { |
| 3175 | brcmf_dbg(SCAN, "PFN NET LOST event. Do Nothing\n"); |
| 3176 | return 0; |
| 3177 | } |
| 3178 | |
| 3179 | pfn_result = (struct brcmf_pno_scanresults_le *)data; |
| 3180 | result_count = le32_to_cpu(pfn_result->count); |
| 3181 | status = le32_to_cpu(pfn_result->status); |
| 3182 | |
| 3183 | /* PFN event is limited to fit 512 bytes so we may get |
| 3184 | * multiple NET_FOUND events. For now place a warning here. |
| 3185 | */ |
| 3186 | WARN_ON(status != BRCMF_PNO_SCAN_COMPLETE); |
| 3187 | brcmf_dbg(SCAN, "PFN NET FOUND event. count: %d\n", result_count); |
| 3188 | if (result_count > 0) { |
| 3189 | int i; |
| 3190 | |
| 3191 | request = kzalloc(sizeof(*request), GFP_KERNEL); |
| 3192 | ssid = kcalloc(result_count, sizeof(*ssid), GFP_KERNEL); |
| 3193 | channel = kcalloc(result_count, sizeof(*channel), GFP_KERNEL); |
| 3194 | if (!request || !ssid || !channel) { |
| 3195 | err = -ENOMEM; |
| 3196 | goto out_err; |
| 3197 | } |
| 3198 | |
| 3199 | request->wiphy = wiphy; |
| 3200 | data += sizeof(struct brcmf_pno_scanresults_le); |
| 3201 | netinfo_start = (struct brcmf_pno_net_info_le *)data; |
| 3202 | |
| 3203 | for (i = 0; i < result_count; i++) { |
| 3204 | netinfo = &netinfo_start[i]; |
| 3205 | if (!netinfo) { |
| 3206 | brcmf_err("Invalid netinfo ptr. index: %d\n", |
| 3207 | i); |
| 3208 | err = -EINVAL; |
| 3209 | goto out_err; |
| 3210 | } |
| 3211 | |
| 3212 | brcmf_dbg(SCAN, "SSID:%s Channel:%d\n", |
| 3213 | netinfo->SSID, netinfo->channel); |
| 3214 | memcpy(ssid[i].ssid, netinfo->SSID, netinfo->SSID_len); |
| 3215 | ssid[i].ssid_len = netinfo->SSID_len; |
| 3216 | request->n_ssids++; |
| 3217 | |
| 3218 | channel_req = netinfo->channel; |
| 3219 | if (channel_req <= CH_MAX_2G_CHANNEL) |
| 3220 | band = NL80211_BAND_2GHZ; |
| 3221 | else |
| 3222 | band = NL80211_BAND_5GHZ; |
| 3223 | channel[i].center_freq = |
| 3224 | ieee80211_channel_to_frequency(channel_req, |
| 3225 | band); |
| 3226 | channel[i].band = band; |
| 3227 | channel[i].flags |= IEEE80211_CHAN_NO_HT40; |
| 3228 | request->channels[i] = &channel[i]; |
| 3229 | request->n_channels++; |
| 3230 | } |
| 3231 | |
| 3232 | /* assign parsed ssid array */ |
| 3233 | if (request->n_ssids) |
| 3234 | request->ssids = &ssid[0]; |
| 3235 | |
| 3236 | if (test_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status)) { |
| 3237 | /* Abort any on-going scan */ |
| 3238 | brcmf_abort_scanning(cfg); |
| 3239 | } |
| 3240 | |
| 3241 | set_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status); |
| 3242 | cfg->escan_info.run = brcmf_run_escan; |
| 3243 | err = brcmf_do_escan(cfg, wiphy, ifp, request); |
| 3244 | if (err) { |
| 3245 | clear_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status); |
| 3246 | goto out_err; |
| 3247 | } |
| 3248 | cfg->sched_escan = true; |
| 3249 | cfg->scan_request = request; |
| 3250 | } else { |
| 3251 | brcmf_err("FALSE PNO Event. (pfn_count == 0)\n"); |
| 3252 | goto out_err; |
| 3253 | } |
| 3254 | |
| 3255 | kfree(ssid); |
| 3256 | kfree(channel); |
| 3257 | kfree(request); |
| 3258 | return 0; |
| 3259 | |
| 3260 | out_err: |
| 3261 | kfree(ssid); |
| 3262 | kfree(channel); |
| 3263 | kfree(request); |
| 3264 | cfg80211_sched_scan_stopped(wiphy); |
| 3265 | return err; |
| 3266 | } |
| 3267 | |
| 3268 | static int brcmf_dev_pno_clean(struct net_device *ndev) |
| 3269 | { |
| 3270 | int ret; |
| 3271 | |
| 3272 | /* Disable pfn */ |
| 3273 | ret = brcmf_fil_iovar_int_set(netdev_priv(ndev), "pfn", 0); |
| 3274 | if (ret == 0) { |
| 3275 | /* clear pfn */ |
| 3276 | ret = brcmf_fil_iovar_data_set(netdev_priv(ndev), "pfnclear", |
| 3277 | NULL, 0); |
| 3278 | } |
| 3279 | if (ret < 0) |
| 3280 | brcmf_err("failed code %d\n", ret); |
| 3281 | |
| 3282 | return ret; |
| 3283 | } |
| 3284 | |
| 3285 | static int brcmf_dev_pno_config(struct brcmf_if *ifp, |
| 3286 | struct cfg80211_sched_scan_request *request) |
| 3287 | { |
| 3288 | struct brcmf_pno_param_le pfn_param; |
| 3289 | struct brcmf_pno_macaddr_le pfn_mac; |
| 3290 | s32 err; |
| 3291 | u8 *mac_mask; |
| 3292 | int i; |
| 3293 | |
| 3294 | memset(&pfn_param, 0, sizeof(pfn_param)); |
| 3295 | pfn_param.version = cpu_to_le32(BRCMF_PNO_VERSION); |
| 3296 | |
| 3297 | /* set extra pno params */ |
| 3298 | pfn_param.flags = cpu_to_le16(1 << BRCMF_PNO_ENABLE_ADAPTSCAN_BIT); |
| 3299 | pfn_param.repeat = BRCMF_PNO_REPEAT; |
| 3300 | pfn_param.exp = BRCMF_PNO_FREQ_EXPO_MAX; |
| 3301 | |
| 3302 | /* set up pno scan fr */ |
| 3303 | pfn_param.scan_freq = cpu_to_le32(BRCMF_PNO_TIME); |
| 3304 | |
| 3305 | err = brcmf_fil_iovar_data_set(ifp, "pfn_set", &pfn_param, |
| 3306 | sizeof(pfn_param)); |
| 3307 | if (err) { |
| 3308 | brcmf_err("pfn_set failed, err=%d\n", err); |
| 3309 | return err; |
| 3310 | } |
| 3311 | |
| 3312 | /* Find out if mac randomization should be turned on */ |
| 3313 | if (!(request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR)) |
| 3314 | return 0; |
| 3315 | |
| 3316 | pfn_mac.version = BRCMF_PFN_MACADDR_CFG_VER; |
| 3317 | pfn_mac.flags = BRCMF_PFN_MAC_OUI_ONLY | BRCMF_PFN_SET_MAC_UNASSOC; |
| 3318 | |
| 3319 | memcpy(pfn_mac.mac, request->mac_addr, ETH_ALEN); |
| 3320 | mac_mask = request->mac_addr_mask; |
| 3321 | for (i = 0; i < ETH_ALEN; i++) { |
| 3322 | pfn_mac.mac[i] &= mac_mask[i]; |
| 3323 | pfn_mac.mac[i] |= get_random_int() & ~(mac_mask[i]); |
| 3324 | } |
| 3325 | /* Clear multi bit */ |
| 3326 | pfn_mac.mac[0] &= 0xFE; |
| 3327 | /* Set locally administered */ |
| 3328 | pfn_mac.mac[0] |= 0x02; |
| 3329 | |
| 3330 | err = brcmf_fil_iovar_data_set(ifp, "pfn_macaddr", &pfn_mac, |
| 3331 | sizeof(pfn_mac)); |
| 3332 | if (err) |
| 3333 | brcmf_err("pfn_macaddr failed, err=%d\n", err); |
| 3334 | |
| 3335 | return err; |
| 3336 | } |
| 3337 | |
| 3338 | static int |
| 3339 | brcmf_cfg80211_sched_scan_start(struct wiphy *wiphy, |
| 3340 | struct net_device *ndev, |
| 3341 | struct cfg80211_sched_scan_request *request) |
| 3342 | { |
| 3343 | struct brcmf_if *ifp = netdev_priv(ndev); |
| 3344 | struct brcmf_cfg80211_info *cfg = wiphy_priv(wiphy); |
| 3345 | struct brcmf_pno_net_param_le pfn; |
| 3346 | int i; |
| 3347 | int ret = 0; |
| 3348 | |
| 3349 | brcmf_dbg(SCAN, "Enter n_match_sets:%d n_ssids:%d\n", |
| 3350 | request->n_match_sets, request->n_ssids); |
| 3351 | if (test_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status)) { |
| 3352 | brcmf_err("Scanning already: status (%lu)\n", cfg->scan_status); |
| 3353 | return -EAGAIN; |
| 3354 | } |
| 3355 | if (test_bit(BRCMF_SCAN_STATUS_SUPPRESS, &cfg->scan_status)) { |
| 3356 | brcmf_err("Scanning suppressed: status (%lu)\n", |
| 3357 | cfg->scan_status); |
| 3358 | return -EAGAIN; |
| 3359 | } |
| 3360 | |
| 3361 | if (!request->n_ssids || !request->n_match_sets) { |
| 3362 | brcmf_dbg(SCAN, "Invalid sched scan req!! n_ssids:%d\n", |
| 3363 | request->n_ssids); |
| 3364 | return -EINVAL; |
| 3365 | } |
| 3366 | |
| 3367 | if (request->n_ssids > 0) { |
| 3368 | for (i = 0; i < request->n_ssids; i++) { |
| 3369 | /* Active scan req for ssids */ |
| 3370 | brcmf_dbg(SCAN, ">>> Active scan req for ssid (%s)\n", |
| 3371 | request->ssids[i].ssid); |
| 3372 | |
| 3373 | /* match_set ssids is a supert set of n_ssid list, |
| 3374 | * so we need not add these set separately. |
| 3375 | */ |
| 3376 | } |
| 3377 | } |
| 3378 | |
| 3379 | if (request->n_match_sets > 0) { |
| 3380 | /* clean up everything */ |
| 3381 | ret = brcmf_dev_pno_clean(ndev); |
| 3382 | if (ret < 0) { |
| 3383 | brcmf_err("failed error=%d\n", ret); |
| 3384 | return ret; |
| 3385 | } |
| 3386 | |
| 3387 | /* configure pno */ |
| 3388 | if (brcmf_dev_pno_config(ifp, request)) |
| 3389 | return -EINVAL; |
| 3390 | |
| 3391 | /* configure each match set */ |
| 3392 | for (i = 0; i < request->n_match_sets; i++) { |
| 3393 | struct cfg80211_ssid *ssid; |
| 3394 | u32 ssid_len; |
| 3395 | |
| 3396 | ssid = &request->match_sets[i].ssid; |
| 3397 | ssid_len = ssid->ssid_len; |
| 3398 | |
| 3399 | if (!ssid_len) { |
| 3400 | brcmf_err("skip broadcast ssid\n"); |
| 3401 | continue; |
| 3402 | } |
| 3403 | pfn.auth = cpu_to_le32(WLAN_AUTH_OPEN); |
| 3404 | pfn.wpa_auth = cpu_to_le32(BRCMF_PNO_WPA_AUTH_ANY); |
| 3405 | pfn.wsec = cpu_to_le32(0); |
| 3406 | pfn.infra = cpu_to_le32(1); |
| 3407 | pfn.flags = cpu_to_le32(1 << BRCMF_PNO_HIDDEN_BIT); |
| 3408 | pfn.ssid.SSID_len = cpu_to_le32(ssid_len); |
| 3409 | memcpy(pfn.ssid.SSID, ssid->ssid, ssid_len); |
| 3410 | ret = brcmf_fil_iovar_data_set(ifp, "pfn_add", &pfn, |
| 3411 | sizeof(pfn)); |
| 3412 | brcmf_dbg(SCAN, ">>> PNO filter %s for ssid (%s)\n", |
| 3413 | ret == 0 ? "set" : "failed", ssid->ssid); |
| 3414 | } |
| 3415 | /* Enable the PNO */ |
| 3416 | if (brcmf_fil_iovar_int_set(ifp, "pfn", 1) < 0) { |
| 3417 | brcmf_err("PNO enable failed!! ret=%d\n", ret); |
| 3418 | return -EINVAL; |
| 3419 | } |
| 3420 | } else { |
| 3421 | return -EINVAL; |
| 3422 | } |
| 3423 | |
| 3424 | return 0; |
| 3425 | } |
| 3426 | |
| 3427 | static int brcmf_cfg80211_sched_scan_stop(struct wiphy *wiphy, |
| 3428 | struct net_device *ndev) |
| 3429 | { |
| 3430 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); |
| 3431 | |
| 3432 | brcmf_dbg(SCAN, "enter\n"); |
| 3433 | brcmf_dev_pno_clean(ndev); |
| 3434 | if (cfg->sched_escan) |
| 3435 | brcmf_notify_escan_complete(cfg, netdev_priv(ndev), true, true); |
| 3436 | return 0; |
| 3437 | } |
| 3438 | |
Alexandre Oliva | 5addc0d | 2012-01-16 14:00:12 -0500 | [diff] [blame] | 3439 | static __always_inline void brcmf_delay(u32 ms) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3440 | { |
| 3441 | if (ms < 1000 / HZ) { |
| 3442 | cond_resched(); |
| 3443 | mdelay(ms); |
| 3444 | } else { |
| 3445 | msleep(ms); |
| 3446 | } |
| 3447 | } |
| 3448 | |
Hante Meuleman | b9a82f8 | 2014-10-28 14:56:06 +0100 | [diff] [blame] | 3449 | static s32 brcmf_config_wowl_pattern(struct brcmf_if *ifp, u8 cmd[4], |
| 3450 | u8 *pattern, u32 patternsize, u8 *mask, |
| 3451 | u32 packet_offset) |
| 3452 | { |
| 3453 | struct brcmf_fil_wowl_pattern_le *filter; |
| 3454 | u32 masksize; |
| 3455 | u32 patternoffset; |
| 3456 | u8 *buf; |
| 3457 | u32 bufsize; |
| 3458 | s32 ret; |
| 3459 | |
| 3460 | masksize = (patternsize + 7) / 8; |
| 3461 | patternoffset = sizeof(*filter) - sizeof(filter->cmd) + masksize; |
| 3462 | |
| 3463 | bufsize = sizeof(*filter) + patternsize + masksize; |
| 3464 | buf = kzalloc(bufsize, GFP_KERNEL); |
| 3465 | if (!buf) |
| 3466 | return -ENOMEM; |
| 3467 | filter = (struct brcmf_fil_wowl_pattern_le *)buf; |
| 3468 | |
| 3469 | memcpy(filter->cmd, cmd, 4); |
| 3470 | filter->masksize = cpu_to_le32(masksize); |
| 3471 | filter->offset = cpu_to_le32(packet_offset); |
| 3472 | filter->patternoffset = cpu_to_le32(patternoffset); |
| 3473 | filter->patternsize = cpu_to_le32(patternsize); |
| 3474 | filter->type = cpu_to_le32(BRCMF_WOWL_PATTERN_TYPE_BITMAP); |
| 3475 | |
| 3476 | if ((mask) && (masksize)) |
| 3477 | memcpy(buf + sizeof(*filter), mask, masksize); |
| 3478 | if ((pattern) && (patternsize)) |
| 3479 | memcpy(buf + sizeof(*filter) + masksize, pattern, patternsize); |
| 3480 | |
| 3481 | ret = brcmf_fil_iovar_data_set(ifp, "wowl_pattern", buf, bufsize); |
| 3482 | |
| 3483 | kfree(buf); |
| 3484 | return ret; |
| 3485 | } |
| 3486 | |
Hante Meuleman | 3021ad9 | 2016-01-05 11:05:45 +0100 | [diff] [blame] | 3487 | static s32 |
| 3488 | brcmf_wowl_nd_results(struct brcmf_if *ifp, const struct brcmf_event_msg *e, |
| 3489 | void *data) |
| 3490 | { |
| 3491 | struct brcmf_cfg80211_info *cfg = ifp->drvr->config; |
| 3492 | struct brcmf_pno_scanresults_le *pfn_result; |
| 3493 | struct brcmf_pno_net_info_le *netinfo; |
| 3494 | |
| 3495 | brcmf_dbg(SCAN, "Enter\n"); |
| 3496 | |
Hante Meuleman | 0aedbca | 2016-02-17 11:26:54 +0100 | [diff] [blame] | 3497 | if (e->datalen < (sizeof(*pfn_result) + sizeof(*netinfo))) { |
| 3498 | brcmf_dbg(SCAN, "Event data to small. Ignore\n"); |
| 3499 | return 0; |
| 3500 | } |
| 3501 | |
Hante Meuleman | 3021ad9 | 2016-01-05 11:05:45 +0100 | [diff] [blame] | 3502 | pfn_result = (struct brcmf_pno_scanresults_le *)data; |
| 3503 | |
| 3504 | if (e->event_code == BRCMF_E_PFN_NET_LOST) { |
| 3505 | brcmf_dbg(SCAN, "PFN NET LOST event. Ignore\n"); |
| 3506 | return 0; |
| 3507 | } |
| 3508 | |
| 3509 | if (le32_to_cpu(pfn_result->count) < 1) { |
| 3510 | brcmf_err("Invalid result count, expected 1 (%d)\n", |
| 3511 | le32_to_cpu(pfn_result->count)); |
| 3512 | return -EINVAL; |
| 3513 | } |
| 3514 | |
| 3515 | data += sizeof(struct brcmf_pno_scanresults_le); |
| 3516 | netinfo = (struct brcmf_pno_net_info_le *)data; |
| 3517 | memcpy(cfg->wowl.nd->ssid.ssid, netinfo->SSID, netinfo->SSID_len); |
| 3518 | cfg->wowl.nd->ssid.ssid_len = netinfo->SSID_len; |
| 3519 | cfg->wowl.nd->n_channels = 1; |
| 3520 | cfg->wowl.nd->channels[0] = |
| 3521 | ieee80211_channel_to_frequency(netinfo->channel, |
| 3522 | netinfo->channel <= CH_MAX_2G_CHANNEL ? |
| 3523 | NL80211_BAND_2GHZ : NL80211_BAND_5GHZ); |
| 3524 | cfg->wowl.nd_info->n_matches = 1; |
| 3525 | cfg->wowl.nd_info->matches[0] = cfg->wowl.nd; |
| 3526 | |
| 3527 | /* Inform (the resume task) that the net detect information was recvd */ |
| 3528 | cfg->wowl.nd_data_completed = true; |
| 3529 | wake_up(&cfg->wowl.nd_data_wait); |
| 3530 | |
| 3531 | return 0; |
| 3532 | } |
| 3533 | |
Hante Meuleman | aeb6422 | 2015-10-29 20:33:19 +0100 | [diff] [blame] | 3534 | #ifdef CONFIG_PM |
| 3535 | |
| 3536 | static void brcmf_report_wowl_wakeind(struct wiphy *wiphy, struct brcmf_if *ifp) |
| 3537 | { |
Hante Meuleman | 3021ad9 | 2016-01-05 11:05:45 +0100 | [diff] [blame] | 3538 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); |
Hante Meuleman | aeb6422 | 2015-10-29 20:33:19 +0100 | [diff] [blame] | 3539 | struct brcmf_wowl_wakeind_le wake_ind_le; |
| 3540 | struct cfg80211_wowlan_wakeup wakeup_data; |
| 3541 | struct cfg80211_wowlan_wakeup *wakeup; |
| 3542 | u32 wakeind; |
| 3543 | s32 err; |
Hante Meuleman | 3021ad9 | 2016-01-05 11:05:45 +0100 | [diff] [blame] | 3544 | int timeout; |
Hante Meuleman | aeb6422 | 2015-10-29 20:33:19 +0100 | [diff] [blame] | 3545 | |
| 3546 | err = brcmf_fil_iovar_data_get(ifp, "wowl_wakeind", &wake_ind_le, |
| 3547 | sizeof(wake_ind_le)); |
Hante Meuleman | 3021ad9 | 2016-01-05 11:05:45 +0100 | [diff] [blame] | 3548 | if (err) { |
Hante Meuleman | aeb6422 | 2015-10-29 20:33:19 +0100 | [diff] [blame] | 3549 | brcmf_err("Get wowl_wakeind failed, err = %d\n", err); |
| 3550 | return; |
| 3551 | } |
| 3552 | |
| 3553 | wakeind = le32_to_cpu(wake_ind_le.ucode_wakeind); |
| 3554 | if (wakeind & (BRCMF_WOWL_MAGIC | BRCMF_WOWL_DIS | BRCMF_WOWL_BCN | |
Hante Meuleman | 3021ad9 | 2016-01-05 11:05:45 +0100 | [diff] [blame] | 3555 | BRCMF_WOWL_RETR | BRCMF_WOWL_NET | |
| 3556 | BRCMF_WOWL_PFN_FOUND)) { |
Hante Meuleman | aeb6422 | 2015-10-29 20:33:19 +0100 | [diff] [blame] | 3557 | wakeup = &wakeup_data; |
| 3558 | memset(&wakeup_data, 0, sizeof(wakeup_data)); |
| 3559 | wakeup_data.pattern_idx = -1; |
| 3560 | |
| 3561 | if (wakeind & BRCMF_WOWL_MAGIC) { |
| 3562 | brcmf_dbg(INFO, "WOWL Wake indicator: BRCMF_WOWL_MAGIC\n"); |
| 3563 | wakeup_data.magic_pkt = true; |
| 3564 | } |
| 3565 | if (wakeind & BRCMF_WOWL_DIS) { |
| 3566 | brcmf_dbg(INFO, "WOWL Wake indicator: BRCMF_WOWL_DIS\n"); |
| 3567 | wakeup_data.disconnect = true; |
| 3568 | } |
| 3569 | if (wakeind & BRCMF_WOWL_BCN) { |
| 3570 | brcmf_dbg(INFO, "WOWL Wake indicator: BRCMF_WOWL_BCN\n"); |
| 3571 | wakeup_data.disconnect = true; |
| 3572 | } |
| 3573 | if (wakeind & BRCMF_WOWL_RETR) { |
| 3574 | brcmf_dbg(INFO, "WOWL Wake indicator: BRCMF_WOWL_RETR\n"); |
| 3575 | wakeup_data.disconnect = true; |
| 3576 | } |
| 3577 | if (wakeind & BRCMF_WOWL_NET) { |
| 3578 | brcmf_dbg(INFO, "WOWL Wake indicator: BRCMF_WOWL_NET\n"); |
| 3579 | /* For now always map to pattern 0, no API to get |
| 3580 | * correct information available at the moment. |
| 3581 | */ |
| 3582 | wakeup_data.pattern_idx = 0; |
| 3583 | } |
Hante Meuleman | 3021ad9 | 2016-01-05 11:05:45 +0100 | [diff] [blame] | 3584 | if (wakeind & BRCMF_WOWL_PFN_FOUND) { |
| 3585 | brcmf_dbg(INFO, "WOWL Wake indicator: BRCMF_WOWL_PFN_FOUND\n"); |
| 3586 | timeout = wait_event_timeout(cfg->wowl.nd_data_wait, |
| 3587 | cfg->wowl.nd_data_completed, |
| 3588 | BRCMF_ND_INFO_TIMEOUT); |
| 3589 | if (!timeout) |
| 3590 | brcmf_err("No result for wowl net detect\n"); |
| 3591 | else |
| 3592 | wakeup_data.net_detect = cfg->wowl.nd_info; |
| 3593 | } |
Hante Meuleman | 5c22fb8 | 2016-02-17 11:27:03 +0100 | [diff] [blame] | 3594 | if (wakeind & BRCMF_WOWL_GTK_FAILURE) { |
| 3595 | brcmf_dbg(INFO, "WOWL Wake indicator: BRCMF_WOWL_GTK_FAILURE\n"); |
| 3596 | wakeup_data.gtk_rekey_failure = true; |
| 3597 | } |
Hante Meuleman | aeb6422 | 2015-10-29 20:33:19 +0100 | [diff] [blame] | 3598 | } else { |
| 3599 | wakeup = NULL; |
| 3600 | } |
| 3601 | cfg80211_report_wowlan_wakeup(&ifp->vif->wdev, wakeup, GFP_KERNEL); |
| 3602 | } |
| 3603 | |
| 3604 | #else |
| 3605 | |
| 3606 | static void brcmf_report_wowl_wakeind(struct wiphy *wiphy, struct brcmf_if *ifp) |
| 3607 | { |
| 3608 | } |
| 3609 | |
| 3610 | #endif /* CONFIG_PM */ |
| 3611 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3612 | static s32 brcmf_cfg80211_resume(struct wiphy *wiphy) |
| 3613 | { |
Hante Meuleman | 4eb3af7 | 2014-09-30 10:23:18 +0200 | [diff] [blame] | 3614 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); |
| 3615 | struct net_device *ndev = cfg_to_ndev(cfg); |
| 3616 | struct brcmf_if *ifp = netdev_priv(ndev); |
| 3617 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 3618 | brcmf_dbg(TRACE, "Enter\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3619 | |
Hante Meuleman | 3021ad9 | 2016-01-05 11:05:45 +0100 | [diff] [blame] | 3620 | if (cfg->wowl.active) { |
Hante Meuleman | aeb6422 | 2015-10-29 20:33:19 +0100 | [diff] [blame] | 3621 | brcmf_report_wowl_wakeind(wiphy, ifp); |
| 3622 | brcmf_fil_iovar_int_set(ifp, "wowl_clear", 0); |
| 3623 | brcmf_config_wowl_pattern(ifp, "clr", NULL, 0, NULL, 0); |
Hante Meuleman | 73ef9e6 | 2016-02-17 11:27:05 +0100 | [diff] [blame] | 3624 | if (!brcmf_feat_is_enabled(ifp, BRCMF_FEAT_WOWL_ARP_ND)) |
| 3625 | brcmf_configure_arp_nd_offload(ifp, true); |
Hante Meuleman | 4eb3af7 | 2014-09-30 10:23:18 +0200 | [diff] [blame] | 3626 | brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_PM, |
Hante Meuleman | 3021ad9 | 2016-01-05 11:05:45 +0100 | [diff] [blame] | 3627 | cfg->wowl.pre_pmmode); |
| 3628 | cfg->wowl.active = false; |
| 3629 | if (cfg->wowl.nd_enabled) { |
| 3630 | brcmf_cfg80211_sched_scan_stop(cfg->wiphy, ifp->ndev); |
| 3631 | brcmf_fweh_unregister(cfg->pub, BRCMF_E_PFN_NET_FOUND); |
| 3632 | brcmf_fweh_register(cfg->pub, BRCMF_E_PFN_NET_FOUND, |
| 3633 | brcmf_notify_sched_scan_results); |
| 3634 | cfg->wowl.nd_enabled = false; |
| 3635 | } |
Hante Meuleman | 4eb3af7 | 2014-09-30 10:23:18 +0200 | [diff] [blame] | 3636 | } |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3637 | return 0; |
| 3638 | } |
| 3639 | |
Hante Meuleman | 4eb3af7 | 2014-09-30 10:23:18 +0200 | [diff] [blame] | 3640 | static void brcmf_configure_wowl(struct brcmf_cfg80211_info *cfg, |
| 3641 | struct brcmf_if *ifp, |
| 3642 | struct cfg80211_wowlan *wowl) |
| 3643 | { |
| 3644 | u32 wowl_config; |
Hante Meuleman | b9a82f8 | 2014-10-28 14:56:06 +0100 | [diff] [blame] | 3645 | u32 i; |
Hante Meuleman | 4eb3af7 | 2014-09-30 10:23:18 +0200 | [diff] [blame] | 3646 | |
| 3647 | brcmf_dbg(TRACE, "Suspend, wowl config.\n"); |
| 3648 | |
Hante Meuleman | 73ef9e6 | 2016-02-17 11:27:05 +0100 | [diff] [blame] | 3649 | if (!brcmf_feat_is_enabled(ifp, BRCMF_FEAT_WOWL_ARP_ND)) |
| 3650 | brcmf_configure_arp_nd_offload(ifp, false); |
Hante Meuleman | 3021ad9 | 2016-01-05 11:05:45 +0100 | [diff] [blame] | 3651 | 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] | 3652 | brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_PM, PM_MAX); |
| 3653 | |
| 3654 | wowl_config = 0; |
| 3655 | if (wowl->disconnect) |
Hante Meuleman | b9a82f8 | 2014-10-28 14:56:06 +0100 | [diff] [blame] | 3656 | wowl_config = BRCMF_WOWL_DIS | BRCMF_WOWL_BCN | BRCMF_WOWL_RETR; |
Hante Meuleman | 4eb3af7 | 2014-09-30 10:23:18 +0200 | [diff] [blame] | 3657 | if (wowl->magic_pkt) |
Hante Meuleman | b9a82f8 | 2014-10-28 14:56:06 +0100 | [diff] [blame] | 3658 | wowl_config |= BRCMF_WOWL_MAGIC; |
| 3659 | if ((wowl->patterns) && (wowl->n_patterns)) { |
| 3660 | wowl_config |= BRCMF_WOWL_NET; |
| 3661 | for (i = 0; i < wowl->n_patterns; i++) { |
| 3662 | brcmf_config_wowl_pattern(ifp, "add", |
| 3663 | (u8 *)wowl->patterns[i].pattern, |
| 3664 | wowl->patterns[i].pattern_len, |
| 3665 | (u8 *)wowl->patterns[i].mask, |
| 3666 | wowl->patterns[i].pkt_offset); |
| 3667 | } |
| 3668 | } |
Hante Meuleman | 3021ad9 | 2016-01-05 11:05:45 +0100 | [diff] [blame] | 3669 | if (wowl->nd_config) { |
| 3670 | brcmf_cfg80211_sched_scan_start(cfg->wiphy, ifp->ndev, |
| 3671 | wowl->nd_config); |
| 3672 | wowl_config |= BRCMF_WOWL_PFN_FOUND; |
| 3673 | |
| 3674 | cfg->wowl.nd_data_completed = false; |
| 3675 | cfg->wowl.nd_enabled = true; |
| 3676 | /* Now reroute the event for PFN to the wowl function. */ |
| 3677 | brcmf_fweh_unregister(cfg->pub, BRCMF_E_PFN_NET_FOUND); |
| 3678 | brcmf_fweh_register(cfg->pub, BRCMF_E_PFN_NET_FOUND, |
| 3679 | brcmf_wowl_nd_results); |
| 3680 | } |
Hante Meuleman | 5c22fb8 | 2016-02-17 11:27:03 +0100 | [diff] [blame] | 3681 | if (wowl->gtk_rekey_failure) |
| 3682 | wowl_config |= BRCMF_WOWL_GTK_FAILURE; |
Hante Meuleman | 3021ad9 | 2016-01-05 11:05:45 +0100 | [diff] [blame] | 3683 | if (!test_bit(BRCMF_VIF_STATUS_CONNECTED, &ifp->vif->sme_state)) |
| 3684 | wowl_config |= BRCMF_WOWL_UNASSOC; |
| 3685 | |
Hante Meuleman | 28b285a | 2016-04-11 11:35:22 +0200 | [diff] [blame] | 3686 | brcmf_fil_iovar_data_set(ifp, "wowl_wakeind", "clear", |
| 3687 | sizeof(struct brcmf_wowl_wakeind_le)); |
Hante Meuleman | 4eb3af7 | 2014-09-30 10:23:18 +0200 | [diff] [blame] | 3688 | brcmf_fil_iovar_int_set(ifp, "wowl", wowl_config); |
| 3689 | brcmf_fil_iovar_int_set(ifp, "wowl_activate", 1); |
| 3690 | brcmf_bus_wowl_config(cfg->pub->bus_if, true); |
Hante Meuleman | 3021ad9 | 2016-01-05 11:05:45 +0100 | [diff] [blame] | 3691 | cfg->wowl.active = true; |
Hante Meuleman | 4eb3af7 | 2014-09-30 10:23:18 +0200 | [diff] [blame] | 3692 | } |
| 3693 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3694 | static s32 brcmf_cfg80211_suspend(struct wiphy *wiphy, |
Hante Meuleman | 4eb3af7 | 2014-09-30 10:23:18 +0200 | [diff] [blame] | 3695 | struct cfg80211_wowlan *wowl) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3696 | { |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 3697 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); |
| 3698 | struct net_device *ndev = cfg_to_ndev(cfg); |
Hante Meuleman | 4eb3af7 | 2014-09-30 10:23:18 +0200 | [diff] [blame] | 3699 | struct brcmf_if *ifp = netdev_priv(ndev); |
Arend van Spriel | 7d64107 | 2012-10-22 13:55:39 -0700 | [diff] [blame] | 3700 | struct brcmf_cfg80211_vif *vif; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3701 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 3702 | brcmf_dbg(TRACE, "Enter\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3703 | |
Hante Meuleman | 4eb3af7 | 2014-09-30 10:23:18 +0200 | [diff] [blame] | 3704 | /* if the primary net_device is not READY there is nothing |
Arend van Spriel | 7d64107 | 2012-10-22 13:55:39 -0700 | [diff] [blame] | 3705 | * we can do but pray resume goes smoothly. |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3706 | */ |
Hante Meuleman | 4eb3af7 | 2014-09-30 10:23:18 +0200 | [diff] [blame] | 3707 | if (!check_vif_up(ifp->vif)) |
Arend van Spriel | 7d64107 | 2012-10-22 13:55:39 -0700 | [diff] [blame] | 3708 | goto exit; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3709 | |
Hante Meuleman | 3021ad9 | 2016-01-05 11:05:45 +0100 | [diff] [blame] | 3710 | /* Stop scheduled scan */ |
| 3711 | if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_PNO)) |
| 3712 | brcmf_cfg80211_sched_scan_stop(wiphy, ndev); |
| 3713 | |
Arend van Spriel | 7d64107 | 2012-10-22 13:55:39 -0700 | [diff] [blame] | 3714 | /* end any scanning */ |
| 3715 | if (test_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status)) |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 3716 | brcmf_abort_scanning(cfg); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3717 | |
Hante Meuleman | 4eb3af7 | 2014-09-30 10:23:18 +0200 | [diff] [blame] | 3718 | if (wowl == NULL) { |
| 3719 | brcmf_bus_wowl_config(cfg->pub->bus_if, false); |
| 3720 | list_for_each_entry(vif, &cfg->vif_list, list) { |
| 3721 | if (!test_bit(BRCMF_VIF_STATUS_READY, &vif->sme_state)) |
| 3722 | continue; |
| 3723 | /* While going to suspend if associated with AP |
| 3724 | * disassociate from AP to save power while system is |
| 3725 | * in suspended state |
| 3726 | */ |
Arend van Spriel | 9b7a0dd | 2015-01-25 20:31:33 +0100 | [diff] [blame] | 3727 | brcmf_link_down(vif, WLAN_REASON_UNSPECIFIED); |
Hante Meuleman | 4eb3af7 | 2014-09-30 10:23:18 +0200 | [diff] [blame] | 3728 | /* Make sure WPA_Supplicant receives all the event |
| 3729 | * generated due to DISASSOC call to the fw to keep |
| 3730 | * the state fw and WPA_Supplicant state consistent |
| 3731 | */ |
| 3732 | brcmf_delay(500); |
| 3733 | } |
| 3734 | /* Configure MPC */ |
| 3735 | brcmf_set_mpc(ifp, 1); |
| 3736 | |
| 3737 | } else { |
| 3738 | /* Configure WOWL paramaters */ |
| 3739 | brcmf_configure_wowl(cfg, ifp, wowl); |
| 3740 | } |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3741 | |
Arend van Spriel | 7d64107 | 2012-10-22 13:55:39 -0700 | [diff] [blame] | 3742 | exit: |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 3743 | brcmf_dbg(TRACE, "Exit\n"); |
Arend van Spriel | 7d64107 | 2012-10-22 13:55:39 -0700 | [diff] [blame] | 3744 | /* clear any scanning activity */ |
| 3745 | cfg->scan_status = 0; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3746 | return 0; |
| 3747 | } |
| 3748 | |
| 3749 | static __used s32 |
Hante Meuleman | 6c404f3 | 2015-12-10 13:43:03 +0100 | [diff] [blame] | 3750 | 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] | 3751 | { |
Hante Meuleman | 6c404f3 | 2015-12-10 13:43:03 +0100 | [diff] [blame] | 3752 | struct brcmf_pmk_list_le *pmk_list; |
| 3753 | int i; |
| 3754 | u32 npmk; |
| 3755 | s32 err; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3756 | |
Hante Meuleman | 6c404f3 | 2015-12-10 13:43:03 +0100 | [diff] [blame] | 3757 | pmk_list = &cfg->pmk_list; |
| 3758 | npmk = le32_to_cpu(pmk_list->npmk); |
Arend van Spriel | 40c8e95 | 2011-10-12 20:51:20 +0200 | [diff] [blame] | 3759 | |
Hante Meuleman | 6c404f3 | 2015-12-10 13:43:03 +0100 | [diff] [blame] | 3760 | brcmf_dbg(CONN, "No of elements %d\n", npmk); |
| 3761 | for (i = 0; i < npmk; i++) |
| 3762 | 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] | 3763 | |
Hante Meuleman | 6c404f3 | 2015-12-10 13:43:03 +0100 | [diff] [blame] | 3764 | err = brcmf_fil_iovar_data_set(ifp, "pmkid_info", pmk_list, |
| 3765 | sizeof(*pmk_list)); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3766 | |
| 3767 | return err; |
| 3768 | } |
| 3769 | |
| 3770 | static s32 |
| 3771 | brcmf_cfg80211_set_pmksa(struct wiphy *wiphy, struct net_device *ndev, |
| 3772 | struct cfg80211_pmksa *pmksa) |
| 3773 | { |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 3774 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); |
Arend van Spriel | 0abb5f21 | 2012-10-22 13:55:32 -0700 | [diff] [blame] | 3775 | struct brcmf_if *ifp = netdev_priv(ndev); |
Hante Meuleman | 6c404f3 | 2015-12-10 13:43:03 +0100 | [diff] [blame] | 3776 | struct brcmf_pmksa *pmk = &cfg->pmk_list.pmk[0]; |
| 3777 | s32 err; |
| 3778 | u32 npmk, i; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3779 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 3780 | brcmf_dbg(TRACE, "Enter\n"); |
Arend van Spriel | ce81e31 | 2012-10-22 13:55:37 -0700 | [diff] [blame] | 3781 | if (!check_vif_up(ifp->vif)) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3782 | return -EIO; |
| 3783 | |
Hante Meuleman | 6c404f3 | 2015-12-10 13:43:03 +0100 | [diff] [blame] | 3784 | npmk = le32_to_cpu(cfg->pmk_list.npmk); |
| 3785 | for (i = 0; i < npmk; i++) |
| 3786 | if (!memcmp(pmksa->bssid, pmk[i].bssid, ETH_ALEN)) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3787 | break; |
Hante Meuleman | 6c404f3 | 2015-12-10 13:43:03 +0100 | [diff] [blame] | 3788 | if (i < BRCMF_MAXPMKID) { |
| 3789 | memcpy(pmk[i].bssid, pmksa->bssid, ETH_ALEN); |
| 3790 | memcpy(pmk[i].pmkid, pmksa->pmkid, WLAN_PMKID_LEN); |
| 3791 | if (i == npmk) { |
| 3792 | npmk++; |
| 3793 | cfg->pmk_list.npmk = cpu_to_le32(npmk); |
Arend van Spriel | 40c8e95 | 2011-10-12 20:51:20 +0200 | [diff] [blame] | 3794 | } |
Hante Meuleman | 6c404f3 | 2015-12-10 13:43:03 +0100 | [diff] [blame] | 3795 | } else { |
| 3796 | brcmf_err("Too many PMKSA entries cached %d\n", npmk); |
| 3797 | return -EINVAL; |
| 3798 | } |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3799 | |
Hante Meuleman | 6c404f3 | 2015-12-10 13:43:03 +0100 | [diff] [blame] | 3800 | brcmf_dbg(CONN, "set_pmksa - PMK bssid: %pM =\n", pmk[npmk].bssid); |
| 3801 | for (i = 0; i < WLAN_PMKID_LEN; i += 4) |
| 3802 | brcmf_dbg(CONN, "%02x %02x %02x %02x\n", pmk[npmk].pmkid[i], |
| 3803 | pmk[npmk].pmkid[i + 1], pmk[npmk].pmkid[i + 2], |
| 3804 | pmk[npmk].pmkid[i + 3]); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3805 | |
Hante Meuleman | 6c404f3 | 2015-12-10 13:43:03 +0100 | [diff] [blame] | 3806 | err = brcmf_update_pmklist(cfg, ifp); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3807 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 3808 | brcmf_dbg(TRACE, "Exit\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3809 | return err; |
| 3810 | } |
| 3811 | |
| 3812 | static s32 |
| 3813 | brcmf_cfg80211_del_pmksa(struct wiphy *wiphy, struct net_device *ndev, |
Hante Meuleman | 6c404f3 | 2015-12-10 13:43:03 +0100 | [diff] [blame] | 3814 | struct cfg80211_pmksa *pmksa) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3815 | { |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 3816 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); |
Arend van Spriel | 0abb5f21 | 2012-10-22 13:55:32 -0700 | [diff] [blame] | 3817 | struct brcmf_if *ifp = netdev_priv(ndev); |
Hante Meuleman | 6c404f3 | 2015-12-10 13:43:03 +0100 | [diff] [blame] | 3818 | struct brcmf_pmksa *pmk = &cfg->pmk_list.pmk[0]; |
| 3819 | s32 err; |
| 3820 | u32 npmk, i; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3821 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 3822 | brcmf_dbg(TRACE, "Enter\n"); |
Arend van Spriel | ce81e31 | 2012-10-22 13:55:37 -0700 | [diff] [blame] | 3823 | if (!check_vif_up(ifp->vif)) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3824 | return -EIO; |
| 3825 | |
Hante Meuleman | 6c404f3 | 2015-12-10 13:43:03 +0100 | [diff] [blame] | 3826 | brcmf_dbg(CONN, "del_pmksa - PMK bssid = %pM\n", &pmksa->bssid); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3827 | |
Hante Meuleman | 6c404f3 | 2015-12-10 13:43:03 +0100 | [diff] [blame] | 3828 | npmk = le32_to_cpu(cfg->pmk_list.npmk); |
| 3829 | for (i = 0; i < npmk; i++) |
| 3830 | if (!memcmp(&pmksa->bssid, &pmk[i].bssid, ETH_ALEN)) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3831 | break; |
| 3832 | |
Hante Meuleman | 6c404f3 | 2015-12-10 13:43:03 +0100 | [diff] [blame] | 3833 | if ((npmk > 0) && (i < npmk)) { |
| 3834 | for (; i < (npmk - 1); i++) { |
| 3835 | memcpy(&pmk[i].bssid, &pmk[i + 1].bssid, ETH_ALEN); |
| 3836 | memcpy(&pmk[i].pmkid, &pmk[i + 1].pmkid, |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3837 | WLAN_PMKID_LEN); |
| 3838 | } |
Hante Meuleman | 6c404f3 | 2015-12-10 13:43:03 +0100 | [diff] [blame] | 3839 | memset(&pmk[i], 0, sizeof(*pmk)); |
| 3840 | cfg->pmk_list.npmk = cpu_to_le32(npmk - 1); |
| 3841 | } else { |
| 3842 | brcmf_err("Cache entry not found\n"); |
| 3843 | return -EINVAL; |
| 3844 | } |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3845 | |
Hante Meuleman | 6c404f3 | 2015-12-10 13:43:03 +0100 | [diff] [blame] | 3846 | err = brcmf_update_pmklist(cfg, ifp); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3847 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 3848 | brcmf_dbg(TRACE, "Exit\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3849 | return err; |
| 3850 | |
| 3851 | } |
| 3852 | |
| 3853 | static s32 |
| 3854 | brcmf_cfg80211_flush_pmksa(struct wiphy *wiphy, struct net_device *ndev) |
| 3855 | { |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 3856 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); |
Arend van Spriel | 0abb5f21 | 2012-10-22 13:55:32 -0700 | [diff] [blame] | 3857 | struct brcmf_if *ifp = netdev_priv(ndev); |
Hante Meuleman | 6c404f3 | 2015-12-10 13:43:03 +0100 | [diff] [blame] | 3858 | s32 err; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3859 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 3860 | brcmf_dbg(TRACE, "Enter\n"); |
Arend van Spriel | ce81e31 | 2012-10-22 13:55:37 -0700 | [diff] [blame] | 3861 | if (!check_vif_up(ifp->vif)) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3862 | return -EIO; |
| 3863 | |
Hante Meuleman | 6c404f3 | 2015-12-10 13:43:03 +0100 | [diff] [blame] | 3864 | memset(&cfg->pmk_list, 0, sizeof(cfg->pmk_list)); |
| 3865 | err = brcmf_update_pmklist(cfg, ifp); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3866 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 3867 | brcmf_dbg(TRACE, "Exit\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3868 | return err; |
| 3869 | |
| 3870 | } |
| 3871 | |
Hante Meuleman | 1f17011 | 2013-02-06 18:40:38 +0100 | [diff] [blame] | 3872 | static s32 brcmf_configure_opensecurity(struct brcmf_if *ifp) |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3873 | { |
| 3874 | s32 err; |
| 3875 | |
| 3876 | /* set auth */ |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 3877 | err = brcmf_fil_bsscfg_int_set(ifp, "auth", 0); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3878 | if (err < 0) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 3879 | brcmf_err("auth error %d\n", err); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3880 | return err; |
| 3881 | } |
| 3882 | /* set wsec */ |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 3883 | err = brcmf_fil_bsscfg_int_set(ifp, "wsec", 0); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3884 | if (err < 0) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 3885 | brcmf_err("wsec error %d\n", err); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3886 | return err; |
| 3887 | } |
| 3888 | /* set upper-layer auth */ |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 3889 | err = brcmf_fil_bsscfg_int_set(ifp, "wpa_auth", WPA_AUTH_NONE); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3890 | if (err < 0) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 3891 | brcmf_err("wpa_auth error %d\n", err); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3892 | return err; |
| 3893 | } |
| 3894 | |
| 3895 | return 0; |
| 3896 | } |
| 3897 | |
| 3898 | static bool brcmf_valid_wpa_oui(u8 *oui, bool is_rsn_ie) |
| 3899 | { |
| 3900 | if (is_rsn_ie) |
| 3901 | return (memcmp(oui, RSN_OUI, TLV_OUI_LEN) == 0); |
| 3902 | |
| 3903 | return (memcmp(oui, WPA_OUI, TLV_OUI_LEN) == 0); |
| 3904 | } |
| 3905 | |
| 3906 | static s32 |
Hante Meuleman | a44aa40 | 2014-12-03 21:05:33 +0100 | [diff] [blame] | 3907 | brcmf_configure_wpaie(struct brcmf_if *ifp, |
Johannes Berg | 4b5800f | 2014-01-15 14:55:59 +0100 | [diff] [blame] | 3908 | const struct brcmf_vs_tlv *wpa_ie, |
| 3909 | bool is_rsn_ie) |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3910 | { |
| 3911 | u32 auth = 0; /* d11 open authentication */ |
| 3912 | u16 count; |
| 3913 | s32 err = 0; |
Hante Meuleman | 240d61a | 2016-02-17 11:27:10 +0100 | [diff] [blame] | 3914 | s32 len; |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3915 | u32 i; |
| 3916 | u32 wsec; |
| 3917 | u32 pval = 0; |
| 3918 | u32 gval = 0; |
| 3919 | u32 wpa_auth = 0; |
| 3920 | u32 offset; |
| 3921 | u8 *data; |
| 3922 | u16 rsn_cap; |
| 3923 | u32 wme_bss_disable; |
Hante Meuleman | 240d61a | 2016-02-17 11:27:10 +0100 | [diff] [blame] | 3924 | u32 mfp; |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3925 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 3926 | brcmf_dbg(TRACE, "Enter\n"); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3927 | if (wpa_ie == NULL) |
| 3928 | goto exit; |
| 3929 | |
| 3930 | len = wpa_ie->len + TLV_HDR_LEN; |
| 3931 | data = (u8 *)wpa_ie; |
Hante Meuleman | 619c5a9 | 2013-01-02 15:12:39 +0100 | [diff] [blame] | 3932 | offset = TLV_HDR_LEN; |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3933 | if (!is_rsn_ie) |
| 3934 | offset += VS_IE_FIXED_HDR_LEN; |
Hante Meuleman | 619c5a9 | 2013-01-02 15:12:39 +0100 | [diff] [blame] | 3935 | else |
| 3936 | offset += WPA_IE_VERSION_LEN; |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3937 | |
| 3938 | /* check for multicast cipher suite */ |
| 3939 | if (offset + WPA_IE_MIN_OUI_LEN > len) { |
| 3940 | err = -EINVAL; |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 3941 | brcmf_err("no multicast cipher suite\n"); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3942 | goto exit; |
| 3943 | } |
| 3944 | |
| 3945 | if (!brcmf_valid_wpa_oui(&data[offset], is_rsn_ie)) { |
| 3946 | err = -EINVAL; |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 3947 | brcmf_err("ivalid OUI\n"); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3948 | goto exit; |
| 3949 | } |
| 3950 | offset += TLV_OUI_LEN; |
| 3951 | |
| 3952 | /* pick up multicast cipher */ |
| 3953 | switch (data[offset]) { |
| 3954 | case WPA_CIPHER_NONE: |
| 3955 | gval = 0; |
| 3956 | break; |
| 3957 | case WPA_CIPHER_WEP_40: |
| 3958 | case WPA_CIPHER_WEP_104: |
| 3959 | gval = WEP_ENABLED; |
| 3960 | break; |
| 3961 | case WPA_CIPHER_TKIP: |
| 3962 | gval = TKIP_ENABLED; |
| 3963 | break; |
| 3964 | case WPA_CIPHER_AES_CCM: |
| 3965 | gval = AES_ENABLED; |
| 3966 | break; |
| 3967 | default: |
| 3968 | err = -EINVAL; |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 3969 | brcmf_err("Invalid multi cast cipher info\n"); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3970 | goto exit; |
| 3971 | } |
| 3972 | |
| 3973 | offset++; |
| 3974 | /* walk thru unicast cipher list and pick up what we recognize */ |
| 3975 | count = data[offset] + (data[offset + 1] << 8); |
| 3976 | offset += WPA_IE_SUITE_COUNT_LEN; |
| 3977 | /* Check for unicast suite(s) */ |
| 3978 | if (offset + (WPA_IE_MIN_OUI_LEN * count) > len) { |
| 3979 | err = -EINVAL; |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 3980 | brcmf_err("no unicast cipher suite\n"); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3981 | goto exit; |
| 3982 | } |
| 3983 | for (i = 0; i < count; i++) { |
| 3984 | if (!brcmf_valid_wpa_oui(&data[offset], is_rsn_ie)) { |
| 3985 | err = -EINVAL; |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 3986 | brcmf_err("ivalid OUI\n"); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3987 | goto exit; |
| 3988 | } |
| 3989 | offset += TLV_OUI_LEN; |
| 3990 | switch (data[offset]) { |
| 3991 | case WPA_CIPHER_NONE: |
| 3992 | break; |
| 3993 | case WPA_CIPHER_WEP_40: |
| 3994 | case WPA_CIPHER_WEP_104: |
| 3995 | pval |= WEP_ENABLED; |
| 3996 | break; |
| 3997 | case WPA_CIPHER_TKIP: |
| 3998 | pval |= TKIP_ENABLED; |
| 3999 | break; |
| 4000 | case WPA_CIPHER_AES_CCM: |
| 4001 | pval |= AES_ENABLED; |
| 4002 | break; |
| 4003 | default: |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 4004 | brcmf_err("Ivalid unicast security info\n"); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4005 | } |
| 4006 | offset++; |
| 4007 | } |
| 4008 | /* walk thru auth management suite list and pick up what we recognize */ |
| 4009 | count = data[offset] + (data[offset + 1] << 8); |
| 4010 | offset += WPA_IE_SUITE_COUNT_LEN; |
| 4011 | /* Check for auth key management suite(s) */ |
| 4012 | if (offset + (WPA_IE_MIN_OUI_LEN * count) > len) { |
| 4013 | err = -EINVAL; |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 4014 | brcmf_err("no auth key mgmt suite\n"); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4015 | goto exit; |
| 4016 | } |
| 4017 | for (i = 0; i < count; i++) { |
| 4018 | if (!brcmf_valid_wpa_oui(&data[offset], is_rsn_ie)) { |
| 4019 | err = -EINVAL; |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 4020 | brcmf_err("ivalid OUI\n"); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4021 | goto exit; |
| 4022 | } |
| 4023 | offset += TLV_OUI_LEN; |
| 4024 | switch (data[offset]) { |
| 4025 | case RSN_AKM_NONE: |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 4026 | brcmf_dbg(TRACE, "RSN_AKM_NONE\n"); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4027 | wpa_auth |= WPA_AUTH_NONE; |
| 4028 | break; |
| 4029 | case RSN_AKM_UNSPECIFIED: |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 4030 | brcmf_dbg(TRACE, "RSN_AKM_UNSPECIFIED\n"); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4031 | is_rsn_ie ? (wpa_auth |= WPA2_AUTH_UNSPECIFIED) : |
| 4032 | (wpa_auth |= WPA_AUTH_UNSPECIFIED); |
| 4033 | break; |
| 4034 | case RSN_AKM_PSK: |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 4035 | brcmf_dbg(TRACE, "RSN_AKM_PSK\n"); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4036 | is_rsn_ie ? (wpa_auth |= WPA2_AUTH_PSK) : |
| 4037 | (wpa_auth |= WPA_AUTH_PSK); |
| 4038 | break; |
Hante Meuleman | 240d61a | 2016-02-17 11:27:10 +0100 | [diff] [blame] | 4039 | case RSN_AKM_SHA256_PSK: |
| 4040 | brcmf_dbg(TRACE, "RSN_AKM_MFP_PSK\n"); |
| 4041 | wpa_auth |= WPA2_AUTH_PSK_SHA256; |
| 4042 | break; |
| 4043 | case RSN_AKM_SHA256_1X: |
| 4044 | brcmf_dbg(TRACE, "RSN_AKM_MFP_1X\n"); |
| 4045 | wpa_auth |= WPA2_AUTH_1X_SHA256; |
| 4046 | break; |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4047 | default: |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 4048 | brcmf_err("Ivalid key mgmt info\n"); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4049 | } |
| 4050 | offset++; |
| 4051 | } |
| 4052 | |
Hante Meuleman | 240d61a | 2016-02-17 11:27:10 +0100 | [diff] [blame] | 4053 | mfp = BRCMF_MFP_NONE; |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4054 | if (is_rsn_ie) { |
| 4055 | wme_bss_disable = 1; |
| 4056 | if ((offset + RSN_CAP_LEN) <= len) { |
| 4057 | rsn_cap = data[offset] + (data[offset + 1] << 8); |
| 4058 | if (rsn_cap & RSN_CAP_PTK_REPLAY_CNTR_MASK) |
| 4059 | wme_bss_disable = 0; |
Hante Meuleman | 240d61a | 2016-02-17 11:27:10 +0100 | [diff] [blame] | 4060 | if (rsn_cap & RSN_CAP_MFPR_MASK) { |
| 4061 | brcmf_dbg(TRACE, "MFP Required\n"); |
| 4062 | mfp = BRCMF_MFP_REQUIRED; |
| 4063 | /* Firmware only supports mfp required in |
| 4064 | * combination with WPA2_AUTH_PSK_SHA256 or |
| 4065 | * WPA2_AUTH_1X_SHA256. |
| 4066 | */ |
| 4067 | if (!(wpa_auth & (WPA2_AUTH_PSK_SHA256 | |
| 4068 | WPA2_AUTH_1X_SHA256))) { |
| 4069 | err = -EINVAL; |
| 4070 | goto exit; |
| 4071 | } |
| 4072 | /* Firmware has requirement that WPA2_AUTH_PSK/ |
| 4073 | * WPA2_AUTH_UNSPECIFIED be set, if SHA256 OUI |
| 4074 | * is to be included in the rsn ie. |
| 4075 | */ |
| 4076 | if (wpa_auth & WPA2_AUTH_PSK_SHA256) |
| 4077 | wpa_auth |= WPA2_AUTH_PSK; |
| 4078 | else if (wpa_auth & WPA2_AUTH_1X_SHA256) |
| 4079 | wpa_auth |= WPA2_AUTH_UNSPECIFIED; |
| 4080 | } else if (rsn_cap & RSN_CAP_MFPC_MASK) { |
| 4081 | brcmf_dbg(TRACE, "MFP Capable\n"); |
| 4082 | mfp = BRCMF_MFP_CAPABLE; |
| 4083 | } |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4084 | } |
Hante Meuleman | 240d61a | 2016-02-17 11:27:10 +0100 | [diff] [blame] | 4085 | offset += RSN_CAP_LEN; |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4086 | /* set wme_bss_disable to sync RSN Capabilities */ |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 4087 | err = brcmf_fil_bsscfg_int_set(ifp, "wme_bss_disable", |
Hante Meuleman | 81f5dcb | 2012-10-22 10:36:14 -0700 | [diff] [blame] | 4088 | wme_bss_disable); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4089 | if (err < 0) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 4090 | brcmf_err("wme_bss_disable error %d\n", err); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4091 | goto exit; |
| 4092 | } |
Hante Meuleman | 240d61a | 2016-02-17 11:27:10 +0100 | [diff] [blame] | 4093 | |
| 4094 | /* Skip PMKID cnt as it is know to be 0 for AP. */ |
| 4095 | offset += RSN_PMKID_COUNT_LEN; |
| 4096 | |
| 4097 | /* See if there is BIP wpa suite left for MFP */ |
| 4098 | if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_MFP) && |
| 4099 | ((offset + WPA_IE_MIN_OUI_LEN) <= len)) { |
| 4100 | err = brcmf_fil_bsscfg_data_set(ifp, "bip", |
| 4101 | &data[offset], |
| 4102 | WPA_IE_MIN_OUI_LEN); |
| 4103 | if (err < 0) { |
| 4104 | brcmf_err("bip error %d\n", err); |
| 4105 | goto exit; |
| 4106 | } |
| 4107 | } |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4108 | } |
| 4109 | /* FOR WPS , set SES_OW_ENABLED */ |
| 4110 | wsec = (pval | gval | SES_OW_ENABLED); |
| 4111 | |
| 4112 | /* set auth */ |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 4113 | err = brcmf_fil_bsscfg_int_set(ifp, "auth", auth); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4114 | if (err < 0) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 4115 | brcmf_err("auth error %d\n", err); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4116 | goto exit; |
| 4117 | } |
| 4118 | /* set wsec */ |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 4119 | err = brcmf_fil_bsscfg_int_set(ifp, "wsec", wsec); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4120 | if (err < 0) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 4121 | brcmf_err("wsec error %d\n", err); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4122 | goto exit; |
| 4123 | } |
Hante Meuleman | 240d61a | 2016-02-17 11:27:10 +0100 | [diff] [blame] | 4124 | /* Configure MFP, this needs to go after wsec otherwise the wsec command |
| 4125 | * will overwrite the values set by MFP |
| 4126 | */ |
| 4127 | if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_MFP)) { |
| 4128 | err = brcmf_fil_bsscfg_int_set(ifp, "mfp", mfp); |
| 4129 | if (err < 0) { |
| 4130 | brcmf_err("mfp error %d\n", err); |
| 4131 | goto exit; |
| 4132 | } |
| 4133 | } |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4134 | /* set upper-layer auth */ |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 4135 | err = brcmf_fil_bsscfg_int_set(ifp, "wpa_auth", wpa_auth); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4136 | if (err < 0) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 4137 | brcmf_err("wpa_auth error %d\n", err); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4138 | goto exit; |
| 4139 | } |
| 4140 | |
| 4141 | exit: |
| 4142 | return err; |
| 4143 | } |
| 4144 | |
| 4145 | static s32 |
Arend van Spriel | 3082b9b | 2012-11-05 16:22:12 -0800 | [diff] [blame] | 4146 | 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] | 4147 | struct parsed_vndr_ies *vndr_ies) |
| 4148 | { |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4149 | struct brcmf_vs_tlv *vndrie; |
| 4150 | struct brcmf_tlv *ie; |
| 4151 | struct parsed_vndr_ie_info *parsed_info; |
| 4152 | s32 remaining_len; |
| 4153 | |
| 4154 | remaining_len = (s32)vndr_ie_len; |
| 4155 | memset(vndr_ies, 0, sizeof(*vndr_ies)); |
| 4156 | |
| 4157 | ie = (struct brcmf_tlv *)vndr_ie_buf; |
| 4158 | while (ie) { |
| 4159 | if (ie->id != WLAN_EID_VENDOR_SPECIFIC) |
| 4160 | goto next; |
| 4161 | vndrie = (struct brcmf_vs_tlv *)ie; |
| 4162 | /* len should be bigger than OUI length + one */ |
| 4163 | 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] | 4164 | brcmf_err("invalid vndr ie. length is too small %d\n", |
| 4165 | vndrie->len); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4166 | goto next; |
| 4167 | } |
| 4168 | /* if wpa or wme ie, do not add ie */ |
| 4169 | if (!memcmp(vndrie->oui, (u8 *)WPA_OUI, TLV_OUI_LEN) && |
| 4170 | ((vndrie->oui_type == WPA_OUI_TYPE) || |
| 4171 | (vndrie->oui_type == WME_OUI_TYPE))) { |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 4172 | brcmf_dbg(TRACE, "Found WPA/WME oui. Do not add it\n"); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4173 | goto next; |
| 4174 | } |
| 4175 | |
| 4176 | parsed_info = &vndr_ies->ie_info[vndr_ies->count]; |
| 4177 | |
| 4178 | /* save vndr ie information */ |
| 4179 | parsed_info->ie_ptr = (char *)vndrie; |
| 4180 | parsed_info->ie_len = vndrie->len + TLV_HDR_LEN; |
| 4181 | memcpy(&parsed_info->vndrie, vndrie, sizeof(*vndrie)); |
| 4182 | |
| 4183 | vndr_ies->count++; |
| 4184 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 4185 | brcmf_dbg(TRACE, "** OUI %02x %02x %02x, type 0x%02x\n", |
| 4186 | parsed_info->vndrie.oui[0], |
| 4187 | parsed_info->vndrie.oui[1], |
| 4188 | parsed_info->vndrie.oui[2], |
| 4189 | parsed_info->vndrie.oui_type); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4190 | |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 4191 | if (vndr_ies->count >= VNDR_IE_PARSE_LIMIT) |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4192 | break; |
| 4193 | next: |
Hante Meuleman | b41fc3d | 2012-11-28 21:44:13 +0100 | [diff] [blame] | 4194 | remaining_len -= (ie->len + TLV_HDR_LEN); |
| 4195 | if (remaining_len <= TLV_HDR_LEN) |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4196 | ie = NULL; |
| 4197 | else |
Hante Meuleman | b41fc3d | 2012-11-28 21:44:13 +0100 | [diff] [blame] | 4198 | ie = (struct brcmf_tlv *)(((u8 *)ie) + ie->len + |
| 4199 | TLV_HDR_LEN); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4200 | } |
Peter Senna Tschudin | 12f3237 | 2014-05-31 10:14:06 -0300 | [diff] [blame] | 4201 | return 0; |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4202 | } |
| 4203 | |
| 4204 | static u32 |
| 4205 | brcmf_vndr_ie(u8 *iebuf, s32 pktflag, u8 *ie_ptr, u32 ie_len, s8 *add_del_cmd) |
| 4206 | { |
| 4207 | |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4208 | strncpy(iebuf, add_del_cmd, VNDR_IE_CMD_LEN - 1); |
| 4209 | iebuf[VNDR_IE_CMD_LEN - 1] = '\0'; |
| 4210 | |
Vaishali Thakkar | 362126c | 2015-01-16 21:36:14 +0530 | [diff] [blame] | 4211 | put_unaligned_le32(1, &iebuf[VNDR_IE_COUNT_OFFSET]); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4212 | |
Vaishali Thakkar | 362126c | 2015-01-16 21:36:14 +0530 | [diff] [blame] | 4213 | put_unaligned_le32(pktflag, &iebuf[VNDR_IE_PKTFLAG_OFFSET]); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4214 | |
| 4215 | memcpy(&iebuf[VNDR_IE_VSIE_OFFSET], ie_ptr, ie_len); |
| 4216 | |
| 4217 | return ie_len + VNDR_IE_HDR_SIZE; |
| 4218 | } |
| 4219 | |
Arend van Spriel | 1332e26 | 2012-11-05 16:22:18 -0800 | [diff] [blame] | 4220 | s32 brcmf_vif_set_mgmt_ie(struct brcmf_cfg80211_vif *vif, s32 pktflag, |
| 4221 | const u8 *vndr_ie_buf, u32 vndr_ie_len) |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4222 | { |
Arend van Spriel | 1332e26 | 2012-11-05 16:22:18 -0800 | [diff] [blame] | 4223 | struct brcmf_if *ifp; |
| 4224 | struct vif_saved_ie *saved_ie; |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4225 | s32 err = 0; |
| 4226 | u8 *iovar_ie_buf; |
| 4227 | u8 *curr_ie_buf; |
| 4228 | u8 *mgmt_ie_buf = NULL; |
Dan Carpenter | 3e4f319 | 2012-10-10 11:13:12 -0700 | [diff] [blame] | 4229 | int mgmt_ie_buf_len; |
Dan Carpenter | 81118d1 | 2012-10-10 11:13:07 -0700 | [diff] [blame] | 4230 | u32 *mgmt_ie_len; |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4231 | u32 del_add_ie_buf_len = 0; |
| 4232 | u32 total_ie_buf_len = 0; |
| 4233 | u32 parsed_ie_buf_len = 0; |
| 4234 | struct parsed_vndr_ies old_vndr_ies; |
| 4235 | struct parsed_vndr_ies new_vndr_ies; |
| 4236 | struct parsed_vndr_ie_info *vndrie_info; |
| 4237 | s32 i; |
| 4238 | u8 *ptr; |
Dan Carpenter | 3e4f319 | 2012-10-10 11:13:12 -0700 | [diff] [blame] | 4239 | int remained_buf_len; |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4240 | |
Arend van Spriel | 1332e26 | 2012-11-05 16:22:18 -0800 | [diff] [blame] | 4241 | if (!vif) |
| 4242 | return -ENODEV; |
| 4243 | ifp = vif->ifp; |
| 4244 | saved_ie = &vif->saved_ie; |
| 4245 | |
Hante Meuleman | 37a869e | 2015-10-29 20:33:17 +0100 | [diff] [blame] | 4246 | brcmf_dbg(TRACE, "bsscfgidx %d, pktflag : 0x%02X\n", ifp->bsscfgidx, |
| 4247 | pktflag); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4248 | iovar_ie_buf = kzalloc(WL_EXTRA_BUF_MAX, GFP_KERNEL); |
| 4249 | if (!iovar_ie_buf) |
| 4250 | return -ENOMEM; |
| 4251 | curr_ie_buf = iovar_ie_buf; |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 4252 | switch (pktflag) { |
| 4253 | case BRCMF_VNDR_IE_PRBREQ_FLAG: |
| 4254 | mgmt_ie_buf = saved_ie->probe_req_ie; |
| 4255 | mgmt_ie_len = &saved_ie->probe_req_ie_len; |
| 4256 | mgmt_ie_buf_len = sizeof(saved_ie->probe_req_ie); |
| 4257 | break; |
| 4258 | case BRCMF_VNDR_IE_PRBRSP_FLAG: |
| 4259 | mgmt_ie_buf = saved_ie->probe_res_ie; |
| 4260 | mgmt_ie_len = &saved_ie->probe_res_ie_len; |
| 4261 | mgmt_ie_buf_len = sizeof(saved_ie->probe_res_ie); |
| 4262 | break; |
| 4263 | case BRCMF_VNDR_IE_BEACON_FLAG: |
| 4264 | mgmt_ie_buf = saved_ie->beacon_ie; |
| 4265 | mgmt_ie_len = &saved_ie->beacon_ie_len; |
| 4266 | mgmt_ie_buf_len = sizeof(saved_ie->beacon_ie); |
| 4267 | break; |
| 4268 | case BRCMF_VNDR_IE_ASSOCREQ_FLAG: |
| 4269 | mgmt_ie_buf = saved_ie->assoc_req_ie; |
| 4270 | mgmt_ie_len = &saved_ie->assoc_req_ie_len; |
| 4271 | mgmt_ie_buf_len = sizeof(saved_ie->assoc_req_ie); |
| 4272 | break; |
| 4273 | default: |
| 4274 | err = -EPERM; |
| 4275 | brcmf_err("not suitable type\n"); |
| 4276 | goto exit; |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4277 | } |
| 4278 | |
| 4279 | if (vndr_ie_len > mgmt_ie_buf_len) { |
| 4280 | err = -ENOMEM; |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 4281 | brcmf_err("extra IE size too big\n"); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4282 | goto exit; |
| 4283 | } |
| 4284 | |
| 4285 | /* parse and save new vndr_ie in curr_ie_buff before comparing it */ |
| 4286 | if (vndr_ie_buf && vndr_ie_len && curr_ie_buf) { |
| 4287 | ptr = curr_ie_buf; |
| 4288 | brcmf_parse_vndr_ies(vndr_ie_buf, vndr_ie_len, &new_vndr_ies); |
| 4289 | for (i = 0; i < new_vndr_ies.count; i++) { |
| 4290 | vndrie_info = &new_vndr_ies.ie_info[i]; |
| 4291 | memcpy(ptr + parsed_ie_buf_len, vndrie_info->ie_ptr, |
| 4292 | vndrie_info->ie_len); |
| 4293 | parsed_ie_buf_len += vndrie_info->ie_len; |
| 4294 | } |
| 4295 | } |
| 4296 | |
Hante Meuleman | b41fc3d | 2012-11-28 21:44:13 +0100 | [diff] [blame] | 4297 | if (mgmt_ie_buf && *mgmt_ie_len) { |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4298 | if (parsed_ie_buf_len && (parsed_ie_buf_len == *mgmt_ie_len) && |
| 4299 | (memcmp(mgmt_ie_buf, curr_ie_buf, |
| 4300 | parsed_ie_buf_len) == 0)) { |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 4301 | brcmf_dbg(TRACE, "Previous mgmt IE equals to current IE\n"); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4302 | goto exit; |
| 4303 | } |
| 4304 | |
| 4305 | /* parse old vndr_ie */ |
| 4306 | brcmf_parse_vndr_ies(mgmt_ie_buf, *mgmt_ie_len, &old_vndr_ies); |
| 4307 | |
| 4308 | /* make a command to delete old ie */ |
| 4309 | for (i = 0; i < old_vndr_ies.count; i++) { |
| 4310 | vndrie_info = &old_vndr_ies.ie_info[i]; |
| 4311 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 4312 | brcmf_dbg(TRACE, "DEL ID : %d, Len: %d , OUI:%02x:%02x:%02x\n", |
| 4313 | vndrie_info->vndrie.id, |
| 4314 | vndrie_info->vndrie.len, |
| 4315 | vndrie_info->vndrie.oui[0], |
| 4316 | vndrie_info->vndrie.oui[1], |
| 4317 | vndrie_info->vndrie.oui[2]); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4318 | |
| 4319 | del_add_ie_buf_len = brcmf_vndr_ie(curr_ie_buf, pktflag, |
| 4320 | vndrie_info->ie_ptr, |
| 4321 | vndrie_info->ie_len, |
| 4322 | "del"); |
| 4323 | curr_ie_buf += del_add_ie_buf_len; |
| 4324 | total_ie_buf_len += del_add_ie_buf_len; |
| 4325 | } |
| 4326 | } |
| 4327 | |
| 4328 | *mgmt_ie_len = 0; |
| 4329 | /* Add if there is any extra IE */ |
| 4330 | if (mgmt_ie_buf && parsed_ie_buf_len) { |
| 4331 | ptr = mgmt_ie_buf; |
| 4332 | |
| 4333 | remained_buf_len = mgmt_ie_buf_len; |
| 4334 | |
| 4335 | /* make a command to add new ie */ |
| 4336 | for (i = 0; i < new_vndr_ies.count; i++) { |
| 4337 | vndrie_info = &new_vndr_ies.ie_info[i]; |
| 4338 | |
Hante Meuleman | b41fc3d | 2012-11-28 21:44:13 +0100 | [diff] [blame] | 4339 | /* verify remained buf size before copy data */ |
| 4340 | if (remained_buf_len < (vndrie_info->vndrie.len + |
| 4341 | VNDR_IE_VSIE_OFFSET)) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 4342 | brcmf_err("no space in mgmt_ie_buf: len left %d", |
| 4343 | remained_buf_len); |
Hante Meuleman | b41fc3d | 2012-11-28 21:44:13 +0100 | [diff] [blame] | 4344 | break; |
| 4345 | } |
| 4346 | remained_buf_len -= (vndrie_info->ie_len + |
| 4347 | VNDR_IE_VSIE_OFFSET); |
| 4348 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 4349 | brcmf_dbg(TRACE, "ADDED ID : %d, Len: %d, OUI:%02x:%02x:%02x\n", |
| 4350 | vndrie_info->vndrie.id, |
| 4351 | vndrie_info->vndrie.len, |
| 4352 | vndrie_info->vndrie.oui[0], |
| 4353 | vndrie_info->vndrie.oui[1], |
| 4354 | vndrie_info->vndrie.oui[2]); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4355 | |
| 4356 | del_add_ie_buf_len = brcmf_vndr_ie(curr_ie_buf, pktflag, |
| 4357 | vndrie_info->ie_ptr, |
| 4358 | vndrie_info->ie_len, |
| 4359 | "add"); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4360 | |
| 4361 | /* save the parsed IE in wl struct */ |
| 4362 | memcpy(ptr + (*mgmt_ie_len), vndrie_info->ie_ptr, |
| 4363 | vndrie_info->ie_len); |
| 4364 | *mgmt_ie_len += vndrie_info->ie_len; |
| 4365 | |
| 4366 | curr_ie_buf += del_add_ie_buf_len; |
| 4367 | total_ie_buf_len += del_add_ie_buf_len; |
| 4368 | } |
| 4369 | } |
| 4370 | if (total_ie_buf_len) { |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 4371 | err = brcmf_fil_bsscfg_data_set(ifp, "vndr_ie", iovar_ie_buf, |
Hante Meuleman | 81f5dcb | 2012-10-22 10:36:14 -0700 | [diff] [blame] | 4372 | total_ie_buf_len); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4373 | if (err) |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 4374 | brcmf_err("vndr ie set error : %d\n", err); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4375 | } |
| 4376 | |
| 4377 | exit: |
| 4378 | kfree(iovar_ie_buf); |
| 4379 | return err; |
| 4380 | } |
| 4381 | |
Arend van Spriel | 5f4f9f1 | 2013-02-08 15:53:41 +0100 | [diff] [blame] | 4382 | s32 brcmf_vif_clear_mgmt_ies(struct brcmf_cfg80211_vif *vif) |
| 4383 | { |
| 4384 | s32 pktflags[] = { |
| 4385 | BRCMF_VNDR_IE_PRBREQ_FLAG, |
| 4386 | BRCMF_VNDR_IE_PRBRSP_FLAG, |
| 4387 | BRCMF_VNDR_IE_BEACON_FLAG |
| 4388 | }; |
| 4389 | int i; |
| 4390 | |
| 4391 | for (i = 0; i < ARRAY_SIZE(pktflags); i++) |
| 4392 | brcmf_vif_set_mgmt_ie(vif, pktflags[i], NULL, 0); |
| 4393 | |
| 4394 | memset(&vif->saved_ie, 0, sizeof(vif->saved_ie)); |
| 4395 | return 0; |
| 4396 | } |
| 4397 | |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4398 | static s32 |
Hante Meuleman | a0f0795 | 2013-02-08 15:53:47 +0100 | [diff] [blame] | 4399 | brcmf_config_ap_mgmt_ie(struct brcmf_cfg80211_vif *vif, |
| 4400 | struct cfg80211_beacon_data *beacon) |
| 4401 | { |
| 4402 | s32 err; |
| 4403 | |
| 4404 | /* Set Beacon IEs to FW */ |
| 4405 | err = brcmf_vif_set_mgmt_ie(vif, BRCMF_VNDR_IE_BEACON_FLAG, |
| 4406 | beacon->tail, beacon->tail_len); |
| 4407 | if (err) { |
| 4408 | brcmf_err("Set Beacon IE Failed\n"); |
| 4409 | return err; |
| 4410 | } |
| 4411 | brcmf_dbg(TRACE, "Applied Vndr IEs for Beacon\n"); |
| 4412 | |
| 4413 | /* Set Probe Response IEs to FW */ |
| 4414 | err = brcmf_vif_set_mgmt_ie(vif, BRCMF_VNDR_IE_PRBRSP_FLAG, |
| 4415 | beacon->proberesp_ies, |
| 4416 | beacon->proberesp_ies_len); |
| 4417 | if (err) |
| 4418 | brcmf_err("Set Probe Resp IE Failed\n"); |
| 4419 | else |
| 4420 | brcmf_dbg(TRACE, "Applied Vndr IEs for Probe Resp\n"); |
| 4421 | |
| 4422 | return err; |
| 4423 | } |
| 4424 | |
| 4425 | static s32 |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4426 | brcmf_cfg80211_start_ap(struct wiphy *wiphy, struct net_device *ndev, |
| 4427 | struct cfg80211_ap_settings *settings) |
| 4428 | { |
| 4429 | s32 ie_offset; |
Hante Meuleman | 1c9d30c | 2013-05-27 21:09:58 +0200 | [diff] [blame] | 4430 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 4431 | struct brcmf_if *ifp = netdev_priv(ndev); |
Johannes Berg | 4b5800f | 2014-01-15 14:55:59 +0100 | [diff] [blame] | 4432 | const struct brcmf_tlv *ssid_ie; |
Arend van Spriel | 9802776 | 2014-12-21 12:43:53 +0100 | [diff] [blame] | 4433 | const struct brcmf_tlv *country_ie; |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4434 | struct brcmf_ssid_le ssid_le; |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4435 | s32 err = -EPERM; |
Johannes Berg | 4b5800f | 2014-01-15 14:55:59 +0100 | [diff] [blame] | 4436 | const struct brcmf_tlv *rsn_ie; |
| 4437 | const struct brcmf_vs_tlv *wpa_ie; |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4438 | struct brcmf_join_params join_params; |
Hante Meuleman | a0f0795 | 2013-02-08 15:53:47 +0100 | [diff] [blame] | 4439 | enum nl80211_iftype dev_role; |
| 4440 | struct brcmf_fil_bss_enable_le bss_enable; |
Arend van Spriel | 06c0158 | 2014-05-12 10:47:37 +0200 | [diff] [blame] | 4441 | u16 chanspec; |
Hante Meuleman | a44aa40 | 2014-12-03 21:05:33 +0100 | [diff] [blame] | 4442 | bool mbss; |
Arend van Spriel | 9802776 | 2014-12-21 12:43:53 +0100 | [diff] [blame] | 4443 | int is_11d; |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4444 | |
Arend van Spriel | 06c0158 | 2014-05-12 10:47:37 +0200 | [diff] [blame] | 4445 | brcmf_dbg(TRACE, "ctrlchn=%d, center=%d, bw=%d, beacon_interval=%d, dtim_period=%d,\n", |
| 4446 | settings->chandef.chan->hw_value, |
| 4447 | settings->chandef.center_freq1, settings->chandef.width, |
Arend van Spriel | a9a5687 | 2014-05-12 10:47:33 +0200 | [diff] [blame] | 4448 | settings->beacon_interval, settings->dtim_period); |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 4449 | brcmf_dbg(TRACE, "ssid=%s(%zu), auth_type=%d, inactivity_timeout=%d\n", |
| 4450 | settings->ssid, settings->ssid_len, settings->auth_type, |
| 4451 | settings->inactivity_timeout); |
Hante Meuleman | 426d0a5 | 2013-02-08 15:53:53 +0100 | [diff] [blame] | 4452 | dev_role = ifp->vif->wdev.iftype; |
Hante Meuleman | a44aa40 | 2014-12-03 21:05:33 +0100 | [diff] [blame] | 4453 | mbss = ifp->vif->mbss; |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4454 | |
Arend van Spriel | 9802776 | 2014-12-21 12:43:53 +0100 | [diff] [blame] | 4455 | /* store current 11d setting */ |
| 4456 | brcmf_fil_cmd_int_get(ifp, BRCMF_C_GET_REGULATORY, &ifp->vif->is_11d); |
| 4457 | country_ie = brcmf_parse_tlvs((u8 *)settings->beacon.tail, |
| 4458 | settings->beacon.tail_len, |
| 4459 | WLAN_EID_COUNTRY); |
| 4460 | is_11d = country_ie ? 1 : 0; |
| 4461 | |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4462 | memset(&ssid_le, 0, sizeof(ssid_le)); |
| 4463 | if (settings->ssid == NULL || settings->ssid_len == 0) { |
| 4464 | ie_offset = DOT11_MGMT_HDR_LEN + DOT11_BCN_PRB_FIXED_LEN; |
| 4465 | ssid_ie = brcmf_parse_tlvs( |
| 4466 | (u8 *)&settings->beacon.head[ie_offset], |
| 4467 | settings->beacon.head_len - ie_offset, |
| 4468 | WLAN_EID_SSID); |
| 4469 | if (!ssid_ie) |
| 4470 | return -EINVAL; |
| 4471 | |
| 4472 | memcpy(ssid_le.SSID, ssid_ie->data, ssid_ie->len); |
| 4473 | ssid_le.SSID_len = cpu_to_le32(ssid_ie->len); |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 4474 | brcmf_dbg(TRACE, "SSID is (%s) in Head\n", ssid_le.SSID); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4475 | } else { |
| 4476 | memcpy(ssid_le.SSID, settings->ssid, settings->ssid_len); |
| 4477 | ssid_le.SSID_len = cpu_to_le32((u32)settings->ssid_len); |
| 4478 | } |
| 4479 | |
Hante Meuleman | a44aa40 | 2014-12-03 21:05:33 +0100 | [diff] [blame] | 4480 | if (!mbss) { |
| 4481 | brcmf_set_mpc(ifp, 0); |
Franky Lin | 52f22fb | 2016-02-17 11:26:55 +0100 | [diff] [blame] | 4482 | brcmf_configure_arp_nd_offload(ifp, false); |
Hante Meuleman | a44aa40 | 2014-12-03 21:05:33 +0100 | [diff] [blame] | 4483 | } |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4484 | |
| 4485 | /* find the RSN_IE */ |
| 4486 | rsn_ie = brcmf_parse_tlvs((u8 *)settings->beacon.tail, |
| 4487 | settings->beacon.tail_len, WLAN_EID_RSN); |
| 4488 | |
| 4489 | /* find the WPA_IE */ |
| 4490 | wpa_ie = brcmf_find_wpaie((u8 *)settings->beacon.tail, |
| 4491 | settings->beacon.tail_len); |
| 4492 | |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4493 | if ((wpa_ie != NULL || rsn_ie != NULL)) { |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 4494 | brcmf_dbg(TRACE, "WPA(2) IE is found\n"); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4495 | if (wpa_ie != NULL) { |
| 4496 | /* WPA IE */ |
Hante Meuleman | a44aa40 | 2014-12-03 21:05:33 +0100 | [diff] [blame] | 4497 | err = brcmf_configure_wpaie(ifp, wpa_ie, false); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4498 | if (err < 0) |
| 4499 | goto exit; |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4500 | } else { |
Hante Meuleman | a44aa40 | 2014-12-03 21:05:33 +0100 | [diff] [blame] | 4501 | struct brcmf_vs_tlv *tmp_ie; |
| 4502 | |
| 4503 | tmp_ie = (struct brcmf_vs_tlv *)rsn_ie; |
| 4504 | |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4505 | /* RSN IE */ |
Hante Meuleman | a44aa40 | 2014-12-03 21:05:33 +0100 | [diff] [blame] | 4506 | err = brcmf_configure_wpaie(ifp, tmp_ie, true); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4507 | if (err < 0) |
| 4508 | goto exit; |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4509 | } |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4510 | } else { |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 4511 | brcmf_dbg(TRACE, "No WPA(2) IEs found\n"); |
Hante Meuleman | 1f17011 | 2013-02-06 18:40:38 +0100 | [diff] [blame] | 4512 | brcmf_configure_opensecurity(ifp); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4513 | } |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4514 | |
Hante Meuleman | a0f0795 | 2013-02-08 15:53:47 +0100 | [diff] [blame] | 4515 | brcmf_config_ap_mgmt_ie(ifp->vif, &settings->beacon); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4516 | |
Hante Meuleman | a44aa40 | 2014-12-03 21:05:33 +0100 | [diff] [blame] | 4517 | if (!mbss) { |
| 4518 | chanspec = chandef_to_chanspec(&cfg->d11inf, |
| 4519 | &settings->chandef); |
| 4520 | err = brcmf_fil_iovar_int_set(ifp, "chanspec", chanspec); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4521 | if (err < 0) { |
Hante Meuleman | a44aa40 | 2014-12-03 21:05:33 +0100 | [diff] [blame] | 4522 | brcmf_err("Set Channel failed: chspec=%d, %d\n", |
| 4523 | chanspec, err); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4524 | goto exit; |
| 4525 | } |
Hante Meuleman | a44aa40 | 2014-12-03 21:05:33 +0100 | [diff] [blame] | 4526 | |
Arend van Spriel | 9802776 | 2014-12-21 12:43:53 +0100 | [diff] [blame] | 4527 | if (is_11d != ifp->vif->is_11d) { |
| 4528 | err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_REGULATORY, |
| 4529 | is_11d); |
| 4530 | if (err < 0) { |
| 4531 | brcmf_err("Regulatory Set Error, %d\n", err); |
| 4532 | goto exit; |
| 4533 | } |
| 4534 | } |
Hante Meuleman | a44aa40 | 2014-12-03 21:05:33 +0100 | [diff] [blame] | 4535 | if (settings->beacon_interval) { |
| 4536 | err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_BCNPRD, |
| 4537 | settings->beacon_interval); |
| 4538 | if (err < 0) { |
| 4539 | brcmf_err("Beacon Interval Set Error, %d\n", |
| 4540 | err); |
| 4541 | goto exit; |
| 4542 | } |
| 4543 | } |
| 4544 | if (settings->dtim_period) { |
| 4545 | err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_DTIMPRD, |
| 4546 | settings->dtim_period); |
| 4547 | if (err < 0) { |
| 4548 | brcmf_err("DTIM Interval Set Error, %d\n", err); |
| 4549 | goto exit; |
| 4550 | } |
| 4551 | } |
| 4552 | |
Hante Meuleman | 8abffd8 | 2015-10-29 20:33:16 +0100 | [diff] [blame] | 4553 | if ((dev_role == NL80211_IFTYPE_AP) && |
| 4554 | ((ifp->ifidx == 0) || |
| 4555 | !brcmf_feat_is_enabled(ifp, BRCMF_FEAT_RSDB))) { |
Hante Meuleman | a44aa40 | 2014-12-03 21:05:33 +0100 | [diff] [blame] | 4556 | err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_DOWN, 1); |
| 4557 | if (err < 0) { |
| 4558 | brcmf_err("BRCMF_C_DOWN error %d\n", err); |
| 4559 | goto exit; |
| 4560 | } |
| 4561 | brcmf_fil_iovar_int_set(ifp, "apsta", 0); |
| 4562 | } |
| 4563 | |
| 4564 | err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_INFRA, 1); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4565 | if (err < 0) { |
Hante Meuleman | a44aa40 | 2014-12-03 21:05:33 +0100 | [diff] [blame] | 4566 | brcmf_err("SET INFRA error %d\n", err); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4567 | goto exit; |
| 4568 | } |
Arend van Spriel | 9802776 | 2014-12-21 12:43:53 +0100 | [diff] [blame] | 4569 | } else if (WARN_ON(is_11d != ifp->vif->is_11d)) { |
| 4570 | /* Multiple-BSS should use same 11d configuration */ |
| 4571 | err = -EINVAL; |
| 4572 | goto exit; |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4573 | } |
Hante Meuleman | a0f0795 | 2013-02-08 15:53:47 +0100 | [diff] [blame] | 4574 | if (dev_role == NL80211_IFTYPE_AP) { |
Hante Meuleman | a44aa40 | 2014-12-03 21:05:33 +0100 | [diff] [blame] | 4575 | if ((brcmf_feat_is_enabled(ifp, BRCMF_FEAT_MBSS)) && (!mbss)) |
| 4576 | brcmf_fil_iovar_int_set(ifp, "mbss", 1); |
| 4577 | |
Hante Meuleman | a0f0795 | 2013-02-08 15:53:47 +0100 | [diff] [blame] | 4578 | err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_AP, 1); |
| 4579 | if (err < 0) { |
| 4580 | brcmf_err("setting AP mode failed %d\n", err); |
| 4581 | goto exit; |
| 4582 | } |
| 4583 | err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_UP, 1); |
| 4584 | if (err < 0) { |
| 4585 | brcmf_err("BRCMF_C_UP error (%d)\n", err); |
| 4586 | goto exit; |
| 4587 | } |
Hante Meuleman | 118eb30 | 2014-12-21 12:43:49 +0100 | [diff] [blame] | 4588 | /* On DOWN the firmware removes the WEP keys, reconfigure |
| 4589 | * them if they were set. |
| 4590 | */ |
| 4591 | brcmf_cfg80211_reconfigure_wep(ifp); |
Hante Meuleman | a0f0795 | 2013-02-08 15:53:47 +0100 | [diff] [blame] | 4592 | |
| 4593 | memset(&join_params, 0, sizeof(join_params)); |
| 4594 | /* join parameters starts with ssid */ |
| 4595 | memcpy(&join_params.ssid_le, &ssid_le, sizeof(ssid_le)); |
| 4596 | /* create softap */ |
| 4597 | err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SET_SSID, |
| 4598 | &join_params, sizeof(join_params)); |
| 4599 | if (err < 0) { |
| 4600 | brcmf_err("SET SSID error (%d)\n", err); |
| 4601 | goto exit; |
| 4602 | } |
| 4603 | brcmf_dbg(TRACE, "AP mode configuration complete\n"); |
| 4604 | } else { |
| 4605 | err = brcmf_fil_bsscfg_data_set(ifp, "ssid", &ssid_le, |
| 4606 | sizeof(ssid_le)); |
| 4607 | if (err < 0) { |
| 4608 | brcmf_err("setting ssid failed %d\n", err); |
| 4609 | goto exit; |
| 4610 | } |
Hante Meuleman | 37a869e | 2015-10-29 20:33:17 +0100 | [diff] [blame] | 4611 | bss_enable.bsscfgidx = cpu_to_le32(ifp->bsscfgidx); |
Hante Meuleman | a0f0795 | 2013-02-08 15:53:47 +0100 | [diff] [blame] | 4612 | bss_enable.enable = cpu_to_le32(1); |
| 4613 | err = brcmf_fil_iovar_data_set(ifp, "bss", &bss_enable, |
| 4614 | sizeof(bss_enable)); |
| 4615 | if (err < 0) { |
| 4616 | brcmf_err("bss_enable config failed %d\n", err); |
| 4617 | goto exit; |
| 4618 | } |
| 4619 | |
| 4620 | brcmf_dbg(TRACE, "GO mode configuration complete\n"); |
| 4621 | } |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 4622 | set_bit(BRCMF_VIF_STATUS_AP_CREATED, &ifp->vif->sme_state); |
Hante Meuleman | 92121e6 | 2015-10-08 20:33:21 +0200 | [diff] [blame] | 4623 | brcmf_net_setcarrier(ifp, true); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4624 | |
| 4625 | exit: |
Hante Meuleman | a44aa40 | 2014-12-03 21:05:33 +0100 | [diff] [blame] | 4626 | if ((err) && (!mbss)) { |
Arend van Spriel | f96aa07 | 2013-04-05 10:57:48 +0200 | [diff] [blame] | 4627 | brcmf_set_mpc(ifp, 1); |
Franky Lin | 52f22fb | 2016-02-17 11:26:55 +0100 | [diff] [blame] | 4628 | brcmf_configure_arp_nd_offload(ifp, true); |
Hante Meuleman | b365745 | 2013-05-27 21:09:53 +0200 | [diff] [blame] | 4629 | } |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4630 | return err; |
| 4631 | } |
| 4632 | |
| 4633 | static int brcmf_cfg80211_stop_ap(struct wiphy *wiphy, struct net_device *ndev) |
| 4634 | { |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 4635 | struct brcmf_if *ifp = netdev_priv(ndev); |
Hante Meuleman | 5c33a94 | 2013-04-02 21:06:18 +0200 | [diff] [blame] | 4636 | s32 err; |
Hante Meuleman | 426d0a5 | 2013-02-08 15:53:53 +0100 | [diff] [blame] | 4637 | struct brcmf_fil_bss_enable_le bss_enable; |
Hante Meuleman | 5c33a94 | 2013-04-02 21:06:18 +0200 | [diff] [blame] | 4638 | struct brcmf_join_params join_params; |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4639 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 4640 | brcmf_dbg(TRACE, "Enter\n"); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4641 | |
Hante Meuleman | 426d0a5 | 2013-02-08 15:53:53 +0100 | [diff] [blame] | 4642 | if (ifp->vif->wdev.iftype == NL80211_IFTYPE_AP) { |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4643 | /* Due to most likely deauths outstanding we sleep */ |
| 4644 | /* first to make sure they get processed by fw. */ |
| 4645 | msleep(400); |
Hante Meuleman | 5c33a94 | 2013-04-02 21:06:18 +0200 | [diff] [blame] | 4646 | |
Hante Meuleman | a44aa40 | 2014-12-03 21:05:33 +0100 | [diff] [blame] | 4647 | if (ifp->vif->mbss) { |
| 4648 | err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_DOWN, 1); |
| 4649 | return err; |
| 4650 | } |
| 4651 | |
Hante Meuleman | 5c33a94 | 2013-04-02 21:06:18 +0200 | [diff] [blame] | 4652 | memset(&join_params, 0, sizeof(join_params)); |
| 4653 | err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SET_SSID, |
| 4654 | &join_params, sizeof(join_params)); |
| 4655 | if (err < 0) |
| 4656 | brcmf_err("SET SSID error (%d)\n", err); |
Hante Meuleman | a44aa40 | 2014-12-03 21:05:33 +0100 | [diff] [blame] | 4657 | err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_DOWN, 1); |
Hante Meuleman | 5c33a94 | 2013-04-02 21:06:18 +0200 | [diff] [blame] | 4658 | if (err < 0) |
Hante Meuleman | a44aa40 | 2014-12-03 21:05:33 +0100 | [diff] [blame] | 4659 | brcmf_err("BRCMF_C_DOWN error %d\n", err); |
Hante Meuleman | 5c33a94 | 2013-04-02 21:06:18 +0200 | [diff] [blame] | 4660 | err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_AP, 0); |
| 4661 | if (err < 0) |
| 4662 | brcmf_err("setting AP mode failed %d\n", err); |
| 4663 | err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_INFRA, 0); |
| 4664 | if (err < 0) |
| 4665 | brcmf_err("setting INFRA mode failed %d\n", err); |
Hante Meuleman | a44aa40 | 2014-12-03 21:05:33 +0100 | [diff] [blame] | 4666 | if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_MBSS)) |
| 4667 | brcmf_fil_iovar_int_set(ifp, "mbss", 0); |
Arend van Spriel | 9802776 | 2014-12-21 12:43:53 +0100 | [diff] [blame] | 4668 | err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_REGULATORY, |
| 4669 | ifp->vif->is_11d); |
| 4670 | if (err < 0) |
| 4671 | brcmf_err("restoring REGULATORY setting failed %d\n", |
| 4672 | err); |
Hante Meuleman | a44aa40 | 2014-12-03 21:05:33 +0100 | [diff] [blame] | 4673 | /* Bring device back up so it can be used again */ |
| 4674 | err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_UP, 1); |
| 4675 | if (err < 0) |
| 4676 | brcmf_err("BRCMF_C_UP error %d\n", err); |
Hante Meuleman | 426d0a5 | 2013-02-08 15:53:53 +0100 | [diff] [blame] | 4677 | } else { |
Hante Meuleman | 37a869e | 2015-10-29 20:33:17 +0100 | [diff] [blame] | 4678 | bss_enable.bsscfgidx = cpu_to_le32(ifp->bsscfgidx); |
Hante Meuleman | 426d0a5 | 2013-02-08 15:53:53 +0100 | [diff] [blame] | 4679 | bss_enable.enable = cpu_to_le32(0); |
| 4680 | err = brcmf_fil_iovar_data_set(ifp, "bss", &bss_enable, |
| 4681 | sizeof(bss_enable)); |
| 4682 | if (err < 0) |
| 4683 | brcmf_err("bss_enable config failed %d\n", err); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4684 | } |
Arend van Spriel | f96aa07 | 2013-04-05 10:57:48 +0200 | [diff] [blame] | 4685 | brcmf_set_mpc(ifp, 1); |
Franky Lin | 52f22fb | 2016-02-17 11:26:55 +0100 | [diff] [blame] | 4686 | brcmf_configure_arp_nd_offload(ifp, true); |
Hante Meuleman | 426d0a5 | 2013-02-08 15:53:53 +0100 | [diff] [blame] | 4687 | clear_bit(BRCMF_VIF_STATUS_AP_CREATED, &ifp->vif->sme_state); |
Hante Meuleman | 92121e6 | 2015-10-08 20:33:21 +0200 | [diff] [blame] | 4688 | brcmf_net_setcarrier(ifp, false); |
Hante Meuleman | 426d0a5 | 2013-02-08 15:53:53 +0100 | [diff] [blame] | 4689 | |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4690 | return err; |
| 4691 | } |
| 4692 | |
Hante Meuleman | a0f0795 | 2013-02-08 15:53:47 +0100 | [diff] [blame] | 4693 | static s32 |
| 4694 | brcmf_cfg80211_change_beacon(struct wiphy *wiphy, struct net_device *ndev, |
| 4695 | struct cfg80211_beacon_data *info) |
| 4696 | { |
Hante Meuleman | a0f0795 | 2013-02-08 15:53:47 +0100 | [diff] [blame] | 4697 | struct brcmf_if *ifp = netdev_priv(ndev); |
| 4698 | s32 err; |
| 4699 | |
| 4700 | brcmf_dbg(TRACE, "Enter\n"); |
| 4701 | |
Hante Meuleman | a0f0795 | 2013-02-08 15:53:47 +0100 | [diff] [blame] | 4702 | err = brcmf_config_ap_mgmt_ie(ifp->vif, info); |
| 4703 | |
| 4704 | return err; |
| 4705 | } |
| 4706 | |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4707 | static int |
| 4708 | brcmf_cfg80211_del_station(struct wiphy *wiphy, struct net_device *ndev, |
Jouni Malinen | 89c771e | 2014-10-10 20:52:40 +0300 | [diff] [blame] | 4709 | struct station_del_parameters *params) |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4710 | { |
Hante Meuleman | a0f0795 | 2013-02-08 15:53:47 +0100 | [diff] [blame] | 4711 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4712 | struct brcmf_scb_val_le scbval; |
Arend van Spriel | 0abb5f21 | 2012-10-22 13:55:32 -0700 | [diff] [blame] | 4713 | struct brcmf_if *ifp = netdev_priv(ndev); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4714 | s32 err; |
| 4715 | |
Jouni Malinen | 89c771e | 2014-10-10 20:52:40 +0300 | [diff] [blame] | 4716 | if (!params->mac) |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4717 | return -EFAULT; |
| 4718 | |
Jouni Malinen | 89c771e | 2014-10-10 20:52:40 +0300 | [diff] [blame] | 4719 | brcmf_dbg(TRACE, "Enter %pM\n", params->mac); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4720 | |
Hante Meuleman | a0f0795 | 2013-02-08 15:53:47 +0100 | [diff] [blame] | 4721 | if (ifp->vif == cfg->p2p.bss_idx[P2PAPI_BSSCFG_DEVICE].vif) |
| 4722 | ifp = cfg->p2p.bss_idx[P2PAPI_BSSCFG_PRIMARY].vif->ifp; |
Arend van Spriel | ce81e31 | 2012-10-22 13:55:37 -0700 | [diff] [blame] | 4723 | if (!check_vif_up(ifp->vif)) |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4724 | return -EIO; |
| 4725 | |
Jouni Malinen | 89c771e | 2014-10-10 20:52:40 +0300 | [diff] [blame] | 4726 | memcpy(&scbval.ea, params->mac, ETH_ALEN); |
Rafał Miłecki | ba8b6ae | 2015-02-08 11:51:47 +0100 | [diff] [blame] | 4727 | scbval.val = cpu_to_le32(params->reason_code); |
Arend van Spriel | 0abb5f21 | 2012-10-22 13:55:32 -0700 | [diff] [blame] | 4728 | 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] | 4729 | &scbval, sizeof(scbval)); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4730 | if (err) |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 4731 | brcmf_err("SCB_DEAUTHENTICATE_FOR_REASON failed %d\n", err); |
Hante Meuleman | 7ab6acd | 2013-02-08 15:53:58 +0100 | [diff] [blame] | 4732 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 4733 | brcmf_dbg(TRACE, "Exit\n"); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4734 | return err; |
| 4735 | } |
| 4736 | |
Hante Meuleman | 6b89dcb | 2014-12-21 12:43:52 +0100 | [diff] [blame] | 4737 | static int |
| 4738 | brcmf_cfg80211_change_station(struct wiphy *wiphy, struct net_device *ndev, |
| 4739 | const u8 *mac, struct station_parameters *params) |
| 4740 | { |
| 4741 | struct brcmf_if *ifp = netdev_priv(ndev); |
| 4742 | s32 err; |
| 4743 | |
| 4744 | brcmf_dbg(TRACE, "Enter, MAC %pM, mask 0x%04x set 0x%04x\n", mac, |
| 4745 | params->sta_flags_mask, params->sta_flags_set); |
| 4746 | |
| 4747 | /* Ignore all 00 MAC */ |
| 4748 | if (is_zero_ether_addr(mac)) |
| 4749 | return 0; |
| 4750 | |
| 4751 | if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED))) |
| 4752 | return 0; |
| 4753 | |
| 4754 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED)) |
| 4755 | err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SET_SCB_AUTHORIZE, |
| 4756 | (void *)mac, ETH_ALEN); |
| 4757 | else |
| 4758 | err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SET_SCB_DEAUTHORIZE, |
| 4759 | (void *)mac, ETH_ALEN); |
| 4760 | if (err < 0) |
| 4761 | brcmf_err("Setting SCB (de-)authorize failed, %d\n", err); |
| 4762 | |
| 4763 | return err; |
| 4764 | } |
Hante Meuleman | 0de8aac | 2013-02-08 15:53:38 +0100 | [diff] [blame] | 4765 | |
| 4766 | static void |
| 4767 | brcmf_cfg80211_mgmt_frame_register(struct wiphy *wiphy, |
| 4768 | struct wireless_dev *wdev, |
| 4769 | u16 frame_type, bool reg) |
| 4770 | { |
Arend van Spriel | 7fa2e35 | 2013-04-05 10:57:47 +0200 | [diff] [blame] | 4771 | struct brcmf_cfg80211_vif *vif; |
Hante Meuleman | 0de8aac | 2013-02-08 15:53:38 +0100 | [diff] [blame] | 4772 | u16 mgmt_type; |
| 4773 | |
| 4774 | brcmf_dbg(TRACE, "Enter, frame_type %04x, reg=%d\n", frame_type, reg); |
| 4775 | |
| 4776 | mgmt_type = (frame_type & IEEE80211_FCTL_STYPE) >> 4; |
Arend van Spriel | 7fa2e35 | 2013-04-05 10:57:47 +0200 | [diff] [blame] | 4777 | vif = container_of(wdev, struct brcmf_cfg80211_vif, wdev); |
Hante Meuleman | 0de8aac | 2013-02-08 15:53:38 +0100 | [diff] [blame] | 4778 | if (reg) |
| 4779 | vif->mgmt_rx_reg |= BIT(mgmt_type); |
| 4780 | else |
Hante Meuleman | 318a64c | 2013-02-08 15:53:45 +0100 | [diff] [blame] | 4781 | vif->mgmt_rx_reg &= ~BIT(mgmt_type); |
Hante Meuleman | 0de8aac | 2013-02-08 15:53:38 +0100 | [diff] [blame] | 4782 | } |
| 4783 | |
| 4784 | |
| 4785 | static int |
| 4786 | brcmf_cfg80211_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev, |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 4787 | struct cfg80211_mgmt_tx_params *params, u64 *cookie) |
Hante Meuleman | 0de8aac | 2013-02-08 15:53:38 +0100 | [diff] [blame] | 4788 | { |
| 4789 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 4790 | struct ieee80211_channel *chan = params->chan; |
| 4791 | const u8 *buf = params->buf; |
| 4792 | size_t len = params->len; |
Hante Meuleman | 0de8aac | 2013-02-08 15:53:38 +0100 | [diff] [blame] | 4793 | const struct ieee80211_mgmt *mgmt; |
| 4794 | struct brcmf_cfg80211_vif *vif; |
| 4795 | s32 err = 0; |
| 4796 | s32 ie_offset; |
| 4797 | s32 ie_len; |
Hante Meuleman | 18e2f61 | 2013-02-08 15:53:49 +0100 | [diff] [blame] | 4798 | struct brcmf_fil_action_frame_le *action_frame; |
| 4799 | struct brcmf_fil_af_params_le *af_params; |
| 4800 | bool ack; |
| 4801 | s32 chan_nr; |
Antonio Quartulli | c2ff8ca | 2013-06-11 14:20:01 +0200 | [diff] [blame] | 4802 | u32 freq; |
Hante Meuleman | 0de8aac | 2013-02-08 15:53:38 +0100 | [diff] [blame] | 4803 | |
| 4804 | brcmf_dbg(TRACE, "Enter\n"); |
| 4805 | |
| 4806 | *cookie = 0; |
| 4807 | |
| 4808 | mgmt = (const struct ieee80211_mgmt *)buf; |
| 4809 | |
Hante Meuleman | a0f0795 | 2013-02-08 15:53:47 +0100 | [diff] [blame] | 4810 | if (!ieee80211_is_mgmt(mgmt->frame_control)) { |
| 4811 | brcmf_err("Driver only allows MGMT packet type\n"); |
| 4812 | return -EPERM; |
Hante Meuleman | 0de8aac | 2013-02-08 15:53:38 +0100 | [diff] [blame] | 4813 | } |
Hante Meuleman | a0f0795 | 2013-02-08 15:53:47 +0100 | [diff] [blame] | 4814 | |
Antonio Quartulli | c2ff8ca | 2013-06-11 14:20:01 +0200 | [diff] [blame] | 4815 | vif = container_of(wdev, struct brcmf_cfg80211_vif, wdev); |
| 4816 | |
Hante Meuleman | a0f0795 | 2013-02-08 15:53:47 +0100 | [diff] [blame] | 4817 | if (ieee80211_is_probe_resp(mgmt->frame_control)) { |
| 4818 | /* Right now the only reason to get a probe response */ |
| 4819 | /* is for p2p listen response or for p2p GO from */ |
| 4820 | /* wpa_supplicant. Unfortunately the probe is send */ |
| 4821 | /* on primary ndev, while dongle wants it on the p2p */ |
| 4822 | /* vif. Since this is only reason for a probe */ |
| 4823 | /* response to be sent, the vif is taken from cfg. */ |
| 4824 | /* If ever desired to send proberesp for non p2p */ |
| 4825 | /* response then data should be checked for */ |
| 4826 | /* "DIRECT-". Note in future supplicant will take */ |
| 4827 | /* dedicated p2p wdev to do this and then this 'hack'*/ |
| 4828 | /* is not needed anymore. */ |
| 4829 | ie_offset = DOT11_MGMT_HDR_LEN + |
| 4830 | DOT11_BCN_PRB_FIXED_LEN; |
| 4831 | ie_len = len - ie_offset; |
Hante Meuleman | a0f0795 | 2013-02-08 15:53:47 +0100 | [diff] [blame] | 4832 | if (vif == cfg->p2p.bss_idx[P2PAPI_BSSCFG_PRIMARY].vif) |
| 4833 | vif = cfg->p2p.bss_idx[P2PAPI_BSSCFG_DEVICE].vif; |
| 4834 | err = brcmf_vif_set_mgmt_ie(vif, |
| 4835 | BRCMF_VNDR_IE_PRBRSP_FLAG, |
| 4836 | &buf[ie_offset], |
| 4837 | ie_len); |
| 4838 | cfg80211_mgmt_tx_status(wdev, *cookie, buf, len, true, |
| 4839 | GFP_KERNEL); |
Hante Meuleman | 18e2f61 | 2013-02-08 15:53:49 +0100 | [diff] [blame] | 4840 | } else if (ieee80211_is_action(mgmt->frame_control)) { |
| 4841 | af_params = kzalloc(sizeof(*af_params), GFP_KERNEL); |
| 4842 | if (af_params == NULL) { |
| 4843 | brcmf_err("unable to allocate frame\n"); |
| 4844 | err = -ENOMEM; |
| 4845 | goto exit; |
| 4846 | } |
| 4847 | action_frame = &af_params->action_frame; |
| 4848 | /* Add the packet Id */ |
| 4849 | action_frame->packet_id = cpu_to_le32(*cookie); |
| 4850 | /* Add BSSID */ |
| 4851 | memcpy(&action_frame->da[0], &mgmt->da[0], ETH_ALEN); |
| 4852 | memcpy(&af_params->bssid[0], &mgmt->bssid[0], ETH_ALEN); |
| 4853 | /* Add the length exepted for 802.11 header */ |
| 4854 | action_frame->len = cpu_to_le16(len - DOT11_MGMT_HDR_LEN); |
Antonio Quartulli | c2ff8ca | 2013-06-11 14:20:01 +0200 | [diff] [blame] | 4855 | /* Add the channel. Use the one specified as parameter if any or |
| 4856 | * the current one (got from the firmware) otherwise |
| 4857 | */ |
| 4858 | if (chan) |
| 4859 | freq = chan->center_freq; |
| 4860 | else |
| 4861 | brcmf_fil_cmd_int_get(vif->ifp, BRCMF_C_GET_CHANNEL, |
| 4862 | &freq); |
| 4863 | chan_nr = ieee80211_frequency_to_channel(freq); |
Hante Meuleman | 18e2f61 | 2013-02-08 15:53:49 +0100 | [diff] [blame] | 4864 | af_params->channel = cpu_to_le32(chan_nr); |
| 4865 | |
| 4866 | memcpy(action_frame->data, &buf[DOT11_MGMT_HDR_LEN], |
| 4867 | le16_to_cpu(action_frame->len)); |
| 4868 | |
| 4869 | brcmf_dbg(TRACE, "Action frame, cookie=%lld, len=%d, freq=%d\n", |
Antonio Quartulli | 86a9c4a | 2013-06-19 13:35:31 +0200 | [diff] [blame] | 4870 | *cookie, le16_to_cpu(action_frame->len), freq); |
Hante Meuleman | 18e2f61 | 2013-02-08 15:53:49 +0100 | [diff] [blame] | 4871 | |
Arend van Spriel | 7fa2e35 | 2013-04-05 10:57:47 +0200 | [diff] [blame] | 4872 | ack = brcmf_p2p_send_action_frame(cfg, cfg_to_ndev(cfg), |
Hante Meuleman | 18e2f61 | 2013-02-08 15:53:49 +0100 | [diff] [blame] | 4873 | af_params); |
| 4874 | |
| 4875 | cfg80211_mgmt_tx_status(wdev, *cookie, buf, len, ack, |
| 4876 | GFP_KERNEL); |
| 4877 | kfree(af_params); |
Hante Meuleman | a0f0795 | 2013-02-08 15:53:47 +0100 | [diff] [blame] | 4878 | } else { |
| 4879 | brcmf_dbg(TRACE, "Unhandled, fc=%04x!!\n", mgmt->frame_control); |
| 4880 | brcmf_dbg_hex_dump(true, buf, len, "payload, len=%Zu\n", len); |
| 4881 | } |
| 4882 | |
Hante Meuleman | 18e2f61 | 2013-02-08 15:53:49 +0100 | [diff] [blame] | 4883 | exit: |
Hante Meuleman | 0de8aac | 2013-02-08 15:53:38 +0100 | [diff] [blame] | 4884 | return err; |
| 4885 | } |
| 4886 | |
| 4887 | |
| 4888 | static int |
| 4889 | brcmf_cfg80211_cancel_remain_on_channel(struct wiphy *wiphy, |
| 4890 | struct wireless_dev *wdev, |
| 4891 | u64 cookie) |
| 4892 | { |
| 4893 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); |
| 4894 | struct brcmf_cfg80211_vif *vif; |
| 4895 | int err = 0; |
| 4896 | |
| 4897 | brcmf_dbg(TRACE, "Enter p2p listen cancel\n"); |
| 4898 | |
| 4899 | vif = cfg->p2p.bss_idx[P2PAPI_BSSCFG_DEVICE].vif; |
| 4900 | if (vif == NULL) { |
| 4901 | brcmf_err("No p2p device available for probe response\n"); |
| 4902 | err = -ENODEV; |
| 4903 | goto exit; |
| 4904 | } |
| 4905 | brcmf_p2p_cancel_remain_on_channel(vif->ifp); |
| 4906 | exit: |
| 4907 | return err; |
| 4908 | } |
| 4909 | |
Piotr Haber | 61730d4 | 2013-04-23 12:53:12 +0200 | [diff] [blame] | 4910 | static int brcmf_cfg80211_crit_proto_start(struct wiphy *wiphy, |
| 4911 | struct wireless_dev *wdev, |
| 4912 | enum nl80211_crit_proto_id proto, |
| 4913 | u16 duration) |
| 4914 | { |
| 4915 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); |
| 4916 | struct brcmf_cfg80211_vif *vif; |
| 4917 | |
| 4918 | vif = container_of(wdev, struct brcmf_cfg80211_vif, wdev); |
| 4919 | |
| 4920 | /* only DHCP support for now */ |
| 4921 | if (proto != NL80211_CRIT_PROTO_DHCP) |
| 4922 | return -EINVAL; |
| 4923 | |
| 4924 | /* suppress and abort scanning */ |
| 4925 | set_bit(BRCMF_SCAN_STATUS_SUPPRESS, &cfg->scan_status); |
| 4926 | brcmf_abort_scanning(cfg); |
| 4927 | |
| 4928 | return brcmf_btcoex_set_mode(vif, BRCMF_BTCOEX_DISABLED, duration); |
| 4929 | } |
| 4930 | |
| 4931 | static void brcmf_cfg80211_crit_proto_stop(struct wiphy *wiphy, |
| 4932 | struct wireless_dev *wdev) |
| 4933 | { |
| 4934 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); |
| 4935 | struct brcmf_cfg80211_vif *vif; |
| 4936 | |
| 4937 | vif = container_of(wdev, struct brcmf_cfg80211_vif, wdev); |
| 4938 | |
| 4939 | brcmf_btcoex_set_mode(vif, BRCMF_BTCOEX_ENABLED, 0); |
| 4940 | clear_bit(BRCMF_SCAN_STATUS_SUPPRESS, &cfg->scan_status); |
| 4941 | } |
| 4942 | |
Hante Meuleman | 70b7d94 | 2014-07-30 13:20:07 +0200 | [diff] [blame] | 4943 | static s32 |
| 4944 | brcmf_notify_tdls_peer_event(struct brcmf_if *ifp, |
| 4945 | const struct brcmf_event_msg *e, void *data) |
| 4946 | { |
| 4947 | switch (e->reason) { |
| 4948 | case BRCMF_E_REASON_TDLS_PEER_DISCOVERED: |
| 4949 | brcmf_dbg(TRACE, "TDLS Peer Discovered\n"); |
| 4950 | break; |
| 4951 | case BRCMF_E_REASON_TDLS_PEER_CONNECTED: |
| 4952 | brcmf_dbg(TRACE, "TDLS Peer Connected\n"); |
| 4953 | brcmf_proto_add_tdls_peer(ifp->drvr, ifp->ifidx, (u8 *)e->addr); |
| 4954 | break; |
| 4955 | case BRCMF_E_REASON_TDLS_PEER_DISCONNECTED: |
| 4956 | brcmf_dbg(TRACE, "TDLS Peer Disconnected\n"); |
| 4957 | brcmf_proto_delete_peer(ifp->drvr, ifp->ifidx, (u8 *)e->addr); |
| 4958 | break; |
| 4959 | } |
| 4960 | |
| 4961 | return 0; |
| 4962 | } |
| 4963 | |
Arend van Spriel | 89c2f38 | 2013-08-10 12:27:25 +0200 | [diff] [blame] | 4964 | static int brcmf_convert_nl80211_tdls_oper(enum nl80211_tdls_operation oper) |
| 4965 | { |
| 4966 | int ret; |
| 4967 | |
| 4968 | switch (oper) { |
| 4969 | case NL80211_TDLS_DISCOVERY_REQ: |
| 4970 | ret = BRCMF_TDLS_MANUAL_EP_DISCOVERY; |
| 4971 | break; |
| 4972 | case NL80211_TDLS_SETUP: |
| 4973 | ret = BRCMF_TDLS_MANUAL_EP_CREATE; |
| 4974 | break; |
| 4975 | case NL80211_TDLS_TEARDOWN: |
| 4976 | ret = BRCMF_TDLS_MANUAL_EP_DELETE; |
| 4977 | break; |
| 4978 | default: |
| 4979 | brcmf_err("unsupported operation: %d\n", oper); |
| 4980 | ret = -EOPNOTSUPP; |
| 4981 | } |
| 4982 | return ret; |
| 4983 | } |
| 4984 | |
| 4985 | static int brcmf_cfg80211_tdls_oper(struct wiphy *wiphy, |
Johannes Berg | 3b3a016 | 2014-05-19 17:19:31 +0200 | [diff] [blame] | 4986 | struct net_device *ndev, const u8 *peer, |
Arend van Spriel | 89c2f38 | 2013-08-10 12:27:25 +0200 | [diff] [blame] | 4987 | enum nl80211_tdls_operation oper) |
| 4988 | { |
| 4989 | struct brcmf_if *ifp; |
| 4990 | struct brcmf_tdls_iovar_le info; |
| 4991 | int ret = 0; |
| 4992 | |
| 4993 | ret = brcmf_convert_nl80211_tdls_oper(oper); |
| 4994 | if (ret < 0) |
| 4995 | return ret; |
| 4996 | |
| 4997 | ifp = netdev_priv(ndev); |
| 4998 | memset(&info, 0, sizeof(info)); |
| 4999 | info.mode = (u8)ret; |
| 5000 | if (peer) |
| 5001 | memcpy(info.ea, peer, ETH_ALEN); |
| 5002 | |
| 5003 | ret = brcmf_fil_iovar_data_set(ifp, "tdls_endpoint", |
| 5004 | &info, sizeof(info)); |
| 5005 | if (ret < 0) |
| 5006 | brcmf_err("tdls_endpoint iovar failed: ret=%d\n", ret); |
| 5007 | |
| 5008 | return ret; |
| 5009 | } |
| 5010 | |
Hante Meuleman | 5c22fb8 | 2016-02-17 11:27:03 +0100 | [diff] [blame] | 5011 | #ifdef CONFIG_PM |
| 5012 | static int |
| 5013 | brcmf_cfg80211_set_rekey_data(struct wiphy *wiphy, struct net_device *ndev, |
| 5014 | struct cfg80211_gtk_rekey_data *gtk) |
| 5015 | { |
| 5016 | struct brcmf_if *ifp = netdev_priv(ndev); |
| 5017 | struct brcmf_gtk_keyinfo_le gtk_le; |
| 5018 | int ret; |
| 5019 | |
| 5020 | brcmf_dbg(TRACE, "Enter, bssidx=%d\n", ifp->bsscfgidx); |
| 5021 | |
| 5022 | memcpy(gtk_le.kck, gtk->kck, sizeof(gtk_le.kck)); |
| 5023 | memcpy(gtk_le.kek, gtk->kek, sizeof(gtk_le.kek)); |
| 5024 | memcpy(gtk_le.replay_counter, gtk->replay_ctr, |
| 5025 | sizeof(gtk_le.replay_counter)); |
| 5026 | |
| 5027 | ret = brcmf_fil_iovar_data_set(ifp, "gtk_key_info", >k_le, |
| 5028 | sizeof(gtk_le)); |
| 5029 | if (ret < 0) |
| 5030 | brcmf_err("gtk_key_info iovar failed: ret=%d\n", ret); |
| 5031 | |
| 5032 | return ret; |
| 5033 | } |
| 5034 | #endif |
| 5035 | |
| 5036 | static struct cfg80211_ops brcmf_cfg80211_ops = { |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 5037 | .add_virtual_intf = brcmf_cfg80211_add_iface, |
| 5038 | .del_virtual_intf = brcmf_cfg80211_del_iface, |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5039 | .change_virtual_intf = brcmf_cfg80211_change_iface, |
| 5040 | .scan = brcmf_cfg80211_scan, |
| 5041 | .set_wiphy_params = brcmf_cfg80211_set_wiphy_params, |
| 5042 | .join_ibss = brcmf_cfg80211_join_ibss, |
| 5043 | .leave_ibss = brcmf_cfg80211_leave_ibss, |
| 5044 | .get_station = brcmf_cfg80211_get_station, |
Hante Meuleman | bf2a7e0 | 2015-10-08 20:33:18 +0200 | [diff] [blame] | 5045 | .dump_station = brcmf_cfg80211_dump_station, |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5046 | .set_tx_power = brcmf_cfg80211_set_tx_power, |
| 5047 | .get_tx_power = brcmf_cfg80211_get_tx_power, |
| 5048 | .add_key = brcmf_cfg80211_add_key, |
| 5049 | .del_key = brcmf_cfg80211_del_key, |
| 5050 | .get_key = brcmf_cfg80211_get_key, |
| 5051 | .set_default_key = brcmf_cfg80211_config_default_key, |
| 5052 | .set_default_mgmt_key = brcmf_cfg80211_config_default_mgmt_key, |
| 5053 | .set_power_mgmt = brcmf_cfg80211_set_power_mgmt, |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5054 | .connect = brcmf_cfg80211_connect, |
| 5055 | .disconnect = brcmf_cfg80211_disconnect, |
| 5056 | .suspend = brcmf_cfg80211_suspend, |
| 5057 | .resume = brcmf_cfg80211_resume, |
| 5058 | .set_pmksa = brcmf_cfg80211_set_pmksa, |
| 5059 | .del_pmksa = brcmf_cfg80211_del_pmksa, |
Arend van Spriel | cbaa177 | 2012-08-30 19:43:02 +0200 | [diff] [blame] | 5060 | .flush_pmksa = brcmf_cfg80211_flush_pmksa, |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 5061 | .start_ap = brcmf_cfg80211_start_ap, |
| 5062 | .stop_ap = brcmf_cfg80211_stop_ap, |
Hante Meuleman | a0f0795 | 2013-02-08 15:53:47 +0100 | [diff] [blame] | 5063 | .change_beacon = brcmf_cfg80211_change_beacon, |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 5064 | .del_station = brcmf_cfg80211_del_station, |
Hante Meuleman | 6b89dcb | 2014-12-21 12:43:52 +0100 | [diff] [blame] | 5065 | .change_station = brcmf_cfg80211_change_station, |
Arend van Spriel | e580607 | 2012-09-19 22:21:08 +0200 | [diff] [blame] | 5066 | .sched_scan_start = brcmf_cfg80211_sched_scan_start, |
| 5067 | .sched_scan_stop = brcmf_cfg80211_sched_scan_stop, |
Hante Meuleman | 0de8aac | 2013-02-08 15:53:38 +0100 | [diff] [blame] | 5068 | .mgmt_frame_register = brcmf_cfg80211_mgmt_frame_register, |
| 5069 | .mgmt_tx = brcmf_cfg80211_mgmt_tx, |
| 5070 | .remain_on_channel = brcmf_p2p_remain_on_channel, |
| 5071 | .cancel_remain_on_channel = brcmf_cfg80211_cancel_remain_on_channel, |
Arend van Spriel | 27f10e3 | 2013-04-05 10:57:50 +0200 | [diff] [blame] | 5072 | .start_p2p_device = brcmf_p2p_start_device, |
| 5073 | .stop_p2p_device = brcmf_p2p_stop_device, |
Piotr Haber | 61730d4 | 2013-04-23 12:53:12 +0200 | [diff] [blame] | 5074 | .crit_proto_start = brcmf_cfg80211_crit_proto_start, |
| 5075 | .crit_proto_stop = brcmf_cfg80211_crit_proto_stop, |
Arend van Spriel | 89c2f38 | 2013-08-10 12:27:25 +0200 | [diff] [blame] | 5076 | .tdls_oper = brcmf_cfg80211_tdls_oper, |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5077 | }; |
| 5078 | |
Arend van Spriel | 3eacf86 | 2012-10-22 13:55:30 -0700 | [diff] [blame] | 5079 | struct brcmf_cfg80211_vif *brcmf_alloc_vif(struct brcmf_cfg80211_info *cfg, |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 5080 | enum nl80211_iftype type, |
| 5081 | bool pm_block) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5082 | { |
Hante Meuleman | a44aa40 | 2014-12-03 21:05:33 +0100 | [diff] [blame] | 5083 | struct brcmf_cfg80211_vif *vif_walk; |
Arend van Spriel | 3eacf86 | 2012-10-22 13:55:30 -0700 | [diff] [blame] | 5084 | struct brcmf_cfg80211_vif *vif; |
Hante Meuleman | a44aa40 | 2014-12-03 21:05:33 +0100 | [diff] [blame] | 5085 | bool mbss; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5086 | |
Arend van Spriel | 33a6b15 | 2013-02-08 15:53:39 +0100 | [diff] [blame] | 5087 | brcmf_dbg(TRACE, "allocating virtual interface (size=%zu)\n", |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 5088 | sizeof(*vif)); |
Arend van Spriel | 3eacf86 | 2012-10-22 13:55:30 -0700 | [diff] [blame] | 5089 | vif = kzalloc(sizeof(*vif), GFP_KERNEL); |
| 5090 | if (!vif) |
| 5091 | return ERR_PTR(-ENOMEM); |
| 5092 | |
| 5093 | vif->wdev.wiphy = cfg->wiphy; |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 5094 | vif->wdev.iftype = type; |
Arend van Spriel | 3eacf86 | 2012-10-22 13:55:30 -0700 | [diff] [blame] | 5095 | |
Arend van Spriel | 3eacf86 | 2012-10-22 13:55:30 -0700 | [diff] [blame] | 5096 | vif->pm_block = pm_block; |
Arend van Spriel | 3eacf86 | 2012-10-22 13:55:30 -0700 | [diff] [blame] | 5097 | |
Arend van Spriel | 6ac4f4e | 2012-10-22 13:55:31 -0700 | [diff] [blame] | 5098 | brcmf_init_prof(&vif->profile); |
| 5099 | |
Hante Meuleman | a44aa40 | 2014-12-03 21:05:33 +0100 | [diff] [blame] | 5100 | if (type == NL80211_IFTYPE_AP) { |
| 5101 | mbss = false; |
| 5102 | list_for_each_entry(vif_walk, &cfg->vif_list, list) { |
| 5103 | if (vif_walk->wdev.iftype == NL80211_IFTYPE_AP) { |
| 5104 | mbss = true; |
| 5105 | break; |
| 5106 | } |
| 5107 | } |
| 5108 | vif->mbss = mbss; |
| 5109 | } |
| 5110 | |
Arend van Spriel | 3eacf86 | 2012-10-22 13:55:30 -0700 | [diff] [blame] | 5111 | list_add_tail(&vif->list, &cfg->vif_list); |
Arend van Spriel | 3eacf86 | 2012-10-22 13:55:30 -0700 | [diff] [blame] | 5112 | return vif; |
| 5113 | } |
| 5114 | |
Arend van Spriel | 427dec5 | 2014-01-06 12:40:47 +0100 | [diff] [blame] | 5115 | void brcmf_free_vif(struct brcmf_cfg80211_vif *vif) |
Arend van Spriel | 3eacf86 | 2012-10-22 13:55:30 -0700 | [diff] [blame] | 5116 | { |
Arend van Spriel | 3eacf86 | 2012-10-22 13:55:30 -0700 | [diff] [blame] | 5117 | list_del(&vif->list); |
Arend van Spriel | 3eacf86 | 2012-10-22 13:55:30 -0700 | [diff] [blame] | 5118 | kfree(vif); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5119 | } |
| 5120 | |
Arend van Spriel | 9df4d54 | 2014-01-06 12:40:49 +0100 | [diff] [blame] | 5121 | void brcmf_cfg80211_free_netdev(struct net_device *ndev) |
| 5122 | { |
| 5123 | struct brcmf_cfg80211_vif *vif; |
| 5124 | struct brcmf_if *ifp; |
| 5125 | |
| 5126 | ifp = netdev_priv(ndev); |
| 5127 | vif = ifp->vif; |
| 5128 | |
Arend van Spriel | 95ef123 | 2015-08-26 22:15:04 +0200 | [diff] [blame] | 5129 | if (vif) |
| 5130 | brcmf_free_vif(vif); |
Arend van Spriel | 9df4d54 | 2014-01-06 12:40:49 +0100 | [diff] [blame] | 5131 | free_netdev(ndev); |
| 5132 | } |
| 5133 | |
Arend van Spriel | 903e0ee | 2012-11-28 21:44:11 +0100 | [diff] [blame] | 5134 | static bool brcmf_is_linkup(const struct brcmf_event_msg *e) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5135 | { |
Arend van Spriel | 5c36b99 | 2012-11-14 18:46:05 -0800 | [diff] [blame] | 5136 | u32 event = e->event_code; |
| 5137 | u32 status = e->status; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5138 | |
| 5139 | if (event == BRCMF_E_SET_SSID && status == BRCMF_E_STATUS_SUCCESS) { |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 5140 | brcmf_dbg(CONN, "Processing set ssid\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5141 | return true; |
| 5142 | } |
| 5143 | |
| 5144 | return false; |
| 5145 | } |
| 5146 | |
Arend van Spriel | 903e0ee | 2012-11-28 21:44:11 +0100 | [diff] [blame] | 5147 | static bool brcmf_is_linkdown(const struct brcmf_event_msg *e) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5148 | { |
Arend van Spriel | 5c36b99 | 2012-11-14 18:46:05 -0800 | [diff] [blame] | 5149 | u32 event = e->event_code; |
| 5150 | u16 flags = e->flags; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5151 | |
Hante Meuleman | 68ca395 | 2014-02-25 20:30:26 +0100 | [diff] [blame] | 5152 | if ((event == BRCMF_E_DEAUTH) || (event == BRCMF_E_DEAUTH_IND) || |
| 5153 | (event == BRCMF_E_DISASSOC_IND) || |
| 5154 | ((event == BRCMF_E_LINK) && (!(flags & BRCMF_EVENT_MSG_LINK)))) { |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 5155 | brcmf_dbg(CONN, "Processing link down\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5156 | return true; |
| 5157 | } |
| 5158 | return false; |
| 5159 | } |
| 5160 | |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5161 | static bool brcmf_is_nonetwork(struct brcmf_cfg80211_info *cfg, |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5162 | const struct brcmf_event_msg *e) |
| 5163 | { |
Arend van Spriel | 5c36b99 | 2012-11-14 18:46:05 -0800 | [diff] [blame] | 5164 | u32 event = e->event_code; |
| 5165 | u32 status = e->status; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5166 | |
| 5167 | if (event == BRCMF_E_LINK && status == BRCMF_E_STATUS_NO_NETWORKS) { |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 5168 | brcmf_dbg(CONN, "Processing Link %s & no network found\n", |
| 5169 | e->flags & BRCMF_EVENT_MSG_LINK ? "up" : "down"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5170 | return true; |
| 5171 | } |
| 5172 | |
| 5173 | if (event == BRCMF_E_SET_SSID && status != BRCMF_E_STATUS_SUCCESS) { |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 5174 | brcmf_dbg(CONN, "Processing connecting & no network found\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5175 | return true; |
| 5176 | } |
| 5177 | |
| 5178 | return false; |
| 5179 | } |
| 5180 | |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5181 | static void brcmf_clear_assoc_ies(struct brcmf_cfg80211_info *cfg) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5182 | { |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5183 | struct brcmf_cfg80211_connect_info *conn_info = cfg_to_conn(cfg); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5184 | |
| 5185 | kfree(conn_info->req_ie); |
| 5186 | conn_info->req_ie = NULL; |
| 5187 | conn_info->req_ie_len = 0; |
| 5188 | kfree(conn_info->resp_ie); |
| 5189 | conn_info->resp_ie = NULL; |
| 5190 | conn_info->resp_ie_len = 0; |
| 5191 | } |
| 5192 | |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 5193 | static s32 brcmf_get_assoc_ies(struct brcmf_cfg80211_info *cfg, |
| 5194 | struct brcmf_if *ifp) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5195 | { |
Arend van Spriel | c4e382d | 2011-10-12 20:51:21 +0200 | [diff] [blame] | 5196 | struct brcmf_cfg80211_assoc_ielen_le *assoc_info; |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5197 | struct brcmf_cfg80211_connect_info *conn_info = cfg_to_conn(cfg); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5198 | u32 req_len; |
| 5199 | u32 resp_len; |
| 5200 | s32 err = 0; |
| 5201 | |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5202 | brcmf_clear_assoc_ies(cfg); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5203 | |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 5204 | err = brcmf_fil_iovar_data_get(ifp, "assoc_info", |
| 5205 | cfg->extra_buf, WL_ASSOC_INFO_MAX); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5206 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 5207 | brcmf_err("could not get assoc info (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5208 | return err; |
| 5209 | } |
Arend van Spriel | c4e382d | 2011-10-12 20:51:21 +0200 | [diff] [blame] | 5210 | assoc_info = |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5211 | (struct brcmf_cfg80211_assoc_ielen_le *)cfg->extra_buf; |
Arend van Spriel | c4e382d | 2011-10-12 20:51:21 +0200 | [diff] [blame] | 5212 | req_len = le32_to_cpu(assoc_info->req_len); |
| 5213 | resp_len = le32_to_cpu(assoc_info->resp_len); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5214 | if (req_len) { |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 5215 | err = brcmf_fil_iovar_data_get(ifp, "assoc_req_ies", |
Hante Meuleman | 81f5dcb | 2012-10-22 10:36:14 -0700 | [diff] [blame] | 5216 | cfg->extra_buf, |
| 5217 | WL_ASSOC_INFO_MAX); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5218 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 5219 | brcmf_err("could not get assoc req (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5220 | return err; |
| 5221 | } |
| 5222 | conn_info->req_ie_len = req_len; |
| 5223 | conn_info->req_ie = |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5224 | kmemdup(cfg->extra_buf, conn_info->req_ie_len, |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5225 | GFP_KERNEL); |
| 5226 | } else { |
| 5227 | conn_info->req_ie_len = 0; |
| 5228 | conn_info->req_ie = NULL; |
| 5229 | } |
| 5230 | if (resp_len) { |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 5231 | err = brcmf_fil_iovar_data_get(ifp, "assoc_resp_ies", |
Hante Meuleman | 81f5dcb | 2012-10-22 10:36:14 -0700 | [diff] [blame] | 5232 | cfg->extra_buf, |
| 5233 | WL_ASSOC_INFO_MAX); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5234 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 5235 | brcmf_err("could not get assoc resp (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5236 | return err; |
| 5237 | } |
| 5238 | conn_info->resp_ie_len = resp_len; |
| 5239 | conn_info->resp_ie = |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5240 | kmemdup(cfg->extra_buf, conn_info->resp_ie_len, |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5241 | GFP_KERNEL); |
| 5242 | } else { |
| 5243 | conn_info->resp_ie_len = 0; |
| 5244 | conn_info->resp_ie = NULL; |
| 5245 | } |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 5246 | brcmf_dbg(CONN, "req len (%d) resp len (%d)\n", |
| 5247 | conn_info->req_ie_len, conn_info->resp_ie_len); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5248 | |
| 5249 | return err; |
| 5250 | } |
| 5251 | |
| 5252 | static s32 |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5253 | brcmf_bss_roaming_done(struct brcmf_cfg80211_info *cfg, |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5254 | struct net_device *ndev, |
| 5255 | const struct brcmf_event_msg *e) |
| 5256 | { |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 5257 | struct brcmf_if *ifp = netdev_priv(ndev); |
| 5258 | struct brcmf_cfg80211_profile *profile = &ifp->vif->profile; |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5259 | struct brcmf_cfg80211_connect_info *conn_info = cfg_to_conn(cfg); |
| 5260 | struct wiphy *wiphy = cfg_to_wiphy(cfg); |
Franky Lin | a180b83 | 2012-10-10 11:13:09 -0700 | [diff] [blame] | 5261 | struct ieee80211_channel *notify_channel = NULL; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5262 | struct ieee80211_supported_band *band; |
Franky Lin | a180b83 | 2012-10-10 11:13:09 -0700 | [diff] [blame] | 5263 | struct brcmf_bss_info_le *bi; |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 5264 | struct brcmu_chan ch; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5265 | u32 freq; |
| 5266 | s32 err = 0; |
Franky Lin | a180b83 | 2012-10-10 11:13:09 -0700 | [diff] [blame] | 5267 | u8 *buf; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5268 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 5269 | brcmf_dbg(TRACE, "Enter\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5270 | |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 5271 | brcmf_get_assoc_ies(cfg, ifp); |
Arend van Spriel | 6c8c4f7 | 2012-09-27 14:17:57 +0200 | [diff] [blame] | 5272 | memcpy(profile->bssid, e->addr, ETH_ALEN); |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 5273 | brcmf_update_bss_info(cfg, ifp); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5274 | |
Franky Lin | a180b83 | 2012-10-10 11:13:09 -0700 | [diff] [blame] | 5275 | buf = kzalloc(WL_BSS_INFO_MAX, GFP_KERNEL); |
| 5276 | if (buf == NULL) { |
| 5277 | err = -ENOMEM; |
| 5278 | goto done; |
| 5279 | } |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5280 | |
Franky Lin | a180b83 | 2012-10-10 11:13:09 -0700 | [diff] [blame] | 5281 | /* data sent to dongle has to be little endian */ |
| 5282 | *(__le32 *)buf = cpu_to_le32(WL_BSS_INFO_MAX); |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 5283 | 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] | 5284 | buf, WL_BSS_INFO_MAX); |
Franky Lin | a180b83 | 2012-10-10 11:13:09 -0700 | [diff] [blame] | 5285 | |
| 5286 | if (err) |
| 5287 | goto done; |
| 5288 | |
| 5289 | bi = (struct brcmf_bss_info_le *)(buf + 4); |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 5290 | ch.chspec = le16_to_cpu(bi->chanspec); |
| 5291 | cfg->d11inf.decchspec(&ch); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5292 | |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 5293 | if (ch.band == BRCMU_CHAN_BAND_2G) |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 5294 | band = wiphy->bands[NL80211_BAND_2GHZ]; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5295 | else |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 5296 | band = wiphy->bands[NL80211_BAND_5GHZ]; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5297 | |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 5298 | freq = ieee80211_channel_to_frequency(ch.chnum, band->band); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5299 | notify_channel = ieee80211_get_channel(wiphy, freq); |
| 5300 | |
Franky Lin | a180b83 | 2012-10-10 11:13:09 -0700 | [diff] [blame] | 5301 | done: |
| 5302 | kfree(buf); |
Arend van Spriel | 06bb123 | 2012-09-27 14:17:56 +0200 | [diff] [blame] | 5303 | cfg80211_roamed(ndev, notify_channel, (u8 *)profile->bssid, |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5304 | conn_info->req_ie, conn_info->req_ie_len, |
| 5305 | conn_info->resp_ie, conn_info->resp_ie_len, GFP_KERNEL); |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 5306 | brcmf_dbg(CONN, "Report roaming result\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5307 | |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 5308 | set_bit(BRCMF_VIF_STATUS_CONNECTED, &ifp->vif->sme_state); |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 5309 | brcmf_dbg(TRACE, "Exit\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5310 | return err; |
| 5311 | } |
| 5312 | |
| 5313 | static s32 |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5314 | brcmf_bss_connect_done(struct brcmf_cfg80211_info *cfg, |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5315 | struct net_device *ndev, const struct brcmf_event_msg *e, |
| 5316 | bool completed) |
| 5317 | { |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 5318 | struct brcmf_if *ifp = netdev_priv(ndev); |
| 5319 | struct brcmf_cfg80211_profile *profile = &ifp->vif->profile; |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5320 | struct brcmf_cfg80211_connect_info *conn_info = cfg_to_conn(cfg); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5321 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 5322 | brcmf_dbg(TRACE, "Enter\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5323 | |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 5324 | if (test_and_clear_bit(BRCMF_VIF_STATUS_CONNECTING, |
| 5325 | &ifp->vif->sme_state)) { |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5326 | if (completed) { |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 5327 | brcmf_get_assoc_ies(cfg, ifp); |
Arend van Spriel | 6c8c4f7 | 2012-09-27 14:17:57 +0200 | [diff] [blame] | 5328 | memcpy(profile->bssid, e->addr, ETH_ALEN); |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 5329 | brcmf_update_bss_info(cfg, ifp); |
| 5330 | set_bit(BRCMF_VIF_STATUS_CONNECTED, |
| 5331 | &ifp->vif->sme_state); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5332 | } |
| 5333 | cfg80211_connect_result(ndev, |
Arend van Spriel | 06bb123 | 2012-09-27 14:17:56 +0200 | [diff] [blame] | 5334 | (u8 *)profile->bssid, |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5335 | conn_info->req_ie, |
| 5336 | conn_info->req_ie_len, |
| 5337 | conn_info->resp_ie, |
| 5338 | conn_info->resp_ie_len, |
| 5339 | completed ? WLAN_STATUS_SUCCESS : |
| 5340 | WLAN_STATUS_AUTH_TIMEOUT, |
| 5341 | GFP_KERNEL); |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 5342 | brcmf_dbg(CONN, "Report connect result - connection %s\n", |
| 5343 | completed ? "succeeded" : "failed"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5344 | } |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 5345 | brcmf_dbg(TRACE, "Exit\n"); |
Peter Senna Tschudin | 12f3237 | 2014-05-31 10:14:06 -0300 | [diff] [blame] | 5346 | return 0; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5347 | } |
| 5348 | |
| 5349 | static s32 |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5350 | brcmf_notify_connect_status_ap(struct brcmf_cfg80211_info *cfg, |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 5351 | struct net_device *ndev, |
| 5352 | const struct brcmf_event_msg *e, void *data) |
| 5353 | { |
Hante Meuleman | a44aa40 | 2014-12-03 21:05:33 +0100 | [diff] [blame] | 5354 | struct brcmf_if *ifp = netdev_priv(ndev); |
Hante Meuleman | 7ee2960 | 2013-02-06 18:40:43 +0100 | [diff] [blame] | 5355 | static int generation; |
Arend van Spriel | 5c36b99 | 2012-11-14 18:46:05 -0800 | [diff] [blame] | 5356 | u32 event = e->event_code; |
| 5357 | u32 reason = e->reason; |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 5358 | struct station_info sinfo; |
| 5359 | |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 5360 | brcmf_dbg(CONN, "event %d, reason %d\n", event, reason); |
Arend van Spriel | 5f4f9f1 | 2013-02-08 15:53:41 +0100 | [diff] [blame] | 5361 | if (event == BRCMF_E_LINK && reason == BRCMF_E_REASON_LINK_BSSCFG_DIS && |
| 5362 | ndev != cfg_to_ndev(cfg)) { |
| 5363 | brcmf_dbg(CONN, "AP mode link down\n"); |
| 5364 | complete(&cfg->vif_disabled); |
Hante Meuleman | a44aa40 | 2014-12-03 21:05:33 +0100 | [diff] [blame] | 5365 | if (ifp->vif->mbss) |
Arend van Spriel | ee6e3a3 | 2015-08-26 22:14:55 +0200 | [diff] [blame] | 5366 | brcmf_remove_interface(ifp); |
Arend van Spriel | 5f4f9f1 | 2013-02-08 15:53:41 +0100 | [diff] [blame] | 5367 | return 0; |
| 5368 | } |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 5369 | |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 5370 | if (((event == BRCMF_E_ASSOC_IND) || (event == BRCMF_E_REASSOC_IND)) && |
Hante Meuleman | 7ee2960 | 2013-02-06 18:40:43 +0100 | [diff] [blame] | 5371 | (reason == BRCMF_E_STATUS_SUCCESS)) { |
| 5372 | memset(&sinfo, 0, sizeof(sinfo)); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 5373 | if (!data) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 5374 | brcmf_err("No IEs present in ASSOC/REASSOC_IND"); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 5375 | return -EINVAL; |
| 5376 | } |
| 5377 | sinfo.assoc_req_ies = data; |
Hante Meuleman | 7ee2960 | 2013-02-06 18:40:43 +0100 | [diff] [blame] | 5378 | sinfo.assoc_req_ies_len = e->datalen; |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 5379 | generation++; |
| 5380 | sinfo.generation = generation; |
Hante Meuleman | 7ee2960 | 2013-02-06 18:40:43 +0100 | [diff] [blame] | 5381 | cfg80211_new_sta(ndev, e->addr, &sinfo, GFP_KERNEL); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 5382 | } else if ((event == BRCMF_E_DISASSOC_IND) || |
| 5383 | (event == BRCMF_E_DEAUTH_IND) || |
| 5384 | (event == BRCMF_E_DEAUTH)) { |
Hante Meuleman | 7ee2960 | 2013-02-06 18:40:43 +0100 | [diff] [blame] | 5385 | cfg80211_del_sta(ndev, e->addr, GFP_KERNEL); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 5386 | } |
Hante Meuleman | 7ee2960 | 2013-02-06 18:40:43 +0100 | [diff] [blame] | 5387 | return 0; |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 5388 | } |
| 5389 | |
| 5390 | static s32 |
Arend van Spriel | 1993732 | 2012-11-05 16:22:32 -0800 | [diff] [blame] | 5391 | brcmf_notify_connect_status(struct brcmf_if *ifp, |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5392 | const struct brcmf_event_msg *e, void *data) |
| 5393 | { |
Arend van Spriel | 1993732 | 2012-11-05 16:22:32 -0800 | [diff] [blame] | 5394 | struct brcmf_cfg80211_info *cfg = ifp->drvr->config; |
| 5395 | struct net_device *ndev = ifp->ndev; |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 5396 | struct brcmf_cfg80211_profile *profile = &ifp->vif->profile; |
Antonio Quartulli | fe94f3a | 2014-01-29 17:53:43 +0100 | [diff] [blame] | 5397 | struct ieee80211_channel *chan; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5398 | s32 err = 0; |
| 5399 | |
Hante Meuleman | 8851cce | 2014-07-30 13:20:02 +0200 | [diff] [blame] | 5400 | if ((e->event_code == BRCMF_E_DEAUTH) || |
| 5401 | (e->event_code == BRCMF_E_DEAUTH_IND) || |
| 5402 | (e->event_code == BRCMF_E_DISASSOC_IND) || |
| 5403 | ((e->event_code == BRCMF_E_LINK) && (!e->flags))) { |
| 5404 | brcmf_proto_delete_peer(ifp->drvr, ifp->ifidx, (u8 *)e->addr); |
| 5405 | } |
| 5406 | |
Arend van Spriel | 967fe2c | 2014-03-15 17:18:21 +0100 | [diff] [blame] | 5407 | if (brcmf_is_apmode(ifp->vif)) { |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5408 | err = brcmf_notify_connect_status_ap(cfg, ndev, e, data); |
Arend van Spriel | 903e0ee | 2012-11-28 21:44:11 +0100 | [diff] [blame] | 5409 | } else if (brcmf_is_linkup(e)) { |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 5410 | brcmf_dbg(CONN, "Linkup\n"); |
Arend van Spriel | 128ce3b | 2012-11-28 21:44:12 +0100 | [diff] [blame] | 5411 | if (brcmf_is_ibssmode(ifp->vif)) { |
Hante Meuleman | b0a7908 | 2015-12-10 13:43:07 +0100 | [diff] [blame] | 5412 | brcmf_inform_ibss(cfg, ndev, e->addr); |
Antonio Quartulli | fe94f3a | 2014-01-29 17:53:43 +0100 | [diff] [blame] | 5413 | chan = ieee80211_get_channel(cfg->wiphy, cfg->channel); |
Arend van Spriel | 6c8c4f7 | 2012-09-27 14:17:57 +0200 | [diff] [blame] | 5414 | memcpy(profile->bssid, e->addr, ETH_ALEN); |
Antonio Quartulli | fe94f3a | 2014-01-29 17:53:43 +0100 | [diff] [blame] | 5415 | cfg80211_ibss_joined(ndev, e->addr, chan, GFP_KERNEL); |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 5416 | clear_bit(BRCMF_VIF_STATUS_CONNECTING, |
| 5417 | &ifp->vif->sme_state); |
| 5418 | set_bit(BRCMF_VIF_STATUS_CONNECTED, |
| 5419 | &ifp->vif->sme_state); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5420 | } else |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5421 | brcmf_bss_connect_done(cfg, ndev, e, true); |
Hante Meuleman | 92121e6 | 2015-10-08 20:33:21 +0200 | [diff] [blame] | 5422 | brcmf_net_setcarrier(ifp, true); |
Arend van Spriel | 903e0ee | 2012-11-28 21:44:11 +0100 | [diff] [blame] | 5423 | } else if (brcmf_is_linkdown(e)) { |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 5424 | brcmf_dbg(CONN, "Linkdown\n"); |
Arend van Spriel | 128ce3b | 2012-11-28 21:44:12 +0100 | [diff] [blame] | 5425 | if (!brcmf_is_ibssmode(ifp->vif)) { |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5426 | brcmf_bss_connect_done(cfg, ndev, e, false); |
Hante Meuleman | 42e0ed0 | 2016-01-05 11:05:50 +0100 | [diff] [blame] | 5427 | brcmf_link_down(ifp->vif, |
| 5428 | brcmf_map_fw_linkdown_reason(e)); |
| 5429 | brcmf_init_prof(ndev_to_prof(ndev)); |
| 5430 | if (ndev != cfg_to_ndev(cfg)) |
| 5431 | complete(&cfg->vif_disabled); |
| 5432 | brcmf_net_setcarrier(ifp, false); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5433 | } |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5434 | } else if (brcmf_is_nonetwork(cfg, e)) { |
Arend van Spriel | 128ce3b | 2012-11-28 21:44:12 +0100 | [diff] [blame] | 5435 | if (brcmf_is_ibssmode(ifp->vif)) |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 5436 | clear_bit(BRCMF_VIF_STATUS_CONNECTING, |
| 5437 | &ifp->vif->sme_state); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5438 | else |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5439 | brcmf_bss_connect_done(cfg, ndev, e, false); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5440 | } |
| 5441 | |
| 5442 | return err; |
| 5443 | } |
| 5444 | |
| 5445 | static s32 |
Arend van Spriel | 1993732 | 2012-11-05 16:22:32 -0800 | [diff] [blame] | 5446 | brcmf_notify_roaming_status(struct brcmf_if *ifp, |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5447 | const struct brcmf_event_msg *e, void *data) |
| 5448 | { |
Arend van Spriel | 1993732 | 2012-11-05 16:22:32 -0800 | [diff] [blame] | 5449 | struct brcmf_cfg80211_info *cfg = ifp->drvr->config; |
Arend van Spriel | 5c36b99 | 2012-11-14 18:46:05 -0800 | [diff] [blame] | 5450 | u32 event = e->event_code; |
| 5451 | u32 status = e->status; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5452 | |
| 5453 | if (event == BRCMF_E_ROAM && status == BRCMF_E_STATUS_SUCCESS) { |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 5454 | if (test_bit(BRCMF_VIF_STATUS_CONNECTED, &ifp->vif->sme_state)) |
Arend van Spriel | 1993732 | 2012-11-05 16:22:32 -0800 | [diff] [blame] | 5455 | brcmf_bss_roaming_done(cfg, ifp->ndev, e); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5456 | else |
Arend van Spriel | 1993732 | 2012-11-05 16:22:32 -0800 | [diff] [blame] | 5457 | brcmf_bss_connect_done(cfg, ifp->ndev, e, true); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5458 | } |
| 5459 | |
Peter Senna Tschudin | 12f3237 | 2014-05-31 10:14:06 -0300 | [diff] [blame] | 5460 | return 0; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5461 | } |
| 5462 | |
| 5463 | static s32 |
Arend van Spriel | 1993732 | 2012-11-05 16:22:32 -0800 | [diff] [blame] | 5464 | brcmf_notify_mic_status(struct brcmf_if *ifp, |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5465 | const struct brcmf_event_msg *e, void *data) |
| 5466 | { |
Arend van Spriel | 5c36b99 | 2012-11-14 18:46:05 -0800 | [diff] [blame] | 5467 | u16 flags = e->flags; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5468 | enum nl80211_key_type key_type; |
| 5469 | |
| 5470 | if (flags & BRCMF_EVENT_MSG_GROUP) |
| 5471 | key_type = NL80211_KEYTYPE_GROUP; |
| 5472 | else |
| 5473 | key_type = NL80211_KEYTYPE_PAIRWISE; |
| 5474 | |
Arend van Spriel | 1993732 | 2012-11-05 16:22:32 -0800 | [diff] [blame] | 5475 | 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] | 5476 | NULL, GFP_KERNEL); |
| 5477 | |
| 5478 | return 0; |
| 5479 | } |
| 5480 | |
Arend van Spriel | d3c0b63 | 2013-02-08 15:53:37 +0100 | [diff] [blame] | 5481 | static s32 brcmf_notify_vif_event(struct brcmf_if *ifp, |
| 5482 | const struct brcmf_event_msg *e, void *data) |
| 5483 | { |
| 5484 | struct brcmf_cfg80211_info *cfg = ifp->drvr->config; |
| 5485 | struct brcmf_if_event *ifevent = (struct brcmf_if_event *)data; |
| 5486 | struct brcmf_cfg80211_vif_event *event = &cfg->vif_event; |
| 5487 | struct brcmf_cfg80211_vif *vif; |
| 5488 | |
Hante Meuleman | 37a869e | 2015-10-29 20:33:17 +0100 | [diff] [blame] | 5489 | 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] | 5490 | ifevent->action, ifevent->flags, ifevent->ifidx, |
Hante Meuleman | 37a869e | 2015-10-29 20:33:17 +0100 | [diff] [blame] | 5491 | ifevent->bsscfgidx); |
Arend van Spriel | d3c0b63 | 2013-02-08 15:53:37 +0100 | [diff] [blame] | 5492 | |
Arend van Spriel | d3c0b63 | 2013-02-08 15:53:37 +0100 | [diff] [blame] | 5493 | mutex_lock(&event->vif_event_lock); |
| 5494 | event->action = ifevent->action; |
| 5495 | vif = event->vif; |
| 5496 | |
| 5497 | switch (ifevent->action) { |
| 5498 | case BRCMF_E_IF_ADD: |
| 5499 | /* waiting process may have timed out */ |
Wei Yongjun | dc4a787 | 2013-02-22 21:32:20 +0800 | [diff] [blame] | 5500 | if (!cfg->vif_event.vif) { |
| 5501 | mutex_unlock(&event->vif_event_lock); |
Arend van Spriel | d3c0b63 | 2013-02-08 15:53:37 +0100 | [diff] [blame] | 5502 | return -EBADF; |
Wei Yongjun | dc4a787 | 2013-02-22 21:32:20 +0800 | [diff] [blame] | 5503 | } |
Arend van Spriel | d3c0b63 | 2013-02-08 15:53:37 +0100 | [diff] [blame] | 5504 | |
| 5505 | ifp->vif = vif; |
| 5506 | vif->ifp = ifp; |
Arend van Spriel | 01b8e7d | 2013-04-05 10:57:51 +0200 | [diff] [blame] | 5507 | if (ifp->ndev) { |
| 5508 | vif->wdev.netdev = ifp->ndev; |
| 5509 | ifp->ndev->ieee80211_ptr = &vif->wdev; |
| 5510 | SET_NETDEV_DEV(ifp->ndev, wiphy_dev(cfg->wiphy)); |
| 5511 | } |
Arend van Spriel | d3c0b63 | 2013-02-08 15:53:37 +0100 | [diff] [blame] | 5512 | mutex_unlock(&event->vif_event_lock); |
| 5513 | wake_up(&event->vif_wq); |
Hante Meuleman | 4b3a89d | 2013-02-08 15:54:01 +0100 | [diff] [blame] | 5514 | return 0; |
Arend van Spriel | d3c0b63 | 2013-02-08 15:53:37 +0100 | [diff] [blame] | 5515 | |
| 5516 | case BRCMF_E_IF_DEL: |
Arend van Spriel | d3c0b63 | 2013-02-08 15:53:37 +0100 | [diff] [blame] | 5517 | mutex_unlock(&event->vif_event_lock); |
| 5518 | /* event may not be upon user request */ |
| 5519 | if (brcmf_cfg80211_vif_event_armed(cfg)) |
| 5520 | wake_up(&event->vif_wq); |
| 5521 | return 0; |
| 5522 | |
Hante Meuleman | 7a5c1f6 | 2013-02-08 15:53:44 +0100 | [diff] [blame] | 5523 | case BRCMF_E_IF_CHANGE: |
| 5524 | mutex_unlock(&event->vif_event_lock); |
| 5525 | wake_up(&event->vif_wq); |
| 5526 | return 0; |
| 5527 | |
Arend van Spriel | d3c0b63 | 2013-02-08 15:53:37 +0100 | [diff] [blame] | 5528 | default: |
| 5529 | mutex_unlock(&event->vif_event_lock); |
| 5530 | break; |
| 5531 | } |
| 5532 | return -EINVAL; |
| 5533 | } |
| 5534 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5535 | static void brcmf_init_conf(struct brcmf_cfg80211_conf *conf) |
| 5536 | { |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5537 | conf->frag_threshold = (u32)-1; |
| 5538 | conf->rts_threshold = (u32)-1; |
| 5539 | conf->retry_short = (u32)-1; |
| 5540 | conf->retry_long = (u32)-1; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5541 | } |
| 5542 | |
Arend van Spriel | 5c36b99 | 2012-11-14 18:46:05 -0800 | [diff] [blame] | 5543 | static void brcmf_register_event_handlers(struct brcmf_cfg80211_info *cfg) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5544 | { |
Arend van Spriel | 5c36b99 | 2012-11-14 18:46:05 -0800 | [diff] [blame] | 5545 | brcmf_fweh_register(cfg->pub, BRCMF_E_LINK, |
| 5546 | brcmf_notify_connect_status); |
| 5547 | brcmf_fweh_register(cfg->pub, BRCMF_E_DEAUTH_IND, |
| 5548 | brcmf_notify_connect_status); |
| 5549 | brcmf_fweh_register(cfg->pub, BRCMF_E_DEAUTH, |
| 5550 | brcmf_notify_connect_status); |
| 5551 | brcmf_fweh_register(cfg->pub, BRCMF_E_DISASSOC_IND, |
| 5552 | brcmf_notify_connect_status); |
| 5553 | brcmf_fweh_register(cfg->pub, BRCMF_E_ASSOC_IND, |
| 5554 | brcmf_notify_connect_status); |
| 5555 | brcmf_fweh_register(cfg->pub, BRCMF_E_REASSOC_IND, |
| 5556 | brcmf_notify_connect_status); |
| 5557 | brcmf_fweh_register(cfg->pub, BRCMF_E_ROAM, |
| 5558 | brcmf_notify_roaming_status); |
| 5559 | brcmf_fweh_register(cfg->pub, BRCMF_E_MIC_ERROR, |
| 5560 | brcmf_notify_mic_status); |
| 5561 | brcmf_fweh_register(cfg->pub, BRCMF_E_SET_SSID, |
| 5562 | brcmf_notify_connect_status); |
| 5563 | brcmf_fweh_register(cfg->pub, BRCMF_E_PFN_NET_FOUND, |
| 5564 | brcmf_notify_sched_scan_results); |
Arend van Spriel | d3c0b63 | 2013-02-08 15:53:37 +0100 | [diff] [blame] | 5565 | brcmf_fweh_register(cfg->pub, BRCMF_E_IF, |
| 5566 | brcmf_notify_vif_event); |
Hante Meuleman | 0de8aac | 2013-02-08 15:53:38 +0100 | [diff] [blame] | 5567 | brcmf_fweh_register(cfg->pub, BRCMF_E_P2P_PROBEREQ_MSG, |
Hante Meuleman | 6eda4e2 | 2013-02-08 15:54:02 +0100 | [diff] [blame] | 5568 | brcmf_p2p_notify_rx_mgmt_p2p_probereq); |
Hante Meuleman | 0de8aac | 2013-02-08 15:53:38 +0100 | [diff] [blame] | 5569 | brcmf_fweh_register(cfg->pub, BRCMF_E_P2P_DISC_LISTEN_COMPLETE, |
| 5570 | brcmf_p2p_notify_listen_complete); |
Hante Meuleman | e6da340 | 2013-02-08 15:53:48 +0100 | [diff] [blame] | 5571 | brcmf_fweh_register(cfg->pub, BRCMF_E_ACTION_FRAME_RX, |
| 5572 | brcmf_p2p_notify_action_frame_rx); |
Hante Meuleman | 18e2f61 | 2013-02-08 15:53:49 +0100 | [diff] [blame] | 5573 | brcmf_fweh_register(cfg->pub, BRCMF_E_ACTION_FRAME_COMPLETE, |
| 5574 | brcmf_p2p_notify_action_tx_complete); |
Hante Meuleman | 6eda4e2 | 2013-02-08 15:54:02 +0100 | [diff] [blame] | 5575 | brcmf_fweh_register(cfg->pub, BRCMF_E_ACTION_FRAME_OFF_CHAN_COMPLETE, |
| 5576 | brcmf_p2p_notify_action_tx_complete); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5577 | } |
| 5578 | |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5579 | static void brcmf_deinit_priv_mem(struct brcmf_cfg80211_info *cfg) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5580 | { |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5581 | kfree(cfg->conf); |
| 5582 | cfg->conf = NULL; |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5583 | kfree(cfg->extra_buf); |
| 5584 | cfg->extra_buf = NULL; |
Hante Meuleman | 3021ad9 | 2016-01-05 11:05:45 +0100 | [diff] [blame] | 5585 | kfree(cfg->wowl.nd); |
| 5586 | cfg->wowl.nd = NULL; |
| 5587 | kfree(cfg->wowl.nd_info); |
| 5588 | cfg->wowl.nd_info = NULL; |
Hante Meuleman | d536733 | 2016-02-17 11:26:51 +0100 | [diff] [blame] | 5589 | kfree(cfg->escan_info.escan_buf); |
| 5590 | cfg->escan_info.escan_buf = NULL; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5591 | } |
| 5592 | |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5593 | static s32 brcmf_init_priv_mem(struct brcmf_cfg80211_info *cfg) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5594 | { |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5595 | cfg->conf = kzalloc(sizeof(*cfg->conf), GFP_KERNEL); |
| 5596 | if (!cfg->conf) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5597 | goto init_priv_mem_out; |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5598 | cfg->extra_buf = kzalloc(WL_EXTRA_BUF_MAX, GFP_KERNEL); |
| 5599 | if (!cfg->extra_buf) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5600 | goto init_priv_mem_out; |
Hante Meuleman | 3021ad9 | 2016-01-05 11:05:45 +0100 | [diff] [blame] | 5601 | cfg->wowl.nd = kzalloc(sizeof(*cfg->wowl.nd) + sizeof(u32), GFP_KERNEL); |
| 5602 | if (!cfg->wowl.nd) |
| 5603 | goto init_priv_mem_out; |
| 5604 | cfg->wowl.nd_info = kzalloc(sizeof(*cfg->wowl.nd_info) + |
| 5605 | sizeof(struct cfg80211_wowlan_nd_match *), |
| 5606 | GFP_KERNEL); |
| 5607 | if (!cfg->wowl.nd_info) |
| 5608 | goto init_priv_mem_out; |
Hante Meuleman | d536733 | 2016-02-17 11:26:51 +0100 | [diff] [blame] | 5609 | cfg->escan_info.escan_buf = kzalloc(BRCMF_ESCAN_BUF_SIZE, GFP_KERNEL); |
| 5610 | if (!cfg->escan_info.escan_buf) |
| 5611 | goto init_priv_mem_out; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5612 | |
| 5613 | return 0; |
| 5614 | |
| 5615 | init_priv_mem_out: |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5616 | brcmf_deinit_priv_mem(cfg); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5617 | |
| 5618 | return -ENOMEM; |
| 5619 | } |
| 5620 | |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5621 | static s32 wl_init_priv(struct brcmf_cfg80211_info *cfg) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5622 | { |
| 5623 | s32 err = 0; |
| 5624 | |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5625 | cfg->scan_request = NULL; |
| 5626 | cfg->pwr_save = true; |
Hante Meuleman | 68ca395 | 2014-02-25 20:30:26 +0100 | [diff] [blame] | 5627 | cfg->active_scan = true; /* we do active scan per default */ |
| 5628 | cfg->dongle_up = false; /* dongle is not up yet */ |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5629 | err = brcmf_init_priv_mem(cfg); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5630 | if (err) |
| 5631 | return err; |
Arend van Spriel | 5c36b99 | 2012-11-14 18:46:05 -0800 | [diff] [blame] | 5632 | brcmf_register_event_handlers(cfg); |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5633 | mutex_init(&cfg->usr_sync); |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5634 | brcmf_init_escan(cfg); |
| 5635 | brcmf_init_conf(cfg->conf); |
Arend van Spriel | 5f4f9f1 | 2013-02-08 15:53:41 +0100 | [diff] [blame] | 5636 | init_completion(&cfg->vif_disabled); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5637 | return err; |
| 5638 | } |
| 5639 | |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5640 | static void wl_deinit_priv(struct brcmf_cfg80211_info *cfg) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5641 | { |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5642 | cfg->dongle_up = false; /* dongle down */ |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5643 | brcmf_abort_scanning(cfg); |
| 5644 | brcmf_deinit_priv_mem(cfg); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5645 | } |
| 5646 | |
Arend van Spriel | d3c0b63 | 2013-02-08 15:53:37 +0100 | [diff] [blame] | 5647 | static void init_vif_event(struct brcmf_cfg80211_vif_event *event) |
| 5648 | { |
| 5649 | init_waitqueue_head(&event->vif_wq); |
Arend van Spriel | d3c0b63 | 2013-02-08 15:53:37 +0100 | [diff] [blame] | 5650 | mutex_init(&event->vif_event_lock); |
| 5651 | } |
| 5652 | |
Hante Meuleman | 1119e23 | 2015-11-25 11:32:42 +0100 | [diff] [blame] | 5653 | static s32 brcmf_dongle_roam(struct brcmf_if *ifp) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5654 | { |
Hante Meuleman | 1119e23 | 2015-11-25 11:32:42 +0100 | [diff] [blame] | 5655 | s32 err; |
| 5656 | u32 bcn_timeout; |
Arend van Spriel | f588bc0 | 2011-10-12 20:51:22 +0200 | [diff] [blame] | 5657 | __le32 roamtrigger[2]; |
| 5658 | __le32 roam_delta[2]; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5659 | |
Hante Meuleman | 1119e23 | 2015-11-25 11:32:42 +0100 | [diff] [blame] | 5660 | /* Configure beacon timeout value based upon roaming setting */ |
Hante Meuleman | 7d34b05 | 2016-01-02 09:41:41 +0100 | [diff] [blame] | 5661 | if (ifp->drvr->settings->roamoff) |
Hante Meuleman | 1119e23 | 2015-11-25 11:32:42 +0100 | [diff] [blame] | 5662 | bcn_timeout = BRCMF_DEFAULT_BCN_TIMEOUT_ROAM_OFF; |
| 5663 | else |
| 5664 | bcn_timeout = BRCMF_DEFAULT_BCN_TIMEOUT_ROAM_ON; |
| 5665 | err = brcmf_fil_iovar_int_set(ifp, "bcn_timeout", bcn_timeout); |
| 5666 | if (err) { |
| 5667 | brcmf_err("bcn_timeout error (%d)\n", err); |
| 5668 | goto roam_setup_done; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5669 | } |
| 5670 | |
Hante Meuleman | 1119e23 | 2015-11-25 11:32:42 +0100 | [diff] [blame] | 5671 | /* Enable/Disable built-in roaming to allow supplicant to take care of |
| 5672 | * roaming. |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5673 | */ |
Hante Meuleman | 68ca395 | 2014-02-25 20:30:26 +0100 | [diff] [blame] | 5674 | brcmf_dbg(INFO, "Internal Roaming = %s\n", |
Hante Meuleman | 7d34b05 | 2016-01-02 09:41:41 +0100 | [diff] [blame] | 5675 | ifp->drvr->settings->roamoff ? "Off" : "On"); |
| 5676 | err = brcmf_fil_iovar_int_set(ifp, "roam_off", |
| 5677 | ifp->drvr->settings->roamoff); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5678 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 5679 | brcmf_err("roam_off error (%d)\n", err); |
Hante Meuleman | 1119e23 | 2015-11-25 11:32:42 +0100 | [diff] [blame] | 5680 | goto roam_setup_done; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5681 | } |
| 5682 | |
Arend van Spriel | f588bc0 | 2011-10-12 20:51:22 +0200 | [diff] [blame] | 5683 | roamtrigger[0] = cpu_to_le32(WL_ROAM_TRIGGER_LEVEL); |
| 5684 | roamtrigger[1] = cpu_to_le32(BRCM_BAND_ALL); |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 5685 | err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SET_ROAM_TRIGGER, |
Hante Meuleman | 81f5dcb | 2012-10-22 10:36:14 -0700 | [diff] [blame] | 5686 | (void *)roamtrigger, sizeof(roamtrigger)); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5687 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 5688 | brcmf_err("WLC_SET_ROAM_TRIGGER error (%d)\n", err); |
Hante Meuleman | 1119e23 | 2015-11-25 11:32:42 +0100 | [diff] [blame] | 5689 | goto roam_setup_done; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5690 | } |
| 5691 | |
Arend van Spriel | f588bc0 | 2011-10-12 20:51:22 +0200 | [diff] [blame] | 5692 | roam_delta[0] = cpu_to_le32(WL_ROAM_DELTA); |
| 5693 | roam_delta[1] = cpu_to_le32(BRCM_BAND_ALL); |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 5694 | err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SET_ROAM_DELTA, |
Hante Meuleman | 81f5dcb | 2012-10-22 10:36:14 -0700 | [diff] [blame] | 5695 | (void *)roam_delta, sizeof(roam_delta)); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5696 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 5697 | brcmf_err("WLC_SET_ROAM_DELTA error (%d)\n", err); |
Hante Meuleman | 1119e23 | 2015-11-25 11:32:42 +0100 | [diff] [blame] | 5698 | goto roam_setup_done; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5699 | } |
| 5700 | |
Hante Meuleman | 1119e23 | 2015-11-25 11:32:42 +0100 | [diff] [blame] | 5701 | roam_setup_done: |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5702 | return err; |
| 5703 | } |
| 5704 | |
| 5705 | static s32 |
Hante Meuleman | 1678ba8 | 2015-12-10 13:43:00 +0100 | [diff] [blame] | 5706 | brcmf_dongle_scantime(struct brcmf_if *ifp) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5707 | { |
| 5708 | s32 err = 0; |
| 5709 | |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 5710 | 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] | 5711 | BRCMF_SCAN_CHANNEL_TIME); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5712 | if (err) { |
Hante Meuleman | 1678ba8 | 2015-12-10 13:43:00 +0100 | [diff] [blame] | 5713 | brcmf_err("Scan assoc time error (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5714 | goto dongle_scantime_out; |
| 5715 | } |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 5716 | 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] | 5717 | BRCMF_SCAN_UNASSOC_TIME); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5718 | if (err) { |
Hante Meuleman | 1678ba8 | 2015-12-10 13:43:00 +0100 | [diff] [blame] | 5719 | brcmf_err("Scan unassoc time error (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5720 | goto dongle_scantime_out; |
| 5721 | } |
| 5722 | |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 5723 | 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] | 5724 | BRCMF_SCAN_PASSIVE_TIME); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5725 | if (err) { |
Hante Meuleman | 1678ba8 | 2015-12-10 13:43:00 +0100 | [diff] [blame] | 5726 | brcmf_err("Scan passive time error (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5727 | goto dongle_scantime_out; |
| 5728 | } |
| 5729 | |
| 5730 | dongle_scantime_out: |
| 5731 | return err; |
| 5732 | } |
| 5733 | |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 5734 | static void brcmf_update_bw40_channel_flag(struct ieee80211_channel *channel, |
| 5735 | struct brcmu_chan *ch) |
| 5736 | { |
| 5737 | u32 ht40_flag; |
| 5738 | |
| 5739 | ht40_flag = channel->flags & IEEE80211_CHAN_NO_HT40; |
| 5740 | if (ch->sb == BRCMU_CHAN_SB_U) { |
| 5741 | if (ht40_flag == IEEE80211_CHAN_NO_HT40) |
| 5742 | channel->flags &= ~IEEE80211_CHAN_NO_HT40; |
| 5743 | channel->flags |= IEEE80211_CHAN_NO_HT40PLUS; |
| 5744 | } else { |
| 5745 | /* It should be one of |
| 5746 | * IEEE80211_CHAN_NO_HT40 or |
| 5747 | * IEEE80211_CHAN_NO_HT40PLUS |
| 5748 | */ |
| 5749 | channel->flags &= ~IEEE80211_CHAN_NO_HT40; |
| 5750 | if (ht40_flag == IEEE80211_CHAN_NO_HT40) |
| 5751 | channel->flags |= IEEE80211_CHAN_NO_HT40MINUS; |
| 5752 | } |
| 5753 | } |
| 5754 | |
| 5755 | static int brcmf_construct_chaninfo(struct brcmf_cfg80211_info *cfg, |
| 5756 | u32 bw_cap[]) |
Hante Meuleman | d48200b | 2013-04-03 12:40:29 +0200 | [diff] [blame] | 5757 | { |
| 5758 | struct brcmf_if *ifp = netdev_priv(cfg_to_ndev(cfg)); |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 5759 | struct ieee80211_supported_band *band; |
| 5760 | struct ieee80211_channel *channel; |
| 5761 | struct wiphy *wiphy; |
Hante Meuleman | d48200b | 2013-04-03 12:40:29 +0200 | [diff] [blame] | 5762 | struct brcmf_chanspec_list *list; |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 5763 | struct brcmu_chan ch; |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 5764 | int err; |
Hante Meuleman | d48200b | 2013-04-03 12:40:29 +0200 | [diff] [blame] | 5765 | u8 *pbuf; |
| 5766 | u32 i, j; |
| 5767 | u32 total; |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 5768 | u32 chaninfo; |
Hante Meuleman | d48200b | 2013-04-03 12:40:29 +0200 | [diff] [blame] | 5769 | u32 index; |
Hante Meuleman | d48200b | 2013-04-03 12:40:29 +0200 | [diff] [blame] | 5770 | |
| 5771 | pbuf = kzalloc(BRCMF_DCMD_MEDLEN, GFP_KERNEL); |
| 5772 | |
| 5773 | if (pbuf == NULL) |
| 5774 | return -ENOMEM; |
| 5775 | |
| 5776 | list = (struct brcmf_chanspec_list *)pbuf; |
| 5777 | |
| 5778 | err = brcmf_fil_iovar_data_get(ifp, "chanspecs", pbuf, |
| 5779 | BRCMF_DCMD_MEDLEN); |
| 5780 | if (err) { |
| 5781 | brcmf_err("get chanspecs error (%d)\n", err); |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 5782 | goto fail_pbuf; |
Hante Meuleman | d48200b | 2013-04-03 12:40:29 +0200 | [diff] [blame] | 5783 | } |
| 5784 | |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 5785 | wiphy = cfg_to_wiphy(cfg); |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 5786 | band = wiphy->bands[NL80211_BAND_2GHZ]; |
Arend van Spriel | 58de92d | 2015-04-14 20:10:24 +0200 | [diff] [blame] | 5787 | if (band) |
| 5788 | for (i = 0; i < band->n_channels; i++) |
| 5789 | band->channels[i].flags = IEEE80211_CHAN_DISABLED; |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 5790 | band = wiphy->bands[NL80211_BAND_5GHZ]; |
Arend van Spriel | 58de92d | 2015-04-14 20:10:24 +0200 | [diff] [blame] | 5791 | if (band) |
| 5792 | for (i = 0; i < band->n_channels; i++) |
| 5793 | band->channels[i].flags = IEEE80211_CHAN_DISABLED; |
Hante Meuleman | d48200b | 2013-04-03 12:40:29 +0200 | [diff] [blame] | 5794 | |
| 5795 | total = le32_to_cpu(list->count); |
| 5796 | for (i = 0; i < total; i++) { |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 5797 | ch.chspec = (u16)le32_to_cpu(list->element[i]); |
| 5798 | cfg->d11inf.decchspec(&ch); |
Hante Meuleman | d48200b | 2013-04-03 12:40:29 +0200 | [diff] [blame] | 5799 | |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 5800 | if (ch.band == BRCMU_CHAN_BAND_2G) { |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 5801 | band = wiphy->bands[NL80211_BAND_2GHZ]; |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 5802 | } else if (ch.band == BRCMU_CHAN_BAND_5G) { |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 5803 | band = wiphy->bands[NL80211_BAND_5GHZ]; |
Hante Meuleman | d48200b | 2013-04-03 12:40:29 +0200 | [diff] [blame] | 5804 | } else { |
Arend van Spriel | 2375d97 | 2014-01-06 12:40:41 +0100 | [diff] [blame] | 5805 | brcmf_err("Invalid channel Spec. 0x%x.\n", ch.chspec); |
Hante Meuleman | d48200b | 2013-04-03 12:40:29 +0200 | [diff] [blame] | 5806 | continue; |
| 5807 | } |
Arend van Spriel | 58de92d | 2015-04-14 20:10:24 +0200 | [diff] [blame] | 5808 | if (!band) |
| 5809 | continue; |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 5810 | if (!(bw_cap[band->band] & WLC_BW_40MHZ_BIT) && |
Arend van Spriel | 2375d97 | 2014-01-06 12:40:41 +0100 | [diff] [blame] | 5811 | ch.bw == BRCMU_CHAN_BW_40) |
Hante Meuleman | d48200b | 2013-04-03 12:40:29 +0200 | [diff] [blame] | 5812 | continue; |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 5813 | if (!(bw_cap[band->band] & WLC_BW_80MHZ_BIT) && |
Arend van Spriel | ee942ec | 2014-05-12 10:47:38 +0200 | [diff] [blame] | 5814 | ch.bw == BRCMU_CHAN_BW_80) |
| 5815 | continue; |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 5816 | |
| 5817 | channel = band->channels; |
| 5818 | index = band->n_channels; |
| 5819 | for (j = 0; j < band->n_channels; j++) { |
| 5820 | if (channel[j].hw_value == ch.chnum) { |
| 5821 | index = j; |
Hante Meuleman | d48200b | 2013-04-03 12:40:29 +0200 | [diff] [blame] | 5822 | break; |
| 5823 | } |
| 5824 | } |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 5825 | channel[index].center_freq = |
| 5826 | ieee80211_channel_to_frequency(ch.chnum, band->band); |
| 5827 | channel[index].hw_value = ch.chnum; |
Hante Meuleman | d48200b | 2013-04-03 12:40:29 +0200 | [diff] [blame] | 5828 | |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 5829 | /* assuming the chanspecs order is HT20, |
| 5830 | * HT40 upper, HT40 lower, and VHT80. |
| 5831 | */ |
| 5832 | if (ch.bw == BRCMU_CHAN_BW_80) { |
| 5833 | channel[index].flags &= ~IEEE80211_CHAN_NO_80MHZ; |
| 5834 | } else if (ch.bw == BRCMU_CHAN_BW_40) { |
| 5835 | brcmf_update_bw40_channel_flag(&channel[index], &ch); |
| 5836 | } else { |
Arend van Spriel | 58de92d | 2015-04-14 20:10:24 +0200 | [diff] [blame] | 5837 | /* enable the channel and disable other bandwidths |
| 5838 | * for now as mentioned order assure they are enabled |
| 5839 | * for subsequent chanspecs. |
Arend van Spriel | ee942ec | 2014-05-12 10:47:38 +0200 | [diff] [blame] | 5840 | */ |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 5841 | channel[index].flags = IEEE80211_CHAN_NO_HT40 | |
| 5842 | IEEE80211_CHAN_NO_80MHZ; |
| 5843 | ch.bw = BRCMU_CHAN_BW_20; |
| 5844 | cfg->d11inf.encchspec(&ch); |
| 5845 | chaninfo = ch.chspec; |
| 5846 | err = brcmf_fil_bsscfg_int_get(ifp, "per_chan_info", |
| 5847 | &chaninfo); |
| 5848 | if (!err) { |
| 5849 | if (chaninfo & WL_CHAN_RADAR) |
| 5850 | channel[index].flags |= |
| 5851 | (IEEE80211_CHAN_RADAR | |
| 5852 | IEEE80211_CHAN_NO_IR); |
| 5853 | if (chaninfo & WL_CHAN_PASSIVE) |
| 5854 | channel[index].flags |= |
| 5855 | IEEE80211_CHAN_NO_IR; |
Hante Meuleman | d48200b | 2013-04-03 12:40:29 +0200 | [diff] [blame] | 5856 | } |
Hante Meuleman | d48200b | 2013-04-03 12:40:29 +0200 | [diff] [blame] | 5857 | } |
| 5858 | } |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 5859 | |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 5860 | fail_pbuf: |
Hante Meuleman | d48200b | 2013-04-03 12:40:29 +0200 | [diff] [blame] | 5861 | kfree(pbuf); |
| 5862 | return err; |
| 5863 | } |
| 5864 | |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 5865 | static int brcmf_enable_bw40_2g(struct brcmf_cfg80211_info *cfg) |
Arend van Spriel | aa70b4f | 2014-07-12 08:49:40 +0200 | [diff] [blame] | 5866 | { |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 5867 | struct brcmf_if *ifp = netdev_priv(cfg_to_ndev(cfg)); |
| 5868 | struct ieee80211_supported_band *band; |
Arend van Spriel | aa70b4f | 2014-07-12 08:49:40 +0200 | [diff] [blame] | 5869 | struct brcmf_fil_bwcap_le band_bwcap; |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 5870 | struct brcmf_chanspec_list *list; |
| 5871 | u8 *pbuf; |
Arend van Spriel | aa70b4f | 2014-07-12 08:49:40 +0200 | [diff] [blame] | 5872 | u32 val; |
| 5873 | int err; |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 5874 | struct brcmu_chan ch; |
| 5875 | u32 num_chan; |
| 5876 | int i, j; |
Arend van Spriel | aa70b4f | 2014-07-12 08:49:40 +0200 | [diff] [blame] | 5877 | |
| 5878 | /* verify support for bw_cap command */ |
| 5879 | val = WLC_BAND_5G; |
| 5880 | err = brcmf_fil_iovar_int_get(ifp, "bw_cap", &val); |
| 5881 | |
| 5882 | if (!err) { |
| 5883 | /* only set 2G bandwidth using bw_cap command */ |
| 5884 | band_bwcap.band = cpu_to_le32(WLC_BAND_2G); |
| 5885 | band_bwcap.bw_cap = cpu_to_le32(WLC_BW_CAP_40MHZ); |
| 5886 | err = brcmf_fil_iovar_data_set(ifp, "bw_cap", &band_bwcap, |
| 5887 | sizeof(band_bwcap)); |
| 5888 | } else { |
| 5889 | brcmf_dbg(INFO, "fallback to mimo_bw_cap\n"); |
| 5890 | val = WLC_N_BW_40ALL; |
| 5891 | err = brcmf_fil_iovar_int_set(ifp, "mimo_bw_cap", val); |
| 5892 | } |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 5893 | |
| 5894 | if (!err) { |
| 5895 | /* update channel info in 2G band */ |
| 5896 | pbuf = kzalloc(BRCMF_DCMD_MEDLEN, GFP_KERNEL); |
| 5897 | |
| 5898 | if (pbuf == NULL) |
| 5899 | return -ENOMEM; |
| 5900 | |
| 5901 | ch.band = BRCMU_CHAN_BAND_2G; |
| 5902 | ch.bw = BRCMU_CHAN_BW_40; |
Hante Meuleman | fac7d2a | 2014-09-11 22:51:30 +0200 | [diff] [blame] | 5903 | ch.sb = BRCMU_CHAN_SB_NONE; |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 5904 | ch.chnum = 0; |
| 5905 | cfg->d11inf.encchspec(&ch); |
| 5906 | |
| 5907 | /* pass encoded chanspec in query */ |
| 5908 | *(__le16 *)pbuf = cpu_to_le16(ch.chspec); |
| 5909 | |
| 5910 | err = brcmf_fil_iovar_data_get(ifp, "chanspecs", pbuf, |
| 5911 | BRCMF_DCMD_MEDLEN); |
| 5912 | if (err) { |
| 5913 | brcmf_err("get chanspecs error (%d)\n", err); |
| 5914 | kfree(pbuf); |
| 5915 | return err; |
| 5916 | } |
| 5917 | |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 5918 | band = cfg_to_wiphy(cfg)->bands[NL80211_BAND_2GHZ]; |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 5919 | list = (struct brcmf_chanspec_list *)pbuf; |
| 5920 | num_chan = le32_to_cpu(list->count); |
| 5921 | for (i = 0; i < num_chan; i++) { |
| 5922 | ch.chspec = (u16)le32_to_cpu(list->element[i]); |
| 5923 | cfg->d11inf.decchspec(&ch); |
| 5924 | if (WARN_ON(ch.band != BRCMU_CHAN_BAND_2G)) |
| 5925 | continue; |
| 5926 | if (WARN_ON(ch.bw != BRCMU_CHAN_BW_40)) |
| 5927 | continue; |
| 5928 | for (j = 0; j < band->n_channels; j++) { |
| 5929 | if (band->channels[j].hw_value == ch.chnum) |
| 5930 | break; |
| 5931 | } |
| 5932 | if (WARN_ON(j == band->n_channels)) |
| 5933 | continue; |
| 5934 | |
| 5935 | brcmf_update_bw40_channel_flag(&band->channels[j], &ch); |
| 5936 | } |
Hante Meuleman | fac7d2a | 2014-09-11 22:51:30 +0200 | [diff] [blame] | 5937 | kfree(pbuf); |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 5938 | } |
Arend van Spriel | aa70b4f | 2014-07-12 08:49:40 +0200 | [diff] [blame] | 5939 | return err; |
| 5940 | } |
| 5941 | |
Arend van Spriel | 2375d97 | 2014-01-06 12:40:41 +0100 | [diff] [blame] | 5942 | static void brcmf_get_bwcap(struct brcmf_if *ifp, u32 bw_cap[]) |
| 5943 | { |
| 5944 | u32 band, mimo_bwcap; |
| 5945 | int err; |
| 5946 | |
| 5947 | band = WLC_BAND_2G; |
| 5948 | err = brcmf_fil_iovar_int_get(ifp, "bw_cap", &band); |
| 5949 | if (!err) { |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 5950 | bw_cap[NL80211_BAND_2GHZ] = band; |
Arend van Spriel | 2375d97 | 2014-01-06 12:40:41 +0100 | [diff] [blame] | 5951 | band = WLC_BAND_5G; |
| 5952 | err = brcmf_fil_iovar_int_get(ifp, "bw_cap", &band); |
| 5953 | if (!err) { |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 5954 | bw_cap[NL80211_BAND_5GHZ] = band; |
Arend van Spriel | 2375d97 | 2014-01-06 12:40:41 +0100 | [diff] [blame] | 5955 | return; |
| 5956 | } |
| 5957 | WARN_ON(1); |
| 5958 | return; |
| 5959 | } |
| 5960 | brcmf_dbg(INFO, "fallback to mimo_bw_cap info\n"); |
| 5961 | mimo_bwcap = 0; |
| 5962 | err = brcmf_fil_iovar_int_get(ifp, "mimo_bw_cap", &mimo_bwcap); |
| 5963 | if (err) |
| 5964 | /* assume 20MHz if firmware does not give a clue */ |
| 5965 | mimo_bwcap = WLC_N_BW_20ALL; |
| 5966 | |
| 5967 | switch (mimo_bwcap) { |
| 5968 | case WLC_N_BW_40ALL: |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 5969 | bw_cap[NL80211_BAND_2GHZ] |= WLC_BW_40MHZ_BIT; |
Arend van Spriel | 2375d97 | 2014-01-06 12:40:41 +0100 | [diff] [blame] | 5970 | /* fall-thru */ |
| 5971 | case WLC_N_BW_20IN2G_40IN5G: |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 5972 | bw_cap[NL80211_BAND_5GHZ] |= WLC_BW_40MHZ_BIT; |
Arend van Spriel | 2375d97 | 2014-01-06 12:40:41 +0100 | [diff] [blame] | 5973 | /* fall-thru */ |
| 5974 | case WLC_N_BW_20ALL: |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 5975 | bw_cap[NL80211_BAND_2GHZ] |= WLC_BW_20MHZ_BIT; |
| 5976 | bw_cap[NL80211_BAND_5GHZ] |= WLC_BW_20MHZ_BIT; |
Arend van Spriel | 2375d97 | 2014-01-06 12:40:41 +0100 | [diff] [blame] | 5977 | break; |
| 5978 | default: |
| 5979 | brcmf_err("invalid mimo_bw_cap value\n"); |
| 5980 | } |
| 5981 | } |
Hante Meuleman | d48200b | 2013-04-03 12:40:29 +0200 | [diff] [blame] | 5982 | |
Arend van Spriel | 18d6c53 | 2014-05-12 10:47:35 +0200 | [diff] [blame] | 5983 | static void brcmf_update_ht_cap(struct ieee80211_supported_band *band, |
| 5984 | u32 bw_cap[2], u32 nchain) |
| 5985 | { |
| 5986 | band->ht_cap.ht_supported = true; |
| 5987 | if (bw_cap[band->band] & WLC_BW_40MHZ_BIT) { |
| 5988 | band->ht_cap.cap |= IEEE80211_HT_CAP_SGI_40; |
| 5989 | band->ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40; |
| 5990 | } |
| 5991 | band->ht_cap.cap |= IEEE80211_HT_CAP_SGI_20; |
| 5992 | band->ht_cap.cap |= IEEE80211_HT_CAP_DSSSCCK40; |
| 5993 | band->ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K; |
| 5994 | band->ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_16; |
| 5995 | memset(band->ht_cap.mcs.rx_mask, 0xff, nchain); |
| 5996 | band->ht_cap.mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED; |
| 5997 | } |
| 5998 | |
| 5999 | static __le16 brcmf_get_mcs_map(u32 nchain, enum ieee80211_vht_mcs_support supp) |
| 6000 | { |
| 6001 | u16 mcs_map; |
| 6002 | int i; |
| 6003 | |
| 6004 | for (i = 0, mcs_map = 0xFFFF; i < nchain; i++) |
| 6005 | mcs_map = (mcs_map << 2) | supp; |
| 6006 | |
| 6007 | return cpu_to_le16(mcs_map); |
| 6008 | } |
| 6009 | |
| 6010 | static void brcmf_update_vht_cap(struct ieee80211_supported_band *band, |
Hante Meuleman | 7bf65aa | 2015-11-25 11:32:43 +0100 | [diff] [blame] | 6011 | u32 bw_cap[2], u32 nchain, u32 txstreams, |
| 6012 | u32 txbf_bfe_cap, u32 txbf_bfr_cap) |
Arend van Spriel | 18d6c53 | 2014-05-12 10:47:35 +0200 | [diff] [blame] | 6013 | { |
| 6014 | __le16 mcs_map; |
| 6015 | |
| 6016 | /* not allowed in 2.4G band */ |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 6017 | if (band->band == NL80211_BAND_2GHZ) |
Arend van Spriel | 18d6c53 | 2014-05-12 10:47:35 +0200 | [diff] [blame] | 6018 | return; |
| 6019 | |
| 6020 | band->vht_cap.vht_supported = true; |
| 6021 | /* 80MHz is mandatory */ |
| 6022 | band->vht_cap.cap |= IEEE80211_VHT_CAP_SHORT_GI_80; |
| 6023 | if (bw_cap[band->band] & WLC_BW_160MHZ_BIT) { |
| 6024 | band->vht_cap.cap |= IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ; |
| 6025 | band->vht_cap.cap |= IEEE80211_VHT_CAP_SHORT_GI_160; |
| 6026 | } |
| 6027 | /* all support 256-QAM */ |
| 6028 | mcs_map = brcmf_get_mcs_map(nchain, IEEE80211_VHT_MCS_SUPPORT_0_9); |
| 6029 | band->vht_cap.vht_mcs.rx_mcs_map = mcs_map; |
| 6030 | band->vht_cap.vht_mcs.tx_mcs_map = mcs_map; |
Hante Meuleman | 7bf65aa | 2015-11-25 11:32:43 +0100 | [diff] [blame] | 6031 | |
| 6032 | /* Beamforming support information */ |
| 6033 | if (txbf_bfe_cap & BRCMF_TXBF_SU_BFE_CAP) |
| 6034 | band->vht_cap.cap |= IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE; |
| 6035 | if (txbf_bfe_cap & BRCMF_TXBF_MU_BFE_CAP) |
| 6036 | band->vht_cap.cap |= IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE; |
| 6037 | if (txbf_bfr_cap & BRCMF_TXBF_SU_BFR_CAP) |
| 6038 | band->vht_cap.cap |= IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE; |
| 6039 | if (txbf_bfr_cap & BRCMF_TXBF_MU_BFR_CAP) |
| 6040 | band->vht_cap.cap |= IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE; |
| 6041 | |
| 6042 | if ((txbf_bfe_cap || txbf_bfr_cap) && (txstreams > 1)) { |
| 6043 | band->vht_cap.cap |= |
| 6044 | (2 << IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT); |
| 6045 | band->vht_cap.cap |= ((txstreams - 1) << |
| 6046 | IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT); |
| 6047 | band->vht_cap.cap |= |
| 6048 | IEEE80211_VHT_CAP_VHT_LINK_ADAPTATION_VHT_MRQ_MFB; |
| 6049 | } |
Arend van Spriel | 18d6c53 | 2014-05-12 10:47:35 +0200 | [diff] [blame] | 6050 | } |
| 6051 | |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 6052 | static int brcmf_setup_wiphybands(struct wiphy *wiphy) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 6053 | { |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 6054 | struct brcmf_cfg80211_info *cfg = wiphy_priv(wiphy); |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 6055 | struct brcmf_if *ifp = netdev_priv(cfg_to_ndev(cfg)); |
Arend van Spriel | 18d6c53 | 2014-05-12 10:47:35 +0200 | [diff] [blame] | 6056 | u32 nmode = 0; |
| 6057 | u32 vhtmode = 0; |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 6058 | u32 bw_cap[2] = { WLC_BW_20MHZ_BIT, WLC_BW_20MHZ_BIT }; |
Daniel Kim | 4aca7a1 | 2014-02-25 20:30:36 +0100 | [diff] [blame] | 6059 | u32 rxchain; |
| 6060 | u32 nchain; |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 6061 | int err; |
Hante Meuleman | d48200b | 2013-04-03 12:40:29 +0200 | [diff] [blame] | 6062 | s32 i; |
Arend van Spriel | 2375d97 | 2014-01-06 12:40:41 +0100 | [diff] [blame] | 6063 | struct ieee80211_supported_band *band; |
Hante Meuleman | 7bf65aa | 2015-11-25 11:32:43 +0100 | [diff] [blame] | 6064 | u32 txstreams = 0; |
| 6065 | u32 txbf_bfe_cap = 0; |
| 6066 | u32 txbf_bfr_cap = 0; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 6067 | |
Arend van Spriel | 18d6c53 | 2014-05-12 10:47:35 +0200 | [diff] [blame] | 6068 | (void)brcmf_fil_iovar_int_get(ifp, "vhtmode", &vhtmode); |
Hante Meuleman | d48200b | 2013-04-03 12:40:29 +0200 | [diff] [blame] | 6069 | err = brcmf_fil_iovar_int_get(ifp, "nmode", &nmode); |
| 6070 | if (err) { |
| 6071 | brcmf_err("nmode error (%d)\n", err); |
| 6072 | } else { |
Arend van Spriel | 2375d97 | 2014-01-06 12:40:41 +0100 | [diff] [blame] | 6073 | brcmf_get_bwcap(ifp, bw_cap); |
Hante Meuleman | d48200b | 2013-04-03 12:40:29 +0200 | [diff] [blame] | 6074 | } |
Arend van Spriel | 18d6c53 | 2014-05-12 10:47:35 +0200 | [diff] [blame] | 6075 | brcmf_dbg(INFO, "nmode=%d, vhtmode=%d, bw_cap=(%d, %d)\n", |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 6076 | nmode, vhtmode, bw_cap[NL80211_BAND_2GHZ], |
| 6077 | bw_cap[NL80211_BAND_5GHZ]); |
Hante Meuleman | d48200b | 2013-04-03 12:40:29 +0200 | [diff] [blame] | 6078 | |
Daniel Kim | 4aca7a1 | 2014-02-25 20:30:36 +0100 | [diff] [blame] | 6079 | err = brcmf_fil_iovar_int_get(ifp, "rxchain", &rxchain); |
| 6080 | if (err) { |
| 6081 | brcmf_err("rxchain error (%d)\n", err); |
| 6082 | nchain = 1; |
| 6083 | } else { |
| 6084 | for (nchain = 0; rxchain; nchain++) |
| 6085 | rxchain = rxchain & (rxchain - 1); |
| 6086 | } |
| 6087 | brcmf_dbg(INFO, "nchain=%d\n", nchain); |
| 6088 | |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 6089 | err = brcmf_construct_chaninfo(cfg, bw_cap); |
Hante Meuleman | d48200b | 2013-04-03 12:40:29 +0200 | [diff] [blame] | 6090 | if (err) { |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 6091 | brcmf_err("brcmf_construct_chaninfo failed (%d)\n", err); |
Hante Meuleman | d48200b | 2013-04-03 12:40:29 +0200 | [diff] [blame] | 6092 | return err; |
| 6093 | } |
| 6094 | |
Hante Meuleman | 7bf65aa | 2015-11-25 11:32:43 +0100 | [diff] [blame] | 6095 | if (vhtmode) { |
| 6096 | (void)brcmf_fil_iovar_int_get(ifp, "txstreams", &txstreams); |
| 6097 | (void)brcmf_fil_iovar_int_get(ifp, "txbf_bfe_cap", |
| 6098 | &txbf_bfe_cap); |
| 6099 | (void)brcmf_fil_iovar_int_get(ifp, "txbf_bfr_cap", |
| 6100 | &txbf_bfr_cap); |
| 6101 | } |
| 6102 | |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 6103 | wiphy = cfg_to_wiphy(cfg); |
| 6104 | for (i = 0; i < ARRAY_SIZE(wiphy->bands); i++) { |
| 6105 | band = wiphy->bands[i]; |
| 6106 | if (band == NULL) |
Arend van Spriel | 2375d97 | 2014-01-06 12:40:41 +0100 | [diff] [blame] | 6107 | continue; |
Hante Meuleman | d48200b | 2013-04-03 12:40:29 +0200 | [diff] [blame] | 6108 | |
Arend van Spriel | 18d6c53 | 2014-05-12 10:47:35 +0200 | [diff] [blame] | 6109 | if (nmode) |
| 6110 | brcmf_update_ht_cap(band, bw_cap, nchain); |
| 6111 | if (vhtmode) |
Hante Meuleman | 7bf65aa | 2015-11-25 11:32:43 +0100 | [diff] [blame] | 6112 | brcmf_update_vht_cap(band, bw_cap, nchain, txstreams, |
| 6113 | txbf_bfe_cap, txbf_bfr_cap); |
Hante Meuleman | d48200b | 2013-04-03 12:40:29 +0200 | [diff] [blame] | 6114 | } |
| 6115 | |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 6116 | return 0; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 6117 | } |
| 6118 | |
Arend van Spriel | aa70b4f | 2014-07-12 08:49:40 +0200 | [diff] [blame] | 6119 | static const struct ieee80211_txrx_stypes |
| 6120 | brcmf_txrx_stypes[NUM_NL80211_IFTYPES] = { |
| 6121 | [NL80211_IFTYPE_STATION] = { |
| 6122 | .tx = 0xffff, |
| 6123 | .rx = BIT(IEEE80211_STYPE_ACTION >> 4) | |
| 6124 | BIT(IEEE80211_STYPE_PROBE_REQ >> 4) |
| 6125 | }, |
| 6126 | [NL80211_IFTYPE_P2P_CLIENT] = { |
| 6127 | .tx = 0xffff, |
| 6128 | .rx = BIT(IEEE80211_STYPE_ACTION >> 4) | |
| 6129 | BIT(IEEE80211_STYPE_PROBE_REQ >> 4) |
| 6130 | }, |
| 6131 | [NL80211_IFTYPE_P2P_GO] = { |
| 6132 | .tx = 0xffff, |
| 6133 | .rx = BIT(IEEE80211_STYPE_ASSOC_REQ >> 4) | |
| 6134 | BIT(IEEE80211_STYPE_REASSOC_REQ >> 4) | |
| 6135 | BIT(IEEE80211_STYPE_PROBE_REQ >> 4) | |
| 6136 | BIT(IEEE80211_STYPE_DISASSOC >> 4) | |
| 6137 | BIT(IEEE80211_STYPE_AUTH >> 4) | |
| 6138 | BIT(IEEE80211_STYPE_DEAUTH >> 4) | |
| 6139 | BIT(IEEE80211_STYPE_ACTION >> 4) |
| 6140 | }, |
| 6141 | [NL80211_IFTYPE_P2P_DEVICE] = { |
| 6142 | .tx = 0xffff, |
| 6143 | .rx = BIT(IEEE80211_STYPE_ACTION >> 4) | |
| 6144 | BIT(IEEE80211_STYPE_PROBE_REQ >> 4) |
| 6145 | } |
| 6146 | }; |
| 6147 | |
Arend van Spriel | 0882dda | 2015-08-20 22:06:03 +0200 | [diff] [blame] | 6148 | /** |
| 6149 | * brcmf_setup_ifmodes() - determine interface modes and combinations. |
| 6150 | * |
| 6151 | * @wiphy: wiphy object. |
| 6152 | * @ifp: interface object needed for feat module api. |
| 6153 | * |
| 6154 | * The interface modes and combinations are determined dynamically here |
| 6155 | * based on firmware functionality. |
| 6156 | * |
| 6157 | * no p2p and no mbss: |
| 6158 | * |
| 6159 | * #STA <= 1, #AP <= 1, channels = 1, 2 total |
| 6160 | * |
| 6161 | * no p2p and mbss: |
| 6162 | * |
| 6163 | * #STA <= 1, #AP <= 1, channels = 1, 2 total |
| 6164 | * #AP <= 4, matching BI, channels = 1, 4 total |
| 6165 | * |
| 6166 | * p2p, no mchan, and mbss: |
| 6167 | * |
| 6168 | * #STA <= 1, #P2P-DEV <= 1, #{P2P-CL, P2P-GO} <= 1, channels = 1, 3 total |
| 6169 | * #STA <= 1, #P2P-DEV <= 1, #AP <= 1, #P2P-CL <= 1, channels = 1, 4 total |
| 6170 | * #AP <= 4, matching BI, channels = 1, 4 total |
| 6171 | * |
| 6172 | * p2p, mchan, and mbss: |
| 6173 | * |
| 6174 | * #STA <= 1, #P2P-DEV <= 1, #{P2P-CL, P2P-GO} <= 1, channels = 2, 3 total |
| 6175 | * #STA <= 1, #P2P-DEV <= 1, #AP <= 1, #P2P-CL <= 1, channels = 1, 4 total |
| 6176 | * #AP <= 4, matching BI, channels = 1, 4 total |
| 6177 | */ |
Pontus Fuchs | 2e5f66f | 2015-06-11 00:12:18 +0200 | [diff] [blame] | 6178 | static int brcmf_setup_ifmodes(struct wiphy *wiphy, struct brcmf_if *ifp) |
| 6179 | { |
| 6180 | struct ieee80211_iface_combination *combo = NULL; |
Arend van Spriel | 0882dda | 2015-08-20 22:06:03 +0200 | [diff] [blame] | 6181 | struct ieee80211_iface_limit *c0_limits = NULL; |
| 6182 | struct ieee80211_iface_limit *p2p_limits = NULL; |
| 6183 | struct ieee80211_iface_limit *mbss_limits = NULL; |
| 6184 | bool mbss, p2p; |
| 6185 | int i, c, n_combos; |
Pontus Fuchs | 2e5f66f | 2015-06-11 00:12:18 +0200 | [diff] [blame] | 6186 | |
Arend van Spriel | 0882dda | 2015-08-20 22:06:03 +0200 | [diff] [blame] | 6187 | mbss = brcmf_feat_is_enabled(ifp, BRCMF_FEAT_MBSS); |
| 6188 | p2p = brcmf_feat_is_enabled(ifp, BRCMF_FEAT_P2P); |
| 6189 | |
| 6190 | n_combos = 1 + !!p2p + !!mbss; |
| 6191 | combo = kcalloc(n_combos, sizeof(*combo), GFP_KERNEL); |
Pontus Fuchs | 2e5f66f | 2015-06-11 00:12:18 +0200 | [diff] [blame] | 6192 | if (!combo) |
| 6193 | goto err; |
| 6194 | |
Arend van Spriel | 0882dda | 2015-08-20 22:06:03 +0200 | [diff] [blame] | 6195 | c0_limits = kcalloc(p2p ? 3 : 2, sizeof(*c0_limits), GFP_KERNEL); |
| 6196 | if (!c0_limits) |
Pontus Fuchs | 2e5f66f | 2015-06-11 00:12:18 +0200 | [diff] [blame] | 6197 | goto err; |
| 6198 | |
Arend van Spriel | 0882dda | 2015-08-20 22:06:03 +0200 | [diff] [blame] | 6199 | if (p2p) { |
| 6200 | p2p_limits = kcalloc(4, sizeof(*p2p_limits), GFP_KERNEL); |
| 6201 | if (!p2p_limits) |
| 6202 | goto err; |
| 6203 | } |
| 6204 | |
| 6205 | if (mbss) { |
| 6206 | mbss_limits = kcalloc(1, sizeof(*mbss_limits), GFP_KERNEL); |
| 6207 | if (!mbss_limits) |
| 6208 | goto err; |
| 6209 | } |
| 6210 | |
Pontus Fuchs | 2e5f66f | 2015-06-11 00:12:18 +0200 | [diff] [blame] | 6211 | wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) | |
| 6212 | BIT(NL80211_IFTYPE_ADHOC) | |
| 6213 | BIT(NL80211_IFTYPE_AP); |
| 6214 | |
Arend van Spriel | 0882dda | 2015-08-20 22:06:03 +0200 | [diff] [blame] | 6215 | c = 0; |
| 6216 | i = 0; |
| 6217 | combo[c].num_different_channels = 1; |
| 6218 | c0_limits[i].max = 1; |
| 6219 | c0_limits[i++].types = BIT(NL80211_IFTYPE_STATION); |
| 6220 | if (p2p) { |
| 6221 | if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_MCHAN)) |
| 6222 | combo[c].num_different_channels = 2; |
Pontus Fuchs | 2e5f66f | 2015-06-11 00:12:18 +0200 | [diff] [blame] | 6223 | wiphy->interface_modes |= BIT(NL80211_IFTYPE_P2P_CLIENT) | |
| 6224 | BIT(NL80211_IFTYPE_P2P_GO) | |
| 6225 | BIT(NL80211_IFTYPE_P2P_DEVICE); |
Arend van Spriel | 0882dda | 2015-08-20 22:06:03 +0200 | [diff] [blame] | 6226 | c0_limits[i].max = 1; |
| 6227 | c0_limits[i++].types = BIT(NL80211_IFTYPE_P2P_DEVICE); |
| 6228 | c0_limits[i].max = 1; |
| 6229 | c0_limits[i++].types = BIT(NL80211_IFTYPE_P2P_CLIENT) | |
| 6230 | BIT(NL80211_IFTYPE_P2P_GO); |
| 6231 | } else { |
| 6232 | c0_limits[i].max = 1; |
| 6233 | c0_limits[i++].types = BIT(NL80211_IFTYPE_AP); |
Pontus Fuchs | 2e5f66f | 2015-06-11 00:12:18 +0200 | [diff] [blame] | 6234 | } |
Arend van Spriel | 0882dda | 2015-08-20 22:06:03 +0200 | [diff] [blame] | 6235 | combo[c].max_interfaces = i; |
| 6236 | combo[c].n_limits = i; |
| 6237 | combo[c].limits = c0_limits; |
Pontus Fuchs | 2e5f66f | 2015-06-11 00:12:18 +0200 | [diff] [blame] | 6238 | |
Arend van Spriel | 0882dda | 2015-08-20 22:06:03 +0200 | [diff] [blame] | 6239 | if (p2p) { |
| 6240 | c++; |
| 6241 | i = 0; |
| 6242 | combo[c].num_different_channels = 1; |
| 6243 | p2p_limits[i].max = 1; |
| 6244 | p2p_limits[i++].types = BIT(NL80211_IFTYPE_STATION); |
| 6245 | p2p_limits[i].max = 1; |
| 6246 | p2p_limits[i++].types = BIT(NL80211_IFTYPE_AP); |
| 6247 | p2p_limits[i].max = 1; |
| 6248 | p2p_limits[i++].types = BIT(NL80211_IFTYPE_P2P_CLIENT); |
| 6249 | p2p_limits[i].max = 1; |
| 6250 | p2p_limits[i++].types = BIT(NL80211_IFTYPE_P2P_DEVICE); |
| 6251 | combo[c].max_interfaces = i; |
| 6252 | combo[c].n_limits = i; |
| 6253 | combo[c].limits = p2p_limits; |
| 6254 | } |
| 6255 | |
| 6256 | if (mbss) { |
| 6257 | c++; |
| 6258 | combo[c].beacon_int_infra_match = true; |
| 6259 | combo[c].num_different_channels = 1; |
| 6260 | mbss_limits[0].max = 4; |
| 6261 | mbss_limits[0].types = BIT(NL80211_IFTYPE_AP); |
| 6262 | combo[c].max_interfaces = 4; |
| 6263 | combo[c].n_limits = 1; |
| 6264 | combo[c].limits = mbss_limits; |
| 6265 | } |
| 6266 | wiphy->n_iface_combinations = n_combos; |
Pontus Fuchs | 2e5f66f | 2015-06-11 00:12:18 +0200 | [diff] [blame] | 6267 | wiphy->iface_combinations = combo; |
Pontus Fuchs | 2e5f66f | 2015-06-11 00:12:18 +0200 | [diff] [blame] | 6268 | return 0; |
| 6269 | |
| 6270 | err: |
Arend van Spriel | 0882dda | 2015-08-20 22:06:03 +0200 | [diff] [blame] | 6271 | kfree(c0_limits); |
| 6272 | kfree(p2p_limits); |
| 6273 | kfree(mbss_limits); |
Pontus Fuchs | 2e5f66f | 2015-06-11 00:12:18 +0200 | [diff] [blame] | 6274 | kfree(combo); |
| 6275 | return -ENOMEM; |
| 6276 | } |
| 6277 | |
Arend van Spriel | aa70b4f | 2014-07-12 08:49:40 +0200 | [diff] [blame] | 6278 | static void brcmf_wiphy_pno_params(struct wiphy *wiphy) |
| 6279 | { |
| 6280 | /* scheduled scan settings */ |
| 6281 | wiphy->max_sched_scan_ssids = BRCMF_PNO_MAX_PFN_COUNT; |
| 6282 | wiphy->max_match_sets = BRCMF_PNO_MAX_PFN_COUNT; |
| 6283 | wiphy->max_sched_scan_ie_len = BRCMF_SCAN_IE_LEN_MAX; |
| 6284 | wiphy->flags |= WIPHY_FLAG_SUPPORTS_SCHED_SCAN; |
| 6285 | } |
| 6286 | |
Hante Meuleman | 4eb3af7 | 2014-09-30 10:23:18 +0200 | [diff] [blame] | 6287 | #ifdef CONFIG_PM |
Hante Meuleman | 3021ad9 | 2016-01-05 11:05:45 +0100 | [diff] [blame] | 6288 | static struct wiphy_wowlan_support brcmf_wowlan_support = { |
Hante Meuleman | 4eb3af7 | 2014-09-30 10:23:18 +0200 | [diff] [blame] | 6289 | .flags = WIPHY_WOWLAN_MAGIC_PKT | WIPHY_WOWLAN_DISCONNECT, |
Hante Meuleman | b9a82f8 | 2014-10-28 14:56:06 +0100 | [diff] [blame] | 6290 | .n_patterns = BRCMF_WOWL_MAXPATTERNS, |
| 6291 | .pattern_max_len = BRCMF_WOWL_MAXPATTERNSIZE, |
| 6292 | .pattern_min_len = 1, |
| 6293 | .max_pkt_offset = 1500, |
Hante Meuleman | 4eb3af7 | 2014-09-30 10:23:18 +0200 | [diff] [blame] | 6294 | }; |
| 6295 | #endif |
| 6296 | |
Hante Meuleman | 3021ad9 | 2016-01-05 11:05:45 +0100 | [diff] [blame] | 6297 | 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] | 6298 | { |
| 6299 | #ifdef CONFIG_PM |
Hante Meuleman | 3021ad9 | 2016-01-05 11:05:45 +0100 | [diff] [blame] | 6300 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); |
Hante Meuleman | 3021ad9 | 2016-01-05 11:05:45 +0100 | [diff] [blame] | 6301 | |
| 6302 | if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_PNO)) { |
Hante Meuleman | 5c22fb8 | 2016-02-17 11:27:03 +0100 | [diff] [blame] | 6303 | if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_WOWL_ND)) { |
| 6304 | brcmf_wowlan_support.flags |= WIPHY_WOWLAN_NET_DETECT; |
| 6305 | init_waitqueue_head(&cfg->wowl.nd_data_wait); |
Hante Meuleman | 3021ad9 | 2016-01-05 11:05:45 +0100 | [diff] [blame] | 6306 | } |
| 6307 | } |
Hante Meuleman | 5c22fb8 | 2016-02-17 11:27:03 +0100 | [diff] [blame] | 6308 | if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_WOWL_GTK)) { |
| 6309 | brcmf_wowlan_support.flags |= WIPHY_WOWLAN_SUPPORTS_GTK_REKEY; |
| 6310 | brcmf_wowlan_support.flags |= WIPHY_WOWLAN_GTK_REKEY_FAILURE; |
| 6311 | } |
| 6312 | |
Hante Meuleman | 4eb3af7 | 2014-09-30 10:23:18 +0200 | [diff] [blame] | 6313 | wiphy->wowlan = &brcmf_wowlan_support; |
| 6314 | #endif |
| 6315 | } |
| 6316 | |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 6317 | 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] | 6318 | { |
Rafa? Mi?ecki | e3faa86 | 2015-07-09 17:07:08 +0200 | [diff] [blame] | 6319 | struct brcmf_pub *drvr = ifp->drvr; |
Rafał Miłecki | 50f32e2 | 2015-08-20 00:16:42 +0200 | [diff] [blame] | 6320 | const struct ieee80211_iface_combination *combo; |
Arend van Spriel | 58de92d | 2015-04-14 20:10:24 +0200 | [diff] [blame] | 6321 | struct ieee80211_supported_band *band; |
Rafał Miłecki | 50f32e2 | 2015-08-20 00:16:42 +0200 | [diff] [blame] | 6322 | u16 max_interfaces = 0; |
Arend van Spriel | 58de92d | 2015-04-14 20:10:24 +0200 | [diff] [blame] | 6323 | __le32 bandlist[3]; |
| 6324 | u32 n_bands; |
| 6325 | int err, i; |
| 6326 | |
Arend van Spriel | aa70b4f | 2014-07-12 08:49:40 +0200 | [diff] [blame] | 6327 | wiphy->max_scan_ssids = WL_NUM_SCAN_MAX; |
| 6328 | wiphy->max_scan_ie_len = BRCMF_SCAN_IE_LEN_MAX; |
Hante Meuleman | 6c404f3 | 2015-12-10 13:43:03 +0100 | [diff] [blame] | 6329 | wiphy->max_num_pmkids = BRCMF_MAXPMKID; |
Pontus Fuchs | 2e5f66f | 2015-06-11 00:12:18 +0200 | [diff] [blame] | 6330 | |
| 6331 | err = brcmf_setup_ifmodes(wiphy, ifp); |
| 6332 | if (err) |
| 6333 | return err; |
| 6334 | |
Rafał Miłecki | 50f32e2 | 2015-08-20 00:16:42 +0200 | [diff] [blame] | 6335 | for (i = 0, combo = wiphy->iface_combinations; |
| 6336 | i < wiphy->n_iface_combinations; i++, combo++) { |
| 6337 | max_interfaces = max(max_interfaces, combo->max_interfaces); |
| 6338 | } |
| 6339 | |
| 6340 | for (i = 0; i < max_interfaces && i < ARRAY_SIZE(drvr->addresses); |
| 6341 | i++) { |
Rafa? Mi?ecki | e3faa86 | 2015-07-09 17:07:08 +0200 | [diff] [blame] | 6342 | u8 *addr = drvr->addresses[i].addr; |
| 6343 | |
| 6344 | memcpy(addr, drvr->mac, ETH_ALEN); |
| 6345 | if (i) { |
| 6346 | addr[0] |= BIT(1); |
| 6347 | addr[ETH_ALEN - 1] ^= i; |
| 6348 | } |
| 6349 | } |
| 6350 | wiphy->addresses = drvr->addresses; |
| 6351 | wiphy->n_addresses = i; |
| 6352 | |
Arend van Spriel | aa70b4f | 2014-07-12 08:49:40 +0200 | [diff] [blame] | 6353 | wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM; |
Hante Meuleman | 240d61a | 2016-02-17 11:27:10 +0100 | [diff] [blame] | 6354 | wiphy->cipher_suites = brcmf_cipher_suites; |
| 6355 | wiphy->n_cipher_suites = ARRAY_SIZE(brcmf_cipher_suites); |
| 6356 | if (!brcmf_feat_is_enabled(ifp, BRCMF_FEAT_MFP)) |
| 6357 | wiphy->n_cipher_suites--; |
Arend van Spriel | 7705ba6 | 2016-04-17 16:44:58 +0200 | [diff] [blame] | 6358 | wiphy->bss_select_support = BIT(NL80211_BSS_SELECT_ATTR_RSSI) | |
| 6359 | BIT(NL80211_BSS_SELECT_ATTR_BAND_PREF) | |
| 6360 | BIT(NL80211_BSS_SELECT_ATTR_RSSI_ADJUST); |
| 6361 | |
Arend van Spriel | aa70b4f | 2014-07-12 08:49:40 +0200 | [diff] [blame] | 6362 | wiphy->flags |= WIPHY_FLAG_PS_ON_BY_DEFAULT | |
| 6363 | WIPHY_FLAG_OFFCHAN_TX | |
Hante Meuleman | a7b82d4 | 2015-12-10 13:43:04 +0100 | [diff] [blame] | 6364 | WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL; |
| 6365 | if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_TDLS)) |
| 6366 | wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS; |
Hante Meuleman | 7d34b05 | 2016-01-02 09:41:41 +0100 | [diff] [blame] | 6367 | if (!ifp->drvr->settings->roamoff) |
Arend van Spriel | aa70b4f | 2014-07-12 08:49:40 +0200 | [diff] [blame] | 6368 | wiphy->flags |= WIPHY_FLAG_SUPPORTS_FW_ROAM; |
| 6369 | wiphy->mgmt_stypes = brcmf_txrx_stypes; |
| 6370 | wiphy->max_remain_on_channel_duration = 5000; |
Arend van Spriel | 7a7a87d | 2015-04-14 20:10:27 +0200 | [diff] [blame] | 6371 | if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_PNO)) |
| 6372 | brcmf_wiphy_pno_params(wiphy); |
Arend van Spriel | aa70b4f | 2014-07-12 08:49:40 +0200 | [diff] [blame] | 6373 | |
| 6374 | /* vendor commands/events support */ |
| 6375 | wiphy->vendor_commands = brcmf_vendor_cmds; |
| 6376 | wiphy->n_vendor_commands = BRCMF_VNDR_CMDS_LAST - 1; |
| 6377 | |
Hante Meuleman | 4eb3af7 | 2014-09-30 10:23:18 +0200 | [diff] [blame] | 6378 | if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_WOWL)) |
Hante Meuleman | 3021ad9 | 2016-01-05 11:05:45 +0100 | [diff] [blame] | 6379 | brcmf_wiphy_wowl_params(wiphy, ifp); |
Arend van Spriel | 58de92d | 2015-04-14 20:10:24 +0200 | [diff] [blame] | 6380 | err = brcmf_fil_cmd_data_get(ifp, BRCMF_C_GET_BANDLIST, &bandlist, |
| 6381 | sizeof(bandlist)); |
| 6382 | if (err) { |
| 6383 | brcmf_err("could not obtain band info: err=%d\n", err); |
| 6384 | return err; |
| 6385 | } |
| 6386 | /* first entry in bandlist is number of bands */ |
| 6387 | n_bands = le32_to_cpu(bandlist[0]); |
| 6388 | for (i = 1; i <= n_bands && i < ARRAY_SIZE(bandlist); i++) { |
| 6389 | if (bandlist[i] == cpu_to_le32(WLC_BAND_2G)) { |
| 6390 | band = kmemdup(&__wl_band_2ghz, sizeof(__wl_band_2ghz), |
| 6391 | GFP_KERNEL); |
| 6392 | if (!band) |
| 6393 | return -ENOMEM; |
| 6394 | |
| 6395 | band->channels = kmemdup(&__wl_2ghz_channels, |
| 6396 | sizeof(__wl_2ghz_channels), |
| 6397 | GFP_KERNEL); |
| 6398 | if (!band->channels) { |
| 6399 | kfree(band); |
| 6400 | return -ENOMEM; |
| 6401 | } |
| 6402 | |
| 6403 | band->n_channels = ARRAY_SIZE(__wl_2ghz_channels); |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 6404 | wiphy->bands[NL80211_BAND_2GHZ] = band; |
Arend van Spriel | 58de92d | 2015-04-14 20:10:24 +0200 | [diff] [blame] | 6405 | } |
| 6406 | if (bandlist[i] == cpu_to_le32(WLC_BAND_5G)) { |
| 6407 | band = kmemdup(&__wl_band_5ghz, sizeof(__wl_band_5ghz), |
| 6408 | GFP_KERNEL); |
| 6409 | if (!band) |
| 6410 | return -ENOMEM; |
| 6411 | |
| 6412 | band->channels = kmemdup(&__wl_5ghz_channels, |
| 6413 | sizeof(__wl_5ghz_channels), |
| 6414 | GFP_KERNEL); |
| 6415 | if (!band->channels) { |
| 6416 | kfree(band); |
| 6417 | return -ENOMEM; |
| 6418 | } |
| 6419 | |
| 6420 | band->n_channels = ARRAY_SIZE(__wl_5ghz_channels); |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 6421 | wiphy->bands[NL80211_BAND_5GHZ] = band; |
Arend van Spriel | 58de92d | 2015-04-14 20:10:24 +0200 | [diff] [blame] | 6422 | } |
| 6423 | } |
| 6424 | err = brcmf_setup_wiphybands(wiphy); |
| 6425 | return err; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 6426 | } |
| 6427 | |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 6428 | static s32 brcmf_config_dongle(struct brcmf_cfg80211_info *cfg) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 6429 | { |
| 6430 | struct net_device *ndev; |
| 6431 | struct wireless_dev *wdev; |
Hante Meuleman | 40a2329 | 2013-01-02 15:22:51 +0100 | [diff] [blame] | 6432 | struct brcmf_if *ifp; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 6433 | s32 power_mode; |
| 6434 | s32 err = 0; |
| 6435 | |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 6436 | if (cfg->dongle_up) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 6437 | return err; |
| 6438 | |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 6439 | ndev = cfg_to_ndev(cfg); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 6440 | wdev = ndev->ieee80211_ptr; |
Hante Meuleman | 40a2329 | 2013-01-02 15:22:51 +0100 | [diff] [blame] | 6441 | ifp = netdev_priv(ndev); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 6442 | |
Hante Meuleman | 40a2329 | 2013-01-02 15:22:51 +0100 | [diff] [blame] | 6443 | /* make sure RF is ready for work */ |
| 6444 | brcmf_fil_cmd_int_set(ifp, BRCMF_C_UP, 0); |
| 6445 | |
Hante Meuleman | 1678ba8 | 2015-12-10 13:43:00 +0100 | [diff] [blame] | 6446 | brcmf_dongle_scantime(ifp); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 6447 | |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 6448 | power_mode = cfg->pwr_save ? PM_FAST : PM_OFF; |
Hante Meuleman | 40a2329 | 2013-01-02 15:22:51 +0100 | [diff] [blame] | 6449 | 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] | 6450 | if (err) |
| 6451 | goto default_conf_out; |
Arend van Spriel | 647c9ae | 2012-12-05 15:26:01 +0100 | [diff] [blame] | 6452 | brcmf_dbg(INFO, "power save set to %s\n", |
| 6453 | (power_mode ? "enabled" : "disabled")); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 6454 | |
Hante Meuleman | 1119e23 | 2015-11-25 11:32:42 +0100 | [diff] [blame] | 6455 | err = brcmf_dongle_roam(ifp); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 6456 | if (err) |
| 6457 | goto default_conf_out; |
Franky Lin | 5dd161f | 2012-10-10 11:13:10 -0700 | [diff] [blame] | 6458 | err = brcmf_cfg80211_change_iface(wdev->wiphy, ndev, wdev->iftype, |
| 6459 | NULL, NULL); |
Hante Meuleman | 40a2329 | 2013-01-02 15:22:51 +0100 | [diff] [blame] | 6460 | if (err) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 6461 | goto default_conf_out; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 6462 | |
Franky Lin | 52f22fb | 2016-02-17 11:26:55 +0100 | [diff] [blame] | 6463 | brcmf_configure_arp_nd_offload(ifp, true); |
Hante Meuleman | b365745 | 2013-05-27 21:09:53 +0200 | [diff] [blame] | 6464 | |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 6465 | cfg->dongle_up = true; |
Hante Meuleman | 40a2329 | 2013-01-02 15:22:51 +0100 | [diff] [blame] | 6466 | default_conf_out: |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 6467 | |
| 6468 | return err; |
| 6469 | |
| 6470 | } |
| 6471 | |
Arend van Spriel | bdf5ff5 | 2012-11-14 18:46:09 -0800 | [diff] [blame] | 6472 | static s32 __brcmf_cfg80211_up(struct brcmf_if *ifp) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 6473 | { |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 6474 | set_bit(BRCMF_VIF_STATUS_READY, &ifp->vif->sme_state); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 6475 | |
Arend van Spriel | bdf5ff5 | 2012-11-14 18:46:09 -0800 | [diff] [blame] | 6476 | return brcmf_config_dongle(ifp->drvr->config); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 6477 | } |
| 6478 | |
Arend van Spriel | bdf5ff5 | 2012-11-14 18:46:09 -0800 | [diff] [blame] | 6479 | static s32 __brcmf_cfg80211_down(struct brcmf_if *ifp) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 6480 | { |
Arend van Spriel | bdf5ff5 | 2012-11-14 18:46:09 -0800 | [diff] [blame] | 6481 | struct brcmf_cfg80211_info *cfg = ifp->drvr->config; |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 6482 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 6483 | /* |
| 6484 | * While going down, if associated with AP disassociate |
| 6485 | * from AP to save power |
| 6486 | */ |
Arend van Spriel | 903e0ee | 2012-11-28 21:44:11 +0100 | [diff] [blame] | 6487 | if (check_vif_up(ifp->vif)) { |
Arend van Spriel | 9b7a0dd | 2015-01-25 20:31:33 +0100 | [diff] [blame] | 6488 | brcmf_link_down(ifp->vif, WLAN_REASON_UNSPECIFIED); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 6489 | |
| 6490 | /* Make sure WPA_Supplicant receives all the event |
| 6491 | generated due to DISASSOC call to the fw to keep |
| 6492 | the state fw and WPA_Supplicant state consistent |
| 6493 | */ |
| 6494 | brcmf_delay(500); |
| 6495 | } |
| 6496 | |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 6497 | brcmf_abort_scanning(cfg); |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 6498 | clear_bit(BRCMF_VIF_STATUS_READY, &ifp->vif->sme_state); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 6499 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 6500 | return 0; |
| 6501 | } |
| 6502 | |
Arend van Spriel | bdf5ff5 | 2012-11-14 18:46:09 -0800 | [diff] [blame] | 6503 | s32 brcmf_cfg80211_up(struct net_device *ndev) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 6504 | { |
Arend van Spriel | bdf5ff5 | 2012-11-14 18:46:09 -0800 | [diff] [blame] | 6505 | struct brcmf_if *ifp = netdev_priv(ndev); |
| 6506 | struct brcmf_cfg80211_info *cfg = ifp->drvr->config; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 6507 | s32 err = 0; |
| 6508 | |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 6509 | mutex_lock(&cfg->usr_sync); |
Arend van Spriel | bdf5ff5 | 2012-11-14 18:46:09 -0800 | [diff] [blame] | 6510 | err = __brcmf_cfg80211_up(ifp); |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 6511 | mutex_unlock(&cfg->usr_sync); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 6512 | |
| 6513 | return err; |
| 6514 | } |
| 6515 | |
Arend van Spriel | bdf5ff5 | 2012-11-14 18:46:09 -0800 | [diff] [blame] | 6516 | s32 brcmf_cfg80211_down(struct net_device *ndev) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 6517 | { |
Arend van Spriel | bdf5ff5 | 2012-11-14 18:46:09 -0800 | [diff] [blame] | 6518 | struct brcmf_if *ifp = netdev_priv(ndev); |
| 6519 | struct brcmf_cfg80211_info *cfg = ifp->drvr->config; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 6520 | s32 err = 0; |
| 6521 | |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 6522 | mutex_lock(&cfg->usr_sync); |
Arend van Spriel | bdf5ff5 | 2012-11-14 18:46:09 -0800 | [diff] [blame] | 6523 | err = __brcmf_cfg80211_down(ifp); |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 6524 | mutex_unlock(&cfg->usr_sync); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 6525 | |
| 6526 | return err; |
| 6527 | } |
| 6528 | |
Arend van Spriel | a7965fb | 2013-04-11 17:08:37 +0200 | [diff] [blame] | 6529 | enum nl80211_iftype brcmf_cfg80211_get_iftype(struct brcmf_if *ifp) |
| 6530 | { |
| 6531 | struct wireless_dev *wdev = &ifp->vif->wdev; |
| 6532 | |
| 6533 | return wdev->iftype; |
| 6534 | } |
| 6535 | |
Hante Meuleman | bfe8197 | 2014-10-28 14:56:16 +0100 | [diff] [blame] | 6536 | bool brcmf_get_vif_state_any(struct brcmf_cfg80211_info *cfg, |
| 6537 | unsigned long state) |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 6538 | { |
| 6539 | struct brcmf_cfg80211_vif *vif; |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 6540 | |
| 6541 | list_for_each_entry(vif, &cfg->vif_list, list) { |
| 6542 | if (test_bit(state, &vif->sme_state)) |
Rasmus Villemoes | e843bb1 | 2014-06-22 20:50:40 +0200 | [diff] [blame] | 6543 | return true; |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 6544 | } |
Rasmus Villemoes | e843bb1 | 2014-06-22 20:50:40 +0200 | [diff] [blame] | 6545 | return false; |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 6546 | } |
Arend van Spriel | d3c0b63 | 2013-02-08 15:53:37 +0100 | [diff] [blame] | 6547 | |
| 6548 | static inline bool vif_event_equals(struct brcmf_cfg80211_vif_event *event, |
| 6549 | u8 action) |
| 6550 | { |
| 6551 | u8 evt_action; |
| 6552 | |
| 6553 | mutex_lock(&event->vif_event_lock); |
| 6554 | evt_action = event->action; |
| 6555 | mutex_unlock(&event->vif_event_lock); |
| 6556 | return evt_action == action; |
| 6557 | } |
| 6558 | |
| 6559 | void brcmf_cfg80211_arm_vif_event(struct brcmf_cfg80211_info *cfg, |
| 6560 | struct brcmf_cfg80211_vif *vif) |
| 6561 | { |
| 6562 | struct brcmf_cfg80211_vif_event *event = &cfg->vif_event; |
| 6563 | |
| 6564 | mutex_lock(&event->vif_event_lock); |
| 6565 | event->vif = vif; |
| 6566 | event->action = 0; |
| 6567 | mutex_unlock(&event->vif_event_lock); |
| 6568 | } |
| 6569 | |
| 6570 | bool brcmf_cfg80211_vif_event_armed(struct brcmf_cfg80211_info *cfg) |
| 6571 | { |
| 6572 | struct brcmf_cfg80211_vif_event *event = &cfg->vif_event; |
| 6573 | bool armed; |
| 6574 | |
| 6575 | mutex_lock(&event->vif_event_lock); |
| 6576 | armed = event->vif != NULL; |
| 6577 | mutex_unlock(&event->vif_event_lock); |
| 6578 | |
| 6579 | return armed; |
| 6580 | } |
Arend van Spriel | a9eb0c4 | 2016-02-17 11:26:50 +0100 | [diff] [blame] | 6581 | |
| 6582 | int brcmf_cfg80211_wait_vif_event(struct brcmf_cfg80211_info *cfg, |
| 6583 | u8 action, ulong timeout) |
Arend van Spriel | d3c0b63 | 2013-02-08 15:53:37 +0100 | [diff] [blame] | 6584 | { |
| 6585 | struct brcmf_cfg80211_vif_event *event = &cfg->vif_event; |
| 6586 | |
| 6587 | return wait_event_timeout(event->vif_wq, |
| 6588 | vif_event_equals(event, action), timeout); |
| 6589 | } |
| 6590 | |
Hante Meuleman | 73345fd | 2016-02-17 11:26:53 +0100 | [diff] [blame] | 6591 | static s32 brcmf_translate_country_code(struct brcmf_pub *drvr, char alpha2[2], |
| 6592 | struct brcmf_fil_country_le *ccreq) |
| 6593 | { |
Hante Meuleman | 4d79289 | 2016-02-17 11:27:07 +0100 | [diff] [blame] | 6594 | struct brcmfmac_pd_cc *country_codes; |
| 6595 | struct brcmfmac_pd_cc_entry *cc; |
Hante Meuleman | 73345fd | 2016-02-17 11:26:53 +0100 | [diff] [blame] | 6596 | s32 found_index; |
| 6597 | int i; |
| 6598 | |
| 6599 | country_codes = drvr->settings->country_codes; |
| 6600 | if (!country_codes) { |
| 6601 | brcmf_dbg(TRACE, "No country codes configured for device\n"); |
| 6602 | return -EINVAL; |
| 6603 | } |
| 6604 | |
| 6605 | if ((alpha2[0] == ccreq->country_abbrev[0]) && |
| 6606 | (alpha2[1] == ccreq->country_abbrev[1])) { |
| 6607 | brcmf_dbg(TRACE, "Country code already set\n"); |
| 6608 | return -EAGAIN; |
| 6609 | } |
| 6610 | |
| 6611 | found_index = -1; |
| 6612 | for (i = 0; i < country_codes->table_size; i++) { |
| 6613 | cc = &country_codes->table[i]; |
| 6614 | if ((cc->iso3166[0] == '\0') && (found_index == -1)) |
| 6615 | found_index = i; |
| 6616 | if ((cc->iso3166[0] == alpha2[0]) && |
| 6617 | (cc->iso3166[1] == alpha2[1])) { |
| 6618 | found_index = i; |
| 6619 | break; |
| 6620 | } |
| 6621 | } |
| 6622 | if (found_index == -1) { |
| 6623 | brcmf_dbg(TRACE, "No country code match found\n"); |
| 6624 | return -EINVAL; |
| 6625 | } |
| 6626 | memset(ccreq, 0, sizeof(*ccreq)); |
| 6627 | ccreq->rev = cpu_to_le32(country_codes->table[found_index].rev); |
| 6628 | memcpy(ccreq->ccode, country_codes->table[found_index].cc, |
| 6629 | BRCMF_COUNTRY_BUF_SZ); |
| 6630 | ccreq->country_abbrev[0] = alpha2[0]; |
| 6631 | ccreq->country_abbrev[1] = alpha2[1]; |
| 6632 | ccreq->country_abbrev[2] = 0; |
| 6633 | |
| 6634 | return 0; |
| 6635 | } |
| 6636 | |
Arend van Spriel | 63db1a4 | 2014-12-21 12:43:51 +0100 | [diff] [blame] | 6637 | static void brcmf_cfg80211_reg_notifier(struct wiphy *wiphy, |
| 6638 | struct regulatory_request *req) |
| 6639 | { |
| 6640 | struct brcmf_cfg80211_info *cfg = wiphy_priv(wiphy); |
| 6641 | struct brcmf_if *ifp = netdev_priv(cfg_to_ndev(cfg)); |
| 6642 | struct brcmf_fil_country_le ccreq; |
Hante Meuleman | 73345fd | 2016-02-17 11:26:53 +0100 | [diff] [blame] | 6643 | s32 err; |
Arend van Spriel | 63db1a4 | 2014-12-21 12:43:51 +0100 | [diff] [blame] | 6644 | int i; |
| 6645 | |
Arend van Spriel | 63db1a4 | 2014-12-21 12:43:51 +0100 | [diff] [blame] | 6646 | /* ignore non-ISO3166 country codes */ |
| 6647 | for (i = 0; i < sizeof(req->alpha2); i++) |
| 6648 | if (req->alpha2[i] < 'A' || req->alpha2[i] > 'Z') { |
Hante Meuleman | 73345fd | 2016-02-17 11:26:53 +0100 | [diff] [blame] | 6649 | brcmf_err("not a ISO3166 code (0x%02x 0x%02x)\n", |
| 6650 | req->alpha2[0], req->alpha2[1]); |
Arend van Spriel | 63db1a4 | 2014-12-21 12:43:51 +0100 | [diff] [blame] | 6651 | return; |
| 6652 | } |
Hante Meuleman | 73345fd | 2016-02-17 11:26:53 +0100 | [diff] [blame] | 6653 | |
| 6654 | brcmf_dbg(TRACE, "Enter: initiator=%d, alpha=%c%c\n", req->initiator, |
| 6655 | req->alpha2[0], req->alpha2[1]); |
| 6656 | |
| 6657 | err = brcmf_fil_iovar_data_get(ifp, "country", &ccreq, sizeof(ccreq)); |
| 6658 | if (err) { |
| 6659 | brcmf_err("Country code iovar returned err = %d\n", err); |
| 6660 | return; |
| 6661 | } |
| 6662 | |
| 6663 | err = brcmf_translate_country_code(ifp->drvr, req->alpha2, &ccreq); |
| 6664 | if (err) |
| 6665 | return; |
| 6666 | |
| 6667 | err = brcmf_fil_iovar_data_set(ifp, "country", &ccreq, sizeof(ccreq)); |
| 6668 | if (err) { |
| 6669 | brcmf_err("Firmware rejected country setting\n"); |
Arend van Spriel | 8afe0ec | 2015-04-14 20:10:25 +0200 | [diff] [blame] | 6670 | return; |
| 6671 | } |
| 6672 | brcmf_setup_wiphybands(wiphy); |
Arend van Spriel | 63db1a4 | 2014-12-21 12:43:51 +0100 | [diff] [blame] | 6673 | } |
| 6674 | |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 6675 | static void brcmf_free_wiphy(struct wiphy *wiphy) |
| 6676 | { |
Arend van Spriel | 0882dda | 2015-08-20 22:06:03 +0200 | [diff] [blame] | 6677 | int i; |
| 6678 | |
Arend van Spriel | 58de92d | 2015-04-14 20:10:24 +0200 | [diff] [blame] | 6679 | if (!wiphy) |
| 6680 | return; |
| 6681 | |
Arend van Spriel | 0882dda | 2015-08-20 22:06:03 +0200 | [diff] [blame] | 6682 | if (wiphy->iface_combinations) { |
| 6683 | for (i = 0; i < wiphy->n_iface_combinations; i++) |
| 6684 | kfree(wiphy->iface_combinations[i].limits); |
| 6685 | } |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 6686 | kfree(wiphy->iface_combinations); |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 6687 | if (wiphy->bands[NL80211_BAND_2GHZ]) { |
| 6688 | kfree(wiphy->bands[NL80211_BAND_2GHZ]->channels); |
| 6689 | kfree(wiphy->bands[NL80211_BAND_2GHZ]); |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 6690 | } |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 6691 | if (wiphy->bands[NL80211_BAND_5GHZ]) { |
| 6692 | kfree(wiphy->bands[NL80211_BAND_5GHZ]->channels); |
| 6693 | kfree(wiphy->bands[NL80211_BAND_5GHZ]); |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 6694 | } |
| 6695 | wiphy_free(wiphy); |
| 6696 | } |
| 6697 | |
Arend van Spriel | ccfd1e8 | 2014-07-12 08:49:38 +0200 | [diff] [blame] | 6698 | struct brcmf_cfg80211_info *brcmf_cfg80211_attach(struct brcmf_pub *drvr, |
Hante Meuleman | ae7c03f | 2015-09-18 22:08:08 +0200 | [diff] [blame] | 6699 | struct device *busdev, |
| 6700 | bool p2pdev_forced) |
Arend van Spriel | ccfd1e8 | 2014-07-12 08:49:38 +0200 | [diff] [blame] | 6701 | { |
Arend van Spriel | 46f3b6e | 2015-08-26 22:14:58 +0200 | [diff] [blame] | 6702 | struct net_device *ndev = brcmf_get_ifp(drvr, 0)->ndev; |
Arend van Spriel | ccfd1e8 | 2014-07-12 08:49:38 +0200 | [diff] [blame] | 6703 | struct brcmf_cfg80211_info *cfg; |
| 6704 | struct wiphy *wiphy; |
Hante Meuleman | 5c22fb8 | 2016-02-17 11:27:03 +0100 | [diff] [blame] | 6705 | struct cfg80211_ops *ops; |
Arend van Spriel | ccfd1e8 | 2014-07-12 08:49:38 +0200 | [diff] [blame] | 6706 | struct brcmf_cfg80211_vif *vif; |
| 6707 | struct brcmf_if *ifp; |
| 6708 | s32 err = 0; |
| 6709 | s32 io_type; |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 6710 | u16 *cap = NULL; |
Arend van Spriel | ccfd1e8 | 2014-07-12 08:49:38 +0200 | [diff] [blame] | 6711 | |
| 6712 | if (!ndev) { |
| 6713 | brcmf_err("ndev is invalid\n"); |
| 6714 | return NULL; |
| 6715 | } |
| 6716 | |
Muhammad Falak R Wani | d464fd8 | 2016-05-19 19:29:03 +0530 | [diff] [blame^] | 6717 | ops = kmemdup(&brcmf_cfg80211_ops, sizeof(*ops), GFP_KERNEL); |
Hante Meuleman | 5c22fb8 | 2016-02-17 11:27:03 +0100 | [diff] [blame] | 6718 | if (!ops) |
| 6719 | return NULL; |
| 6720 | |
Arend van Spriel | ccfd1e8 | 2014-07-12 08:49:38 +0200 | [diff] [blame] | 6721 | ifp = netdev_priv(ndev); |
Hante Meuleman | 5c22fb8 | 2016-02-17 11:27:03 +0100 | [diff] [blame] | 6722 | #ifdef CONFIG_PM |
| 6723 | if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_WOWL_GTK)) |
| 6724 | ops->set_rekey_data = brcmf_cfg80211_set_rekey_data; |
| 6725 | #endif |
| 6726 | wiphy = wiphy_new(ops, sizeof(struct brcmf_cfg80211_info)); |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 6727 | if (!wiphy) { |
| 6728 | brcmf_err("Could not allocate wiphy device\n"); |
Arend van Spriel | ccfd1e8 | 2014-07-12 08:49:38 +0200 | [diff] [blame] | 6729 | return NULL; |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 6730 | } |
Rafał Miłecki | 6896f4f | 2015-05-31 02:52:26 +0200 | [diff] [blame] | 6731 | memcpy(wiphy->perm_addr, drvr->mac, ETH_ALEN); |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 6732 | set_wiphy_dev(wiphy, busdev); |
Arend van Spriel | ccfd1e8 | 2014-07-12 08:49:38 +0200 | [diff] [blame] | 6733 | |
| 6734 | cfg = wiphy_priv(wiphy); |
| 6735 | cfg->wiphy = wiphy; |
Hante Meuleman | 5c22fb8 | 2016-02-17 11:27:03 +0100 | [diff] [blame] | 6736 | cfg->ops = ops; |
Arend van Spriel | ccfd1e8 | 2014-07-12 08:49:38 +0200 | [diff] [blame] | 6737 | cfg->pub = drvr; |
| 6738 | init_vif_event(&cfg->vif_event); |
| 6739 | INIT_LIST_HEAD(&cfg->vif_list); |
| 6740 | |
| 6741 | vif = brcmf_alloc_vif(cfg, NL80211_IFTYPE_STATION, false); |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 6742 | if (IS_ERR(vif)) |
| 6743 | goto wiphy_out; |
Arend van Spriel | ccfd1e8 | 2014-07-12 08:49:38 +0200 | [diff] [blame] | 6744 | |
| 6745 | vif->ifp = ifp; |
| 6746 | vif->wdev.netdev = ndev; |
| 6747 | ndev->ieee80211_ptr = &vif->wdev; |
| 6748 | SET_NETDEV_DEV(ndev, wiphy_dev(cfg->wiphy)); |
| 6749 | |
| 6750 | err = wl_init_priv(cfg); |
| 6751 | if (err) { |
| 6752 | brcmf_err("Failed to init iwm_priv (%d)\n", err); |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 6753 | brcmf_free_vif(vif); |
| 6754 | goto wiphy_out; |
Arend van Spriel | ccfd1e8 | 2014-07-12 08:49:38 +0200 | [diff] [blame] | 6755 | } |
| 6756 | ifp->vif = vif; |
| 6757 | |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 6758 | /* determine d11 io type before wiphy setup */ |
| 6759 | 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] | 6760 | if (err) { |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 6761 | brcmf_err("Failed to get D11 version (%d)\n", err); |
| 6762 | goto priv_out; |
Arend van Spriel | ccfd1e8 | 2014-07-12 08:49:38 +0200 | [diff] [blame] | 6763 | } |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 6764 | cfg->d11inf.io_type = (u8)io_type; |
| 6765 | brcmu_d11_attach(&cfg->d11inf); |
| 6766 | |
| 6767 | err = brcmf_setup_wiphy(wiphy, ifp); |
| 6768 | if (err < 0) |
| 6769 | goto priv_out; |
| 6770 | |
| 6771 | brcmf_dbg(INFO, "Registering custom regulatory\n"); |
Arend van Spriel | 63db1a4 | 2014-12-21 12:43:51 +0100 | [diff] [blame] | 6772 | wiphy->reg_notifier = brcmf_cfg80211_reg_notifier; |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 6773 | wiphy->regulatory_flags |= REGULATORY_CUSTOM_REG; |
| 6774 | wiphy_apply_custom_regulatory(wiphy, &brcmf_regdom); |
| 6775 | |
| 6776 | /* firmware defaults to 40MHz disabled in 2G band. We signal |
| 6777 | * cfg80211 here that we do and have it decide we can enable |
| 6778 | * it. But first check if device does support 2G operation. |
| 6779 | */ |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 6780 | if (wiphy->bands[NL80211_BAND_2GHZ]) { |
| 6781 | cap = &wiphy->bands[NL80211_BAND_2GHZ]->ht_cap.cap; |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 6782 | *cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40; |
| 6783 | } |
| 6784 | err = wiphy_register(wiphy); |
| 6785 | if (err < 0) { |
| 6786 | brcmf_err("Could not register wiphy device (%d)\n", err); |
| 6787 | goto priv_out; |
Arend van Spriel | ccfd1e8 | 2014-07-12 08:49:38 +0200 | [diff] [blame] | 6788 | } |
| 6789 | |
| 6790 | /* If cfg80211 didn't disable 40MHz HT CAP in wiphy_register(), |
| 6791 | * setup 40MHz in 2GHz band and enable OBSS scanning. |
| 6792 | */ |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 6793 | if (cap && (*cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40)) { |
| 6794 | err = brcmf_enable_bw40_2g(cfg); |
Arend van Spriel | ccfd1e8 | 2014-07-12 08:49:38 +0200 | [diff] [blame] | 6795 | if (!err) |
| 6796 | err = brcmf_fil_iovar_int_set(ifp, "obss_coex", |
| 6797 | BRCMF_OBSS_COEX_AUTO); |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 6798 | else |
| 6799 | *cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40; |
Arend van Spriel | ccfd1e8 | 2014-07-12 08:49:38 +0200 | [diff] [blame] | 6800 | } |
Hante Meuleman | 2b76acd | 2015-10-08 20:33:15 +0200 | [diff] [blame] | 6801 | /* p2p might require that "if-events" get processed by fweh. So |
| 6802 | * activate the already registered event handlers now and activate |
| 6803 | * the rest when initialization has completed. drvr->config needs to |
| 6804 | * be assigned before activating events. |
| 6805 | */ |
| 6806 | drvr->config = cfg; |
| 6807 | err = brcmf_fweh_activate_events(ifp); |
| 6808 | if (err) { |
| 6809 | brcmf_err("FWEH activation failed (%d)\n", err); |
| 6810 | goto wiphy_unreg_out; |
| 6811 | } |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 6812 | |
Hante Meuleman | ae7c03f | 2015-09-18 22:08:08 +0200 | [diff] [blame] | 6813 | err = brcmf_p2p_attach(cfg, p2pdev_forced); |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 6814 | if (err) { |
| 6815 | brcmf_err("P2P initilisation failed (%d)\n", err); |
| 6816 | goto wiphy_unreg_out; |
| 6817 | } |
| 6818 | err = brcmf_btcoex_attach(cfg); |
| 6819 | if (err) { |
| 6820 | brcmf_err("BT-coex initialisation failed (%d)\n", err); |
| 6821 | brcmf_p2p_detach(&cfg->p2p); |
| 6822 | goto wiphy_unreg_out; |
| 6823 | } |
Arend van Spriel | ccfd1e8 | 2014-07-12 08:49:38 +0200 | [diff] [blame] | 6824 | |
Hante Meuleman | a7b82d4 | 2015-12-10 13:43:04 +0100 | [diff] [blame] | 6825 | if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_TDLS)) { |
| 6826 | err = brcmf_fil_iovar_int_set(ifp, "tdls_enable", 1); |
| 6827 | if (err) { |
| 6828 | brcmf_dbg(INFO, "TDLS not enabled (%d)\n", err); |
| 6829 | wiphy->flags &= ~WIPHY_FLAG_SUPPORTS_TDLS; |
| 6830 | } else { |
| 6831 | brcmf_fweh_register(cfg->pub, BRCMF_E_TDLS_PEER_EVENT, |
| 6832 | brcmf_notify_tdls_peer_event); |
| 6833 | } |
Arend van Spriel | ccfd1e8 | 2014-07-12 08:49:38 +0200 | [diff] [blame] | 6834 | } |
| 6835 | |
Hante Meuleman | 2b76acd | 2015-10-08 20:33:15 +0200 | [diff] [blame] | 6836 | /* (re-) activate FWEH event handling */ |
| 6837 | err = brcmf_fweh_activate_events(ifp); |
| 6838 | if (err) { |
| 6839 | brcmf_err("FWEH activation failed (%d)\n", err); |
| 6840 | goto wiphy_unreg_out; |
| 6841 | } |
| 6842 | |
Hante Meuleman | 48ed16e | 2016-01-02 09:41:38 +0100 | [diff] [blame] | 6843 | /* Fill in some of the advertised nl80211 supported features */ |
| 6844 | if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_SCAN_RANDOM_MAC)) { |
| 6845 | wiphy->features |= NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR; |
| 6846 | #ifdef CONFIG_PM |
Franky Lin | 6ea0915 | 2016-02-17 11:26:52 +0100 | [diff] [blame] | 6847 | if (wiphy->wowlan && |
| 6848 | wiphy->wowlan->flags & WIPHY_WOWLAN_NET_DETECT) |
Hante Meuleman | 48ed16e | 2016-01-02 09:41:38 +0100 | [diff] [blame] | 6849 | wiphy->features |= NL80211_FEATURE_ND_RANDOM_MAC_ADDR; |
| 6850 | #endif |
| 6851 | } |
| 6852 | |
Arend van Spriel | ccfd1e8 | 2014-07-12 08:49:38 +0200 | [diff] [blame] | 6853 | return cfg; |
| 6854 | |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 6855 | wiphy_unreg_out: |
| 6856 | wiphy_unregister(cfg->wiphy); |
| 6857 | priv_out: |
Arend van Spriel | ccfd1e8 | 2014-07-12 08:49:38 +0200 | [diff] [blame] | 6858 | wl_deinit_priv(cfg); |
Arend van Spriel | ccfd1e8 | 2014-07-12 08:49:38 +0200 | [diff] [blame] | 6859 | brcmf_free_vif(vif); |
Hante Meuleman | 2b5d348 | 2015-09-18 22:08:04 +0200 | [diff] [blame] | 6860 | ifp->vif = NULL; |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 6861 | wiphy_out: |
| 6862 | brcmf_free_wiphy(wiphy); |
Hante Meuleman | 5c22fb8 | 2016-02-17 11:27:03 +0100 | [diff] [blame] | 6863 | kfree(ops); |
Arend van Spriel | ccfd1e8 | 2014-07-12 08:49:38 +0200 | [diff] [blame] | 6864 | return NULL; |
| 6865 | } |
| 6866 | |
| 6867 | void brcmf_cfg80211_detach(struct brcmf_cfg80211_info *cfg) |
| 6868 | { |
| 6869 | if (!cfg) |
| 6870 | return; |
| 6871 | |
Arend van Spriel | ccfd1e8 | 2014-07-12 08:49:38 +0200 | [diff] [blame] | 6872 | brcmf_btcoex_detach(cfg); |
Arend van Spriel | f7a4087 | 2015-06-11 00:12:23 +0200 | [diff] [blame] | 6873 | wiphy_unregister(cfg->wiphy); |
Hante Meuleman | 5c22fb8 | 2016-02-17 11:27:03 +0100 | [diff] [blame] | 6874 | kfree(cfg->ops); |
Arend van Spriel | ccfd1e8 | 2014-07-12 08:49:38 +0200 | [diff] [blame] | 6875 | wl_deinit_priv(cfg); |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 6876 | brcmf_free_wiphy(cfg->wiphy); |
Arend van Spriel | ccfd1e8 | 2014-07-12 08:49:38 +0200 | [diff] [blame] | 6877 | } |