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 | |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 55 | #define BRCMF_IFACE_MAX_CNT 3 |
Arend van Spriel | 3eacf86 | 2012-10-22 13:55:30 -0700 | [diff] [blame] | 56 | |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 57 | #define WPA_OUI "\x00\x50\xF2" /* WPA OUI */ |
| 58 | #define WPA_OUI_TYPE 1 |
| 59 | #define RSN_OUI "\x00\x0F\xAC" /* RSN OUI */ |
| 60 | #define WME_OUI_TYPE 2 |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 61 | #define WPS_OUI_TYPE 4 |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 62 | |
| 63 | #define VS_IE_FIXED_HDR_LEN 6 |
| 64 | #define WPA_IE_VERSION_LEN 2 |
| 65 | #define WPA_IE_MIN_OUI_LEN 4 |
| 66 | #define WPA_IE_SUITE_COUNT_LEN 2 |
| 67 | |
| 68 | #define WPA_CIPHER_NONE 0 /* None */ |
| 69 | #define WPA_CIPHER_WEP_40 1 /* WEP (40-bit) */ |
| 70 | #define WPA_CIPHER_TKIP 2 /* TKIP: default for WPA */ |
| 71 | #define WPA_CIPHER_AES_CCM 4 /* AES (CCM) */ |
| 72 | #define WPA_CIPHER_WEP_104 5 /* WEP (104-bit) */ |
| 73 | |
| 74 | #define RSN_AKM_NONE 0 /* None (IBSS) */ |
| 75 | #define RSN_AKM_UNSPECIFIED 1 /* Over 802.1x */ |
| 76 | #define RSN_AKM_PSK 2 /* Pre-shared Key */ |
| 77 | #define RSN_CAP_LEN 2 /* Length of RSN capabilities */ |
| 78 | #define RSN_CAP_PTK_REPLAY_CNTR_MASK 0x000C |
| 79 | |
| 80 | #define VNDR_IE_CMD_LEN 4 /* length of the set command |
| 81 | * string :"add", "del" (+ NUL) |
| 82 | */ |
| 83 | #define VNDR_IE_COUNT_OFFSET 4 |
| 84 | #define VNDR_IE_PKTFLAG_OFFSET 8 |
| 85 | #define VNDR_IE_VSIE_OFFSET 12 |
| 86 | #define VNDR_IE_HDR_SIZE 12 |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 87 | #define VNDR_IE_PARSE_LIMIT 5 |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 88 | |
| 89 | #define DOT11_MGMT_HDR_LEN 24 /* d11 management header len */ |
| 90 | #define DOT11_BCN_PRB_FIXED_LEN 12 /* beacon/probe fixed length */ |
Hante Meuleman | 0401289 | 2012-09-27 14:17:49 +0200 | [diff] [blame] | 91 | |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 92 | #define BRCMF_SCAN_JOIN_ACTIVE_DWELL_TIME_MS 320 |
| 93 | #define BRCMF_SCAN_JOIN_PASSIVE_DWELL_TIME_MS 400 |
| 94 | #define BRCMF_SCAN_JOIN_PROBE_INTERVAL_MS 20 |
| 95 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 96 | #define BRCMF_ASSOC_PARAMS_FIXED_SIZE \ |
| 97 | (sizeof(struct brcmf_assoc_params_le) - sizeof(u16)) |
| 98 | |
Arend van Spriel | ce81e31 | 2012-10-22 13:55:37 -0700 | [diff] [blame] | 99 | static bool check_vif_up(struct brcmf_cfg80211_vif *vif) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 100 | { |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 101 | if (!test_bit(BRCMF_VIF_STATUS_READY, &vif->sme_state)) { |
Arend van Spriel | 647c9ae | 2012-12-05 15:26:01 +0100 | [diff] [blame] | 102 | brcmf_dbg(INFO, "device is not ready : status (%lu)\n", |
| 103 | vif->sme_state); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 104 | return false; |
| 105 | } |
| 106 | return true; |
| 107 | } |
| 108 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 109 | #define RATE_TO_BASE100KBPS(rate) (((rate) * 10) / 2) |
| 110 | #define RATETAB_ENT(_rateid, _flags) \ |
| 111 | { \ |
| 112 | .bitrate = RATE_TO_BASE100KBPS(_rateid), \ |
| 113 | .hw_value = (_rateid), \ |
| 114 | .flags = (_flags), \ |
| 115 | } |
| 116 | |
| 117 | static struct ieee80211_rate __wl_rates[] = { |
| 118 | RATETAB_ENT(BRCM_RATE_1M, 0), |
| 119 | RATETAB_ENT(BRCM_RATE_2M, IEEE80211_RATE_SHORT_PREAMBLE), |
| 120 | RATETAB_ENT(BRCM_RATE_5M5, IEEE80211_RATE_SHORT_PREAMBLE), |
| 121 | RATETAB_ENT(BRCM_RATE_11M, IEEE80211_RATE_SHORT_PREAMBLE), |
| 122 | RATETAB_ENT(BRCM_RATE_6M, 0), |
| 123 | RATETAB_ENT(BRCM_RATE_9M, 0), |
| 124 | RATETAB_ENT(BRCM_RATE_12M, 0), |
| 125 | RATETAB_ENT(BRCM_RATE_18M, 0), |
| 126 | RATETAB_ENT(BRCM_RATE_24M, 0), |
| 127 | RATETAB_ENT(BRCM_RATE_36M, 0), |
| 128 | RATETAB_ENT(BRCM_RATE_48M, 0), |
| 129 | RATETAB_ENT(BRCM_RATE_54M, 0), |
| 130 | }; |
| 131 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 132 | #define wl_g_rates (__wl_rates + 0) |
Arend van Spriel | 58de92d | 2015-04-14 20:10:24 +0200 | [diff] [blame] | 133 | #define wl_g_rates_size ARRAY_SIZE(__wl_rates) |
| 134 | #define wl_a_rates (__wl_rates + 4) |
| 135 | #define wl_a_rates_size (wl_g_rates_size - 4) |
| 136 | |
| 137 | #define CHAN2G(_channel, _freq) { \ |
| 138 | .band = IEEE80211_BAND_2GHZ, \ |
| 139 | .center_freq = (_freq), \ |
| 140 | .hw_value = (_channel), \ |
| 141 | .flags = IEEE80211_CHAN_DISABLED, \ |
| 142 | .max_antenna_gain = 0, \ |
| 143 | .max_power = 30, \ |
| 144 | } |
| 145 | |
| 146 | #define CHAN5G(_channel) { \ |
| 147 | .band = IEEE80211_BAND_5GHZ, \ |
| 148 | .center_freq = 5000 + (5 * (_channel)), \ |
| 149 | .hw_value = (_channel), \ |
| 150 | .flags = IEEE80211_CHAN_DISABLED, \ |
| 151 | .max_antenna_gain = 0, \ |
| 152 | .max_power = 30, \ |
| 153 | } |
| 154 | |
| 155 | static struct ieee80211_channel __wl_2ghz_channels[] = { |
| 156 | CHAN2G(1, 2412), CHAN2G(2, 2417), CHAN2G(3, 2422), CHAN2G(4, 2427), |
| 157 | CHAN2G(5, 2432), CHAN2G(6, 2437), CHAN2G(7, 2442), CHAN2G(8, 2447), |
| 158 | CHAN2G(9, 2452), CHAN2G(10, 2457), CHAN2G(11, 2462), CHAN2G(12, 2467), |
| 159 | CHAN2G(13, 2472), CHAN2G(14, 2484) |
| 160 | }; |
| 161 | |
| 162 | static struct ieee80211_channel __wl_5ghz_channels[] = { |
| 163 | CHAN5G(34), CHAN5G(36), CHAN5G(38), CHAN5G(40), CHAN5G(42), |
| 164 | CHAN5G(44), CHAN5G(46), CHAN5G(48), CHAN5G(52), CHAN5G(56), |
| 165 | CHAN5G(60), CHAN5G(64), CHAN5G(100), CHAN5G(104), CHAN5G(108), |
| 166 | CHAN5G(112), CHAN5G(116), CHAN5G(120), CHAN5G(124), CHAN5G(128), |
| 167 | CHAN5G(132), CHAN5G(136), CHAN5G(140), CHAN5G(144), CHAN5G(149), |
| 168 | CHAN5G(153), CHAN5G(157), CHAN5G(161), CHAN5G(165) |
| 169 | }; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 170 | |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 171 | /* Band templates duplicated per wiphy. The channel info |
Arend van Spriel | 58de92d | 2015-04-14 20:10:24 +0200 | [diff] [blame] | 172 | * above is added to the band during setup. |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 173 | */ |
| 174 | static const struct ieee80211_supported_band __wl_band_2ghz = { |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 175 | .band = IEEE80211_BAND_2GHZ, |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 176 | .bitrates = wl_g_rates, |
| 177 | .n_bitrates = wl_g_rates_size, |
| 178 | }; |
| 179 | |
Arend van Spriel | 58de92d | 2015-04-14 20:10:24 +0200 | [diff] [blame] | 180 | static const struct ieee80211_supported_band __wl_band_5ghz = { |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 181 | .band = IEEE80211_BAND_5GHZ, |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 182 | .bitrates = wl_a_rates, |
| 183 | .n_bitrates = wl_a_rates_size, |
| 184 | }; |
| 185 | |
Hante Meuleman | d48200b | 2013-04-03 12:40:29 +0200 | [diff] [blame] | 186 | /* This is to override regulatory domains defined in cfg80211 module (reg.c) |
| 187 | * By default world regulatory domain defined in reg.c puts the flags |
Luis R. Rodriguez | 8fe02e1 | 2013-10-21 19:22:25 +0200 | [diff] [blame] | 188 | * NL80211_RRF_NO_IR for 5GHz channels (for * 36..48 and 149..165). |
| 189 | * With respect to these flags, wpa_supplicant doesn't * start p2p |
| 190 | * operations on 5GHz channels. All the changes in world regulatory |
Hante Meuleman | d48200b | 2013-04-03 12:40:29 +0200 | [diff] [blame] | 191 | * domain are to be done here. |
| 192 | */ |
| 193 | static const struct ieee80211_regdomain brcmf_regdom = { |
| 194 | .n_reg_rules = 4, |
| 195 | .alpha2 = "99", |
| 196 | .reg_rules = { |
| 197 | /* IEEE 802.11b/g, channels 1..11 */ |
| 198 | REG_RULE(2412-10, 2472+10, 40, 6, 20, 0), |
| 199 | /* If any */ |
| 200 | /* IEEE 802.11 channel 14 - Only JP enables |
| 201 | * this and for 802.11b only |
| 202 | */ |
| 203 | REG_RULE(2484-10, 2484+10, 20, 6, 20, 0), |
| 204 | /* IEEE 802.11a, channel 36..64 */ |
Arend van Spriel | c555ecd | 2014-05-12 10:47:36 +0200 | [diff] [blame] | 205 | REG_RULE(5150-10, 5350+10, 80, 6, 20, 0), |
Hante Meuleman | d48200b | 2013-04-03 12:40:29 +0200 | [diff] [blame] | 206 | /* IEEE 802.11a, channel 100..165 */ |
Arend van Spriel | c555ecd | 2014-05-12 10:47:36 +0200 | [diff] [blame] | 207 | REG_RULE(5470-10, 5850+10, 80, 6, 20, 0), } |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 208 | }; |
| 209 | |
| 210 | static const u32 __wl_cipher_suites[] = { |
| 211 | WLAN_CIPHER_SUITE_WEP40, |
| 212 | WLAN_CIPHER_SUITE_WEP104, |
| 213 | WLAN_CIPHER_SUITE_TKIP, |
| 214 | WLAN_CIPHER_SUITE_CCMP, |
| 215 | WLAN_CIPHER_SUITE_AES_CMAC, |
| 216 | }; |
| 217 | |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 218 | /* Vendor specific ie. id = 221, oui and type defines exact ie */ |
| 219 | struct brcmf_vs_tlv { |
| 220 | u8 id; |
| 221 | u8 len; |
| 222 | u8 oui[3]; |
| 223 | u8 oui_type; |
| 224 | }; |
| 225 | |
| 226 | struct parsed_vndr_ie_info { |
| 227 | u8 *ie_ptr; |
| 228 | u32 ie_len; /* total length including id & length field */ |
| 229 | struct brcmf_vs_tlv vndrie; |
| 230 | }; |
| 231 | |
| 232 | struct parsed_vndr_ies { |
| 233 | u32 count; |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 234 | struct parsed_vndr_ie_info ie_info[VNDR_IE_PARSE_LIMIT]; |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 235 | }; |
| 236 | |
Hante Meuleman | 68ca395 | 2014-02-25 20:30:26 +0100 | [diff] [blame] | 237 | static int brcmf_roamoff; |
| 238 | module_param_named(roamoff, brcmf_roamoff, int, S_IRUSR); |
| 239 | MODULE_PARM_DESC(roamoff, "do not use internal roaming engine"); |
| 240 | |
Alwin Beukers | ef6ac17 | 2011-10-12 20:51:26 +0200 | [diff] [blame] | 241 | /* Quarter dBm units to mW |
| 242 | * Table starts at QDBM_OFFSET, so the first entry is mW for qdBm=153 |
| 243 | * Table is offset so the last entry is largest mW value that fits in |
| 244 | * a u16. |
| 245 | */ |
| 246 | |
| 247 | #define QDBM_OFFSET 153 /* Offset for first entry */ |
| 248 | #define QDBM_TABLE_LEN 40 /* Table size */ |
| 249 | |
| 250 | /* Smallest mW value that will round up to the first table entry, QDBM_OFFSET. |
| 251 | * Value is ( mW(QDBM_OFFSET - 1) + mW(QDBM_OFFSET) ) / 2 |
| 252 | */ |
| 253 | #define QDBM_TABLE_LOW_BOUND 6493 /* Low bound */ |
| 254 | |
| 255 | /* Largest mW value that will round down to the last table entry, |
| 256 | * QDBM_OFFSET + QDBM_TABLE_LEN-1. |
| 257 | * Value is ( mW(QDBM_OFFSET + QDBM_TABLE_LEN - 1) + |
| 258 | * mW(QDBM_OFFSET + QDBM_TABLE_LEN) ) / 2. |
| 259 | */ |
| 260 | #define QDBM_TABLE_HIGH_BOUND 64938 /* High bound */ |
| 261 | |
| 262 | static const u16 nqdBm_to_mW_map[QDBM_TABLE_LEN] = { |
| 263 | /* qdBm: +0 +1 +2 +3 +4 +5 +6 +7 */ |
| 264 | /* 153: */ 6683, 7079, 7499, 7943, 8414, 8913, 9441, 10000, |
| 265 | /* 161: */ 10593, 11220, 11885, 12589, 13335, 14125, 14962, 15849, |
| 266 | /* 169: */ 16788, 17783, 18836, 19953, 21135, 22387, 23714, 25119, |
| 267 | /* 177: */ 26607, 28184, 29854, 31623, 33497, 35481, 37584, 39811, |
| 268 | /* 185: */ 42170, 44668, 47315, 50119, 53088, 56234, 59566, 63096 |
| 269 | }; |
| 270 | |
| 271 | static u16 brcmf_qdbm_to_mw(u8 qdbm) |
| 272 | { |
| 273 | uint factor = 1; |
| 274 | int idx = qdbm - QDBM_OFFSET; |
| 275 | |
| 276 | if (idx >= QDBM_TABLE_LEN) |
| 277 | /* clamp to max u16 mW value */ |
| 278 | return 0xFFFF; |
| 279 | |
| 280 | /* scale the qdBm index up to the range of the table 0-40 |
| 281 | * where an offset of 40 qdBm equals a factor of 10 mW. |
| 282 | */ |
| 283 | while (idx < 0) { |
| 284 | idx += 40; |
| 285 | factor *= 10; |
| 286 | } |
| 287 | |
| 288 | /* return the mW value scaled down to the correct factor of 10, |
| 289 | * adding in factor/2 to get proper rounding. |
| 290 | */ |
| 291 | return (nqdBm_to_mW_map[idx] + factor / 2) / factor; |
| 292 | } |
| 293 | |
| 294 | static u8 brcmf_mw_to_qdbm(u16 mw) |
| 295 | { |
| 296 | u8 qdbm; |
| 297 | int offset; |
| 298 | uint mw_uint = mw; |
| 299 | uint boundary; |
| 300 | |
| 301 | /* handle boundary case */ |
| 302 | if (mw_uint <= 1) |
| 303 | return 0; |
| 304 | |
| 305 | offset = QDBM_OFFSET; |
| 306 | |
| 307 | /* move mw into the range of the table */ |
| 308 | while (mw_uint < QDBM_TABLE_LOW_BOUND) { |
| 309 | mw_uint *= 10; |
| 310 | offset -= 40; |
| 311 | } |
| 312 | |
| 313 | for (qdbm = 0; qdbm < QDBM_TABLE_LEN - 1; qdbm++) { |
| 314 | boundary = nqdBm_to_mW_map[qdbm] + (nqdBm_to_mW_map[qdbm + 1] - |
| 315 | nqdBm_to_mW_map[qdbm]) / 2; |
| 316 | if (mw_uint < boundary) |
| 317 | break; |
| 318 | } |
| 319 | |
| 320 | qdbm += (u8) offset; |
| 321 | |
| 322 | return qdbm; |
| 323 | } |
| 324 | |
Arend van Spriel | 5a394eb | 2014-05-27 12:56:15 +0200 | [diff] [blame] | 325 | static u16 chandef_to_chanspec(struct brcmu_d11inf *d11inf, |
| 326 | struct cfg80211_chan_def *ch) |
Arend van Spriel | 600a897 | 2014-05-12 10:47:39 +0200 | [diff] [blame] | 327 | { |
| 328 | struct brcmu_chan ch_inf; |
| 329 | s32 primary_offset; |
| 330 | |
| 331 | brcmf_dbg(TRACE, "chandef: control %d center %d width %d\n", |
| 332 | ch->chan->center_freq, ch->center_freq1, ch->width); |
| 333 | ch_inf.chnum = ieee80211_frequency_to_channel(ch->center_freq1); |
| 334 | primary_offset = ch->center_freq1 - ch->chan->center_freq; |
| 335 | switch (ch->width) { |
| 336 | case NL80211_CHAN_WIDTH_20: |
Arend van Spriel | 0cd75b1 | 2014-11-11 13:58:44 +0100 | [diff] [blame] | 337 | case NL80211_CHAN_WIDTH_20_NOHT: |
Arend van Spriel | 600a897 | 2014-05-12 10:47:39 +0200 | [diff] [blame] | 338 | ch_inf.bw = BRCMU_CHAN_BW_20; |
| 339 | WARN_ON(primary_offset != 0); |
| 340 | break; |
| 341 | case NL80211_CHAN_WIDTH_40: |
| 342 | ch_inf.bw = BRCMU_CHAN_BW_40; |
| 343 | if (primary_offset < 0) |
| 344 | ch_inf.sb = BRCMU_CHAN_SB_U; |
| 345 | else |
| 346 | ch_inf.sb = BRCMU_CHAN_SB_L; |
| 347 | break; |
| 348 | case NL80211_CHAN_WIDTH_80: |
| 349 | ch_inf.bw = BRCMU_CHAN_BW_80; |
| 350 | if (primary_offset < 0) { |
| 351 | if (primary_offset < -CH_10MHZ_APART) |
| 352 | ch_inf.sb = BRCMU_CHAN_SB_UU; |
| 353 | else |
| 354 | ch_inf.sb = BRCMU_CHAN_SB_UL; |
| 355 | } else { |
| 356 | if (primary_offset > CH_10MHZ_APART) |
| 357 | ch_inf.sb = BRCMU_CHAN_SB_LL; |
| 358 | else |
| 359 | ch_inf.sb = BRCMU_CHAN_SB_LU; |
| 360 | } |
| 361 | break; |
Arend van Spriel | 0cd75b1 | 2014-11-11 13:58:44 +0100 | [diff] [blame] | 362 | case NL80211_CHAN_WIDTH_80P80: |
| 363 | case NL80211_CHAN_WIDTH_160: |
| 364 | case NL80211_CHAN_WIDTH_5: |
| 365 | case NL80211_CHAN_WIDTH_10: |
Arend van Spriel | 600a897 | 2014-05-12 10:47:39 +0200 | [diff] [blame] | 366 | default: |
| 367 | WARN_ON_ONCE(1); |
| 368 | } |
| 369 | switch (ch->chan->band) { |
| 370 | case IEEE80211_BAND_2GHZ: |
| 371 | ch_inf.band = BRCMU_CHAN_BAND_2G; |
| 372 | break; |
| 373 | case IEEE80211_BAND_5GHZ: |
| 374 | ch_inf.band = BRCMU_CHAN_BAND_5G; |
| 375 | break; |
Arend van Spriel | 0cd75b1 | 2014-11-11 13:58:44 +0100 | [diff] [blame] | 376 | case IEEE80211_BAND_60GHZ: |
Arend van Spriel | 600a897 | 2014-05-12 10:47:39 +0200 | [diff] [blame] | 377 | default: |
| 378 | WARN_ON_ONCE(1); |
| 379 | } |
| 380 | d11inf->encchspec(&ch_inf); |
| 381 | |
| 382 | return ch_inf.chspec; |
| 383 | } |
| 384 | |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 385 | u16 channel_to_chanspec(struct brcmu_d11inf *d11inf, |
| 386 | struct ieee80211_channel *ch) |
Arend van Spriel | 6e18616 | 2012-10-22 10:36:22 -0700 | [diff] [blame] | 387 | { |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 388 | struct brcmu_chan ch_inf; |
Arend van Spriel | 6e18616 | 2012-10-22 10:36:22 -0700 | [diff] [blame] | 389 | |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 390 | ch_inf.chnum = ieee80211_frequency_to_channel(ch->center_freq); |
| 391 | ch_inf.bw = BRCMU_CHAN_BW_20; |
| 392 | d11inf->encchspec(&ch_inf); |
Arend van Spriel | 6e18616 | 2012-10-22 10:36:22 -0700 | [diff] [blame] | 393 | |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 394 | return ch_inf.chspec; |
Arend van Spriel | 6e18616 | 2012-10-22 10:36:22 -0700 | [diff] [blame] | 395 | } |
| 396 | |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 397 | /* Traverse a string of 1-byte tag/1-byte length/variable-length value |
| 398 | * triples, returning a pointer to the substring whose first element |
| 399 | * matches tag |
| 400 | */ |
Johannes Berg | 4b5800f | 2014-01-15 14:55:59 +0100 | [diff] [blame] | 401 | const struct brcmf_tlv * |
| 402 | brcmf_parse_tlvs(const void *buf, int buflen, uint key) |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 403 | { |
Johannes Berg | 4b5800f | 2014-01-15 14:55:59 +0100 | [diff] [blame] | 404 | const struct brcmf_tlv *elt = buf; |
| 405 | int totlen = buflen; |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 406 | |
| 407 | /* find tagged parameter */ |
| 408 | while (totlen >= TLV_HDR_LEN) { |
| 409 | int len = elt->len; |
| 410 | |
| 411 | /* validate remaining totlen */ |
| 412 | if ((elt->id == key) && (totlen >= (len + TLV_HDR_LEN))) |
| 413 | return elt; |
| 414 | |
| 415 | elt = (struct brcmf_tlv *)((u8 *)elt + (len + TLV_HDR_LEN)); |
| 416 | totlen -= (len + TLV_HDR_LEN); |
| 417 | } |
| 418 | |
| 419 | return NULL; |
| 420 | } |
| 421 | |
| 422 | /* Is any of the tlvs the expected entry? If |
| 423 | * not update the tlvs buffer pointer/length. |
| 424 | */ |
| 425 | static bool |
Johannes Berg | 4b5800f | 2014-01-15 14:55:59 +0100 | [diff] [blame] | 426 | brcmf_tlv_has_ie(const u8 *ie, const u8 **tlvs, u32 *tlvs_len, |
| 427 | const u8 *oui, u32 oui_len, u8 type) |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 428 | { |
| 429 | /* If the contents match the OUI and the type */ |
| 430 | if (ie[TLV_LEN_OFF] >= oui_len + 1 && |
| 431 | !memcmp(&ie[TLV_BODY_OFF], oui, oui_len) && |
| 432 | type == ie[TLV_BODY_OFF + oui_len]) { |
| 433 | return true; |
| 434 | } |
| 435 | |
| 436 | if (tlvs == NULL) |
| 437 | return false; |
| 438 | /* point to the next ie */ |
| 439 | ie += ie[TLV_LEN_OFF] + TLV_HDR_LEN; |
| 440 | /* calculate the length of the rest of the buffer */ |
| 441 | *tlvs_len -= (int)(ie - *tlvs); |
| 442 | /* update the pointer to the start of the buffer */ |
| 443 | *tlvs = ie; |
| 444 | |
| 445 | return false; |
| 446 | } |
| 447 | |
| 448 | static struct brcmf_vs_tlv * |
Johannes Berg | 4b5800f | 2014-01-15 14:55:59 +0100 | [diff] [blame] | 449 | brcmf_find_wpaie(const u8 *parse, u32 len) |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 450 | { |
Johannes Berg | 4b5800f | 2014-01-15 14:55:59 +0100 | [diff] [blame] | 451 | const struct brcmf_tlv *ie; |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 452 | |
| 453 | while ((ie = brcmf_parse_tlvs(parse, len, WLAN_EID_VENDOR_SPECIFIC))) { |
Johannes Berg | 4b5800f | 2014-01-15 14:55:59 +0100 | [diff] [blame] | 454 | if (brcmf_tlv_has_ie((const u8 *)ie, &parse, &len, |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 455 | WPA_OUI, TLV_OUI_LEN, WPA_OUI_TYPE)) |
| 456 | return (struct brcmf_vs_tlv *)ie; |
| 457 | } |
| 458 | return NULL; |
| 459 | } |
| 460 | |
| 461 | static struct brcmf_vs_tlv * |
Johannes Berg | 4b5800f | 2014-01-15 14:55:59 +0100 | [diff] [blame] | 462 | brcmf_find_wpsie(const u8 *parse, u32 len) |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 463 | { |
Johannes Berg | 4b5800f | 2014-01-15 14:55:59 +0100 | [diff] [blame] | 464 | const struct brcmf_tlv *ie; |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 465 | |
| 466 | while ((ie = brcmf_parse_tlvs(parse, len, WLAN_EID_VENDOR_SPECIFIC))) { |
| 467 | if (brcmf_tlv_has_ie((u8 *)ie, &parse, &len, |
| 468 | WPA_OUI, TLV_OUI_LEN, WPS_OUI_TYPE)) |
| 469 | return (struct brcmf_vs_tlv *)ie; |
| 470 | } |
| 471 | return NULL; |
| 472 | } |
| 473 | |
| 474 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 475 | static void convert_key_from_CPU(struct brcmf_wsec_key *key, |
| 476 | struct brcmf_wsec_key_le *key_le) |
| 477 | { |
| 478 | key_le->index = cpu_to_le32(key->index); |
| 479 | key_le->len = cpu_to_le32(key->len); |
| 480 | key_le->algo = cpu_to_le32(key->algo); |
| 481 | key_le->flags = cpu_to_le32(key->flags); |
| 482 | key_le->rxiv.hi = cpu_to_le32(key->rxiv.hi); |
| 483 | key_le->rxiv.lo = cpu_to_le16(key->rxiv.lo); |
| 484 | key_le->iv_initialized = cpu_to_le32(key->iv_initialized); |
| 485 | memcpy(key_le->data, key->data, sizeof(key->data)); |
| 486 | memcpy(key_le->ea, key->ea, sizeof(key->ea)); |
| 487 | } |
| 488 | |
Hante Meuleman | f09d0c0 | 2012-09-27 14:17:48 +0200 | [diff] [blame] | 489 | static int |
Hante Meuleman | 118eb30 | 2014-12-21 12:43:49 +0100 | [diff] [blame] | 490 | 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] | 491 | { |
| 492 | int err; |
| 493 | struct brcmf_wsec_key_le key_le; |
| 494 | |
| 495 | convert_key_from_CPU(key, &key_le); |
Hante Meuleman | f09d0c0 | 2012-09-27 14:17:48 +0200 | [diff] [blame] | 496 | |
Hante Meuleman | 118eb30 | 2014-12-21 12:43:49 +0100 | [diff] [blame] | 497 | brcmf_netdev_wait_pend8021x(ifp); |
Hante Meuleman | 81f5dcb | 2012-10-22 10:36:14 -0700 | [diff] [blame] | 498 | |
Hante Meuleman | 118eb30 | 2014-12-21 12:43:49 +0100 | [diff] [blame] | 499 | err = brcmf_fil_bsscfg_data_set(ifp, "wsec_key", &key_le, |
Hante Meuleman | 81f5dcb | 2012-10-22 10:36:14 -0700 | [diff] [blame] | 500 | sizeof(key_le)); |
Hante Meuleman | f09d0c0 | 2012-09-27 14:17:48 +0200 | [diff] [blame] | 501 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 502 | if (err) |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 503 | brcmf_err("wsec_key error (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 504 | return err; |
| 505 | } |
| 506 | |
Hante Meuleman | b365745 | 2013-05-27 21:09:53 +0200 | [diff] [blame] | 507 | static s32 |
| 508 | brcmf_configure_arp_offload(struct brcmf_if *ifp, bool enable) |
| 509 | { |
| 510 | s32 err; |
| 511 | u32 mode; |
| 512 | |
| 513 | if (enable) |
| 514 | mode = BRCMF_ARP_OL_AGENT | BRCMF_ARP_OL_PEER_AUTO_REPLY; |
| 515 | else |
| 516 | mode = 0; |
| 517 | |
| 518 | /* Try to set and enable ARP offload feature, this may fail, then it */ |
| 519 | /* is simply not supported and err 0 will be returned */ |
| 520 | err = brcmf_fil_iovar_int_set(ifp, "arp_ol", mode); |
| 521 | if (err) { |
| 522 | brcmf_dbg(TRACE, "failed to set ARP offload mode to 0x%x, err = %d\n", |
| 523 | mode, err); |
| 524 | err = 0; |
| 525 | } else { |
| 526 | err = brcmf_fil_iovar_int_set(ifp, "arpoe", enable); |
| 527 | if (err) { |
| 528 | brcmf_dbg(TRACE, "failed to configure (%d) ARP offload err = %d\n", |
| 529 | enable, err); |
| 530 | err = 0; |
| 531 | } else |
| 532 | brcmf_dbg(TRACE, "successfully configured (%d) ARP offload to 0x%x\n", |
| 533 | enable, mode); |
| 534 | } |
| 535 | |
| 536 | return err; |
| 537 | } |
| 538 | |
Hante Meuleman | 8851cce | 2014-07-30 13:20:02 +0200 | [diff] [blame] | 539 | static void |
| 540 | brcmf_cfg80211_update_proto_addr_mode(struct wireless_dev *wdev) |
| 541 | { |
Arend van Spriel | 8f2b459 | 2014-09-11 22:51:32 +0200 | [diff] [blame] | 542 | struct brcmf_cfg80211_vif *vif; |
| 543 | struct brcmf_if *ifp; |
| 544 | |
| 545 | vif = container_of(wdev, struct brcmf_cfg80211_vif, wdev); |
| 546 | ifp = vif->ifp; |
Hante Meuleman | 8851cce | 2014-07-30 13:20:02 +0200 | [diff] [blame] | 547 | |
| 548 | if ((wdev->iftype == NL80211_IFTYPE_ADHOC) || |
| 549 | (wdev->iftype == NL80211_IFTYPE_AP) || |
| 550 | (wdev->iftype == NL80211_IFTYPE_P2P_GO)) |
| 551 | brcmf_proto_configure_addr_mode(ifp->drvr, ifp->ifidx, |
| 552 | ADDR_DIRECT); |
| 553 | else |
| 554 | brcmf_proto_configure_addr_mode(ifp->drvr, ifp->ifidx, |
| 555 | ADDR_INDIRECT); |
| 556 | } |
| 557 | |
Hante Meuleman | a44aa40 | 2014-12-03 21:05:33 +0100 | [diff] [blame] | 558 | static int brcmf_cfg80211_request_ap_if(struct brcmf_if *ifp) |
| 559 | { |
| 560 | struct brcmf_mbss_ssid_le mbss_ssid_le; |
| 561 | int bsscfgidx; |
| 562 | int err; |
| 563 | |
| 564 | memset(&mbss_ssid_le, 0, sizeof(mbss_ssid_le)); |
| 565 | bsscfgidx = brcmf_get_next_free_bsscfgidx(ifp->drvr); |
| 566 | if (bsscfgidx < 0) |
| 567 | return bsscfgidx; |
| 568 | |
| 569 | mbss_ssid_le.bsscfgidx = cpu_to_le32(bsscfgidx); |
| 570 | mbss_ssid_le.SSID_len = cpu_to_le32(5); |
| 571 | sprintf(mbss_ssid_le.SSID, "ssid%d" , bsscfgidx); |
| 572 | |
| 573 | err = brcmf_fil_bsscfg_data_set(ifp, "bsscfg:ssid", &mbss_ssid_le, |
| 574 | sizeof(mbss_ssid_le)); |
| 575 | if (err < 0) |
| 576 | brcmf_err("setting ssid failed %d\n", err); |
| 577 | |
| 578 | return err; |
| 579 | } |
| 580 | |
| 581 | /** |
| 582 | * brcmf_ap_add_vif() - create a new AP virtual interface for multiple BSS |
| 583 | * |
| 584 | * @wiphy: wiphy device of new interface. |
| 585 | * @name: name of the new interface. |
| 586 | * @flags: not used. |
| 587 | * @params: contains mac address for AP device. |
| 588 | */ |
| 589 | static |
| 590 | struct wireless_dev *brcmf_ap_add_vif(struct wiphy *wiphy, const char *name, |
| 591 | u32 *flags, struct vif_params *params) |
| 592 | { |
| 593 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); |
| 594 | struct brcmf_if *ifp = netdev_priv(cfg_to_ndev(cfg)); |
| 595 | struct brcmf_cfg80211_vif *vif; |
| 596 | int err; |
| 597 | |
| 598 | if (brcmf_cfg80211_vif_event_armed(cfg)) |
| 599 | return ERR_PTR(-EBUSY); |
| 600 | |
| 601 | brcmf_dbg(INFO, "Adding vif \"%s\"\n", name); |
| 602 | |
| 603 | vif = brcmf_alloc_vif(cfg, NL80211_IFTYPE_AP, false); |
| 604 | if (IS_ERR(vif)) |
| 605 | return (struct wireless_dev *)vif; |
| 606 | |
| 607 | brcmf_cfg80211_arm_vif_event(cfg, vif); |
| 608 | |
| 609 | err = brcmf_cfg80211_request_ap_if(ifp); |
| 610 | if (err) { |
| 611 | brcmf_cfg80211_arm_vif_event(cfg, NULL); |
| 612 | goto fail; |
| 613 | } |
| 614 | |
| 615 | /* wait for firmware event */ |
| 616 | err = brcmf_cfg80211_wait_vif_event_timeout(cfg, BRCMF_E_IF_ADD, |
| 617 | msecs_to_jiffies(1500)); |
| 618 | brcmf_cfg80211_arm_vif_event(cfg, NULL); |
| 619 | if (!err) { |
| 620 | brcmf_err("timeout occurred\n"); |
| 621 | err = -EIO; |
| 622 | goto fail; |
| 623 | } |
| 624 | |
| 625 | /* interface created in firmware */ |
| 626 | ifp = vif->ifp; |
| 627 | if (!ifp) { |
| 628 | brcmf_err("no if pointer provided\n"); |
| 629 | err = -ENOENT; |
| 630 | goto fail; |
| 631 | } |
| 632 | |
| 633 | strncpy(ifp->ndev->name, name, sizeof(ifp->ndev->name) - 1); |
| 634 | err = brcmf_net_attach(ifp, true); |
| 635 | if (err) { |
| 636 | brcmf_err("Registering netdevice failed\n"); |
| 637 | goto fail; |
| 638 | } |
| 639 | |
| 640 | return &ifp->vif->wdev; |
| 641 | |
| 642 | fail: |
| 643 | brcmf_free_vif(vif); |
| 644 | return ERR_PTR(err); |
| 645 | } |
| 646 | |
Arend van Spriel | 967fe2c | 2014-03-15 17:18:21 +0100 | [diff] [blame] | 647 | static bool brcmf_is_apmode(struct brcmf_cfg80211_vif *vif) |
| 648 | { |
| 649 | enum nl80211_iftype iftype; |
| 650 | |
| 651 | iftype = vif->wdev.iftype; |
| 652 | return iftype == NL80211_IFTYPE_AP || iftype == NL80211_IFTYPE_P2P_GO; |
| 653 | } |
| 654 | |
| 655 | static bool brcmf_is_ibssmode(struct brcmf_cfg80211_vif *vif) |
| 656 | { |
| 657 | return vif->wdev.iftype == NL80211_IFTYPE_ADHOC; |
| 658 | } |
| 659 | |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 660 | static struct wireless_dev *brcmf_cfg80211_add_iface(struct wiphy *wiphy, |
| 661 | const char *name, |
Tom Gundersen | 6bab2e19 | 2015-03-18 11:13:39 +0100 | [diff] [blame] | 662 | unsigned char name_assign_type, |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 663 | enum nl80211_iftype type, |
| 664 | u32 *flags, |
| 665 | struct vif_params *params) |
| 666 | { |
Hante Meuleman | 8851cce | 2014-07-30 13:20:02 +0200 | [diff] [blame] | 667 | struct wireless_dev *wdev; |
| 668 | |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 669 | brcmf_dbg(TRACE, "enter: %s type %d\n", name, type); |
| 670 | switch (type) { |
| 671 | case NL80211_IFTYPE_ADHOC: |
| 672 | case NL80211_IFTYPE_STATION: |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 673 | case NL80211_IFTYPE_AP_VLAN: |
| 674 | case NL80211_IFTYPE_WDS: |
| 675 | case NL80211_IFTYPE_MONITOR: |
| 676 | case NL80211_IFTYPE_MESH_POINT: |
| 677 | return ERR_PTR(-EOPNOTSUPP); |
Hante Meuleman | a44aa40 | 2014-12-03 21:05:33 +0100 | [diff] [blame] | 678 | case NL80211_IFTYPE_AP: |
| 679 | wdev = brcmf_ap_add_vif(wiphy, name, flags, params); |
| 680 | if (!IS_ERR(wdev)) |
| 681 | brcmf_cfg80211_update_proto_addr_mode(wdev); |
| 682 | return wdev; |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 683 | case NL80211_IFTYPE_P2P_CLIENT: |
| 684 | case NL80211_IFTYPE_P2P_GO: |
Arend van Spriel | 27f10e3 | 2013-04-05 10:57:50 +0200 | [diff] [blame] | 685 | case NL80211_IFTYPE_P2P_DEVICE: |
Tom Gundersen | 6bab2e19 | 2015-03-18 11:13:39 +0100 | [diff] [blame] | 686 | 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] | 687 | if (!IS_ERR(wdev)) |
| 688 | brcmf_cfg80211_update_proto_addr_mode(wdev); |
| 689 | return wdev; |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 690 | case NL80211_IFTYPE_UNSPECIFIED: |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 691 | default: |
| 692 | return ERR_PTR(-EINVAL); |
| 693 | } |
| 694 | } |
| 695 | |
Daniel Kim | 5e787f7 | 2014-06-21 12:11:18 +0200 | [diff] [blame] | 696 | static void brcmf_scan_config_mpc(struct brcmf_if *ifp, int mpc) |
| 697 | { |
Arend van Spriel | c08437b | 2014-07-12 08:49:39 +0200 | [diff] [blame] | 698 | if (brcmf_feat_is_quirk_enabled(ifp, BRCMF_FEAT_QUIRK_NEED_MPC)) |
Daniel Kim | 5e787f7 | 2014-06-21 12:11:18 +0200 | [diff] [blame] | 699 | brcmf_set_mpc(ifp, mpc); |
| 700 | } |
| 701 | |
Arend van Spriel | f96aa07 | 2013-04-05 10:57:48 +0200 | [diff] [blame] | 702 | void brcmf_set_mpc(struct brcmf_if *ifp, int mpc) |
Arend van Spriel | 5f4f9f1 | 2013-02-08 15:53:41 +0100 | [diff] [blame] | 703 | { |
Arend van Spriel | 5f4f9f1 | 2013-02-08 15:53:41 +0100 | [diff] [blame] | 704 | s32 err = 0; |
| 705 | |
| 706 | if (check_vif_up(ifp->vif)) { |
| 707 | err = brcmf_fil_iovar_int_set(ifp, "mpc", mpc); |
| 708 | if (err) { |
| 709 | brcmf_err("fail to set mpc\n"); |
| 710 | return; |
| 711 | } |
| 712 | brcmf_dbg(INFO, "MPC : %d\n", mpc); |
| 713 | } |
| 714 | } |
| 715 | |
Arend van Spriel | a0f472a | 2013-04-05 10:57:49 +0200 | [diff] [blame] | 716 | s32 brcmf_notify_escan_complete(struct brcmf_cfg80211_info *cfg, |
| 717 | struct brcmf_if *ifp, bool aborted, |
| 718 | bool fw_abort) |
Arend van Spriel | 5f4f9f1 | 2013-02-08 15:53:41 +0100 | [diff] [blame] | 719 | { |
| 720 | struct brcmf_scan_params_le params_le; |
| 721 | struct cfg80211_scan_request *scan_request; |
| 722 | s32 err = 0; |
| 723 | |
| 724 | brcmf_dbg(SCAN, "Enter\n"); |
| 725 | |
| 726 | /* clear scan request, because the FW abort can cause a second call */ |
| 727 | /* to this functon and might cause a double cfg80211_scan_done */ |
| 728 | scan_request = cfg->scan_request; |
| 729 | cfg->scan_request = NULL; |
| 730 | |
| 731 | if (timer_pending(&cfg->escan_timeout)) |
| 732 | del_timer_sync(&cfg->escan_timeout); |
| 733 | |
| 734 | if (fw_abort) { |
| 735 | /* Do a scan abort to stop the driver's scan engine */ |
| 736 | brcmf_dbg(SCAN, "ABORT scan in firmware\n"); |
| 737 | memset(¶ms_le, 0, sizeof(params_le)); |
Joe Perches | 93803b3 | 2015-03-02 19:54:49 -0800 | [diff] [blame] | 738 | eth_broadcast_addr(params_le.bssid); |
Arend van Spriel | 5f4f9f1 | 2013-02-08 15:53:41 +0100 | [diff] [blame] | 739 | params_le.bss_type = DOT11_BSSTYPE_ANY; |
| 740 | params_le.scan_type = 0; |
| 741 | params_le.channel_num = cpu_to_le32(1); |
| 742 | params_le.nprobes = cpu_to_le32(1); |
| 743 | params_le.active_time = cpu_to_le32(-1); |
| 744 | params_le.passive_time = cpu_to_le32(-1); |
| 745 | params_le.home_time = cpu_to_le32(-1); |
| 746 | /* Scan is aborted by setting channel_list[0] to -1 */ |
| 747 | params_le.channel_list[0] = cpu_to_le16(-1); |
| 748 | /* E-Scan (or anyother type) can be aborted by SCAN */ |
Arend van Spriel | f96aa07 | 2013-04-05 10:57:48 +0200 | [diff] [blame] | 749 | err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SCAN, |
Arend van Spriel | 5f4f9f1 | 2013-02-08 15:53:41 +0100 | [diff] [blame] | 750 | ¶ms_le, sizeof(params_le)); |
| 751 | if (err) |
| 752 | brcmf_err("Scan abort failed\n"); |
| 753 | } |
Arend van Spriel | 0f0fe99 | 2014-05-27 12:56:14 +0200 | [diff] [blame] | 754 | |
Daniel Kim | 5e787f7 | 2014-06-21 12:11:18 +0200 | [diff] [blame] | 755 | brcmf_scan_config_mpc(ifp, 1); |
Arend van Spriel | 0f0fe99 | 2014-05-27 12:56:14 +0200 | [diff] [blame] | 756 | |
Arend van Spriel | 5f4f9f1 | 2013-02-08 15:53:41 +0100 | [diff] [blame] | 757 | /* |
| 758 | * e-scan can be initiated by scheduled scan |
| 759 | * which takes precedence. |
| 760 | */ |
| 761 | if (cfg->sched_escan) { |
| 762 | brcmf_dbg(SCAN, "scheduled scan completed\n"); |
| 763 | cfg->sched_escan = false; |
| 764 | if (!aborted) |
| 765 | cfg80211_sched_scan_results(cfg_to_wiphy(cfg)); |
Arend van Spriel | 5f4f9f1 | 2013-02-08 15:53:41 +0100 | [diff] [blame] | 766 | } else if (scan_request) { |
| 767 | brcmf_dbg(SCAN, "ESCAN Completed scan: %s\n", |
| 768 | aborted ? "Aborted" : "Done"); |
| 769 | cfg80211_scan_done(scan_request, aborted); |
Arend van Spriel | 5f4f9f1 | 2013-02-08 15:53:41 +0100 | [diff] [blame] | 770 | } |
Hante Meuleman | 6eda4e2 | 2013-02-08 15:54:02 +0100 | [diff] [blame] | 771 | if (!test_and_clear_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status)) |
| 772 | brcmf_dbg(SCAN, "Scan complete, probably P2P scan\n"); |
Arend van Spriel | 5f4f9f1 | 2013-02-08 15:53:41 +0100 | [diff] [blame] | 773 | |
| 774 | return err; |
| 775 | } |
| 776 | |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 777 | static |
| 778 | int brcmf_cfg80211_del_iface(struct wiphy *wiphy, struct wireless_dev *wdev) |
| 779 | { |
Arend van Spriel | 5f4f9f1 | 2013-02-08 15:53:41 +0100 | [diff] [blame] | 780 | struct brcmf_cfg80211_info *cfg = wiphy_priv(wiphy); |
| 781 | struct net_device *ndev = wdev->netdev; |
| 782 | |
| 783 | /* vif event pending in firmware */ |
| 784 | if (brcmf_cfg80211_vif_event_armed(cfg)) |
| 785 | return -EBUSY; |
| 786 | |
| 787 | if (ndev) { |
| 788 | if (test_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status) && |
Arend van Spriel | a0f472a | 2013-04-05 10:57:49 +0200 | [diff] [blame] | 789 | cfg->escan_info.ifp == netdev_priv(ndev)) |
| 790 | brcmf_notify_escan_complete(cfg, netdev_priv(ndev), |
| 791 | true, true); |
Arend van Spriel | 5f4f9f1 | 2013-02-08 15:53:41 +0100 | [diff] [blame] | 792 | |
| 793 | brcmf_fil_iovar_int_set(netdev_priv(ndev), "mpc", 1); |
| 794 | } |
| 795 | |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 796 | switch (wdev->iftype) { |
| 797 | case NL80211_IFTYPE_ADHOC: |
| 798 | case NL80211_IFTYPE_STATION: |
| 799 | case NL80211_IFTYPE_AP: |
| 800 | case NL80211_IFTYPE_AP_VLAN: |
| 801 | case NL80211_IFTYPE_WDS: |
| 802 | case NL80211_IFTYPE_MONITOR: |
| 803 | case NL80211_IFTYPE_MESH_POINT: |
| 804 | return -EOPNOTSUPP; |
| 805 | case NL80211_IFTYPE_P2P_CLIENT: |
| 806 | case NL80211_IFTYPE_P2P_GO: |
Arend van Spriel | 27f10e3 | 2013-04-05 10:57:50 +0200 | [diff] [blame] | 807 | case NL80211_IFTYPE_P2P_DEVICE: |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 808 | return brcmf_p2p_del_vif(wiphy, wdev); |
| 809 | case NL80211_IFTYPE_UNSPECIFIED: |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 810 | default: |
| 811 | return -EINVAL; |
| 812 | } |
| 813 | return -EOPNOTSUPP; |
| 814 | } |
| 815 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 816 | static s32 |
| 817 | brcmf_cfg80211_change_iface(struct wiphy *wiphy, struct net_device *ndev, |
| 818 | enum nl80211_iftype type, u32 *flags, |
| 819 | struct vif_params *params) |
| 820 | { |
Hante Meuleman | 7a5c1f6 | 2013-02-08 15:53:44 +0100 | [diff] [blame] | 821 | struct brcmf_cfg80211_info *cfg = wiphy_priv(wiphy); |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 822 | struct brcmf_if *ifp = netdev_priv(ndev); |
Arend van Spriel | 128ce3b | 2012-11-28 21:44:12 +0100 | [diff] [blame] | 823 | struct brcmf_cfg80211_vif *vif = ifp->vif; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 824 | s32 infra = 0; |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 825 | s32 ap = 0; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 826 | s32 err = 0; |
| 827 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 828 | brcmf_dbg(TRACE, "Enter, ndev=%p, type=%d\n", ndev, type); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 829 | |
| 830 | switch (type) { |
| 831 | case NL80211_IFTYPE_MONITOR: |
| 832 | case NL80211_IFTYPE_WDS: |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 833 | brcmf_err("type (%d) : currently we do not support this type\n", |
| 834 | type); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 835 | return -EOPNOTSUPP; |
| 836 | case NL80211_IFTYPE_ADHOC: |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 837 | infra = 0; |
| 838 | break; |
| 839 | case NL80211_IFTYPE_STATION: |
Hante Meuleman | 1bc7c65 | 2013-02-08 15:53:56 +0100 | [diff] [blame] | 840 | /* Ignore change for p2p IF. Unclear why supplicant does this */ |
| 841 | if ((vif->wdev.iftype == NL80211_IFTYPE_P2P_CLIENT) || |
| 842 | (vif->wdev.iftype == NL80211_IFTYPE_P2P_GO)) { |
| 843 | brcmf_dbg(TRACE, "Ignoring cmd for p2p if\n"); |
| 844 | /* WAR: It is unexpected to get a change of VIF for P2P |
| 845 | * IF, but it happens. The request can not be handled |
| 846 | * but returning EPERM causes a crash. Returning 0 |
| 847 | * without setting ieee80211_ptr->iftype causes trace |
| 848 | * (WARN_ON) but it works with wpa_supplicant |
| 849 | */ |
| 850 | return 0; |
| 851 | } |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 852 | infra = 1; |
| 853 | break; |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 854 | case NL80211_IFTYPE_AP: |
Hante Meuleman | 7a5c1f6 | 2013-02-08 15:53:44 +0100 | [diff] [blame] | 855 | case NL80211_IFTYPE_P2P_GO: |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 856 | ap = 1; |
| 857 | break; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 858 | default: |
| 859 | err = -EINVAL; |
| 860 | goto done; |
| 861 | } |
| 862 | |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 863 | if (ap) { |
Hante Meuleman | 7a5c1f6 | 2013-02-08 15:53:44 +0100 | [diff] [blame] | 864 | if (type == NL80211_IFTYPE_P2P_GO) { |
| 865 | brcmf_dbg(INFO, "IF Type = P2P GO\n"); |
| 866 | err = brcmf_p2p_ifchange(cfg, BRCMF_FIL_P2P_IF_GO); |
| 867 | } |
| 868 | if (!err) { |
| 869 | set_bit(BRCMF_VIF_STATUS_AP_CREATING, &vif->sme_state); |
| 870 | brcmf_dbg(INFO, "IF Type = AP\n"); |
| 871 | } |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 872 | } else { |
Arend van Spriel | 128ce3b | 2012-11-28 21:44:12 +0100 | [diff] [blame] | 873 | err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_INFRA, infra); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 874 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 875 | brcmf_err("WLC_SET_INFRA error (%d)\n", err); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 876 | err = -EAGAIN; |
| 877 | goto done; |
| 878 | } |
Arend van Spriel | 967fe2c | 2014-03-15 17:18:21 +0100 | [diff] [blame] | 879 | brcmf_dbg(INFO, "IF Type = %s\n", brcmf_is_ibssmode(vif) ? |
Arend van Spriel | 647c9ae | 2012-12-05 15:26:01 +0100 | [diff] [blame] | 880 | "Adhoc" : "Infra"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 881 | } |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 882 | ndev->ieee80211_ptr->iftype = type; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 883 | |
Hante Meuleman | 8851cce | 2014-07-30 13:20:02 +0200 | [diff] [blame] | 884 | brcmf_cfg80211_update_proto_addr_mode(&vif->wdev); |
| 885 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 886 | done: |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 887 | brcmf_dbg(TRACE, "Exit\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 888 | |
| 889 | return err; |
| 890 | } |
| 891 | |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 892 | static void brcmf_escan_prep(struct brcmf_cfg80211_info *cfg, |
| 893 | struct brcmf_scan_params_le *params_le, |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 894 | struct cfg80211_scan_request *request) |
| 895 | { |
| 896 | u32 n_ssids; |
| 897 | u32 n_channels; |
| 898 | s32 i; |
| 899 | s32 offset; |
Arend van Spriel | 029591f | 2012-09-19 22:21:06 +0200 | [diff] [blame] | 900 | u16 chanspec; |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 901 | char *ptr; |
Arend van Spriel | 029591f | 2012-09-19 22:21:06 +0200 | [diff] [blame] | 902 | struct brcmf_ssid_le ssid_le; |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 903 | |
Joe Perches | 93803b3 | 2015-03-02 19:54:49 -0800 | [diff] [blame] | 904 | eth_broadcast_addr(params_le->bssid); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 905 | params_le->bss_type = DOT11_BSSTYPE_ANY; |
| 906 | params_le->scan_type = 0; |
| 907 | params_le->channel_num = 0; |
| 908 | params_le->nprobes = cpu_to_le32(-1); |
| 909 | params_le->active_time = cpu_to_le32(-1); |
| 910 | params_le->passive_time = cpu_to_le32(-1); |
| 911 | params_le->home_time = cpu_to_le32(-1); |
| 912 | memset(¶ms_le->ssid_le, 0, sizeof(params_le->ssid_le)); |
| 913 | |
| 914 | /* if request is null exit so it will be all channel broadcast scan */ |
| 915 | if (!request) |
| 916 | return; |
| 917 | |
| 918 | n_ssids = request->n_ssids; |
| 919 | n_channels = request->n_channels; |
| 920 | /* Copy channel array if applicable */ |
Arend van Spriel | 4e8a008 | 2012-12-05 15:26:03 +0100 | [diff] [blame] | 921 | brcmf_dbg(SCAN, "### List of channelspecs to scan ### %d\n", |
| 922 | n_channels); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 923 | if (n_channels > 0) { |
| 924 | for (i = 0; i < n_channels; i++) { |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 925 | chanspec = channel_to_chanspec(&cfg->d11inf, |
| 926 | request->channels[i]); |
Arend van Spriel | 4e8a008 | 2012-12-05 15:26:03 +0100 | [diff] [blame] | 927 | brcmf_dbg(SCAN, "Chan : %d, Channel spec: %x\n", |
| 928 | request->channels[i]->hw_value, chanspec); |
Arend van Spriel | 029591f | 2012-09-19 22:21:06 +0200 | [diff] [blame] | 929 | params_le->channel_list[i] = cpu_to_le16(chanspec); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 930 | } |
| 931 | } else { |
Arend van Spriel | 4e8a008 | 2012-12-05 15:26:03 +0100 | [diff] [blame] | 932 | brcmf_dbg(SCAN, "Scanning all channels\n"); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 933 | } |
| 934 | /* Copy ssid array if applicable */ |
Arend van Spriel | 4e8a008 | 2012-12-05 15:26:03 +0100 | [diff] [blame] | 935 | brcmf_dbg(SCAN, "### List of SSIDs to scan ### %d\n", n_ssids); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 936 | if (n_ssids > 0) { |
| 937 | offset = offsetof(struct brcmf_scan_params_le, channel_list) + |
| 938 | n_channels * sizeof(u16); |
| 939 | offset = roundup(offset, sizeof(u32)); |
| 940 | ptr = (char *)params_le + offset; |
| 941 | for (i = 0; i < n_ssids; i++) { |
Arend van Spriel | 029591f | 2012-09-19 22:21:06 +0200 | [diff] [blame] | 942 | memset(&ssid_le, 0, sizeof(ssid_le)); |
| 943 | ssid_le.SSID_len = |
| 944 | cpu_to_le32(request->ssids[i].ssid_len); |
| 945 | memcpy(ssid_le.SSID, request->ssids[i].ssid, |
| 946 | request->ssids[i].ssid_len); |
| 947 | if (!ssid_le.SSID_len) |
Arend van Spriel | 4e8a008 | 2012-12-05 15:26:03 +0100 | [diff] [blame] | 948 | brcmf_dbg(SCAN, "%d: Broadcast scan\n", i); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 949 | else |
Arend van Spriel | 4e8a008 | 2012-12-05 15:26:03 +0100 | [diff] [blame] | 950 | brcmf_dbg(SCAN, "%d: scan for %s size =%d\n", |
| 951 | i, ssid_le.SSID, ssid_le.SSID_len); |
Arend van Spriel | 029591f | 2012-09-19 22:21:06 +0200 | [diff] [blame] | 952 | memcpy(ptr, &ssid_le, sizeof(ssid_le)); |
| 953 | ptr += sizeof(ssid_le); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 954 | } |
| 955 | } else { |
Arend van Spriel | 4e8a008 | 2012-12-05 15:26:03 +0100 | [diff] [blame] | 956 | brcmf_dbg(SCAN, "Broadcast scan %p\n", request->ssids); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 957 | if ((request->ssids) && request->ssids->ssid_len) { |
Arend van Spriel | 4e8a008 | 2012-12-05 15:26:03 +0100 | [diff] [blame] | 958 | brcmf_dbg(SCAN, "SSID %s len=%d\n", |
| 959 | params_le->ssid_le.SSID, |
| 960 | request->ssids->ssid_len); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 961 | params_le->ssid_le.SSID_len = |
| 962 | cpu_to_le32(request->ssids->ssid_len); |
| 963 | memcpy(¶ms_le->ssid_le.SSID, request->ssids->ssid, |
| 964 | request->ssids->ssid_len); |
| 965 | } |
| 966 | } |
| 967 | /* Adding mask to channel numbers */ |
| 968 | params_le->channel_num = |
| 969 | cpu_to_le32((n_ssids << BRCMF_SCAN_PARAMS_NSSID_SHIFT) | |
| 970 | (n_channels & BRCMF_SCAN_PARAMS_COUNT_MASK)); |
| 971 | } |
| 972 | |
| 973 | static s32 |
Arend van Spriel | a0f472a | 2013-04-05 10:57:49 +0200 | [diff] [blame] | 974 | brcmf_run_escan(struct brcmf_cfg80211_info *cfg, struct brcmf_if *ifp, |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 975 | struct cfg80211_scan_request *request, u16 action) |
| 976 | { |
| 977 | s32 params_size = BRCMF_SCAN_PARAMS_FIXED_SIZE + |
| 978 | offsetof(struct brcmf_escan_params_le, params_le); |
| 979 | struct brcmf_escan_params_le *params; |
| 980 | s32 err = 0; |
| 981 | |
Arend van Spriel | 4e8a008 | 2012-12-05 15:26:03 +0100 | [diff] [blame] | 982 | brcmf_dbg(SCAN, "E-SCAN START\n"); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 983 | |
| 984 | if (request != NULL) { |
| 985 | /* Allocate space for populating ssids in struct */ |
| 986 | params_size += sizeof(u32) * ((request->n_channels + 1) / 2); |
| 987 | |
| 988 | /* Allocate space for populating ssids in struct */ |
| 989 | params_size += sizeof(struct brcmf_ssid) * request->n_ssids; |
| 990 | } |
| 991 | |
| 992 | params = kzalloc(params_size, GFP_KERNEL); |
| 993 | if (!params) { |
| 994 | err = -ENOMEM; |
| 995 | goto exit; |
| 996 | } |
| 997 | BUG_ON(params_size + sizeof("escan") >= BRCMF_DCMD_MEDLEN); |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 998 | brcmf_escan_prep(cfg, ¶ms->params_le, request); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 999 | params->version = cpu_to_le32(BRCMF_ESCAN_REQ_VERSION); |
| 1000 | params->action = cpu_to_le16(action); |
| 1001 | params->sync_id = cpu_to_le16(0x1234); |
| 1002 | |
Arend van Spriel | a0f472a | 2013-04-05 10:57:49 +0200 | [diff] [blame] | 1003 | err = brcmf_fil_iovar_data_set(ifp, "escan", params, params_size); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1004 | if (err) { |
| 1005 | if (err == -EBUSY) |
Arend van Spriel | 647c9ae | 2012-12-05 15:26:01 +0100 | [diff] [blame] | 1006 | brcmf_dbg(INFO, "system busy : escan canceled\n"); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1007 | else |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1008 | brcmf_err("error (%d)\n", err); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1009 | } |
| 1010 | |
| 1011 | kfree(params); |
| 1012 | exit: |
| 1013 | return err; |
| 1014 | } |
| 1015 | |
| 1016 | static s32 |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 1017 | brcmf_do_escan(struct brcmf_cfg80211_info *cfg, struct wiphy *wiphy, |
Arend van Spriel | a0f472a | 2013-04-05 10:57:49 +0200 | [diff] [blame] | 1018 | struct brcmf_if *ifp, struct cfg80211_scan_request *request) |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1019 | { |
| 1020 | s32 err; |
Hante Meuleman | 81f5dcb | 2012-10-22 10:36:14 -0700 | [diff] [blame] | 1021 | u32 passive_scan; |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1022 | struct brcmf_scan_results *results; |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 1023 | struct escan_info *escan = &cfg->escan_info; |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1024 | |
Arend van Spriel | 4e8a008 | 2012-12-05 15:26:03 +0100 | [diff] [blame] | 1025 | brcmf_dbg(SCAN, "Enter\n"); |
Arend van Spriel | a0f472a | 2013-04-05 10:57:49 +0200 | [diff] [blame] | 1026 | escan->ifp = ifp; |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 1027 | escan->wiphy = wiphy; |
| 1028 | escan->escan_state = WL_ESCAN_STATE_SCANNING; |
Hante Meuleman | 81f5dcb | 2012-10-22 10:36:14 -0700 | [diff] [blame] | 1029 | passive_scan = cfg->active_scan ? 0 : 1; |
Arend van Spriel | f96aa07 | 2013-04-05 10:57:48 +0200 | [diff] [blame] | 1030 | err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_PASSIVE_SCAN, |
Hante Meuleman | 81f5dcb | 2012-10-22 10:36:14 -0700 | [diff] [blame] | 1031 | passive_scan); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1032 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1033 | brcmf_err("error (%d)\n", err); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1034 | return err; |
| 1035 | } |
Daniel Kim | 5e787f7 | 2014-06-21 12:11:18 +0200 | [diff] [blame] | 1036 | brcmf_scan_config_mpc(ifp, 0); |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 1037 | results = (struct brcmf_scan_results *)cfg->escan_info.escan_buf; |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1038 | results->version = 0; |
| 1039 | results->count = 0; |
| 1040 | results->buflen = WL_ESCAN_RESULTS_FIXED_SIZE; |
| 1041 | |
Arend van Spriel | a0f472a | 2013-04-05 10:57:49 +0200 | [diff] [blame] | 1042 | err = escan->run(cfg, ifp, request, WL_ESCAN_ACTION_START); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1043 | if (err) |
Daniel Kim | 5e787f7 | 2014-06-21 12:11:18 +0200 | [diff] [blame] | 1044 | brcmf_scan_config_mpc(ifp, 1); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1045 | return err; |
| 1046 | } |
| 1047 | |
| 1048 | static s32 |
Arend van Spriel | a0f472a | 2013-04-05 10:57:49 +0200 | [diff] [blame] | 1049 | brcmf_cfg80211_escan(struct wiphy *wiphy, struct brcmf_cfg80211_vif *vif, |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1050 | struct cfg80211_scan_request *request, |
| 1051 | struct cfg80211_ssid *this_ssid) |
| 1052 | { |
Arend van Spriel | a0f472a | 2013-04-05 10:57:49 +0200 | [diff] [blame] | 1053 | struct brcmf_if *ifp = vif->ifp; |
| 1054 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1055 | struct cfg80211_ssid *ssids; |
Hante Meuleman | f0799895 | 2012-11-05 16:22:13 -0800 | [diff] [blame] | 1056 | struct brcmf_cfg80211_scan_req *sr = &cfg->scan_req_int; |
Hante Meuleman | 81f5dcb | 2012-10-22 10:36:14 -0700 | [diff] [blame] | 1057 | u32 passive_scan; |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1058 | bool escan_req; |
| 1059 | bool spec_scan; |
| 1060 | s32 err; |
| 1061 | u32 SSID_len; |
| 1062 | |
Arend van Spriel | 4e8a008 | 2012-12-05 15:26:03 +0100 | [diff] [blame] | 1063 | brcmf_dbg(SCAN, "START ESCAN\n"); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1064 | |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 1065 | if (test_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status)) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1066 | brcmf_err("Scanning already: status (%lu)\n", cfg->scan_status); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1067 | return -EAGAIN; |
| 1068 | } |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 1069 | if (test_bit(BRCMF_SCAN_STATUS_ABORT, &cfg->scan_status)) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1070 | brcmf_err("Scanning being aborted: status (%lu)\n", |
| 1071 | cfg->scan_status); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1072 | return -EAGAIN; |
| 1073 | } |
Arend van Spriel | 1687eee | 2013-04-23 12:53:11 +0200 | [diff] [blame] | 1074 | if (test_bit(BRCMF_SCAN_STATUS_SUPPRESS, &cfg->scan_status)) { |
| 1075 | brcmf_err("Scanning suppressed: status (%lu)\n", |
| 1076 | cfg->scan_status); |
| 1077 | return -EAGAIN; |
| 1078 | } |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 1079 | if (test_bit(BRCMF_VIF_STATUS_CONNECTING, &ifp->vif->sme_state)) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1080 | brcmf_err("Connecting: status (%lu)\n", ifp->vif->sme_state); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1081 | return -EAGAIN; |
| 1082 | } |
| 1083 | |
Hante Meuleman | 0f8ffe1 | 2013-02-08 15:53:42 +0100 | [diff] [blame] | 1084 | /* 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] | 1085 | if (vif == cfg->p2p.bss_idx[P2PAPI_BSSCFG_DEVICE].vif) |
| 1086 | vif = cfg->p2p.bss_idx[P2PAPI_BSSCFG_PRIMARY].vif; |
Hante Meuleman | 0f8ffe1 | 2013-02-08 15:53:42 +0100 | [diff] [blame] | 1087 | |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1088 | escan_req = false; |
| 1089 | if (request) { |
| 1090 | /* scan bss */ |
| 1091 | ssids = request->ssids; |
| 1092 | escan_req = true; |
| 1093 | } else { |
| 1094 | /* scan in ibss */ |
| 1095 | /* we don't do escan in ibss */ |
| 1096 | ssids = this_ssid; |
| 1097 | } |
| 1098 | |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 1099 | cfg->scan_request = request; |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 1100 | set_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1101 | if (escan_req) { |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 1102 | cfg->escan_info.run = brcmf_run_escan; |
Arend van Spriel | a0f472a | 2013-04-05 10:57:49 +0200 | [diff] [blame] | 1103 | err = brcmf_p2p_scan_prep(wiphy, request, vif); |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 1104 | if (err) |
| 1105 | goto scan_out; |
| 1106 | |
Arend van Spriel | a0f472a | 2013-04-05 10:57:49 +0200 | [diff] [blame] | 1107 | err = brcmf_do_escan(cfg, wiphy, vif->ifp, request); |
Arend van Spriel | 2cb941c | 2012-11-05 16:22:10 -0800 | [diff] [blame] | 1108 | if (err) |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1109 | goto scan_out; |
| 1110 | } else { |
Arend van Spriel | 4e8a008 | 2012-12-05 15:26:03 +0100 | [diff] [blame] | 1111 | brcmf_dbg(SCAN, "ssid \"%s\", ssid_len (%d)\n", |
| 1112 | ssids->ssid, ssids->ssid_len); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1113 | memset(&sr->ssid_le, 0, sizeof(sr->ssid_le)); |
| 1114 | SSID_len = min_t(u8, sizeof(sr->ssid_le.SSID), ssids->ssid_len); |
| 1115 | sr->ssid_le.SSID_len = cpu_to_le32(0); |
| 1116 | spec_scan = false; |
| 1117 | if (SSID_len) { |
| 1118 | memcpy(sr->ssid_le.SSID, ssids->ssid, SSID_len); |
| 1119 | sr->ssid_le.SSID_len = cpu_to_le32(SSID_len); |
| 1120 | spec_scan = true; |
| 1121 | } else |
Arend van Spriel | 4e8a008 | 2012-12-05 15:26:03 +0100 | [diff] [blame] | 1122 | brcmf_dbg(SCAN, "Broadcast scan\n"); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1123 | |
Hante Meuleman | 81f5dcb | 2012-10-22 10:36:14 -0700 | [diff] [blame] | 1124 | passive_scan = cfg->active_scan ? 0 : 1; |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 1125 | err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_PASSIVE_SCAN, |
Hante Meuleman | 81f5dcb | 2012-10-22 10:36:14 -0700 | [diff] [blame] | 1126 | passive_scan); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1127 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1128 | brcmf_err("WLC_SET_PASSIVE_SCAN error (%d)\n", err); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1129 | goto scan_out; |
| 1130 | } |
Daniel Kim | 5e787f7 | 2014-06-21 12:11:18 +0200 | [diff] [blame] | 1131 | brcmf_scan_config_mpc(ifp, 0); |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 1132 | err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SCAN, |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 1133 | &sr->ssid_le, sizeof(sr->ssid_le)); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1134 | if (err) { |
| 1135 | if (err == -EBUSY) |
Arend van Spriel | 647c9ae | 2012-12-05 15:26:01 +0100 | [diff] [blame] | 1136 | brcmf_dbg(INFO, "BUSY: scan for \"%s\" canceled\n", |
| 1137 | sr->ssid_le.SSID); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1138 | else |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1139 | brcmf_err("WLC_SCAN error (%d)\n", err); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1140 | |
Daniel Kim | 5e787f7 | 2014-06-21 12:11:18 +0200 | [diff] [blame] | 1141 | brcmf_scan_config_mpc(ifp, 1); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1142 | goto scan_out; |
| 1143 | } |
| 1144 | } |
| 1145 | |
Hante Meuleman | 661fa95 | 2015-02-06 18:36:47 +0100 | [diff] [blame] | 1146 | /* Arm scan timeout timer */ |
| 1147 | mod_timer(&cfg->escan_timeout, jiffies + |
| 1148 | WL_ESCAN_TIMER_INTERVAL_MS * HZ / 1000); |
| 1149 | |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1150 | return 0; |
| 1151 | |
| 1152 | scan_out: |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 1153 | clear_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status); |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 1154 | cfg->scan_request = NULL; |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1155 | return err; |
| 1156 | } |
| 1157 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1158 | static s32 |
Arend van Spriel | 0abb5f21 | 2012-10-22 13:55:32 -0700 | [diff] [blame] | 1159 | brcmf_cfg80211_scan(struct wiphy *wiphy, struct cfg80211_scan_request *request) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1160 | { |
Arend van Spriel | a0f472a | 2013-04-05 10:57:49 +0200 | [diff] [blame] | 1161 | struct brcmf_cfg80211_vif *vif; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1162 | s32 err = 0; |
| 1163 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 1164 | brcmf_dbg(TRACE, "Enter\n"); |
Arend van Spriel | a0f472a | 2013-04-05 10:57:49 +0200 | [diff] [blame] | 1165 | vif = container_of(request->wdev, struct brcmf_cfg80211_vif, wdev); |
| 1166 | if (!check_vif_up(vif)) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1167 | return -EIO; |
| 1168 | |
Arend van Spriel | a0f472a | 2013-04-05 10:57:49 +0200 | [diff] [blame] | 1169 | err = brcmf_cfg80211_escan(wiphy, vif, request, NULL); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 1170 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1171 | if (err) |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1172 | brcmf_err("scan error (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1173 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 1174 | brcmf_dbg(TRACE, "Exit\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1175 | return err; |
| 1176 | } |
| 1177 | |
| 1178 | static s32 brcmf_set_rts(struct net_device *ndev, u32 rts_threshold) |
| 1179 | { |
| 1180 | s32 err = 0; |
| 1181 | |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 1182 | err = brcmf_fil_iovar_int_set(netdev_priv(ndev), "rtsthresh", |
| 1183 | rts_threshold); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1184 | if (err) |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1185 | brcmf_err("Error (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1186 | |
| 1187 | return err; |
| 1188 | } |
| 1189 | |
| 1190 | static s32 brcmf_set_frag(struct net_device *ndev, u32 frag_threshold) |
| 1191 | { |
| 1192 | s32 err = 0; |
| 1193 | |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 1194 | err = brcmf_fil_iovar_int_set(netdev_priv(ndev), "fragthresh", |
| 1195 | frag_threshold); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1196 | if (err) |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1197 | brcmf_err("Error (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1198 | |
| 1199 | return err; |
| 1200 | } |
| 1201 | |
| 1202 | static s32 brcmf_set_retry(struct net_device *ndev, u32 retry, bool l) |
| 1203 | { |
| 1204 | s32 err = 0; |
Hante Meuleman | b87e2c4 | 2012-11-14 18:46:23 -0800 | [diff] [blame] | 1205 | u32 cmd = (l ? BRCMF_C_SET_LRL : BRCMF_C_SET_SRL); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1206 | |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 1207 | err = brcmf_fil_cmd_int_set(netdev_priv(ndev), cmd, retry); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1208 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1209 | brcmf_err("cmd (%d) , error (%d)\n", cmd, err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1210 | return err; |
| 1211 | } |
| 1212 | return err; |
| 1213 | } |
| 1214 | |
| 1215 | static s32 brcmf_cfg80211_set_wiphy_params(struct wiphy *wiphy, u32 changed) |
| 1216 | { |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 1217 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); |
| 1218 | struct net_device *ndev = cfg_to_ndev(cfg); |
Arend van Spriel | 0abb5f21 | 2012-10-22 13:55:32 -0700 | [diff] [blame] | 1219 | struct brcmf_if *ifp = netdev_priv(ndev); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1220 | s32 err = 0; |
| 1221 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 1222 | brcmf_dbg(TRACE, "Enter\n"); |
Arend van Spriel | ce81e31 | 2012-10-22 13:55:37 -0700 | [diff] [blame] | 1223 | if (!check_vif_up(ifp->vif)) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1224 | return -EIO; |
| 1225 | |
| 1226 | if (changed & WIPHY_PARAM_RTS_THRESHOLD && |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 1227 | (cfg->conf->rts_threshold != wiphy->rts_threshold)) { |
| 1228 | cfg->conf->rts_threshold = wiphy->rts_threshold; |
| 1229 | err = brcmf_set_rts(ndev, cfg->conf->rts_threshold); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1230 | if (!err) |
| 1231 | goto done; |
| 1232 | } |
| 1233 | if (changed & WIPHY_PARAM_FRAG_THRESHOLD && |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 1234 | (cfg->conf->frag_threshold != wiphy->frag_threshold)) { |
| 1235 | cfg->conf->frag_threshold = wiphy->frag_threshold; |
| 1236 | err = brcmf_set_frag(ndev, cfg->conf->frag_threshold); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1237 | if (!err) |
| 1238 | goto done; |
| 1239 | } |
| 1240 | if (changed & WIPHY_PARAM_RETRY_LONG |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 1241 | && (cfg->conf->retry_long != wiphy->retry_long)) { |
| 1242 | cfg->conf->retry_long = wiphy->retry_long; |
| 1243 | err = brcmf_set_retry(ndev, cfg->conf->retry_long, true); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1244 | if (!err) |
| 1245 | goto done; |
| 1246 | } |
| 1247 | if (changed & WIPHY_PARAM_RETRY_SHORT |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 1248 | && (cfg->conf->retry_short != wiphy->retry_short)) { |
| 1249 | cfg->conf->retry_short = wiphy->retry_short; |
| 1250 | err = brcmf_set_retry(ndev, cfg->conf->retry_short, false); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1251 | if (!err) |
| 1252 | goto done; |
| 1253 | } |
| 1254 | |
| 1255 | done: |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 1256 | brcmf_dbg(TRACE, "Exit\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1257 | return err; |
| 1258 | } |
| 1259 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1260 | static void brcmf_init_prof(struct brcmf_cfg80211_profile *prof) |
| 1261 | { |
| 1262 | memset(prof, 0, sizeof(*prof)); |
| 1263 | } |
| 1264 | |
Arend van Spriel | 9b7a0dd | 2015-01-25 20:31:33 +0100 | [diff] [blame] | 1265 | static u16 brcmf_map_fw_linkdown_reason(const struct brcmf_event_msg *e) |
| 1266 | { |
| 1267 | u16 reason; |
| 1268 | |
| 1269 | switch (e->event_code) { |
| 1270 | case BRCMF_E_DEAUTH: |
| 1271 | case BRCMF_E_DEAUTH_IND: |
| 1272 | case BRCMF_E_DISASSOC_IND: |
| 1273 | reason = e->reason; |
| 1274 | break; |
| 1275 | case BRCMF_E_LINK: |
| 1276 | default: |
| 1277 | reason = 0; |
| 1278 | break; |
| 1279 | } |
| 1280 | return reason; |
| 1281 | } |
| 1282 | |
| 1283 | 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] | 1284 | { |
Piotr Haber | 61730d4 | 2013-04-23 12:53:12 +0200 | [diff] [blame] | 1285 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(vif->wdev.wiphy); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1286 | s32 err = 0; |
| 1287 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 1288 | brcmf_dbg(TRACE, "Enter\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1289 | |
Arend van Spriel | 903e0ee | 2012-11-28 21:44:11 +0100 | [diff] [blame] | 1290 | if (test_bit(BRCMF_VIF_STATUS_CONNECTED, &vif->sme_state)) { |
Arend van Spriel | 647c9ae | 2012-12-05 15:26:01 +0100 | [diff] [blame] | 1291 | brcmf_dbg(INFO, "Call WLC_DISASSOC to stop excess roaming\n "); |
Arend van Spriel | 903e0ee | 2012-11-28 21:44:11 +0100 | [diff] [blame] | 1292 | err = brcmf_fil_cmd_data_set(vif->ifp, |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 1293 | BRCMF_C_DISASSOC, NULL, 0); |
Arend van Spriel | a538ae3 | 2013-07-25 23:01:34 +0200 | [diff] [blame] | 1294 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1295 | brcmf_err("WLC_DISASSOC failed (%d)\n", err); |
Arend van Spriel | a538ae3 | 2013-07-25 23:01:34 +0200 | [diff] [blame] | 1296 | } |
Arend van Spriel | 903e0ee | 2012-11-28 21:44:11 +0100 | [diff] [blame] | 1297 | clear_bit(BRCMF_VIF_STATUS_CONNECTED, &vif->sme_state); |
Arend van Spriel | 9b7a0dd | 2015-01-25 20:31:33 +0100 | [diff] [blame] | 1298 | cfg80211_disconnected(vif->wdev.netdev, reason, NULL, 0, |
Johannes Berg | 80279fb | 2015-05-22 16:22:20 +0200 | [diff] [blame] | 1299 | true, GFP_KERNEL); |
Arend van Spriel | 43dffbc | 2014-01-06 12:40:46 +0100 | [diff] [blame] | 1300 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1301 | } |
Arend van Spriel | 903e0ee | 2012-11-28 21:44:11 +0100 | [diff] [blame] | 1302 | clear_bit(BRCMF_VIF_STATUS_CONNECTING, &vif->sme_state); |
Piotr Haber | 61730d4 | 2013-04-23 12:53:12 +0200 | [diff] [blame] | 1303 | clear_bit(BRCMF_SCAN_STATUS_SUPPRESS, &cfg->scan_status); |
| 1304 | brcmf_btcoex_set_mode(vif, BRCMF_BTCOEX_ENABLED, 0); |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 1305 | brcmf_dbg(TRACE, "Exit\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1306 | } |
| 1307 | |
| 1308 | static s32 |
| 1309 | brcmf_cfg80211_join_ibss(struct wiphy *wiphy, struct net_device *ndev, |
| 1310 | struct cfg80211_ibss_params *params) |
| 1311 | { |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 1312 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); |
Arend van Spriel | 0abb5f21 | 2012-10-22 13:55:32 -0700 | [diff] [blame] | 1313 | struct brcmf_if *ifp = netdev_priv(ndev); |
| 1314 | struct brcmf_cfg80211_profile *profile = &ifp->vif->profile; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1315 | struct brcmf_join_params join_params; |
| 1316 | size_t join_params_size = 0; |
| 1317 | s32 err = 0; |
| 1318 | s32 wsec = 0; |
| 1319 | s32 bcnprd; |
Hante Meuleman | 1701261 | 2013-02-06 18:40:44 +0100 | [diff] [blame] | 1320 | u16 chanspec; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1321 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 1322 | brcmf_dbg(TRACE, "Enter\n"); |
Arend van Spriel | ce81e31 | 2012-10-22 13:55:37 -0700 | [diff] [blame] | 1323 | if (!check_vif_up(ifp->vif)) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1324 | return -EIO; |
| 1325 | |
| 1326 | if (params->ssid) |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 1327 | brcmf_dbg(CONN, "SSID: %s\n", params->ssid); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1328 | else { |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 1329 | brcmf_dbg(CONN, "SSID: NULL, Not supported\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1330 | return -EOPNOTSUPP; |
| 1331 | } |
| 1332 | |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 1333 | set_bit(BRCMF_VIF_STATUS_CONNECTING, &ifp->vif->sme_state); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1334 | |
| 1335 | if (params->bssid) |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 1336 | brcmf_dbg(CONN, "BSSID: %pM\n", params->bssid); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1337 | else |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 1338 | brcmf_dbg(CONN, "No BSSID specified\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1339 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1340 | if (params->chandef.chan) |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 1341 | brcmf_dbg(CONN, "channel: %d\n", |
| 1342 | params->chandef.chan->center_freq); |
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 channel specified\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1345 | |
| 1346 | if (params->channel_fixed) |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 1347 | brcmf_dbg(CONN, "fixed channel required\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1348 | else |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 1349 | brcmf_dbg(CONN, "no fixed channel required\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1350 | |
| 1351 | if (params->ie && params->ie_len) |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 1352 | brcmf_dbg(CONN, "ie len: %d\n", params->ie_len); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1353 | else |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 1354 | brcmf_dbg(CONN, "no ie specified\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1355 | |
| 1356 | if (params->beacon_interval) |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 1357 | brcmf_dbg(CONN, "beacon interval: %d\n", |
| 1358 | params->beacon_interval); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1359 | else |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 1360 | brcmf_dbg(CONN, "no beacon interval specified\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1361 | |
| 1362 | if (params->basic_rates) |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 1363 | brcmf_dbg(CONN, "basic rates: %08X\n", params->basic_rates); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1364 | else |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 1365 | brcmf_dbg(CONN, "no basic rates specified\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1366 | |
| 1367 | if (params->privacy) |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 1368 | brcmf_dbg(CONN, "privacy required\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1369 | else |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 1370 | brcmf_dbg(CONN, "no privacy required\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1371 | |
| 1372 | /* Configure Privacy for starter */ |
| 1373 | if (params->privacy) |
| 1374 | wsec |= WEP_ENABLED; |
| 1375 | |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 1376 | err = brcmf_fil_iovar_int_set(ifp, "wsec", wsec); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1377 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1378 | brcmf_err("wsec failed (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1379 | goto done; |
| 1380 | } |
| 1381 | |
| 1382 | /* Configure Beacon Interval for starter */ |
| 1383 | if (params->beacon_interval) |
| 1384 | bcnprd = params->beacon_interval; |
| 1385 | else |
| 1386 | bcnprd = 100; |
| 1387 | |
Hante Meuleman | b87e2c4 | 2012-11-14 18:46:23 -0800 | [diff] [blame] | 1388 | 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] | 1389 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1390 | brcmf_err("WLC_SET_BCNPRD failed (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1391 | goto done; |
| 1392 | } |
| 1393 | |
| 1394 | /* Configure required join parameter */ |
| 1395 | memset(&join_params, 0, sizeof(struct brcmf_join_params)); |
| 1396 | |
| 1397 | /* SSID */ |
Arend van Spriel | 6c8c4f7 | 2012-09-27 14:17:57 +0200 | [diff] [blame] | 1398 | profile->ssid.SSID_len = min_t(u32, params->ssid_len, 32); |
| 1399 | memcpy(profile->ssid.SSID, params->ssid, profile->ssid.SSID_len); |
| 1400 | memcpy(join_params.ssid_le.SSID, params->ssid, profile->ssid.SSID_len); |
| 1401 | 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] | 1402 | join_params_size = sizeof(join_params.ssid_le); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1403 | |
| 1404 | /* BSSID */ |
| 1405 | if (params->bssid) { |
| 1406 | memcpy(join_params.params_le.bssid, params->bssid, ETH_ALEN); |
| 1407 | join_params_size = sizeof(join_params.ssid_le) + |
| 1408 | BRCMF_ASSOC_PARAMS_FIXED_SIZE; |
Arend van Spriel | 6c8c4f7 | 2012-09-27 14:17:57 +0200 | [diff] [blame] | 1409 | memcpy(profile->bssid, params->bssid, ETH_ALEN); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1410 | } else { |
Joe Perches | 93803b3 | 2015-03-02 19:54:49 -0800 | [diff] [blame] | 1411 | eth_broadcast_addr(join_params.params_le.bssid); |
| 1412 | eth_zero_addr(profile->bssid); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1413 | } |
| 1414 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1415 | /* Channel */ |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1416 | if (params->chandef.chan) { |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1417 | u32 target_channel; |
| 1418 | |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 1419 | cfg->channel = |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1420 | ieee80211_frequency_to_channel( |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1421 | params->chandef.chan->center_freq); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1422 | if (params->channel_fixed) { |
| 1423 | /* adding chanspec */ |
Arend van Spriel | 600a897 | 2014-05-12 10:47:39 +0200 | [diff] [blame] | 1424 | chanspec = chandef_to_chanspec(&cfg->d11inf, |
| 1425 | ¶ms->chandef); |
Hante Meuleman | 1701261 | 2013-02-06 18:40:44 +0100 | [diff] [blame] | 1426 | join_params.params_le.chanspec_list[0] = |
| 1427 | cpu_to_le16(chanspec); |
| 1428 | join_params.params_le.chanspec_num = cpu_to_le32(1); |
| 1429 | join_params_size += sizeof(join_params.params_le); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1430 | } |
| 1431 | |
| 1432 | /* set channel for starter */ |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 1433 | target_channel = cfg->channel; |
Hante Meuleman | b87e2c4 | 2012-11-14 18:46:23 -0800 | [diff] [blame] | 1434 | err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_CHANNEL, |
Hante Meuleman | 81f5dcb | 2012-10-22 10:36:14 -0700 | [diff] [blame] | 1435 | target_channel); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1436 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1437 | brcmf_err("WLC_SET_CHANNEL failed (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1438 | goto done; |
| 1439 | } |
| 1440 | } else |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 1441 | cfg->channel = 0; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1442 | |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 1443 | cfg->ibss_starter = false; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1444 | |
| 1445 | |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 1446 | err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SET_SSID, |
Hante Meuleman | 81f5dcb | 2012-10-22 10:36:14 -0700 | [diff] [blame] | 1447 | &join_params, join_params_size); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1448 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1449 | brcmf_err("WLC_SET_SSID failed (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1450 | goto done; |
| 1451 | } |
| 1452 | |
| 1453 | done: |
| 1454 | if (err) |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 1455 | clear_bit(BRCMF_VIF_STATUS_CONNECTING, &ifp->vif->sme_state); |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 1456 | brcmf_dbg(TRACE, "Exit\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1457 | return err; |
| 1458 | } |
| 1459 | |
| 1460 | static s32 |
| 1461 | brcmf_cfg80211_leave_ibss(struct wiphy *wiphy, struct net_device *ndev) |
| 1462 | { |
Arend van Spriel | 0abb5f21 | 2012-10-22 13:55:32 -0700 | [diff] [blame] | 1463 | struct brcmf_if *ifp = netdev_priv(ndev); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1464 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 1465 | brcmf_dbg(TRACE, "Enter\n"); |
Arend van Spriel | ce81e31 | 2012-10-22 13:55:37 -0700 | [diff] [blame] | 1466 | if (!check_vif_up(ifp->vif)) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1467 | return -EIO; |
| 1468 | |
Arend van Spriel | 9b7a0dd | 2015-01-25 20:31:33 +0100 | [diff] [blame] | 1469 | brcmf_link_down(ifp->vif, WLAN_REASON_DEAUTH_LEAVING); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1470 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 1471 | brcmf_dbg(TRACE, "Exit\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1472 | |
Peter Senna Tschudin | 12f3237 | 2014-05-31 10:14:06 -0300 | [diff] [blame] | 1473 | return 0; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1474 | } |
| 1475 | |
| 1476 | static s32 brcmf_set_wpa_version(struct net_device *ndev, |
| 1477 | struct cfg80211_connect_params *sme) |
| 1478 | { |
Arend van Spriel | 6ac4f4e | 2012-10-22 13:55:31 -0700 | [diff] [blame] | 1479 | struct brcmf_cfg80211_profile *profile = ndev_to_prof(ndev); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1480 | struct brcmf_cfg80211_security *sec; |
| 1481 | s32 val = 0; |
| 1482 | s32 err = 0; |
| 1483 | |
| 1484 | if (sme->crypto.wpa_versions & NL80211_WPA_VERSION_1) |
| 1485 | val = WPA_AUTH_PSK | WPA_AUTH_UNSPECIFIED; |
| 1486 | else if (sme->crypto.wpa_versions & NL80211_WPA_VERSION_2) |
| 1487 | val = WPA2_AUTH_PSK | WPA2_AUTH_UNSPECIFIED; |
| 1488 | else |
| 1489 | val = WPA_AUTH_DISABLED; |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 1490 | brcmf_dbg(CONN, "setting wpa_auth to 0x%0x\n", val); |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 1491 | 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] | 1492 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1493 | brcmf_err("set wpa_auth failed (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1494 | return err; |
| 1495 | } |
Arend van Spriel | 06bb123 | 2012-09-27 14:17:56 +0200 | [diff] [blame] | 1496 | sec = &profile->sec; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1497 | sec->wpa_versions = sme->crypto.wpa_versions; |
| 1498 | return err; |
| 1499 | } |
| 1500 | |
| 1501 | static s32 brcmf_set_auth_type(struct net_device *ndev, |
| 1502 | struct cfg80211_connect_params *sme) |
| 1503 | { |
Arend van Spriel | 6ac4f4e | 2012-10-22 13:55:31 -0700 | [diff] [blame] | 1504 | struct brcmf_cfg80211_profile *profile = ndev_to_prof(ndev); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1505 | struct brcmf_cfg80211_security *sec; |
| 1506 | s32 val = 0; |
| 1507 | s32 err = 0; |
| 1508 | |
| 1509 | switch (sme->auth_type) { |
| 1510 | case NL80211_AUTHTYPE_OPEN_SYSTEM: |
| 1511 | val = 0; |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 1512 | brcmf_dbg(CONN, "open system\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1513 | break; |
| 1514 | case NL80211_AUTHTYPE_SHARED_KEY: |
| 1515 | val = 1; |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 1516 | brcmf_dbg(CONN, "shared key\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1517 | break; |
| 1518 | case NL80211_AUTHTYPE_AUTOMATIC: |
| 1519 | val = 2; |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 1520 | brcmf_dbg(CONN, "automatic\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1521 | break; |
| 1522 | case NL80211_AUTHTYPE_NETWORK_EAP: |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 1523 | brcmf_dbg(CONN, "network eap\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1524 | default: |
| 1525 | val = 2; |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1526 | brcmf_err("invalid auth type (%d)\n", sme->auth_type); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1527 | break; |
| 1528 | } |
| 1529 | |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 1530 | err = brcmf_fil_bsscfg_int_set(netdev_priv(ndev), "auth", val); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1531 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1532 | brcmf_err("set auth failed (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1533 | return err; |
| 1534 | } |
Arend van Spriel | 06bb123 | 2012-09-27 14:17:56 +0200 | [diff] [blame] | 1535 | sec = &profile->sec; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1536 | sec->auth_type = sme->auth_type; |
| 1537 | return err; |
| 1538 | } |
| 1539 | |
| 1540 | static s32 |
Daniel Kim | 87b7e9e | 2014-03-25 21:45:09 +0100 | [diff] [blame] | 1541 | brcmf_set_wsec_mode(struct net_device *ndev, |
| 1542 | struct cfg80211_connect_params *sme, bool mfp) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1543 | { |
Arend van Spriel | 6ac4f4e | 2012-10-22 13:55:31 -0700 | [diff] [blame] | 1544 | struct brcmf_cfg80211_profile *profile = ndev_to_prof(ndev); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1545 | struct brcmf_cfg80211_security *sec; |
| 1546 | s32 pval = 0; |
| 1547 | s32 gval = 0; |
Daniel Kim | 87b7e9e | 2014-03-25 21:45:09 +0100 | [diff] [blame] | 1548 | s32 wsec; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1549 | s32 err = 0; |
| 1550 | |
| 1551 | if (sme->crypto.n_ciphers_pairwise) { |
| 1552 | switch (sme->crypto.ciphers_pairwise[0]) { |
| 1553 | case WLAN_CIPHER_SUITE_WEP40: |
| 1554 | case WLAN_CIPHER_SUITE_WEP104: |
| 1555 | pval = WEP_ENABLED; |
| 1556 | break; |
| 1557 | case WLAN_CIPHER_SUITE_TKIP: |
| 1558 | pval = TKIP_ENABLED; |
| 1559 | break; |
| 1560 | case WLAN_CIPHER_SUITE_CCMP: |
| 1561 | pval = AES_ENABLED; |
| 1562 | break; |
| 1563 | case WLAN_CIPHER_SUITE_AES_CMAC: |
| 1564 | pval = AES_ENABLED; |
| 1565 | break; |
| 1566 | default: |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1567 | brcmf_err("invalid cipher pairwise (%d)\n", |
| 1568 | sme->crypto.ciphers_pairwise[0]); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1569 | return -EINVAL; |
| 1570 | } |
| 1571 | } |
| 1572 | if (sme->crypto.cipher_group) { |
| 1573 | switch (sme->crypto.cipher_group) { |
| 1574 | case WLAN_CIPHER_SUITE_WEP40: |
| 1575 | case WLAN_CIPHER_SUITE_WEP104: |
| 1576 | gval = WEP_ENABLED; |
| 1577 | break; |
| 1578 | case WLAN_CIPHER_SUITE_TKIP: |
| 1579 | gval = TKIP_ENABLED; |
| 1580 | break; |
| 1581 | case WLAN_CIPHER_SUITE_CCMP: |
| 1582 | gval = AES_ENABLED; |
| 1583 | break; |
| 1584 | case WLAN_CIPHER_SUITE_AES_CMAC: |
| 1585 | gval = AES_ENABLED; |
| 1586 | break; |
| 1587 | default: |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1588 | brcmf_err("invalid cipher group (%d)\n", |
| 1589 | sme->crypto.cipher_group); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1590 | return -EINVAL; |
| 1591 | } |
| 1592 | } |
| 1593 | |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 1594 | brcmf_dbg(CONN, "pval (%d) gval (%d)\n", pval, gval); |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 1595 | /* In case of privacy, but no security and WPS then simulate */ |
| 1596 | /* setting AES. WPS-2.0 allows no security */ |
| 1597 | if (brcmf_find_wpsie(sme->ie, sme->ie_len) && !pval && !gval && |
| 1598 | sme->privacy) |
| 1599 | pval = AES_ENABLED; |
Daniel Kim | 87b7e9e | 2014-03-25 21:45:09 +0100 | [diff] [blame] | 1600 | |
| 1601 | if (mfp) |
| 1602 | wsec = pval | gval | MFP_CAPABLE; |
| 1603 | else |
| 1604 | wsec = pval | gval; |
| 1605 | err = brcmf_fil_bsscfg_int_set(netdev_priv(ndev), "wsec", wsec); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1606 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1607 | brcmf_err("error (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1608 | return err; |
| 1609 | } |
| 1610 | |
Arend van Spriel | 06bb123 | 2012-09-27 14:17:56 +0200 | [diff] [blame] | 1611 | sec = &profile->sec; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1612 | sec->cipher_pairwise = sme->crypto.ciphers_pairwise[0]; |
| 1613 | sec->cipher_group = sme->crypto.cipher_group; |
| 1614 | |
| 1615 | return err; |
| 1616 | } |
| 1617 | |
| 1618 | static s32 |
| 1619 | brcmf_set_key_mgmt(struct net_device *ndev, struct cfg80211_connect_params *sme) |
| 1620 | { |
Arend van Spriel | 6ac4f4e | 2012-10-22 13:55:31 -0700 | [diff] [blame] | 1621 | struct brcmf_cfg80211_profile *profile = ndev_to_prof(ndev); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1622 | struct brcmf_cfg80211_security *sec; |
| 1623 | s32 val = 0; |
| 1624 | s32 err = 0; |
| 1625 | |
| 1626 | if (sme->crypto.n_akm_suites) { |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 1627 | err = brcmf_fil_bsscfg_int_get(netdev_priv(ndev), |
| 1628 | "wpa_auth", &val); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1629 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1630 | brcmf_err("could not get wpa_auth (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1631 | return err; |
| 1632 | } |
| 1633 | if (val & (WPA_AUTH_PSK | WPA_AUTH_UNSPECIFIED)) { |
| 1634 | switch (sme->crypto.akm_suites[0]) { |
| 1635 | case WLAN_AKM_SUITE_8021X: |
| 1636 | val = WPA_AUTH_UNSPECIFIED; |
| 1637 | break; |
| 1638 | case WLAN_AKM_SUITE_PSK: |
| 1639 | val = WPA_AUTH_PSK; |
| 1640 | break; |
| 1641 | default: |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1642 | brcmf_err("invalid cipher group (%d)\n", |
| 1643 | sme->crypto.cipher_group); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1644 | return -EINVAL; |
| 1645 | } |
| 1646 | } else if (val & (WPA2_AUTH_PSK | WPA2_AUTH_UNSPECIFIED)) { |
| 1647 | switch (sme->crypto.akm_suites[0]) { |
| 1648 | case WLAN_AKM_SUITE_8021X: |
| 1649 | val = WPA2_AUTH_UNSPECIFIED; |
| 1650 | break; |
| 1651 | case WLAN_AKM_SUITE_PSK: |
| 1652 | val = WPA2_AUTH_PSK; |
| 1653 | break; |
| 1654 | default: |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1655 | brcmf_err("invalid cipher group (%d)\n", |
| 1656 | sme->crypto.cipher_group); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1657 | return -EINVAL; |
| 1658 | } |
| 1659 | } |
| 1660 | |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 1661 | brcmf_dbg(CONN, "setting wpa_auth to %d\n", val); |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 1662 | err = brcmf_fil_bsscfg_int_set(netdev_priv(ndev), |
| 1663 | "wpa_auth", val); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1664 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1665 | brcmf_err("could not set wpa_auth (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1666 | return err; |
| 1667 | } |
| 1668 | } |
Arend van Spriel | 06bb123 | 2012-09-27 14:17:56 +0200 | [diff] [blame] | 1669 | sec = &profile->sec; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1670 | sec->wpa_auth = sme->crypto.akm_suites[0]; |
| 1671 | |
| 1672 | return err; |
| 1673 | } |
| 1674 | |
| 1675 | static s32 |
Hante Meuleman | f09d0c0 | 2012-09-27 14:17:48 +0200 | [diff] [blame] | 1676 | brcmf_set_sharedkey(struct net_device *ndev, |
| 1677 | struct cfg80211_connect_params *sme) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1678 | { |
Arend van Spriel | 6ac4f4e | 2012-10-22 13:55:31 -0700 | [diff] [blame] | 1679 | struct brcmf_cfg80211_profile *profile = ndev_to_prof(ndev); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1680 | struct brcmf_cfg80211_security *sec; |
| 1681 | struct brcmf_wsec_key key; |
| 1682 | s32 val; |
| 1683 | s32 err = 0; |
| 1684 | |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 1685 | brcmf_dbg(CONN, "key len (%d)\n", sme->key_len); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1686 | |
Roland Vossen | a718e2f | 2011-10-12 20:51:24 +0200 | [diff] [blame] | 1687 | if (sme->key_len == 0) |
| 1688 | return 0; |
| 1689 | |
Arend van Spriel | 06bb123 | 2012-09-27 14:17:56 +0200 | [diff] [blame] | 1690 | sec = &profile->sec; |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 1691 | brcmf_dbg(CONN, "wpa_versions 0x%x cipher_pairwise 0x%x\n", |
| 1692 | sec->wpa_versions, sec->cipher_pairwise); |
Roland Vossen | a718e2f | 2011-10-12 20:51:24 +0200 | [diff] [blame] | 1693 | |
| 1694 | if (sec->wpa_versions & (NL80211_WPA_VERSION_1 | NL80211_WPA_VERSION_2)) |
| 1695 | return 0; |
| 1696 | |
Hante Meuleman | f09d0c0 | 2012-09-27 14:17:48 +0200 | [diff] [blame] | 1697 | if (!(sec->cipher_pairwise & |
| 1698 | (WLAN_CIPHER_SUITE_WEP40 | WLAN_CIPHER_SUITE_WEP104))) |
| 1699 | return 0; |
Roland Vossen | a718e2f | 2011-10-12 20:51:24 +0200 | [diff] [blame] | 1700 | |
Hante Meuleman | f09d0c0 | 2012-09-27 14:17:48 +0200 | [diff] [blame] | 1701 | memset(&key, 0, sizeof(key)); |
| 1702 | key.len = (u32) sme->key_len; |
| 1703 | key.index = (u32) sme->key_idx; |
| 1704 | if (key.len > sizeof(key.data)) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1705 | brcmf_err("Too long key length (%u)\n", key.len); |
Hante Meuleman | f09d0c0 | 2012-09-27 14:17:48 +0200 | [diff] [blame] | 1706 | return -EINVAL; |
| 1707 | } |
| 1708 | memcpy(key.data, sme->key, key.len); |
| 1709 | key.flags = BRCMF_PRIMARY_KEY; |
| 1710 | switch (sec->cipher_pairwise) { |
| 1711 | case WLAN_CIPHER_SUITE_WEP40: |
| 1712 | key.algo = CRYPTO_ALGO_WEP1; |
| 1713 | break; |
| 1714 | case WLAN_CIPHER_SUITE_WEP104: |
| 1715 | key.algo = CRYPTO_ALGO_WEP128; |
| 1716 | break; |
| 1717 | default: |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1718 | brcmf_err("Invalid algorithm (%d)\n", |
| 1719 | sme->crypto.ciphers_pairwise[0]); |
Hante Meuleman | f09d0c0 | 2012-09-27 14:17:48 +0200 | [diff] [blame] | 1720 | return -EINVAL; |
| 1721 | } |
| 1722 | /* Set the new key/index */ |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 1723 | brcmf_dbg(CONN, "key length (%d) key index (%d) algo (%d)\n", |
| 1724 | key.len, key.index, key.algo); |
| 1725 | brcmf_dbg(CONN, "key \"%s\"\n", key.data); |
Hante Meuleman | 118eb30 | 2014-12-21 12:43:49 +0100 | [diff] [blame] | 1726 | err = send_key_to_dongle(netdev_priv(ndev), &key); |
Hante Meuleman | f09d0c0 | 2012-09-27 14:17:48 +0200 | [diff] [blame] | 1727 | if (err) |
| 1728 | return err; |
| 1729 | |
| 1730 | if (sec->auth_type == NL80211_AUTHTYPE_SHARED_KEY) { |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 1731 | brcmf_dbg(CONN, "set auth_type to shared key\n"); |
Hante Meuleman | f09d0c0 | 2012-09-27 14:17:48 +0200 | [diff] [blame] | 1732 | val = WL_AUTH_SHARED_KEY; /* shared key */ |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 1733 | err = brcmf_fil_bsscfg_int_set(netdev_priv(ndev), "auth", val); |
Hante Meuleman | f09d0c0 | 2012-09-27 14:17:48 +0200 | [diff] [blame] | 1734 | if (err) |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1735 | brcmf_err("set auth failed (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1736 | } |
| 1737 | return err; |
| 1738 | } |
| 1739 | |
Arend van Spriel | cbb1ec9 | 2013-02-06 18:40:47 +0100 | [diff] [blame] | 1740 | static |
| 1741 | enum nl80211_auth_type brcmf_war_auth_type(struct brcmf_if *ifp, |
| 1742 | enum nl80211_auth_type type) |
| 1743 | { |
Arend van Spriel | c08437b | 2014-07-12 08:49:39 +0200 | [diff] [blame] | 1744 | if (type == NL80211_AUTHTYPE_AUTOMATIC && |
| 1745 | brcmf_feat_is_quirk_enabled(ifp, BRCMF_FEAT_QUIRK_AUTO_AUTH)) { |
| 1746 | brcmf_dbg(CONN, "WAR: use OPEN instead of AUTO\n"); |
| 1747 | type = NL80211_AUTHTYPE_OPEN_SYSTEM; |
Arend van Spriel | cbb1ec9 | 2013-02-06 18:40:47 +0100 | [diff] [blame] | 1748 | } |
| 1749 | return type; |
| 1750 | } |
| 1751 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1752 | static s32 |
| 1753 | brcmf_cfg80211_connect(struct wiphy *wiphy, struct net_device *ndev, |
Arend van Spriel | cbb1ec9 | 2013-02-06 18:40:47 +0100 | [diff] [blame] | 1754 | struct cfg80211_connect_params *sme) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1755 | { |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 1756 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); |
Arend van Spriel | 0abb5f21 | 2012-10-22 13:55:32 -0700 | [diff] [blame] | 1757 | struct brcmf_if *ifp = netdev_priv(ndev); |
| 1758 | struct brcmf_cfg80211_profile *profile = &ifp->vif->profile; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1759 | struct ieee80211_channel *chan = sme->channel; |
| 1760 | struct brcmf_join_params join_params; |
| 1761 | size_t join_params_size; |
Johannes Berg | 4b5800f | 2014-01-15 14:55:59 +0100 | [diff] [blame] | 1762 | const struct brcmf_tlv *rsn_ie; |
| 1763 | const struct brcmf_vs_tlv *wpa_ie; |
| 1764 | const void *ie; |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 1765 | u32 ie_len; |
| 1766 | struct brcmf_ext_join_params_le *ext_join_params; |
Hante Meuleman | 1701261 | 2013-02-06 18:40:44 +0100 | [diff] [blame] | 1767 | u16 chanspec; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1768 | s32 err = 0; |
| 1769 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 1770 | brcmf_dbg(TRACE, "Enter\n"); |
Arend van Spriel | ce81e31 | 2012-10-22 13:55:37 -0700 | [diff] [blame] | 1771 | if (!check_vif_up(ifp->vif)) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1772 | return -EIO; |
| 1773 | |
| 1774 | if (!sme->ssid) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1775 | brcmf_err("Invalid ssid\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1776 | return -EOPNOTSUPP; |
| 1777 | } |
| 1778 | |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 1779 | if (ifp->vif == cfg->p2p.bss_idx[P2PAPI_BSSCFG_PRIMARY].vif) { |
| 1780 | /* A normal (non P2P) connection request setup. */ |
| 1781 | ie = NULL; |
| 1782 | ie_len = 0; |
| 1783 | /* find the WPA_IE */ |
| 1784 | wpa_ie = brcmf_find_wpaie((u8 *)sme->ie, sme->ie_len); |
| 1785 | if (wpa_ie) { |
| 1786 | ie = wpa_ie; |
| 1787 | ie_len = wpa_ie->len + TLV_HDR_LEN; |
| 1788 | } else { |
| 1789 | /* find the RSN_IE */ |
Johannes Berg | 4b5800f | 2014-01-15 14:55:59 +0100 | [diff] [blame] | 1790 | rsn_ie = brcmf_parse_tlvs((const u8 *)sme->ie, |
| 1791 | sme->ie_len, |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 1792 | WLAN_EID_RSN); |
| 1793 | if (rsn_ie) { |
| 1794 | ie = rsn_ie; |
| 1795 | ie_len = rsn_ie->len + TLV_HDR_LEN; |
| 1796 | } |
| 1797 | } |
| 1798 | brcmf_fil_iovar_data_set(ifp, "wpaie", ie, ie_len); |
| 1799 | } |
| 1800 | |
| 1801 | err = brcmf_vif_set_mgmt_ie(ifp->vif, BRCMF_VNDR_IE_ASSOCREQ_FLAG, |
| 1802 | sme->ie, sme->ie_len); |
| 1803 | if (err) |
| 1804 | brcmf_err("Set Assoc REQ IE Failed\n"); |
| 1805 | else |
| 1806 | brcmf_dbg(TRACE, "Applied Vndr IEs for Assoc request\n"); |
| 1807 | |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 1808 | set_bit(BRCMF_VIF_STATUS_CONNECTING, &ifp->vif->sme_state); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1809 | |
| 1810 | if (chan) { |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 1811 | cfg->channel = |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1812 | ieee80211_frequency_to_channel(chan->center_freq); |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 1813 | chanspec = channel_to_chanspec(&cfg->d11inf, chan); |
Hante Meuleman | 1701261 | 2013-02-06 18:40:44 +0100 | [diff] [blame] | 1814 | brcmf_dbg(CONN, "channel=%d, center_req=%d, chanspec=0x%04x\n", |
| 1815 | cfg->channel, chan->center_freq, chanspec); |
| 1816 | } else { |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 1817 | cfg->channel = 0; |
Hante Meuleman | 1701261 | 2013-02-06 18:40:44 +0100 | [diff] [blame] | 1818 | chanspec = 0; |
| 1819 | } |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1820 | |
Arend van Spriel | 647c9ae | 2012-12-05 15:26:01 +0100 | [diff] [blame] | 1821 | 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] | 1822 | |
| 1823 | err = brcmf_set_wpa_version(ndev, sme); |
| 1824 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1825 | brcmf_err("wl_set_wpa_version failed (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1826 | goto done; |
| 1827 | } |
| 1828 | |
Arend van Spriel | cbb1ec9 | 2013-02-06 18:40:47 +0100 | [diff] [blame] | 1829 | sme->auth_type = brcmf_war_auth_type(ifp, sme->auth_type); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1830 | err = brcmf_set_auth_type(ndev, sme); |
| 1831 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1832 | brcmf_err("wl_set_auth_type failed (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1833 | goto done; |
| 1834 | } |
| 1835 | |
Daniel Kim | 87b7e9e | 2014-03-25 21:45:09 +0100 | [diff] [blame] | 1836 | 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] | 1837 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1838 | brcmf_err("wl_set_set_cipher failed (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1839 | goto done; |
| 1840 | } |
| 1841 | |
| 1842 | err = brcmf_set_key_mgmt(ndev, sme); |
| 1843 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1844 | brcmf_err("wl_set_key_mgmt failed (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1845 | goto done; |
| 1846 | } |
| 1847 | |
Hante Meuleman | f09d0c0 | 2012-09-27 14:17:48 +0200 | [diff] [blame] | 1848 | err = brcmf_set_sharedkey(ndev, sme); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1849 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1850 | brcmf_err("brcmf_set_sharedkey failed (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1851 | goto done; |
| 1852 | } |
| 1853 | |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 1854 | profile->ssid.SSID_len = min_t(u32, (u32)sizeof(profile->ssid.SSID), |
| 1855 | (u32)sme->ssid_len); |
| 1856 | memcpy(&profile->ssid.SSID, sme->ssid, profile->ssid.SSID_len); |
| 1857 | if (profile->ssid.SSID_len < IEEE80211_MAX_SSID_LEN) { |
| 1858 | profile->ssid.SSID[profile->ssid.SSID_len] = 0; |
| 1859 | brcmf_dbg(CONN, "SSID \"%s\", len (%d)\n", profile->ssid.SSID, |
| 1860 | profile->ssid.SSID_len); |
| 1861 | } |
| 1862 | |
| 1863 | /* Join with specific BSSID and cached SSID |
| 1864 | * If SSID is zero join based on BSSID only |
| 1865 | */ |
| 1866 | join_params_size = offsetof(struct brcmf_ext_join_params_le, assoc_le) + |
| 1867 | offsetof(struct brcmf_assoc_params_le, chanspec_list); |
| 1868 | if (cfg->channel) |
| 1869 | join_params_size += sizeof(u16); |
| 1870 | ext_join_params = kzalloc(join_params_size, GFP_KERNEL); |
| 1871 | if (ext_join_params == NULL) { |
| 1872 | err = -ENOMEM; |
| 1873 | goto done; |
| 1874 | } |
| 1875 | ext_join_params->ssid_le.SSID_len = cpu_to_le32(profile->ssid.SSID_len); |
| 1876 | memcpy(&ext_join_params->ssid_le.SSID, sme->ssid, |
| 1877 | profile->ssid.SSID_len); |
Hante Meuleman | 63dd99e | 2014-03-15 17:18:19 +0100 | [diff] [blame] | 1878 | |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 1879 | /* Set up join scan parameters */ |
| 1880 | ext_join_params->scan_le.scan_type = -1; |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 1881 | ext_join_params->scan_le.home_time = cpu_to_le32(-1); |
| 1882 | |
| 1883 | if (sme->bssid) |
| 1884 | memcpy(&ext_join_params->assoc_le.bssid, sme->bssid, ETH_ALEN); |
| 1885 | else |
Joe Perches | 93803b3 | 2015-03-02 19:54:49 -0800 | [diff] [blame] | 1886 | eth_broadcast_addr(ext_join_params->assoc_le.bssid); |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 1887 | |
| 1888 | if (cfg->channel) { |
| 1889 | ext_join_params->assoc_le.chanspec_num = cpu_to_le32(1); |
| 1890 | |
| 1891 | ext_join_params->assoc_le.chanspec_list[0] = |
| 1892 | cpu_to_le16(chanspec); |
Hante Meuleman | 63dd99e | 2014-03-15 17:18:19 +0100 | [diff] [blame] | 1893 | /* Increase dwell time to receive probe response or detect |
| 1894 | * beacon from target AP at a noisy air only during connect |
| 1895 | * command. |
| 1896 | */ |
| 1897 | ext_join_params->scan_le.active_time = |
| 1898 | cpu_to_le32(BRCMF_SCAN_JOIN_ACTIVE_DWELL_TIME_MS); |
| 1899 | ext_join_params->scan_le.passive_time = |
| 1900 | cpu_to_le32(BRCMF_SCAN_JOIN_PASSIVE_DWELL_TIME_MS); |
| 1901 | /* To sync with presence period of VSDB GO send probe request |
| 1902 | * more frequently. Probe request will be stopped when it gets |
| 1903 | * probe response from target AP/GO. |
| 1904 | */ |
| 1905 | ext_join_params->scan_le.nprobes = |
| 1906 | cpu_to_le32(BRCMF_SCAN_JOIN_ACTIVE_DWELL_TIME_MS / |
| 1907 | BRCMF_SCAN_JOIN_PROBE_INTERVAL_MS); |
| 1908 | } else { |
| 1909 | ext_join_params->scan_le.active_time = cpu_to_le32(-1); |
| 1910 | ext_join_params->scan_le.passive_time = cpu_to_le32(-1); |
| 1911 | ext_join_params->scan_le.nprobes = cpu_to_le32(-1); |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 1912 | } |
| 1913 | |
| 1914 | err = brcmf_fil_bsscfg_data_set(ifp, "join", ext_join_params, |
| 1915 | join_params_size); |
| 1916 | kfree(ext_join_params); |
| 1917 | if (!err) |
| 1918 | /* This is it. join command worked, we are done */ |
| 1919 | goto done; |
| 1920 | |
| 1921 | /* join command failed, fallback to set ssid */ |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1922 | memset(&join_params, 0, sizeof(join_params)); |
| 1923 | join_params_size = sizeof(join_params.ssid_le); |
| 1924 | |
Arend van Spriel | 6c8c4f7 | 2012-09-27 14:17:57 +0200 | [diff] [blame] | 1925 | 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] | 1926 | 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] | 1927 | |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 1928 | if (sme->bssid) |
| 1929 | memcpy(join_params.params_le.bssid, sme->bssid, ETH_ALEN); |
| 1930 | else |
Joe Perches | 93803b3 | 2015-03-02 19:54:49 -0800 | [diff] [blame] | 1931 | eth_broadcast_addr(join_params.params_le.bssid); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1932 | |
Hante Meuleman | 1701261 | 2013-02-06 18:40:44 +0100 | [diff] [blame] | 1933 | if (cfg->channel) { |
| 1934 | join_params.params_le.chanspec_list[0] = cpu_to_le16(chanspec); |
| 1935 | join_params.params_le.chanspec_num = cpu_to_le32(1); |
| 1936 | join_params_size += sizeof(join_params.params_le); |
| 1937 | } |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 1938 | err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SET_SSID, |
Hante Meuleman | 81f5dcb | 2012-10-22 10:36:14 -0700 | [diff] [blame] | 1939 | &join_params, join_params_size); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1940 | if (err) |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 1941 | brcmf_err("BRCMF_C_SET_SSID failed (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1942 | |
| 1943 | done: |
| 1944 | if (err) |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 1945 | clear_bit(BRCMF_VIF_STATUS_CONNECTING, &ifp->vif->sme_state); |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 1946 | brcmf_dbg(TRACE, "Exit\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1947 | return err; |
| 1948 | } |
| 1949 | |
| 1950 | static s32 |
| 1951 | brcmf_cfg80211_disconnect(struct wiphy *wiphy, struct net_device *ndev, |
| 1952 | u16 reason_code) |
| 1953 | { |
Arend van Spriel | 0abb5f21 | 2012-10-22 13:55:32 -0700 | [diff] [blame] | 1954 | struct brcmf_if *ifp = netdev_priv(ndev); |
| 1955 | struct brcmf_cfg80211_profile *profile = &ifp->vif->profile; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1956 | struct brcmf_scb_val_le scbval; |
| 1957 | s32 err = 0; |
| 1958 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 1959 | brcmf_dbg(TRACE, "Enter. Reason code = %d\n", reason_code); |
Arend van Spriel | ce81e31 | 2012-10-22 13:55:37 -0700 | [diff] [blame] | 1960 | if (!check_vif_up(ifp->vif)) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1961 | return -EIO; |
| 1962 | |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 1963 | clear_bit(BRCMF_VIF_STATUS_CONNECTED, &ifp->vif->sme_state); |
Arend van Spriel | 4f3fff1 | 2014-11-20 22:27:02 +0100 | [diff] [blame] | 1964 | clear_bit(BRCMF_VIF_STATUS_CONNECTING, &ifp->vif->sme_state); |
Johannes Berg | 80279fb | 2015-05-22 16:22:20 +0200 | [diff] [blame] | 1965 | cfg80211_disconnected(ndev, reason_code, NULL, 0, true, GFP_KERNEL); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1966 | |
Arend van Spriel | 06bb123 | 2012-09-27 14:17:56 +0200 | [diff] [blame] | 1967 | memcpy(&scbval.ea, &profile->bssid, ETH_ALEN); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1968 | scbval.val = cpu_to_le32(reason_code); |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 1969 | err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_DISASSOC, |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 1970 | &scbval, sizeof(scbval)); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1971 | if (err) |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 1972 | brcmf_err("error (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1973 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 1974 | brcmf_dbg(TRACE, "Exit\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1975 | return err; |
| 1976 | } |
| 1977 | |
| 1978 | static s32 |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 1979 | 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] | 1980 | enum nl80211_tx_power_setting type, s32 mbm) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1981 | { |
| 1982 | |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 1983 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); |
Arend van Spriel | 0abb5f21 | 2012-10-22 13:55:32 -0700 | [diff] [blame] | 1984 | struct net_device *ndev = cfg_to_ndev(cfg); |
| 1985 | struct brcmf_if *ifp = netdev_priv(ndev); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1986 | u16 txpwrmw; |
| 1987 | s32 err = 0; |
| 1988 | s32 disable = 0; |
Luis R. Rodriguez | d3f3113 | 2011-11-28 16:38:48 -0500 | [diff] [blame] | 1989 | s32 dbm = MBM_TO_DBM(mbm); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1990 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 1991 | brcmf_dbg(TRACE, "Enter\n"); |
Arend van Spriel | ce81e31 | 2012-10-22 13:55:37 -0700 | [diff] [blame] | 1992 | if (!check_vif_up(ifp->vif)) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1993 | return -EIO; |
| 1994 | |
| 1995 | switch (type) { |
| 1996 | case NL80211_TX_POWER_AUTOMATIC: |
| 1997 | break; |
| 1998 | case NL80211_TX_POWER_LIMITED: |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1999 | case NL80211_TX_POWER_FIXED: |
| 2000 | if (dbm < 0) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 2001 | brcmf_err("TX_POWER_FIXED - dbm is negative\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2002 | err = -EINVAL; |
| 2003 | goto done; |
| 2004 | } |
| 2005 | break; |
| 2006 | } |
| 2007 | /* Make sure radio is off or on as far as software is concerned */ |
| 2008 | disable = WL_RADIO_SW_DISABLE << 16; |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 2009 | 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] | 2010 | if (err) |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 2011 | brcmf_err("WLC_SET_RADIO error (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2012 | |
| 2013 | if (dbm > 0xffff) |
| 2014 | txpwrmw = 0xffff; |
| 2015 | else |
| 2016 | txpwrmw = (u16) dbm; |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 2017 | err = brcmf_fil_iovar_int_set(ifp, "qtxpower", |
| 2018 | (s32)brcmf_mw_to_qdbm(txpwrmw)); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2019 | if (err) |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 2020 | brcmf_err("qtxpower error (%d)\n", err); |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 2021 | cfg->conf->tx_power = dbm; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2022 | |
| 2023 | done: |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 2024 | brcmf_dbg(TRACE, "Exit\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2025 | return err; |
| 2026 | } |
| 2027 | |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 2028 | static s32 brcmf_cfg80211_get_tx_power(struct wiphy *wiphy, |
| 2029 | struct wireless_dev *wdev, |
| 2030 | s32 *dbm) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2031 | { |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 2032 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); |
Arend van Spriel | 0abb5f21 | 2012-10-22 13:55:32 -0700 | [diff] [blame] | 2033 | struct brcmf_if *ifp = netdev_priv(cfg_to_ndev(cfg)); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2034 | s32 txpwrdbm; |
| 2035 | u8 result; |
| 2036 | s32 err = 0; |
| 2037 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 2038 | brcmf_dbg(TRACE, "Enter\n"); |
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_iovar_int_get(ifp, "qtxpower", &txpwrdbm); |
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("error (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2045 | goto done; |
| 2046 | } |
| 2047 | |
| 2048 | result = (u8) (txpwrdbm & ~WL_TXPWR_OVERRIDE); |
Alwin Beukers | ef6ac17 | 2011-10-12 20:51:26 +0200 | [diff] [blame] | 2049 | *dbm = (s32) brcmf_qdbm_to_mw(result); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2050 | |
| 2051 | done: |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 2052 | brcmf_dbg(TRACE, "Exit\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2053 | return err; |
| 2054 | } |
| 2055 | |
| 2056 | static s32 |
| 2057 | brcmf_cfg80211_config_default_key(struct wiphy *wiphy, struct net_device *ndev, |
| 2058 | u8 key_idx, bool unicast, bool multicast) |
| 2059 | { |
Arend van Spriel | 0abb5f21 | 2012-10-22 13:55:32 -0700 | [diff] [blame] | 2060 | struct brcmf_if *ifp = netdev_priv(ndev); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2061 | u32 index; |
| 2062 | u32 wsec; |
| 2063 | s32 err = 0; |
| 2064 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 2065 | brcmf_dbg(TRACE, "Enter\n"); |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 2066 | brcmf_dbg(CONN, "key index (%d)\n", key_idx); |
Arend van Spriel | ce81e31 | 2012-10-22 13:55:37 -0700 | [diff] [blame] | 2067 | if (!check_vif_up(ifp->vif)) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2068 | return -EIO; |
| 2069 | |
Arend van Spriel | 0abb5f21 | 2012-10-22 13:55:32 -0700 | [diff] [blame] | 2070 | err = brcmf_fil_bsscfg_int_get(ifp, "wsec", &wsec); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2071 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 2072 | brcmf_err("WLC_GET_WSEC error (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2073 | goto done; |
| 2074 | } |
| 2075 | |
| 2076 | if (wsec & WEP_ENABLED) { |
| 2077 | /* Just select a new current key */ |
| 2078 | index = key_idx; |
Arend van Spriel | 0abb5f21 | 2012-10-22 13:55:32 -0700 | [diff] [blame] | 2079 | err = brcmf_fil_cmd_int_set(ifp, |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 2080 | BRCMF_C_SET_KEY_PRIMARY, index); |
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("error (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2083 | } |
| 2084 | done: |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 2085 | brcmf_dbg(TRACE, "Exit\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2086 | return err; |
| 2087 | } |
| 2088 | |
| 2089 | static s32 |
| 2090 | brcmf_add_keyext(struct wiphy *wiphy, struct net_device *ndev, |
| 2091 | u8 key_idx, const u8 *mac_addr, struct key_params *params) |
| 2092 | { |
Hante Meuleman | 992f606 | 2013-04-02 21:06:17 +0200 | [diff] [blame] | 2093 | struct brcmf_if *ifp = netdev_priv(ndev); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2094 | struct brcmf_wsec_key key; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2095 | s32 err = 0; |
Hante Meuleman | 992f606 | 2013-04-02 21:06:17 +0200 | [diff] [blame] | 2096 | u8 keybuf[8]; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2097 | |
| 2098 | memset(&key, 0, sizeof(key)); |
| 2099 | key.index = (u32) key_idx; |
| 2100 | /* Instead of bcast for ea address for default wep keys, |
| 2101 | driver needs it to be Null */ |
| 2102 | if (!is_multicast_ether_addr(mac_addr)) |
| 2103 | memcpy((char *)&key.ea, (void *)mac_addr, ETH_ALEN); |
| 2104 | key.len = (u32) params->key_len; |
| 2105 | /* check for key index change */ |
| 2106 | if (key.len == 0) { |
| 2107 | /* key delete */ |
Hante Meuleman | 118eb30 | 2014-12-21 12:43:49 +0100 | [diff] [blame] | 2108 | err = send_key_to_dongle(ifp, &key); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2109 | if (err) |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 2110 | brcmf_err("key delete error (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2111 | } else { |
| 2112 | if (key.len > sizeof(key.data)) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 2113 | brcmf_err("Invalid key length (%d)\n", key.len); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2114 | return -EINVAL; |
| 2115 | } |
| 2116 | |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 2117 | brcmf_dbg(CONN, "Setting the key index %d\n", key.index); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2118 | memcpy(key.data, params->key, key.len); |
| 2119 | |
Arend van Spriel | 967fe2c | 2014-03-15 17:18:21 +0100 | [diff] [blame] | 2120 | if (!brcmf_is_apmode(ifp->vif) && |
Hante Meuleman | 992f606 | 2013-04-02 21:06:17 +0200 | [diff] [blame] | 2121 | (params->cipher == WLAN_CIPHER_SUITE_TKIP)) { |
| 2122 | brcmf_dbg(CONN, "Swapping RX/TX MIC key\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2123 | memcpy(keybuf, &key.data[24], sizeof(keybuf)); |
| 2124 | memcpy(&key.data[24], &key.data[16], sizeof(keybuf)); |
| 2125 | memcpy(&key.data[16], keybuf, sizeof(keybuf)); |
| 2126 | } |
| 2127 | |
| 2128 | /* if IW_ENCODE_EXT_RX_SEQ_VALID set */ |
| 2129 | if (params->seq && params->seq_len == 6) { |
| 2130 | /* rx iv */ |
| 2131 | u8 *ivptr; |
| 2132 | ivptr = (u8 *) params->seq; |
| 2133 | key.rxiv.hi = (ivptr[5] << 24) | (ivptr[4] << 16) | |
| 2134 | (ivptr[3] << 8) | ivptr[2]; |
| 2135 | key.rxiv.lo = (ivptr[1] << 8) | ivptr[0]; |
| 2136 | key.iv_initialized = true; |
| 2137 | } |
| 2138 | |
| 2139 | switch (params->cipher) { |
| 2140 | case WLAN_CIPHER_SUITE_WEP40: |
| 2141 | key.algo = CRYPTO_ALGO_WEP1; |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 2142 | brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_WEP40\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2143 | break; |
| 2144 | case WLAN_CIPHER_SUITE_WEP104: |
| 2145 | key.algo = CRYPTO_ALGO_WEP128; |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 2146 | brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_WEP104\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2147 | break; |
| 2148 | case WLAN_CIPHER_SUITE_TKIP: |
| 2149 | key.algo = CRYPTO_ALGO_TKIP; |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 2150 | brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_TKIP\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2151 | break; |
| 2152 | case WLAN_CIPHER_SUITE_AES_CMAC: |
| 2153 | key.algo = CRYPTO_ALGO_AES_CCM; |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 2154 | brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_AES_CMAC\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2155 | break; |
| 2156 | case WLAN_CIPHER_SUITE_CCMP: |
| 2157 | key.algo = CRYPTO_ALGO_AES_CCM; |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 2158 | brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_CCMP\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2159 | break; |
| 2160 | default: |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 2161 | brcmf_err("Invalid cipher (0x%x)\n", params->cipher); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2162 | return -EINVAL; |
| 2163 | } |
Hante Meuleman | 118eb30 | 2014-12-21 12:43:49 +0100 | [diff] [blame] | 2164 | err = send_key_to_dongle(ifp, &key); |
Hante Meuleman | f09d0c0 | 2012-09-27 14:17:48 +0200 | [diff] [blame] | 2165 | if (err) |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 2166 | brcmf_err("wsec_key error (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2167 | } |
| 2168 | return err; |
| 2169 | } |
| 2170 | |
| 2171 | static s32 |
| 2172 | brcmf_cfg80211_add_key(struct wiphy *wiphy, struct net_device *ndev, |
| 2173 | u8 key_idx, bool pairwise, const u8 *mac_addr, |
| 2174 | struct key_params *params) |
| 2175 | { |
Arend van Spriel | 0abb5f21 | 2012-10-22 13:55:32 -0700 | [diff] [blame] | 2176 | struct brcmf_if *ifp = netdev_priv(ndev); |
Hante Meuleman | 118eb30 | 2014-12-21 12:43:49 +0100 | [diff] [blame] | 2177 | struct brcmf_wsec_key *key; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2178 | s32 val; |
| 2179 | s32 wsec; |
| 2180 | s32 err = 0; |
| 2181 | u8 keybuf[8]; |
| 2182 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 2183 | brcmf_dbg(TRACE, "Enter\n"); |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 2184 | brcmf_dbg(CONN, "key index (%d)\n", key_idx); |
Arend van Spriel | ce81e31 | 2012-10-22 13:55:37 -0700 | [diff] [blame] | 2185 | if (!check_vif_up(ifp->vif)) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2186 | return -EIO; |
| 2187 | |
Hante Meuleman | 118eb30 | 2014-12-21 12:43:49 +0100 | [diff] [blame] | 2188 | if (key_idx >= BRCMF_MAX_DEFAULT_KEYS) { |
| 2189 | /* we ignore this key index in this case */ |
| 2190 | brcmf_err("invalid key index (%d)\n", key_idx); |
| 2191 | return -EINVAL; |
| 2192 | } |
| 2193 | |
Daniel Kim | 787eb03 | 2014-01-29 15:32:23 +0100 | [diff] [blame] | 2194 | if (mac_addr && |
| 2195 | (params->cipher != WLAN_CIPHER_SUITE_WEP40) && |
| 2196 | (params->cipher != WLAN_CIPHER_SUITE_WEP104)) { |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 2197 | brcmf_dbg(TRACE, "Exit"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2198 | return brcmf_add_keyext(wiphy, ndev, key_idx, mac_addr, params); |
| 2199 | } |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2200 | |
Hante Meuleman | 118eb30 | 2014-12-21 12:43:49 +0100 | [diff] [blame] | 2201 | key = &ifp->vif->profile.key[key_idx]; |
| 2202 | memset(key, 0, sizeof(*key)); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2203 | |
Hante Meuleman | 118eb30 | 2014-12-21 12:43:49 +0100 | [diff] [blame] | 2204 | if (params->key_len > sizeof(key->data)) { |
| 2205 | brcmf_err("Too long key length (%u)\n", params->key_len); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2206 | err = -EINVAL; |
| 2207 | goto done; |
| 2208 | } |
Hante Meuleman | 118eb30 | 2014-12-21 12:43:49 +0100 | [diff] [blame] | 2209 | key->len = params->key_len; |
| 2210 | key->index = key_idx; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2211 | |
Hante Meuleman | 118eb30 | 2014-12-21 12:43:49 +0100 | [diff] [blame] | 2212 | memcpy(key->data, params->key, key->len); |
| 2213 | |
| 2214 | key->flags = BRCMF_PRIMARY_KEY; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2215 | switch (params->cipher) { |
| 2216 | case WLAN_CIPHER_SUITE_WEP40: |
Hante Meuleman | 118eb30 | 2014-12-21 12:43:49 +0100 | [diff] [blame] | 2217 | key->algo = CRYPTO_ALGO_WEP1; |
Hante Meuleman | f09d0c0 | 2012-09-27 14:17:48 +0200 | [diff] [blame] | 2218 | val = WEP_ENABLED; |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 2219 | brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_WEP40\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2220 | break; |
| 2221 | case WLAN_CIPHER_SUITE_WEP104: |
Hante Meuleman | 118eb30 | 2014-12-21 12:43:49 +0100 | [diff] [blame] | 2222 | key->algo = CRYPTO_ALGO_WEP128; |
Hante Meuleman | f09d0c0 | 2012-09-27 14:17:48 +0200 | [diff] [blame] | 2223 | val = WEP_ENABLED; |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 2224 | brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_WEP104\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2225 | break; |
| 2226 | case WLAN_CIPHER_SUITE_TKIP: |
Arend van Spriel | 967fe2c | 2014-03-15 17:18:21 +0100 | [diff] [blame] | 2227 | if (!brcmf_is_apmode(ifp->vif)) { |
Hante Meuleman | 992f606 | 2013-04-02 21:06:17 +0200 | [diff] [blame] | 2228 | brcmf_dbg(CONN, "Swapping RX/TX MIC key\n"); |
Hante Meuleman | 118eb30 | 2014-12-21 12:43:49 +0100 | [diff] [blame] | 2229 | memcpy(keybuf, &key->data[24], sizeof(keybuf)); |
| 2230 | memcpy(&key->data[24], &key->data[16], sizeof(keybuf)); |
| 2231 | memcpy(&key->data[16], keybuf, sizeof(keybuf)); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 2232 | } |
Hante Meuleman | 118eb30 | 2014-12-21 12:43:49 +0100 | [diff] [blame] | 2233 | key->algo = CRYPTO_ALGO_TKIP; |
Hante Meuleman | f09d0c0 | 2012-09-27 14:17:48 +0200 | [diff] [blame] | 2234 | val = TKIP_ENABLED; |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 2235 | brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_TKIP\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2236 | break; |
| 2237 | case WLAN_CIPHER_SUITE_AES_CMAC: |
Hante Meuleman | 118eb30 | 2014-12-21 12:43:49 +0100 | [diff] [blame] | 2238 | key->algo = CRYPTO_ALGO_AES_CCM; |
Hante Meuleman | f09d0c0 | 2012-09-27 14:17:48 +0200 | [diff] [blame] | 2239 | val = AES_ENABLED; |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 2240 | brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_AES_CMAC\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2241 | break; |
| 2242 | case WLAN_CIPHER_SUITE_CCMP: |
Hante Meuleman | 118eb30 | 2014-12-21 12:43:49 +0100 | [diff] [blame] | 2243 | key->algo = CRYPTO_ALGO_AES_CCM; |
Hante Meuleman | f09d0c0 | 2012-09-27 14:17:48 +0200 | [diff] [blame] | 2244 | val = AES_ENABLED; |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 2245 | brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_CCMP\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2246 | break; |
| 2247 | default: |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 2248 | brcmf_err("Invalid cipher (0x%x)\n", params->cipher); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2249 | err = -EINVAL; |
| 2250 | goto done; |
| 2251 | } |
| 2252 | |
Hante Meuleman | 118eb30 | 2014-12-21 12:43:49 +0100 | [diff] [blame] | 2253 | err = send_key_to_dongle(ifp, key); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2254 | if (err) |
| 2255 | goto done; |
| 2256 | |
Arend van Spriel | 0abb5f21 | 2012-10-22 13:55:32 -0700 | [diff] [blame] | 2257 | err = brcmf_fil_bsscfg_int_get(ifp, "wsec", &wsec); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2258 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 2259 | brcmf_err("get wsec error (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2260 | goto done; |
| 2261 | } |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2262 | wsec |= val; |
Arend van Spriel | 0abb5f21 | 2012-10-22 13:55:32 -0700 | [diff] [blame] | 2263 | err = brcmf_fil_bsscfg_int_set(ifp, "wsec", wsec); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2264 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 2265 | brcmf_err("set wsec error (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2266 | goto done; |
| 2267 | } |
| 2268 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2269 | done: |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 2270 | brcmf_dbg(TRACE, "Exit\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2271 | return err; |
| 2272 | } |
| 2273 | |
| 2274 | static s32 |
| 2275 | brcmf_cfg80211_del_key(struct wiphy *wiphy, struct net_device *ndev, |
| 2276 | u8 key_idx, bool pairwise, const u8 *mac_addr) |
| 2277 | { |
Arend van Spriel | 0abb5f21 | 2012-10-22 13:55:32 -0700 | [diff] [blame] | 2278 | struct brcmf_if *ifp = netdev_priv(ndev); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2279 | struct brcmf_wsec_key key; |
| 2280 | s32 err = 0; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2281 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 2282 | brcmf_dbg(TRACE, "Enter\n"); |
Arend van Spriel | ce81e31 | 2012-10-22 13:55:37 -0700 | [diff] [blame] | 2283 | if (!check_vif_up(ifp->vif)) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2284 | return -EIO; |
| 2285 | |
Hante Meuleman | 118eb30 | 2014-12-21 12:43:49 +0100 | [diff] [blame] | 2286 | if (key_idx >= BRCMF_MAX_DEFAULT_KEYS) { |
Hante Meuleman | 256c374 | 2012-11-05 16:22:28 -0800 | [diff] [blame] | 2287 | /* we ignore this key index in this case */ |
Hante Meuleman | 256c374 | 2012-11-05 16:22:28 -0800 | [diff] [blame] | 2288 | return -EINVAL; |
| 2289 | } |
| 2290 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2291 | memset(&key, 0, sizeof(key)); |
| 2292 | |
| 2293 | key.index = (u32) key_idx; |
| 2294 | key.flags = BRCMF_PRIMARY_KEY; |
| 2295 | key.algo = CRYPTO_ALGO_OFF; |
| 2296 | |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 2297 | brcmf_dbg(CONN, "key index (%d)\n", key_idx); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2298 | |
| 2299 | /* Set the new key/index */ |
Hante Meuleman | 118eb30 | 2014-12-21 12:43:49 +0100 | [diff] [blame] | 2300 | err = send_key_to_dongle(ifp, &key); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2301 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 2302 | brcmf_dbg(TRACE, "Exit\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2303 | return err; |
| 2304 | } |
| 2305 | |
| 2306 | static s32 |
| 2307 | brcmf_cfg80211_get_key(struct wiphy *wiphy, struct net_device *ndev, |
| 2308 | u8 key_idx, bool pairwise, const u8 *mac_addr, void *cookie, |
| 2309 | void (*callback) (void *cookie, struct key_params * params)) |
| 2310 | { |
| 2311 | struct key_params params; |
Arend van Spriel | 0abb5f21 | 2012-10-22 13:55:32 -0700 | [diff] [blame] | 2312 | struct brcmf_if *ifp = netdev_priv(ndev); |
| 2313 | struct brcmf_cfg80211_profile *profile = &ifp->vif->profile; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2314 | struct brcmf_cfg80211_security *sec; |
| 2315 | s32 wsec; |
| 2316 | s32 err = 0; |
| 2317 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 2318 | brcmf_dbg(TRACE, "Enter\n"); |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 2319 | brcmf_dbg(CONN, "key index (%d)\n", key_idx); |
Arend van Spriel | ce81e31 | 2012-10-22 13:55:37 -0700 | [diff] [blame] | 2320 | if (!check_vif_up(ifp->vif)) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2321 | return -EIO; |
| 2322 | |
| 2323 | memset(¶ms, 0, sizeof(params)); |
| 2324 | |
Arend van Spriel | 0abb5f21 | 2012-10-22 13:55:32 -0700 | [diff] [blame] | 2325 | err = brcmf_fil_bsscfg_int_get(ifp, "wsec", &wsec); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2326 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 2327 | brcmf_err("WLC_GET_WSEC error (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2328 | /* Ignore this error, may happen during DISASSOC */ |
| 2329 | err = -EAGAIN; |
| 2330 | goto done; |
| 2331 | } |
Hante Meuleman | c5bf53a | 2013-04-02 21:06:19 +0200 | [diff] [blame] | 2332 | if (wsec & WEP_ENABLED) { |
Arend van Spriel | 06bb123 | 2012-09-27 14:17:56 +0200 | [diff] [blame] | 2333 | sec = &profile->sec; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2334 | if (sec->cipher_pairwise & WLAN_CIPHER_SUITE_WEP40) { |
| 2335 | params.cipher = WLAN_CIPHER_SUITE_WEP40; |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 2336 | brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_WEP40\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2337 | } else if (sec->cipher_pairwise & WLAN_CIPHER_SUITE_WEP104) { |
| 2338 | params.cipher = WLAN_CIPHER_SUITE_WEP104; |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 2339 | brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_WEP104\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2340 | } |
Hante Meuleman | c5bf53a | 2013-04-02 21:06:19 +0200 | [diff] [blame] | 2341 | } else if (wsec & TKIP_ENABLED) { |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2342 | params.cipher = WLAN_CIPHER_SUITE_TKIP; |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 2343 | brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_TKIP\n"); |
Hante Meuleman | c5bf53a | 2013-04-02 21:06:19 +0200 | [diff] [blame] | 2344 | } else if (wsec & AES_ENABLED) { |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2345 | params.cipher = WLAN_CIPHER_SUITE_AES_CMAC; |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 2346 | brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_AES_CMAC\n"); |
Hante Meuleman | c5bf53a | 2013-04-02 21:06:19 +0200 | [diff] [blame] | 2347 | } else { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 2348 | brcmf_err("Invalid algo (0x%x)\n", wsec); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2349 | err = -EINVAL; |
| 2350 | goto done; |
| 2351 | } |
| 2352 | callback(cookie, ¶ms); |
| 2353 | |
| 2354 | done: |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 2355 | brcmf_dbg(TRACE, "Exit\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2356 | return err; |
| 2357 | } |
| 2358 | |
| 2359 | static s32 |
| 2360 | brcmf_cfg80211_config_default_mgmt_key(struct wiphy *wiphy, |
| 2361 | struct net_device *ndev, u8 key_idx) |
| 2362 | { |
Arend van Spriel | 647c9ae | 2012-12-05 15:26:01 +0100 | [diff] [blame] | 2363 | brcmf_dbg(INFO, "Not supported\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2364 | |
| 2365 | return -EOPNOTSUPP; |
| 2366 | } |
| 2367 | |
Hante Meuleman | 118eb30 | 2014-12-21 12:43:49 +0100 | [diff] [blame] | 2368 | static void |
| 2369 | brcmf_cfg80211_reconfigure_wep(struct brcmf_if *ifp) |
| 2370 | { |
| 2371 | s32 err; |
| 2372 | u8 key_idx; |
| 2373 | struct brcmf_wsec_key *key; |
| 2374 | s32 wsec; |
| 2375 | |
| 2376 | for (key_idx = 0; key_idx < BRCMF_MAX_DEFAULT_KEYS; key_idx++) { |
| 2377 | key = &ifp->vif->profile.key[key_idx]; |
| 2378 | if ((key->algo == CRYPTO_ALGO_WEP1) || |
| 2379 | (key->algo == CRYPTO_ALGO_WEP128)) |
| 2380 | break; |
| 2381 | } |
| 2382 | if (key_idx == BRCMF_MAX_DEFAULT_KEYS) |
| 2383 | return; |
| 2384 | |
| 2385 | err = send_key_to_dongle(ifp, key); |
| 2386 | if (err) { |
| 2387 | brcmf_err("Setting WEP key failed (%d)\n", err); |
| 2388 | return; |
| 2389 | } |
| 2390 | err = brcmf_fil_bsscfg_int_get(ifp, "wsec", &wsec); |
| 2391 | if (err) { |
| 2392 | brcmf_err("get wsec error (%d)\n", err); |
| 2393 | return; |
| 2394 | } |
| 2395 | wsec |= WEP_ENABLED; |
| 2396 | err = brcmf_fil_bsscfg_int_set(ifp, "wsec", wsec); |
| 2397 | if (err) |
| 2398 | brcmf_err("set wsec error (%d)\n", err); |
| 2399 | } |
| 2400 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2401 | static s32 |
| 2402 | brcmf_cfg80211_get_station(struct wiphy *wiphy, struct net_device *ndev, |
Johannes Berg | 3b3a016 | 2014-05-19 17:19:31 +0200 | [diff] [blame] | 2403 | const u8 *mac, struct station_info *sinfo) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2404 | { |
Arend van Spriel | 0abb5f21 | 2012-10-22 13:55:32 -0700 | [diff] [blame] | 2405 | struct brcmf_if *ifp = netdev_priv(ndev); |
| 2406 | struct brcmf_cfg80211_profile *profile = &ifp->vif->profile; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2407 | struct brcmf_scb_val_le scb_val; |
| 2408 | int rssi; |
| 2409 | s32 rate; |
| 2410 | s32 err = 0; |
Arend van Spriel | 06bb123 | 2012-09-27 14:17:56 +0200 | [diff] [blame] | 2411 | u8 *bssid = profile->bssid; |
Hante Meuleman | 81f5dcb | 2012-10-22 10:36:14 -0700 | [diff] [blame] | 2412 | struct brcmf_sta_info_le sta_info_le; |
Hante Meuleman | 9ee66d1 | 2014-01-29 15:32:11 +0100 | [diff] [blame] | 2413 | u32 beacon_period; |
| 2414 | u32 dtim_period; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2415 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 2416 | brcmf_dbg(TRACE, "Enter, MAC %pM\n", mac); |
Arend van Spriel | ce81e31 | 2012-10-22 13:55:37 -0700 | [diff] [blame] | 2417 | if (!check_vif_up(ifp->vif)) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2418 | return -EIO; |
| 2419 | |
Arend van Spriel | 967fe2c | 2014-03-15 17:18:21 +0100 | [diff] [blame] | 2420 | if (brcmf_is_apmode(ifp->vif)) { |
Hante Meuleman | 81f5dcb | 2012-10-22 10:36:14 -0700 | [diff] [blame] | 2421 | memcpy(&sta_info_le, mac, ETH_ALEN); |
Arend van Spriel | 0abb5f21 | 2012-10-22 13:55:32 -0700 | [diff] [blame] | 2422 | err = brcmf_fil_iovar_data_get(ifp, "sta_info", |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 2423 | &sta_info_le, |
Hante Meuleman | 81f5dcb | 2012-10-22 10:36:14 -0700 | [diff] [blame] | 2424 | sizeof(sta_info_le)); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 2425 | if (err < 0) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 2426 | brcmf_err("GET STA INFO failed, %d\n", err); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 2427 | goto done; |
Hante Meuleman | 7f6c562 | 2012-08-30 10:05:37 +0200 | [diff] [blame] | 2428 | } |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 2429 | sinfo->filled = BIT(NL80211_STA_INFO_INACTIVE_TIME); |
Hante Meuleman | 81f5dcb | 2012-10-22 10:36:14 -0700 | [diff] [blame] | 2430 | sinfo->inactive_time = le32_to_cpu(sta_info_le.idle) * 1000; |
| 2431 | if (le32_to_cpu(sta_info_le.flags) & BRCMF_STA_ASSOC) { |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 2432 | sinfo->filled |= BIT(NL80211_STA_INFO_CONNECTED_TIME); |
Hante Meuleman | 81f5dcb | 2012-10-22 10:36:14 -0700 | [diff] [blame] | 2433 | sinfo->connected_time = le32_to_cpu(sta_info_le.in); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 2434 | } |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 2435 | brcmf_dbg(TRACE, "STA idle time : %d ms, connected time :%d sec\n", |
| 2436 | sinfo->inactive_time, sinfo->connected_time); |
Arend van Spriel | 967fe2c | 2014-03-15 17:18:21 +0100 | [diff] [blame] | 2437 | } else if (ifp->vif->wdev.iftype == NL80211_IFTYPE_STATION) { |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 2438 | if (memcmp(mac, bssid, ETH_ALEN)) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 2439 | brcmf_err("Wrong Mac address cfg_mac-%pM wl_bssid-%pM\n", |
| 2440 | mac, bssid); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 2441 | err = -ENOENT; |
| 2442 | goto done; |
| 2443 | } |
| 2444 | /* Report the current tx rate */ |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 2445 | err = brcmf_fil_cmd_int_get(ifp, BRCMF_C_GET_RATE, &rate); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 2446 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 2447 | brcmf_err("Could not get rate (%d)\n", err); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 2448 | goto done; |
| 2449 | } else { |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 2450 | sinfo->filled |= BIT(NL80211_STA_INFO_TX_BITRATE); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 2451 | sinfo->txrate.legacy = rate * 5; |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 2452 | brcmf_dbg(CONN, "Rate %d Mbps\n", rate / 2); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 2453 | } |
| 2454 | |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 2455 | if (test_bit(BRCMF_VIF_STATUS_CONNECTED, |
| 2456 | &ifp->vif->sme_state)) { |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 2457 | memset(&scb_val, 0, sizeof(scb_val)); |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 2458 | err = brcmf_fil_cmd_data_get(ifp, BRCMF_C_GET_RSSI, |
| 2459 | &scb_val, sizeof(scb_val)); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 2460 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 2461 | brcmf_err("Could not get rssi (%d)\n", err); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 2462 | goto done; |
| 2463 | } else { |
| 2464 | rssi = le32_to_cpu(scb_val.val); |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 2465 | sinfo->filled |= BIT(NL80211_STA_INFO_SIGNAL); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 2466 | sinfo->signal = rssi; |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 2467 | brcmf_dbg(CONN, "RSSI %d dBm\n", rssi); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 2468 | } |
Hante Meuleman | 9ee66d1 | 2014-01-29 15:32:11 +0100 | [diff] [blame] | 2469 | err = brcmf_fil_cmd_int_get(ifp, BRCMF_C_GET_BCNPRD, |
| 2470 | &beacon_period); |
| 2471 | if (err) { |
| 2472 | brcmf_err("Could not get beacon period (%d)\n", |
| 2473 | err); |
| 2474 | goto done; |
| 2475 | } else { |
| 2476 | sinfo->bss_param.beacon_interval = |
| 2477 | beacon_period; |
| 2478 | brcmf_dbg(CONN, "Beacon peroid %d\n", |
| 2479 | beacon_period); |
| 2480 | } |
| 2481 | err = brcmf_fil_cmd_int_get(ifp, BRCMF_C_GET_DTIMPRD, |
| 2482 | &dtim_period); |
| 2483 | if (err) { |
| 2484 | brcmf_err("Could not get DTIM period (%d)\n", |
| 2485 | err); |
| 2486 | goto done; |
| 2487 | } else { |
| 2488 | sinfo->bss_param.dtim_period = dtim_period; |
| 2489 | brcmf_dbg(CONN, "DTIM peroid %d\n", |
| 2490 | dtim_period); |
| 2491 | } |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 2492 | sinfo->filled |= BIT(NL80211_STA_INFO_BSS_PARAM); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 2493 | } |
| 2494 | } else |
| 2495 | err = -EPERM; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2496 | done: |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 2497 | brcmf_dbg(TRACE, "Exit\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2498 | return err; |
| 2499 | } |
| 2500 | |
| 2501 | static s32 |
| 2502 | brcmf_cfg80211_set_power_mgmt(struct wiphy *wiphy, struct net_device *ndev, |
| 2503 | bool enabled, s32 timeout) |
| 2504 | { |
| 2505 | s32 pm; |
| 2506 | s32 err = 0; |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 2507 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 2508 | struct brcmf_if *ifp = netdev_priv(ndev); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2509 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 2510 | brcmf_dbg(TRACE, "Enter\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2511 | |
| 2512 | /* |
| 2513 | * Powersave enable/disable request is coming from the |
| 2514 | * cfg80211 even before the interface is up. In that |
| 2515 | * scenario, driver will be storing the power save |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 2516 | * preference in cfg struct to apply this to |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2517 | * FW later while initializing the dongle |
| 2518 | */ |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 2519 | cfg->pwr_save = enabled; |
Arend van Spriel | ce81e31 | 2012-10-22 13:55:37 -0700 | [diff] [blame] | 2520 | if (!check_vif_up(ifp->vif)) { |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2521 | |
Arend van Spriel | 647c9ae | 2012-12-05 15:26:01 +0100 | [diff] [blame] | 2522 | 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] | 2523 | goto done; |
| 2524 | } |
| 2525 | |
| 2526 | pm = enabled ? PM_FAST : PM_OFF; |
Hante Meuleman | 102fd0d | 2013-05-27 21:09:59 +0200 | [diff] [blame] | 2527 | /* Do not enable the power save after assoc if it is a p2p interface */ |
| 2528 | if (ifp->vif->wdev.iftype == NL80211_IFTYPE_P2P_CLIENT) { |
| 2529 | brcmf_dbg(INFO, "Do not enable power save for P2P clients\n"); |
| 2530 | pm = PM_OFF; |
| 2531 | } |
Arend van Spriel | 647c9ae | 2012-12-05 15:26:01 +0100 | [diff] [blame] | 2532 | brcmf_dbg(INFO, "power save %s\n", (pm ? "enabled" : "disabled")); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2533 | |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 2534 | 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] | 2535 | if (err) { |
| 2536 | if (err == -ENODEV) |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 2537 | brcmf_err("net_device is not ready yet\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2538 | else |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 2539 | brcmf_err("error (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2540 | } |
| 2541 | done: |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 2542 | brcmf_dbg(TRACE, "Exit\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2543 | return err; |
| 2544 | } |
| 2545 | |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 2546 | static s32 brcmf_inform_single_bss(struct brcmf_cfg80211_info *cfg, |
Roland Vossen | d34bf64 | 2011-10-18 14:03:01 +0200 | [diff] [blame] | 2547 | struct brcmf_bss_info_le *bi) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2548 | { |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 2549 | struct wiphy *wiphy = cfg_to_wiphy(cfg); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2550 | struct ieee80211_channel *notify_channel; |
| 2551 | struct cfg80211_bss *bss; |
| 2552 | struct ieee80211_supported_band *band; |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 2553 | struct brcmu_chan ch; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2554 | u16 channel; |
| 2555 | u32 freq; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2556 | u16 notify_capability; |
| 2557 | u16 notify_interval; |
| 2558 | u8 *notify_ie; |
| 2559 | size_t notify_ielen; |
| 2560 | s32 notify_signal; |
| 2561 | |
| 2562 | if (le32_to_cpu(bi->length) > WL_BSS_INFO_MAX) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 2563 | brcmf_err("Bss info is larger than buffer. Discarding\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2564 | return 0; |
| 2565 | } |
| 2566 | |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 2567 | if (!bi->ctl_ch) { |
| 2568 | ch.chspec = le16_to_cpu(bi->chanspec); |
| 2569 | cfg->d11inf.decchspec(&ch); |
| 2570 | bi->ctl_ch = ch.chnum; |
| 2571 | } |
| 2572 | channel = bi->ctl_ch; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2573 | |
| 2574 | if (channel <= CH_MAX_2G_CHANNEL) |
| 2575 | band = wiphy->bands[IEEE80211_BAND_2GHZ]; |
| 2576 | else |
| 2577 | band = wiphy->bands[IEEE80211_BAND_5GHZ]; |
| 2578 | |
| 2579 | freq = ieee80211_channel_to_frequency(channel, band->band); |
| 2580 | notify_channel = ieee80211_get_channel(wiphy, freq); |
| 2581 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2582 | notify_capability = le16_to_cpu(bi->capability); |
| 2583 | notify_interval = le16_to_cpu(bi->beacon_period); |
| 2584 | notify_ie = (u8 *)bi + le16_to_cpu(bi->ie_offset); |
| 2585 | notify_ielen = le32_to_cpu(bi->ie_length); |
| 2586 | notify_signal = (s16)le16_to_cpu(bi->RSSI) * 100; |
| 2587 | |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 2588 | brcmf_dbg(CONN, "bssid: %pM\n", bi->BSSID); |
| 2589 | brcmf_dbg(CONN, "Channel: %d(%d)\n", channel, freq); |
| 2590 | brcmf_dbg(CONN, "Capability: %X\n", notify_capability); |
| 2591 | brcmf_dbg(CONN, "Beacon interval: %d\n", notify_interval); |
| 2592 | brcmf_dbg(CONN, "Signal: %d\n", notify_signal); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2593 | |
Johannes Berg | 5bc8c1f | 2014-08-12 21:01:28 +0200 | [diff] [blame] | 2594 | bss = cfg80211_inform_bss(wiphy, notify_channel, |
| 2595 | CFG80211_BSS_FTYPE_UNKNOWN, |
| 2596 | (const u8 *)bi->BSSID, |
| 2597 | 0, notify_capability, |
| 2598 | notify_interval, notify_ie, |
| 2599 | notify_ielen, notify_signal, |
| 2600 | GFP_KERNEL); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2601 | |
Franky Lin | e78946e | 2011-11-10 20:30:34 +0100 | [diff] [blame] | 2602 | if (!bss) |
| 2603 | return -ENOMEM; |
| 2604 | |
Johannes Berg | 5b112d3 | 2013-02-01 01:49:58 +0100 | [diff] [blame] | 2605 | cfg80211_put_bss(wiphy, bss); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2606 | |
Peter Senna Tschudin | 12f3237 | 2014-05-31 10:14:06 -0300 | [diff] [blame] | 2607 | return 0; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2608 | } |
| 2609 | |
Roland Vossen | 6f09be0 | 2011-10-18 14:03:02 +0200 | [diff] [blame] | 2610 | static struct brcmf_bss_info_le * |
| 2611 | next_bss_le(struct brcmf_scan_results *list, struct brcmf_bss_info_le *bss) |
| 2612 | { |
| 2613 | if (bss == NULL) |
| 2614 | return list->bss_info_le; |
| 2615 | return (struct brcmf_bss_info_le *)((unsigned long)bss + |
| 2616 | le32_to_cpu(bss->length)); |
| 2617 | } |
| 2618 | |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 2619 | static s32 brcmf_inform_bss(struct brcmf_cfg80211_info *cfg) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2620 | { |
| 2621 | struct brcmf_scan_results *bss_list; |
Roland Vossen | d34bf64 | 2011-10-18 14:03:01 +0200 | [diff] [blame] | 2622 | struct brcmf_bss_info_le *bi = NULL; /* must be initialized */ |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2623 | s32 err = 0; |
| 2624 | int i; |
| 2625 | |
Hante Meuleman | ef8596e | 2014-09-30 10:23:13 +0200 | [diff] [blame] | 2626 | bss_list = (struct brcmf_scan_results *)cfg->escan_info.escan_buf; |
Arend van Spriel | 0ecd816 | 2012-11-05 16:22:11 -0800 | [diff] [blame] | 2627 | if (bss_list->count != 0 && |
| 2628 | bss_list->version != BRCMF_BSS_INFO_VERSION) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 2629 | brcmf_err("Version %d != WL_BSS_INFO_VERSION\n", |
| 2630 | bss_list->version); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2631 | return -EOPNOTSUPP; |
| 2632 | } |
Arend van Spriel | 4e8a008 | 2012-12-05 15:26:03 +0100 | [diff] [blame] | 2633 | brcmf_dbg(SCAN, "scanned AP count (%d)\n", bss_list->count); |
Hante Meuleman | f0799895 | 2012-11-05 16:22:13 -0800 | [diff] [blame] | 2634 | for (i = 0; i < bss_list->count; i++) { |
Roland Vossen | 6f09be0 | 2011-10-18 14:03:02 +0200 | [diff] [blame] | 2635 | bi = next_bss_le(bss_list, bi); |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 2636 | err = brcmf_inform_single_bss(cfg, bi); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2637 | if (err) |
| 2638 | break; |
| 2639 | } |
| 2640 | return err; |
| 2641 | } |
| 2642 | |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 2643 | static s32 wl_inform_ibss(struct brcmf_cfg80211_info *cfg, |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2644 | struct net_device *ndev, const u8 *bssid) |
| 2645 | { |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 2646 | struct wiphy *wiphy = cfg_to_wiphy(cfg); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2647 | struct ieee80211_channel *notify_channel; |
Roland Vossen | d34bf64 | 2011-10-18 14:03:01 +0200 | [diff] [blame] | 2648 | struct brcmf_bss_info_le *bi = NULL; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2649 | struct ieee80211_supported_band *band; |
Franky Lin | e78946e | 2011-11-10 20:30:34 +0100 | [diff] [blame] | 2650 | struct cfg80211_bss *bss; |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 2651 | struct brcmu_chan ch; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2652 | u8 *buf = NULL; |
| 2653 | s32 err = 0; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2654 | u32 freq; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2655 | u16 notify_capability; |
| 2656 | u16 notify_interval; |
| 2657 | u8 *notify_ie; |
| 2658 | size_t notify_ielen; |
| 2659 | s32 notify_signal; |
| 2660 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 2661 | brcmf_dbg(TRACE, "Enter\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2662 | |
| 2663 | buf = kzalloc(WL_BSS_INFO_MAX, GFP_KERNEL); |
| 2664 | if (buf == NULL) { |
| 2665 | err = -ENOMEM; |
| 2666 | goto CleanUp; |
| 2667 | } |
| 2668 | |
| 2669 | *(__le32 *)buf = cpu_to_le32(WL_BSS_INFO_MAX); |
| 2670 | |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 2671 | err = brcmf_fil_cmd_data_get(netdev_priv(ndev), BRCMF_C_GET_BSS_INFO, |
| 2672 | buf, WL_BSS_INFO_MAX); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2673 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 2674 | brcmf_err("WLC_GET_BSS_INFO failed: %d\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2675 | goto CleanUp; |
| 2676 | } |
| 2677 | |
Roland Vossen | d34bf64 | 2011-10-18 14:03:01 +0200 | [diff] [blame] | 2678 | bi = (struct brcmf_bss_info_le *)(buf + 4); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2679 | |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 2680 | ch.chspec = le16_to_cpu(bi->chanspec); |
| 2681 | cfg->d11inf.decchspec(&ch); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2682 | |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 2683 | if (ch.band == BRCMU_CHAN_BAND_2G) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2684 | band = wiphy->bands[IEEE80211_BAND_2GHZ]; |
| 2685 | else |
| 2686 | band = wiphy->bands[IEEE80211_BAND_5GHZ]; |
| 2687 | |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 2688 | freq = ieee80211_channel_to_frequency(ch.chnum, band->band); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2689 | notify_channel = ieee80211_get_channel(wiphy, freq); |
| 2690 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2691 | notify_capability = le16_to_cpu(bi->capability); |
| 2692 | notify_interval = le16_to_cpu(bi->beacon_period); |
| 2693 | notify_ie = (u8 *)bi + le16_to_cpu(bi->ie_offset); |
| 2694 | notify_ielen = le32_to_cpu(bi->ie_length); |
| 2695 | notify_signal = (s16)le16_to_cpu(bi->RSSI) * 100; |
| 2696 | |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 2697 | brcmf_dbg(CONN, "channel: %d(%d)\n", ch.chnum, freq); |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 2698 | brcmf_dbg(CONN, "capability: %X\n", notify_capability); |
| 2699 | brcmf_dbg(CONN, "beacon interval: %d\n", notify_interval); |
| 2700 | brcmf_dbg(CONN, "signal: %d\n", notify_signal); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2701 | |
Johannes Berg | 5bc8c1f | 2014-08-12 21:01:28 +0200 | [diff] [blame] | 2702 | bss = cfg80211_inform_bss(wiphy, notify_channel, |
| 2703 | CFG80211_BSS_FTYPE_UNKNOWN, bssid, 0, |
| 2704 | notify_capability, notify_interval, |
| 2705 | notify_ie, notify_ielen, notify_signal, |
| 2706 | GFP_KERNEL); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2707 | |
Franky Lin | e78946e | 2011-11-10 20:30:34 +0100 | [diff] [blame] | 2708 | if (!bss) { |
| 2709 | err = -ENOMEM; |
| 2710 | goto CleanUp; |
| 2711 | } |
| 2712 | |
Johannes Berg | 5b112d3 | 2013-02-01 01:49:58 +0100 | [diff] [blame] | 2713 | cfg80211_put_bss(wiphy, bss); |
Franky Lin | e78946e | 2011-11-10 20:30:34 +0100 | [diff] [blame] | 2714 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2715 | CleanUp: |
| 2716 | |
| 2717 | kfree(buf); |
| 2718 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 2719 | brcmf_dbg(TRACE, "Exit\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2720 | |
| 2721 | return err; |
| 2722 | } |
| 2723 | |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 2724 | static s32 brcmf_update_bss_info(struct brcmf_cfg80211_info *cfg, |
| 2725 | struct brcmf_if *ifp) |
Alwin Beukers | f8e4b41 | 2011-10-12 20:51:28 +0200 | [diff] [blame] | 2726 | { |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 2727 | struct brcmf_cfg80211_profile *profile = ndev_to_prof(ifp->ndev); |
Roland Vossen | d34bf64 | 2011-10-18 14:03:01 +0200 | [diff] [blame] | 2728 | struct brcmf_bss_info_le *bi; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2729 | struct brcmf_ssid *ssid; |
Johannes Berg | 4b5800f | 2014-01-15 14:55:59 +0100 | [diff] [blame] | 2730 | const struct brcmf_tlv *tim; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2731 | u16 beacon_interval; |
| 2732 | u8 dtim_period; |
| 2733 | size_t ie_len; |
| 2734 | u8 *ie; |
| 2735 | s32 err = 0; |
| 2736 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 2737 | brcmf_dbg(TRACE, "Enter\n"); |
Arend van Spriel | 128ce3b | 2012-11-28 21:44:12 +0100 | [diff] [blame] | 2738 | if (brcmf_is_ibssmode(ifp->vif)) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2739 | return err; |
| 2740 | |
Arend van Spriel | 06bb123 | 2012-09-27 14:17:56 +0200 | [diff] [blame] | 2741 | ssid = &profile->ssid; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2742 | |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 2743 | *(__le32 *)cfg->extra_buf = cpu_to_le32(WL_EXTRA_BUF_MAX); |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 2744 | err = brcmf_fil_cmd_data_get(ifp, BRCMF_C_GET_BSS_INFO, |
Hante Meuleman | 81f5dcb | 2012-10-22 10:36:14 -0700 | [diff] [blame] | 2745 | cfg->extra_buf, WL_EXTRA_BUF_MAX); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2746 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 2747 | brcmf_err("Could not get bss info %d\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2748 | goto update_bss_info_out; |
| 2749 | } |
| 2750 | |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 2751 | bi = (struct brcmf_bss_info_le *)(cfg->extra_buf + 4); |
| 2752 | err = brcmf_inform_single_bss(cfg, bi); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2753 | if (err) |
| 2754 | goto update_bss_info_out; |
| 2755 | |
| 2756 | ie = ((u8 *)bi) + le16_to_cpu(bi->ie_offset); |
| 2757 | ie_len = le32_to_cpu(bi->ie_length); |
| 2758 | beacon_interval = le16_to_cpu(bi->beacon_period); |
| 2759 | |
Alwin Beukers | f8e4b41 | 2011-10-12 20:51:28 +0200 | [diff] [blame] | 2760 | tim = brcmf_parse_tlvs(ie, ie_len, WLAN_EID_TIM); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2761 | if (tim) |
| 2762 | dtim_period = tim->data[1]; |
| 2763 | else { |
| 2764 | /* |
| 2765 | * active scan was done so we could not get dtim |
| 2766 | * information out of probe response. |
| 2767 | * so we speficially query dtim information to dongle. |
| 2768 | */ |
| 2769 | u32 var; |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 2770 | err = brcmf_fil_iovar_int_get(ifp, "dtim_assoc", &var); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2771 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 2772 | brcmf_err("wl dtim_assoc failed (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2773 | goto update_bss_info_out; |
| 2774 | } |
| 2775 | dtim_period = (u8)var; |
| 2776 | } |
| 2777 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2778 | update_bss_info_out: |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 2779 | brcmf_dbg(TRACE, "Exit"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2780 | return err; |
| 2781 | } |
| 2782 | |
Hante Meuleman | 18e2f61 | 2013-02-08 15:53:49 +0100 | [diff] [blame] | 2783 | void brcmf_abort_scanning(struct brcmf_cfg80211_info *cfg) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2784 | { |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 2785 | struct escan_info *escan = &cfg->escan_info; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2786 | |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 2787 | set_bit(BRCMF_SCAN_STATUS_ABORT, &cfg->scan_status); |
Hante Meuleman | f0799895 | 2012-11-05 16:22:13 -0800 | [diff] [blame] | 2788 | if (cfg->scan_request) { |
Arend van Spriel | 108a4be | 2012-09-19 22:21:07 +0200 | [diff] [blame] | 2789 | escan->escan_state = WL_ESCAN_STATE_IDLE; |
Arend van Spriel | a0f472a | 2013-04-05 10:57:49 +0200 | [diff] [blame] | 2790 | brcmf_notify_escan_complete(cfg, escan->ifp, true, true); |
Arend van Spriel | 108a4be | 2012-09-19 22:21:07 +0200 | [diff] [blame] | 2791 | } |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 2792 | clear_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status); |
| 2793 | clear_bit(BRCMF_SCAN_STATUS_ABORT, &cfg->scan_status); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2794 | } |
| 2795 | |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 2796 | static void brcmf_cfg80211_escan_timeout_worker(struct work_struct *work) |
| 2797 | { |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 2798 | struct brcmf_cfg80211_info *cfg = |
| 2799 | container_of(work, struct brcmf_cfg80211_info, |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 2800 | escan_timeout_work); |
| 2801 | |
Hante Meuleman | ef8596e | 2014-09-30 10:23:13 +0200 | [diff] [blame] | 2802 | brcmf_inform_bss(cfg); |
Arend van Spriel | a0f472a | 2013-04-05 10:57:49 +0200 | [diff] [blame] | 2803 | brcmf_notify_escan_complete(cfg, cfg->escan_info.ifp, true, true); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 2804 | } |
| 2805 | |
| 2806 | static void brcmf_escan_timeout(unsigned long data) |
| 2807 | { |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 2808 | struct brcmf_cfg80211_info *cfg = |
| 2809 | (struct brcmf_cfg80211_info *)data; |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 2810 | |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 2811 | if (cfg->scan_request) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 2812 | brcmf_err("timer expired\n"); |
Hante Meuleman | f0799895 | 2012-11-05 16:22:13 -0800 | [diff] [blame] | 2813 | schedule_work(&cfg->escan_timeout_work); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 2814 | } |
| 2815 | } |
| 2816 | |
| 2817 | static s32 |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 2818 | brcmf_compare_update_same_bss(struct brcmf_cfg80211_info *cfg, |
| 2819 | struct brcmf_bss_info_le *bss, |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 2820 | struct brcmf_bss_info_le *bss_info_le) |
| 2821 | { |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 2822 | struct brcmu_chan ch_bss, ch_bss_info_le; |
| 2823 | |
| 2824 | ch_bss.chspec = le16_to_cpu(bss->chanspec); |
| 2825 | cfg->d11inf.decchspec(&ch_bss); |
| 2826 | ch_bss_info_le.chspec = le16_to_cpu(bss_info_le->chanspec); |
| 2827 | cfg->d11inf.decchspec(&ch_bss_info_le); |
| 2828 | |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 2829 | if (!memcmp(&bss_info_le->BSSID, &bss->BSSID, ETH_ALEN) && |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 2830 | ch_bss.band == ch_bss_info_le.band && |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 2831 | bss_info_le->SSID_len == bss->SSID_len && |
| 2832 | !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] | 2833 | if ((bss->flags & BRCMF_BSS_RSSI_ON_CHANNEL) == |
| 2834 | (bss_info_le->flags & BRCMF_BSS_RSSI_ON_CHANNEL)) { |
Arend van Spriel | 029591f | 2012-09-19 22:21:06 +0200 | [diff] [blame] | 2835 | s16 bss_rssi = le16_to_cpu(bss->RSSI); |
| 2836 | s16 bss_info_rssi = le16_to_cpu(bss_info_le->RSSI); |
| 2837 | |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 2838 | /* preserve max RSSI if the measurements are |
| 2839 | * both on-channel or both off-channel |
| 2840 | */ |
Arend van Spriel | 029591f | 2012-09-19 22:21:06 +0200 | [diff] [blame] | 2841 | if (bss_info_rssi > bss_rssi) |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 2842 | bss->RSSI = bss_info_le->RSSI; |
Arend van Spriel | 6f5838a | 2013-11-29 12:25:19 +0100 | [diff] [blame] | 2843 | } else if ((bss->flags & BRCMF_BSS_RSSI_ON_CHANNEL) && |
| 2844 | (bss_info_le->flags & BRCMF_BSS_RSSI_ON_CHANNEL) == 0) { |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 2845 | /* preserve the on-channel rssi measurement |
| 2846 | * if the new measurement is off channel |
| 2847 | */ |
| 2848 | bss->RSSI = bss_info_le->RSSI; |
Arend van Spriel | 6f5838a | 2013-11-29 12:25:19 +0100 | [diff] [blame] | 2849 | bss->flags |= BRCMF_BSS_RSSI_ON_CHANNEL; |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 2850 | } |
| 2851 | return 1; |
| 2852 | } |
| 2853 | return 0; |
| 2854 | } |
| 2855 | |
| 2856 | static s32 |
Arend van Spriel | 1993732 | 2012-11-05 16:22:32 -0800 | [diff] [blame] | 2857 | brcmf_cfg80211_escan_handler(struct brcmf_if *ifp, |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 2858 | const struct brcmf_event_msg *e, void *data) |
| 2859 | { |
Arend van Spriel | 1993732 | 2012-11-05 16:22:32 -0800 | [diff] [blame] | 2860 | struct brcmf_cfg80211_info *cfg = ifp->drvr->config; |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 2861 | s32 status; |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 2862 | struct brcmf_escan_result_le *escan_result_le; |
| 2863 | struct brcmf_bss_info_le *bss_info_le; |
| 2864 | struct brcmf_bss_info_le *bss = NULL; |
| 2865 | u32 bi_length; |
| 2866 | struct brcmf_scan_results *list; |
| 2867 | u32 i; |
Arend van Spriel | 97ed15c | 2012-09-13 21:12:06 +0200 | [diff] [blame] | 2868 | bool aborted; |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 2869 | |
Arend van Spriel | 5c36b99 | 2012-11-14 18:46:05 -0800 | [diff] [blame] | 2870 | status = e->status; |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 2871 | |
Arend van Spriel | a0f472a | 2013-04-05 10:57:49 +0200 | [diff] [blame] | 2872 | if (!test_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status)) { |
| 2873 | brcmf_err("scan not ready, bssidx=%d\n", ifp->bssidx); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 2874 | return -EPERM; |
| 2875 | } |
| 2876 | |
| 2877 | if (status == BRCMF_E_STATUS_PARTIAL) { |
Arend van Spriel | 4e8a008 | 2012-12-05 15:26:03 +0100 | [diff] [blame] | 2878 | brcmf_dbg(SCAN, "ESCAN Partial result\n"); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 2879 | escan_result_le = (struct brcmf_escan_result_le *) data; |
| 2880 | if (!escan_result_le) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 2881 | brcmf_err("Invalid escan result (NULL pointer)\n"); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 2882 | goto exit; |
| 2883 | } |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 2884 | if (le16_to_cpu(escan_result_le->bss_count) != 1) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 2885 | brcmf_err("Invalid bss_count %d: ignoring\n", |
| 2886 | escan_result_le->bss_count); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 2887 | goto exit; |
| 2888 | } |
| 2889 | bss_info_le = &escan_result_le->bss_info_le; |
| 2890 | |
Hante Meuleman | 6eda4e2 | 2013-02-08 15:54:02 +0100 | [diff] [blame] | 2891 | if (brcmf_p2p_scan_finding_common_channel(cfg, bss_info_le)) |
| 2892 | goto exit; |
| 2893 | |
| 2894 | if (!cfg->scan_request) { |
| 2895 | brcmf_dbg(SCAN, "result without cfg80211 request\n"); |
| 2896 | goto exit; |
| 2897 | } |
| 2898 | |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 2899 | bi_length = le32_to_cpu(bss_info_le->length); |
| 2900 | if (bi_length != (le32_to_cpu(escan_result_le->buflen) - |
| 2901 | WL_ESCAN_RESULTS_FIXED_SIZE)) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 2902 | brcmf_err("Invalid bss_info length %d: ignoring\n", |
| 2903 | bi_length); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 2904 | goto exit; |
| 2905 | } |
| 2906 | |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 2907 | if (!(cfg_to_wiphy(cfg)->interface_modes & |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 2908 | BIT(NL80211_IFTYPE_ADHOC))) { |
| 2909 | if (le16_to_cpu(bss_info_le->capability) & |
| 2910 | WLAN_CAPABILITY_IBSS) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 2911 | brcmf_err("Ignoring IBSS result\n"); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 2912 | goto exit; |
| 2913 | } |
| 2914 | } |
| 2915 | |
| 2916 | list = (struct brcmf_scan_results *) |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 2917 | cfg->escan_info.escan_buf; |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 2918 | if (bi_length > WL_ESCAN_BUF_SIZE - list->buflen) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 2919 | brcmf_err("Buffer is too small: ignoring\n"); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 2920 | goto exit; |
| 2921 | } |
| 2922 | |
| 2923 | for (i = 0; i < list->count; i++) { |
| 2924 | bss = bss ? (struct brcmf_bss_info_le *) |
| 2925 | ((unsigned char *)bss + |
| 2926 | le32_to_cpu(bss->length)) : list->bss_info_le; |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 2927 | if (brcmf_compare_update_same_bss(cfg, bss, |
| 2928 | bss_info_le)) |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 2929 | goto exit; |
| 2930 | } |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 2931 | memcpy(&(cfg->escan_info.escan_buf[list->buflen]), |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 2932 | bss_info_le, bi_length); |
| 2933 | list->version = le32_to_cpu(bss_info_le->version); |
| 2934 | list->buflen += bi_length; |
| 2935 | list->count++; |
| 2936 | } else { |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 2937 | cfg->escan_info.escan_state = WL_ESCAN_STATE_IDLE; |
Hante Meuleman | 6eda4e2 | 2013-02-08 15:54:02 +0100 | [diff] [blame] | 2938 | if (brcmf_p2p_scan_finding_common_channel(cfg, NULL)) |
| 2939 | goto exit; |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 2940 | if (cfg->scan_request) { |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 2941 | brcmf_inform_bss(cfg); |
Arend van Spriel | 97ed15c | 2012-09-13 21:12:06 +0200 | [diff] [blame] | 2942 | aborted = status != BRCMF_E_STATUS_SUCCESS; |
Hante Meuleman | ef8596e | 2014-09-30 10:23:13 +0200 | [diff] [blame] | 2943 | brcmf_notify_escan_complete(cfg, ifp, aborted, false); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 2944 | } else |
Hante Meuleman | 6eda4e2 | 2013-02-08 15:54:02 +0100 | [diff] [blame] | 2945 | brcmf_dbg(SCAN, "Ignored scan complete result 0x%x\n", |
| 2946 | status); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 2947 | } |
| 2948 | exit: |
Peter Senna Tschudin | 12f3237 | 2014-05-31 10:14:06 -0300 | [diff] [blame] | 2949 | return 0; |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 2950 | } |
| 2951 | |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 2952 | static void brcmf_init_escan(struct brcmf_cfg80211_info *cfg) |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 2953 | { |
Arend van Spriel | 5c36b99 | 2012-11-14 18:46:05 -0800 | [diff] [blame] | 2954 | brcmf_fweh_register(cfg->pub, BRCMF_E_ESCAN_RESULT, |
| 2955 | brcmf_cfg80211_escan_handler); |
Hante Meuleman | f0799895 | 2012-11-05 16:22:13 -0800 | [diff] [blame] | 2956 | cfg->escan_info.escan_state = WL_ESCAN_STATE_IDLE; |
| 2957 | /* Init scan_timeout timer */ |
| 2958 | init_timer(&cfg->escan_timeout); |
| 2959 | cfg->escan_timeout.data = (unsigned long) cfg; |
| 2960 | cfg->escan_timeout.function = brcmf_escan_timeout; |
| 2961 | INIT_WORK(&cfg->escan_timeout_work, |
| 2962 | brcmf_cfg80211_escan_timeout_worker); |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 2963 | } |
| 2964 | |
Alexandre Oliva | 5addc0d | 2012-01-16 14:00:12 -0500 | [diff] [blame] | 2965 | static __always_inline void brcmf_delay(u32 ms) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 2966 | { |
| 2967 | if (ms < 1000 / HZ) { |
| 2968 | cond_resched(); |
| 2969 | mdelay(ms); |
| 2970 | } else { |
| 2971 | msleep(ms); |
| 2972 | } |
| 2973 | } |
| 2974 | |
Hante Meuleman | b9a82f8 | 2014-10-28 14:56:06 +0100 | [diff] [blame] | 2975 | static s32 brcmf_config_wowl_pattern(struct brcmf_if *ifp, u8 cmd[4], |
| 2976 | u8 *pattern, u32 patternsize, u8 *mask, |
| 2977 | u32 packet_offset) |
| 2978 | { |
| 2979 | struct brcmf_fil_wowl_pattern_le *filter; |
| 2980 | u32 masksize; |
| 2981 | u32 patternoffset; |
| 2982 | u8 *buf; |
| 2983 | u32 bufsize; |
| 2984 | s32 ret; |
| 2985 | |
| 2986 | masksize = (patternsize + 7) / 8; |
| 2987 | patternoffset = sizeof(*filter) - sizeof(filter->cmd) + masksize; |
| 2988 | |
| 2989 | bufsize = sizeof(*filter) + patternsize + masksize; |
| 2990 | buf = kzalloc(bufsize, GFP_KERNEL); |
| 2991 | if (!buf) |
| 2992 | return -ENOMEM; |
| 2993 | filter = (struct brcmf_fil_wowl_pattern_le *)buf; |
| 2994 | |
| 2995 | memcpy(filter->cmd, cmd, 4); |
| 2996 | filter->masksize = cpu_to_le32(masksize); |
| 2997 | filter->offset = cpu_to_le32(packet_offset); |
| 2998 | filter->patternoffset = cpu_to_le32(patternoffset); |
| 2999 | filter->patternsize = cpu_to_le32(patternsize); |
| 3000 | filter->type = cpu_to_le32(BRCMF_WOWL_PATTERN_TYPE_BITMAP); |
| 3001 | |
| 3002 | if ((mask) && (masksize)) |
| 3003 | memcpy(buf + sizeof(*filter), mask, masksize); |
| 3004 | if ((pattern) && (patternsize)) |
| 3005 | memcpy(buf + sizeof(*filter) + masksize, pattern, patternsize); |
| 3006 | |
| 3007 | ret = brcmf_fil_iovar_data_set(ifp, "wowl_pattern", buf, bufsize); |
| 3008 | |
| 3009 | kfree(buf); |
| 3010 | return ret; |
| 3011 | } |
| 3012 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3013 | static s32 brcmf_cfg80211_resume(struct wiphy *wiphy) |
| 3014 | { |
Hante Meuleman | 4eb3af7 | 2014-09-30 10:23:18 +0200 | [diff] [blame] | 3015 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); |
| 3016 | struct net_device *ndev = cfg_to_ndev(cfg); |
| 3017 | struct brcmf_if *ifp = netdev_priv(ndev); |
| 3018 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 3019 | brcmf_dbg(TRACE, "Enter\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3020 | |
Hante Meuleman | 4eb3af7 | 2014-09-30 10:23:18 +0200 | [diff] [blame] | 3021 | if (cfg->wowl_enabled) { |
Hante Meuleman | b9a82f8 | 2014-10-28 14:56:06 +0100 | [diff] [blame] | 3022 | brcmf_configure_arp_offload(ifp, true); |
Hante Meuleman | 4eb3af7 | 2014-09-30 10:23:18 +0200 | [diff] [blame] | 3023 | brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_PM, |
| 3024 | cfg->pre_wowl_pmmode); |
Hante Meuleman | 4eb3af7 | 2014-09-30 10:23:18 +0200 | [diff] [blame] | 3025 | brcmf_fil_iovar_int_set(ifp, "wowl_clear", 0); |
Hante Meuleman | b9a82f8 | 2014-10-28 14:56:06 +0100 | [diff] [blame] | 3026 | brcmf_config_wowl_pattern(ifp, "clr", NULL, 0, NULL, 0); |
Hante Meuleman | 4eb3af7 | 2014-09-30 10:23:18 +0200 | [diff] [blame] | 3027 | cfg->wowl_enabled = false; |
| 3028 | } |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3029 | return 0; |
| 3030 | } |
| 3031 | |
Hante Meuleman | 4eb3af7 | 2014-09-30 10:23:18 +0200 | [diff] [blame] | 3032 | static void brcmf_configure_wowl(struct brcmf_cfg80211_info *cfg, |
| 3033 | struct brcmf_if *ifp, |
| 3034 | struct cfg80211_wowlan *wowl) |
| 3035 | { |
| 3036 | u32 wowl_config; |
Hante Meuleman | b9a82f8 | 2014-10-28 14:56:06 +0100 | [diff] [blame] | 3037 | u32 i; |
Hante Meuleman | 4eb3af7 | 2014-09-30 10:23:18 +0200 | [diff] [blame] | 3038 | |
| 3039 | brcmf_dbg(TRACE, "Suspend, wowl config.\n"); |
| 3040 | |
Hante Meuleman | b9a82f8 | 2014-10-28 14:56:06 +0100 | [diff] [blame] | 3041 | brcmf_configure_arp_offload(ifp, false); |
Hante Meuleman | 4eb3af7 | 2014-09-30 10:23:18 +0200 | [diff] [blame] | 3042 | brcmf_fil_cmd_int_get(ifp, BRCMF_C_GET_PM, &cfg->pre_wowl_pmmode); |
| 3043 | brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_PM, PM_MAX); |
| 3044 | |
| 3045 | wowl_config = 0; |
| 3046 | if (wowl->disconnect) |
Hante Meuleman | b9a82f8 | 2014-10-28 14:56:06 +0100 | [diff] [blame] | 3047 | wowl_config = BRCMF_WOWL_DIS | BRCMF_WOWL_BCN | BRCMF_WOWL_RETR; |
Hante Meuleman | 4eb3af7 | 2014-09-30 10:23:18 +0200 | [diff] [blame] | 3048 | if (wowl->magic_pkt) |
Hante Meuleman | b9a82f8 | 2014-10-28 14:56:06 +0100 | [diff] [blame] | 3049 | wowl_config |= BRCMF_WOWL_MAGIC; |
| 3050 | if ((wowl->patterns) && (wowl->n_patterns)) { |
| 3051 | wowl_config |= BRCMF_WOWL_NET; |
| 3052 | for (i = 0; i < wowl->n_patterns; i++) { |
| 3053 | brcmf_config_wowl_pattern(ifp, "add", |
| 3054 | (u8 *)wowl->patterns[i].pattern, |
| 3055 | wowl->patterns[i].pattern_len, |
| 3056 | (u8 *)wowl->patterns[i].mask, |
| 3057 | wowl->patterns[i].pkt_offset); |
| 3058 | } |
| 3059 | } |
Hante Meuleman | 4eb3af7 | 2014-09-30 10:23:18 +0200 | [diff] [blame] | 3060 | brcmf_fil_iovar_int_set(ifp, "wowl", wowl_config); |
| 3061 | brcmf_fil_iovar_int_set(ifp, "wowl_activate", 1); |
| 3062 | brcmf_bus_wowl_config(cfg->pub->bus_if, true); |
| 3063 | cfg->wowl_enabled = true; |
| 3064 | } |
| 3065 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3066 | static s32 brcmf_cfg80211_suspend(struct wiphy *wiphy, |
Hante Meuleman | 4eb3af7 | 2014-09-30 10:23:18 +0200 | [diff] [blame] | 3067 | struct cfg80211_wowlan *wowl) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3068 | { |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 3069 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); |
| 3070 | struct net_device *ndev = cfg_to_ndev(cfg); |
Hante Meuleman | 4eb3af7 | 2014-09-30 10:23:18 +0200 | [diff] [blame] | 3071 | struct brcmf_if *ifp = netdev_priv(ndev); |
Arend van Spriel | 7d64107 | 2012-10-22 13:55:39 -0700 | [diff] [blame] | 3072 | struct brcmf_cfg80211_vif *vif; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3073 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 3074 | brcmf_dbg(TRACE, "Enter\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3075 | |
Hante Meuleman | 4eb3af7 | 2014-09-30 10:23:18 +0200 | [diff] [blame] | 3076 | /* if the primary net_device is not READY there is nothing |
Arend van Spriel | 7d64107 | 2012-10-22 13:55:39 -0700 | [diff] [blame] | 3077 | * we can do but pray resume goes smoothly. |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3078 | */ |
Hante Meuleman | 4eb3af7 | 2014-09-30 10:23:18 +0200 | [diff] [blame] | 3079 | if (!check_vif_up(ifp->vif)) |
Arend van Spriel | 7d64107 | 2012-10-22 13:55:39 -0700 | [diff] [blame] | 3080 | goto exit; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3081 | |
Arend van Spriel | 7d64107 | 2012-10-22 13:55:39 -0700 | [diff] [blame] | 3082 | /* end any scanning */ |
| 3083 | if (test_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status)) |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 3084 | brcmf_abort_scanning(cfg); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3085 | |
Hante Meuleman | 4eb3af7 | 2014-09-30 10:23:18 +0200 | [diff] [blame] | 3086 | if (wowl == NULL) { |
| 3087 | brcmf_bus_wowl_config(cfg->pub->bus_if, false); |
| 3088 | list_for_each_entry(vif, &cfg->vif_list, list) { |
| 3089 | if (!test_bit(BRCMF_VIF_STATUS_READY, &vif->sme_state)) |
| 3090 | continue; |
| 3091 | /* While going to suspend if associated with AP |
| 3092 | * disassociate from AP to save power while system is |
| 3093 | * in suspended state |
| 3094 | */ |
Arend van Spriel | 9b7a0dd | 2015-01-25 20:31:33 +0100 | [diff] [blame] | 3095 | brcmf_link_down(vif, WLAN_REASON_UNSPECIFIED); |
Hante Meuleman | 4eb3af7 | 2014-09-30 10:23:18 +0200 | [diff] [blame] | 3096 | /* Make sure WPA_Supplicant receives all the event |
| 3097 | * generated due to DISASSOC call to the fw to keep |
| 3098 | * the state fw and WPA_Supplicant state consistent |
| 3099 | */ |
| 3100 | brcmf_delay(500); |
| 3101 | } |
| 3102 | /* Configure MPC */ |
| 3103 | brcmf_set_mpc(ifp, 1); |
| 3104 | |
| 3105 | } else { |
| 3106 | /* Configure WOWL paramaters */ |
| 3107 | brcmf_configure_wowl(cfg, ifp, wowl); |
| 3108 | } |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3109 | |
Arend van Spriel | 7d64107 | 2012-10-22 13:55:39 -0700 | [diff] [blame] | 3110 | exit: |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 3111 | brcmf_dbg(TRACE, "Exit\n"); |
Arend van Spriel | 7d64107 | 2012-10-22 13:55:39 -0700 | [diff] [blame] | 3112 | /* clear any scanning activity */ |
| 3113 | cfg->scan_status = 0; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3114 | return 0; |
| 3115 | } |
| 3116 | |
| 3117 | static __used s32 |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3118 | brcmf_update_pmklist(struct net_device *ndev, |
| 3119 | struct brcmf_cfg80211_pmk_list *pmk_list, s32 err) |
| 3120 | { |
| 3121 | int i, j; |
Arend van Spriel | c15d789 | 2014-11-20 22:26:59 +0100 | [diff] [blame] | 3122 | u32 pmkid_len; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3123 | |
Arend van Spriel | 40c8e95 | 2011-10-12 20:51:20 +0200 | [diff] [blame] | 3124 | pmkid_len = le32_to_cpu(pmk_list->pmkids.npmkid); |
| 3125 | |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 3126 | brcmf_dbg(CONN, "No of elements %d\n", pmkid_len); |
Arend van Spriel | 40c8e95 | 2011-10-12 20:51:20 +0200 | [diff] [blame] | 3127 | for (i = 0; i < pmkid_len; i++) { |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 3128 | brcmf_dbg(CONN, "PMKID[%d]: %pM =\n", i, |
| 3129 | &pmk_list->pmkids.pmkid[i].BSSID); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3130 | for (j = 0; j < WLAN_PMKID_LEN; j++) |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 3131 | brcmf_dbg(CONN, "%02x\n", |
| 3132 | pmk_list->pmkids.pmkid[i].PMKID[j]); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3133 | } |
| 3134 | |
| 3135 | if (!err) |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 3136 | brcmf_fil_iovar_data_set(netdev_priv(ndev), "pmkid_info", |
| 3137 | (char *)pmk_list, sizeof(*pmk_list)); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3138 | |
| 3139 | return err; |
| 3140 | } |
| 3141 | |
| 3142 | static s32 |
| 3143 | brcmf_cfg80211_set_pmksa(struct wiphy *wiphy, struct net_device *ndev, |
| 3144 | struct cfg80211_pmksa *pmksa) |
| 3145 | { |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 3146 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); |
Arend van Spriel | 0abb5f21 | 2012-10-22 13:55:32 -0700 | [diff] [blame] | 3147 | struct brcmf_if *ifp = netdev_priv(ndev); |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 3148 | struct pmkid_list *pmkids = &cfg->pmk_list->pmkids; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3149 | s32 err = 0; |
Arend van Spriel | c15d789 | 2014-11-20 22:26:59 +0100 | [diff] [blame] | 3150 | u32 pmkid_len, i; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3151 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 3152 | brcmf_dbg(TRACE, "Enter\n"); |
Arend van Spriel | ce81e31 | 2012-10-22 13:55:37 -0700 | [diff] [blame] | 3153 | if (!check_vif_up(ifp->vif)) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3154 | return -EIO; |
| 3155 | |
Arend van Spriel | 40c8e95 | 2011-10-12 20:51:20 +0200 | [diff] [blame] | 3156 | pmkid_len = le32_to_cpu(pmkids->npmkid); |
| 3157 | for (i = 0; i < pmkid_len; i++) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3158 | if (!memcmp(pmksa->bssid, pmkids->pmkid[i].BSSID, ETH_ALEN)) |
| 3159 | break; |
| 3160 | if (i < WL_NUM_PMKIDS_MAX) { |
| 3161 | memcpy(pmkids->pmkid[i].BSSID, pmksa->bssid, ETH_ALEN); |
| 3162 | memcpy(pmkids->pmkid[i].PMKID, pmksa->pmkid, WLAN_PMKID_LEN); |
Arend van Spriel | 40c8e95 | 2011-10-12 20:51:20 +0200 | [diff] [blame] | 3163 | if (i == pmkid_len) { |
| 3164 | pmkid_len++; |
| 3165 | pmkids->npmkid = cpu_to_le32(pmkid_len); |
| 3166 | } |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3167 | } else |
| 3168 | err = -EINVAL; |
| 3169 | |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 3170 | brcmf_dbg(CONN, "set_pmksa,IW_PMKSA_ADD - PMKID: %pM =\n", |
| 3171 | pmkids->pmkid[pmkid_len].BSSID); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3172 | for (i = 0; i < WLAN_PMKID_LEN; i++) |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 3173 | brcmf_dbg(CONN, "%02x\n", pmkids->pmkid[pmkid_len].PMKID[i]); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3174 | |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 3175 | err = brcmf_update_pmklist(ndev, cfg->pmk_list, err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3176 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 3177 | brcmf_dbg(TRACE, "Exit\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3178 | return err; |
| 3179 | } |
| 3180 | |
| 3181 | static s32 |
| 3182 | brcmf_cfg80211_del_pmksa(struct wiphy *wiphy, struct net_device *ndev, |
| 3183 | struct cfg80211_pmksa *pmksa) |
| 3184 | { |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 3185 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); |
Arend van Spriel | 0abb5f21 | 2012-10-22 13:55:32 -0700 | [diff] [blame] | 3186 | struct brcmf_if *ifp = netdev_priv(ndev); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3187 | struct pmkid_list pmkid; |
| 3188 | s32 err = 0; |
Arend van Spriel | c15d789 | 2014-11-20 22:26:59 +0100 | [diff] [blame] | 3189 | u32 pmkid_len, i; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3190 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 3191 | brcmf_dbg(TRACE, "Enter\n"); |
Arend van Spriel | ce81e31 | 2012-10-22 13:55:37 -0700 | [diff] [blame] | 3192 | if (!check_vif_up(ifp->vif)) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3193 | return -EIO; |
| 3194 | |
| 3195 | memcpy(&pmkid.pmkid[0].BSSID, pmksa->bssid, ETH_ALEN); |
| 3196 | memcpy(&pmkid.pmkid[0].PMKID, pmksa->pmkid, WLAN_PMKID_LEN); |
| 3197 | |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 3198 | brcmf_dbg(CONN, "del_pmksa,IW_PMKSA_REMOVE - PMKID: %pM =\n", |
| 3199 | &pmkid.pmkid[0].BSSID); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3200 | for (i = 0; i < WLAN_PMKID_LEN; i++) |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 3201 | brcmf_dbg(CONN, "%02x\n", pmkid.pmkid[0].PMKID[i]); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3202 | |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 3203 | pmkid_len = le32_to_cpu(cfg->pmk_list->pmkids.npmkid); |
Arend van Spriel | 40c8e95 | 2011-10-12 20:51:20 +0200 | [diff] [blame] | 3204 | for (i = 0; i < pmkid_len; i++) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3205 | if (!memcmp |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 3206 | (pmksa->bssid, &cfg->pmk_list->pmkids.pmkid[i].BSSID, |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3207 | ETH_ALEN)) |
| 3208 | break; |
| 3209 | |
Arend van Spriel | 40c8e95 | 2011-10-12 20:51:20 +0200 | [diff] [blame] | 3210 | if ((pmkid_len > 0) |
| 3211 | && (i < pmkid_len)) { |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 3212 | memset(&cfg->pmk_list->pmkids.pmkid[i], 0, |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3213 | sizeof(struct pmkid)); |
Arend van Spriel | 40c8e95 | 2011-10-12 20:51:20 +0200 | [diff] [blame] | 3214 | for (; i < (pmkid_len - 1); i++) { |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 3215 | memcpy(&cfg->pmk_list->pmkids.pmkid[i].BSSID, |
| 3216 | &cfg->pmk_list->pmkids.pmkid[i + 1].BSSID, |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3217 | ETH_ALEN); |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 3218 | memcpy(&cfg->pmk_list->pmkids.pmkid[i].PMKID, |
| 3219 | &cfg->pmk_list->pmkids.pmkid[i + 1].PMKID, |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3220 | WLAN_PMKID_LEN); |
| 3221 | } |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 3222 | cfg->pmk_list->pmkids.npmkid = cpu_to_le32(pmkid_len - 1); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3223 | } else |
| 3224 | err = -EINVAL; |
| 3225 | |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 3226 | err = brcmf_update_pmklist(ndev, cfg->pmk_list, err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3227 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 3228 | brcmf_dbg(TRACE, "Exit\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3229 | return err; |
| 3230 | |
| 3231 | } |
| 3232 | |
| 3233 | static s32 |
| 3234 | brcmf_cfg80211_flush_pmksa(struct wiphy *wiphy, struct net_device *ndev) |
| 3235 | { |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 3236 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); |
Arend van Spriel | 0abb5f21 | 2012-10-22 13:55:32 -0700 | [diff] [blame] | 3237 | struct brcmf_if *ifp = netdev_priv(ndev); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3238 | s32 err = 0; |
| 3239 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 3240 | brcmf_dbg(TRACE, "Enter\n"); |
Arend van Spriel | ce81e31 | 2012-10-22 13:55:37 -0700 | [diff] [blame] | 3241 | if (!check_vif_up(ifp->vif)) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3242 | return -EIO; |
| 3243 | |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 3244 | memset(cfg->pmk_list, 0, sizeof(*cfg->pmk_list)); |
| 3245 | err = brcmf_update_pmklist(ndev, cfg->pmk_list, err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3246 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 3247 | brcmf_dbg(TRACE, "Exit\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 3248 | return err; |
| 3249 | |
| 3250 | } |
| 3251 | |
Arend van Spriel | e580607 | 2012-09-19 22:21:08 +0200 | [diff] [blame] | 3252 | /* |
| 3253 | * PFN result doesn't have all the info which are |
| 3254 | * required by the supplicant |
| 3255 | * (For e.g IEs) Do a target Escan so that sched scan results are reported |
| 3256 | * via wl_inform_single_bss in the required format. Escan does require the |
| 3257 | * scan request in the form of cfg80211_scan_request. For timebeing, create |
| 3258 | * cfg80211_scan_request one out of the received PNO event. |
| 3259 | */ |
| 3260 | static s32 |
Arend van Spriel | 1993732 | 2012-11-05 16:22:32 -0800 | [diff] [blame] | 3261 | brcmf_notify_sched_scan_results(struct brcmf_if *ifp, |
Arend van Spriel | e580607 | 2012-09-19 22:21:08 +0200 | [diff] [blame] | 3262 | const struct brcmf_event_msg *e, void *data) |
| 3263 | { |
Arend van Spriel | 1993732 | 2012-11-05 16:22:32 -0800 | [diff] [blame] | 3264 | struct brcmf_cfg80211_info *cfg = ifp->drvr->config; |
Arend van Spriel | e580607 | 2012-09-19 22:21:08 +0200 | [diff] [blame] | 3265 | struct brcmf_pno_net_info_le *netinfo, *netinfo_start; |
| 3266 | struct cfg80211_scan_request *request = NULL; |
| 3267 | struct cfg80211_ssid *ssid = NULL; |
| 3268 | struct ieee80211_channel *channel = NULL; |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 3269 | struct wiphy *wiphy = cfg_to_wiphy(cfg); |
Arend van Spriel | e580607 | 2012-09-19 22:21:08 +0200 | [diff] [blame] | 3270 | int err = 0; |
| 3271 | int channel_req = 0; |
| 3272 | int band = 0; |
| 3273 | struct brcmf_pno_scanresults_le *pfn_result; |
| 3274 | u32 result_count; |
| 3275 | u32 status; |
| 3276 | |
Arend van Spriel | 4e8a008 | 2012-12-05 15:26:03 +0100 | [diff] [blame] | 3277 | brcmf_dbg(SCAN, "Enter\n"); |
Arend van Spriel | e580607 | 2012-09-19 22:21:08 +0200 | [diff] [blame] | 3278 | |
Arend van Spriel | 5c36b99 | 2012-11-14 18:46:05 -0800 | [diff] [blame] | 3279 | if (e->event_code == BRCMF_E_PFN_NET_LOST) { |
Arend van Spriel | 4e8a008 | 2012-12-05 15:26:03 +0100 | [diff] [blame] | 3280 | brcmf_dbg(SCAN, "PFN NET LOST event. Do Nothing\n"); |
Arend van Spriel | e580607 | 2012-09-19 22:21:08 +0200 | [diff] [blame] | 3281 | return 0; |
| 3282 | } |
| 3283 | |
| 3284 | pfn_result = (struct brcmf_pno_scanresults_le *)data; |
| 3285 | result_count = le32_to_cpu(pfn_result->count); |
| 3286 | status = le32_to_cpu(pfn_result->status); |
| 3287 | |
| 3288 | /* |
| 3289 | * PFN event is limited to fit 512 bytes so we may get |
| 3290 | * multiple NET_FOUND events. For now place a warning here. |
| 3291 | */ |
| 3292 | WARN_ON(status != BRCMF_PNO_SCAN_COMPLETE); |
Arend van Spriel | 4e8a008 | 2012-12-05 15:26:03 +0100 | [diff] [blame] | 3293 | 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] | 3294 | if (result_count > 0) { |
| 3295 | int i; |
| 3296 | |
| 3297 | request = kzalloc(sizeof(*request), GFP_KERNEL); |
Dan Carpenter | 58901d1 | 2012-09-26 10:21:48 +0300 | [diff] [blame] | 3298 | ssid = kcalloc(result_count, sizeof(*ssid), GFP_KERNEL); |
| 3299 | channel = kcalloc(result_count, sizeof(*channel), GFP_KERNEL); |
Arend van Spriel | e580607 | 2012-09-19 22:21:08 +0200 | [diff] [blame] | 3300 | if (!request || !ssid || !channel) { |
| 3301 | err = -ENOMEM; |
| 3302 | goto out_err; |
| 3303 | } |
| 3304 | |
| 3305 | request->wiphy = wiphy; |
| 3306 | data += sizeof(struct brcmf_pno_scanresults_le); |
| 3307 | netinfo_start = (struct brcmf_pno_net_info_le *)data; |
| 3308 | |
| 3309 | for (i = 0; i < result_count; i++) { |
| 3310 | netinfo = &netinfo_start[i]; |
| 3311 | if (!netinfo) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 3312 | brcmf_err("Invalid netinfo ptr. index: %d\n", |
| 3313 | i); |
Arend van Spriel | e580607 | 2012-09-19 22:21:08 +0200 | [diff] [blame] | 3314 | err = -EINVAL; |
| 3315 | goto out_err; |
| 3316 | } |
| 3317 | |
Arend van Spriel | 4e8a008 | 2012-12-05 15:26:03 +0100 | [diff] [blame] | 3318 | brcmf_dbg(SCAN, "SSID:%s Channel:%d\n", |
| 3319 | netinfo->SSID, netinfo->channel); |
Arend van Spriel | e580607 | 2012-09-19 22:21:08 +0200 | [diff] [blame] | 3320 | memcpy(ssid[i].ssid, netinfo->SSID, netinfo->SSID_len); |
| 3321 | ssid[i].ssid_len = netinfo->SSID_len; |
| 3322 | request->n_ssids++; |
| 3323 | |
| 3324 | channel_req = netinfo->channel; |
| 3325 | if (channel_req <= CH_MAX_2G_CHANNEL) |
| 3326 | band = NL80211_BAND_2GHZ; |
| 3327 | else |
| 3328 | band = NL80211_BAND_5GHZ; |
| 3329 | channel[i].center_freq = |
| 3330 | ieee80211_channel_to_frequency(channel_req, |
| 3331 | band); |
| 3332 | channel[i].band = band; |
| 3333 | channel[i].flags |= IEEE80211_CHAN_NO_HT40; |
| 3334 | request->channels[i] = &channel[i]; |
| 3335 | request->n_channels++; |
| 3336 | } |
| 3337 | |
| 3338 | /* assign parsed ssid array */ |
| 3339 | if (request->n_ssids) |
| 3340 | request->ssids = &ssid[0]; |
| 3341 | |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 3342 | if (test_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status)) { |
Arend van Spriel | e580607 | 2012-09-19 22:21:08 +0200 | [diff] [blame] | 3343 | /* Abort any on-going scan */ |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 3344 | brcmf_abort_scanning(cfg); |
Arend van Spriel | e580607 | 2012-09-19 22:21:08 +0200 | [diff] [blame] | 3345 | } |
| 3346 | |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 3347 | set_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status); |
Arend van Spriel | 2668b0b | 2014-01-13 22:20:28 +0100 | [diff] [blame] | 3348 | cfg->escan_info.run = brcmf_run_escan; |
Arend van Spriel | a0f472a | 2013-04-05 10:57:49 +0200 | [diff] [blame] | 3349 | err = brcmf_do_escan(cfg, wiphy, ifp, request); |
Arend van Spriel | e580607 | 2012-09-19 22:21:08 +0200 | [diff] [blame] | 3350 | if (err) { |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 3351 | clear_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status); |
Arend van Spriel | e580607 | 2012-09-19 22:21:08 +0200 | [diff] [blame] | 3352 | goto out_err; |
| 3353 | } |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 3354 | cfg->sched_escan = true; |
| 3355 | cfg->scan_request = request; |
Arend van Spriel | e580607 | 2012-09-19 22:21:08 +0200 | [diff] [blame] | 3356 | } else { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 3357 | brcmf_err("FALSE PNO Event. (pfn_count == 0)\n"); |
Arend van Spriel | e580607 | 2012-09-19 22:21:08 +0200 | [diff] [blame] | 3358 | goto out_err; |
| 3359 | } |
| 3360 | |
| 3361 | kfree(ssid); |
| 3362 | kfree(channel); |
| 3363 | kfree(request); |
| 3364 | return 0; |
| 3365 | |
| 3366 | out_err: |
| 3367 | kfree(ssid); |
| 3368 | kfree(channel); |
| 3369 | kfree(request); |
| 3370 | cfg80211_sched_scan_stopped(wiphy); |
| 3371 | return err; |
| 3372 | } |
| 3373 | |
Arend van Spriel | e580607 | 2012-09-19 22:21:08 +0200 | [diff] [blame] | 3374 | static int brcmf_dev_pno_clean(struct net_device *ndev) |
| 3375 | { |
Arend van Spriel | e580607 | 2012-09-19 22:21:08 +0200 | [diff] [blame] | 3376 | int ret; |
| 3377 | |
| 3378 | /* Disable pfn */ |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 3379 | ret = brcmf_fil_iovar_int_set(netdev_priv(ndev), "pfn", 0); |
Arend van Spriel | e580607 | 2012-09-19 22:21:08 +0200 | [diff] [blame] | 3380 | if (ret == 0) { |
| 3381 | /* clear pfn */ |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 3382 | ret = brcmf_fil_iovar_data_set(netdev_priv(ndev), "pfnclear", |
| 3383 | NULL, 0); |
Arend van Spriel | e580607 | 2012-09-19 22:21:08 +0200 | [diff] [blame] | 3384 | } |
| 3385 | if (ret < 0) |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 3386 | brcmf_err("failed code %d\n", ret); |
Arend van Spriel | e580607 | 2012-09-19 22:21:08 +0200 | [diff] [blame] | 3387 | |
| 3388 | return ret; |
| 3389 | } |
| 3390 | |
| 3391 | static int brcmf_dev_pno_config(struct net_device *ndev) |
| 3392 | { |
| 3393 | struct brcmf_pno_param_le pfn_param; |
Arend van Spriel | e580607 | 2012-09-19 22:21:08 +0200 | [diff] [blame] | 3394 | |
| 3395 | memset(&pfn_param, 0, sizeof(pfn_param)); |
| 3396 | pfn_param.version = cpu_to_le32(BRCMF_PNO_VERSION); |
| 3397 | |
| 3398 | /* set extra pno params */ |
| 3399 | pfn_param.flags = cpu_to_le16(1 << BRCMF_PNO_ENABLE_ADAPTSCAN_BIT); |
| 3400 | pfn_param.repeat = BRCMF_PNO_REPEAT; |
| 3401 | pfn_param.exp = BRCMF_PNO_FREQ_EXPO_MAX; |
| 3402 | |
| 3403 | /* set up pno scan fr */ |
| 3404 | pfn_param.scan_freq = cpu_to_le32(BRCMF_PNO_TIME); |
| 3405 | |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 3406 | return brcmf_fil_iovar_data_set(netdev_priv(ndev), "pfn_set", |
| 3407 | &pfn_param, sizeof(pfn_param)); |
Arend van Spriel | e580607 | 2012-09-19 22:21:08 +0200 | [diff] [blame] | 3408 | } |
| 3409 | |
| 3410 | static int |
| 3411 | brcmf_cfg80211_sched_scan_start(struct wiphy *wiphy, |
| 3412 | struct net_device *ndev, |
| 3413 | struct cfg80211_sched_scan_request *request) |
| 3414 | { |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 3415 | struct brcmf_if *ifp = netdev_priv(ndev); |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 3416 | struct brcmf_cfg80211_info *cfg = wiphy_priv(wiphy); |
Arend van Spriel | e580607 | 2012-09-19 22:21:08 +0200 | [diff] [blame] | 3417 | struct brcmf_pno_net_param_le pfn; |
| 3418 | int i; |
| 3419 | int ret = 0; |
| 3420 | |
Arend van Spriel | dc7bdbf | 2013-03-03 12:45:25 +0100 | [diff] [blame] | 3421 | 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] | 3422 | request->n_match_sets, request->n_ssids); |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 3423 | if (test_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status)) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 3424 | brcmf_err("Scanning already: status (%lu)\n", cfg->scan_status); |
Arend van Spriel | e580607 | 2012-09-19 22:21:08 +0200 | [diff] [blame] | 3425 | return -EAGAIN; |
| 3426 | } |
Arend van Spriel | 1687eee | 2013-04-23 12:53:11 +0200 | [diff] [blame] | 3427 | if (test_bit(BRCMF_SCAN_STATUS_SUPPRESS, &cfg->scan_status)) { |
| 3428 | brcmf_err("Scanning suppressed: status (%lu)\n", |
| 3429 | cfg->scan_status); |
| 3430 | return -EAGAIN; |
| 3431 | } |
Arend van Spriel | e580607 | 2012-09-19 22:21:08 +0200 | [diff] [blame] | 3432 | |
Arend van Spriel | dc7bdbf | 2013-03-03 12:45:25 +0100 | [diff] [blame] | 3433 | if (!request->n_ssids || !request->n_match_sets) { |
Arend van Spriel | 181f2d1 | 2014-05-27 12:56:13 +0200 | [diff] [blame] | 3434 | brcmf_dbg(SCAN, "Invalid sched scan req!! n_ssids:%d\n", |
Arend van Spriel | dc7bdbf | 2013-03-03 12:45:25 +0100 | [diff] [blame] | 3435 | request->n_ssids); |
Arend van Spriel | e580607 | 2012-09-19 22:21:08 +0200 | [diff] [blame] | 3436 | return -EINVAL; |
| 3437 | } |
| 3438 | |
| 3439 | if (request->n_ssids > 0) { |
| 3440 | for (i = 0; i < request->n_ssids; i++) { |
| 3441 | /* Active scan req for ssids */ |
Arend van Spriel | 4e8a008 | 2012-12-05 15:26:03 +0100 | [diff] [blame] | 3442 | brcmf_dbg(SCAN, ">>> Active scan req for ssid (%s)\n", |
| 3443 | request->ssids[i].ssid); |
Arend van Spriel | e580607 | 2012-09-19 22:21:08 +0200 | [diff] [blame] | 3444 | |
| 3445 | /* |
| 3446 | * match_set ssids is a supert set of n_ssid list, |
| 3447 | * so we need not add these set seperately. |
| 3448 | */ |
| 3449 | } |
| 3450 | } |
| 3451 | |
| 3452 | if (request->n_match_sets > 0) { |
| 3453 | /* clean up everything */ |
| 3454 | ret = brcmf_dev_pno_clean(ndev); |
| 3455 | if (ret < 0) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 3456 | brcmf_err("failed error=%d\n", ret); |
Arend van Spriel | e580607 | 2012-09-19 22:21:08 +0200 | [diff] [blame] | 3457 | return ret; |
| 3458 | } |
| 3459 | |
| 3460 | /* configure pno */ |
| 3461 | ret = brcmf_dev_pno_config(ndev); |
| 3462 | if (ret < 0) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 3463 | brcmf_err("PNO setup failed!! ret=%d\n", ret); |
Arend van Spriel | e580607 | 2012-09-19 22:21:08 +0200 | [diff] [blame] | 3464 | return -EINVAL; |
| 3465 | } |
| 3466 | |
| 3467 | /* configure each match set */ |
| 3468 | for (i = 0; i < request->n_match_sets; i++) { |
| 3469 | struct cfg80211_ssid *ssid; |
| 3470 | u32 ssid_len; |
| 3471 | |
| 3472 | ssid = &request->match_sets[i].ssid; |
| 3473 | ssid_len = ssid->ssid_len; |
| 3474 | |
| 3475 | if (!ssid_len) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 3476 | brcmf_err("skip broadcast ssid\n"); |
Arend van Spriel | e580607 | 2012-09-19 22:21:08 +0200 | [diff] [blame] | 3477 | continue; |
| 3478 | } |
| 3479 | pfn.auth = cpu_to_le32(WLAN_AUTH_OPEN); |
| 3480 | pfn.wpa_auth = cpu_to_le32(BRCMF_PNO_WPA_AUTH_ANY); |
| 3481 | pfn.wsec = cpu_to_le32(0); |
| 3482 | pfn.infra = cpu_to_le32(1); |
| 3483 | pfn.flags = cpu_to_le32(1 << BRCMF_PNO_HIDDEN_BIT); |
| 3484 | pfn.ssid.SSID_len = cpu_to_le32(ssid_len); |
| 3485 | memcpy(pfn.ssid.SSID, ssid->ssid, ssid_len); |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 3486 | ret = brcmf_fil_iovar_data_set(ifp, "pfn_add", &pfn, |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 3487 | sizeof(pfn)); |
Arend van Spriel | 4e8a008 | 2012-12-05 15:26:03 +0100 | [diff] [blame] | 3488 | brcmf_dbg(SCAN, ">>> PNO filter %s for ssid (%s)\n", |
| 3489 | ret == 0 ? "set" : "failed", ssid->ssid); |
Arend van Spriel | e580607 | 2012-09-19 22:21:08 +0200 | [diff] [blame] | 3490 | } |
| 3491 | /* Enable the PNO */ |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 3492 | if (brcmf_fil_iovar_int_set(ifp, "pfn", 1) < 0) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 3493 | brcmf_err("PNO enable failed!! ret=%d\n", ret); |
Arend van Spriel | e580607 | 2012-09-19 22:21:08 +0200 | [diff] [blame] | 3494 | return -EINVAL; |
| 3495 | } |
| 3496 | } else { |
| 3497 | return -EINVAL; |
| 3498 | } |
| 3499 | |
| 3500 | return 0; |
| 3501 | } |
| 3502 | |
| 3503 | static int brcmf_cfg80211_sched_scan_stop(struct wiphy *wiphy, |
| 3504 | struct net_device *ndev) |
| 3505 | { |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 3506 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); |
Arend van Spriel | e580607 | 2012-09-19 22:21:08 +0200 | [diff] [blame] | 3507 | |
Arend van Spriel | 4e8a008 | 2012-12-05 15:26:03 +0100 | [diff] [blame] | 3508 | brcmf_dbg(SCAN, "enter\n"); |
Arend van Spriel | e580607 | 2012-09-19 22:21:08 +0200 | [diff] [blame] | 3509 | brcmf_dev_pno_clean(ndev); |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 3510 | if (cfg->sched_escan) |
Arend van Spriel | a0f472a | 2013-04-05 10:57:49 +0200 | [diff] [blame] | 3511 | brcmf_notify_escan_complete(cfg, netdev_priv(ndev), true, true); |
Arend van Spriel | e580607 | 2012-09-19 22:21:08 +0200 | [diff] [blame] | 3512 | return 0; |
| 3513 | } |
Arend van Spriel | e580607 | 2012-09-19 22:21:08 +0200 | [diff] [blame] | 3514 | |
Hante Meuleman | 1f17011 | 2013-02-06 18:40:38 +0100 | [diff] [blame] | 3515 | static s32 brcmf_configure_opensecurity(struct brcmf_if *ifp) |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3516 | { |
| 3517 | s32 err; |
| 3518 | |
| 3519 | /* set auth */ |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 3520 | err = brcmf_fil_bsscfg_int_set(ifp, "auth", 0); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3521 | if (err < 0) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 3522 | brcmf_err("auth error %d\n", err); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3523 | return err; |
| 3524 | } |
| 3525 | /* set wsec */ |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 3526 | err = brcmf_fil_bsscfg_int_set(ifp, "wsec", 0); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3527 | if (err < 0) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 3528 | brcmf_err("wsec error %d\n", err); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3529 | return err; |
| 3530 | } |
| 3531 | /* set upper-layer auth */ |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 3532 | err = brcmf_fil_bsscfg_int_set(ifp, "wpa_auth", WPA_AUTH_NONE); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3533 | if (err < 0) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 3534 | brcmf_err("wpa_auth error %d\n", err); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3535 | return err; |
| 3536 | } |
| 3537 | |
| 3538 | return 0; |
| 3539 | } |
| 3540 | |
| 3541 | static bool brcmf_valid_wpa_oui(u8 *oui, bool is_rsn_ie) |
| 3542 | { |
| 3543 | if (is_rsn_ie) |
| 3544 | return (memcmp(oui, RSN_OUI, TLV_OUI_LEN) == 0); |
| 3545 | |
| 3546 | return (memcmp(oui, WPA_OUI, TLV_OUI_LEN) == 0); |
| 3547 | } |
| 3548 | |
| 3549 | static s32 |
Hante Meuleman | a44aa40 | 2014-12-03 21:05:33 +0100 | [diff] [blame] | 3550 | brcmf_configure_wpaie(struct brcmf_if *ifp, |
Johannes Berg | 4b5800f | 2014-01-15 14:55:59 +0100 | [diff] [blame] | 3551 | const struct brcmf_vs_tlv *wpa_ie, |
| 3552 | bool is_rsn_ie) |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3553 | { |
| 3554 | u32 auth = 0; /* d11 open authentication */ |
| 3555 | u16 count; |
| 3556 | s32 err = 0; |
| 3557 | s32 len = 0; |
| 3558 | u32 i; |
| 3559 | u32 wsec; |
| 3560 | u32 pval = 0; |
| 3561 | u32 gval = 0; |
| 3562 | u32 wpa_auth = 0; |
| 3563 | u32 offset; |
| 3564 | u8 *data; |
| 3565 | u16 rsn_cap; |
| 3566 | u32 wme_bss_disable; |
| 3567 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 3568 | brcmf_dbg(TRACE, "Enter\n"); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3569 | if (wpa_ie == NULL) |
| 3570 | goto exit; |
| 3571 | |
| 3572 | len = wpa_ie->len + TLV_HDR_LEN; |
| 3573 | data = (u8 *)wpa_ie; |
Hante Meuleman | 619c5a9 | 2013-01-02 15:12:39 +0100 | [diff] [blame] | 3574 | offset = TLV_HDR_LEN; |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3575 | if (!is_rsn_ie) |
| 3576 | offset += VS_IE_FIXED_HDR_LEN; |
Hante Meuleman | 619c5a9 | 2013-01-02 15:12:39 +0100 | [diff] [blame] | 3577 | else |
| 3578 | offset += WPA_IE_VERSION_LEN; |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3579 | |
| 3580 | /* check for multicast cipher suite */ |
| 3581 | if (offset + WPA_IE_MIN_OUI_LEN > len) { |
| 3582 | err = -EINVAL; |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 3583 | brcmf_err("no multicast cipher suite\n"); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3584 | goto exit; |
| 3585 | } |
| 3586 | |
| 3587 | if (!brcmf_valid_wpa_oui(&data[offset], is_rsn_ie)) { |
| 3588 | err = -EINVAL; |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 3589 | brcmf_err("ivalid OUI\n"); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3590 | goto exit; |
| 3591 | } |
| 3592 | offset += TLV_OUI_LEN; |
| 3593 | |
| 3594 | /* pick up multicast cipher */ |
| 3595 | switch (data[offset]) { |
| 3596 | case WPA_CIPHER_NONE: |
| 3597 | gval = 0; |
| 3598 | break; |
| 3599 | case WPA_CIPHER_WEP_40: |
| 3600 | case WPA_CIPHER_WEP_104: |
| 3601 | gval = WEP_ENABLED; |
| 3602 | break; |
| 3603 | case WPA_CIPHER_TKIP: |
| 3604 | gval = TKIP_ENABLED; |
| 3605 | break; |
| 3606 | case WPA_CIPHER_AES_CCM: |
| 3607 | gval = AES_ENABLED; |
| 3608 | break; |
| 3609 | default: |
| 3610 | err = -EINVAL; |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 3611 | brcmf_err("Invalid multi cast cipher info\n"); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3612 | goto exit; |
| 3613 | } |
| 3614 | |
| 3615 | offset++; |
| 3616 | /* walk thru unicast cipher list and pick up what we recognize */ |
| 3617 | count = data[offset] + (data[offset + 1] << 8); |
| 3618 | offset += WPA_IE_SUITE_COUNT_LEN; |
| 3619 | /* Check for unicast suite(s) */ |
| 3620 | if (offset + (WPA_IE_MIN_OUI_LEN * count) > len) { |
| 3621 | err = -EINVAL; |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 3622 | brcmf_err("no unicast cipher suite\n"); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3623 | goto exit; |
| 3624 | } |
| 3625 | for (i = 0; i < count; i++) { |
| 3626 | if (!brcmf_valid_wpa_oui(&data[offset], is_rsn_ie)) { |
| 3627 | err = -EINVAL; |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 3628 | brcmf_err("ivalid OUI\n"); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3629 | goto exit; |
| 3630 | } |
| 3631 | offset += TLV_OUI_LEN; |
| 3632 | switch (data[offset]) { |
| 3633 | case WPA_CIPHER_NONE: |
| 3634 | break; |
| 3635 | case WPA_CIPHER_WEP_40: |
| 3636 | case WPA_CIPHER_WEP_104: |
| 3637 | pval |= WEP_ENABLED; |
| 3638 | break; |
| 3639 | case WPA_CIPHER_TKIP: |
| 3640 | pval |= TKIP_ENABLED; |
| 3641 | break; |
| 3642 | case WPA_CIPHER_AES_CCM: |
| 3643 | pval |= AES_ENABLED; |
| 3644 | break; |
| 3645 | default: |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 3646 | brcmf_err("Ivalid unicast security info\n"); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3647 | } |
| 3648 | offset++; |
| 3649 | } |
| 3650 | /* walk thru auth management suite list and pick up what we recognize */ |
| 3651 | count = data[offset] + (data[offset + 1] << 8); |
| 3652 | offset += WPA_IE_SUITE_COUNT_LEN; |
| 3653 | /* Check for auth key management suite(s) */ |
| 3654 | if (offset + (WPA_IE_MIN_OUI_LEN * count) > len) { |
| 3655 | err = -EINVAL; |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 3656 | brcmf_err("no auth key mgmt suite\n"); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3657 | goto exit; |
| 3658 | } |
| 3659 | for (i = 0; i < count; i++) { |
| 3660 | if (!brcmf_valid_wpa_oui(&data[offset], is_rsn_ie)) { |
| 3661 | err = -EINVAL; |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 3662 | brcmf_err("ivalid OUI\n"); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3663 | goto exit; |
| 3664 | } |
| 3665 | offset += TLV_OUI_LEN; |
| 3666 | switch (data[offset]) { |
| 3667 | case RSN_AKM_NONE: |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 3668 | brcmf_dbg(TRACE, "RSN_AKM_NONE\n"); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3669 | wpa_auth |= WPA_AUTH_NONE; |
| 3670 | break; |
| 3671 | case RSN_AKM_UNSPECIFIED: |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 3672 | brcmf_dbg(TRACE, "RSN_AKM_UNSPECIFIED\n"); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3673 | is_rsn_ie ? (wpa_auth |= WPA2_AUTH_UNSPECIFIED) : |
| 3674 | (wpa_auth |= WPA_AUTH_UNSPECIFIED); |
| 3675 | break; |
| 3676 | case RSN_AKM_PSK: |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 3677 | brcmf_dbg(TRACE, "RSN_AKM_PSK\n"); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3678 | is_rsn_ie ? (wpa_auth |= WPA2_AUTH_PSK) : |
| 3679 | (wpa_auth |= WPA_AUTH_PSK); |
| 3680 | break; |
| 3681 | default: |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 3682 | brcmf_err("Ivalid key mgmt info\n"); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3683 | } |
| 3684 | offset++; |
| 3685 | } |
| 3686 | |
| 3687 | if (is_rsn_ie) { |
| 3688 | wme_bss_disable = 1; |
| 3689 | if ((offset + RSN_CAP_LEN) <= len) { |
| 3690 | rsn_cap = data[offset] + (data[offset + 1] << 8); |
| 3691 | if (rsn_cap & RSN_CAP_PTK_REPLAY_CNTR_MASK) |
| 3692 | wme_bss_disable = 0; |
| 3693 | } |
| 3694 | /* set wme_bss_disable to sync RSN Capabilities */ |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 3695 | err = brcmf_fil_bsscfg_int_set(ifp, "wme_bss_disable", |
Hante Meuleman | 81f5dcb | 2012-10-22 10:36:14 -0700 | [diff] [blame] | 3696 | wme_bss_disable); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3697 | if (err < 0) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 3698 | brcmf_err("wme_bss_disable error %d\n", err); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3699 | goto exit; |
| 3700 | } |
| 3701 | } |
| 3702 | /* FOR WPS , set SES_OW_ENABLED */ |
| 3703 | wsec = (pval | gval | SES_OW_ENABLED); |
| 3704 | |
| 3705 | /* set auth */ |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 3706 | err = brcmf_fil_bsscfg_int_set(ifp, "auth", auth); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3707 | if (err < 0) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 3708 | brcmf_err("auth error %d\n", err); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3709 | goto exit; |
| 3710 | } |
| 3711 | /* set wsec */ |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 3712 | err = brcmf_fil_bsscfg_int_set(ifp, "wsec", wsec); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3713 | if (err < 0) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 3714 | brcmf_err("wsec error %d\n", err); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3715 | goto exit; |
| 3716 | } |
| 3717 | /* set upper-layer auth */ |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 3718 | err = brcmf_fil_bsscfg_int_set(ifp, "wpa_auth", wpa_auth); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3719 | if (err < 0) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 3720 | brcmf_err("wpa_auth error %d\n", err); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3721 | goto exit; |
| 3722 | } |
| 3723 | |
| 3724 | exit: |
| 3725 | return err; |
| 3726 | } |
| 3727 | |
| 3728 | static s32 |
Arend van Spriel | 3082b9b | 2012-11-05 16:22:12 -0800 | [diff] [blame] | 3729 | 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] | 3730 | struct parsed_vndr_ies *vndr_ies) |
| 3731 | { |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3732 | struct brcmf_vs_tlv *vndrie; |
| 3733 | struct brcmf_tlv *ie; |
| 3734 | struct parsed_vndr_ie_info *parsed_info; |
| 3735 | s32 remaining_len; |
| 3736 | |
| 3737 | remaining_len = (s32)vndr_ie_len; |
| 3738 | memset(vndr_ies, 0, sizeof(*vndr_ies)); |
| 3739 | |
| 3740 | ie = (struct brcmf_tlv *)vndr_ie_buf; |
| 3741 | while (ie) { |
| 3742 | if (ie->id != WLAN_EID_VENDOR_SPECIFIC) |
| 3743 | goto next; |
| 3744 | vndrie = (struct brcmf_vs_tlv *)ie; |
| 3745 | /* len should be bigger than OUI length + one */ |
| 3746 | 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] | 3747 | brcmf_err("invalid vndr ie. length is too small %d\n", |
| 3748 | vndrie->len); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3749 | goto next; |
| 3750 | } |
| 3751 | /* if wpa or wme ie, do not add ie */ |
| 3752 | if (!memcmp(vndrie->oui, (u8 *)WPA_OUI, TLV_OUI_LEN) && |
| 3753 | ((vndrie->oui_type == WPA_OUI_TYPE) || |
| 3754 | (vndrie->oui_type == WME_OUI_TYPE))) { |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 3755 | brcmf_dbg(TRACE, "Found WPA/WME oui. Do not add it\n"); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3756 | goto next; |
| 3757 | } |
| 3758 | |
| 3759 | parsed_info = &vndr_ies->ie_info[vndr_ies->count]; |
| 3760 | |
| 3761 | /* save vndr ie information */ |
| 3762 | parsed_info->ie_ptr = (char *)vndrie; |
| 3763 | parsed_info->ie_len = vndrie->len + TLV_HDR_LEN; |
| 3764 | memcpy(&parsed_info->vndrie, vndrie, sizeof(*vndrie)); |
| 3765 | |
| 3766 | vndr_ies->count++; |
| 3767 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 3768 | brcmf_dbg(TRACE, "** OUI %02x %02x %02x, type 0x%02x\n", |
| 3769 | parsed_info->vndrie.oui[0], |
| 3770 | parsed_info->vndrie.oui[1], |
| 3771 | parsed_info->vndrie.oui[2], |
| 3772 | parsed_info->vndrie.oui_type); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3773 | |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 3774 | if (vndr_ies->count >= VNDR_IE_PARSE_LIMIT) |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3775 | break; |
| 3776 | next: |
Hante Meuleman | b41fc3d | 2012-11-28 21:44:13 +0100 | [diff] [blame] | 3777 | remaining_len -= (ie->len + TLV_HDR_LEN); |
| 3778 | if (remaining_len <= TLV_HDR_LEN) |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3779 | ie = NULL; |
| 3780 | else |
Hante Meuleman | b41fc3d | 2012-11-28 21:44:13 +0100 | [diff] [blame] | 3781 | ie = (struct brcmf_tlv *)(((u8 *)ie) + ie->len + |
| 3782 | TLV_HDR_LEN); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3783 | } |
Peter Senna Tschudin | 12f3237 | 2014-05-31 10:14:06 -0300 | [diff] [blame] | 3784 | return 0; |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3785 | } |
| 3786 | |
| 3787 | static u32 |
| 3788 | brcmf_vndr_ie(u8 *iebuf, s32 pktflag, u8 *ie_ptr, u32 ie_len, s8 *add_del_cmd) |
| 3789 | { |
| 3790 | |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3791 | strncpy(iebuf, add_del_cmd, VNDR_IE_CMD_LEN - 1); |
| 3792 | iebuf[VNDR_IE_CMD_LEN - 1] = '\0'; |
| 3793 | |
Vaishali Thakkar | 362126c | 2015-01-16 21:36:14 +0530 | [diff] [blame] | 3794 | put_unaligned_le32(1, &iebuf[VNDR_IE_COUNT_OFFSET]); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3795 | |
Vaishali Thakkar | 362126c | 2015-01-16 21:36:14 +0530 | [diff] [blame] | 3796 | put_unaligned_le32(pktflag, &iebuf[VNDR_IE_PKTFLAG_OFFSET]); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3797 | |
| 3798 | memcpy(&iebuf[VNDR_IE_VSIE_OFFSET], ie_ptr, ie_len); |
| 3799 | |
| 3800 | return ie_len + VNDR_IE_HDR_SIZE; |
| 3801 | } |
| 3802 | |
Arend van Spriel | 1332e26 | 2012-11-05 16:22:18 -0800 | [diff] [blame] | 3803 | s32 brcmf_vif_set_mgmt_ie(struct brcmf_cfg80211_vif *vif, s32 pktflag, |
| 3804 | const u8 *vndr_ie_buf, u32 vndr_ie_len) |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3805 | { |
Arend van Spriel | 1332e26 | 2012-11-05 16:22:18 -0800 | [diff] [blame] | 3806 | struct brcmf_if *ifp; |
| 3807 | struct vif_saved_ie *saved_ie; |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3808 | s32 err = 0; |
| 3809 | u8 *iovar_ie_buf; |
| 3810 | u8 *curr_ie_buf; |
| 3811 | u8 *mgmt_ie_buf = NULL; |
Dan Carpenter | 3e4f319 | 2012-10-10 11:13:12 -0700 | [diff] [blame] | 3812 | int mgmt_ie_buf_len; |
Dan Carpenter | 81118d1 | 2012-10-10 11:13:07 -0700 | [diff] [blame] | 3813 | u32 *mgmt_ie_len; |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3814 | u32 del_add_ie_buf_len = 0; |
| 3815 | u32 total_ie_buf_len = 0; |
| 3816 | u32 parsed_ie_buf_len = 0; |
| 3817 | struct parsed_vndr_ies old_vndr_ies; |
| 3818 | struct parsed_vndr_ies new_vndr_ies; |
| 3819 | struct parsed_vndr_ie_info *vndrie_info; |
| 3820 | s32 i; |
| 3821 | u8 *ptr; |
Dan Carpenter | 3e4f319 | 2012-10-10 11:13:12 -0700 | [diff] [blame] | 3822 | int remained_buf_len; |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3823 | |
Arend van Spriel | 1332e26 | 2012-11-05 16:22:18 -0800 | [diff] [blame] | 3824 | if (!vif) |
| 3825 | return -ENODEV; |
| 3826 | ifp = vif->ifp; |
| 3827 | saved_ie = &vif->saved_ie; |
| 3828 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 3829 | brcmf_dbg(TRACE, "bssidx %d, pktflag : 0x%02X\n", ifp->bssidx, pktflag); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3830 | iovar_ie_buf = kzalloc(WL_EXTRA_BUF_MAX, GFP_KERNEL); |
| 3831 | if (!iovar_ie_buf) |
| 3832 | return -ENOMEM; |
| 3833 | curr_ie_buf = iovar_ie_buf; |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 3834 | switch (pktflag) { |
| 3835 | case BRCMF_VNDR_IE_PRBREQ_FLAG: |
| 3836 | mgmt_ie_buf = saved_ie->probe_req_ie; |
| 3837 | mgmt_ie_len = &saved_ie->probe_req_ie_len; |
| 3838 | mgmt_ie_buf_len = sizeof(saved_ie->probe_req_ie); |
| 3839 | break; |
| 3840 | case BRCMF_VNDR_IE_PRBRSP_FLAG: |
| 3841 | mgmt_ie_buf = saved_ie->probe_res_ie; |
| 3842 | mgmt_ie_len = &saved_ie->probe_res_ie_len; |
| 3843 | mgmt_ie_buf_len = sizeof(saved_ie->probe_res_ie); |
| 3844 | break; |
| 3845 | case BRCMF_VNDR_IE_BEACON_FLAG: |
| 3846 | mgmt_ie_buf = saved_ie->beacon_ie; |
| 3847 | mgmt_ie_len = &saved_ie->beacon_ie_len; |
| 3848 | mgmt_ie_buf_len = sizeof(saved_ie->beacon_ie); |
| 3849 | break; |
| 3850 | case BRCMF_VNDR_IE_ASSOCREQ_FLAG: |
| 3851 | mgmt_ie_buf = saved_ie->assoc_req_ie; |
| 3852 | mgmt_ie_len = &saved_ie->assoc_req_ie_len; |
| 3853 | mgmt_ie_buf_len = sizeof(saved_ie->assoc_req_ie); |
| 3854 | break; |
| 3855 | default: |
| 3856 | err = -EPERM; |
| 3857 | brcmf_err("not suitable type\n"); |
| 3858 | goto exit; |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3859 | } |
| 3860 | |
| 3861 | if (vndr_ie_len > mgmt_ie_buf_len) { |
| 3862 | err = -ENOMEM; |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 3863 | brcmf_err("extra IE size too big\n"); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3864 | goto exit; |
| 3865 | } |
| 3866 | |
| 3867 | /* parse and save new vndr_ie in curr_ie_buff before comparing it */ |
| 3868 | if (vndr_ie_buf && vndr_ie_len && curr_ie_buf) { |
| 3869 | ptr = curr_ie_buf; |
| 3870 | brcmf_parse_vndr_ies(vndr_ie_buf, vndr_ie_len, &new_vndr_ies); |
| 3871 | for (i = 0; i < new_vndr_ies.count; i++) { |
| 3872 | vndrie_info = &new_vndr_ies.ie_info[i]; |
| 3873 | memcpy(ptr + parsed_ie_buf_len, vndrie_info->ie_ptr, |
| 3874 | vndrie_info->ie_len); |
| 3875 | parsed_ie_buf_len += vndrie_info->ie_len; |
| 3876 | } |
| 3877 | } |
| 3878 | |
Hante Meuleman | b41fc3d | 2012-11-28 21:44:13 +0100 | [diff] [blame] | 3879 | if (mgmt_ie_buf && *mgmt_ie_len) { |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3880 | if (parsed_ie_buf_len && (parsed_ie_buf_len == *mgmt_ie_len) && |
| 3881 | (memcmp(mgmt_ie_buf, curr_ie_buf, |
| 3882 | parsed_ie_buf_len) == 0)) { |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 3883 | brcmf_dbg(TRACE, "Previous mgmt IE equals to current IE\n"); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3884 | goto exit; |
| 3885 | } |
| 3886 | |
| 3887 | /* parse old vndr_ie */ |
| 3888 | brcmf_parse_vndr_ies(mgmt_ie_buf, *mgmt_ie_len, &old_vndr_ies); |
| 3889 | |
| 3890 | /* make a command to delete old ie */ |
| 3891 | for (i = 0; i < old_vndr_ies.count; i++) { |
| 3892 | vndrie_info = &old_vndr_ies.ie_info[i]; |
| 3893 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 3894 | brcmf_dbg(TRACE, "DEL ID : %d, Len: %d , OUI:%02x:%02x:%02x\n", |
| 3895 | vndrie_info->vndrie.id, |
| 3896 | vndrie_info->vndrie.len, |
| 3897 | vndrie_info->vndrie.oui[0], |
| 3898 | vndrie_info->vndrie.oui[1], |
| 3899 | vndrie_info->vndrie.oui[2]); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3900 | |
| 3901 | del_add_ie_buf_len = brcmf_vndr_ie(curr_ie_buf, pktflag, |
| 3902 | vndrie_info->ie_ptr, |
| 3903 | vndrie_info->ie_len, |
| 3904 | "del"); |
| 3905 | curr_ie_buf += del_add_ie_buf_len; |
| 3906 | total_ie_buf_len += del_add_ie_buf_len; |
| 3907 | } |
| 3908 | } |
| 3909 | |
| 3910 | *mgmt_ie_len = 0; |
| 3911 | /* Add if there is any extra IE */ |
| 3912 | if (mgmt_ie_buf && parsed_ie_buf_len) { |
| 3913 | ptr = mgmt_ie_buf; |
| 3914 | |
| 3915 | remained_buf_len = mgmt_ie_buf_len; |
| 3916 | |
| 3917 | /* make a command to add new ie */ |
| 3918 | for (i = 0; i < new_vndr_ies.count; i++) { |
| 3919 | vndrie_info = &new_vndr_ies.ie_info[i]; |
| 3920 | |
Hante Meuleman | b41fc3d | 2012-11-28 21:44:13 +0100 | [diff] [blame] | 3921 | /* verify remained buf size before copy data */ |
| 3922 | if (remained_buf_len < (vndrie_info->vndrie.len + |
| 3923 | VNDR_IE_VSIE_OFFSET)) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 3924 | brcmf_err("no space in mgmt_ie_buf: len left %d", |
| 3925 | remained_buf_len); |
Hante Meuleman | b41fc3d | 2012-11-28 21:44:13 +0100 | [diff] [blame] | 3926 | break; |
| 3927 | } |
| 3928 | remained_buf_len -= (vndrie_info->ie_len + |
| 3929 | VNDR_IE_VSIE_OFFSET); |
| 3930 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 3931 | brcmf_dbg(TRACE, "ADDED ID : %d, Len: %d, OUI:%02x:%02x:%02x\n", |
| 3932 | vndrie_info->vndrie.id, |
| 3933 | vndrie_info->vndrie.len, |
| 3934 | vndrie_info->vndrie.oui[0], |
| 3935 | vndrie_info->vndrie.oui[1], |
| 3936 | vndrie_info->vndrie.oui[2]); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3937 | |
| 3938 | del_add_ie_buf_len = brcmf_vndr_ie(curr_ie_buf, pktflag, |
| 3939 | vndrie_info->ie_ptr, |
| 3940 | vndrie_info->ie_len, |
| 3941 | "add"); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3942 | |
| 3943 | /* save the parsed IE in wl struct */ |
| 3944 | memcpy(ptr + (*mgmt_ie_len), vndrie_info->ie_ptr, |
| 3945 | vndrie_info->ie_len); |
| 3946 | *mgmt_ie_len += vndrie_info->ie_len; |
| 3947 | |
| 3948 | curr_ie_buf += del_add_ie_buf_len; |
| 3949 | total_ie_buf_len += del_add_ie_buf_len; |
| 3950 | } |
| 3951 | } |
| 3952 | if (total_ie_buf_len) { |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 3953 | err = brcmf_fil_bsscfg_data_set(ifp, "vndr_ie", iovar_ie_buf, |
Hante Meuleman | 81f5dcb | 2012-10-22 10:36:14 -0700 | [diff] [blame] | 3954 | total_ie_buf_len); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3955 | if (err) |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 3956 | brcmf_err("vndr ie set error : %d\n", err); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3957 | } |
| 3958 | |
| 3959 | exit: |
| 3960 | kfree(iovar_ie_buf); |
| 3961 | return err; |
| 3962 | } |
| 3963 | |
Arend van Spriel | 5f4f9f1 | 2013-02-08 15:53:41 +0100 | [diff] [blame] | 3964 | s32 brcmf_vif_clear_mgmt_ies(struct brcmf_cfg80211_vif *vif) |
| 3965 | { |
| 3966 | s32 pktflags[] = { |
| 3967 | BRCMF_VNDR_IE_PRBREQ_FLAG, |
| 3968 | BRCMF_VNDR_IE_PRBRSP_FLAG, |
| 3969 | BRCMF_VNDR_IE_BEACON_FLAG |
| 3970 | }; |
| 3971 | int i; |
| 3972 | |
| 3973 | for (i = 0; i < ARRAY_SIZE(pktflags); i++) |
| 3974 | brcmf_vif_set_mgmt_ie(vif, pktflags[i], NULL, 0); |
| 3975 | |
| 3976 | memset(&vif->saved_ie, 0, sizeof(vif->saved_ie)); |
| 3977 | return 0; |
| 3978 | } |
| 3979 | |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 3980 | static s32 |
Hante Meuleman | a0f0795 | 2013-02-08 15:53:47 +0100 | [diff] [blame] | 3981 | brcmf_config_ap_mgmt_ie(struct brcmf_cfg80211_vif *vif, |
| 3982 | struct cfg80211_beacon_data *beacon) |
| 3983 | { |
| 3984 | s32 err; |
| 3985 | |
| 3986 | /* Set Beacon IEs to FW */ |
| 3987 | err = brcmf_vif_set_mgmt_ie(vif, BRCMF_VNDR_IE_BEACON_FLAG, |
| 3988 | beacon->tail, beacon->tail_len); |
| 3989 | if (err) { |
| 3990 | brcmf_err("Set Beacon IE Failed\n"); |
| 3991 | return err; |
| 3992 | } |
| 3993 | brcmf_dbg(TRACE, "Applied Vndr IEs for Beacon\n"); |
| 3994 | |
| 3995 | /* Set Probe Response IEs to FW */ |
| 3996 | err = brcmf_vif_set_mgmt_ie(vif, BRCMF_VNDR_IE_PRBRSP_FLAG, |
| 3997 | beacon->proberesp_ies, |
| 3998 | beacon->proberesp_ies_len); |
| 3999 | if (err) |
| 4000 | brcmf_err("Set Probe Resp IE Failed\n"); |
| 4001 | else |
| 4002 | brcmf_dbg(TRACE, "Applied Vndr IEs for Probe Resp\n"); |
| 4003 | |
| 4004 | return err; |
| 4005 | } |
| 4006 | |
| 4007 | static s32 |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4008 | brcmf_cfg80211_start_ap(struct wiphy *wiphy, struct net_device *ndev, |
| 4009 | struct cfg80211_ap_settings *settings) |
| 4010 | { |
| 4011 | s32 ie_offset; |
Hante Meuleman | 1c9d30c | 2013-05-27 21:09:58 +0200 | [diff] [blame] | 4012 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 4013 | struct brcmf_if *ifp = netdev_priv(ndev); |
Johannes Berg | 4b5800f | 2014-01-15 14:55:59 +0100 | [diff] [blame] | 4014 | const struct brcmf_tlv *ssid_ie; |
Arend van Spriel | 9802776 | 2014-12-21 12:43:53 +0100 | [diff] [blame] | 4015 | const struct brcmf_tlv *country_ie; |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4016 | struct brcmf_ssid_le ssid_le; |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4017 | s32 err = -EPERM; |
Johannes Berg | 4b5800f | 2014-01-15 14:55:59 +0100 | [diff] [blame] | 4018 | const struct brcmf_tlv *rsn_ie; |
| 4019 | const struct brcmf_vs_tlv *wpa_ie; |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4020 | struct brcmf_join_params join_params; |
Hante Meuleman | a0f0795 | 2013-02-08 15:53:47 +0100 | [diff] [blame] | 4021 | enum nl80211_iftype dev_role; |
| 4022 | struct brcmf_fil_bss_enable_le bss_enable; |
Arend van Spriel | 06c0158 | 2014-05-12 10:47:37 +0200 | [diff] [blame] | 4023 | u16 chanspec; |
Hante Meuleman | a44aa40 | 2014-12-03 21:05:33 +0100 | [diff] [blame] | 4024 | bool mbss; |
Arend van Spriel | 9802776 | 2014-12-21 12:43:53 +0100 | [diff] [blame] | 4025 | int is_11d; |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4026 | |
Arend van Spriel | 06c0158 | 2014-05-12 10:47:37 +0200 | [diff] [blame] | 4027 | brcmf_dbg(TRACE, "ctrlchn=%d, center=%d, bw=%d, beacon_interval=%d, dtim_period=%d,\n", |
| 4028 | settings->chandef.chan->hw_value, |
| 4029 | settings->chandef.center_freq1, settings->chandef.width, |
Arend van Spriel | a9a5687 | 2014-05-12 10:47:33 +0200 | [diff] [blame] | 4030 | settings->beacon_interval, settings->dtim_period); |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 4031 | brcmf_dbg(TRACE, "ssid=%s(%zu), auth_type=%d, inactivity_timeout=%d\n", |
| 4032 | settings->ssid, settings->ssid_len, settings->auth_type, |
| 4033 | settings->inactivity_timeout); |
Hante Meuleman | 426d0a5 | 2013-02-08 15:53:53 +0100 | [diff] [blame] | 4034 | dev_role = ifp->vif->wdev.iftype; |
Hante Meuleman | a44aa40 | 2014-12-03 21:05:33 +0100 | [diff] [blame] | 4035 | mbss = ifp->vif->mbss; |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4036 | |
Arend van Spriel | 9802776 | 2014-12-21 12:43:53 +0100 | [diff] [blame] | 4037 | /* store current 11d setting */ |
| 4038 | brcmf_fil_cmd_int_get(ifp, BRCMF_C_GET_REGULATORY, &ifp->vif->is_11d); |
| 4039 | country_ie = brcmf_parse_tlvs((u8 *)settings->beacon.tail, |
| 4040 | settings->beacon.tail_len, |
| 4041 | WLAN_EID_COUNTRY); |
| 4042 | is_11d = country_ie ? 1 : 0; |
| 4043 | |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4044 | memset(&ssid_le, 0, sizeof(ssid_le)); |
| 4045 | if (settings->ssid == NULL || settings->ssid_len == 0) { |
| 4046 | ie_offset = DOT11_MGMT_HDR_LEN + DOT11_BCN_PRB_FIXED_LEN; |
| 4047 | ssid_ie = brcmf_parse_tlvs( |
| 4048 | (u8 *)&settings->beacon.head[ie_offset], |
| 4049 | settings->beacon.head_len - ie_offset, |
| 4050 | WLAN_EID_SSID); |
| 4051 | if (!ssid_ie) |
| 4052 | return -EINVAL; |
| 4053 | |
| 4054 | memcpy(ssid_le.SSID, ssid_ie->data, ssid_ie->len); |
| 4055 | ssid_le.SSID_len = cpu_to_le32(ssid_ie->len); |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 4056 | brcmf_dbg(TRACE, "SSID is (%s) in Head\n", ssid_le.SSID); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4057 | } else { |
| 4058 | memcpy(ssid_le.SSID, settings->ssid, settings->ssid_len); |
| 4059 | ssid_le.SSID_len = cpu_to_le32((u32)settings->ssid_len); |
| 4060 | } |
| 4061 | |
Hante Meuleman | a44aa40 | 2014-12-03 21:05:33 +0100 | [diff] [blame] | 4062 | if (!mbss) { |
| 4063 | brcmf_set_mpc(ifp, 0); |
| 4064 | brcmf_configure_arp_offload(ifp, false); |
| 4065 | } |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4066 | |
| 4067 | /* find the RSN_IE */ |
| 4068 | rsn_ie = brcmf_parse_tlvs((u8 *)settings->beacon.tail, |
| 4069 | settings->beacon.tail_len, WLAN_EID_RSN); |
| 4070 | |
| 4071 | /* find the WPA_IE */ |
| 4072 | wpa_ie = brcmf_find_wpaie((u8 *)settings->beacon.tail, |
| 4073 | settings->beacon.tail_len); |
| 4074 | |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4075 | if ((wpa_ie != NULL || rsn_ie != NULL)) { |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 4076 | brcmf_dbg(TRACE, "WPA(2) IE is found\n"); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4077 | if (wpa_ie != NULL) { |
| 4078 | /* WPA IE */ |
Hante Meuleman | a44aa40 | 2014-12-03 21:05:33 +0100 | [diff] [blame] | 4079 | err = brcmf_configure_wpaie(ifp, wpa_ie, false); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4080 | if (err < 0) |
| 4081 | goto exit; |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4082 | } else { |
Hante Meuleman | a44aa40 | 2014-12-03 21:05:33 +0100 | [diff] [blame] | 4083 | struct brcmf_vs_tlv *tmp_ie; |
| 4084 | |
| 4085 | tmp_ie = (struct brcmf_vs_tlv *)rsn_ie; |
| 4086 | |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4087 | /* RSN IE */ |
Hante Meuleman | a44aa40 | 2014-12-03 21:05:33 +0100 | [diff] [blame] | 4088 | err = brcmf_configure_wpaie(ifp, tmp_ie, true); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4089 | if (err < 0) |
| 4090 | goto exit; |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4091 | } |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4092 | } else { |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 4093 | brcmf_dbg(TRACE, "No WPA(2) IEs found\n"); |
Hante Meuleman | 1f17011 | 2013-02-06 18:40:38 +0100 | [diff] [blame] | 4094 | brcmf_configure_opensecurity(ifp); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4095 | } |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4096 | |
Hante Meuleman | a0f0795 | 2013-02-08 15:53:47 +0100 | [diff] [blame] | 4097 | brcmf_config_ap_mgmt_ie(ifp->vif, &settings->beacon); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4098 | |
Hante Meuleman | a44aa40 | 2014-12-03 21:05:33 +0100 | [diff] [blame] | 4099 | if (!mbss) { |
| 4100 | chanspec = chandef_to_chanspec(&cfg->d11inf, |
| 4101 | &settings->chandef); |
| 4102 | err = brcmf_fil_iovar_int_set(ifp, "chanspec", chanspec); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4103 | if (err < 0) { |
Hante Meuleman | a44aa40 | 2014-12-03 21:05:33 +0100 | [diff] [blame] | 4104 | brcmf_err("Set Channel failed: chspec=%d, %d\n", |
| 4105 | chanspec, err); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4106 | goto exit; |
| 4107 | } |
Hante Meuleman | a44aa40 | 2014-12-03 21:05:33 +0100 | [diff] [blame] | 4108 | |
Arend van Spriel | 9802776 | 2014-12-21 12:43:53 +0100 | [diff] [blame] | 4109 | if (is_11d != ifp->vif->is_11d) { |
| 4110 | err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_REGULATORY, |
| 4111 | is_11d); |
| 4112 | if (err < 0) { |
| 4113 | brcmf_err("Regulatory Set Error, %d\n", err); |
| 4114 | goto exit; |
| 4115 | } |
| 4116 | } |
Hante Meuleman | a44aa40 | 2014-12-03 21:05:33 +0100 | [diff] [blame] | 4117 | if (settings->beacon_interval) { |
| 4118 | err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_BCNPRD, |
| 4119 | settings->beacon_interval); |
| 4120 | if (err < 0) { |
| 4121 | brcmf_err("Beacon Interval Set Error, %d\n", |
| 4122 | err); |
| 4123 | goto exit; |
| 4124 | } |
| 4125 | } |
| 4126 | if (settings->dtim_period) { |
| 4127 | err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_DTIMPRD, |
| 4128 | settings->dtim_period); |
| 4129 | if (err < 0) { |
| 4130 | brcmf_err("DTIM Interval Set Error, %d\n", err); |
| 4131 | goto exit; |
| 4132 | } |
| 4133 | } |
| 4134 | |
| 4135 | if (dev_role == NL80211_IFTYPE_AP) { |
| 4136 | err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_DOWN, 1); |
| 4137 | if (err < 0) { |
| 4138 | brcmf_err("BRCMF_C_DOWN error %d\n", err); |
| 4139 | goto exit; |
| 4140 | } |
| 4141 | brcmf_fil_iovar_int_set(ifp, "apsta", 0); |
| 4142 | } |
| 4143 | |
| 4144 | err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_INFRA, 1); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4145 | if (err < 0) { |
Hante Meuleman | a44aa40 | 2014-12-03 21:05:33 +0100 | [diff] [blame] | 4146 | brcmf_err("SET INFRA error %d\n", err); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4147 | goto exit; |
| 4148 | } |
Arend van Spriel | 9802776 | 2014-12-21 12:43:53 +0100 | [diff] [blame] | 4149 | } else if (WARN_ON(is_11d != ifp->vif->is_11d)) { |
| 4150 | /* Multiple-BSS should use same 11d configuration */ |
| 4151 | err = -EINVAL; |
| 4152 | goto exit; |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4153 | } |
Hante Meuleman | a0f0795 | 2013-02-08 15:53:47 +0100 | [diff] [blame] | 4154 | if (dev_role == NL80211_IFTYPE_AP) { |
Hante Meuleman | a44aa40 | 2014-12-03 21:05:33 +0100 | [diff] [blame] | 4155 | if ((brcmf_feat_is_enabled(ifp, BRCMF_FEAT_MBSS)) && (!mbss)) |
| 4156 | brcmf_fil_iovar_int_set(ifp, "mbss", 1); |
| 4157 | |
Hante Meuleman | a0f0795 | 2013-02-08 15:53:47 +0100 | [diff] [blame] | 4158 | err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_AP, 1); |
| 4159 | if (err < 0) { |
| 4160 | brcmf_err("setting AP mode failed %d\n", err); |
| 4161 | goto exit; |
| 4162 | } |
| 4163 | err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_UP, 1); |
| 4164 | if (err < 0) { |
| 4165 | brcmf_err("BRCMF_C_UP error (%d)\n", err); |
| 4166 | goto exit; |
| 4167 | } |
Hante Meuleman | 118eb30 | 2014-12-21 12:43:49 +0100 | [diff] [blame] | 4168 | /* On DOWN the firmware removes the WEP keys, reconfigure |
| 4169 | * them if they were set. |
| 4170 | */ |
| 4171 | brcmf_cfg80211_reconfigure_wep(ifp); |
Hante Meuleman | a0f0795 | 2013-02-08 15:53:47 +0100 | [diff] [blame] | 4172 | |
| 4173 | memset(&join_params, 0, sizeof(join_params)); |
| 4174 | /* join parameters starts with ssid */ |
| 4175 | memcpy(&join_params.ssid_le, &ssid_le, sizeof(ssid_le)); |
| 4176 | /* create softap */ |
| 4177 | err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SET_SSID, |
| 4178 | &join_params, sizeof(join_params)); |
| 4179 | if (err < 0) { |
| 4180 | brcmf_err("SET SSID error (%d)\n", err); |
| 4181 | goto exit; |
| 4182 | } |
| 4183 | brcmf_dbg(TRACE, "AP mode configuration complete\n"); |
| 4184 | } else { |
| 4185 | err = brcmf_fil_bsscfg_data_set(ifp, "ssid", &ssid_le, |
| 4186 | sizeof(ssid_le)); |
| 4187 | if (err < 0) { |
| 4188 | brcmf_err("setting ssid failed %d\n", err); |
| 4189 | goto exit; |
| 4190 | } |
| 4191 | bss_enable.bsscfg_idx = cpu_to_le32(ifp->bssidx); |
| 4192 | bss_enable.enable = cpu_to_le32(1); |
| 4193 | err = brcmf_fil_iovar_data_set(ifp, "bss", &bss_enable, |
| 4194 | sizeof(bss_enable)); |
| 4195 | if (err < 0) { |
| 4196 | brcmf_err("bss_enable config failed %d\n", err); |
| 4197 | goto exit; |
| 4198 | } |
| 4199 | |
| 4200 | brcmf_dbg(TRACE, "GO mode configuration complete\n"); |
| 4201 | } |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 4202 | clear_bit(BRCMF_VIF_STATUS_AP_CREATING, &ifp->vif->sme_state); |
| 4203 | set_bit(BRCMF_VIF_STATUS_AP_CREATED, &ifp->vif->sme_state); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4204 | |
| 4205 | exit: |
Hante Meuleman | a44aa40 | 2014-12-03 21:05:33 +0100 | [diff] [blame] | 4206 | if ((err) && (!mbss)) { |
Arend van Spriel | f96aa07 | 2013-04-05 10:57:48 +0200 | [diff] [blame] | 4207 | brcmf_set_mpc(ifp, 1); |
Hante Meuleman | b365745 | 2013-05-27 21:09:53 +0200 | [diff] [blame] | 4208 | brcmf_configure_arp_offload(ifp, true); |
| 4209 | } |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4210 | return err; |
| 4211 | } |
| 4212 | |
| 4213 | static int brcmf_cfg80211_stop_ap(struct wiphy *wiphy, struct net_device *ndev) |
| 4214 | { |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 4215 | struct brcmf_if *ifp = netdev_priv(ndev); |
Hante Meuleman | 5c33a94 | 2013-04-02 21:06:18 +0200 | [diff] [blame] | 4216 | s32 err; |
Hante Meuleman | 426d0a5 | 2013-02-08 15:53:53 +0100 | [diff] [blame] | 4217 | struct brcmf_fil_bss_enable_le bss_enable; |
Hante Meuleman | 5c33a94 | 2013-04-02 21:06:18 +0200 | [diff] [blame] | 4218 | struct brcmf_join_params join_params; |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4219 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 4220 | brcmf_dbg(TRACE, "Enter\n"); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4221 | |
Hante Meuleman | 426d0a5 | 2013-02-08 15:53:53 +0100 | [diff] [blame] | 4222 | if (ifp->vif->wdev.iftype == NL80211_IFTYPE_AP) { |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4223 | /* Due to most likely deauths outstanding we sleep */ |
| 4224 | /* first to make sure they get processed by fw. */ |
| 4225 | msleep(400); |
Hante Meuleman | 5c33a94 | 2013-04-02 21:06:18 +0200 | [diff] [blame] | 4226 | |
Hante Meuleman | a44aa40 | 2014-12-03 21:05:33 +0100 | [diff] [blame] | 4227 | if (ifp->vif->mbss) { |
| 4228 | err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_DOWN, 1); |
| 4229 | return err; |
| 4230 | } |
| 4231 | |
Hante Meuleman | 5c33a94 | 2013-04-02 21:06:18 +0200 | [diff] [blame] | 4232 | memset(&join_params, 0, sizeof(join_params)); |
| 4233 | err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SET_SSID, |
| 4234 | &join_params, sizeof(join_params)); |
| 4235 | if (err < 0) |
| 4236 | brcmf_err("SET SSID error (%d)\n", err); |
Hante Meuleman | a44aa40 | 2014-12-03 21:05:33 +0100 | [diff] [blame] | 4237 | err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_DOWN, 1); |
Hante Meuleman | 5c33a94 | 2013-04-02 21:06:18 +0200 | [diff] [blame] | 4238 | if (err < 0) |
Hante Meuleman | a44aa40 | 2014-12-03 21:05:33 +0100 | [diff] [blame] | 4239 | brcmf_err("BRCMF_C_DOWN error %d\n", err); |
Hante Meuleman | 5c33a94 | 2013-04-02 21:06:18 +0200 | [diff] [blame] | 4240 | err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_AP, 0); |
| 4241 | if (err < 0) |
| 4242 | brcmf_err("setting AP mode failed %d\n", err); |
| 4243 | err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_INFRA, 0); |
| 4244 | if (err < 0) |
| 4245 | brcmf_err("setting INFRA mode failed %d\n", err); |
Hante Meuleman | a44aa40 | 2014-12-03 21:05:33 +0100 | [diff] [blame] | 4246 | if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_MBSS)) |
| 4247 | brcmf_fil_iovar_int_set(ifp, "mbss", 0); |
Arend van Spriel | 9802776 | 2014-12-21 12:43:53 +0100 | [diff] [blame] | 4248 | err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_REGULATORY, |
| 4249 | ifp->vif->is_11d); |
| 4250 | if (err < 0) |
| 4251 | brcmf_err("restoring REGULATORY setting failed %d\n", |
| 4252 | err); |
Hante Meuleman | a44aa40 | 2014-12-03 21:05:33 +0100 | [diff] [blame] | 4253 | /* Bring device back up so it can be used again */ |
| 4254 | err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_UP, 1); |
| 4255 | if (err < 0) |
| 4256 | brcmf_err("BRCMF_C_UP error %d\n", err); |
Hante Meuleman | 426d0a5 | 2013-02-08 15:53:53 +0100 | [diff] [blame] | 4257 | } else { |
| 4258 | bss_enable.bsscfg_idx = cpu_to_le32(ifp->bssidx); |
| 4259 | bss_enable.enable = cpu_to_le32(0); |
| 4260 | err = brcmf_fil_iovar_data_set(ifp, "bss", &bss_enable, |
| 4261 | sizeof(bss_enable)); |
| 4262 | if (err < 0) |
| 4263 | brcmf_err("bss_enable config failed %d\n", err); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4264 | } |
Arend van Spriel | f96aa07 | 2013-04-05 10:57:48 +0200 | [diff] [blame] | 4265 | brcmf_set_mpc(ifp, 1); |
Hante Meuleman | b365745 | 2013-05-27 21:09:53 +0200 | [diff] [blame] | 4266 | brcmf_configure_arp_offload(ifp, true); |
Hante Meuleman | 426d0a5 | 2013-02-08 15:53:53 +0100 | [diff] [blame] | 4267 | set_bit(BRCMF_VIF_STATUS_AP_CREATING, &ifp->vif->sme_state); |
| 4268 | clear_bit(BRCMF_VIF_STATUS_AP_CREATED, &ifp->vif->sme_state); |
| 4269 | |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4270 | return err; |
| 4271 | } |
| 4272 | |
Hante Meuleman | a0f0795 | 2013-02-08 15:53:47 +0100 | [diff] [blame] | 4273 | static s32 |
| 4274 | brcmf_cfg80211_change_beacon(struct wiphy *wiphy, struct net_device *ndev, |
| 4275 | struct cfg80211_beacon_data *info) |
| 4276 | { |
Hante Meuleman | a0f0795 | 2013-02-08 15:53:47 +0100 | [diff] [blame] | 4277 | struct brcmf_if *ifp = netdev_priv(ndev); |
| 4278 | s32 err; |
| 4279 | |
| 4280 | brcmf_dbg(TRACE, "Enter\n"); |
| 4281 | |
Hante Meuleman | a0f0795 | 2013-02-08 15:53:47 +0100 | [diff] [blame] | 4282 | err = brcmf_config_ap_mgmt_ie(ifp->vif, info); |
| 4283 | |
| 4284 | return err; |
| 4285 | } |
| 4286 | |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4287 | static int |
| 4288 | brcmf_cfg80211_del_station(struct wiphy *wiphy, struct net_device *ndev, |
Jouni Malinen | 89c771e | 2014-10-10 20:52:40 +0300 | [diff] [blame] | 4289 | struct station_del_parameters *params) |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4290 | { |
Hante Meuleman | a0f0795 | 2013-02-08 15:53:47 +0100 | [diff] [blame] | 4291 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4292 | struct brcmf_scb_val_le scbval; |
Arend van Spriel | 0abb5f21 | 2012-10-22 13:55:32 -0700 | [diff] [blame] | 4293 | struct brcmf_if *ifp = netdev_priv(ndev); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4294 | s32 err; |
| 4295 | |
Jouni Malinen | 89c771e | 2014-10-10 20:52:40 +0300 | [diff] [blame] | 4296 | if (!params->mac) |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4297 | return -EFAULT; |
| 4298 | |
Jouni Malinen | 89c771e | 2014-10-10 20:52:40 +0300 | [diff] [blame] | 4299 | brcmf_dbg(TRACE, "Enter %pM\n", params->mac); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4300 | |
Hante Meuleman | a0f0795 | 2013-02-08 15:53:47 +0100 | [diff] [blame] | 4301 | if (ifp->vif == cfg->p2p.bss_idx[P2PAPI_BSSCFG_DEVICE].vif) |
| 4302 | ifp = cfg->p2p.bss_idx[P2PAPI_BSSCFG_PRIMARY].vif->ifp; |
Arend van Spriel | ce81e31 | 2012-10-22 13:55:37 -0700 | [diff] [blame] | 4303 | if (!check_vif_up(ifp->vif)) |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4304 | return -EIO; |
| 4305 | |
Jouni Malinen | 89c771e | 2014-10-10 20:52:40 +0300 | [diff] [blame] | 4306 | memcpy(&scbval.ea, params->mac, ETH_ALEN); |
Rafał Miłecki | ba8b6ae | 2015-02-08 11:51:47 +0100 | [diff] [blame] | 4307 | scbval.val = cpu_to_le32(params->reason_code); |
Arend van Spriel | 0abb5f21 | 2012-10-22 13:55:32 -0700 | [diff] [blame] | 4308 | 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] | 4309 | &scbval, sizeof(scbval)); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4310 | if (err) |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 4311 | brcmf_err("SCB_DEAUTHENTICATE_FOR_REASON failed %d\n", err); |
Hante Meuleman | 7ab6acd | 2013-02-08 15:53:58 +0100 | [diff] [blame] | 4312 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 4313 | brcmf_dbg(TRACE, "Exit\n"); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4314 | return err; |
| 4315 | } |
| 4316 | |
Hante Meuleman | 6b89dcb | 2014-12-21 12:43:52 +0100 | [diff] [blame] | 4317 | static int |
| 4318 | brcmf_cfg80211_change_station(struct wiphy *wiphy, struct net_device *ndev, |
| 4319 | const u8 *mac, struct station_parameters *params) |
| 4320 | { |
| 4321 | struct brcmf_if *ifp = netdev_priv(ndev); |
| 4322 | s32 err; |
| 4323 | |
| 4324 | brcmf_dbg(TRACE, "Enter, MAC %pM, mask 0x%04x set 0x%04x\n", mac, |
| 4325 | params->sta_flags_mask, params->sta_flags_set); |
| 4326 | |
| 4327 | /* Ignore all 00 MAC */ |
| 4328 | if (is_zero_ether_addr(mac)) |
| 4329 | return 0; |
| 4330 | |
| 4331 | if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED))) |
| 4332 | return 0; |
| 4333 | |
| 4334 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED)) |
| 4335 | err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SET_SCB_AUTHORIZE, |
| 4336 | (void *)mac, ETH_ALEN); |
| 4337 | else |
| 4338 | err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SET_SCB_DEAUTHORIZE, |
| 4339 | (void *)mac, ETH_ALEN); |
| 4340 | if (err < 0) |
| 4341 | brcmf_err("Setting SCB (de-)authorize failed, %d\n", err); |
| 4342 | |
| 4343 | return err; |
| 4344 | } |
Hante Meuleman | 0de8aac | 2013-02-08 15:53:38 +0100 | [diff] [blame] | 4345 | |
| 4346 | static void |
| 4347 | brcmf_cfg80211_mgmt_frame_register(struct wiphy *wiphy, |
| 4348 | struct wireless_dev *wdev, |
| 4349 | u16 frame_type, bool reg) |
| 4350 | { |
Arend van Spriel | 7fa2e35 | 2013-04-05 10:57:47 +0200 | [diff] [blame] | 4351 | struct brcmf_cfg80211_vif *vif; |
Hante Meuleman | 0de8aac | 2013-02-08 15:53:38 +0100 | [diff] [blame] | 4352 | u16 mgmt_type; |
| 4353 | |
| 4354 | brcmf_dbg(TRACE, "Enter, frame_type %04x, reg=%d\n", frame_type, reg); |
| 4355 | |
| 4356 | mgmt_type = (frame_type & IEEE80211_FCTL_STYPE) >> 4; |
Arend van Spriel | 7fa2e35 | 2013-04-05 10:57:47 +0200 | [diff] [blame] | 4357 | vif = container_of(wdev, struct brcmf_cfg80211_vif, wdev); |
Hante Meuleman | 0de8aac | 2013-02-08 15:53:38 +0100 | [diff] [blame] | 4358 | if (reg) |
| 4359 | vif->mgmt_rx_reg |= BIT(mgmt_type); |
| 4360 | else |
Hante Meuleman | 318a64c | 2013-02-08 15:53:45 +0100 | [diff] [blame] | 4361 | vif->mgmt_rx_reg &= ~BIT(mgmt_type); |
Hante Meuleman | 0de8aac | 2013-02-08 15:53:38 +0100 | [diff] [blame] | 4362 | } |
| 4363 | |
| 4364 | |
| 4365 | static int |
| 4366 | brcmf_cfg80211_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev, |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 4367 | struct cfg80211_mgmt_tx_params *params, u64 *cookie) |
Hante Meuleman | 0de8aac | 2013-02-08 15:53:38 +0100 | [diff] [blame] | 4368 | { |
| 4369 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 4370 | struct ieee80211_channel *chan = params->chan; |
| 4371 | const u8 *buf = params->buf; |
| 4372 | size_t len = params->len; |
Hante Meuleman | 0de8aac | 2013-02-08 15:53:38 +0100 | [diff] [blame] | 4373 | const struct ieee80211_mgmt *mgmt; |
| 4374 | struct brcmf_cfg80211_vif *vif; |
| 4375 | s32 err = 0; |
| 4376 | s32 ie_offset; |
| 4377 | s32 ie_len; |
Hante Meuleman | 18e2f61 | 2013-02-08 15:53:49 +0100 | [diff] [blame] | 4378 | struct brcmf_fil_action_frame_le *action_frame; |
| 4379 | struct brcmf_fil_af_params_le *af_params; |
| 4380 | bool ack; |
| 4381 | s32 chan_nr; |
Antonio Quartulli | c2ff8ca | 2013-06-11 14:20:01 +0200 | [diff] [blame] | 4382 | u32 freq; |
Hante Meuleman | 0de8aac | 2013-02-08 15:53:38 +0100 | [diff] [blame] | 4383 | |
| 4384 | brcmf_dbg(TRACE, "Enter\n"); |
| 4385 | |
| 4386 | *cookie = 0; |
| 4387 | |
| 4388 | mgmt = (const struct ieee80211_mgmt *)buf; |
| 4389 | |
Hante Meuleman | a0f0795 | 2013-02-08 15:53:47 +0100 | [diff] [blame] | 4390 | if (!ieee80211_is_mgmt(mgmt->frame_control)) { |
| 4391 | brcmf_err("Driver only allows MGMT packet type\n"); |
| 4392 | return -EPERM; |
Hante Meuleman | 0de8aac | 2013-02-08 15:53:38 +0100 | [diff] [blame] | 4393 | } |
Hante Meuleman | a0f0795 | 2013-02-08 15:53:47 +0100 | [diff] [blame] | 4394 | |
Antonio Quartulli | c2ff8ca | 2013-06-11 14:20:01 +0200 | [diff] [blame] | 4395 | vif = container_of(wdev, struct brcmf_cfg80211_vif, wdev); |
| 4396 | |
Hante Meuleman | a0f0795 | 2013-02-08 15:53:47 +0100 | [diff] [blame] | 4397 | if (ieee80211_is_probe_resp(mgmt->frame_control)) { |
| 4398 | /* Right now the only reason to get a probe response */ |
| 4399 | /* is for p2p listen response or for p2p GO from */ |
| 4400 | /* wpa_supplicant. Unfortunately the probe is send */ |
| 4401 | /* on primary ndev, while dongle wants it on the p2p */ |
| 4402 | /* vif. Since this is only reason for a probe */ |
| 4403 | /* response to be sent, the vif is taken from cfg. */ |
| 4404 | /* If ever desired to send proberesp for non p2p */ |
| 4405 | /* response then data should be checked for */ |
| 4406 | /* "DIRECT-". Note in future supplicant will take */ |
| 4407 | /* dedicated p2p wdev to do this and then this 'hack'*/ |
| 4408 | /* is not needed anymore. */ |
| 4409 | ie_offset = DOT11_MGMT_HDR_LEN + |
| 4410 | DOT11_BCN_PRB_FIXED_LEN; |
| 4411 | ie_len = len - ie_offset; |
Hante Meuleman | a0f0795 | 2013-02-08 15:53:47 +0100 | [diff] [blame] | 4412 | if (vif == cfg->p2p.bss_idx[P2PAPI_BSSCFG_PRIMARY].vif) |
| 4413 | vif = cfg->p2p.bss_idx[P2PAPI_BSSCFG_DEVICE].vif; |
| 4414 | err = brcmf_vif_set_mgmt_ie(vif, |
| 4415 | BRCMF_VNDR_IE_PRBRSP_FLAG, |
| 4416 | &buf[ie_offset], |
| 4417 | ie_len); |
| 4418 | cfg80211_mgmt_tx_status(wdev, *cookie, buf, len, true, |
| 4419 | GFP_KERNEL); |
Hante Meuleman | 18e2f61 | 2013-02-08 15:53:49 +0100 | [diff] [blame] | 4420 | } else if (ieee80211_is_action(mgmt->frame_control)) { |
| 4421 | af_params = kzalloc(sizeof(*af_params), GFP_KERNEL); |
| 4422 | if (af_params == NULL) { |
| 4423 | brcmf_err("unable to allocate frame\n"); |
| 4424 | err = -ENOMEM; |
| 4425 | goto exit; |
| 4426 | } |
| 4427 | action_frame = &af_params->action_frame; |
| 4428 | /* Add the packet Id */ |
| 4429 | action_frame->packet_id = cpu_to_le32(*cookie); |
| 4430 | /* Add BSSID */ |
| 4431 | memcpy(&action_frame->da[0], &mgmt->da[0], ETH_ALEN); |
| 4432 | memcpy(&af_params->bssid[0], &mgmt->bssid[0], ETH_ALEN); |
| 4433 | /* Add the length exepted for 802.11 header */ |
| 4434 | action_frame->len = cpu_to_le16(len - DOT11_MGMT_HDR_LEN); |
Antonio Quartulli | c2ff8ca | 2013-06-11 14:20:01 +0200 | [diff] [blame] | 4435 | /* Add the channel. Use the one specified as parameter if any or |
| 4436 | * the current one (got from the firmware) otherwise |
| 4437 | */ |
| 4438 | if (chan) |
| 4439 | freq = chan->center_freq; |
| 4440 | else |
| 4441 | brcmf_fil_cmd_int_get(vif->ifp, BRCMF_C_GET_CHANNEL, |
| 4442 | &freq); |
| 4443 | chan_nr = ieee80211_frequency_to_channel(freq); |
Hante Meuleman | 18e2f61 | 2013-02-08 15:53:49 +0100 | [diff] [blame] | 4444 | af_params->channel = cpu_to_le32(chan_nr); |
| 4445 | |
| 4446 | memcpy(action_frame->data, &buf[DOT11_MGMT_HDR_LEN], |
| 4447 | le16_to_cpu(action_frame->len)); |
| 4448 | |
| 4449 | brcmf_dbg(TRACE, "Action frame, cookie=%lld, len=%d, freq=%d\n", |
Antonio Quartulli | 86a9c4a | 2013-06-19 13:35:31 +0200 | [diff] [blame] | 4450 | *cookie, le16_to_cpu(action_frame->len), freq); |
Hante Meuleman | 18e2f61 | 2013-02-08 15:53:49 +0100 | [diff] [blame] | 4451 | |
Arend van Spriel | 7fa2e35 | 2013-04-05 10:57:47 +0200 | [diff] [blame] | 4452 | ack = brcmf_p2p_send_action_frame(cfg, cfg_to_ndev(cfg), |
Hante Meuleman | 18e2f61 | 2013-02-08 15:53:49 +0100 | [diff] [blame] | 4453 | af_params); |
| 4454 | |
| 4455 | cfg80211_mgmt_tx_status(wdev, *cookie, buf, len, ack, |
| 4456 | GFP_KERNEL); |
| 4457 | kfree(af_params); |
Hante Meuleman | a0f0795 | 2013-02-08 15:53:47 +0100 | [diff] [blame] | 4458 | } else { |
| 4459 | brcmf_dbg(TRACE, "Unhandled, fc=%04x!!\n", mgmt->frame_control); |
| 4460 | brcmf_dbg_hex_dump(true, buf, len, "payload, len=%Zu\n", len); |
| 4461 | } |
| 4462 | |
Hante Meuleman | 18e2f61 | 2013-02-08 15:53:49 +0100 | [diff] [blame] | 4463 | exit: |
Hante Meuleman | 0de8aac | 2013-02-08 15:53:38 +0100 | [diff] [blame] | 4464 | return err; |
| 4465 | } |
| 4466 | |
| 4467 | |
| 4468 | static int |
| 4469 | brcmf_cfg80211_cancel_remain_on_channel(struct wiphy *wiphy, |
| 4470 | struct wireless_dev *wdev, |
| 4471 | u64 cookie) |
| 4472 | { |
| 4473 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); |
| 4474 | struct brcmf_cfg80211_vif *vif; |
| 4475 | int err = 0; |
| 4476 | |
| 4477 | brcmf_dbg(TRACE, "Enter p2p listen cancel\n"); |
| 4478 | |
| 4479 | vif = cfg->p2p.bss_idx[P2PAPI_BSSCFG_DEVICE].vif; |
| 4480 | if (vif == NULL) { |
| 4481 | brcmf_err("No p2p device available for probe response\n"); |
| 4482 | err = -ENODEV; |
| 4483 | goto exit; |
| 4484 | } |
| 4485 | brcmf_p2p_cancel_remain_on_channel(vif->ifp); |
| 4486 | exit: |
| 4487 | return err; |
| 4488 | } |
| 4489 | |
Piotr Haber | 61730d4 | 2013-04-23 12:53:12 +0200 | [diff] [blame] | 4490 | static int brcmf_cfg80211_crit_proto_start(struct wiphy *wiphy, |
| 4491 | struct wireless_dev *wdev, |
| 4492 | enum nl80211_crit_proto_id proto, |
| 4493 | u16 duration) |
| 4494 | { |
| 4495 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); |
| 4496 | struct brcmf_cfg80211_vif *vif; |
| 4497 | |
| 4498 | vif = container_of(wdev, struct brcmf_cfg80211_vif, wdev); |
| 4499 | |
| 4500 | /* only DHCP support for now */ |
| 4501 | if (proto != NL80211_CRIT_PROTO_DHCP) |
| 4502 | return -EINVAL; |
| 4503 | |
| 4504 | /* suppress and abort scanning */ |
| 4505 | set_bit(BRCMF_SCAN_STATUS_SUPPRESS, &cfg->scan_status); |
| 4506 | brcmf_abort_scanning(cfg); |
| 4507 | |
| 4508 | return brcmf_btcoex_set_mode(vif, BRCMF_BTCOEX_DISABLED, duration); |
| 4509 | } |
| 4510 | |
| 4511 | static void brcmf_cfg80211_crit_proto_stop(struct wiphy *wiphy, |
| 4512 | struct wireless_dev *wdev) |
| 4513 | { |
| 4514 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); |
| 4515 | struct brcmf_cfg80211_vif *vif; |
| 4516 | |
| 4517 | vif = container_of(wdev, struct brcmf_cfg80211_vif, wdev); |
| 4518 | |
| 4519 | brcmf_btcoex_set_mode(vif, BRCMF_BTCOEX_ENABLED, 0); |
| 4520 | clear_bit(BRCMF_SCAN_STATUS_SUPPRESS, &cfg->scan_status); |
| 4521 | } |
| 4522 | |
Hante Meuleman | 70b7d94 | 2014-07-30 13:20:07 +0200 | [diff] [blame] | 4523 | static s32 |
| 4524 | brcmf_notify_tdls_peer_event(struct brcmf_if *ifp, |
| 4525 | const struct brcmf_event_msg *e, void *data) |
| 4526 | { |
| 4527 | switch (e->reason) { |
| 4528 | case BRCMF_E_REASON_TDLS_PEER_DISCOVERED: |
| 4529 | brcmf_dbg(TRACE, "TDLS Peer Discovered\n"); |
| 4530 | break; |
| 4531 | case BRCMF_E_REASON_TDLS_PEER_CONNECTED: |
| 4532 | brcmf_dbg(TRACE, "TDLS Peer Connected\n"); |
| 4533 | brcmf_proto_add_tdls_peer(ifp->drvr, ifp->ifidx, (u8 *)e->addr); |
| 4534 | break; |
| 4535 | case BRCMF_E_REASON_TDLS_PEER_DISCONNECTED: |
| 4536 | brcmf_dbg(TRACE, "TDLS Peer Disconnected\n"); |
| 4537 | brcmf_proto_delete_peer(ifp->drvr, ifp->ifidx, (u8 *)e->addr); |
| 4538 | break; |
| 4539 | } |
| 4540 | |
| 4541 | return 0; |
| 4542 | } |
| 4543 | |
Arend van Spriel | 89c2f38 | 2013-08-10 12:27:25 +0200 | [diff] [blame] | 4544 | static int brcmf_convert_nl80211_tdls_oper(enum nl80211_tdls_operation oper) |
| 4545 | { |
| 4546 | int ret; |
| 4547 | |
| 4548 | switch (oper) { |
| 4549 | case NL80211_TDLS_DISCOVERY_REQ: |
| 4550 | ret = BRCMF_TDLS_MANUAL_EP_DISCOVERY; |
| 4551 | break; |
| 4552 | case NL80211_TDLS_SETUP: |
| 4553 | ret = BRCMF_TDLS_MANUAL_EP_CREATE; |
| 4554 | break; |
| 4555 | case NL80211_TDLS_TEARDOWN: |
| 4556 | ret = BRCMF_TDLS_MANUAL_EP_DELETE; |
| 4557 | break; |
| 4558 | default: |
| 4559 | brcmf_err("unsupported operation: %d\n", oper); |
| 4560 | ret = -EOPNOTSUPP; |
| 4561 | } |
| 4562 | return ret; |
| 4563 | } |
| 4564 | |
| 4565 | static int brcmf_cfg80211_tdls_oper(struct wiphy *wiphy, |
Johannes Berg | 3b3a016 | 2014-05-19 17:19:31 +0200 | [diff] [blame] | 4566 | struct net_device *ndev, const u8 *peer, |
Arend van Spriel | 89c2f38 | 2013-08-10 12:27:25 +0200 | [diff] [blame] | 4567 | enum nl80211_tdls_operation oper) |
| 4568 | { |
| 4569 | struct brcmf_if *ifp; |
| 4570 | struct brcmf_tdls_iovar_le info; |
| 4571 | int ret = 0; |
| 4572 | |
| 4573 | ret = brcmf_convert_nl80211_tdls_oper(oper); |
| 4574 | if (ret < 0) |
| 4575 | return ret; |
| 4576 | |
| 4577 | ifp = netdev_priv(ndev); |
| 4578 | memset(&info, 0, sizeof(info)); |
| 4579 | info.mode = (u8)ret; |
| 4580 | if (peer) |
| 4581 | memcpy(info.ea, peer, ETH_ALEN); |
| 4582 | |
| 4583 | ret = brcmf_fil_iovar_data_set(ifp, "tdls_endpoint", |
| 4584 | &info, sizeof(info)); |
| 4585 | if (ret < 0) |
| 4586 | brcmf_err("tdls_endpoint iovar failed: ret=%d\n", ret); |
| 4587 | |
| 4588 | return ret; |
| 4589 | } |
| 4590 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4591 | static struct cfg80211_ops wl_cfg80211_ops = { |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 4592 | .add_virtual_intf = brcmf_cfg80211_add_iface, |
| 4593 | .del_virtual_intf = brcmf_cfg80211_del_iface, |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4594 | .change_virtual_intf = brcmf_cfg80211_change_iface, |
| 4595 | .scan = brcmf_cfg80211_scan, |
| 4596 | .set_wiphy_params = brcmf_cfg80211_set_wiphy_params, |
| 4597 | .join_ibss = brcmf_cfg80211_join_ibss, |
| 4598 | .leave_ibss = brcmf_cfg80211_leave_ibss, |
| 4599 | .get_station = brcmf_cfg80211_get_station, |
| 4600 | .set_tx_power = brcmf_cfg80211_set_tx_power, |
| 4601 | .get_tx_power = brcmf_cfg80211_get_tx_power, |
| 4602 | .add_key = brcmf_cfg80211_add_key, |
| 4603 | .del_key = brcmf_cfg80211_del_key, |
| 4604 | .get_key = brcmf_cfg80211_get_key, |
| 4605 | .set_default_key = brcmf_cfg80211_config_default_key, |
| 4606 | .set_default_mgmt_key = brcmf_cfg80211_config_default_mgmt_key, |
| 4607 | .set_power_mgmt = brcmf_cfg80211_set_power_mgmt, |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4608 | .connect = brcmf_cfg80211_connect, |
| 4609 | .disconnect = brcmf_cfg80211_disconnect, |
| 4610 | .suspend = brcmf_cfg80211_suspend, |
| 4611 | .resume = brcmf_cfg80211_resume, |
| 4612 | .set_pmksa = brcmf_cfg80211_set_pmksa, |
| 4613 | .del_pmksa = brcmf_cfg80211_del_pmksa, |
Arend van Spriel | cbaa177 | 2012-08-30 19:43:02 +0200 | [diff] [blame] | 4614 | .flush_pmksa = brcmf_cfg80211_flush_pmksa, |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4615 | .start_ap = brcmf_cfg80211_start_ap, |
| 4616 | .stop_ap = brcmf_cfg80211_stop_ap, |
Hante Meuleman | a0f0795 | 2013-02-08 15:53:47 +0100 | [diff] [blame] | 4617 | .change_beacon = brcmf_cfg80211_change_beacon, |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4618 | .del_station = brcmf_cfg80211_del_station, |
Hante Meuleman | 6b89dcb | 2014-12-21 12:43:52 +0100 | [diff] [blame] | 4619 | .change_station = brcmf_cfg80211_change_station, |
Arend van Spriel | e580607 | 2012-09-19 22:21:08 +0200 | [diff] [blame] | 4620 | .sched_scan_start = brcmf_cfg80211_sched_scan_start, |
| 4621 | .sched_scan_stop = brcmf_cfg80211_sched_scan_stop, |
Hante Meuleman | 0de8aac | 2013-02-08 15:53:38 +0100 | [diff] [blame] | 4622 | .mgmt_frame_register = brcmf_cfg80211_mgmt_frame_register, |
| 4623 | .mgmt_tx = brcmf_cfg80211_mgmt_tx, |
| 4624 | .remain_on_channel = brcmf_p2p_remain_on_channel, |
| 4625 | .cancel_remain_on_channel = brcmf_cfg80211_cancel_remain_on_channel, |
Arend van Spriel | 27f10e3 | 2013-04-05 10:57:50 +0200 | [diff] [blame] | 4626 | .start_p2p_device = brcmf_p2p_start_device, |
| 4627 | .stop_p2p_device = brcmf_p2p_stop_device, |
Piotr Haber | 61730d4 | 2013-04-23 12:53:12 +0200 | [diff] [blame] | 4628 | .crit_proto_start = brcmf_cfg80211_crit_proto_start, |
| 4629 | .crit_proto_stop = brcmf_cfg80211_crit_proto_stop, |
Arend van Spriel | 89c2f38 | 2013-08-10 12:27:25 +0200 | [diff] [blame] | 4630 | .tdls_oper = brcmf_cfg80211_tdls_oper, |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4631 | }; |
| 4632 | |
Arend van Spriel | 3eacf86 | 2012-10-22 13:55:30 -0700 | [diff] [blame] | 4633 | 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] | 4634 | enum nl80211_iftype type, |
| 4635 | bool pm_block) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4636 | { |
Hante Meuleman | a44aa40 | 2014-12-03 21:05:33 +0100 | [diff] [blame] | 4637 | struct brcmf_cfg80211_vif *vif_walk; |
Arend van Spriel | 3eacf86 | 2012-10-22 13:55:30 -0700 | [diff] [blame] | 4638 | struct brcmf_cfg80211_vif *vif; |
Hante Meuleman | a44aa40 | 2014-12-03 21:05:33 +0100 | [diff] [blame] | 4639 | bool mbss; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4640 | |
Arend van Spriel | 33a6b15 | 2013-02-08 15:53:39 +0100 | [diff] [blame] | 4641 | brcmf_dbg(TRACE, "allocating virtual interface (size=%zu)\n", |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 4642 | sizeof(*vif)); |
Arend van Spriel | 3eacf86 | 2012-10-22 13:55:30 -0700 | [diff] [blame] | 4643 | vif = kzalloc(sizeof(*vif), GFP_KERNEL); |
| 4644 | if (!vif) |
| 4645 | return ERR_PTR(-ENOMEM); |
| 4646 | |
| 4647 | vif->wdev.wiphy = cfg->wiphy; |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 4648 | vif->wdev.iftype = type; |
Arend van Spriel | 3eacf86 | 2012-10-22 13:55:30 -0700 | [diff] [blame] | 4649 | |
Arend van Spriel | 3eacf86 | 2012-10-22 13:55:30 -0700 | [diff] [blame] | 4650 | vif->pm_block = pm_block; |
| 4651 | vif->roam_off = -1; |
| 4652 | |
Arend van Spriel | 6ac4f4e | 2012-10-22 13:55:31 -0700 | [diff] [blame] | 4653 | brcmf_init_prof(&vif->profile); |
| 4654 | |
Hante Meuleman | a44aa40 | 2014-12-03 21:05:33 +0100 | [diff] [blame] | 4655 | if (type == NL80211_IFTYPE_AP) { |
| 4656 | mbss = false; |
| 4657 | list_for_each_entry(vif_walk, &cfg->vif_list, list) { |
| 4658 | if (vif_walk->wdev.iftype == NL80211_IFTYPE_AP) { |
| 4659 | mbss = true; |
| 4660 | break; |
| 4661 | } |
| 4662 | } |
| 4663 | vif->mbss = mbss; |
| 4664 | } |
| 4665 | |
Arend van Spriel | 3eacf86 | 2012-10-22 13:55:30 -0700 | [diff] [blame] | 4666 | list_add_tail(&vif->list, &cfg->vif_list); |
Arend van Spriel | 3eacf86 | 2012-10-22 13:55:30 -0700 | [diff] [blame] | 4667 | return vif; |
| 4668 | } |
| 4669 | |
Arend van Spriel | 427dec5 | 2014-01-06 12:40:47 +0100 | [diff] [blame] | 4670 | void brcmf_free_vif(struct brcmf_cfg80211_vif *vif) |
Arend van Spriel | 3eacf86 | 2012-10-22 13:55:30 -0700 | [diff] [blame] | 4671 | { |
Arend van Spriel | 3eacf86 | 2012-10-22 13:55:30 -0700 | [diff] [blame] | 4672 | list_del(&vif->list); |
Arend van Spriel | 3eacf86 | 2012-10-22 13:55:30 -0700 | [diff] [blame] | 4673 | kfree(vif); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4674 | } |
| 4675 | |
Arend van Spriel | 9df4d54 | 2014-01-06 12:40:49 +0100 | [diff] [blame] | 4676 | void brcmf_cfg80211_free_netdev(struct net_device *ndev) |
| 4677 | { |
| 4678 | struct brcmf_cfg80211_vif *vif; |
| 4679 | struct brcmf_if *ifp; |
| 4680 | |
| 4681 | ifp = netdev_priv(ndev); |
| 4682 | vif = ifp->vif; |
| 4683 | |
| 4684 | brcmf_free_vif(vif); |
| 4685 | free_netdev(ndev); |
| 4686 | } |
| 4687 | |
Arend van Spriel | 903e0ee | 2012-11-28 21:44:11 +0100 | [diff] [blame] | 4688 | static bool brcmf_is_linkup(const struct brcmf_event_msg *e) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4689 | { |
Arend van Spriel | 5c36b99 | 2012-11-14 18:46:05 -0800 | [diff] [blame] | 4690 | u32 event = e->event_code; |
| 4691 | u32 status = e->status; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4692 | |
| 4693 | if (event == BRCMF_E_SET_SSID && status == BRCMF_E_STATUS_SUCCESS) { |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 4694 | brcmf_dbg(CONN, "Processing set ssid\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4695 | return true; |
| 4696 | } |
| 4697 | |
| 4698 | return false; |
| 4699 | } |
| 4700 | |
Arend van Spriel | 903e0ee | 2012-11-28 21:44:11 +0100 | [diff] [blame] | 4701 | static bool brcmf_is_linkdown(const struct brcmf_event_msg *e) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4702 | { |
Arend van Spriel | 5c36b99 | 2012-11-14 18:46:05 -0800 | [diff] [blame] | 4703 | u32 event = e->event_code; |
| 4704 | u16 flags = e->flags; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4705 | |
Hante Meuleman | 68ca395 | 2014-02-25 20:30:26 +0100 | [diff] [blame] | 4706 | if ((event == BRCMF_E_DEAUTH) || (event == BRCMF_E_DEAUTH_IND) || |
| 4707 | (event == BRCMF_E_DISASSOC_IND) || |
| 4708 | ((event == BRCMF_E_LINK) && (!(flags & BRCMF_EVENT_MSG_LINK)))) { |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 4709 | brcmf_dbg(CONN, "Processing link down\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4710 | return true; |
| 4711 | } |
| 4712 | return false; |
| 4713 | } |
| 4714 | |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 4715 | static bool brcmf_is_nonetwork(struct brcmf_cfg80211_info *cfg, |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4716 | const struct brcmf_event_msg *e) |
| 4717 | { |
Arend van Spriel | 5c36b99 | 2012-11-14 18:46:05 -0800 | [diff] [blame] | 4718 | u32 event = e->event_code; |
| 4719 | u32 status = e->status; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4720 | |
| 4721 | if (event == BRCMF_E_LINK && status == BRCMF_E_STATUS_NO_NETWORKS) { |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 4722 | brcmf_dbg(CONN, "Processing Link %s & no network found\n", |
| 4723 | e->flags & BRCMF_EVENT_MSG_LINK ? "up" : "down"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4724 | return true; |
| 4725 | } |
| 4726 | |
| 4727 | if (event == BRCMF_E_SET_SSID && status != BRCMF_E_STATUS_SUCCESS) { |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 4728 | brcmf_dbg(CONN, "Processing connecting & no network found\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4729 | return true; |
| 4730 | } |
| 4731 | |
| 4732 | return false; |
| 4733 | } |
| 4734 | |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 4735 | static void brcmf_clear_assoc_ies(struct brcmf_cfg80211_info *cfg) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4736 | { |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 4737 | struct brcmf_cfg80211_connect_info *conn_info = cfg_to_conn(cfg); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4738 | |
| 4739 | kfree(conn_info->req_ie); |
| 4740 | conn_info->req_ie = NULL; |
| 4741 | conn_info->req_ie_len = 0; |
| 4742 | kfree(conn_info->resp_ie); |
| 4743 | conn_info->resp_ie = NULL; |
| 4744 | conn_info->resp_ie_len = 0; |
| 4745 | } |
| 4746 | |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 4747 | static s32 brcmf_get_assoc_ies(struct brcmf_cfg80211_info *cfg, |
| 4748 | struct brcmf_if *ifp) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4749 | { |
Arend van Spriel | c4e382d | 2011-10-12 20:51:21 +0200 | [diff] [blame] | 4750 | struct brcmf_cfg80211_assoc_ielen_le *assoc_info; |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 4751 | struct brcmf_cfg80211_connect_info *conn_info = cfg_to_conn(cfg); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4752 | u32 req_len; |
| 4753 | u32 resp_len; |
| 4754 | s32 err = 0; |
| 4755 | |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 4756 | brcmf_clear_assoc_ies(cfg); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4757 | |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 4758 | err = brcmf_fil_iovar_data_get(ifp, "assoc_info", |
| 4759 | cfg->extra_buf, WL_ASSOC_INFO_MAX); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4760 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 4761 | brcmf_err("could not get assoc info (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4762 | return err; |
| 4763 | } |
Arend van Spriel | c4e382d | 2011-10-12 20:51:21 +0200 | [diff] [blame] | 4764 | assoc_info = |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 4765 | (struct brcmf_cfg80211_assoc_ielen_le *)cfg->extra_buf; |
Arend van Spriel | c4e382d | 2011-10-12 20:51:21 +0200 | [diff] [blame] | 4766 | req_len = le32_to_cpu(assoc_info->req_len); |
| 4767 | resp_len = le32_to_cpu(assoc_info->resp_len); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4768 | if (req_len) { |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 4769 | err = brcmf_fil_iovar_data_get(ifp, "assoc_req_ies", |
Hante Meuleman | 81f5dcb | 2012-10-22 10:36:14 -0700 | [diff] [blame] | 4770 | cfg->extra_buf, |
| 4771 | WL_ASSOC_INFO_MAX); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4772 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 4773 | brcmf_err("could not get assoc req (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4774 | return err; |
| 4775 | } |
| 4776 | conn_info->req_ie_len = req_len; |
| 4777 | conn_info->req_ie = |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 4778 | kmemdup(cfg->extra_buf, conn_info->req_ie_len, |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4779 | GFP_KERNEL); |
| 4780 | } else { |
| 4781 | conn_info->req_ie_len = 0; |
| 4782 | conn_info->req_ie = NULL; |
| 4783 | } |
| 4784 | if (resp_len) { |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 4785 | err = brcmf_fil_iovar_data_get(ifp, "assoc_resp_ies", |
Hante Meuleman | 81f5dcb | 2012-10-22 10:36:14 -0700 | [diff] [blame] | 4786 | cfg->extra_buf, |
| 4787 | WL_ASSOC_INFO_MAX); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4788 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 4789 | brcmf_err("could not get assoc resp (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4790 | return err; |
| 4791 | } |
| 4792 | conn_info->resp_ie_len = resp_len; |
| 4793 | conn_info->resp_ie = |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 4794 | kmemdup(cfg->extra_buf, conn_info->resp_ie_len, |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4795 | GFP_KERNEL); |
| 4796 | } else { |
| 4797 | conn_info->resp_ie_len = 0; |
| 4798 | conn_info->resp_ie = NULL; |
| 4799 | } |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 4800 | brcmf_dbg(CONN, "req len (%d) resp len (%d)\n", |
| 4801 | conn_info->req_ie_len, conn_info->resp_ie_len); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4802 | |
| 4803 | return err; |
| 4804 | } |
| 4805 | |
| 4806 | static s32 |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 4807 | brcmf_bss_roaming_done(struct brcmf_cfg80211_info *cfg, |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4808 | struct net_device *ndev, |
| 4809 | const struct brcmf_event_msg *e) |
| 4810 | { |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 4811 | struct brcmf_if *ifp = netdev_priv(ndev); |
| 4812 | struct brcmf_cfg80211_profile *profile = &ifp->vif->profile; |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 4813 | struct brcmf_cfg80211_connect_info *conn_info = cfg_to_conn(cfg); |
| 4814 | struct wiphy *wiphy = cfg_to_wiphy(cfg); |
Franky Lin | a180b83 | 2012-10-10 11:13:09 -0700 | [diff] [blame] | 4815 | struct ieee80211_channel *notify_channel = NULL; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4816 | struct ieee80211_supported_band *band; |
Franky Lin | a180b83 | 2012-10-10 11:13:09 -0700 | [diff] [blame] | 4817 | struct brcmf_bss_info_le *bi; |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 4818 | struct brcmu_chan ch; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4819 | u32 freq; |
| 4820 | s32 err = 0; |
Franky Lin | a180b83 | 2012-10-10 11:13:09 -0700 | [diff] [blame] | 4821 | u8 *buf; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4822 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 4823 | brcmf_dbg(TRACE, "Enter\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4824 | |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 4825 | brcmf_get_assoc_ies(cfg, ifp); |
Arend van Spriel | 6c8c4f7 | 2012-09-27 14:17:57 +0200 | [diff] [blame] | 4826 | memcpy(profile->bssid, e->addr, ETH_ALEN); |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 4827 | brcmf_update_bss_info(cfg, ifp); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4828 | |
Franky Lin | a180b83 | 2012-10-10 11:13:09 -0700 | [diff] [blame] | 4829 | buf = kzalloc(WL_BSS_INFO_MAX, GFP_KERNEL); |
| 4830 | if (buf == NULL) { |
| 4831 | err = -ENOMEM; |
| 4832 | goto done; |
| 4833 | } |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4834 | |
Franky Lin | a180b83 | 2012-10-10 11:13:09 -0700 | [diff] [blame] | 4835 | /* data sent to dongle has to be little endian */ |
| 4836 | *(__le32 *)buf = cpu_to_le32(WL_BSS_INFO_MAX); |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 4837 | 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] | 4838 | buf, WL_BSS_INFO_MAX); |
Franky Lin | a180b83 | 2012-10-10 11:13:09 -0700 | [diff] [blame] | 4839 | |
| 4840 | if (err) |
| 4841 | goto done; |
| 4842 | |
| 4843 | bi = (struct brcmf_bss_info_le *)(buf + 4); |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 4844 | ch.chspec = le16_to_cpu(bi->chanspec); |
| 4845 | cfg->d11inf.decchspec(&ch); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4846 | |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 4847 | if (ch.band == BRCMU_CHAN_BAND_2G) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4848 | band = wiphy->bands[IEEE80211_BAND_2GHZ]; |
| 4849 | else |
| 4850 | band = wiphy->bands[IEEE80211_BAND_5GHZ]; |
| 4851 | |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 4852 | freq = ieee80211_channel_to_frequency(ch.chnum, band->band); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4853 | notify_channel = ieee80211_get_channel(wiphy, freq); |
| 4854 | |
Franky Lin | a180b83 | 2012-10-10 11:13:09 -0700 | [diff] [blame] | 4855 | done: |
| 4856 | kfree(buf); |
Arend van Spriel | 06bb123 | 2012-09-27 14:17:56 +0200 | [diff] [blame] | 4857 | cfg80211_roamed(ndev, notify_channel, (u8 *)profile->bssid, |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4858 | conn_info->req_ie, conn_info->req_ie_len, |
| 4859 | conn_info->resp_ie, conn_info->resp_ie_len, GFP_KERNEL); |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 4860 | brcmf_dbg(CONN, "Report roaming result\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4861 | |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 4862 | set_bit(BRCMF_VIF_STATUS_CONNECTED, &ifp->vif->sme_state); |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 4863 | brcmf_dbg(TRACE, "Exit\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4864 | return err; |
| 4865 | } |
| 4866 | |
| 4867 | static s32 |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 4868 | brcmf_bss_connect_done(struct brcmf_cfg80211_info *cfg, |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4869 | struct net_device *ndev, const struct brcmf_event_msg *e, |
| 4870 | bool completed) |
| 4871 | { |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 4872 | struct brcmf_if *ifp = netdev_priv(ndev); |
| 4873 | struct brcmf_cfg80211_profile *profile = &ifp->vif->profile; |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 4874 | struct brcmf_cfg80211_connect_info *conn_info = cfg_to_conn(cfg); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4875 | |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 4876 | brcmf_dbg(TRACE, "Enter\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4877 | |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 4878 | if (test_and_clear_bit(BRCMF_VIF_STATUS_CONNECTING, |
| 4879 | &ifp->vif->sme_state)) { |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4880 | if (completed) { |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 4881 | brcmf_get_assoc_ies(cfg, ifp); |
Arend van Spriel | 6c8c4f7 | 2012-09-27 14:17:57 +0200 | [diff] [blame] | 4882 | memcpy(profile->bssid, e->addr, ETH_ALEN); |
Hante Meuleman | 89286dc | 2013-02-08 15:53:46 +0100 | [diff] [blame] | 4883 | brcmf_update_bss_info(cfg, ifp); |
| 4884 | set_bit(BRCMF_VIF_STATUS_CONNECTED, |
| 4885 | &ifp->vif->sme_state); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4886 | } |
| 4887 | cfg80211_connect_result(ndev, |
Arend van Spriel | 06bb123 | 2012-09-27 14:17:56 +0200 | [diff] [blame] | 4888 | (u8 *)profile->bssid, |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4889 | conn_info->req_ie, |
| 4890 | conn_info->req_ie_len, |
| 4891 | conn_info->resp_ie, |
| 4892 | conn_info->resp_ie_len, |
| 4893 | completed ? WLAN_STATUS_SUCCESS : |
| 4894 | WLAN_STATUS_AUTH_TIMEOUT, |
| 4895 | GFP_KERNEL); |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 4896 | brcmf_dbg(CONN, "Report connect result - connection %s\n", |
| 4897 | completed ? "succeeded" : "failed"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4898 | } |
Arend van Spriel | d96b801 | 2012-12-05 15:26:02 +0100 | [diff] [blame] | 4899 | brcmf_dbg(TRACE, "Exit\n"); |
Peter Senna Tschudin | 12f3237 | 2014-05-31 10:14:06 -0300 | [diff] [blame] | 4900 | return 0; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4901 | } |
| 4902 | |
| 4903 | static s32 |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 4904 | brcmf_notify_connect_status_ap(struct brcmf_cfg80211_info *cfg, |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4905 | struct net_device *ndev, |
| 4906 | const struct brcmf_event_msg *e, void *data) |
| 4907 | { |
Hante Meuleman | a44aa40 | 2014-12-03 21:05:33 +0100 | [diff] [blame] | 4908 | struct brcmf_if *ifp = netdev_priv(ndev); |
Hante Meuleman | 7ee2960 | 2013-02-06 18:40:43 +0100 | [diff] [blame] | 4909 | static int generation; |
Arend van Spriel | 5c36b99 | 2012-11-14 18:46:05 -0800 | [diff] [blame] | 4910 | u32 event = e->event_code; |
| 4911 | u32 reason = e->reason; |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4912 | struct station_info sinfo; |
| 4913 | |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 4914 | brcmf_dbg(CONN, "event %d, reason %d\n", event, reason); |
Arend van Spriel | 5f4f9f1 | 2013-02-08 15:53:41 +0100 | [diff] [blame] | 4915 | if (event == BRCMF_E_LINK && reason == BRCMF_E_REASON_LINK_BSSCFG_DIS && |
| 4916 | ndev != cfg_to_ndev(cfg)) { |
| 4917 | brcmf_dbg(CONN, "AP mode link down\n"); |
| 4918 | complete(&cfg->vif_disabled); |
Hante Meuleman | a44aa40 | 2014-12-03 21:05:33 +0100 | [diff] [blame] | 4919 | if (ifp->vif->mbss) |
| 4920 | brcmf_remove_interface(ifp->drvr, ifp->bssidx); |
Arend van Spriel | 5f4f9f1 | 2013-02-08 15:53:41 +0100 | [diff] [blame] | 4921 | return 0; |
| 4922 | } |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4923 | |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4924 | if (((event == BRCMF_E_ASSOC_IND) || (event == BRCMF_E_REASSOC_IND)) && |
Hante Meuleman | 7ee2960 | 2013-02-06 18:40:43 +0100 | [diff] [blame] | 4925 | (reason == BRCMF_E_STATUS_SUCCESS)) { |
| 4926 | memset(&sinfo, 0, sizeof(sinfo)); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4927 | if (!data) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 4928 | brcmf_err("No IEs present in ASSOC/REASSOC_IND"); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4929 | return -EINVAL; |
| 4930 | } |
| 4931 | sinfo.assoc_req_ies = data; |
Hante Meuleman | 7ee2960 | 2013-02-06 18:40:43 +0100 | [diff] [blame] | 4932 | sinfo.assoc_req_ies_len = e->datalen; |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4933 | generation++; |
| 4934 | sinfo.generation = generation; |
Hante Meuleman | 7ee2960 | 2013-02-06 18:40:43 +0100 | [diff] [blame] | 4935 | cfg80211_new_sta(ndev, e->addr, &sinfo, GFP_KERNEL); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4936 | } else if ((event == BRCMF_E_DISASSOC_IND) || |
| 4937 | (event == BRCMF_E_DEAUTH_IND) || |
| 4938 | (event == BRCMF_E_DEAUTH)) { |
Hante Meuleman | 7ee2960 | 2013-02-06 18:40:43 +0100 | [diff] [blame] | 4939 | cfg80211_del_sta(ndev, e->addr, GFP_KERNEL); |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4940 | } |
Hante Meuleman | 7ee2960 | 2013-02-06 18:40:43 +0100 | [diff] [blame] | 4941 | return 0; |
Hante Meuleman | 1a87334 | 2012-09-27 14:17:54 +0200 | [diff] [blame] | 4942 | } |
| 4943 | |
| 4944 | static s32 |
Arend van Spriel | 1993732 | 2012-11-05 16:22:32 -0800 | [diff] [blame] | 4945 | brcmf_notify_connect_status(struct brcmf_if *ifp, |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4946 | const struct brcmf_event_msg *e, void *data) |
| 4947 | { |
Arend van Spriel | 1993732 | 2012-11-05 16:22:32 -0800 | [diff] [blame] | 4948 | struct brcmf_cfg80211_info *cfg = ifp->drvr->config; |
| 4949 | struct net_device *ndev = ifp->ndev; |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 4950 | struct brcmf_cfg80211_profile *profile = &ifp->vif->profile; |
Antonio Quartulli | fe94f3a | 2014-01-29 17:53:43 +0100 | [diff] [blame] | 4951 | struct ieee80211_channel *chan; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4952 | s32 err = 0; |
| 4953 | |
Hante Meuleman | 8851cce | 2014-07-30 13:20:02 +0200 | [diff] [blame] | 4954 | if ((e->event_code == BRCMF_E_DEAUTH) || |
| 4955 | (e->event_code == BRCMF_E_DEAUTH_IND) || |
| 4956 | (e->event_code == BRCMF_E_DISASSOC_IND) || |
| 4957 | ((e->event_code == BRCMF_E_LINK) && (!e->flags))) { |
| 4958 | brcmf_proto_delete_peer(ifp->drvr, ifp->ifidx, (u8 *)e->addr); |
| 4959 | } |
| 4960 | |
Arend van Spriel | 967fe2c | 2014-03-15 17:18:21 +0100 | [diff] [blame] | 4961 | if (brcmf_is_apmode(ifp->vif)) { |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 4962 | err = brcmf_notify_connect_status_ap(cfg, ndev, e, data); |
Arend van Spriel | 903e0ee | 2012-11-28 21:44:11 +0100 | [diff] [blame] | 4963 | } else if (brcmf_is_linkup(e)) { |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 4964 | brcmf_dbg(CONN, "Linkup\n"); |
Arend van Spriel | 128ce3b | 2012-11-28 21:44:12 +0100 | [diff] [blame] | 4965 | if (brcmf_is_ibssmode(ifp->vif)) { |
Antonio Quartulli | fe94f3a | 2014-01-29 17:53:43 +0100 | [diff] [blame] | 4966 | chan = ieee80211_get_channel(cfg->wiphy, cfg->channel); |
Arend van Spriel | 6c8c4f7 | 2012-09-27 14:17:57 +0200 | [diff] [blame] | 4967 | memcpy(profile->bssid, e->addr, ETH_ALEN); |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 4968 | wl_inform_ibss(cfg, ndev, e->addr); |
Antonio Quartulli | fe94f3a | 2014-01-29 17:53:43 +0100 | [diff] [blame] | 4969 | cfg80211_ibss_joined(ndev, e->addr, chan, GFP_KERNEL); |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 4970 | clear_bit(BRCMF_VIF_STATUS_CONNECTING, |
| 4971 | &ifp->vif->sme_state); |
| 4972 | set_bit(BRCMF_VIF_STATUS_CONNECTED, |
| 4973 | &ifp->vif->sme_state); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4974 | } else |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 4975 | brcmf_bss_connect_done(cfg, ndev, e, true); |
Arend van Spriel | 903e0ee | 2012-11-28 21:44:11 +0100 | [diff] [blame] | 4976 | } else if (brcmf_is_linkdown(e)) { |
Arend van Spriel | 1688673 | 2012-12-05 15:26:04 +0100 | [diff] [blame] | 4977 | brcmf_dbg(CONN, "Linkdown\n"); |
Arend van Spriel | 128ce3b | 2012-11-28 21:44:12 +0100 | [diff] [blame] | 4978 | if (!brcmf_is_ibssmode(ifp->vif)) { |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 4979 | brcmf_bss_connect_done(cfg, ndev, e, false); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4980 | } |
Arend van Spriel | 9b7a0dd | 2015-01-25 20:31:33 +0100 | [diff] [blame] | 4981 | brcmf_link_down(ifp->vif, brcmf_map_fw_linkdown_reason(e)); |
Arend van Spriel | 6ac4f4e | 2012-10-22 13:55:31 -0700 | [diff] [blame] | 4982 | brcmf_init_prof(ndev_to_prof(ndev)); |
Arend van Spriel | 5f4f9f1 | 2013-02-08 15:53:41 +0100 | [diff] [blame] | 4983 | if (ndev != cfg_to_ndev(cfg)) |
| 4984 | complete(&cfg->vif_disabled); |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 4985 | } else if (brcmf_is_nonetwork(cfg, e)) { |
Arend van Spriel | 128ce3b | 2012-11-28 21:44:12 +0100 | [diff] [blame] | 4986 | if (brcmf_is_ibssmode(ifp->vif)) |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 4987 | clear_bit(BRCMF_VIF_STATUS_CONNECTING, |
| 4988 | &ifp->vif->sme_state); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4989 | else |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 4990 | brcmf_bss_connect_done(cfg, ndev, e, false); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4991 | } |
| 4992 | |
| 4993 | return err; |
| 4994 | } |
| 4995 | |
| 4996 | static s32 |
Arend van Spriel | 1993732 | 2012-11-05 16:22:32 -0800 | [diff] [blame] | 4997 | brcmf_notify_roaming_status(struct brcmf_if *ifp, |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 4998 | const struct brcmf_event_msg *e, void *data) |
| 4999 | { |
Arend van Spriel | 1993732 | 2012-11-05 16:22:32 -0800 | [diff] [blame] | 5000 | struct brcmf_cfg80211_info *cfg = ifp->drvr->config; |
Arend van Spriel | 5c36b99 | 2012-11-14 18:46:05 -0800 | [diff] [blame] | 5001 | u32 event = e->event_code; |
| 5002 | u32 status = e->status; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5003 | |
| 5004 | if (event == BRCMF_E_ROAM && status == BRCMF_E_STATUS_SUCCESS) { |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 5005 | if (test_bit(BRCMF_VIF_STATUS_CONNECTED, &ifp->vif->sme_state)) |
Arend van Spriel | 1993732 | 2012-11-05 16:22:32 -0800 | [diff] [blame] | 5006 | brcmf_bss_roaming_done(cfg, ifp->ndev, e); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5007 | else |
Arend van Spriel | 1993732 | 2012-11-05 16:22:32 -0800 | [diff] [blame] | 5008 | brcmf_bss_connect_done(cfg, ifp->ndev, e, true); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5009 | } |
| 5010 | |
Peter Senna Tschudin | 12f3237 | 2014-05-31 10:14:06 -0300 | [diff] [blame] | 5011 | return 0; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5012 | } |
| 5013 | |
| 5014 | static s32 |
Arend van Spriel | 1993732 | 2012-11-05 16:22:32 -0800 | [diff] [blame] | 5015 | brcmf_notify_mic_status(struct brcmf_if *ifp, |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5016 | const struct brcmf_event_msg *e, void *data) |
| 5017 | { |
Arend van Spriel | 5c36b99 | 2012-11-14 18:46:05 -0800 | [diff] [blame] | 5018 | u16 flags = e->flags; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5019 | enum nl80211_key_type key_type; |
| 5020 | |
| 5021 | if (flags & BRCMF_EVENT_MSG_GROUP) |
| 5022 | key_type = NL80211_KEYTYPE_GROUP; |
| 5023 | else |
| 5024 | key_type = NL80211_KEYTYPE_PAIRWISE; |
| 5025 | |
Arend van Spriel | 1993732 | 2012-11-05 16:22:32 -0800 | [diff] [blame] | 5026 | 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] | 5027 | NULL, GFP_KERNEL); |
| 5028 | |
| 5029 | return 0; |
| 5030 | } |
| 5031 | |
Arend van Spriel | d3c0b63 | 2013-02-08 15:53:37 +0100 | [diff] [blame] | 5032 | static s32 brcmf_notify_vif_event(struct brcmf_if *ifp, |
| 5033 | const struct brcmf_event_msg *e, void *data) |
| 5034 | { |
| 5035 | struct brcmf_cfg80211_info *cfg = ifp->drvr->config; |
| 5036 | struct brcmf_if_event *ifevent = (struct brcmf_if_event *)data; |
| 5037 | struct brcmf_cfg80211_vif_event *event = &cfg->vif_event; |
| 5038 | struct brcmf_cfg80211_vif *vif; |
| 5039 | |
| 5040 | brcmf_dbg(TRACE, "Enter: action %u flags %u ifidx %u bsscfg %u\n", |
| 5041 | ifevent->action, ifevent->flags, ifevent->ifidx, |
| 5042 | ifevent->bssidx); |
| 5043 | |
Arend van Spriel | d3c0b63 | 2013-02-08 15:53:37 +0100 | [diff] [blame] | 5044 | mutex_lock(&event->vif_event_lock); |
| 5045 | event->action = ifevent->action; |
| 5046 | vif = event->vif; |
| 5047 | |
| 5048 | switch (ifevent->action) { |
| 5049 | case BRCMF_E_IF_ADD: |
| 5050 | /* waiting process may have timed out */ |
Wei Yongjun | dc4a787 | 2013-02-22 21:32:20 +0800 | [diff] [blame] | 5051 | if (!cfg->vif_event.vif) { |
| 5052 | mutex_unlock(&event->vif_event_lock); |
Arend van Spriel | d3c0b63 | 2013-02-08 15:53:37 +0100 | [diff] [blame] | 5053 | return -EBADF; |
Wei Yongjun | dc4a787 | 2013-02-22 21:32:20 +0800 | [diff] [blame] | 5054 | } |
Arend van Spriel | d3c0b63 | 2013-02-08 15:53:37 +0100 | [diff] [blame] | 5055 | |
| 5056 | ifp->vif = vif; |
| 5057 | vif->ifp = ifp; |
Arend van Spriel | 01b8e7d | 2013-04-05 10:57:51 +0200 | [diff] [blame] | 5058 | if (ifp->ndev) { |
| 5059 | vif->wdev.netdev = ifp->ndev; |
| 5060 | ifp->ndev->ieee80211_ptr = &vif->wdev; |
| 5061 | SET_NETDEV_DEV(ifp->ndev, wiphy_dev(cfg->wiphy)); |
| 5062 | } |
Arend van Spriel | d3c0b63 | 2013-02-08 15:53:37 +0100 | [diff] [blame] | 5063 | mutex_unlock(&event->vif_event_lock); |
| 5064 | wake_up(&event->vif_wq); |
Hante Meuleman | 4b3a89d | 2013-02-08 15:54:01 +0100 | [diff] [blame] | 5065 | return 0; |
Arend van Spriel | d3c0b63 | 2013-02-08 15:53:37 +0100 | [diff] [blame] | 5066 | |
| 5067 | case BRCMF_E_IF_DEL: |
Arend van Spriel | d3c0b63 | 2013-02-08 15:53:37 +0100 | [diff] [blame] | 5068 | mutex_unlock(&event->vif_event_lock); |
| 5069 | /* event may not be upon user request */ |
| 5070 | if (brcmf_cfg80211_vif_event_armed(cfg)) |
| 5071 | wake_up(&event->vif_wq); |
| 5072 | return 0; |
| 5073 | |
Hante Meuleman | 7a5c1f6 | 2013-02-08 15:53:44 +0100 | [diff] [blame] | 5074 | case BRCMF_E_IF_CHANGE: |
| 5075 | mutex_unlock(&event->vif_event_lock); |
| 5076 | wake_up(&event->vif_wq); |
| 5077 | return 0; |
| 5078 | |
Arend van Spriel | d3c0b63 | 2013-02-08 15:53:37 +0100 | [diff] [blame] | 5079 | default: |
| 5080 | mutex_unlock(&event->vif_event_lock); |
| 5081 | break; |
| 5082 | } |
| 5083 | return -EINVAL; |
| 5084 | } |
| 5085 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5086 | static void brcmf_init_conf(struct brcmf_cfg80211_conf *conf) |
| 5087 | { |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5088 | conf->frag_threshold = (u32)-1; |
| 5089 | conf->rts_threshold = (u32)-1; |
| 5090 | conf->retry_short = (u32)-1; |
| 5091 | conf->retry_long = (u32)-1; |
| 5092 | conf->tx_power = -1; |
| 5093 | } |
| 5094 | |
Arend van Spriel | 5c36b99 | 2012-11-14 18:46:05 -0800 | [diff] [blame] | 5095 | static void brcmf_register_event_handlers(struct brcmf_cfg80211_info *cfg) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5096 | { |
Arend van Spriel | 5c36b99 | 2012-11-14 18:46:05 -0800 | [diff] [blame] | 5097 | brcmf_fweh_register(cfg->pub, BRCMF_E_LINK, |
| 5098 | brcmf_notify_connect_status); |
| 5099 | brcmf_fweh_register(cfg->pub, BRCMF_E_DEAUTH_IND, |
| 5100 | brcmf_notify_connect_status); |
| 5101 | brcmf_fweh_register(cfg->pub, BRCMF_E_DEAUTH, |
| 5102 | brcmf_notify_connect_status); |
| 5103 | brcmf_fweh_register(cfg->pub, BRCMF_E_DISASSOC_IND, |
| 5104 | brcmf_notify_connect_status); |
| 5105 | brcmf_fweh_register(cfg->pub, BRCMF_E_ASSOC_IND, |
| 5106 | brcmf_notify_connect_status); |
| 5107 | brcmf_fweh_register(cfg->pub, BRCMF_E_REASSOC_IND, |
| 5108 | brcmf_notify_connect_status); |
| 5109 | brcmf_fweh_register(cfg->pub, BRCMF_E_ROAM, |
| 5110 | brcmf_notify_roaming_status); |
| 5111 | brcmf_fweh_register(cfg->pub, BRCMF_E_MIC_ERROR, |
| 5112 | brcmf_notify_mic_status); |
| 5113 | brcmf_fweh_register(cfg->pub, BRCMF_E_SET_SSID, |
| 5114 | brcmf_notify_connect_status); |
| 5115 | brcmf_fweh_register(cfg->pub, BRCMF_E_PFN_NET_FOUND, |
| 5116 | brcmf_notify_sched_scan_results); |
Arend van Spriel | d3c0b63 | 2013-02-08 15:53:37 +0100 | [diff] [blame] | 5117 | brcmf_fweh_register(cfg->pub, BRCMF_E_IF, |
| 5118 | brcmf_notify_vif_event); |
Hante Meuleman | 0de8aac | 2013-02-08 15:53:38 +0100 | [diff] [blame] | 5119 | brcmf_fweh_register(cfg->pub, BRCMF_E_P2P_PROBEREQ_MSG, |
Hante Meuleman | 6eda4e2 | 2013-02-08 15:54:02 +0100 | [diff] [blame] | 5120 | brcmf_p2p_notify_rx_mgmt_p2p_probereq); |
Hante Meuleman | 0de8aac | 2013-02-08 15:53:38 +0100 | [diff] [blame] | 5121 | brcmf_fweh_register(cfg->pub, BRCMF_E_P2P_DISC_LISTEN_COMPLETE, |
| 5122 | brcmf_p2p_notify_listen_complete); |
Hante Meuleman | e6da340 | 2013-02-08 15:53:48 +0100 | [diff] [blame] | 5123 | brcmf_fweh_register(cfg->pub, BRCMF_E_ACTION_FRAME_RX, |
| 5124 | brcmf_p2p_notify_action_frame_rx); |
Hante Meuleman | 18e2f61 | 2013-02-08 15:53:49 +0100 | [diff] [blame] | 5125 | brcmf_fweh_register(cfg->pub, BRCMF_E_ACTION_FRAME_COMPLETE, |
| 5126 | brcmf_p2p_notify_action_tx_complete); |
Hante Meuleman | 6eda4e2 | 2013-02-08 15:54:02 +0100 | [diff] [blame] | 5127 | brcmf_fweh_register(cfg->pub, BRCMF_E_ACTION_FRAME_OFF_CHAN_COMPLETE, |
| 5128 | brcmf_p2p_notify_action_tx_complete); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5129 | } |
| 5130 | |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5131 | static void brcmf_deinit_priv_mem(struct brcmf_cfg80211_info *cfg) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5132 | { |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5133 | kfree(cfg->conf); |
| 5134 | cfg->conf = NULL; |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5135 | kfree(cfg->escan_ioctl_buf); |
| 5136 | cfg->escan_ioctl_buf = NULL; |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5137 | kfree(cfg->extra_buf); |
| 5138 | cfg->extra_buf = NULL; |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5139 | kfree(cfg->pmk_list); |
| 5140 | cfg->pmk_list = NULL; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5141 | } |
| 5142 | |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5143 | static s32 brcmf_init_priv_mem(struct brcmf_cfg80211_info *cfg) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5144 | { |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5145 | cfg->conf = kzalloc(sizeof(*cfg->conf), GFP_KERNEL); |
| 5146 | if (!cfg->conf) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5147 | goto init_priv_mem_out; |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5148 | cfg->escan_ioctl_buf = kzalloc(BRCMF_DCMD_MEDLEN, GFP_KERNEL); |
| 5149 | if (!cfg->escan_ioctl_buf) |
Hante Meuleman | e756af5 | 2012-09-11 21:18:52 +0200 | [diff] [blame] | 5150 | goto init_priv_mem_out; |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5151 | cfg->extra_buf = kzalloc(WL_EXTRA_BUF_MAX, GFP_KERNEL); |
| 5152 | if (!cfg->extra_buf) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5153 | goto init_priv_mem_out; |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5154 | cfg->pmk_list = kzalloc(sizeof(*cfg->pmk_list), GFP_KERNEL); |
| 5155 | if (!cfg->pmk_list) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5156 | goto init_priv_mem_out; |
| 5157 | |
| 5158 | return 0; |
| 5159 | |
| 5160 | init_priv_mem_out: |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5161 | brcmf_deinit_priv_mem(cfg); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5162 | |
| 5163 | return -ENOMEM; |
| 5164 | } |
| 5165 | |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5166 | static s32 wl_init_priv(struct brcmf_cfg80211_info *cfg) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5167 | { |
| 5168 | s32 err = 0; |
| 5169 | |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5170 | cfg->scan_request = NULL; |
| 5171 | cfg->pwr_save = true; |
Hante Meuleman | 68ca395 | 2014-02-25 20:30:26 +0100 | [diff] [blame] | 5172 | cfg->active_scan = true; /* we do active scan per default */ |
| 5173 | cfg->dongle_up = false; /* dongle is not up yet */ |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5174 | err = brcmf_init_priv_mem(cfg); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5175 | if (err) |
| 5176 | return err; |
Arend van Spriel | 5c36b99 | 2012-11-14 18:46:05 -0800 | [diff] [blame] | 5177 | brcmf_register_event_handlers(cfg); |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5178 | mutex_init(&cfg->usr_sync); |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5179 | brcmf_init_escan(cfg); |
| 5180 | brcmf_init_conf(cfg->conf); |
Arend van Spriel | 5f4f9f1 | 2013-02-08 15:53:41 +0100 | [diff] [blame] | 5181 | init_completion(&cfg->vif_disabled); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5182 | return err; |
| 5183 | } |
| 5184 | |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5185 | static void wl_deinit_priv(struct brcmf_cfg80211_info *cfg) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5186 | { |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5187 | cfg->dongle_up = false; /* dongle down */ |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5188 | brcmf_abort_scanning(cfg); |
| 5189 | brcmf_deinit_priv_mem(cfg); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5190 | } |
| 5191 | |
Arend van Spriel | d3c0b63 | 2013-02-08 15:53:37 +0100 | [diff] [blame] | 5192 | static void init_vif_event(struct brcmf_cfg80211_vif_event *event) |
| 5193 | { |
| 5194 | init_waitqueue_head(&event->vif_wq); |
Arend van Spriel | d3c0b63 | 2013-02-08 15:53:37 +0100 | [diff] [blame] | 5195 | mutex_init(&event->vif_event_lock); |
| 5196 | } |
| 5197 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5198 | static s32 |
Hante Meuleman | 68ca395 | 2014-02-25 20:30:26 +0100 | [diff] [blame] | 5199 | brcmf_dongle_roam(struct brcmf_if *ifp, u32 bcn_timeout) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5200 | { |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5201 | s32 err = 0; |
Arend van Spriel | f588bc0 | 2011-10-12 20:51:22 +0200 | [diff] [blame] | 5202 | __le32 roamtrigger[2]; |
| 5203 | __le32 roam_delta[2]; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5204 | |
| 5205 | /* |
| 5206 | * Setup timeout if Beacons are lost and roam is |
| 5207 | * off to report link down |
| 5208 | */ |
Hante Meuleman | 68ca395 | 2014-02-25 20:30:26 +0100 | [diff] [blame] | 5209 | if (brcmf_roamoff) { |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 5210 | err = brcmf_fil_iovar_int_set(ifp, "bcn_timeout", bcn_timeout); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5211 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 5212 | brcmf_err("bcn_timeout error (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5213 | goto dongle_rom_out; |
| 5214 | } |
| 5215 | } |
| 5216 | |
| 5217 | /* |
| 5218 | * Enable/Disable built-in roaming to allow supplicant |
| 5219 | * to take care of roaming |
| 5220 | */ |
Hante Meuleman | 68ca395 | 2014-02-25 20:30:26 +0100 | [diff] [blame] | 5221 | brcmf_dbg(INFO, "Internal Roaming = %s\n", |
| 5222 | brcmf_roamoff ? "Off" : "On"); |
| 5223 | err = brcmf_fil_iovar_int_set(ifp, "roam_off", !!(brcmf_roamoff)); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5224 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 5225 | brcmf_err("roam_off error (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5226 | goto dongle_rom_out; |
| 5227 | } |
| 5228 | |
Arend van Spriel | f588bc0 | 2011-10-12 20:51:22 +0200 | [diff] [blame] | 5229 | roamtrigger[0] = cpu_to_le32(WL_ROAM_TRIGGER_LEVEL); |
| 5230 | roamtrigger[1] = cpu_to_le32(BRCM_BAND_ALL); |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 5231 | err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SET_ROAM_TRIGGER, |
Hante Meuleman | 81f5dcb | 2012-10-22 10:36:14 -0700 | [diff] [blame] | 5232 | (void *)roamtrigger, sizeof(roamtrigger)); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5233 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 5234 | brcmf_err("WLC_SET_ROAM_TRIGGER error (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5235 | goto dongle_rom_out; |
| 5236 | } |
| 5237 | |
Arend van Spriel | f588bc0 | 2011-10-12 20:51:22 +0200 | [diff] [blame] | 5238 | roam_delta[0] = cpu_to_le32(WL_ROAM_DELTA); |
| 5239 | roam_delta[1] = cpu_to_le32(BRCM_BAND_ALL); |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 5240 | err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SET_ROAM_DELTA, |
Hante Meuleman | 81f5dcb | 2012-10-22 10:36:14 -0700 | [diff] [blame] | 5241 | (void *)roam_delta, sizeof(roam_delta)); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5242 | if (err) { |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 5243 | brcmf_err("WLC_SET_ROAM_DELTA error (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5244 | goto dongle_rom_out; |
| 5245 | } |
| 5246 | |
| 5247 | dongle_rom_out: |
| 5248 | return err; |
| 5249 | } |
| 5250 | |
| 5251 | static s32 |
Hante Meuleman | 40a2329 | 2013-01-02 15:22:51 +0100 | [diff] [blame] | 5252 | brcmf_dongle_scantime(struct brcmf_if *ifp, s32 scan_assoc_time, |
Arend van Spriel | c68cdc0 | 2011-10-12 20:51:23 +0200 | [diff] [blame] | 5253 | s32 scan_unassoc_time, s32 scan_passive_time) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5254 | { |
| 5255 | s32 err = 0; |
| 5256 | |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 5257 | 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] | 5258 | scan_assoc_time); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5259 | if (err) { |
| 5260 | if (err == -EOPNOTSUPP) |
Arend van Spriel | 647c9ae | 2012-12-05 15:26:01 +0100 | [diff] [blame] | 5261 | brcmf_dbg(INFO, "Scan assoc time is not supported\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5262 | else |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 5263 | brcmf_err("Scan assoc time error (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5264 | goto dongle_scantime_out; |
| 5265 | } |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 5266 | 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] | 5267 | scan_unassoc_time); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5268 | if (err) { |
| 5269 | if (err == -EOPNOTSUPP) |
Arend van Spriel | 647c9ae | 2012-12-05 15:26:01 +0100 | [diff] [blame] | 5270 | brcmf_dbg(INFO, "Scan unassoc time is not supported\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5271 | else |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 5272 | brcmf_err("Scan unassoc time error (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5273 | goto dongle_scantime_out; |
| 5274 | } |
| 5275 | |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 5276 | 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] | 5277 | scan_passive_time); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5278 | if (err) { |
| 5279 | if (err == -EOPNOTSUPP) |
Arend van Spriel | 647c9ae | 2012-12-05 15:26:01 +0100 | [diff] [blame] | 5280 | brcmf_dbg(INFO, "Scan passive time is not supported\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5281 | else |
Arend van Spriel | 57d6e91 | 2012-12-05 15:26:00 +0100 | [diff] [blame] | 5282 | brcmf_err("Scan passive time error (%d)\n", err); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5283 | goto dongle_scantime_out; |
| 5284 | } |
| 5285 | |
| 5286 | dongle_scantime_out: |
| 5287 | return err; |
| 5288 | } |
| 5289 | |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 5290 | static void brcmf_update_bw40_channel_flag(struct ieee80211_channel *channel, |
| 5291 | struct brcmu_chan *ch) |
| 5292 | { |
| 5293 | u32 ht40_flag; |
| 5294 | |
| 5295 | ht40_flag = channel->flags & IEEE80211_CHAN_NO_HT40; |
| 5296 | if (ch->sb == BRCMU_CHAN_SB_U) { |
| 5297 | if (ht40_flag == IEEE80211_CHAN_NO_HT40) |
| 5298 | channel->flags &= ~IEEE80211_CHAN_NO_HT40; |
| 5299 | channel->flags |= IEEE80211_CHAN_NO_HT40PLUS; |
| 5300 | } else { |
| 5301 | /* It should be one of |
| 5302 | * IEEE80211_CHAN_NO_HT40 or |
| 5303 | * IEEE80211_CHAN_NO_HT40PLUS |
| 5304 | */ |
| 5305 | channel->flags &= ~IEEE80211_CHAN_NO_HT40; |
| 5306 | if (ht40_flag == IEEE80211_CHAN_NO_HT40) |
| 5307 | channel->flags |= IEEE80211_CHAN_NO_HT40MINUS; |
| 5308 | } |
| 5309 | } |
| 5310 | |
| 5311 | static int brcmf_construct_chaninfo(struct brcmf_cfg80211_info *cfg, |
| 5312 | u32 bw_cap[]) |
Hante Meuleman | d48200b | 2013-04-03 12:40:29 +0200 | [diff] [blame] | 5313 | { |
| 5314 | struct brcmf_if *ifp = netdev_priv(cfg_to_ndev(cfg)); |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 5315 | struct ieee80211_supported_band *band; |
| 5316 | struct ieee80211_channel *channel; |
| 5317 | struct wiphy *wiphy; |
Hante Meuleman | d48200b | 2013-04-03 12:40:29 +0200 | [diff] [blame] | 5318 | struct brcmf_chanspec_list *list; |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 5319 | struct brcmu_chan ch; |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 5320 | int err; |
Hante Meuleman | d48200b | 2013-04-03 12:40:29 +0200 | [diff] [blame] | 5321 | u8 *pbuf; |
| 5322 | u32 i, j; |
| 5323 | u32 total; |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 5324 | u32 chaninfo; |
Hante Meuleman | d48200b | 2013-04-03 12:40:29 +0200 | [diff] [blame] | 5325 | u32 index; |
Hante Meuleman | d48200b | 2013-04-03 12:40:29 +0200 | [diff] [blame] | 5326 | |
| 5327 | pbuf = kzalloc(BRCMF_DCMD_MEDLEN, GFP_KERNEL); |
| 5328 | |
| 5329 | if (pbuf == NULL) |
| 5330 | return -ENOMEM; |
| 5331 | |
| 5332 | list = (struct brcmf_chanspec_list *)pbuf; |
| 5333 | |
| 5334 | err = brcmf_fil_iovar_data_get(ifp, "chanspecs", pbuf, |
| 5335 | BRCMF_DCMD_MEDLEN); |
| 5336 | if (err) { |
| 5337 | brcmf_err("get chanspecs error (%d)\n", err); |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 5338 | goto fail_pbuf; |
Hante Meuleman | d48200b | 2013-04-03 12:40:29 +0200 | [diff] [blame] | 5339 | } |
| 5340 | |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 5341 | wiphy = cfg_to_wiphy(cfg); |
Arend van Spriel | 58de92d | 2015-04-14 20:10:24 +0200 | [diff] [blame] | 5342 | band = wiphy->bands[IEEE80211_BAND_2GHZ]; |
| 5343 | if (band) |
| 5344 | for (i = 0; i < band->n_channels; i++) |
| 5345 | band->channels[i].flags = IEEE80211_CHAN_DISABLED; |
| 5346 | band = wiphy->bands[IEEE80211_BAND_5GHZ]; |
| 5347 | if (band) |
| 5348 | for (i = 0; i < band->n_channels; i++) |
| 5349 | band->channels[i].flags = IEEE80211_CHAN_DISABLED; |
Hante Meuleman | d48200b | 2013-04-03 12:40:29 +0200 | [diff] [blame] | 5350 | |
| 5351 | total = le32_to_cpu(list->count); |
| 5352 | for (i = 0; i < total; i++) { |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 5353 | ch.chspec = (u16)le32_to_cpu(list->element[i]); |
| 5354 | cfg->d11inf.decchspec(&ch); |
Hante Meuleman | d48200b | 2013-04-03 12:40:29 +0200 | [diff] [blame] | 5355 | |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 5356 | if (ch.band == BRCMU_CHAN_BAND_2G) { |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 5357 | band = wiphy->bands[IEEE80211_BAND_2GHZ]; |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 5358 | } else if (ch.band == BRCMU_CHAN_BAND_5G) { |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 5359 | band = wiphy->bands[IEEE80211_BAND_5GHZ]; |
Hante Meuleman | d48200b | 2013-04-03 12:40:29 +0200 | [diff] [blame] | 5360 | } else { |
Arend van Spriel | 2375d97 | 2014-01-06 12:40:41 +0100 | [diff] [blame] | 5361 | brcmf_err("Invalid channel Spec. 0x%x.\n", ch.chspec); |
Hante Meuleman | d48200b | 2013-04-03 12:40:29 +0200 | [diff] [blame] | 5362 | continue; |
| 5363 | } |
Arend van Spriel | 58de92d | 2015-04-14 20:10:24 +0200 | [diff] [blame] | 5364 | if (!band) |
| 5365 | continue; |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 5366 | if (!(bw_cap[band->band] & WLC_BW_40MHZ_BIT) && |
Arend van Spriel | 2375d97 | 2014-01-06 12:40:41 +0100 | [diff] [blame] | 5367 | ch.bw == BRCMU_CHAN_BW_40) |
Hante Meuleman | d48200b | 2013-04-03 12:40:29 +0200 | [diff] [blame] | 5368 | continue; |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 5369 | if (!(bw_cap[band->band] & WLC_BW_80MHZ_BIT) && |
Arend van Spriel | ee942ec | 2014-05-12 10:47:38 +0200 | [diff] [blame] | 5370 | ch.bw == BRCMU_CHAN_BW_80) |
| 5371 | continue; |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 5372 | |
| 5373 | channel = band->channels; |
| 5374 | index = band->n_channels; |
| 5375 | for (j = 0; j < band->n_channels; j++) { |
| 5376 | if (channel[j].hw_value == ch.chnum) { |
| 5377 | index = j; |
Hante Meuleman | d48200b | 2013-04-03 12:40:29 +0200 | [diff] [blame] | 5378 | break; |
| 5379 | } |
| 5380 | } |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 5381 | channel[index].center_freq = |
| 5382 | ieee80211_channel_to_frequency(ch.chnum, band->band); |
| 5383 | channel[index].hw_value = ch.chnum; |
Hante Meuleman | d48200b | 2013-04-03 12:40:29 +0200 | [diff] [blame] | 5384 | |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 5385 | /* assuming the chanspecs order is HT20, |
| 5386 | * HT40 upper, HT40 lower, and VHT80. |
| 5387 | */ |
| 5388 | if (ch.bw == BRCMU_CHAN_BW_80) { |
| 5389 | channel[index].flags &= ~IEEE80211_CHAN_NO_80MHZ; |
| 5390 | } else if (ch.bw == BRCMU_CHAN_BW_40) { |
| 5391 | brcmf_update_bw40_channel_flag(&channel[index], &ch); |
| 5392 | } else { |
Arend van Spriel | 58de92d | 2015-04-14 20:10:24 +0200 | [diff] [blame] | 5393 | /* enable the channel and disable other bandwidths |
| 5394 | * for now as mentioned order assure they are enabled |
| 5395 | * for subsequent chanspecs. |
Arend van Spriel | ee942ec | 2014-05-12 10:47:38 +0200 | [diff] [blame] | 5396 | */ |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 5397 | channel[index].flags = IEEE80211_CHAN_NO_HT40 | |
| 5398 | IEEE80211_CHAN_NO_80MHZ; |
| 5399 | ch.bw = BRCMU_CHAN_BW_20; |
| 5400 | cfg->d11inf.encchspec(&ch); |
| 5401 | chaninfo = ch.chspec; |
| 5402 | err = brcmf_fil_bsscfg_int_get(ifp, "per_chan_info", |
| 5403 | &chaninfo); |
| 5404 | if (!err) { |
| 5405 | if (chaninfo & WL_CHAN_RADAR) |
| 5406 | channel[index].flags |= |
| 5407 | (IEEE80211_CHAN_RADAR | |
| 5408 | IEEE80211_CHAN_NO_IR); |
| 5409 | if (chaninfo & WL_CHAN_PASSIVE) |
| 5410 | channel[index].flags |= |
| 5411 | IEEE80211_CHAN_NO_IR; |
Hante Meuleman | d48200b | 2013-04-03 12:40:29 +0200 | [diff] [blame] | 5412 | } |
Hante Meuleman | d48200b | 2013-04-03 12:40:29 +0200 | [diff] [blame] | 5413 | } |
| 5414 | } |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 5415 | |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 5416 | fail_pbuf: |
Hante Meuleman | d48200b | 2013-04-03 12:40:29 +0200 | [diff] [blame] | 5417 | kfree(pbuf); |
| 5418 | return err; |
| 5419 | } |
| 5420 | |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 5421 | static int brcmf_enable_bw40_2g(struct brcmf_cfg80211_info *cfg) |
Arend van Spriel | aa70b4f | 2014-07-12 08:49:40 +0200 | [diff] [blame] | 5422 | { |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 5423 | struct brcmf_if *ifp = netdev_priv(cfg_to_ndev(cfg)); |
| 5424 | struct ieee80211_supported_band *band; |
Arend van Spriel | aa70b4f | 2014-07-12 08:49:40 +0200 | [diff] [blame] | 5425 | struct brcmf_fil_bwcap_le band_bwcap; |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 5426 | struct brcmf_chanspec_list *list; |
| 5427 | u8 *pbuf; |
Arend van Spriel | aa70b4f | 2014-07-12 08:49:40 +0200 | [diff] [blame] | 5428 | u32 val; |
| 5429 | int err; |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 5430 | struct brcmu_chan ch; |
| 5431 | u32 num_chan; |
| 5432 | int i, j; |
Arend van Spriel | aa70b4f | 2014-07-12 08:49:40 +0200 | [diff] [blame] | 5433 | |
| 5434 | /* verify support for bw_cap command */ |
| 5435 | val = WLC_BAND_5G; |
| 5436 | err = brcmf_fil_iovar_int_get(ifp, "bw_cap", &val); |
| 5437 | |
| 5438 | if (!err) { |
| 5439 | /* only set 2G bandwidth using bw_cap command */ |
| 5440 | band_bwcap.band = cpu_to_le32(WLC_BAND_2G); |
| 5441 | band_bwcap.bw_cap = cpu_to_le32(WLC_BW_CAP_40MHZ); |
| 5442 | err = brcmf_fil_iovar_data_set(ifp, "bw_cap", &band_bwcap, |
| 5443 | sizeof(band_bwcap)); |
| 5444 | } else { |
| 5445 | brcmf_dbg(INFO, "fallback to mimo_bw_cap\n"); |
| 5446 | val = WLC_N_BW_40ALL; |
| 5447 | err = brcmf_fil_iovar_int_set(ifp, "mimo_bw_cap", val); |
| 5448 | } |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 5449 | |
| 5450 | if (!err) { |
| 5451 | /* update channel info in 2G band */ |
| 5452 | pbuf = kzalloc(BRCMF_DCMD_MEDLEN, GFP_KERNEL); |
| 5453 | |
| 5454 | if (pbuf == NULL) |
| 5455 | return -ENOMEM; |
| 5456 | |
| 5457 | ch.band = BRCMU_CHAN_BAND_2G; |
| 5458 | ch.bw = BRCMU_CHAN_BW_40; |
Hante Meuleman | fac7d2a | 2014-09-11 22:51:30 +0200 | [diff] [blame] | 5459 | ch.sb = BRCMU_CHAN_SB_NONE; |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 5460 | ch.chnum = 0; |
| 5461 | cfg->d11inf.encchspec(&ch); |
| 5462 | |
| 5463 | /* pass encoded chanspec in query */ |
| 5464 | *(__le16 *)pbuf = cpu_to_le16(ch.chspec); |
| 5465 | |
| 5466 | err = brcmf_fil_iovar_data_get(ifp, "chanspecs", pbuf, |
| 5467 | BRCMF_DCMD_MEDLEN); |
| 5468 | if (err) { |
| 5469 | brcmf_err("get chanspecs error (%d)\n", err); |
| 5470 | kfree(pbuf); |
| 5471 | return err; |
| 5472 | } |
| 5473 | |
| 5474 | band = cfg_to_wiphy(cfg)->bands[IEEE80211_BAND_2GHZ]; |
| 5475 | list = (struct brcmf_chanspec_list *)pbuf; |
| 5476 | num_chan = le32_to_cpu(list->count); |
| 5477 | for (i = 0; i < num_chan; i++) { |
| 5478 | ch.chspec = (u16)le32_to_cpu(list->element[i]); |
| 5479 | cfg->d11inf.decchspec(&ch); |
| 5480 | if (WARN_ON(ch.band != BRCMU_CHAN_BAND_2G)) |
| 5481 | continue; |
| 5482 | if (WARN_ON(ch.bw != BRCMU_CHAN_BW_40)) |
| 5483 | continue; |
| 5484 | for (j = 0; j < band->n_channels; j++) { |
| 5485 | if (band->channels[j].hw_value == ch.chnum) |
| 5486 | break; |
| 5487 | } |
| 5488 | if (WARN_ON(j == band->n_channels)) |
| 5489 | continue; |
| 5490 | |
| 5491 | brcmf_update_bw40_channel_flag(&band->channels[j], &ch); |
| 5492 | } |
Hante Meuleman | fac7d2a | 2014-09-11 22:51:30 +0200 | [diff] [blame] | 5493 | kfree(pbuf); |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 5494 | } |
Arend van Spriel | aa70b4f | 2014-07-12 08:49:40 +0200 | [diff] [blame] | 5495 | return err; |
| 5496 | } |
| 5497 | |
Arend van Spriel | 2375d97 | 2014-01-06 12:40:41 +0100 | [diff] [blame] | 5498 | static void brcmf_get_bwcap(struct brcmf_if *ifp, u32 bw_cap[]) |
| 5499 | { |
| 5500 | u32 band, mimo_bwcap; |
| 5501 | int err; |
| 5502 | |
| 5503 | band = WLC_BAND_2G; |
| 5504 | err = brcmf_fil_iovar_int_get(ifp, "bw_cap", &band); |
| 5505 | if (!err) { |
| 5506 | bw_cap[IEEE80211_BAND_2GHZ] = band; |
| 5507 | band = WLC_BAND_5G; |
| 5508 | err = brcmf_fil_iovar_int_get(ifp, "bw_cap", &band); |
| 5509 | if (!err) { |
| 5510 | bw_cap[IEEE80211_BAND_5GHZ] = band; |
| 5511 | return; |
| 5512 | } |
| 5513 | WARN_ON(1); |
| 5514 | return; |
| 5515 | } |
| 5516 | brcmf_dbg(INFO, "fallback to mimo_bw_cap info\n"); |
| 5517 | mimo_bwcap = 0; |
| 5518 | err = brcmf_fil_iovar_int_get(ifp, "mimo_bw_cap", &mimo_bwcap); |
| 5519 | if (err) |
| 5520 | /* assume 20MHz if firmware does not give a clue */ |
| 5521 | mimo_bwcap = WLC_N_BW_20ALL; |
| 5522 | |
| 5523 | switch (mimo_bwcap) { |
| 5524 | case WLC_N_BW_40ALL: |
| 5525 | bw_cap[IEEE80211_BAND_2GHZ] |= WLC_BW_40MHZ_BIT; |
| 5526 | /* fall-thru */ |
| 5527 | case WLC_N_BW_20IN2G_40IN5G: |
| 5528 | bw_cap[IEEE80211_BAND_5GHZ] |= WLC_BW_40MHZ_BIT; |
| 5529 | /* fall-thru */ |
| 5530 | case WLC_N_BW_20ALL: |
| 5531 | bw_cap[IEEE80211_BAND_2GHZ] |= WLC_BW_20MHZ_BIT; |
| 5532 | bw_cap[IEEE80211_BAND_5GHZ] |= WLC_BW_20MHZ_BIT; |
| 5533 | break; |
| 5534 | default: |
| 5535 | brcmf_err("invalid mimo_bw_cap value\n"); |
| 5536 | } |
| 5537 | } |
Hante Meuleman | d48200b | 2013-04-03 12:40:29 +0200 | [diff] [blame] | 5538 | |
Arend van Spriel | 18d6c53 | 2014-05-12 10:47:35 +0200 | [diff] [blame] | 5539 | static void brcmf_update_ht_cap(struct ieee80211_supported_band *band, |
| 5540 | u32 bw_cap[2], u32 nchain) |
| 5541 | { |
| 5542 | band->ht_cap.ht_supported = true; |
| 5543 | if (bw_cap[band->band] & WLC_BW_40MHZ_BIT) { |
| 5544 | band->ht_cap.cap |= IEEE80211_HT_CAP_SGI_40; |
| 5545 | band->ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40; |
| 5546 | } |
| 5547 | band->ht_cap.cap |= IEEE80211_HT_CAP_SGI_20; |
| 5548 | band->ht_cap.cap |= IEEE80211_HT_CAP_DSSSCCK40; |
| 5549 | band->ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K; |
| 5550 | band->ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_16; |
| 5551 | memset(band->ht_cap.mcs.rx_mask, 0xff, nchain); |
| 5552 | band->ht_cap.mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED; |
| 5553 | } |
| 5554 | |
| 5555 | static __le16 brcmf_get_mcs_map(u32 nchain, enum ieee80211_vht_mcs_support supp) |
| 5556 | { |
| 5557 | u16 mcs_map; |
| 5558 | int i; |
| 5559 | |
| 5560 | for (i = 0, mcs_map = 0xFFFF; i < nchain; i++) |
| 5561 | mcs_map = (mcs_map << 2) | supp; |
| 5562 | |
| 5563 | return cpu_to_le16(mcs_map); |
| 5564 | } |
| 5565 | |
| 5566 | static void brcmf_update_vht_cap(struct ieee80211_supported_band *band, |
| 5567 | u32 bw_cap[2], u32 nchain) |
| 5568 | { |
| 5569 | __le16 mcs_map; |
| 5570 | |
| 5571 | /* not allowed in 2.4G band */ |
| 5572 | if (band->band == IEEE80211_BAND_2GHZ) |
| 5573 | return; |
| 5574 | |
| 5575 | band->vht_cap.vht_supported = true; |
| 5576 | /* 80MHz is mandatory */ |
| 5577 | band->vht_cap.cap |= IEEE80211_VHT_CAP_SHORT_GI_80; |
| 5578 | if (bw_cap[band->band] & WLC_BW_160MHZ_BIT) { |
| 5579 | band->vht_cap.cap |= IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ; |
| 5580 | band->vht_cap.cap |= IEEE80211_VHT_CAP_SHORT_GI_160; |
| 5581 | } |
| 5582 | /* all support 256-QAM */ |
| 5583 | mcs_map = brcmf_get_mcs_map(nchain, IEEE80211_VHT_MCS_SUPPORT_0_9); |
| 5584 | band->vht_cap.vht_mcs.rx_mcs_map = mcs_map; |
| 5585 | band->vht_cap.vht_mcs.tx_mcs_map = mcs_map; |
| 5586 | } |
| 5587 | |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 5588 | static int brcmf_setup_wiphybands(struct wiphy *wiphy) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5589 | { |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 5590 | struct brcmf_cfg80211_info *cfg = wiphy_priv(wiphy); |
Arend van Spriel | ac24be6 | 2012-10-22 10:36:23 -0700 | [diff] [blame] | 5591 | struct brcmf_if *ifp = netdev_priv(cfg_to_ndev(cfg)); |
Arend van Spriel | 18d6c53 | 2014-05-12 10:47:35 +0200 | [diff] [blame] | 5592 | u32 nmode = 0; |
| 5593 | u32 vhtmode = 0; |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 5594 | u32 bw_cap[2] = { WLC_BW_20MHZ_BIT, WLC_BW_20MHZ_BIT }; |
Daniel Kim | 4aca7a1 | 2014-02-25 20:30:36 +0100 | [diff] [blame] | 5595 | u32 rxchain; |
| 5596 | u32 nchain; |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 5597 | int err; |
Hante Meuleman | d48200b | 2013-04-03 12:40:29 +0200 | [diff] [blame] | 5598 | s32 i; |
Arend van Spriel | 2375d97 | 2014-01-06 12:40:41 +0100 | [diff] [blame] | 5599 | struct ieee80211_supported_band *band; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5600 | |
Arend van Spriel | 18d6c53 | 2014-05-12 10:47:35 +0200 | [diff] [blame] | 5601 | (void)brcmf_fil_iovar_int_get(ifp, "vhtmode", &vhtmode); |
Hante Meuleman | d48200b | 2013-04-03 12:40:29 +0200 | [diff] [blame] | 5602 | err = brcmf_fil_iovar_int_get(ifp, "nmode", &nmode); |
| 5603 | if (err) { |
| 5604 | brcmf_err("nmode error (%d)\n", err); |
| 5605 | } else { |
Arend van Spriel | 2375d97 | 2014-01-06 12:40:41 +0100 | [diff] [blame] | 5606 | brcmf_get_bwcap(ifp, bw_cap); |
Hante Meuleman | d48200b | 2013-04-03 12:40:29 +0200 | [diff] [blame] | 5607 | } |
Arend van Spriel | 18d6c53 | 2014-05-12 10:47:35 +0200 | [diff] [blame] | 5608 | brcmf_dbg(INFO, "nmode=%d, vhtmode=%d, bw_cap=(%d, %d)\n", |
| 5609 | nmode, vhtmode, bw_cap[IEEE80211_BAND_2GHZ], |
| 5610 | bw_cap[IEEE80211_BAND_5GHZ]); |
Hante Meuleman | d48200b | 2013-04-03 12:40:29 +0200 | [diff] [blame] | 5611 | |
Daniel Kim | 4aca7a1 | 2014-02-25 20:30:36 +0100 | [diff] [blame] | 5612 | err = brcmf_fil_iovar_int_get(ifp, "rxchain", &rxchain); |
| 5613 | if (err) { |
| 5614 | brcmf_err("rxchain error (%d)\n", err); |
| 5615 | nchain = 1; |
| 5616 | } else { |
| 5617 | for (nchain = 0; rxchain; nchain++) |
| 5618 | rxchain = rxchain & (rxchain - 1); |
| 5619 | } |
| 5620 | brcmf_dbg(INFO, "nchain=%d\n", nchain); |
| 5621 | |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 5622 | err = brcmf_construct_chaninfo(cfg, bw_cap); |
Hante Meuleman | d48200b | 2013-04-03 12:40:29 +0200 | [diff] [blame] | 5623 | if (err) { |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 5624 | brcmf_err("brcmf_construct_chaninfo failed (%d)\n", err); |
Hante Meuleman | d48200b | 2013-04-03 12:40:29 +0200 | [diff] [blame] | 5625 | return err; |
| 5626 | } |
| 5627 | |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 5628 | wiphy = cfg_to_wiphy(cfg); |
| 5629 | for (i = 0; i < ARRAY_SIZE(wiphy->bands); i++) { |
| 5630 | band = wiphy->bands[i]; |
| 5631 | if (band == NULL) |
Arend van Spriel | 2375d97 | 2014-01-06 12:40:41 +0100 | [diff] [blame] | 5632 | continue; |
Hante Meuleman | d48200b | 2013-04-03 12:40:29 +0200 | [diff] [blame] | 5633 | |
Arend van Spriel | 18d6c53 | 2014-05-12 10:47:35 +0200 | [diff] [blame] | 5634 | if (nmode) |
| 5635 | brcmf_update_ht_cap(band, bw_cap, nchain); |
| 5636 | if (vhtmode) |
| 5637 | brcmf_update_vht_cap(band, bw_cap, nchain); |
Hante Meuleman | d48200b | 2013-04-03 12:40:29 +0200 | [diff] [blame] | 5638 | } |
| 5639 | |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 5640 | return 0; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5641 | } |
| 5642 | |
Hante Meuleman | a44aa40 | 2014-12-03 21:05:33 +0100 | [diff] [blame] | 5643 | static const struct ieee80211_iface_limit brcmf_iface_limits_mbss[] = { |
| 5644 | { |
| 5645 | .max = 1, |
| 5646 | .types = BIT(NL80211_IFTYPE_STATION) | |
| 5647 | BIT(NL80211_IFTYPE_ADHOC) |
| 5648 | }, |
| 5649 | { |
| 5650 | .max = 4, |
| 5651 | .types = BIT(NL80211_IFTYPE_AP) |
| 5652 | }, |
| 5653 | { |
| 5654 | .max = 1, |
| 5655 | .types = BIT(NL80211_IFTYPE_P2P_CLIENT) | |
| 5656 | BIT(NL80211_IFTYPE_P2P_GO) |
| 5657 | }, |
| 5658 | { |
| 5659 | .max = 1, |
| 5660 | .types = BIT(NL80211_IFTYPE_P2P_DEVICE) |
| 5661 | } |
| 5662 | }; |
| 5663 | |
| 5664 | static const struct ieee80211_iface_limit brcmf_iface_limits_sbss[] = { |
Arend van Spriel | aa70b4f | 2014-07-12 08:49:40 +0200 | [diff] [blame] | 5665 | { |
| 5666 | .max = 2, |
| 5667 | .types = BIT(NL80211_IFTYPE_STATION) | |
| 5668 | BIT(NL80211_IFTYPE_ADHOC) | |
| 5669 | BIT(NL80211_IFTYPE_AP) |
| 5670 | }, |
| 5671 | { |
| 5672 | .max = 1, |
| 5673 | .types = BIT(NL80211_IFTYPE_P2P_CLIENT) | |
| 5674 | BIT(NL80211_IFTYPE_P2P_GO) |
| 5675 | }, |
| 5676 | { |
| 5677 | .max = 1, |
| 5678 | .types = BIT(NL80211_IFTYPE_P2P_DEVICE) |
| 5679 | } |
| 5680 | }; |
| 5681 | static struct ieee80211_iface_combination brcmf_iface_combos[] = { |
| 5682 | { |
| 5683 | .max_interfaces = BRCMF_IFACE_MAX_CNT, |
| 5684 | .num_different_channels = 1, |
Hante Meuleman | a44aa40 | 2014-12-03 21:05:33 +0100 | [diff] [blame] | 5685 | .n_limits = ARRAY_SIZE(brcmf_iface_limits_sbss), |
| 5686 | .limits = brcmf_iface_limits_sbss, |
Arend van Spriel | aa70b4f | 2014-07-12 08:49:40 +0200 | [diff] [blame] | 5687 | } |
| 5688 | }; |
| 5689 | |
| 5690 | static const struct ieee80211_txrx_stypes |
| 5691 | brcmf_txrx_stypes[NUM_NL80211_IFTYPES] = { |
| 5692 | [NL80211_IFTYPE_STATION] = { |
| 5693 | .tx = 0xffff, |
| 5694 | .rx = BIT(IEEE80211_STYPE_ACTION >> 4) | |
| 5695 | BIT(IEEE80211_STYPE_PROBE_REQ >> 4) |
| 5696 | }, |
| 5697 | [NL80211_IFTYPE_P2P_CLIENT] = { |
| 5698 | .tx = 0xffff, |
| 5699 | .rx = BIT(IEEE80211_STYPE_ACTION >> 4) | |
| 5700 | BIT(IEEE80211_STYPE_PROBE_REQ >> 4) |
| 5701 | }, |
| 5702 | [NL80211_IFTYPE_P2P_GO] = { |
| 5703 | .tx = 0xffff, |
| 5704 | .rx = BIT(IEEE80211_STYPE_ASSOC_REQ >> 4) | |
| 5705 | BIT(IEEE80211_STYPE_REASSOC_REQ >> 4) | |
| 5706 | BIT(IEEE80211_STYPE_PROBE_REQ >> 4) | |
| 5707 | BIT(IEEE80211_STYPE_DISASSOC >> 4) | |
| 5708 | BIT(IEEE80211_STYPE_AUTH >> 4) | |
| 5709 | BIT(IEEE80211_STYPE_DEAUTH >> 4) | |
| 5710 | BIT(IEEE80211_STYPE_ACTION >> 4) |
| 5711 | }, |
| 5712 | [NL80211_IFTYPE_P2P_DEVICE] = { |
| 5713 | .tx = 0xffff, |
| 5714 | .rx = BIT(IEEE80211_STYPE_ACTION >> 4) | |
| 5715 | BIT(IEEE80211_STYPE_PROBE_REQ >> 4) |
| 5716 | } |
| 5717 | }; |
| 5718 | |
| 5719 | static void brcmf_wiphy_pno_params(struct wiphy *wiphy) |
| 5720 | { |
| 5721 | /* scheduled scan settings */ |
| 5722 | wiphy->max_sched_scan_ssids = BRCMF_PNO_MAX_PFN_COUNT; |
| 5723 | wiphy->max_match_sets = BRCMF_PNO_MAX_PFN_COUNT; |
| 5724 | wiphy->max_sched_scan_ie_len = BRCMF_SCAN_IE_LEN_MAX; |
| 5725 | wiphy->flags |= WIPHY_FLAG_SUPPORTS_SCHED_SCAN; |
| 5726 | } |
| 5727 | |
Hante Meuleman | 4eb3af7 | 2014-09-30 10:23:18 +0200 | [diff] [blame] | 5728 | #ifdef CONFIG_PM |
| 5729 | static const struct wiphy_wowlan_support brcmf_wowlan_support = { |
| 5730 | .flags = WIPHY_WOWLAN_MAGIC_PKT | WIPHY_WOWLAN_DISCONNECT, |
Hante Meuleman | b9a82f8 | 2014-10-28 14:56:06 +0100 | [diff] [blame] | 5731 | .n_patterns = BRCMF_WOWL_MAXPATTERNS, |
| 5732 | .pattern_max_len = BRCMF_WOWL_MAXPATTERNSIZE, |
| 5733 | .pattern_min_len = 1, |
| 5734 | .max_pkt_offset = 1500, |
Hante Meuleman | 4eb3af7 | 2014-09-30 10:23:18 +0200 | [diff] [blame] | 5735 | }; |
| 5736 | #endif |
| 5737 | |
| 5738 | static void brcmf_wiphy_wowl_params(struct wiphy *wiphy) |
| 5739 | { |
| 5740 | #ifdef CONFIG_PM |
| 5741 | /* wowl settings */ |
| 5742 | wiphy->wowlan = &brcmf_wowlan_support; |
| 5743 | #endif |
| 5744 | } |
| 5745 | |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 5746 | 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] | 5747 | { |
Arend van Spriel | 58de92d | 2015-04-14 20:10:24 +0200 | [diff] [blame] | 5748 | struct ieee80211_supported_band *band; |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 5749 | struct ieee80211_iface_combination ifc_combo; |
Arend van Spriel | 58de92d | 2015-04-14 20:10:24 +0200 | [diff] [blame] | 5750 | __le32 bandlist[3]; |
| 5751 | u32 n_bands; |
| 5752 | int err, i; |
| 5753 | |
Arend van Spriel | aa70b4f | 2014-07-12 08:49:40 +0200 | [diff] [blame] | 5754 | wiphy->max_scan_ssids = WL_NUM_SCAN_MAX; |
| 5755 | wiphy->max_scan_ie_len = BRCMF_SCAN_IE_LEN_MAX; |
| 5756 | wiphy->max_num_pmkids = WL_NUM_PMKIDS_MAX; |
| 5757 | wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) | |
| 5758 | BIT(NL80211_IFTYPE_ADHOC) | |
| 5759 | BIT(NL80211_IFTYPE_AP) | |
| 5760 | BIT(NL80211_IFTYPE_P2P_CLIENT) | |
| 5761 | BIT(NL80211_IFTYPE_P2P_GO) | |
| 5762 | BIT(NL80211_IFTYPE_P2P_DEVICE); |
| 5763 | /* need VSDB firmware feature for concurrent channels */ |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 5764 | ifc_combo = brcmf_iface_combos[0]; |
Arend van Spriel | aa70b4f | 2014-07-12 08:49:40 +0200 | [diff] [blame] | 5765 | if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_MCHAN)) |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 5766 | ifc_combo.num_different_channels = 2; |
Hante Meuleman | a44aa40 | 2014-12-03 21:05:33 +0100 | [diff] [blame] | 5767 | if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_MBSS)) { |
| 5768 | ifc_combo.n_limits = ARRAY_SIZE(brcmf_iface_limits_mbss), |
| 5769 | ifc_combo.limits = brcmf_iface_limits_mbss; |
| 5770 | } |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 5771 | wiphy->iface_combinations = kmemdup(&ifc_combo, |
| 5772 | sizeof(ifc_combo), |
| 5773 | GFP_KERNEL); |
Arend van Spriel | aa70b4f | 2014-07-12 08:49:40 +0200 | [diff] [blame] | 5774 | wiphy->n_iface_combinations = ARRAY_SIZE(brcmf_iface_combos); |
Arend van Spriel | aa70b4f | 2014-07-12 08:49:40 +0200 | [diff] [blame] | 5775 | wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM; |
| 5776 | wiphy->cipher_suites = __wl_cipher_suites; |
| 5777 | wiphy->n_cipher_suites = ARRAY_SIZE(__wl_cipher_suites); |
| 5778 | wiphy->flags |= WIPHY_FLAG_PS_ON_BY_DEFAULT | |
| 5779 | WIPHY_FLAG_OFFCHAN_TX | |
| 5780 | WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL | |
| 5781 | WIPHY_FLAG_SUPPORTS_TDLS; |
| 5782 | if (!brcmf_roamoff) |
| 5783 | wiphy->flags |= WIPHY_FLAG_SUPPORTS_FW_ROAM; |
| 5784 | wiphy->mgmt_stypes = brcmf_txrx_stypes; |
| 5785 | wiphy->max_remain_on_channel_duration = 5000; |
Arend van Spriel | 7a7a87d | 2015-04-14 20:10:27 +0200 | [diff] [blame] | 5786 | if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_PNO)) |
| 5787 | brcmf_wiphy_pno_params(wiphy); |
Arend van Spriel | aa70b4f | 2014-07-12 08:49:40 +0200 | [diff] [blame] | 5788 | |
| 5789 | /* vendor commands/events support */ |
| 5790 | wiphy->vendor_commands = brcmf_vendor_cmds; |
| 5791 | wiphy->n_vendor_commands = BRCMF_VNDR_CMDS_LAST - 1; |
| 5792 | |
Hante Meuleman | 4eb3af7 | 2014-09-30 10:23:18 +0200 | [diff] [blame] | 5793 | if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_WOWL)) |
| 5794 | brcmf_wiphy_wowl_params(wiphy); |
| 5795 | |
Arend van Spriel | 58de92d | 2015-04-14 20:10:24 +0200 | [diff] [blame] | 5796 | err = brcmf_fil_cmd_data_get(ifp, BRCMF_C_GET_BANDLIST, &bandlist, |
| 5797 | sizeof(bandlist)); |
| 5798 | if (err) { |
| 5799 | brcmf_err("could not obtain band info: err=%d\n", err); |
| 5800 | return err; |
| 5801 | } |
| 5802 | /* first entry in bandlist is number of bands */ |
| 5803 | n_bands = le32_to_cpu(bandlist[0]); |
| 5804 | for (i = 1; i <= n_bands && i < ARRAY_SIZE(bandlist); i++) { |
| 5805 | if (bandlist[i] == cpu_to_le32(WLC_BAND_2G)) { |
| 5806 | band = kmemdup(&__wl_band_2ghz, sizeof(__wl_band_2ghz), |
| 5807 | GFP_KERNEL); |
| 5808 | if (!band) |
| 5809 | return -ENOMEM; |
| 5810 | |
| 5811 | band->channels = kmemdup(&__wl_2ghz_channels, |
| 5812 | sizeof(__wl_2ghz_channels), |
| 5813 | GFP_KERNEL); |
| 5814 | if (!band->channels) { |
| 5815 | kfree(band); |
| 5816 | return -ENOMEM; |
| 5817 | } |
| 5818 | |
| 5819 | band->n_channels = ARRAY_SIZE(__wl_2ghz_channels); |
| 5820 | wiphy->bands[IEEE80211_BAND_2GHZ] = band; |
| 5821 | } |
| 5822 | if (bandlist[i] == cpu_to_le32(WLC_BAND_5G)) { |
| 5823 | band = kmemdup(&__wl_band_5ghz, sizeof(__wl_band_5ghz), |
| 5824 | GFP_KERNEL); |
| 5825 | if (!band) |
| 5826 | return -ENOMEM; |
| 5827 | |
| 5828 | band->channels = kmemdup(&__wl_5ghz_channels, |
| 5829 | sizeof(__wl_5ghz_channels), |
| 5830 | GFP_KERNEL); |
| 5831 | if (!band->channels) { |
| 5832 | kfree(band); |
| 5833 | return -ENOMEM; |
| 5834 | } |
| 5835 | |
| 5836 | band->n_channels = ARRAY_SIZE(__wl_5ghz_channels); |
| 5837 | wiphy->bands[IEEE80211_BAND_5GHZ] = band; |
| 5838 | } |
| 5839 | } |
| 5840 | err = brcmf_setup_wiphybands(wiphy); |
| 5841 | return err; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5842 | } |
| 5843 | |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5844 | static s32 brcmf_config_dongle(struct brcmf_cfg80211_info *cfg) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5845 | { |
| 5846 | struct net_device *ndev; |
| 5847 | struct wireless_dev *wdev; |
Hante Meuleman | 40a2329 | 2013-01-02 15:22:51 +0100 | [diff] [blame] | 5848 | struct brcmf_if *ifp; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5849 | s32 power_mode; |
| 5850 | s32 err = 0; |
| 5851 | |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5852 | if (cfg->dongle_up) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5853 | return err; |
| 5854 | |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5855 | ndev = cfg_to_ndev(cfg); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5856 | wdev = ndev->ieee80211_ptr; |
Hante Meuleman | 40a2329 | 2013-01-02 15:22:51 +0100 | [diff] [blame] | 5857 | ifp = netdev_priv(ndev); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5858 | |
Hante Meuleman | 40a2329 | 2013-01-02 15:22:51 +0100 | [diff] [blame] | 5859 | /* make sure RF is ready for work */ |
| 5860 | brcmf_fil_cmd_int_set(ifp, BRCMF_C_UP, 0); |
| 5861 | |
| 5862 | brcmf_dongle_scantime(ifp, WL_SCAN_CHANNEL_TIME, |
| 5863 | WL_SCAN_UNASSOC_TIME, WL_SCAN_PASSIVE_TIME); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5864 | |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5865 | power_mode = cfg->pwr_save ? PM_FAST : PM_OFF; |
Hante Meuleman | 40a2329 | 2013-01-02 15:22:51 +0100 | [diff] [blame] | 5866 | 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] | 5867 | if (err) |
| 5868 | goto default_conf_out; |
Arend van Spriel | 647c9ae | 2012-12-05 15:26:01 +0100 | [diff] [blame] | 5869 | brcmf_dbg(INFO, "power save set to %s\n", |
| 5870 | (power_mode ? "enabled" : "disabled")); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5871 | |
Hante Meuleman | 68ca395 | 2014-02-25 20:30:26 +0100 | [diff] [blame] | 5872 | err = brcmf_dongle_roam(ifp, WL_BEACON_TIMEOUT); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5873 | if (err) |
| 5874 | goto default_conf_out; |
Franky Lin | 5dd161f | 2012-10-10 11:13:10 -0700 | [diff] [blame] | 5875 | err = brcmf_cfg80211_change_iface(wdev->wiphy, ndev, wdev->iftype, |
| 5876 | NULL, NULL); |
Hante Meuleman | 40a2329 | 2013-01-02 15:22:51 +0100 | [diff] [blame] | 5877 | if (err) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5878 | goto default_conf_out; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5879 | |
Hante Meuleman | b365745 | 2013-05-27 21:09:53 +0200 | [diff] [blame] | 5880 | brcmf_configure_arp_offload(ifp, true); |
| 5881 | |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5882 | cfg->dongle_up = true; |
Hante Meuleman | 40a2329 | 2013-01-02 15:22:51 +0100 | [diff] [blame] | 5883 | default_conf_out: |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5884 | |
| 5885 | return err; |
| 5886 | |
| 5887 | } |
| 5888 | |
Arend van Spriel | bdf5ff5 | 2012-11-14 18:46:09 -0800 | [diff] [blame] | 5889 | static s32 __brcmf_cfg80211_up(struct brcmf_if *ifp) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5890 | { |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 5891 | set_bit(BRCMF_VIF_STATUS_READY, &ifp->vif->sme_state); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5892 | |
Arend van Spriel | bdf5ff5 | 2012-11-14 18:46:09 -0800 | [diff] [blame] | 5893 | return brcmf_config_dongle(ifp->drvr->config); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5894 | } |
| 5895 | |
Arend van Spriel | bdf5ff5 | 2012-11-14 18:46:09 -0800 | [diff] [blame] | 5896 | static s32 __brcmf_cfg80211_down(struct brcmf_if *ifp) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5897 | { |
Arend van Spriel | bdf5ff5 | 2012-11-14 18:46:09 -0800 | [diff] [blame] | 5898 | struct brcmf_cfg80211_info *cfg = ifp->drvr->config; |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 5899 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5900 | /* |
| 5901 | * While going down, if associated with AP disassociate |
| 5902 | * from AP to save power |
| 5903 | */ |
Arend van Spriel | 903e0ee | 2012-11-28 21:44:11 +0100 | [diff] [blame] | 5904 | if (check_vif_up(ifp->vif)) { |
Arend van Spriel | 9b7a0dd | 2015-01-25 20:31:33 +0100 | [diff] [blame] | 5905 | brcmf_link_down(ifp->vif, WLAN_REASON_UNSPECIFIED); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5906 | |
| 5907 | /* Make sure WPA_Supplicant receives all the event |
| 5908 | generated due to DISASSOC call to the fw to keep |
| 5909 | the state fw and WPA_Supplicant state consistent |
| 5910 | */ |
| 5911 | brcmf_delay(500); |
| 5912 | } |
| 5913 | |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5914 | brcmf_abort_scanning(cfg); |
Arend van Spriel | c117903 | 2012-10-22 13:55:33 -0700 | [diff] [blame] | 5915 | clear_bit(BRCMF_VIF_STATUS_READY, &ifp->vif->sme_state); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5916 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5917 | return 0; |
| 5918 | } |
| 5919 | |
Arend van Spriel | bdf5ff5 | 2012-11-14 18:46:09 -0800 | [diff] [blame] | 5920 | s32 brcmf_cfg80211_up(struct net_device *ndev) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5921 | { |
Arend van Spriel | bdf5ff5 | 2012-11-14 18:46:09 -0800 | [diff] [blame] | 5922 | struct brcmf_if *ifp = netdev_priv(ndev); |
| 5923 | struct brcmf_cfg80211_info *cfg = ifp->drvr->config; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5924 | s32 err = 0; |
| 5925 | |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5926 | mutex_lock(&cfg->usr_sync); |
Arend van Spriel | bdf5ff5 | 2012-11-14 18:46:09 -0800 | [diff] [blame] | 5927 | err = __brcmf_cfg80211_up(ifp); |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5928 | mutex_unlock(&cfg->usr_sync); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5929 | |
| 5930 | return err; |
| 5931 | } |
| 5932 | |
Arend van Spriel | bdf5ff5 | 2012-11-14 18:46:09 -0800 | [diff] [blame] | 5933 | s32 brcmf_cfg80211_down(struct net_device *ndev) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5934 | { |
Arend van Spriel | bdf5ff5 | 2012-11-14 18:46:09 -0800 | [diff] [blame] | 5935 | struct brcmf_if *ifp = netdev_priv(ndev); |
| 5936 | struct brcmf_cfg80211_info *cfg = ifp->drvr->config; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5937 | s32 err = 0; |
| 5938 | |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5939 | mutex_lock(&cfg->usr_sync); |
Arend van Spriel | bdf5ff5 | 2012-11-14 18:46:09 -0800 | [diff] [blame] | 5940 | err = __brcmf_cfg80211_down(ifp); |
Arend van Spriel | 27a68fe | 2012-09-27 14:17:55 +0200 | [diff] [blame] | 5941 | mutex_unlock(&cfg->usr_sync); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 5942 | |
| 5943 | return err; |
| 5944 | } |
| 5945 | |
Arend van Spriel | a7965fb | 2013-04-11 17:08:37 +0200 | [diff] [blame] | 5946 | enum nl80211_iftype brcmf_cfg80211_get_iftype(struct brcmf_if *ifp) |
| 5947 | { |
| 5948 | struct wireless_dev *wdev = &ifp->vif->wdev; |
| 5949 | |
| 5950 | return wdev->iftype; |
| 5951 | } |
| 5952 | |
Hante Meuleman | bfe8197 | 2014-10-28 14:56:16 +0100 | [diff] [blame] | 5953 | bool brcmf_get_vif_state_any(struct brcmf_cfg80211_info *cfg, |
| 5954 | unsigned long state) |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 5955 | { |
| 5956 | struct brcmf_cfg80211_vif *vif; |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 5957 | |
| 5958 | list_for_each_entry(vif, &cfg->vif_list, list) { |
| 5959 | if (test_bit(state, &vif->sme_state)) |
Rasmus Villemoes | e843bb1 | 2014-06-22 20:50:40 +0200 | [diff] [blame] | 5960 | return true; |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 5961 | } |
Rasmus Villemoes | e843bb1 | 2014-06-22 20:50:40 +0200 | [diff] [blame] | 5962 | return false; |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 5963 | } |
Arend van Spriel | d3c0b63 | 2013-02-08 15:53:37 +0100 | [diff] [blame] | 5964 | |
| 5965 | static inline bool vif_event_equals(struct brcmf_cfg80211_vif_event *event, |
| 5966 | u8 action) |
| 5967 | { |
| 5968 | u8 evt_action; |
| 5969 | |
| 5970 | mutex_lock(&event->vif_event_lock); |
| 5971 | evt_action = event->action; |
| 5972 | mutex_unlock(&event->vif_event_lock); |
| 5973 | return evt_action == action; |
| 5974 | } |
| 5975 | |
| 5976 | void brcmf_cfg80211_arm_vif_event(struct brcmf_cfg80211_info *cfg, |
| 5977 | struct brcmf_cfg80211_vif *vif) |
| 5978 | { |
| 5979 | struct brcmf_cfg80211_vif_event *event = &cfg->vif_event; |
| 5980 | |
| 5981 | mutex_lock(&event->vif_event_lock); |
| 5982 | event->vif = vif; |
| 5983 | event->action = 0; |
| 5984 | mutex_unlock(&event->vif_event_lock); |
| 5985 | } |
| 5986 | |
| 5987 | bool brcmf_cfg80211_vif_event_armed(struct brcmf_cfg80211_info *cfg) |
| 5988 | { |
| 5989 | struct brcmf_cfg80211_vif_event *event = &cfg->vif_event; |
| 5990 | bool armed; |
| 5991 | |
| 5992 | mutex_lock(&event->vif_event_lock); |
| 5993 | armed = event->vif != NULL; |
| 5994 | mutex_unlock(&event->vif_event_lock); |
| 5995 | |
| 5996 | return armed; |
| 5997 | } |
| 5998 | int brcmf_cfg80211_wait_vif_event_timeout(struct brcmf_cfg80211_info *cfg, |
| 5999 | u8 action, ulong timeout) |
| 6000 | { |
| 6001 | struct brcmf_cfg80211_vif_event *event = &cfg->vif_event; |
| 6002 | |
| 6003 | return wait_event_timeout(event->vif_wq, |
| 6004 | vif_event_equals(event, action), timeout); |
| 6005 | } |
| 6006 | |
Arend van Spriel | 63db1a4 | 2014-12-21 12:43:51 +0100 | [diff] [blame] | 6007 | static void brcmf_cfg80211_reg_notifier(struct wiphy *wiphy, |
| 6008 | struct regulatory_request *req) |
| 6009 | { |
| 6010 | struct brcmf_cfg80211_info *cfg = wiphy_priv(wiphy); |
| 6011 | struct brcmf_if *ifp = netdev_priv(cfg_to_ndev(cfg)); |
| 6012 | struct brcmf_fil_country_le ccreq; |
| 6013 | int i; |
| 6014 | |
| 6015 | brcmf_dbg(TRACE, "enter: initiator=%d, alpha=%c%c\n", req->initiator, |
| 6016 | req->alpha2[0], req->alpha2[1]); |
| 6017 | |
| 6018 | /* ignore non-ISO3166 country codes */ |
| 6019 | for (i = 0; i < sizeof(req->alpha2); i++) |
| 6020 | if (req->alpha2[i] < 'A' || req->alpha2[i] > 'Z') { |
| 6021 | brcmf_err("not a ISO3166 code\n"); |
| 6022 | return; |
| 6023 | } |
| 6024 | memset(&ccreq, 0, sizeof(ccreq)); |
| 6025 | ccreq.rev = cpu_to_le32(-1); |
| 6026 | memcpy(ccreq.ccode, req->alpha2, sizeof(req->alpha2)); |
Arend van Spriel | 8afe0ec | 2015-04-14 20:10:25 +0200 | [diff] [blame] | 6027 | if (brcmf_fil_iovar_data_set(ifp, "country", &ccreq, sizeof(ccreq))) { |
| 6028 | brcmf_err("firmware rejected country setting\n"); |
| 6029 | return; |
| 6030 | } |
| 6031 | brcmf_setup_wiphybands(wiphy); |
Arend van Spriel | 63db1a4 | 2014-12-21 12:43:51 +0100 | [diff] [blame] | 6032 | } |
| 6033 | |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 6034 | static void brcmf_free_wiphy(struct wiphy *wiphy) |
| 6035 | { |
Arend van Spriel | 58de92d | 2015-04-14 20:10:24 +0200 | [diff] [blame] | 6036 | if (!wiphy) |
| 6037 | return; |
| 6038 | |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 6039 | kfree(wiphy->iface_combinations); |
| 6040 | if (wiphy->bands[IEEE80211_BAND_2GHZ]) { |
| 6041 | kfree(wiphy->bands[IEEE80211_BAND_2GHZ]->channels); |
| 6042 | kfree(wiphy->bands[IEEE80211_BAND_2GHZ]); |
| 6043 | } |
| 6044 | if (wiphy->bands[IEEE80211_BAND_5GHZ]) { |
| 6045 | kfree(wiphy->bands[IEEE80211_BAND_5GHZ]->channels); |
| 6046 | kfree(wiphy->bands[IEEE80211_BAND_5GHZ]); |
| 6047 | } |
| 6048 | wiphy_free(wiphy); |
| 6049 | } |
| 6050 | |
Arend van Spriel | ccfd1e8 | 2014-07-12 08:49:38 +0200 | [diff] [blame] | 6051 | struct brcmf_cfg80211_info *brcmf_cfg80211_attach(struct brcmf_pub *drvr, |
| 6052 | struct device *busdev) |
| 6053 | { |
| 6054 | struct net_device *ndev = drvr->iflist[0]->ndev; |
| 6055 | struct brcmf_cfg80211_info *cfg; |
| 6056 | struct wiphy *wiphy; |
| 6057 | struct brcmf_cfg80211_vif *vif; |
| 6058 | struct brcmf_if *ifp; |
| 6059 | s32 err = 0; |
| 6060 | s32 io_type; |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 6061 | u16 *cap = NULL; |
Arend van Spriel | ccfd1e8 | 2014-07-12 08:49:38 +0200 | [diff] [blame] | 6062 | |
| 6063 | if (!ndev) { |
| 6064 | brcmf_err("ndev is invalid\n"); |
| 6065 | return NULL; |
| 6066 | } |
| 6067 | |
| 6068 | ifp = netdev_priv(ndev); |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 6069 | wiphy = wiphy_new(&wl_cfg80211_ops, sizeof(struct brcmf_cfg80211_info)); |
| 6070 | if (!wiphy) { |
| 6071 | brcmf_err("Could not allocate wiphy device\n"); |
Arend van Spriel | ccfd1e8 | 2014-07-12 08:49:38 +0200 | [diff] [blame] | 6072 | return NULL; |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 6073 | } |
Rafał Miłecki | 6896f4f | 2015-05-31 02:52:26 +0200 | [diff] [blame] | 6074 | memcpy(wiphy->perm_addr, drvr->mac, ETH_ALEN); |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 6075 | set_wiphy_dev(wiphy, busdev); |
Arend van Spriel | ccfd1e8 | 2014-07-12 08:49:38 +0200 | [diff] [blame] | 6076 | |
| 6077 | cfg = wiphy_priv(wiphy); |
| 6078 | cfg->wiphy = wiphy; |
| 6079 | cfg->pub = drvr; |
| 6080 | init_vif_event(&cfg->vif_event); |
| 6081 | INIT_LIST_HEAD(&cfg->vif_list); |
| 6082 | |
| 6083 | vif = brcmf_alloc_vif(cfg, NL80211_IFTYPE_STATION, false); |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 6084 | if (IS_ERR(vif)) |
| 6085 | goto wiphy_out; |
Arend van Spriel | ccfd1e8 | 2014-07-12 08:49:38 +0200 | [diff] [blame] | 6086 | |
| 6087 | vif->ifp = ifp; |
| 6088 | vif->wdev.netdev = ndev; |
| 6089 | ndev->ieee80211_ptr = &vif->wdev; |
| 6090 | SET_NETDEV_DEV(ndev, wiphy_dev(cfg->wiphy)); |
| 6091 | |
| 6092 | err = wl_init_priv(cfg); |
| 6093 | if (err) { |
| 6094 | brcmf_err("Failed to init iwm_priv (%d)\n", err); |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 6095 | brcmf_free_vif(vif); |
| 6096 | goto wiphy_out; |
Arend van Spriel | ccfd1e8 | 2014-07-12 08:49:38 +0200 | [diff] [blame] | 6097 | } |
| 6098 | ifp->vif = vif; |
| 6099 | |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 6100 | /* determine d11 io type before wiphy setup */ |
| 6101 | 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] | 6102 | if (err) { |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 6103 | brcmf_err("Failed to get D11 version (%d)\n", err); |
| 6104 | goto priv_out; |
Arend van Spriel | ccfd1e8 | 2014-07-12 08:49:38 +0200 | [diff] [blame] | 6105 | } |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 6106 | cfg->d11inf.io_type = (u8)io_type; |
| 6107 | brcmu_d11_attach(&cfg->d11inf); |
| 6108 | |
| 6109 | err = brcmf_setup_wiphy(wiphy, ifp); |
| 6110 | if (err < 0) |
| 6111 | goto priv_out; |
| 6112 | |
| 6113 | brcmf_dbg(INFO, "Registering custom regulatory\n"); |
Arend van Spriel | 63db1a4 | 2014-12-21 12:43:51 +0100 | [diff] [blame] | 6114 | wiphy->reg_notifier = brcmf_cfg80211_reg_notifier; |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 6115 | wiphy->regulatory_flags |= REGULATORY_CUSTOM_REG; |
| 6116 | wiphy_apply_custom_regulatory(wiphy, &brcmf_regdom); |
| 6117 | |
| 6118 | /* firmware defaults to 40MHz disabled in 2G band. We signal |
| 6119 | * cfg80211 here that we do and have it decide we can enable |
| 6120 | * it. But first check if device does support 2G operation. |
| 6121 | */ |
| 6122 | if (wiphy->bands[IEEE80211_BAND_2GHZ]) { |
| 6123 | cap = &wiphy->bands[IEEE80211_BAND_2GHZ]->ht_cap.cap; |
| 6124 | *cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40; |
| 6125 | } |
| 6126 | err = wiphy_register(wiphy); |
| 6127 | if (err < 0) { |
| 6128 | brcmf_err("Could not register wiphy device (%d)\n", err); |
| 6129 | goto priv_out; |
Arend van Spriel | ccfd1e8 | 2014-07-12 08:49:38 +0200 | [diff] [blame] | 6130 | } |
| 6131 | |
| 6132 | /* If cfg80211 didn't disable 40MHz HT CAP in wiphy_register(), |
| 6133 | * setup 40MHz in 2GHz band and enable OBSS scanning. |
| 6134 | */ |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 6135 | if (cap && (*cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40)) { |
| 6136 | err = brcmf_enable_bw40_2g(cfg); |
Arend van Spriel | ccfd1e8 | 2014-07-12 08:49:38 +0200 | [diff] [blame] | 6137 | if (!err) |
| 6138 | err = brcmf_fil_iovar_int_set(ifp, "obss_coex", |
| 6139 | BRCMF_OBSS_COEX_AUTO); |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 6140 | else |
| 6141 | *cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40; |
Arend van Spriel | ccfd1e8 | 2014-07-12 08:49:38 +0200 | [diff] [blame] | 6142 | } |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 6143 | |
| 6144 | err = brcmf_p2p_attach(cfg); |
| 6145 | if (err) { |
| 6146 | brcmf_err("P2P initilisation failed (%d)\n", err); |
| 6147 | goto wiphy_unreg_out; |
| 6148 | } |
| 6149 | err = brcmf_btcoex_attach(cfg); |
| 6150 | if (err) { |
| 6151 | brcmf_err("BT-coex initialisation failed (%d)\n", err); |
| 6152 | brcmf_p2p_detach(&cfg->p2p); |
| 6153 | goto wiphy_unreg_out; |
| 6154 | } |
Arend van Spriel | ccfd1e8 | 2014-07-12 08:49:38 +0200 | [diff] [blame] | 6155 | |
| 6156 | err = brcmf_fil_iovar_int_set(ifp, "tdls_enable", 1); |
| 6157 | if (err) { |
| 6158 | brcmf_dbg(INFO, "TDLS not enabled (%d)\n", err); |
| 6159 | wiphy->flags &= ~WIPHY_FLAG_SUPPORTS_TDLS; |
Hante Meuleman | 70b7d94 | 2014-07-30 13:20:07 +0200 | [diff] [blame] | 6160 | } else { |
| 6161 | brcmf_fweh_register(cfg->pub, BRCMF_E_TDLS_PEER_EVENT, |
| 6162 | brcmf_notify_tdls_peer_event); |
Arend van Spriel | ccfd1e8 | 2014-07-12 08:49:38 +0200 | [diff] [blame] | 6163 | } |
| 6164 | |
Arend van Spriel | ccfd1e8 | 2014-07-12 08:49:38 +0200 | [diff] [blame] | 6165 | return cfg; |
| 6166 | |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 6167 | wiphy_unreg_out: |
| 6168 | wiphy_unregister(cfg->wiphy); |
| 6169 | priv_out: |
Arend van Spriel | ccfd1e8 | 2014-07-12 08:49:38 +0200 | [diff] [blame] | 6170 | wl_deinit_priv(cfg); |
Arend van Spriel | ccfd1e8 | 2014-07-12 08:49:38 +0200 | [diff] [blame] | 6171 | brcmf_free_vif(vif); |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 6172 | wiphy_out: |
| 6173 | brcmf_free_wiphy(wiphy); |
Arend van Spriel | ccfd1e8 | 2014-07-12 08:49:38 +0200 | [diff] [blame] | 6174 | return NULL; |
| 6175 | } |
| 6176 | |
| 6177 | void brcmf_cfg80211_detach(struct brcmf_cfg80211_info *cfg) |
| 6178 | { |
| 6179 | if (!cfg) |
| 6180 | return; |
| 6181 | |
| 6182 | WARN_ON(!list_empty(&cfg->vif_list)); |
| 6183 | wiphy_unregister(cfg->wiphy); |
| 6184 | brcmf_btcoex_detach(cfg); |
Arend van Spriel | c3da74b | 2014-07-12 08:49:42 +0200 | [diff] [blame] | 6185 | brcmf_p2p_detach(&cfg->p2p); |
Arend van Spriel | ccfd1e8 | 2014-07-12 08:49:38 +0200 | [diff] [blame] | 6186 | wl_deinit_priv(cfg); |
Arend van Spriel | b48d891 | 2014-07-12 08:49:41 +0200 | [diff] [blame] | 6187 | brcmf_free_wiphy(cfg->wiphy); |
Arend van Spriel | ccfd1e8 | 2014-07-12 08:49:38 +0200 | [diff] [blame] | 6188 | } |