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 */ |
| 75 | #define RSN_CAP_LEN 2 /* Length of RSN capabilities */ |
| 76 | #define RSN_CAP_PTK_REPLAY_CNTR_MASK 0x000C |
| 77 | |
| 78 | #define VNDR_IE_CMD_LEN 4 /* length of the set command |
| 79 | * string :"add", "del" (+ NUL) |
| 80 | */ |
| 81 | #define VNDR_IE_COUNT_OFFSET 4 |
| 82 | #define VNDR_IE_PKTFLAG_OFFSET 8 |
| 83 | #define VNDR_IE_VSIE_OFFSET 12 |
| 84 | #define VNDR_IE_HDR_SIZE 12 |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 85 | #define VNDR_IE_PARSE_LIMIT 5 |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 86 | |
| 87 | #define DOT11_MGMT_HDR_LEN 24 /* d11 management header len */ |
| 88 | #define DOT11_BCN_PRB_FIXED_LEN 12 /* beacon/probe fixed length */ |
Hante Meuleman | 0401289 | 2012-09-27 14:17:49 +0200 | [diff] [blame] | 89 | |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 90 | #define BRCMF_SCAN_JOIN_ACTIVE_DWELL_TIME_MS 320 |
| 91 | #define BRCMF_SCAN_JOIN_PASSIVE_DWELL_TIME_MS 400 |
| 92 | #define BRCMF_SCAN_JOIN_PROBE_INTERVAL_MS 20 |
| 93 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 94 | #define BRCMF_ASSOC_PARAMS_FIXED_SIZE \ |
| 95 | (sizeof(struct brcmf_assoc_params_le) - sizeof(u16)) |
| 96 | |
Arend van Spriel | ce81e31 | 2012-10-22 13:55:37 -0700 | [diff] [blame] | 97 | static bool check_vif_up(struct brcmf_cfg80211_vif *vif) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 98 | { |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 99 | if (!test_bit(BRCMF_VIF_STATUS_READY, &vif->sme_state)) { |
Arend van Spriel | 647c9ae | 2012-12-05 15:26:01 +0100 | [diff] [blame] | 100 | brcmf_dbg(INFO, "device is not ready : status (%lu)\n", |
| 101 | vif->sme_state); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 102 | return false; |
| 103 | } |
| 104 | return true; |
| 105 | } |
| 106 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 107 | #define RATE_TO_BASE100KBPS(rate) (((rate) * 10) / 2) |
| 108 | #define RATETAB_ENT(_rateid, _flags) \ |
| 109 | { \ |
| 110 | .bitrate = RATE_TO_BASE100KBPS(_rateid), \ |
| 111 | .hw_value = (_rateid), \ |
| 112 | .flags = (_flags), \ |
| 113 | } |
| 114 | |
| 115 | static struct ieee80211_rate __wl_rates[] = { |
| 116 | RATETAB_ENT(BRCM_RATE_1M, 0), |
| 117 | RATETAB_ENT(BRCM_RATE_2M, IEEE80211_RATE_SHORT_PREAMBLE), |
| 118 | RATETAB_ENT(BRCM_RATE_5M5, IEEE80211_RATE_SHORT_PREAMBLE), |
| 119 | RATETAB_ENT(BRCM_RATE_11M, IEEE80211_RATE_SHORT_PREAMBLE), |
| 120 | RATETAB_ENT(BRCM_RATE_6M, 0), |
| 121 | RATETAB_ENT(BRCM_RATE_9M, 0), |
| 122 | RATETAB_ENT(BRCM_RATE_12M, 0), |
| 123 | RATETAB_ENT(BRCM_RATE_18M, 0), |
| 124 | RATETAB_ENT(BRCM_RATE_24M, 0), |
| 125 | RATETAB_ENT(BRCM_RATE_36M, 0), |
| 126 | RATETAB_ENT(BRCM_RATE_48M, 0), |
| 127 | RATETAB_ENT(BRCM_RATE_54M, 0), |
| 128 | }; |
| 129 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 130 | #define wl_g_rates (__wl_rates + 0) |
Arend van Spriel | 58de92d | 2015-04-14 20:10:24 +0200 | [diff] [blame] | 131 | #define wl_g_rates_size ARRAY_SIZE(__wl_rates) |
| 132 | #define wl_a_rates (__wl_rates + 4) |
| 133 | #define wl_a_rates_size (wl_g_rates_size - 4) |
| 134 | |
| 135 | #define CHAN2G(_channel, _freq) { \ |
| 136 | .band = IEEE80211_BAND_2GHZ, \ |
| 137 | .center_freq = (_freq), \ |
| 138 | .hw_value = (_channel), \ |
| 139 | .flags = IEEE80211_CHAN_DISABLED, \ |
| 140 | .max_antenna_gain = 0, \ |
| 141 | .max_power = 30, \ |
| 142 | } |
| 143 | |
| 144 | #define CHAN5G(_channel) { \ |
| 145 | .band = IEEE80211_BAND_5GHZ, \ |
| 146 | .center_freq = 5000 + (5 * (_channel)), \ |
| 147 | .hw_value = (_channel), \ |
| 148 | .flags = IEEE80211_CHAN_DISABLED, \ |
| 149 | .max_antenna_gain = 0, \ |
| 150 | .max_power = 30, \ |
| 151 | } |
| 152 | |
| 153 | static struct ieee80211_channel __wl_2ghz_channels[] = { |
| 154 | CHAN2G(1, 2412), CHAN2G(2, 2417), CHAN2G(3, 2422), CHAN2G(4, 2427), |
| 155 | CHAN2G(5, 2432), CHAN2G(6, 2437), CHAN2G(7, 2442), CHAN2G(8, 2447), |
| 156 | CHAN2G(9, 2452), CHAN2G(10, 2457), CHAN2G(11, 2462), CHAN2G(12, 2467), |
| 157 | CHAN2G(13, 2472), CHAN2G(14, 2484) |
| 158 | }; |
| 159 | |
| 160 | static struct ieee80211_channel __wl_5ghz_channels[] = { |
| 161 | CHAN5G(34), CHAN5G(36), CHAN5G(38), CHAN5G(40), CHAN5G(42), |
| 162 | CHAN5G(44), CHAN5G(46), CHAN5G(48), CHAN5G(52), CHAN5G(56), |
| 163 | CHAN5G(60), CHAN5G(64), CHAN5G(100), CHAN5G(104), CHAN5G(108), |
| 164 | CHAN5G(112), CHAN5G(116), CHAN5G(120), CHAN5G(124), CHAN5G(128), |
| 165 | CHAN5G(132), CHAN5G(136), CHAN5G(140), CHAN5G(144), CHAN5G(149), |
| 166 | CHAN5G(153), CHAN5G(157), CHAN5G(161), CHAN5G(165) |
| 167 | }; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 168 | |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 169 | /* Band templates duplicated per wiphy. The channel info |
Arend van Spriel | 58de92d | 2015-04-14 20:10:24 +0200 | [diff] [blame] | 170 | * above is added to the band during setup. |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 171 | */ |
| 172 | static const struct ieee80211_supported_band __wl_band_2ghz = { |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 173 | .band = IEEE80211_BAND_2GHZ, |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 174 | .bitrates = wl_g_rates, |
| 175 | .n_bitrates = wl_g_rates_size, |
| 176 | }; |
| 177 | |
Arend van Spriel | 58de92d | 2015-04-14 20:10:24 +0200 | [diff] [blame] | 178 | static const struct ieee80211_supported_band __wl_band_5ghz = { |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 179 | .band = IEEE80211_BAND_5GHZ, |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 180 | .bitrates = wl_a_rates, |
| 181 | .n_bitrates = wl_a_rates_size, |
| 182 | }; |
| 183 | |
Hante Meuleman | d48200b | 2013-04-03 12:40:29 +0200 | [diff] [blame] | 184 | /* This is to override regulatory domains defined in cfg80211 module (reg.c) |
| 185 | * By default world regulatory domain defined in reg.c puts the flags |
Luis R. Rodriguez | 8fe02e1 | 2013-10-21 19:22:25 +0200 | [diff] [blame] | 186 | * NL80211_RRF_NO_IR for 5GHz channels (for * 36..48 and 149..165). |
| 187 | * With respect to these flags, wpa_supplicant doesn't * start p2p |
| 188 | * operations on 5GHz channels. All the changes in world regulatory |
Hante Meuleman | d48200b | 2013-04-03 12:40:29 +0200 | [diff] [blame] | 189 | * domain are to be done here. |
| 190 | */ |
| 191 | static const struct ieee80211_regdomain brcmf_regdom = { |
| 192 | .n_reg_rules = 4, |
| 193 | .alpha2 = "99", |
| 194 | .reg_rules = { |
| 195 | /* IEEE 802.11b/g, channels 1..11 */ |
| 196 | REG_RULE(2412-10, 2472+10, 40, 6, 20, 0), |
| 197 | /* If any */ |
| 198 | /* IEEE 802.11 channel 14 - Only JP enables |
| 199 | * this and for 802.11b only |
| 200 | */ |
| 201 | REG_RULE(2484-10, 2484+10, 20, 6, 20, 0), |
| 202 | /* IEEE 802.11a, channel 36..64 */ |
Arend van Spriel | c555ecd | 2014-05-12 10:47:36 +0200 | [diff] [blame] | 203 | REG_RULE(5150-10, 5350+10, 80, 6, 20, 0), |
Hante Meuleman | d48200b | 2013-04-03 12:40:29 +0200 | [diff] [blame] | 204 | /* IEEE 802.11a, channel 100..165 */ |
Arend van Spriel | c555ecd | 2014-05-12 10:47:36 +0200 | [diff] [blame] | 205 | REG_RULE(5470-10, 5850+10, 80, 6, 20, 0), } |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 206 | }; |
| 207 | |
| 208 | static const u32 __wl_cipher_suites[] = { |
| 209 | WLAN_CIPHER_SUITE_WEP40, |
| 210 | WLAN_CIPHER_SUITE_WEP104, |
| 211 | WLAN_CIPHER_SUITE_TKIP, |
| 212 | WLAN_CIPHER_SUITE_CCMP, |
| 213 | WLAN_CIPHER_SUITE_AES_CMAC, |
| 214 | }; |
| 215 | |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 216 | /* Vendor specific ie. id = 221, oui and type defines exact ie */ |
| 217 | struct brcmf_vs_tlv { |
| 218 | u8 id; |
| 219 | u8 len; |
| 220 | u8 oui[3]; |
| 221 | u8 oui_type; |
| 222 | }; |
| 223 | |
| 224 | struct parsed_vndr_ie_info { |
| 225 | u8 *ie_ptr; |
| 226 | u32 ie_len; /* total length including id & length field */ |
| 227 | struct brcmf_vs_tlv vndrie; |
| 228 | }; |
| 229 | |
| 230 | struct parsed_vndr_ies { |
| 231 | u32 count; |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 232 | struct parsed_vndr_ie_info ie_info[VNDR_IE_PARSE_LIMIT]; |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 233 | }; |
| 234 | |
Hante Meuleman | 68ca395 | 2014-02-25 20:30:26 +0100 | [diff] [blame] | 235 | static int brcmf_roamoff; |
| 236 | module_param_named(roamoff, brcmf_roamoff, int, S_IRUSR); |
| 237 | MODULE_PARM_DESC(roamoff, "do not use internal roaming engine"); |
| 238 | |
Alwin Beukers | ef6ac17 | 2011-10-12 20:51:26 +0200 | [diff] [blame] | 239 | |
Arend van Spriel | 5a394eb | 2014-05-27 12:56:15 +0200 | [diff] [blame] | 240 | static u16 chandef_to_chanspec(struct brcmu_d11inf *d11inf, |
| 241 | struct cfg80211_chan_def *ch) |
Arend van Spriel | 600a897 | 2014-05-12 10:47:39 +0200 | [diff] [blame] | 242 | { |
| 243 | struct brcmu_chan ch_inf; |
| 244 | s32 primary_offset; |
| 245 | |
| 246 | brcmf_dbg(TRACE, "chandef: control %d center %d width %d\n", |
| 247 | ch->chan->center_freq, ch->center_freq1, ch->width); |
| 248 | ch_inf.chnum = ieee80211_frequency_to_channel(ch->center_freq1); |
| 249 | primary_offset = ch->center_freq1 - ch->chan->center_freq; |
| 250 | switch (ch->width) { |
| 251 | case NL80211_CHAN_WIDTH_20: |
Arend van Spriel | 0cd75b1 | 2014-11-11 13:58:44 +0100 | [diff] [blame] | 252 | case NL80211_CHAN_WIDTH_20_NOHT: |
Arend van Spriel | 600a897 | 2014-05-12 10:47:39 +0200 | [diff] [blame] | 253 | ch_inf.bw = BRCMU_CHAN_BW_20; |
| 254 | WARN_ON(primary_offset != 0); |
| 255 | break; |
| 256 | case NL80211_CHAN_WIDTH_40: |
| 257 | ch_inf.bw = BRCMU_CHAN_BW_40; |
| 258 | if (primary_offset < 0) |
| 259 | ch_inf.sb = BRCMU_CHAN_SB_U; |
| 260 | else |
| 261 | ch_inf.sb = BRCMU_CHAN_SB_L; |
| 262 | break; |
| 263 | case NL80211_CHAN_WIDTH_80: |
| 264 | ch_inf.bw = BRCMU_CHAN_BW_80; |
| 265 | if (primary_offset < 0) { |
| 266 | if (primary_offset < -CH_10MHZ_APART) |
| 267 | ch_inf.sb = BRCMU_CHAN_SB_UU; |
| 268 | else |
| 269 | ch_inf.sb = BRCMU_CHAN_SB_UL; |
| 270 | } else { |
| 271 | if (primary_offset > CH_10MHZ_APART) |
| 272 | ch_inf.sb = BRCMU_CHAN_SB_LL; |
| 273 | else |
| 274 | ch_inf.sb = BRCMU_CHAN_SB_LU; |
| 275 | } |
| 276 | break; |
Arend van Spriel | 0cd75b1 | 2014-11-11 13:58:44 +0100 | [diff] [blame] | 277 | case NL80211_CHAN_WIDTH_80P80: |
| 278 | case NL80211_CHAN_WIDTH_160: |
| 279 | case NL80211_CHAN_WIDTH_5: |
| 280 | case NL80211_CHAN_WIDTH_10: |
Arend van Spriel | 600a897 | 2014-05-12 10:47:39 +0200 | [diff] [blame] | 281 | default: |
| 282 | WARN_ON_ONCE(1); |
| 283 | } |
| 284 | switch (ch->chan->band) { |
| 285 | case IEEE80211_BAND_2GHZ: |
| 286 | ch_inf.band = BRCMU_CHAN_BAND_2G; |
| 287 | break; |
| 288 | case IEEE80211_BAND_5GHZ: |
| 289 | ch_inf.band = BRCMU_CHAN_BAND_5G; |
| 290 | break; |
Arend van Spriel | 0cd75b1 | 2014-11-11 13:58:44 +0100 | [diff] [blame] | 291 | case IEEE80211_BAND_60GHZ: |
Arend van Spriel | 600a897 | 2014-05-12 10:47:39 +0200 | [diff] [blame] | 292 | default: |
| 293 | WARN_ON_ONCE(1); |
| 294 | } |
| 295 | d11inf->encchspec(&ch_inf); |
| 296 | |
| 297 | return ch_inf.chspec; |
| 298 | } |
| 299 | |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 300 | u16 channel_to_chanspec(struct brcmu_d11inf *d11inf, |
| 301 | struct ieee80211_channel *ch) |
Arend van Spriel | 6e18616 | 2012-10-22 10:36:22 -0700 | [diff] [blame] | 302 | { |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 303 | struct brcmu_chan ch_inf; |
Arend van Spriel | 6e18616 | 2012-10-22 10:36:22 -0700 | [diff] [blame] | 304 | |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 305 | ch_inf.chnum = ieee80211_frequency_to_channel(ch->center_freq); |
| 306 | ch_inf.bw = BRCMU_CHAN_BW_20; |
| 307 | d11inf->encchspec(&ch_inf); |
Arend van Spriel | 6e18616 | 2012-10-22 10:36:22 -0700 | [diff] [blame] | 308 | |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 309 | return ch_inf.chspec; |
Arend van Spriel | 6e18616 | 2012-10-22 10:36:22 -0700 | [diff] [blame] | 310 | } |
| 311 | |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 312 | /* Traverse a string of 1-byte tag/1-byte length/variable-length value |
| 313 | * triples, returning a pointer to the substring whose first element |
| 314 | * matches tag |
| 315 | */ |
Johannes Berg | 4b5800f | 2014-01-15 14:55:59 +0100 | [diff] [blame] | 316 | const struct brcmf_tlv * |
| 317 | brcmf_parse_tlvs(const void *buf, int buflen, uint key) |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 318 | { |
Johannes Berg | 4b5800f | 2014-01-15 14:55:59 +0100 | [diff] [blame] | 319 | const struct brcmf_tlv *elt = buf; |
| 320 | int totlen = buflen; |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 321 | |
| 322 | /* find tagged parameter */ |
| 323 | while (totlen >= TLV_HDR_LEN) { |
| 324 | int len = elt->len; |
| 325 | |
| 326 | /* validate remaining totlen */ |
| 327 | if ((elt->id == key) && (totlen >= (len + TLV_HDR_LEN))) |
| 328 | return elt; |
| 329 | |
| 330 | elt = (struct brcmf_tlv *)((u8 *)elt + (len + TLV_HDR_LEN)); |
| 331 | totlen -= (len + TLV_HDR_LEN); |
| 332 | } |
| 333 | |
| 334 | return NULL; |
| 335 | } |
| 336 | |
| 337 | /* Is any of the tlvs the expected entry? If |
| 338 | * not update the tlvs buffer pointer/length. |
| 339 | */ |
| 340 | static bool |
Johannes Berg | 4b5800f | 2014-01-15 14:55:59 +0100 | [diff] [blame] | 341 | brcmf_tlv_has_ie(const u8 *ie, const u8 **tlvs, u32 *tlvs_len, |
| 342 | const u8 *oui, u32 oui_len, u8 type) |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 343 | { |
| 344 | /* If the contents match the OUI and the type */ |
| 345 | if (ie[TLV_LEN_OFF] >= oui_len + 1 && |
| 346 | !memcmp(&ie[TLV_BODY_OFF], oui, oui_len) && |
| 347 | type == ie[TLV_BODY_OFF + oui_len]) { |
| 348 | return true; |
| 349 | } |
| 350 | |
| 351 | if (tlvs == NULL) |
| 352 | return false; |
| 353 | /* point to the next ie */ |
| 354 | ie += ie[TLV_LEN_OFF] + TLV_HDR_LEN; |
| 355 | /* calculate the length of the rest of the buffer */ |
| 356 | *tlvs_len -= (int)(ie - *tlvs); |
| 357 | /* update the pointer to the start of the buffer */ |
| 358 | *tlvs = ie; |
| 359 | |
| 360 | return false; |
| 361 | } |
| 362 | |
| 363 | static struct brcmf_vs_tlv * |
Johannes Berg | 4b5800f | 2014-01-15 14:55:59 +0100 | [diff] [blame] | 364 | brcmf_find_wpaie(const u8 *parse, u32 len) |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 365 | { |
Johannes Berg | 4b5800f | 2014-01-15 14:55:59 +0100 | [diff] [blame] | 366 | const struct brcmf_tlv *ie; |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 367 | |
| 368 | while ((ie = brcmf_parse_tlvs(parse, len, WLAN_EID_VENDOR_SPECIFIC))) { |
Johannes Berg | 4b5800f | 2014-01-15 14:55:59 +0100 | [diff] [blame] | 369 | if (brcmf_tlv_has_ie((const u8 *)ie, &parse, &len, |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 370 | WPA_OUI, TLV_OUI_LEN, WPA_OUI_TYPE)) |
| 371 | return (struct brcmf_vs_tlv *)ie; |
| 372 | } |
| 373 | return NULL; |
| 374 | } |
| 375 | |
| 376 | static struct brcmf_vs_tlv * |
Johannes Berg | 4b5800f | 2014-01-15 14:55:59 +0100 | [diff] [blame] | 377 | brcmf_find_wpsie(const u8 *parse, u32 len) |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 378 | { |
Johannes Berg | 4b5800f | 2014-01-15 14:55:59 +0100 | [diff] [blame] | 379 | const struct brcmf_tlv *ie; |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 380 | |
| 381 | while ((ie = brcmf_parse_tlvs(parse, len, WLAN_EID_VENDOR_SPECIFIC))) { |
| 382 | if (brcmf_tlv_has_ie((u8 *)ie, &parse, &len, |
| 383 | WPA_OUI, TLV_OUI_LEN, WPS_OUI_TYPE)) |
| 384 | return (struct brcmf_vs_tlv *)ie; |
| 385 | } |
| 386 | return NULL; |
| 387 | } |
| 388 | |
Arend van Spriel | 39504a2 | 2015-08-20 22:06:05 +0200 | [diff] [blame] | 389 | static int brcmf_vif_change_validate(struct brcmf_cfg80211_info *cfg, |
| 390 | struct brcmf_cfg80211_vif *vif, |
| 391 | enum nl80211_iftype new_type) |
| 392 | { |
| 393 | int iftype_num[NUM_NL80211_IFTYPES]; |
| 394 | struct brcmf_cfg80211_vif *pos; |
| 395 | |
| 396 | memset(&iftype_num[0], 0, sizeof(iftype_num)); |
| 397 | list_for_each_entry(pos, &cfg->vif_list, list) |
| 398 | if (pos == vif) |
| 399 | iftype_num[new_type]++; |
| 400 | else |
| 401 | iftype_num[pos->wdev.iftype]++; |
| 402 | |
| 403 | return cfg80211_check_combinations(cfg->wiphy, 1, 0, iftype_num); |
| 404 | } |
| 405 | |
| 406 | static int brcmf_vif_add_validate(struct brcmf_cfg80211_info *cfg, |
| 407 | enum nl80211_iftype new_type) |
| 408 | { |
| 409 | int iftype_num[NUM_NL80211_IFTYPES]; |
| 410 | struct brcmf_cfg80211_vif *pos; |
| 411 | |
| 412 | memset(&iftype_num[0], 0, sizeof(iftype_num)); |
| 413 | list_for_each_entry(pos, &cfg->vif_list, list) |
| 414 | iftype_num[pos->wdev.iftype]++; |
| 415 | |
| 416 | iftype_num[new_type]++; |
| 417 | return cfg80211_check_combinations(cfg->wiphy, 1, 0, iftype_num); |
| 418 | } |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 419 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 420 | static void convert_key_from_CPU(struct brcmf_wsec_key *key, |
| 421 | struct brcmf_wsec_key_le *key_le) |
| 422 | { |
| 423 | key_le->index = cpu_to_le32(key->index); |
| 424 | key_le->len = cpu_to_le32(key->len); |
| 425 | key_le->algo = cpu_to_le32(key->algo); |
| 426 | key_le->flags = cpu_to_le32(key->flags); |
| 427 | key_le->rxiv.hi = cpu_to_le32(key->rxiv.hi); |
| 428 | key_le->rxiv.lo = cpu_to_le16(key->rxiv.lo); |
| 429 | key_le->iv_initialized = cpu_to_le32(key->iv_initialized); |
| 430 | memcpy(key_le->data, key->data, sizeof(key->data)); |
| 431 | memcpy(key_le->ea, key->ea, sizeof(key->ea)); |
| 432 | } |
| 433 | |
Hante Meuleman | f09d0c0 | 2012-09-27 14:17:48 +0200 | [diff] [blame] | 434 | static int |
Hante Meuleman | 118eb30 | 2014-12-21 12:43:49 +0100 | [diff] [blame] | 435 | 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] | 436 | { |
| 437 | int err; |
| 438 | struct brcmf_wsec_key_le key_le; |
| 439 | |
| 440 | convert_key_from_CPU(key, &key_le); |
Hante Meuleman | f09d0c0 | 2012-09-27 14:17:48 +0200 | [diff] [blame] | 441 | |
Hante Meuleman | 118eb30 | 2014-12-21 12:43:49 +0100 | [diff] [blame] | 442 | brcmf_netdev_wait_pend8021x(ifp); |
Hante Meuleman | 81f5dcb | 2012-10-22 10:36:14 -0700 | [diff] [blame] | 443 | |
Hante Meuleman | 118eb30 | 2014-12-21 12:43:49 +0100 | [diff] [blame] | 444 | err = brcmf_fil_bsscfg_data_set(ifp, "wsec_key", &key_le, |
Hante Meuleman | 81f5dcb | 2012-10-22 10:36:14 -0700 | [diff] [blame] | 445 | sizeof(key_le)); |
Hante Meuleman | f09d0c0 | 2012-09-27 14:17:48 +0200 | [diff] [blame] | 446 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 447 | if (err) |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 448 | brcmf_err("wsec_key error (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 449 | return err; |
| 450 | } |
| 451 | |
Hante Meuleman | b365745 | 2013-05-27 21:09:53 +0200 | [diff] [blame] | 452 | static s32 |
| 453 | brcmf_configure_arp_offload(struct brcmf_if *ifp, bool enable) |
| 454 | { |
| 455 | s32 err; |
| 456 | u32 mode; |
| 457 | |
| 458 | if (enable) |
| 459 | mode = BRCMF_ARP_OL_AGENT | BRCMF_ARP_OL_PEER_AUTO_REPLY; |
| 460 | else |
| 461 | mode = 0; |
| 462 | |
| 463 | /* Try to set and enable ARP offload feature, this may fail, then it */ |
| 464 | /* is simply not supported and err 0 will be returned */ |
| 465 | err = brcmf_fil_iovar_int_set(ifp, "arp_ol", mode); |
| 466 | if (err) { |
| 467 | brcmf_dbg(TRACE, "failed to set ARP offload mode to 0x%x, err = %d\n", |
| 468 | mode, err); |
| 469 | err = 0; |
| 470 | } else { |
| 471 | err = brcmf_fil_iovar_int_set(ifp, "arpoe", enable); |
| 472 | if (err) { |
| 473 | brcmf_dbg(TRACE, "failed to configure (%d) ARP offload err = %d\n", |
| 474 | enable, err); |
| 475 | err = 0; |
| 476 | } else |
| 477 | brcmf_dbg(TRACE, "successfully configured (%d) ARP offload to 0x%x\n", |
| 478 | enable, mode); |
| 479 | } |
| 480 | |
| 481 | return err; |
| 482 | } |
| 483 | |
Hante Meuleman | 8851cce | 2014-07-30 13:20:02 +0200 | [diff] [blame] | 484 | static void |
| 485 | brcmf_cfg80211_update_proto_addr_mode(struct wireless_dev *wdev) |
| 486 | { |
Arend van Spriel | 8f2b459 | 2014-09-11 22:51:32 +0200 | [diff] [blame] | 487 | struct brcmf_cfg80211_vif *vif; |
| 488 | struct brcmf_if *ifp; |
| 489 | |
| 490 | vif = container_of(wdev, struct brcmf_cfg80211_vif, wdev); |
| 491 | ifp = vif->ifp; |
Hante Meuleman | 8851cce | 2014-07-30 13:20:02 +0200 | [diff] [blame] | 492 | |
| 493 | if ((wdev->iftype == NL80211_IFTYPE_ADHOC) || |
| 494 | (wdev->iftype == NL80211_IFTYPE_AP) || |
| 495 | (wdev->iftype == NL80211_IFTYPE_P2P_GO)) |
| 496 | brcmf_proto_configure_addr_mode(ifp->drvr, ifp->ifidx, |
| 497 | ADDR_DIRECT); |
| 498 | else |
| 499 | brcmf_proto_configure_addr_mode(ifp->drvr, ifp->ifidx, |
| 500 | ADDR_INDIRECT); |
| 501 | } |
| 502 | |
Hante Meuleman | a44aa40 | 2014-12-03 21:05:33 +0100 | [diff] [blame] | 503 | static int brcmf_cfg80211_request_ap_if(struct brcmf_if *ifp) |
| 504 | { |
| 505 | struct brcmf_mbss_ssid_le mbss_ssid_le; |
| 506 | int bsscfgidx; |
| 507 | int err; |
| 508 | |
| 509 | memset(&mbss_ssid_le, 0, sizeof(mbss_ssid_le)); |
| 510 | bsscfgidx = brcmf_get_next_free_bsscfgidx(ifp->drvr); |
| 511 | if (bsscfgidx < 0) |
| 512 | return bsscfgidx; |
| 513 | |
| 514 | mbss_ssid_le.bsscfgidx = cpu_to_le32(bsscfgidx); |
| 515 | mbss_ssid_le.SSID_len = cpu_to_le32(5); |
| 516 | sprintf(mbss_ssid_le.SSID, "ssid%d" , bsscfgidx); |
| 517 | |
| 518 | err = brcmf_fil_bsscfg_data_set(ifp, "bsscfg:ssid", &mbss_ssid_le, |
| 519 | sizeof(mbss_ssid_le)); |
| 520 | if (err < 0) |
| 521 | brcmf_err("setting ssid failed %d\n", err); |
| 522 | |
| 523 | return err; |
| 524 | } |
| 525 | |
| 526 | /** |
| 527 | * brcmf_ap_add_vif() - create a new AP virtual interface for multiple BSS |
| 528 | * |
| 529 | * @wiphy: wiphy device of new interface. |
| 530 | * @name: name of the new interface. |
| 531 | * @flags: not used. |
| 532 | * @params: contains mac address for AP device. |
| 533 | */ |
| 534 | static |
| 535 | struct wireless_dev *brcmf_ap_add_vif(struct wiphy *wiphy, const char *name, |
| 536 | u32 *flags, struct vif_params *params) |
| 537 | { |
| 538 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); |
| 539 | struct brcmf_if *ifp = netdev_priv(cfg_to_ndev(cfg)); |
| 540 | struct brcmf_cfg80211_vif *vif; |
| 541 | int err; |
| 542 | |
| 543 | if (brcmf_cfg80211_vif_event_armed(cfg)) |
| 544 | return ERR_PTR(-EBUSY); |
| 545 | |
| 546 | brcmf_dbg(INFO, "Adding vif \"%s\"\n", name); |
| 547 | |
| 548 | vif = brcmf_alloc_vif(cfg, NL80211_IFTYPE_AP, false); |
| 549 | if (IS_ERR(vif)) |
| 550 | return (struct wireless_dev *)vif; |
| 551 | |
| 552 | brcmf_cfg80211_arm_vif_event(cfg, vif); |
| 553 | |
| 554 | err = brcmf_cfg80211_request_ap_if(ifp); |
| 555 | if (err) { |
| 556 | brcmf_cfg80211_arm_vif_event(cfg, NULL); |
| 557 | goto fail; |
| 558 | } |
| 559 | |
| 560 | /* wait for firmware event */ |
| 561 | err = brcmf_cfg80211_wait_vif_event_timeout(cfg, BRCMF_E_IF_ADD, |
| 562 | msecs_to_jiffies(1500)); |
| 563 | brcmf_cfg80211_arm_vif_event(cfg, NULL); |
| 564 | if (!err) { |
| 565 | brcmf_err("timeout occurred\n"); |
| 566 | err = -EIO; |
| 567 | goto fail; |
| 568 | } |
| 569 | |
| 570 | /* interface created in firmware */ |
| 571 | ifp = vif->ifp; |
| 572 | if (!ifp) { |
| 573 | brcmf_err("no if pointer provided\n"); |
| 574 | err = -ENOENT; |
| 575 | goto fail; |
| 576 | } |
| 577 | |
| 578 | strncpy(ifp->ndev->name, name, sizeof(ifp->ndev->name) - 1); |
| 579 | err = brcmf_net_attach(ifp, true); |
| 580 | if (err) { |
| 581 | brcmf_err("Registering netdevice failed\n"); |
| 582 | goto fail; |
| 583 | } |
| 584 | |
| 585 | return &ifp->vif->wdev; |
| 586 | |
| 587 | fail: |
| 588 | brcmf_free_vif(vif); |
| 589 | return ERR_PTR(err); |
| 590 | } |
| 591 | |
Arend van Spriel | 967fe2c | 2014-03-15 17:18:21 +0100 | [diff] [blame] | 592 | static bool brcmf_is_apmode(struct brcmf_cfg80211_vif *vif) |
| 593 | { |
| 594 | enum nl80211_iftype iftype; |
| 595 | |
| 596 | iftype = vif->wdev.iftype; |
| 597 | return iftype == NL80211_IFTYPE_AP || iftype == NL80211_IFTYPE_P2P_GO; |
| 598 | } |
| 599 | |
| 600 | static bool brcmf_is_ibssmode(struct brcmf_cfg80211_vif *vif) |
| 601 | { |
| 602 | return vif->wdev.iftype == NL80211_IFTYPE_ADHOC; |
| 603 | } |
| 604 | |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 605 | static struct wireless_dev *brcmf_cfg80211_add_iface(struct wiphy *wiphy, |
| 606 | const char *name, |
Tom Gundersen | 6bab2e19 | 2015-03-18 11:13:39 +0100 | [diff] [blame] | 607 | unsigned char name_assign_type, |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 608 | enum nl80211_iftype type, |
| 609 | u32 *flags, |
| 610 | struct vif_params *params) |
| 611 | { |
Hante Meuleman | 8851cce | 2014-07-30 13:20:02 +0200 | [diff] [blame] | 612 | struct wireless_dev *wdev; |
Arend van Spriel | 39504a2 | 2015-08-20 22:06:05 +0200 | [diff] [blame] | 613 | int err; |
Hante Meuleman | 8851cce | 2014-07-30 13:20:02 +0200 | [diff] [blame] | 614 | |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 615 | brcmf_dbg(TRACE, "enter: %s type %d\n", name, type); |
Arend van Spriel | 39504a2 | 2015-08-20 22:06:05 +0200 | [diff] [blame] | 616 | err = brcmf_vif_add_validate(wiphy_to_cfg(wiphy), type); |
| 617 | if (err) { |
| 618 | brcmf_err("iface validation failed: err=%d\n", err); |
| 619 | return ERR_PTR(err); |
| 620 | } |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 621 | switch (type) { |
| 622 | case NL80211_IFTYPE_ADHOC: |
| 623 | case NL80211_IFTYPE_STATION: |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 624 | case NL80211_IFTYPE_AP_VLAN: |
| 625 | case NL80211_IFTYPE_WDS: |
| 626 | case NL80211_IFTYPE_MONITOR: |
| 627 | case NL80211_IFTYPE_MESH_POINT: |
| 628 | return ERR_PTR(-EOPNOTSUPP); |
Hante Meuleman | a44aa40 | 2014-12-03 21:05:33 +0100 | [diff] [blame] | 629 | case NL80211_IFTYPE_AP: |
| 630 | wdev = brcmf_ap_add_vif(wiphy, name, flags, params); |
| 631 | if (!IS_ERR(wdev)) |
| 632 | brcmf_cfg80211_update_proto_addr_mode(wdev); |
| 633 | return wdev; |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 634 | case NL80211_IFTYPE_P2P_CLIENT: |
| 635 | case NL80211_IFTYPE_P2P_GO: |
Arend van Spriel | 27f10e3 | 2013-04-05 10:57:50 +0200 | [diff] [blame] | 636 | case NL80211_IFTYPE_P2P_DEVICE: |
Tom Gundersen | 6bab2e19 | 2015-03-18 11:13:39 +0100 | [diff] [blame] | 637 | 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] | 638 | if (!IS_ERR(wdev)) |
| 639 | brcmf_cfg80211_update_proto_addr_mode(wdev); |
| 640 | return wdev; |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 641 | case NL80211_IFTYPE_UNSPECIFIED: |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 642 | default: |
| 643 | return ERR_PTR(-EINVAL); |
| 644 | } |
| 645 | } |
| 646 | |
Daniel Kim | 5e787f7 | 2014-06-21 12:11:18 +0200 | [diff] [blame] | 647 | static void brcmf_scan_config_mpc(struct brcmf_if *ifp, int mpc) |
| 648 | { |
Arend van Spriel | c08437b | 2014-07-12 08:49:39 +0200 | [diff] [blame] | 649 | if (brcmf_feat_is_quirk_enabled(ifp, BRCMF_FEAT_QUIRK_NEED_MPC)) |
Daniel Kim | 5e787f7 | 2014-06-21 12:11:18 +0200 | [diff] [blame] | 650 | brcmf_set_mpc(ifp, mpc); |
| 651 | } |
| 652 | |
Arend van Spriel | f96aa07 | 2013-04-05 10:57:48 +0200 | [diff] [blame] | 653 | void brcmf_set_mpc(struct brcmf_if *ifp, int mpc) |
Arend van Spriel | 5f4f9f1 | 2013-02-08 15:53:41 +0100 | [diff] [blame] | 654 | { |
Arend van Spriel | 5f4f9f1 | 2013-02-08 15:53:41 +0100 | [diff] [blame] | 655 | s32 err = 0; |
| 656 | |
| 657 | if (check_vif_up(ifp->vif)) { |
| 658 | err = brcmf_fil_iovar_int_set(ifp, "mpc", mpc); |
| 659 | if (err) { |
| 660 | brcmf_err("fail to set mpc\n"); |
| 661 | return; |
| 662 | } |
| 663 | brcmf_dbg(INFO, "MPC : %d\n", mpc); |
| 664 | } |
| 665 | } |
| 666 | |
Arend van Spriel | a0f472a | 2013-04-05 10:57:49 +0200 | [diff] [blame] | 667 | s32 brcmf_notify_escan_complete(struct brcmf_cfg80211_info *cfg, |
| 668 | struct brcmf_if *ifp, bool aborted, |
| 669 | bool fw_abort) |
Arend van Spriel | 5f4f9f1 | 2013-02-08 15:53:41 +0100 | [diff] [blame] | 670 | { |
| 671 | struct brcmf_scan_params_le params_le; |
| 672 | struct cfg80211_scan_request *scan_request; |
| 673 | s32 err = 0; |
| 674 | |
| 675 | brcmf_dbg(SCAN, "Enter\n"); |
| 676 | |
| 677 | /* clear scan request, because the FW abort can cause a second call */ |
| 678 | /* to this functon and might cause a double cfg80211_scan_done */ |
| 679 | scan_request = cfg->scan_request; |
| 680 | cfg->scan_request = NULL; |
| 681 | |
| 682 | if (timer_pending(&cfg->escan_timeout)) |
| 683 | del_timer_sync(&cfg->escan_timeout); |
| 684 | |
| 685 | if (fw_abort) { |
| 686 | /* Do a scan abort to stop the driver's scan engine */ |
| 687 | brcmf_dbg(SCAN, "ABORT scan in firmware\n"); |
| 688 | memset(¶ms_le, 0, sizeof(params_le)); |
Joe Perches | 93803b3 | 2015-03-02 19:54:49 -0800 | [diff] [blame] | 689 | eth_broadcast_addr(params_le.bssid); |
Arend van Spriel | 5f4f9f1 | 2013-02-08 15:53:41 +0100 | [diff] [blame] | 690 | params_le.bss_type = DOT11_BSSTYPE_ANY; |
| 691 | params_le.scan_type = 0; |
| 692 | params_le.channel_num = cpu_to_le32(1); |
| 693 | params_le.nprobes = cpu_to_le32(1); |
| 694 | params_le.active_time = cpu_to_le32(-1); |
| 695 | params_le.passive_time = cpu_to_le32(-1); |
| 696 | params_le.home_time = cpu_to_le32(-1); |
| 697 | /* Scan is aborted by setting channel_list[0] to -1 */ |
| 698 | params_le.channel_list[0] = cpu_to_le16(-1); |
| 699 | /* E-Scan (or anyother type) can be aborted by SCAN */ |
Arend van Spriel | f96aa07 | 2013-04-05 10:57:48 +0200 | [diff] [blame] | 700 | err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SCAN, |
Arend van Spriel | 5f4f9f1 | 2013-02-08 15:53:41 +0100 | [diff] [blame] | 701 | ¶ms_le, sizeof(params_le)); |
| 702 | if (err) |
| 703 | brcmf_err("Scan abort failed\n"); |
| 704 | } |
Arend van Spriel | 0f0fe99 | 2014-05-27 12:56:14 +0200 | [diff] [blame] | 705 | |
Daniel Kim | 5e787f7 | 2014-06-21 12:11:18 +0200 | [diff] [blame] | 706 | brcmf_scan_config_mpc(ifp, 1); |
Arend van Spriel | 0f0fe99 | 2014-05-27 12:56:14 +0200 | [diff] [blame] | 707 | |
Arend van Spriel | 5f4f9f1 | 2013-02-08 15:53:41 +0100 | [diff] [blame] | 708 | /* |
| 709 | * e-scan can be initiated by scheduled scan |
| 710 | * which takes precedence. |
| 711 | */ |
| 712 | if (cfg->sched_escan) { |
| 713 | brcmf_dbg(SCAN, "scheduled scan completed\n"); |
| 714 | cfg->sched_escan = false; |
| 715 | if (!aborted) |
| 716 | cfg80211_sched_scan_results(cfg_to_wiphy(cfg)); |
Arend van Spriel | 5f4f9f1 | 2013-02-08 15:53:41 +0100 | [diff] [blame] | 717 | } else if (scan_request) { |
| 718 | brcmf_dbg(SCAN, "ESCAN Completed scan: %s\n", |
| 719 | aborted ? "Aborted" : "Done"); |
| 720 | cfg80211_scan_done(scan_request, aborted); |
Arend van Spriel | 5f4f9f1 | 2013-02-08 15:53:41 +0100 | [diff] [blame] | 721 | } |
Hante Meuleman | 6eda4e2 | 2013-02-08 15:54:02 +0100 | [diff] [blame] | 722 | if (!test_and_clear_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status)) |
| 723 | brcmf_dbg(SCAN, "Scan complete, probably P2P scan\n"); |
Arend van Spriel | 5f4f9f1 | 2013-02-08 15:53:41 +0100 | [diff] [blame] | 724 | |
| 725 | return err; |
| 726 | } |
| 727 | |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 728 | static |
| 729 | int brcmf_cfg80211_del_iface(struct wiphy *wiphy, struct wireless_dev *wdev) |
| 730 | { |
Arend van Spriel | 5f4f9f1 | 2013-02-08 15:53:41 +0100 | [diff] [blame] | 731 | struct brcmf_cfg80211_info *cfg = wiphy_priv(wiphy); |
| 732 | struct net_device *ndev = wdev->netdev; |
| 733 | |
| 734 | /* vif event pending in firmware */ |
| 735 | if (brcmf_cfg80211_vif_event_armed(cfg)) |
| 736 | return -EBUSY; |
| 737 | |
| 738 | if (ndev) { |
| 739 | if (test_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status) && |
Arend van Spriel | a0f472a | 2013-04-05 10:57:49 +0200 | [diff] [blame] | 740 | cfg->escan_info.ifp == netdev_priv(ndev)) |
| 741 | brcmf_notify_escan_complete(cfg, netdev_priv(ndev), |
| 742 | true, true); |
Arend van Spriel | 5f4f9f1 | 2013-02-08 15:53:41 +0100 | [diff] [blame] | 743 | |
| 744 | brcmf_fil_iovar_int_set(netdev_priv(ndev), "mpc", 1); |
| 745 | } |
| 746 | |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 747 | switch (wdev->iftype) { |
| 748 | case NL80211_IFTYPE_ADHOC: |
| 749 | case NL80211_IFTYPE_STATION: |
| 750 | case NL80211_IFTYPE_AP: |
| 751 | case NL80211_IFTYPE_AP_VLAN: |
| 752 | case NL80211_IFTYPE_WDS: |
| 753 | case NL80211_IFTYPE_MONITOR: |
| 754 | case NL80211_IFTYPE_MESH_POINT: |
| 755 | return -EOPNOTSUPP; |
| 756 | case NL80211_IFTYPE_P2P_CLIENT: |
| 757 | case NL80211_IFTYPE_P2P_GO: |
Arend van Spriel | 27f10e3 | 2013-04-05 10:57:50 +0200 | [diff] [blame] | 758 | case NL80211_IFTYPE_P2P_DEVICE: |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 759 | return brcmf_p2p_del_vif(wiphy, wdev); |
| 760 | case NL80211_IFTYPE_UNSPECIFIED: |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 761 | default: |
| 762 | return -EINVAL; |
| 763 | } |
| 764 | return -EOPNOTSUPP; |
| 765 | } |
| 766 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 767 | static s32 |
| 768 | brcmf_cfg80211_change_iface(struct wiphy *wiphy, struct net_device *ndev, |
| 769 | enum nl80211_iftype type, u32 *flags, |
| 770 | struct vif_params *params) |
| 771 | { |
Hante Meuleman | 7a5c1f6 | 2013-02-08 15:53:44 +0100 | [diff] [blame] | 772 | struct brcmf_cfg80211_info *cfg = wiphy_priv(wiphy); |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 773 | struct brcmf_if *ifp = netdev_priv(ndev); |
Arend van Spriel | 128ce3b | 2012-11-28 21:44:12 +0100 | [diff] [blame] | 774 | struct brcmf_cfg80211_vif *vif = ifp->vif; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 775 | s32 infra = 0; |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 776 | s32 ap = 0; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 777 | s32 err = 0; |
| 778 | |
Arend van Spriel | 39504a2 | 2015-08-20 22:06:05 +0200 | [diff] [blame] | 779 | brcmf_dbg(TRACE, "Enter, idx=%d, type=%d\n", ifp->bssidx, type); |
Hante Meuleman | 178e9ef | 2015-09-18 22:08:11 +0200 | [diff] [blame] | 780 | |
| 781 | /* WAR: There are a number of p2p interface related problems which |
| 782 | * need to be handled initially (before doing the validate). |
| 783 | * wpa_supplicant tends to do iface changes on p2p device/client/go |
| 784 | * which are not always possible/allowed. However we need to return |
| 785 | * OK otherwise the wpa_supplicant wont start. The situation differs |
| 786 | * on configuration and setup (p2pon=1 module param). The first check |
| 787 | * is to see if the request is a change to station for p2p iface. |
| 788 | */ |
| 789 | if ((type == NL80211_IFTYPE_STATION) && |
| 790 | ((vif->wdev.iftype == NL80211_IFTYPE_P2P_CLIENT) || |
| 791 | (vif->wdev.iftype == NL80211_IFTYPE_P2P_GO) || |
| 792 | (vif->wdev.iftype == NL80211_IFTYPE_P2P_DEVICE))) { |
| 793 | brcmf_dbg(TRACE, "Ignoring cmd for p2p if\n"); |
| 794 | /* Now depending on whether module param p2pon=1 was used the |
| 795 | * response needs to be either 0 or EOPNOTSUPP. The reason is |
| 796 | * that if p2pon=1 is used, but a newer supplicant is used then |
| 797 | * we should return an error, as this combination wont work. |
| 798 | * In other situations 0 is returned and supplicant will start |
| 799 | * normally. It will give a trace in cfg80211, but it is the |
| 800 | * only way to get it working. Unfortunately this will result |
| 801 | * in situation where we wont support new supplicant in |
| 802 | * combination with module param p2pon=1, but that is the way |
| 803 | * it is. If the user tries this then unloading of driver might |
| 804 | * fail/lock. |
| 805 | */ |
| 806 | if (cfg->p2p.p2pdev_dynamically) |
| 807 | return -EOPNOTSUPP; |
| 808 | else |
| 809 | return 0; |
| 810 | } |
Arend van Spriel | 39504a2 | 2015-08-20 22:06:05 +0200 | [diff] [blame] | 811 | err = brcmf_vif_change_validate(wiphy_to_cfg(wiphy), vif, type); |
| 812 | if (err) { |
| 813 | brcmf_err("iface validation failed: err=%d\n", err); |
| 814 | return err; |
| 815 | } |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 816 | switch (type) { |
| 817 | case NL80211_IFTYPE_MONITOR: |
| 818 | case NL80211_IFTYPE_WDS: |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 819 | brcmf_err("type (%d) : currently we do not support this type\n", |
| 820 | type); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 821 | return -EOPNOTSUPP; |
| 822 | case NL80211_IFTYPE_ADHOC: |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 823 | infra = 0; |
| 824 | break; |
| 825 | case NL80211_IFTYPE_STATION: |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 826 | infra = 1; |
| 827 | break; |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 828 | case NL80211_IFTYPE_AP: |
Hante Meuleman | 7a5c1f6 | 2013-02-08 15:53:44 +0100 | [diff] [blame] | 829 | case NL80211_IFTYPE_P2P_GO: |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 830 | ap = 1; |
| 831 | break; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 832 | default: |
| 833 | err = -EINVAL; |
| 834 | goto done; |
| 835 | } |
| 836 | |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 837 | if (ap) { |
Hante Meuleman | 7a5c1f6 | 2013-02-08 15:53:44 +0100 | [diff] [blame] | 838 | if (type == NL80211_IFTYPE_P2P_GO) { |
| 839 | brcmf_dbg(INFO, "IF Type = P2P GO\n"); |
| 840 | err = brcmf_p2p_ifchange(cfg, BRCMF_FIL_P2P_IF_GO); |
| 841 | } |
| 842 | if (!err) { |
| 843 | set_bit(BRCMF_VIF_STATUS_AP_CREATING, &vif->sme_state); |
| 844 | brcmf_dbg(INFO, "IF Type = AP\n"); |
| 845 | } |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 846 | } else { |
Arend van Spriel | 128ce3b | 2012-11-28 21:44:12 +0100 | [diff] [blame] | 847 | err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_INFRA, infra); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 848 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 849 | brcmf_err("WLC_SET_INFRA error (%d)\n", err); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 850 | err = -EAGAIN; |
| 851 | goto done; |
| 852 | } |
Arend van Spriel | 967fe2c | 2014-03-15 17:18:21 +0100 | [diff] [blame] | 853 | brcmf_dbg(INFO, "IF Type = %s\n", brcmf_is_ibssmode(vif) ? |
Arend van Spriel | 647c9ae | 2012-12-05 15:26:01 +0100 | [diff] [blame] | 854 | "Adhoc" : "Infra"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 855 | } |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 856 | ndev->ieee80211_ptr->iftype = type; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 857 | |
Hante Meuleman | 8851cce | 2014-07-30 13:20:02 +0200 | [diff] [blame] | 858 | brcmf_cfg80211_update_proto_addr_mode(&vif->wdev); |
| 859 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 860 | done: |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 861 | brcmf_dbg(TRACE, "Exit\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 862 | |
| 863 | return err; |
| 864 | } |
| 865 | |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 866 | static void brcmf_escan_prep(struct brcmf_cfg80211_info *cfg, |
| 867 | struct brcmf_scan_params_le *params_le, |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 868 | struct cfg80211_scan_request *request) |
| 869 | { |
| 870 | u32 n_ssids; |
| 871 | u32 n_channels; |
| 872 | s32 i; |
| 873 | s32 offset; |
Arend van Spriel | 029591f | 2012-09-19 22:21:06 +0200 | [diff] [blame] | 874 | u16 chanspec; |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 875 | char *ptr; |
Arend van Spriel | 029591f | 2012-09-19 22:21:06 +0200 | [diff] [blame] | 876 | struct brcmf_ssid_le ssid_le; |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 877 | |
Joe Perches | 93803b3 | 2015-03-02 19:54:49 -0800 | [diff] [blame] | 878 | eth_broadcast_addr(params_le->bssid); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 879 | params_le->bss_type = DOT11_BSSTYPE_ANY; |
| 880 | params_le->scan_type = 0; |
| 881 | params_le->channel_num = 0; |
| 882 | params_le->nprobes = cpu_to_le32(-1); |
| 883 | params_le->active_time = cpu_to_le32(-1); |
| 884 | params_le->passive_time = cpu_to_le32(-1); |
| 885 | params_le->home_time = cpu_to_le32(-1); |
| 886 | memset(¶ms_le->ssid_le, 0, sizeof(params_le->ssid_le)); |
| 887 | |
| 888 | /* if request is null exit so it will be all channel broadcast scan */ |
| 889 | if (!request) |
| 890 | return; |
| 891 | |
| 892 | n_ssids = request->n_ssids; |
| 893 | n_channels = request->n_channels; |
| 894 | /* Copy channel array if applicable */ |
Arend van Spriel | 4e8a008 | 2012-12-05 15:26:03 +0100 | [diff] [blame] | 895 | brcmf_dbg(SCAN, "### List of channelspecs to scan ### %d\n", |
| 896 | n_channels); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 897 | if (n_channels > 0) { |
| 898 | for (i = 0; i < n_channels; i++) { |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 899 | chanspec = channel_to_chanspec(&cfg->d11inf, |
| 900 | request->channels[i]); |
Arend van Spriel | 4e8a008 | 2012-12-05 15:26:03 +0100 | [diff] [blame] | 901 | brcmf_dbg(SCAN, "Chan : %d, Channel spec: %x\n", |
| 902 | request->channels[i]->hw_value, chanspec); |
Arend van Spriel | 029591f | 2012-09-19 22:21:06 +0200 | [diff] [blame] | 903 | params_le->channel_list[i] = cpu_to_le16(chanspec); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 904 | } |
| 905 | } else { |
Arend van Spriel | 4e8a008 | 2012-12-05 15:26:03 +0100 | [diff] [blame] | 906 | brcmf_dbg(SCAN, "Scanning all channels\n"); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 907 | } |
| 908 | /* Copy ssid array if applicable */ |
Arend van Spriel | 4e8a008 | 2012-12-05 15:26:03 +0100 | [diff] [blame] | 909 | brcmf_dbg(SCAN, "### List of SSIDs to scan ### %d\n", n_ssids); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 910 | if (n_ssids > 0) { |
| 911 | offset = offsetof(struct brcmf_scan_params_le, channel_list) + |
| 912 | n_channels * sizeof(u16); |
| 913 | offset = roundup(offset, sizeof(u32)); |
| 914 | ptr = (char *)params_le + offset; |
| 915 | for (i = 0; i < n_ssids; i++) { |
Arend van Spriel | 029591f | 2012-09-19 22:21:06 +0200 | [diff] [blame] | 916 | memset(&ssid_le, 0, sizeof(ssid_le)); |
| 917 | ssid_le.SSID_len = |
| 918 | cpu_to_le32(request->ssids[i].ssid_len); |
| 919 | memcpy(ssid_le.SSID, request->ssids[i].ssid, |
| 920 | request->ssids[i].ssid_len); |
| 921 | if (!ssid_le.SSID_len) |
Arend van Spriel | 4e8a008 | 2012-12-05 15:26:03 +0100 | [diff] [blame] | 922 | brcmf_dbg(SCAN, "%d: Broadcast scan\n", i); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 923 | else |
Arend van Spriel | 4e8a008 | 2012-12-05 15:26:03 +0100 | [diff] [blame] | 924 | brcmf_dbg(SCAN, "%d: scan for %s size =%d\n", |
| 925 | i, ssid_le.SSID, ssid_le.SSID_len); |
Arend van Spriel | 029591f | 2012-09-19 22:21:06 +0200 | [diff] [blame] | 926 | memcpy(ptr, &ssid_le, sizeof(ssid_le)); |
| 927 | ptr += sizeof(ssid_le); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 928 | } |
| 929 | } else { |
Arend van Spriel | 4e8a008 | 2012-12-05 15:26:03 +0100 | [diff] [blame] | 930 | brcmf_dbg(SCAN, "Broadcast scan %p\n", request->ssids); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 931 | if ((request->ssids) && request->ssids->ssid_len) { |
Arend van Spriel | 4e8a008 | 2012-12-05 15:26:03 +0100 | [diff] [blame] | 932 | brcmf_dbg(SCAN, "SSID %s len=%d\n", |
| 933 | params_le->ssid_le.SSID, |
| 934 | request->ssids->ssid_len); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 935 | params_le->ssid_le.SSID_len = |
| 936 | cpu_to_le32(request->ssids->ssid_len); |
| 937 | memcpy(¶ms_le->ssid_le.SSID, request->ssids->ssid, |
| 938 | request->ssids->ssid_len); |
| 939 | } |
| 940 | } |
| 941 | /* Adding mask to channel numbers */ |
| 942 | params_le->channel_num = |
| 943 | cpu_to_le32((n_ssids << BRCMF_SCAN_PARAMS_NSSID_SHIFT) | |
| 944 | (n_channels & BRCMF_SCAN_PARAMS_COUNT_MASK)); |
| 945 | } |
| 946 | |
| 947 | static s32 |
Arend van Spriel | a0f472a | 2013-04-05 10:57:49 +0200 | [diff] [blame] | 948 | brcmf_run_escan(struct brcmf_cfg80211_info *cfg, struct brcmf_if *ifp, |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 949 | struct cfg80211_scan_request *request, u16 action) |
| 950 | { |
| 951 | s32 params_size = BRCMF_SCAN_PARAMS_FIXED_SIZE + |
| 952 | offsetof(struct brcmf_escan_params_le, params_le); |
| 953 | struct brcmf_escan_params_le *params; |
| 954 | s32 err = 0; |
| 955 | |
Arend van Spriel | 4e8a008 | 2012-12-05 15:26:03 +0100 | [diff] [blame] | 956 | brcmf_dbg(SCAN, "E-SCAN START\n"); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 957 | |
| 958 | if (request != NULL) { |
| 959 | /* Allocate space for populating ssids in struct */ |
| 960 | params_size += sizeof(u32) * ((request->n_channels + 1) / 2); |
| 961 | |
| 962 | /* Allocate space for populating ssids in struct */ |
| 963 | params_size += sizeof(struct brcmf_ssid) * request->n_ssids; |
| 964 | } |
| 965 | |
| 966 | params = kzalloc(params_size, GFP_KERNEL); |
| 967 | if (!params) { |
| 968 | err = -ENOMEM; |
| 969 | goto exit; |
| 970 | } |
| 971 | BUG_ON(params_size + sizeof("escan") >= BRCMF_DCMD_MEDLEN); |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 972 | brcmf_escan_prep(cfg, ¶ms->params_le, request); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 973 | params->version = cpu_to_le32(BRCMF_ESCAN_REQ_VERSION); |
| 974 | params->action = cpu_to_le16(action); |
| 975 | params->sync_id = cpu_to_le16(0x1234); |
| 976 | |
Arend van Spriel | a0f472a | 2013-04-05 10:57:49 +0200 | [diff] [blame] | 977 | err = brcmf_fil_iovar_data_set(ifp, "escan", params, params_size); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 978 | if (err) { |
| 979 | if (err == -EBUSY) |
Arend van Spriel | 647c9ae | 2012-12-05 15:26:01 +0100 | [diff] [blame] | 980 | brcmf_dbg(INFO, "system busy : escan canceled\n"); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 981 | else |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 982 | brcmf_err("error (%d)\n", err); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 983 | } |
| 984 | |
| 985 | kfree(params); |
| 986 | exit: |
| 987 | return err; |
| 988 | } |
| 989 | |
| 990 | static s32 |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 991 | brcmf_do_escan(struct brcmf_cfg80211_info *cfg, struct wiphy *wiphy, |
Arend van Spriel | a0f472a | 2013-04-05 10:57:49 +0200 | [diff] [blame] | 992 | struct brcmf_if *ifp, struct cfg80211_scan_request *request) |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 993 | { |
| 994 | s32 err; |
Hante Meuleman | 81f5dcb | 2012-10-22 10:36:14 -0700 | [diff] [blame] | 995 | u32 passive_scan; |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 996 | struct brcmf_scan_results *results; |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 997 | struct escan_info *escan = &cfg->escan_info; |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 998 | |
Arend van Spriel | 4e8a008 | 2012-12-05 15:26:03 +0100 | [diff] [blame] | 999 | brcmf_dbg(SCAN, "Enter\n"); |
Arend van Spriel | a0f472a | 2013-04-05 10:57:49 +0200 | [diff] [blame] | 1000 | escan->ifp = ifp; |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 1001 | escan->wiphy = wiphy; |
| 1002 | escan->escan_state = WL_ESCAN_STATE_SCANNING; |
Hante Meuleman | 81f5dcb | 2012-10-22 10:36:14 -0700 | [diff] [blame] | 1003 | passive_scan = cfg->active_scan ? 0 : 1; |
Arend van Spriel | f96aa07 | 2013-04-05 10:57:48 +0200 | [diff] [blame] | 1004 | err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_PASSIVE_SCAN, |
Hante Meuleman | 81f5dcb | 2012-10-22 10:36:14 -0700 | [diff] [blame] | 1005 | passive_scan); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1006 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1007 | brcmf_err("error (%d)\n", err); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1008 | return err; |
| 1009 | } |
Daniel Kim | 5e787f7 | 2014-06-21 12:11:18 +0200 | [diff] [blame] | 1010 | brcmf_scan_config_mpc(ifp, 0); |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 1011 | results = (struct brcmf_scan_results *)cfg->escan_info.escan_buf; |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1012 | results->version = 0; |
| 1013 | results->count = 0; |
| 1014 | results->buflen = WL_ESCAN_RESULTS_FIXED_SIZE; |
| 1015 | |
Arend van Spriel | a0f472a | 2013-04-05 10:57:49 +0200 | [diff] [blame] | 1016 | err = escan->run(cfg, ifp, request, WL_ESCAN_ACTION_START); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1017 | if (err) |
Daniel Kim | 5e787f7 | 2014-06-21 12:11:18 +0200 | [diff] [blame] | 1018 | brcmf_scan_config_mpc(ifp, 1); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1019 | return err; |
| 1020 | } |
| 1021 | |
| 1022 | static s32 |
Arend van Spriel | a0f472a | 2013-04-05 10:57:49 +0200 | [diff] [blame] | 1023 | brcmf_cfg80211_escan(struct wiphy *wiphy, struct brcmf_cfg80211_vif *vif, |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1024 | struct cfg80211_scan_request *request, |
| 1025 | struct cfg80211_ssid *this_ssid) |
| 1026 | { |
Arend van Spriel | a0f472a | 2013-04-05 10:57:49 +0200 | [diff] [blame] | 1027 | struct brcmf_if *ifp = vif->ifp; |
| 1028 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1029 | struct cfg80211_ssid *ssids; |
Hante Meuleman | f0799895 | 2012-11-05 16:22:13 -0800 | [diff] [blame] | 1030 | struct brcmf_cfg80211_scan_req *sr = &cfg->scan_req_int; |
Hante Meuleman | 81f5dcb | 2012-10-22 10:36:14 -0700 | [diff] [blame] | 1031 | u32 passive_scan; |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1032 | bool escan_req; |
| 1033 | bool spec_scan; |
| 1034 | s32 err; |
| 1035 | u32 SSID_len; |
| 1036 | |
Arend van Spriel | 4e8a008 | 2012-12-05 15:26:03 +0100 | [diff] [blame] | 1037 | brcmf_dbg(SCAN, "START ESCAN\n"); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1038 | |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 1039 | if (test_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status)) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1040 | brcmf_err("Scanning already: status (%lu)\n", cfg->scan_status); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1041 | return -EAGAIN; |
| 1042 | } |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 1043 | if (test_bit(BRCMF_SCAN_STATUS_ABORT, &cfg->scan_status)) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1044 | brcmf_err("Scanning being aborted: status (%lu)\n", |
| 1045 | cfg->scan_status); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1046 | return -EAGAIN; |
| 1047 | } |
Arend van Spriel | 1687eee | 2013-04-23 12:53:11 +0200 | [diff] [blame] | 1048 | if (test_bit(BRCMF_SCAN_STATUS_SUPPRESS, &cfg->scan_status)) { |
| 1049 | brcmf_err("Scanning suppressed: status (%lu)\n", |
| 1050 | cfg->scan_status); |
| 1051 | return -EAGAIN; |
| 1052 | } |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 1053 | if (test_bit(BRCMF_VIF_STATUS_CONNECTING, &ifp->vif->sme_state)) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1054 | brcmf_err("Connecting: status (%lu)\n", ifp->vif->sme_state); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1055 | return -EAGAIN; |
| 1056 | } |
| 1057 | |
Hante Meuleman | 0f8ffe1 | 2013-02-08 15:53:42 +0100 | [diff] [blame] | 1058 | /* 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] | 1059 | if (vif == cfg->p2p.bss_idx[P2PAPI_BSSCFG_DEVICE].vif) |
| 1060 | vif = cfg->p2p.bss_idx[P2PAPI_BSSCFG_PRIMARY].vif; |
Hante Meuleman | 0f8ffe1 | 2013-02-08 15:53:42 +0100 | [diff] [blame] | 1061 | |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1062 | escan_req = false; |
| 1063 | if (request) { |
| 1064 | /* scan bss */ |
| 1065 | ssids = request->ssids; |
| 1066 | escan_req = true; |
| 1067 | } else { |
| 1068 | /* scan in ibss */ |
| 1069 | /* we don't do escan in ibss */ |
| 1070 | ssids = this_ssid; |
| 1071 | } |
| 1072 | |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 1073 | cfg->scan_request = request; |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 1074 | set_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1075 | if (escan_req) { |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 1076 | cfg->escan_info.run = brcmf_run_escan; |
Arend van Spriel | a0f472a | 2013-04-05 10:57:49 +0200 | [diff] [blame] | 1077 | err = brcmf_p2p_scan_prep(wiphy, request, vif); |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 1078 | if (err) |
| 1079 | goto scan_out; |
| 1080 | |
Arend van Spriel | a0f472a | 2013-04-05 10:57:49 +0200 | [diff] [blame] | 1081 | err = brcmf_do_escan(cfg, wiphy, vif->ifp, request); |
Arend van Spriel | 2cb941c | 2012-11-05 16:22:10 -0800 | [diff] [blame] | 1082 | if (err) |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1083 | goto scan_out; |
| 1084 | } else { |
Arend van Spriel | 4e8a008 | 2012-12-05 15:26:03 +0100 | [diff] [blame] | 1085 | brcmf_dbg(SCAN, "ssid \"%s\", ssid_len (%d)\n", |
| 1086 | ssids->ssid, ssids->ssid_len); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1087 | memset(&sr->ssid_le, 0, sizeof(sr->ssid_le)); |
| 1088 | SSID_len = min_t(u8, sizeof(sr->ssid_le.SSID), ssids->ssid_len); |
| 1089 | sr->ssid_le.SSID_len = cpu_to_le32(0); |
| 1090 | spec_scan = false; |
| 1091 | if (SSID_len) { |
| 1092 | memcpy(sr->ssid_le.SSID, ssids->ssid, SSID_len); |
| 1093 | sr->ssid_le.SSID_len = cpu_to_le32(SSID_len); |
| 1094 | spec_scan = true; |
| 1095 | } else |
Arend van Spriel | 4e8a008 | 2012-12-05 15:26:03 +0100 | [diff] [blame] | 1096 | brcmf_dbg(SCAN, "Broadcast scan\n"); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1097 | |
Hante Meuleman | 81f5dcb | 2012-10-22 10:36:14 -0700 | [diff] [blame] | 1098 | passive_scan = cfg->active_scan ? 0 : 1; |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 1099 | err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_PASSIVE_SCAN, |
Hante Meuleman | 81f5dcb | 2012-10-22 10:36:14 -0700 | [diff] [blame] | 1100 | passive_scan); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1101 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1102 | brcmf_err("WLC_SET_PASSIVE_SCAN error (%d)\n", err); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1103 | goto scan_out; |
| 1104 | } |
Daniel Kim | 5e787f7 | 2014-06-21 12:11:18 +0200 | [diff] [blame] | 1105 | brcmf_scan_config_mpc(ifp, 0); |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 1106 | err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SCAN, |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 1107 | &sr->ssid_le, sizeof(sr->ssid_le)); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1108 | if (err) { |
| 1109 | if (err == -EBUSY) |
Arend van Spriel | 647c9ae | 2012-12-05 15:26:01 +0100 | [diff] [blame] | 1110 | brcmf_dbg(INFO, "BUSY: scan for \"%s\" canceled\n", |
| 1111 | sr->ssid_le.SSID); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1112 | else |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1113 | brcmf_err("WLC_SCAN error (%d)\n", err); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1114 | |
Daniel Kim | 5e787f7 | 2014-06-21 12:11:18 +0200 | [diff] [blame] | 1115 | brcmf_scan_config_mpc(ifp, 1); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1116 | goto scan_out; |
| 1117 | } |
| 1118 | } |
| 1119 | |
Hante Meuleman | 661fa95 | 2015-02-06 18:36:47 +0100 | [diff] [blame] | 1120 | /* Arm scan timeout timer */ |
| 1121 | mod_timer(&cfg->escan_timeout, jiffies + |
| 1122 | WL_ESCAN_TIMER_INTERVAL_MS * HZ / 1000); |
| 1123 | |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1124 | return 0; |
| 1125 | |
| 1126 | scan_out: |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 1127 | clear_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status); |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 1128 | cfg->scan_request = NULL; |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1129 | return err; |
| 1130 | } |
| 1131 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1132 | static s32 |
Arend van Spriel | 0abb5f21 | 2012-10-22 13:55:32 -0700 | [diff] [blame] | 1133 | brcmf_cfg80211_scan(struct wiphy *wiphy, struct cfg80211_scan_request *request) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1134 | { |
Arend van Spriel | a0f472a | 2013-04-05 10:57:49 +0200 | [diff] [blame] | 1135 | struct brcmf_cfg80211_vif *vif; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1136 | s32 err = 0; |
| 1137 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 1138 | brcmf_dbg(TRACE, "Enter\n"); |
Arend van Spriel | a0f472a | 2013-04-05 10:57:49 +0200 | [diff] [blame] | 1139 | vif = container_of(request->wdev, struct brcmf_cfg80211_vif, wdev); |
| 1140 | if (!check_vif_up(vif)) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1141 | return -EIO; |
| 1142 | |
Arend van Spriel | a0f472a | 2013-04-05 10:57:49 +0200 | [diff] [blame] | 1143 | err = brcmf_cfg80211_escan(wiphy, vif, request, NULL); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1144 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1145 | if (err) |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1146 | brcmf_err("scan error (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1147 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 1148 | brcmf_dbg(TRACE, "Exit\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1149 | return err; |
| 1150 | } |
| 1151 | |
| 1152 | static s32 brcmf_set_rts(struct net_device *ndev, u32 rts_threshold) |
| 1153 | { |
| 1154 | s32 err = 0; |
| 1155 | |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 1156 | err = brcmf_fil_iovar_int_set(netdev_priv(ndev), "rtsthresh", |
| 1157 | rts_threshold); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1158 | if (err) |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1159 | brcmf_err("Error (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1160 | |
| 1161 | return err; |
| 1162 | } |
| 1163 | |
| 1164 | static s32 brcmf_set_frag(struct net_device *ndev, u32 frag_threshold) |
| 1165 | { |
| 1166 | s32 err = 0; |
| 1167 | |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 1168 | err = brcmf_fil_iovar_int_set(netdev_priv(ndev), "fragthresh", |
| 1169 | frag_threshold); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1170 | if (err) |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1171 | brcmf_err("Error (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1172 | |
| 1173 | return err; |
| 1174 | } |
| 1175 | |
| 1176 | static s32 brcmf_set_retry(struct net_device *ndev, u32 retry, bool l) |
| 1177 | { |
| 1178 | s32 err = 0; |
Hante Meuleman | b87e2c4 | 2012-11-14 18:46:23 -0800 | [diff] [blame] | 1179 | u32 cmd = (l ? BRCMF_C_SET_LRL : BRCMF_C_SET_SRL); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1180 | |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 1181 | err = brcmf_fil_cmd_int_set(netdev_priv(ndev), cmd, retry); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1182 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1183 | brcmf_err("cmd (%d) , error (%d)\n", cmd, err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1184 | return err; |
| 1185 | } |
| 1186 | return err; |
| 1187 | } |
| 1188 | |
| 1189 | static s32 brcmf_cfg80211_set_wiphy_params(struct wiphy *wiphy, u32 changed) |
| 1190 | { |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 1191 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); |
| 1192 | struct net_device *ndev = cfg_to_ndev(cfg); |
Arend van Spriel | 0abb5f21 | 2012-10-22 13:55:32 -0700 | [diff] [blame] | 1193 | struct brcmf_if *ifp = netdev_priv(ndev); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1194 | s32 err = 0; |
| 1195 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 1196 | brcmf_dbg(TRACE, "Enter\n"); |
Arend van Spriel | ce81e31 | 2012-10-22 13:55:37 -0700 | [diff] [blame] | 1197 | if (!check_vif_up(ifp->vif)) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1198 | return -EIO; |
| 1199 | |
| 1200 | if (changed & WIPHY_PARAM_RTS_THRESHOLD && |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 1201 | (cfg->conf->rts_threshold != wiphy->rts_threshold)) { |
| 1202 | cfg->conf->rts_threshold = wiphy->rts_threshold; |
| 1203 | err = brcmf_set_rts(ndev, cfg->conf->rts_threshold); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1204 | if (!err) |
| 1205 | goto done; |
| 1206 | } |
| 1207 | if (changed & WIPHY_PARAM_FRAG_THRESHOLD && |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 1208 | (cfg->conf->frag_threshold != wiphy->frag_threshold)) { |
| 1209 | cfg->conf->frag_threshold = wiphy->frag_threshold; |
| 1210 | err = brcmf_set_frag(ndev, cfg->conf->frag_threshold); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1211 | if (!err) |
| 1212 | goto done; |
| 1213 | } |
| 1214 | if (changed & WIPHY_PARAM_RETRY_LONG |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 1215 | && (cfg->conf->retry_long != wiphy->retry_long)) { |
| 1216 | cfg->conf->retry_long = wiphy->retry_long; |
| 1217 | err = brcmf_set_retry(ndev, cfg->conf->retry_long, true); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1218 | if (!err) |
| 1219 | goto done; |
| 1220 | } |
| 1221 | if (changed & WIPHY_PARAM_RETRY_SHORT |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 1222 | && (cfg->conf->retry_short != wiphy->retry_short)) { |
| 1223 | cfg->conf->retry_short = wiphy->retry_short; |
| 1224 | err = brcmf_set_retry(ndev, cfg->conf->retry_short, false); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1225 | if (!err) |
| 1226 | goto done; |
| 1227 | } |
| 1228 | |
| 1229 | done: |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 1230 | brcmf_dbg(TRACE, "Exit\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1231 | return err; |
| 1232 | } |
| 1233 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1234 | static void brcmf_init_prof(struct brcmf_cfg80211_profile *prof) |
| 1235 | { |
| 1236 | memset(prof, 0, sizeof(*prof)); |
| 1237 | } |
| 1238 | |
Arend van Spriel | 9b7a0dd | 2015-01-25 20:31:33 +0100 | [diff] [blame] | 1239 | static u16 brcmf_map_fw_linkdown_reason(const struct brcmf_event_msg *e) |
| 1240 | { |
| 1241 | u16 reason; |
| 1242 | |
| 1243 | switch (e->event_code) { |
| 1244 | case BRCMF_E_DEAUTH: |
| 1245 | case BRCMF_E_DEAUTH_IND: |
| 1246 | case BRCMF_E_DISASSOC_IND: |
| 1247 | reason = e->reason; |
| 1248 | break; |
| 1249 | case BRCMF_E_LINK: |
| 1250 | default: |
| 1251 | reason = 0; |
| 1252 | break; |
| 1253 | } |
| 1254 | return reason; |
| 1255 | } |
| 1256 | |
| 1257 | 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] | 1258 | { |
Piotr Haber | 61730d4 | 2013-04-23 12:53:12 +0200 | [diff] [blame] | 1259 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(vif->wdev.wiphy); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1260 | s32 err = 0; |
| 1261 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 1262 | brcmf_dbg(TRACE, "Enter\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1263 | |
Arend van Spriel | 903e0ee | 2012-11-28 21:44:11 +0100 | [diff] [blame] | 1264 | if (test_bit(BRCMF_VIF_STATUS_CONNECTED, &vif->sme_state)) { |
Arend van Spriel | 647c9ae | 2012-12-05 15:26:01 +0100 | [diff] [blame] | 1265 | brcmf_dbg(INFO, "Call WLC_DISASSOC to stop excess roaming\n "); |
Arend van Spriel | 903e0ee | 2012-11-28 21:44:11 +0100 | [diff] [blame] | 1266 | err = brcmf_fil_cmd_data_set(vif->ifp, |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 1267 | BRCMF_C_DISASSOC, NULL, 0); |
Arend van Spriel | a538ae3 | 2013-07-25 23:01:34 +0200 | [diff] [blame] | 1268 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1269 | brcmf_err("WLC_DISASSOC failed (%d)\n", err); |
Arend van Spriel | a538ae3 | 2013-07-25 23:01:34 +0200 | [diff] [blame] | 1270 | } |
Arend van Spriel | 903e0ee | 2012-11-28 21:44:11 +0100 | [diff] [blame] | 1271 | clear_bit(BRCMF_VIF_STATUS_CONNECTED, &vif->sme_state); |
Arend van Spriel | 9b7a0dd | 2015-01-25 20:31:33 +0100 | [diff] [blame] | 1272 | cfg80211_disconnected(vif->wdev.netdev, reason, NULL, 0, |
Johannes Berg | 80279fb | 2015-05-22 16:22:20 +0200 | [diff] [blame] | 1273 | true, GFP_KERNEL); |
Arend van Spriel | 43dffbc | 2014-01-06 12:40:46 +0100 | [diff] [blame] | 1274 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1275 | } |
Arend van Spriel | 903e0ee | 2012-11-28 21:44:11 +0100 | [diff] [blame] | 1276 | clear_bit(BRCMF_VIF_STATUS_CONNECTING, &vif->sme_state); |
Piotr Haber | 61730d4 | 2013-04-23 12:53:12 +0200 | [diff] [blame] | 1277 | clear_bit(BRCMF_SCAN_STATUS_SUPPRESS, &cfg->scan_status); |
| 1278 | brcmf_btcoex_set_mode(vif, BRCMF_BTCOEX_ENABLED, 0); |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 1279 | brcmf_dbg(TRACE, "Exit\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1280 | } |
| 1281 | |
| 1282 | static s32 |
| 1283 | brcmf_cfg80211_join_ibss(struct wiphy *wiphy, struct net_device *ndev, |
| 1284 | struct cfg80211_ibss_params *params) |
| 1285 | { |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 1286 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); |
Arend van Spriel | 0abb5f21 | 2012-10-22 13:55:32 -0700 | [diff] [blame] | 1287 | struct brcmf_if *ifp = netdev_priv(ndev); |
| 1288 | struct brcmf_cfg80211_profile *profile = &ifp->vif->profile; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1289 | struct brcmf_join_params join_params; |
| 1290 | size_t join_params_size = 0; |
| 1291 | s32 err = 0; |
| 1292 | s32 wsec = 0; |
| 1293 | s32 bcnprd; |
Hante Meuleman | 1701261 | 2013-02-06 18:40:44 +0100 | [diff] [blame] | 1294 | u16 chanspec; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1295 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 1296 | brcmf_dbg(TRACE, "Enter\n"); |
Arend van Spriel | ce81e31 | 2012-10-22 13:55:37 -0700 | [diff] [blame] | 1297 | if (!check_vif_up(ifp->vif)) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1298 | return -EIO; |
| 1299 | |
| 1300 | if (params->ssid) |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 1301 | brcmf_dbg(CONN, "SSID: %s\n", params->ssid); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1302 | else { |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 1303 | brcmf_dbg(CONN, "SSID: NULL, Not supported\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1304 | return -EOPNOTSUPP; |
| 1305 | } |
| 1306 | |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 1307 | set_bit(BRCMF_VIF_STATUS_CONNECTING, &ifp->vif->sme_state); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1308 | |
| 1309 | if (params->bssid) |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 1310 | brcmf_dbg(CONN, "BSSID: %pM\n", params->bssid); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1311 | else |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 1312 | brcmf_dbg(CONN, "No BSSID specified\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1313 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1314 | if (params->chandef.chan) |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 1315 | brcmf_dbg(CONN, "channel: %d\n", |
| 1316 | params->chandef.chan->center_freq); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1317 | else |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 1318 | brcmf_dbg(CONN, "no channel specified\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1319 | |
| 1320 | if (params->channel_fixed) |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 1321 | brcmf_dbg(CONN, "fixed channel required\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1322 | else |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 1323 | brcmf_dbg(CONN, "no fixed channel required\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1324 | |
| 1325 | if (params->ie && params->ie_len) |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 1326 | brcmf_dbg(CONN, "ie len: %d\n", params->ie_len); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1327 | else |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 1328 | brcmf_dbg(CONN, "no ie specified\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1329 | |
| 1330 | if (params->beacon_interval) |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 1331 | brcmf_dbg(CONN, "beacon interval: %d\n", |
| 1332 | params->beacon_interval); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1333 | else |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 1334 | brcmf_dbg(CONN, "no beacon interval specified\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1335 | |
| 1336 | if (params->basic_rates) |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 1337 | brcmf_dbg(CONN, "basic rates: %08X\n", params->basic_rates); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1338 | else |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 1339 | brcmf_dbg(CONN, "no basic rates specified\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1340 | |
| 1341 | if (params->privacy) |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 1342 | brcmf_dbg(CONN, "privacy required\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1343 | else |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 1344 | brcmf_dbg(CONN, "no privacy required\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1345 | |
| 1346 | /* Configure Privacy for starter */ |
| 1347 | if (params->privacy) |
| 1348 | wsec |= WEP_ENABLED; |
| 1349 | |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 1350 | err = brcmf_fil_iovar_int_set(ifp, "wsec", wsec); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1351 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1352 | brcmf_err("wsec failed (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1353 | goto done; |
| 1354 | } |
| 1355 | |
| 1356 | /* Configure Beacon Interval for starter */ |
| 1357 | if (params->beacon_interval) |
| 1358 | bcnprd = params->beacon_interval; |
| 1359 | else |
| 1360 | bcnprd = 100; |
| 1361 | |
Hante Meuleman | b87e2c4 | 2012-11-14 18:46:23 -0800 | [diff] [blame] | 1362 | 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] | 1363 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1364 | brcmf_err("WLC_SET_BCNPRD failed (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1365 | goto done; |
| 1366 | } |
| 1367 | |
| 1368 | /* Configure required join parameter */ |
| 1369 | memset(&join_params, 0, sizeof(struct brcmf_join_params)); |
| 1370 | |
| 1371 | /* SSID */ |
Arend van Spriel | 6c8c4f7 | 2012-09-27 14:17:57 +0200 | [diff] [blame] | 1372 | profile->ssid.SSID_len = min_t(u32, params->ssid_len, 32); |
| 1373 | memcpy(profile->ssid.SSID, params->ssid, profile->ssid.SSID_len); |
| 1374 | memcpy(join_params.ssid_le.SSID, params->ssid, profile->ssid.SSID_len); |
| 1375 | join_params.ssid_le.SSID_len = cpu_to_le32(profile->ssid.SSID_len); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1376 | join_params_size = sizeof(join_params.ssid_le); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1377 | |
| 1378 | /* BSSID */ |
| 1379 | if (params->bssid) { |
| 1380 | memcpy(join_params.params_le.bssid, params->bssid, ETH_ALEN); |
| 1381 | join_params_size = sizeof(join_params.ssid_le) + |
| 1382 | BRCMF_ASSOC_PARAMS_FIXED_SIZE; |
Arend van Spriel | 6c8c4f7 | 2012-09-27 14:17:57 +0200 | [diff] [blame] | 1383 | memcpy(profile->bssid, params->bssid, ETH_ALEN); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1384 | } else { |
Joe Perches | 93803b3 | 2015-03-02 19:54:49 -0800 | [diff] [blame] | 1385 | eth_broadcast_addr(join_params.params_le.bssid); |
| 1386 | eth_zero_addr(profile->bssid); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1387 | } |
| 1388 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1389 | /* Channel */ |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1390 | if (params->chandef.chan) { |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1391 | u32 target_channel; |
| 1392 | |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 1393 | cfg->channel = |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1394 | ieee80211_frequency_to_channel( |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1395 | params->chandef.chan->center_freq); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1396 | if (params->channel_fixed) { |
| 1397 | /* adding chanspec */ |
Arend van Spriel | 600a897 | 2014-05-12 10:47:39 +0200 | [diff] [blame] | 1398 | chanspec = chandef_to_chanspec(&cfg->d11inf, |
| 1399 | ¶ms->chandef); |
Hante Meuleman | 1701261 | 2013-02-06 18:40:44 +0100 | [diff] [blame] | 1400 | join_params.params_le.chanspec_list[0] = |
| 1401 | cpu_to_le16(chanspec); |
| 1402 | join_params.params_le.chanspec_num = cpu_to_le32(1); |
| 1403 | join_params_size += sizeof(join_params.params_le); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1404 | } |
| 1405 | |
| 1406 | /* set channel for starter */ |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 1407 | target_channel = cfg->channel; |
Hante Meuleman | b87e2c4 | 2012-11-14 18:46:23 -0800 | [diff] [blame] | 1408 | err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_CHANNEL, |
Hante Meuleman | 81f5dcb | 2012-10-22 10:36:14 -0700 | [diff] [blame] | 1409 | target_channel); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1410 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1411 | brcmf_err("WLC_SET_CHANNEL failed (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1412 | goto done; |
| 1413 | } |
| 1414 | } else |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 1415 | cfg->channel = 0; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1416 | |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 1417 | cfg->ibss_starter = false; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1418 | |
| 1419 | |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 1420 | err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SET_SSID, |
Hante Meuleman | 81f5dcb | 2012-10-22 10:36:14 -0700 | [diff] [blame] | 1421 | &join_params, join_params_size); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1422 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1423 | brcmf_err("WLC_SET_SSID failed (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1424 | goto done; |
| 1425 | } |
| 1426 | |
| 1427 | done: |
| 1428 | if (err) |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 1429 | clear_bit(BRCMF_VIF_STATUS_CONNECTING, &ifp->vif->sme_state); |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 1430 | brcmf_dbg(TRACE, "Exit\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1431 | return err; |
| 1432 | } |
| 1433 | |
| 1434 | static s32 |
| 1435 | brcmf_cfg80211_leave_ibss(struct wiphy *wiphy, struct net_device *ndev) |
| 1436 | { |
Arend van Spriel | 0abb5f21 | 2012-10-22 13:55:32 -0700 | [diff] [blame] | 1437 | struct brcmf_if *ifp = netdev_priv(ndev); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1438 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 1439 | brcmf_dbg(TRACE, "Enter\n"); |
Arend van Spriel | ce81e31 | 2012-10-22 13:55:37 -0700 | [diff] [blame] | 1440 | if (!check_vif_up(ifp->vif)) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1441 | return -EIO; |
| 1442 | |
Arend van Spriel | 9b7a0dd | 2015-01-25 20:31:33 +0100 | [diff] [blame] | 1443 | brcmf_link_down(ifp->vif, WLAN_REASON_DEAUTH_LEAVING); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1444 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 1445 | brcmf_dbg(TRACE, "Exit\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1446 | |
Peter Senna Tschudin | 12f3237 | 2014-05-31 10:14:06 -0300 | [diff] [blame] | 1447 | return 0; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1448 | } |
| 1449 | |
| 1450 | static s32 brcmf_set_wpa_version(struct net_device *ndev, |
| 1451 | struct cfg80211_connect_params *sme) |
| 1452 | { |
Arend van Spriel | 6ac4f4e | 2012-10-22 13:55:31 -0700 | [diff] [blame] | 1453 | struct brcmf_cfg80211_profile *profile = ndev_to_prof(ndev); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1454 | struct brcmf_cfg80211_security *sec; |
| 1455 | s32 val = 0; |
| 1456 | s32 err = 0; |
| 1457 | |
| 1458 | if (sme->crypto.wpa_versions & NL80211_WPA_VERSION_1) |
| 1459 | val = WPA_AUTH_PSK | WPA_AUTH_UNSPECIFIED; |
| 1460 | else if (sme->crypto.wpa_versions & NL80211_WPA_VERSION_2) |
| 1461 | val = WPA2_AUTH_PSK | WPA2_AUTH_UNSPECIFIED; |
| 1462 | else |
| 1463 | val = WPA_AUTH_DISABLED; |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 1464 | brcmf_dbg(CONN, "setting wpa_auth to 0x%0x\n", val); |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 1465 | 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] | 1466 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1467 | brcmf_err("set wpa_auth failed (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1468 | return err; |
| 1469 | } |
Arend van Spriel | 06bb123 | 2012-09-27 14:17:56 +0200 | [diff] [blame] | 1470 | sec = &profile->sec; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1471 | sec->wpa_versions = sme->crypto.wpa_versions; |
| 1472 | return err; |
| 1473 | } |
| 1474 | |
| 1475 | static s32 brcmf_set_auth_type(struct net_device *ndev, |
| 1476 | struct cfg80211_connect_params *sme) |
| 1477 | { |
Arend van Spriel | 6ac4f4e | 2012-10-22 13:55:31 -0700 | [diff] [blame] | 1478 | struct brcmf_cfg80211_profile *profile = ndev_to_prof(ndev); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1479 | struct brcmf_cfg80211_security *sec; |
| 1480 | s32 val = 0; |
| 1481 | s32 err = 0; |
| 1482 | |
| 1483 | switch (sme->auth_type) { |
| 1484 | case NL80211_AUTHTYPE_OPEN_SYSTEM: |
| 1485 | val = 0; |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 1486 | brcmf_dbg(CONN, "open system\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1487 | break; |
| 1488 | case NL80211_AUTHTYPE_SHARED_KEY: |
| 1489 | val = 1; |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 1490 | brcmf_dbg(CONN, "shared key\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1491 | break; |
| 1492 | case NL80211_AUTHTYPE_AUTOMATIC: |
| 1493 | val = 2; |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 1494 | brcmf_dbg(CONN, "automatic\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1495 | break; |
| 1496 | case NL80211_AUTHTYPE_NETWORK_EAP: |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 1497 | brcmf_dbg(CONN, "network eap\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1498 | default: |
| 1499 | val = 2; |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1500 | brcmf_err("invalid auth type (%d)\n", sme->auth_type); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1501 | break; |
| 1502 | } |
| 1503 | |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 1504 | err = brcmf_fil_bsscfg_int_set(netdev_priv(ndev), "auth", val); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1505 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1506 | brcmf_err("set auth failed (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1507 | return err; |
| 1508 | } |
Arend van Spriel | 06bb123 | 2012-09-27 14:17:56 +0200 | [diff] [blame] | 1509 | sec = &profile->sec; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1510 | sec->auth_type = sme->auth_type; |
| 1511 | return err; |
| 1512 | } |
| 1513 | |
| 1514 | static s32 |
Daniel Kim | 87b7e9e | 2014-03-25 21:45:09 +0100 | [diff] [blame] | 1515 | brcmf_set_wsec_mode(struct net_device *ndev, |
| 1516 | struct cfg80211_connect_params *sme, bool mfp) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1517 | { |
Arend van Spriel | 6ac4f4e | 2012-10-22 13:55:31 -0700 | [diff] [blame] | 1518 | struct brcmf_cfg80211_profile *profile = ndev_to_prof(ndev); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1519 | struct brcmf_cfg80211_security *sec; |
| 1520 | s32 pval = 0; |
| 1521 | s32 gval = 0; |
Daniel Kim | 87b7e9e | 2014-03-25 21:45:09 +0100 | [diff] [blame] | 1522 | s32 wsec; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1523 | s32 err = 0; |
| 1524 | |
| 1525 | if (sme->crypto.n_ciphers_pairwise) { |
| 1526 | switch (sme->crypto.ciphers_pairwise[0]) { |
| 1527 | case WLAN_CIPHER_SUITE_WEP40: |
| 1528 | case WLAN_CIPHER_SUITE_WEP104: |
| 1529 | pval = WEP_ENABLED; |
| 1530 | break; |
| 1531 | case WLAN_CIPHER_SUITE_TKIP: |
| 1532 | pval = TKIP_ENABLED; |
| 1533 | break; |
| 1534 | case WLAN_CIPHER_SUITE_CCMP: |
| 1535 | pval = AES_ENABLED; |
| 1536 | break; |
| 1537 | case WLAN_CIPHER_SUITE_AES_CMAC: |
| 1538 | pval = AES_ENABLED; |
| 1539 | break; |
| 1540 | default: |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1541 | brcmf_err("invalid cipher pairwise (%d)\n", |
| 1542 | sme->crypto.ciphers_pairwise[0]); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1543 | return -EINVAL; |
| 1544 | } |
| 1545 | } |
| 1546 | if (sme->crypto.cipher_group) { |
| 1547 | switch (sme->crypto.cipher_group) { |
| 1548 | case WLAN_CIPHER_SUITE_WEP40: |
| 1549 | case WLAN_CIPHER_SUITE_WEP104: |
| 1550 | gval = WEP_ENABLED; |
| 1551 | break; |
| 1552 | case WLAN_CIPHER_SUITE_TKIP: |
| 1553 | gval = TKIP_ENABLED; |
| 1554 | break; |
| 1555 | case WLAN_CIPHER_SUITE_CCMP: |
| 1556 | gval = AES_ENABLED; |
| 1557 | break; |
| 1558 | case WLAN_CIPHER_SUITE_AES_CMAC: |
| 1559 | gval = AES_ENABLED; |
| 1560 | break; |
| 1561 | default: |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1562 | brcmf_err("invalid cipher group (%d)\n", |
| 1563 | sme->crypto.cipher_group); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1564 | return -EINVAL; |
| 1565 | } |
| 1566 | } |
| 1567 | |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 1568 | brcmf_dbg(CONN, "pval (%d) gval (%d)\n", pval, gval); |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 1569 | /* In case of privacy, but no security and WPS then simulate */ |
| 1570 | /* setting AES. WPS-2.0 allows no security */ |
| 1571 | if (brcmf_find_wpsie(sme->ie, sme->ie_len) && !pval && !gval && |
| 1572 | sme->privacy) |
| 1573 | pval = AES_ENABLED; |
Daniel Kim | 87b7e9e | 2014-03-25 21:45:09 +0100 | [diff] [blame] | 1574 | |
| 1575 | if (mfp) |
| 1576 | wsec = pval | gval | MFP_CAPABLE; |
| 1577 | else |
| 1578 | wsec = pval | gval; |
| 1579 | err = brcmf_fil_bsscfg_int_set(netdev_priv(ndev), "wsec", wsec); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1580 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1581 | brcmf_err("error (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1582 | return err; |
| 1583 | } |
| 1584 | |
Arend van Spriel | 06bb123 | 2012-09-27 14:17:56 +0200 | [diff] [blame] | 1585 | sec = &profile->sec; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1586 | sec->cipher_pairwise = sme->crypto.ciphers_pairwise[0]; |
| 1587 | sec->cipher_group = sme->crypto.cipher_group; |
| 1588 | |
| 1589 | return err; |
| 1590 | } |
| 1591 | |
| 1592 | static s32 |
| 1593 | brcmf_set_key_mgmt(struct net_device *ndev, struct cfg80211_connect_params *sme) |
| 1594 | { |
Arend van Spriel | 6ac4f4e | 2012-10-22 13:55:31 -0700 | [diff] [blame] | 1595 | struct brcmf_cfg80211_profile *profile = ndev_to_prof(ndev); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1596 | struct brcmf_cfg80211_security *sec; |
| 1597 | s32 val = 0; |
| 1598 | s32 err = 0; |
| 1599 | |
| 1600 | if (sme->crypto.n_akm_suites) { |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 1601 | err = brcmf_fil_bsscfg_int_get(netdev_priv(ndev), |
| 1602 | "wpa_auth", &val); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1603 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1604 | brcmf_err("could not get wpa_auth (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1605 | return err; |
| 1606 | } |
| 1607 | if (val & (WPA_AUTH_PSK | WPA_AUTH_UNSPECIFIED)) { |
| 1608 | switch (sme->crypto.akm_suites[0]) { |
| 1609 | case WLAN_AKM_SUITE_8021X: |
| 1610 | val = WPA_AUTH_UNSPECIFIED; |
| 1611 | break; |
| 1612 | case WLAN_AKM_SUITE_PSK: |
| 1613 | val = WPA_AUTH_PSK; |
| 1614 | break; |
| 1615 | default: |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1616 | brcmf_err("invalid cipher group (%d)\n", |
| 1617 | sme->crypto.cipher_group); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1618 | return -EINVAL; |
| 1619 | } |
| 1620 | } else if (val & (WPA2_AUTH_PSK | WPA2_AUTH_UNSPECIFIED)) { |
| 1621 | switch (sme->crypto.akm_suites[0]) { |
| 1622 | case WLAN_AKM_SUITE_8021X: |
| 1623 | val = WPA2_AUTH_UNSPECIFIED; |
| 1624 | break; |
| 1625 | case WLAN_AKM_SUITE_PSK: |
| 1626 | val = WPA2_AUTH_PSK; |
| 1627 | break; |
| 1628 | default: |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1629 | brcmf_err("invalid cipher group (%d)\n", |
| 1630 | sme->crypto.cipher_group); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1631 | return -EINVAL; |
| 1632 | } |
| 1633 | } |
| 1634 | |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 1635 | brcmf_dbg(CONN, "setting wpa_auth to %d\n", val); |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 1636 | err = brcmf_fil_bsscfg_int_set(netdev_priv(ndev), |
| 1637 | "wpa_auth", val); |
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("could not set wpa_auth (%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->wpa_auth = sme->crypto.akm_suites[0]; |
| 1645 | |
| 1646 | return err; |
| 1647 | } |
| 1648 | |
| 1649 | static s32 |
Hante Meuleman | f09d0c0 | 2012-09-27 14:17:48 +0200 | [diff] [blame] | 1650 | brcmf_set_sharedkey(struct net_device *ndev, |
| 1651 | struct cfg80211_connect_params *sme) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1652 | { |
Arend van Spriel | 6ac4f4e | 2012-10-22 13:55:31 -0700 | [diff] [blame] | 1653 | struct brcmf_cfg80211_profile *profile = ndev_to_prof(ndev); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1654 | struct brcmf_cfg80211_security *sec; |
| 1655 | struct brcmf_wsec_key key; |
| 1656 | s32 val; |
| 1657 | s32 err = 0; |
| 1658 | |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 1659 | brcmf_dbg(CONN, "key len (%d)\n", sme->key_len); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1660 | |
Roland Vossen | a718e2f | 2011-10-12 20:51:24 +0200 | [diff] [blame] | 1661 | if (sme->key_len == 0) |
| 1662 | return 0; |
| 1663 | |
Arend van Spriel | 06bb123 | 2012-09-27 14:17:56 +0200 | [diff] [blame] | 1664 | sec = &profile->sec; |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 1665 | brcmf_dbg(CONN, "wpa_versions 0x%x cipher_pairwise 0x%x\n", |
| 1666 | sec->wpa_versions, sec->cipher_pairwise); |
Roland Vossen | a718e2f | 2011-10-12 20:51:24 +0200 | [diff] [blame] | 1667 | |
| 1668 | if (sec->wpa_versions & (NL80211_WPA_VERSION_1 | NL80211_WPA_VERSION_2)) |
| 1669 | return 0; |
| 1670 | |
Hante Meuleman | f09d0c0 | 2012-09-27 14:17:48 +0200 | [diff] [blame] | 1671 | if (!(sec->cipher_pairwise & |
| 1672 | (WLAN_CIPHER_SUITE_WEP40 | WLAN_CIPHER_SUITE_WEP104))) |
| 1673 | return 0; |
Roland Vossen | a718e2f | 2011-10-12 20:51:24 +0200 | [diff] [blame] | 1674 | |
Hante Meuleman | f09d0c0 | 2012-09-27 14:17:48 +0200 | [diff] [blame] | 1675 | memset(&key, 0, sizeof(key)); |
| 1676 | key.len = (u32) sme->key_len; |
| 1677 | key.index = (u32) sme->key_idx; |
| 1678 | if (key.len > sizeof(key.data)) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1679 | brcmf_err("Too long key length (%u)\n", key.len); |
Hante Meuleman | f09d0c0 | 2012-09-27 14:17:48 +0200 | [diff] [blame] | 1680 | return -EINVAL; |
| 1681 | } |
| 1682 | memcpy(key.data, sme->key, key.len); |
| 1683 | key.flags = BRCMF_PRIMARY_KEY; |
| 1684 | switch (sec->cipher_pairwise) { |
| 1685 | case WLAN_CIPHER_SUITE_WEP40: |
| 1686 | key.algo = CRYPTO_ALGO_WEP1; |
| 1687 | break; |
| 1688 | case WLAN_CIPHER_SUITE_WEP104: |
| 1689 | key.algo = CRYPTO_ALGO_WEP128; |
| 1690 | break; |
| 1691 | default: |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1692 | brcmf_err("Invalid algorithm (%d)\n", |
| 1693 | sme->crypto.ciphers_pairwise[0]); |
Hante Meuleman | f09d0c0 | 2012-09-27 14:17:48 +0200 | [diff] [blame] | 1694 | return -EINVAL; |
| 1695 | } |
| 1696 | /* Set the new key/index */ |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 1697 | brcmf_dbg(CONN, "key length (%d) key index (%d) algo (%d)\n", |
| 1698 | key.len, key.index, key.algo); |
| 1699 | brcmf_dbg(CONN, "key \"%s\"\n", key.data); |
Hante Meuleman | 118eb30 | 2014-12-21 12:43:49 +0100 | [diff] [blame] | 1700 | err = send_key_to_dongle(netdev_priv(ndev), &key); |
Hante Meuleman | f09d0c0 | 2012-09-27 14:17:48 +0200 | [diff] [blame] | 1701 | if (err) |
| 1702 | return err; |
| 1703 | |
| 1704 | if (sec->auth_type == NL80211_AUTHTYPE_SHARED_KEY) { |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 1705 | brcmf_dbg(CONN, "set auth_type to shared key\n"); |
Hante Meuleman | f09d0c0 | 2012-09-27 14:17:48 +0200 | [diff] [blame] | 1706 | val = WL_AUTH_SHARED_KEY; /* shared key */ |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 1707 | err = brcmf_fil_bsscfg_int_set(netdev_priv(ndev), "auth", val); |
Hante Meuleman | f09d0c0 | 2012-09-27 14:17:48 +0200 | [diff] [blame] | 1708 | if (err) |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1709 | brcmf_err("set auth failed (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1710 | } |
| 1711 | return err; |
| 1712 | } |
| 1713 | |
Arend van Spriel | cbb1ec9 | 2013-02-06 18:40:47 +0100 | [diff] [blame] | 1714 | static |
| 1715 | enum nl80211_auth_type brcmf_war_auth_type(struct brcmf_if *ifp, |
| 1716 | enum nl80211_auth_type type) |
| 1717 | { |
Arend van Spriel | c08437b | 2014-07-12 08:49:39 +0200 | [diff] [blame] | 1718 | if (type == NL80211_AUTHTYPE_AUTOMATIC && |
| 1719 | brcmf_feat_is_quirk_enabled(ifp, BRCMF_FEAT_QUIRK_AUTO_AUTH)) { |
| 1720 | brcmf_dbg(CONN, "WAR: use OPEN instead of AUTO\n"); |
| 1721 | type = NL80211_AUTHTYPE_OPEN_SYSTEM; |
Arend van Spriel | cbb1ec9 | 2013-02-06 18:40:47 +0100 | [diff] [blame] | 1722 | } |
| 1723 | return type; |
| 1724 | } |
| 1725 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1726 | static s32 |
| 1727 | brcmf_cfg80211_connect(struct wiphy *wiphy, struct net_device *ndev, |
Arend van Spriel | cbb1ec9 | 2013-02-06 18:40:47 +0100 | [diff] [blame] | 1728 | struct cfg80211_connect_params *sme) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1729 | { |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 1730 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); |
Arend van Spriel | 0abb5f21 | 2012-10-22 13:55:32 -0700 | [diff] [blame] | 1731 | struct brcmf_if *ifp = netdev_priv(ndev); |
| 1732 | struct brcmf_cfg80211_profile *profile = &ifp->vif->profile; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1733 | struct ieee80211_channel *chan = sme->channel; |
| 1734 | struct brcmf_join_params join_params; |
| 1735 | size_t join_params_size; |
Johannes Berg | 4b5800f | 2014-01-15 14:55:59 +0100 | [diff] [blame] | 1736 | const struct brcmf_tlv *rsn_ie; |
| 1737 | const struct brcmf_vs_tlv *wpa_ie; |
| 1738 | const void *ie; |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 1739 | u32 ie_len; |
| 1740 | struct brcmf_ext_join_params_le *ext_join_params; |
Hante Meuleman | 1701261 | 2013-02-06 18:40:44 +0100 | [diff] [blame] | 1741 | u16 chanspec; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1742 | s32 err = 0; |
| 1743 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 1744 | brcmf_dbg(TRACE, "Enter\n"); |
Arend van Spriel | ce81e31 | 2012-10-22 13:55:37 -0700 | [diff] [blame] | 1745 | if (!check_vif_up(ifp->vif)) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1746 | return -EIO; |
| 1747 | |
| 1748 | if (!sme->ssid) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1749 | brcmf_err("Invalid ssid\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1750 | return -EOPNOTSUPP; |
| 1751 | } |
| 1752 | |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 1753 | if (ifp->vif == cfg->p2p.bss_idx[P2PAPI_BSSCFG_PRIMARY].vif) { |
| 1754 | /* A normal (non P2P) connection request setup. */ |
| 1755 | ie = NULL; |
| 1756 | ie_len = 0; |
| 1757 | /* find the WPA_IE */ |
| 1758 | wpa_ie = brcmf_find_wpaie((u8 *)sme->ie, sme->ie_len); |
| 1759 | if (wpa_ie) { |
| 1760 | ie = wpa_ie; |
| 1761 | ie_len = wpa_ie->len + TLV_HDR_LEN; |
| 1762 | } else { |
| 1763 | /* find the RSN_IE */ |
Johannes Berg | 4b5800f | 2014-01-15 14:55:59 +0100 | [diff] [blame] | 1764 | rsn_ie = brcmf_parse_tlvs((const u8 *)sme->ie, |
| 1765 | sme->ie_len, |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 1766 | WLAN_EID_RSN); |
| 1767 | if (rsn_ie) { |
| 1768 | ie = rsn_ie; |
| 1769 | ie_len = rsn_ie->len + TLV_HDR_LEN; |
| 1770 | } |
| 1771 | } |
| 1772 | brcmf_fil_iovar_data_set(ifp, "wpaie", ie, ie_len); |
| 1773 | } |
| 1774 | |
| 1775 | err = brcmf_vif_set_mgmt_ie(ifp->vif, BRCMF_VNDR_IE_ASSOCREQ_FLAG, |
| 1776 | sme->ie, sme->ie_len); |
| 1777 | if (err) |
| 1778 | brcmf_err("Set Assoc REQ IE Failed\n"); |
| 1779 | else |
| 1780 | brcmf_dbg(TRACE, "Applied Vndr IEs for Assoc request\n"); |
| 1781 | |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 1782 | set_bit(BRCMF_VIF_STATUS_CONNECTING, &ifp->vif->sme_state); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1783 | |
| 1784 | if (chan) { |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 1785 | cfg->channel = |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1786 | ieee80211_frequency_to_channel(chan->center_freq); |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 1787 | chanspec = channel_to_chanspec(&cfg->d11inf, chan); |
Hante Meuleman | 1701261 | 2013-02-06 18:40:44 +0100 | [diff] [blame] | 1788 | brcmf_dbg(CONN, "channel=%d, center_req=%d, chanspec=0x%04x\n", |
| 1789 | cfg->channel, chan->center_freq, chanspec); |
| 1790 | } else { |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 1791 | cfg->channel = 0; |
Hante Meuleman | 1701261 | 2013-02-06 18:40:44 +0100 | [diff] [blame] | 1792 | chanspec = 0; |
| 1793 | } |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1794 | |
Arend van Spriel | 647c9ae | 2012-12-05 15:26:01 +0100 | [diff] [blame] | 1795 | 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] | 1796 | |
| 1797 | err = brcmf_set_wpa_version(ndev, sme); |
| 1798 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1799 | brcmf_err("wl_set_wpa_version failed (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1800 | goto done; |
| 1801 | } |
| 1802 | |
Arend van Spriel | cbb1ec9 | 2013-02-06 18:40:47 +0100 | [diff] [blame] | 1803 | sme->auth_type = brcmf_war_auth_type(ifp, sme->auth_type); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1804 | err = brcmf_set_auth_type(ndev, sme); |
| 1805 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1806 | brcmf_err("wl_set_auth_type failed (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1807 | goto done; |
| 1808 | } |
| 1809 | |
Daniel Kim | 87b7e9e | 2014-03-25 21:45:09 +0100 | [diff] [blame] | 1810 | err = brcmf_set_wsec_mode(ndev, sme, sme->mfp == NL80211_MFP_REQUIRED); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1811 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1812 | brcmf_err("wl_set_set_cipher failed (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1813 | goto done; |
| 1814 | } |
| 1815 | |
| 1816 | err = brcmf_set_key_mgmt(ndev, sme); |
| 1817 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1818 | brcmf_err("wl_set_key_mgmt failed (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1819 | goto done; |
| 1820 | } |
| 1821 | |
Hante Meuleman | f09d0c0 | 2012-09-27 14:17:48 +0200 | [diff] [blame] | 1822 | err = brcmf_set_sharedkey(ndev, sme); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1823 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1824 | brcmf_err("brcmf_set_sharedkey failed (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1825 | goto done; |
| 1826 | } |
| 1827 | |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 1828 | profile->ssid.SSID_len = min_t(u32, (u32)sizeof(profile->ssid.SSID), |
| 1829 | (u32)sme->ssid_len); |
| 1830 | memcpy(&profile->ssid.SSID, sme->ssid, profile->ssid.SSID_len); |
| 1831 | if (profile->ssid.SSID_len < IEEE80211_MAX_SSID_LEN) { |
| 1832 | profile->ssid.SSID[profile->ssid.SSID_len] = 0; |
| 1833 | brcmf_dbg(CONN, "SSID \"%s\", len (%d)\n", profile->ssid.SSID, |
| 1834 | profile->ssid.SSID_len); |
| 1835 | } |
| 1836 | |
| 1837 | /* Join with specific BSSID and cached SSID |
| 1838 | * If SSID is zero join based on BSSID only |
| 1839 | */ |
| 1840 | join_params_size = offsetof(struct brcmf_ext_join_params_le, assoc_le) + |
| 1841 | offsetof(struct brcmf_assoc_params_le, chanspec_list); |
| 1842 | if (cfg->channel) |
| 1843 | join_params_size += sizeof(u16); |
| 1844 | ext_join_params = kzalloc(join_params_size, GFP_KERNEL); |
| 1845 | if (ext_join_params == NULL) { |
| 1846 | err = -ENOMEM; |
| 1847 | goto done; |
| 1848 | } |
| 1849 | ext_join_params->ssid_le.SSID_len = cpu_to_le32(profile->ssid.SSID_len); |
| 1850 | memcpy(&ext_join_params->ssid_le.SSID, sme->ssid, |
| 1851 | profile->ssid.SSID_len); |
Hante Meuleman | 63dd99e | 2014-03-15 17:18:19 +0100 | [diff] [blame] | 1852 | |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 1853 | /* Set up join scan parameters */ |
| 1854 | ext_join_params->scan_le.scan_type = -1; |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 1855 | ext_join_params->scan_le.home_time = cpu_to_le32(-1); |
| 1856 | |
| 1857 | if (sme->bssid) |
| 1858 | memcpy(&ext_join_params->assoc_le.bssid, sme->bssid, ETH_ALEN); |
| 1859 | else |
Joe Perches | 93803b3 | 2015-03-02 19:54:49 -0800 | [diff] [blame] | 1860 | eth_broadcast_addr(ext_join_params->assoc_le.bssid); |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 1861 | |
| 1862 | if (cfg->channel) { |
| 1863 | ext_join_params->assoc_le.chanspec_num = cpu_to_le32(1); |
| 1864 | |
| 1865 | ext_join_params->assoc_le.chanspec_list[0] = |
| 1866 | cpu_to_le16(chanspec); |
Hante Meuleman | 63dd99e | 2014-03-15 17:18:19 +0100 | [diff] [blame] | 1867 | /* Increase dwell time to receive probe response or detect |
| 1868 | * beacon from target AP at a noisy air only during connect |
| 1869 | * command. |
| 1870 | */ |
| 1871 | ext_join_params->scan_le.active_time = |
| 1872 | cpu_to_le32(BRCMF_SCAN_JOIN_ACTIVE_DWELL_TIME_MS); |
| 1873 | ext_join_params->scan_le.passive_time = |
| 1874 | cpu_to_le32(BRCMF_SCAN_JOIN_PASSIVE_DWELL_TIME_MS); |
| 1875 | /* To sync with presence period of VSDB GO send probe request |
| 1876 | * more frequently. Probe request will be stopped when it gets |
| 1877 | * probe response from target AP/GO. |
| 1878 | */ |
| 1879 | ext_join_params->scan_le.nprobes = |
| 1880 | cpu_to_le32(BRCMF_SCAN_JOIN_ACTIVE_DWELL_TIME_MS / |
| 1881 | BRCMF_SCAN_JOIN_PROBE_INTERVAL_MS); |
| 1882 | } else { |
| 1883 | ext_join_params->scan_le.active_time = cpu_to_le32(-1); |
| 1884 | ext_join_params->scan_le.passive_time = cpu_to_le32(-1); |
| 1885 | ext_join_params->scan_le.nprobes = cpu_to_le32(-1); |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 1886 | } |
| 1887 | |
| 1888 | err = brcmf_fil_bsscfg_data_set(ifp, "join", ext_join_params, |
| 1889 | join_params_size); |
| 1890 | kfree(ext_join_params); |
| 1891 | if (!err) |
| 1892 | /* This is it. join command worked, we are done */ |
| 1893 | goto done; |
| 1894 | |
| 1895 | /* join command failed, fallback to set ssid */ |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1896 | memset(&join_params, 0, sizeof(join_params)); |
| 1897 | join_params_size = sizeof(join_params.ssid_le); |
| 1898 | |
Arend van Spriel | 6c8c4f7 | 2012-09-27 14:17:57 +0200 | [diff] [blame] | 1899 | memcpy(&join_params.ssid_le.SSID, sme->ssid, profile->ssid.SSID_len); |
Arend van Spriel | 6c8c4f7 | 2012-09-27 14:17:57 +0200 | [diff] [blame] | 1900 | join_params.ssid_le.SSID_len = cpu_to_le32(profile->ssid.SSID_len); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1901 | |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 1902 | if (sme->bssid) |
| 1903 | memcpy(join_params.params_le.bssid, sme->bssid, ETH_ALEN); |
| 1904 | else |
Joe Perches | 93803b3 | 2015-03-02 19:54:49 -0800 | [diff] [blame] | 1905 | eth_broadcast_addr(join_params.params_le.bssid); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1906 | |
Hante Meuleman | 1701261 | 2013-02-06 18:40:44 +0100 | [diff] [blame] | 1907 | if (cfg->channel) { |
| 1908 | join_params.params_le.chanspec_list[0] = cpu_to_le16(chanspec); |
| 1909 | join_params.params_le.chanspec_num = cpu_to_le32(1); |
| 1910 | join_params_size += sizeof(join_params.params_le); |
| 1911 | } |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 1912 | err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SET_SSID, |
Hante Meuleman | 81f5dcb | 2012-10-22 10:36:14 -0700 | [diff] [blame] | 1913 | &join_params, join_params_size); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1914 | if (err) |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 1915 | brcmf_err("BRCMF_C_SET_SSID failed (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1916 | |
| 1917 | done: |
| 1918 | if (err) |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 1919 | clear_bit(BRCMF_VIF_STATUS_CONNECTING, &ifp->vif->sme_state); |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 1920 | brcmf_dbg(TRACE, "Exit\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1921 | return err; |
| 1922 | } |
| 1923 | |
| 1924 | static s32 |
| 1925 | brcmf_cfg80211_disconnect(struct wiphy *wiphy, struct net_device *ndev, |
| 1926 | u16 reason_code) |
| 1927 | { |
Arend van Spriel | 0abb5f21 | 2012-10-22 13:55:32 -0700 | [diff] [blame] | 1928 | struct brcmf_if *ifp = netdev_priv(ndev); |
| 1929 | struct brcmf_cfg80211_profile *profile = &ifp->vif->profile; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1930 | struct brcmf_scb_val_le scbval; |
| 1931 | s32 err = 0; |
| 1932 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 1933 | brcmf_dbg(TRACE, "Enter. Reason code = %d\n", reason_code); |
Arend van Spriel | ce81e31 | 2012-10-22 13:55:37 -0700 | [diff] [blame] | 1934 | if (!check_vif_up(ifp->vif)) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1935 | return -EIO; |
| 1936 | |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 1937 | clear_bit(BRCMF_VIF_STATUS_CONNECTED, &ifp->vif->sme_state); |
Arend van Spriel | 4f3fff1 | 2014-11-20 22:27:02 +0100 | [diff] [blame] | 1938 | clear_bit(BRCMF_VIF_STATUS_CONNECTING, &ifp->vif->sme_state); |
Johannes Berg | 80279fb | 2015-05-22 16:22:20 +0200 | [diff] [blame] | 1939 | cfg80211_disconnected(ndev, reason_code, NULL, 0, true, GFP_KERNEL); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1940 | |
Arend van Spriel | 06bb123 | 2012-09-27 14:17:56 +0200 | [diff] [blame] | 1941 | memcpy(&scbval.ea, &profile->bssid, ETH_ALEN); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1942 | scbval.val = cpu_to_le32(reason_code); |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 1943 | err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_DISASSOC, |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 1944 | &scbval, sizeof(scbval)); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1945 | if (err) |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1946 | brcmf_err("error (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1947 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 1948 | brcmf_dbg(TRACE, "Exit\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1949 | return err; |
| 1950 | } |
| 1951 | |
| 1952 | static s32 |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 1953 | 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] | 1954 | enum nl80211_tx_power_setting type, s32 mbm) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1955 | { |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 1956 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); |
Arend van Spriel | 0abb5f21 | 2012-10-22 13:55:32 -0700 | [diff] [blame] | 1957 | struct net_device *ndev = cfg_to_ndev(cfg); |
| 1958 | struct brcmf_if *ifp = netdev_priv(ndev); |
Hante Meuleman | 60dc35e | 2015-09-18 22:08:06 +0200 | [diff] [blame] | 1959 | s32 err; |
| 1960 | s32 disable; |
| 1961 | u32 qdbm = 127; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1962 | |
Hante Meuleman | 60dc35e | 2015-09-18 22:08:06 +0200 | [diff] [blame] | 1963 | brcmf_dbg(TRACE, "Enter %d %d\n", type, mbm); |
Arend van Spriel | ce81e31 | 2012-10-22 13:55:37 -0700 | [diff] [blame] | 1964 | if (!check_vif_up(ifp->vif)) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1965 | return -EIO; |
| 1966 | |
| 1967 | switch (type) { |
| 1968 | case NL80211_TX_POWER_AUTOMATIC: |
| 1969 | break; |
| 1970 | case NL80211_TX_POWER_LIMITED: |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1971 | case NL80211_TX_POWER_FIXED: |
Hante Meuleman | 60dc35e | 2015-09-18 22:08:06 +0200 | [diff] [blame] | 1972 | if (mbm < 0) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1973 | brcmf_err("TX_POWER_FIXED - dbm is negative\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1974 | err = -EINVAL; |
| 1975 | goto done; |
| 1976 | } |
Hante Meuleman | 60dc35e | 2015-09-18 22:08:06 +0200 | [diff] [blame] | 1977 | qdbm = MBM_TO_DBM(4 * mbm); |
| 1978 | if (qdbm > 127) |
| 1979 | qdbm = 127; |
| 1980 | qdbm |= WL_TXPWR_OVERRIDE; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1981 | break; |
Hante Meuleman | 60dc35e | 2015-09-18 22:08:06 +0200 | [diff] [blame] | 1982 | default: |
| 1983 | brcmf_err("Unsupported type %d\n", type); |
| 1984 | err = -EINVAL; |
| 1985 | goto done; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1986 | } |
| 1987 | /* Make sure radio is off or on as far as software is concerned */ |
| 1988 | disable = WL_RADIO_SW_DISABLE << 16; |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 1989 | 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] | 1990 | if (err) |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1991 | brcmf_err("WLC_SET_RADIO error (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1992 | |
Hante Meuleman | 60dc35e | 2015-09-18 22:08:06 +0200 | [diff] [blame] | 1993 | err = brcmf_fil_iovar_int_set(ifp, "qtxpower", qdbm); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1994 | if (err) |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1995 | brcmf_err("qtxpower error (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1996 | |
| 1997 | done: |
Hante Meuleman | 60dc35e | 2015-09-18 22:08:06 +0200 | [diff] [blame] | 1998 | brcmf_dbg(TRACE, "Exit %d (qdbm)\n", qdbm & ~WL_TXPWR_OVERRIDE); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1999 | return err; |
| 2000 | } |
| 2001 | |
Hante Meuleman | 60dc35e | 2015-09-18 22:08:06 +0200 | [diff] [blame] | 2002 | static s32 |
| 2003 | brcmf_cfg80211_get_tx_power(struct wiphy *wiphy, struct wireless_dev *wdev, |
| 2004 | s32 *dbm) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2005 | { |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 2006 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); |
Hante Meuleman | 60dc35e | 2015-09-18 22:08:06 +0200 | [diff] [blame] | 2007 | struct net_device *ndev = cfg_to_ndev(cfg); |
| 2008 | struct brcmf_if *ifp = netdev_priv(ndev); |
| 2009 | s32 qdbm = 0; |
| 2010 | s32 err; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2011 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 2012 | brcmf_dbg(TRACE, "Enter\n"); |
Arend van Spriel | ce81e31 | 2012-10-22 13:55:37 -0700 | [diff] [blame] | 2013 | if (!check_vif_up(ifp->vif)) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2014 | return -EIO; |
| 2015 | |
Hante Meuleman | 60dc35e | 2015-09-18 22:08:06 +0200 | [diff] [blame] | 2016 | err = brcmf_fil_iovar_int_get(ifp, "qtxpower", &qdbm); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2017 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 2018 | brcmf_err("error (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2019 | goto done; |
| 2020 | } |
Hante Meuleman | 60dc35e | 2015-09-18 22:08:06 +0200 | [diff] [blame] | 2021 | *dbm = (qdbm & ~WL_TXPWR_OVERRIDE) / 4; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2022 | |
| 2023 | done: |
Hante Meuleman | 60dc35e | 2015-09-18 22:08:06 +0200 | [diff] [blame] | 2024 | brcmf_dbg(TRACE, "Exit (0x%x %d)\n", qdbm, *dbm); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2025 | return err; |
| 2026 | } |
| 2027 | |
| 2028 | static s32 |
| 2029 | brcmf_cfg80211_config_default_key(struct wiphy *wiphy, struct net_device *ndev, |
Hante Meuleman | 60dc35e | 2015-09-18 22:08:06 +0200 | [diff] [blame] | 2030 | u8 key_idx, bool unicast, bool multicast) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2031 | { |
Arend van Spriel | 0abb5f21 | 2012-10-22 13:55:32 -0700 | [diff] [blame] | 2032 | struct brcmf_if *ifp = netdev_priv(ndev); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2033 | u32 index; |
| 2034 | u32 wsec; |
| 2035 | s32 err = 0; |
| 2036 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 2037 | brcmf_dbg(TRACE, "Enter\n"); |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 2038 | brcmf_dbg(CONN, "key index (%d)\n", key_idx); |
Arend van Spriel | ce81e31 | 2012-10-22 13:55:37 -0700 | [diff] [blame] | 2039 | if (!check_vif_up(ifp->vif)) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2040 | return -EIO; |
| 2041 | |
Arend van Spriel | 0abb5f21 | 2012-10-22 13:55:32 -0700 | [diff] [blame] | 2042 | err = brcmf_fil_bsscfg_int_get(ifp, "wsec", &wsec); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2043 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 2044 | brcmf_err("WLC_GET_WSEC error (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2045 | goto done; |
| 2046 | } |
| 2047 | |
| 2048 | if (wsec & WEP_ENABLED) { |
| 2049 | /* Just select a new current key */ |
| 2050 | index = key_idx; |
Arend van Spriel | 0abb5f21 | 2012-10-22 13:55:32 -0700 | [diff] [blame] | 2051 | err = brcmf_fil_cmd_int_set(ifp, |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 2052 | BRCMF_C_SET_KEY_PRIMARY, index); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2053 | if (err) |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 2054 | brcmf_err("error (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2055 | } |
| 2056 | done: |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 2057 | brcmf_dbg(TRACE, "Exit\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2058 | return err; |
| 2059 | } |
| 2060 | |
| 2061 | static s32 |
| 2062 | brcmf_add_keyext(struct wiphy *wiphy, struct net_device *ndev, |
| 2063 | u8 key_idx, const u8 *mac_addr, struct key_params *params) |
| 2064 | { |
Hante Meuleman | 992f606 | 2013-04-02 21:06:17 +0200 | [diff] [blame] | 2065 | struct brcmf_if *ifp = netdev_priv(ndev); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2066 | struct brcmf_wsec_key key; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2067 | s32 err = 0; |
Hante Meuleman | 992f606 | 2013-04-02 21:06:17 +0200 | [diff] [blame] | 2068 | u8 keybuf[8]; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2069 | |
| 2070 | memset(&key, 0, sizeof(key)); |
| 2071 | key.index = (u32) key_idx; |
| 2072 | /* Instead of bcast for ea address for default wep keys, |
| 2073 | driver needs it to be Null */ |
| 2074 | if (!is_multicast_ether_addr(mac_addr)) |
| 2075 | memcpy((char *)&key.ea, (void *)mac_addr, ETH_ALEN); |
| 2076 | key.len = (u32) params->key_len; |
| 2077 | /* check for key index change */ |
| 2078 | if (key.len == 0) { |
| 2079 | /* key delete */ |
Hante Meuleman | 118eb30 | 2014-12-21 12:43:49 +0100 | [diff] [blame] | 2080 | err = send_key_to_dongle(ifp, &key); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2081 | if (err) |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 2082 | brcmf_err("key delete error (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2083 | } else { |
| 2084 | if (key.len > sizeof(key.data)) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 2085 | brcmf_err("Invalid key length (%d)\n", key.len); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2086 | return -EINVAL; |
| 2087 | } |
| 2088 | |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 2089 | brcmf_dbg(CONN, "Setting the key index %d\n", key.index); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2090 | memcpy(key.data, params->key, key.len); |
| 2091 | |
Arend van Spriel | 967fe2c | 2014-03-15 17:18:21 +0100 | [diff] [blame] | 2092 | if (!brcmf_is_apmode(ifp->vif) && |
Hante Meuleman | 992f606 | 2013-04-02 21:06:17 +0200 | [diff] [blame] | 2093 | (params->cipher == WLAN_CIPHER_SUITE_TKIP)) { |
| 2094 | brcmf_dbg(CONN, "Swapping RX/TX MIC key\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2095 | memcpy(keybuf, &key.data[24], sizeof(keybuf)); |
| 2096 | memcpy(&key.data[24], &key.data[16], sizeof(keybuf)); |
| 2097 | memcpy(&key.data[16], keybuf, sizeof(keybuf)); |
| 2098 | } |
| 2099 | |
| 2100 | /* if IW_ENCODE_EXT_RX_SEQ_VALID set */ |
| 2101 | if (params->seq && params->seq_len == 6) { |
| 2102 | /* rx iv */ |
| 2103 | u8 *ivptr; |
| 2104 | ivptr = (u8 *) params->seq; |
| 2105 | key.rxiv.hi = (ivptr[5] << 24) | (ivptr[4] << 16) | |
| 2106 | (ivptr[3] << 8) | ivptr[2]; |
| 2107 | key.rxiv.lo = (ivptr[1] << 8) | ivptr[0]; |
| 2108 | key.iv_initialized = true; |
| 2109 | } |
| 2110 | |
| 2111 | switch (params->cipher) { |
| 2112 | case WLAN_CIPHER_SUITE_WEP40: |
| 2113 | key.algo = CRYPTO_ALGO_WEP1; |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 2114 | brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_WEP40\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2115 | break; |
| 2116 | case WLAN_CIPHER_SUITE_WEP104: |
| 2117 | key.algo = CRYPTO_ALGO_WEP128; |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 2118 | brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_WEP104\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2119 | break; |
| 2120 | case WLAN_CIPHER_SUITE_TKIP: |
| 2121 | key.algo = CRYPTO_ALGO_TKIP; |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 2122 | brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_TKIP\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2123 | break; |
| 2124 | case WLAN_CIPHER_SUITE_AES_CMAC: |
| 2125 | key.algo = CRYPTO_ALGO_AES_CCM; |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 2126 | brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_AES_CMAC\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2127 | break; |
| 2128 | case WLAN_CIPHER_SUITE_CCMP: |
| 2129 | key.algo = CRYPTO_ALGO_AES_CCM; |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 2130 | brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_CCMP\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2131 | break; |
| 2132 | default: |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 2133 | brcmf_err("Invalid cipher (0x%x)\n", params->cipher); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2134 | return -EINVAL; |
| 2135 | } |
Hante Meuleman | 118eb30 | 2014-12-21 12:43:49 +0100 | [diff] [blame] | 2136 | err = send_key_to_dongle(ifp, &key); |
Hante Meuleman | f09d0c0 | 2012-09-27 14:17:48 +0200 | [diff] [blame] | 2137 | if (err) |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 2138 | brcmf_err("wsec_key error (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2139 | } |
| 2140 | return err; |
| 2141 | } |
| 2142 | |
| 2143 | static s32 |
| 2144 | brcmf_cfg80211_add_key(struct wiphy *wiphy, struct net_device *ndev, |
| 2145 | u8 key_idx, bool pairwise, const u8 *mac_addr, |
| 2146 | struct key_params *params) |
| 2147 | { |
Arend van Spriel | 0abb5f21 | 2012-10-22 13:55:32 -0700 | [diff] [blame] | 2148 | struct brcmf_if *ifp = netdev_priv(ndev); |
Hante Meuleman | 118eb30 | 2014-12-21 12:43:49 +0100 | [diff] [blame] | 2149 | struct brcmf_wsec_key *key; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2150 | s32 val; |
| 2151 | s32 wsec; |
| 2152 | s32 err = 0; |
| 2153 | u8 keybuf[8]; |
| 2154 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 2155 | brcmf_dbg(TRACE, "Enter\n"); |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 2156 | brcmf_dbg(CONN, "key index (%d)\n", key_idx); |
Arend van Spriel | ce81e31 | 2012-10-22 13:55:37 -0700 | [diff] [blame] | 2157 | if (!check_vif_up(ifp->vif)) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2158 | return -EIO; |
| 2159 | |
Hante Meuleman | 118eb30 | 2014-12-21 12:43:49 +0100 | [diff] [blame] | 2160 | if (key_idx >= BRCMF_MAX_DEFAULT_KEYS) { |
| 2161 | /* we ignore this key index in this case */ |
| 2162 | brcmf_err("invalid key index (%d)\n", key_idx); |
| 2163 | return -EINVAL; |
| 2164 | } |
| 2165 | |
Daniel Kim | 787eb03 | 2014-01-29 15:32:23 +0100 | [diff] [blame] | 2166 | if (mac_addr && |
| 2167 | (params->cipher != WLAN_CIPHER_SUITE_WEP40) && |
| 2168 | (params->cipher != WLAN_CIPHER_SUITE_WEP104)) { |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 2169 | brcmf_dbg(TRACE, "Exit"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2170 | return brcmf_add_keyext(wiphy, ndev, key_idx, mac_addr, params); |
| 2171 | } |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2172 | |
Hante Meuleman | 118eb30 | 2014-12-21 12:43:49 +0100 | [diff] [blame] | 2173 | key = &ifp->vif->profile.key[key_idx]; |
| 2174 | memset(key, 0, sizeof(*key)); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2175 | |
Hante Meuleman | 118eb30 | 2014-12-21 12:43:49 +0100 | [diff] [blame] | 2176 | if (params->key_len > sizeof(key->data)) { |
| 2177 | brcmf_err("Too long key length (%u)\n", params->key_len); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2178 | err = -EINVAL; |
| 2179 | goto done; |
| 2180 | } |
Hante Meuleman | 118eb30 | 2014-12-21 12:43:49 +0100 | [diff] [blame] | 2181 | key->len = params->key_len; |
| 2182 | key->index = key_idx; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2183 | |
Hante Meuleman | 118eb30 | 2014-12-21 12:43:49 +0100 | [diff] [blame] | 2184 | memcpy(key->data, params->key, key->len); |
| 2185 | |
| 2186 | key->flags = BRCMF_PRIMARY_KEY; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2187 | switch (params->cipher) { |
| 2188 | case WLAN_CIPHER_SUITE_WEP40: |
Hante Meuleman | 118eb30 | 2014-12-21 12:43:49 +0100 | [diff] [blame] | 2189 | key->algo = CRYPTO_ALGO_WEP1; |
Hante Meuleman | f09d0c0 | 2012-09-27 14:17:48 +0200 | [diff] [blame] | 2190 | val = WEP_ENABLED; |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 2191 | brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_WEP40\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2192 | break; |
| 2193 | case WLAN_CIPHER_SUITE_WEP104: |
Hante Meuleman | 118eb30 | 2014-12-21 12:43:49 +0100 | [diff] [blame] | 2194 | key->algo = CRYPTO_ALGO_WEP128; |
Hante Meuleman | f09d0c0 | 2012-09-27 14:17:48 +0200 | [diff] [blame] | 2195 | val = WEP_ENABLED; |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 2196 | brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_WEP104\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2197 | break; |
| 2198 | case WLAN_CIPHER_SUITE_TKIP: |
Arend van Spriel | 967fe2c | 2014-03-15 17:18:21 +0100 | [diff] [blame] | 2199 | if (!brcmf_is_apmode(ifp->vif)) { |
Hante Meuleman | 992f606 | 2013-04-02 21:06:17 +0200 | [diff] [blame] | 2200 | brcmf_dbg(CONN, "Swapping RX/TX MIC key\n"); |
Hante Meuleman | 118eb30 | 2014-12-21 12:43:49 +0100 | [diff] [blame] | 2201 | memcpy(keybuf, &key->data[24], sizeof(keybuf)); |
| 2202 | memcpy(&key->data[24], &key->data[16], sizeof(keybuf)); |
| 2203 | memcpy(&key->data[16], keybuf, sizeof(keybuf)); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 2204 | } |
Hante Meuleman | 118eb30 | 2014-12-21 12:43:49 +0100 | [diff] [blame] | 2205 | key->algo = CRYPTO_ALGO_TKIP; |
Hante Meuleman | f09d0c0 | 2012-09-27 14:17:48 +0200 | [diff] [blame] | 2206 | val = TKIP_ENABLED; |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 2207 | brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_TKIP\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2208 | break; |
| 2209 | case WLAN_CIPHER_SUITE_AES_CMAC: |
Hante Meuleman | 118eb30 | 2014-12-21 12:43:49 +0100 | [diff] [blame] | 2210 | key->algo = CRYPTO_ALGO_AES_CCM; |
Hante Meuleman | f09d0c0 | 2012-09-27 14:17:48 +0200 | [diff] [blame] | 2211 | val = AES_ENABLED; |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 2212 | brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_AES_CMAC\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2213 | break; |
| 2214 | case WLAN_CIPHER_SUITE_CCMP: |
Hante Meuleman | 118eb30 | 2014-12-21 12:43:49 +0100 | [diff] [blame] | 2215 | key->algo = CRYPTO_ALGO_AES_CCM; |
Hante Meuleman | f09d0c0 | 2012-09-27 14:17:48 +0200 | [diff] [blame] | 2216 | val = AES_ENABLED; |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 2217 | brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_CCMP\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2218 | break; |
| 2219 | default: |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 2220 | brcmf_err("Invalid cipher (0x%x)\n", params->cipher); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2221 | err = -EINVAL; |
| 2222 | goto done; |
| 2223 | } |
| 2224 | |
Hante Meuleman | 118eb30 | 2014-12-21 12:43:49 +0100 | [diff] [blame] | 2225 | err = send_key_to_dongle(ifp, key); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2226 | if (err) |
| 2227 | goto done; |
| 2228 | |
Arend van Spriel | 0abb5f21 | 2012-10-22 13:55:32 -0700 | [diff] [blame] | 2229 | err = brcmf_fil_bsscfg_int_get(ifp, "wsec", &wsec); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2230 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 2231 | brcmf_err("get wsec error (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2232 | goto done; |
| 2233 | } |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2234 | wsec |= val; |
Arend van Spriel | 0abb5f21 | 2012-10-22 13:55:32 -0700 | [diff] [blame] | 2235 | err = brcmf_fil_bsscfg_int_set(ifp, "wsec", wsec); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2236 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 2237 | brcmf_err("set wsec error (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2238 | goto done; |
| 2239 | } |
| 2240 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2241 | done: |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 2242 | brcmf_dbg(TRACE, "Exit\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2243 | return err; |
| 2244 | } |
| 2245 | |
| 2246 | static s32 |
| 2247 | brcmf_cfg80211_del_key(struct wiphy *wiphy, struct net_device *ndev, |
| 2248 | u8 key_idx, bool pairwise, const u8 *mac_addr) |
| 2249 | { |
Arend van Spriel | 0abb5f21 | 2012-10-22 13:55:32 -0700 | [diff] [blame] | 2250 | struct brcmf_if *ifp = netdev_priv(ndev); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2251 | struct brcmf_wsec_key key; |
| 2252 | s32 err = 0; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2253 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 2254 | brcmf_dbg(TRACE, "Enter\n"); |
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) { |
Hante Meuleman | 256c374 | 2012-11-05 16:22:28 -0800 | [diff] [blame] | 2259 | /* we ignore this key index in this case */ |
Hante Meuleman | 256c374 | 2012-11-05 16:22:28 -0800 | [diff] [blame] | 2260 | return -EINVAL; |
| 2261 | } |
| 2262 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2263 | memset(&key, 0, sizeof(key)); |
| 2264 | |
| 2265 | key.index = (u32) key_idx; |
| 2266 | key.flags = BRCMF_PRIMARY_KEY; |
| 2267 | key.algo = CRYPTO_ALGO_OFF; |
| 2268 | |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 2269 | brcmf_dbg(CONN, "key index (%d)\n", key_idx); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2270 | |
| 2271 | /* Set the new key/index */ |
Hante Meuleman | 118eb30 | 2014-12-21 12:43:49 +0100 | [diff] [blame] | 2272 | err = send_key_to_dongle(ifp, &key); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2273 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 2274 | brcmf_dbg(TRACE, "Exit\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2275 | return err; |
| 2276 | } |
| 2277 | |
| 2278 | static s32 |
| 2279 | brcmf_cfg80211_get_key(struct wiphy *wiphy, struct net_device *ndev, |
| 2280 | u8 key_idx, bool pairwise, const u8 *mac_addr, void *cookie, |
| 2281 | void (*callback) (void *cookie, struct key_params * params)) |
| 2282 | { |
| 2283 | struct key_params params; |
Arend van Spriel | 0abb5f21 | 2012-10-22 13:55:32 -0700 | [diff] [blame] | 2284 | struct brcmf_if *ifp = netdev_priv(ndev); |
| 2285 | struct brcmf_cfg80211_profile *profile = &ifp->vif->profile; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2286 | struct brcmf_cfg80211_security *sec; |
| 2287 | s32 wsec; |
| 2288 | s32 err = 0; |
| 2289 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 2290 | brcmf_dbg(TRACE, "Enter\n"); |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 2291 | brcmf_dbg(CONN, "key index (%d)\n", key_idx); |
Arend van Spriel | ce81e31 | 2012-10-22 13:55:37 -0700 | [diff] [blame] | 2292 | if (!check_vif_up(ifp->vif)) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2293 | return -EIO; |
| 2294 | |
| 2295 | memset(¶ms, 0, sizeof(params)); |
| 2296 | |
Arend van Spriel | 0abb5f21 | 2012-10-22 13:55:32 -0700 | [diff] [blame] | 2297 | err = brcmf_fil_bsscfg_int_get(ifp, "wsec", &wsec); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2298 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 2299 | brcmf_err("WLC_GET_WSEC error (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2300 | /* Ignore this error, may happen during DISASSOC */ |
| 2301 | err = -EAGAIN; |
| 2302 | goto done; |
| 2303 | } |
Hante Meuleman | c5bf53a | 2013-04-02 21:06:19 +0200 | [diff] [blame] | 2304 | if (wsec & WEP_ENABLED) { |
Arend van Spriel | 06bb123 | 2012-09-27 14:17:56 +0200 | [diff] [blame] | 2305 | sec = &profile->sec; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2306 | if (sec->cipher_pairwise & WLAN_CIPHER_SUITE_WEP40) { |
| 2307 | params.cipher = WLAN_CIPHER_SUITE_WEP40; |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 2308 | brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_WEP40\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2309 | } else if (sec->cipher_pairwise & WLAN_CIPHER_SUITE_WEP104) { |
| 2310 | params.cipher = WLAN_CIPHER_SUITE_WEP104; |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 2311 | brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_WEP104\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2312 | } |
Hante Meuleman | c5bf53a | 2013-04-02 21:06:19 +0200 | [diff] [blame] | 2313 | } else if (wsec & TKIP_ENABLED) { |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2314 | params.cipher = WLAN_CIPHER_SUITE_TKIP; |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 2315 | brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_TKIP\n"); |
Hante Meuleman | c5bf53a | 2013-04-02 21:06:19 +0200 | [diff] [blame] | 2316 | } else if (wsec & AES_ENABLED) { |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2317 | params.cipher = WLAN_CIPHER_SUITE_AES_CMAC; |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 2318 | brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_AES_CMAC\n"); |
Hante Meuleman | c5bf53a | 2013-04-02 21:06:19 +0200 | [diff] [blame] | 2319 | } else { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 2320 | brcmf_err("Invalid algo (0x%x)\n", wsec); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2321 | err = -EINVAL; |
| 2322 | goto done; |
| 2323 | } |
| 2324 | callback(cookie, ¶ms); |
| 2325 | |
| 2326 | done: |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 2327 | brcmf_dbg(TRACE, "Exit\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2328 | return err; |
| 2329 | } |
| 2330 | |
| 2331 | static s32 |
| 2332 | brcmf_cfg80211_config_default_mgmt_key(struct wiphy *wiphy, |
| 2333 | struct net_device *ndev, u8 key_idx) |
| 2334 | { |
Arend van Spriel | 647c9ae | 2012-12-05 15:26:01 +0100 | [diff] [blame] | 2335 | brcmf_dbg(INFO, "Not supported\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2336 | |
| 2337 | return -EOPNOTSUPP; |
| 2338 | } |
| 2339 | |
Hante Meuleman | 118eb30 | 2014-12-21 12:43:49 +0100 | [diff] [blame] | 2340 | static void |
| 2341 | brcmf_cfg80211_reconfigure_wep(struct brcmf_if *ifp) |
| 2342 | { |
| 2343 | s32 err; |
| 2344 | u8 key_idx; |
| 2345 | struct brcmf_wsec_key *key; |
| 2346 | s32 wsec; |
| 2347 | |
| 2348 | for (key_idx = 0; key_idx < BRCMF_MAX_DEFAULT_KEYS; key_idx++) { |
| 2349 | key = &ifp->vif->profile.key[key_idx]; |
| 2350 | if ((key->algo == CRYPTO_ALGO_WEP1) || |
| 2351 | (key->algo == CRYPTO_ALGO_WEP128)) |
| 2352 | break; |
| 2353 | } |
| 2354 | if (key_idx == BRCMF_MAX_DEFAULT_KEYS) |
| 2355 | return; |
| 2356 | |
| 2357 | err = send_key_to_dongle(ifp, key); |
| 2358 | if (err) { |
| 2359 | brcmf_err("Setting WEP key failed (%d)\n", err); |
| 2360 | return; |
| 2361 | } |
| 2362 | err = brcmf_fil_bsscfg_int_get(ifp, "wsec", &wsec); |
| 2363 | if (err) { |
| 2364 | brcmf_err("get wsec error (%d)\n", err); |
| 2365 | return; |
| 2366 | } |
| 2367 | wsec |= WEP_ENABLED; |
| 2368 | err = brcmf_fil_bsscfg_int_set(ifp, "wsec", wsec); |
| 2369 | if (err) |
| 2370 | brcmf_err("set wsec error (%d)\n", err); |
| 2371 | } |
| 2372 | |
Arend van Spriel | 1f0dc59 | 2015-06-11 00:12:19 +0200 | [diff] [blame] | 2373 | static void brcmf_convert_sta_flags(u32 fw_sta_flags, struct station_info *si) |
| 2374 | { |
| 2375 | struct nl80211_sta_flag_update *sfu; |
| 2376 | |
| 2377 | brcmf_dbg(TRACE, "flags %08x\n", fw_sta_flags); |
| 2378 | si->filled |= BIT(NL80211_STA_INFO_STA_FLAGS); |
| 2379 | sfu = &si->sta_flags; |
| 2380 | sfu->mask = BIT(NL80211_STA_FLAG_WME) | |
| 2381 | BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 2382 | BIT(NL80211_STA_FLAG_ASSOCIATED) | |
| 2383 | BIT(NL80211_STA_FLAG_AUTHORIZED); |
| 2384 | if (fw_sta_flags & BRCMF_STA_WME) |
| 2385 | sfu->set |= BIT(NL80211_STA_FLAG_WME); |
| 2386 | if (fw_sta_flags & BRCMF_STA_AUTHE) |
| 2387 | sfu->set |= BIT(NL80211_STA_FLAG_AUTHENTICATED); |
| 2388 | if (fw_sta_flags & BRCMF_STA_ASSOC) |
| 2389 | sfu->set |= BIT(NL80211_STA_FLAG_ASSOCIATED); |
| 2390 | if (fw_sta_flags & BRCMF_STA_AUTHO) |
| 2391 | sfu->set |= BIT(NL80211_STA_FLAG_AUTHORIZED); |
| 2392 | } |
| 2393 | |
| 2394 | static void brcmf_fill_bss_param(struct brcmf_if *ifp, struct station_info *si) |
| 2395 | { |
| 2396 | struct { |
| 2397 | __le32 len; |
| 2398 | struct brcmf_bss_info_le bss_le; |
| 2399 | } *buf; |
| 2400 | u16 capability; |
| 2401 | int err; |
| 2402 | |
| 2403 | buf = kzalloc(WL_BSS_INFO_MAX, GFP_KERNEL); |
| 2404 | if (!buf) |
| 2405 | return; |
| 2406 | |
| 2407 | buf->len = cpu_to_le32(WL_BSS_INFO_MAX); |
| 2408 | err = brcmf_fil_cmd_data_get(ifp, BRCMF_C_GET_BSS_INFO, buf, |
| 2409 | WL_BSS_INFO_MAX); |
| 2410 | if (err) { |
| 2411 | brcmf_err("Failed to get bss info (%d)\n", err); |
| 2412 | return; |
| 2413 | } |
| 2414 | si->filled |= BIT(NL80211_STA_INFO_BSS_PARAM); |
| 2415 | si->bss_param.beacon_interval = le16_to_cpu(buf->bss_le.beacon_period); |
| 2416 | si->bss_param.dtim_period = buf->bss_le.dtim_period; |
| 2417 | capability = le16_to_cpu(buf->bss_le.capability); |
| 2418 | if (capability & IEEE80211_HT_STBC_PARAM_DUAL_CTS_PROT) |
| 2419 | si->bss_param.flags |= BSS_PARAM_FLAGS_CTS_PROT; |
| 2420 | if (capability & WLAN_CAPABILITY_SHORT_PREAMBLE) |
| 2421 | si->bss_param.flags |= BSS_PARAM_FLAGS_SHORT_PREAMBLE; |
| 2422 | if (capability & WLAN_CAPABILITY_SHORT_SLOT_TIME) |
| 2423 | si->bss_param.flags |= BSS_PARAM_FLAGS_SHORT_SLOT_TIME; |
| 2424 | } |
| 2425 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2426 | static s32 |
| 2427 | brcmf_cfg80211_get_station(struct wiphy *wiphy, struct net_device *ndev, |
Johannes Berg | 3b3a016 | 2014-05-19 17:19:31 +0200 | [diff] [blame] | 2428 | const u8 *mac, struct station_info *sinfo) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2429 | { |
Arend van Spriel | 0abb5f21 | 2012-10-22 13:55:32 -0700 | [diff] [blame] | 2430 | struct brcmf_if *ifp = netdev_priv(ndev); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2431 | s32 err = 0; |
Hante Meuleman | 81f5dcb | 2012-10-22 10:36:14 -0700 | [diff] [blame] | 2432 | struct brcmf_sta_info_le sta_info_le; |
Arend van Spriel | 1f0dc59 | 2015-06-11 00:12:19 +0200 | [diff] [blame] | 2433 | u32 sta_flags; |
| 2434 | u32 is_tdls_peer; |
Hante Meuleman | cae355d | 2015-10-08 20:33:17 +0200 | [diff] [blame^] | 2435 | s32 total_rssi; |
| 2436 | s32 count_rssi; |
| 2437 | u32 i; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2438 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 2439 | brcmf_dbg(TRACE, "Enter, MAC %pM\n", mac); |
Arend van Spriel | ce81e31 | 2012-10-22 13:55:37 -0700 | [diff] [blame] | 2440 | if (!check_vif_up(ifp->vif)) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2441 | return -EIO; |
| 2442 | |
Arend van Spriel | 1f0dc59 | 2015-06-11 00:12:19 +0200 | [diff] [blame] | 2443 | memset(&sta_info_le, 0, sizeof(sta_info_le)); |
| 2444 | memcpy(&sta_info_le, mac, ETH_ALEN); |
| 2445 | err = brcmf_fil_iovar_data_get(ifp, "tdls_sta_info", |
| 2446 | &sta_info_le, |
| 2447 | sizeof(sta_info_le)); |
| 2448 | is_tdls_peer = !err; |
| 2449 | if (err) { |
Arend van Spriel | 0abb5f21 | 2012-10-22 13:55:32 -0700 | [diff] [blame] | 2450 | err = brcmf_fil_iovar_data_get(ifp, "sta_info", |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 2451 | &sta_info_le, |
Hante Meuleman | 81f5dcb | 2012-10-22 10:36:14 -0700 | [diff] [blame] | 2452 | sizeof(sta_info_le)); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 2453 | if (err < 0) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 2454 | brcmf_err("GET STA INFO failed, %d\n", err); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 2455 | goto done; |
Hante Meuleman | 7f6c562 | 2012-08-30 10:05:37 +0200 | [diff] [blame] | 2456 | } |
Arend van Spriel | 1f0dc59 | 2015-06-11 00:12:19 +0200 | [diff] [blame] | 2457 | } |
| 2458 | brcmf_dbg(TRACE, "version %d\n", le16_to_cpu(sta_info_le.ver)); |
| 2459 | sinfo->filled = BIT(NL80211_STA_INFO_INACTIVE_TIME); |
| 2460 | sinfo->inactive_time = le32_to_cpu(sta_info_le.idle) * 1000; |
| 2461 | sta_flags = le32_to_cpu(sta_info_le.flags); |
| 2462 | brcmf_convert_sta_flags(sta_flags, sinfo); |
| 2463 | sinfo->sta_flags.mask |= BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 2464 | if (is_tdls_peer) |
| 2465 | sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 2466 | else |
| 2467 | sinfo->sta_flags.set &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 2468 | if (sta_flags & BRCMF_STA_ASSOC) { |
| 2469 | sinfo->filled |= BIT(NL80211_STA_INFO_CONNECTED_TIME); |
| 2470 | sinfo->connected_time = le32_to_cpu(sta_info_le.in); |
| 2471 | brcmf_fill_bss_param(ifp, sinfo); |
| 2472 | } |
| 2473 | if (sta_flags & BRCMF_STA_SCBSTATS) { |
| 2474 | sinfo->filled |= BIT(NL80211_STA_INFO_TX_FAILED); |
| 2475 | sinfo->tx_failed = le32_to_cpu(sta_info_le.tx_failures); |
| 2476 | sinfo->filled |= BIT(NL80211_STA_INFO_TX_PACKETS); |
| 2477 | sinfo->tx_packets = le32_to_cpu(sta_info_le.tx_pkts); |
| 2478 | sinfo->tx_packets += le32_to_cpu(sta_info_le.tx_mcast_pkts); |
| 2479 | sinfo->filled |= BIT(NL80211_STA_INFO_RX_PACKETS); |
| 2480 | sinfo->rx_packets = le32_to_cpu(sta_info_le.rx_ucast_pkts); |
| 2481 | sinfo->rx_packets += le32_to_cpu(sta_info_le.rx_mcast_pkts); |
| 2482 | if (sinfo->tx_packets) { |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 2483 | sinfo->filled |= BIT(NL80211_STA_INFO_TX_BITRATE); |
Hante Meuleman | 124d517 | 2015-10-08 20:33:16 +0200 | [diff] [blame] | 2484 | sinfo->txrate.legacy = |
| 2485 | le32_to_cpu(sta_info_le.tx_rate) / 100; |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 2486 | } |
Arend van Spriel | 1f0dc59 | 2015-06-11 00:12:19 +0200 | [diff] [blame] | 2487 | if (sinfo->rx_packets) { |
| 2488 | sinfo->filled |= BIT(NL80211_STA_INFO_RX_BITRATE); |
Hante Meuleman | 124d517 | 2015-10-08 20:33:16 +0200 | [diff] [blame] | 2489 | sinfo->rxrate.legacy = |
| 2490 | le32_to_cpu(sta_info_le.rx_rate) / 100; |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 2491 | } |
Arend van Spriel | 1f0dc59 | 2015-06-11 00:12:19 +0200 | [diff] [blame] | 2492 | if (le16_to_cpu(sta_info_le.ver) >= 4) { |
| 2493 | sinfo->filled |= BIT(NL80211_STA_INFO_TX_BYTES); |
| 2494 | sinfo->tx_bytes = le64_to_cpu(sta_info_le.tx_tot_bytes); |
| 2495 | sinfo->filled |= BIT(NL80211_STA_INFO_RX_BYTES); |
| 2496 | sinfo->rx_bytes = le64_to_cpu(sta_info_le.rx_tot_bytes); |
| 2497 | } |
Hante Meuleman | cae355d | 2015-10-08 20:33:17 +0200 | [diff] [blame^] | 2498 | total_rssi = 0; |
| 2499 | count_rssi = 0; |
| 2500 | for (i = 0; i < BRCMF_ANT_MAX; i++) { |
| 2501 | if (sta_info_le.rssi[i]) { |
| 2502 | sinfo->chain_signal_avg[count_rssi] = |
| 2503 | sta_info_le.rssi[i]; |
| 2504 | sinfo->chain_signal[count_rssi] = |
| 2505 | sta_info_le.rssi[i]; |
| 2506 | total_rssi += sta_info_le.rssi[i]; |
| 2507 | count_rssi++; |
| 2508 | } |
| 2509 | } |
| 2510 | if (count_rssi) { |
| 2511 | sinfo->filled |= BIT(NL80211_STA_INFO_CHAIN_SIGNAL); |
| 2512 | sinfo->chains = count_rssi; |
| 2513 | |
| 2514 | sinfo->filled |= BIT(NL80211_STA_INFO_SIGNAL); |
| 2515 | total_rssi /= count_rssi; |
| 2516 | sinfo->signal = total_rssi; |
| 2517 | } |
Arend van Spriel | 1f0dc59 | 2015-06-11 00:12:19 +0200 | [diff] [blame] | 2518 | } |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2519 | done: |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 2520 | brcmf_dbg(TRACE, "Exit\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2521 | return err; |
| 2522 | } |
| 2523 | |
| 2524 | static s32 |
| 2525 | brcmf_cfg80211_set_power_mgmt(struct wiphy *wiphy, struct net_device *ndev, |
| 2526 | bool enabled, s32 timeout) |
| 2527 | { |
| 2528 | s32 pm; |
| 2529 | s32 err = 0; |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 2530 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 2531 | struct brcmf_if *ifp = netdev_priv(ndev); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2532 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 2533 | brcmf_dbg(TRACE, "Enter\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2534 | |
| 2535 | /* |
| 2536 | * Powersave enable/disable request is coming from the |
| 2537 | * cfg80211 even before the interface is up. In that |
| 2538 | * scenario, driver will be storing the power save |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 2539 | * preference in cfg struct to apply this to |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2540 | * FW later while initializing the dongle |
| 2541 | */ |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 2542 | cfg->pwr_save = enabled; |
Arend van Spriel | ce81e31 | 2012-10-22 13:55:37 -0700 | [diff] [blame] | 2543 | if (!check_vif_up(ifp->vif)) { |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2544 | |
Arend van Spriel | 647c9ae | 2012-12-05 15:26:01 +0100 | [diff] [blame] | 2545 | 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] | 2546 | goto done; |
| 2547 | } |
| 2548 | |
| 2549 | pm = enabled ? PM_FAST : PM_OFF; |
Hante Meuleman | 102fd0d | 2013-05-27 21:09:59 +0200 | [diff] [blame] | 2550 | /* Do not enable the power save after assoc if it is a p2p interface */ |
| 2551 | if (ifp->vif->wdev.iftype == NL80211_IFTYPE_P2P_CLIENT) { |
| 2552 | brcmf_dbg(INFO, "Do not enable power save for P2P clients\n"); |
| 2553 | pm = PM_OFF; |
| 2554 | } |
Arend van Spriel | 647c9ae | 2012-12-05 15:26:01 +0100 | [diff] [blame] | 2555 | brcmf_dbg(INFO, "power save %s\n", (pm ? "enabled" : "disabled")); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2556 | |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 2557 | 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] | 2558 | if (err) { |
| 2559 | if (err == -ENODEV) |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 2560 | brcmf_err("net_device is not ready yet\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2561 | else |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 2562 | brcmf_err("error (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2563 | } |
| 2564 | done: |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 2565 | brcmf_dbg(TRACE, "Exit\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2566 | return err; |
| 2567 | } |
| 2568 | |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 2569 | static s32 brcmf_inform_single_bss(struct brcmf_cfg80211_info *cfg, |
Roland Vossen | d34bf64 | 2011-10-18 14:03:01 +0200 | [diff] [blame] | 2570 | struct brcmf_bss_info_le *bi) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2571 | { |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 2572 | struct wiphy *wiphy = cfg_to_wiphy(cfg); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2573 | struct ieee80211_channel *notify_channel; |
| 2574 | struct cfg80211_bss *bss; |
| 2575 | struct ieee80211_supported_band *band; |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 2576 | struct brcmu_chan ch; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2577 | u16 channel; |
| 2578 | u32 freq; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2579 | u16 notify_capability; |
| 2580 | u16 notify_interval; |
| 2581 | u8 *notify_ie; |
| 2582 | size_t notify_ielen; |
| 2583 | s32 notify_signal; |
| 2584 | |
| 2585 | if (le32_to_cpu(bi->length) > WL_BSS_INFO_MAX) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 2586 | brcmf_err("Bss info is larger than buffer. Discarding\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2587 | return 0; |
| 2588 | } |
| 2589 | |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 2590 | if (!bi->ctl_ch) { |
| 2591 | ch.chspec = le16_to_cpu(bi->chanspec); |
| 2592 | cfg->d11inf.decchspec(&ch); |
| 2593 | bi->ctl_ch = ch.chnum; |
| 2594 | } |
| 2595 | channel = bi->ctl_ch; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2596 | |
| 2597 | if (channel <= CH_MAX_2G_CHANNEL) |
| 2598 | band = wiphy->bands[IEEE80211_BAND_2GHZ]; |
| 2599 | else |
| 2600 | band = wiphy->bands[IEEE80211_BAND_5GHZ]; |
| 2601 | |
| 2602 | freq = ieee80211_channel_to_frequency(channel, band->band); |
| 2603 | notify_channel = ieee80211_get_channel(wiphy, freq); |
| 2604 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2605 | notify_capability = le16_to_cpu(bi->capability); |
| 2606 | notify_interval = le16_to_cpu(bi->beacon_period); |
| 2607 | notify_ie = (u8 *)bi + le16_to_cpu(bi->ie_offset); |
| 2608 | notify_ielen = le32_to_cpu(bi->ie_length); |
| 2609 | notify_signal = (s16)le16_to_cpu(bi->RSSI) * 100; |
| 2610 | |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 2611 | brcmf_dbg(CONN, "bssid: %pM\n", bi->BSSID); |
| 2612 | brcmf_dbg(CONN, "Channel: %d(%d)\n", channel, freq); |
| 2613 | brcmf_dbg(CONN, "Capability: %X\n", notify_capability); |
| 2614 | brcmf_dbg(CONN, "Beacon interval: %d\n", notify_interval); |
| 2615 | brcmf_dbg(CONN, "Signal: %d\n", notify_signal); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2616 | |
Johannes Berg | 5bc8c1f | 2014-08-12 21:01:28 +0200 | [diff] [blame] | 2617 | bss = cfg80211_inform_bss(wiphy, notify_channel, |
| 2618 | CFG80211_BSS_FTYPE_UNKNOWN, |
| 2619 | (const u8 *)bi->BSSID, |
| 2620 | 0, notify_capability, |
| 2621 | notify_interval, notify_ie, |
| 2622 | notify_ielen, notify_signal, |
| 2623 | GFP_KERNEL); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2624 | |
Franky Lin | e78946e | 2011-11-10 20:30:34 +0100 | [diff] [blame] | 2625 | if (!bss) |
| 2626 | return -ENOMEM; |
| 2627 | |
Johannes Berg | 5b112d3 | 2013-02-01 01:49:58 +0100 | [diff] [blame] | 2628 | cfg80211_put_bss(wiphy, bss); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2629 | |
Peter Senna Tschudin | 12f3237 | 2014-05-31 10:14:06 -0300 | [diff] [blame] | 2630 | return 0; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2631 | } |
| 2632 | |
Roland Vossen | 6f09be0 | 2011-10-18 14:03:02 +0200 | [diff] [blame] | 2633 | static struct brcmf_bss_info_le * |
| 2634 | next_bss_le(struct brcmf_scan_results *list, struct brcmf_bss_info_le *bss) |
| 2635 | { |
| 2636 | if (bss == NULL) |
| 2637 | return list->bss_info_le; |
| 2638 | return (struct brcmf_bss_info_le *)((unsigned long)bss + |
| 2639 | le32_to_cpu(bss->length)); |
| 2640 | } |
| 2641 | |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 2642 | static s32 brcmf_inform_bss(struct brcmf_cfg80211_info *cfg) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2643 | { |
| 2644 | struct brcmf_scan_results *bss_list; |
Roland Vossen | d34bf64 | 2011-10-18 14:03:01 +0200 | [diff] [blame] | 2645 | struct brcmf_bss_info_le *bi = NULL; /* must be initialized */ |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2646 | s32 err = 0; |
| 2647 | int i; |
| 2648 | |
Hante Meuleman | ef8596e | 2014-09-30 10:23:13 +0200 | [diff] [blame] | 2649 | bss_list = (struct brcmf_scan_results *)cfg->escan_info.escan_buf; |
Arend van Spriel | 0ecd816 | 2012-11-05 16:22:11 -0800 | [diff] [blame] | 2650 | if (bss_list->count != 0 && |
| 2651 | bss_list->version != BRCMF_BSS_INFO_VERSION) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 2652 | brcmf_err("Version %d != WL_BSS_INFO_VERSION\n", |
| 2653 | bss_list->version); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2654 | return -EOPNOTSUPP; |
| 2655 | } |
Arend van Spriel | 4e8a008 | 2012-12-05 15:26:03 +0100 | [diff] [blame] | 2656 | brcmf_dbg(SCAN, "scanned AP count (%d)\n", bss_list->count); |
Hante Meuleman | f0799895 | 2012-11-05 16:22:13 -0800 | [diff] [blame] | 2657 | for (i = 0; i < bss_list->count; i++) { |
Roland Vossen | 6f09be0 | 2011-10-18 14:03:02 +0200 | [diff] [blame] | 2658 | bi = next_bss_le(bss_list, bi); |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 2659 | err = brcmf_inform_single_bss(cfg, bi); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2660 | if (err) |
| 2661 | break; |
| 2662 | } |
| 2663 | return err; |
| 2664 | } |
| 2665 | |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 2666 | static s32 wl_inform_ibss(struct brcmf_cfg80211_info *cfg, |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2667 | struct net_device *ndev, const u8 *bssid) |
| 2668 | { |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 2669 | struct wiphy *wiphy = cfg_to_wiphy(cfg); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2670 | struct ieee80211_channel *notify_channel; |
Roland Vossen | d34bf64 | 2011-10-18 14:03:01 +0200 | [diff] [blame] | 2671 | struct brcmf_bss_info_le *bi = NULL; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2672 | struct ieee80211_supported_band *band; |
Franky Lin | e78946e | 2011-11-10 20:30:34 +0100 | [diff] [blame] | 2673 | struct cfg80211_bss *bss; |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 2674 | struct brcmu_chan ch; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2675 | u8 *buf = NULL; |
| 2676 | s32 err = 0; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2677 | u32 freq; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2678 | u16 notify_capability; |
| 2679 | u16 notify_interval; |
| 2680 | u8 *notify_ie; |
| 2681 | size_t notify_ielen; |
| 2682 | s32 notify_signal; |
| 2683 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 2684 | brcmf_dbg(TRACE, "Enter\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2685 | |
| 2686 | buf = kzalloc(WL_BSS_INFO_MAX, GFP_KERNEL); |
| 2687 | if (buf == NULL) { |
| 2688 | err = -ENOMEM; |
| 2689 | goto CleanUp; |
| 2690 | } |
| 2691 | |
| 2692 | *(__le32 *)buf = cpu_to_le32(WL_BSS_INFO_MAX); |
| 2693 | |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 2694 | err = brcmf_fil_cmd_data_get(netdev_priv(ndev), BRCMF_C_GET_BSS_INFO, |
| 2695 | buf, WL_BSS_INFO_MAX); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2696 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 2697 | brcmf_err("WLC_GET_BSS_INFO failed: %d\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2698 | goto CleanUp; |
| 2699 | } |
| 2700 | |
Roland Vossen | d34bf64 | 2011-10-18 14:03:01 +0200 | [diff] [blame] | 2701 | bi = (struct brcmf_bss_info_le *)(buf + 4); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2702 | |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 2703 | ch.chspec = le16_to_cpu(bi->chanspec); |
| 2704 | cfg->d11inf.decchspec(&ch); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2705 | |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 2706 | if (ch.band == BRCMU_CHAN_BAND_2G) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2707 | band = wiphy->bands[IEEE80211_BAND_2GHZ]; |
| 2708 | else |
| 2709 | band = wiphy->bands[IEEE80211_BAND_5GHZ]; |
| 2710 | |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 2711 | freq = ieee80211_channel_to_frequency(ch.chnum, band->band); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2712 | notify_channel = ieee80211_get_channel(wiphy, freq); |
| 2713 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2714 | notify_capability = le16_to_cpu(bi->capability); |
| 2715 | notify_interval = le16_to_cpu(bi->beacon_period); |
| 2716 | notify_ie = (u8 *)bi + le16_to_cpu(bi->ie_offset); |
| 2717 | notify_ielen = le32_to_cpu(bi->ie_length); |
| 2718 | notify_signal = (s16)le16_to_cpu(bi->RSSI) * 100; |
| 2719 | |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 2720 | brcmf_dbg(CONN, "channel: %d(%d)\n", ch.chnum, freq); |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 2721 | brcmf_dbg(CONN, "capability: %X\n", notify_capability); |
| 2722 | brcmf_dbg(CONN, "beacon interval: %d\n", notify_interval); |
| 2723 | brcmf_dbg(CONN, "signal: %d\n", notify_signal); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2724 | |
Johannes Berg | 5bc8c1f | 2014-08-12 21:01:28 +0200 | [diff] [blame] | 2725 | bss = cfg80211_inform_bss(wiphy, notify_channel, |
| 2726 | CFG80211_BSS_FTYPE_UNKNOWN, bssid, 0, |
| 2727 | notify_capability, notify_interval, |
| 2728 | notify_ie, notify_ielen, notify_signal, |
| 2729 | GFP_KERNEL); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2730 | |
Franky Lin | e78946e | 2011-11-10 20:30:34 +0100 | [diff] [blame] | 2731 | if (!bss) { |
| 2732 | err = -ENOMEM; |
| 2733 | goto CleanUp; |
| 2734 | } |
| 2735 | |
Johannes Berg | 5b112d3 | 2013-02-01 01:49:58 +0100 | [diff] [blame] | 2736 | cfg80211_put_bss(wiphy, bss); |
Franky Lin | e78946e | 2011-11-10 20:30:34 +0100 | [diff] [blame] | 2737 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2738 | CleanUp: |
| 2739 | |
| 2740 | kfree(buf); |
| 2741 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 2742 | brcmf_dbg(TRACE, "Exit\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2743 | |
| 2744 | return err; |
| 2745 | } |
| 2746 | |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 2747 | static s32 brcmf_update_bss_info(struct brcmf_cfg80211_info *cfg, |
| 2748 | struct brcmf_if *ifp) |
Alwin Beukers | f8e4b41 | 2011-10-12 20:51:28 +0200 | [diff] [blame] | 2749 | { |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 2750 | struct brcmf_cfg80211_profile *profile = ndev_to_prof(ifp->ndev); |
Roland Vossen | d34bf64 | 2011-10-18 14:03:01 +0200 | [diff] [blame] | 2751 | struct brcmf_bss_info_le *bi; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2752 | struct brcmf_ssid *ssid; |
Johannes Berg | 4b5800f | 2014-01-15 14:55:59 +0100 | [diff] [blame] | 2753 | const struct brcmf_tlv *tim; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2754 | u16 beacon_interval; |
| 2755 | u8 dtim_period; |
| 2756 | size_t ie_len; |
| 2757 | u8 *ie; |
| 2758 | s32 err = 0; |
| 2759 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 2760 | brcmf_dbg(TRACE, "Enter\n"); |
Arend van Spriel | 128ce3b | 2012-11-28 21:44:12 +0100 | [diff] [blame] | 2761 | if (brcmf_is_ibssmode(ifp->vif)) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2762 | return err; |
| 2763 | |
Arend van Spriel | 06bb123 | 2012-09-27 14:17:56 +0200 | [diff] [blame] | 2764 | ssid = &profile->ssid; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2765 | |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 2766 | *(__le32 *)cfg->extra_buf = cpu_to_le32(WL_EXTRA_BUF_MAX); |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 2767 | err = brcmf_fil_cmd_data_get(ifp, BRCMF_C_GET_BSS_INFO, |
Hante Meuleman | 81f5dcb | 2012-10-22 10:36:14 -0700 | [diff] [blame] | 2768 | cfg->extra_buf, WL_EXTRA_BUF_MAX); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2769 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 2770 | brcmf_err("Could not get bss info %d\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2771 | goto update_bss_info_out; |
| 2772 | } |
| 2773 | |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 2774 | bi = (struct brcmf_bss_info_le *)(cfg->extra_buf + 4); |
| 2775 | err = brcmf_inform_single_bss(cfg, bi); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2776 | if (err) |
| 2777 | goto update_bss_info_out; |
| 2778 | |
| 2779 | ie = ((u8 *)bi) + le16_to_cpu(bi->ie_offset); |
| 2780 | ie_len = le32_to_cpu(bi->ie_length); |
| 2781 | beacon_interval = le16_to_cpu(bi->beacon_period); |
| 2782 | |
Alwin Beukers | f8e4b41 | 2011-10-12 20:51:28 +0200 | [diff] [blame] | 2783 | tim = brcmf_parse_tlvs(ie, ie_len, WLAN_EID_TIM); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2784 | if (tim) |
| 2785 | dtim_period = tim->data[1]; |
| 2786 | else { |
| 2787 | /* |
| 2788 | * active scan was done so we could not get dtim |
| 2789 | * information out of probe response. |
| 2790 | * so we speficially query dtim information to dongle. |
| 2791 | */ |
| 2792 | u32 var; |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 2793 | err = brcmf_fil_iovar_int_get(ifp, "dtim_assoc", &var); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2794 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 2795 | brcmf_err("wl dtim_assoc failed (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2796 | goto update_bss_info_out; |
| 2797 | } |
| 2798 | dtim_period = (u8)var; |
| 2799 | } |
| 2800 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2801 | update_bss_info_out: |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 2802 | brcmf_dbg(TRACE, "Exit"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2803 | return err; |
| 2804 | } |
| 2805 | |
Hante Meuleman | 18e2f61 | 2013-02-08 15:53:49 +0100 | [diff] [blame] | 2806 | void brcmf_abort_scanning(struct brcmf_cfg80211_info *cfg) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2807 | { |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 2808 | struct escan_info *escan = &cfg->escan_info; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2809 | |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 2810 | set_bit(BRCMF_SCAN_STATUS_ABORT, &cfg->scan_status); |
Hante Meuleman | f0799895 | 2012-11-05 16:22:13 -0800 | [diff] [blame] | 2811 | if (cfg->scan_request) { |
Arend van Spriel | 108a4be | 2012-09-19 22:21:07 +0200 | [diff] [blame] | 2812 | escan->escan_state = WL_ESCAN_STATE_IDLE; |
Arend van Spriel | a0f472a | 2013-04-05 10:57:49 +0200 | [diff] [blame] | 2813 | brcmf_notify_escan_complete(cfg, escan->ifp, true, true); |
Arend van Spriel | 108a4be | 2012-09-19 22:21:07 +0200 | [diff] [blame] | 2814 | } |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 2815 | clear_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status); |
| 2816 | clear_bit(BRCMF_SCAN_STATUS_ABORT, &cfg->scan_status); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2817 | } |
| 2818 | |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 2819 | static void brcmf_cfg80211_escan_timeout_worker(struct work_struct *work) |
| 2820 | { |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 2821 | struct brcmf_cfg80211_info *cfg = |
| 2822 | container_of(work, struct brcmf_cfg80211_info, |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 2823 | escan_timeout_work); |
| 2824 | |
Hante Meuleman | ef8596e | 2014-09-30 10:23:13 +0200 | [diff] [blame] | 2825 | brcmf_inform_bss(cfg); |
Arend van Spriel | a0f472a | 2013-04-05 10:57:49 +0200 | [diff] [blame] | 2826 | brcmf_notify_escan_complete(cfg, cfg->escan_info.ifp, true, true); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 2827 | } |
| 2828 | |
| 2829 | static void brcmf_escan_timeout(unsigned long data) |
| 2830 | { |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 2831 | struct brcmf_cfg80211_info *cfg = |
| 2832 | (struct brcmf_cfg80211_info *)data; |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 2833 | |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 2834 | if (cfg->scan_request) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 2835 | brcmf_err("timer expired\n"); |
Hante Meuleman | f0799895 | 2012-11-05 16:22:13 -0800 | [diff] [blame] | 2836 | schedule_work(&cfg->escan_timeout_work); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 2837 | } |
| 2838 | } |
| 2839 | |
| 2840 | static s32 |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 2841 | brcmf_compare_update_same_bss(struct brcmf_cfg80211_info *cfg, |
| 2842 | struct brcmf_bss_info_le *bss, |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 2843 | struct brcmf_bss_info_le *bss_info_le) |
| 2844 | { |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 2845 | struct brcmu_chan ch_bss, ch_bss_info_le; |
| 2846 | |
| 2847 | ch_bss.chspec = le16_to_cpu(bss->chanspec); |
| 2848 | cfg->d11inf.decchspec(&ch_bss); |
| 2849 | ch_bss_info_le.chspec = le16_to_cpu(bss_info_le->chanspec); |
| 2850 | cfg->d11inf.decchspec(&ch_bss_info_le); |
| 2851 | |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 2852 | if (!memcmp(&bss_info_le->BSSID, &bss->BSSID, ETH_ALEN) && |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 2853 | ch_bss.band == ch_bss_info_le.band && |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 2854 | bss_info_le->SSID_len == bss->SSID_len && |
| 2855 | !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] | 2856 | if ((bss->flags & BRCMF_BSS_RSSI_ON_CHANNEL) == |
| 2857 | (bss_info_le->flags & BRCMF_BSS_RSSI_ON_CHANNEL)) { |
Arend van Spriel | 029591f | 2012-09-19 22:21:06 +0200 | [diff] [blame] | 2858 | s16 bss_rssi = le16_to_cpu(bss->RSSI); |
| 2859 | s16 bss_info_rssi = le16_to_cpu(bss_info_le->RSSI); |
| 2860 | |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 2861 | /* preserve max RSSI if the measurements are |
| 2862 | * both on-channel or both off-channel |
| 2863 | */ |
Arend van Spriel | 029591f | 2012-09-19 22:21:06 +0200 | [diff] [blame] | 2864 | if (bss_info_rssi > bss_rssi) |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 2865 | bss->RSSI = bss_info_le->RSSI; |
Arend van Spriel | 6f5838a | 2013-11-29 12:25:19 +0100 | [diff] [blame] | 2866 | } else if ((bss->flags & BRCMF_BSS_RSSI_ON_CHANNEL) && |
| 2867 | (bss_info_le->flags & BRCMF_BSS_RSSI_ON_CHANNEL) == 0) { |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 2868 | /* preserve the on-channel rssi measurement |
| 2869 | * if the new measurement is off channel |
| 2870 | */ |
| 2871 | bss->RSSI = bss_info_le->RSSI; |
Arend van Spriel | 6f5838a | 2013-11-29 12:25:19 +0100 | [diff] [blame] | 2872 | bss->flags |= BRCMF_BSS_RSSI_ON_CHANNEL; |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 2873 | } |
| 2874 | return 1; |
| 2875 | } |
| 2876 | return 0; |
| 2877 | } |
| 2878 | |
| 2879 | static s32 |
Arend van Spriel | 1993732 | 2012-11-05 16:22:32 -0800 | [diff] [blame] | 2880 | brcmf_cfg80211_escan_handler(struct brcmf_if *ifp, |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 2881 | const struct brcmf_event_msg *e, void *data) |
| 2882 | { |
Arend van Spriel | 1993732 | 2012-11-05 16:22:32 -0800 | [diff] [blame] | 2883 | struct brcmf_cfg80211_info *cfg = ifp->drvr->config; |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 2884 | s32 status; |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 2885 | struct brcmf_escan_result_le *escan_result_le; |
| 2886 | struct brcmf_bss_info_le *bss_info_le; |
| 2887 | struct brcmf_bss_info_le *bss = NULL; |
| 2888 | u32 bi_length; |
| 2889 | struct brcmf_scan_results *list; |
| 2890 | u32 i; |
Arend van Spriel | 97ed15c | 2012-09-13 21:12:06 +0200 | [diff] [blame] | 2891 | bool aborted; |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 2892 | |
Arend van Spriel | 5c36b99 | 2012-11-14 18:46:05 -0800 | [diff] [blame] | 2893 | status = e->status; |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 2894 | |
Arend van Spriel | a0f472a | 2013-04-05 10:57:49 +0200 | [diff] [blame] | 2895 | if (!test_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status)) { |
| 2896 | brcmf_err("scan not ready, bssidx=%d\n", ifp->bssidx); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 2897 | return -EPERM; |
| 2898 | } |
| 2899 | |
| 2900 | if (status == BRCMF_E_STATUS_PARTIAL) { |
Arend van Spriel | 4e8a008 | 2012-12-05 15:26:03 +0100 | [diff] [blame] | 2901 | brcmf_dbg(SCAN, "ESCAN Partial result\n"); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 2902 | escan_result_le = (struct brcmf_escan_result_le *) data; |
| 2903 | if (!escan_result_le) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 2904 | brcmf_err("Invalid escan result (NULL pointer)\n"); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 2905 | goto exit; |
| 2906 | } |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 2907 | if (le16_to_cpu(escan_result_le->bss_count) != 1) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 2908 | brcmf_err("Invalid bss_count %d: ignoring\n", |
| 2909 | escan_result_le->bss_count); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 2910 | goto exit; |
| 2911 | } |
| 2912 | bss_info_le = &escan_result_le->bss_info_le; |
| 2913 | |
Hante Meuleman | 6eda4e2 | 2013-02-08 15:54:02 +0100 | [diff] [blame] | 2914 | if (brcmf_p2p_scan_finding_common_channel(cfg, bss_info_le)) |
| 2915 | goto exit; |
| 2916 | |
| 2917 | if (!cfg->scan_request) { |
| 2918 | brcmf_dbg(SCAN, "result without cfg80211 request\n"); |
| 2919 | goto exit; |
| 2920 | } |
| 2921 | |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 2922 | bi_length = le32_to_cpu(bss_info_le->length); |
| 2923 | if (bi_length != (le32_to_cpu(escan_result_le->buflen) - |
| 2924 | WL_ESCAN_RESULTS_FIXED_SIZE)) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 2925 | brcmf_err("Invalid bss_info length %d: ignoring\n", |
| 2926 | bi_length); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 2927 | goto exit; |
| 2928 | } |
| 2929 | |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 2930 | if (!(cfg_to_wiphy(cfg)->interface_modes & |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 2931 | BIT(NL80211_IFTYPE_ADHOC))) { |
| 2932 | if (le16_to_cpu(bss_info_le->capability) & |
| 2933 | WLAN_CAPABILITY_IBSS) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 2934 | brcmf_err("Ignoring IBSS result\n"); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 2935 | goto exit; |
| 2936 | } |
| 2937 | } |
| 2938 | |
| 2939 | list = (struct brcmf_scan_results *) |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 2940 | cfg->escan_info.escan_buf; |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 2941 | if (bi_length > WL_ESCAN_BUF_SIZE - list->buflen) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 2942 | brcmf_err("Buffer is too small: ignoring\n"); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 2943 | goto exit; |
| 2944 | } |
| 2945 | |
| 2946 | for (i = 0; i < list->count; i++) { |
| 2947 | bss = bss ? (struct brcmf_bss_info_le *) |
| 2948 | ((unsigned char *)bss + |
| 2949 | le32_to_cpu(bss->length)) : list->bss_info_le; |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 2950 | if (brcmf_compare_update_same_bss(cfg, bss, |
| 2951 | bss_info_le)) |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 2952 | goto exit; |
| 2953 | } |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 2954 | memcpy(&(cfg->escan_info.escan_buf[list->buflen]), |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 2955 | bss_info_le, bi_length); |
| 2956 | list->version = le32_to_cpu(bss_info_le->version); |
| 2957 | list->buflen += bi_length; |
| 2958 | list->count++; |
| 2959 | } else { |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 2960 | cfg->escan_info.escan_state = WL_ESCAN_STATE_IDLE; |
Hante Meuleman | 6eda4e2 | 2013-02-08 15:54:02 +0100 | [diff] [blame] | 2961 | if (brcmf_p2p_scan_finding_common_channel(cfg, NULL)) |
| 2962 | goto exit; |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 2963 | if (cfg->scan_request) { |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 2964 | brcmf_inform_bss(cfg); |
Arend van Spriel | 97ed15c | 2012-09-13 21:12:06 +0200 | [diff] [blame] | 2965 | aborted = status != BRCMF_E_STATUS_SUCCESS; |
Hante Meuleman | ef8596e | 2014-09-30 10:23:13 +0200 | [diff] [blame] | 2966 | brcmf_notify_escan_complete(cfg, ifp, aborted, false); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 2967 | } else |
Hante Meuleman | 6eda4e2 | 2013-02-08 15:54:02 +0100 | [diff] [blame] | 2968 | brcmf_dbg(SCAN, "Ignored scan complete result 0x%x\n", |
| 2969 | status); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 2970 | } |
| 2971 | exit: |
Peter Senna Tschudin | 12f3237 | 2014-05-31 10:14:06 -0300 | [diff] [blame] | 2972 | return 0; |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 2973 | } |
| 2974 | |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 2975 | static void brcmf_init_escan(struct brcmf_cfg80211_info *cfg) |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 2976 | { |
Arend van Spriel | 5c36b99 | 2012-11-14 18:46:05 -0800 | [diff] [blame] | 2977 | brcmf_fweh_register(cfg->pub, BRCMF_E_ESCAN_RESULT, |
| 2978 | brcmf_cfg80211_escan_handler); |
Hante Meuleman | f0799895 | 2012-11-05 16:22:13 -0800 | [diff] [blame] | 2979 | cfg->escan_info.escan_state = WL_ESCAN_STATE_IDLE; |
| 2980 | /* Init scan_timeout timer */ |
| 2981 | init_timer(&cfg->escan_timeout); |
| 2982 | cfg->escan_timeout.data = (unsigned long) cfg; |
| 2983 | cfg->escan_timeout.function = brcmf_escan_timeout; |
| 2984 | INIT_WORK(&cfg->escan_timeout_work, |
| 2985 | brcmf_cfg80211_escan_timeout_worker); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 2986 | } |
| 2987 | |
Alexandre Oliva | 5addc0d | 2012-01-16 14:00:12 -0500 | [diff] [blame] | 2988 | static __always_inline void brcmf_delay(u32 ms) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2989 | { |
| 2990 | if (ms < 1000 / HZ) { |
| 2991 | cond_resched(); |
| 2992 | mdelay(ms); |
| 2993 | } else { |
| 2994 | msleep(ms); |
| 2995 | } |
| 2996 | } |
| 2997 | |
Hante Meuleman | b9a82f8 | 2014-10-28 14:56:06 +0100 | [diff] [blame] | 2998 | static s32 brcmf_config_wowl_pattern(struct brcmf_if *ifp, u8 cmd[4], |
| 2999 | u8 *pattern, u32 patternsize, u8 *mask, |
| 3000 | u32 packet_offset) |
| 3001 | { |
| 3002 | struct brcmf_fil_wowl_pattern_le *filter; |
| 3003 | u32 masksize; |
| 3004 | u32 patternoffset; |
| 3005 | u8 *buf; |
| 3006 | u32 bufsize; |
| 3007 | s32 ret; |
| 3008 | |
| 3009 | masksize = (patternsize + 7) / 8; |
| 3010 | patternoffset = sizeof(*filter) - sizeof(filter->cmd) + masksize; |
| 3011 | |
| 3012 | bufsize = sizeof(*filter) + patternsize + masksize; |
| 3013 | buf = kzalloc(bufsize, GFP_KERNEL); |
| 3014 | if (!buf) |
| 3015 | return -ENOMEM; |
| 3016 | filter = (struct brcmf_fil_wowl_pattern_le *)buf; |
| 3017 | |
| 3018 | memcpy(filter->cmd, cmd, 4); |
| 3019 | filter->masksize = cpu_to_le32(masksize); |
| 3020 | filter->offset = cpu_to_le32(packet_offset); |
| 3021 | filter->patternoffset = cpu_to_le32(patternoffset); |
| 3022 | filter->patternsize = cpu_to_le32(patternsize); |
| 3023 | filter->type = cpu_to_le32(BRCMF_WOWL_PATTERN_TYPE_BITMAP); |
| 3024 | |
| 3025 | if ((mask) && (masksize)) |
| 3026 | memcpy(buf + sizeof(*filter), mask, masksize); |
| 3027 | if ((pattern) && (patternsize)) |
| 3028 | memcpy(buf + sizeof(*filter) + masksize, pattern, patternsize); |
| 3029 | |
| 3030 | ret = brcmf_fil_iovar_data_set(ifp, "wowl_pattern", buf, bufsize); |
| 3031 | |
| 3032 | kfree(buf); |
| 3033 | return ret; |
| 3034 | } |
| 3035 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3036 | static s32 brcmf_cfg80211_resume(struct wiphy *wiphy) |
| 3037 | { |
Hante Meuleman | 4eb3af7 | 2014-09-30 10:23:18 +0200 | [diff] [blame] | 3038 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); |
| 3039 | struct net_device *ndev = cfg_to_ndev(cfg); |
| 3040 | struct brcmf_if *ifp = netdev_priv(ndev); |
| 3041 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 3042 | brcmf_dbg(TRACE, "Enter\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3043 | |
Hante Meuleman | 4eb3af7 | 2014-09-30 10:23:18 +0200 | [diff] [blame] | 3044 | if (cfg->wowl_enabled) { |
Hante Meuleman | b9a82f8 | 2014-10-28 14:56:06 +0100 | [diff] [blame] | 3045 | brcmf_configure_arp_offload(ifp, true); |
Hante Meuleman | 4eb3af7 | 2014-09-30 10:23:18 +0200 | [diff] [blame] | 3046 | brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_PM, |
| 3047 | cfg->pre_wowl_pmmode); |
Hante Meuleman | 4eb3af7 | 2014-09-30 10:23:18 +0200 | [diff] [blame] | 3048 | brcmf_fil_iovar_int_set(ifp, "wowl_clear", 0); |
Hante Meuleman | b9a82f8 | 2014-10-28 14:56:06 +0100 | [diff] [blame] | 3049 | brcmf_config_wowl_pattern(ifp, "clr", NULL, 0, NULL, 0); |
Hante Meuleman | 4eb3af7 | 2014-09-30 10:23:18 +0200 | [diff] [blame] | 3050 | cfg->wowl_enabled = false; |
| 3051 | } |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3052 | return 0; |
| 3053 | } |
| 3054 | |
Hante Meuleman | 4eb3af7 | 2014-09-30 10:23:18 +0200 | [diff] [blame] | 3055 | static void brcmf_configure_wowl(struct brcmf_cfg80211_info *cfg, |
| 3056 | struct brcmf_if *ifp, |
| 3057 | struct cfg80211_wowlan *wowl) |
| 3058 | { |
| 3059 | u32 wowl_config; |
Hante Meuleman | b9a82f8 | 2014-10-28 14:56:06 +0100 | [diff] [blame] | 3060 | u32 i; |
Hante Meuleman | 4eb3af7 | 2014-09-30 10:23:18 +0200 | [diff] [blame] | 3061 | |
| 3062 | brcmf_dbg(TRACE, "Suspend, wowl config.\n"); |
| 3063 | |
Hante Meuleman | b9a82f8 | 2014-10-28 14:56:06 +0100 | [diff] [blame] | 3064 | brcmf_configure_arp_offload(ifp, false); |
Hante Meuleman | 4eb3af7 | 2014-09-30 10:23:18 +0200 | [diff] [blame] | 3065 | brcmf_fil_cmd_int_get(ifp, BRCMF_C_GET_PM, &cfg->pre_wowl_pmmode); |
| 3066 | brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_PM, PM_MAX); |
| 3067 | |
| 3068 | wowl_config = 0; |
| 3069 | if (wowl->disconnect) |
Hante Meuleman | b9a82f8 | 2014-10-28 14:56:06 +0100 | [diff] [blame] | 3070 | wowl_config = BRCMF_WOWL_DIS | BRCMF_WOWL_BCN | BRCMF_WOWL_RETR; |
Hante Meuleman | 4eb3af7 | 2014-09-30 10:23:18 +0200 | [diff] [blame] | 3071 | if (wowl->magic_pkt) |
Hante Meuleman | b9a82f8 | 2014-10-28 14:56:06 +0100 | [diff] [blame] | 3072 | wowl_config |= BRCMF_WOWL_MAGIC; |
| 3073 | if ((wowl->patterns) && (wowl->n_patterns)) { |
| 3074 | wowl_config |= BRCMF_WOWL_NET; |
| 3075 | for (i = 0; i < wowl->n_patterns; i++) { |
| 3076 | brcmf_config_wowl_pattern(ifp, "add", |
| 3077 | (u8 *)wowl->patterns[i].pattern, |
| 3078 | wowl->patterns[i].pattern_len, |
| 3079 | (u8 *)wowl->patterns[i].mask, |
| 3080 | wowl->patterns[i].pkt_offset); |
| 3081 | } |
| 3082 | } |
Hante Meuleman | 4eb3af7 | 2014-09-30 10:23:18 +0200 | [diff] [blame] | 3083 | brcmf_fil_iovar_int_set(ifp, "wowl", wowl_config); |
| 3084 | brcmf_fil_iovar_int_set(ifp, "wowl_activate", 1); |
| 3085 | brcmf_bus_wowl_config(cfg->pub->bus_if, true); |
| 3086 | cfg->wowl_enabled = true; |
| 3087 | } |
| 3088 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3089 | static s32 brcmf_cfg80211_suspend(struct wiphy *wiphy, |
Hante Meuleman | 4eb3af7 | 2014-09-30 10:23:18 +0200 | [diff] [blame] | 3090 | struct cfg80211_wowlan *wowl) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3091 | { |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 3092 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); |
| 3093 | struct net_device *ndev = cfg_to_ndev(cfg); |
Hante Meuleman | 4eb3af7 | 2014-09-30 10:23:18 +0200 | [diff] [blame] | 3094 | struct brcmf_if *ifp = netdev_priv(ndev); |
Arend van Spriel | 7d64107 | 2012-10-22 13:55:39 -0700 | [diff] [blame] | 3095 | struct brcmf_cfg80211_vif *vif; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3096 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 3097 | brcmf_dbg(TRACE, "Enter\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3098 | |
Hante Meuleman | 4eb3af7 | 2014-09-30 10:23:18 +0200 | [diff] [blame] | 3099 | /* if the primary net_device is not READY there is nothing |
Arend van Spriel | 7d64107 | 2012-10-22 13:55:39 -0700 | [diff] [blame] | 3100 | * we can do but pray resume goes smoothly. |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3101 | */ |
Hante Meuleman | 4eb3af7 | 2014-09-30 10:23:18 +0200 | [diff] [blame] | 3102 | if (!check_vif_up(ifp->vif)) |
Arend van Spriel | 7d64107 | 2012-10-22 13:55:39 -0700 | [diff] [blame] | 3103 | goto exit; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3104 | |
Arend van Spriel | 7d64107 | 2012-10-22 13:55:39 -0700 | [diff] [blame] | 3105 | /* end any scanning */ |
| 3106 | if (test_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status)) |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 3107 | brcmf_abort_scanning(cfg); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3108 | |
Hante Meuleman | 4eb3af7 | 2014-09-30 10:23:18 +0200 | [diff] [blame] | 3109 | if (wowl == NULL) { |
| 3110 | brcmf_bus_wowl_config(cfg->pub->bus_if, false); |
| 3111 | list_for_each_entry(vif, &cfg->vif_list, list) { |
| 3112 | if (!test_bit(BRCMF_VIF_STATUS_READY, &vif->sme_state)) |
| 3113 | continue; |
| 3114 | /* While going to suspend if associated with AP |
| 3115 | * disassociate from AP to save power while system is |
| 3116 | * in suspended state |
| 3117 | */ |
Arend van Spriel | 9b7a0dd | 2015-01-25 20:31:33 +0100 | [diff] [blame] | 3118 | brcmf_link_down(vif, WLAN_REASON_UNSPECIFIED); |
Hante Meuleman | 4eb3af7 | 2014-09-30 10:23:18 +0200 | [diff] [blame] | 3119 | /* Make sure WPA_Supplicant receives all the event |
| 3120 | * generated due to DISASSOC call to the fw to keep |
| 3121 | * the state fw and WPA_Supplicant state consistent |
| 3122 | */ |
| 3123 | brcmf_delay(500); |
| 3124 | } |
| 3125 | /* Configure MPC */ |
| 3126 | brcmf_set_mpc(ifp, 1); |
| 3127 | |
| 3128 | } else { |
| 3129 | /* Configure WOWL paramaters */ |
| 3130 | brcmf_configure_wowl(cfg, ifp, wowl); |
| 3131 | } |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3132 | |
Arend van Spriel | 7d64107 | 2012-10-22 13:55:39 -0700 | [diff] [blame] | 3133 | exit: |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 3134 | brcmf_dbg(TRACE, "Exit\n"); |
Arend van Spriel | 7d64107 | 2012-10-22 13:55:39 -0700 | [diff] [blame] | 3135 | /* clear any scanning activity */ |
| 3136 | cfg->scan_status = 0; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3137 | return 0; |
| 3138 | } |
| 3139 | |
| 3140 | static __used s32 |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3141 | brcmf_update_pmklist(struct net_device *ndev, |
| 3142 | struct brcmf_cfg80211_pmk_list *pmk_list, s32 err) |
| 3143 | { |
| 3144 | int i, j; |
Arend van Spriel | c15d789 | 2014-11-20 22:26:59 +0100 | [diff] [blame] | 3145 | u32 pmkid_len; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3146 | |
Arend van Spriel | 40c8e95 | 2011-10-12 20:51:20 +0200 | [diff] [blame] | 3147 | pmkid_len = le32_to_cpu(pmk_list->pmkids.npmkid); |
| 3148 | |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 3149 | brcmf_dbg(CONN, "No of elements %d\n", pmkid_len); |
Arend van Spriel | 40c8e95 | 2011-10-12 20:51:20 +0200 | [diff] [blame] | 3150 | for (i = 0; i < pmkid_len; i++) { |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 3151 | brcmf_dbg(CONN, "PMKID[%d]: %pM =\n", i, |
| 3152 | &pmk_list->pmkids.pmkid[i].BSSID); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3153 | for (j = 0; j < WLAN_PMKID_LEN; j++) |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 3154 | brcmf_dbg(CONN, "%02x\n", |
| 3155 | pmk_list->pmkids.pmkid[i].PMKID[j]); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3156 | } |
| 3157 | |
| 3158 | if (!err) |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 3159 | brcmf_fil_iovar_data_set(netdev_priv(ndev), "pmkid_info", |
| 3160 | (char *)pmk_list, sizeof(*pmk_list)); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3161 | |
| 3162 | return err; |
| 3163 | } |
| 3164 | |
| 3165 | static s32 |
| 3166 | brcmf_cfg80211_set_pmksa(struct wiphy *wiphy, struct net_device *ndev, |
| 3167 | struct cfg80211_pmksa *pmksa) |
| 3168 | { |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 3169 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); |
Arend van Spriel | 0abb5f21 | 2012-10-22 13:55:32 -0700 | [diff] [blame] | 3170 | struct brcmf_if *ifp = netdev_priv(ndev); |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 3171 | struct pmkid_list *pmkids = &cfg->pmk_list->pmkids; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3172 | s32 err = 0; |
Arend van Spriel | c15d789 | 2014-11-20 22:26:59 +0100 | [diff] [blame] | 3173 | u32 pmkid_len, i; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3174 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 3175 | brcmf_dbg(TRACE, "Enter\n"); |
Arend van Spriel | ce81e31 | 2012-10-22 13:55:37 -0700 | [diff] [blame] | 3176 | if (!check_vif_up(ifp->vif)) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3177 | return -EIO; |
| 3178 | |
Arend van Spriel | 40c8e95 | 2011-10-12 20:51:20 +0200 | [diff] [blame] | 3179 | pmkid_len = le32_to_cpu(pmkids->npmkid); |
| 3180 | for (i = 0; i < pmkid_len; i++) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3181 | if (!memcmp(pmksa->bssid, pmkids->pmkid[i].BSSID, ETH_ALEN)) |
| 3182 | break; |
| 3183 | if (i < WL_NUM_PMKIDS_MAX) { |
| 3184 | memcpy(pmkids->pmkid[i].BSSID, pmksa->bssid, ETH_ALEN); |
| 3185 | memcpy(pmkids->pmkid[i].PMKID, pmksa->pmkid, WLAN_PMKID_LEN); |
Arend van Spriel | 40c8e95 | 2011-10-12 20:51:20 +0200 | [diff] [blame] | 3186 | if (i == pmkid_len) { |
| 3187 | pmkid_len++; |
| 3188 | pmkids->npmkid = cpu_to_le32(pmkid_len); |
| 3189 | } |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3190 | } else |
| 3191 | err = -EINVAL; |
| 3192 | |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 3193 | brcmf_dbg(CONN, "set_pmksa,IW_PMKSA_ADD - PMKID: %pM =\n", |
| 3194 | pmkids->pmkid[pmkid_len].BSSID); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3195 | for (i = 0; i < WLAN_PMKID_LEN; i++) |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 3196 | brcmf_dbg(CONN, "%02x\n", pmkids->pmkid[pmkid_len].PMKID[i]); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3197 | |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 3198 | err = brcmf_update_pmklist(ndev, cfg->pmk_list, err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3199 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 3200 | brcmf_dbg(TRACE, "Exit\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3201 | return err; |
| 3202 | } |
| 3203 | |
| 3204 | static s32 |
| 3205 | brcmf_cfg80211_del_pmksa(struct wiphy *wiphy, struct net_device *ndev, |
| 3206 | struct cfg80211_pmksa *pmksa) |
| 3207 | { |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 3208 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); |
Arend van Spriel | 0abb5f21 | 2012-10-22 13:55:32 -0700 | [diff] [blame] | 3209 | struct brcmf_if *ifp = netdev_priv(ndev); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3210 | struct pmkid_list pmkid; |
| 3211 | s32 err = 0; |
Arend van Spriel | c15d789 | 2014-11-20 22:26:59 +0100 | [diff] [blame] | 3212 | u32 pmkid_len, i; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3213 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 3214 | brcmf_dbg(TRACE, "Enter\n"); |
Arend van Spriel | ce81e31 | 2012-10-22 13:55:37 -0700 | [diff] [blame] | 3215 | if (!check_vif_up(ifp->vif)) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3216 | return -EIO; |
| 3217 | |
| 3218 | memcpy(&pmkid.pmkid[0].BSSID, pmksa->bssid, ETH_ALEN); |
| 3219 | memcpy(&pmkid.pmkid[0].PMKID, pmksa->pmkid, WLAN_PMKID_LEN); |
| 3220 | |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 3221 | brcmf_dbg(CONN, "del_pmksa,IW_PMKSA_REMOVE - PMKID: %pM =\n", |
| 3222 | &pmkid.pmkid[0].BSSID); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3223 | for (i = 0; i < WLAN_PMKID_LEN; i++) |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 3224 | brcmf_dbg(CONN, "%02x\n", pmkid.pmkid[0].PMKID[i]); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3225 | |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 3226 | pmkid_len = le32_to_cpu(cfg->pmk_list->pmkids.npmkid); |
Arend van Spriel | 40c8e95 | 2011-10-12 20:51:20 +0200 | [diff] [blame] | 3227 | for (i = 0; i < pmkid_len; i++) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3228 | if (!memcmp |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 3229 | (pmksa->bssid, &cfg->pmk_list->pmkids.pmkid[i].BSSID, |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3230 | ETH_ALEN)) |
| 3231 | break; |
| 3232 | |
Arend van Spriel | 40c8e95 | 2011-10-12 20:51:20 +0200 | [diff] [blame] | 3233 | if ((pmkid_len > 0) |
| 3234 | && (i < pmkid_len)) { |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 3235 | memset(&cfg->pmk_list->pmkids.pmkid[i], 0, |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3236 | sizeof(struct pmkid)); |
Arend van Spriel | 40c8e95 | 2011-10-12 20:51:20 +0200 | [diff] [blame] | 3237 | for (; i < (pmkid_len - 1); i++) { |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 3238 | memcpy(&cfg->pmk_list->pmkids.pmkid[i].BSSID, |
| 3239 | &cfg->pmk_list->pmkids.pmkid[i + 1].BSSID, |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3240 | ETH_ALEN); |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 3241 | memcpy(&cfg->pmk_list->pmkids.pmkid[i].PMKID, |
| 3242 | &cfg->pmk_list->pmkids.pmkid[i + 1].PMKID, |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3243 | WLAN_PMKID_LEN); |
| 3244 | } |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 3245 | cfg->pmk_list->pmkids.npmkid = cpu_to_le32(pmkid_len - 1); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3246 | } else |
| 3247 | err = -EINVAL; |
| 3248 | |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 3249 | err = brcmf_update_pmklist(ndev, cfg->pmk_list, err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3250 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 3251 | brcmf_dbg(TRACE, "Exit\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3252 | return err; |
| 3253 | |
| 3254 | } |
| 3255 | |
| 3256 | static s32 |
| 3257 | brcmf_cfg80211_flush_pmksa(struct wiphy *wiphy, struct net_device *ndev) |
| 3258 | { |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 3259 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); |
Arend van Spriel | 0abb5f21 | 2012-10-22 13:55:32 -0700 | [diff] [blame] | 3260 | struct brcmf_if *ifp = netdev_priv(ndev); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3261 | s32 err = 0; |
| 3262 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 3263 | brcmf_dbg(TRACE, "Enter\n"); |
Arend van Spriel | ce81e31 | 2012-10-22 13:55:37 -0700 | [diff] [blame] | 3264 | if (!check_vif_up(ifp->vif)) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3265 | return -EIO; |
| 3266 | |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 3267 | memset(cfg->pmk_list, 0, sizeof(*cfg->pmk_list)); |
| 3268 | err = brcmf_update_pmklist(ndev, cfg->pmk_list, err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3269 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 3270 | brcmf_dbg(TRACE, "Exit\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3271 | return err; |
| 3272 | |
| 3273 | } |
| 3274 | |
Arend van Spriel | e580607 | 2012-09-19 22:21:08 +0200 | [diff] [blame] | 3275 | /* |
| 3276 | * PFN result doesn't have all the info which are |
| 3277 | * required by the supplicant |
| 3278 | * (For e.g IEs) Do a target Escan so that sched scan results are reported |
| 3279 | * via wl_inform_single_bss in the required format. Escan does require the |
| 3280 | * scan request in the form of cfg80211_scan_request. For timebeing, create |
| 3281 | * cfg80211_scan_request one out of the received PNO event. |
| 3282 | */ |
| 3283 | static s32 |
Arend van Spriel | 1993732 | 2012-11-05 16:22:32 -0800 | [diff] [blame] | 3284 | brcmf_notify_sched_scan_results(struct brcmf_if *ifp, |
Arend van Spriel | e580607 | 2012-09-19 22:21:08 +0200 | [diff] [blame] | 3285 | const struct brcmf_event_msg *e, void *data) |
| 3286 | { |
Arend van Spriel | 1993732 | 2012-11-05 16:22:32 -0800 | [diff] [blame] | 3287 | struct brcmf_cfg80211_info *cfg = ifp->drvr->config; |
Arend van Spriel | e580607 | 2012-09-19 22:21:08 +0200 | [diff] [blame] | 3288 | struct brcmf_pno_net_info_le *netinfo, *netinfo_start; |
| 3289 | struct cfg80211_scan_request *request = NULL; |
| 3290 | struct cfg80211_ssid *ssid = NULL; |
| 3291 | struct ieee80211_channel *channel = NULL; |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 3292 | struct wiphy *wiphy = cfg_to_wiphy(cfg); |
Arend van Spriel | e580607 | 2012-09-19 22:21:08 +0200 | [diff] [blame] | 3293 | int err = 0; |
| 3294 | int channel_req = 0; |
| 3295 | int band = 0; |
| 3296 | struct brcmf_pno_scanresults_le *pfn_result; |
| 3297 | u32 result_count; |
| 3298 | u32 status; |
| 3299 | |
Arend van Spriel | 4e8a008 | 2012-12-05 15:26:03 +0100 | [diff] [blame] | 3300 | brcmf_dbg(SCAN, "Enter\n"); |
Arend van Spriel | e580607 | 2012-09-19 22:21:08 +0200 | [diff] [blame] | 3301 | |
Arend van Spriel | 5c36b99 | 2012-11-14 18:46:05 -0800 | [diff] [blame] | 3302 | if (e->event_code == BRCMF_E_PFN_NET_LOST) { |
Arend van Spriel | 4e8a008 | 2012-12-05 15:26:03 +0100 | [diff] [blame] | 3303 | brcmf_dbg(SCAN, "PFN NET LOST event. Do Nothing\n"); |
Arend van Spriel | e580607 | 2012-09-19 22:21:08 +0200 | [diff] [blame] | 3304 | return 0; |
| 3305 | } |
| 3306 | |
| 3307 | pfn_result = (struct brcmf_pno_scanresults_le *)data; |
| 3308 | result_count = le32_to_cpu(pfn_result->count); |
| 3309 | status = le32_to_cpu(pfn_result->status); |
| 3310 | |
| 3311 | /* |
| 3312 | * PFN event is limited to fit 512 bytes so we may get |
| 3313 | * multiple NET_FOUND events. For now place a warning here. |
| 3314 | */ |
| 3315 | WARN_ON(status != BRCMF_PNO_SCAN_COMPLETE); |
Arend van Spriel | 4e8a008 | 2012-12-05 15:26:03 +0100 | [diff] [blame] | 3316 | brcmf_dbg(SCAN, "PFN NET FOUND event. count: %d\n", result_count); |
Arend van Spriel | e580607 | 2012-09-19 22:21:08 +0200 | [diff] [blame] | 3317 | if (result_count > 0) { |
| 3318 | int i; |
| 3319 | |
| 3320 | request = kzalloc(sizeof(*request), GFP_KERNEL); |
Dan Carpenter | 58901d1 | 2012-09-26 10:21:48 +0300 | [diff] [blame] | 3321 | ssid = kcalloc(result_count, sizeof(*ssid), GFP_KERNEL); |
| 3322 | channel = kcalloc(result_count, sizeof(*channel), GFP_KERNEL); |
Arend van Spriel | e580607 | 2012-09-19 22:21:08 +0200 | [diff] [blame] | 3323 | if (!request || !ssid || !channel) { |
| 3324 | err = -ENOMEM; |
| 3325 | goto out_err; |
| 3326 | } |
| 3327 | |
| 3328 | request->wiphy = wiphy; |
| 3329 | data += sizeof(struct brcmf_pno_scanresults_le); |
| 3330 | netinfo_start = (struct brcmf_pno_net_info_le *)data; |
| 3331 | |
| 3332 | for (i = 0; i < result_count; i++) { |
| 3333 | netinfo = &netinfo_start[i]; |
| 3334 | if (!netinfo) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 3335 | brcmf_err("Invalid netinfo ptr. index: %d\n", |
| 3336 | i); |
Arend van Spriel | e580607 | 2012-09-19 22:21:08 +0200 | [diff] [blame] | 3337 | err = -EINVAL; |
| 3338 | goto out_err; |
| 3339 | } |
| 3340 | |
Arend van Spriel | 4e8a008 | 2012-12-05 15:26:03 +0100 | [diff] [blame] | 3341 | brcmf_dbg(SCAN, "SSID:%s Channel:%d\n", |
| 3342 | netinfo->SSID, netinfo->channel); |
Arend van Spriel | e580607 | 2012-09-19 22:21:08 +0200 | [diff] [blame] | 3343 | memcpy(ssid[i].ssid, netinfo->SSID, netinfo->SSID_len); |
| 3344 | ssid[i].ssid_len = netinfo->SSID_len; |
| 3345 | request->n_ssids++; |
| 3346 | |
| 3347 | channel_req = netinfo->channel; |
| 3348 | if (channel_req <= CH_MAX_2G_CHANNEL) |
| 3349 | band = NL80211_BAND_2GHZ; |
| 3350 | else |
| 3351 | band = NL80211_BAND_5GHZ; |
| 3352 | channel[i].center_freq = |
| 3353 | ieee80211_channel_to_frequency(channel_req, |
| 3354 | band); |
| 3355 | channel[i].band = band; |
| 3356 | channel[i].flags |= IEEE80211_CHAN_NO_HT40; |
| 3357 | request->channels[i] = &channel[i]; |
| 3358 | request->n_channels++; |
| 3359 | } |
| 3360 | |
| 3361 | /* assign parsed ssid array */ |
| 3362 | if (request->n_ssids) |
| 3363 | request->ssids = &ssid[0]; |
| 3364 | |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 3365 | if (test_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status)) { |
Arend van Spriel | e580607 | 2012-09-19 22:21:08 +0200 | [diff] [blame] | 3366 | /* Abort any on-going scan */ |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 3367 | brcmf_abort_scanning(cfg); |
Arend van Spriel | e580607 | 2012-09-19 22:21:08 +0200 | [diff] [blame] | 3368 | } |
| 3369 | |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 3370 | set_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status); |
Arend van Spriel | 2668b0b | 2014-01-13 22:20:28 +0100 | [diff] [blame] | 3371 | cfg->escan_info.run = brcmf_run_escan; |
Arend van Spriel | a0f472a | 2013-04-05 10:57:49 +0200 | [diff] [blame] | 3372 | err = brcmf_do_escan(cfg, wiphy, ifp, request); |
Arend van Spriel | e580607 | 2012-09-19 22:21:08 +0200 | [diff] [blame] | 3373 | if (err) { |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 3374 | clear_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status); |
Arend van Spriel | e580607 | 2012-09-19 22:21:08 +0200 | [diff] [blame] | 3375 | goto out_err; |
| 3376 | } |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 3377 | cfg->sched_escan = true; |
| 3378 | cfg->scan_request = request; |
Arend van Spriel | e580607 | 2012-09-19 22:21:08 +0200 | [diff] [blame] | 3379 | } else { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 3380 | brcmf_err("FALSE PNO Event. (pfn_count == 0)\n"); |
Arend van Spriel | e580607 | 2012-09-19 22:21:08 +0200 | [diff] [blame] | 3381 | goto out_err; |
| 3382 | } |
| 3383 | |
| 3384 | kfree(ssid); |
| 3385 | kfree(channel); |
| 3386 | kfree(request); |
| 3387 | return 0; |
| 3388 | |
| 3389 | out_err: |
| 3390 | kfree(ssid); |
| 3391 | kfree(channel); |
| 3392 | kfree(request); |
| 3393 | cfg80211_sched_scan_stopped(wiphy); |
| 3394 | return err; |
| 3395 | } |
| 3396 | |
Arend van Spriel | e580607 | 2012-09-19 22:21:08 +0200 | [diff] [blame] | 3397 | static int brcmf_dev_pno_clean(struct net_device *ndev) |
| 3398 | { |
Arend van Spriel | e580607 | 2012-09-19 22:21:08 +0200 | [diff] [blame] | 3399 | int ret; |
| 3400 | |
| 3401 | /* Disable pfn */ |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 3402 | ret = brcmf_fil_iovar_int_set(netdev_priv(ndev), "pfn", 0); |
Arend van Spriel | e580607 | 2012-09-19 22:21:08 +0200 | [diff] [blame] | 3403 | if (ret == 0) { |
| 3404 | /* clear pfn */ |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 3405 | ret = brcmf_fil_iovar_data_set(netdev_priv(ndev), "pfnclear", |
| 3406 | NULL, 0); |
Arend van Spriel | e580607 | 2012-09-19 22:21:08 +0200 | [diff] [blame] | 3407 | } |
| 3408 | if (ret < 0) |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 3409 | brcmf_err("failed code %d\n", ret); |
Arend van Spriel | e580607 | 2012-09-19 22:21:08 +0200 | [diff] [blame] | 3410 | |
| 3411 | return ret; |
| 3412 | } |
| 3413 | |
| 3414 | static int brcmf_dev_pno_config(struct net_device *ndev) |
| 3415 | { |
| 3416 | struct brcmf_pno_param_le pfn_param; |
Arend van Spriel | e580607 | 2012-09-19 22:21:08 +0200 | [diff] [blame] | 3417 | |
| 3418 | memset(&pfn_param, 0, sizeof(pfn_param)); |
| 3419 | pfn_param.version = cpu_to_le32(BRCMF_PNO_VERSION); |
| 3420 | |
| 3421 | /* set extra pno params */ |
| 3422 | pfn_param.flags = cpu_to_le16(1 << BRCMF_PNO_ENABLE_ADAPTSCAN_BIT); |
| 3423 | pfn_param.repeat = BRCMF_PNO_REPEAT; |
| 3424 | pfn_param.exp = BRCMF_PNO_FREQ_EXPO_MAX; |
| 3425 | |
| 3426 | /* set up pno scan fr */ |
| 3427 | pfn_param.scan_freq = cpu_to_le32(BRCMF_PNO_TIME); |
| 3428 | |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 3429 | return brcmf_fil_iovar_data_set(netdev_priv(ndev), "pfn_set", |
| 3430 | &pfn_param, sizeof(pfn_param)); |
Arend van Spriel | e580607 | 2012-09-19 22:21:08 +0200 | [diff] [blame] | 3431 | } |
| 3432 | |
| 3433 | static int |
| 3434 | brcmf_cfg80211_sched_scan_start(struct wiphy *wiphy, |
| 3435 | struct net_device *ndev, |
| 3436 | struct cfg80211_sched_scan_request *request) |
| 3437 | { |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 3438 | struct brcmf_if *ifp = netdev_priv(ndev); |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 3439 | struct brcmf_cfg80211_info *cfg = wiphy_priv(wiphy); |
Arend van Spriel | e580607 | 2012-09-19 22:21:08 +0200 | [diff] [blame] | 3440 | struct brcmf_pno_net_param_le pfn; |
| 3441 | int i; |
| 3442 | int ret = 0; |
| 3443 | |
Arend van Spriel | dc7bdbf | 2013-03-03 12:45:25 +0100 | [diff] [blame] | 3444 | brcmf_dbg(SCAN, "Enter n_match_sets:%d n_ssids:%d\n", |
Arend van Spriel | 4e8a008 | 2012-12-05 15:26:03 +0100 | [diff] [blame] | 3445 | request->n_match_sets, request->n_ssids); |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 3446 | if (test_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status)) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 3447 | brcmf_err("Scanning already: status (%lu)\n", cfg->scan_status); |
Arend van Spriel | e580607 | 2012-09-19 22:21:08 +0200 | [diff] [blame] | 3448 | return -EAGAIN; |
| 3449 | } |
Arend van Spriel | 1687eee | 2013-04-23 12:53:11 +0200 | [diff] [blame] | 3450 | if (test_bit(BRCMF_SCAN_STATUS_SUPPRESS, &cfg->scan_status)) { |
| 3451 | brcmf_err("Scanning suppressed: status (%lu)\n", |
| 3452 | cfg->scan_status); |
| 3453 | return -EAGAIN; |
| 3454 | } |
Arend van Spriel | e580607 | 2012-09-19 22:21:08 +0200 | [diff] [blame] | 3455 | |
Arend van Spriel | dc7bdbf | 2013-03-03 12:45:25 +0100 | [diff] [blame] | 3456 | if (!request->n_ssids || !request->n_match_sets) { |
Arend van Spriel | 181f2d1 | 2014-05-27 12:56:13 +0200 | [diff] [blame] | 3457 | brcmf_dbg(SCAN, "Invalid sched scan req!! n_ssids:%d\n", |
Arend van Spriel | dc7bdbf | 2013-03-03 12:45:25 +0100 | [diff] [blame] | 3458 | request->n_ssids); |
Arend van Spriel | e580607 | 2012-09-19 22:21:08 +0200 | [diff] [blame] | 3459 | return -EINVAL; |
| 3460 | } |
| 3461 | |
| 3462 | if (request->n_ssids > 0) { |
| 3463 | for (i = 0; i < request->n_ssids; i++) { |
| 3464 | /* Active scan req for ssids */ |
Arend van Spriel | 4e8a008 | 2012-12-05 15:26:03 +0100 | [diff] [blame] | 3465 | brcmf_dbg(SCAN, ">>> Active scan req for ssid (%s)\n", |
| 3466 | request->ssids[i].ssid); |
Arend van Spriel | e580607 | 2012-09-19 22:21:08 +0200 | [diff] [blame] | 3467 | |
| 3468 | /* |
| 3469 | * match_set ssids is a supert set of n_ssid list, |
| 3470 | * so we need not add these set seperately. |
| 3471 | */ |
| 3472 | } |
| 3473 | } |
| 3474 | |
| 3475 | if (request->n_match_sets > 0) { |
| 3476 | /* clean up everything */ |
| 3477 | ret = brcmf_dev_pno_clean(ndev); |
| 3478 | if (ret < 0) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 3479 | brcmf_err("failed error=%d\n", ret); |
Arend van Spriel | e580607 | 2012-09-19 22:21:08 +0200 | [diff] [blame] | 3480 | return ret; |
| 3481 | } |
| 3482 | |
| 3483 | /* configure pno */ |
| 3484 | ret = brcmf_dev_pno_config(ndev); |
| 3485 | if (ret < 0) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 3486 | brcmf_err("PNO setup failed!! ret=%d\n", ret); |
Arend van Spriel | e580607 | 2012-09-19 22:21:08 +0200 | [diff] [blame] | 3487 | return -EINVAL; |
| 3488 | } |
| 3489 | |
| 3490 | /* configure each match set */ |
| 3491 | for (i = 0; i < request->n_match_sets; i++) { |
| 3492 | struct cfg80211_ssid *ssid; |
| 3493 | u32 ssid_len; |
| 3494 | |
| 3495 | ssid = &request->match_sets[i].ssid; |
| 3496 | ssid_len = ssid->ssid_len; |
| 3497 | |
| 3498 | if (!ssid_len) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 3499 | brcmf_err("skip broadcast ssid\n"); |
Arend van Spriel | e580607 | 2012-09-19 22:21:08 +0200 | [diff] [blame] | 3500 | continue; |
| 3501 | } |
| 3502 | pfn.auth = cpu_to_le32(WLAN_AUTH_OPEN); |
| 3503 | pfn.wpa_auth = cpu_to_le32(BRCMF_PNO_WPA_AUTH_ANY); |
| 3504 | pfn.wsec = cpu_to_le32(0); |
| 3505 | pfn.infra = cpu_to_le32(1); |
| 3506 | pfn.flags = cpu_to_le32(1 << BRCMF_PNO_HIDDEN_BIT); |
| 3507 | pfn.ssid.SSID_len = cpu_to_le32(ssid_len); |
| 3508 | memcpy(pfn.ssid.SSID, ssid->ssid, ssid_len); |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 3509 | ret = brcmf_fil_iovar_data_set(ifp, "pfn_add", &pfn, |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 3510 | sizeof(pfn)); |
Arend van Spriel | 4e8a008 | 2012-12-05 15:26:03 +0100 | [diff] [blame] | 3511 | brcmf_dbg(SCAN, ">>> PNO filter %s for ssid (%s)\n", |
| 3512 | ret == 0 ? "set" : "failed", ssid->ssid); |
Arend van Spriel | e580607 | 2012-09-19 22:21:08 +0200 | [diff] [blame] | 3513 | } |
| 3514 | /* Enable the PNO */ |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 3515 | if (brcmf_fil_iovar_int_set(ifp, "pfn", 1) < 0) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 3516 | brcmf_err("PNO enable failed!! ret=%d\n", ret); |
Arend van Spriel | e580607 | 2012-09-19 22:21:08 +0200 | [diff] [blame] | 3517 | return -EINVAL; |
| 3518 | } |
| 3519 | } else { |
| 3520 | return -EINVAL; |
| 3521 | } |
| 3522 | |
| 3523 | return 0; |
| 3524 | } |
| 3525 | |
| 3526 | static int brcmf_cfg80211_sched_scan_stop(struct wiphy *wiphy, |
| 3527 | struct net_device *ndev) |
| 3528 | { |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 3529 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); |
Arend van Spriel | e580607 | 2012-09-19 22:21:08 +0200 | [diff] [blame] | 3530 | |
Arend van Spriel | 4e8a008 | 2012-12-05 15:26:03 +0100 | [diff] [blame] | 3531 | brcmf_dbg(SCAN, "enter\n"); |
Arend van Spriel | e580607 | 2012-09-19 22:21:08 +0200 | [diff] [blame] | 3532 | brcmf_dev_pno_clean(ndev); |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 3533 | if (cfg->sched_escan) |
Arend van Spriel | a0f472a | 2013-04-05 10:57:49 +0200 | [diff] [blame] | 3534 | brcmf_notify_escan_complete(cfg, netdev_priv(ndev), true, true); |
Arend van Spriel | e580607 | 2012-09-19 22:21:08 +0200 | [diff] [blame] | 3535 | return 0; |
| 3536 | } |
Arend van Spriel | e580607 | 2012-09-19 22:21:08 +0200 | [diff] [blame] | 3537 | |
Hante Meuleman | 1f17011 | 2013-02-06 18:40:38 +0100 | [diff] [blame] | 3538 | static s32 brcmf_configure_opensecurity(struct brcmf_if *ifp) |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3539 | { |
| 3540 | s32 err; |
| 3541 | |
| 3542 | /* set auth */ |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 3543 | err = brcmf_fil_bsscfg_int_set(ifp, "auth", 0); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3544 | if (err < 0) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 3545 | brcmf_err("auth error %d\n", err); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3546 | return err; |
| 3547 | } |
| 3548 | /* set wsec */ |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 3549 | err = brcmf_fil_bsscfg_int_set(ifp, "wsec", 0); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3550 | if (err < 0) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 3551 | brcmf_err("wsec error %d\n", err); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3552 | return err; |
| 3553 | } |
| 3554 | /* set upper-layer auth */ |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 3555 | err = brcmf_fil_bsscfg_int_set(ifp, "wpa_auth", WPA_AUTH_NONE); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3556 | if (err < 0) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 3557 | brcmf_err("wpa_auth error %d\n", err); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3558 | return err; |
| 3559 | } |
| 3560 | |
| 3561 | return 0; |
| 3562 | } |
| 3563 | |
| 3564 | static bool brcmf_valid_wpa_oui(u8 *oui, bool is_rsn_ie) |
| 3565 | { |
| 3566 | if (is_rsn_ie) |
| 3567 | return (memcmp(oui, RSN_OUI, TLV_OUI_LEN) == 0); |
| 3568 | |
| 3569 | return (memcmp(oui, WPA_OUI, TLV_OUI_LEN) == 0); |
| 3570 | } |
| 3571 | |
| 3572 | static s32 |
Hante Meuleman | a44aa40 | 2014-12-03 21:05:33 +0100 | [diff] [blame] | 3573 | brcmf_configure_wpaie(struct brcmf_if *ifp, |
Johannes Berg | 4b5800f | 2014-01-15 14:55:59 +0100 | [diff] [blame] | 3574 | const struct brcmf_vs_tlv *wpa_ie, |
| 3575 | bool is_rsn_ie) |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3576 | { |
| 3577 | u32 auth = 0; /* d11 open authentication */ |
| 3578 | u16 count; |
| 3579 | s32 err = 0; |
| 3580 | s32 len = 0; |
| 3581 | u32 i; |
| 3582 | u32 wsec; |
| 3583 | u32 pval = 0; |
| 3584 | u32 gval = 0; |
| 3585 | u32 wpa_auth = 0; |
| 3586 | u32 offset; |
| 3587 | u8 *data; |
| 3588 | u16 rsn_cap; |
| 3589 | u32 wme_bss_disable; |
| 3590 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 3591 | brcmf_dbg(TRACE, "Enter\n"); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3592 | if (wpa_ie == NULL) |
| 3593 | goto exit; |
| 3594 | |
| 3595 | len = wpa_ie->len + TLV_HDR_LEN; |
| 3596 | data = (u8 *)wpa_ie; |
Hante Meuleman | 619c5a9 | 2013-01-02 15:12:39 +0100 | [diff] [blame] | 3597 | offset = TLV_HDR_LEN; |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3598 | if (!is_rsn_ie) |
| 3599 | offset += VS_IE_FIXED_HDR_LEN; |
Hante Meuleman | 619c5a9 | 2013-01-02 15:12:39 +0100 | [diff] [blame] | 3600 | else |
| 3601 | offset += WPA_IE_VERSION_LEN; |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3602 | |
| 3603 | /* check for multicast cipher suite */ |
| 3604 | if (offset + WPA_IE_MIN_OUI_LEN > len) { |
| 3605 | err = -EINVAL; |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 3606 | brcmf_err("no multicast cipher suite\n"); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3607 | goto exit; |
| 3608 | } |
| 3609 | |
| 3610 | if (!brcmf_valid_wpa_oui(&data[offset], is_rsn_ie)) { |
| 3611 | err = -EINVAL; |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 3612 | brcmf_err("ivalid OUI\n"); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3613 | goto exit; |
| 3614 | } |
| 3615 | offset += TLV_OUI_LEN; |
| 3616 | |
| 3617 | /* pick up multicast cipher */ |
| 3618 | switch (data[offset]) { |
| 3619 | case WPA_CIPHER_NONE: |
| 3620 | gval = 0; |
| 3621 | break; |
| 3622 | case WPA_CIPHER_WEP_40: |
| 3623 | case WPA_CIPHER_WEP_104: |
| 3624 | gval = WEP_ENABLED; |
| 3625 | break; |
| 3626 | case WPA_CIPHER_TKIP: |
| 3627 | gval = TKIP_ENABLED; |
| 3628 | break; |
| 3629 | case WPA_CIPHER_AES_CCM: |
| 3630 | gval = AES_ENABLED; |
| 3631 | break; |
| 3632 | default: |
| 3633 | err = -EINVAL; |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 3634 | brcmf_err("Invalid multi cast cipher info\n"); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3635 | goto exit; |
| 3636 | } |
| 3637 | |
| 3638 | offset++; |
| 3639 | /* walk thru unicast cipher list and pick up what we recognize */ |
| 3640 | count = data[offset] + (data[offset + 1] << 8); |
| 3641 | offset += WPA_IE_SUITE_COUNT_LEN; |
| 3642 | /* Check for unicast suite(s) */ |
| 3643 | if (offset + (WPA_IE_MIN_OUI_LEN * count) > len) { |
| 3644 | err = -EINVAL; |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 3645 | brcmf_err("no unicast cipher suite\n"); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3646 | goto exit; |
| 3647 | } |
| 3648 | for (i = 0; i < count; i++) { |
| 3649 | if (!brcmf_valid_wpa_oui(&data[offset], is_rsn_ie)) { |
| 3650 | err = -EINVAL; |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 3651 | brcmf_err("ivalid OUI\n"); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3652 | goto exit; |
| 3653 | } |
| 3654 | offset += TLV_OUI_LEN; |
| 3655 | switch (data[offset]) { |
| 3656 | case WPA_CIPHER_NONE: |
| 3657 | break; |
| 3658 | case WPA_CIPHER_WEP_40: |
| 3659 | case WPA_CIPHER_WEP_104: |
| 3660 | pval |= WEP_ENABLED; |
| 3661 | break; |
| 3662 | case WPA_CIPHER_TKIP: |
| 3663 | pval |= TKIP_ENABLED; |
| 3664 | break; |
| 3665 | case WPA_CIPHER_AES_CCM: |
| 3666 | pval |= AES_ENABLED; |
| 3667 | break; |
| 3668 | default: |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 3669 | brcmf_err("Ivalid unicast security info\n"); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3670 | } |
| 3671 | offset++; |
| 3672 | } |
| 3673 | /* walk thru auth management suite list and pick up what we recognize */ |
| 3674 | count = data[offset] + (data[offset + 1] << 8); |
| 3675 | offset += WPA_IE_SUITE_COUNT_LEN; |
| 3676 | /* Check for auth key management suite(s) */ |
| 3677 | if (offset + (WPA_IE_MIN_OUI_LEN * count) > len) { |
| 3678 | err = -EINVAL; |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 3679 | brcmf_err("no auth key mgmt suite\n"); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3680 | goto exit; |
| 3681 | } |
| 3682 | for (i = 0; i < count; i++) { |
| 3683 | if (!brcmf_valid_wpa_oui(&data[offset], is_rsn_ie)) { |
| 3684 | err = -EINVAL; |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 3685 | brcmf_err("ivalid OUI\n"); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3686 | goto exit; |
| 3687 | } |
| 3688 | offset += TLV_OUI_LEN; |
| 3689 | switch (data[offset]) { |
| 3690 | case RSN_AKM_NONE: |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 3691 | brcmf_dbg(TRACE, "RSN_AKM_NONE\n"); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3692 | wpa_auth |= WPA_AUTH_NONE; |
| 3693 | break; |
| 3694 | case RSN_AKM_UNSPECIFIED: |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 3695 | brcmf_dbg(TRACE, "RSN_AKM_UNSPECIFIED\n"); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3696 | is_rsn_ie ? (wpa_auth |= WPA2_AUTH_UNSPECIFIED) : |
| 3697 | (wpa_auth |= WPA_AUTH_UNSPECIFIED); |
| 3698 | break; |
| 3699 | case RSN_AKM_PSK: |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 3700 | brcmf_dbg(TRACE, "RSN_AKM_PSK\n"); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3701 | is_rsn_ie ? (wpa_auth |= WPA2_AUTH_PSK) : |
| 3702 | (wpa_auth |= WPA_AUTH_PSK); |
| 3703 | break; |
| 3704 | default: |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 3705 | brcmf_err("Ivalid key mgmt info\n"); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3706 | } |
| 3707 | offset++; |
| 3708 | } |
| 3709 | |
| 3710 | if (is_rsn_ie) { |
| 3711 | wme_bss_disable = 1; |
| 3712 | if ((offset + RSN_CAP_LEN) <= len) { |
| 3713 | rsn_cap = data[offset] + (data[offset + 1] << 8); |
| 3714 | if (rsn_cap & RSN_CAP_PTK_REPLAY_CNTR_MASK) |
| 3715 | wme_bss_disable = 0; |
| 3716 | } |
| 3717 | /* set wme_bss_disable to sync RSN Capabilities */ |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 3718 | err = brcmf_fil_bsscfg_int_set(ifp, "wme_bss_disable", |
Hante Meuleman | 81f5dcb | 2012-10-22 10:36:14 -0700 | [diff] [blame] | 3719 | wme_bss_disable); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3720 | if (err < 0) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 3721 | brcmf_err("wme_bss_disable error %d\n", err); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3722 | goto exit; |
| 3723 | } |
| 3724 | } |
| 3725 | /* FOR WPS , set SES_OW_ENABLED */ |
| 3726 | wsec = (pval | gval | SES_OW_ENABLED); |
| 3727 | |
| 3728 | /* set auth */ |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 3729 | err = brcmf_fil_bsscfg_int_set(ifp, "auth", auth); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3730 | if (err < 0) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 3731 | brcmf_err("auth error %d\n", err); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3732 | goto exit; |
| 3733 | } |
| 3734 | /* set wsec */ |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 3735 | err = brcmf_fil_bsscfg_int_set(ifp, "wsec", wsec); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3736 | if (err < 0) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 3737 | brcmf_err("wsec error %d\n", err); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3738 | goto exit; |
| 3739 | } |
| 3740 | /* set upper-layer auth */ |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 3741 | err = brcmf_fil_bsscfg_int_set(ifp, "wpa_auth", wpa_auth); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3742 | if (err < 0) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 3743 | brcmf_err("wpa_auth error %d\n", err); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3744 | goto exit; |
| 3745 | } |
| 3746 | |
| 3747 | exit: |
| 3748 | return err; |
| 3749 | } |
| 3750 | |
| 3751 | static s32 |
Arend van Spriel | 3082b9b | 2012-11-05 16:22:12 -0800 | [diff] [blame] | 3752 | 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] | 3753 | struct parsed_vndr_ies *vndr_ies) |
| 3754 | { |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3755 | struct brcmf_vs_tlv *vndrie; |
| 3756 | struct brcmf_tlv *ie; |
| 3757 | struct parsed_vndr_ie_info *parsed_info; |
| 3758 | s32 remaining_len; |
| 3759 | |
| 3760 | remaining_len = (s32)vndr_ie_len; |
| 3761 | memset(vndr_ies, 0, sizeof(*vndr_ies)); |
| 3762 | |
| 3763 | ie = (struct brcmf_tlv *)vndr_ie_buf; |
| 3764 | while (ie) { |
| 3765 | if (ie->id != WLAN_EID_VENDOR_SPECIFIC) |
| 3766 | goto next; |
| 3767 | vndrie = (struct brcmf_vs_tlv *)ie; |
| 3768 | /* len should be bigger than OUI length + one */ |
| 3769 | 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] | 3770 | brcmf_err("invalid vndr ie. length is too small %d\n", |
| 3771 | vndrie->len); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3772 | goto next; |
| 3773 | } |
| 3774 | /* if wpa or wme ie, do not add ie */ |
| 3775 | if (!memcmp(vndrie->oui, (u8 *)WPA_OUI, TLV_OUI_LEN) && |
| 3776 | ((vndrie->oui_type == WPA_OUI_TYPE) || |
| 3777 | (vndrie->oui_type == WME_OUI_TYPE))) { |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 3778 | brcmf_dbg(TRACE, "Found WPA/WME oui. Do not add it\n"); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3779 | goto next; |
| 3780 | } |
| 3781 | |
| 3782 | parsed_info = &vndr_ies->ie_info[vndr_ies->count]; |
| 3783 | |
| 3784 | /* save vndr ie information */ |
| 3785 | parsed_info->ie_ptr = (char *)vndrie; |
| 3786 | parsed_info->ie_len = vndrie->len + TLV_HDR_LEN; |
| 3787 | memcpy(&parsed_info->vndrie, vndrie, sizeof(*vndrie)); |
| 3788 | |
| 3789 | vndr_ies->count++; |
| 3790 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 3791 | brcmf_dbg(TRACE, "** OUI %02x %02x %02x, type 0x%02x\n", |
| 3792 | parsed_info->vndrie.oui[0], |
| 3793 | parsed_info->vndrie.oui[1], |
| 3794 | parsed_info->vndrie.oui[2], |
| 3795 | parsed_info->vndrie.oui_type); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3796 | |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 3797 | if (vndr_ies->count >= VNDR_IE_PARSE_LIMIT) |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3798 | break; |
| 3799 | next: |
Hante Meuleman | b41fc3d | 2012-11-28 21:44:13 +0100 | [diff] [blame] | 3800 | remaining_len -= (ie->len + TLV_HDR_LEN); |
| 3801 | if (remaining_len <= TLV_HDR_LEN) |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3802 | ie = NULL; |
| 3803 | else |
Hante Meuleman | b41fc3d | 2012-11-28 21:44:13 +0100 | [diff] [blame] | 3804 | ie = (struct brcmf_tlv *)(((u8 *)ie) + ie->len + |
| 3805 | TLV_HDR_LEN); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3806 | } |
Peter Senna Tschudin | 12f3237 | 2014-05-31 10:14:06 -0300 | [diff] [blame] | 3807 | return 0; |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3808 | } |
| 3809 | |
| 3810 | static u32 |
| 3811 | brcmf_vndr_ie(u8 *iebuf, s32 pktflag, u8 *ie_ptr, u32 ie_len, s8 *add_del_cmd) |
| 3812 | { |
| 3813 | |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3814 | strncpy(iebuf, add_del_cmd, VNDR_IE_CMD_LEN - 1); |
| 3815 | iebuf[VNDR_IE_CMD_LEN - 1] = '\0'; |
| 3816 | |
Vaishali Thakkar | 362126c | 2015-01-16 21:36:14 +0530 | [diff] [blame] | 3817 | put_unaligned_le32(1, &iebuf[VNDR_IE_COUNT_OFFSET]); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3818 | |
Vaishali Thakkar | 362126c | 2015-01-16 21:36:14 +0530 | [diff] [blame] | 3819 | put_unaligned_le32(pktflag, &iebuf[VNDR_IE_PKTFLAG_OFFSET]); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3820 | |
| 3821 | memcpy(&iebuf[VNDR_IE_VSIE_OFFSET], ie_ptr, ie_len); |
| 3822 | |
| 3823 | return ie_len + VNDR_IE_HDR_SIZE; |
| 3824 | } |
| 3825 | |
Arend van Spriel | 1332e26 | 2012-11-05 16:22:18 -0800 | [diff] [blame] | 3826 | s32 brcmf_vif_set_mgmt_ie(struct brcmf_cfg80211_vif *vif, s32 pktflag, |
| 3827 | const u8 *vndr_ie_buf, u32 vndr_ie_len) |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3828 | { |
Arend van Spriel | 1332e26 | 2012-11-05 16:22:18 -0800 | [diff] [blame] | 3829 | struct brcmf_if *ifp; |
| 3830 | struct vif_saved_ie *saved_ie; |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3831 | s32 err = 0; |
| 3832 | u8 *iovar_ie_buf; |
| 3833 | u8 *curr_ie_buf; |
| 3834 | u8 *mgmt_ie_buf = NULL; |
Dan Carpenter | 3e4f319 | 2012-10-10 11:13:12 -0700 | [diff] [blame] | 3835 | int mgmt_ie_buf_len; |
Dan Carpenter | 81118d1 | 2012-10-10 11:13:07 -0700 | [diff] [blame] | 3836 | u32 *mgmt_ie_len; |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3837 | u32 del_add_ie_buf_len = 0; |
| 3838 | u32 total_ie_buf_len = 0; |
| 3839 | u32 parsed_ie_buf_len = 0; |
| 3840 | struct parsed_vndr_ies old_vndr_ies; |
| 3841 | struct parsed_vndr_ies new_vndr_ies; |
| 3842 | struct parsed_vndr_ie_info *vndrie_info; |
| 3843 | s32 i; |
| 3844 | u8 *ptr; |
Dan Carpenter | 3e4f319 | 2012-10-10 11:13:12 -0700 | [diff] [blame] | 3845 | int remained_buf_len; |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3846 | |
Arend van Spriel | 1332e26 | 2012-11-05 16:22:18 -0800 | [diff] [blame] | 3847 | if (!vif) |
| 3848 | return -ENODEV; |
| 3849 | ifp = vif->ifp; |
| 3850 | saved_ie = &vif->saved_ie; |
| 3851 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 3852 | brcmf_dbg(TRACE, "bssidx %d, pktflag : 0x%02X\n", ifp->bssidx, pktflag); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3853 | iovar_ie_buf = kzalloc(WL_EXTRA_BUF_MAX, GFP_KERNEL); |
| 3854 | if (!iovar_ie_buf) |
| 3855 | return -ENOMEM; |
| 3856 | curr_ie_buf = iovar_ie_buf; |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 3857 | switch (pktflag) { |
| 3858 | case BRCMF_VNDR_IE_PRBREQ_FLAG: |
| 3859 | mgmt_ie_buf = saved_ie->probe_req_ie; |
| 3860 | mgmt_ie_len = &saved_ie->probe_req_ie_len; |
| 3861 | mgmt_ie_buf_len = sizeof(saved_ie->probe_req_ie); |
| 3862 | break; |
| 3863 | case BRCMF_VNDR_IE_PRBRSP_FLAG: |
| 3864 | mgmt_ie_buf = saved_ie->probe_res_ie; |
| 3865 | mgmt_ie_len = &saved_ie->probe_res_ie_len; |
| 3866 | mgmt_ie_buf_len = sizeof(saved_ie->probe_res_ie); |
| 3867 | break; |
| 3868 | case BRCMF_VNDR_IE_BEACON_FLAG: |
| 3869 | mgmt_ie_buf = saved_ie->beacon_ie; |
| 3870 | mgmt_ie_len = &saved_ie->beacon_ie_len; |
| 3871 | mgmt_ie_buf_len = sizeof(saved_ie->beacon_ie); |
| 3872 | break; |
| 3873 | case BRCMF_VNDR_IE_ASSOCREQ_FLAG: |
| 3874 | mgmt_ie_buf = saved_ie->assoc_req_ie; |
| 3875 | mgmt_ie_len = &saved_ie->assoc_req_ie_len; |
| 3876 | mgmt_ie_buf_len = sizeof(saved_ie->assoc_req_ie); |
| 3877 | break; |
| 3878 | default: |
| 3879 | err = -EPERM; |
| 3880 | brcmf_err("not suitable type\n"); |
| 3881 | goto exit; |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3882 | } |
| 3883 | |
| 3884 | if (vndr_ie_len > mgmt_ie_buf_len) { |
| 3885 | err = -ENOMEM; |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 3886 | brcmf_err("extra IE size too big\n"); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3887 | goto exit; |
| 3888 | } |
| 3889 | |
| 3890 | /* parse and save new vndr_ie in curr_ie_buff before comparing it */ |
| 3891 | if (vndr_ie_buf && vndr_ie_len && curr_ie_buf) { |
| 3892 | ptr = curr_ie_buf; |
| 3893 | brcmf_parse_vndr_ies(vndr_ie_buf, vndr_ie_len, &new_vndr_ies); |
| 3894 | for (i = 0; i < new_vndr_ies.count; i++) { |
| 3895 | vndrie_info = &new_vndr_ies.ie_info[i]; |
| 3896 | memcpy(ptr + parsed_ie_buf_len, vndrie_info->ie_ptr, |
| 3897 | vndrie_info->ie_len); |
| 3898 | parsed_ie_buf_len += vndrie_info->ie_len; |
| 3899 | } |
| 3900 | } |
| 3901 | |
Hante Meuleman | b41fc3d | 2012-11-28 21:44:13 +0100 | [diff] [blame] | 3902 | if (mgmt_ie_buf && *mgmt_ie_len) { |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3903 | if (parsed_ie_buf_len && (parsed_ie_buf_len == *mgmt_ie_len) && |
| 3904 | (memcmp(mgmt_ie_buf, curr_ie_buf, |
| 3905 | parsed_ie_buf_len) == 0)) { |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 3906 | brcmf_dbg(TRACE, "Previous mgmt IE equals to current IE\n"); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3907 | goto exit; |
| 3908 | } |
| 3909 | |
| 3910 | /* parse old vndr_ie */ |
| 3911 | brcmf_parse_vndr_ies(mgmt_ie_buf, *mgmt_ie_len, &old_vndr_ies); |
| 3912 | |
| 3913 | /* make a command to delete old ie */ |
| 3914 | for (i = 0; i < old_vndr_ies.count; i++) { |
| 3915 | vndrie_info = &old_vndr_ies.ie_info[i]; |
| 3916 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 3917 | brcmf_dbg(TRACE, "DEL ID : %d, Len: %d , OUI:%02x:%02x:%02x\n", |
| 3918 | vndrie_info->vndrie.id, |
| 3919 | vndrie_info->vndrie.len, |
| 3920 | vndrie_info->vndrie.oui[0], |
| 3921 | vndrie_info->vndrie.oui[1], |
| 3922 | vndrie_info->vndrie.oui[2]); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3923 | |
| 3924 | del_add_ie_buf_len = brcmf_vndr_ie(curr_ie_buf, pktflag, |
| 3925 | vndrie_info->ie_ptr, |
| 3926 | vndrie_info->ie_len, |
| 3927 | "del"); |
| 3928 | curr_ie_buf += del_add_ie_buf_len; |
| 3929 | total_ie_buf_len += del_add_ie_buf_len; |
| 3930 | } |
| 3931 | } |
| 3932 | |
| 3933 | *mgmt_ie_len = 0; |
| 3934 | /* Add if there is any extra IE */ |
| 3935 | if (mgmt_ie_buf && parsed_ie_buf_len) { |
| 3936 | ptr = mgmt_ie_buf; |
| 3937 | |
| 3938 | remained_buf_len = mgmt_ie_buf_len; |
| 3939 | |
| 3940 | /* make a command to add new ie */ |
| 3941 | for (i = 0; i < new_vndr_ies.count; i++) { |
| 3942 | vndrie_info = &new_vndr_ies.ie_info[i]; |
| 3943 | |
Hante Meuleman | b41fc3d | 2012-11-28 21:44:13 +0100 | [diff] [blame] | 3944 | /* verify remained buf size before copy data */ |
| 3945 | if (remained_buf_len < (vndrie_info->vndrie.len + |
| 3946 | VNDR_IE_VSIE_OFFSET)) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 3947 | brcmf_err("no space in mgmt_ie_buf: len left %d", |
| 3948 | remained_buf_len); |
Hante Meuleman | b41fc3d | 2012-11-28 21:44:13 +0100 | [diff] [blame] | 3949 | break; |
| 3950 | } |
| 3951 | remained_buf_len -= (vndrie_info->ie_len + |
| 3952 | VNDR_IE_VSIE_OFFSET); |
| 3953 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 3954 | brcmf_dbg(TRACE, "ADDED ID : %d, Len: %d, OUI:%02x:%02x:%02x\n", |
| 3955 | vndrie_info->vndrie.id, |
| 3956 | vndrie_info->vndrie.len, |
| 3957 | vndrie_info->vndrie.oui[0], |
| 3958 | vndrie_info->vndrie.oui[1], |
| 3959 | vndrie_info->vndrie.oui[2]); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3960 | |
| 3961 | del_add_ie_buf_len = brcmf_vndr_ie(curr_ie_buf, pktflag, |
| 3962 | vndrie_info->ie_ptr, |
| 3963 | vndrie_info->ie_len, |
| 3964 | "add"); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3965 | |
| 3966 | /* save the parsed IE in wl struct */ |
| 3967 | memcpy(ptr + (*mgmt_ie_len), vndrie_info->ie_ptr, |
| 3968 | vndrie_info->ie_len); |
| 3969 | *mgmt_ie_len += vndrie_info->ie_len; |
| 3970 | |
| 3971 | curr_ie_buf += del_add_ie_buf_len; |
| 3972 | total_ie_buf_len += del_add_ie_buf_len; |
| 3973 | } |
| 3974 | } |
| 3975 | if (total_ie_buf_len) { |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 3976 | err = brcmf_fil_bsscfg_data_set(ifp, "vndr_ie", iovar_ie_buf, |
Hante Meuleman | 81f5dcb | 2012-10-22 10:36:14 -0700 | [diff] [blame] | 3977 | total_ie_buf_len); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3978 | if (err) |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 3979 | brcmf_err("vndr ie set error : %d\n", err); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3980 | } |
| 3981 | |
| 3982 | exit: |
| 3983 | kfree(iovar_ie_buf); |
| 3984 | return err; |
| 3985 | } |
| 3986 | |
Arend van Spriel | 5f4f9f1 | 2013-02-08 15:53:41 +0100 | [diff] [blame] | 3987 | s32 brcmf_vif_clear_mgmt_ies(struct brcmf_cfg80211_vif *vif) |
| 3988 | { |
| 3989 | s32 pktflags[] = { |
| 3990 | BRCMF_VNDR_IE_PRBREQ_FLAG, |
| 3991 | BRCMF_VNDR_IE_PRBRSP_FLAG, |
| 3992 | BRCMF_VNDR_IE_BEACON_FLAG |
| 3993 | }; |
| 3994 | int i; |
| 3995 | |
| 3996 | for (i = 0; i < ARRAY_SIZE(pktflags); i++) |
| 3997 | brcmf_vif_set_mgmt_ie(vif, pktflags[i], NULL, 0); |
| 3998 | |
| 3999 | memset(&vif->saved_ie, 0, sizeof(vif->saved_ie)); |
| 4000 | return 0; |
| 4001 | } |
| 4002 | |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4003 | static s32 |
Hante Meuleman | a0f0795 | 2013-02-08 15:53:47 +0100 | [diff] [blame] | 4004 | brcmf_config_ap_mgmt_ie(struct brcmf_cfg80211_vif *vif, |
| 4005 | struct cfg80211_beacon_data *beacon) |
| 4006 | { |
| 4007 | s32 err; |
| 4008 | |
| 4009 | /* Set Beacon IEs to FW */ |
| 4010 | err = brcmf_vif_set_mgmt_ie(vif, BRCMF_VNDR_IE_BEACON_FLAG, |
| 4011 | beacon->tail, beacon->tail_len); |
| 4012 | if (err) { |
| 4013 | brcmf_err("Set Beacon IE Failed\n"); |
| 4014 | return err; |
| 4015 | } |
| 4016 | brcmf_dbg(TRACE, "Applied Vndr IEs for Beacon\n"); |
| 4017 | |
| 4018 | /* Set Probe Response IEs to FW */ |
| 4019 | err = brcmf_vif_set_mgmt_ie(vif, BRCMF_VNDR_IE_PRBRSP_FLAG, |
| 4020 | beacon->proberesp_ies, |
| 4021 | beacon->proberesp_ies_len); |
| 4022 | if (err) |
| 4023 | brcmf_err("Set Probe Resp IE Failed\n"); |
| 4024 | else |
| 4025 | brcmf_dbg(TRACE, "Applied Vndr IEs for Probe Resp\n"); |
| 4026 | |
| 4027 | return err; |
| 4028 | } |
| 4029 | |
| 4030 | static s32 |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4031 | brcmf_cfg80211_start_ap(struct wiphy *wiphy, struct net_device *ndev, |
| 4032 | struct cfg80211_ap_settings *settings) |
| 4033 | { |
| 4034 | s32 ie_offset; |
Hante Meuleman | 1c9d30c | 2013-05-27 21:09:58 +0200 | [diff] [blame] | 4035 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 4036 | struct brcmf_if *ifp = netdev_priv(ndev); |
Johannes Berg | 4b5800f | 2014-01-15 14:55:59 +0100 | [diff] [blame] | 4037 | const struct brcmf_tlv *ssid_ie; |
Arend van Spriel | 9802776 | 2014-12-21 12:43:53 +0100 | [diff] [blame] | 4038 | const struct brcmf_tlv *country_ie; |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4039 | struct brcmf_ssid_le ssid_le; |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4040 | s32 err = -EPERM; |
Johannes Berg | 4b5800f | 2014-01-15 14:55:59 +0100 | [diff] [blame] | 4041 | const struct brcmf_tlv *rsn_ie; |
| 4042 | const struct brcmf_vs_tlv *wpa_ie; |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4043 | struct brcmf_join_params join_params; |
Hante Meuleman | a0f0795 | 2013-02-08 15:53:47 +0100 | [diff] [blame] | 4044 | enum nl80211_iftype dev_role; |
| 4045 | struct brcmf_fil_bss_enable_le bss_enable; |
Arend van Spriel | 06c0158 | 2014-05-12 10:47:37 +0200 | [diff] [blame] | 4046 | u16 chanspec; |
Hante Meuleman | a44aa40 | 2014-12-03 21:05:33 +0100 | [diff] [blame] | 4047 | bool mbss; |
Arend van Spriel | 9802776 | 2014-12-21 12:43:53 +0100 | [diff] [blame] | 4048 | int is_11d; |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4049 | |
Arend van Spriel | 06c0158 | 2014-05-12 10:47:37 +0200 | [diff] [blame] | 4050 | brcmf_dbg(TRACE, "ctrlchn=%d, center=%d, bw=%d, beacon_interval=%d, dtim_period=%d,\n", |
| 4051 | settings->chandef.chan->hw_value, |
| 4052 | settings->chandef.center_freq1, settings->chandef.width, |
Arend van Spriel | a9a5687 | 2014-05-12 10:47:33 +0200 | [diff] [blame] | 4053 | settings->beacon_interval, settings->dtim_period); |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 4054 | brcmf_dbg(TRACE, "ssid=%s(%zu), auth_type=%d, inactivity_timeout=%d\n", |
| 4055 | settings->ssid, settings->ssid_len, settings->auth_type, |
| 4056 | settings->inactivity_timeout); |
Hante Meuleman | 426d0a5 | 2013-02-08 15:53:53 +0100 | [diff] [blame] | 4057 | dev_role = ifp->vif->wdev.iftype; |
Hante Meuleman | a44aa40 | 2014-12-03 21:05:33 +0100 | [diff] [blame] | 4058 | mbss = ifp->vif->mbss; |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4059 | |
Arend van Spriel | 9802776 | 2014-12-21 12:43:53 +0100 | [diff] [blame] | 4060 | /* store current 11d setting */ |
| 4061 | brcmf_fil_cmd_int_get(ifp, BRCMF_C_GET_REGULATORY, &ifp->vif->is_11d); |
| 4062 | country_ie = brcmf_parse_tlvs((u8 *)settings->beacon.tail, |
| 4063 | settings->beacon.tail_len, |
| 4064 | WLAN_EID_COUNTRY); |
| 4065 | is_11d = country_ie ? 1 : 0; |
| 4066 | |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4067 | memset(&ssid_le, 0, sizeof(ssid_le)); |
| 4068 | if (settings->ssid == NULL || settings->ssid_len == 0) { |
| 4069 | ie_offset = DOT11_MGMT_HDR_LEN + DOT11_BCN_PRB_FIXED_LEN; |
| 4070 | ssid_ie = brcmf_parse_tlvs( |
| 4071 | (u8 *)&settings->beacon.head[ie_offset], |
| 4072 | settings->beacon.head_len - ie_offset, |
| 4073 | WLAN_EID_SSID); |
| 4074 | if (!ssid_ie) |
| 4075 | return -EINVAL; |
| 4076 | |
| 4077 | memcpy(ssid_le.SSID, ssid_ie->data, ssid_ie->len); |
| 4078 | ssid_le.SSID_len = cpu_to_le32(ssid_ie->len); |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 4079 | brcmf_dbg(TRACE, "SSID is (%s) in Head\n", ssid_le.SSID); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4080 | } else { |
| 4081 | memcpy(ssid_le.SSID, settings->ssid, settings->ssid_len); |
| 4082 | ssid_le.SSID_len = cpu_to_le32((u32)settings->ssid_len); |
| 4083 | } |
| 4084 | |
Hante Meuleman | a44aa40 | 2014-12-03 21:05:33 +0100 | [diff] [blame] | 4085 | if (!mbss) { |
| 4086 | brcmf_set_mpc(ifp, 0); |
| 4087 | brcmf_configure_arp_offload(ifp, false); |
| 4088 | } |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4089 | |
| 4090 | /* find the RSN_IE */ |
| 4091 | rsn_ie = brcmf_parse_tlvs((u8 *)settings->beacon.tail, |
| 4092 | settings->beacon.tail_len, WLAN_EID_RSN); |
| 4093 | |
| 4094 | /* find the WPA_IE */ |
| 4095 | wpa_ie = brcmf_find_wpaie((u8 *)settings->beacon.tail, |
| 4096 | settings->beacon.tail_len); |
| 4097 | |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4098 | if ((wpa_ie != NULL || rsn_ie != NULL)) { |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 4099 | brcmf_dbg(TRACE, "WPA(2) IE is found\n"); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4100 | if (wpa_ie != NULL) { |
| 4101 | /* WPA IE */ |
Hante Meuleman | a44aa40 | 2014-12-03 21:05:33 +0100 | [diff] [blame] | 4102 | err = brcmf_configure_wpaie(ifp, wpa_ie, false); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4103 | if (err < 0) |
| 4104 | goto exit; |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4105 | } else { |
Hante Meuleman | a44aa40 | 2014-12-03 21:05:33 +0100 | [diff] [blame] | 4106 | struct brcmf_vs_tlv *tmp_ie; |
| 4107 | |
| 4108 | tmp_ie = (struct brcmf_vs_tlv *)rsn_ie; |
| 4109 | |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4110 | /* RSN IE */ |
Hante Meuleman | a44aa40 | 2014-12-03 21:05:33 +0100 | [diff] [blame] | 4111 | err = brcmf_configure_wpaie(ifp, tmp_ie, true); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4112 | if (err < 0) |
| 4113 | goto exit; |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4114 | } |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4115 | } else { |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 4116 | brcmf_dbg(TRACE, "No WPA(2) IEs found\n"); |
Hante Meuleman | 1f17011 | 2013-02-06 18:40:38 +0100 | [diff] [blame] | 4117 | brcmf_configure_opensecurity(ifp); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4118 | } |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4119 | |
Hante Meuleman | a0f0795 | 2013-02-08 15:53:47 +0100 | [diff] [blame] | 4120 | brcmf_config_ap_mgmt_ie(ifp->vif, &settings->beacon); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4121 | |
Hante Meuleman | a44aa40 | 2014-12-03 21:05:33 +0100 | [diff] [blame] | 4122 | if (!mbss) { |
| 4123 | chanspec = chandef_to_chanspec(&cfg->d11inf, |
| 4124 | &settings->chandef); |
| 4125 | err = brcmf_fil_iovar_int_set(ifp, "chanspec", chanspec); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4126 | if (err < 0) { |
Hante Meuleman | a44aa40 | 2014-12-03 21:05:33 +0100 | [diff] [blame] | 4127 | brcmf_err("Set Channel failed: chspec=%d, %d\n", |
| 4128 | chanspec, err); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4129 | goto exit; |
| 4130 | } |
Hante Meuleman | a44aa40 | 2014-12-03 21:05:33 +0100 | [diff] [blame] | 4131 | |
Arend van Spriel | 9802776 | 2014-12-21 12:43:53 +0100 | [diff] [blame] | 4132 | if (is_11d != ifp->vif->is_11d) { |
| 4133 | err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_REGULATORY, |
| 4134 | is_11d); |
| 4135 | if (err < 0) { |
| 4136 | brcmf_err("Regulatory Set Error, %d\n", err); |
| 4137 | goto exit; |
| 4138 | } |
| 4139 | } |
Hante Meuleman | a44aa40 | 2014-12-03 21:05:33 +0100 | [diff] [blame] | 4140 | if (settings->beacon_interval) { |
| 4141 | err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_BCNPRD, |
| 4142 | settings->beacon_interval); |
| 4143 | if (err < 0) { |
| 4144 | brcmf_err("Beacon Interval Set Error, %d\n", |
| 4145 | err); |
| 4146 | goto exit; |
| 4147 | } |
| 4148 | } |
| 4149 | if (settings->dtim_period) { |
| 4150 | err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_DTIMPRD, |
| 4151 | settings->dtim_period); |
| 4152 | if (err < 0) { |
| 4153 | brcmf_err("DTIM Interval Set Error, %d\n", err); |
| 4154 | goto exit; |
| 4155 | } |
| 4156 | } |
| 4157 | |
| 4158 | if (dev_role == NL80211_IFTYPE_AP) { |
| 4159 | err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_DOWN, 1); |
| 4160 | if (err < 0) { |
| 4161 | brcmf_err("BRCMF_C_DOWN error %d\n", err); |
| 4162 | goto exit; |
| 4163 | } |
| 4164 | brcmf_fil_iovar_int_set(ifp, "apsta", 0); |
| 4165 | } |
| 4166 | |
| 4167 | err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_INFRA, 1); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4168 | if (err < 0) { |
Hante Meuleman | a44aa40 | 2014-12-03 21:05:33 +0100 | [diff] [blame] | 4169 | brcmf_err("SET INFRA error %d\n", err); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4170 | goto exit; |
| 4171 | } |
Arend van Spriel | 9802776 | 2014-12-21 12:43:53 +0100 | [diff] [blame] | 4172 | } else if (WARN_ON(is_11d != ifp->vif->is_11d)) { |
| 4173 | /* Multiple-BSS should use same 11d configuration */ |
| 4174 | err = -EINVAL; |
| 4175 | goto exit; |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4176 | } |
Hante Meuleman | a0f0795 | 2013-02-08 15:53:47 +0100 | [diff] [blame] | 4177 | if (dev_role == NL80211_IFTYPE_AP) { |
Hante Meuleman | a44aa40 | 2014-12-03 21:05:33 +0100 | [diff] [blame] | 4178 | if ((brcmf_feat_is_enabled(ifp, BRCMF_FEAT_MBSS)) && (!mbss)) |
| 4179 | brcmf_fil_iovar_int_set(ifp, "mbss", 1); |
| 4180 | |
Hante Meuleman | a0f0795 | 2013-02-08 15:53:47 +0100 | [diff] [blame] | 4181 | err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_AP, 1); |
| 4182 | if (err < 0) { |
| 4183 | brcmf_err("setting AP mode failed %d\n", err); |
| 4184 | goto exit; |
| 4185 | } |
| 4186 | err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_UP, 1); |
| 4187 | if (err < 0) { |
| 4188 | brcmf_err("BRCMF_C_UP error (%d)\n", err); |
| 4189 | goto exit; |
| 4190 | } |
Hante Meuleman | 118eb30 | 2014-12-21 12:43:49 +0100 | [diff] [blame] | 4191 | /* On DOWN the firmware removes the WEP keys, reconfigure |
| 4192 | * them if they were set. |
| 4193 | */ |
| 4194 | brcmf_cfg80211_reconfigure_wep(ifp); |
Hante Meuleman | a0f0795 | 2013-02-08 15:53:47 +0100 | [diff] [blame] | 4195 | |
| 4196 | memset(&join_params, 0, sizeof(join_params)); |
| 4197 | /* join parameters starts with ssid */ |
| 4198 | memcpy(&join_params.ssid_le, &ssid_le, sizeof(ssid_le)); |
| 4199 | /* create softap */ |
| 4200 | err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SET_SSID, |
| 4201 | &join_params, sizeof(join_params)); |
| 4202 | if (err < 0) { |
| 4203 | brcmf_err("SET SSID error (%d)\n", err); |
| 4204 | goto exit; |
| 4205 | } |
| 4206 | brcmf_dbg(TRACE, "AP mode configuration complete\n"); |
| 4207 | } else { |
| 4208 | err = brcmf_fil_bsscfg_data_set(ifp, "ssid", &ssid_le, |
| 4209 | sizeof(ssid_le)); |
| 4210 | if (err < 0) { |
| 4211 | brcmf_err("setting ssid failed %d\n", err); |
| 4212 | goto exit; |
| 4213 | } |
| 4214 | bss_enable.bsscfg_idx = cpu_to_le32(ifp->bssidx); |
| 4215 | bss_enable.enable = cpu_to_le32(1); |
| 4216 | err = brcmf_fil_iovar_data_set(ifp, "bss", &bss_enable, |
| 4217 | sizeof(bss_enable)); |
| 4218 | if (err < 0) { |
| 4219 | brcmf_err("bss_enable config failed %d\n", err); |
| 4220 | goto exit; |
| 4221 | } |
| 4222 | |
| 4223 | brcmf_dbg(TRACE, "GO mode configuration complete\n"); |
| 4224 | } |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 4225 | clear_bit(BRCMF_VIF_STATUS_AP_CREATING, &ifp->vif->sme_state); |
| 4226 | set_bit(BRCMF_VIF_STATUS_AP_CREATED, &ifp->vif->sme_state); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4227 | |
| 4228 | exit: |
Hante Meuleman | a44aa40 | 2014-12-03 21:05:33 +0100 | [diff] [blame] | 4229 | if ((err) && (!mbss)) { |
Arend van Spriel | f96aa07 | 2013-04-05 10:57:48 +0200 | [diff] [blame] | 4230 | brcmf_set_mpc(ifp, 1); |
Hante Meuleman | b365745 | 2013-05-27 21:09:53 +0200 | [diff] [blame] | 4231 | brcmf_configure_arp_offload(ifp, true); |
| 4232 | } |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4233 | return err; |
| 4234 | } |
| 4235 | |
| 4236 | static int brcmf_cfg80211_stop_ap(struct wiphy *wiphy, struct net_device *ndev) |
| 4237 | { |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 4238 | struct brcmf_if *ifp = netdev_priv(ndev); |
Hante Meuleman | 5c33a94 | 2013-04-02 21:06:18 +0200 | [diff] [blame] | 4239 | s32 err; |
Hante Meuleman | 426d0a5 | 2013-02-08 15:53:53 +0100 | [diff] [blame] | 4240 | struct brcmf_fil_bss_enable_le bss_enable; |
Hante Meuleman | 5c33a94 | 2013-04-02 21:06:18 +0200 | [diff] [blame] | 4241 | struct brcmf_join_params join_params; |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4242 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 4243 | brcmf_dbg(TRACE, "Enter\n"); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4244 | |
Hante Meuleman | 426d0a5 | 2013-02-08 15:53:53 +0100 | [diff] [blame] | 4245 | if (ifp->vif->wdev.iftype == NL80211_IFTYPE_AP) { |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4246 | /* Due to most likely deauths outstanding we sleep */ |
| 4247 | /* first to make sure they get processed by fw. */ |
| 4248 | msleep(400); |
Hante Meuleman | 5c33a94 | 2013-04-02 21:06:18 +0200 | [diff] [blame] | 4249 | |
Hante Meuleman | a44aa40 | 2014-12-03 21:05:33 +0100 | [diff] [blame] | 4250 | if (ifp->vif->mbss) { |
| 4251 | err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_DOWN, 1); |
| 4252 | return err; |
| 4253 | } |
| 4254 | |
Hante Meuleman | 5c33a94 | 2013-04-02 21:06:18 +0200 | [diff] [blame] | 4255 | memset(&join_params, 0, sizeof(join_params)); |
| 4256 | err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SET_SSID, |
| 4257 | &join_params, sizeof(join_params)); |
| 4258 | if (err < 0) |
| 4259 | brcmf_err("SET SSID error (%d)\n", err); |
Hante Meuleman | a44aa40 | 2014-12-03 21:05:33 +0100 | [diff] [blame] | 4260 | err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_DOWN, 1); |
Hante Meuleman | 5c33a94 | 2013-04-02 21:06:18 +0200 | [diff] [blame] | 4261 | if (err < 0) |
Hante Meuleman | a44aa40 | 2014-12-03 21:05:33 +0100 | [diff] [blame] | 4262 | brcmf_err("BRCMF_C_DOWN error %d\n", err); |
Hante Meuleman | 5c33a94 | 2013-04-02 21:06:18 +0200 | [diff] [blame] | 4263 | err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_AP, 0); |
| 4264 | if (err < 0) |
| 4265 | brcmf_err("setting AP mode failed %d\n", err); |
| 4266 | err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_INFRA, 0); |
| 4267 | if (err < 0) |
| 4268 | brcmf_err("setting INFRA mode failed %d\n", err); |
Hante Meuleman | a44aa40 | 2014-12-03 21:05:33 +0100 | [diff] [blame] | 4269 | if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_MBSS)) |
| 4270 | brcmf_fil_iovar_int_set(ifp, "mbss", 0); |
Arend van Spriel | 9802776 | 2014-12-21 12:43:53 +0100 | [diff] [blame] | 4271 | err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_REGULATORY, |
| 4272 | ifp->vif->is_11d); |
| 4273 | if (err < 0) |
| 4274 | brcmf_err("restoring REGULATORY setting failed %d\n", |
| 4275 | err); |
Hante Meuleman | a44aa40 | 2014-12-03 21:05:33 +0100 | [diff] [blame] | 4276 | /* Bring device back up so it can be used again */ |
| 4277 | err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_UP, 1); |
| 4278 | if (err < 0) |
| 4279 | brcmf_err("BRCMF_C_UP error %d\n", err); |
Hante Meuleman | 426d0a5 | 2013-02-08 15:53:53 +0100 | [diff] [blame] | 4280 | } else { |
| 4281 | bss_enable.bsscfg_idx = cpu_to_le32(ifp->bssidx); |
| 4282 | bss_enable.enable = cpu_to_le32(0); |
| 4283 | err = brcmf_fil_iovar_data_set(ifp, "bss", &bss_enable, |
| 4284 | sizeof(bss_enable)); |
| 4285 | if (err < 0) |
| 4286 | brcmf_err("bss_enable config failed %d\n", err); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4287 | } |
Arend van Spriel | f96aa07 | 2013-04-05 10:57:48 +0200 | [diff] [blame] | 4288 | brcmf_set_mpc(ifp, 1); |
Hante Meuleman | b365745 | 2013-05-27 21:09:53 +0200 | [diff] [blame] | 4289 | brcmf_configure_arp_offload(ifp, true); |
Hante Meuleman | 426d0a5 | 2013-02-08 15:53:53 +0100 | [diff] [blame] | 4290 | set_bit(BRCMF_VIF_STATUS_AP_CREATING, &ifp->vif->sme_state); |
| 4291 | clear_bit(BRCMF_VIF_STATUS_AP_CREATED, &ifp->vif->sme_state); |
| 4292 | |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4293 | return err; |
| 4294 | } |
| 4295 | |
Hante Meuleman | a0f0795 | 2013-02-08 15:53:47 +0100 | [diff] [blame] | 4296 | static s32 |
| 4297 | brcmf_cfg80211_change_beacon(struct wiphy *wiphy, struct net_device *ndev, |
| 4298 | struct cfg80211_beacon_data *info) |
| 4299 | { |
Hante Meuleman | a0f0795 | 2013-02-08 15:53:47 +0100 | [diff] [blame] | 4300 | struct brcmf_if *ifp = netdev_priv(ndev); |
| 4301 | s32 err; |
| 4302 | |
| 4303 | brcmf_dbg(TRACE, "Enter\n"); |
| 4304 | |
Hante Meuleman | a0f0795 | 2013-02-08 15:53:47 +0100 | [diff] [blame] | 4305 | err = brcmf_config_ap_mgmt_ie(ifp->vif, info); |
| 4306 | |
| 4307 | return err; |
| 4308 | } |
| 4309 | |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4310 | static int |
| 4311 | brcmf_cfg80211_del_station(struct wiphy *wiphy, struct net_device *ndev, |
Jouni Malinen | 89c771e | 2014-10-10 20:52:40 +0300 | [diff] [blame] | 4312 | struct station_del_parameters *params) |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4313 | { |
Hante Meuleman | a0f0795 | 2013-02-08 15:53:47 +0100 | [diff] [blame] | 4314 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4315 | struct brcmf_scb_val_le scbval; |
Arend van Spriel | 0abb5f21 | 2012-10-22 13:55:32 -0700 | [diff] [blame] | 4316 | struct brcmf_if *ifp = netdev_priv(ndev); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4317 | s32 err; |
| 4318 | |
Jouni Malinen | 89c771e | 2014-10-10 20:52:40 +0300 | [diff] [blame] | 4319 | if (!params->mac) |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4320 | return -EFAULT; |
| 4321 | |
Jouni Malinen | 89c771e | 2014-10-10 20:52:40 +0300 | [diff] [blame] | 4322 | brcmf_dbg(TRACE, "Enter %pM\n", params->mac); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4323 | |
Hante Meuleman | a0f0795 | 2013-02-08 15:53:47 +0100 | [diff] [blame] | 4324 | if (ifp->vif == cfg->p2p.bss_idx[P2PAPI_BSSCFG_DEVICE].vif) |
| 4325 | ifp = cfg->p2p.bss_idx[P2PAPI_BSSCFG_PRIMARY].vif->ifp; |
Arend van Spriel | ce81e31 | 2012-10-22 13:55:37 -0700 | [diff] [blame] | 4326 | if (!check_vif_up(ifp->vif)) |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4327 | return -EIO; |
| 4328 | |
Jouni Malinen | 89c771e | 2014-10-10 20:52:40 +0300 | [diff] [blame] | 4329 | memcpy(&scbval.ea, params->mac, ETH_ALEN); |
Rafał Miłecki | ba8b6ae | 2015-02-08 11:51:47 +0100 | [diff] [blame] | 4330 | scbval.val = cpu_to_le32(params->reason_code); |
Arend van Spriel | 0abb5f21 | 2012-10-22 13:55:32 -0700 | [diff] [blame] | 4331 | 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] | 4332 | &scbval, sizeof(scbval)); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4333 | if (err) |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 4334 | brcmf_err("SCB_DEAUTHENTICATE_FOR_REASON failed %d\n", err); |
Hante Meuleman | 7ab6acd | 2013-02-08 15:53:58 +0100 | [diff] [blame] | 4335 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 4336 | brcmf_dbg(TRACE, "Exit\n"); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4337 | return err; |
| 4338 | } |
| 4339 | |
Hante Meuleman | 6b89dcb | 2014-12-21 12:43:52 +0100 | [diff] [blame] | 4340 | static int |
| 4341 | brcmf_cfg80211_change_station(struct wiphy *wiphy, struct net_device *ndev, |
| 4342 | const u8 *mac, struct station_parameters *params) |
| 4343 | { |
| 4344 | struct brcmf_if *ifp = netdev_priv(ndev); |
| 4345 | s32 err; |
| 4346 | |
| 4347 | brcmf_dbg(TRACE, "Enter, MAC %pM, mask 0x%04x set 0x%04x\n", mac, |
| 4348 | params->sta_flags_mask, params->sta_flags_set); |
| 4349 | |
| 4350 | /* Ignore all 00 MAC */ |
| 4351 | if (is_zero_ether_addr(mac)) |
| 4352 | return 0; |
| 4353 | |
| 4354 | if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED))) |
| 4355 | return 0; |
| 4356 | |
| 4357 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED)) |
| 4358 | err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SET_SCB_AUTHORIZE, |
| 4359 | (void *)mac, ETH_ALEN); |
| 4360 | else |
| 4361 | err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SET_SCB_DEAUTHORIZE, |
| 4362 | (void *)mac, ETH_ALEN); |
| 4363 | if (err < 0) |
| 4364 | brcmf_err("Setting SCB (de-)authorize failed, %d\n", err); |
| 4365 | |
| 4366 | return err; |
| 4367 | } |
Hante Meuleman | 0de8aac | 2013-02-08 15:53:38 +0100 | [diff] [blame] | 4368 | |
| 4369 | static void |
| 4370 | brcmf_cfg80211_mgmt_frame_register(struct wiphy *wiphy, |
| 4371 | struct wireless_dev *wdev, |
| 4372 | u16 frame_type, bool reg) |
| 4373 | { |
Arend van Spriel | 7fa2e35 | 2013-04-05 10:57:47 +0200 | [diff] [blame] | 4374 | struct brcmf_cfg80211_vif *vif; |
Hante Meuleman | 0de8aac | 2013-02-08 15:53:38 +0100 | [diff] [blame] | 4375 | u16 mgmt_type; |
| 4376 | |
| 4377 | brcmf_dbg(TRACE, "Enter, frame_type %04x, reg=%d\n", frame_type, reg); |
| 4378 | |
| 4379 | mgmt_type = (frame_type & IEEE80211_FCTL_STYPE) >> 4; |
Arend van Spriel | 7fa2e35 | 2013-04-05 10:57:47 +0200 | [diff] [blame] | 4380 | vif = container_of(wdev, struct brcmf_cfg80211_vif, wdev); |
Hante Meuleman | 0de8aac | 2013-02-08 15:53:38 +0100 | [diff] [blame] | 4381 | if (reg) |
| 4382 | vif->mgmt_rx_reg |= BIT(mgmt_type); |
| 4383 | else |
Hante Meuleman | 318a64c | 2013-02-08 15:53:45 +0100 | [diff] [blame] | 4384 | vif->mgmt_rx_reg &= ~BIT(mgmt_type); |
Hante Meuleman | 0de8aac | 2013-02-08 15:53:38 +0100 | [diff] [blame] | 4385 | } |
| 4386 | |
| 4387 | |
| 4388 | static int |
| 4389 | brcmf_cfg80211_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev, |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 4390 | struct cfg80211_mgmt_tx_params *params, u64 *cookie) |
Hante Meuleman | 0de8aac | 2013-02-08 15:53:38 +0100 | [diff] [blame] | 4391 | { |
| 4392 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 4393 | struct ieee80211_channel *chan = params->chan; |
| 4394 | const u8 *buf = params->buf; |
| 4395 | size_t len = params->len; |
Hante Meuleman | 0de8aac | 2013-02-08 15:53:38 +0100 | [diff] [blame] | 4396 | const struct ieee80211_mgmt *mgmt; |
| 4397 | struct brcmf_cfg80211_vif *vif; |
| 4398 | s32 err = 0; |
| 4399 | s32 ie_offset; |
| 4400 | s32 ie_len; |
Hante Meuleman | 18e2f61 | 2013-02-08 15:53:49 +0100 | [diff] [blame] | 4401 | struct brcmf_fil_action_frame_le *action_frame; |
| 4402 | struct brcmf_fil_af_params_le *af_params; |
| 4403 | bool ack; |
| 4404 | s32 chan_nr; |
Antonio Quartulli | c2ff8ca | 2013-06-11 14:20:01 +0200 | [diff] [blame] | 4405 | u32 freq; |
Hante Meuleman | 0de8aac | 2013-02-08 15:53:38 +0100 | [diff] [blame] | 4406 | |
| 4407 | brcmf_dbg(TRACE, "Enter\n"); |
| 4408 | |
| 4409 | *cookie = 0; |
| 4410 | |
| 4411 | mgmt = (const struct ieee80211_mgmt *)buf; |
| 4412 | |
Hante Meuleman | a0f0795 | 2013-02-08 15:53:47 +0100 | [diff] [blame] | 4413 | if (!ieee80211_is_mgmt(mgmt->frame_control)) { |
| 4414 | brcmf_err("Driver only allows MGMT packet type\n"); |
| 4415 | return -EPERM; |
Hante Meuleman | 0de8aac | 2013-02-08 15:53:38 +0100 | [diff] [blame] | 4416 | } |
Hante Meuleman | a0f0795 | 2013-02-08 15:53:47 +0100 | [diff] [blame] | 4417 | |
Antonio Quartulli | c2ff8ca | 2013-06-11 14:20:01 +0200 | [diff] [blame] | 4418 | vif = container_of(wdev, struct brcmf_cfg80211_vif, wdev); |
| 4419 | |
Hante Meuleman | a0f0795 | 2013-02-08 15:53:47 +0100 | [diff] [blame] | 4420 | if (ieee80211_is_probe_resp(mgmt->frame_control)) { |
| 4421 | /* Right now the only reason to get a probe response */ |
| 4422 | /* is for p2p listen response or for p2p GO from */ |
| 4423 | /* wpa_supplicant. Unfortunately the probe is send */ |
| 4424 | /* on primary ndev, while dongle wants it on the p2p */ |
| 4425 | /* vif. Since this is only reason for a probe */ |
| 4426 | /* response to be sent, the vif is taken from cfg. */ |
| 4427 | /* If ever desired to send proberesp for non p2p */ |
| 4428 | /* response then data should be checked for */ |
| 4429 | /* "DIRECT-". Note in future supplicant will take */ |
| 4430 | /* dedicated p2p wdev to do this and then this 'hack'*/ |
| 4431 | /* is not needed anymore. */ |
| 4432 | ie_offset = DOT11_MGMT_HDR_LEN + |
| 4433 | DOT11_BCN_PRB_FIXED_LEN; |
| 4434 | ie_len = len - ie_offset; |
Hante Meuleman | a0f0795 | 2013-02-08 15:53:47 +0100 | [diff] [blame] | 4435 | if (vif == cfg->p2p.bss_idx[P2PAPI_BSSCFG_PRIMARY].vif) |
| 4436 | vif = cfg->p2p.bss_idx[P2PAPI_BSSCFG_DEVICE].vif; |
| 4437 | err = brcmf_vif_set_mgmt_ie(vif, |
| 4438 | BRCMF_VNDR_IE_PRBRSP_FLAG, |
| 4439 | &buf[ie_offset], |
| 4440 | ie_len); |
| 4441 | cfg80211_mgmt_tx_status(wdev, *cookie, buf, len, true, |
| 4442 | GFP_KERNEL); |
Hante Meuleman | 18e2f61 | 2013-02-08 15:53:49 +0100 | [diff] [blame] | 4443 | } else if (ieee80211_is_action(mgmt->frame_control)) { |
| 4444 | af_params = kzalloc(sizeof(*af_params), GFP_KERNEL); |
| 4445 | if (af_params == NULL) { |
| 4446 | brcmf_err("unable to allocate frame\n"); |
| 4447 | err = -ENOMEM; |
| 4448 | goto exit; |
| 4449 | } |
| 4450 | action_frame = &af_params->action_frame; |
| 4451 | /* Add the packet Id */ |
| 4452 | action_frame->packet_id = cpu_to_le32(*cookie); |
| 4453 | /* Add BSSID */ |
| 4454 | memcpy(&action_frame->da[0], &mgmt->da[0], ETH_ALEN); |
| 4455 | memcpy(&af_params->bssid[0], &mgmt->bssid[0], ETH_ALEN); |
| 4456 | /* Add the length exepted for 802.11 header */ |
| 4457 | action_frame->len = cpu_to_le16(len - DOT11_MGMT_HDR_LEN); |
Antonio Quartulli | c2ff8ca | 2013-06-11 14:20:01 +0200 | [diff] [blame] | 4458 | /* Add the channel. Use the one specified as parameter if any or |
| 4459 | * the current one (got from the firmware) otherwise |
| 4460 | */ |
| 4461 | if (chan) |
| 4462 | freq = chan->center_freq; |
| 4463 | else |
| 4464 | brcmf_fil_cmd_int_get(vif->ifp, BRCMF_C_GET_CHANNEL, |
| 4465 | &freq); |
| 4466 | chan_nr = ieee80211_frequency_to_channel(freq); |
Hante Meuleman | 18e2f61 | 2013-02-08 15:53:49 +0100 | [diff] [blame] | 4467 | af_params->channel = cpu_to_le32(chan_nr); |
| 4468 | |
| 4469 | memcpy(action_frame->data, &buf[DOT11_MGMT_HDR_LEN], |
| 4470 | le16_to_cpu(action_frame->len)); |
| 4471 | |
| 4472 | brcmf_dbg(TRACE, "Action frame, cookie=%lld, len=%d, freq=%d\n", |
Antonio Quartulli | 86a9c4a | 2013-06-19 13:35:31 +0200 | [diff] [blame] | 4473 | *cookie, le16_to_cpu(action_frame->len), freq); |
Hante Meuleman | 18e2f61 | 2013-02-08 15:53:49 +0100 | [diff] [blame] | 4474 | |
Arend van Spriel | 7fa2e35 | 2013-04-05 10:57:47 +0200 | [diff] [blame] | 4475 | ack = brcmf_p2p_send_action_frame(cfg, cfg_to_ndev(cfg), |
Hante Meuleman | 18e2f61 | 2013-02-08 15:53:49 +0100 | [diff] [blame] | 4476 | af_params); |
| 4477 | |
| 4478 | cfg80211_mgmt_tx_status(wdev, *cookie, buf, len, ack, |
| 4479 | GFP_KERNEL); |
| 4480 | kfree(af_params); |
Hante Meuleman | a0f0795 | 2013-02-08 15:53:47 +0100 | [diff] [blame] | 4481 | } else { |
| 4482 | brcmf_dbg(TRACE, "Unhandled, fc=%04x!!\n", mgmt->frame_control); |
| 4483 | brcmf_dbg_hex_dump(true, buf, len, "payload, len=%Zu\n", len); |
| 4484 | } |
| 4485 | |
Hante Meuleman | 18e2f61 | 2013-02-08 15:53:49 +0100 | [diff] [blame] | 4486 | exit: |
Hante Meuleman | 0de8aac | 2013-02-08 15:53:38 +0100 | [diff] [blame] | 4487 | return err; |
| 4488 | } |
| 4489 | |
| 4490 | |
| 4491 | static int |
| 4492 | brcmf_cfg80211_cancel_remain_on_channel(struct wiphy *wiphy, |
| 4493 | struct wireless_dev *wdev, |
| 4494 | u64 cookie) |
| 4495 | { |
| 4496 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); |
| 4497 | struct brcmf_cfg80211_vif *vif; |
| 4498 | int err = 0; |
| 4499 | |
| 4500 | brcmf_dbg(TRACE, "Enter p2p listen cancel\n"); |
| 4501 | |
| 4502 | vif = cfg->p2p.bss_idx[P2PAPI_BSSCFG_DEVICE].vif; |
| 4503 | if (vif == NULL) { |
| 4504 | brcmf_err("No p2p device available for probe response\n"); |
| 4505 | err = -ENODEV; |
| 4506 | goto exit; |
| 4507 | } |
| 4508 | brcmf_p2p_cancel_remain_on_channel(vif->ifp); |
| 4509 | exit: |
| 4510 | return err; |
| 4511 | } |
| 4512 | |
Piotr Haber | 61730d4 | 2013-04-23 12:53:12 +0200 | [diff] [blame] | 4513 | static int brcmf_cfg80211_crit_proto_start(struct wiphy *wiphy, |
| 4514 | struct wireless_dev *wdev, |
| 4515 | enum nl80211_crit_proto_id proto, |
| 4516 | u16 duration) |
| 4517 | { |
| 4518 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); |
| 4519 | struct brcmf_cfg80211_vif *vif; |
| 4520 | |
| 4521 | vif = container_of(wdev, struct brcmf_cfg80211_vif, wdev); |
| 4522 | |
| 4523 | /* only DHCP support for now */ |
| 4524 | if (proto != NL80211_CRIT_PROTO_DHCP) |
| 4525 | return -EINVAL; |
| 4526 | |
| 4527 | /* suppress and abort scanning */ |
| 4528 | set_bit(BRCMF_SCAN_STATUS_SUPPRESS, &cfg->scan_status); |
| 4529 | brcmf_abort_scanning(cfg); |
| 4530 | |
| 4531 | return brcmf_btcoex_set_mode(vif, BRCMF_BTCOEX_DISABLED, duration); |
| 4532 | } |
| 4533 | |
| 4534 | static void brcmf_cfg80211_crit_proto_stop(struct wiphy *wiphy, |
| 4535 | struct wireless_dev *wdev) |
| 4536 | { |
| 4537 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); |
| 4538 | struct brcmf_cfg80211_vif *vif; |
| 4539 | |
| 4540 | vif = container_of(wdev, struct brcmf_cfg80211_vif, wdev); |
| 4541 | |
| 4542 | brcmf_btcoex_set_mode(vif, BRCMF_BTCOEX_ENABLED, 0); |
| 4543 | clear_bit(BRCMF_SCAN_STATUS_SUPPRESS, &cfg->scan_status); |
| 4544 | } |
| 4545 | |
Hante Meuleman | 70b7d94 | 2014-07-30 13:20:07 +0200 | [diff] [blame] | 4546 | static s32 |
| 4547 | brcmf_notify_tdls_peer_event(struct brcmf_if *ifp, |
| 4548 | const struct brcmf_event_msg *e, void *data) |
| 4549 | { |
| 4550 | switch (e->reason) { |
| 4551 | case BRCMF_E_REASON_TDLS_PEER_DISCOVERED: |
| 4552 | brcmf_dbg(TRACE, "TDLS Peer Discovered\n"); |
| 4553 | break; |
| 4554 | case BRCMF_E_REASON_TDLS_PEER_CONNECTED: |
| 4555 | brcmf_dbg(TRACE, "TDLS Peer Connected\n"); |
| 4556 | brcmf_proto_add_tdls_peer(ifp->drvr, ifp->ifidx, (u8 *)e->addr); |
| 4557 | break; |
| 4558 | case BRCMF_E_REASON_TDLS_PEER_DISCONNECTED: |
| 4559 | brcmf_dbg(TRACE, "TDLS Peer Disconnected\n"); |
| 4560 | brcmf_proto_delete_peer(ifp->drvr, ifp->ifidx, (u8 *)e->addr); |
| 4561 | break; |
| 4562 | } |
| 4563 | |
| 4564 | return 0; |
| 4565 | } |
| 4566 | |
Arend van Spriel | 89c2f38 | 2013-08-10 12:27:25 +0200 | [diff] [blame] | 4567 | static int brcmf_convert_nl80211_tdls_oper(enum nl80211_tdls_operation oper) |
| 4568 | { |
| 4569 | int ret; |
| 4570 | |
| 4571 | switch (oper) { |
| 4572 | case NL80211_TDLS_DISCOVERY_REQ: |
| 4573 | ret = BRCMF_TDLS_MANUAL_EP_DISCOVERY; |
| 4574 | break; |
| 4575 | case NL80211_TDLS_SETUP: |
| 4576 | ret = BRCMF_TDLS_MANUAL_EP_CREATE; |
| 4577 | break; |
| 4578 | case NL80211_TDLS_TEARDOWN: |
| 4579 | ret = BRCMF_TDLS_MANUAL_EP_DELETE; |
| 4580 | break; |
| 4581 | default: |
| 4582 | brcmf_err("unsupported operation: %d\n", oper); |
| 4583 | ret = -EOPNOTSUPP; |
| 4584 | } |
| 4585 | return ret; |
| 4586 | } |
| 4587 | |
| 4588 | static int brcmf_cfg80211_tdls_oper(struct wiphy *wiphy, |
Johannes Berg | 3b3a016 | 2014-05-19 17:19:31 +0200 | [diff] [blame] | 4589 | struct net_device *ndev, const u8 *peer, |
Arend van Spriel | 89c2f38 | 2013-08-10 12:27:25 +0200 | [diff] [blame] | 4590 | enum nl80211_tdls_operation oper) |
| 4591 | { |
| 4592 | struct brcmf_if *ifp; |
| 4593 | struct brcmf_tdls_iovar_le info; |
| 4594 | int ret = 0; |
| 4595 | |
| 4596 | ret = brcmf_convert_nl80211_tdls_oper(oper); |
| 4597 | if (ret < 0) |
| 4598 | return ret; |
| 4599 | |
| 4600 | ifp = netdev_priv(ndev); |
| 4601 | memset(&info, 0, sizeof(info)); |
| 4602 | info.mode = (u8)ret; |
| 4603 | if (peer) |
| 4604 | memcpy(info.ea, peer, ETH_ALEN); |
| 4605 | |
| 4606 | ret = brcmf_fil_iovar_data_set(ifp, "tdls_endpoint", |
| 4607 | &info, sizeof(info)); |
| 4608 | if (ret < 0) |
| 4609 | brcmf_err("tdls_endpoint iovar failed: ret=%d\n", ret); |
| 4610 | |
| 4611 | return ret; |
| 4612 | } |
| 4613 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4614 | static struct cfg80211_ops wl_cfg80211_ops = { |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 4615 | .add_virtual_intf = brcmf_cfg80211_add_iface, |
| 4616 | .del_virtual_intf = brcmf_cfg80211_del_iface, |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4617 | .change_virtual_intf = brcmf_cfg80211_change_iface, |
| 4618 | .scan = brcmf_cfg80211_scan, |
| 4619 | .set_wiphy_params = brcmf_cfg80211_set_wiphy_params, |
| 4620 | .join_ibss = brcmf_cfg80211_join_ibss, |
| 4621 | .leave_ibss = brcmf_cfg80211_leave_ibss, |
| 4622 | .get_station = brcmf_cfg80211_get_station, |
| 4623 | .set_tx_power = brcmf_cfg80211_set_tx_power, |
| 4624 | .get_tx_power = brcmf_cfg80211_get_tx_power, |
| 4625 | .add_key = brcmf_cfg80211_add_key, |
| 4626 | .del_key = brcmf_cfg80211_del_key, |
| 4627 | .get_key = brcmf_cfg80211_get_key, |
| 4628 | .set_default_key = brcmf_cfg80211_config_default_key, |
| 4629 | .set_default_mgmt_key = brcmf_cfg80211_config_default_mgmt_key, |
| 4630 | .set_power_mgmt = brcmf_cfg80211_set_power_mgmt, |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4631 | .connect = brcmf_cfg80211_connect, |
| 4632 | .disconnect = brcmf_cfg80211_disconnect, |
| 4633 | .suspend = brcmf_cfg80211_suspend, |
| 4634 | .resume = brcmf_cfg80211_resume, |
| 4635 | .set_pmksa = brcmf_cfg80211_set_pmksa, |
| 4636 | .del_pmksa = brcmf_cfg80211_del_pmksa, |
Arend van Spriel | cbaa177 | 2012-08-30 19:43:02 +0200 | [diff] [blame] | 4637 | .flush_pmksa = brcmf_cfg80211_flush_pmksa, |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4638 | .start_ap = brcmf_cfg80211_start_ap, |
| 4639 | .stop_ap = brcmf_cfg80211_stop_ap, |
Hante Meuleman | a0f0795 | 2013-02-08 15:53:47 +0100 | [diff] [blame] | 4640 | .change_beacon = brcmf_cfg80211_change_beacon, |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4641 | .del_station = brcmf_cfg80211_del_station, |
Hante Meuleman | 6b89dcb | 2014-12-21 12:43:52 +0100 | [diff] [blame] | 4642 | .change_station = brcmf_cfg80211_change_station, |
Arend van Spriel | e580607 | 2012-09-19 22:21:08 +0200 | [diff] [blame] | 4643 | .sched_scan_start = brcmf_cfg80211_sched_scan_start, |
| 4644 | .sched_scan_stop = brcmf_cfg80211_sched_scan_stop, |
Hante Meuleman | 0de8aac | 2013-02-08 15:53:38 +0100 | [diff] [blame] | 4645 | .mgmt_frame_register = brcmf_cfg80211_mgmt_frame_register, |
| 4646 | .mgmt_tx = brcmf_cfg80211_mgmt_tx, |
| 4647 | .remain_on_channel = brcmf_p2p_remain_on_channel, |
| 4648 | .cancel_remain_on_channel = brcmf_cfg80211_cancel_remain_on_channel, |
Arend van Spriel | 27f10e3 | 2013-04-05 10:57:50 +0200 | [diff] [blame] | 4649 | .start_p2p_device = brcmf_p2p_start_device, |
| 4650 | .stop_p2p_device = brcmf_p2p_stop_device, |
Piotr Haber | 61730d4 | 2013-04-23 12:53:12 +0200 | [diff] [blame] | 4651 | .crit_proto_start = brcmf_cfg80211_crit_proto_start, |
| 4652 | .crit_proto_stop = brcmf_cfg80211_crit_proto_stop, |
Arend van Spriel | 89c2f38 | 2013-08-10 12:27:25 +0200 | [diff] [blame] | 4653 | .tdls_oper = brcmf_cfg80211_tdls_oper, |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4654 | }; |
| 4655 | |
Arend van Spriel | 3eacf86 | 2012-10-22 13:55:30 -0700 | [diff] [blame] | 4656 | 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] | 4657 | enum nl80211_iftype type, |
| 4658 | bool pm_block) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4659 | { |
Hante Meuleman | a44aa40 | 2014-12-03 21:05:33 +0100 | [diff] [blame] | 4660 | struct brcmf_cfg80211_vif *vif_walk; |
Arend van Spriel | 3eacf86 | 2012-10-22 13:55:30 -0700 | [diff] [blame] | 4661 | struct brcmf_cfg80211_vif *vif; |
Hante Meuleman | a44aa40 | 2014-12-03 21:05:33 +0100 | [diff] [blame] | 4662 | bool mbss; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4663 | |
Arend van Spriel | 33a6b15 | 2013-02-08 15:53:39 +0100 | [diff] [blame] | 4664 | brcmf_dbg(TRACE, "allocating virtual interface (size=%zu)\n", |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 4665 | sizeof(*vif)); |
Arend van Spriel | 3eacf86 | 2012-10-22 13:55:30 -0700 | [diff] [blame] | 4666 | vif = kzalloc(sizeof(*vif), GFP_KERNEL); |
| 4667 | if (!vif) |
| 4668 | return ERR_PTR(-ENOMEM); |
| 4669 | |
| 4670 | vif->wdev.wiphy = cfg->wiphy; |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 4671 | vif->wdev.iftype = type; |
Arend van Spriel | 3eacf86 | 2012-10-22 13:55:30 -0700 | [diff] [blame] | 4672 | |
Arend van Spriel | 3eacf86 | 2012-10-22 13:55:30 -0700 | [diff] [blame] | 4673 | vif->pm_block = pm_block; |
| 4674 | vif->roam_off = -1; |
| 4675 | |
Arend van Spriel | 6ac4f4e | 2012-10-22 13:55:31 -0700 | [diff] [blame] | 4676 | brcmf_init_prof(&vif->profile); |
| 4677 | |
Hante Meuleman | a44aa40 | 2014-12-03 21:05:33 +0100 | [diff] [blame] | 4678 | if (type == NL80211_IFTYPE_AP) { |
| 4679 | mbss = false; |
| 4680 | list_for_each_entry(vif_walk, &cfg->vif_list, list) { |
| 4681 | if (vif_walk->wdev.iftype == NL80211_IFTYPE_AP) { |
| 4682 | mbss = true; |
| 4683 | break; |
| 4684 | } |
| 4685 | } |
| 4686 | vif->mbss = mbss; |
| 4687 | } |
| 4688 | |
Arend van Spriel | 3eacf86 | 2012-10-22 13:55:30 -0700 | [diff] [blame] | 4689 | list_add_tail(&vif->list, &cfg->vif_list); |
Arend van Spriel | 3eacf86 | 2012-10-22 13:55:30 -0700 | [diff] [blame] | 4690 | return vif; |
| 4691 | } |
| 4692 | |
Arend van Spriel | 427dec5 | 2014-01-06 12:40:47 +0100 | [diff] [blame] | 4693 | void brcmf_free_vif(struct brcmf_cfg80211_vif *vif) |
Arend van Spriel | 3eacf86 | 2012-10-22 13:55:30 -0700 | [diff] [blame] | 4694 | { |
Arend van Spriel | 3eacf86 | 2012-10-22 13:55:30 -0700 | [diff] [blame] | 4695 | list_del(&vif->list); |
Arend van Spriel | 3eacf86 | 2012-10-22 13:55:30 -0700 | [diff] [blame] | 4696 | kfree(vif); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4697 | } |
| 4698 | |
Arend van Spriel | 9df4d54 | 2014-01-06 12:40:49 +0100 | [diff] [blame] | 4699 | void brcmf_cfg80211_free_netdev(struct net_device *ndev) |
| 4700 | { |
| 4701 | struct brcmf_cfg80211_vif *vif; |
| 4702 | struct brcmf_if *ifp; |
| 4703 | |
| 4704 | ifp = netdev_priv(ndev); |
| 4705 | vif = ifp->vif; |
| 4706 | |
Arend van Spriel | 95ef123 | 2015-08-26 22:15:04 +0200 | [diff] [blame] | 4707 | if (vif) |
| 4708 | brcmf_free_vif(vif); |
Arend van Spriel | 9df4d54 | 2014-01-06 12:40:49 +0100 | [diff] [blame] | 4709 | free_netdev(ndev); |
| 4710 | } |
| 4711 | |
Arend van Spriel | 903e0ee | 2012-11-28 21:44:11 +0100 | [diff] [blame] | 4712 | static bool brcmf_is_linkup(const struct brcmf_event_msg *e) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4713 | { |
Arend van Spriel | 5c36b99 | 2012-11-14 18:46:05 -0800 | [diff] [blame] | 4714 | u32 event = e->event_code; |
| 4715 | u32 status = e->status; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4716 | |
| 4717 | if (event == BRCMF_E_SET_SSID && status == BRCMF_E_STATUS_SUCCESS) { |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 4718 | brcmf_dbg(CONN, "Processing set ssid\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4719 | return true; |
| 4720 | } |
| 4721 | |
| 4722 | return false; |
| 4723 | } |
| 4724 | |
Arend van Spriel | 903e0ee | 2012-11-28 21:44:11 +0100 | [diff] [blame] | 4725 | static bool brcmf_is_linkdown(const struct brcmf_event_msg *e) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4726 | { |
Arend van Spriel | 5c36b99 | 2012-11-14 18:46:05 -0800 | [diff] [blame] | 4727 | u32 event = e->event_code; |
| 4728 | u16 flags = e->flags; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4729 | |
Hante Meuleman | 68ca395 | 2014-02-25 20:30:26 +0100 | [diff] [blame] | 4730 | if ((event == BRCMF_E_DEAUTH) || (event == BRCMF_E_DEAUTH_IND) || |
| 4731 | (event == BRCMF_E_DISASSOC_IND) || |
| 4732 | ((event == BRCMF_E_LINK) && (!(flags & BRCMF_EVENT_MSG_LINK)))) { |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 4733 | brcmf_dbg(CONN, "Processing link down\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4734 | return true; |
| 4735 | } |
| 4736 | return false; |
| 4737 | } |
| 4738 | |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 4739 | static bool brcmf_is_nonetwork(struct brcmf_cfg80211_info *cfg, |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4740 | const struct brcmf_event_msg *e) |
| 4741 | { |
Arend van Spriel | 5c36b99 | 2012-11-14 18:46:05 -0800 | [diff] [blame] | 4742 | u32 event = e->event_code; |
| 4743 | u32 status = e->status; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4744 | |
| 4745 | if (event == BRCMF_E_LINK && status == BRCMF_E_STATUS_NO_NETWORKS) { |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 4746 | brcmf_dbg(CONN, "Processing Link %s & no network found\n", |
| 4747 | e->flags & BRCMF_EVENT_MSG_LINK ? "up" : "down"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4748 | return true; |
| 4749 | } |
| 4750 | |
| 4751 | if (event == BRCMF_E_SET_SSID && status != BRCMF_E_STATUS_SUCCESS) { |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 4752 | brcmf_dbg(CONN, "Processing connecting & no network found\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4753 | return true; |
| 4754 | } |
| 4755 | |
| 4756 | return false; |
| 4757 | } |
| 4758 | |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 4759 | static void brcmf_clear_assoc_ies(struct brcmf_cfg80211_info *cfg) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4760 | { |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 4761 | struct brcmf_cfg80211_connect_info *conn_info = cfg_to_conn(cfg); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4762 | |
| 4763 | kfree(conn_info->req_ie); |
| 4764 | conn_info->req_ie = NULL; |
| 4765 | conn_info->req_ie_len = 0; |
| 4766 | kfree(conn_info->resp_ie); |
| 4767 | conn_info->resp_ie = NULL; |
| 4768 | conn_info->resp_ie_len = 0; |
| 4769 | } |
| 4770 | |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 4771 | static s32 brcmf_get_assoc_ies(struct brcmf_cfg80211_info *cfg, |
| 4772 | struct brcmf_if *ifp) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4773 | { |
Arend van Spriel | c4e382d | 2011-10-12 20:51:21 +0200 | [diff] [blame] | 4774 | struct brcmf_cfg80211_assoc_ielen_le *assoc_info; |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 4775 | struct brcmf_cfg80211_connect_info *conn_info = cfg_to_conn(cfg); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4776 | u32 req_len; |
| 4777 | u32 resp_len; |
| 4778 | s32 err = 0; |
| 4779 | |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 4780 | brcmf_clear_assoc_ies(cfg); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4781 | |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 4782 | err = brcmf_fil_iovar_data_get(ifp, "assoc_info", |
| 4783 | cfg->extra_buf, WL_ASSOC_INFO_MAX); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4784 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 4785 | brcmf_err("could not get assoc info (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4786 | return err; |
| 4787 | } |
Arend van Spriel | c4e382d | 2011-10-12 20:51:21 +0200 | [diff] [blame] | 4788 | assoc_info = |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 4789 | (struct brcmf_cfg80211_assoc_ielen_le *)cfg->extra_buf; |
Arend van Spriel | c4e382d | 2011-10-12 20:51:21 +0200 | [diff] [blame] | 4790 | req_len = le32_to_cpu(assoc_info->req_len); |
| 4791 | resp_len = le32_to_cpu(assoc_info->resp_len); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4792 | if (req_len) { |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 4793 | err = brcmf_fil_iovar_data_get(ifp, "assoc_req_ies", |
Hante Meuleman | 81f5dcb | 2012-10-22 10:36:14 -0700 | [diff] [blame] | 4794 | cfg->extra_buf, |
| 4795 | WL_ASSOC_INFO_MAX); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4796 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 4797 | brcmf_err("could not get assoc req (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4798 | return err; |
| 4799 | } |
| 4800 | conn_info->req_ie_len = req_len; |
| 4801 | conn_info->req_ie = |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 4802 | kmemdup(cfg->extra_buf, conn_info->req_ie_len, |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4803 | GFP_KERNEL); |
| 4804 | } else { |
| 4805 | conn_info->req_ie_len = 0; |
| 4806 | conn_info->req_ie = NULL; |
| 4807 | } |
| 4808 | if (resp_len) { |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 4809 | err = brcmf_fil_iovar_data_get(ifp, "assoc_resp_ies", |
Hante Meuleman | 81f5dcb | 2012-10-22 10:36:14 -0700 | [diff] [blame] | 4810 | cfg->extra_buf, |
| 4811 | WL_ASSOC_INFO_MAX); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4812 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 4813 | brcmf_err("could not get assoc resp (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4814 | return err; |
| 4815 | } |
| 4816 | conn_info->resp_ie_len = resp_len; |
| 4817 | conn_info->resp_ie = |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 4818 | kmemdup(cfg->extra_buf, conn_info->resp_ie_len, |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4819 | GFP_KERNEL); |
| 4820 | } else { |
| 4821 | conn_info->resp_ie_len = 0; |
| 4822 | conn_info->resp_ie = NULL; |
| 4823 | } |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 4824 | brcmf_dbg(CONN, "req len (%d) resp len (%d)\n", |
| 4825 | conn_info->req_ie_len, conn_info->resp_ie_len); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4826 | |
| 4827 | return err; |
| 4828 | } |
| 4829 | |
| 4830 | static s32 |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 4831 | brcmf_bss_roaming_done(struct brcmf_cfg80211_info *cfg, |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4832 | struct net_device *ndev, |
| 4833 | const struct brcmf_event_msg *e) |
| 4834 | { |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 4835 | struct brcmf_if *ifp = netdev_priv(ndev); |
| 4836 | struct brcmf_cfg80211_profile *profile = &ifp->vif->profile; |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 4837 | struct brcmf_cfg80211_connect_info *conn_info = cfg_to_conn(cfg); |
| 4838 | struct wiphy *wiphy = cfg_to_wiphy(cfg); |
Franky Lin | a180b83 | 2012-10-10 11:13:09 -0700 | [diff] [blame] | 4839 | struct ieee80211_channel *notify_channel = NULL; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4840 | struct ieee80211_supported_band *band; |
Franky Lin | a180b83 | 2012-10-10 11:13:09 -0700 | [diff] [blame] | 4841 | struct brcmf_bss_info_le *bi; |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 4842 | struct brcmu_chan ch; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4843 | u32 freq; |
| 4844 | s32 err = 0; |
Franky Lin | a180b83 | 2012-10-10 11:13:09 -0700 | [diff] [blame] | 4845 | u8 *buf; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4846 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 4847 | brcmf_dbg(TRACE, "Enter\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4848 | |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 4849 | brcmf_get_assoc_ies(cfg, ifp); |
Arend van Spriel | 6c8c4f7 | 2012-09-27 14:17:57 +0200 | [diff] [blame] | 4850 | memcpy(profile->bssid, e->addr, ETH_ALEN); |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 4851 | brcmf_update_bss_info(cfg, ifp); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4852 | |
Franky Lin | a180b83 | 2012-10-10 11:13:09 -0700 | [diff] [blame] | 4853 | buf = kzalloc(WL_BSS_INFO_MAX, GFP_KERNEL); |
| 4854 | if (buf == NULL) { |
| 4855 | err = -ENOMEM; |
| 4856 | goto done; |
| 4857 | } |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4858 | |
Franky Lin | a180b83 | 2012-10-10 11:13:09 -0700 | [diff] [blame] | 4859 | /* data sent to dongle has to be little endian */ |
| 4860 | *(__le32 *)buf = cpu_to_le32(WL_BSS_INFO_MAX); |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 4861 | 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] | 4862 | buf, WL_BSS_INFO_MAX); |
Franky Lin | a180b83 | 2012-10-10 11:13:09 -0700 | [diff] [blame] | 4863 | |
| 4864 | if (err) |
| 4865 | goto done; |
| 4866 | |
| 4867 | bi = (struct brcmf_bss_info_le *)(buf + 4); |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 4868 | ch.chspec = le16_to_cpu(bi->chanspec); |
| 4869 | cfg->d11inf.decchspec(&ch); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4870 | |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 4871 | if (ch.band == BRCMU_CHAN_BAND_2G) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4872 | band = wiphy->bands[IEEE80211_BAND_2GHZ]; |
| 4873 | else |
| 4874 | band = wiphy->bands[IEEE80211_BAND_5GHZ]; |
| 4875 | |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 4876 | freq = ieee80211_channel_to_frequency(ch.chnum, band->band); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4877 | notify_channel = ieee80211_get_channel(wiphy, freq); |
| 4878 | |
Franky Lin | a180b83 | 2012-10-10 11:13:09 -0700 | [diff] [blame] | 4879 | done: |
| 4880 | kfree(buf); |
Arend van Spriel | 06bb123 | 2012-09-27 14:17:56 +0200 | [diff] [blame] | 4881 | cfg80211_roamed(ndev, notify_channel, (u8 *)profile->bssid, |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4882 | conn_info->req_ie, conn_info->req_ie_len, |
| 4883 | conn_info->resp_ie, conn_info->resp_ie_len, GFP_KERNEL); |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 4884 | brcmf_dbg(CONN, "Report roaming result\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4885 | |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 4886 | set_bit(BRCMF_VIF_STATUS_CONNECTED, &ifp->vif->sme_state); |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 4887 | brcmf_dbg(TRACE, "Exit\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4888 | return err; |
| 4889 | } |
| 4890 | |
| 4891 | static s32 |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 4892 | brcmf_bss_connect_done(struct brcmf_cfg80211_info *cfg, |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4893 | struct net_device *ndev, const struct brcmf_event_msg *e, |
| 4894 | bool completed) |
| 4895 | { |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 4896 | struct brcmf_if *ifp = netdev_priv(ndev); |
| 4897 | struct brcmf_cfg80211_profile *profile = &ifp->vif->profile; |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 4898 | struct brcmf_cfg80211_connect_info *conn_info = cfg_to_conn(cfg); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4899 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 4900 | brcmf_dbg(TRACE, "Enter\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4901 | |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 4902 | if (test_and_clear_bit(BRCMF_VIF_STATUS_CONNECTING, |
| 4903 | &ifp->vif->sme_state)) { |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4904 | if (completed) { |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 4905 | brcmf_get_assoc_ies(cfg, ifp); |
Arend van Spriel | 6c8c4f7 | 2012-09-27 14:17:57 +0200 | [diff] [blame] | 4906 | memcpy(profile->bssid, e->addr, ETH_ALEN); |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 4907 | brcmf_update_bss_info(cfg, ifp); |
| 4908 | set_bit(BRCMF_VIF_STATUS_CONNECTED, |
| 4909 | &ifp->vif->sme_state); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4910 | } |
| 4911 | cfg80211_connect_result(ndev, |
Arend van Spriel | 06bb123 | 2012-09-27 14:17:56 +0200 | [diff] [blame] | 4912 | (u8 *)profile->bssid, |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4913 | conn_info->req_ie, |
| 4914 | conn_info->req_ie_len, |
| 4915 | conn_info->resp_ie, |
| 4916 | conn_info->resp_ie_len, |
| 4917 | completed ? WLAN_STATUS_SUCCESS : |
| 4918 | WLAN_STATUS_AUTH_TIMEOUT, |
| 4919 | GFP_KERNEL); |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 4920 | brcmf_dbg(CONN, "Report connect result - connection %s\n", |
| 4921 | completed ? "succeeded" : "failed"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4922 | } |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 4923 | brcmf_dbg(TRACE, "Exit\n"); |
Peter Senna Tschudin | 12f3237 | 2014-05-31 10:14:06 -0300 | [diff] [blame] | 4924 | return 0; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4925 | } |
| 4926 | |
| 4927 | static s32 |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 4928 | brcmf_notify_connect_status_ap(struct brcmf_cfg80211_info *cfg, |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4929 | struct net_device *ndev, |
| 4930 | const struct brcmf_event_msg *e, void *data) |
| 4931 | { |
Hante Meuleman | a44aa40 | 2014-12-03 21:05:33 +0100 | [diff] [blame] | 4932 | struct brcmf_if *ifp = netdev_priv(ndev); |
Hante Meuleman | 7ee2960 | 2013-02-06 18:40:43 +0100 | [diff] [blame] | 4933 | static int generation; |
Arend van Spriel | 5c36b99 | 2012-11-14 18:46:05 -0800 | [diff] [blame] | 4934 | u32 event = e->event_code; |
| 4935 | u32 reason = e->reason; |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4936 | struct station_info sinfo; |
| 4937 | |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 4938 | brcmf_dbg(CONN, "event %d, reason %d\n", event, reason); |
Arend van Spriel | 5f4f9f1 | 2013-02-08 15:53:41 +0100 | [diff] [blame] | 4939 | if (event == BRCMF_E_LINK && reason == BRCMF_E_REASON_LINK_BSSCFG_DIS && |
| 4940 | ndev != cfg_to_ndev(cfg)) { |
| 4941 | brcmf_dbg(CONN, "AP mode link down\n"); |
| 4942 | complete(&cfg->vif_disabled); |
Hante Meuleman | a44aa40 | 2014-12-03 21:05:33 +0100 | [diff] [blame] | 4943 | if (ifp->vif->mbss) |
Arend van Spriel | ee6e3a3 | 2015-08-26 22:14:55 +0200 | [diff] [blame] | 4944 | brcmf_remove_interface(ifp); |
Arend van Spriel | 5f4f9f1 | 2013-02-08 15:53:41 +0100 | [diff] [blame] | 4945 | return 0; |
| 4946 | } |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4947 | |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4948 | if (((event == BRCMF_E_ASSOC_IND) || (event == BRCMF_E_REASSOC_IND)) && |
Hante Meuleman | 7ee2960 | 2013-02-06 18:40:43 +0100 | [diff] [blame] | 4949 | (reason == BRCMF_E_STATUS_SUCCESS)) { |
| 4950 | memset(&sinfo, 0, sizeof(sinfo)); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4951 | if (!data) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 4952 | brcmf_err("No IEs present in ASSOC/REASSOC_IND"); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4953 | return -EINVAL; |
| 4954 | } |
| 4955 | sinfo.assoc_req_ies = data; |
Hante Meuleman | 7ee2960 | 2013-02-06 18:40:43 +0100 | [diff] [blame] | 4956 | sinfo.assoc_req_ies_len = e->datalen; |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4957 | generation++; |
| 4958 | sinfo.generation = generation; |
Hante Meuleman | 7ee2960 | 2013-02-06 18:40:43 +0100 | [diff] [blame] | 4959 | cfg80211_new_sta(ndev, e->addr, &sinfo, GFP_KERNEL); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4960 | } else if ((event == BRCMF_E_DISASSOC_IND) || |
| 4961 | (event == BRCMF_E_DEAUTH_IND) || |
| 4962 | (event == BRCMF_E_DEAUTH)) { |
Hante Meuleman | 7ee2960 | 2013-02-06 18:40:43 +0100 | [diff] [blame] | 4963 | cfg80211_del_sta(ndev, e->addr, GFP_KERNEL); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4964 | } |
Hante Meuleman | 7ee2960 | 2013-02-06 18:40:43 +0100 | [diff] [blame] | 4965 | return 0; |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4966 | } |
| 4967 | |
| 4968 | static s32 |
Arend van Spriel | 1993732 | 2012-11-05 16:22:32 -0800 | [diff] [blame] | 4969 | brcmf_notify_connect_status(struct brcmf_if *ifp, |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4970 | const struct brcmf_event_msg *e, void *data) |
| 4971 | { |
Arend van Spriel | 1993732 | 2012-11-05 16:22:32 -0800 | [diff] [blame] | 4972 | struct brcmf_cfg80211_info *cfg = ifp->drvr->config; |
| 4973 | struct net_device *ndev = ifp->ndev; |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 4974 | struct brcmf_cfg80211_profile *profile = &ifp->vif->profile; |
Antonio Quartulli | fe94f3a | 2014-01-29 17:53:43 +0100 | [diff] [blame] | 4975 | struct ieee80211_channel *chan; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4976 | s32 err = 0; |
| 4977 | |
Hante Meuleman | 8851cce | 2014-07-30 13:20:02 +0200 | [diff] [blame] | 4978 | if ((e->event_code == BRCMF_E_DEAUTH) || |
| 4979 | (e->event_code == BRCMF_E_DEAUTH_IND) || |
| 4980 | (e->event_code == BRCMF_E_DISASSOC_IND) || |
| 4981 | ((e->event_code == BRCMF_E_LINK) && (!e->flags))) { |
| 4982 | brcmf_proto_delete_peer(ifp->drvr, ifp->ifidx, (u8 *)e->addr); |
| 4983 | } |
| 4984 | |
Arend van Spriel | 967fe2c | 2014-03-15 17:18:21 +0100 | [diff] [blame] | 4985 | if (brcmf_is_apmode(ifp->vif)) { |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 4986 | err = brcmf_notify_connect_status_ap(cfg, ndev, e, data); |
Arend van Spriel | 903e0ee | 2012-11-28 21:44:11 +0100 | [diff] [blame] | 4987 | } else if (brcmf_is_linkup(e)) { |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 4988 | brcmf_dbg(CONN, "Linkup\n"); |
Arend van Spriel | 128ce3b | 2012-11-28 21:44:12 +0100 | [diff] [blame] | 4989 | if (brcmf_is_ibssmode(ifp->vif)) { |
Antonio Quartulli | fe94f3a | 2014-01-29 17:53:43 +0100 | [diff] [blame] | 4990 | chan = ieee80211_get_channel(cfg->wiphy, cfg->channel); |
Arend van Spriel | 6c8c4f7 | 2012-09-27 14:17:57 +0200 | [diff] [blame] | 4991 | memcpy(profile->bssid, e->addr, ETH_ALEN); |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 4992 | wl_inform_ibss(cfg, ndev, e->addr); |
Antonio Quartulli | fe94f3a | 2014-01-29 17:53:43 +0100 | [diff] [blame] | 4993 | cfg80211_ibss_joined(ndev, e->addr, chan, GFP_KERNEL); |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 4994 | clear_bit(BRCMF_VIF_STATUS_CONNECTING, |
| 4995 | &ifp->vif->sme_state); |
| 4996 | set_bit(BRCMF_VIF_STATUS_CONNECTED, |
| 4997 | &ifp->vif->sme_state); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4998 | } else |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 4999 | brcmf_bss_connect_done(cfg, ndev, e, true); |
Arend van Spriel | 903e0ee | 2012-11-28 21:44:11 +0100 | [diff] [blame] | 5000 | } else if (brcmf_is_linkdown(e)) { |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 5001 | brcmf_dbg(CONN, "Linkdown\n"); |
Arend van Spriel | 128ce3b | 2012-11-28 21:44:12 +0100 | [diff] [blame] | 5002 | if (!brcmf_is_ibssmode(ifp->vif)) { |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5003 | brcmf_bss_connect_done(cfg, ndev, e, false); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5004 | } |
Arend van Spriel | 9b7a0dd | 2015-01-25 20:31:33 +0100 | [diff] [blame] | 5005 | brcmf_link_down(ifp->vif, brcmf_map_fw_linkdown_reason(e)); |
Arend van Spriel | 6ac4f4e | 2012-10-22 13:55:31 -0700 | [diff] [blame] | 5006 | brcmf_init_prof(ndev_to_prof(ndev)); |
Arend van Spriel | 5f4f9f1 | 2013-02-08 15:53:41 +0100 | [diff] [blame] | 5007 | if (ndev != cfg_to_ndev(cfg)) |
| 5008 | complete(&cfg->vif_disabled); |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5009 | } else if (brcmf_is_nonetwork(cfg, e)) { |
Arend van Spriel | 128ce3b | 2012-11-28 21:44:12 +0100 | [diff] [blame] | 5010 | if (brcmf_is_ibssmode(ifp->vif)) |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 5011 | clear_bit(BRCMF_VIF_STATUS_CONNECTING, |
| 5012 | &ifp->vif->sme_state); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5013 | else |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5014 | brcmf_bss_connect_done(cfg, ndev, e, false); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5015 | } |
| 5016 | |
| 5017 | return err; |
| 5018 | } |
| 5019 | |
| 5020 | static s32 |
Arend van Spriel | 1993732 | 2012-11-05 16:22:32 -0800 | [diff] [blame] | 5021 | brcmf_notify_roaming_status(struct brcmf_if *ifp, |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5022 | const struct brcmf_event_msg *e, void *data) |
| 5023 | { |
Arend van Spriel | 1993732 | 2012-11-05 16:22:32 -0800 | [diff] [blame] | 5024 | struct brcmf_cfg80211_info *cfg = ifp->drvr->config; |
Arend van Spriel | 5c36b99 | 2012-11-14 18:46:05 -0800 | [diff] [blame] | 5025 | u32 event = e->event_code; |
| 5026 | u32 status = e->status; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5027 | |
| 5028 | if (event == BRCMF_E_ROAM && status == BRCMF_E_STATUS_SUCCESS) { |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 5029 | if (test_bit(BRCMF_VIF_STATUS_CONNECTED, &ifp->vif->sme_state)) |
Arend van Spriel | 1993732 | 2012-11-05 16:22:32 -0800 | [diff] [blame] | 5030 | brcmf_bss_roaming_done(cfg, ifp->ndev, e); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5031 | else |
Arend van Spriel | 1993732 | 2012-11-05 16:22:32 -0800 | [diff] [blame] | 5032 | brcmf_bss_connect_done(cfg, ifp->ndev, e, true); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5033 | } |
| 5034 | |
Peter Senna Tschudin | 12f3237 | 2014-05-31 10:14:06 -0300 | [diff] [blame] | 5035 | return 0; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5036 | } |
| 5037 | |
| 5038 | static s32 |
Arend van Spriel | 1993732 | 2012-11-05 16:22:32 -0800 | [diff] [blame] | 5039 | brcmf_notify_mic_status(struct brcmf_if *ifp, |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5040 | const struct brcmf_event_msg *e, void *data) |
| 5041 | { |
Arend van Spriel | 5c36b99 | 2012-11-14 18:46:05 -0800 | [diff] [blame] | 5042 | u16 flags = e->flags; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5043 | enum nl80211_key_type key_type; |
| 5044 | |
| 5045 | if (flags & BRCMF_EVENT_MSG_GROUP) |
| 5046 | key_type = NL80211_KEYTYPE_GROUP; |
| 5047 | else |
| 5048 | key_type = NL80211_KEYTYPE_PAIRWISE; |
| 5049 | |
Arend van Spriel | 1993732 | 2012-11-05 16:22:32 -0800 | [diff] [blame] | 5050 | 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] | 5051 | NULL, GFP_KERNEL); |
| 5052 | |
| 5053 | return 0; |
| 5054 | } |
| 5055 | |
Arend van Spriel | d3c0b63 | 2013-02-08 15:53:37 +0100 | [diff] [blame] | 5056 | static s32 brcmf_notify_vif_event(struct brcmf_if *ifp, |
| 5057 | const struct brcmf_event_msg *e, void *data) |
| 5058 | { |
| 5059 | struct brcmf_cfg80211_info *cfg = ifp->drvr->config; |
| 5060 | struct brcmf_if_event *ifevent = (struct brcmf_if_event *)data; |
| 5061 | struct brcmf_cfg80211_vif_event *event = &cfg->vif_event; |
| 5062 | struct brcmf_cfg80211_vif *vif; |
| 5063 | |
| 5064 | brcmf_dbg(TRACE, "Enter: action %u flags %u ifidx %u bsscfg %u\n", |
| 5065 | ifevent->action, ifevent->flags, ifevent->ifidx, |
| 5066 | ifevent->bssidx); |
| 5067 | |
Arend van Spriel | d3c0b63 | 2013-02-08 15:53:37 +0100 | [diff] [blame] | 5068 | mutex_lock(&event->vif_event_lock); |
| 5069 | event->action = ifevent->action; |
| 5070 | vif = event->vif; |
| 5071 | |
| 5072 | switch (ifevent->action) { |
| 5073 | case BRCMF_E_IF_ADD: |
| 5074 | /* waiting process may have timed out */ |
Wei Yongjun | dc4a787 | 2013-02-22 21:32:20 +0800 | [diff] [blame] | 5075 | if (!cfg->vif_event.vif) { |
| 5076 | mutex_unlock(&event->vif_event_lock); |
Arend van Spriel | d3c0b63 | 2013-02-08 15:53:37 +0100 | [diff] [blame] | 5077 | return -EBADF; |
Wei Yongjun | dc4a787 | 2013-02-22 21:32:20 +0800 | [diff] [blame] | 5078 | } |
Arend van Spriel | d3c0b63 | 2013-02-08 15:53:37 +0100 | [diff] [blame] | 5079 | |
| 5080 | ifp->vif = vif; |
| 5081 | vif->ifp = ifp; |
Arend van Spriel | 01b8e7d | 2013-04-05 10:57:51 +0200 | [diff] [blame] | 5082 | if (ifp->ndev) { |
| 5083 | vif->wdev.netdev = ifp->ndev; |
| 5084 | ifp->ndev->ieee80211_ptr = &vif->wdev; |
| 5085 | SET_NETDEV_DEV(ifp->ndev, wiphy_dev(cfg->wiphy)); |
| 5086 | } |
Arend van Spriel | d3c0b63 | 2013-02-08 15:53:37 +0100 | [diff] [blame] | 5087 | mutex_unlock(&event->vif_event_lock); |
| 5088 | wake_up(&event->vif_wq); |
Hante Meuleman | 4b3a89d | 2013-02-08 15:54:01 +0100 | [diff] [blame] | 5089 | return 0; |
Arend van Spriel | d3c0b63 | 2013-02-08 15:53:37 +0100 | [diff] [blame] | 5090 | |
| 5091 | case BRCMF_E_IF_DEL: |
Arend van Spriel | d3c0b63 | 2013-02-08 15:53:37 +0100 | [diff] [blame] | 5092 | mutex_unlock(&event->vif_event_lock); |
| 5093 | /* event may not be upon user request */ |
| 5094 | if (brcmf_cfg80211_vif_event_armed(cfg)) |
| 5095 | wake_up(&event->vif_wq); |
| 5096 | return 0; |
| 5097 | |
Hante Meuleman | 7a5c1f6 | 2013-02-08 15:53:44 +0100 | [diff] [blame] | 5098 | case BRCMF_E_IF_CHANGE: |
| 5099 | mutex_unlock(&event->vif_event_lock); |
| 5100 | wake_up(&event->vif_wq); |
| 5101 | return 0; |
| 5102 | |
Arend van Spriel | d3c0b63 | 2013-02-08 15:53:37 +0100 | [diff] [blame] | 5103 | default: |
| 5104 | mutex_unlock(&event->vif_event_lock); |
| 5105 | break; |
| 5106 | } |
| 5107 | return -EINVAL; |
| 5108 | } |
| 5109 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5110 | static void brcmf_init_conf(struct brcmf_cfg80211_conf *conf) |
| 5111 | { |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5112 | conf->frag_threshold = (u32)-1; |
| 5113 | conf->rts_threshold = (u32)-1; |
| 5114 | conf->retry_short = (u32)-1; |
| 5115 | conf->retry_long = (u32)-1; |
| 5116 | conf->tx_power = -1; |
| 5117 | } |
| 5118 | |
Arend van Spriel | 5c36b99 | 2012-11-14 18:46:05 -0800 | [diff] [blame] | 5119 | static void brcmf_register_event_handlers(struct brcmf_cfg80211_info *cfg) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5120 | { |
Arend van Spriel | 5c36b99 | 2012-11-14 18:46:05 -0800 | [diff] [blame] | 5121 | brcmf_fweh_register(cfg->pub, BRCMF_E_LINK, |
| 5122 | brcmf_notify_connect_status); |
| 5123 | brcmf_fweh_register(cfg->pub, BRCMF_E_DEAUTH_IND, |
| 5124 | brcmf_notify_connect_status); |
| 5125 | brcmf_fweh_register(cfg->pub, BRCMF_E_DEAUTH, |
| 5126 | brcmf_notify_connect_status); |
| 5127 | brcmf_fweh_register(cfg->pub, BRCMF_E_DISASSOC_IND, |
| 5128 | brcmf_notify_connect_status); |
| 5129 | brcmf_fweh_register(cfg->pub, BRCMF_E_ASSOC_IND, |
| 5130 | brcmf_notify_connect_status); |
| 5131 | brcmf_fweh_register(cfg->pub, BRCMF_E_REASSOC_IND, |
| 5132 | brcmf_notify_connect_status); |
| 5133 | brcmf_fweh_register(cfg->pub, BRCMF_E_ROAM, |
| 5134 | brcmf_notify_roaming_status); |
| 5135 | brcmf_fweh_register(cfg->pub, BRCMF_E_MIC_ERROR, |
| 5136 | brcmf_notify_mic_status); |
| 5137 | brcmf_fweh_register(cfg->pub, BRCMF_E_SET_SSID, |
| 5138 | brcmf_notify_connect_status); |
| 5139 | brcmf_fweh_register(cfg->pub, BRCMF_E_PFN_NET_FOUND, |
| 5140 | brcmf_notify_sched_scan_results); |
Arend van Spriel | d3c0b63 | 2013-02-08 15:53:37 +0100 | [diff] [blame] | 5141 | brcmf_fweh_register(cfg->pub, BRCMF_E_IF, |
| 5142 | brcmf_notify_vif_event); |
Hante Meuleman | 0de8aac | 2013-02-08 15:53:38 +0100 | [diff] [blame] | 5143 | brcmf_fweh_register(cfg->pub, BRCMF_E_P2P_PROBEREQ_MSG, |
Hante Meuleman | 6eda4e2 | 2013-02-08 15:54:02 +0100 | [diff] [blame] | 5144 | brcmf_p2p_notify_rx_mgmt_p2p_probereq); |
Hante Meuleman | 0de8aac | 2013-02-08 15:53:38 +0100 | [diff] [blame] | 5145 | brcmf_fweh_register(cfg->pub, BRCMF_E_P2P_DISC_LISTEN_COMPLETE, |
| 5146 | brcmf_p2p_notify_listen_complete); |
Hante Meuleman | e6da340 | 2013-02-08 15:53:48 +0100 | [diff] [blame] | 5147 | brcmf_fweh_register(cfg->pub, BRCMF_E_ACTION_FRAME_RX, |
| 5148 | brcmf_p2p_notify_action_frame_rx); |
Hante Meuleman | 18e2f61 | 2013-02-08 15:53:49 +0100 | [diff] [blame] | 5149 | brcmf_fweh_register(cfg->pub, BRCMF_E_ACTION_FRAME_COMPLETE, |
| 5150 | brcmf_p2p_notify_action_tx_complete); |
Hante Meuleman | 6eda4e2 | 2013-02-08 15:54:02 +0100 | [diff] [blame] | 5151 | brcmf_fweh_register(cfg->pub, BRCMF_E_ACTION_FRAME_OFF_CHAN_COMPLETE, |
| 5152 | brcmf_p2p_notify_action_tx_complete); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5153 | } |
| 5154 | |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5155 | static void brcmf_deinit_priv_mem(struct brcmf_cfg80211_info *cfg) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5156 | { |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5157 | kfree(cfg->conf); |
| 5158 | cfg->conf = NULL; |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5159 | kfree(cfg->escan_ioctl_buf); |
| 5160 | cfg->escan_ioctl_buf = NULL; |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5161 | kfree(cfg->extra_buf); |
| 5162 | cfg->extra_buf = NULL; |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5163 | kfree(cfg->pmk_list); |
| 5164 | cfg->pmk_list = NULL; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5165 | } |
| 5166 | |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5167 | static s32 brcmf_init_priv_mem(struct brcmf_cfg80211_info *cfg) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5168 | { |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5169 | cfg->conf = kzalloc(sizeof(*cfg->conf), GFP_KERNEL); |
| 5170 | if (!cfg->conf) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5171 | goto init_priv_mem_out; |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5172 | cfg->escan_ioctl_buf = kzalloc(BRCMF_DCMD_MEDLEN, GFP_KERNEL); |
| 5173 | if (!cfg->escan_ioctl_buf) |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 5174 | goto init_priv_mem_out; |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5175 | cfg->extra_buf = kzalloc(WL_EXTRA_BUF_MAX, GFP_KERNEL); |
| 5176 | if (!cfg->extra_buf) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5177 | goto init_priv_mem_out; |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5178 | cfg->pmk_list = kzalloc(sizeof(*cfg->pmk_list), GFP_KERNEL); |
| 5179 | if (!cfg->pmk_list) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5180 | goto init_priv_mem_out; |
| 5181 | |
| 5182 | return 0; |
| 5183 | |
| 5184 | init_priv_mem_out: |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5185 | brcmf_deinit_priv_mem(cfg); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5186 | |
| 5187 | return -ENOMEM; |
| 5188 | } |
| 5189 | |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5190 | static s32 wl_init_priv(struct brcmf_cfg80211_info *cfg) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5191 | { |
| 5192 | s32 err = 0; |
| 5193 | |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5194 | cfg->scan_request = NULL; |
| 5195 | cfg->pwr_save = true; |
Hante Meuleman | 68ca395 | 2014-02-25 20:30:26 +0100 | [diff] [blame] | 5196 | cfg->active_scan = true; /* we do active scan per default */ |
| 5197 | cfg->dongle_up = false; /* dongle is not up yet */ |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5198 | err = brcmf_init_priv_mem(cfg); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5199 | if (err) |
| 5200 | return err; |
Arend van Spriel | 5c36b99 | 2012-11-14 18:46:05 -0800 | [diff] [blame] | 5201 | brcmf_register_event_handlers(cfg); |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5202 | mutex_init(&cfg->usr_sync); |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5203 | brcmf_init_escan(cfg); |
| 5204 | brcmf_init_conf(cfg->conf); |
Arend van Spriel | 5f4f9f1 | 2013-02-08 15:53:41 +0100 | [diff] [blame] | 5205 | init_completion(&cfg->vif_disabled); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5206 | return err; |
| 5207 | } |
| 5208 | |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5209 | static void wl_deinit_priv(struct brcmf_cfg80211_info *cfg) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5210 | { |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5211 | cfg->dongle_up = false; /* dongle down */ |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5212 | brcmf_abort_scanning(cfg); |
| 5213 | brcmf_deinit_priv_mem(cfg); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5214 | } |
| 5215 | |
Arend van Spriel | d3c0b63 | 2013-02-08 15:53:37 +0100 | [diff] [blame] | 5216 | static void init_vif_event(struct brcmf_cfg80211_vif_event *event) |
| 5217 | { |
| 5218 | init_waitqueue_head(&event->vif_wq); |
Arend van Spriel | d3c0b63 | 2013-02-08 15:53:37 +0100 | [diff] [blame] | 5219 | mutex_init(&event->vif_event_lock); |
| 5220 | } |
| 5221 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5222 | static s32 |
Hante Meuleman | 68ca395 | 2014-02-25 20:30:26 +0100 | [diff] [blame] | 5223 | brcmf_dongle_roam(struct brcmf_if *ifp, u32 bcn_timeout) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5224 | { |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5225 | s32 err = 0; |
Arend van Spriel | f588bc0 | 2011-10-12 20:51:22 +0200 | [diff] [blame] | 5226 | __le32 roamtrigger[2]; |
| 5227 | __le32 roam_delta[2]; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5228 | |
| 5229 | /* |
| 5230 | * Setup timeout if Beacons are lost and roam is |
| 5231 | * off to report link down |
| 5232 | */ |
Hante Meuleman | 68ca395 | 2014-02-25 20:30:26 +0100 | [diff] [blame] | 5233 | if (brcmf_roamoff) { |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 5234 | err = brcmf_fil_iovar_int_set(ifp, "bcn_timeout", bcn_timeout); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5235 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 5236 | brcmf_err("bcn_timeout error (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5237 | goto dongle_rom_out; |
| 5238 | } |
| 5239 | } |
| 5240 | |
| 5241 | /* |
| 5242 | * Enable/Disable built-in roaming to allow supplicant |
| 5243 | * to take care of roaming |
| 5244 | */ |
Hante Meuleman | 68ca395 | 2014-02-25 20:30:26 +0100 | [diff] [blame] | 5245 | brcmf_dbg(INFO, "Internal Roaming = %s\n", |
| 5246 | brcmf_roamoff ? "Off" : "On"); |
| 5247 | err = brcmf_fil_iovar_int_set(ifp, "roam_off", !!(brcmf_roamoff)); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5248 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 5249 | brcmf_err("roam_off error (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5250 | goto dongle_rom_out; |
| 5251 | } |
| 5252 | |
Arend van Spriel | f588bc0 | 2011-10-12 20:51:22 +0200 | [diff] [blame] | 5253 | roamtrigger[0] = cpu_to_le32(WL_ROAM_TRIGGER_LEVEL); |
| 5254 | roamtrigger[1] = cpu_to_le32(BRCM_BAND_ALL); |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 5255 | err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SET_ROAM_TRIGGER, |
Hante Meuleman | 81f5dcb | 2012-10-22 10:36:14 -0700 | [diff] [blame] | 5256 | (void *)roamtrigger, sizeof(roamtrigger)); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5257 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 5258 | brcmf_err("WLC_SET_ROAM_TRIGGER error (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5259 | goto dongle_rom_out; |
| 5260 | } |
| 5261 | |
Arend van Spriel | f588bc0 | 2011-10-12 20:51:22 +0200 | [diff] [blame] | 5262 | roam_delta[0] = cpu_to_le32(WL_ROAM_DELTA); |
| 5263 | roam_delta[1] = cpu_to_le32(BRCM_BAND_ALL); |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 5264 | err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SET_ROAM_DELTA, |
Hante Meuleman | 81f5dcb | 2012-10-22 10:36:14 -0700 | [diff] [blame] | 5265 | (void *)roam_delta, sizeof(roam_delta)); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5266 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 5267 | brcmf_err("WLC_SET_ROAM_DELTA error (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5268 | goto dongle_rom_out; |
| 5269 | } |
| 5270 | |
| 5271 | dongle_rom_out: |
| 5272 | return err; |
| 5273 | } |
| 5274 | |
| 5275 | static s32 |
Hante Meuleman | 40a2329 | 2013-01-02 15:22:51 +0100 | [diff] [blame] | 5276 | brcmf_dongle_scantime(struct brcmf_if *ifp, s32 scan_assoc_time, |
Arend van Spriel | c68cdc0 | 2011-10-12 20:51:23 +0200 | [diff] [blame] | 5277 | s32 scan_unassoc_time, s32 scan_passive_time) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5278 | { |
| 5279 | s32 err = 0; |
| 5280 | |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 5281 | err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_SCAN_CHANNEL_TIME, |
Hante Meuleman | 81f5dcb | 2012-10-22 10:36:14 -0700 | [diff] [blame] | 5282 | scan_assoc_time); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5283 | if (err) { |
| 5284 | if (err == -EOPNOTSUPP) |
Arend van Spriel | 647c9ae | 2012-12-05 15:26:01 +0100 | [diff] [blame] | 5285 | brcmf_dbg(INFO, "Scan assoc time is not supported\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5286 | else |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 5287 | brcmf_err("Scan assoc time error (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5288 | goto dongle_scantime_out; |
| 5289 | } |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 5290 | err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_SCAN_UNASSOC_TIME, |
Hante Meuleman | 81f5dcb | 2012-10-22 10:36:14 -0700 | [diff] [blame] | 5291 | scan_unassoc_time); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5292 | if (err) { |
| 5293 | if (err == -EOPNOTSUPP) |
Arend van Spriel | 647c9ae | 2012-12-05 15:26:01 +0100 | [diff] [blame] | 5294 | brcmf_dbg(INFO, "Scan unassoc time is not supported\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5295 | else |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 5296 | brcmf_err("Scan unassoc time error (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5297 | goto dongle_scantime_out; |
| 5298 | } |
| 5299 | |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 5300 | err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_SCAN_PASSIVE_TIME, |
Hante Meuleman | 81f5dcb | 2012-10-22 10:36:14 -0700 | [diff] [blame] | 5301 | scan_passive_time); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5302 | if (err) { |
| 5303 | if (err == -EOPNOTSUPP) |
Arend van Spriel | 647c9ae | 2012-12-05 15:26:01 +0100 | [diff] [blame] | 5304 | brcmf_dbg(INFO, "Scan passive time is not supported\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5305 | else |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 5306 | brcmf_err("Scan passive time error (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5307 | goto dongle_scantime_out; |
| 5308 | } |
| 5309 | |
| 5310 | dongle_scantime_out: |
| 5311 | return err; |
| 5312 | } |
| 5313 | |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 5314 | static void brcmf_update_bw40_channel_flag(struct ieee80211_channel *channel, |
| 5315 | struct brcmu_chan *ch) |
| 5316 | { |
| 5317 | u32 ht40_flag; |
| 5318 | |
| 5319 | ht40_flag = channel->flags & IEEE80211_CHAN_NO_HT40; |
| 5320 | if (ch->sb == BRCMU_CHAN_SB_U) { |
| 5321 | if (ht40_flag == IEEE80211_CHAN_NO_HT40) |
| 5322 | channel->flags &= ~IEEE80211_CHAN_NO_HT40; |
| 5323 | channel->flags |= IEEE80211_CHAN_NO_HT40PLUS; |
| 5324 | } else { |
| 5325 | /* It should be one of |
| 5326 | * IEEE80211_CHAN_NO_HT40 or |
| 5327 | * IEEE80211_CHAN_NO_HT40PLUS |
| 5328 | */ |
| 5329 | channel->flags &= ~IEEE80211_CHAN_NO_HT40; |
| 5330 | if (ht40_flag == IEEE80211_CHAN_NO_HT40) |
| 5331 | channel->flags |= IEEE80211_CHAN_NO_HT40MINUS; |
| 5332 | } |
| 5333 | } |
| 5334 | |
| 5335 | static int brcmf_construct_chaninfo(struct brcmf_cfg80211_info *cfg, |
| 5336 | u32 bw_cap[]) |
Hante Meuleman | d48200b | 2013-04-03 12:40:29 +0200 | [diff] [blame] | 5337 | { |
| 5338 | struct brcmf_if *ifp = netdev_priv(cfg_to_ndev(cfg)); |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 5339 | struct ieee80211_supported_band *band; |
| 5340 | struct ieee80211_channel *channel; |
| 5341 | struct wiphy *wiphy; |
Hante Meuleman | d48200b | 2013-04-03 12:40:29 +0200 | [diff] [blame] | 5342 | struct brcmf_chanspec_list *list; |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 5343 | struct brcmu_chan ch; |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 5344 | int err; |
Hante Meuleman | d48200b | 2013-04-03 12:40:29 +0200 | [diff] [blame] | 5345 | u8 *pbuf; |
| 5346 | u32 i, j; |
| 5347 | u32 total; |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 5348 | u32 chaninfo; |
Hante Meuleman | d48200b | 2013-04-03 12:40:29 +0200 | [diff] [blame] | 5349 | u32 index; |
Hante Meuleman | d48200b | 2013-04-03 12:40:29 +0200 | [diff] [blame] | 5350 | |
| 5351 | pbuf = kzalloc(BRCMF_DCMD_MEDLEN, GFP_KERNEL); |
| 5352 | |
| 5353 | if (pbuf == NULL) |
| 5354 | return -ENOMEM; |
| 5355 | |
| 5356 | list = (struct brcmf_chanspec_list *)pbuf; |
| 5357 | |
| 5358 | err = brcmf_fil_iovar_data_get(ifp, "chanspecs", pbuf, |
| 5359 | BRCMF_DCMD_MEDLEN); |
| 5360 | if (err) { |
| 5361 | brcmf_err("get chanspecs error (%d)\n", err); |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 5362 | goto fail_pbuf; |
Hante Meuleman | d48200b | 2013-04-03 12:40:29 +0200 | [diff] [blame] | 5363 | } |
| 5364 | |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 5365 | wiphy = cfg_to_wiphy(cfg); |
Arend van Spriel | 58de92d | 2015-04-14 20:10:24 +0200 | [diff] [blame] | 5366 | band = wiphy->bands[IEEE80211_BAND_2GHZ]; |
| 5367 | if (band) |
| 5368 | for (i = 0; i < band->n_channels; i++) |
| 5369 | band->channels[i].flags = IEEE80211_CHAN_DISABLED; |
| 5370 | band = wiphy->bands[IEEE80211_BAND_5GHZ]; |
| 5371 | if (band) |
| 5372 | for (i = 0; i < band->n_channels; i++) |
| 5373 | band->channels[i].flags = IEEE80211_CHAN_DISABLED; |
Hante Meuleman | d48200b | 2013-04-03 12:40:29 +0200 | [diff] [blame] | 5374 | |
| 5375 | total = le32_to_cpu(list->count); |
| 5376 | for (i = 0; i < total; i++) { |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 5377 | ch.chspec = (u16)le32_to_cpu(list->element[i]); |
| 5378 | cfg->d11inf.decchspec(&ch); |
Hante Meuleman | d48200b | 2013-04-03 12:40:29 +0200 | [diff] [blame] | 5379 | |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 5380 | if (ch.band == BRCMU_CHAN_BAND_2G) { |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 5381 | band = wiphy->bands[IEEE80211_BAND_2GHZ]; |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 5382 | } else if (ch.band == BRCMU_CHAN_BAND_5G) { |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 5383 | band = wiphy->bands[IEEE80211_BAND_5GHZ]; |
Hante Meuleman | d48200b | 2013-04-03 12:40:29 +0200 | [diff] [blame] | 5384 | } else { |
Arend van Spriel | 2375d97 | 2014-01-06 12:40:41 +0100 | [diff] [blame] | 5385 | brcmf_err("Invalid channel Spec. 0x%x.\n", ch.chspec); |
Hante Meuleman | d48200b | 2013-04-03 12:40:29 +0200 | [diff] [blame] | 5386 | continue; |
| 5387 | } |
Arend van Spriel | 58de92d | 2015-04-14 20:10:24 +0200 | [diff] [blame] | 5388 | if (!band) |
| 5389 | continue; |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 5390 | if (!(bw_cap[band->band] & WLC_BW_40MHZ_BIT) && |
Arend van Spriel | 2375d97 | 2014-01-06 12:40:41 +0100 | [diff] [blame] | 5391 | ch.bw == BRCMU_CHAN_BW_40) |
Hante Meuleman | d48200b | 2013-04-03 12:40:29 +0200 | [diff] [blame] | 5392 | continue; |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 5393 | if (!(bw_cap[band->band] & WLC_BW_80MHZ_BIT) && |
Arend van Spriel | ee942ec | 2014-05-12 10:47:38 +0200 | [diff] [blame] | 5394 | ch.bw == BRCMU_CHAN_BW_80) |
| 5395 | continue; |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 5396 | |
| 5397 | channel = band->channels; |
| 5398 | index = band->n_channels; |
| 5399 | for (j = 0; j < band->n_channels; j++) { |
| 5400 | if (channel[j].hw_value == ch.chnum) { |
| 5401 | index = j; |
Hante Meuleman | d48200b | 2013-04-03 12:40:29 +0200 | [diff] [blame] | 5402 | break; |
| 5403 | } |
| 5404 | } |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 5405 | channel[index].center_freq = |
| 5406 | ieee80211_channel_to_frequency(ch.chnum, band->band); |
| 5407 | channel[index].hw_value = ch.chnum; |
Hante Meuleman | d48200b | 2013-04-03 12:40:29 +0200 | [diff] [blame] | 5408 | |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 5409 | /* assuming the chanspecs order is HT20, |
| 5410 | * HT40 upper, HT40 lower, and VHT80. |
| 5411 | */ |
| 5412 | if (ch.bw == BRCMU_CHAN_BW_80) { |
| 5413 | channel[index].flags &= ~IEEE80211_CHAN_NO_80MHZ; |
| 5414 | } else if (ch.bw == BRCMU_CHAN_BW_40) { |
| 5415 | brcmf_update_bw40_channel_flag(&channel[index], &ch); |
| 5416 | } else { |
Arend van Spriel | 58de92d | 2015-04-14 20:10:24 +0200 | [diff] [blame] | 5417 | /* enable the channel and disable other bandwidths |
| 5418 | * for now as mentioned order assure they are enabled |
| 5419 | * for subsequent chanspecs. |
Arend van Spriel | ee942ec | 2014-05-12 10:47:38 +0200 | [diff] [blame] | 5420 | */ |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 5421 | channel[index].flags = IEEE80211_CHAN_NO_HT40 | |
| 5422 | IEEE80211_CHAN_NO_80MHZ; |
| 5423 | ch.bw = BRCMU_CHAN_BW_20; |
| 5424 | cfg->d11inf.encchspec(&ch); |
| 5425 | chaninfo = ch.chspec; |
| 5426 | err = brcmf_fil_bsscfg_int_get(ifp, "per_chan_info", |
| 5427 | &chaninfo); |
| 5428 | if (!err) { |
| 5429 | if (chaninfo & WL_CHAN_RADAR) |
| 5430 | channel[index].flags |= |
| 5431 | (IEEE80211_CHAN_RADAR | |
| 5432 | IEEE80211_CHAN_NO_IR); |
| 5433 | if (chaninfo & WL_CHAN_PASSIVE) |
| 5434 | channel[index].flags |= |
| 5435 | IEEE80211_CHAN_NO_IR; |
Hante Meuleman | d48200b | 2013-04-03 12:40:29 +0200 | [diff] [blame] | 5436 | } |
Hante Meuleman | d48200b | 2013-04-03 12:40:29 +0200 | [diff] [blame] | 5437 | } |
| 5438 | } |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 5439 | |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 5440 | fail_pbuf: |
Hante Meuleman | d48200b | 2013-04-03 12:40:29 +0200 | [diff] [blame] | 5441 | kfree(pbuf); |
| 5442 | return err; |
| 5443 | } |
| 5444 | |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 5445 | static int brcmf_enable_bw40_2g(struct brcmf_cfg80211_info *cfg) |
Arend van Spriel | aa70b4f | 2014-07-12 08:49:40 +0200 | [diff] [blame] | 5446 | { |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 5447 | struct brcmf_if *ifp = netdev_priv(cfg_to_ndev(cfg)); |
| 5448 | struct ieee80211_supported_band *band; |
Arend van Spriel | aa70b4f | 2014-07-12 08:49:40 +0200 | [diff] [blame] | 5449 | struct brcmf_fil_bwcap_le band_bwcap; |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 5450 | struct brcmf_chanspec_list *list; |
| 5451 | u8 *pbuf; |
Arend van Spriel | aa70b4f | 2014-07-12 08:49:40 +0200 | [diff] [blame] | 5452 | u32 val; |
| 5453 | int err; |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 5454 | struct brcmu_chan ch; |
| 5455 | u32 num_chan; |
| 5456 | int i, j; |
Arend van Spriel | aa70b4f | 2014-07-12 08:49:40 +0200 | [diff] [blame] | 5457 | |
| 5458 | /* verify support for bw_cap command */ |
| 5459 | val = WLC_BAND_5G; |
| 5460 | err = brcmf_fil_iovar_int_get(ifp, "bw_cap", &val); |
| 5461 | |
| 5462 | if (!err) { |
| 5463 | /* only set 2G bandwidth using bw_cap command */ |
| 5464 | band_bwcap.band = cpu_to_le32(WLC_BAND_2G); |
| 5465 | band_bwcap.bw_cap = cpu_to_le32(WLC_BW_CAP_40MHZ); |
| 5466 | err = brcmf_fil_iovar_data_set(ifp, "bw_cap", &band_bwcap, |
| 5467 | sizeof(band_bwcap)); |
| 5468 | } else { |
| 5469 | brcmf_dbg(INFO, "fallback to mimo_bw_cap\n"); |
| 5470 | val = WLC_N_BW_40ALL; |
| 5471 | err = brcmf_fil_iovar_int_set(ifp, "mimo_bw_cap", val); |
| 5472 | } |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 5473 | |
| 5474 | if (!err) { |
| 5475 | /* update channel info in 2G band */ |
| 5476 | pbuf = kzalloc(BRCMF_DCMD_MEDLEN, GFP_KERNEL); |
| 5477 | |
| 5478 | if (pbuf == NULL) |
| 5479 | return -ENOMEM; |
| 5480 | |
| 5481 | ch.band = BRCMU_CHAN_BAND_2G; |
| 5482 | ch.bw = BRCMU_CHAN_BW_40; |
Hante Meuleman | fac7d2a | 2014-09-11 22:51:30 +0200 | [diff] [blame] | 5483 | ch.sb = BRCMU_CHAN_SB_NONE; |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 5484 | ch.chnum = 0; |
| 5485 | cfg->d11inf.encchspec(&ch); |
| 5486 | |
| 5487 | /* pass encoded chanspec in query */ |
| 5488 | *(__le16 *)pbuf = cpu_to_le16(ch.chspec); |
| 5489 | |
| 5490 | err = brcmf_fil_iovar_data_get(ifp, "chanspecs", pbuf, |
| 5491 | BRCMF_DCMD_MEDLEN); |
| 5492 | if (err) { |
| 5493 | brcmf_err("get chanspecs error (%d)\n", err); |
| 5494 | kfree(pbuf); |
| 5495 | return err; |
| 5496 | } |
| 5497 | |
| 5498 | band = cfg_to_wiphy(cfg)->bands[IEEE80211_BAND_2GHZ]; |
| 5499 | list = (struct brcmf_chanspec_list *)pbuf; |
| 5500 | num_chan = le32_to_cpu(list->count); |
| 5501 | for (i = 0; i < num_chan; i++) { |
| 5502 | ch.chspec = (u16)le32_to_cpu(list->element[i]); |
| 5503 | cfg->d11inf.decchspec(&ch); |
| 5504 | if (WARN_ON(ch.band != BRCMU_CHAN_BAND_2G)) |
| 5505 | continue; |
| 5506 | if (WARN_ON(ch.bw != BRCMU_CHAN_BW_40)) |
| 5507 | continue; |
| 5508 | for (j = 0; j < band->n_channels; j++) { |
| 5509 | if (band->channels[j].hw_value == ch.chnum) |
| 5510 | break; |
| 5511 | } |
| 5512 | if (WARN_ON(j == band->n_channels)) |
| 5513 | continue; |
| 5514 | |
| 5515 | brcmf_update_bw40_channel_flag(&band->channels[j], &ch); |
| 5516 | } |
Hante Meuleman | fac7d2a | 2014-09-11 22:51:30 +0200 | [diff] [blame] | 5517 | kfree(pbuf); |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 5518 | } |
Arend van Spriel | aa70b4f | 2014-07-12 08:49:40 +0200 | [diff] [blame] | 5519 | return err; |
| 5520 | } |
| 5521 | |
Arend van Spriel | 2375d97 | 2014-01-06 12:40:41 +0100 | [diff] [blame] | 5522 | static void brcmf_get_bwcap(struct brcmf_if *ifp, u32 bw_cap[]) |
| 5523 | { |
| 5524 | u32 band, mimo_bwcap; |
| 5525 | int err; |
| 5526 | |
| 5527 | band = WLC_BAND_2G; |
| 5528 | err = brcmf_fil_iovar_int_get(ifp, "bw_cap", &band); |
| 5529 | if (!err) { |
| 5530 | bw_cap[IEEE80211_BAND_2GHZ] = band; |
| 5531 | band = WLC_BAND_5G; |
| 5532 | err = brcmf_fil_iovar_int_get(ifp, "bw_cap", &band); |
| 5533 | if (!err) { |
| 5534 | bw_cap[IEEE80211_BAND_5GHZ] = band; |
| 5535 | return; |
| 5536 | } |
| 5537 | WARN_ON(1); |
| 5538 | return; |
| 5539 | } |
| 5540 | brcmf_dbg(INFO, "fallback to mimo_bw_cap info\n"); |
| 5541 | mimo_bwcap = 0; |
| 5542 | err = brcmf_fil_iovar_int_get(ifp, "mimo_bw_cap", &mimo_bwcap); |
| 5543 | if (err) |
| 5544 | /* assume 20MHz if firmware does not give a clue */ |
| 5545 | mimo_bwcap = WLC_N_BW_20ALL; |
| 5546 | |
| 5547 | switch (mimo_bwcap) { |
| 5548 | case WLC_N_BW_40ALL: |
| 5549 | bw_cap[IEEE80211_BAND_2GHZ] |= WLC_BW_40MHZ_BIT; |
| 5550 | /* fall-thru */ |
| 5551 | case WLC_N_BW_20IN2G_40IN5G: |
| 5552 | bw_cap[IEEE80211_BAND_5GHZ] |= WLC_BW_40MHZ_BIT; |
| 5553 | /* fall-thru */ |
| 5554 | case WLC_N_BW_20ALL: |
| 5555 | bw_cap[IEEE80211_BAND_2GHZ] |= WLC_BW_20MHZ_BIT; |
| 5556 | bw_cap[IEEE80211_BAND_5GHZ] |= WLC_BW_20MHZ_BIT; |
| 5557 | break; |
| 5558 | default: |
| 5559 | brcmf_err("invalid mimo_bw_cap value\n"); |
| 5560 | } |
| 5561 | } |
Hante Meuleman | d48200b | 2013-04-03 12:40:29 +0200 | [diff] [blame] | 5562 | |
Arend van Spriel | 18d6c53 | 2014-05-12 10:47:35 +0200 | [diff] [blame] | 5563 | static void brcmf_update_ht_cap(struct ieee80211_supported_band *band, |
| 5564 | u32 bw_cap[2], u32 nchain) |
| 5565 | { |
| 5566 | band->ht_cap.ht_supported = true; |
| 5567 | if (bw_cap[band->band] & WLC_BW_40MHZ_BIT) { |
| 5568 | band->ht_cap.cap |= IEEE80211_HT_CAP_SGI_40; |
| 5569 | band->ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40; |
| 5570 | } |
| 5571 | band->ht_cap.cap |= IEEE80211_HT_CAP_SGI_20; |
| 5572 | band->ht_cap.cap |= IEEE80211_HT_CAP_DSSSCCK40; |
| 5573 | band->ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K; |
| 5574 | band->ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_16; |
| 5575 | memset(band->ht_cap.mcs.rx_mask, 0xff, nchain); |
| 5576 | band->ht_cap.mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED; |
| 5577 | } |
| 5578 | |
| 5579 | static __le16 brcmf_get_mcs_map(u32 nchain, enum ieee80211_vht_mcs_support supp) |
| 5580 | { |
| 5581 | u16 mcs_map; |
| 5582 | int i; |
| 5583 | |
| 5584 | for (i = 0, mcs_map = 0xFFFF; i < nchain; i++) |
| 5585 | mcs_map = (mcs_map << 2) | supp; |
| 5586 | |
| 5587 | return cpu_to_le16(mcs_map); |
| 5588 | } |
| 5589 | |
| 5590 | static void brcmf_update_vht_cap(struct ieee80211_supported_band *band, |
| 5591 | u32 bw_cap[2], u32 nchain) |
| 5592 | { |
| 5593 | __le16 mcs_map; |
| 5594 | |
| 5595 | /* not allowed in 2.4G band */ |
| 5596 | if (band->band == IEEE80211_BAND_2GHZ) |
| 5597 | return; |
| 5598 | |
| 5599 | band->vht_cap.vht_supported = true; |
| 5600 | /* 80MHz is mandatory */ |
| 5601 | band->vht_cap.cap |= IEEE80211_VHT_CAP_SHORT_GI_80; |
| 5602 | if (bw_cap[band->band] & WLC_BW_160MHZ_BIT) { |
| 5603 | band->vht_cap.cap |= IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ; |
| 5604 | band->vht_cap.cap |= IEEE80211_VHT_CAP_SHORT_GI_160; |
| 5605 | } |
| 5606 | /* all support 256-QAM */ |
| 5607 | mcs_map = brcmf_get_mcs_map(nchain, IEEE80211_VHT_MCS_SUPPORT_0_9); |
| 5608 | band->vht_cap.vht_mcs.rx_mcs_map = mcs_map; |
| 5609 | band->vht_cap.vht_mcs.tx_mcs_map = mcs_map; |
| 5610 | } |
| 5611 | |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 5612 | static int brcmf_setup_wiphybands(struct wiphy *wiphy) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5613 | { |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 5614 | struct brcmf_cfg80211_info *cfg = wiphy_priv(wiphy); |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 5615 | struct brcmf_if *ifp = netdev_priv(cfg_to_ndev(cfg)); |
Arend van Spriel | 18d6c53 | 2014-05-12 10:47:35 +0200 | [diff] [blame] | 5616 | u32 nmode = 0; |
| 5617 | u32 vhtmode = 0; |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 5618 | u32 bw_cap[2] = { WLC_BW_20MHZ_BIT, WLC_BW_20MHZ_BIT }; |
Daniel Kim | 4aca7a1 | 2014-02-25 20:30:36 +0100 | [diff] [blame] | 5619 | u32 rxchain; |
| 5620 | u32 nchain; |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 5621 | int err; |
Hante Meuleman | d48200b | 2013-04-03 12:40:29 +0200 | [diff] [blame] | 5622 | s32 i; |
Arend van Spriel | 2375d97 | 2014-01-06 12:40:41 +0100 | [diff] [blame] | 5623 | struct ieee80211_supported_band *band; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5624 | |
Arend van Spriel | 18d6c53 | 2014-05-12 10:47:35 +0200 | [diff] [blame] | 5625 | (void)brcmf_fil_iovar_int_get(ifp, "vhtmode", &vhtmode); |
Hante Meuleman | d48200b | 2013-04-03 12:40:29 +0200 | [diff] [blame] | 5626 | err = brcmf_fil_iovar_int_get(ifp, "nmode", &nmode); |
| 5627 | if (err) { |
| 5628 | brcmf_err("nmode error (%d)\n", err); |
| 5629 | } else { |
Arend van Spriel | 2375d97 | 2014-01-06 12:40:41 +0100 | [diff] [blame] | 5630 | brcmf_get_bwcap(ifp, bw_cap); |
Hante Meuleman | d48200b | 2013-04-03 12:40:29 +0200 | [diff] [blame] | 5631 | } |
Arend van Spriel | 18d6c53 | 2014-05-12 10:47:35 +0200 | [diff] [blame] | 5632 | brcmf_dbg(INFO, "nmode=%d, vhtmode=%d, bw_cap=(%d, %d)\n", |
| 5633 | nmode, vhtmode, bw_cap[IEEE80211_BAND_2GHZ], |
| 5634 | bw_cap[IEEE80211_BAND_5GHZ]); |
Hante Meuleman | d48200b | 2013-04-03 12:40:29 +0200 | [diff] [blame] | 5635 | |
Daniel Kim | 4aca7a1 | 2014-02-25 20:30:36 +0100 | [diff] [blame] | 5636 | err = brcmf_fil_iovar_int_get(ifp, "rxchain", &rxchain); |
| 5637 | if (err) { |
| 5638 | brcmf_err("rxchain error (%d)\n", err); |
| 5639 | nchain = 1; |
| 5640 | } else { |
| 5641 | for (nchain = 0; rxchain; nchain++) |
| 5642 | rxchain = rxchain & (rxchain - 1); |
| 5643 | } |
| 5644 | brcmf_dbg(INFO, "nchain=%d\n", nchain); |
| 5645 | |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 5646 | err = brcmf_construct_chaninfo(cfg, bw_cap); |
Hante Meuleman | d48200b | 2013-04-03 12:40:29 +0200 | [diff] [blame] | 5647 | if (err) { |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 5648 | brcmf_err("brcmf_construct_chaninfo failed (%d)\n", err); |
Hante Meuleman | d48200b | 2013-04-03 12:40:29 +0200 | [diff] [blame] | 5649 | return err; |
| 5650 | } |
| 5651 | |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 5652 | wiphy = cfg_to_wiphy(cfg); |
| 5653 | for (i = 0; i < ARRAY_SIZE(wiphy->bands); i++) { |
| 5654 | band = wiphy->bands[i]; |
| 5655 | if (band == NULL) |
Arend van Spriel | 2375d97 | 2014-01-06 12:40:41 +0100 | [diff] [blame] | 5656 | continue; |
Hante Meuleman | d48200b | 2013-04-03 12:40:29 +0200 | [diff] [blame] | 5657 | |
Arend van Spriel | 18d6c53 | 2014-05-12 10:47:35 +0200 | [diff] [blame] | 5658 | if (nmode) |
| 5659 | brcmf_update_ht_cap(band, bw_cap, nchain); |
| 5660 | if (vhtmode) |
| 5661 | brcmf_update_vht_cap(band, bw_cap, nchain); |
Hante Meuleman | d48200b | 2013-04-03 12:40:29 +0200 | [diff] [blame] | 5662 | } |
| 5663 | |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 5664 | return 0; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5665 | } |
| 5666 | |
Arend van Spriel | aa70b4f | 2014-07-12 08:49:40 +0200 | [diff] [blame] | 5667 | static const struct ieee80211_txrx_stypes |
| 5668 | brcmf_txrx_stypes[NUM_NL80211_IFTYPES] = { |
| 5669 | [NL80211_IFTYPE_STATION] = { |
| 5670 | .tx = 0xffff, |
| 5671 | .rx = BIT(IEEE80211_STYPE_ACTION >> 4) | |
| 5672 | BIT(IEEE80211_STYPE_PROBE_REQ >> 4) |
| 5673 | }, |
| 5674 | [NL80211_IFTYPE_P2P_CLIENT] = { |
| 5675 | .tx = 0xffff, |
| 5676 | .rx = BIT(IEEE80211_STYPE_ACTION >> 4) | |
| 5677 | BIT(IEEE80211_STYPE_PROBE_REQ >> 4) |
| 5678 | }, |
| 5679 | [NL80211_IFTYPE_P2P_GO] = { |
| 5680 | .tx = 0xffff, |
| 5681 | .rx = BIT(IEEE80211_STYPE_ASSOC_REQ >> 4) | |
| 5682 | BIT(IEEE80211_STYPE_REASSOC_REQ >> 4) | |
| 5683 | BIT(IEEE80211_STYPE_PROBE_REQ >> 4) | |
| 5684 | BIT(IEEE80211_STYPE_DISASSOC >> 4) | |
| 5685 | BIT(IEEE80211_STYPE_AUTH >> 4) | |
| 5686 | BIT(IEEE80211_STYPE_DEAUTH >> 4) | |
| 5687 | BIT(IEEE80211_STYPE_ACTION >> 4) |
| 5688 | }, |
| 5689 | [NL80211_IFTYPE_P2P_DEVICE] = { |
| 5690 | .tx = 0xffff, |
| 5691 | .rx = BIT(IEEE80211_STYPE_ACTION >> 4) | |
| 5692 | BIT(IEEE80211_STYPE_PROBE_REQ >> 4) |
| 5693 | } |
| 5694 | }; |
| 5695 | |
Arend van Spriel | 0882dda | 2015-08-20 22:06:03 +0200 | [diff] [blame] | 5696 | /** |
| 5697 | * brcmf_setup_ifmodes() - determine interface modes and combinations. |
| 5698 | * |
| 5699 | * @wiphy: wiphy object. |
| 5700 | * @ifp: interface object needed for feat module api. |
| 5701 | * |
| 5702 | * The interface modes and combinations are determined dynamically here |
| 5703 | * based on firmware functionality. |
| 5704 | * |
| 5705 | * no p2p and no mbss: |
| 5706 | * |
| 5707 | * #STA <= 1, #AP <= 1, channels = 1, 2 total |
| 5708 | * |
| 5709 | * no p2p and mbss: |
| 5710 | * |
| 5711 | * #STA <= 1, #AP <= 1, channels = 1, 2 total |
| 5712 | * #AP <= 4, matching BI, channels = 1, 4 total |
| 5713 | * |
| 5714 | * p2p, no mchan, and mbss: |
| 5715 | * |
| 5716 | * #STA <= 1, #P2P-DEV <= 1, #{P2P-CL, P2P-GO} <= 1, channels = 1, 3 total |
| 5717 | * #STA <= 1, #P2P-DEV <= 1, #AP <= 1, #P2P-CL <= 1, channels = 1, 4 total |
| 5718 | * #AP <= 4, matching BI, channels = 1, 4 total |
| 5719 | * |
| 5720 | * p2p, mchan, and mbss: |
| 5721 | * |
| 5722 | * #STA <= 1, #P2P-DEV <= 1, #{P2P-CL, P2P-GO} <= 1, channels = 2, 3 total |
| 5723 | * #STA <= 1, #P2P-DEV <= 1, #AP <= 1, #P2P-CL <= 1, channels = 1, 4 total |
| 5724 | * #AP <= 4, matching BI, channels = 1, 4 total |
| 5725 | */ |
Pontus Fuchs | 2e5f66f | 2015-06-11 00:12:18 +0200 | [diff] [blame] | 5726 | static int brcmf_setup_ifmodes(struct wiphy *wiphy, struct brcmf_if *ifp) |
| 5727 | { |
| 5728 | struct ieee80211_iface_combination *combo = NULL; |
Arend van Spriel | 0882dda | 2015-08-20 22:06:03 +0200 | [diff] [blame] | 5729 | struct ieee80211_iface_limit *c0_limits = NULL; |
| 5730 | struct ieee80211_iface_limit *p2p_limits = NULL; |
| 5731 | struct ieee80211_iface_limit *mbss_limits = NULL; |
| 5732 | bool mbss, p2p; |
| 5733 | int i, c, n_combos; |
Pontus Fuchs | 2e5f66f | 2015-06-11 00:12:18 +0200 | [diff] [blame] | 5734 | |
Arend van Spriel | 0882dda | 2015-08-20 22:06:03 +0200 | [diff] [blame] | 5735 | mbss = brcmf_feat_is_enabled(ifp, BRCMF_FEAT_MBSS); |
| 5736 | p2p = brcmf_feat_is_enabled(ifp, BRCMF_FEAT_P2P); |
| 5737 | |
| 5738 | n_combos = 1 + !!p2p + !!mbss; |
| 5739 | combo = kcalloc(n_combos, sizeof(*combo), GFP_KERNEL); |
Pontus Fuchs | 2e5f66f | 2015-06-11 00:12:18 +0200 | [diff] [blame] | 5740 | if (!combo) |
| 5741 | goto err; |
| 5742 | |
Arend van Spriel | 0882dda | 2015-08-20 22:06:03 +0200 | [diff] [blame] | 5743 | c0_limits = kcalloc(p2p ? 3 : 2, sizeof(*c0_limits), GFP_KERNEL); |
| 5744 | if (!c0_limits) |
Pontus Fuchs | 2e5f66f | 2015-06-11 00:12:18 +0200 | [diff] [blame] | 5745 | goto err; |
| 5746 | |
Arend van Spriel | 0882dda | 2015-08-20 22:06:03 +0200 | [diff] [blame] | 5747 | if (p2p) { |
| 5748 | p2p_limits = kcalloc(4, sizeof(*p2p_limits), GFP_KERNEL); |
| 5749 | if (!p2p_limits) |
| 5750 | goto err; |
| 5751 | } |
| 5752 | |
| 5753 | if (mbss) { |
| 5754 | mbss_limits = kcalloc(1, sizeof(*mbss_limits), GFP_KERNEL); |
| 5755 | if (!mbss_limits) |
| 5756 | goto err; |
| 5757 | } |
| 5758 | |
Pontus Fuchs | 2e5f66f | 2015-06-11 00:12:18 +0200 | [diff] [blame] | 5759 | wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) | |
| 5760 | BIT(NL80211_IFTYPE_ADHOC) | |
| 5761 | BIT(NL80211_IFTYPE_AP); |
| 5762 | |
Arend van Spriel | 0882dda | 2015-08-20 22:06:03 +0200 | [diff] [blame] | 5763 | c = 0; |
| 5764 | i = 0; |
| 5765 | combo[c].num_different_channels = 1; |
| 5766 | c0_limits[i].max = 1; |
| 5767 | c0_limits[i++].types = BIT(NL80211_IFTYPE_STATION); |
| 5768 | if (p2p) { |
| 5769 | if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_MCHAN)) |
| 5770 | combo[c].num_different_channels = 2; |
Pontus Fuchs | 2e5f66f | 2015-06-11 00:12:18 +0200 | [diff] [blame] | 5771 | wiphy->interface_modes |= BIT(NL80211_IFTYPE_P2P_CLIENT) | |
| 5772 | BIT(NL80211_IFTYPE_P2P_GO) | |
| 5773 | BIT(NL80211_IFTYPE_P2P_DEVICE); |
Arend van Spriel | 0882dda | 2015-08-20 22:06:03 +0200 | [diff] [blame] | 5774 | c0_limits[i].max = 1; |
| 5775 | c0_limits[i++].types = BIT(NL80211_IFTYPE_P2P_DEVICE); |
| 5776 | c0_limits[i].max = 1; |
| 5777 | c0_limits[i++].types = BIT(NL80211_IFTYPE_P2P_CLIENT) | |
| 5778 | BIT(NL80211_IFTYPE_P2P_GO); |
| 5779 | } else { |
| 5780 | c0_limits[i].max = 1; |
| 5781 | c0_limits[i++].types = BIT(NL80211_IFTYPE_AP); |
Pontus Fuchs | 2e5f66f | 2015-06-11 00:12:18 +0200 | [diff] [blame] | 5782 | } |
Arend van Spriel | 0882dda | 2015-08-20 22:06:03 +0200 | [diff] [blame] | 5783 | combo[c].max_interfaces = i; |
| 5784 | combo[c].n_limits = i; |
| 5785 | combo[c].limits = c0_limits; |
Pontus Fuchs | 2e5f66f | 2015-06-11 00:12:18 +0200 | [diff] [blame] | 5786 | |
Arend van Spriel | 0882dda | 2015-08-20 22:06:03 +0200 | [diff] [blame] | 5787 | if (p2p) { |
| 5788 | c++; |
| 5789 | i = 0; |
| 5790 | combo[c].num_different_channels = 1; |
| 5791 | p2p_limits[i].max = 1; |
| 5792 | p2p_limits[i++].types = BIT(NL80211_IFTYPE_STATION); |
| 5793 | p2p_limits[i].max = 1; |
| 5794 | p2p_limits[i++].types = BIT(NL80211_IFTYPE_AP); |
| 5795 | p2p_limits[i].max = 1; |
| 5796 | p2p_limits[i++].types = BIT(NL80211_IFTYPE_P2P_CLIENT); |
| 5797 | p2p_limits[i].max = 1; |
| 5798 | p2p_limits[i++].types = BIT(NL80211_IFTYPE_P2P_DEVICE); |
| 5799 | combo[c].max_interfaces = i; |
| 5800 | combo[c].n_limits = i; |
| 5801 | combo[c].limits = p2p_limits; |
| 5802 | } |
| 5803 | |
| 5804 | if (mbss) { |
| 5805 | c++; |
| 5806 | combo[c].beacon_int_infra_match = true; |
| 5807 | combo[c].num_different_channels = 1; |
| 5808 | mbss_limits[0].max = 4; |
| 5809 | mbss_limits[0].types = BIT(NL80211_IFTYPE_AP); |
| 5810 | combo[c].max_interfaces = 4; |
| 5811 | combo[c].n_limits = 1; |
| 5812 | combo[c].limits = mbss_limits; |
| 5813 | } |
| 5814 | wiphy->n_iface_combinations = n_combos; |
Pontus Fuchs | 2e5f66f | 2015-06-11 00:12:18 +0200 | [diff] [blame] | 5815 | wiphy->iface_combinations = combo; |
Pontus Fuchs | 2e5f66f | 2015-06-11 00:12:18 +0200 | [diff] [blame] | 5816 | return 0; |
| 5817 | |
| 5818 | err: |
Arend van Spriel | 0882dda | 2015-08-20 22:06:03 +0200 | [diff] [blame] | 5819 | kfree(c0_limits); |
| 5820 | kfree(p2p_limits); |
| 5821 | kfree(mbss_limits); |
Pontus Fuchs | 2e5f66f | 2015-06-11 00:12:18 +0200 | [diff] [blame] | 5822 | kfree(combo); |
| 5823 | return -ENOMEM; |
| 5824 | } |
| 5825 | |
Arend van Spriel | aa70b4f | 2014-07-12 08:49:40 +0200 | [diff] [blame] | 5826 | static void brcmf_wiphy_pno_params(struct wiphy *wiphy) |
| 5827 | { |
| 5828 | /* scheduled scan settings */ |
| 5829 | wiphy->max_sched_scan_ssids = BRCMF_PNO_MAX_PFN_COUNT; |
| 5830 | wiphy->max_match_sets = BRCMF_PNO_MAX_PFN_COUNT; |
| 5831 | wiphy->max_sched_scan_ie_len = BRCMF_SCAN_IE_LEN_MAX; |
| 5832 | wiphy->flags |= WIPHY_FLAG_SUPPORTS_SCHED_SCAN; |
| 5833 | } |
| 5834 | |
Hante Meuleman | 4eb3af7 | 2014-09-30 10:23:18 +0200 | [diff] [blame] | 5835 | #ifdef CONFIG_PM |
| 5836 | static const struct wiphy_wowlan_support brcmf_wowlan_support = { |
| 5837 | .flags = WIPHY_WOWLAN_MAGIC_PKT | WIPHY_WOWLAN_DISCONNECT, |
Hante Meuleman | b9a82f8 | 2014-10-28 14:56:06 +0100 | [diff] [blame] | 5838 | .n_patterns = BRCMF_WOWL_MAXPATTERNS, |
| 5839 | .pattern_max_len = BRCMF_WOWL_MAXPATTERNSIZE, |
| 5840 | .pattern_min_len = 1, |
| 5841 | .max_pkt_offset = 1500, |
Hante Meuleman | 4eb3af7 | 2014-09-30 10:23:18 +0200 | [diff] [blame] | 5842 | }; |
| 5843 | #endif |
| 5844 | |
| 5845 | static void brcmf_wiphy_wowl_params(struct wiphy *wiphy) |
| 5846 | { |
| 5847 | #ifdef CONFIG_PM |
| 5848 | /* wowl settings */ |
| 5849 | wiphy->wowlan = &brcmf_wowlan_support; |
| 5850 | #endif |
| 5851 | } |
| 5852 | |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 5853 | 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] | 5854 | { |
Rafa? Mi?ecki | e3faa86 | 2015-07-09 17:07:08 +0200 | [diff] [blame] | 5855 | struct brcmf_pub *drvr = ifp->drvr; |
Rafał Miłecki | 50f32e2 | 2015-08-20 00:16:42 +0200 | [diff] [blame] | 5856 | const struct ieee80211_iface_combination *combo; |
Arend van Spriel | 58de92d | 2015-04-14 20:10:24 +0200 | [diff] [blame] | 5857 | struct ieee80211_supported_band *band; |
Rafał Miłecki | 50f32e2 | 2015-08-20 00:16:42 +0200 | [diff] [blame] | 5858 | u16 max_interfaces = 0; |
Arend van Spriel | 58de92d | 2015-04-14 20:10:24 +0200 | [diff] [blame] | 5859 | __le32 bandlist[3]; |
| 5860 | u32 n_bands; |
| 5861 | int err, i; |
| 5862 | |
Arend van Spriel | aa70b4f | 2014-07-12 08:49:40 +0200 | [diff] [blame] | 5863 | wiphy->max_scan_ssids = WL_NUM_SCAN_MAX; |
| 5864 | wiphy->max_scan_ie_len = BRCMF_SCAN_IE_LEN_MAX; |
| 5865 | wiphy->max_num_pmkids = WL_NUM_PMKIDS_MAX; |
Pontus Fuchs | 2e5f66f | 2015-06-11 00:12:18 +0200 | [diff] [blame] | 5866 | |
| 5867 | err = brcmf_setup_ifmodes(wiphy, ifp); |
| 5868 | if (err) |
| 5869 | return err; |
| 5870 | |
Rafał Miłecki | 50f32e2 | 2015-08-20 00:16:42 +0200 | [diff] [blame] | 5871 | for (i = 0, combo = wiphy->iface_combinations; |
| 5872 | i < wiphy->n_iface_combinations; i++, combo++) { |
| 5873 | max_interfaces = max(max_interfaces, combo->max_interfaces); |
| 5874 | } |
| 5875 | |
| 5876 | for (i = 0; i < max_interfaces && i < ARRAY_SIZE(drvr->addresses); |
| 5877 | i++) { |
Rafa? Mi?ecki | e3faa86 | 2015-07-09 17:07:08 +0200 | [diff] [blame] | 5878 | u8 *addr = drvr->addresses[i].addr; |
| 5879 | |
| 5880 | memcpy(addr, drvr->mac, ETH_ALEN); |
| 5881 | if (i) { |
| 5882 | addr[0] |= BIT(1); |
| 5883 | addr[ETH_ALEN - 1] ^= i; |
| 5884 | } |
| 5885 | } |
| 5886 | wiphy->addresses = drvr->addresses; |
| 5887 | wiphy->n_addresses = i; |
| 5888 | |
Arend van Spriel | aa70b4f | 2014-07-12 08:49:40 +0200 | [diff] [blame] | 5889 | wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM; |
| 5890 | wiphy->cipher_suites = __wl_cipher_suites; |
| 5891 | wiphy->n_cipher_suites = ARRAY_SIZE(__wl_cipher_suites); |
| 5892 | wiphy->flags |= WIPHY_FLAG_PS_ON_BY_DEFAULT | |
| 5893 | WIPHY_FLAG_OFFCHAN_TX | |
| 5894 | WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL | |
| 5895 | WIPHY_FLAG_SUPPORTS_TDLS; |
| 5896 | if (!brcmf_roamoff) |
| 5897 | wiphy->flags |= WIPHY_FLAG_SUPPORTS_FW_ROAM; |
| 5898 | wiphy->mgmt_stypes = brcmf_txrx_stypes; |
| 5899 | wiphy->max_remain_on_channel_duration = 5000; |
Arend van Spriel | 7a7a87d | 2015-04-14 20:10:27 +0200 | [diff] [blame] | 5900 | if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_PNO)) |
| 5901 | brcmf_wiphy_pno_params(wiphy); |
Arend van Spriel | aa70b4f | 2014-07-12 08:49:40 +0200 | [diff] [blame] | 5902 | |
| 5903 | /* vendor commands/events support */ |
| 5904 | wiphy->vendor_commands = brcmf_vendor_cmds; |
| 5905 | wiphy->n_vendor_commands = BRCMF_VNDR_CMDS_LAST - 1; |
| 5906 | |
Hante Meuleman | 4eb3af7 | 2014-09-30 10:23:18 +0200 | [diff] [blame] | 5907 | if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_WOWL)) |
| 5908 | brcmf_wiphy_wowl_params(wiphy); |
| 5909 | |
Arend van Spriel | 58de92d | 2015-04-14 20:10:24 +0200 | [diff] [blame] | 5910 | err = brcmf_fil_cmd_data_get(ifp, BRCMF_C_GET_BANDLIST, &bandlist, |
| 5911 | sizeof(bandlist)); |
| 5912 | if (err) { |
| 5913 | brcmf_err("could not obtain band info: err=%d\n", err); |
| 5914 | return err; |
| 5915 | } |
| 5916 | /* first entry in bandlist is number of bands */ |
| 5917 | n_bands = le32_to_cpu(bandlist[0]); |
| 5918 | for (i = 1; i <= n_bands && i < ARRAY_SIZE(bandlist); i++) { |
| 5919 | if (bandlist[i] == cpu_to_le32(WLC_BAND_2G)) { |
| 5920 | band = kmemdup(&__wl_band_2ghz, sizeof(__wl_band_2ghz), |
| 5921 | GFP_KERNEL); |
| 5922 | if (!band) |
| 5923 | return -ENOMEM; |
| 5924 | |
| 5925 | band->channels = kmemdup(&__wl_2ghz_channels, |
| 5926 | sizeof(__wl_2ghz_channels), |
| 5927 | GFP_KERNEL); |
| 5928 | if (!band->channels) { |
| 5929 | kfree(band); |
| 5930 | return -ENOMEM; |
| 5931 | } |
| 5932 | |
| 5933 | band->n_channels = ARRAY_SIZE(__wl_2ghz_channels); |
| 5934 | wiphy->bands[IEEE80211_BAND_2GHZ] = band; |
| 5935 | } |
| 5936 | if (bandlist[i] == cpu_to_le32(WLC_BAND_5G)) { |
| 5937 | band = kmemdup(&__wl_band_5ghz, sizeof(__wl_band_5ghz), |
| 5938 | GFP_KERNEL); |
| 5939 | if (!band) |
| 5940 | return -ENOMEM; |
| 5941 | |
| 5942 | band->channels = kmemdup(&__wl_5ghz_channels, |
| 5943 | sizeof(__wl_5ghz_channels), |
| 5944 | GFP_KERNEL); |
| 5945 | if (!band->channels) { |
| 5946 | kfree(band); |
| 5947 | return -ENOMEM; |
| 5948 | } |
| 5949 | |
| 5950 | band->n_channels = ARRAY_SIZE(__wl_5ghz_channels); |
| 5951 | wiphy->bands[IEEE80211_BAND_5GHZ] = band; |
| 5952 | } |
| 5953 | } |
| 5954 | err = brcmf_setup_wiphybands(wiphy); |
| 5955 | return err; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5956 | } |
| 5957 | |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5958 | static s32 brcmf_config_dongle(struct brcmf_cfg80211_info *cfg) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5959 | { |
| 5960 | struct net_device *ndev; |
| 5961 | struct wireless_dev *wdev; |
Hante Meuleman | 40a2329 | 2013-01-02 15:22:51 +0100 | [diff] [blame] | 5962 | struct brcmf_if *ifp; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5963 | s32 power_mode; |
| 5964 | s32 err = 0; |
| 5965 | |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5966 | if (cfg->dongle_up) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5967 | return err; |
| 5968 | |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5969 | ndev = cfg_to_ndev(cfg); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5970 | wdev = ndev->ieee80211_ptr; |
Hante Meuleman | 40a2329 | 2013-01-02 15:22:51 +0100 | [diff] [blame] | 5971 | ifp = netdev_priv(ndev); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5972 | |
Hante Meuleman | 40a2329 | 2013-01-02 15:22:51 +0100 | [diff] [blame] | 5973 | /* make sure RF is ready for work */ |
| 5974 | brcmf_fil_cmd_int_set(ifp, BRCMF_C_UP, 0); |
| 5975 | |
| 5976 | brcmf_dongle_scantime(ifp, WL_SCAN_CHANNEL_TIME, |
| 5977 | WL_SCAN_UNASSOC_TIME, WL_SCAN_PASSIVE_TIME); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5978 | |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5979 | power_mode = cfg->pwr_save ? PM_FAST : PM_OFF; |
Hante Meuleman | 40a2329 | 2013-01-02 15:22:51 +0100 | [diff] [blame] | 5980 | 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] | 5981 | if (err) |
| 5982 | goto default_conf_out; |
Arend van Spriel | 647c9ae | 2012-12-05 15:26:01 +0100 | [diff] [blame] | 5983 | brcmf_dbg(INFO, "power save set to %s\n", |
| 5984 | (power_mode ? "enabled" : "disabled")); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5985 | |
Hante Meuleman | 68ca395 | 2014-02-25 20:30:26 +0100 | [diff] [blame] | 5986 | err = brcmf_dongle_roam(ifp, WL_BEACON_TIMEOUT); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5987 | if (err) |
| 5988 | goto default_conf_out; |
Franky Lin | 5dd161f | 2012-10-10 11:13:10 -0700 | [diff] [blame] | 5989 | err = brcmf_cfg80211_change_iface(wdev->wiphy, ndev, wdev->iftype, |
| 5990 | NULL, NULL); |
Hante Meuleman | 40a2329 | 2013-01-02 15:22:51 +0100 | [diff] [blame] | 5991 | if (err) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5992 | goto default_conf_out; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5993 | |
Hante Meuleman | b365745 | 2013-05-27 21:09:53 +0200 | [diff] [blame] | 5994 | brcmf_configure_arp_offload(ifp, true); |
| 5995 | |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5996 | cfg->dongle_up = true; |
Hante Meuleman | 40a2329 | 2013-01-02 15:22:51 +0100 | [diff] [blame] | 5997 | default_conf_out: |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5998 | |
| 5999 | return err; |
| 6000 | |
| 6001 | } |
| 6002 | |
Arend van Spriel | bdf5ff5 | 2012-11-14 18:46:09 -0800 | [diff] [blame] | 6003 | static s32 __brcmf_cfg80211_up(struct brcmf_if *ifp) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 6004 | { |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 6005 | set_bit(BRCMF_VIF_STATUS_READY, &ifp->vif->sme_state); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 6006 | |
Arend van Spriel | bdf5ff5 | 2012-11-14 18:46:09 -0800 | [diff] [blame] | 6007 | return brcmf_config_dongle(ifp->drvr->config); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 6008 | } |
| 6009 | |
Arend van Spriel | bdf5ff5 | 2012-11-14 18:46:09 -0800 | [diff] [blame] | 6010 | static s32 __brcmf_cfg80211_down(struct brcmf_if *ifp) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 6011 | { |
Arend van Spriel | bdf5ff5 | 2012-11-14 18:46:09 -0800 | [diff] [blame] | 6012 | struct brcmf_cfg80211_info *cfg = ifp->drvr->config; |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 6013 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 6014 | /* |
| 6015 | * While going down, if associated with AP disassociate |
| 6016 | * from AP to save power |
| 6017 | */ |
Arend van Spriel | 903e0ee | 2012-11-28 21:44:11 +0100 | [diff] [blame] | 6018 | if (check_vif_up(ifp->vif)) { |
Arend van Spriel | 9b7a0dd | 2015-01-25 20:31:33 +0100 | [diff] [blame] | 6019 | brcmf_link_down(ifp->vif, WLAN_REASON_UNSPECIFIED); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 6020 | |
| 6021 | /* Make sure WPA_Supplicant receives all the event |
| 6022 | generated due to DISASSOC call to the fw to keep |
| 6023 | the state fw and WPA_Supplicant state consistent |
| 6024 | */ |
| 6025 | brcmf_delay(500); |
| 6026 | } |
| 6027 | |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 6028 | brcmf_abort_scanning(cfg); |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 6029 | clear_bit(BRCMF_VIF_STATUS_READY, &ifp->vif->sme_state); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 6030 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 6031 | return 0; |
| 6032 | } |
| 6033 | |
Arend van Spriel | bdf5ff5 | 2012-11-14 18:46:09 -0800 | [diff] [blame] | 6034 | s32 brcmf_cfg80211_up(struct net_device *ndev) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 6035 | { |
Arend van Spriel | bdf5ff5 | 2012-11-14 18:46:09 -0800 | [diff] [blame] | 6036 | struct brcmf_if *ifp = netdev_priv(ndev); |
| 6037 | struct brcmf_cfg80211_info *cfg = ifp->drvr->config; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 6038 | s32 err = 0; |
| 6039 | |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 6040 | mutex_lock(&cfg->usr_sync); |
Arend van Spriel | bdf5ff5 | 2012-11-14 18:46:09 -0800 | [diff] [blame] | 6041 | err = __brcmf_cfg80211_up(ifp); |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 6042 | mutex_unlock(&cfg->usr_sync); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 6043 | |
| 6044 | return err; |
| 6045 | } |
| 6046 | |
Arend van Spriel | bdf5ff5 | 2012-11-14 18:46:09 -0800 | [diff] [blame] | 6047 | s32 brcmf_cfg80211_down(struct net_device *ndev) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 6048 | { |
Arend van Spriel | bdf5ff5 | 2012-11-14 18:46:09 -0800 | [diff] [blame] | 6049 | struct brcmf_if *ifp = netdev_priv(ndev); |
| 6050 | struct brcmf_cfg80211_info *cfg = ifp->drvr->config; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 6051 | s32 err = 0; |
| 6052 | |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 6053 | mutex_lock(&cfg->usr_sync); |
Arend van Spriel | bdf5ff5 | 2012-11-14 18:46:09 -0800 | [diff] [blame] | 6054 | err = __brcmf_cfg80211_down(ifp); |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 6055 | mutex_unlock(&cfg->usr_sync); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 6056 | |
| 6057 | return err; |
| 6058 | } |
| 6059 | |
Arend van Spriel | a7965fb | 2013-04-11 17:08:37 +0200 | [diff] [blame] | 6060 | enum nl80211_iftype brcmf_cfg80211_get_iftype(struct brcmf_if *ifp) |
| 6061 | { |
| 6062 | struct wireless_dev *wdev = &ifp->vif->wdev; |
| 6063 | |
| 6064 | return wdev->iftype; |
| 6065 | } |
| 6066 | |
Hante Meuleman | bfe8197 | 2014-10-28 14:56:16 +0100 | [diff] [blame] | 6067 | bool brcmf_get_vif_state_any(struct brcmf_cfg80211_info *cfg, |
| 6068 | unsigned long state) |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 6069 | { |
| 6070 | struct brcmf_cfg80211_vif *vif; |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 6071 | |
| 6072 | list_for_each_entry(vif, &cfg->vif_list, list) { |
| 6073 | if (test_bit(state, &vif->sme_state)) |
Rasmus Villemoes | e843bb1 | 2014-06-22 20:50:40 +0200 | [diff] [blame] | 6074 | return true; |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 6075 | } |
Rasmus Villemoes | e843bb1 | 2014-06-22 20:50:40 +0200 | [diff] [blame] | 6076 | return false; |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 6077 | } |
Arend van Spriel | d3c0b63 | 2013-02-08 15:53:37 +0100 | [diff] [blame] | 6078 | |
| 6079 | static inline bool vif_event_equals(struct brcmf_cfg80211_vif_event *event, |
| 6080 | u8 action) |
| 6081 | { |
| 6082 | u8 evt_action; |
| 6083 | |
| 6084 | mutex_lock(&event->vif_event_lock); |
| 6085 | evt_action = event->action; |
| 6086 | mutex_unlock(&event->vif_event_lock); |
| 6087 | return evt_action == action; |
| 6088 | } |
| 6089 | |
| 6090 | void brcmf_cfg80211_arm_vif_event(struct brcmf_cfg80211_info *cfg, |
| 6091 | struct brcmf_cfg80211_vif *vif) |
| 6092 | { |
| 6093 | struct brcmf_cfg80211_vif_event *event = &cfg->vif_event; |
| 6094 | |
| 6095 | mutex_lock(&event->vif_event_lock); |
| 6096 | event->vif = vif; |
| 6097 | event->action = 0; |
| 6098 | mutex_unlock(&event->vif_event_lock); |
| 6099 | } |
| 6100 | |
| 6101 | bool brcmf_cfg80211_vif_event_armed(struct brcmf_cfg80211_info *cfg) |
| 6102 | { |
| 6103 | struct brcmf_cfg80211_vif_event *event = &cfg->vif_event; |
| 6104 | bool armed; |
| 6105 | |
| 6106 | mutex_lock(&event->vif_event_lock); |
| 6107 | armed = event->vif != NULL; |
| 6108 | mutex_unlock(&event->vif_event_lock); |
| 6109 | |
| 6110 | return armed; |
| 6111 | } |
| 6112 | int brcmf_cfg80211_wait_vif_event_timeout(struct brcmf_cfg80211_info *cfg, |
| 6113 | u8 action, ulong timeout) |
| 6114 | { |
| 6115 | struct brcmf_cfg80211_vif_event *event = &cfg->vif_event; |
| 6116 | |
| 6117 | return wait_event_timeout(event->vif_wq, |
| 6118 | vif_event_equals(event, action), timeout); |
| 6119 | } |
| 6120 | |
Arend van Spriel | 63db1a4 | 2014-12-21 12:43:51 +0100 | [diff] [blame] | 6121 | static void brcmf_cfg80211_reg_notifier(struct wiphy *wiphy, |
| 6122 | struct regulatory_request *req) |
| 6123 | { |
| 6124 | struct brcmf_cfg80211_info *cfg = wiphy_priv(wiphy); |
| 6125 | struct brcmf_if *ifp = netdev_priv(cfg_to_ndev(cfg)); |
| 6126 | struct brcmf_fil_country_le ccreq; |
| 6127 | int i; |
| 6128 | |
| 6129 | brcmf_dbg(TRACE, "enter: initiator=%d, alpha=%c%c\n", req->initiator, |
| 6130 | req->alpha2[0], req->alpha2[1]); |
| 6131 | |
| 6132 | /* ignore non-ISO3166 country codes */ |
| 6133 | for (i = 0; i < sizeof(req->alpha2); i++) |
| 6134 | if (req->alpha2[i] < 'A' || req->alpha2[i] > 'Z') { |
| 6135 | brcmf_err("not a ISO3166 code\n"); |
| 6136 | return; |
| 6137 | } |
| 6138 | memset(&ccreq, 0, sizeof(ccreq)); |
| 6139 | ccreq.rev = cpu_to_le32(-1); |
| 6140 | memcpy(ccreq.ccode, req->alpha2, sizeof(req->alpha2)); |
Arend van Spriel | 8afe0ec | 2015-04-14 20:10:25 +0200 | [diff] [blame] | 6141 | if (brcmf_fil_iovar_data_set(ifp, "country", &ccreq, sizeof(ccreq))) { |
| 6142 | brcmf_err("firmware rejected country setting\n"); |
| 6143 | return; |
| 6144 | } |
| 6145 | brcmf_setup_wiphybands(wiphy); |
Arend van Spriel | 63db1a4 | 2014-12-21 12:43:51 +0100 | [diff] [blame] | 6146 | } |
| 6147 | |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 6148 | static void brcmf_free_wiphy(struct wiphy *wiphy) |
| 6149 | { |
Arend van Spriel | 0882dda | 2015-08-20 22:06:03 +0200 | [diff] [blame] | 6150 | int i; |
| 6151 | |
Arend van Spriel | 58de92d | 2015-04-14 20:10:24 +0200 | [diff] [blame] | 6152 | if (!wiphy) |
| 6153 | return; |
| 6154 | |
Arend van Spriel | 0882dda | 2015-08-20 22:06:03 +0200 | [diff] [blame] | 6155 | if (wiphy->iface_combinations) { |
| 6156 | for (i = 0; i < wiphy->n_iface_combinations; i++) |
| 6157 | kfree(wiphy->iface_combinations[i].limits); |
| 6158 | } |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 6159 | kfree(wiphy->iface_combinations); |
| 6160 | if (wiphy->bands[IEEE80211_BAND_2GHZ]) { |
| 6161 | kfree(wiphy->bands[IEEE80211_BAND_2GHZ]->channels); |
| 6162 | kfree(wiphy->bands[IEEE80211_BAND_2GHZ]); |
| 6163 | } |
| 6164 | if (wiphy->bands[IEEE80211_BAND_5GHZ]) { |
| 6165 | kfree(wiphy->bands[IEEE80211_BAND_5GHZ]->channels); |
| 6166 | kfree(wiphy->bands[IEEE80211_BAND_5GHZ]); |
| 6167 | } |
| 6168 | wiphy_free(wiphy); |
| 6169 | } |
| 6170 | |
Arend van Spriel | ccfd1e8 | 2014-07-12 08:49:38 +0200 | [diff] [blame] | 6171 | struct brcmf_cfg80211_info *brcmf_cfg80211_attach(struct brcmf_pub *drvr, |
Hante Meuleman | ae7c03f | 2015-09-18 22:08:08 +0200 | [diff] [blame] | 6172 | struct device *busdev, |
| 6173 | bool p2pdev_forced) |
Arend van Spriel | ccfd1e8 | 2014-07-12 08:49:38 +0200 | [diff] [blame] | 6174 | { |
Arend van Spriel | 46f3b6e | 2015-08-26 22:14:58 +0200 | [diff] [blame] | 6175 | struct net_device *ndev = brcmf_get_ifp(drvr, 0)->ndev; |
Arend van Spriel | ccfd1e8 | 2014-07-12 08:49:38 +0200 | [diff] [blame] | 6176 | struct brcmf_cfg80211_info *cfg; |
| 6177 | struct wiphy *wiphy; |
| 6178 | struct brcmf_cfg80211_vif *vif; |
| 6179 | struct brcmf_if *ifp; |
| 6180 | s32 err = 0; |
| 6181 | s32 io_type; |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 6182 | u16 *cap = NULL; |
Arend van Spriel | ccfd1e8 | 2014-07-12 08:49:38 +0200 | [diff] [blame] | 6183 | |
| 6184 | if (!ndev) { |
| 6185 | brcmf_err("ndev is invalid\n"); |
| 6186 | return NULL; |
| 6187 | } |
| 6188 | |
| 6189 | ifp = netdev_priv(ndev); |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 6190 | wiphy = wiphy_new(&wl_cfg80211_ops, sizeof(struct brcmf_cfg80211_info)); |
| 6191 | if (!wiphy) { |
| 6192 | brcmf_err("Could not allocate wiphy device\n"); |
Arend van Spriel | ccfd1e8 | 2014-07-12 08:49:38 +0200 | [diff] [blame] | 6193 | return NULL; |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 6194 | } |
Rafał Miłecki | 6896f4f | 2015-05-31 02:52:26 +0200 | [diff] [blame] | 6195 | memcpy(wiphy->perm_addr, drvr->mac, ETH_ALEN); |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 6196 | set_wiphy_dev(wiphy, busdev); |
Arend van Spriel | ccfd1e8 | 2014-07-12 08:49:38 +0200 | [diff] [blame] | 6197 | |
| 6198 | cfg = wiphy_priv(wiphy); |
| 6199 | cfg->wiphy = wiphy; |
| 6200 | cfg->pub = drvr; |
| 6201 | init_vif_event(&cfg->vif_event); |
| 6202 | INIT_LIST_HEAD(&cfg->vif_list); |
| 6203 | |
| 6204 | vif = brcmf_alloc_vif(cfg, NL80211_IFTYPE_STATION, false); |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 6205 | if (IS_ERR(vif)) |
| 6206 | goto wiphy_out; |
Arend van Spriel | ccfd1e8 | 2014-07-12 08:49:38 +0200 | [diff] [blame] | 6207 | |
| 6208 | vif->ifp = ifp; |
| 6209 | vif->wdev.netdev = ndev; |
| 6210 | ndev->ieee80211_ptr = &vif->wdev; |
| 6211 | SET_NETDEV_DEV(ndev, wiphy_dev(cfg->wiphy)); |
| 6212 | |
| 6213 | err = wl_init_priv(cfg); |
| 6214 | if (err) { |
| 6215 | brcmf_err("Failed to init iwm_priv (%d)\n", err); |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 6216 | brcmf_free_vif(vif); |
| 6217 | goto wiphy_out; |
Arend van Spriel | ccfd1e8 | 2014-07-12 08:49:38 +0200 | [diff] [blame] | 6218 | } |
| 6219 | ifp->vif = vif; |
| 6220 | |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 6221 | /* determine d11 io type before wiphy setup */ |
| 6222 | 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] | 6223 | if (err) { |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 6224 | brcmf_err("Failed to get D11 version (%d)\n", err); |
| 6225 | goto priv_out; |
Arend van Spriel | ccfd1e8 | 2014-07-12 08:49:38 +0200 | [diff] [blame] | 6226 | } |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 6227 | cfg->d11inf.io_type = (u8)io_type; |
| 6228 | brcmu_d11_attach(&cfg->d11inf); |
| 6229 | |
| 6230 | err = brcmf_setup_wiphy(wiphy, ifp); |
| 6231 | if (err < 0) |
| 6232 | goto priv_out; |
| 6233 | |
| 6234 | brcmf_dbg(INFO, "Registering custom regulatory\n"); |
Arend van Spriel | 63db1a4 | 2014-12-21 12:43:51 +0100 | [diff] [blame] | 6235 | wiphy->reg_notifier = brcmf_cfg80211_reg_notifier; |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 6236 | wiphy->regulatory_flags |= REGULATORY_CUSTOM_REG; |
| 6237 | wiphy_apply_custom_regulatory(wiphy, &brcmf_regdom); |
| 6238 | |
| 6239 | /* firmware defaults to 40MHz disabled in 2G band. We signal |
| 6240 | * cfg80211 here that we do and have it decide we can enable |
| 6241 | * it. But first check if device does support 2G operation. |
| 6242 | */ |
| 6243 | if (wiphy->bands[IEEE80211_BAND_2GHZ]) { |
| 6244 | cap = &wiphy->bands[IEEE80211_BAND_2GHZ]->ht_cap.cap; |
| 6245 | *cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40; |
| 6246 | } |
| 6247 | err = wiphy_register(wiphy); |
| 6248 | if (err < 0) { |
| 6249 | brcmf_err("Could not register wiphy device (%d)\n", err); |
| 6250 | goto priv_out; |
Arend van Spriel | ccfd1e8 | 2014-07-12 08:49:38 +0200 | [diff] [blame] | 6251 | } |
| 6252 | |
| 6253 | /* If cfg80211 didn't disable 40MHz HT CAP in wiphy_register(), |
| 6254 | * setup 40MHz in 2GHz band and enable OBSS scanning. |
| 6255 | */ |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 6256 | if (cap && (*cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40)) { |
| 6257 | err = brcmf_enable_bw40_2g(cfg); |
Arend van Spriel | ccfd1e8 | 2014-07-12 08:49:38 +0200 | [diff] [blame] | 6258 | if (!err) |
| 6259 | err = brcmf_fil_iovar_int_set(ifp, "obss_coex", |
| 6260 | BRCMF_OBSS_COEX_AUTO); |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 6261 | else |
| 6262 | *cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40; |
Arend van Spriel | ccfd1e8 | 2014-07-12 08:49:38 +0200 | [diff] [blame] | 6263 | } |
Hante Meuleman | 2b76acd | 2015-10-08 20:33:15 +0200 | [diff] [blame] | 6264 | /* p2p might require that "if-events" get processed by fweh. So |
| 6265 | * activate the already registered event handlers now and activate |
| 6266 | * the rest when initialization has completed. drvr->config needs to |
| 6267 | * be assigned before activating events. |
| 6268 | */ |
| 6269 | drvr->config = cfg; |
| 6270 | err = brcmf_fweh_activate_events(ifp); |
| 6271 | if (err) { |
| 6272 | brcmf_err("FWEH activation failed (%d)\n", err); |
| 6273 | goto wiphy_unreg_out; |
| 6274 | } |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 6275 | |
Hante Meuleman | ae7c03f | 2015-09-18 22:08:08 +0200 | [diff] [blame] | 6276 | err = brcmf_p2p_attach(cfg, p2pdev_forced); |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 6277 | if (err) { |
| 6278 | brcmf_err("P2P initilisation failed (%d)\n", err); |
| 6279 | goto wiphy_unreg_out; |
| 6280 | } |
| 6281 | err = brcmf_btcoex_attach(cfg); |
| 6282 | if (err) { |
| 6283 | brcmf_err("BT-coex initialisation failed (%d)\n", err); |
| 6284 | brcmf_p2p_detach(&cfg->p2p); |
| 6285 | goto wiphy_unreg_out; |
| 6286 | } |
Arend van Spriel | ccfd1e8 | 2014-07-12 08:49:38 +0200 | [diff] [blame] | 6287 | |
| 6288 | err = brcmf_fil_iovar_int_set(ifp, "tdls_enable", 1); |
| 6289 | if (err) { |
| 6290 | brcmf_dbg(INFO, "TDLS not enabled (%d)\n", err); |
| 6291 | wiphy->flags &= ~WIPHY_FLAG_SUPPORTS_TDLS; |
Hante Meuleman | 70b7d94 | 2014-07-30 13:20:07 +0200 | [diff] [blame] | 6292 | } else { |
| 6293 | brcmf_fweh_register(cfg->pub, BRCMF_E_TDLS_PEER_EVENT, |
| 6294 | brcmf_notify_tdls_peer_event); |
Arend van Spriel | ccfd1e8 | 2014-07-12 08:49:38 +0200 | [diff] [blame] | 6295 | } |
| 6296 | |
Hante Meuleman | 2b76acd | 2015-10-08 20:33:15 +0200 | [diff] [blame] | 6297 | /* (re-) activate FWEH event handling */ |
| 6298 | err = brcmf_fweh_activate_events(ifp); |
| 6299 | if (err) { |
| 6300 | brcmf_err("FWEH activation failed (%d)\n", err); |
| 6301 | goto wiphy_unreg_out; |
| 6302 | } |
| 6303 | |
Arend van Spriel | ccfd1e8 | 2014-07-12 08:49:38 +0200 | [diff] [blame] | 6304 | return cfg; |
| 6305 | |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 6306 | wiphy_unreg_out: |
| 6307 | wiphy_unregister(cfg->wiphy); |
| 6308 | priv_out: |
Arend van Spriel | ccfd1e8 | 2014-07-12 08:49:38 +0200 | [diff] [blame] | 6309 | wl_deinit_priv(cfg); |
Arend van Spriel | ccfd1e8 | 2014-07-12 08:49:38 +0200 | [diff] [blame] | 6310 | brcmf_free_vif(vif); |
Hante Meuleman | 2b5d348 | 2015-09-18 22:08:04 +0200 | [diff] [blame] | 6311 | ifp->vif = NULL; |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 6312 | wiphy_out: |
| 6313 | brcmf_free_wiphy(wiphy); |
Arend van Spriel | ccfd1e8 | 2014-07-12 08:49:38 +0200 | [diff] [blame] | 6314 | return NULL; |
| 6315 | } |
| 6316 | |
| 6317 | void brcmf_cfg80211_detach(struct brcmf_cfg80211_info *cfg) |
| 6318 | { |
| 6319 | if (!cfg) |
| 6320 | return; |
| 6321 | |
Arend van Spriel | ccfd1e8 | 2014-07-12 08:49:38 +0200 | [diff] [blame] | 6322 | brcmf_btcoex_detach(cfg); |
Arend van Spriel | f7a4087 | 2015-06-11 00:12:23 +0200 | [diff] [blame] | 6323 | wiphy_unregister(cfg->wiphy); |
Arend van Spriel | ccfd1e8 | 2014-07-12 08:49:38 +0200 | [diff] [blame] | 6324 | wl_deinit_priv(cfg); |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 6325 | brcmf_free_wiphy(cfg->wiphy); |
Arend van Spriel | ccfd1e8 | 2014-07-12 08:49:38 +0200 | [diff] [blame] | 6326 | } |